/ Check-in [69d5bed0]
Login

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

Overview
Comment:Merge in the latest changes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: 69d5bed017bda3e184857febcc8b6f6bed6ad228
User & Date: drh 2013-08-06 14:52:27
Context
2013-08-19
12:49
Merge in all the latest updates and enhancements from trunk. check-in: 67587a33 user: drh tags: sessions
2013-08-06
14:52
Merge in the latest changes from trunk. check-in: 69d5bed0 user: drh tags: sessions
14:36
For the ".import" command of the command-line shell, start a transaction if there is not one active already. check-in: 5dcc2d91 user: drh tags: trunk
2013-08-02
20:44
Merge in the latest trunk changes, including partial indexes, the MAX_PATH fix in os_win.c, and the sqlite3_cancel_auto_extension() API. check-in: 7e1acb39 user: drh tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/vtshim.c.

   425    425   
   426    426   /* The destructor function for a disposible module */
   427    427   static void vtshimAuxDestructor(void *pXAux){
   428    428     vtshim_aux *pAux = (vtshim_aux*)pXAux;
   429    429     assert( pAux->pAllVtab==0 );
   430    430     if( !pAux->bDisposed && pAux->xChildDestroy ){
   431    431       pAux->xChildDestroy(pAux->pChildAux);
          432  +    pAux->xChildDestroy = 0;
   432    433     }
   433    434     sqlite3_free(pAux->zName);
   434    435     sqlite3_free(pAux->pMod);
   435    436     sqlite3_free(pAux);
   436    437   }
   437    438   
   438    439   static int vtshimCopyModule(
................................................................................
   523    524       for(pVtab=pAux->pAllVtab; pVtab; pVtab=pVtab->pNext){
   524    525         for(pCur=pVtab->pAllCur; pCur; pCur=pCur->pNext){
   525    526           pAux->pMod->xClose(pCur->pChild);
   526    527         }
   527    528         pAux->pMod->xDisconnect(pVtab->pChild);
   528    529       }
   529    530       pAux->bDisposed = 1;
   530         -    if( pAux->xChildDestroy ) pAux->xChildDestroy(pAux->pChildAux);
          531  +    if( pAux->xChildDestroy ){
          532  +      pAux->xChildDestroy(pAux->pChildAux);
          533  +      pAux->xChildDestroy = 0;
          534  +    }
   531    535     }
   532    536   }
   533    537   
   534    538   
   535    539   #endif /* SQLITE_OMIT_VIRTUALTABLE */
   536    540   
   537    541   #ifdef _WIN32

Changes to mkopcodeh.awk.

    31     31   # properties apply to that opcode.  Set corresponding flags using the
    32     32   # OPFLG_INITIALIZER macro.
    33     33   #
    34     34   
    35     35   
    36     36   # Remember the TK_ values from the parse.h file
    37     37   /^#define TK_/ {
    38         -  tk[$2] = 0+$3
           38  +  tk[$2] = 0+$3    # tk[x] holds the numeric value for TK symbol X
    39     39   }
    40     40   
    41     41   # Scan for "case OP_aaaa:" lines in the vdbe.c file
    42     42   /^case OP_/ {
    43     43     name = $2
    44     44     sub(/:/,"",name)
    45     45     sub("\r","",name)
    46         -  op[name] = -1
           46  +  op[name] = -1       # op[x] holds the numeric value for OP symbol x
    47     47     jump[name] = 0
    48     48     out2_prerelease[name] = 0
    49     49     in1[name] = 0
    50     50     in2[name] = 0
    51     51     in3[name] = 0
    52     52     out2[name] = 0
    53     53     out3[name] = 0
    54     54     for(i=3; i<NF; i++){
    55     55       if($i=="same" && $(i+1)=="as"){
    56     56         sym = $(i+2)
    57     57         sub(/,/,"",sym)
    58         -      op[name] = tk[sym]
    59         -      used[op[name]] = 1
    60         -      sameas[op[name]] = sym
           58  +      val = tk[sym]
           59  +      op[name] = val
           60  +      used[val] = 1
           61  +      sameas[val] = sym
           62  +      def[val] = name
    61     63       }
    62     64       x = $i
    63     65       sub(",","",x)
    64     66       if(x=="jump"){
    65     67         jump[name] = 1
    66     68       }else if(x=="out2-prerelease"){
    67     69         out2_prerelease[name] = 1
................................................................................
    86     88     max = 0
    87     89     print "/* Automatically generated.  Do not edit */"
    88     90     print "/* See the mkopcodeh.awk script for details */"
    89     91     op["OP_Noop"] = -1;
    90     92     order[n_op++] = "OP_Noop";
    91     93     op["OP_Explain"] = -1;
    92     94     order[n_op++] = "OP_Explain";
           95  +
           96  +  # Assign small values to opcodes that are processed by resolveP2Values()
           97  +  # to make code generation for the switch() statement smaller and faster.
           98  +  for(i=0; i<n_op; i++){
           99  +    name = order[i];
          100  +    if( op[name]>=0 ) continue;
          101  +    if( name=="OP_Function"      \
          102  +     || name=="OP_AggStep"       \
          103  +     || name=="OP_Transaction"   \
          104  +     || name=="OP_AutoCommit"    \
          105  +     || name=="OP_Savepoint"     \
          106  +     || name=="OP_Checkpoint"    \
          107  +     || name=="OP_Vacuum"        \
          108  +     || name=="OP_JournalMode"   \
          109  +     || name=="OP_VUpdate"       \
          110  +     || name=="OP_VFilter"       \
          111  +     || name=="OP_Next"          \
          112  +     || name=="OP_SorterNext"    \
          113  +     || name=="OP_Prev"          \
          114  +    ){
          115  +      cnt++
          116  +      while( used[cnt] ) cnt++
          117  +      op[name] = cnt
          118  +      used[cnt] = 1
          119  +      def[cnt] = name
          120  +    }
          121  +  }
          122  +
          123  +  # Generate the numeric values for opcodes
    93    124     for(i=0; i<n_op; i++){
    94    125       name = order[i];
    95    126       if( op[name]<0 ){
    96    127         cnt++
    97    128         while( used[cnt] ) cnt++
    98    129         op[name] = cnt
          130  +      used[cnt] = 1
          131  +      def[cnt] = name
          132  +    }
          133  +  }
          134  +  max = cnt
          135  +  for(i=1; i<=max; i++){
          136  +    if( !used[i] ){
          137  +      def[i] = "OP_NotUsed_" i 
    99    138       }
   100         -    used[op[name]] = 1;
   101         -    if( op[name]>max ) max = op[name]
   102         -    printf "#define %-25s %15d", name, op[name]
   103         -    if( sameas[op[name]] ) {
   104         -      printf "   /* same as %-12s*/", sameas[op[name]]
          139  +    printf "#define %-25s %15d", def[i], i
          140  +    if( sameas[i] ){
          141  +      printf "   /* same as %-12s*/", sameas[i]
   105    142       } 
   106    143       printf "\n"
   107         -
   108         -  }
   109         -  seenUnused = 0;
   110         -  for(i=1; i<max; i++){
   111         -    if( !used[i] ){
   112         -      if( !seenUnused ){
   113         -        printf "\n/* The following opcode values are never used */\n"
   114         -        seenUnused = 1
   115         -      }
   116         -      printf "#define %-25s %15d\n", sprintf( "OP_NotUsed_%-3d", i ), i
   117         -    }
   118    144     }
   119    145   
   120    146     # Generate the bitvectors:
   121    147     #
   122    148     #  bit 0:     jump
   123    149     #  bit 1:     pushes a result onto stack
   124    150     #  bit 2:     output to p1.  release p1 before opcode runs
   125    151     #
   126         -  for(i=0; i<=max; i++) bv[i] = 0;
   127         -  for(i=0; i<n_op; i++){
   128         -    name = order[i];
   129         -    x = op[name]
          152  +  for(i=0; i<=max; i++){
          153  +    name = def[i]
   130    154       a0 = a1 = a2 = a3 = a4 = a5 = a6 = a7 = 0
   131         -    # a7 = a9 = a10 = a11 = a12 = a13 = a14 = a15 = 0
   132    155       if( jump[name] ) a0 = 1;
   133    156       if( out2_prerelease[name] ) a1 = 2;
   134    157       if( in1[name] ) a2 = 4;
   135    158       if( in2[name] ) a3 = 8;
   136    159       if( in3[name] ) a4 = 16;
   137    160       if( out2[name] ) a5 = 32;
   138    161       if( out3[name] ) a6 = 64;
   139         -    # bv[x] = a0+a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15;
   140         -    bv[x] = a0+a1+a2+a3+a4+a5+a6+a7;
          162  +    bv[i] = a0+a1+a2+a3+a4+a5+a6+a7;
   141    163     }
   142    164     print "\n"
   143    165     print "/* Properties such as \"out2\" or \"jump\" that are specified in"
   144    166     print "** comments following the \"case\" for each opcode in the vdbe.c"
   145    167     print "** are encoded into bitvectors as follows:"
   146    168     print "*/"
   147    169     print "#define OPFLG_JUMP            0x0001  /* jump:  P2 holds jmp target */"

Changes to src/build.c.

  3801   3801   ** pointer. If an error occurs (out of memory or missing collation 
  3802   3802   ** sequence), NULL is returned and the state of pParse updated to reflect
  3803   3803   ** the error.
  3804   3804   */
  3805   3805   KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){
  3806   3806     int i;
  3807   3807     int nCol = pIdx->nColumn;
  3808         -  int nBytes = sizeof(KeyInfo) + (nCol-1)*sizeof(CollSeq*) + nCol;
  3809         -  sqlite3 *db = pParse->db;
  3810         -  KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZero(db, nBytes);
         3808  +  KeyInfo *pKey;
  3811   3809   
         3810  +  pKey = sqlite3KeyInfoAlloc(pParse->db, nCol);
  3812   3811     if( pKey ){
  3813         -    pKey->db = pParse->db;
  3814         -    pKey->aSortOrder = (u8 *)&(pKey->aColl[nCol]);
  3815         -    assert( &pKey->aSortOrder[nCol]==&(((u8 *)pKey)[nBytes]) );
  3816   3812       for(i=0; i<nCol; i++){
  3817   3813         char *zColl = pIdx->azColl[i];
  3818   3814         assert( zColl );
  3819   3815         pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
  3820   3816         pKey->aSortOrder[i] = pIdx->aSortOrder[i];
  3821   3817       }
  3822         -    pKey->nField = (u16)nCol;
  3823   3818     }
  3824   3819   
  3825   3820     if( pParse->nErr ){
  3826         -    sqlite3DbFree(db, pKey);
         3821  +    sqlite3DbFree(pParse->db, pKey);
  3827   3822       pKey = 0;
  3828   3823     }
  3829   3824     return pKey;
  3830   3825   }

Changes to src/expr.c.

  1688   1688       sqlite3VdbeAddOp4(v, OP_Explain, pParse->iSelectId, 0, 0, zMsg, P4_DYNAMIC);
  1689   1689     }
  1690   1690   #endif
  1691   1691   
  1692   1692     switch( pExpr->op ){
  1693   1693       case TK_IN: {
  1694   1694         char affinity;              /* Affinity of the LHS of the IN */
  1695         -      KeyInfo keyInfo;            /* Keyinfo for the generated table */
  1696         -      static u8 sortOrder = 0;    /* Fake aSortOrder for keyInfo */
  1697   1695         int addr;                   /* Address of OP_OpenEphemeral instruction */
  1698   1696         Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
         1697  +      KeyInfo *pKeyInfo = 0;      /* Key information */
  1699   1698   
  1700   1699         if( rMayHaveNull ){
  1701   1700           sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
  1702   1701         }
  1703   1702   
  1704   1703         affinity = sqlite3ExprAffinity(pLeft);
  1705   1704   
................................................................................
  1715   1714         ** if either column has NUMERIC or INTEGER affinity. If neither
  1716   1715         ** 'x' nor the SELECT... statement are columns, then numeric affinity
  1717   1716         ** is used.
  1718   1717         */
  1719   1718         pExpr->iTable = pParse->nTab++;
  1720   1719         addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
  1721   1720         if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
  1722         -      memset(&keyInfo, 0, sizeof(keyInfo));
  1723         -      keyInfo.nField = 1;
  1724         -      keyInfo.aSortOrder = &sortOrder;
         1721  +      pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1);
  1725   1722   
  1726   1723         if( ExprHasProperty(pExpr, EP_xIsSelect) ){
  1727   1724           /* Case 1:     expr IN (SELECT ...)
  1728   1725           **
  1729   1726           ** Generate code to write the results of the select into the temporary
  1730   1727           ** table allocated and opened above.
  1731   1728           */
................................................................................
  1734   1731   
  1735   1732           assert( !isRowid );
  1736   1733           sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
  1737   1734           dest.affSdst = (u8)affinity;
  1738   1735           assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
  1739   1736           pExpr->x.pSelect->iLimit = 0;
  1740   1737           if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
         1738  +          sqlite3DbFree(pParse->db, pKeyInfo);
  1741   1739             return 0;
  1742   1740           }
  1743   1741           pEList = pExpr->x.pSelect->pEList;
  1744         -        if( ALWAYS(pEList!=0 && pEList->nExpr>0) ){ 
  1745         -          keyInfo.aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
         1742  +        if( pKeyInfo && ALWAYS(pEList!=0 && pEList->nExpr>0) ){ 
         1743  +          pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
  1746   1744                 pEList->a[0].pExpr);
  1747   1745           }
  1748   1746         }else if( ALWAYS(pExpr->x.pList!=0) ){
  1749   1747           /* Case 2:     expr IN (exprlist)
  1750   1748           **
  1751   1749           ** For each expression, build an index key from the evaluation and
  1752   1750           ** store it in the temporary table. If <expr> is a column, then use
................................................................................
  1757   1755           ExprList *pList = pExpr->x.pList;
  1758   1756           struct ExprList_item *pItem;
  1759   1757           int r1, r2, r3;
  1760   1758   
  1761   1759           if( !affinity ){
  1762   1760             affinity = SQLITE_AFF_NONE;
  1763   1761           }
  1764         -        keyInfo.aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
  1765         -        keyInfo.aSortOrder = &sortOrder;
         1762  +        if( pKeyInfo ){
         1763  +          pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
         1764  +        }
  1766   1765   
  1767   1766           /* Loop through each expression in <exprlist>. */
  1768   1767           r1 = sqlite3GetTempReg(pParse);
  1769   1768           r2 = sqlite3GetTempReg(pParse);
  1770   1769           sqlite3VdbeAddOp2(v, OP_Null, 0, r2);
  1771   1770           for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
  1772   1771             Expr *pE2 = pItem->pExpr;
................................................................................
  1797   1796                 sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
  1798   1797               }
  1799   1798             }
  1800   1799           }
  1801   1800           sqlite3ReleaseTempReg(pParse, r1);
  1802   1801           sqlite3ReleaseTempReg(pParse, r2);
  1803   1802         }
  1804         -      if( !isRowid ){
  1805         -        sqlite3VdbeChangeP4(v, addr, (void *)&keyInfo, P4_KEYINFO);
         1803  +      if( pKeyInfo ){
         1804  +        sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO_HANDOFF);
  1806   1805         }
  1807   1806         break;
  1808   1807       }
  1809   1808   
  1810   1809       case TK_EXISTS:
  1811   1810       case TK_SELECT:
  1812   1811       default: {

Changes to src/parse.y.

   413    413   
   414    414   select(A) ::= oneselect(X).                      {A = X;}
   415    415   %ifndef SQLITE_OMIT_COMPOUND_SELECT
   416    416   select(A) ::= select(X) multiselect_op(Y) oneselect(Z).  {
   417    417     if( Z ){
   418    418       Z->op = (u8)Y;
   419    419       Z->pPrior = X;
          420  +    if( Y!=TK_ALL ) pParse->hasCompound = 1;
   420    421     }else{
   421    422       sqlite3SelectDelete(pParse->db, X);
   422    423     }
   423    424     A = Z;
   424    425   }
   425    426   %type multiselect_op {int}
   426    427   multiselect_op(A) ::= UNION(OP).             {A = @OP;}

Changes to src/select.c.

   797    797     ** there is a sorter, in which case the sorter has already limited
   798    798     ** the output for us.
   799    799     */
   800    800     if( pOrderBy==0 && p->iLimit ){
   801    801       sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
   802    802     }
   803    803   }
          804  +
          805  +/*
          806  +** Allocate a KeyInfo object sufficient for an index of N columns.
          807  +**
          808  +** Actually, always allocate one extra column for the rowid at the end
          809  +** of the index.  So the KeyInfo returned will have space sufficient for
          810  +** N+1 columns.
          811  +*/
          812  +KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N){
          813  +  KeyInfo *p = sqlite3DbMallocZero(db, 
          814  +                   sizeof(KeyInfo) + (N+1)*(sizeof(CollSeq*)+1));
          815  +  if( p ){
          816  +    p->aSortOrder = (u8*)&p->aColl[N+1];
          817  +    p->nField = (u16)N;
          818  +    p->enc = ENC(db);
          819  +    p->db = db;
          820  +  }
          821  +  return p;
          822  +}
   804    823   
   805    824   /*
   806    825   ** Given an expression list, generate a KeyInfo structure that records
   807    826   ** the collating sequence for each expression in that expression list.
   808    827   **
   809    828   ** If the ExprList is an ORDER BY or GROUP BY clause then the resulting
   810    829   ** KeyInfo structure is appropriate for initializing a virtual index to
................................................................................
   814    833   **
   815    834   ** Space to hold the KeyInfo structure is obtain from malloc.  The calling
   816    835   ** function is responsible for seeing that this structure is eventually
   817    836   ** freed.  Add the KeyInfo structure to the P4 field of an opcode using
   818    837   ** P4_KEYINFO_HANDOFF is the usual way of dealing with this.
   819    838   */
   820    839   static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
   821         -  sqlite3 *db = pParse->db;
   822    840     int nExpr;
   823    841     KeyInfo *pInfo;
   824    842     struct ExprList_item *pItem;
          843  +  sqlite3 *db = pParse->db;
   825    844     int i;
   826    845   
   827    846     nExpr = pList->nExpr;
   828         -  pInfo = sqlite3DbMallocZero(db, sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
          847  +  pInfo = sqlite3KeyInfoAlloc(db, nExpr);
   829    848     if( pInfo ){
   830         -    pInfo->aSortOrder = (u8*)&pInfo->aColl[nExpr];
   831         -    pInfo->nField = (u16)nExpr;
   832         -    pInfo->enc = ENC(db);
   833         -    pInfo->db = db;
   834    849       for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
   835    850         CollSeq *pColl;
   836    851         pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
   837         -      if( !pColl ){
   838         -        pColl = db->pDfltColl;
   839         -      }
          852  +      if( !pColl ) pColl = db->pDfltColl;
   840    853         pInfo->aColl[i] = pColl;
   841    854         pInfo->aSortOrder[i] = pItem->sortOrder;
   842    855       }
   843    856     }
   844    857     return pInfo;
   845    858   }
   846    859   
