/ Check-in [9c685171]
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:Add support for read-only shadow tables on virtual tables. Added the SQLITE_DEFAULT_DEFENSIVE compile-time option that can put SQLite in defensive mode by default.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9c685171c4d7ae8615d1489c9621aba79fe4ef1f0e56b75823b88c3e70d127df
User & Date: drh 2018-11-10 18:23:32
Context
2018-11-12
13:20
Fix a use-after-free problem in the fts5vocab virtual table. check-in: ac69d169 user: dan tags: trunk
2018-11-10
20:07
Merge the read-only shadow table and defensive mode enhancments from trunk. check-in: 977fc44e user: drh tags: apple-osx
18:23
Add support for read-only shadow tables on virtual tables. Added the SQLITE_DEFAULT_DEFENSIVE compile-time option that can put SQLite in defensive mode by default. check-in: 9c685171 user: drh tags: trunk
17:37
Add the "changesetfuzz" program. For fuzzing changeset blobs. check-in: 2bae0e7c user: dan tags: trunk
04:14
Remove a NEVER() that is reachable after all. Reverts checkin [9292d3351c40339]. Closed-Leaf check-in: c5dc7fb8 user: drh tags: read-only-shadow
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/expert/sqlite3expert.c.

   640    640       0,                            /* xCommit - commit transaction */
   641    641       0,                            /* xRollback - rollback transaction */
   642    642       0,                            /* xFindFunction - function overloading */
   643    643       0,                            /* xRename - rename the table */
   644    644       0,                            /* xSavepoint */
   645    645       0,                            /* xRelease */
   646    646       0,                            /* xRollbackTo */
          647  +    0,                            /* xShadowName */
   647    648     };
   648    649   
   649    650     return sqlite3_create_module(p->dbv, "expert", &expertModule, (void*)p);
   650    651   }
   651    652   /*
   652    653   ** End of virtual table implementation.
   653    654   *************************************************************************/

Changes to ext/fts3/fts3.c.

  3841   3841     UNUSED_PARAMETER(iSavepoint);
  3842   3842     assert( p->inTransaction );
  3843   3843     assert( p->mxSavepoint >= iSavepoint );
  3844   3844     TESTONLY( p->mxSavepoint = iSavepoint );
  3845   3845     sqlite3Fts3PendingTermsClear(p);
  3846   3846     return SQLITE_OK;
  3847   3847   }
         3848  +
         3849  +/*
         3850  +** Return true if zName is the extension on one of the shadow tables used
         3851  +** by this module.
         3852  +*/
         3853  +static int fts3ShadowName(const char *zName){
         3854  +  static const char *azName[] = {
         3855  +    "content", "docsize", "segdir", "segments", "stat", 
         3856  +  };
         3857  +  unsigned int i;
         3858  +  for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
         3859  +    if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
         3860  +  }
         3861  +  return 0;
         3862  +}
  3848   3863   
  3849   3864   static const sqlite3_module fts3Module = {
  3850         -  /* iVersion      */ 2,
         3865  +  /* iVersion      */ 3,
  3851   3866     /* xCreate       */ fts3CreateMethod,
  3852   3867     /* xConnect      */ fts3ConnectMethod,
  3853   3868     /* xBestIndex    */ fts3BestIndexMethod,
  3854   3869     /* xDisconnect   */ fts3DisconnectMethod,
  3855   3870     /* xDestroy      */ fts3DestroyMethod,
  3856   3871     /* xOpen         */ fts3OpenMethod,
  3857   3872     /* xClose        */ fts3CloseMethod,
................................................................................
  3866   3881     /* xCommit       */ fts3CommitMethod,
  3867   3882     /* xRollback     */ fts3RollbackMethod,
  3868   3883     /* xFindFunction */ fts3FindFunctionMethod,
  3869   3884     /* xRename */       fts3RenameMethod,
  3870   3885     /* xSavepoint    */ fts3SavepointMethod,
  3871   3886     /* xRelease      */ fts3ReleaseMethod,
  3872   3887     /* xRollbackTo   */ fts3RollbackToMethod,
         3888  +  /* xShadowName   */ fts3ShadowName,
  3873   3889   };
  3874   3890   
  3875   3891   /*
  3876   3892   ** This function is registered as the module destructor (called when an
  3877   3893   ** FTS3 enabled database connection is closed). It frees the memory
  3878   3894   ** allocated for the tokenizer hash table.
  3879   3895   */

Changes to ext/fts3/fts3_aux.c.

   535    535        0,                           /* xSync         */
   536    536        0,                           /* xCommit       */
   537    537        0,                           /* xRollback     */
   538    538        0,                           /* xFindFunction */
   539    539        0,                           /* xRename       */
   540    540        0,                           /* xSavepoint    */
   541    541        0,                           /* xRelease      */
   542         -     0                            /* xRollbackTo   */
          542  +     0,                           /* xRollbackTo   */
          543  +     0                            /* xShadowName   */
   543    544     };
   544    545     int rc;                         /* Return code */
   545    546   
   546    547     rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
   547    548     return rc;
   548    549   }
   549    550   
   550    551   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */

Changes to ext/fts3/fts3_term.c.

   357    357        0,                           /* xSync         */
   358    358        0,                           /* xCommit       */
   359    359        0,                           /* xRollback     */
   360    360        0,                           /* xFindFunction */
   361    361        0,                           /* xRename       */
   362    362        0,                           /* xSavepoint    */
   363    363        0,                           /* xRelease      */
   364         -     0                            /* xRollbackTo   */
          364  +     0,                           /* xRollbackTo   */
          365  +     0                            /* xShadowName   */
   365    366     };
   366    367     int rc;                         /* Return code */
   367    368   
   368    369     rc = sqlite3_create_module(db, "fts4term", &fts3term_module, 0);
   369    370     return rc;
   370    371   }
   371    372   
   372    373   #endif
   373    374   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */

Changes to ext/fts3/fts3_tokenize_vtab.c.

   439    439        0,                           /* xSync         */
   440    440        0,                           /* xCommit       */
   441    441        0,                           /* xRollback     */
   442    442        0,                           /* xFindFunction */
   443    443        0,                           /* xRename       */
   444    444        0,                           /* xSavepoint    */
   445    445        0,                           /* xRelease      */
   446         -     0                            /* xRollbackTo   */
          446  +     0,                           /* xRollbackTo   */
          447  +     0                            /* xShadowName   */
   447    448     };
   448    449     int rc;                         /* Return code */
   449    450   
   450    451     rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash);
   451    452     return rc;
   452    453   }
   453    454   
   454    455   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */

Changes to ext/fts5/fts5_main.c.

  2640   2640     int nArg,                       /* Number of args */
  2641   2641     sqlite3_value **apUnused        /* Function arguments */
  2642   2642   ){
  2643   2643     assert( nArg==0 );
  2644   2644     UNUSED_PARAM2(nArg, apUnused);
  2645   2645     sqlite3_result_text(pCtx, "--FTS5-SOURCE-ID--", -1, SQLITE_TRANSIENT);
  2646   2646   }
         2647  +
         2648  +/*
         2649  +** Return true if zName is the extension on one of the shadow tables used
         2650  +** by this module.
         2651  +*/
         2652  +static int fts5ShadowName(const char *zName){
         2653  +  static const char *azName[] = {
         2654  +    "config", "content", "data", "docsize", "idx"
         2655  +  };
         2656  +  unsigned int i;
         2657  +  for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
         2658  +    if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
         2659  +  }
         2660  +  return 0;
         2661  +}
  2647   2662   
  2648   2663   static int fts5Init(sqlite3 *db){
  2649   2664     static const sqlite3_module fts5Mod = {
  2650         -    /* iVersion      */ 2,
         2665  +    /* iVersion      */ 3,
  2651   2666       /* xCreate       */ fts5CreateMethod,
  2652   2667       /* xConnect      */ fts5ConnectMethod,
  2653   2668       /* xBestIndex    */ fts5BestIndexMethod,
  2654   2669       /* xDisconnect   */ fts5DisconnectMethod,
  2655   2670       /* xDestroy      */ fts5DestroyMethod,
  2656   2671       /* xOpen         */ fts5OpenMethod,
  2657   2672       /* xClose        */ fts5CloseMethod,
................................................................................
  2666   2681       /* xCommit       */ fts5CommitMethod,
  2667   2682       /* xRollback     */ fts5RollbackMethod,
  2668   2683       /* xFindFunction */ fts5FindFunctionMethod,
  2669   2684       /* xRename       */ fts5RenameMethod,
  2670   2685       /* xSavepoint    */ fts5SavepointMethod,
  2671   2686       /* xRelease      */ fts5ReleaseMethod,
  2672   2687       /* xRollbackTo   */ fts5RollbackToMethod,
         2688  +    /* xShadowName   */ fts5ShadowName
  2673   2689     };
  2674   2690   
  2675   2691     int rc;
  2676   2692     Fts5Global *pGlobal = 0;
  2677   2693   
  2678   2694     pGlobal = (Fts5Global*)sqlite3_malloc(sizeof(Fts5Global));
  2679   2695     if( pGlobal==0 ){

Changes to ext/fts5/fts5_test_tok.c.

   467    467        0,                           /* xSync         */
   468    468        0,                           /* xCommit       */
   469    469        0,                           /* xRollback     */
   470    470        0,                           /* xFindFunction */
   471    471        0,                           /* xRename       */
   472    472        0,                           /* xSavepoint    */
   473    473        0,                           /* xRelease      */
   474         -     0                            /* xRollbackTo   */
          474  +     0,                           /* xRollbackTo   */
          475  +     0                            /* xShadowName   */
   475    476     };
   476    477     int rc;                         /* Return code */
   477    478   
   478    479     rc = sqlite3_create_module(db, "fts5tokenize", &fts5tok_module, (void*)pApi);
   479    480     return rc;
   480    481   }
   481    482   
   482    483   #endif /* defined(SQLITE_TEST) && defined(SQLITE_ENABLE_FTS5) */

Changes to ext/fts5/fts5_vocab.c.

   751    751       /* xCommit       */ 0,
   752    752       /* xRollback     */ 0,
   753    753       /* xFindFunction */ 0,
   754    754       /* xRename       */ 0,
   755    755       /* xSavepoint    */ 0,
   756    756       /* xRelease      */ 0,
   757    757       /* xRollbackTo   */ 0,
          758  +    /* xShadowName   */ 0
   758    759     };
   759    760     void *p = (void*)pGlobal;
   760    761   
   761    762     return sqlite3_create_module_v2(db, "fts5vocab", &fts5Vocab, p, 0);
   762    763   }
   763         -
   764         -

Changes to ext/fts5/test/fts5aa.test.

   405    405     }
   406    406     set nRow
   407    407   } {200}
   408    408   
   409    409   do_execsql_test 15.0 {
   410    410     INSERT INTO t1(t1) VALUES('integrity-check');
   411    411   }
          412  +sqlite3_db_config db DEFENSIVE 0
   412    413   do_execsql_test 15.1 {
   413    414     UPDATE t1_content SET c1 = 'xyz xyz xyz xyz xyz abc' WHERE rowid = 1;
   414    415   }
   415    416   do_catchsql_test 15.2 {
   416    417     INSERT INTO t1(t1) VALUES('integrity-check');
   417    418   } {1 {database disk image is malformed}}
   418    419   

Changes to ext/fts5/test/fts5connect.test.

   240    240   
   241    241     do_execsql_test 4.$tn.3 {
   242    242       INSERT INTO ft3(ft3) VALUES('integrity-check');
   243    243     }
   244    244   }
   245    245   
   246    246   finish_test
   247         -

Changes to ext/fts5/test/fts5corrupt.test.

    37     37     fts5_level_segs t1
    38     38   } {1}
    39     39   db_save
    40     40   
    41     41   do_execsql_test 1.2 { INSERT INTO t1(t1) VALUES('integrity-check') }
    42     42   set segid [lindex [fts5_level_segids t1] 0]
    43     43   
           44  +sqlite3_db_config db DEFENSIVE 0
    44     45   do_test 1.3 {
    45     46     execsql {
    46     47       DELETE FROM t1_data WHERE rowid = fts5_rowid('segment', $segid, 4);
    47     48     }
    48     49     catchsql { INSERT INTO t1(t1) VALUES('integrity-check') }
    49     50   } {1 {database disk image is malformed}}
    50     51   
    51     52   do_test 1.4 {
    52     53     db_restore_and_reopen
           54  +  sqlite3_db_config db DEFENSIVE 0
    53     55     execsql {
    54     56       UPDATE t1_data set block = X'00000000' || substr(block, 5) WHERE
    55     57       rowid = fts5_rowid('segment', $segid, 4);
    56     58     }
    57     59     catchsql { INSERT INTO t1(t1) VALUES('integrity-check') }
    58     60   } {1 {database disk image is malformed}}
    59     61   
................................................................................
    85     87     INSERT INTO t3 VALUES('three o');
    86     88     INSERT INTO t3 VALUES('four e');
    87     89     INSERT INTO t3 VALUES('five o');
    88     90   }
    89     91   do_execsql_test 3.1 {
    90     92     SELECT * FROM t3 WHERE t3 MATCH 'o'
    91     93   } {{one o} {three o} {five o}}
    92         -
           94  +sqlite3_db_config db DEFENSIVE 0
    93     95   do_catchsql_test 3.1 {
    94     96     DELETE FROM t3_content WHERE rowid = 3;
    95     97     SELECT * FROM t3 WHERE t3 MATCH 'o';
    96     98   } {1 {database disk image is malformed}}
    97     99   
    98    100   finish_test

