/ Check-in [cfd110bf]
Login

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

Overview
Comment:Merge the latest trunk changes into the sessions branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: cfd110bf5db2c1993a5e2ca718648bd9c17ee22c
User & Date: drh 2013-12-24 12:09:42
Context
2014-01-24
14:05
Bring in all the latest trunk changes, including the Common Table Expressions implementation. check-in: 9b43e559 user: drh tags: sessions
2013-12-24
12:09
Merge the latest trunk changes into the sessions branch. check-in: cfd110bf user: drh tags: sessions
12:04
Add -I. to the main.mk makefile for building sqlite3.o and speedtest1. check-in: cc72c5ae user: drh tags: trunk
2013-12-14
18:24
Merge in all recent preformance enhancements from trunk. check-in: 32477642 user: drh tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3_porter.c.

   399    399     if( z[0]=='y' && hasVowel(z+1) ){
   400    400       z[0] = 'i';
   401    401     }
   402    402   
   403    403     /* Step 2 */
   404    404     switch( z[1] ){
   405    405      case 'a':
   406         -     stem(&z, "lanoita", "ate", m_gt_0) ||
   407         -     stem(&z, "lanoit", "tion", m_gt_0);
          406  +     if( !stem(&z, "lanoita", "ate", m_gt_0) ){
          407  +       stem(&z, "lanoit", "tion", m_gt_0);
          408  +     }
   408    409        break;
   409    410      case 'c':
   410         -     stem(&z, "icne", "ence", m_gt_0) ||
   411         -     stem(&z, "icna", "ance", m_gt_0);
          411  +     if( !stem(&z, "icne", "ence", m_gt_0) ){
          412  +       stem(&z, "icna", "ance", m_gt_0);
          413  +     }
   412    414        break;
   413    415      case 'e':
   414    416        stem(&z, "rezi", "ize", m_gt_0);
   415    417        break;
   416    418      case 'g':
   417    419        stem(&z, "igol", "log", m_gt_0);
   418    420        break;
   419    421      case 'l':
   420         -     stem(&z, "ilb", "ble", m_gt_0) ||
   421         -     stem(&z, "illa", "al", m_gt_0) ||
   422         -     stem(&z, "iltne", "ent", m_gt_0) ||
   423         -     stem(&z, "ile", "e", m_gt_0) ||
   424         -     stem(&z, "ilsuo", "ous", m_gt_0);
          422  +     if( !stem(&z, "ilb", "ble", m_gt_0) 
          423  +      && !stem(&z, "illa", "al", m_gt_0)
          424  +      && !stem(&z, "iltne", "ent", m_gt_0)
          425  +      && !stem(&z, "ile", "e", m_gt_0)
          426  +     ){
          427  +       stem(&z, "ilsuo", "ous", m_gt_0);
          428  +     }
   425    429        break;
   426    430      case 'o':
   427         -     stem(&z, "noitazi", "ize", m_gt_0) ||
   428         -     stem(&z, "noita", "ate", m_gt_0) ||
   429         -     stem(&z, "rota", "ate", m_gt_0);
          431  +     if( !stem(&z, "noitazi", "ize", m_gt_0)
          432  +      && !stem(&z, "noita", "ate", m_gt_0)
          433  +     ){
          434  +       stem(&z, "rota", "ate", m_gt_0);
          435  +     }
   430    436        break;
   431    437      case 's':
   432         -     stem(&z, "msila", "al", m_gt_0) ||
   433         -     stem(&z, "ssenevi", "ive", m_gt_0) ||
   434         -     stem(&z, "ssenluf", "ful", m_gt_0) ||
   435         -     stem(&z, "ssensuo", "ous", m_gt_0);
          438  +     if( !stem(&z, "msila", "al", m_gt_0)
          439  +      && !stem(&z, "ssenevi", "ive", m_gt_0)
          440  +      && !stem(&z, "ssenluf", "ful", m_gt_0)
          441  +     ){
          442  +       stem(&z, "ssensuo", "ous", m_gt_0);
          443  +     }
   436    444        break;
   437    445      case 't':
   438         -     stem(&z, "itila", "al", m_gt_0) ||
   439         -     stem(&z, "itivi", "ive", m_gt_0) ||
   440         -     stem(&z, "itilib", "ble", m_gt_0);
          446  +     if( !stem(&z, "itila", "al", m_gt_0)
          447  +      && !stem(&z, "itivi", "ive", m_gt_0)
          448  +     ){
          449  +       stem(&z, "itilib", "ble", m_gt_0);
          450  +     }
   441    451        break;
   442    452     }
   443    453   
   444    454     /* Step 3 */
   445    455     switch( z[0] ){
   446    456      case 'e':
   447         -     stem(&z, "etaci", "ic", m_gt_0) ||
   448         -     stem(&z, "evita", "", m_gt_0)   ||
   449         -     stem(&z, "ezila", "al", m_gt_0);
          457  +     if( !stem(&z, "etaci", "ic", m_gt_0)
          458  +      && !stem(&z, "evita", "", m_gt_0)
          459  +     ){
          460  +       stem(&z, "ezila", "al", m_gt_0);
          461  +     }
   450    462        break;
   451    463      case 'i':
   452    464        stem(&z, "itici", "ic", m_gt_0);
   453    465        break;
   454    466      case 'l':
   455         -     stem(&z, "laci", "ic", m_gt_0) ||
   456         -     stem(&z, "luf", "", m_gt_0);
          467  +     if( !stem(&z, "laci", "ic", m_gt_0) ){
          468  +       stem(&z, "luf", "", m_gt_0);
          469  +     }
   457    470        break;
   458    471      case 's':
   459    472        stem(&z, "ssen", "", m_gt_0);
   460    473        break;
   461    474     }
   462    475   
   463    476     /* Step 4 */
................................................................................
   490    503      case 'n':
   491    504        if( z[0]=='t' ){
   492    505          if( z[2]=='a' ){
   493    506            if( m_gt_1(z+3) ){
   494    507              z += 3;
   495    508            }
   496    509          }else if( z[2]=='e' ){
   497         -         stem(&z, "tneme", "", m_gt_1) ||
   498         -         stem(&z, "tnem", "", m_gt_1) ||
   499         -         stem(&z, "tne", "", m_gt_1);
          510  +         if( !stem(&z, "tneme", "", m_gt_1)
          511  +          && !stem(&z, "tnem", "", m_gt_1)
          512  +         ){
          513  +           stem(&z, "tne", "", m_gt_1);
          514  +         }
   500    515          }
   501    516        }
   502    517        break;
   503    518      case 'o':
   504    519        if( z[0]=='u' ){
   505    520          if( m_gt_1(z+2) ){
   506    521            z += 2;
................................................................................
   511    526        break;
   512    527      case 's':
   513    528        if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
   514    529          z += 3;
   515    530        }
   516    531        break;
   517    532      case 't':
   518         -     stem(&z, "eta", "", m_gt_1) ||
   519         -     stem(&z, "iti", "", m_gt_1);
          533  +     if( !stem(&z, "eta", "", m_gt_1) ){
          534  +       stem(&z, "iti", "", m_gt_1);
          535  +     }
   520    536        break;
   521    537      case 'u':
   522    538        if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
   523    539          z += 3;
   524    540        }
   525    541        break;
   526    542      case 'v':

Changes to main.mk.

   391    391   		libsqlite3.a $(LIBREADLINE) $(TLIBS) $(THREADLIB)
   392    392   
   393    393   mptester$(EXE):	sqlite3.c $(TOP)/mptest/mptest.c
   394    394   	$(TCCX) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \
   395    395   		$(TLIBS) $(THREADLIB)
   396    396   
   397    397   sqlite3.o:	sqlite3.c
   398         -	$(TCCX) -c sqlite3.c
          398  +	$(TCCX) -I. -c sqlite3.c
   399    399   
   400    400   # This target creates a directory named "tsrc" and fills it with
   401    401   # copies of all of the C source code and header files needed to
   402    402   # build on the target system.  Some of the C source code and header
   403    403   # files are automatically generated.  This target takes care of
   404    404   # all that automatic generation.
   405    405   #
................................................................................
   638    638   		$(TOP)/tool/showdb.c sqlite3.c
   639    639   
   640    640   wordcount$(EXE):	$(TOP)/test/wordcount.c sqlite3.c
   641    641   	$(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -o wordcount$(EXE) \
   642    642   		$(TOP)/test/wordcount.c sqlite3.c
   643    643   
   644    644   speedtest1$(EXE):	$(TOP)/test/speedtest1.c sqlite3.o
   645         -	$(TCC) -o speedtest1$(EXE) $(TOP)/test/speedtest1.c sqlite3.o $(THREADLIB)
          645  +	$(TCC) -I. -o speedtest1$(EXE) $(TOP)/test/speedtest1.c sqlite3.o $(THREADLIB)
   646    646   
   647    647   # This target will fail if the SQLite amalgamation contains any exported
   648    648   # symbols that do not begin with "sqlite3_". It is run as part of the
   649    649   # releasetest.tcl script.
   650    650   #
   651    651   checksymbols: sqlite3.o
   652    652   	nm -g --defined-only sqlite3.o | grep -v " sqlite3_" ; test $$? -ne 0

Changes to src/attach.c.

    34     34   */
    35     35   static int resolveAttachExpr(NameContext *pName, Expr *pExpr)
    36     36   {
    37     37     int rc = SQLITE_OK;
    38     38     if( pExpr ){
    39     39       if( pExpr->op!=TK_ID ){
    40     40         rc = sqlite3ResolveExprNames(pName, pExpr);
    41         -      if( rc==SQLITE_OK && !sqlite3ExprIsConstant(pExpr) ){
    42         -        sqlite3ErrorMsg(pName->pParse, "invalid name: \"%s\"", pExpr->u.zToken);
    43         -        return SQLITE_ERROR;
    44         -      }
    45     41       }else{
    46     42         pExpr->op = TK_STRING;
    47     43       }
    48     44     }
    49     45     return rc;
    50     46   }
    51     47   

Changes to src/delete.c.

   776    776     int *piPartIdxLabel  /* OUT: Jump to this label to skip partial index */
   777    777   ){
   778    778     Vdbe *v = pParse->pVdbe;
   779    779     int j;
   780    780     Table *pTab = pIdx->pTable;
   781    781     int regBase;
   782    782     int nCol;
   783         -  Index *pPk;
   784    783   
   785    784     if( piPartIdxLabel ){
   786    785       if( pIdx->pPartIdxWhere ){
   787    786         *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
   788    787         pParse->iPartIdxTab = iDataCur;
   789    788         sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, 
   790    789                            SQLITE_JUMPIFNULL);
   791    790       }else{
   792    791         *piPartIdxLabel = 0;
   793    792       }
   794    793     }
   795    794     nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
   796    795     regBase = sqlite3GetTempRange(pParse, nCol);
   797         -  pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
   798    796     for(j=0; j<nCol; j++){
   799         -    i16 idx = pIdx->aiColumn[j];
   800         -    if( pPk ) idx = sqlite3ColumnOfIndex(pPk, idx);
   801         -    if( idx<0 || idx==pTab->iPKey ){
   802         -      sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regBase+j);
   803         -    }else{
   804         -      sqlite3VdbeAddOp3(v, OP_Column, iDataCur, idx, regBase+j);
   805         -      sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[j], -1);
   806         -    }
          797  +    sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
          798  +                                    regBase+j);
   807    799     }
   808    800     if( regOut ){
   809    801       const char *zAff;
   810    802       if( pTab->pSelect
   811    803        || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
   812    804       ){
   813    805         zAff = 0;

Changes to src/expr.c.

  2166   2166   /*
  2167   2167   ** Remember the current column cache context.  Any new entries added
  2168   2168   ** added to the column cache after this call are removed when the
  2169   2169   ** corresponding pop occurs.
  2170   2170   */
  2171   2171   void sqlite3ExprCachePush(Parse *pParse){
  2172   2172     pParse->iCacheLevel++;
         2173  +#ifdef SQLITE_DEBUG
         2174  +  if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
         2175  +    printf("PUSH to %d\n", pParse->iCacheLevel);
         2176  +  }
         2177  +#endif
  2173   2178   }
  2174   2179   
  2175   2180   /*
  2176   2181   ** Remove from the column cache any entries that were added since the
  2177   2182   ** the previous N Push operations.  In other words, restore the cache
  2178   2183   ** to the state it was in N Pushes ago.
  2179   2184   */
  2180   2185   void sqlite3ExprCachePop(Parse *pParse, int N){
  2181   2186     int i;
  2182   2187     struct yColCache *p;
  2183   2188     assert( N>0 );
  2184   2189     assert( pParse->iCacheLevel>=N );
  2185   2190     pParse->iCacheLevel -= N;
         2191  +#ifdef SQLITE_DEBUG
         2192  +  if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
         2193  +    printf("POP  to %d\n", pParse->iCacheLevel);
         2194  +  }
         2195  +#endif
  2186   2196     for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
  2187   2197       if( p->iReg && p->iLevel>pParse->iCacheLevel ){
  2188   2198         cacheEntryClear(pParse, p);
  2189   2199         p->iReg = 0;
  2190   2200       }
  2191   2201     }
  2192   2202   }
................................................................................
  2273   2283   /*
  2274   2284   ** Clear all column cache entries.
  2275   2285   */
  2276   2286   void sqlite3ExprCacheClear(Parse *pParse){
  2277   2287     int i;
  2278   2288     struct yColCache *p;
  2279   2289   
         2290  +#if SQLITE_DEBUG
         2291  +  if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
         2292  +    printf("CLEAR\n");
         2293  +  }
         2294  +#endif
  2280   2295     for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
  2281   2296       if( p->iReg ){
  2282   2297         cacheEntryClear(pParse, p);
  2283   2298         p->iReg = 0;
  2284   2299       }
  2285   2300     }
  2286   2301   }
