/ Check-in [2e573350]
Login

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

Overview
Comment:Merge latest trunk changes with this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | shared-mapping-hack
Files: files | file ages | folders
SHA3-256: 2e57335081287a2db9fd20d86a8e98218309a37569e1ca1df8deb5fb198d73ff
User & Date: dan 2017-09-18 08:51:04
Context
2017-09-18
08:51
Merge latest trunk changes with this branch. Leaf check-in: 2e573350 user: dan tags: shared-mapping-hack
00:18
Fix the CSV virtual table extension so that it works when the default character is unsigned. check-in: 42f07775 user: drh tags: trunk
2017-09-12
18:11
Merge the mutex-free PRNG change into this branch. check-in: 8b1fc4b9 user: dan tags: shared-mapping-hack
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/csv.c.

    74     74   struct CsvReader {
    75     75     FILE *in;              /* Read the CSV text from this input stream */
    76     76     char *z;               /* Accumulated text for a field */
    77     77     int n;                 /* Number of bytes in z */
    78     78     int nAlloc;            /* Space allocated for z[] */
    79     79     int nLine;             /* Current line number */
    80     80     int bNotFirst;         /* True if prior text has been seen */
    81         -  char cTerm;            /* Character that terminated the most recent field */
           81  +  int cTerm;             /* Character that terminated the most recent field */
    82     82     size_t iIn;            /* Next unread character in the input buffer */
    83     83     size_t nIn;            /* Number of characters in the input buffer */
    84     84     char *zIn;             /* The input buffer */
    85     85     char zErr[CSV_MXERR];  /* Error message */
    86     86   };
    87     87   
    88     88   /* Initialize a CsvReader object */
................................................................................
   162    162   
   163    163   /* Return the next character of input.  Return EOF at end of input. */
   164    164   static int csv_getc(CsvReader *p){
   165    165     if( p->iIn >= p->nIn ){
   166    166       if( p->in!=0 ) return csv_getc_refill(p);
   167    167       return EOF;
   168    168     }
   169         -  return p->zIn[p->iIn++];
          169  +  return ((unsigned char*)p->zIn)[p->iIn++];
   170    170   }
   171    171   
   172    172   /* Increase the size of p->z and append character c to the end. 
   173    173   ** Return 0 on success and non-zero if there is an OOM error */
   174    174   static CSV_NOINLINE int csv_resize_and_append(CsvReader *p, char c){
   175    175     char *zNew;
   176    176     int nNew = p->nAlloc*2 + 100;

Changes to src/expr.c.

  1298   1298   ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
  1299   1299     ExprList *pNew;
  1300   1300     struct ExprList_item *pItem, *pOldItem;
  1301   1301     int i;
  1302   1302     Expr *pPriorSelectCol = 0;
  1303   1303     assert( db!=0 );
  1304   1304     if( p==0 ) return 0;
  1305         -  pNew = sqlite3DbMallocRawNN(db, 
  1306         -             sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
         1305  +  pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p));
  1307   1306     if( pNew==0 ) return 0;
  1308         -  pNew->nAlloc = pNew->nExpr = p->nExpr;
         1307  +  pNew->nExpr = p->nExpr;
  1309   1308     pItem = pNew->a;
  1310   1309     pOldItem = p->a;
  1311   1310     for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
  1312   1311       Expr *pOldExpr = pOldItem->pExpr;
  1313   1312       Expr *pNewExpr;
  1314   1313       pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
  1315   1314       if( pOldExpr 
................................................................................
  1455   1454   #endif
  1456   1455   
  1457   1456   
  1458   1457   /*
  1459   1458   ** Add a new element to the end of an expression list.  If pList is
  1460   1459   ** initially NULL, then create a new expression list.
  1461   1460   **
         1461  +** The pList argument must be either NULL or a pointer to an ExprList
         1462  +** obtained from a prior call to sqlite3ExprListAppend().  This routine
         1463  +** may not be used with an ExprList obtained from sqlite3ExprListDup().
         1464  +** Reason:  This routine assumes that the number of slots in pList->a[]
         1465  +** is a power of two.  That is true for sqlite3ExprListAppend() returns
         1466  +** but is not necessarily true from the return value of sqlite3ExprListDup().
         1467  +**
  1462   1468   ** If a memory allocation error occurs, the entire list is freed and
  1463   1469   ** NULL is returned.  If non-NULL is returned, then it is guaranteed
  1464   1470   ** that the new entry was successfully appended.
  1465   1471   */
  1466   1472   ExprList *sqlite3ExprListAppend(
  1467   1473     Parse *pParse,          /* Parsing context */
  1468   1474     ExprList *pList,        /* List to which to append. Might be NULL */
................................................................................
  1473   1479     assert( db!=0 );
  1474   1480     if( pList==0 ){
  1475   1481       pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
  1476   1482       if( pList==0 ){
  1477   1483         goto no_mem;
  1478   1484       }
  1479   1485       pList->nExpr = 0;
  1480         -    pList->nAlloc = 1;
  1481         -  }else if( pList->nExpr==pList->nAlloc ){
         1486  +  }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
  1482   1487       ExprList *pNew;
  1483   1488       pNew = sqlite3DbRealloc(db, pList, 
  1484         -             sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
         1489  +             sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0]));
  1485   1490       if( pNew==0 ){
  1486   1491         goto no_mem;
  1487   1492       }
  1488   1493       pList = pNew;
  1489         -    pList->nAlloc *= 2;
  1490   1494     }
  1491   1495     pItem = &pList->a[pList->nExpr++];
  1492   1496     assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) );
  1493   1497     assert( offsetof(struct ExprList_item,pExpr)==0 );
  1494   1498     memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName));
  1495   1499     pItem->pExpr = pExpr;
  1496   1500     return pList;
................................................................................
  4237   4241     exprToRegister(pExpr, iMem);
  4238   4242   }
  4239   4243   
  4240   4244   /*
  4241   4245   ** Generate code that pushes the value of every element of the given
  4242   4246   ** expression list into a sequence of registers beginning at target.
  4243   4247   **
  4244         -** Return the number of elements evaluated.
         4248  +** Return the number of elements evaluated.  The number returned will
         4249  +** usually be pList->nExpr but might be reduced if SQLITE_ECEL_OMITREF
         4250  +** is defined.
  4245   4251   **
  4246   4252   ** The SQLITE_ECEL_DUP flag prevents the arguments from being
  4247   4253   ** filled using OP_SCopy.  OP_Copy must be used instead.
  4248   4254   **
  4249   4255   ** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
  4250   4256   ** factored out into initialization code.
  4251   4257   **
  4252   4258   ** The SQLITE_ECEL_REF flag means that expressions in the list with
  4253   4259   ** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
  4254   4260   ** in registers at srcReg, and so the value can be copied from there.
         4261  +** If SQLITE_ECEL_OMITREF is also set, then the values with u.x.iOrderByCol>0
         4262  +** are simply omitted rather than being copied from srcReg.
  4255   4263   */
  4256   4264   int sqlite3ExprCodeExprList(
  4257   4265     Parse *pParse,     /* Parsing context */
  4258   4266     ExprList *pList,   /* The expression list to be coded */
  4259   4267     int target,        /* Where to write results */
  4260   4268     int srcReg,        /* Source registers if SQLITE_ECEL_REF */
  4261   4269     u8 flags           /* SQLITE_ECEL_* flags */

Changes to src/os_unix.c.

  5345   5345   ){
  5346   5346     const sqlite3_io_methods *pLockingStyle;
  5347   5347     unixFile *pNew = (unixFile *)pId;
  5348   5348     int rc = SQLITE_OK;
  5349   5349   
  5350   5350     assert( pNew->pInode==NULL );
  5351   5351   
  5352         -  /* Usually the path zFilename should not be a relative pathname. The
  5353         -  ** exception is when opening the proxy "conch" file in builds that
  5354         -  ** include the special Apple locking styles.
  5355         -  */
  5356         -#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
  5357         -  assert( zFilename==0 || zFilename[0]=='/' 
  5358         -    || pVfs->pAppData==(void*)&autolockIoFinder );
  5359         -#else
  5360         -  assert( zFilename==0 || zFilename[0]=='/' );
  5361         -#endif
  5362         -
  5363   5352     /* No locking occurs in temporary files */
  5364   5353     assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
  5365   5354   
  5366   5355     OSTRACE(("OPEN    %-3d %s\n", h, zFilename));
  5367   5356     pNew->h = h;
  5368   5357     pNew->pVfs = pVfs;
  5369   5358     pNew->zPath = zFilename;
................................................................................
  5721   5710       **   "<path to db>-walNN"
  5722   5711       **
  5723   5712       ** where NN is a decimal number. The NN naming schemes are 
  5724   5713       ** used by the test_multiplex.c module.
  5725   5714       */
  5726   5715       nDb = sqlite3Strlen30(zPath) - 1; 
  5727   5716       while( zPath[nDb]!='-' ){
  5728         -#ifndef SQLITE_ENABLE_8_3_NAMES
  5729         -      /* In the normal case (8+3 filenames disabled) the journal filename
  5730         -      ** is guaranteed to contain a '-' character. */
  5731         -      assert( nDb>0 );
  5732         -      assert( sqlite3Isalnum(zPath[nDb]) );
  5733         -#else
  5734         -      /* If 8+3 names are possible, then the journal file might not contain
  5735         -      ** a '-' character.  So check for that case and return early. */
         5717  +      /* In normal operation, the journal file name will always contain
         5718  +      ** a '-' character.  However in 8+3 filename mode, or if a corrupt
         5719  +      ** rollback journal specifies a master journal with a goofy name, then
         5720  +      ** the '-' might be missing. */
  5736   5721         if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
  5737         -#endif
  5738   5722         nDb--;
  5739   5723       }
  5740   5724       memcpy(zDb, zPath, nDb);
  5741   5725       zDb[nDb] = '\0';
  5742   5726   
  5743   5727       rc = getFileMode(zDb, pMode, pUid, pGid);
  5744   5728     }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