Changes to ext/fts5/test/fts5corrupt2.test.

    95     95   # Also tested is that "MATCH 'x*'" does not crash and sometimes reports
    96     96   # corruption. It may not report the db as corrupt because truncating the
    97     97   # final leaf to some sizes may create a valid leaf page.
    98     98   #
    99     99   set lrowid [db one {SELECT max(rowid) FROM t1_data WHERE (rowid & $mask)=0}] 
   100    100   set nbyte [db one {SELECT length(block) FROM t1_data WHERE rowid=$lrowid}]
   101    101   set all [db eval {SELECT rowid FROM t1}]
          102  +sqlite3_db_config db DEFENSIVE 0
   102    103   for {set i [expr $nbyte-2]} {$i>=0} {incr i -1} {
   103    104     do_execsql_test 2.$i.1 {
   104    105       BEGIN;
   105    106         UPDATE t1_data SET block = substr(block, 1, $i) WHERE rowid=$lrowid;
   106    107     }
   107    108   
   108    109     do_catchsql_test 2.$i.2 {
................................................................................
   244    245   
   245    246       execsql ROLLBACK
   246    247     }
   247    248   }
   248    249   
   249    250   #--------------------------------------------------------------------
   250    251   reset_db
          252  +sqlite3_db_config db DEFENSIVE 0
   251    253   do_execsql_test 6.1 {
   252    254     CREATE VIRTUAL TABLE x5 USING fts5(tt);
   253    255     INSERT INTO x5 VALUES('a');
   254    256     INSERT INTO x5 VALUES('a a');
   255    257     INSERT INTO x5 VALUES('a a a');
   256    258     INSERT INTO x5 VALUES('a a a a');
   257    259   

Changes to ext/fts5/test/fts5corrupt3.test.

    47     47     set rowid [db one {
    48     48       SELECT max(rowid) FROM t1_data WHERE ((rowid>>31) & 0x0F)==1
    49     49     }]
    50     50     set L [db one {SELECT length(block) FROM t1_data WHERE rowid = $rowid}]
    51     51     set {} {}
    52     52   } {} 
    53     53   
           54  +sqlite3_db_config db DEFENSIVE 0
    54     55   for {set i 0} {$i < $L} {incr i} {
    55     56     do_test 1.2.$i {
    56     57       catchsql {
    57     58         BEGIN;
    58     59         UPDATE t1_data SET block = substr(block, 1, $i) WHERE id = $rowid;
    59     60         INSERT INTO t1(t1) VALUES('integrity-check');
    60     61       }
................................................................................
    82     83   
    83     84   
    84     85   #-------------------------------------------------------------------------
    85     86   # Test that missing leaf pages are recognized as corruption.
    86     87   #
    87     88   reset_db
    88     89   do_test 3.0 { create_t1 } {}
           90  +sqlite3_db_config db DEFENSIVE 0
    89     91   
    90     92   do_execsql_test 3.1 {
    91     93     SELECT count(*) FROM t1_data;
    92     94   } {105}
    93     95   
    94     96   proc do_3_test {tn} {
    95     97     set i 0
................................................................................
   154    156   
   155    157   do_3_test 3.10
   156    158   
   157    159   #-------------------------------------------------------------------------
   158    160   # Test that segments that end unexpectedly are identified as corruption.
   159    161   #
   160    162   reset_db
          163  +sqlite3_db_config db DEFENSIVE 0
   161    164   do_test 4.0 {
   162    165     execsql { 
   163    166       CREATE VIRTUAL TABLE t1 USING fts5(x);
   164    167       INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
   165    168     }
   166    169     for {set i 0} {$i < 100} {incr i} {
   167    170       set rnd [expr int(rand() * 100)]
................................................................................
   178    181     set end [lindex $var end]
   179    182     if {$end<=$i} break
   180    183     lset var end [expr $end - $i]
   181    184     set struct [binary format c* $var]
   182    185   
   183    186     db close
   184    187     sqlite3 db test.db
          188  +  sqlite3_db_config db DEFENSIVE 0
   185    189   
   186    190     db eval {
   187    191       BEGIN;
   188    192       UPDATE t1_data SET block = $struct WHERE id=10;
   189    193     }
   190    194     do_test 4.1.$i {
   191    195       incr nErr [catch { db eval { SELECT rowid FROM t1 WHERE t1 MATCH 'x*' } }]
................................................................................
   253    257       catch { db eval ROLLBACK }
   254    258     }
   255    259   }
   256    260   
   257    261   #------------------------------------------------------------------------
   258    262   #
   259    263   reset_db
          264  +sqlite3_db_config db DEFENSIVE 0
   260    265   do_execsql_test 6.1.0 {
   261    266     CREATE VIRTUAL TABLE t1 USING fts5(a);
   262    267     INSERT INTO t1 VALUES('bbbbb ccccc');
   263    268     SELECT quote(block) FROM t1_data WHERE rowid>100;
   264    269   } {X'000000180630626262626201020201056363636363010203040A'}
   265    270   do_execsql_test 6.1.1 {
   266    271     UPDATE t1_data SET block = 
................................................................................
   269    274   }
   270    275   do_catchsql_test 6.1.2 {
   271    276     INSERT INTO t1(t1) VALUES('integrity-check');
   272    277   } {1 {database disk image is malformed}}
   273    278   
   274    279   #-------
   275    280   reset_db
          281  +sqlite3_db_config db DEFENSIVE 0
   276    282   do_execsql_test 6.2.0 {
   277    283     CREATE VIRTUAL TABLE t1 USING fts5(a);
   278    284     INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
   279    285     INSERT INTO t1 VALUES('aa bb cc dd ee');
   280    286     SELECT pgno, quote(term) FROM t1_idx;
   281    287   } {2 X'' 4 X'3064'}
   282    288   do_execsql_test 6.2.1 {
................................................................................
   284    290   }
   285    291   do_catchsql_test 6.2.2 {
   286    292     INSERT INTO t1(t1) VALUES('integrity-check');
   287    293   } {1 {database disk image is malformed}}
   288    294   
   289    295   #-------
   290    296   reset_db
          297  +sqlite3_db_config db DEFENSIVE 0
   291    298   do_execsql_test 6.3.0 {
   292    299     CREATE VIRTUAL TABLE t1 USING fts5(a);
   293    300     INSERT INTO t1 VALUES('abc abcdef abcdefghi');
   294    301     SELECT quote(block) FROM t1_data WHERE id>100;
   295    302   }    {X'0000001C043061626301020204036465660102030703676869010204040808'}
   296    303   do_execsql_test 6.3.1 {
   297    304     BEGIN;
................................................................................
   358    365       INSERT INTO t5 VALUES( rnddoc(10000) );
   359    366       INSERT INTO t5 VALUES( rnddoc(10000) );
   360    367       INSERT INTO t5 VALUES( rnddoc(10000) );
   361    368       INSERT INTO t5(t5) VALUES('optimize');
   362    369     }
   363    370   } {}
   364    371   
          372  +sqlite3_db_config db DEFENSIVE 0
   365    373   do_test 7.1 {
   366    374     foreach i [db eval { SELECT rowid FROM t5_data WHERE rowid>100 }] {
   367    375       db eval BEGIN  
   368    376       db eval {DELETE FROM t5_data WHERE rowid = $i}
   369    377       set r [catchsql { INSERT INTO t5(t5) VALUES('integrity-check')} ]
   370    378       if {$r != "1 {database disk image is malformed}"} { error $r }
   371    379       db eval ROLLBACK  
................................................................................
   379    387   #
   380    388   reset_db
   381    389   do_execsql_test 8.1 {
   382    390     CREATE VIRTUAL TABLE t1 USING fts5(x, y);
   383    391     INSERT INTO t1 VALUES('one', 'two');
   384    392   }
   385    393   
          394  +sqlite3_db_config db DEFENSIVE 0
   386    395   do_test 9.1.1 {
   387    396     set    blob "12345678"    ;# cookie
   388    397     append blob "0105"        ;# 1 level, total of 5 segments
   389    398     append blob "06"          ;# write counter
   390    399     append blob "0002"        ;# first level has 0 segments merging, 2 other.
   391    400     append blob "450108"      ;# first segment
   392    401     execsql "REPLACE INTO t1_data VALUES(10, X'$blob')"

Changes to ext/fts5/test/fts5first.test.

    89     89     SELECT * FROM x2('a + b');
    90     90   } {1 {fts5: phrase queries are not supported (detail!=full)}}
    91     91   
    92     92   do_catchsql_test 3.3 {
    93     93     SELECT * FROM x2('^a');
    94     94   } {1 {fts5: phrase queries are not supported (detail!=full)}}
    95     95   finish_test
    96         -

Changes to ext/fts5/test/fts5integrity.test.

    67     67     INSERT INTO aa(zz) VALUES('a');
    68     68     SELECT length(sz) FROM aa_docsize;
    69     69   } {1 1 1 1 1}
    70     70   do_execsql_test 4.1 { 
    71     71     INSERT INTO aa(aa) VALUES('integrity-check'); 
    72     72   }
    73     73   
           74  +sqlite3_db_config db DEFENSIVE 0
    74     75   do_catchsql_test 4.2 { 
    75     76     BEGIN;
    76     77       UPDATE aa_docsize SET sz = X'44' WHERE rowid = 3;
    77     78       INSERT INTO aa(aa) VALUES('integrity-check'); 
    78     79   } {1 {database disk image is malformed}}
    79     80   
    80     81   do_catchsql_test 4.3 { 

Changes to ext/fts5/test/fts5rank.test.

   159    159   }
   160    160   
   161    161   do_execsql_test 5.1 {
   162    162     SELECT rowid FROM ttt('word') WHERE rowid BETWEEN 30 AND 40 ORDER BY rank;
   163    163   } {30 31 32 33 34 35 36 37 38 39 40}
   164    164   
   165    165   finish_test
   166         -

Changes to ext/fts5/test/fts5rebuild.test.

    35     35     INSERT INTO f1(f1) VALUES('rebuild');
    36     36   } {}
    37     37   
    38     38   do_execsql_test 1.4 {
    39     39     INSERT INTO f1(f1) VALUES('integrity-check');
    40     40   } {}
    41     41   
           42  +sqlite3_db_config db DEFENSIVE 0
    42     43   do_execsql_test 1.5 {
    43     44     DELETE FROM f1_data;
    44     45   } {}
    45     46   
    46     47   do_catchsql_test 1.6 {
    47     48     INSERT INTO f1(f1) VALUES('integrity-check');
    48     49   } {1 {database disk image is malformed}}

Changes to ext/fts5/test/fts5rowid.test.

    66     66     DELETE FROM x1 WHERE (rowid%2);
    67     67   }
    68     68   
    69     69   set res [db one {SELECT count(*) FROM x1_data}]
    70     70   do_execsql_test 2.3 {
    71     71     SELECT count(fts5_decode(rowid, block)) FROM x1_data;
    72     72   } $res
           73  +sqlite3_db_config db DEFENSIVE 0
    73     74   do_execsql_test 2.4 {
    74     75     UPDATE x1_data SET block = X'';
    75     76     SELECT count(fts5_decode(rowid, block)) FROM x1_data;
    76     77   } $res
    77     78   
    78     79   do_execsql_test 2.5 {
    79     80     INSERT INTO x1(x1, rank) VALUES('pgsz', 1024);

Changes to ext/fts5/test/fts5version.test.

    32     32     SELECT * FROM t1_config WHERE k='version'
    33     33   } {version 4}
    34     34   
    35     35   do_execsql_test 1.3 {
    36     36     SELECT rowid FROM t1 WHERE t1 MATCH 'a';
    37     37   } {1}
    38     38   
           39  +sqlite3_db_config db DEFENSIVE 0
    39     40   do_execsql_test 1.4 {
    40     41     UPDATE t1_config set v=5 WHERE k='version';
    41         -} 
           42  +}
    42     43   
    43     44   do_test 1.5 {
    44     45     db close
    45     46     sqlite3 db test.db
    46     47     catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' }
    47     48   } {1 {invalid fts5 file format (found 5, expected 4) - run 'rebuild'}}
    48     49   
................................................................................
    49     50   do_test 1.6 {
    50     51     db close
    51     52     sqlite3 db test.db
    52     53     catchsql { INSERT INTO t1 VALUES('x y z') }
    53     54   } {1 {invalid fts5 file format (found 5, expected 4) - run 'rebuild'}}
    54     55   
    55     56   do_test 1.7 {
           57  +  sqlite3_db_config db DEFENSIVE 0
    56     58     execsql { DELETE FROM t1_config WHERE k='version' }
    57     59     db close
    58     60     sqlite3 db test.db
    59     61     catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' }
    60     62   } {1 {invalid fts5 file format (found 0, expected 4) - run 'rebuild'}}
    61     63   
    62     64   
    63     65   finish_test

Changes to ext/fts5/test/fts5vocab.test.

   416    416     i a 1 1 i b 1 1 i c 1 1
   417    417   }]
   418    418   if {[detail_is_none]} { set resc [row_to_col $resr] }
   419    419   
   420    420   do_execsql_test 8.1.1 { SELECT * FROM x1_r; } $resr
   421    421   do_execsql_test 8.1.2 { SELECT * FROM x1_c } $resc
   422    422   
          423  +sqlite3_db_config db DEFENSIVE 0
   423    424   do_execsql_test 8.2 {
   424    425     PRAGMA writable_schema = 1;
   425    426     UPDATE sqlite_master 
   426    427     SET sql = 'CREATE VIRTUAL TABLE x1 USING fts5(a, detail=%DETAIL%)'
   427    428     WHERE name = 'x1';
   428    429   }
   429    430   db close
................................................................................
   477    478     set e2 [db eval { EXPLAIN SELECT * FROM rrr ORDER BY term DESC }]
   478    479     expr [lsearch $e2 SorterSort]<0
   479    480   } 0
   480    481   
   481    482   
   482    483   
   483    484   finish_test
   484         -

Changes to ext/fts5/test/fts5vocab2.test.

   202    202   do_execsql_test 3.5 {
   203    203     DELETE FROM t1;
   204    204     SELECT * FROM v1;
   205    205   } {
   206    206   }
   207    207   
   208    208   finish_test
   209         -

Changes to ext/misc/amatch.c.

  1469   1469     0,                      /* xSync */
  1470   1470     0,                      /* xCommit */
  1471   1471     0,                      /* xRollback */
  1472   1472     0,                      /* xFindMethod */
  1473   1473     0,                      /* xRename */
  1474   1474     0,                      /* xSavepoint */
  1475   1475     0,                      /* xRelease */
  1476         -  0                       /* xRollbackTo */
         1476  +  0,                      /* xRollbackTo */
         1477  +  0                       /* xShadowName */
  1477   1478   };
  1478   1479   
  1479   1480   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  1480   1481   
  1481   1482   /*
  1482   1483   ** Register the amatch virtual table
  1483   1484   */

Changes to ext/misc/btreeinfo.c.

   407    407       0,                           /* xCommit */
   408    408       0,                           /* xRollback */
   409    409       0,                           /* xFindMethod */
   410    410       0,                           /* xRename */
   411    411       0,                           /* xSavepoint */
   412    412       0,                           /* xRelease */
   413    413       0,                           /* xRollbackTo */
          414  +    0                            /* xShadowName */
   414    415     };
   415    416     return sqlite3_create_module(db, "sqlite_btreeinfo", &binfo_module, 0);
   416    417   }
   417    418   
   418    419   #ifdef _WIN32
   419    420   __declspec(dllexport)
   420    421   #endif

Changes to ext/misc/closure.c.

   934    934     0,                      /* xSync */
   935    935     0,                      /* xCommit */
   936    936     0,                      /* xRollback */
   937    937     0,                      /* xFindMethod */
   938    938     0,                      /* xRename */
   939    939     0,                      /* xSavepoint */
   940    940     0,                      /* xRelease */
   941         -  0                       /* xRollbackTo */
          941  +  0,                      /* xRollbackTo */
          942  +  0                       /* xShadowName */
   942    943   };
   943    944   
   944    945   #endif /* SQLITE_OMIT_VIRTUALTABLE */
   945    946   
   946    947   /*
   947    948   ** Register the closure virtual table
   948    949   */

Changes to ext/misc/completion.c.

   464    464     0,                         /* xSync */
   465    465     0,                         /* xCommit */
   466    466     0,                         /* xRollback */
   467    467     0,                         /* xFindMethod */
   468    468     0,                         /* xRename */
   469    469     0,                         /* xSavepoint */
   470    470     0,                         /* xRelease */
   471         -  0                          /* xRollbackTo */
          471  +  0,                         /* xRollbackTo */
          472  +  0                          /* xShadowName */
   472    473   };
   473    474   
   474    475   #endif /* SQLITE_OMIT_VIRTUALTABLE */
   475    476   
   476    477   int sqlite3CompletionVtabInit(sqlite3 *db){
   477    478     int rc = SQLITE_OK;
   478    479   #ifndef SQLITE_OMIT_VIRTUALTABLE

Changes to ext/misc/explain.c.

   276    276     0,                         /* xCommit */
   277    277     0,                         /* xRollback */
   278    278     0,                         /* xFindMethod */
   279    279     0,                         /* xRename */
   280    280     0,                         /* xSavepoint */
   281    281     0,                         /* xRelease */
   282    282     0,                         /* xRollbackTo */
          283  +  0,                         /* xShadowName */
   283    284   };
   284    285   
   285    286   #endif /* SQLITE_OMIT_VIRTUALTABLE */
   286    287   
   287    288   int sqlite3ExplainVtabInit(sqlite3 *db){
   288    289     int rc = SQLITE_OK;
   289    290   #ifndef SQLITE_OMIT_VIRTUALTABLE

Changes to ext/misc/fileio.c.

   884    884       0,                         /* xSync */
   885    885       0,                         /* xCommit */
   886    886       0,                         /* xRollback */
   887    887       0,                         /* xFindMethod */
   888    888       0,                         /* xRename */
   889    889       0,                         /* xSavepoint */
   890    890       0,                         /* xRelease */
   891         -    0                          /* xRollbackTo */
          891  +    0,                         /* xRollbackTo */
          892  +    0,                         /* xShadowName */
   892    893     };
   893    894   
   894    895     int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
   895    896     return rc;
   896    897   }
   897    898   #else         /* SQLITE_OMIT_VIRTUALTABLE */
   898    899   # define fsdirRegister(x) SQLITE_OK