................................................................................
  3409   3424     for(pItem=pList->a, i=0; i<n; i++, pItem++){
  3410   3425       Expr *pExpr = pItem->pExpr;
  3411   3426       if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
  3412   3427         sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
  3413   3428       }else{
  3414   3429         int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
  3415   3430         if( inReg!=target+i ){
  3416         -        sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i);
         3431  +        VdbeOp *pOp;
         3432  +        Vdbe *v = pParse->pVdbe;
         3433  +        if( copyOp==OP_Copy
         3434  +         && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
         3435  +         && pOp->p1+pOp->p3+1==inReg
         3436  +         && pOp->p2+pOp->p3+1==target+i
         3437  +        ){
         3438  +          pOp->p3++;
         3439  +        }else{
         3440  +          sqlite3VdbeAddOp2(v, copyOp, inReg, target+i);
         3441  +        }
  3417   3442         }
  3418   3443       }
  3419   3444     }
  3420   3445     return n;
  3421   3446   }
  3422   3447   
  3423   3448   /*

Changes to src/func.c.

   213    213         nHaystack--;
   214    214         zHaystack++;
   215    215       }while( isText && (zHaystack[0]&0xc0)==0x80 );
   216    216     }
   217    217     if( nNeedle>nHaystack ) N = 0;
   218    218     sqlite3_result_int(context, N);
   219    219   }
          220  +
          221  +/*
          222  +** Implementation of the printf() function.
          223  +*/
          224  +static void printfFunc(
          225  +  sqlite3_context *context,
          226  +  int argc,
          227  +  sqlite3_value **argv
          228  +){
          229  +  PrintfArguments x;
          230  +  StrAccum str;
          231  +  const char *zFormat;
          232  +  int n;
          233  +
          234  +  if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
          235  +    x.nArg = argc-1;
          236  +    x.nUsed = 0;
          237  +    x.apArg = argv+1;
          238  +    sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
          239  +    str.db = sqlite3_context_db_handle(context);
          240  +    sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
          241  +    n = str.nChar;
          242  +    sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
          243  +                        SQLITE_DYNAMIC);
          244  +  }
          245  +}
   220    246   
   221    247   /*
   222    248   ** Implementation of the substr() function.
   223    249   **
   224    250   ** substr(x,p1,p2)  returns p2 characters of x[] beginning with p1.
   225    251   ** p1 is 1-indexed.  So substr(x,1,1) returns the first character
   226    252   ** of x.  If x is text, then we actually count UTF-8 characters.
................................................................................
  1644   1670       FUNCTION(max,                0, 1, 1, 0                ),
  1645   1671       AGGREGATE(max,               1, 1, 1, minmaxStep,      minMaxFinalize ),
  1646   1672       FUNCTION2(typeof,            1, 0, 0, typeofFunc,  SQLITE_FUNC_TYPEOF),
  1647   1673       FUNCTION2(length,            1, 0, 0, lengthFunc,  SQLITE_FUNC_LENGTH),
  1648   1674       FUNCTION(instr,              2, 0, 0, instrFunc        ),
  1649   1675       FUNCTION(substr,             2, 0, 0, substrFunc       ),
  1650   1676       FUNCTION(substr,             3, 0, 0, substrFunc       ),
         1677  +    FUNCTION(printf,            -1, 0, 0, printfFunc       ),
  1651   1678       FUNCTION(unicode,            1, 0, 0, unicodeFunc      ),
  1652   1679       FUNCTION(char,              -1, 0, 0, charFunc         ),
  1653   1680       FUNCTION(abs,                1, 0, 0, absFunc          ),
  1654   1681   #ifndef SQLITE_OMIT_FLOATING_POINT
  1655   1682       FUNCTION(round,              1, 0, 0, roundFunc        ),
  1656   1683       FUNCTION(round,              2, 0, 0, roundFunc        ),
  1657   1684   #endif

Changes to src/insert.c.

  1511   1511       
  1512   1512       /* Check to see if the new index entry will be unique */
  1513   1513       sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
  1514   1514                            regIdx, pIdx->nKeyCol);
  1515   1515   
  1516   1516       /* Generate code to handle collisions */
  1517   1517       regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
  1518         -    if( HasRowid(pTab) ){
  1519         -      sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
  1520         -      /* Conflict only if the rowid of the existing index entry
  1521         -      ** is different from old-rowid */
  1522         -      if( isUpdate ){
  1523         -        sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
  1524         -      }
  1525         -    }else{
  1526         -      int x;
  1527         -      /* Extract the PRIMARY KEY from the end of the index entry and
  1528         -      ** store it in registers regR..regR+nPk-1 */
  1529         -      if( (isUpdate || onError==OE_Replace) && pIdx!=pPk ){
  1530         -        for(i=0; i<pPk->nKeyCol; i++){
  1531         -          x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
  1532         -          sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
  1533         -          VdbeComment((v, "%s.%s", pTab->zName,
  1534         -                       pTab->aCol[pPk->aiColumn[i]].zName));
         1518  +    if( isUpdate || onError==OE_Replace ){
         1519  +      if( HasRowid(pTab) ){
         1520  +        sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
         1521  +        /* Conflict only if the rowid of the existing index entry
         1522  +        ** is different from old-rowid */
         1523  +        if( isUpdate ){
         1524  +          sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
         1525  +        }
         1526  +      }else{
         1527  +        int x;
         1528  +        /* Extract the PRIMARY KEY from the end of the index entry and
         1529  +        ** store it in registers regR..regR+nPk-1 */
         1530  +        if( pIdx!=pPk ){
         1531  +          for(i=0; i<pPk->nKeyCol; i++){
         1532  +            x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
         1533  +            sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
         1534  +            VdbeComment((v, "%s.%s", pTab->zName,
         1535  +                         pTab->aCol[pPk->aiColumn[i]].zName));
         1536  +          }
  1535   1537           }
  1536         -      }
  1537         -      if( isUpdate ){
  1538         -        /* If currently processing the PRIMARY KEY of a WITHOUT ROWID 
  1539         -        ** table, only conflict if the new PRIMARY KEY values are actually
  1540         -        ** different from the old.
  1541         -        **
  1542         -        ** For a UNIQUE index, only conflict if the PRIMARY KEY values
  1543         -        ** of the matched index row are different from the original PRIMARY
  1544         -        ** KEY values of this row before the update.  */
  1545         -        int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
  1546         -        int op = OP_Ne;
  1547         -        int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
  1548         -
  1549         -        for(i=0; i<pPk->nKeyCol; i++){
  1550         -          char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
  1551         -          x = pPk->aiColumn[i];
  1552         -          if( i==(pPk->nKeyCol-1) ){
  1553         -            addrJump = addrUniqueOk;
  1554         -            op = OP_Eq;
  1555         -          }
  1556         -          sqlite3VdbeAddOp4(v, op, 
  1557         -              regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
  1558         -          );
         1538  +        if( isUpdate ){
         1539  +          /* If currently processing the PRIMARY KEY of a WITHOUT ROWID 
         1540  +          ** table, only conflict if the new PRIMARY KEY values are actually
         1541  +          ** different from the old.
         1542  +          **
         1543  +          ** For a UNIQUE index, only conflict if the PRIMARY KEY values
         1544  +          ** of the matched index row are different from the original PRIMARY
         1545  +          ** KEY values of this row before the update.  */
         1546  +          int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
         1547  +          int op = OP_Ne;
         1548  +          int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
         1549  +  
         1550  +          for(i=0; i<pPk->nKeyCol; i++){
         1551  +            char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
         1552  +            x = pPk->aiColumn[i];
         1553  +            if( i==(pPk->nKeyCol-1) ){
         1554  +              addrJump = addrUniqueOk;
         1555  +              op = OP_Eq;
         1556  +            }
         1557  +            sqlite3VdbeAddOp4(v, op, 
         1558  +                regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
         1559  +            );
         1560  +          }
  1559   1561           }
  1560   1562         }
  1561   1563       }
  1562   1564   
  1563   1565       /* Generate code that executes if the new index entry is not unique */
  1564   1566       assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
  1565   1567           || onError==OE_Ignore || onError==OE_Replace );

Changes to src/main.c.

  1058   1058     }
  1059   1059   }
  1060   1060   
  1061   1061   /*
  1062   1062   ** Return a static string containing the name corresponding to the error code
  1063   1063   ** specified in the argument.
  1064   1064   */
  1065         -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
  1066         -    defined(SQLITE_DEBUG_OS_TRACE)
         1065  +#if defined(SQLITE_TEST)
  1067   1066   const char *sqlite3ErrName(int rc){
  1068   1067     const char *zName = 0;
  1069   1068     int i, origRc = rc;
  1070   1069     for(i=0; i<2 && zName==0; i++, rc &= 0xff){
  1071   1070       switch( rc ){
  1072   1071         case SQLITE_OK:                 zName = "SQLITE_OK";                break;
  1073   1072         case SQLITE_ERROR:              zName = "SQLITE_ERROR";             break;
................................................................................
  2657   2656     ** mode.  Doing nothing at all also makes NORMAL the default.
  2658   2657     */
  2659   2658   #ifdef SQLITE_DEFAULT_LOCKING_MODE
  2660   2659     db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
  2661   2660     sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
  2662   2661                             SQLITE_DEFAULT_LOCKING_MODE);
  2663   2662   #endif
         2663  +
         2664  +  if( rc ) sqlite3Error(db, rc, 0);
  2664   2665   
  2665   2666     /* Enable the lookaside-malloc subsystem */
  2666   2667     setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
  2667   2668                           sqlite3GlobalConfig.nLookaside);
  2668   2669   
  2669   2670     sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
  2670   2671   

Changes to src/os.c.

   103    103   ** and we need to know about the failures.  Use sqlite3OsFileControlHint()
   104    104   ** when simply tossing information over the wall to the VFS and we do not
   105    105   ** really care if the VFS receives and understands the information since it
   106    106   ** is only a hint and can be safely ignored.  The sqlite3OsFileControlHint()
   107    107   ** routine has no return value since the return value would be meaningless.
   108    108   */
   109    109   int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
   110         -  DO_OS_MALLOC_TEST(id);
          110  +#ifdef SQLITE_TEST
          111  +  if( op!=SQLITE_FCNTL_COMMIT_PHASETWO ){
          112  +    /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
          113  +    ** is using a regular VFS, it is called after the corresponding 
          114  +    ** transaction has been committed. Injecting a fault at this point 
          115  +    ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM
          116  +    ** but the transaction is committed anyway.
          117  +    **
          118  +    ** The core must call OsFileControl() though, not OsFileControlHint(),
          119  +    ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
          120  +    ** means the commit really has failed and an error should be returned
          121  +    ** to the user.  */
          122  +    DO_OS_MALLOC_TEST(id);
          123  +  }
          124  +#endif
   111    125     return id->pMethods->xFileControl(id, op, pArg);
   112    126   }
   113    127   void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){
   114    128     (void)id->pMethods->xFileControl(id, op, pArg);
   115    129   }
   116    130   
   117    131   int sqlite3OsSectorSize(sqlite3_file *id){

Changes to src/prepare.c.

   524    524     return i;
   525    525   }
   526    526   
   527    527   /*
   528    528   ** Free all memory allocations in the pParse object
   529    529   */
   530    530   void sqlite3ParserReset(Parse *pParse){
   531         -  if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
          531  +  if( pParse ){
          532  +    sqlite3 *db = pParse->db;
          533  +    sqlite3DbFree(db, pParse->aLabel);
          534  +    sqlite3ExprListDelete(db, pParse->pConstExpr);
          535  +  }
   532    536   }
   533    537   
   534    538   /*
   535    539   ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
   536    540   */
   537    541   static int sqlite3Prepare(
   538    542     sqlite3 *db,              /* Database handle. */

Changes to src/printf.c.

   147    147       sqlite3StrAccumAppend(pAccum, zSpaces, N);
   148    148     }
   149    149   }
   150    150   
   151    151   /*
   152    152   ** Set the StrAccum object to an error mode.
   153    153   */
   154         -void setStrAccumError(StrAccum *p, u8 eError){
          154  +static void setStrAccumError(StrAccum *p, u8 eError){
   155    155     p->accError = eError;
   156    156     p->nAlloc = 0;
   157    157   }
          158  +
          159  +/*
          160  +** Extra argument values from a PrintfArguments object
          161  +*/
          162  +static sqlite3_int64 getIntArg(PrintfArguments *p){
          163  +  if( p->nArg<=p->nUsed ) return 0;
          164  +  return sqlite3_value_int64(p->apArg[p->nUsed++]);
          165  +}
          166  +static double getDoubleArg(PrintfArguments *p){
          167  +  if( p->nArg<=p->nUsed ) return 0.0;
          168  +  return sqlite3_value_double(p->apArg[p->nUsed++]);
          169  +}
          170  +static char *getTextArg(PrintfArguments *p){
          171  +  if( p->nArg<=p->nUsed ) return 0;
          172  +  return (char*)sqlite3_value_text(p->apArg[p->nUsed++]);
          173  +}
          174  +
   158    175   
   159    176   /*
   160    177   ** On machines with a small stack size, you can redefine the
   161    178   ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
   162    179   */
   163    180   #ifndef SQLITE_PRINT_BUF_SIZE
   164    181   # define SQLITE_PRINT_BUF_SIZE 70
................................................................................
   165    182   #endif
   166    183   #define etBUFSIZE SQLITE_PRINT_BUF_SIZE  /* Size of the output buffer */
   167    184   
   168    185   /*
   169    186   ** Render a string given by "fmt" into the StrAccum object.
   170    187   */
   171    188   void sqlite3VXPrintf(
   172         -  StrAccum *pAccum,                  /* Accumulate results here */
   173         -  int useExtended,                   /* Allow extended %-conversions */
   174         -  const char *fmt,                   /* Format string */
   175         -  va_list ap                         /* arguments */
          189  +  StrAccum *pAccum,          /* Accumulate results here */
          190  +  u32 bFlags,                /* SQLITE_PRINTF_* flags */
          191  +  const char *fmt,           /* Format string */
          192  +  va_list ap                 /* arguments */
   176    193   ){
   177    194     int c;                     /* Next character in the format string */
   178    195     char *bufpt;               /* Pointer to the conversion buffer */
   179    196     int precision;             /* Precision of the current field */
   180    197     int length;                /* Length of the field */
   181    198     int idx;                   /* A general purpose loop counter */
   182    199     int width;                 /* Width of the current field */
................................................................................
   186    203     etByte flag_alternateform; /* True if "#" flag is present */
   187    204     etByte flag_altform2;      /* True if "!" flag is present */
   188    205     etByte flag_zeropad;       /* True if field width constant starts with zero */
   189    206     etByte flag_long;          /* True if "l" flag is present */
   190    207     etByte flag_longlong;      /* True if the "ll" flag is present */
   191    208     etByte done;               /* Loop termination flag */
   192    209     etByte xtype = 0;          /* Conversion paradigm */
          210  +  u8 bArgList;               /* True for SQLITE_PRINTF_SQLFUNC */
          211  +  u8 useIntern;              /* Ok to use internal conversions (ex: %T) */
   193    212     char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */
   194    213     sqlite_uint64 longvalue;   /* Value for integer types */
   195    214     LONGDOUBLE_TYPE realvalue; /* Value for real types */
   196    215     const et_info *infop;      /* Pointer to the appropriate info structure */
   197    216     char *zOut;                /* Rendering buffer */
   198    217     int nOut;                  /* Size of the rendering buffer */
   199    218     char *zExtra;              /* Malloced memory used by some conversion */
................................................................................
   200    219   #ifndef SQLITE_OMIT_FLOATING_POINT
   201    220     int  exp, e2;              /* exponent of real numbers */
   202    221     int nsd;                   /* Number of significant digits returned */
   203    222     double rounder;            /* Used for rounding floating point values */
   204    223     etByte flag_dp;            /* True if decimal point should be shown */
   205    224     etByte flag_rtz;           /* True if trailing zeros should be removed */
   206    225   #endif
          226  +  PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
   207    227     char buf[etBUFSIZE];       /* Conversion buffer */
   208    228   
   209    229     bufpt = 0;
          230  +  if( bFlags ){
          231  +    if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
          232  +      pArgList = va_arg(ap, PrintfArguments*);
          233  +    }
          234  +    useIntern = bFlags & SQLITE_PRINTF_INTERNAL;
          235  +  }else{
          236  +    bArgList = useIntern = 0;
          237  +  }
   210    238     for(; (c=(*fmt))!=0; ++fmt){
   211    239       if( c!='%' ){
   212    240         int amt;
   213    241         bufpt = (char *)fmt;
   214    242         amt = 1;
   215    243         while( (c=(*++fmt))!='%' && c!=0 ) amt++;
   216    244         sqlite3StrAccumAppend(pAccum, bufpt, amt);
................................................................................
   234    262           case '0':   flag_zeropad = 1;         break;
   235    263           default:    done = 1;                 break;
   236    264         }
   237    265       }while( !done && (c=(*++fmt))!=0 );
   238    266       /* Get the field width */
   239    267       width = 0;
   240    268       if( c=='*' ){
   241         -      width = va_arg(ap,int);
          269  +      if( bArgList ){
          270  +        width = (int)getIntArg(pArgList);
          271  +      }else{
          272  +        width = va_arg(ap,int);
          273  +      }
   242    274         if( width<0 ){
   243    275           flag_leftjustify = 1;
   244    276           width = -width;
   245    277         }
   246    278         c = *++fmt;
   247    279       }else{
   248    280         while( c>='0' && c<='9' ){
................................................................................
   251    283         }
   252    284       }
   253    285       /* Get the precision */
   254    286       if( c=='.' ){
   255    287         precision = 0;
   256    288         c = *++fmt;
   257    289         if( c=='*' ){
   258         -        precision = va_arg(ap,int);
          290  +        if( bArgList ){
          291  +          precision = (int)getIntArg(pArgList);
          292  +        }else{
          293  +          precision = va_arg(ap,int);
          294  +        }
   259    295           if( precision<0 ) precision = -precision;
   260    296           c = *++fmt;
   261    297         }else{
   262    298           while( c>='0' && c<='9' ){
   263    299             precision = precision*10 + c - '0';
   264    300             c = *++fmt;
   265    301           }
................................................................................
   282    318       }
   283    319       /* Fetch the info entry for the field */
   284    320       infop = &fmtinfo[0];
   285    321       xtype = etINVALID;
   286    322       for(idx=0; idx<ArraySize(fmtinfo); idx++){
   287    323         if( c==fmtinfo[idx].fmttype ){
   288    324           infop = &fmtinfo[idx];
   289         -        if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
          325  +        if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
   290    326             xtype = infop->type;
   291    327           }else{
   292    328             return;
   293    329           }
   294    330           break;
   295    331         }
   296    332       }
................................................................................
   322    358           flag_longlong = sizeof(char*)==sizeof(i64);
   323    359           flag_long = sizeof(char*)==sizeof(long int);
   324    360           /* Fall through into the next case */
   325    361         case etORDINAL:
   326    362         case etRADIX:
   327    363           if( infop->flags & FLAG_SIGNED ){
   328    364             i64 v;
   329         -          if( flag_longlong ){
          365  +          if( bArgList ){
          366  +            v = getIntArg(pArgList);
          367  +          }else if( flag_longlong ){
   330    368               v = va_arg(ap,i64);
   331    369             }else if( flag_long ){
   332    370               v = va_arg(ap,long int);
   333    371             }else{
   334    372               v = va_arg(ap,int);
   335    373             }
   336    374             if( v<0 ){
................................................................................
   343    381             }else{
   344    382               longvalue = v;
   345    383               if( flag_plussign )        prefix = '+';
   346    384               else if( flag_blanksign )  prefix = ' ';
   347    385               else                       prefix = 0;
   348    386             }
   349    387           }else{
   350         -          if( flag_longlong ){
          388  +          if( bArgList ){
          389  +            longvalue = (u64)getIntArg(pArgList);
          390  +          }else if( flag_longlong ){
   351    391               longvalue = va_arg(ap,u64);
   352    392             }else if( flag_long ){
   353    393               longvalue = va_arg(ap,unsigned long int);
   354    394             }else{
   355    395               longvalue = va_arg(ap,unsigned int);
   356    396             }
   357    397             prefix = 0;
................................................................................
   403    443             for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
   404    444           }
   405    445           length = (int)(&zOut[nOut-1]-bufpt);
   406    446           break;
   407    447         case etFLOAT:
   408    448         case etEXP:
   409    449         case etGENERIC:
   410         -        realvalue = va_arg(ap,double);
          450  +        if( bArgList ){
          451  +          realvalue = getDoubleArg(pArgList);
          452  +        }else{
          453  +          realvalue = va_arg(ap,double);
          454  +        }
   411    455   #ifdef SQLITE_OMIT_FLOATING_POINT
   412    456           length = 0;
   413    457   #else
   414    458           if( precision<0 ) precision = 6;         /* Set default precision */
   415    459           if( realvalue<0.0 ){
   416    460             realvalue = -realvalue;
   417    461             prefix = '-';
................................................................................
   558    602             i = prefix!=0;
   559    603             while( nPad-- ) bufpt[i++] = '0';
   560    604             length = width;
   561    605           }
   562    606   #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */
   563    607           break;
   564    608         case etSIZE:
   565         -        *(va_arg(ap,int*)) = pAccum->nChar;
          609  +        if( !bArgList ){
          610  +          *(va_arg(ap,int*)) = pAccum->nChar;
          611  +        }
   566    612           length = width = 0;
   567    613           break;
   568    614         case etPERCENT:
   569    615           buf[0] = '%';
   570    616           bufpt = buf;
   571    617           length = 1;
   572    618           break;
   573    619         case etCHARX:
   574         -        c = va_arg(ap,int);
          620  +        if( bArgList ){
          621  +          bufpt = getTextArg(pArgList);
          622  +          c = bufpt ? bufpt[0] : 0;
          623  +        }else{
          624  +          c = va_arg(ap,int);
          625  +        }
   575    626           buf[0] = (char)c;
   576    627           if( precision>=0 ){
   577    628             for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
   578    629             length = precision;
   579    630           }else{
   580    631             length =1;
   581    632           }
   582    633           bufpt = buf;
   583    634           break;
   584    635         case etSTRING:
   585    636         case etDYNSTRING:
   586         -        bufpt = va_arg(ap,char*);
          637  +        if( bArgList ){
          638  +          bufpt = getTextArg(pArgList);
          639  +        }else{
          640  +          bufpt = va_arg(ap,char*);
          641  +        }
   587    642           if( bufpt==0 ){
   588    643             bufpt = "";
   589         -        }else if( xtype==etDYNSTRING ){
          644  +        }else if( xtype==etDYNSTRING && !bArgList ){
   590    645             zExtra = bufpt;
   591    646           }
   592    647           if( precision>=0 ){
   593    648             for(length=0; length<precision && bufpt[length]; length++){}
   594    649           }else{
   595    650             length = sqlite3Strlen30(bufpt);
   596    651           }
................................................................................
   598    653         case etSQLESCAPE:
   599    654         case etSQLESCAPE2:
   600    655         case etSQLESCAPE3: {
   601    656           int i, j, k, n, isnull;
   602    657           int needQuote;
   603    658           char ch;
   604    659           char q = ((xtype==etSQLESCAPE3)?'"':'\'');   /* Quote character */
   605         -        char *escarg = va_arg(ap,char*);
          660  +        char *escarg;
          661  +
          662  +        if( bArgList ){
          663  +          escarg = getTextArg(pArgList);
          664  +        }else{
          665  +          escarg = va_arg(ap,char*);
          666  +        }
   606    667           isnull = escarg==0;
   607    668           if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
   608    669           k = precision;
   609    670           for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
   610    671             if( ch==q )  n++;
   611    672           }
   612    673           needQuote = !isnull && xtype==etSQLESCAPE2;
................................................................................
   633    694           /* The precision in %q and %Q means how many input characters to
   634    695           ** consume, not the length of the output...
   635    696           ** if( precision>=0 && precision<length ) length = precision; */
   636    697           break;
   637    698         }
   638    699         case etTOKEN: {
   639    700           Token *pToken = va_arg(ap, Token*);
          701  +        assert( bArgList==0 );
   640    702           if( pToken && pToken->n ){
   641    703             sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
   642    704           }
   643    705           length = width = 0;
   644    706           break;
   645    707         }
   646    708         case etSRCLIST: {
   647    709           SrcList *pSrc = va_arg(ap, SrcList*);
   648    710           int k = va_arg(ap, int);
   649    711           struct SrcList_item *pItem = &pSrc->a[k];
          712  +        assert( bArgList==0 );
   650    713           assert( k>=0 && k<pSrc->nSrc );
   651    714           if( pItem->zDatabase ){
   652    715             sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
   653    716             sqlite3StrAccumAppend(pAccum, ".", 1);
   654    717           }
   655    718           sqlite3StrAccumAppendAll(pAccum, pItem->zName);
   656    719           length = width = 0;
................................................................................
   806    869     char *z;
   807    870     char zBase[SQLITE_PRINT_BUF_SIZE];
   808    871     StrAccum acc;
   809    872     assert( db!=0 );
   810    873     sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
   811    874                         db->aLimit[SQLITE_LIMIT_LENGTH]);
   812    875     acc.db = db;
   813         -  sqlite3VXPrintf(&acc, 1, zFormat, ap);
          876  +  sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
   814    877     z = sqlite3StrAccumFinish(&acc);
   815    878     if( acc.accError==STRACCUM_NOMEM ){
   816    879       db->mallocFailed = 1;
   817    880     }
   818    881     return z;
   819    882   }
   820    883   
................................................................................
   962   1025     va_end(ap);
   963   1026     sqlite3StrAccumFinish(&acc);
   964   1027     fprintf(stdout,"%s", zBuf);
   965   1028     fflush(stdout);
   966   1029   }
   967   1030   #endif
   968   1031   
   969         -#ifndef SQLITE_OMIT_TRACE
   970   1032   /*
   971   1033   ** variable-argument wrapper around sqlite3VXPrintf().
   972   1034   */
   973         -void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){
         1035  +void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
   974   1036     va_list ap;
   975   1037     va_start(ap,zFormat);
   976         -  sqlite3VXPrintf(p, 1, zFormat, ap);
         1038  +  sqlite3VXPrintf(p, bFlags, zFormat, ap);
   977   1039     va_end(ap);
   978   1040   }
   979         -#endif