................................................................................
  6016   6000           }
  6017   6001         }
  6018   6002         goto open_finished;
  6019   6003       }
  6020   6004     }
  6021   6005   #endif
  6022   6006     
         6007  +  assert( zPath==0 || zPath[0]=='/' 
         6008  +      || eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL 
         6009  +  );
  6023   6010     rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
  6024   6011   
  6025   6012   open_finished:
  6026   6013     if( rc!=SQLITE_OK ){
  6027   6014       sqlite3_free(p->pPreallocatedUnused);
  6028   6015     }
  6029   6016     return rc;

Changes to src/os_win.c.

  5692   5692     UNUSED_PARAMETER(pVfs);
  5693   5693     memset(zBuf, 0, nBuf);
  5694   5694     return nBuf;
  5695   5695   #else
  5696   5696     EntropyGatherer e;
  5697   5697     UNUSED_PARAMETER(pVfs);
  5698   5698     memset(zBuf, 0, nBuf);
  5699         -#if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE
  5700         -  rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */
  5701         -#endif /* defined(_MSC_VER) && _MSC_VER>=1400 */
  5702   5699     e.a = (unsigned char*)zBuf;
  5703   5700     e.na = nBuf;
  5704   5701     e.nXor = 0;
  5705   5702     e.i = 0;
  5706   5703     {
  5707   5704       SYSTEMTIME x;
  5708   5705       osGetSystemTime(&x);

Changes to src/pager.c.

  2840   2840     pPager->journalOff = 0;
  2841   2841     needPagerReset = isHot;
  2842   2842   
  2843   2843     /* This loop terminates either when a readJournalHdr() or 
  2844   2844     ** pager_playback_one_page() call returns SQLITE_DONE or an IO error 
  2845   2845     ** occurs. 
  2846   2846     */
  2847         -  while( 1 ){
         2847  +  do{
  2848   2848       /* Read the next journal header from the journal file.  If there are
  2849   2849       ** not enough bytes left in the journal file for a complete header, or
  2850   2850       ** it is corrupted, then a process must have failed while writing it.
  2851   2851       ** This indicates nothing more needs to be rolled back.
  2852   2852       */
         2853  +    u32 savedPageSize = pPager->pageSize;
  2853   2854       rc = readJournalHdr(pPager, isHot, szJ, &nRec, &mxPg);
  2854   2855       if( rc!=SQLITE_OK ){ 
  2855   2856         if( rc==SQLITE_DONE ){
  2856   2857           rc = SQLITE_OK;
  2857   2858         }
  2858   2859         goto end_playback;
  2859   2860       }
................................................................................
  2927   2928             ** so that no further harm will be done.  Perhaps the next
  2928   2929             ** process to come along will be able to rollback the database.
  2929   2930             */
  2930   2931             goto end_playback;
  2931   2932           }
  2932   2933         }
  2933   2934       }
  2934         -  }
  2935         -  /*NOTREACHED*/
  2936         -  assert( 0 );
         2935  +    rc = sqlite3PagerSetPagesize(pPager, &savedPageSize, -1);
         2936  +  }while( rc==SQLITE_OK );
  2937   2937   
  2938   2938   end_playback:
  2939   2939     /* Following a rollback, the database file should be back in its original
  2940   2940     ** state prior to the start of the transaction, so invoke the
  2941   2941     ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
  2942   2942     ** assertion that the transaction counter was modified.
  2943   2943     */

Changes to src/pragma.c.

   294    294     }
   295    295     return lwr>upr ? 0 : &aPragmaName[mid];
   296    296   }
   297    297   
   298    298   /*
   299    299   ** Helper subroutine for PRAGMA integrity_check:
   300    300   **
   301         -** Generate code to output a single-column result row with the result
   302         -** held in register regResult.  Decrement the result count and halt if
   303         -** the maximum number of result rows have been issued.
          301  +** Generate code to output a single-column result row with a value of the
          302  +** string held in register 3.  Decrement the result count in register 1
          303  +** and halt if the maximum number of result rows have been issued.
   304    304   */
   305         -static int integrityCheckResultRow(Vdbe *v, int regResult){
          305  +static int integrityCheckResultRow(Vdbe *v){
   306    306     int addr;
   307         -  sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1);
          307  +  sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
   308    308     addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
   309    309     VdbeCoverage(v);
   310         -  sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
          310  +  sqlite3VdbeAddOp0(v, OP_Halt);
   311    311     return addr;
   312    312   }
   313    313   
   314    314   /*
   315    315   ** Process a pragma statement.  
   316    316   **
   317    317   ** Pragmas are of this form:
................................................................................
  1480   1480           mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
  1481   1481         }
  1482   1482       }
  1483   1483       sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
  1484   1484   
  1485   1485       /* Do an integrity check on each database file */
  1486   1486       for(i=0; i<db->nDb; i++){
  1487         -      HashElem *x;
  1488         -      Hash *pTbls;
  1489         -      int *aRoot;
  1490         -      int cnt = 0;
  1491         -      int mxIdx = 0;
  1492         -      int nIdx;
         1487  +      HashElem *x;     /* For looping over tables in the schema */
         1488  +      Hash *pTbls;     /* Set of all tables in the schema */
         1489  +      int *aRoot;      /* Array of root page numbers of all btrees */
         1490  +      int cnt = 0;     /* Number of entries in aRoot[] */
         1491  +      int mxIdx = 0;   /* Maximum number of indexes for any table */
  1493   1492   
  1494   1493         if( OMIT_TEMPDB && i==1 ) continue;
  1495   1494         if( iDb>=0 && i!=iDb ) continue;
  1496   1495   
  1497   1496         sqlite3CodeVerifySchema(pParse, i);
  1498   1497   
  1499   1498         /* Do an integrity check of the B-Tree
................................................................................
  1500   1499         **
  1501   1500         ** Begin by finding the root pages numbers
  1502   1501         ** for all tables and indices in the database.
  1503   1502         */
  1504   1503         assert( sqlite3SchemaMutexHeld(db, i, 0) );
  1505   1504         pTbls = &db->aDb[i].pSchema->tblHash;
  1506   1505         for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
  1507         -        Table *pTab = sqliteHashData(x);
  1508         -        Index *pIdx;
         1506  +        Table *pTab = sqliteHashData(x);  /* Current table */
         1507  +        Index *pIdx;                      /* An index on pTab */
         1508  +        int nIdx;                         /* Number of indexes on pTab */
  1509   1509           if( HasRowid(pTab) ) cnt++;
  1510   1510           for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
  1511   1511           if( nIdx>mxIdx ) mxIdx = nIdx;
  1512   1512         }
  1513   1513         aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
  1514   1514         if( aRoot==0 ) break;
  1515   1515         for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
