| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.8.2. By combining all the individual C code files into this |
| 3 | +** version 3.8.3. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -133,13 +133,13 @@ |
| 133 | 133 | ** |
| 134 | 134 | ** See also: [sqlite3_libversion()], |
| 135 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 137 | */ |
| 138 | | -#define SQLITE_VERSION "3.8.2" |
| 139 | | -#define SQLITE_VERSION_NUMBER 3008002 |
| 140 | | -#define SQLITE_SOURCE_ID "2013-12-03 10:35:00 e4164fd8f75ce1c8d63bec70db7049b68208c12c" |
| 138 | +#define SQLITE_VERSION "3.8.3" |
| 139 | +#define SQLITE_VERSION_NUMBER 3008003 |
| 140 | +#define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3" |
| 141 | 141 | |
| 142 | 142 | /* |
| 143 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 145 | ** |
| | @@ -517,10 +517,11 @@ |
| 517 | 517 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 518 | 518 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 519 | 519 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 520 | 520 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 521 | 521 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 522 | +#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 522 | 523 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 523 | 524 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 524 | 525 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 525 | 526 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 526 | 527 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| | @@ -584,11 +585,12 @@ |
| 584 | 585 | ** information is written to disk in the same order as calls |
| 585 | 586 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 586 | 587 | ** after reboot following a crash or power loss, the only bytes in a |
| 587 | 588 | ** file that were written at the application level might have changed |
| 588 | 589 | ** and that adjacent bytes, even bytes within the same sector are |
| 589 | | -** guaranteed to be unchanged. |
| 590 | +** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 591 | +** flag indicate that a file cannot be deleted when open. |
| 590 | 592 | */ |
| 591 | 593 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 592 | 594 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 593 | 595 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 594 | 596 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| | @@ -947,10 +949,16 @@ |
| 947 | 949 | ** This file control is used by some VFS activity tracing [shims]. |
| 948 | 950 | ** The argument is a zero-terminated string. Higher layers in the |
| 949 | 951 | ** SQLite stack may generate instances of this file control if |
| 950 | 952 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
| 951 | 953 | ** |
| 954 | +** <li>[[SQLITE_FCNTL_HAS_MOVED]] |
| 955 | +** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a |
| 956 | +** pointer to an integer and it writes a boolean into that integer depending |
| 957 | +** on whether or not the file has been renamed, moved, or deleted since it |
| 958 | +** was first opened. |
| 959 | +** |
| 952 | 960 | ** </ul> |
| 953 | 961 | */ |
| 954 | 962 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 955 | 963 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 956 | 964 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| | @@ -967,10 +975,11 @@ |
| 967 | 975 | #define SQLITE_FCNTL_PRAGMA 14 |
| 968 | 976 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 969 | 977 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 970 | 978 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 971 | 979 | #define SQLITE_FCNTL_TRACE 19 |
| 980 | +#define SQLITE_FCNTL_HAS_MOVED 20 |
| 972 | 981 | |
| 973 | 982 | /* |
| 974 | 983 | ** CAPI3REF: Mutex Handle |
| 975 | 984 | ** |
| 976 | 985 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| | @@ -12492,10 +12501,11 @@ |
| 12492 | 12501 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 12493 | 12502 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 12494 | 12503 | |
| 12495 | 12504 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); |
| 12496 | 12505 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 12506 | +SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*); |
| 12497 | 12507 | SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int); |
| 12498 | 12508 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 12499 | 12509 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| 12500 | 12510 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 12501 | 12511 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| | @@ -13322,10 +13332,13 @@ |
| 13322 | 13332 | "SMALL_STACK", |
| 13323 | 13333 | #endif |
| 13324 | 13334 | #ifdef SQLITE_SOUNDEX |
| 13325 | 13335 | "SOUNDEX", |
| 13326 | 13336 | #endif |
| 13337 | +#ifdef SQLITE_SYSTEM_MALLOC |
| 13338 | + "SYSTEM_MALLOC", |
| 13339 | +#endif |
| 13327 | 13340 | #ifdef SQLITE_TCL |
| 13328 | 13341 | "TCL", |
| 13329 | 13342 | #endif |
| 13330 | 13343 | #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc) |
| 13331 | 13344 | "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE), |
| | @@ -13336,10 +13349,13 @@ |
| 13336 | 13349 | #if defined(SQLITE_THREADSAFE) |
| 13337 | 13350 | "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE), |
| 13338 | 13351 | #endif |
| 13339 | 13352 | #ifdef SQLITE_USE_ALLOCA |
| 13340 | 13353 | "USE_ALLOCA", |
| 13354 | +#endif |
| 13355 | +#ifdef SQLITE_WIN32_MALLOC |
| 13356 | + "WIN32_MALLOC", |
| 13341 | 13357 | #endif |
| 13342 | 13358 | #ifdef SQLITE_ZERO_MALLOC |
| 13343 | 13359 | "ZERO_MALLOC" |
| 13344 | 13360 | #endif |
| 13345 | 13361 | }; |
| | @@ -13789,11 +13805,11 @@ |
| 13789 | 13805 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 13790 | 13806 | SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*); |
| 13791 | 13807 | #endif |
| 13792 | 13808 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 13793 | 13809 | SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int); |
| 13794 | | -SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int); |
| 13810 | +SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 13795 | 13811 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| 13796 | 13812 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); |
| 13797 | 13813 | |
| 13798 | 13814 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 13799 | 13815 | SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*); |
| | @@ -17518,11 +17534,11 @@ |
| 17518 | 17534 | ** works for chunks that are currently checked out. |
| 17519 | 17535 | */ |
| 17520 | 17536 | static int memsys5Size(void *p){ |
| 17521 | 17537 | int iSize = 0; |
| 17522 | 17538 | if( p ){ |
| 17523 | | - int i = ((u8 *)p-mem5.zPool)/mem5.szAtom; |
| 17539 | + int i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom); |
| 17524 | 17540 | assert( i>=0 && i<mem5.nBlock ); |
| 17525 | 17541 | iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE)); |
| 17526 | 17542 | } |
| 17527 | 17543 | return iSize; |
| 17528 | 17544 | } |
| | @@ -17605,11 +17621,11 @@ |
| 17605 | 17621 | int iBlock; |
| 17606 | 17622 | |
| 17607 | 17623 | /* Set iBlock to the index of the block pointed to by pOld in |
| 17608 | 17624 | ** the array of mem5.szAtom byte blocks pointed to by mem5.zPool. |
| 17609 | 17625 | */ |
| 17610 | | - iBlock = ((u8 *)pOld-mem5.zPool)/mem5.szAtom; |
| 17626 | + iBlock = (int)(((u8 *)pOld-mem5.zPool)/mem5.szAtom); |
| 17611 | 17627 | |
| 17612 | 17628 | /* Check that the pointer pOld points to a valid, non-free block. */ |
| 17613 | 17629 | assert( iBlock>=0 && iBlock<mem5.nBlock ); |
| 17614 | 17630 | assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 ); |
| 17615 | 17631 | assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 ); |
| | @@ -19374,11 +19390,11 @@ |
| 19374 | 19390 | /* |
| 19375 | 19391 | ** TRUE if p is a lookaside memory allocation from db |
| 19376 | 19392 | */ |
| 19377 | 19393 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 19378 | 19394 | static int isLookaside(sqlite3 *db, void *p){ |
| 19379 | | - return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd; |
| 19395 | + return p>=db->lookaside.pStart && p<db->lookaside.pEnd; |
| 19380 | 19396 | } |
| 19381 | 19397 | #else |
| 19382 | 19398 | #define isLookaside(A,B) 0 |
| 19383 | 19399 | #endif |
| 19384 | 19400 | |
| | @@ -19390,12 +19406,13 @@ |
| 19390 | 19406 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 19391 | 19407 | assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); |
| 19392 | 19408 | return sqlite3GlobalConfig.m.xSize(p); |
| 19393 | 19409 | } |
| 19394 | 19410 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ |
| 19395 | | - assert( db==0 || sqlite3_mutex_held(db->mutex) ); |
| 19396 | | - if( db && isLookaside(db, p) ){ |
| 19411 | + assert( db!=0 ); |
| 19412 | + assert( sqlite3_mutex_held(db->mutex) ); |
| 19413 | + if( isLookaside(db, p) ){ |
| 19397 | 19414 | return db->lookaside.sz; |
| 19398 | 19415 | }else{ |
| 19399 | 19416 | assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 19400 | 19417 | assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) ); |
| 19401 | 19418 | assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| | @@ -19873,10 +19890,18 @@ |
| 19873 | 19890 | } |
| 19874 | 19891 | if( N>0 ){ |
| 19875 | 19892 | sqlite3StrAccumAppend(pAccum, zSpaces, N); |
| 19876 | 19893 | } |
| 19877 | 19894 | } |
| 19895 | + |
| 19896 | +/* |
| 19897 | +** Set the StrAccum object to an error mode. |
| 19898 | +*/ |
| 19899 | +void setStrAccumError(StrAccum *p, u8 eError){ |
| 19900 | + p->accError = eError; |
| 19901 | + p->nAlloc = 0; |
| 19902 | +} |
| 19878 | 19903 | |
| 19879 | 19904 | /* |
| 19880 | 19905 | ** On machines with a small stack size, you can redefine the |
| 19881 | 19906 | ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. |
| 19882 | 19907 | */ |
| | @@ -20085,11 +20110,11 @@ |
| 20085 | 20110 | zOut = buf; |
| 20086 | 20111 | }else{ |
| 20087 | 20112 | nOut = precision + 10; |
| 20088 | 20113 | zOut = zExtra = sqlite3Malloc( nOut ); |
| 20089 | 20114 | if( zOut==0 ){ |
| 20090 | | - pAccum->accError = STRACCUM_NOMEM; |
| 20115 | + setStrAccumError(pAccum, STRACCUM_NOMEM); |
| 20091 | 20116 | return; |
| 20092 | 20117 | } |
| 20093 | 20118 | } |
| 20094 | 20119 | bufpt = &zOut[nOut-1]; |
| 20095 | 20120 | if( xtype==etORDINAL ){ |
| | @@ -20197,11 +20222,11 @@ |
| 20197 | 20222 | e2 = exp; |
| 20198 | 20223 | } |
| 20199 | 20224 | if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ |
| 20200 | 20225 | bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); |
| 20201 | 20226 | if( bufpt==0 ){ |
| 20202 | | - pAccum->accError = STRACCUM_NOMEM; |
| 20227 | + setStrAccumError(pAccum, STRACCUM_NOMEM); |
| 20203 | 20228 | return; |
| 20204 | 20229 | } |
| 20205 | 20230 | } |
| 20206 | 20231 | zOut = bufpt; |
| 20207 | 20232 | nsd = 16 + flag_altform2*10; |
| | @@ -20332,11 +20357,11 @@ |
| 20332 | 20357 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 20333 | 20358 | n += i + 1 + needQuote*2; |
| 20334 | 20359 | if( n>etBUFSIZE ){ |
| 20335 | 20360 | bufpt = zExtra = sqlite3Malloc( n ); |
| 20336 | 20361 | if( bufpt==0 ){ |
| 20337 | | - pAccum->accError = STRACCUM_NOMEM; |
| 20362 | + setStrAccumError(pAccum, STRACCUM_NOMEM); |
| 20338 | 20363 | return; |
| 20339 | 20364 | } |
| 20340 | 20365 | }else{ |
| 20341 | 20366 | bufpt = buf; |
| 20342 | 20367 | } |
| | @@ -20355,11 +20380,11 @@ |
| 20355 | 20380 | ** if( precision>=0 && precision<length ) length = precision; */ |
| 20356 | 20381 | break; |
| 20357 | 20382 | } |
| 20358 | 20383 | case etTOKEN: { |
| 20359 | 20384 | Token *pToken = va_arg(ap, Token*); |
| 20360 | | - if( pToken ){ |
| 20385 | + if( pToken && pToken->n ){ |
| 20361 | 20386 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
| 20362 | 20387 | } |
| 20363 | 20388 | length = width = 0; |
| 20364 | 20389 | break; |
| 20365 | 20390 | } |
| | @@ -20367,14 +20392,14 @@ |
| 20367 | 20392 | SrcList *pSrc = va_arg(ap, SrcList*); |
| 20368 | 20393 | int k = va_arg(ap, int); |
| 20369 | 20394 | struct SrcList_item *pItem = &pSrc->a[k]; |
| 20370 | 20395 | assert( k>=0 && k<pSrc->nSrc ); |
| 20371 | 20396 | if( pItem->zDatabase ){ |
| 20372 | | - sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1); |
| 20397 | + sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); |
| 20373 | 20398 | sqlite3StrAccumAppend(pAccum, ".", 1); |
| 20374 | 20399 | } |
| 20375 | | - sqlite3StrAccumAppend(pAccum, pItem->zName, -1); |
| 20400 | + sqlite3StrAccumAppendAll(pAccum, pItem->zName); |
| 20376 | 20401 | length = width = 0; |
| 20377 | 20402 | break; |
| 20378 | 20403 | } |
| 20379 | 20404 | default: { |
| 20380 | 20405 | assert( xtype==etINVALID ); |
| | @@ -20409,36 +20434,34 @@ |
| 20409 | 20434 | |
| 20410 | 20435 | /* |
| 20411 | 20436 | ** Append N bytes of text from z to the StrAccum object. |
| 20412 | 20437 | */ |
| 20413 | 20438 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 20414 | | - assert( z!=0 || N==0 ); |
| 20415 | | - if( p->accError ){ |
| 20416 | | - testcase(p->accError==STRACCUM_TOOBIG); |
| 20417 | | - testcase(p->accError==STRACCUM_NOMEM); |
| 20418 | | - return; |
| 20419 | | - } |
| 20420 | | - assert( p->zText!=0 || p->nChar==0 ); |
| 20421 | | - if( N<=0 ){ |
| 20422 | | - if( N==0 || z[0]==0 ) return; |
| 20423 | | - N = sqlite3Strlen30(z); |
| 20424 | | - } |
| 20439 | + assert( z!=0 ); |
| 20440 | + assert( p->zText!=0 || p->nChar==0 || p->accError ); |
| 20441 | + assert( N>=0 ); |
| 20442 | + assert( p->accError==0 || p->nAlloc==0 ); |
| 20425 | 20443 | if( p->nChar+N >= p->nAlloc ){ |
| 20426 | 20444 | char *zNew; |
| 20445 | + if( p->accError ){ |
| 20446 | + testcase(p->accError==STRACCUM_TOOBIG); |
| 20447 | + testcase(p->accError==STRACCUM_NOMEM); |
| 20448 | + return; |
| 20449 | + } |
| 20427 | 20450 | if( !p->useMalloc ){ |
| 20428 | | - p->accError = STRACCUM_TOOBIG; |
| 20429 | 20451 | N = p->nAlloc - p->nChar - 1; |
| 20452 | + setStrAccumError(p, STRACCUM_TOOBIG); |
| 20430 | 20453 | if( N<=0 ){ |
| 20431 | 20454 | return; |
| 20432 | 20455 | } |
| 20433 | 20456 | }else{ |
| 20434 | 20457 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 20435 | 20458 | i64 szNew = p->nChar; |
| 20436 | 20459 | szNew += N + 1; |
| 20437 | 20460 | if( szNew > p->mxAlloc ){ |
| 20438 | 20461 | sqlite3StrAccumReset(p); |
| 20439 | | - p->accError = STRACCUM_TOOBIG; |
| 20462 | + setStrAccumError(p, STRACCUM_TOOBIG); |
| 20440 | 20463 | return; |
| 20441 | 20464 | }else{ |
| 20442 | 20465 | p->nAlloc = (int)szNew; |
| 20443 | 20466 | } |
| 20444 | 20467 | if( p->useMalloc==1 ){ |
| | @@ -20448,20 +20471,28 @@ |
| 20448 | 20471 | } |
| 20449 | 20472 | if( zNew ){ |
| 20450 | 20473 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 20451 | 20474 | p->zText = zNew; |
| 20452 | 20475 | }else{ |
| 20453 | | - p->accError = STRACCUM_NOMEM; |
| 20454 | 20476 | sqlite3StrAccumReset(p); |
| 20477 | + setStrAccumError(p, STRACCUM_NOMEM); |
| 20455 | 20478 | return; |
| 20456 | 20479 | } |
| 20457 | 20480 | } |
| 20458 | 20481 | } |
| 20459 | 20482 | assert( p->zText ); |
| 20460 | 20483 | memcpy(&p->zText[p->nChar], z, N); |
| 20461 | 20484 | p->nChar += N; |
| 20462 | 20485 | } |
| 20486 | + |
| 20487 | +/* |
| 20488 | +** Append the complete text of zero-terminated string z[] to the p string. |
| 20489 | +*/ |
| 20490 | +SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){ |
| 20491 | + sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z)); |
| 20492 | +} |
| 20493 | + |
| 20463 | 20494 | |
| 20464 | 20495 | /* |
| 20465 | 20496 | ** Finish off a string by making sure it is zero-terminated. |
| 20466 | 20497 | ** Return a pointer to the resulting string. Return a NULL |
| 20467 | 20498 | ** pointer if any kind of error was encountered. |
| | @@ -20476,11 +20507,11 @@ |
| 20476 | 20507 | p->zText = sqlite3_malloc(p->nChar+1); |
| 20477 | 20508 | } |
| 20478 | 20509 | if( p->zText ){ |
| 20479 | 20510 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 20480 | 20511 | }else{ |
| 20481 | | - p->accError = STRACCUM_NOMEM; |
| 20512 | + setStrAccumError(p, STRACCUM_NOMEM); |
| 20482 | 20513 | } |
| 20483 | 20514 | } |
| 20484 | 20515 | } |
| 20485 | 20516 | return p->zText; |
| 20486 | 20517 | } |
| | @@ -22629,11 +22660,13 @@ |
| 22629 | 22660 | if( x<10 ) return 1; |
| 22630 | 22661 | n = x%10; |
| 22631 | 22662 | x /= 10; |
| 22632 | 22663 | if( n>=5 ) n -= 2; |
| 22633 | 22664 | else if( n>=1 ) n -= 1; |
| 22634 | | - if( x>=3 ) return (n+8)<<(x-3); |
| 22665 | + if( x>=3 ){ |
| 22666 | + return x>60 ? (u64)LARGEST_INT64 : (n+8)<<(x-3); |
| 22667 | + } |
| 22635 | 22668 | return (n+8)>>(3-x); |
| 22636 | 22669 | } |
| 22637 | 22670 | |
| 22638 | 22671 | /************** End of util.c ************************************************/ |
| 22639 | 22672 | /************** Begin file hash.c ********************************************/ |
| | @@ -24611,10 +24644,19 @@ |
| 24611 | 24644 | } |
| 24612 | 24645 | *ppInode = pInode; |
| 24613 | 24646 | return SQLITE_OK; |
| 24614 | 24647 | } |
| 24615 | 24648 | |
| 24649 | +/* |
| 24650 | +** Return TRUE if pFile has been renamed or unlinked since it was first opened. |
| 24651 | +*/ |
| 24652 | +static int fileHasMoved(unixFile *pFile){ |
| 24653 | + struct stat buf; |
| 24654 | + return pFile->pInode!=0 && |
| 24655 | + (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); |
| 24656 | +} |
| 24657 | + |
| 24616 | 24658 | |
| 24617 | 24659 | /* |
| 24618 | 24660 | ** Check a unixFile that is a database. Verify the following: |
| 24619 | 24661 | ** |
| 24620 | 24662 | ** (1) There is exactly one hard link on the file |
| | @@ -24645,14 +24687,11 @@ |
| 24645 | 24687 | if( buf.st_nlink>1 ){ |
| 24646 | 24688 | sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); |
| 24647 | 24689 | pFile->ctrlFlags |= UNIXFILE_WARNED; |
| 24648 | 24690 | return; |
| 24649 | 24691 | } |
| 24650 | | - if( pFile->pInode!=0 |
| 24651 | | - && ((rc = osStat(pFile->zPath, &buf))!=0 |
| 24652 | | - || buf.st_ino!=pFile->pInode->fileId.ino) |
| 24653 | | - ){ |
| 24692 | + if( fileHasMoved(pFile) ){ |
| 24654 | 24693 | sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); |
| 24655 | 24694 | pFile->ctrlFlags |= UNIXFILE_WARNED; |
| 24656 | 24695 | return; |
| 24657 | 24696 | } |
| 24658 | 24697 | } |
| | @@ -27096,10 +27135,14 @@ |
| 27096 | 27135 | if( zTFile ){ |
| 27097 | 27136 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 27098 | 27137 | *(char**)pArg = zTFile; |
| 27099 | 27138 | } |
| 27100 | 27139 | return SQLITE_OK; |
| 27140 | + } |
| 27141 | + case SQLITE_FCNTL_HAS_MOVED: { |
| 27142 | + *(int*)pArg = fileHasMoved(pFile); |
| 27143 | + return SQLITE_OK; |
| 27101 | 27144 | } |
| 27102 | 27145 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 27103 | 27146 | case SQLITE_FCNTL_MMAP_SIZE: { |
| 27104 | 27147 | i64 newLimit = *(i64*)pArg; |
| 27105 | 27148 | int rc = SQLITE_OK; |
| | @@ -27377,11 +27420,11 @@ |
| 27377 | 27420 | |
| 27378 | 27421 | /* Update the global lock state and do debug tracing */ |
| 27379 | 27422 | #ifdef SQLITE_DEBUG |
| 27380 | 27423 | { u16 mask; |
| 27381 | 27424 | OSTRACE(("SHM-LOCK ")); |
| 27382 | | - mask = (1<<(ofst+n)) - (1<<ofst); |
| 27425 | + mask = ofst>31 ? 0xffffffff : (1<<(ofst+n)) - (1<<ofst); |
| 27383 | 27426 | if( rc==SQLITE_OK ){ |
| 27384 | 27427 | if( lockType==F_UNLCK ){ |
| 27385 | 27428 | OSTRACE(("unlock %d ok", ofst)); |
| 27386 | 27429 | pShmNode->exclMask &= ~mask; |
| 27387 | 27430 | pShmNode->sharedMask &= ~mask; |
| | @@ -34073,11 +34116,11 @@ |
| 34073 | 34116 | winModeBit(pFile, WINFILE_PSOW, (int*)pArg); |
| 34074 | 34117 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 34075 | 34118 | return SQLITE_OK; |
| 34076 | 34119 | } |
| 34077 | 34120 | case SQLITE_FCNTL_VFSNAME: { |
| 34078 | | - *(char**)pArg = sqlite3_mprintf("win32"); |
| 34121 | + *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 34079 | 34122 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 34080 | 34123 | return SQLITE_OK; |
| 34081 | 34124 | } |
| 34082 | 34125 | case SQLITE_FCNTL_WIN32_AV_RETRY: { |
| 34083 | 34126 | int *a = (int*)pArg; |
| | @@ -43889,10 +43932,34 @@ |
| 43889 | 43932 | *ppPager = pPager; |
| 43890 | 43933 | return SQLITE_OK; |
| 43891 | 43934 | } |
| 43892 | 43935 | |
| 43893 | 43936 | |
| 43937 | +/* Verify that the database file has not be deleted or renamed out from |
| 43938 | +** under the pager. Return SQLITE_OK if the database is still were it ought |
| 43939 | +** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error |
| 43940 | +** code from sqlite3OsAccess()) if the database has gone missing. |
| 43941 | +*/ |
| 43942 | +static int databaseIsUnmoved(Pager *pPager){ |
| 43943 | + int bHasMoved = 0; |
| 43944 | + int rc; |
| 43945 | + |
| 43946 | + if( pPager->tempFile ) return SQLITE_OK; |
| 43947 | + if( pPager->dbSize==0 ) return SQLITE_OK; |
| 43948 | + assert( pPager->zFilename && pPager->zFilename[0] ); |
| 43949 | + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved); |
| 43950 | + if( rc==SQLITE_NOTFOUND ){ |
| 43951 | + /* If the HAS_MOVED file-control is unimplemented, assume that the file |
| 43952 | + ** has not been moved. That is the historical behavior of SQLite: prior to |
| 43953 | + ** version 3.8.3, it never checked */ |
| 43954 | + rc = SQLITE_OK; |
| 43955 | + }else if( rc==SQLITE_OK && bHasMoved ){ |
| 43956 | + rc = SQLITE_READONLY_DBMOVED; |
| 43957 | + } |
| 43958 | + return rc; |
| 43959 | +} |
| 43960 | + |
| 43894 | 43961 | |
| 43895 | 43962 | /* |
| 43896 | 43963 | ** This function is called after transitioning from PAGER_UNLOCK to |
| 43897 | 43964 | ** PAGER_SHARED state. It tests if there is a hot journal present in |
| 43898 | 43965 | ** the file-system for the given pager. A hot journal is one that |
| | @@ -44360,11 +44427,11 @@ |
| 44360 | 44427 | if( bMmapOk && pagerUseWal(pPager) ){ |
| 44361 | 44428 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame); |
| 44362 | 44429 | if( rc!=SQLITE_OK ) goto pager_acquire_err; |
| 44363 | 44430 | } |
| 44364 | 44431 | |
| 44365 | | - if( iFrame==0 && bMmapOk ){ |
| 44432 | + if( bMmapOk && iFrame==0 ){ |
| 44366 | 44433 | void *pData = 0; |
| 44367 | 44434 | |
| 44368 | 44435 | rc = sqlite3OsFetch(pPager->fd, |
| 44369 | 44436 | (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData |
| 44370 | 44437 | ); |
| | @@ -44565,17 +44632,23 @@ |
| 44565 | 44632 | SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| |
| 44566 | 44633 | (pPager->tempFile ? |
| 44567 | 44634 | (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL): |
| 44568 | 44635 | (SQLITE_OPEN_MAIN_JOURNAL) |
| 44569 | 44636 | ); |
| 44570 | | - #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 44571 | | - rc = sqlite3JournalOpen( |
| 44572 | | - pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager) |
| 44573 | | - ); |
| 44574 | | - #else |
| 44575 | | - rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0); |
| 44576 | | - #endif |
| 44637 | + |
| 44638 | + /* Verify that the database still has the same name as it did when |
| 44639 | + ** it was originally opened. */ |
| 44640 | + rc = databaseIsUnmoved(pPager); |
| 44641 | + if( rc==SQLITE_OK ){ |
| 44642 | +#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 44643 | + rc = sqlite3JournalOpen( |
| 44644 | + pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager) |
| 44645 | + ); |
| 44646 | +#else |
| 44647 | + rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0); |
| 44648 | +#endif |
| 44649 | + } |
| 44577 | 44650 | } |
| 44578 | 44651 | assert( rc!=SQLITE_OK || isOpen(pPager->jfd) ); |
| 44579 | 44652 | } |
| 44580 | 44653 | |
| 44581 | 44654 | |
| | @@ -44705,18 +44778,12 @@ |
| 44705 | 44778 | assert( pPager->eState==PAGER_WRITER_LOCKED |
| 44706 | 44779 | || pPager->eState==PAGER_WRITER_CACHEMOD |
| 44707 | 44780 | || pPager->eState==PAGER_WRITER_DBMOD |
| 44708 | 44781 | ); |
| 44709 | 44782 | assert( assert_pager_state(pPager) ); |
| 44710 | | - |
| 44711 | | - /* If an error has been previously detected, report the same error |
| 44712 | | - ** again. This should not happen, but the check provides robustness. */ |
| 44713 | | - if( NEVER(pPager->errCode) ) return pPager->errCode; |
| 44714 | | - |
| 44715 | | - /* Higher-level routines never call this function if database is not |
| 44716 | | - ** writable. But check anyway, just for robustness. */ |
| 44717 | | - if( NEVER(pPager->readOnly) ) return SQLITE_PERM; |
| 44783 | + assert( pPager->errCode==0 ); |
| 44784 | + assert( pPager->readOnly==0 ); |
| 44718 | 44785 | |
| 44719 | 44786 | CHECK_PAGE(pPg); |
| 44720 | 44787 | |
| 44721 | 44788 | /* The journal file needs to be opened. Higher level routines have already |
| 44722 | 44789 | ** obtained the necessary locks to begin the write-transaction, but the |
| | @@ -44841,23 +44908,23 @@ |
| 44841 | 44908 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){ |
| 44842 | 44909 | int rc = SQLITE_OK; |
| 44843 | 44910 | |
| 44844 | 44911 | PgHdr *pPg = pDbPage; |
| 44845 | 44912 | Pager *pPager = pPg->pPager; |
| 44846 | | - Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); |
| 44847 | 44913 | |
| 44848 | 44914 | assert( (pPg->flags & PGHDR_MMAP)==0 ); |
| 44849 | 44915 | assert( pPager->eState>=PAGER_WRITER_LOCKED ); |
| 44850 | 44916 | assert( pPager->eState!=PAGER_ERROR ); |
| 44851 | 44917 | assert( assert_pager_state(pPager) ); |
| 44852 | 44918 | |
| 44853 | | - if( nPagePerSector>1 ){ |
| 44919 | + if( pPager->sectorSize > (u32)pPager->pageSize ){ |
| 44854 | 44920 | Pgno nPageCount; /* Total number of pages in database file */ |
| 44855 | 44921 | Pgno pg1; /* First page of the sector pPg is located on. */ |
| 44856 | 44922 | int nPage = 0; /* Number of pages starting at pg1 to journal */ |
| 44857 | 44923 | int ii; /* Loop counter */ |
| 44858 | 44924 | int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */ |
| 44925 | + Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); |
| 44859 | 44926 | |
| 44860 | 44927 | /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow |
| 44861 | 44928 | ** a journal header to be written between the pages journaled by |
| 44862 | 44929 | ** this function. |
| 44863 | 44930 | */ |
| | @@ -51991,11 +52058,11 @@ |
| 51991 | 52058 | |
| 51992 | 52059 | if( pgno>btreePagecount(pBt) ){ |
| 51993 | 52060 | rc = SQLITE_CORRUPT_BKPT; |
| 51994 | 52061 | }else{ |
| 51995 | 52062 | rc = btreeGetPage(pBt, pgno, ppPage, bReadonly); |
| 51996 | | - if( rc==SQLITE_OK ){ |
| 52063 | + if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){ |
| 51997 | 52064 | rc = btreeInitPage(*ppPage); |
| 51998 | 52065 | if( rc!=SQLITE_OK ){ |
| 51999 | 52066 | releasePage(*ppPage); |
| 52000 | 52067 | } |
| 52001 | 52068 | } |
| | @@ -54531,14 +54598,14 @@ |
| 54531 | 54598 | } |
| 54532 | 54599 | |
| 54533 | 54600 | /* |
| 54534 | 54601 | ** Return a pointer to payload information from the entry that the |
| 54535 | 54602 | ** pCur cursor is pointing to. The pointer is to the beginning of |
| 54536 | | -** the key if skipKey==0 and it points to the beginning of data if |
| 54537 | | -** skipKey==1. The number of bytes of available key/data is written |
| 54538 | | -** into *pAmt. If *pAmt==0, then the value returned will not be |
| 54539 | | -** a valid pointer. |
| 54603 | +** the key if index btrees (pPage->intKey==0) and is the data for |
| 54604 | +** table btrees (pPage->intKey==1). The number of bytes of available |
| 54605 | +** key/data is written into *pAmt. If *pAmt==0, then the value |
| 54606 | +** returned will not be a valid pointer. |
| 54540 | 54607 | ** |
| 54541 | 54608 | ** This routine is an optimization. It is common for the entire key |
| 54542 | 54609 | ** and data to fit on the local page and for there to be no overflow |
| 54543 | 54610 | ** pages. When that is so, this routine can be used to access the |
| 54544 | 54611 | ** key and data without making a copy. If the key and/or data spills |
| | @@ -54547,45 +54614,25 @@ |
| 54547 | 54614 | ** |
| 54548 | 54615 | ** The pointer returned by this routine looks directly into the cached |
| 54549 | 54616 | ** page of the database. The data might change or move the next time |
| 54550 | 54617 | ** any btree routine is called. |
| 54551 | 54618 | */ |
| 54552 | | -static const unsigned char *fetchPayload( |
| 54619 | +static const void *fetchPayload( |
| 54553 | 54620 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 54554 | | - u32 *pAmt, /* Write the number of available bytes here */ |
| 54555 | | - int skipKey /* read beginning at data if this is true */ |
| 54621 | + u32 *pAmt /* Write the number of available bytes here */ |
| 54556 | 54622 | ){ |
| 54557 | | - unsigned char *aPayload; |
| 54558 | | - MemPage *pPage; |
| 54559 | | - u32 nKey; |
| 54560 | | - u32 nLocal; |
| 54561 | | - |
| 54562 | 54623 | assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 54563 | 54624 | assert( pCur->eState==CURSOR_VALID ); |
| 54625 | + assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 54564 | 54626 | assert( cursorHoldsMutex(pCur) ); |
| 54565 | | - pPage = pCur->apPage[pCur->iPage]; |
| 54566 | | - assert( pCur->aiIdx[pCur->iPage]<pPage->nCell ); |
| 54627 | + assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 54567 | 54628 | if( pCur->info.nSize==0 ){ |
| 54568 | 54629 | btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage], |
| 54569 | 54630 | &pCur->info); |
| 54570 | 54631 | } |
| 54571 | | - aPayload = pCur->info.pCell; |
| 54572 | | - aPayload += pCur->info.nHeader; |
| 54573 | | - if( pPage->intKey ){ |
| 54574 | | - nKey = 0; |
| 54575 | | - }else{ |
| 54576 | | - nKey = (int)pCur->info.nKey; |
| 54577 | | - } |
| 54578 | | - if( skipKey ){ |
| 54579 | | - aPayload += nKey; |
| 54580 | | - nLocal = pCur->info.nLocal - nKey; |
| 54581 | | - }else{ |
| 54582 | | - nLocal = pCur->info.nLocal; |
| 54583 | | - assert( nLocal<=nKey ); |
| 54584 | | - } |
| 54585 | | - *pAmt = nLocal; |
| 54586 | | - return aPayload; |
| 54632 | + *pAmt = pCur->info.nLocal; |
| 54633 | + return (void*)(pCur->info.pCell + pCur->info.nHeader); |
| 54587 | 54634 | } |
| 54588 | 54635 | |
| 54589 | 54636 | |
| 54590 | 54637 | /* |
| 54591 | 54638 | ** For the entry that cursor pCur is point to, return as |
| | @@ -54600,26 +54647,14 @@ |
| 54600 | 54647 | ** |
| 54601 | 54648 | ** These routines is used to get quick access to key and data |
| 54602 | 54649 | ** in the common case where no overflow pages are used. |
| 54603 | 54650 | */ |
| 54604 | 54651 | SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){ |
| 54605 | | - const void *p = 0; |
| 54606 | | - assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 54607 | | - assert( cursorHoldsMutex(pCur) ); |
| 54608 | | - if( ALWAYS(pCur->eState==CURSOR_VALID) ){ |
| 54609 | | - p = (const void*)fetchPayload(pCur, pAmt, 0); |
| 54610 | | - } |
| 54611 | | - return p; |
| 54652 | + return fetchPayload(pCur, pAmt); |
| 54612 | 54653 | } |
| 54613 | 54654 | SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){ |
| 54614 | | - const void *p = 0; |
| 54615 | | - assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 54616 | | - assert( cursorHoldsMutex(pCur) ); |
| 54617 | | - if( ALWAYS(pCur->eState==CURSOR_VALID) ){ |
| 54618 | | - p = (const void*)fetchPayload(pCur, pAmt, 1); |
| 54619 | | - } |
| 54620 | | - return p; |
| 54655 | + return fetchPayload(pCur, pAmt); |
| 54621 | 54656 | } |
| 54622 | 54657 | |
| 54623 | 54658 | |
| 54624 | 54659 | /* |
| 54625 | 54660 | ** Move the cursor down to a new child page. The newPgno argument is the |
| | @@ -54734,12 +54769,10 @@ |
| 54734 | 54769 | ** b-tree). |
| 54735 | 54770 | */ |
| 54736 | 54771 | static int moveToRoot(BtCursor *pCur){ |
| 54737 | 54772 | MemPage *pRoot; |
| 54738 | 54773 | int rc = SQLITE_OK; |
| 54739 | | - Btree *p = pCur->pBtree; |
| 54740 | | - BtShared *pBt = p->pBt; |
| 54741 | 54774 | |
| 54742 | 54775 | assert( cursorHoldsMutex(pCur) ); |
| 54743 | 54776 | assert( CURSOR_INVALID < CURSOR_REQUIRESEEK ); |
| 54744 | 54777 | assert( CURSOR_VALID < CURSOR_REQUIRESEEK ); |
| 54745 | 54778 | assert( CURSOR_FAULT > CURSOR_REQUIRESEEK ); |
| | @@ -54750,20 +54783,16 @@ |
| 54750 | 54783 | } |
| 54751 | 54784 | sqlite3BtreeClearCursor(pCur); |
| 54752 | 54785 | } |
| 54753 | 54786 | |
| 54754 | 54787 | if( pCur->iPage>=0 ){ |
| 54755 | | - int i; |
| 54756 | | - for(i=1; i<=pCur->iPage; i++){ |
| 54757 | | - releasePage(pCur->apPage[i]); |
| 54758 | | - } |
| 54759 | | - pCur->iPage = 0; |
| 54788 | + while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]); |
| 54760 | 54789 | }else if( pCur->pgnoRoot==0 ){ |
| 54761 | 54790 | pCur->eState = CURSOR_INVALID; |
| 54762 | 54791 | return SQLITE_OK; |
| 54763 | 54792 | }else{ |
| 54764 | | - rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0], |
| 54793 | + rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0], |
| 54765 | 54794 | pCur->wrFlag==0 ? PAGER_GET_READONLY : 0); |
| 54766 | 54795 | if( rc!=SQLITE_OK ){ |
| 54767 | 54796 | pCur->eState = CURSOR_INVALID; |
| 54768 | 54797 | return rc; |
| 54769 | 54798 | } |
| | @@ -54792,18 +54821,20 @@ |
| 54792 | 54821 | pCur->aiIdx[0] = 0; |
| 54793 | 54822 | pCur->info.nSize = 0; |
| 54794 | 54823 | pCur->atLast = 0; |
| 54795 | 54824 | pCur->validNKey = 0; |
| 54796 | 54825 | |
| 54797 | | - if( pRoot->nCell==0 && !pRoot->leaf ){ |
| 54826 | + if( pRoot->nCell>0 ){ |
| 54827 | + pCur->eState = CURSOR_VALID; |
| 54828 | + }else if( !pRoot->leaf ){ |
| 54798 | 54829 | Pgno subpage; |
| 54799 | 54830 | if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT; |
| 54800 | 54831 | subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]); |
| 54801 | 54832 | pCur->eState = CURSOR_VALID; |
| 54802 | 54833 | rc = moveToChild(pCur, subpage); |
| 54803 | 54834 | }else{ |
| 54804 | | - pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID); |
| 54835 | + pCur->eState = CURSOR_INVALID; |
| 54805 | 54836 | } |
| 54806 | 54837 | return rc; |
| 54807 | 54838 | } |
| 54808 | 54839 | |
| 54809 | 54840 | /* |
| | @@ -55055,21 +55086,18 @@ |
| 55055 | 55086 | ** the entire cell by checking for the cases where the record is |
| 55056 | 55087 | ** stored entirely within the b-tree page by inspecting the first |
| 55057 | 55088 | ** 2 bytes of the cell. |
| 55058 | 55089 | */ |
| 55059 | 55090 | nCell = pCell[0]; |
| 55060 | | - if( nCell<=pPage->max1bytePayload |
| 55061 | | - /* && (pCell+nCell)<pPage->aDataEnd */ |
| 55062 | | - ){ |
| 55091 | + if( nCell<=pPage->max1bytePayload ){ |
| 55063 | 55092 | /* This branch runs if the record-size field of the cell is a |
| 55064 | 55093 | ** single byte varint and the record fits entirely on the main |
| 55065 | 55094 | ** b-tree page. */ |
| 55066 | 55095 | testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 55067 | 55096 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 55068 | 55097 | }else if( !(pCell[1] & 0x80) |
| 55069 | 55098 | && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 55070 | | - /* && (pCell+nCell+2)<=pPage->aDataEnd */ |
| 55071 | 55099 | ){ |
| 55072 | 55100 | /* The record-size field is a 2 byte varint and the record |
| 55073 | 55101 | ** fits entirely on the main b-tree page. */ |
| 55074 | 55102 | testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 55075 | 55103 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| | @@ -55889,11 +55917,11 @@ |
| 55889 | 55917 | nHeader = 0; |
| 55890 | 55918 | if( !pPage->leaf ){ |
| 55891 | 55919 | nHeader += 4; |
| 55892 | 55920 | } |
| 55893 | 55921 | if( pPage->hasData ){ |
| 55894 | | - nHeader += putVarint(&pCell[nHeader], nData+nZero); |
| 55922 | + nHeader += putVarint32(&pCell[nHeader], nData+nZero); |
| 55895 | 55923 | }else{ |
| 55896 | 55924 | nData = nZero = 0; |
| 55897 | 55925 | } |
| 55898 | 55926 | nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey); |
| 55899 | 55927 | btreeParseCellPtr(pPage, pCell, &info); |
| | @@ -56017,11 +56045,10 @@ |
| 56017 | 56045 | */ |
| 56018 | 56046 | static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){ |
| 56019 | 56047 | u32 pc; /* Offset to cell content of cell being deleted */ |
| 56020 | 56048 | u8 *data; /* pPage->aData */ |
| 56021 | 56049 | u8 *ptr; /* Used to move bytes around within data[] */ |
| 56022 | | - u8 *endPtr; /* End of loop */ |
| 56023 | 56050 | int rc; /* The return code */ |
| 56024 | 56051 | int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */ |
| 56025 | 56052 | |
| 56026 | 56053 | if( *pRC ) return; |
| 56027 | 56054 | |
| | @@ -56042,17 +56069,12 @@ |
| 56042 | 56069 | rc = freeSpace(pPage, pc, sz); |
| 56043 | 56070 | if( rc ){ |
| 56044 | 56071 | *pRC = rc; |
| 56045 | 56072 | return; |
| 56046 | 56073 | } |
| 56047 | | - endPtr = &pPage->aCellIdx[2*pPage->nCell - 2]; |
| 56048 | | - assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */ |
| 56049 | | - while( ptr<endPtr ){ |
| 56050 | | - *(u16*)ptr = *(u16*)&ptr[2]; |
| 56051 | | - ptr += 2; |
| 56052 | | - } |
| 56053 | 56074 | pPage->nCell--; |
| 56075 | + memmove(ptr, ptr+2, 2*(pPage->nCell - idx)); |
| 56054 | 56076 | put2byte(&data[hdr+3], pPage->nCell); |
| 56055 | 56077 | pPage->nFree += 2; |
| 56056 | 56078 | } |
| 56057 | 56079 | |
| 56058 | 56080 | /* |
| | @@ -56085,13 +56107,10 @@ |
| 56085 | 56107 | int j; /* Loop counter */ |
| 56086 | 56108 | int end; /* First byte past the last cell pointer in data[] */ |
| 56087 | 56109 | int ins; /* Index in data[] where new cell pointer is inserted */ |
| 56088 | 56110 | int cellOffset; /* Address of first cell pointer in data[] */ |
| 56089 | 56111 | u8 *data; /* The content of the whole page */ |
| 56090 | | - u8 *ptr; /* Used for moving information around in data[] */ |
| 56091 | | - u8 *endPtr; /* End of the loop */ |
| 56092 | | - |
| 56093 | 56112 | int nSkip = (iChild ? 4 : 0); |
| 56094 | 56113 | |
| 56095 | 56114 | if( *pRC ) return; |
| 56096 | 56115 | |
| 56097 | 56116 | assert( i>=0 && i<=pPage->nCell+pPage->nOverflow ); |
| | @@ -56138,17 +56157,11 @@ |
| 56138 | 56157 | pPage->nFree -= (u16)(2 + sz); |
| 56139 | 56158 | memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip); |
| 56140 | 56159 | if( iChild ){ |
| 56141 | 56160 | put4byte(&data[idx], iChild); |
| 56142 | 56161 | } |
| 56143 | | - ptr = &data[end]; |
| 56144 | | - endPtr = &data[ins]; |
| 56145 | | - assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */ |
| 56146 | | - while( ptr>endPtr ){ |
| 56147 | | - *(u16*)ptr = *(u16*)&ptr[-2]; |
| 56148 | | - ptr -= 2; |
| 56149 | | - } |
| 56162 | + memmove(&data[ins+2], &data[ins], end-ins); |
| 56150 | 56163 | put2byte(&data[ins], idx); |
| 56151 | 56164 | put2byte(&data[pPage->hdrOffset+3], pPage->nCell); |
| 56152 | 56165 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 56153 | 56166 | if( pPage->pBt->autoVacuum ){ |
| 56154 | 56167 | /* The cell may contain a pointer to an overflow page. If so, write |
| | @@ -58106,11 +58119,11 @@ |
| 58106 | 58119 | va_start(ap, zFormat); |
| 58107 | 58120 | if( pCheck->errMsg.nChar ){ |
| 58108 | 58121 | sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1); |
| 58109 | 58122 | } |
| 58110 | 58123 | if( zMsg1 ){ |
| 58111 | | - sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1); |
| 58124 | + sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1); |
| 58112 | 58125 | } |
| 58113 | 58126 | sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); |
| 58114 | 58127 | va_end(ap); |
| 58115 | 58128 | if( pCheck->errMsg.accError==STRACCUM_NOMEM ){ |
| 58116 | 58129 | pCheck->mallocFailed = 1; |
| | @@ -59682,61 +59695,59 @@ |
| 59682 | 59695 | #endif |
| 59683 | 59696 | } |
| 59684 | 59697 | |
| 59685 | 59698 | /* |
| 59686 | 59699 | ** Make sure pMem->z points to a writable allocation of at least |
| 59687 | | -** n bytes. |
| 59688 | | -** |
| 59689 | | -** If the third argument passed to this function is true, then memory |
| 59690 | | -** cell pMem must contain a string or blob. In this case the content is |
| 59691 | | -** preserved. Otherwise, if the third parameter to this function is false, |
| 59692 | | -** any current string or blob value may be discarded. |
| 59693 | | -** |
| 59694 | | -** This function sets the MEM_Dyn flag and clears any xDel callback. |
| 59695 | | -** It also clears MEM_Ephem and MEM_Static. If the preserve flag is |
| 59696 | | -** not set, Mem.n is zeroed. |
| 59697 | | -*/ |
| 59698 | | -SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ |
| 59700 | +** min(n,32) bytes. |
| 59701 | +** |
| 59702 | +** If the bPreserve argument is true, then copy of the content of |
| 59703 | +** pMem->z into the new allocation. pMem must be either a string or |
| 59704 | +** blob if bPreserve is true. If bPreserve is false, any prior content |
| 59705 | +** in pMem->z is discarded. |
| 59706 | +*/ |
| 59707 | +SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){ |
| 59699 | 59708 | assert( 1 >= |
| 59700 | 59709 | ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + |
| 59701 | 59710 | (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + |
| 59702 | 59711 | ((pMem->flags&MEM_Ephem) ? 1 : 0) + |
| 59703 | 59712 | ((pMem->flags&MEM_Static) ? 1 : 0) |
| 59704 | 59713 | ); |
| 59705 | 59714 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 59706 | 59715 | |
| 59707 | | - /* If the preserve flag is set to true, then the memory cell must already |
| 59716 | + /* If the bPreserve flag is set to true, then the memory cell must already |
| 59708 | 59717 | ** contain a valid string or blob value. */ |
| 59709 | | - assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); |
| 59718 | + assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); |
| 59719 | + testcase( bPreserve && pMem->z==0 ); |
| 59710 | 59720 | |
| 59711 | | - if( n<32 ) n = 32; |
| 59712 | | - if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ |
| 59713 | | - if( preserve && pMem->z==pMem->zMalloc ){ |
| 59721 | + if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ |
| 59722 | + if( n<32 ) n = 32; |
| 59723 | + if( bPreserve && pMem->z==pMem->zMalloc ){ |
| 59714 | 59724 | pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); |
| 59715 | | - preserve = 0; |
| 59725 | + bPreserve = 0; |
| 59716 | 59726 | }else{ |
| 59717 | 59727 | sqlite3DbFree(pMem->db, pMem->zMalloc); |
| 59718 | 59728 | pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); |
| 59719 | 59729 | } |
| 59730 | + if( pMem->zMalloc==0 ){ |
| 59731 | + sqlite3VdbeMemRelease(pMem); |
| 59732 | + pMem->flags = MEM_Null; |
| 59733 | + return SQLITE_NOMEM; |
| 59734 | + } |
| 59720 | 59735 | } |
| 59721 | 59736 | |
| 59722 | | - if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){ |
| 59737 | + if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){ |
| 59723 | 59738 | memcpy(pMem->zMalloc, pMem->z, pMem->n); |
| 59724 | 59739 | } |
| 59725 | | - if( pMem->flags&MEM_Dyn && pMem->xDel ){ |
| 59740 | + if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){ |
| 59726 | 59741 | assert( pMem->xDel!=SQLITE_DYNAMIC ); |
| 59727 | 59742 | pMem->xDel((void *)(pMem->z)); |
| 59728 | 59743 | } |
| 59729 | 59744 | |
| 59730 | 59745 | pMem->z = pMem->zMalloc; |
| 59731 | | - if( pMem->z==0 ){ |
| 59732 | | - pMem->flags = MEM_Null; |
| 59733 | | - }else{ |
| 59734 | | - pMem->flags &= ~(MEM_Ephem|MEM_Static); |
| 59735 | | - } |
| 59746 | + pMem->flags &= ~(MEM_Ephem|MEM_Static); |
| 59736 | 59747 | pMem->xDel = 0; |
| 59737 | | - return (pMem->z ? SQLITE_OK : SQLITE_NOMEM); |
| 59748 | + return SQLITE_OK; |
| 59738 | 59749 | } |
| 59739 | 59750 | |
| 59740 | 59751 | /* |
| 59741 | 59752 | ** Make the given Mem object MEM_Dyn. In other words, make it so |
| 59742 | 59753 | ** that any TEXT or BLOB content is stored in memory obtained from |
| | @@ -59918,14 +59929,16 @@ |
| 59918 | 59929 | ** inconsistent state, for example with (Mem.z==0) and |
| 59919 | 59930 | ** (Mem.type==SQLITE_TEXT). |
| 59920 | 59931 | */ |
| 59921 | 59932 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){ |
| 59922 | 59933 | VdbeMemRelease(p); |
| 59923 | | - sqlite3DbFree(p->db, p->zMalloc); |
| 59934 | + if( p->zMalloc ){ |
| 59935 | + sqlite3DbFree(p->db, p->zMalloc); |
| 59936 | + p->zMalloc = 0; |
| 59937 | + } |
| 59924 | 59938 | p->z = 0; |
| 59925 | | - p->zMalloc = 0; |
| 59926 | | - p->xDel = 0; |
| 59939 | + assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */ |
| 59927 | 59940 | } |
| 59928 | 59941 | |
| 59929 | 59942 | /* |
| 59930 | 59943 | ** Convert a 64-bit IEEE double into a 64-bit signed integer. |
| 59931 | 59944 | ** If the double is out of range of a 64-bit signed integer then |
| | @@ -60639,19 +60652,19 @@ |
| 60639 | 60652 | Index *pIdx = p->pIdx; /* Index being probed */ |
| 60640 | 60653 | int nByte; /* Bytes of space to allocate */ |
| 60641 | 60654 | int i; /* Counter variable */ |
| 60642 | 60655 | int nCol = pIdx->nColumn; /* Number of index columns including rowid */ |
| 60643 | 60656 | |
| 60644 | | - nByte = sizeof(Mem) * nCol + sizeof(UnpackedRecord); |
| 60657 | + nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord)); |
| 60645 | 60658 | pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte); |
| 60646 | 60659 | if( pRec ){ |
| 60647 | 60660 | pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx); |
| 60648 | 60661 | if( pRec->pKeyInfo ){ |
| 60649 | 60662 | assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol ); |
| 60650 | 60663 | assert( pRec->pKeyInfo->enc==ENC(db) ); |
| 60651 | 60664 | pRec->flags = UNPACKED_PREFIX_MATCH; |
| 60652 | | - pRec->aMem = (Mem *)&pRec[1]; |
| 60665 | + pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord))); |
| 60653 | 60666 | for(i=0; i<nCol; i++){ |
| 60654 | 60667 | pRec->aMem[i].flags = MEM_Null; |
| 60655 | 60668 | pRec->aMem[i].type = SQLITE_NULL; |
| 60656 | 60669 | pRec->aMem[i].db = db; |
| 60657 | 60670 | } |
| | @@ -60842,11 +60855,11 @@ |
| 60842 | 60855 | if( aRet==0 ){ |
| 60843 | 60856 | sqlite3_result_error_nomem(context); |
| 60844 | 60857 | }else{ |
| 60845 | 60858 | aRet[0] = nSerial+1; |
| 60846 | 60859 | sqlite3PutVarint(&aRet[1], iSerial); |
| 60847 | | - sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format); |
| 60860 | + sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial); |
| 60848 | 60861 | sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT); |
| 60849 | 60862 | sqlite3DbFree(db, aRet); |
| 60850 | 60863 | } |
| 60851 | 60864 | } |
| 60852 | 60865 | |
| | @@ -60920,11 +60933,10 @@ |
| 60920 | 60933 | |
| 60921 | 60934 | if( !pExpr ){ |
| 60922 | 60935 | pVal = valueNew(db, &alloc); |
| 60923 | 60936 | if( pVal ){ |
| 60924 | 60937 | sqlite3VdbeMemSetNull((Mem*)pVal); |
| 60925 | | - *pbOk = 1; |
| 60926 | 60938 | } |
| 60927 | 60939 | }else if( pExpr->op==TK_VARIABLE |
| 60928 | 60940 | || NEVER(pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE) |
| 60929 | 60941 | ){ |
| 60930 | 60942 | Vdbe *v; |
| | @@ -60936,20 +60948,17 @@ |
| 60936 | 60948 | rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]); |
| 60937 | 60949 | if( rc==SQLITE_OK ){ |
| 60938 | 60950 | sqlite3ValueApplyAffinity(pVal, affinity, ENC(db)); |
| 60939 | 60951 | } |
| 60940 | 60952 | pVal->db = pParse->db; |
| 60941 | | - *pbOk = 1; |
| 60942 | 60953 | sqlite3VdbeMemStoreType((Mem*)pVal); |
| 60943 | 60954 | } |
| 60944 | | - }else{ |
| 60945 | | - *pbOk = 0; |
| 60946 | 60955 | } |
| 60947 | 60956 | }else{ |
| 60948 | 60957 | rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc); |
| 60949 | | - *pbOk = (pVal!=0); |
| 60950 | 60958 | } |
| 60959 | + *pbOk = (pVal!=0); |
| 60951 | 60960 | |
| 60952 | 60961 | assert( pVal==0 || pVal->db==db ); |
| 60953 | 60962 | return rc; |
| 60954 | 60963 | } |
| 60955 | 60964 | |
| | @@ -63838,25 +63847,19 @@ |
| 63838 | 63847 | /* |
| 63839 | 63848 | ** Write the serialized data blob for the value stored in pMem into |
| 63840 | 63849 | ** buf. It is assumed that the caller has allocated sufficient space. |
| 63841 | 63850 | ** Return the number of bytes written. |
| 63842 | 63851 | ** |
| 63843 | | -** nBuf is the amount of space left in buf[]. nBuf must always be |
| 63844 | | -** large enough to hold the entire field. Except, if the field is |
| 63845 | | -** a blob with a zero-filled tail, then buf[] might be just the right |
| 63846 | | -** size to hold everything except for the zero-filled tail. If buf[] |
| 63847 | | -** is only big enough to hold the non-zero prefix, then only write that |
| 63848 | | -** prefix into buf[]. But if buf[] is large enough to hold both the |
| 63849 | | -** prefix and the tail then write the prefix and set the tail to all |
| 63850 | | -** zeros. |
| 63852 | +** nBuf is the amount of space left in buf[]. The caller is responsible |
| 63853 | +** for allocating enough space to buf[] to hold the entire field, exclusive |
| 63854 | +** of the pMem->u.nZero bytes for a MEM_Zero value. |
| 63851 | 63855 | ** |
| 63852 | 63856 | ** Return the number of bytes actually written into buf[]. The number |
| 63853 | 63857 | ** of bytes in the zero-filled tail is included in the return value only |
| 63854 | 63858 | ** if those bytes were zeroed in buf[]. |
| 63855 | 63859 | */ |
| 63856 | | -SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){ |
| 63857 | | - u32 serial_type = sqlite3VdbeSerialType(pMem, file_format); |
| 63860 | +SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){ |
| 63858 | 63861 | u32 len; |
| 63859 | 63862 | |
| 63860 | 63863 | /* Integer and Real */ |
| 63861 | 63864 | if( serial_type<=7 && serial_type>0 ){ |
| 63862 | 63865 | u64 v; |
| | @@ -63867,11 +63870,10 @@ |
| 63867 | 63870 | swapMixedEndianFloat(v); |
| 63868 | 63871 | }else{ |
| 63869 | 63872 | v = pMem->u.i; |
| 63870 | 63873 | } |
| 63871 | 63874 | len = i = sqlite3VdbeSerialTypeLen(serial_type); |
| 63872 | | - assert( len<=(u32)nBuf ); |
| 63873 | 63875 | while( i-- ){ |
| 63874 | 63876 | buf[i] = (u8)(v&0xFF); |
| 63875 | 63877 | v >>= 8; |
| 63876 | 63878 | } |
| 63877 | 63879 | return len; |
| | @@ -63879,21 +63881,12 @@ |
| 63879 | 63881 | |
| 63880 | 63882 | /* String or blob */ |
| 63881 | 63883 | if( serial_type>=12 ){ |
| 63882 | 63884 | assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0) |
| 63883 | 63885 | == (int)sqlite3VdbeSerialTypeLen(serial_type) ); |
| 63884 | | - assert( pMem->n<=nBuf ); |
| 63885 | 63886 | len = pMem->n; |
| 63886 | 63887 | memcpy(buf, pMem->z, len); |
| 63887 | | - if( pMem->flags & MEM_Zero ){ |
| 63888 | | - len += pMem->u.nZero; |
| 63889 | | - assert( nBuf>=0 ); |
| 63890 | | - if( len > (u32)nBuf ){ |
| 63891 | | - len = (u32)nBuf; |
| 63892 | | - } |
| 63893 | | - memset(&buf[pMem->n], 0, len-pMem->n); |
| 63894 | | - } |
| 63895 | 63888 | return len; |
| 63896 | 63889 | } |
| 63897 | 63890 | |
| 63898 | 63891 | /* NULL or constants 0 or 1 */ |
| 63899 | 63892 | return 0; |
| | @@ -65815,10 +65808,11 @@ |
| 65815 | 65808 | if( db->nVdbeExec>1 ){ |
| 65816 | 65809 | while( *zRawSql ){ |
| 65817 | 65810 | const char *zStart = zRawSql; |
| 65818 | 65811 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 65819 | 65812 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 65813 | + assert( (zRawSql - zStart) > 0 ); |
| 65820 | 65814 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| 65821 | 65815 | } |
| 65822 | 65816 | }else{ |
| 65823 | 65817 | while( zRawSql[0] ){ |
| 65824 | 65818 | n = findNextHostParameter(zRawSql, &nToken); |
| | @@ -66658,433 +66652,11 @@ |
| 66658 | 66652 | i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ |
| 66659 | 66653 | #ifdef VDBE_PROFILE |
| 66660 | 66654 | u64 start; /* CPU clock count at start of opcode */ |
| 66661 | 66655 | int origPc; /* Program counter at start of opcode */ |
| 66662 | 66656 | #endif |
| 66663 | | - /******************************************************************** |
| 66664 | | - ** Automatically generated code |
| 66665 | | - ** |
| 66666 | | - ** The following union is automatically generated by the |
| 66667 | | - ** vdbe-compress.tcl script. The purpose of this union is to |
| 66668 | | - ** reduce the amount of stack space required by this function. |
| 66669 | | - ** See comments in the vdbe-compress.tcl script for details. |
| 66670 | | - */ |
| 66671 | | - union vdbeExecUnion { |
| 66672 | | - struct OP_Yield_stack_vars { |
| 66673 | | - int pcDest; |
| 66674 | | - } aa; |
| 66675 | | - struct OP_Halt_stack_vars { |
| 66676 | | - const char *zType; |
| 66677 | | - const char *zLogFmt; |
| 66678 | | - } ab; |
| 66679 | | - struct OP_Null_stack_vars { |
| 66680 | | - int cnt; |
| 66681 | | - u16 nullFlag; |
| 66682 | | - } ac; |
| 66683 | | - struct OP_Variable_stack_vars { |
| 66684 | | - Mem *pVar; /* Value being transferred */ |
| 66685 | | - } ad; |
| 66686 | | - struct OP_Move_stack_vars { |
| 66687 | | - char *zMalloc; /* Holding variable for allocated memory */ |
| 66688 | | - int n; /* Number of registers left to copy */ |
| 66689 | | - int p1; /* Register to copy from */ |
| 66690 | | - int p2; /* Register to copy to */ |
| 66691 | | - } ae; |
| 66692 | | - struct OP_Copy_stack_vars { |
| 66693 | | - int n; |
| 66694 | | - } af; |
| 66695 | | - struct OP_ResultRow_stack_vars { |
| 66696 | | - Mem *pMem; |
| 66697 | | - int i; |
| 66698 | | - } ag; |
| 66699 | | - struct OP_Concat_stack_vars { |
| 66700 | | - i64 nByte; |
| 66701 | | - } ah; |
| 66702 | | - struct OP_Remainder_stack_vars { |
| 66703 | | - char bIntint; /* Started out as two integer operands */ |
| 66704 | | - int flags; /* Combined MEM_* flags from both inputs */ |
| 66705 | | - i64 iA; /* Integer value of left operand */ |
| 66706 | | - i64 iB; /* Integer value of right operand */ |
| 66707 | | - double rA; /* Real value of left operand */ |
| 66708 | | - double rB; /* Real value of right operand */ |
| 66709 | | - } ai; |
| 66710 | | - struct OP_Function_stack_vars { |
| 66711 | | - int i; |
| 66712 | | - Mem *pArg; |
| 66713 | | - sqlite3_context ctx; |
| 66714 | | - sqlite3_value **apVal; |
| 66715 | | - int n; |
| 66716 | | - } aj; |
| 66717 | | - struct OP_ShiftRight_stack_vars { |
| 66718 | | - i64 iA; |
| 66719 | | - u64 uA; |
| 66720 | | - i64 iB; |
| 66721 | | - u8 op; |
| 66722 | | - } ak; |
| 66723 | | - struct OP_Ge_stack_vars { |
| 66724 | | - int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 66725 | | - char affinity; /* Affinity to use for comparison */ |
| 66726 | | - u16 flags1; /* Copy of initial value of pIn1->flags */ |
| 66727 | | - u16 flags3; /* Copy of initial value of pIn3->flags */ |
| 66728 | | - } al; |
| 66729 | | - struct OP_Compare_stack_vars { |
| 66730 | | - int n; |
| 66731 | | - int i; |
| 66732 | | - int p1; |
| 66733 | | - int p2; |
| 66734 | | - const KeyInfo *pKeyInfo; |
| 66735 | | - int idx; |
| 66736 | | - CollSeq *pColl; /* Collating sequence to use on this term */ |
| 66737 | | - int bRev; /* True for DESCENDING sort order */ |
| 66738 | | - } am; |
| 66739 | | - struct OP_Or_stack_vars { |
| 66740 | | - int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 66741 | | - int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 66742 | | - } an; |
| 66743 | | - struct OP_IfNot_stack_vars { |
| 66744 | | - int c; |
| 66745 | | - } ao; |
| 66746 | | - struct OP_Column_stack_vars { |
| 66747 | | - i64 payloadSize64; /* Number of bytes in the record */ |
| 66748 | | - int p2; /* column number to retrieve */ |
| 66749 | | - VdbeCursor *pC; /* The VDBE cursor */ |
| 66750 | | - BtCursor *pCrsr; /* The BTree cursor */ |
| 66751 | | - u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| 66752 | | - u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 66753 | | - int len; /* The length of the serialized data for the column */ |
| 66754 | | - int i; /* Loop counter */ |
| 66755 | | - Mem *pDest; /* Where to write the extracted value */ |
| 66756 | | - Mem sMem; /* For storing the record being decoded */ |
| 66757 | | - const u8 *zData; /* Part of the record being decoded */ |
| 66758 | | - const u8 *zHdr; /* Next unparsed byte of the header */ |
| 66759 | | - const u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 66760 | | - u32 offset; /* Offset into the data */ |
| 66761 | | - u32 szField; /* Number of bytes in the content of a field */ |
| 66762 | | - u32 avail; /* Number of bytes of available data */ |
| 66763 | | - u32 t; /* A type code from the record header */ |
| 66764 | | - Mem *pReg; /* PseudoTable input register */ |
| 66765 | | - } ap; |
| 66766 | | - struct OP_Affinity_stack_vars { |
| 66767 | | - const char *zAffinity; /* The affinity to be applied */ |
| 66768 | | - char cAff; /* A single character of affinity */ |
| 66769 | | - } aq; |
| 66770 | | - struct OP_MakeRecord_stack_vars { |
| 66771 | | - u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 66772 | | - Mem *pRec; /* The new record */ |
| 66773 | | - u64 nData; /* Number of bytes of data space */ |
| 66774 | | - int nHdr; /* Number of bytes of header space */ |
| 66775 | | - i64 nByte; /* Data space required for this record */ |
| 66776 | | - int nZero; /* Number of zero bytes at the end of the record */ |
| 66777 | | - int nVarint; /* Number of bytes in a varint */ |
| 66778 | | - u32 serial_type; /* Type field */ |
| 66779 | | - Mem *pData0; /* First field to be combined into the record */ |
| 66780 | | - Mem *pLast; /* Last field of the record */ |
| 66781 | | - int nField; /* Number of fields in the record */ |
| 66782 | | - char *zAffinity; /* The affinity string for the record */ |
| 66783 | | - int file_format; /* File format to use for encoding */ |
| 66784 | | - int i; /* Space used in zNewRecord[] */ |
| 66785 | | - int len; /* Length of a field */ |
| 66786 | | - } ar; |
| 66787 | | - struct OP_Count_stack_vars { |
| 66788 | | - i64 nEntry; |
| 66789 | | - BtCursor *pCrsr; |
| 66790 | | - } as; |
| 66791 | | - struct OP_Savepoint_stack_vars { |
| 66792 | | - int p1; /* Value of P1 operand */ |
| 66793 | | - char *zName; /* Name of savepoint */ |
| 66794 | | - int nName; |
| 66795 | | - Savepoint *pNew; |
| 66796 | | - Savepoint *pSavepoint; |
| 66797 | | - Savepoint *pTmp; |
| 66798 | | - int iSavepoint; |
| 66799 | | - int ii; |
| 66800 | | - } at; |
| 66801 | | - struct OP_AutoCommit_stack_vars { |
| 66802 | | - int desiredAutoCommit; |
| 66803 | | - int iRollback; |
| 66804 | | - int turnOnAC; |
| 66805 | | - } au; |
| 66806 | | - struct OP_Transaction_stack_vars { |
| 66807 | | - Btree *pBt; |
| 66808 | | - } av; |
| 66809 | | - struct OP_ReadCookie_stack_vars { |
| 66810 | | - int iMeta; |
| 66811 | | - int iDb; |
| 66812 | | - int iCookie; |
| 66813 | | - } aw; |
| 66814 | | - struct OP_SetCookie_stack_vars { |
| 66815 | | - Db *pDb; |
| 66816 | | - } ax; |
| 66817 | | - struct OP_VerifyCookie_stack_vars { |
| 66818 | | - int iMeta; |
| 66819 | | - int iGen; |
| 66820 | | - Btree *pBt; |
| 66821 | | - } ay; |
| 66822 | | - struct OP_OpenWrite_stack_vars { |
| 66823 | | - int nField; |
| 66824 | | - KeyInfo *pKeyInfo; |
| 66825 | | - int p2; |
| 66826 | | - int iDb; |
| 66827 | | - int wrFlag; |
| 66828 | | - Btree *pX; |
| 66829 | | - VdbeCursor *pCur; |
| 66830 | | - Db *pDb; |
| 66831 | | - } az; |
| 66832 | | - struct OP_OpenEphemeral_stack_vars { |
| 66833 | | - VdbeCursor *pCx; |
| 66834 | | - KeyInfo *pKeyInfo; |
| 66835 | | - } ba; |
| 66836 | | - struct OP_SorterOpen_stack_vars { |
| 66837 | | - VdbeCursor *pCx; |
| 66838 | | - } bb; |
| 66839 | | - struct OP_OpenPseudo_stack_vars { |
| 66840 | | - VdbeCursor *pCx; |
| 66841 | | - } bc; |
| 66842 | | - struct OP_SeekGt_stack_vars { |
| 66843 | | - int res; |
| 66844 | | - int oc; |
| 66845 | | - VdbeCursor *pC; |
| 66846 | | - UnpackedRecord r; |
| 66847 | | - int nField; |
| 66848 | | - i64 iKey; /* The rowid we are to seek to */ |
| 66849 | | - } bd; |
| 66850 | | - struct OP_Seek_stack_vars { |
| 66851 | | - VdbeCursor *pC; |
| 66852 | | - } be; |
| 66853 | | - struct OP_Found_stack_vars { |
| 66854 | | - int alreadyExists; |
| 66855 | | - int ii; |
| 66856 | | - VdbeCursor *pC; |
| 66857 | | - int res; |
| 66858 | | - char *pFree; |
| 66859 | | - UnpackedRecord *pIdxKey; |
| 66860 | | - UnpackedRecord r; |
| 66861 | | - char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; |
| 66862 | | - } bf; |
| 66863 | | - struct OP_NotExists_stack_vars { |
| 66864 | | - VdbeCursor *pC; |
| 66865 | | - BtCursor *pCrsr; |
| 66866 | | - int res; |
| 66867 | | - u64 iKey; |
| 66868 | | - } bg; |
| 66869 | | - struct OP_NewRowid_stack_vars { |
| 66870 | | - i64 v; /* The new rowid */ |
| 66871 | | - VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 66872 | | - int res; /* Result of an sqlite3BtreeLast() */ |
| 66873 | | - int cnt; /* Counter to limit the number of searches */ |
| 66874 | | - Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 66875 | | - VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 66876 | | - } bh; |
| 66877 | | - struct OP_InsertInt_stack_vars { |
| 66878 | | - Mem *pData; /* MEM cell holding data for the record to be inserted */ |
| 66879 | | - Mem *pKey; /* MEM cell holding key for the record */ |
| 66880 | | - i64 iKey; /* The integer ROWID or key for the record to be inserted */ |
| 66881 | | - VdbeCursor *pC; /* Cursor to table into which insert is written */ |
| 66882 | | - int nZero; /* Number of zero-bytes to append */ |
| 66883 | | - int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ |
| 66884 | | - const char *zDb; /* database name - used by the update hook */ |
| 66885 | | - const char *zTbl; /* Table name - used by the opdate hook */ |
| 66886 | | - int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ |
| 66887 | | - } bi; |
| 66888 | | - struct OP_Delete_stack_vars { |
| 66889 | | - i64 iKey; |
| 66890 | | - VdbeCursor *pC; |
| 66891 | | - } bj; |
| 66892 | | - struct OP_SorterCompare_stack_vars { |
| 66893 | | - VdbeCursor *pC; |
| 66894 | | - int res; |
| 66895 | | - int nIgnore; |
| 66896 | | - } bk; |
| 66897 | | - struct OP_SorterData_stack_vars { |
| 66898 | | - VdbeCursor *pC; |
| 66899 | | - } bl; |
| 66900 | | - struct OP_RowData_stack_vars { |
| 66901 | | - VdbeCursor *pC; |
| 66902 | | - BtCursor *pCrsr; |
| 66903 | | - u32 n; |
| 66904 | | - i64 n64; |
| 66905 | | - } bm; |
| 66906 | | - struct OP_Rowid_stack_vars { |
| 66907 | | - VdbeCursor *pC; |
| 66908 | | - i64 v; |
| 66909 | | - sqlite3_vtab *pVtab; |
| 66910 | | - const sqlite3_module *pModule; |
| 66911 | | - } bn; |
| 66912 | | - struct OP_NullRow_stack_vars { |
| 66913 | | - VdbeCursor *pC; |
| 66914 | | - } bo; |
| 66915 | | - struct OP_Last_stack_vars { |
| 66916 | | - VdbeCursor *pC; |
| 66917 | | - BtCursor *pCrsr; |
| 66918 | | - int res; |
| 66919 | | - } bp; |
| 66920 | | - struct OP_Rewind_stack_vars { |
| 66921 | | - VdbeCursor *pC; |
| 66922 | | - BtCursor *pCrsr; |
| 66923 | | - int res; |
| 66924 | | - } bq; |
| 66925 | | - struct OP_SorterNext_stack_vars { |
| 66926 | | - VdbeCursor *pC; |
| 66927 | | - int res; |
| 66928 | | - } br; |
| 66929 | | - struct OP_IdxInsert_stack_vars { |
| 66930 | | - VdbeCursor *pC; |
| 66931 | | - BtCursor *pCrsr; |
| 66932 | | - int nKey; |
| 66933 | | - const char *zKey; |
| 66934 | | - } bs; |
| 66935 | | - struct OP_IdxDelete_stack_vars { |
| 66936 | | - VdbeCursor *pC; |
| 66937 | | - BtCursor *pCrsr; |
| 66938 | | - int res; |
| 66939 | | - UnpackedRecord r; |
| 66940 | | - } bt; |
| 66941 | | - struct OP_IdxRowid_stack_vars { |
| 66942 | | - BtCursor *pCrsr; |
| 66943 | | - VdbeCursor *pC; |
| 66944 | | - i64 rowid; |
| 66945 | | - } bu; |
| 66946 | | - struct OP_IdxGE_stack_vars { |
| 66947 | | - VdbeCursor *pC; |
| 66948 | | - int res; |
| 66949 | | - UnpackedRecord r; |
| 66950 | | - } bv; |
| 66951 | | - struct OP_Destroy_stack_vars { |
| 66952 | | - int iMoved; |
| 66953 | | - int iCnt; |
| 66954 | | - Vdbe *pVdbe; |
| 66955 | | - int iDb; |
| 66956 | | - } bw; |
| 66957 | | - struct OP_Clear_stack_vars { |
| 66958 | | - int nChange; |
| 66959 | | - } bx; |
| 66960 | | - struct OP_CreateTable_stack_vars { |
| 66961 | | - int pgno; |
| 66962 | | - int flags; |
| 66963 | | - Db *pDb; |
| 66964 | | - } by; |
| 66965 | | - struct OP_ParseSchema_stack_vars { |
| 66966 | | - int iDb; |
| 66967 | | - const char *zMaster; |
| 66968 | | - char *zSql; |
| 66969 | | - InitData initData; |
| 66970 | | - } bz; |
| 66971 | | - struct OP_IntegrityCk_stack_vars { |
| 66972 | | - int nRoot; /* Number of tables to check. (Number of root pages.) */ |
| 66973 | | - int *aRoot; /* Array of rootpage numbers for tables to be checked */ |
| 66974 | | - int j; /* Loop counter */ |
| 66975 | | - int nErr; /* Number of errors reported */ |
| 66976 | | - char *z; /* Text of the error report */ |
| 66977 | | - Mem *pnErr; /* Register keeping track of errors remaining */ |
| 66978 | | - } ca; |
| 66979 | | - struct OP_RowSetRead_stack_vars { |
| 66980 | | - i64 val; |
| 66981 | | - } cb; |
| 66982 | | - struct OP_RowSetTest_stack_vars { |
| 66983 | | - int iSet; |
| 66984 | | - int exists; |
| 66985 | | - } cc; |
| 66986 | | - struct OP_Program_stack_vars { |
| 66987 | | - int nMem; /* Number of memory registers for sub-program */ |
| 66988 | | - int nByte; /* Bytes of runtime space required for sub-program */ |
| 66989 | | - Mem *pRt; /* Register to allocate runtime space */ |
| 66990 | | - Mem *pMem; /* Used to iterate through memory cells */ |
| 66991 | | - Mem *pEnd; /* Last memory cell in new array */ |
| 66992 | | - VdbeFrame *pFrame; /* New vdbe frame to execute in */ |
| 66993 | | - SubProgram *pProgram; /* Sub-program to execute */ |
| 66994 | | - void *t; /* Token identifying trigger */ |
| 66995 | | - } cd; |
| 66996 | | - struct OP_Param_stack_vars { |
| 66997 | | - VdbeFrame *pFrame; |
| 66998 | | - Mem *pIn; |
| 66999 | | - } ce; |
| 67000 | | - struct OP_MemMax_stack_vars { |
| 67001 | | - Mem *pIn1; |
| 67002 | | - VdbeFrame *pFrame; |
| 67003 | | - } cf; |
| 67004 | | - struct OP_AggStep_stack_vars { |
| 67005 | | - int n; |
| 67006 | | - int i; |
| 67007 | | - Mem *pMem; |
| 67008 | | - Mem *pRec; |
| 67009 | | - sqlite3_context ctx; |
| 67010 | | - sqlite3_value **apVal; |
| 67011 | | - } cg; |
| 67012 | | - struct OP_AggFinal_stack_vars { |
| 67013 | | - Mem *pMem; |
| 67014 | | - } ch; |
| 67015 | | - struct OP_Checkpoint_stack_vars { |
| 67016 | | - int i; /* Loop counter */ |
| 67017 | | - int aRes[3]; /* Results */ |
| 67018 | | - Mem *pMem; /* Write results here */ |
| 67019 | | - } ci; |
| 67020 | | - struct OP_JournalMode_stack_vars { |
| 67021 | | - Btree *pBt; /* Btree to change journal mode of */ |
| 67022 | | - Pager *pPager; /* Pager associated with pBt */ |
| 67023 | | - int eNew; /* New journal mode */ |
| 67024 | | - int eOld; /* The old journal mode */ |
| 67025 | | -#ifndef SQLITE_OMIT_WAL |
| 67026 | | - const char *zFilename; /* Name of database file for pPager */ |
| 67027 | | -#endif |
| 67028 | | - } cj; |
| 67029 | | - struct OP_IncrVacuum_stack_vars { |
| 67030 | | - Btree *pBt; |
| 67031 | | - } ck; |
| 67032 | | - struct OP_VBegin_stack_vars { |
| 67033 | | - VTable *pVTab; |
| 67034 | | - } cl; |
| 67035 | | - struct OP_VOpen_stack_vars { |
| 67036 | | - VdbeCursor *pCur; |
| 67037 | | - sqlite3_vtab_cursor *pVtabCursor; |
| 67038 | | - sqlite3_vtab *pVtab; |
| 67039 | | - sqlite3_module *pModule; |
| 67040 | | - } cm; |
| 67041 | | - struct OP_VFilter_stack_vars { |
| 67042 | | - int nArg; |
| 67043 | | - int iQuery; |
| 67044 | | - const sqlite3_module *pModule; |
| 67045 | | - Mem *pQuery; |
| 67046 | | - Mem *pArgc; |
| 67047 | | - sqlite3_vtab_cursor *pVtabCursor; |
| 67048 | | - sqlite3_vtab *pVtab; |
| 67049 | | - VdbeCursor *pCur; |
| 67050 | | - int res; |
| 67051 | | - int i; |
| 67052 | | - Mem **apArg; |
| 67053 | | - } cn; |
| 67054 | | - struct OP_VColumn_stack_vars { |
| 67055 | | - sqlite3_vtab *pVtab; |
| 67056 | | - const sqlite3_module *pModule; |
| 67057 | | - Mem *pDest; |
| 67058 | | - sqlite3_context sContext; |
| 67059 | | - } co; |
| 67060 | | - struct OP_VNext_stack_vars { |
| 67061 | | - sqlite3_vtab *pVtab; |
| 67062 | | - const sqlite3_module *pModule; |
| 67063 | | - int res; |
| 67064 | | - VdbeCursor *pCur; |
| 67065 | | - } cp; |
| 67066 | | - struct OP_VRename_stack_vars { |
| 67067 | | - sqlite3_vtab *pVtab; |
| 67068 | | - Mem *pName; |
| 67069 | | - } cq; |
| 67070 | | - struct OP_VUpdate_stack_vars { |
| 67071 | | - sqlite3_vtab *pVtab; |
| 67072 | | - sqlite3_module *pModule; |
| 67073 | | - int nArg; |
| 67074 | | - int i; |
| 67075 | | - sqlite_int64 rowid; |
| 67076 | | - Mem **apArg; |
| 67077 | | - Mem *pX; |
| 67078 | | - } cr; |
| 67079 | | - struct OP_Trace_stack_vars { |
| 67080 | | - char *zTrace; |
| 67081 | | - char *z; |
| 67082 | | - } cs; |
| 67083 | | - } u; |
| 67084 | | - /* End automatically generated code |
| 67085 | | - ********************************************************************/ |
| 66657 | + /*** INSERT STACK UNION HERE ***/ |
| 67086 | 66658 | |
| 67087 | 66659 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 67088 | 66660 | sqlite3VdbeEnter(p); |
| 67089 | 66661 | if( p->rc==SQLITE_NOMEM ){ |
| 67090 | 66662 | /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| | @@ -67326,20 +66898,18 @@ |
| 67326 | 66898 | /* Opcode: Yield P1 * * * * |
| 67327 | 66899 | ** |
| 67328 | 66900 | ** Swap the program counter with the value in register P1. |
| 67329 | 66901 | */ |
| 67330 | 66902 | case OP_Yield: { /* in1 */ |
| 67331 | | -#if 0 /* local variables moved into u.aa */ |
| 67332 | 66903 | int pcDest; |
| 67333 | | -#endif /* local variables moved into u.aa */ |
| 67334 | 66904 | pIn1 = &aMem[pOp->p1]; |
| 67335 | 66905 | assert( (pIn1->flags & MEM_Dyn)==0 ); |
| 67336 | 66906 | pIn1->flags = MEM_Int; |
| 67337 | | - u.aa.pcDest = (int)pIn1->u.i; |
| 66907 | + pcDest = (int)pIn1->u.i; |
| 67338 | 66908 | pIn1->u.i = pc; |
| 67339 | 66909 | REGISTER_TRACE(pOp->p1, pIn1); |
| 67340 | | - pc = u.aa.pcDest; |
| 66910 | + pc = pcDest; |
| 67341 | 66911 | break; |
| 67342 | 66912 | } |
| 67343 | 66913 | |
| 67344 | 66914 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 67345 | 66915 | ** Synopsis: if r[P3] null then halt |
| | @@ -67384,14 +66954,12 @@ |
| 67384 | 66954 | ** There is an implied "Halt 0 0 0" instruction inserted at the very end of |
| 67385 | 66955 | ** every program. So a jump past the last instruction of the program |
| 67386 | 66956 | ** is the same as executing Halt. |
| 67387 | 66957 | */ |
| 67388 | 66958 | case OP_Halt: { |
| 67389 | | -#if 0 /* local variables moved into u.ab */ |
| 67390 | 66959 | const char *zType; |
| 67391 | 66960 | const char *zLogFmt; |
| 67392 | | -#endif /* local variables moved into u.ab */ |
| 67393 | 66961 | |
| 67394 | 66962 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 67395 | 66963 | /* Halt the sub-program. Return control to the parent frame. */ |
| 67396 | 66964 | VdbeFrame *pFrame = p->pFrame; |
| 67397 | 66965 | p->pFrame = pFrame->pParent; |
| | @@ -67398,11 +66966,11 @@ |
| 67398 | 66966 | p->nFrame--; |
| 67399 | 66967 | sqlite3VdbeSetChanges(db, p->nChange); |
| 67400 | 66968 | pc = sqlite3VdbeFrameRestore(pFrame); |
| 67401 | 66969 | lastRowid = db->lastRowid; |
| 67402 | 66970 | if( pOp->p2==OE_Ignore ){ |
| 67403 | | - /* Instruction pc is the OP_Program that invoked the sub-program |
| 66971 | + /* Instruction pc is the OP_Program that invoked the sub-program |
| 67404 | 66972 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 67405 | 66973 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 67406 | 66974 | ** an IGNORE exception. In this case jump to the address specified |
| 67407 | 66975 | ** as the p2 of the calling OP_Program. */ |
| 67408 | 66976 | pc = p->aOp[pc].p2-1; |
| | @@ -67421,25 +66989,25 @@ |
| 67421 | 66989 | assert( pOp->p5>=1 && pOp->p5<=4 ); |
| 67422 | 66990 | testcase( pOp->p5==1 ); |
| 67423 | 66991 | testcase( pOp->p5==2 ); |
| 67424 | 66992 | testcase( pOp->p5==3 ); |
| 67425 | 66993 | testcase( pOp->p5==4 ); |
| 67426 | | - u.ab.zType = azType[pOp->p5-1]; |
| 66994 | + zType = azType[pOp->p5-1]; |
| 67427 | 66995 | }else{ |
| 67428 | | - u.ab.zType = 0; |
| 66996 | + zType = 0; |
| 67429 | 66997 | } |
| 67430 | | - assert( u.ab.zType!=0 || pOp->p4.z!=0 ); |
| 67431 | | - u.ab.zLogFmt = "abort at %d in [%s]: %s"; |
| 67432 | | - if( u.ab.zType && pOp->p4.z ){ |
| 67433 | | - sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s", |
| 67434 | | - u.ab.zType, pOp->p4.z); |
| 66998 | + assert( zType!=0 || pOp->p4.z!=0 ); |
| 66999 | + zLogFmt = "abort at %d in [%s]: %s"; |
| 67000 | + if( zType && pOp->p4.z ){ |
| 67001 | + sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s", |
| 67002 | + zType, pOp->p4.z); |
| 67435 | 67003 | }else if( pOp->p4.z ){ |
| 67436 | 67004 | sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); |
| 67437 | 67005 | }else{ |
| 67438 | | - sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType); |
| 67006 | + sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); |
| 67439 | 67007 | } |
| 67440 | | - sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg); |
| 67008 | + sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg); |
| 67441 | 67009 | } |
| 67442 | 67010 | rc = sqlite3VdbeHalt(p); |
| 67443 | 67011 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 67444 | 67012 | if( rc==SQLITE_BUSY ){ |
| 67445 | 67013 | p->rc = rc = SQLITE_BUSY; |
| | @@ -67549,23 +67117,21 @@ |
| 67549 | 67117 | ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 67550 | 67118 | ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 67551 | 67119 | ** OP_Ne or OP_Eq. |
| 67552 | 67120 | */ |
| 67553 | 67121 | case OP_Null: { /* out2-prerelease */ |
| 67554 | | -#if 0 /* local variables moved into u.ac */ |
| 67555 | 67122 | int cnt; |
| 67556 | 67123 | u16 nullFlag; |
| 67557 | | -#endif /* local variables moved into u.ac */ |
| 67558 | | - u.ac.cnt = pOp->p3-pOp->p2; |
| 67124 | + cnt = pOp->p3-pOp->p2; |
| 67559 | 67125 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 67560 | | - pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 67561 | | - while( u.ac.cnt>0 ){ |
| 67126 | + pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 67127 | + while( cnt>0 ){ |
| 67562 | 67128 | pOut++; |
| 67563 | 67129 | memAboutToChange(p, pOut); |
| 67564 | 67130 | VdbeMemRelease(pOut); |
| 67565 | | - pOut->flags = u.ac.nullFlag; |
| 67566 | | - u.ac.cnt--; |
| 67131 | + pOut->flags = nullFlag; |
| 67132 | + cnt--; |
| 67567 | 67133 | } |
| 67568 | 67134 | break; |
| 67569 | 67135 | } |
| 67570 | 67136 | |
| 67571 | 67137 | |
| | @@ -67590,21 +67156,19 @@ |
| 67590 | 67156 | ** |
| 67591 | 67157 | ** If the parameter is named, then its name appears in P4 and P3==1. |
| 67592 | 67158 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 67593 | 67159 | */ |
| 67594 | 67160 | case OP_Variable: { /* out2-prerelease */ |
| 67595 | | -#if 0 /* local variables moved into u.ad */ |
| 67596 | 67161 | Mem *pVar; /* Value being transferred */ |
| 67597 | | -#endif /* local variables moved into u.ad */ |
| 67598 | 67162 | |
| 67599 | 67163 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 67600 | 67164 | assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 67601 | | - u.ad.pVar = &p->aVar[pOp->p1 - 1]; |
| 67602 | | - if( sqlite3VdbeMemTooBig(u.ad.pVar) ){ |
| 67165 | + pVar = &p->aVar[pOp->p1 - 1]; |
| 67166 | + if( sqlite3VdbeMemTooBig(pVar) ){ |
| 67603 | 67167 | goto too_big; |
| 67604 | 67168 | } |
| 67605 | | - sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static); |
| 67169 | + sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 67606 | 67170 | UPDATE_MAX_BLOBSIZE(pOut); |
| 67607 | 67171 | break; |
| 67608 | 67172 | } |
| 67609 | 67173 | |
| 67610 | 67174 | /* Opcode: Move P1 P2 P3 * * |
| | @@ -67614,43 +67178,41 @@ |
| 67614 | 67178 | ** registers P2..P2+P3. Registers P1..P1+P3 are |
| 67615 | 67179 | ** left holding a NULL. It is an error for register ranges |
| 67616 | 67180 | ** P1..P1+P3 and P2..P2+P3 to overlap. |
| 67617 | 67181 | */ |
| 67618 | 67182 | case OP_Move: { |
| 67619 | | -#if 0 /* local variables moved into u.ae */ |
| 67620 | 67183 | char *zMalloc; /* Holding variable for allocated memory */ |
| 67621 | 67184 | int n; /* Number of registers left to copy */ |
| 67622 | 67185 | int p1; /* Register to copy from */ |
| 67623 | 67186 | int p2; /* Register to copy to */ |
| 67624 | | -#endif /* local variables moved into u.ae */ |
| 67625 | | - |
| 67626 | | - u.ae.n = pOp->p3; |
| 67627 | | - u.ae.p1 = pOp->p1; |
| 67628 | | - u.ae.p2 = pOp->p2; |
| 67629 | | - assert( u.ae.n>=0 && u.ae.p1>0 && u.ae.p2>0 ); |
| 67630 | | - assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 ); |
| 67631 | | - |
| 67632 | | - pIn1 = &aMem[u.ae.p1]; |
| 67633 | | - pOut = &aMem[u.ae.p2]; |
| 67187 | + |
| 67188 | + n = pOp->p3; |
| 67189 | + p1 = pOp->p1; |
| 67190 | + p2 = pOp->p2; |
| 67191 | + assert( n>=0 && p1>0 && p2>0 ); |
| 67192 | + assert( p1+n<=p2 || p2+n<=p1 ); |
| 67193 | + |
| 67194 | + pIn1 = &aMem[p1]; |
| 67195 | + pOut = &aMem[p2]; |
| 67634 | 67196 | do{ |
| 67635 | 67197 | assert( pOut<=&aMem[(p->nMem-p->nCursor)] ); |
| 67636 | 67198 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 67637 | 67199 | assert( memIsValid(pIn1) ); |
| 67638 | 67200 | memAboutToChange(p, pOut); |
| 67639 | | - u.ae.zMalloc = pOut->zMalloc; |
| 67201 | + zMalloc = pOut->zMalloc; |
| 67640 | 67202 | pOut->zMalloc = 0; |
| 67641 | 67203 | sqlite3VdbeMemMove(pOut, pIn1); |
| 67642 | 67204 | #ifdef SQLITE_DEBUG |
| 67643 | | - if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){ |
| 67644 | | - pOut->pScopyFrom += u.ae.p1 - pOp->p2; |
| 67205 | + if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){ |
| 67206 | + pOut->pScopyFrom += p1 - pOp->p2; |
| 67645 | 67207 | } |
| 67646 | 67208 | #endif |
| 67647 | | - pIn1->zMalloc = u.ae.zMalloc; |
| 67648 | | - REGISTER_TRACE(u.ae.p2++, pOut); |
| 67209 | + pIn1->zMalloc = zMalloc; |
| 67210 | + REGISTER_TRACE(p2++, pOut); |
| 67649 | 67211 | pIn1++; |
| 67650 | 67212 | pOut++; |
| 67651 | | - }while( u.ae.n-- ); |
| 67213 | + }while( n-- ); |
| 67652 | 67214 | break; |
| 67653 | 67215 | } |
| 67654 | 67216 | |
| 67655 | 67217 | /* Opcode: Copy P1 P2 P3 * * |
| 67656 | 67218 | ** Synopsis: r[P2@P3]=r[P1@P3] |
| | @@ -67659,26 +67221,24 @@ |
| 67659 | 67221 | ** |
| 67660 | 67222 | ** This instruction makes a deep copy of the value. A duplicate |
| 67661 | 67223 | ** is made of any string or blob constant. See also OP_SCopy. |
| 67662 | 67224 | */ |
| 67663 | 67225 | case OP_Copy: { |
| 67664 | | -#if 0 /* local variables moved into u.af */ |
| 67665 | 67226 | int n; |
| 67666 | | -#endif /* local variables moved into u.af */ |
| 67667 | 67227 | |
| 67668 | | - u.af.n = pOp->p3; |
| 67228 | + n = pOp->p3; |
| 67669 | 67229 | pIn1 = &aMem[pOp->p1]; |
| 67670 | 67230 | pOut = &aMem[pOp->p2]; |
| 67671 | 67231 | assert( pOut!=pIn1 ); |
| 67672 | 67232 | while( 1 ){ |
| 67673 | 67233 | sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); |
| 67674 | 67234 | Deephemeralize(pOut); |
| 67675 | 67235 | #ifdef SQLITE_DEBUG |
| 67676 | 67236 | pOut->pScopyFrom = 0; |
| 67677 | 67237 | #endif |
| 67678 | | - REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut); |
| 67679 | | - if( (u.af.n--)==0 ) break; |
| 67238 | + REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut); |
| 67239 | + if( (n--)==0 ) break; |
| 67680 | 67240 | pOut++; |
| 67681 | 67241 | pIn1++; |
| 67682 | 67242 | } |
| 67683 | 67243 | break; |
| 67684 | 67244 | } |
| | @@ -67715,14 +67275,12 @@ |
| 67715 | 67275 | ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt |
| 67716 | 67276 | ** structure to provide access to the top P1 values as the result |
| 67717 | 67277 | ** row. |
| 67718 | 67278 | */ |
| 67719 | 67279 | case OP_ResultRow: { |
| 67720 | | -#if 0 /* local variables moved into u.ag */ |
| 67721 | 67280 | Mem *pMem; |
| 67722 | 67281 | int i; |
| 67723 | | -#endif /* local variables moved into u.ag */ |
| 67724 | 67282 | assert( p->nResColumn==pOp->p2 ); |
| 67725 | 67283 | assert( pOp->p1>0 ); |
| 67726 | 67284 | assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 ); |
| 67727 | 67285 | |
| 67728 | 67286 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| | @@ -67744,12 +67302,12 @@ |
| 67744 | 67302 | assert( db->flags&SQLITE_CountRows ); |
| 67745 | 67303 | assert( p->usesStmtJournal ); |
| 67746 | 67304 | break; |
| 67747 | 67305 | } |
| 67748 | 67306 | |
| 67749 | | - /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then |
| 67750 | | - ** DML statements invoke this opcode to return the number of rows |
| 67307 | + /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then |
| 67308 | + ** DML statements invoke this opcode to return the number of rows |
| 67751 | 67309 | ** modified to the user. This is the only way that a VM that |
| 67752 | 67310 | ** opens a statement transaction may invoke this opcode. |
| 67753 | 67311 | ** |
| 67754 | 67312 | ** In case this is such a statement, close any statement transaction |
| 67755 | 67313 | ** opened by this VM before returning control to the user. This is to |
| | @@ -67772,19 +67330,19 @@ |
| 67772 | 67330 | |
| 67773 | 67331 | /* Make sure the results of the current row are \000 terminated |
| 67774 | 67332 | ** and have an assigned type. The results are de-ephemeralized as |
| 67775 | 67333 | ** a side effect. |
| 67776 | 67334 | */ |
| 67777 | | - u.ag.pMem = p->pResultSet = &aMem[pOp->p1]; |
| 67778 | | - for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){ |
| 67779 | | - assert( memIsValid(&u.ag.pMem[u.ag.i]) ); |
| 67780 | | - Deephemeralize(&u.ag.pMem[u.ag.i]); |
| 67781 | | - assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0 |
| 67782 | | - || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 ); |
| 67783 | | - sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]); |
| 67784 | | - sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]); |
| 67785 | | - REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]); |
| 67335 | + pMem = p->pResultSet = &aMem[pOp->p1]; |
| 67336 | + for(i=0; i<pOp->p2; i++){ |
| 67337 | + assert( memIsValid(&pMem[i]) ); |
| 67338 | + Deephemeralize(&pMem[i]); |
| 67339 | + assert( (pMem[i].flags & MEM_Ephem)==0 |
| 67340 | + || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 ); |
| 67341 | + sqlite3VdbeMemNulTerminate(&pMem[i]); |
| 67342 | + sqlite3VdbeMemStoreType(&pMem[i]); |
| 67343 | + REGISTER_TRACE(pOp->p1+i, &pMem[i]); |
| 67786 | 67344 | } |
| 67787 | 67345 | if( db->mallocFailed ) goto no_mem; |
| 67788 | 67346 | |
| 67789 | 67347 | /* Return SQLITE_ROW |
| 67790 | 67348 | */ |
| | @@ -67805,13 +67363,11 @@ |
| 67805 | 67363 | ** It is illegal for P1 and P3 to be the same register. Sometimes, |
| 67806 | 67364 | ** if P3 is the same register as P2, the implementation is able |
| 67807 | 67365 | ** to avoid a memcpy(). |
| 67808 | 67366 | */ |
| 67809 | 67367 | case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */ |
| 67810 | | -#if 0 /* local variables moved into u.ah */ |
| 67811 | 67368 | i64 nByte; |
| 67812 | | -#endif /* local variables moved into u.ah */ |
| 67813 | 67369 | |
| 67814 | 67370 | pIn1 = &aMem[pOp->p1]; |
| 67815 | 67371 | pIn2 = &aMem[pOp->p2]; |
| 67816 | 67372 | pOut = &aMem[pOp->p3]; |
| 67817 | 67373 | assert( pIn1!=pOut ); |
| | @@ -67820,26 +67376,26 @@ |
| 67820 | 67376 | break; |
| 67821 | 67377 | } |
| 67822 | 67378 | if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem; |
| 67823 | 67379 | Stringify(pIn1, encoding); |
| 67824 | 67380 | Stringify(pIn2, encoding); |
| 67825 | | - u.ah.nByte = pIn1->n + pIn2->n; |
| 67826 | | - if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 67381 | + nByte = pIn1->n + pIn2->n; |
| 67382 | + if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 67827 | 67383 | goto too_big; |
| 67828 | 67384 | } |
| 67829 | 67385 | MemSetTypeFlag(pOut, MEM_Str); |
| 67830 | | - if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){ |
| 67386 | + if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){ |
| 67831 | 67387 | goto no_mem; |
| 67832 | 67388 | } |
| 67833 | 67389 | if( pOut!=pIn2 ){ |
| 67834 | 67390 | memcpy(pOut->z, pIn2->z, pIn2->n); |
| 67835 | 67391 | } |
| 67836 | 67392 | memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n); |
| 67837 | | - pOut->z[u.ah.nByte]=0; |
| 67838 | | - pOut->z[u.ah.nByte+1] = 0; |
| 67393 | + pOut->z[nByte]=0; |
| 67394 | + pOut->z[nByte+1] = 0; |
| 67839 | 67395 | pOut->flags |= MEM_Term; |
| 67840 | | - pOut->n = (int)u.ah.nByte; |
| 67396 | + pOut->n = (int)nByte; |
| 67841 | 67397 | pOut->enc = encoding; |
| 67842 | 67398 | UPDATE_MAX_BLOBSIZE(pOut); |
| 67843 | 67399 | break; |
| 67844 | 67400 | } |
| 67845 | 67401 | |
| | @@ -67884,83 +67440,81 @@ |
| 67884 | 67440 | case OP_Add: /* same as TK_PLUS, in1, in2, out3 */ |
| 67885 | 67441 | case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */ |
| 67886 | 67442 | case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */ |
| 67887 | 67443 | case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */ |
| 67888 | 67444 | case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ |
| 67889 | | -#if 0 /* local variables moved into u.ai */ |
| 67890 | 67445 | char bIntint; /* Started out as two integer operands */ |
| 67891 | 67446 | int flags; /* Combined MEM_* flags from both inputs */ |
| 67892 | 67447 | i64 iA; /* Integer value of left operand */ |
| 67893 | 67448 | i64 iB; /* Integer value of right operand */ |
| 67894 | 67449 | double rA; /* Real value of left operand */ |
| 67895 | 67450 | double rB; /* Real value of right operand */ |
| 67896 | | -#endif /* local variables moved into u.ai */ |
| 67897 | 67451 | |
| 67898 | 67452 | pIn1 = &aMem[pOp->p1]; |
| 67899 | 67453 | applyNumericAffinity(pIn1); |
| 67900 | 67454 | pIn2 = &aMem[pOp->p2]; |
| 67901 | 67455 | applyNumericAffinity(pIn2); |
| 67902 | 67456 | pOut = &aMem[pOp->p3]; |
| 67903 | | - u.ai.flags = pIn1->flags | pIn2->flags; |
| 67904 | | - if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; |
| 67457 | + flags = pIn1->flags | pIn2->flags; |
| 67458 | + if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; |
| 67905 | 67459 | if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ |
| 67906 | | - u.ai.iA = pIn1->u.i; |
| 67907 | | - u.ai.iB = pIn2->u.i; |
| 67908 | | - u.ai.bIntint = 1; |
| 67460 | + iA = pIn1->u.i; |
| 67461 | + iB = pIn2->u.i; |
| 67462 | + bIntint = 1; |
| 67909 | 67463 | switch( pOp->opcode ){ |
| 67910 | | - case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; |
| 67911 | | - case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; |
| 67912 | | - case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; |
| 67464 | + case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break; |
| 67465 | + case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break; |
| 67466 | + case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break; |
| 67913 | 67467 | case OP_Divide: { |
| 67914 | | - if( u.ai.iA==0 ) goto arithmetic_result_is_null; |
| 67915 | | - if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math; |
| 67916 | | - u.ai.iB /= u.ai.iA; |
| 67468 | + if( iA==0 ) goto arithmetic_result_is_null; |
| 67469 | + if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math; |
| 67470 | + iB /= iA; |
| 67917 | 67471 | break; |
| 67918 | 67472 | } |
| 67919 | 67473 | default: { |
| 67920 | | - if( u.ai.iA==0 ) goto arithmetic_result_is_null; |
| 67921 | | - if( u.ai.iA==-1 ) u.ai.iA = 1; |
| 67922 | | - u.ai.iB %= u.ai.iA; |
| 67474 | + if( iA==0 ) goto arithmetic_result_is_null; |
| 67475 | + if( iA==-1 ) iA = 1; |
| 67476 | + iB %= iA; |
| 67923 | 67477 | break; |
| 67924 | 67478 | } |
| 67925 | 67479 | } |
| 67926 | | - pOut->u.i = u.ai.iB; |
| 67480 | + pOut->u.i = iB; |
| 67927 | 67481 | MemSetTypeFlag(pOut, MEM_Int); |
| 67928 | 67482 | }else{ |
| 67929 | | - u.ai.bIntint = 0; |
| 67483 | + bIntint = 0; |
| 67930 | 67484 | fp_math: |
| 67931 | | - u.ai.rA = sqlite3VdbeRealValue(pIn1); |
| 67932 | | - u.ai.rB = sqlite3VdbeRealValue(pIn2); |
| 67485 | + rA = sqlite3VdbeRealValue(pIn1); |
| 67486 | + rB = sqlite3VdbeRealValue(pIn2); |
| 67933 | 67487 | switch( pOp->opcode ){ |
| 67934 | | - case OP_Add: u.ai.rB += u.ai.rA; break; |
| 67935 | | - case OP_Subtract: u.ai.rB -= u.ai.rA; break; |
| 67936 | | - case OP_Multiply: u.ai.rB *= u.ai.rA; break; |
| 67488 | + case OP_Add: rB += rA; break; |
| 67489 | + case OP_Subtract: rB -= rA; break; |
| 67490 | + case OP_Multiply: rB *= rA; break; |
| 67937 | 67491 | case OP_Divide: { |
| 67938 | 67492 | /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ |
| 67939 | | - if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null; |
| 67940 | | - u.ai.rB /= u.ai.rA; |
| 67493 | + if( rA==(double)0 ) goto arithmetic_result_is_null; |
| 67494 | + rB /= rA; |
| 67941 | 67495 | break; |
| 67942 | 67496 | } |
| 67943 | 67497 | default: { |
| 67944 | | - u.ai.iA = (i64)u.ai.rA; |
| 67945 | | - u.ai.iB = (i64)u.ai.rB; |
| 67946 | | - if( u.ai.iA==0 ) goto arithmetic_result_is_null; |
| 67947 | | - if( u.ai.iA==-1 ) u.ai.iA = 1; |
| 67948 | | - u.ai.rB = (double)(u.ai.iB % u.ai.iA); |
| 67498 | + iA = (i64)rA; |
| 67499 | + iB = (i64)rB; |
| 67500 | + if( iA==0 ) goto arithmetic_result_is_null; |
| 67501 | + if( iA==-1 ) iA = 1; |
| 67502 | + rB = (double)(iB % iA); |
| 67949 | 67503 | break; |
| 67950 | 67504 | } |
| 67951 | 67505 | } |
| 67952 | 67506 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 67953 | | - pOut->u.i = u.ai.rB; |
| 67507 | + pOut->u.i = rB; |
| 67954 | 67508 | MemSetTypeFlag(pOut, MEM_Int); |
| 67955 | 67509 | #else |
| 67956 | | - if( sqlite3IsNaN(u.ai.rB) ){ |
| 67510 | + if( sqlite3IsNaN(rB) ){ |
| 67957 | 67511 | goto arithmetic_result_is_null; |
| 67958 | 67512 | } |
| 67959 | | - pOut->r = u.ai.rB; |
| 67513 | + pOut->r = rB; |
| 67960 | 67514 | MemSetTypeFlag(pOut, MEM_Real); |
| 67961 | | - if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){ |
| 67515 | + if( (flags & MEM_Real)==0 && !bIntint ){ |
| 67962 | 67516 | sqlite3VdbeIntegerAffinity(pOut); |
| 67963 | 67517 | } |
| 67964 | 67518 | #endif |
| 67965 | 67519 | } |
| 67966 | 67520 | break; |
| | @@ -68009,85 +67563,83 @@ |
| 68009 | 67563 | ** invocation of this opcode. |
| 68010 | 67564 | ** |
| 68011 | 67565 | ** See also: AggStep and AggFinal |
| 68012 | 67566 | */ |
| 68013 | 67567 | case OP_Function: { |
| 68014 | | -#if 0 /* local variables moved into u.aj */ |
| 68015 | 67568 | int i; |
| 68016 | 67569 | Mem *pArg; |
| 68017 | 67570 | sqlite3_context ctx; |
| 68018 | 67571 | sqlite3_value **apVal; |
| 68019 | 67572 | int n; |
| 68020 | | -#endif /* local variables moved into u.aj */ |
| 68021 | 67573 | |
| 68022 | | - u.aj.n = pOp->p5; |
| 68023 | | - u.aj.apVal = p->apArg; |
| 68024 | | - assert( u.aj.apVal || u.aj.n==0 ); |
| 67574 | + n = pOp->p5; |
| 67575 | + apVal = p->apArg; |
| 67576 | + assert( apVal || n==0 ); |
| 68025 | 67577 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68026 | 67578 | pOut = &aMem[pOp->p3]; |
| 68027 | 67579 | memAboutToChange(p, pOut); |
| 68028 | 67580 | |
| 68029 | | - assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) ); |
| 68030 | | - assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n ); |
| 68031 | | - u.aj.pArg = &aMem[pOp->p2]; |
| 68032 | | - for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){ |
| 68033 | | - assert( memIsValid(u.aj.pArg) ); |
| 68034 | | - u.aj.apVal[u.aj.i] = u.aj.pArg; |
| 68035 | | - Deephemeralize(u.aj.pArg); |
| 68036 | | - sqlite3VdbeMemStoreType(u.aj.pArg); |
| 68037 | | - REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg); |
| 67581 | + assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) ); |
| 67582 | + assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n ); |
| 67583 | + pArg = &aMem[pOp->p2]; |
| 67584 | + for(i=0; i<n; i++, pArg++){ |
| 67585 | + assert( memIsValid(pArg) ); |
| 67586 | + apVal[i] = pArg; |
| 67587 | + Deephemeralize(pArg); |
| 67588 | + sqlite3VdbeMemStoreType(pArg); |
| 67589 | + REGISTER_TRACE(pOp->p2+i, pArg); |
| 68038 | 67590 | } |
| 68039 | 67591 | |
| 68040 | 67592 | assert( pOp->p4type==P4_FUNCDEF ); |
| 68041 | | - u.aj.ctx.pFunc = pOp->p4.pFunc; |
| 68042 | | - u.aj.ctx.iOp = pc; |
| 68043 | | - u.aj.ctx.pVdbe = p; |
| 67593 | + ctx.pFunc = pOp->p4.pFunc; |
| 67594 | + ctx.iOp = pc; |
| 67595 | + ctx.pVdbe = p; |
| 68044 | 67596 | |
| 68045 | 67597 | /* The output cell may already have a buffer allocated. Move |
| 68046 | | - ** the pointer to u.aj.ctx.s so in case the user-function can use |
| 67598 | + ** the pointer to ctx.s so in case the user-function can use |
| 68047 | 67599 | ** the already allocated buffer instead of allocating a new one. |
| 68048 | 67600 | */ |
| 68049 | | - memcpy(&u.aj.ctx.s, pOut, sizeof(Mem)); |
| 67601 | + memcpy(&ctx.s, pOut, sizeof(Mem)); |
| 68050 | 67602 | pOut->flags = MEM_Null; |
| 68051 | 67603 | pOut->xDel = 0; |
| 68052 | 67604 | pOut->zMalloc = 0; |
| 68053 | | - MemSetTypeFlag(&u.aj.ctx.s, MEM_Null); |
| 67605 | + MemSetTypeFlag(&ctx.s, MEM_Null); |
| 68054 | 67606 | |
| 68055 | | - u.aj.ctx.fErrorOrAux = 0; |
| 68056 | | - if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 67607 | + ctx.fErrorOrAux = 0; |
| 67608 | + if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 68057 | 67609 | assert( pOp>aOp ); |
| 68058 | 67610 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 68059 | 67611 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 68060 | | - u.aj.ctx.pColl = pOp[-1].p4.pColl; |
| 67612 | + ctx.pColl = pOp[-1].p4.pColl; |
| 68061 | 67613 | } |
| 68062 | 67614 | db->lastRowid = lastRowid; |
| 68063 | | - (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */ |
| 67615 | + (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| 68064 | 67616 | lastRowid = db->lastRowid; |
| 68065 | 67617 | |
| 68066 | 67618 | if( db->mallocFailed ){ |
| 68067 | 67619 | /* Even though a malloc() has failed, the implementation of the |
| 68068 | 67620 | ** user function may have called an sqlite3_result_XXX() function |
| 68069 | 67621 | ** to return a value. The following call releases any resources |
| 68070 | 67622 | ** associated with such a value. |
| 68071 | 67623 | */ |
| 68072 | | - sqlite3VdbeMemRelease(&u.aj.ctx.s); |
| 67624 | + sqlite3VdbeMemRelease(&ctx.s); |
| 68073 | 67625 | goto no_mem; |
| 68074 | 67626 | } |
| 68075 | 67627 | |
| 68076 | 67628 | /* If the function returned an error, throw an exception */ |
| 68077 | | - if( u.aj.ctx.fErrorOrAux ){ |
| 68078 | | - if( u.aj.ctx.isError ){ |
| 68079 | | - sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s)); |
| 68080 | | - rc = u.aj.ctx.isError; |
| 67629 | + if( ctx.fErrorOrAux ){ |
| 67630 | + if( ctx.isError ){ |
| 67631 | + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); |
| 67632 | + rc = ctx.isError; |
| 68081 | 67633 | } |
| 68082 | 67634 | sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 68083 | 67635 | } |
| 68084 | 67636 | |
| 68085 | 67637 | /* Copy the result of the function into register P3 */ |
| 68086 | | - sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding); |
| 67638 | + sqlite3VdbeChangeEncoding(&ctx.s, encoding); |
| 68087 | 67639 | assert( pOut->flags==MEM_Null ); |
| 68088 | | - memcpy(pOut, &u.aj.ctx.s, sizeof(Mem)); |
| 67640 | + memcpy(pOut, &ctx.s, sizeof(Mem)); |
| 68089 | 67641 | if( sqlite3VdbeMemTooBig(pOut) ){ |
| 68090 | 67642 | goto too_big; |
| 68091 | 67643 | } |
| 68092 | 67644 | |
| 68093 | 67645 | #if 0 |
| | @@ -68135,56 +67687,54 @@ |
| 68135 | 67687 | */ |
| 68136 | 67688 | case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */ |
| 68137 | 67689 | case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */ |
| 68138 | 67690 | case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */ |
| 68139 | 67691 | case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */ |
| 68140 | | -#if 0 /* local variables moved into u.ak */ |
| 68141 | 67692 | i64 iA; |
| 68142 | 67693 | u64 uA; |
| 68143 | 67694 | i64 iB; |
| 68144 | 67695 | u8 op; |
| 68145 | | -#endif /* local variables moved into u.ak */ |
| 68146 | 67696 | |
| 68147 | 67697 | pIn1 = &aMem[pOp->p1]; |
| 68148 | 67698 | pIn2 = &aMem[pOp->p2]; |
| 68149 | 67699 | pOut = &aMem[pOp->p3]; |
| 68150 | 67700 | if( (pIn1->flags | pIn2->flags) & MEM_Null ){ |
| 68151 | 67701 | sqlite3VdbeMemSetNull(pOut); |
| 68152 | 67702 | break; |
| 68153 | 67703 | } |
| 68154 | | - u.ak.iA = sqlite3VdbeIntValue(pIn2); |
| 68155 | | - u.ak.iB = sqlite3VdbeIntValue(pIn1); |
| 68156 | | - u.ak.op = pOp->opcode; |
| 68157 | | - if( u.ak.op==OP_BitAnd ){ |
| 68158 | | - u.ak.iA &= u.ak.iB; |
| 68159 | | - }else if( u.ak.op==OP_BitOr ){ |
| 68160 | | - u.ak.iA |= u.ak.iB; |
| 68161 | | - }else if( u.ak.iB!=0 ){ |
| 68162 | | - assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft ); |
| 67704 | + iA = sqlite3VdbeIntValue(pIn2); |
| 67705 | + iB = sqlite3VdbeIntValue(pIn1); |
| 67706 | + op = pOp->opcode; |
| 67707 | + if( op==OP_BitAnd ){ |
| 67708 | + iA &= iB; |
| 67709 | + }else if( op==OP_BitOr ){ |
| 67710 | + iA |= iB; |
| 67711 | + }else if( iB!=0 ){ |
| 67712 | + assert( op==OP_ShiftRight || op==OP_ShiftLeft ); |
| 68163 | 67713 | |
| 68164 | 67714 | /* If shifting by a negative amount, shift in the other direction */ |
| 68165 | | - if( u.ak.iB<0 ){ |
| 67715 | + if( iB<0 ){ |
| 68166 | 67716 | assert( OP_ShiftRight==OP_ShiftLeft+1 ); |
| 68167 | | - u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op; |
| 68168 | | - u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64; |
| 67717 | + op = 2*OP_ShiftLeft + 1 - op; |
| 67718 | + iB = iB>(-64) ? -iB : 64; |
| 68169 | 67719 | } |
| 68170 | 67720 | |
| 68171 | | - if( u.ak.iB>=64 ){ |
| 68172 | | - u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1; |
| 68173 | | - }else{ |
| 68174 | | - memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA)); |
| 68175 | | - if( u.ak.op==OP_ShiftLeft ){ |
| 68176 | | - u.ak.uA <<= u.ak.iB; |
| 68177 | | - }else{ |
| 68178 | | - u.ak.uA >>= u.ak.iB; |
| 67721 | + if( iB>=64 ){ |
| 67722 | + iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1; |
| 67723 | + }else{ |
| 67724 | + memcpy(&uA, &iA, sizeof(uA)); |
| 67725 | + if( op==OP_ShiftLeft ){ |
| 67726 | + uA <<= iB; |
| 67727 | + }else{ |
| 67728 | + uA >>= iB; |
| 68179 | 67729 | /* Sign-extend on a right shift of a negative number */ |
| 68180 | | - if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB); |
| 67730 | + if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB); |
| 68181 | 67731 | } |
| 68182 | | - memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA)); |
| 67732 | + memcpy(&iA, &uA, sizeof(iA)); |
| 68183 | 67733 | } |
| 68184 | 67734 | } |
| 68185 | | - pOut->u.i = u.ak.iA; |
| 67735 | + pOut->u.i = iA; |
| 68186 | 67736 | MemSetTypeFlag(pOut, MEM_Int); |
| 68187 | 67737 | break; |
| 68188 | 67738 | } |
| 68189 | 67739 | |
| 68190 | 67740 | /* Opcode: AddImm P1 P2 * * * |
| | @@ -68434,37 +67984,35 @@ |
| 68434 | 67984 | case OP_Ne: /* same as TK_NE, jump, in1, in3 */ |
| 68435 | 67985 | case OP_Lt: /* same as TK_LT, jump, in1, in3 */ |
| 68436 | 67986 | case OP_Le: /* same as TK_LE, jump, in1, in3 */ |
| 68437 | 67987 | case OP_Gt: /* same as TK_GT, jump, in1, in3 */ |
| 68438 | 67988 | case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ |
| 68439 | | -#if 0 /* local variables moved into u.al */ |
| 68440 | 67989 | int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 68441 | 67990 | char affinity; /* Affinity to use for comparison */ |
| 68442 | 67991 | u16 flags1; /* Copy of initial value of pIn1->flags */ |
| 68443 | 67992 | u16 flags3; /* Copy of initial value of pIn3->flags */ |
| 68444 | | -#endif /* local variables moved into u.al */ |
| 68445 | 67993 | |
| 68446 | 67994 | pIn1 = &aMem[pOp->p1]; |
| 68447 | 67995 | pIn3 = &aMem[pOp->p3]; |
| 68448 | | - u.al.flags1 = pIn1->flags; |
| 68449 | | - u.al.flags3 = pIn3->flags; |
| 68450 | | - if( (u.al.flags1 | u.al.flags3)&MEM_Null ){ |
| 67996 | + flags1 = pIn1->flags; |
| 67997 | + flags3 = pIn3->flags; |
| 67998 | + if( (flags1 | flags3)&MEM_Null ){ |
| 68451 | 67999 | /* One or both operands are NULL */ |
| 68452 | 68000 | if( pOp->p5 & SQLITE_NULLEQ ){ |
| 68453 | 68001 | /* If SQLITE_NULLEQ is set (which will only happen if the operator is |
| 68454 | 68002 | ** OP_Eq or OP_Ne) then take the jump or not depending on whether |
| 68455 | 68003 | ** or not both operands are null. |
| 68456 | 68004 | */ |
| 68457 | 68005 | assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne ); |
| 68458 | | - assert( (u.al.flags1 & MEM_Cleared)==0 ); |
| 68459 | | - if( (u.al.flags1&MEM_Null)!=0 |
| 68460 | | - && (u.al.flags3&MEM_Null)!=0 |
| 68461 | | - && (u.al.flags3&MEM_Cleared)==0 |
| 68006 | + assert( (flags1 & MEM_Cleared)==0 ); |
| 68007 | + if( (flags1&MEM_Null)!=0 |
| 68008 | + && (flags3&MEM_Null)!=0 |
| 68009 | + && (flags3&MEM_Cleared)==0 |
| 68462 | 68010 | ){ |
| 68463 | | - u.al.res = 0; /* Results are equal */ |
| 68011 | + res = 0; /* Results are equal */ |
| 68464 | 68012 | }else{ |
| 68465 | | - u.al.res = 1; /* Results are not equal */ |
| 68013 | + res = 1; /* Results are not equal */ |
| 68466 | 68014 | } |
| 68467 | 68015 | }else{ |
| 68468 | 68016 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 68469 | 68017 | ** then the result is always NULL. |
| 68470 | 68018 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| | @@ -68478,44 +68026,44 @@ |
| 68478 | 68026 | } |
| 68479 | 68027 | break; |
| 68480 | 68028 | } |
| 68481 | 68029 | }else{ |
| 68482 | 68030 | /* Neither operand is NULL. Do a comparison. */ |
| 68483 | | - u.al.affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 68484 | | - if( u.al.affinity ){ |
| 68485 | | - applyAffinity(pIn1, u.al.affinity, encoding); |
| 68486 | | - applyAffinity(pIn3, u.al.affinity, encoding); |
| 68031 | + affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 68032 | + if( affinity ){ |
| 68033 | + applyAffinity(pIn1, affinity, encoding); |
| 68034 | + applyAffinity(pIn3, affinity, encoding); |
| 68487 | 68035 | if( db->mallocFailed ) goto no_mem; |
| 68488 | 68036 | } |
| 68489 | 68037 | |
| 68490 | 68038 | assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); |
| 68491 | 68039 | ExpandBlob(pIn1); |
| 68492 | 68040 | ExpandBlob(pIn3); |
| 68493 | | - u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); |
| 68041 | + res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); |
| 68494 | 68042 | } |
| 68495 | 68043 | switch( pOp->opcode ){ |
| 68496 | | - case OP_Eq: u.al.res = u.al.res==0; break; |
| 68497 | | - case OP_Ne: u.al.res = u.al.res!=0; break; |
| 68498 | | - case OP_Lt: u.al.res = u.al.res<0; break; |
| 68499 | | - case OP_Le: u.al.res = u.al.res<=0; break; |
| 68500 | | - case OP_Gt: u.al.res = u.al.res>0; break; |
| 68501 | | - default: u.al.res = u.al.res>=0; break; |
| 68044 | + case OP_Eq: res = res==0; break; |
| 68045 | + case OP_Ne: res = res!=0; break; |
| 68046 | + case OP_Lt: res = res<0; break; |
| 68047 | + case OP_Le: res = res<=0; break; |
| 68048 | + case OP_Gt: res = res>0; break; |
| 68049 | + default: res = res>=0; break; |
| 68502 | 68050 | } |
| 68503 | 68051 | |
| 68504 | 68052 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 68505 | 68053 | pOut = &aMem[pOp->p2]; |
| 68506 | 68054 | memAboutToChange(p, pOut); |
| 68507 | 68055 | MemSetTypeFlag(pOut, MEM_Int); |
| 68508 | | - pOut->u.i = u.al.res; |
| 68056 | + pOut->u.i = res; |
| 68509 | 68057 | REGISTER_TRACE(pOp->p2, pOut); |
| 68510 | | - }else if( u.al.res ){ |
| 68058 | + }else if( res ){ |
| 68511 | 68059 | pc = pOp->p2-1; |
| 68512 | 68060 | } |
| 68513 | 68061 | |
| 68514 | 68062 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 68515 | | - pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask); |
| 68516 | | - pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask); |
| 68063 | + pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask); |
| 68064 | + pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask); |
| 68517 | 68065 | break; |
| 68518 | 68066 | } |
| 68519 | 68067 | |
| 68520 | 68068 | /* Opcode: Permutation * * * P4 * |
| 68521 | 68069 | ** |
| | @@ -68551,51 +68099,49 @@ |
| 68551 | 68099 | ** The comparison is a sort comparison, so NULLs compare equal, |
| 68552 | 68100 | ** NULLs are less than numbers, numbers are less than strings, |
| 68553 | 68101 | ** and strings are less than blobs. |
| 68554 | 68102 | */ |
| 68555 | 68103 | case OP_Compare: { |
| 68556 | | -#if 0 /* local variables moved into u.am */ |
| 68557 | 68104 | int n; |
| 68558 | 68105 | int i; |
| 68559 | 68106 | int p1; |
| 68560 | 68107 | int p2; |
| 68561 | 68108 | const KeyInfo *pKeyInfo; |
| 68562 | 68109 | int idx; |
| 68563 | 68110 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 68564 | 68111 | int bRev; /* True for DESCENDING sort order */ |
| 68565 | | -#endif /* local variables moved into u.am */ |
| 68566 | 68112 | |
| 68567 | 68113 | if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; |
| 68568 | | - u.am.n = pOp->p3; |
| 68569 | | - u.am.pKeyInfo = pOp->p4.pKeyInfo; |
| 68570 | | - assert( u.am.n>0 ); |
| 68571 | | - assert( u.am.pKeyInfo!=0 ); |
| 68572 | | - u.am.p1 = pOp->p1; |
| 68573 | | - u.am.p2 = pOp->p2; |
| 68114 | + n = pOp->p3; |
| 68115 | + pKeyInfo = pOp->p4.pKeyInfo; |
| 68116 | + assert( n>0 ); |
| 68117 | + assert( pKeyInfo!=0 ); |
| 68118 | + p1 = pOp->p1; |
| 68119 | + p2 = pOp->p2; |
| 68574 | 68120 | #if SQLITE_DEBUG |
| 68575 | 68121 | if( aPermute ){ |
| 68576 | 68122 | int k, mx = 0; |
| 68577 | | - for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k]; |
| 68578 | | - assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 ); |
| 68579 | | - assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 ); |
| 68123 | + for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k]; |
| 68124 | + assert( p1>0 && p1+mx<=(p->nMem-p->nCursor)+1 ); |
| 68125 | + assert( p2>0 && p2+mx<=(p->nMem-p->nCursor)+1 ); |
| 68580 | 68126 | }else{ |
| 68581 | | - assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 ); |
| 68582 | | - assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 ); |
| 68127 | + assert( p1>0 && p1+n<=(p->nMem-p->nCursor)+1 ); |
| 68128 | + assert( p2>0 && p2+n<=(p->nMem-p->nCursor)+1 ); |
| 68583 | 68129 | } |
| 68584 | 68130 | #endif /* SQLITE_DEBUG */ |
| 68585 | | - for(u.am.i=0; u.am.i<u.am.n; u.am.i++){ |
| 68586 | | - u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i; |
| 68587 | | - assert( memIsValid(&aMem[u.am.p1+u.am.idx]) ); |
| 68588 | | - assert( memIsValid(&aMem[u.am.p2+u.am.idx]) ); |
| 68589 | | - REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]); |
| 68590 | | - REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]); |
| 68591 | | - assert( u.am.i<u.am.pKeyInfo->nField ); |
| 68592 | | - u.am.pColl = u.am.pKeyInfo->aColl[u.am.i]; |
| 68593 | | - u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i]; |
| 68594 | | - iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl); |
| 68131 | + for(i=0; i<n; i++){ |
| 68132 | + idx = aPermute ? aPermute[i] : i; |
| 68133 | + assert( memIsValid(&aMem[p1+idx]) ); |
| 68134 | + assert( memIsValid(&aMem[p2+idx]) ); |
| 68135 | + REGISTER_TRACE(p1+idx, &aMem[p1+idx]); |
| 68136 | + REGISTER_TRACE(p2+idx, &aMem[p2+idx]); |
| 68137 | + assert( i<pKeyInfo->nField ); |
| 68138 | + pColl = pKeyInfo->aColl[i]; |
| 68139 | + bRev = pKeyInfo->aSortOrder[i]; |
| 68140 | + iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl); |
| 68595 | 68141 | if( iCompare ){ |
| 68596 | | - if( u.am.bRev ) iCompare = -iCompare; |
| 68142 | + if( bRev ) iCompare = -iCompare; |
| 68597 | 68143 | break; |
| 68598 | 68144 | } |
| 68599 | 68145 | } |
| 68600 | 68146 | aPermute = 0; |
| 68601 | 68147 | break; |
| | @@ -68638,39 +68184,37 @@ |
| 68638 | 68184 | ** even if the other input is NULL. A NULL and false or two NULLs |
| 68639 | 68185 | ** give a NULL output. |
| 68640 | 68186 | */ |
| 68641 | 68187 | case OP_And: /* same as TK_AND, in1, in2, out3 */ |
| 68642 | 68188 | case OP_Or: { /* same as TK_OR, in1, in2, out3 */ |
| 68643 | | -#if 0 /* local variables moved into u.an */ |
| 68644 | 68189 | int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 68645 | 68190 | int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 68646 | | -#endif /* local variables moved into u.an */ |
| 68647 | 68191 | |
| 68648 | 68192 | pIn1 = &aMem[pOp->p1]; |
| 68649 | 68193 | if( pIn1->flags & MEM_Null ){ |
| 68650 | | - u.an.v1 = 2; |
| 68194 | + v1 = 2; |
| 68651 | 68195 | }else{ |
| 68652 | | - u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0; |
| 68196 | + v1 = sqlite3VdbeIntValue(pIn1)!=0; |
| 68653 | 68197 | } |
| 68654 | 68198 | pIn2 = &aMem[pOp->p2]; |
| 68655 | 68199 | if( pIn2->flags & MEM_Null ){ |
| 68656 | | - u.an.v2 = 2; |
| 68200 | + v2 = 2; |
| 68657 | 68201 | }else{ |
| 68658 | | - u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0; |
| 68202 | + v2 = sqlite3VdbeIntValue(pIn2)!=0; |
| 68659 | 68203 | } |
| 68660 | 68204 | if( pOp->opcode==OP_And ){ |
| 68661 | 68205 | static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 }; |
| 68662 | | - u.an.v1 = and_logic[u.an.v1*3+u.an.v2]; |
| 68206 | + v1 = and_logic[v1*3+v2]; |
| 68663 | 68207 | }else{ |
| 68664 | 68208 | static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 }; |
| 68665 | | - u.an.v1 = or_logic[u.an.v1*3+u.an.v2]; |
| 68209 | + v1 = or_logic[v1*3+v2]; |
| 68666 | 68210 | } |
| 68667 | 68211 | pOut = &aMem[pOp->p3]; |
| 68668 | | - if( u.an.v1==2 ){ |
| 68212 | + if( v1==2 ){ |
| 68669 | 68213 | MemSetTypeFlag(pOut, MEM_Null); |
| 68670 | 68214 | }else{ |
| 68671 | | - pOut->u.i = u.an.v1; |
| 68215 | + pOut->u.i = v1; |
| 68672 | 68216 | MemSetTypeFlag(pOut, MEM_Int); |
| 68673 | 68217 | } |
| 68674 | 68218 | break; |
| 68675 | 68219 | } |
| 68676 | 68220 | |
| | @@ -68737,25 +68281,23 @@ |
| 68737 | 68281 | ** is considered false if it has a numeric value of zero. If the value |
| 68738 | 68282 | ** in P1 is NULL then take the jump if P3 is zero. |
| 68739 | 68283 | */ |
| 68740 | 68284 | case OP_If: /* jump, in1 */ |
| 68741 | 68285 | case OP_IfNot: { /* jump, in1 */ |
| 68742 | | -#if 0 /* local variables moved into u.ao */ |
| 68743 | 68286 | int c; |
| 68744 | | -#endif /* local variables moved into u.ao */ |
| 68745 | 68287 | pIn1 = &aMem[pOp->p1]; |
| 68746 | 68288 | if( pIn1->flags & MEM_Null ){ |
| 68747 | | - u.ao.c = pOp->p3; |
| 68289 | + c = pOp->p3; |
| 68748 | 68290 | }else{ |
| 68749 | 68291 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 68750 | | - u.ao.c = sqlite3VdbeIntValue(pIn1)!=0; |
| 68292 | + c = sqlite3VdbeIntValue(pIn1)!=0; |
| 68751 | 68293 | #else |
| 68752 | | - u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0; |
| 68294 | + c = sqlite3VdbeRealValue(pIn1)!=0.0; |
| 68753 | 68295 | #endif |
| 68754 | | - if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c; |
| 68296 | + if( pOp->opcode==OP_IfNot ) c = !c; |
| 68755 | 68297 | } |
| 68756 | | - if( u.ao.c ){ |
| 68298 | + if( c ){ |
| 68757 | 68299 | pc = pOp->p2-1; |
| 68758 | 68300 | } |
| 68759 | 68301 | break; |
| 68760 | 68302 | } |
| 68761 | 68303 | |
| | @@ -68809,11 +68351,10 @@ |
| 68809 | 68351 | ** the result is guaranteed to only be used as the argument of a length() |
| 68810 | 68352 | ** or typeof() function, respectively. The loading of large blobs can be |
| 68811 | 68353 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 68812 | 68354 | */ |
| 68813 | 68355 | case OP_Column: { |
| 68814 | | -#if 0 /* local variables moved into u.ap */ |
| 68815 | 68356 | i64 payloadSize64; /* Number of bytes in the record */ |
| 68816 | 68357 | int p2; /* column number to retrieve */ |
| 68817 | 68358 | VdbeCursor *pC; /* The VDBE cursor */ |
| 68818 | 68359 | BtCursor *pCrsr; /* The BTree cursor */ |
| 68819 | 68360 | u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| | @@ -68828,89 +68369,88 @@ |
| 68828 | 68369 | u32 offset; /* Offset into the data */ |
| 68829 | 68370 | u32 szField; /* Number of bytes in the content of a field */ |
| 68830 | 68371 | u32 avail; /* Number of bytes of available data */ |
| 68831 | 68372 | u32 t; /* A type code from the record header */ |
| 68832 | 68373 | Mem *pReg; /* PseudoTable input register */ |
| 68833 | | -#endif /* local variables moved into u.ap */ |
| 68834 | | - |
| 68835 | | - u.ap.p2 = pOp->p2; |
| 68836 | | - assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68837 | | - u.ap.pDest = &aMem[pOp->p3]; |
| 68838 | | - memAboutToChange(p, u.ap.pDest); |
| 68839 | | - assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 68840 | | - u.ap.pC = p->apCsr[pOp->p1]; |
| 68841 | | - assert( u.ap.pC!=0 ); |
| 68842 | | - assert( u.ap.p2<u.ap.pC->nField ); |
| 68843 | | - u.ap.aType = u.ap.pC->aType; |
| 68844 | | - u.ap.aOffset = u.ap.aType + u.ap.pC->nField; |
| 68845 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 68846 | | - assert( u.ap.pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ |
| 68847 | | -#endif |
| 68848 | | - u.ap.pCrsr = u.ap.pC->pCursor; |
| 68849 | | - assert( u.ap.pCrsr!=0 || u.ap.pC->pseudoTableReg>0 ); /* u.ap.pCrsr NULL on PseudoTables */ |
| 68850 | | - assert( u.ap.pCrsr!=0 || u.ap.pC->nullRow ); /* u.ap.pC->nullRow on PseudoTables */ |
| 68851 | | - |
| 68852 | | - /* If the cursor cache is stale, bring it up-to-date */ |
| 68853 | | - rc = sqlite3VdbeCursorMoveto(u.ap.pC); |
| 68854 | | - if( rc ) goto abort_due_to_error; |
| 68855 | | - if( u.ap.pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){ |
| 68856 | | - if( u.ap.pC->nullRow ){ |
| 68857 | | - if( u.ap.pCrsr==0 ){ |
| 68858 | | - assert( u.ap.pC->pseudoTableReg>0 ); |
| 68859 | | - u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg]; |
| 68860 | | - if( u.ap.pC->multiPseudo ){ |
| 68861 | | - sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem); |
| 68862 | | - Deephemeralize(u.ap.pDest); |
| 68863 | | - goto op_column_out; |
| 68864 | | - } |
| 68865 | | - assert( u.ap.pReg->flags & MEM_Blob ); |
| 68866 | | - assert( memIsValid(u.ap.pReg) ); |
| 68867 | | - u.ap.pC->payloadSize = u.ap.pC->szRow = u.ap.avail = u.ap.pReg->n; |
| 68868 | | - u.ap.pC->aRow = (u8*)u.ap.pReg->z; |
| 68869 | | - }else{ |
| 68870 | | - MemSetTypeFlag(u.ap.pDest, MEM_Null); |
| 68871 | | - goto op_column_out; |
| 68872 | | - } |
| 68873 | | - }else{ |
| 68874 | | - assert( u.ap.pCrsr ); |
| 68875 | | - if( u.ap.pC->isTable==0 ){ |
| 68876 | | - assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); |
| 68877 | | - VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64); |
| 68878 | | - assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 68879 | | - /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the |
| 68880 | | - ** payload size, so it is impossible for u.ap.payloadSize64 to be |
| 68881 | | - ** larger than 32 bits. */ |
| 68882 | | - assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 ); |
| 68883 | | - u.ap.pC->aRow = sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail); |
| 68884 | | - u.ap.pC->payloadSize = (u32)u.ap.payloadSize64; |
| 68885 | | - }else{ |
| 68886 | | - assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); |
| 68887 | | - VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.pC->payloadSize); |
| 68888 | | - assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 68889 | | - u.ap.pC->aRow = sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail); |
| 68890 | | - } |
| 68891 | | - assert( u.ap.avail<=65536 ); /* Maximum page size is 64KiB */ |
| 68892 | | - if( u.ap.pC->payloadSize <= (u32)u.ap.avail ){ |
| 68893 | | - u.ap.pC->szRow = u.ap.pC->payloadSize; |
| 68894 | | - }else{ |
| 68895 | | - u.ap.pC->szRow = u.ap.avail; |
| 68896 | | - } |
| 68897 | | - if( u.ap.pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 68898 | | - goto too_big; |
| 68899 | | - } |
| 68900 | | - } |
| 68901 | | - u.ap.pC->cacheStatus = p->cacheCtr; |
| 68902 | | - u.ap.pC->iHdrOffset = getVarint32(u.ap.pC->aRow, u.ap.offset); |
| 68903 | | - u.ap.pC->nHdrParsed = 0; |
| 68904 | | - u.ap.aOffset[0] = u.ap.offset; |
| 68905 | | - if( u.ap.avail<u.ap.offset ){ |
| 68906 | | - /* u.ap.pC->aRow does not have to hold the entire row, but it does at least |
| 68907 | | - ** need to cover the header of the record. If u.ap.pC->aRow does not contain |
| 68908 | | - ** the complete header, then set it to zero, forcing the header to be |
| 68909 | | - ** dynamically allocated. */ |
| 68910 | | - u.ap.pC->aRow = 0; |
| 68911 | | - u.ap.pC->szRow = 0; |
| 68374 | + |
| 68375 | + p2 = pOp->p2; |
| 68376 | + assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68377 | + pDest = &aMem[pOp->p3]; |
| 68378 | + memAboutToChange(p, pDest); |
| 68379 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 68380 | + pC = p->apCsr[pOp->p1]; |
| 68381 | + assert( pC!=0 ); |
| 68382 | + assert( p2<pC->nField ); |
| 68383 | + aType = pC->aType; |
| 68384 | + aOffset = aType + pC->nField; |
| 68385 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 68386 | + assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ |
| 68387 | +#endif |
| 68388 | + pCrsr = pC->pCursor; |
| 68389 | + assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */ |
| 68390 | + assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */ |
| 68391 | + |
| 68392 | + /* If the cursor cache is stale, bring it up-to-date */ |
| 68393 | + rc = sqlite3VdbeCursorMoveto(pC); |
| 68394 | + if( rc ) goto abort_due_to_error; |
| 68395 | + if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){ |
| 68396 | + if( pC->nullRow ){ |
| 68397 | + if( pCrsr==0 ){ |
| 68398 | + assert( pC->pseudoTableReg>0 ); |
| 68399 | + pReg = &aMem[pC->pseudoTableReg]; |
| 68400 | + if( pC->multiPseudo ){ |
| 68401 | + sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem); |
| 68402 | + Deephemeralize(pDest); |
| 68403 | + goto op_column_out; |
| 68404 | + } |
| 68405 | + assert( pReg->flags & MEM_Blob ); |
| 68406 | + assert( memIsValid(pReg) ); |
| 68407 | + pC->payloadSize = pC->szRow = avail = pReg->n; |
| 68408 | + pC->aRow = (u8*)pReg->z; |
| 68409 | + }else{ |
| 68410 | + MemSetTypeFlag(pDest, MEM_Null); |
| 68411 | + goto op_column_out; |
| 68412 | + } |
| 68413 | + }else{ |
| 68414 | + assert( pCrsr ); |
| 68415 | + if( pC->isTable==0 ){ |
| 68416 | + assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 68417 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64); |
| 68418 | + assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 68419 | + /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the |
| 68420 | + ** payload size, so it is impossible for payloadSize64 to be |
| 68421 | + ** larger than 32 bits. */ |
| 68422 | + assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 ); |
| 68423 | + pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail); |
| 68424 | + pC->payloadSize = (u32)payloadSize64; |
| 68425 | + }else{ |
| 68426 | + assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 68427 | + VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize); |
| 68428 | + assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 68429 | + pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail); |
| 68430 | + } |
| 68431 | + assert( avail<=65536 ); /* Maximum page size is 64KiB */ |
| 68432 | + if( pC->payloadSize <= (u32)avail ){ |
| 68433 | + pC->szRow = pC->payloadSize; |
| 68434 | + }else{ |
| 68435 | + pC->szRow = avail; |
| 68436 | + } |
| 68437 | + if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 68438 | + goto too_big; |
| 68439 | + } |
| 68440 | + } |
| 68441 | + pC->cacheStatus = p->cacheCtr; |
| 68442 | + pC->iHdrOffset = getVarint32(pC->aRow, offset); |
| 68443 | + pC->nHdrParsed = 0; |
| 68444 | + aOffset[0] = offset; |
| 68445 | + if( avail<offset ){ |
| 68446 | + /* pC->aRow does not have to hold the entire row, but it does at least |
| 68447 | + ** need to cover the header of the record. If pC->aRow does not contain |
| 68448 | + ** the complete header, then set it to zero, forcing the header to be |
| 68449 | + ** dynamically allocated. */ |
| 68450 | + pC->aRow = 0; |
| 68451 | + pC->szRow = 0; |
| 68912 | 68452 | } |
| 68913 | 68453 | |
| 68914 | 68454 | /* Make sure a corrupt database has not given us an oversize header. |
| 68915 | 68455 | ** Do this now to avoid an oversize memory allocation. |
| 68916 | 68456 | ** |
| | @@ -68918,154 +68458,154 @@ |
| 68918 | 68458 | ** types use so much data space that there can only be 4096 and 32 of |
| 68919 | 68459 | ** them, respectively. So the maximum header length results from a |
| 68920 | 68460 | ** 3-byte type for each of the maximum of 32768 columns plus three |
| 68921 | 68461 | ** extra bytes for the header length itself. 32768*3 + 3 = 98307. |
| 68922 | 68462 | */ |
| 68923 | | - if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){ |
| 68463 | + if( offset > 98307 || offset > pC->payloadSize ){ |
| 68924 | 68464 | rc = SQLITE_CORRUPT_BKPT; |
| 68925 | 68465 | goto op_column_error; |
| 68926 | 68466 | } |
| 68927 | 68467 | } |
| 68928 | 68468 | |
| 68929 | | - /* Make sure at least the first u.ap.p2+1 entries of the header have been |
| 68930 | | - ** parsed and valid information is in u.ap.aOffset[] and u.ap.aType[]. |
| 68469 | + /* Make sure at least the first p2+1 entries of the header have been |
| 68470 | + ** parsed and valid information is in aOffset[] and aType[]. |
| 68931 | 68471 | */ |
| 68932 | | - if( u.ap.pC->nHdrParsed<=u.ap.p2 ){ |
| 68472 | + if( pC->nHdrParsed<=p2 ){ |
| 68933 | 68473 | /* If there is more header available for parsing in the record, try |
| 68934 | | - ** to extract additional fields up through the u.ap.p2+1-th field |
| 68474 | + ** to extract additional fields up through the p2+1-th field |
| 68935 | 68475 | */ |
| 68936 | | - if( u.ap.pC->iHdrOffset<u.ap.aOffset[0] ){ |
| 68937 | | - /* Make sure u.ap.zData points to enough of the record to cover the header. */ |
| 68938 | | - if( u.ap.pC->aRow==0 ){ |
| 68939 | | - memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); |
| 68940 | | - rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.aOffset[0], |
| 68941 | | - !u.ap.pC->isTable, &u.ap.sMem); |
| 68476 | + if( pC->iHdrOffset<aOffset[0] ){ |
| 68477 | + /* Make sure zData points to enough of the record to cover the header. */ |
| 68478 | + if( pC->aRow==0 ){ |
| 68479 | + memset(&sMem, 0, sizeof(sMem)); |
| 68480 | + rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], |
| 68481 | + !pC->isTable, &sMem); |
| 68942 | 68482 | if( rc!=SQLITE_OK ){ |
| 68943 | 68483 | goto op_column_error; |
| 68944 | 68484 | } |
| 68945 | | - u.ap.zData = (u8*)u.ap.sMem.z; |
| 68485 | + zData = (u8*)sMem.z; |
| 68946 | 68486 | }else{ |
| 68947 | | - u.ap.zData = u.ap.pC->aRow; |
| 68948 | | - } |
| 68949 | | - |
| 68950 | | - /* Fill in u.ap.aType[u.ap.i] and u.ap.aOffset[u.ap.i] values through the u.ap.p2-th field. */ |
| 68951 | | - u.ap.i = u.ap.pC->nHdrParsed; |
| 68952 | | - u.ap.offset = u.ap.aOffset[u.ap.i]; |
| 68953 | | - u.ap.zHdr = u.ap.zData + u.ap.pC->iHdrOffset; |
| 68954 | | - u.ap.zEndHdr = u.ap.zData + u.ap.aOffset[0]; |
| 68955 | | - assert( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr ); |
| 68487 | + zData = pC->aRow; |
| 68488 | + } |
| 68489 | + |
| 68490 | + /* Fill in aType[i] and aOffset[i] values through the p2-th field. */ |
| 68491 | + i = pC->nHdrParsed; |
| 68492 | + offset = aOffset[i]; |
| 68493 | + zHdr = zData + pC->iHdrOffset; |
| 68494 | + zEndHdr = zData + aOffset[0]; |
| 68495 | + assert( i<=p2 && zHdr<zEndHdr ); |
| 68956 | 68496 | do{ |
| 68957 | | - if( u.ap.zHdr[0]<0x80 ){ |
| 68958 | | - u.ap.t = u.ap.zHdr[0]; |
| 68959 | | - u.ap.zHdr++; |
| 68497 | + if( zHdr[0]<0x80 ){ |
| 68498 | + t = zHdr[0]; |
| 68499 | + zHdr++; |
| 68960 | 68500 | }else{ |
| 68961 | | - u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t); |
| 68501 | + zHdr += sqlite3GetVarint32(zHdr, &t); |
| 68962 | 68502 | } |
| 68963 | | - u.ap.aType[u.ap.i] = u.ap.t; |
| 68964 | | - u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t); |
| 68965 | | - u.ap.offset += u.ap.szField; |
| 68966 | | - if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */ |
| 68967 | | - u.ap.zHdr = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 68503 | + aType[i] = t; |
| 68504 | + szField = sqlite3VdbeSerialTypeLen(t); |
| 68505 | + offset += szField; |
| 68506 | + if( offset<szField ){ /* True if offset overflows */ |
| 68507 | + zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 68968 | 68508 | break; |
| 68969 | 68509 | } |
| 68970 | | - u.ap.i++; |
| 68971 | | - u.ap.aOffset[u.ap.i] = u.ap.offset; |
| 68972 | | - }while( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr ); |
| 68973 | | - u.ap.pC->nHdrParsed = u.ap.i; |
| 68974 | | - u.ap.pC->iHdrOffset = (u32)(u.ap.zHdr - u.ap.zData); |
| 68975 | | - if( u.ap.pC->aRow==0 ){ |
| 68976 | | - sqlite3VdbeMemRelease(&u.ap.sMem); |
| 68977 | | - u.ap.sMem.flags = MEM_Null; |
| 68978 | | - } |
| 68979 | | - |
| 68510 | + i++; |
| 68511 | + aOffset[i] = offset; |
| 68512 | + }while( i<=p2 && zHdr<zEndHdr ); |
| 68513 | + pC->nHdrParsed = i; |
| 68514 | + pC->iHdrOffset = (u32)(zHdr - zData); |
| 68515 | + if( pC->aRow==0 ){ |
| 68516 | + sqlite3VdbeMemRelease(&sMem); |
| 68517 | + sMem.flags = MEM_Null; |
| 68518 | + } |
| 68519 | + |
| 68980 | 68520 | /* If we have read more header data than was contained in the header, |
| 68981 | 68521 | ** or if the end of the last field appears to be past the end of the |
| 68982 | 68522 | ** record, or if the end of the last field appears to be before the end |
| 68983 | | - ** of the record (when all fields present), then we must be dealing |
| 68523 | + ** of the record (when all fields present), then we must be dealing |
| 68984 | 68524 | ** with a corrupt database. |
| 68985 | 68525 | */ |
| 68986 | | - if( (u.ap.zHdr > u.ap.zEndHdr) |
| 68987 | | - || (u.ap.offset > u.ap.pC->payloadSize) |
| 68988 | | - || (u.ap.zHdr==u.ap.zEndHdr && u.ap.offset!=u.ap.pC->payloadSize) |
| 68526 | + if( (zHdr > zEndHdr) |
| 68527 | + || (offset > pC->payloadSize) |
| 68528 | + || (zHdr==zEndHdr && offset!=pC->payloadSize) |
| 68989 | 68529 | ){ |
| 68990 | 68530 | rc = SQLITE_CORRUPT_BKPT; |
| 68991 | 68531 | goto op_column_error; |
| 68992 | 68532 | } |
| 68993 | 68533 | } |
| 68994 | 68534 | |
| 68995 | 68535 | /* If after trying to extra new entries from the header, nHdrParsed is |
| 68996 | | - ** still not up to u.ap.p2, that means that the record has fewer than u.ap.p2 |
| 68536 | + ** still not up to p2, that means that the record has fewer than p2 |
| 68997 | 68537 | ** columns. So the result will be either the default value or a NULL. |
| 68998 | 68538 | */ |
| 68999 | | - if( u.ap.pC->nHdrParsed<=u.ap.p2 ){ |
| 68539 | + if( pC->nHdrParsed<=p2 ){ |
| 69000 | 68540 | if( pOp->p4type==P4_MEM ){ |
| 69001 | | - sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static); |
| 68541 | + sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); |
| 69002 | 68542 | }else{ |
| 69003 | | - MemSetTypeFlag(u.ap.pDest, MEM_Null); |
| 68543 | + MemSetTypeFlag(pDest, MEM_Null); |
| 69004 | 68544 | } |
| 69005 | 68545 | goto op_column_out; |
| 69006 | 68546 | } |
| 69007 | 68547 | } |
| 69008 | 68548 | |
| 69009 | | - /* Extract the content for the u.ap.p2+1-th column. Control can only |
| 69010 | | - ** reach this point if u.ap.aOffset[u.ap.p2], u.ap.aOffset[u.ap.p2+1], and u.ap.aType[u.ap.p2] are |
| 68549 | + /* Extract the content for the p2+1-th column. Control can only |
| 68550 | + ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are |
| 69011 | 68551 | ** all valid. |
| 69012 | 68552 | */ |
| 69013 | | - assert( u.ap.p2<u.ap.pC->nHdrParsed ); |
| 68553 | + assert( p2<pC->nHdrParsed ); |
| 69014 | 68554 | assert( rc==SQLITE_OK ); |
| 69015 | | - if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){ |
| 68555 | + if( pC->szRow>=aOffset[p2+1] ){ |
| 69016 | 68556 | /* This is the common case where the desired content fits on the original |
| 69017 | 68557 | ** page - where the content is not on an overflow page */ |
| 69018 | | - VdbeMemRelease(u.ap.pDest); |
| 69019 | | - sqlite3VdbeSerialGet(u.ap.pC->aRow+u.ap.aOffset[u.ap.p2], u.ap.aType[u.ap.p2], u.ap.pDest); |
| 68558 | + VdbeMemRelease(pDest); |
| 68559 | + sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest); |
| 69020 | 68560 | }else{ |
| 69021 | | - /* This branch happens only when content is on overflow pages */ |
| 69022 | | - u.ap.t = u.ap.aType[u.ap.p2]; |
| 68561 | + /* This branch happens only when content is on overflow pages */ |
| 68562 | + t = aType[p2]; |
| 69023 | 68563 | if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 69024 | | - && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) |
| 69025 | | - || (u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t))==0 |
| 68564 | + && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) |
| 68565 | + || (len = sqlite3VdbeSerialTypeLen(t))==0 |
| 69026 | 68566 | ){ |
| 69027 | 68567 | /* Content is irrelevant for the typeof() function and for |
| 69028 | 68568 | ** the length(X) function if X is a blob. So we might as well use |
| 69029 | 68569 | ** bogus content rather than reading content from disk. NULL works |
| 69030 | | - ** for text and blob and whatever is in the u.ap.payloadSize64 variable |
| 68570 | + ** for text and blob and whatever is in the payloadSize64 variable |
| 69031 | 68571 | ** will work for everything else. Content is also irrelevant if |
| 69032 | 68572 | ** the content length is 0. */ |
| 69033 | | - u.ap.zData = u.ap.t<=13 ? (u8*)&u.ap.payloadSize64 : 0; |
| 69034 | | - u.ap.sMem.zMalloc = 0; |
| 68573 | + zData = t<=13 ? (u8*)&payloadSize64 : 0; |
| 68574 | + sMem.zMalloc = 0; |
| 69035 | 68575 | }else{ |
| 69036 | | - memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); |
| 69037 | | - sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest); |
| 69038 | | - rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, !u.ap.pC->isTable, |
| 69039 | | - &u.ap.sMem); |
| 68576 | + memset(&sMem, 0, sizeof(sMem)); |
| 68577 | + sqlite3VdbeMemMove(&sMem, pDest); |
| 68578 | + rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable, |
| 68579 | + &sMem); |
| 69040 | 68580 | if( rc!=SQLITE_OK ){ |
| 69041 | 68581 | goto op_column_error; |
| 69042 | 68582 | } |
| 69043 | | - u.ap.zData = (u8*)u.ap.sMem.z; |
| 68583 | + zData = (u8*)sMem.z; |
| 69044 | 68584 | } |
| 69045 | | - sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest); |
| 68585 | + sqlite3VdbeSerialGet(zData, t, pDest); |
| 69046 | 68586 | /* If we dynamically allocated space to hold the data (in the |
| 69047 | 68587 | ** sqlite3VdbeMemFromBtree() call above) then transfer control of that |
| 69048 | | - ** dynamically allocated space over to the u.ap.pDest structure. |
| 68588 | + ** dynamically allocated space over to the pDest structure. |
| 69049 | 68589 | ** This prevents a memory copy. */ |
| 69050 | | - if( u.ap.sMem.zMalloc ){ |
| 69051 | | - assert( u.ap.sMem.z==u.ap.sMem.zMalloc ); |
| 69052 | | - assert( !(u.ap.pDest->flags & MEM_Dyn) ); |
| 69053 | | - assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z ); |
| 69054 | | - u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static); |
| 69055 | | - u.ap.pDest->flags |= MEM_Term; |
| 69056 | | - u.ap.pDest->z = u.ap.sMem.z; |
| 69057 | | - u.ap.pDest->zMalloc = u.ap.sMem.zMalloc; |
| 68590 | + if( sMem.zMalloc ){ |
| 68591 | + assert( sMem.z==sMem.zMalloc ); |
| 68592 | + assert( !(pDest->flags & MEM_Dyn) ); |
| 68593 | + assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z ); |
| 68594 | + pDest->flags &= ~(MEM_Ephem|MEM_Static); |
| 68595 | + pDest->flags |= MEM_Term; |
| 68596 | + pDest->z = sMem.z; |
| 68597 | + pDest->zMalloc = sMem.zMalloc; |
| 69058 | 68598 | } |
| 69059 | 68599 | } |
| 69060 | | - u.ap.pDest->enc = encoding; |
| 68600 | + pDest->enc = encoding; |
| 69061 | 68601 | |
| 69062 | 68602 | op_column_out: |
| 69063 | | - rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest); |
| 68603 | + Deephemeralize(pDest); |
| 69064 | 68604 | op_column_error: |
| 69065 | | - UPDATE_MAX_BLOBSIZE(u.ap.pDest); |
| 69066 | | - REGISTER_TRACE(pOp->p3, u.ap.pDest); |
| 68605 | + UPDATE_MAX_BLOBSIZE(pDest); |
| 68606 | + REGISTER_TRACE(pOp->p3, pDest); |
| 69067 | 68607 | break; |
| 69068 | 68608 | } |
| 69069 | 68609 | |
| 69070 | 68610 | /* Opcode: Affinity P1 P2 * P4 * |
| 69071 | 68611 | ** Synopsis: affinity(r[P1@P2]) |
| | @@ -69075,24 +68615,22 @@ |
| 69075 | 68615 | ** P4 is a string that is P2 characters long. The nth character of the |
| 69076 | 68616 | ** string indicates the column affinity that should be used for the nth |
| 69077 | 68617 | ** memory cell in the range. |
| 69078 | 68618 | */ |
| 69079 | 68619 | case OP_Affinity: { |
| 69080 | | -#if 0 /* local variables moved into u.aq */ |
| 69081 | 68620 | const char *zAffinity; /* The affinity to be applied */ |
| 69082 | 68621 | char cAff; /* A single character of affinity */ |
| 69083 | | -#endif /* local variables moved into u.aq */ |
| 69084 | 68622 | |
| 69085 | | - u.aq.zAffinity = pOp->p4.z; |
| 69086 | | - assert( u.aq.zAffinity!=0 ); |
| 69087 | | - assert( u.aq.zAffinity[pOp->p2]==0 ); |
| 68623 | + zAffinity = pOp->p4.z; |
| 68624 | + assert( zAffinity!=0 ); |
| 68625 | + assert( zAffinity[pOp->p2]==0 ); |
| 69088 | 68626 | pIn1 = &aMem[pOp->p1]; |
| 69089 | | - while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){ |
| 68627 | + while( (cAff = *(zAffinity++))!=0 ){ |
| 69090 | 68628 | assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] ); |
| 69091 | 68629 | assert( memIsValid(pIn1) ); |
| 69092 | 68630 | ExpandBlob(pIn1); |
| 69093 | | - applyAffinity(pIn1, u.aq.cAff, encoding); |
| 68631 | + applyAffinity(pIn1, cAff, encoding); |
| 69094 | 68632 | pIn1++; |
| 69095 | 68633 | } |
| 69096 | 68634 | break; |
| 69097 | 68635 | } |
| 69098 | 68636 | |
| | @@ -69111,11 +68649,10 @@ |
| 69111 | 68649 | ** macros defined in sqliteInt.h. |
| 69112 | 68650 | ** |
| 69113 | 68651 | ** If P4 is NULL then all index fields have the affinity NONE. |
| 69114 | 68652 | */ |
| 69115 | 68653 | case OP_MakeRecord: { |
| 69116 | | -#if 0 /* local variables moved into u.ar */ |
| 69117 | 68654 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 69118 | 68655 | Mem *pRec; /* The new record */ |
| 69119 | 68656 | u64 nData; /* Number of bytes of data space */ |
| 69120 | 68657 | int nHdr; /* Number of bytes of header space */ |
| 69121 | 68658 | i64 nByte; /* Data space required for this record */ |
| | @@ -69125,106 +68662,123 @@ |
| 69125 | 68662 | Mem *pData0; /* First field to be combined into the record */ |
| 69126 | 68663 | Mem *pLast; /* Last field of the record */ |
| 69127 | 68664 | int nField; /* Number of fields in the record */ |
| 69128 | 68665 | char *zAffinity; /* The affinity string for the record */ |
| 69129 | 68666 | int file_format; /* File format to use for encoding */ |
| 69130 | | - int i; /* Space used in zNewRecord[] */ |
| 68667 | + int i; /* Space used in zNewRecord[] header */ |
| 68668 | + int j; /* Space used in zNewRecord[] content */ |
| 69131 | 68669 | int len; /* Length of a field */ |
| 69132 | | -#endif /* local variables moved into u.ar */ |
| 69133 | 68670 | |
| 69134 | 68671 | /* Assuming the record contains N fields, the record format looks |
| 69135 | 68672 | ** like this: |
| 69136 | 68673 | ** |
| 69137 | 68674 | ** ------------------------------------------------------------------------ |
| 69138 | | - ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | |
| 68675 | + ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | |
| 69139 | 68676 | ** ------------------------------------------------------------------------ |
| 69140 | 68677 | ** |
| 69141 | 68678 | ** Data(0) is taken from register P1. Data(1) comes from register P1+1 |
| 69142 | 68679 | ** and so froth. |
| 69143 | 68680 | ** |
| 69144 | | - ** Each type field is a varint representing the serial type of the |
| 68681 | + ** Each type field is a varint representing the serial type of the |
| 69145 | 68682 | ** corresponding data element (see sqlite3VdbeSerialType()). The |
| 69146 | 68683 | ** hdr-size field is also a varint which is the offset from the beginning |
| 69147 | 68684 | ** of the record to data0. |
| 69148 | 68685 | */ |
| 69149 | | - u.ar.nData = 0; /* Number of bytes of data space */ |
| 69150 | | - u.ar.nHdr = 0; /* Number of bytes of header space */ |
| 69151 | | - u.ar.nZero = 0; /* Number of zero bytes at the end of the record */ |
| 69152 | | - u.ar.nField = pOp->p1; |
| 69153 | | - u.ar.zAffinity = pOp->p4.z; |
| 69154 | | - assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 ); |
| 69155 | | - u.ar.pData0 = &aMem[u.ar.nField]; |
| 69156 | | - u.ar.nField = pOp->p2; |
| 69157 | | - u.ar.pLast = &u.ar.pData0[u.ar.nField-1]; |
| 69158 | | - u.ar.file_format = p->minWriteFileFormat; |
| 68686 | + nData = 0; /* Number of bytes of data space */ |
| 68687 | + nHdr = 0; /* Number of bytes of header space */ |
| 68688 | + nZero = 0; /* Number of zero bytes at the end of the record */ |
| 68689 | + nField = pOp->p1; |
| 68690 | + zAffinity = pOp->p4.z; |
| 68691 | + assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem-p->nCursor)+1 ); |
| 68692 | + pData0 = &aMem[nField]; |
| 68693 | + nField = pOp->p2; |
| 68694 | + pLast = &pData0[nField-1]; |
| 68695 | + file_format = p->minWriteFileFormat; |
| 69159 | 68696 | |
| 69160 | 68697 | /* Identify the output register */ |
| 69161 | 68698 | assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); |
| 69162 | 68699 | pOut = &aMem[pOp->p3]; |
| 69163 | 68700 | memAboutToChange(p, pOut); |
| 68701 | + |
| 68702 | + /* Apply the requested affinity to all inputs |
| 68703 | + */ |
| 68704 | + assert( pData0<=pLast ); |
| 68705 | + if( zAffinity ){ |
| 68706 | + pRec = pData0; |
| 68707 | + do{ |
| 68708 | + applyAffinity(pRec, *(zAffinity++), encoding); |
| 68709 | + }while( (++pRec)<=pLast ); |
| 68710 | + } |
| 69164 | 68711 | |
| 69165 | 68712 | /* Loop through the elements that will make up the record to figure |
| 69166 | 68713 | ** out how much space is required for the new record. |
| 69167 | 68714 | */ |
| 69168 | | - for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ |
| 69169 | | - assert( memIsValid(u.ar.pRec) ); |
| 69170 | | - if( u.ar.zAffinity ){ |
| 69171 | | - applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding); |
| 69172 | | - } |
| 69173 | | - if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){ |
| 69174 | | - sqlite3VdbeMemExpandBlob(u.ar.pRec); |
| 69175 | | - } |
| 69176 | | - u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format); |
| 69177 | | - u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type); |
| 69178 | | - u.ar.nData += u.ar.len; |
| 69179 | | - u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type); |
| 69180 | | - if( u.ar.pRec->flags & MEM_Zero ){ |
| 69181 | | - /* Only pure zero-filled BLOBs can be input to this Opcode. |
| 69182 | | - ** We do not allow blobs with a prefix and a zero-filled tail. */ |
| 69183 | | - u.ar.nZero += u.ar.pRec->u.nZero; |
| 69184 | | - }else if( u.ar.len ){ |
| 69185 | | - u.ar.nZero = 0; |
| 69186 | | - } |
| 69187 | | - } |
| 68715 | + pRec = pLast; |
| 68716 | + do{ |
| 68717 | + assert( memIsValid(pRec) ); |
| 68718 | + serial_type = sqlite3VdbeSerialType(pRec, file_format); |
| 68719 | + len = sqlite3VdbeSerialTypeLen(serial_type); |
| 68720 | + if( pRec->flags & MEM_Zero ){ |
| 68721 | + if( nData ){ |
| 68722 | + sqlite3VdbeMemExpandBlob(pRec); |
| 68723 | + }else{ |
| 68724 | + nZero += pRec->u.nZero; |
| 68725 | + len -= pRec->u.nZero; |
| 68726 | + } |
| 68727 | + } |
| 68728 | + nData += len; |
| 68729 | + testcase( serial_type==127 ); |
| 68730 | + testcase( serial_type==128 ); |
| 68731 | + nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type); |
| 68732 | + }while( (--pRec)>=pData0 ); |
| 69188 | 68733 | |
| 69189 | 68734 | /* Add the initial header varint and total the size */ |
| 69190 | | - u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr); |
| 69191 | | - if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){ |
| 69192 | | - u.ar.nHdr++; |
| 68735 | + testcase( nHdr==126 ); |
| 68736 | + testcase( nHdr==127 ); |
| 68737 | + if( nHdr<=126 ){ |
| 68738 | + /* The common case */ |
| 68739 | + nHdr += 1; |
| 68740 | + }else{ |
| 68741 | + /* Rare case of a really large header */ |
| 68742 | + nVarint = sqlite3VarintLen(nHdr); |
| 68743 | + nHdr += nVarint; |
| 68744 | + if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; |
| 69193 | 68745 | } |
| 69194 | | - u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero; |
| 69195 | | - if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 68746 | + nByte = nHdr+nData; |
| 68747 | + if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 69196 | 68748 | goto too_big; |
| 69197 | 68749 | } |
| 69198 | 68750 | |
| 69199 | | - /* Make sure the output register has a buffer large enough to store |
| 68751 | + /* Make sure the output register has a buffer large enough to store |
| 69200 | 68752 | ** the new record. The output register (pOp->p3) is not allowed to |
| 69201 | 68753 | ** be one of the input registers (because the following call to |
| 69202 | 68754 | ** sqlite3VdbeMemGrow() could clobber the value before it is used). |
| 69203 | 68755 | */ |
| 69204 | | - if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){ |
| 68756 | + if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){ |
| 69205 | 68757 | goto no_mem; |
| 69206 | 68758 | } |
| 69207 | | - u.ar.zNewRecord = (u8 *)pOut->z; |
| 68759 | + zNewRecord = (u8 *)pOut->z; |
| 69208 | 68760 | |
| 69209 | 68761 | /* Write the record */ |
| 69210 | | - u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr); |
| 69211 | | - for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ |
| 69212 | | - u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format); |
| 69213 | | - u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */ |
| 69214 | | - } |
| 69215 | | - for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */ |
| 69216 | | - u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format); |
| 69217 | | - } |
| 69218 | | - assert( u.ar.i==u.ar.nByte ); |
| 68762 | + i = putVarint32(zNewRecord, nHdr); |
| 68763 | + j = nHdr; |
| 68764 | + assert( pData0<=pLast ); |
| 68765 | + pRec = pData0; |
| 68766 | + do{ |
| 68767 | + serial_type = sqlite3VdbeSerialType(pRec, file_format); |
| 68768 | + i += putVarint32(&zNewRecord[i], serial_type); /* serial type */ |
| 68769 | + j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */ |
| 68770 | + }while( (++pRec)<=pLast ); |
| 68771 | + assert( i==nHdr ); |
| 68772 | + assert( j==nByte ); |
| 69219 | 68773 | |
| 69220 | 68774 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 69221 | | - pOut->n = (int)u.ar.nByte; |
| 68775 | + pOut->n = (int)nByte; |
| 69222 | 68776 | pOut->flags = MEM_Blob | MEM_Dyn; |
| 69223 | 68777 | pOut->xDel = 0; |
| 69224 | | - if( u.ar.nZero ){ |
| 69225 | | - pOut->u.nZero = u.ar.nZero; |
| 68778 | + if( nZero ){ |
| 68779 | + pOut->u.nZero = nZero; |
| 69226 | 68780 | pOut->flags |= MEM_Zero; |
| 69227 | 68781 | } |
| 69228 | 68782 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ |
| 69229 | 68783 | REGISTER_TRACE(pOp->p3, pOut); |
| 69230 | 68784 | UPDATE_MAX_BLOBSIZE(pOut); |
| | @@ -69237,19 +68791,18 @@ |
| 69237 | 68791 | ** Store the number of entries (an integer value) in the table or index |
| 69238 | 68792 | ** opened by cursor P1 in register P2 |
| 69239 | 68793 | */ |
| 69240 | 68794 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 69241 | 68795 | case OP_Count: { /* out2-prerelease */ |
| 69242 | | -#if 0 /* local variables moved into u.as */ |
| 69243 | 68796 | i64 nEntry; |
| 69244 | 68797 | BtCursor *pCrsr; |
| 69245 | | -#endif /* local variables moved into u.as */ |
| 69246 | 68798 | |
| 69247 | | - u.as.pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 69248 | | - assert( u.as.pCrsr ); |
| 69249 | | - rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry); |
| 69250 | | - pOut->u.i = u.as.nEntry; |
| 68799 | + pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 68800 | + assert( pCrsr ); |
| 68801 | + nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 68802 | + rc = sqlite3BtreeCount(pCrsr, &nEntry); |
| 68803 | + pOut->u.i = nEntry; |
| 69251 | 68804 | break; |
| 69252 | 68805 | } |
| 69253 | 68806 | #endif |
| 69254 | 68807 | |
| 69255 | 68808 | /* Opcode: Savepoint P1 * * P4 * |
| | @@ -69257,43 +68810,41 @@ |
| 69257 | 68810 | ** Open, release or rollback the savepoint named by parameter P4, depending |
| 69258 | 68811 | ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an |
| 69259 | 68812 | ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2. |
| 69260 | 68813 | */ |
| 69261 | 68814 | case OP_Savepoint: { |
| 69262 | | -#if 0 /* local variables moved into u.at */ |
| 69263 | 68815 | int p1; /* Value of P1 operand */ |
| 69264 | 68816 | char *zName; /* Name of savepoint */ |
| 69265 | 68817 | int nName; |
| 69266 | 68818 | Savepoint *pNew; |
| 69267 | 68819 | Savepoint *pSavepoint; |
| 69268 | 68820 | Savepoint *pTmp; |
| 69269 | 68821 | int iSavepoint; |
| 69270 | 68822 | int ii; |
| 69271 | | -#endif /* local variables moved into u.at */ |
| 69272 | 68823 | |
| 69273 | | - u.at.p1 = pOp->p1; |
| 69274 | | - u.at.zName = pOp->p4.z; |
| 68824 | + p1 = pOp->p1; |
| 68825 | + zName = pOp->p4.z; |
| 69275 | 68826 | |
| 69276 | | - /* Assert that the u.at.p1 parameter is valid. Also that if there is no open |
| 69277 | | - ** transaction, then there cannot be any savepoints. |
| 68827 | + /* Assert that the p1 parameter is valid. Also that if there is no open |
| 68828 | + ** transaction, then there cannot be any savepoints. |
| 69278 | 68829 | */ |
| 69279 | 68830 | assert( db->pSavepoint==0 || db->autoCommit==0 ); |
| 69280 | | - assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK ); |
| 68831 | + assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK ); |
| 69281 | 68832 | assert( db->pSavepoint || db->isTransactionSavepoint==0 ); |
| 69282 | 68833 | assert( checkSavepointCount(db) ); |
| 69283 | 68834 | assert( p->bIsReader ); |
| 69284 | 68835 | |
| 69285 | | - if( u.at.p1==SAVEPOINT_BEGIN ){ |
| 68836 | + if( p1==SAVEPOINT_BEGIN ){ |
| 69286 | 68837 | if( db->nVdbeWrite>0 ){ |
| 69287 | | - /* A new savepoint cannot be created if there are active write |
| 68838 | + /* A new savepoint cannot be created if there are active write |
| 69288 | 68839 | ** statements (i.e. open read/write incremental blob handles). |
| 69289 | 68840 | */ |
| 69290 | 68841 | sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - " |
| 69291 | 68842 | "SQL statements in progress"); |
| 69292 | 68843 | rc = SQLITE_BUSY; |
| 69293 | 68844 | }else{ |
| 69294 | | - u.at.nName = sqlite3Strlen30(u.at.zName); |
| 68845 | + nName = sqlite3Strlen30(zName); |
| 69295 | 68846 | |
| 69296 | 68847 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 69297 | 68848 | /* This call is Ok even if this savepoint is actually a transaction |
| 69298 | 68849 | ** savepoint (and therefore should not prompt xSavepoint()) callbacks. |
| 69299 | 68850 | ** If this is a transaction savepoint being opened, it is guaranteed |
| | @@ -69303,62 +68854,62 @@ |
| 69303 | 68854 | db->nStatement+db->nSavepoint); |
| 69304 | 68855 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69305 | 68856 | #endif |
| 69306 | 68857 | |
| 69307 | 68858 | /* Create a new savepoint structure. */ |
| 69308 | | - u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1); |
| 69309 | | - if( u.at.pNew ){ |
| 69310 | | - u.at.pNew->zName = (char *)&u.at.pNew[1]; |
| 69311 | | - memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1); |
| 69312 | | - |
| 68859 | + pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1); |
| 68860 | + if( pNew ){ |
| 68861 | + pNew->zName = (char *)&pNew[1]; |
| 68862 | + memcpy(pNew->zName, zName, nName+1); |
| 68863 | + |
| 69313 | 68864 | /* If there is no open transaction, then mark this as a special |
| 69314 | 68865 | ** "transaction savepoint". */ |
| 69315 | 68866 | if( db->autoCommit ){ |
| 69316 | 68867 | db->autoCommit = 0; |
| 69317 | 68868 | db->isTransactionSavepoint = 1; |
| 69318 | 68869 | }else{ |
| 69319 | 68870 | db->nSavepoint++; |
| 69320 | 68871 | } |
| 69321 | | - |
| 68872 | + |
| 69322 | 68873 | /* Link the new savepoint into the database handle's list. */ |
| 69323 | | - u.at.pNew->pNext = db->pSavepoint; |
| 69324 | | - db->pSavepoint = u.at.pNew; |
| 69325 | | - u.at.pNew->nDeferredCons = db->nDeferredCons; |
| 69326 | | - u.at.pNew->nDeferredImmCons = db->nDeferredImmCons; |
| 68874 | + pNew->pNext = db->pSavepoint; |
| 68875 | + db->pSavepoint = pNew; |
| 68876 | + pNew->nDeferredCons = db->nDeferredCons; |
| 68877 | + pNew->nDeferredImmCons = db->nDeferredImmCons; |
| 69327 | 68878 | } |
| 69328 | 68879 | } |
| 69329 | 68880 | }else{ |
| 69330 | | - u.at.iSavepoint = 0; |
| 68881 | + iSavepoint = 0; |
| 69331 | 68882 | |
| 69332 | 68883 | /* Find the named savepoint. If there is no such savepoint, then an |
| 69333 | 68884 | ** an error is returned to the user. */ |
| 69334 | 68885 | for( |
| 69335 | | - u.at.pSavepoint = db->pSavepoint; |
| 69336 | | - u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName); |
| 69337 | | - u.at.pSavepoint = u.at.pSavepoint->pNext |
| 68886 | + pSavepoint = db->pSavepoint; |
| 68887 | + pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName); |
| 68888 | + pSavepoint = pSavepoint->pNext |
| 69338 | 68889 | ){ |
| 69339 | | - u.at.iSavepoint++; |
| 68890 | + iSavepoint++; |
| 69340 | 68891 | } |
| 69341 | | - if( !u.at.pSavepoint ){ |
| 69342 | | - sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName); |
| 68892 | + if( !pSavepoint ){ |
| 68893 | + sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName); |
| 69343 | 68894 | rc = SQLITE_ERROR; |
| 69344 | | - }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){ |
| 69345 | | - /* It is not possible to release (commit) a savepoint if there are |
| 68895 | + }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){ |
| 68896 | + /* It is not possible to release (commit) a savepoint if there are |
| 69346 | 68897 | ** active write statements. |
| 69347 | 68898 | */ |
| 69348 | | - sqlite3SetString(&p->zErrMsg, db, |
| 68899 | + sqlite3SetString(&p->zErrMsg, db, |
| 69349 | 68900 | "cannot release savepoint - SQL statements in progress" |
| 69350 | 68901 | ); |
| 69351 | 68902 | rc = SQLITE_BUSY; |
| 69352 | 68903 | }else{ |
| 69353 | 68904 | |
| 69354 | 68905 | /* Determine whether or not this is a transaction savepoint. If so, |
| 69355 | | - ** and this is a RELEASE command, then the current transaction |
| 69356 | | - ** is committed. |
| 68906 | + ** and this is a RELEASE command, then the current transaction |
| 68907 | + ** is committed. |
| 69357 | 68908 | */ |
| 69358 | | - int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint; |
| 69359 | | - if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){ |
| 68909 | + int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint; |
| 68910 | + if( isTransaction && p1==SAVEPOINT_RELEASE ){ |
| 69360 | 68911 | if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 69361 | 68912 | goto vdbe_return; |
| 69362 | 68913 | } |
| 69363 | 68914 | db->autoCommit = 1; |
| 69364 | 68915 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| | @@ -69368,56 +68919,56 @@ |
| 69368 | 68919 | goto vdbe_return; |
| 69369 | 68920 | } |
| 69370 | 68921 | db->isTransactionSavepoint = 0; |
| 69371 | 68922 | rc = p->rc; |
| 69372 | 68923 | }else{ |
| 69373 | | - u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1; |
| 69374 | | - if( u.at.p1==SAVEPOINT_ROLLBACK ){ |
| 69375 | | - for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){ |
| 69376 | | - sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT); |
| 68924 | + iSavepoint = db->nSavepoint - iSavepoint - 1; |
| 68925 | + if( p1==SAVEPOINT_ROLLBACK ){ |
| 68926 | + for(ii=0; ii<db->nDb; ii++){ |
| 68927 | + sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT); |
| 69377 | 68928 | } |
| 69378 | 68929 | } |
| 69379 | | - for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){ |
| 69380 | | - rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint); |
| 68930 | + for(ii=0; ii<db->nDb; ii++){ |
| 68931 | + rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint); |
| 69381 | 68932 | if( rc!=SQLITE_OK ){ |
| 69382 | 68933 | goto abort_due_to_error; |
| 69383 | 68934 | } |
| 69384 | 68935 | } |
| 69385 | | - if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 68936 | + if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 69386 | 68937 | sqlite3ExpirePreparedStatements(db); |
| 69387 | 68938 | sqlite3ResetAllSchemasOfConnection(db); |
| 69388 | 68939 | db->flags = (db->flags | SQLITE_InternChanges); |
| 69389 | 68940 | } |
| 69390 | 68941 | } |
| 69391 | | - |
| 69392 | | - /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| 68942 | + |
| 68943 | + /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| 69393 | 68944 | ** savepoints nested inside of the savepoint being operated on. */ |
| 69394 | | - while( db->pSavepoint!=u.at.pSavepoint ){ |
| 69395 | | - u.at.pTmp = db->pSavepoint; |
| 69396 | | - db->pSavepoint = u.at.pTmp->pNext; |
| 69397 | | - sqlite3DbFree(db, u.at.pTmp); |
| 68945 | + while( db->pSavepoint!=pSavepoint ){ |
| 68946 | + pTmp = db->pSavepoint; |
| 68947 | + db->pSavepoint = pTmp->pNext; |
| 68948 | + sqlite3DbFree(db, pTmp); |
| 69398 | 68949 | db->nSavepoint--; |
| 69399 | 68950 | } |
| 69400 | 68951 | |
| 69401 | | - /* If it is a RELEASE, then destroy the savepoint being operated on |
| 69402 | | - ** too. If it is a ROLLBACK TO, then set the number of deferred |
| 68952 | + /* If it is a RELEASE, then destroy the savepoint being operated on |
| 68953 | + ** too. If it is a ROLLBACK TO, then set the number of deferred |
| 69403 | 68954 | ** constraint violations present in the database to the value stored |
| 69404 | 68955 | ** when the savepoint was created. */ |
| 69405 | | - if( u.at.p1==SAVEPOINT_RELEASE ){ |
| 69406 | | - assert( u.at.pSavepoint==db->pSavepoint ); |
| 69407 | | - db->pSavepoint = u.at.pSavepoint->pNext; |
| 69408 | | - sqlite3DbFree(db, u.at.pSavepoint); |
| 68956 | + if( p1==SAVEPOINT_RELEASE ){ |
| 68957 | + assert( pSavepoint==db->pSavepoint ); |
| 68958 | + db->pSavepoint = pSavepoint->pNext; |
| 68959 | + sqlite3DbFree(db, pSavepoint); |
| 69409 | 68960 | if( !isTransaction ){ |
| 69410 | 68961 | db->nSavepoint--; |
| 69411 | 68962 | } |
| 69412 | 68963 | }else{ |
| 69413 | | - db->nDeferredCons = u.at.pSavepoint->nDeferredCons; |
| 69414 | | - db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons; |
| 68964 | + db->nDeferredCons = pSavepoint->nDeferredCons; |
| 68965 | + db->nDeferredImmCons = pSavepoint->nDeferredImmCons; |
| 69415 | 68966 | } |
| 69416 | 68967 | |
| 69417 | 68968 | if( !isTransaction ){ |
| 69418 | | - rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint); |
| 68969 | + rc = sqlite3VtabSavepoint(db, p1, iSavepoint); |
| 69419 | 68970 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69420 | 68971 | } |
| 69421 | 68972 | } |
| 69422 | 68973 | } |
| 69423 | 68974 | |
| | @@ -69432,54 +68983,52 @@ |
| 69432 | 68983 | ** there are active writing VMs or active VMs that use shared cache. |
| 69433 | 68984 | ** |
| 69434 | 68985 | ** This instruction causes the VM to halt. |
| 69435 | 68986 | */ |
| 69436 | 68987 | case OP_AutoCommit: { |
| 69437 | | -#if 0 /* local variables moved into u.au */ |
| 69438 | 68988 | int desiredAutoCommit; |
| 69439 | 68989 | int iRollback; |
| 69440 | 68990 | int turnOnAC; |
| 69441 | | -#endif /* local variables moved into u.au */ |
| 69442 | 68991 | |
| 69443 | | - u.au.desiredAutoCommit = pOp->p1; |
| 69444 | | - u.au.iRollback = pOp->p2; |
| 69445 | | - u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit; |
| 69446 | | - assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 ); |
| 69447 | | - assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 ); |
| 68992 | + desiredAutoCommit = pOp->p1; |
| 68993 | + iRollback = pOp->p2; |
| 68994 | + turnOnAC = desiredAutoCommit && !db->autoCommit; |
| 68995 | + assert( desiredAutoCommit==1 || desiredAutoCommit==0 ); |
| 68996 | + assert( desiredAutoCommit==1 || iRollback==0 ); |
| 69448 | 68997 | assert( db->nVdbeActive>0 ); /* At least this one VM is active */ |
| 69449 | 68998 | assert( p->bIsReader ); |
| 69450 | 68999 | |
| 69451 | 69000 | #if 0 |
| 69452 | | - if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){ |
| 69001 | + if( turnOnAC && iRollback && db->nVdbeActive>1 ){ |
| 69453 | 69002 | /* If this instruction implements a ROLLBACK and other VMs are |
| 69454 | 69003 | ** still running, and a transaction is active, return an error indicating |
| 69455 | | - ** that the other VMs must complete first. |
| 69004 | + ** that the other VMs must complete first. |
| 69456 | 69005 | */ |
| 69457 | 69006 | sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - " |
| 69458 | 69007 | "SQL statements in progress"); |
| 69459 | 69008 | rc = SQLITE_BUSY; |
| 69460 | 69009 | }else |
| 69461 | 69010 | #endif |
| 69462 | | - if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){ |
| 69011 | + if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){ |
| 69463 | 69012 | /* If this instruction implements a COMMIT and other VMs are writing |
| 69464 | | - ** return an error indicating that the other VMs must complete first. |
| 69013 | + ** return an error indicating that the other VMs must complete first. |
| 69465 | 69014 | */ |
| 69466 | 69015 | sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - " |
| 69467 | 69016 | "SQL statements in progress"); |
| 69468 | 69017 | rc = SQLITE_BUSY; |
| 69469 | | - }else if( u.au.desiredAutoCommit!=db->autoCommit ){ |
| 69470 | | - if( u.au.iRollback ){ |
| 69471 | | - assert( u.au.desiredAutoCommit==1 ); |
| 69018 | + }else if( desiredAutoCommit!=db->autoCommit ){ |
| 69019 | + if( iRollback ){ |
| 69020 | + assert( desiredAutoCommit==1 ); |
| 69472 | 69021 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 69473 | 69022 | db->autoCommit = 1; |
| 69474 | 69023 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 69475 | 69024 | goto vdbe_return; |
| 69476 | 69025 | }else{ |
| 69477 | | - db->autoCommit = (u8)u.au.desiredAutoCommit; |
| 69026 | + db->autoCommit = (u8)desiredAutoCommit; |
| 69478 | 69027 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 69479 | 69028 | p->pc = pc; |
| 69480 | | - db->autoCommit = (u8)(1-u.au.desiredAutoCommit); |
| 69029 | + db->autoCommit = (u8)(1-desiredAutoCommit); |
| 69481 | 69030 | p->rc = rc = SQLITE_BUSY; |
| 69482 | 69031 | goto vdbe_return; |
| 69483 | 69032 | } |
| 69484 | 69033 | } |
| 69485 | 69034 | assert( db->nStatement==0 ); |
| | @@ -69490,14 +69039,14 @@ |
| 69490 | 69039 | rc = SQLITE_ERROR; |
| 69491 | 69040 | } |
| 69492 | 69041 | goto vdbe_return; |
| 69493 | 69042 | }else{ |
| 69494 | 69043 | sqlite3SetString(&p->zErrMsg, db, |
| 69495 | | - (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":( |
| 69496 | | - (u.au.iRollback)?"cannot rollback - no transaction is active": |
| 69044 | + (!desiredAutoCommit)?"cannot start a transaction within a transaction":( |
| 69045 | + (iRollback)?"cannot rollback - no transaction is active": |
| 69497 | 69046 | "cannot commit - no transaction is active")); |
| 69498 | | - |
| 69047 | + |
| 69499 | 69048 | rc = SQLITE_ERROR; |
| 69500 | 69049 | } |
| 69501 | 69050 | break; |
| 69502 | 69051 | } |
| 69503 | 69052 | |
| | @@ -69531,48 +69080,46 @@ |
| 69531 | 69080 | ** will automatically commit when the VDBE halts. |
| 69532 | 69081 | ** |
| 69533 | 69082 | ** If P2 is zero, then a read-lock is obtained on the database file. |
| 69534 | 69083 | */ |
| 69535 | 69084 | case OP_Transaction: { |
| 69536 | | -#if 0 /* local variables moved into u.av */ |
| 69537 | 69085 | Btree *pBt; |
| 69538 | | -#endif /* local variables moved into u.av */ |
| 69539 | 69086 | |
| 69540 | 69087 | assert( p->bIsReader ); |
| 69541 | 69088 | assert( p->readOnly==0 || pOp->p2==0 ); |
| 69542 | 69089 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69543 | 69090 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69544 | 69091 | if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ |
| 69545 | 69092 | rc = SQLITE_READONLY; |
| 69546 | 69093 | goto abort_due_to_error; |
| 69547 | 69094 | } |
| 69548 | | - u.av.pBt = db->aDb[pOp->p1].pBt; |
| 69095 | + pBt = db->aDb[pOp->p1].pBt; |
| 69549 | 69096 | |
| 69550 | | - if( u.av.pBt ){ |
| 69551 | | - rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2); |
| 69097 | + if( pBt ){ |
| 69098 | + rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); |
| 69552 | 69099 | if( rc==SQLITE_BUSY ){ |
| 69553 | 69100 | p->pc = pc; |
| 69554 | 69101 | p->rc = rc = SQLITE_BUSY; |
| 69555 | 69102 | goto vdbe_return; |
| 69556 | 69103 | } |
| 69557 | 69104 | if( rc!=SQLITE_OK ){ |
| 69558 | 69105 | goto abort_due_to_error; |
| 69559 | 69106 | } |
| 69560 | 69107 | |
| 69561 | | - if( pOp->p2 && p->usesStmtJournal |
| 69562 | | - && (db->autoCommit==0 || db->nVdbeRead>1) |
| 69108 | + if( pOp->p2 && p->usesStmtJournal |
| 69109 | + && (db->autoCommit==0 || db->nVdbeRead>1) |
| 69563 | 69110 | ){ |
| 69564 | | - assert( sqlite3BtreeIsInTrans(u.av.pBt) ); |
| 69111 | + assert( sqlite3BtreeIsInTrans(pBt) ); |
| 69565 | 69112 | if( p->iStatement==0 ){ |
| 69566 | 69113 | assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 69567 | | - db->nStatement++; |
| 69114 | + db->nStatement++; |
| 69568 | 69115 | p->iStatement = db->nSavepoint + db->nStatement; |
| 69569 | 69116 | } |
| 69570 | 69117 | |
| 69571 | 69118 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1); |
| 69572 | 69119 | if( rc==SQLITE_OK ){ |
| 69573 | | - rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement); |
| 69120 | + rc = sqlite3BtreeBeginStmt(pBt, p->iStatement); |
| 69574 | 69121 | } |
| 69575 | 69122 | |
| 69576 | 69123 | /* Store the current value of the database handles deferred constraint |
| 69577 | 69124 | ** counter. If the statement transaction needs to be rolled back, |
| 69578 | 69125 | ** the value of this counter needs to be restored too. */ |
| | @@ -69594,26 +69141,24 @@ |
| 69594 | 69141 | ** There must be a read-lock on the database (either a transaction |
| 69595 | 69142 | ** must be started or there must be an open cursor) before |
| 69596 | 69143 | ** executing this instruction. |
| 69597 | 69144 | */ |
| 69598 | 69145 | case OP_ReadCookie: { /* out2-prerelease */ |
| 69599 | | -#if 0 /* local variables moved into u.aw */ |
| 69600 | 69146 | int iMeta; |
| 69601 | 69147 | int iDb; |
| 69602 | 69148 | int iCookie; |
| 69603 | | -#endif /* local variables moved into u.aw */ |
| 69604 | 69149 | |
| 69605 | 69150 | assert( p->bIsReader ); |
| 69606 | | - u.aw.iDb = pOp->p1; |
| 69607 | | - u.aw.iCookie = pOp->p3; |
| 69151 | + iDb = pOp->p1; |
| 69152 | + iCookie = pOp->p3; |
| 69608 | 69153 | assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 69609 | | - assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb ); |
| 69610 | | - assert( db->aDb[u.aw.iDb].pBt!=0 ); |
| 69611 | | - assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 ); |
| 69154 | + assert( iDb>=0 && iDb<db->nDb ); |
| 69155 | + assert( db->aDb[iDb].pBt!=0 ); |
| 69156 | + assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); |
| 69612 | 69157 | |
| 69613 | | - sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta); |
| 69614 | | - pOut->u.i = u.aw.iMeta; |
| 69158 | + sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); |
| 69159 | + pOut->u.i = iMeta; |
| 69615 | 69160 | break; |
| 69616 | 69161 | } |
| 69617 | 69162 | |
| 69618 | 69163 | /* Opcode: SetCookie P1 P2 P3 * * |
| 69619 | 69164 | ** |
| | @@ -69624,31 +69169,29 @@ |
| 69624 | 69169 | ** database file used to store temporary tables. |
| 69625 | 69170 | ** |
| 69626 | 69171 | ** A transaction must be started before executing this opcode. |
| 69627 | 69172 | */ |
| 69628 | 69173 | case OP_SetCookie: { /* in3 */ |
| 69629 | | -#if 0 /* local variables moved into u.ax */ |
| 69630 | 69174 | Db *pDb; |
| 69631 | | -#endif /* local variables moved into u.ax */ |
| 69632 | 69175 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 69633 | 69176 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69634 | 69177 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69635 | 69178 | assert( p->readOnly==0 ); |
| 69636 | | - u.ax.pDb = &db->aDb[pOp->p1]; |
| 69637 | | - assert( u.ax.pDb->pBt!=0 ); |
| 69179 | + pDb = &db->aDb[pOp->p1]; |
| 69180 | + assert( pDb->pBt!=0 ); |
| 69638 | 69181 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69639 | 69182 | pIn3 = &aMem[pOp->p3]; |
| 69640 | 69183 | sqlite3VdbeMemIntegerify(pIn3); |
| 69641 | 69184 | /* See note about index shifting on OP_ReadCookie */ |
| 69642 | | - rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i); |
| 69185 | + rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i); |
| 69643 | 69186 | if( pOp->p2==BTREE_SCHEMA_VERSION ){ |
| 69644 | 69187 | /* When the schema cookie changes, record the new cookie internally */ |
| 69645 | | - u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i; |
| 69188 | + pDb->pSchema->schema_cookie = (int)pIn3->u.i; |
| 69646 | 69189 | db->flags |= SQLITE_InternChanges; |
| 69647 | 69190 | }else if( pOp->p2==BTREE_FILE_FORMAT ){ |
| 69648 | 69191 | /* Record changes in the file format */ |
| 69649 | | - u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i; |
| 69192 | + pDb->pSchema->file_format = (u8)pIn3->u.i; |
| 69650 | 69193 | } |
| 69651 | 69194 | if( pOp->p1==1 ){ |
| 69652 | 69195 | /* Invalidate all prepared statements whenever the TEMP database |
| 69653 | 69196 | ** schema is changed. Ticket #1644 */ |
| 69654 | 69197 | sqlite3ExpirePreparedStatements(db); |
| | @@ -69674,44 +69217,42 @@ |
| 69674 | 69217 | ** Either a transaction needs to have been started or an OP_Open needs |
| 69675 | 69218 | ** to be executed (to establish a read lock) before this opcode is |
| 69676 | 69219 | ** invoked. |
| 69677 | 69220 | */ |
| 69678 | 69221 | case OP_VerifyCookie: { |
| 69679 | | -#if 0 /* local variables moved into u.ay */ |
| 69680 | 69222 | int iMeta; |
| 69681 | 69223 | int iGen; |
| 69682 | 69224 | Btree *pBt; |
| 69683 | | -#endif /* local variables moved into u.ay */ |
| 69684 | 69225 | |
| 69685 | 69226 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69686 | 69227 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69687 | 69228 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69688 | 69229 | assert( p->bIsReader ); |
| 69689 | | - u.ay.pBt = db->aDb[pOp->p1].pBt; |
| 69690 | | - if( u.ay.pBt ){ |
| 69691 | | - sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta); |
| 69692 | | - u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 69230 | + pBt = db->aDb[pOp->p1].pBt; |
| 69231 | + if( pBt ){ |
| 69232 | + sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta); |
| 69233 | + iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 69693 | 69234 | }else{ |
| 69694 | | - u.ay.iGen = u.ay.iMeta = 0; |
| 69235 | + iGen = iMeta = 0; |
| 69695 | 69236 | } |
| 69696 | | - if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){ |
| 69237 | + if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){ |
| 69697 | 69238 | sqlite3DbFree(db, p->zErrMsg); |
| 69698 | 69239 | p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 69699 | | - /* If the schema-cookie from the database file matches the cookie |
| 69240 | + /* If the schema-cookie from the database file matches the cookie |
| 69700 | 69241 | ** stored with the in-memory representation of the schema, do |
| 69701 | 69242 | ** not reload the schema from the database file. |
| 69702 | 69243 | ** |
| 69703 | 69244 | ** If virtual-tables are in use, this is not just an optimization. |
| 69704 | 69245 | ** Often, v-tables store their data in other SQLite tables, which |
| 69705 | 69246 | ** are queried from within xNext() and other v-table methods using |
| 69706 | 69247 | ** prepared queries. If such a query is out-of-date, we do not want to |
| 69707 | 69248 | ** discard the database schema, as the user code implementing the |
| 69708 | 69249 | ** v-table would have to be ready for the sqlite3_vtab structure itself |
| 69709 | | - ** to be invalidated whenever sqlite3_step() is called from within |
| 69250 | + ** to be invalidated whenever sqlite3_step() is called from within |
| 69710 | 69251 | ** a v-table method. |
| 69711 | 69252 | */ |
| 69712 | | - if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){ |
| 69253 | + if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){ |
| 69713 | 69254 | sqlite3ResetOneSchema(db, pOp->p1); |
| 69714 | 69255 | } |
| 69715 | 69256 | |
| 69716 | 69257 | p->expired = 1; |
| 69717 | 69258 | rc = SQLITE_SCHEMA; |
| | @@ -69770,20 +69311,18 @@ |
| 69770 | 69311 | ** |
| 69771 | 69312 | ** See also OpenRead. |
| 69772 | 69313 | */ |
| 69773 | 69314 | case OP_OpenRead: |
| 69774 | 69315 | case OP_OpenWrite: { |
| 69775 | | -#if 0 /* local variables moved into u.az */ |
| 69776 | 69316 | int nField; |
| 69777 | 69317 | KeyInfo *pKeyInfo; |
| 69778 | 69318 | int p2; |
| 69779 | 69319 | int iDb; |
| 69780 | 69320 | int wrFlag; |
| 69781 | 69321 | Btree *pX; |
| 69782 | 69322 | VdbeCursor *pCur; |
| 69783 | 69323 | Db *pDb; |
| 69784 | | -#endif /* local variables moved into u.az */ |
| 69785 | 69324 | |
| 69786 | 69325 | assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 ); |
| 69787 | 69326 | assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 ); |
| 69788 | 69327 | assert( p->bIsReader ); |
| 69789 | 69328 | assert( pOp->opcode==OP_OpenRead || p->readOnly==0 ); |
| | @@ -69791,74 +69330,74 @@ |
| 69791 | 69330 | if( p->expired ){ |
| 69792 | 69331 | rc = SQLITE_ABORT; |
| 69793 | 69332 | break; |
| 69794 | 69333 | } |
| 69795 | 69334 | |
| 69796 | | - u.az.nField = 0; |
| 69797 | | - u.az.pKeyInfo = 0; |
| 69798 | | - u.az.p2 = pOp->p2; |
| 69799 | | - u.az.iDb = pOp->p3; |
| 69800 | | - assert( u.az.iDb>=0 && u.az.iDb<db->nDb ); |
| 69801 | | - assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 ); |
| 69802 | | - u.az.pDb = &db->aDb[u.az.iDb]; |
| 69803 | | - u.az.pX = u.az.pDb->pBt; |
| 69804 | | - assert( u.az.pX!=0 ); |
| 69335 | + nField = 0; |
| 69336 | + pKeyInfo = 0; |
| 69337 | + p2 = pOp->p2; |
| 69338 | + iDb = pOp->p3; |
| 69339 | + assert( iDb>=0 && iDb<db->nDb ); |
| 69340 | + assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); |
| 69341 | + pDb = &db->aDb[iDb]; |
| 69342 | + pX = pDb->pBt; |
| 69343 | + assert( pX!=0 ); |
| 69805 | 69344 | if( pOp->opcode==OP_OpenWrite ){ |
| 69806 | | - u.az.wrFlag = 1; |
| 69807 | | - assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) ); |
| 69808 | | - if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){ |
| 69809 | | - p->minWriteFileFormat = u.az.pDb->pSchema->file_format; |
| 69345 | + wrFlag = 1; |
| 69346 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 69347 | + if( pDb->pSchema->file_format < p->minWriteFileFormat ){ |
| 69348 | + p->minWriteFileFormat = pDb->pSchema->file_format; |
| 69810 | 69349 | } |
| 69811 | 69350 | }else{ |
| 69812 | | - u.az.wrFlag = 0; |
| 69351 | + wrFlag = 0; |
| 69813 | 69352 | } |
| 69814 | 69353 | if( pOp->p5 & OPFLAG_P2ISREG ){ |
| 69815 | | - assert( u.az.p2>0 ); |
| 69816 | | - assert( u.az.p2<=(p->nMem-p->nCursor) ); |
| 69817 | | - pIn2 = &aMem[u.az.p2]; |
| 69354 | + assert( p2>0 ); |
| 69355 | + assert( p2<=(p->nMem-p->nCursor) ); |
| 69356 | + pIn2 = &aMem[p2]; |
| 69818 | 69357 | assert( memIsValid(pIn2) ); |
| 69819 | 69358 | assert( (pIn2->flags & MEM_Int)!=0 ); |
| 69820 | 69359 | sqlite3VdbeMemIntegerify(pIn2); |
| 69821 | | - u.az.p2 = (int)pIn2->u.i; |
| 69822 | | - /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and |
| 69823 | | - ** that opcode will always set the u.az.p2 value to 2 or more or else fail. |
| 69360 | + p2 = (int)pIn2->u.i; |
| 69361 | + /* The p2 value always comes from a prior OP_CreateTable opcode and |
| 69362 | + ** that opcode will always set the p2 value to 2 or more or else fail. |
| 69824 | 69363 | ** If there were a failure, the prepared statement would have halted |
| 69825 | 69364 | ** before reaching this instruction. */ |
| 69826 | | - if( NEVER(u.az.p2<2) ) { |
| 69365 | + if( NEVER(p2<2) ) { |
| 69827 | 69366 | rc = SQLITE_CORRUPT_BKPT; |
| 69828 | 69367 | goto abort_due_to_error; |
| 69829 | 69368 | } |
| 69830 | 69369 | } |
| 69831 | 69370 | if( pOp->p4type==P4_KEYINFO ){ |
| 69832 | | - u.az.pKeyInfo = pOp->p4.pKeyInfo; |
| 69833 | | - assert( u.az.pKeyInfo->enc==ENC(db) ); |
| 69834 | | - assert( u.az.pKeyInfo->db==db ); |
| 69835 | | - u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField; |
| 69371 | + pKeyInfo = pOp->p4.pKeyInfo; |
| 69372 | + assert( pKeyInfo->enc==ENC(db) ); |
| 69373 | + assert( pKeyInfo->db==db ); |
| 69374 | + nField = pKeyInfo->nField+pKeyInfo->nXField; |
| 69836 | 69375 | }else if( pOp->p4type==P4_INT32 ){ |
| 69837 | | - u.az.nField = pOp->p4.i; |
| 69376 | + nField = pOp->p4.i; |
| 69838 | 69377 | } |
| 69839 | 69378 | assert( pOp->p1>=0 ); |
| 69840 | | - assert( u.az.nField>=0 ); |
| 69841 | | - testcase( u.az.nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ |
| 69842 | | - u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1); |
| 69843 | | - if( u.az.pCur==0 ) goto no_mem; |
| 69844 | | - u.az.pCur->nullRow = 1; |
| 69845 | | - u.az.pCur->isOrdered = 1; |
| 69846 | | - rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor); |
| 69847 | | - u.az.pCur->pKeyInfo = u.az.pKeyInfo; |
| 69379 | + assert( nField>=0 ); |
| 69380 | + testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ |
| 69381 | + pCur = allocateCursor(p, pOp->p1, nField, iDb, 1); |
| 69382 | + if( pCur==0 ) goto no_mem; |
| 69383 | + pCur->nullRow = 1; |
| 69384 | + pCur->isOrdered = 1; |
| 69385 | + rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor); |
| 69386 | + pCur->pKeyInfo = pKeyInfo; |
| 69848 | 69387 | assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); |
| 69849 | | - sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR)); |
| 69388 | + sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR)); |
| 69850 | 69389 | |
| 69851 | 69390 | /* Since it performs no memory allocation or IO, the only value that |
| 69852 | 69391 | ** sqlite3BtreeCursor() may return is SQLITE_OK. */ |
| 69853 | 69392 | assert( rc==SQLITE_OK ); |
| 69854 | 69393 | |
| 69855 | 69394 | /* Set the VdbeCursor.isTable variable. Previous versions of |
| 69856 | 69395 | ** SQLite used to check if the root-page flags were sane at this point |
| 69857 | 69396 | ** and report database corruption if they were not, but this check has |
| 69858 | | - ** since moved into the btree layer. */ |
| 69859 | | - u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO; |
| 69397 | + ** since moved into the btree layer. */ |
| 69398 | + pCur->isTable = pOp->p4type!=P4_KEYINFO; |
| 69860 | 69399 | break; |
| 69861 | 69400 | } |
| 69862 | 69401 | |
| 69863 | 69402 | /* Opcode: OpenEphemeral P1 P2 * P4 P5 |
| 69864 | 69403 | ** Synopsis: nColumn=P2 |
| | @@ -69886,55 +69425,53 @@ |
| 69886 | 69425 | ** by this opcode will be used for automatically created transient |
| 69887 | 69426 | ** indices in joins. |
| 69888 | 69427 | */ |
| 69889 | 69428 | case OP_OpenAutoindex: |
| 69890 | 69429 | case OP_OpenEphemeral: { |
| 69891 | | -#if 0 /* local variables moved into u.ba */ |
| 69892 | 69430 | VdbeCursor *pCx; |
| 69893 | 69431 | KeyInfo *pKeyInfo; |
| 69894 | | -#endif /* local variables moved into u.ba */ |
| 69895 | 69432 | |
| 69896 | | - static const int vfsFlags = |
| 69433 | + static const int vfsFlags = |
| 69897 | 69434 | SQLITE_OPEN_READWRITE | |
| 69898 | 69435 | SQLITE_OPEN_CREATE | |
| 69899 | 69436 | SQLITE_OPEN_EXCLUSIVE | |
| 69900 | 69437 | SQLITE_OPEN_DELETEONCLOSE | |
| 69901 | 69438 | SQLITE_OPEN_TRANSIENT_DB; |
| 69902 | 69439 | assert( pOp->p1>=0 ); |
| 69903 | 69440 | assert( pOp->p2>=0 ); |
| 69904 | | - u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69905 | | - if( u.ba.pCx==0 ) goto no_mem; |
| 69906 | | - u.ba.pCx->nullRow = 1; |
| 69907 | | - rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt, |
| 69441 | + pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69442 | + if( pCx==0 ) goto no_mem; |
| 69443 | + pCx->nullRow = 1; |
| 69444 | + rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt, |
| 69908 | 69445 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| 69909 | 69446 | if( rc==SQLITE_OK ){ |
| 69910 | | - rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1); |
| 69447 | + rc = sqlite3BtreeBeginTrans(pCx->pBt, 1); |
| 69911 | 69448 | } |
| 69912 | 69449 | if( rc==SQLITE_OK ){ |
| 69913 | 69450 | /* If a transient index is required, create it by calling |
| 69914 | 69451 | ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before |
| 69915 | 69452 | ** opening it. If a transient table is required, just use the |
| 69916 | 69453 | ** automatically created table with root-page 1 (an BLOB_INTKEY table). |
| 69917 | 69454 | */ |
| 69918 | | - if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 69455 | + if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 69919 | 69456 | int pgno; |
| 69920 | 69457 | assert( pOp->p4type==P4_KEYINFO ); |
| 69921 | | - rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); |
| 69458 | + rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); |
| 69922 | 69459 | if( rc==SQLITE_OK ){ |
| 69923 | 69460 | assert( pgno==MASTER_ROOT+1 ); |
| 69924 | | - assert( u.ba.pKeyInfo->db==db ); |
| 69925 | | - assert( u.ba.pKeyInfo->enc==ENC(db) ); |
| 69926 | | - u.ba.pCx->pKeyInfo = u.ba.pKeyInfo; |
| 69927 | | - rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor); |
| 69928 | | - } |
| 69929 | | - u.ba.pCx->isTable = 0; |
| 69930 | | - }else{ |
| 69931 | | - rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor); |
| 69932 | | - u.ba.pCx->isTable = 1; |
| 69461 | + assert( pKeyInfo->db==db ); |
| 69462 | + assert( pKeyInfo->enc==ENC(db) ); |
| 69463 | + pCx->pKeyInfo = pKeyInfo; |
| 69464 | + rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor); |
| 69465 | + } |
| 69466 | + pCx->isTable = 0; |
| 69467 | + }else{ |
| 69468 | + rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor); |
| 69469 | + pCx->isTable = 1; |
| 69933 | 69470 | } |
| 69934 | 69471 | } |
| 69935 | | - u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 69472 | + pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 69936 | 69473 | break; |
| 69937 | 69474 | } |
| 69938 | 69475 | |
| 69939 | 69476 | /* Opcode: SorterOpen P1 * * P4 * |
| 69940 | 69477 | ** |
| | @@ -69941,22 +69478,20 @@ |
| 69941 | 69478 | ** This opcode works like OP_OpenEphemeral except that it opens |
| 69942 | 69479 | ** a transient index that is specifically designed to sort large |
| 69943 | 69480 | ** tables using an external merge-sort algorithm. |
| 69944 | 69481 | */ |
| 69945 | 69482 | case OP_SorterOpen: { |
| 69946 | | -#if 0 /* local variables moved into u.bb */ |
| 69947 | 69483 | VdbeCursor *pCx; |
| 69948 | | -#endif /* local variables moved into u.bb */ |
| 69949 | 69484 | |
| 69950 | 69485 | assert( pOp->p1>=0 ); |
| 69951 | 69486 | assert( pOp->p2>=0 ); |
| 69952 | | - u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69953 | | - if( u.bb.pCx==0 ) goto no_mem; |
| 69954 | | - u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo; |
| 69955 | | - assert( u.bb.pCx->pKeyInfo->db==db ); |
| 69956 | | - assert( u.bb.pCx->pKeyInfo->enc==ENC(db) ); |
| 69957 | | - rc = sqlite3VdbeSorterInit(db, u.bb.pCx); |
| 69487 | + pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69488 | + if( pCx==0 ) goto no_mem; |
| 69489 | + pCx->pKeyInfo = pOp->p4.pKeyInfo; |
| 69490 | + assert( pCx->pKeyInfo->db==db ); |
| 69491 | + assert( pCx->pKeyInfo->enc==ENC(db) ); |
| 69492 | + rc = sqlite3VdbeSorterInit(db, pCx); |
| 69958 | 69493 | break; |
| 69959 | 69494 | } |
| 69960 | 69495 | |
| 69961 | 69496 | /* Opcode: OpenPseudo P1 P2 P3 * P5 |
| 69962 | 69497 | ** Synopsis: content in r[P2@P3] |
| | @@ -69974,22 +69509,20 @@ |
| 69974 | 69509 | ** |
| 69975 | 69510 | ** P3 is the number of fields in the records that will be stored by |
| 69976 | 69511 | ** the pseudo-table. |
| 69977 | 69512 | */ |
| 69978 | 69513 | case OP_OpenPseudo: { |
| 69979 | | -#if 0 /* local variables moved into u.bc */ |
| 69980 | 69514 | VdbeCursor *pCx; |
| 69981 | | -#endif /* local variables moved into u.bc */ |
| 69982 | 69515 | |
| 69983 | 69516 | assert( pOp->p1>=0 ); |
| 69984 | 69517 | assert( pOp->p3>=0 ); |
| 69985 | | - u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); |
| 69986 | | - if( u.bc.pCx==0 ) goto no_mem; |
| 69987 | | - u.bc.pCx->nullRow = 1; |
| 69988 | | - u.bc.pCx->pseudoTableReg = pOp->p2; |
| 69989 | | - u.bc.pCx->isTable = 1; |
| 69990 | | - u.bc.pCx->multiPseudo = pOp->p5; |
| 69518 | + pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); |
| 69519 | + if( pCx==0 ) goto no_mem; |
| 69520 | + pCx->nullRow = 1; |
| 69521 | + pCx->pseudoTableReg = pOp->p2; |
| 69522 | + pCx->isTable = 1; |
| 69523 | + pCx->multiPseudo = pOp->p5; |
| 69991 | 69524 | break; |
| 69992 | 69525 | } |
| 69993 | 69526 | |
| 69994 | 69527 | /* Opcode: Close P1 * * * * |
| 69995 | 69528 | ** |
| | @@ -70061,39 +69594,37 @@ |
| 70061 | 69594 | */ |
| 70062 | 69595 | case OP_SeekLt: /* jump, in3 */ |
| 70063 | 69596 | case OP_SeekLe: /* jump, in3 */ |
| 70064 | 69597 | case OP_SeekGe: /* jump, in3 */ |
| 70065 | 69598 | case OP_SeekGt: { /* jump, in3 */ |
| 70066 | | -#if 0 /* local variables moved into u.bd */ |
| 70067 | 69599 | int res; |
| 70068 | 69600 | int oc; |
| 70069 | 69601 | VdbeCursor *pC; |
| 70070 | 69602 | UnpackedRecord r; |
| 70071 | 69603 | int nField; |
| 70072 | 69604 | i64 iKey; /* The rowid we are to seek to */ |
| 70073 | | -#endif /* local variables moved into u.bd */ |
| 70074 | 69605 | |
| 70075 | 69606 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70076 | 69607 | assert( pOp->p2!=0 ); |
| 70077 | | - u.bd.pC = p->apCsr[pOp->p1]; |
| 70078 | | - assert( u.bd.pC!=0 ); |
| 70079 | | - assert( u.bd.pC->pseudoTableReg==0 ); |
| 69608 | + pC = p->apCsr[pOp->p1]; |
| 69609 | + assert( pC!=0 ); |
| 69610 | + assert( pC->pseudoTableReg==0 ); |
| 70080 | 69611 | assert( OP_SeekLe == OP_SeekLt+1 ); |
| 70081 | 69612 | assert( OP_SeekGe == OP_SeekLt+2 ); |
| 70082 | 69613 | assert( OP_SeekGt == OP_SeekLt+3 ); |
| 70083 | | - assert( u.bd.pC->isOrdered ); |
| 70084 | | - assert( u.bd.pC->pCursor!=0 ); |
| 70085 | | - u.bd.oc = pOp->opcode; |
| 70086 | | - u.bd.pC->nullRow = 0; |
| 70087 | | - if( u.bd.pC->isTable ){ |
| 69614 | + assert( pC->isOrdered ); |
| 69615 | + assert( pC->pCursor!=0 ); |
| 69616 | + oc = pOp->opcode; |
| 69617 | + pC->nullRow = 0; |
| 69618 | + if( pC->isTable ){ |
| 70088 | 69619 | /* The input value in P3 might be of any type: integer, real, string, |
| 70089 | 69620 | ** blob, or NULL. But it needs to be an integer before we can do |
| 70090 | 69621 | ** the seek, so covert it. */ |
| 70091 | 69622 | pIn3 = &aMem[pOp->p3]; |
| 70092 | 69623 | applyNumericAffinity(pIn3); |
| 70093 | | - u.bd.iKey = sqlite3VdbeIntValue(pIn3); |
| 70094 | | - u.bd.pC->rowidIsValid = 0; |
| 69624 | + iKey = sqlite3VdbeIntValue(pIn3); |
| 69625 | + pC->rowidIsValid = 0; |
| 70095 | 69626 | |
| 70096 | 69627 | /* If the P3 value could not be converted into an integer without |
| 70097 | 69628 | ** loss of information, then special processing is required... */ |
| 70098 | 69629 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 70099 | 69630 | if( (pIn3->flags & MEM_Real)==0 ){ |
| | @@ -70101,100 +69632,100 @@ |
| 70101 | 69632 | ** then the seek is not possible, so jump to P2 */ |
| 70102 | 69633 | pc = pOp->p2 - 1; |
| 70103 | 69634 | break; |
| 70104 | 69635 | } |
| 70105 | 69636 | |
| 70106 | | - /* If the approximation u.bd.iKey is larger than the actual real search |
| 69637 | + /* If the approximation iKey is larger than the actual real search |
| 70107 | 69638 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| 70108 | 69639 | ** is 4.9 and the integer approximation 5: |
| 70109 | 69640 | ** |
| 70110 | 69641 | ** (x > 4.9) -> (x >= 5) |
| 70111 | 69642 | ** (x <= 4.9) -> (x < 5) |
| 70112 | 69643 | */ |
| 70113 | | - if( pIn3->r<(double)u.bd.iKey ){ |
| 70114 | | - assert( OP_SeekGe==(OP_SeekGt-1) ); |
| 70115 | | - assert( OP_SeekLt==(OP_SeekLe-1) ); |
| 70116 | | - assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); |
| 70117 | | - if( (u.bd.oc & 0x0001)==(OP_SeekGt & 0x0001) ) u.bd.oc--; |
| 70118 | | - } |
| 70119 | | - |
| 70120 | | - /* If the approximation u.bd.iKey is smaller than the actual real search |
| 70121 | | - ** term, substitute <= for < and > for >=. */ |
| 70122 | | - else if( pIn3->r>(double)u.bd.iKey ){ |
| 70123 | | - assert( OP_SeekLe==(OP_SeekLt+1) ); |
| 70124 | | - assert( OP_SeekGt==(OP_SeekGe+1) ); |
| 70125 | | - assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); |
| 70126 | | - if( (u.bd.oc & 0x0001)==(OP_SeekLt & 0x0001) ) u.bd.oc++; |
| 70127 | | - } |
| 70128 | | - } |
| 70129 | | - rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res); |
| 70130 | | - if( rc!=SQLITE_OK ){ |
| 70131 | | - goto abort_due_to_error; |
| 70132 | | - } |
| 70133 | | - if( u.bd.res==0 ){ |
| 70134 | | - u.bd.pC->rowidIsValid = 1; |
| 70135 | | - u.bd.pC->lastRowid = u.bd.iKey; |
| 70136 | | - } |
| 70137 | | - }else{ |
| 70138 | | - u.bd.nField = pOp->p4.i; |
| 70139 | | - assert( pOp->p4type==P4_INT32 ); |
| 70140 | | - assert( u.bd.nField>0 ); |
| 70141 | | - u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo; |
| 70142 | | - u.bd.r.nField = (u16)u.bd.nField; |
| 70143 | | - |
| 70144 | | - /* The next line of code computes as follows, only faster: |
| 70145 | | - ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){ |
| 70146 | | - ** u.bd.r.flags = UNPACKED_INCRKEY; |
| 70147 | | - ** }else{ |
| 70148 | | - ** u.bd.r.flags = 0; |
| 70149 | | - ** } |
| 70150 | | - */ |
| 70151 | | - u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt))); |
| 70152 | | - assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY ); |
| 70153 | | - assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY ); |
| 70154 | | - assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 ); |
| 70155 | | - assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 ); |
| 70156 | | - |
| 70157 | | - u.bd.r.aMem = &aMem[pOp->p3]; |
| 70158 | | -#ifdef SQLITE_DEBUG |
| 70159 | | - { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); } |
| 70160 | | -#endif |
| 70161 | | - ExpandBlob(u.bd.r.aMem); |
| 70162 | | - rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res); |
| 70163 | | - if( rc!=SQLITE_OK ){ |
| 70164 | | - goto abort_due_to_error; |
| 70165 | | - } |
| 70166 | | - u.bd.pC->rowidIsValid = 0; |
| 70167 | | - } |
| 70168 | | - u.bd.pC->deferredMoveto = 0; |
| 70169 | | - u.bd.pC->cacheStatus = CACHE_STALE; |
| 70170 | | -#ifdef SQLITE_TEST |
| 70171 | | - sqlite3_search_count++; |
| 70172 | | -#endif |
| 70173 | | - if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt ); |
| 70174 | | - if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){ |
| 70175 | | - rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res); |
| 70176 | | - if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 70177 | | - u.bd.pC->rowidIsValid = 0; |
| 70178 | | - }else{ |
| 70179 | | - u.bd.res = 0; |
| 70180 | | - } |
| 70181 | | - }else{ |
| 70182 | | - assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe ); |
| 70183 | | - if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){ |
| 70184 | | - rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res); |
| 70185 | | - if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 70186 | | - u.bd.pC->rowidIsValid = 0; |
| 70187 | | - }else{ |
| 70188 | | - /* u.bd.res might be negative because the table is empty. Check to |
| 70189 | | - ** see if this is the case. |
| 70190 | | - */ |
| 70191 | | - u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor); |
| 70192 | | - } |
| 70193 | | - } |
| 70194 | | - assert( pOp->p2>0 ); |
| 70195 | | - if( u.bd.res ){ |
| 69644 | + if( pIn3->r<(double)iKey ){ |
| 69645 | + assert( OP_SeekGe==(OP_SeekGt-1) ); |
| 69646 | + assert( OP_SeekLt==(OP_SeekLe-1) ); |
| 69647 | + assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); |
| 69648 | + if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--; |
| 69649 | + } |
| 69650 | + |
| 69651 | + /* If the approximation iKey is smaller than the actual real search |
| 69652 | + ** term, substitute <= for < and > for >=. */ |
| 69653 | + else if( pIn3->r>(double)iKey ){ |
| 69654 | + assert( OP_SeekLe==(OP_SeekLt+1) ); |
| 69655 | + assert( OP_SeekGt==(OP_SeekGe+1) ); |
| 69656 | + assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); |
| 69657 | + if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++; |
| 69658 | + } |
| 69659 | + } |
| 69660 | + rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res); |
| 69661 | + if( rc!=SQLITE_OK ){ |
| 69662 | + goto abort_due_to_error; |
| 69663 | + } |
| 69664 | + if( res==0 ){ |
| 69665 | + pC->rowidIsValid = 1; |
| 69666 | + pC->lastRowid = iKey; |
| 69667 | + } |
| 69668 | + }else{ |
| 69669 | + nField = pOp->p4.i; |
| 69670 | + assert( pOp->p4type==P4_INT32 ); |
| 69671 | + assert( nField>0 ); |
| 69672 | + r.pKeyInfo = pC->pKeyInfo; |
| 69673 | + r.nField = (u16)nField; |
| 69674 | + |
| 69675 | + /* The next line of code computes as follows, only faster: |
| 69676 | + ** if( oc==OP_SeekGt || oc==OP_SeekLe ){ |
| 69677 | + ** r.flags = UNPACKED_INCRKEY; |
| 69678 | + ** }else{ |
| 69679 | + ** r.flags = 0; |
| 69680 | + ** } |
| 69681 | + */ |
| 69682 | + r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt))); |
| 69683 | + assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY ); |
| 69684 | + assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY ); |
| 69685 | + assert( oc!=OP_SeekGe || r.flags==0 ); |
| 69686 | + assert( oc!=OP_SeekLt || r.flags==0 ); |
| 69687 | + |
| 69688 | + r.aMem = &aMem[pOp->p3]; |
| 69689 | +#ifdef SQLITE_DEBUG |
| 69690 | + { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 69691 | +#endif |
| 69692 | + ExpandBlob(r.aMem); |
| 69693 | + rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res); |
| 69694 | + if( rc!=SQLITE_OK ){ |
| 69695 | + goto abort_due_to_error; |
| 69696 | + } |
| 69697 | + pC->rowidIsValid = 0; |
| 69698 | + } |
| 69699 | + pC->deferredMoveto = 0; |
| 69700 | + pC->cacheStatus = CACHE_STALE; |
| 69701 | +#ifdef SQLITE_TEST |
| 69702 | + sqlite3_search_count++; |
| 69703 | +#endif |
| 69704 | + if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt ); |
| 69705 | + if( res<0 || (res==0 && oc==OP_SeekGt) ){ |
| 69706 | + rc = sqlite3BtreeNext(pC->pCursor, &res); |
| 69707 | + if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69708 | + pC->rowidIsValid = 0; |
| 69709 | + }else{ |
| 69710 | + res = 0; |
| 69711 | + } |
| 69712 | + }else{ |
| 69713 | + assert( oc==OP_SeekLt || oc==OP_SeekLe ); |
| 69714 | + if( res>0 || (res==0 && oc==OP_SeekLt) ){ |
| 69715 | + rc = sqlite3BtreePrevious(pC->pCursor, &res); |
| 69716 | + if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69717 | + pC->rowidIsValid = 0; |
| 69718 | + }else{ |
| 69719 | + /* res might be negative because the table is empty. Check to |
| 69720 | + ** see if this is the case. |
| 69721 | + */ |
| 69722 | + res = sqlite3BtreeEof(pC->pCursor); |
| 69723 | + } |
| 69724 | + } |
| 69725 | + assert( pOp->p2>0 ); |
| 69726 | + if( res ){ |
| 70196 | 69727 | pc = pOp->p2 - 1; |
| 70197 | 69728 | } |
| 70198 | 69729 | break; |
| 70199 | 69730 | } |
| 70200 | 69731 | |
| | @@ -70207,24 +69738,22 @@ |
| 70207 | 69738 | ** This is actually a deferred seek. Nothing actually happens until |
| 70208 | 69739 | ** the cursor is used to read a record. That way, if no reads |
| 70209 | 69740 | ** occur, no unnecessary I/O happens. |
| 70210 | 69741 | */ |
| 70211 | 69742 | case OP_Seek: { /* in2 */ |
| 70212 | | -#if 0 /* local variables moved into u.be */ |
| 70213 | 69743 | VdbeCursor *pC; |
| 70214 | | -#endif /* local variables moved into u.be */ |
| 70215 | 69744 | |
| 70216 | 69745 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70217 | | - u.be.pC = p->apCsr[pOp->p1]; |
| 70218 | | - assert( u.be.pC!=0 ); |
| 70219 | | - assert( u.be.pC->pCursor!=0 ); |
| 70220 | | - assert( u.be.pC->isTable ); |
| 70221 | | - u.be.pC->nullRow = 0; |
| 69746 | + pC = p->apCsr[pOp->p1]; |
| 69747 | + assert( pC!=0 ); |
| 69748 | + assert( pC->pCursor!=0 ); |
| 69749 | + assert( pC->isTable ); |
| 69750 | + pC->nullRow = 0; |
| 70222 | 69751 | pIn2 = &aMem[pOp->p2]; |
| 70223 | | - u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2); |
| 70224 | | - u.be.pC->rowidIsValid = 0; |
| 70225 | | - u.be.pC->deferredMoveto = 1; |
| 69752 | + pC->movetoTarget = sqlite3VdbeIntValue(pIn2); |
| 69753 | + pC->rowidIsValid = 0; |
| 69754 | + pC->deferredMoveto = 1; |
| 70226 | 69755 | break; |
| 70227 | 69756 | } |
| 70228 | 69757 | |
| 70229 | 69758 | |
| 70230 | 69759 | /* Opcode: Found P1 P2 P3 P4 * |
| | @@ -70275,85 +69804,83 @@ |
| 70275 | 69804 | ** See also: NotFound, Found, NotExists |
| 70276 | 69805 | */ |
| 70277 | 69806 | case OP_NoConflict: /* jump, in3 */ |
| 70278 | 69807 | case OP_NotFound: /* jump, in3 */ |
| 70279 | 69808 | case OP_Found: { /* jump, in3 */ |
| 70280 | | -#if 0 /* local variables moved into u.bf */ |
| 70281 | 69809 | int alreadyExists; |
| 70282 | 69810 | int ii; |
| 70283 | 69811 | VdbeCursor *pC; |
| 70284 | 69812 | int res; |
| 70285 | 69813 | char *pFree; |
| 70286 | 69814 | UnpackedRecord *pIdxKey; |
| 70287 | 69815 | UnpackedRecord r; |
| 70288 | 69816 | char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; |
| 70289 | | -#endif /* local variables moved into u.bf */ |
| 70290 | 69817 | |
| 70291 | 69818 | #ifdef SQLITE_TEST |
| 70292 | 69819 | if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++; |
| 70293 | 69820 | #endif |
| 70294 | 69821 | |
| 70295 | | - u.bf.alreadyExists = 0; |
| 70296 | 69822 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70297 | 69823 | assert( pOp->p4type==P4_INT32 ); |
| 70298 | | - u.bf.pC = p->apCsr[pOp->p1]; |
| 70299 | | - assert( u.bf.pC!=0 ); |
| 69824 | + pC = p->apCsr[pOp->p1]; |
| 69825 | + assert( pC!=0 ); |
| 70300 | 69826 | pIn3 = &aMem[pOp->p3]; |
| 70301 | | - assert( u.bf.pC->pCursor!=0 ); |
| 70302 | | - assert( u.bf.pC->isTable==0 ); |
| 69827 | + assert( pC->pCursor!=0 ); |
| 69828 | + assert( pC->isTable==0 ); |
| 69829 | + pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ |
| 70303 | 69830 | if( pOp->p4.i>0 ){ |
| 70304 | | - u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo; |
| 70305 | | - u.bf.r.nField = (u16)pOp->p4.i; |
| 70306 | | - u.bf.r.aMem = pIn3; |
| 69831 | + r.pKeyInfo = pC->pKeyInfo; |
| 69832 | + r.nField = (u16)pOp->p4.i; |
| 69833 | + r.aMem = pIn3; |
| 70307 | 69834 | #ifdef SQLITE_DEBUG |
| 70308 | 69835 | { |
| 70309 | 69836 | int i; |
| 70310 | | - for(i=0; i<u.bf.r.nField; i++){ |
| 70311 | | - assert( memIsValid(&u.bf.r.aMem[i]) ); |
| 70312 | | - if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]); |
| 69837 | + for(i=0; i<r.nField; i++){ |
| 69838 | + assert( memIsValid(&r.aMem[i]) ); |
| 69839 | + if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]); |
| 70313 | 69840 | } |
| 70314 | 69841 | } |
| 70315 | 69842 | #endif |
| 70316 | | - u.bf.r.flags = UNPACKED_PREFIX_MATCH; |
| 70317 | | - u.bf.pIdxKey = &u.bf.r; |
| 69843 | + r.flags = UNPACKED_PREFIX_MATCH; |
| 69844 | + pIdxKey = &r; |
| 70318 | 69845 | }else{ |
| 70319 | | - u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 70320 | | - u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree |
| 70321 | | - ); |
| 70322 | | - if( u.bf.pIdxKey==0 ) goto no_mem; |
| 69846 | + pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 69847 | + pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree |
| 69848 | + ); |
| 69849 | + if( pIdxKey==0 ) goto no_mem; |
| 70323 | 69850 | assert( pIn3->flags & MEM_Blob ); |
| 70324 | 69851 | assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */ |
| 70325 | | - sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey); |
| 70326 | | - u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH; |
| 69852 | + sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 69853 | + pIdxKey->flags |= UNPACKED_PREFIX_MATCH; |
| 70327 | 69854 | } |
| 70328 | 69855 | if( pOp->opcode==OP_NoConflict ){ |
| 70329 | 69856 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 70330 | 69857 | ** input fields are NULL, since any key with a NULL will not |
| 70331 | 69858 | ** conflict */ |
| 70332 | | - for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){ |
| 70333 | | - if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){ |
| 69859 | + for(ii=0; ii<r.nField; ii++){ |
| 69860 | + if( r.aMem[ii].flags & MEM_Null ){ |
| 70334 | 69861 | pc = pOp->p2 - 1; |
| 70335 | 69862 | break; |
| 70336 | 69863 | } |
| 70337 | 69864 | } |
| 70338 | 69865 | } |
| 70339 | | - rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res); |
| 69866 | + rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); |
| 70340 | 69867 | if( pOp->p4.i==0 ){ |
| 70341 | | - sqlite3DbFree(db, u.bf.pFree); |
| 69868 | + sqlite3DbFree(db, pFree); |
| 70342 | 69869 | } |
| 70343 | 69870 | if( rc!=SQLITE_OK ){ |
| 70344 | 69871 | break; |
| 70345 | 69872 | } |
| 70346 | | - u.bf.pC->seekResult = u.bf.res; |
| 70347 | | - u.bf.alreadyExists = (u.bf.res==0); |
| 70348 | | - u.bf.pC->nullRow = 1-u.bf.alreadyExists; |
| 70349 | | - u.bf.pC->deferredMoveto = 0; |
| 70350 | | - u.bf.pC->cacheStatus = CACHE_STALE; |
| 69873 | + pC->seekResult = res; |
| 69874 | + alreadyExists = (res==0); |
| 69875 | + pC->nullRow = 1-alreadyExists; |
| 69876 | + pC->deferredMoveto = 0; |
| 69877 | + pC->cacheStatus = CACHE_STALE; |
| 70351 | 69878 | if( pOp->opcode==OP_Found ){ |
| 70352 | | - if( u.bf.alreadyExists ) pc = pOp->p2 - 1; |
| 69879 | + if( alreadyExists ) pc = pOp->p2 - 1; |
| 70353 | 69880 | }else{ |
| 70354 | | - if( !u.bf.alreadyExists ) pc = pOp->p2 - 1; |
| 69881 | + if( !alreadyExists ) pc = pOp->p2 - 1; |
| 70355 | 69882 | } |
| 70356 | 69883 | break; |
| 70357 | 69884 | } |
| 70358 | 69885 | |
| 70359 | 69886 | /* Opcode: NotExists P1 P2 P3 * * |
| | @@ -70369,39 +69896,37 @@ |
| 70369 | 69896 | ** (with arbitrary multi-value keys). |
| 70370 | 69897 | ** |
| 70371 | 69898 | ** See also: Found, NotFound, NoConflict |
| 70372 | 69899 | */ |
| 70373 | 69900 | case OP_NotExists: { /* jump, in3 */ |
| 70374 | | -#if 0 /* local variables moved into u.bg */ |
| 70375 | 69901 | VdbeCursor *pC; |
| 70376 | 69902 | BtCursor *pCrsr; |
| 70377 | 69903 | int res; |
| 70378 | 69904 | u64 iKey; |
| 70379 | | -#endif /* local variables moved into u.bg */ |
| 70380 | 69905 | |
| 70381 | 69906 | pIn3 = &aMem[pOp->p3]; |
| 70382 | 69907 | assert( pIn3->flags & MEM_Int ); |
| 70383 | 69908 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70384 | | - u.bg.pC = p->apCsr[pOp->p1]; |
| 70385 | | - assert( u.bg.pC!=0 ); |
| 70386 | | - assert( u.bg.pC->isTable ); |
| 70387 | | - assert( u.bg.pC->pseudoTableReg==0 ); |
| 70388 | | - u.bg.pCrsr = u.bg.pC->pCursor; |
| 70389 | | - assert( u.bg.pCrsr!=0 ); |
| 70390 | | - u.bg.res = 0; |
| 70391 | | - u.bg.iKey = pIn3->u.i; |
| 70392 | | - rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res); |
| 70393 | | - u.bg.pC->lastRowid = pIn3->u.i; |
| 70394 | | - u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0; |
| 70395 | | - u.bg.pC->nullRow = 0; |
| 70396 | | - u.bg.pC->cacheStatus = CACHE_STALE; |
| 70397 | | - u.bg.pC->deferredMoveto = 0; |
| 70398 | | - if( u.bg.res!=0 ){ |
| 69909 | + pC = p->apCsr[pOp->p1]; |
| 69910 | + assert( pC!=0 ); |
| 69911 | + assert( pC->isTable ); |
| 69912 | + assert( pC->pseudoTableReg==0 ); |
| 69913 | + pCrsr = pC->pCursor; |
| 69914 | + assert( pCrsr!=0 ); |
| 69915 | + res = 0; |
| 69916 | + iKey = pIn3->u.i; |
| 69917 | + rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); |
| 69918 | + pC->lastRowid = pIn3->u.i; |
| 69919 | + pC->rowidIsValid = res==0 ?1:0; |
| 69920 | + pC->nullRow = 0; |
| 69921 | + pC->cacheStatus = CACHE_STALE; |
| 69922 | + pC->deferredMoveto = 0; |
| 69923 | + if( res!=0 ){ |
| 70399 | 69924 | pc = pOp->p2 - 1; |
| 70400 | | - assert( u.bg.pC->rowidIsValid==0 ); |
| 69925 | + assert( pC->rowidIsValid==0 ); |
| 70401 | 69926 | } |
| 70402 | | - u.bg.pC->seekResult = u.bg.res; |
| 69927 | + pC->seekResult = res; |
| 70403 | 69928 | break; |
| 70404 | 69929 | } |
| 70405 | 69930 | |
| 70406 | 69931 | /* Opcode: Sequence P1 P2 * * * |
| 70407 | 69932 | ** Synopsis: r[P2]=rowid |
| | @@ -70433,25 +69958,23 @@ |
| 70433 | 69958 | ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 70434 | 69959 | ** generated record number. This P3 mechanism is used to help implement the |
| 70435 | 69960 | ** AUTOINCREMENT feature. |
| 70436 | 69961 | */ |
| 70437 | 69962 | case OP_NewRowid: { /* out2-prerelease */ |
| 70438 | | -#if 0 /* local variables moved into u.bh */ |
| 70439 | 69963 | i64 v; /* The new rowid */ |
| 70440 | 69964 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 70441 | 69965 | int res; /* Result of an sqlite3BtreeLast() */ |
| 70442 | 69966 | int cnt; /* Counter to limit the number of searches */ |
| 70443 | 69967 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 70444 | 69968 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 70445 | | -#endif /* local variables moved into u.bh */ |
| 70446 | 69969 | |
| 70447 | | - u.bh.v = 0; |
| 70448 | | - u.bh.res = 0; |
| 69970 | + v = 0; |
| 69971 | + res = 0; |
| 70449 | 69972 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70450 | | - u.bh.pC = p->apCsr[pOp->p1]; |
| 70451 | | - assert( u.bh.pC!=0 ); |
| 70452 | | - if( NEVER(u.bh.pC->pCursor==0) ){ |
| 69973 | + pC = p->apCsr[pOp->p1]; |
| 69974 | + assert( pC!=0 ); |
| 69975 | + if( NEVER(pC->pCursor==0) ){ |
| 70453 | 69976 | /* The zero initialization above is all that is needed */ |
| 70454 | 69977 | }else{ |
| 70455 | 69978 | /* The next rowid or record number (different terms for the same |
| 70456 | 69979 | ** thing) is obtained in a two-step algorithm. |
| 70457 | 69980 | ** |
| | @@ -70463,11 +69986,11 @@ |
| 70463 | 69986 | ** The second algorithm is to select a rowid at random and see if |
| 70464 | 69987 | ** it already exists in the table. If it does not exist, we have |
| 70465 | 69988 | ** succeeded. If the random rowid does exist, we select a new one |
| 70466 | 69989 | ** and try again, up to 100 times. |
| 70467 | 69990 | */ |
| 70468 | | - assert( u.bh.pC->isTable ); |
| 69991 | + assert( pC->isTable ); |
| 70469 | 69992 | |
| 70470 | 69993 | #ifdef SQLITE_32BIT_ROWID |
| 70471 | 69994 | # define MAX_ROWID 0x7fffffff |
| 70472 | 69995 | #else |
| 70473 | 69996 | /* Some compilers complain about constants of the form 0x7fffffffffffffff. |
| | @@ -70475,101 +69998,101 @@ |
| 70475 | 69998 | ** to provide the constant while making all compilers happy. |
| 70476 | 69999 | */ |
| 70477 | 70000 | # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff ) |
| 70478 | 70001 | #endif |
| 70479 | 70002 | |
| 70480 | | - if( !u.bh.pC->useRandomRowid ){ |
| 70481 | | - u.bh.v = sqlite3BtreeGetCachedRowid(u.bh.pC->pCursor); |
| 70482 | | - if( u.bh.v==0 ){ |
| 70483 | | - rc = sqlite3BtreeLast(u.bh.pC->pCursor, &u.bh.res); |
| 70003 | + if( !pC->useRandomRowid ){ |
| 70004 | + v = sqlite3BtreeGetCachedRowid(pC->pCursor); |
| 70005 | + if( v==0 ){ |
| 70006 | + rc = sqlite3BtreeLast(pC->pCursor, &res); |
| 70484 | 70007 | if( rc!=SQLITE_OK ){ |
| 70485 | 70008 | goto abort_due_to_error; |
| 70486 | 70009 | } |
| 70487 | | - if( u.bh.res ){ |
| 70488 | | - u.bh.v = 1; /* IMP: R-61914-48074 */ |
| 70010 | + if( res ){ |
| 70011 | + v = 1; /* IMP: R-61914-48074 */ |
| 70489 | 70012 | }else{ |
| 70490 | | - assert( sqlite3BtreeCursorIsValid(u.bh.pC->pCursor) ); |
| 70491 | | - rc = sqlite3BtreeKeySize(u.bh.pC->pCursor, &u.bh.v); |
| 70013 | + assert( sqlite3BtreeCursorIsValid(pC->pCursor) ); |
| 70014 | + rc = sqlite3BtreeKeySize(pC->pCursor, &v); |
| 70492 | 70015 | assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ |
| 70493 | | - if( u.bh.v>=MAX_ROWID ){ |
| 70494 | | - u.bh.pC->useRandomRowid = 1; |
| 70016 | + if( v>=MAX_ROWID ){ |
| 70017 | + pC->useRandomRowid = 1; |
| 70495 | 70018 | }else{ |
| 70496 | | - u.bh.v++; /* IMP: R-29538-34987 */ |
| 70019 | + v++; /* IMP: R-29538-34987 */ |
| 70497 | 70020 | } |
| 70498 | 70021 | } |
| 70499 | 70022 | } |
| 70500 | 70023 | |
| 70501 | 70024 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 70502 | 70025 | if( pOp->p3 ){ |
| 70503 | 70026 | /* Assert that P3 is a valid memory cell. */ |
| 70504 | 70027 | assert( pOp->p3>0 ); |
| 70505 | 70028 | if( p->pFrame ){ |
| 70506 | | - for(u.bh.pFrame=p->pFrame; u.bh.pFrame->pParent; u.bh.pFrame=u.bh.pFrame->pParent); |
| 70029 | + for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 70507 | 70030 | /* Assert that P3 is a valid memory cell. */ |
| 70508 | | - assert( pOp->p3<=u.bh.pFrame->nMem ); |
| 70509 | | - u.bh.pMem = &u.bh.pFrame->aMem[pOp->p3]; |
| 70031 | + assert( pOp->p3<=pFrame->nMem ); |
| 70032 | + pMem = &pFrame->aMem[pOp->p3]; |
| 70510 | 70033 | }else{ |
| 70511 | 70034 | /* Assert that P3 is a valid memory cell. */ |
| 70512 | 70035 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 70513 | | - u.bh.pMem = &aMem[pOp->p3]; |
| 70514 | | - memAboutToChange(p, u.bh.pMem); |
| 70515 | | - } |
| 70516 | | - assert( memIsValid(u.bh.pMem) ); |
| 70517 | | - |
| 70518 | | - REGISTER_TRACE(pOp->p3, u.bh.pMem); |
| 70519 | | - sqlite3VdbeMemIntegerify(u.bh.pMem); |
| 70520 | | - assert( (u.bh.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ |
| 70521 | | - if( u.bh.pMem->u.i==MAX_ROWID || u.bh.pC->useRandomRowid ){ |
| 70036 | + pMem = &aMem[pOp->p3]; |
| 70037 | + memAboutToChange(p, pMem); |
| 70038 | + } |
| 70039 | + assert( memIsValid(pMem) ); |
| 70040 | + |
| 70041 | + REGISTER_TRACE(pOp->p3, pMem); |
| 70042 | + sqlite3VdbeMemIntegerify(pMem); |
| 70043 | + assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ |
| 70044 | + if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){ |
| 70522 | 70045 | rc = SQLITE_FULL; /* IMP: R-12275-61338 */ |
| 70523 | 70046 | goto abort_due_to_error; |
| 70524 | 70047 | } |
| 70525 | | - if( u.bh.v<u.bh.pMem->u.i+1 ){ |
| 70526 | | - u.bh.v = u.bh.pMem->u.i + 1; |
| 70048 | + if( v<pMem->u.i+1 ){ |
| 70049 | + v = pMem->u.i + 1; |
| 70527 | 70050 | } |
| 70528 | | - u.bh.pMem->u.i = u.bh.v; |
| 70051 | + pMem->u.i = v; |
| 70529 | 70052 | } |
| 70530 | 70053 | #endif |
| 70531 | 70054 | |
| 70532 | | - sqlite3BtreeSetCachedRowid(u.bh.pC->pCursor, u.bh.v<MAX_ROWID ? u.bh.v+1 : 0); |
| 70055 | + sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0); |
| 70533 | 70056 | } |
| 70534 | | - if( u.bh.pC->useRandomRowid ){ |
| 70057 | + if( pC->useRandomRowid ){ |
| 70535 | 70058 | /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the |
| 70536 | 70059 | ** largest possible integer (9223372036854775807) then the database |
| 70537 | 70060 | ** engine starts picking positive candidate ROWIDs at random until |
| 70538 | 70061 | ** it finds one that is not previously used. */ |
| 70539 | 70062 | assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is |
| 70540 | 70063 | ** an AUTOINCREMENT table. */ |
| 70541 | 70064 | /* on the first attempt, simply do one more than previous */ |
| 70542 | | - u.bh.v = lastRowid; |
| 70543 | | - u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 70544 | | - u.bh.v++; /* ensure non-zero */ |
| 70545 | | - u.bh.cnt = 0; |
| 70546 | | - while( ((rc = sqlite3BtreeMovetoUnpacked(u.bh.pC->pCursor, 0, (u64)u.bh.v, |
| 70547 | | - 0, &u.bh.res))==SQLITE_OK) |
| 70548 | | - && (u.bh.res==0) |
| 70549 | | - && (++u.bh.cnt<100)){ |
| 70065 | + v = lastRowid; |
| 70066 | + v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 70067 | + v++; /* ensure non-zero */ |
| 70068 | + cnt = 0; |
| 70069 | + while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v, |
| 70070 | + 0, &res))==SQLITE_OK) |
| 70071 | + && (res==0) |
| 70072 | + && (++cnt<100)){ |
| 70550 | 70073 | /* collision - try another random rowid */ |
| 70551 | | - sqlite3_randomness(sizeof(u.bh.v), &u.bh.v); |
| 70552 | | - if( u.bh.cnt<5 ){ |
| 70074 | + sqlite3_randomness(sizeof(v), &v); |
| 70075 | + if( cnt<5 ){ |
| 70553 | 70076 | /* try "small" random rowids for the initial attempts */ |
| 70554 | | - u.bh.v &= 0xffffff; |
| 70077 | + v &= 0xffffff; |
| 70555 | 70078 | }else{ |
| 70556 | | - u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 70079 | + v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 70557 | 70080 | } |
| 70558 | | - u.bh.v++; /* ensure non-zero */ |
| 70081 | + v++; /* ensure non-zero */ |
| 70559 | 70082 | } |
| 70560 | | - if( rc==SQLITE_OK && u.bh.res==0 ){ |
| 70083 | + if( rc==SQLITE_OK && res==0 ){ |
| 70561 | 70084 | rc = SQLITE_FULL; /* IMP: R-38219-53002 */ |
| 70562 | 70085 | goto abort_due_to_error; |
| 70563 | 70086 | } |
| 70564 | | - assert( u.bh.v>0 ); /* EV: R-40812-03570 */ |
| 70087 | + assert( v>0 ); /* EV: R-40812-03570 */ |
| 70565 | 70088 | } |
| 70566 | | - u.bh.pC->rowidIsValid = 0; |
| 70567 | | - u.bh.pC->deferredMoveto = 0; |
| 70568 | | - u.bh.pC->cacheStatus = CACHE_STALE; |
| 70089 | + pC->rowidIsValid = 0; |
| 70090 | + pC->deferredMoveto = 0; |
| 70091 | + pC->cacheStatus = CACHE_STALE; |
| 70569 | 70092 | } |
| 70570 | | - pOut->u.i = u.bh.v; |
| 70093 | + pOut->u.i = v; |
| 70571 | 70094 | break; |
| 70572 | 70095 | } |
| 70573 | 70096 | |
| 70574 | 70097 | /* Opcode: Insert P1 P2 P3 P4 P5 |
| 70575 | 70098 | ** Synopsis: intkey=r[P3] data=r[P2] |
| | @@ -70617,74 +70140,72 @@ |
| 70617 | 70140 | ** This works exactly like OP_Insert except that the key is the |
| 70618 | 70141 | ** integer value P3, not the value of the integer stored in register P3. |
| 70619 | 70142 | */ |
| 70620 | 70143 | case OP_Insert: |
| 70621 | 70144 | case OP_InsertInt: { |
| 70622 | | -#if 0 /* local variables moved into u.bi */ |
| 70623 | 70145 | Mem *pData; /* MEM cell holding data for the record to be inserted */ |
| 70624 | 70146 | Mem *pKey; /* MEM cell holding key for the record */ |
| 70625 | 70147 | i64 iKey; /* The integer ROWID or key for the record to be inserted */ |
| 70626 | 70148 | VdbeCursor *pC; /* Cursor to table into which insert is written */ |
| 70627 | 70149 | int nZero; /* Number of zero-bytes to append */ |
| 70628 | 70150 | int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ |
| 70629 | 70151 | const char *zDb; /* database name - used by the update hook */ |
| 70630 | 70152 | const char *zTbl; /* Table name - used by the opdate hook */ |
| 70631 | 70153 | int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ |
| 70632 | | -#endif /* local variables moved into u.bi */ |
| 70633 | 70154 | |
| 70634 | | - u.bi.pData = &aMem[pOp->p2]; |
| 70155 | + pData = &aMem[pOp->p2]; |
| 70635 | 70156 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70636 | | - assert( memIsValid(u.bi.pData) ); |
| 70637 | | - u.bi.pC = p->apCsr[pOp->p1]; |
| 70638 | | - assert( u.bi.pC!=0 ); |
| 70639 | | - assert( u.bi.pC->pCursor!=0 ); |
| 70640 | | - assert( u.bi.pC->pseudoTableReg==0 ); |
| 70641 | | - assert( u.bi.pC->isTable ); |
| 70642 | | - REGISTER_TRACE(pOp->p2, u.bi.pData); |
| 70157 | + assert( memIsValid(pData) ); |
| 70158 | + pC = p->apCsr[pOp->p1]; |
| 70159 | + assert( pC!=0 ); |
| 70160 | + assert( pC->pCursor!=0 ); |
| 70161 | + assert( pC->pseudoTableReg==0 ); |
| 70162 | + assert( pC->isTable ); |
| 70163 | + REGISTER_TRACE(pOp->p2, pData); |
| 70643 | 70164 | |
| 70644 | 70165 | if( pOp->opcode==OP_Insert ){ |
| 70645 | | - u.bi.pKey = &aMem[pOp->p3]; |
| 70646 | | - assert( u.bi.pKey->flags & MEM_Int ); |
| 70647 | | - assert( memIsValid(u.bi.pKey) ); |
| 70648 | | - REGISTER_TRACE(pOp->p3, u.bi.pKey); |
| 70649 | | - u.bi.iKey = u.bi.pKey->u.i; |
| 70166 | + pKey = &aMem[pOp->p3]; |
| 70167 | + assert( pKey->flags & MEM_Int ); |
| 70168 | + assert( memIsValid(pKey) ); |
| 70169 | + REGISTER_TRACE(pOp->p3, pKey); |
| 70170 | + iKey = pKey->u.i; |
| 70650 | 70171 | }else{ |
| 70651 | 70172 | assert( pOp->opcode==OP_InsertInt ); |
| 70652 | | - u.bi.iKey = pOp->p3; |
| 70173 | + iKey = pOp->p3; |
| 70653 | 70174 | } |
| 70654 | 70175 | |
| 70655 | 70176 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 70656 | | - if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bi.iKey; |
| 70657 | | - if( u.bi.pData->flags & MEM_Null ){ |
| 70658 | | - u.bi.pData->z = 0; |
| 70659 | | - u.bi.pData->n = 0; |
| 70660 | | - }else{ |
| 70661 | | - assert( u.bi.pData->flags & (MEM_Blob|MEM_Str) ); |
| 70662 | | - } |
| 70663 | | - u.bi.seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bi.pC->seekResult : 0); |
| 70664 | | - if( u.bi.pData->flags & MEM_Zero ){ |
| 70665 | | - u.bi.nZero = u.bi.pData->u.nZero; |
| 70666 | | - }else{ |
| 70667 | | - u.bi.nZero = 0; |
| 70668 | | - } |
| 70669 | | - sqlite3BtreeSetCachedRowid(u.bi.pC->pCursor, 0); |
| 70670 | | - rc = sqlite3BtreeInsert(u.bi.pC->pCursor, 0, u.bi.iKey, |
| 70671 | | - u.bi.pData->z, u.bi.pData->n, u.bi.nZero, |
| 70672 | | - (pOp->p5 & OPFLAG_APPEND)!=0, u.bi.seekResult |
| 70177 | + if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey; |
| 70178 | + if( pData->flags & MEM_Null ){ |
| 70179 | + pData->z = 0; |
| 70180 | + pData->n = 0; |
| 70181 | + }else{ |
| 70182 | + assert( pData->flags & (MEM_Blob|MEM_Str) ); |
| 70183 | + } |
| 70184 | + seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0); |
| 70185 | + if( pData->flags & MEM_Zero ){ |
| 70186 | + nZero = pData->u.nZero; |
| 70187 | + }else{ |
| 70188 | + nZero = 0; |
| 70189 | + } |
| 70190 | + sqlite3BtreeSetCachedRowid(pC->pCursor, 0); |
| 70191 | + rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, |
| 70192 | + pData->z, pData->n, nZero, |
| 70193 | + (pOp->p5 & OPFLAG_APPEND)!=0, seekResult |
| 70673 | 70194 | ); |
| 70674 | | - u.bi.pC->rowidIsValid = 0; |
| 70675 | | - u.bi.pC->deferredMoveto = 0; |
| 70676 | | - u.bi.pC->cacheStatus = CACHE_STALE; |
| 70195 | + pC->rowidIsValid = 0; |
| 70196 | + pC->deferredMoveto = 0; |
| 70197 | + pC->cacheStatus = CACHE_STALE; |
| 70677 | 70198 | |
| 70678 | 70199 | /* Invoke the update-hook if required. */ |
| 70679 | 70200 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){ |
| 70680 | | - u.bi.zDb = db->aDb[u.bi.pC->iDb].zName; |
| 70681 | | - u.bi.zTbl = pOp->p4.z; |
| 70682 | | - u.bi.op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); |
| 70683 | | - assert( u.bi.pC->isTable ); |
| 70684 | | - db->xUpdateCallback(db->pUpdateArg, u.bi.op, u.bi.zDb, u.bi.zTbl, u.bi.iKey); |
| 70685 | | - assert( u.bi.pC->iDb>=0 ); |
| 70201 | + zDb = db->aDb[pC->iDb].zName; |
| 70202 | + zTbl = pOp->p4.z; |
| 70203 | + op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); |
| 70204 | + assert( pC->isTable ); |
| 70205 | + db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey); |
| 70206 | + assert( pC->iDb>=0 ); |
| 70686 | 70207 | } |
| 70687 | 70208 | break; |
| 70688 | 70209 | } |
| 70689 | 70210 | |
| 70690 | 70211 | /* Opcode: Delete P1 P2 * P4 * |
| | @@ -70706,41 +70227,39 @@ |
| 70706 | 70227 | ** pointing to. The update hook will be invoked, if it exists. |
| 70707 | 70228 | ** If P4 is not NULL then the P1 cursor must have been positioned |
| 70708 | 70229 | ** using OP_NotFound prior to invoking this opcode. |
| 70709 | 70230 | */ |
| 70710 | 70231 | case OP_Delete: { |
| 70711 | | -#if 0 /* local variables moved into u.bj */ |
| 70712 | 70232 | i64 iKey; |
| 70713 | 70233 | VdbeCursor *pC; |
| 70714 | | -#endif /* local variables moved into u.bj */ |
| 70715 | 70234 | |
| 70716 | 70235 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70717 | | - u.bj.pC = p->apCsr[pOp->p1]; |
| 70718 | | - assert( u.bj.pC!=0 ); |
| 70719 | | - assert( u.bj.pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ |
| 70720 | | - u.bj.iKey = u.bj.pC->lastRowid; /* Only used for the update hook */ |
| 70236 | + pC = p->apCsr[pOp->p1]; |
| 70237 | + assert( pC!=0 ); |
| 70238 | + assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ |
| 70239 | + iKey = pC->lastRowid; /* Only used for the update hook */ |
| 70721 | 70240 | |
| 70722 | 70241 | /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or |
| 70723 | 70242 | ** OP_Column on the same table without any intervening operations that |
| 70724 | | - ** might move or invalidate the cursor. Hence cursor u.bj.pC is always pointing |
| 70243 | + ** might move or invalidate the cursor. Hence cursor pC is always pointing |
| 70725 | 70244 | ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation |
| 70726 | 70245 | ** below is always a no-op and cannot fail. We will run it anyhow, though, |
| 70727 | 70246 | ** to guard against future changes to the code generator. |
| 70728 | 70247 | **/ |
| 70729 | | - assert( u.bj.pC->deferredMoveto==0 ); |
| 70730 | | - rc = sqlite3VdbeCursorMoveto(u.bj.pC); |
| 70248 | + assert( pC->deferredMoveto==0 ); |
| 70249 | + rc = sqlite3VdbeCursorMoveto(pC); |
| 70731 | 70250 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70732 | 70251 | |
| 70733 | | - sqlite3BtreeSetCachedRowid(u.bj.pC->pCursor, 0); |
| 70734 | | - rc = sqlite3BtreeDelete(u.bj.pC->pCursor); |
| 70735 | | - u.bj.pC->cacheStatus = CACHE_STALE; |
| 70252 | + sqlite3BtreeSetCachedRowid(pC->pCursor, 0); |
| 70253 | + rc = sqlite3BtreeDelete(pC->pCursor); |
| 70254 | + pC->cacheStatus = CACHE_STALE; |
| 70736 | 70255 | |
| 70737 | 70256 | /* Invoke the update-hook if required. */ |
| 70738 | | - if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && u.bj.pC->isTable ){ |
| 70257 | + if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ |
| 70739 | 70258 | db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 70740 | | - db->aDb[u.bj.pC->iDb].zName, pOp->p4.z, u.bj.iKey); |
| 70741 | | - assert( u.bj.pC->iDb>=0 ); |
| 70259 | + db->aDb[pC->iDb].zName, pOp->p4.z, iKey); |
| 70260 | + assert( pC->iDb>=0 ); |
| 70742 | 70261 | } |
| 70743 | 70262 | if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| 70744 | 70263 | break; |
| 70745 | 70264 | } |
| 70746 | 70265 | /* Opcode: ResetCount * * * * * |
| | @@ -70770,23 +70289,21 @@ |
| 70770 | 70289 | ** |
| 70771 | 70290 | ** Fall through to next instruction if the two records compare equal to |
| 70772 | 70291 | ** each other. Jump to P2 if they are different. |
| 70773 | 70292 | */ |
| 70774 | 70293 | case OP_SorterCompare: { |
| 70775 | | -#if 0 /* local variables moved into u.bk */ |
| 70776 | 70294 | VdbeCursor *pC; |
| 70777 | 70295 | int res; |
| 70778 | 70296 | int nIgnore; |
| 70779 | | -#endif /* local variables moved into u.bk */ |
| 70780 | 70297 | |
| 70781 | | - u.bk.pC = p->apCsr[pOp->p1]; |
| 70782 | | - assert( isSorter(u.bk.pC) ); |
| 70298 | + pC = p->apCsr[pOp->p1]; |
| 70299 | + assert( isSorter(pC) ); |
| 70783 | 70300 | assert( pOp->p4type==P4_INT32 ); |
| 70784 | 70301 | pIn3 = &aMem[pOp->p3]; |
| 70785 | | - u.bk.nIgnore = pOp->p4.i; |
| 70786 | | - rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res); |
| 70787 | | - if( u.bk.res ){ |
| 70302 | + nIgnore = pOp->p4.i; |
| 70303 | + rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res); |
| 70304 | + if( res ){ |
| 70788 | 70305 | pc = pOp->p2-1; |
| 70789 | 70306 | } |
| 70790 | 70307 | break; |
| 70791 | 70308 | }; |
| 70792 | 70309 | |
| | @@ -70794,18 +70311,16 @@ |
| 70794 | 70311 | ** Synopsis: r[P2]=data |
| 70795 | 70312 | ** |
| 70796 | 70313 | ** Write into register P2 the current sorter data for sorter cursor P1. |
| 70797 | 70314 | */ |
| 70798 | 70315 | case OP_SorterData: { |
| 70799 | | -#if 0 /* local variables moved into u.bl */ |
| 70800 | 70316 | VdbeCursor *pC; |
| 70801 | | -#endif /* local variables moved into u.bl */ |
| 70802 | 70317 | |
| 70803 | 70318 | pOut = &aMem[pOp->p2]; |
| 70804 | | - u.bl.pC = p->apCsr[pOp->p1]; |
| 70805 | | - assert( isSorter(u.bl.pC) ); |
| 70806 | | - rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut); |
| 70319 | + pC = p->apCsr[pOp->p1]; |
| 70320 | + assert( isSorter(pC) ); |
| 70321 | + rc = sqlite3VdbeSorterRowkey(pC, pOut); |
| 70807 | 70322 | break; |
| 70808 | 70323 | } |
| 70809 | 70324 | |
| 70810 | 70325 | /* Opcode: RowData P1 P2 * * * |
| 70811 | 70326 | ** Synopsis: r[P2]=data |
| | @@ -70829,66 +70344,64 @@ |
| 70829 | 70344 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 70830 | 70345 | ** of a real table, not a pseudo-table. |
| 70831 | 70346 | */ |
| 70832 | 70347 | case OP_RowKey: |
| 70833 | 70348 | case OP_RowData: { |
| 70834 | | -#if 0 /* local variables moved into u.bm */ |
| 70835 | 70349 | VdbeCursor *pC; |
| 70836 | 70350 | BtCursor *pCrsr; |
| 70837 | 70351 | u32 n; |
| 70838 | 70352 | i64 n64; |
| 70839 | | -#endif /* local variables moved into u.bm */ |
| 70840 | 70353 | |
| 70841 | 70354 | pOut = &aMem[pOp->p2]; |
| 70842 | 70355 | memAboutToChange(p, pOut); |
| 70843 | 70356 | |
| 70844 | 70357 | /* Note that RowKey and RowData are really exactly the same instruction */ |
| 70845 | 70358 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70846 | | - u.bm.pC = p->apCsr[pOp->p1]; |
| 70847 | | - assert( isSorter(u.bm.pC)==0 ); |
| 70848 | | - assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData ); |
| 70849 | | - assert( u.bm.pC->isTable==0 || pOp->opcode==OP_RowData ); |
| 70850 | | - assert( u.bm.pC!=0 ); |
| 70851 | | - assert( u.bm.pC->nullRow==0 ); |
| 70852 | | - assert( u.bm.pC->pseudoTableReg==0 ); |
| 70853 | | - assert( u.bm.pC->pCursor!=0 ); |
| 70854 | | - u.bm.pCrsr = u.bm.pC->pCursor; |
| 70855 | | - assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) ); |
| 70359 | + pC = p->apCsr[pOp->p1]; |
| 70360 | + assert( isSorter(pC)==0 ); |
| 70361 | + assert( pC->isTable || pOp->opcode!=OP_RowData ); |
| 70362 | + assert( pC->isTable==0 || pOp->opcode==OP_RowData ); |
| 70363 | + assert( pC!=0 ); |
| 70364 | + assert( pC->nullRow==0 ); |
| 70365 | + assert( pC->pseudoTableReg==0 ); |
| 70366 | + assert( pC->pCursor!=0 ); |
| 70367 | + pCrsr = pC->pCursor; |
| 70368 | + assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 70856 | 70369 | |
| 70857 | 70370 | /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or |
| 70858 | 70371 | ** OP_Rewind/Op_Next with no intervening instructions that might invalidate |
| 70859 | 70372 | ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always |
| 70860 | 70373 | ** a no-op and can never fail. But we leave it in place as a safety. |
| 70861 | 70374 | */ |
| 70862 | | - assert( u.bm.pC->deferredMoveto==0 ); |
| 70863 | | - rc = sqlite3VdbeCursorMoveto(u.bm.pC); |
| 70864 | | - if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70865 | | - |
| 70866 | | - if( u.bm.pC->isTable==0 ){ |
| 70867 | | - assert( !u.bm.pC->isTable ); |
| 70868 | | - VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64); |
| 70869 | | - assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 70870 | | - if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70871 | | - goto too_big; |
| 70872 | | - } |
| 70873 | | - u.bm.n = (u32)u.bm.n64; |
| 70874 | | - }else{ |
| 70875 | | - VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bm.pCrsr, &u.bm.n); |
| 70876 | | - assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 70877 | | - if( u.bm.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70878 | | - goto too_big; |
| 70879 | | - } |
| 70880 | | - } |
| 70881 | | - if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){ |
| 70882 | | - goto no_mem; |
| 70883 | | - } |
| 70884 | | - pOut->n = u.bm.n; |
| 70885 | | - MemSetTypeFlag(pOut, MEM_Blob); |
| 70886 | | - if( u.bm.pC->isTable==0 ){ |
| 70887 | | - rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z); |
| 70888 | | - }else{ |
| 70889 | | - rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z); |
| 70375 | + assert( pC->deferredMoveto==0 ); |
| 70376 | + rc = sqlite3VdbeCursorMoveto(pC); |
| 70377 | + if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70378 | + |
| 70379 | + if( pC->isTable==0 ){ |
| 70380 | + assert( !pC->isTable ); |
| 70381 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64); |
| 70382 | + assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 70383 | + if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70384 | + goto too_big; |
| 70385 | + } |
| 70386 | + n = (u32)n64; |
| 70387 | + }else{ |
| 70388 | + VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n); |
| 70389 | + assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 70390 | + if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70391 | + goto too_big; |
| 70392 | + } |
| 70393 | + } |
| 70394 | + if( sqlite3VdbeMemGrow(pOut, n, 0) ){ |
| 70395 | + goto no_mem; |
| 70396 | + } |
| 70397 | + pOut->n = n; |
| 70398 | + MemSetTypeFlag(pOut, MEM_Blob); |
| 70399 | + if( pC->isTable==0 ){ |
| 70400 | + rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z); |
| 70401 | + }else{ |
| 70402 | + rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z); |
| 70890 | 70403 | } |
| 70891 | 70404 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ |
| 70892 | 70405 | UPDATE_MAX_BLOBSIZE(pOut); |
| 70893 | 70406 | REGISTER_TRACE(pOp->p2, pOut); |
| 70894 | 70407 | break; |
| | @@ -70903,46 +70416,44 @@ |
| 70903 | 70416 | ** P1 can be either an ordinary table or a virtual table. There used to |
| 70904 | 70417 | ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 70905 | 70418 | ** one opcode now works for both table types. |
| 70906 | 70419 | */ |
| 70907 | 70420 | case OP_Rowid: { /* out2-prerelease */ |
| 70908 | | -#if 0 /* local variables moved into u.bn */ |
| 70909 | 70421 | VdbeCursor *pC; |
| 70910 | 70422 | i64 v; |
| 70911 | 70423 | sqlite3_vtab *pVtab; |
| 70912 | 70424 | const sqlite3_module *pModule; |
| 70913 | | -#endif /* local variables moved into u.bn */ |
| 70914 | 70425 | |
| 70915 | 70426 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70916 | | - u.bn.pC = p->apCsr[pOp->p1]; |
| 70917 | | - assert( u.bn.pC!=0 ); |
| 70918 | | - assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow ); |
| 70919 | | - if( u.bn.pC->nullRow ){ |
| 70427 | + pC = p->apCsr[pOp->p1]; |
| 70428 | + assert( pC!=0 ); |
| 70429 | + assert( pC->pseudoTableReg==0 || pC->nullRow ); |
| 70430 | + if( pC->nullRow ){ |
| 70920 | 70431 | pOut->flags = MEM_Null; |
| 70921 | 70432 | break; |
| 70922 | | - }else if( u.bn.pC->deferredMoveto ){ |
| 70923 | | - u.bn.v = u.bn.pC->movetoTarget; |
| 70433 | + }else if( pC->deferredMoveto ){ |
| 70434 | + v = pC->movetoTarget; |
| 70924 | 70435 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 70925 | | - }else if( u.bn.pC->pVtabCursor ){ |
| 70926 | | - u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab; |
| 70927 | | - u.bn.pModule = u.bn.pVtab->pModule; |
| 70928 | | - assert( u.bn.pModule->xRowid ); |
| 70929 | | - rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v); |
| 70930 | | - sqlite3VtabImportErrmsg(p, u.bn.pVtab); |
| 70436 | + }else if( pC->pVtabCursor ){ |
| 70437 | + pVtab = pC->pVtabCursor->pVtab; |
| 70438 | + pModule = pVtab->pModule; |
| 70439 | + assert( pModule->xRowid ); |
| 70440 | + rc = pModule->xRowid(pC->pVtabCursor, &v); |
| 70441 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 70931 | 70442 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 70932 | 70443 | }else{ |
| 70933 | | - assert( u.bn.pC->pCursor!=0 ); |
| 70934 | | - rc = sqlite3VdbeCursorMoveto(u.bn.pC); |
| 70444 | + assert( pC->pCursor!=0 ); |
| 70445 | + rc = sqlite3VdbeCursorMoveto(pC); |
| 70935 | 70446 | if( rc ) goto abort_due_to_error; |
| 70936 | | - if( u.bn.pC->rowidIsValid ){ |
| 70937 | | - u.bn.v = u.bn.pC->lastRowid; |
| 70447 | + if( pC->rowidIsValid ){ |
| 70448 | + v = pC->lastRowid; |
| 70938 | 70449 | }else{ |
| 70939 | | - rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v); |
| 70450 | + rc = sqlite3BtreeKeySize(pC->pCursor, &v); |
| 70940 | 70451 | assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */ |
| 70941 | 70452 | } |
| 70942 | 70453 | } |
| 70943 | | - pOut->u.i = u.bn.v; |
| 70454 | + pOut->u.i = v; |
| 70944 | 70455 | break; |
| 70945 | 70456 | } |
| 70946 | 70457 | |
| 70947 | 70458 | /* Opcode: NullRow P1 * * * * |
| 70948 | 70459 | ** |
| | @@ -70949,23 +70460,21 @@ |
| 70949 | 70460 | ** Move the cursor P1 to a null row. Any OP_Column operations |
| 70950 | 70461 | ** that occur while the cursor is on the null row will always |
| 70951 | 70462 | ** write a NULL. |
| 70952 | 70463 | */ |
| 70953 | 70464 | case OP_NullRow: { |
| 70954 | | -#if 0 /* local variables moved into u.bo */ |
| 70955 | 70465 | VdbeCursor *pC; |
| 70956 | | -#endif /* local variables moved into u.bo */ |
| 70957 | 70466 | |
| 70958 | 70467 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70959 | | - u.bo.pC = p->apCsr[pOp->p1]; |
| 70960 | | - assert( u.bo.pC!=0 ); |
| 70961 | | - u.bo.pC->nullRow = 1; |
| 70962 | | - u.bo.pC->rowidIsValid = 0; |
| 70963 | | - u.bo.pC->cacheStatus = CACHE_STALE; |
| 70964 | | - assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor ); |
| 70965 | | - if( u.bo.pC->pCursor ){ |
| 70966 | | - sqlite3BtreeClearCursor(u.bo.pC->pCursor); |
| 70468 | + pC = p->apCsr[pOp->p1]; |
| 70469 | + assert( pC!=0 ); |
| 70470 | + pC->nullRow = 1; |
| 70471 | + pC->rowidIsValid = 0; |
| 70472 | + pC->cacheStatus = CACHE_STALE; |
| 70473 | + assert( pC->pCursor || pC->pVtabCursor ); |
| 70474 | + if( pC->pCursor ){ |
| 70475 | + sqlite3BtreeClearCursor(pC->pCursor); |
| 70967 | 70476 | } |
| 70968 | 70477 | break; |
| 70969 | 70478 | } |
| 70970 | 70479 | |
| 70971 | 70480 | /* Opcode: Last P1 P2 * * * |
| | @@ -70975,28 +70484,26 @@ |
| 70975 | 70484 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 70976 | 70485 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 70977 | 70486 | ** to the following instruction. |
| 70978 | 70487 | */ |
| 70979 | 70488 | case OP_Last: { /* jump */ |
| 70980 | | -#if 0 /* local variables moved into u.bp */ |
| 70981 | 70489 | VdbeCursor *pC; |
| 70982 | 70490 | BtCursor *pCrsr; |
| 70983 | 70491 | int res; |
| 70984 | | -#endif /* local variables moved into u.bp */ |
| 70985 | 70492 | |
| 70986 | 70493 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70987 | | - u.bp.pC = p->apCsr[pOp->p1]; |
| 70988 | | - assert( u.bp.pC!=0 ); |
| 70989 | | - u.bp.pCrsr = u.bp.pC->pCursor; |
| 70990 | | - u.bp.res = 0; |
| 70991 | | - assert( u.bp.pCrsr!=0 ); |
| 70992 | | - rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res); |
| 70993 | | - u.bp.pC->nullRow = (u8)u.bp.res; |
| 70994 | | - u.bp.pC->deferredMoveto = 0; |
| 70995 | | - u.bp.pC->rowidIsValid = 0; |
| 70996 | | - u.bp.pC->cacheStatus = CACHE_STALE; |
| 70997 | | - if( pOp->p2>0 && u.bp.res ){ |
| 70494 | + pC = p->apCsr[pOp->p1]; |
| 70495 | + assert( pC!=0 ); |
| 70496 | + pCrsr = pC->pCursor; |
| 70497 | + res = 0; |
| 70498 | + assert( pCrsr!=0 ); |
| 70499 | + rc = sqlite3BtreeLast(pCrsr, &res); |
| 70500 | + pC->nullRow = (u8)res; |
| 70501 | + pC->deferredMoveto = 0; |
| 70502 | + pC->rowidIsValid = 0; |
| 70503 | + pC->cacheStatus = CACHE_STALE; |
| 70504 | + if( pOp->p2>0 && res ){ |
| 70998 | 70505 | pc = pOp->p2 - 1; |
| 70999 | 70506 | } |
| 71000 | 70507 | break; |
| 71001 | 70508 | } |
| 71002 | 70509 | |
| | @@ -71029,34 +70536,32 @@ |
| 71029 | 70536 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 71030 | 70537 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 71031 | 70538 | ** to the following instruction. |
| 71032 | 70539 | */ |
| 71033 | 70540 | case OP_Rewind: { /* jump */ |
| 71034 | | -#if 0 /* local variables moved into u.bq */ |
| 71035 | 70541 | VdbeCursor *pC; |
| 71036 | 70542 | BtCursor *pCrsr; |
| 71037 | 70543 | int res; |
| 71038 | | -#endif /* local variables moved into u.bq */ |
| 71039 | 70544 | |
| 71040 | 70545 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71041 | | - u.bq.pC = p->apCsr[pOp->p1]; |
| 71042 | | - assert( u.bq.pC!=0 ); |
| 71043 | | - assert( isSorter(u.bq.pC)==(pOp->opcode==OP_SorterSort) ); |
| 71044 | | - u.bq.res = 1; |
| 71045 | | - if( isSorter(u.bq.pC) ){ |
| 71046 | | - rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res); |
| 70546 | + pC = p->apCsr[pOp->p1]; |
| 70547 | + assert( pC!=0 ); |
| 70548 | + assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) ); |
| 70549 | + res = 1; |
| 70550 | + if( isSorter(pC) ){ |
| 70551 | + rc = sqlite3VdbeSorterRewind(db, pC, &res); |
| 71047 | 70552 | }else{ |
| 71048 | | - u.bq.pCrsr = u.bq.pC->pCursor; |
| 71049 | | - assert( u.bq.pCrsr ); |
| 71050 | | - rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res); |
| 71051 | | - u.bq.pC->deferredMoveto = 0; |
| 71052 | | - u.bq.pC->cacheStatus = CACHE_STALE; |
| 71053 | | - u.bq.pC->rowidIsValid = 0; |
| 71054 | | - } |
| 71055 | | - u.bq.pC->nullRow = (u8)u.bq.res; |
| 70553 | + pCrsr = pC->pCursor; |
| 70554 | + assert( pCrsr ); |
| 70555 | + rc = sqlite3BtreeFirst(pCrsr, &res); |
| 70556 | + pC->deferredMoveto = 0; |
| 70557 | + pC->cacheStatus = CACHE_STALE; |
| 70558 | + pC->rowidIsValid = 0; |
| 70559 | + } |
| 70560 | + pC->nullRow = (u8)res; |
| 71056 | 70561 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 71057 | | - if( u.bq.res ){ |
| 70562 | + if( res ){ |
| 71058 | 70563 | pc = pOp->p2 - 1; |
| 71059 | 70564 | } |
| 71060 | 70565 | break; |
| 71061 | 70566 | } |
| 71062 | 70567 | |
| | @@ -71103,49 +70608,47 @@ |
| 71103 | 70608 | ** |
| 71104 | 70609 | ** This opcode works just like OP_Prev except that if cursor P1 is not |
| 71105 | 70610 | ** open it behaves a no-op. |
| 71106 | 70611 | */ |
| 71107 | 70612 | case OP_SorterNext: { /* jump */ |
| 71108 | | -#if 0 /* local variables moved into u.br */ |
| 71109 | 70613 | VdbeCursor *pC; |
| 71110 | 70614 | int res; |
| 71111 | | -#endif /* local variables moved into u.br */ |
| 71112 | 70615 | |
| 71113 | | - u.br.pC = p->apCsr[pOp->p1]; |
| 71114 | | - assert( isSorter(u.br.pC) ); |
| 71115 | | - rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res); |
| 70616 | + pC = p->apCsr[pOp->p1]; |
| 70617 | + assert( isSorter(pC) ); |
| 70618 | + rc = sqlite3VdbeSorterNext(db, pC, &res); |
| 71116 | 70619 | goto next_tail; |
| 71117 | 70620 | case OP_PrevIfOpen: /* jump */ |
| 71118 | 70621 | case OP_NextIfOpen: /* jump */ |
| 71119 | 70622 | if( p->apCsr[pOp->p1]==0 ) break; |
| 71120 | 70623 | /* Fall through */ |
| 71121 | 70624 | case OP_Prev: /* jump */ |
| 71122 | 70625 | case OP_Next: /* jump */ |
| 71123 | 70626 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71124 | 70627 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 71125 | | - u.br.pC = p->apCsr[pOp->p1]; |
| 71126 | | - assert( u.br.pC!=0 ); |
| 71127 | | - assert( u.br.pC->deferredMoveto==0 ); |
| 71128 | | - assert( u.br.pC->pCursor ); |
| 70628 | + pC = p->apCsr[pOp->p1]; |
| 70629 | + assert( pC!=0 ); |
| 70630 | + assert( pC->deferredMoveto==0 ); |
| 70631 | + assert( pC->pCursor ); |
| 71129 | 70632 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 71130 | 70633 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 71131 | 70634 | assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 71132 | 70635 | assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); |
| 71133 | | - rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res); |
| 70636 | + rc = pOp->p4.xAdvance(pC->pCursor, &res); |
| 71134 | 70637 | next_tail: |
| 71135 | | - u.br.pC->cacheStatus = CACHE_STALE; |
| 71136 | | - if( u.br.res==0 ){ |
| 71137 | | - u.br.pC->nullRow = 0; |
| 70638 | + pC->cacheStatus = CACHE_STALE; |
| 70639 | + if( res==0 ){ |
| 70640 | + pC->nullRow = 0; |
| 71138 | 70641 | pc = pOp->p2 - 1; |
| 71139 | 70642 | p->aCounter[pOp->p5]++; |
| 71140 | 70643 | #ifdef SQLITE_TEST |
| 71141 | 70644 | sqlite3_search_count++; |
| 71142 | 70645 | #endif |
| 71143 | 70646 | }else{ |
| 71144 | | - u.br.pC->nullRow = 1; |
| 70647 | + pC->nullRow = 1; |
| 71145 | 70648 | } |
| 71146 | | - u.br.pC->rowidIsValid = 0; |
| 70649 | + pC->rowidIsValid = 0; |
| 71147 | 70650 | goto check_for_interrupt; |
| 71148 | 70651 | } |
| 71149 | 70652 | |
| 71150 | 70653 | /* Opcode: IdxInsert P1 P2 P3 * P5 |
| 71151 | 70654 | ** Synopsis: key=r[P2] |
| | @@ -71160,39 +70663,37 @@ |
| 71160 | 70663 | ** This instruction only works for indices. The equivalent instruction |
| 71161 | 70664 | ** for tables is OP_Insert. |
| 71162 | 70665 | */ |
| 71163 | 70666 | case OP_SorterInsert: /* in2 */ |
| 71164 | 70667 | case OP_IdxInsert: { /* in2 */ |
| 71165 | | -#if 0 /* local variables moved into u.bs */ |
| 71166 | 70668 | VdbeCursor *pC; |
| 71167 | 70669 | BtCursor *pCrsr; |
| 71168 | 70670 | int nKey; |
| 71169 | 70671 | const char *zKey; |
| 71170 | | -#endif /* local variables moved into u.bs */ |
| 71171 | 70672 | |
| 71172 | 70673 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71173 | | - u.bs.pC = p->apCsr[pOp->p1]; |
| 71174 | | - assert( u.bs.pC!=0 ); |
| 71175 | | - assert( isSorter(u.bs.pC)==(pOp->opcode==OP_SorterInsert) ); |
| 70674 | + pC = p->apCsr[pOp->p1]; |
| 70675 | + assert( pC!=0 ); |
| 70676 | + assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) ); |
| 71176 | 70677 | pIn2 = &aMem[pOp->p2]; |
| 71177 | 70678 | assert( pIn2->flags & MEM_Blob ); |
| 71178 | | - u.bs.pCrsr = u.bs.pC->pCursor; |
| 70679 | + pCrsr = pC->pCursor; |
| 71179 | 70680 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 71180 | | - assert( u.bs.pCrsr!=0 ); |
| 71181 | | - assert( u.bs.pC->isTable==0 ); |
| 70681 | + assert( pCrsr!=0 ); |
| 70682 | + assert( pC->isTable==0 ); |
| 71182 | 70683 | rc = ExpandBlob(pIn2); |
| 71183 | 70684 | if( rc==SQLITE_OK ){ |
| 71184 | | - if( isSorter(u.bs.pC) ){ |
| 71185 | | - rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2); |
| 70685 | + if( isSorter(pC) ){ |
| 70686 | + rc = sqlite3VdbeSorterWrite(db, pC, pIn2); |
| 71186 | 70687 | }else{ |
| 71187 | | - u.bs.nKey = pIn2->n; |
| 71188 | | - u.bs.zKey = pIn2->z; |
| 71189 | | - rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3, |
| 71190 | | - ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0) |
| 70688 | + nKey = pIn2->n; |
| 70689 | + zKey = pIn2->z; |
| 70690 | + rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3, |
| 70691 | + ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 71191 | 70692 | ); |
| 71192 | | - assert( u.bs.pC->deferredMoveto==0 ); |
| 71193 | | - u.bs.pC->cacheStatus = CACHE_STALE; |
| 70693 | + assert( pC->deferredMoveto==0 ); |
| 70694 | + pC->cacheStatus = CACHE_STALE; |
| 71194 | 70695 | } |
| 71195 | 70696 | } |
| 71196 | 70697 | break; |
| 71197 | 70698 | } |
| 71198 | 70699 | |
| | @@ -71202,38 +70703,36 @@ |
| 71202 | 70703 | ** The content of P3 registers starting at register P2 form |
| 71203 | 70704 | ** an unpacked index key. This opcode removes that entry from the |
| 71204 | 70705 | ** index opened by cursor P1. |
| 71205 | 70706 | */ |
| 71206 | 70707 | case OP_IdxDelete: { |
| 71207 | | -#if 0 /* local variables moved into u.bt */ |
| 71208 | 70708 | VdbeCursor *pC; |
| 71209 | 70709 | BtCursor *pCrsr; |
| 71210 | 70710 | int res; |
| 71211 | 70711 | UnpackedRecord r; |
| 71212 | | -#endif /* local variables moved into u.bt */ |
| 71213 | 70712 | |
| 71214 | 70713 | assert( pOp->p3>0 ); |
| 71215 | 70714 | assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 ); |
| 71216 | 70715 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71217 | | - u.bt.pC = p->apCsr[pOp->p1]; |
| 71218 | | - assert( u.bt.pC!=0 ); |
| 71219 | | - u.bt.pCrsr = u.bt.pC->pCursor; |
| 71220 | | - assert( u.bt.pCrsr!=0 ); |
| 70716 | + pC = p->apCsr[pOp->p1]; |
| 70717 | + assert( pC!=0 ); |
| 70718 | + pCrsr = pC->pCursor; |
| 70719 | + assert( pCrsr!=0 ); |
| 71221 | 70720 | assert( pOp->p5==0 ); |
| 71222 | | - u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo; |
| 71223 | | - u.bt.r.nField = (u16)pOp->p3; |
| 71224 | | - u.bt.r.flags = UNPACKED_PREFIX_MATCH; |
| 71225 | | - u.bt.r.aMem = &aMem[pOp->p2]; |
| 70721 | + r.pKeyInfo = pC->pKeyInfo; |
| 70722 | + r.nField = (u16)pOp->p3; |
| 70723 | + r.flags = UNPACKED_PREFIX_MATCH; |
| 70724 | + r.aMem = &aMem[pOp->p2]; |
| 71226 | 70725 | #ifdef SQLITE_DEBUG |
| 71227 | | - { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); } |
| 70726 | + { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 71228 | 70727 | #endif |
| 71229 | | - rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res); |
| 71230 | | - if( rc==SQLITE_OK && u.bt.res==0 ){ |
| 71231 | | - rc = sqlite3BtreeDelete(u.bt.pCrsr); |
| 70728 | + rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 70729 | + if( rc==SQLITE_OK && res==0 ){ |
| 70730 | + rc = sqlite3BtreeDelete(pCrsr); |
| 71232 | 70731 | } |
| 71233 | | - assert( u.bt.pC->deferredMoveto==0 ); |
| 71234 | | - u.bt.pC->cacheStatus = CACHE_STALE; |
| 70732 | + assert( pC->deferredMoveto==0 ); |
| 70733 | + pC->cacheStatus = CACHE_STALE; |
| 71235 | 70734 | break; |
| 71236 | 70735 | } |
| 71237 | 70736 | |
| 71238 | 70737 | /* Opcode: IdxRowid P1 P2 * * * |
| 71239 | 70738 | ** Synopsis: r[P2]=rowid |
| | @@ -71243,32 +70742,31 @@ |
| 71243 | 70742 | ** the rowid of the table entry to which this index entry points. |
| 71244 | 70743 | ** |
| 71245 | 70744 | ** See also: Rowid, MakeRecord. |
| 71246 | 70745 | */ |
| 71247 | 70746 | case OP_IdxRowid: { /* out2-prerelease */ |
| 71248 | | -#if 0 /* local variables moved into u.bu */ |
| 71249 | 70747 | BtCursor *pCrsr; |
| 71250 | 70748 | VdbeCursor *pC; |
| 71251 | 70749 | i64 rowid; |
| 71252 | | -#endif /* local variables moved into u.bu */ |
| 71253 | 70750 | |
| 71254 | 70751 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71255 | | - u.bu.pC = p->apCsr[pOp->p1]; |
| 71256 | | - assert( u.bu.pC!=0 ); |
| 71257 | | - u.bu.pCrsr = u.bu.pC->pCursor; |
| 71258 | | - assert( u.bu.pCrsr!=0 ); |
| 70752 | + pC = p->apCsr[pOp->p1]; |
| 70753 | + assert( pC!=0 ); |
| 70754 | + pCrsr = pC->pCursor; |
| 70755 | + assert( pCrsr!=0 ); |
| 71259 | 70756 | pOut->flags = MEM_Null; |
| 71260 | | - rc = sqlite3VdbeCursorMoveto(u.bu.pC); |
| 70757 | + rc = sqlite3VdbeCursorMoveto(pC); |
| 71261 | 70758 | if( NEVER(rc) ) goto abort_due_to_error; |
| 71262 | | - assert( u.bu.pC->deferredMoveto==0 ); |
| 71263 | | - assert( u.bu.pC->isTable==0 ); |
| 71264 | | - if( !u.bu.pC->nullRow ){ |
| 71265 | | - rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid); |
| 70759 | + assert( pC->deferredMoveto==0 ); |
| 70760 | + assert( pC->isTable==0 ); |
| 70761 | + if( !pC->nullRow ){ |
| 70762 | + rowid = 0; /* Not needed. Only used to silence a warning. */ |
| 70763 | + rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid); |
| 71266 | 70764 | if( rc!=SQLITE_OK ){ |
| 71267 | 70765 | goto abort_due_to_error; |
| 71268 | 70766 | } |
| 71269 | | - pOut->u.i = u.bu.rowid; |
| 70767 | + pOut->u.i = rowid; |
| 71270 | 70768 | pOut->flags = MEM_Int; |
| 71271 | 70769 | } |
| 71272 | 70770 | break; |
| 71273 | 70771 | } |
| 71274 | 70772 | |
| | @@ -71300,43 +70798,42 @@ |
| 71300 | 70798 | ** If P5 is non-zero then the key value is increased by an epsilon prior |
| 71301 | 70799 | ** to the comparison. This makes the opcode work like IdxLE. |
| 71302 | 70800 | */ |
| 71303 | 70801 | case OP_IdxLT: /* jump */ |
| 71304 | 70802 | case OP_IdxGE: { /* jump */ |
| 71305 | | -#if 0 /* local variables moved into u.bv */ |
| 71306 | 70803 | VdbeCursor *pC; |
| 71307 | 70804 | int res; |
| 71308 | 70805 | UnpackedRecord r; |
| 71309 | | -#endif /* local variables moved into u.bv */ |
| 71310 | 70806 | |
| 71311 | 70807 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71312 | | - u.bv.pC = p->apCsr[pOp->p1]; |
| 71313 | | - assert( u.bv.pC!=0 ); |
| 71314 | | - assert( u.bv.pC->isOrdered ); |
| 71315 | | - assert( u.bv.pC->pCursor!=0); |
| 71316 | | - assert( u.bv.pC->deferredMoveto==0 ); |
| 70808 | + pC = p->apCsr[pOp->p1]; |
| 70809 | + assert( pC!=0 ); |
| 70810 | + assert( pC->isOrdered ); |
| 70811 | + assert( pC->pCursor!=0); |
| 70812 | + assert( pC->deferredMoveto==0 ); |
| 71317 | 70813 | assert( pOp->p5==0 || pOp->p5==1 ); |
| 71318 | 70814 | assert( pOp->p4type==P4_INT32 ); |
| 71319 | | - u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo; |
| 71320 | | - u.bv.r.nField = (u16)pOp->p4.i; |
| 70815 | + r.pKeyInfo = pC->pKeyInfo; |
| 70816 | + r.nField = (u16)pOp->p4.i; |
| 71321 | 70817 | if( pOp->p5 ){ |
| 71322 | | - u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH; |
| 70818 | + r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH; |
| 71323 | 70819 | }else{ |
| 71324 | | - u.bv.r.flags = UNPACKED_PREFIX_MATCH; |
| 70820 | + r.flags = UNPACKED_PREFIX_MATCH; |
| 71325 | 70821 | } |
| 71326 | | - u.bv.r.aMem = &aMem[pOp->p3]; |
| 70822 | + r.aMem = &aMem[pOp->p3]; |
| 71327 | 70823 | #ifdef SQLITE_DEBUG |
| 71328 | | - { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); } |
| 70824 | + { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 71329 | 70825 | #endif |
| 71330 | | - rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res); |
| 70826 | + res = 0; /* Not needed. Only used to silence a warning. */ |
| 70827 | + rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res); |
| 71331 | 70828 | if( pOp->opcode==OP_IdxLT ){ |
| 71332 | | - u.bv.res = -u.bv.res; |
| 70829 | + res = -res; |
| 71333 | 70830 | }else{ |
| 71334 | 70831 | assert( pOp->opcode==OP_IdxGE ); |
| 71335 | | - u.bv.res++; |
| 70832 | + res++; |
| 71336 | 70833 | } |
| 71337 | | - if( u.bv.res>0 ){ |
| 70834 | + if( res>0 ){ |
| 71338 | 70835 | pc = pOp->p2 - 1 ; |
| 71339 | 70836 | } |
| 71340 | 70837 | break; |
| 71341 | 70838 | } |
| 71342 | 70839 | |
| | @@ -71359,47 +70856,46 @@ |
| 71359 | 70856 | ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 71360 | 70857 | ** |
| 71361 | 70858 | ** See also: Clear |
| 71362 | 70859 | */ |
| 71363 | 70860 | case OP_Destroy: { /* out2-prerelease */ |
| 71364 | | -#if 0 /* local variables moved into u.bw */ |
| 71365 | 70861 | int iMoved; |
| 71366 | 70862 | int iCnt; |
| 71367 | 70863 | Vdbe *pVdbe; |
| 71368 | 70864 | int iDb; |
| 71369 | | -#endif /* local variables moved into u.bw */ |
| 71370 | 70865 | |
| 71371 | 70866 | assert( p->readOnly==0 ); |
| 71372 | 70867 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 71373 | | - u.bw.iCnt = 0; |
| 71374 | | - for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){ |
| 71375 | | - if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader |
| 71376 | | - && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0 |
| 70868 | + iCnt = 0; |
| 70869 | + for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){ |
| 70870 | + if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader |
| 70871 | + && pVdbe->inVtabMethod<2 && pVdbe->pc>=0 |
| 71377 | 70872 | ){ |
| 71378 | | - u.bw.iCnt++; |
| 70873 | + iCnt++; |
| 71379 | 70874 | } |
| 71380 | 70875 | } |
| 71381 | 70876 | #else |
| 71382 | | - u.bw.iCnt = db->nVdbeRead; |
| 70877 | + iCnt = db->nVdbeRead; |
| 71383 | 70878 | #endif |
| 71384 | 70879 | pOut->flags = MEM_Null; |
| 71385 | | - if( u.bw.iCnt>1 ){ |
| 70880 | + if( iCnt>1 ){ |
| 71386 | 70881 | rc = SQLITE_LOCKED; |
| 71387 | 70882 | p->errorAction = OE_Abort; |
| 71388 | 70883 | }else{ |
| 71389 | | - u.bw.iDb = pOp->p3; |
| 71390 | | - assert( u.bw.iCnt==1 ); |
| 71391 | | - assert( (p->btreeMask & (((yDbMask)1)<<u.bw.iDb))!=0 ); |
| 71392 | | - rc = sqlite3BtreeDropTable(db->aDb[u.bw.iDb].pBt, pOp->p1, &u.bw.iMoved); |
| 70884 | + iDb = pOp->p3; |
| 70885 | + assert( iCnt==1 ); |
| 70886 | + assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); |
| 70887 | + iMoved = 0; /* Not needed. Only to silence a warning. */ |
| 70888 | + rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved); |
| 71393 | 70889 | pOut->flags = MEM_Int; |
| 71394 | | - pOut->u.i = u.bw.iMoved; |
| 70890 | + pOut->u.i = iMoved; |
| 71395 | 70891 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 71396 | | - if( rc==SQLITE_OK && u.bw.iMoved!=0 ){ |
| 71397 | | - sqlite3RootPageMoved(db, u.bw.iDb, u.bw.iMoved, pOp->p1); |
| 70892 | + if( rc==SQLITE_OK && iMoved!=0 ){ |
| 70893 | + sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1); |
| 71398 | 70894 | /* All OP_Destroy operations occur on the same btree */ |
| 71399 | | - assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.bw.iDb+1 ); |
| 71400 | | - resetSchemaOnFault = u.bw.iDb+1; |
| 70895 | + assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 ); |
| 70896 | + resetSchemaOnFault = iDb+1; |
| 71401 | 70897 | } |
| 71402 | 70898 | #endif |
| 71403 | 70899 | } |
| 71404 | 70900 | break; |
| 71405 | 70901 | } |
| | @@ -71421,27 +70917,25 @@ |
| 71421 | 70917 | ** also incremented by the number of rows in the table being cleared. |
| 71422 | 70918 | ** |
| 71423 | 70919 | ** See also: Destroy |
| 71424 | 70920 | */ |
| 71425 | 70921 | case OP_Clear: { |
| 71426 | | -#if 0 /* local variables moved into u.bx */ |
| 71427 | 70922 | int nChange; |
| 71428 | | -#endif /* local variables moved into u.bx */ |
| 71429 | | - |
| 71430 | | - u.bx.nChange = 0; |
| 70923 | + |
| 70924 | + nChange = 0; |
| 71431 | 70925 | assert( p->readOnly==0 ); |
| 71432 | 70926 | assert( pOp->p1!=1 ); |
| 71433 | 70927 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 ); |
| 71434 | 70928 | rc = sqlite3BtreeClearTable( |
| 71435 | | - db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0) |
| 70929 | + db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0) |
| 71436 | 70930 | ); |
| 71437 | 70931 | if( pOp->p3 ){ |
| 71438 | | - p->nChange += u.bx.nChange; |
| 70932 | + p->nChange += nChange; |
| 71439 | 70933 | if( pOp->p3>0 ){ |
| 71440 | 70934 | assert( memIsValid(&aMem[pOp->p3]) ); |
| 71441 | 70935 | memAboutToChange(p, &aMem[pOp->p3]); |
| 71442 | | - aMem[pOp->p3].u.i += u.bx.nChange; |
| 70936 | + aMem[pOp->p3].u.i += nChange; |
| 71443 | 70937 | } |
| 71444 | 70938 | } |
| 71445 | 70939 | break; |
| 71446 | 70940 | } |
| 71447 | 70941 | |
| | @@ -71469,30 +70963,28 @@ |
| 71469 | 70963 | ** |
| 71470 | 70964 | ** See documentation on OP_CreateTable for additional information. |
| 71471 | 70965 | */ |
| 71472 | 70966 | case OP_CreateIndex: /* out2-prerelease */ |
| 71473 | 70967 | case OP_CreateTable: { /* out2-prerelease */ |
| 71474 | | -#if 0 /* local variables moved into u.by */ |
| 71475 | 70968 | int pgno; |
| 71476 | 70969 | int flags; |
| 71477 | 70970 | Db *pDb; |
| 71478 | | -#endif /* local variables moved into u.by */ |
| 71479 | 70971 | |
| 71480 | | - u.by.pgno = 0; |
| 70972 | + pgno = 0; |
| 71481 | 70973 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 71482 | 70974 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 71483 | 70975 | assert( p->readOnly==0 ); |
| 71484 | | - u.by.pDb = &db->aDb[pOp->p1]; |
| 71485 | | - assert( u.by.pDb->pBt!=0 ); |
| 70976 | + pDb = &db->aDb[pOp->p1]; |
| 70977 | + assert( pDb->pBt!=0 ); |
| 71486 | 70978 | if( pOp->opcode==OP_CreateTable ){ |
| 71487 | | - /* u.by.flags = BTREE_INTKEY; */ |
| 71488 | | - u.by.flags = BTREE_INTKEY; |
| 70979 | + /* flags = BTREE_INTKEY; */ |
| 70980 | + flags = BTREE_INTKEY; |
| 71489 | 70981 | }else{ |
| 71490 | | - u.by.flags = BTREE_BLOBKEY; |
| 70982 | + flags = BTREE_BLOBKEY; |
| 71491 | 70983 | } |
| 71492 | | - rc = sqlite3BtreeCreateTable(u.by.pDb->pBt, &u.by.pgno, u.by.flags); |
| 71493 | | - pOut->u.i = u.by.pgno; |
| 70984 | + rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags); |
| 70985 | + pOut->u.i = pgno; |
| 71494 | 70986 | break; |
| 71495 | 70987 | } |
| 71496 | 70988 | |
| 71497 | 70989 | /* Opcode: ParseSchema P1 * * P4 * |
| 71498 | 70990 | ** |
| | @@ -71501,56 +70993,54 @@ |
| 71501 | 70993 | ** |
| 71502 | 70994 | ** This opcode invokes the parser to create a new virtual machine, |
| 71503 | 70995 | ** then runs the new virtual machine. It is thus a re-entrant opcode. |
| 71504 | 70996 | */ |
| 71505 | 70997 | case OP_ParseSchema: { |
| 71506 | | -#if 0 /* local variables moved into u.bz */ |
| 71507 | 70998 | int iDb; |
| 71508 | 70999 | const char *zMaster; |
| 71509 | 71000 | char *zSql; |
| 71510 | 71001 | InitData initData; |
| 71511 | | -#endif /* local variables moved into u.bz */ |
| 71512 | 71002 | |
| 71513 | 71003 | /* Any prepared statement that invokes this opcode will hold mutexes |
| 71514 | | - ** on every btree. This is a prerequisite for invoking |
| 71004 | + ** on every btree. This is a prerequisite for invoking |
| 71515 | 71005 | ** sqlite3InitCallback(). |
| 71516 | 71006 | */ |
| 71517 | 71007 | #ifdef SQLITE_DEBUG |
| 71518 | | - for(u.bz.iDb=0; u.bz.iDb<db->nDb; u.bz.iDb++){ |
| 71519 | | - assert( u.bz.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bz.iDb].pBt) ); |
| 71008 | + for(iDb=0; iDb<db->nDb; iDb++){ |
| 71009 | + assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 71520 | 71010 | } |
| 71521 | 71011 | #endif |
| 71522 | 71012 | |
| 71523 | | - u.bz.iDb = pOp->p1; |
| 71524 | | - assert( u.bz.iDb>=0 && u.bz.iDb<db->nDb ); |
| 71525 | | - assert( DbHasProperty(db, u.bz.iDb, DB_SchemaLoaded) ); |
| 71013 | + iDb = pOp->p1; |
| 71014 | + assert( iDb>=0 && iDb<db->nDb ); |
| 71015 | + assert( DbHasProperty(db, iDb, DB_SchemaLoaded) ); |
| 71526 | 71016 | /* Used to be a conditional */ { |
| 71527 | | - u.bz.zMaster = SCHEMA_TABLE(u.bz.iDb); |
| 71528 | | - u.bz.initData.db = db; |
| 71529 | | - u.bz.initData.iDb = pOp->p1; |
| 71530 | | - u.bz.initData.pzErrMsg = &p->zErrMsg; |
| 71531 | | - u.bz.zSql = sqlite3MPrintf(db, |
| 71017 | + zMaster = SCHEMA_TABLE(iDb); |
| 71018 | + initData.db = db; |
| 71019 | + initData.iDb = pOp->p1; |
| 71020 | + initData.pzErrMsg = &p->zErrMsg; |
| 71021 | + zSql = sqlite3MPrintf(db, |
| 71532 | 71022 | "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid", |
| 71533 | | - db->aDb[u.bz.iDb].zName, u.bz.zMaster, pOp->p4.z); |
| 71534 | | - if( u.bz.zSql==0 ){ |
| 71023 | + db->aDb[iDb].zName, zMaster, pOp->p4.z); |
| 71024 | + if( zSql==0 ){ |
| 71535 | 71025 | rc = SQLITE_NOMEM; |
| 71536 | 71026 | }else{ |
| 71537 | 71027 | assert( db->init.busy==0 ); |
| 71538 | 71028 | db->init.busy = 1; |
| 71539 | | - u.bz.initData.rc = SQLITE_OK; |
| 71029 | + initData.rc = SQLITE_OK; |
| 71540 | 71030 | assert( !db->mallocFailed ); |
| 71541 | | - rc = sqlite3_exec(db, u.bz.zSql, sqlite3InitCallback, &u.bz.initData, 0); |
| 71542 | | - if( rc==SQLITE_OK ) rc = u.bz.initData.rc; |
| 71543 | | - sqlite3DbFree(db, u.bz.zSql); |
| 71031 | + rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); |
| 71032 | + if( rc==SQLITE_OK ) rc = initData.rc; |
| 71033 | + sqlite3DbFree(db, zSql); |
| 71544 | 71034 | db->init.busy = 0; |
| 71545 | 71035 | } |
| 71546 | 71036 | } |
| 71547 | 71037 | if( rc ) sqlite3ResetAllSchemasOfConnection(db); |
| 71548 | 71038 | if( rc==SQLITE_NOMEM ){ |
| 71549 | 71039 | goto no_mem; |
| 71550 | 71040 | } |
| 71551 | | - break; |
| 71041 | + break; |
| 71552 | 71042 | } |
| 71553 | 71043 | |
| 71554 | 71044 | #if !defined(SQLITE_OMIT_ANALYZE) |
| 71555 | 71045 | /* Opcode: LoadAnalysis P1 * * * * |
| 71556 | 71046 | ** |
| | @@ -71622,46 +71112,44 @@ |
| 71622 | 71112 | ** file, not the main database file. |
| 71623 | 71113 | ** |
| 71624 | 71114 | ** This opcode is used to implement the integrity_check pragma. |
| 71625 | 71115 | */ |
| 71626 | 71116 | case OP_IntegrityCk: { |
| 71627 | | -#if 0 /* local variables moved into u.ca */ |
| 71628 | 71117 | int nRoot; /* Number of tables to check. (Number of root pages.) */ |
| 71629 | 71118 | int *aRoot; /* Array of rootpage numbers for tables to be checked */ |
| 71630 | 71119 | int j; /* Loop counter */ |
| 71631 | 71120 | int nErr; /* Number of errors reported */ |
| 71632 | 71121 | char *z; /* Text of the error report */ |
| 71633 | 71122 | Mem *pnErr; /* Register keeping track of errors remaining */ |
| 71634 | | -#endif /* local variables moved into u.ca */ |
| 71635 | 71123 | |
| 71636 | 71124 | assert( p->bIsReader ); |
| 71637 | | - u.ca.nRoot = pOp->p2; |
| 71638 | | - assert( u.ca.nRoot>0 ); |
| 71639 | | - u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) ); |
| 71640 | | - if( u.ca.aRoot==0 ) goto no_mem; |
| 71125 | + nRoot = pOp->p2; |
| 71126 | + assert( nRoot>0 ); |
| 71127 | + aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) ); |
| 71128 | + if( aRoot==0 ) goto no_mem; |
| 71641 | 71129 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 71642 | | - u.ca.pnErr = &aMem[pOp->p3]; |
| 71643 | | - assert( (u.ca.pnErr->flags & MEM_Int)!=0 ); |
| 71644 | | - assert( (u.ca.pnErr->flags & (MEM_Str|MEM_Blob))==0 ); |
| 71130 | + pnErr = &aMem[pOp->p3]; |
| 71131 | + assert( (pnErr->flags & MEM_Int)!=0 ); |
| 71132 | + assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 ); |
| 71645 | 71133 | pIn1 = &aMem[pOp->p1]; |
| 71646 | | - for(u.ca.j=0; u.ca.j<u.ca.nRoot; u.ca.j++){ |
| 71647 | | - u.ca.aRoot[u.ca.j] = (int)sqlite3VdbeIntValue(&pIn1[u.ca.j]); |
| 71134 | + for(j=0; j<nRoot; j++){ |
| 71135 | + aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]); |
| 71648 | 71136 | } |
| 71649 | | - u.ca.aRoot[u.ca.j] = 0; |
| 71137 | + aRoot[j] = 0; |
| 71650 | 71138 | assert( pOp->p5<db->nDb ); |
| 71651 | 71139 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 ); |
| 71652 | | - u.ca.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.ca.aRoot, u.ca.nRoot, |
| 71653 | | - (int)u.ca.pnErr->u.i, &u.ca.nErr); |
| 71654 | | - sqlite3DbFree(db, u.ca.aRoot); |
| 71655 | | - u.ca.pnErr->u.i -= u.ca.nErr; |
| 71140 | + z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot, |
| 71141 | + (int)pnErr->u.i, &nErr); |
| 71142 | + sqlite3DbFree(db, aRoot); |
| 71143 | + pnErr->u.i -= nErr; |
| 71656 | 71144 | sqlite3VdbeMemSetNull(pIn1); |
| 71657 | | - if( u.ca.nErr==0 ){ |
| 71658 | | - assert( u.ca.z==0 ); |
| 71659 | | - }else if( u.ca.z==0 ){ |
| 71145 | + if( nErr==0 ){ |
| 71146 | + assert( z==0 ); |
| 71147 | + }else if( z==0 ){ |
| 71660 | 71148 | goto no_mem; |
| 71661 | 71149 | }else{ |
| 71662 | | - sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free); |
| 71150 | + sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free); |
| 71663 | 71151 | } |
| 71664 | 71152 | UPDATE_MAX_BLOBSIZE(pIn1); |
| 71665 | 71153 | sqlite3VdbeChangeEncoding(pIn1, encoding); |
| 71666 | 71154 | break; |
| 71667 | 71155 | } |
| | @@ -71693,24 +71181,22 @@ |
| 71693 | 71181 | ** Extract the smallest value from boolean index P1 and put that value into |
| 71694 | 71182 | ** register P3. Or, if boolean index P1 is initially empty, leave P3 |
| 71695 | 71183 | ** unchanged and jump to instruction P2. |
| 71696 | 71184 | */ |
| 71697 | 71185 | case OP_RowSetRead: { /* jump, in1, out3 */ |
| 71698 | | -#if 0 /* local variables moved into u.cb */ |
| 71699 | 71186 | i64 val; |
| 71700 | | -#endif /* local variables moved into u.cb */ |
| 71701 | 71187 | |
| 71702 | 71188 | pIn1 = &aMem[pOp->p1]; |
| 71703 | | - if( (pIn1->flags & MEM_RowSet)==0 |
| 71704 | | - || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0 |
| 71189 | + if( (pIn1->flags & MEM_RowSet)==0 |
| 71190 | + || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 |
| 71705 | 71191 | ){ |
| 71706 | 71192 | /* The boolean index is empty */ |
| 71707 | 71193 | sqlite3VdbeMemSetNull(pIn1); |
| 71708 | 71194 | pc = pOp->p2 - 1; |
| 71709 | 71195 | }else{ |
| 71710 | 71196 | /* A value was pulled from the index */ |
| 71711 | | - sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val); |
| 71197 | + sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); |
| 71712 | 71198 | } |
| 71713 | 71199 | goto check_for_interrupt; |
| 71714 | 71200 | } |
| 71715 | 71201 | |
| 71716 | 71202 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| | @@ -71736,18 +71222,16 @@ |
| 71736 | 71222 | ** inserted, there is no need to search to see if the same value was |
| 71737 | 71223 | ** previously inserted as part of set X (only if it was previously |
| 71738 | 71224 | ** inserted as part of some other set). |
| 71739 | 71225 | */ |
| 71740 | 71226 | case OP_RowSetTest: { /* jump, in1, in3 */ |
| 71741 | | -#if 0 /* local variables moved into u.cc */ |
| 71742 | 71227 | int iSet; |
| 71743 | 71228 | int exists; |
| 71744 | | -#endif /* local variables moved into u.cc */ |
| 71745 | 71229 | |
| 71746 | 71230 | pIn1 = &aMem[pOp->p1]; |
| 71747 | 71231 | pIn3 = &aMem[pOp->p3]; |
| 71748 | | - u.cc.iSet = pOp->p4.i; |
| 71232 | + iSet = pOp->p4.i; |
| 71749 | 71233 | assert( pIn3->flags&MEM_Int ); |
| 71750 | 71234 | |
| 71751 | 71235 | /* If there is anything other than a rowset object in memory cell P1, |
| 71752 | 71236 | ** delete it now and initialize P1 with an empty rowset |
| 71753 | 71237 | */ |
| | @@ -71755,21 +71239,21 @@ |
| 71755 | 71239 | sqlite3VdbeMemSetRowSet(pIn1); |
| 71756 | 71240 | if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem; |
| 71757 | 71241 | } |
| 71758 | 71242 | |
| 71759 | 71243 | assert( pOp->p4type==P4_INT32 ); |
| 71760 | | - assert( u.cc.iSet==-1 || u.cc.iSet>=0 ); |
| 71761 | | - if( u.cc.iSet ){ |
| 71762 | | - u.cc.exists = sqlite3RowSetTest(pIn1->u.pRowSet, |
| 71763 | | - (u8)(u.cc.iSet>=0 ? u.cc.iSet & 0xf : 0xff), |
| 71244 | + assert( iSet==-1 || iSet>=0 ); |
| 71245 | + if( iSet ){ |
| 71246 | + exists = sqlite3RowSetTest(pIn1->u.pRowSet, |
| 71247 | + (u8)(iSet>=0 ? iSet & 0xf : 0xff), |
| 71764 | 71248 | pIn3->u.i); |
| 71765 | | - if( u.cc.exists ){ |
| 71249 | + if( exists ){ |
| 71766 | 71250 | pc = pOp->p2 - 1; |
| 71767 | 71251 | break; |
| 71768 | 71252 | } |
| 71769 | 71253 | } |
| 71770 | | - if( u.cc.iSet>=0 ){ |
| 71254 | + if( iSet>=0 ){ |
| 71771 | 71255 | sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 71772 | 71256 | } |
| 71773 | 71257 | break; |
| 71774 | 71258 | } |
| 71775 | 71259 | |
| | @@ -71788,111 +71272,109 @@ |
| 71788 | 71272 | ** memory required by the sub-vdbe at runtime. |
| 71789 | 71273 | ** |
| 71790 | 71274 | ** P4 is a pointer to the VM containing the trigger program. |
| 71791 | 71275 | */ |
| 71792 | 71276 | case OP_Program: { /* jump */ |
| 71793 | | -#if 0 /* local variables moved into u.cd */ |
| 71794 | 71277 | int nMem; /* Number of memory registers for sub-program */ |
| 71795 | 71278 | int nByte; /* Bytes of runtime space required for sub-program */ |
| 71796 | 71279 | Mem *pRt; /* Register to allocate runtime space */ |
| 71797 | 71280 | Mem *pMem; /* Used to iterate through memory cells */ |
| 71798 | 71281 | Mem *pEnd; /* Last memory cell in new array */ |
| 71799 | 71282 | VdbeFrame *pFrame; /* New vdbe frame to execute in */ |
| 71800 | 71283 | SubProgram *pProgram; /* Sub-program to execute */ |
| 71801 | 71284 | void *t; /* Token identifying trigger */ |
| 71802 | | -#endif /* local variables moved into u.cd */ |
| 71803 | 71285 | |
| 71804 | | - u.cd.pProgram = pOp->p4.pProgram; |
| 71805 | | - u.cd.pRt = &aMem[pOp->p3]; |
| 71806 | | - assert( u.cd.pProgram->nOp>0 ); |
| 71807 | | - |
| 71808 | | - /* If the p5 flag is clear, then recursive invocation of triggers is |
| 71286 | + pProgram = pOp->p4.pProgram; |
| 71287 | + pRt = &aMem[pOp->p3]; |
| 71288 | + assert( pProgram->nOp>0 ); |
| 71289 | + |
| 71290 | + /* If the p5 flag is clear, then recursive invocation of triggers is |
| 71809 | 71291 | ** disabled for backwards compatibility (p5 is set if this sub-program |
| 71810 | 71292 | ** is really a trigger, not a foreign key action, and the flag set |
| 71811 | 71293 | ** and cleared by the "PRAGMA recursive_triggers" command is clear). |
| 71812 | | - ** |
| 71813 | | - ** It is recursive invocation of triggers, at the SQL level, that is |
| 71814 | | - ** disabled. In some cases a single trigger may generate more than one |
| 71815 | | - ** SubProgram (if the trigger may be executed with more than one different |
| 71294 | + ** |
| 71295 | + ** It is recursive invocation of triggers, at the SQL level, that is |
| 71296 | + ** disabled. In some cases a single trigger may generate more than one |
| 71297 | + ** SubProgram (if the trigger may be executed with more than one different |
| 71816 | 71298 | ** ON CONFLICT algorithm). SubProgram structures associated with a |
| 71817 | | - ** single trigger all have the same value for the SubProgram.token |
| 71299 | + ** single trigger all have the same value for the SubProgram.token |
| 71818 | 71300 | ** variable. */ |
| 71819 | 71301 | if( pOp->p5 ){ |
| 71820 | | - u.cd.t = u.cd.pProgram->token; |
| 71821 | | - for(u.cd.pFrame=p->pFrame; u.cd.pFrame && u.cd.pFrame->token!=u.cd.t; u.cd.pFrame=u.cd.pFrame->pParent); |
| 71822 | | - if( u.cd.pFrame ) break; |
| 71302 | + t = pProgram->token; |
| 71303 | + for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent); |
| 71304 | + if( pFrame ) break; |
| 71823 | 71305 | } |
| 71824 | 71306 | |
| 71825 | 71307 | if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 71826 | 71308 | rc = SQLITE_ERROR; |
| 71827 | 71309 | sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion"); |
| 71828 | 71310 | break; |
| 71829 | 71311 | } |
| 71830 | 71312 | |
| 71831 | | - /* Register u.cd.pRt is used to store the memory required to save the state |
| 71313 | + /* Register pRt is used to store the memory required to save the state |
| 71832 | 71314 | ** of the current program, and the memory required at runtime to execute |
| 71833 | | - ** the trigger program. If this trigger has been fired before, then u.cd.pRt |
| 71315 | + ** the trigger program. If this trigger has been fired before, then pRt |
| 71834 | 71316 | ** is already allocated. Otherwise, it must be initialized. */ |
| 71835 | | - if( (u.cd.pRt->flags&MEM_Frame)==0 ){ |
| 71836 | | - /* SubProgram.nMem is set to the number of memory cells used by the |
| 71317 | + if( (pRt->flags&MEM_Frame)==0 ){ |
| 71318 | + /* SubProgram.nMem is set to the number of memory cells used by the |
| 71837 | 71319 | ** program stored in SubProgram.aOp. As well as these, one memory |
| 71838 | 71320 | ** cell is required for each cursor used by the program. Set local |
| 71839 | | - ** variable u.cd.nMem (and later, VdbeFrame.nChildMem) to this value. |
| 71321 | + ** variable nMem (and later, VdbeFrame.nChildMem) to this value. |
| 71840 | 71322 | */ |
| 71841 | | - u.cd.nMem = u.cd.pProgram->nMem + u.cd.pProgram->nCsr; |
| 71842 | | - u.cd.nByte = ROUND8(sizeof(VdbeFrame)) |
| 71843 | | - + u.cd.nMem * sizeof(Mem) |
| 71844 | | - + u.cd.pProgram->nCsr * sizeof(VdbeCursor *) |
| 71845 | | - + u.cd.pProgram->nOnce * sizeof(u8); |
| 71846 | | - u.cd.pFrame = sqlite3DbMallocZero(db, u.cd.nByte); |
| 71847 | | - if( !u.cd.pFrame ){ |
| 71323 | + nMem = pProgram->nMem + pProgram->nCsr; |
| 71324 | + nByte = ROUND8(sizeof(VdbeFrame)) |
| 71325 | + + nMem * sizeof(Mem) |
| 71326 | + + pProgram->nCsr * sizeof(VdbeCursor *) |
| 71327 | + + pProgram->nOnce * sizeof(u8); |
| 71328 | + pFrame = sqlite3DbMallocZero(db, nByte); |
| 71329 | + if( !pFrame ){ |
| 71848 | 71330 | goto no_mem; |
| 71849 | 71331 | } |
| 71850 | | - sqlite3VdbeMemRelease(u.cd.pRt); |
| 71851 | | - u.cd.pRt->flags = MEM_Frame; |
| 71852 | | - u.cd.pRt->u.pFrame = u.cd.pFrame; |
| 71853 | | - |
| 71854 | | - u.cd.pFrame->v = p; |
| 71855 | | - u.cd.pFrame->nChildMem = u.cd.nMem; |
| 71856 | | - u.cd.pFrame->nChildCsr = u.cd.pProgram->nCsr; |
| 71857 | | - u.cd.pFrame->pc = pc; |
| 71858 | | - u.cd.pFrame->aMem = p->aMem; |
| 71859 | | - u.cd.pFrame->nMem = p->nMem; |
| 71860 | | - u.cd.pFrame->apCsr = p->apCsr; |
| 71861 | | - u.cd.pFrame->nCursor = p->nCursor; |
| 71862 | | - u.cd.pFrame->aOp = p->aOp; |
| 71863 | | - u.cd.pFrame->nOp = p->nOp; |
| 71864 | | - u.cd.pFrame->token = u.cd.pProgram->token; |
| 71865 | | - u.cd.pFrame->aOnceFlag = p->aOnceFlag; |
| 71866 | | - u.cd.pFrame->nOnceFlag = p->nOnceFlag; |
| 71867 | | - |
| 71868 | | - u.cd.pEnd = &VdbeFrameMem(u.cd.pFrame)[u.cd.pFrame->nChildMem]; |
| 71869 | | - for(u.cd.pMem=VdbeFrameMem(u.cd.pFrame); u.cd.pMem!=u.cd.pEnd; u.cd.pMem++){ |
| 71870 | | - u.cd.pMem->flags = MEM_Invalid; |
| 71871 | | - u.cd.pMem->db = db; |
| 71332 | + sqlite3VdbeMemRelease(pRt); |
| 71333 | + pRt->flags = MEM_Frame; |
| 71334 | + pRt->u.pFrame = pFrame; |
| 71335 | + |
| 71336 | + pFrame->v = p; |
| 71337 | + pFrame->nChildMem = nMem; |
| 71338 | + pFrame->nChildCsr = pProgram->nCsr; |
| 71339 | + pFrame->pc = pc; |
| 71340 | + pFrame->aMem = p->aMem; |
| 71341 | + pFrame->nMem = p->nMem; |
| 71342 | + pFrame->apCsr = p->apCsr; |
| 71343 | + pFrame->nCursor = p->nCursor; |
| 71344 | + pFrame->aOp = p->aOp; |
| 71345 | + pFrame->nOp = p->nOp; |
| 71346 | + pFrame->token = pProgram->token; |
| 71347 | + pFrame->aOnceFlag = p->aOnceFlag; |
| 71348 | + pFrame->nOnceFlag = p->nOnceFlag; |
| 71349 | + |
| 71350 | + pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; |
| 71351 | + for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ |
| 71352 | + pMem->flags = MEM_Invalid; |
| 71353 | + pMem->db = db; |
| 71872 | 71354 | } |
| 71873 | 71355 | }else{ |
| 71874 | | - u.cd.pFrame = u.cd.pRt->u.pFrame; |
| 71875 | | - assert( u.cd.pProgram->nMem+u.cd.pProgram->nCsr==u.cd.pFrame->nChildMem ); |
| 71876 | | - assert( u.cd.pProgram->nCsr==u.cd.pFrame->nChildCsr ); |
| 71877 | | - assert( pc==u.cd.pFrame->pc ); |
| 71356 | + pFrame = pRt->u.pFrame; |
| 71357 | + assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); |
| 71358 | + assert( pProgram->nCsr==pFrame->nChildCsr ); |
| 71359 | + assert( pc==pFrame->pc ); |
| 71878 | 71360 | } |
| 71879 | 71361 | |
| 71880 | 71362 | p->nFrame++; |
| 71881 | | - u.cd.pFrame->pParent = p->pFrame; |
| 71882 | | - u.cd.pFrame->lastRowid = lastRowid; |
| 71883 | | - u.cd.pFrame->nChange = p->nChange; |
| 71363 | + pFrame->pParent = p->pFrame; |
| 71364 | + pFrame->lastRowid = lastRowid; |
| 71365 | + pFrame->nChange = p->nChange; |
| 71884 | 71366 | p->nChange = 0; |
| 71885 | | - p->pFrame = u.cd.pFrame; |
| 71886 | | - p->aMem = aMem = &VdbeFrameMem(u.cd.pFrame)[-1]; |
| 71887 | | - p->nMem = u.cd.pFrame->nChildMem; |
| 71888 | | - p->nCursor = (u16)u.cd.pFrame->nChildCsr; |
| 71367 | + p->pFrame = pFrame; |
| 71368 | + p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; |
| 71369 | + p->nMem = pFrame->nChildMem; |
| 71370 | + p->nCursor = (u16)pFrame->nChildCsr; |
| 71889 | 71371 | p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 71890 | | - p->aOp = aOp = u.cd.pProgram->aOp; |
| 71891 | | - p->nOp = u.cd.pProgram->nOp; |
| 71372 | + p->aOp = aOp = pProgram->aOp; |
| 71373 | + p->nOp = pProgram->nOp; |
| 71892 | 71374 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 71893 | | - p->nOnceFlag = u.cd.pProgram->nOnce; |
| 71375 | + p->nOnceFlag = pProgram->nOnce; |
| 71894 | 71376 | pc = -1; |
| 71895 | 71377 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 71896 | 71378 | |
| 71897 | 71379 | break; |
| 71898 | 71380 | } |
| | @@ -71908,17 +71390,15 @@ |
| 71908 | 71390 | ** The address of the cell in the parent frame is determined by adding |
| 71909 | 71391 | ** the value of the P1 argument to the value of the P1 argument to the |
| 71910 | 71392 | ** calling OP_Program instruction. |
| 71911 | 71393 | */ |
| 71912 | 71394 | case OP_Param: { /* out2-prerelease */ |
| 71913 | | -#if 0 /* local variables moved into u.ce */ |
| 71914 | 71395 | VdbeFrame *pFrame; |
| 71915 | 71396 | Mem *pIn; |
| 71916 | | -#endif /* local variables moved into u.ce */ |
| 71917 | | - u.ce.pFrame = p->pFrame; |
| 71918 | | - u.ce.pIn = &u.ce.pFrame->aMem[pOp->p1 + u.ce.pFrame->aOp[u.ce.pFrame->pc].p1]; |
| 71919 | | - sqlite3VdbeMemShallowCopy(pOut, u.ce.pIn, MEM_Ephem); |
| 71397 | + pFrame = p->pFrame; |
| 71398 | + pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; |
| 71399 | + sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); |
| 71920 | 71400 | break; |
| 71921 | 71401 | } |
| 71922 | 71402 | |
| 71923 | 71403 | #endif /* #ifndef SQLITE_OMIT_TRIGGER */ |
| 71924 | 71404 | |
| | @@ -71975,26 +71455,23 @@ |
| 71975 | 71455 | ** |
| 71976 | 71456 | ** This instruction throws an error if the memory cell is not initially |
| 71977 | 71457 | ** an integer. |
| 71978 | 71458 | */ |
| 71979 | 71459 | case OP_MemMax: { /* in2 */ |
| 71980 | | -#if 0 /* local variables moved into u.cf */ |
| 71981 | | - Mem *pIn1; |
| 71982 | 71460 | VdbeFrame *pFrame; |
| 71983 | | -#endif /* local variables moved into u.cf */ |
| 71984 | 71461 | if( p->pFrame ){ |
| 71985 | | - for(u.cf.pFrame=p->pFrame; u.cf.pFrame->pParent; u.cf.pFrame=u.cf.pFrame->pParent); |
| 71986 | | - u.cf.pIn1 = &u.cf.pFrame->aMem[pOp->p1]; |
| 71462 | + for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 71463 | + pIn1 = &pFrame->aMem[pOp->p1]; |
| 71987 | 71464 | }else{ |
| 71988 | | - u.cf.pIn1 = &aMem[pOp->p1]; |
| 71465 | + pIn1 = &aMem[pOp->p1]; |
| 71989 | 71466 | } |
| 71990 | | - assert( memIsValid(u.cf.pIn1) ); |
| 71991 | | - sqlite3VdbeMemIntegerify(u.cf.pIn1); |
| 71467 | + assert( memIsValid(pIn1) ); |
| 71468 | + sqlite3VdbeMemIntegerify(pIn1); |
| 71992 | 71469 | pIn2 = &aMem[pOp->p2]; |
| 71993 | 71470 | sqlite3VdbeMemIntegerify(pIn2); |
| 71994 | | - if( u.cf.pIn1->u.i<pIn2->u.i){ |
| 71995 | | - u.cf.pIn1->u.i = pIn2->u.i; |
| 71471 | + if( pIn1->u.i<pIn2->u.i){ |
| 71472 | + pIn1->u.i = pIn2->u.i; |
| 71996 | 71473 | } |
| 71997 | 71474 | break; |
| 71998 | 71475 | } |
| 71999 | 71476 | #endif /* SQLITE_OMIT_AUTOINCREMENT */ |
| 72000 | 71477 | |
| | @@ -72061,60 +71538,58 @@ |
| 72061 | 71538 | ** |
| 72062 | 71539 | ** The P5 arguments are taken from register P2 and its |
| 72063 | 71540 | ** successors. |
| 72064 | 71541 | */ |
| 72065 | 71542 | case OP_AggStep: { |
| 72066 | | -#if 0 /* local variables moved into u.cg */ |
| 72067 | 71543 | int n; |
| 72068 | 71544 | int i; |
| 72069 | 71545 | Mem *pMem; |
| 72070 | 71546 | Mem *pRec; |
| 72071 | 71547 | sqlite3_context ctx; |
| 72072 | 71548 | sqlite3_value **apVal; |
| 72073 | | -#endif /* local variables moved into u.cg */ |
| 72074 | | - |
| 72075 | | - u.cg.n = pOp->p5; |
| 72076 | | - assert( u.cg.n>=0 ); |
| 72077 | | - u.cg.pRec = &aMem[pOp->p2]; |
| 72078 | | - u.cg.apVal = p->apArg; |
| 72079 | | - assert( u.cg.apVal || u.cg.n==0 ); |
| 72080 | | - for(u.cg.i=0; u.cg.i<u.cg.n; u.cg.i++, u.cg.pRec++){ |
| 72081 | | - assert( memIsValid(u.cg.pRec) ); |
| 72082 | | - u.cg.apVal[u.cg.i] = u.cg.pRec; |
| 72083 | | - memAboutToChange(p, u.cg.pRec); |
| 72084 | | - sqlite3VdbeMemStoreType(u.cg.pRec); |
| 72085 | | - } |
| 72086 | | - u.cg.ctx.pFunc = pOp->p4.pFunc; |
| 71549 | + |
| 71550 | + n = pOp->p5; |
| 71551 | + assert( n>=0 ); |
| 71552 | + pRec = &aMem[pOp->p2]; |
| 71553 | + apVal = p->apArg; |
| 71554 | + assert( apVal || n==0 ); |
| 71555 | + for(i=0; i<n; i++, pRec++){ |
| 71556 | + assert( memIsValid(pRec) ); |
| 71557 | + apVal[i] = pRec; |
| 71558 | + memAboutToChange(p, pRec); |
| 71559 | + sqlite3VdbeMemStoreType(pRec); |
| 71560 | + } |
| 71561 | + ctx.pFunc = pOp->p4.pFunc; |
| 72087 | 71562 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 72088 | | - u.cg.ctx.pMem = u.cg.pMem = &aMem[pOp->p3]; |
| 72089 | | - u.cg.pMem->n++; |
| 72090 | | - u.cg.ctx.s.flags = MEM_Null; |
| 72091 | | - u.cg.ctx.s.z = 0; |
| 72092 | | - u.cg.ctx.s.zMalloc = 0; |
| 72093 | | - u.cg.ctx.s.xDel = 0; |
| 72094 | | - u.cg.ctx.s.db = db; |
| 72095 | | - u.cg.ctx.isError = 0; |
| 72096 | | - u.cg.ctx.pColl = 0; |
| 72097 | | - u.cg.ctx.skipFlag = 0; |
| 72098 | | - if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 71563 | + ctx.pMem = pMem = &aMem[pOp->p3]; |
| 71564 | + pMem->n++; |
| 71565 | + ctx.s.flags = MEM_Null; |
| 71566 | + ctx.s.z = 0; |
| 71567 | + ctx.s.zMalloc = 0; |
| 71568 | + ctx.s.xDel = 0; |
| 71569 | + ctx.s.db = db; |
| 71570 | + ctx.isError = 0; |
| 71571 | + ctx.pColl = 0; |
| 71572 | + ctx.skipFlag = 0; |
| 71573 | + if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 72099 | 71574 | assert( pOp>p->aOp ); |
| 72100 | 71575 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 72101 | 71576 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 72102 | | - u.cg.ctx.pColl = pOp[-1].p4.pColl; |
| 72103 | | - } |
| 72104 | | - (u.cg.ctx.pFunc->xStep)(&u.cg.ctx, u.cg.n, u.cg.apVal); /* IMP: R-24505-23230 */ |
| 72105 | | - if( u.cg.ctx.isError ){ |
| 72106 | | - sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cg.ctx.s)); |
| 72107 | | - rc = u.cg.ctx.isError; |
| 72108 | | - } |
| 72109 | | - if( u.cg.ctx.skipFlag ){ |
| 71577 | + ctx.pColl = pOp[-1].p4.pColl; |
| 71578 | + } |
| 71579 | + (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| 71580 | + if( ctx.isError ){ |
| 71581 | + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); |
| 71582 | + rc = ctx.isError; |
| 71583 | + } |
| 71584 | + if( ctx.skipFlag ){ |
| 72110 | 71585 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 72111 | | - u.cg.i = pOp[-1].p1; |
| 72112 | | - if( u.cg.i ) sqlite3VdbeMemSetInt64(&aMem[u.cg.i], 1); |
| 71586 | + i = pOp[-1].p1; |
| 71587 | + if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); |
| 72113 | 71588 | } |
| 72114 | 71589 | |
| 72115 | | - sqlite3VdbeMemRelease(&u.cg.ctx.s); |
| 71590 | + sqlite3VdbeMemRelease(&ctx.s); |
| 72116 | 71591 | |
| 72117 | 71592 | break; |
| 72118 | 71593 | } |
| 72119 | 71594 | |
| 72120 | 71595 | /* Opcode: AggFinal P1 P2 * P4 * |
| | @@ -72129,23 +71604,21 @@ |
| 72129 | 71604 | ** functions that can take varying numbers of arguments. The |
| 72130 | 71605 | ** P4 argument is only needed for the degenerate case where |
| 72131 | 71606 | ** the step function was not previously called. |
| 72132 | 71607 | */ |
| 72133 | 71608 | case OP_AggFinal: { |
| 72134 | | -#if 0 /* local variables moved into u.ch */ |
| 72135 | 71609 | Mem *pMem; |
| 72136 | | -#endif /* local variables moved into u.ch */ |
| 72137 | 71610 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 72138 | | - u.ch.pMem = &aMem[pOp->p1]; |
| 72139 | | - assert( (u.ch.pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 72140 | | - rc = sqlite3VdbeMemFinalize(u.ch.pMem, pOp->p4.pFunc); |
| 71611 | + pMem = &aMem[pOp->p1]; |
| 71612 | + assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 71613 | + rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc); |
| 72141 | 71614 | if( rc ){ |
| 72142 | | - sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem)); |
| 71615 | + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem)); |
| 72143 | 71616 | } |
| 72144 | | - sqlite3VdbeChangeEncoding(u.ch.pMem, encoding); |
| 72145 | | - UPDATE_MAX_BLOBSIZE(u.ch.pMem); |
| 72146 | | - if( sqlite3VdbeMemTooBig(u.ch.pMem) ){ |
| 71617 | + sqlite3VdbeChangeEncoding(pMem, encoding); |
| 71618 | + UPDATE_MAX_BLOBSIZE(pMem); |
| 71619 | + if( sqlite3VdbeMemTooBig(pMem) ){ |
| 72147 | 71620 | goto too_big; |
| 72148 | 71621 | } |
| 72149 | 71622 | break; |
| 72150 | 71623 | } |
| 72151 | 71624 | |
| | @@ -72160,31 +71633,29 @@ |
| 72160 | 71633 | ** in the WAL that have been checkpointed after the checkpoint |
| 72161 | 71634 | ** completes into mem[P3+2]. However on an error, mem[P3+1] and |
| 72162 | 71635 | ** mem[P3+2] are initialized to -1. |
| 72163 | 71636 | */ |
| 72164 | 71637 | case OP_Checkpoint: { |
| 72165 | | -#if 0 /* local variables moved into u.ci */ |
| 72166 | 71638 | int i; /* Loop counter */ |
| 72167 | 71639 | int aRes[3]; /* Results */ |
| 72168 | 71640 | Mem *pMem; /* Write results here */ |
| 72169 | | -#endif /* local variables moved into u.ci */ |
| 72170 | 71641 | |
| 72171 | 71642 | assert( p->readOnly==0 ); |
| 72172 | | - u.ci.aRes[0] = 0; |
| 72173 | | - u.ci.aRes[1] = u.ci.aRes[2] = -1; |
| 71643 | + aRes[0] = 0; |
| 71644 | + aRes[1] = aRes[2] = -1; |
| 72174 | 71645 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 72175 | 71646 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 72176 | 71647 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 72177 | 71648 | ); |
| 72178 | | - rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ci.aRes[1], &u.ci.aRes[2]); |
| 71649 | + rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); |
| 72179 | 71650 | if( rc==SQLITE_BUSY ){ |
| 72180 | 71651 | rc = SQLITE_OK; |
| 72181 | | - u.ci.aRes[0] = 1; |
| 71652 | + aRes[0] = 1; |
| 72182 | 71653 | } |
| 72183 | | - for(u.ci.i=0, u.ci.pMem = &aMem[pOp->p3]; u.ci.i<3; u.ci.i++, u.ci.pMem++){ |
| 72184 | | - sqlite3VdbeMemSetInt64(u.ci.pMem, (i64)u.ci.aRes[u.ci.i]); |
| 72185 | | - } |
| 71654 | + for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){ |
| 71655 | + sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]); |
| 71656 | + } |
| 72186 | 71657 | break; |
| 72187 | 71658 | }; |
| 72188 | 71659 | #endif |
| 72189 | 71660 | |
| 72190 | 71661 | #ifndef SQLITE_OMIT_PRAGMA |
| | @@ -72198,98 +71669,96 @@ |
| 72198 | 71669 | ** If changing into or out of WAL mode the procedure is more complicated. |
| 72199 | 71670 | ** |
| 72200 | 71671 | ** Write a string containing the final journal-mode to register P2. |
| 72201 | 71672 | */ |
| 72202 | 71673 | case OP_JournalMode: { /* out2-prerelease */ |
| 72203 | | -#if 0 /* local variables moved into u.cj */ |
| 72204 | 71674 | Btree *pBt; /* Btree to change journal mode of */ |
| 72205 | 71675 | Pager *pPager; /* Pager associated with pBt */ |
| 72206 | 71676 | int eNew; /* New journal mode */ |
| 72207 | 71677 | int eOld; /* The old journal mode */ |
| 72208 | 71678 | #ifndef SQLITE_OMIT_WAL |
| 72209 | 71679 | const char *zFilename; /* Name of database file for pPager */ |
| 72210 | 71680 | #endif |
| 72211 | | -#endif /* local variables moved into u.cj */ |
| 72212 | | - |
| 72213 | | - u.cj.eNew = pOp->p3; |
| 72214 | | - assert( u.cj.eNew==PAGER_JOURNALMODE_DELETE |
| 72215 | | - || u.cj.eNew==PAGER_JOURNALMODE_TRUNCATE |
| 72216 | | - || u.cj.eNew==PAGER_JOURNALMODE_PERSIST |
| 72217 | | - || u.cj.eNew==PAGER_JOURNALMODE_OFF |
| 72218 | | - || u.cj.eNew==PAGER_JOURNALMODE_MEMORY |
| 72219 | | - || u.cj.eNew==PAGER_JOURNALMODE_WAL |
| 72220 | | - || u.cj.eNew==PAGER_JOURNALMODE_QUERY |
| 71681 | + |
| 71682 | + eNew = pOp->p3; |
| 71683 | + assert( eNew==PAGER_JOURNALMODE_DELETE |
| 71684 | + || eNew==PAGER_JOURNALMODE_TRUNCATE |
| 71685 | + || eNew==PAGER_JOURNALMODE_PERSIST |
| 71686 | + || eNew==PAGER_JOURNALMODE_OFF |
| 71687 | + || eNew==PAGER_JOURNALMODE_MEMORY |
| 71688 | + || eNew==PAGER_JOURNALMODE_WAL |
| 71689 | + || eNew==PAGER_JOURNALMODE_QUERY |
| 72221 | 71690 | ); |
| 72222 | 71691 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 72223 | 71692 | assert( p->readOnly==0 ); |
| 72224 | 71693 | |
| 72225 | | - u.cj.pBt = db->aDb[pOp->p1].pBt; |
| 72226 | | - u.cj.pPager = sqlite3BtreePager(u.cj.pBt); |
| 72227 | | - u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager); |
| 72228 | | - if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld; |
| 72229 | | - if( !sqlite3PagerOkToChangeJournalMode(u.cj.pPager) ) u.cj.eNew = u.cj.eOld; |
| 71694 | + pBt = db->aDb[pOp->p1].pBt; |
| 71695 | + pPager = sqlite3BtreePager(pBt); |
| 71696 | + eOld = sqlite3PagerGetJournalMode(pPager); |
| 71697 | + if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld; |
| 71698 | + if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld; |
| 72230 | 71699 | |
| 72231 | 71700 | #ifndef SQLITE_OMIT_WAL |
| 72232 | | - u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1); |
| 71701 | + zFilename = sqlite3PagerFilename(pPager, 1); |
| 72233 | 71702 | |
| 72234 | 71703 | /* Do not allow a transition to journal_mode=WAL for a database |
| 72235 | | - ** in temporary storage or if the VFS does not support shared memory |
| 71704 | + ** in temporary storage or if the VFS does not support shared memory |
| 72236 | 71705 | */ |
| 72237 | | - if( u.cj.eNew==PAGER_JOURNALMODE_WAL |
| 72238 | | - && (sqlite3Strlen30(u.cj.zFilename)==0 /* Temp file */ |
| 72239 | | - || !sqlite3PagerWalSupported(u.cj.pPager)) /* No shared-memory support */ |
| 71706 | + if( eNew==PAGER_JOURNALMODE_WAL |
| 71707 | + && (sqlite3Strlen30(zFilename)==0 /* Temp file */ |
| 71708 | + || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */ |
| 72240 | 71709 | ){ |
| 72241 | | - u.cj.eNew = u.cj.eOld; |
| 71710 | + eNew = eOld; |
| 72242 | 71711 | } |
| 72243 | 71712 | |
| 72244 | | - if( (u.cj.eNew!=u.cj.eOld) |
| 72245 | | - && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL) |
| 71713 | + if( (eNew!=eOld) |
| 71714 | + && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL) |
| 72246 | 71715 | ){ |
| 72247 | 71716 | if( !db->autoCommit || db->nVdbeRead>1 ){ |
| 72248 | 71717 | rc = SQLITE_ERROR; |
| 72249 | | - sqlite3SetString(&p->zErrMsg, db, |
| 71718 | + sqlite3SetString(&p->zErrMsg, db, |
| 72250 | 71719 | "cannot change %s wal mode from within a transaction", |
| 72251 | | - (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") |
| 71720 | + (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") |
| 72252 | 71721 | ); |
| 72253 | 71722 | break; |
| 72254 | 71723 | }else{ |
| 72255 | | - |
| 72256 | | - if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){ |
| 71724 | + |
| 71725 | + if( eOld==PAGER_JOURNALMODE_WAL ){ |
| 72257 | 71726 | /* If leaving WAL mode, close the log file. If successful, the call |
| 72258 | | - ** to PagerCloseWal() checkpoints and deletes the write-ahead-log |
| 72259 | | - ** file. An EXCLUSIVE lock may still be held on the database file |
| 72260 | | - ** after a successful return. |
| 71727 | + ** to PagerCloseWal() checkpoints and deletes the write-ahead-log |
| 71728 | + ** file. An EXCLUSIVE lock may still be held on the database file |
| 71729 | + ** after a successful return. |
| 72261 | 71730 | */ |
| 72262 | | - rc = sqlite3PagerCloseWal(u.cj.pPager); |
| 71731 | + rc = sqlite3PagerCloseWal(pPager); |
| 72263 | 71732 | if( rc==SQLITE_OK ){ |
| 72264 | | - sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew); |
| 71733 | + sqlite3PagerSetJournalMode(pPager, eNew); |
| 72265 | 71734 | } |
| 72266 | | - }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){ |
| 71735 | + }else if( eOld==PAGER_JOURNALMODE_MEMORY ){ |
| 72267 | 71736 | /* Cannot transition directly from MEMORY to WAL. Use mode OFF |
| 72268 | 71737 | ** as an intermediate */ |
| 72269 | | - sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF); |
| 71738 | + sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF); |
| 72270 | 71739 | } |
| 72271 | | - |
| 71740 | + |
| 72272 | 71741 | /* Open a transaction on the database file. Regardless of the journal |
| 72273 | 71742 | ** mode, this transaction always uses a rollback journal. |
| 72274 | 71743 | */ |
| 72275 | | - assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 ); |
| 71744 | + assert( sqlite3BtreeIsInTrans(pBt)==0 ); |
| 72276 | 71745 | if( rc==SQLITE_OK ){ |
| 72277 | | - rc = sqlite3BtreeSetVersion(u.cj.pBt, (u.cj.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1)); |
| 71746 | + rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1)); |
| 72278 | 71747 | } |
| 72279 | 71748 | } |
| 72280 | 71749 | } |
| 72281 | 71750 | #endif /* ifndef SQLITE_OMIT_WAL */ |
| 72282 | 71751 | |
| 72283 | 71752 | if( rc ){ |
| 72284 | | - u.cj.eNew = u.cj.eOld; |
| 71753 | + eNew = eOld; |
| 72285 | 71754 | } |
| 72286 | | - u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew); |
| 71755 | + eNew = sqlite3PagerSetJournalMode(pPager, eNew); |
| 72287 | 71756 | |
| 72288 | 71757 | pOut = &aMem[pOp->p2]; |
| 72289 | 71758 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 72290 | | - pOut->z = (char *)sqlite3JournalModename(u.cj.eNew); |
| 71759 | + pOut->z = (char *)sqlite3JournalModename(eNew); |
| 72291 | 71760 | pOut->n = sqlite3Strlen30(pOut->z); |
| 72292 | 71761 | pOut->enc = SQLITE_UTF8; |
| 72293 | 71762 | sqlite3VdbeChangeEncoding(pOut, encoding); |
| 72294 | 71763 | break; |
| 72295 | 71764 | }; |
| | @@ -72315,19 +71784,17 @@ |
| 72315 | 71784 | ** Perform a single step of the incremental vacuum procedure on |
| 72316 | 71785 | ** the P1 database. If the vacuum has finished, jump to instruction |
| 72317 | 71786 | ** P2. Otherwise, fall through to the next instruction. |
| 72318 | 71787 | */ |
| 72319 | 71788 | case OP_IncrVacuum: { /* jump */ |
| 72320 | | -#if 0 /* local variables moved into u.ck */ |
| 72321 | 71789 | Btree *pBt; |
| 72322 | | -#endif /* local variables moved into u.ck */ |
| 72323 | 71790 | |
| 72324 | 71791 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 72325 | 71792 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 72326 | 71793 | assert( p->readOnly==0 ); |
| 72327 | | - u.ck.pBt = db->aDb[pOp->p1].pBt; |
| 72328 | | - rc = sqlite3BtreeIncrVacuum(u.ck.pBt); |
| 71794 | + pBt = db->aDb[pOp->p1].pBt; |
| 71795 | + rc = sqlite3BtreeIncrVacuum(pBt); |
| 72329 | 71796 | if( rc==SQLITE_DONE ){ |
| 72330 | 71797 | pc = pOp->p2 - 1; |
| 72331 | 71798 | rc = SQLITE_OK; |
| 72332 | 71799 | } |
| 72333 | 71800 | break; |
| | @@ -72394,16 +71861,14 @@ |
| 72394 | 71861 | ** Also, whether or not P4 is set, check that this is not being called from |
| 72395 | 71862 | ** within a callback to a virtual table xSync() method. If it is, the error |
| 72396 | 71863 | ** code will be set to SQLITE_LOCKED. |
| 72397 | 71864 | */ |
| 72398 | 71865 | case OP_VBegin: { |
| 72399 | | -#if 0 /* local variables moved into u.cl */ |
| 72400 | 71866 | VTable *pVTab; |
| 72401 | | -#endif /* local variables moved into u.cl */ |
| 72402 | | - u.cl.pVTab = pOp->p4.pVtab; |
| 72403 | | - rc = sqlite3VtabBegin(db, u.cl.pVTab); |
| 72404 | | - if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab); |
| 71867 | + pVTab = pOp->p4.pVtab; |
| 71868 | + rc = sqlite3VtabBegin(db, pVTab); |
| 71869 | + if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab); |
| 72405 | 71870 | break; |
| 72406 | 71871 | } |
| 72407 | 71872 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 72408 | 71873 | |
| 72409 | 71874 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -72438,36 +71903,34 @@ |
| 72438 | 71903 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72439 | 71904 | ** P1 is a cursor number. This opcode opens a cursor to the virtual |
| 72440 | 71905 | ** table and stores that cursor in P1. |
| 72441 | 71906 | */ |
| 72442 | 71907 | case OP_VOpen: { |
| 72443 | | -#if 0 /* local variables moved into u.cm */ |
| 72444 | 71908 | VdbeCursor *pCur; |
| 72445 | 71909 | sqlite3_vtab_cursor *pVtabCursor; |
| 72446 | 71910 | sqlite3_vtab *pVtab; |
| 72447 | 71911 | sqlite3_module *pModule; |
| 72448 | | -#endif /* local variables moved into u.cm */ |
| 72449 | 71912 | |
| 72450 | 71913 | assert( p->bIsReader ); |
| 72451 | | - u.cm.pCur = 0; |
| 72452 | | - u.cm.pVtabCursor = 0; |
| 72453 | | - u.cm.pVtab = pOp->p4.pVtab->pVtab; |
| 72454 | | - u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule; |
| 72455 | | - assert(u.cm.pVtab && u.cm.pModule); |
| 72456 | | - rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor); |
| 72457 | | - sqlite3VtabImportErrmsg(p, u.cm.pVtab); |
| 71914 | + pCur = 0; |
| 71915 | + pVtabCursor = 0; |
| 71916 | + pVtab = pOp->p4.pVtab->pVtab; |
| 71917 | + pModule = (sqlite3_module *)pVtab->pModule; |
| 71918 | + assert(pVtab && pModule); |
| 71919 | + rc = pModule->xOpen(pVtab, &pVtabCursor); |
| 71920 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 72458 | 71921 | if( SQLITE_OK==rc ){ |
| 72459 | 71922 | /* Initialize sqlite3_vtab_cursor base class */ |
| 72460 | | - u.cm.pVtabCursor->pVtab = u.cm.pVtab; |
| 71923 | + pVtabCursor->pVtab = pVtab; |
| 72461 | 71924 | |
| 72462 | 71925 | /* Initialize vdbe cursor object */ |
| 72463 | | - u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 72464 | | - if( u.cm.pCur ){ |
| 72465 | | - u.cm.pCur->pVtabCursor = u.cm.pVtabCursor; |
| 71926 | + pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 71927 | + if( pCur ){ |
| 71928 | + pCur->pVtabCursor = pVtabCursor; |
| 72466 | 71929 | }else{ |
| 72467 | 71930 | db->mallocFailed = 1; |
| 72468 | | - u.cm.pModule->xClose(u.cm.pVtabCursor); |
| 71931 | + pModule->xClose(pVtabCursor); |
| 72469 | 71932 | } |
| 72470 | 71933 | } |
| 72471 | 71934 | break; |
| 72472 | 71935 | } |
| 72473 | 71936 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| | @@ -72491,11 +71954,10 @@ |
| 72491 | 71954 | ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter. |
| 72492 | 71955 | ** |
| 72493 | 71956 | ** A jump is made to P2 if the result set after filtering would be empty. |
| 72494 | 71957 | */ |
| 72495 | 71958 | case OP_VFilter: { /* jump */ |
| 72496 | | -#if 0 /* local variables moved into u.cn */ |
| 72497 | 71959 | int nArg; |
| 72498 | 71960 | int iQuery; |
| 72499 | 71961 | const sqlite3_module *pModule; |
| 72500 | 71962 | Mem *pQuery; |
| 72501 | 71963 | Mem *pArgc; |
| | @@ -72503,49 +71965,48 @@ |
| 72503 | 71965 | sqlite3_vtab *pVtab; |
| 72504 | 71966 | VdbeCursor *pCur; |
| 72505 | 71967 | int res; |
| 72506 | 71968 | int i; |
| 72507 | 71969 | Mem **apArg; |
| 72508 | | -#endif /* local variables moved into u.cn */ |
| 72509 | | - |
| 72510 | | - u.cn.pQuery = &aMem[pOp->p3]; |
| 72511 | | - u.cn.pArgc = &u.cn.pQuery[1]; |
| 72512 | | - u.cn.pCur = p->apCsr[pOp->p1]; |
| 72513 | | - assert( memIsValid(u.cn.pQuery) ); |
| 72514 | | - REGISTER_TRACE(pOp->p3, u.cn.pQuery); |
| 72515 | | - assert( u.cn.pCur->pVtabCursor ); |
| 72516 | | - u.cn.pVtabCursor = u.cn.pCur->pVtabCursor; |
| 72517 | | - u.cn.pVtab = u.cn.pVtabCursor->pVtab; |
| 72518 | | - u.cn.pModule = u.cn.pVtab->pModule; |
| 71970 | + |
| 71971 | + pQuery = &aMem[pOp->p3]; |
| 71972 | + pArgc = &pQuery[1]; |
| 71973 | + pCur = p->apCsr[pOp->p1]; |
| 71974 | + assert( memIsValid(pQuery) ); |
| 71975 | + REGISTER_TRACE(pOp->p3, pQuery); |
| 71976 | + assert( pCur->pVtabCursor ); |
| 71977 | + pVtabCursor = pCur->pVtabCursor; |
| 71978 | + pVtab = pVtabCursor->pVtab; |
| 71979 | + pModule = pVtab->pModule; |
| 72519 | 71980 | |
| 72520 | 71981 | /* Grab the index number and argc parameters */ |
| 72521 | | - assert( (u.cn.pQuery->flags&MEM_Int)!=0 && u.cn.pArgc->flags==MEM_Int ); |
| 72522 | | - u.cn.nArg = (int)u.cn.pArgc->u.i; |
| 72523 | | - u.cn.iQuery = (int)u.cn.pQuery->u.i; |
| 71982 | + assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); |
| 71983 | + nArg = (int)pArgc->u.i; |
| 71984 | + iQuery = (int)pQuery->u.i; |
| 72524 | 71985 | |
| 72525 | 71986 | /* Invoke the xFilter method */ |
| 72526 | 71987 | { |
| 72527 | | - u.cn.res = 0; |
| 72528 | | - u.cn.apArg = p->apArg; |
| 72529 | | - for(u.cn.i = 0; u.cn.i<u.cn.nArg; u.cn.i++){ |
| 72530 | | - u.cn.apArg[u.cn.i] = &u.cn.pArgc[u.cn.i+1]; |
| 72531 | | - sqlite3VdbeMemStoreType(u.cn.apArg[u.cn.i]); |
| 71988 | + res = 0; |
| 71989 | + apArg = p->apArg; |
| 71990 | + for(i = 0; i<nArg; i++){ |
| 71991 | + apArg[i] = &pArgc[i+1]; |
| 71992 | + sqlite3VdbeMemStoreType(apArg[i]); |
| 72532 | 71993 | } |
| 72533 | 71994 | |
| 72534 | 71995 | p->inVtabMethod = 1; |
| 72535 | | - rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg); |
| 71996 | + rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); |
| 72536 | 71997 | p->inVtabMethod = 0; |
| 72537 | | - sqlite3VtabImportErrmsg(p, u.cn.pVtab); |
| 71998 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 72538 | 71999 | if( rc==SQLITE_OK ){ |
| 72539 | | - u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor); |
| 72000 | + res = pModule->xEof(pVtabCursor); |
| 72540 | 72001 | } |
| 72541 | 72002 | |
| 72542 | | - if( u.cn.res ){ |
| 72003 | + if( res ){ |
| 72543 | 72004 | pc = pOp->p2 - 1; |
| 72544 | 72005 | } |
| 72545 | 72006 | } |
| 72546 | | - u.cn.pCur->nullRow = 0; |
| 72007 | + pCur->nullRow = 0; |
| 72547 | 72008 | |
| 72548 | 72009 | break; |
| 72549 | 72010 | } |
| 72550 | 72011 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 72551 | 72012 | |
| | @@ -72556,55 +72017,53 @@ |
| 72556 | 72017 | ** Store the value of the P2-th column of |
| 72557 | 72018 | ** the row of the virtual-table that the |
| 72558 | 72019 | ** P1 cursor is pointing to into register P3. |
| 72559 | 72020 | */ |
| 72560 | 72021 | case OP_VColumn: { |
| 72561 | | -#if 0 /* local variables moved into u.co */ |
| 72562 | 72022 | sqlite3_vtab *pVtab; |
| 72563 | 72023 | const sqlite3_module *pModule; |
| 72564 | 72024 | Mem *pDest; |
| 72565 | 72025 | sqlite3_context sContext; |
| 72566 | | -#endif /* local variables moved into u.co */ |
| 72567 | 72026 | |
| 72568 | 72027 | VdbeCursor *pCur = p->apCsr[pOp->p1]; |
| 72569 | 72028 | assert( pCur->pVtabCursor ); |
| 72570 | 72029 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 72571 | | - u.co.pDest = &aMem[pOp->p3]; |
| 72572 | | - memAboutToChange(p, u.co.pDest); |
| 72030 | + pDest = &aMem[pOp->p3]; |
| 72031 | + memAboutToChange(p, pDest); |
| 72573 | 72032 | if( pCur->nullRow ){ |
| 72574 | | - sqlite3VdbeMemSetNull(u.co.pDest); |
| 72033 | + sqlite3VdbeMemSetNull(pDest); |
| 72575 | 72034 | break; |
| 72576 | 72035 | } |
| 72577 | | - u.co.pVtab = pCur->pVtabCursor->pVtab; |
| 72578 | | - u.co.pModule = u.co.pVtab->pModule; |
| 72579 | | - assert( u.co.pModule->xColumn ); |
| 72580 | | - memset(&u.co.sContext, 0, sizeof(u.co.sContext)); |
| 72036 | + pVtab = pCur->pVtabCursor->pVtab; |
| 72037 | + pModule = pVtab->pModule; |
| 72038 | + assert( pModule->xColumn ); |
| 72039 | + memset(&sContext, 0, sizeof(sContext)); |
| 72581 | 72040 | |
| 72582 | 72041 | /* The output cell may already have a buffer allocated. Move |
| 72583 | | - ** the current contents to u.co.sContext.s so in case the user-function |
| 72584 | | - ** can use the already allocated buffer instead of allocating a |
| 72042 | + ** the current contents to sContext.s so in case the user-function |
| 72043 | + ** can use the already allocated buffer instead of allocating a |
| 72585 | 72044 | ** new one. |
| 72586 | 72045 | */ |
| 72587 | | - sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest); |
| 72588 | | - MemSetTypeFlag(&u.co.sContext.s, MEM_Null); |
| 72046 | + sqlite3VdbeMemMove(&sContext.s, pDest); |
| 72047 | + MemSetTypeFlag(&sContext.s, MEM_Null); |
| 72589 | 72048 | |
| 72590 | | - rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2); |
| 72591 | | - sqlite3VtabImportErrmsg(p, u.co.pVtab); |
| 72592 | | - if( u.co.sContext.isError ){ |
| 72593 | | - rc = u.co.sContext.isError; |
| 72049 | + rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2); |
| 72050 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 72051 | + if( sContext.isError ){ |
| 72052 | + rc = sContext.isError; |
| 72594 | 72053 | } |
| 72595 | 72054 | |
| 72596 | 72055 | /* Copy the result of the function to the P3 register. We |
| 72597 | 72056 | ** do this regardless of whether or not an error occurred to ensure any |
| 72598 | | - ** dynamic allocation in u.co.sContext.s (a Mem struct) is released. |
| 72057 | + ** dynamic allocation in sContext.s (a Mem struct) is released. |
| 72599 | 72058 | */ |
| 72600 | | - sqlite3VdbeChangeEncoding(&u.co.sContext.s, encoding); |
| 72601 | | - sqlite3VdbeMemMove(u.co.pDest, &u.co.sContext.s); |
| 72602 | | - REGISTER_TRACE(pOp->p3, u.co.pDest); |
| 72603 | | - UPDATE_MAX_BLOBSIZE(u.co.pDest); |
| 72059 | + sqlite3VdbeChangeEncoding(&sContext.s, encoding); |
| 72060 | + sqlite3VdbeMemMove(pDest, &sContext.s); |
| 72061 | + REGISTER_TRACE(pOp->p3, pDest); |
| 72062 | + UPDATE_MAX_BLOBSIZE(pDest); |
| 72604 | 72063 | |
| 72605 | | - if( sqlite3VdbeMemTooBig(u.co.pDest) ){ |
| 72064 | + if( sqlite3VdbeMemTooBig(pDest) ){ |
| 72606 | 72065 | goto too_big; |
| 72607 | 72066 | } |
| 72608 | 72067 | break; |
| 72609 | 72068 | } |
| 72610 | 72069 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| | @@ -72615,42 +72074,40 @@ |
| 72615 | 72074 | ** Advance virtual table P1 to the next row in its result set and |
| 72616 | 72075 | ** jump to instruction P2. Or, if the virtual table has reached |
| 72617 | 72076 | ** the end of its result set, then fall through to the next instruction. |
| 72618 | 72077 | */ |
| 72619 | 72078 | case OP_VNext: { /* jump */ |
| 72620 | | -#if 0 /* local variables moved into u.cp */ |
| 72621 | 72079 | sqlite3_vtab *pVtab; |
| 72622 | 72080 | const sqlite3_module *pModule; |
| 72623 | 72081 | int res; |
| 72624 | 72082 | VdbeCursor *pCur; |
| 72625 | | -#endif /* local variables moved into u.cp */ |
| 72626 | 72083 | |
| 72627 | | - u.cp.res = 0; |
| 72628 | | - u.cp.pCur = p->apCsr[pOp->p1]; |
| 72629 | | - assert( u.cp.pCur->pVtabCursor ); |
| 72630 | | - if( u.cp.pCur->nullRow ){ |
| 72084 | + res = 0; |
| 72085 | + pCur = p->apCsr[pOp->p1]; |
| 72086 | + assert( pCur->pVtabCursor ); |
| 72087 | + if( pCur->nullRow ){ |
| 72631 | 72088 | break; |
| 72632 | 72089 | } |
| 72633 | | - u.cp.pVtab = u.cp.pCur->pVtabCursor->pVtab; |
| 72634 | | - u.cp.pModule = u.cp.pVtab->pModule; |
| 72635 | | - assert( u.cp.pModule->xNext ); |
| 72090 | + pVtab = pCur->pVtabCursor->pVtab; |
| 72091 | + pModule = pVtab->pModule; |
| 72092 | + assert( pModule->xNext ); |
| 72636 | 72093 | |
| 72637 | 72094 | /* Invoke the xNext() method of the module. There is no way for the |
| 72638 | 72095 | ** underlying implementation to return an error if one occurs during |
| 72639 | | - ** xNext(). Instead, if an error occurs, true is returned (indicating that |
| 72096 | + ** xNext(). Instead, if an error occurs, true is returned (indicating that |
| 72640 | 72097 | ** data is available) and the error code returned when xColumn or |
| 72641 | 72098 | ** some other method is next invoked on the save virtual table cursor. |
| 72642 | 72099 | */ |
| 72643 | 72100 | p->inVtabMethod = 1; |
| 72644 | | - rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor); |
| 72101 | + rc = pModule->xNext(pCur->pVtabCursor); |
| 72645 | 72102 | p->inVtabMethod = 0; |
| 72646 | | - sqlite3VtabImportErrmsg(p, u.cp.pVtab); |
| 72103 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 72647 | 72104 | if( rc==SQLITE_OK ){ |
| 72648 | | - u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor); |
| 72105 | + res = pModule->xEof(pCur->pVtabCursor); |
| 72649 | 72106 | } |
| 72650 | 72107 | |
| 72651 | | - if( !u.cp.res ){ |
| 72108 | + if( !res ){ |
| 72652 | 72109 | /* If there is data, jump to P2 */ |
| 72653 | 72110 | pc = pOp->p2 - 1; |
| 72654 | 72111 | } |
| 72655 | 72112 | goto check_for_interrupt; |
| 72656 | 72113 | } |
| | @@ -72662,29 +72119,27 @@ |
| 72662 | 72119 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72663 | 72120 | ** This opcode invokes the corresponding xRename method. The value |
| 72664 | 72121 | ** in register P1 is passed as the zName argument to the xRename method. |
| 72665 | 72122 | */ |
| 72666 | 72123 | case OP_VRename: { |
| 72667 | | -#if 0 /* local variables moved into u.cq */ |
| 72668 | 72124 | sqlite3_vtab *pVtab; |
| 72669 | 72125 | Mem *pName; |
| 72670 | | -#endif /* local variables moved into u.cq */ |
| 72671 | 72126 | |
| 72672 | | - u.cq.pVtab = pOp->p4.pVtab->pVtab; |
| 72673 | | - u.cq.pName = &aMem[pOp->p1]; |
| 72674 | | - assert( u.cq.pVtab->pModule->xRename ); |
| 72675 | | - assert( memIsValid(u.cq.pName) ); |
| 72127 | + pVtab = pOp->p4.pVtab->pVtab; |
| 72128 | + pName = &aMem[pOp->p1]; |
| 72129 | + assert( pVtab->pModule->xRename ); |
| 72130 | + assert( memIsValid(pName) ); |
| 72676 | 72131 | assert( p->readOnly==0 ); |
| 72677 | | - REGISTER_TRACE(pOp->p1, u.cq.pName); |
| 72678 | | - assert( u.cq.pName->flags & MEM_Str ); |
| 72679 | | - testcase( u.cq.pName->enc==SQLITE_UTF8 ); |
| 72680 | | - testcase( u.cq.pName->enc==SQLITE_UTF16BE ); |
| 72681 | | - testcase( u.cq.pName->enc==SQLITE_UTF16LE ); |
| 72682 | | - rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8); |
| 72132 | + REGISTER_TRACE(pOp->p1, pName); |
| 72133 | + assert( pName->flags & MEM_Str ); |
| 72134 | + testcase( pName->enc==SQLITE_UTF8 ); |
| 72135 | + testcase( pName->enc==SQLITE_UTF16BE ); |
| 72136 | + testcase( pName->enc==SQLITE_UTF16LE ); |
| 72137 | + rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8); |
| 72683 | 72138 | if( rc==SQLITE_OK ){ |
| 72684 | | - rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z); |
| 72685 | | - sqlite3VtabImportErrmsg(p, u.cq.pVtab); |
| 72139 | + rc = pVtab->pModule->xRename(pVtab, pName->z); |
| 72140 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 72686 | 72141 | p->expired = 0; |
| 72687 | 72142 | } |
| 72688 | 72143 | break; |
| 72689 | 72144 | } |
| 72690 | 72145 | #endif |
| | @@ -72713,46 +72168,44 @@ |
| 72713 | 72168 | ** P1 is a boolean flag. If it is set to true and the xUpdate call |
| 72714 | 72169 | ** is successful, then the value returned by sqlite3_last_insert_rowid() |
| 72715 | 72170 | ** is set to the value of the rowid for the row just inserted. |
| 72716 | 72171 | */ |
| 72717 | 72172 | case OP_VUpdate: { |
| 72718 | | -#if 0 /* local variables moved into u.cr */ |
| 72719 | 72173 | sqlite3_vtab *pVtab; |
| 72720 | 72174 | sqlite3_module *pModule; |
| 72721 | 72175 | int nArg; |
| 72722 | 72176 | int i; |
| 72723 | 72177 | sqlite_int64 rowid; |
| 72724 | 72178 | Mem **apArg; |
| 72725 | 72179 | Mem *pX; |
| 72726 | | -#endif /* local variables moved into u.cr */ |
| 72727 | 72180 | |
| 72728 | | - assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 72181 | + assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 72729 | 72182 | || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| 72730 | 72183 | ); |
| 72731 | 72184 | assert( p->readOnly==0 ); |
| 72732 | | - u.cr.pVtab = pOp->p4.pVtab->pVtab; |
| 72733 | | - u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule; |
| 72734 | | - u.cr.nArg = pOp->p2; |
| 72185 | + pVtab = pOp->p4.pVtab->pVtab; |
| 72186 | + pModule = (sqlite3_module *)pVtab->pModule; |
| 72187 | + nArg = pOp->p2; |
| 72735 | 72188 | assert( pOp->p4type==P4_VTAB ); |
| 72736 | | - if( ALWAYS(u.cr.pModule->xUpdate) ){ |
| 72189 | + if( ALWAYS(pModule->xUpdate) ){ |
| 72737 | 72190 | u8 vtabOnConflict = db->vtabOnConflict; |
| 72738 | | - u.cr.apArg = p->apArg; |
| 72739 | | - u.cr.pX = &aMem[pOp->p3]; |
| 72740 | | - for(u.cr.i=0; u.cr.i<u.cr.nArg; u.cr.i++){ |
| 72741 | | - assert( memIsValid(u.cr.pX) ); |
| 72742 | | - memAboutToChange(p, u.cr.pX); |
| 72743 | | - sqlite3VdbeMemStoreType(u.cr.pX); |
| 72744 | | - u.cr.apArg[u.cr.i] = u.cr.pX; |
| 72745 | | - u.cr.pX++; |
| 72191 | + apArg = p->apArg; |
| 72192 | + pX = &aMem[pOp->p3]; |
| 72193 | + for(i=0; i<nArg; i++){ |
| 72194 | + assert( memIsValid(pX) ); |
| 72195 | + memAboutToChange(p, pX); |
| 72196 | + sqlite3VdbeMemStoreType(pX); |
| 72197 | + apArg[i] = pX; |
| 72198 | + pX++; |
| 72746 | 72199 | } |
| 72747 | 72200 | db->vtabOnConflict = pOp->p5; |
| 72748 | | - rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid); |
| 72201 | + rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); |
| 72749 | 72202 | db->vtabOnConflict = vtabOnConflict; |
| 72750 | | - sqlite3VtabImportErrmsg(p, u.cr.pVtab); |
| 72203 | + sqlite3VtabImportErrmsg(p, pVtab); |
| 72751 | 72204 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 72752 | | - assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) ); |
| 72753 | | - db->lastRowid = lastRowid = u.cr.rowid; |
| 72205 | + assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); |
| 72206 | + db->lastRowid = lastRowid = rowid; |
| 72754 | 72207 | } |
| 72755 | 72208 | if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 72756 | 72209 | if( pOp->p5==OE_Ignore ){ |
| 72757 | 72210 | rc = SQLITE_OK; |
| 72758 | 72211 | }else{ |
| | @@ -72808,38 +72261,36 @@ |
| 72808 | 72261 | ** |
| 72809 | 72262 | ** If tracing is enabled (by the sqlite3_trace()) interface, then |
| 72810 | 72263 | ** the UTF-8 string contained in P4 is emitted on the trace callback. |
| 72811 | 72264 | */ |
| 72812 | 72265 | case OP_Trace: { |
| 72813 | | -#if 0 /* local variables moved into u.cs */ |
| 72814 | 72266 | char *zTrace; |
| 72815 | 72267 | char *z; |
| 72816 | | -#endif /* local variables moved into u.cs */ |
| 72817 | 72268 | |
| 72818 | 72269 | if( db->xTrace |
| 72819 | 72270 | && !p->doingRerun |
| 72820 | | - && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72271 | + && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72821 | 72272 | ){ |
| 72822 | | - u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace); |
| 72823 | | - db->xTrace(db->pTraceArg, u.cs.z); |
| 72824 | | - sqlite3DbFree(db, u.cs.z); |
| 72273 | + z = sqlite3VdbeExpandSql(p, zTrace); |
| 72274 | + db->xTrace(db->pTraceArg, z); |
| 72275 | + sqlite3DbFree(db, z); |
| 72825 | 72276 | } |
| 72826 | 72277 | #ifdef SQLITE_USE_FCNTL_TRACE |
| 72827 | | - u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); |
| 72828 | | - if( u.cs.zTrace ){ |
| 72278 | + zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); |
| 72279 | + if( zTrace ){ |
| 72829 | 72280 | int i; |
| 72830 | 72281 | for(i=0; i<db->nDb; i++){ |
| 72831 | 72282 | if( ((1<<i) & p->btreeMask)==0 ) continue; |
| 72832 | | - sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace); |
| 72283 | + sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace); |
| 72833 | 72284 | } |
| 72834 | 72285 | } |
| 72835 | 72286 | #endif /* SQLITE_USE_FCNTL_TRACE */ |
| 72836 | 72287 | #ifdef SQLITE_DEBUG |
| 72837 | 72288 | if( (db->flags & SQLITE_SqlTrace)!=0 |
| 72838 | | - && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72289 | + && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72839 | 72290 | ){ |
| 72840 | | - sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace); |
| 72291 | + sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); |
| 72841 | 72292 | } |
| 72842 | 72293 | #endif /* SQLITE_DEBUG */ |
| 72843 | 72294 | break; |
| 72844 | 72295 | } |
| 72845 | 72296 | #endif |
| | @@ -72964,10 +72415,11 @@ |
| 72964 | 72415 | rc = SQLITE_INTERRUPT; |
| 72965 | 72416 | p->rc = rc; |
| 72966 | 72417 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc)); |
| 72967 | 72418 | goto vdbe_error_halt; |
| 72968 | 72419 | } |
| 72420 | + |
| 72969 | 72421 | |
| 72970 | 72422 | /************** End of vdbe.c ************************************************/ |
| 72971 | 72423 | /************** Begin file vdbeblob.c ****************************************/ |
| 72972 | 72424 | /* |
| 72973 | 72425 | ** 2007 May 1 |
| | @@ -88225,13 +87677,13 @@ |
| 88225 | 87677 | sqlite3StrAccumInit(&errMsg, 0, 0, 200); |
| 88226 | 87678 | errMsg.db = pParse->db; |
| 88227 | 87679 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 88228 | 87680 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 88229 | 87681 | if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); |
| 88230 | | - sqlite3StrAccumAppend(&errMsg, pTab->zName, -1); |
| 87682 | + sqlite3StrAccumAppendAll(&errMsg, pTab->zName); |
| 88231 | 87683 | sqlite3StrAccumAppend(&errMsg, ".", 1); |
| 88232 | | - sqlite3StrAccumAppend(&errMsg, zCol, -1); |
| 87684 | + sqlite3StrAccumAppendAll(&errMsg, zCol); |
| 88233 | 87685 | } |
| 88234 | 87686 | zErr = sqlite3StrAccumFinish(&errMsg); |
| 88235 | 87687 | sqlite3HaltConstraint(pParse, |
| 88236 | 87688 | (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE, |
| 88237 | 87689 | onError, zErr, P4_DYNAMIC, P5_ConstraintUnique); |
| | @@ -88419,12 +87871,13 @@ |
| 88419 | 87871 | } |
| 88420 | 87872 | if( pKey ){ |
| 88421 | 87873 | assert( sqlite3KeyInfoIsWriteable(pKey) ); |
| 88422 | 87874 | for(i=0; i<nCol; i++){ |
| 88423 | 87875 | char *zColl = pIdx->azColl[i]; |
| 88424 | | - if( NEVER(zColl==0) ) zColl = "BINARY"; |
| 88425 | | - pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl); |
| 87876 | + assert( zColl!=0 ); |
| 87877 | + pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 : |
| 87878 | + sqlite3LocateCollSeq(pParse, zColl); |
| 88426 | 87879 | pKey->aSortOrder[i] = pIdx->aSortOrder[i]; |
| 88427 | 87880 | } |
| 88428 | 87881 | if( pParse->nErr ){ |
| 88429 | 87882 | sqlite3KeyInfoUnref(pKey); |
| 88430 | 87883 | }else{ |
| | @@ -91238,15 +90691,15 @@ |
| 91238 | 90691 | nSep = sqlite3_value_bytes(argv[1]); |
| 91239 | 90692 | }else{ |
| 91240 | 90693 | zSep = ","; |
| 91241 | 90694 | nSep = 1; |
| 91242 | 90695 | } |
| 91243 | | - sqlite3StrAccumAppend(pAccum, zSep, nSep); |
| 90696 | + if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep); |
| 91244 | 90697 | } |
| 91245 | 90698 | zVal = (char*)sqlite3_value_text(argv[0]); |
| 91246 | 90699 | nVal = sqlite3_value_bytes(argv[0]); |
| 91247 | | - sqlite3StrAccumAppend(pAccum, zVal, nVal); |
| 90700 | + if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal); |
| 91248 | 90701 | } |
| 91249 | 90702 | } |
| 91250 | 90703 | static void groupConcatFinalize(sqlite3_context *context){ |
| 91251 | 90704 | StrAccum *pAccum; |
| 91252 | 90705 | pAccum = sqlite3_aggregate_context(context, 0); |
| | @@ -110314,12 +109767,11 @@ |
| 110314 | 109767 | int res; /* Result of comparison operation */ |
| 110315 | 109768 | |
| 110316 | 109769 | #ifndef SQLITE_DEBUG |
| 110317 | 109770 | UNUSED_PARAMETER( pParse ); |
| 110318 | 109771 | #endif |
| 110319 | | - assert( pRec!=0 || pParse->db->mallocFailed ); |
| 110320 | | - if( pRec==0 ) return; |
| 109772 | + assert( pRec!=0 ); |
| 110321 | 109773 | iCol = pRec->nField - 1; |
| 110322 | 109774 | assert( pIdx->nSample>0 ); |
| 110323 | 109775 | assert( pRec->nField>0 && iCol<pIdx->nSampleCol ); |
| 110324 | 109776 | do{ |
| 110325 | 109777 | iTest = (iMin+i)/2; |
| | @@ -110978,11 +110430,11 @@ |
| 110978 | 110430 | int iTerm, /* Index of this term. First is zero */ |
| 110979 | 110431 | const char *zColumn, /* Name of the column */ |
| 110980 | 110432 | const char *zOp /* Name of the operator */ |
| 110981 | 110433 | ){ |
| 110982 | 110434 | if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5); |
| 110983 | | - sqlite3StrAccumAppend(pStr, zColumn, -1); |
| 110435 | + sqlite3StrAccumAppendAll(pStr, zColumn); |
| 110984 | 110436 | sqlite3StrAccumAppend(pStr, zOp, 1); |
| 110985 | 110437 | sqlite3StrAccumAppend(pStr, "?", 1); |
| 110986 | 110438 | } |
| 110987 | 110439 | |
| 110988 | 110440 | /* |
| | @@ -111024,11 +110476,11 @@ |
| 111024 | 110476 | if( i>=nSkip ){ |
| 111025 | 110477 | explainAppendTerm(&txt, i, z, "="); |
| 111026 | 110478 | }else{ |
| 111027 | 110479 | if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5); |
| 111028 | 110480 | sqlite3StrAccumAppend(&txt, "ANY(", 4); |
| 111029 | | - sqlite3StrAccumAppend(&txt, z, -1); |
| 110481 | + sqlite3StrAccumAppendAll(&txt, z); |
| 111030 | 110482 | sqlite3StrAccumAppend(&txt, ")", 1); |
| 111031 | 110483 | } |
| 111032 | 110484 | } |
| 111033 | 110485 | |
| 111034 | 110486 | j = i; |
| | @@ -119582,11 +119034,12 @@ |
| 119582 | 119034 | } |
| 119583 | 119035 | db->lookaside.pEnd = p; |
| 119584 | 119036 | db->lookaside.bEnabled = 1; |
| 119585 | 119037 | db->lookaside.bMalloced = pBuf==0 ?1:0; |
| 119586 | 119038 | }else{ |
| 119587 | | - db->lookaside.pEnd = 0; |
| 119039 | + db->lookaside.pStart = db; |
| 119040 | + db->lookaside.pEnd = db; |
| 119588 | 119041 | db->lookaside.bEnabled = 0; |
| 119589 | 119042 | db->lookaside.bMalloced = 0; |
| 119590 | 119043 | } |
| 119591 | 119044 | return SQLITE_OK; |
| 119592 | 119045 | } |
| | @@ -120080,10 +119533,11 @@ |
| 120080 | 119533 | case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; |
| 120081 | 119534 | case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; |
| 120082 | 119535 | case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break; |
| 120083 | 119536 | case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break; |
| 120084 | 119537 | case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break; |
| 119538 | + case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break; |
| 120085 | 119539 | case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; |
| 120086 | 119540 | case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; |
| 120087 | 119541 | case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break; |
| 120088 | 119542 | case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break; |
| 120089 | 119543 | case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break; |
| 120090 | 119544 | |