Changes to src/select.c.

   594    594       for(i=0; i<nColumn; i++){
   595    595         sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
   596    596       }
   597    597     }else if( eDest!=SRT_Exists ){
   598    598       /* If the destination is an EXISTS(...) expression, the actual
   599    599       ** values returned by the SELECT are not required.
   600    600       */
   601         -    sqlite3ExprCacheClear(pParse);
   602    601       sqlite3ExprCodeExprList(pParse, pEList, regResult,
   603    602                               (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
   604    603     }
   605    604     nColumn = nResultCol;
   606    605   
   607    606     /* If the DISTINCT keyword was present on the SELECT statement
   608    607     ** and this row has been seen before, then do not make this row
................................................................................
  1561   1560   /*
  1562   1561   ** Get a VDBE for the given parser context.  Create a new one if necessary.
  1563   1562   ** If an error occurs, return NULL and leave a message in pParse.
  1564   1563   */
  1565   1564   Vdbe *sqlite3GetVdbe(Parse *pParse){
  1566   1565     Vdbe *v = pParse->pVdbe;
  1567   1566     if( v==0 ){
  1568         -    v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db);
         1567  +    v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
  1569   1568   #ifndef SQLITE_OMIT_TRACE
  1570   1569       if( v ){
  1571   1570         sqlite3VdbeAddOp0(v, OP_Trace);
  1572   1571       }
  1573   1572   #endif
  1574   1573     }
  1575   1574     return v;
................................................................................
  3819   3818   ** routine generates code that stores NULLs in all of those memory
  3820   3819   ** cells.
  3821   3820   */
  3822   3821   static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
  3823   3822     Vdbe *v = pParse->pVdbe;
  3824   3823     int i;
  3825   3824     struct AggInfo_func *pFunc;
  3826         -  if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){
  3827         -    return;
  3828         -  }
         3825  +  int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
         3826  +  if( nReg==0 ) return;
         3827  +#ifdef SQLITE_DEBUG
         3828  +  /* Verify that all AggInfo registers are within the range specified by
         3829  +  ** AggInfo.mnReg..AggInfo.mxReg */
         3830  +  assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
  3829   3831     for(i=0; i<pAggInfo->nColumn; i++){
  3830         -    sqlite3VdbeAddOp2(v, OP_Null, 0, pAggInfo->aCol[i].iMem);
         3832  +    assert( pAggInfo->aCol[i].iMem>=pAggInfo->mnReg
         3833  +         && pAggInfo->aCol[i].iMem<=pAggInfo->mxReg );
  3831   3834     }
         3835  +  for(i=0; i<pAggInfo->nFunc; i++){
         3836  +    assert( pAggInfo->aFunc[i].iMem>=pAggInfo->mnReg
         3837  +         && pAggInfo->aFunc[i].iMem<=pAggInfo->mxReg );
         3838  +  }
         3839  +#endif
         3840  +  sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
  3832   3841     for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
  3833         -    sqlite3VdbeAddOp2(v, OP_Null, 0, pFunc->iMem);
  3834   3842       if( pFunc->iDistinct>=0 ){
  3835   3843         Expr *pE = pFunc->pExpr;
  3836   3844         assert( !ExprHasProperty(pE, EP_xIsSelect) );
  3837   3845         if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
  3838   3846           sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
  3839   3847              "argument");
  3840   3848           pFunc->iDistinct = -1;
................................................................................
  3872   3880     int i;
  3873   3881     int regHit = 0;
  3874   3882     int addrHitTest = 0;
  3875   3883     struct AggInfo_func *pF;
  3876   3884     struct AggInfo_col *pC;
  3877   3885   
  3878   3886     pAggInfo->directMode = 1;
  3879         -  sqlite3ExprCacheClear(pParse);
  3880   3887     for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
  3881   3888       int nArg;
  3882   3889       int addrNext = 0;
  3883   3890       int regAgg;
  3884   3891       ExprList *pList = pF->pExpr->x.pList;
  3885   3892       assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
  3886   3893       if( pList ){
................................................................................
  4405   4412       ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
  4406   4413       ** SELECT statement.
  4407   4414       */
  4408   4415       memset(&sNC, 0, sizeof(sNC));
  4409   4416       sNC.pParse = pParse;
  4410   4417       sNC.pSrcList = pTabList;
  4411   4418       sNC.pAggInfo = &sAggInfo;
         4419  +    sAggInfo.mnReg = pParse->nMem+1;
  4412   4420       sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0;
  4413   4421       sAggInfo.pGroupBy = pGroupBy;
  4414   4422       sqlite3ExprAnalyzeAggList(&sNC, pEList);
  4415   4423       sqlite3ExprAnalyzeAggList(&sNC, pOrderBy);
  4416   4424       if( pHaving ){
  4417   4425         sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
  4418   4426       }
................................................................................
  4419   4427       sAggInfo.nAccumulator = sAggInfo.nColumn;
  4420   4428       for(i=0; i<sAggInfo.nFunc; i++){
  4421   4429         assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
  4422   4430         sNC.ncFlags |= NC_InAggFunc;
  4423   4431         sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
  4424   4432         sNC.ncFlags &= ~NC_InAggFunc;
  4425   4433       }
         4434  +    sAggInfo.mxReg = pParse->nMem;
  4426   4435       if( db->mallocFailed ) goto select_end;
  4427   4436   
  4428   4437       /* Processing for aggregates with GROUP BY is very different and
  4429   4438       ** much more complex than aggregates without a GROUP BY.
  4430   4439       */
  4431   4440       if( pGroupBy ){
  4432   4441         KeyInfo *pKeyInfo;  /* Keying information for the group by clause */

Changes to src/shell.c.

  3034   3034         break;
  3035   3035       }
  3036   3036       if( seenInterrupt ){
  3037   3037         if( in!=0 ) break;
  3038   3038         seenInterrupt = 0;
  3039   3039       }
  3040   3040       lineno++;
  3041         -    if( nSql==0 && _all_whitespace(zLine) ) continue;
         3041  +    if( nSql==0 && _all_whitespace(zLine) ){
         3042  +      if( p->echoOn ) printf("%s\n", zLine);
         3043  +      continue;
         3044  +    }
  3042   3045       if( zLine && zLine[0]=='.' && nSql==0 ){
  3043   3046         if( p->echoOn ) printf("%s\n", zLine);
  3044   3047         rc = do_meta_command(zLine, p);
  3045   3048         if( rc==2 ){ /* exit requested */
  3046   3049           break;
  3047   3050         }else if( rc ){
  3048   3051           errCnt++;
................................................................................
  3096   3099           }else{
  3097   3100             fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
  3098   3101           }
  3099   3102           errCnt++;
  3100   3103         }
  3101   3104         nSql = 0;
  3102   3105       }else if( nSql && _all_whitespace(zSql) ){
         3106  +      if( p->echoOn ) printf("%s\n", zSql);
  3103   3107         nSql = 0;
  3104   3108       }
  3105   3109     }
  3106   3110     if( nSql ){
  3107   3111       if( !_all_whitespace(zSql) ){
  3108   3112         fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
  3109   3113       }

Changes to src/sqliteInt.h.

   739    739   typedef struct KeyInfo KeyInfo;
   740    740   typedef struct Lookaside Lookaside;
   741    741   typedef struct LookasideSlot LookasideSlot;
   742    742   typedef struct Module Module;
   743    743   typedef struct NameContext NameContext;
   744    744   typedef struct Parse Parse;
   745    745   typedef struct PreUpdate PreUpdate;
          746  +typedef struct PrintfArguments PrintfArguments;
   746    747   typedef struct RowSet RowSet;
   747    748   typedef struct Savepoint Savepoint;
   748    749   typedef struct Select Select;
   749    750   typedef struct SelectDest SelectDest;
   750    751   typedef struct SrcList SrcList;
   751    752   typedef struct StrAccum StrAccum;
   752    753   typedef struct Table Table;
................................................................................
  1691   1692     u8 directMode;          /* Direct rendering mode means take data directly
  1692   1693                             ** from source tables rather than from accumulators */
  1693   1694     u8 useSortingIdx;       /* In direct mode, reference the sorting index rather
  1694   1695                             ** than the source table */
  1695   1696     int sortingIdx;         /* Cursor number of the sorting index */
  1696   1697     int sortingIdxPTab;     /* Cursor number of pseudo-table */
  1697   1698     int nSortingColumn;     /* Number of columns in the sorting index */
         1699  +  int mnReg, mxReg;       /* Range of registers allocated for aCol and aFunc */
  1698   1700     ExprList *pGroupBy;     /* The group by clause */
  1699   1701     struct AggInfo_col {    /* For each column used in source tables */
  1700   1702       Table *pTab;             /* Source table */
  1701   1703       int iTable;              /* Cursor number of the source table */
  1702   1704       int iColumn;             /* Column number within the source table */
  1703   1705       int iSorterColumn;       /* Column number in the sorting index */
  1704   1706       int iMem;                /* Memory location that acts as accumulator */
................................................................................
  2292   2294     int nRangeReg;       /* Size of the temporary register block */
  2293   2295     int iRangeReg;       /* First register in temporary register block */
  2294   2296     int nErr;            /* Number of errors seen */
  2295   2297     int nTab;            /* Number of previously allocated VDBE cursors */
  2296   2298     int nMem;            /* Number of memory cells used so far */
  2297   2299     int nSet;            /* Number of sets used so far */
  2298   2300     int nOnce;           /* Number of OP_Once instructions so far */
         2301  +  int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
         2302  +  int nLabel;          /* Number of labels used */
         2303  +  int *aLabel;         /* Space to hold the labels */
  2299   2304     int ckBase;          /* Base register of data during check constraints */
  2300   2305     int iPartIdxTab;     /* Table corresponding to a partial index */
  2301   2306     int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  2302   2307     int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
  2303   2308     struct yColCache {
  2304   2309       int iTable;           /* Table cursor number */
  2305   2310       int iColumn;          /* Table column number */
................................................................................
  2772   2777   
  2773   2778   #ifndef SQLITE_OMIT_FLOATING_POINT
  2774   2779     int sqlite3IsNaN(double);
  2775   2780   #else
  2776   2781   # define sqlite3IsNaN(X)  0
  2777   2782   #endif
  2778   2783   
  2779         -void sqlite3VXPrintf(StrAccum*, int, const char*, va_list);
  2780         -#ifndef SQLITE_OMIT_TRACE
  2781         -void sqlite3XPrintf(StrAccum*, const char*, ...);
  2782         -#endif
         2784  +/*
         2785  +** An instance of the following structure holds information about SQL
         2786  +** functions arguments that are the parameters to the printf() function.
         2787  +*/
         2788  +struct PrintfArguments {
         2789  +  int nArg;                /* Total number of arguments */
         2790  +  int nUsed;               /* Number of arguments used so far */
         2791  +  sqlite3_value **apArg;   /* The argument values */
         2792  +};
         2793  +
         2794  +#define SQLITE_PRINTF_INTERNAL 0x01
         2795  +#define SQLITE_PRINTF_SQLFUNC  0x02
         2796  +void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
         2797  +void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
  2783   2798   char *sqlite3MPrintf(sqlite3*,const char*, ...);
  2784   2799   char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
  2785   2800   char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
  2786   2801   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
  2787   2802     void sqlite3DebugPrintf(const char*, ...);
  2788   2803   #endif
  2789   2804   #if defined(SQLITE_TEST)
................................................................................
  3134   3149   char sqlite3ExprAffinity(Expr *pExpr);
  3135   3150   int sqlite3Atoi64(const char*, i64*, int, u8);
  3136   3151   void sqlite3Error(sqlite3*, int, const char*,...);
  3137   3152   void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
  3138   3153   u8 sqlite3HexToInt(int h);
  3139   3154   int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
  3140   3155   
  3141         -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
  3142         -    defined(SQLITE_DEBUG_OS_TRACE)
         3156  +#if defined(SQLITE_TEST) 
  3143   3157   const char *sqlite3ErrName(int);
  3144   3158   #endif
  3145   3159   
  3146   3160   const char *sqlite3ErrStr(int);
  3147   3161   int sqlite3ReadSchema(Parse *pParse);
  3148   3162   CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
  3149   3163   CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);

Changes to src/tclsqlite.c.

  1570   1570   ** even though the only invocations of them are within conditional blocks 
  1571   1571   ** of the form:
  1572   1572   **
  1573   1573   **   if( DbUseNre() ) { ... }
  1574   1574   */
  1575   1575   # define SQLITE_TCL_NRE 0
  1576   1576   # define DbUseNre() 0
  1577         -# define Tcl_NRAddCallback(a,b,c,d,e,f) 0
         1577  +# define Tcl_NRAddCallback(a,b,c,d,e,f) (void)0
  1578   1578   # define Tcl_NREvalObj(a,b,c) 0
  1579         -# define Tcl_NRCreateCommand(a,b,c,d,e,f) 0
         1579  +# define Tcl_NRCreateCommand(a,b,c,d,e,f) (void)0
  1580   1580   #endif
  1581   1581   
  1582   1582   /*
  1583   1583   ** This function is part of the implementation of the command:
  1584   1584   **
  1585   1585   **   $db eval SQL ?ARRAYNAME? SCRIPT
  1586   1586   */
................................................................................
  2851   2851       /* If using NRE, schedule a callback to invoke the script pScript, then
  2852   2852       ** a second callback to commit (or rollback) the transaction or savepoint
  2853   2853       ** opened above. If not using NRE, evaluate the script directly, then
  2854   2854       ** call function DbTransPostCmd() to commit (or rollback) the transaction 
  2855   2855       ** or savepoint.  */
  2856   2856       if( DbUseNre() ){
  2857   2857         Tcl_NRAddCallback(interp, DbTransPostCmd, cd, 0, 0, 0);
  2858         -      Tcl_NREvalObj(interp, pScript, 0);
         2858  +      (void)Tcl_NREvalObj(interp, pScript, 0);
  2859   2859       }else{
  2860   2860         rc = DbTransPostCmd(&cd, interp, Tcl_EvalObjEx(interp, pScript, 0));
  2861   2861       }
  2862   2862       break;
  2863   2863     }
  2864   2864   
  2865   2865     /*
................................................................................
  3513   3513           } else {
  3514   3514                   /* Pad block to 56 bytes */
  3515   3515                   memset(p, 0, count-8);
  3516   3516           }
  3517   3517           byteReverse(ctx->in, 14);
  3518   3518   
  3519   3519           /* Append length in bits and transform */
  3520         -        ((uint32 *)ctx->in)[ 14 ] = ctx->bits[0];
  3521         -        ((uint32 *)ctx->in)[ 15 ] = ctx->bits[1];
         3520  +        memcpy(ctx->in + 14*4, ctx->bits, 8);
  3522   3521   
  3523   3522           MD5Transform(ctx->buf, (uint32 *)ctx->in);
  3524   3523           byteReverse((unsigned char *)ctx->buf, 4);
  3525   3524           memcpy(digest, ctx->buf, 16);
  3526   3525   }
  3527   3526   
  3528   3527   /*

Changes to src/update.c.

    68     68       assert( i<pTab->nCol );
    69     69       sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc, 
    70     70                            pCol->affinity, &pValue);
    71     71       if( pValue ){
    72     72         sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM);
    73     73       }
    74     74   #ifndef SQLITE_OMIT_FLOATING_POINT
    75         -    if( iReg>=0 && pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
           75  +    if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
    76     76         sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
    77     77       }
    78     78   #endif
    79     79     }
    80     80   }
    81     81   
    82     82   /*
................................................................................
   492    492     ** the database after the BEFORE triggers are fired anyway (as the trigger 
   493    493     ** may have modified them). So not loading those that are not going to
   494    494     ** be used eliminates some redundant opcodes.
   495    495     */
   496    496     newmask = sqlite3TriggerColmask(
   497    497         pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError
   498    498     );
   499         -  sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1);
          499  +  /*sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1);*/
   500    500     for(i=0; i<pTab->nCol; i++){
   501    501       if( i==pTab->iPKey ){
   502         -      /*sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);*/
          502  +      sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);
   503    503       }else{
   504    504         j = aXRef[i];
   505    505         if( j>=0 ){
   506    506           sqlite3ExprCode(pParse, pChanges->a[j].pExpr, regNew+i);
   507    507         }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask&(1<<i)) ){
   508    508           /* This branch loads the value of a column that will not be changed 
   509    509           ** into a register. This is done if there are no BEFORE triggers, or
   510    510           ** if there are one or more BEFORE triggers that use this value via
   511    511           ** a new.* reference in a trigger program.
   512    512           */
   513    513           testcase( i==31 );
   514    514           testcase( i==32 );
   515    515           sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i);
          516  +      }else{
          517  +        sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);
   516    518         }
   517    519       }
   518    520     }
   519    521   
   520    522     /* Fire any BEFORE UPDATE triggers. This happens before constraints are
   521    523     ** verified. One could argue that this is wrong.
   522    524     */