................................................................................
  1529   1529         /* Do the b-tree integrity checks */
  1530   1530         sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
  1531   1531         sqlite3VdbeChangeP5(v, (u8)i);
  1532   1532         addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
  1533   1533         sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
  1534   1534            sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
  1535   1535            P4_DYNAMIC);
  1536         -      sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
  1537         -      sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
  1538         -      integrityCheckResultRow(v, 2);
         1536  +      sqlite3VdbeAddOp3(v, OP_Concat, 2, 3, 3);
         1537  +      integrityCheckResultRow(v);
  1539   1538         sqlite3VdbeJumpHere(v, addr);
  1540   1539   
  1541   1540         /* Make sure all the indices are constructed correctly.
  1542   1541         */
  1543   1542         for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
  1544   1543           Table *pTab = sqliteHashData(x);
  1545   1544           Index *pIdx, *pPk;
  1546   1545           Index *pPrior = 0;
  1547   1546           int loopTop;
  1548   1547           int iDataCur, iIdxCur;
  1549   1548           int r1 = -1;
  1550   1549   
  1551   1550           if( pTab->tnum<1 ) continue;  /* Skip VIEWs or VIRTUAL TABLEs */
  1552         -        if( pTab->pCheck==0
  1553         -         && (pTab->tabFlags & TF_HasNotNull)==0
  1554         -         && (pTab->pIndex==0 || isQuick)
  1555         -        ){
  1556         -          continue;  /* No additional checks needed for this table */
  1557         -        }
  1558   1551           pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
  1559   1552           sqlite3ExprCacheClear(pParse);
  1560   1553           sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
  1561   1554                                      1, 0, &iDataCur, &iIdxCur);
         1555  +        /* reg[7] counts the number of entries in the table.
         1556  +        ** reg[8+i] counts the number of entries in the i-th index 
         1557  +        */
  1562   1558           sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
  1563   1559           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
  1564   1560             sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
  1565   1561           }
  1566   1562           assert( pParse->nMem>=8+j );
  1567   1563           assert( sqlite3NoTempsInRange(pParse,1,7+j) );
  1568   1564           sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