................................................................................
  1938   1951       KeyInfo *pKeyInfo;            /* Collating sequence for the result set */
  1939   1952       Select *pLoop;                /* For looping through SELECT statements */
  1940   1953       CollSeq **apColl;             /* For looping through pKeyInfo->aColl[] */
  1941   1954       int nCol;                     /* Number of columns in result set */
  1942   1955   
  1943   1956       assert( p->pRightmost==p );
  1944   1957       nCol = p->pEList->nExpr;
  1945         -    pKeyInfo = sqlite3DbMallocZero(db,
  1946         -                       sizeof(*pKeyInfo)+nCol*(sizeof(CollSeq*) + 1));
         1958  +    pKeyInfo = sqlite3KeyInfoAlloc(db, nCol);
  1947   1959       if( !pKeyInfo ){
  1948   1960         rc = SQLITE_NOMEM;
  1949   1961         goto multi_select_end;
  1950   1962       }
  1951         -
  1952         -    pKeyInfo->enc = ENC(db);
  1953         -    pKeyInfo->nField = (u16)nCol;
  1954         -
  1955   1963       for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
  1956   1964         *apColl = multiSelectCollSeq(pParse, p, i);
  1957   1965         if( 0==*apColl ){
  1958   1966           *apColl = db->pDfltColl;
  1959   1967         }
  1960   1968       }
  1961         -    pKeyInfo->aSortOrder = (u8*)apColl;
  1962   1969   
  1963   1970       for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
  1964   1971         for(i=0; i<2; i++){
  1965   1972           int addr = pLoop->addrOpenEphm[i];
  1966   1973           if( addr<0 ){
  1967   1974             /* If [0] is unused then [1] is also unused.  So we can
  1968   1975             ** always safely abort as soon as the first unused slot is found */
................................................................................
  2323   2330     aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
  2324   2331     if( aPermute ){
  2325   2332       struct ExprList_item *pItem;
  2326   2333       for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
  2327   2334         assert( pItem->iOrderByCol>0  && pItem->iOrderByCol<=p->pEList->nExpr );
  2328   2335         aPermute[i] = pItem->iOrderByCol - 1;
  2329   2336       }
  2330         -    pKeyMerge =
  2331         -      sqlite3DbMallocRaw(db, sizeof(*pKeyMerge)+nOrderBy*(sizeof(CollSeq*)+1));
         2337  +    pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy);
  2332   2338       if( pKeyMerge ){
  2333         -      pKeyMerge->aSortOrder = (u8*)&pKeyMerge->aColl[nOrderBy];
  2334         -      pKeyMerge->nField = (u16)nOrderBy;
  2335         -      pKeyMerge->enc = ENC(db);
  2336   2339         for(i=0; i<nOrderBy; i++){
  2337   2340           CollSeq *pColl;
  2338   2341           Expr *pTerm = pOrderBy->a[i].pExpr;
  2339   2342           if( pTerm->flags & EP_Collate ){
  2340   2343             pColl = sqlite3ExprCollSeq(pParse, pTerm);
  2341   2344           }else{
  2342   2345             pColl = multiSelectCollSeq(pParse, p, aPermute[i]);
................................................................................
  2365   2368       regPrev = 0;
  2366   2369     }else{
  2367   2370       int nExpr = p->pEList->nExpr;
  2368   2371       assert( nOrderBy>=nExpr || db->mallocFailed );
  2369   2372       regPrev = pParse->nMem+1;
  2370   2373       pParse->nMem += nExpr+1;
  2371   2374       sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
  2372         -    pKeyDup = sqlite3DbMallocZero(db,
  2373         -                  sizeof(*pKeyDup) + nExpr*(sizeof(CollSeq*)+1) );
         2375  +    pKeyDup = sqlite3KeyInfoAlloc(db, nExpr);
  2374   2376       if( pKeyDup ){
  2375         -      pKeyDup->aSortOrder = (u8*)&pKeyDup->aColl[nExpr];
  2376         -      pKeyDup->nField = (u16)nExpr;
  2377         -      pKeyDup->enc = ENC(db);
  2378   2377         for(i=0; i<nExpr; i++){
  2379   2378           pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
  2380   2379           pKeyDup->aSortOrder[i] = 0;
  2381   2380         }
  2382   2381       }
  2383   2382     }
  2384   2383    
................................................................................
  3636   3635   ** If anything goes wrong, an error message is written into pParse.
  3637   3636   ** The calling function can detect the problem by looking at pParse->nErr
  3638   3637   ** and/or pParse->db->mallocFailed.
  3639   3638   */
  3640   3639   static void sqlite3SelectExpand(Parse *pParse, Select *pSelect){
  3641   3640     Walker w;
  3642   3641     memset(&w, 0, sizeof(w));
  3643         -  w.xSelectCallback = convertCompoundSelectToSubquery;
  3644   3642     w.xExprCallback = exprWalkNoop;
  3645   3643     w.pParse = pParse;
  3646         -  sqlite3WalkSelect(&w, pSelect);
         3644  +  if( pParse->hasCompound ){
         3645  +    w.xSelectCallback = convertCompoundSelectToSubquery;
         3646  +    sqlite3WalkSelect(&w, pSelect);
         3647  +  }
  3647   3648     w.xSelectCallback = selectExpander;
  3648   3649     sqlite3WalkSelect(&w, pSelect);
  3649   3650   }
  3650   3651   
  3651   3652   
  3652   3653   #ifndef SQLITE_OMIT_SUBQUERY
  3653   3654   /*

Changes to src/shell.c.

    49     49   # include <editline/editline.h>
    50     50   #endif
    51     51   #if defined(HAVE_READLINE) && HAVE_READLINE==1
    52     52   # include <readline/readline.h>
    53     53   # include <readline/history.h>
    54     54   #endif
    55     55   #if !defined(HAVE_EDITLINE) && (!defined(HAVE_READLINE) || HAVE_READLINE!=1)
    56         -# define readline(p) local_getline(p,stdin,0)
    57     56   # define add_history(X)
    58     57   # define read_history(X)
    59     58   # define write_history(X)
    60     59   # define stifle_history(X)
    61     60   #endif
    62     61   
    63     62   #if defined(_WIN32) || defined(WIN32)
................................................................................
   333    332   
   334    333   /*
   335    334   ** This routine reads a line of text from FILE in, stores
   336    335   ** the text in memory obtained from malloc() and returns a pointer
   337    336   ** to the text.  NULL is returned at end of file, or if malloc()
   338    337   ** fails.
   339    338   **
   340         -** The interface is like "readline" but no command-line editing
   341         -** is done.
          339  +** If zLine is not NULL then it is a malloced buffer returned from
          340  +** a previous call to this routine that may be reused.
   342    341   */
   343         -static char *local_getline(char *zPrompt, FILE *in, int csvFlag){
   344         -  char *zLine;
   345         -  int nLine;
   346         -  int n;
   347         -  int inQuote = 0;
          342  +static char *local_getline(char *zLine, FILE *in){
          343  +  int nLine = zLine==0 ? 0 : 100;
          344  +  int n = 0;
   348    345   
   349         -  if( zPrompt && *zPrompt ){
   350         -    printf("%s",zPrompt);
   351         -    fflush(stdout);
   352         -  }
   353         -  nLine = 100;
   354         -  zLine = malloc( nLine );
   355         -  if( zLine==0 ) return 0;
   356         -  n = 0;
   357    346     while( 1 ){
   358    347       if( n+100>nLine ){
   359    348         nLine = nLine*2 + 100;
   360    349         zLine = realloc(zLine, nLine);
   361    350         if( zLine==0 ) return 0;
   362    351       }
   363    352       if( fgets(&zLine[n], nLine - n, in)==0 ){
................................................................................
   364    353         if( n==0 ){
   365    354           free(zLine);
   366    355           return 0;
   367    356         }
   368    357         zLine[n] = 0;
   369    358         break;
   370    359       }
   371         -    while( zLine[n] ){
   372         -      if( zLine[n]=='"' ) inQuote = !inQuote;
   373         -      n++;
   374         -    }
   375         -    if( n>0 && zLine[n-1]=='\n' && (!inQuote || !csvFlag) ){
          360  +    while( zLine[n] ) n++;
          361  +    if( n>0 && zLine[n-1]=='\n' ){
   376    362         n--;
   377    363         if( n>0 && zLine[n-1]=='\r' ) n--;
   378    364         zLine[n] = 0;
   379    365         break;
   380    366       }
   381    367     }
   382         -  zLine = realloc( zLine, n+1 );
   383    368     return zLine;
   384    369   }
   385    370   
   386    371   /*
   387    372   ** Retrieve a single line of input text.
   388    373   **
   389         -** zPrior is a string of prior text retrieved.  If not the empty
   390         -** string, then issue a continuation prompt.
          374  +** If in==0 then read from standard input and prompt before each line.
          375  +** If isContinuation is true, then a continuation prompt is appropriate.
          376  +** If isContinuation is zero, then the main prompt should be used.
          377  +**
          378  +** If zPrior is not NULL then it is a buffer from a prior call to this
          379  +** routine that can be reused.
          380  +**
          381  +** The result is stored in space obtained from malloc() and must either
          382  +** be freed by the caller or else passed back into this routine via the
          383  +** zPrior argument for reuse.
   391    384   */
   392         -static char *one_input_line(const char *zPrior, FILE *in){
          385  +static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
   393    386     char *zPrompt;
   394    387     char *zResult;
   395    388     if( in!=0 ){
   396         -    return local_getline(0, in, 0);
   397         -  }
   398         -  if( zPrior && zPrior[0] ){
   399         -    zPrompt = continuePrompt;
          389  +    zResult = local_getline(zPrior, in);
   400    390     }else{
   401         -    zPrompt = mainPrompt;
   402         -  }
   403         -  zResult = readline(zPrompt);
          391  +    zPrompt = isContinuation ? continuePrompt : mainPrompt;
   404    392   #if defined(HAVE_READLINE) && HAVE_READLINE==1
   405         -  if( zResult && *zResult ) add_history(zResult);
          393  +    free(zPrior);
          394  +    zResult = readline(zPrompt);
          395  +    if( zResult && *zResult ) add_history(zResult);
          396  +#else
          397  +    printf("%s", zPrompt);
          398  +    fflush(stdout);
          399  +    zResult = local_getline(zPrior, stdin);
   406    400   #endif
          401  +  }
   407    402     return zResult;
   408    403   }
   409    404   
   410    405   struct previous_mode_data {
   411    406     int valid;        /* Is there legit data in here? */
   412    407     int mode;
   413    408     int showHeader;
................................................................................
  1991   1986     if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
  1992   1987       char *zTable = azArg[2];    /* Insert data into this table */
  1993   1988       char *zFile = azArg[1];     /* Name of file to extra content from */
  1994   1989       sqlite3_stmt *pStmt = NULL; /* A statement */
  1995   1990       int nCol;                   /* Number of columns in the table */
  1996   1991       int nByte;                  /* Number of bytes in an SQL string */
  1997   1992       int i, j;                   /* Loop counters */
         1993  +    int needCommit;             /* True to COMMIT or ROLLBACK at end */
  1998   1994       int nSep;                   /* Number of bytes in p->separator[] */
  1999   1995       char *zSql;                 /* An SQL statement */
  2000   1996       CSVReader sCsv;             /* Reader context */
  2001   1997       int (*xCloser)(FILE*);      /* Procedure to close th3 connection */
  2002   1998   
  2003   1999       seenInterrupt = 0;
  2004   2000       memset(&sCsv, 0, sizeof(sCsv));
................................................................................
  2092   2088       sqlite3_free(zSql);
  2093   2089       if( rc ){
  2094   2090         fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
  2095   2091         if (pStmt) sqlite3_finalize(pStmt);
  2096   2092         xCloser(sCsv.in);
  2097   2093         return 1;
  2098   2094       }
         2095  +    needCommit = sqlite3_get_autocommit(db);
         2096  +    if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0);
  2099   2097       do{
  2100   2098         int startLine = sCsv.nLine;
  2101   2099         for(i=0; i<nCol; i++){
  2102   2100           char *z = csv_read_one_field(&sCsv);
  2103   2101           if( z==0 && i==0 ) break;
  2104   2102           sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
  2105   2103           if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
................................................................................
  2128   2126           }
  2129   2127         }
  2130   2128       }while( sCsv.cTerm!=EOF );
  2131   2129   
  2132   2130       xCloser(sCsv.in);
  2133   2131       sqlite3_free(sCsv.z);
  2134   2132       sqlite3_finalize(pStmt);
  2135         -    sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
         2133  +    if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
  2136   2134     }else
  2137   2135   
  2138   2136     if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
  2139   2137       struct callback_data data;
  2140   2138       char *zErrMsg = 0;
  2141   2139       open_db(p);
  2142   2140       memcpy(&data, p, sizeof(data));
................................................................................
  2777   2775     return rc;
  2778   2776   }
  2779   2777   
  2780   2778   /*
  2781   2779   ** Return TRUE if a semicolon occurs anywhere in the first N characters
  2782   2780   ** of string z[].
  2783   2781   */
  2784         -static int _contains_semicolon(const char *z, int N){
         2782  +static int line_contains_semicolon(const char *z, int N){
  2785   2783     int i;
  2786   2784     for(i=0; i<N; i++){  if( z[i]==';' ) return 1; }
  2787   2785     return 0;
  2788   2786   }
  2789   2787   
  2790   2788   /*
  2791   2789   ** Test to see if a line consists entirely of whitespace.
................................................................................
  2812   2810   }
  2813   2811   
  2814   2812   /*
  2815   2813   ** Return TRUE if the line typed in is an SQL command terminator other
  2816   2814   ** than a semi-colon.  The SQL Server style "go" command is understood
  2817   2815   ** as is the Oracle "/".
  2818   2816   */
  2819         -static int _is_command_terminator(const char *zLine){
         2817  +static int line_is_command_terminator(const char *zLine){
  2820   2818     while( IsSpace(zLine[0]) ){ zLine++; };
  2821   2819     if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ){
  2822   2820       return 1;  /* Oracle */
  2823   2821     }
  2824   2822     if( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o'
  2825   2823            && _all_whitespace(&zLine[2]) ){
  2826   2824       return 1;  /* SQL Server */
................................................................................
  2828   2826     return 0;
  2829   2827   }
  2830   2828   
  2831   2829   /*
  2832   2830   ** Return true if zSql is a complete SQL statement.  Return false if it
  2833   2831   ** ends in the middle of a string literal or C-style comment.
  2834   2832   */
  2835         -static int _is_complete(char *zSql, int nSql){
         2833  +static int line_is_complete(char *zSql, int nSql){
  2836   2834     int rc;
  2837   2835     if( zSql==0 ) return 1;
  2838   2836     zSql[nSql] = ';';
  2839   2837     zSql[nSql+1] = 0;
  2840   2838     rc = sqlite3_complete(zSql);
  2841   2839     zSql[nSql] = 0;
  2842   2840     return rc;
................................................................................
  2848   2846   ** is coming from a file or device.  A prompt is issued and history
  2849   2847   ** is saved only if input is interactive.  An interrupt signal will
  2850   2848   ** cause this routine to exit immediately, unless input is interactive.
  2851   2849   **
  2852   2850   ** Return the number of errors.
  2853   2851   */
  2854   2852   static int process_input(struct callback_data *p, FILE *in){
  2855         -  char *zLine = 0;
  2856         -  char *zSql = 0;
  2857         -  int nSql = 0;
  2858         -  int nSqlPrior = 0;
  2859         -  char *zErrMsg;
  2860         -  int rc;
  2861         -  int errCnt = 0;
  2862         -  int lineno = 0;
  2863         -  int startline = 0;
         2853  +  char *zLine = 0;          /* A single input line */
         2854  +  char *zSql = 0;           /* Accumulated SQL text */
         2855  +  int nLine;                /* Length of current line */
         2856  +  int nSql = 0;             /* Bytes of zSql[] used */
         2857  +  int nAlloc = 0;           /* Allocated zSql[] space */
         2858  +  int nSqlPrior = 0;        /* Bytes of zSql[] used by prior line */
         2859  +  char *zErrMsg;            /* Error message returned */
         2860  +  int rc;                   /* Error code */
         2861  +  int errCnt = 0;           /* Number of errors seen */
         2862  +  int lineno = 0;           /* Current line number */
         2863  +  int startline = 0;        /* Line number for start of current input */
  2864   2864   
  2865   2865     while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){
  2866   2866       fflush(p->out);
  2867         -    free(zLine);
  2868         -    zLine = one_input_line(zSql, in);
         2867  +    zLine = one_input_line(in, zLine, nSql>0);
  2869   2868       if( zLine==0 ){
  2870   2869         /* End of input */
  2871   2870         if( stdin_is_interactive ) printf("\n");
  2872   2871         break;
  2873   2872       }
  2874   2873       if( seenInterrupt ){
  2875   2874         if( in!=0 ) break;
  2876   2875         seenInterrupt = 0;
  2877   2876       }
  2878   2877       lineno++;
  2879         -    if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
         2878  +    if( nSql==0 && _all_whitespace(zLine) ) continue;
  2880   2879       if( zLine && zLine[0]=='.' && nSql==0 ){
  2881   2880         if( p->echoOn ) printf("%s\n", zLine);
  2882   2881         rc = do_meta_command(zLine, p);
  2883   2882         if( rc==2 ){ /* exit requested */
  2884   2883           break;
  2885   2884         }else if( rc ){
  2886   2885           errCnt++;
  2887   2886         }
  2888   2887         continue;
  2889   2888       }
  2890         -    if( _is_command_terminator(zLine) && _is_complete(zSql, nSql) ){
         2889  +    if( line_is_command_terminator(zLine) && line_is_complete(zSql, nSql) ){
  2891   2890         memcpy(zLine,";",2);
         2891  +    }
         2892  +    nLine = strlen30(zLine);
         2893  +    if( nSql+nLine+2>=nAlloc ){
         2894  +      nAlloc = nSql+nLine+100;
         2895  +      zSql = realloc(zSql, nAlloc);
         2896  +      if( zSql==0 ){
         2897  +        fprintf(stderr, "Error: out of memory\n");
         2898  +        exit(1);
         2899  +      }
  2892   2900       }
  2893   2901       nSqlPrior = nSql;
  2894         -    if( zSql==0 ){
         2902  +    if( nSql==0 ){
  2895   2903         int i;
  2896   2904         for(i=0; zLine[i] && IsSpace(zLine[i]); i++){}
  2897         -      if( zLine[i]!=0 ){
  2898         -        nSql = strlen30(zLine);
  2899         -        zSql = malloc( nSql+3 );
  2900         -        if( zSql==0 ){
  2901         -          fprintf(stderr, "Error: out of memory\n");
  2902         -          exit(1);
  2903         -        }
  2904         -        memcpy(zSql, zLine, nSql+1);
  2905         -        startline = lineno;
  2906         -      }
         2905  +      memcpy(zSql, zLine+i, nLine+1-i);
         2906  +      startline = lineno;
         2907  +      nSql = nLine-i;
  2907   2908       }else{
  2908         -      int len = strlen30(zLine);
  2909         -      zSql = realloc( zSql, nSql + len + 4 );
  2910         -      if( zSql==0 ){
  2911         -        fprintf(stderr,"Error: out of memory\n");
  2912         -        exit(1);
  2913         -      }
  2914   2909         zSql[nSql++] = '\n';
  2915         -      memcpy(&zSql[nSql], zLine, len+1);
  2916         -      nSql += len;
         2910  +      memcpy(zSql+nSql, zLine, nLine+1);
         2911  +      nSql += nLine;
  2917   2912       }
  2918         -    if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
         2913  +    if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
  2919   2914                   && sqlite3_complete(zSql) ){
  2920   2915         p->cnt = 0;
  2921   2916         open_db(p);
  2922   2917         BEGIN_TIMER;
  2923   2918         rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
  2924   2919         END_TIMER;
  2925   2920         if( rc || zErrMsg ){
................................................................................
  2935   2930             sqlite3_free(zErrMsg);
  2936   2931             zErrMsg = 0;
  2937   2932           }else{
  2938   2933             fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
  2939   2934           }
  2940   2935           errCnt++;
  2941   2936         }
  2942         -      free(zSql);
  2943         -      zSql = 0;
  2944   2937         nSql = 0;
  2945         -    }else if( zSql && _all_whitespace(zSql) ){
  2946         -      free(zSql);
  2947         -      zSql = 0;
         2938  +    }else if( nSql && _all_whitespace(zSql) ){
  2948   2939         nSql = 0;
  2949   2940       }
  2950   2941     }
  2951         -  if( zSql ){
         2942  +  if( nSql ){
  2952   2943       if( !_all_whitespace(zSql) ){
  2953   2944         fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
  2954   2945       }
  2955   2946       free(zSql);
  2956   2947     }
  2957   2948     free(zLine);
  2958   2949     return errCnt>0;

Changes to src/sqliteInt.h.

  1468   1468   #define OE_Default  99  /* Do whatever the default action is */
  1469   1469   
  1470   1470   
  1471   1471   /*
  1472   1472   ** An instance of the following structure is passed as the first
  1473   1473   ** argument to sqlite3VdbeKeyCompare and is used to control the 
  1474   1474   ** comparison of the two index keys.
         1475  +**
         1476  +** Note that aSortOrder[] and aColl[] have nField+1 slots.  There
         1477  +** are nField slots for the columns of an index then one extra slot
         1478  +** for the rowid at the end.
  1475   1479   */
  1476   1480   struct KeyInfo {
  1477   1481     sqlite3 *db;        /* The database connection */
  1478   1482     u8 enc;             /* Text encoding - one of the SQLITE_UTF* values */
  1479         -  u16 nField;         /* Number of entries in aColl[] */
  1480         -  u8 *aSortOrder;     /* Sort order for each column.  May be NULL */
         1483  +  u16 nField;         /* Maximum index for aColl[] and aSortOrder[] */
         1484  +  u8 *aSortOrder;     /* Sort order for each column. */
  1481   1485     CollSeq *aColl[1];  /* Collating sequence for each term of the key */
  1482   1486   };
  1483   1487   
  1484   1488   /*
  1485   1489   ** An instance of the following structure holds information about a
  1486   1490   ** single index record that has already been parsed out into individual
  1487   1491   ** values.
................................................................................
  2078   2082   #define SF_UsesEphemeral   0x0008  /* Uses the OpenEphemeral opcode */
  2079   2083   #define SF_Expanded        0x0010  /* sqlite3SelectExpand() called on this */
  2080   2084   #define SF_HasTypeInfo     0x0020  /* FROM subqueries have Table metadata */
  2081   2085   #define SF_UseSorter       0x0040  /* Sort using a sorter */
  2082   2086   #define SF_Values          0x0080  /* Synthesized from VALUES clause */
  2083   2087   #define SF_Materialize     0x0100  /* Force materialization of views */
  2084   2088   #define SF_NestedFrom      0x0200  /* Part of a parenthesized FROM clause */
         2089  +#define SF_MaybeConvert    0x0400  /* Need convertCompoundSelectToSubquery() */
  2085   2090   
  2086   2091   
  2087   2092   /*
  2088   2093   ** The results of a select can be distributed in several ways.  The
  2089   2094   ** "SRT" prefix means "SELECT Result Type".
  2090   2095   */
  2091   2096   #define SRT_Union        1  /* Store result as keys in an index */
................................................................................
  2199   2204     u8 nested;           /* Number of nested calls to the parser/code generator */
  2200   2205     u8 nTempReg;         /* Number of temporary registers in aTempReg[] */
  2201   2206     u8 nTempInUse;       /* Number of aTempReg[] currently checked out */
  2202   2207     u8 nColCache;        /* Number of entries in aColCache[] */
  2203   2208     u8 iColCache;        /* Next entry in aColCache[] to replace */
  2204   2209     u8 isMultiWrite;     /* True if statement may modify/insert multiple rows */
  2205   2210     u8 mayAbort;         /* True if statement may throw an ABORT exception */
         2211  +  u8 hasCompound;      /* Need to invoke convertCompoundSelectToSubquery() */
  2206   2212     int aTempReg[8];     /* Holding area for temporary registers */
  2207   2213     int nRangeReg;       /* Size of the temporary register block */
  2208   2214     int iRangeReg;       /* First register in temporary register block */
  2209   2215     int nErr;            /* Number of errors seen */
  2210   2216     int nTab;            /* Number of previously allocated VDBE cursors */
  2211   2217     int nMem;            /* Number of memory cells used so far */
  2212   2218     int nSet;            /* Number of sets used so far */
................................................................................
  3094   3100   void sqlite3DefaultRowEst(Index*);
  3095   3101   void sqlite3RegisterLikeFunctions(sqlite3*, int);
  3096   3102   int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
  3097   3103   void sqlite3MinimumFileFormat(Parse*, int, int);
  3098   3104   void sqlite3SchemaClear(void *);
  3099   3105   Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
  3100   3106   int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
         3107  +KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int);
  3101   3108   KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
  3102   3109   int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, 
  3103   3110     void (*)(sqlite3_context*,int,sqlite3_value **),
  3104   3111     void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
  3105   3112     FuncDestructor *pDestructor
  3106   3113   );
  3107   3114   int sqlite3ApiExit(sqlite3 *db, int);

Changes to src/test_rtree.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing all sorts of SQLite interfaces. This code
    13     13   ** is not included in the SQLite library. 
    14     14   */
    15     15   
    16     16   #include <sqlite3.h>
           17  +#include <tcl.h>
    17     18   
    18     19   /* Solely for the UNUSED_PARAMETER() macro. */
    19     20   #include "sqliteInt.h"
    20     21   
    21     22   #ifdef SQLITE_ENABLE_RTREE
    22     23   /* 
    23     24   ** Type used to cache parameter information for the "circle" r-tree geometry

Changes to src/tokenize.c.

   119    119         testcase( z[0]=='\r' );
   120    120         for(i=1; sqlite3Isspace(z[i]); i++){}
   121    121         *tokenType = TK_SPACE;
   122    122         return i;
   123    123       }
   124    124       case '-': {
   125    125         if( z[1]=='-' ){
   126         -        /* IMP: R-50417-27976 -- syntax diagram for comments */
   127    126           for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
   128    127           *tokenType = TK_SPACE;   /* IMP: R-22934-25134 */
   129    128           return i;
   130    129         }
   131    130         *tokenType = TK_MINUS;
   132    131         return 1;
   133    132       }
................................................................................
   152    151         return 1;
   153    152       }
   154    153       case '/': {
   155    154         if( z[1]!='*' || z[2]==0 ){
   156    155           *tokenType = TK_SLASH;
   157    156           return 1;
   158    157         }
   159         -      /* IMP: R-50417-27976 -- syntax diagram for comments */
   160    158         for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){}
   161    159         if( c ) i++;
   162    160         *tokenType = TK_SPACE;   /* IMP: R-22934-25134 */
   163    161         return i;
   164    162       }
   165    163       case '%': {
   166    164         *tokenType = TK_REM;

Changes to src/vdbe.c.

   561    561     int rc = SQLITE_OK;        /* Value to return */
   562    562     sqlite3 *db = p->db;       /* The database */
   563    563     u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
   564    564     u8 encoding = ENC(db);     /* The database encoding */
   565    565     int iCompare = 0;          /* Result of last OP_Compare operation */
   566    566     unsigned nVmStep = 0;      /* Number of virtual machine steps */
   567    567   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   568         -  unsigned nProgressLimit;   /* Invoke xProgress() when nVmStep reaches this */
          568  +  unsigned nProgressLimit = 0;/* Invoke xProgress() when nVmStep reaches this */
   569    569   #endif
   570    570     Mem *aMem = p->aMem;       /* Copy of p->aMem */
   571    571     Mem *pIn1 = 0;             /* 1st input operand */
   572    572     Mem *pIn2 = 0;             /* 2nd input operand */
   573    573     Mem *pIn3 = 0;             /* 3rd input operand */
   574    574     Mem *pOut = 0;             /* Output operand */
   575    575     int *aPermute = 0;         /* Permutation of columns for OP_Compare */

Changes to src/vdbeaux.c.

   404    404     Op *pOp;
   405    405     int *aLabel = p->aLabel;
   406    406     p->readOnly = 1;
   407    407     p->bIsReader = 0;
   408    408     for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
   409    409       u8 opcode = pOp->opcode;
   410    410   
   411         -    pOp->opflags = sqlite3OpcodeProperty[opcode];
   412         -    if( opcode==OP_Function || opcode==OP_AggStep ){
   413         -      if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
   414         -    }else if( opcode==OP_Transaction ){
   415         -      if( pOp->p2!=0 ) p->readOnly = 0;
   416         -      p->bIsReader = 1;
   417         -    }else if( opcode==OP_AutoCommit || opcode==OP_Savepoint ){
   418         -      p->bIsReader = 1;
   419         -    }else if( opcode==OP_Vacuum
   420         -           || opcode==OP_JournalMode
          411  +    /* NOTE: Be sure to update mkopcodeh.awk when adding or removing
          412  +    ** cases from this switch! */
          413  +    switch( opcode ){
          414  +      case OP_Function:
          415  +      case OP_AggStep: {
          416  +        if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
          417  +        break;
          418  +      }
          419  +      case OP_Transaction: {
          420  +        if( pOp->p2!=0 ) p->readOnly = 0;
          421  +        /* fall thru */
          422  +      }
          423  +      case OP_AutoCommit:
          424  +      case OP_Savepoint: {
          425  +        p->bIsReader = 1;
          426  +        break;
          427  +      }
   421    428   #ifndef SQLITE_OMIT_WAL
   422         -           || opcode==OP_Checkpoint
          429  +      case OP_Checkpoint:
   423    430   #endif
   424         -    ){
   425         -      p->readOnly = 0;
   426         -      p->bIsReader = 1;
          431  +      case OP_Vacuum:
          432  +      case OP_JournalMode: {
          433  +        p->readOnly = 0;
          434  +        p->bIsReader = 1;
          435  +        break;
          436  +      }
   427    437   #ifndef SQLITE_OMIT_VIRTUALTABLE
   428         -    }else if( opcode==OP_VUpdate ){
   429         -      if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
   430         -    }else if( opcode==OP_VFilter ){
   431         -      int n;
   432         -      assert( p->nOp - i >= 3 );
   433         -      assert( pOp[-1].opcode==OP_Integer );
   434         -      n = pOp[-1].p1;
   435         -      if( n>nMaxArgs ) nMaxArgs = n;
   436         -#endif
   437         -    }else if( opcode==OP_Next || opcode==OP_SorterNext ){
   438         -      pOp->p4.xAdvance = sqlite3BtreeNext;
   439         -      pOp->p4type = P4_ADVANCE;
   440         -    }else if( opcode==OP_Prev ){
   441         -      pOp->p4.xAdvance = sqlite3BtreePrevious;
   442         -      pOp->p4type = P4_ADVANCE;
   443         -    }
   444         -
          438  +      case OP_VUpdate: {
          439  +        if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
          440  +        break;
          441  +      }
          442  +      case OP_VFilter: {
          443  +        int n;
          444  +        assert( p->nOp - i >= 3 );
          445  +        assert( pOp[-1].opcode==OP_Integer );
          446  +        n = pOp[-1].p1;
          447  +        if( n>nMaxArgs ) nMaxArgs = n;
          448  +        break;
          449  +      }
          450  +#endif
          451  +      case OP_Next:
          452  +      case OP_SorterNext: {
          453  +        pOp->p4.xAdvance = sqlite3BtreeNext;
          454  +        pOp->p4type = P4_ADVANCE;
          455  +        break;
          456  +      }
          457  +      case OP_Prev: {
          458  +        pOp->p4.xAdvance = sqlite3BtreePrevious;
          459  +        pOp->p4type = P4_ADVANCE;
          460  +        break;
          461  +      }
          462  +    }
          463  +
          464  +    pOp->opflags = sqlite3OpcodeProperty[opcode];
   445    465       if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
   446    466         assert( -1-pOp->p2<p->nLabel );
   447    467         pOp->p2 = aLabel[-1-pOp->p2];
   448    468       }
   449    469     }
   450    470     sqlite3DbFree(p->db, p->aLabel);
   451    471     p->aLabel = 0;