Changes to src/vdbe.c.

  1117   1117       pIn1++;
  1118   1118       pOut++;
  1119   1119     }while( n-- );
  1120   1120     break;
  1121   1121   }
  1122   1122   
  1123   1123   /* Opcode: Copy P1 P2 P3 * *
  1124         -** Synopsis: r[P2@P3]=r[P1@P3]
         1124  +** Synopsis: r[P2@P3+1]=r[P1@P3+1]
  1125   1125   **
  1126   1126   ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
  1127   1127   **
  1128   1128   ** This instruction makes a deep copy of the value.  A duplicate
  1129   1129   ** is made of any string or blob constant.  See also OP_SCopy.
  1130   1130   */
  1131   1131   case OP_Copy: {
................................................................................
  2460   2460     assert( rc==SQLITE_OK );
  2461   2461     if( pC->szRow>=aOffset[p2+1] ){
  2462   2462       /* This is the common case where the desired content fits on the original
  2463   2463       ** page - where the content is not on an overflow page */
  2464   2464       VdbeMemRelease(pDest);
  2465   2465       sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
  2466   2466     }else{
  2467         -    /* This branch happens only when content is on overflow pages */	
         2467  +    /* This branch happens only when content is on overflow pages */
  2468   2468       t = aType[p2];
  2469   2469       if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
  2470   2470             && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
  2471   2471        || (len = sqlite3VdbeSerialTypeLen(t))==0
  2472   2472       ){
  2473   2473         /* Content is irrelevant for the typeof() function and for
  2474   2474         ** the length(X) function if X is a blob.  So we might as well use

Changes to src/vdbe.h.

   158    158   */
   159    159   #include "opcodes.h"
   160    160   
   161    161   /*
   162    162   ** Prototypes for the VDBE interface.  See comments on the implementation
   163    163   ** for a description of what each of these routines does.
   164    164   */
   165         -Vdbe *sqlite3VdbeCreate(sqlite3*);
          165  +Vdbe *sqlite3VdbeCreate(Parse*);
   166    166   int sqlite3VdbeAddOp0(Vdbe*,int);
   167    167   int sqlite3VdbeAddOp1(Vdbe*,int,int);
   168    168   int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
   169    169   int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
   170    170   int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
   171    171   int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
   172    172   int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);

Changes to src/vdbeInt.h.

   308    308   struct Vdbe {
   309    309     sqlite3 *db;            /* The database connection that owns this statement */
   310    310     Op *aOp;                /* Space to hold the virtual machine's program */
   311    311     Mem *aMem;              /* The memory locations */
   312    312     Mem **apArg;            /* Arguments to currently executing user function */
   313    313     Mem *aColName;          /* Column names to return */
   314    314     Mem *pResultSet;        /* Pointer to an array of results */
          315  +  Parse *pParse;          /* Parsing context used to create this Vdbe */
   315    316     int nMem;               /* Number of memory locations currently allocated */
   316    317     int nOp;                /* Number of instructions in the program */
   317         -  int nOpAlloc;           /* Number of slots allocated for aOp[] */
   318         -  int nLabel;             /* Number of labels used */
   319         -  int *aLabel;            /* Space to hold the labels */
   320         -  u16 nResColumn;         /* Number of columns in one row of the result set */
   321    318     int nCursor;            /* Number of slots in apCsr[] */
   322    319     u32 magic;              /* Magic number for sanity checking */
   323    320     char *zErrMsg;          /* Error message written here */
   324    321     Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
   325    322     VdbeCursor **apCsr;     /* One element of this array for each open cursor */
   326    323     Mem *aVar;              /* Values for the OP_Variable opcode. */
   327    324     char **azVar;           /* Name of variables */
   328    325     ynVar nVar;             /* Number of entries in aVar[] */
   329    326     ynVar nzVar;            /* Number of entries in azVar[] */
   330    327     u32 cacheCtr;           /* VdbeCursor row cache generation counter */
   331    328     int pc;                 /* The program counter */
   332    329     int rc;                 /* Value to return */
          330  +  u16 nResColumn;         /* Number of columns in one row of the result set */
   333    331     u8 errorAction;         /* Recovery action to do in case of an error */
   334    332     u8 minWriteFileFormat;  /* Minimum file format for writable database files */
   335    333     bft explain:2;          /* True if EXPLAIN present on SQL command */
   336    334     bft inVtabMethod:2;     /* See comments above */
   337    335     bft changeCntOn:1;      /* True to update the change-counter */
   338    336     bft expired:1;          /* True if the VM needs to be recompiled */
   339    337     bft runOnlyOnce:1;      /* Automatically expire on reset */

Changes to src/vdbeaux.c.

    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include "vdbeInt.h"
    19     19   
    20     20   /*
    21     21   ** Create a new virtual database engine.
    22     22   */
    23         -Vdbe *sqlite3VdbeCreate(sqlite3 *db){
           23  +Vdbe *sqlite3VdbeCreate(Parse *pParse){
           24  +  sqlite3 *db = pParse->db;
    24     25     Vdbe *p;
    25     26     p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
    26     27     if( p==0 ) return 0;
    27     28     p->db = db;
    28     29     if( db->pVdbe ){
    29     30       db->pVdbe->pPrev = p;
    30     31     }
    31     32     p->pNext = db->pVdbe;
    32     33     p->pPrev = 0;
    33     34     db->pVdbe = p;
    34     35     p->magic = VDBE_MAGIC_INIT;
           36  +  p->pParse = pParse;
           37  +  assert( pParse->aLabel==0 );
           38  +  assert( pParse->nLabel==0 );
           39  +  assert( pParse->nOpAlloc==0 );
    35     40     return p;
    36     41   }
    37     42   
    38     43   /*
    39     44   ** Remember the SQL string for a prepared statement.
    40     45   */
    41     46   void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, int isPrepareV2){
................................................................................
    84     89   ** it was.
    85     90   **
    86     91   ** If an out-of-memory error occurs while resizing the array, return
    87     92   ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain 
    88     93   ** unchanged (this is so that any opcodes already allocated can be 
    89     94   ** correctly deallocated along with the rest of the Vdbe).
    90     95   */
    91         -static int growOpArray(Vdbe *p){
           96  +static int growOpArray(Vdbe *v){
    92     97     VdbeOp *pNew;
           98  +  Parse *p = v->pParse;
    93     99     int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
    94         -  pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
          100  +  pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
    95    101     if( pNew ){
    96    102       p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
    97         -    p->aOp = pNew;
          103  +    v->aOp = pNew;
    98    104     }
    99    105     return (pNew ? SQLITE_OK : SQLITE_NOMEM);
   100    106   }
   101    107   
   102    108   #ifdef SQLITE_DEBUG
   103    109   /* This routine is just a convenient place to set a breakpoint that will
   104    110   ** fire after each opcode is inserted and displayed using
................................................................................
   129    135   int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
   130    136     int i;
   131    137     VdbeOp *pOp;
   132    138   
   133    139     i = p->nOp;
   134    140     assert( p->magic==VDBE_MAGIC_INIT );
   135    141     assert( op>0 && op<0xff );
   136         -  if( p->nOpAlloc<=i ){
          142  +  if( p->pParse->nOpAlloc<=i ){
   137    143       if( growOpArray(p) ){
   138    144         return 1;
   139    145       }
   140    146     }
   141    147     p->nOp++;
   142    148     pOp = &p->aOp[i];
   143    149     pOp->opcode = (u8)op;
................................................................................
   148    154     pOp->p4.p = 0;
   149    155     pOp->p4type = P4_NOTUSED;
   150    156   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
   151    157     pOp->zComment = 0;
   152    158   #endif
   153    159   #ifdef SQLITE_DEBUG
   154    160     if( p->db->flags & SQLITE_VdbeAddopTrace ){
          161  +    int jj, kk;
          162  +    Parse *pParse = p->pParse;
          163  +    for(jj=kk=0; jj<SQLITE_N_COLCACHE; jj++){
          164  +      struct yColCache *x = pParse->aColCache + jj;
          165  +      if( x->iLevel>pParse->iCacheLevel || x->iReg==0 ) continue;
          166  +      printf(" r[%d]={%d:%d}", x->iReg, x->iTable, x->iColumn);
          167  +      kk++;
          168  +    }
          169  +    if( kk ) printf("\n");
   155    170       sqlite3VdbePrintOp(0, i, &p->aOp[i]);
   156    171       test_addop_breakpoint();
   157    172     }
   158    173   #endif
   159    174   #ifdef VDBE_PROFILE
   160    175     pOp->cycles = 0;
   161    176     pOp->cnt = 0;
................................................................................
   231    246   **
   232    247   ** The VDBE knows that a P2 value is a label because labels are
   233    248   ** always negative and P2 values are suppose to be non-negative.
   234    249   ** Hence, a negative P2 value is a label that has yet to be resolved.
   235    250   **
   236    251   ** Zero is returned if a malloc() fails.
   237    252   */
   238         -int sqlite3VdbeMakeLabel(Vdbe *p){
          253  +int sqlite3VdbeMakeLabel(Vdbe *v){
          254  +  Parse *p = v->pParse;
   239    255     int i = p->nLabel++;
   240         -  assert( p->magic==VDBE_MAGIC_INIT );
          256  +  assert( v->magic==VDBE_MAGIC_INIT );
   241    257     if( (i & (i-1))==0 ){
   242    258       p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, 
   243    259                                          (i*2+1)*sizeof(p->aLabel[0]));
   244    260     }
   245    261     if( p->aLabel ){
   246    262       p->aLabel[i] = -1;
   247    263     }
................................................................................
   249    265   }
   250    266   
   251    267   /*
   252    268   ** Resolve label "x" to be the address of the next instruction to
   253    269   ** be inserted.  The parameter "x" must have been obtained from
   254    270   ** a prior call to sqlite3VdbeMakeLabel().
   255    271   */
   256         -void sqlite3VdbeResolveLabel(Vdbe *p, int x){
          272  +void sqlite3VdbeResolveLabel(Vdbe *v, int x){
          273  +  Parse *p = v->pParse;
   257    274     int j = -1-x;
   258         -  assert( p->magic==VDBE_MAGIC_INIT );
          275  +  assert( v->magic==VDBE_MAGIC_INIT );
   259    276     assert( j<p->nLabel );
   260    277     if( j>=0 && p->aLabel ){
   261         -    p->aLabel[j] = p->nOp;
          278  +    p->aLabel[j] = v->nOp;
   262    279     }
   263    280   }
   264    281   
   265    282   /*
   266    283   ** Mark the VDBE as one that can only be run one time.
   267    284   */
   268    285   void sqlite3VdbeRunOnlyOnce(Vdbe *p){
................................................................................
   403    420   **
   404    421   ** The Op.opflags field is set on all opcodes.
   405    422   */
   406    423   static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
   407    424     int i;
   408    425     int nMaxArgs = *pMaxFuncArgs;
   409    426     Op *pOp;
   410         -  int *aLabel = p->aLabel;
          427  +  Parse *pParse = p->pParse;
          428  +  int *aLabel = pParse->aLabel;
   411    429     p->readOnly = 1;
   412    430     p->bIsReader = 0;
   413    431     for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
   414    432       u8 opcode = pOp->opcode;
   415    433   
   416    434       /* NOTE: Be sure to update mkopcodeh.awk when adding or removing
   417    435       ** cases from this switch! */
................................................................................
   466    484           pOp->p4type = P4_ADVANCE;
   467    485           break;
   468    486         }
   469    487       }
   470    488   
   471    489       pOp->opflags = sqlite3OpcodeProperty[opcode];
   472    490       if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
   473         -      assert( -1-pOp->p2<p->nLabel );
          491  +      assert( -1-pOp->p2<pParse->nLabel );
   474    492         pOp->p2 = aLabel[-1-pOp->p2];
   475    493       }
   476    494     }
   477         -  sqlite3DbFree(p->db, p->aLabel);
   478         -  p->aLabel = 0;
          495  +  sqlite3DbFree(p->db, pParse->aLabel);
          496  +  pParse->aLabel = 0;
          497  +  pParse->nLabel = 0;
   479    498     *pMaxFuncArgs = nMaxArgs;
   480    499     assert( p->bIsReader!=0 || p->btreeMask==0 );
   481    500   }
   482    501   
   483    502   /*
   484    503   ** Return the address of the next instruction to be inserted.
   485    504   */
................................................................................
   515    534   /*
   516    535   ** Add a whole list of operations to the operation stack.  Return the
   517    536   ** address of the first operation added.
   518    537   */
   519    538   int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
   520    539     int addr;
   521    540     assert( p->magic==VDBE_MAGIC_INIT );
   522         -  if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){
          541  +  if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
   523    542       return 0;
   524    543     }
   525    544     addr = p->nOp;
   526    545     if( ALWAYS(nOp>0) ){
   527    546       int i;
   528    547       VdbeOpList const *pIn = aOp;
   529    548       for(i=0; i<nOp; i++, pIn++){
................................................................................
   869    888     if( c=='2' ) return pOp->p2;
   870    889     if( c=='3' ) return pOp->p3;
   871    890     if( c=='4' ) return pOp->p4.i;
   872    891     return pOp->p5;
   873    892   }
   874    893   
   875    894   /*
   876         -** Compute a string for the "comment" field of a VDBE opcode listing
          895  +** Compute a string for the "comment" field of a VDBE opcode listing.
          896  +**
          897  +** The Synopsis: field in comments in the vdbe.c source file gets converted
          898  +** to an extra string that is appended to the sqlite3OpcodeName().  In the
          899  +** absence of other comments, this synopsis becomes the comment on the opcode.
          900  +** Some translation occurs:
          901  +**
          902  +**       "PX"      ->  "r[X]"
          903  +**       "PX@PY"   ->  "r[X..X+Y-1]"  or "r[x]" if y is 0 or 1
          904  +**       "PX@PY+1" ->  "r[X..X+Y]"    or "r[x]" if y is 0
          905  +**       "PY..PY"  ->  "r[X..Y]"      or "r[x]" if y<=x
   877    906   */
   878    907   static int displayComment(
   879    908     const Op *pOp,     /* The opcode to be commented */
   880    909     const char *zP4,   /* Previously obtained value for P4 */
   881    910     char *zTemp,       /* Write result here */
   882    911     int nTemp          /* Space available in zTemp[] */
   883    912   ){
................................................................................
   903    932             int v1 = translateP(c, pOp);
   904    933             int v2;
   905    934             sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1);
   906    935             if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
   907    936               ii += 3;
   908    937               jj += sqlite3Strlen30(zTemp+jj);
   909    938               v2 = translateP(zSynopsis[ii], pOp);
   910         -            if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
          939  +            if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){
          940  +              ii += 2;
          941  +              v2++;
          942  +            }
          943  +            if( v2>1 ){
          944  +              sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
          945  +            }
   911    946             }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
   912    947               ii += 4;
   913    948             }
   914    949           }
   915    950           jj += sqlite3Strlen30(zTemp+jj);
   916    951         }else{
   917    952           zTemp[jj++] = c;
................................................................................
  1135   1170     if( pOut==0 ) pOut = stdout;
  1136   1171     zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
  1137   1172   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
  1138   1173     displayComment(pOp, zP4, zCom, sizeof(zCom));
  1139   1174   #else
  1140   1175     zCom[0] = 0
  1141   1176   #endif
         1177  +  /* NB:  The sqlite3OpcodeName() function is implemented by code created
         1178  +  ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
         1179  +  ** information from the vdbe.c source text */
  1142   1180     fprintf(pOut, zFormat1, pc, 
  1143   1181         sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5,
  1144   1182         zCom
  1145   1183     );
  1146   1184     fflush(pOut);
  1147   1185   }
  1148   1186   #endif