Changes to ext/misc/json1.c.

  2384   2384     0,                         /* xSync */
  2385   2385     0,                         /* xCommit */
  2386   2386     0,                         /* xRollback */
  2387   2387     0,                         /* xFindMethod */
  2388   2388     0,                         /* xRename */
  2389   2389     0,                         /* xSavepoint */
  2390   2390     0,                         /* xRelease */
  2391         -  0                          /* xRollbackTo */
         2391  +  0,                         /* xRollbackTo */
         2392  +  0                          /* xShadowName */
  2392   2393   };
  2393   2394   
  2394   2395   /* The methods of the json_tree virtual table. */
  2395   2396   static sqlite3_module jsonTreeModule = {
  2396   2397     0,                         /* iVersion */
  2397   2398     0,                         /* xCreate */
  2398   2399     jsonEachConnect,           /* xConnect */
................................................................................
  2411   2412     0,                         /* xSync */
  2412   2413     0,                         /* xCommit */
  2413   2414     0,                         /* xRollback */
  2414   2415     0,                         /* xFindMethod */
  2415   2416     0,                         /* xRename */
  2416   2417     0,                         /* xSavepoint */
  2417   2418     0,                         /* xRelease */
  2418         -  0                          /* xRollbackTo */
         2419  +  0,                         /* xRollbackTo */
         2420  +  0                          /* xShadowName */
  2419   2421   };
  2420   2422   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  2421   2423   
  2422   2424   /****************************************************************************
  2423   2425   ** The following routines are the only publically visible identifiers in this
  2424   2426   ** file.  Call the following routines in order to register the various SQL
  2425   2427   ** functions and the virtual table implemented by this file.

Changes to ext/misc/memstat.c.

   391    391     0,                         /* xCommit */
   392    392     0,                         /* xRollback */
   393    393     0,                         /* xFindMethod */
   394    394     0,                         /* xRename */
   395    395     0,                         /* xSavepoint */
   396    396     0,                         /* xRelease */
   397    397     0,                         /* xRollbackTo */
          398  +  0,                         /* xShadowName */
   398    399   };
   399    400   
   400    401   #endif /* SQLITE_OMIT_VIRTUALTABLE */
   401    402   
   402    403   int sqlite3MemstatVtabInit(sqlite3 *db){
   403    404     int rc = SQLITE_OK;
   404    405   #ifndef SQLITE_OMIT_VIRTUALTABLE

Changes to ext/misc/stmt.c.

   262    262     0,                         /* xCommit */
   263    263     0,                         /* xRollback */
   264    264     0,                         /* xFindMethod */
   265    265     0,                         /* xRename */
   266    266     0,                         /* xSavepoint */
   267    267     0,                         /* xRelease */
   268    268     0,                         /* xRollbackTo */
          269  +  0,                         /* xShadowName */
   269    270   };
   270    271   
   271    272   #endif /* SQLITE_OMIT_VIRTUALTABLE */
   272    273   
   273    274   int sqlite3StmtVtabInit(sqlite3 *db){
   274    275     int rc = SQLITE_OK;
   275    276   #ifndef SQLITE_OMIT_VIRTUALTABLE

Changes to ext/misc/templatevtab.c.

   244    244     /* xSync       */ 0,
   245    245     /* xCommit     */ 0,
   246    246     /* xRollback   */ 0,
   247    247     /* xFindMethod */ 0,
   248    248     /* xRename     */ 0,
   249    249     /* xSavepoint  */ 0,
   250    250     /* xRelease    */ 0,
   251         -  /* xRollbackTo */ 0
          251  +  /* xRollbackTo */ 0,
          252  +  /* xShadowName */ 0
   252    253   };
   253    254   
   254    255   
   255    256   #ifdef _WIN32
   256    257   __declspec(dllexport)
   257    258   #endif
   258    259   int sqlite3_templatevtab_init(

Changes to ext/misc/unionvtab.c.

  1346   1346       0,                            /* xSync */
  1347   1347       0,                            /* xCommit */
  1348   1348       0,                            /* xRollback */
  1349   1349       0,                            /* xFindMethod */
  1350   1350       0,                            /* xRename */
  1351   1351       0,                            /* xSavepoint */
  1352   1352       0,                            /* xRelease */
  1353         -    0                             /* xRollbackTo */
         1353  +    0,                            /* xRollbackTo */
         1354  +    0                             /* xShadowName */
  1354   1355     };
  1355   1356     int rc;
  1356   1357   
  1357   1358     rc = sqlite3_create_module(db, "unionvtab", &unionModule, 0);
  1358   1359     if( rc==SQLITE_OK ){
  1359   1360       rc = sqlite3_create_module(db, "swarmvtab", &unionModule, (void*)db);
  1360   1361     }

Changes to ext/misc/vtablog.c.

   488    488     0,                         /* xCommit */
   489    489     0,                         /* xRollback */
   490    490     0,                         /* xFindMethod */
   491    491     0,                         /* xRename */
   492    492     0,                         /* xSavepoint */
   493    493     0,                         /* xRelease */
   494    494     0,                         /* xRollbackTo */
          495  +  0,                         /* xShadowName */
   495    496   };
   496    497   
   497    498   #ifdef _WIN32
   498    499   __declspec(dllexport)
   499    500   #endif
   500    501   int sqlite3_vtablog_init(
   501    502     sqlite3 *db, 

Changes to ext/rbu/rbu1.test.

   666    666   
   667    667     catch { db close }
   668    668     eval $destroy_vfs
   669    669   }
   670    670   
   671    671   
   672    672   finish_test
   673         -

Changes to ext/rbu/rbu10.test.

   181    181       INSERT INTO data_t3 VALUES(1, 'abc', '-6.0', 0);
   182    182     }
   183    183     list [catch { apply_rbu $rbu } msg] $msg
   184    184   } {0 SQLITE_DONE}
   185    185   
   186    186   
   187    187   finish_test
   188         -

Changes to ext/rbu/rbu11.test.

   191    191     rbu step
   192    192   } {SQLITE_ERROR}
   193    193   do_test 4.7.2 {
   194    194     list [catch {rbu close} msg] $msg
   195    195   } {1 {SQLITE_ERROR - rbu_state mismatch error}}
   196    196   
   197    197   finish_test
   198         -

Changes to ext/rbu/rbu12.test.

   228    228     do_test 2.$tn.6 {
   229    229       list [sql1 {PRAGMA data_version}] [sql2 {PRAGMA data_version}]
   230    230     } [list $V1 $V2]
   231    231   
   232    232   }
   233    233   
   234    234   finish_test
   235         -

Changes to ext/rbu/rbu13.test.

    58     58   do_execsql_test 1.4 {
    59     59     SELECT count(*) FROM t1 WHERE
    60     60     a == ( (b<<6) + (c<<5) + (d<<4) + (e<<3) + (f<<2) + (g<<1) + (h<<0) )
    61     61   } {128}
    62     62   
    63     63   
    64     64   finish_test
    65         -

Changes to ext/rbu/rbu14.test.

    88     88     } {4 5 6 50 50 50}
    89     89   
    90     90     integrity_check $tn.4
    91     91   }
    92     92   
    93     93   
    94     94   finish_test
    95         -

Changes to ext/rbu/rbu3.test.

   199    199   do_test 5.3 {
   200    200     expr {[file size test.db-wal] > (1024 * 1200)}
   201    201   } 1
   202    202   
   203    203   do_test 6.1 { sqlite3rbu_internal_test } {}
   204    204   
   205    205   finish_test
   206         -
   207         -

Changes to ext/rbu/rbu5.test.

   296    296   
   297    297       db close
   298    298     }
   299    299   }
   300    300   
   301    301   
   302    302   finish_test
   303         -
   304         -
   305         -
   306         -

Changes to ext/rbu/rbu6.test.

    96     96     do_execsql_test 1.$nStep.5 {
    97     97       SELECT * FROM t1;
    98     98     } {1 t1 5 hello}
    99     99   }
   100    100   
   101    101   
   102    102   finish_test
   103         -

Changes to ext/rbu/rbu7.test.

   102    102       2 2 d
   103    103       3 1 e
   104    104       3 2 f
   105    105     }
   106    106   }
   107    107   
   108    108   finish_test
   109         -
   110         -

Changes to ext/rbu/rbu8.test.

    68     68     {}   2 2
    69     69     _iii 3 three-III
    70     70   }
    71     71   integrity_check 1.3.3
    72     72   
    73     73   
    74     74   finish_test
    75         -

Changes to ext/rbu/rbu9.test.

   121    121     }
   122    122     
   123    123     integrity_check 2.$tn.4
   124    124   }
   125    125   
   126    126   
   127    127   finish_test
   128         -

Changes to ext/rbu/rbuA.test.

    76     76   
    77     77   do_test 2.2 {
    78     78     list [catch { rbu close } msg] $msg
    79     79   } {1 {SQLITE_ERROR - cannot update wal mode database}}
    80     80   
    81     81   
    82     82   finish_test
    83         -

Changes to ext/rbu/rbuB.test.

    55     55   } {1 2 3 4 5 6 7 8 9}
    56     56   
    57     57   db close
    58     58   sqlite3_shutdown
    59     59   test_sqlite3_log 
    60     60   sqlite3_initialize
    61     61   finish_test
    62         -

Changes to ext/rbu/rbuC.test.

   135    135     
   136    136     integrity_check 3.$tn.4
   137    137   }
   138    138   
   139    139   
   140    140   
   141    141   finish_test
   142         -

Changes to ext/rbu/rbucollate.test.

    56     56     }
    57     57     rbu close
    58     58     db eval { SELECT * FROM t1 }
    59     59   } {a one 1 b two 2 c three 3}
    60     60   
    61     61   #forcedelete testrbu.db
    62     62   finish_test
    63         -

Changes to ext/rbu/rbucrash.test.

   141    141   for {set nPre 0} {$nPre < $rbu_num_steps} {incr nPre} {
   142    142     for {set is 1} {$is <= ($rbu_num_steps - $nPre)} {incr is} {
   143    143       do_rbu_crash_test 2.pre=$nPre.step=$is $nPre $is
   144    144     }
   145    145   }
   146    146   
   147    147   finish_test
   148         -

Changes to ext/rbu/rbucrash2.test.

    99     99         sqlite3rbu rbu test.db test.db2
   100    100       }
   101    101       rbu close
   102    102     }
   103    103   }
   104    104   
   105    105   finish_test
   106         -

Changes to ext/rbu/rbudiff.test.

   296    296       db close
   297    297       db2 close
   298    298     }
   299    299   }
   300    300   
   301    301   
   302    302   finish_test
   303         -

Changes to ext/rbu/rbudor.test.

    52     52   } {SQLITE_DONE}
    53     53   
    54     54   do_execsql_test 1.4 {
    55     55     SELECT * FROM t1 
    56     56   } [list 1 $bigA 2 $bigB]
    57     57   
    58     58   finish_test
    59         -

Changes to ext/rbu/rbufault.test.

   230    230           }
   231    231         }
   232    232       }
   233    233     }
   234    234   }
   235    235   
   236    236   finish_test
   237         -

Changes to ext/rbu/rbufault2.test.

    51     51         {1 {SQLITE_NOMEM - out of memory}} 
    52     52   }
    53     53   
    54     54   
    55     55   
    56     56   
    57     57   finish_test
    58         -

Changes to ext/rbu/rbufault3.test.

    91     91     } -test {
    92     92       eval [list faultsim_test_result {0 SQLITE_OK} {*}$::errlist]
    93     93     }
    94     94   
    95     95   }
    96     96   
    97     97   finish_test
    98         -

Changes to ext/rbu/rbufault4.test.

    59     59       if {$rc!="ok"} { error "Got $rc instead of ok!" }
    60     60     }
    61     61   }
    62     62   
    63     63   
    64     64   
    65     65   finish_test
    66         -

Changes to ext/rbu/rbufts.test.

   127    127       INSERT INTO data_ft VALUES('7 8 9', 1, 'x');
   128    128     } } msg] $msg]
   129    129   } {1 {SQLITE_ERROR - SQL logic error]}}
   130    130   
   131    131   
   132    132   
   133    133   finish_test
   134         -

Changes to ext/rbu/rbumulti.test.

   168    168       sqlite3rbu_destroy_vfs myrbu
   169    169     }
   170    170   
   171    171   }
   172    172   
   173    173   
   174    174   finish_test
   175         -

Changes to ext/rbu/rbuprogress.test.

   412    412         do_sp_test 5.$tn.$bReopen.$tn2.1 $bReopen test.db rbu.db $R($tn)
   413    413       }
   414    414     }
   415    415   }
   416    416   
   417    417   
   418    418   finish_test
   419         -

Changes to ext/rbu/rburesume.test.

   247    247         PRAGMA integrity_check;
   248    248       }
   249    249     } {60 ok}
   250    250     db2 close
   251    251   }
   252    252   
   253    253   finish_test
   254         -

Changes to ext/rbu/rbusave.test.

    98     98   
    99     99   do_execsql_test 1.5 {
   100    100     SELECT * FROM t1;
   101    101     SELECT * FROM t2;
   102    102   } {1 one 1 3 3 3 4 4 4 1 one 1 3 3 3 4 4 4}
   103    103   
   104    104   finish_test
   105         -

Changes to ext/rbu/rbusplit.test.

    88     88       1 1 1 2 2 2 3 3 3 4 4 4
    89     89       5 5 5 6 6 6 7 7 7 8 8 8
    90     90       9 9 9
    91     91     }
    92     92   }
    93     93   
    94     94   finish_test
    95         -

Changes to ext/rbu/rbutemplimit.test.

   122    122     setup_databases
   123    123     unset -nocomplain ::A
   124    124     step_rbu_cachesize test.db test.db2 1000 10 1400000
   125    125   } {1 SQLITE_FULL}
   126    126   do_test 1.6.2 { info commands rbu } {}
   127    127   
   128    128   finish_test
   129         -

Changes to ext/rbu/rbuvacuum.test.

   393    393   
   394    394     while {[rbu step]=="SQLITE_OK"} {}
   395    395     list [catch { rbu close } msg] $msg
   396    396   } {0 SQLITE_DONE}
   397    397   
   398    398   catch { db close }
   399    399   finish_test
   400         -

Changes to ext/rbu/rbuvacuum2.test.

   228    228     sqlite3rbu_vacuum rbu test.db test.db2
   229    229     while {[rbu step]!="SQLITE_DONE"} { rbu step }
   230    230     rbu close
   231    231     execsql { PRAGMA integrity_check }
   232    232   } {ok}
   233    233   
   234    234   finish_test
   235         -

Changes to ext/repair/test/checkindex01.test.

   343    343   }
   344    344   do_index_check_test 7.3 t7i3 {
   345    345     {} 1,1 {} 3,3
   346    346   }
   347    347   do_index_check_test 7.4 t7i4 {
   348    348     {} 1,1 {} 3,3
   349    349   }
   350         -
   351         -