................................................................................
  1575   1571             if( pTab->aCol[j].notNull==0 ) continue;
  1576   1572             sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
  1577   1573             sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
  1578   1574             jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
  1579   1575             zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
  1580   1576                                 pTab->aCol[j].zName);
  1581   1577             sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
  1582         -          integrityCheckResultRow(v, 3);
         1578  +          integrityCheckResultRow(v);
  1583   1579             sqlite3VdbeJumpHere(v, jmp2);
  1584   1580           }
  1585   1581           /* Verify CHECK constraints */
  1586         -        sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nCol-1, 3);
  1587   1582           if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
  1588   1583             ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
  1589   1584             if( db->mallocFailed==0 ){
  1590   1585               int addrCkFault = sqlite3VdbeMakeLabel(v);
  1591   1586               int addrCkOk = sqlite3VdbeMakeLabel(v);
  1592   1587               char *zErr;
  1593   1588               int k;
................................................................................
  1599   1594               sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
  1600   1595                   SQLITE_JUMPIFNULL);
  1601   1596               sqlite3VdbeResolveLabel(v, addrCkFault);
  1602   1597               pParse->iSelfTab = 0;
  1603   1598               zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
  1604   1599                   pTab->zName);
  1605   1600               sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
  1606         -            integrityCheckResultRow(v, 3);
         1601  +            integrityCheckResultRow(v);
  1607   1602               sqlite3VdbeResolveLabel(v, addrCkOk);
  1608   1603               sqlite3ExprCachePop(pParse);
  1609   1604             }
  1610   1605             sqlite3ExprListDelete(db, pCheck);
  1611   1606           }
  1612         -        /* Validate index entries for the current row */
  1613         -        for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
  1614         -          int jmp2, jmp3, jmp4, jmp5;
  1615         -          int ckUniq = sqlite3VdbeMakeLabel(v);
  1616         -          if( pPk==pIdx ) continue;
  1617         -          r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
  1618         -                                       pPrior, r1);
  1619         -          pPrior = pIdx;
  1620         -          sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);  /* increment entry count */
  1621         -          /* Verify that an index entry exists for the current table row */
  1622         -          jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
  1623         -                                      pIdx->nColumn); VdbeCoverage(v);
  1624         -          sqlite3VdbeLoadString(v, 3, "row ");
  1625         -          sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
  1626         -          sqlite3VdbeLoadString(v, 4, " missing from index ");
  1627         -          sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
  1628         -          jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
  1629         -          sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
  1630         -          jmp4 = integrityCheckResultRow(v, 3);
  1631         -          sqlite3VdbeJumpHere(v, jmp2);
  1632         -          /* For UNIQUE indexes, verify that only one entry exists with the
  1633         -          ** current key.  The entry is unique if (1) any column is NULL
  1634         -          ** or (2) the next entry has a different key */
  1635         -          if( IsUniqueIndex(pIdx) ){
  1636         -            int uniqOk = sqlite3VdbeMakeLabel(v);
  1637         -            int jmp6;
  1638         -            int kk;
  1639         -            for(kk=0; kk<pIdx->nKeyCol; kk++){
  1640         -              int iCol = pIdx->aiColumn[kk];
  1641         -              assert( iCol!=XN_ROWID && iCol<pTab->nCol );
  1642         -              if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
  1643         -              sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
  1644         -              VdbeCoverage(v);
         1607  +        if( !isQuick ){ /* Omit the remaining tests for quick_check */
         1608  +          /* Sanity check on record header decoding */
         1609  +          sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nCol-1, 3);
         1610  +          sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
         1611  +          /* Validate index entries for the current row */
         1612  +          for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
         1613  +            int jmp2, jmp3, jmp4, jmp5;
         1614  +            int ckUniq = sqlite3VdbeMakeLabel(v);
         1615  +            if( pPk==pIdx ) continue;
         1616  +            r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
         1617  +                                         pPrior, r1);
         1618  +            pPrior = pIdx;
         1619  +            sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */
         1620  +            /* Verify that an index entry exists for the current table row */
         1621  +            jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
         1622  +                                        pIdx->nColumn); VdbeCoverage(v);
         1623  +            sqlite3VdbeLoadString(v, 3, "row ");
         1624  +            sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
         1625  +            sqlite3VdbeLoadString(v, 4, " missing from index ");
         1626  +            sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
         1627  +            jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
         1628  +            sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
         1629  +            jmp4 = integrityCheckResultRow(v);
         1630  +            sqlite3VdbeJumpHere(v, jmp2);
         1631  +            /* For UNIQUE indexes, verify that only one entry exists with the
         1632  +            ** current key.  The entry is unique if (1) any column is NULL
         1633  +            ** or (2) the next entry has a different key */
         1634  +            if( IsUniqueIndex(pIdx) ){
         1635  +              int uniqOk = sqlite3VdbeMakeLabel(v);
         1636  +              int jmp6;
         1637  +              int kk;
         1638  +              for(kk=0; kk<pIdx->nKeyCol; kk++){
         1639  +                int iCol = pIdx->aiColumn[kk];
         1640  +                assert( iCol!=XN_ROWID && iCol<pTab->nCol );
         1641  +                if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
         1642  +                sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
         1643  +                VdbeCoverage(v);
         1644  +              }
         1645  +              jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
         1646  +              sqlite3VdbeGoto(v, uniqOk);
         1647  +              sqlite3VdbeJumpHere(v, jmp6);
         1648  +              sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
         1649  +                                   pIdx->nKeyCol); VdbeCoverage(v);
         1650  +              sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
         1651  +              sqlite3VdbeGoto(v, jmp5);
         1652  +              sqlite3VdbeResolveLabel(v, uniqOk);
  1645   1653               }
  1646         -            jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
  1647         -            sqlite3VdbeGoto(v, uniqOk);
  1648         -            sqlite3VdbeJumpHere(v, jmp6);
  1649         -            sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
  1650         -                                 pIdx->nKeyCol); VdbeCoverage(v);
  1651         -            sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
  1652         -            sqlite3VdbeGoto(v, jmp5);
  1653         -            sqlite3VdbeResolveLabel(v, uniqOk);
         1654  +            sqlite3VdbeJumpHere(v, jmp4);
         1655  +            sqlite3ResolvePartIdxLabel(pParse, jmp3);
  1654   1656             }
  1655         -          sqlite3VdbeJumpHere(v, jmp4);
  1656         -          sqlite3ResolvePartIdxLabel(pParse, jmp3);
  1657   1657           }
  1658   1658           sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
  1659   1659           sqlite3VdbeJumpHere(v, loopTop-1);
  1660   1660   #ifndef SQLITE_OMIT_BTREECOUNT
  1661   1661           if( !isQuick ){
  1662   1662             sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
  1663   1663             for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
  1664   1664               if( pPk==pIdx ) continue;
  1665   1665               sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
  1666   1666               addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
  1667   1667               sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
  1668         -            sqlite3VdbeLoadString(v, 3, pIdx->zName);
  1669         -            sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
  1670         -            integrityCheckResultRow(v, 7);
         1668  +            sqlite3VdbeLoadString(v, 4, pIdx->zName);
         1669  +            sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3);
         1670  +            integrityCheckResultRow(v);
  1671   1671               sqlite3VdbeJumpHere(v, addr);
  1672   1672             }
  1673   1673           }
  1674   1674   #endif /* SQLITE_OMIT_BTREECOUNT */
  1675   1675         } 
  1676   1676       }
  1677   1677       {
  1678   1678         static const int iLn = VDBE_OFFSET_LINENO(2);
  1679   1679         static const VdbeOpList endCode[] = {
  1680   1680           { OP_AddImm,      1, 0,        0},    /* 0 */
  1681   1681           { OP_IfNotZero,   1, 4,        0},    /* 1 */
  1682   1682           { OP_String8,     0, 3,        0},    /* 2 */
  1683   1683           { OP_ResultRow,   3, 1,        0},    /* 3 */
         1684  +        { OP_Halt,        0, 0,        0},    /* 4 */
         1685  +        { OP_String8,     0, 3,        0},    /* 5 */
         1686  +        { OP_Goto,        0, 3,        0},    /* 6 */
  1684   1687         };
  1685   1688         VdbeOp *aOp;
  1686   1689   
  1687   1690         aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
  1688   1691         if( aOp ){
  1689   1692           aOp[0].p2 = 1-mxErr;
  1690   1693           aOp[2].p4type = P4_STATIC;
  1691   1694           aOp[2].p4.z = "ok";
         1695  +        aOp[5].p4type = P4_STATIC;
         1696  +        aOp[5].p4.z = (char*)sqlite3ErrStr(SQLITE_CORRUPT);
  1692   1697         }
         1698  +      sqlite3VdbeChangeP3(v, 0, sqlite3VdbeCurrentAddr(v)-2);
  1693   1699       }
  1694   1700     }
  1695   1701     break;
  1696   1702   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
  1697   1703   
  1698   1704   #ifndef SQLITE_OMIT_UTF16
  1699   1705     /*

Changes to src/select.c.

   660    660     sqlite3ReleaseTempReg(pParse, r1);
   661    661   }
   662    662   
   663    663   /*
   664    664   ** This routine generates the code for the inside of the inner loop
   665    665   ** of a SELECT.
   666    666   **
   667         -** If srcTab is negative, then the pEList expressions
          667  +** If srcTab is negative, then the p->pEList expressions
   668    668   ** are evaluated in order to get the data for this row.  If srcTab is
   669         -** zero or more, then data is pulled from srcTab and pEList is used only 
          669  +** zero or more, then data is pulled from srcTab and p->pEList is used only 
   670    670   ** to get the number of columns and the collation sequence for each column.
   671    671   */
   672    672   static void selectInnerLoop(
   673    673     Parse *pParse,          /* The parser context */
   674    674     Select *p,              /* The complete select statement being coded */
   675         -  ExprList *pEList,       /* List of values being extracted */
   676         -  int srcTab,             /* Pull data from this table */
          675  +  int srcTab,             /* Pull data from this table if non-negative */
   677    676     SortCtx *pSort,         /* If not NULL, info on how to process ORDER BY */
   678    677     DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */
   679    678     SelectDest *pDest,      /* How to dispose of the results */
   680    679     int iContinue,          /* Jump here to continue with next row */
   681    680     int iBreak              /* Jump here to break out of the inner loop */
   682    681   ){
   683    682     Vdbe *v = pParse->pVdbe;
................................................................................
   693    692     ** same value. However, if the results are being sent to the sorter, the
   694    693     ** values for any expressions that are also part of the sort-key are omitted
   695    694     ** from this array. In this case regOrig is set to zero.  */
   696    695     int regResult;              /* Start of memory holding current results */
   697    696     int regOrig;                /* Start of memory holding full result (or 0) */
   698    697   
   699    698     assert( v );
   700         -  assert( pEList!=0 );
          699  +  assert( p->pEList!=0 );
   701    700     hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
   702    701     if( pSort && pSort->pOrderBy==0 ) pSort = 0;
   703    702     if( pSort==0 && !hasDistinct ){
   704    703       assert( iContinue!=0 );
   705    704       codeOffset(v, p->iOffset, iContinue);
   706    705     }
   707    706   
   708    707     /* Pull the requested columns.
   709    708     */
   710         -  nResultCol = pEList->nExpr;
          709  +  nResultCol = p->pEList->nExpr;
   711    710   
   712    711     if( pDest->iSdst==0 ){
   713    712       if( pSort ){
   714    713         nPrefixReg = pSort->pOrderBy->nExpr;
   715    714         if( !(pSort->sortFlags & SORTFLAG_UseSorter) ) nPrefixReg++;
   716    715         pParse->nMem += nPrefixReg;
   717    716       }
................................................................................
   726    725       pParse->nMem += nResultCol;
   727    726     }
   728    727     pDest->nSdst = nResultCol;
   729    728     regOrig = regResult = pDest->iSdst;
   730    729     if( srcTab>=0 ){
   731    730       for(i=0; i<nResultCol; i++){
   732    731         sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
   733         -      VdbeComment((v, "%s", pEList->a[i].zName));
          732  +      VdbeComment((v, "%s", p->pEList->a[i].zName));
   734    733       }
   735    734     }else if( eDest!=SRT_Exists ){
   736    735       /* If the destination is an EXISTS(...) expression, the actual
   737    736       ** values returned by the SELECT are not required.
   738    737       */
   739    738       u8 ecelFlags;
   740    739       if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
   741    740         ecelFlags = SQLITE_ECEL_DUP;
   742    741       }else{
   743    742         ecelFlags = 0;
   744    743       }
   745    744       if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
   746         -      /* For each expression in pEList that is a copy of an expression in
          745  +      /* For each expression in p->pEList that is a copy of an expression in
   747    746         ** the ORDER BY clause (pSort->pOrderBy), set the associated 
   748    747         ** iOrderByCol value to one more than the index of the ORDER BY 
   749    748         ** expression within the sort-key that pushOntoSorter() will generate.
   750         -      ** This allows the pEList field to be omitted from the sorted record,
          749  +      ** This allows the p->pEList field to be omitted from the sorted record,
   751    750         ** saving space and CPU cycles.  */
   752    751         ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF);
   753    752         for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){
   754    753           int j;
   755    754           if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
   756         -          pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
          755  +          p->pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
   757    756           }
   758    757         }
   759    758         regOrig = 0;
   760    759         assert( eDest==SRT_Set || eDest==SRT_Mem 
   761    760              || eDest==SRT_Coroutine || eDest==SRT_Output );
   762    761       }
   763         -    nResultCol = sqlite3ExprCodeExprList(pParse,pEList,regResult,0,ecelFlags);
          762  +    nResultCol = sqlite3ExprCodeExprList(pParse,p->pEList,regResult,0,ecelFlags);
   764    763     }
   765    764   
   766    765     /* If the DISTINCT keyword was present on the SELECT statement
   767    766     ** and this row has been seen before, then do not make this row
   768    767     ** part of the result.
   769    768     */
   770    769     if( hasDistinct ){
................................................................................
   788    787           pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);
   789    788           pOp->opcode = OP_Null;
   790    789           pOp->p1 = 1;
   791    790           pOp->p2 = regPrev;
   792    791   
   793    792           iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
   794    793           for(i=0; i<nResultCol; i++){
   795         -          CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
          794  +          CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr);
   796    795             if( i<nResultCol-1 ){
   797    796               sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
   798    797               VdbeCoverage(v);
   799    798             }else{
   800    799               sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
   801    800               VdbeCoverage(v);
   802    801              }