................................................................................
  1566   1604     u8 *zEnd;                      /* First byte past allocated memory */
  1567   1605     int nByte;                     /* How much extra memory is needed */
  1568   1606   
  1569   1607     assert( p!=0 );
  1570   1608     assert( p->nOp>0 );
  1571   1609     assert( pParse!=0 );
  1572   1610     assert( p->magic==VDBE_MAGIC_INIT );
         1611  +  assert( pParse==p->pParse );
  1573   1612     db = p->db;
  1574   1613     assert( db->mallocFailed==0 );
  1575   1614     nVar = pParse->nVar;
  1576   1615     nMem = pParse->nMem;
  1577   1616     nCursor = pParse->nTab;
  1578   1617     nArg = pParse->nMaxArg;
  1579   1618     nOnce = pParse->nOnce;
................................................................................
  1589   1628     ** See also: allocateCursor().
  1590   1629     */
  1591   1630     nMem += nCursor;
  1592   1631   
  1593   1632     /* Allocate space for memory registers, SQL variables, VDBE cursors and 
  1594   1633     ** an array to marshal SQL function arguments in.
  1595   1634     */
  1596         -  zCsr = (u8*)&p->aOp[p->nOp];       /* Memory avaliable for allocation */
  1597         -  zEnd = (u8*)&p->aOp[p->nOpAlloc];  /* First byte past end of zCsr[] */
         1635  +  zCsr = (u8*)&p->aOp[p->nOp];            /* Memory avaliable for allocation */
         1636  +  zEnd = (u8*)&p->aOp[pParse->nOpAlloc];  /* First byte past end of zCsr[] */
  1598   1637   
  1599   1638     resolveP2Values(p, &nArg);
  1600   1639     p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
  1601   1640     if( pParse->explain && nMem<10 ){
  1602   1641       nMem = 10;
  1603   1642     }
  1604   1643     memset(zCsr, 0, zEnd-zCsr);