................................................................................
   726    746       ** that was cast to a (const char *). */
   727    747       pOp->p4.i = SQLITE_PTR_TO_INT(zP4);
   728    748       pOp->p4type = P4_INT32;
   729    749     }else if( zP4==0 ){
   730    750       pOp->p4.p = 0;
   731    751       pOp->p4type = P4_NOTUSED;
   732    752     }else if( n==P4_KEYINFO ){
   733         -    KeyInfo *pKeyInfo;
   734         -    int nField, nByte;
          753  +    KeyInfo *pOrig, *pNew;
   735    754   
   736         -    nField = ((KeyInfo*)zP4)->nField;
   737         -    nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
   738         -    pKeyInfo = sqlite3DbMallocRaw(0, nByte);
   739         -    pOp->p4.pKeyInfo = pKeyInfo;
   740         -    if( pKeyInfo ){
   741         -      u8 *aSortOrder;
   742         -      memcpy((char*)pKeyInfo, zP4, nByte - nField);
   743         -      aSortOrder = pKeyInfo->aSortOrder;
   744         -      assert( aSortOrder!=0 );
   745         -      pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
   746         -      memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
          755  +    pOrig = (KeyInfo*)zP4;
          756  +    pOp->p4.pKeyInfo = pNew = sqlite3KeyInfoAlloc(db, pOrig->nField);
          757  +    if( pNew ){
          758  +      memcpy(pNew->aColl, pOrig->aColl, pOrig->nField*sizeof(pNew->aColl[0]));
          759  +      memcpy(pNew->aSortOrder, pOrig->aSortOrder, pOrig->nField);
   747    760         pOp->p4type = P4_KEYINFO;
   748    761       }else{
   749    762         p->db->mallocFailed = 1;
   750    763         pOp->p4type = P4_NOTUSED;
   751    764       }
   752    765     }else if( n==P4_KEYINFO_HANDOFF ){
   753    766       pOp->p4.p = (void*)zP4;
................................................................................
  2991   3004     int nKey1, const void *pKey1, /* Left key */
  2992   3005     UnpackedRecord *pPKey2        /* Right key */
  2993   3006   ){
  2994   3007     u32 d1;            /* Offset into aKey[] of next data element */
  2995   3008     u32 idx1;          /* Offset into aKey[] of next header element */
  2996   3009     u32 szHdr1;        /* Number of bytes in header */
  2997   3010     int i = 0;
  2998         -  int nField;
  2999   3011     int rc = 0;
  3000   3012     const unsigned char *aKey1 = (const unsigned char *)pKey1;
  3001   3013     KeyInfo *pKeyInfo;
  3002   3014     Mem mem1;
  3003   3015   
  3004   3016     pKeyInfo = pPKey2->pKeyInfo;
  3005   3017     mem1.enc = pKeyInfo->enc;
................................................................................
  3014   3026     ** impact, since this routine is a very high runner.  And so, we choose
  3015   3027     ** to ignore the compiler warnings and leave this variable uninitialized.
  3016   3028     */
  3017   3029     /*  mem1.u.i = 0;  // not needed, here to silence compiler warning */
  3018   3030     
  3019   3031     idx1 = getVarint32(aKey1, szHdr1);
  3020   3032     d1 = szHdr1;
  3021         -  nField = pKeyInfo->nField;
         3033  +  assert( pKeyInfo->nField+1>=pPKey2->nField );
  3022   3034     assert( pKeyInfo->aSortOrder!=0 );
  3023   3035     while( idx1<szHdr1 && i<pPKey2->nField ){
  3024   3036       u32 serial_type1;
  3025   3037   
  3026   3038       /* Read the serial types for the next element in each key. */
  3027   3039       idx1 += getVarint32( aKey1+idx1, serial_type1 );
  3028         -    if( d1+sqlite3VdbeSerialTypeLen(serial_type1)>(u32)nKey1 ) break;
         3040  +
         3041  +    /* Verify that there is enough key space remaining to avoid
         3042  +    ** a buffer overread.  The "d1+serial_type1+2" subexpression will
         3043  +    ** always be greater than or equal to the amount of required key space.
         3044  +    ** Use that approximation to avoid the more expensive call to
         3045  +    ** sqlite3VdbeSerialTypeLen() in the common case.
         3046  +    */
         3047  +    if( d1+serial_type1+2>(u32)nKey1
         3048  +     && d1+sqlite3VdbeSerialTypeLen(serial_type1)>(u32)nKey1 
         3049  +    ){
         3050  +      break;
         3051  +    }
  3029   3052   
  3030   3053       /* Extract the values to be compared.
  3031   3054       */
  3032   3055       d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
  3033   3056   
  3034   3057       /* Do the comparison
  3035   3058       */
  3036         -    rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
  3037         -                           i<nField ? pKeyInfo->aColl[i] : 0);
         3059  +    rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
  3038   3060       if( rc!=0 ){
  3039   3061         assert( mem1.zMalloc==0 );  /* See comment below */
  3040   3062   
  3041   3063         /* Invert the result if we are using DESC sort order. */
  3042         -      if( i<nField && pKeyInfo->aSortOrder[i] ){
         3064  +      if( pKeyInfo->aSortOrder[i] ){
  3043   3065           rc = -rc;
  3044   3066         }
  3045   3067       
  3046   3068         /* If the PREFIX_SEARCH flag is set and all fields except the final
  3047   3069         ** rowid field were equal, then clear the PREFIX_SEARCH flag and set 
  3048   3070         ** pPKey2->rowid to the value of the rowid field in (pKey1, nKey1).
  3049   3071         ** This is used by the OP_IsUnique opcode.

Changes to src/where.c.

   654    654   ** WhereTerms.  All pointers to WhereTerms should be invalidated after
   655    655   ** calling this routine.  Such pointers may be reinitialized by referencing
   656    656   ** the pWC->a[] array.
   657    657   */
   658    658   static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){
   659    659     WhereTerm *pTerm;
   660    660     int idx;
   661         -  testcase( wtFlags & TERM_VIRTUAL );  /* EV: R-00211-15100 */
          661  +  testcase( wtFlags & TERM_VIRTUAL );
   662    662     if( pWC->nTerm>=pWC->nSlot ){
   663    663       WhereTerm *pOld = pWC->a;
   664    664       sqlite3 *db = pWC->pWInfo->pParse->db;
   665    665       pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
   666    666       if( pWC->a==0 ){
   667    667         if( wtFlags & TERM_DYNAMIC ){
   668    668           sqlite3ExprDelete(db, p);
................................................................................
   799    799     return mask;
   800    800   }
   801    801   
   802    802   /*
   803    803   ** Return TRUE if the given operator is one of the operators that is
   804    804   ** allowed for an indexable WHERE clause term.  The allowed operators are
   805    805   ** "=", "<", ">", "<=", ">=", "IN", and "IS NULL"
   806         -**
   807         -** IMPLEMENTATION-OF: R-59926-26393 To be usable by an index a term must be
   808         -** of one of the following forms: column = expression column > expression
   809         -** column >= expression column < expression column <= expression
   810         -** expression = column expression > column expression >= column
   811         -** expression < column expression <= column column IN
   812         -** (expression-list) column IN (subquery) column IS NULL
   813    806   */
   814    807   static int allowedOp(int op){
   815    808     assert( TK_GT>TK_EQ && TK_GT<TK_GE );
   816    809     assert( TK_LT>TK_EQ && TK_LT<TK_GE );
   817    810     assert( TK_LE>TK_EQ && TK_LE<TK_GE );
   818    811     assert( TK_GE==TK_EQ+4 );
   819    812     return op==TK_IN || (op>=TK_EQ && op<=TK_GE) || op==TK_ISNULL;
................................................................................
  1479   1472           }
  1480   1473         }
  1481   1474       }
  1482   1475   
  1483   1476       /* At this point, okToChngToIN is true if original pTerm satisfies
  1484   1477       ** case 1.  In that case, construct a new virtual term that is 
  1485   1478       ** pTerm converted into an IN operator.
  1486         -    **
  1487         -    ** EV: R-00211-15100
  1488   1479       */
  1489   1480       if( okToChngToIN ){
  1490   1481         Expr *pDup;            /* A transient duplicate expression */
  1491   1482         ExprList *pList = 0;   /* The RHS of the IN operator */
  1492   1483         Expr *pLeft = 0;       /* The LHS of the IN operator */
  1493   1484         Expr *pNew;            /* The complete IN operator */
  1494   1485   
................................................................................
  1722   1713         if( noCase ){
  1723   1714           /* The point is to increment the last character before the first
  1724   1715           ** wildcard.  But if we increment '@', that will push it into the
  1725   1716           ** alphabetic range where case conversions will mess up the 
  1726   1717           ** inequality.  To avoid this, make sure to also run the full
  1727   1718           ** LIKE on all candidate expressions by clearing the isComplete flag
  1728   1719           */
  1729         -        if( c=='A'-1 ) isComplete = 0;   /* EV: R-64339-08207 */
  1730         -
  1731         -
         1720  +        if( c=='A'-1 ) isComplete = 0;
  1732   1721           c = sqlite3UpperToLower[c];
  1733   1722         }
  1734   1723         *pC = c + 1;
  1735   1724       }
  1736   1725       sCollSeqName.z = noCase ? "NOCASE" : "BINARY";
  1737   1726       sCollSeqName.n = 6;
  1738   1727       pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
................................................................................
  2814   2803   **   (2)  SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.x AND t2.z='ok'
  2815   2804   **   (3)  SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok'
  2816   2805   **
  2817   2806   ** The t2.z='ok' is disabled in the in (2) because it originates
  2818   2807   ** in the ON clause.  The term is disabled in (3) because it is not part
  2819   2808   ** of a LEFT OUTER JOIN.  In (1), the term is not disabled.
  2820   2809   **
  2821         -** IMPLEMENTATION-OF: R-24597-58655 No tests are done for terms that are
  2822         -** completely satisfied by indices.
  2823         -**
  2824   2810   ** Disabling a term causes that term to not be tested in the inner loop
  2825   2811   ** of the join.  Disabling is an optimization.  When terms are satisfied
  2826   2812   ** by indices, we disable them to prevent redundant tests in the inner
  2827   2813   ** loop.  We would get the correct results if nothing were ever disabled,
  2828   2814   ** but joins might run a little slower.  The trick is to disable as much
  2829   2815   ** as we can without disabling too much.  If we disabled in (1), we'd get
  2830   2816   ** the wrong answer.  See ticket #813.
................................................................................
  3046   3032     for(j=0; j<nEq; j++){
  3047   3033       int r1;
  3048   3034       pTerm = pLoop->aLTerm[j];
  3049   3035       assert( pTerm!=0 );
  3050   3036       /* The following true for indices with redundant columns. 
  3051   3037       ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
  3052   3038       testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
  3053         -    testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
         3039  +    testcase( pTerm->wtFlags & TERM_VIRTUAL );
  3054   3040       r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
  3055   3041       if( r1!=regBase+j ){
  3056   3042         if( nReg==1 ){
  3057   3043           sqlite3ReleaseTempReg(pParse, regBase);
  3058   3044           regBase = r1;
  3059   3045         }else{
  3060   3046           sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
................................................................................
  3357   3343       */
  3358   3344       assert( pLoop->u.btree.nEq==1 );
  3359   3345       iReleaseReg = sqlite3GetTempReg(pParse);
  3360   3346       pTerm = pLoop->aLTerm[0];
  3361   3347       assert( pTerm!=0 );
  3362   3348       assert( pTerm->pExpr!=0 );
  3363   3349       assert( omitTable==0 );
  3364         -    testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
         3350  +    testcase( pTerm->wtFlags & TERM_VIRTUAL );
  3365   3351       iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
  3366   3352       addrNxt = pLevel->addrNxt;
  3367   3353       sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
  3368   3354       sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
  3369   3355       sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
  3370   3356       sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
  3371   3357       VdbeComment((v, "pk"));
................................................................................
  3405   3391              /* TK_GE */  OP_SeekGe
  3406   3392         };
  3407   3393         assert( TK_LE==TK_GT+1 );      /* Make sure the ordering.. */
  3408   3394         assert( TK_LT==TK_GT+2 );      /*  ... of the TK_xx values... */
  3409   3395         assert( TK_GE==TK_GT+3 );      /*  ... is correcct. */
  3410   3396   
  3411   3397         assert( (pStart->wtFlags & TERM_VNULL)==0 );
  3412         -      testcase( pStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
         3398  +      testcase( pStart->wtFlags & TERM_VIRTUAL );
  3413   3399         pX = pStart->pExpr;
  3414   3400         assert( pX!=0 );
  3415   3401         testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
  3416   3402         r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
  3417   3403         sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
  3418   3404         VdbeComment((v, "pk"));
  3419   3405         sqlite3ExprCacheAffinityChange(pParse, r1, 1);
................................................................................
  3424   3410       }
  3425   3411       if( pEnd ){
  3426   3412         Expr *pX;
  3427   3413         pX = pEnd->pExpr;
  3428   3414         assert( pX!=0 );
  3429   3415         assert( (pEnd->wtFlags & TERM_VNULL)==0 );
  3430   3416         testcase( pEnd->leftCursor!=iCur ); /* Transitive constraints */
  3431         -      testcase( pEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
         3417  +      testcase( pEnd->wtFlags & TERM_VIRTUAL );
  3432   3418         memEndValue = ++pParse->nMem;
  3433   3419         sqlite3ExprCode(pParse, pX->pRight, memEndValue);
  3434   3420         if( pX->op==TK_LT || pX->op==TK_GT ){
  3435   3421           testOp = bRev ? OP_Le : OP_Ge;
  3436   3422         }else{
  3437   3423           testOp = bRev ? OP_Lt : OP_Gt;
  3438   3424         }
................................................................................
  3590   3576             zStartAff[nEq] = SQLITE_AFF_NONE;
  3591   3577           }
  3592   3578           if( sqlite3ExprNeedsNoAffinityChange(pRight, zStartAff[nEq]) ){
  3593   3579             zStartAff[nEq] = SQLITE_AFF_NONE;
  3594   3580           }
  3595   3581         }  
  3596   3582         nConstraint++;
  3597         -      testcase( pRangeStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
         3583  +      testcase( pRangeStart->wtFlags & TERM_VIRTUAL );
  3598   3584       }else if( isMinQuery ){
  3599   3585         sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
  3600   3586         nConstraint++;
  3601   3587         startEq = 0;
  3602   3588         start_constraints = 1;
  3603   3589       }
  3604   3590       codeApplyAffinity(pParse, regBase, nConstraint, zStartAff);
................................................................................
  3632   3618           }
  3633   3619           if( sqlite3ExprNeedsNoAffinityChange(pRight, zEndAff[nEq]) ){
  3634   3620             zEndAff[nEq] = SQLITE_AFF_NONE;
  3635   3621           }
  3636   3622         }  
  3637   3623         codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
  3638   3624         nConstraint++;
  3639         -      testcase( pRangeEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
         3625  +      testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
  3640   3626       }
  3641   3627       sqlite3DbFree(db, zStartAff);
  3642   3628       sqlite3DbFree(db, zEndAff);
  3643   3629   
  3644   3630       /* Top of the loop body */
  3645   3631       pLevel->p2 = sqlite3VdbeCurrentAddr(v);
  3646   3632   
................................................................................
  3919   3905       pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
  3920   3906       pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
  3921   3907     }
  3922   3908     newNotReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
  3923   3909   
  3924   3910     /* Insert code to test every subexpression that can be completely
  3925   3911     ** computed using the current set of tables.
  3926         -  **
  3927         -  ** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through
  3928         -  ** the use of indices become tests that are evaluated against each row of
  3929         -  ** the relevant input tables.
  3930   3912     */
  3931   3913     for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
  3932   3914       Expr *pE;
  3933         -    testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */
         3915  +    testcase( pTerm->wtFlags & TERM_VIRTUAL );
  3934   3916       testcase( pTerm->wtFlags & TERM_CODED );
  3935   3917       if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
  3936   3918       if( (pTerm->prereqAll & newNotReady)!=0 ){
  3937   3919         testcase( pWInfo->untestedTerms==0
  3938   3920                  && (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
  3939   3921         pWInfo->untestedTerms = 1;
  3940   3922         continue;
................................................................................
  3986   3968     */
  3987   3969     if( pLevel->iLeftJoin ){
  3988   3970       pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
  3989   3971       sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
  3990   3972       VdbeComment((v, "record LEFT JOIN hit"));
  3991   3973       sqlite3ExprCacheClear(pParse);
  3992   3974       for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
  3993         -      testcase( pTerm->wtFlags & TERM_VIRTUAL );  /* IMP: R-30575-11662 */
         3975  +      testcase( pTerm->wtFlags & TERM_VIRTUAL );
  3994   3976         testcase( pTerm->wtFlags & TERM_CODED );
  3995   3977         if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
  3996   3978         if( (pTerm->prereqAll & newNotReady)!=0 ){
  3997   3979           assert( pWInfo->untestedTerms );
  3998   3980           continue;
  3999   3981         }
  4000   3982         assert( pTerm->pExpr );
................................................................................
  5759   5741   
  5760   5742     /* Split the WHERE clause into separate subexpressions where each
  5761   5743     ** subexpression is separated by an AND operator.
  5762   5744     */
  5763   5745     initMaskSet(pMaskSet);
  5764   5746     whereClauseInit(&pWInfo->sWC, pWInfo);
  5765   5747     sqlite3ExprCodeConstants(pParse, pWhere);
  5766         -  whereSplit(&pWInfo->sWC, pWhere, TK_AND);   /* IMP: R-15842-53296 */
         5748  +  whereSplit(&pWInfo->sWC, pWhere, TK_AND);
  5767   5749     sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
  5768   5750       
  5769   5751     /* Special case: a WHERE clause that is constant.  Evaluate the
  5770   5752     ** expression and either jump over all of the code or fall thru.
  5771   5753     */
  5772   5754     if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
  5773   5755       sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL);

Changes to test/e_createtable.test.

    54     54         db eval "SELECT DISTINCT tbl_name FROM $master ORDER BY tbl_name"
    55     55       ]
    56     56     }
    57     57     set res
    58     58   }
    59     59   
    60     60   
    61         -# EVIDENCE-OF: R-47266-09114 -- syntax diagram type-name
    62         -#
    63     61   do_createtable_tests 0.1.1 -repair {
    64     62     drop_all_tables
    65     63   } {
    66     64     1   "CREATE TABLE t1(c1 one)"                        {}
    67     65     2   "CREATE TABLE t1(c1 one two)"                    {}
    68     66     3   "CREATE TABLE t1(c1 one two three)"              {}
    69     67     4   "CREATE TABLE t1(c1 one two three four)"         {}
................................................................................
    75     73   do_createtable_tests 0.1.2 -error {
    76     74     near "%s": syntax error
    77     75   } {
    78     76     1   "CREATE TABLE t1(c1 one(number))"                {number}
    79     77   }
    80     78   
    81     79   
    82         -# EVIDENCE-OF: R-60689-48779 -- syntax diagram column-constraint
           80  +# syntax diagram column-constraint
    83     81   #
    84     82   do_createtable_tests 0.2.1 -repair {
    85     83     drop_all_tables 
    86     84     execsql { CREATE TABLE t2(x PRIMARY KEY) }
    87     85   } {
    88     86     1.1   "CREATE TABLE t1(c1 text PRIMARY KEY)"                         {}
    89     87     1.2   "CREATE TABLE t1(c1 text PRIMARY KEY ASC)"                     {}
................................................................................
   122    120     8.2   {
   123    121       CREATE TABLE t1(c1 
   124    122         REFERENCES t1 DEFAULT 123 CHECK(c1 IS 'ten') UNIQUE NOT NULL PRIMARY KEY 
   125    123       );
   126    124     } {}
   127    125   }
   128    126   
   129         -# EVIDENCE-OF: R-58169-51804 -- syntax diagram table-constraint
          127  +# -- syntax diagram table-constraint
   130    128   #
   131    129   do_createtable_tests 0.3.1 -repair {
   132    130     drop_all_tables 
   133    131     execsql { CREATE TABLE t2(x PRIMARY KEY) }
   134    132   } {
   135    133     1.1   "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1))"                         {}
   136    134     1.2   "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2))"                     {}
................................................................................
   141    139     2.3   "CREATE TABLE t1(c1, c2, UNIQUE(c1, c2) ON CONFLICT IGNORE)"       {}
   142    140   
   143    141     3.1   "CREATE TABLE t1(c1, c2, CHECK(c1 IS NOT c2))"                     {}
   144    142   
   145    143     4.1   "CREATE TABLE t1(c1, c2, FOREIGN KEY(c1) REFERENCES t2)"           {}
   146    144   }
   147    145   
   148         -# EVIDENCE-OF: R-44826-22243 -- syntax diagram column-def
          146  +# -- syntax diagram column-def
   149    147   #
   150    148   do_createtable_tests 0.4.1 -repair {
   151    149     drop_all_tables 
   152    150   } {
   153    151     1     {CREATE TABLE t1(
   154    152              col1,
   155    153              col2 TEXT,
................................................................................
   156    154              col3 INTEGER UNIQUE,
   157    155              col4 VARCHAR(10, 10) PRIMARY KEY,
   158    156              "name with spaces" REFERENCES t1
   159    157            );
   160    158           } {}
   161    159   }
   162    160   
   163         -# EVIDENCE-OF: R-45698-45677 -- syntax diagram create-table-stmt
          161  +# -- syntax diagram create-table-stmt
   164    162   #
   165    163   do_createtable_tests 0.5.1 -repair {
   166    164     drop_all_tables 
   167    165     execsql { CREATE TABLE t2(a, b, c) }
   168    166   } {
   169    167     1     "CREATE TABLE t1(a, b, c)"                                    {}
   170    168     2     "CREATE TEMP TABLE t1(a, b, c)"                               {}
................................................................................
   181    179     12    "CREATE TEMPORARY TABLE IF NOT EXISTS temp.t1(a, b, c)"       {}
   182    180   
   183    181     13    "CREATE TABLE t1 AS SELECT * FROM t2"                         {}
   184    182     14    "CREATE TEMP TABLE t1 AS SELECT c, b, a FROM t2"              {}
   185    183     15    "CREATE TABLE t1 AS SELECT count(*), max(b), min(a) FROM t2"  {}
   186    184   }
   187    185   
   188         -# EVIDENCE-OF: R-24369-11919 -- syntax diagram foreign-key-clause
   189    186   #
   190    187   #   1:         Explicit parent-key columns.
   191    188   #   2:         Implicit child-key columns.
   192    189   #
   193    190   #   1:         MATCH FULL
   194    191   #   2:         MATCH PARTIAL
   195    192   #   3:         MATCH SIMPLE

Changes to test/e_delete.test.

    25     25   }
    26     26   
    27     27   do_execsql_test e_delete-0.0 {
    28     28     CREATE TABLE t1(a, b);
    29     29     CREATE INDEX i1 ON t1(a);
    30     30   } {}
    31     31   
    32         -# EVIDENCE-OF: R-62077-19799 -- syntax diagram delete-stmt
    33         -#
    34         -# EVIDENCE-OF: R-60796-31013 -- syntax diagram qualified-table-name
           32  +# -- syntax diagram delete-stmt
           33  +# -- syntax diagram qualified-table-name
    35     34   #
    36     35   do_delete_tests e_delete-0.1 {
    37     36     1  "DELETE FROM t1"                              {}
    38     37     2  "DELETE FROM t1 INDEXED BY i1"                {}
    39     38     3  "DELETE FROM t1 NOT INDEXED"                  {}
    40     39     4  "DELETE FROM main.t1"                         {}
    41     40     5  "DELETE FROM main.t1 INDEXED BY i1"           {}
................................................................................
   288    287   }
   289    288   
   290    289   # EVIDENCE-OF: R-40026-10531 If SQLite is compiled with the
   291    290   # SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option, then the syntax
   292    291   # of the DELETE statement is extended by the addition of optional ORDER
   293    292   # BY and LIMIT clauses:
   294    293   #
   295         -# EVIDENCE-OF: R-52694-53361 -- syntax diagram delete-stmt-limited
          294  +# -- syntax diagram delete-stmt-limited
   296    295   #
   297    296   do_delete_tests e_delete-3.1 {
   298    297     1   "DELETE FROM t1 LIMIT 5"                                    {}
   299    298     2   "DELETE FROM t1 LIMIT 5-1 OFFSET 2+2"                       {}
   300    299     3   "DELETE FROM t1 LIMIT 2+2, 16/4"                            {}
   301    300     4   "DELETE FROM t1 ORDER BY x LIMIT 5"                         {}
   302    301     5   "DELETE FROM t1 ORDER BY x LIMIT 5-1 OFFSET 2+2"            {}

Changes to test/e_droptrigger.test.

    65     65       CREATE TRIGGER aux.tr1 BEFORE $event ON t3 BEGIN SELECT r('aux.tr1') ; END;
    66     66       CREATE TRIGGER aux.tr2 AFTER  $event ON t3 BEGIN SELECT r('aux.tr2') ; END;
    67     67       CREATE TRIGGER aux.tr3 AFTER  $event ON t3 BEGIN SELECT r('aux.tr3') ; END;
    68     68     "
    69     69   }
    70     70   
    71     71   
    72         -# EVIDENCE-OF: R-27975-10951 -- syntax diagram drop-trigger-stmt
           72  +# -- syntax diagram drop-trigger-stmt
    73     73   #
    74     74   do_droptrigger_tests 1.1 -repair {
    75     75     droptrigger_reopen_db
    76     76   } -tclquery {
    77     77     list_all_triggers 
    78     78   } {
    79     79     1   "DROP TRIGGER main.tr1"            

Changes to test/e_dropview.test.

    66     66     set res
    67     67   }
    68     68   
    69     69   proc do_dropview_tests {nm args} {
    70     70     uplevel do_select_tests $nm $args
    71     71   }
    72     72   
    73         -# EVIDENCE-OF: R-53136-36436 -- syntax diagram drop-view-stmt
           73  +# -- syntax diagram drop-view-stmt
    74     74   #
    75     75   # All paths in the syntax diagram for DROP VIEW are tested by tests 1.*.
    76     76   #
    77     77   do_dropview_tests 1 -repair {
    78     78     dropview_reopen_db
    79     79   } -tclquery {
    80     80     list_all_views

Changes to test/e_expr.test.

   362    362     string compare [reverse_str $zLeft] [reverse_str $zRight]
   363    363   }
   364    364   db collate reverse reverse_collate
   365    365   
   366    366   # EVIDENCE-OF: R-59577-33471 The COLLATE operator is a unary postfix
   367    367   # operator that assigns a collating sequence to an expression.
   368    368   #
   369         -# EVIDENCE-OF: R-23441-22541 The COLLATE operator has a higher
   370         -# precedence (binds more tightly) than any prefix unary operator or any
   371         -# binary operator.
          369  +# EVIDENCE-OF: R-36231-30731 The COLLATE operator has a higher
          370  +# precedence (binds more tightly) than any binary operator and any unary
          371  +# prefix operator except "~".
   372    372   #
   373    373   do_execsql_test e_expr-9.1 { SELECT  'abcd' < 'bbbb'    COLLATE reverse } 0
   374    374   do_execsql_test e_expr-9.2 { SELECT ('abcd' < 'bbbb')   COLLATE reverse } 1
   375    375   do_execsql_test e_expr-9.3 { SELECT  'abcd' <= 'bbbb'   COLLATE reverse } 0
   376    376   do_execsql_test e_expr-9.4 { SELECT ('abcd' <= 'bbbb')  COLLATE reverse } 1
   377    377   
   378    378   do_execsql_test e_expr-9.5 { SELECT  'abcd' > 'bbbb'    COLLATE reverse } 1
................................................................................
   627    627          [sqlite3_column_type $stmt 3] 
   628    628   } {NULL NULL NULL NULL}
   629    629   do_test e_expr-11.7.1 { sqlite3_finalize $stmt } SQLITE_OK
   630    630   
   631    631   #-------------------------------------------------------------------------
   632    632   # "Test" the syntax diagrams in lang_expr.html.
   633    633   #
   634         -# EVIDENCE-OF: R-02989-21050 -- syntax diagram signed-number
          634  +# -- syntax diagram signed-number
   635    635   #
   636    636   do_execsql_test e_expr-12.1.1 { SELECT 0, +0, -0 } {0 0 0}
   637    637   do_execsql_test e_expr-12.1.2 { SELECT 1, +1, -1 } {1 1 -1}
   638    638   do_execsql_test e_expr-12.1.3 { SELECT 2, +2, -2 } {2 2 -2}
   639    639   do_execsql_test e_expr-12.1.4 { 
   640    640     SELECT 1.4, +1.4, -1.4 
   641    641   } {1.4 1.4 -1.4}