................................................................................
  1858   1857     return pTab;
  1859   1858   }
  1860   1859   
  1861   1860   /*
  1862   1861   ** Get a VDBE for the given parser context.  Create a new one if necessary.
  1863   1862   ** If an error occurs, return NULL and leave a message in pParse.
  1864   1863   */
  1865         -static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){
  1866         -  Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
  1867         -  if( v ) sqlite3VdbeAddOp2(v, OP_Init, 0, 1);
         1864  +Vdbe *sqlite3GetVdbe(Parse *pParse){
         1865  +  if( pParse->pVdbe ){
         1866  +    return pParse->pVdbe;
         1867  +  }
  1868   1868     if( pParse->pToplevel==0
  1869   1869      && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
  1870   1870     ){
  1871   1871       pParse->okConstFactor = 1;
  1872   1872     }
  1873         -  return v;
  1874         -}
  1875         -Vdbe *sqlite3GetVdbe(Parse *pParse){
  1876         -  Vdbe *v = pParse->pVdbe;
  1877         -  return v ? v : allocVdbe(pParse);
         1873  +  return sqlite3VdbeCreate(pParse);
  1878   1874   }
  1879   1875   
  1880   1876   
  1881   1877   /*
  1882   1878   ** Compute the iLimit and iOffset fields of the SELECT based on the
  1883   1879   ** pLimit and pOffset expressions.  pLimit and pOffset hold the expressions
  1884   1880   ** that appear in the original SQL statement after the LIMIT and OFFSET
................................................................................
  2143   2139       sqlite3VdbeAddOp2(v, OP_RowData, iQueue, regCurrent);
  2144   2140     }
  2145   2141     sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
  2146   2142   
  2147   2143     /* Output the single row in Current */
  2148   2144     addrCont = sqlite3VdbeMakeLabel(v);
  2149   2145     codeOffset(v, regOffset, addrCont);
  2150         -  selectInnerLoop(pParse, p, p->pEList, iCurrent,
         2146  +  selectInnerLoop(pParse, p, iCurrent,
  2151   2147         0, 0, pDest, addrCont, addrBreak);
  2152   2148     if( regLimit ){
  2153   2149       sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
  2154   2150       VdbeCoverage(v);
  2155   2151     }
  2156   2152     sqlite3VdbeResolveLabel(v, addrCont);
  2157   2153   
................................................................................
  2462   2458           int iCont, iBreak, iStart;
  2463   2459           assert( p->pEList );
  2464   2460           iBreak = sqlite3VdbeMakeLabel(v);
  2465   2461           iCont = sqlite3VdbeMakeLabel(v);
  2466   2462           computeLimitRegisters(pParse, p, iBreak);
  2467   2463           sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
  2468   2464           iStart = sqlite3VdbeCurrentAddr(v);
  2469         -        selectInnerLoop(pParse, p, p->pEList, unionTab,
         2465  +        selectInnerLoop(pParse, p, unionTab,
  2470   2466                           0, 0, &dest, iCont, iBreak);
  2471   2467           sqlite3VdbeResolveLabel(v, iCont);
  2472   2468           sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
  2473   2469           sqlite3VdbeResolveLabel(v, iBreak);
  2474   2470           sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
  2475   2471         }
  2476   2472         break;
................................................................................
  2535   2531         iCont = sqlite3VdbeMakeLabel(v);
  2536   2532         computeLimitRegisters(pParse, p, iBreak);
  2537   2533         sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
  2538   2534         r1 = sqlite3GetTempReg(pParse);
  2539   2535         iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
  2540   2536         sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
  2541   2537         sqlite3ReleaseTempReg(pParse, r1);
  2542         -      selectInnerLoop(pParse, p, p->pEList, tab1,
         2538  +      selectInnerLoop(pParse, p, tab1,
  2543   2539                         0, 0, &dest, iCont, iBreak);
  2544   2540         sqlite3VdbeResolveLabel(v, iCont);
  2545   2541         sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
  2546   2542         sqlite3VdbeResolveLabel(v, iBreak);
  2547   2543         sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
  2548   2544         sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
  2549   2545         break;
................................................................................
  5541   5537       ** into an OP_Noop.
  5542   5538       */
  5543   5539       if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
  5544   5540         sqlite3VdbeChangeToNoop(v, sSort.addrSortIndex);
  5545   5541       }
  5546   5542   
  5547   5543       /* Use the standard inner loop. */
  5548         -    selectInnerLoop(pParse, p, pEList, -1, &sSort, &sDistinct, pDest,
         5544  +    assert( p->pEList==pEList );
         5545  +    selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest,
  5549   5546                       sqlite3WhereContinueLabel(pWInfo),
  5550   5547                       sqlite3WhereBreakLabel(pWInfo));
  5551   5548   
  5552   5549       /* End the database scan loop.
  5553   5550       */
  5554   5551       sqlite3WhereEnd(pWInfo);
  5555   5552     }else{
................................................................................
  5844   5841         addrOutputRow = sqlite3VdbeCurrentAddr(v);
  5845   5842         sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
  5846   5843         VdbeCoverage(v);
  5847   5844         VdbeComment((v, "Groupby result generator entry point"));
  5848   5845         sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
  5849   5846         finalizeAggFunctions(pParse, &sAggInfo);
  5850   5847         sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
  5851         -      selectInnerLoop(pParse, p, p->pEList, -1, &sSort,
         5848  +      selectInnerLoop(pParse, p, -1, &sSort,
  5852   5849                         &sDistinct, pDest,
  5853   5850                         addrOutputRow+1, addrSetAbort);
  5854   5851         sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
  5855   5852         VdbeComment((v, "end groupby result generator"));
  5856   5853   
  5857   5854         /* Generate a subroutine that will reset the group-by accumulator
  5858   5855         */
................................................................................
  5988   5985           }
  5989   5986           sqlite3WhereEnd(pWInfo);
  5990   5987           finalizeAggFunctions(pParse, &sAggInfo);
  5991   5988         }
  5992   5989   
  5993   5990         sSort.pOrderBy = 0;
  5994   5991         sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
  5995         -      selectInnerLoop(pParse, p, p->pEList, -1, 0, 0, 
         5992  +      selectInnerLoop(pParse, p, -1, 0, 0, 
  5996   5993                         pDest, addrEnd, addrEnd);
  5997   5994         sqlite3ExprListDelete(db, pDel);
  5998   5995       }
  5999   5996       sqlite3VdbeResolveLabel(v, addrEnd);
  6000   5997       
  6001   5998     } /* endif aggregate query */
  6002   5999   

Changes to src/sqliteInt.h.

    46     46   ** Make sure the Tcl calling convention macro is defined.  This macro is
    47     47   ** only used by test code and Tcl integration code.
    48     48   */
    49     49   #ifndef SQLITE_TCLAPI
    50     50   #  define SQLITE_TCLAPI
    51     51   #endif
    52     52   
    53         -/*
    54         -** Make sure that rand_s() is available on Windows systems with MSVC 2005
    55         -** or higher.
    56         -*/
    57         -#if defined(_MSC_VER) && _MSC_VER>=1400
    58         -#  define _CRT_RAND_S
    59         -#endif
    60         -
    61     53   /*
    62     54   ** Include the header file used to customize the compiler options for MSVC.
    63     55   ** This should be done first so that it can successfully prevent spurious
    64     56   ** compiler warnings due to subsequent content in this file and other files
    65     57   ** that are included by this file.
    66     58   */
    67     59   #include "msvc.h"