................................................................................
  2593   2632     for(pSub=p->pProgram; pSub; pSub=pNext){
  2594   2633       pNext = pSub->pNext;
  2595   2634       vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
  2596   2635       sqlite3DbFree(db, pSub);
  2597   2636     }
  2598   2637     for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
  2599   2638     vdbeFreeOpArray(db, p->aOp, p->nOp);
  2600         -  sqlite3DbFree(db, p->aLabel);
  2601   2639     sqlite3DbFree(db, p->aColName);
  2602   2640     sqlite3DbFree(db, p->zSql);
  2603   2641     sqlite3DbFree(db, p->pFree);
  2604   2642   #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
  2605   2643     sqlite3DbFree(db, p->zExplain);
  2606   2644     sqlite3DbFree(db, p->pExplain);
  2607   2645   #endif

Changes to src/vdbeblob.c.

   255    255           zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
   256    256           rc = SQLITE_ERROR;
   257    257           sqlite3BtreeLeaveAll(db);
   258    258           goto blob_open_out;
   259    259         }
   260    260       }
   261    261   
   262         -    pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db);
          262  +    pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse);
   263    263       assert( pBlob->pStmt || db->mallocFailed );
   264    264       if( pBlob->pStmt ){
   265    265         Vdbe *v = (Vdbe *)pBlob->pStmt;
   266    266         int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   267    267   
   268    268         sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob);
   269    269   

Changes to src/vdbetrace.c.

   121    121         zRawSql += nToken;
   122    122         nextIndex = idx + 1;
   123    123         assert( idx>0 && idx<=p->nVar );
   124    124         pVar = &p->aVar[idx-1];
   125    125         if( pVar->flags & MEM_Null ){
   126    126           sqlite3StrAccumAppend(&out, "NULL", 4);
   127    127         }else if( pVar->flags & MEM_Int ){
   128         -        sqlite3XPrintf(&out, "%lld", pVar->u.i);
          128  +        sqlite3XPrintf(&out, 0, "%lld", pVar->u.i);
   129    129         }else if( pVar->flags & MEM_Real ){
   130         -        sqlite3XPrintf(&out, "%!.15g", pVar->r);
          130  +        sqlite3XPrintf(&out, 0, "%!.15g", pVar->r);
   131    131         }else if( pVar->flags & MEM_Str ){
   132    132           int nOut;  /* Number of bytes of the string text to include in output */
   133    133   #ifndef SQLITE_OMIT_UTF16
   134    134           u8 enc = ENC(db);
   135    135           Mem utf8;
   136    136           if( enc!=SQLITE_UTF8 ){
   137    137             memset(&utf8, 0, sizeof(utf8));
................................................................................
   144    144           nOut = pVar->n;
   145    145   #ifdef SQLITE_TRACE_SIZE_LIMIT
   146    146           if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
   147    147             nOut = SQLITE_TRACE_SIZE_LIMIT;
   148    148             while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
   149    149           }
   150    150   #endif    
   151         -        sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z);
          151  +        sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z);
   152    152   #ifdef SQLITE_TRACE_SIZE_LIMIT
   153         -        if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
          153  +        if( nOut<pVar->n ){
          154  +          sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
          155  +        }
   154    156   #endif
   155    157   #ifndef SQLITE_OMIT_UTF16
   156    158           if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
   157    159   #endif
   158    160         }else if( pVar->flags & MEM_Zero ){
   159         -        sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
          161  +        sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero);
   160    162         }else{
   161    163           int nOut;  /* Number of bytes of the blob to include in output */
   162    164           assert( pVar->flags & MEM_Blob );
   163    165           sqlite3StrAccumAppend(&out, "x'", 2);
   164    166           nOut = pVar->n;
   165    167   #ifdef SQLITE_TRACE_SIZE_LIMIT
   166    168           if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
   167    169   #endif
   168    170           for(i=0; i<nOut; i++){
   169         -          sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
          171  +          sqlite3XPrintf(&out, 0, "%02x", pVar->z[i]&0xff);
   170    172           }
   171    173           sqlite3StrAccumAppend(&out, "'", 1);
   172    174   #ifdef SQLITE_TRACE_SIZE_LIMIT
   173         -        if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
          175  +        if( nOut<pVar->n ){
          176  +          sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
          177  +        }
   174    178   #endif
   175    179         }
   176    180       }
   177    181     }
   178    182     return sqlite3StrAccumFinish(&out);
   179    183   }
   180    184   
................................................................................
   225    229       va_list ap;
   226    230       if( p->nIndent && endsWithNL(p) ){
   227    231         int n = p->nIndent;
   228    232         if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
   229    233         sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
   230    234       }   
   231    235       va_start(ap, zFormat);
   232         -    sqlite3VXPrintf(&p->str, 1, zFormat, ap);
          236  +    sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap);
   233    237       va_end(ap);
   234    238     }
   235    239   }
   236    240   
   237    241   /*
   238    242   ** Append a '\n' if there is not already one.
   239    243   */

