/ Check-in [86685679]
Login

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

Overview
Comment:Merge changes from begin-concurrent-wal2. Also modify the unix-excl shm-locks on this branch so that it is not an error to attempt to release an EXCLUSIVE lock that is not held.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent-pnu-wal2
Files: files | file ages | folders
SHA3-256: 86685679b4cff94704fe4b52364f25f579d98ee725407cfe3bd2bbf7ecd651a8
User & Date: dan 2019-01-02 19:46:46
Wiki:begin-concurrent-pnu-wal2
Context
2019-01-04
17:12
Update the "tserver" program to report the amount of time spent in COMMIT commands. check-in: cf494b41 user: dan tags: begin-concurrent-pnu-wal2
2019-01-02
19:46
Merge changes from begin-concurrent-wal2. Also modify the unix-excl shm-locks on this branch so that it is not an error to attempt to release an EXCLUSIVE lock that is not held. check-in: 86685679 user: dan tags: begin-concurrent-pnu-wal2
17:08
Reinstate assert() statements in os_unix.c that were removed to allow wal-mode SHARED locks to be taken over more than one locking slot (this branch no longer does that, so the assert() statements can go back in). check-in: fcb7348b user: dan tags: begin-concurrent-wal2
2018-12-18
19:46
Add the "mutexfree-shmlock" patch to this branch. check-in: c3191fc8 user: dan tags: begin-concurrent-pnu-wal2
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/expert/expert1.test.

   239    239     CREATE TABLE t7(a, b);
   240    240   } {
   241    241     SELECT * FROM t7 WHERE a=? OR b=?
   242    242   } {
   243    243     CREATE INDEX t7_idx_00000062 ON t7(b);
   244    244     CREATE INDEX t7_idx_00000061 ON t7(a);
   245    245     MULTI-INDEX OR
   246         -    SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?) 
   247         -    SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
          246  +    INDEX 1
          247  +      SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?) 
          248  +    INDEX 2
          249  +      SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
   248    250   }
   249    251   
   250    252   # rowid terms.
   251    253   #
   252    254   do_setup_rec_test $tn.13.1 {
   253    255     CREATE TABLE t8(a, b);
   254    256   } {

Changes to ext/fts3/fts3.c.

   334    334     }while( vu!=0 );
   335    335     q[-1] &= 0x7f;  /* turn off high bit in final byte */
   336    336     assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
   337    337     return (int) (q - (unsigned char *)p);
   338    338   }
   339    339   
   340    340   #define GETVARINT_STEP(v, ptr, shift, mask1, mask2, var, ret) \
   341         -  v = (v & mask1) | ( (*ptr++) << shift );                    \
          341  +  v = (v & mask1) | ( (*(ptr++)) << shift );  \
   342    342     if( (v & mask2)==0 ){ var = v; return ret; }
   343    343   #define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
   344    344     v = (*ptr++);                                               \
   345    345     if( (v & mask2)==0 ){ var = v; return ret; }
   346    346   
   347    347   /* 
   348    348   ** Read a 64-bit variable-length integer from memory starting at p[0].
................................................................................
   372    372   }
   373    373   
   374    374   /*
   375    375   ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to 
   376    376   ** a non-negative 32-bit integer before it is returned.
   377    377   */
   378    378   int sqlite3Fts3GetVarint32(const char *p, int *pi){
          379  +  const unsigned char *ptr = (const unsigned char*)p;
   379    380     u32 a;
   380    381   
   381    382   #ifndef fts3GetVarint32
   382         -  GETVARINT_INIT(a, p, 0,  0x00,     0x80, *pi, 1);
          383  +  GETVARINT_INIT(a, ptr, 0,  0x00,     0x80, *pi, 1);
   383    384   #else
   384         -  a = (*p++);
          385  +  a = (*ptr++);
   385    386     assert( a & 0x80 );
   386    387   #endif
   387    388   
   388         -  GETVARINT_STEP(a, p, 7,  0x7F,     0x4000, *pi, 2);
   389         -  GETVARINT_STEP(a, p, 14, 0x3FFF,   0x200000, *pi, 3);
   390         -  GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
          389  +  GETVARINT_STEP(a, ptr, 7,  0x7F,     0x4000, *pi, 2);
          390  +  GETVARINT_STEP(a, ptr, 14, 0x3FFF,   0x200000, *pi, 3);
          391  +  GETVARINT_STEP(a, ptr, 21, 0x1FFFFF, 0x10000000, *pi, 4);
   391    392     a = (a & 0x0FFFFFFF );
   392         -  *pi = (int)(a | ((u32)(*p & 0x07) << 28));
          393  +  *pi = (int)(a | ((u32)(*ptr & 0x07) << 28));
   393    394     assert( 0==(a & 0x80000000) );
   394    395     assert( *pi>=0 );
   395    396     return 5;
   396    397   }
   397    398   
   398    399   /*
   399    400   ** Return the number of bytes required to encode v as a varint

Changes to ext/fts3/fts3_unicode2.c.

   196    196       'f',       'g',       'h',       'h',       'i',       'i'|HIBIT, 
   197    197       'k',       'l',       'l'|HIBIT, 'l',       'm',       'n',       
   198    198       'o'|HIBIT, 'p',       'r',       'r'|HIBIT, 'r',       's',       
   199    199       's'|HIBIT, 't',       'u',       'u'|HIBIT, 'v',       'w',       
   200    200       'w',       'x',       'y',       'z',       'h',       't',       
   201    201       'w',       'y',       'a',       'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT, 
   202    202       'e',       'e'|HIBIT, 'e'|HIBIT, 'i',       'o',       'o'|HIBIT, 
   203         -    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',  
          203  +    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',       
   204    204     };
   205    205   
   206    206     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
   207    207     int iRes = 0;
   208    208     int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
   209    209     int iLo = 0;
   210    210     while( iHi>=iLo ){
................................................................................
   227    227   ** is a diacritical modifier character.
   228    228   */
   229    229   int sqlite3FtsUnicodeIsdiacritic(int c){
   230    230     unsigned int mask0 = 0x08029FDF;
   231    231     unsigned int mask1 = 0x000361F8;
   232    232     if( c<768 || c>817 ) return 0;
   233    233     return (c < 768+32) ?
   234         -      (mask0 & (1 << (c-768))) :
   235         -      (mask1 & (1 << (c-768-32)));
          234  +      (mask0 & ((unsigned int)1 << (c-768))) :
          235  +      (mask1 & ((unsigned int)1 << (c-768-32)));
   236    236   }
   237    237   
   238    238   
   239    239   /*
   240    240   ** Interpret the argument as a unicode codepoint. If the codepoint
   241    241   ** is an upper case character that has a lower case equivalent,
   242    242   ** return the codepoint corresponding to the lower case version.

Changes to ext/fts3/fts3_write.c.

   392    392     sqlite3_stmt *pStmt;
   393    393   
   394    394     assert( SizeofArray(azSql)==SizeofArray(p->aStmt) );
   395    395     assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
   396    396     
   397    397     pStmt = p->aStmt[eStmt];
   398    398     if( !pStmt ){
          399  +    int f = SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB;
   399    400       char *zSql;
   400    401       if( eStmt==SQL_CONTENT_INSERT ){
   401    402         zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName, p->zWriteExprlist);
   402    403       }else if( eStmt==SQL_SELECT_CONTENT_BY_ROWID ){
          404  +      f &= ~SQLITE_PREPARE_NO_VTAB;
   403    405         zSql = sqlite3_mprintf(azSql[eStmt], p->zReadExprlist);
   404    406       }else{
   405    407         zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName);
   406    408       }
   407    409       if( !zSql ){
   408    410         rc = SQLITE_NOMEM;
   409    411       }else{
   410         -      rc = sqlite3_prepare_v3(p->db, zSql, -1, SQLITE_PREPARE_PERSISTENT,
   411         -                              &pStmt, NULL);
          412  +      rc = sqlite3_prepare_v3(p->db, zSql, -1, f, &pStmt, NULL);
   412    413         sqlite3_free(zSql);
   413    414         assert( rc==SQLITE_OK || pStmt==0 );
   414    415         p->aStmt[eStmt] = pStmt;
   415    416       }
   416    417     }
   417    418     if( apVal ){
   418    419       int i;
................................................................................
  1404   1405     pReader->aDoclist = pNext;
  1405   1406     pReader->pOffsetList = 0;
  1406   1407   
  1407   1408     /* Check that the doclist does not appear to extend past the end of the
  1408   1409     ** b-tree node. And that the final byte of the doclist is 0x00. If either 
  1409   1410     ** of these statements is untrue, then the data structure is corrupt.
  1410   1411     */
  1411         -  if( (&pReader->aNode[pReader->nNode] - pReader->aDoclist)<pReader->nDoclist
         1412  +  if( pReader->nDoclist > pReader->nNode-(pReader->aDoclist-pReader->aNode)
  1412   1413      || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
  1413   1414     ){
  1414   1415       return FTS_CORRUPT_VTAB;
  1415   1416     }
  1416   1417     return SQLITE_OK;
  1417   1418   }
  1418   1419   
................................................................................
  1604   1605     const char *zRoot,              /* Buffer containing root node */
  1605   1606     int nRoot,                      /* Size of buffer containing root node */
  1606   1607     Fts3SegReader **ppReader        /* OUT: Allocated Fts3SegReader */
  1607   1608   ){
  1608   1609     Fts3SegReader *pReader;         /* Newly allocated SegReader object */
  1609   1610     int nExtra = 0;                 /* Bytes to allocate segment root node */
  1610   1611   
  1611         -  assert( iStartLeaf<=iEndLeaf );
         1612  +  assert( zRoot!=0 || nRoot==0 );
         1613  +#ifdef CORRUPT_DB
         1614  +  assert( zRoot!=0 || CORRUPT_DB );
         1615  +#endif
         1616  +
  1612   1617     if( iStartLeaf==0 ){
  1613   1618       nExtra = nRoot + FTS3_NODE_PADDING;
  1614   1619     }
  1615   1620   
  1616   1621     pReader = (Fts3SegReader *)sqlite3_malloc(sizeof(Fts3SegReader) + nExtra);
  1617   1622     if( !pReader ){
  1618   1623       return SQLITE_NOMEM;
................................................................................
  1625   1630     pReader->iEndBlock = iEndBlock;
  1626   1631   
  1627   1632     if( nExtra ){
  1628   1633       /* The entire segment is stored in the root node. */
  1629   1634       pReader->aNode = (char *)&pReader[1];
  1630   1635       pReader->rootOnly = 1;
  1631   1636       pReader->nNode = nRoot;
  1632         -    memcpy(pReader->aNode, zRoot, nRoot);
         1637  +    if( nRoot ) memcpy(pReader->aNode, zRoot, nRoot);
  1633   1638       memset(&pReader->aNode[nRoot], 0, FTS3_NODE_PADDING);
  1634   1639     }else{
  1635   1640       pReader->iCurrentBlock = iStartLeaf-1;
  1636   1641     }
  1637   1642     *ppReader = pReader;
  1638   1643     return SQLITE_OK;
  1639   1644   }

Changes to ext/fts3/unicode/mkunicode.tcl.

    59     59       incr i
    60     60   
    61     61       puts -nonewline [format "%5d" [expr ($iCode<<3) + $nRange-1]]
    62     62       puts -nonewline ", "
    63     63     }
    64     64     puts ""
    65     65     puts "  \};"
           66  +  puts "#define HIBIT ((char)0x80)"
    66     67     puts "  char aChar\[\] = \{"
    67     68     puts -nonewline "    '\\0',      "
    68     69     set i 1
    69     70     foreach c $aChar f $aFlag {
    70     71       if { $f } {
    71         -      set str "'$c'|0x80,  "
           72  +      set str "'$c'|HIBIT, "
    72     73       } else {
    73         -      set str "'$c'|0x00,  "
           74  +      set str "'$c',       "
    74     75       }
    75     76       if {$c == ""} { set str "'\\0',      " }
    76     77   
    77     78       if {($i % 6)==0} {puts "" ; puts -nonewline "    " }
    78     79       incr i
    79     80       puts -nonewline "$str"
    80     81     }
................................................................................
   130    131     puts "*/"
   131    132     puts "int ${zFunc}\(int c)\{"
   132    133     puts "  unsigned int mask0 = [format "0x%08X" $i1];"
   133    134     puts "  unsigned int mask1 = [format "0x%08X" $i2];"
   134    135   
   135    136     puts "  if( c<$iFirst || c>$iLast ) return 0;"
   136    137     puts "  return (c < $iFirst+32) ?"
   137         -  puts "      (mask0 & (1 << (c-$iFirst))) :"
   138         -  puts "      (mask1 & (1 << (c-$iFirst-32)));"
          138  +  puts "      (mask0 & ((unsigned int)1 << (c-$iFirst))) :"
          139  +  puts "      (mask1 & ((unsigned int)1 << (c-$iFirst-32)));"
   139    140     puts "\}"
   140    141   }
   141    142   
   142    143   
   143    144   #-------------------------------------------------------------------------
   144    145   
   145    146   proc an_load_separator_ranges {} {
................................................................................
   695    696     set aMapArray [intarray $aMap]
   696    697     set aDataArray [intarray $aData]
   697    698     puts [code {
   698    699       static u16 aFts5UnicodeBlock[] = {$aBlockArray};
   699    700       static u16 aFts5UnicodeMap[] = {$aMapArray};
   700    701       static u16 aFts5UnicodeData[] = {$aDataArray};
   701    702   
   702         -    int sqlite3Fts5UnicodeCategory(int iCode) { 
          703  +    int sqlite3Fts5UnicodeCategory(u32 iCode) { 
   703    704         int iRes = -1;
   704    705         int iHi;
   705    706         int iLo;
   706    707         int ret;
   707    708         u16 iKey;
   708    709   
   709    710         if( iCode>=(1<<20) ){
................................................................................
   778    779           if( aCP[iCP].iCode==i ){
   779    780             sqlite3Fts5UnicodeCatParse(aCP[iCP].zCat, aArray);
   780    781             iCP++;
   781    782           }else{
   782    783             aArray[0] = 1;
   783    784           }
   784    785   
   785         -        c = sqlite3Fts5UnicodeCategory(i);
          786  +        c = sqlite3Fts5UnicodeCategory((u32)i);
   786    787           if( aArray[c]==0 ){
   787    788             *piCode = i;
   788    789             return 1;
   789    790           }
   790    791         }
   791    792   
   792    793         return 0;

Changes to ext/fts5/fts5Int.h.

   784    784   /**************************************************************************
   785    785   ** Interface to automatically generated code in fts5_unicode2.c. 
   786    786   */
   787    787   int sqlite3Fts5UnicodeIsdiacritic(int c);
   788    788   int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic);
   789    789   
   790    790   int sqlite3Fts5UnicodeCatParse(const char*, u8*);
   791         -int sqlite3Fts5UnicodeCategory(int iCode);
          791  +int sqlite3Fts5UnicodeCategory(u32 iCode);
   792    792   void sqlite3Fts5UnicodeAscii(u8*, u8*);
   793    793   /*
   794    794   ** End of interface to code in fts5_unicode2.c.
   795    795   **************************************************************************/
   796    796   
   797    797   #endif

Changes to ext/fts5/fts5_expr.c.

  2549   2549       return;
  2550   2550     }
  2551   2551     memset(aArr, 0, sizeof(aArr));
  2552   2552     sqlite3Fts5UnicodeCatParse("L*", aArr);
  2553   2553     sqlite3Fts5UnicodeCatParse("N*", aArr);
  2554   2554     sqlite3Fts5UnicodeCatParse("Co", aArr);
  2555   2555     iCode = sqlite3_value_int(apVal[0]);
  2556         -  sqlite3_result_int(pCtx, aArr[sqlite3Fts5UnicodeCategory(iCode)]);
         2556  +  sqlite3_result_int(pCtx, aArr[sqlite3Fts5UnicodeCategory((u32)iCode)]);
  2557   2557   }
  2558   2558   
  2559   2559   static void fts5ExprFold(
  2560   2560     sqlite3_context *pCtx,          /* Function call context */
  2561   2561     int nArg,                       /* Number of args */
  2562   2562     sqlite3_value **apVal           /* Function arguments */
  2563   2563   ){

Changes to ext/fts5/fts5_index.c.

   686    686           rc = sqlite3_blob_read(p->pReader, aOut, nByte, 0);
   687    687         }
   688    688         if( rc!=SQLITE_OK ){
   689    689           sqlite3_free(pRet);
   690    690           pRet = 0;
   691    691         }else{
   692    692           /* TODO1: Fix this */
          693  +        pRet->p[nByte] = 0x00;
   693    694           pRet->szLeaf = fts5GetU16(&pRet->p[2]);
   694    695         }
   695    696       }
   696    697       p->rc = rc;
   697    698       p->nRead++;
   698    699     }
   699    700   
................................................................................
   725    726     Fts5Index *p,
   726    727     sqlite3_stmt **ppStmt,
   727    728     char *zSql
   728    729   ){
   729    730     if( p->rc==SQLITE_OK ){
   730    731       if( zSql ){
   731    732         p->rc = sqlite3_prepare_v3(p->pConfig->db, zSql, -1,
   732         -                                 SQLITE_PREPARE_PERSISTENT, ppStmt, 0);
          733  +          SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB,
          734  +          ppStmt, 0);
   733    735       }else{
   734    736         p->rc = SQLITE_NOMEM;
   735    737       }
   736    738     }
   737    739     sqlite3_free(zSql);
   738    740     return p->rc;
   739    741   }
................................................................................
   766    768   **
   767    769   **     DELETE FROM %_data WHERE id BETWEEN $iFirst AND $iLast
   768    770   */
   769    771   static void fts5DataDelete(Fts5Index *p, i64 iFirst, i64 iLast){
   770    772     if( p->rc!=SQLITE_OK ) return;
   771    773   
   772    774     if( p->pDeleter==0 ){
   773         -    int rc;
   774    775       Fts5Config *pConfig = p->pConfig;
   775    776       char *zSql = sqlite3_mprintf(
   776    777           "DELETE FROM '%q'.'%q_data' WHERE id>=? AND id<=?", 
   777    778             pConfig->zDb, pConfig->zName
   778    779       );
   779         -    if( zSql==0 ){
   780         -      rc = SQLITE_NOMEM;
   781         -    }else{
   782         -      rc = sqlite3_prepare_v3(pConfig->db, zSql, -1,
   783         -                              SQLITE_PREPARE_PERSISTENT, &p->pDeleter, 0);
   784         -      sqlite3_free(zSql);
   785         -    }
   786         -    if( rc!=SQLITE_OK ){
   787         -      p->rc = rc;
   788         -      return;
   789         -    }
          780  +    if( fts5IndexPrepareStmt(p, &p->pDeleter, zSql) ) return;
   790    781     }
   791    782   
   792    783     sqlite3_bind_int64(p->pDeleter, 1, iFirst);
   793    784     sqlite3_bind_int64(p->pDeleter, 2, iLast);
   794    785     sqlite3_step(p->pDeleter);
   795    786     p->rc = sqlite3_reset(p->pDeleter);
   796    787   }
................................................................................
   865    856     if( piCookie ) *piCookie = sqlite3Fts5Get32(pData);
   866    857     i = 4;
   867    858   
   868    859     /* Read the total number of levels and segments from the start of the
   869    860     ** structure record.  */
   870    861     i += fts5GetVarint32(&pData[i], nLevel);
   871    862     i += fts5GetVarint32(&pData[i], nSegment);
          863  +  if( nLevel>FTS5_MAX_SEGMENT   || nLevel<0
          864  +   || nSegment>FTS5_MAX_SEGMENT || nSegment<0
          865  +  ){
          866  +    return FTS5_CORRUPT;
          867  +  }
   872    868     nByte = (
   873    869         sizeof(Fts5Structure) +                    /* Main structure */
   874    870         sizeof(Fts5StructureLevel) * (nLevel-1)    /* aLevel[] array */
   875    871     );
   876    872     pRet = (Fts5Structure*)sqlite3Fts5MallocZero(&rc, nByte);
   877    873   
   878    874     if( pRet ){
................................................................................
   887    883         int iSeg;
   888    884   
   889    885         if( i>=nData ){
   890    886           rc = FTS5_CORRUPT;
   891    887         }else{
   892    888           i += fts5GetVarint32(&pData[i], pLvl->nMerge);
   893    889           i += fts5GetVarint32(&pData[i], nTotal);
   894         -        assert( nTotal>=pLvl->nMerge );
          890  +        if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT;
   895    891           pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc, 
   896    892               nTotal * sizeof(Fts5StructureSegment)
   897    893           );
          894  +        nSegment -= nTotal;
   898    895         }
   899    896   
   900    897         if( rc==SQLITE_OK ){
   901    898           pLvl->nSeg = nTotal;
   902    899           for(iSeg=0; iSeg<nTotal; iSeg++){
          900  +          Fts5StructureSegment *pSeg = &pLvl->aSeg[iSeg];
   903    901             if( i>=nData ){
   904    902               rc = FTS5_CORRUPT;
   905    903               break;
   906    904             }
   907         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].iSegid);
   908         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].pgnoFirst);
   909         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].pgnoLast);
          905  +          i += fts5GetVarint32(&pData[i], pSeg->iSegid);
          906  +          i += fts5GetVarint32(&pData[i], pSeg->pgnoFirst);
          907  +          i += fts5GetVarint32(&pData[i], pSeg->pgnoLast);
          908  +          if( pSeg->pgnoLast<pSeg->pgnoFirst ){
          909  +            rc = FTS5_CORRUPT;
          910  +            break;
          911  +          }
   910    912           }
          913  +        if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
          914  +        if( iLvl==nLevel-1 && pLvl->nMerge ) rc = FTS5_CORRUPT;
   911    915         }
   912    916       }
          917  +    if( nSegment!=0 && rc==SQLITE_OK ) rc = FTS5_CORRUPT;
          918  +
   913    919       if( rc!=SQLITE_OK ){
   914    920         fts5StructureRelease(pRet);
   915    921         pRet = 0;
   916    922       }
   917    923     }
   918    924   
   919    925     *ppOut = pRet;
................................................................................
  1643   1649   */
  1644   1650   static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
  1645   1651     u8 *a = pIter->pLeaf->p;        /* Buffer to read data from */
  1646   1652     int iOff = pIter->iLeafOffset;  /* Offset to read at */
  1647   1653     int nNew;                       /* Bytes of new data */
  1648   1654   
  1649   1655     iOff += fts5GetVarint32(&a[iOff], nNew);
  1650         -  if( iOff+nNew>pIter->pLeaf->nn ){
         1656  +  if( iOff+nNew>pIter->pLeaf->nn || nKeep>pIter->term.n ){
  1651   1657       p->rc = FTS5_CORRUPT;
  1652   1658       return;
  1653   1659     }
  1654   1660     pIter->term.n = nKeep;
  1655   1661     fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
         1662  +  assert( pIter->term.n<=pIter->term.nSpace );
  1656   1663     iOff += nNew;
  1657   1664     pIter->iTermLeafOffset = iOff;
  1658   1665     pIter->iTermLeafPgno = pIter->iLeafPgno;
  1659   1666     pIter->iLeafOffset = iOff;
  1660   1667   
  1661   1668     if( pIter->iPgidxOff>=pIter->pLeaf->nn ){
  1662   1669       pIter->iEndofDoclist = pIter->pLeaf->nn+1;
................................................................................
  1713   1720       pIter->iLeafPgno = pSeg->pgnoFirst-1;
  1714   1721       fts5SegIterNextPage(p, pIter);
  1715   1722     }
  1716   1723   
  1717   1724     if( p->rc==SQLITE_OK ){
  1718   1725       pIter->iLeafOffset = 4;
  1719   1726       assert_nc( pIter->pLeaf->nn>4 );
  1720         -    assert( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
         1727  +    assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
  1721   1728       pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
  1722   1729       fts5SegIterLoadTerm(p, pIter, 0);
  1723   1730       fts5SegIterLoadNPos(p, pIter);
  1724   1731     }
  1725   1732   }
  1726   1733   
  1727   1734   /*
................................................................................
  2302   2309         if( pIter->pLeaf==0 ) return;
  2303   2310         a = pIter->pLeaf->p;
  2304   2311         if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
  2305   2312           iPgidx = pIter->pLeaf->szLeaf;
  2306   2313           iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
  2307   2314           if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
  2308   2315             p->rc = FTS5_CORRUPT;
         2316  +          return;
  2309   2317           }else{
  2310   2318             nKeep = 0;
  2311   2319             iTermOff = iOff;
  2312   2320             n = pIter->pLeaf->nn;
  2313   2321             iOff += fts5GetVarint32(&a[iOff], nNew);
  2314   2322             break;
  2315   2323           }
  2316   2324         }
  2317   2325       }while( 1 );
  2318   2326     }
  2319   2327   
  2320   2328    search_success:
  2321         -
  2322   2329     pIter->iLeafOffset = iOff + nNew;
         2330  +  if( pIter->iLeafOffset>n ){
         2331  +    p->rc = FTS5_CORRUPT;
         2332  +    return;
         2333  +  }
  2323   2334     pIter->iTermLeafOffset = pIter->iLeafOffset;
  2324   2335     pIter->iTermLeafPgno = pIter->iLeafPgno;
  2325   2336   
  2326   2337     fts5BufferSet(&p->rc, &pIter->term, nKeep, pTerm);
  2327   2338     fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
  2328   2339   
  2329   2340     if( iPgidx>=n ){
................................................................................
  3570   3581         int i;
  3571   3582         u32 mask;
  3572   3583         memset(aUsed, 0, sizeof(aUsed));
  3573   3584         for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3574   3585           for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3575   3586             int iId = pStruct->aLevel[iLvl].aSeg[iSeg].iSegid;
  3576   3587             if( iId<=FTS5_MAX_SEGMENT ){
  3577         -            aUsed[(iId-1) / 32] |= 1 << ((iId-1) % 32);
         3588  +            aUsed[(iId-1) / 32] |= (u32)1 << ((iId-1) % 32);
  3578   3589             }
  3579   3590           }
  3580   3591         }
  3581   3592   
  3582   3593         for(i=0; aUsed[i]==0xFFFFFFFF; i++);
  3583   3594         mask = aUsed[i];
  3584         -      for(iSegid=0; mask & (1 << iSegid); iSegid++);
         3595  +      for(iSegid=0; mask & ((u32)1 << iSegid); iSegid++);
  3585   3596         iSegid += 1 + i*32;
  3586   3597   
  3587   3598   #ifdef SQLITE_DEBUG
  3588   3599         for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3589   3600           for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3590         -          assert( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
         3601  +          assert_nc( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
  3591   3602           }
  3592   3603         }
  3593         -      assert( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
         3604  +      assert_nc( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
  3594   3605   
  3595   3606         {
  3596   3607           sqlite3_stmt *pIdxSelect = fts5IdxSelectStmt(p);
  3597   3608           if( p->rc==SQLITE_OK ){
  3598   3609             u8 aBlob[2] = {0xff, 0xff};
  3599   3610             sqlite3_bind_int(pIdxSelect, 1, iSegid);
  3600   3611             sqlite3_bind_blob(pIdxSelect, 2, aBlob, 2, SQLITE_STATIC);
  3601         -          assert( sqlite3_step(pIdxSelect)!=SQLITE_ROW );
         3612  +          assert_nc( sqlite3_step(pIdxSelect)!=SQLITE_ROW );
  3602   3613             p->rc = sqlite3_reset(pIdxSelect);
  3603   3614             sqlite3_bind_null(pIdxSelect, 2);
  3604   3615           }
  3605   3616         }
  3606   3617   #endif
  3607   3618       }
  3608   3619     }
................................................................................
  3895   3906     Fts5Index *p, 
  3896   3907     Fts5SegWriter *pWriter,
  3897   3908     int nTerm, const u8 *pTerm 
  3898   3909   ){
  3899   3910     int nPrefix;                    /* Bytes of prefix compression for term */
  3900   3911     Fts5PageWriter *pPage = &pWriter->writer;
  3901   3912     Fts5Buffer *pPgidx = &pWriter->writer.pgidx;
         3913  +  int nMin = MIN(pPage->term.n, nTerm);
  3902   3914   
  3903   3915     assert( p->rc==SQLITE_OK );
  3904   3916     assert( pPage->buf.n>=4 );
  3905   3917     assert( pPage->buf.n>4 || pWriter->bFirstTermInPage );
  3906   3918   
  3907   3919     /* If the current leaf page is full, flush it to disk. */
  3908   3920     if( (pPage->buf.n + pPgidx->n + nTerm + 2)>=p->pConfig->pgsz ){
................................................................................
  3936   3948         ** Usually, the previous term is available in pPage->term. The exception
  3937   3949         ** is if this is the first term written in an incremental-merge step.
  3938   3950         ** In this case the previous term is not available, so just write a
  3939   3951         ** copy of (pTerm/nTerm) into the parent node. This is slightly
  3940   3952         ** inefficient, but still correct.  */
  3941   3953         int n = nTerm;
  3942   3954         if( pPage->term.n ){
  3943         -        n = 1 + fts5PrefixCompress(pPage->term.n, pPage->term.p, pTerm);
         3955  +        n = 1 + fts5PrefixCompress(nMin, pPage->term.p, pTerm);
  3944   3956         }
  3945   3957         fts5WriteBtreeTerm(p, pWriter, n, pTerm);
  3946   3958         pPage = &pWriter->writer;
  3947   3959       }
  3948   3960     }else{
  3949         -    nPrefix = fts5PrefixCompress(pPage->term.n, pPage->term.p, pTerm);
         3961  +    nPrefix = fts5PrefixCompress(nMin, pPage->term.p, pTerm);
  3950   3962       fts5BufferAppendVarint(&p->rc, &pPage->buf, nPrefix);
  3951   3963     }
  3952   3964   
  3953   3965     /* Append the number of bytes of new data, then the term data itself
  3954   3966     ** to the page. */
  3955   3967     fts5BufferAppendVarint(&p->rc, &pPage->buf, nTerm - nPrefix);
  3956   3968     fts5BufferAppendBlob(&p->rc, &pPage->buf, nTerm - nPrefix, &pTerm[nPrefix]);
................................................................................
  5860   5872         int iOff;                   /* Offset of first term on leaf */
  5861   5873         int iRowidOff;              /* Offset of first rowid on leaf */
  5862   5874         int nTerm;                  /* Size of term on leaf in bytes */
  5863   5875         int res;                    /* Comparison of term and split-key */
  5864   5876   
  5865   5877         iOff = fts5LeafFirstTermOff(pLeaf);
  5866   5878         iRowidOff = fts5LeafFirstRowidOff(pLeaf);
  5867         -      if( iRowidOff>=iOff ){
         5879  +      if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
  5868   5880           p->rc = FTS5_CORRUPT;
  5869   5881         }else{
  5870   5882           iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
  5871   5883           res = memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
  5872   5884           if( res==0 ) res = nTerm - nIdxTerm;
  5873   5885           if( res<0 ) p->rc = FTS5_CORRUPT;
  5874   5886         }
................................................................................
  6275   6287     ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
  6276   6288     ** buffer overreads even if the record is corrupt.  */
  6277   6289     n = sqlite3_value_bytes(apVal[1]);
  6278   6290     aBlob = sqlite3_value_blob(apVal[1]);
  6279   6291     nSpace = n + FTS5_DATA_ZERO_PADDING;
  6280   6292     a = (u8*)sqlite3Fts5MallocZero(&rc, nSpace);
  6281   6293     if( a==0 ) goto decode_out;
  6282         -  memcpy(a, aBlob, n);
  6283         -
         6294  +  if( n>0 ) memcpy(a, aBlob, n);
  6284   6295   
  6285   6296     fts5DecodeRowid(iRowid, &iSegid, &bDlidx, &iHeight, &iPgno);
  6286   6297   
  6287   6298     fts5DebugRowid(&rc, &s, iRowid);
  6288   6299     if( bDlidx ){
  6289   6300       Fts5Data dlidx;
  6290   6301       Fts5DlidxLvl lvl;

Changes to ext/fts5/fts5_storage.c.

   132    132           zSql = sqlite3_mprintf(azStmt[eStmt], pC->zDb, pC->zName);
   133    133           break;
   134    134       }
   135    135   
   136    136       if( zSql==0 ){
   137    137         rc = SQLITE_NOMEM;
   138    138       }else{
   139         -      rc = sqlite3_prepare_v3(pC->db, zSql, -1,
   140         -                              SQLITE_PREPARE_PERSISTENT, &p->aStmt[eStmt], 0);
          139  +      int f = SQLITE_PREPARE_PERSISTENT;
          140  +      if( eStmt>FTS5_STMT_LOOKUP ) f |= SQLITE_PREPARE_NO_VTAB;
          141  +      rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
   141    142         sqlite3_free(zSql);
   142    143         if( rc!=SQLITE_OK && pzErrMsg ){
   143    144           *pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
   144    145         }
   145    146       }
   146    147     }
   147    148   

Changes to ext/fts5/fts5_test_tok.c.

   374    374     if( idxNum==1 ){
   375    375       const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
   376    376       int nByte = sqlite3_value_bytes(apVal[0]);
   377    377       pCsr->zInput = sqlite3_malloc(nByte+1);
   378    378       if( pCsr->zInput==0 ){
   379    379         rc = SQLITE_NOMEM;
   380    380       }else{
   381         -      memcpy(pCsr->zInput, zByte, nByte);
          381  +      if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte);
   382    382         pCsr->zInput[nByte] = 0;
   383    383         rc = pTab->tok.xTokenize(
   384    384             pTab->pTok, (void*)pCsr, 0, zByte, nByte, fts5tokCb
   385    385         );
   386    386       }
   387    387     }
   388    388   

Changes to ext/fts5/fts5_tokenize.c.

   258    258     if( n>0 ){
   259    259       aNew = (int*)sqlite3_realloc(p->aiException, (n+p->nException)*sizeof(int));
   260    260       if( aNew ){
   261    261         int nNew = p->nException;
   262    262         const unsigned char *zCsr = (const unsigned char*)z;
   263    263         const unsigned char *zTerm = (const unsigned char*)&z[n];
   264    264         while( zCsr<zTerm ){
   265         -        int iCode;
          265  +        u32 iCode;
   266    266           int bToken;
   267    267           READ_UTF8(zCsr, zTerm, iCode);
   268    268           if( iCode<128 ){
   269    269             p->aTokenChar[iCode] = (unsigned char)bTokenChars;
   270    270           }else{
   271    271             bToken = p->aCategory[sqlite3Fts5UnicodeCategory(iCode)];
   272    272             assert( (bToken==0 || bToken==1) ); 
   273    273             assert( (bTokenChars==0 || bTokenChars==1) );
   274    274             if( bToken!=bTokenChars && sqlite3Fts5UnicodeIsdiacritic(iCode)==0 ){
   275    275               int i;
   276    276               for(i=0; i<nNew; i++){
   277         -              if( aNew[i]>iCode ) break;
          277  +              if( (u32)aNew[i]>iCode ) break;
   278    278               }
   279    279               memmove(&aNew[i+1], &aNew[i], (nNew-i)*sizeof(int));
   280    280               aNew[i] = iCode;
   281    281               nNew++;
   282    282             }
   283    283           }
   284    284         }
................................................................................
   425    425   /*
   426    426   ** Return true if, for the purposes of tokenizing with the tokenizer
   427    427   ** passed as the first argument, codepoint iCode is considered a token 
   428    428   ** character (not a separator).
   429    429   */
   430    430   static int fts5UnicodeIsAlnum(Unicode61Tokenizer *p, int iCode){
   431    431     return (
   432         -    p->aCategory[sqlite3Fts5UnicodeCategory(iCode)]
          432  +    p->aCategory[sqlite3Fts5UnicodeCategory((u32)iCode)]
   433    433       ^ fts5UnicodeIsException(p, iCode)
   434    434     );
   435    435   }
   436    436   
   437    437   static int fts5UnicodeTokenize(
   438    438     Fts5Tokenizer *pTokenizer,
   439    439     void *pCtx,
................................................................................
   454    454     const char *pEnd = &aFold[nFold-6];
   455    455   
   456    456     UNUSED_PARAM(iUnused);
   457    457   
   458    458     /* Each iteration of this loop gobbles up a contiguous run of separators,
   459    459     ** then the next token.  */
   460    460     while( rc==SQLITE_OK ){
   461         -    int iCode;                    /* non-ASCII codepoint read from input */
          461  +    u32 iCode;                    /* non-ASCII codepoint read from input */
   462    462       char *zOut = aFold;
   463    463       int is;
   464    464       int ie;
   465    465   
   466    466       /* Skip any separator characters. */
   467    467       while( 1 ){
   468    468         if( zCsr>=zTerm ) goto tokenize_done;
................................................................................
  1280   1280           &aBuiltin[i].x,
  1281   1281           0
  1282   1282       );
  1283   1283     }
  1284   1284   
  1285   1285     return rc;
  1286   1286   }
  1287         -
  1288         -

Changes to ext/fts5/fts5_unicode2.c.

    65     65       'f',       'g',       'h',       'h',       'i',       'i'|HIBIT, 
    66     66       'k',       'l',       'l'|HIBIT, 'l',       'm',       'n',       
    67     67       'o'|HIBIT, 'p',       'r',       'r'|HIBIT, 'r',       's',       
    68     68       's'|HIBIT, 't',       'u',       'u'|HIBIT, 'v',       'w',       
    69     69       'w',       'x',       'y',       'z',       'h',       't',       
    70     70       'w',       'y',       'a',       'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT, 
    71     71       'e',       'e'|HIBIT, 'e'|HIBIT, 'i',       'o',       'o'|HIBIT, 
    72         -    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',  
           72  +    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',       
    73     73     };
    74     74   
    75     75     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
    76     76     int iRes = 0;
    77     77     int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
    78     78     int iLo = 0;
    79     79     while( iHi>=iLo ){
................................................................................
    96     96   ** is a diacritical modifier character.
    97     97   */
    98     98   int sqlite3Fts5UnicodeIsdiacritic(int c){
    99     99     unsigned int mask0 = 0x08029FDF;
   100    100     unsigned int mask1 = 0x000361F8;
   101    101     if( c<768 || c>817 ) return 0;
   102    102     return (c < 768+32) ?
   103         -      (mask0 & (1 << (c-768))) :
   104         -      (mask1 & (1 << (c-768-32)));
          103  +      (mask0 & ((unsigned int)1 << (c-768))) :
          104  +      (mask1 & ((unsigned int)1 << (c-768-32)));
   105    105   }
   106    106   
   107    107   
   108    108   /*
   109    109   ** Interpret the argument as a unicode codepoint. If the codepoint
   110    110   ** is an upper case character that has a lower case equivalent,
   111    111   ** return the codepoint corresponding to the lower case version.
................................................................................
   244    244     
   245    245     else if( c>=66560 && c<66600 ){
   246    246       ret = c + 40;
   247    247     }
   248    248   
   249    249     return ret;
   250    250   }
          251  +
   251    252   
   252    253   int sqlite3Fts5UnicodeCatParse(const char *zCat, u8 *aArray){ 
   253    254     aArray[0] = 1;
   254    255     switch( zCat[0] ){
   255    256       case 'C':
   256    257             switch( zCat[1] ){
   257    258               case 'c': aArray[1] = 1; break;
................................................................................
   726    727       89,    1434,  3226,  506,   474,   506,   506,   367,   1018,  1946,  
   727    728       1402,  954,   1402,  314,   90,    1082,  218,   2266,  666,   1210,  
   728    729       186,   570,   2042,  58,    5850,  154,   2010,  154,   794,   2266,  
   729    730       378,   2266,  3738,  39,    39,    39,    39,    39,    39,    17351, 
   730    731       34,    3074,  7692,  63,    63,    
   731    732     };
   732    733   
   733         -int sqlite3Fts5UnicodeCategory(int iCode) { 
          734  +int sqlite3Fts5UnicodeCategory(u32 iCode) { 
   734    735     int iRes = -1;
   735    736     int iHi;
   736    737     int iLo;
   737    738     int ret;
   738    739     u16 iKey;
   739    740   
   740    741     if( iCode>=(1<<20) ){
................................................................................
   769    770       int n = (aFts5UnicodeData[iTbl] >> 5) + i;
   770    771       for(; i<128 && i<n; i++){
   771    772         aAscii[i] = bToken;
   772    773       }
   773    774       iTbl++;
   774    775     }
   775    776   }
          777  +

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

    34     34     t1_docsize {CREATE TABLE 't1_docsize'(id INTEGER PRIMARY KEY, sz BLOB)}
    35     35     t1_config {CREATE TABLE 't1_config'(k PRIMARY KEY, v) WITHOUT ROWID}
    36     36   }
    37     37   
    38     38   do_execsql_test 1.1 {
    39     39     DROP TABLE t1;
    40     40     SELECT name, sql FROM sqlite_master;
    41         -} {
    42         -}
           41  +} {}
    43     42   
    44     43   #-------------------------------------------------------------------------
    45     44   #
    46     45   
    47     46   do_execsql_test 2.0 {
    48     47     CREATE VIRTUAL TABLE t1 USING fts5(x, y, detail=%DETAIL%);
    49     48   }

Added ext/fts5/test/fts5circref.test.

            1  +# 2018 Dec 22
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#*************************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this script is testing the FTS5 module.
           13  +#
           14  +
           15  +source [file join [file dirname [info script]] fts5_common.tcl]
           16  +set testprefix fts5circref
           17  +
           18  +# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
           19  +ifcapable !fts5 {
           20  +  finish_test
           21  +  return
           22  +}
           23  +
           24  +do_execsql_test 1.0 {
           25  +  CREATE VIRTUAL TABLE tt USING fts5(a);
           26  +  SELECT name FROM sqlite_master ORDER BY 1;
           27  +} {
           28  +  tt tt_config tt_content tt_data tt_docsize tt_idx
           29  +}
           30  +db_save_and_close
           31  +
           32  +foreach {tn schema sql} {
           33  +  1 {
           34  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_config BEGIN
           35  +      SELECT * FROM tt;
           36  +    END;
           37  +  } {
           38  +    INSERT INTO tt(tt, rank) VALUES('usermerge', 4);
           39  +  }
           40  +
           41  +  2 {
           42  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_docsize BEGIN
           43  +      SELECT * FROM tt;
           44  +    END;
           45  +  } {
           46  +    INSERT INTO tt(a) VALUES('one two three');
           47  +  }
           48  +
           49  +  3 {
           50  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_content BEGIN
           51  +      SELECT * FROM tt;
           52  +    END;
           53  +  } {
           54  +    INSERT INTO tt(a) VALUES('one two three');
           55  +  }
           56  +
           57  +  4 {
           58  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_data BEGIN
           59  +      SELECT * FROM tt;
           60  +    END;
           61  +  } {
           62  +    INSERT INTO tt(a) VALUES('one two three');
           63  +  }
           64  +
           65  +  5 {
           66  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_idx BEGIN
           67  +      SELECT * FROM tt;
           68  +    END;
           69  +  } {
           70  +    INSERT INTO tt(a) VALUES('one two three');
           71  +  }
           72  +} {
           73  +  db_restore_and_reopen
           74  +  do_execsql_test 1.1.$tn.1 $schema
           75  +  do_catchsql_test 1.1.$tn.2 $sql {1 {SQL logic error}}
           76  +  db close
           77  +}
           78  +
           79  +
           80  +finish_test

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

    31     31       CREATE VIRTUAL TABLE t1 USING fts5(x);
    32     32       INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
    33     33       WITH ii(i) AS (SELECT 1 UNION SELECT i+1 FROM ii WHERE i<100)
    34     34         INSERT INTO t1 SELECT rnddoc(10) FROM ii;
    35     35     }
    36     36   }
    37     37   
    38         -if 1 {
    39         -
    40     38   # Create a simple FTS5 table containing 100 documents. Each document 
    41     39   # contains 10 terms, each of which start with the character "x".
    42     40   #
    43     41   do_test 1.0 { create_t1 } {}
    44     42   
    45     43   do_test 1.1 {
    46     44     # Pick out the rowid of the right-most b-tree leaf in the new segment.
................................................................................
   376    374       db eval {DELETE FROM t5_data WHERE rowid = $i}
   377    375       set r [catchsql { INSERT INTO t5(t5) VALUES('integrity-check')} ]
   378    376       if {$r != "1 {database disk image is malformed}"} { error $r }
   379    377       db eval ROLLBACK  
   380    378     }
   381    379   } {}
   382    380   
   383         -}
   384         -
   385    381   #------------------------------------------------------------------------
   386    382   # Corruption within the structure record.
   387    383   #
   388    384   reset_db
   389    385   do_execsql_test 8.1 {
   390    386     CREATE VIRTUAL TABLE t1 USING fts5(x, y);
   391    387     INSERT INTO t1 VALUES('one', 'two');
................................................................................
   412    408     append blob "450108"      ;# first segment
   413    409     execsql "REPLACE INTO t1_data VALUES(10, X'$blob')"
   414    410   } {}
   415    411   do_catchsql_test 9.2.2 {
   416    412     SELECT * FROM t1('one AND two');
   417    413   } {1 {database disk image is malformed}}
   418    414   
          415  +#-------------------------------------------------------------------------
          416  +reset_db
          417  +do_test 10.0 {
          418  +  sqlite3 db {}
          419  +  db deserialize [decode_hexdb {
          420  +| size 32768 pagesize 4096 filename c9.db
          421  +| page 1 offset 0
          422  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          423  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          424  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 04   ................
          425  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          426  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          427  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          428  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          429  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          430  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          431  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          432  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          433  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          434  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          435  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          436  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          437  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          438  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          439  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          440  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          441  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          442  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          443  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          444  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          445  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          446  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          447  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          448  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          449  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          450  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          451  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          452  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          453  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          454  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          455  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          456  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          457  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          458  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          459  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          460  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          461  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          462  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          463  +| page 2 offset 4096
          464  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
          465  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          466  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          467  +|   4048: 63 6b 01 02 02 04 02 66 74 02 06 36 b0 a0 10 21   ck.....ft..6...!
          468  +|   4064: d6 f7 07 46 96 d6 97 a6 05 01 03 00 10 03 03 0f   ...F............
          469  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
          470  +| page 3 offset 8192
          471  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
          472  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          473  +| page 4 offset 12288
          474  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
          475  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          476  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          477  +| page 5 offset 16384
          478  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
          479  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          480  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          481  +| page 6 offset 20480
          482  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          483  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          484  +| page 7 offset 24576
          485  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          486  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          487  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          488  +|   4080: 68 65 62 6c 65 74 31 74 31 43 52 45 41 54 45 20   heblet1t1CREATE 
          489  +| page 8 offset 28672
          490  +|      0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31   VIRTUAL TABLE t1
          491  +|     16: 20 55 53 49 4e 47 20 66 74 73 35 28 63 6f 6e 74    USING fts5(cont
          492  +|     32: 65 6e 74 29 0d 00 00 00 03 0f bd 00 0f e8 0f ef   ent)............
          493  +|     48: 0f bd 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
          494  +| end c9.db
          495  +  }]
          496  +} {}
          497  +do_catchsql_test 10.1 {
          498  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
          499  +} {1 {database disk image is malformed}}
          500  +
          501  +#-------------------------------------------------------------------------
          502  +#
          503  +reset_db
          504  +do_test 11.0 {
          505  +  sqlite3 db {}
          506  +  db deserialize [decode_hexdb {
          507  +| size 28672 pagesize 4096 filename c10b.db
          508  +| page 1 offset 0
          509  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          510  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
          511  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          512  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          513  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
          514  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
          515  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          516  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          517  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          518  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          519  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          520  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          521  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          522  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          523  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          524  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          525  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          526  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          527  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          528  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          529  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          530  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          531  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          532  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          533  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          534  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          535  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          536  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          537  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          538  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          539  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          540  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          541  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          542  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          543  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          544  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          545  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 44 d9   (id INTEGER PRD.
          546  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          547  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          548  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          549  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          550  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          551  +| page 2 offset 4096
          552  +|      0: 0d 00 00 00 06 0f 59 00 0f e8 0f ef 0f bd 0f b0   ......Y.........
          553  +|     16: 0f 73 0f 59 00 00 00 00 00 00 00 00 00 00 00 00   .s.Y............
          554  +|   3920: 00 00 00 00 00 00 00 00 00 13 84 80 80 80 80 04   ................
          555  +|   3936: 03 01 2a 0a 00 00 00 00 01 02 02 00 02 01 01 01   ..*.............
          556  +|   3952: 02 01 01 36 84 80 80 80 80 03 03 05 66 00 40 00   ...6........f.@.
          557  +|   3968: 00 00 01 00 00 00 29 07 30 61 63 74 69 76 65 04   ......).0active.
          558  +|   3984: 02 02 02 03 74 6f 6d 06 02 02 05 02 69 63 07 02   ....tom.....ic..
          559  +|   4000: 02 01 06 62 6f 6f 6d 65 72 05 02 02 04 0b 08 07   ...boomer.......
          560  +|   4016: 06 84 80 80 80 80 02 03 01 10 01 07 07 24 84 80   .............$..
          561  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          562  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          563  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
          564  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
          565  +| page 3 offset 8192
          566  +|      0: 0a 00 00 00 02 0f f3 00 0f fa 0f f3 00 00 00 00   ................
          567  +|   4080: 00 00 00 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
          568  +| page 4 offset 12288
          569  +|      0: 0d 00 00 00 07 0f b6 00 0f f6 0f ec 0f e0 0f d5   ................
          570  +|     16: 0f ca 0f c1 0f b6 00 00 00 00 00 00 00 00 00 00   ................
          571  +|   4016: 00 00 00 00 00 00 09 07 03 00 19 61 74 6f 6d 69   ...........atomi
          572  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 09 05 03 00 19 62   c.....atom.....b
          573  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
          574  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          575  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          576  +| page 5 offset 16384
          577  +|      0: 0d 00 00 00 07 0f d6 00 0f fa 0f f4 0f ee 0f e8   ................
          578  +|     16: 0f e2 0f dc 0f d6 00 00 00 00 00 00 00 00 00 00   ................
          579  +|   4048: 00 00 00 00 00 00 04 07 03 00 0e 01 04 06 03 00   ................
          580  +|   4064: 0e 01 04 05 03 00 0e 01 04 04 03 00 0e 01 04 03   ................
          581  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          582  +| page 6 offset 20480
          583  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          584  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          585  +| page 7 offset 24576
          586  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          587  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          588  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          589  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          590  +| end c10b.db
          591  +}]} {}
          592  +
          593  +# This returns SQLITE_CONSTRAINT instead of SQLITE_CORRUPT. The problem is
          594  +# that the corrupted structure-record leads fts5 to try to use a segment-id
          595  +# that is already in use. This is caught by the PRIMARY KEY constraint on
          596  +# the %_idx table.
          597  +#
          598  +do_catchsql_test 11.1 {
          599  +  UPDATE t1 SET content='abc' WHERE content='boomer';
          600  +} {1 {constraint failed}}
          601  +
          602  +#-------------------------------------------------------------------------
          603  +#
          604  +reset_db
          605  +do_test 12.0 {
          606  +  sqlite3 db {}
          607  +  db deserialize [decode_hexdb {
          608  +| size 28672 pagesize 4096 filename c2.db
          609  +| page 1 offset 0
          610  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          611  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          612  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
          613  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          614  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          615  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          616  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          617  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          618  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          619  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          620  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          621  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          622  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          623  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          624  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          625  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          626  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          627  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          628  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          629  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          630  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          631  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          632  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          633  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          634  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          635  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          636  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          637  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          638  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          639  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          640  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          641  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          642  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          643  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          644  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          645  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          646  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          647  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          648  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          649  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          650  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          651  +| page 2 offset 4096
          652  +|      0: 0d 00 00 00 03 0f bd 00 0f d8 0f ef 0f bd 00 00   ................
          653  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          654  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          655  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          656  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
          657  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 20 01 01 01 01   ...$....... ....
          658  +| page 3 offset 8192
          659  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
          660  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          661  +| page 4 offset 12288
          662  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 3f e0   ..............?.
          663  +|     16: a0 30 30 01 b6 16 26 16 e6 46 f6 e0 80 20 30 01   .00...&..F... 0.
          664  +|     32: 76 16 26 16 67 40 80 10 30 01 76 16 26 16 36 b0   v.&.g@..0.v.&.6.
          665  +|     48: d0 00 00 00 30 fe e0 00 ff a0 ff 40 fe 00 00 00   ....0......@....
          666  +| page 5 offset 16384
          667  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          668  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          669  +| page 6 offset 20480
          670  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          671  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          672  +| page 7 offset 24576
          673  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          674  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          675  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          676  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          677  +| end c2.db
          678  +}]} {}
          679  +
          680  +do_catchsql_test 11.1 {
          681  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
          682  +} {1 {vtable constructor failed: t1}}
          683  +
          684  +do_catchsql_test 11.2 {
          685  +  INSERT INTO t1(t1, rank) VALUES('merge', 500);
          686  +} {1 {vtable constructor failed: t1}}
          687  +
          688  +#-------------------------------------------------------------------------
          689  +#
          690  +reset_db
          691  +do_test 13.0 {
          692  +  sqlite3 db {}
          693  +  db deserialize [decode_hexdb {
          694  +| size 28672 pagesize 4096 filename c13.db
          695  +| page 1 offset 0
          696  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          697  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          698  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 04   ................
          699  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          700  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          701  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          702  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          703  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          704  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          705  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          706  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          707  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          708  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          709  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          710  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          711  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          712  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          713  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          714  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          715  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          716  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          717  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          718  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          719  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          720  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          721  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          722  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          723  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 4f 69 64   ATE TABLE 't1Oid
          724  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          725  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          726  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          727  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          728  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          729  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          730  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          731  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          732  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          733  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          734  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          735  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          736  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          737  +| page 2 offset 4096
          738  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
          739  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          740  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          741  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          742  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
          743  +|   4080: 0a 03 00 24 00 eb 00 00 00 01 01 01 00 01 01 01   ...$............
          744  +| page 3 offset 8192
          745  +|      0: 01 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00   ................
          746  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          747  +| page 4 offset 12288
          748  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
          749  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          750  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          751  +| page 5 offset 16384
          752  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f2 0f ee 00 00   ................
          753  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          754  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          755  +| page 6 offset 20480
          756  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          757  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          758  +| page 7 offset 24576
          759  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          760  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          761  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          762  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          763  +| end c13.db
          764  +SELECT * FROM t1 WHERE t1 MATCH 'abandon';
          765  +}]} {}
          766  +
          767  +do_catchsql_test 13.1 {
          768  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon'; 
          769  +} {1 {vtable constructor failed: t1}}
          770  +
          771  +#-------------------------------------------------------------------------
          772  +reset_db
          773  +do_test 14.0 {
          774  +  sqlite3 db {}
          775  +  db deserialize [decode_hexdb {
          776  +| size 28672 pagesize 4096 filename c14b.db
          777  +| page 1 offset 0
          778  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          779  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
          780  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          781  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          782  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
          783  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
          784  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          785  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          786  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          787  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          788  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          789  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          790  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          791  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          792  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          793  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          794  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          795  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          796  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          797  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          798  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          799  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          800  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          801  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          802  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          803  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          804  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          805  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          806  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          807  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          808  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          809  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          810  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          811  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          812  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          813  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          814  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          815  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          816  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          817  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          818  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          819  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          820  +| page 2 offset 4096
          821  +|      0: 0d 0f ef 00 04 0f 18 00 0f e8 0f 18 0f bd 0f 2c   ...............,
          822  +|   3856: 00 00 00 00 00 00 00 00 12 0a 03 00 2a 00 00 00   ............*...
          823  +|   3872: 00 01 02 02 00 02 01 01 01 02 01 01 81 09 88 80   ................
          824  +|   3888: 80 80 80 01 04 00 82 16 00 00 00 79 06 30 61 62   ...........y.0ab
          825  +|   3904: 61 63 6b 08 02 07 04 04 6e 64 6f 6e 08 02 05 02   ack.....ndon....
          826  +|   3920: 05 63 74 69 76 65 04 02 02 04 02 0b 02 04 6c 70   .ctive........lp
          827  +|   3936: 68 61 08 04 02 0a 02 03 74 6b 6d 06 02 02 03 02   ha......tkm.....
          828  +|   3952: 6f 6d 08 02 09 05 02 69 63 07 02 02 01 06 62 61   om.....ic.....ba
          829  +|   3968: 63 6b 75 70 08 02 04 02 05 6f 6f 6d 65 72 05 02   ckup.....oomer..
          830  +|   3984: 02 01 0c 63 68 61 6e 6e 65 62 6f 6f 6d 65 72 08   ...channeboomer.
          831  +|   4000: 02 08 07 01 6c 08 02 03 01 04 74 65 73 74 08 02   ....l.....test..
          832  +|   4016: 06 04 0a 09 0d 0a 08 07 07 0b 0a 11 06 24 84 80   .............$..
          833  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          834  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          835  +|   4064: 6f 6e 03 02 02 03 9a 07 05 01 03 00 10 08 11 00   on..............
          836  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
          837  +| page 3 offset 8192
          838  +|      0: 0a 00 00 00 02 0f f3 00 0f fa 0f f3 00 00 00 00   ................
          839  +|   4080: 00 00 00 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
          840  +| page 4 offset 12288
          841  +|      0: 0d 00 00 00 08 0f 6a 00 0f f6 0f ec 0f e0 0f d5   ......j.........
          842  +|     16: 0f ca 0f c1 0f b6 0f 6a 00 00 00 00 00 00 00 00   .......j........
          843  +|   3936: 00 00 00 00 00 00 00 00 00 00 4a 08 04 00 81 19   ..........J.....
          844  +|   3952: 61 6c 70 68 61 20 63 68 61 6e 6e 65 6c 20 62 61   alpha channel ba
          845  +|   3968: 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65 73   ckup abandon tes
          846  +|   3984: 74 20 61 62 61 63 6b 20 63 68 61 6e 6e 65 62 6f   t aback channebo
          847  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
          848  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
          849  +|   4032: 63 07 06 03 00 15 61 74 6b 6d 09 05 03 00 19 62   c.....atkm.....b
          850  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
          851  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          852  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          853  +| page 5 offset 16384
          854  +|      0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8   ................
          855  +|     16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00   ................
          856  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
          857  +|   4064: 0e 01 04 05 03 00 0e 01 04 04 03 00 0e 01 04 03   ................
          858  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          859  +| page 6 offset 20480
          860  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          861  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          862  +| page 7 offset 24576
          863  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          864  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          865  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          866  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          867  +| end c14b.db
          868  +}]} {}
          869  +
          870  +do_catchsql_test 14.1 {
          871  +  INSERT INTO t1(t1) VALUES('optimize');
          872  +} {1 {database disk image is malformed}}
          873  +
          874  +#---------------------------------------------------------------------------
          875  +#
          876  +reset_db
          877  +do_test 15.0 {
          878  +  sqlite3 db {}
          879  +  db deserialize [decode_hexdb {
          880  +| size 32768 pagesize 4096 filename c16.db
          881  +| page 1 offset 0
          882  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          883  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          884  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
          885  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          886  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          887  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          888  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          889  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          890  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          891  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          892  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          893  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          894  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          895  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          896  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 00 0f f6 0f ec   ..!!...tabl.....
          897  +|   3680: 0f e0 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ..sizet1_docsize
          898  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          899  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          900  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          901  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          902  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          903  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          904  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          905  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          906  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          907  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          908  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          909  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          910  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          911  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          912  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          913  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          914  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          915  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          916  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          917  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          918  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          919  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          920  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          921  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          922  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          923  +| page 2 offset 4096
          924  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
          925  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          926  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          927  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
          928  +|   4064: 6f 6e 04 67 90 38 2a 07 05 01 03 00 10 03 03 0f   on.g.8*.........
          929  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
          930  +| page 3 offset 8192
          931  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
          932  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          933  +| page 4 offset 12288
          934  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
          935  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          936  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          937  +| page 5 offset 16384
          938  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
          939  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          940  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          941  +| page 6 offset 20480
          942  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          943  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          944  +| page 7 offset 24576
          945  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          946  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          947  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          948  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          949  +| page 8 offset 28672
          950  +|      0: 03 07 17 19 19 01 81 2d 74 61 62 6c 65 74 31 5f   .......-tablet1_
          951  +|     16: 69 64 78 74 31 5f 69 64 78 03 43 52 45 41 54 45   idxt1_idx.CREATE
          952  +|     32: 20 54 41 42 4c 45 20 27 74 31 5f 66 17 42 03 30    TABLE 't1_f.B.0
          953  +|     48: 01 00 00 10 10 04 02 02 00 00 00 00 00 00 00 00   ................
          954  +|     64: 70 00 00 00 00 00 00 00 00 00 00 00 70 00 00 00   p...........p...
          955  +| end c16.db
          956  +}]} {}
          957  +
          958  +do_catchsql_test 15.1 {
          959  +  INSERT INTO t1(t1) VALUES('integrity-check');
          960  +} {1 {database disk image is malformed}}
          961  +
          962  +#---------------------------------------------------------------------------
          963  +#
          964  +reset_db
          965  +do_test 16.0 {
          966  +  sqlite3 db {}
          967  +  db deserialize [decode_hexdb {
          968  +| size 28672 pagesize 4096 filename c17.db
          969  +| page 1 offset 0
          970  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          971  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          972  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
          973  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          974  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          975  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          976  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          977  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          978  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          979  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          980  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          981  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          982  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          983  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          984  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          985  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          986  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          987  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          988  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          989  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          990  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          991  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          992  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          993  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          994  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          995  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          996  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          997  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          998  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          999  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1000  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1001  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1002  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1003  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1004  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1005  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1006  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1007  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1008  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1009  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1010  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1011  +| page 2 offset 4096
         1012  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1013  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1014  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1015  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1016  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1017  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 41 01   ...$..........A.
         1018  +| page 3 offset 8192
         1019  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         1020  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1021  +| page 4 offset 12288
         1022  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1023  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1024  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1025  +| page 5 offset 16384
         1026  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1027  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1028  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1029  +| page 6 offset 20480
         1030  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1031  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1032  +| page 7 offset 24576
         1033  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1034  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1035  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1036  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1037  +| end c17.db
         1038  +}]} {}
         1039  +
         1040  +do_catchsql_test 16.1 {
         1041  +INSERT INTO t1(t1) VALUES('integrity-check');
         1042  +} {1 {vtable constructor failed: t1}}
         1043  +
         1044  +#--------------------------------------------------------------------------
         1045  +reset_db
         1046  +do_test 17.0 {
         1047  +  sqlite3 db {}
         1048  +  db deserialize [decode_hexdb {
         1049  +| size 28672 pagesize 4096 filename c18.db
         1050  +| page 1 offset 0
         1051  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1052  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         1053  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
         1054  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1055  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
         1056  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1057  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1058  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1059  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1060  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1061  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1062  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1063  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1064  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1065  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1066  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1067  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1068  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1069  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1070  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1071  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1072  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1073  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1074  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1075  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1076  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1077  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1078  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1079  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1080  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1081  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1082  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1083  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1084  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1085  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1086  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1087  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1088  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1089  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1090  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1091  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1092  +| page 2 offset 4096
         1093  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1094  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1095  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1096  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1097  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1098  +|   4080: 0a 03 00 24 00 00 0a aa aa aa aa aa aa aa aa aa   ...$............
         1099  +| page 3 offset 8192
         1100  +|      0: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa   ................
         1101  +|     16: aa aa aa aa aa aa aa aa 00 00 10 10 10 00 10 10   ................
         1102  +|     32: 10 10 a0 00 00 00 10 ff a0 00 ff 52 05 64 95 25   ...........R.d.%
         1103  +|     48: 45 54 14 c2 05 44 14 24 c4 52 07 43 12 05 55 34   ET...D.$.R.C..U4
         1104  +|     64: 94 e4 72 06 67 47 33 52 86 36 f6 e7 46 56 e7 42   ..r.gG3R.6..FV.B
         1105  +|     80: 90 d0 00 00 00 30 fb d0 00 fe 80 fe f0 fb 00 00   .....0..........
         1106  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1107  +| page 4 offset 12288
         1108  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1109  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1110  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1111  +| page 5 offset 16384
         1112  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1113  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1114  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1115  +| page 6 offset 20480
         1116  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1117  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1118  +| page 7 offset 24576
         1119  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1120  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1121  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1122  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1123  +| end c18.db
         1124  +}]} {}
         1125  +
         1126  +do_catchsql_test 17.1 {
         1127  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
         1128  +} {1 {vtable constructor failed: t1}}
         1129  +
         1130  +#--------------------------------------------------------------------------
         1131  +reset_db
         1132  +do_test 18.0 {
         1133  +  sqlite3 db {}
         1134  +  db deserialize [decode_hexdb {
         1135  +| size 28672 pagesize 4096 filename c19b.db
         1136  +| page 1 offset 0
         1137  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1138  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1139  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1140  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1141  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1142  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1143  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1144  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1145  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1146  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1147  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1148  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1149  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1150  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1151  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1152  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1153  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1154  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1155  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1156  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1157  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1158  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1159  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1160  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1161  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1162  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1163  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1164  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1165  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1166  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1167  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1168  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1169  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1170  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1171  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1172  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1173  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1174  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1175  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1176  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1177  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1178  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1179  +| page 2 offset 4096
         1180  +|      0: 0d 09 a6 00 06 09 22 00 0f e8 09 22 0f bd 0f 2c   ...............,
         1181  +|     16: 09 bd 09 3c 00 00 00 00 00 00 00 00 00 00 00 00   ...<............
         1182  +|   2336: 00 00 18 0a 03 00 36 00 00 00 00 01 04 04 00 04   ......6.........
         1183  +|   2352: 01 01 01 02 01 01 03 01 01 04 01 01 63 90 80 80   ............c...
         1184  +|   2368: 80 80 01 04 00 81 4a 00 00 00 56 06 30 61 62 61   ......J...V.0aba
         1185  +|   2384: 63 6b 08 01 04 04 6e 64 6f 6e 03 01 05 01 02 05   ck....ndon......
         1186  +|   2400: 63 74 69 76 65 08 01 02 04 6c 70 68 61 08 01 02   ctive....lpha...
         1187  +|   2416: 03 74 6f 6d 08 01 01 06 62 61 63 6b 75 70 08 01   .tom....backup..
         1188  +|   2432: 01 0c 63 68 61 6e 6e 65 62 6f 6f 6d 65 72 08 01   ..channeboomer..
         1189  +|   2448: 07 01 6c 08 01 01 04 74 65 73 74 08 01 04 09 0a   ..l....test.....
         1190  +|   2464: 09 08 07 0a 10 05 0f 18 00 17 30 00 00 00 00 01   ..........0.....
         1191  +|   2480: 03 03 00 03 01 01 01 02 01 01 03 01 01 8a 53 8c   ..............S.
         1192  +|   2496: 80 80 80 80 01 04 00 95 2a 00 00 05 35 0d 30 30   ........*...5.00
         1193  +|   2512: 31 30 66 66 61 30 30 30 66 66 61 05 02 1c 02 49   10ffa000ffa....I
         1194  +|   2528: 33 34 33 35 32 34 35 34 31 35 34 34 35 32 30 35   3435245415445205
         1195  +|   2544: 34 34 31 34 32 34 63 34 35 32 30 32 37 37 34 33   441424c452027743
         1196  +|   2560: 31 35 66 36 39 36 34 37 38 32 37 32 38 37 33 36   15f6964782728736
         1197  +|   2576: 35 36 37 36 39 36 34 32 63 32 30 37 34 36 35 37   56769642c2074657
         1198  +|   2592: 32 36 64 32 63 32 30 37 30 05 02 12 02 3b 36 31   26d2c2070....;61
         1199  +|   2608: 37 32 31 32 31 30 31 37 37 37 34 36 31 36 32 35   7212101777461625
         1200  +|   2624: 63 36 35 37 34 33 31 35 66 36 33 36 66 36 65 37   c6574315f636f6e7
         1201  +|   2640: 34 36 35 36 65 37 34 37 34 33 31 35 66 36 33 36   4656e7474315f636
         1202  +|   2656: 66 36 65 37 34 36 35 36 65 05 04 07 07 01 04 31   f6e74656e......1
         1203  +|   2672: 66 62 64 05 02 19 01 44 32 34 38 34 38 30 38 30   fbd....D24848080
         1204  +|   2688: 38 30 38 30 30 31 30 33 30 30 34 65 30 30 30 30   80800103004e0000
         1205  +|   2704: 30 30 31 65 30 36 33 30 36 31 36 32 36 31 36 33   001e063061626163
         1206  +|   2720: 36 62 30 31 30 32 30 32 30 34 30 32 36 36 37 34   6b01020204026674
         1207  +|   2736: 30 32 30 32 30 32 30 34 30 34 36 65 05 02 1a 02   02020204046e....
         1208  +|   2752: 03 66 65 72 05 02 1d 01 28 33 65 37 34 36 35 36   .fer....(3e74656
         1209  +|   2768: 65 37 34 32 39 30 64 30 30 30 30 30 30 30 33 30   e74290d000000030
         1210  +|   2784: 66 62 64 30 30 30 66 65 38 30 66 65 66 30 66 62   fbd000fe80fef0fb
         1211  +|   2800: 64 05 02 18 01 4a 34 31 35 32 35 39 32 30 34 62   d....J415259204b
         1212  +|   2816: 34 35 35 39 32 63 32 30 36 32 36 63 36 66 36 33   45592c20626c6f63
         1213  +|   2832: 36 62 32 30 34 32 34 63 34 66 34 32 32 39 33 61   6b20424c4f42293a
         1214  +|   2848: 30 31 30 36 31 37 31 31 31 31 30 38 36 33 37 34   0106171111086374
         1215  +|   2864: 36 31 36 32 36 63 36 35 37 34 33 31 37 34 33 31   61626c6574317431
         1216  +|   2880: 05 02 16 02 49 33 35 32 34 35 34 31 35 34 34 35   ....I35245415445
         1217  +|   2896: 32 30 35 36 34 39 35 32 35 34 35 35 34 31 34 63   205649525455414c
         1218  +|   2912: 32 30 35 34 34 31 34 32 34 63 34 35 32 30 37 34   205441424c452074
         1219  +|   2928: 33 31 6f 30 35 35 35 33 34 39 34 65 34 37 32 30   31o05553494e4720
         1220  +|   2944: 36 36 37 34 37 33 33 35 32 38 36 33 36 66 05 02   6674733528636f..
         1221  +|   2960: 17 02 49 35 32 30 35 34 34 31 34 32 34 63 34 35   ..I5205441424c45
         1222  +|   2976: 32 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65   202774315f636f6e
         1223  +|   2992: 37 34 36 35 36 65 37 34 32 37 32 38 36 39 36 34   74656e7427286964
         1224  +|   3008: 32 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32   20494e5445474552
         1225  +|   3024: 32 30 35 30 35 32 34 39 34 64 34 31 05 02 0e 44   205052494d41...D
         1226  +|   3040: 29 62 30 35 30 37 31 37 32 31 32 31 30 31 38 31   )b05071721210181
         1227  +|   3056: 30 31 37 34 36 31 36 32 36 63 36 35 37 34 33 31   017461626c657431
         1228  +|   3072: 35 66 36 34 36 66 36 33 37 33 05 02 09 01 4a 35   5f646f6373....J5
         1229  +|   3088: 32 34 35 34 31 35 34 34 35 32 30 35 34 34 31 34   2454154452054414
         1230  +|   3104: 32 34 63 34 35 32 30 32 37 37 34 33 31 35 66 36   24c45202774315f6
         1231  +|   3120: 34 36 31 37 34 36 31 32 37 32 38 36 39 36 34 32   4617461272869642
         1232  +|   3136: 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32   0494e54454745522
         1233  +|   3152: 30 35 30 35 32 34 39 34 64 05 02 15 03 3a 35 39   05052494d....:59
         1234  +|   3168: 32 30 34 62 34 35 35 39 32 63 32 30 36 33 33 30   204b45592c206330
         1235  +|   3184: 32 39 36 39 30 33 30 37 31 37 31 39 31 39 30 31   2969030717191901
         1236  +|   3200: 38 31 32 64 37 34 36 31 36 32 36 63 36 35 37 34   812d7461626c6574
         1237  +|   3216: 33 31 35 66 36 39 79 79 05 02 0f 02 49 34 32 30   315f69yy....I420
         1238  +|   3232: 35 32 34 66 35 37 34 39 34 34 35 35 30 32 30 37   524f574944550207
         1239  +|   3248: 31 37 31 62 31 62 30 31 38 31 30 31 37 34 36 31   171b1b0181017461
         1240  +|   3264: 36 32 36 63 36 37 37 34 33 31 35 66 36 34 36 31   626c6774315f6461
         1241  +|   3280: 37 34 36 31 37 34 33 31 35 66 36 34 36 31 37 34   746174315f646174
         1242  +|   3296: 36 31 30 32 34 33 05 02 14 02 07 66 36 39 36 34   610243.....f6964
         1243  +|   3312: 37 38 05 02 11 01 4a 36 34 36 66 36 65 30 33 30   78....J646f6e030
         1244  +|   3328: 32 30 32 30 34 30 61 30 37 30 35 30 31 30 33 30   202040a070501030
         1245  +|   3344: 30 31 30 30 33 30 33 30 66 30 61 30 33 30 30 32   01003030f0a03002
         1246  +|   3360: 34 30 30 30 30 30 30 30 30 30 31 30 31 30 31 30   4000000000101010
         1247  +|   3376: 30 30 31 30 31 30 31 30 31 30 61 30 30 30 30 30   0010101010a00000
         1248  +|   3392: 30 05 02 1b 02 49 35 32 37 32 38 36 39 36 34 32   0....I5272869642
         1249  +|   3408: 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32   0494e54454745522
         1250  +|   3424: 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32   05052494d4152592
         1251  +|   3440: 30 34 62 34 35 35 39 32 63 32 30 37 33 37 61 32   04b45592c20737a2
         1252  +|   3456: 30 34 32 34 63 34 66 34 32 32 39 35 35 30 34 05   0424c4f42295504.
         1253  +|   3472: 04 06 07 02 49 37 36 65 36 66 32 63 32 30 35 30   ....I76e6f2c2050
         1254  +|   3488: 35 32 34 39 34 64 34 31 35 32 35 39 32 30 34 62   52494d415259204b
         1255  +|   3504: 34 35 35 39 32 38 37 33 36 35 36 37 36 39 36 34   4559287365676964
         1256  +|   3520: 32 63 32 30 37 34 36 35 37 32 36 64 32 39 32 39   2c207465726d2929
         1257  +|   3536: 32 30 35 37 34 39 35 34 34 38 34 66 35 35 05 02   20574954484f55..
         1258  +|   3552: 13 02 49 39 37 61 36 35 37 34 33 31 35 66 36 34   ..I97a6574315f64
         1259  +|   3568: 36 66 36 33 37 33 36 39 37 61 36 35 30 35 34 33   6f6373697a650543
         1260  +|   3584: 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34 31   5245415445205441
         1261  +|   3600: 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35 66   424c45202774315f
         1262  +|   3616: 36 34 36 66 36 33 37 33 36 39 37 61 05 04 05 07   646f6373697a....
         1263  +|   3632: 01 0e 37 34 30 34 34 33 35 32 34 35 34 31 35 34   ..74044352454154
         1264  +|   3648: 05 04 08 07 02 49 36 32 39 32 30 35 37 34 39 35   .....I6292057495
         1265  +|   3664: 34 34 38 34 66 35 35 35 34 32 30 35 32 34 66 35   4484f555420524f5
         1266  +|   3680: 37 34 39 34 34 35 62 30 35 30 37 31 37 32 31 32   749445b050717212
         1267  +|   3696: 31 30 31 38 31 30 31 37 34 36 31 36 32 36 63 36   10181017461626c6
         1268  +|   3712: 35 37 34 33 31 35 66 36 34 36 66 36 33 37 33 05   574315f646f6373.
         1269  +|   3728: 02 04 01 06 62 61 63 6b 75 70 05 02 1e 02 05 65   ....backup.....e
         1270  +|   3744: 61 6d 65 72 05 02 02 02 05 6f 6f 6d 65 72 05 01   amer.....oomer..
         1271  +|   3760: 02 40 75 6d 6d 32 34 63 34 35 32 30 32 37 37 34   .@umm24c45202774
         1272  +|   3776: 33 31 35 66 36 33 36 66 36 65 36 36 36 39 36 37   315f636f6e666967
         1273  +|   3792: 32 37 32 38 36 62 32 30 35 30 35 32 34 39 34 64   27286b205052494d
         1274  +|   3808: 34 31 35 32 35 39 32 30 34 62 34 35 35 39 32 63   415259204b45592c
         1275  +|   3824: 32 30 05 02 03 01 04 79 65 6b 72 05 02 10 04 11   20.....yekr.....
         1276  +|   3840: 4e 41 09 49 08 2d 4f 4e 4e 2e 4f 3f 4e 0c 4f 4f   NA.I.-ONN.O?N.OO
         1277  +|   3856: 4e 4f 14 4e 0b 0a 09 45 0f ef 00 14 2a 00 00 00   NO.N...E....*...
         1278  +|   3872: 00 01 02 02 00 02 01 01 01 02 01 01 81 09 88 80   ................
         1279  +|   3888: 80 80 80 01 04 00 82 16 00 00 00 79 06 30 61 62   ...........y.0ab
         1280  +|   3904: 61 63 6b 08 02 07 04 04 6e 64 6f 6e 08 02 05 02   ack.....ndon....
         1281  +|   3920: 05 63 74 69 76 65 04 02 02 04 02 0b 02 04 6c 70   .ctive........lp
         1282  +|   3936: 68 61 08 04 02 0a 02 03 74 6b 6d 06 02 02 03 02   ha......tkm.....
         1283  +|   3952: 6f 6d 08 02 09 05 02 69 63 07 02 02 01 06 62 61   om.....ic.....ba
         1284  +|   3968: 63 6b 75 70 08 02 04 02 05 6f 6f 6d 65 72 05 02   ckup.....oomer..
         1285  +|   3984: 02 01 0c 63 68 61 6e 6e 65 62 6f 6f 6d 65 72 08   ...channeboomer.
         1286  +|   4000: 02 08 07 01 6c 08 02 03 01 04 74 65 73 74 08 02   ....l.....test..
         1287  +|   4016: 06 04 0a 09 0d 0a 08 07 07 0b 0a 11 06 24 84 80   .............$..
         1288  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1289  +|   4048: 63 6b 01 08 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1290  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 06 22 00   on..............
         1291  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1292  +| page 3 offset 8192
         1293  +|      0: 0a 00 00 00 04 0f e5 00 0f fa 0f f3 0f ec 0f e5   ................
         1294  +|   4064: 00 00 00 00 00 06 04 01 0c 01 04 02 06 04 01 0c   ................
         1295  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1296  +| page 4 offset 12288
         1297  +|      0: 0d 0f 68 00 06 08 98 00 0f f6 0f ec 0f d5 08 98   ..h.............
         1298  +|     16: 0f c1 0f b6 0f 68 0f 68 00 00 00 00 00 00 00 00   .....h.h........
         1299  +|   2192: 00 00 00 00 00 00 00 00 8d 4d 05 04 00 9b 1f 62   .........M.....b
         1300  +|   2208: 65 61 6d 65 72 20 62 75 6d 6d 32 34 63 34 35 32   eamer bumm24c452
         1301  +|   2224: 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65 36   02774315f636f6e6
         1302  +|   2240: 36 36 39 36 37 32 37 32 38 36 62 32 30 35 30 35   6696727286b20505
         1303  +|   2256: 32 34 39 34 64 34 31 35 32 35 39 32 30 34 62 34   2494d415259204b4
         1304  +|   2272: 35 35 39 32 63 32 30 0a 37 36 32 39 32 30 35 37   5592c20.76292057
         1305  +|   2288: 34 39 35 34 34 38 34 66 35 35 35 34 32 30 35 32   4954484f55542052
         1306  +|   2304: 34 66 35 37 34 39 34 34 35 62 30 35 30 37 31 37   4f5749445b050717
         1307  +|   2320: 32 31 32 31 30 31 38 31 30 31 37 34 36 31 36 32   2121018101746162
         1308  +|   2336: 36 63 36 35 37 34 33 31 35 66 36 34 36 66 36 33   6c6574315f646f63
         1309  +|   2352: 37 33 0a 36 39 37 61 36 35 37 34 33 31 35 66 36   73.697a6574315f6
         1310  +|   2368: 34 36 66 36 33 37 33 36 39 37 61 36 35 30 35 34   46f6373697a65054
         1311  +|   2384: 33 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34   3524541544520544
         1312  +|   2400: 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35   1424c45202774315
         1313  +|   2416: 66 36 34 36 66 36 33 37 33 36 39 37 61 0a 36 35   f646f6373697a.65
         1314  +|   2432: 32 37 32 38 36 39 36 34 32 30 34 39 34 65 35 34   2728696420494e54
         1315  +|   2448: 34 35 34 37 34 35 35 32 32 30 35 30 35 32 34 39   4547455220505249
         1316  +|   2464: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1317  +|   2480: 32 63 32 30 37 33 37 61 32 30 34 32 34 63 34 66   2c20737a20424c4f
         1318  +|   2496: 34 32 32 39 35 35 30 34 0a 30 36 31 37 32 31 32   42295504.0617212
         1319  +|   2512: 31 30 31 37 37 37 34 36 31 36 32 35 63 36 35 37   101777461625c657
         1320  +|   2528: 34 33 31 35 66 36 33 36 66 36 65 37 34 36 35 36   4315f636f6e74656
         1321  +|   2544: 65 37 34 37 34 33 31 35 66 36 33 36 66 36 65 37   e7474315f636f6e7
         1322  +|   2560: 34 36 35 36 65 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   4656e...........
         1323  +|   2576: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1324  +|   2592: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1325  +|   2608: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1326  +|   2624: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1327  +|   2640: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1328  +|   2656: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 37 34 30   .............740
         1329  +|   2672: 34 34 33 35 32 34 35 34 31 35 34 0a 34 35 32 30   44352454154.4520
         1330  +|   2688: 35 34 34 31 34 32 34 63 34 35 32 30 32 37 37 34   5441424c45202774
         1331  +|   2704: 33 31 35 66 36 33 36 66 36 65 37 34 36 35 36 65   315f636f6e74656e
         1332  +|   2720: 37 34 32 37 32 38 36 39 36 34 32 30 34 39 34 65   742728696420494e
         1333  +|   2736: 35 34 34 35 34 37 34 35 35 32 32 30 35 30 35 62   544547455220505b
         1334  +|   2752: 30 35 30 37 31 37 32 31 32 31 30 31 38 31 30 31   0507172121018101
         1335  +|   2768: 37 34 36 31 36 32 36 63 36 35 37 34 33 31 35 66   7461626c6574315f
         1336  +|   2784: 36 34 36 66 36 33 37 33 0a 36 39 37 61 36 35 37   646f6373.697a657
         1337  +|   2800: 34 33 31 35 66 36 34 36 66 36 33 37 33 36 39 37   4315f646f6373697
         1338  +|   2816: 61 36 35 30 35 34 33 35 32 34 35 34 31 35 34 34   a650543524541544
         1339  +|   2832: 35 32 30 35 34 34 31 34 32 34 63 34 35 32 30 32   5205441424c45202
         1340  +|   2848: 37 37 34 33 31 35 66 36 34 36 66 36 33 37 33 36   774315f646f63736
         1341  +|   2864: 39 37 61 0a 36 35 32 37 32 38 36 39 36 34 32 30   97a.652728696420
         1342  +|   2880: 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30   494e544547455220
         1343  +|   2896: 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32 30   5052494d41525920
         1344  +|   2912: 34 62 34 35 35 39 32 63 32 30 37 33 37 61 32 30   4b45592c20737a20
         1345  +|   2928: 34 32 34 63 34 66 34 32 32 39 35 35 30 34 0a 30   424c4f42295504.0
         1346  +|   2944: 36 31 37 32 31 32 31 30 31 37 37 37 34 36 31 36   6172121017774616
         1347  +|   2960: 32 35 63 36 35 37 34 33 31 35 66 36 33 36 66 36   25c6574315f636f6
         1348  +|   2976: 65 37 34 36 35 36 65 37 34 37 34 33 31 35 66 36   e74656e7474315f6
         1349  +|   2992: 33 36 66 36 65 37 34 36 35 36 65 0b 0b 0b 0b 0b   36f6e74656e.....
         1350  +|   3008: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1351  +|   3024: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1352  +|   3040: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1353  +|   3056: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1354  +|   3072: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1355  +|   3088: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1356  +|   3104: 0b 0b 0b 37 34 30 34 34 33 35 32 34 35 34 31 35   ...7404435245415
         1357  +|   3120: 34 0a 34 35 32 30 35 34 34 31 34 32 34 63 34 35   4.45205441424c45
         1358  +|   3136: 32 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65   202774315f636f6e
         1359  +|   3152: 37 34 36 35 36 65 37 34 32 37 32 38 36 39 36 34   74656e7427286964
         1360  +|   3168: 32 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32   20494e5445474552
         1361  +|   3184: 32 30 35 30 35 32 34 39 34 64 34 31 0a 35 32 35   205052494d41.525
         1362  +|   3200: 39 32 30 34 62 34 35 35 39 32 63 32 30 36 33 33   9204b45592c20633
         1363  +|   3216: 30 32 39 36 39 30 33 30 37 31 37 31 39 31 39 30   0296903071719190
         1364  +|   3232: 31 38 31 32 64 37 34 36 31 36 32 36 63 36 35 37   1812d7461626c657
         1365  +|   3248: 34 33 31 35 66 36 39 c3 bf c3 bf 7e c3 bf c3 89   4315f69....~....
         1366  +|   3264: 4b 52 c2 81 35 66 36 39 36 34 37 38 0a 30 33 34   KR..5f696478.034
         1367  +|   3280: 33 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34   3524541544520544
         1368  +|   3296: 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35   1424c45202774315
         1369  +|   3312: 66 36 39 36 34 37 38 32 37 32 38 37 33 36 35 36   f696478272873656
         1370  +|   3328: 37 36 39 36 34 32 63 32 30 37 34 36 35 37 32 36   769642c207465726
         1371  +|   3344: 64 32 63 32 30 37 30 0a 36 37 36 65 36 66 32 63   d2c2070.676e6f2c
         1372  +|   3360: 32 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39   205052494d415259
         1373  +|   3376: 32 30 34 62 34 35 35 39 32 38 37 33 36 35 36 37   204b455928736567
         1374  +|   3392: 36 39 36 34 32 63 32 30 37 34 36 35 37 32 36 64   69642c207465726d
         1375  +|   3408: 32 39 32 39 32 30 35 37 34 39 35 34 34 38 34 66   292920574954484f
         1376  +|   3424: 35 35 0a 35 34 32 30 35 32 34 66 35 37 34 39 34   55.5420524f57494
         1377  +|   3440: 34 35 35 30 32 30 37 31 37 31 62 31 62 30 31 38   4550207171b1b018
         1378  +|   3456: 31 30 31 37 34 36 31 36 32 36 63 36 37 37 34 33   1017461626c67743
         1379  +|   3472: 31 35 66 36 34 36 31 37 34 36 31 37 34 33 31 35   15f6461746174315
         1380  +|   3488: 66 36 34 36 31 37 34 36 31 30 32 34 33 0a 35 32   f646174610243.52
         1381  +|   3504: 34 35 34 31 35 34 34 35 32 30 35 34 34 31 34 32   4541544520544142
         1382  +|   3520: 34 63 34 35 32 30 32 37 37 34 33 31 35 66 36 34   4c45202774315f64
         1383  +|   3536: 36 31 37 34 36 31 32 37 32 38 36 39 36 34 32 30   6174612728696420
         1384  +|   3552: 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30   494e544547455220
         1385  +|   3568: 35 30 35 32 34 39 34 64 0a 34 31 35 32 35 39 32   5052494d.4152592
         1386  +|   3584: 30 34 62 34 35 35 39 32 63 32 30 36 32 36 63 36   04b45592c20626c6
         1387  +|   3600: 66 36 33 36 62 32 30 34 32 34 63 34 66 34 32 32   f636b20424c4f422
         1388  +|   3616: 39 33 61 30 31 30 36 31 37 31 31 31 31 30 38 36   93a0106171111086
         1389  +|   3632: 33 37 34 36 31 36 32 36 63 36 35 37 34 33 31 37   37461626c6574317
         1390  +|   3648: 34 33 31 0a 34 33 35 32 34 35 34 31 35 34 34 35   431.435245415445
         1391  +|   3664: 32 30 35 36 34 39 35 32 35 34 35 35 34 31 34 63   205649525455414c
         1392  +|   3680: 32 30 35 34 34 31 34 32 34 63 34 35 32 30 37 34   205441424c452074
         1393  +|   3696: 33 31 c3 94 30 35 35 35 33 34 39 34 65 34 37 32   31..05553494e472
         1394  +|   3712: 30 36 36 37 34 37 33 33 35 32 38 36 33 36 66 0a   06674733528636f.
         1395  +|   3728: 33 65 37 34 36 35 36 65 37 34 32 39 30 64 30 30   3e74656e74290d00
         1396  +|   3744: 30 30 30 30 30 33 30 66 62 64 30 30 30 66 65 38   0000030fbd000fe8
         1397  +|   3760: 30 66 65 66 30 66 62 64 0a 5b 31 66 62 64 5d 32   0fef0fbd.[1fbd]2
         1398  +|   3776: 34 38 34 38 30 38 30 38 30 38 30 30 31 30 33 30   4848080808001030
         1399  +|   3792: 30 34 65 30 30 30 30 30 30 31 65 30 36 33 30 36   04e0000001e06306
         1400  +|   3808: 31 36 32 36 31 36 33 36 62 30 31 30 32 30 32 30   16261636b0102020
         1401  +|   3824: 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34 30   4026674020202040
         1402  +|   3840: 34 36 65 0a 36 34 36 66 36 65 30 33 30 32 30 32   46e.646f6e030202
         1403  +|   3856: 30 34 30 61 30 37 30 35 30 31 30 33 30 30 31 30   040a070501030010
         1404  +|   3872: 30 33 30 33 30 66 30 61 30 33 30 30 32 34 30 30   03030f0a03002400
         1405  +|   3888: 30 30 30 30 30 30 30 31 30 31 30 31 30 30 30 31   0000000101010001
         1406  +|   3904: 30 31 30 31 30 31 30 61 30 30 30 30 30 30 0a 30   0101010a000000.0
         1407  +|   3920: 31 30 66 66 61 30 30 30 66 66 61 0a 5b 32 66 65   10ffa000ffa.[2fe
         1408  +|   3936: 72 20 62 61 63 6b 75 70 0f ca 00 4e 81 1d 61 6c   r backup...N..al
         1409  +|   3952: 70 68 61 20 63 68 61 6e 6e 65 6c 20 c2 af 62 61   pha channel ..ba
         1410  +|   3968: 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65 73   ckup abandon tes
         1411  +|   3984: 74 20 61 62 61 63 6b 20 63 68 61 6e 6e 65 62 6f   t aback channebo
         1412  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1413  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1414  +|   4032: 63 07 06 03 00 15 61 74 6b 6d 0f e0 00 0b 19 62   c.....atkm.....b
         1415  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         1416  +|   4064: 00 00 00 0c 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1417  +|   4080: 17 61 66 21 66 74 08 01 03 00 17 61 62 61 63 6b   .af!ft.....aback
         1418  +| page 5 offset 16384
         1419  +|      0: 0d 0f ee 00 06 0f d6 00 0f fa 0f f4 0f e8 0f e2   ................
         1420  +|     16: 0f dc 0f d6 0f d0 0f d0 00 00 00 00 00 00 00 00   ................
         1421  +|   4048: 0f ee 00 06 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1422  +|   4064: 0e 01 04 05 03 00 0e 1d 04 04 03 00 0e 01 00 00   ................
         1423  +|   4080: 00 06 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1424  +| page 6 offset 20480
         1425  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1426  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1427  +| page 7 offset 24576
         1428  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1429  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1430  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1431  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1432  +| end c19b.db
         1433  +}]} {}
         1434  +
         1435  +do_catchsql_test 18.1 {
         1436  +  INSERT INTO t1(t1) VALUES('optimize');
         1437  +} {1 {database disk image is malformed}}
         1438  +
         1439  +#--------------------------------------------------------------------------
         1440  +reset_db
         1441  +do_test 19.0 {
         1442  +  sqlite3 db {}
         1443  +  db deserialize [decode_hexdb {
         1444  +| size 28672 pagesize 4096 filename c20b.db
         1445  +| page 1 offset 0
         1446  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1447  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1448  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1449  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1450  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1451  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1452  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1453  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1454  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1455  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1456  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1457  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1458  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1459  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1460  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1461  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1462  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1463  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1464  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1465  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1466  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1467  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1468  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1469  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1470  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1471  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1472  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1473  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1474  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1475  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1476  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1477  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1478  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1479  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1480  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1481  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1482  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1483  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1484  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1485  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1486  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1487  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1488  +| page 2 offset 4096
         1489  +|      0: 0d 0f 20 00 05 0e a0 00 0f e8 0e a0 0f bd 0f 34   .. ............4
         1490  +|     16: 0e b7 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1491  +|   3744: 15 0a 03 00 30 00 00 00 00 01 03 03 00 03 01 01   ....0...........
         1492  +|   3760: 01 02 01 01 03 01 01 62 8c 80 80 80 80 01 04 00   .......b........
         1493  +|   3776: 81 48 00 00 00 55 06 30 61 62 61 63 6b 08 01 04   .H...U.0aback...
         1494  +|   3792: 04 6e 64 6f 6e 03 01 05 01 02 05 63 74 69 76 65   .ndon......ctive
         1495  +|   3808: 08 01 02 04 6c 70 68 61 08 01 02 03 74 6f 6d 08   ....lpha....tom.
         1496  +|   3824: 01 01 06 62 61 63 6b 75 70 08 01 02 05 6f 6f 6d   ...backup....oom
         1497  +|   3840: 65 72 08 01 01 07 63 68 61 6e 6e 65 6c 08 01 01   er....channel...
         1498  +|   3856: 04 74 65 73 74 08 01 04 09 0a 09 08 07 0a 09 0b   .test...........
         1499  +|   3872: 0f ef 00 14 2a 00 00 00 00 01 02 02 00 02 01 01   ....*...........
         1500  +|   3888: 01 02 01 01 81 01 88 80 80 80 80 01 04 00 82 06   ................
         1501  +|   3904: 00 00 00 72 06 30 61 62 61 63 6b 08 02 07 04 04   ...r.0aback.....
         1502  +|   3920: 6e 64 6f 6e 08 02 05 02 05 63 74 69 76 65 04 02   ndon.....ctive..
         1503  +|   3936: 02 04 02 0b 02 04 6c 70 68 61 08 04 02 0a 02 03   ......lpha......
         1504  +|   3952: 74 6f 6d 06 02 02 02 02 09 05 02 69 63 07 02 02   tom........ic...
         1505  +|   3968: 01 06 62 61 63 6b 75 70 08 02 04 02 05 6f 6f 66   ..backup.....oof
         1506  +|   3984: 65 72 05 02 02 04 03 6d 65 72 08 02 08 01 07 63   er.....mer.....c
         1507  +|   4000: 68 61 6e 6e 65 6c 08 02 03 01 04 74 65 73 74 08   hannel.....test.
         1508  +|   4016: 02 06 04 0a 09 0d 0a 0b 07 0b 0a 08 0c 24 84 80   .............$..
         1509  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1510  +|   4048: 63 6b 01 02 66 04 00 22 74 00 02 22 04 04 6e 64   ck..f...t.....nd
         1511  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 06 06 00   on..............
         1512  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1513  +| page 3 offset 8192
         1514  +|      0: 0a 00 00 00 03 0f ec 00 0f fa 0f f3 0f ec 00 00   ................
         1515  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         1516  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1517  +| page 4 offset 12288
         1518  +|      0: 0d 0f e0 00 06 0f b6 00 0f f6 0f ec 0f d5 0f ca   ................
         1519  +|     16: 0f c1 0f b6 0f 70 0f 70 00 00 00 00 00 00 00 00   .....p.p........
         1520  +|   3952: 0f e0 00 46 81 0d 61 6c 70 68 61 20 63 68 61 6e   ...F..alpha chan
         1521  +|   3968: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1522  +|   3984: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1523  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1524  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1525  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 09 05 03 00 19 62   c.....atom.....b
         1526  +|   4048: 6f 6f 66 65 72 09 04 03 00 19 61 63 74 69 76 65   oofer.....active
         1527  +|   4064: 00 00 00 0c 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1528  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1529  +| page 5 offset 16384
         1530  +|      0: 0d 0f ee 00 06 0f d6 00 0f fa 0f f4 0f e8 0f e2   ................
         1531  +|     16: 0f dc 0f d6 0f d0 0f d0 00 00 00 00 00 00 00 00   ................
         1532  +|   4048: 0f ee 00 06 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1533  +|   4064: 0e 01 04 05 03 00 0e 01 04 04 03 00 0e 01 00 00   ................
         1534  +|   4080: 00 06 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1535  +| page 6 offset 20480
         1536  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1537  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1538  +| page 7 offset 24576
         1539  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1540  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1541  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1542  +|   4080: 86 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   .eck....optimize
         1543  +| end c20b.db
         1544  +}]} {}
         1545  +
         1546  +do_catchsql_test 19.1 {
         1547  +  INSERT INTO t1(t1) VALUES('optimize');
         1548  +} {1 {database disk image is malformed}}
         1549  +
         1550  +#--------------------------------------------------------------------------
         1551  +reset_db
         1552  +do_test 20.0 {
         1553  +  sqlite3 db {}
         1554  +  db deserialize [decode_hexdb {
         1555  +| size 28672 pagesize 4096 filename crash-cf347c523f793c.db
         1556  +| page 1 offset 0
         1557  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1558  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         1559  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
         1560  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1561  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
         1562  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1563  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1564  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1565  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1566  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1567  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1568  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1569  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1570  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1571  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1572  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1573  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1574  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1575  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1576  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1577  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1578  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1579  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1580  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1581  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1582  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1583  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1584  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1585  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1586  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1587  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1588  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1589  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1590  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1591  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1592  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1593  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1594  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1595  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1596  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1597  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1598  +| page 2 offset 4096
         1599  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1600  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1601  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1602  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
         1603  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1604  +|   4080: 0a 03 00 24 00 00 00 0e ee ee ee ee ee ee ee ee   ...$............
         1605  +| page 3 offset 8192
         1606  +|      0: ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee   ................
         1607  +|     16: ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee   ................
         1608  +|     32: ee ee ee ee ee ee ee ee ee ee ee ee 00 10 10 10   ................
         1609  +|     48: 00 10 10 10 10 a0 00 00 00 10 ff a0 00 ff 00 00   ................
         1610  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1611  +| page 4 offset 12288
         1612  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1613  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1614  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1615  +| page 5 offset 16384
         1616  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1617  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1618  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1619  +| page 6 offset 20480
         1620  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1621  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1622  +| page 7 offset 24576
         1623  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1624  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1625  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1626  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1627  +| end crash-cf347c523f793c.db
         1628  +}]} {}
         1629  +
         1630  +do_catchsql_test 20.1 {
         1631  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
         1632  +} {1 {vtable constructor failed: t1}}
         1633  +
         1634  +#-------------------------------------------------------------------------
         1635  +reset_db
         1636  +do_test 21.0 {
         1637  +  sqlite3 db {}
         1638  +  db deserialize [decode_hexdb {
         1639  +| size 28672 pagesize 4096 filename c22b.db
         1640  +| page 1 offset 0
         1641  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1642  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1643  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1644  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1645  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1646  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1647  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1648  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1649  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1650  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1651  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1652  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1653  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1654  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1655  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1656  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1657  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1658  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1659  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1660  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1661  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1662  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1663  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1664  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1665  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1666  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1667  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1668  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1669  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1670  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1671  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1672  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1673  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1674  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1675  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1676  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1677  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1678  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1679  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1680  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1681  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1682  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1683  +| page 2 offset 4096
         1684  +|      0: 0d 0e 8e 00 06 0e 2f 00 0f e8 0e 2f 0f bd 0f 3b   ....../..../...;
         1685  +|     16: 0e a5 0e 49 00 00 00 00 00 00 00 00 00 00 00 00   ...I............
         1686  +|   3616: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18   ................
         1687  +|   3632: 0a 03 00 36 00 00 00 00 01 04 04 00 04 01 01 01   ...6............
         1688  +|   3648: 02 01 01 03 01 01 04 01 01 3e 90 80 80 80 80 01   .........>......
         1689  +|   3664: 04 00 81 00 00 00 00 36 06 30 62 61 63 6b 75 05   .......6.0backu.
         1690  +|   3680: 02 04 05 02 04 02 05 65 61 6d 65 72 05 02 02 05   .......eamer....
         1691  +|   3696: 02 02 02 05 6f 6f 6d 65 72 05 01 05 01 02 05 75   ....oomer......u
         1692  +|   3712: 6d 6d 65 72 05 02 03 05 02 03 04 0d 0d 0b 0f 27   mmer...........'
         1693  +|   3728: 00 17 30 00 00 00 00 01 03 03 00 03 01 01 01 02   ..0.............
         1694  +|   3744: 01 01 03 01 01 7b 8c 80 80 80 80 01 04 00 81 7a   ...............z
         1695  +|   3760: 00 00 00 6d 06 30 61 62 61 63 6b 0d 02 07 04 04   ...m.0aback.....
         1696  +|   3776: 6e 64 6f 6e 0d 02 05 02 05 63 74 69 76 65 09 02   ndon.....ctive..
         1697  +|   3792: 02 04 02 0b 02 04 6c 70 68 61 0d 04 02 0a 02 03   ......lpha......
         1698  +|   3808: 74 6f 6d 0b 02 02 02 02 09 05 02 69 63 0c 02 02   tom........ic...
         1699  +|   3824: 01 06 62 61 63 6b 75 70 0d 02 04 02 05 6f 6f 6d   ..backup.....oom
         1700  +|   3840: 65 72 0a 02 02 03 02 08 01 07 63 68 61 6e 6e 65   er........channe
         1701  +|   3856: 6c 0d 02 03 01 04 74 65 73 74 0d 02 06 04 0a 09   l.....test......
         1702  +|   3872: 0d 0a 0b 07 0b 0d 0c 0f ef 00 14 2a 00 00 00 00   ...........*....
         1703  +|   3888: 01 02 02 00 02 01 01 01 02 01 01 7b 88 80 80 80   ................
         1704  +|   3904: 80 01 04 00 81 7a 00 00 00 6d 06 30 61 62 61 63   .....z...m.0abac
         1705  +|   3920: 6b 08 02 07 04 04 6e 64 6f 6e 08 02 05 02 05 63   k.....ndon.....c
         1706  +|   3936: 74 69 76 65 04 02 02 04 02 0b 02 04 6c 70 68 61   tive........lpha
         1707  +|   3952: 08 04 02 0a 02 03 74 6f 6d 06 02 02 02 02 09 05   ......tom.......
         1708  +|   3968: 02 69 63 07 02 02 01 06 62 61 63 6b 75 70 08 02   .ic.....backup..
         1709  +|   3984: 04 02 05 6f 6f 6d 65 72 05 02 02 03 02 08 01 07   ...oomer........
         1710  +|   4000: 63 68 61 6e 6e 65 6c 08 02 03 01 04 74 65 73 74   channel.....test
         1711  +|   4016: 08 02 06 04 0a 09 0d 0a 0b 07 0b 0d 0c 24 84 80   .............$..
         1712  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1713  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1714  +|   4064: 6f 6e 03 02 02 08 0a 07 05 01 03 00 10 0d 23 00   on............#.
         1715  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1716  +| page 3 offset 8192
         1717  +|      0: 0a 00 00 00 04 0f e5 00 0f fa 0f f3 0f ec 0f e5   ................
         1718  +|   4064: 00 00 00 00 00 06 04 01 0c 01 04 02 06 04 01 0c   ................
         1719  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1720  +| page 4 offset 12288
         1721  +|      0: 0d 0f 5a 00 0d 0e ce 00 0f f6 0f ec 0f e0 0f d5   ..Z.............
         1722  +|     16: 0e e7 0f c1 0f b6 0f 70 0f 65 0e ce 0f 51 0f 46   .......p.e...Q.F
         1723  +|     32: 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1724  +|   3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 0a   ................
         1725  +|   3792: 03 00 35 62 65 61 6d 65 72 20 62 75 6d 6d 65 72   ..5beamer bummer
         1726  +|   3808: 20 62 61 63 6b 75 29 17 05 03 00 35 62 65 61 6d    backu)....5beam
         1727  +|   3824: 65 72 20 62 75 6d 6d 65 72 20 62 61 63 6b 75 29   er bummer backu)
         1728  +|   3840: 44 0d 04 00 81 0d 61 6c 70 68 61 20 63 68 61 6e   D.....alpha chan
         1729  +|   3856: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1730  +|   3872: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1731  +|   3888: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1732  +|   3904: 61 63 74 69 76 65 09 0c 03 00 19 61 74 6f 6d 69   active.....atomi
         1733  +|   3920: 63 07 0b 03 00 15 61 74 6f 6d 0f ca 00 0b 19 62   c.....atom.....b
         1734  +|   3936: 6f 6f 6d 65 72 09 09 03 00 19 61 63 74 69 76 65   oomer.....active
         1735  +|   3952: 44 08 04 00 81 0d 61 6c 70 68 61 20 63 68 61 6e   D.....alpha chan
         1736  +|   3968: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1737  +|   3984: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1738  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1739  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1740  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 00 00 00 0b 19 62   c.....atom.....b
         1741  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         1742  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1743  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1744  +| page 5 offset 16384
         1745  +|      0: 0d 00 00 00 0d 0f b2 00 0f fa 0f f4 0f ee 0f e8   ................
         1746  +|     16: 0f e2 0f dc 0f d6 0f d0 0f ca 0f c4 0f be 0f b8   ................
         1747  +|     32: 0f b2 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1748  +|   4016: 00 00 04 0d 03 00 0e 0a 04 0c 03 00 0e 01 04 0b   ................
         1749  +|   4032: 03 00 0e 01 04 0a 03 00 0e 03 04 09 03 00 0e 01   ................
         1750  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1751  +|   4064: 0e 01 04 05 03 00 0e 03 04 04 03 00 0e 01 04 03   ................
         1752  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1753  +| page 6 offset 20480
         1754  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1755  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1756  +| page 7 offset 24576
         1757  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1758  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1759  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1760  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1761  +| end c22b.db
         1762  +}]} {}
         1763  +
         1764  +do_catchsql_test 21.1 {
         1765  +  DELETE FROM t1 WHERE t1 MATCH 'ab*ndon';
         1766  +} {1 {database disk image is malformed}}
         1767  +
         1768  +#-------------------------------------------------------------------------
         1769  +#
         1770  +reset_db
         1771  +do_test 22.0 {
         1772  +  sqlite3 db {}
         1773  +  db deserialize [decode_hexdb {
         1774  +| size 28672 pagesize 4096 filename c22b.db
         1775  +| page 1 offset 0
         1776  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1777  +|     16: 10 00 01 01 00 40 20 20 00 00 00 02 00 00 00 07   .....@  ........
         1778  +|     32: 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00   ................
         1779  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1780  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02   ................
         1781  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1782  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1783  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1784  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1785  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1786  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1787  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1788  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1789  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1790  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1791  +|   3664: 07 17 21 21 01 81 01 74 41 62 6c 65 74 31 5f 64   ..!!...tAblet1_d
         1792  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1793  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1794  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1795  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1796  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1797  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1798  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1799  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1800  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1801  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1802  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1803  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1804  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1805  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1806  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1807  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1808  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1809  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1810  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1811  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1812  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1813  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1814  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1815  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1816  +|   4064: 75 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   uAL TABLE t1 USI
         1817  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1818  +| page 2 offset 4096
         1819  +|      0: 0d 0f 15 00 05 08 4e 00 0f e8 08 4e 0f bd 0f 29   ......N....N...)
         1820  +|     16: 08 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .e..............
         1821  +|   2112: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 0a   ................
         1822  +|   2128: 03 00 30 00 00 00 00 01 03 02 01 03 01 01 01 02   ..0.............
         1823  +|   2144: 01 01 03 01 01 8d 28 8c 80 80 80 80 01 04 00 9a   ......(.........
         1824  +|   2160: 54 00 00 06 77 19 30 30 30 30 30 30 33 30 66 65   T...w.00000030fe
         1825  +|   2176: 65 30 30 30 66 66 61 30 66 66 34 30 66 65 65 05   e000ffa0ff40fee.
         1826  +|   2192: 02 19 02 0b 31 30 66 66 61 30 30 30 66 66 61 05   ....10ffa000ffa.
         1827  +|   2208: 06 13 18 09 02 25 33 34 33 35 32 34 35 34 31 35   .....%3435245415
         1828  +|   2224: 34 34 35 32 30 35 34 34 31 34 32 34 63 34 35 32   445205441424c452
         1829  +|   2240: 30 32 37 37 34 33 31 35 66 36 39 05 02 07 02 37   02774315f69....7
         1830  +|   2256: 34 30 33 30 33 30 30 30 65 30 31 30 34 30 32 30   40303000e0104020
         1831  +|   2272: 33 30 30 30 65 30 31 30 34 30 31 30 33 30 30 30   3000e01040103000
         1832  +|   2288: 65 30 31 30 61 30 30 30 30 30 30 30 31 30 66 66   e010a000000010ff
         1833  +|   2304: 34 30 30 30 66 66 34 05 02 1b 02 27 35 30 34 30   4000ff4....'5040
         1834  +|   2320: 39 30 63 30 31 30 32 30 64 30 30 30 30 30 30 30   90c01020d0000000
         1835  +|   2336: 33 30 66 65 30 30 30 30 66 66 36 30 66 65 63 30   30fe0000ff60fec0
         1836  +|   2352: 66 65 30 05 02 2c 27 02 66 30 05 02 16 02 1d 36   fe0..,'.f0.....6
         1837  +|   2368: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1838  +|   2384: 36 63 36 35 37 34 33 31 37 34 33 31 05 02 0d 02   6c6574317431....
         1839  +|   2400: 29 39 30 33 30 32 31 62 37 32 36 35 36 32 37 35   )903021b72656275
         1840  +|   2416: 36 34 36 31 37 34 36 31 37 34 33 31 35 66 36 34   6461746174315f64
         1841  +|   2432: 36 31 37 34 36 31 30 32 34 33 05 02 1f 02 43 61   6174610243....Ca
         1842  +|   2448: 30 33 30 33 30 30 31 62 36 31 36 32 36 31 36 65   0303001b6162616e
         1843  +|   2464: 36 34 36 66 36 65 30 38 30 32 30 33 30 30 31 37   646f6e0802030017
         1844  +|   2480: 36 31 36 32 36 31 36 36 37 34 30 38 30 31 30 33   6162616674080103
         1845  +|   2496: 30 30 31 37 36 31 36 32 36 31 36 33 36 62 30 64   0017616261636b0d
         1846  +|   2512: 30 30 05 02 18 34 1d 33 36 62 30 31 30 32 30 32   00...4.36b010202
         1847  +|   2528: 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34   0402667402020204
         1848  +|   2544: 30 34 36 65 05 02 2e 02 33 62 30 33 31 62 30 31   046e....3b031b01
         1849  +|   2560: 37 36 36 35 37 32 37 33 36 39 36 66 36 65 30 34   76657273696f6e04
         1850  +|   2576: 30 64 30 30 30 30 30 30 30 33 30 66 64 36 30 30   0d000000030fd600
         1851  +|   2592: 30 66 66 34 30 66 65 31 30 66 64 36 05 02 1d 01   0ff40fe10fd6....
         1852  +|   2608: 04 31 66 62 64 05 04 10 18 01 01 32 05 02 14 02   .1fbd......2....
         1853  +|   2624: 43 34 38 34 38 30 38 30 38 30 38 30 30 31 30 33   C484808080800103
         1854  +|   2640: 30 30 34 65 30 30 30 30 30 30 31 65 30 36 33 30   004e0000001e0630
         1855  +|   2656: 36 31 36 32 36 31 36 33 36 62 30 31 30 32 30 32   616261636b010202
         1856  +|   2672: 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34   0402667402020204
         1857  +|   2688: 30 34 36 65 05 04 11 18 02 01 66 05 02 2a 03 02   046e......f..*..
         1858  +|   2704: 65 72 05 02 31 01 08 33 35 32 38 36 33 36 66 05   er..1..3528636f.
         1859  +|   2720: 02 24 02 03 66 65 30 05 04 17 18 01 2b 34 31 35   .$..fe0.....+415
         1860  +|   2736: 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30 36   259204b45592c206
         1861  +|   2752: 32 36 63 36 66 36 33 36 62 32 30 34 32 34 63 34   26c6f636b20424c4
         1862  +|   2768: 66 34 32 32 39 33 61 30 05 02 0c 2c 1f 31 30 36   f42293a0...,.106
         1863  +|   2784: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1864  +|   2800: 36 63 36 35 37 34 33 31 37 34 33 31 05 02 22 02   6c6574317431....
         1865  +|   2816: 40 33 35 32 34 35 34 31 35 34 34 35 32 30 35 36   @352454154452056
         1866  +|   2832: 34 39 35 32 35 34 37 35 34 31 34 63 32 30 35 34   49525475414c2054
         1867  +|   2848: 34 31 34 32 34 63 34 35 32 30 37 34 33 31 32 30   41424c4520743120
         1868  +|   2864: 35 35 35 33 34 39 34 65 34 37 32 30 36 36 37 34   5553494e47206674
         1869  +|   2880: 37 05 02 23 42 09 33 33 35 32 38 36 33 36 66 05   7..#B.33528636f.
         1870  +|   2896: 02 0e 02 03 66 65 65 05 02 1a 01 34 35 32 34 35   ....fee....45245
         1871  +|   2912: 34 31 35 34 34 35 32 30 35 34 34 31 34 32 34 63   415445205441424c
         1872  +|   2928: 34 35 32 30 32 37 37 34 33 31 35 66 36 34 36 31   45202774315f6461
         1873  +|   2944: 37 34 36 31 32 37 32 38 36 39 36 34 32 30 34 39   7461272869642049
         1874  +|   2960: 05 02 20 16 37 c3 b0 35 32 30 32 37 37 34 33 31   .. .7..520277431
         1875  +|   2976: 35 66 36 34 36 31 37 34 36 31 32 37 32 38 36 39   5f64617461272869
         1876  +|   2992: 36 34 32 30 34 39 34 65 35 34 34 35 34 37 34 35   6420494e54454745
         1877  +|   3008: 35 32 32 30 35 30 35 32 34 39 34 64 05 02 0b 03   52205052494d....
         1878  +|   3024: 48 35 39 32 30 34 62 34 35 35 39 32 63 32 30 36   H59204b45592c206
         1879  +|   3040: 33 33 30 32 39 36 39 30 33 30 30 30 31 35 37 35   3302969030001575
         1880  +|   3056: 33 31 31 39 32 36 64 37 34 36 31 36 32 36 63 36   311926d7461626c6
         1881  +|   3072: 35 37 34 33 31 35 66 36 39 36 34 37 38 37 34 33   574315f696478743
         1882  +|   3088: 31 35 66 36 39 36 34 37 38 05 02 06 02 38 34 32   15f696478....842
         1883  +|   3104: 30 35 32 34 66 35 37 34 39 34 34 35 35 30 32 30   0524f57494455020
         1884  +|   3120: 37 31 37 31 62 31 62 30 31 38 31 30 31 37 34 36   7171b1b018101746
         1885  +|   3136: 31 36 32 36 63 36 35 37 34 33 31 35 66 31 37 34   1626c6574315f174
         1886  +|   3152: 36 31 30 32 34 33 05 02 0a 02 03 66 66 34 05 02   610243.....ff4..
         1887  +|   3168: 1c 01 4a 36 34 36 66 36 65 30 33 30 32 30 32 30   ..J646f6e0302020
         1888  +|   3184: 34 30 61 30 37 30 35 30 31 30 33 30 30 31 30 30   40a0705010300100
         1889  +|   3200: 33 30 33 30 66 30 61 30 33 30 30 32 34 30 30 30   3030f0a030024000
         1890  +|   3216: 30 30 30 30 30 30 31 30 31 30 31 30 30 30 31 30   0000001010100010
         1891  +|   3232: 31 30 31 30 30 39 61 30 30 30 30 30 30 05 02 2f   101009a000000../
         1892  +|   3248: 42 09 31 30 61 30 30 30 30 30 30 05 02 28 08 43   B.10a000000..(.C
         1893  +|   3264: 74 30 32 30 32 30 34 30 61 30 37 30 35 30 31 30   t0202040a0705010
         1894  +|   3280: 33 30 30 31 30 30 33 30 33 30 66 30 61 30 33 30   3001003030f0a030
         1895  +|   3296: 30 32 34 30 30 30 30 30 30 30 30 30 31 30 31 30   0240000000001010
         1896  +|   3312: 31 30 30 30 31 30 31 30 31 30 31 30 61 30 30 30   100010101010a000
         1897  +|   3328: 30 30 30 05 02 12 02 49 37 36 65 36 66 32 63 32   000....I76e6f2c2
         1898  +|   3344: 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32   05052494d4152592
         1899  +|   3360: 30 34 62 34 35 35 39 32 38 37 33 36 35 36 37 36   04b4559287365676
         1900  +|   3376: 39 36 34 32 63 32 30 37 34 36 35 37 32 36 64 32   9642c207465726d2
         1901  +|   3392: 39 32 39 32 30 35 37 34 39 35 34 34 38 34 66 35   92920574954484f5
         1902  +|   3408: 35 05 02 09 02 4c 39 37 61 36 35 37 34 33 31 35   5....L97a6574315
         1903  +|   3424: 66 36 34 36 66 36 33 37 33 36 39 37 61 36 35 30   f646f6373697a650
         1904  +|   3440: 35 34 33 35 32 34 35 34 31 35 34 34 35 32 30 35   5435245415445205
         1905  +|   3456: 34 38 36 39 36 34 32 30 34 39 34 65 35 34 34 35   48696420494e5445
         1906  +|   3472: 34 37 34 35 35 32 32 30 35 30 35 32 34 39 34 34   4745522050524944
         1907  +|   3488: 64 31 05 02 05 02 27 65 37 34 36 35 36 65 37 34   d1....'e74656e74
         1908  +|   3504: 32 39 30 64 30 30 30 30 30 30 30 33 30 66 62 64   290d000000030fbd
         1909  +|   3520: 30 30 30 62 65 38 30 66 65 66 30 66 62 64 05 02   000be80fef0fbd..
         1910  +|   3536: 0f 1e 0b 66 65 38 30 66 65 66 30 66 62 64 05 02   ...fe80fef0fbd..
         1911  +|   3552: 25 02 03 66 64 36 05 02 1e 01 4a 37 36 32 39 32   %..fd6....J76292
         1912  +|   3568: 30 35 37 34 39 35 34 34 38 34 66 35 35 35 34 32   0574954484f55542
         1913  +|   3584: 30 35 32 34 66 35 37 34 39 34 34 35 62 30 35 30   0524f5749445b050
         1914  +|   3600: 37 31 37 32 31 32 31 30 31 38 31 30 31 37 34 36   7172121018101746
         1915  +|   3616: 31 36 32 36 63 36 35 37 34 33 31 35 66 36 34 36   1626c6574315f646
         1916  +|   3632: 66 36 33 37 33 05 02 04 02 21 38 32 37 32 38 37   f6373....!827287
         1917  +|   3648: 33 36 35 36 37 36 39 36 34 32 63 32 30 37 34 36   3656769642c20746
         1918  +|   3664: 35 37 32 36 64 32 63 32 30 37 30 05 02 08 01 01   5726d2c2070.....
         1919  +|   3680: 61 05 02 2b 01 06 62 61 63 6b 75 70 05 02 32 02   a..+..backup..2.
         1920  +|   3696: 05 65 61 6d 65 72 05 02 02 02 05 6f 6f 6d 65 72   .eamer.....oomer
         1921  +|   3712: 05 01 02 40 75 6d 6d 32 34 63 34 35 32 30 32 37   ...@umm24c452027
         1922  +|   3728: 37 34 33 31 35 66 36 33 36 66 36 65 36 36 36 39   74315f636f6e6669
         1923  +|   3744: 36 37 32 37 32 38 36 62 32 30 35 30 35 32 34 39   6727286b20505249
         1924  +|   3760: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1925  +|   3776: 32 63 32 30 05 02 03 01 15 65 35 34 34 35 34 37   2c20.....e544547
         1926  +|   3792: 34 35 35 32 32 30 35 30 35 32 34 39 34 64 05 02   4552205052494d..
         1927  +|   3808: 21 01 02 66 61 05 02 15 04 1d 12 2a 3c 2c 07 22   !..fa......*<,..
         1928  +|   3824: 2e 48 22 38 0a 06 49 06 07 0d 09 30 24 45 0e 08   .H.8..I....0$E..
         1929  +|   3840: 39 3c 4d 3d 08 4f 0e 48 4e 51 2c 10 08 4f 26 06   9<M=.O.HNQ,..O&.
         1930  +|   3856: 0b 0a 09 45 1a 0f ef 00 14 2a 00 00 00 00 01 02   ...E.....*......
         1931  +|   3872: 01 01 02 01 01 01 02 01 01 81 0c 88 80 80 80 80   ................
         1932  +|   3888: 01 04 00 82 1c 00 00 00 7c 08 30 61 62 61 6e 64   ........|.0aband
         1933  +|   3904: 6f 6e 08 02 05 02 05 63 74 69 76 65 04 02 02 04   on.....ctive....
         1934  +|   3920: 02 0b 02 04 6c 70 68 61 08 04 02 0a 02 03 74 6b   ....lpha......tk
         1935  +|   3936: 6d 06 02 02 03 02 6f 6d 08 02 09 05 02 69 63 07   m.....om.....ic.
         1936  +|   3952: 02 02 01 06 62 61 63 6b 75 70 08 02 04 02 05 6f   ....backup.....o
         1937  +|   3968: 6f 6d 65 72 05 02 02 01 0c 63 68 61 6e 6e 65 62   omer.....channeb
         1938  +|   3984: 6f 6f 6d 65 72 08 02 08 07 01 6c 08 02 03 01 06   oomer.....l.....
         1939  +|   4000: 73 74 61 61 63 6b 08 02 07 01 03 74 65 62 08 02   staack.....teb..
         1940  +|   4016: 06 04 0c 0d 0a 08 07 07 0b 0a 11 06 0b 24 84 80   .............$..
         1941  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1942  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
         1943  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 08 41 00   on............A.
         1944  +|   4080: 00 00 11 24 00 00 00 00 01 01 00 01 01 01 01 01   ...$............
         1945  +| page 3 offset 8192
         1946  +|      0: 0a 00 00 00 03 0f ec 00 ff 00 0f f3 0f ec 00 00   ................
         1947  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         1948  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1949  +| page 4 offset 12288
         1950  +|      0: 0d 0f ca 00 08 07 e1 00 0f f6 0f ec 0f e0 0f d5   ................
         1951  +|     16: 07 e1 0f c1 0f b6 0f 6a 00 00 00 00 00 00 00 00   .......j........
         1952  +|   2016: 00 8f 06 05 04 00 9e 11 62 65 61 6d 65 72 20 62   ........beamer b
         1953  +|   2032: 75 6d 6d 32 34 63 34 35 32 30 32 37 37 34 33 31   umm24c4520277431
         1954  +|   2048: 35 66 36 33 36 66 36 65 36 36 36 39 36 37 32 37   5f636f6e66696727
         1955  +|   2064: 32 38 36 62 32 30 35 30 35 32 34 39 34 64 34 31   286b205052494d41
         1956  +|   2080: 35 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30   5259204b45592c20
         1957  +|   2096: 0a 37 36 32 39 32 30 35 37 34 39 35 34 34 38 34   .762920574954484
         1958  +|   2112: 66 35 35 35 34 32 30 35 32 34 66 35 37 34 39 34   f555420524f57494
         1959  +|   2128: 34 35 62 30 35 30 37 31 37 32 31 32 31 30 31 38   45b0507172121018
         1960  +|   2144: 31 30 31 37 34 36 31 36 32 36 63 36 35 37 34 33   1017461626c65743
         1961  +|   2160: 31 35 66 36 34 36 66 36 33 37 33 0a 36 39 37 61   15f646f6373.697a
         1962  +|   2176: 36 35 37 34 33 31 35 66 36 34 36 66 36 33 37 33   6574315f646f6373
         1963  +|   2192: 36 39 37 61 36 35 30 35 34 33 35 32 34 35 34 31   697a650543524541
         1964  +|   2208: 35 34 34 35 32 30 35 34 38 36 39 36 34 32 30 34   5445205486964204
         1965  +|   2224: 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30 35   94e5445474552205
         1966  +|   2240: 30 35 32 34 39 34 34 64 31 0a 35 32 35 39 32 30   0524944d1.525920
         1967  +|   2256: 34 62 34 35 35 39 32 63 32 30 36 33 33 30 32 39   4b45592c20633029
         1968  +|   2272: 36 39 30 33 30 30 30 31 35 37 35 33 31 31 39 32   6903000157531192
         1969  +|   2288: 36 64 37 34 36 31 36 32 36 63 36 35 37 34 33 31   6d7461626c657431
         1970  +|   2304: 35 66 36 39 36 34 37 38 37 34 33 31 35 66 36 39   5f69647874315f69
         1971  +|   2320: 36 34 37 38 0a 30 33 34 33 35 32 34 35 34 31 35   6478.03435245415
         1972  +|   2336: 34 34 35 32 30 35 34 34 31 34 32 34 63 34 35 32   445205441424c452
         1973  +|   2352: 30 32 37 37 34 33 31 35 66 36 39 01 0e 37 38 32   02774315f69..782
         1974  +|   2368: 37 32 38 37 33 36 35 36 37 36 39 36 34 32 63 32   72873656769642c2
         1975  +|   2384: 30 37 34 36 35 37 32 36 64 32 63 32 30 37 30 0a   07465726d2c2070.
         1976  +|   2400: 36 37 36 65 36 66 32 63 32 30 35 30 35 32 34 39   676e6f2c20505249
         1977  +|   2416: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1978  +|   2432: 32 38 37 33 36 35 36 37 36 39 36 34 32 63 32 30   2873656769642c20
         1979  +|   2448: 37 34 36 35 37 32 36 64 32 39 32 39 32 30 35 37   7465726d29292057
         1980  +|   2464: 34 39 35 34 34 38 34 66 35 35 0a 35 34 32 30 35   4954484f55.54205
         1981  +|   2480: 32 34 66 35 37 34 39 34 34 35 35 30 32 30 37 31   24f5749445502071
         1982  +|   2496: 37 31 62 31 62 30 31 38 31 30 31 37 34 36 31 36   71b1b01810174616
         1983  +|   2512: 32 36 63 36 35 37 34 33 31 35 66 31 37 34 36 31   26c6574315f17461
         1984  +|   2528: 30 32 34 33 0a 35 32 34 35 34 31 35 34 34 35 32   0243.52454154452
         1985  +|   2544: 30 35 34 34 31 34 32 34 63 34 c3 b0 35 32 30 32   05441424c4..5202
         1986  +|   2560: 37 37 34 33 31 35 66 36 34 36 31 37 34 36 31 32   774315f646174612
         1987  +|   2576: 37 32 38 36 39 36 34 32 30 34 39 34 65 35 34 34   728696420494e544
         1988  +|   2592: 35 34 37 34 35 35 32 32 30 35 30 35 32 34 39 34   5474552205052494
         1989  +|   2608: 64 0a 34 31 35 32 35 39 32 30 34 62 34 35 35 39   d.415259204b4559
         1990  +|   2624: 32 63 32 30 36 32 36 63 36 66 36 33 36 62 32 30   2c20626c6f636b20
         1991  +|   2640: 34 32 34 63 34 66 34 32 32 39 33 61 30 21 30 36   424c4f42293a0!06
         1992  +|   2656: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1993  +|   2672: 36 63 36 35 37 34 33 31 37 34 33 31 0a 34 33 35   6c6574317431.435
         1994  +|   2688: 32 34 35 34 31 35 34 34 35 32 30 35 36 34 39 35   2454154452056495
         1995  +|   2704: 32 35 34 37 35 34 31 34 63 32 30 35 34 34 31 34   25475414c2054414
         1996  +|   2720: 32 34 63 34 35 32 30 37 34 33 31 32 30 35 35 35   24c4520743120555
         1997  +|   2736: 33 34 39 34 65 34 37 32 30 36 36 37 34 37 33 33   3494e47206674733
         1998  +|   2752: 35 32 38 36 33 36 66 0a 36 65 37 34 36 35 36 65   528636f.6e74656e
         1999  +|   2768: 37 34 32 39 30 64 30 30 30 30 30 30 30 33 30 66   74290d000000030f
         2000  +|   2784: 62 64 30 30 30 62 65 38 30 66 65 66 30 66 62 64   bd000be80fef0fbd
         2001  +|   2800: 0a 5b 31 66 62 64 5d 32 34 38 34 38 30 38 30 38   .[1fbd]248480808
         2002  +|   2816: 30 38 30 30 31 30 33 30 30 34 65 30 30 30 30 30   0800103004e00000
         2003  +|   2832: 30 31 65 30 36 33 30 36 31 36 32 36 31 36 33 36   01e0630616261636
         2004  +|   2848: 62 30 31 30 32 30 32 30 34 30 32 36 36 37 34 30   b010202040266740
         2005  +|   2864: 32 30 32 30 32 30 34 30 34 36 65 0a 36 34 36 66   2020204046e.646f
         2006  +|   2880: 36 65 30 54 30 32 30 32 30 34 30 61 30 37 30 35   6e0T0202040a0705
         2007  +|   2896: 30 31 30 33 30 30 31 30 30 33 30 33 30 66 30 61   0103001003030f0a
         2008  +|   2912: 30 33 30 30 32 34 30 30 30 30 30 30 30 30 30 31   0300240000000001
         2009  +|   2928: 30 31 30 31 30 30 30 31 30 31 30 31 30 31 30 61   010100010101010a
         2010  +|   2944: 30 30 30 30 30 30 0a 30 31 30 66 66 61 30 30 30   000000.010ffa000
         2011  +|   2960: 66 66 61 0a 5b 32 21 66 61 5d 30 35 30 34 30 39   ffa.[2!fa]050409
         2012  +|   2976: 30 63 30 31 30 32 30 64 30 30 30 30 30 30 30 33   0c01020d00000003
         2013  +|   2992: 30 66 65 30 30 30 30 66 66 36 30 66 65 63 30 66   0fe0000ff60fec0f
         2014  +|   3008: 66 30 0a 5b 33 66 65 30 5d 30 61 30 33 30 33 30   f0.[3fe0]0a03030
         2015  +|   3024: 30 31 62 36 31 36 32 36 31 36 65 36 34 36 66 36   01b6162616e646f6
         2016  +|   3040: 65 30 38 30 32 30 33 30 30 31 37 36 31 36 32 36   e080203001761626
         2017  +|   3056: 31 36 36 37 34 30 38 30 31 30 33 30 30 31 37 36   1667408010300176
         2018  +|   3072: 31 36 32 36 31 36 33 36 62 30 64 30 30 0a 30 30   16261636b0d00.00
         2019  +|   3088: 30 30 30 33 30 66 65 65 30 30 30 66 66 61 30 66   00030fee000ffa0f
         2020  +|   3104: 66 34 30 66 65 65 0a 5b 34 66 65 65 5d 30 34 30   f40fee.[4fee]040
         2021  +|   3120: 33 30 33 30 30 30 65 30 31 30 34 30 32 30 33 30   303000e010402030
         2022  +|   3136: 30 30 65 30 31 30 34 30 31 30 33 30 30 30 65 30   00e01040103000e0
         2023  +|   3152: 31 30 61 30 30 30 30 30 30 30 31 30 66 66 34 30   10a000000010ff40
         2024  +|   3168: 30 30 66 66 34 0a 5b 35 66 66 34 5d 30 62 30 33   00ff4.[5ff4]0b03
         2025  +|   3184: 31 62 30 31 37 36 36 35 37 32 37 33 36 39 36 66   1b0176657273696f
         2026  +|   3200: 36 65 30 34 30 64 30 30 30 30 30 30 30 33 30 66   6e040d000000030f
         2027  +|   3216: 64 36 30 30 30 66 66 34 30 66 65 31 30 66 64 36   d6000ff40fe10fd6
         2028  +|   3232: 0a 5b 36 66 64 36 5d 30 39 30 33 30 32 31 62 37   .[6fd6]0903021b7
         2029  +|   3248: 32 36 35 36 32 37 35 36 34 36 31 37 34 36 31 37   2656275646174617
         2030  +|   3264: 34 33 31 35 66 36 34 36 31 37 34 36 31 30 32 34   4315f64617461024
         2031  +|   3280: 33 0a 35 32 34 35 34 31 35 34 34 35 32 30 35 34   3.52454154452054
         2032  +|   3296: 34 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31   41424c4520277431
         2033  +|   3312: 35 66 36 34 36 31 37 34 36 31 32 37 32 38 36 39   5f64617461272869
         2034  +|   3328: 36 34 32 30 34 39 c2 81 65 35 34 34 35 34 37 34   642049..e5445474
         2035  +|   3344: 35 35 32 32 30 35 30 35 32 34 39 34 64 0a 34 31   552205052494d.41
         2036  +|   3360: 35 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30   5259204b45592c20
         2037  +|   3376: 36 32 36 63 36 66 36 33 36 62 32 30 34 32 34 63   626c6f636b20424c
         2038  +|   3392: 34 66 34 32 32 39 33 61 30 31 30 36 31 37 31 31   4f42293a01061711
         2039  +|   3408: 31 31 30 38 36 33 37 34 36 31 36 32 36 63 36 35   1108637461626c65
         2040  +|   3424: 37 34 33 31 37 34 33 31 0a 34 33 35 32 34 35 34   74317431.4352454
         2041  +|   3440: 31 35 34 34 35 32 30 35 36 34 39 35 32 35 34 37   1544520564952547
         2042  +|   3456: 35 34 31 34 63 32 30 35 34 34 31 34 32 34 63 34   5414c205441424c4
         2043  +|   3472: 35 32 30 37 34 33 31 32 30 35 35 35 33 34 39 34   5207431205553494
         2044  +|   3488: 65 34 37 32 30 36 36 37 34 37 3b 33 35 32 38 36   e472066747;35286
         2045  +|   3504: 33 36 66 0a 36 65 37 34 36 35 36 65 37 34 32 39   36f.6e74656e7429
         2046  +|   3520: 30 64 30 30 30 30 30 30 30 33 30 66 62 64 30 30   0d000000030fbd00
         2047  +|   3536: 30 66 65 38 30 66 65 66 30 66 62 64 0a 5b 31 66   0fe80fef0fbd.[1f
         2048  +|   3552: 62 64 5d 32 34 38 34 38 30 38 30 38 30 38 30 30   bd]2484808080800
         2049  +|   3568: 31 30 33 30 30 34 65 30 30 30 30 30 30 31 65 30   103004e0000001e0
         2050  +|   3584: 36 33 30 36 31 36 32 36 31 36 33 36 62 30 31 30   630616261636b010
         2051  +|   3600: 32 30 32 30 34 30 32 36 36 37 34 30 32 30 32 30   2020402667402020
         2052  +|   3616: 32 30 34 30 34 36 65 0a 36 34 36 66 36 65 30 33   204046e.646f6e03
         2053  +|   3632: 30 32 30 32 30 34 30 61 30 37 30 35 30 31 30 33   0202040a07050103
         2054  +|   3648: 30 30 31 30 30 33 30 33 30 66 30 61 30 33 30 30   001003030f0a0300
         2055  +|   3664: 32 34 30 30 30 30 30 30 30 30 30 31 30 31 30 31   2400000000010101
         2056  +|   3680: 30 30 30 31 30 31 30 31 30 31 30 61 30 30 30 30   00010101010a0000
         2057  +|   3696: 30 30 0a 30 31 30 66 66 61 30 30 30 66 66 61 0a   00.010ffa000ffa.
         2058  +|   3712: 5b 32 66 29 61 5d 30 35 30 34 30 39 30 63 30 31   [2f)a]0504090c01
         2059  +|   3728: 30 32 30 64 30 30 30 30 30 30 30 33 30 66 65 30   020d000000030fe0
         2060  +|   3744: 30 30 30 66 66 36 30 66 65 63 30 66 65 30 0a 5b   000ff60fec0fe0.[
         2061  +|   3760: 33 66 65 30 5d 30 61 30 33 30 33 30 30 31 62 36   3fe0]0a0303001b6
         2062  +|   3776: 31 36 32 36 31 36 65 36 34 36 66 36 65 30 38 30   162616e646f6e080
         2063  +|   3792: 32 30 33 30 30 31 37 36 31 36 32 36 31 36 36 37   2030017616261667
         2064  +|   3808: 34 30 38 30 31 30 33 30 33 36 62 30 31 30 32 30   4080103036b01020
         2065  +|   3824: 32 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30   2040266740202020
         2066  +|   3840: 34 30 34 36 65 0a 36 34 36 66 36 65 30 33 30 32   4046e.646f6e0302
         2067  +|   3856: 30 32 30 34 30 61 30 37 30 35 30 31 30 33 30 30   02040a0705010300
         2068  +|   3872: 31 30 30 33 30 33 30 66 30 61 30 33 30 30 32 34   1003030f0a030024
         2069  +|   3888: 30 30 30 30 30 30 30 30 30 31 30 31 30 31 30 30   0000000001010100
         2070  +|   3904: 30 31 30 31 30 31 30 30 39 61 30 30 30 30 30 30   010101009a000000
         2071  +|   3920: 0a 30 31 30 66 66 61 30 30 30 66 66 61 0a 5b 32   .010ffa000ffa.[2
         2072  +|   3936: 66 65 72 20 62 61 63 6b 75 70 4a 08 04 00 81 19   fer backupJ.....
         2073  +|   3952: 61 6c 70 68 61 20 63 68 61 6e 6e 65 6c 20 62 61   alpha channel ba
         2074  +|   3968: 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65 62   ckup abandon teb
         2075  +|   3984: 20 73 74 61 61 63 6b 20 63 68 61 6e 6e 65 62 6f    staack channebo
         2076  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         2077  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         2078  +|   4032: 63 07 06 03 00 15 61 74 6b 6d 00 00 00 0b 19 62   c.....atkm.....b
         2079  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         2080  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         2081  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         2082  +| page 5 offset 16384
         2083  +|      0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8   ................
         2084  +|     16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00   ................
         2085  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         2086  +|   4064: 0e 01 04 05 03 00 0e 31 04 04 03 00 0e 01 04 03   .......1........
         2087  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         2088  +| page 6 offset 20480
         2089  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         2090  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         2091  +| page 7 offset 24576
         2092  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         2093  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         2094  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         2095  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         2096  +| end c22b.db
         2097  +}]} {}
         2098  +
         2099  +
         2100  +do_catchsql_test 22.1 {
         2101  +  INSERT INTO t1(t1) VALUES('optimize');
         2102  +} {1 {vtable constructor failed: t1}}
         2103  +
   419   2104   sqlite3_fts5_may_be_corrupt 0
   420   2105   finish_test
         2106  +

Changes to ext/fts5/test/fts5unicode3.test.

    17     17   # If SQLITE_ENABLE_FTS5 is defined, omit this file.
    18     18   ifcapable !fts5 {
    19     19     finish_test
    20     20     return
    21     21   }
    22     22   
    23     23   proc fts3_unicode_path {file} {
    24         -  file join [file dirname [info script]] .. .. fts3 unicode $file
           24  +  file join .. [file dirname [info script]] .. .. fts3 unicode $file
    25     25   }
    26     26   
    27     27   source [fts3_unicode_path parseunicode.tcl]
    28     28   set testprefix fts5unicode3
    29     29   
    30     30   set CF [fts3_unicode_path CaseFolding.txt]
    31     31   set UD [fts3_unicode_path UnicodeData.txt]

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

    75     75   } {
    76     76     0 term {} 0 {} 0
    77     77     1 col {} 0 {} 0
    78     78     2 doc {} 0 {} 0
    79     79     3 cnt {} 0 {} 0
    80     80   }
    81     81   
    82         -do_execsql_test 1.2.1 { SELECT * FROM v1 } { }
    83         -do_execsql_test 1.2.2 { SELECT * FROM v2 } { }
           82  +do_execsql_test 1.2.1 { SELECT * FROM v1 } {}
           83  +do_execsql_test 1.2.2 { SELECT * FROM v2 } {}
    84     84   
    85     85   do_execsql_test 1.3 {
    86     86     INSERT INTO t1 VALUES('x y z');
    87     87     INSERT INTO t1 VALUES('x x x');
    88     88   }
    89     89   
    90     90   do_execsql_test 1.4.1 {

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

    76     76     four  2 b 0
    77     77     three 2 a 0
    78     78   }
    79     79   
    80     80   do_execsql_test 1.5 {
    81     81     DELETE FROM t1;
    82     82     SELECT * FROM v1;
    83         -} {
    84         -}
           83  +} {}
    85     84   
    86     85   #-------------------------------------------------------------------------
    87     86   #
    88     87   do_execsql_test 2.0 {
    89     88     DROP TABLE IF EXISTS t1;
    90     89     DROP TABLE IF EXISTS v1;
    91     90   
................................................................................
   139    138     four  2 b {}
   140    139     three 2 a {}
   141    140   }
   142    141   
   143    142   do_execsql_test 2.5 {
   144    143     DELETE FROM t1;
   145    144     SELECT * FROM v1;
   146         -} {
   147         -}
          145  +} {}
   148    146   
   149    147   #-------------------------------------------------------------------------
   150    148   #
   151    149   do_execsql_test 3.0 {
   152    150     DROP TABLE IF EXISTS t1;
   153    151     DROP TABLE IF EXISTS v1;
   154    152   
................................................................................
   198    196     four  2 {} {}
   199    197     three 2 {} {}
   200    198   }
   201    199   
   202    200   do_execsql_test 3.5 {
   203    201     DELETE FROM t1;
   204    202     SELECT * FROM v1;
   205         -} {
   206         -}
          203  +} {}
   207    204   
   208    205   finish_test

Changes to ext/misc/csv.c.

   617    617     pNew->tstFlags = tstFlags;
   618    618   #endif
   619    619     if( bHeader!=1 ){
   620    620       pNew->iStart = 0;
   621    621     }else if( pNew->zData ){
   622    622       pNew->iStart = (int)sRdr.iIn;
   623    623     }else{
   624         -    pNew->iStart = ftell(sRdr.in);
          624  +    pNew->iStart = ftell(sRdr.in) - sRdr.nIn + sRdr.iIn;
   625    625     }
   626    626     csv_reader_reset(&sRdr);
   627    627     rc = sqlite3_declare_vtab(db, CSV_SCHEMA);
   628    628     if( rc ){
   629    629       csv_errmsg(&sRdr, "bad schema: '%s' - %s", CSV_SCHEMA, sqlite3_errmsg(db));
   630    630       goto csvtab_connect_error;
   631    631     }

Changes to ext/rtree/rtree.c.

   124    124     u8 nDim;                    /* Number of dimensions */
   125    125     u8 nDim2;                   /* Twice the number of dimensions */
   126    126     u8 eCoordType;              /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */
   127    127     u8 nBytesPerCell;           /* Bytes consumed per cell */
   128    128     u8 inWrTrans;               /* True if inside write transaction */
   129    129     u8 nAux;                    /* # of auxiliary columns in %_rowid */
   130    130     u8 nAuxNotNull;             /* Number of initial not-null aux columns */
          131  +#ifdef SQLITE_DEBUG
          132  +  u8 bCorrupt;                /* Shadow table corruption detected */
          133  +#endif
   131    134     int iDepth;                 /* Current depth of the r-tree structure */
   132    135     char *zDb;                  /* Name of database containing r-tree table */
   133    136     char *zName;                /* Name of r-tree table */ 
   134    137     u32 nBusy;                  /* Current number of users of this structure */
   135    138     i64 nRowEst;                /* Estimated number of rows in this table */
   136    139     u32 nCursor;                /* Number of open cursors */
   137    140     u32 nNodeRef;               /* Number RtreeNodes with positive nRef */
................................................................................
   183    186   # define RTREE_ZERO 0
   184    187   #else
   185    188     typedef double RtreeDValue;              /* High accuracy coordinate */
   186    189     typedef float RtreeValue;                /* Low accuracy coordinate */
   187    190   # define RTREE_ZERO 0.0
   188    191   #endif
   189    192   
          193  +/*
          194  +** Set the Rtree.bCorrupt flag
          195  +*/
          196  +#ifdef SQLITE_DEBUG
          197  +# define RTREE_IS_CORRUPT(X) ((X)->bCorrupt = 1)
          198  +#else
          199  +# define RTREE_IS_CORRUPT(X)
          200  +#endif
          201  +
   190    202   /*
   191    203   ** When doing a search of an r-tree, instances of the following structure
   192    204   ** record intermediate results from the tree walk.
   193    205   **
   194    206   ** The id is always a node-id.  For iLevel>=1 the id is the node-id of
   195    207   ** the node that the RtreeSearchPoint represents.  When iLevel==0, however,
   196    208   ** the id is of the parent node and the cell that RtreeSearchPoint
................................................................................
   549    561     p->isDirty = 1;
   550    562   }
   551    563   
   552    564   /*
   553    565   ** Given a node number iNode, return the corresponding key to use
   554    566   ** in the Rtree.aHash table.
   555    567   */
   556         -static int nodeHash(i64 iNode){
   557         -  return iNode % HASHSIZE;
          568  +static unsigned int nodeHash(i64 iNode){
          569  +  return ((unsigned)iNode) % HASHSIZE;
   558    570   }
   559    571   
   560    572   /*
   561    573   ** Search the node hash table for node iNode. If found, return a pointer
   562    574   ** to it. Otherwise, return 0.
   563    575   */
   564    576   static RtreeNode *nodeHashLookup(Rtree *pRtree, i64 iNode){
................................................................................
   618    630   static void nodeBlobReset(Rtree *pRtree){
   619    631     if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){
   620    632       sqlite3_blob *pBlob = pRtree->pNodeBlob;
   621    633       pRtree->pNodeBlob = 0;
   622    634       sqlite3_blob_close(pBlob);
   623    635     }
   624    636   }
          637  +
          638  +/*
          639  +** Check to see if pNode is the same as pParent or any of the parents
          640  +** of pParent.
          641  +*/
          642  +static int nodeInParentChain(const RtreeNode *pNode, const RtreeNode *pParent){
          643  +  do{
          644  +    if( pNode==pParent ) return 1;
          645  +    pParent = pParent->pParent;
          646  +  }while( pParent );
          647  +  return 0;
          648  +}
   625    649   
   626    650   /*
   627    651   ** Obtain a reference to an r-tree node.
   628    652   */
   629    653   static int nodeAcquire(
   630    654     Rtree *pRtree,             /* R-tree structure */
   631    655     i64 iNode,                 /* Node number to load */
................................................................................
   637    661   
   638    662     /* Check if the requested node is already in the hash table. If so,
   639    663     ** increase its reference count and return it.
   640    664     */
   641    665     if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
   642    666       assert( !pParent || !pNode->pParent || pNode->pParent==pParent );
   643    667       if( pParent && !pNode->pParent ){
          668  +      if( nodeInParentChain(pNode, pParent) ){
          669  +        RTREE_IS_CORRUPT(pRtree);
          670  +        return SQLITE_CORRUPT_VTAB;
          671  +      }
   644    672         pParent->nRef++;
   645    673         pNode->pParent = pParent;
   646    674       }
   647    675       pNode->nRef++;
   648    676       *ppNode = pNode;
   649    677       return SQLITE_OK;
   650    678     }
................................................................................
   667    695       sqlite3_free(zTab);
   668    696     }
   669    697     if( rc ){
   670    698       nodeBlobReset(pRtree);
   671    699       *ppNode = 0;
   672    700       /* If unable to open an sqlite3_blob on the desired row, that can only
   673    701       ** be because the shadow tables hold erroneous data. */
   674         -    if( rc==SQLITE_ERROR ) rc = SQLITE_CORRUPT_VTAB;
          702  +    if( rc==SQLITE_ERROR ){
          703  +      rc = SQLITE_CORRUPT_VTAB;
          704  +      RTREE_IS_CORRUPT(pRtree);
          705  +    }
   675    706     }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
   676    707       pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize);
   677    708       if( !pNode ){
   678    709         rc = SQLITE_NOMEM;
   679    710       }else{
   680    711         pNode->pParent = pParent;
   681    712         pNode->zData = (u8 *)&pNode[1];
................................................................................
   696    727     ** are the leaves, and so on. If the depth as specified on the root node
   697    728     ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
   698    729     */
   699    730     if( pNode && iNode==1 ){
   700    731       pRtree->iDepth = readInt16(pNode->zData);
   701    732       if( pRtree->iDepth>RTREE_MAX_DEPTH ){
   702    733         rc = SQLITE_CORRUPT_VTAB;
          734  +      RTREE_IS_CORRUPT(pRtree);
   703    735       }
   704    736     }
   705    737   
   706    738     /* If no error has occurred so far, check if the "number of entries"
   707    739     ** field on the node is too large. If so, set the return code to 
   708    740     ** SQLITE_CORRUPT_VTAB.
   709    741     */
   710    742     if( pNode && rc==SQLITE_OK ){
   711    743       if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
   712    744         rc = SQLITE_CORRUPT_VTAB;
          745  +      RTREE_IS_CORRUPT(pRtree);
   713    746       }
   714    747     }
   715    748   
   716    749     if( rc==SQLITE_OK ){
   717    750       if( pNode!=0 ){
   718    751         nodeHashInsert(pRtree, pNode);
   719    752       }else{
   720    753         rc = SQLITE_CORRUPT_VTAB;
          754  +      RTREE_IS_CORRUPT(pRtree);
   721    755       }
   722    756       *ppNode = pNode;
   723    757     }else{
   724    758       if( pNode ){
   725    759         pRtree->nNodeRef--;
   726    760         sqlite3_free(pNode);
   727    761       }
................................................................................
   939    973   */
   940    974   static void rtreeRelease(Rtree *pRtree){
   941    975     pRtree->nBusy--;
   942    976     if( pRtree->nBusy==0 ){
   943    977       pRtree->inWrTrans = 0;
   944    978       assert( pRtree->nCursor==0 );
   945    979       nodeBlobReset(pRtree);
   946         -    assert( pRtree->nNodeRef==0 );
          980  +    assert( pRtree->nNodeRef==0 || pRtree->bCorrupt );
   947    981       sqlite3_finalize(pRtree->pWriteNode);
   948    982       sqlite3_finalize(pRtree->pDeleteNode);
   949    983       sqlite3_finalize(pRtree->pReadRowid);
   950    984       sqlite3_finalize(pRtree->pWriteRowid);
   951    985       sqlite3_finalize(pRtree->pDeleteRowid);
   952    986       sqlite3_finalize(pRtree->pReadParent);
   953    987       sqlite3_finalize(pRtree->pWriteParent);
................................................................................
  1271   1305     assert( nCell<200 );
  1272   1306     for(ii=0; ii<nCell; ii++){
  1273   1307       if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
  1274   1308         *piIndex = ii;
  1275   1309         return SQLITE_OK;
  1276   1310       }
  1277   1311     }
         1312  +  RTREE_IS_CORRUPT(pRtree);
  1278   1313     return SQLITE_CORRUPT_VTAB;
  1279   1314   }
  1280   1315   
  1281   1316   /*
  1282   1317   ** Return the index of the cell containing a pointer to node pNode
  1283   1318   ** in its parent. If pNode is the root node, return -1.
  1284   1319   */
................................................................................
  1911   1946   
  1912   1947       if( p->usable
  1913   1948       && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
  1914   1949           || p->op==SQLITE_INDEX_CONSTRAINT_MATCH)
  1915   1950       ){
  1916   1951         u8 op;
  1917   1952         switch( p->op ){
  1918         -        case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
  1919         -        case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
  1920         -        case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
  1921         -        case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
  1922         -        case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break;
  1923         -        default:
  1924         -          assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
  1925         -          op = RTREE_MATCH; 
  1926         -          break;
         1953  +        case SQLITE_INDEX_CONSTRAINT_EQ:    op = RTREE_EQ;    break;
         1954  +        case SQLITE_INDEX_CONSTRAINT_GT:    op = RTREE_GT;    break;
         1955  +        case SQLITE_INDEX_CONSTRAINT_LE:    op = RTREE_LE;    break;
         1956  +        case SQLITE_INDEX_CONSTRAINT_LT:    op = RTREE_LT;    break;
         1957  +        case SQLITE_INDEX_CONSTRAINT_GE:    op = RTREE_GE;    break;
         1958  +        case SQLITE_INDEX_CONSTRAINT_MATCH: op = RTREE_MATCH; break;
         1959  +        default:                            op = 0;           break;
  1927   1960         }
  1928         -      zIdxStr[iIdx++] = op;
  1929         -      zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
  1930         -      pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
  1931         -      pIdxInfo->aConstraintUsage[ii].omit = 1;
         1961  +      if( op ){
         1962  +        zIdxStr[iIdx++] = op;
         1963  +        zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
         1964  +        pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
         1965  +        pIdxInfo->aConstraintUsage[ii].omit = 1;
         1966  +      }
  1932   1967       }
  1933   1968     }
  1934   1969   
  1935   1970     pIdxInfo->idxNum = 2;
  1936   1971     pIdxInfo->needToFreeIdxStr = 1;
  1937   1972     if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){
  1938   1973       return SQLITE_NOMEM;
................................................................................
  2133   2168   */
  2134   2169   static int AdjustTree(
  2135   2170     Rtree *pRtree,                    /* Rtree table */
  2136   2171     RtreeNode *pNode,                 /* Adjust ancestry of this node. */
  2137   2172     RtreeCell *pCell                  /* This cell was just inserted */
  2138   2173   ){
  2139   2174     RtreeNode *p = pNode;
         2175  +  int cnt = 0;
  2140   2176     while( p->pParent ){
  2141   2177       RtreeNode *pParent = p->pParent;
  2142   2178       RtreeCell cell;
  2143   2179       int iCell;
  2144   2180   
  2145         -    if( nodeParentIndex(pRtree, p, &iCell) ){
         2181  +    if( (++cnt)>1000 || nodeParentIndex(pRtree, p, &iCell)  ){
         2182  +      RTREE_IS_CORRUPT(pRtree);
  2146   2183         return SQLITE_CORRUPT_VTAB;
  2147   2184       }
  2148   2185   
  2149   2186       nodeGetCell(pRtree, pParent, iCell, &cell);
  2150   2187       if( !cellContains(pRtree, &cell, pCell) ){
  2151   2188         cellUnion(pRtree, &cell, pCell);
  2152   2189         nodeOverwriteCell(pRtree, pParent, &cell, iCell);
................................................................................
  2606   2643         for(pTest=pLeaf; pTest && pTest->iNode!=iNode; pTest=pTest->pParent);
  2607   2644         if( !pTest ){
  2608   2645           rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
  2609   2646         }
  2610   2647       }
  2611   2648       rc = sqlite3_reset(pRtree->pReadParent);
  2612   2649       if( rc==SQLITE_OK ) rc = rc2;
  2613         -    if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT_VTAB;
         2650  +    if( rc==SQLITE_OK && !pChild->pParent ){
         2651  +      RTREE_IS_CORRUPT(pRtree);
         2652  +      rc = SQLITE_CORRUPT_VTAB;
         2653  +    }
  2614   2654       pChild = pChild->pParent;
  2615   2655     }
  2616   2656     return rc;
  2617   2657   }
  2618   2658   
  2619   2659   static int deleteCell(Rtree *, RtreeNode *, int, int);
  2620   2660   
................................................................................
  2919   2959   
  2920   2960     /* Obtain a reference to the leaf node that contains the entry 
  2921   2961     ** about to be deleted. 
  2922   2962     */
  2923   2963     if( rc==SQLITE_OK ){
  2924   2964       rc = findLeafNode(pRtree, iDelete, &pLeaf, 0);
  2925   2965     }
         2966  +
         2967  +#ifdef CORRUPT_DB
         2968  +  assert( pLeaf!=0 || rc!=SQLITE_OK || CORRUPT_DB );
         2969  +#endif
  2926   2970   
  2927   2971     /* Delete the cell in question from the leaf node. */
  2928         -  if( rc==SQLITE_OK ){
         2972  +  if( rc==SQLITE_OK && pLeaf ){
  2929   2973       int rc2;
  2930   2974       rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
  2931   2975       if( rc==SQLITE_OK ){
  2932   2976         rc = deleteCell(pRtree, pLeaf, iCell, 0);
  2933   2977       }
  2934   2978       rc2 = nodeRelease(pRtree, pLeaf);
  2935   2979       if( rc==SQLITE_OK ){
................................................................................
  3193   3237         pRtree->iReinsertHeight = -1;
  3194   3238         rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
  3195   3239         rc2 = nodeRelease(pRtree, pLeaf);
  3196   3240         if( rc==SQLITE_OK ){
  3197   3241           rc = rc2;
  3198   3242         }
  3199   3243       }
  3200         -    if( pRtree->nAux ){
         3244  +    if( rc==SQLITE_OK && pRtree->nAux ){
  3201   3245         sqlite3_stmt *pUp = pRtree->pWriteAux;
  3202   3246         int jj;
  3203   3247         sqlite3_bind_int64(pUp, 1, *pRowid);
  3204   3248         for(jj=0; jj<pRtree->nAux; jj++){
  3205   3249           sqlite3_bind_value(pUp, jj+2, aData[pRtree->nDim2+3+jj]);
  3206   3250         }
  3207   3251         sqlite3_step(pUp);
................................................................................
  3391   3435       /* Read and write the xxx_parent table */
  3392   3436       "SELECT parentnode FROM '%q'.'%q_parent' WHERE nodeno = ?1",
  3393   3437       "INSERT OR REPLACE INTO '%q'.'%q_parent' VALUES(?1, ?2)",
  3394   3438       "DELETE FROM '%q'.'%q_parent' WHERE nodeno = ?1"
  3395   3439     };
  3396   3440     sqlite3_stmt **appStmt[N_STATEMENT];
  3397   3441     int i;
         3442  +  const int f = SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB;
  3398   3443   
  3399   3444     pRtree->db = db;
  3400   3445   
  3401   3446     if( isCreate ){
  3402   3447       char *zCreate;
  3403   3448       sqlite3_str *p = sqlite3_str_new(db);
  3404   3449       int ii;
................................................................................
  3447   3492          /* An UPSERT is very slightly slower than REPLACE, but it is needed
  3448   3493          ** if there are auxiliary columns */
  3449   3494          zFormat = "INSERT INTO\"%w\".\"%w_rowid\"(rowid,nodeno)VALUES(?1,?2)"
  3450   3495                     "ON CONFLICT(rowid)DO UPDATE SET nodeno=excluded.nodeno";
  3451   3496       }
  3452   3497       zSql = sqlite3_mprintf(zFormat, zDb, zPrefix);
  3453   3498       if( zSql ){
  3454         -      rc = sqlite3_prepare_v3(db, zSql, -1, SQLITE_PREPARE_PERSISTENT,
  3455         -                              appStmt[i], 0); 
         3499  +      rc = sqlite3_prepare_v3(db, zSql, -1, f, appStmt[i], 0); 
  3456   3500       }else{
  3457   3501         rc = SQLITE_NOMEM;
  3458   3502       }
  3459   3503       sqlite3_free(zSql);
  3460   3504     }
  3461   3505     if( pRtree->nAux ){
  3462   3506       pRtree->zReadAuxSql = sqlite3_mprintf(
................................................................................
  3478   3522           }
  3479   3523         }
  3480   3524         sqlite3_str_appendf(p, " WHERE rowid=?1");
  3481   3525         zSql = sqlite3_str_finish(p);
  3482   3526         if( zSql==0 ){
  3483   3527           rc = SQLITE_NOMEM;
  3484   3528         }else{
  3485         -        rc = sqlite3_prepare_v3(db, zSql, -1, SQLITE_PREPARE_PERSISTENT,
  3486         -                                &pRtree->pWriteAux, 0); 
         3529  +        rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0); 
  3487   3530           sqlite3_free(zSql);
  3488   3531         }
  3489   3532       }
  3490   3533     }
  3491   3534   
  3492   3535     return rc;
  3493   3536   }
................................................................................
  3555   3598           pRtree->zDb, pRtree->zName
  3556   3599       );
  3557   3600       rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
  3558   3601       if( rc!=SQLITE_OK ){
  3559   3602         *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
  3560   3603       }else if( pRtree->iNodeSize<(512-64) ){
  3561   3604         rc = SQLITE_CORRUPT_VTAB;
         3605  +      RTREE_IS_CORRUPT(pRtree);
  3562   3606         *pzErr = sqlite3_mprintf("undersize RTree blobs in \"%q_node\"",
  3563   3607                                  pRtree->zName);
  3564   3608       }
  3565   3609     }
  3566   3610   
  3567   3611     sqlite3_free(zSql);
  3568   3612     return rc;
................................................................................
  3878   3922   ** Or, if an error does occur, NULL is returned and an error code left
  3879   3923   ** in the RtreeCheck object. The final value of *pnNode is undefined in
  3880   3924   ** this case.
  3881   3925   */
  3882   3926   static u8 *rtreeCheckGetNode(RtreeCheck *pCheck, i64 iNode, int *pnNode){
  3883   3927     u8 *pRet = 0;                   /* Return value */
  3884   3928   
  3885         -  assert( pCheck->rc==SQLITE_OK );
  3886         -  if( pCheck->pGetNode==0 ){
         3929  +  if( pCheck->rc==SQLITE_OK && pCheck->pGetNode==0 ){
  3887   3930       pCheck->pGetNode = rtreeCheckPrepare(pCheck,
  3888   3931           "SELECT data FROM %Q.'%q_node' WHERE nodeno=?", 
  3889   3932           pCheck->zDb, pCheck->zTab
  3890   3933       );
  3891   3934     }
  3892   3935   
  3893   3936     if( pCheck->rc==SQLITE_OK ){

Changes to ext/rtree/rtree6.test.

    54     54       CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
    55     55     }
    56     56   } {}
    57     57   
    58     58   do_test rtree6-1.2 {
    59     59     rtree_strategy {SELECT * FROM t1 WHERE x1>10}
    60     60   } {E0}
           61  +do_test rtree6-1.2.1 {
           62  +  rtree_strategy {SELECT * FROM t1 WHERE x1>10 AND x2 LIKE '%x%'}
           63  +} {E0}
    61     64   
    62     65   do_test rtree6-1.3 {
    63     66     rtree_strategy {SELECT * FROM t1 WHERE x1<10}
    64     67   } {C0}
    65     68   
    66     69   do_test rtree6-1.4 {
    67     70     rtree_strategy {SELECT * FROM t1,t2 WHERE k=ii AND x1<10}

Added ext/rtree/rtreecirc.test.

            1  +# 2018 Dec 22
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#*************************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this script is testing the FTS5 module.
           13  +#
           14  +
           15  +if {![info exists testdir]} {
           16  +  set testdir [file join [file dirname [info script]] .. .. test]
           17  +}
           18  +source [file join [file dirname [info script]] rtree_util.tcl]
           19  +source $testdir/tester.tcl
           20  +set testprefix rtreecirc
           21  +
           22  +ifcapable !rtree {
           23  +  finish_test
           24  +  return
           25  +}
           26  +
           27  +do_execsql_test 1.0 {
           28  +  CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2, y1, y2);
           29  +  SELECT name FROM sqlite_master ORDER BY 1;
           30  +} {
           31  +  rt rt_node rt_parent rt_rowid
           32  +}
           33  +db_save_and_close
           34  +
           35  +foreach {tn schema sql} {
           36  +  1 {
           37  +    CREATE TRIGGER tr1 AFTER INSERT ON rt_node BEGIN
           38  +      SELECT * FROM rt;
           39  +    END;
           40  +  } {
           41  +    INSERT INTO rt VALUES(1, 2, 3, 4, 5);
           42  +  }
           43  +  2 {
           44  +    CREATE TRIGGER tr1 AFTER INSERT ON rt_parent BEGIN
           45  +      SELECT * FROM rt;
           46  +    END;
           47  +  } {
           48  +    INSERT INTO rt VALUES(1, 2, 3, 4, 5);
           49  +  }
           50  +  3 {
           51  +    CREATE TRIGGER tr1 AFTER INSERT ON rt_rowid BEGIN
           52  +      SELECT * FROM rt;
           53  +    END;
           54  +  } {
           55  +    INSERT INTO rt VALUES(1, 2, 3, 4, 5);
           56  +  }
           57  +} {
           58  +  db_restore_and_reopen
           59  +  do_execsql_test  1.1.$tn.1 $schema
           60  +  do_catchsql_test 1.1.$tn.2 $sql {1 {no such table: main.rt}}
           61  +  db close
           62  +}
           63  +
           64  +
           65  +finish_test
           66  +

Added ext/rtree/rtreefuzz001.test.

            1  +# 2012-12-21
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# Test cases for corrupt database files.
           13  +
           14  +if {![info exists testdir]} {
           15  +  set testdir [file join [file dirname [info script]] .. .. test]
           16  +} 
           17  +source $testdir/tester.tcl
           18  +
           19  +ifcapable !deserialize||!rtree {
           20  +  finish_test
           21  +  return
           22  +}
           23  +database_may_be_corrupt
           24  +
           25  +do_test rtreefuzz001-100 {
           26  +  sqlite3 db {}
           27  +  db deserialize [decode_hexdb {
           28  +| size 24576 pagesize 4096 filename c1b.db
           29  +| page 1 offset 0
           30  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
           31  +|     16: 10 00 01 01 00 40 20 20 00 00 00 03 00 00 00 06   .....@  ........
           32  +|     32: 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 04   ................
           33  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
           34  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03   ................
           35  +|     96: 00 2e 30 38 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f   ..08...........O
           36  +|    112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00   ................
           37  +|   3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17   ............^...
           38  +|   3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72   .....tablet1_par
           39  +|   3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45   entt1_parent.CRE
           40  +|   3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61   ATE TABLE .t1_pa
           41  +|   3792: 72 66 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54   rfnt.(nodeno INT
           42  +|   3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
           43  +|   3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17   ,parentnode)Q...
           44  +|   3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65   ....tablet1_node
           45  +|   3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54   t1_node.CREATE T
           46  +|   3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e   ABLE .t1_node.(n
           47  +|   3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52   odeno INTEGER PR
           48  +|   3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c   IMARY KEY,data).
           49  +|   3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f   ........tablet1_
           50  +|   3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52   rowidt1_rowid.CR
           51  +|   3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72   EATE TABLE .t1_r
           52  +|   3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45   owid.(rowid INTE
           53  +|   3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c   GER PRIMARY KEY,
           54  +|   4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07   nodeno,a0,a1)Q..
           55  +|   4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43   ......tablet1t1C
           56  +|   4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41   REATE VIRTUAL TA
           57  +|   4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72   BLE t1 USING rtr
           58  +|   4064: 65 65 28 69 64 2c 78 30 2c 78 31 2c 79 30 2c 79   ee(id,x0,x1,y0,y
           59  +|   4080: 31 2c 2b 6c 61 62 65 6c 2c 2b 6f 74 68 65 72 29   1,+label,+other)
           60  +| page 2 offset 4096
           61  +|      0: 0d 0c cd 00 74 08 75 01 0f e8 0c b3 0f d0 0f b7   ....t.u.........
           62  +|     16: 0f 9e 0f 91 0f 81 0f 70 0f 5e 0f 4f 0f 39 0f 29   .......p.^.O.9.)
           63  +|     32: 0f 18 0f 06 0e f7 0c 65 0e 58 0d c2 0d 2c 0c 25   .......e.X...,.%
           64  +|     48: 0b 85 0a e5 0a 45 09 a5 09 05 0c 83 0c 93 0c a3   .....E..........
           65  +|     64: 0f f0 0c 15 0b 75 0a d5 0a 35 09 95 08 f5 0e d8   .....u...5......
           66  +|     80: 0e 42 0d ac 0d 16 0c 05 0b 65 0a c5 0a 25 09 85   .B.......e...%..
           67  +|     96: 08 e5 0e c8 0e 32 0d 9c 0d 06 0b f5 0b 55 0a b5   .....2.......U..
           68  +|    112: 0a 15 09 75 08 d5 0e b8 0e 22 0d 8c 0c f6 0b e5   ...u............
           69  +|    128: 0b 45 0a a5 0a 05 09 65 08 c5 0e a8 0e 12 0d 7c   .E.....e.......|
           70  +|    144: 0c e6 0b d5 0b 35 0a 95 09 f5 09 55 08 b5 0e 98   .....5.....U....
           71  +|    160: 0e 02 0d 6c 0c d6 0b c5 0b 25 0a 85 09 e5 09 45   ...l.....%.....E
           72  +|    176: 08 a5 0e 88 0d f2 0d 5c 0c 55 0b b5 0b 15 0a 75   .........U.....u
           73  +|    192: 09 d5 09 35 08 95 0e 78 0d e2 0d 4c 0c 45 0b a5   ...5...x...L.E..
           74  +|    208: 0b 05 0a 65 09 c5 09 25 08 85 0e 68 0d d2 0d 3c   ...e...%...h...<
           75  +|    224: 0c 35 0b 95 0a f5 0a 55 09 b5 09 15 08 75 0c 75   .5.....U.....u.u
           76  +|   2160: 00 00 00 00 00 0d 8e 75 05 00 01 1b 00 04 62 6f   .......u......bo
           77  +|   2176: 78 2d 39 2c 39 0d 8e 11 05 00 01 1b 00 02 62 6f   x-9,9.........bo
           78  +|   2192: 78 2d 39 2c 38 0d 8d 2d 05 00 01 1b 00 02 62 6f   x-9,8..-......bo
           79  +|   2208: 78 2d 39 2c 37 0d 8c 49 05 00 01 1b 00 02 62 6f   x-9,7..I......bo
           80  +|   2224: 78 2d 39 2c 36 0d 8b 65 05 00 01 1b 00 02 62 6f   x-9,6..e......bo
           81  +|   2240: 78 2d 39 2c 35 0d 8b 01 05 00 01 1b 00 02 62 6f   x-9,5.........bo
           82  +|   2256: 78 2d 39 2c 34 0d 8a 1d 05 00 01 1b 00 02 62 6f   x-9,4.........bo
           83  +|   2272: 78 2d 39 2c 33 0d 89 39 05 00 01 1b 00 02 62 6f   x-9,3..9......bo
           84  +|   2288: 78 2d 39 2c 32 0d 88 55 05 00 01 1b 00 02 62 6f   x-9,2..U......bo
           85  +|   2304: 78 2d 39 2c 31 0d 87 71 05 00 01 1b 00 02 62 6f   x-9,1..q......bo
           86  +|   2320: 78 2d 39 2c 30 0d 8e 74 05 00 01 1b 00 04 62 6f   x-9,0..t......bo
           87  +|   2336: 78 2d 38 2c 39 0d 8e 10 05 00 01 1b 00 02 62 6f   x-8,9.........bo
           88  +|   2352: 78 2d 38 2c 38 0d 8d 2c 05 00 01 1b 00 02 62 6f   x-8,8..,......bo
           89  +|   2368: 78 2d 38 2c 37 0d 8c 48 05 00 01 1b 00 02 62 6f   x-8,7..H......bo
           90  +|   2384: 78 2d 38 2c 36 0d 8b 64 05 00 01 1b 00 02 62 6f   x-8,6..d......bo
           91  +|   2400: 78 2d 38 2c 35 0d 8b 00 05 00 01 1b 00 02 62 6f   x-8,5.........bo
           92  +|   2416: 78 2d 38 2c 34 0d 8a 1c 05 00 01 1b 00 02 62 6f   x-8,4.........bo
           93  +|   2432: 78 2d 38 2c 33 0d 89 38 05 00 01 1b 00 02 62 6f   x-8,3..8......bo
           94  +|   2448: 78 2d 38 2c 32 0d 88 54 05 00 01 1b 00 02 62 6f   x-8,2..T......bo
           95  +|   2464: 78 2d 38 2c 31 0d 87 70 05 00 01 1b 00 02 62 6f   x-8,1..p......bo
           96  +|   2480: 78 2d 38 2c 30 0d 8e 73 05 00 01 1b 00 05 62 6f   x-8,0..s......bo
           97  +|   2496: 78 2d 37 2c 39 0d 8e 0f 05 00 01 1b 00 05 62 6f   x-7,9.........bo
           98  +|   2512: 78 2d 37 2c 38 0d 8d 2b 05 00 01 1b 00 05 62 6f   x-7,8..+......bo
           99  +|   2528: 78 2d 37 2c 37 0d 8c 47 05 00 01 1b 00 05 62 6f   x-7,7..G......bo
          100  +|   2544: 78 2d 37 2c 36 0d 8b 63 05 00 01 1b 00 05 62 6f   x-7,6..c......bo
          101  +|   2560: 78 2d 37 2c 35 0d 8a 7f 05 00 01 1b 00 05 62 6f   x-7,5.........bo
          102  +|   2576: 78 2d 37 2c 34 0d 8a 1b 05 00 01 1b 00 05 62 6f   x-7,4.........bo
          103  +|   2592: 78 2d 37 2c 33 0d 89 37 05 00 01 1b 00 05 62 6f   x-7,3..7......bo
          104  +|   2608: 78 2d 37 2c 32 0d 88 53 05 00 01 1b 00 05 62 6f   x-7,2..S......bo
          105  +|   2624: 78 2d 37 2c 31 0d 87 6f 05 00 01 1b 00 05 62 6f   x-7,1..o......bo
          106  +|   2640: 78 2d 37 2c 30 0d 8e 72 05 00 01 1b 00 04 62 6f   x-7,0..r......bo
          107  +|   2656: 78 2d 36 2c 39 0d 8e 0e 05 00 01 1b 00 05 62 6f   x-6,9.........bo
          108  +|   2672: 78 2d 36 2c 38 0d 8d 2a 05 00 01 1b 00 05 62 6f   x-6,8..*......bo
          109  +|   2688: 78 2d 36 2c 37 0d 8c 46 05 00 01 1b 00 05 62 6f   x-6,7..F......bo
          110  +|   2704: 78 2d 36 2c 36 0d 8b 62 05 00 01 1b 00 05 62 6f   x-6,6..b......bo
          111  +|   2720: 78 2d 36 2c 35 0d 8a 7e 05 00 01 1b 00 05 62 6f   x-6,5..~......bo
          112  +|   2736: 78 2d 36 2c 34 0d 8a 1a 05 00 01 1b 00 05 62 6f   x-6,4.........bo
          113  +|   2752: 78 2d 36 2c 33 0d 89 36 05 00 01 1b 00 05 62 6f   x-6,3..6......bo
          114  +|   2768: 78 2d 36 2c 32 0d 88 52 05 00 01 1b 00 05 62 6f   x-6,2..R......bo
          115  +|   2784: 78 2d 36 2c 31 0d 87 6e 05 00 01 1b 00 05 62 6f   x-6,1..n......bo
          116  +|   2800: 78 2d 36 2c 30 0d 8e 71 05 00 01 1b 00 04 62 6f   x-6,0..q......bo
          117  +|   2816: 78 2d 35 2c 39 0d 8e 0d 05 00 01 1b 00 05 62 6f   x-5,9.........bo
          118  +|   2832: 78 2d 35 2c 38 0d 8d 29 05 00 01 1b 00 05 62 6f   x-5,8..)......bo
          119  +|   2848: 78 2d 35 2c 37 0d 8c 45 05 00 01 1b 00 05 62 6f   x-5,7..E......bo
          120  +|   2864: 78 2d 35 2c 36 0d 8b 61 05 00 01 1b 00 05 62 6f   x-5,6..a......bo
          121  +|   2880: 78 2d 35 2c 35 0d 8a 7d 05 00 01 1b 00 05 62 6f   x-5,5.........bo
          122  +|   2896: 78 2d 35 2c 34 0d 8a 19 05 00 01 1b 00 05 62 6f   x-5,4.........bo
          123  +|   2912: 78 2d 35 2c 33 0d 89 35 05 00 01 1b 00 05 62 6f   x-5,3..5......bo
          124  +|   2928: 78 2d 35 2c 32 0d 88 51 05 00 01 1b 00 05 62 6f   x-5,2..Q......bo
          125  +|   2944: 78 2d 35 2c 31 0d 87 6d 05 00 01 1b 00 05 62 6f   x-5,1..m......bo
          126  +|   2960: 78 2d 35 2c 30 0d 8e 70 05 00 01 1b 00 04 62 6f   x-5,0..p......bo
          127  +|   2976: 78 2d 34 2c 39 0d 8e 0c 05 00 01 1b 00 04 62 6f   x-4,9.........bo
          128  +|   2992: 78 2d 34 2c 38 0d 8d 28 05 00 01 1b 00 04 62 6f   x-4,8..(......bo
          129  +|   3008: 78 2d 34 2c 37 0d 8c 44 05 00 01 1b 00 04 62 6f   x-4,7..D......bo
          130  +|   3024: 78 2d 34 2c 36 0d 8b 60 05 00 01 1b 00 02 62 6f   x-4,6..`......bo
          131  +|   3040: 78 2d 34 2c 35 0d 8a 7c 05 00 01 1b 00 02 62 6f   x-4,5..|......bo
          132  +|   3056: 78 2d 34 2c 34 0d 8a 18 05 00 01 1b 00 02 62 6f   x-4,4.........bo
          133  +|   3072: 78 2d 34 2c 33 0d 89 34 05 00 01 1b 00 02 62 6f   x-4,3..4......bo
          134  +|   3088: 78 2d 34 2c 32 0d 88 50 05 00 01 1b 00 02 62 6f   x-4,2..P......bo
          135  +|   3104: 78 2d 34 2c 31 0d 87 6c 05 00 01 1b 00 02 62 6f   x-4,1..l......bo
          136  +|   3120: 78 2d 34 2c 30 0d 8e 6f 05 00 01 1b 00 04 62 6f   x-4,0..o......bo
          137  +|   3136: 78 2d 33 2c 39 0d 8e 0b 05 00 01 1b 00 04 62 6f   x-3,9.........bo
          138  +|   3152: 78 2d 33 2c 38 0d 8d 27 05 00 01 1b 00 04 62 6f   x-3,8..'......bo
          139  +|   3168: 78 2d 33 2c 37 0d 87 68 05 00 01 1b 00 03 62 6f   x-3,7..h......bo
          140  +|   3184: 78 2d 30 2c 30 06 90 d9 80 80 81 84 4c 05 00 01   x-0,0.......L...
          141  +|   3200: 00 00 03 0d 88 4c 05 00 01 1b 00 02 62 6f 78 2d   .....L......box-
          142  +|   3216: 30 2c 31 0d 88 4d 05 00 01 1b 00 02 62 6f 78 2d   0,1..M......box-
          143  +|   3232: 31 2c 31 0d 88 4e 05 00 01 1b 00 02 62 6f 78 2d   1,1..N......box-
          144  +|   3248: 32 2c 31 17 01 05 00 01 2f 00 02 6c 6f 77 65 72   2,1...../..lower
          145  +|   3264: 2d 6c 65 66 74 20 63 6f 72 6e 65 72 0d 0d 26 00   -left corner..&.
          146  +|   3280: 09 00 01 00 00 04 0d 8c 43 05 00 01 1b 00 04 62   ........C......b
          147  +|   3296: 6f 78 2d 33 2c 36 0d 8b 5f 05 00 01 1b 00 02 62   ox-3,6.._......b
          148  +|   3312: 6f 78 2d 33 2c 35 0d 8a 7b 05 00 01 1b 00 02 62   ox-3,5.........b
          149  +|   3328: 6f 78 2d 33 2c 34 0d 8a 17 05 00 01 1b 00 02 62   ox-3,4.........b
          150  +|   3344: 6f 78 2d 33 2c 33 0d 89 33 05 00 01 1b 00 02 62   ox-3,3..3......b
          151  +|   3360: 6f 78 2d 33 2c 32 0d bc 00 06 00 09 0d 87 6b 05   ox-3,2........k.
          152  +|   3376: 00 01 1b 00 03 62 6f 78 2d 33 2c 30 0d 8e 6e 05   .....box-3,0..n.
          153  +|   3392: 00 01 1b 00 04 62 6f 78 2d 32 2c 39 0d 8e 0a 05   .....box-2,9....
          154  +|   3408: 00 01 1b 00 04 62 6f 78 2d 32 2c 38 0d 8d 26 05   .....box-2,8..&.
          155  +|   3424: 00 01 1b 00 04 62 6f 78 2d 32 2c 37 0d 8c 42 05   .....box-2,7..B.
          156  +|   3440: 00 01 1b 00 04 62 6f 78 2d 32 2c 36 0d 8b 5e 05   .....box-2,6..^.
          157  +|   3456: 00 01 1b 00 02 62 6f 78 2d 32 2c 35 0d 8a 7a 05   .....box-2,5..z.
          158  +|   3472: 00 01 1b 00 02 62 6f 78 2d 32 2c 34 0d 8a 16 05   .....box-2,4....
          159  +|   3488: 00 01 1b 00 02 62 6f 78 2d 32 2c 33 0d 89 32 05   .....box-2,3..2.
          160  +|   3504: 00 01 1b 00 02 62 6f 78 2d 32 2c 32 0e 52 00 06   .....box-2,2.R..
          161  +|   3520: 00 09 0d 87 6a 05 00 01 1b 00 03 62 6f 78 2d 32   ....j......box-2
          162  +|   3536: 2c 30 0d 8e 6d 05 00 01 1b 00 04 62 6f 78 2d 31   ,0..m......box-1
          163  +|   3552: 2c 39 0d 8e 09 05 00 01 1b 00 04 62 6f 78 2d 31   ,9.........box-1
          164  +|   3568: 2c 38 0d 8d 25 05 00 01 1b 00 04 62 6f 78 2d 31   ,8..%......box-1
          165  +|   3584: 2c 37 0d 8c 41 05 00 01 1b 00 04 62 6f 78 2d 31   ,7..A......box-1
          166  +|   3600: 2c 36 0d 8b 5d 05 00 01 1b 00 02 62 6f 78 2d 31   ,6..]......box-1
          167  +|   3616: 2c 35 0d 8a 79 05 00 01 1b 00 02 62 6f 78 2d 31   ,5..y......box-1
          168  +|   3632: 2c 34 0d 8a 15 05 00 01 1b 00 02 62 6f 78 2d 31   ,4.........box-1
          169  +|   3648: 2c 33 0d 89 31 05 00 01 1b 00 02 62 6f 78 2d 31   ,3..1......box-1
          170  +|   3664: 2c 32 0e e8 00 06 00 09 0d 87 69 05 00 01 1b 00   ,2........i.....
          171  +|   3680: 03 62 6f 78 2d 31 2c 30 0d 8e 6c 05 00 01 1b 00   .box-1,0..l.....
          172  +|   3696: 04 62 6f 78 2d 30 2c 39 0d 8e 08 05 00 01 1b 00   .box-0,9........
          173  +|   3712: 04 62 6f 78 2d 30 2c 38 0d 8d 24 05 00 01 1b 00   .box-0,8..$.....
          174  +|   3728: 04 62 6f 78 2d 30 2c 37 0d 8c 40 05 00 01 1b 00   .box-0,7..@.....
          175  +|   3744: 04 62 6f 78 2d 30 2c 36 0d 8b 5c 05 00 01 1b 00   .box-0,6........
          176  +|   3760: 02 62 6f 78 2d 30 2c 35 0d 8a 78 05 00 01 1b 00   .box-0,5..x.....
          177  +|   3776: 02 62 6f 78 2d 30 2c 34 0d 8a 14 05 00 01 1b 00   .box-0,4........
          178  +|   3792: 02 62 6f 78 2d 30 2c 33 0d 89 30 05 00 01 1b 00   .box-0,3..0.....
          179  +|   3808: 02 62 6f 78 2d 30 2c 32 00 00 00 0f 00 09 1b 00   .box-0,2........
          180  +|   3824: 62 6f 78 2d 30 2c 30 0d 0e 05 00 09 1d 00 74 6f   box-0,0.......to
          181  +|   3840: 70 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74   p half.....#.bot
          182  +|   3856: 74 6f 6d 20 68 61 6c 66 0f 0c 02 05 09 01 00 72   tom half.......r
          183  +|   3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00   ight half.......
          184  +|   3888: 6c 65 66 74 20 68 61 6c 66 14 0a 05 00 09 2b 00   left half.....+.
          185  +|   3904: 74 68 65 20 77 68 6f 6c 65 20 74 68 69 6e 67 0d   the whole thing.
          186  +|   3920: 09 05 00 09 1d 00 74 6f 70 20 65 64 67 65 10 08   ......top edge..
          187  +|   3936: 05 00 09 23 00 62 6f 74 74 6f 6d 20 65 64 67 65   ...#.bottom edge
          188  +|   3952: 0f 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67   .....!.right edg
          189  +|   3968: 65 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67   e.......left edg
          190  +|   3984: 65 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04   e.......center..
          191  +|   4000: 05 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74   ...1.upper-right
          192  +|   4016: 20 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f    corner.....1.lo
          193  +|   4032: 77 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72   wer-right corner
          194  +|   4048: 16 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66   ...../.upper-lef
          195  +|   4064: 74 20 63 6f 72 6e 65 72 06 00 05 00 01 00 00 03   t corner........
          196  +|   4080: 0d 88 4f 05 00 01 1b 00 02 62 6f 78 2d 33 2c 31   ..O......box-3,1
          197  +| page 3 offset 8192
          198  +|      0: 05 00 00 00 01 0f fb 00 00 00 00 06 0f fb 00 00   ................
          199  +|    384: 00 00 00 00 00 00 00 89 50 03 04 00 93 24 00 00   ........P....$..
          200  +|    400: 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
          201  +|    688: 00 00 00 00 42 c8 00 00 42 4c 00 00 42 00 00 00   ....B...BL..B...
          202  +|    720: 03 eb 40 40 00 00 40 80 00 00 00 00 00 00 3f 80   ..@@..@.......?.
          203  +|    736: 00 00 00 00 00 00 00 00 03 ea 40 00 00 00 40 40   ..........@...@@
          204  +|    752: 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 00   ......?.........
          205  +|    768: 03 e9 3f 80 00 00 40 00 00 00 00 00 00 00 3f 80   ..?...@.......?.
          206  +|    784: 00 00 00 00 00 00 00 00 03 e8 00 00 00 00 3f 80   ..............?.
          207  +|    800: 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 00   ......?.........
          208  +|   1616: 00 00 00 00 00 00 00 00 00 00 89 50 02 04 00 93   ...........P....
          209  +|   1632: 24 00 00 00 33 00 00 00 00 00 00 00 01 00 00 00   $...3...........
          210  +|   1648: 00 41 20 00 00 00 00 00 00 41 0e 00 00 00 00 00   .A ......A......
          211  +|   1664: 00 00 00 04 4f 40 40 00 00 40 80 00 00 3f 80 00   ....O@@..@...?..
          212  +|   1680: 00 40 00 00 00 00 00 00 00 00 00 04 4e 40 00 00   .@..........N@..
          213  +|   1696: 00 40 40 00 00 3f 80 00 00 40 00 00 00 00 00 00   .@@..?...@......
          214  +|   1712: 00 00 00 04 4d 3f 80 00 00 40 00 00 00 3f 80 00   ....M?...@...?..
          215  +|   1728: 00 40 00 00 00 00 00 00 00 00 00 04 4c 00 00 00   .@..........L...
          216  +|   1744: 00 3f 80 00 00 3f 80 00 00 40 00 00 00 00 00 00   .?...?...@......
          217  +|   1760: 00 00 00 04 b3 40 40 00 00 40 80 00 00 40 00 00   .....@@..@...@..
          218  +|   1776: 00 40 40 00 00 00 00 00 00 00 00 04 b2 40 00 00   .@@..........@..
          219  +|   1792: 00 40 40 00 00 40 00 00 00 40 40 00 00 00 00 00   .@@..@...@@.....
          220  +|   1808: 00 00 00 04 b1 3f 80 00 00 40 00 00 00 40 00 00   .....?...@...@..
          221  +|   1824: 00 40 40 00 00 00 00 00 00 00 00 04 b0 00 00 00   .@@.............
          222  +|   1840: 00 3f 80 00 00 40 00 00 00 40 40 00 00 00 00 00   .?...@...@@.....
          223  +|   1856: 00 00 00 05 17 40 40 00 00 40 80 00 00 40 40 00   .....@@..@...@@.
          224  +|   1872: 00 40 80 00 00 00 00 00 00 00 00 05 16 40 00 00   .@...........@..
          225  +|   1888: 00 40 40 00 00 40 40 00 00 40 80 00 00 00 00 00   .@@..@@..@......
          226  +|   1904: 00 00 00 05 15 3f 80 00 00 40 00 00 00 40 40 00   .....?...@...@@.
          227  +|   1920: 00 40 80 00 00 00 00 00 00 00 00 05 14 00 00 00   .@..............
          228  +|   1936: 00 3f 80 00 00 40 40 00 00 40 80 00 00 00 00 00   .?...@@..@......
          229  +|   1952: 00 00 00 05 7b 40 40 00 00 40 80 00 00 40 80 00   .....@@..@...@..
          230  +|   1968: 00 40 a0 00 00 00 00 00 00 00 00 05 7a 40 00 00   .@..........z@..
          231  +|   1984: 00 40 40 00 00 40 80 00 00 40 a0 00 00 00 00 00   .@@..@...@......
          232  +|   2000: 00 00 00 05 79 3f 80 00 00 40 00 00 00 40 80 00   ....y?...@...@..
          233  +|   2016: 00 40 a0 00 00 00 00 00 00 00 00 05 78 00 00 00   .@..........x...
          234  +|   2032: 00 3f 80 00 00 40 80 00 00 40 a0 00 00 00 00 00   .?...@...@......
          235  +|   2048: 00 00 00 05 df 40 40 00 00 40 80 00 00 40 a0 00   .....@@..@...@..
          236  +|   2064: 00 40 c0 00 00 00 00 00 00 00 00 05 de 40 00 00   .@...........@..
          237  +|   2080: 00 40 40 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .@@..@...@......
          238  +|   2096: 00 00 00 05 dd 3f 80 00 00 40 00 00 00 40 a0 00   .....?...@...@..
          239  +|   2112: 00 40 c0 00 00 00 00 00 00 00 00 05 dc 00 00 00   .@..............
          240  +|   2128: 00 3f 80 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .?...@...@......
          241  +|   2144: 00 00 00 06 43 40 40 00 00 40 80 00 00 40 c0 00   ....C@@..@...@..
          242  +|   2160: 00 40 e0 00 00 00 00 00 00 00 00 06 42 40 00 00   .@..........B@..
          243  +|   2176: 00 40 40 00 00 40 c0 00 00 40 e0 00 00 00 00 00   .@@..@...@......
          244  +|   2192: 00 00 00 06 41 3f 80 00 00 40 00 00 00 40 c0 00   ....A?...@...@..
          245  +|   2208: 00 40 e0 00 00 00 00 00 00 00 00 06 40 00 00 00   .@..........@...
          246  +|   2224: 00 3f 80 00 00 40 c0 00 00 40 e0 00 00 00 00 00   .?...@...@......
          247  +|   2240: 00 00 00 06 a7 40 40 00 00 40 80 00 00 40 e0 00   .....@@..@...@..
          248  +|   2256: 00 41 00 00 00 00 00 00 00 00 00 06 a6 40 00 00   .A...........@..
          249  +|   2272: 00 40 40 00 00 40 e0 00 00 41 00 00 00 00 00 00   .@@..@...A......
          250  +|   2288: 00 00 00 06 a5 3f 80 00 00 40 00 00 00 40 e0 00   .....?...@...@..
          251  +|   2304: 00 41 00 00 00 00 00 00 00 00 00 06 a4 00 00 00   .A..............
          252  +|   2320: 00 3f 80 00 00 40 e0 00 00 41 00 00 00 00 00 00   .?...@...A......
          253  +|   2336: 00 00 00 07 0a 40 00 00 00 40 40 00 00 41 00 00   .....@...@@..A..
          254  +|   2352: 00 41 10 00 00 00 00 00 00 00 00 07 09 3f 80 00   .A...........?..
          255  +|   2368: 00 40 00 00 00 41 00 00 00 41 10 00 00 00 00 00   .@...A...A......
          256  +|   2384: 00 00 00 07 08 00 00 00 00 3f 80 00 00 41 00 00   .........?...A..
          257  +|   2400: 00 41 10 00 00 00 00 00 00 00 00 07 6e 40 00 00   .A..........n@..
          258  +|   2416: 00 40 40 00 00 41 10 00 00 41 20 00 00 00 00 00   .@@..A...A .....
          259  +|   2432: 00 00 00 07 6d 3f 80 00 00 40 00 00 00 41 10 00   ....m?...@...A..
          260  +|   2448: 00 41 20 00 00 00 00 00 00 00 00 07 6c 00 00 00   .A .........l...
          261  +|   2464: 00 3f 80 00 00 41 10 00 00 41 20 00 00 00 00 00   .?...A...A .....
          262  +|   2480: 00 00 00 07 0b 40 40 00 00 40 80 00 00 41 00 00   .....@@..@...A..
          263  +|   2496: 00 41 10 00 00 00 00 00 00 00 00 07 6f 40 40 00   .A..........o@@.
          264  +|   2512: 00 40 80 00 00 41 10 00 00 41 20 00 00 00 00 00   .@...A...A .....
          265  +|   2528: 00 00 00 03 ec 40 80 00 00 40 a0 00 00 00 00 00   .....@...@......
          266  +|   2544: 00 3f 80 00 00 00 00 00 00 00 00 04 50 40 80 00   .?..........P@..
          267  +|   2560: 00 40 a0 00 00 3f 80 00 00 40 00 00 00 00 00 00   .@...?...@......
          268  +|   2576: 00 00 00 04 b4 40 80 00 00 40 a0 00 00 40 00 00   .....@...@...@..
          269  +|   2592: 00 40 40 00 00 00 00 00 00 00 00 05 18 40 80 00   .@@..........@..
          270  +|   2608: 00 40 a0 00 00 40 40 00 00 40 80 00 00 00 00 00   .@...@@..@......
          271  +|   2624: 00 00 00 05 7c 40 80 00 00 40 a0 00 00 40 80 00   ....|@...@...@..
          272  +|   2640: 00 40 a0 00 00 00 00 00 00 00 00 05 e0 40 80 00   .@...........@..
          273  +|   2656: 00 40 a0 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .@...@...@......
          274  +|   2672: 00 00 00 06 44 40 80 00 00 40 a0 00 00 40 c0 00   ....D@...@...@..
          275  +|   2688: 00 40 e0 00 00 00 00 00 00 00 00 06 a8 40 80 00   .@...........@..
          276  +|   2704: 00 40 a0 00 00 40 e0 00 00 41 00 00 00 00 00 00   .@...@...A......
          277  +|   2720: 00 00 00 07 0c 40 80 00 00 40 a0 00 00 41 00 00   .....@...@...A..
          278  +|   2736: 00 41 10 00 00 00 00 00 00 00 00 07 70 40 80 00   .A..........p@..
          279  +|   2752: 00 40 a0 00 00 41 10 00 00 41 20 00 00 00 00 00   .@...A...A .....
          280  +|   2768: 00 00 00 03 ed 40 a0 00 00 40 c0 00 00 00 00 00   .....@...@......
          281  +|   2784: 00 3f 80 00 00 00 00 00 00 00 00 04 51 40 a0 00   .?..........Q@..
          282  +|   2800: 00 40 c0 00 00 3f 80 00 00 40 00 00 00 00 00 00   .@...?...@......
          283  +|   2816: 00 00 00 04 b5 40 a0 00 00 40 c0 00 00 40 00 00   .....@...@...@..
          284  +|   2832: 00 40 40 00 00 00 00 00 00 00 00 05 19 40 a0 00   .@@..........@..
          285  +|   2848: 00 40 c0 00 00 40 40 00 00 40 80 00 00 89 50 01   .@...@@..@....P.
          286  +|   2864: 04 00 93 24 00 01 00 02 00 00 00 00 00 00 00 03   ...$............
          287  +|   2880: 00 00 00 00 40 80 00 00 00 00 00 00 3f 80 00 00   ....@.......?...
          288  +|   2896: 00 00 00 00 00 00 00 02 00 00 00 00 41 20 00 00   ............A ..
          289  +|   2912: 00 00 00 00 41 20 00 00 00 00 00 00 00 00 00 00   ....A ..........
          290  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 03   ................
          291  +| page 4 offset 12288
          292  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
          293  +| page 5 offset 16384
          294  +|      0: 0d 00 00 00 03 01 87 00 0b 2d 06 5a 01 87 00 00   .........-.Z....
          295  +|    384: 00 00 00 00 00 00 00 89 50 03 04 00 93 24 00 00   ........P....$..
          296  +|    400: 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
          297  +|    688: 00 00 00 00 42 c8 00 00 42 4c 00 00 42 00 00 00   ....B...BL..B...
          298  +|    720: 03 eb 40 40 00 00 40 80 00 00 00 00 00 00 3f 80   ..@@..@.......?.
          299  +|    736: 00 00 00 00 00 00 00 00 03 ea 40 00 00 00 40 40   ..........@...@@
          300  +|    752: 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 00   ......?.........
          301  +|    768: 03 e9 3f 80 00 00 40 00 00 00 00 00 00 00 3f 80   ..?...@.......?.
          302  +|    784: 00 00 00 00 00 00 00 00 03 e8 00 00 00 00 3f 80   ..............?.
          303  +|    800: 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 00   ......?.........
          304  +|   1616: 00 00 00 00 00 00 00 00 00 00 89 50 02 04 00 93   ...........P....
          305  +|   1632: 24 00 00 00 2d 00 00 00 00 00 00 04 4c 00 00 00   $...-.......L...
          306  +|   1648: 00 3f 80 00 00 3f 80 00 00 40 00 00 00 00 00 00   .?...?...@......
          307  +|   1664: 00 00 00 04 b0 00 00 00 00 3f 80 00 00 40 00 00   .........?...@..
          308  +|   1680: 00 40 40 00 00 00 00 00 00 00 00 05 14 00 00 00   .@@.............
          309  +|   1696: 00 3f 80 00 00 40 40 00 00 40 80 00 00 00 00 00   .?...@@..@......
          310  +|   1712: 00 00 00 05 78 00 00 00 00 3f 80 00 00 40 80 00   ....x....?...@..
          311  +|   1728: 00 40 a0 00 00 00 00 00 00 00 00 05 dc 00 00 00   .@..............
          312  +|   1744: 00 3f 80 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .?...@...@......
          313  +|   1760: 00 00 00 00 01 00 00 00 00 41 20 00 00 00 00 00   .........A .....
          314  +|   1776: 00 41 0e 00 00 00 00 00 00 00 00 04 4d 3f 80 00   .A..........M?..
          315  +|   1792: 00 40 00 00 00 3f 80 00 00 40 00 00 00 00 00 00   .@...?...@......
          316  +|   1808: 00 00 00 04 b1 3f 80 00 00 40 00 00 00 40 00 00   .....?...@...@..
          317  +|   1824: 00 40 40 00 00 00 00 00 00 00 00 05 15 3f 80 00   .@@..........?..
          318  +|   1840: 00 40 00 00 00 40 40 00 00 40 80 00 00 00 00 00   .@...@@..@......
          319  +|   1856: 00 00 00 05 79 3f 80 00 00 40 00 00 00 40 80 00   ....y?...@...@..
          320  +|   1872: 00 40 a0 00 00 00 00 00 00 00 00 05 dd 3f 80 00   .@...........?..
          321  +|   1888: 00 40 00 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .@...@...@......
          322  +|   1904: 00 00 00 04 4e 40 00 00 00 40 40 00 00 3f 80 00   ....N@...@@..?..
          323  +|   1920: 00 40 00 00 00 00 00 00 00 00 00 04 b2 40 00 00   .@...........@..
          324  +|   1936: 00 40 40 00 00 40 00 00 00 40 40 00 00 00 00 00   .@@..@...@@.....
          325  +|   1952: 00 00 00 05 16 40 00 00 00 40 40 00 00 40 40 00   .....@...@@..@@.
          326  +|   1968: 00 40 80 00 00 00 00 00 00 00 00 05 7a 40 00 00   .@..........z@..
          327  +|   1984: 00 40 40 00 00 40 80 00 00 40 a0 00 00 00 00 00   .@@..@...@......
          328  +|   2000: 00 00 00 05 de 40 00 00 00 40 40 00 00 40 a0 00   .....@...@@..@..
          329  +|   2016: 00 40 c0 00 00 00 00 00 00 00 00 04 4f 40 40 00   .@..........O@@.
          330  +|   2032: 00 40 80 00 00 3f 80 00 00 40 00 00 00 00 00 00   .@...?...@......
          331  +|   2048: 00 00 00 04 b3 40 40 00 00 40 80 00 00 40 00 00   .....@@..@...@..
          332  +|   2064: 00 40 40 00 00 00 00 00 00 00 00 05 17 40 40 00   .@@..........@@.
          333  +|   2080: 00 40 80 00 00 40 40 00 00 40 80 00 00 00 00 00   .@...@@..@......
          334  +|   2096: 00 00 00 05 7b 40 40 00 00 40 80 00 00 40 80 00   .....@@..@...@..
          335  +|   2112: 00 40 a0 00 00 00 00 00 00 00 00 05 df 40 40 00   .@...........@@.
          336  +|   2128: 00 40 80 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .@...@...@......
          337  +|   2144: 00 00 00 03 ec 40 80 00 00 40 a0 00 00 00 00 00   .....@...@......
          338  +|   2160: 00 3f 80 00 00 00 00 00 00 00 00 04 50 40 80 00   .?..........P@..
          339  +|   2176: 00 40 a0 00 00 3f 80 00 00 40 00 00 00 00 00 00   .@...?...@......
          340  +|   2192: 00 00 00 04 b4 40 80 00 00 40 a0 00 00 40 00 00   .....@...@...@..
          341  +|   2208: 00 40 40 00 00 00 00 00 00 00 00 05 18 40 80 00   .@@..........@..
          342  +|   2224: 00 40 a0 00 00 40 40 00 00 40 80 00 00 00 00 00   .@...@@..@......
          343  +|   2240: 00 00 00 05 7c 40 80 00 00 40 a0 00 00 40 80 00   ....|@...@...@..
          344  +|   2256: 00 40 a0 00 00 00 00 00 00 00 00 05 e0 40 80 00   .@...........@..
          345  +|   2272: 00 40 a0 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .@...@...@......
          346  +|   2288: 00 00 00 03 f0 41 00 00 00 41 10 00 00 00 00 00   .....A...A......
          347  +|   2304: 00 3f 80 00 00 00 00 00 00 00 00 04 54 41 00 00   .?..........TA..
          348  +|   2320: 00 41 10 00 00 3f 80 00 00 40 00 00 00 00 00 00   .A...?...@......
          349  +|   2336: 00 00 00 04 b8 41 00 00 00 41 10 00 00 40 00 00   .....A...A...@..
          350  +|   2352: 00 40 40 00 00 00 00 00 00 00 00 05 1c 41 00 00   .@@..........A..
          351  +|   2368: 00 41 10 00 00 40 40 00 00 40 80 00 00 00 00 00   .A...@@..@......
          352  +|   2384: 00 00 00 05 80 41 00 00 00 41 10 00 00 40 80 00   .....A...A...@..
          353  +|   2400: 00 40 a0 00 00 00 00 00 00 00 00 05 e4 41 00 00   .@...........A..
          354  +|   2416: 00 41 10 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .A...@...@......
          355  +|   2432: 00 00 00 06 48 41 00 00 00 41 10 00 00 40 c0 00   ....HA...A...@..
          356  +|   2448: 00 40 e0 00 00 00 00 00 00 00 00 06 ac 41 00 00   .@...........A..
          357  +|   2464: 00 41 10 00 00 40 e0 00 00 41 00 00 00 00 00 00   .A...@...A......
          358  +|   2480: 00 00 00 07 10 41 00 00 00 41 10 00 00 41 00 00   .....A...A...A..
          359  +|   2496: 00 41 10 00 00 00 00 00 00 00 00 03 f1 41 10 00   .A...........A..
          360  +|   2512: 00 41 20 00 00 00 00 00 00 3f 80 00 00 00 00 00   .A ......?......
          361  +|   2528: 00 00 00 04 55 41 10 00 00 41 20 00 00 3f 80 00   ....UA...A ..?..
          362  +|   2544: 00 40 00 00 00 00 00 00 00 00 00 04 b9 41 10 00   .@...........A..
          363  +|   2560: 00 41 20 00 00 40 00 00 00 40 40 00 00 00 00 00   .A ..@...@@.....
          364  +|   2576: 00 00 00 05 1d 41 10 00 00 41 20 00 00 40 40 00   .....A...A ..@@.
          365  +|   2592: 00 40 80 00 00 00 00 00 00 00 00 05 81 41 10 00   .@...........A..
          366  +|   2608: 00 41 20 00 00 40 80 00 00 40 a0 00 00 00 00 00   .A ..@...@......
          367  +|   2624: 00 00 00 05 e5 41 10 00 00 41 20 00 00 40 a0 00   .....A...A ..@..
          368  +|   2640: 00 40 c0 00 00 00 00 00 00 00 00 06 49 41 10 00   .@..........IA..
          369  +|   2656: 00 41 20 00 00 40 c0 00 00 40 e0 00 00 00 00 00   .A ..@...@......
          370  +|   2672: 00 00 00 06 ad 41 10 00 00 41 20 00 00 40 e0 00   .....A...A ..@..
          371  +|   2688: 00 41 00 00 00 00 00 00 00 00 00 07 11 41 10 00   .A...........A..
          372  +|   2704: 00 41 20 00 00 41 00 00 00 41 10 00 00 00 00 00   .A ..A...A......
          373  +|   2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01   ..............P.
          374  +|   2864: 04 00 93 24 00 01 00 04 00 00 00 00 00 00 00 03   ...$............
          375  +|   2880: 00 00 00 00 40 80 00 00 00 00 00 00 3f 80 00 00   ....@.......?...
          376  +|   2896: 00 00 00 00 00 00 00 02 00 00 00 00 41 20 00 00   ............A ..
          377  +|   2912: 00 00 00 00 41 10 00 00 00 00 00 00 00 00 00 04   ....A...........
          378  +|   2928: 00 00 00 00 41 20 00 00 40 c0 00 00 41 20 00 00   ....A ..@...A ..
          379  +|   2944: 00 00 00 00 00 00 00 05 40 a0 00 00 41 00 00 00   ........@...A...
          380  +|   2960: 00 00 00 00 41 20 00 00 00 00 00 00 00 00 00 00   ....A ..........
          381  +| page 6 offset 20480
          382  +|      0: 0d 00 00 00 02 06 5a 00 0b 2d 06 5a 00 00 00 00   ......Z..-.Z....
          383  +|   1616: 00 00 00 00 00 00 00 00 00 00 89 50 05 04 00 93   ...........P....
          384  +|   1632: 24 00 00 00 1c 00 00 00 00 00 00 03 ed 40 a0 00   $............@..
          385  +|   1648: 00 40 c0 00 00 00 00 00 00 3f 80 00 00 00 00 00   .@.......?......
          386  +|   1664: 00 00 00 04 51 40 a0 00 00 40 c0 00 00 3f 80 00   ....Q@...@...?..
          387  +|   1680: 00 40 00 00 00 00 00 00 00 00 00 04 b5 40 a0 00   .@...........@..
          388  +|   1696: 00 40 c0 00 00 40 00 00 00 40 40 00 00 00 00 00   .@...@...@@.....
          389  +|   1712: 00 00 00 05 19 40 a0 00 00 40 c0 00 00 40 40 00   .....@...@...@@.
          390  +|   1728: 00 40 80 00 00 00 00 00 00 00 00 05 7d 40 a0 00   .@...........@..
          391  +|   1744: 00 40 c0 00 00 40 80 00 00 40 a0 00 00 00 00 00   .@...@...@......
          392  +|   1760: 00 00 00 05 e1 40 a0 00 00 40 c0 00 00 40 a0 00   .....@...@...@..
          393  +|   1776: 00 40 c0 00 00 00 00 00 00 00 00 06 45 40 a0 00   .@..........E@..
          394  +|   1792: 00 40 c0 00 00 40 c0 00 00 40 e0 00 00 00 00 00   .@...@...@......
          395  +|   1808: 00 00 00 06 a9 40 a0 00 00 40 c0 00 00 40 e0 00   .....@...@...@..
          396  +|   1824: 00 41 00 00 00 00 00 00 00 00 00 07 0d 40 a0 00   .A...........@..
          397  +|   1840: 00 40 c0 00 00 41 00 00 00 41 10 00 00 00 00 00   .@...A...A......
          398  +|   1856: 00 00 00 03 ee 40 c0 00 00 40 e0 00 00 00 00 00   .....@...@......
          399  +|   1872: 00 3f 80 00 00 00 00 00 00 00 00 04 52 40 c0 00   .?..........R@..
          400  +|   1888: 00 40 e0 00 00 3f 80 00 00 40 00 00 00 00 00 00   .@...?...@......
          401  +|   1904: 00 00 00 04 b6 40 c0 00 00 40 e0 00 00 40 00 00   .....@...@...@..
          402  +|   1920: 00 40 40 00 00 00 00 00 00 00 00 05 1a 40 c0 00   .@@..........@..
          403  +|   1936: 00 40 e0 00 00 40 40 00 00 40 80 00 00 00 00 00   .@...@@..@......
          404  +|   1952: 00 00 00 05 7e 40 c0 00 00 40 e0 00 00 40 80 00   ....~@...@...@..
          405  +|   1968: 00 40 a0 00 00 00 00 00 00 00 00 05 e2 40 c0 00   .@...........@..
          406  +|   1984: 00 40 e0 00 00 40 a0 00 00 40 c0 00 00 00 00 00   .@...@...@......
          407  +|   2000: 00 00 00 06 46 40 c0 00 00 40 e0 00 00 40 c0 00   ....F@...@...@..
          408  +|   2016: 00 40 e0 00 00 00 00 00 00 00 00 06 aa 40 c0 00   .@...........@..
          409  +|   2032: 00 40 e0 00 00 40 e0 00 00 41 00 00 00 00 00 00   .@...@...A......
          410  +|   2048: 00 00 00 07 0e 40 c0 00 00 40 e0 00 00 41 00 00   .....@...@...A..
          411  +|   2064: 00 41 10 00 00 00 00 00 00 00 00 03 ef 40 e0 00   .A...........@..
          412  +|   2080: 00 41 00 00 00 00 00 00 00 3f 80 00 00 00 00 00   .A.......?......
          413  +|   2096: 00 00 00 04 53 40 e0 00 00 41 00 00 00 3f 80 00   ....S@...A...?..
          414  +|   2112: 00 40 00 00 00 00 00 00 00 00 00 04 b7 40 e0 00   .@...........@..
          415  +|   2128: 00 41 00 00 00 40 00 00 00 40 40 00 00 00 00 00   .A...@...@@.....
          416  +|   2144: 00 00 00 05 1b 40 e0 00 00 41 00 00 00 40 40 00   .....@...A...@@.
          417  +|   2160: 00 40 80 00 00 00 00 00 00 00 00 05 7f 40 e0 00   .@...........@..
          418  +|   2176: 00 41 00 00 00 40 80 00 00 40 a0 00 00 00 00 00   .A...@...@......
          419  +|   2192: 00 00 00 05 e3 40 e0 00 00 41 00 00 00 40 a0 00   .....@...A...@..
          420  +|   2208: 00 40 c0 00 00 00 00 00 00 00 00 06 47 40 e0 00   .@..........G@..
          421  +|   2224: 00 41 00 00 00 40 c0 00 00 40 e0 00 00 00 00 00   .A...@...@......
          422  +|   2240: 00 00 00 06 ab 40 e0 00 00 41 00 00 00 40 e0 00   .....@...A...@..
          423  +|   2256: 00 41 00 00 00 00 00 00 00 00 00 07 0f 40 e0 00   .A...........@..
          424  +|   2272: 00 41 00 00 00 41 00 00 00 41 10 00 00 00 00 00   .A...A...A......
          425  +|   2288: 00 00 00 07 73 40 e0 00 00 41 00 00 00 41 10 00   ....s@...A...A..
          426  +|   2304: 00 41 20 00 00 00 00 00 00 00 00 00 00 00 00 00   .A .............
          427  +|   2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 04   ..............P.
          428  +|   2864: 04 00 93 24 00 00 00 18 00 00 00 00 00 00 06 43   ...$...........C
          429  +|   2880: 40 40 00 00 40 80 00 00 40 c0 00 00 40 e0 00 00   @@..@...@...@...
          430  +|   2896: 00 00 00 00 00 00 06 42 40 00 00 00 40 40 00 00   .......B@...@@..
          431  +|   2912: 40 c0 00 00 40 e0 00 00 00 00 00 00 00 00 06 41   @...@..........A
          432  +|   2928: 3f 80 00 00 40 00 00 00 40 c0 00 00 40 e0 00 00   ?...@...@...@...
          433  +|   2944: 00 00 00 00 00 00 06 40 00 00 00 00 3f 80 00 00   .......@....?...
          434  +|   2960: 40 c0 00 00 40 e0 00 00 00 00 00 00 00 00 06 44   @...@..........D
          435  +|   2976: 40 80 00 00 40 a0 00 00 40 c0 00 00 40 e0 00 00   @...@...@...@...
          436  +|   2992: 00 00 00 00 00 00 06 a7 40 40 00 00 40 80 00 00   ........@@..@...
          437  +|   3008: 40 e0 00 00 41 00 00 00 00 00 00 00 00 00 06 a6   @...A...........
          438  +|   3024: 40 00 00 00 40 40 00 00 40 e0 00 00 41 00 00 00   @...@@..@...A...
          439  +|   3040: 00 00 00 00 00 00 06 a5 3f 80 00 00 40 00 00 00   ........?...@...
          440  +|   3056: 40 e0 00 00 41 00 00 00 00 00 00 00 00 00 06 a4   @...A...........
          441  +|   3072: 00 00 00 00 3f 80 00 00 40 e0 00 00 41 00 00 00   ....?...@...A...
          442  +|   3088: 00 00 00 00 00 00 06 a8 40 80 00 00 40 a0 00 00   ........@...@...
          443  +|   3104: 40 e0 00 00 41 00 00 00 00 00 00 00 00 00 07 0a   @...A...........
          444  +|   3120: 40 00 00 00 40 40 00 00 41 00 00 00 41 10 00 00   @...@@..A...A...
          445  +|   3136: 00 00 00 00 00 00 07 09 3f 80 00 00 40 00 00 00   ........?...@...
          446  +|   3152: 41 00 00 00 41 10 00 00 00 00 00 00 00 00 07 08   A...A...........
          447  +|   3168: 00 00 00 00 3f 80 00 00 41 00 00 00 41 10 00 00   ....?...A...A...
          448  +|   3184: 00 00 00 00 00 00 07 0b 40 40 00 00 40 80 00 00   ........@@..@...
          449  +|   3200: 41 00 00 00 41 10 00 00 00 00 00 00 00 00 07 0c   A...A...........
          450  +|   3216: 40 80 00 00 40 a0 00 00 41 00 00 00 41 10 00 00   @...@...A...A...
          451  +|   3232: 00 00 00 00 00 00 07 6e 40 00 00 00 40 40 00 00   .......n@...@@..
          452  +|   3248: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 07 6d   A...A .........m
          453  +|   3264: 3f 80 00 00 40 00 00 00 41 10 00 00 41 20 00 00   ?...@...A...A ..
          454  +|   3280: 00 00 00 00 00 00 07 6c 00 00 00 00 3f 80 00 00   .......l....?...
          455  +|   3296: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 07 6f   A...A .........o
          456  +|   3312: 40 40 00 00 40 80 00 00 41 10 00 00 41 20 00 00   @@..@...A...A ..
          457  +|   3328: 00 00 00 00 00 00 07 70 40 80 00 00 40 a0 00 00   .......p@...@...
          458  +|   3344: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 07 71   A...A .........q
          459  +|   3360: 40 a0 00 00 40 c0 00 00 41 10 00 00 41 20 00 00   @...@...A...A ..
          460  +|   3376: 00 00 00 00 00 00 07 72 40 c0 00 00 40 e0 00 00   .......r@...@...
          461  +|   3392: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 07 74   A...A .........t
          462  +|   3408: 41 00 00 00 41 10 00 00 41 10 00 00 41 20 00 00   A...A...A...A ..
          463  +|   3424: 00 00 00 00 00 00 07 75 41 10 00 00 41 20 00 00   .......uA...A ..
          464  +|   3440: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 00 00   A...A ..........
          465  +| end c1b.db
          466  +  }]
          467  +  catchsql {
          468  +     SELECT rtreecheck('t1');
          469  +  }
          470  +} {1 {SQL logic error}}
          471  +
          472  +do_test rtreefuzz001-200 {
          473  +  sqlite3 db {}
          474  +  db deserialize [decode_hexdb {
          475  +| size 16384 pagesize 4096 filename c3.db
          476  +| page 1 offset 0
          477  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          478  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04   .....@  ........
          479  +|     32: 00 00 00 00 01 00 00 00 00 00 00 04 00 00 00 04   ................
          480  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          481  +|     96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f   ...............O
          482  +|    112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00   ................
          483  +|   3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17   ............^...
          484  +|   3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72   .....tablet1_par
          485  +|   3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45   entt1_parent.CRE
          486  +|   3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61   ATE TABLE .t1_pa
          487  +|   3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54   rent.(nodeno INT
          488  +|   3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
          489  +|   3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17   ,parentnode)Q...
          490  +|   3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65   ....tablet1_node
          491  +|   3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54   t1_node.CREATE T
          492  +|   3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e   ABLE .t1_node.(n
          493  +|   3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52   odeno INTEGER PR
          494  +|   3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c   IMARY KEY,data).
          495  +|   3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f   ........tablet1_
          496  +|   3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52   rowidt1_rowid.CR
          497  +|   3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72   EATE TABLE .t1_r
          498  +|   3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45   owid.(rowid INTE
          499  +|   3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c   GER PRIMARY KEY,
          500  +|   4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07   nodeno,a0,a1)Q..
          501  +|   4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43   ......tablet1t1C
          502  +|   4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41   REATE VIRTUAL TA
          503  +|   4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72   BLE t1 USING rtr
          504  +|   4064: 65 65 28 69 64 2c 78 30 2c 78 31 2c 79 30 2c 79   ee(id,x0,x1,y0,y
          505  +|   4080: 31 2c 2b 6c 61 62 65 6c 2c 2b 6f 74 68 65 72 29   1,+label,+other)
          506  +| page 2 offset 4096
          507  +|      0: 0d 00 00 00 0e 0e f7 00 0f e8 0f d0 0f b7 0f 9e   ................
          508  +|     16: 0f 91 0f 81 0f 70 0f 5e 0f 4f 0f 39 0f 29 0f 18   .....p.^.O.9.)..
          509  +|     32: 0f 06 0e f7 00 00 00 00 00 00 00 00 00 00 00 00   ................
          510  +|   3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f   ..............to
          511  +|   3840: 70 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74   p half.....#.bot
          512  +|   3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72   tom half.....!.r
          513  +|   3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00   ight half.......
          514  +|   3888: 6c 65 66 74 20 68 61 6c 66 14 0a 05 00 09 2b 00   left half.....+.
          515  +|   3904: 74 68 65 20 77 68 6f 6c 65 20 74 68 69 6e 67 0d   the whole thing.
          516  +|   3920: 09 05 00 09 1d 00 74 6f 70 20 65 64 67 65 10 08   ......top edge..
          517  +|   3936: 05 00 09 23 00 62 6f 74 74 6f 6d 20 65 64 67 65   ...#.bottom edge
          518  +|   3952: 0f 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67   .....!.right edg
          519  +|   3968: 65 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67   e.......left edg
          520  +|   3984: 65 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04   e.......center..
          521  +|   4000: 05 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74   ...1.upper-right
          522  +|   4016: 20 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f    corner.....1.lo
          523  +|   4032: 77 65 72 2d 72 69 67 68 74 27 60 f6 32 6e 65 72   wer-right'`.2ner
          524  +|   4048: 16 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66   ...../.upper-lef
          525  +|   4064: 74 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 00 6c   t corner...../.l
          526  +|   4080: 6f 77 65 72 2d 6c 65 66 74 20 63 6f 72 6e 65 72   ower-left corner
          527  +| page 3 offset 8192
          528  +|      0: 0d 00 00 00 02 0b 2d 00 0b 2d 00 00 00 00 00 00   ......-..-......
          529  +|   2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01   ..............P.
          530  +|   2864: 04 00 93 24 00 00 00 0e 00 00 00 00 00 00 00 01   ...$............
          531  +|   2880: 00 00 00 00 41 20 00 00 00 00 00 00 41 20 01 00   ....A ......A ..
          532  +|   2896: 00 00 00 00 00 00 00 02 00 00 00 00 41 00 00 04   ............A...
          533  +|   2912: 2b 40 00 0c 42 c8 00 00 00 00 00 00 00 00 00 03   +@..B...........
          534  +|   2928: 42 b4 00 00 42 c8 00 00 00 00 00 00 41 20 00 00   B...B.......A ..
          535  +|   2944: 00 00 00 00 00 00 00 04 42 b4 00 00 42 c8 00 00   ........B...B...
          536  +|   2960: 42 b4 00 00 42 c8 00 00 00 00 00 00 00 00 00 05   B...B...........
          537  +|   2976: 42 20 00 00 42 70 00 00 42 20 00 00 42 70 00 00   B ..Bp..B ..Bp..
          538  +|   2992: 00 00 00 00 00 00 00 60 00 00 00 04 0a 00 00 00   .......`........
          539  +|   3008: 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 07 42   ...B...........B
          540  +|   3024: be 00 00 42 c8 00 00 00 00 00 00 42 c8 00 00 00   ...B.......B....
          541  +|   3040: 00 00 00 00 00 00 08 00 00 00 00 42 c8 00 00 00   ...........B....
          542  +|   3056: 00 00 00 40 a0 00 00 00 00 00 00 00 00 00 09 00   ...@............
          543  +|   3072: 00 00 00 42 c8 00 00 42 be 00 00 42 c8 00 00 00   ...B...B...B....
          544  +|   3088: 00 00 00 00 00 00 0a 00 00 00 00 42 c8 00 00 00   ...........B....
          545  +|   3104: 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 0b 00   ...B............
          546  +|   3120: 00 00 00 42 48 00 00 00 00 00 04 2c 80 00 00 00   ...BH......,....
          547  +|   3136: 00 00 00 00 00 00 c4 24 c0 00 04 2c 80 00 00 00   .......$...,....
          548  +|   3152: 00 00 04 2c 80 00 00 00 00 00 00 00 00 00 d0 00   ...,............
          549  +|   3168: 00 00 04 2c 80 00 00 00 00 00 04 24 80 00 00 00   ...,.......$....
          550  +|   3184: 00 00 00 00 00 00 e0 00 00 00 04 2c 80 00 04 24   ...........,...$
          551  +|   3200: c0 00 04 2c 00 00 00 00 00 00 00 00 00 00 00 00   ...,............
          552  +| page 4 offset 12288
          553  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
          554  +| end c3.db
          555  +  }]
          556  +  catchsql {
          557  +    WITH RECURSIVE
          558  +      c1(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c1 WHERE x<99),
          559  +      c2(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM c2 WHERE y<99)
          560  +    INSERT INTO t1(id, x0,x1,y0,y1,label)
          561  +      SELECT 1000+x+y*100, x, x+1, y, y+1, printf('box-%d,%d',x,y) FROM c1, c2;
          562  +  }
          563  +} {1 {database disk image is malformed}}
          564  +do_test rtreefuzz001-210 {
          565  +  catchsql {
          566  +    SELECT rtreecheck('t1');
          567  +  }
          568  +} {/1 .*corrupt.*/}
          569  +
          570  +do_test rtreefuzz001-300 {
          571  +  sqlite3 db {}
          572  +  db deserialize [decode_hexdb {
          573  +| size 16384 pagesize 4096 filename c4.db
          574  +| page 1 offset 0
          575  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          576  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04   .....@  ........
          577  +|     32: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04   ................
          578  +|     96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f   ...............O
          579  +|    112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00   ................
          580  +|   3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17   ............^...
          581  +|   3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72   .....tablet1_par
          582  +|   3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45   entt1_parent.CRE
          583  +|   3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61   ATE TABLE .t1_pa
          584  +|   3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54   rent.(nodeno INT
          585  +|   3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
          586  +|   3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17   ,parentnode)Q...
          587  +|   3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65   ....tablet1_node
          588  +|   3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54   t1_node.CREATE T
          589  +|   3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e   ABLE .t1_node.(n
          590  +|   3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52   odeno INTEGER PR
          591  +|   3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c   IMARY KEY,data).
          592  +|   3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f   ........tablet1_
          593  +|   3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52   rowidt1_rowid.CR
          594  +|   3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72   EATE TABLE .t1_r
          595  +|   3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45   owid.(rowid INTE
          596  +|   3984: 47 45 72 20 50 52 49 4d 41 52 59 20 4b 45 59 2c   GEr PRIMARY KEY,
          597  +|   4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07   nodeno,a0,a1)Q..
          598  +|   4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43   ......tablet1t1C
          599  +|   4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41   REATE VIRTUAL TA
          600  +|   4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72   BLE t1 USING rtr
          601  +|   4064: 65 65 28 69 64 2c 78 30 2c 78 31 2c 79 30 2c 79   ee(id,x0,x1,y0,y
          602  +|   4080: 31 2c 2b 6c 61 62 65 6c 2c 2b 6f 74 68 65 72 29   1,+label,+other)
          603  +| page 2 offset 4096
          604  +|      0: 0d 00 00 00 0e 0e f7 00 0f e8 0f 00 fb 70 f9 e0   .............p..
          605  +|     16: f9 10 f8 10 f7 00 f5 e0 f4 f0 f3 90 f2 90 f1 80   ................
          606  +|     32: f0 60 ef 00 00 00 00 00 00 00 00 00 00 00 00 00   .`..............
          607  +|   3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f   ..............to
          608  +|   3840: 70 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74   p half.....#.bot
          609  +|   3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72   tom half.....!.r
          610  +|   3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00   ight half.......
          611  +|   3888: 6c 65 66 74 20 68 61 6c 66 14 0a 05 00 09 2b 00   left half.....+.
          612  +|   3904: 00 03 98 20 49 98 2f 6c 62 05 74 68 69 6e 67 0d   ... I./lb.thing.
          613  +|   3920: 09 05 00 09 1d 00 74 6f 70 20 65 64 67 65 10 08   ......top edge..
          614  +|   3936: 05 00 09 23 00 62 6f 74 74 6f 6d 20 65 64 67 65   ...#.bottom edge
          615  +|   3952: 0f 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67   .....!.right edg
          616  +|   3968: 65 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67   e.......left edg
          617  +|   3984: 65 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04   e.......center..
          618  +|   4000: 05 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74   ...1.upper-right
          619  +|   4016: 20 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f    corner.....1.lo
          620  +|   4032: 77 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72   wer-right corner
          621  +|   4048: 16 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66   ...../.upper-lef
          622  +|   4064: 74 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 00 6c   t corner...../.l
          623  +|   4080: 6f 77 65 72 2d 6c 65 66 74 20 63 6f 72 6e 65 72   ower-left corner
          624  +| page 3 offset 8192
          625  +|      0: 0d 00 00 00 01 0b 2d 00 0b 2d 00 00 00 00 00 00   ......-..-......
          626  +|   2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01   ..............P.
          627  +|   2864: 04 00 93 24 00 00 00 0e 00 00 00 00 00 00 00 01   ...$............
          628  +|   2880: 00 00 00 04 01 20 00 00 00 00 00 04 12 00 00 00   ..... ..........
          629  +|   2896: 00 00 00 00 00 00 00 23 00 00 00 00 41 20 00 00   .......#....A ..
          630  +|   2912: 42 b4 00 00 42 c8 00 00 00 00 00 00 00 00 00 03   B...B...........
          631  +|   2928: 42 b4 00 00 42 c8 00 00 00 00 00 00 41 20 00 00   B...B.......A ..
          632  +|   2944: 00 00 00 00 00 00 00 04 42 b4 00 00 42 c8 00 00   ........B...B...
          633  +|   2960: 42 b4 00 00 42 c8 00 00 00 00 00 00 00 00 00 05   B...B...........
          634  +|   2976: 42 20 00 00 42 70 00 00 42 20 00 00 42 70 00 00   B ..Bp..B ..Bp..
          635  +|   2992: 00 00 00 00 00 00 00 06 00 00 00 00 40 a0 00 00   ............@...
          636  +|   3008: 00 00 00 04 2c 80 00 00 00 00 00 00 00 00 00 74   ....,..........t
          637  +|   3024: 2b e0 00 04 2c 80 00 04 2c 80 00 00 00 00 00 00   +...,...,.......
          638  +|   3040: 00 00 00 80 00 00 00 04 2c 80 00 00 00 00 00 04   ........,.......
          639  +|   3056: 0a 00 00 00 00 00 b0 80 00 00 04 2c 80 00 04 2b   ...........,...+
          640  +|   3072: e0 00 04 2c 80 00 00 00 00 00 00 00 00 00 a0 00   ...,............
          641  +|   3088: 00 00 04 2c 80 00 00 00 00 00 04 2c 80 00 00 00   ...,.......,....
          642  +|   3104: 00 00 00 00 00 00 b0 00 00 00 04 24 80 00 00 00   ...........$....
          643  +|   3120: 00 00 04 2c 80 00 00 00 00 00 00 00 50 00 91 f0   ...,........P...
          644  +|   3136: 06 c6 56 67 42 06 86 16 c6 61 40 a0 50 00 92 b0   ..VgB....a@.P...
          645  +|   3152: 07 46 86 52 07 76 86 f6 c6 52 07 46 86 96 e6 70   .F.R.v...R.F...p
          646  +|   3168: d0 90 50 00 91 d0 07 46 f7 02 06 56 46 76 51 00   ..P....F...VFvQ.
          647  +|   3184: 80 50 00 92 30 06 26 f7 47 46 f6 d2 06 56 46 76   .P..0.&.GF...VFv
          648  +|   3200: 50 f0 70 50 00 92 10 07 26 96 76 87 42 06 56 46   P.pP....&.v.B.VF
          649  +|   3216: 76 50 e0 60 50 00 91 f0 06 c6 56 67 42 06 56 46   vP.`P.....VgB.VF
          650  +|   3232: 76 50 b0 50 50 00 91 90 06 36 56 e7 46 57 21 70   vP.PP....6V.FW!p
          651  +|   3248: 40 50 00 93 10 07 57 07 06 57 22 d7 26 96 76 87   @P....W..W..&.v.
          652  +|   3264: 42 06 36 f7 26 e6 57 21 70 30 50 00 93 10 06 c6   B.6.&.W!p0P.....
          653  +|   3280: f7 76 57 22 d7 26 96 76 87 42 06 36 f7 26 e6 57   .vW..&.v.B.6.&.W
          654  +|   3296: 21 60 20 50 00 92 f0 07 57 07 06 57 22 d6 c6 56   !` P....W..W...V
          655  +|   3312: 60 00 00 c4 24 c0 00 04 2c 80 00 00 00 00 00 04   `...$...,.......
          656  +|   3328: 2c 80 00 00 00 00 00 00 00 00 00 d0 00 00 00 04   ,...............
          657  +|   3344: 2c 80 00 00 00 00 00 04 24 80 00 00 00 00 00 00   ,.......$.......
          658  +|   3360: 00 00 00 e0 00 00 00 04 2c 80 00 04 24 c0 00 04   ........,...$...
          659  +|   3376: 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ,...............
          660  +| page 4 offset 12288
          661  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
          662  +| end c4.db
          663  +  }]
          664  +  catchsql {
          665  +    UPDATE t1 SET label='x';
          666  +  }
          667  +} {1 {rtree constraint failed: t1.(y0<=y1)}}
          668  +do_test rtreefuzz001-310 {
          669  +  catchsql {
          670  +    SELECT rtreecheck('t1');
          671  +  }
          672  +} {/1 .*corrupt.*/}
          673  +
          674  +do_test rtreefuzz001-400 {
          675  +  sqlite3 db {}
          676  +  db deserialize [decode_hexdb {
          677  +| size 16384 pagesize 4096 filename c7.db
          678  +| page 1 offset 0
          679  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          680  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04   .....@  ........
          681  +|     32: 00 00 00 00 01 00 00 00 00 00 00 04 00 00 00 04   ................
          682  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          683  +|     96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f   ...............O
          684  +|    112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00   ................
          685  +|   3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17   ............^...
          686  +|   3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72   .....tablet1_par
          687  +|   3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45   entt1_parent.CRE
          688  +|   3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61   ATE TABLE .t1_pa
          689  +|   3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54   rent.(nodeno INT
          690  +|   3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
          691  +|   3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17   ,parentnode)Q...
          692  +|   3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65   ....tablet1_node
          693  +|   3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54   t1_node.CREATE T
          694  +|   3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e   ABLE .t1_node.(n
          695  +|   3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52   odeno INTEGER PR
          696  +|   3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c   IMARY KEY,data).
          697  +|   3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f   ........tablet1_
          698  +|   3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52   rowidt1_rowid.CR
          699  +|   3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72   EATE TABLE .t1_r
          700  +|   3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45   owid.(rowid INTE
          701  +|   3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c   GER PRIMARY KEY,
          702  +|   4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07   nodeno,a0,a1)Q..
          703  +|   4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43   ......tablet1t1C
          704  +|   4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41   REATE VIRTUAL TA
          705  +|   4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72   BLE t1 USING rtr
          706  +|   4064: 65 65 28 69 64 2c 78 30 2c 78 31 2c 79 30 2c 79   ee(id,x0,x1,y0,y
          707  +|   4080: 31 2c 2b 6c 61 62 65 6c 2c 2b 6f 74 68 65 72 29   1,+label,+other)
          708  +| page 2 offset 4096
          709  +|      0: 0d 00 00 00 0e 0e f7 00 0f e8 0f d0 0f b7 0f 9e   ................
          710  +|     16: 0f 91 0f 81 0f 70 0f 5e 0f 4f 0f 39 0f 29 0f 18   .....p.^.O.9.)..
          711  +|     32: 0f 06 0e f7 00 00 00 00 00 00 00 00 00 00 00 00   ................
          712  +|   3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f   ..............to
          713  +|   3840: 70 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74   p half.....#.bot
          714  +|   3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72   tom half.....!.r
          715  +|   3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00   ight half.......
          716  +|   3888: 6c 65 66 74 20 68 61 6c 66 14 0a 05 00 09 2b 00   left half.....+.
          717  +|   3904: 74 68 65 20 77 68 6f 6c 65 20 74 68 69 6e 67 0d   the whole thing.
          718  +|   3920: 09 05 00 09 1d 00 74 6f 70 20 65 64 67 65 10 08   ......top edge..
          719  +|   3936: 05 00 09 23 00 62 6f 74 74 6f 6d 20 65 64 67 65   ...#.bottom edge
          720  +|   3952: 0f 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67   .....!.right edg
          721  +|   3968: 65 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67   e.......left edg
          722  +|   3984: 65 0b 05 05 00 09 19 00 23 65 6e 74 65 72 17 04   e.......#enter..
          723  +|   4000: 05 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74   ...1.upper-right
          724  +|   4016: 20 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f    corner.....1.lo
          725  +|   4032: 77 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72   wer-right corner
          726  +|   4048: 16 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66   ...../.upper-lef
          727  +|   4064: 74 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 00 6c   t corner...../.l
          728  +|   4080: 6f 77 65 72 2d 6c 65 66 74 20 63 6f 72 6e 65 72   ower-left corner
          729  +| page 3 offset 8192
          730  +|      0: 0d 00 00 00 02 0b 2d 00 0b 2d 00 00 00 00 00 00   ......-..-......
          731  +|   2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01   ..............P.
          732  +|   2864: 04 00 93 24 00 00 00 00 00 00 00 00 08 00 00 00   ...$............
          733  +|   2880: 00 42 c8 00 00 00 00 00 00 40 a0 00 00 00 00 00   .B.......@......
          734  +|   2896: 00 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 07   ....B...........
          735  +|   2912: 42 be 00 00 42 c8 00 00 00 00 00 00 42 c8 00 00   B...B.......B...
          736  +|   2928: 00 00 00 00 00 00 00 08 00 00 00 00 42 c8 00 00   ............B...
          737  +|   2944: 00 00 00 00 40 a0 00 00 00 00 00 00 00 00 00 09   ....@...........
          738  +|   2960: 00 00 00 00 42 c8 00 00 42 be 00 00 42 c8 00 00   ....B...B...B...
          739  +|   2976: 00 00 00 00 00 00 00 0a 00 00 00 00 42 c8 00 00   ............B...
          740  +|   2992: 00 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 0b   ....B...........
          741  +|   3008: 00 00 00 00 42 48 00 00 00 00 00 04 2c 80 00 00   ....BH......,...
          742  +|   3024: 00 00 00 00 00 00 00 c4 00 00 00 00 00 42 c8 00   .............B..
          743  +|   3040: 00 00 00 00 00 00 00 00 07 42 be 00 00 42 c8 00   .........B...B..
          744  +|   3056: 00 00 00 00 00 42 c8 00 00 00 00 00 00 00 00 00   .....B..........
          745  +|   3072: 08 00 00 00 00 42 c8 00 00 00 00 00 00 40 a0 00   .....B.......@..
          746  +|   3088: 00 00 00 00 00 00 00 00 09 00 00 00 00 42 c8 00   .............B..
          747  +|   3104: 00 42 be 00 00 42 c8 00 00 00 00 00 00 00 00 00   .B...B..........
          748  +|   3120: 0a 00 00 00 00 42 c8 00 00 00 00 00 00 42 c8 00   .....B.......B..
          749  +|   3136: 00 00 00 00 00 00 00 00 0b 00 00 00 00 42 48 00   .............BH.
          750  +|   3152: 00 00 00 00 04 2c 80 00 00 00 00 00 00 00 00 00   .....,..........
          751  +|   3168: c4 24 c0 00 04 2c 80 00 00 00 00 00 04 2c 80 00   .$...,.......,..
          752  +|   3184: 00 00 00 00 00 00 00 00 d0 00 00 00 04 2c 80 00   .............,..
          753  +|   3200: 00 00 00 00 04 24 80 00 00 00 00 00 00 00 00 00   .....$..........
          754  +|   3216: e0 00 00 00 04 2c 80 00 04 24 c0 00 04 2c 00 00   .....,...$...,..
          755  +| page 4 offset 12288
          756  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 0e 00 00 00   ................
          757  +|     16: 00 42 c8 00 00 42 4c 00 00 42 c8 00 00 00 00 00   .B...BL..B......
          758  +|     32: 00 00 00 0a 00 00 00 00 42 c8 00 00 00 00 00 00   ........B.......
          759  +|     48: 42 c8 00 00 00 00 00 00 00 00 00 0b 00 00 00 00   B...............
          760  +|     64: 42 48 00 00 00 00 00 04 2c 80 00 00 00 00 00 00   BH......,.......
          761  +|     80: 00 00 00 c4 24 c0 00 04 2c 80 00 00 00 00 00 04   ....$...,.......
          762  +|     96: 2c 80 00 00 00 00 00 00 00 00 00 d0 00 00 00 04   ,...............
          763  +|    112: 2c 80 00 00 00 00 00 04 24 80 00 00 00 00 00 00   ,.......$.......
          764  +|    128: 00 00 00 e0 00 00 00 04 2c 80 00 04 24 c0 00 04   ........,...$...
          765  +|    144: 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ,...............
          766  +| end c7.db
          767  +  }]
          768  +  catchsql {
          769  +    WITH RECURSIVE
          770  +      c1(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c1 WHERE x<8),
          771  +      c2(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM c2 WHERE y<5)
          772  +    INSERT INTO t1(id, x0,x1,y0,y1,label)
          773  +      SELECT 1000+x+y*100, x, x+1, y, y+1, printf('box-%d,%d',x,y) FROM c1, c2;
          774  +  }
          775  +} {1 {database disk image is malformed}}
          776  +
          777  +finish_test

Changes to ext/session/sqlite3session.h.

   332    332   */
   333    333   int sqlite3session_fullchangeset(
   334    334     sqlite3_session *pSession,      /* Session object */
   335    335     int *pnChangeset,               /* OUT: Size of buffer at *ppChangeset */
   336    336     void **ppChangeset              /* OUT: Buffer containing changeset */
   337    337   );
   338    338   
          339  +/*
          340  +** CAPI3REF: Generate A Full Changeset From A Session Object
          341  +**
          342  +** This function is similar to sqlite3session_changeset(), except that for
          343  +** each row affected by an UPDATE statement, all old.* values are recorded
          344  +** as part of the changeset, not just those modified.
          345  +*/
          346  +int sqlite3session_fullchangeset(
          347  +  sqlite3_session *pSession,      /* Session object */
          348  +  int *pnChangeset,               /* OUT: Size of buffer at *ppChangeset */
          349  +  void **ppChangeset              /* OUT: Buffer containing changeset */
          350  +);
          351  +
   339    352   /*
   340    353   ** CAPI3REF: Load The Difference Between Tables Into A Session
   341    354   ** METHOD: sqlite3_session
   342    355   **
   343    356   ** If it is not already attached to the session object passed as the first
   344    357   ** argument, this function attaches table zTbl in the same manner as the
   345    358   ** [sqlite3session_attach()] function. If zTbl does not exist, or if it
................................................................................
   557    570   **
   558    571   ** If argument pzTab is not NULL, then *pzTab is set to point to a
   559    572   ** nul-terminated utf-8 encoded string containing the name of the table
   560    573   ** affected by the current change. The buffer remains valid until either
   561    574   ** sqlite3changeset_next() is called on the iterator or until the 
   562    575   ** conflict-handler function returns. If pnCol is not NULL, then *pnCol is 
   563    576   ** set to the number of columns in the table affected by the change. If
   564         -** pbIncorrect is not NULL, then *pbIndirect is set to true (1) if the change
          577  +** pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
   565    578   ** is an indirect change, or false (0) otherwise. See the documentation for
   566    579   ** [sqlite3session_indirect()] for a description of direct and indirect
   567    580   ** changes. Finally, if pOp is not NULL, then *pOp is set to one of 
   568    581   ** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the 
   569    582   ** type of change that the iterator currently points to.
   570    583   **
   571    584   ** If no error occurs, SQLITE_OK is returned. If an error does occur, an

Changes to src/alter.c.

    24     24   ** Parameter zName is the name of a table that is about to be altered
    25     25   ** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).
    26     26   ** If the table is a system table, this function leaves an error message
    27     27   ** in pParse->zErr (system tables may not be altered) and returns non-zero.
    28     28   **
    29     29   ** Or, if zName is not a system table, zero is returned.
    30     30   */
    31         -static int isSystemTable(Parse *pParse, const char *zName){
    32         -  if( 0==sqlite3StrNICmp(zName, "sqlite_", 7) ){
    33         -    sqlite3ErrorMsg(pParse, "table %s may not be altered", zName);
           31  +static int isAlterableTable(Parse *pParse, Table *pTab){
           32  +  if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) 
           33  +#ifndef SQLITE_OMIT_VIRTUALTABLE
           34  +   || ( (pTab->tabFlags & TF_Shadow) 
           35  +     && (pParse->db->flags & SQLITE_Defensive)
           36  +     && pParse->db->nVdbeExec==0
           37  +   )
           38  +#endif
           39  +  ){
           40  +    sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
    34     41       return 1;
    35     42     }
    36     43     return 0;
    37     44   }
    38     45   
    39     46   /*
    40     47   ** Generate code to verify that the schemas of database zDb and, if
................................................................................
   122    129           "there is already another table or index with this name: %s", zName);
   123    130       goto exit_rename_table;
   124    131     }
   125    132   
   126    133     /* Make sure it is not a system table being altered, or a reserved name
   127    134     ** that the table is being renamed to.
   128    135     */
   129         -  if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){
          136  +  if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
   130    137       goto exit_rename_table;
   131    138     }
   132    139     if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto
   133    140       exit_rename_table;
   134    141     }
   135    142   
   136    143   #ifndef SQLITE_OMIT_VIEW
................................................................................
   420    427   #endif
   421    428   
   422    429     /* Make sure this is not an attempt to ALTER a view. */
   423    430     if( pTab->pSelect ){
   424    431       sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
   425    432       goto exit_begin_add_column;
   426    433     }
   427         -  if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){
          434  +  if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
   428    435       goto exit_begin_add_column;
   429    436     }
   430    437   
   431    438     assert( pTab->addColOffset>0 );
   432    439     iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   433    440   
   434    441     /* Put a copy of the Table struct in Parse.pNewTable for the
................................................................................
   522    529     int bQuote;                     /* True to quote the new name */
   523    530   
   524    531     /* Locate the table to be altered */
   525    532     pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
   526    533     if( !pTab ) goto exit_rename_column;
   527    534   
   528    535     /* Cannot alter a system table */
   529         -  if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ) goto exit_rename_column;
          536  +  if( SQLITE_OK!=isAlterableTable(pParse, pTab) ) goto exit_rename_column;
   530    537     if( SQLITE_OK!=isRealTable(pParse, pTab) ) goto exit_rename_column;
   531    538   
   532    539     /* Which schema holds the table to be altered */  
   533    540     iSchema = sqlite3SchemaToIndex(db, pTab->pSchema);
   534    541     assert( iSchema>=0 );
   535    542     zDb = db->aDb[iSchema].zDbSName;
   536    543   

Changes to src/analyze.c.

  1152   1152       */
  1153   1153       addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
  1154   1154       VdbeCoverage(v);
  1155   1155       sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
  1156   1156       addrNextRow = sqlite3VdbeCurrentAddr(v);
  1157   1157   
  1158   1158       if( nColTest>0 ){
  1159         -      int endDistinctTest = sqlite3VdbeMakeLabel(v);
         1159  +      int endDistinctTest = sqlite3VdbeMakeLabel(pParse);
  1160   1160         int *aGotoChng;               /* Array of jump instruction addresses */
  1161   1161         aGotoChng = sqlite3DbMallocRawNN(db, sizeof(int)*nColTest);
  1162   1162         if( aGotoChng==0 ) continue;
  1163   1163   
  1164   1164         /*
  1165   1165         **  next_row:
  1166   1166         **   regChng = 0

Changes to src/btree.c.

  4863   4863         }while( ALWAYS(pPrev) );
  4864   4864       }
  4865   4865       btreeReleaseAllCursorPages(pCur);
  4866   4866       unlockBtreeIfUnused(pBt);
  4867   4867       sqlite3_free(pCur->aOverflow);
  4868   4868       sqlite3_free(pCur->pKey);
  4869   4869       sqlite3BtreeLeave(pBtree);
         4870  +    pCur->pBtree = 0;
  4870   4871     }
  4871   4872     return SQLITE_OK;
  4872   4873   }
  4873   4874   
  4874   4875   /*
  4875   4876   ** Make sure the BtCursor* given in the argument has a valid
  4876   4877   ** BtCursor.info structure.  If it is not already valid, call

Changes to src/build.c.

   352    352      && SQLITE_OK!=sqlite3ReadSchema(pParse)
   353    353     ){
   354    354       return 0;
   355    355     }
   356    356   
   357    357     p = sqlite3FindTable(db, zName, zDbase);
   358    358     if( p==0 ){
   359         -    const char *zMsg = flags & LOCATE_VIEW ? "no such view" : "no such table";
   360    359   #ifndef SQLITE_OMIT_VIRTUALTABLE
   361    360       /* If zName is the not the name of a table in the schema created using
   362    361       ** CREATE, then check to see if it is the name of an virtual table that
   363    362       ** can be an eponymous virtual table. */
   364         -    Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
   365         -    if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
   366         -      pMod = sqlite3PragmaVtabRegister(db, zName);
   367         -    }
   368         -    if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
   369         -      return pMod->pEpoTab;
          363  +    if( pParse->disableVtab==0 ){
          364  +      Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
          365  +      if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
          366  +        pMod = sqlite3PragmaVtabRegister(db, zName);
          367  +      }
          368  +      if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
          369  +        return pMod->pEpoTab;
          370  +      }
   370    371       }
   371    372   #endif
   372         -    if( (flags & LOCATE_NOERR)==0 ){
   373         -      if( zDbase ){
   374         -        sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
   375         -      }else{
   376         -        sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
   377         -      }
   378         -      pParse->checkSchema = 1;
          373  +    if( flags & LOCATE_NOERR ) return 0;
          374  +    pParse->checkSchema = 1;
          375  +  }else if( IsVirtual(p) && pParse->disableVtab ){
          376  +    p = 0;
          377  +  }
          378  +
          379  +  if( p==0 ){
          380  +    const char *zMsg = flags & LOCATE_VIEW ? "no such view" : "no such table";
          381  +    if( zDbase ){
          382  +      sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
          383  +    }else{
          384  +      sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
   379    385       }
   380    386     }
   381    387   
   382    388     return p;
   383    389   }
   384    390   
   385    391   /*
................................................................................
  2630   2636     }
  2631   2637   
  2632   2638     /* Remove the table entry from SQLite's internal schema and modify
  2633   2639     ** the schema cookie.
  2634   2640     */
  2635   2641     if( IsVirtual(pTab) ){
  2636   2642       sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
         2643  +    sqlite3MayAbort(pParse);
  2637   2644     }
  2638   2645     sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
  2639   2646     sqlite3ChangeCookie(pParse, iDb);
  2640   2647     sqliteViewResetAll(db, iDb);
  2641   2648   }
  2642   2649   
  2643   2650   /*

Changes to src/delete.c.

   513    513           sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
   514    514         }
   515    515       }
   516    516     
   517    517       /* If this DELETE cannot use the ONEPASS strategy, this is the 
   518    518       ** end of the WHERE loop */
   519    519       if( eOnePass!=ONEPASS_OFF ){
   520         -      addrBypass = sqlite3VdbeMakeLabel(v);
          520  +      addrBypass = sqlite3VdbeMakeLabel(pParse);
   521    521       }else{
   522    522         sqlite3WhereEnd(pWInfo);
   523    523       }
   524    524     
   525    525       /* Unless this is a view, open cursors for the table we are 
   526    526       ** deleting from and all its indices. If this is a view, then the
   527    527       ** only effect this statement has is to fire the INSTEAD OF 
................................................................................
   702    702     assert( v );
   703    703     VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",
   704    704                            iDataCur, iIdxCur, iPk, (int)nPk));
   705    705   
   706    706     /* Seek cursor iCur to the row to delete. If this row no longer exists 
   707    707     ** (this can happen if a trigger program has already deleted it), do
   708    708     ** not attempt to delete it or fire any DELETE triggers.  */
   709         -  iLabel = sqlite3VdbeMakeLabel(v);
          709  +  iLabel = sqlite3VdbeMakeLabel(pParse);
   710    710     opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
   711    711     if( eMode==ONEPASS_OFF ){
   712    712       sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
   713    713       VdbeCoverageIf(v, opSeek==OP_NotExists);
   714    714       VdbeCoverageIf(v, opSeek==OP_NotFound);
   715    715     }
   716    716    
................................................................................
   908    908     Vdbe *v = pParse->pVdbe;
   909    909     int j;
   910    910     int regBase;
   911    911     int nCol;
   912    912   
   913    913     if( piPartIdxLabel ){
   914    914       if( pIdx->pPartIdxWhere ){
   915         -      *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
          915  +      *piPartIdxLabel = sqlite3VdbeMakeLabel(pParse);
   916    916         pParse->iSelfTab = iDataCur + 1;
   917    917         sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, 
   918    918                               SQLITE_JUMPIFNULL);
   919    919         pParse->iSelfTab = 0;
   920    920       }else{
   921    921         *piPartIdxLabel = 0;
   922    922       }

Changes to src/expr.c.

   477    477   **
   478    478   ** If pExpr is not a TK_SELECT expression, return 0.
   479    479   */
   480    480   static int exprCodeSubselect(Parse *pParse, Expr *pExpr){
   481    481     int reg = 0;
   482    482   #ifndef SQLITE_OMIT_SUBQUERY
   483    483     if( pExpr->op==TK_SELECT ){
   484         -    reg = sqlite3CodeSubselect(pParse, pExpr, 0, 0);
          484  +    reg = sqlite3CodeSubselect(pParse, pExpr);
   485    485     }
   486    486   #endif
   487    487     return reg;
   488    488   }
   489    489   
   490    490   /*
   491    491   ** Argument pVector points to a vector expression - either a TK_VECTOR
................................................................................
   549    549     Expr *pLeft = pExpr->pLeft;
   550    550     Expr *pRight = pExpr->pRight;
   551    551     int nLeft = sqlite3ExprVectorSize(pLeft);
   552    552     int i;
   553    553     int regLeft = 0;
   554    554     int regRight = 0;
   555    555     u8 opx = op;
   556         -  int addrDone = sqlite3VdbeMakeLabel(v);
          556  +  int addrDone = sqlite3VdbeMakeLabel(pParse);
   557    557   
   558    558     if( nLeft!=sqlite3ExprVectorSize(pRight) ){
   559    559       sqlite3ErrorMsg(pParse, "row value misused");
   560    560       return;
   561    561     }
   562    562     assert( pExpr->op==TK_EQ || pExpr->op==TK_NE 
   563    563          || pExpr->op==TK_IS || pExpr->op==TK_ISNOT 
................................................................................
  2108   2108   ** be a small performance hit but is otherwise harmless.  On the other
  2109   2109   ** hand, a false negative (returning FALSE when the result could be NULL)
  2110   2110   ** will likely result in an incorrect answer.  So when in doubt, return
  2111   2111   ** TRUE.
  2112   2112   */
  2113   2113   int sqlite3ExprCanBeNull(const Expr *p){
  2114   2114     u8 op;
  2115         -  while( p->op==TK_UPLUS || p->op==TK_UMINUS ){ p = p->pLeft; }
         2115  +  while( p->op==TK_UPLUS || p->op==TK_UMINUS ){
         2116  +    p = p->pLeft;
         2117  +  }
  2116   2118     op = p->op;
  2117   2119     if( op==TK_REGISTER ) op = p->op2;
  2118   2120     switch( op ){
  2119   2121       case TK_INTEGER:
  2120   2122       case TK_STRING:
  2121   2123       case TK_FLOAT:
  2122   2124       case TK_BLOB:
................................................................................
  2344   2346   */
  2345   2347   #ifndef SQLITE_OMIT_SUBQUERY
  2346   2348   int sqlite3FindInIndex(
  2347   2349     Parse *pParse,             /* Parsing context */
  2348   2350     Expr *pX,                  /* The right-hand side (RHS) of the IN operator */
  2349   2351     u32 inFlags,               /* IN_INDEX_LOOP, _MEMBERSHIP, and/or _NOOP_OK */
  2350   2352     int *prRhsHasNull,         /* Register holding NULL status.  See notes */
  2351         -  int *aiMap                 /* Mapping from Index fields to RHS fields */
         2353  +  int *aiMap,                /* Mapping from Index fields to RHS fields */
         2354  +  int *piTab                 /* OUT: index to use */
  2352   2355   ){
  2353   2356     Select *p;                            /* SELECT to the right of IN operator */
  2354   2357     int eType = 0;                        /* Type of RHS table. IN_INDEX_* */
  2355   2358     int iTab = pParse->nTab++;            /* Cursor of the RHS table */
  2356   2359     int mustBeUnique;                     /* True if RHS must be unique */
  2357   2360     Vdbe *v = sqlite3GetVdbe(pParse);     /* Virtual machine being coded */
  2358   2361   
................................................................................
  2536   2539         pParse->nQueryLoop = 0;
  2537   2540         if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
  2538   2541           eType = IN_INDEX_ROWID;
  2539   2542         }
  2540   2543       }else if( prRhsHasNull ){
  2541   2544         *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
  2542   2545       }
  2543         -    sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
         2546  +    assert( pX->op==TK_IN );
         2547  +    sqlite3CodeRhsOfIN(pParse, pX, iTab, eType==IN_INDEX_ROWID);
         2548  +    if( rMayHaveNull ){
         2549  +      sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
         2550  +    }
  2544   2551       pParse->nQueryLoop = savedNQueryLoop;
  2545         -  }else{
  2546         -    pX->iTable = iTab;
  2547   2552     }
  2548   2553   
  2549   2554     if( aiMap && eType!=IN_INDEX_INDEX_ASC && eType!=IN_INDEX_INDEX_DESC ){
  2550   2555       int i, n;
  2551   2556       n = sqlite3ExprVectorSize(pX->pLeft);
  2552   2557       for(i=0; i<n; i++) aiMap[i] = i;
  2553   2558     }
         2559  +  *piTab = iTab;
  2554   2560     return eType;
  2555   2561   }
  2556   2562   #endif
  2557   2563   
  2558   2564   #ifndef SQLITE_OMIT_SUBQUERY
  2559   2565   /*
  2560   2566   ** Argument pExpr is an (?, ?...) IN(...) expression. This 
................................................................................
  2620   2626     }else
  2621   2627   #endif
  2622   2628     {
  2623   2629       sqlite3ErrorMsg(pParse, "row value misused");
  2624   2630     }
  2625   2631   }
  2626   2632   
         2633  +#ifndef SQLITE_OMIT_SUBQUERY
  2627   2634   /*
  2628         -** Generate code for scalar subqueries used as a subquery expression, EXISTS,
  2629         -** or IN operators.  Examples:
         2635  +** Generate code that will construct an ephemeral table containing all terms
         2636  +** in the RHS of an IN operator.  The IN operator can be in either of two
         2637  +** forms:
  2630   2638   **
  2631         -**     (SELECT a FROM b)          -- subquery
  2632         -**     EXISTS (SELECT a FROM b)   -- EXISTS subquery
  2633   2639   **     x IN (4,5,11)              -- IN operator with list on right-hand side
  2634   2640   **     x IN (SELECT a FROM b)     -- IN operator with subquery on the right
  2635   2641   **
  2636         -** The pExpr parameter describes the expression that contains the IN
  2637         -** operator or subquery.
  2638         -**
  2639         -** If parameter isRowid is non-zero, then expression pExpr is guaranteed
  2640         -** to be of the form "<rowid> IN (?, ?, ?)", where <rowid> is a reference
  2641         -** to some integer key column of a table B-Tree. In this case, use an
  2642         -** intkey B-Tree to store the set of IN(...) values instead of the usual
  2643         -** (slower) variable length keys B-Tree.
  2644         -**
  2645         -** If rMayHaveNull is non-zero, that means that the operation is an IN
  2646         -** (not a SELECT or EXISTS) and that the RHS might contains NULLs.
  2647         -** All this routine does is initialize the register given by rMayHaveNull
  2648         -** to NULL.  Calling routines will take care of changing this register
  2649         -** value to non-NULL if the RHS is NULL-free.
  2650         -**
  2651         -** For a SELECT or EXISTS operator, return the register that holds the
  2652         -** result.  For a multi-column SELECT, the result is stored in a contiguous
  2653         -** array of registers and the return value is the register of the left-most
  2654         -** result column.  Return 0 for IN operators or if an error occurs.
         2642  +** The pExpr parameter is the IN operator.  The cursor number for the
         2643  +** constructed ephermeral table is returned.  The first time the ephemeral
         2644  +** table is computed, the cursor number is also stored in pExpr->iTable,
         2645  +** however the cursor number returned might not be the same, as it might
         2646  +** have been duplicated using OP_OpenDup.
         2647  +**
         2648  +** If parameter isRowid is non-zero, then LHS of the IN operator is guaranteed
         2649  +** to be a non-null integer. In this case, the ephemeral table can be an
         2650  +** table B-Tree that keyed by only integers.  The more general cases uses
         2651  +** an index B-Tree which can have arbitrary keys, but is slower to both
         2652  +** read and write.
         2653  +**
         2654  +** If the LHS expression ("x" in the examples) is a column value, or
         2655  +** the SELECT statement returns a column value, then the affinity of that
         2656  +** column is used to build the index keys. If both 'x' and the
         2657  +** SELECT... statement are columns, then numeric affinity is used
         2658  +** if either column has NUMERIC or INTEGER affinity. If neither
         2659  +** 'x' nor the SELECT... statement are columns, then numeric affinity
         2660  +** is used.
         2661  +*/
         2662  +void sqlite3CodeRhsOfIN(
         2663  +  Parse *pParse,          /* Parsing context */
         2664  +  Expr *pExpr,            /* The IN operator */
         2665  +  int iTab,               /* Use this cursor number */
         2666  +  int isRowid             /* If true, LHS is a rowid */
         2667  +){
         2668  +  int addrOnce = 0;           /* Address of the OP_Once instruction at top */
         2669  +  int addr;                   /* Address of OP_OpenEphemeral instruction */
         2670  +  Expr *pLeft;                /* the LHS of the IN operator */
         2671  +  KeyInfo *pKeyInfo = 0;      /* Key information */
         2672  +  int nVal;                   /* Size of vector pLeft */
         2673  +  Vdbe *v;                    /* The prepared statement under construction */
         2674  +
         2675  +  v = pParse->pVdbe;
         2676  +  assert( v!=0 );
         2677  +
         2678  +  /* The evaluation of the IN must be repeated every time it
         2679  +  ** is encountered if any of the following is true:
         2680  +  **
         2681  +  **    *  The right-hand side is a correlated subquery
         2682  +  **    *  The right-hand side is an expression list containing variables
         2683  +  **    *  We are inside a trigger
         2684  +  **
         2685  +  ** If all of the above are false, then we can compute the RHS just once
         2686  +  ** and reuse it many names.
         2687  +  */
         2688  +  if( !ExprHasProperty(pExpr, EP_VarSelect) && pParse->iSelfTab==0 ){
         2689  +    /* Reuse of the RHS is allowed */
         2690  +    /* If this routine has already been coded, but the previous code
         2691  +    ** might not have been invoked yet, so invoke it now as a subroutine. 
         2692  +    */
         2693  +    if( ExprHasProperty(pExpr, EP_Subrtn) ){
         2694  +      addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
         2695  +      if( ExprHasProperty(pExpr, EP_xIsSelect) ){
         2696  +        ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
         2697  +              pExpr->x.pSelect->selId));
         2698  +      }
         2699  +      sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
         2700  +                        pExpr->y.sub.iAddr);
         2701  +      sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
         2702  +      sqlite3VdbeJumpHere(v, addrOnce);
         2703  +      return;
         2704  +    }
         2705  +
         2706  +    /* Begin coding the subroutine */
         2707  +    ExprSetProperty(pExpr, EP_Subrtn);
         2708  +    pExpr->y.sub.regReturn = ++pParse->nMem;
         2709  +    pExpr->y.sub.iAddr =
         2710  +      sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
         2711  +    VdbeComment((v, "return address"));
         2712  +
         2713  +    addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
         2714  +  }
         2715  +
         2716  +  /* Check to see if this is a vector IN operator */
         2717  +  pLeft = pExpr->pLeft;
         2718  +  nVal = sqlite3ExprVectorSize(pLeft);
         2719  +  assert( !isRowid || nVal==1 );
         2720  +
         2721  +  /* Construct the ephemeral table that will contain the content of
         2722  +  ** RHS of the IN operator.
         2723  +  */
         2724  +  pExpr->iTable = iTab;
         2725  +  addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, 
         2726  +      pExpr->iTable, (isRowid?0:nVal));
         2727  +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
         2728  +  if( ExprHasProperty(pExpr, EP_xIsSelect) ){
         2729  +    VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
         2730  +  }else{
         2731  +    VdbeComment((v, "RHS of IN operator"));
         2732  +  }
         2733  +#endif
         2734  +  pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
         2735  +
         2736  +  if( ExprHasProperty(pExpr, EP_xIsSelect) ){
         2737  +    /* Case 1:     expr IN (SELECT ...)
         2738  +    **
         2739  +    ** Generate code to write the results of the select into the temporary
         2740  +    ** table allocated and opened above.
         2741  +    */
         2742  +    Select *pSelect = pExpr->x.pSelect;
         2743  +    ExprList *pEList = pSelect->pEList;
         2744  +
         2745  +    ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY %d",
         2746  +        addrOnce?"":"CORRELATED ", pSelect->selId
         2747  +    ));
         2748  +    assert( !isRowid );
         2749  +    /* If the LHS and RHS of the IN operator do not match, that
         2750  +    ** error will have been caught long before we reach this point. */
         2751  +    if( ALWAYS(pEList->nExpr==nVal) ){
         2752  +      SelectDest dest;
         2753  +      int i;
         2754  +      sqlite3SelectDestInit(&dest, SRT_Set, iTab);
         2755  +      dest.zAffSdst = exprINAffinity(pParse, pExpr);
         2756  +      pSelect->iLimit = 0;
         2757  +      testcase( pSelect->selFlags & SF_Distinct );
         2758  +      testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
         2759  +      if( sqlite3Select(pParse, pSelect, &dest) ){
         2760  +        sqlite3DbFree(pParse->db, dest.zAffSdst);
         2761  +        sqlite3KeyInfoUnref(pKeyInfo);
         2762  +        return;
         2763  +      }
         2764  +      sqlite3DbFree(pParse->db, dest.zAffSdst);
         2765  +      assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
         2766  +      assert( pEList!=0 );
         2767  +      assert( pEList->nExpr>0 );
         2768  +      assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
         2769  +      for(i=0; i<nVal; i++){
         2770  +        Expr *p = sqlite3VectorFieldSubexpr(pLeft, i);
         2771  +        pKeyInfo->aColl[i] = sqlite3BinaryCompareCollSeq(
         2772  +            pParse, p, pEList->a[i].pExpr
         2773  +        );
         2774  +      }
         2775  +    }
         2776  +  }else if( ALWAYS(pExpr->x.pList!=0) ){
         2777  +    /* Case 2:     expr IN (exprlist)
         2778  +    **
         2779  +    ** For each expression, build an index key from the evaluation and
         2780  +    ** store it in the temporary table. If <expr> is a column, then use
         2781  +    ** that columns affinity when building index keys. If <expr> is not
         2782  +    ** a column, use numeric affinity.
         2783  +    */
         2784  +    char affinity;            /* Affinity of the LHS of the IN */
         2785  +    int i;
         2786  +    ExprList *pList = pExpr->x.pList;
         2787  +    struct ExprList_item *pItem;
         2788  +    int r1, r2, r3;
         2789  +    affinity = sqlite3ExprAffinity(pLeft);
         2790  +    if( !affinity ){
         2791  +      affinity = SQLITE_AFF_BLOB;
         2792  +    }
         2793  +    if( pKeyInfo ){
         2794  +      assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
         2795  +      pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
         2796  +    }
         2797  +
         2798  +    /* Loop through each expression in <exprlist>. */
         2799  +    r1 = sqlite3GetTempReg(pParse);
         2800  +    r2 = sqlite3GetTempReg(pParse);
         2801  +    if( isRowid ) sqlite3VdbeAddOp4(v, OP_Blob, 0, r2, 0, "", P4_STATIC);
         2802  +    for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
         2803  +      Expr *pE2 = pItem->pExpr;
         2804  +      int iValToIns;
         2805  +
         2806  +      /* If the expression is not constant then we will need to
         2807  +      ** disable the test that was generated above that makes sure
         2808  +      ** this code only executes once.  Because for a non-constant
         2809  +      ** expression we need to rerun this code each time.
         2810  +      */
         2811  +      if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
         2812  +        sqlite3VdbeChangeToNoop(v, addrOnce);
         2813  +        addrOnce = 0;
         2814  +      }
         2815  +
         2816  +      /* Evaluate the expression and insert it into the temp table */
         2817  +      if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
         2818  +        sqlite3VdbeAddOp3(v, OP_InsertInt, iTab, r2, iValToIns);
         2819  +      }else{
         2820  +        r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
         2821  +        if( isRowid ){
         2822  +          sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
         2823  +                            sqlite3VdbeCurrentAddr(v)+2);
         2824  +          VdbeCoverage(v);
         2825  +          sqlite3VdbeAddOp3(v, OP_Insert, iTab, r2, r3);
         2826  +        }else{
         2827  +          sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
         2828  +          sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
         2829  +        }
         2830  +      }
         2831  +    }
         2832  +    sqlite3ReleaseTempReg(pParse, r1);
         2833  +    sqlite3ReleaseTempReg(pParse, r2);
         2834  +  }
         2835  +  if( pKeyInfo ){
         2836  +    sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
         2837  +  }
         2838  +  if( addrOnce ){
         2839  +    sqlite3VdbeJumpHere(v, addrOnce);
         2840  +    /* Subroutine return */
         2841  +    sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
         2842  +    sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
         2843  +  }
         2844  +}
         2845  +#endif /* SQLITE_OMIT_SUBQUERY */
         2846  +
         2847  +/*
         2848  +** Generate code for scalar subqueries used as a subquery expression
         2849  +** or EXISTS operator:
         2850  +**
         2851  +**     (SELECT a FROM b)          -- subquery
         2852  +**     EXISTS (SELECT a FROM b)   -- EXISTS subquery
         2853  +**
         2854  +** The pExpr parameter is the SELECT or EXISTS operator to be coded.
         2855  +**
         2856  +** The register that holds the result.  For a multi-column SELECT, 
         2857  +** the result is stored in a contiguous array of registers and the
         2858  +** return value is the register of the left-most result column.
         2859  +** Return 0 if an error occurs.
  2655   2860   */
  2656   2861   #ifndef SQLITE_OMIT_SUBQUERY
  2657         -int sqlite3CodeSubselect(
  2658         -  Parse *pParse,          /* Parsing context */
  2659         -  Expr *pExpr,            /* The IN, SELECT, or EXISTS operator */
  2660         -  int rHasNullFlag,       /* Register that records whether NULLs exist in RHS */
  2661         -  int isRowid             /* If true, LHS of IN operator is a rowid */
  2662         -){
  2663         -  int jmpIfDynamic = -1;                      /* One-time test address */
  2664         -  int rReg = 0;                           /* Register storing resulting */
  2665         -  Vdbe *v = sqlite3GetVdbe(pParse);
  2666         -  if( NEVER(v==0) ) return 0;
         2862  +int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
         2863  +  int addrOnce = 0;           /* Address of OP_Once at top of subroutine */
         2864  +  int rReg = 0;               /* Register storing resulting */
         2865  +  Select *pSel;               /* SELECT statement to encode */
         2866  +  SelectDest dest;            /* How to deal with SELECT result */
         2867  +  int nReg;                   /* Registers to allocate */
         2868  +  Expr *pLimit;               /* New limit expression */
  2667   2869   
  2668         -  /* The evaluation of the IN/EXISTS/SELECT must be repeated every time it
         2870  +  Vdbe *v = pParse->pVdbe;
         2871  +  assert( v!=0 );
         2872  +  testcase( pExpr->op==TK_EXISTS );
         2873  +  testcase( pExpr->op==TK_SELECT );
         2874  +  assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
         2875  +  assert( ExprHasProperty(pExpr, EP_xIsSelect) );
         2876  +  pSel = pExpr->x.pSelect;
         2877  +
         2878  +  /* The evaluation of the EXISTS/SELECT must be repeated every time it
  2669   2879     ** is encountered if any of the following is true:
  2670   2880     **
  2671   2881     **    *  The right-hand side is a correlated subquery
  2672   2882     **    *  The right-hand side is an expression list containing variables
  2673   2883     **    *  We are inside a trigger
  2674   2884     **
  2675   2885     ** If all of the above are false, then we can run this code just once
  2676   2886     ** save the results, and reuse the same result on subsequent invocations.
  2677   2887     */
  2678   2888     if( !ExprHasProperty(pExpr, EP_VarSelect) ){
  2679         -    jmpIfDynamic = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
  2680         -  }
  2681         -
  2682         -  switch( pExpr->op ){
  2683         -    case TK_IN: {
  2684         -      int addr;                   /* Address of OP_OpenEphemeral instruction */
  2685         -      Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
  2686         -      KeyInfo *pKeyInfo = 0;      /* Key information */
  2687         -      int nVal;                   /* Size of vector pLeft */
  2688         -      
  2689         -      nVal = sqlite3ExprVectorSize(pLeft);
  2690         -      assert( !isRowid || nVal==1 );
  2691         -
  2692         -      /* Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)'
  2693         -      ** expression it is handled the same way.  An ephemeral table is 
  2694         -      ** filled with index keys representing the results from the 
  2695         -      ** SELECT or the <exprlist>.
  2696         -      **
  2697         -      ** If the 'x' expression is a column value, or the SELECT...
  2698         -      ** statement returns a column value, then the affinity of that
  2699         -      ** column is used to build the index keys. If both 'x' and the
  2700         -      ** SELECT... statement are columns, then numeric affinity is used
  2701         -      ** if either column has NUMERIC or INTEGER affinity. If neither
  2702         -      ** 'x' nor the SELECT... statement are columns, then numeric affinity
  2703         -      ** is used.
  2704         -      */
  2705         -      pExpr->iTable = pParse->nTab++;
  2706         -      addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, 
  2707         -          pExpr->iTable, (isRowid?0:nVal));
  2708         -      pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
  2709         -
  2710         -      if( ExprHasProperty(pExpr, EP_xIsSelect) ){
  2711         -        /* Case 1:     expr IN (SELECT ...)
  2712         -        **
  2713         -        ** Generate code to write the results of the select into the temporary
  2714         -        ** table allocated and opened above.
  2715         -        */
  2716         -        Select *pSelect = pExpr->x.pSelect;
  2717         -        ExprList *pEList = pSelect->pEList;
  2718         -
  2719         -        ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY",
  2720         -            jmpIfDynamic>=0?"":"CORRELATED "
  2721         -        ));
  2722         -        assert( !isRowid );
  2723         -        /* If the LHS and RHS of the IN operator do not match, that
  2724         -        ** error will have been caught long before we reach this point. */
  2725         -        if( ALWAYS(pEList->nExpr==nVal) ){
  2726         -          SelectDest dest;
  2727         -          int i;
  2728         -          sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
  2729         -          dest.zAffSdst = exprINAffinity(pParse, pExpr);
  2730         -          pSelect->iLimit = 0;
  2731         -          testcase( pSelect->selFlags & SF_Distinct );
  2732         -          testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
  2733         -          if( sqlite3Select(pParse, pSelect, &dest) ){
  2734         -            sqlite3DbFree(pParse->db, dest.zAffSdst);
  2735         -            sqlite3KeyInfoUnref(pKeyInfo);
  2736         -            return 0;
  2737         -          }
  2738         -          sqlite3DbFree(pParse->db, dest.zAffSdst);
  2739         -          assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
  2740         -          assert( pEList!=0 );
  2741         -          assert( pEList->nExpr>0 );
  2742         -          assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
  2743         -          for(i=0; i<nVal; i++){
  2744         -            Expr *p = sqlite3VectorFieldSubexpr(pLeft, i);
  2745         -            pKeyInfo->aColl[i] = sqlite3BinaryCompareCollSeq(
  2746         -                pParse, p, pEList->a[i].pExpr
  2747         -            );
  2748         -          }
  2749         -        }
  2750         -      }else if( ALWAYS(pExpr->x.pList!=0) ){
  2751         -        /* Case 2:     expr IN (exprlist)
  2752         -        **
  2753         -        ** For each expression, build an index key from the evaluation and
  2754         -        ** store it in the temporary table. If <expr> is a column, then use
  2755         -        ** that columns affinity when building index keys. If <expr> is not
  2756         -        ** a column, use numeric affinity.
  2757         -        */
  2758         -        char affinity;            /* Affinity of the LHS of the IN */
  2759         -        int i;
  2760         -        ExprList *pList = pExpr->x.pList;
  2761         -        struct ExprList_item *pItem;
  2762         -        int r1, r2, r3;
  2763         -        affinity = sqlite3ExprAffinity(pLeft);
  2764         -        if( !affinity ){
  2765         -          affinity = SQLITE_AFF_BLOB;
  2766         -        }
  2767         -        if( pKeyInfo ){
  2768         -          assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
  2769         -          pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
  2770         -        }
  2771         -
  2772         -        /* Loop through each expression in <exprlist>. */
  2773         -        r1 = sqlite3GetTempReg(pParse);
  2774         -        r2 = sqlite3GetTempReg(pParse);
  2775         -        if( isRowid ) sqlite3VdbeAddOp4(v, OP_Blob, 0, r2, 0, "", P4_STATIC);
  2776         -        for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
  2777         -          Expr *pE2 = pItem->pExpr;
  2778         -          int iValToIns;
  2779         -
  2780         -          /* If the expression is not constant then we will need to
  2781         -          ** disable the test that was generated above that makes sure
  2782         -          ** this code only executes once.  Because for a non-constant
  2783         -          ** expression we need to rerun this code each time.
  2784         -          */
  2785         -          if( jmpIfDynamic>=0 && !sqlite3ExprIsConstant(pE2) ){
  2786         -            sqlite3VdbeChangeToNoop(v, jmpIfDynamic);
  2787         -            jmpIfDynamic = -1;
  2788         -          }
  2789         -
  2790         -          /* Evaluate the expression and insert it into the temp table */
  2791         -          if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
  2792         -            sqlite3VdbeAddOp3(v, OP_InsertInt, pExpr->iTable, r2, iValToIns);
  2793         -          }else{
  2794         -            r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
  2795         -            if( isRowid ){
  2796         -              sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
  2797         -                                sqlite3VdbeCurrentAddr(v)+2);
  2798         -              VdbeCoverage(v);
  2799         -              sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
  2800         -            }else{
  2801         -              sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
  2802         -              sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pExpr->iTable, r2, r3, 1);
  2803         -            }
  2804         -          }
  2805         -        }
  2806         -        sqlite3ReleaseTempReg(pParse, r1);
  2807         -        sqlite3ReleaseTempReg(pParse, r2);
  2808         -      }
  2809         -      if( pKeyInfo ){
  2810         -        sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
  2811         -      }
  2812         -      break;
  2813         -    }
  2814         -
  2815         -    case TK_EXISTS:
  2816         -    case TK_SELECT:
  2817         -    default: {
  2818         -      /* Case 3:    (SELECT ... FROM ...)
  2819         -      **     or:    EXISTS(SELECT ... FROM ...)
  2820         -      **
  2821         -      ** For a SELECT, generate code to put the values for all columns of
  2822         -      ** the first row into an array of registers and return the index of
  2823         -      ** the first register.
  2824         -      **
  2825         -      ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
  2826         -      ** into a register and return that register number.
  2827         -      **
  2828         -      ** In both cases, the query is augmented with "LIMIT 1".  Any 
  2829         -      ** preexisting limit is discarded in place of the new LIMIT 1.
  2830         -      */
  2831         -      Select *pSel;                         /* SELECT statement to encode */
  2832         -      SelectDest dest;                      /* How to deal with SELECT result */
  2833         -      int nReg;                             /* Registers to allocate */
  2834         -      Expr *pLimit;                         /* New limit expression */
  2835         -
  2836         -      testcase( pExpr->op==TK_EXISTS );
  2837         -      testcase( pExpr->op==TK_SELECT );
  2838         -      assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
  2839         -      assert( ExprHasProperty(pExpr, EP_xIsSelect) );
  2840         -
  2841         -      pSel = pExpr->x.pSelect;
  2842         -      ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY",
  2843         -            jmpIfDynamic>=0?"":"CORRELATED "));
  2844         -      nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
  2845         -      sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
  2846         -      pParse->nMem += nReg;
  2847         -      if( pExpr->op==TK_SELECT ){
  2848         -        dest.eDest = SRT_Mem;
  2849         -        dest.iSdst = dest.iSDParm;
  2850         -        dest.nSdst = nReg;
  2851         -        sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1);
  2852         -        VdbeComment((v, "Init subquery result"));
  2853         -      }else{
  2854         -        dest.eDest = SRT_Exists;
  2855         -        sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
  2856         -        VdbeComment((v, "Init EXISTS result"));
  2857         -      }
  2858         -      pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0);
  2859         -      if( pSel->pLimit ){
  2860         -        sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft);
  2861         -        pSel->pLimit->pLeft = pLimit;
  2862         -      }else{
  2863         -        pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
  2864         -      }
  2865         -      pSel->iLimit = 0;
  2866         -      if( sqlite3Select(pParse, pSel, &dest) ){
  2867         -        return 0;
  2868         -      }
  2869         -      rReg = dest.iSDParm;
  2870         -      ExprSetVVAProperty(pExpr, EP_NoReduce);
  2871         -      break;
  2872         -    }
  2873         -  }
  2874         -
  2875         -  if( rHasNullFlag ){
  2876         -    sqlite3SetHasNullFlag(v, pExpr->iTable, rHasNullFlag);
  2877         -  }
  2878         -
  2879         -  if( jmpIfDynamic>=0 ){
  2880         -    sqlite3VdbeJumpHere(v, jmpIfDynamic);
         2889  +    /* If this routine has already been coded, then invoke it as a
         2890  +    ** subroutine. */
         2891  +    if( ExprHasProperty(pExpr, EP_Subrtn) ){
         2892  +      ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
         2893  +      sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
         2894  +                        pExpr->y.sub.iAddr);
         2895  +      return pExpr->iTable;
         2896  +    }
         2897  +
         2898  +    /* Begin coding the subroutine */
         2899  +    ExprSetProperty(pExpr, EP_Subrtn);
         2900  +    pExpr->y.sub.regReturn = ++pParse->nMem;
         2901  +    pExpr->y.sub.iAddr =
         2902  +      sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
         2903  +    VdbeComment((v, "return address"));
         2904  +
         2905  +    addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
         2906  +  }
         2907  +  
         2908  +  /* For a SELECT, generate code to put the values for all columns of
         2909  +  ** the first row into an array of registers and return the index of
         2910  +  ** the first register.
         2911  +  **
         2912  +  ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
         2913  +  ** into a register and return that register number.
         2914  +  **
         2915  +  ** In both cases, the query is augmented with "LIMIT 1".  Any 
         2916  +  ** preexisting limit is discarded in place of the new LIMIT 1.
         2917  +  */
         2918  +  ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY %d",
         2919  +        addrOnce?"":"CORRELATED ", pSel->selId));
         2920  +  nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
         2921  +  sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
         2922  +  pParse->nMem += nReg;
         2923  +  if( pExpr->op==TK_SELECT ){
         2924  +    dest.eDest = SRT_Mem;
         2925  +    dest.iSdst = dest.iSDParm;
         2926  +    dest.nSdst = nReg;
         2927  +    sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1);
         2928  +    VdbeComment((v, "Init subquery result"));
         2929  +  }else{
         2930  +    dest.eDest = SRT_Exists;
         2931  +    sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
         2932  +    VdbeComment((v, "Init EXISTS result"));
         2933  +  }
         2934  +  pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0);
         2935  +  if( pSel->pLimit ){
         2936  +    sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft);
         2937  +    pSel->pLimit->pLeft = pLimit;
         2938  +  }else{
         2939  +    pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
         2940  +  }
         2941  +  pSel->iLimit = 0;
         2942  +  if( sqlite3Select(pParse, pSel, &dest) ){
         2943  +    return 0;
         2944  +  }
         2945  +  pExpr->iTable = rReg = dest.iSDParm;
         2946  +  ExprSetVVAProperty(pExpr, EP_NoReduce);
         2947  +  if( addrOnce ){
         2948  +    sqlite3VdbeJumpHere(v, addrOnce);
         2949  +
         2950  +    /* Subroutine return */
         2951  +    sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
         2952  +    sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
  2881   2953     }
  2882   2954   
  2883   2955     return rReg;
  2884   2956   }
  2885   2957   #endif /* SQLITE_OMIT_SUBQUERY */
  2886   2958   
  2887   2959   #ifndef SQLITE_OMIT_SUBQUERY
................................................................................
  2950   3022     Expr *pLeft;          /* The LHS of the IN operator */
  2951   3023     int i;                /* loop counter */
  2952   3024     int destStep2;        /* Where to jump when NULLs seen in step 2 */
  2953   3025     int destStep6 = 0;    /* Start of code for Step 6 */
  2954   3026     int addrTruthOp;      /* Address of opcode that determines the IN is true */
  2955   3027     int destNotNull;      /* Jump here if a comparison is not true in step 6 */
  2956   3028     int addrTop;          /* Top of the step-6 loop */ 
         3029  +  int iTab = 0;         /* Index to use */
  2957   3030   
  2958   3031     pLeft = pExpr->pLeft;
  2959   3032     if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
  2960   3033     zAff = exprINAffinity(pParse, pExpr);
  2961   3034     nVector = sqlite3ExprVectorSize(pExpr->pLeft);
  2962   3035     aiMap = (int*)sqlite3DbMallocZero(
  2963   3036         pParse->db, nVector*(sizeof(int) + sizeof(char)) + 1
  2964   3037     );
  2965   3038     if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
  2966   3039   
  2967   3040     /* Attempt to compute the RHS. After this step, if anything other than
  2968         -  ** IN_INDEX_NOOP is returned, the table opened ith cursor pExpr->iTable 
         3041  +  ** IN_INDEX_NOOP is returned, the table opened with cursor iTab
  2969   3042     ** contains the values that make up the RHS. If IN_INDEX_NOOP is returned,
  2970   3043     ** the RHS has not yet been coded.  */
  2971   3044     v = pParse->pVdbe;
  2972   3045     assert( v!=0 );       /* OOM detected prior to this routine */
  2973   3046     VdbeNoopComment((v, "begin IN expr"));
  2974   3047     eType = sqlite3FindInIndex(pParse, pExpr,
  2975   3048                                IN_INDEX_MEMBERSHIP | IN_INDEX_NOOP_OK,
  2976         -                             destIfFalse==destIfNull ? 0 : &rRhsHasNull, aiMap);
         3049  +                             destIfFalse==destIfNull ? 0 : &rRhsHasNull,
         3050  +                             aiMap, &iTab);
  2977   3051   
  2978   3052     assert( pParse->nErr || nVector==1 || eType==IN_INDEX_EPH
  2979   3053          || eType==IN_INDEX_INDEX_ASC || eType==IN_INDEX_INDEX_DESC 
  2980   3054     );
  2981   3055   #ifdef SQLITE_DEBUG
  2982   3056     /* Confirm that aiMap[] contains nVector integer values between 0 and
  2983   3057     ** nVector-1. */
................................................................................
  3015   3089     ** sequence of comparisons.
  3016   3090     **
  3017   3091     ** This is step (1) in the in-operator.md optimized algorithm.
  3018   3092     */
  3019   3093     if( eType==IN_INDEX_NOOP ){
  3020   3094       ExprList *pList = pExpr->x.pList;
  3021   3095       CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
  3022         -    int labelOk = sqlite3VdbeMakeLabel(v);
         3096  +    int labelOk = sqlite3VdbeMakeLabel(pParse);
  3023   3097       int r2, regToFree;
  3024   3098       int regCkNull = 0;
  3025   3099       int ii;
  3026   3100       assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
  3027   3101       if( destIfNull!=destIfFalse ){
  3028   3102         regCkNull = sqlite3GetTempReg(pParse);
  3029   3103         sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
................................................................................
  3059   3133     /* Step 2: Check to see if the LHS contains any NULL columns.  If the
  3060   3134     ** LHS does contain NULLs then the result must be either FALSE or NULL.
  3061   3135     ** We will then skip the binary search of the RHS.
  3062   3136     */
  3063   3137     if( destIfNull==destIfFalse ){
  3064   3138       destStep2 = destIfFalse;
  3065   3139     }else{
  3066         -    destStep2 = destStep6 = sqlite3VdbeMakeLabel(v);
         3140  +    destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
  3067   3141     }
  3068   3142     for(i=0; i<nVector; i++){
  3069   3143       Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
  3070   3144       if( sqlite3ExprCanBeNull(p) ){
  3071   3145         sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
  3072   3146         VdbeCoverage(v);
  3073   3147       }
................................................................................
  3077   3151     ** of the RHS using the LHS as a probe.  If found, the result is
  3078   3152     ** true.
  3079   3153     */
  3080   3154     if( eType==IN_INDEX_ROWID ){
  3081   3155       /* In this case, the RHS is the ROWID of table b-tree and so we also
  3082   3156       ** know that the RHS is non-NULL.  Hence, we combine steps 3 and 4
  3083   3157       ** into a single opcode. */
  3084         -    sqlite3VdbeAddOp3(v, OP_SeekRowid, pExpr->iTable, destIfFalse, rLhs);
         3158  +    sqlite3VdbeAddOp3(v, OP_SeekRowid, iTab, destIfFalse, rLhs);
  3085   3159       VdbeCoverage(v);
  3086   3160       addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto);  /* Return True */
  3087   3161     }else{
  3088   3162       sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
  3089   3163       if( destIfFalse==destIfNull ){
  3090   3164         /* Combine Step 3 and Step 5 into a single opcode */
  3091         -      sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse,
         3165  +      sqlite3VdbeAddOp4Int(v, OP_NotFound, iTab, destIfFalse,
  3092   3166                              rLhs, nVector); VdbeCoverage(v);
  3093   3167         goto sqlite3ExprCodeIN_finished;
  3094   3168       }
  3095   3169       /* Ordinary Step 3, for the case where FALSE and NULL are distinct */
  3096         -    addrTruthOp = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0,
         3170  +    addrTruthOp = sqlite3VdbeAddOp4Int(v, OP_Found, iTab, 0,
  3097   3171                                         rLhs, nVector); VdbeCoverage(v);
  3098   3172     }
  3099   3173   
  3100   3174     /* Step 4.  If the RHS is known to be non-NULL and we did not find
  3101   3175     ** an match on the search above, then the result must be FALSE.
  3102   3176     */
  3103   3177     if( rRhsHasNull && nVector==1 ){
................................................................................
  3114   3188     ** If any comparison is NULL, then the result is NULL.  If all
  3115   3189     ** comparisons are FALSE then the final result is FALSE.
  3116   3190     **
  3117   3191     ** For a scalar LHS, it is sufficient to check just the first row
  3118   3192     ** of the RHS.
  3119   3193     */
  3120   3194     if( destStep6 ) sqlite3VdbeResolveLabel(v, destStep6);
  3121         -  addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
         3195  +  addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, destIfFalse);
  3122   3196     VdbeCoverage(v);
  3123   3197     if( nVector>1 ){
  3124         -    destNotNull = sqlite3VdbeMakeLabel(v);
         3198  +    destNotNull = sqlite3VdbeMakeLabel(pParse);
  3125   3199     }else{
  3126   3200       /* For nVector==1, combine steps 6 and 7 by immediately returning
  3127   3201       ** FALSE if the first comparison is not NULL */
  3128   3202       destNotNull = destIfFalse;
  3129   3203     }
  3130   3204     for(i=0; i<nVector; i++){
  3131   3205       Expr *p;
  3132   3206       CollSeq *pColl;
  3133   3207       int r3 = sqlite3GetTempReg(pParse);
  3134   3208       p = sqlite3VectorFieldSubexpr(pLeft, i);
  3135   3209       pColl = sqlite3ExprCollSeq(pParse, p);
  3136         -    sqlite3VdbeAddOp3(v, OP_Column, pExpr->iTable, i, r3);
         3210  +    sqlite3VdbeAddOp3(v, OP_Column, iTab, i, r3);
  3137   3211       sqlite3VdbeAddOp4(v, OP_Ne, rLhs+i, destNotNull, r3,
  3138   3212                         (void*)pColl, P4_COLLSEQ);
  3139   3213       VdbeCoverage(v);
  3140   3214       sqlite3ReleaseTempReg(pParse, r3);
  3141   3215     }
  3142   3216     sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
  3143   3217     if( nVector>1 ){
  3144   3218       sqlite3VdbeResolveLabel(v, destNotNull);
  3145         -    sqlite3VdbeAddOp2(v, OP_Next, pExpr->iTable, addrTop+1);
         3219  +    sqlite3VdbeAddOp2(v, OP_Next, iTab, addrTop+1);
  3146   3220       VdbeCoverage(v);
  3147   3221   
  3148   3222       /* Step 7:  If we reach this point, we know that the result must
  3149   3223       ** be false. */
  3150   3224       sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
  3151   3225     }
  3152   3226   
................................................................................
  3337   3411       iResult = sqlite3ExprCodeTemp(pParse, p, piFreeable);
  3338   3412     }else{
  3339   3413       *piFreeable = 0;
  3340   3414       if( p->op==TK_SELECT ){
  3341   3415   #if SQLITE_OMIT_SUBQUERY
  3342   3416         iResult = 0;
  3343   3417   #else
  3344         -      iResult = sqlite3CodeSubselect(pParse, p, 0, 0);
         3418  +      iResult = sqlite3CodeSubselect(pParse, p);
  3345   3419   #endif
  3346   3420       }else{
  3347   3421         int i;
  3348   3422         iResult = pParse->nMem+1;
  3349   3423         pParse->nMem += nResult;
  3350   3424         for(i=0; i<nResult; i++){
  3351   3425           sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
................................................................................
  3682   3756         }
  3683   3757   
  3684   3758         /* Attempt a direct implementation of the built-in COALESCE() and
  3685   3759         ** IFNULL() functions.  This avoids unnecessary evaluation of
  3686   3760         ** arguments past the first non-NULL argument.
  3687   3761         */
  3688   3762         if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
  3689         -        int endCoalesce = sqlite3VdbeMakeLabel(v);
         3763  +        int endCoalesce = sqlite3VdbeMakeLabel(pParse);
  3690   3764           assert( nFarg>=2 );
  3691   3765           sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
  3692   3766           for(i=1; i<nFarg; i++){
  3693   3767             sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
  3694   3768             VdbeCoverage(v);
  3695   3769             sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
  3696   3770           }
................................................................................
  3811   3885       case TK_SELECT: {
  3812   3886         int nCol;
  3813   3887         testcase( op==TK_EXISTS );
  3814   3888         testcase( op==TK_SELECT );
  3815   3889         if( op==TK_SELECT && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 ){
  3816   3890           sqlite3SubselectError(pParse, nCol, 1);
  3817   3891         }else{
  3818         -        return sqlite3CodeSubselect(pParse, pExpr, 0, 0);
         3892  +        return sqlite3CodeSubselect(pParse, pExpr);
  3819   3893         }
  3820   3894         break;
  3821   3895       }
  3822   3896       case TK_SELECT_COLUMN: {
  3823   3897         int n;
  3824   3898         if( pExpr->pLeft->iTable==0 ){
  3825         -        pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft, 0, 0);
         3899  +        pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft);
  3826   3900         }
  3827   3901         assert( pExpr->iTable==0 || pExpr->pLeft->op==TK_SELECT );
  3828   3902         if( pExpr->iTable
  3829   3903          && pExpr->iTable!=(n = sqlite3ExprVectorSize(pExpr->pLeft)) 
  3830   3904         ){
  3831   3905           sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
  3832   3906                                   pExpr->iTable, n);
  3833   3907         }
  3834   3908         return pExpr->pLeft->iTable + pExpr->iColumn;
  3835   3909       }
  3836   3910       case TK_IN: {
  3837         -      int destIfFalse = sqlite3VdbeMakeLabel(v);
  3838         -      int destIfNull = sqlite3VdbeMakeLabel(v);
         3911  +      int destIfFalse = sqlite3VdbeMakeLabel(pParse);
         3912  +      int destIfNull = sqlite3VdbeMakeLabel(pParse);
  3839   3913         sqlite3VdbeAddOp2(v, OP_Null, 0, target);
  3840   3914         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
  3841   3915         sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
  3842   3916         sqlite3VdbeResolveLabel(v, destIfFalse);
  3843   3917         sqlite3VdbeAddOp2(v, OP_AddImm, target, 0);
  3844   3918         sqlite3VdbeResolveLabel(v, destIfNull);
  3845   3919         return target;
................................................................................
  3971   4045         Expr *pTest = 0;                  /* X==Ei (form A) or just Ei (form B) */
  3972   4046   
  3973   4047         assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
  3974   4048         assert(pExpr->x.pList->nExpr > 0);
  3975   4049         pEList = pExpr->x.pList;
  3976   4050         aListelem = pEList->a;
  3977   4051         nExpr = pEList->nExpr;
  3978         -      endLabel = sqlite3VdbeMakeLabel(v);
         4052  +      endLabel = sqlite3VdbeMakeLabel(pParse);
  3979   4053         if( (pX = pExpr->pLeft)!=0 ){
  3980   4054           tempX = *pX;
  3981   4055           testcase( pX->op==TK_COLUMN );
  3982   4056           exprToRegister(&tempX, exprCodeVector(pParse, &tempX, &regFree1));
  3983   4057           testcase( regFree1==0 );
  3984   4058           memset(&opCompare, 0, sizeof(opCompare));
  3985   4059           opCompare.op = TK_EQ;
................................................................................
  3994   4068         for(i=0; i<nExpr-1; i=i+2){
  3995   4069           if( pX ){
  3996   4070             assert( pTest!=0 );
  3997   4071             opCompare.pRight = aListelem[i].pExpr;
  3998   4072           }else{
  3999   4073             pTest = aListelem[i].pExpr;
  4000   4074           }
  4001         -        nextCase = sqlite3VdbeMakeLabel(v);
         4075  +        nextCase = sqlite3VdbeMakeLabel(pParse);
  4002   4076           testcase( pTest->op==TK_COLUMN );
  4003   4077           sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
  4004   4078           testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
  4005   4079           sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
  4006   4080           sqlite3VdbeGoto(v, endLabel);
  4007   4081           sqlite3VdbeResolveLabel(v, nextCase);
  4008   4082         }
................................................................................
  4363   4437   
  4364   4438     assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
  4365   4439     if( NEVER(v==0) )     return;  /* Existence of VDBE checked by caller */
  4366   4440     if( NEVER(pExpr==0) ) return;  /* No way this can happen */
  4367   4441     op = pExpr->op;
  4368   4442     switch( op ){
  4369   4443       case TK_AND: {
  4370         -      int d2 = sqlite3VdbeMakeLabel(v);
         4444  +      int d2 = sqlite3VdbeMakeLabel(pParse);
  4371   4445         testcase( jumpIfNull==0 );
  4372   4446         sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
  4373   4447         sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
  4374   4448         sqlite3VdbeResolveLabel(v, d2);
  4375   4449         break;
  4376   4450       }
  4377   4451       case TK_OR: {
................................................................................
  4449   4523       case TK_BETWEEN: {
  4450   4524         testcase( jumpIfNull==0 );
  4451   4525         exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfTrue, jumpIfNull);
  4452   4526         break;
  4453   4527       }
  4454   4528   #ifndef SQLITE_OMIT_SUBQUERY
  4455   4529       case TK_IN: {
  4456         -      int destIfFalse = sqlite3VdbeMakeLabel(v);
         4530  +      int destIfFalse = sqlite3VdbeMakeLabel(pParse);
  4457   4531         int destIfNull = jumpIfNull ? dest : destIfFalse;
  4458   4532         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
  4459   4533         sqlite3VdbeGoto(v, dest);
  4460   4534         sqlite3VdbeResolveLabel(v, destIfFalse);
  4461   4535         break;
  4462   4536       }
  4463   4537   #endif
................................................................................
  4536   4610       case TK_AND: {
  4537   4611         testcase( jumpIfNull==0 );
  4538   4612         sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
  4539   4613         sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
  4540   4614         break;
  4541   4615       }
  4542   4616       case TK_OR: {
  4543         -      int d2 = sqlite3VdbeMakeLabel(v);
         4617  +      int d2 = sqlite3VdbeMakeLabel(pParse);
  4544   4618         testcase( jumpIfNull==0 );
  4545   4619         sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
  4546   4620         sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
  4547   4621         sqlite3VdbeResolveLabel(v, d2);
  4548   4622         break;
  4549   4623       }
  4550   4624       case TK_NOT: {
................................................................................
  4620   4694         break;
  4621   4695       }
  4622   4696   #ifndef SQLITE_OMIT_SUBQUERY
  4623   4697       case TK_IN: {
  4624   4698         if( jumpIfNull ){
  4625   4699           sqlite3ExprCodeIN(pParse, pExpr, dest, dest);
  4626   4700         }else{
  4627         -        int destIfNull = sqlite3VdbeMakeLabel(v);
         4701  +        int destIfNull = sqlite3VdbeMakeLabel(pParse);
  4628   4702           sqlite3ExprCodeIN(pParse, pExpr, dest, destIfNull);
  4629   4703           sqlite3VdbeResolveLabel(v, destIfNull);
  4630   4704         }
  4631   4705         break;
  4632   4706       }
  4633   4707   #endif
  4634   4708       default: {
................................................................................
  4741   4815     combinedFlags = pA->flags | pB->flags;
  4742   4816     if( combinedFlags & EP_IntValue ){
  4743   4817       if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
  4744   4818         return 0;
  4745   4819       }
  4746   4820       return 2;
  4747   4821     }
  4748         -  if( pA->op!=pB->op ){
         4822  +  if( pA->op!=pB->op || pA->op==TK_RAISE ){
  4749   4823       if( pA->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA->pLeft,pB,iTab)<2 ){
  4750   4824         return 1;
  4751   4825       }
  4752   4826       if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){
  4753   4827         return 1;
  4754   4828       }
  4755   4829       return 2;

Changes to src/fkey.c.

   325    325     int regData,          /* Address of array containing child table row */
   326    326     int nIncr,            /* Increment constraint counter by this */
   327    327     int isIgnore          /* If true, pretend pTab contains all NULL values */
   328    328   ){
   329    329     int i;                                    /* Iterator variable */
   330    330     Vdbe *v = sqlite3GetVdbe(pParse);         /* Vdbe to add code to */
   331    331     int iCur = pParse->nTab - 1;              /* Cursor number to use */
   332         -  int iOk = sqlite3VdbeMakeLabel(v);        /* jump here if parent key found */
          332  +  int iOk = sqlite3VdbeMakeLabel(pParse);   /* jump here if parent key found */
   333    333   
   334    334     sqlite3VdbeVerifyAbortable(v,
   335    335       (!pFKey->isDeferred
   336    336         && !(pParse->db->flags & SQLITE_DeferFKs)
   337    337         && !pParse->pToplevel 
   338    338         && !pParse->isMultiWrite) ? OE_Abort : OE_Ignore);
   339    339   
................................................................................
   598    598     ** to the WHERE clause that prevent this entry from being scanned.
   599    599     ** The added WHERE clause terms are like this:
   600    600     **
   601    601     **     $current_rowid!=rowid
   602    602     **     NOT( $current_a==a AND $current_b==b AND ... )
   603    603     **
   604    604     ** The first form is used for rowid tables.  The second form is used
   605         -  ** for WITHOUT ROWID tables.  In the second form, the primary key is
   606         -  ** (a,b,...)
          605  +  ** for WITHOUT ROWID tables. In the second form, the *parent* key is
          606  +  ** (a,b,...). Either the parent or primary key could be used to 
          607  +  ** uniquely identify the current row, but the parent key is more convenient
          608  +  ** as the required values have already been loaded into registers
          609  +  ** by the caller.
   607    610     */
   608    611     if( pTab==pFKey->pFrom && nIncr>0 ){
   609    612       Expr *pNe;                    /* Expression (pLeft != pRight) */
   610    613       Expr *pLeft;                  /* Value from parent table row */
   611    614       Expr *pRight;                 /* Column ref to child table */
   612    615       if( HasRowid(pTab) ){
   613    616         pLeft = exprTableRegister(pParse, pTab, regData, -1);
   614    617         pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
   615    618         pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight);
   616    619       }else{
   617    620         Expr *pEq, *pAll = 0;
   618         -      Index *pPk = sqlite3PrimaryKeyIndex(pTab);
   619    621         assert( pIdx!=0 );
   620         -      for(i=0; i<pPk->nKeyCol; i++){
          622  +      for(i=0; i<pIdx->nKeyCol; i++){
   621    623           i16 iCol = pIdx->aiColumn[i];
   622    624           assert( iCol>=0 );
   623    625           pLeft = exprTableRegister(pParse, pTab, regData, iCol);
   624         -        pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
   625         -        pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
          626  +        pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName);
          627  +        pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight);
   626    628           pAll = sqlite3ExprAnd(db, pAll, pEq);
   627    629         }
   628    630         pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
   629    631       }
   630    632       pWhere = sqlite3ExprAnd(db, pWhere, pNe);
   631    633     }
   632    634   
................................................................................
   723    725         ** the entire DELETE if there are no outstanding deferred constraints
   724    726         ** when this statement is run.  */
   725    727         FKey *p;
   726    728         for(p=pTab->pFKey; p; p=p->pNextFrom){
   727    729           if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
   728    730         }
   729    731         if( !p ) return;
   730         -      iSkip = sqlite3VdbeMakeLabel(v);
          732  +      iSkip = sqlite3VdbeMakeLabel(pParse);
   731    733         sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
   732    734       }
   733    735   
   734    736       pParse->disableTriggers = 1;
   735    737       sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
   736    738       pParse->disableTriggers = 0;
   737    739   

Changes to src/insert.c.

   862    862       */
   863    863       addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
   864    864       VdbeCoverage(v);
   865    865     }
   866    866   
   867    867     /* Run the BEFORE and INSTEAD OF triggers, if there are any
   868    868     */
   869         -  endOfLoop = sqlite3VdbeMakeLabel(v);
          869  +  endOfLoop = sqlite3VdbeMakeLabel(pParse);
   870    870     if( tmask & TRIGGER_BEFORE ){
   871    871       int regCols = sqlite3GetTempRange(pParse, pTab->nCol+1);
   872    872   
   873    873       /* build the NEW.* reference row.  Note that if there is an INTEGER
   874    874       ** PRIMARY KEY into which a NULL is being inserted, that NULL will be
   875    875       ** translated into a unique ID for the row.  But on a BEFORE trigger,
   876    876       ** we do not know what the unique ID will be (because the insert has
................................................................................
  1348   1348         onError = OE_Abort;
  1349   1349       }
  1350   1350       if( onError==OE_Replace && pTab->aCol[i].pDflt==0 ){
  1351   1351         onError = OE_Abort;
  1352   1352       }
  1353   1353       assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
  1354   1354           || onError==OE_Ignore || onError==OE_Replace );
         1355  +    addr1 = 0;
  1355   1356       switch( onError ){
         1357  +      case OE_Replace: {
         1358  +        assert( onError==OE_Replace );
         1359  +        addr1 = sqlite3VdbeMakeLabel(pParse);
         1360  +        sqlite3VdbeAddOp2(v, OP_NotNull, regNewData+1+i, addr1);
         1361  +          VdbeCoverage(v);
         1362  +        sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
         1363  +        sqlite3VdbeAddOp2(v, OP_NotNull, regNewData+1+i, addr1);
         1364  +          VdbeCoverage(v);
         1365  +        onError = OE_Abort;
         1366  +        /* Fall through into the OE_Abort case to generate code that runs
         1367  +        ** if both the input and the default value are NULL */
         1368  +      }
  1356   1369         case OE_Abort:
  1357   1370           sqlite3MayAbort(pParse);
  1358   1371           /* Fall through */
  1359   1372         case OE_Rollback:
  1360   1373         case OE_Fail: {
  1361   1374           char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
  1362   1375                                       pTab->aCol[i].zName);
  1363   1376           sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
  1364   1377                             regNewData+1+i);
  1365   1378           sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
  1366   1379           sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
  1367   1380           VdbeCoverage(v);
  1368         -        break;
  1369         -      }
  1370         -      case OE_Ignore: {
  1371         -        sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
  1372         -        VdbeCoverage(v);
         1381  +        if( addr1 ) sqlite3VdbeResolveLabel(v, addr1);
  1373   1382           break;
  1374   1383         }
  1375   1384         default: {
  1376         -        assert( onError==OE_Replace );
  1377         -        addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i);
  1378         -           VdbeCoverage(v);
  1379         -        sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
  1380         -        sqlite3VdbeJumpHere(v, addr1);
         1385  +        assert( onError==OE_Ignore );
         1386  +        sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
         1387  +        VdbeCoverage(v);
  1381   1388           break;
  1382   1389         }
  1383   1390       }
  1384   1391     }
  1385   1392   
  1386   1393     /* Test all CHECK constraints
  1387   1394     */
................................................................................
  1396   1403         if( aiChng
  1397   1404          && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng)
  1398   1405         ){
  1399   1406           /* The check constraints do not reference any of the columns being
  1400   1407           ** updated so there is no point it verifying the check constraint */
  1401   1408           continue;
  1402   1409         }
  1403         -      allOk = sqlite3VdbeMakeLabel(v);
         1410  +      allOk = sqlite3VdbeMakeLabel(pParse);
  1404   1411         sqlite3VdbeVerifyAbortable(v, onError);
  1405   1412         sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL);
  1406   1413         if( onError==OE_Ignore ){
  1407   1414           sqlite3VdbeGoto(v, ignoreDest);
  1408   1415         }else{
  1409   1416           char *zName = pCheck->a[i].zName;
  1410   1417           if( zName==0 ) zName = pTab->zName;
................................................................................
  1463   1470       }
  1464   1471     }
  1465   1472   
  1466   1473     /* If rowid is changing, make sure the new rowid does not previously
  1467   1474     ** exist in the table.
  1468   1475     */
  1469   1476     if( pkChng && pPk==0 ){
  1470         -    int addrRowidOk = sqlite3VdbeMakeLabel(v);
         1477  +    int addrRowidOk = sqlite3VdbeMakeLabel(pParse);
  1471   1478   
  1472   1479       /* Figure out what action to take in case of a rowid collision */
  1473   1480       onError = pTab->keyConf;
  1474   1481       if( overrideError!=OE_Default ){
  1475   1482         onError = overrideError;
  1476   1483       }else if( onError==OE_Default ){
  1477   1484         onError = OE_Abort;
................................................................................
  1613   1620       if( aRegIdx[ix]==0 ) continue;  /* Skip indices that do not change */
  1614   1621       if( pUpIdx==pIdx ){
  1615   1622         addrUniqueOk = upsertJump+1;
  1616   1623         upsertBypass = sqlite3VdbeGoto(v, 0);
  1617   1624         VdbeComment((v, "Skip upsert subroutine"));
  1618   1625         sqlite3VdbeJumpHere(v, upsertJump);
  1619   1626       }else{
  1620         -      addrUniqueOk = sqlite3VdbeMakeLabel(v);
         1627  +      addrUniqueOk = sqlite3VdbeMakeLabel(pParse);
  1621   1628       }
  1622   1629       if( bAffinityDone==0 && (pUpIdx==0 || pUpIdx==pIdx) ){
  1623   1630         sqlite3TableAffinity(v, pTab, regNewData+1);
  1624   1631         bAffinityDone = 1;
  1625   1632       }
  1626   1633       VdbeNoopComment((v, "uniqueness check for %s", pIdx->zName));
  1627   1634       iThisCur = iIdxCur+ix;

Changes to src/os_unix.c.

  4355   4355   
  4356   4356     /* Access to the unixShmNode object is serialized by the caller */
  4357   4357     pShmNode = pFile->pInode->pShmNode;
  4358   4358     assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->pShmMutex) );
  4359   4359     assert( pShmNode->nRef>0 || unixMutexHeld() );
  4360   4360   
  4361   4361     /* Shared locks never span more than one byte */
  4362         -  /* assert( n==1 || lockType!=F_RDLCK ); */
         4362  +  assert( n==1 || lockType!=F_RDLCK );
  4363   4363   
  4364   4364     /* Locks are within range */
  4365   4365     assert( n>=1 && n<=SQLITE_SHM_NLOCK );
  4366   4366   
  4367   4367     if( pShmNode->hShm>=0 ){
  4368   4368       /* Initialize the locking parameters */
  4369   4369       f.l_type = lockType;
................................................................................
  4852   4852       { 3+2*SQLITE_MFS_NSHARD, SQLITE_MFS_NSHARD },
  4853   4853       { 3+3*SQLITE_MFS_NSHARD, SQLITE_MFS_NSHARD },
  4854   4854       { 3+4*SQLITE_MFS_NSHARD, SQLITE_MFS_NSHARD },
  4855   4855       { 3+5*SQLITE_MFS_NSHARD, 0 },
  4856   4856     };
  4857   4857   
  4858   4858     unixShm *p = pFd->pShm;               /* The shared memory being locked */
  4859         -  unixShm *pX;                          /* For looping over all siblings */
  4860   4859     unixShmNode *pShmNode = p->pShmNode;  /* The underlying file iNode */
  4861         -  int rc = SQLITE_OK;
  4862         -  int iIncr;
  4863         -  u16 mask;                             /* Mask of locks to take or release */
  4864   4860   
  4865   4861     if( flags & SQLITE_SHM_SHARED ){
  4866   4862       /* SHARED locks */
  4867   4863       u32 iOld, iNew, *ptr;
  4868   4864       int iIncr = -1;
  4869   4865       if( (flags & SQLITE_SHM_UNLOCK)==0 ){
  4870   4866         p->aMFCurrent[ofst] = (p->aMFCurrent[ofst] + 1) % aMap[ofst].nSlot;
................................................................................
  4876   4872         iNew = iOld + iIncr;
  4877   4873         if( iNew>SQLITE_MFS_EXCLUSIVE ){
  4878   4874           return SQLITE_BUSY;
  4879   4875         }
  4880   4876       }while( 0==unixCompareAndSwap(ptr, iOld, iNew) );
  4881   4877     }else{
  4882   4878       /* EXCLUSIVE locks */
  4883         -    int iFirst = aMap[ofst].iFirst;
  4884         -    int iLast = aMap[ofst+n].iFirst;
  4885         -    int i;
  4886         -    for(i=iFirst; i<iLast; i++){
  4887         -      u32 *ptr = &pShmNode->aMFSlot[i].nLock;
  4888         -      if( flags & SQLITE_SHM_UNLOCK ){
  4889         -        assert( (*ptr)==SQLITE_MFS_EXCLUSIVE );
  4890         -        *ptr = 0;
  4891         -      }else{
  4892         -        u32 iOld;
  4893         -        do {
  4894         -          iOld = *ptr;
  4895         -          if( iOld>0 ){
  4896         -            while( i>iFirst ){
  4897         -              i--;
  4898         -              pShmNode->aMFSlot[i].nLock = 0;
         4879  +    u16 mask = (1<<(ofst+n)) - (1<<ofst);
         4880  +    if( (flags & SQLITE_SHM_LOCK) || (mask & p->exclMask) ){
         4881  +      int iFirst = aMap[ofst].iFirst;
         4882  +      int iLast = aMap[ofst+n].iFirst;
         4883  +      int i;
         4884  +      for(i=iFirst; i<iLast; i++){
         4885  +        u32 *ptr = &pShmNode->aMFSlot[i].nLock;
         4886  +        if( flags & SQLITE_SHM_UNLOCK ){
         4887  +          assert( (*ptr)==SQLITE_MFS_EXCLUSIVE );
         4888  +          *ptr = 0;
         4889  +        }else{
         4890  +          u32 iOld;
         4891  +          do {
         4892  +            iOld = *ptr;
         4893  +            if( iOld>0 ){
         4894  +              while( i>iFirst ){
         4895  +                i--;
         4896  +                pShmNode->aMFSlot[i].nLock = 0;
         4897  +              }
         4898  +              return SQLITE_BUSY;
  4899   4899               }
  4900         -            return SQLITE_BUSY;
  4901         -          }
  4902         -        }while( 0==unixCompareAndSwap(ptr, iOld, SQLITE_MFS_EXCLUSIVE) );
         4900  +          }while( 0==unixCompareAndSwap(ptr, iOld, SQLITE_MFS_EXCLUSIVE) );
         4901  +        }
         4902  +      }
         4903  +      if( flags & SQLITE_SHM_UNLOCK ){
         4904  +        p->exclMask &= ~mask;
         4905  +      }else{
         4906  +        p->exclMask |= mask;
  4903   4907         }
  4904   4908       }
  4905   4909     }
  4906   4910   
  4907   4911     return SQLITE_OK;
  4908   4912   }
  4909   4913   #else
................................................................................
  4935   4939     assert( pShmNode->pInode==pDbFd->pInode );
  4936   4940     assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
  4937   4941     assert( n>=1 );
  4938   4942     assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
  4939   4943          || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
  4940   4944          || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
  4941   4945          || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
  4942         -  /* assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); */
         4946  +  assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
  4943   4947     assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
  4944   4948     assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
  4945   4949   
  4946   4950     if( pDbFd->pInode->bProcessLock ){
  4947   4951       return unixMutexFreeShmlock(pDbFd, ofst, n, flags);
  4948   4952     }
  4949   4953   
................................................................................
  4950   4954     mask = (1<<(ofst+n)) - (1<<ofst);
  4951   4955     assert( n>1 || mask==(1<<ofst) );
  4952   4956     if( flags & SQLITE_SHM_LOCK ){
  4953   4957       assert( !(flags&SQLITE_SHM_SHARED) || (p->sharedMask&mask)==0 );
  4954   4958       assert( !(flags&SQLITE_SHM_EXCLUSIVE) || !(p->exclMask&mask) );
  4955   4959     }else{
  4956   4960       assert( !(flags&SQLITE_SHM_SHARED) || (p->sharedMask&mask)==mask );
  4957         -    assert( !(flags&SQLITE_SHM_EXCLUSIVE) || (p->exclMask&mask)==mask );
         4961  +    /* assert( !(flags&SQLITE_SHM_EXCLUSIVE) || (p->exclMask&mask)==mask ); */
  4958   4962     }
  4959   4963   
  4960   4964     sqlite3_mutex_enter(pShmNode->pShmMutex);
  4961   4965     if( flags & SQLITE_SHM_UNLOCK ){
  4962   4966       u16 allMask = 0; /* Mask of locks held by siblings */
  4963   4967   
  4964   4968       /* See if any siblings hold this same lock */

Changes to src/pager.c.

  3199   3199     ** been written (but not committed) to the log file, do one of the 
  3200   3200     ** following:
  3201   3201     **
  3202   3202     **   + Discard the cached page (if refcount==0), or
  3203   3203     **   + Reload page content from the database (if refcount>0).
  3204   3204     */
  3205   3205     pPager->dbSize = pPager->dbOrigSize;
  3206         -  rc = sqlite3WalUndo(pPager->pWal, pagerUndoCallback, (void *)pPager);
         3206  +  rc = sqlite3WalUndo(pPager->pWal, pagerUndoCallback, (void *)pPager, 
         3207  +#ifdef SQLITE_OMIT_CONCURRENT
         3208  +      0
         3209  +#else
         3210  +      pPager->pAllRead!=0
         3211  +#endif
         3212  +  );
  3207   3213     pList = sqlite3PcacheDirtyList(pPager->pPCache);
  3208   3214   
  3209   3215   #ifndef SQLITE_OMIT_CONCURRENT
  3210   3216     /* If this is an CONCURRENT transaction, then page 1 must be reread from 
  3211   3217     ** the db file, even if it is not dirty. This is because the b-tree layer 
  3212   3218     ** may have already zeroed the nFree and iTrunk header fields.  */
  3213   3219     if( rc==SQLITE_OK && (pList==0 || pList->pgno!=1) && pPager->pAllRead ){

Changes to src/pragma.c.

  1373   1373           pParent = sqlite3FindTable(db, pFK->zTo, zDb);
  1374   1374           pIdx = 0;
  1375   1375           aiCols = 0;
  1376   1376           if( pParent ){
  1377   1377             x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
  1378   1378             assert( x==0 );
  1379   1379           }
  1380         -        addrOk = sqlite3VdbeMakeLabel(v);
         1380  +        addrOk = sqlite3VdbeMakeLabel(pParse);
  1381   1381   
  1382   1382           /* Generate code to read the child key values into registers
  1383   1383           ** regRow..regRow+n. If any of the child key values are NULL, this 
  1384   1384           ** row cannot cause an FK violation. Jump directly to addrOk in 
  1385   1385           ** this case. */
  1386   1386           for(j=0; j<pFK->nCol; j++){
  1387   1387             int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
................................................................................
  1593   1593             integrityCheckResultRow(v);
  1594   1594             sqlite3VdbeJumpHere(v, jmp2);
  1595   1595           }
  1596   1596           /* Verify CHECK constraints */
  1597   1597           if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
  1598   1598             ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
  1599   1599             if( db->mallocFailed==0 ){
  1600         -            int addrCkFault = sqlite3VdbeMakeLabel(v);
  1601         -            int addrCkOk = sqlite3VdbeMakeLabel(v);
         1600  +            int addrCkFault = sqlite3VdbeMakeLabel(pParse);
         1601  +            int addrCkOk = sqlite3VdbeMakeLabel(pParse);
  1602   1602               char *zErr;
  1603   1603               int k;
  1604   1604               pParse->iSelfTab = iDataCur + 1;
  1605   1605               for(k=pCheck->nExpr-1; k>0; k--){
  1606   1606                 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
  1607   1607               }
  1608   1608               sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
................................................................................
  1617   1617             }
  1618   1618             sqlite3ExprListDelete(db, pCheck);
  1619   1619           }
  1620   1620           if( !isQuick ){ /* Omit the remaining tests for quick_check */
  1621   1621             /* Validate index entries for the current row */
  1622   1622             for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
  1623   1623               int jmp2, jmp3, jmp4, jmp5;
  1624         -            int ckUniq = sqlite3VdbeMakeLabel(v);
         1624  +            int ckUniq = sqlite3VdbeMakeLabel(pParse);
  1625   1625               if( pPk==pIdx ) continue;
  1626   1626               r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
  1627   1627                                            pPrior, r1);
  1628   1628               pPrior = pIdx;
  1629   1629               sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */
  1630   1630               /* Verify that an index entry exists for the current table row */
  1631   1631               jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
................................................................................
  1638   1638               sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
  1639   1639               jmp4 = integrityCheckResultRow(v);
  1640   1640               sqlite3VdbeJumpHere(v, jmp2);
  1641   1641               /* For UNIQUE indexes, verify that only one entry exists with the
  1642   1642               ** current key.  The entry is unique if (1) any column is NULL
  1643   1643               ** or (2) the next entry has a different key */
  1644   1644               if( IsUniqueIndex(pIdx) ){
  1645         -              int uniqOk = sqlite3VdbeMakeLabel(v);
         1645  +              int uniqOk = sqlite3VdbeMakeLabel(pParse);
  1646   1646                 int jmp6;
  1647   1647                 int kk;
  1648   1648                 for(kk=0; kk<pIdx->nKeyCol; kk++){
  1649   1649                   int iCol = pIdx->aiColumn[kk];
  1650   1650                   assert( iCol!=XN_ROWID && iCol<pTab->nCol );
  1651   1651                   if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
  1652   1652                   sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);

Changes to src/prepare.c.

   541    541     /* For a long-term use prepared statement avoid the use of
   542    542     ** lookaside memory.
   543    543     */
   544    544     if( prepFlags & SQLITE_PREPARE_PERSISTENT ){
   545    545       sParse.disableLookaside++;
   546    546       db->lookaside.bDisable++;
   547    547     }
          548  +  sParse.disableVtab = (prepFlags & SQLITE_PREPARE_NO_VTAB)!=0;
   548    549   
   549    550     /* Check to verify that it is possible to get a read lock on all
   550    551     ** database schemas.  The inability to get a read lock indicates that
   551    552     ** some other database connection is holding a write-lock, which in
   552    553     ** turn means that the other connection has made uncommitted changes
   553    554     ** to the schema.
   554    555     **

Changes to src/resolve.c.

  1658   1658     w.xSelectCallback2 = 0;
  1659   1659     w.pParse = pParse;
  1660   1660     w.u.pNC = pOuterNC;
  1661   1661     sqlite3WalkSelect(&w, p);
  1662   1662   }
  1663   1663   
  1664   1664   /*
  1665         -** Resolve names in expressions that can only reference a single table:
         1665  +** Resolve names in expressions that can only reference a single table
         1666  +** or which cannot reference any tables at all.  Examples:
  1666   1667   **
  1667         -**    *   CHECK constraints
  1668         -**    *   WHERE clauses on partial indices
         1668  +**    (1)   CHECK constraints
         1669  +**    (2)   WHERE clauses on partial indices
         1670  +**    (3)   Expressions in indexes on expressions
         1671  +**    (4)   Expression arguments to VACUUM INTO.
  1669   1672   **
  1670         -** The Expr.iTable value for Expr.op==TK_COLUMN nodes of the expression
  1671         -** is set to -1 and the Expr.iColumn value is set to the column number.
         1673  +** In all cases except (4), the Expr.iTable value for Expr.op==TK_COLUMN
         1674  +** nodes of the expression is set to -1 and the Expr.iColumn value is
         1675  +** set to the column number.  In case (4), TK_COLUMN nodes cause an error.
  1672   1676   **
  1673   1677   ** Any errors cause an error message to be set in pParse.
  1674   1678   */
  1675         -void sqlite3ResolveSelfReference(
         1679  +int sqlite3ResolveSelfReference(
  1676   1680     Parse *pParse,      /* Parsing context */
  1677         -  Table *pTab,        /* The table being referenced */
  1678         -  int type,           /* NC_IsCheck or NC_PartIdx or NC_IdxExpr */
         1681  +  Table *pTab,        /* The table being referenced, or NULL */
         1682  +  int type,           /* NC_IsCheck or NC_PartIdx or NC_IdxExpr, or 0 */
  1679   1683     Expr *pExpr,        /* Expression to resolve.  May be NULL. */
  1680   1684     ExprList *pList     /* Expression list to resolve.  May be NULL. */
  1681   1685   ){
  1682   1686     SrcList sSrc;                   /* Fake SrcList for pParse->pNewTable */
  1683   1687     NameContext sNC;                /* Name context for pParse->pNewTable */
         1688  +  int rc;
  1684   1689   
  1685         -  assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr );
         1690  +  assert( type==0 || pTab!=0 );
         1691  +  assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr || pTab==0 );
  1686   1692     memset(&sNC, 0, sizeof(sNC));
  1687   1693     memset(&sSrc, 0, sizeof(sSrc));
  1688         -  sSrc.nSrc = 1;
  1689         -  sSrc.a[0].zName = pTab->zName;
  1690         -  sSrc.a[0].pTab = pTab;
  1691         -  sSrc.a[0].iCursor = -1;
         1694  +  if( pTab ){
         1695  +    sSrc.nSrc = 1;
         1696  +    sSrc.a[0].zName = pTab->zName;
         1697  +    sSrc.a[0].pTab = pTab;
         1698  +    sSrc.a[0].iCursor = -1;
         1699  +  }
  1692   1700     sNC.pParse = pParse;
  1693   1701     sNC.pSrcList = &sSrc;
  1694   1702     sNC.ncFlags = type;
  1695         -  if( sqlite3ResolveExprNames(&sNC, pExpr) ) return;
  1696         -  if( pList ) sqlite3ResolveExprListNames(&sNC, pList);
         1703  +  if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
         1704  +  if( pList ) rc = sqlite3ResolveExprListNames(&sNC, pList);
         1705  +  return rc;
  1697   1706   }

Changes to src/select.c.

   627    627       regBase = regData - nPrefixReg;
   628    628     }else{
   629    629       regBase = pParse->nMem + 1;
   630    630       pParse->nMem += nBase;
   631    631     }
   632    632     assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
   633    633     iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
   634         -  pSort->labelDone = sqlite3VdbeMakeLabel(v);
          634  +  pSort->labelDone = sqlite3VdbeMakeLabel(pParse);
   635    635     sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
   636    636                             SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
   637    637     if( bSeq ){
   638    638       sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
   639    639     }
   640    640     if( nPrefixReg==0 && nData>0 ){
   641    641       sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
................................................................................
   666    666       memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */
   667    667       sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
   668    668       testcase( pKI->nAllField > pKI->nKeyField+2 );
   669    669       pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
   670    670                                              pKI->nAllField-pKI->nKeyField-1);
   671    671       addrJmp = sqlite3VdbeCurrentAddr(v);
   672    672       sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
   673         -    pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
          673  +    pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
   674    674       pSort->regReturn = ++pParse->nMem;
   675    675       sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
   676    676       sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor);
   677    677       if( iLimit ){
   678    678         sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, pSort->labelDone);
   679    679         VdbeCoverage(v);
   680    680       }
................................................................................
  1413   1413     Select *p,        /* The SELECT statement */
  1414   1414     SortCtx *pSort,   /* Information on the ORDER BY clause */
  1415   1415     int nColumn,      /* Number of columns of data */
  1416   1416     SelectDest *pDest /* Write the sorted results here */
  1417   1417   ){
  1418   1418     Vdbe *v = pParse->pVdbe;                     /* The prepared statement */
  1419   1419     int addrBreak = pSort->labelDone;            /* Jump here to exit loop */
  1420         -  int addrContinue = sqlite3VdbeMakeLabel(v);  /* Jump here for next cycle */
         1420  +  int addrContinue = sqlite3VdbeMakeLabel(pParse);/* Jump here for next cycle */
  1421   1421     int addr;                       /* Top of output loop. Jump for Next. */
  1422   1422     int addrOnce = 0;
  1423   1423     int iTab;
  1424   1424     ExprList *pOrderBy = pSort->pOrderBy;
  1425   1425     int eDest = pDest->eDest;
  1426   1426     int iParm = pDest->iSDParm;
  1427   1427     int regRow;
................................................................................
  2325   2325     }
  2326   2326   #endif
  2327   2327   
  2328   2328     /* Obtain authorization to do a recursive query */
  2329   2329     if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
  2330   2330   
  2331   2331     /* Process the LIMIT and OFFSET clauses, if they exist */
  2332         -  addrBreak = sqlite3VdbeMakeLabel(v);
         2332  +  addrBreak = sqlite3VdbeMakeLabel(pParse);
  2333   2333     p->nSelectRow = 320;  /* 4 billion rows */
  2334   2334     computeLimitRegisters(pParse, p, addrBreak);
  2335   2335     pLimit = p->pLimit;
  2336   2336     regLimit = p->iLimit;
  2337   2337     regOffset = p->iOffset;
  2338   2338     p->pLimit = 0;
  2339   2339     p->iLimit = p->iOffset = 0;
................................................................................
  2395   2395       sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
  2396   2396     }else{
  2397   2397       sqlite3VdbeAddOp2(v, OP_RowData, iQueue, regCurrent);
  2398   2398     }
  2399   2399     sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
  2400   2400   
  2401   2401     /* Output the single row in Current */
  2402         -  addrCont = sqlite3VdbeMakeLabel(v);
         2402  +  addrCont = sqlite3VdbeMakeLabel(pParse);
  2403   2403     codeOffset(v, regOffset, addrCont);
  2404   2404     selectInnerLoop(pParse, p, iCurrent,
  2405   2405         0, 0, pDest, addrCont, addrBreak);
  2406   2406     if( regLimit ){
  2407   2407       sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
  2408   2408       VdbeCoverage(v);
  2409   2409     }
................................................................................
  2703   2703           /* Convert the data in the temporary table into whatever form
  2704   2704           ** it is that we currently need.
  2705   2705           */
  2706   2706           assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
  2707   2707           if( dest.eDest!=priorOp ){
  2708   2708             int iCont, iBreak, iStart;
  2709   2709             assert( p->pEList );
  2710         -          iBreak = sqlite3VdbeMakeLabel(v);
  2711         -          iCont = sqlite3VdbeMakeLabel(v);
         2710  +          iBreak = sqlite3VdbeMakeLabel(pParse);
         2711  +          iCont = sqlite3VdbeMakeLabel(pParse);
  2712   2712             computeLimitRegisters(pParse, p, iBreak);
  2713   2713             sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
  2714   2714             iStart = sqlite3VdbeCurrentAddr(v);
  2715   2715             selectInnerLoop(pParse, p, unionTab,
  2716   2716                             0, 0, &dest, iCont, iBreak);
  2717   2717             sqlite3VdbeResolveLabel(v, iCont);
  2718   2718             sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
................................................................................
  2772   2772           sqlite3ExprDelete(db, p->pLimit);
  2773   2773           p->pLimit = pLimit;
  2774   2774     
  2775   2775           /* Generate code to take the intersection of the two temporary
  2776   2776           ** tables.
  2777   2777           */
  2778   2778           assert( p->pEList );
  2779         -        iBreak = sqlite3VdbeMakeLabel(v);
  2780         -        iCont = sqlite3VdbeMakeLabel(v);
         2779  +        iBreak = sqlite3VdbeMakeLabel(pParse);
         2780  +        iCont = sqlite3VdbeMakeLabel(pParse);
  2781   2781           computeLimitRegisters(pParse, p, iBreak);
  2782   2782           sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
  2783   2783           r1 = sqlite3GetTempReg(pParse);
  2784   2784           iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
  2785   2785           sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
  2786   2786           VdbeCoverage(v);
  2787   2787           sqlite3ReleaseTempReg(pParse, r1);
................................................................................
  2903   2903     int iBreak              /* Jump here if we hit the LIMIT */
  2904   2904   ){
  2905   2905     Vdbe *v = pParse->pVdbe;
  2906   2906     int iContinue;
  2907   2907     int addr;
  2908   2908   
  2909   2909     addr = sqlite3VdbeCurrentAddr(v);
  2910         -  iContinue = sqlite3VdbeMakeLabel(v);
         2910  +  iContinue = sqlite3VdbeMakeLabel(pParse);
  2911   2911   
  2912   2912     /* Suppress duplicates for UNION, EXCEPT, and INTERSECT 
  2913   2913     */
  2914   2914     if( regPrev ){
  2915   2915       int addr1, addr2;
  2916   2916       addr1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
  2917   2917       addr2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
................................................................................
  3140   3140     int *aPermute;        /* Mapping from ORDER BY terms to result set columns */
  3141   3141   
  3142   3142     assert( p->pOrderBy!=0 );
  3143   3143     assert( pKeyDup==0 ); /* "Managed" code needs this.  Ticket #3382. */
  3144   3144     db = pParse->db;
  3145   3145     v = pParse->pVdbe;
  3146   3146     assert( v!=0 );       /* Already thrown the error if VDBE alloc failed */
  3147         -  labelEnd = sqlite3VdbeMakeLabel(v);
  3148         -  labelCmpr = sqlite3VdbeMakeLabel(v);
         3147  +  labelEnd = sqlite3VdbeMakeLabel(pParse);
         3148  +  labelCmpr = sqlite3VdbeMakeLabel(pParse);
  3149   3149   
  3150   3150   
  3151   3151     /* Patch up the ORDER BY clause
  3152   3152     */
  3153   3153     op = p->op;  
  3154   3154     pPrior = p->pPrior;
  3155   3155     assert( pPrior->pOrderBy==0 );
................................................................................
  5326   5326         regAgg = sqlite3GetTempRange(pParse, nArg);
  5327   5327         sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
  5328   5328       }else{
  5329   5329         nArg = 0;
  5330   5330         regAgg = 0;
  5331   5331       }
  5332   5332       if( pF->iDistinct>=0 ){
  5333         -      addrNext = sqlite3VdbeMakeLabel(v);
         5333  +      addrNext = sqlite3VdbeMakeLabel(pParse);
  5334   5334         testcase( nArg==0 );  /* Error condition */
  5335   5335         testcase( nArg>1 );   /* Also an error */
  5336   5336         codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
  5337   5337       }
  5338   5338       if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
  5339   5339         CollSeq *pColl = 0;
  5340   5340         struct ExprList_item *pItem;
................................................................................
  5462   5462   */
  5463   5463   static struct SrcList_item *isSelfJoinView(
  5464   5464     SrcList *pTabList,           /* Search for self-joins in this FROM clause */
  5465   5465     struct SrcList_item *pThis   /* Search for prior reference to this subquery */
  5466   5466   ){
  5467   5467     struct SrcList_item *pItem;
  5468   5468     for(pItem = pTabList->a; pItem<pThis; pItem++){
         5469  +    Select *pS1;
  5469   5470       if( pItem->pSelect==0 ) continue;
  5470   5471       if( pItem->fg.viaCoroutine ) continue;
  5471   5472       if( pItem->zName==0 ) continue;
  5472   5473       if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
  5473   5474       if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
  5474         -    if( sqlite3ExprCompare(0, 
  5475         -          pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1) 
  5476         -    ){
         5475  +    pS1 = pItem->pSelect;
         5476  +    if( pThis->pSelect->selId!=pS1->selId ){
         5477  +      /* The query flattener left two different CTE tables with identical
         5478  +      ** names in the same FROM clause. */
         5479  +      continue;
         5480  +    }
         5481  +    if( sqlite3ExprCompare(0, pThis->pSelect->pWhere, pS1->pWhere, -1) ){
  5477   5482         /* The view was modified by some other optimization such as
  5478   5483         ** pushDownWhereTerms() */
  5479   5484         continue;
  5480   5485       }
  5481   5486       return pItem;
  5482   5487     }
  5483   5488     return 0;
................................................................................
  5826   5831   
  5827   5832   #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
  5828   5833       /* Generate code for all sub-queries in the FROM clause
  5829   5834       */
  5830   5835       pSub = pItem->pSelect;
  5831   5836       if( pSub==0 ) continue;
  5832   5837   
  5833         -    /* Sometimes the code for a subquery will be generated more than
  5834         -    ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
  5835         -    ** for example.  In that case, do not regenerate the code to manifest
  5836         -    ** a view or the co-routine to implement a view.  The first instance
  5837         -    ** is sufficient, though the subroutine to manifest the view does need
  5838         -    ** to be invoked again. */
  5839         -    if( pItem->addrFillSub ){
  5840         -      if( pItem->fg.viaCoroutine==0 ){
  5841         -        /* The subroutine that manifests the view might be a one-time routine,
  5842         -        ** or it might need to be rerun on each iteration because it
  5843         -        ** encodes a correlated subquery. */
  5844         -        testcase( sqlite3VdbeGetOp(v, pItem->addrFillSub)->opcode==OP_Once );
  5845         -        sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
  5846         -      }
  5847         -      continue;
  5848         -    }
         5838  +    /* The code for a subquery should only be generated once, though it is
         5839  +    ** technically harmless for it to be generated multiple times. The
         5840  +    ** following assert() will detect if something changes to cause
         5841  +    ** the same subquery to be coded multiple times, as a signal to the
         5842  +    ** developers to try to optimize the situation. */
         5843  +    assert( pItem->addrFillSub==0 );
  5849   5844   
  5850   5845       /* Increment Parse.nHeight by the height of the largest expression
  5851   5846       ** tree referred to by this, the parent select. The child select
  5852   5847       ** may contain expression trees of at most
  5853   5848       ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit
  5854   5849       ** more conservative than necessary, but much easier than enforcing
  5855   5850       ** an exact limit.
................................................................................
  6029   6024     */
  6030   6025     if( pDest->eDest==SRT_EphemTab ){
  6031   6026       sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
  6032   6027     }
  6033   6028   
  6034   6029     /* Set the limiter.
  6035   6030     */
  6036         -  iEnd = sqlite3VdbeMakeLabel(v);
         6031  +  iEnd = sqlite3VdbeMakeLabel(pParse);
  6037   6032     if( (p->selFlags & SF_FixedLimit)==0 ){
  6038   6033       p->nSelectRow = 320;  /* 4 billion rows */
  6039   6034     }
  6040   6035     computeLimitRegisters(pParse, p, iEnd);
  6041   6036     if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
  6042   6037       sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
  6043   6038       sSort.sortFlags |= SORTFLAG_UseSorter;
................................................................................
  6096   6091       if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
  6097   6092         sqlite3VdbeChangeToNoop(v, sSort.addrSortIndex);
  6098   6093       }
  6099   6094   
  6100   6095       assert( p->pEList==pEList );
  6101   6096   #ifndef SQLITE_OMIT_WINDOWFUNC
  6102   6097       if( pWin ){
  6103         -      int addrGosub = sqlite3VdbeMakeLabel(v);
  6104         -      int iCont = sqlite3VdbeMakeLabel(v);
  6105         -      int iBreak = sqlite3VdbeMakeLabel(v);
         6098  +      int addrGosub = sqlite3VdbeMakeLabel(pParse);
         6099  +      int iCont = sqlite3VdbeMakeLabel(pParse);
         6100  +      int iBreak = sqlite3VdbeMakeLabel(pParse);
  6106   6101         int regGosub = ++pParse->nMem;
  6107   6102   
  6108   6103         sqlite3WindowCodeStep(pParse, p, pWInfo, regGosub, addrGosub);
  6109   6104   
  6110   6105         sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
  6111   6106         sqlite3VdbeResolveLabel(v, addrGosub);
  6112   6107         VdbeNoopComment((v, "inner-loop subroutine"));
................................................................................
  6173   6168       ** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
  6174   6169       ** variable.  */
  6175   6170       if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
  6176   6171         orderByGrp = 1;
  6177   6172       }
  6178   6173    
  6179   6174       /* Create a label to jump to when we want to abort the query */
  6180         -    addrEnd = sqlite3VdbeMakeLabel(v);
         6175  +    addrEnd = sqlite3VdbeMakeLabel(pParse);
  6181   6176   
  6182   6177       /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
  6183   6178       ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
  6184   6179       ** SELECT statement.
  6185   6180       */
  6186   6181       memset(&sNC, 0, sizeof(sNC));
  6187   6182       sNC.pParse = pParse;
................................................................................
  6262   6257             0, (char*)pKeyInfo, P4_KEYINFO);
  6263   6258   
  6264   6259         /* Initialize memory locations used by GROUP BY aggregate processing
  6265   6260         */
  6266   6261         iUseFlag = ++pParse->nMem;
  6267   6262         iAbortFlag = ++pParse->nMem;
  6268   6263         regOutputRow = ++pParse->nMem;
  6269         -      addrOutputRow = sqlite3VdbeMakeLabel(v);
         6264  +      addrOutputRow = sqlite3VdbeMakeLabel(pParse);
  6270   6265         regReset = ++pParse->nMem;
  6271         -      addrReset = sqlite3VdbeMakeLabel(v);
         6266  +      addrReset = sqlite3VdbeMakeLabel(pParse);
  6272   6267         iAMem = pParse->nMem + 1;
  6273   6268         pParse->nMem += pGroupBy->nExpr;
  6274   6269         iBMem = pParse->nMem + 1;
  6275   6270         pParse->nMem += pGroupBy->nExpr;
  6276   6271         sqlite3VdbeAddOp2(v, OP_Integer, 0, iAbortFlag);
  6277   6272         VdbeComment((v, "clear abort flag"));
  6278   6273         sqlite3VdbeAddOp3(v, OP_Null, 0, iAMem, iAMem+pGroupBy->nExpr-1);

Changes to src/sqlite.h.in.

  3632   3632   ** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>
  3633   3633   ** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used
  3634   3634   ** to be required for any prepared statement that wanted to use the
  3635   3635   ** [sqlite3_normalized_sql()] interface.  However, the
  3636   3636   ** [sqlite3_normalized_sql()] interface is now available to all
  3637   3637   ** prepared statements, regardless of whether or not they use this
  3638   3638   ** flag.
         3639  +**
         3640  +** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>
         3641  +** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
         3642  +** to return an error (error code SQLITE_ERROR) if the statement uses
         3643  +** any virtual tables.
  3639   3644   ** </dl>
  3640   3645   */
  3641   3646   #define SQLITE_PREPARE_PERSISTENT              0x01
  3642   3647   #define SQLITE_PREPARE_NORMALIZE               0x02
         3648  +#define SQLITE_PREPARE_NO_VTAB                 0x04
  3643   3649   
  3644   3650   /*
  3645   3651   ** CAPI3REF: Compiling An SQL Statement
  3646   3652   ** KEYWORDS: {SQL statement compiler}
  3647   3653   ** METHOD: sqlite3
  3648   3654   ** CONSTRUCTOR: sqlite3_stmt
  3649   3655   **

Changes to src/sqliteInt.h.

  2493   2493                            ** TK_COLUMN: the value of p5 for OP_Column
  2494   2494                            ** TK_AGG_FUNCTION: nesting depth */
  2495   2495     AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  2496   2496     union {
  2497   2497       Table *pTab;           /* TK_COLUMN: Table containing column. Can be NULL
  2498   2498                              ** for a column of an index on an expression */
  2499   2499       Window *pWin;          /* TK_FUNCTION: Window definition for the func */
         2500  +    struct {               /* TK_IN, TK_SELECT, and TK_EXISTS */
         2501  +      int iAddr;             /* Subroutine entry address */
         2502  +      int regReturn;         /* Register used to hold return address */
         2503  +    } sub;
  2500   2504     } y;
  2501   2505   };
  2502   2506   
  2503   2507   /*
  2504   2508   ** The following are the meanings of bits in the Expr.flags field.
  2505   2509   */
  2506   2510   #define EP_FromJoin  0x000001 /* Originates in ON/USING clause of outer join */
................................................................................
  2524   2528   #define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */
  2525   2529   #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
  2526   2530   #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
  2527   2531   #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
  2528   2532   #define EP_Alias     0x400000 /* Is an alias for a result set column */
  2529   2533   #define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
  2530   2534   #define EP_WinFunc  0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
         2535  +#define EP_Subrtn   0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
  2531   2536   
  2532   2537   /*
  2533   2538   ** The EP_Propagate mask is a set of properties that automatically propagate
  2534   2539   ** upwards into parent nodes.
  2535   2540   */
  2536   2541   #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
  2537   2542   
................................................................................
  3067   3072     u8 nested;           /* Number of nested calls to the parser/code generator */
  3068   3073     u8 nTempReg;         /* Number of temporary registers in aTempReg[] */
  3069   3074     u8 isMultiWrite;     /* True if statement may modify/insert multiple rows */
  3070   3075     u8 mayAbort;         /* True if statement may throw an ABORT exception */
  3071   3076     u8 hasCompound;      /* Need to invoke convertCompoundSelectToSubquery() */
  3072   3077     u8 okConstFactor;    /* OK to factor out constants */
  3073   3078     u8 disableLookaside; /* Number of times lookaside has been disabled */
         3079  +  u8 disableVtab;      /* Disable all virtual tables for this parse */
  3074   3080     int nRangeReg;       /* Size of the temporary register block */
  3075   3081     int iRangeReg;       /* First register in temporary register block */
  3076   3082     int nErr;            /* Number of errors seen */
  3077   3083     int nTab;            /* Number of previously allocated VDBE cursors */
  3078   3084     int nMem;            /* Number of memory cells used so far */
  3079         -  int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
  3080   3085     int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  3081   3086     int iSelfTab;        /* Table associated with an index on expr, or negative
  3082   3087                          ** of the base register during check-constraint eval */
  3083         -  int nLabel;          /* Number of labels used */
         3088  +  int nLabel;          /* The *negative* of the number of labels used */
         3089  +  int nLabelAlloc;     /* Number of slots in aLabel */
  3084   3090     int *aLabel;         /* Space to hold the labels */
  3085   3091     ExprList *pConstExpr;/* Constant expressions */
  3086   3092     Token constraintName;/* Name of the constraint currently being parsed */
  3087   3093     yDbMask writeMask;   /* Start a write transaction on these databases */
  3088   3094     yDbMask cookieMask;  /* Bitmask of schema verified databases */
  3089   3095     int regRowid;        /* Register holding rowid of CREATE TABLE entry */
  3090   3096     int regRoot;         /* Register holding root page number for new objects */
................................................................................
  4267   4273   void sqlite3Reindex(Parse*, Token*, Token*);
  4268   4274   void sqlite3AlterFunctions(void);
  4269   4275   void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
  4270   4276   void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
  4271   4277   int sqlite3GetToken(const unsigned char *, int *);
  4272   4278   void sqlite3NestedParse(Parse*, const char*, ...);
  4273   4279   void sqlite3ExpirePreparedStatements(sqlite3*, int);
  4274         -int sqlite3CodeSubselect(Parse*, Expr *, int, int);
         4280  +void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
         4281  +int sqlite3CodeSubselect(Parse*, Expr*);
  4275   4282   void sqlite3SelectPrep(Parse*, Select*, NameContext*);
  4276   4283   void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
  4277   4284   int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
  4278   4285   int sqlite3ResolveExprNames(NameContext*, Expr*);
  4279   4286   int sqlite3ResolveExprListNames(NameContext*, ExprList*);
  4280   4287   void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
  4281         -void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
         4288  +int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
  4282   4289   int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
  4283   4290   void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  4284   4291   void sqlite3AlterFinishAddColumn(Parse *, Token *);
  4285   4292   void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  4286   4293   void *sqlite3RenameTokenMap(Parse*, void*, Token*);
  4287   4294   void sqlite3RenameTokenRemap(Parse*, void *pTo, void *pFrom);
  4288   4295   void sqlite3RenameExprUnmap(Parse*, Expr*);
................................................................................
  4519   4526   #define IN_INDEX_NOOP         5   /* No table available. Use comparisons */
  4520   4527   /*
  4521   4528   ** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
  4522   4529   */
  4523   4530   #define IN_INDEX_NOOP_OK     0x0001  /* OK to return IN_INDEX_NOOP */
  4524   4531   #define IN_INDEX_MEMBERSHIP  0x0002  /* IN operator used for membership test */
  4525   4532   #define IN_INDEX_LOOP        0x0004  /* IN operator used as a loop */
  4526         -int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
         4533  +int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*);
  4527   4534   
  4528   4535   int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
  4529   4536   int sqlite3JournalSize(sqlite3_vfs *);
  4530   4537   #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
  4531   4538    || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
  4532   4539     int sqlite3JournalCreate(sqlite3_file *);
  4533   4540   #endif

Changes to src/test_vfs.c.

   224    224   };
   225    225   
   226    226   static int tvfsResultCode(Testvfs *p, int *pRc){
   227    227     struct errcode {
   228    228       int eCode;
   229    229       const char *zCode;
   230    230     } aCode[] = {
   231         -    { SQLITE_OK,     "SQLITE_OK"     },
   232         -    { SQLITE_ERROR,  "SQLITE_ERROR"  },
   233         -    { SQLITE_IOERR,  "SQLITE_IOERR"  },
   234         -    { SQLITE_LOCKED, "SQLITE_LOCKED" },
   235         -    { SQLITE_BUSY,   "SQLITE_BUSY"   },
          231  +    { SQLITE_OK,       "SQLITE_OK"     },
          232  +    { SQLITE_ERROR,    "SQLITE_ERROR"  },
          233  +    { SQLITE_IOERR,    "SQLITE_IOERR"  },
          234  +    { SQLITE_LOCKED,   "SQLITE_LOCKED" },
          235  +    { SQLITE_BUSY,     "SQLITE_BUSY"   },
          236  +    { SQLITE_READONLY, "SQLITE_READONLY"   },
          237  +    { SQLITE_READONLY_CANTINIT, "SQLITE_READONLY_CANTINIT"   },
   236    238     };
   237    239   
   238    240     const char *z;
   239    241     int i;
   240    242   
   241    243     z = Tcl_GetStringResult(p->interp);
   242    244     for(i=0; i<ArraySize(aCode); i++){
................................................................................
   861    863       p->pBuffer = pBuffer;
   862    864     }
   863    865   
   864    866     /* Connect the TestvfsBuffer to the new TestvfsShm handle and return. */
   865    867     pFd->pNext = pBuffer->pFile;
   866    868     pBuffer->pFile = pFd;
   867    869     pFd->pShm = pBuffer;
   868         -  return SQLITE_OK;
          870  +  return rc;
   869    871   }
   870    872   
   871    873   static void tvfsAllocPage(TestvfsBuffer *p, int iPage, int pgsz){
   872    874     assert( iPage<TESTVFS_MAX_PAGES );
   873    875     if( p->aPage[iPage]==0 ){
   874    876       p->aPage[iPage] = (u8 *)ckalloc(pgsz);
   875    877       memset(p->aPage[iPage], 0, pgsz);
................................................................................
   914    916     if( rc==SQLITE_OK && p->mask&TESTVFS_SHMMAP_MASK && tvfsInjectIoerr(p) ){
   915    917       rc = SQLITE_IOERR;
   916    918     }
   917    919   
   918    920     if( rc==SQLITE_OK && isWrite && !pFd->pShm->aPage[iPage] ){
   919    921       tvfsAllocPage(pFd->pShm, iPage, pgsz);
   920    922     }
   921         -  *pp = (void volatile *)pFd->pShm->aPage[iPage];
          923  +  if( rc==SQLITE_OK || rc==SQLITE_READONLY ){
          924  +    *pp = (void volatile *)pFd->pShm->aPage[iPage];
          925  +  }
   922    926   
   923    927     return rc;
   924    928   }
   925    929   
   926    930   
   927    931   static int tvfsShmLock(
   928    932     sqlite3_file *pFile,
................................................................................
  1611   1615         (iArg1==0 ? SQLITE_SHM_SHARED : SQLITE_SHM_EXCLUSIVE)
  1612   1616       | (iArg2==0 ? SQLITE_SHM_LOCK : SQLITE_SHM_UNLOCK)
  1613   1617     );
  1614   1618     Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
  1615   1619     return TCL_OK;
  1616   1620   }
  1617   1621   
         1622  +static int SQLITE_TCLAPI test_vfs_set_readmark(
         1623  +  void * clientData,
         1624  +  Tcl_Interp *interp,
         1625  +  int objc,
         1626  +  Tcl_Obj *CONST objv[]
         1627  +){
         1628  +  sqlite3 *db = 0;
         1629  +  int rc = SQLITE_OK;
         1630  +  const char *zDbname = 0;
         1631  +  int iSlot = 0;
         1632  +  int iVal = -1;
         1633  +  sqlite3_file *pFd;
         1634  +  void volatile *pShm = 0;
         1635  +  u32 *aShm;
         1636  +  int iOff;
         1637  +
         1638  +  if( objc!=4 && objc!=5 ){
         1639  +    Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SLOT ?VALUE?");
         1640  +    return TCL_ERROR;
         1641  +  }
         1642  +
         1643  +  zDbname = Tcl_GetString(objv[2]);
         1644  +  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) 
         1645  +   || Tcl_GetIntFromObj(interp, objv[3], &iSlot)
         1646  +   || (objc==5 && Tcl_GetIntFromObj(interp, objv[4], &iVal))
         1647  +  ){
         1648  +    return TCL_ERROR;
         1649  +  }
         1650  +
         1651  +  sqlite3_file_control(db, zDbname, SQLITE_FCNTL_FILE_POINTER, (void*)&pFd);
         1652  +  if( pFd==0 ){
         1653  +    return TCL_ERROR;
         1654  +  }
         1655  +  rc = pFd->pMethods->xShmMap(pFd, 0, 32*1024, 0, &pShm);
         1656  +  if( rc!=SQLITE_OK ){
         1657  +    Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
         1658  +    return TCL_ERROR;
         1659  +  }
         1660  +  if( pShm==0 ){
         1661  +    Tcl_AppendResult(interp, "*-shm is not yet mapped", 0);
         1662  +    return TCL_ERROR;
         1663  +  }
         1664  +  aShm = (u32*)pShm;
         1665  +  iOff = 12*2+1+iSlot;
         1666  +
         1667  +  if( objc==5 ){
         1668  +    aShm[iOff] = iVal;
         1669  +  }
         1670  +  Tcl_SetObjResult(interp, Tcl_NewIntObj(aShm[iOff]));
         1671  +
         1672  +  return TCL_OK;
         1673  +}
  1618   1674   
  1619   1675   int Sqlitetestvfs_Init(Tcl_Interp *interp){
  1620   1676     Tcl_CreateObjCommand(interp, "testvfs", testvfs_cmd, 0, 0);
  1621   1677     Tcl_CreateObjCommand(interp, "vfs_shmlock", test_vfs_shmlock, 0, 0);
         1678  +  Tcl_CreateObjCommand(interp, "vfs_set_readmark", test_vfs_set_readmark, 0, 0);
  1622   1679     return TCL_OK;
  1623   1680   }
  1624   1681   
  1625   1682   #endif

Changes to src/treeview.c.

   134    134       sqlite3_str_appendf(&x, "{%d,*}", pItem->iCursor);
   135    135       if( pItem->zDatabase ){
   136    136         sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
   137    137       }else if( pItem->zName ){
   138    138         sqlite3_str_appendf(&x, " %s", pItem->zName);
   139    139       }
   140    140       if( pItem->pTab ){
   141         -      sqlite3_str_appendf(&x, " tabname=%Q", pItem->pTab->zName);
          141  +      sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p",
          142  +           pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab);
   142    143       }
   143    144       if( pItem->zAlias ){
   144    145         sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
   145    146       }
   146    147       if( pItem->fg.jointype & JT_LEFT ){
   147    148         sqlite3_str_appendf(&x, " LEFT-JOIN");
   148    149       }

Changes to src/trigger.c.

   912    912     sNC.pParse = pSubParse;
   913    913     pSubParse->db = db;
   914    914     pSubParse->pTriggerTab = pTab;
   915    915     pSubParse->pToplevel = pTop;
   916    916     pSubParse->zAuthContext = pTrigger->zName;
   917    917     pSubParse->eTriggerOp = pTrigger->op;
   918    918     pSubParse->nQueryLoop = pParse->nQueryLoop;
          919  +  pSubParse->disableVtab = pParse->disableVtab;
   919    920   
   920    921     v = sqlite3GetVdbe(pSubParse);
   921    922     if( v ){
   922    923       VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)", 
   923    924         pTrigger->zName, onErrorText(orconf),
   924    925         (pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"),
   925    926           (pTrigger->op==TK_UPDATE ? "UPDATE" : ""),
................................................................................
   939    940       ** (or NULL) the sub-vdbe is immediately halted by jumping to the 
   940    941       ** OP_Halt inserted at the end of the program.  */
   941    942       if( pTrigger->pWhen ){
   942    943         pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
   943    944         if( SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen) 
   944    945          && db->mallocFailed==0 
   945    946         ){
   946         -        iEndTrigger = sqlite3VdbeMakeLabel(v);
          947  +        iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
   947    948           sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
   948    949         }
   949    950         sqlite3ExprDelete(db, pWhen);
   950    951       }
   951    952   
   952    953       /* Code the trigger program into the sub-vdbe. */
   953    954       codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);

Changes to src/update.c.

   448    448       updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
   449    449                          pWhere, onError);
   450    450       goto update_cleanup;
   451    451     }
   452    452   #endif
   453    453   
   454    454     /* Jump to labelBreak to abandon further processing of this UPDATE */
   455         -  labelContinue = labelBreak = sqlite3VdbeMakeLabel(v);
          455  +  labelContinue = labelBreak = sqlite3VdbeMakeLabel(pParse);
   456    456   
   457    457     /* Not an UPSERT.  Normal processing.  Begin by
   458    458     ** initialize the count of updated rows */
   459    459     if( (db->flags&SQLITE_CountRows)!=0
   460    460      && !pParse->pTriggerTab
   461    461      && !pParse->nested
   462    462      && pUpsert==0
................................................................................
   583    583       if( eOnePass!=ONEPASS_OFF ){
   584    584         if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
   585    585           assert( pPk );
   586    586           sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey);
   587    587           VdbeCoverage(v);
   588    588         }
   589    589         if( eOnePass!=ONEPASS_SINGLE ){
   590         -        labelContinue = sqlite3VdbeMakeLabel(v);
          590  +        labelContinue = sqlite3VdbeMakeLabel(pParse);
   591    591         }
   592    592         sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
   593    593         VdbeCoverageIf(v, pPk==0);
   594    594         VdbeCoverageIf(v, pPk!=0);
   595    595       }else if( pPk ){
   596         -      labelContinue = sqlite3VdbeMakeLabel(v);
          596  +      labelContinue = sqlite3VdbeMakeLabel(pParse);
   597    597         sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
   598    598         addrTop = sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
   599    599         sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
   600    600         VdbeCoverage(v);
   601    601       }else{
   602    602         labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet,labelBreak,
   603    603                                  regOldRowid);

Changes to src/vacuum.c.

   120    120       ** legacy applications. */
   121    121       iDb = sqlite3FindDb(pParse->db, pNm);
   122    122       if( iDb<0 ) iDb = 0;
   123    123   #endif
   124    124     }
   125    125     if( iDb!=1 ){
   126    126       int iIntoReg = 0;
   127         -    if( pInto ){
          127  +    if( pInto && sqlite3ResolveSelfReference(pParse,0,0,pInto,0)==0 ){
   128    128         iIntoReg = ++pParse->nMem;
   129    129         sqlite3ExprCode(pParse, pInto, iIntoReg);
   130    130       }
   131    131       sqlite3VdbeAddOp2(v, OP_Vacuum, iDb, iIntoReg);
   132    132       sqlite3VdbeUsesBtree(v, iDb);
   133    133     }
   134    134   build_vacuum_end:

Changes to src/vdbe.c.

   236    236     VdbeCursor *pCx = 0;
   237    237     nByte = 
   238    238         ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + 
   239    239         (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
   240    240   
   241    241     assert( iCur>=0 && iCur<p->nCursor );
   242    242     if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
          243  +    /* Before calling sqlite3VdbeFreeCursor(), ensure the isEphemeral flag
          244  +    ** is clear. Otherwise, if this is an ephemeral cursor created by 
          245  +    ** OP_OpenDup, the cursor will not be closed and will still be part
          246  +    ** of a BtShared.pCursor list.  */
          247  +    p->apCsr[iCur]->isEphemeral = 0;
   243    248       sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
   244    249       p->apCsr[iCur] = 0;
   245    250     }
   246    251     if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
   247    252       p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
   248    253       memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
   249    254       pCx->eCurType = eCurType;
................................................................................
  1921   1926       if( pOp->p5 & SQLITE_NULLEQ ){
  1922   1927         /* If SQLITE_NULLEQ is set (which will only happen if the operator is
  1923   1928         ** OP_Eq or OP_Ne) then take the jump or not depending on whether
  1924   1929         ** or not both operands are null.
  1925   1930         */
  1926   1931         assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
  1927   1932         assert( (flags1 & MEM_Cleared)==0 );
  1928         -      assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 );
         1933  +      assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
         1934  +      testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
  1929   1935         if( (flags1&flags3&MEM_Null)!=0
  1930   1936          && (flags3&MEM_Cleared)==0
  1931   1937         ){
  1932   1938           res = 0;  /* Operands are equal */
  1933   1939         }else{
  1934   1940           res = 1;  /* Operands are not equal */
  1935   1941         }
................................................................................
  3636   3642   
  3637   3643     pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
  3638   3644     if( pCx==0 ) goto no_mem;
  3639   3645     pCx->nullRow = 1;
  3640   3646     pCx->isEphemeral = 1;
  3641   3647     pCx->pKeyInfo = pOrig->pKeyInfo;
  3642   3648     pCx->isTable = pOrig->isTable;
  3643         -  rc = sqlite3BtreeCursor(pOrig->pBtx, MASTER_ROOT, BTREE_WRCSR,
         3649  +  pCx->pgnoRoot = pOrig->pgnoRoot;
         3650  +  rc = sqlite3BtreeCursor(pOrig->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
  3644   3651                             pCx->pKeyInfo, pCx->uc.pCursor);
  3645   3652     /* The sqlite3BtreeCursor() routine can only fail for the first cursor
  3646   3653     ** opened for a database.  Since there is already an open cursor when this
  3647   3654     ** opcode is run, the sqlite3BtreeCursor() cannot fail */
  3648   3655     assert( rc==SQLITE_OK );
  3649   3656     break;
  3650   3657   }
................................................................................
  3653   3660   /* Opcode: OpenEphemeral P1 P2 * P4 P5
  3654   3661   ** Synopsis: nColumn=P2
  3655   3662   **
  3656   3663   ** Open a new cursor P1 to a transient table.
  3657   3664   ** The cursor is always opened read/write even if 
  3658   3665   ** the main database is read-only.  The ephemeral
  3659   3666   ** table is deleted automatically when the cursor is closed.
         3667  +**
         3668  +** If the cursor P1 is already opened on an ephermal table, the table
         3669  +** is cleared (all content is erased).
  3660   3670   **
  3661   3671   ** P2 is the number of columns in the ephemeral table.
  3662   3672   ** The cursor points to a BTree table if P4==0 and to a BTree index
  3663   3673   ** if P4 is not 0.  If P4 is not NULL, it points to a KeyInfo structure
  3664   3674   ** that defines the format of keys in the index.
  3665   3675   **
  3666   3676   ** The P5 parameter can be a mask of the BTREE_* flags defined
................................................................................
  3685   3695         SQLITE_OPEN_READWRITE |
  3686   3696         SQLITE_OPEN_CREATE |
  3687   3697         SQLITE_OPEN_EXCLUSIVE |
  3688   3698         SQLITE_OPEN_DELETEONCLOSE |
  3689   3699         SQLITE_OPEN_TRANSIENT_DB;
  3690   3700     assert( pOp->p1>=0 );
  3691   3701     assert( pOp->p2>=0 );
  3692         -  pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
  3693         -  if( pCx==0 ) goto no_mem;
  3694         -  pCx->nullRow = 1;
  3695         -  pCx->isEphemeral = 1;
  3696         -  rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, 
  3697         -                        BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
  3698         -  if( rc==SQLITE_OK ){
  3699         -    rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
  3700         -  }
  3701         -  if( rc==SQLITE_OK ){
  3702         -    /* If a transient index is required, create it by calling
  3703         -    ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
  3704         -    ** opening it. If a transient table is required, just use the
  3705         -    ** automatically created table with root-page 1 (an BLOB_INTKEY table).
  3706         -    */
  3707         -    if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
  3708         -      int pgno;
  3709         -      assert( pOp->p4type==P4_KEYINFO );
  3710         -      rc = sqlite3BtreeCreateTable(pCx->pBtx, &pgno, BTREE_BLOBKEY | pOp->p5); 
  3711         -      if( rc==SQLITE_OK ){
  3712         -        assert( pgno==MASTER_ROOT+1 );
  3713         -        assert( pKeyInfo->db==db );
  3714         -        assert( pKeyInfo->enc==ENC(db) );
  3715         -        rc = sqlite3BtreeCursor(pCx->pBtx, pgno, BTREE_WRCSR,
  3716         -                                pKeyInfo, pCx->uc.pCursor);
  3717         -      }
  3718         -      pCx->isTable = 0;
  3719         -    }else{
  3720         -      rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
  3721         -                              0, pCx->uc.pCursor);
  3722         -      pCx->isTable = 1;
  3723         -    }
  3724         -  }
  3725         -  if( rc ) goto abort_due_to_error;
  3726         -  pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
         3702  +  pCx = p->apCsr[pOp->p1];
         3703  +  if( pCx ){
         3704  +    /* If the ephermeral table is already open, erase all existing content
         3705  +    ** so that the table is empty again, rather than creating a new table. */
         3706  +    rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
         3707  +  }else{
         3708  +    pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
         3709  +    if( pCx==0 ) goto no_mem;
         3710  +    pCx->nullRow = 1;
         3711  +    pCx->isEphemeral = 1;
         3712  +    rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, 
         3713  +                          BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5,
         3714  +                          vfsFlags);
         3715  +    if( rc==SQLITE_OK ){
         3716  +      rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
         3717  +    }
         3718  +    if( rc==SQLITE_OK ){
         3719  +      /* If a transient index is required, create it by calling
         3720  +      ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
         3721  +      ** opening it. If a transient table is required, just use the
         3722  +      ** automatically created table with root-page 1 (an BLOB_INTKEY table).
         3723  +      */
         3724  +      if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
         3725  +        assert( pOp->p4type==P4_KEYINFO );
         3726  +        rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot,
         3727  +                                     BTREE_BLOBKEY | pOp->p5); 
         3728  +        if( rc==SQLITE_OK ){
         3729  +          assert( pCx->pgnoRoot==MASTER_ROOT+1 );
         3730  +          assert( pKeyInfo->db==db );
         3731  +          assert( pKeyInfo->enc==ENC(db) );
         3732  +          rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
         3733  +                                  pKeyInfo, pCx->uc.pCursor);
         3734  +        }
         3735  +        pCx->isTable = 0;
         3736  +      }else{
         3737  +        pCx->pgnoRoot = MASTER_ROOT;
         3738  +        rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
         3739  +                                0, pCx->uc.pCursor);
         3740  +        pCx->isTable = 1;
         3741  +      }
         3742  +    }
         3743  +    pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
         3744  +  }
         3745  +  if( rc ) goto abort_due_to_error;
  3727   3746     break;
  3728   3747   }
  3729   3748   
  3730   3749   /* Opcode: SorterOpen P1 P2 P3 P4 *
  3731   3750   **
  3732   3751   ** This opcode works like OP_OpenEphemeral except that it opens
  3733   3752   ** a transient index that is specifically designed to sort large
................................................................................
  4369   4388   case OP_NotExists:          /* jump, in3 */
  4370   4389     pIn3 = &aMem[pOp->p3];
  4371   4390     assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
  4372   4391     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  4373   4392     pC = p->apCsr[pOp->p1];
  4374   4393     assert( pC!=0 );
  4375   4394   #ifdef SQLITE_DEBUG
  4376         -  pC->seekOp = OP_SeekRowid;
         4395  +  if( pOp->opcode==OP_SeekRowid ) pC->seekOp = OP_SeekRowid;
  4377   4396   #endif
  4378   4397     assert( pC->isTable );
  4379   4398     assert( pC->eCurType==CURTYPE_BTREE );
  4380   4399     pCrsr = pC->uc.pCursor;
  4381   4400     assert( pCrsr!=0 );
  4382   4401     res = 0;
  4383   4402     iKey = pIn3->u.i;
................................................................................
  5277   5296     assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
  5278   5297   
  5279   5298     /* The Next opcode is only used after SeekGT, SeekGE, Rewind, and Found.
  5280   5299     ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */
  5281   5300     assert( pOp->opcode!=OP_Next
  5282   5301          || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
  5283   5302          || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found 
  5284         -       || pC->seekOp==OP_NullRow);
         5303  +       || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid);
  5285   5304     assert( pOp->opcode!=OP_Prev
  5286   5305          || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
  5287   5306          || pC->seekOp==OP_Last 
  5288   5307          || pC->seekOp==OP_NullRow);
  5289   5308   
  5290   5309     rc = pOp->p4.xAdvance(pC->uc.pCursor, pOp->p3);
  5291   5310   next_tail:
................................................................................
  6895   6914   ** P4 is the name of a virtual table in database P1.  Call the xDestroy method
  6896   6915   ** of that table.
  6897   6916   */
  6898   6917   case OP_VDestroy: {
  6899   6918     db->nVDestroy++;
  6900   6919     rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
  6901   6920     db->nVDestroy--;
         6921  +  assert( p->errorAction==OE_Abort && p->usesStmtJournal );
  6902   6922     if( rc ) goto abort_due_to_error;
  6903   6923     break;
  6904   6924   }
  6905   6925   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  6906   6926   
  6907   6927   #ifndef SQLITE_OMIT_VIRTUALTABLE
  6908   6928   /* Opcode: VOpen P1 * * P4 *

Changes to src/vdbe.h.

   152    152   #   define COLNAME_N      1      /* Store only the name */
   153    153   # else
   154    154   #   define COLNAME_N      2      /* Store the name and decltype */
   155    155   # endif
   156    156   #endif
   157    157   
   158    158   /*
   159         -** The following macro converts a relative address in the p2 field
   160         -** of a VdbeOp structure into a negative number so that 
   161         -** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
   162         -** the macro again restores the address.
          159  +** The following macro converts a label returned by sqlite3VdbeMakeLabel()
          160  +** into an index into the Parse.aLabel[] array that contains the resolved
          161  +** address of that label.
   163    162   */
   164         -#define ADDR(X)  (-1-(X))
          163  +#define ADDR(X)  (~(X))
   165    164   
   166    165   /*
   167    166   ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
   168    167   ** header file that defines a number for each opcode used by the VDBE.
   169    168   */
   170    169   #include "opcodes.h"
   171    170   
................................................................................
   211    210   # define ExplainQueryPlan(P)        sqlite3VdbeExplain P
   212    211   # define ExplainQueryPlanPop(P)     sqlite3VdbeExplainPop(P)
   213    212   # define ExplainQueryPlanParent(P)  sqlite3VdbeExplainParent(P)
   214    213   #else
   215    214   # define ExplainQueryPlan(P)
   216    215   # define ExplainQueryPlanPop(P)
   217    216   # define ExplainQueryPlanParent(P) 0
          217  +# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
          218  +#endif
          219  +#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_EXPLAIN)
          220  +  void sqlite3ExplainBreakpoint(const char*,const char*);
          221  +#else
          222  +# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
   218    223   #endif
   219    224   void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
   220    225   void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
   221    226   void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
   222    227   void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
   223    228   void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
   224    229   void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
................................................................................
   226    231   int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
   227    232   int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
   228    233   void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
   229    234   void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
   230    235   void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
   231    236   void sqlite3VdbeUsesBtree(Vdbe*, int);
   232    237   VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
   233         -int sqlite3VdbeMakeLabel(Vdbe*);
          238  +int sqlite3VdbeMakeLabel(Parse*);
   234    239   void sqlite3VdbeRunOnlyOnce(Vdbe*);
   235    240   void sqlite3VdbeReusable(Vdbe*);
   236    241   void sqlite3VdbeDelete(Vdbe*);
   237    242   void sqlite3VdbeClearObject(sqlite3*,Vdbe*);
   238    243   void sqlite3VdbeMakeReady(Vdbe*,Parse*);
   239    244   int sqlite3VdbeFinalize(Vdbe*);
   240    245   void sqlite3VdbeResolveLabel(Vdbe*, int);

Changes to src/vdbeInt.h.

   381    381     int rc;                 /* Value to return */
   382    382     int nChange;            /* Number of db changes made since last reset */
   383    383     int iStatement;         /* Statement number (or 0 if has no opened stmt) */
   384    384     i64 iCurrentTime;       /* Value of julianday('now') for this statement */
   385    385     i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
   386    386     i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
   387    387     i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
          388  +  Mem *aMem;              /* The memory locations */
          389  +  Mem **apArg;            /* Arguments to currently executing user function */
          390  +  VdbeCursor **apCsr;     /* One element of this array for each open cursor */
          391  +  Mem *aVar;              /* Values for the OP_Variable opcode. */
   388    392   
   389    393     /* When allocating a new Vdbe object, all of the fields below should be
   390    394     ** initialized to zero or NULL */
   391    395   
   392    396     Op *aOp;                /* Space to hold the virtual machine's program */
   393         -  Mem *aMem;              /* The memory locations */
   394         -  Mem **apArg;            /* Arguments to currently executing user function */
          397  +  int nOp;                /* Number of instructions in the program */
          398  +  int nOpAlloc;           /* Slots allocated for aOp[] */
   395    399     Mem *aColName;          /* Column names to return */
   396    400     Mem *pResultSet;        /* Pointer to an array of results */
   397    401     char *zErrMsg;          /* Error message written here */
   398         -  VdbeCursor **apCsr;     /* One element of this array for each open cursor */
   399         -  Mem *aVar;              /* Values for the OP_Variable opcode. */
   400    402     VList *pVList;          /* Name of variables */
   401    403   #ifndef SQLITE_OMIT_TRACE
   402    404     i64 startTime;          /* Time when query started - used for profiling */
   403    405   #endif
   404         -  int nOp;                /* Number of instructions in the program */
   405    406   #ifdef SQLITE_DEBUG
   406    407     int rcApp;              /* errcode set by sqlite3_result_error_code() */
   407    408     u32 nWrite;             /* Number of write operations that have occurred */
   408    409   #endif
   409    410     u16 nResColumn;         /* Number of columns in one row of the result set */
   410    411     u8 errorAction;         /* Recovery action to do in case of an error */
   411    412     u8 minWriteFileFormat;  /* Minimum file format for writable database files */

Changes to src/vdbeaux.c.

    32     32     p->pPrev = 0;
    33     33     db->pVdbe = p;
    34     34     p->magic = VDBE_MAGIC_INIT;
    35     35     p->pParse = pParse;
    36     36     pParse->pVdbe = p;
    37     37     assert( pParse->aLabel==0 );
    38     38     assert( pParse->nLabel==0 );
    39         -  assert( pParse->nOpAlloc==0 );
           39  +  assert( p->nOpAlloc==0 );
    40     40     assert( pParse->szOpAlloc==0 );
    41     41     sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
    42     42     return p;
    43     43   }
    44     44   
    45     45   /*
    46     46   ** Change the error string stored in Vdbe.zErrMsg
................................................................................
   135    135   
   136    136   /*
   137    137   ** Resize the Vdbe.aOp array so that it is at least nOp elements larger 
   138    138   ** than its current size. nOp is guaranteed to be less than or equal
   139    139   ** to 1024/sizeof(Op).
   140    140   **
   141    141   ** If an out-of-memory error occurs while resizing the array, return
   142         -** SQLITE_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain 
          142  +** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain 
   143    143   ** unchanged (this is so that any opcodes already allocated can be 
   144    144   ** correctly deallocated along with the rest of the Vdbe).
   145    145   */
   146    146   static int growOpArray(Vdbe *v, int nOp){
   147    147     VdbeOp *pNew;
   148    148     Parse *p = v->pParse;
   149    149   
................................................................................
   151    151     ** more frequent reallocs and hence provide more opportunities for 
   152    152     ** simulated OOM faults.  SQLITE_TEST_REALLOC_STRESS is generally used
   153    153     ** during testing only.  With SQLITE_TEST_REALLOC_STRESS grow the op array
   154    154     ** by the minimum* amount required until the size reaches 512.  Normal
   155    155     ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
   156    156     ** size of the op array or add 1KB of space, whichever is smaller. */
   157    157   #ifdef SQLITE_TEST_REALLOC_STRESS
   158         -  int nNew = (p->nOpAlloc>=512 ? p->nOpAlloc*2 : p->nOpAlloc+nOp);
          158  +  int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp);
   159    159   #else
   160         -  int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
          160  +  int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op)));
   161    161     UNUSED_PARAMETER(nOp);
   162    162   #endif
   163    163   
   164    164     /* Ensure that the size of a VDBE does not grow too large */
   165    165     if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
   166    166       sqlite3OomFault(p->db);
   167    167       return SQLITE_NOMEM;
   168    168     }
   169    169   
   170    170     assert( nOp<=(1024/sizeof(Op)) );
   171         -  assert( nNew>=(p->nOpAlloc+nOp) );
          171  +  assert( nNew>=(v->nOpAlloc+nOp) );
   172    172     pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
   173    173     if( pNew ){
   174    174       p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew);
   175         -    p->nOpAlloc = p->szOpAlloc/sizeof(Op);
          175  +    v->nOpAlloc = p->szOpAlloc/sizeof(Op);
   176    176       v->aOp = pNew;
   177    177     }
   178    178     return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
   179    179   }
   180    180   
   181    181   #ifdef SQLITE_DEBUG
   182    182   /* This routine is just a convenient place to set a breakpoint that will
................................................................................
   202    202   **    p1, p2, p3      Operands
   203    203   **
   204    204   ** Use the sqlite3VdbeResolveLabel() function to fix an address and
   205    205   ** the sqlite3VdbeChangeP4() function to change the value of the P4
   206    206   ** operand.
   207    207   */
   208    208   static SQLITE_NOINLINE int growOp3(Vdbe *p, int op, int p1, int p2, int p3){
   209         -  assert( p->pParse->nOpAlloc<=p->nOp );
          209  +  assert( p->nOpAlloc<=p->nOp );
   210    210     if( growOpArray(p, 1) ) return 1;
   211         -  assert( p->pParse->nOpAlloc>p->nOp );
          211  +  assert( p->nOpAlloc>p->nOp );
   212    212     return sqlite3VdbeAddOp3(p, op, p1, p2, p3);
   213    213   }
   214    214   int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
   215    215     int i;
   216    216     VdbeOp *pOp;
   217    217   
   218    218     i = p->nOp;
   219    219     assert( p->magic==VDBE_MAGIC_INIT );
   220    220     assert( op>=0 && op<0xff );
   221         -  if( p->pParse->nOpAlloc<=i ){
          221  +  if( p->nOpAlloc<=i ){
   222    222       return growOp3(p, op, p1, p2, p3);
   223    223     }
   224    224     p->nOp++;
   225    225     pOp = &p->aOp[i];
   226    226     pOp->opcode = (u8)op;
   227    227     pOp->p5 = 0;
   228    228     pOp->p1 = p1;
................................................................................
   346    346     VdbeOp *pOp;
   347    347     if( pParse->addrExplain==0 ) return 0;
   348    348     pOp = sqlite3VdbeGetOp(pParse->pVdbe, pParse->addrExplain);
   349    349     return pOp->p2;
   350    350   }
   351    351   
   352    352   /*
   353         -** Add a new OP_Explain opcode.
          353  +** Set a debugger breakpoint on the following routine in order to
          354  +** monitor the EXPLAIN QUERY PLAN code generation.
          355  +*/
          356  +#if defined(SQLITE_DEBUG)
          357  +void sqlite3ExplainBreakpoint(const char *z1, const char *z2){
          358  +  (void)z1;
          359  +  (void)z2;
          360  +}
          361  +#endif
          362  +
          363  +/*
          364  +** Add a new OP_ opcode.
   354    365   **
   355    366   ** If the bPush flag is true, then make this opcode the parent for
   356    367   ** subsequent Explains until sqlite3VdbeExplainPop() is called.
   357    368   */
   358    369   void sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){
   359         -  if( pParse->explain==2 ){
          370  +#ifndef SQLITE_DEBUG
          371  +  /* Always include the OP_Explain opcodes if SQLITE_DEBUG is defined.
          372  +  ** But omit them (for performance) during production builds */
          373  +  if( pParse->explain==2 )
          374  +#endif
          375  +  {
   360    376       char *zMsg;
   361    377       Vdbe *v;
   362    378       va_list ap;
   363    379       int iThis;
   364    380       va_start(ap, zFmt);
   365    381       zMsg = sqlite3VMPrintf(pParse->db, zFmt, ap);
   366    382       va_end(ap);
   367    383       v = pParse->pVdbe;
   368    384       iThis = v->nOp;
   369    385       sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
   370    386                         zMsg, P4_DYNAMIC);
   371         -    if( bPush) pParse->addrExplain = iThis;
          387  +    sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetOp(v,-1)->p4.z);
          388  +    if( bPush){
          389  +      pParse->addrExplain = iThis;
          390  +    }
   372    391     }
   373    392   }
   374    393   
   375    394   /*
   376    395   ** Pop the EXPLAIN QUERY PLAN stack one level.
   377    396   */
   378    397   void sqlite3VdbeExplainPop(Parse *pParse){
          398  +  sqlite3ExplainBreakpoint("POP", 0);
   379    399     pParse->addrExplain = sqlite3VdbeExplainParent(pParse);
   380    400   }
   381    401   #endif /* SQLITE_OMIT_EXPLAIN */
   382    402   
   383    403   /*
   384    404   ** Add an OP_ParseSchema opcode.  This routine is broken out from
   385    405   ** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees
................................................................................
   436    456   ** the label is resolved to a specific address, the VDBE will scan
   437    457   ** through its operation list and change all values of P2 which match
   438    458   ** the label into the resolved address.
   439    459   **
   440    460   ** The VDBE knows that a P2 value is a label because labels are
   441    461   ** always negative and P2 values are suppose to be non-negative.
   442    462   ** Hence, a negative P2 value is a label that has yet to be resolved.
          463  +** (Later:) This is only true for opcodes that have the OPFLG_JUMP
          464  +** property.
   443    465   **
   444         -** Zero is returned if a malloc() fails.
          466  +** Variable usage notes:
          467  +**
          468  +**     Parse.aLabel[x]     Stores the address that the x-th label resolves
          469  +**                         into.  For testing (SQLITE_DEBUG), unresolved
          470  +**                         labels stores -1, but that is not required.
          471  +**     Parse.nLabelAlloc   Number of slots allocated to Parse.aLabel[]
          472  +**     Parse.nLabel        The *negative* of the number of labels that have
          473  +**                         been issued.  The negative is stored because
          474  +**                         that gives a performance improvement over storing
          475  +**                         the equivalent positive value.
   445    476   */
   446         -int sqlite3VdbeMakeLabel(Vdbe *v){
   447         -  Parse *p = v->pParse;
   448         -  int i = p->nLabel++;
   449         -  assert( v->magic==VDBE_MAGIC_INIT );
   450         -  if( (i & (i-1))==0 ){
   451         -    p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, 
   452         -                                       (i*2+1)*sizeof(p->aLabel[0]));
   453         -  }
   454         -  if( p->aLabel ){
   455         -    p->aLabel[i] = -1;
   456         -  }
   457         -  return ADDR(i);
          477  +int sqlite3VdbeMakeLabel(Parse *pParse){
          478  +  return --pParse->nLabel;
   458    479   }
   459    480   
   460    481   /*
   461    482   ** Resolve label "x" to be the address of the next instruction to
   462    483   ** be inserted.  The parameter "x" must have been obtained from
   463    484   ** a prior call to sqlite3VdbeMakeLabel().
   464    485   */
          486  +static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
          487  +  int nNewSize = 10 - p->nLabel;
          488  +  p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
          489  +                     nNewSize*sizeof(p->aLabel[0]));
          490  +  if( p->aLabel==0 ){
          491  +    p->nLabelAlloc = 0;
          492  +  }else{
          493  +#ifdef SQLITE_DEBUG
          494  +    int i;
          495  +    for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1;
          496  +#endif
          497  +    p->nLabelAlloc = nNewSize;
          498  +    p->aLabel[j] = v->nOp;
          499  +  }
          500  +}
   465    501   void sqlite3VdbeResolveLabel(Vdbe *v, int x){
   466    502     Parse *p = v->pParse;
   467    503     int j = ADDR(x);
   468    504     assert( v->magic==VDBE_MAGIC_INIT );
   469         -  assert( j<p->nLabel );
          505  +  assert( j<-p->nLabel );
   470    506     assert( j>=0 );
   471         -  if( p->aLabel ){
   472    507   #ifdef SQLITE_DEBUG
   473         -    if( p->db->flags & SQLITE_VdbeAddopTrace ){
   474         -      printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
   475         -    }
          508  +  if( p->db->flags & SQLITE_VdbeAddopTrace ){
          509  +    printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
          510  +  }
   476    511   #endif
          512  +  if( p->nLabelAlloc + p->nLabel < 0 ){
          513  +    resizeResolveLabel(p,v,j);
          514  +  }else{
   477    515       assert( p->aLabel[j]==(-1) ); /* Labels may only be resolved once */
   478    516       p->aLabel[j] = v->nOp;
   479    517     }
   480    518   }
   481    519   
   482    520   /*
   483    521   ** Mark the VDBE as one that can only be run one time.
................................................................................
   594    632     VdbeOpIter sIter;
   595    633     memset(&sIter, 0, sizeof(sIter));
   596    634     sIter.v = v;
   597    635   
   598    636     while( (pOp = opIterNext(&sIter))!=0 ){
   599    637       int opcode = pOp->opcode;
   600    638       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
          639  +     || opcode==OP_VDestroy
   601    640        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   602    641         && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
   603    642       ){
   604    643         hasAbort = 1;
   605    644         break;
   606    645       }
   607    646       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
................................................................................
   744    783   #endif
   745    784           default: {
   746    785             if( pOp->p2<0 ){
   747    786               /* The mkopcodeh.tcl script has so arranged things that the only
   748    787               ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
   749    788               ** have non-negative values for P2. */
   750    789               assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
   751         -            assert( ADDR(pOp->p2)<pParse->nLabel );
          790  +            assert( ADDR(pOp->p2)<-pParse->nLabel );
   752    791               pOp->p2 = aLabel[ADDR(pOp->p2)];
   753    792             }
   754    793             break;
   755    794           }
   756    795         }
   757    796         /* The mkopcodeh.tcl script has so arranged things that the only
   758    797         ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
................................................................................
   783    822   ** SQLITE_TEST_REALLOC_STRESS).  This interface is used during testing
   784    823   ** to verify that certain calls to sqlite3VdbeAddOpList() can never
   785    824   ** fail due to a OOM fault and hence that the return value from
   786    825   ** sqlite3VdbeAddOpList() will always be non-NULL.
   787    826   */
   788    827   #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
   789    828   void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N){
   790         -  assert( p->nOp + N <= p->pParse->nOpAlloc );
          829  +  assert( p->nOp + N <= p->nOpAlloc );
   791    830   }
   792    831   #endif
   793    832   
   794    833   /*
   795    834   ** Verify that the VM passed as the only argument does not contain
   796    835   ** an OP_ResultRow opcode. Fail an assert() if it does. This is used
   797    836   ** by code in pragma.c to ensure that the implementation of certain
................................................................................
   855    894     VdbeOpList const *aOp,       /* The opcodes to be added */
   856    895     int iLineno                  /* Source-file line number of first opcode */
   857    896   ){
   858    897     int i;
   859    898     VdbeOp *pOut, *pFirst;
   860    899     assert( nOp>0 );
   861    900     assert( p->magic==VDBE_MAGIC_INIT );
   862         -  if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){
          901  +  if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
   863    902       return 0;
   864    903     }
   865    904     pFirst = pOut = &p->aOp[p->nOp];
   866    905     for(i=0; i<nOp; i++, aOp++, pOut++){
   867    906       pOut->opcode = aOp->opcode;
   868    907       pOut->p1 = aOp->p1;
   869    908       pOut->p2 = aOp->p2;
................................................................................
  2177   2216     ** requirements by reusing the opcode array tail, then the second
  2178   2217     ** pass will fill in the remainder using a fresh memory allocation.  
  2179   2218     **
  2180   2219     ** This two-pass approach that reuses as much memory as possible from
  2181   2220     ** the leftover memory at the end of the opcode array.  This can significantly
  2182   2221     ** reduce the amount of memory held by a prepared statement.
  2183   2222     */
  2184         -  do {
  2185         -    x.nNeeded = 0;
  2186         -    p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
  2187         -    p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
  2188         -    p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
  2189         -    p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
         2223  +  x.nNeeded = 0;
         2224  +  p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
         2225  +  p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
         2226  +  p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
         2227  +  p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
  2190   2228   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
  2191         -    p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
         2229  +  p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
  2192   2230   #endif
  2193         -    if( x.nNeeded==0 ) break;
         2231  +  if( x.nNeeded ){
  2194   2232       x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
  2195   2233       x.nFree = x.nNeeded;
  2196         -  }while( !db->mallocFailed );
         2234  +    if( !db->mallocFailed ){
         2235  +      p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
         2236  +      p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
         2237  +      p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
         2238  +      p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
         2239  +#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
         2240  +      p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
         2241  +#endif
         2242  +    }
         2243  +  }
  2197   2244   
  2198   2245     p->pVList = pParse->pVList;
  2199   2246     pParse->pVList =  0;
  2200   2247     p->explain = pParse->explain;
  2201   2248     if( db->mallocFailed ){
  2202   2249       p->nVar = 0;
  2203   2250       p->nCursor = 0;

Changes to src/wal.c.

   301    301   **
   302    302   ** The wal file that writers are currently appending to (the one they
   303    303   ** don't have to check the above two criteria before writing to) is called
   304    304   ** the "current" wal file.
   305    305   **
   306    306   ** The first wal file takes the same name as the wal file in legacy wal
   307    307   ** mode systems - "<db>-wal". The second is named "<db>-wal2".
          308  +
          309  +**
          310  +** CHECKPOINTS
          311  +**
          312  +** The "pre-configured size" mentioned above is the value set by 
          313  +** "PRAGMA journal_size_limit". Or, if journal_size_limit is not set, 
          314  +** 1000 pages.
          315  +**
          316  +** There is only a single type of checkpoint in wal2 mode (no "truncate",
          317  +** "restart" etc.), and it always checkpoints the entire contents of a single
          318  +** wal file. A wal file cannot be checkpointed until after a writer has written
          319  +** the first transaction into the other wal file and all readers are reading a
          320  +** snapshot that includes at least one transaction from the other wal file.
          321  +**
          322  +** The wal-hook, if one is registered, is invoked after a write-transaction
          323  +** is committed, just as it is in legacy wal mode. The integer parameter
          324  +** passed to the wal-hook is the total number of uncheckpointed frames in both
          325  +** wal files. Except, the parameter is set to zero if there is no frames 
          326  +** that may be checkpointed. This happens in two scenarios:
          327  +**
          328  +**   1. The "other" wal file (the one that the writer did not just append to)
          329  +**      is completely empty, or
          330  +**
          331  +**   2. The "other" wal file (the one that the writer did not just append to)
          332  +**      has already been checkpointed.
          333  +**
   308    334   **
   309    335   ** WAL FILE FORMAT
   310    336   **
   311    337   ** The file format used for each wal file in wal2 mode is the same as for
   312    338   ** legacy wal mode.  Except, the file format field is set to 3021000 
   313    339   ** instead of 3007000.
   314    340   **
................................................................................
  1291   1317     testcase( mxFrame==HASHTABLE_NPAGE_ONE-1 );
  1292   1318     testcase( mxFrame==HASHTABLE_NPAGE_ONE );
  1293   1319     testcase( mxFrame==HASHTABLE_NPAGE_ONE+1 );
  1294   1320   
  1295   1321     if( mxFrame==0 ) return;
  1296   1322   
  1297   1323     /* Obtain pointers to the hash-table and page-number array containing 
  1298         -  ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
  1299         -  ** that the page said hash-table and array reside on is already mapped.
  1300         -  */
         1324  +  ** the entry that corresponds to frame pWal->hdr.mxFrame.  */
  1301   1325     assert( pWal->nWiData>walFramePage(iExternal) );
  1302   1326     assert( pWal->apWiData[walFramePage(iExternal)] );
  1303   1327     walHashGet(pWal, walFramePage(iExternal), &sLoc);
  1304   1328   
  1305   1329     /* Zero all hash-table entries that correspond to frame numbers greater
  1306   1330     ** than pWal->hdr.mxFrame.
  1307   1331     */
................................................................................
  3561   3585     u32 *piRead                     /* OUT: Frame number (or zero) */
  3562   3586   ){
  3563   3587     int bWal2 = isWalMode2(pWal);
  3564   3588     int iApp = walidxGetFile(&pWal->hdr);
  3565   3589     int rc = SQLITE_OK;
  3566   3590     u32 iRead = 0;                  /* If !=0, WAL frame to return data from */
  3567   3591   
  3568         -  /* This routine is only be called from within a read transaction. */
  3569         -  assert( pWal->readLock!=WAL_LOCK_NONE );
         3592  +  /* This routine is only be called from within a read transaction. Or,
         3593  +  ** sometimes, as part of a rollback that occurs after an error reaquiring
         3594  +  ** a read-lock in walRestartLog().  */
         3595  +  assert( pWal->readLock!=WAL_LOCK_NONE || pWal->writeLock );
  3570   3596   
  3571   3597     /* If this is a regular wal system, then iApp must be set to 0 (there is
  3572   3598     ** only one wal file, after all). Or, if this is a wal2 system and the
  3573   3599     ** write-lock is not held, the client must have a partial-wal lock on wal 
  3574   3600     ** file iApp. This is not always true if the write-lock is held and this
  3575   3601     ** function is being called after WalLockForCommit() as part of committing
  3576   3602     ** a CONCURRENT transaction.  */
................................................................................
  3833   3859         ** occurs if some other writer has crashed while committing a 
  3834   3860         ** transaction to this database since the current concurrent transaction
  3835   3861         ** was opened.  */
  3836   3862         rc = SQLITE_BUSY_SNAPSHOT;
  3837   3863       }else if( memcmp(&pWal->hdr, (void*)&head, sizeof(WalIndexHdr))!=0 ){
  3838   3864         int bWal2 = isWalMode2(pWal);
  3839   3865         int iHash;
  3840         -      int iLastHash = walFramePage(head.mxFrame);
  3841   3866         int nLoop = 1+(bWal2 && walidxGetFile(&head)!=walidxGetFile(&pWal->hdr));
  3842   3867         int iLoop;
  3843   3868         
  3844   3869   
  3845   3870         assert( nLoop==1 || nLoop==2 );
  3846         -      for(iLoop=0; iLoop<nLoop && rc==SQLITE_OK; iLoop++){
         3871  +      for(iLoop=0; rc==SQLITE_OK && iLoop<nLoop; iLoop++){
  3847   3872           u32 iFirst;               /* First (external) wal frame to check */
  3848   3873           u32 iLastHash;            /* Last hash to check this loop */
  3849   3874           u32 mxFrame;              /* Last (external) wal frame to check */
  3850   3875   
  3851   3876           if( bWal2==0 ){
  3852   3877             assert( iLoop==0 );
  3853   3878             /* Special case for wal mode. If this concurrent transaction was
................................................................................
  3892   3917                 if( sLoc.aPgno[i]==1 ){
  3893   3918                   /* Check that the schema cookie has not been modified. If
  3894   3919                   ** it has not, the commit can proceed. */
  3895   3920                   u8 aNew[4];
  3896   3921                   u8 *aOld = &((u8*)pPage1->pData)[40];
  3897   3922                   int sz;
  3898   3923                   i64 iOff;
  3899         -                int iFrame = sLoc.iZero + i;
         3924  +                u32 iFrame = sLoc.iZero + i;
  3900   3925                   int iWal = 0;
  3901   3926                   if( bWal2 ){
  3902   3927                     iWal = walExternalDecode(iFrame, &iFrame);
  3903   3928                   }
  3904   3929                   sz = pWal->hdr.szPage;
  3905   3930                   sz = (sz&0xfe00) + ((sz&0x0001)<<16);
  3906   3931                   iOff = walFrameOffset(iFrame, sz) + WAL_FRAME_HDRSIZE + 40;
................................................................................
  3998   4023   ** to the WAL since the start of the transaction. If the callback returns
  3999   4024   ** other than SQLITE_OK, it is not invoked again and the error code is
  4000   4025   ** returned to the caller.
  4001   4026   **
  4002   4027   ** Otherwise, if the callback function does not return an error, this
  4003   4028   ** function returns SQLITE_OK.
  4004   4029   */
  4005         -int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
         4030  +int sqlite3WalUndo(
         4031  +  Wal *pWal, 
         4032  +  int (*xUndo)(void *, Pgno), 
         4033  +  void *pUndoCtx,
         4034  +  int bConcurrent                 /* True if this is a CONCURRENT transaction */
         4035  +){
  4006   4036     int rc = SQLITE_OK;
  4007   4037     if( pWal->writeLock ){
  4008   4038       int iWal = walidxGetFile(&pWal->hdr);
  4009   4039       Pgno iMax = walidxGetMxFrame(&pWal->hdr, iWal);
  4010   4040       Pgno iNew;
  4011   4041       Pgno iFrame;
  4012   4042   
  4013   4043       assert( isWalMode2(pWal) || iWal==0 );
  4014   4044   
  4015   4045       /* Restore the clients cache of the wal-index header to the state it
  4016   4046       ** was in before the client began writing to the database. 
  4017   4047       */
  4018   4048       memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr));
  4019         -    assert( walidxGetFile(&pWal->hdr)==iWal );
  4020   4049       iNew = walidxGetMxFrame(&pWal->hdr, walidxGetFile(&pWal->hdr));
         4050  +
         4051  +    /* BEGIN CONCURRENT transactions are different, as the header just
         4052  +    ** memcpy()d into pWal->hdr may not be the same as the current header 
         4053  +    ** when the transaction was started. Instead, pWal->hdr now contains
         4054  +    ** the header written by the most recent successful COMMIT. Because
         4055  +    ** Wal.writeLock is set, if this is a BEGIN CONCURRENT transaction,
         4056  +    ** the rollback must be taking place because an error occurred during
         4057  +    ** a COMMIT.
         4058  +    **
         4059  +    ** The code below is still valid. All frames between (iNew+1) and iMax 
         4060  +    ** must have been written by this transaction before the error occurred.
         4061  +    ** The exception is in wal2 mode - if the current wal file at the time
         4062  +    ** of the last COMMIT is not wal file iWal, then the error must have
         4063  +    ** occurred in WalLockForCommit(), before any pages were written
         4064  +    ** to the database file. In this case return early.  */
         4065  +#ifndef SQLITE_OMIT_CONCURRENT
         4066  +    if( bConcurrent ){
         4067  +      pWal->hdr.aCksum[0]++;
         4068  +    }
         4069  +    if( walidxGetFile(&pWal->hdr)!=iWal ){
         4070  +      assert( bConcurrent && isWalMode2(pWal) );
         4071  +      return SQLITE_OK;
         4072  +    }
         4073  +#endif
         4074  +    assert( walidxGetFile(&pWal->hdr)==iWal );
  4021   4075   
  4022   4076       for(iFrame=iNew+1; ALWAYS(rc==SQLITE_OK) && iFrame<=iMax; iFrame++){
  4023   4077         /* This call cannot fail. Unless the page for which the page number
  4024   4078         ** is passed as the second argument is (a) in the cache and 
  4025   4079         ** (b) has an outstanding reference, then xUndo is either a no-op
  4026   4080         ** (if (a) is false) or simply expels the page from the cache (if (b)
  4027   4081         ** is false).
................................................................................
  4116   4170         nWalSize = (pWal->mxWalSize-WAL_HDRSIZE+pWal->szPage+WAL_FRAME_HDRSIZE-1) 
  4117   4171           / (pWal->szPage+WAL_FRAME_HDRSIZE);
  4118   4172         nWalSize = MAX(nWalSize, 1);
  4119   4173       }
  4120   4174   
  4121   4175       if( walidxGetMxFrame(&pWal->hdr, iApp)>=nWalSize ){
  4122   4176         volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
  4123         -      if( walidxGetMxFrame(&pWal->hdr, !iApp)==0 || pInfo->nBackfill ){
         4177  +      u32 mxFrame = walidxGetMxFrame(&pWal->hdr, !iApp);
         4178  +      if( mxFrame==0 || pInfo->nBackfill ){
  4124   4179           rc = wal2RestartOk(pWal, iApp);
  4125   4180           if( rc==SQLITE_OK ){
  4126   4181             int iNew = !iApp;
  4127   4182             pWal->nCkpt++;
  4128   4183             walidxSetFile(&pWal->hdr, iNew);
  4129   4184             walidxSetMxFrame(&pWal->hdr, iNew, 0);
  4130   4185             sqlite3Put4byte((u8*)&pWal->hdr.aSalt[0], pWal->hdr.aFrameCksum[0]);
................................................................................
  4659   4714         sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
  4660   4715       }
  4661   4716     }
  4662   4717   
  4663   4718     /* Copy data from the log to the database file. */
  4664   4719     if( rc==SQLITE_OK ){
  4665   4720       if( (walPagesize(pWal)!=nBuf) 
  4666         -     && (walidxGetMxFrame(&pWal->hdr, 0) || walidxGetMxFrame(&pWal->hdr, 1))
         4721  +     && ((pWal->hdr.mxFrame2 & 0x7FFFFFFF) || pWal->hdr.mxFrame)
  4667   4722       ){
  4668   4723         rc = SQLITE_CORRUPT_BKPT;
  4669   4724       }else{
  4670   4725         rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags, zBuf);
  4671   4726       }
  4672   4727   
  4673   4728       /* If no error occurred, set the output variables. */

Changes to src/wal.h.

    30     30   # define sqlite3WalLimit(x,y)
    31     31   # define sqlite3WalClose(v,w,x,y,z)              0
    32     32   # define sqlite3WalBeginReadTransaction(y,z)     0
    33     33   # define sqlite3WalEndReadTransaction(z)
    34     34   # define sqlite3WalDbsize(y)                     0
    35     35   # define sqlite3WalBeginWriteTransaction(y)      0
    36     36   # define sqlite3WalEndWriteTransaction(x)        0
    37         -# define sqlite3WalUndo(x,y,z)                   0
           37  +# define sqlite3WalUndo(w,x,y,z)                 0
    38     38   # define sqlite3WalSavepoint(y,z)
    39     39   # define sqlite3WalSavepointUndo(y,z)            0
    40     40   # define sqlite3WalFrames(u,v,w,x,y,z)           0
    41     41   # define sqlite3WalCheckpoint(q,r,s,t,u,v,w,x,y,z) 0
    42     42   # define sqlite3WalCallback(z)                   0
    43     43   # define sqlite3WalExclusiveMode(y,z)            0
    44     44   # define sqlite3WalHeapMemory(z)                 0
................................................................................
    80     80   Pgno sqlite3WalDbsize(Wal *pWal);
    81     81   
    82     82   /* Obtain or release the WRITER lock. */
    83     83   int sqlite3WalBeginWriteTransaction(Wal *pWal);
    84     84   int sqlite3WalEndWriteTransaction(Wal *pWal);
    85     85   
    86     86   /* Undo any frames written (but not committed) to the log */
    87         -int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx);
           87  +int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx, int);
    88     88   
    89     89   /* Return an integer that records the current (uncommitted) write
    90     90   ** position in the WAL */
    91     91   void sqlite3WalSavepoint(Wal *pWal, u32 *aWalData);
    92     92   
    93     93   /* Move the write position of the WAL back to iFrame.  Called in
    94     94   ** response to a ROLLBACK TO command. */

Changes to src/where.c.

   833    833       addrTop =  sqlite3VdbeAddOp1(v, OP_Yield, regYield);
   834    834       VdbeCoverage(v);
   835    835       VdbeComment((v, "next row of %s", pTabItem->pTab->zName));
   836    836     }else{
   837    837       addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
   838    838     }
   839    839     if( pPartial ){
   840         -    iContinue = sqlite3VdbeMakeLabel(v);
          840  +    iContinue = sqlite3VdbeMakeLabel(pParse);
   841    841       sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
   842    842       pLoop->wsFlags |= WHERE_PARTIALIDX;
   843    843     }
   844    844     regRecord = sqlite3GetTempReg(pParse);
   845    845     regBase = sqlite3GenerateIndexKey(
   846    846         pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
   847    847     );
................................................................................
   850    850     if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
   851    851     if( pTabItem->fg.viaCoroutine ){
   852    852       sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
   853    853       testcase( pParse->db->mallocFailed );
   854    854       translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
   855    855                             pTabItem->regResult, 1);
   856    856       sqlite3VdbeGoto(v, addrTop);
          857  +    pTabItem->fg.viaCoroutine = 0;
   857    858     }else{
   858    859       sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
   859    860     }
   860    861     sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
   861    862     sqlite3VdbeJumpHere(v, addrTop);
   862    863     sqlite3ReleaseTempReg(pParse, regRecord);
   863    864     
................................................................................
  4639   4640     pWInfo->pParse = pParse;
  4640   4641     pWInfo->pTabList = pTabList;
  4641   4642     pWInfo->pOrderBy = pOrderBy;
  4642   4643     pWInfo->pWhere = pWhere;
  4643   4644     pWInfo->pResultSet = pResultSet;
  4644   4645     pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
  4645   4646     pWInfo->nLevel = nTabList;
  4646         -  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
         4647  +  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse);
  4647   4648     pWInfo->wctrlFlags = wctrlFlags;
  4648   4649     pWInfo->iLimit = iAuxArg;
  4649   4650     pWInfo->savedNQueryLoop = pParse->nQueryLoop;
  4650   4651     memset(&pWInfo->nOBSat, 0, 
  4651   4652            offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
  4652   4653     memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
  4653   4654     assert( pWInfo->eOnePass==ONEPASS_OFF );  /* ONEPASS defaults to OFF */
................................................................................
  5070   5071         if( db->mallocFailed ) goto whereBeginError;
  5071   5072       }
  5072   5073   #endif
  5073   5074       addrExplain = sqlite3WhereExplainOneScan(
  5074   5075           pParse, pTabList, pLevel, wctrlFlags
  5075   5076       );
  5076   5077       pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
  5077         -    notReady = sqlite3WhereCodeOneLoopStart(pWInfo, ii, notReady);
         5078  +    notReady = sqlite3WhereCodeOneLoopStart(pParse,v,pWInfo,ii,pLevel,notReady);
  5078   5079       pWInfo->iContinue = pLevel->addrCont;
  5079   5080       if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
  5080   5081         sqlite3WhereAddScanStatus(v, pTabList, pLevel, addrExplain);
  5081   5082       }
  5082   5083     }
  5083   5084   
  5084   5085     /* Done. */

Changes to src/whereInt.h.

   503    503     WhereLevel *pLvl,               /* Level to add scanstatus() entry for */
   504    504     int addrExplain                 /* Address of OP_Explain (or 0) */
   505    505   );
   506    506   #else
   507    507   # define sqlite3WhereAddScanStatus(a, b, c, d) ((void)d)
   508    508   #endif
   509    509   Bitmask sqlite3WhereCodeOneLoopStart(
          510  +  Parse *pParse,       /* Parsing context */
          511  +  Vdbe *v,             /* Prepared statement under construction */
   510    512     WhereInfo *pWInfo,   /* Complete information about the WHERE clause */
   511    513     int iLevel,          /* Which level of pWInfo->a[] should be coded */
          514  +  WhereLevel *pLevel,  /* The current level pointer */
   512    515     Bitmask notReady     /* Which tables are currently available */
   513    516   );
   514    517   
   515    518   /* whereexpr.c: */
   516    519   void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
   517    520   void sqlite3WhereClauseClear(WhereClause*);
   518    521   void sqlite3WhereSplit(WhereClause*,Expr*,u8);

Changes to src/wherecode.c.

   209    209         sqlite3_str_appendf(&str, " (~%llu rows)",
   210    210                sqlite3LogEstToInt(pLoop->nOut));
   211    211       }else{
   212    212         sqlite3_str_append(&str, " (~1 row)", 9);
   213    213       }
   214    214   #endif
   215    215       zMsg = sqlite3StrAccumFinish(&str);
          216  +    sqlite3ExplainBreakpoint("",zMsg);
   216    217       ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
   217    218                               pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
   218    219     }
   219    220     return ret;
   220    221   }
   221    222   #endif /* SQLITE_OMIT_EXPLAIN */
   222    223   
................................................................................
   534    535         }
   535    536       }
   536    537       for(i=iEq;i<pLoop->nLTerm; i++){
   537    538         assert( pLoop->aLTerm[i]!=0 );
   538    539         if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
   539    540       }
   540    541   
          542  +    iTab = 0;
   541    543       if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
   542         -      eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
          544  +      eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
   543    545       }else{
   544    546         sqlite3 *db = pParse->db;
   545    547         pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
   546    548   
   547    549         if( !db->mallocFailed ){
   548    550           aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
   549         -        eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
   550         -        pTerm->pExpr->iTable = pX->iTable;
          551  +        eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
          552  +        pTerm->pExpr->iTable = iTab;
   551    553         }
   552    554         sqlite3ExprDelete(db, pX);
   553    555         pX = pTerm->pExpr;
   554    556       }
   555    557   
   556    558       if( eType==IN_INDEX_INDEX_DESC ){
   557    559         testcase( bRev );
   558    560         bRev = !bRev;
   559    561       }
   560         -    iTab = pX->iTable;
   561    562       sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
   562    563       VdbeCoverageIf(v, bRev);
   563    564       VdbeCoverageIf(v, !bRev);
   564    565       assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
   565    566   
   566    567       pLoop->wsFlags |= WHERE_IN_ABLE;
   567    568       if( pLevel->u.in.nIn==0 ){
   568         -      pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
          569  +      pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
   569    570       }
   570    571   
   571    572       i = pLevel->u.in.nIn;
   572    573       pLevel->u.in.nIn += nEq;
   573    574       pLevel->u.in.aInLoop =
   574    575          sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
   575    576                                 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
................................................................................
  1072   1073   */
  1073   1074   static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
  1074   1075     assert( nReg>0 );
  1075   1076     if( p && sqlite3ExprIsVector(p) ){
  1076   1077   #ifndef SQLITE_OMIT_SUBQUERY
  1077   1078       if( (p->flags & EP_xIsSelect) ){
  1078   1079         Vdbe *v = pParse->pVdbe;
  1079         -      int iSelect = sqlite3CodeSubselect(pParse, p, 0, 0);
         1080  +      int iSelect;
         1081  +      assert( p->op==TK_SELECT );
         1082  +      iSelect = sqlite3CodeSubselect(pParse, p);
  1080   1083         sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
  1081   1084       }else
  1082   1085   #endif
  1083   1086       {
  1084   1087         int i;
  1085   1088         ExprList *pList = p->x.pList;
  1086   1089         assert( nReg<=pList->nExpr );
................................................................................
  1158   1161   }
  1159   1162   
  1160   1163   /*
  1161   1164   ** Generate code for the start of the iLevel-th loop in the WHERE clause
  1162   1165   ** implementation described by pWInfo.
  1163   1166   */
  1164   1167   Bitmask sqlite3WhereCodeOneLoopStart(
         1168  +  Parse *pParse,       /* Parsing context */
         1169  +  Vdbe *v,             /* Prepared statement under construction */
  1165   1170     WhereInfo *pWInfo,   /* Complete information about the WHERE clause */
  1166   1171     int iLevel,          /* Which level of pWInfo->a[] should be coded */
         1172  +  WhereLevel *pLevel,  /* The current level pointer */
  1167   1173     Bitmask notReady     /* Which tables are currently available */
  1168   1174   ){
  1169   1175     int j, k;            /* Loop counters */
  1170   1176     int iCur;            /* The VDBE cursor for the table */
  1171   1177     int addrNxt;         /* Where to jump to continue with the next IN case */
  1172         -  int omitTable;       /* True if we use the index only */
  1173   1178     int bRev;            /* True if we need to scan in reverse order */
  1174         -  WhereLevel *pLevel;  /* The where level to be coded */
  1175   1179     WhereLoop *pLoop;    /* The WhereLoop object being coded */
  1176   1180     WhereClause *pWC;    /* Decomposition of the entire WHERE clause */
  1177   1181     WhereTerm *pTerm;               /* A WHERE clause term */
  1178         -  Parse *pParse;                  /* Parsing context */
  1179   1182     sqlite3 *db;                    /* Database connection */
  1180         -  Vdbe *v;                        /* The prepared stmt under constructions */
  1181   1183     struct SrcList_item *pTabItem;  /* FROM clause term being coded */
  1182   1184     int addrBrk;                    /* Jump here to break out of the loop */
  1183   1185     int addrHalt;                   /* addrBrk for the outermost loop */
  1184   1186     int addrCont;                   /* Jump here to continue with next cycle */
  1185   1187     int iRowidReg = 0;        /* Rowid is stored in this register, if not zero */
  1186   1188     int iReleaseReg = 0;      /* Temp register to free before returning */
  1187   1189     Index *pIdx = 0;          /* Index used by loop (if any) */
  1188   1190     int iLoop;                /* Iteration of constraint generator loop */
  1189   1191   
  1190         -  pParse = pWInfo->pParse;
  1191         -  v = pParse->pVdbe;
  1192   1192     pWC = &pWInfo->sWC;
  1193   1193     db = pParse->db;
  1194         -  pLevel = &pWInfo->a[iLevel];
  1195   1194     pLoop = pLevel->pWLoop;
  1196   1195     pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
  1197   1196     iCur = pTabItem->iCursor;
  1198   1197     pLevel->notReady = notReady & ~sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
  1199   1198     bRev = (pWInfo->revMask>>iLevel)&1;
  1200         -  omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0 
  1201         -           && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
  1202   1199     VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
  1203   1200   
  1204   1201     /* Create labels for the "break" and "continue" instructions
  1205   1202     ** for the current loop.  Jump to addrBrk to break out of a loop.
  1206   1203     ** Jump to cont to go immediately to the next iteration of the
  1207   1204     ** loop.
  1208   1205     **
  1209   1206     ** When there is an IN operator, we also have a "addrNxt" label that
  1210   1207     ** means to continue with the next IN value combination.  When
  1211   1208     ** there are no IN operators in the constraints, the "addrNxt" label
  1212   1209     ** is the same as "addrBrk".
  1213   1210     */
  1214         -  addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
  1215         -  addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);
         1211  +  addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
         1212  +  addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
  1216   1213   
  1217   1214     /* If this is the right table of a LEFT OUTER JOIN, allocate and
  1218   1215     ** initialize a memory cell that records if this table matches any
  1219   1216     ** row of the left table of the join.
  1220   1217     */
  1221   1218     assert( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
  1222   1219          || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
................................................................................
  1335   1332       **          we reference multiple rows using a "rowid IN (...)"
  1336   1333       **          construct.
  1337   1334       */
  1338   1335       assert( pLoop->u.btree.nEq==1 );
  1339   1336       pTerm = pLoop->aLTerm[0];
  1340   1337       assert( pTerm!=0 );
  1341   1338       assert( pTerm->pExpr!=0 );
  1342         -    assert( omitTable==0 );
  1343   1339       testcase( pTerm->wtFlags & TERM_VIRTUAL );
  1344   1340       iReleaseReg = ++pParse->nMem;
  1345   1341       iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
  1346   1342       if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
  1347   1343       addrNxt = pLevel->addrNxt;
  1348   1344       sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg);
  1349   1345       VdbeCoverage(v);
................................................................................
  1354   1350       /* Case 3:  We have an inequality comparison against the ROWID field.
  1355   1351       */
  1356   1352       int testOp = OP_Noop;
  1357   1353       int start;
  1358   1354       int memEndValue = 0;
  1359   1355       WhereTerm *pStart, *pEnd;
  1360   1356   
  1361         -    assert( omitTable==0 );
  1362   1357       j = 0;
  1363   1358       pStart = pEnd = 0;
  1364   1359       if( pLoop->wsFlags & WHERE_BTM_LIMIT ) pStart = pLoop->aLTerm[j++];
  1365   1360       if( pLoop->wsFlags & WHERE_TOP_LIMIT ) pEnd = pLoop->aLTerm[j++];
  1366   1361       assert( pStart!=0 || pEnd!=0 );
  1367   1362       if( bRev ){
  1368   1363         pTerm = pStart;
................................................................................
  1518   1513       int iIdxCur;                 /* The VDBE cursor for the index */
  1519   1514       int nExtraReg = 0;           /* Number of extra registers needed */
  1520   1515       int op;                      /* Instruction opcode */
  1521   1516       char *zStartAff;             /* Affinity for start of range constraint */
  1522   1517       char *zEndAff = 0;           /* Affinity for end of range constraint */
  1523   1518       u8 bSeekPastNull = 0;        /* True to seek past initial nulls */
  1524   1519       u8 bStopAtNull = 0;          /* Add condition to terminate at NULLs */
         1520  +    int omitTable;               /* True if we use the index only */
         1521  +
  1525   1522   
  1526   1523       pIdx = pLoop->u.btree.pIndex;
  1527   1524       iIdxCur = pLevel->iIdxCur;
  1528   1525       assert( nEq>=pLoop->nSkip );
  1529   1526   
  1530   1527       /* If this loop satisfies a sort order (pOrderBy) request that 
  1531   1528       ** was passed to this function to implement a "SELECT min(x) ..." 
................................................................................
  1719   1716       }
  1720   1717   
  1721   1718       if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){
  1722   1719         sqlite3VdbeAddOp2(v, OP_SeekHit, iIdxCur, 1);
  1723   1720       }
  1724   1721   
  1725   1722       /* Seek the table cursor, if required */
         1723  +    omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0 
         1724  +           && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
  1726   1725       if( omitTable ){
  1727   1726         /* pIdx is a covering index.  No need to access the main table. */
  1728   1727       }else if( HasRowid(pIdx->pTable) ){
  1729   1728         if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE) || (
  1730   1729             (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE) 
  1731   1730          && (pWInfo->eOnePass==ONEPASS_SINGLE)
  1732   1731         )){
................................................................................
  1829   1828       SrcList *pOrTab;       /* Shortened table list or OR-clause generation */
  1830   1829       Index *pCov = 0;             /* Potential covering index (or NULL) */
  1831   1830       int iCovCur = pParse->nTab++;  /* Cursor used for index scans (if any) */
  1832   1831   
  1833   1832       int regReturn = ++pParse->nMem;           /* Register used with OP_Gosub */
  1834   1833       int regRowset = 0;                        /* Register for RowSet object */
  1835   1834       int regRowid = 0;                         /* Register holding rowid */
  1836         -    int iLoopBody = sqlite3VdbeMakeLabel(v);  /* Start of loop body */
         1835  +    int iLoopBody = sqlite3VdbeMakeLabel(pParse);/* Start of loop body */
  1837   1836       int iRetInit;                             /* Address of regReturn init */
  1838   1837       int untestedTerms = 0;             /* Some terms not completely tested */
  1839   1838       int ii;                            /* Loop counter */
  1840   1839       u16 wctrlFlags;                    /* Flags for sub-WHERE clause */
  1841   1840       Expr *pAndExpr = 0;                /* An ".. AND (...)" expression */
  1842   1841       Table *pTab = pTabItem->pTab;
  1843   1842   
................................................................................
  1945   1944                || ExprHasProperty(pOrExpr, EP_FromJoin) 
  1946   1945           );
  1947   1946           if( pAndExpr ){
  1948   1947             pAndExpr->pLeft = pOrExpr;
  1949   1948             pOrExpr = pAndExpr;
  1950   1949           }
  1951   1950           /* Loop through table entries that match term pOrTerm. */
         1951  +        ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
  1952   1952           WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
  1953   1953           pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
  1954   1954                                         wctrlFlags, iCovCur);
  1955   1955           assert( pSubWInfo || pParse->nErr || db->mallocFailed );
  1956   1956           if( pSubWInfo ){
  1957   1957             WhereLoop *pSubLoop;
  1958   1958             int addrExplain = sqlite3WhereExplainOneScan(
................................................................................
  2048   2048               pCov = pSubLoop->u.btree.pIndex;
  2049   2049             }else{
  2050   2050               pCov = 0;
  2051   2051             }
  2052   2052   
  2053   2053             /* Finish the loop through table entries that match term pOrTerm. */
  2054   2054             sqlite3WhereEnd(pSubWInfo);
         2055  +          ExplainQueryPlanPop(pParse);
  2055   2056           }
  2056   2057         }
  2057   2058       }
  2058   2059       ExplainQueryPlanPop(pParse);
  2059   2060       pLevel->u.pCovidx = pCov;
  2060   2061       if( pCov ) pLevel->iIdxCur = iCovCur;
  2061   2062       if( pAndExpr ){

Changes to src/window.c.

  1326   1326     Window *pWin;
  1327   1327     for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
  1328   1328       FuncDef *pFunc = pWin->pFunc;
  1329   1329       if( pFunc->zName==nth_valueName
  1330   1330        || pFunc->zName==first_valueName
  1331   1331       ){
  1332   1332         int csr = pWin->csrApp;
  1333         -      int lbl = sqlite3VdbeMakeLabel(v);
         1333  +      int lbl = sqlite3VdbeMakeLabel(pParse);
  1334   1334         int tmpReg = sqlite3GetTempReg(pParse);
  1335   1335         sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
  1336   1336   
  1337   1337         if( pFunc->zName==nth_valueName ){
  1338   1338           sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+1,tmpReg);
  1339   1339           windowCheckIntValue(pParse, tmpReg, 2);
  1340   1340         }else{
................................................................................
  1349   1349         sqlite3VdbeResolveLabel(v, lbl);
  1350   1350         sqlite3ReleaseTempReg(pParse, tmpReg);
  1351   1351       }
  1352   1352       else if( pFunc->zName==leadName || pFunc->zName==lagName ){
  1353   1353         int nArg = pWin->pOwner->x.pList->nExpr;
  1354   1354         int iEph = pMWin->iEphCsr;
  1355   1355         int csr = pWin->csrApp;
  1356         -      int lbl = sqlite3VdbeMakeLabel(v);
         1356  +      int lbl = sqlite3VdbeMakeLabel(pParse);
  1357   1357         int tmpReg = sqlite3GetTempReg(pParse);
  1358   1358   
  1359   1359         if( nArg<3 ){
  1360   1360           sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
  1361   1361         }else{
  1362   1362           sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+2, pWin->regResult);
  1363   1363         }
................................................................................
  1610   1610          || pMWin->eEnd==TK_CURRENT 
  1611   1611          || pMWin->eEnd==TK_UNBOUNDED 
  1612   1612          || pMWin->eEnd==TK_PRECEDING 
  1613   1613     );
  1614   1614   
  1615   1615     /* Allocate register and label for the "flush_partition" sub-routine. */
  1616   1616     regFlushPart = ++pParse->nMem;
  1617         -  lblFlushPart = sqlite3VdbeMakeLabel(v);
  1618         -  lblFlushDone = sqlite3VdbeMakeLabel(v);
         1617  +  lblFlushPart = sqlite3VdbeMakeLabel(pParse);
         1618  +  lblFlushDone = sqlite3VdbeMakeLabel(pParse);
  1619   1619   
  1620   1620     regStart = ++pParse->nMem;
  1621   1621     regEnd = ++pParse->nMem;
  1622   1622   
  1623   1623     windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
  1624   1624   
  1625   1625     addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
................................................................................
  1721   1721       sqlite3VdbeJumpHere(v, addrIfPos2);
  1722   1722     }
  1723   1723   
  1724   1724     if( pMWin->eStart==TK_CURRENT 
  1725   1725      || pMWin->eStart==TK_PRECEDING 
  1726   1726      || pMWin->eStart==TK_FOLLOWING 
  1727   1727     ){
  1728         -    int lblSkipInverse = sqlite3VdbeMakeLabel(v);;
         1728  +    int lblSkipInverse = sqlite3VdbeMakeLabel(pParse);;
  1729   1729       if( pMWin->eStart==TK_PRECEDING ){
  1730   1730         sqlite3VdbeAddOp3(v, OP_IfPos, regStart, lblSkipInverse, 1);
  1731   1731         VdbeCoverage(v);
  1732   1732       }
  1733   1733       if( pMWin->eStart==TK_FOLLOWING ){
  1734   1734         sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+2);
  1735   1735         VdbeCoverage(v);
................................................................................
  1886   1886   
  1887   1887     assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT) 
  1888   1888          || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED) 
  1889   1889          || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT) 
  1890   1890          || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED) 
  1891   1891     );
  1892   1892   
  1893         -  lblEmpty = sqlite3VdbeMakeLabel(v);
         1893  +  lblEmpty = sqlite3VdbeMakeLabel(pParse);
  1894   1894     regNewPeer = pParse->nMem+1;
  1895   1895     pParse->nMem += nPeer;
  1896   1896   
  1897   1897     /* Allocate register and label for the "flush_partition" sub-routine. */
  1898   1898     regFlushPart = ++pParse->nMem;
  1899         -  lblFlushPart = sqlite3VdbeMakeLabel(v);
         1899  +  lblFlushPart = sqlite3VdbeMakeLabel(pParse);
  1900   1900   
  1901   1901     csrLead = pParse->nTab++;
  1902   1902     regCtr = ++pParse->nMem;
  1903   1903   
  1904   1904     windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
  1905   1905     addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
  1906   1906   

Changes to test/altertab.test.

   501    501     SELECT * FROM x;
   502    502   } {x x x}
   503    503   
   504    504   do_execsql_test 15.5 {
   505    505     SELECT sql FROM sqlite_master WHERE name = 'y';
   506    506   } {{CREATE VIEW y AS SELECT f2 AS f1 FROM x}}
   507    507   
          508  +#-------------------------------------------------------------------------
          509  +# Test that it is not possible to rename a shadow table in DEFENSIVE mode.
          510  +#
          511  +ifcapable fts3 {
          512  +  proc vtab_command {method args} {
          513  +    switch -- $method {
          514  +      xConnect {
          515  +        if {[info exists ::vtab_connect_sql]} {
          516  +          execsql $::vtab_connect_sql
          517  +        }
          518  +        return "CREATE TABLE t1(a, b, c)"
          519  +      }
          520  +
          521  +      xBestIndex {
          522  +        set clist [lindex $args 0]
          523  +        if {[llength $clist]!=1} { error "unexpected constraint list" }
          524  +        catch { array unset C }
          525  +        array set C [lindex $clist 0]
          526  +        if {$C(usable)} {
          527  +          return "omit 0 cost 0 rows 1 idxnum 555 idxstr eq!"
          528  +        } else {
          529  +          return "cost 1000000 rows 0 idxnum 0 idxstr scan..."
          530  +        }
          531  +      }
          532  +    }
          533  +
          534  +    return {}
          535  +  }
          536  +
          537  +  register_tcl_module db
          538  +
          539  +  sqlite3_db_config db DEFENSIVE 1
          540  +
          541  +  do_execsql_test 16.0 {
          542  +    CREATE VIRTUAL TABLE y1 USING fts3;
          543  +  }
          544  +
          545  +  do_catchsql_test 16.1 {
          546  +    INSERT INTO y1_segments VALUES(1, X'1234567890');
          547  +  } {1 {table y1_segments may not be modified}}
          548  +
          549  +  do_catchsql_test 16.2 {
          550  +    ALTER TABLE y1_segments RENAME TO abc;
          551  +  } {1 {table y1_segments may not be altered}}
          552  +
          553  +  do_execsql_test 16.3 {
          554  +    ALTER TABLE y1 RENAME TO z1;
          555  +  }
          556  +
          557  +  do_execsql_test 16.4 {
          558  +    SELECT * FROM z1_segments;
          559  +  }
          560  +}
   508    561   
   509    562   finish_test

Changes to test/autoindex1.test.

   180    180   }
   181    181   do_eqp_test autoindex1-500.1 {
   182    182     SELECT b FROM t501
   183    183      WHERE t501.a IN (SELECT x FROM t502 WHERE y=?);
   184    184   } {
   185    185     QUERY PLAN
   186    186     |--SEARCH TABLE t501 USING INTEGER PRIMARY KEY (rowid=?)
   187         -  `--LIST SUBQUERY
          187  +  `--LIST SUBQUERY xxxxxx
   188    188        `--SCAN TABLE t502
   189    189   }
   190    190   do_eqp_test autoindex1-501 {
   191    191     SELECT b FROM t501
   192    192      WHERE t501.a IN (SELECT x FROM t502 WHERE y=t501.b);
   193    193   } {
   194    194     QUERY PLAN
   195    195     |--SCAN TABLE t501
   196         -  `--CORRELATED LIST SUBQUERY
          196  +  `--CORRELATED LIST SUBQUERY xxxxxx
   197    197        `--SEARCH TABLE t502 USING AUTOMATIC COVERING INDEX (y=?)
   198    198   }
   199    199   do_eqp_test autoindex1-502 {
   200    200     SELECT b FROM t501
   201    201      WHERE t501.a=123
   202    202        AND t501.a IN (SELECT x FROM t502 WHERE y=t501.b);
   203    203   } {
   204    204     QUERY PLAN
   205    205     |--SEARCH TABLE t501 USING INTEGER PRIMARY KEY (rowid=?)
   206         -  `--CORRELATED LIST SUBQUERY
          206  +  `--CORRELATED LIST SUBQUERY xxxxxx
   207    207        `--SCAN TABLE t502
   208    208   }
   209    209   
   210    210   # The following code checks a performance regression reported on the
   211    211   # mailing list on 2010-10-19.  The problem is that the nRowEst field
   212    212   # of ephermeral tables was not being initialized correctly and so no
   213    213   # automatic index was being created for the emphemeral table when it was
................................................................................
   276    276      WHERE y.sheep_no IS NULL
   277    277      ORDER BY x.registering_flock;
   278    278   } {
   279    279     QUERY PLAN
   280    280     |--MATERIALIZE xxxxxx
   281    281     |  |--SCAN TABLE sheep AS s
   282    282     |  |--SEARCH TABLE flock_owner AS prev USING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date<?)
   283         -  |  `--CORRELATED SCALAR SUBQUERY
          283  +  |  `--CORRELATED SCALAR SUBQUERY xxxxxx
   284    284     |     `--SEARCH TABLE flock_owner AS later USING COVERING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date>? AND owner_change_date<?)
   285    285     |--SCAN TABLE sheep AS x USING INDEX sheep_reg_flock_index
   286    286     `--SEARCH SUBQUERY xxxxxx AS y USING AUTOMATIC COVERING INDEX (sheep_no=?)
   287    287   }
   288    288   
   289    289   
   290    290   do_execsql_test autoindex1-700 {

Changes to test/bestindex3.test.

    86     86   } {SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a EQ ?}
    87     87   
    88     88   do_eqp_test 1.3 {
    89     89     SELECT * FROM t1 WHERE a = 'abc' OR b = 'def';
    90     90   } {
    91     91     QUERY PLAN
    92     92     `--MULTI-INDEX OR
    93         -     |--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a EQ ?
    94         -     `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:b EQ ?
           93  +     |--INDEX 1
           94  +     |  `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a EQ ?
           95  +     `--INDEX 2
           96  +        `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:b EQ ?
    95     97   }
    96     98   
    97     99   do_eqp_test 1.4 {
    98    100     SELECT * FROM t1 WHERE a LIKE 'abc%' OR b = 'def';
    99    101   } {
   100    102     QUERY PLAN
   101    103     `--MULTI-INDEX OR
   102         -     |--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a LIKE ?
   103         -     `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:b EQ ?
          104  +     |--INDEX 1
          105  +     |  `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a LIKE ?
          106  +     `--INDEX 2
          107  +        `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:b EQ ?
   104    108   }
   105    109   
   106    110   do_execsql_test 1.5 {
   107    111     CREATE TABLE ttt(a, b, c);
   108    112   
   109    113     INSERT INTO ttt VALUES(1, 'two',   'three');
   110    114     INSERT INTO ttt VALUES(2, 'one',   'two');
................................................................................
   146    150     }
   147    151   
   148    152     do_eqp_test 2.2 {
   149    153       SELECT * FROM t2 WHERE x LIKE 'abc%' OR y = 'def'
   150    154     } [string map {"\n  " \n} {
   151    155       QUERY PLAN
   152    156       `--MULTI-INDEX OR
   153         -       |--SEARCH TABLE t2 USING INDEX t2x (x>? AND x<?)
   154         -       `--SEARCH TABLE t2 USING INDEX t2y (y=?)
          157  +       |--INDEX 1
          158  +       |  `--SEARCH TABLE t2 USING INDEX t2x (x>? AND x<?)
          159  +       `--INDEX 2
          160  +          `--SEARCH TABLE t2 USING INDEX t2y (y=?)
   155    161     }]
   156    162   }
   157    163   
   158    164   #-------------------------------------------------------------------------
   159    165   # Test that any PRIMARY KEY within a sqlite3_decl_vtab() CREATE TABLE 
   160    166   # statement is currently ignored.
   161    167   #

Changes to test/btree02.test.

    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   load_static_extension db eval
    21     21   do_execsql_test btree02-100 {
    22     22     CREATE TABLE t1(a TEXT, ax INTEGER, b INT, PRIMARY KEY(a,ax)) WITHOUT ROWID;
    23     23     WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10)
    24         -    INSERT INTO t1(a,ax,b) SELECT printf('%02x',i), random(), i FROM c;
           24  +    INSERT INTO t1(a,ax,b) SELECT printf('%02x',i+160), random(), i FROM c;
    25     25     CREATE INDEX t1a ON t1(a);
    26     26     CREATE TABLE t2(x,y);
    27     27     CREATE TABLE t3(cnt);
    28     28     WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<4)
    29     29       INSERT INTO t3(cnt) SELECT i FROM c;
    30     30     SELECT count(*) FROM t1;
    31     31   } {10}
           32  +
           33  +proc showt1 {} {
           34  +  puts -nonewline "t1: "
           35  +  puts [db eval {SELECT printf('(%s,%s)',quote(a),quote(b)) FROM t1}]
           36  +}
           37  +
    32     38   do_test btree02-110 {
    33     39     db eval BEGIN
    34     40     set i 0
           41  +  # showt1
    35     42     db eval {SELECT a, ax, b, cnt FROM t1 CROSS JOIN t3 WHERE b IS NOT NULL} {
    36         -    if {$a==""} {set a 0}
    37         -    if {$b==""} {set b 0}    
           43  +    if {$a==""} continue
    38     44       db eval {INSERT INTO t2(x,y) VALUES($b,$cnt)}
    39     45       # puts "a,b,cnt = ($a,$b,$cnt)"
    40     46       incr i
    41     47       if {$i%2==1} {
    42     48         set bx [expr {$b+1000}]
    43         -      # puts "INSERT ($a),$bx"
           49  +      #  puts "INSERT ($a),$bx"
    44     50         db eval {INSERT INTO t1(a,ax,b) VALUES(printf('(%s)',$a),random(),$bx)}
           51  +      # showt1
    45     52       } else {
    46     53         # puts "DELETE a=$a"
    47     54         db eval {DELETE FROM t1 WHERE a=$a}
           55  +      # showt1
    48     56       }
    49     57       db eval {COMMIT; BEGIN}
    50     58     }  
    51     59     db one {COMMIT; SELECT count(*) FROM t1;}
    52         -} {27}
           60  +} {10}
    53     61   
    54     62   finish_test

Added test/concfault2.test.

            1  +# 2018 Dec 28
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# This file contains fault injection tests designed to test the concurrent
           13  +# transactions feature.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +source $testdir/malloc_common.tcl
           19  +set testprefix concfault2
           20  +
           21  +ifcapable !concurrent {
           22  +  finish_test
           23  +  return
           24  +}
           25  +
           26  +do_execsql_test 1.0 {
           27  +  PRAGMA auto_vacuum = 0;
           28  +  PRAGMA journal_mode = wal2;
           29  +  CREATE TABLE t1(a PRIMARY KEY, b);
           30  +  CREATE TABLE t2(a PRIMARY KEY, b);
           31  +  INSERT INTO t1 VALUES(randomblob(1000), randomblob(100));
           32  +  INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
           33  +  INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
           34  +  INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
           35  +  INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
           36  +  DELETE FROM t1 WHERE rowid%2;
           37  +} {wal2}
           38  +
           39  +do_test 1.1 {
           40  +  list [expr [file size test.db-wal]>75000] [file size test.db-shm]
           41  +} {1 32768}
           42  +
           43  +faultsim_save_and_close
           44  +
           45  +do_faultsim_test 1 -prep {
           46  +  faultsim_restore_and_reopen
           47  +  execsql {
           48  +    SELECT * FROM t1;
           49  +    BEGIN CONCURRENT;
           50  +      INSERT INTO t2 VALUES(1, 2);
           51  +  }
           52  +  sqlite3 db2 test.db
           53  +  execsql {
           54  +    PRAGMA journal_size_limit = 10000;
           55  +    INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
           56  +  } db2
           57  +  db2 close
           58  +} -body {
           59  +  execsql { COMMIT }
           60  +} -test {
           61  +  faultsim_test_result {0 {}} 
           62  +  catchsql { ROLLBACK }
           63  +  set res [catchsql { SELECT count(*) FROM t1 }]
           64  +  if {$res!="0 9"} { error "expected {0 9} got {$res}" }
           65  +  faultsim_integrity_check
           66  +}
           67  +
           68  +finish_test
           69  +

Changes to test/concurrent2.test.

    18     18   source $testdir/wal_common.tcl
    19     19   set ::testprefix concurrent2
    20     20   
    21     21   ifcapable !concurrent {
    22     22     finish_test
    23     23     return
    24     24   }
           25  +
           26  +do_test 0.1 {
           27  +  llength [sqlite3_wal_info db main]
           28  +} {2}
    25     29   
    26     30   do_multiclient_test tn {
    27     31   
    28     32     do_test 1.$tn.1 {
    29     33       sql1 {
    30     34         PRAGMA journal_mode = wal;
    31     35         CREATE TABLE t1(x);

Changes to test/conflict.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for the conflict resolution extension
    14     14   # to SQLite.
    15     15   #
    16         -# $Id: conflict.test,v 1.32 2009/04/30 09:10:38 danielk1977 Exp $
    17     16   
    18     17   set testdir [file dirname $argv0]
    19     18   source $testdir/tester.tcl
    20     19   
    21     20   ifcapable !conflict {
    22     21     finish_test
    23     22     return
................................................................................
   820    819     execsql {
   821    820       REPLACE INTO t13 VALUES(3);
   822    821       COMMIT;
   823    822       SELECT * FROM t13;
   824    823     }
   825    824   } {1 3}
   826    825   
          826  +
          827  +# Ticket https://www.sqlite.org/src/tktview/e6f1f2e34dceeb1ed61531c7e9
          828  +# Verify that it is not possible to sneak a NULL value into a NOT NULL
          829  +# column using REPLACE.
          830  +#
          831  +do_catchsql_test conflict-14.1 {
          832  +  DROP TABLE IF EXISTS t1;
          833  +  CREATE TABLE t1(x NOT NULL DEFAULT NULL);
          834  +  REPLACE INTO t1 DEFAULT VALUES;
          835  +} {1 {NOT NULL constraint failed: t1.x}}
          836  +
   827    837   
   828    838   finish_test

Changes to test/cost.test.

    54     54   do_eqp_test 3.2 {
    55     55     SELECT a FROM t5 
    56     56     WHERE b IS NULL OR c IS NULL OR d IS NULL 
    57     57     ORDER BY a;
    58     58   } {
    59     59     QUERY PLAN
    60     60     |--MULTI-INDEX OR
    61         -  |  |--SEARCH TABLE t5 USING INDEX t5b (b=?)
    62         -  |  |--SEARCH TABLE t5 USING INDEX t5c (c=?)
    63         -  |  `--SEARCH TABLE t5 USING INDEX t5d (d=?)
           61  +  |  |--INDEX 1
           62  +  |  |  `--SEARCH TABLE t5 USING INDEX t5b (b=?)
           63  +  |  |--INDEX 2
           64  +  |  |  `--SEARCH TABLE t5 USING INDEX t5c (c=?)
           65  +  |  `--INDEX 3
           66  +  |     `--SEARCH TABLE t5 USING INDEX t5d (d=?)
    64     67     `--USE TEMP B-TREE FOR ORDER BY
    65     68   }
    66     69   
    67     70   #-------------------------------------------------------------------------
    68     71   # If there is no likelihood() or stat3 data, SQLite assumes that a closed
    69     72   # range scan (e.g. one constrained by "col BETWEEN ? AND ?" constraint)
    70     73   # visits 1/64 of the rows in a table.
................................................................................
   120    123   }
   121    124   
   122    125   do_eqp_test 6.2 {
   123    126     SELECT a FROM t3 WHERE (b BETWEEN 2 AND 4) OR c=100 ORDER BY a
   124    127   } {
   125    128     QUERY PLAN
   126    129     |--MULTI-INDEX OR
   127         -  |  |--SEARCH TABLE t3 USING INDEX t3i1 (b>? AND b<?)
   128         -  |  `--SEARCH TABLE t3 USING INDEX t3i2 (c=?)
          130  +  |  |--INDEX 1
          131  +  |  |  `--SEARCH TABLE t3 USING INDEX t3i1 (b>? AND b<?)
          132  +  |  `--INDEX 2
          133  +  |     `--SEARCH TABLE t3 USING INDEX t3i2 (c=?)
   129    134     `--USE TEMP B-TREE FOR ORDER BY
   130    135   }
   131    136   
   132    137   #-------------------------------------------------------------------------
   133    138   #
   134    139   reset_db
   135    140   do_execsql_test 7.1 {
................................................................................
   145    150   do_eqp_test 7.2 {
   146    151     SELECT a FROM t1
   147    152        WHERE (b>=950 AND b<=1010) OR (b IS NULL AND c NOT NULL)
   148    153     ORDER BY a
   149    154   } {
   150    155     QUERY PLAN
   151    156     |--MULTI-INDEX OR
   152         -  |  |--SEARCH TABLE t1 USING INDEX t1b (b>? AND b<?)
   153         -  |  `--SEARCH TABLE t1 USING INDEX t1b (b=?)
          157  +  |  |--INDEX 1
          158  +  |  |  `--SEARCH TABLE t1 USING INDEX t1b (b>? AND b<?)
          159  +  |  `--INDEX 2
          160  +  |     `--SEARCH TABLE t1 USING INDEX t1b (b=?)
   154    161     `--USE TEMP B-TREE FOR ORDER BY
   155    162   }
   156    163   
   157    164   do_eqp_test 7.3 {
   158    165     SELECT rowid FROM t1
   159    166     WHERE (+b IS NULL AND c NOT NULL AND d NOT NULL)
   160    167           OR (b NOT NULL AND c IS NULL AND d NOT NULL)

Changes to test/csv01.test.

   210    210   # by Trent W. Buck.
   211    211   #
   212    212   do_execsql_test 4.4 {
   213    213     CREATE VIRTUAL TABLE temp.trent USING csv(data='1');
   214    214     SELECT * FROM trent;
   215    215   } {1}
   216    216   
          217  +# 2018-12-26
          218  +# Bug report on the mailing list
          219  +#
          220  +forcedelete csv01.csv
          221  +set fd [open csv01.csv w]
          222  +puts $fd "a,b,c,d\r\n1,2,3,4\r\none,two,three,four\r\n5,6,7,8"
          223  +close $fd
          224  +do_execsql_test 5.1 {
          225  +  CREATE VIRTUAL TABLE t5_1 USING csv(filename='csv01.csv');
          226  +  SELECT name FROM temp.pragma_table_info('t5_1');
          227  +} {c0 c1 c2 c3}
          228  +do_execsql_test 5.2 {
          229  +  SELECT *, '|' FROM t5_1;
          230  +} {a b c d | 1 2 3 4 | one two three four | 5 6 7 8 |}
          231  +do_execsql_test 5.3 {
          232  +  DROP TABLE t5_1;
          233  +  CREATE VIRTUAL TABLE t5_1 USING csv(filename='csv01.csv', header);
          234  +  SELECT name FROM temp.pragma_table_info('t5_1');
          235  +} {a b c d}
          236  +do_execsql_test 5.4 {
          237  +  SELECT *, '|' FROM t5_1;
          238  +} {1 2 3 4 | one two three four | 5 6 7 8 |}
          239  +
   217    240   finish_test

Changes to test/e_select.test.

   163    163     2002.1  "SELECT ALL 1, 2, 3 GROUP BY 2 HAVING count(*)=1" {1 2 3}
   164    164     2002.2  "SELECT ALL 1, 2, 3 GROUP BY 2 HAVING count(*)>1" {}
   165    165   
   166    166     0101.1  "SELECT count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b}
   167    167     0102.1  "SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=1" {
   168    168       1 a 1 c 1 b
   169    169     }
   170         -  0102.2  "SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=2" { }
          170  +  0102.2  "SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=2" {}
   171    171   
   172    172     1101.1  "SELECT DISTINCT count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b}
   173    173     1102.1  "SELECT DISTINCT count(*), max(a) FROM t1 
   174    174              GROUP BY b HAVING count(*)=1" {
   175    175       1 a 1 c 1 b
   176    176     }
   177    177     1102.2  "SELECT DISTINCT count(*), max(a) FROM t1 
   178         -           GROUP BY b HAVING count(*)=2" { 
   179         -  }
          178  +           GROUP BY b HAVING count(*)=2" {}
   180    179   
   181    180     2101.1  "SELECT ALL count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b}
   182    181     2102.1  "SELECT ALL count(*), max(a) FROM t1 
   183    182              GROUP BY b HAVING count(*)=1" {
   184    183       1 a 1 c 1 b
   185    184     }
   186    185     2102.2  "SELECT ALL count(*), max(a) FROM t1 
   187         -           GROUP BY b HAVING count(*)=2" { 
   188         -  }
          186  +           GROUP BY b HAVING count(*)=2" {}
   189    187   
   190    188     0011.1  "SELECT 1, 2, 3 WHERE 1 GROUP BY 2" {1 2 3}
   191    189     0012.1  "SELECT 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)=1" {}
   192    190     0012.2  "SELECT 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)>1" {}
   193    191   
   194    192     1011.1  "SELECT DISTINCT 1, 2, 3 WHERE 0 GROUP BY 2" {}
   195    193     1012.1  "SELECT DISTINCT 1, 2, 3 WHERE 1 GROUP BY 2 HAVING count(*)=1" 
................................................................................
   200    198     2012.1  "SELECT ALL 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)=1" {}
   201    199     2012.2  "SELECT ALL 1, 2, 3 WHERE 'abc' GROUP BY 2 HAVING count(*)>1" {}
   202    200   
   203    201     0111.1  "SELECT count(*), max(a) FROM t1 WHERE a='a' GROUP BY b" {1 a}
   204    202     0112.1  "SELECT count(*), max(a) FROM t1 
   205    203              WHERE a='c' GROUP BY b HAVING count(*)=1" {1 c}
   206    204     0112.2  "SELECT count(*), max(a) FROM t1 
   207         -           WHERE 0 GROUP BY b HAVING count(*)=2" { }
          205  +           WHERE 0 GROUP BY b HAVING count(*)=2" {}
   208    206     1111.1  "SELECT DISTINCT count(*), max(a) FROM t1 WHERE a<'c' GROUP BY b" 
   209    207             {1 a 1 b}
   210    208     1112.1  "SELECT DISTINCT count(*), max(a) FROM t1 WHERE a>'a'
   211    209              GROUP BY b HAVING count(*)=1" {
   212    210       1 c 1 b
   213    211     }
   214    212     1112.2  "SELECT DISTINCT count(*), max(a) FROM t1 WHERE 0
   215         -           GROUP BY b HAVING count(*)=2" { 
   216         -  }
          213  +           GROUP BY b HAVING count(*)=2" {}
   217    214   
   218    215     2111.1  "SELECT ALL count(*), max(a) FROM t1 WHERE b>'one' GROUP BY b" 
   219    216             {1 c 1 b}
   220    217     2112.1  "SELECT ALL count(*), max(a) FROM t1 WHERE a!='b'
   221    218              GROUP BY b HAVING count(*)=1" {
   222    219       1 a 1 c
   223    220     }
   224    221     2112.2  "SELECT ALL count(*), max(a) FROM t1 
   225         -           WHERE 0 GROUP BY b HAVING count(*)=2" { }
          222  +           WHERE 0 GROUP BY b HAVING count(*)=2" {}
   226    223   }
   227    224   
   228    225   
   229    226   # -- syntax diagram result-column
   230    227   #
   231    228   do_select_tests e_select-0.3 {
   232    229     1  "SELECT * FROM t1" {a one b two c three}

Changes to test/eqp.test.

    41     41   }
    42     42   
    43     43   do_eqp_test 1.2 {
    44     44     SELECT * FROM t2, t1 WHERE t1.a=1 OR t1.b=2;
    45     45   } {
    46     46     QUERY PLAN
    47     47     |--MULTI-INDEX OR
    48         -  |  |--SEARCH TABLE t1 USING INDEX i1 (a=?)
    49         -  |  `--SEARCH TABLE t1 USING INDEX i2 (b=?)
           48  +  |  |--INDEX 1
           49  +  |  |  `--SEARCH TABLE t1 USING INDEX i1 (a=?)
           50  +  |  `--INDEX 2
           51  +  |     `--SEARCH TABLE t1 USING INDEX i2 (b=?)
    50     52     `--SCAN TABLE t2
    51     53   }
    52     54   do_eqp_test 1.3 {
    53     55     SELECT * FROM t2 CROSS JOIN t1 WHERE t1.a=1 OR t1.b=2;
    54     56   } {
    55     57     QUERY PLAN
    56     58     |--SCAN TABLE t2
    57     59     `--MULTI-INDEX OR
    58         -     |--SEARCH TABLE t1 USING INDEX i1 (a=?)
    59         -     `--SEARCH TABLE t1 USING INDEX i2 (b=?)
           60  +     |--INDEX 1
           61  +     |  `--SEARCH TABLE t1 USING INDEX i1 (a=?)
           62  +     `--INDEX 2
           63  +        `--SEARCH TABLE t1 USING INDEX i2 (b=?)
    60     64   }
    61     65   do_eqp_test 1.3 {
    62     66     SELECT a FROM t1 ORDER BY a
    63     67   } {
    64     68     QUERY PLAN
    65     69     `--SCAN TABLE t1 USING COVERING INDEX i1
    66     70   }
................................................................................
   221    225   # Test cases eqp-3.* - tests for select statements that use sub-selects.
   222    226   #
   223    227   do_eqp_test 3.1.1 {
   224    228     SELECT (SELECT x FROM t1 AS sub) FROM t1;
   225    229   } {
   226    230     QUERY PLAN
   227    231     |--SCAN TABLE t1
   228         -  `--SCALAR SUBQUERY
          232  +  `--SCALAR SUBQUERY xxxxxx
   229    233        `--SCAN TABLE t1 AS sub
   230    234   }
   231    235   do_eqp_test 3.1.2 {
   232    236     SELECT * FROM t1 WHERE (SELECT x FROM t1 AS sub);
   233    237   } {
   234    238     QUERY PLAN
   235    239     |--SCAN TABLE t1
   236         -  `--SCALAR SUBQUERY
          240  +  `--SCALAR SUBQUERY xxxxxx
   237    241        `--SCAN TABLE t1 AS sub
   238    242   }
   239    243   do_eqp_test 3.1.3 {
   240    244     SELECT * FROM t1 WHERE (SELECT x FROM t1 AS sub ORDER BY y);
   241    245   } {
   242    246     QUERY PLAN
   243    247     |--SCAN TABLE t1
   244         -  `--SCALAR SUBQUERY
          248  +  `--SCALAR SUBQUERY xxxxxx
   245    249        |--SCAN TABLE t1 AS sub
   246    250        `--USE TEMP B-TREE FOR ORDER BY
   247    251   }
   248    252   do_eqp_test 3.1.4 {
   249    253     SELECT * FROM t1 WHERE (SELECT x FROM t2 ORDER BY x);
   250    254   } {
   251    255     QUERY PLAN
   252    256     |--SCAN TABLE t1
   253         -  `--SCALAR SUBQUERY
          257  +  `--SCALAR SUBQUERY xxxxxx
   254    258        `--SCAN TABLE t2 USING COVERING INDEX t2i1
   255    259   }
   256    260   
   257    261   det 3.2.1 {
   258    262     SELECT * FROM (SELECT * FROM t1 ORDER BY x LIMIT 10) ORDER BY y LIMIT 5
   259    263   } {
   260    264     QUERY PLAN
................................................................................
   282    286   }
   283    287   
   284    288   det 3.3.1 {
   285    289     SELECT * FROM t1 WHERE y IN (SELECT y FROM t2)
   286    290   } {
   287    291     QUERY PLAN
   288    292     |--SCAN TABLE t1
   289         -  `--LIST SUBQUERY
          293  +  `--LIST SUBQUERY xxxxxx
   290    294        `--SCAN TABLE t2
   291    295   }
   292    296   det 3.3.2 {
   293    297     SELECT * FROM t1 WHERE y IN (SELECT y FROM t2 WHERE t1.x!=t2.x)
   294    298   } {
   295    299     QUERY PLAN
   296    300     |--SCAN TABLE t1
   297         -  `--CORRELATED LIST SUBQUERY
          301  +  `--CORRELATED LIST SUBQUERY xxxxxx
   298    302        `--SCAN TABLE t2
   299    303   }
   300    304   det 3.3.3 {
   301    305     SELECT * FROM t1 WHERE EXISTS (SELECT y FROM t2 WHERE t1.x!=t2.x)
   302    306   } {
   303    307     QUERY PLAN
   304    308     |--SCAN TABLE t1
   305         -  `--CORRELATED SCALAR SUBQUERY
          309  +  `--CORRELATED SCALAR SUBQUERY xxxxxx
   306    310        `--SCAN TABLE t2
   307    311   }
   308    312   
   309    313   #-------------------------------------------------------------------------
   310    314   # Test cases eqp-4.* - tests for composite select statements.
   311    315   #
   312    316   do_eqp_test 4.1.1 {
................................................................................
   809    813       AND event.objid=thread.last
   810    814     ORDER BY 1;
   811    815   } {
   812    816     QUERY PLAN
   813    817     |--MATERIALIZE xxxxxx
   814    818     |  |--SCAN TABLE forumpost AS x USING INDEX forumthread
   815    819     |  |--USING ROWID SEARCH ON TABLE private FOR IN-OPERATOR
   816         -  |  |--CORRELATED SCALAR SUBQUERY
          820  +  |  |--CORRELATED SCALAR SUBQUERY xxxxxx
   817    821     |  |  |--SEARCH TABLE forumpost USING COVERING INDEX forumthread (froot=?)
   818    822     |  |  `--USING ROWID SEARCH ON TABLE private FOR IN-OPERATOR
   819    823     |  `--USE TEMP B-TREE FOR ORDER BY
   820    824     |--SCAN SUBQUERY xxxxxx
   821    825     |--SEARCH TABLE blob USING INTEGER PRIMARY KEY (rowid=?)
   822    826     |--SEARCH TABLE event USING INTEGER PRIMARY KEY (rowid=?)
   823    827     `--USE TEMP B-TREE FOR ORDER BY
   824    828   }
   825    829   
   826    830   finish_test

Changes to test/fkey8.test.

   160    160     END;
   161    161   }
   162    162   
   163    163   do_catchsql_test 2.3.1 {
   164    164     DELETE FROM p3 WHERE a=1
   165    165   } {1 {FOREIGN KEY constraint failed}}
   166    166   
          167  +
          168  +do_execsql_test 3.0 {
          169  +  PRAGMA foreign_keys=ON;
          170  +  CREATE TABLE t2(
          171  +    a PRIMARY KEY, b, c, d, e,
          172  +      FOREIGN KEY(b, c) REFERENCES t2(d, e)
          173  +  ) WITHOUT ROWID;
          174  +  CREATE UNIQUE INDEX idx ON t2(d, e);
          175  +
          176  +  INSERT INTO t2 VALUES(1, 'one', 'one', 'one', 'one'); -- row is parent of self
          177  +  INSERT INTO t2 VALUES(2, 'one', 'one', 'one', NULL);  -- parent is row 1
          178  +}
          179  +
          180  +do_catchsql_test 3.1 {
          181  +  DELETE FROM t2 WHERE a=1;
          182  +} {1 {FOREIGN KEY constraint failed}}
          183  +
          184  +do_execsql_test 4.0 {
          185  +  CREATE TABLE t1 (
          186  +      c1 PRIMARY KEY,
          187  +      c2 NUMERIC,
          188  +      FOREIGN KEY(c1) REFERENCES t1(c2)
          189  +      ) WITHOUT ROWID ;
          190  +  CREATE INDEX t1c1 ON t1(c1);
          191  +  CREATE UNIQUE INDEX t1c1unique ON t1(c2);
          192  +}
          193  +do_catchsql_test 4.1 {
          194  +  INSERT OR REPLACE INTO t1 VALUES(10000, 20000);
          195  +} {1 {FOREIGN KEY constraint failed}}
          196  +do_execsql_test 4.2 {
          197  +  INSERT OR REPLACE INTO t1 VALUES(20000, 20000);
          198  +}
          199  +
   167    200   finish_test
          201  +

Changes to test/fts3aa.test.

   246    246   do_execsql_test 9.1 {
   247    247     CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---');
   248    248   }
   249    249   do_execsql_test 9.2 {
   250    250     CREATE VIRTUAL TABLE t10 USING fts3(<, b, c);
   251    251   }
   252    252   
          253  +do_execsql_test 10.0 {
          254  +  CREATE VIRTUAL TABLE z1 USING fts3;
          255  +  INSERT INTO z1 VALUES('one two three'),('four one five'),('six two five');
          256  +  CREATE TRIGGER z1r1 AFTER DELETE ON z1_content BEGIN
          257  +    DELETE FROM z1;
          258  +  END;
          259  +}
          260  +do_catchsql_test 10.1 {
          261  +  DELETE FROM z1;
          262  +} {1 {SQL logic error}}
          263  +
   253    264   expand_all_sql db
   254    265   finish_test

Changes to test/fts3corrupt4.test.

   140    140     UPDATE ft_segdir 
   141    141     SET root = blob('0101056162633132FFFFFFFF070236030132030136');
   142    142   }
   143    143   
   144    144   do_catchsql_test 3.1 {
   145    145     SELECT * FROM ft WHERE ft MATCH 'abc20'
   146    146   } {1 {database disk image is malformed}}
          147  +
          148  +#-------------------------------------------------------------------------
          149  +reset_db
          150  +do_execsql_test 4.0 {
          151  +  CREATE VIRTUAL TABLE t1 USING fts3();
          152  +  INSERT INTO t1 VALUES('one two three');
          153  +  UPDATE t1_segdir SET start_block = 1;
          154  +}
          155  +
          156  +do_catchsql_test 4.1 { 
          157  +  SELECT * FROM t1 WHERE t1 MATCH 'one'; 
          158  +} {1 {database disk image is malformed}}
          159  +do_catchsql_test 4.2 { 
          160  +  SELECT * FROM t1 WHERE t1 MATCH 'two'; 
          161  +} {1 {database disk image is malformed}}
          162  +do_catchsql_test 4.3 { 
          163  +  SELECT * FROM t1 WHERE t1 MATCH 'three'; 
          164  +} {1 {database disk image is malformed}}
          165  +do_execsql_test 4.4 {
          166  +  INSERT INTO t1(t1) VALUES('optimize');
          167  +}
          168  +
          169  +#-------------------------------------------------------------------------
          170  +reset_db
          171  +do_test 5.0 {
          172  +  sqlite3 db {}
          173  +  db deserialize [decode_hexdb {
          174  +| size 24576 pagesize 4096 filename c15.db
          175  +| page 1 offset 0
          176  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          177  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04   .....@  ........
          178  +|     32: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04   ................
          179  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          180  +|     96: 00 00 00 00 0d 0e f9 00 06 0d ec 00 0f cd 0f 69   ...............i
          181  +|    112: 0f 01 0e 10 0e c6 0d ec 00 00 00 00 00 00 00 00   ................
          182  +|   3552: 00 00 00 00 00 00 00 00 00 00 00 00 22 06 06 17   ................
          183  +|   3568: 11 11 01 31 74 61 62 6c 65 74 32 74 32 06 43 52   ...1tablet2t2.CR
          184  +|   3584: 45 41 54 45 20 54 41 42 4c 45 20 74 32 28 78 29   EATE TABLE t2(x)
          185  +|   3600: 81 33 04 07 17 1f 1f 01 82 35 74 61 62 6c 65 74   .3.......5tablet
          186  +|   3616: 31 5f 73 65 67 64 69 72 74 31 5f 73 65 67 64 69   1_segdirt1_segdi
          187  +|   3632: 72 04 43 52 45 41 54 45 20 54 41 42 4c 45 20 27   r.CREATE TABLE '
          188  +|   3648: 74 31 5f 73 65 67 64 69 72 27 28 6c 65 76 65 6c   t1_segdir'(level
          189  +|   3664: 20 49 4e 54 45 47 45 52 2c 69 64 78 20 49 4e 54    INTEGER,idx INT
          190  +|   3680: 45 47 45 52 2c 73 74 61 72 74 5f 62 6c 6f 63 6b   EGER,start_block
          191  +|   3696: 20 49 4e 54 45 47 45 52 2c 6c 65 61 76 65 73 5f    INTEGER,leaves_
          192  +|   3712: 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45   end_block INTEGE
          193  +|   3728: 52 2c 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45   R,end_block INTE
          194  +|   3744: 47 45 52 2c 72 6f 6f 74 20 42 4c 4f 42 2c 50 52   GER,root BLOB,PR
          195  +|   3760: 49 4d 41 52 59 20 4b 45 59 28 6c 65 76 65 6c 2c   IMARY KEY(level,
          196  +|   3776: 20 69 64 78 29 29 31 05 06 17 45 1f 01 00 69 6e    idx))1...E...in
          197  +|   3792: 64 65 78 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e   dexsqlite_autoin
          198  +|   3808: 64 65 79 5f 74 31 5f 73 65 67 64 69 72 5f 31 74   dey_t1_segdir_1t
          199  +|   3824: 31 5f 73 65 67 64 69 72 05 00 00 00 08 00 00 00   1_segdir........
          200  +|   3840: 00 66 03 07 17 23 23 01 81 13 74 61 62 6c 65 74   .f...##...tablet
          201  +|   3856: 31 5f 73 65 67 6d 65 6e 74 73 74 31 5f 73 65 67   1_segmentst1_seg
          202  +|   3872: 6d 65 6e 74 73 03 43 52 45 41 54 45 20 54 41 42   ments.CREATE TAB
          203  +|   3888: 4c 45 20 27 74 31 5f 73 65 67 6d 65 6e 74 73 27   LE 't1_segments'
          204  +|   3904: 28 62 6c 6f 63 6b 69 64 20 49 4e 54 45 47 45 52   (blockid INTEGER
          205  +|   3920: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 6c    PRIMARY KEY, bl
          206  +|   3936: 6f 63 6b 20 42 4c 4f 42 29 62 02 07 17 21 21 01   ock BLOB)b...!!.
          207  +|   3952: 81 0f 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65 6e   ..tablet1_conten
          208  +|   3968: 74 74 31 5f 63 6f 6e 74 65 6e 74 02 43 52 45 41   tt1_content.CREA
          209  +|   3984: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f 6e   TE TABLE 't1_con
          210  +|   4000: 74 65 6e 74 27 28 64 6f 63 69 64 20 49 4e 54 45   tent'(docid INTE
          211  +|   4016: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c   GER PRIMARY KEY,
          212  +|   4032: 20 27 63 30 63 6f 6e 74 65 6e 74 27 29 31 01 06    'c0content')1..
          213  +|   4048: 17 11 11 08 51 74 61 62 6c 65 74 31 74 31 43 52   ....Qtablet1t1CR
          214  +|   4064: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
          215  +|   4080: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
          216  +| page 2 offset 4096
          217  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
          218  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          219  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          220  +| page 3 offset 8192
          221  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
          222  +| page 4 offset 12288
          223  +|      0: 0d 00 00 00 01 0f d6 00 0f d6 00 00 00 00 00 00   ................
          224  +|   4048: 00 00 00 00 00 00 28 01 07 08 08 08 08 15 46 30   ......(.......F0
          225  +|   4064: 20 32 39 00 05 61 62 61 63 6b 03 01 02 00 03 02    29..aback......
          226  +|   4080: 66 74 03 02 02 00 03 04 6e 64 6f 60 30 30 20 00   ft......ndo`00 .
          227  +| page 5 offset 16384
          228  +|      0: a0 00 00 00 10 ff b0 00 ff fb 00 00 00 00 00 00   ................
          229  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 04 04 08 08 09   ................
          230  +| page 6 offset 20480
          231  +|      0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7   ................
          232  +|     16: 0f b8 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64   ..'t1_content'(d
          233  +|     32: 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49   ocid INTEGER PRI
          234  +|     48: 4d 41 52 59 20 4b 45 59 2c 20 27 63 30 63 6f 6e   MARY KEY, 'c0con
          235  +|     64: 74 65 6e 74 27 29 31 01 06 17 11 11 08 51 74 61   tent')1......Qta
          236  +|     80: 62 6c 65 74 31 74 31 43 52 45 41 54 45 20 56 49   blet1t1CREATE VI
          237  +|     96: 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55   RTUAL TABLE t1 U
          238  +|    112: 53 49 4e 47 20 66 74 73 33 0d 00 00 00 03 0f e0   SING fts3.......
          239  +|    128: 00 0f f6 0f ec 0f e0 00 00 00 00 00 00 00 00 00   ................
          240  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f   ...........#auto
          241  +|   4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65   merge=5...#merge
          242  +|   4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72   =100,8...+integr
          243  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
          244  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
          245  +| end c15.db
          246  +}]} {}
          247  +
          248  +do_catchsql_test 5.1 {
          249  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
          250  +} {1 {database disk image is malformed}}
   147    251   
   148    252   finish_test

Added test/fts3fuzz001.test.

            1  +# 2012-12-21
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# Test cases for corrupt database files.
           13  +
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +
           17  +ifcapable !deserialize||!fts3 {
           18  +  finish_test
           19  +  return
           20  +}
           21  +database_may_be_corrupt
           22  +
           23  +do_test fts3fuzz001-100 {
           24  +  sqlite3 db {}
           25  +  db deserialize [decode_hexdb {
           26  +| size 24576 pagesize 4096 filename c6.db
           27  +| page 1 offset 0
           28  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
           29  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06   .....@  ........
           30  +|     32: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 04   ................
           31  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
           32  +|     96: 00 00 00 00 0d 0e f9 00 06 0d ec 00 0f cd 0f 69   ...............i
           33  +|    112: 0f 01 0e 10 0e c6 0d ec 00 00 00 00 00 00 00 00   ................
           34  +|   3552: 00 00 00 00 00 00 00 00 00 00 00 00 22 06 06 17   ............"...
           35  +|   3568: 11 11 01 31 74 61 62 6c 65 74 32 74 32 06 43 52   ...1tablet2t2.CR
           36  +|   3584: 45 41 54 45 20 54 41 42 4c 45 20 74 32 28 78 29   EATE TABLE t2(x)
           37  +|   3600: 81 33 04 07 17 1f 1f 01 82 35 74 61 62 6c 65 74   .3.......5tablet
           38  +|   3616: 31 5f 73 65 67 64 69 72 74 31 5f 73 65 67 64 69   1_segdirt1_segdi
           39  +|   3632: 72 04 43 52 45 41 54 45 20 54 41 42 4c 45 20 27   r.CREATE TABLE '
           40  +|   3648: 74 31 5f 73 65 67 64 69 72 27 28 6c 65 76 65 6c   t1_segdir'(level
           41  +|   3664: 20 49 4e 54 45 47 45 52 2c 69 64 78 20 49 4e 54    INTEGER,idx INT
           42  +|   3680: 45 47 45 52 2c 73 74 61 72 74 5f 62 6c 6f 63 6b   EGER,start_block
           43  +|   3696: 20 49 4e 54 45 47 45 52 2c 6c 65 61 76 65 73 5f    INTEGER,leaves_
           44  +|   3712: 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45   end_block INTEGE
           45  +|   3728: 52 2c 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45   R,end_block INTE
           46  +|   3744: 47 45 52 2c 72 6f 6f 74 20 42 4c 4f 42 2c 50 52   GER,root BLOB,PR
           47  +|   3760: 49 4d 41 52 59 20 4b 45 59 28 6c 65 76 65 6c 2c   IMARY KEY(level,
           48  +|   3776: 20 69 64 78 29 29 31 05 06 17 45 1f 01 00 69 6e    idx))1...E...in
           49  +|   3792: 64 65 78 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e   dexsqlite_autoin
           50  +|   3808: 64 65 78 5f 74 15 f7 36 56 76 46 97 25 f3 17 43   dex_t..6VvF.%..C
           51  +|   3824: 15 5f 73 65 67 64 69 72 05 00 00 00 08 00 00 00   ._segdir........
           52  +|   3840: 00 66 03 07 17 23 23 01 81 13 74 61 62 6c 65 74   .f...##...tablet
           53  +|   3856: 31 5f 73 65 67 6d 65 6e 74 73 74 31 5f 73 65 67   1_segmentst1_seg
           54  +|   3872: 6d 65 6e 74 73 03 43 52 45 41 54 45 20 54 41 42   ments.CREATE TAB
           55  +|   3888: 4c 45 20 27 74 31 5f 73 65 67 6d 65 6e 74 73 27   LE 't1_segments'
           56  +|   3904: 28 62 6c 6f 63 6b 69 64 20 49 4e 54 45 47 45 52   (blockid INTEGER
           57  +|   3920: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 6c    PRIMARY KEY, bl
           58  +|   3936: 6f 63 6b 20 42 4c 4f 42 29 62 02 07 17 21 21 01   ock BLOB)b...!!.
           59  +|   3952: 81 0f 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65 6e   ..tablet1_conten
           60  +|   3968: 74 74 31 5f 63 6f 6e 74 65 6e 74 02 43 52 45 41   tt1_content.CREA
           61  +|   3984: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f 6e   TE TABLE 't1_con
           62  +|   4000: 74 65 6e 74 27 28 64 6f 63 69 64 20 49 4e 54 45   tent'(docid INTE
           63  +|   4016: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c   GER PRIMARY KEY,
           64  +|   4032: 20 27 63 30 63 6f 6e 74 65 6e 74 27 29 31 01 06    'c0content')1..
           65  +|   4048: 17 11 11 08 51 74 61 62 6c 65 74 31 74 31 43 52   ....Qtablet1t1CR
           66  +|   4064: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
           67  +|   4080: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
           68  +| page 2 offset 4096
           69  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
           70  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
           71  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
           72  +| page 3 offset 8192
           73  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
           74  +| page 4 offset 12288
           75  +|      0: 0d 00 00 00 01 0f d6 00 0f 00 00 00 00 00 00 00   ................
           76  +|   4048: 00 00 00 00 00 00 28 01 07 08 08 08 08 15 46 30   ......(.......F0
           77  +|   4064: 20 32 39 00 05 61 62 61 63 6b 03 01 02 00 03 02    29..aback......
           78  +|   4080: 66 74 03 02 02 00 03 04 6e 64 6f 6e 03 03 02 00   ft......ndon....
           79  +| page 5 offset 16384
           80  +|      0: 0a 00 00 00 01 0f fb 00 0f fb 00 00 00 00 00 00   ................
           81  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 04 04 08 08 09   ................
           82  +| page 6 offset 20480
           83  +|      0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7   ................
           84  +|     16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
           85  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f   ...........#auto
           86  +|   4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65   merge=5...#merge
           87  +|   4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72   =100,8...+integr
           88  +|   4064: 69 74 79 3d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity=check....reb
           89  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
           90  +| end c6.db
           91  +  }]
           92  +  catchsql {
           93  +    INSERT INTO t1(t1) SELECT x FROM t2;
           94  +  }
           95  +} {1 {database disk image is malformed}}
           96  +do_test fts3fuzz001-110 {
           97  +  catchsql {
           98  +    INSERT INTO t1(t1) VALUES('integrity-check');
           99  +  }
          100  +} {1 {database disk image is malformed}}
          101  +do_test fts3fuzz001-120 {
          102  +  catchsql {
          103  +    INSERT INTO t1(t1) VALUES('optimize');
          104  +  }
          105  +} {0 {}}
          106  +do_test fts3fuzz001-121 {
          107  +  catchsql {
          108  +    INSERT INTO t1(t1) VALUES('integrity-check');
          109  +  }
          110  +} {1 {database disk image is malformed}}
          111  +
          112  +
          113  +finish_test

Changes to test/fts4umlaut.test.

    18     18   
    19     19   ifcapable !fts3 {
    20     20     finish_test
    21     21     return
    22     22   }
    23     23   
    24     24   do_execsql_test 1.0 {
    25         -  CREATE VIRTUAL TABLE t1 USING fts5(x);
           25  +  CREATE VIRTUAL TABLE t1 USING fts4(x, tokenize=unicode61);
    26     26     CREATE VIRTUAL TABLE t2 USING fts4(
    27     27         x, 
    28     28         tokenize=unicode61 "remove_diacritics=2"
    29     29     );
    30     30   }
    31     31   
    32     32   foreach {tn q res1 res2} {
................................................................................
    45     45     } $res1
    46     46     do_execsql_test 1.$tn.2 {
    47     47       DELETE FROM t1;
    48     48       INSERT INTO t1(rowid, x) VALUES (1, $q);
    49     49       SELECT count(*) FROM t1 WHERE t1 MATCH 'Ha Noi'
    50     50     } $res1
    51     51   
    52         -  do_execsql_test 1.$tn.2 {
           52  +  do_execsql_test 1.$tn.3 {
    53     53       DELETE FROM t2;
    54     54       INSERT INTO t2(rowid, x) VALUES (1, 'Ha Noi');
    55     55       SELECT count(*) FROM t2 WHERE t2 MATCH $q
    56     56     } $res2
    57         -  do_execsql_test 1.$tn.2 {
           57  +  do_execsql_test 1.$tn.4 {
    58     58       DELETE FROM t2;
    59     59       INSERT INTO t2(rowid, x) VALUES (1, $q);
    60     60       SELECT count(*) FROM t2 WHERE t2 MATCH 'Ha Noi'
    61     61     } $res2
    62     62   }
    63     63   
    64     64   finish_test
    65         -

Changes to test/join5.test.

   263    263     SELECT * FROM t1 LEFT JOIN t2 ON (
   264    264       t2.x = t1.x AND (t2.y=? OR (t2.y=? AND t2.z IS NOT NULL))
   265    265     );
   266    266   } {
   267    267     QUERY PLAN
   268    268     |--SCAN TABLE t1
   269    269     `--MULTI-INDEX OR
   270         -     |--SEARCH TABLE t2 USING INDEX t2xy (x=? AND y=?)
   271         -     `--SEARCH TABLE t2 USING INDEX t2xy (x=? AND y=?)
          270  +     |--INDEX 1
          271  +     |  `--SEARCH TABLE t2 USING INDEX t2xy (x=? AND y=?)
          272  +     `--INDEX 2
          273  +        `--SEARCH TABLE t2 USING INDEX t2xy (x=? AND y=?)
   272    274   }
   273    275   
   274    276   do_execsql_test 7.3 {
   275    277     CREATE TABLE t3(x);
   276    278   
   277    279     CREATE TABLE t4(x, y, z);
   278    280     CREATE INDEX t4xy ON t4(x, y);

Changes to test/misc1.test.

   740    740     SELECT a,b,c FROM dup1;
   741    741   } {1 2 3}
   742    742   do_execsql_test misc1-27.1 {
   743    743     UPDATE dup1 SET a=7, b=8, c=9, a=10, b=11, c=12;
   744    744     SELECT a,b,c FROM dup1;
   745    745   } {10 11 12}
   746    746   
          747  +# 2018-12-20
          748  +#
          749  +# The Cursor.seekOp debugging value set incorrectly
          750  +# in OP_NotExists.
          751  +#
          752  +sqlite3 db :memory:
          753  +do_execsql_test misc1-28.0 {
          754  +  CREATE TABLE t1(x);
          755  +  CREATE UNIQUE INDEX t1x ON t1(x) WHERE x=1;
          756  +  INSERT OR ABORT INTO t1 DEFAULT VALUES;
          757  +  UPDATE OR REPLACE t1 SET x = 1;
          758  +  PRAGMA integrity_check;
          759  +  SELECT * FROM t1;
          760  +} {ok 1}
   747    761   
   748    762   finish_test

Changes to test/permutations.test.

   436    436   walbak.test walbig.test walblock.test walcksum.test 
   437    437   walfault.test walhook.test walmode.test walnoshm.test
   438    438   waloverwrite.test walpersist.test walprotocol2.test
   439    439   walprotocol.test walro2.test walrofault.test walro.test
   440    440   walshared.test walslow.test wal.test
   441    441   wal2savepoint.test wal2lock.test wal2recover2.test
   442    442   
   443         -wal2concurrent.test
   444         -concurrent.test concurrent2.test concurrent3.test
   445         -concurrent4.test concurrent5.test concurrent6.test
   446         -concurrent7.test
          443  +  wal2concurrent.test
          444  +  concurrent.test concurrent2.test concurrent3.test
          445  +  concurrent4.test concurrent5.test concurrent6.test
          446  +  concurrent7.test
          447  +  concfault.test concfault2.test
          448  +
          449  +  walvfs.test walfault2.test nockpt.test
          450  +  snapshot2.test snapshot3.test snapshot4.test
          451  +  snapshot_fault.test snapshot.test snapshot_up.test
          452  +  walcrash2.test walcrash3.test walcrash4.test walcrash.test
          453  +  wal2fault.test
   447    454   } 
   448    455   
   449    456   test_suite "coverage-pager" -description {
   450    457     Coverage tests for file pager.c.
   451    458   } -files {
   452    459     pager1.test    pager2.test  pagerfault.test  pagerfault2.test
   453    460     walfault.test  walbak.test  journal2.test    tkt-9d68c883.test

Changes to test/rowvalue4.test.

   231    231   do_eqp_test 5.1 {
   232    232     SELECT * FROM d2 WHERE 
   233    233       (a, b) IN (SELECT x, y FROM d1) AND
   234    234       (c) IN (SELECT y FROM d1)
   235    235   } {
   236    236     QUERY PLAN
   237    237     |--SEARCH TABLE d2 USING INDEX d2ab (a=? AND b=?)
   238         -  |--LIST SUBQUERY
          238  +  |--LIST SUBQUERY xxxxxx
   239    239     |  `--SCAN TABLE d1
   240         -  `--LIST SUBQUERY
          240  +  `--LIST SUBQUERY xxxxxx
   241    241        `--SCAN TABLE d1
   242    242   }
   243    243   
   244    244   do_execsql_test 6.0 {
   245    245     CREATE TABLE e1(a, b, c, d, e);
   246    246     CREATE INDEX e1ab ON e1(a, b);
   247    247     CREATE INDEX e1cde ON e1(c, d, e);

Changes to test/snapshot_fault.test.

   217    217     db eval COMMIT
   218    218   } -body {
   219    219     sqlite3_snapshot_recover db main
   220    220   } -test {
   221    221     faultsim_test_result {0 {}} {1 SQLITE_IOERR}
   222    222   }
   223    223   
          224  +#-------------------------------------------------------------------------
          225  +# Test the handling of faults that occur within sqlite3_snapshot_get().
          226  +#
          227  +reset_db
          228  +do_execsql_test 5.0 {
          229  +  PRAGMA page_size = 512;
          230  +  PRAGMA journal_mode = wal;
          231  +  PRAGMA wal_autocheckpoint = 0;
          232  +  CREATE TABLE t1(zzz);
          233  +  INSERT INTO t1 VALUES(randomblob( 5000 ));
          234  +  PRAGMA user_version = 211;
          235  +} {wal 0}
          236  +faultsim_save_and_close
          237  +
          238  +do_faultsim_test 5 -prep {
          239  +  faultsim_restore_and_reopen
          240  +  execsql { SELECT count(*) FROM sqlite_master }
          241  +  execsql BEGIN
          242  +} -body {
          243  +  sqlite3_snapshot_get_blob db main
          244  +  set {} {}
          245  +} -test {
          246  +  execsql END
          247  +  faultsim_test_result {0 {}} {1 SQLITE_IOERR} {1 SQLITE_NOMEM}
          248  +}
   224    249   
   225    250   
   226    251   finish_test

Changes to test/tkt-80ba201079.test.

   106    106                AND entry_id IN (SELECT change_id
   107    107                                 FROM object_changes
   108    108                                  WHERE obj_context = 'exported_pools'));
   109    109     }
   110    110   } {300 object_change 2048}
   111    111   do_test tkt-80ba2-201 {
   112    112     db eval {
          113  +PRAGMA vdbe_debug=on;
          114  +PRAGMA vdbe_addoptrace=on;
   113    115       CREATE INDEX timeline_entry_id_idx on timeline(entry_id);
   114    116       SELECT entry_type,
   115    117              entry_types.name,
   116    118              entry_id
   117    119         FROM timeline JOIN entry_types ON entry_type = entry_types.id
   118    120        WHERE (entry_types.name = 'cli_command' AND entry_id=2114)
   119    121           OR (entry_types.name = 'object_change'

Changes to test/triggerC.test.

  1038   1038   
  1039   1039     INSERT INTO x1 VALUES('go!');
  1040   1040   }
  1041   1041   
  1042   1042   do_execsql_test 15.2.2 { SELECT * FROM x2;       } {1 2 3 4}
  1043   1043   do_execsql_test 15.2.3 { SELECT * FROM """x2"""; } {3 11 x y}
  1044   1044   
         1045  +#-------------------------------------------------------------------------
         1046  +# At one point queries such as the following were causing segfaults.
         1047  +#
         1048  +do_catchsql_test 16.1 {
         1049  +  SELECT raise(ABORT, 'msg') FROM sqlite_master 
         1050  +  UNION SELECT 1 
         1051  +  ORDER BY raise(IGNORE);
         1052  +} {1 {1st ORDER BY term does not match any column in the result set}}
         1053  +
         1054  +do_catchsql_test 16.2 {
         1055  +  SELECT count(*) FROM sqlite_master 
         1056  +  GROUP BY raise(IGNORE) 
         1057  +  HAVING raise(ABORT, 'msg');
         1058  +} {1 {RAISE() may only be used within a trigger-program}}
         1059  +
  1045   1060   finish_test
         1061  +

Changes to test/triggerF.test.

    16     16   ifcapable {!trigger} {
    17     17     finish_test
    18     18     return
    19     19   }
    20     20   
    21     21   
    22     22   foreach {tn sql log} {
    23         -  1 { } { }
           23  +  1 {} {}
    24     24   
    25     25     2 { 
    26     26       CREATE TRIGGER trd AFTER DELETE ON t1 BEGIN
    27     27         INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
    28     28       END;
    29     29     } {1one2 2two1 3three1}
    30     30   

Changes to test/unionvtab.test.

   369    369   do_execsql_test 4.3.3 {
   370    370     SELECT * FROM sl WHERE rowid<=-9223372036854775808
   371    371   } {
   372    372     -9223372036854775808 one
   373    373   }
   374    374   do_execsql_test 4.3.4 {
   375    375     SELECT * FROM sl WHERE rowid<-9223372036854775808
   376         -} { }
          376  +} {}
   377    377   
   378    378   do_execsql_test 4.4.1 {
   379    379     SELECT * FROM sl WHERE rowid<9223372036854775807
   380    380   } {
   381    381     -9223372036854775808 one -9223372036854775807 two -9223372036854775806 three
   382    382      9223372036854775805 four 9223372036854775806 five
   383    383   }
................................................................................
   390    390   do_execsql_test 4.4.3 {
   391    391     SELECT * FROM sl WHERE rowid>=9223372036854775807
   392    392   } {
   393    393     9223372036854775807 six
   394    394   }
   395    395   do_execsql_test 4.4.4 {
   396    396     SELECT * FROM sl WHERE rowid>9223372036854775807
   397         -} { }
          397  +} {}
   398    398   
   399    399   #-------------------------------------------------------------------------
   400    400   # More than 8 source tables.
   401    401   #
   402    402   do_execsql_test 5.0 {
   403    403     CREATE TABLE c0(one, two INTEGER PRIMARY KEY);
   404    404     CREATE TABLE c1(one, two INTEGER PRIMARY KEY);

Changes to test/vacuum-into.test.

    61     61     CREATE TABLE t2(name TEXT);
    62     62     INSERT INTO t2 VALUES(':memory:');
    63     63     VACUUM main INTO (SELECT name FROM t2);
    64     64   } {}
    65     65   do_catchsql_test vacuum-into-310 {
    66     66     VACUUM INTO null;
    67     67   } {1 {non-text filename}}
           68  +do_catchsql_test vacuum-into-320 {
           69  +  VACUUM INTO x;
           70  +} {1 {no such column: x}}
           71  +do_catchsql_test vacuum-into-330 {
           72  +  VACUUM INTO t1.nosuchcol;
           73  +} {1 {no such column: t1.nosuchcol}}
           74  +do_catchsql_test vacuum-into-340 {
           75  +  VACUUM INTO main.t1.nosuchcol;
           76  +} {1 {no such column: main.t1.nosuchcol}}
           77  +
           78  +forcedelete test.db2
           79  +db func target target
           80  +proc target {} { return "test.db2" }
           81  +do_test vacuum-into-410 {
           82  +  execsql { VACUUM INTO target() }
           83  +  file exists test.db2
           84  +} 1
           85  +do_catchsql_test vacuum-into-420 {
           86  +  VACUUM INTO target2()
           87  +} {1 {no such function: target2}}
           88  +
    68     89   
    69     90   finish_test

Added test/vtabdrop.test.

            1  +# 2018 December 28
            2  +#
            3  +#    May you do good and not evil.
            4  +#    May you find forgiveness for yourself and forgive others.
            5  +#    May you share freely, never taking more than you give.
            6  +#
            7  +#***********************************************************************
            8  +#
            9  +# The tests in this file test edge cases surrounding DROP TABLE on 
           10  +# virtual tables.
           11  +#
           12  +
           13  +set testdir [file dirname $argv0]
           14  +source $testdir/tester.tcl
           15  +
           16  +ifcapable !vtab { finish_test ; return }
           17  +source $testdir/fts3_common.tcl
           18  +source $testdir/malloc_common.tcl
           19  +
           20  +set testprefix vtabdrop
           21  +
           22  +#-------------------------------------------------------------------------
           23  +# Test that if a DROP TABLE is executed against an rtree table, but the
           24  +# xDestroy() call fails, the rtree table is not dropped, the sqlite_master
           25  +# table is not modified and the internal schema remains intact.
           26  +# 
           27  +ifcapable rtree {
           28  +  do_execsql_test 1.0 {
           29  +    CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2);
           30  +    CREATE TABLE t1(x, y);
           31  +    INSERT INTO t1 VALUES(1, 2);
           32  +  }
           33  +  
           34  +  do_test 1.1 {
           35  +    execsql {
           36  +      BEGIN;
           37  +        INSERT INTO t1 VALUES(3, 4);
           38  +    }
           39  +    db eval { SELECT * FROM t1 } {
           40  +      catchsql { DROP TABLE rt }
           41  +    }
           42  +    execsql COMMIT
           43  +  } {}
           44  +  
           45  +  do_execsql_test 1.2 {
           46  +    SELECT name FROM sqlite_master ORDER BY 1;
           47  +    SELECT * FROM t1;
           48  +    SELECT * FROM rt;
           49  +  } {rt rt_node rt_parent rt_rowid t1 1 2 3 4}
           50  +  
           51  +  db close
           52  +  sqlite3 db test.db
           53  +  
           54  +  do_execsql_test 1.3 {
           55  +    SELECT name FROM sqlite_master ORDER BY 1;
           56  +  } {rt rt_node rt_parent rt_rowid t1}
           57  +}
           58  +
           59  +#-------------------------------------------------------------------------
           60  +# Same as tests 1.*, except with fts5 instead of rtree.
           61  +# 
           62  +ifcapable fts5 {
           63  +  reset_db
           64  +  do_execsql_test 2.0 {
           65  +    CREATE VIRTUAL TABLE ft USING fts5(x);
           66  +    CREATE TABLE t1(x, y);
           67  +    INSERT INTO t1 VALUES(1, 2);
           68  +  }
           69  +  
           70  +  do_test 2.1 {
           71  +    execsql {
           72  +      BEGIN;
           73  +        INSERT INTO t1 VALUES(3, 4);
           74  +    }
           75  +    db eval { SELECT * FROM t1 } {
           76  +      catchsql { DROP TABLE ft }
           77  +    }
           78  +    execsql COMMIT
           79  +  } {}
           80  +  
           81  +  do_execsql_test 2.2 {
           82  +    SELECT name FROM sqlite_master ORDER BY 1;
           83  +  } {ft ft_config ft_content ft_data ft_docsize ft_idx t1}
           84  +  
           85  +  db close
           86  +  sqlite3 db test.db
           87  +  
           88  +  do_execsql_test 2.3 {
           89  +    SELECT name FROM sqlite_master ORDER BY 1;
           90  +  } {ft ft_config ft_content ft_data ft_docsize ft_idx t1}
           91  +}
           92  +
           93  +#-------------------------------------------------------------------------
           94  +# Same as tests 1.*, except with fts3 instead of rtree.
           95  +# 
           96  +ifcapable fts3 {
           97  +  reset_db
           98  +  do_execsql_test 2.0 {
           99  +    CREATE VIRTUAL TABLE ft USING fts3(x);
          100  +    CREATE TABLE t1(x, y);
          101  +    INSERT INTO t1 VALUES(1, 2);
          102  +  }
          103  +  
          104  +  do_test 2.1 {
          105  +    execsql {
          106  +      BEGIN;
          107  +        INSERT INTO t1 VALUES(3, 4);
          108  +    }
          109  +    db eval { SELECT * FROM t1 } {
          110  +      catchsql { DROP TABLE ft }
          111  +    }
          112  +    execsql COMMIT
          113  +  } {}
          114  +  
          115  +  do_execsql_test 2.2 {
          116  +    SELECT name FROM sqlite_master ORDER BY 1;
          117  +  } {ft ft_content ft_segdir ft_segments sqlite_autoindex_ft_segdir_1 t1}
          118  +  
          119  +  db close
          120  +  sqlite3 db test.db
          121  +  
          122  +  do_execsql_test 2.3 {
          123  +    SELECT name FROM sqlite_master ORDER BY 1;
          124  +  } {ft ft_content ft_segdir ft_segments sqlite_autoindex_ft_segdir_1 t1}
          125  +}
          126  +
          127  +finish_test

Changes to test/wal.test.

  1170   1170     5   2048    1
  1171   1171     6   4096    1
  1172   1172     7   8192    1
  1173   1173     8  16384    1
  1174   1174     9  32768    1
  1175   1175    10  65536    1
  1176   1176    11 131072    0
  1177         - 11   1016    0
         1177  + 12   1016    0
  1178   1178   } {
  1179   1179   
  1180   1180     if {$::SQLITE_MAX_PAGE_SIZE < $pgsz} {
  1181   1181       set works 0
  1182   1182     }
  1183   1183   
  1184   1184     for {set pg 1} {$pg <= 3} {incr pg} {
  1185   1185       forcecopy testX.db test.db
  1186   1186       forcedelete test.db-wal
  1187         -  
         1187  +
  1188   1188       # Check that the database now exists and consists of three pages. And
  1189   1189       # that there is no associated wal file.
  1190   1190       #
  1191   1191       do_test wal-18.2.$tn.$pg.1 { file exists test.db-wal } 0
  1192   1192       do_test wal-18.2.$tn.$pg.2 { file exists test.db } 1
  1193   1193       do_test wal-18.2.$tn.$pg.3 { file size test.db } [expr 1024*3]
  1194         -  
         1194  +
  1195   1195       do_test wal-18.2.$tn.$pg.4 {
  1196   1196   
  1197   1197         # Create a wal file that contains a single frame (database page
  1198   1198         # number $pg) with the commit flag set. The frame checksum is
  1199   1199         # correct, but the contents of the database page are corrupt.
  1200   1200         #
  1201   1201         # The page-size in the log file header is set to $pgsz. If the
................................................................................
  1219   1219   
  1220   1220         set fd [open test.db-wal w]
  1221   1221         fconfigure $fd -encoding binary -translation binary
  1222   1222         puts -nonewline $fd $walhdr
  1223   1223         puts -nonewline $fd $framehdr
  1224   1224         puts -nonewline $fd $framebody
  1225   1225         close $fd
  1226         -  
         1226  +
  1227   1227         file size test.db-wal
  1228   1228       } [wal_file_size 1 $pgsz]
  1229         -  
         1229  +
  1230   1230       do_test wal-18.2.$tn.$pg.5 {
  1231   1231         sqlite3 db test.db
  1232   1232         set rc [catch { db one {PRAGMA integrity_check} } msg]
  1233   1233         expr { $rc!=0 || $msg!="ok" }
  1234   1234       } $works
  1235         -  
         1235  + 
  1236   1236       db close
  1237   1237     }
  1238   1238   }
  1239   1239   
  1240   1240   #-------------------------------------------------------------------------
  1241   1241   # The following test - wal-19.* - fixes a bug that was present during
  1242   1242   # development.

Added test/wal2fault.test.

            1  +# 2010 May 03
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing the operation of the library in
           13  +# "PRAGMA journal_mode=WAL" mode.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +source $testdir/malloc_common.tcl
           19  +source $testdir/lock_common.tcl
           20  +
           21  +ifcapable !wal {finish_test ; return }
           22  +set testprefix wal2fault
           23  +
           24  +do_execsql_test 1.0 {
           25  +  CREATE TABLE t1(x,y);
           26  +  PRAGMA journal_mode = wal2;
           27  +  WITH s(i) AS ( SELECT 100 UNION ALL SELECT i-1 FROM s WHERE (i-1)>0 )
           28  +  INSERT INTO t1 SELECT i, randomblob(i) FROM s;
           29  +  WITH s(i) AS ( SELECT 100 UNION ALL SELECT i-1 FROM s WHERE (i-1)>0 )
           30  +  INSERT INTO t1 SELECT i, randomblob(i) FROM s;
           31  +} {wal2}
           32  +
           33  +do_test 1.1 {
           34  +  expr [file size test.db-wal]>10000
           35  +} {1}
           36  +faultsim_save_and_close
           37  +
           38  +do_faultsim_test 1 -prep {
           39  +  faultsim_restore_and_reopen
           40  +  execsql {
           41  +    PRAGMA journal_size_limit = 10000;
           42  +    SELECT count(*) FROM sqlite_master;
           43  +  }
           44  +} -body {
           45  +  execsql {
           46  +    INSERT INTO t1 VALUES(1, 2);
           47  +  }
           48  +} -test {
           49  +  faultsim_test_result {0 {}}
           50  +}
           51  +
           52  +finish_test

Changes to test/wal2recover2.test.

   216    216         SELECT sum(x) FROM t1;
   217    217         SELECT sum(x) FROM t2;
   218    218       } db2
   219    219     } $res
   220    220     db2 close
   221    221   }
   222    222   
          223  +
          224  +#-------------------------------------------------------------------------
          225  +reset_db
          226  +do_execsql_test 1.8.1 {
          227  +  PRAGMA autovacuum = 0;
          228  +  PRAGMA page_size = 4096;
          229  +  CREATE TABLE t1(x);
          230  +  CREATE TABLE t2(x);
          231  +  WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1500 )
          232  +    INSERT INTO t1 SELECT i FROM s;
          233  +  WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1500 )
          234  +    INSERT INTO t2 SELECT i FROM s;
          235  +
          236  +  PRAGMA journal_mode = wal2;
          237  +  PRAGMA journal_size_limit = 10000;
          238  +
          239  +  WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1500 )
          240  +    INSERT INTO t2 SELECT i FROM s;
          241  +} {wal2 10000}
          242  +
          243  +do_test 1.8.2 {
          244  +  list [file size test.db-wal] [file size test.db-wal2]
          245  +} {24752 0}
          246  +
          247  +do_execsql_test 1.8.3 { PRAGMA user_version = 123 }
          248  +do_test 1.8.4 {
          249  +  list [file size test.db-wal] [file size test.db-wal2]
          250  +} {24752 4152}
          251  +
          252  +do_test 1.8.5 {
          253  +  hexio_write test.db-wal2 [expr 56+16] 0400
          254  +  fix_wal_cksums test.db-wal2
          255  +} {}
          256  +
          257  +do_test 1.8.6 {
          258  +  forcecopy test.db test.db2
          259  +  forcecopy test.db-wal test.db2-wal
          260  +  forcecopy test.db-wal2 test.db2-wal2
          261  +  sqlite3 db2 test.db2
          262  +  catchsql { SELECT * FROM sqlite_master } db2
          263  +} {1 {database disk image is malformed}}
          264  +db2 close
          265  +
   223    266   #-------------------------------------------------------------------------
   224    267   reset_db
   225    268   do_execsql_test 1.0 {
   226    269     CREATE TABLE t1(a, b, c);
   227    270     CREATE INDEX t1a ON t1(a);
   228    271     CREATE INDEX t1b ON t1(b);
   229    272     CREATE INDEX t1c ON t1(c);

Added test/wal2rollback.test.

            1  +# 2017 September 19
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing the operation of the library in
           13  +# "PRAGMA journal_mode=WAL2" mode.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +source $testdir/lock_common.tcl
           19  +source $testdir/malloc_common.tcl
           20  +source $testdir/wal_common.tcl
           21  +
           22  +set testprefix wal2rollback
           23  +ifcapable !wal {finish_test ; return }
           24  +
           25  +do_execsql_test 1.0 {
           26  +  CREATE TABLE t1(a, b, c);
           27  +  CREATE TABLE t2(a, b, c);
           28  +  CREATE INDEX i1 ON t1(a);
           29  +  CREATE INDEX i2 ON t1(b);
           30  +  PRAGMA journal_mode = wal2;
           31  +  PRAGMA cache_size = 5;
           32  +  PRAGMA journal_size_limit = 10000;
           33  +  WITH s(i) AS (
           34  +    SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 1000
           35  +  )
           36  +  INSERT INTO t1 SELECT i, i, randomblob(200) FROM s;
           37  +} {wal2 10000}
           38  +
           39  +do_test 1.1 {
           40  +  expr [file size test.db-wal] > 10000
           41  +} 1
           42  +
           43  +do_test 1.2 {
           44  +  execsql {
           45  +    BEGIN;
           46  +      UPDATE t1 SET b=b+1;
           47  +      INSERT INTO t2 VALUES(1,2,3);
           48  +  }
           49  +  expr [file size test.db-wal2] > 10000
           50  +} {1}
           51  +
           52  +breakpoint
           53  +do_execsql_test 1.3 {
           54  +  ROLLBACK;
           55  +  SELECT * FROM t2;
           56  +  SELECT count(*) FROM t1 WHERE a=b;
           57  +  PRAGMA integrity_check;
           58  +} {1000 ok}
           59  +
           60  +
           61  +
           62  +finish_test

Changes to test/wal2savepoint.test.

    51     51       ROLLBACK TO abc;
    52     52       WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s where i < 10)
    53     53       INSERT INTO t1 SELECT random(), random(), random() FROM s;
    54     54     COMMIT;
    55     55     SELECT count(*) FROM t1;
    56     56     PRAGMA integrity_check;
    57     57   } {210 ok}
           58  +
           59  +do_execsql_test 1.4 {
           60  +  BEGIN;
           61  +    SAVEPOINT abc;
           62  +      WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s where i < 100)
           63  +      INSERT INTO t1 SELECT random(), random(), random() FROM s;
           64  +    ROLLBACK TO abc;
           65  +    WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s where i < 10)
           66  +    INSERT INTO t1 SELECT random(), random(), random() FROM s;
           67  +  COMMIT;
           68  +  SELECT count(*) FROM t1;
           69  +  PRAGMA integrity_check;
           70  +} {220 ok}
    58     71   
    59     72   
    60     73   finish_test
    61     74   

Changes to test/wal2snapshot.test.

    63     63       do_test 1.6 {
    64     64         execsql BEGIN
    65     65         set SNAPSHOT [sqlite3_snapshot_get_blob db main]
    66     66         sqlite3_snapshot_open_blob db main $SNAPSHOT
    67     67         execsql COMMIT
    68     68       } {}
    69     69     } else {
    70         -    do_test 2.6 {
           70  +
           71  +    do_test 2.6.1 {
           72  +      execsql BEGIN
           73  +      set res [
           74  +        list [catch { sqlite3_snapshot_open_blob db main $SNAPSHOT } msg] $msg
           75  +      ]
           76  +      execsql COMMIT
           77  +      set res
           78  +    } {1 SQLITE_ERROR}
           79  +    do_test 2.6.2 {
    71     80         execsql BEGIN
           81  +      execsql {SELECT * FROM sqlite_master}
    72     82         set res [
    73     83           list [catch { sqlite3_snapshot_open_blob db main $SNAPSHOT } msg] $msg
    74     84         ]
    75     85         execsql COMMIT
    76     86         set res
    77     87       } {1 SQLITE_ERROR}
    78     88     }
    79     89   }
    80     90   
    81     91   
    82     92   finish_test
    83     93   
    84     94   

Added test/walfault2.test.

            1  +# 2010 May 03
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing the operation of the library in
           13  +# "PRAGMA journal_mode=WAL" mode.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +source $testdir/malloc_common.tcl
           19  +source $testdir/lock_common.tcl
           20  +
           21  +ifcapable !wal {finish_test ; return }
           22  +set testprefix walfault2
           23  +
           24  +#-------------------------------------------------------------------------
           25  +# Inject faults while truncating the wal file.
           26  +#
           27  +do_execsql_test 1.0 {
           28  +  PRAGMA auto_vacuum = 0;
           29  +  CREATE TABLE t1(a, b);
           30  +  PRAGMA journal_mode = wal;
           31  +  WITH s(i) AS (
           32  +    SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 30
           33  +  )
           34  +  INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s;
           35  +} {wal}
           36  +faultsim_save_and_close
           37  +
           38  +do_faultsim_test 1 -prep {
           39  +  faultsim_restore
           40  +  sqlite3 db file:test.db?psow=0 -uri 1
           41  +  file_control_powersafe_overwrite db 0
           42  +  execsql {
           43  +    PRAGMA wal_checkpoint;
           44  +    PRAGMA journal_size_limit = 10000;
           45  +    PRAGMA synchronous = full;
           46  +  }
           47  +} -body {
           48  +  execsql { INSERT INTO t1 VALUES(1,1) }
           49  +} -test {
           50  +  faultsim_test_result {0 {}}
           51  +}
           52  +
           53  +#-------------------------------------------------------------------------
           54  +# Inject faults while rewriting checksums.
           55  +#
           56  +reset_db
           57  +do_execsql_test 2.0 {
           58  +  PRAGMA auto_vacuum = 0;
           59  +  CREATE TABLE t1(a, b);
           60  +  PRAGMA journal_mode = wal;
           61  +  WITH s(i) AS (
           62  +    SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 30
           63  +  )
           64  +  INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s;
           65  +} {wal}
           66  +faultsim_save_and_close
           67  +
           68  +do_faultsim_test 2 -prep {
           69  +  faultsim_restore_and_reopen
           70  +  execsql {
           71  +    PRAGMA cache_size = 2;
           72  +    BEGIN;
           73  +    UPDATE t1 SET a=randomblob(400);
           74  +    UPDATE t1 SET b=randomblob(400);
           75  +    UPDATE t1 SET a=randomblob(400);
           76  +    UPDATE t1 SET b=randomblob(400);
           77  +    UPDATE t1 SET a=randomblob(400);
           78  +    UPDATE t1 SET b=randomblob(400);
           79  +    UPDATE t1 SET a=randomblob(400);
           80  +    UPDATE t1 SET b=randomblob(400);
           81  +  }
           82  +} -body {
           83  +  execsql COMMIT
           84  +} -test {
           85  +  faultsim_test_result {0 {}}
           86  +}
           87  +
           88  +
           89  +
           90  +finish_test

Changes to test/walrofault.test.

    50     50     faultsim_restore
    51     51     sqlite3 db file:test.db?readonly_shm=1
    52     52   } -body {
    53     53     execsql { SELECT * FROM t1 }
    54     54   } -test {
    55     55     faultsim_test_result {0 {hello world ! world hello}}
    56     56   }
    57         -
    58         -
    59     57   
    60     58   finish_test

Added test/walvfs.test.

            1  +# 2018 December 23
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing the operation of the library in
           13  +# "PRAGMA journal_mode=WAL" mode.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +source $testdir/lock_common.tcl
           19  +source $testdir/malloc_common.tcl
           20  +source $testdir/wal_common.tcl
           21  +set testprefix walvfs
           22  +
           23  +ifcapable !wal {finish_test ; return }
           24  +
           25  +db close
           26  +testvfs tvfs 
           27  +tvfs script xSync
           28  +tvfs filter xSync
           29  +set ::sync_count 0
           30  +proc xSync {method file args} {
           31  +  if {[file tail $file]=="test.db-wal"} {
           32  +    incr ::sync_count
           33  +  }
           34  +}
           35  +
           36  +
           37  +#-------------------------------------------------------------------------
           38  +# Test that if IOCAP_SEQUENTIAL is set, the wal-header is not synced to
           39  +# disk immediately after it is written.
           40  +#
           41  +sqlite3 db test.db -vfs tvfs
           42  +do_execsql_test 1.0 {
           43  +  PRAGMA auto_vacuum = 0;
           44  +  PRAGMA journal_mode = wal;
           45  +  PRAGMA synchronous = normal;
           46  +  CREATE TABLE t1(a, b, c);
           47  +  INSERT INTO t1 VALUES(1, 2, 3);
           48  +  INSERT INTO t1 VALUES(4, 5, 6);
           49  +  INSERT INTO t1 VALUES(7, 8, 9);
           50  +  PRAGMA wal_checkpoint;
           51  +} {wal 0 5 5}
           52  +
           53  +set ::sync_count 0
           54  +do_test 1.1 {
           55  +  execsql { INSERT INTO t1 VALUES(10, 11, 12) }
           56  +  set ::sync_count
           57  +} 1
           58  +
           59  +db close
           60  +tvfs devchar sequential
           61  +sqlite3 db test.db -vfs tvfs
           62  +do_execsql_test 1.2 {
           63  +  PRAGMA synchronous = normal;
           64  +  INSERT INTO t1 VALUES(13, 14, 15);
           65  +  INSERT INTO t1 VALUES(16, 17, 18);
           66  +  PRAGMA wal_checkpoint;
           67  +} {0 4 4}
           68  +
           69  +set ::sync_count 0
           70  +do_test 1.3 {
           71  +  execsql { INSERT INTO t1 VALUES(10, 11, 12) }
           72  +  set ::sync_count
           73  +} 0
           74  +
           75  +#-------------------------------------------------------------------------
           76  +# Test that "PRAGMA journal_size_limit" works in wal mode.
           77  +#
           78  +reset_db
           79  +do_execsql_test 2.0 {
           80  +  PRAGMA journal_size_limit = 10000;
           81  +  CREATE TABLE t1(x);
           82  +  PRAGMA journal_mode = wal;
           83  +  WITH s(i) AS (
           84  +    SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20
           85  +  )
           86  +  INSERT INTO t1 SELECT randomblob(750) FROM s;
           87  +} {10000 wal}
           88  +do_test 2.1 {
           89  +  expr [file size test.db-wal]>12000
           90  +} {1}
           91  +do_test 2.2 {
           92  +  execsql {
           93  +    PRAGMA wal_checkpoint;
           94  +    INSERT INTO t1 VALUES(randomblob(750));
           95  +  }
           96  +  file size test.db-wal
           97  +} {10000}
           98  +do_test 2.3 {
           99  +  execsql {
          100  +    PRAGMA journal_size_limit = 8000;
          101  +    PRAGMA wal_checkpoint;
          102  +    INSERT INTO t1 VALUES(randomblob(750));
          103  +  }
          104  +  file size test.db-wal
          105  +} {8000}
          106  +
          107  +#-------------------------------------------------------------------------
          108  +# Test that a checkpoint may be interrupted using sqlite3_interrupt().
          109  +# And that the error code is SQLITE_NOMEM, not SQLITE_INTERRUPT, if
          110  +# an OOM error occurs just before the sqlite3_interrupt() call.
          111  +#
          112  +reset_db
          113  +db close
          114  +sqlite3 db test.db -vfs tvfs
          115  +tvfs filter {}
          116  +
          117  +do_execsql_test 3.0 {
          118  +  CREATE TABLE t1(x);
          119  +  PRAGMA journal_mode = wal;
          120  +  WITH s(i) AS (
          121  +    SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20
          122  +  )
          123  +  INSERT INTO t1 SELECT randomblob(750) FROM s;
          124  +} {wal}
          125  +
          126  +tvfs filter xWrite
          127  +tvfs script xWrite
          128  +set ::cnt 2
          129  +proc xWrite {method file args} {
          130  +  if {[file tail $file]=="test.db"} {
          131  +    incr ::cnt -1
          132  +    if {$::cnt==0} {
          133  +      sqlite3_interrupt db
          134  +    }
          135  +  }
          136  +  return SQLITE_OK
          137  +}
          138  +
          139  +do_catchsql_test 3.1 {
          140  +  PRAGMA wal_checkpoint
          141  +} {1 interrupted}
          142  +
          143  +set ::cnt 2
          144  +proc xWrite {method file args} {
          145  +  if {[file tail $file]=="test.db"} {
          146  +    incr ::cnt -1
          147  +    if {$::cnt==0} {
          148  +      sqlite3_memdebug_fail 5 -repeat 0
          149  +      catchsql { SELECT 'a big long string!' }
          150  +      sqlite3_interrupt db
          151  +    }
          152  +  }
          153  +  return SQLITE_OK
          154  +}
          155  +
          156  +do_catchsql_test 3.2 {
          157  +  PRAGMA wal_checkpoint
          158  +} {1 {out of memory}}
          159  +
          160  +#-------------------------------------------------------------------------
          161  +#
          162  +reset_db
          163  +db close
          164  +do_test 4.0 {
          165  +  sqlite3 db test.db -vfs tvfs
          166  +  execsql {
          167  +    CREATE TABLE t1(x);
          168  +    PRAGMA journal_mode = wal;
          169  +    WITH s(i) AS (
          170  +        SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20
          171  +    )
          172  +    INSERT INTO t1 SELECT randomblob(750) FROM s;
          173  +  } db
          174  +} {wal}
          175  +db close
          176  +
          177  +tvfs filter xShmMap
          178  +tvfs script xShmMap
          1