................................................................................
  2482   2474   ** column expression as it exists in a SELECT statement.  However, if
  2483   2475   ** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
  2484   2476   ** of the result column in the form: DATABASE.TABLE.COLUMN.  This later
  2485   2477   ** form is used for name resolution with nested FROM clauses.
  2486   2478   */
  2487   2479   struct ExprList {
  2488   2480     int nExpr;             /* Number of expressions on the list */
  2489         -  int nAlloc;            /* Number of a[] slots allocated */
  2490   2481     struct ExprList_item { /* For each expression in the list */
  2491   2482       Expr *pExpr;            /* The parse tree for this expression */
  2492   2483       char *zName;            /* Token associated with this expression */
  2493   2484       char *zSpan;            /* Original text of the expression */
  2494   2485       u8 sortOrder;           /* 1 for DESC or 0 for ASC */
  2495   2486       unsigned done :1;       /* A flag to indicate when processing is finished */
  2496   2487       unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */

Changes to src/vdbe.c.

  2457   2457         ** Type entries can be between 1 and 5 bytes each.  But 4 and 5 byte
  2458   2458         ** types use so much data space that there can only be 4096 and 32 of
  2459   2459         ** them, respectively.  So the maximum header length results from a
  2460   2460         ** 3-byte type for each of the maximum of 32768 columns plus three
  2461   2461         ** extra bytes for the header length itself.  32768*3 + 3 = 98307.
  2462   2462         */
  2463   2463         if( aOffset[0] > 98307 || aOffset[0] > pC->payloadSize ){
  2464         -        rc = SQLITE_CORRUPT_BKPT;
  2465         -        goto abort_due_to_error;
         2464  +        goto op_column_corrupt;
  2466   2465         }
  2467   2466       }else{
  2468   2467         /* This is an optimization.  By skipping over the first few tests
  2469   2468         ** (ex: pC->nHdrParsed<=p2) in the next section, we achieve a
  2470   2469         ** measurable performance gain.
  2471   2470         **
  2472   2471         ** This branch is taken even if aOffset[0]==0.  Such a record is never
................................................................................
  2531   2530          || (offset64 > pC->payloadSize)
  2532   2531         ){
  2533   2532           if( aOffset[0]==0 ){
  2534   2533             i = 0;
  2535   2534             zHdr = zEndHdr;
  2536   2535           }else{
  2537   2536             if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
  2538         -          rc = SQLITE_CORRUPT_BKPT;
  2539         -          goto abort_due_to_error;
         2537  +          goto op_column_corrupt;
  2540   2538           }
  2541   2539         }
  2542   2540   
  2543   2541         pC->nHdrParsed = i;
  2544   2542         pC->iHdrOffset = (u32)(zHdr - zData);
  2545   2543         if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
  2546   2544       }else{
................................................................................
  2627   2625       }
  2628   2626     }
  2629   2627   
  2630   2628   op_column_out:
  2631   2629     UPDATE_MAX_BLOBSIZE(pDest);
  2632   2630     REGISTER_TRACE(pOp->p3, pDest);
  2633   2631     break;
         2632  +
         2633  +op_column_corrupt:
         2634  +  if( aOp[0].p3>0 ){
         2635  +    pOp = &aOp[aOp[0].p3-1];
         2636  +    break;
         2637  +  }else{
         2638  +    rc = SQLITE_CORRUPT_BKPT;
         2639  +    goto abort_due_to_error;
         2640  +  }
  2634   2641   }
  2635   2642   
  2636   2643   /* Opcode: Affinity P1 P2 * P4 *
  2637   2644   ** Synopsis: affinity(r[P1@P2])
  2638   2645   **
  2639   2646   ** Apply affinities to a range of P2 registers starting with P1.
  2640   2647   **
................................................................................
  7011   7018   
  7012   7019     REGISTER_TRACE(pOp->p3, pOut);
  7013   7020     UPDATE_MAX_BLOBSIZE(pOut);
  7014   7021     break;
  7015   7022   }
  7016   7023   
  7017   7024   
  7018         -/* Opcode: Init P1 P2 * P4 *
         7025  +/* Opcode: Init P1 P2 P3 P4 *
  7019   7026   ** Synopsis: Start at P2
  7020   7027   **
  7021   7028   ** Programs contain a single instance of this opcode as the very first
  7022   7029   ** opcode.
  7023   7030   **
  7024   7031   ** If tracing is enabled (by the sqlite3_trace()) interface, then
  7025   7032   ** the UTF-8 string contained in P4 is emitted on the trace callback.
  7026   7033   ** Or if P4 is blank, use the string returned by sqlite3_sql().
  7027   7034   **
  7028   7035   ** If P2 is not zero, jump to instruction P2.
  7029   7036   **
  7030   7037   ** Increment the value of P1 so that OP_Once opcodes will jump the
  7031   7038   ** first time they are evaluated for this run.
         7039  +**
         7040  +** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
         7041  +** error is encountered.
  7032   7042   */
  7033   7043   case OP_Init: {          /* jump */
  7034   7044     char *zTrace;
  7035   7045     int i;
  7036   7046   
  7037   7047     /* If the P4 argument is not NULL, then it must be an SQL comment string.
  7038   7048     ** The "--" string is broken up to prevent false-positives with srcck1.c.

Changes to src/vdbeaux.c.

    29     29       db->pVdbe->pPrev = p;
    30     30     }
    31     31     p->pNext = db->pVdbe;
    32     32     p->pPrev = 0;
    33     33     db->pVdbe = p;
    34     34     p->magic = VDBE_MAGIC_INIT;
    35     35     p->pParse = pParse;
           36  +  pParse->pVdbe = p;
    36     37     assert( pParse->aLabel==0 );
    37     38     assert( pParse->nLabel==0 );
    38     39     assert( pParse->nOpAlloc==0 );
    39     40     assert( pParse->szOpAlloc==0 );
           41  +  sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
    40     42     return p;
    41     43   }
    42     44   
    43     45   /*
    44     46   ** Change the error string stored in Vdbe.zErrMsg
    45     47   */
    46     48   void sqlite3VdbeError(Vdbe *p, const char *zFormat, ...){
................................................................................
  2154   2156     }
  2155   2157   
  2156   2158     /* Delete any auxdata allocations made by the VM */
  2157   2159     if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p->db, &p->pAuxData, -1, 0);
  2158   2160     assert( p->pAuxData==0 );
  2159   2161   }
  2160   2162   
  2161         -/*
  2162         -** Clean up the VM after a single run.
  2163         -*/
  2164         -static void Cleanup(Vdbe *p){
  2165         -  sqlite3 *db = p->db;
  2166         -
  2167         -#ifdef SQLITE_DEBUG
  2168         -  /* Execute assert() statements to ensure that the Vdbe.apCsr[] and 
  2169         -  ** Vdbe.aMem[] arrays have already been cleaned up.  */
  2170         -  int i;
  2171         -  if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
  2172         -  if( p->aMem ){
  2173         -    for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
  2174         -  }
  2175         -#endif
  2176         -
  2177         -  sqlite3DbFree(db, p->zErrMsg);
  2178         -  p->zErrMsg = 0;
  2179         -  p->pResultSet = 0;
  2180         -}
  2181         -
  2182   2163   /*
  2183   2164   ** Set the number of result columns that will be returned by this SQL
  2184   2165   ** statement. This is now set at compile time, rather than during
  2185   2166   ** execution of the vdbe program so that sqlite3_column_count() can
  2186   2167   ** be called on an SQL statement before sqlite3_step().
  2187   2168   */
  2188   2169   void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
................................................................................
  2900   2881     ** and error message from the VDBE into the main database structure.  But
  2901   2882     ** if the VDBE has just been set to run but has not actually executed any
  2902   2883     ** instructions yet, leave the main database error information unchanged.
  2903   2884     */
  2904   2885     if( p->pc>=0 ){
  2905   2886       vdbeInvokeSqllog(p);
  2906   2887       sqlite3VdbeTransferError(p);
  2907         -    sqlite3DbFree(db, p->zErrMsg);
  2908         -    p->zErrMsg = 0;
  2909   2888       if( p->runOnlyOnce ) p->expired = 1;
  2910   2889     }else if( p->rc && p->expired ){
  2911   2890       /* The expired flag was set on the VDBE before the first call
  2912   2891       ** to sqlite3_step(). For consistency (since sqlite3_step() was
  2913   2892       ** called), set the database error in this case as well.
  2914   2893       */
  2915   2894       sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
  2916         -    sqlite3DbFree(db, p->zErrMsg);
  2917         -    p->zErrMsg = 0;
  2918   2895     }
  2919   2896   
  2920         -  /* Reclaim all memory used by the VDBE
         2897  +  /* Reset register contents and reclaim error message memory.
  2921   2898     */
  2922         -  Cleanup(p);
         2899  +#ifdef SQLITE_DEBUG
         2900  +  /* Execute assert() statements to ensure that the Vdbe.apCsr[] and 
         2901  +  ** Vdbe.aMem[] arrays have already been cleaned up.  */
         2902  +  int i;
         2903  +  if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
         2904  +  if( p->aMem ){
         2905  +    for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
         2906  +  }
         2907  +#endif
         2908  +  sqlite3DbFree(db, p->zErrMsg);
         2909  +  p->zErrMsg = 0;
         2910  +  p->pResultSet = 0;
  2923   2911   
  2924   2912     /* Save profiling information from this VDBE run.
  2925   2913     */
  2926   2914   #ifdef VDBE_PROFILE
  2927   2915     {
  2928   2916       FILE *out = fopen("vdbe_profile.out", "a");
  2929   2917       if( out ){

Changes to src/vdbeblob.c.

   271    271         Vdbe *v = (Vdbe *)pBlob->pStmt;
   272    272         int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   273    273         VdbeOp *aOp;
   274    274   
   275    275         sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag, 
   276    276                              pTab->pSchema->schema_cookie,
   277    277                              pTab->pSchema->iGeneration);
   278         -      sqlite3VdbeChangeP5(v, 1);     
          278  +      sqlite3VdbeChangeP5(v, 1);
          279  +      assert( sqlite3VdbeCurrentAddr(v)==2 || db->mallocFailed );
   279    280         aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
   280    281   
   281    282         /* Make sure a mutex is held on the table to be accessed */
   282    283         sqlite3VdbeUsesBtree(v, iDb); 
   283    284   
   284    285         if( db->mallocFailed==0 ){
   285    286           assert( aOp!=0 );
................................................................................
   286    287           /* Configure the OP_TableLock instruction */
   287    288   #ifdef SQLITE_OMIT_SHARED_CACHE
   288    289           aOp[0].opcode = OP_Noop;
   289    290   #else
   290    291           aOp[0].p1 = iDb;
   291    292           aOp[0].p2 = pTab->tnum;
   292    293           aOp[0].p3 = wrFlag;
   293         -        sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
          294  +        sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
   294    295         }
   295    296         if( db->mallocFailed==0 ){
   296    297   #endif
   297    298   
   298    299           /* Remove either the OP_OpenWrite or OpenRead. Set the P2 
   299    300           ** parameter of the other to pTab->tnum.  */
   300    301           if( wrFlag ) aOp[1].opcode = OP_OpenWrite;

Changes to src/where.c.

  4794   4794       }else{
  4795   4795         sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
  4796   4796       }
  4797   4797       if( pLoop->wsFlags & WHERE_INDEXED ){
  4798   4798         Index *pIx = pLoop->u.btree.pIndex;
  4799   4799         int iIndexCur;
  4800   4800         int op = OP_OpenRead;
  4801         -      /* iAuxArg is always set if to a positive value if ONEPASS is possible */
         4801  +      /* iAuxArg is always set to a positive value if ONEPASS is possible */
  4802   4802         assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
  4803   4803         if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIx)
  4804   4804          && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0
  4805   4805         ){
  4806   4806           /* This is one term of an OR-optimization using the PRIMARY KEY of a
  4807   4807           ** WITHOUT ROWID table.  No need for a separate index */
  4808   4808           iIndexCur = pLevel->iTabCur;

Changes to test/corruptC.test.

   160    160     hexio_write test.db 3119 [format %02x 0xdf]
   161    161     hexio_write test.db 4073 [format %02x 0xbf]
   162    162   
   163    163     sqlite3 db test.db
   164    164     catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;}
   165    165     catchsql {PRAGMA integrity_check}
   166    166   } {0 {{*** in database main ***
   167         -On tree page 4 cell 19: Extends off end of page}}}
          167  +On tree page 4 cell 19: Extends off end of page} {database disk image is malformed}}}
   168    168   
   169    169   # {0 {{*** in database main ***
   170    170   # Corruption detected in cell 710 on page 4
   171    171   # Multiple uses for byte 661 of page 4
   172    172   # Fragmented space is 249 byte reported as 21 on page 4}}}
   173    173   
   174    174   # test that a corrupt free cell size is handled (seed 169595)