Changes to src/where.c.

  3924   3924     ** number 18 was found by experimentation to be the payoff point where
  3925   3925     ** skip-scan become faster than a full-scan.
  3926   3926     */
  3927   3927     if( pTerm==0
  3928   3928      && saved_nEq==saved_nSkip
  3929   3929      && saved_nEq+1<pProbe->nKeyCol
  3930   3930      && pProbe->aiRowEst[saved_nEq+1]>=18  /* TUNING: Minimum for skip-scan */
         3931  +   && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
  3931   3932     ){
  3932   3933       LogEst nIter;
  3933   3934       pNew->u.btree.nEq++;
  3934   3935       pNew->u.btree.nSkip++;
  3935   3936       pNew->aLTerm[pNew->nLTerm++] = 0;
  3936   3937       pNew->wsFlags |= WHERE_SKIPSCAN;
  3937   3938       nIter = sqlite3LogEst(pProbe->aiRowEst[0]/pProbe->aiRowEst[saved_nEq+1]);

Changes to test/attach3.test.

   318    318   do_test attach3-12.9 {
   319    319     execsql {
   320    320       ATTACH DATABASE '' AS NULL
   321    321     }
   322    322     db_list
   323    323   } {main temp {}}
   324    324   do_test attach3-12.10 {
   325         -breakpoint
   326    325     execsql {
   327    326       DETACH ?
   328    327     }
   329    328     db_list
   330    329   } {main temp}
   331    330   do_test attach3-12.11 {
   332    331     catchsql {

Changes to test/capi3.test.

  1187   1187     db2 close
  1188   1188     sqlite3_step $STMT
  1189   1189   } {SQLITE_ERROR}
  1190   1190   do_test capi3-18.2 {
  1191   1191     sqlite3_reset $STMT
  1192   1192     sqlite3_errcode db
  1193   1193   } {SQLITE_SCHEMA}
  1194         -breakpoint
  1195   1194   do_test capi3-18.3 {
  1196   1195     sqlite3_errmsg db
  1197   1196   } {database schema has changed}
  1198   1197   # The error persist on retry when sqlite3_prepare() has been used.
  1199   1198   do_test capi3-18.4 {
  1200   1199     sqlite3_step $STMT
  1201   1200   } {SQLITE_ERROR}

Changes to test/collate1.test.

    71     71   } {}
    72     72   do_test collate1-1.1 {
    73     73     execsql {
    74     74       SELECT c2 FROM collate1t1 ORDER BY 1;
    75     75     }
    76     76   } {{} 0x119 0x2D}
    77     77   do_test collate1-1.2 {
    78         -breakpoint
    79     78     execsql {
    80     79       SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex;
    81     80     }
    82     81   } {{} 0x2D 0x119}
    83     82   do_test collate1-1.3 {
    84     83     execsql {
    85     84       SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex DESC;

Changes to test/exclusive2.test.

   297    297     execsql {
   298    298       PRAGMA locking_mode = exclusive;
   299    299       INSERT INTO t1 VALUES(randstr(200, 200));
   300    300     }
   301    301     readPagerChangeCounter test.db
   302    302   } {4}
   303    303   do_test exclusive2-3.4 {
   304         -breakpoint
   305    304     execsql {
   306    305       INSERT INTO t1 VALUES(randstr(200, 200));
   307    306     }
   308    307     readPagerChangeCounter test.db
   309    308   } {4}
   310    309   do_test exclusive2-3.5 {
   311    310     execsql {

Changes to test/fts3aa.test.

   142    142   do_test fts3aa-3.2 {
   143    143     execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
   144    144   } {1 5 9 13 17 21 25 29}
   145    145   do_test fts3aa-3.3 {
   146    146     execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
   147    147   } {1 5 9 13 17 21 25 29}
   148    148   
   149         -breakpoint
   150    149   do_test fts3aa-4.1 {
   151    150     execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'}
   152    151   } {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31}
   153    152   do_test fts3aa-4.2 {
   154    153     execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'}
   155    154   } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
   156    155   do_test fts3aa-4.3 {

Changes to test/fts3ab.test.

   111    111      CREATE VIRTUAL TABLE t4 USING fts3([norm],'plusone',"invert");
   112    112   }
   113    113   for {set i 1} {$i<=15} {incr i} {
   114    114     set vset [list [wordset $i] [wordset [expr {$i+1}]] [wordset [expr {~$i}]]]
   115    115     db eval "INSERT INTO t4(norm,plusone,invert) VALUES([join $vset ,]);"
   116    116   }
   117    117   
   118         -breakpoint
   119    118   do_test fts3ab-4.1 {
   120    119     execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one'}
   121    120   } {1 3 5 7 9 11 13 15}
   122    121   do_test fts3ab-4.2 {
   123    122     execsql {SELECT rowid FROM t4 WHERE norm MATCH 'one'}
   124    123   } {1 3 5 7 9 11 13 15}
   125    124   do_test fts3ab-4.3 {

Changes to test/fts3ag.test.

    74     74   do_test fts3ag-1.10 {
    75     75     catchsql {SELECT rowid FROM t1 WHERE t1 MATCH '-this -something'}
    76     76   } {1 {malformed MATCH expression: [-this -something]}}
    77     77   
    78     78   # Test that docListOrMerge() correctly handles reaching the end of one
    79     79   # doclist before it reaches the end of the other.
    80     80   do_test fts3ag-1.11 {
    81         -breakpoint
    82     81     execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this OR also'}
    83     82   } {1 2}
    84     83   do_test fts3ag-1.12 {
    85     84     execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'also OR this'}
    86     85   } {1 2}
    87     86   
    88     87   # Empty left and right in docListOrMerge().  Each term matches neither
    89     88   # row, and when combined there was an assertion failure.
    90     89   do_test fts3ag-1.13 {
    91     90     execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something OR nothing'}
    92     91   } {}
    93     92   
    94     93   finish_test

Changes to test/fts3d.test.

   249    249   check_doclist fts3d-4.4.7  1 0 this {[1 0[0]] [3 0[0]]}
   250    250   check_doclist fts3d-4.4.8  1 0 three {[1] [2] [3]}
   251    251   check_doclist fts3d-4.4.9  1 0 two {[1] [2] [3]}
   252    252   check_doclist fts3d-4.4.10 1 0 was {[2 0[1]]}
   253    253   
   254    254   # Optimize should leave the result in the level of the highest-level
   255    255   # prior segment.
   256         -breakpoint
   257    256   do_test fts3d-4.5 {
   258    257     execsql {
   259    258       SELECT OPTIMIZE(t1) FROM t1 LIMIT 1;
   260    259       SELECT level, idx FROM t1_segdir ORDER BY level, idx;
   261    260     }
   262    261   } {{Index optimized} 1 0}
   263    262   

Changes to test/fts3near.test.

   161    161     execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'two NEAR/2 three'}
   162    162   } {{0 0 4 3 0 1 8 5 0 0 14 3 0 1 27 5}}
   163    163   do_test fts3near-3.6 {
   164    164     execsql {
   165    165       SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/0 "two four"'
   166    166     }
   167    167   } {{0 0 8 5 0 1 14 3 0 2 18 4}}
   168         -breakpoint
   169    168   do_test fts3near-3.7 {
   170    169     execsql {
   171    170       SELECT offsets(t1) FROM t1 WHERE content MATCH '"two four" NEAR/0 three'}
   172    171   } {{0 2 8 5 0 0 14 3 0 1 18 4}}
   173    172   
   174    173   db eval {
   175    174     INSERT INTO t1(content) VALUES('

Changes to test/fts3tok1.test.

    86     86   }
    87     87   
    88     88   do_execsql_test 1.13.1 {
    89     89     CREATE TABLE c1(x);
    90     90     INSERT INTO c1(x) VALUES('a b c');
    91     91     INSERT INTO c1(x) VALUES('d e f');
    92     92   }
    93         -breakpoint
    94     93   do_execsql_test 1.13.2 {
    95     94     SELECT * FROM c1, t1 WHERE input = x AND c1.rowid=t1.rowid;
    96     95   } {
    97     96     {a b c} {a b c} a 0 1 0 
    98     97     {d e f} {d e f} e 2 3 1 
    99     98   }
   100     99   

Changes to test/fts4unicode.test.

   388    388     do_isspace_test 6.$T.22 $T   {8200 8201 8202 8239}
   389    389     do_isspace_test 6.$T.23 $T   {8287 12288}
   390    390   }
   391    391   
   392    392   #-------------------------------------------------------------------------
   393    393   # Test that the private use ranges are treated as alphanumeric.
   394    394   #
   395         -breakpoint
   396    395   foreach {tn1 c} {
   397    396     1 \ue000 2 \ue001 3 \uf000 4 \uf8fe 5 \uf8ff
   398    397   } {
   399    398     foreach {tn2 config res} {
   400    399       1 ""             "0 hello*world hello*world"
   401    400       2 "separators=*" "0 hello hello 1 world world"
   402    401     } {
................................................................................
   553    552     );
   554    553     SELECT token FROM ft1 WHERE input = 'berlin@street123sydney.road';
   555    554   } {
   556    555     berlin@street sydney.road
   557    556   }
   558    557   
   559    558   finish_test
   560         -
   561         -
   562         -
   563         -

Changes to test/mmapfault.test.

    37     37     faultsim_save_and_close
    38     38   } {}
    39     39   
    40     40   
    41     41   do_faultsim_test 1 -prep {
    42     42     faultsim_restore_and_reopen
    43     43     db func a_string a_string
    44         -  breakpoint
    45     44     execsql {
    46     45       PRAGMA mmap_size = 1000000;
    47     46       PRAGMA cache_size = 5;
    48     47       BEGIN;
    49     48         INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
    50     49         INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
    51     50         INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;

Added test/printf2.test.

            1  +# 2013-12-17
            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 printf() SQL function.
           13  +#
           14  +#
           15  +# EVIDENCE-OF: R-63057-40065 The printf(FORMAT,...) SQL function works
           16  +# like the sqlite3_mprintf() C-language function and the printf()
           17  +# function from the standard C library.
           18  +#
           19  +
           20  +set testdir [file dirname $argv0]
           21  +source $testdir/tester.tcl
           22  +
           23  +# EVIDENCE-OF: R-40086-60101 If the FORMAT argument is missing or NULL
           24  +# then the result is NULL.
           25  +#
           26  +do_execsql_test printf2-1.1 {
           27  +  SELECT quote(printf()), quote(printf(NULL,1,2,3));
           28  +} {NULL NULL}
           29  +
           30  +
           31  +do_execsql_test printf2-1.2 {
           32  +  SELECT printf('hello');
           33  +} {hello}
           34  +do_execsql_test printf2-1.3 {
           35  +  SELECT printf('%d,%d,%d',55,-11,3421);
           36  +} {55,-11,3421}
           37  +do_execsql_test printf2-1.4 {
           38  +  SELECT printf('%d,%d,%d',55,'-11',3421);
           39  +} {55,-11,3421}
           40  +do_execsql_test printf2-1.5 {
           41  +  SELECT printf('%d,%d,%d,%d',55,'-11',3421);
           42  +} {55,-11,3421,0}
           43  +do_execsql_test printf2-1.6 {
           44  +  SELECT printf('%.2f',3.141592653);
           45  +} {3.14}
           46  +do_execsql_test printf2-1.7 {
           47  +  SELECT printf('%.*f',2,3.141592653);
           48  +} {3.14}
           49  +do_execsql_test printf2-1.8 {
           50  +  SELECT printf('%*.*f',5,2,3.141592653);
           51  +} {{ 3.14}}
           52  +do_execsql_test printf2-1.9 {
           53  +  SELECT printf('%d',314159.2653);
           54  +} {314159}
           55  +do_execsql_test printf2-1.10 {
           56  +  SELECT printf('%lld',314159.2653);
           57  +} {314159}
           58  +do_execsql_test printf2-1.11 {
           59  +  SELECT printf('%lld%n',314159.2653,'hi');
           60  +} {314159}
           61  +
           62  +# EVIDENCE-OF: R-20555-31089 The %z format is interchangable with %s.
           63  +#
           64  +do_execsql_test printf2-1.12 {
           65  +  SELECT printf('%.*z',5,'abcdefghijklmnop');
           66  +} {abcde}
           67  +do_execsql_test printf2-1.13 {
           68  +  SELECT printf('%c','abcdefghijklmnop');
           69  +} {a}
           70  +
           71  +# EVIDENCE-OF: R-02347-27622 The %n format is silently ignored and does
           72  +# not consume an argument.
           73  +#
           74  +do_execsql_test printf2-2.1 {
           75  +  CREATE TABLE t1(a,b,c);
           76  +  INSERT INTO t1 VALUES(1,2,3);
           77  +  INSERT INTO t1 VALUES(-1,-2,-3);
           78  +  INSERT INTO t1 VALUES('abc','def','ghi');
           79  +  INSERT INTO t1 VALUES(1.5,2.25,3.125);
           80  +  SELECT printf('(%s)-%n-(%s)',a,b,c) FROM t1 ORDER BY rowid;
           81  +} {(1)--(2) (-1)--(-2) (abc)--(def) (1.5)--(2.25)}
           82  +
           83  +# EVIDENCE-OF: R-56064-04001 The %p format is an alias for %X.
           84  +#
           85  +do_execsql_test printf2-2.2 {
           86  +  SELECT printf('%s=(%p)',a,a) FROM t1 ORDER BY a;
           87  +} {-1=(FFFFFFFFFFFFFFFF) 1=(1) 1.5=(1) abc=(0)}
           88  +
           89  +# EVIDENCE-OF: R-29410-53018 If there are too few arguments in the
           90  +# argument list, missing arguments are assumed to have a NULL value,
           91  +# which is translated into 0 or 0.0 for numeric formats or an empty
           92  +# string for %s.
           93  +#
           94  +do_execsql_test printf2-2.3 {
           95  +  SELECT printf('%s=(%d/%g/%s)',a) FROM t1 ORDER BY a;
           96  +} {-1=(0/0/) 1=(0/0/) 1.5=(0/0/) abc=(0/0/)}
           97  +
           98  +
           99  +finish_test

Changes to test/securedel.test.

    43     43   do_test securedel-1.3 {
    44     44     db eval {
    45     45       PRAGMA secure_delete=OFF;
    46     46       PRAGMA db2.secure_delete;
    47     47     }
    48     48   } {0 0}
    49     49   do_test securedel-1.4 {
    50         -breakpoint
    51     50     db eval {
    52     51       PRAGMA secure_delete=ON;
    53     52       PRAGMA db2.secure_delete;
    54     53     }
    55     54   } {1 1}
    56     55   
    57     56   do_test securedel-2.1 {

Changes to test/shell2.test.

   151    151   INSERT INTO foo1(a) VALUES(2);
   152    152   INSERT INTO foo2(b) VALUES(2);
   153    153   SELECT * FROM foo1;
   154    154   1
   155    155   2
   156    156   SELECT * FROM foo2;
   157    157   1
   158         -2}}
          158  +2
          159  +}}
   159    160   
   160    161   # Test with echo on and headers on using dot command and 
   161    162   # multiple commands per line.
   162    163   # NB. whitespace is important
   163    164   do_test shell2-1.4.6 {
   164    165     forcedelete foo.db
   165    166     catchcmd "foo.db" {.echo ON
................................................................................
   188    189   SELECT * FROM foo1;
   189    190   a
   190    191   1
   191    192   2
   192    193   SELECT * FROM foo2;
   193    194   b
   194    195   1
   195         -2}}
          196  +2
          197  +}}
   196    198   
   197    199   finish_test

Changes to test/skipscan1.test.

   182    182     EXPLAIN QUERY PLAN
   183    183     SELECT a,b,c,d,'|' FROM t3 WHERE b=345 ORDER BY a;
   184    184   } {/* INDEX sqlite_autoindex_t3_1 (ANY(a) AND b=?)*/}
   185    185   do_execsql_test skipscan1-3.2sort {
   186    186     EXPLAIN QUERY PLAN
   187    187     SELECT a,b,c,d,'|' FROM t3 WHERE b=345 ORDER BY a;
   188    188   } {~/*ORDER BY*/}
          189  +
          190  +# Ticket 520070ec7fbaac: Array overrun in the skip-scan optimization
          191  +# 2013-12-22
          192  +#
          193  +do_execsql_test skipscan1-4.1 {
          194  +  CREATE TABLE t4(a,b,c,d,e,f,g,h,i);
          195  +  CREATE INDEX t4all ON t4(a,b,c,d,e,f,g,h);
          196  +  INSERT INTO t4 VALUES(1,2,3,4,5,6,7,8,9);
          197  +  ANALYZE;
          198  +  DELETE FROM sqlite_stat1;
          199  +  INSERT INTO sqlite_stat1 
          200  +    VALUES('t4','t4all','655360 163840 40960 10240 2560 640 160 40 10');
          201  +  ANALYZE sqlite_master;
          202  +  SELECT i FROM t4 WHERE a=1;
          203  +  SELECT i FROM t4 WHERE b=2;
          204  +  SELECT i FROM t4 WHERE c=3;
          205  +  SELECT i FROM t4 WHERE d=4;
          206  +  SELECT i FROM t4 WHERE e=5;
          207  +  SELECT i FROM t4 WHERE f=6;
          208  +  SELECT i FROM t4 WHERE g=7;
          209  +  SELECT i FROM t4 WHERE h=8;
          210  +} {9 9 9 9 9 9 9 9}
   189    211   
   190    212   finish_test

Changes to test/speedtest1.c.

     5      5   */
     6      6   static const char zHelp[] =
     7      7     "Usage: %s [--options] DATABASE\n"
     8      8     "Options:\n"
     9      9     "  --autovacuum        Enable AUTOVACUUM mode\n"
    10     10     "  --cachesize N       Set the cache size to N\n" 
    11     11     "  --exclusive         Enable locking_mode=EXCLUSIVE\n"
           12  +  "  --explain           Like --sqlonly but with added EXPLAIN keywords\n"
    12     13     "  --heap SZ MIN       Memory allocator uses SZ bytes & min allocation MIN\n"
    13     14     "  --incrvacuum        Enable incremenatal vacuum mode\n"
    14     15     "  --journalmode M     Set the journal_mode to MODE\n"
    15     16     "  --key KEY           Set the encryption key to KEY\n"
    16     17     "  --lookaside N SZ    Configure lookaside for N slots of SZ bytes each\n"
    17     18     "  --nosync            Set PRAGMA synchronous=OFF\n"
    18     19     "  --notnull           Add NOT NULL constraints to table columns\n"
................................................................................
    45     46     sqlite3 *db;               /* The open database connection */
    46     47     sqlite3_stmt *pStmt;       /* Current SQL statement */
    47     48     sqlite3_int64 iStart;      /* Start-time for the current test */
    48     49     sqlite3_int64 iTotal;      /* Total time */
    49     50     int bWithoutRowid;         /* True for --without-rowid */
    50     51     int bReprepare;            /* True to reprepare the SQL on each rerun */
    51     52     int bSqlOnly;              /* True to print the SQL once only */
           53  +  int bExplain;              /* Print SQL with EXPLAIN prefix */
    52     54     int szTest;                /* Scale factor for test iterations */
    53     55     const char *zWR;           /* Might be WITHOUT ROWID */
    54     56     const char *zNN;           /* Might be NOT NULL */
    55     57     const char *zPK;           /* Might be UNIQUE or PRIMARY KEY */
    56     58     unsigned int x, y;         /* Pseudo-random number generator state */
    57     59     int nResult;               /* Size of the current result */
    58     60     char zResult[3000];        /* Text of the current result */
