Fossil SCM
Pull from upstream the SQLite version after the collating-sequence refactor. Fossil does not need this - the purpose is for testing the new SQLite in a real-world application.
Commit
8e31adafad2b8836359dbb35b7e2a3cb5f748123
Parent
f51c8a44478c628…
2 files changed
+352
-244
+12
-2
+352
-244
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -673,11 +673,11 @@ | ||
| 673 | 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | 675 | */ |
| 676 | 676 | #define SQLITE_VERSION "3.7.15" |
| 677 | 677 | #define SQLITE_VERSION_NUMBER 3007015 |
| 678 | -#define SQLITE_SOURCE_ID "2012-12-05 14:31:13 9f6c68856b694373b7ffb124abd996e519ba5921" | |
| 678 | +#define SQLITE_SOURCE_ID "2012-12-08 22:14:29 92c9ab56b1c67b9468bec57ab1d2c483a69a2810" | |
| 679 | 679 | |
| 680 | 680 | /* |
| 681 | 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | 683 | ** |
| @@ -1421,11 +1421,10 @@ | ||
| 1421 | 1421 | ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
| 1422 | 1422 | ** that the VFS encountered an error while handling the [PRAGMA] and the |
| 1423 | 1423 | ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
| 1424 | 1424 | ** file control occurs at the beginning of pragma statement analysis and so |
| 1425 | 1425 | ** it is able to override built-in [PRAGMA] statements. |
| 1426 | -** </ul> | |
| 1427 | 1426 | ** |
| 1428 | 1427 | ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
| 1429 | 1428 | ** ^This file-control may be invoked by SQLite on the database file handle |
| 1430 | 1429 | ** shortly after it is opened in order to provide a custom VFS with access |
| 1431 | 1430 | ** to the connections busy-handler callback. The argument is of type (void **) |
| @@ -1433,10 +1432,20 @@ | ||
| 1433 | 1432 | ** to a function of type (int (*)(void *)). In order to invoke the connections |
| 1434 | 1433 | ** busy-handler, this function should be invoked with the second (void *) in |
| 1435 | 1434 | ** the array as the only argument. If it returns non-zero, then the operation |
| 1436 | 1435 | ** should be retried. If it returns zero, the custom VFS should abandon the |
| 1437 | 1436 | ** current operation. |
| 1437 | +** | |
| 1438 | +** <li>[[SQLITE_FCNTL_TEMPFILENAME]] | |
| 1439 | +** ^Application can invoke this file-control to have SQLite generate a | |
| 1440 | +** temporary filename using the same algorithm that is followed to generate | |
| 1441 | +** temporary filenames for TEMP tables and other internal uses. The | |
| 1442 | +** argument should be a char** which will be filled with the filename | |
| 1443 | +** written into memory obtained from [sqlite3_malloc()]. The caller should | |
| 1444 | +** invoke [sqlite3_free()] on the result to avoid a memory leak. | |
| 1445 | +** | |
| 1446 | +** </ul> | |
| 1438 | 1447 | */ |
| 1439 | 1448 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 1440 | 1449 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 1441 | 1450 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 1442 | 1451 | #define SQLITE_LAST_ERRNO 4 |
| @@ -1449,10 +1458,11 @@ | ||
| 1449 | 1458 | #define SQLITE_FCNTL_OVERWRITE 11 |
| 1450 | 1459 | #define SQLITE_FCNTL_VFSNAME 12 |
| 1451 | 1460 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
| 1452 | 1461 | #define SQLITE_FCNTL_PRAGMA 14 |
| 1453 | 1462 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 1463 | +#define SQLITE_FCNTL_TEMPFILENAME 16 | |
| 1454 | 1464 | |
| 1455 | 1465 | /* |
| 1456 | 1466 | ** CAPI3REF: Mutex Handle |
| 1457 | 1467 | ** |
| 1458 | 1468 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -10209,23 +10219,11 @@ | ||
| 10209 | 10219 | /* |
| 10210 | 10220 | ** A "Collating Sequence" is defined by an instance of the following |
| 10211 | 10221 | ** structure. Conceptually, a collating sequence consists of a name and |
| 10212 | 10222 | ** a comparison routine that defines the order of that sequence. |
| 10213 | 10223 | ** |
| 10214 | -** There may two separate implementations of the collation function, one | |
| 10215 | -** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that | |
| 10216 | -** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine | |
| 10217 | -** native byte order. When a collation sequence is invoked, SQLite selects | |
| 10218 | -** the version that will require the least expensive encoding | |
| 10219 | -** translations, if any. | |
| 10220 | -** | |
| 10221 | -** The CollSeq.pUser member variable is an extra parameter that passed in | |
| 10222 | -** as the first argument to the UTF-8 comparison function, xCmp. | |
| 10223 | -** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function, | |
| 10224 | -** xCmp16. | |
| 10225 | -** | |
| 10226 | -** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the | |
| 10224 | +** If CollSeq.xCmp is NULL, it means that the | |
| 10227 | 10225 | ** collating sequence is undefined. Indices built on an undefined |
| 10228 | 10226 | ** collating sequence may not be read or written. |
| 10229 | 10227 | */ |
| 10230 | 10228 | struct CollSeq { |
| 10231 | 10229 | char *zName; /* Name of the collating sequence, UTF-8 encoded */ |
| @@ -10749,11 +10747,10 @@ | ||
| 10749 | 10747 | Expr *pRight; /* Right subnode */ |
| 10750 | 10748 | union { |
| 10751 | 10749 | ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */ |
| 10752 | 10750 | Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */ |
| 10753 | 10751 | } x; |
| 10754 | - CollSeq *pColl; /* The collation type of the column or 0 */ | |
| 10755 | 10752 | |
| 10756 | 10753 | /* If the EP_Reduced flag is set in the Expr.flags mask, then no |
| 10757 | 10754 | ** space is allocated for the fields below this point. An attempt to |
| 10758 | 10755 | ** access them will result in a segfault or malfunction. |
| 10759 | 10756 | *********************************************************************/ |
| @@ -10785,11 +10782,11 @@ | ||
| 10785 | 10782 | #define EP_Error 0x0008 /* Expression contains one or more errors */ |
| 10786 | 10783 | #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */ |
| 10787 | 10784 | #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ |
| 10788 | 10785 | #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */ |
| 10789 | 10786 | #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ |
| 10790 | -#define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */ | |
| 10787 | +#define EP_Collate 0x0100 /* Tree contains a TK_COLLATE opeartor */ | |
| 10791 | 10788 | #define EP_FixedDest 0x0200 /* Result needed in a specific register */ |
| 10792 | 10789 | #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ |
| 10793 | 10790 | #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ |
| 10794 | 10791 | #define EP_Hint 0x1000 /* Not used */ |
| 10795 | 10792 | #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ |
| @@ -11402,10 +11399,11 @@ | ||
| 11402 | 11399 | #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */ |
| 11403 | 11400 | #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ |
| 11404 | 11401 | #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ |
| 11405 | 11402 | #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ |
| 11406 | 11403 | #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */ |
| 11404 | +#define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ | |
| 11407 | 11405 | |
| 11408 | 11406 | /* |
| 11409 | 11407 | * Each trigger present in the database schema is stored as an instance of |
| 11410 | 11408 | * struct Trigger. |
| 11411 | 11409 | * |
| @@ -12093,12 +12091,13 @@ | ||
| 12093 | 12091 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 12094 | 12092 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 12095 | 12093 | SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 12096 | 12094 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| 12097 | 12095 | SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); |
| 12098 | -SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*); | |
| 12099 | -SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*); | |
| 12096 | +SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, Token*); | |
| 12097 | +SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); | |
| 12098 | +SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*); | |
| 12100 | 12099 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 12101 | 12100 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *); |
| 12102 | 12101 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 12103 | 12102 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 12104 | 12103 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| @@ -26456,10 +26455,13 @@ | ||
| 26456 | 26455 | }else{ |
| 26457 | 26456 | pFile->ctrlFlags |= mask; |
| 26458 | 26457 | } |
| 26459 | 26458 | } |
| 26460 | 26459 | |
| 26460 | +/* Forward declaration */ | |
| 26461 | +static int unixGetTempname(int nBuf, char *zBuf); | |
| 26462 | + | |
| 26461 | 26463 | /* |
| 26462 | 26464 | ** Information and control of an open file handle. |
| 26463 | 26465 | */ |
| 26464 | 26466 | static int unixFileControl(sqlite3_file *id, int op, void *pArg){ |
| 26465 | 26467 | unixFile *pFile = (unixFile*)id; |
| @@ -26492,10 +26494,18 @@ | ||
| 26492 | 26494 | return SQLITE_OK; |
| 26493 | 26495 | } |
| 26494 | 26496 | case SQLITE_FCNTL_VFSNAME: { |
| 26495 | 26497 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 26496 | 26498 | return SQLITE_OK; |
| 26499 | + } | |
| 26500 | + case SQLITE_FCNTL_TEMPFILENAME: { | |
| 26501 | + char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname ); | |
| 26502 | + if( zTFile ){ | |
| 26503 | + unixGetTempname(pFile->pVfs->mxPathname, zTFile); | |
| 26504 | + *(char**)pArg = zTFile; | |
| 26505 | + } | |
| 26506 | + return SQLITE_OK; | |
| 26497 | 26507 | } |
| 26498 | 26508 | #ifdef SQLITE_DEBUG |
| 26499 | 26509 | /* The pager calls this method to signal that it has done |
| 26500 | 26510 | ** a rollback and that the database is therefore unchanged and |
| 26501 | 26511 | ** it hence it is OK for the transaction change counter to be |
| @@ -32782,10 +32792,13 @@ | ||
| 32782 | 32792 | }else{ |
| 32783 | 32793 | pFile->ctrlFlags |= mask; |
| 32784 | 32794 | } |
| 32785 | 32795 | } |
| 32786 | 32796 | |
| 32797 | +/* Forward declaration */ | |
| 32798 | +static int getTempname(int nBuf, char *zBuf); | |
| 32799 | + | |
| 32787 | 32800 | /* |
| 32788 | 32801 | ** Control and query of the open file handle. |
| 32789 | 32802 | */ |
| 32790 | 32803 | static int winFileControl(sqlite3_file *id, int op, void *pArg){ |
| 32791 | 32804 | winFile *pFile = (winFile*)id; |
| @@ -32841,10 +32854,18 @@ | ||
| 32841 | 32854 | win32IoerrRetryDelay = a[1]; |
| 32842 | 32855 | }else{ |
| 32843 | 32856 | a[1] = win32IoerrRetryDelay; |
| 32844 | 32857 | } |
| 32845 | 32858 | return SQLITE_OK; |
| 32859 | + } | |
| 32860 | + case SQLITE_FCNTL_TEMPFILENAME: { | |
| 32861 | + char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname ); | |
| 32862 | + if( zTFile ){ | |
| 32863 | + getTempname(pFile->pVfs->mxPathname, zTFile); | |
| 32864 | + *(char**)pArg = zTFile; | |
| 32865 | + } | |
| 32866 | + return SQLITE_OK; | |
| 32846 | 32867 | } |
| 32847 | 32868 | } |
| 32848 | 32869 | return SQLITE_NOTFOUND; |
| 32849 | 32870 | } |
| 32850 | 32871 | |
| @@ -59392,26 +59413,22 @@ | ||
| 59392 | 59413 | assert( pKeyInfo->aSortOrder!=0 ); |
| 59393 | 59414 | sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField); |
| 59394 | 59415 | i = sqlite3Strlen30(zTemp); |
| 59395 | 59416 | for(j=0; j<pKeyInfo->nField; j++){ |
| 59396 | 59417 | CollSeq *pColl = pKeyInfo->aColl[j]; |
| 59397 | - if( pColl ){ | |
| 59398 | - int n = sqlite3Strlen30(pColl->zName); | |
| 59399 | - if( i+n>nTemp-6 ){ | |
| 59400 | - memcpy(&zTemp[i],",...",4); | |
| 59401 | - break; | |
| 59402 | - } | |
| 59403 | - zTemp[i++] = ','; | |
| 59404 | - if( pKeyInfo->aSortOrder[j] ){ | |
| 59405 | - zTemp[i++] = '-'; | |
| 59406 | - } | |
| 59407 | - memcpy(&zTemp[i], pColl->zName,n+1); | |
| 59408 | - i += n; | |
| 59409 | - }else if( i+4<nTemp-6 ){ | |
| 59410 | - memcpy(&zTemp[i],",nil",4); | |
| 59411 | - i += 4; | |
| 59412 | - } | |
| 59418 | + const char *zColl = pColl ? pColl->zName : "nil"; | |
| 59419 | + int n = sqlite3Strlen30(zColl); | |
| 59420 | + if( i+n>nTemp-6 ){ | |
| 59421 | + memcpy(&zTemp[i],",...",4); | |
| 59422 | + break; | |
| 59423 | + } | |
| 59424 | + zTemp[i++] = ','; | |
| 59425 | + if( pKeyInfo->aSortOrder[j] ){ | |
| 59426 | + zTemp[i++] = '-'; | |
| 59427 | + } | |
| 59428 | + memcpy(&zTemp[i], zColl, n+1); | |
| 59429 | + i += n; | |
| 59413 | 59430 | } |
| 59414 | 59431 | zTemp[i++] = ')'; |
| 59415 | 59432 | zTemp[i] = 0; |
| 59416 | 59433 | assert( i<nTemp ); |
| 59417 | 59434 | break; |
| @@ -63797,11 +63814,13 @@ | ||
| 63797 | 63814 | #ifdef SQLITE_DEBUG |
| 63798 | 63815 | /* |
| 63799 | 63816 | ** Print the value of a register for tracing purposes: |
| 63800 | 63817 | */ |
| 63801 | 63818 | static void memTracePrint(FILE *out, Mem *p){ |
| 63802 | - if( p->flags & MEM_Null ){ | |
| 63819 | + if( p->flags & MEM_Invalid ){ | |
| 63820 | + fprintf(out, " undefined"); | |
| 63821 | + }else if( p->flags & MEM_Null ){ | |
| 63803 | 63822 | fprintf(out, " NULL"); |
| 63804 | 63823 | }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ |
| 63805 | 63824 | fprintf(out, " si:%lld", p->u.i); |
| 63806 | 63825 | }else if( p->flags & MEM_Int ){ |
| 63807 | 63826 | fprintf(out, " i:%lld", p->u.i); |
| @@ -64979,10 +64998,13 @@ | ||
| 64979 | 64998 | pOut = &aMem[pOp->p2]; |
| 64980 | 64999 | assert( pOut!=pIn1 ); |
| 64981 | 65000 | while( 1 ){ |
| 64982 | 65001 | sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); |
| 64983 | 65002 | Deephemeralize(pOut); |
| 65003 | +#ifdef SQLITE_DEBUG | |
| 65004 | + pOut->pScopyFrom = 0; | |
| 65005 | +#endif | |
| 64984 | 65006 | REGISTER_TRACE(pOp->p2+pOp->p3-u.ae.n, pOut); |
| 64985 | 65007 | if( (u.ae.n--)==0 ) break; |
| 64986 | 65008 | pOut++; |
| 64987 | 65009 | pIn1++; |
| 64988 | 65010 | } |
| @@ -65801,26 +65823,31 @@ | ||
| 65801 | 65823 | /* Opcode: Permutation * * * P4 * |
| 65802 | 65824 | ** |
| 65803 | 65825 | ** Set the permutation used by the OP_Compare operator to be the array |
| 65804 | 65826 | ** of integers in P4. |
| 65805 | 65827 | ** |
| 65806 | -** The permutation is only valid until the next OP_Permutation, OP_Compare, | |
| 65807 | -** OP_Halt, or OP_ResultRow. Typically the OP_Permutation should occur | |
| 65808 | -** immediately prior to the OP_Compare. | |
| 65828 | +** The permutation is only valid until the next OP_Compare that has | |
| 65829 | +** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should | |
| 65830 | +** occur immediately prior to the OP_Compare. | |
| 65809 | 65831 | */ |
| 65810 | 65832 | case OP_Permutation: { |
| 65811 | 65833 | assert( pOp->p4type==P4_INTARRAY ); |
| 65812 | 65834 | assert( pOp->p4.ai ); |
| 65813 | 65835 | aPermute = pOp->p4.ai; |
| 65814 | 65836 | break; |
| 65815 | 65837 | } |
| 65816 | 65838 | |
| 65817 | -/* Opcode: Compare P1 P2 P3 P4 * | |
| 65839 | +/* Opcode: Compare P1 P2 P3 P4 P5 | |
| 65818 | 65840 | ** |
| 65819 | 65841 | ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this |
| 65820 | 65842 | ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of |
| 65821 | 65843 | ** the comparison for use by the next OP_Jump instruct. |
| 65844 | +** | |
| 65845 | +** If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is | |
| 65846 | +** determined by the most recent OP_Permutation operator. If the | |
| 65847 | +** OPFLAG_PERMUTE bit is clear, then register are compared in sequential | |
| 65848 | +** order. | |
| 65822 | 65849 | ** |
| 65823 | 65850 | ** P4 is a KeyInfo structure that defines collating sequences and sort |
| 65824 | 65851 | ** orders for the comparison. The permutation applies to registers |
| 65825 | 65852 | ** only. The KeyInfo elements are used sequentially. |
| 65826 | 65853 | ** |
| @@ -65838,10 +65865,11 @@ | ||
| 65838 | 65865 | int idx; |
| 65839 | 65866 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 65840 | 65867 | int bRev; /* True for DESCENDING sort order */ |
| 65841 | 65868 | #endif /* local variables moved into u.al */ |
| 65842 | 65869 | |
| 65870 | + if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; | |
| 65843 | 65871 | u.al.n = pOp->p3; |
| 65844 | 65872 | u.al.pKeyInfo = pOp->p4.pKeyInfo; |
| 65845 | 65873 | assert( u.al.n>0 ); |
| 65846 | 65874 | assert( u.al.pKeyInfo!=0 ); |
| 65847 | 65875 | u.al.p1 = pOp->p1; |
| @@ -72523,10 +72551,19 @@ | ||
| 72523 | 72551 | ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5 |
| 72524 | 72552 | ** |
| 72525 | 72553 | ** The result of random()%5 in the GROUP BY clause is probably different |
| 72526 | 72554 | ** from the result in the result-set. We might fix this someday. Or |
| 72527 | 72555 | ** then again, we might not... |
| 72556 | +** | |
| 72557 | +** If the reference is followed by a COLLATE operator, then make sure | |
| 72558 | +** the COLLATE operator is preserved. For example: | |
| 72559 | +** | |
| 72560 | +** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase; | |
| 72561 | +** | |
| 72562 | +** Should be transformed into: | |
| 72563 | +** | |
| 72564 | +** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase; | |
| 72528 | 72565 | ** |
| 72529 | 72566 | ** The nSubquery parameter specifies how many levels of subquery the |
| 72530 | 72567 | ** alias is removed from the original expression. The usually value is |
| 72531 | 72568 | ** zero but it might be more if the alias is contained within a subquery |
| 72532 | 72569 | ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION |
| @@ -72547,45 +72584,40 @@ | ||
| 72547 | 72584 | assert( iCol>=0 && iCol<pEList->nExpr ); |
| 72548 | 72585 | pOrig = pEList->a[iCol].pExpr; |
| 72549 | 72586 | assert( pOrig!=0 ); |
| 72550 | 72587 | assert( pOrig->flags & EP_Resolved ); |
| 72551 | 72588 | db = pParse->db; |
| 72589 | + pDup = sqlite3ExprDup(db, pOrig, 0); | |
| 72590 | + if( pDup==0 ) return; | |
| 72552 | 72591 | if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ |
| 72553 | - pDup = sqlite3ExprDup(db, pOrig, 0); | |
| 72554 | 72592 | incrAggFunctionDepth(pDup, nSubquery); |
| 72555 | 72593 | pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0); |
| 72556 | 72594 | if( pDup==0 ) return; |
| 72557 | 72595 | if( pEList->a[iCol].iAlias==0 ){ |
| 72558 | 72596 | pEList->a[iCol].iAlias = (u16)(++pParse->nAlias); |
| 72559 | 72597 | } |
| 72560 | 72598 | pDup->iTable = pEList->a[iCol].iAlias; |
| 72561 | - }else if( ExprHasProperty(pOrig, EP_IntValue) || pOrig->u.zToken==0 ){ | |
| 72562 | - pDup = sqlite3ExprDup(db, pOrig, 0); | |
| 72563 | - if( pDup==0 ) return; | |
| 72564 | - }else{ | |
| 72565 | - char *zToken = pOrig->u.zToken; | |
| 72566 | - assert( zToken!=0 ); | |
| 72567 | - pOrig->u.zToken = 0; | |
| 72568 | - pDup = sqlite3ExprDup(db, pOrig, 0); | |
| 72569 | - pOrig->u.zToken = zToken; | |
| 72570 | - if( pDup==0 ) return; | |
| 72571 | - assert( (pDup->flags & (EP_Reduced|EP_TokenOnly))==0 ); | |
| 72572 | - pDup->flags2 |= EP2_MallocedToken; | |
| 72573 | - pDup->u.zToken = sqlite3DbStrDup(db, zToken); | |
| 72574 | - } | |
| 72575 | - if( pExpr->flags & EP_ExpCollate ){ | |
| 72576 | - pDup->pColl = pExpr->pColl; | |
| 72577 | - pDup->flags |= EP_ExpCollate; | |
| 72599 | + } | |
| 72600 | + if( pExpr->op==TK_COLLATE ){ | |
| 72601 | + pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); | |
| 72578 | 72602 | } |
| 72579 | 72603 | |
| 72580 | 72604 | /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This |
| 72581 | 72605 | ** prevents ExprDelete() from deleting the Expr structure itself, |
| 72582 | 72606 | ** allowing it to be repopulated by the memcpy() on the following line. |
| 72607 | + ** The pExpr->u.zToken might point into memory that will be freed by the | |
| 72608 | + ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to | |
| 72609 | + ** make a copy of the token before doing the sqlite3DbFree(). | |
| 72583 | 72610 | */ |
| 72584 | 72611 | ExprSetProperty(pExpr, EP_Static); |
| 72585 | 72612 | sqlite3ExprDelete(db, pExpr); |
| 72586 | 72613 | memcpy(pExpr, pDup, sizeof(*pExpr)); |
| 72614 | + if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){ | |
| 72615 | + assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 ); | |
| 72616 | + pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken); | |
| 72617 | + pExpr->flags2 |= EP2_MallocedToken; | |
| 72618 | + } | |
| 72587 | 72619 | sqlite3DbFree(db, pDup); |
| 72588 | 72620 | } |
| 72589 | 72621 | |
| 72590 | 72622 | |
| 72591 | 72623 | /* |
| @@ -73268,11 +73300,11 @@ | ||
| 73268 | 73300 | assert( pEList!=0 ); |
| 73269 | 73301 | for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ |
| 73270 | 73302 | int iCol = -1; |
| 73271 | 73303 | Expr *pE, *pDup; |
| 73272 | 73304 | if( pItem->done ) continue; |
| 73273 | - pE = pItem->pExpr; | |
| 73305 | + pE = sqlite3ExprSkipCollate(pItem->pExpr); | |
| 73274 | 73306 | if( sqlite3ExprIsInteger(pE, &iCol) ){ |
| 73275 | 73307 | if( iCol<=0 || iCol>pEList->nExpr ){ |
| 73276 | 73308 | resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); |
| 73277 | 73309 | return 1; |
| 73278 | 73310 | } |
| @@ -73286,18 +73318,24 @@ | ||
| 73286 | 73318 | } |
| 73287 | 73319 | sqlite3ExprDelete(db, pDup); |
| 73288 | 73320 | } |
| 73289 | 73321 | } |
| 73290 | 73322 | if( iCol>0 ){ |
| 73291 | - CollSeq *pColl = pE->pColl; | |
| 73292 | - int flags = pE->flags & EP_ExpCollate; | |
| 73323 | + /* Convert the ORDER BY term into an integer column number iCol, | |
| 73324 | + ** taking care to preserve the COLLATE clause if it exists */ | |
| 73325 | + Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0); | |
| 73326 | + if( pNew==0 ) return 1; | |
| 73327 | + pNew->flags |= EP_IntValue; | |
| 73328 | + pNew->u.iValue = iCol; | |
| 73329 | + if( pItem->pExpr==pE ){ | |
| 73330 | + pItem->pExpr = pNew; | |
| 73331 | + }else{ | |
| 73332 | + assert( pItem->pExpr->op==TK_COLLATE ); | |
| 73333 | + assert( pItem->pExpr->pLeft==pE ); | |
| 73334 | + pItem->pExpr->pLeft = pNew; | |
| 73335 | + } | |
| 73293 | 73336 | sqlite3ExprDelete(db, pE); |
| 73294 | - pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0); | |
| 73295 | - if( pE==0 ) return 1; | |
| 73296 | - pE->pColl = pColl; | |
| 73297 | - pE->flags |= EP_IntValue | flags; | |
| 73298 | - pE->u.iValue = iCol; | |
| 73299 | 73337 | pItem->iOrderByCol = (u16)iCol; |
| 73300 | 73338 | pItem->done = 1; |
| 73301 | 73339 | }else{ |
| 73302 | 73340 | moreToDo = 1; |
| 73303 | 73341 | } |
| @@ -73398,15 +73436,15 @@ | ||
| 73398 | 73436 | ** sqlite3ResolveOrderGroupBy() will convert the expression to a |
| 73399 | 73437 | ** copy of the iCol-th result-set expression. */ |
| 73400 | 73438 | pItem->iOrderByCol = (u16)iCol; |
| 73401 | 73439 | continue; |
| 73402 | 73440 | } |
| 73403 | - if( sqlite3ExprIsInteger(pE, &iCol) ){ | |
| 73441 | + if( sqlite3ExprIsInteger(sqlite3ExprSkipCollate(pE), &iCol) ){ | |
| 73404 | 73442 | /* The ORDER BY term is an integer constant. Again, set the column |
| 73405 | 73443 | ** number so that sqlite3ResolveOrderGroupBy() will convert the |
| 73406 | 73444 | ** order-by term to a copy of the result-set expression */ |
| 73407 | - if( iCol<1 ){ | |
| 73445 | + if( iCol<1 || iCol>0xffff ){ | |
| 73408 | 73446 | resolveOutOfRangeError(pParse, zType, i+1, nResult); |
| 73409 | 73447 | return 1; |
| 73410 | 73448 | } |
| 73411 | 73449 | pItem->iOrderByCol = (u16)iCol; |
| 73412 | 73450 | continue; |
| @@ -73756,11 +73794,13 @@ | ||
| 73756 | 73794 | ** SELECT * FROM t1 WHERE a; |
| 73757 | 73795 | ** SELECT a AS b FROM t1 WHERE b; |
| 73758 | 73796 | ** SELECT * FROM t1 WHERE (select a from t1); |
| 73759 | 73797 | */ |
| 73760 | 73798 | SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr){ |
| 73761 | - int op = pExpr->op; | |
| 73799 | + int op; | |
| 73800 | + pExpr = sqlite3ExprSkipCollate(pExpr); | |
| 73801 | + op = pExpr->op; | |
| 73762 | 73802 | if( op==TK_SELECT ){ |
| 73763 | 73803 | assert( pExpr->flags&EP_xIsSelect ); |
| 73764 | 73804 | return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); |
| 73765 | 73805 | } |
| 73766 | 73806 | #ifndef SQLITE_OMIT_CAST |
| @@ -73781,70 +73821,98 @@ | ||
| 73781 | 73821 | } |
| 73782 | 73822 | return pExpr->affinity; |
| 73783 | 73823 | } |
| 73784 | 73824 | |
| 73785 | 73825 | /* |
| 73786 | -** Set the explicit collating sequence for an expression to the | |
| 73787 | -** collating sequence supplied in the second argument. | |
| 73788 | -*/ | |
| 73789 | -SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr *pExpr, CollSeq *pColl){ | |
| 73790 | - if( pExpr && pColl ){ | |
| 73791 | - pExpr->pColl = pColl; | |
| 73792 | - pExpr->flags |= EP_ExpCollate; | |
| 73793 | - } | |
| 73794 | - return pExpr; | |
| 73795 | -} | |
| 73796 | - | |
| 73797 | -/* | |
| 73798 | -** Set the collating sequence for expression pExpr to be the collating | |
| 73799 | -** sequence named by pToken. Return a pointer to the revised expression. | |
| 73800 | -** The collating sequence is marked as "explicit" using the EP_ExpCollate | |
| 73801 | -** flag. An explicit collating sequence will override implicit | |
| 73802 | -** collating sequences. | |
| 73803 | -*/ | |
| 73804 | -SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr *pExpr, Token *pCollName){ | |
| 73805 | - char *zColl = 0; /* Dequoted name of collation sequence */ | |
| 73806 | - CollSeq *pColl; | |
| 73807 | - sqlite3 *db = pParse->db; | |
| 73808 | - zColl = sqlite3NameFromToken(db, pCollName); | |
| 73809 | - pColl = sqlite3LocateCollSeq(pParse, zColl); | |
| 73810 | - sqlite3ExprSetColl(pExpr, pColl); | |
| 73811 | - sqlite3DbFree(db, zColl); | |
| 73812 | - return pExpr; | |
| 73813 | -} | |
| 73814 | - | |
| 73815 | -/* | |
| 73816 | -** Return the default collation sequence for the expression pExpr. If | |
| 73817 | -** there is no default collation type, return 0. | |
| 73818 | -*/ | |
| 73819 | -SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ | |
| 73820 | - CollSeq *pColl = 0; | |
| 73821 | - Expr *p = pExpr; | |
| 73822 | - while( p ){ | |
| 73823 | - int op; | |
| 73824 | - pColl = p->pColl; | |
| 73825 | - if( pColl ) break; | |
| 73826 | - op = p->op; | |
| 73827 | - if( p->pTab!=0 && ( | |
| 73828 | - op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER || op==TK_TRIGGER | |
| 73829 | - )){ | |
| 73830 | - /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally | |
| 73831 | - ** a TK_COLUMN but was previously evaluated and cached in a register */ | |
| 73832 | - const char *zColl; | |
| 73833 | - int j = p->iColumn; | |
| 73834 | - if( j>=0 ){ | |
| 73835 | - sqlite3 *db = pParse->db; | |
| 73836 | - zColl = p->pTab->aCol[j].zColl; | |
| 73837 | - pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); | |
| 73838 | - pExpr->pColl = pColl; | |
| 73839 | - } | |
| 73840 | - break; | |
| 73841 | - } | |
| 73842 | - if( op!=TK_CAST && op!=TK_UPLUS ){ | |
| 73843 | - break; | |
| 73844 | - } | |
| 73845 | - p = p->pLeft; | |
| 73826 | +** Set the collating sequence for expression pExpr to be the collating | |
| 73827 | +** sequence named by pToken. Return a pointer to a new Expr node that | |
| 73828 | +** implements the COLLATE operator. | |
| 73829 | +** | |
| 73830 | +** If a memory allocation error occurs, that fact is recorded in pParse->db | |
| 73831 | +** and the pExpr parameter is returned unchanged. | |
| 73832 | +*/ | |
| 73833 | +SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr *pExpr, Token *pCollName){ | |
| 73834 | + if( pCollName->n>0 ){ | |
| 73835 | + Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1); | |
| 73836 | + if( pNew ){ | |
| 73837 | + pNew->pLeft = pExpr; | |
| 73838 | + pNew->flags |= EP_Collate; | |
| 73839 | + pExpr = pNew; | |
| 73840 | + } | |
| 73841 | + } | |
| 73842 | + return pExpr; | |
| 73843 | +} | |
| 73844 | +SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){ | |
| 73845 | + Token s; | |
| 73846 | + assert( zC!=0 ); | |
| 73847 | + s.z = zC; | |
| 73848 | + s.n = sqlite3Strlen30(s.z); | |
| 73849 | + return sqlite3ExprAddCollateToken(pParse, pExpr, &s); | |
| 73850 | +} | |
| 73851 | + | |
| 73852 | +/* | |
| 73853 | +** Skip over any TK_COLLATE and/or TK_AS operators at the root of | |
| 73854 | +** an expression. | |
| 73855 | +*/ | |
| 73856 | +SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){ | |
| 73857 | + while( pExpr && (pExpr->op==TK_COLLATE || pExpr->op==TK_AS) ){ | |
| 73858 | + pExpr = pExpr->pLeft; | |
| 73859 | + } | |
| 73860 | + return pExpr; | |
| 73861 | +} | |
| 73862 | + | |
| 73863 | +/* | |
| 73864 | +** Return the collation sequence for the expression pExpr. If | |
| 73865 | +** there is no defined collating sequence, return NULL. | |
| 73866 | +** | |
| 73867 | +** The collating sequence might be determined by a COLLATE operator | |
| 73868 | +** or by the presence of a column with a defined collating sequence. | |
| 73869 | +** COLLATE operators take first precedence. Left operands take | |
| 73870 | +** precedence over right operands. | |
| 73871 | +*/ | |
| 73872 | +SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ | |
| 73873 | + sqlite3 *db = pParse->db; | |
| 73874 | + CollSeq *pColl = 0; | |
| 73875 | + Expr *p = pExpr; | |
| 73876 | + while( p ){ | |
| 73877 | + int op = p->op; | |
| 73878 | + if( op==TK_CAST || op==TK_UPLUS ){ | |
| 73879 | + p = p->pLeft; | |
| 73880 | + continue; | |
| 73881 | + } | |
| 73882 | + assert( op!=TK_REGISTER || p->op2!=TK_COLLATE ); | |
| 73883 | + if( op==TK_COLLATE ){ | |
| 73884 | + if( db->init.busy ){ | |
| 73885 | + /* Do not report errors when parsing while the schema */ | |
| 73886 | + pColl = sqlite3FindCollSeq(db, ENC(db), p->u.zToken, 0); | |
| 73887 | + }else{ | |
| 73888 | + pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); | |
| 73889 | + } | |
| 73890 | + break; | |
| 73891 | + } | |
| 73892 | + if( p->pTab!=0 | |
| 73893 | + && (op==TK_AGG_COLUMN || op==TK_COLUMN | |
| 73894 | + || op==TK_REGISTER || op==TK_TRIGGER) | |
| 73895 | + ){ | |
| 73896 | + /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally | |
| 73897 | + ** a TK_COLUMN but was previously evaluated and cached in a register */ | |
| 73898 | + int j = p->iColumn; | |
| 73899 | + if( j>=0 ){ | |
| 73900 | + const char *zColl = p->pTab->aCol[j].zColl; | |
| 73901 | + pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); | |
| 73902 | + } | |
| 73903 | + break; | |
| 73904 | + } | |
| 73905 | + if( p->flags & EP_Collate ){ | |
| 73906 | + if( ALWAYS(p->pLeft) && (p->pLeft->flags & EP_Collate)!=0 ){ | |
| 73907 | + p = p->pLeft; | |
| 73908 | + }else{ | |
| 73909 | + p = p->pRight; | |
| 73910 | + } | |
| 73911 | + }else{ | |
| 73912 | + break; | |
| 73913 | + } | |
| 73846 | 73914 | } |
| 73847 | 73915 | if( sqlite3CheckCollSeq(pParse, pColl) ){ |
| 73848 | 73916 | pColl = 0; |
| 73849 | 73917 | } |
| 73850 | 73918 | return pColl; |
| @@ -73944,16 +74012,14 @@ | ||
| 73944 | 74012 | Expr *pLeft, |
| 73945 | 74013 | Expr *pRight |
| 73946 | 74014 | ){ |
| 73947 | 74015 | CollSeq *pColl; |
| 73948 | 74016 | assert( pLeft ); |
| 73949 | - if( pLeft->flags & EP_ExpCollate ){ | |
| 73950 | - assert( pLeft->pColl ); | |
| 73951 | - pColl = pLeft->pColl; | |
| 73952 | - }else if( pRight && pRight->flags & EP_ExpCollate ){ | |
| 73953 | - assert( pRight->pColl ); | |
| 73954 | - pColl = pRight->pColl; | |
| 74017 | + if( pLeft->flags & EP_Collate ){ | |
| 74018 | + pColl = sqlite3ExprCollSeq(pParse, pLeft); | |
| 74019 | + }else if( pRight && (pRight->flags & EP_Collate)!=0 ){ | |
| 74020 | + pColl = sqlite3ExprCollSeq(pParse, pRight); | |
| 73955 | 74021 | }else{ |
| 73956 | 74022 | pColl = sqlite3ExprCollSeq(pParse, pLeft); |
| 73957 | 74023 | if( !pColl ){ |
| 73958 | 74024 | pColl = sqlite3ExprCollSeq(pParse, pRight); |
| 73959 | 74025 | } |
| @@ -74179,21 +74245,15 @@ | ||
| 74179 | 74245 | sqlite3ExprDelete(db, pLeft); |
| 74180 | 74246 | sqlite3ExprDelete(db, pRight); |
| 74181 | 74247 | }else{ |
| 74182 | 74248 | if( pRight ){ |
| 74183 | 74249 | pRoot->pRight = pRight; |
| 74184 | - if( pRight->flags & EP_ExpCollate ){ | |
| 74185 | - pRoot->flags |= EP_ExpCollate; | |
| 74186 | - pRoot->pColl = pRight->pColl; | |
| 74187 | - } | |
| 74250 | + pRoot->flags |= EP_Collate & pRight->flags; | |
| 74188 | 74251 | } |
| 74189 | 74252 | if( pLeft ){ |
| 74190 | 74253 | pRoot->pLeft = pLeft; |
| 74191 | - if( pLeft->flags & EP_ExpCollate ){ | |
| 74192 | - pRoot->flags |= EP_ExpCollate; | |
| 74193 | - pRoot->pColl = pLeft->pColl; | |
| 74194 | - } | |
| 74254 | + pRoot->flags |= EP_Collate & pLeft->flags; | |
| 74195 | 74255 | } |
| 74196 | 74256 | exprSetHeight(pRoot); |
| 74197 | 74257 | } |
| 74198 | 74258 | } |
| 74199 | 74259 | |
| @@ -74447,11 +74507,11 @@ | ||
| 74447 | 74507 | }else{ |
| 74448 | 74508 | assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 74449 | 74509 | assert( !ExprHasProperty(p, EP_FromJoin) ); |
| 74450 | 74510 | assert( (p->flags2 & EP2_MallocedToken)==0 ); |
| 74451 | 74511 | assert( (p->flags2 & EP2_Irreducible)==0 ); |
| 74452 | - if( p->pLeft || p->pRight || p->pColl || p->x.pList ){ | |
| 74512 | + if( p->pLeft || p->pRight || p->x.pList ){ | |
| 74453 | 74513 | nSize = EXPR_REDUCEDSIZE | EP_Reduced; |
| 74454 | 74514 | }else{ |
| 74455 | 74515 | nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly; |
| 74456 | 74516 | } |
| 74457 | 74517 | } |
| @@ -76471,10 +76531,11 @@ | ||
| 76471 | 76531 | sqlite3VdbeAddOp3(v, OP_And, r3, r4, target); |
| 76472 | 76532 | sqlite3ReleaseTempReg(pParse, r3); |
| 76473 | 76533 | sqlite3ReleaseTempReg(pParse, r4); |
| 76474 | 76534 | break; |
| 76475 | 76535 | } |
| 76536 | + case TK_COLLATE: | |
| 76476 | 76537 | case TK_UPLUS: { |
| 76477 | 76538 | inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); |
| 76478 | 76539 | break; |
| 76479 | 76540 | } |
| 76480 | 76541 | |
| @@ -76839,10 +76900,16 @@ | ||
| 76839 | 76900 | case TK_UPLUS: zUniOp = "UPLUS"; break; |
| 76840 | 76901 | case TK_BITNOT: zUniOp = "BITNOT"; break; |
| 76841 | 76902 | case TK_NOT: zUniOp = "NOT"; break; |
| 76842 | 76903 | case TK_ISNULL: zUniOp = "ISNULL"; break; |
| 76843 | 76904 | case TK_NOTNULL: zUniOp = "NOTNULL"; break; |
| 76905 | + | |
| 76906 | + case TK_COLLATE: { | |
| 76907 | + sqlite3ExplainExpr(pOut, pExpr->pLeft); | |
| 76908 | + sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken); | |
| 76909 | + break; | |
| 76910 | + } | |
| 76844 | 76911 | |
| 76845 | 76912 | case TK_AGG_FUNCTION: |
| 76846 | 76913 | case TK_CONST_FUNC: |
| 76847 | 76914 | case TK_FUNCTION: { |
| 76848 | 76915 | ExprList *pFarg; /* List of function arguments */ |
| @@ -77058,10 +77125,13 @@ | ||
| 77058 | 77125 | switch( pExpr->op ){ |
| 77059 | 77126 | case TK_IN: |
| 77060 | 77127 | case TK_REGISTER: { |
| 77061 | 77128 | return WRC_Prune; |
| 77062 | 77129 | } |
| 77130 | + case TK_COLLATE: { | |
| 77131 | + return WRC_Continue; | |
| 77132 | + } | |
| 77063 | 77133 | case TK_FUNCTION: |
| 77064 | 77134 | case TK_AGG_FUNCTION: |
| 77065 | 77135 | case TK_CONST_FUNC: { |
| 77066 | 77136 | /* The arguments to a function have a fixed destination. |
| 77067 | 77137 | ** Mark them this way to avoid generated unneeded OP_SCopy |
| @@ -77079,13 +77149,15 @@ | ||
| 77079 | 77149 | break; |
| 77080 | 77150 | } |
| 77081 | 77151 | } |
| 77082 | 77152 | if( isAppropriateForFactoring(pExpr) ){ |
| 77083 | 77153 | int r1 = ++pParse->nMem; |
| 77084 | - int r2; | |
| 77085 | - r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); | |
| 77086 | - if( NEVER(r1!=r2) ) sqlite3ReleaseTempReg(pParse, r1); | |
| 77154 | + int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); | |
| 77155 | + /* If r2!=r1, it means that register r1 is never used. That is harmless | |
| 77156 | + ** but suboptimal, so we want to know about the situation to fix it. | |
| 77157 | + ** Hence the following assert: */ | |
| 77158 | + assert( r2==r1 ); | |
| 77087 | 77159 | pExpr->op2 = pExpr->op; |
| 77088 | 77160 | pExpr->op = TK_REGISTER; |
| 77089 | 77161 | pExpr->iTable = r2; |
| 77090 | 77162 | return WRC_Prune; |
| 77091 | 77163 | } |
| @@ -77498,11 +77570,19 @@ | ||
| 77498 | 77570 | assert( !ExprHasAnyProperty(pB, EP_TokenOnly|EP_Reduced) ); |
| 77499 | 77571 | if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){ |
| 77500 | 77572 | return 2; |
| 77501 | 77573 | } |
| 77502 | 77574 | if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2; |
| 77503 | - if( pA->op!=pB->op ) return 2; | |
| 77575 | + if( pA->op!=pB->op ){ | |
| 77576 | + if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB)<2 ){ | |
| 77577 | + return 1; | |
| 77578 | + } | |
| 77579 | + if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft)<2 ){ | |
| 77580 | + return 1; | |
| 77581 | + } | |
| 77582 | + return 2; | |
| 77583 | + } | |
| 77504 | 77584 | if( sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 2; |
| 77505 | 77585 | if( sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 2; |
| 77506 | 77586 | if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList) ) return 2; |
| 77507 | 77587 | if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2; |
| 77508 | 77588 | if( ExprHasProperty(pA, EP_IntValue) ){ |
| @@ -77510,15 +77590,13 @@ | ||
| 77510 | 77590 | return 2; |
| 77511 | 77591 | } |
| 77512 | 77592 | }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){ |
| 77513 | 77593 | if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; |
| 77514 | 77594 | if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ |
| 77515 | - return 2; | |
| 77595 | + return pA->op==TK_COLLATE ? 1 : 2; | |
| 77516 | 77596 | } |
| 77517 | 77597 | } |
| 77518 | - if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1; | |
| 77519 | - if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2; | |
| 77520 | 77598 | return 0; |
| 77521 | 77599 | } |
| 77522 | 77600 | |
| 77523 | 77601 | /* |
| 77524 | 77602 | ** Compare two ExprList objects. Return 0 if they are identical and |
| @@ -80765,10 +80843,11 @@ | ||
| 80765 | 80843 | */ |
| 80766 | 80844 | SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){ |
| 80767 | 80845 | sqlite3 *db; |
| 80768 | 80846 | Vdbe *v; |
| 80769 | 80847 | |
| 80848 | + assert( pParse->pToplevel==0 ); | |
| 80770 | 80849 | db = pParse->db; |
| 80771 | 80850 | if( db->mallocFailed ) return; |
| 80772 | 80851 | if( pParse->nested ) return; |
| 80773 | 80852 | if( pParse->nErr ) return; |
| 80774 | 80853 | |
| @@ -83328,14 +83407,12 @@ | ||
| 83328 | 83407 | ** specified collation sequence names. |
| 83329 | 83408 | */ |
| 83330 | 83409 | for(i=0; i<pList->nExpr; i++){ |
| 83331 | 83410 | Expr *pExpr = pList->a[i].pExpr; |
| 83332 | 83411 | if( pExpr ){ |
| 83333 | - CollSeq *pColl = pExpr->pColl; | |
| 83334 | - /* Either pColl!=0 or there was an OOM failure. But if an OOM | |
| 83335 | - ** failure we have quit before reaching this point. */ | |
| 83336 | - if( ALWAYS(pColl) ){ | |
| 83412 | + CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr); | |
| 83413 | + if( pColl ){ | |
| 83337 | 83414 | nExtra += (1 + sqlite3Strlen30(pColl->zName)); |
| 83338 | 83415 | } |
| 83339 | 83416 | } |
| 83340 | 83417 | } |
| 83341 | 83418 | |
| @@ -83394,10 +83471,11 @@ | ||
| 83394 | 83471 | */ |
| 83395 | 83472 | for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){ |
| 83396 | 83473 | const char *zColName = pListItem->zName; |
| 83397 | 83474 | Column *pTabCol; |
| 83398 | 83475 | int requestedSortOrder; |
| 83476 | + CollSeq *pColl; /* Collating sequence */ | |
| 83399 | 83477 | char *zColl; /* Collation sequence name */ |
| 83400 | 83478 | |
| 83401 | 83479 | for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){ |
| 83402 | 83480 | if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; |
| 83403 | 83481 | } |
| @@ -83406,18 +83484,15 @@ | ||
| 83406 | 83484 | pTab->zName, zColName); |
| 83407 | 83485 | pParse->checkSchema = 1; |
| 83408 | 83486 | goto exit_create_index; |
| 83409 | 83487 | } |
| 83410 | 83488 | pIndex->aiColumn[i] = j; |
| 83411 | - /* Justification of the ALWAYS(pListItem->pExpr->pColl): Because of | |
| 83412 | - ** the way the "idxlist" non-terminal is constructed by the parser, | |
| 83413 | - ** if pListItem->pExpr is not null then either pListItem->pExpr->pColl | |
| 83414 | - ** must exist or else there must have been an OOM error. But if there | |
| 83415 | - ** was an OOM error, we would never reach this point. */ | |
| 83416 | - if( pListItem->pExpr && ALWAYS(pListItem->pExpr->pColl) ){ | |
| 83489 | + if( pListItem->pExpr | |
| 83490 | + && (pColl = sqlite3ExprCollSeq(pParse, pListItem->pExpr))!=0 | |
| 83491 | + ){ | |
| 83417 | 83492 | int nColl; |
| 83418 | - zColl = pListItem->pExpr->pColl->zName; | |
| 83493 | + zColl = pColl->zName; | |
| 83419 | 83494 | nColl = sqlite3Strlen30(zColl) + 1; |
| 83420 | 83495 | assert( nExtra>=nColl ); |
| 83421 | 83496 | memcpy(zExtra, zColl, nColl); |
| 83422 | 83497 | zColl = zExtra; |
| 83423 | 83498 | zExtra += nColl; |
| @@ -84227,10 +84302,19 @@ | ||
| 84227 | 84302 | ** early in the code, before we know if any database tables will be used. |
| 84228 | 84303 | */ |
| 84229 | 84304 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ |
| 84230 | 84305 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 84231 | 84306 | |
| 84307 | +#ifndef SQLITE_OMIT_TRIGGER | |
| 84308 | + if( pToplevel!=pParse ){ | |
| 84309 | + /* This branch is taken if a trigger is currently being coded. In this | |
| 84310 | + ** case, set cookieGoto to a non-zero value to show that this function | |
| 84311 | + ** has been called. This is used by the sqlite3ExprCodeConstants() | |
| 84312 | + ** function. */ | |
| 84313 | + pParse->cookieGoto = -1; | |
| 84314 | + } | |
| 84315 | +#endif | |
| 84232 | 84316 | if( pToplevel->cookieGoto==0 ){ |
| 84233 | 84317 | Vdbe *v = sqlite3GetVdbe(pToplevel); |
| 84234 | 84318 | if( v==0 ) return; /* This only happens if there was a prior error */ |
| 84235 | 84319 | pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1; |
| 84236 | 84320 | } |
| @@ -87806,16 +87890,19 @@ | ||
| 87806 | 87890 | if( pLeft ){ |
| 87807 | 87891 | /* Set the collation sequence and affinity of the LHS of each TK_EQ |
| 87808 | 87892 | ** expression to the parent key column defaults. */ |
| 87809 | 87893 | if( pIdx ){ |
| 87810 | 87894 | Column *pCol; |
| 87895 | + const char *zColl; | |
| 87811 | 87896 | iCol = pIdx->aiColumn[i]; |
| 87812 | 87897 | pCol = &pTab->aCol[iCol]; |
| 87813 | 87898 | if( pTab->iPKey==iCol ) iCol = -1; |
| 87814 | 87899 | pLeft->iTable = regData+iCol+1; |
| 87815 | 87900 | pLeft->affinity = pCol->affinity; |
| 87816 | - pLeft->pColl = sqlite3LocateCollSeq(pParse, pCol->zColl); | |
| 87901 | + zColl = pCol->zColl; | |
| 87902 | + if( zColl==0 ) zColl = db->pDfltColl->zName; | |
| 87903 | + pLeft = sqlite3ExprAddCollateString(pParse, pLeft, zColl); | |
| 87817 | 87904 | }else{ |
| 87818 | 87905 | pLeft->iTable = regData; |
| 87819 | 87906 | pLeft->affinity = SQLITE_AFF_INTEGER; |
| 87820 | 87907 | } |
| 87821 | 87908 | } |
| @@ -89791,29 +89878,24 @@ | ||
| 89791 | 89878 | ExprList *pCheck = pTab->pCheck; |
| 89792 | 89879 | pParse->ckBase = regData; |
| 89793 | 89880 | onError = overrideError!=OE_Default ? overrideError : OE_Abort; |
| 89794 | 89881 | for(i=0; i<pCheck->nExpr; i++){ |
| 89795 | 89882 | int allOk = sqlite3VdbeMakeLabel(v); |
| 89796 | - Expr *pDup = sqlite3ExprDup(db, pCheck->a[i].pExpr, 0); | |
| 89797 | - if( !db->mallocFailed ){ | |
| 89798 | - assert( pDup!=0 ); | |
| 89799 | - sqlite3ExprIfTrue(pParse, pDup, allOk, SQLITE_JUMPIFNULL); | |
| 89800 | - if( onError==OE_Ignore ){ | |
| 89801 | - sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); | |
| 89802 | - }else{ | |
| 89803 | - char *zConsName = pCheck->a[i].zName; | |
| 89804 | - if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ | |
| 89805 | - if( zConsName ){ | |
| 89806 | - zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); | |
| 89807 | - }else{ | |
| 89808 | - zConsName = 0; | |
| 89809 | - } | |
| 89810 | - sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); | |
| 89811 | - } | |
| 89812 | - sqlite3VdbeResolveLabel(v, allOk); | |
| 89813 | - } | |
| 89814 | - sqlite3ExprDelete(db, pDup); | |
| 89883 | + sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL); | |
| 89884 | + if( onError==OE_Ignore ){ | |
| 89885 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); | |
| 89886 | + }else{ | |
| 89887 | + char *zConsName = pCheck->a[i].zName; | |
| 89888 | + if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ | |
| 89889 | + if( zConsName ){ | |
| 89890 | + zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); | |
| 89891 | + }else{ | |
| 89892 | + zConsName = 0; | |
| 89893 | + } | |
| 89894 | + sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); | |
| 89895 | + } | |
| 89896 | + sqlite3VdbeResolveLabel(v, allOk); | |
| 89815 | 89897 | } |
| 89816 | 89898 | } |
| 89817 | 89899 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| 89818 | 89900 | |
| 89819 | 89901 | /* If we have an INTEGER PRIMARY KEY, make sure the primary key |
| @@ -95536,11 +95618,11 @@ | ||
| 95536 | 95618 | *paCol = aCol; |
| 95537 | 95619 | |
| 95538 | 95620 | for(i=0, pCol=aCol; i<nCol; i++, pCol++){ |
| 95539 | 95621 | /* Get an appropriate name for the column |
| 95540 | 95622 | */ |
| 95541 | - p = pEList->a[i].pExpr; | |
| 95623 | + p = sqlite3ExprSkipCollate(pEList->a[i].pExpr); | |
| 95542 | 95624 | assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue) |
| 95543 | 95625 | || p->pRight->u.zToken==0 || p->pRight->u.zToken[0]!=0 ); |
| 95544 | 95626 | if( (zName = pEList->a[i].zName)!=0 ){ |
| 95545 | 95627 | /* If the column contains an "AS <name>" phrase, use <name> as the name */ |
| 95546 | 95628 | zName = sqlite3DbStrDup(db, zName); |
| @@ -96534,16 +96616,17 @@ | ||
| 96534 | 96616 | pKeyMerge->nField = (u16)nOrderBy; |
| 96535 | 96617 | pKeyMerge->enc = ENC(db); |
| 96536 | 96618 | for(i=0; i<nOrderBy; i++){ |
| 96537 | 96619 | CollSeq *pColl; |
| 96538 | 96620 | Expr *pTerm = pOrderBy->a[i].pExpr; |
| 96539 | - if( pTerm->flags & EP_ExpCollate ){ | |
| 96540 | - pColl = pTerm->pColl; | |
| 96621 | + if( pTerm->flags & EP_Collate ){ | |
| 96622 | + pColl = sqlite3ExprCollSeq(pParse, pTerm); | |
| 96541 | 96623 | }else{ |
| 96542 | 96624 | pColl = multiSelectCollSeq(pParse, p, aPermute[i]); |
| 96543 | - pTerm->flags |= EP_ExpCollate; | |
| 96544 | - pTerm->pColl = pColl; | |
| 96625 | + if( pColl==0 ) pColl = db->pDfltColl; | |
| 96626 | + pOrderBy->a[i].pExpr = | |
| 96627 | + sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName); | |
| 96545 | 96628 | } |
| 96546 | 96629 | pKeyMerge->aColl[i] = pColl; |
| 96547 | 96630 | pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder; |
| 96548 | 96631 | } |
| 96549 | 96632 | } |
| @@ -96742,10 +96825,11 @@ | ||
| 96742 | 96825 | */ |
| 96743 | 96826 | sqlite3VdbeResolveLabel(v, labelCmpr); |
| 96744 | 96827 | sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY); |
| 96745 | 96828 | sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy, |
| 96746 | 96829 | (char*)pKeyMerge, P4_KEYINFO_HANDOFF); |
| 96830 | + sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE); | |
| 96747 | 96831 | sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); |
| 96748 | 96832 | |
| 96749 | 96833 | /* Release temporary registers |
| 96750 | 96834 | */ |
| 96751 | 96835 | if( regPrev ){ |
| @@ -96809,13 +96893,10 @@ | ||
| 96809 | 96893 | }else{ |
| 96810 | 96894 | Expr *pNew; |
| 96811 | 96895 | assert( pEList!=0 && pExpr->iColumn<pEList->nExpr ); |
| 96812 | 96896 | assert( pExpr->pLeft==0 && pExpr->pRight==0 ); |
| 96813 | 96897 | pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0); |
| 96814 | - if( pNew && pExpr->pColl ){ | |
| 96815 | - pNew->pColl = pExpr->pColl; | |
| 96816 | - } | |
| 96817 | 96898 | sqlite3ExprDelete(db, pExpr); |
| 96818 | 96899 | pExpr = pNew; |
| 96819 | 96900 | } |
| 96820 | 96901 | }else{ |
| 96821 | 96902 | pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList); |
| @@ -98151,10 +98232,19 @@ | ||
| 98151 | 98232 | */ |
| 98152 | 98233 | int addrTop; |
| 98153 | 98234 | int addrEof; |
| 98154 | 98235 | pItem->regReturn = ++pParse->nMem; |
| 98155 | 98236 | addrEof = ++pParse->nMem; |
| 98237 | + /* Before coding the OP_Goto to jump to the start of the main routine, | |
| 98238 | + ** ensure that the jump to the verify-schema routine has already | |
| 98239 | + ** been coded. Otherwise, the verify-schema would likely be coded as | |
| 98240 | + ** part of the co-routine. If the main routine then accessed the | |
| 98241 | + ** database before invoking the co-routine for the first time (for | |
| 98242 | + ** example to initialize a LIMIT register from a sub-select), it would | |
| 98243 | + ** be doing so without having verified the schema version and obtained | |
| 98244 | + ** the required db locks. See ticket d6b36be38. */ | |
| 98245 | + sqlite3CodeVerifySchema(pParse, -1); | |
| 98156 | 98246 | sqlite3VdbeAddOp0(v, OP_Goto); |
| 98157 | 98247 | addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor); |
| 98158 | 98248 | sqlite3VdbeChangeP5(v, 1); |
| 98159 | 98249 | VdbeComment((v, "coroutine for %s", pItem->pTab->zName)); |
| 98160 | 98250 | pItem->addrFillSub = addrTop; |
| @@ -99827,10 +99917,19 @@ | ||
| 99827 | 99917 | ** |
| 99828 | 99918 | ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy |
| 99829 | 99919 | ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy |
| 99830 | 99920 | */ |
| 99831 | 99921 | pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf; |
| 99922 | + | |
| 99923 | + /* Clear the cookieGoto flag. When coding triggers, the cookieGoto | |
| 99924 | + ** variable is used as a flag to indicate to sqlite3ExprCodeConstants() | |
| 99925 | + ** that it is not safe to refactor constants (this happens after the | |
| 99926 | + ** start of the first loop in the SQL statement is coded - at that | |
| 99927 | + ** point code may be conditionally executed, so it is no longer safe to | |
| 99928 | + ** initialize constant register values). */ | |
| 99929 | + assert( pParse->cookieGoto==0 || pParse->cookieGoto==-1 ); | |
| 99930 | + pParse->cookieGoto = 0; | |
| 99832 | 99931 | |
| 99833 | 99932 | switch( pStep->op ){ |
| 99834 | 99933 | case TK_UPDATE: { |
| 99835 | 99934 | sqlite3Update(pParse, |
| 99836 | 99935 | targetSrcList(pParse, pStep), |
| @@ -102913,27 +103012,36 @@ | ||
| 102913 | 103012 | |
| 102914 | 103013 | /* |
| 102915 | 103014 | ** Commute a comparison operator. Expressions of the form "X op Y" |
| 102916 | 103015 | ** are converted into "Y op X". |
| 102917 | 103016 | ** |
| 102918 | -** If a collation sequence is associated with either the left or right | |
| 103017 | +** If left/right precendence rules come into play when determining the | |
| 103018 | +** collating | |
| 102919 | 103019 | ** side of the comparison, it remains associated with the same side after |
| 102920 | 103020 | ** the commutation. So "Y collate NOCASE op X" becomes |
| 102921 | -** "X collate NOCASE op Y". This is because any collation sequence on | |
| 103021 | +** "X op Y". This is because any collation sequence on | |
| 102922 | 103022 | ** the left hand side of a comparison overrides any collation sequence |
| 102923 | -** attached to the right. For the same reason the EP_ExpCollate flag | |
| 103023 | +** attached to the right. For the same reason the EP_Collate flag | |
| 102924 | 103024 | ** is not commuted. |
| 102925 | 103025 | */ |
| 102926 | 103026 | static void exprCommute(Parse *pParse, Expr *pExpr){ |
| 102927 | - u16 expRight = (pExpr->pRight->flags & EP_ExpCollate); | |
| 102928 | - u16 expLeft = (pExpr->pLeft->flags & EP_ExpCollate); | |
| 103027 | + u16 expRight = (pExpr->pRight->flags & EP_Collate); | |
| 103028 | + u16 expLeft = (pExpr->pLeft->flags & EP_Collate); | |
| 102929 | 103029 | assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN ); |
| 102930 | - pExpr->pRight->pColl = sqlite3ExprCollSeq(pParse, pExpr->pRight); | |
| 102931 | - pExpr->pLeft->pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); | |
| 102932 | - SWAP(CollSeq*,pExpr->pRight->pColl,pExpr->pLeft->pColl); | |
| 102933 | - pExpr->pRight->flags = (pExpr->pRight->flags & ~EP_ExpCollate) | expLeft; | |
| 102934 | - pExpr->pLeft->flags = (pExpr->pLeft->flags & ~EP_ExpCollate) | expRight; | |
| 103030 | + if( expRight==expLeft ){ | |
| 103031 | + /* Either X and Y both have COLLATE operator or neither do */ | |
| 103032 | + if( expRight ){ | |
| 103033 | + /* Both X and Y have COLLATE operators. Make sure X is always | |
| 103034 | + ** used by clearing the EP_Collate flag from Y. */ | |
| 103035 | + pExpr->pRight->flags &= ~EP_Collate; | |
| 103036 | + }else if( sqlite3ExprCollSeq(pParse, pExpr->pLeft)!=0 ){ | |
| 103037 | + /* Neither X nor Y have COLLATE operators, but X has a non-default | |
| 103038 | + ** collating sequence. So add the EP_Collate marker on X to cause | |
| 103039 | + ** it to be searched first. */ | |
| 103040 | + pExpr->pLeft->flags |= EP_Collate; | |
| 103041 | + } | |
| 103042 | + } | |
| 102935 | 103043 | SWAP(Expr*,pExpr->pRight,pExpr->pLeft); |
| 102936 | 103044 | if( pExpr->op>=TK_GT ){ |
| 102937 | 103045 | assert( TK_LT==TK_GT+2 ); |
| 102938 | 103046 | assert( TK_GE==TK_LE+2 ); |
| 102939 | 103047 | assert( TK_GT>TK_EQ ); |
| @@ -103006,16 +103114,16 @@ | ||
| 103006 | 103114 | ** it to be useful for optimising expression pX. Store this |
| 103007 | 103115 | ** value in variable pColl. |
| 103008 | 103116 | */ |
| 103009 | 103117 | assert(pX->pLeft); |
| 103010 | 103118 | pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| 103011 | - assert(pColl || pParse->nErr); | |
| 103119 | + if( pColl==0 ) pColl = pParse->db->pDfltColl; | |
| 103012 | 103120 | |
| 103013 | 103121 | for(j=0; pIdx->aiColumn[j]!=iColumn; j++){ |
| 103014 | 103122 | if( NEVER(j>=pIdx->nColumn) ) return 0; |
| 103015 | 103123 | } |
| 103016 | - if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue; | |
| 103124 | + if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue; | |
| 103017 | 103125 | } |
| 103018 | 103126 | return pTerm; |
| 103019 | 103127 | } |
| 103020 | 103128 | } |
| 103021 | 103129 | } |
| @@ -103529,11 +103637,11 @@ | ||
| 103529 | 103637 | if( db->mallocFailed ){ |
| 103530 | 103638 | return; |
| 103531 | 103639 | } |
| 103532 | 103640 | pTerm = &pWC->a[idxTerm]; |
| 103533 | 103641 | pMaskSet = pWC->pMaskSet; |
| 103534 | - pExpr = pTerm->pExpr; | |
| 103642 | + pExpr = sqlite3ExprSkipCollate(pTerm->pExpr); | |
| 103535 | 103643 | prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); |
| 103536 | 103644 | op = pExpr->op; |
| 103537 | 103645 | if( op==TK_IN ){ |
| 103538 | 103646 | assert( pExpr->pRight==0 ); |
| 103539 | 103647 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| @@ -103556,12 +103664,12 @@ | ||
| 103556 | 103664 | pTerm->prereqAll = prereqAll; |
| 103557 | 103665 | pTerm->leftCursor = -1; |
| 103558 | 103666 | pTerm->iParent = -1; |
| 103559 | 103667 | pTerm->eOperator = 0; |
| 103560 | 103668 | if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){ |
| 103561 | - Expr *pLeft = pExpr->pLeft; | |
| 103562 | - Expr *pRight = pExpr->pRight; | |
| 103669 | + Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft); | |
| 103670 | + Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight); | |
| 103563 | 103671 | if( pLeft->op==TK_COLUMN ){ |
| 103564 | 103672 | pTerm->leftCursor = pLeft->iTable; |
| 103565 | 103673 | pTerm->u.leftColumn = pLeft->iColumn; |
| 103566 | 103674 | pTerm->eOperator = operatorMask(op); |
| 103567 | 103675 | } |
| @@ -103585,11 +103693,11 @@ | ||
| 103585 | 103693 | }else{ |
| 103586 | 103694 | pDup = pExpr; |
| 103587 | 103695 | pNew = pTerm; |
| 103588 | 103696 | } |
| 103589 | 103697 | exprCommute(pParse, pDup); |
| 103590 | - pLeft = pDup->pLeft; | |
| 103698 | + pLeft = sqlite3ExprSkipCollate(pDup->pLeft); | |
| 103591 | 103699 | pNew->leftCursor = pLeft->iTable; |
| 103592 | 103700 | pNew->u.leftColumn = pLeft->iColumn; |
| 103593 | 103701 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 103594 | 103702 | pNew->prereqRight = prereqLeft | extraRight; |
| 103595 | 103703 | pNew->prereqAll = prereqAll; |
| @@ -103664,11 +103772,11 @@ | ||
| 103664 | 103772 | Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */ |
| 103665 | 103773 | Expr *pNewExpr1; |
| 103666 | 103774 | Expr *pNewExpr2; |
| 103667 | 103775 | int idxNew1; |
| 103668 | 103776 | int idxNew2; |
| 103669 | - CollSeq *pColl; /* Collating sequence to use */ | |
| 103777 | + Token sCollSeqName; /* Name of collating sequence */ | |
| 103670 | 103778 | |
| 103671 | 103779 | pLeft = pExpr->x.pList->a[1].pExpr; |
| 103672 | 103780 | pStr2 = sqlite3ExprDup(db, pStr1, 0); |
| 103673 | 103781 | if( !db->mallocFailed ){ |
| 103674 | 103782 | u8 c, *pC; /* Last character before the first wildcard */ |
| @@ -103686,20 +103794,23 @@ | ||
| 103686 | 103794 | |
| 103687 | 103795 | c = sqlite3UpperToLower[c]; |
| 103688 | 103796 | } |
| 103689 | 103797 | *pC = c + 1; |
| 103690 | 103798 | } |
| 103691 | - pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0); | |
| 103799 | + sCollSeqName.z = noCase ? "NOCASE" : "BINARY"; | |
| 103800 | + sCollSeqName.n = 6; | |
| 103801 | + pNewExpr1 = sqlite3ExprDup(db, pLeft, 0); | |
| 103692 | 103802 | pNewExpr1 = sqlite3PExpr(pParse, TK_GE, |
| 103693 | - sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl), | |
| 103694 | - pStr1, 0); | |
| 103803 | + sqlite3ExprAddCollateToken(pParse,pNewExpr1,&sCollSeqName), | |
| 103804 | + pStr1, 0); | |
| 103695 | 103805 | idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); |
| 103696 | 103806 | testcase( idxNew1==0 ); |
| 103697 | 103807 | exprAnalyze(pSrc, pWC, idxNew1); |
| 103808 | + pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); | |
| 103698 | 103809 | pNewExpr2 = sqlite3PExpr(pParse, TK_LT, |
| 103699 | - sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl), | |
| 103700 | - pStr2, 0); | |
| 103810 | + sqlite3ExprAddCollateToken(pParse,pNewExpr2,&sCollSeqName), | |
| 103811 | + pStr2, 0); | |
| 103701 | 103812 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); |
| 103702 | 103813 | testcase( idxNew2==0 ); |
| 103703 | 103814 | exprAnalyze(pSrc, pWC, idxNew2); |
| 103704 | 103815 | pTerm = &pWC->a[idxTerm]; |
| 103705 | 103816 | if( isComplete ){ |
| @@ -103813,16 +103924,16 @@ | ||
| 103813 | 103924 | ){ |
| 103814 | 103925 | int i; |
| 103815 | 103926 | const char *zColl = pIdx->azColl[iCol]; |
| 103816 | 103927 | |
| 103817 | 103928 | for(i=0; i<pList->nExpr; i++){ |
| 103818 | - Expr *p = pList->a[i].pExpr; | |
| 103929 | + Expr *p = sqlite3ExprSkipCollate(pList->a[i].pExpr); | |
| 103819 | 103930 | if( p->op==TK_COLUMN |
| 103820 | 103931 | && p->iColumn==pIdx->aiColumn[iCol] |
| 103821 | 103932 | && p->iTable==iBase |
| 103822 | 103933 | ){ |
| 103823 | - CollSeq *pColl = sqlite3ExprCollSeq(pParse, p); | |
| 103934 | + CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); | |
| 103824 | 103935 | if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ |
| 103825 | 103936 | return i; |
| 103826 | 103937 | } |
| 103827 | 103938 | } |
| 103828 | 103939 | } |
| @@ -103865,11 +103976,11 @@ | ||
| 103865 | 103976 | ** matching "col=X" expression and the column is on the same table as pIdx, |
| 103866 | 103977 | ** set the corresponding bit in variable mask. |
| 103867 | 103978 | */ |
| 103868 | 103979 | for(i=0; i<pDistinct->nExpr; i++){ |
| 103869 | 103980 | WhereTerm *pTerm; |
| 103870 | - Expr *p = pDistinct->a[i].pExpr; | |
| 103981 | + Expr *p = sqlite3ExprSkipCollate(pDistinct->a[i].pExpr); | |
| 103871 | 103982 | if( p->op!=TK_COLUMN ) return 0; |
| 103872 | 103983 | pTerm = findTerm(pWC, p->iTable, p->iColumn, ~(Bitmask)0, WO_EQ, 0); |
| 103873 | 103984 | if( pTerm ){ |
| 103874 | 103985 | Expr *pX = pTerm->pExpr; |
| 103875 | 103986 | CollSeq *p1 = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| @@ -103917,11 +104028,11 @@ | ||
| 103917 | 104028 | /* If any of the expressions is an IPK column on table iBase, then return |
| 103918 | 104029 | ** true. Note: The (p->iTable==iBase) part of this test may be false if the |
| 103919 | 104030 | ** current SELECT is a correlated sub-query. |
| 103920 | 104031 | */ |
| 103921 | 104032 | for(i=0; i<pDistinct->nExpr; i++){ |
| 103922 | - Expr *p = pDistinct->a[i].pExpr; | |
| 104033 | + Expr *p = sqlite3ExprSkipCollate(pDistinct->a[i].pExpr); | |
| 103923 | 104034 | if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1; |
| 103924 | 104035 | } |
| 103925 | 104036 | |
| 103926 | 104037 | /* Loop through all indices on the table, checking each to see if it makes |
| 103927 | 104038 | ** the DISTINCT qualifier redundant. It does so if: |
| @@ -105203,11 +105314,11 @@ | ||
| 105203 | 105314 | WhereTerm *pConstraint; /* A constraint in the WHERE clause */ |
| 105204 | 105315 | |
| 105205 | 105316 | /* If the next term of the ORDER BY clause refers to anything other than |
| 105206 | 105317 | ** a column in the "base" table, then this index will not be of any |
| 105207 | 105318 | ** further use in handling the ORDER BY. */ |
| 105208 | - pOBExpr = pOBItem->pExpr; | |
| 105319 | + pOBExpr = sqlite3ExprSkipCollate(pOBItem->pExpr); | |
| 105209 | 105320 | if( pOBExpr->op!=TK_COLUMN || pOBExpr->iTable!=base ){ |
| 105210 | 105321 | break; |
| 105211 | 105322 | } |
| 105212 | 105323 | |
| 105213 | 105324 | /* Find column number and collating sequence for the next entry |
| @@ -105229,11 +105340,11 @@ | ||
| 105229 | 105340 | /* Check to see if the column number and collating sequence of the |
| 105230 | 105341 | ** index match the column number and collating sequence of the ORDER BY |
| 105231 | 105342 | ** clause entry. Set isMatch to 1 if they both match. */ |
| 105232 | 105343 | if( pOBExpr->iColumn==iColumn ){ |
| 105233 | 105344 | if( zColl ){ |
| 105234 | - pColl = sqlite3ExprCollSeq(pParse, pOBExpr); | |
| 105345 | + pColl = sqlite3ExprCollSeq(pParse, pOBItem->pExpr); | |
| 105235 | 105346 | if( !pColl ) pColl = db->pDfltColl; |
| 105236 | 105347 | isMatch = sqlite3StrICmp(pColl->zName, zColl)==0; |
| 105237 | 105348 | }else{ |
| 105238 | 105349 | isMatch = 1; |
| 105239 | 105350 | } |
| @@ -105370,10 +105481,15 @@ | ||
| 105370 | 105481 | int idxEqTermMask; /* Index mask of valid equality operators */ |
| 105371 | 105482 | Index sPk; /* A fake index object for the primary key */ |
| 105372 | 105483 | tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */ |
| 105373 | 105484 | int aiColumnPk = -1; /* The aColumn[] value for the sPk index */ |
| 105374 | 105485 | int wsFlagMask; /* Allowed flags in p->cost.plan.wsFlag */ |
| 105486 | + int nPriorSat; /* ORDER BY terms satisfied by outer loops */ | |
| 105487 | + int nOrderBy; /* Number of ORDER BY terms */ | |
| 105488 | + char bSortInit; /* Initializer for bSort in inner loop */ | |
| 105489 | + char bDistInit; /* Initializer for bDist in inner loop */ | |
| 105490 | + | |
| 105375 | 105491 | |
| 105376 | 105492 | /* Initialize the cost to a worst-case value */ |
| 105377 | 105493 | memset(&p->cost, 0, sizeof(p->cost)); |
| 105378 | 105494 | p->cost.rCost = SQLITE_BIG_DBL; |
| 105379 | 105495 | |
| @@ -105418,10 +105534,21 @@ | ||
| 105418 | 105534 | WHERE_COLUMN_IN|WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_RANGE |
| 105419 | 105535 | ); |
| 105420 | 105536 | eqTermMask = WO_EQ|WO_IN; |
| 105421 | 105537 | pIdx = 0; |
| 105422 | 105538 | } |
| 105539 | + | |
| 105540 | + nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0; | |
| 105541 | + if( p->i ){ | |
| 105542 | + nPriorSat = p->aLevel[p->i-1].plan.nOBSat; | |
| 105543 | + bSortInit = nPriorSat<nOrderBy; | |
| 105544 | + bDistInit = 0; | |
| 105545 | + }else{ | |
| 105546 | + nPriorSat = 0; | |
| 105547 | + bSortInit = nOrderBy>0; | |
| 105548 | + bDistInit = p->pDistinct!=0; | |
| 105549 | + } | |
| 105423 | 105550 | |
| 105424 | 105551 | /* Loop over all indices looking for the best one to use |
| 105425 | 105552 | */ |
| 105426 | 105553 | for(; pProbe; pIdx=pProbe=pProbe->pNext){ |
| 105427 | 105554 | const tRowcnt * const aiRowEst = pProbe->aiRowEst; |
| @@ -105496,15 +105623,13 @@ | ||
| 105496 | 105623 | */ |
| 105497 | 105624 | int bInEst = 0; /* True if "x IN (SELECT...)" seen */ |
| 105498 | 105625 | int nInMul = 1; /* Number of distinct equalities to lookup */ |
| 105499 | 105626 | double rangeDiv = (double)1; /* Estimated reduction in search space */ |
| 105500 | 105627 | int nBound = 0; /* Number of range constraints seen */ |
| 105501 | - int bSort; /* True if external sort required */ | |
| 105502 | - int bDist; /* True if index cannot help with DISTINCT */ | |
| 105503 | - int bLookup = 0; /* True if not a covering index */ | |
| 105504 | - int nPriorSat; /* ORDER BY terms satisfied by outer loops */ | |
| 105505 | - int nOrderBy; /* Number of ORDER BY terms */ | |
| 105628 | + char bSort = bSortInit; /* True if external sort required */ | |
| 105629 | + char bDist = bDistInit; /* True if index cannot help with DISTINCT */ | |
| 105630 | + char bLookup = 0; /* True if not a covering index */ | |
| 105506 | 105631 | WhereTerm *pTerm; /* A single term of the WHERE clause */ |
| 105507 | 105632 | #ifdef SQLITE_ENABLE_STAT3 |
| 105508 | 105633 | WhereTerm *pFirstTerm = 0; /* First term matching the index */ |
| 105509 | 105634 | #endif |
| 105510 | 105635 | |
| @@ -105511,20 +105636,11 @@ | ||
| 105511 | 105636 | WHERETRACE(( |
| 105512 | 105637 | " %s(%s):\n", |
| 105513 | 105638 | pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk") |
| 105514 | 105639 | )); |
| 105515 | 105640 | memset(&pc, 0, sizeof(pc)); |
| 105516 | - nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0; | |
| 105517 | - if( p->i ){ | |
| 105518 | - nPriorSat = pc.plan.nOBSat = p->aLevel[p->i-1].plan.nOBSat; | |
| 105519 | - bSort = nPriorSat<nOrderBy; | |
| 105520 | - bDist = 0; | |
| 105521 | - }else{ | |
| 105522 | - nPriorSat = pc.plan.nOBSat = 0; | |
| 105523 | - bSort = nOrderBy>0; | |
| 105524 | - bDist = p->pDistinct!=0; | |
| 105525 | - } | |
| 105641 | + pc.plan.nOBSat = nPriorSat; | |
| 105526 | 105642 | |
| 105527 | 105643 | /* Determine the values of pc.plan.nEq and nInMul */ |
| 105528 | 105644 | for(pc.plan.nEq=0; pc.plan.nEq<pProbe->nColumn; pc.plan.nEq++){ |
| 105529 | 105645 | int j = pProbe->aiColumn[pc.plan.nEq]; |
| 105530 | 105646 | pTerm = findTerm(pWC, iCur, j, p->notReady, eqTermMask, pIdx); |
| @@ -110554,11 +110670,11 @@ | ||
| 110554 | 110670 | spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); |
| 110555 | 110671 | } |
| 110556 | 110672 | break; |
| 110557 | 110673 | case 194: /* expr ::= expr COLLATE ids */ |
| 110558 | 110674 | { |
| 110559 | - yygotominor.yy342.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy342.pExpr, &yymsp[0].minor.yy0); | |
| 110675 | + yygotominor.yy342.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy342.pExpr, &yymsp[0].minor.yy0); | |
| 110560 | 110676 | yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart; |
| 110561 | 110677 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110562 | 110678 | } |
| 110563 | 110679 | break; |
| 110564 | 110680 | case 195: /* expr ::= CAST LP expr AS typetoken RP */ |
| @@ -110813,28 +110929,20 @@ | ||
| 110813 | 110929 | case 244: /* uniqueflag ::= */ |
| 110814 | 110930 | {yygotominor.yy392 = OE_None;} |
| 110815 | 110931 | break; |
| 110816 | 110932 | case 247: /* idxlist ::= idxlist COMMA nm collate sortorder */ |
| 110817 | 110933 | { |
| 110818 | - Expr *p = 0; | |
| 110819 | - if( yymsp[-1].minor.yy0.n>0 ){ | |
| 110820 | - p = sqlite3Expr(pParse->db, TK_COLUMN, 0); | |
| 110821 | - sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0); | |
| 110822 | - } | |
| 110934 | + Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0); | |
| 110823 | 110935 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, p); |
| 110824 | 110936 | sqlite3ExprListSetName(pParse,yygotominor.yy442,&yymsp[-2].minor.yy0,1); |
| 110825 | 110937 | sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index"); |
| 110826 | 110938 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110827 | 110939 | } |
| 110828 | 110940 | break; |
| 110829 | 110941 | case 248: /* idxlist ::= nm collate sortorder */ |
| 110830 | 110942 | { |
| 110831 | - Expr *p = 0; | |
| 110832 | - if( yymsp[-1].minor.yy0.n>0 ){ | |
| 110833 | - p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); | |
| 110834 | - sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0); | |
| 110835 | - } | |
| 110943 | + Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0); | |
| 110836 | 110944 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, p); |
| 110837 | 110945 | sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1); |
| 110838 | 110946 | sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index"); |
| 110839 | 110947 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110840 | 110948 | } |
| 110841 | 110949 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -673,11 +673,11 @@ | |
| 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | */ |
| 676 | #define SQLITE_VERSION "3.7.15" |
| 677 | #define SQLITE_VERSION_NUMBER 3007015 |
| 678 | #define SQLITE_SOURCE_ID "2012-12-05 14:31:13 9f6c68856b694373b7ffb124abd996e519ba5921" |
| 679 | |
| 680 | /* |
| 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | ** |
| @@ -1421,11 +1421,10 @@ | |
| 1421 | ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
| 1422 | ** that the VFS encountered an error while handling the [PRAGMA] and the |
| 1423 | ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
| 1424 | ** file control occurs at the beginning of pragma statement analysis and so |
| 1425 | ** it is able to override built-in [PRAGMA] statements. |
| 1426 | ** </ul> |
| 1427 | ** |
| 1428 | ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
| 1429 | ** ^This file-control may be invoked by SQLite on the database file handle |
| 1430 | ** shortly after it is opened in order to provide a custom VFS with access |
| 1431 | ** to the connections busy-handler callback. The argument is of type (void **) |
| @@ -1433,10 +1432,20 @@ | |
| 1433 | ** to a function of type (int (*)(void *)). In order to invoke the connections |
| 1434 | ** busy-handler, this function should be invoked with the second (void *) in |
| 1435 | ** the array as the only argument. If it returns non-zero, then the operation |
| 1436 | ** should be retried. If it returns zero, the custom VFS should abandon the |
| 1437 | ** current operation. |
| 1438 | */ |
| 1439 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 1440 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 1441 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 1442 | #define SQLITE_LAST_ERRNO 4 |
| @@ -1449,10 +1458,11 @@ | |
| 1449 | #define SQLITE_FCNTL_OVERWRITE 11 |
| 1450 | #define SQLITE_FCNTL_VFSNAME 12 |
| 1451 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
| 1452 | #define SQLITE_FCNTL_PRAGMA 14 |
| 1453 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 1454 | |
| 1455 | /* |
| 1456 | ** CAPI3REF: Mutex Handle |
| 1457 | ** |
| 1458 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -10209,23 +10219,11 @@ | |
| 10209 | /* |
| 10210 | ** A "Collating Sequence" is defined by an instance of the following |
| 10211 | ** structure. Conceptually, a collating sequence consists of a name and |
| 10212 | ** a comparison routine that defines the order of that sequence. |
| 10213 | ** |
| 10214 | ** There may two separate implementations of the collation function, one |
| 10215 | ** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that |
| 10216 | ** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine |
| 10217 | ** native byte order. When a collation sequence is invoked, SQLite selects |
| 10218 | ** the version that will require the least expensive encoding |
| 10219 | ** translations, if any. |
| 10220 | ** |
| 10221 | ** The CollSeq.pUser member variable is an extra parameter that passed in |
| 10222 | ** as the first argument to the UTF-8 comparison function, xCmp. |
| 10223 | ** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function, |
| 10224 | ** xCmp16. |
| 10225 | ** |
| 10226 | ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the |
| 10227 | ** collating sequence is undefined. Indices built on an undefined |
| 10228 | ** collating sequence may not be read or written. |
| 10229 | */ |
| 10230 | struct CollSeq { |
| 10231 | char *zName; /* Name of the collating sequence, UTF-8 encoded */ |
| @@ -10749,11 +10747,10 @@ | |
| 10749 | Expr *pRight; /* Right subnode */ |
| 10750 | union { |
| 10751 | ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */ |
| 10752 | Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */ |
| 10753 | } x; |
| 10754 | CollSeq *pColl; /* The collation type of the column or 0 */ |
| 10755 | |
| 10756 | /* If the EP_Reduced flag is set in the Expr.flags mask, then no |
| 10757 | ** space is allocated for the fields below this point. An attempt to |
| 10758 | ** access them will result in a segfault or malfunction. |
| 10759 | *********************************************************************/ |
| @@ -10785,11 +10782,11 @@ | |
| 10785 | #define EP_Error 0x0008 /* Expression contains one or more errors */ |
| 10786 | #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */ |
| 10787 | #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ |
| 10788 | #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */ |
| 10789 | #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ |
| 10790 | #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */ |
| 10791 | #define EP_FixedDest 0x0200 /* Result needed in a specific register */ |
| 10792 | #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ |
| 10793 | #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ |
| 10794 | #define EP_Hint 0x1000 /* Not used */ |
| 10795 | #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ |
| @@ -11402,10 +11399,11 @@ | |
| 11402 | #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */ |
| 11403 | #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ |
| 11404 | #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ |
| 11405 | #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ |
| 11406 | #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */ |
| 11407 | |
| 11408 | /* |
| 11409 | * Each trigger present in the database schema is stored as an instance of |
| 11410 | * struct Trigger. |
| 11411 | * |
| @@ -12093,12 +12091,13 @@ | |
| 12093 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 12094 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 12095 | SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 12096 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| 12097 | SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); |
| 12098 | SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*); |
| 12099 | SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*); |
| 12100 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 12101 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *); |
| 12102 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 12103 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 12104 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| @@ -26456,10 +26455,13 @@ | |
| 26456 | }else{ |
| 26457 | pFile->ctrlFlags |= mask; |
| 26458 | } |
| 26459 | } |
| 26460 | |
| 26461 | /* |
| 26462 | ** Information and control of an open file handle. |
| 26463 | */ |
| 26464 | static int unixFileControl(sqlite3_file *id, int op, void *pArg){ |
| 26465 | unixFile *pFile = (unixFile*)id; |
| @@ -26492,10 +26494,18 @@ | |
| 26492 | return SQLITE_OK; |
| 26493 | } |
| 26494 | case SQLITE_FCNTL_VFSNAME: { |
| 26495 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 26496 | return SQLITE_OK; |
| 26497 | } |
| 26498 | #ifdef SQLITE_DEBUG |
| 26499 | /* The pager calls this method to signal that it has done |
| 26500 | ** a rollback and that the database is therefore unchanged and |
| 26501 | ** it hence it is OK for the transaction change counter to be |
| @@ -32782,10 +32792,13 @@ | |
| 32782 | }else{ |
| 32783 | pFile->ctrlFlags |= mask; |
| 32784 | } |
| 32785 | } |
| 32786 | |
| 32787 | /* |
| 32788 | ** Control and query of the open file handle. |
| 32789 | */ |
| 32790 | static int winFileControl(sqlite3_file *id, int op, void *pArg){ |
| 32791 | winFile *pFile = (winFile*)id; |
| @@ -32841,10 +32854,18 @@ | |
| 32841 | win32IoerrRetryDelay = a[1]; |
| 32842 | }else{ |
| 32843 | a[1] = win32IoerrRetryDelay; |
| 32844 | } |
| 32845 | return SQLITE_OK; |
| 32846 | } |
| 32847 | } |
| 32848 | return SQLITE_NOTFOUND; |
| 32849 | } |
| 32850 | |
| @@ -59392,26 +59413,22 @@ | |
| 59392 | assert( pKeyInfo->aSortOrder!=0 ); |
| 59393 | sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField); |
| 59394 | i = sqlite3Strlen30(zTemp); |
| 59395 | for(j=0; j<pKeyInfo->nField; j++){ |
| 59396 | CollSeq *pColl = pKeyInfo->aColl[j]; |
| 59397 | if( pColl ){ |
| 59398 | int n = sqlite3Strlen30(pColl->zName); |
| 59399 | if( i+n>nTemp-6 ){ |
| 59400 | memcpy(&zTemp[i],",...",4); |
| 59401 | break; |
| 59402 | } |
| 59403 | zTemp[i++] = ','; |
| 59404 | if( pKeyInfo->aSortOrder[j] ){ |
| 59405 | zTemp[i++] = '-'; |
| 59406 | } |
| 59407 | memcpy(&zTemp[i], pColl->zName,n+1); |
| 59408 | i += n; |
| 59409 | }else if( i+4<nTemp-6 ){ |
| 59410 | memcpy(&zTemp[i],",nil",4); |
| 59411 | i += 4; |
| 59412 | } |
| 59413 | } |
| 59414 | zTemp[i++] = ')'; |
| 59415 | zTemp[i] = 0; |
| 59416 | assert( i<nTemp ); |
| 59417 | break; |
| @@ -63797,11 +63814,13 @@ | |
| 63797 | #ifdef SQLITE_DEBUG |
| 63798 | /* |
| 63799 | ** Print the value of a register for tracing purposes: |
| 63800 | */ |
| 63801 | static void memTracePrint(FILE *out, Mem *p){ |
| 63802 | if( p->flags & MEM_Null ){ |
| 63803 | fprintf(out, " NULL"); |
| 63804 | }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ |
| 63805 | fprintf(out, " si:%lld", p->u.i); |
| 63806 | }else if( p->flags & MEM_Int ){ |
| 63807 | fprintf(out, " i:%lld", p->u.i); |
| @@ -64979,10 +64998,13 @@ | |
| 64979 | pOut = &aMem[pOp->p2]; |
| 64980 | assert( pOut!=pIn1 ); |
| 64981 | while( 1 ){ |
| 64982 | sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); |
| 64983 | Deephemeralize(pOut); |
| 64984 | REGISTER_TRACE(pOp->p2+pOp->p3-u.ae.n, pOut); |
| 64985 | if( (u.ae.n--)==0 ) break; |
| 64986 | pOut++; |
| 64987 | pIn1++; |
| 64988 | } |
| @@ -65801,26 +65823,31 @@ | |
| 65801 | /* Opcode: Permutation * * * P4 * |
| 65802 | ** |
| 65803 | ** Set the permutation used by the OP_Compare operator to be the array |
| 65804 | ** of integers in P4. |
| 65805 | ** |
| 65806 | ** The permutation is only valid until the next OP_Permutation, OP_Compare, |
| 65807 | ** OP_Halt, or OP_ResultRow. Typically the OP_Permutation should occur |
| 65808 | ** immediately prior to the OP_Compare. |
| 65809 | */ |
| 65810 | case OP_Permutation: { |
| 65811 | assert( pOp->p4type==P4_INTARRAY ); |
| 65812 | assert( pOp->p4.ai ); |
| 65813 | aPermute = pOp->p4.ai; |
| 65814 | break; |
| 65815 | } |
| 65816 | |
| 65817 | /* Opcode: Compare P1 P2 P3 P4 * |
| 65818 | ** |
| 65819 | ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this |
| 65820 | ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of |
| 65821 | ** the comparison for use by the next OP_Jump instruct. |
| 65822 | ** |
| 65823 | ** P4 is a KeyInfo structure that defines collating sequences and sort |
| 65824 | ** orders for the comparison. The permutation applies to registers |
| 65825 | ** only. The KeyInfo elements are used sequentially. |
| 65826 | ** |
| @@ -65838,10 +65865,11 @@ | |
| 65838 | int idx; |
| 65839 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 65840 | int bRev; /* True for DESCENDING sort order */ |
| 65841 | #endif /* local variables moved into u.al */ |
| 65842 | |
| 65843 | u.al.n = pOp->p3; |
| 65844 | u.al.pKeyInfo = pOp->p4.pKeyInfo; |
| 65845 | assert( u.al.n>0 ); |
| 65846 | assert( u.al.pKeyInfo!=0 ); |
| 65847 | u.al.p1 = pOp->p1; |
| @@ -72523,10 +72551,19 @@ | |
| 72523 | ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5 |
| 72524 | ** |
| 72525 | ** The result of random()%5 in the GROUP BY clause is probably different |
| 72526 | ** from the result in the result-set. We might fix this someday. Or |
| 72527 | ** then again, we might not... |
| 72528 | ** |
| 72529 | ** The nSubquery parameter specifies how many levels of subquery the |
| 72530 | ** alias is removed from the original expression. The usually value is |
| 72531 | ** zero but it might be more if the alias is contained within a subquery |
| 72532 | ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION |
| @@ -72547,45 +72584,40 @@ | |
| 72547 | assert( iCol>=0 && iCol<pEList->nExpr ); |
| 72548 | pOrig = pEList->a[iCol].pExpr; |
| 72549 | assert( pOrig!=0 ); |
| 72550 | assert( pOrig->flags & EP_Resolved ); |
| 72551 | db = pParse->db; |
| 72552 | if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ |
| 72553 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 72554 | incrAggFunctionDepth(pDup, nSubquery); |
| 72555 | pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0); |
| 72556 | if( pDup==0 ) return; |
| 72557 | if( pEList->a[iCol].iAlias==0 ){ |
| 72558 | pEList->a[iCol].iAlias = (u16)(++pParse->nAlias); |
| 72559 | } |
| 72560 | pDup->iTable = pEList->a[iCol].iAlias; |
| 72561 | }else if( ExprHasProperty(pOrig, EP_IntValue) || pOrig->u.zToken==0 ){ |
| 72562 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 72563 | if( pDup==0 ) return; |
| 72564 | }else{ |
| 72565 | char *zToken = pOrig->u.zToken; |
| 72566 | assert( zToken!=0 ); |
| 72567 | pOrig->u.zToken = 0; |
| 72568 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 72569 | pOrig->u.zToken = zToken; |
| 72570 | if( pDup==0 ) return; |
| 72571 | assert( (pDup->flags & (EP_Reduced|EP_TokenOnly))==0 ); |
| 72572 | pDup->flags2 |= EP2_MallocedToken; |
| 72573 | pDup->u.zToken = sqlite3DbStrDup(db, zToken); |
| 72574 | } |
| 72575 | if( pExpr->flags & EP_ExpCollate ){ |
| 72576 | pDup->pColl = pExpr->pColl; |
| 72577 | pDup->flags |= EP_ExpCollate; |
| 72578 | } |
| 72579 | |
| 72580 | /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This |
| 72581 | ** prevents ExprDelete() from deleting the Expr structure itself, |
| 72582 | ** allowing it to be repopulated by the memcpy() on the following line. |
| 72583 | */ |
| 72584 | ExprSetProperty(pExpr, EP_Static); |
| 72585 | sqlite3ExprDelete(db, pExpr); |
| 72586 | memcpy(pExpr, pDup, sizeof(*pExpr)); |
| 72587 | sqlite3DbFree(db, pDup); |
| 72588 | } |
| 72589 | |
| 72590 | |
| 72591 | /* |
| @@ -73268,11 +73300,11 @@ | |
| 73268 | assert( pEList!=0 ); |
| 73269 | for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ |
| 73270 | int iCol = -1; |
| 73271 | Expr *pE, *pDup; |
| 73272 | if( pItem->done ) continue; |
| 73273 | pE = pItem->pExpr; |
| 73274 | if( sqlite3ExprIsInteger(pE, &iCol) ){ |
| 73275 | if( iCol<=0 || iCol>pEList->nExpr ){ |
| 73276 | resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); |
| 73277 | return 1; |
| 73278 | } |
| @@ -73286,18 +73318,24 @@ | |
| 73286 | } |
| 73287 | sqlite3ExprDelete(db, pDup); |
| 73288 | } |
| 73289 | } |
| 73290 | if( iCol>0 ){ |
| 73291 | CollSeq *pColl = pE->pColl; |
| 73292 | int flags = pE->flags & EP_ExpCollate; |
| 73293 | sqlite3ExprDelete(db, pE); |
| 73294 | pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0); |
| 73295 | if( pE==0 ) return 1; |
| 73296 | pE->pColl = pColl; |
| 73297 | pE->flags |= EP_IntValue | flags; |
| 73298 | pE->u.iValue = iCol; |
| 73299 | pItem->iOrderByCol = (u16)iCol; |
| 73300 | pItem->done = 1; |
| 73301 | }else{ |
| 73302 | moreToDo = 1; |
| 73303 | } |
| @@ -73398,15 +73436,15 @@ | |
| 73398 | ** sqlite3ResolveOrderGroupBy() will convert the expression to a |
| 73399 | ** copy of the iCol-th result-set expression. */ |
| 73400 | pItem->iOrderByCol = (u16)iCol; |
| 73401 | continue; |
| 73402 | } |
| 73403 | if( sqlite3ExprIsInteger(pE, &iCol) ){ |
| 73404 | /* The ORDER BY term is an integer constant. Again, set the column |
| 73405 | ** number so that sqlite3ResolveOrderGroupBy() will convert the |
| 73406 | ** order-by term to a copy of the result-set expression */ |
| 73407 | if( iCol<1 ){ |
| 73408 | resolveOutOfRangeError(pParse, zType, i+1, nResult); |
| 73409 | return 1; |
| 73410 | } |
| 73411 | pItem->iOrderByCol = (u16)iCol; |
| 73412 | continue; |
| @@ -73756,11 +73794,13 @@ | |
| 73756 | ** SELECT * FROM t1 WHERE a; |
| 73757 | ** SELECT a AS b FROM t1 WHERE b; |
| 73758 | ** SELECT * FROM t1 WHERE (select a from t1); |
| 73759 | */ |
| 73760 | SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr){ |
| 73761 | int op = pExpr->op; |
| 73762 | if( op==TK_SELECT ){ |
| 73763 | assert( pExpr->flags&EP_xIsSelect ); |
| 73764 | return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); |
| 73765 | } |
| 73766 | #ifndef SQLITE_OMIT_CAST |
| @@ -73781,70 +73821,98 @@ | |
| 73781 | } |
| 73782 | return pExpr->affinity; |
| 73783 | } |
| 73784 | |
| 73785 | /* |
| 73786 | ** Set the explicit collating sequence for an expression to the |
| 73787 | ** collating sequence supplied in the second argument. |
| 73788 | */ |
| 73789 | SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr *pExpr, CollSeq *pColl){ |
| 73790 | if( pExpr && pColl ){ |
| 73791 | pExpr->pColl = pColl; |
| 73792 | pExpr->flags |= EP_ExpCollate; |
| 73793 | } |
| 73794 | return pExpr; |
| 73795 | } |
| 73796 | |
| 73797 | /* |
| 73798 | ** Set the collating sequence for expression pExpr to be the collating |
| 73799 | ** sequence named by pToken. Return a pointer to the revised expression. |
| 73800 | ** The collating sequence is marked as "explicit" using the EP_ExpCollate |
| 73801 | ** flag. An explicit collating sequence will override implicit |
| 73802 | ** collating sequences. |
| 73803 | */ |
| 73804 | SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr *pExpr, Token *pCollName){ |
| 73805 | char *zColl = 0; /* Dequoted name of collation sequence */ |
| 73806 | CollSeq *pColl; |
| 73807 | sqlite3 *db = pParse->db; |
| 73808 | zColl = sqlite3NameFromToken(db, pCollName); |
| 73809 | pColl = sqlite3LocateCollSeq(pParse, zColl); |
| 73810 | sqlite3ExprSetColl(pExpr, pColl); |
| 73811 | sqlite3DbFree(db, zColl); |
| 73812 | return pExpr; |
| 73813 | } |
| 73814 | |
| 73815 | /* |
| 73816 | ** Return the default collation sequence for the expression pExpr. If |
| 73817 | ** there is no default collation type, return 0. |
| 73818 | */ |
| 73819 | SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ |
| 73820 | CollSeq *pColl = 0; |
| 73821 | Expr *p = pExpr; |
| 73822 | while( p ){ |
| 73823 | int op; |
| 73824 | pColl = p->pColl; |
| 73825 | if( pColl ) break; |
| 73826 | op = p->op; |
| 73827 | if( p->pTab!=0 && ( |
| 73828 | op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER || op==TK_TRIGGER |
| 73829 | )){ |
| 73830 | /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally |
| 73831 | ** a TK_COLUMN but was previously evaluated and cached in a register */ |
| 73832 | const char *zColl; |
| 73833 | int j = p->iColumn; |
| 73834 | if( j>=0 ){ |
| 73835 | sqlite3 *db = pParse->db; |
| 73836 | zColl = p->pTab->aCol[j].zColl; |
| 73837 | pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 73838 | pExpr->pColl = pColl; |
| 73839 | } |
| 73840 | break; |
| 73841 | } |
| 73842 | if( op!=TK_CAST && op!=TK_UPLUS ){ |
| 73843 | break; |
| 73844 | } |
| 73845 | p = p->pLeft; |
| 73846 | } |
| 73847 | if( sqlite3CheckCollSeq(pParse, pColl) ){ |
| 73848 | pColl = 0; |
| 73849 | } |
| 73850 | return pColl; |
| @@ -73944,16 +74012,14 @@ | |
| 73944 | Expr *pLeft, |
| 73945 | Expr *pRight |
| 73946 | ){ |
| 73947 | CollSeq *pColl; |
| 73948 | assert( pLeft ); |
| 73949 | if( pLeft->flags & EP_ExpCollate ){ |
| 73950 | assert( pLeft->pColl ); |
| 73951 | pColl = pLeft->pColl; |
| 73952 | }else if( pRight && pRight->flags & EP_ExpCollate ){ |
| 73953 | assert( pRight->pColl ); |
| 73954 | pColl = pRight->pColl; |
| 73955 | }else{ |
| 73956 | pColl = sqlite3ExprCollSeq(pParse, pLeft); |
| 73957 | if( !pColl ){ |
| 73958 | pColl = sqlite3ExprCollSeq(pParse, pRight); |
| 73959 | } |
| @@ -74179,21 +74245,15 @@ | |
| 74179 | sqlite3ExprDelete(db, pLeft); |
| 74180 | sqlite3ExprDelete(db, pRight); |
| 74181 | }else{ |
| 74182 | if( pRight ){ |
| 74183 | pRoot->pRight = pRight; |
| 74184 | if( pRight->flags & EP_ExpCollate ){ |
| 74185 | pRoot->flags |= EP_ExpCollate; |
| 74186 | pRoot->pColl = pRight->pColl; |
| 74187 | } |
| 74188 | } |
| 74189 | if( pLeft ){ |
| 74190 | pRoot->pLeft = pLeft; |
| 74191 | if( pLeft->flags & EP_ExpCollate ){ |
| 74192 | pRoot->flags |= EP_ExpCollate; |
| 74193 | pRoot->pColl = pLeft->pColl; |
| 74194 | } |
| 74195 | } |
| 74196 | exprSetHeight(pRoot); |
| 74197 | } |
| 74198 | } |
| 74199 | |
| @@ -74447,11 +74507,11 @@ | |
| 74447 | }else{ |
| 74448 | assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 74449 | assert( !ExprHasProperty(p, EP_FromJoin) ); |
| 74450 | assert( (p->flags2 & EP2_MallocedToken)==0 ); |
| 74451 | assert( (p->flags2 & EP2_Irreducible)==0 ); |
| 74452 | if( p->pLeft || p->pRight || p->pColl || p->x.pList ){ |
| 74453 | nSize = EXPR_REDUCEDSIZE | EP_Reduced; |
| 74454 | }else{ |
| 74455 | nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly; |
| 74456 | } |
| 74457 | } |
| @@ -76471,10 +76531,11 @@ | |
| 76471 | sqlite3VdbeAddOp3(v, OP_And, r3, r4, target); |
| 76472 | sqlite3ReleaseTempReg(pParse, r3); |
| 76473 | sqlite3ReleaseTempReg(pParse, r4); |
| 76474 | break; |
| 76475 | } |
| 76476 | case TK_UPLUS: { |
| 76477 | inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); |
| 76478 | break; |
| 76479 | } |
| 76480 | |
| @@ -76839,10 +76900,16 @@ | |
| 76839 | case TK_UPLUS: zUniOp = "UPLUS"; break; |
| 76840 | case TK_BITNOT: zUniOp = "BITNOT"; break; |
| 76841 | case TK_NOT: zUniOp = "NOT"; break; |
| 76842 | case TK_ISNULL: zUniOp = "ISNULL"; break; |
| 76843 | case TK_NOTNULL: zUniOp = "NOTNULL"; break; |
| 76844 | |
| 76845 | case TK_AGG_FUNCTION: |
| 76846 | case TK_CONST_FUNC: |
| 76847 | case TK_FUNCTION: { |
| 76848 | ExprList *pFarg; /* List of function arguments */ |
| @@ -77058,10 +77125,13 @@ | |
| 77058 | switch( pExpr->op ){ |
| 77059 | case TK_IN: |
| 77060 | case TK_REGISTER: { |
| 77061 | return WRC_Prune; |
| 77062 | } |
| 77063 | case TK_FUNCTION: |
| 77064 | case TK_AGG_FUNCTION: |
| 77065 | case TK_CONST_FUNC: { |
| 77066 | /* The arguments to a function have a fixed destination. |
| 77067 | ** Mark them this way to avoid generated unneeded OP_SCopy |
| @@ -77079,13 +77149,15 @@ | |
| 77079 | break; |
| 77080 | } |
| 77081 | } |
| 77082 | if( isAppropriateForFactoring(pExpr) ){ |
| 77083 | int r1 = ++pParse->nMem; |
| 77084 | int r2; |
| 77085 | r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); |
| 77086 | if( NEVER(r1!=r2) ) sqlite3ReleaseTempReg(pParse, r1); |
| 77087 | pExpr->op2 = pExpr->op; |
| 77088 | pExpr->op = TK_REGISTER; |
| 77089 | pExpr->iTable = r2; |
| 77090 | return WRC_Prune; |
| 77091 | } |
| @@ -77498,11 +77570,19 @@ | |
| 77498 | assert( !ExprHasAnyProperty(pB, EP_TokenOnly|EP_Reduced) ); |
| 77499 | if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){ |
| 77500 | return 2; |
| 77501 | } |
| 77502 | if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2; |
| 77503 | if( pA->op!=pB->op ) return 2; |
| 77504 | if( sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 2; |
| 77505 | if( sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 2; |
| 77506 | if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList) ) return 2; |
| 77507 | if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2; |
| 77508 | if( ExprHasProperty(pA, EP_IntValue) ){ |
| @@ -77510,15 +77590,13 @@ | |
| 77510 | return 2; |
| 77511 | } |
| 77512 | }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){ |
| 77513 | if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; |
| 77514 | if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ |
| 77515 | return 2; |
| 77516 | } |
| 77517 | } |
| 77518 | if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1; |
| 77519 | if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2; |
| 77520 | return 0; |
| 77521 | } |
| 77522 | |
| 77523 | /* |
| 77524 | ** Compare two ExprList objects. Return 0 if they are identical and |
| @@ -80765,10 +80843,11 @@ | |
| 80765 | */ |
| 80766 | SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){ |
| 80767 | sqlite3 *db; |
| 80768 | Vdbe *v; |
| 80769 | |
| 80770 | db = pParse->db; |
| 80771 | if( db->mallocFailed ) return; |
| 80772 | if( pParse->nested ) return; |
| 80773 | if( pParse->nErr ) return; |
| 80774 | |
| @@ -83328,14 +83407,12 @@ | |
| 83328 | ** specified collation sequence names. |
| 83329 | */ |
| 83330 | for(i=0; i<pList->nExpr; i++){ |
| 83331 | Expr *pExpr = pList->a[i].pExpr; |
| 83332 | if( pExpr ){ |
| 83333 | CollSeq *pColl = pExpr->pColl; |
| 83334 | /* Either pColl!=0 or there was an OOM failure. But if an OOM |
| 83335 | ** failure we have quit before reaching this point. */ |
| 83336 | if( ALWAYS(pColl) ){ |
| 83337 | nExtra += (1 + sqlite3Strlen30(pColl->zName)); |
| 83338 | } |
| 83339 | } |
| 83340 | } |
| 83341 | |
| @@ -83394,10 +83471,11 @@ | |
| 83394 | */ |
| 83395 | for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){ |
| 83396 | const char *zColName = pListItem->zName; |
| 83397 | Column *pTabCol; |
| 83398 | int requestedSortOrder; |
| 83399 | char *zColl; /* Collation sequence name */ |
| 83400 | |
| 83401 | for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){ |
| 83402 | if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; |
| 83403 | } |
| @@ -83406,18 +83484,15 @@ | |
| 83406 | pTab->zName, zColName); |
| 83407 | pParse->checkSchema = 1; |
| 83408 | goto exit_create_index; |
| 83409 | } |
| 83410 | pIndex->aiColumn[i] = j; |
| 83411 | /* Justification of the ALWAYS(pListItem->pExpr->pColl): Because of |
| 83412 | ** the way the "idxlist" non-terminal is constructed by the parser, |
| 83413 | ** if pListItem->pExpr is not null then either pListItem->pExpr->pColl |
| 83414 | ** must exist or else there must have been an OOM error. But if there |
| 83415 | ** was an OOM error, we would never reach this point. */ |
| 83416 | if( pListItem->pExpr && ALWAYS(pListItem->pExpr->pColl) ){ |
| 83417 | int nColl; |
| 83418 | zColl = pListItem->pExpr->pColl->zName; |
| 83419 | nColl = sqlite3Strlen30(zColl) + 1; |
| 83420 | assert( nExtra>=nColl ); |
| 83421 | memcpy(zExtra, zColl, nColl); |
| 83422 | zColl = zExtra; |
| 83423 | zExtra += nColl; |
| @@ -84227,10 +84302,19 @@ | |
| 84227 | ** early in the code, before we know if any database tables will be used. |
| 84228 | */ |
| 84229 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ |
| 84230 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 84231 | |
| 84232 | if( pToplevel->cookieGoto==0 ){ |
| 84233 | Vdbe *v = sqlite3GetVdbe(pToplevel); |
| 84234 | if( v==0 ) return; /* This only happens if there was a prior error */ |
| 84235 | pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1; |
| 84236 | } |
| @@ -87806,16 +87890,19 @@ | |
| 87806 | if( pLeft ){ |
| 87807 | /* Set the collation sequence and affinity of the LHS of each TK_EQ |
| 87808 | ** expression to the parent key column defaults. */ |
| 87809 | if( pIdx ){ |
| 87810 | Column *pCol; |
| 87811 | iCol = pIdx->aiColumn[i]; |
| 87812 | pCol = &pTab->aCol[iCol]; |
| 87813 | if( pTab->iPKey==iCol ) iCol = -1; |
| 87814 | pLeft->iTable = regData+iCol+1; |
| 87815 | pLeft->affinity = pCol->affinity; |
| 87816 | pLeft->pColl = sqlite3LocateCollSeq(pParse, pCol->zColl); |
| 87817 | }else{ |
| 87818 | pLeft->iTable = regData; |
| 87819 | pLeft->affinity = SQLITE_AFF_INTEGER; |
| 87820 | } |
| 87821 | } |
| @@ -89791,29 +89878,24 @@ | |
| 89791 | ExprList *pCheck = pTab->pCheck; |
| 89792 | pParse->ckBase = regData; |
| 89793 | onError = overrideError!=OE_Default ? overrideError : OE_Abort; |
| 89794 | for(i=0; i<pCheck->nExpr; i++){ |
| 89795 | int allOk = sqlite3VdbeMakeLabel(v); |
| 89796 | Expr *pDup = sqlite3ExprDup(db, pCheck->a[i].pExpr, 0); |
| 89797 | if( !db->mallocFailed ){ |
| 89798 | assert( pDup!=0 ); |
| 89799 | sqlite3ExprIfTrue(pParse, pDup, allOk, SQLITE_JUMPIFNULL); |
| 89800 | if( onError==OE_Ignore ){ |
| 89801 | sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); |
| 89802 | }else{ |
| 89803 | char *zConsName = pCheck->a[i].zName; |
| 89804 | if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ |
| 89805 | if( zConsName ){ |
| 89806 | zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); |
| 89807 | }else{ |
| 89808 | zConsName = 0; |
| 89809 | } |
| 89810 | sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); |
| 89811 | } |
| 89812 | sqlite3VdbeResolveLabel(v, allOk); |
| 89813 | } |
| 89814 | sqlite3ExprDelete(db, pDup); |
| 89815 | } |
| 89816 | } |
| 89817 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| 89818 | |
| 89819 | /* If we have an INTEGER PRIMARY KEY, make sure the primary key |
| @@ -95536,11 +95618,11 @@ | |
| 95536 | *paCol = aCol; |
| 95537 | |
| 95538 | for(i=0, pCol=aCol; i<nCol; i++, pCol++){ |
| 95539 | /* Get an appropriate name for the column |
| 95540 | */ |
| 95541 | p = pEList->a[i].pExpr; |
| 95542 | assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue) |
| 95543 | || p->pRight->u.zToken==0 || p->pRight->u.zToken[0]!=0 ); |
| 95544 | if( (zName = pEList->a[i].zName)!=0 ){ |
| 95545 | /* If the column contains an "AS <name>" phrase, use <name> as the name */ |
| 95546 | zName = sqlite3DbStrDup(db, zName); |
| @@ -96534,16 +96616,17 @@ | |
| 96534 | pKeyMerge->nField = (u16)nOrderBy; |
| 96535 | pKeyMerge->enc = ENC(db); |
| 96536 | for(i=0; i<nOrderBy; i++){ |
| 96537 | CollSeq *pColl; |
| 96538 | Expr *pTerm = pOrderBy->a[i].pExpr; |
| 96539 | if( pTerm->flags & EP_ExpCollate ){ |
| 96540 | pColl = pTerm->pColl; |
| 96541 | }else{ |
| 96542 | pColl = multiSelectCollSeq(pParse, p, aPermute[i]); |
| 96543 | pTerm->flags |= EP_ExpCollate; |
| 96544 | pTerm->pColl = pColl; |
| 96545 | } |
| 96546 | pKeyMerge->aColl[i] = pColl; |
| 96547 | pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder; |
| 96548 | } |
| 96549 | } |
| @@ -96742,10 +96825,11 @@ | |
| 96742 | */ |
| 96743 | sqlite3VdbeResolveLabel(v, labelCmpr); |
| 96744 | sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY); |
| 96745 | sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy, |
| 96746 | (char*)pKeyMerge, P4_KEYINFO_HANDOFF); |
| 96747 | sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); |
| 96748 | |
| 96749 | /* Release temporary registers |
| 96750 | */ |
| 96751 | if( regPrev ){ |
| @@ -96809,13 +96893,10 @@ | |
| 96809 | }else{ |
| 96810 | Expr *pNew; |
| 96811 | assert( pEList!=0 && pExpr->iColumn<pEList->nExpr ); |
| 96812 | assert( pExpr->pLeft==0 && pExpr->pRight==0 ); |
| 96813 | pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0); |
| 96814 | if( pNew && pExpr->pColl ){ |
| 96815 | pNew->pColl = pExpr->pColl; |
| 96816 | } |
| 96817 | sqlite3ExprDelete(db, pExpr); |
| 96818 | pExpr = pNew; |
| 96819 | } |
| 96820 | }else{ |
| 96821 | pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList); |
| @@ -98151,10 +98232,19 @@ | |
| 98151 | */ |
| 98152 | int addrTop; |
| 98153 | int addrEof; |
| 98154 | pItem->regReturn = ++pParse->nMem; |
| 98155 | addrEof = ++pParse->nMem; |
| 98156 | sqlite3VdbeAddOp0(v, OP_Goto); |
| 98157 | addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor); |
| 98158 | sqlite3VdbeChangeP5(v, 1); |
| 98159 | VdbeComment((v, "coroutine for %s", pItem->pTab->zName)); |
| 98160 | pItem->addrFillSub = addrTop; |
| @@ -99827,10 +99917,19 @@ | |
| 99827 | ** |
| 99828 | ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy |
| 99829 | ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy |
| 99830 | */ |
| 99831 | pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf; |
| 99832 | |
| 99833 | switch( pStep->op ){ |
| 99834 | case TK_UPDATE: { |
| 99835 | sqlite3Update(pParse, |
| 99836 | targetSrcList(pParse, pStep), |
| @@ -102913,27 +103012,36 @@ | |
| 102913 | |
| 102914 | /* |
| 102915 | ** Commute a comparison operator. Expressions of the form "X op Y" |
| 102916 | ** are converted into "Y op X". |
| 102917 | ** |
| 102918 | ** If a collation sequence is associated with either the left or right |
| 102919 | ** side of the comparison, it remains associated with the same side after |
| 102920 | ** the commutation. So "Y collate NOCASE op X" becomes |
| 102921 | ** "X collate NOCASE op Y". This is because any collation sequence on |
| 102922 | ** the left hand side of a comparison overrides any collation sequence |
| 102923 | ** attached to the right. For the same reason the EP_ExpCollate flag |
| 102924 | ** is not commuted. |
| 102925 | */ |
| 102926 | static void exprCommute(Parse *pParse, Expr *pExpr){ |
| 102927 | u16 expRight = (pExpr->pRight->flags & EP_ExpCollate); |
| 102928 | u16 expLeft = (pExpr->pLeft->flags & EP_ExpCollate); |
| 102929 | assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN ); |
| 102930 | pExpr->pRight->pColl = sqlite3ExprCollSeq(pParse, pExpr->pRight); |
| 102931 | pExpr->pLeft->pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); |
| 102932 | SWAP(CollSeq*,pExpr->pRight->pColl,pExpr->pLeft->pColl); |
| 102933 | pExpr->pRight->flags = (pExpr->pRight->flags & ~EP_ExpCollate) | expLeft; |
| 102934 | pExpr->pLeft->flags = (pExpr->pLeft->flags & ~EP_ExpCollate) | expRight; |
| 102935 | SWAP(Expr*,pExpr->pRight,pExpr->pLeft); |
| 102936 | if( pExpr->op>=TK_GT ){ |
| 102937 | assert( TK_LT==TK_GT+2 ); |
| 102938 | assert( TK_GE==TK_LE+2 ); |
| 102939 | assert( TK_GT>TK_EQ ); |
| @@ -103006,16 +103114,16 @@ | |
| 103006 | ** it to be useful for optimising expression pX. Store this |
| 103007 | ** value in variable pColl. |
| 103008 | */ |
| 103009 | assert(pX->pLeft); |
| 103010 | pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| 103011 | assert(pColl || pParse->nErr); |
| 103012 | |
| 103013 | for(j=0; pIdx->aiColumn[j]!=iColumn; j++){ |
| 103014 | if( NEVER(j>=pIdx->nColumn) ) return 0; |
| 103015 | } |
| 103016 | if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue; |
| 103017 | } |
| 103018 | return pTerm; |
| 103019 | } |
| 103020 | } |
| 103021 | } |
| @@ -103529,11 +103637,11 @@ | |
| 103529 | if( db->mallocFailed ){ |
| 103530 | return; |
| 103531 | } |
| 103532 | pTerm = &pWC->a[idxTerm]; |
| 103533 | pMaskSet = pWC->pMaskSet; |
| 103534 | pExpr = pTerm->pExpr; |
| 103535 | prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); |
| 103536 | op = pExpr->op; |
| 103537 | if( op==TK_IN ){ |
| 103538 | assert( pExpr->pRight==0 ); |
| 103539 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| @@ -103556,12 +103664,12 @@ | |
| 103556 | pTerm->prereqAll = prereqAll; |
| 103557 | pTerm->leftCursor = -1; |
| 103558 | pTerm->iParent = -1; |
| 103559 | pTerm->eOperator = 0; |
| 103560 | if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){ |
| 103561 | Expr *pLeft = pExpr->pLeft; |
| 103562 | Expr *pRight = pExpr->pRight; |
| 103563 | if( pLeft->op==TK_COLUMN ){ |
| 103564 | pTerm->leftCursor = pLeft->iTable; |
| 103565 | pTerm->u.leftColumn = pLeft->iColumn; |
| 103566 | pTerm->eOperator = operatorMask(op); |
| 103567 | } |
| @@ -103585,11 +103693,11 @@ | |
| 103585 | }else{ |
| 103586 | pDup = pExpr; |
| 103587 | pNew = pTerm; |
| 103588 | } |
| 103589 | exprCommute(pParse, pDup); |
| 103590 | pLeft = pDup->pLeft; |
| 103591 | pNew->leftCursor = pLeft->iTable; |
| 103592 | pNew->u.leftColumn = pLeft->iColumn; |
| 103593 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 103594 | pNew->prereqRight = prereqLeft | extraRight; |
| 103595 | pNew->prereqAll = prereqAll; |
| @@ -103664,11 +103772,11 @@ | |
| 103664 | Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */ |
| 103665 | Expr *pNewExpr1; |
| 103666 | Expr *pNewExpr2; |
| 103667 | int idxNew1; |
| 103668 | int idxNew2; |
| 103669 | CollSeq *pColl; /* Collating sequence to use */ |
| 103670 | |
| 103671 | pLeft = pExpr->x.pList->a[1].pExpr; |
| 103672 | pStr2 = sqlite3ExprDup(db, pStr1, 0); |
| 103673 | if( !db->mallocFailed ){ |
| 103674 | u8 c, *pC; /* Last character before the first wildcard */ |
| @@ -103686,20 +103794,23 @@ | |
| 103686 | |
| 103687 | c = sqlite3UpperToLower[c]; |
| 103688 | } |
| 103689 | *pC = c + 1; |
| 103690 | } |
| 103691 | pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0); |
| 103692 | pNewExpr1 = sqlite3PExpr(pParse, TK_GE, |
| 103693 | sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl), |
| 103694 | pStr1, 0); |
| 103695 | idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); |
| 103696 | testcase( idxNew1==0 ); |
| 103697 | exprAnalyze(pSrc, pWC, idxNew1); |
| 103698 | pNewExpr2 = sqlite3PExpr(pParse, TK_LT, |
| 103699 | sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl), |
| 103700 | pStr2, 0); |
| 103701 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); |
| 103702 | testcase( idxNew2==0 ); |
| 103703 | exprAnalyze(pSrc, pWC, idxNew2); |
| 103704 | pTerm = &pWC->a[idxTerm]; |
| 103705 | if( isComplete ){ |
| @@ -103813,16 +103924,16 @@ | |
| 103813 | ){ |
| 103814 | int i; |
| 103815 | const char *zColl = pIdx->azColl[iCol]; |
| 103816 | |
| 103817 | for(i=0; i<pList->nExpr; i++){ |
| 103818 | Expr *p = pList->a[i].pExpr; |
| 103819 | if( p->op==TK_COLUMN |
| 103820 | && p->iColumn==pIdx->aiColumn[iCol] |
| 103821 | && p->iTable==iBase |
| 103822 | ){ |
| 103823 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, p); |
| 103824 | if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ |
| 103825 | return i; |
| 103826 | } |
| 103827 | } |
| 103828 | } |
| @@ -103865,11 +103976,11 @@ | |
| 103865 | ** matching "col=X" expression and the column is on the same table as pIdx, |
| 103866 | ** set the corresponding bit in variable mask. |
| 103867 | */ |
| 103868 | for(i=0; i<pDistinct->nExpr; i++){ |
| 103869 | WhereTerm *pTerm; |
| 103870 | Expr *p = pDistinct->a[i].pExpr; |
| 103871 | if( p->op!=TK_COLUMN ) return 0; |
| 103872 | pTerm = findTerm(pWC, p->iTable, p->iColumn, ~(Bitmask)0, WO_EQ, 0); |
| 103873 | if( pTerm ){ |
| 103874 | Expr *pX = pTerm->pExpr; |
| 103875 | CollSeq *p1 = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| @@ -103917,11 +104028,11 @@ | |
| 103917 | /* If any of the expressions is an IPK column on table iBase, then return |
| 103918 | ** true. Note: The (p->iTable==iBase) part of this test may be false if the |
| 103919 | ** current SELECT is a correlated sub-query. |
| 103920 | */ |
| 103921 | for(i=0; i<pDistinct->nExpr; i++){ |
| 103922 | Expr *p = pDistinct->a[i].pExpr; |
| 103923 | if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1; |
| 103924 | } |
| 103925 | |
| 103926 | /* Loop through all indices on the table, checking each to see if it makes |
| 103927 | ** the DISTINCT qualifier redundant. It does so if: |
| @@ -105203,11 +105314,11 @@ | |
| 105203 | WhereTerm *pConstraint; /* A constraint in the WHERE clause */ |
| 105204 | |
| 105205 | /* If the next term of the ORDER BY clause refers to anything other than |
| 105206 | ** a column in the "base" table, then this index will not be of any |
| 105207 | ** further use in handling the ORDER BY. */ |
| 105208 | pOBExpr = pOBItem->pExpr; |
| 105209 | if( pOBExpr->op!=TK_COLUMN || pOBExpr->iTable!=base ){ |
| 105210 | break; |
| 105211 | } |
| 105212 | |
| 105213 | /* Find column number and collating sequence for the next entry |
| @@ -105229,11 +105340,11 @@ | |
| 105229 | /* Check to see if the column number and collating sequence of the |
| 105230 | ** index match the column number and collating sequence of the ORDER BY |
| 105231 | ** clause entry. Set isMatch to 1 if they both match. */ |
| 105232 | if( pOBExpr->iColumn==iColumn ){ |
| 105233 | if( zColl ){ |
| 105234 | pColl = sqlite3ExprCollSeq(pParse, pOBExpr); |
| 105235 | if( !pColl ) pColl = db->pDfltColl; |
| 105236 | isMatch = sqlite3StrICmp(pColl->zName, zColl)==0; |
| 105237 | }else{ |
| 105238 | isMatch = 1; |
| 105239 | } |
| @@ -105370,10 +105481,15 @@ | |
| 105370 | int idxEqTermMask; /* Index mask of valid equality operators */ |
| 105371 | Index sPk; /* A fake index object for the primary key */ |
| 105372 | tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */ |
| 105373 | int aiColumnPk = -1; /* The aColumn[] value for the sPk index */ |
| 105374 | int wsFlagMask; /* Allowed flags in p->cost.plan.wsFlag */ |
| 105375 | |
| 105376 | /* Initialize the cost to a worst-case value */ |
| 105377 | memset(&p->cost, 0, sizeof(p->cost)); |
| 105378 | p->cost.rCost = SQLITE_BIG_DBL; |
| 105379 | |
| @@ -105418,10 +105534,21 @@ | |
| 105418 | WHERE_COLUMN_IN|WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_RANGE |
| 105419 | ); |
| 105420 | eqTermMask = WO_EQ|WO_IN; |
| 105421 | pIdx = 0; |
| 105422 | } |
| 105423 | |
| 105424 | /* Loop over all indices looking for the best one to use |
| 105425 | */ |
| 105426 | for(; pProbe; pIdx=pProbe=pProbe->pNext){ |
| 105427 | const tRowcnt * const aiRowEst = pProbe->aiRowEst; |
| @@ -105496,15 +105623,13 @@ | |
| 105496 | */ |
| 105497 | int bInEst = 0; /* True if "x IN (SELECT...)" seen */ |
| 105498 | int nInMul = 1; /* Number of distinct equalities to lookup */ |
| 105499 | double rangeDiv = (double)1; /* Estimated reduction in search space */ |
| 105500 | int nBound = 0; /* Number of range constraints seen */ |
| 105501 | int bSort; /* True if external sort required */ |
| 105502 | int bDist; /* True if index cannot help with DISTINCT */ |
| 105503 | int bLookup = 0; /* True if not a covering index */ |
| 105504 | int nPriorSat; /* ORDER BY terms satisfied by outer loops */ |
| 105505 | int nOrderBy; /* Number of ORDER BY terms */ |
| 105506 | WhereTerm *pTerm; /* A single term of the WHERE clause */ |
| 105507 | #ifdef SQLITE_ENABLE_STAT3 |
| 105508 | WhereTerm *pFirstTerm = 0; /* First term matching the index */ |
| 105509 | #endif |
| 105510 | |
| @@ -105511,20 +105636,11 @@ | |
| 105511 | WHERETRACE(( |
| 105512 | " %s(%s):\n", |
| 105513 | pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk") |
| 105514 | )); |
| 105515 | memset(&pc, 0, sizeof(pc)); |
| 105516 | nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0; |
| 105517 | if( p->i ){ |
| 105518 | nPriorSat = pc.plan.nOBSat = p->aLevel[p->i-1].plan.nOBSat; |
| 105519 | bSort = nPriorSat<nOrderBy; |
| 105520 | bDist = 0; |
| 105521 | }else{ |
| 105522 | nPriorSat = pc.plan.nOBSat = 0; |
| 105523 | bSort = nOrderBy>0; |
| 105524 | bDist = p->pDistinct!=0; |
| 105525 | } |
| 105526 | |
| 105527 | /* Determine the values of pc.plan.nEq and nInMul */ |
| 105528 | for(pc.plan.nEq=0; pc.plan.nEq<pProbe->nColumn; pc.plan.nEq++){ |
| 105529 | int j = pProbe->aiColumn[pc.plan.nEq]; |
| 105530 | pTerm = findTerm(pWC, iCur, j, p->notReady, eqTermMask, pIdx); |
| @@ -110554,11 +110670,11 @@ | |
| 110554 | spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); |
| 110555 | } |
| 110556 | break; |
| 110557 | case 194: /* expr ::= expr COLLATE ids */ |
| 110558 | { |
| 110559 | yygotominor.yy342.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy342.pExpr, &yymsp[0].minor.yy0); |
| 110560 | yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart; |
| 110561 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110562 | } |
| 110563 | break; |
| 110564 | case 195: /* expr ::= CAST LP expr AS typetoken RP */ |
| @@ -110813,28 +110929,20 @@ | |
| 110813 | case 244: /* uniqueflag ::= */ |
| 110814 | {yygotominor.yy392 = OE_None;} |
| 110815 | break; |
| 110816 | case 247: /* idxlist ::= idxlist COMMA nm collate sortorder */ |
| 110817 | { |
| 110818 | Expr *p = 0; |
| 110819 | if( yymsp[-1].minor.yy0.n>0 ){ |
| 110820 | p = sqlite3Expr(pParse->db, TK_COLUMN, 0); |
| 110821 | sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0); |
| 110822 | } |
| 110823 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, p); |
| 110824 | sqlite3ExprListSetName(pParse,yygotominor.yy442,&yymsp[-2].minor.yy0,1); |
| 110825 | sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index"); |
| 110826 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110827 | } |
| 110828 | break; |
| 110829 | case 248: /* idxlist ::= nm collate sortorder */ |
| 110830 | { |
| 110831 | Expr *p = 0; |
| 110832 | if( yymsp[-1].minor.yy0.n>0 ){ |
| 110833 | p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); |
| 110834 | sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0); |
| 110835 | } |
| 110836 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, p); |
| 110837 | sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1); |
| 110838 | sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index"); |
| 110839 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110840 | } |
| 110841 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -673,11 +673,11 @@ | |
| 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | */ |
| 676 | #define SQLITE_VERSION "3.7.15" |
| 677 | #define SQLITE_VERSION_NUMBER 3007015 |
| 678 | #define SQLITE_SOURCE_ID "2012-12-08 22:14:29 92c9ab56b1c67b9468bec57ab1d2c483a69a2810" |
| 679 | |
| 680 | /* |
| 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | ** |
| @@ -1421,11 +1421,10 @@ | |
| 1421 | ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
| 1422 | ** that the VFS encountered an error while handling the [PRAGMA] and the |
| 1423 | ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
| 1424 | ** file control occurs at the beginning of pragma statement analysis and so |
| 1425 | ** it is able to override built-in [PRAGMA] statements. |
| 1426 | ** |
| 1427 | ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
| 1428 | ** ^This file-control may be invoked by SQLite on the database file handle |
| 1429 | ** shortly after it is opened in order to provide a custom VFS with access |
| 1430 | ** to the connections busy-handler callback. The argument is of type (void **) |
| @@ -1433,10 +1432,20 @@ | |
| 1432 | ** to a function of type (int (*)(void *)). In order to invoke the connections |
| 1433 | ** busy-handler, this function should be invoked with the second (void *) in |
| 1434 | ** the array as the only argument. If it returns non-zero, then the operation |
| 1435 | ** should be retried. If it returns zero, the custom VFS should abandon the |
| 1436 | ** current operation. |
| 1437 | ** |
| 1438 | ** <li>[[SQLITE_FCNTL_TEMPFILENAME]] |
| 1439 | ** ^Application can invoke this file-control to have SQLite generate a |
| 1440 | ** temporary filename using the same algorithm that is followed to generate |
| 1441 | ** temporary filenames for TEMP tables and other internal uses. The |
| 1442 | ** argument should be a char** which will be filled with the filename |
| 1443 | ** written into memory obtained from [sqlite3_malloc()]. The caller should |
| 1444 | ** invoke [sqlite3_free()] on the result to avoid a memory leak. |
| 1445 | ** |
| 1446 | ** </ul> |
| 1447 | */ |
| 1448 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 1449 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 1450 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 1451 | #define SQLITE_LAST_ERRNO 4 |
| @@ -1449,10 +1458,11 @@ | |
| 1458 | #define SQLITE_FCNTL_OVERWRITE 11 |
| 1459 | #define SQLITE_FCNTL_VFSNAME 12 |
| 1460 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
| 1461 | #define SQLITE_FCNTL_PRAGMA 14 |
| 1462 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 1463 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 1464 | |
| 1465 | /* |
| 1466 | ** CAPI3REF: Mutex Handle |
| 1467 | ** |
| 1468 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -10209,23 +10219,11 @@ | |
| 10219 | /* |
| 10220 | ** A "Collating Sequence" is defined by an instance of the following |
| 10221 | ** structure. Conceptually, a collating sequence consists of a name and |
| 10222 | ** a comparison routine that defines the order of that sequence. |
| 10223 | ** |
| 10224 | ** If CollSeq.xCmp is NULL, it means that the |
| 10225 | ** collating sequence is undefined. Indices built on an undefined |
| 10226 | ** collating sequence may not be read or written. |
| 10227 | */ |
| 10228 | struct CollSeq { |
| 10229 | char *zName; /* Name of the collating sequence, UTF-8 encoded */ |
| @@ -10749,11 +10747,10 @@ | |
| 10747 | Expr *pRight; /* Right subnode */ |
| 10748 | union { |
| 10749 | ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */ |
| 10750 | Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */ |
| 10751 | } x; |
| 10752 | |
| 10753 | /* If the EP_Reduced flag is set in the Expr.flags mask, then no |
| 10754 | ** space is allocated for the fields below this point. An attempt to |
| 10755 | ** access them will result in a segfault or malfunction. |
| 10756 | *********************************************************************/ |
| @@ -10785,11 +10782,11 @@ | |
| 10782 | #define EP_Error 0x0008 /* Expression contains one or more errors */ |
| 10783 | #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */ |
| 10784 | #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ |
| 10785 | #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */ |
| 10786 | #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ |
| 10787 | #define EP_Collate 0x0100 /* Tree contains a TK_COLLATE opeartor */ |
| 10788 | #define EP_FixedDest 0x0200 /* Result needed in a specific register */ |
| 10789 | #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ |
| 10790 | #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ |
| 10791 | #define EP_Hint 0x1000 /* Not used */ |
| 10792 | #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ |
| @@ -11402,10 +11399,11 @@ | |
| 11399 | #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */ |
| 11400 | #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ |
| 11401 | #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ |
| 11402 | #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ |
| 11403 | #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */ |
| 11404 | #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ |
| 11405 | |
| 11406 | /* |
| 11407 | * Each trigger present in the database schema is stored as an instance of |
| 11408 | * struct Trigger. |
| 11409 | * |
| @@ -12093,12 +12091,13 @@ | |
| 12091 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 12092 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 12093 | SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 12094 | SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| 12095 | SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); |
| 12096 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, Token*); |
| 12097 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); |
| 12098 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*); |
| 12099 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 12100 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *); |
| 12101 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 12102 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 12103 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| @@ -26456,10 +26455,13 @@ | |
| 26455 | }else{ |
| 26456 | pFile->ctrlFlags |= mask; |
| 26457 | } |
| 26458 | } |
| 26459 | |
| 26460 | /* Forward declaration */ |
| 26461 | static int unixGetTempname(int nBuf, char *zBuf); |
| 26462 | |
| 26463 | /* |
| 26464 | ** Information and control of an open file handle. |
| 26465 | */ |
| 26466 | static int unixFileControl(sqlite3_file *id, int op, void *pArg){ |
| 26467 | unixFile *pFile = (unixFile*)id; |
| @@ -26492,10 +26494,18 @@ | |
| 26494 | return SQLITE_OK; |
| 26495 | } |
| 26496 | case SQLITE_FCNTL_VFSNAME: { |
| 26497 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 26498 | return SQLITE_OK; |
| 26499 | } |
| 26500 | case SQLITE_FCNTL_TEMPFILENAME: { |
| 26501 | char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname ); |
| 26502 | if( zTFile ){ |
| 26503 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 26504 | *(char**)pArg = zTFile; |
| 26505 | } |
| 26506 | return SQLITE_OK; |
| 26507 | } |
| 26508 | #ifdef SQLITE_DEBUG |
| 26509 | /* The pager calls this method to signal that it has done |
| 26510 | ** a rollback and that the database is therefore unchanged and |
| 26511 | ** it hence it is OK for the transaction change counter to be |
| @@ -32782,10 +32792,13 @@ | |
| 32792 | }else{ |
| 32793 | pFile->ctrlFlags |= mask; |
| 32794 | } |
| 32795 | } |
| 32796 | |
| 32797 | /* Forward declaration */ |
| 32798 | static int getTempname(int nBuf, char *zBuf); |
| 32799 | |
| 32800 | /* |
| 32801 | ** Control and query of the open file handle. |
| 32802 | */ |
| 32803 | static int winFileControl(sqlite3_file *id, int op, void *pArg){ |
| 32804 | winFile *pFile = (winFile*)id; |
| @@ -32841,10 +32854,18 @@ | |
| 32854 | win32IoerrRetryDelay = a[1]; |
| 32855 | }else{ |
| 32856 | a[1] = win32IoerrRetryDelay; |
| 32857 | } |
| 32858 | return SQLITE_OK; |
| 32859 | } |
| 32860 | case SQLITE_FCNTL_TEMPFILENAME: { |
| 32861 | char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname ); |
| 32862 | if( zTFile ){ |
| 32863 | getTempname(pFile->pVfs->mxPathname, zTFile); |
| 32864 | *(char**)pArg = zTFile; |
| 32865 | } |
| 32866 | return SQLITE_OK; |
| 32867 | } |
| 32868 | } |
| 32869 | return SQLITE_NOTFOUND; |
| 32870 | } |
| 32871 | |
| @@ -59392,26 +59413,22 @@ | |
| 59413 | assert( pKeyInfo->aSortOrder!=0 ); |
| 59414 | sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField); |
| 59415 | i = sqlite3Strlen30(zTemp); |
| 59416 | for(j=0; j<pKeyInfo->nField; j++){ |
| 59417 | CollSeq *pColl = pKeyInfo->aColl[j]; |
| 59418 | const char *zColl = pColl ? pColl->zName : "nil"; |
| 59419 | int n = sqlite3Strlen30(zColl); |
| 59420 | if( i+n>nTemp-6 ){ |
| 59421 | memcpy(&zTemp[i],",...",4); |
| 59422 | break; |
| 59423 | } |
| 59424 | zTemp[i++] = ','; |
| 59425 | if( pKeyInfo->aSortOrder[j] ){ |
| 59426 | zTemp[i++] = '-'; |
| 59427 | } |
| 59428 | memcpy(&zTemp[i], zColl, n+1); |
| 59429 | i += n; |
| 59430 | } |
| 59431 | zTemp[i++] = ')'; |
| 59432 | zTemp[i] = 0; |
| 59433 | assert( i<nTemp ); |
| 59434 | break; |
| @@ -63797,11 +63814,13 @@ | |
| 63814 | #ifdef SQLITE_DEBUG |
| 63815 | /* |
| 63816 | ** Print the value of a register for tracing purposes: |
| 63817 | */ |
| 63818 | static void memTracePrint(FILE *out, Mem *p){ |
| 63819 | if( p->flags & MEM_Invalid ){ |
| 63820 | fprintf(out, " undefined"); |
| 63821 | }else if( p->flags & MEM_Null ){ |
| 63822 | fprintf(out, " NULL"); |
| 63823 | }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ |
| 63824 | fprintf(out, " si:%lld", p->u.i); |
| 63825 | }else if( p->flags & MEM_Int ){ |
| 63826 | fprintf(out, " i:%lld", p->u.i); |
| @@ -64979,10 +64998,13 @@ | |
| 64998 | pOut = &aMem[pOp->p2]; |
| 64999 | assert( pOut!=pIn1 ); |
| 65000 | while( 1 ){ |
| 65001 | sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); |
| 65002 | Deephemeralize(pOut); |
| 65003 | #ifdef SQLITE_DEBUG |
| 65004 | pOut->pScopyFrom = 0; |
| 65005 | #endif |
| 65006 | REGISTER_TRACE(pOp->p2+pOp->p3-u.ae.n, pOut); |
| 65007 | if( (u.ae.n--)==0 ) break; |
| 65008 | pOut++; |
| 65009 | pIn1++; |
| 65010 | } |
| @@ -65801,26 +65823,31 @@ | |
| 65823 | /* Opcode: Permutation * * * P4 * |
| 65824 | ** |
| 65825 | ** Set the permutation used by the OP_Compare operator to be the array |
| 65826 | ** of integers in P4. |
| 65827 | ** |
| 65828 | ** The permutation is only valid until the next OP_Compare that has |
| 65829 | ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should |
| 65830 | ** occur immediately prior to the OP_Compare. |
| 65831 | */ |
| 65832 | case OP_Permutation: { |
| 65833 | assert( pOp->p4type==P4_INTARRAY ); |
| 65834 | assert( pOp->p4.ai ); |
| 65835 | aPermute = pOp->p4.ai; |
| 65836 | break; |
| 65837 | } |
| 65838 | |
| 65839 | /* Opcode: Compare P1 P2 P3 P4 P5 |
| 65840 | ** |
| 65841 | ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this |
| 65842 | ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of |
| 65843 | ** the comparison for use by the next OP_Jump instruct. |
| 65844 | ** |
| 65845 | ** If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is |
| 65846 | ** determined by the most recent OP_Permutation operator. If the |
| 65847 | ** OPFLAG_PERMUTE bit is clear, then register are compared in sequential |
| 65848 | ** order. |
| 65849 | ** |
| 65850 | ** P4 is a KeyInfo structure that defines collating sequences and sort |
| 65851 | ** orders for the comparison. The permutation applies to registers |
| 65852 | ** only. The KeyInfo elements are used sequentially. |
| 65853 | ** |
| @@ -65838,10 +65865,11 @@ | |
| 65865 | int idx; |
| 65866 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 65867 | int bRev; /* True for DESCENDING sort order */ |
| 65868 | #endif /* local variables moved into u.al */ |
| 65869 | |
| 65870 | if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; |
| 65871 | u.al.n = pOp->p3; |
| 65872 | u.al.pKeyInfo = pOp->p4.pKeyInfo; |
| 65873 | assert( u.al.n>0 ); |
| 65874 | assert( u.al.pKeyInfo!=0 ); |
| 65875 | u.al.p1 = pOp->p1; |
| @@ -72523,10 +72551,19 @@ | |
| 72551 | ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5 |
| 72552 | ** |
| 72553 | ** The result of random()%5 in the GROUP BY clause is probably different |
| 72554 | ** from the result in the result-set. We might fix this someday. Or |
| 72555 | ** then again, we might not... |
| 72556 | ** |
| 72557 | ** If the reference is followed by a COLLATE operator, then make sure |
| 72558 | ** the COLLATE operator is preserved. For example: |
| 72559 | ** |
| 72560 | ** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase; |
| 72561 | ** |
| 72562 | ** Should be transformed into: |
| 72563 | ** |
| 72564 | ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase; |
| 72565 | ** |
| 72566 | ** The nSubquery parameter specifies how many levels of subquery the |
| 72567 | ** alias is removed from the original expression. The usually value is |
| 72568 | ** zero but it might be more if the alias is contained within a subquery |
| 72569 | ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION |
| @@ -72547,45 +72584,40 @@ | |
| 72584 | assert( iCol>=0 && iCol<pEList->nExpr ); |
| 72585 | pOrig = pEList->a[iCol].pExpr; |
| 72586 | assert( pOrig!=0 ); |
| 72587 | assert( pOrig->flags & EP_Resolved ); |
| 72588 | db = pParse->db; |
| 72589 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 72590 | if( pDup==0 ) return; |
| 72591 | if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ |
| 72592 | incrAggFunctionDepth(pDup, nSubquery); |
| 72593 | pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0); |
| 72594 | if( pDup==0 ) return; |
| 72595 | if( pEList->a[iCol].iAlias==0 ){ |
| 72596 | pEList->a[iCol].iAlias = (u16)(++pParse->nAlias); |
| 72597 | } |
| 72598 | pDup->iTable = pEList->a[iCol].iAlias; |
| 72599 | } |
| 72600 | if( pExpr->op==TK_COLLATE ){ |
| 72601 | pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); |
| 72602 | } |
| 72603 | |
| 72604 | /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This |
| 72605 | ** prevents ExprDelete() from deleting the Expr structure itself, |
| 72606 | ** allowing it to be repopulated by the memcpy() on the following line. |
| 72607 | ** The pExpr->u.zToken might point into memory that will be freed by the |
| 72608 | ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to |
| 72609 | ** make a copy of the token before doing the sqlite3DbFree(). |
| 72610 | */ |
| 72611 | ExprSetProperty(pExpr, EP_Static); |
| 72612 | sqlite3ExprDelete(db, pExpr); |
| 72613 | memcpy(pExpr, pDup, sizeof(*pExpr)); |
| 72614 | if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){ |
| 72615 | assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 ); |
| 72616 | pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken); |
| 72617 | pExpr->flags2 |= EP2_MallocedToken; |
| 72618 | } |
| 72619 | sqlite3DbFree(db, pDup); |
| 72620 | } |
| 72621 | |
| 72622 | |
| 72623 | /* |
| @@ -73268,11 +73300,11 @@ | |
| 73300 | assert( pEList!=0 ); |
| 73301 | for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ |
| 73302 | int iCol = -1; |
| 73303 | Expr *pE, *pDup; |
| 73304 | if( pItem->done ) continue; |
| 73305 | pE = sqlite3ExprSkipCollate(pItem->pExpr); |
| 73306 | if( sqlite3ExprIsInteger(pE, &iCol) ){ |
| 73307 | if( iCol<=0 || iCol>pEList->nExpr ){ |
| 73308 | resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); |
| 73309 | return 1; |
| 73310 | } |
| @@ -73286,18 +73318,24 @@ | |
| 73318 | } |
| 73319 | sqlite3ExprDelete(db, pDup); |
| 73320 | } |
| 73321 | } |
| 73322 | if( iCol>0 ){ |
| 73323 | /* Convert the ORDER BY term into an integer column number iCol, |
| 73324 | ** taking care to preserve the COLLATE clause if it exists */ |
| 73325 | Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0); |
| 73326 | if( pNew==0 ) return 1; |
| 73327 | pNew->flags |= EP_IntValue; |
| 73328 | pNew->u.iValue = iCol; |
| 73329 | if( pItem->pExpr==pE ){ |
| 73330 | pItem->pExpr = pNew; |
| 73331 | }else{ |
| 73332 | assert( pItem->pExpr->op==TK_COLLATE ); |
| 73333 | assert( pItem->pExpr->pLeft==pE ); |
| 73334 | pItem->pExpr->pLeft = pNew; |
| 73335 | } |
| 73336 | sqlite3ExprDelete(db, pE); |
| 73337 | pItem->iOrderByCol = (u16)iCol; |
| 73338 | pItem->done = 1; |
| 73339 | }else{ |
| 73340 | moreToDo = 1; |
| 73341 | } |
| @@ -73398,15 +73436,15 @@ | |
| 73436 | ** sqlite3ResolveOrderGroupBy() will convert the expression to a |
| 73437 | ** copy of the iCol-th result-set expression. */ |
| 73438 | pItem->iOrderByCol = (u16)iCol; |
| 73439 | continue; |
| 73440 | } |
| 73441 | if( sqlite3ExprIsInteger(sqlite3ExprSkipCollate(pE), &iCol) ){ |
| 73442 | /* The ORDER BY term is an integer constant. Again, set the column |
| 73443 | ** number so that sqlite3ResolveOrderGroupBy() will convert the |
| 73444 | ** order-by term to a copy of the result-set expression */ |
| 73445 | if( iCol<1 || iCol>0xffff ){ |
| 73446 | resolveOutOfRangeError(pParse, zType, i+1, nResult); |
| 73447 | return 1; |
| 73448 | } |
| 73449 | pItem->iOrderByCol = (u16)iCol; |
| 73450 | continue; |
| @@ -73756,11 +73794,13 @@ | |
| 73794 | ** SELECT * FROM t1 WHERE a; |
| 73795 | ** SELECT a AS b FROM t1 WHERE b; |
| 73796 | ** SELECT * FROM t1 WHERE (select a from t1); |
| 73797 | */ |
| 73798 | SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr){ |
| 73799 | int op; |
| 73800 | pExpr = sqlite3ExprSkipCollate(pExpr); |
| 73801 | op = pExpr->op; |
| 73802 | if( op==TK_SELECT ){ |
| 73803 | assert( pExpr->flags&EP_xIsSelect ); |
| 73804 | return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); |
| 73805 | } |
| 73806 | #ifndef SQLITE_OMIT_CAST |
| @@ -73781,70 +73821,98 @@ | |
| 73821 | } |
| 73822 | return pExpr->affinity; |
| 73823 | } |
| 73824 | |
| 73825 | /* |
| 73826 | ** Set the collating sequence for expression pExpr to be the collating |
| 73827 | ** sequence named by pToken. Return a pointer to a new Expr node that |
| 73828 | ** implements the COLLATE operator. |
| 73829 | ** |
| 73830 | ** If a memory allocation error occurs, that fact is recorded in pParse->db |
| 73831 | ** and the pExpr parameter is returned unchanged. |
| 73832 | */ |
| 73833 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr *pExpr, Token *pCollName){ |
| 73834 | if( pCollName->n>0 ){ |
| 73835 | Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1); |
| 73836 | if( pNew ){ |
| 73837 | pNew->pLeft = pExpr; |
| 73838 | pNew->flags |= EP_Collate; |
| 73839 | pExpr = pNew; |
| 73840 | } |
| 73841 | } |
| 73842 | return pExpr; |
| 73843 | } |
| 73844 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){ |
| 73845 | Token s; |
| 73846 | assert( zC!=0 ); |
| 73847 | s.z = zC; |
| 73848 | s.n = sqlite3Strlen30(s.z); |
| 73849 | return sqlite3ExprAddCollateToken(pParse, pExpr, &s); |
| 73850 | } |
| 73851 | |
| 73852 | /* |
| 73853 | ** Skip over any TK_COLLATE and/or TK_AS operators at the root of |
| 73854 | ** an expression. |
| 73855 | */ |
| 73856 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){ |
| 73857 | while( pExpr && (pExpr->op==TK_COLLATE || pExpr->op==TK_AS) ){ |
| 73858 | pExpr = pExpr->pLeft; |
| 73859 | } |
| 73860 | return pExpr; |
| 73861 | } |
| 73862 | |
| 73863 | /* |
| 73864 | ** Return the collation sequence for the expression pExpr. If |
| 73865 | ** there is no defined collating sequence, return NULL. |
| 73866 | ** |
| 73867 | ** The collating sequence might be determined by a COLLATE operator |
| 73868 | ** or by the presence of a column with a defined collating sequence. |
| 73869 | ** COLLATE operators take first precedence. Left operands take |
| 73870 | ** precedence over right operands. |
| 73871 | */ |
| 73872 | SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ |
| 73873 | sqlite3 *db = pParse->db; |
| 73874 | CollSeq *pColl = 0; |
| 73875 | Expr *p = pExpr; |
| 73876 | while( p ){ |
| 73877 | int op = p->op; |
| 73878 | if( op==TK_CAST || op==TK_UPLUS ){ |
| 73879 | p = p->pLeft; |
| 73880 | continue; |
| 73881 | } |
| 73882 | assert( op!=TK_REGISTER || p->op2!=TK_COLLATE ); |
| 73883 | if( op==TK_COLLATE ){ |
| 73884 | if( db->init.busy ){ |
| 73885 | /* Do not report errors when parsing while the schema */ |
| 73886 | pColl = sqlite3FindCollSeq(db, ENC(db), p->u.zToken, 0); |
| 73887 | }else{ |
| 73888 | pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); |
| 73889 | } |
| 73890 | break; |
| 73891 | } |
| 73892 | if( p->pTab!=0 |
| 73893 | && (op==TK_AGG_COLUMN || op==TK_COLUMN |
| 73894 | || op==TK_REGISTER || op==TK_TRIGGER) |
| 73895 | ){ |
| 73896 | /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally |
| 73897 | ** a TK_COLUMN but was previously evaluated and cached in a register */ |
| 73898 | int j = p->iColumn; |
| 73899 | if( j>=0 ){ |
| 73900 | const char *zColl = p->pTab->aCol[j].zColl; |
| 73901 | pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 73902 | } |
| 73903 | break; |
| 73904 | } |
| 73905 | if( p->flags & EP_Collate ){ |
| 73906 | if( ALWAYS(p->pLeft) && (p->pLeft->flags & EP_Collate)!=0 ){ |
| 73907 | p = p->pLeft; |
| 73908 | }else{ |
| 73909 | p = p->pRight; |
| 73910 | } |
| 73911 | }else{ |
| 73912 | break; |
| 73913 | } |
| 73914 | } |
| 73915 | if( sqlite3CheckCollSeq(pParse, pColl) ){ |
| 73916 | pColl = 0; |
| 73917 | } |
| 73918 | return pColl; |
| @@ -73944,16 +74012,14 @@ | |
| 74012 | Expr *pLeft, |
| 74013 | Expr *pRight |
| 74014 | ){ |
| 74015 | CollSeq *pColl; |
| 74016 | assert( pLeft ); |
| 74017 | if( pLeft->flags & EP_Collate ){ |
| 74018 | pColl = sqlite3ExprCollSeq(pParse, pLeft); |
| 74019 | }else if( pRight && (pRight->flags & EP_Collate)!=0 ){ |
| 74020 | pColl = sqlite3ExprCollSeq(pParse, pRight); |
| 74021 | }else{ |
| 74022 | pColl = sqlite3ExprCollSeq(pParse, pLeft); |
| 74023 | if( !pColl ){ |
| 74024 | pColl = sqlite3ExprCollSeq(pParse, pRight); |
| 74025 | } |
| @@ -74179,21 +74245,15 @@ | |
| 74245 | sqlite3ExprDelete(db, pLeft); |
| 74246 | sqlite3ExprDelete(db, pRight); |
| 74247 | }else{ |
| 74248 | if( pRight ){ |
| 74249 | pRoot->pRight = pRight; |
| 74250 | pRoot->flags |= EP_Collate & pRight->flags; |
| 74251 | } |
| 74252 | if( pLeft ){ |
| 74253 | pRoot->pLeft = pLeft; |
| 74254 | pRoot->flags |= EP_Collate & pLeft->flags; |
| 74255 | } |
| 74256 | exprSetHeight(pRoot); |
| 74257 | } |
| 74258 | } |
| 74259 | |
| @@ -74447,11 +74507,11 @@ | |
| 74507 | }else{ |
| 74508 | assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 74509 | assert( !ExprHasProperty(p, EP_FromJoin) ); |
| 74510 | assert( (p->flags2 & EP2_MallocedToken)==0 ); |
| 74511 | assert( (p->flags2 & EP2_Irreducible)==0 ); |
| 74512 | if( p->pLeft || p->pRight || p->x.pList ){ |
| 74513 | nSize = EXPR_REDUCEDSIZE | EP_Reduced; |
| 74514 | }else{ |
| 74515 | nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly; |
| 74516 | } |
| 74517 | } |
| @@ -76471,10 +76531,11 @@ | |
| 76531 | sqlite3VdbeAddOp3(v, OP_And, r3, r4, target); |
| 76532 | sqlite3ReleaseTempReg(pParse, r3); |
| 76533 | sqlite3ReleaseTempReg(pParse, r4); |
| 76534 | break; |
| 76535 | } |
| 76536 | case TK_COLLATE: |
| 76537 | case TK_UPLUS: { |
| 76538 | inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); |
| 76539 | break; |
| 76540 | } |
| 76541 | |
| @@ -76839,10 +76900,16 @@ | |
| 76900 | case TK_UPLUS: zUniOp = "UPLUS"; break; |
| 76901 | case TK_BITNOT: zUniOp = "BITNOT"; break; |
| 76902 | case TK_NOT: zUniOp = "NOT"; break; |
| 76903 | case TK_ISNULL: zUniOp = "ISNULL"; break; |
| 76904 | case TK_NOTNULL: zUniOp = "NOTNULL"; break; |
| 76905 | |
| 76906 | case TK_COLLATE: { |
| 76907 | sqlite3ExplainExpr(pOut, pExpr->pLeft); |
| 76908 | sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken); |
| 76909 | break; |
| 76910 | } |
| 76911 | |
| 76912 | case TK_AGG_FUNCTION: |
| 76913 | case TK_CONST_FUNC: |
| 76914 | case TK_FUNCTION: { |
| 76915 | ExprList *pFarg; /* List of function arguments */ |
| @@ -77058,10 +77125,13 @@ | |
| 77125 | switch( pExpr->op ){ |
| 77126 | case TK_IN: |
| 77127 | case TK_REGISTER: { |
| 77128 | return WRC_Prune; |
| 77129 | } |
| 77130 | case TK_COLLATE: { |
| 77131 | return WRC_Continue; |
| 77132 | } |
| 77133 | case TK_FUNCTION: |
| 77134 | case TK_AGG_FUNCTION: |
| 77135 | case TK_CONST_FUNC: { |
| 77136 | /* The arguments to a function have a fixed destination. |
| 77137 | ** Mark them this way to avoid generated unneeded OP_SCopy |
| @@ -77079,13 +77149,15 @@ | |
| 77149 | break; |
| 77150 | } |
| 77151 | } |
| 77152 | if( isAppropriateForFactoring(pExpr) ){ |
| 77153 | int r1 = ++pParse->nMem; |
| 77154 | int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); |
| 77155 | /* If r2!=r1, it means that register r1 is never used. That is harmless |
| 77156 | ** but suboptimal, so we want to know about the situation to fix it. |
| 77157 | ** Hence the following assert: */ |
| 77158 | assert( r2==r1 ); |
| 77159 | pExpr->op2 = pExpr->op; |
| 77160 | pExpr->op = TK_REGISTER; |
| 77161 | pExpr->iTable = r2; |
| 77162 | return WRC_Prune; |
| 77163 | } |
| @@ -77498,11 +77570,19 @@ | |
| 77570 | assert( !ExprHasAnyProperty(pB, EP_TokenOnly|EP_Reduced) ); |
| 77571 | if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){ |
| 77572 | return 2; |
| 77573 | } |
| 77574 | if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2; |
| 77575 | if( pA->op!=pB->op ){ |
| 77576 | if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB)<2 ){ |
| 77577 | return 1; |
| 77578 | } |
| 77579 | if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft)<2 ){ |
| 77580 | return 1; |
| 77581 | } |
| 77582 | return 2; |
| 77583 | } |
| 77584 | if( sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 2; |
| 77585 | if( sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 2; |
| 77586 | if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList) ) return 2; |
| 77587 | if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2; |
| 77588 | if( ExprHasProperty(pA, EP_IntValue) ){ |
| @@ -77510,15 +77590,13 @@ | |
| 77590 | return 2; |
| 77591 | } |
| 77592 | }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){ |
| 77593 | if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; |
| 77594 | if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ |
| 77595 | return pA->op==TK_COLLATE ? 1 : 2; |
| 77596 | } |
| 77597 | } |
| 77598 | return 0; |
| 77599 | } |
| 77600 | |
| 77601 | /* |
| 77602 | ** Compare two ExprList objects. Return 0 if they are identical and |
| @@ -80765,10 +80843,11 @@ | |
| 80843 | */ |
| 80844 | SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){ |
| 80845 | sqlite3 *db; |
| 80846 | Vdbe *v; |
| 80847 | |
| 80848 | assert( pParse->pToplevel==0 ); |
| 80849 | db = pParse->db; |
| 80850 | if( db->mallocFailed ) return; |
| 80851 | if( pParse->nested ) return; |
| 80852 | if( pParse->nErr ) return; |
| 80853 | |
| @@ -83328,14 +83407,12 @@ | |
| 83407 | ** specified collation sequence names. |
| 83408 | */ |
| 83409 | for(i=0; i<pList->nExpr; i++){ |
| 83410 | Expr *pExpr = pList->a[i].pExpr; |
| 83411 | if( pExpr ){ |
| 83412 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr); |
| 83413 | if( pColl ){ |
| 83414 | nExtra += (1 + sqlite3Strlen30(pColl->zName)); |
| 83415 | } |
| 83416 | } |
| 83417 | } |
| 83418 | |
| @@ -83394,10 +83471,11 @@ | |
| 83471 | */ |
| 83472 | for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){ |
| 83473 | const char *zColName = pListItem->zName; |
| 83474 | Column *pTabCol; |
| 83475 | int requestedSortOrder; |
| 83476 | CollSeq *pColl; /* Collating sequence */ |
| 83477 | char *zColl; /* Collation sequence name */ |
| 83478 | |
| 83479 | for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){ |
| 83480 | if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; |
| 83481 | } |
| @@ -83406,18 +83484,15 @@ | |
| 83484 | pTab->zName, zColName); |
| 83485 | pParse->checkSchema = 1; |
| 83486 | goto exit_create_index; |
| 83487 | } |
| 83488 | pIndex->aiColumn[i] = j; |
| 83489 | if( pListItem->pExpr |
| 83490 | && (pColl = sqlite3ExprCollSeq(pParse, pListItem->pExpr))!=0 |
| 83491 | ){ |
| 83492 | int nColl; |
| 83493 | zColl = pColl->zName; |
| 83494 | nColl = sqlite3Strlen30(zColl) + 1; |
| 83495 | assert( nExtra>=nColl ); |
| 83496 | memcpy(zExtra, zColl, nColl); |
| 83497 | zColl = zExtra; |
| 83498 | zExtra += nColl; |
| @@ -84227,10 +84302,19 @@ | |
| 84302 | ** early in the code, before we know if any database tables will be used. |
| 84303 | */ |
| 84304 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ |
| 84305 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 84306 | |
| 84307 | #ifndef SQLITE_OMIT_TRIGGER |
| 84308 | if( pToplevel!=pParse ){ |
| 84309 | /* This branch is taken if a trigger is currently being coded. In this |
| 84310 | ** case, set cookieGoto to a non-zero value to show that this function |
| 84311 | ** has been called. This is used by the sqlite3ExprCodeConstants() |
| 84312 | ** function. */ |
| 84313 | pParse->cookieGoto = -1; |
| 84314 | } |
| 84315 | #endif |
| 84316 | if( pToplevel->cookieGoto==0 ){ |
| 84317 | Vdbe *v = sqlite3GetVdbe(pToplevel); |
| 84318 | if( v==0 ) return; /* This only happens if there was a prior error */ |
| 84319 | pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1; |
| 84320 | } |
| @@ -87806,16 +87890,19 @@ | |
| 87890 | if( pLeft ){ |
| 87891 | /* Set the collation sequence and affinity of the LHS of each TK_EQ |
| 87892 | ** expression to the parent key column defaults. */ |
| 87893 | if( pIdx ){ |
| 87894 | Column *pCol; |
| 87895 | const char *zColl; |
| 87896 | iCol = pIdx->aiColumn[i]; |
| 87897 | pCol = &pTab->aCol[iCol]; |
| 87898 | if( pTab->iPKey==iCol ) iCol = -1; |
| 87899 | pLeft->iTable = regData+iCol+1; |
| 87900 | pLeft->affinity = pCol->affinity; |
| 87901 | zColl = pCol->zColl; |
| 87902 | if( zColl==0 ) zColl = db->pDfltColl->zName; |
| 87903 | pLeft = sqlite3ExprAddCollateString(pParse, pLeft, zColl); |
| 87904 | }else{ |
| 87905 | pLeft->iTable = regData; |
| 87906 | pLeft->affinity = SQLITE_AFF_INTEGER; |
| 87907 | } |
| 87908 | } |
| @@ -89791,29 +89878,24 @@ | |
| 89878 | ExprList *pCheck = pTab->pCheck; |
| 89879 | pParse->ckBase = regData; |
| 89880 | onError = overrideError!=OE_Default ? overrideError : OE_Abort; |
| 89881 | for(i=0; i<pCheck->nExpr; i++){ |
| 89882 | int allOk = sqlite3VdbeMakeLabel(v); |
| 89883 | sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL); |
| 89884 | if( onError==OE_Ignore ){ |
| 89885 | sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); |
| 89886 | }else{ |
| 89887 | char *zConsName = pCheck->a[i].zName; |
| 89888 | if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ |
| 89889 | if( zConsName ){ |
| 89890 | zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); |
| 89891 | }else{ |
| 89892 | zConsName = 0; |
| 89893 | } |
| 89894 | sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); |
| 89895 | } |
| 89896 | sqlite3VdbeResolveLabel(v, allOk); |
| 89897 | } |
| 89898 | } |
| 89899 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| 89900 | |
| 89901 | /* If we have an INTEGER PRIMARY KEY, make sure the primary key |
| @@ -95536,11 +95618,11 @@ | |
| 95618 | *paCol = aCol; |
| 95619 | |
| 95620 | for(i=0, pCol=aCol; i<nCol; i++, pCol++){ |
| 95621 | /* Get an appropriate name for the column |
| 95622 | */ |
| 95623 | p = sqlite3ExprSkipCollate(pEList->a[i].pExpr); |
| 95624 | assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue) |
| 95625 | || p->pRight->u.zToken==0 || p->pRight->u.zToken[0]!=0 ); |
| 95626 | if( (zName = pEList->a[i].zName)!=0 ){ |
| 95627 | /* If the column contains an "AS <name>" phrase, use <name> as the name */ |
| 95628 | zName = sqlite3DbStrDup(db, zName); |
| @@ -96534,16 +96616,17 @@ | |
| 96616 | pKeyMerge->nField = (u16)nOrderBy; |
| 96617 | pKeyMerge->enc = ENC(db); |
| 96618 | for(i=0; i<nOrderBy; i++){ |
| 96619 | CollSeq *pColl; |
| 96620 | Expr *pTerm = pOrderBy->a[i].pExpr; |
| 96621 | if( pTerm->flags & EP_Collate ){ |
| 96622 | pColl = sqlite3ExprCollSeq(pParse, pTerm); |
| 96623 | }else{ |
| 96624 | pColl = multiSelectCollSeq(pParse, p, aPermute[i]); |
| 96625 | if( pColl==0 ) pColl = db->pDfltColl; |
| 96626 | pOrderBy->a[i].pExpr = |
| 96627 | sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName); |
| 96628 | } |
| 96629 | pKeyMerge->aColl[i] = pColl; |
| 96630 | pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder; |
| 96631 | } |
| 96632 | } |
| @@ -96742,10 +96825,11 @@ | |
| 96825 | */ |
| 96826 | sqlite3VdbeResolveLabel(v, labelCmpr); |
| 96827 | sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY); |
| 96828 | sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy, |
| 96829 | (char*)pKeyMerge, P4_KEYINFO_HANDOFF); |
| 96830 | sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE); |
| 96831 | sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); |
| 96832 | |
| 96833 | /* Release temporary registers |
| 96834 | */ |
| 96835 | if( regPrev ){ |
| @@ -96809,13 +96893,10 @@ | |
| 96893 | }else{ |
| 96894 | Expr *pNew; |
| 96895 | assert( pEList!=0 && pExpr->iColumn<pEList->nExpr ); |
| 96896 | assert( pExpr->pLeft==0 && pExpr->pRight==0 ); |
| 96897 | pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0); |
| 96898 | sqlite3ExprDelete(db, pExpr); |
| 96899 | pExpr = pNew; |
| 96900 | } |
| 96901 | }else{ |
| 96902 | pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList); |
| @@ -98151,10 +98232,19 @@ | |
| 98232 | */ |
| 98233 | int addrTop; |
| 98234 | int addrEof; |
| 98235 | pItem->regReturn = ++pParse->nMem; |
| 98236 | addrEof = ++pParse->nMem; |
| 98237 | /* Before coding the OP_Goto to jump to the start of the main routine, |
| 98238 | ** ensure that the jump to the verify-schema routine has already |
| 98239 | ** been coded. Otherwise, the verify-schema would likely be coded as |
| 98240 | ** part of the co-routine. If the main routine then accessed the |
| 98241 | ** database before invoking the co-routine for the first time (for |
| 98242 | ** example to initialize a LIMIT register from a sub-select), it would |
| 98243 | ** be doing so without having verified the schema version and obtained |
| 98244 | ** the required db locks. See ticket d6b36be38. */ |
| 98245 | sqlite3CodeVerifySchema(pParse, -1); |
| 98246 | sqlite3VdbeAddOp0(v, OP_Goto); |
| 98247 | addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor); |
| 98248 | sqlite3VdbeChangeP5(v, 1); |
| 98249 | VdbeComment((v, "coroutine for %s", pItem->pTab->zName)); |
| 98250 | pItem->addrFillSub = addrTop; |
| @@ -99827,10 +99917,19 @@ | |
| 99917 | ** |
| 99918 | ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy |
| 99919 | ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy |
| 99920 | */ |
| 99921 | pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf; |
| 99922 | |
| 99923 | /* Clear the cookieGoto flag. When coding triggers, the cookieGoto |
| 99924 | ** variable is used as a flag to indicate to sqlite3ExprCodeConstants() |
| 99925 | ** that it is not safe to refactor constants (this happens after the |
| 99926 | ** start of the first loop in the SQL statement is coded - at that |
| 99927 | ** point code may be conditionally executed, so it is no longer safe to |
| 99928 | ** initialize constant register values). */ |
| 99929 | assert( pParse->cookieGoto==0 || pParse->cookieGoto==-1 ); |
| 99930 | pParse->cookieGoto = 0; |
| 99931 | |
| 99932 | switch( pStep->op ){ |
| 99933 | case TK_UPDATE: { |
| 99934 | sqlite3Update(pParse, |
| 99935 | targetSrcList(pParse, pStep), |
| @@ -102913,27 +103012,36 @@ | |
| 103012 | |
| 103013 | /* |
| 103014 | ** Commute a comparison operator. Expressions of the form "X op Y" |
| 103015 | ** are converted into "Y op X". |
| 103016 | ** |
| 103017 | ** If left/right precendence rules come into play when determining the |
| 103018 | ** collating |
| 103019 | ** side of the comparison, it remains associated with the same side after |
| 103020 | ** the commutation. So "Y collate NOCASE op X" becomes |
| 103021 | ** "X op Y". This is because any collation sequence on |
| 103022 | ** the left hand side of a comparison overrides any collation sequence |
| 103023 | ** attached to the right. For the same reason the EP_Collate flag |
| 103024 | ** is not commuted. |
| 103025 | */ |
| 103026 | static void exprCommute(Parse *pParse, Expr *pExpr){ |
| 103027 | u16 expRight = (pExpr->pRight->flags & EP_Collate); |
| 103028 | u16 expLeft = (pExpr->pLeft->flags & EP_Collate); |
| 103029 | assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN ); |
| 103030 | if( expRight==expLeft ){ |
| 103031 | /* Either X and Y both have COLLATE operator or neither do */ |
| 103032 | if( expRight ){ |
| 103033 | /* Both X and Y have COLLATE operators. Make sure X is always |
| 103034 | ** used by clearing the EP_Collate flag from Y. */ |
| 103035 | pExpr->pRight->flags &= ~EP_Collate; |
| 103036 | }else if( sqlite3ExprCollSeq(pParse, pExpr->pLeft)!=0 ){ |
| 103037 | /* Neither X nor Y have COLLATE operators, but X has a non-default |
| 103038 | ** collating sequence. So add the EP_Collate marker on X to cause |
| 103039 | ** it to be searched first. */ |
| 103040 | pExpr->pLeft->flags |= EP_Collate; |
| 103041 | } |
| 103042 | } |
| 103043 | SWAP(Expr*,pExpr->pRight,pExpr->pLeft); |
| 103044 | if( pExpr->op>=TK_GT ){ |
| 103045 | assert( TK_LT==TK_GT+2 ); |
| 103046 | assert( TK_GE==TK_LE+2 ); |
| 103047 | assert( TK_GT>TK_EQ ); |
| @@ -103006,16 +103114,16 @@ | |
| 103114 | ** it to be useful for optimising expression pX. Store this |
| 103115 | ** value in variable pColl. |
| 103116 | */ |
| 103117 | assert(pX->pLeft); |
| 103118 | pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| 103119 | if( pColl==0 ) pColl = pParse->db->pDfltColl; |
| 103120 | |
| 103121 | for(j=0; pIdx->aiColumn[j]!=iColumn; j++){ |
| 103122 | if( NEVER(j>=pIdx->nColumn) ) return 0; |
| 103123 | } |
| 103124 | if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue; |
| 103125 | } |
| 103126 | return pTerm; |
| 103127 | } |
| 103128 | } |
| 103129 | } |
| @@ -103529,11 +103637,11 @@ | |
| 103637 | if( db->mallocFailed ){ |
| 103638 | return; |
| 103639 | } |
| 103640 | pTerm = &pWC->a[idxTerm]; |
| 103641 | pMaskSet = pWC->pMaskSet; |
| 103642 | pExpr = sqlite3ExprSkipCollate(pTerm->pExpr); |
| 103643 | prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); |
| 103644 | op = pExpr->op; |
| 103645 | if( op==TK_IN ){ |
| 103646 | assert( pExpr->pRight==0 ); |
| 103647 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| @@ -103556,12 +103664,12 @@ | |
| 103664 | pTerm->prereqAll = prereqAll; |
| 103665 | pTerm->leftCursor = -1; |
| 103666 | pTerm->iParent = -1; |
| 103667 | pTerm->eOperator = 0; |
| 103668 | if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){ |
| 103669 | Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft); |
| 103670 | Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight); |
| 103671 | if( pLeft->op==TK_COLUMN ){ |
| 103672 | pTerm->leftCursor = pLeft->iTable; |
| 103673 | pTerm->u.leftColumn = pLeft->iColumn; |
| 103674 | pTerm->eOperator = operatorMask(op); |
| 103675 | } |
| @@ -103585,11 +103693,11 @@ | |
| 103693 | }else{ |
| 103694 | pDup = pExpr; |
| 103695 | pNew = pTerm; |
| 103696 | } |
| 103697 | exprCommute(pParse, pDup); |
| 103698 | pLeft = sqlite3ExprSkipCollate(pDup->pLeft); |
| 103699 | pNew->leftCursor = pLeft->iTable; |
| 103700 | pNew->u.leftColumn = pLeft->iColumn; |
| 103701 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 103702 | pNew->prereqRight = prereqLeft | extraRight; |
| 103703 | pNew->prereqAll = prereqAll; |
| @@ -103664,11 +103772,11 @@ | |
| 103772 | Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */ |
| 103773 | Expr *pNewExpr1; |
| 103774 | Expr *pNewExpr2; |
| 103775 | int idxNew1; |
| 103776 | int idxNew2; |
| 103777 | Token sCollSeqName; /* Name of collating sequence */ |
| 103778 | |
| 103779 | pLeft = pExpr->x.pList->a[1].pExpr; |
| 103780 | pStr2 = sqlite3ExprDup(db, pStr1, 0); |
| 103781 | if( !db->mallocFailed ){ |
| 103782 | u8 c, *pC; /* Last character before the first wildcard */ |
| @@ -103686,20 +103794,23 @@ | |
| 103794 | |
| 103795 | c = sqlite3UpperToLower[c]; |
| 103796 | } |
| 103797 | *pC = c + 1; |
| 103798 | } |
| 103799 | sCollSeqName.z = noCase ? "NOCASE" : "BINARY"; |
| 103800 | sCollSeqName.n = 6; |
| 103801 | pNewExpr1 = sqlite3ExprDup(db, pLeft, 0); |
| 103802 | pNewExpr1 = sqlite3PExpr(pParse, TK_GE, |
| 103803 | sqlite3ExprAddCollateToken(pParse,pNewExpr1,&sCollSeqName), |
| 103804 | pStr1, 0); |
| 103805 | idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); |
| 103806 | testcase( idxNew1==0 ); |
| 103807 | exprAnalyze(pSrc, pWC, idxNew1); |
| 103808 | pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); |
| 103809 | pNewExpr2 = sqlite3PExpr(pParse, TK_LT, |
| 103810 | sqlite3ExprAddCollateToken(pParse,pNewExpr2,&sCollSeqName), |
| 103811 | pStr2, 0); |
| 103812 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); |
| 103813 | testcase( idxNew2==0 ); |
| 103814 | exprAnalyze(pSrc, pWC, idxNew2); |
| 103815 | pTerm = &pWC->a[idxTerm]; |
| 103816 | if( isComplete ){ |
| @@ -103813,16 +103924,16 @@ | |
| 103924 | ){ |
| 103925 | int i; |
| 103926 | const char *zColl = pIdx->azColl[iCol]; |
| 103927 | |
| 103928 | for(i=0; i<pList->nExpr; i++){ |
| 103929 | Expr *p = sqlite3ExprSkipCollate(pList->a[i].pExpr); |
| 103930 | if( p->op==TK_COLUMN |
| 103931 | && p->iColumn==pIdx->aiColumn[iCol] |
| 103932 | && p->iTable==iBase |
| 103933 | ){ |
| 103934 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); |
| 103935 | if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ |
| 103936 | return i; |
| 103937 | } |
| 103938 | } |
| 103939 | } |
| @@ -103865,11 +103976,11 @@ | |
| 103976 | ** matching "col=X" expression and the column is on the same table as pIdx, |
| 103977 | ** set the corresponding bit in variable mask. |
| 103978 | */ |
| 103979 | for(i=0; i<pDistinct->nExpr; i++){ |
| 103980 | WhereTerm *pTerm; |
| 103981 | Expr *p = sqlite3ExprSkipCollate(pDistinct->a[i].pExpr); |
| 103982 | if( p->op!=TK_COLUMN ) return 0; |
| 103983 | pTerm = findTerm(pWC, p->iTable, p->iColumn, ~(Bitmask)0, WO_EQ, 0); |
| 103984 | if( pTerm ){ |
| 103985 | Expr *pX = pTerm->pExpr; |
| 103986 | CollSeq *p1 = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); |
| @@ -103917,11 +104028,11 @@ | |
| 104028 | /* If any of the expressions is an IPK column on table iBase, then return |
| 104029 | ** true. Note: The (p->iTable==iBase) part of this test may be false if the |
| 104030 | ** current SELECT is a correlated sub-query. |
| 104031 | */ |
| 104032 | for(i=0; i<pDistinct->nExpr; i++){ |
| 104033 | Expr *p = sqlite3ExprSkipCollate(pDistinct->a[i].pExpr); |
| 104034 | if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1; |
| 104035 | } |
| 104036 | |
| 104037 | /* Loop through all indices on the table, checking each to see if it makes |
| 104038 | ** the DISTINCT qualifier redundant. It does so if: |
| @@ -105203,11 +105314,11 @@ | |
| 105314 | WhereTerm *pConstraint; /* A constraint in the WHERE clause */ |
| 105315 | |
| 105316 | /* If the next term of the ORDER BY clause refers to anything other than |
| 105317 | ** a column in the "base" table, then this index will not be of any |
| 105318 | ** further use in handling the ORDER BY. */ |
| 105319 | pOBExpr = sqlite3ExprSkipCollate(pOBItem->pExpr); |
| 105320 | if( pOBExpr->op!=TK_COLUMN || pOBExpr->iTable!=base ){ |
| 105321 | break; |
| 105322 | } |
| 105323 | |
| 105324 | /* Find column number and collating sequence for the next entry |
| @@ -105229,11 +105340,11 @@ | |
| 105340 | /* Check to see if the column number and collating sequence of the |
| 105341 | ** index match the column number and collating sequence of the ORDER BY |
| 105342 | ** clause entry. Set isMatch to 1 if they both match. */ |
| 105343 | if( pOBExpr->iColumn==iColumn ){ |
| 105344 | if( zColl ){ |
| 105345 | pColl = sqlite3ExprCollSeq(pParse, pOBItem->pExpr); |
| 105346 | if( !pColl ) pColl = db->pDfltColl; |
| 105347 | isMatch = sqlite3StrICmp(pColl->zName, zColl)==0; |
| 105348 | }else{ |
| 105349 | isMatch = 1; |
| 105350 | } |
| @@ -105370,10 +105481,15 @@ | |
| 105481 | int idxEqTermMask; /* Index mask of valid equality operators */ |
| 105482 | Index sPk; /* A fake index object for the primary key */ |
| 105483 | tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */ |
| 105484 | int aiColumnPk = -1; /* The aColumn[] value for the sPk index */ |
| 105485 | int wsFlagMask; /* Allowed flags in p->cost.plan.wsFlag */ |
| 105486 | int nPriorSat; /* ORDER BY terms satisfied by outer loops */ |
| 105487 | int nOrderBy; /* Number of ORDER BY terms */ |
| 105488 | char bSortInit; /* Initializer for bSort in inner loop */ |
| 105489 | char bDistInit; /* Initializer for bDist in inner loop */ |
| 105490 | |
| 105491 | |
| 105492 | /* Initialize the cost to a worst-case value */ |
| 105493 | memset(&p->cost, 0, sizeof(p->cost)); |
| 105494 | p->cost.rCost = SQLITE_BIG_DBL; |
| 105495 | |
| @@ -105418,10 +105534,21 @@ | |
| 105534 | WHERE_COLUMN_IN|WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_RANGE |
| 105535 | ); |
| 105536 | eqTermMask = WO_EQ|WO_IN; |
| 105537 | pIdx = 0; |
| 105538 | } |
| 105539 | |
| 105540 | nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0; |
| 105541 | if( p->i ){ |
| 105542 | nPriorSat = p->aLevel[p->i-1].plan.nOBSat; |
| 105543 | bSortInit = nPriorSat<nOrderBy; |
| 105544 | bDistInit = 0; |
| 105545 | }else{ |
| 105546 | nPriorSat = 0; |
| 105547 | bSortInit = nOrderBy>0; |
| 105548 | bDistInit = p->pDistinct!=0; |
| 105549 | } |
| 105550 | |
| 105551 | /* Loop over all indices looking for the best one to use |
| 105552 | */ |
| 105553 | for(; pProbe; pIdx=pProbe=pProbe->pNext){ |
| 105554 | const tRowcnt * const aiRowEst = pProbe->aiRowEst; |
| @@ -105496,15 +105623,13 @@ | |
| 105623 | */ |
| 105624 | int bInEst = 0; /* True if "x IN (SELECT...)" seen */ |
| 105625 | int nInMul = 1; /* Number of distinct equalities to lookup */ |
| 105626 | double rangeDiv = (double)1; /* Estimated reduction in search space */ |
| 105627 | int nBound = 0; /* Number of range constraints seen */ |
| 105628 | char bSort = bSortInit; /* True if external sort required */ |
| 105629 | char bDist = bDistInit; /* True if index cannot help with DISTINCT */ |
| 105630 | char bLookup = 0; /* True if not a covering index */ |
| 105631 | WhereTerm *pTerm; /* A single term of the WHERE clause */ |
| 105632 | #ifdef SQLITE_ENABLE_STAT3 |
| 105633 | WhereTerm *pFirstTerm = 0; /* First term matching the index */ |
| 105634 | #endif |
| 105635 | |
| @@ -105511,20 +105636,11 @@ | |
| 105636 | WHERETRACE(( |
| 105637 | " %s(%s):\n", |
| 105638 | pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk") |
| 105639 | )); |
| 105640 | memset(&pc, 0, sizeof(pc)); |
| 105641 | pc.plan.nOBSat = nPriorSat; |
| 105642 | |
| 105643 | /* Determine the values of pc.plan.nEq and nInMul */ |
| 105644 | for(pc.plan.nEq=0; pc.plan.nEq<pProbe->nColumn; pc.plan.nEq++){ |
| 105645 | int j = pProbe->aiColumn[pc.plan.nEq]; |
| 105646 | pTerm = findTerm(pWC, iCur, j, p->notReady, eqTermMask, pIdx); |
| @@ -110554,11 +110670,11 @@ | |
| 110670 | spanSet(&yygotominor.yy342, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); |
| 110671 | } |
| 110672 | break; |
| 110673 | case 194: /* expr ::= expr COLLATE ids */ |
| 110674 | { |
| 110675 | yygotominor.yy342.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy342.pExpr, &yymsp[0].minor.yy0); |
| 110676 | yygotominor.yy342.zStart = yymsp[-2].minor.yy342.zStart; |
| 110677 | yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 110678 | } |
| 110679 | break; |
| 110680 | case 195: /* expr ::= CAST LP expr AS typetoken RP */ |
| @@ -110813,28 +110929,20 @@ | |
| 110929 | case 244: /* uniqueflag ::= */ |
| 110930 | {yygotominor.yy392 = OE_None;} |
| 110931 | break; |
| 110932 | case 247: /* idxlist ::= idxlist COMMA nm collate sortorder */ |
| 110933 | { |
| 110934 | Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0); |
| 110935 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy442, p); |
| 110936 | sqlite3ExprListSetName(pParse,yygotominor.yy442,&yymsp[-2].minor.yy0,1); |
| 110937 | sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index"); |
| 110938 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110939 | } |
| 110940 | break; |
| 110941 | case 248: /* idxlist ::= nm collate sortorder */ |
| 110942 | { |
| 110943 | Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0); |
| 110944 | yygotominor.yy442 = sqlite3ExprListAppend(pParse,0, p); |
| 110945 | sqlite3ExprListSetName(pParse, yygotominor.yy442, &yymsp[-2].minor.yy0, 1); |
| 110946 | sqlite3ExprListCheckLength(pParse, yygotominor.yy442, "index"); |
| 110947 | if( yygotominor.yy442 ) yygotominor.yy442->a[yygotominor.yy442->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy392; |
| 110948 | } |
| 110949 |
+12
-2
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.15" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3007015 |
| 112 | -#define SQLITE_SOURCE_ID "2012-12-05 14:31:13 9f6c68856b694373b7ffb124abd996e519ba5921" | |
| 112 | +#define SQLITE_SOURCE_ID "2012-12-08 22:14:29 92c9ab56b1c67b9468bec57ab1d2c483a69a2810" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -855,11 +855,10 @@ | ||
| 855 | 855 | ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
| 856 | 856 | ** that the VFS encountered an error while handling the [PRAGMA] and the |
| 857 | 857 | ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
| 858 | 858 | ** file control occurs at the beginning of pragma statement analysis and so |
| 859 | 859 | ** it is able to override built-in [PRAGMA] statements. |
| 860 | -** </ul> | |
| 861 | 860 | ** |
| 862 | 861 | ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
| 863 | 862 | ** ^This file-control may be invoked by SQLite on the database file handle |
| 864 | 863 | ** shortly after it is opened in order to provide a custom VFS with access |
| 865 | 864 | ** to the connections busy-handler callback. The argument is of type (void **) |
| @@ -867,10 +866,20 @@ | ||
| 867 | 866 | ** to a function of type (int (*)(void *)). In order to invoke the connections |
| 868 | 867 | ** busy-handler, this function should be invoked with the second (void *) in |
| 869 | 868 | ** the array as the only argument. If it returns non-zero, then the operation |
| 870 | 869 | ** should be retried. If it returns zero, the custom VFS should abandon the |
| 871 | 870 | ** current operation. |
| 871 | +** | |
| 872 | +** <li>[[SQLITE_FCNTL_TEMPFILENAME]] | |
| 873 | +** ^Application can invoke this file-control to have SQLite generate a | |
| 874 | +** temporary filename using the same algorithm that is followed to generate | |
| 875 | +** temporary filenames for TEMP tables and other internal uses. The | |
| 876 | +** argument should be a char** which will be filled with the filename | |
| 877 | +** written into memory obtained from [sqlite3_malloc()]. The caller should | |
| 878 | +** invoke [sqlite3_free()] on the result to avoid a memory leak. | |
| 879 | +** | |
| 880 | +** </ul> | |
| 872 | 881 | */ |
| 873 | 882 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 874 | 883 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 875 | 884 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 876 | 885 | #define SQLITE_LAST_ERRNO 4 |
| @@ -883,10 +892,11 @@ | ||
| 883 | 892 | #define SQLITE_FCNTL_OVERWRITE 11 |
| 884 | 893 | #define SQLITE_FCNTL_VFSNAME 12 |
| 885 | 894 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
| 886 | 895 | #define SQLITE_FCNTL_PRAGMA 14 |
| 887 | 896 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 897 | +#define SQLITE_FCNTL_TEMPFILENAME 16 | |
| 888 | 898 | |
| 889 | 899 | /* |
| 890 | 900 | ** CAPI3REF: Mutex Handle |
| 891 | 901 | ** |
| 892 | 902 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| 893 | 903 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.15" |
| 111 | #define SQLITE_VERSION_NUMBER 3007015 |
| 112 | #define SQLITE_SOURCE_ID "2012-12-05 14:31:13 9f6c68856b694373b7ffb124abd996e519ba5921" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -855,11 +855,10 @@ | |
| 855 | ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
| 856 | ** that the VFS encountered an error while handling the [PRAGMA] and the |
| 857 | ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
| 858 | ** file control occurs at the beginning of pragma statement analysis and so |
| 859 | ** it is able to override built-in [PRAGMA] statements. |
| 860 | ** </ul> |
| 861 | ** |
| 862 | ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
| 863 | ** ^This file-control may be invoked by SQLite on the database file handle |
| 864 | ** shortly after it is opened in order to provide a custom VFS with access |
| 865 | ** to the connections busy-handler callback. The argument is of type (void **) |
| @@ -867,10 +866,20 @@ | |
| 867 | ** to a function of type (int (*)(void *)). In order to invoke the connections |
| 868 | ** busy-handler, this function should be invoked with the second (void *) in |
| 869 | ** the array as the only argument. If it returns non-zero, then the operation |
| 870 | ** should be retried. If it returns zero, the custom VFS should abandon the |
| 871 | ** current operation. |
| 872 | */ |
| 873 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 874 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 875 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 876 | #define SQLITE_LAST_ERRNO 4 |
| @@ -883,10 +892,11 @@ | |
| 883 | #define SQLITE_FCNTL_OVERWRITE 11 |
| 884 | #define SQLITE_FCNTL_VFSNAME 12 |
| 885 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
| 886 | #define SQLITE_FCNTL_PRAGMA 14 |
| 887 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 888 | |
| 889 | /* |
| 890 | ** CAPI3REF: Mutex Handle |
| 891 | ** |
| 892 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| 893 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.15" |
| 111 | #define SQLITE_VERSION_NUMBER 3007015 |
| 112 | #define SQLITE_SOURCE_ID "2012-12-08 22:14:29 92c9ab56b1c67b9468bec57ab1d2c483a69a2810" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -855,11 +855,10 @@ | |
| 855 | ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
| 856 | ** that the VFS encountered an error while handling the [PRAGMA] and the |
| 857 | ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
| 858 | ** file control occurs at the beginning of pragma statement analysis and so |
| 859 | ** it is able to override built-in [PRAGMA] statements. |
| 860 | ** |
| 861 | ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
| 862 | ** ^This file-control may be invoked by SQLite on the database file handle |
| 863 | ** shortly after it is opened in order to provide a custom VFS with access |
| 864 | ** to the connections busy-handler callback. The argument is of type (void **) |
| @@ -867,10 +866,20 @@ | |
| 866 | ** to a function of type (int (*)(void *)). In order to invoke the connections |
| 867 | ** busy-handler, this function should be invoked with the second (void *) in |
| 868 | ** the array as the only argument. If it returns non-zero, then the operation |
| 869 | ** should be retried. If it returns zero, the custom VFS should abandon the |
| 870 | ** current operation. |
| 871 | ** |
| 872 | ** <li>[[SQLITE_FCNTL_TEMPFILENAME]] |
| 873 | ** ^Application can invoke this file-control to have SQLite generate a |
| 874 | ** temporary filename using the same algorithm that is followed to generate |
| 875 | ** temporary filenames for TEMP tables and other internal uses. The |
| 876 | ** argument should be a char** which will be filled with the filename |
| 877 | ** written into memory obtained from [sqlite3_malloc()]. The caller should |
| 878 | ** invoke [sqlite3_free()] on the result to avoid a memory leak. |
| 879 | ** |
| 880 | ** </ul> |
| 881 | */ |
| 882 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 883 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 884 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 885 | #define SQLITE_LAST_ERRNO 4 |
| @@ -883,10 +892,11 @@ | |
| 892 | #define SQLITE_FCNTL_OVERWRITE 11 |
| 893 | #define SQLITE_FCNTL_VFSNAME 12 |
| 894 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
| 895 | #define SQLITE_FCNTL_PRAGMA 14 |
| 896 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 897 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 898 | |
| 899 | /* |
| 900 | ** CAPI3REF: Mutex Handle |
| 901 | ** |
| 902 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| 903 |