................................................................................
   642    642   do_execsql_test e_expr-12.1.5 { 
   643    643     SELECT 1.5e+5, +1.5e+5, -1.5e+5 
   644    644   } {150000.0 150000.0 -150000.0}
   645    645   do_execsql_test e_expr-12.1.6 { 
   646    646     SELECT 0.0001, +0.0001, -0.0001 
   647    647   } {0.0001 0.0001 -0.0001}
   648    648   
   649         -# EVIDENCE-OF: R-43188-60852 -- syntax diagram literal-value
          649  +# -- syntax diagram literal-value
   650    650   #
   651    651   set sqlite_current_time 1
   652    652   do_execsql_test e_expr-12.2.1 {SELECT 123}               {123}
   653    653   do_execsql_test e_expr-12.2.2 {SELECT 123.4e05}          {12340000.0}
   654    654   do_execsql_test e_expr-12.2.3 {SELECT 'abcde'}           {abcde}
   655    655   do_execsql_test e_expr-12.2.4 {SELECT X'414243'}         {ABC}
   656    656   do_execsql_test e_expr-12.2.5 {SELECT NULL}              {{}}
   657    657   do_execsql_test e_expr-12.2.6 {SELECT CURRENT_TIME}      {00:00:01}
   658    658   do_execsql_test e_expr-12.2.7 {SELECT CURRENT_DATE}      {1970-01-01}
   659    659   do_execsql_test e_expr-12.2.8 {SELECT CURRENT_TIMESTAMP} {{1970-01-01 00:00:01}}
   660    660   set sqlite_current_time 0
   661    661   
   662         -# EVIDENCE-OF: R-50544-32159 -- syntax diagram expr
          662  +# -- syntax diagram expr
   663    663   #
   664    664   forcedelete test.db2
   665    665   execsql {
   666    666     ATTACH 'test.db2' AS dbname;
   667    667     CREATE TABLE dbname.tblname(cname);
   668    668   }
   669    669   