................................................................................
   285    287   /* Report end of testing */
   286    288   void speedtest1_final(void){
   287    289     if( !g.bSqlOnly ){
   288    290       printf("       TOTAL%.*s %4d.%03ds\n", NAMEWIDTH-5, zDots,
   289    291              (int)(g.iTotal/1000), (int)(g.iTotal%1000));
   290    292     }
   291    293   }
          294  +
          295  +/* Print an SQL statement to standard output */
          296  +static void printSql(const char *zSql){
          297  +  int n = (int)strlen(zSql);
          298  +  while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
          299  +  if( g.bExplain ) printf("EXPLAIN ");
          300  +  printf("%.*s;\n", n, zSql);
          301  +  if( g.bExplain
          302  +#if SQLITE_VERSION_NUMBER>=3007010 
          303  +   && ( sqlite3_strglob("CREATE *", zSql)==0
          304  +     || sqlite3_strglob("DROP *", zSql)==0
          305  +     || sqlite3_strglob("ALTER *", zSql)==0
          306  +      )
          307  +#endif
          308  +  ){
          309  +    printf("%.*s;\n", n, zSql);
          310  +  }
          311  +}
   292    312   
   293    313   /* Run SQL */
   294    314   void speedtest1_exec(const char *zFormat, ...){
   295    315     va_list ap;
   296    316     char *zSql;
   297    317     va_start(ap, zFormat);
   298    318     zSql = sqlite3_vmprintf(zFormat, ap);
   299    319     va_end(ap);
   300    320     if( g.bSqlOnly ){
   301         -    int n = (int)strlen(zSql);
   302         -    while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
   303         -    printf("%.*s;\n", n, zSql);
          321  +    printSql(zSql);
   304    322     }else{
   305    323       char *zErrMsg = 0;
   306    324       int rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
   307    325       if( zErrMsg ) fatal_error("SQL error: %s\n%s\n", zErrMsg, zSql);
   308    326       if( rc!=SQLITE_OK ) fatal_error("exec error: %s\n", sqlite3_errmsg(g.db));
   309    327     }
   310    328     sqlite3_free(zSql);
................................................................................
   314    332   void speedtest1_prepare(const char *zFormat, ...){
   315    333     va_list ap;
   316    334     char *zSql;
   317    335     va_start(ap, zFormat);
   318    336     zSql = sqlite3_vmprintf(zFormat, ap);
   319    337     va_end(ap);
   320    338     if( g.bSqlOnly ){
   321         -    int n = (int)strlen(zSql);
   322         -    while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
   323         -    printf("%.*s;\n", n, zSql);
          339  +    printSql(zSql);
   324    340     }else{
   325    341       int rc;
   326    342       if( g.pStmt ) sqlite3_finalize(g.pStmt);
   327    343       rc = sqlite3_prepare_v2(g.db, zSql, -1, &g.pStmt, 0);
   328    344       if( rc ){
   329    345         fatal_error("SQL error: %s\n", sqlite3_errmsg(g.db));
   330    346       }
................................................................................
   373    389   static void randomFunc(
   374    390     sqlite3_context *context,
   375    391     int NotUsed,
   376    392     sqlite3_value **NotUsed2
   377    393   ){
   378    394     sqlite3_result_int64(context, (sqlite3_int64)speedtest1_random());
   379    395   }
          396  +
          397  +/* Estimate the square root of an integer */
          398  +static int est_square_root(int x){
          399  +  int y0 = x/2;
          400  +  int y1;
          401  +  int n;
          402  +  for(n=0; y0>0 && n<10; n++){
          403  +    y1 = (y0 + x/y0)/2;
          404  +    if( y1==y0 ) break;
          405  +    y0 = y1;
          406  +  }
          407  +  return y0;
          408  +}
   380    409   
   381    410   /*
   382    411   ** The main and default testset
   383    412   */
   384    413   void testset_main(void){
   385    414     int i;                        /* Loop counter */
   386    415     int n;                        /* iteration count */
................................................................................
   480    509       speedtest1_run();
   481    510     }
   482    511     speedtest1_exec("COMMIT");
   483    512     speedtest1_end_test();
   484    513   
   485    514   
   486    515     speedtest1_begin_test(150, "CREATE INDEX five times");
   487         -  speedtest1_exec(
   488         -      "BEGIN;\n"
   489         -      "CREATE UNIQUE INDEX t1b ON t1(b);\n"
   490         -      "CREATE INDEX t1c ON t1(c);\n"
   491         -      "CREATE UNIQUE INDEX t2b ON t2(b);\n"
   492         -      "CREATE INDEX t2c ON t2(c DESC);\n"
   493         -      "CREATE INDEX t3bc ON t3(b,c);\n"
   494         -      "COMMIT;\n"
   495         -  );
          516  +  speedtest1_exec("BEGIN;");
          517  +  speedtest1_exec("CREATE UNIQUE INDEX t1b ON t1(b);");
          518  +  speedtest1_exec("CREATE INDEX t1c ON t1(c);");
          519  +  speedtest1_exec("CREATE UNIQUE INDEX t2b ON t2(b);");
          520  +  speedtest1_exec("CREATE INDEX t2c ON t2(c DESC);");
          521  +  speedtest1_exec("CREATE INDEX t3bc ON t3(b,c);");
          522  +  speedtest1_exec("COMMIT;");
   496    523     speedtest1_end_test();
   497    524   
   498    525   
   499    526     n = sz/5;
   500    527     speedtest1_begin_test(160, "%d SELECTS, numeric BETWEEN, indexed", n);
   501    528     speedtest1_exec("BEGIN");
   502    529     speedtest1_prepare(
................................................................................
   562    589     speedtest1_exec("CREATE INDEX t4c ON t4(c)");
   563    590     speedtest1_exec("INSERT INTO t4 SELECT * FROM t1");
   564    591     speedtest1_exec("COMMIT");
   565    592     speedtest1_end_test();
   566    593   
   567    594     n = sz;
   568    595     speedtest1_begin_test(190, "DELETE and REFILL one table", n);
   569         -  speedtest1_exec(
   570         -    "DELETE FROM t2;"
   571         -    "INSERT INTO t2 SELECT * FROM t1;"
   572         -  );
          596  +  speedtest1_exec("DELETE FROM t2;");
          597  +  speedtest1_exec("INSERT INTO t2 SELECT * FROM t1;");
   573    598     speedtest1_end_test();
   574    599   
   575    600   
   576    601     speedtest1_begin_test(200, "VACUUM");
   577    602     speedtest1_exec("VACUUM");
   578    603     speedtest1_end_test();
   579    604   
................................................................................
   659    684   
   660    685   
   661    686     speedtest1_begin_test(290, "Refill two %d-row tables using REPLACE", sz);
   662    687     speedtest1_exec("REPLACE INTO t2(a,b,c) SELECT a,b,c FROM t1");
   663    688     speedtest1_exec("REPLACE INTO t3(a,b,c) SELECT a,b,c FROM t1");
   664    689     speedtest1_end_test();
   665    690   
          691  +  speedtest1_begin_test(300, "Refill a %d-row table using (b&1)==(a&1)", sz);
          692  +  speedtest1_exec("DELETE FROM t2;");
          693  +  speedtest1_exec("INSERT INTO t2(a,b,c)\n"
          694  +                  " SELECT a,b,c FROM t1  WHERE (b&1)==(a&1);");
          695  +  speedtest1_exec("INSERT INTO t2(a,b,c)\n"
          696  +                  " SELECT a,b,c FROM t1  WHERE (b&1)<>(a&1);");
          697  +  speedtest1_end_test();
          698  +
   666    699   
   667    700     n = sz/5;
   668         -  speedtest1_begin_test(300, "%d four-ways joins", n);
          701  +  speedtest1_begin_test(310, "%d four-ways joins", n);
   669    702     speedtest1_exec("BEGIN");
   670    703     speedtest1_prepare(
   671    704       "SELECT t1.c FROM t1, t2, t3, t4\n"
   672    705       " WHERE t4.a BETWEEN ?1 AND ?2\n"
   673    706       "   AND t3.a=t4.b\n"
   674    707       "   AND t2.a=t3.b\n"
   675    708       "   AND t1.c=t2.c"
................................................................................
   680    713       sqlite3_bind_int(g.pStmt, 1, x1);
   681    714       sqlite3_bind_int(g.pStmt, 2, x2);
   682    715       speedtest1_run();
   683    716     }
   684    717     speedtest1_exec("COMMIT");
   685    718     speedtest1_end_test();
   686    719   
   687         -
          720  +  speedtest1_begin_test(320, "subquery in result set", n);
          721  +  speedtest1_prepare(
          722  +    "SELECT sum(a), max(c),\n"
          723  +    "       avg((SELECT a FROM t2 WHERE 5+t2.b=t1.b) AND rowid<?1), max(c)\n"
          724  +    " FROM t1 WHERE rowid<?1;"
          725  +  );
          726  +  sqlite3_bind_int(g.pStmt, 1, est_square_root(g.szTest)*50);
          727  +  speedtest1_run();
          728  +  speedtest1_end_test();
   688    729   
   689    730     speedtest1_begin_test(980, "PRAGMA integrity_check");
   690    731     speedtest1_exec("PRAGMA integrity_check");
   691    732     speedtest1_end_test();
   692    733   
   693    734   
   694    735     speedtest1_begin_test(990, "ANALYZE");
................................................................................
   753    794           doAutovac = 1;
   754    795         }else if( strcmp(z,"cachesize")==0 ){
   755    796           if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
   756    797           i++;
   757    798           cacheSize = integerValue(argv[i]);
   758    799         }else if( strcmp(z,"exclusive")==0 ){
   759    800           doExclusive = 1;
          801  +      }else if( strcmp(z,"explain")==0 ){
          802  +        g.bSqlOnly = 1;
          803  +        g.bExplain = 1;
   760    804         }else if( strcmp(z,"heap")==0 ){
   761    805           if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
   762    806           nHeap = integerValue(argv[i+1]);
   763    807           mnHeap = integerValue(argv[i+2]);
   764    808           i += 2;
   765    809         }else if( strcmp(z,"incrvacuum")==0 ){
   766    810           doIncrvac = 1;
................................................................................
   892    936     if( doExclusive ){
   893    937       speedtest1_exec("PRAGMA locking_mode=EXCLUSIVE");
   894    938     }
   895    939     if( zJMode ){
   896    940       speedtest1_exec("PRAGMA journal_mode=%s", zJMode);
   897    941     }
   898    942   
          943  +  if( g.bExplain ) printf(".explain\n.echo on\n");
   899    944     if( strcmp(zTSet,"main")==0 ){
   900    945       testset_main();
   901    946     }else if( strcmp(zTSet,"debug1")==0 ){
   902    947       testset_debug1();
   903    948     }else{
   904    949       fatal_error("unknown testset: \"%s\"\n", zTSet);
   905    950     }

Changes to test/stat.test.

   160    160     t5 / 19 leaf 0 0 1016 0 \
   161    161   ]
   162    162   
   163    163   db close
   164    164   forcedelete test.db
   165    165   sqlite3 db test.db
   166    166   register_dbstat_vtab db
   167         -breakpoint
   168    167   do_execsql_test stat-5.1 {
   169    168     PRAGMA auto_vacuum = OFF;
   170    169     CREATE VIRTUAL TABLE temp.stat USING dbstat;
   171    170     CREATE TABLE t1(x);
   172    171     INSERT INTO t1 VALUES(zeroblob(1513));
   173    172     INSERT INTO t1 VALUES(zeroblob(1514));
   174    173     SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload

Changes to test/tkt-94c04eaadb.test.

    40     40   
    41     41   # Read from and write to the db just past the 4096MB mark.
    42     42   #
    43     43   do_test tkt-94c94-2.1 {
    44     44     execsql { CREATE TABLE t2(x, y) } db
    45     45   } {}
    46     46   do_test tkt-94c94-2.2 {
    47         -breakpoint
    48     47     execsql { INSERT INTO t2 VALUES(1, 2) } db2
    49     48   } {}
    50     49   do_test tkt-94c94-2.3 {
    51     50     execsql { SELECT * FROM t2 } db
    52     51   } {1 2}
    53     52   do_test tkt-94c94-2.4 {
    54     53     sqlite3async_control halt idle

Changes to test/vtab_shared.test.

   112    112       set error [catchsql { DROP TABLE t1 } db2]
   113    113       break
   114    114     }
   115    115     set error
   116    116   } {1 {database table is locked: sqlite_master}}
   117    117   
   118    118   do_test vtab_shared-1.11 {
   119         -breakpoint
   120    119     execsql {
   121    120       CREATE VIRTUAL TABLE t2 USING echo(t0);
   122    121       CREATE VIRTUAL TABLE t3 USING echo(t0);
   123    122     }
   124    123     execsql { SELECT * FROM t3 } db2
   125    124   } {1 2 3 4 5 6}
   126    125   

Changes to test/wal.test.

   848    848     set fd [open test.db-wal w]
   849    849     seek $fd [expr 200*1024*1024]
   850    850     puts $fd ""
   851    851     close $fd
   852    852     sqlite3 db test.db
   853    853     execsql { SELECT * FROM t2 }
   854    854   } {B 2}
   855         -breakpoint
   856    855   do_test wal-13.1.3 {
   857    856     db close
   858    857     file exists test.db-wal
   859    858   } {0}
   860    859   
   861    860   do_test wal-13.2.1 {
   862    861     sqlite3 db test.db

Changes to test/wal2.test.

  1275   1275       PRAGMA wal_autocheckpoint = OFF;
  1276   1276       PRAGMA journal_mode = WAL;
  1277   1277       PRAGMA checkpoint_fullfsync = [lindex $settings 0];
  1278   1278       PRAGMA fullfsync = [lindex $settings 1];
  1279   1279       PRAGMA synchronous = [lindex $settings 2];
  1280   1280     " {0 wal}
  1281   1281   
  1282         -if { $tn==2} breakpoint
  1283   1282     do_test 15.$tn.2 {
  1284   1283       set sync(normal) 0
  1285   1284       set sync(full) 0
  1286   1285       execsql { INSERT INTO t1 VALUES('abc') }
  1287   1286       list $::sync(normal) $::sync(full)
  1288   1287     } $restart_sync
  1289   1288   

Changes to test/walfault.test.

   563    563         INSERT INTO abc VALUES(randomblob(1500));
   564    564       COMMIT;
   565    565     }
   566    566     faultsim_save_and_close
   567    567   } {}
   568    568   do_faultsim_test walfault-14 -prep {
   569    569     faultsim_restore_and_reopen
   570         -  breakpoint
   571    570     execsql {
   572    571       SELECT count(*) FROM abc;
   573    572       PRAGMA locking_mode = exclusive;
   574    573       BEGIN;
   575    574         INSERT INTO abc VALUES(randomblob(1500));
   576    575       COMMIT;
   577    576     }