/ Check-in [1b9478da]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a problem with the incremental blob API. sqlite3_blob_open() was always reading the data for the leftmost column of the row that the opened blob was stored in. If this column happened to contain a (the) large blob, sqlite would make a large memory allocation to read the data into. Which defeats the purpose of using incremental blobs. (CVS 5222)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1b9478da2f421c1270e76297324fff8037d2f231
User & Date: danielk1977 2008-06-16 14:19:58
Context
2008-06-16
14:36
Fix a recently introduced resource leak in test file incrblob2.test (forgot to close a blob handle). (CVS 5223) check-in: 88e1c609 user: danielk1977 tags: trunk
14:19
Fix a problem with the incremental blob API. sqlite3_blob_open() was always reading the data for the leftmost column of the row that the opened blob was stored in. If this column happened to contain a (the) large blob, sqlite would make a large memory allocation to read the data into. Which defeats the purpose of using incremental blobs. (CVS 5222) check-in: 1b9478da user: danielk1977 tags: trunk
06:31
Add a test to verify that IN(...) WHERE clause terms are not handled by virtual table implemetations. (CVS 5221) check-in: 85483c8f user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/test8.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the virtual table interfaces.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test8.c,v 1.64 2008/05/13 13:27:34 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>

#ifndef SQLITE_OMIT_VIRTUALTABLE
................................................................................

    pConstraint = &pIdxInfo->aConstraint[ii];
    pUsage = &pIdxInfo->aConstraintUsage[ii];

    if( !isIgnoreUsable && !pConstraint->usable ) continue;

    iCol = pConstraint->iColumn;
    if( pVtab->aIndex[iCol] ){
      char *zCol = pVtab->aCol[iCol];
      char *zOp = 0;
      useIdx = 1;
      if( iCol<0 ){
        zCol = "rowid";
      }
      switch( pConstraint->op ){







|







 







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the virtual table interfaces.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test8.c,v 1.65 2008/06/16 14:19:58 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>

#ifndef SQLITE_OMIT_VIRTUALTABLE
................................................................................

    pConstraint = &pIdxInfo->aConstraint[ii];
    pUsage = &pIdxInfo->aConstraintUsage[ii];

    if( !isIgnoreUsable && !pConstraint->usable ) continue;

    iCol = pConstraint->iColumn;
    if( pVtab->aIndex[iCol] || iCol<0 ){
      char *zCol = pVtab->aCol[iCol];
      char *zOp = 0;
      useIdx = 1;
      if( iCol<0 ){
        zCol = "rowid";
      }
      switch( pConstraint->op ){

Changes to src/vdbeblob.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
187
188
189
190
191
192
193

194
195
196
197
198
199
200
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement incremental BLOB I/O.
**
** $Id: vdbeblob.c,v 1.22 2008/04/24 09:49:55 danielk1977 Exp $
*/

#include "sqliteInt.h"
#include "vdbeInt.h"

#ifndef SQLITE_OMIT_INCRBLOB

................................................................................
      ** think that the table has one more column than it really
      ** does. An OP_Column to retrieve this imaginary column will
      ** always return an SQL NULL. This is useful because it means
      ** we can invoke OP_Column to fill in the vdbe cursors type 
      ** and offset cache without causing any IO.
      */
      sqlite3VdbeChangeP2(v, flags ? 4 : 2, pTab->nCol+1);

      if( !db->mallocFailed ){
        sqlite3VdbeMakeReady(v, 1, 1, 1, 0);
      }
    }
   
    sqlite3BtreeLeaveAll(db);
    rc = sqlite3SafetyOff(db);







|







 







>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement incremental BLOB I/O.
**
** $Id: vdbeblob.c,v 1.23 2008/06/16 14:19:58 danielk1977 Exp $
*/

#include "sqliteInt.h"
#include "vdbeInt.h"

#ifndef SQLITE_OMIT_INCRBLOB

................................................................................
      ** think that the table has one more column than it really
      ** does. An OP_Column to retrieve this imaginary column will
      ** always return an SQL NULL. This is useful because it means
      ** we can invoke OP_Column to fill in the vdbe cursors type 
      ** and offset cache without causing any IO.
      */
      sqlite3VdbeChangeP2(v, flags ? 4 : 2, pTab->nCol+1);
      sqlite3VdbeChangeP2(v, 8, pTab->nCol);
      if( !db->mallocFailed ){
        sqlite3VdbeMakeReady(v, 1, 1, 1, 0);
      }
    }
   
    sqlite3BtreeLeaveAll(db);
    rc = sqlite3SafetyOff(db);

Changes to test/incrblob2.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
300
301
302
303
304
305
306

307
308
309
310
311
312
313
...
319
320
321
322
323
324
325























326
327
328
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Test that it is possible to have two open blob handles on a single
# blob object.
#
# $Id: incrblob2.test,v 1.3 2008/06/12 14:42:07 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable {!autovacuum || !pragma || !incrblob} {
  finish_test
................................................................................
  
  set rdHandle [db incrblob -readonly t1 data 1]
  set wrHandle [db incrblob t1 data 1]

  sqlite3_blob_read $rdHandle 0 100

  sqlite3_blob_write $wrHandle 0 ABCDEF

  close $wrHandle
  close $rdHandle
} {}

do_test incrblob2-6.2 {
  set rdHandle [db incrblob -readonly t1 data 1]
  sqlite3_blob_read $rdHandle 0 2
................................................................................
  sqlite3_blob_read $rdHandle 2 4
} {ZZZZ}

do_test incrblob2-6.4 {
  close $wrHandle
  close $rdHandle
} {}
























finish_test








|







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Test that it is possible to have two open blob handles on a single
# blob object.
#
# $Id: incrblob2.test,v 1.4 2008/06/16 14:19:58 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable {!autovacuum || !pragma || !incrblob} {
  finish_test
................................................................................
  
  set rdHandle [db incrblob -readonly t1 data 1]
  set wrHandle [db incrblob t1 data 1]

  sqlite3_blob_read $rdHandle 0 100

  sqlite3_blob_write $wrHandle 0 ABCDEF

  close $wrHandle
  close $rdHandle
} {}

do_test incrblob2-6.2 {
  set rdHandle [db incrblob -readonly t1 data 1]
  sqlite3_blob_read $rdHandle 0 2
................................................................................
  sqlite3_blob_read $rdHandle 2 4
} {ZZZZ}

do_test incrblob2-6.4 {
  close $wrHandle
  close $rdHandle
} {}

sqlite3_memory_highwater 1
do_test incrblob2-7.1 {
  db eval {
    CREATE TABLE t2(B BLOB);
    INSERT INTO t2 VALUES(zeroblob(10 * 1024 * 1024)); 
  }
  expr {[sqlite3_memory_highwater]<(5 * 1024 * 1024)}
} {1}

do_test incrblob2-7.2 {
  set h [db incrblob t2 B 1]
  expr {[sqlite3_memory_highwater]<(5 * 1024 * 1024)}
} {1}

do_test incrblob2-7.3 {
  seek $h 0 end
  tell $h
} [expr 10 * 1024 * 1024]

do_test incrblob2-7.4 {
  expr {[sqlite3_memory_highwater]<(5 * 1024 * 1024)}
} {1}

finish_test