................................................................................
   812    812       incr x
   813    813       do_test e_expr-12.3.$tn.$x { 
   814    814         set rc [catch { execsql "SELECT $e FROM tblname" } msg]
   815    815       } {0}
   816    816     }
   817    817   }
   818    818   
   819         -# EVIDENCE-OF: R-39820-63916 -- syntax diagram raise-function
          819  +# -- syntax diagram raise-function
   820    820   #
   821    821   foreach {tn raiseexpr} {
   822    822     1 "RAISE(IGNORE)"
   823    823     2 "RAISE(ROLLBACK, 'error message')"
   824    824     3 "RAISE(ABORT, 'error message')"
   825    825     4 "RAISE(FAIL, 'error message')"
   826    826   } {

Changes to test/e_insert.test.

    46     46     CREATE TABLE a4(c UNIQUE, d);
    47     47   } {}
    48     48   
    49     49   proc do_insert_tests {args} {
    50     50     uplevel do_select_tests $args
    51     51   }
    52     52   
    53         -# EVIDENCE-OF: R-21350-31508 -- syntax diagram insert-stmt
           53  +# -- syntax diagram insert-stmt
    54     54   #
    55     55   do_insert_tests e_insert-0 {
    56     56        1  "INSERT             INTO a1 DEFAULT VALUES"                   {}
    57     57        2  "INSERT             INTO main.a1 DEFAULT VALUES"              {}
    58     58        3  "INSERT OR ROLLBACK INTO main.a1 DEFAULT VALUES"              {}
    59     59        4  "INSERT OR ROLLBACK INTO a1 DEFAULT VALUES"                   {}
    60     60        5  "INSERT OR ABORT    INTO main.a1 DEFAULT VALUES"              {}

Changes to test/e_reindex.test.

    22     22   
    23     23   do_execsql_test e_reindex-0.0 {
    24     24     CREATE TABLE t1(a, b);
    25     25     CREATE INDEX i1 ON t1(a, b);
    26     26     CREATE INDEX i2 ON t1(b, a);
    27     27   } {}
    28     28   
    29         -# EVIDENCE-OF: R-51477-38549 -- syntax diagram reindex-stmt
           29  +#  -- syntax diagram reindex-stmt
    30     30   #
    31     31   do_reindex_tests e_reindex-0.1 {
    32     32     1   "REINDEX"           {}
    33     33     2   "REINDEX nocase"    {}
    34     34     3   "REINDEX binary"    {}
    35     35     4   "REINDEX t1"        {}
    36     36     5   "REINDEX main.t1"   {}

Changes to test/e_select.test.

    79     79     }
    80     80   }
    81     81   
    82     82   #-------------------------------------------------------------------------
    83     83   # The following tests check that all paths on the syntax diagrams on
    84     84   # the lang_select.html page may be taken.
    85     85   #
    86         -# EVIDENCE-OF: R-11353-33501 -- syntax diagram join-constraint
           86  +# -- syntax diagram join-constraint
    87     87   #
    88     88   do_join_test e_select-0.1.1 {
    89     89     SELECT count(*) FROM t1 %JOIN% t2 ON (t1.a=t2.a)
    90     90   } {3}
    91     91   do_join_test e_select-0.1.2 {
    92     92     SELECT count(*) FROM t1 %JOIN% t2 USING (a)
    93     93   } {3}