Changes to ext/rtree/geopoly.c.

  1721   1721       return SQLITE_INDEX_CONSTRAINT_FUNCTION+1;
  1722   1722     }
  1723   1723     return 0;
  1724   1724   }
  1725   1725   
  1726   1726   
  1727   1727   static sqlite3_module geopolyModule = {
  1728         -  2,                          /* iVersion */
         1728  +  3,                          /* iVersion */
  1729   1729     geopolyCreate,              /* xCreate - create a table */
  1730   1730     geopolyConnect,             /* xConnect - connect to an existing table */
  1731   1731     geopolyBestIndex,           /* xBestIndex - Determine search strategy */
  1732   1732     rtreeDisconnect,            /* xDisconnect - Disconnect from a table */
  1733   1733     rtreeDestroy,               /* xDestroy - Drop a table */
  1734   1734     rtreeOpen,                  /* xOpen - open a cursor */
  1735   1735     rtreeClose,                 /* xClose - close a cursor */
................................................................................
  1744   1744     rtreeEndTransaction,        /* xCommit - commit transaction */
  1745   1745     rtreeEndTransaction,        /* xRollback - rollback transaction */
  1746   1746     geopolyFindFunction,        /* xFindFunction - function overloading */
  1747   1747     rtreeRename,                /* xRename - rename the table */
  1748   1748     rtreeSavepoint,             /* xSavepoint */
  1749   1749     0,                          /* xRelease */
  1750   1750     0,                          /* xRollbackTo */
         1751  +  rtreeShadowName             /* xShadowName */
  1751   1752   };
  1752   1753   
  1753   1754   static int sqlite3_geopoly_init(sqlite3 *db){
  1754   1755     int rc = SQLITE_OK;
  1755   1756     static const struct {
  1756   1757       void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
  1757   1758       signed char nArg;

Changes to ext/rtree/rtree.c.

  3321   3321       }
  3322   3322       sqlite3_free(zSql);
  3323   3323     }
  3324   3324   
  3325   3325     return rc;
  3326   3326   }
  3327   3327   
         3328  +
         3329  +/*
         3330  +** Return true if zName is the extension on one of the shadow tables used
         3331  +** by this module.
         3332  +*/
         3333  +static int rtreeShadowName(const char *zName){
         3334  +  static const char *azName[] = {
         3335  +    "node", "parent", "rowid"
         3336  +  };
         3337  +  unsigned int i;
         3338  +  for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
         3339  +    if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
         3340  +  }
         3341  +  return 0;
         3342  +}
         3343  +
  3328   3344   static sqlite3_module rtreeModule = {
  3329         -  2,                          /* iVersion */
         3345  +  3,                          /* iVersion */
  3330   3346     rtreeCreate,                /* xCreate - create a table */
  3331   3347     rtreeConnect,               /* xConnect - connect to an existing table */
  3332   3348     rtreeBestIndex,             /* xBestIndex - Determine search strategy */
  3333   3349     rtreeDisconnect,            /* xDisconnect - Disconnect from a table */
  3334   3350     rtreeDestroy,               /* xDestroy - Drop a table */
  3335   3351     rtreeOpen,                  /* xOpen - open a cursor */
  3336   3352     rtreeClose,                 /* xClose - close a cursor */
................................................................................
  3345   3361     rtreeEndTransaction,        /* xCommit - commit transaction */
  3346   3362     rtreeEndTransaction,        /* xRollback - rollback transaction */
  3347   3363     0,                          /* xFindFunction - function overloading */
  3348   3364     rtreeRename,                /* xRename - rename the table */
  3349   3365     rtreeSavepoint,             /* xSavepoint */
  3350   3366     0,                          /* xRelease */
  3351   3367     0,                          /* xRollbackTo */
         3368  +  rtreeShadowName             /* xShadowName */
  3352   3369   };
  3353   3370   
  3354   3371   static int rtreeSqlInit(
  3355   3372     Rtree *pRtree, 
  3356   3373     sqlite3 *db, 
  3357   3374     const char *zDb, 
  3358   3375     const char *zPrefix, 

Changes to ext/rtree/rtree8.test.

    97     97   # The following block of tests - rtree8-2.* - test a couple of database
    98     98   # corruption cases. In this case things are not corrupted at the b-tree
    99     99   # level, but the contents of the various tables used internally by an
   100    100   # r-tree table are inconsistent.
   101    101   #
   102    102   populate_t1 50
   103    103   do_execsql_test rtree8-2.1.1 { SELECT max(nodeno) FROM t1_node } {5}
          104  +sqlite3_db_config db DEFENSIVE 0
   104    105   do_execsql_test rtree8-2.1.2 { DELETE FROM t1_node } {}
   105    106   for {set i 1} {$i <= 50} {incr i} {
   106    107     do_catchsql_test rtree8-2.1.3.$i { 
   107    108       SELECT * FROM t1 WHERE id = $i 
   108    109     } {1 {database disk image is malformed}}
   109    110   }
   110    111   do_catchsql_test rtree8-2.1.4 { 
................................................................................
   117    118   do_execsql_test rtree8-2.1.6 { 
   118    119     DROP TABLE t1;
   119    120     CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
   120    121   } {}
   121    122   
   122    123   
   123    124   populate_t1 50
          125  +sqlite3_db_config db DEFENSIVE 0
   124    126   do_execsql_test rtree8-2.2.1 {
   125    127     DELETE FROM t1_parent
   126    128   } {}
   127    129   do_catchsql_test rtree8-2.2.2 {
   128    130     DELETE FROM t1 WHERE id=25
   129    131   } {1 {database disk image is malformed}}
   130    132   do_execsql_test rtree8-2.2.3 { 

Changes to ext/rtree/rtreeA.test.

    32     32     execsql BEGIN
    33     33     for {set i 0} {$i < 500} {incr i} {
    34     34       set x2 [expr $i+5]
    35     35       set y2 [expr $i+5]
    36     36       execsql { INSERT INTO t1 VALUES($i, $i, $x2, $i, $y2) }
    37     37     }
    38     38     execsql COMMIT
           39  +  sqlite3_db_config db DEFENSIVE 0
    39     40   }
    40     41   
    41     42   proc truncate_node {nodeno nTrunc} {
    42     43     set blob [db one {SELECT data FROM t1_node WHERE nodeno=$nodeno}]
    43     44     if {$nTrunc<0} {set nTrunc "end-$nTrunc"}
    44     45     set blob [string range $blob 0 $nTrunc]
    45     46     db eval { UPDATE t1_node SET data = $blob WHERE nodeno=$nodeno }
................................................................................
   242    243   
   243    244   #-------------------------------------------------------------------------
   244    245   # Truncated blobs in the _node table.
   245    246   #
   246    247   create_t1
   247    248   populate_t1
   248    249   sqlite3 db test.db
          250  +sqlite3_db_config db DEFENSIVE 0
   249    251   do_execsql_test rtreeA-7.100 { 
   250    252     UPDATE t1_node SET data=x'' WHERE rowid=1;
   251    253   } {}
   252    254   do_catchsql_test rtreeA-7.110 {
   253    255     SELECT * FROM t1 WHERE x1>0 AND x1<100 AND x2>0 AND x2<100;
   254    256   } {1 {undersize RTree blobs in "t1_node"}}
   255    257   do_test rtreeA-7.120 {
   256    258     sqlite3_extended_errcode db
   257    259   } {SQLITE_CORRUPT_VTAB}
   258    260   
   259    261   
   260    262   finish_test
   261         -

Changes to ext/rtree/rtreecheck.test.

    57     57       CREATE VIRTUAL TABLE r1 USING $module (id, x1, x2, y1, y2);
    58     58       INSERT INTO r1 VALUES(1,  5, 5, 5, 5);  --  3
    59     59       INSERT INTO r1 VALUES(2,  6, 6, 6, 6);  --  9
    60     60       INSERT INTO r1 VALUES(3,  7, 7, 7, 7);  -- 15
    61     61       INSERT INTO r1 VALUES(4,  8, 8, 8, 8);  -- 21
    62     62       INSERT INTO r1 VALUES(5,  9, 9, 9, 9);  -- 27
    63     63     "
           64  +  sqlite3_db_config db DEFENSIVE 0
    64     65   }
    65     66   
    66     67   setup_simple_db
    67     68   do_execsql_test 2.1 { 
    68     69     SELECT rtreecheck('r1') 
    69     70   } {ok}
    70     71   
................................................................................
   108    109   
   109    110   do_execsql_test 3.1 { 
   110    111     CREATE VIRTUAL TABLE r2 USING rtree_i32(id, x1, x2);
   111    112     INSERT INTO r2 VALUES(2, -1*(1<<31), -1*(1<<31)+5);
   112    113     SELECT rtreecheck('r2') 
   113    114   } {ok}
   114    115   
          116  +sqlite3_db_config db DEFENSIVE 0
   115    117   do_execsql_test 3.2 {
   116    118     BEGIN;
   117    119       UPDATE r2_node SET data = X'123456';
   118    120       SELECT rtreecheck('r2')!="ok";
   119    121   } {1}
   120    122   
   121    123   do_execsql_test 3.3 {
................................................................................
   136    138   do_execsql_test 5.0 {
   137    139     CREATE VIRTUAL TABLE r3 USING rtree_i32(id, x1, x2, y1, y2);
   138    140     WITH x(i) AS (
   139    141       SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<1000
   140    142     )
   141    143     INSERT INTO r3 SELECT i, i, i, i, i FROM x;
   142    144   }
          145  +sqlite3_db_config db DEFENSIVE 0
   143    146   do_execsql_test 5.1 {
   144    147     BEGIN;
   145    148       UPDATE r3_node SET data = set_int32(data, 3, 5000);
   146    149       UPDATE r3_node SET data = set_int32(data, 4, 5000);
   147    150       SELECT rtreecheck('r3')=='ok'
   148    151   } 0
   149    152   do_execsql_test 5.2 {
................................................................................
   151    154     BEGIN;
   152    155       UPDATE r3_node SET data = set_int32(data, 3, 0);
   153    156       UPDATE r3_node SET data = set_int32(data, 4, 0);
   154    157       SELECT rtreecheck('r3')=='ok'
   155    158   } 0
   156    159   
   157    160   finish_test
   158         -

Changes to ext/session/sessionC.test.

   191    191       SELECT * FROM t3;
   192    192     }
   193    193   } {1 1 3 3}
   194    194   
   195    195   
   196    196   
   197    197   finish_test
   198         -

Changes to ext/session/sessionD.test.

   251    251   } {0 {}}
   252    252   S delete
   253    253   do_catchsql_test 4.5.2 {
   254    254     SELECT * FROM ixua.i8;
   255    255   } {1 {no such table: ixua.i8}}
   256    256   
   257    257   finish_test
   258         -

Changes to ext/session/sessionE.test.

   107    107     {INSERT t2 0 X. {} {i 7 i 8}}
   108    108   }
   109    109   
   110    110   
   111    111   S delete
   112    112   
   113    113   finish_test
   114         -
   115         -

Changes to ext/session/sessionF.test.

   288    288     }
   289    289   
   290    290     do_test 3.$tn { set res } [list {*}$result]
   291    291   }
   292    292   
   293    293   
   294    294   finish_test
   295         -

Changes to ext/session/sessionG.test.

   244    244     SELECT count(*) FROM t1 WHERE number_name(a+1) IS NOT b; 
   245    245   } {0}
   246    246   
   247    247   # db eval { SELECT * FROM t1 } { puts "$a || $b" }
   248    248   
   249    249   
   250    250   finish_test
   251         -

Changes to ext/session/sessionH.test.

    32     32       INSERT INTO t1 SELECT 'abcde', randomblob(16), i FROM s;
    33     33     }
    34     34     compare_db db db2
    35     35   } {}
    36     36   
    37     37   
    38     38   finish_test
    39         -

Changes to ext/session/sessionfault2.test.

   278    278   } -test {
   279    279     catch { R delete } 
   280    280     faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
   281    281   }
   282    282   
   283    283   
   284    284   finish_test
   285         -

Changes to ext/session/sessionrebase.test.

   470    470       R configure $::rebase
   471    471       expr [catch {R rebase $P}]==0
   472    472     } $rebasable
   473    473   
   474    474     catch { R delete }
   475    475   }
   476    476   finish_test
   477         -

Changes to ext/session/sessionstat1.test.

   304    304       return "REPLACE"
   305    305     }
   306    306     sqlite3changeset_apply db2 $C xConflict
   307    307     execsql { SELECT * FROM sqlite_stat1 ORDER BY 1,2 } db2
   308    308   } {t3 null 3}
   309    309   
   310    310   finish_test
   311         -

Changes to ext/session/sessionwor.test.

    50     50   do_iterator_test 1.3 t1 {
    51     51     DELETE FROM t1;
    52     52   } {
    53     53     {DELETE t1 0 X. {t one t three} {}}
    54     54   }
    55     55   
    56     56   finish_test
    57         -

Changes to src/build.c.

  1889   1889       assert( pPk->nColumn==j );
  1890   1890       assert( pTab->nCol==j );
  1891   1891     }else{
  1892   1892       pPk->nColumn = pTab->nCol;
  1893   1893     }
  1894   1894     recomputeColumnsNotIndexed(pPk);
  1895   1895   }
         1896  +
         1897  +/*
         1898  +** Return true if zName is a shadow table name in the current database
         1899  +** connection.
         1900  +**
         1901  +** zName is temporarily modified while this routine is running, but is
         1902  +** restored to its original value prior to this routine returning.
         1903  +*/
         1904  +static int isShadowTableName(sqlite3 *db, char *zName){
         1905  +  char *zTail;                  /* Pointer to the last "_" in zName */
         1906  +  Table *pTab;                  /* Table that zName is a shadow of */
         1907  +  Module *pMod;                 /* Module for the virtual table */
         1908  +
         1909  +  zTail = strrchr(zName, '_');
         1910  +  if( zTail==0 ) return 0;
         1911  +  *zTail = 0;
         1912  +  pTab = sqlite3FindTable(db, zName, 0);
         1913  +  *zTail = '_';
         1914  +  if( pTab==0 ) return 0;
         1915  +  if( !IsVirtual(pTab) ) return 0;
         1916  +  pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]);
         1917  +  if( pMod==0 ) return 0;
         1918  +  if( pMod->pModule->iVersion<3 ) return 0;
         1919  +  if( pMod->pModule->xShadowName==0 ) return 0;
         1920  +  return pMod->pModule->xShadowName(zTail+1);
         1921  +}
  1896   1922   
  1897   1923   /*
  1898   1924   ** This routine is called to report the final ")" that terminates
  1899   1925   ** a CREATE TABLE statement.
  1900   1926   **
  1901   1927   ** The table structure that other action routines have been building
  1902   1928   ** is added to the internal hash tables, assuming no errors have
................................................................................
  1928   1954   
  1929   1955     if( pEnd==0 && pSelect==0 ){
  1930   1956       return;
  1931   1957     }
  1932   1958     assert( !db->mallocFailed );
  1933   1959     p = pParse->pNewTable;
  1934   1960     if( p==0 ) return;
         1961  +
         1962  +  if( pSelect==0 && isShadowTableName(db, p->zName) ){
         1963  +    p->tabFlags |= TF_Shadow;
         1964  +  }
  1935   1965   
  1936   1966     /* If the db->init.busy is 1 it means we are reading the SQL off the
  1937   1967     ** "sqlite_master" or "sqlite_temp_master" table on the disk.
  1938   1968     ** So do not write to the disk again.  Extract the root page number
  1939   1969     ** for the table from the db->init.newTnum field.  (The page number
  1940   1970     ** should have been put there by the sqliteOpenCb routine.)
  1941   1971     **

Changes to src/dbpage.c.

   403    403       0,                            /* xCommit */
   404    404       0,                            /* xRollback */
   405    405       0,                            /* xFindMethod */
   406    406       0,                            /* xRename */
   407    407       0,                            /* xSavepoint */
   408    408       0,                            /* xRelease */
   409    409       0,                            /* xRollbackTo */
          410  +    0                             /* xShadowName */
   410    411     };
   411    412     return sqlite3_create_module(db, "sqlite_dbpage", &dbpage_module, 0);
   412    413   }
   413    414   #elif defined(SQLITE_ENABLE_DBPAGE_VTAB)
   414    415   int sqlite3DbpageRegister(sqlite3 *db){ return SQLITE_OK; }
   415    416   #endif /* SQLITE_ENABLE_DBSTAT_VTAB */

Changes to src/dbstat.c.

   716    716       0,                            /* xCommit */
   717    717       0,                            /* xRollback */
   718    718       0,                            /* xFindMethod */
   719    719       0,                            /* xRename */
   720    720       0,                            /* xSavepoint */
   721    721       0,                            /* xRelease */
   722    722       0,                            /* xRollbackTo */
          723  +    0                             /* xShadowName */
   723    724     };
   724    725     return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
   725    726   }
   726    727   #elif defined(SQLITE_ENABLE_DBSTAT_VTAB)
   727    728   int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; }
   728    729   #endif /* SQLITE_ENABLE_DBSTAT_VTAB */

Changes to src/delete.c.

    39     39       pTab->nTabRef++;
    40     40     }
    41     41     if( sqlite3IndexedByLookup(pParse, pItem) ){
    42     42       pTab = 0;
    43     43     }
    44     44     return pTab;
    45     45   }
           46  +
           47  +/* Return true if table pTab is read-only.
           48  +**
           49  +** A table is read-only if any of the following are true:
           50  +**
           51  +**   1) It is a virtual table and no implementation of the xUpdate method
           52  +**      has been provided
           53  +**
           54  +**   2) It is a system table (i.e. sqlite_master), this call is not
           55  +**      part of a nested parse and writable_schema pragma has not 
           56  +**      been specified
           57  +**
           58  +**   3) The table is a shadow table, the database connection is in
           59  +**      defensive mode, and the current sqlite3_prepare()
           60  +**      is for a top-level SQL statement.
           61  +*/
           62  +static int tabIsReadOnly(Parse *pParse, Table *pTab){
           63  +  sqlite3 *db;
           64  +  if( IsVirtual(pTab) ){
           65  +    return sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0;
           66  +  }
           67  +  if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
           68  +  db = pParse->db;
           69  +  if( (pTab->tabFlags & TF_Readonly)!=0 ){
           70  +    return sqlite3WritableSchema(db)==0 && pParse->nested==0;
           71  +  }
           72  +  assert( pTab->tabFlags & TF_Shadow );
           73  +  return (db->flags & SQLITE_Defensive)!=0
           74  +           && db->nVdbeExec==0
           75  +           && db->pVtabCtx==0;
           76  +}
    46     77   
    47     78   /*
    48     79   ** Check to make sure the given table is writable.  If it is not
    49     80   ** writable, generate an error message and return 1.  If it is
    50     81   ** writable return 0;
    51     82   */
    52     83   int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
    53         -  /* A table is not writable under the following circumstances:
    54         -  **
    55         -  **   1) It is a virtual table and no implementation of the xUpdate method
    56         -  **      has been provided, or
    57         -  **   2) It is a system table (i.e. sqlite_master), this call is not
    58         -  **      part of a nested parse and writable_schema pragma has not 
    59         -  **      been specified.
    60         -  **
    61         -  ** In either case leave an error message in pParse and return non-zero.
    62         -  */
    63         -  if( ( IsVirtual(pTab) 
    64         -     && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
    65         -   || ( (pTab->tabFlags & TF_Readonly)!=0
    66         -     && sqlite3WritableSchema(pParse->db)==0
    67         -     && pParse->nested==0)
    68         -  ){
           84  +  if( tabIsReadOnly(pParse, pTab) ){
    69     85       sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
    70     86       return 1;
    71     87     }
    72         -
    73     88   #ifndef SQLITE_OMIT_VIEW
    74     89     if( !viewOk && pTab->pSelect ){
    75     90       sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName);
    76     91       return 1;
    77     92     }
    78     93   #endif
    79     94     return 0;

Changes to src/main.c.

  3058   3058                    | SQLITE_CellSizeCk
  3059   3059   #endif
  3060   3060   #if defined(SQLITE_ENABLE_FTS3_TOKENIZER)
  3061   3061                    | SQLITE_Fts3Tokenizer
  3062   3062   #endif
  3063   3063   #if defined(SQLITE_ENABLE_QPSG)
  3064   3064                    | SQLITE_EnableQPSG
         3065  +#endif
         3066  +#if defined(SQLITE_DEFAULT_DEFENSIVE)
         3067  +                 | SQLITE_Defensive
  3065   3068   #endif
  3066   3069         ;
  3067   3070     sqlite3HashInit(&db->aCollSeq);
  3068   3071   #ifndef SQLITE_OMIT_VIRTUALTABLE
  3069   3072     sqlite3HashInit(&db->aModule);
  3070   3073   #endif
  3071   3074   

Changes to src/pragma.c.

  2473   2473     0,                           /* xSync - sync transaction */
  2474   2474     0,                           /* xCommit - commit transaction */
  2475   2475     0,                           /* xRollback - rollback transaction */
  2476   2476     0,                           /* xFindFunction - function overloading */
  2477   2477     0,                           /* xRename - rename the table */
  2478   2478     0,                           /* xSavepoint */
  2479   2479     0,                           /* xRelease */
  2480         -  0                            /* xRollbackTo */
         2480  +  0,                           /* xRollbackTo */
         2481  +  0                            /* xShadowName */
  2481   2482   };
  2482   2483   
  2483   2484   /*
  2484   2485   ** Check to see if zTabName is really the name of a pragma.  If it is,
  2485   2486   ** then register an eponymous virtual table for that pragma and return
  2486   2487   ** a pointer to the Module object for the new virtual table.
  2487   2488   */

