Fossil SCM
Use the latest SQLite 3.8.3 alpha from upstream.
Commit
da90bbe591a535533c9ce82a0609756e66f279d1
Parent
60acb3183d3c130…
2 files changed
+167
-73
+7
-5
+167
-73
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -135,11 +135,11 @@ | ||
| 135 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 137 | */ |
| 138 | 138 | #define SQLITE_VERSION "3.8.3" |
| 139 | 139 | #define SQLITE_VERSION_NUMBER 3008003 |
| 140 | -#define SQLITE_SOURCE_ID "2013-12-23 11:33:32 25b8a1c9ba77df3b7c78cbce922cb593d661696d" | |
| 140 | +#define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6" | |
| 141 | 141 | |
| 142 | 142 | /* |
| 143 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 145 | ** |
| @@ -2426,15 +2426,17 @@ | ||
| 2426 | 2426 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2427 | 2427 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2428 | 2428 | ** applications to access the same PRNG for other purposes. |
| 2429 | 2429 | ** |
| 2430 | 2430 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2431 | +** ^If N is less than one, then P can be a NULL pointer. | |
| 2431 | 2432 | ** |
| 2432 | -** ^The first time this routine is invoked (either internally or by | |
| 2433 | -** the application) the PRNG is seeded using randomness obtained | |
| 2434 | -** from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2435 | -** ^On all subsequent invocations, the pseudo-randomness is generated | |
| 2433 | +** ^If this routine has not been previously called or if the previous | |
| 2434 | +** call had N less than one, then the PRNG is seeded using randomness | |
| 2435 | +** obtained from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2436 | +** ^If the previous call to this routine had an N of 1 or more then | |
| 2437 | +** the pseudo-randomness is generated | |
| 2436 | 2438 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2437 | 2439 | ** method. |
| 2438 | 2440 | */ |
| 2439 | 2441 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2440 | 2442 | |
| @@ -9278,10 +9280,11 @@ | ||
| 9278 | 9280 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 9279 | 9281 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 9280 | 9282 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 9281 | 9283 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 9282 | 9284 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 9285 | +SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe*); | |
| 9283 | 9286 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 9284 | 9287 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 9285 | 9288 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 9286 | 9289 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| 9287 | 9290 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*); |
| @@ -10371,11 +10374,11 @@ | ||
| 10371 | 10374 | */ |
| 10372 | 10375 | #define SQLITE_QueryFlattener 0x0001 /* Query flattening */ |
| 10373 | 10376 | #define SQLITE_ColumnCache 0x0002 /* Column cache */ |
| 10374 | 10377 | #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ |
| 10375 | 10378 | #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ |
| 10376 | -#define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */ | |
| 10379 | +/* not used 0x0010 // Was: SQLITE_IdxRealAsInt */ | |
| 10377 | 10380 | #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ |
| 10378 | 10381 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10379 | 10382 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10380 | 10383 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10381 | 10384 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| @@ -11605,10 +11608,13 @@ | ||
| 11605 | 11608 | int nErr; /* Number of errors seen */ |
| 11606 | 11609 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 11607 | 11610 | int nMem; /* Number of memory cells used so far */ |
| 11608 | 11611 | int nSet; /* Number of sets used so far */ |
| 11609 | 11612 | int nOnce; /* Number of OP_Once instructions so far */ |
| 11613 | + int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ | |
| 11614 | + int nLabel; /* Number of labels used */ | |
| 11615 | + int *aLabel; /* Space to hold the labels */ | |
| 11610 | 11616 | int ckBase; /* Base register of data during check constraints */ |
| 11611 | 11617 | int iPartIdxTab; /* Table corresponding to a partial index */ |
| 11612 | 11618 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 11613 | 11619 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 11614 | 11620 | struct yColCache { |
| @@ -12284,11 +12290,10 @@ | ||
| 12284 | 12290 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12285 | 12291 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12286 | 12292 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12287 | 12293 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12288 | 12294 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12289 | -SQLITE_PRIVATE void sqlite3PrngResetState(void); | |
| 12290 | 12295 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12291 | 12296 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12292 | 12297 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12293 | 12298 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12294 | 12299 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -13776,19 +13781,13 @@ | ||
| 13776 | 13781 | Op *aOp; /* Space to hold the virtual machine's program */ |
| 13777 | 13782 | Mem *aMem; /* The memory locations */ |
| 13778 | 13783 | Mem **apArg; /* Arguments to currently executing user function */ |
| 13779 | 13784 | Mem *aColName; /* Column names to return */ |
| 13780 | 13785 | Mem *pResultSet; /* Pointer to an array of results */ |
| 13781 | -#ifdef SQLITE_DEBUG | |
| 13782 | 13786 | Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 13783 | -#endif | |
| 13784 | 13787 | int nMem; /* Number of memory locations currently allocated */ |
| 13785 | 13788 | int nOp; /* Number of instructions in the program */ |
| 13786 | - int nOpAlloc; /* Number of slots allocated for aOp[] */ | |
| 13787 | - int nLabel; /* Number of labels used */ | |
| 13788 | - int *aLabel; /* Space to hold the labels */ | |
| 13789 | - u16 nResColumn; /* Number of columns in one row of the result set */ | |
| 13790 | 13789 | int nCursor; /* Number of slots in apCsr[] */ |
| 13791 | 13790 | u32 magic; /* Magic number for sanity checking */ |
| 13792 | 13791 | char *zErrMsg; /* Error message written here */ |
| 13793 | 13792 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 13794 | 13793 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| @@ -13797,10 +13796,11 @@ | ||
| 13797 | 13796 | ynVar nVar; /* Number of entries in aVar[] */ |
| 13798 | 13797 | ynVar nzVar; /* Number of entries in azVar[] */ |
| 13799 | 13798 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 13800 | 13799 | int pc; /* The program counter */ |
| 13801 | 13800 | int rc; /* Value to return */ |
| 13801 | + u16 nResColumn; /* Number of columns in one row of the result set */ | |
| 13802 | 13802 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 13803 | 13803 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 13804 | 13804 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 13805 | 13805 | bft inVtabMethod:2; /* See comments above */ |
| 13806 | 13806 | bft changeCntOn:1; /* True to update the change-counter */ |
| @@ -20901,10 +20901,16 @@ | ||
| 20901 | 20901 | |
| 20902 | 20902 | #if SQLITE_THREADSAFE |
| 20903 | 20903 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20904 | 20904 | sqlite3_mutex_enter(mutex); |
| 20905 | 20905 | #endif |
| 20906 | + | |
| 20907 | + if( N<=0 ){ | |
| 20908 | + wsdPrng.isInit = 0; | |
| 20909 | + sqlite3_mutex_leave(mutex); | |
| 20910 | + return; | |
| 20911 | + } | |
| 20906 | 20912 | |
| 20907 | 20913 | /* Initialize the state of the random number generator once, |
| 20908 | 20914 | ** the first time this routine is called. The seed value does |
| 20909 | 20915 | ** not need to contain a lot of randomness since we are not |
| 20910 | 20916 | ** trying to do secure encryption or anything like that... |
| @@ -20929,19 +20935,20 @@ | ||
| 20929 | 20935 | wsdPrng.s[i] = t; |
| 20930 | 20936 | } |
| 20931 | 20937 | wsdPrng.isInit = 1; |
| 20932 | 20938 | } |
| 20933 | 20939 | |
| 20934 | - while( N-- ){ | |
| 20940 | + assert( N>0 ); | |
| 20941 | + do{ | |
| 20935 | 20942 | wsdPrng.i++; |
| 20936 | 20943 | t = wsdPrng.s[wsdPrng.i]; |
| 20937 | 20944 | wsdPrng.j += t; |
| 20938 | 20945 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20939 | 20946 | wsdPrng.s[wsdPrng.j] = t; |
| 20940 | 20947 | t += wsdPrng.s[wsdPrng.i]; |
| 20941 | 20948 | *(zBuf++) = wsdPrng.s[t]; |
| 20942 | - } | |
| 20949 | + }while( --N ); | |
| 20943 | 20950 | sqlite3_mutex_leave(mutex); |
| 20944 | 20951 | } |
| 20945 | 20952 | |
| 20946 | 20953 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20947 | 20954 | /* |
| @@ -20966,13 +20973,10 @@ | ||
| 20966 | 20973 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20967 | 20974 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20968 | 20975 | sizeof(sqlite3Prng) |
| 20969 | 20976 | ); |
| 20970 | 20977 | } |
| 20971 | -SQLITE_PRIVATE void sqlite3PrngResetState(void){ | |
| 20972 | - GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0; | |
| 20973 | -} | |
| 20974 | 20978 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20975 | 20979 | |
| 20976 | 20980 | /************** End of random.c **********************************************/ |
| 20977 | 20981 | /************** Begin file utf.c *********************************************/ |
| 20978 | 20982 | /* |
| @@ -23505,10 +23509,16 @@ | ||
| 23505 | 23509 | ** it is larger than the struct CrashFile defined in test6.c. |
| 23506 | 23510 | */ |
| 23507 | 23511 | char aPadding[32]; |
| 23508 | 23512 | #endif |
| 23509 | 23513 | }; |
| 23514 | + | |
| 23515 | +/* This variable holds the process id (pid) from when the xRandomness() | |
| 23516 | +** method was called. If xOpen() is called from a different process id, | |
| 23517 | +** indicating that a fork() has occurred, the PRNG will be reset. | |
| 23518 | +*/ | |
| 23519 | +static int randomnessPid = 0; | |
| 23510 | 23520 | |
| 23511 | 23521 | /* |
| 23512 | 23522 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23513 | 23523 | */ |
| 23514 | 23524 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| @@ -29104,10 +29114,20 @@ | ||
| 29104 | 29114 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB |
| 29105 | 29115 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 29106 | 29116 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 29107 | 29117 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 29108 | 29118 | ); |
| 29119 | + | |
| 29120 | + /* Detect a pid change and reset the PRNG. There is a race condition | |
| 29121 | + ** here such that two or more threads all trying to open databases at | |
| 29122 | + ** the same instant might all reset the PRNG. But multiple resets | |
| 29123 | + ** are harmless. | |
| 29124 | + */ | |
| 29125 | + if( randomnessPid!=getpid() ){ | |
| 29126 | + randomnessPid = getpid(); | |
| 29127 | + sqlite3_randomness(0,0); | |
| 29128 | + } | |
| 29109 | 29129 | |
| 29110 | 29130 | memset(p, 0, sizeof(unixFile)); |
| 29111 | 29131 | |
| 29112 | 29132 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 29113 | 29133 | UnixUnusedFd *pUnused; |
| @@ -29492,22 +29512,22 @@ | ||
| 29492 | 29512 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29493 | 29513 | ** that we always use the same random number sequence. This makes the |
| 29494 | 29514 | ** tests repeatable. |
| 29495 | 29515 | */ |
| 29496 | 29516 | memset(zBuf, 0, nBuf); |
| 29517 | + randomnessPid = getpid(); | |
| 29497 | 29518 | #if !defined(SQLITE_TEST) |
| 29498 | 29519 | { |
| 29499 | - int pid, fd, got; | |
| 29520 | + int fd, got; | |
| 29500 | 29521 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29501 | 29522 | if( fd<0 ){ |
| 29502 | 29523 | time_t t; |
| 29503 | 29524 | time(&t); |
| 29504 | 29525 | memcpy(zBuf, &t, sizeof(t)); |
| 29505 | - pid = getpid(); | |
| 29506 | - memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); | |
| 29507 | - assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); | |
| 29508 | - nBuf = sizeof(t) + sizeof(pid); | |
| 29526 | + memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid)); | |
| 29527 | + assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf ); | |
| 29528 | + nBuf = sizeof(t) + sizeof(randomnessPid); | |
| 29509 | 29529 | }else{ |
| 29510 | 29530 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29511 | 29531 | robust_close(0, fd, __LINE__); |
| 29512 | 29532 | } |
| 29513 | 29533 | } |
| @@ -61200,13 +61220,14 @@ | ||
| 61200 | 61220 | } |
| 61201 | 61221 | p->pNext = db->pVdbe; |
| 61202 | 61222 | p->pPrev = 0; |
| 61203 | 61223 | db->pVdbe = p; |
| 61204 | 61224 | p->magic = VDBE_MAGIC_INIT; |
| 61205 | -#if SQLITE_DEBUG | |
| 61206 | 61225 | p->pParse = pParse; |
| 61207 | -#endif | |
| 61226 | + assert( pParse->aLabel==0 ); | |
| 61227 | + assert( pParse->nLabel==0 ); | |
| 61228 | + assert( pParse->nOpAlloc==0 ); | |
| 61208 | 61229 | return p; |
| 61209 | 61230 | } |
| 61210 | 61231 | |
| 61211 | 61232 | /* |
| 61212 | 61233 | ** Remember the SQL string for a prepared statement. |
| @@ -61258,17 +61279,18 @@ | ||
| 61258 | 61279 | ** If an out-of-memory error occurs while resizing the array, return |
| 61259 | 61280 | ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain |
| 61260 | 61281 | ** unchanged (this is so that any opcodes already allocated can be |
| 61261 | 61282 | ** correctly deallocated along with the rest of the Vdbe). |
| 61262 | 61283 | */ |
| 61263 | -static int growOpArray(Vdbe *p){ | |
| 61284 | +static int growOpArray(Vdbe *v){ | |
| 61264 | 61285 | VdbeOp *pNew; |
| 61286 | + Parse *p = v->pParse; | |
| 61265 | 61287 | int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op))); |
| 61266 | - pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op)); | |
| 61288 | + pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); | |
| 61267 | 61289 | if( pNew ){ |
| 61268 | 61290 | p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op); |
| 61269 | - p->aOp = pNew; | |
| 61291 | + v->aOp = pNew; | |
| 61270 | 61292 | } |
| 61271 | 61293 | return (pNew ? SQLITE_OK : SQLITE_NOMEM); |
| 61272 | 61294 | } |
| 61273 | 61295 | |
| 61274 | 61296 | #ifdef SQLITE_DEBUG |
| @@ -61303,11 +61325,11 @@ | ||
| 61303 | 61325 | VdbeOp *pOp; |
| 61304 | 61326 | |
| 61305 | 61327 | i = p->nOp; |
| 61306 | 61328 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61307 | 61329 | assert( op>0 && op<0xff ); |
| 61308 | - if( p->nOpAlloc<=i ){ | |
| 61330 | + if( p->pParse->nOpAlloc<=i ){ | |
| 61309 | 61331 | if( growOpArray(p) ){ |
| 61310 | 61332 | return 1; |
| 61311 | 61333 | } |
| 61312 | 61334 | } |
| 61313 | 61335 | p->nOp++; |
| @@ -61414,13 +61436,14 @@ | ||
| 61414 | 61436 | ** always negative and P2 values are suppose to be non-negative. |
| 61415 | 61437 | ** Hence, a negative P2 value is a label that has yet to be resolved. |
| 61416 | 61438 | ** |
| 61417 | 61439 | ** Zero is returned if a malloc() fails. |
| 61418 | 61440 | */ |
| 61419 | -SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){ | |
| 61441 | +SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *v){ | |
| 61442 | + Parse *p = v->pParse; | |
| 61420 | 61443 | int i = p->nLabel++; |
| 61421 | - assert( p->magic==VDBE_MAGIC_INIT ); | |
| 61444 | + assert( v->magic==VDBE_MAGIC_INIT ); | |
| 61422 | 61445 | if( (i & (i-1))==0 ){ |
| 61423 | 61446 | p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, |
| 61424 | 61447 | (i*2+1)*sizeof(p->aLabel[0])); |
| 61425 | 61448 | } |
| 61426 | 61449 | if( p->aLabel ){ |
| @@ -61432,16 +61455,17 @@ | ||
| 61432 | 61455 | /* |
| 61433 | 61456 | ** Resolve label "x" to be the address of the next instruction to |
| 61434 | 61457 | ** be inserted. The parameter "x" must have been obtained from |
| 61435 | 61458 | ** a prior call to sqlite3VdbeMakeLabel(). |
| 61436 | 61459 | */ |
| 61437 | -SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){ | |
| 61460 | +SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ | |
| 61461 | + Parse *p = v->pParse; | |
| 61438 | 61462 | int j = -1-x; |
| 61439 | - assert( p->magic==VDBE_MAGIC_INIT ); | |
| 61463 | + assert( v->magic==VDBE_MAGIC_INIT ); | |
| 61440 | 61464 | assert( j<p->nLabel ); |
| 61441 | 61465 | if( j>=0 && p->aLabel ){ |
| 61442 | - p->aLabel[j] = p->nOp; | |
| 61466 | + p->aLabel[j] = v->nOp; | |
| 61443 | 61467 | } |
| 61444 | 61468 | } |
| 61445 | 61469 | |
| 61446 | 61470 | /* |
| 61447 | 61471 | ** Mark the VDBE as one that can only be run one time. |
| @@ -61586,11 +61610,12 @@ | ||
| 61586 | 61610 | */ |
| 61587 | 61611 | static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ |
| 61588 | 61612 | int i; |
| 61589 | 61613 | int nMaxArgs = *pMaxFuncArgs; |
| 61590 | 61614 | Op *pOp; |
| 61591 | - int *aLabel = p->aLabel; | |
| 61615 | + Parse *pParse = p->pParse; | |
| 61616 | + int *aLabel = pParse->aLabel; | |
| 61592 | 61617 | p->readOnly = 1; |
| 61593 | 61618 | p->bIsReader = 0; |
| 61594 | 61619 | for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ |
| 61595 | 61620 | u8 opcode = pOp->opcode; |
| 61596 | 61621 | |
| @@ -61649,16 +61674,17 @@ | ||
| 61649 | 61674 | } |
| 61650 | 61675 | } |
| 61651 | 61676 | |
| 61652 | 61677 | pOp->opflags = sqlite3OpcodeProperty[opcode]; |
| 61653 | 61678 | if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 61654 | - assert( -1-pOp->p2<p->nLabel ); | |
| 61679 | + assert( -1-pOp->p2<pParse->nLabel ); | |
| 61655 | 61680 | pOp->p2 = aLabel[-1-pOp->p2]; |
| 61656 | 61681 | } |
| 61657 | 61682 | } |
| 61658 | - sqlite3DbFree(p->db, p->aLabel); | |
| 61659 | - p->aLabel = 0; | |
| 61683 | + sqlite3DbFree(p->db, pParse->aLabel); | |
| 61684 | + pParse->aLabel = 0; | |
| 61685 | + pParse->nLabel = 0; | |
| 61660 | 61686 | *pMaxFuncArgs = nMaxArgs; |
| 61661 | 61687 | assert( p->bIsReader!=0 || p->btreeMask==0 ); |
| 61662 | 61688 | } |
| 61663 | 61689 | |
| 61664 | 61690 | /* |
| @@ -61698,11 +61724,11 @@ | ||
| 61698 | 61724 | ** address of the first operation added. |
| 61699 | 61725 | */ |
| 61700 | 61726 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ |
| 61701 | 61727 | int addr; |
| 61702 | 61728 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61703 | - if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){ | |
| 61729 | + if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){ | |
| 61704 | 61730 | return 0; |
| 61705 | 61731 | } |
| 61706 | 61732 | addr = p->nOp; |
| 61707 | 61733 | if( ALWAYS(nOp>0) ){ |
| 61708 | 61734 | int i; |
| @@ -61886,10 +61912,17 @@ | ||
| 61886 | 61912 | memset(pOp, 0, sizeof(pOp[0])); |
| 61887 | 61913 | pOp->opcode = OP_Noop; |
| 61888 | 61914 | if( addr==p->nOp-1 ) p->nOp--; |
| 61889 | 61915 | } |
| 61890 | 61916 | } |
| 61917 | + | |
| 61918 | +/* | |
| 61919 | +** Remove the last opcode inserted | |
| 61920 | +*/ | |
| 61921 | +SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe *p){ | |
| 61922 | + p->nOp--; | |
| 61923 | +} | |
| 61891 | 61924 | |
| 61892 | 61925 | /* |
| 61893 | 61926 | ** Change the value of the P4 operand for a specific instruction. |
| 61894 | 61927 | ** This routine is useful when a large program is loaded from a |
| 61895 | 61928 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| @@ -62768,10 +62801,11 @@ | ||
| 62768 | 62801 | |
| 62769 | 62802 | assert( p!=0 ); |
| 62770 | 62803 | assert( p->nOp>0 ); |
| 62771 | 62804 | assert( pParse!=0 ); |
| 62772 | 62805 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 62806 | + assert( pParse==p->pParse ); | |
| 62773 | 62807 | db = p->db; |
| 62774 | 62808 | assert( db->mallocFailed==0 ); |
| 62775 | 62809 | nVar = pParse->nVar; |
| 62776 | 62810 | nMem = pParse->nMem; |
| 62777 | 62811 | nCursor = pParse->nTab; |
| @@ -62791,12 +62825,12 @@ | ||
| 62791 | 62825 | nMem += nCursor; |
| 62792 | 62826 | |
| 62793 | 62827 | /* Allocate space for memory registers, SQL variables, VDBE cursors and |
| 62794 | 62828 | ** an array to marshal SQL function arguments in. |
| 62795 | 62829 | */ |
| 62796 | - zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ | |
| 62797 | - zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */ | |
| 62830 | + zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ | |
| 62831 | + zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */ | |
| 62798 | 62832 | |
| 62799 | 62833 | resolveP2Values(p, &nArg); |
| 62800 | 62834 | p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort); |
| 62801 | 62835 | if( pParse->explain && nMem<10 ){ |
| 62802 | 62836 | nMem = 10; |
| @@ -63795,11 +63829,10 @@ | ||
| 63795 | 63829 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 63796 | 63830 | sqlite3DbFree(db, pSub); |
| 63797 | 63831 | } |
| 63798 | 63832 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 63799 | 63833 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 63800 | - sqlite3DbFree(db, p->aLabel); | |
| 63801 | 63834 | sqlite3DbFree(db, p->aColName); |
| 63802 | 63835 | sqlite3DbFree(db, p->zSql); |
| 63803 | 63836 | sqlite3DbFree(db, p->pFree); |
| 63804 | 63837 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 63805 | 63838 | sqlite3DbFree(db, p->zExplain); |
| @@ -76765,20 +76798,29 @@ | ||
| 76765 | 76798 | } |
| 76766 | 76799 | return p; |
| 76767 | 76800 | } |
| 76768 | 76801 | |
| 76769 | 76802 | /* |
| 76770 | -** Return 1 if an expression must be FALSE in all cases and 0 if the | |
| 76771 | -** expression might be true. This is an optimization. If is OK to | |
| 76772 | -** return 0 here even if the expression really is always false (a | |
| 76773 | -** false negative). But it is a bug to return 1 if the expression | |
| 76774 | -** might be true in some rare circumstances (a false positive.) | |
| 76803 | +** If the expression is always either TRUE or FALSE (respectively), | |
| 76804 | +** then return 1. If one cannot determine the truth value of the | |
| 76805 | +** expression at compile-time return 0. | |
| 76806 | +** | |
| 76807 | +** This is an optimization. If is OK to return 0 here even if | |
| 76808 | +** the expression really is always false or false (a false negative). | |
| 76809 | +** But it is a bug to return 1 if the expression might have different | |
| 76810 | +** boolean values in different circumstances (a false positive.) | |
| 76775 | 76811 | ** |
| 76776 | 76812 | ** Note that if the expression is part of conditional for a |
| 76777 | 76813 | ** LEFT JOIN, then we cannot determine at compile-time whether or not |
| 76778 | 76814 | ** is it true or false, so always return 0. |
| 76779 | 76815 | */ |
| 76816 | +static int exprAlwaysTrue(Expr *p){ | |
| 76817 | + int v = 0; | |
| 76818 | + if( ExprHasProperty(p, EP_FromJoin) ) return 0; | |
| 76819 | + if( !sqlite3ExprIsInteger(p, &v) ) return 0; | |
| 76820 | + return v!=0; | |
| 76821 | +} | |
| 76780 | 76822 | static int exprAlwaysFalse(Expr *p){ |
| 76781 | 76823 | int v = 0; |
| 76782 | 76824 | if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 76783 | 76825 | if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 76784 | 76826 | return v==0; |
| @@ -79621,11 +79663,11 @@ | ||
| 79621 | 79663 | sqlite3ExplainPush(pOut); |
| 79622 | 79664 | for(i=0; i<pList->nExpr; i++){ |
| 79623 | 79665 | sqlite3ExplainPrintf(pOut, "item[%d] = ", i); |
| 79624 | 79666 | sqlite3ExplainPush(pOut); |
| 79625 | 79667 | sqlite3ExplainExpr(pOut, pList->a[i].pExpr); |
| 79626 | - sqlite3ExplainPop(pOut); | |
| 79668 | + sqlite3ExplainPop(pOut, 1); | |
| 79627 | 79669 | if( pList->a[i].zName ){ |
| 79628 | 79670 | sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName); |
| 79629 | 79671 | } |
| 79630 | 79672 | if( pList->a[i].bSpanIsTab ){ |
| 79631 | 79673 | sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan); |
| @@ -79771,21 +79813,23 @@ | ||
| 79771 | 79813 | op = pExpr->op; |
| 79772 | 79814 | switch( op ){ |
| 79773 | 79815 | case TK_AND: { |
| 79774 | 79816 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79775 | 79817 | testcase( jumpIfNull==0 ); |
| 79776 | - sqlite3ExprCachePush(pParse); | |
| 79777 | 79818 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL); |
| 79819 | + sqlite3ExprCachePush(pParse); | |
| 79778 | 79820 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79779 | 79821 | sqlite3VdbeResolveLabel(v, d2); |
| 79780 | 79822 | sqlite3ExprCachePop(pParse, 1); |
| 79781 | 79823 | break; |
| 79782 | 79824 | } |
| 79783 | 79825 | case TK_OR: { |
| 79784 | 79826 | testcase( jumpIfNull==0 ); |
| 79785 | 79827 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79828 | + sqlite3ExprCachePush(pParse); | |
| 79786 | 79829 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79830 | + sqlite3ExprCachePop(pParse, 1); | |
| 79787 | 79831 | break; |
| 79788 | 79832 | } |
| 79789 | 79833 | case TK_NOT: { |
| 79790 | 79834 | testcase( jumpIfNull==0 ); |
| 79791 | 79835 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| @@ -79856,14 +79900,20 @@ | ||
| 79856 | 79900 | sqlite3VdbeResolveLabel(v, destIfFalse); |
| 79857 | 79901 | break; |
| 79858 | 79902 | } |
| 79859 | 79903 | #endif |
| 79860 | 79904 | default: { |
| 79861 | - r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); | |
| 79862 | - sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); | |
| 79863 | - testcase( regFree1==0 ); | |
| 79864 | - testcase( jumpIfNull==0 ); | |
| 79905 | + if( exprAlwaysTrue(pExpr) ){ | |
| 79906 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, dest); | |
| 79907 | + }else if( exprAlwaysFalse(pExpr) ){ | |
| 79908 | + /* No-op */ | |
| 79909 | + }else{ | |
| 79910 | + r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); | |
| 79911 | + sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); | |
| 79912 | + testcase( regFree1==0 ); | |
| 79913 | + testcase( jumpIfNull==0 ); | |
| 79914 | + } | |
| 79865 | 79915 | break; |
| 79866 | 79916 | } |
| 79867 | 79917 | } |
| 79868 | 79918 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 79869 | 79919 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -79922,18 +79972,20 @@ | ||
| 79922 | 79972 | |
| 79923 | 79973 | switch( pExpr->op ){ |
| 79924 | 79974 | case TK_AND: { |
| 79925 | 79975 | testcase( jumpIfNull==0 ); |
| 79926 | 79976 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79977 | + sqlite3ExprCachePush(pParse); | |
| 79927 | 79978 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79979 | + sqlite3ExprCachePop(pParse, 1); | |
| 79928 | 79980 | break; |
| 79929 | 79981 | } |
| 79930 | 79982 | case TK_OR: { |
| 79931 | 79983 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79932 | 79984 | testcase( jumpIfNull==0 ); |
| 79933 | - sqlite3ExprCachePush(pParse); | |
| 79934 | 79985 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL); |
| 79986 | + sqlite3ExprCachePush(pParse); | |
| 79935 | 79987 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79936 | 79988 | sqlite3VdbeResolveLabel(v, d2); |
| 79937 | 79989 | sqlite3ExprCachePop(pParse, 1); |
| 79938 | 79990 | break; |
| 79939 | 79991 | } |
| @@ -80001,14 +80053,20 @@ | ||
| 80001 | 80053 | } |
| 80002 | 80054 | break; |
| 80003 | 80055 | } |
| 80004 | 80056 | #endif |
| 80005 | 80057 | default: { |
| 80006 | - r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); | |
| 80007 | - sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); | |
| 80008 | - testcase( regFree1==0 ); | |
| 80009 | - testcase( jumpIfNull==0 ); | |
| 80058 | + if( exprAlwaysFalse(pExpr) ){ | |
| 80059 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, dest); | |
| 80060 | + }else if( exprAlwaysTrue(pExpr) ){ | |
| 80061 | + /* no-op */ | |
| 80062 | + }else{ | |
| 80063 | + r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); | |
| 80064 | + sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); | |
| 80065 | + testcase( regFree1==0 ); | |
| 80066 | + testcase( jumpIfNull==0 ); | |
| 80067 | + } | |
| 80010 | 80068 | break; |
| 80011 | 80069 | } |
| 80012 | 80070 | } |
| 80013 | 80071 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 80014 | 80072 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -89357,22 +89415,22 @@ | ||
| 89357 | 89415 | nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn; |
| 89358 | 89416 | regBase = sqlite3GetTempRange(pParse, nCol); |
| 89359 | 89417 | for(j=0; j<nCol; j++){ |
| 89360 | 89418 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j], |
| 89361 | 89419 | regBase+j); |
| 89420 | + /* If the column affinity is REAL but the number is an integer, then it | |
| 89421 | + ** might be stored in the table as an integer (using a compact | |
| 89422 | + ** representation) then converted to REAL by an OP_RealAffinity opcode. | |
| 89423 | + ** But we are getting ready to store this value back into an index, where | |
| 89424 | + ** it should be converted by to INTEGER again. So omit the OP_RealAffinity | |
| 89425 | + ** opcode if it is present */ | |
| 89426 | + if( sqlite3VdbeGetOp(v, -1)->opcode==OP_RealAffinity ){ | |
| 89427 | + sqlite3VdbeDeleteLastOpcode(v); | |
| 89428 | + } | |
| 89362 | 89429 | } |
| 89363 | 89430 | if( regOut ){ |
| 89364 | - const char *zAff; | |
| 89365 | - if( pTab->pSelect | |
| 89366 | - || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt) | |
| 89367 | - ){ | |
| 89368 | - zAff = 0; | |
| 89369 | - }else{ | |
| 89370 | - zAff = sqlite3IndexAffinityStr(v, pIdx); | |
| 89371 | - } | |
| 89372 | 89431 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 89373 | - sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT); | |
| 89374 | 89432 | } |
| 89375 | 89433 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 89376 | 89434 | return regBase; |
| 89377 | 89435 | } |
| 89378 | 89436 | |
| @@ -93721,10 +93779,11 @@ | ||
| 93721 | 93779 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 93722 | 93780 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 93723 | 93781 | int ipkTop = 0; /* Top of the rowid change constraint check */ |
| 93724 | 93782 | int ipkBottom = 0; /* Bottom of the rowid change constraint check */ |
| 93725 | 93783 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| 93784 | + int regRowid = -1; /* Register holding ROWID value */ | |
| 93726 | 93785 | |
| 93727 | 93786 | isUpdate = regOldData!=0; |
| 93728 | 93787 | db = pParse->db; |
| 93729 | 93788 | v = sqlite3GetVdbe(pParse); |
| 93730 | 93789 | assert( v!=0 ); |
| @@ -93951,11 +94010,13 @@ | ||
| 93951 | 94010 | regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn); |
| 93952 | 94011 | for(i=0; i<pIdx->nColumn; i++){ |
| 93953 | 94012 | int iField = pIdx->aiColumn[i]; |
| 93954 | 94013 | int x; |
| 93955 | 94014 | if( iField<0 || iField==pTab->iPKey ){ |
| 94015 | + if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */ | |
| 93956 | 94016 | x = regNewData; |
| 94017 | + regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i; | |
| 93957 | 94018 | }else{ |
| 93958 | 94019 | x = iField + regNewData + 1; |
| 93959 | 94020 | } |
| 93960 | 94021 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 93961 | 94022 | VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); |
| @@ -98780,11 +98841,15 @@ | ||
| 98780 | 98841 | |
| 98781 | 98842 | /* |
| 98782 | 98843 | ** Free all memory allocations in the pParse object |
| 98783 | 98844 | */ |
| 98784 | 98845 | SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ |
| 98785 | - if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr); | |
| 98846 | + if( pParse ){ | |
| 98847 | + sqlite3 *db = pParse->db; | |
| 98848 | + sqlite3DbFree(db, pParse->aLabel); | |
| 98849 | + sqlite3ExprListDelete(db, pParse->pConstExpr); | |
| 98850 | + } | |
| 98786 | 98851 | } |
| 98787 | 98852 | |
| 98788 | 98853 | /* |
| 98789 | 98854 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 98790 | 98855 | */ |
| @@ -113528,13 +113593,16 @@ | ||
| 113528 | 113593 | sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 113529 | 113594 | |
| 113530 | 113595 | /* Special case: a WHERE clause that is constant. Evaluate the |
| 113531 | 113596 | ** expression and either jump over all of the code or fall thru. |
| 113532 | 113597 | */ |
| 113533 | - if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){ | |
| 113534 | - sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL); | |
| 113535 | - pWhere = 0; | |
| 113598 | + for(ii=0; ii<sWLB.pWC->nTerm; ii++){ | |
| 113599 | + if( nTabList==0 || sqlite3ExprIsConstantNotJoin(sWLB.pWC->a[ii].pExpr) ){ | |
| 113600 | + sqlite3ExprIfFalse(pParse, sWLB.pWC->a[ii].pExpr, pWInfo->iBreak, | |
| 113601 | + SQLITE_JUMPIFNULL); | |
| 113602 | + sWLB.pWC->a[ii].wtFlags |= TERM_CODED; | |
| 113603 | + } | |
| 113536 | 113604 | } |
| 113537 | 113605 | |
| 113538 | 113606 | /* Special case: No FROM clause |
| 113539 | 113607 | */ |
| 113540 | 113608 | if( nTabList==0 ){ |
| @@ -121784,11 +121852,11 @@ | ||
| 121784 | 121852 | ** Reset the PRNG back to its uninitialized state. The next call |
| 121785 | 121853 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 121786 | 121854 | ** to the xRandomness method of the default VFS. |
| 121787 | 121855 | */ |
| 121788 | 121856 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 121789 | - sqlite3PrngResetState(); | |
| 121857 | + sqlite3_randomness(0,0); | |
| 121790 | 121858 | break; |
| 121791 | 121859 | } |
| 121792 | 121860 | |
| 121793 | 121861 | /* |
| 121794 | 121862 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| @@ -124767,10 +124835,23 @@ | ||
| 124767 | 124835 | sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */ |
| 124768 | 124836 | char **pzErr /* OUT: sqlite3_malloc'd error message */ |
| 124769 | 124837 | ){ |
| 124770 | 124838 | return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr); |
| 124771 | 124839 | } |
| 124840 | + | |
| 124841 | +/* | |
| 124842 | +** Set the pIdxInfo->estimatedRows variable to nRow. Unless this | |
| 124843 | +** extension is currently being used by a version of SQLite too old to | |
| 124844 | +** support estimatedRows. In that case this function is a no-op. | |
| 124845 | +*/ | |
| 124846 | +static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){ | |
| 124847 | +#if SQLITE_VERSION_NUMBER>=3008002 | |
| 124848 | + if( sqlite3_libversion_number()>=3008002 ){ | |
| 124849 | + pIdxInfo->estimatedRows = nRow; | |
| 124850 | + } | |
| 124851 | +#endif | |
| 124852 | +} | |
| 124772 | 124853 | |
| 124773 | 124854 | /* |
| 124774 | 124855 | ** Implementation of the xBestIndex method for FTS3 tables. There |
| 124775 | 124856 | ** are three possible strategies, in order of preference: |
| 124776 | 124857 | ** |
| @@ -124795,11 +124876,24 @@ | ||
| 124795 | 124876 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 124796 | 124877 | pInfo->estimatedCost = 5000000; |
| 124797 | 124878 | for(i=0; i<pInfo->nConstraint; i++){ |
| 124798 | 124879 | int bDocid; /* True if this constraint is on docid */ |
| 124799 | 124880 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 124800 | - if( pCons->usable==0 ) continue; | |
| 124881 | + if( pCons->usable==0 ){ | |
| 124882 | + if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH ){ | |
| 124883 | + /* There exists an unusable MATCH constraint. This means that if | |
| 124884 | + ** the planner does elect to use the results of this call as part | |
| 124885 | + ** of the overall query plan the user will see an "unable to use | |
| 124886 | + ** function MATCH in the requested context" error. To discourage | |
| 124887 | + ** this, return a very high cost here. */ | |
| 124888 | + pInfo->idxNum = FTS3_FULLSCAN_SEARCH; | |
| 124889 | + pInfo->estimatedCost = 1e50; | |
| 124890 | + setEstimatedRows(pInfo, ((sqlite3_int64)1) << 50); | |
| 124891 | + return SQLITE_OK; | |
| 124892 | + } | |
| 124893 | + continue; | |
| 124894 | + } | |
| 124801 | 124895 | |
| 124802 | 124896 | bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1); |
| 124803 | 124897 | |
| 124804 | 124898 | /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */ |
| 124805 | 124899 | if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){ |
| 124806 | 124900 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -135,11 +135,11 @@ | |
| 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | */ |
| 138 | #define SQLITE_VERSION "3.8.3" |
| 139 | #define SQLITE_VERSION_NUMBER 3008003 |
| 140 | #define SQLITE_SOURCE_ID "2013-12-23 11:33:32 25b8a1c9ba77df3b7c78cbce922cb593d661696d" |
| 141 | |
| 142 | /* |
| 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | ** |
| @@ -2426,15 +2426,17 @@ | |
| 2426 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2427 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2428 | ** applications to access the same PRNG for other purposes. |
| 2429 | ** |
| 2430 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2431 | ** |
| 2432 | ** ^The first time this routine is invoked (either internally or by |
| 2433 | ** the application) the PRNG is seeded using randomness obtained |
| 2434 | ** from the xRandomness method of the default [sqlite3_vfs] object. |
| 2435 | ** ^On all subsequent invocations, the pseudo-randomness is generated |
| 2436 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2437 | ** method. |
| 2438 | */ |
| 2439 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2440 | |
| @@ -9278,10 +9280,11 @@ | |
| 9278 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 9279 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 9280 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 9281 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 9282 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 9283 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 9284 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 9285 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 9286 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| 9287 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*); |
| @@ -10371,11 +10374,11 @@ | |
| 10371 | */ |
| 10372 | #define SQLITE_QueryFlattener 0x0001 /* Query flattening */ |
| 10373 | #define SQLITE_ColumnCache 0x0002 /* Column cache */ |
| 10374 | #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ |
| 10375 | #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ |
| 10376 | #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */ |
| 10377 | #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ |
| 10378 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10379 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10380 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10381 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| @@ -11605,10 +11608,13 @@ | |
| 11605 | int nErr; /* Number of errors seen */ |
| 11606 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 11607 | int nMem; /* Number of memory cells used so far */ |
| 11608 | int nSet; /* Number of sets used so far */ |
| 11609 | int nOnce; /* Number of OP_Once instructions so far */ |
| 11610 | int ckBase; /* Base register of data during check constraints */ |
| 11611 | int iPartIdxTab; /* Table corresponding to a partial index */ |
| 11612 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 11613 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 11614 | struct yColCache { |
| @@ -12284,11 +12290,10 @@ | |
| 12284 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12285 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12286 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12287 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12288 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12289 | SQLITE_PRIVATE void sqlite3PrngResetState(void); |
| 12290 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12291 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12292 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12293 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12294 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -13776,19 +13781,13 @@ | |
| 13776 | Op *aOp; /* Space to hold the virtual machine's program */ |
| 13777 | Mem *aMem; /* The memory locations */ |
| 13778 | Mem **apArg; /* Arguments to currently executing user function */ |
| 13779 | Mem *aColName; /* Column names to return */ |
| 13780 | Mem *pResultSet; /* Pointer to an array of results */ |
| 13781 | #ifdef SQLITE_DEBUG |
| 13782 | Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 13783 | #endif |
| 13784 | int nMem; /* Number of memory locations currently allocated */ |
| 13785 | int nOp; /* Number of instructions in the program */ |
| 13786 | int nOpAlloc; /* Number of slots allocated for aOp[] */ |
| 13787 | int nLabel; /* Number of labels used */ |
| 13788 | int *aLabel; /* Space to hold the labels */ |
| 13789 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 13790 | int nCursor; /* Number of slots in apCsr[] */ |
| 13791 | u32 magic; /* Magic number for sanity checking */ |
| 13792 | char *zErrMsg; /* Error message written here */ |
| 13793 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 13794 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| @@ -13797,10 +13796,11 @@ | |
| 13797 | ynVar nVar; /* Number of entries in aVar[] */ |
| 13798 | ynVar nzVar; /* Number of entries in azVar[] */ |
| 13799 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 13800 | int pc; /* The program counter */ |
| 13801 | int rc; /* Value to return */ |
| 13802 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 13803 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 13804 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 13805 | bft inVtabMethod:2; /* See comments above */ |
| 13806 | bft changeCntOn:1; /* True to update the change-counter */ |
| @@ -20901,10 +20901,16 @@ | |
| 20901 | |
| 20902 | #if SQLITE_THREADSAFE |
| 20903 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20904 | sqlite3_mutex_enter(mutex); |
| 20905 | #endif |
| 20906 | |
| 20907 | /* Initialize the state of the random number generator once, |
| 20908 | ** the first time this routine is called. The seed value does |
| 20909 | ** not need to contain a lot of randomness since we are not |
| 20910 | ** trying to do secure encryption or anything like that... |
| @@ -20929,19 +20935,20 @@ | |
| 20929 | wsdPrng.s[i] = t; |
| 20930 | } |
| 20931 | wsdPrng.isInit = 1; |
| 20932 | } |
| 20933 | |
| 20934 | while( N-- ){ |
| 20935 | wsdPrng.i++; |
| 20936 | t = wsdPrng.s[wsdPrng.i]; |
| 20937 | wsdPrng.j += t; |
| 20938 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20939 | wsdPrng.s[wsdPrng.j] = t; |
| 20940 | t += wsdPrng.s[wsdPrng.i]; |
| 20941 | *(zBuf++) = wsdPrng.s[t]; |
| 20942 | } |
| 20943 | sqlite3_mutex_leave(mutex); |
| 20944 | } |
| 20945 | |
| 20946 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20947 | /* |
| @@ -20966,13 +20973,10 @@ | |
| 20966 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20967 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20968 | sizeof(sqlite3Prng) |
| 20969 | ); |
| 20970 | } |
| 20971 | SQLITE_PRIVATE void sqlite3PrngResetState(void){ |
| 20972 | GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0; |
| 20973 | } |
| 20974 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20975 | |
| 20976 | /************** End of random.c **********************************************/ |
| 20977 | /************** Begin file utf.c *********************************************/ |
| 20978 | /* |
| @@ -23505,10 +23509,16 @@ | |
| 23505 | ** it is larger than the struct CrashFile defined in test6.c. |
| 23506 | */ |
| 23507 | char aPadding[32]; |
| 23508 | #endif |
| 23509 | }; |
| 23510 | |
| 23511 | /* |
| 23512 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23513 | */ |
| 23514 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| @@ -29104,10 +29114,20 @@ | |
| 29104 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB |
| 29105 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 29106 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 29107 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 29108 | ); |
| 29109 | |
| 29110 | memset(p, 0, sizeof(unixFile)); |
| 29111 | |
| 29112 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 29113 | UnixUnusedFd *pUnused; |
| @@ -29492,22 +29512,22 @@ | |
| 29492 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29493 | ** that we always use the same random number sequence. This makes the |
| 29494 | ** tests repeatable. |
| 29495 | */ |
| 29496 | memset(zBuf, 0, nBuf); |
| 29497 | #if !defined(SQLITE_TEST) |
| 29498 | { |
| 29499 | int pid, fd, got; |
| 29500 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29501 | if( fd<0 ){ |
| 29502 | time_t t; |
| 29503 | time(&t); |
| 29504 | memcpy(zBuf, &t, sizeof(t)); |
| 29505 | pid = getpid(); |
| 29506 | memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); |
| 29507 | assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); |
| 29508 | nBuf = sizeof(t) + sizeof(pid); |
| 29509 | }else{ |
| 29510 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29511 | robust_close(0, fd, __LINE__); |
| 29512 | } |
| 29513 | } |
| @@ -61200,13 +61220,14 @@ | |
| 61200 | } |
| 61201 | p->pNext = db->pVdbe; |
| 61202 | p->pPrev = 0; |
| 61203 | db->pVdbe = p; |
| 61204 | p->magic = VDBE_MAGIC_INIT; |
| 61205 | #if SQLITE_DEBUG |
| 61206 | p->pParse = pParse; |
| 61207 | #endif |
| 61208 | return p; |
| 61209 | } |
| 61210 | |
| 61211 | /* |
| 61212 | ** Remember the SQL string for a prepared statement. |
| @@ -61258,17 +61279,18 @@ | |
| 61258 | ** If an out-of-memory error occurs while resizing the array, return |
| 61259 | ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain |
| 61260 | ** unchanged (this is so that any opcodes already allocated can be |
| 61261 | ** correctly deallocated along with the rest of the Vdbe). |
| 61262 | */ |
| 61263 | static int growOpArray(Vdbe *p){ |
| 61264 | VdbeOp *pNew; |
| 61265 | int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op))); |
| 61266 | pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op)); |
| 61267 | if( pNew ){ |
| 61268 | p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op); |
| 61269 | p->aOp = pNew; |
| 61270 | } |
| 61271 | return (pNew ? SQLITE_OK : SQLITE_NOMEM); |
| 61272 | } |
| 61273 | |
| 61274 | #ifdef SQLITE_DEBUG |
| @@ -61303,11 +61325,11 @@ | |
| 61303 | VdbeOp *pOp; |
| 61304 | |
| 61305 | i = p->nOp; |
| 61306 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61307 | assert( op>0 && op<0xff ); |
| 61308 | if( p->nOpAlloc<=i ){ |
| 61309 | if( growOpArray(p) ){ |
| 61310 | return 1; |
| 61311 | } |
| 61312 | } |
| 61313 | p->nOp++; |
| @@ -61414,13 +61436,14 @@ | |
| 61414 | ** always negative and P2 values are suppose to be non-negative. |
| 61415 | ** Hence, a negative P2 value is a label that has yet to be resolved. |
| 61416 | ** |
| 61417 | ** Zero is returned if a malloc() fails. |
| 61418 | */ |
| 61419 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){ |
| 61420 | int i = p->nLabel++; |
| 61421 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61422 | if( (i & (i-1))==0 ){ |
| 61423 | p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, |
| 61424 | (i*2+1)*sizeof(p->aLabel[0])); |
| 61425 | } |
| 61426 | if( p->aLabel ){ |
| @@ -61432,16 +61455,17 @@ | |
| 61432 | /* |
| 61433 | ** Resolve label "x" to be the address of the next instruction to |
| 61434 | ** be inserted. The parameter "x" must have been obtained from |
| 61435 | ** a prior call to sqlite3VdbeMakeLabel(). |
| 61436 | */ |
| 61437 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){ |
| 61438 | int j = -1-x; |
| 61439 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61440 | assert( j<p->nLabel ); |
| 61441 | if( j>=0 && p->aLabel ){ |
| 61442 | p->aLabel[j] = p->nOp; |
| 61443 | } |
| 61444 | } |
| 61445 | |
| 61446 | /* |
| 61447 | ** Mark the VDBE as one that can only be run one time. |
| @@ -61586,11 +61610,12 @@ | |
| 61586 | */ |
| 61587 | static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ |
| 61588 | int i; |
| 61589 | int nMaxArgs = *pMaxFuncArgs; |
| 61590 | Op *pOp; |
| 61591 | int *aLabel = p->aLabel; |
| 61592 | p->readOnly = 1; |
| 61593 | p->bIsReader = 0; |
| 61594 | for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ |
| 61595 | u8 opcode = pOp->opcode; |
| 61596 | |
| @@ -61649,16 +61674,17 @@ | |
| 61649 | } |
| 61650 | } |
| 61651 | |
| 61652 | pOp->opflags = sqlite3OpcodeProperty[opcode]; |
| 61653 | if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 61654 | assert( -1-pOp->p2<p->nLabel ); |
| 61655 | pOp->p2 = aLabel[-1-pOp->p2]; |
| 61656 | } |
| 61657 | } |
| 61658 | sqlite3DbFree(p->db, p->aLabel); |
| 61659 | p->aLabel = 0; |
| 61660 | *pMaxFuncArgs = nMaxArgs; |
| 61661 | assert( p->bIsReader!=0 || p->btreeMask==0 ); |
| 61662 | } |
| 61663 | |
| 61664 | /* |
| @@ -61698,11 +61724,11 @@ | |
| 61698 | ** address of the first operation added. |
| 61699 | */ |
| 61700 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ |
| 61701 | int addr; |
| 61702 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61703 | if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){ |
| 61704 | return 0; |
| 61705 | } |
| 61706 | addr = p->nOp; |
| 61707 | if( ALWAYS(nOp>0) ){ |
| 61708 | int i; |
| @@ -61886,10 +61912,17 @@ | |
| 61886 | memset(pOp, 0, sizeof(pOp[0])); |
| 61887 | pOp->opcode = OP_Noop; |
| 61888 | if( addr==p->nOp-1 ) p->nOp--; |
| 61889 | } |
| 61890 | } |
| 61891 | |
| 61892 | /* |
| 61893 | ** Change the value of the P4 operand for a specific instruction. |
| 61894 | ** This routine is useful when a large program is loaded from a |
| 61895 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| @@ -62768,10 +62801,11 @@ | |
| 62768 | |
| 62769 | assert( p!=0 ); |
| 62770 | assert( p->nOp>0 ); |
| 62771 | assert( pParse!=0 ); |
| 62772 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 62773 | db = p->db; |
| 62774 | assert( db->mallocFailed==0 ); |
| 62775 | nVar = pParse->nVar; |
| 62776 | nMem = pParse->nMem; |
| 62777 | nCursor = pParse->nTab; |
| @@ -62791,12 +62825,12 @@ | |
| 62791 | nMem += nCursor; |
| 62792 | |
| 62793 | /* Allocate space for memory registers, SQL variables, VDBE cursors and |
| 62794 | ** an array to marshal SQL function arguments in. |
| 62795 | */ |
| 62796 | zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ |
| 62797 | zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */ |
| 62798 | |
| 62799 | resolveP2Values(p, &nArg); |
| 62800 | p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort); |
| 62801 | if( pParse->explain && nMem<10 ){ |
| 62802 | nMem = 10; |
| @@ -63795,11 +63829,10 @@ | |
| 63795 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 63796 | sqlite3DbFree(db, pSub); |
| 63797 | } |
| 63798 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 63799 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 63800 | sqlite3DbFree(db, p->aLabel); |
| 63801 | sqlite3DbFree(db, p->aColName); |
| 63802 | sqlite3DbFree(db, p->zSql); |
| 63803 | sqlite3DbFree(db, p->pFree); |
| 63804 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 63805 | sqlite3DbFree(db, p->zExplain); |
| @@ -76765,20 +76798,29 @@ | |
| 76765 | } |
| 76766 | return p; |
| 76767 | } |
| 76768 | |
| 76769 | /* |
| 76770 | ** Return 1 if an expression must be FALSE in all cases and 0 if the |
| 76771 | ** expression might be true. This is an optimization. If is OK to |
| 76772 | ** return 0 here even if the expression really is always false (a |
| 76773 | ** false negative). But it is a bug to return 1 if the expression |
| 76774 | ** might be true in some rare circumstances (a false positive.) |
| 76775 | ** |
| 76776 | ** Note that if the expression is part of conditional for a |
| 76777 | ** LEFT JOIN, then we cannot determine at compile-time whether or not |
| 76778 | ** is it true or false, so always return 0. |
| 76779 | */ |
| 76780 | static int exprAlwaysFalse(Expr *p){ |
| 76781 | int v = 0; |
| 76782 | if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 76783 | if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 76784 | return v==0; |
| @@ -79621,11 +79663,11 @@ | |
| 79621 | sqlite3ExplainPush(pOut); |
| 79622 | for(i=0; i<pList->nExpr; i++){ |
| 79623 | sqlite3ExplainPrintf(pOut, "item[%d] = ", i); |
| 79624 | sqlite3ExplainPush(pOut); |
| 79625 | sqlite3ExplainExpr(pOut, pList->a[i].pExpr); |
| 79626 | sqlite3ExplainPop(pOut); |
| 79627 | if( pList->a[i].zName ){ |
| 79628 | sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName); |
| 79629 | } |
| 79630 | if( pList->a[i].bSpanIsTab ){ |
| 79631 | sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan); |
| @@ -79771,21 +79813,23 @@ | |
| 79771 | op = pExpr->op; |
| 79772 | switch( op ){ |
| 79773 | case TK_AND: { |
| 79774 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79775 | testcase( jumpIfNull==0 ); |
| 79776 | sqlite3ExprCachePush(pParse); |
| 79777 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL); |
| 79778 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79779 | sqlite3VdbeResolveLabel(v, d2); |
| 79780 | sqlite3ExprCachePop(pParse, 1); |
| 79781 | break; |
| 79782 | } |
| 79783 | case TK_OR: { |
| 79784 | testcase( jumpIfNull==0 ); |
| 79785 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79786 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79787 | break; |
| 79788 | } |
| 79789 | case TK_NOT: { |
| 79790 | testcase( jumpIfNull==0 ); |
| 79791 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| @@ -79856,14 +79900,20 @@ | |
| 79856 | sqlite3VdbeResolveLabel(v, destIfFalse); |
| 79857 | break; |
| 79858 | } |
| 79859 | #endif |
| 79860 | default: { |
| 79861 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 79862 | sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); |
| 79863 | testcase( regFree1==0 ); |
| 79864 | testcase( jumpIfNull==0 ); |
| 79865 | break; |
| 79866 | } |
| 79867 | } |
| 79868 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 79869 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -79922,18 +79972,20 @@ | |
| 79922 | |
| 79923 | switch( pExpr->op ){ |
| 79924 | case TK_AND: { |
| 79925 | testcase( jumpIfNull==0 ); |
| 79926 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79927 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79928 | break; |
| 79929 | } |
| 79930 | case TK_OR: { |
| 79931 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79932 | testcase( jumpIfNull==0 ); |
| 79933 | sqlite3ExprCachePush(pParse); |
| 79934 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL); |
| 79935 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79936 | sqlite3VdbeResolveLabel(v, d2); |
| 79937 | sqlite3ExprCachePop(pParse, 1); |
| 79938 | break; |
| 79939 | } |
| @@ -80001,14 +80053,20 @@ | |
| 80001 | } |
| 80002 | break; |
| 80003 | } |
| 80004 | #endif |
| 80005 | default: { |
| 80006 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 80007 | sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); |
| 80008 | testcase( regFree1==0 ); |
| 80009 | testcase( jumpIfNull==0 ); |
| 80010 | break; |
| 80011 | } |
| 80012 | } |
| 80013 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 80014 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -89357,22 +89415,22 @@ | |
| 89357 | nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn; |
| 89358 | regBase = sqlite3GetTempRange(pParse, nCol); |
| 89359 | for(j=0; j<nCol; j++){ |
| 89360 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j], |
| 89361 | regBase+j); |
| 89362 | } |
| 89363 | if( regOut ){ |
| 89364 | const char *zAff; |
| 89365 | if( pTab->pSelect |
| 89366 | || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt) |
| 89367 | ){ |
| 89368 | zAff = 0; |
| 89369 | }else{ |
| 89370 | zAff = sqlite3IndexAffinityStr(v, pIdx); |
| 89371 | } |
| 89372 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 89373 | sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT); |
| 89374 | } |
| 89375 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 89376 | return regBase; |
| 89377 | } |
| 89378 | |
| @@ -93721,10 +93779,11 @@ | |
| 93721 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 93722 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 93723 | int ipkTop = 0; /* Top of the rowid change constraint check */ |
| 93724 | int ipkBottom = 0; /* Bottom of the rowid change constraint check */ |
| 93725 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| 93726 | |
| 93727 | isUpdate = regOldData!=0; |
| 93728 | db = pParse->db; |
| 93729 | v = sqlite3GetVdbe(pParse); |
| 93730 | assert( v!=0 ); |
| @@ -93951,11 +94010,13 @@ | |
| 93951 | regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn); |
| 93952 | for(i=0; i<pIdx->nColumn; i++){ |
| 93953 | int iField = pIdx->aiColumn[i]; |
| 93954 | int x; |
| 93955 | if( iField<0 || iField==pTab->iPKey ){ |
| 93956 | x = regNewData; |
| 93957 | }else{ |
| 93958 | x = iField + regNewData + 1; |
| 93959 | } |
| 93960 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 93961 | VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); |
| @@ -98780,11 +98841,15 @@ | |
| 98780 | |
| 98781 | /* |
| 98782 | ** Free all memory allocations in the pParse object |
| 98783 | */ |
| 98784 | SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ |
| 98785 | if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr); |
| 98786 | } |
| 98787 | |
| 98788 | /* |
| 98789 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 98790 | */ |
| @@ -113528,13 +113593,16 @@ | |
| 113528 | sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 113529 | |
| 113530 | /* Special case: a WHERE clause that is constant. Evaluate the |
| 113531 | ** expression and either jump over all of the code or fall thru. |
| 113532 | */ |
| 113533 | if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){ |
| 113534 | sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL); |
| 113535 | pWhere = 0; |
| 113536 | } |
| 113537 | |
| 113538 | /* Special case: No FROM clause |
| 113539 | */ |
| 113540 | if( nTabList==0 ){ |
| @@ -121784,11 +121852,11 @@ | |
| 121784 | ** Reset the PRNG back to its uninitialized state. The next call |
| 121785 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 121786 | ** to the xRandomness method of the default VFS. |
| 121787 | */ |
| 121788 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 121789 | sqlite3PrngResetState(); |
| 121790 | break; |
| 121791 | } |
| 121792 | |
| 121793 | /* |
| 121794 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| @@ -124767,10 +124835,23 @@ | |
| 124767 | sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */ |
| 124768 | char **pzErr /* OUT: sqlite3_malloc'd error message */ |
| 124769 | ){ |
| 124770 | return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr); |
| 124771 | } |
| 124772 | |
| 124773 | /* |
| 124774 | ** Implementation of the xBestIndex method for FTS3 tables. There |
| 124775 | ** are three possible strategies, in order of preference: |
| 124776 | ** |
| @@ -124795,11 +124876,24 @@ | |
| 124795 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 124796 | pInfo->estimatedCost = 5000000; |
| 124797 | for(i=0; i<pInfo->nConstraint; i++){ |
| 124798 | int bDocid; /* True if this constraint is on docid */ |
| 124799 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 124800 | if( pCons->usable==0 ) continue; |
| 124801 | |
| 124802 | bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1); |
| 124803 | |
| 124804 | /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */ |
| 124805 | if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){ |
| 124806 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -135,11 +135,11 @@ | |
| 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | */ |
| 138 | #define SQLITE_VERSION "3.8.3" |
| 139 | #define SQLITE_VERSION_NUMBER 3008003 |
| 140 | #define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6" |
| 141 | |
| 142 | /* |
| 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | ** |
| @@ -2426,15 +2426,17 @@ | |
| 2426 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2427 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2428 | ** applications to access the same PRNG for other purposes. |
| 2429 | ** |
| 2430 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2431 | ** ^If N is less than one, then P can be a NULL pointer. |
| 2432 | ** |
| 2433 | ** ^If this routine has not been previously called or if the previous |
| 2434 | ** call had N less than one, then the PRNG is seeded using randomness |
| 2435 | ** obtained from the xRandomness method of the default [sqlite3_vfs] object. |
| 2436 | ** ^If the previous call to this routine had an N of 1 or more then |
| 2437 | ** the pseudo-randomness is generated |
| 2438 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2439 | ** method. |
| 2440 | */ |
| 2441 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2442 | |
| @@ -9278,10 +9280,11 @@ | |
| 9280 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 9281 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 9282 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 9283 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 9284 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 9285 | SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe*); |
| 9286 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 9287 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 9288 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 9289 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| 9290 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*); |
| @@ -10371,11 +10374,11 @@ | |
| 10374 | */ |
| 10375 | #define SQLITE_QueryFlattener 0x0001 /* Query flattening */ |
| 10376 | #define SQLITE_ColumnCache 0x0002 /* Column cache */ |
| 10377 | #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ |
| 10378 | #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ |
| 10379 | /* not used 0x0010 // Was: SQLITE_IdxRealAsInt */ |
| 10380 | #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ |
| 10381 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10382 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10383 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10384 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| @@ -11605,10 +11608,13 @@ | |
| 11608 | int nErr; /* Number of errors seen */ |
| 11609 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 11610 | int nMem; /* Number of memory cells used so far */ |
| 11611 | int nSet; /* Number of sets used so far */ |
| 11612 | int nOnce; /* Number of OP_Once instructions so far */ |
| 11613 | int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ |
| 11614 | int nLabel; /* Number of labels used */ |
| 11615 | int *aLabel; /* Space to hold the labels */ |
| 11616 | int ckBase; /* Base register of data during check constraints */ |
| 11617 | int iPartIdxTab; /* Table corresponding to a partial index */ |
| 11618 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 11619 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 11620 | struct yColCache { |
| @@ -12284,11 +12290,10 @@ | |
| 12290 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12291 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12292 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12293 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12294 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12295 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12296 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12297 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12298 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12299 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -13776,19 +13781,13 @@ | |
| 13781 | Op *aOp; /* Space to hold the virtual machine's program */ |
| 13782 | Mem *aMem; /* The memory locations */ |
| 13783 | Mem **apArg; /* Arguments to currently executing user function */ |
| 13784 | Mem *aColName; /* Column names to return */ |
| 13785 | Mem *pResultSet; /* Pointer to an array of results */ |
| 13786 | Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 13787 | int nMem; /* Number of memory locations currently allocated */ |
| 13788 | int nOp; /* Number of instructions in the program */ |
| 13789 | int nCursor; /* Number of slots in apCsr[] */ |
| 13790 | u32 magic; /* Magic number for sanity checking */ |
| 13791 | char *zErrMsg; /* Error message written here */ |
| 13792 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 13793 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| @@ -13797,10 +13796,11 @@ | |
| 13796 | ynVar nVar; /* Number of entries in aVar[] */ |
| 13797 | ynVar nzVar; /* Number of entries in azVar[] */ |
| 13798 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 13799 | int pc; /* The program counter */ |
| 13800 | int rc; /* Value to return */ |
| 13801 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 13802 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 13803 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 13804 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 13805 | bft inVtabMethod:2; /* See comments above */ |
| 13806 | bft changeCntOn:1; /* True to update the change-counter */ |
| @@ -20901,10 +20901,16 @@ | |
| 20901 | |
| 20902 | #if SQLITE_THREADSAFE |
| 20903 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20904 | sqlite3_mutex_enter(mutex); |
| 20905 | #endif |
| 20906 | |
| 20907 | if( N<=0 ){ |
| 20908 | wsdPrng.isInit = 0; |
| 20909 | sqlite3_mutex_leave(mutex); |
| 20910 | return; |
| 20911 | } |
| 20912 | |
| 20913 | /* Initialize the state of the random number generator once, |
| 20914 | ** the first time this routine is called. The seed value does |
| 20915 | ** not need to contain a lot of randomness since we are not |
| 20916 | ** trying to do secure encryption or anything like that... |
| @@ -20929,19 +20935,20 @@ | |
| 20935 | wsdPrng.s[i] = t; |
| 20936 | } |
| 20937 | wsdPrng.isInit = 1; |
| 20938 | } |
| 20939 | |
| 20940 | assert( N>0 ); |
| 20941 | do{ |
| 20942 | wsdPrng.i++; |
| 20943 | t = wsdPrng.s[wsdPrng.i]; |
| 20944 | wsdPrng.j += t; |
| 20945 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20946 | wsdPrng.s[wsdPrng.j] = t; |
| 20947 | t += wsdPrng.s[wsdPrng.i]; |
| 20948 | *(zBuf++) = wsdPrng.s[t]; |
| 20949 | }while( --N ); |
| 20950 | sqlite3_mutex_leave(mutex); |
| 20951 | } |
| 20952 | |
| 20953 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20954 | /* |
| @@ -20966,13 +20973,10 @@ | |
| 20973 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20974 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20975 | sizeof(sqlite3Prng) |
| 20976 | ); |
| 20977 | } |
| 20978 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20979 | |
| 20980 | /************** End of random.c **********************************************/ |
| 20981 | /************** Begin file utf.c *********************************************/ |
| 20982 | /* |
| @@ -23505,10 +23509,16 @@ | |
| 23509 | ** it is larger than the struct CrashFile defined in test6.c. |
| 23510 | */ |
| 23511 | char aPadding[32]; |
| 23512 | #endif |
| 23513 | }; |
| 23514 | |
| 23515 | /* This variable holds the process id (pid) from when the xRandomness() |
| 23516 | ** method was called. If xOpen() is called from a different process id, |
| 23517 | ** indicating that a fork() has occurred, the PRNG will be reset. |
| 23518 | */ |
| 23519 | static int randomnessPid = 0; |
| 23520 | |
| 23521 | /* |
| 23522 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23523 | */ |
| 23524 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| @@ -29104,10 +29114,20 @@ | |
| 29114 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB |
| 29115 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 29116 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 29117 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 29118 | ); |
| 29119 | |
| 29120 | /* Detect a pid change and reset the PRNG. There is a race condition |
| 29121 | ** here such that two or more threads all trying to open databases at |
| 29122 | ** the same instant might all reset the PRNG. But multiple resets |
| 29123 | ** are harmless. |
| 29124 | */ |
| 29125 | if( randomnessPid!=getpid() ){ |
| 29126 | randomnessPid = getpid(); |
| 29127 | sqlite3_randomness(0,0); |
| 29128 | } |
| 29129 | |
| 29130 | memset(p, 0, sizeof(unixFile)); |
| 29131 | |
| 29132 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 29133 | UnixUnusedFd *pUnused; |
| @@ -29492,22 +29512,22 @@ | |
| 29512 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29513 | ** that we always use the same random number sequence. This makes the |
| 29514 | ** tests repeatable. |
| 29515 | */ |
| 29516 | memset(zBuf, 0, nBuf); |
| 29517 | randomnessPid = getpid(); |
| 29518 | #if !defined(SQLITE_TEST) |
| 29519 | { |
| 29520 | int fd, got; |
| 29521 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29522 | if( fd<0 ){ |
| 29523 | time_t t; |
| 29524 | time(&t); |
| 29525 | memcpy(zBuf, &t, sizeof(t)); |
| 29526 | memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid)); |
| 29527 | assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf ); |
| 29528 | nBuf = sizeof(t) + sizeof(randomnessPid); |
| 29529 | }else{ |
| 29530 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29531 | robust_close(0, fd, __LINE__); |
| 29532 | } |
| 29533 | } |
| @@ -61200,13 +61220,14 @@ | |
| 61220 | } |
| 61221 | p->pNext = db->pVdbe; |
| 61222 | p->pPrev = 0; |
| 61223 | db->pVdbe = p; |
| 61224 | p->magic = VDBE_MAGIC_INIT; |
| 61225 | p->pParse = pParse; |
| 61226 | assert( pParse->aLabel==0 ); |
| 61227 | assert( pParse->nLabel==0 ); |
| 61228 | assert( pParse->nOpAlloc==0 ); |
| 61229 | return p; |
| 61230 | } |
| 61231 | |
| 61232 | /* |
| 61233 | ** Remember the SQL string for a prepared statement. |
| @@ -61258,17 +61279,18 @@ | |
| 61279 | ** If an out-of-memory error occurs while resizing the array, return |
| 61280 | ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain |
| 61281 | ** unchanged (this is so that any opcodes already allocated can be |
| 61282 | ** correctly deallocated along with the rest of the Vdbe). |
| 61283 | */ |
| 61284 | static int growOpArray(Vdbe *v){ |
| 61285 | VdbeOp *pNew; |
| 61286 | Parse *p = v->pParse; |
| 61287 | int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op))); |
| 61288 | pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); |
| 61289 | if( pNew ){ |
| 61290 | p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op); |
| 61291 | v->aOp = pNew; |
| 61292 | } |
| 61293 | return (pNew ? SQLITE_OK : SQLITE_NOMEM); |
| 61294 | } |
| 61295 | |
| 61296 | #ifdef SQLITE_DEBUG |
| @@ -61303,11 +61325,11 @@ | |
| 61325 | VdbeOp *pOp; |
| 61326 | |
| 61327 | i = p->nOp; |
| 61328 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61329 | assert( op>0 && op<0xff ); |
| 61330 | if( p->pParse->nOpAlloc<=i ){ |
| 61331 | if( growOpArray(p) ){ |
| 61332 | return 1; |
| 61333 | } |
| 61334 | } |
| 61335 | p->nOp++; |
| @@ -61414,13 +61436,14 @@ | |
| 61436 | ** always negative and P2 values are suppose to be non-negative. |
| 61437 | ** Hence, a negative P2 value is a label that has yet to be resolved. |
| 61438 | ** |
| 61439 | ** Zero is returned if a malloc() fails. |
| 61440 | */ |
| 61441 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *v){ |
| 61442 | Parse *p = v->pParse; |
| 61443 | int i = p->nLabel++; |
| 61444 | assert( v->magic==VDBE_MAGIC_INIT ); |
| 61445 | if( (i & (i-1))==0 ){ |
| 61446 | p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, |
| 61447 | (i*2+1)*sizeof(p->aLabel[0])); |
| 61448 | } |
| 61449 | if( p->aLabel ){ |
| @@ -61432,16 +61455,17 @@ | |
| 61455 | /* |
| 61456 | ** Resolve label "x" to be the address of the next instruction to |
| 61457 | ** be inserted. The parameter "x" must have been obtained from |
| 61458 | ** a prior call to sqlite3VdbeMakeLabel(). |
| 61459 | */ |
| 61460 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ |
| 61461 | Parse *p = v->pParse; |
| 61462 | int j = -1-x; |
| 61463 | assert( v->magic==VDBE_MAGIC_INIT ); |
| 61464 | assert( j<p->nLabel ); |
| 61465 | if( j>=0 && p->aLabel ){ |
| 61466 | p->aLabel[j] = v->nOp; |
| 61467 | } |
| 61468 | } |
| 61469 | |
| 61470 | /* |
| 61471 | ** Mark the VDBE as one that can only be run one time. |
| @@ -61586,11 +61610,12 @@ | |
| 61610 | */ |
| 61611 | static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ |
| 61612 | int i; |
| 61613 | int nMaxArgs = *pMaxFuncArgs; |
| 61614 | Op *pOp; |
| 61615 | Parse *pParse = p->pParse; |
| 61616 | int *aLabel = pParse->aLabel; |
| 61617 | p->readOnly = 1; |
| 61618 | p->bIsReader = 0; |
| 61619 | for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ |
| 61620 | u8 opcode = pOp->opcode; |
| 61621 | |
| @@ -61649,16 +61674,17 @@ | |
| 61674 | } |
| 61675 | } |
| 61676 | |
| 61677 | pOp->opflags = sqlite3OpcodeProperty[opcode]; |
| 61678 | if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 61679 | assert( -1-pOp->p2<pParse->nLabel ); |
| 61680 | pOp->p2 = aLabel[-1-pOp->p2]; |
| 61681 | } |
| 61682 | } |
| 61683 | sqlite3DbFree(p->db, pParse->aLabel); |
| 61684 | pParse->aLabel = 0; |
| 61685 | pParse->nLabel = 0; |
| 61686 | *pMaxFuncArgs = nMaxArgs; |
| 61687 | assert( p->bIsReader!=0 || p->btreeMask==0 ); |
| 61688 | } |
| 61689 | |
| 61690 | /* |
| @@ -61698,11 +61724,11 @@ | |
| 61724 | ** address of the first operation added. |
| 61725 | */ |
| 61726 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ |
| 61727 | int addr; |
| 61728 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61729 | if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){ |
| 61730 | return 0; |
| 61731 | } |
| 61732 | addr = p->nOp; |
| 61733 | if( ALWAYS(nOp>0) ){ |
| 61734 | int i; |
| @@ -61886,10 +61912,17 @@ | |
| 61912 | memset(pOp, 0, sizeof(pOp[0])); |
| 61913 | pOp->opcode = OP_Noop; |
| 61914 | if( addr==p->nOp-1 ) p->nOp--; |
| 61915 | } |
| 61916 | } |
| 61917 | |
| 61918 | /* |
| 61919 | ** Remove the last opcode inserted |
| 61920 | */ |
| 61921 | SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe *p){ |
| 61922 | p->nOp--; |
| 61923 | } |
| 61924 | |
| 61925 | /* |
| 61926 | ** Change the value of the P4 operand for a specific instruction. |
| 61927 | ** This routine is useful when a large program is loaded from a |
| 61928 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| @@ -62768,10 +62801,11 @@ | |
| 62801 | |
| 62802 | assert( p!=0 ); |
| 62803 | assert( p->nOp>0 ); |
| 62804 | assert( pParse!=0 ); |
| 62805 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 62806 | assert( pParse==p->pParse ); |
| 62807 | db = p->db; |
| 62808 | assert( db->mallocFailed==0 ); |
| 62809 | nVar = pParse->nVar; |
| 62810 | nMem = pParse->nMem; |
| 62811 | nCursor = pParse->nTab; |
| @@ -62791,12 +62825,12 @@ | |
| 62825 | nMem += nCursor; |
| 62826 | |
| 62827 | /* Allocate space for memory registers, SQL variables, VDBE cursors and |
| 62828 | ** an array to marshal SQL function arguments in. |
| 62829 | */ |
| 62830 | zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ |
| 62831 | zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */ |
| 62832 | |
| 62833 | resolveP2Values(p, &nArg); |
| 62834 | p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort); |
| 62835 | if( pParse->explain && nMem<10 ){ |
| 62836 | nMem = 10; |
| @@ -63795,11 +63829,10 @@ | |
| 63829 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 63830 | sqlite3DbFree(db, pSub); |
| 63831 | } |
| 63832 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 63833 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 63834 | sqlite3DbFree(db, p->aColName); |
| 63835 | sqlite3DbFree(db, p->zSql); |
| 63836 | sqlite3DbFree(db, p->pFree); |
| 63837 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 63838 | sqlite3DbFree(db, p->zExplain); |
| @@ -76765,20 +76798,29 @@ | |
| 76798 | } |
| 76799 | return p; |
| 76800 | } |
| 76801 | |
| 76802 | /* |
| 76803 | ** If the expression is always either TRUE or FALSE (respectively), |
| 76804 | ** then return 1. If one cannot determine the truth value of the |
| 76805 | ** expression at compile-time return 0. |
| 76806 | ** |
| 76807 | ** This is an optimization. If is OK to return 0 here even if |
| 76808 | ** the expression really is always false or false (a false negative). |
| 76809 | ** But it is a bug to return 1 if the expression might have different |
| 76810 | ** boolean values in different circumstances (a false positive.) |
| 76811 | ** |
| 76812 | ** Note that if the expression is part of conditional for a |
| 76813 | ** LEFT JOIN, then we cannot determine at compile-time whether or not |
| 76814 | ** is it true or false, so always return 0. |
| 76815 | */ |
| 76816 | static int exprAlwaysTrue(Expr *p){ |
| 76817 | int v = 0; |
| 76818 | if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 76819 | if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 76820 | return v!=0; |
| 76821 | } |
| 76822 | static int exprAlwaysFalse(Expr *p){ |
| 76823 | int v = 0; |
| 76824 | if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 76825 | if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 76826 | return v==0; |
| @@ -79621,11 +79663,11 @@ | |
| 79663 | sqlite3ExplainPush(pOut); |
| 79664 | for(i=0; i<pList->nExpr; i++){ |
| 79665 | sqlite3ExplainPrintf(pOut, "item[%d] = ", i); |
| 79666 | sqlite3ExplainPush(pOut); |
| 79667 | sqlite3ExplainExpr(pOut, pList->a[i].pExpr); |
| 79668 | sqlite3ExplainPop(pOut, 1); |
| 79669 | if( pList->a[i].zName ){ |
| 79670 | sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName); |
| 79671 | } |
| 79672 | if( pList->a[i].bSpanIsTab ){ |
| 79673 | sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan); |
| @@ -79771,21 +79813,23 @@ | |
| 79813 | op = pExpr->op; |
| 79814 | switch( op ){ |
| 79815 | case TK_AND: { |
| 79816 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79817 | testcase( jumpIfNull==0 ); |
| 79818 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL); |
| 79819 | sqlite3ExprCachePush(pParse); |
| 79820 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79821 | sqlite3VdbeResolveLabel(v, d2); |
| 79822 | sqlite3ExprCachePop(pParse, 1); |
| 79823 | break; |
| 79824 | } |
| 79825 | case TK_OR: { |
| 79826 | testcase( jumpIfNull==0 ); |
| 79827 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79828 | sqlite3ExprCachePush(pParse); |
| 79829 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79830 | sqlite3ExprCachePop(pParse, 1); |
| 79831 | break; |
| 79832 | } |
| 79833 | case TK_NOT: { |
| 79834 | testcase( jumpIfNull==0 ); |
| 79835 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| @@ -79856,14 +79900,20 @@ | |
| 79900 | sqlite3VdbeResolveLabel(v, destIfFalse); |
| 79901 | break; |
| 79902 | } |
| 79903 | #endif |
| 79904 | default: { |
| 79905 | if( exprAlwaysTrue(pExpr) ){ |
| 79906 | sqlite3VdbeAddOp2(v, OP_Goto, 0, dest); |
| 79907 | }else if( exprAlwaysFalse(pExpr) ){ |
| 79908 | /* No-op */ |
| 79909 | }else{ |
| 79910 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 79911 | sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); |
| 79912 | testcase( regFree1==0 ); |
| 79913 | testcase( jumpIfNull==0 ); |
| 79914 | } |
| 79915 | break; |
| 79916 | } |
| 79917 | } |
| 79918 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 79919 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -79922,18 +79972,20 @@ | |
| 79972 | |
| 79973 | switch( pExpr->op ){ |
| 79974 | case TK_AND: { |
| 79975 | testcase( jumpIfNull==0 ); |
| 79976 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79977 | sqlite3ExprCachePush(pParse); |
| 79978 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79979 | sqlite3ExprCachePop(pParse, 1); |
| 79980 | break; |
| 79981 | } |
| 79982 | case TK_OR: { |
| 79983 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79984 | testcase( jumpIfNull==0 ); |
| 79985 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL); |
| 79986 | sqlite3ExprCachePush(pParse); |
| 79987 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79988 | sqlite3VdbeResolveLabel(v, d2); |
| 79989 | sqlite3ExprCachePop(pParse, 1); |
| 79990 | break; |
| 79991 | } |
| @@ -80001,14 +80053,20 @@ | |
| 80053 | } |
| 80054 | break; |
| 80055 | } |
| 80056 | #endif |
| 80057 | default: { |
| 80058 | if( exprAlwaysFalse(pExpr) ){ |
| 80059 | sqlite3VdbeAddOp2(v, OP_Goto, 0, dest); |
| 80060 | }else if( exprAlwaysTrue(pExpr) ){ |
| 80061 | /* no-op */ |
| 80062 | }else{ |
| 80063 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 80064 | sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); |
| 80065 | testcase( regFree1==0 ); |
| 80066 | testcase( jumpIfNull==0 ); |
| 80067 | } |
| 80068 | break; |
| 80069 | } |
| 80070 | } |
| 80071 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 80072 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -89357,22 +89415,22 @@ | |
| 89415 | nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn; |
| 89416 | regBase = sqlite3GetTempRange(pParse, nCol); |
| 89417 | for(j=0; j<nCol; j++){ |
| 89418 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j], |
| 89419 | regBase+j); |
| 89420 | /* If the column affinity is REAL but the number is an integer, then it |
| 89421 | ** might be stored in the table as an integer (using a compact |
| 89422 | ** representation) then converted to REAL by an OP_RealAffinity opcode. |
| 89423 | ** But we are getting ready to store this value back into an index, where |
| 89424 | ** it should be converted by to INTEGER again. So omit the OP_RealAffinity |
| 89425 | ** opcode if it is present */ |
| 89426 | if( sqlite3VdbeGetOp(v, -1)->opcode==OP_RealAffinity ){ |
| 89427 | sqlite3VdbeDeleteLastOpcode(v); |
| 89428 | } |
| 89429 | } |
| 89430 | if( regOut ){ |
| 89431 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 89432 | } |
| 89433 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 89434 | return regBase; |
| 89435 | } |
| 89436 | |
| @@ -93721,10 +93779,11 @@ | |
| 93779 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 93780 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 93781 | int ipkTop = 0; /* Top of the rowid change constraint check */ |
| 93782 | int ipkBottom = 0; /* Bottom of the rowid change constraint check */ |
| 93783 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| 93784 | int regRowid = -1; /* Register holding ROWID value */ |
| 93785 | |
| 93786 | isUpdate = regOldData!=0; |
| 93787 | db = pParse->db; |
| 93788 | v = sqlite3GetVdbe(pParse); |
| 93789 | assert( v!=0 ); |
| @@ -93951,11 +94010,13 @@ | |
| 94010 | regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn); |
| 94011 | for(i=0; i<pIdx->nColumn; i++){ |
| 94012 | int iField = pIdx->aiColumn[i]; |
| 94013 | int x; |
| 94014 | if( iField<0 || iField==pTab->iPKey ){ |
| 94015 | if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */ |
| 94016 | x = regNewData; |
| 94017 | regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i; |
| 94018 | }else{ |
| 94019 | x = iField + regNewData + 1; |
| 94020 | } |
| 94021 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 94022 | VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); |
| @@ -98780,11 +98841,15 @@ | |
| 98841 | |
| 98842 | /* |
| 98843 | ** Free all memory allocations in the pParse object |
| 98844 | */ |
| 98845 | SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ |
| 98846 | if( pParse ){ |
| 98847 | sqlite3 *db = pParse->db; |
| 98848 | sqlite3DbFree(db, pParse->aLabel); |
| 98849 | sqlite3ExprListDelete(db, pParse->pConstExpr); |
| 98850 | } |
| 98851 | } |
| 98852 | |
| 98853 | /* |
| 98854 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 98855 | */ |
| @@ -113528,13 +113593,16 @@ | |
| 113593 | sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 113594 | |
| 113595 | /* Special case: a WHERE clause that is constant. Evaluate the |
| 113596 | ** expression and either jump over all of the code or fall thru. |
| 113597 | */ |
| 113598 | for(ii=0; ii<sWLB.pWC->nTerm; ii++){ |
| 113599 | if( nTabList==0 || sqlite3ExprIsConstantNotJoin(sWLB.pWC->a[ii].pExpr) ){ |
| 113600 | sqlite3ExprIfFalse(pParse, sWLB.pWC->a[ii].pExpr, pWInfo->iBreak, |
| 113601 | SQLITE_JUMPIFNULL); |
| 113602 | sWLB.pWC->a[ii].wtFlags |= TERM_CODED; |
| 113603 | } |
| 113604 | } |
| 113605 | |
| 113606 | /* Special case: No FROM clause |
| 113607 | */ |
| 113608 | if( nTabList==0 ){ |
| @@ -121784,11 +121852,11 @@ | |
| 121852 | ** Reset the PRNG back to its uninitialized state. The next call |
| 121853 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 121854 | ** to the xRandomness method of the default VFS. |
| 121855 | */ |
| 121856 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 121857 | sqlite3_randomness(0,0); |
| 121858 | break; |
| 121859 | } |
| 121860 | |
| 121861 | /* |
| 121862 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| @@ -124767,10 +124835,23 @@ | |
| 124835 | sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */ |
| 124836 | char **pzErr /* OUT: sqlite3_malloc'd error message */ |
| 124837 | ){ |
| 124838 | return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr); |
| 124839 | } |
| 124840 | |
| 124841 | /* |
| 124842 | ** Set the pIdxInfo->estimatedRows variable to nRow. Unless this |
| 124843 | ** extension is currently being used by a version of SQLite too old to |
| 124844 | ** support estimatedRows. In that case this function is a no-op. |
| 124845 | */ |
| 124846 | static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){ |
| 124847 | #if SQLITE_VERSION_NUMBER>=3008002 |
| 124848 | if( sqlite3_libversion_number()>=3008002 ){ |
| 124849 | pIdxInfo->estimatedRows = nRow; |
| 124850 | } |
| 124851 | #endif |
| 124852 | } |
| 124853 | |
| 124854 | /* |
| 124855 | ** Implementation of the xBestIndex method for FTS3 tables. There |
| 124856 | ** are three possible strategies, in order of preference: |
| 124857 | ** |
| @@ -124795,11 +124876,24 @@ | |
| 124876 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 124877 | pInfo->estimatedCost = 5000000; |
| 124878 | for(i=0; i<pInfo->nConstraint; i++){ |
| 124879 | int bDocid; /* True if this constraint is on docid */ |
| 124880 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 124881 | if( pCons->usable==0 ){ |
| 124882 | if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH ){ |
| 124883 | /* There exists an unusable MATCH constraint. This means that if |
| 124884 | ** the planner does elect to use the results of this call as part |
| 124885 | ** of the overall query plan the user will see an "unable to use |
| 124886 | ** function MATCH in the requested context" error. To discourage |
| 124887 | ** this, return a very high cost here. */ |
| 124888 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 124889 | pInfo->estimatedCost = 1e50; |
| 124890 | setEstimatedRows(pInfo, ((sqlite3_int64)1) << 50); |
| 124891 | return SQLITE_OK; |
| 124892 | } |
| 124893 | continue; |
| 124894 | } |
| 124895 | |
| 124896 | bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1); |
| 124897 | |
| 124898 | /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */ |
| 124899 | if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){ |
| 124900 |
+7
-5
| --- 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.8.3" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3008003 |
| 112 | -#define SQLITE_SOURCE_ID "2013-12-23 11:33:32 25b8a1c9ba77df3b7c78cbce922cb593d661696d" | |
| 112 | +#define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -2398,15 +2398,17 @@ | ||
| 2398 | 2398 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2399 | 2399 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2400 | 2400 | ** applications to access the same PRNG for other purposes. |
| 2401 | 2401 | ** |
| 2402 | 2402 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2403 | +** ^If N is less than one, then P can be a NULL pointer. | |
| 2403 | 2404 | ** |
| 2404 | -** ^The first time this routine is invoked (either internally or by | |
| 2405 | -** the application) the PRNG is seeded using randomness obtained | |
| 2406 | -** from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2407 | -** ^On all subsequent invocations, the pseudo-randomness is generated | |
| 2405 | +** ^If this routine has not been previously called or if the previous | |
| 2406 | +** call had N less than one, then the PRNG is seeded using randomness | |
| 2407 | +** obtained from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2408 | +** ^If the previous call to this routine had an N of 1 or more then | |
| 2409 | +** the pseudo-randomness is generated | |
| 2408 | 2410 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2409 | 2411 | ** method. |
| 2410 | 2412 | */ |
| 2411 | 2413 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2412 | 2414 | |
| 2413 | 2415 |
| --- 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.8.3" |
| 111 | #define SQLITE_VERSION_NUMBER 3008003 |
| 112 | #define SQLITE_SOURCE_ID "2013-12-23 11:33:32 25b8a1c9ba77df3b7c78cbce922cb593d661696d" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -2398,15 +2398,17 @@ | |
| 2398 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2399 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2400 | ** applications to access the same PRNG for other purposes. |
| 2401 | ** |
| 2402 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2403 | ** |
| 2404 | ** ^The first time this routine is invoked (either internally or by |
| 2405 | ** the application) the PRNG is seeded using randomness obtained |
| 2406 | ** from the xRandomness method of the default [sqlite3_vfs] object. |
| 2407 | ** ^On all subsequent invocations, the pseudo-randomness is generated |
| 2408 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2409 | ** method. |
| 2410 | */ |
| 2411 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2412 | |
| 2413 |
| --- 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.8.3" |
| 111 | #define SQLITE_VERSION_NUMBER 3008003 |
| 112 | #define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -2398,15 +2398,17 @@ | |
| 2398 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2399 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2400 | ** applications to access the same PRNG for other purposes. |
| 2401 | ** |
| 2402 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2403 | ** ^If N is less than one, then P can be a NULL pointer. |
| 2404 | ** |
| 2405 | ** ^If this routine has not been previously called or if the previous |
| 2406 | ** call had N less than one, then the PRNG is seeded using randomness |
| 2407 | ** obtained from the xRandomness method of the default [sqlite3_vfs] object. |
| 2408 | ** ^If the previous call to this routine had an N of 1 or more then |
| 2409 | ** the pseudo-randomness is generated |
| 2410 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2411 | ** method. |
| 2412 | */ |
| 2413 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2414 | |
| 2415 |