................................................................................
    97     97   do_catchsql_test e_select-0.1.4 {
    98     98     SELECT count(*) FROM t1, t2 ON (t1.a=t2.a) USING (a)
    99     99   } {1 {cannot have both ON and USING clauses in the same join}}
   100    100   do_catchsql_test e_select-0.1.5 {
   101    101     SELECT count(*) FROM t1, t2 USING (a) ON (t1.a=t2.a)
   102    102   } {1 {near "ON": syntax error}}
   103    103   
   104         -# EVIDENCE-OF: R-40919-40941 -- syntax diagram select-core
          104  +# -- syntax diagram select-core
   105    105   #
   106    106   #   0: SELECT ...
   107    107   #   1: SELECT DISTINCT ...
   108    108   #   2: SELECT ALL ...
   109    109   #
   110    110   #   0: No FROM clause
   111    111   #   1: Has FROM clause
................................................................................
   222    222       1 a 1 c
   223    223     }
   224    224     2112.2  "SELECT ALL count(*), max(a) FROM t1 
   225    225              WHERE 0 GROUP BY b HAVING count(*)=2" { }
   226    226   }
   227    227   
   228    228   
   229         -# EVIDENCE-OF: R-41378-26734 -- syntax diagram result-column
          229  +# -- syntax diagram result-column
   230    230   #
   231    231   do_select_tests e_select-0.3 {
   232    232     1  "SELECT * FROM t1" {a one b two c three}
   233    233     2  "SELECT t1.* FROM t1" {a one b two c three}
   234    234     3  "SELECT 'x'||a||'x' FROM t1" {xax xbx xcx}
   235    235     4  "SELECT 'x'||a||'x' alias FROM t1" {xax xbx xcx}
   236    236     5  "SELECT 'x'||a||'x' AS alias FROM t1" {xax xbx xcx}
   237    237   }
   238    238   
   239         -# EVIDENCE-OF: R-43129-35648 -- syntax diagram join-source
          239  +# -- syntax diagram join-source
   240    240   #
   241         -# EVIDENCE-OF: R-36683-37460 -- syntax diagram join-op
          241  +# -- syntax diagram join-op
   242    242   #
   243    243   do_select_tests e_select-0.4 {
   244    244     1  "SELECT t1.rowid FROM t1" {1 2 3}
   245    245     2  "SELECT t1.rowid FROM t1,t2" {1 1 1 2 2 2 3 3 3}
   246    246     3  "SELECT t1.rowid FROM t1,t2,t3" {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3}
   247    247   
   248    248     4  "SELECT t1.rowid FROM t1" {1 2 3}
................................................................................
   259    259     12 "SELECT t1.rowid FROM t1 JOIN t3" {1 1 2 2 3 3}
   260    260     13 "SELECT t1.rowid FROM t1 LEFT OUTER JOIN t3" {1 1 2 2 3 3}
   261    261     14 "SELECT t1.rowid FROM t1 LEFT JOIN t3" {1 1 2 2 3 3}
   262    262     15 "SELECT t1.rowid FROM t1 INNER JOIN t3" {1 1 2 2 3 3}
   263    263     16 "SELECT t1.rowid FROM t1 CROSS JOIN t3" {1 1 2 2 3 3}
   264    264   }
   265    265   
   266         -# EVIDENCE-OF: R-28308-37813 -- syntax diagram compound-operator
          266  +# -- syntax diagram compound-operator
   267    267   #
   268    268   do_select_tests e_select-0.5 {
   269    269     1  "SELECT rowid FROM t1 UNION ALL SELECT rowid+2 FROM t4" {1 2 3 3 4}
   270    270     2  "SELECT rowid FROM t1 UNION     SELECT rowid+2 FROM t4" {1 2 3 4}
   271    271     3  "SELECT rowid FROM t1 INTERSECT SELECT rowid+2 FROM t4" {3}
   272    272     4  "SELECT rowid FROM t1 EXCEPT    SELECT rowid+2 FROM t4" {1 2}
   273    273   }
   274    274   
   275         -# EVIDENCE-OF: R-06480-34950 -- syntax diagram ordering-term
          275  +# -- syntax diagram ordering-term
   276    276   #
   277    277   do_select_tests e_select-0.6 {
   278    278     1  "SELECT b||a FROM t1 ORDER BY b||a"                  {onea threec twob}
   279    279     2  "SELECT b||a FROM t1 ORDER BY (b||a) COLLATE nocase" {onea threec twob}
   280    280     3  "SELECT b||a FROM t1 ORDER BY (b||a) ASC"            {onea threec twob}
   281    281     4  "SELECT b||a FROM t1 ORDER BY (b||a) DESC"           {twob threec onea}
   282    282   }
   283    283   
   284         -# EVIDENCE-OF: R-23926-36668 -- syntax diagram select-stmt
          284  +# -- syntax diagram select-stmt
   285    285   #
   286    286   do_select_tests e_select-0.7 {
   287    287     1  "SELECT * FROM t1" {a one b two c three}
   288    288     2  "SELECT * FROM t1 ORDER BY b" {a one c three b two}
   289    289     3  "SELECT * FROM t1 ORDER BY b, a" {a one c three b two}
   290    290   
   291    291     4  "SELECT * FROM t1 LIMIT 10" {a one b two c three}
................................................................................
   391    391   #    The tests are built on this assertion. Really, they test that the output
   392    392   #    of a CROSS JOIN, JOIN, INNER JOIN or "," join matches the expected result
   393    393   #    of calculating the cartesian product of the left and right-hand datasets. 
   394    394   #
   395    395   # EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER
   396    396   # JOIN", "JOIN" and "," join operators.
   397    397   #
   398         -# EVIDENCE-OF: R-07544-24155 The "CROSS JOIN" join operator produces the
   399         -# same data as the "INNER JOIN", "JOIN" and "," operators
          398  +# EVIDENCE-OF: R-25071-21202 The "CROSS JOIN" join operator produces the
          399  +# same result as the "INNER JOIN", "JOIN" and "," operators
   400    400   #
   401    401   #    All tests are run 4 times, with the only difference in each run being
   402    402   #    which of the 4 equivalent cartesian product join operators are used.
   403    403   #    Since the output data is the same in all cases, we consider that this
   404    404   #    qualifies as testing the two statements above.
   405    405   #
   406    406   do_execsql_test e_select-1.4.0 {
................................................................................
  1222   1222     1   "SELECT ALL a FROM h1"      {1 1 1 4 4 4}
  1223   1223     2   "SELECT DISTINCT a FROM h1" {1 4}
  1224   1224   }
  1225   1225   
  1226   1226   # EVIDENCE-OF: R-08861-34280 If the simple SELECT is a SELECT ALL, then
  1227   1227   # the entire set of result rows are returned by the SELECT.
  1228   1228   #
  1229         -# EVIDENCE-OF: R-47911-02086 If neither ALL or DISTINCT are present,
         1229  +# EVIDENCE-OF: R-01256-01950 If neither ALL or DISTINCT are present,
  1230   1230   # then the behavior is as if ALL were specified.
  1231   1231   #
  1232   1232   # EVIDENCE-OF: R-14442-41305 If the simple SELECT is a SELECT DISTINCT,
  1233   1233   # then duplicate rows are removed from the set of result rows before it
  1234   1234   # is returned.
  1235   1235   #
  1236   1236   #   The three testable statements above are tested by e_select-5.2.*,

Changes to test/e_select2.test.

   348    348     # JOIN", "JOIN" or a comma (",") and there is no ON or USING clause,
   349    349     # then the result of the join is simply the cartesian product of the
   350    350     # left and right-hand datasets.
   351    351     #
   352    352     # EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER
   353    353     # JOIN", "JOIN" and "," join operators.
   354    354     #
   355         -  # EVIDENCE-OF: R-07544-24155 The "CROSS JOIN" join operator produces the
   356         -  # same data as the "INNER JOIN", "JOIN" and "," operators
          355  +  # EVIDENCE-OF: R-25071-21202 The "CROSS JOIN" join operator produces the
          356  +  # same result as the "INNER JOIN", "JOIN" and "," operators
   357    357     #
   358    358     test_join $tn.1.1  "t1, t2"                {t1 t2}
   359    359     test_join $tn.1.2  "t1 INNER JOIN t2"      {t1 t2}
   360    360     test_join $tn.1.3  "t1 CROSS JOIN t2"      {t1 t2}
   361    361     test_join $tn.1.4  "t1 JOIN t2"            {t1 t2}
   362    362     test_join $tn.1.5  "t2, t3"                {t2 t3}
   363    363     test_join $tn.1.6  "t2 INNER JOIN t3"      {t2 t3}

Changes to test/e_update.test.

    45     45     CREATE TABLE aux.t5(a, b);
    46     46   } {}
    47     47   
    48     48   proc do_update_tests {args} {
    49     49     uplevel do_select_tests $args
    50     50   }
    51     51   
    52         -# EVIDENCE-OF: R-62337-45828 -- syntax diagram update-stmt
           52  +# -- syntax diagram update-stmt
    53     53   #
    54     54   do_update_tests e_update-0 {
    55     55     1    "UPDATE t1 SET a=10" {}
    56     56     2    "UPDATE t1 SET a=10, b=5" {}
    57     57     3    "UPDATE t1 SET a=10 WHERE b=5" {}
    58     58     4    "UPDATE t1 SET b=5,a=10 WHERE 1" {}
    59     59     5    "UPDATE main.t1 SET a=10" {}
................................................................................
   489    489   }
   490    490   
   491    491   # EVIDENCE-OF: R-59581-44104 If SQLite is built with the
   492    492   # SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option then the syntax
   493    493   # of the UPDATE statement is extended with optional ORDER BY and LIMIT
   494    494   # clauses
   495    495   #
   496         -# EVIDENCE-OF: R-45169-39597 -- syntax diagram update-stmt-limited
          496  +# -- syntax diagram update-stmt-limited
   497    497   #
   498    498   do_update_tests e_update-3.0 {
   499    499     1   "UPDATE t1 SET a=b LIMIT 5"                                    {}
   500    500     2   "UPDATE t1 SET a=b LIMIT 5-1 OFFSET 2+2"                       {}
   501    501     3   "UPDATE t1 SET a=b LIMIT 2+2, 16/4"                            {}
   502    502     4   "UPDATE t1 SET a=b ORDER BY a LIMIT 5"                         {}
   503    503     5   "UPDATE t1 SET a=b ORDER BY a LIMIT 5-1 OFFSET 2+2"            {}

Changes to test/e_uri.test.

   355    355   # EVIDENCE-OF: R-23027-03515 Setting it to "shared" is equivalent to
   356    356   # setting the SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed
   357    357   # to sqlite3_open_v2().
   358    358   #
   359    359   # EVIDENCE-OF: R-49793-28525 Setting the cache parameter to "private" is
   360    360   # equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
   361    361   #
   362         -# EVIDENCE-OF: R-19510-48080 If sqlite3_open_v2() is used and the
          362  +# EVIDENCE-OF: R-31773-41793 If sqlite3_open_v2() is used and the
   363    363   # "cache" parameter is present in a URI filename, its value overrides
   364    364   # any behavior requested by setting SQLITE_OPEN_PRIVATECACHE or
   365    365   # SQLITE_OPEN_SHAREDCACHE flag.
   366    366   #
   367    367   set orig [sqlite3_enable_shared_cache]
   368    368   foreach {tn uri flags shared_default isshared} {
   369    369     1.1   "file:test.db"                  ""         0    0

Changes to test/e_vacuum.test.

    61     61       set prevpageno $pageno
    62     62     }
    63     63     execsql { DROP TABLE temp.stat }
    64     64     set nFrag
    65     65   }
    66     66   
    67     67   
    68         -# EVIDENCE-OF: R-45173-45977 -- syntax diagram vacuum-stmt
           68  +# -- syntax diagram vacuum-stmt
    69     69   #
    70     70   do_execsql_test e_vacuum-0.1 { VACUUM } {}
    71     71   
    72     72   # EVIDENCE-OF: R-51469-36013 Unless SQLite is running in
    73     73   # "auto_vacuum=FULL" mode, when a large amount of data is deleted from
    74     74   # the database file it leaves behind empty space, or "free" database
    75     75   # pages.