Changes to src/sqlite.h.in.

  2156   2156   ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
  2157   2157   ** </ol>
  2158   2158   ** Because resetting a database is destructive and irreversible, the
  2159   2159   ** process requires the use of this obscure API and multiple steps to help
  2160   2160   ** ensure that it does not happen by accident.
  2161   2161   **
  2162   2162   ** <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
  2163         -** <dd>The SQLITE_DBCONFIG_DEFENSIVE option actives or deactivates the
         2163  +** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
  2164   2164   ** "defensive" flag for a database connection.  When the defensive
  2165         -** flag is enabled, some obscure features of SQLite are disabled in order
  2166         -** to reduce the attack surface. Applications that run untrusted SQL
  2167         -** can activate this flag to reduce the risk of zero-day exploits.
  2168         -** <p>
  2169         -** Features disabled by the defensive flag include:
         2165  +** flag is enabled, language features that allow ordinary SQL to 
         2166  +** deliberately corrupt the database file are disabled.  The disabled
         2167  +** features include but are not limited to the following:
  2170   2168   ** <ul>
  2171         -** <li>The [PRAGMA writable_schema=ON] statement.
  2172         -** <li>Writes to the [sqlite_dbpage] virtual table.
         2169  +** <li> The [PRAGMA writable_schema=ON] statement.
         2170  +** <li> Writes to the [sqlite_dbpage] virtual table.
         2171  +** <li> Direct writes to shadow tables.
  2173   2172   ** </ul>
  2174         -** New restrictions may be added in future releases.
  2175         -** <p>
  2176         -** To be clear: It should never be possible for hostile SQL to cause
  2177         -** arbitrary memory reads, memory leaks, buffer overflows, assertion
  2178         -** faults, arbitrary code execution, crashes, or other mischief, regardless
  2179         -** of the value of the defensive flag.  Any occurrance of these problems
  2180         -** is considered a serious bug and will be fixed promptly.  It is not
  2181         -** necessary to enable the defensive flag in order to make SQLite secure
  2182         -** against attack. The defensive flag merely provides an additional layer
  2183         -** of defense against unknown vulnerabilities.
  2184   2173   ** </dd>
  2185   2174   ** </dl>
  2186   2175   */
  2187   2176   #define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
  2188   2177   #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
  2189   2178   #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
  2190   2179   #define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
................................................................................
  6318   6307                          void **ppArg);
  6319   6308     int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  6320   6309     /* The methods above are in version 1 of the sqlite_module object. Those 
  6321   6310     ** below are for version 2 and greater. */
  6322   6311     int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  6323   6312     int (*xRelease)(sqlite3_vtab *pVTab, int);
  6324   6313     int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
         6314  +  /* The methods above are in versions 1 and 2 of the sqlite_module object.
         6315  +  ** Those below are for version 3 and greater. */
         6316  +  int (*xShadowName)(const char*);
  6325   6317   };
  6326   6318   
  6327   6319   /*
  6328   6320   ** CAPI3REF: Virtual Table Indexing Information
  6329   6321   ** KEYWORDS: sqlite3_index_info
  6330   6322   **
  6331   6323   ** The sqlite3_index_info structure and its substructures is used as part

Changes to src/sqliteInt.h.

  1997   1997   #define TF_HasStat1        0x0010    /* nRowLogEst set from sqlite_stat1 */
  1998   1998   #define TF_WithoutRowid    0x0020    /* No rowid.  PRIMARY KEY is the key */
  1999   1999   #define TF_NoVisibleRowid  0x0040    /* No user-visible "rowid" column */
  2000   2000   #define TF_OOOHidden       0x0080    /* Out-of-Order hidden columns */
  2001   2001   #define TF_StatsUsed       0x0100    /* Query planner decisions affected by
  2002   2002                                        ** Index.aiRowLogEst[] values */
  2003   2003   #define TF_HasNotNull      0x0200    /* Contains NOT NULL constraints */
         2004  +#define TF_Shadow          0x0400    /* True for a shadow table */
  2004   2005   
  2005   2006   /*
  2006   2007   ** Test to see whether or not a table is a virtual table.  This is
  2007   2008   ** done as a macro so that it will be optimized out when virtual
  2008   2009   ** table support is omitted from the build.
  2009   2010   */
  2010   2011   #ifndef SQLITE_OMIT_VIRTUALTABLE