Changes to test/fts3conf.test.

   132    132       INSERT INTO t1(docid, x) VALUES(1, 'a b c');
   133    133       REPLACE INTO t1(docid, x) VALUES('zero', 'd e f');
   134    134   } {1 {datatype mismatch}}
   135    135   do_execsql_test 2.2.2 { COMMIT }
   136    136   do_execsql_test 2.2.3 { SELECT * FROM t1 } {{a b c} {a b c}}
   137    137   fts3_integrity 2.2.4 db t1
   138    138   
   139         -do_execsql_test 3.1 {
   140         -  CREATE VIRTUAL TABLE t3 USING fts4;
   141         -  REPLACE INTO t3(docid, content) VALUES (1, 'one two');
   142         -  SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one'
   143         -} {X'0100000002000000'}
   144         -
   145         -do_execsql_test 3.2 {
   146         -  REPLACE INTO t3(docid, content) VALUES (2, 'one two three four');
   147         -  SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'four'
   148         -} {X'0200000003000000'}
   149         -
   150         -do_execsql_test 3.3 {
   151         -  REPLACE INTO t3(docid, content) VALUES (1, 'one two three four five six');
   152         -  SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six'
   153         -} {X'0200000005000000'}
   154         -
   155         -do_execsql_test 3.4 {
   156         -  UPDATE OR REPLACE t3 SET docid = 2 WHERE docid=1;
   157         -  SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six'
   158         -} {X'0100000006000000'}
   159         -
   160         -do_execsql_test 3.5 {
   161         -  UPDATE OR REPLACE t3 SET docid = 3 WHERE docid=2;
   162         -  SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six'
   163         -} {X'0100000006000000'}
   164         -
   165         -do_execsql_test 3.6 {
   166         -  REPLACE INTO t3(docid, content) VALUES (3, 'one two');
   167         -  SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one'
   168         -} {X'0100000002000000'}
   169         -
   170         -do_execsql_test 3.7 {
   171         -  REPLACE INTO t3(docid, content) VALUES (NULL, 'one two three four');
   172         -  REPLACE INTO t3(docid, content) VALUES (NULL, 'one two three four five six');
   173         -  SELECT docid FROM t3;
   174         -} {3 4 5}
   175         -
   176         -do_execsql_test 3.8 {
   177         -  UPDATE OR REPLACE t3 SET docid = 5, content='three four' WHERE docid = 4;
   178         -  SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one'
   179         -} {X'0200000002000000'}
          139  +if {$tcl_platform(byteOrder)=="littleEndian"} {
          140  +  do_execsql_test 3.1 {
          141  +    CREATE VIRTUAL TABLE t3 USING fts4;
          142  +    REPLACE INTO t3(docid, content) VALUES (1, 'one two');
          143  +    SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one'
          144  +  } {X'0100000002000000'}
          145  +  
          146  +  do_execsql_test 3.2 {
          147  +    REPLACE INTO t3(docid, content) VALUES (2, 'one two three four');
          148  +    SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'four'
          149  +  } {X'0200000003000000'}
          150  +  
          151  +  do_execsql_test 3.3 {
          152  +    REPLACE INTO t3(docid, content) VALUES (1, 'one two three four five six');
          153  +    SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six'
          154  +  } {X'0200000005000000'}
          155  +  
          156  +  do_execsql_test 3.4 {
          157  +    UPDATE OR REPLACE t3 SET docid = 2 WHERE docid=1;
          158  +    SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six'
          159  +  } {X'0100000006000000'}
          160  +  
          161  +  do_execsql_test 3.5 {
          162  +    UPDATE OR REPLACE t3 SET docid = 3 WHERE docid=2;
          163  +    SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six'
          164  +  } {X'0100000006000000'}
          165  +  
          166  +  do_execsql_test 3.6 {
          167  +    REPLACE INTO t3(docid, content) VALUES (3, 'one two');
          168  +    SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one'
          169  +  } {X'0100000002000000'}
          170  +  
          171  +  do_execsql_test 3.7 {
          172  +    REPLACE INTO t3(docid, content) VALUES(NULL,'one two three four');
          173  +    REPLACE INTO t3(docid, content) VALUES(NULL,'one two three four five six');
          174  +    SELECT docid FROM t3;
          175  +  } {3 4 5}
          176  +  
          177  +  do_execsql_test 3.8 {
          178  +    UPDATE OR REPLACE t3 SET docid = 5, content='three four' WHERE docid = 4;
          179  +    SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one'
          180  +  } {X'0200000002000000'}
          181  +}
   180    182   
   181    183   #-------------------------------------------------------------------------
   182    184   # Test that the xSavepoint is invoked correctly if the first write 
   183    185   # operation within a transaction is to a virtual table. 
   184    186   # 
   185    187   do_catchsql_test 4.1.1 {
   186    188     CREATE VIRTUAL TABLE t0 USING fts4;

Changes to test/misc1.test.

   707    707   # minutes to prepare.  This has been speeded up to about 250 milliseconds.
   708    708   #
   709    709   do_catchsql_test misc1-25.0 {
   710    710   SELECT-1 UNION  SELECT 5 UNION SELECT 0 UNION SElECT*from(SELECT-5) UNION SELECT*from(SELECT-0) UNION  SELECT:SELECT-0 UNION SELECT-1 UNION SELECT 1 UNION SELECT 1 ORDER BY S  in(WITH K AS(WITH K AS(select'CREINDERcharREADEVIRTUL5TABLECONFLICT !1 USIN'' MFtOR(b38q,eWITH K AS(selectCREATe TABLE t0(a,b,c,d,e, PRIMARY KEY(a,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,b,c,d,c,a,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d'CEIl,k'',ab, g, a,b,o11b, i'nEX/charREDE IVT LR!VABLt5SG',N  ,N in rement,l_vacuum,M&U,'te3(''5l' a,bB,b,l*e)SELECT:SELECT, *,*,*from(( SELECT
   711    711   $group,:conc ap0,1)fro,(select"",:PBAG,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,c,d,c,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d, foreign_keysc,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,c,d,c,a,b,d,d,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,bb,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,c,d,c,a,b,d,d,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,MAato_aecSELEC,+?b," "O,"i","a",""b  ,5 ))KEY)SELECT*FROM((k()reaC,k,K) eA,k '' )t ,K  M);
   712    712   } {1 {'k' is not a function}}
   713    713   
          714  +# 2017-09-17
          715  +#
          716  +# Sometimes sqlite3ExprListAppend() can be invoked on an ExprList that
          717  +# was obtained from sqlite3ExprListDup().
          718  +#
          719  +do_execsql_test misc1-26.0 {
          720  +  DROP TABLE IF EXISTS abc;
          721  +  CREATE TABLE abc(a, b, c);
          722  +  SELECT randomblob(min(max(coalesce(EXISTS (SELECT 1 FROM ( SELECT (SELECT 2147483647) NOT IN (SELECT 2147483649 UNION ALL SELECT DISTINCT -1) IN (SELECT 2147483649), 'fault', (SELECT ALL -1 INTERSECT SELECT 'experiments') IN (SELECT ALL 56.1 ORDER BY 'experiments' DESC) FROM (SELECT DISTINCT 2147483648, 'hardware' UNION ALL SELECT -2147483648, 'experiments' ORDER BY 2147483648 LIMIT 1 OFFSET 123456789.1234567899) GROUP BY (SELECT ALL 0 INTERSECT SELECT 'in') IN (SELECT DISTINCT 'experiments' ORDER BY zeroblob(1000) LIMIT 56.1 OFFSET -456) HAVING EXISTS (SELECT 'fault' EXCEPT    SELECT DISTINCT 56.1) UNION SELECT 'The', 'The', 2147483649 UNION ALL SELECT DISTINCT 'hardware', 'first', 'experiments' ORDER BY 'hardware' LIMIT 123456789.1234567899 OFFSET -2147483647)) NOT IN (SELECT (SELECT DISTINCT (SELECT 'The') FROM abc ORDER BY EXISTS (SELECT -1 INTERSECT SELECT ALL NULL) ASC) IN (SELECT DISTINCT EXISTS (SELECT ALL 123456789.1234567899 ORDER BY 1 ASC, NULL DESC) FROM sqlite_master INTERSECT SELECT 456)), (SELECT ALL 'injection' UNION ALL SELECT ALL (SELECT DISTINCT 'first' UNION     SELECT DISTINCT 'The') FROM (SELECT 456, 'in', 2147483649))),1), 500)), 'first', EXISTS (SELECT DISTINCT 456 FROM abc ORDER BY 'experiments' DESC) FROM abc;
          723  +} {}
   714    724   
   715    725   finish_test

Added test/mjournal.test.

            1  +# 2017 September 15
            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.
           12  +#
           13  +
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +set testprefix mjournal
           17  +
           18  +# Test that nothing bad happens if a journal file contains a pointer to
           19  +# a master journal file that does not have a "-" in the name. At one point
           20  +# this was causing a segfault on unix.
           21  +#
           22  +do_execsql_test 1.0 {
           23  +  CREATE TABLE t1(a, b);
           24  +}
           25  +
           26  +do_test 1.1 {
           27  +  forcedelete test.db2journal test.db-journal
           28  +
           29  +  close [open test.db-journal w]
           30  +  
           31  +  hexio_write test.db-journal 0 746573742e6462326a6f75726e616c00
           32  +  hexio_write test.db-journal 16 00000010
           33  +  hexio_write test.db-journal 20 000005e1
           34  +  hexio_write test.db-journal 24 d9d505f920a163d7
           35  +
           36  +  close [open test.db2journal w]
           37  +  hexio_write test.db2journal 0 abcd
           38  +} {2}
           39  +
           40  +do_execsql_test 1.2 {
           41  +  SELECT * FROM t1;
           42  +}
           43  +
           44  +do_test 1.3 {
           45  +  forcedelete test0db2journal test.db-journal
           46  +  close [open test.db-journal w]
           47  +  hexio_write test.db-journal 0 74657374306462326a6f75726e616c00
           48  +  hexio_write test.db-journal 16 00000010
           49  +  hexio_write test.db-journal 20 000005e3
           50  +  hexio_write test.db-journal 24 d9d505f920a163d7
           51  +
           52  +  close [open test0db2journal w]
           53  +  hexio_write test0db2journal 0 abcd
           54  +} {2}
           55  +
           56  +do_execsql_test 1.4 {
           57  +  SELECT * FROM t1;
           58  +}
           59  +
           60  +# And now test that nothing bad happens if a master journal contains a
           61  +# pointer to a journal file that does not have a "-" in the name. 
           62  +#
           63  +do_test 1.5 {
           64  +  forcedelete test.db2-master test.db-journal test1
           65  +  close [open test.db-journal w]
           66  +  hexio_write test.db-journal 0 746573742e6462322d6d617374657200
           67  +  hexio_write test.db-journal 16 00000010
           68  +  hexio_write test.db-journal 20 0000059f
           69  +  hexio_write test.db-journal 24 d9d505f920a163d7
           70  +
           71  +  close [open test.db2-master w]
           72  +  hexio_write test.db2-master 0 746573743100
           73  +
           74  +  close [open test1 w]
           75  +  hexio_write test1 0 abcd
           76  +} {2}
           77  +
           78  +do_execsql_test 1.6 {
           79  +  SELECT * FROM t1;
           80  +}
           81  +
           82  +  
           83  +finish_test

Changes to test/pragma.test.

  1949   1949   
  1950   1950   sqlite3 db test.db
  1951   1951   do_catchsql_test 24.1 {
  1952   1952     SELECT * FROM t1;
  1953   1953   } {1 {database disk image is malformed}}
  1954   1954   do_catchsql_test 24.2 {
  1955   1955     PRAGMA integrity_check;
  1956         -} {1 {database disk image is malformed}}
         1956  +} {0 {{database disk image is malformed}}}
  1957   1957   
  1958   1958   database_never_corrupt
  1959   1959   finish_test