Changes to test/eqp.test.

   366    366   
   367    367   #-------------------------------------------------------------------------
   368    368   # This next block of tests verifies that the examples on the 
   369    369   # lang_explain.html page are correct.
   370    370   #
   371    371   drop_all_tables
   372    372   
   373         -# EVIDENCE-OF: R-64208-08323 sqlite> EXPLAIN QUERY PLAN SELECT a, b
   374         -# FROM t1 WHERE a=1; 0|0|0|SCAN TABLE t1
          373  +# EVIDENCE-OF: R-47779-47605 sqlite> EXPLAIN QUERY PLAN SELECT a, b
          374  +# FROM t1 WHERE a=1;
          375  +# 0|0|0|SCAN TABLE t1
          376  +#
   375    377   do_execsql_test 5.1.0 { CREATE TABLE t1(a, b) }
   376    378   det 5.1.1 "SELECT a, b FROM t1 WHERE a=1" {
   377    379     0 0 0 {SCAN TABLE t1}
   378    380   }
   379    381   
   380         -# EVIDENCE-OF: R-09022-44606 sqlite> CREATE INDEX i1 ON t1(a);
          382  +# EVIDENCE-OF: R-55852-17599 sqlite> CREATE INDEX i1 ON t1(a);
   381    383   # sqlite> EXPLAIN QUERY PLAN SELECT a, b FROM t1 WHERE a=1;
   382         -# 0|0|0|SEARCH TABLE t1 USING INDEX i1 (a=?)
          384  +# 0|0|0|SEARCH TABLE t1 USING INDEX i1
          385  +#
   383    386   do_execsql_test 5.2.0 { CREATE INDEX i1 ON t1(a) }
   384    387   det 5.2.1 "SELECT a, b FROM t1 WHERE a=1" {
   385    388     0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}
   386    389   }
   387    390   
   388         -# EVIDENCE-OF: R-62228-34103 sqlite> CREATE INDEX i2 ON t1(a, b);
          391  +# EVIDENCE-OF: R-21179-11011 sqlite> CREATE INDEX i2 ON t1(a, b);
   389    392   # sqlite> EXPLAIN QUERY PLAN SELECT a, b FROM t1 WHERE a=1;
   390    393   # 0|0|0|SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)
          394  +#
   391    395   do_execsql_test 5.3.0 { CREATE INDEX i2 ON t1(a, b) }
   392    396   det 5.3.1 "SELECT a, b FROM t1 WHERE a=1" {
   393    397     0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)}
   394    398   }
   395    399   
   396         -# EVIDENCE-OF: R-22253-05302 sqlite> EXPLAIN QUERY PLAN SELECT t1.*,
   397         -# t2.* FROM t1, t2 WHERE t1.a=1 AND t1.b>2; 0|0|0|SEARCH TABLE t1
   398         -# USING COVERING INDEX i2 (a=? AND b>?) 0|1|1|SCAN TABLE t2
          400  +# EVIDENCE-OF: R-09991-48941 sqlite> EXPLAIN QUERY PLAN
          401  +# SELECT t1.*, t2.* FROM t1, t2 WHERE t1.a=1 AND t1.b>2;
          402  +# 0|0|0|SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)
          403  +# 0|1|1|SCAN TABLE t2
   399    404   #
   400    405   do_execsql_test 5.4.0 {CREATE TABLE t2(c, d)}
   401    406   det 5.4.1 "SELECT t1.*, t2.* FROM t1, t2 WHERE t1.a=1 AND t1.b>2" {
   402    407     0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)}
   403    408     0 1 1 {SCAN TABLE t2}
   404    409   }
   405    410   
   406         -# EVIDENCE-OF: R-21040-07025 sqlite> EXPLAIN QUERY PLAN SELECT t1.*,
   407         -# t2.* FROM t2, t1 WHERE t1.a=1 AND t1.b>2; 0|0|1|SEARCH TABLE t1
   408         -# USING COVERING INDEX i2 (a=? AND b>?) 0|1|0|SCAN TABLE t2
          411  +# EVIDENCE-OF: R-33626-61085 sqlite> EXPLAIN QUERY PLAN
          412  +# SELECT t1.*, t2.* FROM t2, t1 WHERE t1.a=1 AND t1.b>2;
          413  +# 0|0|1|SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)
          414  +# 0|1|0|SCAN TABLE t2
   409    415   #
   410    416   det 5.5 "SELECT t1.*, t2.* FROM t2, t1 WHERE t1.a=1 AND t1.b>2" {
   411    417     0 0 1 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)}
   412    418     0 1 0 {SCAN TABLE t2}
   413    419   }
   414    420   
   415         -# EVIDENCE-OF: R-39007-61103 sqlite> CREATE INDEX i3 ON t1(b);
          421  +# EVIDENCE-OF: R-04002-25654 sqlite> CREATE INDEX i3 ON t1(b);
   416    422   # sqlite> EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=1 OR b=2;
   417    423   # 0|0|0|SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)
   418    424   # 0|0|0|SEARCH TABLE t1 USING INDEX i3 (b=?)
          425  +#
   419    426   do_execsql_test 5.5.0 {CREATE INDEX i3 ON t1(b)}
   420    427   det 5.6.1 "SELECT * FROM t1 WHERE a=1 OR b=2" {
   421    428     0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)}
   422    429     0 0 0 {SEARCH TABLE t1 USING INDEX i3 (b=?)}
   423    430   }
   424    431   
   425         -# EVIDENCE-OF: R-33025-54904 sqlite> EXPLAIN QUERY PLAN SELECT c, d
   426         -# FROM t2 ORDER BY c; 0|0|0|SCAN TABLE t2 0|0|0|USE TEMP
   427         -# B-TREE FOR ORDER BY
          432  +# EVIDENCE-OF: R-24577-38891 sqlite> EXPLAIN QUERY PLAN
          433  +# SELECT c, d FROM t2 ORDER BY c;
          434  +# 0|0|0|SCAN TABLE t2
          435  +# 0|0|0|USE TEMP B-TREE FOR ORDER BY
          436  +#
   428    437   det 5.7 "SELECT c, d FROM t2 ORDER BY c" {
   429    438     0 0 0 {SCAN TABLE t2}
   430    439     0 0 0 {USE TEMP B-TREE FOR ORDER BY}
   431    440   }
   432    441   
   433         -# EVIDENCE-OF: R-38854-22809 sqlite> CREATE INDEX i4 ON t2(c);
          442  +# EVIDENCE-OF: R-58157-12355 sqlite> CREATE INDEX i4 ON t2(c);
   434    443   # sqlite> EXPLAIN QUERY PLAN SELECT c, d FROM t2 ORDER BY c;
   435    444   # 0|0|0|SCAN TABLE t2 USING INDEX i4
          445  +#
   436    446   do_execsql_test 5.8.0 {CREATE INDEX i4 ON t2(c)}
   437    447   det 5.8.1 "SELECT c, d FROM t2 ORDER BY c" {
   438    448     0 0 0 {SCAN TABLE t2 USING INDEX i4}
   439    449   }
   440    450   
   441         -# EVIDENCE-OF: R-29884-43993 sqlite> EXPLAIN QUERY PLAN SELECT
          451  +# EVIDENCE-OF: R-13931-10421 sqlite> EXPLAIN QUERY PLAN SELECT
   442    452   # (SELECT b FROM t1 WHERE a=0), (SELECT a FROM t1 WHERE b=t2.c) FROM t2;
   443         -# 0|0|0|SCAN TABLE t2 0|0|0|EXECUTE SCALAR SUBQUERY 1
          453  +# 0|0|0|SCAN TABLE t2
          454  +# 0|0|0|EXECUTE SCALAR SUBQUERY 1
   444    455   # 1|0|0|SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)
   445         -# 0|0|0|EXECUTE CORRELATED SCALAR SUBQUERY 2 2|0|0|SEARCH TABLE t1 USING
   446         -# INDEX i3 (b=?)
          456  +# 0|0|0|EXECUTE CORRELATED SCALAR SUBQUERY 2
          457  +# 2|0|0|SEARCH TABLE t1 USING INDEX i3 (b=?)
          458  +#
   447    459   det 5.9 {
   448    460     SELECT (SELECT b FROM t1 WHERE a=0), (SELECT a FROM t1 WHERE b=t2.c) FROM t2
   449    461   } {
   450    462     0 0 0 {SCAN TABLE t2 USING COVERING INDEX i4}
   451    463     0 0 0 {EXECUTE SCALAR SUBQUERY 1}
   452    464     1 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)}
   453    465     0 0 0 {EXECUTE CORRELATED SCALAR SUBQUERY 2}
   454    466     2 0 0 {SEARCH TABLE t1 USING INDEX i3 (b=?)}
   455    467   }
   456    468   
   457         -# EVIDENCE-OF: R-17911-16445 sqlite> EXPLAIN QUERY PLAN SELECT
   458         -# count(*) FROM (SELECT max(b) AS x FROM t1 GROUP BY a) GROUP BY x;
   459         -# 1|0|0|SCAN TABLE t1 USING COVERING INDEX i2 0|0|0|SCAN
   460         -# SUBQUERY 1 0|0|0|USE TEMP B-TREE FOR GROUP BY
          469  +# EVIDENCE-OF: R-50892-45943 sqlite> EXPLAIN QUERY PLAN
          470  +# SELECT count(*) FROM (SELECT max(b) AS x FROM t1 GROUP BY a) GROUP BY x;
          471  +# 1|0|0|SCAN TABLE t1 USING COVERING INDEX i2
          472  +# 0|0|0|SCAN SUBQUERY 1
          473  +# 0|0|0|USE TEMP B-TREE FOR GROUP BY
          474  +#
   461    475   det 5.10 {
   462    476     SELECT count(*) FROM (SELECT max(b) AS x FROM t1 GROUP BY a) GROUP BY x
   463    477   } {
   464    478     1 0 0 {SCAN TABLE t1 USING COVERING INDEX i2}
   465    479     0 0 0 {SCAN SUBQUERY 1}
   466    480     0 0 0 {USE TEMP B-TREE FOR GROUP BY}
   467    481   }
   468    482   
   469         -# EVIDENCE-OF: R-18544-33103 sqlite> EXPLAIN QUERY PLAN SELECT * FROM
   470         -# (SELECT * FROM t2 WHERE c=1), t1; 0|0|0|SEARCH TABLE t2 USING INDEX i4
   471         -# (c=?) 0|1|1|SCAN TABLE t1
          483  +# EVIDENCE-OF: R-46219-33846 sqlite> EXPLAIN QUERY PLAN
          484  +# SELECT * FROM (SELECT * FROM t2 WHERE c=1), t1;
          485  +# 0|0|0|SEARCH TABLE t2 USING INDEX i4 (c=?)
          486  +# 0|1|1|SCAN TABLE t1
          487  +#
   472    488   det 5.11 "SELECT * FROM (SELECT * FROM t2 WHERE c=1), t1" {
   473    489     0 0 0 {SEARCH TABLE t2 USING INDEX i4 (c=?)}
   474    490     0 1 1 {SCAN TABLE t1 USING COVERING INDEX i2}
   475    491   }
   476    492   
   477         -# EVIDENCE-OF: R-40701-42164 sqlite> EXPLAIN QUERY PLAN SELECT a FROM
   478         -# t1 UNION SELECT c FROM t2; 1|0|0|SCAN TABLE t1
   479         -# 2|0|0|SCAN TABLE t2 0|0|0|COMPOUND SUBQUERIES 1 AND 2
   480         -# USING TEMP B-TREE (UNION)
          493  +# EVIDENCE-OF: R-37879-39987 sqlite> EXPLAIN QUERY PLAN
          494  +# SELECT a FROM t1 UNION SELECT c FROM t2;
          495  +# 1|0|0|SCAN TABLE t1
          496  +# 2|0|0|SCAN TABLE t2
          497  +# 0|0|0|COMPOUND SUBQUERIES 1 AND 2 USING TEMP B-TREE (UNION)
          498  +#
   481    499   det 5.12 "SELECT a FROM t1 UNION SELECT c FROM t2" {
   482    500     1 0 0 {SCAN TABLE t1 USING COVERING INDEX i2}
   483    501     2 0 0 {SCAN TABLE t2 USING COVERING INDEX i4}
   484    502     0 0 0 {COMPOUND SUBQUERIES 1 AND 2 USING TEMP B-TREE (UNION)}
   485    503   }
   486    504   
   487         -# EVIDENCE-OF: R-61538-24748 sqlite> EXPLAIN QUERY PLAN SELECT a FROM
   488         -# t1 EXCEPT SELECT d FROM t2 ORDER BY 1; 1|0|0|SCAN TABLE t1 USING
   489         -# COVERING INDEX i2 2|0|0|SCAN TABLE t2
   490         -# 2|0|0|USE TEMP B-TREE FOR ORDER BY 0|0|0|COMPOUND SUBQUERIES 1 AND 2
   491         -# (EXCEPT)
          505  +# EVIDENCE-OF: R-44864-63011 sqlite> EXPLAIN QUERY PLAN
          506  +# SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1;
          507  +# 1|0|0|SCAN TABLE t1 USING COVERING INDEX i2
          508  +# 2|0|0|SCAN TABLE t2 2|0|0|USE TEMP B-TREE FOR ORDER BY
          509  +# 0|0|0|COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)
          510  +#
   492    511   det 5.13 "SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1" {
   493    512     1 0 0 {SCAN TABLE t1 USING COVERING INDEX i2}
   494    513     2 0 0 {SCAN TABLE t2}
   495    514     2 0 0 {USE TEMP B-TREE FOR ORDER BY}
   496    515     0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)}
   497    516   }
   498    517