Changes to src/vacuum.c.

   162    162     saved_flags = db->flags;
   163    163     saved_mDbFlags = db->mDbFlags;
   164    164     saved_nChange = db->nChange;
   165    165     saved_nTotalChange = db->nTotalChange;
   166    166     saved_mTrace = db->mTrace;
   167    167     db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
   168    168     db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
   169         -  db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
          169  +  db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder
          170  +                   | SQLITE_Defensive | SQLITE_CountRows);
   170    171     db->mTrace = 0;
   171    172   
   172    173     zDbMain = db->aDb[iDb].zDbSName;
   173    174     pMain = db->aDb[iDb].pBt;
   174    175     isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
   175    176   
   176    177     /* Attach the temporary database as 'vacuum_db'. The synchronous pragma

Changes to test/alter2.test.

    60     60   # to the supplied value. This is 2 if the added column has a default that is
    61     61   # NULL, or 3 otherwise. 
    62     62   #
    63     63   proc alter_table {tbl sql {file_format 2}} {
    64     64     sqlite3 dbat test.db
    65     65     set s [string map {' ''} $sql]
    66     66     set t [string map {' ''} $tbl]
           67  +  sqlite3_db_config dbat DEFENSIVE 0
    67     68     dbat eval [subst {
    68     69       PRAGMA writable_schema = 1;
    69     70       UPDATE sqlite_master SET sql = '$s' WHERE name = '$t' AND type = 'table';
    70     71       PRAGMA writable_schema = 0;
    71     72     }]
    72     73     dbat close
    73     74     set_file_format 2
................................................................................
    87     88     catchsql {SELECT substr('abcdefg',1,3)}
    88     89   } {1 {bad function}}
    89     90   
    90     91   
    91     92   #-----------------------------------------------------------------------
    92     93   # Some basic tests to make sure short rows are handled.
    93     94   #
           95  +sqlite3_db_config db DEFENSIVE 0
    94     96   do_test alter2-1.1 {
    95     97     execsql {
    96     98       CREATE TABLE abc(a, b);
    97     99       INSERT INTO abc VALUES(1, 2);
    98    100       INSERT INTO abc VALUES(3, 4);
    99    101       INSERT INTO abc VALUES(5, 6);
   100    102     }

Changes to test/altercol.test.

   549    549   
   550    550   do_execsql_test 13.1.3 {
   551    551     DROP TRIGGER tr1;
   552    552     CREATE INDEX x1i ON x1(i);
   553    553     SELECT sql FROM sqlite_master WHERE name='x1i';
   554    554   } {{CREATE INDEX x1i ON x1(i)}}
   555    555   
          556  +sqlite3_db_config db DEFENSIVE 0
   556    557   do_execsql_test 13.1.4 {
   557    558     PRAGMA writable_schema = 1;
   558    559     UPDATE sqlite_master SET sql = 'CREATE INDEX x1i ON x1(j)' WHERE name='x1i';
   559    560   } {}
   560    561   
   561    562   do_catchsql_test 13.1.5 {
   562    563     ALTER TABLE x1 RENAME COLUMN t TO ttt;

Changes to test/alterlegacy.test.

   463    463   }
   464    464   do_execsql_test 14.6 {
   465    465     ALTER TABLE t1 RENAME TO tt1;
   466    466   }
   467    467   
   468    468   
   469    469   finish_test
   470         -

Changes to test/altertab.test.

   501    501   
   502    502   do_execsql_test 15.5 {
   503    503     SELECT sql FROM sqlite_master WHERE name = 'y';
   504    504   } {{CREATE VIEW y AS SELECT f2 AS f1 FROM x}}
   505    505   
   506    506   
   507    507   finish_test
   508         -

Changes to test/altertab2.test.

    83     83     {CREATE TABLE c1(x REFERENCES "p3")}
    84     84     {CREATE TABLE c2(x, FOREIGN KEY (x) REFERENCES "p3")}
    85     85     {CREATE TABLE c3(x, FOREIGN KEY (x) REFERENCES "p3"(a))}
    86     86   }
    87     87   
    88     88   
    89     89   finish_test
    90         -

Changes to test/analyze.test.

   346    346     } {t4i1 t4i2 t4}
   347    347   }
   348    348   
   349    349   # This test corrupts the database file so it must be the last test
   350    350   # in the series.
   351    351   #
   352    352   do_test analyze-5.99 {
          353  +  sqlite3_db_config db DEFENSIVE 0
   353    354     execsql {
   354    355       PRAGMA writable_schema=on;
   355    356       UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1';
   356    357     }
   357    358     db close
   358    359     catch { sqlite3 db test.db }
   359    360     catchsql {

Changes to test/autoinc.test.

   693    693   # Does not crash if the sqlite_sequence table schema is missing
   694    694   # or corrupt.
   695    695   #
   696    696   do_test autoinc-12.1 {
   697    697     db close
   698    698     forcedelete test.db
   699    699     sqlite3 db test.db
          700  +  sqlite3_db_config db DEFENSIVE 0
   700    701     db eval {
   701    702       CREATE TABLE fake_sequence(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
   702    703       PRAGMA writable_schema=on;
   703    704       UPDATE sqlite_master SET
   704    705        sql=replace(sql,'fake_','sqlite_'),
   705    706        name='sqlite_sequence',
   706    707        tbl_name='sqlite_sequence'
................................................................................
   714    715     }} msg]
   715    716     lappend res $msg
   716    717   } {1 {database disk image is malformed}}
   717    718   do_test autoinc-12.2 {
   718    719     db close
   719    720     forcedelete test.db
   720    721     sqlite3 db test.db
          722  +  sqlite3_db_config db DEFENSIVE 0
   721    723     db eval {
   722    724      CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   723    725      INSERT INTO t1(b) VALUES('one');
   724    726      PRAGMA writable_schema=on;
   725    727      UPDATE sqlite_master SET
   726    728        sql=replace(sql,'sqlite_','x_'),
   727    729        name='x_sequence',
................................................................................
   740    742   } else {
   741    743     set err {malformed database schema (sqlite_sequence) - near "VIRTUAL": syntax error}
   742    744   }
   743    745   do_test autoinc-12.3 {
   744    746     db close
   745    747     forcedelete test.db
   746    748     sqlite3 db test.db
          749  +  sqlite3_db_config db DEFENSIVE 0
   747    750     db eval {
   748    751      CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   749    752      INSERT INTO t1(b) VALUES('one');
   750    753      PRAGMA writable_schema=on;
   751    754      UPDATE sqlite_master SET
   752    755        sql='CREATE VIRTUAL TABLE sqlite_sequence USING sqlite_dbpage'
   753    756       WHERE name='sqlite_sequence';
................................................................................
   768    771       INSERT INTO t1(b) VALUES('one');
   769    772       CREATE TABLE fake(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
   770    773     }
   771    774     set root1 [db one {SELECT rootpage FROM sqlite_master
   772    775                        WHERE name='sqlite_sequence'}]
   773    776     set root2 [db one {SELECT rootpage FROM sqlite_master
   774    777                        WHERE name='fake'}]
          778  +  sqlite3_db_config db DEFENSIVE 0
   775    779     db eval {
   776    780      PRAGMA writable_schema=on;
   777    781      UPDATE sqlite_master SET rootpage=$root2
   778    782       WHERE name='sqlite_sequence';
   779    783      UPDATE sqlite_master SET rootpage=$root1
   780    784       WHERE name='fake';
   781    785     }
................................................................................
   787    791     lappend res $msg
   788    792   } {1 {database disk image is malformed}}
   789    793   breakpoint
   790    794   do_test autoinc-12.5 {
   791    795     db close
   792    796     forcedelete test.db
   793    797     sqlite3 db test.db
          798  +  sqlite3_db_config db DEFENSIVE 0
   794    799     db eval {
   795    800       CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   796    801       INSERT INTO t1(b) VALUES('one');
   797    802       PRAGMA writable_schema=on;
   798    803       UPDATE sqlite_master SET
   799    804          sql='CREATE TABLE sqlite_sequence(x)'
   800    805         WHERE name='sqlite_sequence';
................................................................................
   806    811     }} msg]
   807    812     lappend res $msg
   808    813   } {1 {database disk image is malformed}}
   809    814   do_test autoinc-12.6 {
   810    815     db close
   811    816     forcedelete test.db
   812    817     sqlite3 db test.db
          818  +  sqlite3_db_config db DEFENSIVE 0
   813    819     db eval {
   814    820       CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   815    821       INSERT INTO t1(b) VALUES('one');
   816    822       PRAGMA writable_schema=on;
   817    823       UPDATE sqlite_master SET
   818    824          sql='CREATE TABLE sqlite_sequence(x,y INTEGER PRIMARY KEY)'
   819    825         WHERE name='sqlite_sequence';
................................................................................
   827    833     }} msg]
   828    834     lappend res $msg
   829    835   } {0 ok}
   830    836   do_test autoinc-12.7 {
   831    837     db close
   832    838     forcedelete test.db
   833    839     sqlite3 db test.db
          840  +  sqlite3_db_config db DEFENSIVE 0
   834    841     db eval {
   835    842       CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   836    843       INSERT INTO t1(b) VALUES('one');
   837    844       PRAGMA writable_schema=on;
   838    845       UPDATE sqlite_master SET
   839    846          sql='CREATE TABLE sqlite_sequence(y INTEGER PRIMARY KEY,x)'
   840    847         WHERE name='sqlite_sequence';

Changes to test/bestindex5.test.

   243    243   do_execsql_test 3.3 { SELECT rowid, * FROM t4 WHERE x!=245; } {}
   244    244   do_execsql_test 3.4 { SELECT rowid, * FROM t4 WHERE x!='245'; } {}
   245    245   
   246    246   do_execsql_test 3.5 { SELECT rowid, * FROM t4 WHERE rowid!=1 OR x!='245'; } {}
   247    247   
   248    248   
   249    249   finish_test
   250         -

Changes to test/capi3.test.

   737    737       execsql {
   738    738         CREATE TABLE t1(a);
   739    739       }
   740    740       db close
   741    741     } {}
   742    742     do_test capi3-8.2 {
   743    743       sqlite3 db test.db
          744  +    sqlite3_db_config db DEFENSIVE 0
   744    745       execsql {
   745    746         PRAGMA writable_schema=ON;
   746    747         INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
   747    748       }
   748    749       db close
   749    750     } {}
   750    751     do_test capi3-8.3 {
................................................................................
   755    756     } {1 {malformed database schema (?)}}
   756    757     do_test capi3-8.4 {
   757    758       # Build a 5-field row record. The first field is a string 'table', and
   758    759       # subsequent fields are all NULL.
   759    760       db close
   760    761       forcedelete test.db test.db-journal
   761    762       sqlite3 db test.db
          763  +    sqlite3_db_config db DEFENSIVE 0
   762    764       execsql {
   763    765         CREATE TABLE t1(a);
   764    766         PRAGMA writable_schema=ON;
   765    767         INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
   766    768       }
   767    769       db close
   768    770     } {};

Changes to test/capi3c.test.

   682    682       execsql {
   683    683         CREATE TABLE t1(a);
   684    684       }
   685    685       db close
   686    686     } {}
   687    687     do_test capi3c-8.2 {
   688    688       sqlite3 db test.db
          689  +    sqlite3_db_config db DEFENSIVE 0
   689    690       execsql {
   690    691         PRAGMA writable_schema=ON;
   691    692         INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
   692    693       }
   693    694       db close
   694    695     } {}
   695    696     do_test capi3c-8.3 {
................................................................................
   700    701     } {1 {malformed database schema (?)}}
   701    702     do_test capi3c-8.4 {
   702    703       # Build a 5-field row record. The first field is a string 'table', and
   703    704       # subsequent fields are all NULL.
   704    705       db close
   705    706       forcedelete test.db test.db-journal
   706    707       sqlite3 db test.db
          708  +    sqlite3_db_config db DEFENSIVE 0
   707    709       execsql {
   708    710         CREATE TABLE t1(a);
   709    711         PRAGMA writable_schema=ON;
   710    712         INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
   711    713       }
   712    714       db close
   713    715     } {};

Changes to test/corrupt.test.

   128    128     sqlite3 db test.db
   129    129     list
   130    130   } {}
   131    131   do_test corrupt-3.2 {
   132    132     set t1_r [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't1i1'}]
   133    133     set t1i1_r [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't1'}]
   134    134     set cookie [expr [execsql {PRAGMA schema_version}] + 1]
          135  +  sqlite3_db_config db DEFENSIVE 0
   135    136     execsql "
   136    137       PRAGMA writable_schema = 1;
   137    138       UPDATE sqlite_master SET rootpage = $t1_r WHERE name = 't1';
   138    139       UPDATE sqlite_master SET rootpage = $t1i1_r WHERE name = 't1i1';
   139    140       PRAGMA writable_schema = 0;
   140    141       PRAGMA schema_version = $cookie;
   141    142     "

Changes to test/corrupt2.test.

   129    129   do_test corrupt2-2.1 {
   130    130   
   131    131     forcedelete corrupt.db
   132    132     forcedelete corrupt.db-journal
   133    133     forcecopy test.db corrupt.db
   134    134   
   135    135     sqlite3 db2 corrupt.db 
          136  +  sqlite3_db_config db2 DEFENSIVE 0
   136    137     execsql "
   137    138       $::presql
   138    139       CREATE INDEX a1 ON abc(a);
   139    140       CREATE INDEX a2 ON abc(b);
   140    141       PRAGMA writable_schema = 1;
   141    142       UPDATE sqlite_master 
   142    143         SET name = 'a3', sql = 'CREATE INDEX a3' || substr(sql, 16, 10000)
................................................................................
   261    262     array set A $args
   262    263   
   263    264     catch {db close}
   264    265     forcedelete corrupt.db
   265    266     forcedelete corrupt.db-journal
   266    267   
   267    268     sqlite3 db corrupt.db 
          269  +  sqlite3_db_config db DEFENSIVE 0
   268    270     db eval $::presql
   269    271     eval $A(-tclprep)
   270    272     db eval $A(-sqlprep)
   271    273     db close
   272    274   
   273    275     eval $A(-corrupt)
   274    276   

Changes to test/corrupt5.test.

    29     29     finish_test
    30     30     return
    31     31   }
    32     32   
    33     33   # Create a database with a freelist containing at least two pages.
    34     34   #
    35     35   do_test corrupt5-1.1 {
           36  +  sqlite3_db_config db DEFENSIVE 0
    36     37     execsql {
    37     38       CREATE TABLE t1(a,b,c);
    38     39       CREATE INDEX i1 ON t1(a,b);
    39     40       PRAGMA writable_schema=ON;
    40     41       UPDATE sqlite_master SET name=NULL, sql=NULL WHERE name='i1';
    41     42     }
    42     43     db close

Changes to test/corruptI.test.

   218    218     PRAGMA auto_vacuum=0;
   219    219     CREATE TABLE t1(x PRIMARY KEY, y);
   220    220     INSERT INTO t1 VALUES('a', 'A');
   221    221     INSERT INTO t1 VALUES('b', 'A');
   222    222     INSERT INTO t1 VALUES('c', 'A');
   223    223     SELECT name FROM sqlite_master;
   224    224   } {t1 sqlite_autoindex_t1_1}
          225  +sqlite3_db_config db DEFENSIVE 0
   225    226   do_execsql_test 7.1 {
   226    227     PRAGMA writable_schema = 1;
   227    228     DELETE FROM sqlite_master WHERE name = 'sqlite_autoindex_t1_1';
   228    229   }
   229    230   do_test 7.2 {
   230    231     db close
   231    232     sqlite3 db test.db

Changes to test/corruptK.test.

   139    139       PRAGMA page_size=1024;
   140    140       CREATE TABLE t1(a, b, c);
   141    141       CREATE TABLE t2(a, b, c);
   142    142       CREATE TABLE t3(a, b, c);
   143    143       CREATE TABLE t4(a, b, c);
   144    144       CREATE TABLE t5(a, b, c);
   145    145     }
   146         -  
          146  +  sqlite3_db_config db DEFENSIVE 0
   147    147     do_execsql_test 3.2 {
   148    148       UPDATE sqlite_dbpage SET data = hex2blob('
   149    149      000: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
   150    150      010: 04 00 01 01 20 40 20 20 00 00 3e d9 00 00 00 06 .... @  ..>.....
   151    151      020: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................
   152    152      030: 0f 00 00 00 00 00 00 00 00 00 00 01 00 00 83 00 ................
   153    153      040: 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 00 .............8..

Changes to test/countofview.test.

    37     37   do_execsql_test 1.3 {
    38     38     select count(*) from (
    39     39       select c from t2 union all select f from t3
    40     40     )
    41     41   } {3}
    42     42   
    43     43   finish_test
    44         -

Changes to test/dbpage.test.

    17     17   set testprefix dbpage
    18     18   
    19     19   ifcapable !vtab||!compound {
    20     20     finish_test
    21     21     return
    22     22   }
    23     23   
           24  +sqlite3_db_config db DEFENSIVE 0
    24     25   do_test 100 {
    25     26     execsql {
    26     27       PRAGMA auto_vacuum=0;
    27     28       PRAGMA page_size=4096;
    28     29       PRAGMA journal_mode=WAL;
    29     30     }
    30     31     execsql { 

Changes to test/default.test.

   102    102   # Do now allow bound parameters in new DEFAULT values. 
   103    103   # Silently convert bound parameters to NULL in DEFAULT causes
   104    104   # in the sqlite_master table, for backwards compatibility.
   105    105   #
   106    106   db close
   107    107   forcedelete test.db
   108    108   sqlite3 db test.db
          109  +sqlite3_db_config db DEFENSIVE 0
   109    110   do_execsql_test default-4.0 {
   110    111     CREATE TABLE t1(a TEXT, b TEXT DEFAULT(99));
   111    112     PRAGMA writable_schema=ON;
   112    113     UPDATE sqlite_master SET sql='CREATE TABLE t1(a TEXT, b TEXT DEFAULT(:xyz))';
   113    114   } {}
   114    115   db close 
   115    116   sqlite3 db test.db

Changes to test/e_fts3.test.

   673    673   #
   674    674   set DO_MALLOC_TEST 0
   675    675   ddl_test   10.1.1 { CREATE VIRTUAL TABLE ta USING fts3 }
   676    676   write_test 10.1.2 ta_content { 
   677    677     INSERT INTO ta VALUES('During a summer vacation in 1790') }
   678    678   write_test 10.1.3 ta_content {
   679    679     INSERT INTO ta VALUES('Wordsworth went on a walking tour') }
          680  +sqlite3_db_config db DEFENSIVE 0
   680    681   write_test 10.1.4 ta_content { DELETE FROM ta_content WHERE rowid = 2 }
   681    682   read_test  10.1.5 {
   682    683     SELECT * FROM ta WHERE ta MATCH 'summer'
   683    684   } {{During a summer vacation in 1790}}
   684    685   error_test 10.1.6 {
   685    686     SELECT * FROM ta WHERE ta MATCH 'walking'
   686    687   } {database disk image is malformed}

Changes to test/e_reindex.test.

    40     40   
    41     41   # EVIDENCE-OF: R-52173-44778 The REINDEX command is used to delete and
    42     42   # recreate indices from scratch.
    43     43   #
    44     44   #    Test this by corrupting some database indexes, running REINDEX, and
    45     45   #    observing that the corruption is gone.
    46     46   #
           47  +sqlite3_db_config db DEFENSIVE 0
    47     48   do_execsql_test e_reindex-1.1 {
    48     49     INSERT INTO t1 VALUES(1, 2);
    49     50     INSERT INTO t1 VALUES(3, 4);
    50     51     INSERT INTO t1 VALUES(5, 6);
    51     52   
    52     53     CREATE TABLE saved(a,b,c,d,e);
    53     54     INSERT INTO saved SELECT * FROM sqlite_master WHERE type = 'index';
    54     55     PRAGMA writable_schema = 1;
    55     56     DELETE FROM sqlite_master WHERE type = 'index';
    56     57   } {}
    57     58   
    58     59   db close
    59     60   sqlite3 db test.db
           61  +sqlite3_db_config db DEFENSIVE 0
    60     62   do_execsql_test e_reindex-1.2 {
    61     63     DELETE FROM t1 WHERE a = 3;
    62     64     INSERT INTO t1 VALUES(7, 8);
    63     65     INSERT INTO t1 VALUES(9, 10);
    64     66     PRAGMA writable_schema = 1;
    65     67     INSERT INTO sqlite_master SELECT * FROM saved;
    66     68     DROP TABLE saved;

Changes to test/fts3auto.test.

   130    130   
   131    131     return [expr $nRow*$pgsz]
   132    132   }
   133    133   
   134    134   #    fts3_zero_long_segments TABLE ?LIMIT?
   135    135   #
   136    136   proc fts3_zero_long_segments {tbl limit} {
          137  +  sqlite3_db_config db DEFENSIVE 0
   137    138     execsql " 
   138    139       UPDATE ${tbl}_segments 
   139    140       SET block = zeroblob(length(block)) 
   140    141       WHERE length(block)>$limit
   141    142     "
   142    143     return [db changes]
   143    144   }

Changes to test/fts3corrupt.test.

    19     19   set ::testprefix fts3corrupt
    20     20   
    21     21   
    22     22   # Test that a doclist with a length field that indicates that the doclist
    23     23   # extends past the end of the node on which it resides is correctly identified
    24     24   # as database corruption.
    25     25   #
           26  +sqlite3_db_config db DEFENSIVE 0
    26     27   do_execsql_test 1.0 {
    27     28     CREATE VIRTUAL TABLE t1 USING fts3;
    28     29     INSERT INTO t1 VALUES('hello');
    29     30   } {}
    30     31   do_test fts3corrupt-1.1 {
    31     32     set blob [db one {SELECT root from t1_segdir}]
    32     33     set blob [binary format a7ca* $blob 24 [string range $blob 8 end]]

Changes to test/fts3corrupt2.test.

    45     45      "ayjafsraz addjj agsj asejtziqws acatvhegu aoxdjqblsvv aekdmmbs aaobe"
    46     46      "abjjvzubkwt alczv ati awz auyxgcxeb aymjoym anqoukprtyt atwfhpmbooh"
    47     47      "ajfqz aethlgir aclcx aowlyvetby aproqm afjlqtkv anebfy akzrcpfrrvw"
    48     48      "aoledfotm aiwlfm aeejlaej anz abgbvk aktfn aayoh anpywgdvgz"
    49     49      "acvmldguld asdvz aqb aeomsyzyu aggylhprbdz asrfkwz auipybpsn agsnszzfb"
    50     50   }
    51     51   
           52  +sqlite3_db_config db DEFENSIVE 0
    52     53   do_test fts3corrupt2-1.0 {
    53     54     execsql BEGIN
    54     55     execsql { CREATE VIRTUAL TABLE t2 USING FTS3(a, b); }
    55     56     execsql { INSERT INTO t2(t2) VALUES('nodesize=32') }
    56     57     foreach d $data {
    57     58       execsql { INSERT INTO t2 VALUES($d, $d) }
    58     59     }

Changes to test/fts3corrupt3.test.

    29     29       INSERT INTO t1 VALUES('one');
    30     30       INSERT INTO t1 VALUES('one');
    31     31     COMMIT;
    32     32   }
    33     33   do_execsql_test 1.1 {
    34     34     SELECT quote(root) from t1_segdir;
    35     35   } {X'00036F6E6509010200010200010200'}
           36  +sqlite3_db_config db DEFENSIVE 0
    36     37   do_execsql_test 1.2 {
    37     38     UPDATE t1_segdir SET root = X'00036F6E650EFFFFFFFFFFFFFFFFFFFFFFFF0200';
    38     39   }
    39     40   do_catchsql_test 1.3 {
    40     41     SELECT rowid FROM t1 WHERE t1 MATCH 'one'
    41     42   } {0 -1}
    42     43   

Changes to test/fts3corrupt4.test.

    36     36   proc blob {a} { binary decode hex $a }
    37     37   db func blob blob
    38     38   
    39     39   do_execsql_test 1.1 {
    40     40     SELECT quote(root) FROM ft_segdir;
    41     41   } {X'0005616261636B03010200030266740302020003046E646F6E03030200'}
    42     42   
           43  +sqlite3_db_config db DEFENSIVE 0
    43     44   do_execsql_test 1.2 {
    44     45     UPDATE ft_segdir SET root = blob(
    45     46       '0005616261636B03010200 FFFFFFFF0702 66740302020003046E646F6E03030200'
    46     47     );
    47     48   }
    48     49   
    49     50   do_catchsql_test 1.3 {
................................................................................
    79     80   } {12 3}
    80     81   
    81     82   do_execsql_test 2.2 {
    82     83     SELECT quote(block) FROM ft_segments WHERE blockid=2
    83     84   } {X'00056162633130031F0200'}
    84     85   
    85     86   db func blob blob
           87  +sqlite3_db_config db DEFENSIVE 0
    86     88   do_execsql_test 2.3.1 {
    87     89     UPDATE ft_segments SET block = 
    88     90       blob('00056162633130031F0200 FFFFFFFF07FF55 66740302020003046E646F6E03030200')
    89     91       WHERE blockid=2;
    90     92   } {}
    91     93   do_catchsql_test 2.3.2 {
    92     94     INSERT INTO ft(ft) VALUES('merge=1,4');
................................................................................
   129    131   } {1 5}
   130    132   
   131    133   do_execsql_test 3.1 {
   132    134     SELECT quote(root) FROM ft_segdir
   133    135   } {X'0101056162633132040136030132030136'}
   134    136   
   135    137   db func blob blob
          138  +sqlite3_db_config db DEFENSIVE 0
   136    139   do_execsql_test 3.2 {
   137    140     UPDATE ft_segdir 
   138    141     SET root = blob('0101056162633132FFFFFFFF070236030132030136');
   139    142   }
   140    143   
   141    144   do_catchsql_test 3.1 {
   142    145     SELECT * FROM ft WHERE ft MATCH 'abc20'
   143    146   } {1 {database disk image is malformed}}
   144    147   
   145    148   finish_test
   146         -
   147         -

Changes to test/fts3cov.test.

    85     85     execsql {
    86     86       INSERT INTO t1(t1) VALUES('optimize');
    87     87       SELECT substr(hex(root), 1, 2) FROM t1_segdir;
    88     88     }
    89     89   } {03}
    90     90   
    91     91   # Test the "missing entry" case:
           92  +sqlite3_db_config db DEFENSIVE 0
    92     93   do_test fts3cov-2.2 {
    93     94     set root [db one {SELECT root FROM t1_segdir}]
    94     95     read_fts3varint [string range $root 1 end] left_child
    95     96     execsql { DELETE FROM t1_segments WHERE blockid = $left_child }
    96     97   } {}
    97     98   do_error_test fts3cov-2.3 {
    98     99     SELECT * FROM t1 WHERE t1 MATCH 'c*'
................................................................................
   401    402   }
   402    403   do_execsql_test 15.1 {
   403    404     SELECT rowid FROM t15 WHERE t15 MATCH '"abc* def2"'
   404    405   } {1 2}
   405    406   
   406    407   # Test a corruption case.
   407    408   #
          409  +sqlite3_db_config db DEFENSIVE 0
   408    410   do_execsql_test 16.1 {
   409    411     CREATE VIRTUAL TABLE t16 USING fts4;
   410    412     INSERT INTO t16 VALUES('theoretical work to examine the relationship');
   411    413     INSERT INTO t16 VALUES('solution of our problems on the invisible');
   412    414     DELETE FROM t16_content WHERE rowid = 2;
   413    415   }
   414    416   do_catchsql_test 16.2 {

Changes to test/fts3d.test.

   292    292     execsql {
   293    293       SELECT OPTIMIZE(t1) FROM t1 LIMIT 1;
   294    294       SELECT level, idx FROM t1_segdir ORDER BY level, idx;
   295    295     }
   296    296   } {{Index already optimal} 1 0}
   297    297   
   298    298   # Even if we move things around, still does nothing.
          299  +sqlite3_db_config db DEFENSIVE 0
   299    300   do_test fts3d-5.1 {
   300    301     execsql {
   301    302       UPDATE t1_segdir SET level = 2 WHERE level = 1 AND idx = 0;
   302    303       SELECT OPTIMIZE(t1) FROM t1 LIMIT 1;
   303    304       SELECT level, idx FROM t1_segdir ORDER BY level, idx;
   304    305     }
   305    306   } {{Index already optimal} 2 0}

Changes to test/fts3defer.test.

    55     55     4  {SELECT snippet(t1) FROM t1 WHERE t1 MATCH '"a longer phrase"'}  
    56     56        {"an instance of <b>a</b> <b>longer</b> <b>phrase</b>"}
    57     57     5  {SELECT rowid FROM t1 WHERE t1 MATCH 'a dog'}                   {1}
    58     58   }
    59     59   
    60     60   do_select_tests 1.2 $tests
    61     61   
           62  +sqlite3_db_config db DEFENSIVE 0
    62     63   do_execsql_test 1.3 {
    63     64     SELECT count(*) FROM t1_segments WHERE length(block)>10000;
    64     65     UPDATE t1_segments 
    65     66       SET block = zeroblob(length(block)) 
    66     67       WHERE length(block)>10000;
    67     68   } {1}
    68     69   
................................................................................
   221    222       foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
   222    223     }
   223    224     3 {
   224    225       set dmt_modes {0 1 2}
   225    226       execsql { CREATE VIRTUAL TABLE t1 USING FTS4 }
   226    227       foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
   227    228       add_empty_records 1000
          229  +    sqlite3_db_config db DEFENSIVE 0
   228    230       execsql $zero_long_doclists
   229    231     }
   230    232     4 {
   231    233       set dmt_modes 0
   232    234       execsql { CREATE VIRTUAL TABLE t1 USING FTS4 }
   233    235       foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
   234    236       add_empty_records 1000
   235    237       execsql "INSERT INTO t1(t1) VALUES('optimize')"
          238  +    sqlite3_db_config db DEFENSIVE 0
   236    239       execsql $zero_long_doclists
   237    240     }
   238    241     5 {
   239    242       set dmt_modes 0
   240    243       execsql { CREATE VIRTUAL TABLE t1 USING FTS4(matchinfo=fts3) }
   241    244       foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
   242    245       add_empty_records 1000
          246  +    sqlite3_db_config db DEFENSIVE 0
   243    247       execsql $zero_long_doclists
   244    248     }
   245    249   } {
   246    250   
   247    251     execsql { DROP TABLE IF EXISTS t1 }
   248    252     eval $setup
   249    253     set ::testprefix fts3defer-2.$tn

Changes to test/fts3defer2.test.

    42     42     INSERT INTO t1 VALUES('');
    43     43     INSERT INTO t1 VALUES('');
    44     44     INSERT INTO t1 VALUES('');
    45     45     INSERT INTO t1 VALUES('');
    46     46     INSERT INTO t1 VALUES('');
    47     47     INSERT INTO t1(t1) VALUES('optimize');
    48     48   }
           49  +sqlite3_db_config db DEFENSIVE 0
    49     50   do_execsql_test 1.1.4 {
    50     51     SELECT count(*) FROM t1_segments WHERE length(block)>10000;
    51     52     UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000;
    52     53   } {2}
    53     54   
    54     55   do_execsql_test 1.2.0 {
    55     56     SELECT content FROM t1 WHERE t1 MATCH 'f (e a)';
................................................................................
    94     95   foreach {tn sql} {
    95     96     1 {}
    96     97     2 { INSERT INTO t2(t2) VALUES('optimize') }
    97     98     3 { UPDATE t2_segments SET block = zeroblob(length(block)) 
    98     99         WHERE length(block)>10000;
    99    100     }
   100    101   } {
          102  +  sqlite3_db_config db DEFENSIVE 0
   101    103     execsql $sql
   102    104   
   103    105     do_execsql_test 2.2.$tn.1 {
   104    106       SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b';
   105    107     } [list                                          \
   106    108       [list 2 1  1 54 54  1 3 3  54 372 8]        \
   107    109       [list 2 1  1 54 54  1 3 3  54 372 7]        \
................................................................................
   148    150   foreach {tn sql} {
   149    151     1 {}
   150    152     2 { INSERT INTO t3(t3) VALUES('optimize') }
   151    153     3 { UPDATE t3_segments SET block = zeroblob(length(block)) 
   152    154         WHERE length(block)>10000;
   153    155     }
   154    156   } {
          157  +  sqlite3_db_config db DEFENSIVE 0
   155    158     execsql $sql
   156    159     do_execsql_test 2.4.$tn {
   157    160       SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"';
   158    161     } {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}}
   159    162   }
   160    163   
   161    164   
   162    165   finish_test

Changes to test/fts3matchinfo.test.

   274    274   do_matchinfo_test 4.3.4 t5 {t5 MATCH 'a a a'}       { s {3 1} }
   275    275   do_matchinfo_test 4.3.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} }
   276    276   do_matchinfo_test 4.3.6 t5 {t5 MATCH 'a OR b'}      { s {1 2 1 1} }
   277    277   
   278    278   do_execsql_test 4.4.0.1 { INSERT INTO t5(t5) VALUES('optimize') }
   279    279   
   280    280   ifcapable fts4_deferred {
          281  +  sqlite3_db_config db DEFENSIVE 0
   281    282     do_execsql_test 4.4.0.2 {
   282    283       UPDATE t5_segments 
   283    284       SET block = zeroblob(length(block)) 
   284    285       WHERE length(block)>10000;
   285    286     }
   286    287   }
   287    288   
................................................................................
   335    336     CREATE VIRTUAL TABLE t9 USING fts4;
   336    337     INSERT INTO t9 VALUES(
   337    338       'this record is used to try to dectect corruption'
   338    339     );
   339    340     SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to';
   340    341   } {{0 0 20 2 0 0 27 2}}
   341    342   
          343  +sqlite3_db_config db DEFENSIVE 0
   342    344   do_catchsql_test 6.2 {
   343    345     UPDATE t9_content SET c0content = 'this record is used to'; 
   344    346     SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to';
   345    347   } {1 {database disk image is malformed}}
   346    348   
   347    349   #-------------------------------------------------------------------------
   348    350   # Test the outcome of matchinfo() when used within a query that does not
................................................................................
   388    390     execsql { INSERT INTO t11(t11) VALUES('optimize') }
   389    391   } {}
   390    392   do_execsql_test 8.3 {
   391    393     SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*'
   392    394   } {{204 1 3 3 0} {204 1 3 3 0} {204 1 3 3 0}}
   393    395   
   394    396   # Corruption related tests.
          397  +sqlite3_db_config db DEFENSIVE 0
   395    398   do_execsql_test  8.4.1.1 { UPDATE t11_stat SET value = X'0000'; }
   396    399   do_catchsql_test 8.5.1.2 {
   397    400     SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*'
   398    401   } {1 {database disk image is malformed}}
   399    402   
   400    403   do_execsql_test  8.4.2.1 { UPDATE t11_stat SET value = X'00'; }
   401    404   do_catchsql_test 8.5.2.2 {

Changes to test/fts3misc.test.

   156    156     }
   157    157     do_execsql_test 4.1 {
   158    158       SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
   159    159     } {8000}
   160    160     do_execsql_test 4.2 {
   161    161       SELECT quote(value) from t4_stat where id=0
   162    162     } {X'C03EC0B204C0A608'}
          163  +  sqlite3_db_config db DEFENSIVE 0
   163    164     do_execsql_test 4.3 {
   164    165       UPDATE t4_stat SET value = X'C03EC0B204C0A60800' WHERE id=0;
   165    166     }
   166    167     do_catchsql_test 4.4 {
   167    168       SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
   168    169     } {1 {database disk image is malformed}}
   169    170     do_execsql_test 4.5 {

Changes to test/fts3query.test.

   163    163     illegal first argument to %s
   164    164   } {
   165    165     1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo
   166    166     2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'"   offsets
   167    167     3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'"   snippet
   168    168     4 "SELECT optimize(content) FROM t2 WHERE t2 MATCH 'history'"  optimize
   169    169   }
          170  +sqlite3_db_config db DEFENSIVE 0
   170    171   do_execsql_test 5.4.0 { UPDATE t2_content SET c0content = X'1234' }
   171    172   do_select_tests 5.4 -errorformat {
   172    173     illegal first argument to %s
   173    174   } {
   174    175     1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo
   175    176     2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'"   offsets
   176    177     3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'"   snippet

Changes to test/fts3snippet.test.

   180    180     do_offsets_test $T.2.1 {twohundred} [list 1 0 $off 10]
   181    181   
   182    182     set off [string first "onehundred " $numbers]
   183    183     do_offsets_test $T.2.2 {onehundred} \
   184    184       [list 0 0 $off 10 1 0 $off 10] [list 0 0 $off 10]
   185    185   
   186    186     # Test a corruption case:
          187  +  sqlite3_db_config db DEFENSIVE 0
   187    188     execsql { UPDATE ft_content SET c1b = 'hello world' WHERE c1b = $numbers }
   188    189     do_error_test $T.2.3 {
   189    190       SELECT offsets(ft) FROM ft WHERE ft MATCH 'onehundred'
   190    191     } {database disk image is malformed}
   191    192     
   192    193     ##########################################################################
   193    194     # Test the snippet function.

Changes to test/fts4check.test.

    62     62     }
    63     63     3 {
    64     64       DELETE FROM t1_segdir WHERE level=0 AND idx=(
    65     65         SELECT max(idx) FROM t1_segdir WHERE level=0
    66     66       );
    67     67     }
    68     68   } {
           69  +  sqlite3_db_config db DEFENSIVE 0
    69     70     do_execsql_test  1.2.1.$tn "BEGIN; $disruption"
    70     71     do_catchsql_test 1.2.2.$tn {
    71     72       INSERT INTO t1 (t1) VALUES('integrity-check')
    72     73     } {1 {database disk image is malformed}}
    73     74     do_execsql_test  1.2.3.$tn "ROLLBACK"
    74     75   }
    75     76   
................................................................................
    96     97     }
    97     98     3 {
    98     99       DELETE FROM t2_segdir WHERE level=0 AND idx=(
    99    100         SELECT max(idx) FROM t2_segdir WHERE level=1024
   100    101       );
   101    102     }
   102    103   } {
          104  +  sqlite3_db_config db DEFENSIVE 0
   103    105     do_execsql_test  2.2.1.$tn "BEGIN; $disruption"
   104    106     do_catchsql_test 2.2.2.$tn {
   105    107       INSERT INTO t2 (t2) VALUES('integrity-check')
   106    108     } {1 {database disk image is malformed}}
   107    109     do_execsql_test  2.2.3.$tn "ROLLBACK"
   108    110   }
   109    111   
................................................................................
   141    143     }
   142    144     2 {
   143    145       UPDATE t3_content SET langid=langid+1 WHERE rowid = (
   144    146         SELECT max(rowid) FROM t3_content
   145    147       )
   146    148     }
   147    149   } {
          150  +  sqlite3_db_config db DEFENSIVE 0
   148    151     do_execsql_test  3.2.1.$tn "BEGIN; $disruption"
   149    152     do_catchsql_test 3.2.2.$tn {
   150    153       INSERT INTO t3 (t3) VALUES('integrity-check')
   151    154     } {1 {database disk image is malformed}}
   152    155     do_execsql_test  3.2.3.$tn "ROLLBACK"
   153    156   }
   154    157   
................................................................................
   159    162   #
   160    163   do_execsql_test 4.0 {
   161    164     CREATE VIRTUAL TABLE t4 USING fts4(a, b, c, notindexed=b);
   162    165     INSERT INTO t4 VALUES('text one', 'text two', 'text three');
   163    166     INSERT INTO t4(t4) VALUES('integrity-check');
   164    167   }
   165    168   
          169  +sqlite3_db_config db DEFENSIVE 0
   166    170   do_execsql_test 4.1 {
   167    171     PRAGMA writable_schema = 1;
   168    172     UPDATE sqlite_master 
   169    173       SET sql = 'CREATE VIRTUAL TABLE t4 USING fts4(a, b, c)' 
   170    174       WHERE name = 't4';
   171    175   }
   172    176   
................................................................................
   193    197     INSERT INTO t5 VALUES('and the stockmen tell the story of his ride');
   194    198   }
   195    199   
   196    200   do_execsql_test 5.1 {
   197    201     INSERT INTO t5(t5) VALUES('integrity-check');
   198    202   } {}
   199    203   
          204  +sqlite3_db_config db DEFENSIVE 0
   200    205   do_catchsql_test 5.2 {
   201    206     INSERT INTO t5_content VALUES(5, 'his hardy mountain pony');
   202    207     INSERT INTO t5(t5) VALUES('integrity-check');
   203    208   } {1 {database disk image is malformed}}
   204    209   
   205    210   do_execsql_test 5.3 ROLLBACK
   206    211   
   207    212   do_execsql_test 5.4 {
   208    213     CREATE VIRTUAL TABLE t5 USING fts4(a, prefix="1,2,3");
   209    214     INSERT INTO t5(t5) VALUES('integrity-check');
   210    215   } {}
   211    216   
   212    217   finish_test

Changes to test/fts4growth.test.

    21     21   ifcapable !fts3 {
    22     22     finish_test
    23     23     return
    24     24   }
    25     25   
    26     26   source $testdir/genesis.tcl
    27     27   
           28  +sqlite3_db_config db DEFENSIVE 0
    28     29   do_execsql_test 1.1 { CREATE VIRTUAL TABLE x1 USING fts3; }
    29     30   
    30     31   do_test 1.2 {
    31     32     foreach L {
    32     33       {"See here, young man," said Mulga Bill, "from Walgett to the sea,}
    33     34       {From Conroy's Gap to Castlereagh, there's none can ride like me.}
    34     35       {I'm good all round at everything as everybody knows,}

Changes to test/fts4merge.test.

   152    152       } $expect
   153    153     }
   154    154     
   155    155     do_execsql_test 4.4.1 {
   156    156       SELECT quote(value) FROM t4_stat WHERE rowid=1
   157    157     } {X'0006'}
   158    158     
          159  +  sqlite3_db_config db DEFENSIVE 0
   159    160     do_execsql_test 4.4.2 {
   160    161       DELETE FROM t4_stat WHERE rowid=1;
   161    162       INSERT INTO t4(t4) VALUES('merge=1,12');
   162    163       SELECT level, group_concat(idx, ' ') FROM t4_segdir GROUP BY level;
   163    164     } "0 {0 1 2 3 4 5}                     1 0"
   164    165     
   165    166     

Changes to test/fts4opt.test.

    33     33   # Argument $db is an open database handle. $tbl is the name of an FTS3/4
    34     34   # table with the database. This command rearranges the contents of the
    35     35   # %_segdir table so that all segments within each index are on the same
    36     36   # level. This means that the 'merge' command can then be used for an
    37     37   # incremental optimize routine.
    38     38   #
    39     39   proc prepare_for_optimize {db tbl} {
           40  +  sqlite3_db_config $db DEFENSIVE 0
    40     41     $db eval [string map [list % $tbl] {
    41     42       BEGIN;
    42     43         CREATE TEMP TABLE tmp_segdir(
    43     44           level, idx, start_block, leaves_end_block, end_block, root
    44     45         );
    45     46   
    46     47         INSERT INTO temp.tmp_segdir 

Changes to test/index.test.

   622    622   # tested somewhere.
   623    623   do_test index-18.1 {
   624    624     catchsql {
   625    625       CREATE TABLE sqlite_t1(a, b, c);
   626    626     }
   627    627   } {1 {object name reserved for internal use: sqlite_t1}}
   628    628   do_test index-18.1.2 {
   629         -  sqlite3_db_config db DEFENSIVE 1
   630    629     catchsql {
   631    630       CREATE TABLE sqlite_t1(a, b, c);
   632    631     }
   633    632   } {1 {object name reserved for internal use: sqlite_t1}}
   634    633   sqlite3_db_config db DEFENSIVE 0
   635    634   do_test index-18.2 {
   636    635     catchsql {

Changes to test/index3.test.

    79     79   
    80     80   
    81     81   
    82     82   # This test corrupts the database file so it must be the last test
    83     83   # in the series.
    84     84   #
    85     85   do_test index3-99.1 {
           86  +  sqlite3_db_config db DEFENSIVE 0
    86     87     execsql {
    87     88       PRAGMA writable_schema=on;
    88     89       UPDATE sqlite_master SET sql='nonsense' WHERE name='t1d'
    89     90     }
    90     91     db close
    91     92     catch { sqlite3 db test.db }
    92     93     catchsql { DROP INDEX t1c }
    93     94   } {1 {malformed database schema (t1d)}}
    94     95   
    95     96   finish_test

Changes to test/misc1.test.

   655    655     SELECT ""+3 FROM (SELECT ""+5);
   656    656   } {3}
   657    657   
   658    658   # 2015-04-19: NULL pointer dereference on a corrupt schema
   659    659   #
   660    660   db close
   661    661   sqlite3 db :memory:
          662  +sqlite3_db_config db DEFENSIVE 0
   662    663   do_execsql_test misc1-23.1 {
   663    664     CREATE TABLE t1(x);
   664    665     PRAGMA writable_schema=ON;
   665    666     UPDATE sqlite_master SET sql='CREATE table t(d CHECK(T(#0)';
   666    667     BEGIN;
   667    668     CREATE TABLE t2(y);
   668    669     ROLLBACK;
................................................................................
   670    671   } {}
   671    672   
   672    673   # 2015-04-19:  Faulty assert() statement
   673    674   #
   674    675   db close
   675    676   database_may_be_corrupt
   676    677   sqlite3 db :memory:
          678  +sqlite3_db_config db DEFENSIVE 0
   677    679   do_catchsql_test misc1-23.2 {
   678    680     CREATE TABLE t1(x UNIQUE);
   679    681     PRAGMA writable_schema=ON;
   680    682     UPDATE sqlite_master SET sql='CREATE TABLE IF not EXISTS t(c)';
   681    683     BEGIN;
   682    684     CREATE TABLE t2(x);
   683    685     ROLLBACK;
   684    686     DROP TABLE F;
   685    687   } {1 {no such table: F}}
   686    688   db close
   687    689   sqlite3 db :memory:
          690  +sqlite3_db_config db DEFENSIVE 0
   688    691   do_catchsql_test misc1-23.3 {
   689    692     CREATE TABLE t1(x UNIQUE);
   690    693     PRAGMA writable_schema=ON;
   691    694     UPDATE sqlite_master SET sql='CREATE table y(a TEXT, a TEXT)';
   692    695     BEGIN;
   693    696     CREATE TABLE t2(y);
   694    697     ROLLBACK;

Changes to test/misc4.test.

   208    208     }
   209    209   } {1}
   210    210   
   211    211   # 2015-05-15.  Error message formatting problem.
   212    212   #
   213    213   db close
   214    214   sqlite3 db :memory:
          215  +sqlite3_db_config db DEFENSIVE 0
   215    216   do_catchsql_test misc4-7.1 {
   216    217     CREATE TABLE t7(x);
   217    218     PRAGMA writable_schema=ON;
   218    219     UPDATE sqlite_master SET sql='CREATE TABLE [M%s%s%s%s%s%s%s%s%s%s%s%s%s';
   219    220     VACUUM;
   220    221   } {1 {unrecognized token: "[M%s%s%s%s%s%s%s%s%s%s%s%s%s"}}
   221    222   

Changes to test/misc5.test.

   586    586   } {1 {parser stack overflow}}
   587    587   
   588    588   # Parser stack overflow is silently ignored when it occurs while parsing the
   589    589   # schema and PRAGMA writable_schema is turned on.
   590    590   #
   591    591   do_test misc5-7.2 {
   592    592     sqlite3 db2 :memory:
          593  +  sqlite3_db_config db2 DEFENSIVE 0
   593    594     catchsql {
   594    595       CREATE TABLE t1(x UNIQUE);
   595    596       PRAGMA writable_schema=ON;
   596    597       UPDATE sqlite_master SET sql='CREATE table t(o CHECK(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((;VALUES(o)';
   597    598       BEGIN;
   598    599       CREATE TABLE t2(y);
   599    600       ROLLBACK;

Changes to test/misc7.test.

   430    430         }
   431    431       } {0 32}
   432    432       
   433    433       # sqlite3_test_control_pending_page [expr ($::sqlite_pending_byte / 1024) + 1]
   434    434       set ::pending_byte_page [expr ($::sqlite_pending_byte / 1024) + 1]
   435    435       sqlite3_test_control_pending_byte $::sqlite_pending_byte 
   436    436       do_test misc7-17.3 {
          437  +      sqlite3_db_config db DEFENSIVE 0
   437    438         db eval {
   438    439           pragma writable_schema = true;
   439    440           UPDATE sqlite_master 
   440    441             SET rootpage = $pending_byte_page
   441    442             WHERE type = 'table' AND name = 't3';
   442    443         }
   443    444         execsql {

Changes to test/mjournal.test.

   156    156     BEGIN;
   157    157       INSERT INTO t1 VALUES(1);
   158    158       INSERT INTO t4 VALUES(1);
   159    159     COMMIT;
   160    160   } {0}
   161    161   
   162    162   finish_test
   163         -

Changes to test/notnull.test.

   602    602   do_uses_op_next_test notnull-6.7 "SELECT * FROM t7 WHERE a IS ?" 0
   603    603   do_uses_op_next_test notnull-6.8 "SELECT * FROM t8 WHERE a IS ?" 0
   604    604   
   605    605   do_uses_op_next_test notnull-6.9 "SELECT * FROM t8 WHERE a IS ?" 0
   606    606   do_uses_op_next_test notnull-6.10 "SELECT * FROM t8 WHERE a IS ?" 0
   607    607   
   608    608   finish_test
   609         -

Changes to test/pager1.test.

  1875   1875       INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1;
  1876   1876       INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1;
  1877   1877     }
  1878   1878   } {}
  1879   1879   do_test pager1-18.2 {
  1880   1880     set root [db one "SELECT rootpage FROM sqlite_master"]
  1881   1881     set lockingpage [expr (0x10000/1024) + 1]
         1882  +  sqlite3_db_config db DEFENSIVE 0
  1882   1883     execsql {
  1883   1884       PRAGMA writable_schema = 1;
  1884   1885       UPDATE sqlite_master SET rootpage = $lockingpage;
  1885   1886     }
  1886   1887     sqlite3 db2 test.db
  1887   1888     catchsql { SELECT count(*) FROM t1 } db2
  1888   1889   } {1 {database disk image is malformed}}
................................................................................
  1927   1928     hexio_write test.db [expr ($pgno-1)*1024] 90000000
  1928   1929     sqlite3 db2 test.db
  1929   1930     catchsql { SELECT length(x||'') FROM t2 } db2
  1930   1931   } {1 {database disk image is malformed}}
  1931   1932   db2 close
  1932   1933   do_test pager1-18.5 {
  1933   1934     sqlite3 db ""
         1935  +  sqlite3_db_config db DEFENSIVE 0
  1934   1936     execsql {
  1935   1937       CREATE TABLE t1(a, b);
  1936   1938       CREATE TABLE t2(a, b);
  1937   1939       PRAGMA writable_schema = 1;
  1938   1940       UPDATE sqlite_master SET rootpage=5 WHERE tbl_name = 't1';
  1939   1941       PRAGMA writable_schema = 0;
  1940   1942       ALTER TABLE t1 RENAME TO x1;

Changes to test/parser1.test.

    24     24   } {1 {syntax error after column name "b"}}
    25     25   
    26     26   
    27     27   # Verify that a legacy schema in the sqlite_master file is allowed to have
    28     28   # COLLATE, ASC, and DESC keywords on the id list of a FK constraint, and that
    29     29   # those keywords are silently ignored.
    30     30   #
           31  +sqlite3_db_config db DEFENSIVE 0
    31     32   do_execsql_test parser1-1.2 {
    32     33     CREATE TABLE t1(
    33     34       a TEXT PRIMARY KEY,
    34     35       b TEXT,
    35     36       FOREIGN KEY(b) REFERENCES t1(a)
    36     37     );
    37     38     INSERT INTO t1 VALUES('abc',NULL),('xyz','abc');

Changes to test/pragma.test.

   493    493       db eval {PRAGMA integrity_check}
   494    494     } {ok}
   495    495   }
   496    496   
   497    497   # Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL
   498    498   # constraint violations.
   499    499   #
          500  +sqlite3_db_config db DEFENSIVE 0
   500    501   do_execsql_test pragma-3.20 {
   501    502     CREATE TABLE t1(a,b);
   502    503     CREATE INDEX t1a ON t1(a);
   503    504     INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6);
   504    505     PRAGMA writable_schema=ON;
   505    506     UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)'
   506    507      WHERE name='t1a';

Changes to test/resetdb.test.

    61     61       PRAGMA page_count;
    62     62     } db2
    63     63   } {210 6000 ok delete 8}
    64     64   
    65     65   do_test 200 {
    66     66     # Thoroughly corrupt the database file by overwriting the first
    67     67     # page with randomness.
           68  +  sqlite3_db_config db DEFENSIVE 0
    68     69     catchsql {
    69     70       UPDATE sqlite_dbpage SET data=randomblob(4096) WHERE pgno=1;
    70     71       PRAGMA quick_check;
    71     72     }
    72     73   } {1 {unsupported file format}}
    73     74   do_test 201 {
    74     75     catchsql {
................................................................................
   121    122       PRAGMA journal_mode;
   122    123       PRAGMA page_size;
   123    124       PRAGMA page_count;
   124    125     } db2
   125    126   } {210 26000 ok wal 8192 12}
   126    127   
   127    128   # Corrupt the database again
          129  +sqlite3_db_config db DEFENSIVE 0
   128    130   do_catchsql_test 320 {
   129    131     UPDATE sqlite_dbpage SET data=randomblob(8192) WHERE pgno=1;
   130    132     PRAGMA quick_check
   131    133   } {1 {file is not a database}}
   132    134   
   133    135   do_test 330 {
   134    136     catchsql {
................................................................................
   224    226   } {19 ok}
   225    227   
   226    228   if {[nonzero_reserved_bytes]} {
   227    229     finish_test
   228    230     return
   229    231   }
   230    232   
          233  +sqlite3_db_config db DEFENSIVE 0
   231    234   do_execsql_test 710 {
   232    235     UPDATE sqlite_dbpage SET data=
   233    236       X'53514C69746520666F726D61742033000200030100402020000000000000001300000000000000000000000300000004000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000D00000003017C0001D801AC017C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002E03061715110145696E6465787431626374310443524541544520494E4445582074316263204F4E20743128622C63292A0206171311013F696E64657874316174310343524541544520494E44455820743161204F4E20743128612926010617111101397461626C657431743102435245415445205441424C4520743128612C622C6329' WHERE pgno=1;
   234    237   }
   235    238   
   236    239   do_execsql_test 720 {
   237    240     PRAGMA integrity_check;

Changes to test/shared8.test.

    58     58       INSERT INTO t1 VALUES(4, 4);
    59     59       CREATE VIEW v1 AS SELECT a, roman(b) FROM t1;
    60     60       SELECT * FROM v1;
    61     61     } db1
    62     62   } {1 i 2 ii 3 iii 4 iv}
    63     63   
    64     64   do_test 1.1 {
           65  +  sqlite3_db_config db1 DEFENSIVE 0
    65     66     execsql { 
    66     67       PRAGMA writable_schema = 1;
    67     68       DELETE FROM sqlite_master WHERE 1;
    68     69       PRAGMA writable_schema = 0;
    69     70       SELECT * FROM sqlite_master;
    70     71     } db1
    71     72   } {}

Changes to test/snapshot2.test.

   234    234     execsql { INSERT INTO t2 VALUES('jkl') } 
   235    235     execsql BEGIN db2
   236    236     list [catch { sqlite3_snapshot_open_blob db2 main $snap } msg] $msg
   237    237   } {1 SQLITE_ERROR_SNAPSHOT}
   238    238   
   239    239   
   240    240   finish_test
   241         -

Changes to test/snapshot3.test.

    93     93   
    94     94   do_test 1.8 {
    95     95     execsql BEGIN db3
    96     96     list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
    97     97   } {1 SQLITE_ERROR_SNAPSHOT}
    98     98   
    99     99   finish_test
   100         -

Changes to test/snapshot4.test.

    68     68     execsql {
    69     69       SELECT count(*) FROM t1
    70     70     } 
    71     71   } {100}
    72     72   
    73     73   
    74     74   finish_test
    75         -

Changes to test/snapshot_up.test.

   177    177     set ::res
   178    178   } {1 SQLITE_BUSY}
   179    179   
   180    180   sqlite3_snapshot_free $::snap1
   181    181   sqlite3_snapshot_free $::snap2
   182    182   
   183    183   finish_test
   184         -

Changes to test/swarmvtab3.test.

   227    227   }
   228    228   
   229    229   db close
   230    230   forcedelete {*}[glob test.db*]
   231    231   forcedelete {*}[glob test_remote.db*]
   232    232   
   233    233   finish_test
   234         -

Changes to test/swarmvtabfault.test.

    59     59   } -body {
    60     60     execsql { SELECT a FROM xyz }
    61     61   } -test {
    62     62     faultsim_test_result {0 {1 2 9}} {1 {sql error: out of memory}}
    63     63   }
    64     64   
    65     65   finish_test
    66         -

Changes to test/table.test.

   272    272     }
   273    273   } {}
   274    274   
   275    275   do_test table-5.2.2 {
   276    276     db close
   277    277     forcedelete test.db
   278    278     sqlite3 db test.db
          279  +  sqlite3_db_config db DEFENSIVE 0
   279    280     db eval {
   280    281       CREATE TABLE t0(a,b);
   281    282       CREATE INDEX t ON t0(a);
   282    283       PRAGMA writable_schema=ON;
   283    284       UPDATE sqlite_master SET sql='CREATE TABLE a.b(a UNIQUE';
   284    285       BEGIN;
   285    286       CREATE TABLE t1(x);

Changes to test/trigger7.test.

   102    102     }
   103    103   } {}
   104    104   
   105    105   # This test corrupts the database file so it must be the last test
   106    106   # in the series.
   107    107   #
   108    108   do_test trigger7-99.1 {
          109  +  sqlite3_db_config db DEFENSIVE 0
   109    110     execsql {
   110    111       PRAGMA writable_schema=on;
   111    112       UPDATE sqlite_master SET sql='nonsense';
   112    113     }
   113    114     db close
   114    115     catch { sqlite3 db test.db }
   115    116     catchsql { DROP TRIGGER t2r5 }
   116    117   } {/1 {malformed database schema .*}/}
   117    118   
   118    119   finish_test

Changes to test/triggerE.test.

    64     64     do_catchsql_test 1.2.$tn "CREATE TEMP TRIGGER tr1 $defn" [list 1 $errmsg]
    65     65   }
    66     66   
    67     67   #-------------------------------------------------------------------------
    68     68   # Test that variable references within trigger definitions loaded from 
    69     69   # the sqlite_master table are automatically converted to NULL.
    70     70   #
           71  +sqlite3_db_config db DEFENSIVE 0
    71     72   do_execsql_test 2.1 {
    72     73     PRAGMA writable_schema = 1;
    73     74     INSERT INTO sqlite_master VALUES('trigger', 'tr1', 't1', 0,
    74     75       'CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN 
    75     76           INSERT INTO t2 VALUES(?1, ?2); 
    76     77        END'
    77     78     );

Changes to test/unionvtab.test.

   451    451   } {five six seven eight nine}
   452    452   
   453    453   do_execsql_test 5.4 {
   454    454     SELECT * FROM cc WHERE two LIKE '6'
   455    455   } {six 6}
   456    456   
   457    457   finish_test
   458         -

Changes to test/unionvtabfault.test.

    77     77   } -test {
    78     78     faultsim_test_result {0 {}} {1 {initialization of unionvtab failed: }}
    79     79   }
    80     80   
    81     81   
    82     82   
    83     83   finish_test
    84         -

Changes to test/vtab1.test.

  1249   1249   
  1250   1250   # The following test case exposes an instance in sqlite3_declare_vtab()
  1251   1251   # an error message was set using a call similar to sqlite3_mprintf(zErr),
  1252   1252   # where zErr is an arbitrary string. This is no good if the string contains
  1253   1253   # characters that can be mistaken for printf() formatting directives.
  1254   1254   #
  1255   1255   do_test vtab1-17.1 {
         1256  +  sqlite3_db_config db DEFENSIVE 0
  1256   1257     execsql { 
  1257   1258       PRAGMA writable_schema = 1;
  1258   1259       INSERT INTO sqlite_master VALUES(
  1259   1260         'table', 't3', 't3', 0, 'INSERT INTO "%s%s" VALUES(1)'
  1260   1261       );
  1261   1262     }
  1262   1263     catchsql { CREATE VIRTUAL TABLE t4 USING echo(t3); }

Changes to test/wherelimit2.test.

   293    293     set ::log {}
   294    294     execsql { UPDATE "v w" SET "a b" = "a b" || 'x' ORDER BY "a b" LIMIT 5; }
   295    295     set ::log
   296    296   } {ax a bx b cx c dx d ex a}
   297    297   
   298    298   
   299    299   finish_test
   300         -

Changes to test/window5.test.

    90     90   } {1 {sum() may not be used as a window function}}
    91     91   do_execsql_test 3.1 {
    92     92     SELECT sum(a) FROM t1;
    93     93   } {21}
    94     94   
    95     95   
    96     96   finish_test
    97         -

Changes to test/windowfault.test.

   159    159       ORDER BY a;
   160    160     }
   161    161   } -test {
   162    162     faultsim_test_result {0 {1 2 5 6 9 10}}
   163    163   }
   164    164   
   165    165   finish_test
   166         -

Changes to test/zipfile2.test.

   237    237     INSERT INTO temp.zip (name,data) VALUES ('test1','test'); 
   238    238     INSERT INTO temp.zip (name,data) VALUES ('test2','test'); 
   239    239     UPDATE OR REPLACE zip SET name='test2' WHERE name='test1';
   240    240     SELECT name FROM zip;
   241    241   } {test2}
   242    242   
   243    243   finish_test
   244         -

Changes to tool/genfkey.test.

   347    347   } {1 {constraint failed}}
   348    348   do_test genfkey-6.7 {
   349    349     execsql {
   350    350       SELECT * FROM parent;
   351    351       SELECT * FROM child;
   352    352     }
   353    353   } {1 1}
   354         -