Changes to test/releasetest.tcl.

   110    110       -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
   111    111       -DSQLITE_ENABLE_STAT4
   112    112       -DSQLITE_ENABLE_STMT_SCANSTATUS
   113    113       --enable-json1 --enable-fts5 --enable-session
   114    114     }
   115    115     "Debug-One" {
   116    116       --disable-shared
   117         -    -O2
          117  +    -O2 -funsigned-char
   118    118       -DSQLITE_DEBUG=1
   119    119       -DSQLITE_MEMDEBUG=1
   120    120       -DSQLITE_MUTEX_NOOP=1
   121    121       -DSQLITE_TCL_DEFAULT_FULLMUTEX=1
   122    122       -DSQLITE_ENABLE_FTS3=1
   123    123       -DSQLITE_ENABLE_RTREE=1
   124    124       -DSQLITE_ENABLE_MEMSYS5=1

Changes to test/win32heap.test.

     5      5   #
     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12         -# focus of this script is recovery from transient manditory locks
    13         -# that sometimes appear on database files due to anti-virus software.
           12  +# focus of this script is the Win32 heap implementation.
    14     13   #
    15     14   
    16     15   if {$tcl_platform(platform)!="windows"} return
    17     16   
    18     17   set testdir [file dirname $argv0]
    19     18   source $testdir/tester.tcl
    20     19