Fossil SCM

Update the built-in SQLite to the latest version 3.8.3 alpha.

drh 2013-12-11 12:06 trunk
Commit faa2e9d5cf1672504124cec721f33e766ff25d68
2 files changed +1571 -2117 +13 -4
+1571 -2117
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** 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
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -133,13 +133,13 @@
133133
**
134134
** See also: [sqlite3_libversion()],
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
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"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -517,10 +517,11 @@
517517
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518518
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519519
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520520
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521521
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
522
+#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
522523
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
523524
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
524525
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
525526
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
526527
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -584,11 +585,12 @@
584585
** information is written to disk in the same order as calls
585586
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
586587
** after reboot following a crash or power loss, the only bytes in a
587588
** file that were written at the application level might have changed
588589
** 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.
590592
*/
591593
#define SQLITE_IOCAP_ATOMIC 0x00000001
592594
#define SQLITE_IOCAP_ATOMIC512 0x00000002
593595
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
594596
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -947,10 +949,16 @@
947949
** This file control is used by some VFS activity tracing [shims].
948950
** The argument is a zero-terminated string. Higher layers in the
949951
** SQLite stack may generate instances of this file control if
950952
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
951953
**
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
+**
952960
** </ul>
953961
*/
954962
#define SQLITE_FCNTL_LOCKSTATE 1
955963
#define SQLITE_GET_LOCKPROXYFILE 2
956964
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -967,10 +975,11 @@
967975
#define SQLITE_FCNTL_PRAGMA 14
968976
#define SQLITE_FCNTL_BUSYHANDLER 15
969977
#define SQLITE_FCNTL_TEMPFILENAME 16
970978
#define SQLITE_FCNTL_MMAP_SIZE 18
971979
#define SQLITE_FCNTL_TRACE 19
980
+#define SQLITE_FCNTL_HAS_MOVED 20
972981
973982
/*
974983
** CAPI3REF: Mutex Handle
975984
**
976985
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -12492,10 +12501,11 @@
1249212501
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1249312502
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1249412503
1249512504
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
1249612505
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
12506
+SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
1249712507
SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
1249812508
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
1249912509
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
1250012510
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
1250112511
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -13322,10 +13332,13 @@
1332213332
"SMALL_STACK",
1332313333
#endif
1332413334
#ifdef SQLITE_SOUNDEX
1332513335
"SOUNDEX",
1332613336
#endif
13337
+#ifdef SQLITE_SYSTEM_MALLOC
13338
+ "SYSTEM_MALLOC",
13339
+#endif
1332713340
#ifdef SQLITE_TCL
1332813341
"TCL",
1332913342
#endif
1333013343
#if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
1333113344
"TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
@@ -13336,10 +13349,13 @@
1333613349
#if defined(SQLITE_THREADSAFE)
1333713350
"THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
1333813351
#endif
1333913352
#ifdef SQLITE_USE_ALLOCA
1334013353
"USE_ALLOCA",
13354
+#endif
13355
+#ifdef SQLITE_WIN32_MALLOC
13356
+ "WIN32_MALLOC",
1334113357
#endif
1334213358
#ifdef SQLITE_ZERO_MALLOC
1334313359
"ZERO_MALLOC"
1334413360
#endif
1334513361
};
@@ -13789,11 +13805,11 @@
1378913805
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
1379013806
SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
1379113807
#endif
1379213808
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
1379313809
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);
1379513811
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
1379613812
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
1379713813
1379813814
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
1379913815
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -17518,11 +17534,11 @@
1751817534
** works for chunks that are currently checked out.
1751917535
*/
1752017536
static int memsys5Size(void *p){
1752117537
int iSize = 0;
1752217538
if( p ){
17523
- int i = ((u8 *)p-mem5.zPool)/mem5.szAtom;
17539
+ int i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom);
1752417540
assert( i>=0 && i<mem5.nBlock );
1752517541
iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
1752617542
}
1752717543
return iSize;
1752817544
}
@@ -17605,11 +17621,11 @@
1760517621
int iBlock;
1760617622
1760717623
/* Set iBlock to the index of the block pointed to by pOld in
1760817624
** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
1760917625
*/
17610
- iBlock = ((u8 *)pOld-mem5.zPool)/mem5.szAtom;
17626
+ iBlock = (int)(((u8 *)pOld-mem5.zPool)/mem5.szAtom);
1761117627
1761217628
/* Check that the pointer pOld points to a valid, non-free block. */
1761317629
assert( iBlock>=0 && iBlock<mem5.nBlock );
1761417630
assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
1761517631
assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
@@ -19374,11 +19390,11 @@
1937419390
/*
1937519391
** TRUE if p is a lookaside memory allocation from db
1937619392
*/
1937719393
#ifndef SQLITE_OMIT_LOOKASIDE
1937819394
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;
1938019396
}
1938119397
#else
1938219398
#define isLookaside(A,B) 0
1938319399
#endif
1938419400
@@ -19390,12 +19406,13 @@
1939019406
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1939119407
assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
1939219408
return sqlite3GlobalConfig.m.xSize(p);
1939319409
}
1939419410
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) ){
1939719414
return db->lookaside.sz;
1939819415
}else{
1939919416
assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
1940019417
assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
1940119418
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19873,10 +19890,18 @@
1987319890
}
1987419891
if( N>0 ){
1987519892
sqlite3StrAccumAppend(pAccum, zSpaces, N);
1987619893
}
1987719894
}
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
+}
1987819903
1987919904
/*
1988019905
** On machines with a small stack size, you can redefine the
1988119906
** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
1988219907
*/
@@ -20085,11 +20110,11 @@
2008520110
zOut = buf;
2008620111
}else{
2008720112
nOut = precision + 10;
2008820113
zOut = zExtra = sqlite3Malloc( nOut );
2008920114
if( zOut==0 ){
20090
- pAccum->accError = STRACCUM_NOMEM;
20115
+ setStrAccumError(pAccum, STRACCUM_NOMEM);
2009120116
return;
2009220117
}
2009320118
}
2009420119
bufpt = &zOut[nOut-1];
2009520120
if( xtype==etORDINAL ){
@@ -20197,11 +20222,11 @@
2019720222
e2 = exp;
2019820223
}
2019920224
if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
2020020225
bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
2020120226
if( bufpt==0 ){
20202
- pAccum->accError = STRACCUM_NOMEM;
20227
+ setStrAccumError(pAccum, STRACCUM_NOMEM);
2020320228
return;
2020420229
}
2020520230
}
2020620231
zOut = bufpt;
2020720232
nsd = 16 + flag_altform2*10;
@@ -20332,11 +20357,11 @@
2033220357
needQuote = !isnull && xtype==etSQLESCAPE2;
2033320358
n += i + 1 + needQuote*2;
2033420359
if( n>etBUFSIZE ){
2033520360
bufpt = zExtra = sqlite3Malloc( n );
2033620361
if( bufpt==0 ){
20337
- pAccum->accError = STRACCUM_NOMEM;
20362
+ setStrAccumError(pAccum, STRACCUM_NOMEM);
2033820363
return;
2033920364
}
2034020365
}else{
2034120366
bufpt = buf;
2034220367
}
@@ -20355,11 +20380,11 @@
2035520380
** if( precision>=0 && precision<length ) length = precision; */
2035620381
break;
2035720382
}
2035820383
case etTOKEN: {
2035920384
Token *pToken = va_arg(ap, Token*);
20360
- if( pToken ){
20385
+ if( pToken && pToken->n ){
2036120386
sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
2036220387
}
2036320388
length = width = 0;
2036420389
break;
2036520390
}
@@ -20367,14 +20392,14 @@
2036720392
SrcList *pSrc = va_arg(ap, SrcList*);
2036820393
int k = va_arg(ap, int);
2036920394
struct SrcList_item *pItem = &pSrc->a[k];
2037020395
assert( k>=0 && k<pSrc->nSrc );
2037120396
if( pItem->zDatabase ){
20372
- sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1);
20397
+ sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
2037320398
sqlite3StrAccumAppend(pAccum, ".", 1);
2037420399
}
20375
- sqlite3StrAccumAppend(pAccum, pItem->zName, -1);
20400
+ sqlite3StrAccumAppendAll(pAccum, pItem->zName);
2037620401
length = width = 0;
2037720402
break;
2037820403
}
2037920404
default: {
2038020405
assert( xtype==etINVALID );
@@ -20409,36 +20434,34 @@
2040920434
2041020435
/*
2041120436
** Append N bytes of text from z to the StrAccum object.
2041220437
*/
2041320438
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 );
2042520443
if( p->nChar+N >= p->nAlloc ){
2042620444
char *zNew;
20445
+ if( p->accError ){
20446
+ testcase(p->accError==STRACCUM_TOOBIG);
20447
+ testcase(p->accError==STRACCUM_NOMEM);
20448
+ return;
20449
+ }
2042720450
if( !p->useMalloc ){
20428
- p->accError = STRACCUM_TOOBIG;
2042920451
N = p->nAlloc - p->nChar - 1;
20452
+ setStrAccumError(p, STRACCUM_TOOBIG);
2043020453
if( N<=0 ){
2043120454
return;
2043220455
}
2043320456
}else{
2043420457
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
2043520458
i64 szNew = p->nChar;
2043620459
szNew += N + 1;
2043720460
if( szNew > p->mxAlloc ){
2043820461
sqlite3StrAccumReset(p);
20439
- p->accError = STRACCUM_TOOBIG;
20462
+ setStrAccumError(p, STRACCUM_TOOBIG);
2044020463
return;
2044120464
}else{
2044220465
p->nAlloc = (int)szNew;
2044320466
}
2044420467
if( p->useMalloc==1 ){
@@ -20448,20 +20471,28 @@
2044820471
}
2044920472
if( zNew ){
2045020473
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2045120474
p->zText = zNew;
2045220475
}else{
20453
- p->accError = STRACCUM_NOMEM;
2045420476
sqlite3StrAccumReset(p);
20477
+ setStrAccumError(p, STRACCUM_NOMEM);
2045520478
return;
2045620479
}
2045720480
}
2045820481
}
2045920482
assert( p->zText );
2046020483
memcpy(&p->zText[p->nChar], z, N);
2046120484
p->nChar += N;
2046220485
}
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
+
2046320494
2046420495
/*
2046520496
** Finish off a string by making sure it is zero-terminated.
2046620497
** Return a pointer to the resulting string. Return a NULL
2046720498
** pointer if any kind of error was encountered.
@@ -20476,11 +20507,11 @@
2047620507
p->zText = sqlite3_malloc(p->nChar+1);
2047720508
}
2047820509
if( p->zText ){
2047920510
memcpy(p->zText, p->zBase, p->nChar+1);
2048020511
}else{
20481
- p->accError = STRACCUM_NOMEM;
20512
+ setStrAccumError(p, STRACCUM_NOMEM);
2048220513
}
2048320514
}
2048420515
}
2048520516
return p->zText;
2048620517
}
@@ -22629,11 +22660,13 @@
2262922660
if( x<10 ) return 1;
2263022661
n = x%10;
2263122662
x /= 10;
2263222663
if( n>=5 ) n -= 2;
2263322664
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
+ }
2263522668
return (n+8)>>(3-x);
2263622669
}
2263722670
2263822671
/************** End of util.c ************************************************/
2263922672
/************** Begin file hash.c ********************************************/
@@ -24611,10 +24644,19 @@
2461124644
}
2461224645
*ppInode = pInode;
2461324646
return SQLITE_OK;
2461424647
}
2461524648
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
+
2461624658
2461724659
/*
2461824660
** Check a unixFile that is a database. Verify the following:
2461924661
**
2462024662
** (1) There is exactly one hard link on the file
@@ -24645,14 +24687,11 @@
2464524687
if( buf.st_nlink>1 ){
2464624688
sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
2464724689
pFile->ctrlFlags |= UNIXFILE_WARNED;
2464824690
return;
2464924691
}
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) ){
2465424693
sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
2465524694
pFile->ctrlFlags |= UNIXFILE_WARNED;
2465624695
return;
2465724696
}
2465824697
}
@@ -27096,10 +27135,14 @@
2709627135
if( zTFile ){
2709727136
unixGetTempname(pFile->pVfs->mxPathname, zTFile);
2709827137
*(char**)pArg = zTFile;
2709927138
}
2710027139
return SQLITE_OK;
27140
+ }
27141
+ case SQLITE_FCNTL_HAS_MOVED: {
27142
+ *(int*)pArg = fileHasMoved(pFile);
27143
+ return SQLITE_OK;
2710127144
}
2710227145
#if SQLITE_MAX_MMAP_SIZE>0
2710327146
case SQLITE_FCNTL_MMAP_SIZE: {
2710427147
i64 newLimit = *(i64*)pArg;
2710527148
int rc = SQLITE_OK;
@@ -27377,11 +27420,11 @@
2737727420
2737827421
/* Update the global lock state and do debug tracing */
2737927422
#ifdef SQLITE_DEBUG
2738027423
{ u16 mask;
2738127424
OSTRACE(("SHM-LOCK "));
27382
- mask = (1<<(ofst+n)) - (1<<ofst);
27425
+ mask = ofst>31 ? 0xffffffff : (1<<(ofst+n)) - (1<<ofst);
2738327426
if( rc==SQLITE_OK ){
2738427427
if( lockType==F_UNLCK ){
2738527428
OSTRACE(("unlock %d ok", ofst));
2738627429
pShmNode->exclMask &= ~mask;
2738727430
pShmNode->sharedMask &= ~mask;
@@ -43889,10 +43932,34 @@
4388943932
*ppPager = pPager;
4389043933
return SQLITE_OK;
4389143934
}
4389243935
4389343936
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
+
4389443961
4389543962
/*
4389643963
** This function is called after transitioning from PAGER_UNLOCK to
4389743964
** PAGER_SHARED state. It tests if there is a hot journal present in
4389843965
** the file-system for the given pager. A hot journal is one that
@@ -44360,11 +44427,11 @@
4436044427
if( bMmapOk && pagerUseWal(pPager) ){
4436144428
rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
4436244429
if( rc!=SQLITE_OK ) goto pager_acquire_err;
4436344430
}
4436444431
44365
- if( iFrame==0 && bMmapOk ){
44432
+ if( bMmapOk && iFrame==0 ){
4436644433
void *pData = 0;
4436744434
4436844435
rc = sqlite3OsFetch(pPager->fd,
4436944436
(i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
4437044437
);
@@ -44565,17 +44632,23 @@
4456544632
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
4456644633
(pPager->tempFile ?
4456744634
(SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
4456844635
(SQLITE_OPEN_MAIN_JOURNAL)
4456944636
);
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
+ }
4457744650
}
4457844651
assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
4457944652
}
4458044653
4458144654
@@ -44705,18 +44778,12 @@
4470544778
assert( pPager->eState==PAGER_WRITER_LOCKED
4470644779
|| pPager->eState==PAGER_WRITER_CACHEMOD
4470744780
|| pPager->eState==PAGER_WRITER_DBMOD
4470844781
);
4470944782
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 );
4471844785
4471944786
CHECK_PAGE(pPg);
4472044787
4472144788
/* The journal file needs to be opened. Higher level routines have already
4472244789
** obtained the necessary locks to begin the write-transaction, but the
@@ -44841,23 +44908,23 @@
4484144908
SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
4484244909
int rc = SQLITE_OK;
4484344910
4484444911
PgHdr *pPg = pDbPage;
4484544912
Pager *pPager = pPg->pPager;
44846
- Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
4484744913
4484844914
assert( (pPg->flags & PGHDR_MMAP)==0 );
4484944915
assert( pPager->eState>=PAGER_WRITER_LOCKED );
4485044916
assert( pPager->eState!=PAGER_ERROR );
4485144917
assert( assert_pager_state(pPager) );
4485244918
44853
- if( nPagePerSector>1 ){
44919
+ if( pPager->sectorSize > (u32)pPager->pageSize ){
4485444920
Pgno nPageCount; /* Total number of pages in database file */
4485544921
Pgno pg1; /* First page of the sector pPg is located on. */
4485644922
int nPage = 0; /* Number of pages starting at pg1 to journal */
4485744923
int ii; /* Loop counter */
4485844924
int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
44925
+ Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
4485944926
4486044927
/* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
4486144928
** a journal header to be written between the pages journaled by
4486244929
** this function.
4486344930
*/
@@ -51991,11 +52058,11 @@
5199152058
5199252059
if( pgno>btreePagecount(pBt) ){
5199352060
rc = SQLITE_CORRUPT_BKPT;
5199452061
}else{
5199552062
rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
51996
- if( rc==SQLITE_OK ){
52063
+ if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
5199752064
rc = btreeInitPage(*ppPage);
5199852065
if( rc!=SQLITE_OK ){
5199952066
releasePage(*ppPage);
5200052067
}
5200152068
}
@@ -54531,14 +54598,14 @@
5453154598
}
5453254599
5453354600
/*
5453454601
** Return a pointer to payload information from the entry that the
5453554602
** 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.
5454054607
**
5454154608
** This routine is an optimization. It is common for the entire key
5454254609
** and data to fit on the local page and for there to be no overflow
5454354610
** pages. When that is so, this routine can be used to access the
5454454611
** key and data without making a copy. If the key and/or data spills
@@ -54547,45 +54614,25 @@
5454754614
**
5454854615
** The pointer returned by this routine looks directly into the cached
5454954616
** page of the database. The data might change or move the next time
5455054617
** any btree routine is called.
5455154618
*/
54552
-static const unsigned char *fetchPayload(
54619
+static const void *fetchPayload(
5455354620
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 */
5455654622
){
54557
- unsigned char *aPayload;
54558
- MemPage *pPage;
54559
- u32 nKey;
54560
- u32 nLocal;
54561
-
5456254623
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
5456354624
assert( pCur->eState==CURSOR_VALID );
54625
+ assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5456454626
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 );
5456754628
if( pCur->info.nSize==0 ){
5456854629
btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
5456954630
&pCur->info);
5457054631
}
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);
5458754634
}
5458854635
5458954636
5459054637
/*
5459154638
** For the entry that cursor pCur is point to, return as
@@ -54600,26 +54647,14 @@
5460054647
**
5460154648
** These routines is used to get quick access to key and data
5460254649
** in the common case where no overflow pages are used.
5460354650
*/
5460454651
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);
5461254653
}
5461354654
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);
5462154656
}
5462254657
5462354658
5462454659
/*
5462554660
** Move the cursor down to a new child page. The newPgno argument is the
@@ -54734,12 +54769,10 @@
5473454769
** b-tree).
5473554770
*/
5473654771
static int moveToRoot(BtCursor *pCur){
5473754772
MemPage *pRoot;
5473854773
int rc = SQLITE_OK;
54739
- Btree *p = pCur->pBtree;
54740
- BtShared *pBt = p->pBt;
5474154774
5474254775
assert( cursorHoldsMutex(pCur) );
5474354776
assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
5474454777
assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
5474554778
assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54750,20 +54783,16 @@
5475054783
}
5475154784
sqlite3BtreeClearCursor(pCur);
5475254785
}
5475354786
5475454787
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--]);
5476054789
}else if( pCur->pgnoRoot==0 ){
5476154790
pCur->eState = CURSOR_INVALID;
5476254791
return SQLITE_OK;
5476354792
}else{
54764
- rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
54793
+ rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
5476554794
pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
5476654795
if( rc!=SQLITE_OK ){
5476754796
pCur->eState = CURSOR_INVALID;
5476854797
return rc;
5476954798
}
@@ -54792,18 +54821,20 @@
5479254821
pCur->aiIdx[0] = 0;
5479354822
pCur->info.nSize = 0;
5479454823
pCur->atLast = 0;
5479554824
pCur->validNKey = 0;
5479654825
54797
- if( pRoot->nCell==0 && !pRoot->leaf ){
54826
+ if( pRoot->nCell>0 ){
54827
+ pCur->eState = CURSOR_VALID;
54828
+ }else if( !pRoot->leaf ){
5479854829
Pgno subpage;
5479954830
if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
5480054831
subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
5480154832
pCur->eState = CURSOR_VALID;
5480254833
rc = moveToChild(pCur, subpage);
5480354834
}else{
54804
- pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
54835
+ pCur->eState = CURSOR_INVALID;
5480554836
}
5480654837
return rc;
5480754838
}
5480854839
5480954840
/*
@@ -55055,21 +55086,18 @@
5505555086
** the entire cell by checking for the cases where the record is
5505655087
** stored entirely within the b-tree page by inspecting the first
5505755088
** 2 bytes of the cell.
5505855089
*/
5505955090
nCell = pCell[0];
55060
- if( nCell<=pPage->max1bytePayload
55061
- /* && (pCell+nCell)<pPage->aDataEnd */
55062
- ){
55091
+ if( nCell<=pPage->max1bytePayload ){
5506355092
/* This branch runs if the record-size field of the cell is a
5506455093
** single byte varint and the record fits entirely on the main
5506555094
** b-tree page. */
5506655095
testcase( pCell+nCell+1==pPage->aDataEnd );
5506755096
c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
5506855097
}else if( !(pCell[1] & 0x80)
5506955098
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
55070
- /* && (pCell+nCell+2)<=pPage->aDataEnd */
5507155099
){
5507255100
/* The record-size field is a 2 byte varint and the record
5507355101
** fits entirely on the main b-tree page. */
5507455102
testcase( pCell+nCell+2==pPage->aDataEnd );
5507555103
c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -55889,11 +55917,11 @@
5588955917
nHeader = 0;
5589055918
if( !pPage->leaf ){
5589155919
nHeader += 4;
5589255920
}
5589355921
if( pPage->hasData ){
55894
- nHeader += putVarint(&pCell[nHeader], nData+nZero);
55922
+ nHeader += putVarint32(&pCell[nHeader], nData+nZero);
5589555923
}else{
5589655924
nData = nZero = 0;
5589755925
}
5589855926
nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
5589955927
btreeParseCellPtr(pPage, pCell, &info);
@@ -56017,11 +56045,10 @@
5601756045
*/
5601856046
static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
5601956047
u32 pc; /* Offset to cell content of cell being deleted */
5602056048
u8 *data; /* pPage->aData */
5602156049
u8 *ptr; /* Used to move bytes around within data[] */
56022
- u8 *endPtr; /* End of loop */
5602356050
int rc; /* The return code */
5602456051
int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
5602556052
5602656053
if( *pRC ) return;
5602756054
@@ -56042,17 +56069,12 @@
5604256069
rc = freeSpace(pPage, pc, sz);
5604356070
if( rc ){
5604456071
*pRC = rc;
5604556072
return;
5604656073
}
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
- }
5605356074
pPage->nCell--;
56075
+ memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
5605456076
put2byte(&data[hdr+3], pPage->nCell);
5605556077
pPage->nFree += 2;
5605656078
}
5605756079
5605856080
/*
@@ -56085,13 +56107,10 @@
5608556107
int j; /* Loop counter */
5608656108
int end; /* First byte past the last cell pointer in data[] */
5608756109
int ins; /* Index in data[] where new cell pointer is inserted */
5608856110
int cellOffset; /* Address of first cell pointer in data[] */
5608956111
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
-
5609356112
int nSkip = (iChild ? 4 : 0);
5609456113
5609556114
if( *pRC ) return;
5609656115
5609756116
assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56138,17 +56157,11 @@
5613856157
pPage->nFree -= (u16)(2 + sz);
5613956158
memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
5614056159
if( iChild ){
5614156160
put4byte(&data[idx], iChild);
5614256161
}
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);
5615056163
put2byte(&data[ins], idx);
5615156164
put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
5615256165
#ifndef SQLITE_OMIT_AUTOVACUUM
5615356166
if( pPage->pBt->autoVacuum ){
5615456167
/* The cell may contain a pointer to an overflow page. If so, write
@@ -58106,11 +58119,11 @@
5810658119
va_start(ap, zFormat);
5810758120
if( pCheck->errMsg.nChar ){
5810858121
sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
5810958122
}
5811058123
if( zMsg1 ){
58111
- sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
58124
+ sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1);
5811258125
}
5811358126
sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
5811458127
va_end(ap);
5811558128
if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
5811658129
pCheck->mallocFailed = 1;
@@ -59682,61 +59695,59 @@
5968259695
#endif
5968359696
}
5968459697
5968559698
/*
5968659699
** 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){
5969959708
assert( 1 >=
5970059709
((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
5970159710
(((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
5970259711
((pMem->flags&MEM_Ephem) ? 1 : 0) +
5970359712
((pMem->flags&MEM_Static) ? 1 : 0)
5970459713
);
5970559714
assert( (pMem->flags&MEM_RowSet)==0 );
5970659715
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
5970859717
** 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 );
5971059720
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 ){
5971459724
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59715
- preserve = 0;
59725
+ bPreserve = 0;
5971659726
}else{
5971759727
sqlite3DbFree(pMem->db, pMem->zMalloc);
5971859728
pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
5971959729
}
59730
+ if( pMem->zMalloc==0 ){
59731
+ sqlite3VdbeMemRelease(pMem);
59732
+ pMem->flags = MEM_Null;
59733
+ return SQLITE_NOMEM;
59734
+ }
5972059735
}
5972159736
59722
- if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
59737
+ if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
5972359738
memcpy(pMem->zMalloc, pMem->z, pMem->n);
5972459739
}
59725
- if( pMem->flags&MEM_Dyn && pMem->xDel ){
59740
+ if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
5972659741
assert( pMem->xDel!=SQLITE_DYNAMIC );
5972759742
pMem->xDel((void *)(pMem->z));
5972859743
}
5972959744
5973059745
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);
5973659747
pMem->xDel = 0;
59737
- return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);
59748
+ return SQLITE_OK;
5973859749
}
5973959750
5974059751
/*
5974159752
** Make the given Mem object MEM_Dyn. In other words, make it so
5974259753
** that any TEXT or BLOB content is stored in memory obtained from
@@ -59918,14 +59929,16 @@
5991859929
** inconsistent state, for example with (Mem.z==0) and
5991959930
** (Mem.type==SQLITE_TEXT).
5992059931
*/
5992159932
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
5992259933
VdbeMemRelease(p);
59923
- sqlite3DbFree(p->db, p->zMalloc);
59934
+ if( p->zMalloc ){
59935
+ sqlite3DbFree(p->db, p->zMalloc);
59936
+ p->zMalloc = 0;
59937
+ }
5992459938
p->z = 0;
59925
- p->zMalloc = 0;
59926
- p->xDel = 0;
59939
+ assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */
5992759940
}
5992859941
5992959942
/*
5993059943
** Convert a 64-bit IEEE double into a 64-bit signed integer.
5993159944
** If the double is out of range of a 64-bit signed integer then
@@ -60639,19 +60652,19 @@
6063960652
Index *pIdx = p->pIdx; /* Index being probed */
6064060653
int nByte; /* Bytes of space to allocate */
6064160654
int i; /* Counter variable */
6064260655
int nCol = pIdx->nColumn; /* Number of index columns including rowid */
6064360656
60644
- nByte = sizeof(Mem) * nCol + sizeof(UnpackedRecord);
60657
+ nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
6064560658
pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
6064660659
if( pRec ){
6064760660
pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
6064860661
if( pRec->pKeyInfo ){
6064960662
assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
6065060663
assert( pRec->pKeyInfo->enc==ENC(db) );
6065160664
pRec->flags = UNPACKED_PREFIX_MATCH;
60652
- pRec->aMem = (Mem *)&pRec[1];
60665
+ pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
6065360666
for(i=0; i<nCol; i++){
6065460667
pRec->aMem[i].flags = MEM_Null;
6065560668
pRec->aMem[i].type = SQLITE_NULL;
6065660669
pRec->aMem[i].db = db;
6065760670
}
@@ -60842,11 +60855,11 @@
6084260855
if( aRet==0 ){
6084360856
sqlite3_result_error_nomem(context);
6084460857
}else{
6084560858
aRet[0] = nSerial+1;
6084660859
sqlite3PutVarint(&aRet[1], iSerial);
60847
- sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format);
60860
+ sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
6084860861
sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
6084960862
sqlite3DbFree(db, aRet);
6085060863
}
6085160864
}
6085260865
@@ -60920,11 +60933,10 @@
6092060933
6092160934
if( !pExpr ){
6092260935
pVal = valueNew(db, &alloc);
6092360936
if( pVal ){
6092460937
sqlite3VdbeMemSetNull((Mem*)pVal);
60925
- *pbOk = 1;
6092660938
}
6092760939
}else if( pExpr->op==TK_VARIABLE
6092860940
|| NEVER(pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
6092960941
){
6093060942
Vdbe *v;
@@ -60936,20 +60948,17 @@
6093660948
rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
6093760949
if( rc==SQLITE_OK ){
6093860950
sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
6093960951
}
6094060952
pVal->db = pParse->db;
60941
- *pbOk = 1;
6094260953
sqlite3VdbeMemStoreType((Mem*)pVal);
6094360954
}
60944
- }else{
60945
- *pbOk = 0;
6094660955
}
6094760956
}else{
6094860957
rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
60949
- *pbOk = (pVal!=0);
6095060958
}
60959
+ *pbOk = (pVal!=0);
6095160960
6095260961
assert( pVal==0 || pVal->db==db );
6095360962
return rc;
6095460963
}
6095560964
@@ -63838,25 +63847,19 @@
6383863847
/*
6383963848
** Write the serialized data blob for the value stored in pMem into
6384063849
** buf. It is assumed that the caller has allocated sufficient space.
6384163850
** Return the number of bytes written.
6384263851
**
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.
6385163855
**
6385263856
** Return the number of bytes actually written into buf[]. The number
6385363857
** of bytes in the zero-filled tail is included in the return value only
6385463858
** if those bytes were zeroed in buf[].
6385563859
*/
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){
6385863861
u32 len;
6385963862
6386063863
/* Integer and Real */
6386163864
if( serial_type<=7 && serial_type>0 ){
6386263865
u64 v;
@@ -63867,11 +63870,10 @@
6386763870
swapMixedEndianFloat(v);
6386863871
}else{
6386963872
v = pMem->u.i;
6387063873
}
6387163874
len = i = sqlite3VdbeSerialTypeLen(serial_type);
63872
- assert( len<=(u32)nBuf );
6387363875
while( i-- ){
6387463876
buf[i] = (u8)(v&0xFF);
6387563877
v >>= 8;
6387663878
}
6387763879
return len;
@@ -63879,21 +63881,12 @@
6387963881
6388063882
/* String or blob */
6388163883
if( serial_type>=12 ){
6388263884
assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
6388363885
== (int)sqlite3VdbeSerialTypeLen(serial_type) );
63884
- assert( pMem->n<=nBuf );
6388563886
len = pMem->n;
6388663887
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
- }
6389563888
return len;
6389663889
}
6389763890
6389863891
/* NULL or constants 0 or 1 */
6389963892
return 0;
@@ -65815,10 +65808,11 @@
6581565808
if( db->nVdbeExec>1 ){
6581665809
while( *zRawSql ){
6581765810
const char *zStart = zRawSql;
6581865811
while( *(zRawSql++)!='\n' && *zRawSql );
6581965812
sqlite3StrAccumAppend(&out, "-- ", 3);
65813
+ assert( (zRawSql - zStart) > 0 );
6582065814
sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
6582165815
}
6582265816
}else{
6582365817
while( zRawSql[0] ){
6582465818
n = findNextHostParameter(zRawSql, &nToken);
@@ -66658,433 +66652,11 @@
6665866652
i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
6665966653
#ifdef VDBE_PROFILE
6666066654
u64 start; /* CPU clock count at start of opcode */
6666166655
int origPc; /* Program counter at start of opcode */
6666266656
#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 ***/
6708666658
6708766659
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
6708866660
sqlite3VdbeEnter(p);
6708966661
if( p->rc==SQLITE_NOMEM ){
6709066662
/* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67326,20 +66898,18 @@
6732666898
/* Opcode: Yield P1 * * * *
6732766899
**
6732866900
** Swap the program counter with the value in register P1.
6732966901
*/
6733066902
case OP_Yield: { /* in1 */
67331
-#if 0 /* local variables moved into u.aa */
6733266903
int pcDest;
67333
-#endif /* local variables moved into u.aa */
6733466904
pIn1 = &aMem[pOp->p1];
6733566905
assert( (pIn1->flags & MEM_Dyn)==0 );
6733666906
pIn1->flags = MEM_Int;
67337
- u.aa.pcDest = (int)pIn1->u.i;
66907
+ pcDest = (int)pIn1->u.i;
6733866908
pIn1->u.i = pc;
6733966909
REGISTER_TRACE(pOp->p1, pIn1);
67340
- pc = u.aa.pcDest;
66910
+ pc = pcDest;
6734166911
break;
6734266912
}
6734366913
6734466914
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
6734566915
** Synopsis: if r[P3] null then halt
@@ -67384,14 +66954,12 @@
6738466954
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
6738566955
** every program. So a jump past the last instruction of the program
6738666956
** is the same as executing Halt.
6738766957
*/
6738866958
case OP_Halt: {
67389
-#if 0 /* local variables moved into u.ab */
6739066959
const char *zType;
6739166960
const char *zLogFmt;
67392
-#endif /* local variables moved into u.ab */
6739366961
6739466962
if( pOp->p1==SQLITE_OK && p->pFrame ){
6739566963
/* Halt the sub-program. Return control to the parent frame. */
6739666964
VdbeFrame *pFrame = p->pFrame;
6739766965
p->pFrame = pFrame->pParent;
@@ -67398,11 +66966,11 @@
6739866966
p->nFrame--;
6739966967
sqlite3VdbeSetChanges(db, p->nChange);
6740066968
pc = sqlite3VdbeFrameRestore(pFrame);
6740166969
lastRowid = db->lastRowid;
6740266970
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
6740466972
** currently being halted. If the p2 instruction of this OP_Halt
6740566973
** instruction is set to OE_Ignore, then the sub-program is throwing
6740666974
** an IGNORE exception. In this case jump to the address specified
6740766975
** as the p2 of the calling OP_Program. */
6740866976
pc = p->aOp[pc].p2-1;
@@ -67421,25 +66989,25 @@
6742166989
assert( pOp->p5>=1 && pOp->p5<=4 );
6742266990
testcase( pOp->p5==1 );
6742366991
testcase( pOp->p5==2 );
6742466992
testcase( pOp->p5==3 );
6742566993
testcase( pOp->p5==4 );
67426
- u.ab.zType = azType[pOp->p5-1];
66994
+ zType = azType[pOp->p5-1];
6742766995
}else{
67428
- u.ab.zType = 0;
66996
+ zType = 0;
6742966997
}
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);
6743567003
}else if( pOp->p4.z ){
6743667004
sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
6743767005
}else{
67438
- sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType);
67006
+ sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
6743967007
}
67440
- sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg);
67008
+ sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
6744167009
}
6744267010
rc = sqlite3VdbeHalt(p);
6744367011
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
6744467012
if( rc==SQLITE_BUSY ){
6744567013
p->rc = rc = SQLITE_BUSY;
@@ -67549,23 +67117,21 @@
6754967117
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
6755067118
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
6755167119
** OP_Ne or OP_Eq.
6755267120
*/
6755367121
case OP_Null: { /* out2-prerelease */
67554
-#if 0 /* local variables moved into u.ac */
6755567122
int cnt;
6755667123
u16 nullFlag;
67557
-#endif /* local variables moved into u.ac */
67558
- u.ac.cnt = pOp->p3-pOp->p2;
67124
+ cnt = pOp->p3-pOp->p2;
6755967125
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 ){
6756267128
pOut++;
6756367129
memAboutToChange(p, pOut);
6756467130
VdbeMemRelease(pOut);
67565
- pOut->flags = u.ac.nullFlag;
67566
- u.ac.cnt--;
67131
+ pOut->flags = nullFlag;
67132
+ cnt--;
6756767133
}
6756867134
break;
6756967135
}
6757067136
6757167137
@@ -67590,21 +67156,19 @@
6759067156
**
6759167157
** If the parameter is named, then its name appears in P4 and P3==1.
6759267158
** The P4 value is used by sqlite3_bind_parameter_name().
6759367159
*/
6759467160
case OP_Variable: { /* out2-prerelease */
67595
-#if 0 /* local variables moved into u.ad */
6759667161
Mem *pVar; /* Value being transferred */
67597
-#endif /* local variables moved into u.ad */
6759867162
6759967163
assert( pOp->p1>0 && pOp->p1<=p->nVar );
6760067164
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) ){
6760367167
goto too_big;
6760467168
}
67605
- sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static);
67169
+ sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
6760667170
UPDATE_MAX_BLOBSIZE(pOut);
6760767171
break;
6760867172
}
6760967173
6761067174
/* Opcode: Move P1 P2 P3 * *
@@ -67614,43 +67178,41 @@
6761467178
** registers P2..P2+P3. Registers P1..P1+P3 are
6761567179
** left holding a NULL. It is an error for register ranges
6761667180
** P1..P1+P3 and P2..P2+P3 to overlap.
6761767181
*/
6761867182
case OP_Move: {
67619
-#if 0 /* local variables moved into u.ae */
6762067183
char *zMalloc; /* Holding variable for allocated memory */
6762167184
int n; /* Number of registers left to copy */
6762267185
int p1; /* Register to copy from */
6762367186
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];
6763467196
do{
6763567197
assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
6763667198
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
6763767199
assert( memIsValid(pIn1) );
6763867200
memAboutToChange(p, pOut);
67639
- u.ae.zMalloc = pOut->zMalloc;
67201
+ zMalloc = pOut->zMalloc;
6764067202
pOut->zMalloc = 0;
6764167203
sqlite3VdbeMemMove(pOut, pIn1);
6764267204
#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;
6764567207
}
6764667208
#endif
67647
- pIn1->zMalloc = u.ae.zMalloc;
67648
- REGISTER_TRACE(u.ae.p2++, pOut);
67209
+ pIn1->zMalloc = zMalloc;
67210
+ REGISTER_TRACE(p2++, pOut);
6764967211
pIn1++;
6765067212
pOut++;
67651
- }while( u.ae.n-- );
67213
+ }while( n-- );
6765267214
break;
6765367215
}
6765467216
6765567217
/* Opcode: Copy P1 P2 P3 * *
6765667218
** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67659,26 +67221,24 @@
6765967221
**
6766067222
** This instruction makes a deep copy of the value. A duplicate
6766167223
** is made of any string or blob constant. See also OP_SCopy.
6766267224
*/
6766367225
case OP_Copy: {
67664
-#if 0 /* local variables moved into u.af */
6766567226
int n;
67666
-#endif /* local variables moved into u.af */
6766767227
67668
- u.af.n = pOp->p3;
67228
+ n = pOp->p3;
6766967229
pIn1 = &aMem[pOp->p1];
6767067230
pOut = &aMem[pOp->p2];
6767167231
assert( pOut!=pIn1 );
6767267232
while( 1 ){
6767367233
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
6767467234
Deephemeralize(pOut);
6767567235
#ifdef SQLITE_DEBUG
6767667236
pOut->pScopyFrom = 0;
6767767237
#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;
6768067240
pOut++;
6768167241
pIn1++;
6768267242
}
6768367243
break;
6768467244
}
@@ -67715,14 +67275,12 @@
6771567275
** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
6771667276
** structure to provide access to the top P1 values as the result
6771767277
** row.
6771867278
*/
6771967279
case OP_ResultRow: {
67720
-#if 0 /* local variables moved into u.ag */
6772167280
Mem *pMem;
6772267281
int i;
67723
-#endif /* local variables moved into u.ag */
6772467282
assert( p->nResColumn==pOp->p2 );
6772567283
assert( pOp->p1>0 );
6772667284
assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
6772767285
6772867286
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -67744,12 +67302,12 @@
6774467302
assert( db->flags&SQLITE_CountRows );
6774567303
assert( p->usesStmtJournal );
6774667304
break;
6774767305
}
6774867306
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
6775167309
** modified to the user. This is the only way that a VM that
6775267310
** opens a statement transaction may invoke this opcode.
6775367311
**
6775467312
** In case this is such a statement, close any statement transaction
6775567313
** opened by this VM before returning control to the user. This is to
@@ -67772,19 +67330,19 @@
6777267330
6777367331
/* Make sure the results of the current row are \000 terminated
6777467332
** and have an assigned type. The results are de-ephemeralized as
6777567333
** a side effect.
6777667334
*/
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]);
6778667344
}
6778767345
if( db->mallocFailed ) goto no_mem;
6778867346
6778967347
/* Return SQLITE_ROW
6779067348
*/
@@ -67805,13 +67363,11 @@
6780567363
** It is illegal for P1 and P3 to be the same register. Sometimes,
6780667364
** if P3 is the same register as P2, the implementation is able
6780767365
** to avoid a memcpy().
6780867366
*/
6780967367
case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67810
-#if 0 /* local variables moved into u.ah */
6781167368
i64 nByte;
67812
-#endif /* local variables moved into u.ah */
6781367369
6781467370
pIn1 = &aMem[pOp->p1];
6781567371
pIn2 = &aMem[pOp->p2];
6781667372
pOut = &aMem[pOp->p3];
6781767373
assert( pIn1!=pOut );
@@ -67820,26 +67376,26 @@
6782067376
break;
6782167377
}
6782267378
if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
6782367379
Stringify(pIn1, encoding);
6782467380
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] ){
6782767383
goto too_big;
6782867384
}
6782967385
MemSetTypeFlag(pOut, MEM_Str);
67830
- if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){
67386
+ if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
6783167387
goto no_mem;
6783267388
}
6783367389
if( pOut!=pIn2 ){
6783467390
memcpy(pOut->z, pIn2->z, pIn2->n);
6783567391
}
6783667392
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;
6783967395
pOut->flags |= MEM_Term;
67840
- pOut->n = (int)u.ah.nByte;
67396
+ pOut->n = (int)nByte;
6784167397
pOut->enc = encoding;
6784267398
UPDATE_MAX_BLOBSIZE(pOut);
6784367399
break;
6784467400
}
6784567401
@@ -67884,83 +67440,81 @@
6788467440
case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
6788567441
case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
6788667442
case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
6788767443
case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
6788867444
case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67889
-#if 0 /* local variables moved into u.ai */
6789067445
char bIntint; /* Started out as two integer operands */
6789167446
int flags; /* Combined MEM_* flags from both inputs */
6789267447
i64 iA; /* Integer value of left operand */
6789367448
i64 iB; /* Integer value of right operand */
6789467449
double rA; /* Real value of left operand */
6789567450
double rB; /* Real value of right operand */
67896
-#endif /* local variables moved into u.ai */
6789767451
6789867452
pIn1 = &aMem[pOp->p1];
6789967453
applyNumericAffinity(pIn1);
6790067454
pIn2 = &aMem[pOp->p2];
6790167455
applyNumericAffinity(pIn2);
6790267456
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;
6790567459
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;
6790967463
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;
6791367467
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;
6791767471
break;
6791867472
}
6791967473
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;
6792367477
break;
6792467478
}
6792567479
}
67926
- pOut->u.i = u.ai.iB;
67480
+ pOut->u.i = iB;
6792767481
MemSetTypeFlag(pOut, MEM_Int);
6792867482
}else{
67929
- u.ai.bIntint = 0;
67483
+ bIntint = 0;
6793067484
fp_math:
67931
- u.ai.rA = sqlite3VdbeRealValue(pIn1);
67932
- u.ai.rB = sqlite3VdbeRealValue(pIn2);
67485
+ rA = sqlite3VdbeRealValue(pIn1);
67486
+ rB = sqlite3VdbeRealValue(pIn2);
6793367487
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;
6793767491
case OP_Divide: {
6793867492
/* (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;
6794167495
break;
6794267496
}
6794367497
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);
6794967503
break;
6795067504
}
6795167505
}
6795267506
#ifdef SQLITE_OMIT_FLOATING_POINT
67953
- pOut->u.i = u.ai.rB;
67507
+ pOut->u.i = rB;
6795467508
MemSetTypeFlag(pOut, MEM_Int);
6795567509
#else
67956
- if( sqlite3IsNaN(u.ai.rB) ){
67510
+ if( sqlite3IsNaN(rB) ){
6795767511
goto arithmetic_result_is_null;
6795867512
}
67959
- pOut->r = u.ai.rB;
67513
+ pOut->r = rB;
6796067514
MemSetTypeFlag(pOut, MEM_Real);
67961
- if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){
67515
+ if( (flags & MEM_Real)==0 && !bIntint ){
6796267516
sqlite3VdbeIntegerAffinity(pOut);
6796367517
}
6796467518
#endif
6796567519
}
6796667520
break;
@@ -68009,85 +67563,83 @@
6800967563
** invocation of this opcode.
6801067564
**
6801167565
** See also: AggStep and AggFinal
6801267566
*/
6801367567
case OP_Function: {
68014
-#if 0 /* local variables moved into u.aj */
6801567568
int i;
6801667569
Mem *pArg;
6801767570
sqlite3_context ctx;
6801867571
sqlite3_value **apVal;
6801967572
int n;
68020
-#endif /* local variables moved into u.aj */
6802167573
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 );
6802567577
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
6802667578
pOut = &aMem[pOp->p3];
6802767579
memAboutToChange(p, pOut);
6802867580
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);
6803867590
}
6803967591
6804067592
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;
6804467596
6804567597
/* 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
6804767599
** the already allocated buffer instead of allocating a new one.
6804867600
*/
68049
- memcpy(&u.aj.ctx.s, pOut, sizeof(Mem));
67601
+ memcpy(&ctx.s, pOut, sizeof(Mem));
6805067602
pOut->flags = MEM_Null;
6805167603
pOut->xDel = 0;
6805267604
pOut->zMalloc = 0;
68053
- MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
67605
+ MemSetTypeFlag(&ctx.s, MEM_Null);
6805467606
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 ){
6805767609
assert( pOp>aOp );
6805867610
assert( pOp[-1].p4type==P4_COLLSEQ );
6805967611
assert( pOp[-1].opcode==OP_CollSeq );
68060
- u.aj.ctx.pColl = pOp[-1].p4.pColl;
67612
+ ctx.pColl = pOp[-1].p4.pColl;
6806167613
}
6806267614
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 */
6806467616
lastRowid = db->lastRowid;
6806567617
6806667618
if( db->mallocFailed ){
6806767619
/* Even though a malloc() has failed, the implementation of the
6806867620
** user function may have called an sqlite3_result_XXX() function
6806967621
** to return a value. The following call releases any resources
6807067622
** associated with such a value.
6807167623
*/
68072
- sqlite3VdbeMemRelease(&u.aj.ctx.s);
67624
+ sqlite3VdbeMemRelease(&ctx.s);
6807367625
goto no_mem;
6807467626
}
6807567627
6807667628
/* 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;
6808167633
}
6808267634
sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
6808367635
}
6808467636
6808567637
/* Copy the result of the function into register P3 */
68086
- sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
67638
+ sqlite3VdbeChangeEncoding(&ctx.s, encoding);
6808767639
assert( pOut->flags==MEM_Null );
68088
- memcpy(pOut, &u.aj.ctx.s, sizeof(Mem));
67640
+ memcpy(pOut, &ctx.s, sizeof(Mem));
6808967641
if( sqlite3VdbeMemTooBig(pOut) ){
6809067642
goto too_big;
6809167643
}
6809267644
6809367645
#if 0
@@ -68135,56 +67687,54 @@
6813567687
*/
6813667688
case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
6813767689
case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
6813867690
case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
6813967691
case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
68140
-#if 0 /* local variables moved into u.ak */
6814167692
i64 iA;
6814267693
u64 uA;
6814367694
i64 iB;
6814467695
u8 op;
68145
-#endif /* local variables moved into u.ak */
6814667696
6814767697
pIn1 = &aMem[pOp->p1];
6814867698
pIn2 = &aMem[pOp->p2];
6814967699
pOut = &aMem[pOp->p3];
6815067700
if( (pIn1->flags | pIn2->flags) & MEM_Null ){
6815167701
sqlite3VdbeMemSetNull(pOut);
6815267702
break;
6815367703
}
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 );
6816367713
6816467714
/* If shifting by a negative amount, shift in the other direction */
68165
- if( u.ak.iB<0 ){
67715
+ if( iB<0 ){
6816667716
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;
6816967719
}
6817067720
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;
6817967729
/* 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);
6818167731
}
68182
- memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA));
67732
+ memcpy(&iA, &uA, sizeof(iA));
6818367733
}
6818467734
}
68185
- pOut->u.i = u.ak.iA;
67735
+ pOut->u.i = iA;
6818667736
MemSetTypeFlag(pOut, MEM_Int);
6818767737
break;
6818867738
}
6818967739
6819067740
/* Opcode: AddImm P1 P2 * * *
@@ -68434,37 +67984,35 @@
6843467984
case OP_Ne: /* same as TK_NE, jump, in1, in3 */
6843567985
case OP_Lt: /* same as TK_LT, jump, in1, in3 */
6843667986
case OP_Le: /* same as TK_LE, jump, in1, in3 */
6843767987
case OP_Gt: /* same as TK_GT, jump, in1, in3 */
6843867988
case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
68439
-#if 0 /* local variables moved into u.al */
6844067989
int res; /* Result of the comparison of pIn1 against pIn3 */
6844167990
char affinity; /* Affinity to use for comparison */
6844267991
u16 flags1; /* Copy of initial value of pIn1->flags */
6844367992
u16 flags3; /* Copy of initial value of pIn3->flags */
68444
-#endif /* local variables moved into u.al */
6844567993
6844667994
pIn1 = &aMem[pOp->p1];
6844767995
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 ){
6845167999
/* One or both operands are NULL */
6845268000
if( pOp->p5 & SQLITE_NULLEQ ){
6845368001
/* If SQLITE_NULLEQ is set (which will only happen if the operator is
6845468002
** OP_Eq or OP_Ne) then take the jump or not depending on whether
6845568003
** or not both operands are null.
6845668004
*/
6845768005
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
6846268010
){
68463
- u.al.res = 0; /* Results are equal */
68011
+ res = 0; /* Results are equal */
6846468012
}else{
68465
- u.al.res = 1; /* Results are not equal */
68013
+ res = 1; /* Results are not equal */
6846668014
}
6846768015
}else{
6846868016
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
6846968017
** then the result is always NULL.
6847068018
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68478,44 +68026,44 @@
6847868026
}
6847968027
break;
6848068028
}
6848168029
}else{
6848268030
/* 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);
6848768035
if( db->mallocFailed ) goto no_mem;
6848868036
}
6848968037
6849068038
assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
6849168039
ExpandBlob(pIn1);
6849268040
ExpandBlob(pIn3);
68493
- u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68041
+ res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
6849468042
}
6849568043
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;
6850268050
}
6850368051
6850468052
if( pOp->p5 & SQLITE_STOREP2 ){
6850568053
pOut = &aMem[pOp->p2];
6850668054
memAboutToChange(p, pOut);
6850768055
MemSetTypeFlag(pOut, MEM_Int);
68508
- pOut->u.i = u.al.res;
68056
+ pOut->u.i = res;
6850968057
REGISTER_TRACE(pOp->p2, pOut);
68510
- }else if( u.al.res ){
68058
+ }else if( res ){
6851168059
pc = pOp->p2-1;
6851268060
}
6851368061
6851468062
/* 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);
6851768065
break;
6851868066
}
6851968067
6852068068
/* Opcode: Permutation * * * P4 *
6852168069
**
@@ -68551,51 +68099,49 @@
6855168099
** The comparison is a sort comparison, so NULLs compare equal,
6855268100
** NULLs are less than numbers, numbers are less than strings,
6855368101
** and strings are less than blobs.
6855468102
*/
6855568103
case OP_Compare: {
68556
-#if 0 /* local variables moved into u.am */
6855768104
int n;
6855868105
int i;
6855968106
int p1;
6856068107
int p2;
6856168108
const KeyInfo *pKeyInfo;
6856268109
int idx;
6856368110
CollSeq *pColl; /* Collating sequence to use on this term */
6856468111
int bRev; /* True for DESCENDING sort order */
68565
-#endif /* local variables moved into u.am */
6856668112
6856768113
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;
6857468120
#if SQLITE_DEBUG
6857568121
if( aPermute ){
6857668122
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 );
6858068126
}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 );
6858368129
}
6858468130
#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);
6859568141
if( iCompare ){
68596
- if( u.am.bRev ) iCompare = -iCompare;
68142
+ if( bRev ) iCompare = -iCompare;
6859768143
break;
6859868144
}
6859968145
}
6860068146
aPermute = 0;
6860168147
break;
@@ -68638,39 +68184,37 @@
6863868184
** even if the other input is NULL. A NULL and false or two NULLs
6863968185
** give a NULL output.
6864068186
*/
6864168187
case OP_And: /* same as TK_AND, in1, in2, out3 */
6864268188
case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68643
-#if 0 /* local variables moved into u.an */
6864468189
int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
6864568190
int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68646
-#endif /* local variables moved into u.an */
6864768191
6864868192
pIn1 = &aMem[pOp->p1];
6864968193
if( pIn1->flags & MEM_Null ){
68650
- u.an.v1 = 2;
68194
+ v1 = 2;
6865168195
}else{
68652
- u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0;
68196
+ v1 = sqlite3VdbeIntValue(pIn1)!=0;
6865368197
}
6865468198
pIn2 = &aMem[pOp->p2];
6865568199
if( pIn2->flags & MEM_Null ){
68656
- u.an.v2 = 2;
68200
+ v2 = 2;
6865768201
}else{
68658
- u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0;
68202
+ v2 = sqlite3VdbeIntValue(pIn2)!=0;
6865968203
}
6866068204
if( pOp->opcode==OP_And ){
6866168205
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];
6866368207
}else{
6866468208
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];
6866668210
}
6866768211
pOut = &aMem[pOp->p3];
68668
- if( u.an.v1==2 ){
68212
+ if( v1==2 ){
6866968213
MemSetTypeFlag(pOut, MEM_Null);
6867068214
}else{
68671
- pOut->u.i = u.an.v1;
68215
+ pOut->u.i = v1;
6867268216
MemSetTypeFlag(pOut, MEM_Int);
6867368217
}
6867468218
break;
6867568219
}
6867668220
@@ -68737,25 +68281,23 @@
6873768281
** is considered false if it has a numeric value of zero. If the value
6873868282
** in P1 is NULL then take the jump if P3 is zero.
6873968283
*/
6874068284
case OP_If: /* jump, in1 */
6874168285
case OP_IfNot: { /* jump, in1 */
68742
-#if 0 /* local variables moved into u.ao */
6874368286
int c;
68744
-#endif /* local variables moved into u.ao */
6874568287
pIn1 = &aMem[pOp->p1];
6874668288
if( pIn1->flags & MEM_Null ){
68747
- u.ao.c = pOp->p3;
68289
+ c = pOp->p3;
6874868290
}else{
6874968291
#ifdef SQLITE_OMIT_FLOATING_POINT
68750
- u.ao.c = sqlite3VdbeIntValue(pIn1)!=0;
68292
+ c = sqlite3VdbeIntValue(pIn1)!=0;
6875168293
#else
68752
- u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0;
68294
+ c = sqlite3VdbeRealValue(pIn1)!=0.0;
6875368295
#endif
68754
- if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c;
68296
+ if( pOp->opcode==OP_IfNot ) c = !c;
6875568297
}
68756
- if( u.ao.c ){
68298
+ if( c ){
6875768299
pc = pOp->p2-1;
6875868300
}
6875968301
break;
6876068302
}
6876168303
@@ -68809,11 +68351,10 @@
6880968351
** the result is guaranteed to only be used as the argument of a length()
6881068352
** or typeof() function, respectively. The loading of large blobs can be
6881168353
** skipped for length() and all content loading can be skipped for typeof().
6881268354
*/
6881368355
case OP_Column: {
68814
-#if 0 /* local variables moved into u.ap */
6881568356
i64 payloadSize64; /* Number of bytes in the record */
6881668357
int p2; /* column number to retrieve */
6881768358
VdbeCursor *pC; /* The VDBE cursor */
6881868359
BtCursor *pCrsr; /* The BTree cursor */
6881968360
u32 *aType; /* aType[i] holds the numeric type of the i-th column */
@@ -68828,89 +68369,88 @@
6882868369
u32 offset; /* Offset into the data */
6882968370
u32 szField; /* Number of bytes in the content of a field */
6883068371
u32 avail; /* Number of bytes of available data */
6883168372
u32 t; /* A type code from the record header */
6883268373
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;
6891268452
}
6891368453
6891468454
/* Make sure a corrupt database has not given us an oversize header.
6891568455
** Do this now to avoid an oversize memory allocation.
6891668456
**
@@ -68918,154 +68458,154 @@
6891868458
** types use so much data space that there can only be 4096 and 32 of
6891968459
** them, respectively. So the maximum header length results from a
6892068460
** 3-byte type for each of the maximum of 32768 columns plus three
6892168461
** extra bytes for the header length itself. 32768*3 + 3 = 98307.
6892268462
*/
68923
- if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){
68463
+ if( offset > 98307 || offset > pC->payloadSize ){
6892468464
rc = SQLITE_CORRUPT_BKPT;
6892568465
goto op_column_error;
6892668466
}
6892768467
}
6892868468
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[].
6893168471
*/
68932
- if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
68472
+ if( pC->nHdrParsed<=p2 ){
6893368473
/* 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
6893568475
*/
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);
6894268482
if( rc!=SQLITE_OK ){
6894368483
goto op_column_error;
6894468484
}
68945
- u.ap.zData = (u8*)u.ap.sMem.z;
68485
+ zData = (u8*)sMem.z;
6894668486
}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 );
6895668496
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++;
6896068500
}else{
68961
- u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t);
68501
+ zHdr += sqlite3GetVarint32(zHdr, &t);
6896268502
}
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 */
6896868508
break;
6896968509
}
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
+
6898068520
/* If we have read more header data than was contained in the header,
6898168521
** or if the end of the last field appears to be past the end of the
6898268522
** 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
6898468524
** with a corrupt database.
6898568525
*/
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)
6898968529
){
6899068530
rc = SQLITE_CORRUPT_BKPT;
6899168531
goto op_column_error;
6899268532
}
6899368533
}
6899468534
6899568535
/* 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
6899768537
** columns. So the result will be either the default value or a NULL.
6899868538
*/
68999
- if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
68539
+ if( pC->nHdrParsed<=p2 ){
6900068540
if( pOp->p4type==P4_MEM ){
69001
- sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
68541
+ sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
6900268542
}else{
69003
- MemSetTypeFlag(u.ap.pDest, MEM_Null);
68543
+ MemSetTypeFlag(pDest, MEM_Null);
6900468544
}
6900568545
goto op_column_out;
6900668546
}
6900768547
}
6900868548
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
6901168551
** all valid.
6901268552
*/
69013
- assert( u.ap.p2<u.ap.pC->nHdrParsed );
68553
+ assert( p2<pC->nHdrParsed );
6901468554
assert( rc==SQLITE_OK );
69015
- if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){
68555
+ if( pC->szRow>=aOffset[p2+1] ){
6901668556
/* This is the common case where the desired content fits on the original
6901768557
** 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);
6902068560
}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];
6902368563
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
6902668566
){
6902768567
/* Content is irrelevant for the typeof() function and for
6902868568
** the length(X) function if X is a blob. So we might as well use
6902968569
** 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
6903168571
** will work for everything else. Content is also irrelevant if
6903268572
** 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;
6903568575
}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);
6904068580
if( rc!=SQLITE_OK ){
6904168581
goto op_column_error;
6904268582
}
69043
- u.ap.zData = (u8*)u.ap.sMem.z;
68583
+ zData = (u8*)sMem.z;
6904468584
}
69045
- sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest);
68585
+ sqlite3VdbeSerialGet(zData, t, pDest);
6904668586
/* If we dynamically allocated space to hold the data (in the
6904768587
** 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.
6904968589
** 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;
6905868598
}
6905968599
}
69060
- u.ap.pDest->enc = encoding;
68600
+ pDest->enc = encoding;
6906168601
6906268602
op_column_out:
69063
- rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
68603
+ Deephemeralize(pDest);
6906468604
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);
6906768607
break;
6906868608
}
6906968609
6907068610
/* Opcode: Affinity P1 P2 * P4 *
6907168611
** Synopsis: affinity(r[P1@P2])
@@ -69075,24 +68615,22 @@
6907568615
** P4 is a string that is P2 characters long. The nth character of the
6907668616
** string indicates the column affinity that should be used for the nth
6907768617
** memory cell in the range.
6907868618
*/
6907968619
case OP_Affinity: {
69080
-#if 0 /* local variables moved into u.aq */
6908168620
const char *zAffinity; /* The affinity to be applied */
6908268621
char cAff; /* A single character of affinity */
69083
-#endif /* local variables moved into u.aq */
6908468622
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 );
6908868626
pIn1 = &aMem[pOp->p1];
69089
- while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){
68627
+ while( (cAff = *(zAffinity++))!=0 ){
6909068628
assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
6909168629
assert( memIsValid(pIn1) );
6909268630
ExpandBlob(pIn1);
69093
- applyAffinity(pIn1, u.aq.cAff, encoding);
68631
+ applyAffinity(pIn1, cAff, encoding);
6909468632
pIn1++;
6909568633
}
6909668634
break;
6909768635
}
6909868636
@@ -69111,11 +68649,10 @@
6911168649
** macros defined in sqliteInt.h.
6911268650
**
6911368651
** If P4 is NULL then all index fields have the affinity NONE.
6911468652
*/
6911568653
case OP_MakeRecord: {
69116
-#if 0 /* local variables moved into u.ar */
6911768654
u8 *zNewRecord; /* A buffer to hold the data for the new record */
6911868655
Mem *pRec; /* The new record */
6911968656
u64 nData; /* Number of bytes of data space */
6912068657
int nHdr; /* Number of bytes of header space */
6912168658
i64 nByte; /* Data space required for this record */
@@ -69125,106 +68662,123 @@
6912568662
Mem *pData0; /* First field to be combined into the record */
6912668663
Mem *pLast; /* Last field of the record */
6912768664
int nField; /* Number of fields in the record */
6912868665
char *zAffinity; /* The affinity string for the record */
6912968666
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 */
6913168669
int len; /* Length of a field */
69132
-#endif /* local variables moved into u.ar */
6913368670
6913468671
/* Assuming the record contains N fields, the record format looks
6913568672
** like this:
6913668673
**
6913768674
** ------------------------------------------------------------------------
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 |
6913968676
** ------------------------------------------------------------------------
6914068677
**
6914168678
** Data(0) is taken from register P1. Data(1) comes from register P1+1
6914268679
** and so froth.
6914368680
**
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
6914568682
** corresponding data element (see sqlite3VdbeSerialType()). The
6914668683
** hdr-size field is also a varint which is the offset from the beginning
6914768684
** of the record to data0.
6914868685
*/
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;
6915968696
6916068697
/* Identify the output register */
6916168698
assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
6916268699
pOut = &aMem[pOp->p3];
6916368700
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
+ }
6916468711
6916568712
/* Loop through the elements that will make up the record to figure
6916668713
** out how much space is required for the new record.
6916768714
*/
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 );
6918868733
6918968734
/* 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++;
6919368745
}
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] ){
6919668748
goto too_big;
6919768749
}
6919868750
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
6920068752
** the new record. The output register (pOp->p3) is not allowed to
6920168753
** be one of the input registers (because the following call to
6920268754
** sqlite3VdbeMemGrow() could clobber the value before it is used).
6920368755
*/
69204
- if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){
68756
+ if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){
6920568757
goto no_mem;
6920668758
}
69207
- u.ar.zNewRecord = (u8 *)pOut->z;
68759
+ zNewRecord = (u8 *)pOut->z;
6920868760
6920968761
/* 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 );
6921968773
6922068774
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69221
- pOut->n = (int)u.ar.nByte;
68775
+ pOut->n = (int)nByte;
6922268776
pOut->flags = MEM_Blob | MEM_Dyn;
6922368777
pOut->xDel = 0;
69224
- if( u.ar.nZero ){
69225
- pOut->u.nZero = u.ar.nZero;
68778
+ if( nZero ){
68779
+ pOut->u.nZero = nZero;
6922668780
pOut->flags |= MEM_Zero;
6922768781
}
6922868782
pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
6922968783
REGISTER_TRACE(pOp->p3, pOut);
6923068784
UPDATE_MAX_BLOBSIZE(pOut);
@@ -69237,19 +68791,18 @@
6923768791
** Store the number of entries (an integer value) in the table or index
6923868792
** opened by cursor P1 in register P2
6923968793
*/
6924068794
#ifndef SQLITE_OMIT_BTREECOUNT
6924168795
case OP_Count: { /* out2-prerelease */
69242
-#if 0 /* local variables moved into u.as */
6924368796
i64 nEntry;
6924468797
BtCursor *pCrsr;
69245
-#endif /* local variables moved into u.as */
6924668798
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;
6925168804
break;
6925268805
}
6925368806
#endif
6925468807
6925568808
/* Opcode: Savepoint P1 * * P4 *
@@ -69257,43 +68810,41 @@
6925768810
** Open, release or rollback the savepoint named by parameter P4, depending
6925868811
** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
6925968812
** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
6926068813
*/
6926168814
case OP_Savepoint: {
69262
-#if 0 /* local variables moved into u.at */
6926368815
int p1; /* Value of P1 operand */
6926468816
char *zName; /* Name of savepoint */
6926568817
int nName;
6926668818
Savepoint *pNew;
6926768819
Savepoint *pSavepoint;
6926868820
Savepoint *pTmp;
6926968821
int iSavepoint;
6927068822
int ii;
69271
-#endif /* local variables moved into u.at */
6927268823
69273
- u.at.p1 = pOp->p1;
69274
- u.at.zName = pOp->p4.z;
68824
+ p1 = pOp->p1;
68825
+ zName = pOp->p4.z;
6927568826
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.
6927868829
*/
6927968830
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 );
6928168832
assert( db->pSavepoint || db->isTransactionSavepoint==0 );
6928268833
assert( checkSavepointCount(db) );
6928368834
assert( p->bIsReader );
6928468835
69285
- if( u.at.p1==SAVEPOINT_BEGIN ){
68836
+ if( p1==SAVEPOINT_BEGIN ){
6928668837
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
6928868839
** statements (i.e. open read/write incremental blob handles).
6928968840
*/
6929068841
sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
6929168842
"SQL statements in progress");
6929268843
rc = SQLITE_BUSY;
6929368844
}else{
69294
- u.at.nName = sqlite3Strlen30(u.at.zName);
68845
+ nName = sqlite3Strlen30(zName);
6929568846
6929668847
#ifndef SQLITE_OMIT_VIRTUALTABLE
6929768848
/* This call is Ok even if this savepoint is actually a transaction
6929868849
** savepoint (and therefore should not prompt xSavepoint()) callbacks.
6929968850
** If this is a transaction savepoint being opened, it is guaranteed
@@ -69303,62 +68854,62 @@
6930368854
db->nStatement+db->nSavepoint);
6930468855
if( rc!=SQLITE_OK ) goto abort_due_to_error;
6930568856
#endif
6930668857
6930768858
/* 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
+
6931368864
/* If there is no open transaction, then mark this as a special
6931468865
** "transaction savepoint". */
6931568866
if( db->autoCommit ){
6931668867
db->autoCommit = 0;
6931768868
db->isTransactionSavepoint = 1;
6931868869
}else{
6931968870
db->nSavepoint++;
6932068871
}
69321
-
68872
+
6932268873
/* 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;
6932768878
}
6932868879
}
6932968880
}else{
69330
- u.at.iSavepoint = 0;
68881
+ iSavepoint = 0;
6933168882
6933268883
/* Find the named savepoint. If there is no such savepoint, then an
6933368884
** an error is returned to the user. */
6933468885
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
6933868889
){
69339
- u.at.iSavepoint++;
68890
+ iSavepoint++;
6934068891
}
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);
6934368894
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
6934668897
** active write statements.
6934768898
*/
69348
- sqlite3SetString(&p->zErrMsg, db,
68899
+ sqlite3SetString(&p->zErrMsg, db,
6934968900
"cannot release savepoint - SQL statements in progress"
6935068901
);
6935168902
rc = SQLITE_BUSY;
6935268903
}else{
6935368904
6935468905
/* 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.
6935768908
*/
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 ){
6936068911
if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
6936168912
goto vdbe_return;
6936268913
}
6936368914
db->autoCommit = 1;
6936468915
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69368,56 +68919,56 @@
6936868919
goto vdbe_return;
6936968920
}
6937068921
db->isTransactionSavepoint = 0;
6937168922
rc = p->rc;
6937268923
}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);
6937768928
}
6937868929
}
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);
6938168932
if( rc!=SQLITE_OK ){
6938268933
goto abort_due_to_error;
6938368934
}
6938468935
}
69385
- if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
68936
+ if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
6938668937
sqlite3ExpirePreparedStatements(db);
6938768938
sqlite3ResetAllSchemasOfConnection(db);
6938868939
db->flags = (db->flags | SQLITE_InternChanges);
6938968940
}
6939068941
}
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
6939368944
** 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);
6939868949
db->nSavepoint--;
6939968950
}
6940068951
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
6940368954
** constraint violations present in the database to the value stored
6940468955
** 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);
6940968960
if( !isTransaction ){
6941068961
db->nSavepoint--;
6941168962
}
6941268963
}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;
6941568966
}
6941668967
6941768968
if( !isTransaction ){
69418
- rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint);
68969
+ rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
6941968970
if( rc!=SQLITE_OK ) goto abort_due_to_error;
6942068971
}
6942168972
}
6942268973
}
6942368974
@@ -69432,54 +68983,52 @@
6943268983
** there are active writing VMs or active VMs that use shared cache.
6943368984
**
6943468985
** This instruction causes the VM to halt.
6943568986
*/
6943668987
case OP_AutoCommit: {
69437
-#if 0 /* local variables moved into u.au */
6943868988
int desiredAutoCommit;
6943968989
int iRollback;
6944068990
int turnOnAC;
69441
-#endif /* local variables moved into u.au */
6944268991
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 );
6944868997
assert( db->nVdbeActive>0 ); /* At least this one VM is active */
6944968998
assert( p->bIsReader );
6945068999
6945169000
#if 0
69452
- if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){
69001
+ if( turnOnAC && iRollback && db->nVdbeActive>1 ){
6945369002
/* If this instruction implements a ROLLBACK and other VMs are
6945469003
** 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.
6945669005
*/
6945769006
sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
6945869007
"SQL statements in progress");
6945969008
rc = SQLITE_BUSY;
6946069009
}else
6946169010
#endif
69462
- if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){
69011
+ if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
6946369012
/* 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.
6946569014
*/
6946669015
sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
6946769016
"SQL statements in progress");
6946869017
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 );
6947269021
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6947369022
db->autoCommit = 1;
6947469023
}else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
6947569024
goto vdbe_return;
6947669025
}else{
69477
- db->autoCommit = (u8)u.au.desiredAutoCommit;
69026
+ db->autoCommit = (u8)desiredAutoCommit;
6947869027
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
6947969028
p->pc = pc;
69480
- db->autoCommit = (u8)(1-u.au.desiredAutoCommit);
69029
+ db->autoCommit = (u8)(1-desiredAutoCommit);
6948169030
p->rc = rc = SQLITE_BUSY;
6948269031
goto vdbe_return;
6948369032
}
6948469033
}
6948569034
assert( db->nStatement==0 );
@@ -69490,14 +69039,14 @@
6949069039
rc = SQLITE_ERROR;
6949169040
}
6949269041
goto vdbe_return;
6949369042
}else{
6949469043
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":
6949769046
"cannot commit - no transaction is active"));
69498
-
69047
+
6949969048
rc = SQLITE_ERROR;
6950069049
}
6950169050
break;
6950269051
}
6950369052
@@ -69531,48 +69080,46 @@
6953169080
** will automatically commit when the VDBE halts.
6953269081
**
6953369082
** If P2 is zero, then a read-lock is obtained on the database file.
6953469083
*/
6953569084
case OP_Transaction: {
69536
-#if 0 /* local variables moved into u.av */
6953769085
Btree *pBt;
69538
-#endif /* local variables moved into u.av */
6953969086
6954069087
assert( p->bIsReader );
6954169088
assert( p->readOnly==0 || pOp->p2==0 );
6954269089
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6954369090
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6954469091
if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
6954569092
rc = SQLITE_READONLY;
6954669093
goto abort_due_to_error;
6954769094
}
69548
- u.av.pBt = db->aDb[pOp->p1].pBt;
69095
+ pBt = db->aDb[pOp->p1].pBt;
6954969096
69550
- if( u.av.pBt ){
69551
- rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2);
69097
+ if( pBt ){
69098
+ rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
6955269099
if( rc==SQLITE_BUSY ){
6955369100
p->pc = pc;
6955469101
p->rc = rc = SQLITE_BUSY;
6955569102
goto vdbe_return;
6955669103
}
6955769104
if( rc!=SQLITE_OK ){
6955869105
goto abort_due_to_error;
6955969106
}
6956069107
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)
6956369110
){
69564
- assert( sqlite3BtreeIsInTrans(u.av.pBt) );
69111
+ assert( sqlite3BtreeIsInTrans(pBt) );
6956569112
if( p->iStatement==0 ){
6956669113
assert( db->nStatement>=0 && db->nSavepoint>=0 );
69567
- db->nStatement++;
69114
+ db->nStatement++;
6956869115
p->iStatement = db->nSavepoint + db->nStatement;
6956969116
}
6957069117
6957169118
rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
6957269119
if( rc==SQLITE_OK ){
69573
- rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement);
69120
+ rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
6957469121
}
6957569122
6957669123
/* Store the current value of the database handles deferred constraint
6957769124
** counter. If the statement transaction needs to be rolled back,
6957869125
** the value of this counter needs to be restored too. */
@@ -69594,26 +69141,24 @@
6959469141
** There must be a read-lock on the database (either a transaction
6959569142
** must be started or there must be an open cursor) before
6959669143
** executing this instruction.
6959769144
*/
6959869145
case OP_ReadCookie: { /* out2-prerelease */
69599
-#if 0 /* local variables moved into u.aw */
6960069146
int iMeta;
6960169147
int iDb;
6960269148
int iCookie;
69603
-#endif /* local variables moved into u.aw */
6960469149
6960569150
assert( p->bIsReader );
69606
- u.aw.iDb = pOp->p1;
69607
- u.aw.iCookie = pOp->p3;
69151
+ iDb = pOp->p1;
69152
+ iCookie = pOp->p3;
6960869153
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 );
6961269157
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;
6961569160
break;
6961669161
}
6961769162
6961869163
/* Opcode: SetCookie P1 P2 P3 * *
6961969164
**
@@ -69624,31 +69169,29 @@
6962469169
** database file used to store temporary tables.
6962569170
**
6962669171
** A transaction must be started before executing this opcode.
6962769172
*/
6962869173
case OP_SetCookie: { /* in3 */
69629
-#if 0 /* local variables moved into u.ax */
6963069174
Db *pDb;
69631
-#endif /* local variables moved into u.ax */
6963269175
assert( pOp->p2<SQLITE_N_BTREE_META );
6963369176
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6963469177
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6963569178
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 );
6963869181
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6963969182
pIn3 = &aMem[pOp->p3];
6964069183
sqlite3VdbeMemIntegerify(pIn3);
6964169184
/* 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);
6964369186
if( pOp->p2==BTREE_SCHEMA_VERSION ){
6964469187
/* 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;
6964669189
db->flags |= SQLITE_InternChanges;
6964769190
}else if( pOp->p2==BTREE_FILE_FORMAT ){
6964869191
/* 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;
6965069193
}
6965169194
if( pOp->p1==1 ){
6965269195
/* Invalidate all prepared statements whenever the TEMP database
6965369196
** schema is changed. Ticket #1644 */
6965469197
sqlite3ExpirePreparedStatements(db);
@@ -69674,44 +69217,42 @@
6967469217
** Either a transaction needs to have been started or an OP_Open needs
6967569218
** to be executed (to establish a read lock) before this opcode is
6967669219
** invoked.
6967769220
*/
6967869221
case OP_VerifyCookie: {
69679
-#if 0 /* local variables moved into u.ay */
6968069222
int iMeta;
6968169223
int iGen;
6968269224
Btree *pBt;
69683
-#endif /* local variables moved into u.ay */
6968469225
6968569226
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6968669227
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6968769228
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6968869229
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;
6969369234
}else{
69694
- u.ay.iGen = u.ay.iMeta = 0;
69235
+ iGen = iMeta = 0;
6969569236
}
69696
- if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){
69237
+ if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
6969769238
sqlite3DbFree(db, p->zErrMsg);
6969869239
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
6970069241
** stored with the in-memory representation of the schema, do
6970169242
** not reload the schema from the database file.
6970269243
**
6970369244
** If virtual-tables are in use, this is not just an optimization.
6970469245
** Often, v-tables store their data in other SQLite tables, which
6970569246
** are queried from within xNext() and other v-table methods using
6970669247
** prepared queries. If such a query is out-of-date, we do not want to
6970769248
** discard the database schema, as the user code implementing the
6970869249
** 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
6971069251
** a v-table method.
6971169252
*/
69712
- if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){
69253
+ if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
6971369254
sqlite3ResetOneSchema(db, pOp->p1);
6971469255
}
6971569256
6971669257
p->expired = 1;
6971769258
rc = SQLITE_SCHEMA;
@@ -69770,20 +69311,18 @@
6977069311
**
6977169312
** See also OpenRead.
6977269313
*/
6977369314
case OP_OpenRead:
6977469315
case OP_OpenWrite: {
69775
-#if 0 /* local variables moved into u.az */
6977669316
int nField;
6977769317
KeyInfo *pKeyInfo;
6977869318
int p2;
6977969319
int iDb;
6978069320
int wrFlag;
6978169321
Btree *pX;
6978269322
VdbeCursor *pCur;
6978369323
Db *pDb;
69784
-#endif /* local variables moved into u.az */
6978569324
6978669325
assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
6978769326
assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
6978869327
assert( p->bIsReader );
6978969328
assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69791,74 +69330,74 @@
6979169330
if( p->expired ){
6979269331
rc = SQLITE_ABORT;
6979369332
break;
6979469333
}
6979569334
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 );
6980569344
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;
6981069349
}
6981169350
}else{
69812
- u.az.wrFlag = 0;
69351
+ wrFlag = 0;
6981369352
}
6981469353
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];
6981869357
assert( memIsValid(pIn2) );
6981969358
assert( (pIn2->flags & MEM_Int)!=0 );
6982069359
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.
6982469363
** If there were a failure, the prepared statement would have halted
6982569364
** before reaching this instruction. */
69826
- if( NEVER(u.az.p2<2) ) {
69365
+ if( NEVER(p2<2) ) {
6982769366
rc = SQLITE_CORRUPT_BKPT;
6982869367
goto abort_due_to_error;
6982969368
}
6983069369
}
6983169370
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;
6983669375
}else if( pOp->p4type==P4_INT32 ){
69837
- u.az.nField = pOp->p4.i;
69376
+ nField = pOp->p4.i;
6983869377
}
6983969378
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;
6984869387
assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69849
- sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69388
+ sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
6985069389
6985169390
/* Since it performs no memory allocation or IO, the only value that
6985269391
** sqlite3BtreeCursor() may return is SQLITE_OK. */
6985369392
assert( rc==SQLITE_OK );
6985469393
6985569394
/* Set the VdbeCursor.isTable variable. Previous versions of
6985669395
** SQLite used to check if the root-page flags were sane at this point
6985769396
** 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;
6986069399
break;
6986169400
}
6986269401
6986369402
/* Opcode: OpenEphemeral P1 P2 * P4 P5
6986469403
** Synopsis: nColumn=P2
@@ -69886,55 +69425,53 @@
6988669425
** by this opcode will be used for automatically created transient
6988769426
** indices in joins.
6988869427
*/
6988969428
case OP_OpenAutoindex:
6989069429
case OP_OpenEphemeral: {
69891
-#if 0 /* local variables moved into u.ba */
6989269430
VdbeCursor *pCx;
6989369431
KeyInfo *pKeyInfo;
69894
-#endif /* local variables moved into u.ba */
6989569432
69896
- static const int vfsFlags =
69433
+ static const int vfsFlags =
6989769434
SQLITE_OPEN_READWRITE |
6989869435
SQLITE_OPEN_CREATE |
6989969436
SQLITE_OPEN_EXCLUSIVE |
6990069437
SQLITE_OPEN_DELETEONCLOSE |
6990169438
SQLITE_OPEN_TRANSIENT_DB;
6990269439
assert( pOp->p1>=0 );
6990369440
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,
6990869445
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
6990969446
if( rc==SQLITE_OK ){
69910
- rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
69447
+ rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
6991169448
}
6991269449
if( rc==SQLITE_OK ){
6991369450
/* If a transient index is required, create it by calling
6991469451
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
6991569452
** opening it. If a transient table is required, just use the
6991669453
** automatically created table with root-page 1 (an BLOB_INTKEY table).
6991769454
*/
69918
- if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69455
+ if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
6991969456
int pgno;
6992069457
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);
6992269459
if( rc==SQLITE_OK ){
6992369460
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;
6993369470
}
6993469471
}
69935
- u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69472
+ pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
6993669473
break;
6993769474
}
6993869475
6993969476
/* Opcode: SorterOpen P1 * * P4 *
6994069477
**
@@ -69941,22 +69478,20 @@
6994169478
** This opcode works like OP_OpenEphemeral except that it opens
6994269479
** a transient index that is specifically designed to sort large
6994369480
** tables using an external merge-sort algorithm.
6994469481
*/
6994569482
case OP_SorterOpen: {
69946
-#if 0 /* local variables moved into u.bb */
6994769483
VdbeCursor *pCx;
69948
-#endif /* local variables moved into u.bb */
6994969484
6995069485
assert( pOp->p1>=0 );
6995169486
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);
6995869493
break;
6995969494
}
6996069495
6996169496
/* Opcode: OpenPseudo P1 P2 P3 * P5
6996269497
** Synopsis: content in r[P2@P3]
@@ -69974,22 +69509,20 @@
6997469509
**
6997569510
** P3 is the number of fields in the records that will be stored by
6997669511
** the pseudo-table.
6997769512
*/
6997869513
case OP_OpenPseudo: {
69979
-#if 0 /* local variables moved into u.bc */
6998069514
VdbeCursor *pCx;
69981
-#endif /* local variables moved into u.bc */
6998269515
6998369516
assert( pOp->p1>=0 );
6998469517
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;
6999169524
break;
6999269525
}
6999369526
6999469527
/* Opcode: Close P1 * * * *
6999569528
**
@@ -70061,39 +69594,37 @@
7006169594
*/
7006269595
case OP_SeekLt: /* jump, in3 */
7006369596
case OP_SeekLe: /* jump, in3 */
7006469597
case OP_SeekGe: /* jump, in3 */
7006569598
case OP_SeekGt: { /* jump, in3 */
70066
-#if 0 /* local variables moved into u.bd */
7006769599
int res;
7006869600
int oc;
7006969601
VdbeCursor *pC;
7007069602
UnpackedRecord r;
7007169603
int nField;
7007269604
i64 iKey; /* The rowid we are to seek to */
70073
-#endif /* local variables moved into u.bd */
7007469605
7007569606
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7007669607
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 );
7008069611
assert( OP_SeekLe == OP_SeekLt+1 );
7008169612
assert( OP_SeekGe == OP_SeekLt+2 );
7008269613
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 ){
7008869619
/* The input value in P3 might be of any type: integer, real, string,
7008969620
** blob, or NULL. But it needs to be an integer before we can do
7009069621
** the seek, so covert it. */
7009169622
pIn3 = &aMem[pOp->p3];
7009269623
applyNumericAffinity(pIn3);
70093
- u.bd.iKey = sqlite3VdbeIntValue(pIn3);
70094
- u.bd.pC->rowidIsValid = 0;
69624
+ iKey = sqlite3VdbeIntValue(pIn3);
69625
+ pC->rowidIsValid = 0;
7009569626
7009669627
/* If the P3 value could not be converted into an integer without
7009769628
** loss of information, then special processing is required... */
7009869629
if( (pIn3->flags & MEM_Int)==0 ){
7009969630
if( (pIn3->flags & MEM_Real)==0 ){
@@ -70101,100 +69632,100 @@
7010169632
** then the seek is not possible, so jump to P2 */
7010269633
pc = pOp->p2 - 1;
7010369634
break;
7010469635
}
7010569636
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
7010769638
** term, substitute >= for > and < for <=. e.g. if the search term
7010869639
** is 4.9 and the integer approximation 5:
7010969640
**
7011069641
** (x > 4.9) -> (x >= 5)
7011169642
** (x <= 4.9) -> (x < 5)
7011269643
*/
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 ){
7019669727
pc = pOp->p2 - 1;
7019769728
}
7019869729
break;
7019969730
}
7020069731
@@ -70207,24 +69738,22 @@
7020769738
** This is actually a deferred seek. Nothing actually happens until
7020869739
** the cursor is used to read a record. That way, if no reads
7020969740
** occur, no unnecessary I/O happens.
7021069741
*/
7021169742
case OP_Seek: { /* in2 */
70212
-#if 0 /* local variables moved into u.be */
7021369743
VdbeCursor *pC;
70214
-#endif /* local variables moved into u.be */
7021569744
7021669745
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;
7022269751
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;
7022669755
break;
7022769756
}
7022869757
7022969758
7023069759
/* Opcode: Found P1 P2 P3 P4 *
@@ -70275,85 +69804,83 @@
7027569804
** See also: NotFound, Found, NotExists
7027669805
*/
7027769806
case OP_NoConflict: /* jump, in3 */
7027869807
case OP_NotFound: /* jump, in3 */
7027969808
case OP_Found: { /* jump, in3 */
70280
-#if 0 /* local variables moved into u.bf */
7028169809
int alreadyExists;
7028269810
int ii;
7028369811
VdbeCursor *pC;
7028469812
int res;
7028569813
char *pFree;
7028669814
UnpackedRecord *pIdxKey;
7028769815
UnpackedRecord r;
7028869816
char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
70289
-#endif /* local variables moved into u.bf */
7029069817
7029169818
#ifdef SQLITE_TEST
7029269819
if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
7029369820
#endif
7029469821
70295
- u.bf.alreadyExists = 0;
7029669822
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7029769823
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 );
7030069826
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. */
7030369830
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;
7030769834
#ifdef SQLITE_DEBUG
7030869835
{
7030969836
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]);
7031369840
}
7031469841
}
7031569842
#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;
7031869845
}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;
7032369850
assert( pIn3->flags & MEM_Blob );
7032469851
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;
7032769854
}
7032869855
if( pOp->opcode==OP_NoConflict ){
7032969856
/* For the OP_NoConflict opcode, take the jump if any of the
7033069857
** input fields are NULL, since any key with a NULL will not
7033169858
** 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 ){
7033469861
pc = pOp->p2 - 1;
7033569862
break;
7033669863
}
7033769864
}
7033869865
}
70339
- rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res);
69866
+ rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
7034069867
if( pOp->p4.i==0 ){
70341
- sqlite3DbFree(db, u.bf.pFree);
69868
+ sqlite3DbFree(db, pFree);
7034269869
}
7034369870
if( rc!=SQLITE_OK ){
7034469871
break;
7034569872
}
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;
7035169878
if( pOp->opcode==OP_Found ){
70352
- if( u.bf.alreadyExists ) pc = pOp->p2 - 1;
69879
+ if( alreadyExists ) pc = pOp->p2 - 1;
7035369880
}else{
70354
- if( !u.bf.alreadyExists ) pc = pOp->p2 - 1;
69881
+ if( !alreadyExists ) pc = pOp->p2 - 1;
7035569882
}
7035669883
break;
7035769884
}
7035869885
7035969886
/* Opcode: NotExists P1 P2 P3 * *
@@ -70369,39 +69896,37 @@
7036969896
** (with arbitrary multi-value keys).
7037069897
**
7037169898
** See also: Found, NotFound, NoConflict
7037269899
*/
7037369900
case OP_NotExists: { /* jump, in3 */
70374
-#if 0 /* local variables moved into u.bg */
7037569901
VdbeCursor *pC;
7037669902
BtCursor *pCrsr;
7037769903
int res;
7037869904
u64 iKey;
70379
-#endif /* local variables moved into u.bg */
7038069905
7038169906
pIn3 = &aMem[pOp->p3];
7038269907
assert( pIn3->flags & MEM_Int );
7038369908
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 ){
7039969924
pc = pOp->p2 - 1;
70400
- assert( u.bg.pC->rowidIsValid==0 );
69925
+ assert( pC->rowidIsValid==0 );
7040169926
}
70402
- u.bg.pC->seekResult = u.bg.res;
69927
+ pC->seekResult = res;
7040369928
break;
7040469929
}
7040569930
7040669931
/* Opcode: Sequence P1 P2 * * *
7040769932
** Synopsis: r[P2]=rowid
@@ -70433,25 +69958,23 @@
7043369958
** an SQLITE_FULL error is generated. The P3 register is updated with the '
7043469959
** generated record number. This P3 mechanism is used to help implement the
7043569960
** AUTOINCREMENT feature.
7043669961
*/
7043769962
case OP_NewRowid: { /* out2-prerelease */
70438
-#if 0 /* local variables moved into u.bh */
7043969963
i64 v; /* The new rowid */
7044069964
VdbeCursor *pC; /* Cursor of table to get the new rowid */
7044169965
int res; /* Result of an sqlite3BtreeLast() */
7044269966
int cnt; /* Counter to limit the number of searches */
7044369967
Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
7044469968
VdbeFrame *pFrame; /* Root frame of VDBE */
70445
-#endif /* local variables moved into u.bh */
7044669969
70447
- u.bh.v = 0;
70448
- u.bh.res = 0;
69970
+ v = 0;
69971
+ res = 0;
7044969972
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) ){
7045369976
/* The zero initialization above is all that is needed */
7045469977
}else{
7045569978
/* The next rowid or record number (different terms for the same
7045669979
** thing) is obtained in a two-step algorithm.
7045769980
**
@@ -70463,11 +69986,11 @@
7046369986
** The second algorithm is to select a rowid at random and see if
7046469987
** it already exists in the table. If it does not exist, we have
7046569988
** succeeded. If the random rowid does exist, we select a new one
7046669989
** and try again, up to 100 times.
7046769990
*/
70468
- assert( u.bh.pC->isTable );
69991
+ assert( pC->isTable );
7046969992
7047069993
#ifdef SQLITE_32BIT_ROWID
7047169994
# define MAX_ROWID 0x7fffffff
7047269995
#else
7047369996
/* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70475,101 +69998,101 @@
7047569998
** to provide the constant while making all compilers happy.
7047669999
*/
7047770000
# define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
7047870001
#endif
7047970002
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);
7048470007
if( rc!=SQLITE_OK ){
7048570008
goto abort_due_to_error;
7048670009
}
70487
- if( u.bh.res ){
70488
- u.bh.v = 1; /* IMP: R-61914-48074 */
70010
+ if( res ){
70011
+ v = 1; /* IMP: R-61914-48074 */
7048970012
}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);
7049270015
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;
7049570018
}else{
70496
- u.bh.v++; /* IMP: R-29538-34987 */
70019
+ v++; /* IMP: R-29538-34987 */
7049770020
}
7049870021
}
7049970022
}
7050070023
7050170024
#ifndef SQLITE_OMIT_AUTOINCREMENT
7050270025
if( pOp->p3 ){
7050370026
/* Assert that P3 is a valid memory cell. */
7050470027
assert( pOp->p3>0 );
7050570028
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);
7050770030
/* 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];
7051070033
}else{
7051170034
/* Assert that P3 is a valid memory cell. */
7051270035
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 ){
7052270045
rc = SQLITE_FULL; /* IMP: R-12275-61338 */
7052370046
goto abort_due_to_error;
7052470047
}
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;
7052770050
}
70528
- u.bh.pMem->u.i = u.bh.v;
70051
+ pMem->u.i = v;
7052970052
}
7053070053
#endif
7053170054
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);
7053370056
}
70534
- if( u.bh.pC->useRandomRowid ){
70057
+ if( pC->useRandomRowid ){
7053570058
/* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
7053670059
** largest possible integer (9223372036854775807) then the database
7053770060
** engine starts picking positive candidate ROWIDs at random until
7053870061
** it finds one that is not previously used. */
7053970062
assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
7054070063
** an AUTOINCREMENT table. */
7054170064
/* 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)){
7055070073
/* 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 ){
7055370076
/* try "small" random rowids for the initial attempts */
70554
- u.bh.v &= 0xffffff;
70077
+ v &= 0xffffff;
7055570078
}else{
70556
- u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70079
+ v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
7055770080
}
70558
- u.bh.v++; /* ensure non-zero */
70081
+ v++; /* ensure non-zero */
7055970082
}
70560
- if( rc==SQLITE_OK && u.bh.res==0 ){
70083
+ if( rc==SQLITE_OK && res==0 ){
7056170084
rc = SQLITE_FULL; /* IMP: R-38219-53002 */
7056270085
goto abort_due_to_error;
7056370086
}
70564
- assert( u.bh.v>0 ); /* EV: R-40812-03570 */
70087
+ assert( v>0 ); /* EV: R-40812-03570 */
7056570088
}
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;
7056970092
}
70570
- pOut->u.i = u.bh.v;
70093
+ pOut->u.i = v;
7057170094
break;
7057270095
}
7057370096
7057470097
/* Opcode: Insert P1 P2 P3 P4 P5
7057570098
** Synopsis: intkey=r[P3] data=r[P2]
@@ -70617,74 +70140,72 @@
7061770140
** This works exactly like OP_Insert except that the key is the
7061870141
** integer value P3, not the value of the integer stored in register P3.
7061970142
*/
7062070143
case OP_Insert:
7062170144
case OP_InsertInt: {
70622
-#if 0 /* local variables moved into u.bi */
7062370145
Mem *pData; /* MEM cell holding data for the record to be inserted */
7062470146
Mem *pKey; /* MEM cell holding key for the record */
7062570147
i64 iKey; /* The integer ROWID or key for the record to be inserted */
7062670148
VdbeCursor *pC; /* Cursor to table into which insert is written */
7062770149
int nZero; /* Number of zero-bytes to append */
7062870150
int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
7062970151
const char *zDb; /* database name - used by the update hook */
7063070152
const char *zTbl; /* Table name - used by the opdate hook */
7063170153
int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
70632
-#endif /* local variables moved into u.bi */
7063370154
70634
- u.bi.pData = &aMem[pOp->p2];
70155
+ pData = &aMem[pOp->p2];
7063570156
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);
7064370164
7064470165
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;
7065070171
}else{
7065170172
assert( pOp->opcode==OP_InsertInt );
70652
- u.bi.iKey = pOp->p3;
70173
+ iKey = pOp->p3;
7065370174
}
7065470175
7065570176
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
7067370194
);
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;
7067770198
7067870199
/* Invoke the update-hook if required. */
7067970200
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 );
7068670207
}
7068770208
break;
7068870209
}
7068970210
7069070211
/* Opcode: Delete P1 P2 * P4 *
@@ -70706,41 +70227,39 @@
7070670227
** pointing to. The update hook will be invoked, if it exists.
7070770228
** If P4 is not NULL then the P1 cursor must have been positioned
7070870229
** using OP_NotFound prior to invoking this opcode.
7070970230
*/
7071070231
case OP_Delete: {
70711
-#if 0 /* local variables moved into u.bj */
7071270232
i64 iKey;
7071370233
VdbeCursor *pC;
70714
-#endif /* local variables moved into u.bj */
7071570234
7071670235
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 */
7072170240
7072270241
/* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
7072370242
** 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
7072570244
** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
7072670245
** below is always a no-op and cannot fail. We will run it anyhow, though,
7072770246
** to guard against future changes to the code generator.
7072870247
**/
70729
- assert( u.bj.pC->deferredMoveto==0 );
70730
- rc = sqlite3VdbeCursorMoveto(u.bj.pC);
70248
+ assert( pC->deferredMoveto==0 );
70249
+ rc = sqlite3VdbeCursorMoveto(pC);
7073170250
if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
7073270251
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;
7073670255
7073770256
/* 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 ){
7073970258
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 );
7074270261
}
7074370262
if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
7074470263
break;
7074570264
}
7074670265
/* Opcode: ResetCount * * * * *
@@ -70770,23 +70289,21 @@
7077070289
**
7077170290
** Fall through to next instruction if the two records compare equal to
7077270291
** each other. Jump to P2 if they are different.
7077370292
*/
7077470293
case OP_SorterCompare: {
70775
-#if 0 /* local variables moved into u.bk */
7077670294
VdbeCursor *pC;
7077770295
int res;
7077870296
int nIgnore;
70779
-#endif /* local variables moved into u.bk */
7078070297
70781
- u.bk.pC = p->apCsr[pOp->p1];
70782
- assert( isSorter(u.bk.pC) );
70298
+ pC = p->apCsr[pOp->p1];
70299
+ assert( isSorter(pC) );
7078370300
assert( pOp->p4type==P4_INT32 );
7078470301
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 ){
7078870305
pc = pOp->p2-1;
7078970306
}
7079070307
break;
7079170308
};
7079270309
@@ -70794,18 +70311,16 @@
7079470311
** Synopsis: r[P2]=data
7079570312
**
7079670313
** Write into register P2 the current sorter data for sorter cursor P1.
7079770314
*/
7079870315
case OP_SorterData: {
70799
-#if 0 /* local variables moved into u.bl */
7080070316
VdbeCursor *pC;
70801
-#endif /* local variables moved into u.bl */
7080270317
7080370318
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);
7080770322
break;
7080870323
}
7080970324
7081070325
/* Opcode: RowData P1 P2 * * *
7081170326
** Synopsis: r[P2]=data
@@ -70829,66 +70344,64 @@
7082970344
** If the P1 cursor must be pointing to a valid row (not a NULL row)
7083070345
** of a real table, not a pseudo-table.
7083170346
*/
7083270347
case OP_RowKey:
7083370348
case OP_RowData: {
70834
-#if 0 /* local variables moved into u.bm */
7083570349
VdbeCursor *pC;
7083670350
BtCursor *pCrsr;
7083770351
u32 n;
7083870352
i64 n64;
70839
-#endif /* local variables moved into u.bm */
7084070353
7084170354
pOut = &aMem[pOp->p2];
7084270355
memAboutToChange(p, pOut);
7084370356
7084470357
/* Note that RowKey and RowData are really exactly the same instruction */
7084570358
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) );
7085670369
7085770370
/* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
7085870371
** OP_Rewind/Op_Next with no intervening instructions that might invalidate
7085970372
** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
7086070373
** a no-op and can never fail. But we leave it in place as a safety.
7086170374
*/
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);
7089070403
}
7089170404
pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
7089270405
UPDATE_MAX_BLOBSIZE(pOut);
7089370406
REGISTER_TRACE(pOp->p2, pOut);
7089470407
break;
@@ -70903,46 +70416,44 @@
7090370416
** P1 can be either an ordinary table or a virtual table. There used to
7090470417
** be a separate OP_VRowid opcode for use with virtual tables, but this
7090570418
** one opcode now works for both table types.
7090670419
*/
7090770420
case OP_Rowid: { /* out2-prerelease */
70908
-#if 0 /* local variables moved into u.bn */
7090970421
VdbeCursor *pC;
7091070422
i64 v;
7091170423
sqlite3_vtab *pVtab;
7091270424
const sqlite3_module *pModule;
70913
-#endif /* local variables moved into u.bn */
7091470425
7091570426
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 ){
7092070431
pOut->flags = MEM_Null;
7092170432
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;
7092470435
#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);
7093170442
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7093270443
}else{
70933
- assert( u.bn.pC->pCursor!=0 );
70934
- rc = sqlite3VdbeCursorMoveto(u.bn.pC);
70444
+ assert( pC->pCursor!=0 );
70445
+ rc = sqlite3VdbeCursorMoveto(pC);
7093570446
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;
7093870449
}else{
70939
- rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v);
70450
+ rc = sqlite3BtreeKeySize(pC->pCursor, &v);
7094070451
assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
7094170452
}
7094270453
}
70943
- pOut->u.i = u.bn.v;
70454
+ pOut->u.i = v;
7094470455
break;
7094570456
}
7094670457
7094770458
/* Opcode: NullRow P1 * * * *
7094870459
**
@@ -70949,23 +70460,21 @@
7094970460
** Move the cursor P1 to a null row. Any OP_Column operations
7095070461
** that occur while the cursor is on the null row will always
7095170462
** write a NULL.
7095270463
*/
7095370464
case OP_NullRow: {
70954
-#if 0 /* local variables moved into u.bo */
7095570465
VdbeCursor *pC;
70956
-#endif /* local variables moved into u.bo */
7095770466
7095870467
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);
7096770476
}
7096870477
break;
7096970478
}
7097070479
7097170480
/* Opcode: Last P1 P2 * * *
@@ -70975,28 +70484,26 @@
7097570484
** If the table or index is empty and P2>0, then jump immediately to P2.
7097670485
** If P2 is 0 or if the table or index is not empty, fall through
7097770486
** to the following instruction.
7097870487
*/
7097970488
case OP_Last: { /* jump */
70980
-#if 0 /* local variables moved into u.bp */
7098170489
VdbeCursor *pC;
7098270490
BtCursor *pCrsr;
7098370491
int res;
70984
-#endif /* local variables moved into u.bp */
7098570492
7098670493
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 ){
7099870505
pc = pOp->p2 - 1;
7099970506
}
7100070507
break;
7100170508
}
7100270509
@@ -71029,34 +70536,32 @@
7102970536
** If the table or index is empty and P2>0, then jump immediately to P2.
7103070537
** If P2 is 0 or if the table or index is not empty, fall through
7103170538
** to the following instruction.
7103270539
*/
7103370540
case OP_Rewind: { /* jump */
71034
-#if 0 /* local variables moved into u.bq */
7103570541
VdbeCursor *pC;
7103670542
BtCursor *pCrsr;
7103770543
int res;
71038
-#endif /* local variables moved into u.bq */
7103970544
7104070545
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);
7104770552
}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;
7105670561
assert( pOp->p2>0 && pOp->p2<p->nOp );
71057
- if( u.bq.res ){
70562
+ if( res ){
7105870563
pc = pOp->p2 - 1;
7105970564
}
7106070565
break;
7106170566
}
7106270567
@@ -71103,49 +70608,47 @@
7110370608
**
7110470609
** This opcode works just like OP_Prev except that if cursor P1 is not
7110570610
** open it behaves a no-op.
7110670611
*/
7110770612
case OP_SorterNext: { /* jump */
71108
-#if 0 /* local variables moved into u.br */
7110970613
VdbeCursor *pC;
7111070614
int res;
71111
-#endif /* local variables moved into u.br */
7111270615
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);
7111670619
goto next_tail;
7111770620
case OP_PrevIfOpen: /* jump */
7111870621
case OP_NextIfOpen: /* jump */
7111970622
if( p->apCsr[pOp->p1]==0 ) break;
7112070623
/* Fall through */
7112170624
case OP_Prev: /* jump */
7112270625
case OP_Next: /* jump */
7112370626
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7112470627
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 );
7112970632
assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
7113070633
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
7113170634
assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
7113270635
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);
7113470637
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;
7113870641
pc = pOp->p2 - 1;
7113970642
p->aCounter[pOp->p5]++;
7114070643
#ifdef SQLITE_TEST
7114170644
sqlite3_search_count++;
7114270645
#endif
7114370646
}else{
71144
- u.br.pC->nullRow = 1;
70647
+ pC->nullRow = 1;
7114570648
}
71146
- u.br.pC->rowidIsValid = 0;
70649
+ pC->rowidIsValid = 0;
7114770650
goto check_for_interrupt;
7114870651
}
7114970652
7115070653
/* Opcode: IdxInsert P1 P2 P3 * P5
7115170654
** Synopsis: key=r[P2]
@@ -71160,39 +70663,37 @@
7116070663
** This instruction only works for indices. The equivalent instruction
7116170664
** for tables is OP_Insert.
7116270665
*/
7116370666
case OP_SorterInsert: /* in2 */
7116470667
case OP_IdxInsert: { /* in2 */
71165
-#if 0 /* local variables moved into u.bs */
7116670668
VdbeCursor *pC;
7116770669
BtCursor *pCrsr;
7116870670
int nKey;
7116970671
const char *zKey;
71170
-#endif /* local variables moved into u.bs */
7117170672
7117270673
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) );
7117670677
pIn2 = &aMem[pOp->p2];
7117770678
assert( pIn2->flags & MEM_Blob );
71178
- u.bs.pCrsr = u.bs.pC->pCursor;
70679
+ pCrsr = pC->pCursor;
7117970680
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 );
7118270683
rc = ExpandBlob(pIn2);
7118370684
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);
7118670687
}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)
7119170692
);
71192
- assert( u.bs.pC->deferredMoveto==0 );
71193
- u.bs.pC->cacheStatus = CACHE_STALE;
70693
+ assert( pC->deferredMoveto==0 );
70694
+ pC->cacheStatus = CACHE_STALE;
7119470695
}
7119570696
}
7119670697
break;
7119770698
}
7119870699
@@ -71202,38 +70703,36 @@
7120270703
** The content of P3 registers starting at register P2 form
7120370704
** an unpacked index key. This opcode removes that entry from the
7120470705
** index opened by cursor P1.
7120570706
*/
7120670707
case OP_IdxDelete: {
71207
-#if 0 /* local variables moved into u.bt */
7120870708
VdbeCursor *pC;
7120970709
BtCursor *pCrsr;
7121070710
int res;
7121170711
UnpackedRecord r;
71212
-#endif /* local variables moved into u.bt */
7121370712
7121470713
assert( pOp->p3>0 );
7121570714
assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
7121670715
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 );
7122170720
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];
7122670725
#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]) ); }
7122870727
#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);
7123270731
}
71233
- assert( u.bt.pC->deferredMoveto==0 );
71234
- u.bt.pC->cacheStatus = CACHE_STALE;
70732
+ assert( pC->deferredMoveto==0 );
70733
+ pC->cacheStatus = CACHE_STALE;
7123570734
break;
7123670735
}
7123770736
7123870737
/* Opcode: IdxRowid P1 P2 * * *
7123970738
** Synopsis: r[P2]=rowid
@@ -71243,32 +70742,31 @@
7124370742
** the rowid of the table entry to which this index entry points.
7124470743
**
7124570744
** See also: Rowid, MakeRecord.
7124670745
*/
7124770746
case OP_IdxRowid: { /* out2-prerelease */
71248
-#if 0 /* local variables moved into u.bu */
7124970747
BtCursor *pCrsr;
7125070748
VdbeCursor *pC;
7125170749
i64 rowid;
71252
-#endif /* local variables moved into u.bu */
7125370750
7125470751
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 );
7125970756
pOut->flags = MEM_Null;
71260
- rc = sqlite3VdbeCursorMoveto(u.bu.pC);
70757
+ rc = sqlite3VdbeCursorMoveto(pC);
7126170758
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);
7126670764
if( rc!=SQLITE_OK ){
7126770765
goto abort_due_to_error;
7126870766
}
71269
- pOut->u.i = u.bu.rowid;
70767
+ pOut->u.i = rowid;
7127070768
pOut->flags = MEM_Int;
7127170769
}
7127270770
break;
7127370771
}
7127470772
@@ -71300,43 +70798,42 @@
7130070798
** If P5 is non-zero then the key value is increased by an epsilon prior
7130170799
** to the comparison. This makes the opcode work like IdxLE.
7130270800
*/
7130370801
case OP_IdxLT: /* jump */
7130470802
case OP_IdxGE: { /* jump */
71305
-#if 0 /* local variables moved into u.bv */
7130670803
VdbeCursor *pC;
7130770804
int res;
7130870805
UnpackedRecord r;
71309
-#endif /* local variables moved into u.bv */
7131070806
7131170807
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 );
7131770813
assert( pOp->p5==0 || pOp->p5==1 );
7131870814
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;
7132170817
if( pOp->p5 ){
71322
- u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
70818
+ r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
7132370819
}else{
71324
- u.bv.r.flags = UNPACKED_PREFIX_MATCH;
70820
+ r.flags = UNPACKED_PREFIX_MATCH;
7132570821
}
71326
- u.bv.r.aMem = &aMem[pOp->p3];
70822
+ r.aMem = &aMem[pOp->p3];
7132770823
#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]) ); }
7132970825
#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);
7133170828
if( pOp->opcode==OP_IdxLT ){
71332
- u.bv.res = -u.bv.res;
70829
+ res = -res;
7133370830
}else{
7133470831
assert( pOp->opcode==OP_IdxGE );
71335
- u.bv.res++;
70832
+ res++;
7133670833
}
71337
- if( u.bv.res>0 ){
70834
+ if( res>0 ){
7133870835
pc = pOp->p2 - 1 ;
7133970836
}
7134070837
break;
7134170838
}
7134270839
@@ -71359,47 +70856,46 @@
7135970856
** If AUTOVACUUM is disabled then a zero is stored in register P2.
7136070857
**
7136170858
** See also: Clear
7136270859
*/
7136370860
case OP_Destroy: { /* out2-prerelease */
71364
-#if 0 /* local variables moved into u.bw */
7136570861
int iMoved;
7136670862
int iCnt;
7136770863
Vdbe *pVdbe;
7136870864
int iDb;
71369
-#endif /* local variables moved into u.bw */
7137070865
7137170866
assert( p->readOnly==0 );
7137270867
#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
7137770872
){
71378
- u.bw.iCnt++;
70873
+ iCnt++;
7137970874
}
7138070875
}
7138170876
#else
71382
- u.bw.iCnt = db->nVdbeRead;
70877
+ iCnt = db->nVdbeRead;
7138370878
#endif
7138470879
pOut->flags = MEM_Null;
71385
- if( u.bw.iCnt>1 ){
70880
+ if( iCnt>1 ){
7138670881
rc = SQLITE_LOCKED;
7138770882
p->errorAction = OE_Abort;
7138870883
}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);
7139370889
pOut->flags = MEM_Int;
71394
- pOut->u.i = u.bw.iMoved;
70890
+ pOut->u.i = iMoved;
7139570891
#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);
7139870894
/* 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;
7140170897
}
7140270898
#endif
7140370899
}
7140470900
break;
7140570901
}
@@ -71421,27 +70917,25 @@
7142170917
** also incremented by the number of rows in the table being cleared.
7142270918
**
7142370919
** See also: Destroy
7142470920
*/
7142570921
case OP_Clear: {
71426
-#if 0 /* local variables moved into u.bx */
7142770922
int nChange;
71428
-#endif /* local variables moved into u.bx */
71429
-
71430
- u.bx.nChange = 0;
70923
+
70924
+ nChange = 0;
7143170925
assert( p->readOnly==0 );
7143270926
assert( pOp->p1!=1 );
7143370927
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
7143470928
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)
7143670930
);
7143770931
if( pOp->p3 ){
71438
- p->nChange += u.bx.nChange;
70932
+ p->nChange += nChange;
7143970933
if( pOp->p3>0 ){
7144070934
assert( memIsValid(&aMem[pOp->p3]) );
7144170935
memAboutToChange(p, &aMem[pOp->p3]);
71442
- aMem[pOp->p3].u.i += u.bx.nChange;
70936
+ aMem[pOp->p3].u.i += nChange;
7144370937
}
7144470938
}
7144570939
break;
7144670940
}
7144770941
@@ -71469,30 +70963,28 @@
7146970963
**
7147070964
** See documentation on OP_CreateTable for additional information.
7147170965
*/
7147270966
case OP_CreateIndex: /* out2-prerelease */
7147370967
case OP_CreateTable: { /* out2-prerelease */
71474
-#if 0 /* local variables moved into u.by */
7147570968
int pgno;
7147670969
int flags;
7147770970
Db *pDb;
71478
-#endif /* local variables moved into u.by */
7147970971
71480
- u.by.pgno = 0;
70972
+ pgno = 0;
7148170973
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7148270974
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
7148370975
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 );
7148670978
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;
7148970981
}else{
71490
- u.by.flags = BTREE_BLOBKEY;
70982
+ flags = BTREE_BLOBKEY;
7149170983
}
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;
7149470986
break;
7149570987
}
7149670988
7149770989
/* Opcode: ParseSchema P1 * * P4 *
7149870990
**
@@ -71501,56 +70993,54 @@
7150170993
**
7150270994
** This opcode invokes the parser to create a new virtual machine,
7150370995
** then runs the new virtual machine. It is thus a re-entrant opcode.
7150470996
*/
7150570997
case OP_ParseSchema: {
71506
-#if 0 /* local variables moved into u.bz */
7150770998
int iDb;
7150870999
const char *zMaster;
7150971000
char *zSql;
7151071001
InitData initData;
71511
-#endif /* local variables moved into u.bz */
7151271002
7151371003
/* 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
7151571005
** sqlite3InitCallback().
7151671006
*/
7151771007
#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) );
7152071010
}
7152171011
#endif
7152271012
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) );
7152671016
/* 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,
7153271022
"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 ){
7153571025
rc = SQLITE_NOMEM;
7153671026
}else{
7153771027
assert( db->init.busy==0 );
7153871028
db->init.busy = 1;
71539
- u.bz.initData.rc = SQLITE_OK;
71029
+ initData.rc = SQLITE_OK;
7154071030
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);
7154471034
db->init.busy = 0;
7154571035
}
7154671036
}
7154771037
if( rc ) sqlite3ResetAllSchemasOfConnection(db);
7154871038
if( rc==SQLITE_NOMEM ){
7154971039
goto no_mem;
7155071040
}
71551
- break;
71041
+ break;
7155271042
}
7155371043
7155471044
#if !defined(SQLITE_OMIT_ANALYZE)
7155571045
/* Opcode: LoadAnalysis P1 * * * *
7155671046
**
@@ -71622,46 +71112,44 @@
7162271112
** file, not the main database file.
7162371113
**
7162471114
** This opcode is used to implement the integrity_check pragma.
7162571115
*/
7162671116
case OP_IntegrityCk: {
71627
-#if 0 /* local variables moved into u.ca */
7162871117
int nRoot; /* Number of tables to check. (Number of root pages.) */
7162971118
int *aRoot; /* Array of rootpage numbers for tables to be checked */
7163071119
int j; /* Loop counter */
7163171120
int nErr; /* Number of errors reported */
7163271121
char *z; /* Text of the error report */
7163371122
Mem *pnErr; /* Register keeping track of errors remaining */
71634
-#endif /* local variables moved into u.ca */
7163571123
7163671124
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;
7164171129
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 );
7164571133
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]);
7164871136
}
71649
- u.ca.aRoot[u.ca.j] = 0;
71137
+ aRoot[j] = 0;
7165071138
assert( pOp->p5<db->nDb );
7165171139
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;
7165671144
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 ){
7166071148
goto no_mem;
7166171149
}else{
71662
- sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free);
71150
+ sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
7166371151
}
7166471152
UPDATE_MAX_BLOBSIZE(pIn1);
7166571153
sqlite3VdbeChangeEncoding(pIn1, encoding);
7166671154
break;
7166771155
}
@@ -71693,24 +71181,22 @@
7169371181
** Extract the smallest value from boolean index P1 and put that value into
7169471182
** register P3. Or, if boolean index P1 is initially empty, leave P3
7169571183
** unchanged and jump to instruction P2.
7169671184
*/
7169771185
case OP_RowSetRead: { /* jump, in1, out3 */
71698
-#if 0 /* local variables moved into u.cb */
7169971186
i64 val;
71700
-#endif /* local variables moved into u.cb */
7170171187
7170271188
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
7170571191
){
7170671192
/* The boolean index is empty */
7170771193
sqlite3VdbeMemSetNull(pIn1);
7170871194
pc = pOp->p2 - 1;
7170971195
}else{
7171071196
/* A value was pulled from the index */
71711
- sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
71197
+ sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
7171271198
}
7171371199
goto check_for_interrupt;
7171471200
}
7171571201
7171671202
/* Opcode: RowSetTest P1 P2 P3 P4
@@ -71736,18 +71222,16 @@
7173671222
** inserted, there is no need to search to see if the same value was
7173771223
** previously inserted as part of set X (only if it was previously
7173871224
** inserted as part of some other set).
7173971225
*/
7174071226
case OP_RowSetTest: { /* jump, in1, in3 */
71741
-#if 0 /* local variables moved into u.cc */
7174271227
int iSet;
7174371228
int exists;
71744
-#endif /* local variables moved into u.cc */
7174571229
7174671230
pIn1 = &aMem[pOp->p1];
7174771231
pIn3 = &aMem[pOp->p3];
71748
- u.cc.iSet = pOp->p4.i;
71232
+ iSet = pOp->p4.i;
7174971233
assert( pIn3->flags&MEM_Int );
7175071234
7175171235
/* If there is anything other than a rowset object in memory cell P1,
7175271236
** delete it now and initialize P1 with an empty rowset
7175371237
*/
@@ -71755,21 +71239,21 @@
7175571239
sqlite3VdbeMemSetRowSet(pIn1);
7175671240
if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
7175771241
}
7175871242
7175971243
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),
7176471248
pIn3->u.i);
71765
- if( u.cc.exists ){
71249
+ if( exists ){
7176671250
pc = pOp->p2 - 1;
7176771251
break;
7176871252
}
7176971253
}
71770
- if( u.cc.iSet>=0 ){
71254
+ if( iSet>=0 ){
7177171255
sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
7177271256
}
7177371257
break;
7177471258
}
7177571259
@@ -71788,111 +71272,109 @@
7178871272
** memory required by the sub-vdbe at runtime.
7178971273
**
7179071274
** P4 is a pointer to the VM containing the trigger program.
7179171275
*/
7179271276
case OP_Program: { /* jump */
71793
-#if 0 /* local variables moved into u.cd */
7179471277
int nMem; /* Number of memory registers for sub-program */
7179571278
int nByte; /* Bytes of runtime space required for sub-program */
7179671279
Mem *pRt; /* Register to allocate runtime space */
7179771280
Mem *pMem; /* Used to iterate through memory cells */
7179871281
Mem *pEnd; /* Last memory cell in new array */
7179971282
VdbeFrame *pFrame; /* New vdbe frame to execute in */
7180071283
SubProgram *pProgram; /* Sub-program to execute */
7180171284
void *t; /* Token identifying trigger */
71802
-#endif /* local variables moved into u.cd */
7180371285
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
7180971291
** disabled for backwards compatibility (p5 is set if this sub-program
7181071292
** is really a trigger, not a foreign key action, and the flag set
7181171293
** 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
7181671298
** 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
7181871300
** variable. */
7181971301
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;
7182371305
}
7182471306
7182571307
if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
7182671308
rc = SQLITE_ERROR;
7182771309
sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
7182871310
break;
7182971311
}
7183071312
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
7183271314
** 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
7183471316
** 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
7183771319
** program stored in SubProgram.aOp. As well as these, one memory
7183871320
** 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.
7184071322
*/
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 ){
7184871330
goto no_mem;
7184971331
}
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;
7187271354
}
7187371355
}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 );
7187871360
}
7187971361
7188071362
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;
7188471366
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;
7188971371
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;
7189271374
p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71893
- p->nOnceFlag = u.cd.pProgram->nOnce;
71375
+ p->nOnceFlag = pProgram->nOnce;
7189471376
pc = -1;
7189571377
memset(p->aOnceFlag, 0, p->nOnceFlag);
7189671378
7189771379
break;
7189871380
}
@@ -71908,17 +71390,15 @@
7190871390
** The address of the cell in the parent frame is determined by adding
7190971391
** the value of the P1 argument to the value of the P1 argument to the
7191071392
** calling OP_Program instruction.
7191171393
*/
7191271394
case OP_Param: { /* out2-prerelease */
71913
-#if 0 /* local variables moved into u.ce */
7191471395
VdbeFrame *pFrame;
7191571396
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);
7192071400
break;
7192171401
}
7192271402
7192371403
#endif /* #ifndef SQLITE_OMIT_TRIGGER */
7192471404
@@ -71975,26 +71455,23 @@
7197571455
**
7197671456
** This instruction throws an error if the memory cell is not initially
7197771457
** an integer.
7197871458
*/
7197971459
case OP_MemMax: { /* in2 */
71980
-#if 0 /* local variables moved into u.cf */
71981
- Mem *pIn1;
7198271460
VdbeFrame *pFrame;
71983
-#endif /* local variables moved into u.cf */
7198471461
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];
7198771464
}else{
71988
- u.cf.pIn1 = &aMem[pOp->p1];
71465
+ pIn1 = &aMem[pOp->p1];
7198971466
}
71990
- assert( memIsValid(u.cf.pIn1) );
71991
- sqlite3VdbeMemIntegerify(u.cf.pIn1);
71467
+ assert( memIsValid(pIn1) );
71468
+ sqlite3VdbeMemIntegerify(pIn1);
7199271469
pIn2 = &aMem[pOp->p2];
7199371470
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;
7199671473
}
7199771474
break;
7199871475
}
7199971476
#endif /* SQLITE_OMIT_AUTOINCREMENT */
7200071477
@@ -72061,60 +71538,58 @@
7206171538
**
7206271539
** The P5 arguments are taken from register P2 and its
7206371540
** successors.
7206471541
*/
7206571542
case OP_AggStep: {
72066
-#if 0 /* local variables moved into u.cg */
7206771543
int n;
7206871544
int i;
7206971545
Mem *pMem;
7207071546
Mem *pRec;
7207171547
sqlite3_context ctx;
7207271548
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;
7208771562
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 ){
7209971574
assert( pOp>p->aOp );
7210071575
assert( pOp[-1].p4type==P4_COLLSEQ );
7210171576
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 ){
7211071585
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);
7211371588
}
7211471589
72115
- sqlite3VdbeMemRelease(&u.cg.ctx.s);
71590
+ sqlite3VdbeMemRelease(&ctx.s);
7211671591
7211771592
break;
7211871593
}
7211971594
7212071595
/* Opcode: AggFinal P1 P2 * P4 *
@@ -72129,23 +71604,21 @@
7212971604
** functions that can take varying numbers of arguments. The
7213071605
** P4 argument is only needed for the degenerate case where
7213171606
** the step function was not previously called.
7213271607
*/
7213371608
case OP_AggFinal: {
72134
-#if 0 /* local variables moved into u.ch */
7213571609
Mem *pMem;
72136
-#endif /* local variables moved into u.ch */
7213771610
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);
7214171614
if( rc ){
72142
- sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem));
71615
+ sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem));
7214371616
}
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) ){
7214771620
goto too_big;
7214871621
}
7214971622
break;
7215071623
}
7215171624
@@ -72160,31 +71633,29 @@
7216071633
** in the WAL that have been checkpointed after the checkpoint
7216171634
** completes into mem[P3+2]. However on an error, mem[P3+1] and
7216271635
** mem[P3+2] are initialized to -1.
7216371636
*/
7216471637
case OP_Checkpoint: {
72165
-#if 0 /* local variables moved into u.ci */
7216671638
int i; /* Loop counter */
7216771639
int aRes[3]; /* Results */
7216871640
Mem *pMem; /* Write results here */
72169
-#endif /* local variables moved into u.ci */
7217071641
7217171642
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;
7217471645
assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
7217571646
|| pOp->p2==SQLITE_CHECKPOINT_FULL
7217671647
|| pOp->p2==SQLITE_CHECKPOINT_RESTART
7217771648
);
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]);
7217971650
if( rc==SQLITE_BUSY ){
7218071651
rc = SQLITE_OK;
72181
- u.ci.aRes[0] = 1;
71652
+ aRes[0] = 1;
7218271653
}
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
+ }
7218671657
break;
7218771658
};
7218871659
#endif
7218971660
7219071661
#ifndef SQLITE_OMIT_PRAGMA
@@ -72198,98 +71669,96 @@
7219871669
** If changing into or out of WAL mode the procedure is more complicated.
7219971670
**
7220071671
** Write a string containing the final journal-mode to register P2.
7220171672
*/
7220271673
case OP_JournalMode: { /* out2-prerelease */
72203
-#if 0 /* local variables moved into u.cj */
7220471674
Btree *pBt; /* Btree to change journal mode of */
7220571675
Pager *pPager; /* Pager associated with pBt */
7220671676
int eNew; /* New journal mode */
7220771677
int eOld; /* The old journal mode */
7220871678
#ifndef SQLITE_OMIT_WAL
7220971679
const char *zFilename; /* Name of database file for pPager */
7221071680
#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
7222171690
);
7222271691
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7222371692
assert( p->readOnly==0 );
7222471693
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;
7223071699
7223171700
#ifndef SQLITE_OMIT_WAL
72232
- u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1);
71701
+ zFilename = sqlite3PagerFilename(pPager, 1);
7223371702
7223471703
/* 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
7223671705
*/
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 */
7224071709
){
72241
- u.cj.eNew = u.cj.eOld;
71710
+ eNew = eOld;
7224271711
}
7224371712
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)
7224671715
){
7224771716
if( !db->autoCommit || db->nVdbeRead>1 ){
7224871717
rc = SQLITE_ERROR;
72249
- sqlite3SetString(&p->zErrMsg, db,
71718
+ sqlite3SetString(&p->zErrMsg, db,
7225071719
"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")
7225271721
);
7225371722
break;
7225471723
}else{
72255
-
72256
- if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){
71724
+
71725
+ if( eOld==PAGER_JOURNALMODE_WAL ){
7225771726
/* 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.
7226171730
*/
72262
- rc = sqlite3PagerCloseWal(u.cj.pPager);
71731
+ rc = sqlite3PagerCloseWal(pPager);
7226371732
if( rc==SQLITE_OK ){
72264
- sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
71733
+ sqlite3PagerSetJournalMode(pPager, eNew);
7226571734
}
72266
- }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){
71735
+ }else if( eOld==PAGER_JOURNALMODE_MEMORY ){
7226771736
/* Cannot transition directly from MEMORY to WAL. Use mode OFF
7226871737
** as an intermediate */
72269
- sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF);
71738
+ sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF);
7227071739
}
72271
-
71740
+
7227271741
/* Open a transaction on the database file. Regardless of the journal
7227371742
** mode, this transaction always uses a rollback journal.
7227471743
*/
72275
- assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 );
71744
+ assert( sqlite3BtreeIsInTrans(pBt)==0 );
7227671745
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));
7227871747
}
7227971748
}
7228071749
}
7228171750
#endif /* ifndef SQLITE_OMIT_WAL */
7228271751
7228371752
if( rc ){
72284
- u.cj.eNew = u.cj.eOld;
71753
+ eNew = eOld;
7228571754
}
72286
- u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
71755
+ eNew = sqlite3PagerSetJournalMode(pPager, eNew);
7228771756
7228871757
pOut = &aMem[pOp->p2];
7228971758
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
72290
- pOut->z = (char *)sqlite3JournalModename(u.cj.eNew);
71759
+ pOut->z = (char *)sqlite3JournalModename(eNew);
7229171760
pOut->n = sqlite3Strlen30(pOut->z);
7229271761
pOut->enc = SQLITE_UTF8;
7229371762
sqlite3VdbeChangeEncoding(pOut, encoding);
7229471763
break;
7229571764
};
@@ -72315,19 +71784,17 @@
7231571784
** Perform a single step of the incremental vacuum procedure on
7231671785
** the P1 database. If the vacuum has finished, jump to instruction
7231771786
** P2. Otherwise, fall through to the next instruction.
7231871787
*/
7231971788
case OP_IncrVacuum: { /* jump */
72320
-#if 0 /* local variables moved into u.ck */
7232171789
Btree *pBt;
72322
-#endif /* local variables moved into u.ck */
7232371790
7232471791
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7232571792
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
7232671793
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);
7232971796
if( rc==SQLITE_DONE ){
7233071797
pc = pOp->p2 - 1;
7233171798
rc = SQLITE_OK;
7233271799
}
7233371800
break;
@@ -72394,16 +71861,14 @@
7239471861
** Also, whether or not P4 is set, check that this is not being called from
7239571862
** within a callback to a virtual table xSync() method. If it is, the error
7239671863
** code will be set to SQLITE_LOCKED.
7239771864
*/
7239871865
case OP_VBegin: {
72399
-#if 0 /* local variables moved into u.cl */
7240071866
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);
7240571870
break;
7240671871
}
7240771872
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7240871873
7240971874
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72438,36 +71903,34 @@
7243871903
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7243971904
** P1 is a cursor number. This opcode opens a cursor to the virtual
7244071905
** table and stores that cursor in P1.
7244171906
*/
7244271907
case OP_VOpen: {
72443
-#if 0 /* local variables moved into u.cm */
7244471908
VdbeCursor *pCur;
7244571909
sqlite3_vtab_cursor *pVtabCursor;
7244671910
sqlite3_vtab *pVtab;
7244771911
sqlite3_module *pModule;
72448
-#endif /* local variables moved into u.cm */
7244971912
7245071913
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);
7245871921
if( SQLITE_OK==rc ){
7245971922
/* Initialize sqlite3_vtab_cursor base class */
72460
- u.cm.pVtabCursor->pVtab = u.cm.pVtab;
71923
+ pVtabCursor->pVtab = pVtab;
7246171924
7246271925
/* 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;
7246671929
}else{
7246771930
db->mallocFailed = 1;
72468
- u.cm.pModule->xClose(u.cm.pVtabCursor);
71931
+ pModule->xClose(pVtabCursor);
7246971932
}
7247071933
}
7247171934
break;
7247271935
}
7247371936
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72491,11 +71954,10 @@
7249171954
** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
7249271955
**
7249371956
** A jump is made to P2 if the result set after filtering would be empty.
7249471957
*/
7249571958
case OP_VFilter: { /* jump */
72496
-#if 0 /* local variables moved into u.cn */
7249771959
int nArg;
7249871960
int iQuery;
7249971961
const sqlite3_module *pModule;
7250071962
Mem *pQuery;
7250171963
Mem *pArgc;
@@ -72503,49 +71965,48 @@
7250371965
sqlite3_vtab *pVtab;
7250471966
VdbeCursor *pCur;
7250571967
int res;
7250671968
int i;
7250771969
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;
7251971980
7252071981
/* 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;
7252471985
7252571986
/* Invoke the xFilter method */
7252671987
{
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]);
7253271993
}
7253371994
7253471995
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);
7253671997
p->inVtabMethod = 0;
72537
- sqlite3VtabImportErrmsg(p, u.cn.pVtab);
71998
+ sqlite3VtabImportErrmsg(p, pVtab);
7253871999
if( rc==SQLITE_OK ){
72539
- u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
72000
+ res = pModule->xEof(pVtabCursor);
7254072001
}
7254172002
72542
- if( u.cn.res ){
72003
+ if( res ){
7254372004
pc = pOp->p2 - 1;
7254472005
}
7254572006
}
72546
- u.cn.pCur->nullRow = 0;
72007
+ pCur->nullRow = 0;
7254772008
7254872009
break;
7254972010
}
7255072011
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7255172012
@@ -72556,55 +72017,53 @@
7255672017
** Store the value of the P2-th column of
7255772018
** the row of the virtual-table that the
7255872019
** P1 cursor is pointing to into register P3.
7255972020
*/
7256072021
case OP_VColumn: {
72561
-#if 0 /* local variables moved into u.co */
7256272022
sqlite3_vtab *pVtab;
7256372023
const sqlite3_module *pModule;
7256472024
Mem *pDest;
7256572025
sqlite3_context sContext;
72566
-#endif /* local variables moved into u.co */
7256772026
7256872027
VdbeCursor *pCur = p->apCsr[pOp->p1];
7256972028
assert( pCur->pVtabCursor );
7257072029
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);
7257372032
if( pCur->nullRow ){
72574
- sqlite3VdbeMemSetNull(u.co.pDest);
72033
+ sqlite3VdbeMemSetNull(pDest);
7257572034
break;
7257672035
}
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));
7258172040
7258272041
/* 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
7258572044
** new one.
7258672045
*/
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);
7258972048
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;
7259472053
}
7259572054
7259672055
/* Copy the result of the function to the P3 register. We
7259772056
** 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.
7259972058
*/
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);
7260472063
72605
- if( sqlite3VdbeMemTooBig(u.co.pDest) ){
72064
+ if( sqlite3VdbeMemTooBig(pDest) ){
7260672065
goto too_big;
7260772066
}
7260872067
break;
7260972068
}
7261072069
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72615,42 +72074,40 @@
7261572074
** Advance virtual table P1 to the next row in its result set and
7261672075
** jump to instruction P2. Or, if the virtual table has reached
7261772076
** the end of its result set, then fall through to the next instruction.
7261872077
*/
7261972078
case OP_VNext: { /* jump */
72620
-#if 0 /* local variables moved into u.cp */
7262172079
sqlite3_vtab *pVtab;
7262272080
const sqlite3_module *pModule;
7262372081
int res;
7262472082
VdbeCursor *pCur;
72625
-#endif /* local variables moved into u.cp */
7262672083
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 ){
7263172088
break;
7263272089
}
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 );
7263672093
7263772094
/* Invoke the xNext() method of the module. There is no way for the
7263872095
** 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
7264072097
** data is available) and the error code returned when xColumn or
7264172098
** some other method is next invoked on the save virtual table cursor.
7264272099
*/
7264372100
p->inVtabMethod = 1;
72644
- rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
72101
+ rc = pModule->xNext(pCur->pVtabCursor);
7264572102
p->inVtabMethod = 0;
72646
- sqlite3VtabImportErrmsg(p, u.cp.pVtab);
72103
+ sqlite3VtabImportErrmsg(p, pVtab);
7264772104
if( rc==SQLITE_OK ){
72648
- u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
72105
+ res = pModule->xEof(pCur->pVtabCursor);
7264972106
}
7265072107
72651
- if( !u.cp.res ){
72108
+ if( !res ){
7265272109
/* If there is data, jump to P2 */
7265372110
pc = pOp->p2 - 1;
7265472111
}
7265572112
goto check_for_interrupt;
7265672113
}
@@ -72662,29 +72119,27 @@
7266272119
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7266372120
** This opcode invokes the corresponding xRename method. The value
7266472121
** in register P1 is passed as the zName argument to the xRename method.
7266572122
*/
7266672123
case OP_VRename: {
72667
-#if 0 /* local variables moved into u.cq */
7266872124
sqlite3_vtab *pVtab;
7266972125
Mem *pName;
72670
-#endif /* local variables moved into u.cq */
7267172126
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) );
7267672131
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);
7268372138
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);
7268672141
p->expired = 0;
7268772142
}
7268872143
break;
7268972144
}
7269072145
#endif
@@ -72713,46 +72168,44 @@
7271372168
** P1 is a boolean flag. If it is set to true and the xUpdate call
7271472169
** is successful, then the value returned by sqlite3_last_insert_rowid()
7271572170
** is set to the value of the rowid for the row just inserted.
7271672171
*/
7271772172
case OP_VUpdate: {
72718
-#if 0 /* local variables moved into u.cr */
7271972173
sqlite3_vtab *pVtab;
7272072174
sqlite3_module *pModule;
7272172175
int nArg;
7272272176
int i;
7272372177
sqlite_int64 rowid;
7272472178
Mem **apArg;
7272572179
Mem *pX;
72726
-#endif /* local variables moved into u.cr */
7272772180
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
7272972182
|| pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
7273072183
);
7273172184
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;
7273572188
assert( pOp->p4type==P4_VTAB );
72736
- if( ALWAYS(u.cr.pModule->xUpdate) ){
72189
+ if( ALWAYS(pModule->xUpdate) ){
7273772190
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++;
7274672199
}
7274772200
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);
7274972202
db->vtabOnConflict = vtabOnConflict;
72750
- sqlite3VtabImportErrmsg(p, u.cr.pVtab);
72203
+ sqlite3VtabImportErrmsg(p, pVtab);
7275172204
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;
7275472207
}
7275572208
if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
7275672209
if( pOp->p5==OE_Ignore ){
7275772210
rc = SQLITE_OK;
7275872211
}else{
@@ -72808,38 +72261,36 @@
7280872261
**
7280972262
** If tracing is enabled (by the sqlite3_trace()) interface, then
7281072263
** the UTF-8 string contained in P4 is emitted on the trace callback.
7281172264
*/
7281272265
case OP_Trace: {
72813
-#if 0 /* local variables moved into u.cs */
7281472266
char *zTrace;
7281572267
char *z;
72816
-#endif /* local variables moved into u.cs */
7281772268
7281872269
if( db->xTrace
7281972270
&& !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
7282172272
){
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);
7282572276
}
7282672277
#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 ){
7282972280
int i;
7283072281
for(i=0; i<db->nDb; i++){
7283172282
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);
7283372284
}
7283472285
}
7283572286
#endif /* SQLITE_USE_FCNTL_TRACE */
7283672287
#ifdef SQLITE_DEBUG
7283772288
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
7283972290
){
72840
- sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
72291
+ sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
7284172292
}
7284272293
#endif /* SQLITE_DEBUG */
7284372294
break;
7284472295
}
7284572296
#endif
@@ -72964,10 +72415,11 @@
7296472415
rc = SQLITE_INTERRUPT;
7296572416
p->rc = rc;
7296672417
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
7296772418
goto vdbe_error_halt;
7296872419
}
72420
+
7296972421
7297072422
/************** End of vdbe.c ************************************************/
7297172423
/************** Begin file vdbeblob.c ****************************************/
7297272424
/*
7297372425
** 2007 May 1
@@ -88225,13 +87677,13 @@
8822587677
sqlite3StrAccumInit(&errMsg, 0, 0, 200);
8822687678
errMsg.db = pParse->db;
8822787679
for(j=0; j<pIdx->nKeyCol; j++){
8822887680
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
8822987681
if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
88230
- sqlite3StrAccumAppend(&errMsg, pTab->zName, -1);
87682
+ sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
8823187683
sqlite3StrAccumAppend(&errMsg, ".", 1);
88232
- sqlite3StrAccumAppend(&errMsg, zCol, -1);
87684
+ sqlite3StrAccumAppendAll(&errMsg, zCol);
8823387685
}
8823487686
zErr = sqlite3StrAccumFinish(&errMsg);
8823587687
sqlite3HaltConstraint(pParse,
8823687688
(pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
8823787689
onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88419,12 +87871,13 @@
8841987871
}
8842087872
if( pKey ){
8842187873
assert( sqlite3KeyInfoIsWriteable(pKey) );
8842287874
for(i=0; i<nCol; i++){
8842387875
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);
8842687879
pKey->aSortOrder[i] = pIdx->aSortOrder[i];
8842787880
}
8842887881
if( pParse->nErr ){
8842987882
sqlite3KeyInfoUnref(pKey);
8843087883
}else{
@@ -91238,15 +90691,15 @@
9123890691
nSep = sqlite3_value_bytes(argv[1]);
9123990692
}else{
9124090693
zSep = ",";
9124190694
nSep = 1;
9124290695
}
91243
- sqlite3StrAccumAppend(pAccum, zSep, nSep);
90696
+ if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep);
9124490697
}
9124590698
zVal = (char*)sqlite3_value_text(argv[0]);
9124690699
nVal = sqlite3_value_bytes(argv[0]);
91247
- sqlite3StrAccumAppend(pAccum, zVal, nVal);
90700
+ if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal);
9124890701
}
9124990702
}
9125090703
static void groupConcatFinalize(sqlite3_context *context){
9125190704
StrAccum *pAccum;
9125290705
pAccum = sqlite3_aggregate_context(context, 0);
@@ -110314,12 +109767,11 @@
110314109767
int res; /* Result of comparison operation */
110315109768
110316109769
#ifndef SQLITE_DEBUG
110317109770
UNUSED_PARAMETER( pParse );
110318109771
#endif
110319
- assert( pRec!=0 || pParse->db->mallocFailed );
110320
- if( pRec==0 ) return;
109772
+ assert( pRec!=0 );
110321109773
iCol = pRec->nField - 1;
110322109774
assert( pIdx->nSample>0 );
110323109775
assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
110324109776
do{
110325109777
iTest = (iMin+i)/2;
@@ -110978,11 +110430,11 @@
110978110430
int iTerm, /* Index of this term. First is zero */
110979110431
const char *zColumn, /* Name of the column */
110980110432
const char *zOp /* Name of the operator */
110981110433
){
110982110434
if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110983
- sqlite3StrAccumAppend(pStr, zColumn, -1);
110435
+ sqlite3StrAccumAppendAll(pStr, zColumn);
110984110436
sqlite3StrAccumAppend(pStr, zOp, 1);
110985110437
sqlite3StrAccumAppend(pStr, "?", 1);
110986110438
}
110987110439
110988110440
/*
@@ -111024,11 +110476,11 @@
111024110476
if( i>=nSkip ){
111025110477
explainAppendTerm(&txt, i, z, "=");
111026110478
}else{
111027110479
if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
111028110480
sqlite3StrAccumAppend(&txt, "ANY(", 4);
111029
- sqlite3StrAccumAppend(&txt, z, -1);
110481
+ sqlite3StrAccumAppendAll(&txt, z);
111030110482
sqlite3StrAccumAppend(&txt, ")", 1);
111031110483
}
111032110484
}
111033110485
111034110486
j = i;
@@ -119582,11 +119034,12 @@
119582119034
}
119583119035
db->lookaside.pEnd = p;
119584119036
db->lookaside.bEnabled = 1;
119585119037
db->lookaside.bMalloced = pBuf==0 ?1:0;
119586119038
}else{
119587
- db->lookaside.pEnd = 0;
119039
+ db->lookaside.pStart = db;
119040
+ db->lookaside.pEnd = db;
119588119041
db->lookaside.bEnabled = 0;
119589119042
db->lookaside.bMalloced = 0;
119590119043
}
119591119044
return SQLITE_OK;
119592119045
}
@@ -120080,10 +119533,11 @@
120080119533
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
120081119534
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
120082119535
case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
120083119536
case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
120084119537
case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
119538
+ case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
120085119539
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
120086119540
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
120087119541
case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
120088119542
case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
120089119543
case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
120090119544
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
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
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -133,13 +133,13 @@
133 **
134 ** See also: [sqlite3_libversion()],
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
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"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -517,10 +517,11 @@
517 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
 
522 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
523 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
524 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
525 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
526 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -584,11 +585,12 @@
584 ** information is written to disk in the same order as calls
585 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
586 ** after reboot following a crash or power loss, the only bytes in a
587 ** file that were written at the application level might have changed
588 ** and that adjacent bytes, even bytes within the same sector are
589 ** guaranteed to be unchanged.
 
590 */
591 #define SQLITE_IOCAP_ATOMIC 0x00000001
592 #define SQLITE_IOCAP_ATOMIC512 0x00000002
593 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
594 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -947,10 +949,16 @@
947 ** This file control is used by some VFS activity tracing [shims].
948 ** The argument is a zero-terminated string. Higher layers in the
949 ** SQLite stack may generate instances of this file control if
950 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
951 **
 
 
 
 
 
 
952 ** </ul>
953 */
954 #define SQLITE_FCNTL_LOCKSTATE 1
955 #define SQLITE_GET_LOCKPROXYFILE 2
956 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -967,10 +975,11 @@
967 #define SQLITE_FCNTL_PRAGMA 14
968 #define SQLITE_FCNTL_BUSYHANDLER 15
969 #define SQLITE_FCNTL_TEMPFILENAME 16
970 #define SQLITE_FCNTL_MMAP_SIZE 18
971 #define SQLITE_FCNTL_TRACE 19
 
972
973 /*
974 ** CAPI3REF: Mutex Handle
975 **
976 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -12492,10 +12501,11 @@
12492 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
12493 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
12494
12495 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
12496 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
 
12497 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
12498 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
12499 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
12500 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
12501 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -13322,10 +13332,13 @@
13322 "SMALL_STACK",
13323 #endif
13324 #ifdef SQLITE_SOUNDEX
13325 "SOUNDEX",
13326 #endif
 
 
 
13327 #ifdef SQLITE_TCL
13328 "TCL",
13329 #endif
13330 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
13331 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
@@ -13336,10 +13349,13 @@
13336 #if defined(SQLITE_THREADSAFE)
13337 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
13338 #endif
13339 #ifdef SQLITE_USE_ALLOCA
13340 "USE_ALLOCA",
 
 
 
13341 #endif
13342 #ifdef SQLITE_ZERO_MALLOC
13343 "ZERO_MALLOC"
13344 #endif
13345 };
@@ -13789,11 +13805,11 @@
13789 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
13790 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
13791 #endif
13792 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13793 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13794 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
13795 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13796 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
13797
13798 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13799 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -17518,11 +17534,11 @@
17518 ** works for chunks that are currently checked out.
17519 */
17520 static int memsys5Size(void *p){
17521 int iSize = 0;
17522 if( p ){
17523 int i = ((u8 *)p-mem5.zPool)/mem5.szAtom;
17524 assert( i>=0 && i<mem5.nBlock );
17525 iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
17526 }
17527 return iSize;
17528 }
@@ -17605,11 +17621,11 @@
17605 int iBlock;
17606
17607 /* Set iBlock to the index of the block pointed to by pOld in
17608 ** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
17609 */
17610 iBlock = ((u8 *)pOld-mem5.zPool)/mem5.szAtom;
17611
17612 /* Check that the pointer pOld points to a valid, non-free block. */
17613 assert( iBlock>=0 && iBlock<mem5.nBlock );
17614 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
17615 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
@@ -19374,11 +19390,11 @@
19374 /*
19375 ** TRUE if p is a lookaside memory allocation from db
19376 */
19377 #ifndef SQLITE_OMIT_LOOKASIDE
19378 static int isLookaside(sqlite3 *db, void *p){
19379 return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19380 }
19381 #else
19382 #define isLookaside(A,B) 0
19383 #endif
19384
@@ -19390,12 +19406,13 @@
19390 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
19391 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
19392 return sqlite3GlobalConfig.m.xSize(p);
19393 }
19394 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19395 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19396 if( db && isLookaside(db, p) ){
 
19397 return db->lookaside.sz;
19398 }else{
19399 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
19400 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
19401 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19873,10 +19890,18 @@
19873 }
19874 if( N>0 ){
19875 sqlite3StrAccumAppend(pAccum, zSpaces, N);
19876 }
19877 }
 
 
 
 
 
 
 
 
19878
19879 /*
19880 ** On machines with a small stack size, you can redefine the
19881 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19882 */
@@ -20085,11 +20110,11 @@
20085 zOut = buf;
20086 }else{
20087 nOut = precision + 10;
20088 zOut = zExtra = sqlite3Malloc( nOut );
20089 if( zOut==0 ){
20090 pAccum->accError = STRACCUM_NOMEM;
20091 return;
20092 }
20093 }
20094 bufpt = &zOut[nOut-1];
20095 if( xtype==etORDINAL ){
@@ -20197,11 +20222,11 @@
20197 e2 = exp;
20198 }
20199 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
20200 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
20201 if( bufpt==0 ){
20202 pAccum->accError = STRACCUM_NOMEM;
20203 return;
20204 }
20205 }
20206 zOut = bufpt;
20207 nsd = 16 + flag_altform2*10;
@@ -20332,11 +20357,11 @@
20332 needQuote = !isnull && xtype==etSQLESCAPE2;
20333 n += i + 1 + needQuote*2;
20334 if( n>etBUFSIZE ){
20335 bufpt = zExtra = sqlite3Malloc( n );
20336 if( bufpt==0 ){
20337 pAccum->accError = STRACCUM_NOMEM;
20338 return;
20339 }
20340 }else{
20341 bufpt = buf;
20342 }
@@ -20355,11 +20380,11 @@
20355 ** if( precision>=0 && precision<length ) length = precision; */
20356 break;
20357 }
20358 case etTOKEN: {
20359 Token *pToken = va_arg(ap, Token*);
20360 if( pToken ){
20361 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
20362 }
20363 length = width = 0;
20364 break;
20365 }
@@ -20367,14 +20392,14 @@
20367 SrcList *pSrc = va_arg(ap, SrcList*);
20368 int k = va_arg(ap, int);
20369 struct SrcList_item *pItem = &pSrc->a[k];
20370 assert( k>=0 && k<pSrc->nSrc );
20371 if( pItem->zDatabase ){
20372 sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1);
20373 sqlite3StrAccumAppend(pAccum, ".", 1);
20374 }
20375 sqlite3StrAccumAppend(pAccum, pItem->zName, -1);
20376 length = width = 0;
20377 break;
20378 }
20379 default: {
20380 assert( xtype==etINVALID );
@@ -20409,36 +20434,34 @@
20409
20410 /*
20411 ** Append N bytes of text from z to the StrAccum object.
20412 */
20413 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 }
20425 if( p->nChar+N >= p->nAlloc ){
20426 char *zNew;
 
 
 
 
 
20427 if( !p->useMalloc ){
20428 p->accError = STRACCUM_TOOBIG;
20429 N = p->nAlloc - p->nChar - 1;
 
20430 if( N<=0 ){
20431 return;
20432 }
20433 }else{
20434 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
20435 i64 szNew = p->nChar;
20436 szNew += N + 1;
20437 if( szNew > p->mxAlloc ){
20438 sqlite3StrAccumReset(p);
20439 p->accError = STRACCUM_TOOBIG;
20440 return;
20441 }else{
20442 p->nAlloc = (int)szNew;
20443 }
20444 if( p->useMalloc==1 ){
@@ -20448,20 +20471,28 @@
20448 }
20449 if( zNew ){
20450 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20451 p->zText = zNew;
20452 }else{
20453 p->accError = STRACCUM_NOMEM;
20454 sqlite3StrAccumReset(p);
 
20455 return;
20456 }
20457 }
20458 }
20459 assert( p->zText );
20460 memcpy(&p->zText[p->nChar], z, N);
20461 p->nChar += N;
20462 }
 
 
 
 
 
 
 
 
20463
20464 /*
20465 ** Finish off a string by making sure it is zero-terminated.
20466 ** Return a pointer to the resulting string. Return a NULL
20467 ** pointer if any kind of error was encountered.
@@ -20476,11 +20507,11 @@
20476 p->zText = sqlite3_malloc(p->nChar+1);
20477 }
20478 if( p->zText ){
20479 memcpy(p->zText, p->zBase, p->nChar+1);
20480 }else{
20481 p->accError = STRACCUM_NOMEM;
20482 }
20483 }
20484 }
20485 return p->zText;
20486 }
@@ -22629,11 +22660,13 @@
22629 if( x<10 ) return 1;
22630 n = x%10;
22631 x /= 10;
22632 if( n>=5 ) n -= 2;
22633 else if( n>=1 ) n -= 1;
22634 if( x>=3 ) return (n+8)<<(x-3);
 
 
22635 return (n+8)>>(3-x);
22636 }
22637
22638 /************** End of util.c ************************************************/
22639 /************** Begin file hash.c ********************************************/
@@ -24611,10 +24644,19 @@
24611 }
24612 *ppInode = pInode;
24613 return SQLITE_OK;
24614 }
24615
 
 
 
 
 
 
 
 
 
24616
24617 /*
24618 ** Check a unixFile that is a database. Verify the following:
24619 **
24620 ** (1) There is exactly one hard link on the file
@@ -24645,14 +24687,11 @@
24645 if( buf.st_nlink>1 ){
24646 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
24647 pFile->ctrlFlags |= UNIXFILE_WARNED;
24648 return;
24649 }
24650 if( pFile->pInode!=0
24651 && ((rc = osStat(pFile->zPath, &buf))!=0
24652 || buf.st_ino!=pFile->pInode->fileId.ino)
24653 ){
24654 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
24655 pFile->ctrlFlags |= UNIXFILE_WARNED;
24656 return;
24657 }
24658 }
@@ -27096,10 +27135,14 @@
27096 if( zTFile ){
27097 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
27098 *(char**)pArg = zTFile;
27099 }
27100 return SQLITE_OK;
 
 
 
 
27101 }
27102 #if SQLITE_MAX_MMAP_SIZE>0
27103 case SQLITE_FCNTL_MMAP_SIZE: {
27104 i64 newLimit = *(i64*)pArg;
27105 int rc = SQLITE_OK;
@@ -27377,11 +27420,11 @@
27377
27378 /* Update the global lock state and do debug tracing */
27379 #ifdef SQLITE_DEBUG
27380 { u16 mask;
27381 OSTRACE(("SHM-LOCK "));
27382 mask = (1<<(ofst+n)) - (1<<ofst);
27383 if( rc==SQLITE_OK ){
27384 if( lockType==F_UNLCK ){
27385 OSTRACE(("unlock %d ok", ofst));
27386 pShmNode->exclMask &= ~mask;
27387 pShmNode->sharedMask &= ~mask;
@@ -43889,10 +43932,34 @@
43889 *ppPager = pPager;
43890 return SQLITE_OK;
43891 }
43892
43893
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43894
43895 /*
43896 ** This function is called after transitioning from PAGER_UNLOCK to
43897 ** PAGER_SHARED state. It tests if there is a hot journal present in
43898 ** the file-system for the given pager. A hot journal is one that
@@ -44360,11 +44427,11 @@
44360 if( bMmapOk && pagerUseWal(pPager) ){
44361 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
44362 if( rc!=SQLITE_OK ) goto pager_acquire_err;
44363 }
44364
44365 if( iFrame==0 && bMmapOk ){
44366 void *pData = 0;
44367
44368 rc = sqlite3OsFetch(pPager->fd,
44369 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
44370 );
@@ -44565,17 +44632,23 @@
44565 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
44566 (pPager->tempFile ?
44567 (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
44568 (SQLITE_OPEN_MAIN_JOURNAL)
44569 );
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
 
 
 
 
 
 
44577 }
44578 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
44579 }
44580
44581
@@ -44705,18 +44778,12 @@
44705 assert( pPager->eState==PAGER_WRITER_LOCKED
44706 || pPager->eState==PAGER_WRITER_CACHEMOD
44707 || pPager->eState==PAGER_WRITER_DBMOD
44708 );
44709 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;
44718
44719 CHECK_PAGE(pPg);
44720
44721 /* The journal file needs to be opened. Higher level routines have already
44722 ** obtained the necessary locks to begin the write-transaction, but the
@@ -44841,23 +44908,23 @@
44841 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
44842 int rc = SQLITE_OK;
44843
44844 PgHdr *pPg = pDbPage;
44845 Pager *pPager = pPg->pPager;
44846 Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
44847
44848 assert( (pPg->flags & PGHDR_MMAP)==0 );
44849 assert( pPager->eState>=PAGER_WRITER_LOCKED );
44850 assert( pPager->eState!=PAGER_ERROR );
44851 assert( assert_pager_state(pPager) );
44852
44853 if( nPagePerSector>1 ){
44854 Pgno nPageCount; /* Total number of pages in database file */
44855 Pgno pg1; /* First page of the sector pPg is located on. */
44856 int nPage = 0; /* Number of pages starting at pg1 to journal */
44857 int ii; /* Loop counter */
44858 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
 
44859
44860 /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
44861 ** a journal header to be written between the pages journaled by
44862 ** this function.
44863 */
@@ -51991,11 +52058,11 @@
51991
51992 if( pgno>btreePagecount(pBt) ){
51993 rc = SQLITE_CORRUPT_BKPT;
51994 }else{
51995 rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
51996 if( rc==SQLITE_OK ){
51997 rc = btreeInitPage(*ppPage);
51998 if( rc!=SQLITE_OK ){
51999 releasePage(*ppPage);
52000 }
52001 }
@@ -54531,14 +54598,14 @@
54531 }
54532
54533 /*
54534 ** Return a pointer to payload information from the entry that the
54535 ** 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.
54540 **
54541 ** This routine is an optimization. It is common for the entire key
54542 ** and data to fit on the local page and for there to be no overflow
54543 ** pages. When that is so, this routine can be used to access the
54544 ** key and data without making a copy. If the key and/or data spills
@@ -54547,45 +54614,25 @@
54547 **
54548 ** The pointer returned by this routine looks directly into the cached
54549 ** page of the database. The data might change or move the next time
54550 ** any btree routine is called.
54551 */
54552 static const unsigned char *fetchPayload(
54553 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 */
54556 ){
54557 unsigned char *aPayload;
54558 MemPage *pPage;
54559 u32 nKey;
54560 u32 nLocal;
54561
54562 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
54563 assert( pCur->eState==CURSOR_VALID );
 
54564 assert( cursorHoldsMutex(pCur) );
54565 pPage = pCur->apPage[pCur->iPage];
54566 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
54567 if( pCur->info.nSize==0 ){
54568 btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
54569 &pCur->info);
54570 }
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;
54587 }
54588
54589
54590 /*
54591 ** For the entry that cursor pCur is point to, return as
@@ -54600,26 +54647,14 @@
54600 **
54601 ** These routines is used to get quick access to key and data
54602 ** in the common case where no overflow pages are used.
54603 */
54604 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;
54612 }
54613 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;
54621 }
54622
54623
54624 /*
54625 ** Move the cursor down to a new child page. The newPgno argument is the
@@ -54734,12 +54769,10 @@
54734 ** b-tree).
54735 */
54736 static int moveToRoot(BtCursor *pCur){
54737 MemPage *pRoot;
54738 int rc = SQLITE_OK;
54739 Btree *p = pCur->pBtree;
54740 BtShared *pBt = p->pBt;
54741
54742 assert( cursorHoldsMutex(pCur) );
54743 assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
54744 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
54745 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54750,20 +54783,16 @@
54750 }
54751 sqlite3BtreeClearCursor(pCur);
54752 }
54753
54754 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;
54760 }else if( pCur->pgnoRoot==0 ){
54761 pCur->eState = CURSOR_INVALID;
54762 return SQLITE_OK;
54763 }else{
54764 rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
54765 pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
54766 if( rc!=SQLITE_OK ){
54767 pCur->eState = CURSOR_INVALID;
54768 return rc;
54769 }
@@ -54792,18 +54821,20 @@
54792 pCur->aiIdx[0] = 0;
54793 pCur->info.nSize = 0;
54794 pCur->atLast = 0;
54795 pCur->validNKey = 0;
54796
54797 if( pRoot->nCell==0 && !pRoot->leaf ){
 
 
54798 Pgno subpage;
54799 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
54800 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
54801 pCur->eState = CURSOR_VALID;
54802 rc = moveToChild(pCur, subpage);
54803 }else{
54804 pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
54805 }
54806 return rc;
54807 }
54808
54809 /*
@@ -55055,21 +55086,18 @@
55055 ** the entire cell by checking for the cases where the record is
55056 ** stored entirely within the b-tree page by inspecting the first
55057 ** 2 bytes of the cell.
55058 */
55059 nCell = pCell[0];
55060 if( nCell<=pPage->max1bytePayload
55061 /* && (pCell+nCell)<pPage->aDataEnd */
55062 ){
55063 /* This branch runs if the record-size field of the cell is a
55064 ** single byte varint and the record fits entirely on the main
55065 ** b-tree page. */
55066 testcase( pCell+nCell+1==pPage->aDataEnd );
55067 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55068 }else if( !(pCell[1] & 0x80)
55069 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
55070 /* && (pCell+nCell+2)<=pPage->aDataEnd */
55071 ){
55072 /* The record-size field is a 2 byte varint and the record
55073 ** fits entirely on the main b-tree page. */
55074 testcase( pCell+nCell+2==pPage->aDataEnd );
55075 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -55889,11 +55917,11 @@
55889 nHeader = 0;
55890 if( !pPage->leaf ){
55891 nHeader += 4;
55892 }
55893 if( pPage->hasData ){
55894 nHeader += putVarint(&pCell[nHeader], nData+nZero);
55895 }else{
55896 nData = nZero = 0;
55897 }
55898 nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
55899 btreeParseCellPtr(pPage, pCell, &info);
@@ -56017,11 +56045,10 @@
56017 */
56018 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
56019 u32 pc; /* Offset to cell content of cell being deleted */
56020 u8 *data; /* pPage->aData */
56021 u8 *ptr; /* Used to move bytes around within data[] */
56022 u8 *endPtr; /* End of loop */
56023 int rc; /* The return code */
56024 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
56025
56026 if( *pRC ) return;
56027
@@ -56042,17 +56069,12 @@
56042 rc = freeSpace(pPage, pc, sz);
56043 if( rc ){
56044 *pRC = rc;
56045 return;
56046 }
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 pPage->nCell--;
 
56054 put2byte(&data[hdr+3], pPage->nCell);
56055 pPage->nFree += 2;
56056 }
56057
56058 /*
@@ -56085,13 +56107,10 @@
56085 int j; /* Loop counter */
56086 int end; /* First byte past the last cell pointer in data[] */
56087 int ins; /* Index in data[] where new cell pointer is inserted */
56088 int cellOffset; /* Address of first cell pointer in data[] */
56089 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 int nSkip = (iChild ? 4 : 0);
56094
56095 if( *pRC ) return;
56096
56097 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56138,17 +56157,11 @@
56138 pPage->nFree -= (u16)(2 + sz);
56139 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
56140 if( iChild ){
56141 put4byte(&data[idx], iChild);
56142 }
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 }
56150 put2byte(&data[ins], idx);
56151 put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
56152 #ifndef SQLITE_OMIT_AUTOVACUUM
56153 if( pPage->pBt->autoVacuum ){
56154 /* The cell may contain a pointer to an overflow page. If so, write
@@ -58106,11 +58119,11 @@
58106 va_start(ap, zFormat);
58107 if( pCheck->errMsg.nChar ){
58108 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
58109 }
58110 if( zMsg1 ){
58111 sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
58112 }
58113 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
58114 va_end(ap);
58115 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
58116 pCheck->mallocFailed = 1;
@@ -59682,61 +59695,59 @@
59682 #endif
59683 }
59684
59685 /*
59686 ** 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){
59699 assert( 1 >=
59700 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
59701 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
59702 ((pMem->flags&MEM_Ephem) ? 1 : 0) +
59703 ((pMem->flags&MEM_Static) ? 1 : 0)
59704 );
59705 assert( (pMem->flags&MEM_RowSet)==0 );
59706
59707 /* If the preserve flag is set to true, then the memory cell must already
59708 ** contain a valid string or blob value. */
59709 assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
 
59710
59711 if( n<32 ) n = 32;
59712 if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59713 if( preserve && pMem->z==pMem->zMalloc ){
59714 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59715 preserve = 0;
59716 }else{
59717 sqlite3DbFree(pMem->db, pMem->zMalloc);
59718 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
59719 }
 
 
 
 
 
59720 }
59721
59722 if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
59723 memcpy(pMem->zMalloc, pMem->z, pMem->n);
59724 }
59725 if( pMem->flags&MEM_Dyn && pMem->xDel ){
59726 assert( pMem->xDel!=SQLITE_DYNAMIC );
59727 pMem->xDel((void *)(pMem->z));
59728 }
59729
59730 pMem->z = pMem->zMalloc;
59731 if( pMem->z==0 ){
59732 pMem->flags = MEM_Null;
59733 }else{
59734 pMem->flags &= ~(MEM_Ephem|MEM_Static);
59735 }
59736 pMem->xDel = 0;
59737 return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);
59738 }
59739
59740 /*
59741 ** Make the given Mem object MEM_Dyn. In other words, make it so
59742 ** that any TEXT or BLOB content is stored in memory obtained from
@@ -59918,14 +59929,16 @@
59918 ** inconsistent state, for example with (Mem.z==0) and
59919 ** (Mem.type==SQLITE_TEXT).
59920 */
59921 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
59922 VdbeMemRelease(p);
59923 sqlite3DbFree(p->db, p->zMalloc);
 
 
 
59924 p->z = 0;
59925 p->zMalloc = 0;
59926 p->xDel = 0;
59927 }
59928
59929 /*
59930 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
59931 ** If the double is out of range of a 64-bit signed integer then
@@ -60639,19 +60652,19 @@
60639 Index *pIdx = p->pIdx; /* Index being probed */
60640 int nByte; /* Bytes of space to allocate */
60641 int i; /* Counter variable */
60642 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
60643
60644 nByte = sizeof(Mem) * nCol + sizeof(UnpackedRecord);
60645 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
60646 if( pRec ){
60647 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
60648 if( pRec->pKeyInfo ){
60649 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
60650 assert( pRec->pKeyInfo->enc==ENC(db) );
60651 pRec->flags = UNPACKED_PREFIX_MATCH;
60652 pRec->aMem = (Mem *)&pRec[1];
60653 for(i=0; i<nCol; i++){
60654 pRec->aMem[i].flags = MEM_Null;
60655 pRec->aMem[i].type = SQLITE_NULL;
60656 pRec->aMem[i].db = db;
60657 }
@@ -60842,11 +60855,11 @@
60842 if( aRet==0 ){
60843 sqlite3_result_error_nomem(context);
60844 }else{
60845 aRet[0] = nSerial+1;
60846 sqlite3PutVarint(&aRet[1], iSerial);
60847 sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format);
60848 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
60849 sqlite3DbFree(db, aRet);
60850 }
60851 }
60852
@@ -60920,11 +60933,10 @@
60920
60921 if( !pExpr ){
60922 pVal = valueNew(db, &alloc);
60923 if( pVal ){
60924 sqlite3VdbeMemSetNull((Mem*)pVal);
60925 *pbOk = 1;
60926 }
60927 }else if( pExpr->op==TK_VARIABLE
60928 || NEVER(pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
60929 ){
60930 Vdbe *v;
@@ -60936,20 +60948,17 @@
60936 rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
60937 if( rc==SQLITE_OK ){
60938 sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
60939 }
60940 pVal->db = pParse->db;
60941 *pbOk = 1;
60942 sqlite3VdbeMemStoreType((Mem*)pVal);
60943 }
60944 }else{
60945 *pbOk = 0;
60946 }
60947 }else{
60948 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
60949 *pbOk = (pVal!=0);
60950 }
 
60951
60952 assert( pVal==0 || pVal->db==db );
60953 return rc;
60954 }
60955
@@ -63838,25 +63847,19 @@
63838 /*
63839 ** Write the serialized data blob for the value stored in pMem into
63840 ** buf. It is assumed that the caller has allocated sufficient space.
63841 ** Return the number of bytes written.
63842 **
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.
63851 **
63852 ** Return the number of bytes actually written into buf[]. The number
63853 ** of bytes in the zero-filled tail is included in the return value only
63854 ** if those bytes were zeroed in buf[].
63855 */
63856 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
63857 u32 serial_type = sqlite3VdbeSerialType(pMem, file_format);
63858 u32 len;
63859
63860 /* Integer and Real */
63861 if( serial_type<=7 && serial_type>0 ){
63862 u64 v;
@@ -63867,11 +63870,10 @@
63867 swapMixedEndianFloat(v);
63868 }else{
63869 v = pMem->u.i;
63870 }
63871 len = i = sqlite3VdbeSerialTypeLen(serial_type);
63872 assert( len<=(u32)nBuf );
63873 while( i-- ){
63874 buf[i] = (u8)(v&0xFF);
63875 v >>= 8;
63876 }
63877 return len;
@@ -63879,21 +63881,12 @@
63879
63880 /* String or blob */
63881 if( serial_type>=12 ){
63882 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
63883 == (int)sqlite3VdbeSerialTypeLen(serial_type) );
63884 assert( pMem->n<=nBuf );
63885 len = pMem->n;
63886 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 return len;
63896 }
63897
63898 /* NULL or constants 0 or 1 */
63899 return 0;
@@ -65815,10 +65808,11 @@
65815 if( db->nVdbeExec>1 ){
65816 while( *zRawSql ){
65817 const char *zStart = zRawSql;
65818 while( *(zRawSql++)!='\n' && *zRawSql );
65819 sqlite3StrAccumAppend(&out, "-- ", 3);
 
65820 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
65821 }
65822 }else{
65823 while( zRawSql[0] ){
65824 n = findNextHostParameter(zRawSql, &nToken);
@@ -66658,433 +66652,11 @@
66658 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
66659 #ifdef VDBE_PROFILE
66660 u64 start; /* CPU clock count at start of opcode */
66661 int origPc; /* Program counter at start of opcode */
66662 #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 ********************************************************************/
67086
67087 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
67088 sqlite3VdbeEnter(p);
67089 if( p->rc==SQLITE_NOMEM ){
67090 /* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67326,20 +66898,18 @@
67326 /* Opcode: Yield P1 * * * *
67327 **
67328 ** Swap the program counter with the value in register P1.
67329 */
67330 case OP_Yield: { /* in1 */
67331 #if 0 /* local variables moved into u.aa */
67332 int pcDest;
67333 #endif /* local variables moved into u.aa */
67334 pIn1 = &aMem[pOp->p1];
67335 assert( (pIn1->flags & MEM_Dyn)==0 );
67336 pIn1->flags = MEM_Int;
67337 u.aa.pcDest = (int)pIn1->u.i;
67338 pIn1->u.i = pc;
67339 REGISTER_TRACE(pOp->p1, pIn1);
67340 pc = u.aa.pcDest;
67341 break;
67342 }
67343
67344 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67345 ** Synopsis: if r[P3] null then halt
@@ -67384,14 +66954,12 @@
67384 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
67385 ** every program. So a jump past the last instruction of the program
67386 ** is the same as executing Halt.
67387 */
67388 case OP_Halt: {
67389 #if 0 /* local variables moved into u.ab */
67390 const char *zType;
67391 const char *zLogFmt;
67392 #endif /* local variables moved into u.ab */
67393
67394 if( pOp->p1==SQLITE_OK && p->pFrame ){
67395 /* Halt the sub-program. Return control to the parent frame. */
67396 VdbeFrame *pFrame = p->pFrame;
67397 p->pFrame = pFrame->pParent;
@@ -67398,11 +66966,11 @@
67398 p->nFrame--;
67399 sqlite3VdbeSetChanges(db, p->nChange);
67400 pc = sqlite3VdbeFrameRestore(pFrame);
67401 lastRowid = db->lastRowid;
67402 if( pOp->p2==OE_Ignore ){
67403 /* Instruction pc is the OP_Program that invoked the sub-program
67404 ** currently being halted. If the p2 instruction of this OP_Halt
67405 ** instruction is set to OE_Ignore, then the sub-program is throwing
67406 ** an IGNORE exception. In this case jump to the address specified
67407 ** as the p2 of the calling OP_Program. */
67408 pc = p->aOp[pc].p2-1;
@@ -67421,25 +66989,25 @@
67421 assert( pOp->p5>=1 && pOp->p5<=4 );
67422 testcase( pOp->p5==1 );
67423 testcase( pOp->p5==2 );
67424 testcase( pOp->p5==3 );
67425 testcase( pOp->p5==4 );
67426 u.ab.zType = azType[pOp->p5-1];
67427 }else{
67428 u.ab.zType = 0;
67429 }
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);
67435 }else if( pOp->p4.z ){
67436 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67437 }else{
67438 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType);
67439 }
67440 sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg);
67441 }
67442 rc = sqlite3VdbeHalt(p);
67443 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
67444 if( rc==SQLITE_BUSY ){
67445 p->rc = rc = SQLITE_BUSY;
@@ -67549,23 +67117,21 @@
67549 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
67550 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
67551 ** OP_Ne or OP_Eq.
67552 */
67553 case OP_Null: { /* out2-prerelease */
67554 #if 0 /* local variables moved into u.ac */
67555 int cnt;
67556 u16 nullFlag;
67557 #endif /* local variables moved into u.ac */
67558 u.ac.cnt = pOp->p3-pOp->p2;
67559 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 ){
67562 pOut++;
67563 memAboutToChange(p, pOut);
67564 VdbeMemRelease(pOut);
67565 pOut->flags = u.ac.nullFlag;
67566 u.ac.cnt--;
67567 }
67568 break;
67569 }
67570
67571
@@ -67590,21 +67156,19 @@
67590 **
67591 ** If the parameter is named, then its name appears in P4 and P3==1.
67592 ** The P4 value is used by sqlite3_bind_parameter_name().
67593 */
67594 case OP_Variable: { /* out2-prerelease */
67595 #if 0 /* local variables moved into u.ad */
67596 Mem *pVar; /* Value being transferred */
67597 #endif /* local variables moved into u.ad */
67598
67599 assert( pOp->p1>0 && pOp->p1<=p->nVar );
67600 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) ){
67603 goto too_big;
67604 }
67605 sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static);
67606 UPDATE_MAX_BLOBSIZE(pOut);
67607 break;
67608 }
67609
67610 /* Opcode: Move P1 P2 P3 * *
@@ -67614,43 +67178,41 @@
67614 ** registers P2..P2+P3. Registers P1..P1+P3 are
67615 ** left holding a NULL. It is an error for register ranges
67616 ** P1..P1+P3 and P2..P2+P3 to overlap.
67617 */
67618 case OP_Move: {
67619 #if 0 /* local variables moved into u.ae */
67620 char *zMalloc; /* Holding variable for allocated memory */
67621 int n; /* Number of registers left to copy */
67622 int p1; /* Register to copy from */
67623 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];
67634 do{
67635 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67636 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67637 assert( memIsValid(pIn1) );
67638 memAboutToChange(p, pOut);
67639 u.ae.zMalloc = pOut->zMalloc;
67640 pOut->zMalloc = 0;
67641 sqlite3VdbeMemMove(pOut, pIn1);
67642 #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;
67645 }
67646 #endif
67647 pIn1->zMalloc = u.ae.zMalloc;
67648 REGISTER_TRACE(u.ae.p2++, pOut);
67649 pIn1++;
67650 pOut++;
67651 }while( u.ae.n-- );
67652 break;
67653 }
67654
67655 /* Opcode: Copy P1 P2 P3 * *
67656 ** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67659,26 +67221,24 @@
67659 **
67660 ** This instruction makes a deep copy of the value. A duplicate
67661 ** is made of any string or blob constant. See also OP_SCopy.
67662 */
67663 case OP_Copy: {
67664 #if 0 /* local variables moved into u.af */
67665 int n;
67666 #endif /* local variables moved into u.af */
67667
67668 u.af.n = pOp->p3;
67669 pIn1 = &aMem[pOp->p1];
67670 pOut = &aMem[pOp->p2];
67671 assert( pOut!=pIn1 );
67672 while( 1 ){
67673 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67674 Deephemeralize(pOut);
67675 #ifdef SQLITE_DEBUG
67676 pOut->pScopyFrom = 0;
67677 #endif
67678 REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut);
67679 if( (u.af.n--)==0 ) break;
67680 pOut++;
67681 pIn1++;
67682 }
67683 break;
67684 }
@@ -67715,14 +67275,12 @@
67715 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67716 ** structure to provide access to the top P1 values as the result
67717 ** row.
67718 */
67719 case OP_ResultRow: {
67720 #if 0 /* local variables moved into u.ag */
67721 Mem *pMem;
67722 int i;
67723 #endif /* local variables moved into u.ag */
67724 assert( p->nResColumn==pOp->p2 );
67725 assert( pOp->p1>0 );
67726 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67727
67728 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -67744,12 +67302,12 @@
67744 assert( db->flags&SQLITE_CountRows );
67745 assert( p->usesStmtJournal );
67746 break;
67747 }
67748
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
67751 ** modified to the user. This is the only way that a VM that
67752 ** opens a statement transaction may invoke this opcode.
67753 **
67754 ** In case this is such a statement, close any statement transaction
67755 ** opened by this VM before returning control to the user. This is to
@@ -67772,19 +67330,19 @@
67772
67773 /* Make sure the results of the current row are \000 terminated
67774 ** and have an assigned type. The results are de-ephemeralized as
67775 ** a side effect.
67776 */
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]);
67786 }
67787 if( db->mallocFailed ) goto no_mem;
67788
67789 /* Return SQLITE_ROW
67790 */
@@ -67805,13 +67363,11 @@
67805 ** It is illegal for P1 and P3 to be the same register. Sometimes,
67806 ** if P3 is the same register as P2, the implementation is able
67807 ** to avoid a memcpy().
67808 */
67809 case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67810 #if 0 /* local variables moved into u.ah */
67811 i64 nByte;
67812 #endif /* local variables moved into u.ah */
67813
67814 pIn1 = &aMem[pOp->p1];
67815 pIn2 = &aMem[pOp->p2];
67816 pOut = &aMem[pOp->p3];
67817 assert( pIn1!=pOut );
@@ -67820,26 +67376,26 @@
67820 break;
67821 }
67822 if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
67823 Stringify(pIn1, encoding);
67824 Stringify(pIn2, encoding);
67825 u.ah.nByte = pIn1->n + pIn2->n;
67826 if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67827 goto too_big;
67828 }
67829 MemSetTypeFlag(pOut, MEM_Str);
67830 if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){
67831 goto no_mem;
67832 }
67833 if( pOut!=pIn2 ){
67834 memcpy(pOut->z, pIn2->z, pIn2->n);
67835 }
67836 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67837 pOut->z[u.ah.nByte]=0;
67838 pOut->z[u.ah.nByte+1] = 0;
67839 pOut->flags |= MEM_Term;
67840 pOut->n = (int)u.ah.nByte;
67841 pOut->enc = encoding;
67842 UPDATE_MAX_BLOBSIZE(pOut);
67843 break;
67844 }
67845
@@ -67884,83 +67440,81 @@
67884 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67885 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67886 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
67887 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
67888 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67889 #if 0 /* local variables moved into u.ai */
67890 char bIntint; /* Started out as two integer operands */
67891 int flags; /* Combined MEM_* flags from both inputs */
67892 i64 iA; /* Integer value of left operand */
67893 i64 iB; /* Integer value of right operand */
67894 double rA; /* Real value of left operand */
67895 double rB; /* Real value of right operand */
67896 #endif /* local variables moved into u.ai */
67897
67898 pIn1 = &aMem[pOp->p1];
67899 applyNumericAffinity(pIn1);
67900 pIn2 = &aMem[pOp->p2];
67901 applyNumericAffinity(pIn2);
67902 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;
67905 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;
67909 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;
67913 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;
67917 break;
67918 }
67919 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;
67923 break;
67924 }
67925 }
67926 pOut->u.i = u.ai.iB;
67927 MemSetTypeFlag(pOut, MEM_Int);
67928 }else{
67929 u.ai.bIntint = 0;
67930 fp_math:
67931 u.ai.rA = sqlite3VdbeRealValue(pIn1);
67932 u.ai.rB = sqlite3VdbeRealValue(pIn2);
67933 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;
67937 case OP_Divide: {
67938 /* (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;
67941 break;
67942 }
67943 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);
67949 break;
67950 }
67951 }
67952 #ifdef SQLITE_OMIT_FLOATING_POINT
67953 pOut->u.i = u.ai.rB;
67954 MemSetTypeFlag(pOut, MEM_Int);
67955 #else
67956 if( sqlite3IsNaN(u.ai.rB) ){
67957 goto arithmetic_result_is_null;
67958 }
67959 pOut->r = u.ai.rB;
67960 MemSetTypeFlag(pOut, MEM_Real);
67961 if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){
67962 sqlite3VdbeIntegerAffinity(pOut);
67963 }
67964 #endif
67965 }
67966 break;
@@ -68009,85 +67563,83 @@
68009 ** invocation of this opcode.
68010 **
68011 ** See also: AggStep and AggFinal
68012 */
68013 case OP_Function: {
68014 #if 0 /* local variables moved into u.aj */
68015 int i;
68016 Mem *pArg;
68017 sqlite3_context ctx;
68018 sqlite3_value **apVal;
68019 int n;
68020 #endif /* local variables moved into u.aj */
68021
68022 u.aj.n = pOp->p5;
68023 u.aj.apVal = p->apArg;
68024 assert( u.aj.apVal || u.aj.n==0 );
68025 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68026 pOut = &aMem[pOp->p3];
68027 memAboutToChange(p, pOut);
68028
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);
68038 }
68039
68040 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;
68044
68045 /* 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
68047 ** the already allocated buffer instead of allocating a new one.
68048 */
68049 memcpy(&u.aj.ctx.s, pOut, sizeof(Mem));
68050 pOut->flags = MEM_Null;
68051 pOut->xDel = 0;
68052 pOut->zMalloc = 0;
68053 MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
68054
68055 u.aj.ctx.fErrorOrAux = 0;
68056 if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
68057 assert( pOp>aOp );
68058 assert( pOp[-1].p4type==P4_COLLSEQ );
68059 assert( pOp[-1].opcode==OP_CollSeq );
68060 u.aj.ctx.pColl = pOp[-1].p4.pColl;
68061 }
68062 db->lastRowid = lastRowid;
68063 (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */
68064 lastRowid = db->lastRowid;
68065
68066 if( db->mallocFailed ){
68067 /* Even though a malloc() has failed, the implementation of the
68068 ** user function may have called an sqlite3_result_XXX() function
68069 ** to return a value. The following call releases any resources
68070 ** associated with such a value.
68071 */
68072 sqlite3VdbeMemRelease(&u.aj.ctx.s);
68073 goto no_mem;
68074 }
68075
68076 /* 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;
68081 }
68082 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
68083 }
68084
68085 /* Copy the result of the function into register P3 */
68086 sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
68087 assert( pOut->flags==MEM_Null );
68088 memcpy(pOut, &u.aj.ctx.s, sizeof(Mem));
68089 if( sqlite3VdbeMemTooBig(pOut) ){
68090 goto too_big;
68091 }
68092
68093 #if 0
@@ -68135,56 +67687,54 @@
68135 */
68136 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
68137 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
68138 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
68139 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
68140 #if 0 /* local variables moved into u.ak */
68141 i64 iA;
68142 u64 uA;
68143 i64 iB;
68144 u8 op;
68145 #endif /* local variables moved into u.ak */
68146
68147 pIn1 = &aMem[pOp->p1];
68148 pIn2 = &aMem[pOp->p2];
68149 pOut = &aMem[pOp->p3];
68150 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
68151 sqlite3VdbeMemSetNull(pOut);
68152 break;
68153 }
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 );
68163
68164 /* If shifting by a negative amount, shift in the other direction */
68165 if( u.ak.iB<0 ){
68166 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;
68169 }
68170
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;
68179 /* 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);
68181 }
68182 memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA));
68183 }
68184 }
68185 pOut->u.i = u.ak.iA;
68186 MemSetTypeFlag(pOut, MEM_Int);
68187 break;
68188 }
68189
68190 /* Opcode: AddImm P1 P2 * * *
@@ -68434,37 +67984,35 @@
68434 case OP_Ne: /* same as TK_NE, jump, in1, in3 */
68435 case OP_Lt: /* same as TK_LT, jump, in1, in3 */
68436 case OP_Le: /* same as TK_LE, jump, in1, in3 */
68437 case OP_Gt: /* same as TK_GT, jump, in1, in3 */
68438 case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
68439 #if 0 /* local variables moved into u.al */
68440 int res; /* Result of the comparison of pIn1 against pIn3 */
68441 char affinity; /* Affinity to use for comparison */
68442 u16 flags1; /* Copy of initial value of pIn1->flags */
68443 u16 flags3; /* Copy of initial value of pIn3->flags */
68444 #endif /* local variables moved into u.al */
68445
68446 pIn1 = &aMem[pOp->p1];
68447 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 ){
68451 /* One or both operands are NULL */
68452 if( pOp->p5 & SQLITE_NULLEQ ){
68453 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
68454 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68455 ** or not both operands are null.
68456 */
68457 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
68462 ){
68463 u.al.res = 0; /* Results are equal */
68464 }else{
68465 u.al.res = 1; /* Results are not equal */
68466 }
68467 }else{
68468 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68469 ** then the result is always NULL.
68470 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68478,44 +68026,44 @@
68478 }
68479 break;
68480 }
68481 }else{
68482 /* 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);
68487 if( db->mallocFailed ) goto no_mem;
68488 }
68489
68490 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
68491 ExpandBlob(pIn1);
68492 ExpandBlob(pIn3);
68493 u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68494 }
68495 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;
68502 }
68503
68504 if( pOp->p5 & SQLITE_STOREP2 ){
68505 pOut = &aMem[pOp->p2];
68506 memAboutToChange(p, pOut);
68507 MemSetTypeFlag(pOut, MEM_Int);
68508 pOut->u.i = u.al.res;
68509 REGISTER_TRACE(pOp->p2, pOut);
68510 }else if( u.al.res ){
68511 pc = pOp->p2-1;
68512 }
68513
68514 /* 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);
68517 break;
68518 }
68519
68520 /* Opcode: Permutation * * * P4 *
68521 **
@@ -68551,51 +68099,49 @@
68551 ** The comparison is a sort comparison, so NULLs compare equal,
68552 ** NULLs are less than numbers, numbers are less than strings,
68553 ** and strings are less than blobs.
68554 */
68555 case OP_Compare: {
68556 #if 0 /* local variables moved into u.am */
68557 int n;
68558 int i;
68559 int p1;
68560 int p2;
68561 const KeyInfo *pKeyInfo;
68562 int idx;
68563 CollSeq *pColl; /* Collating sequence to use on this term */
68564 int bRev; /* True for DESCENDING sort order */
68565 #endif /* local variables moved into u.am */
68566
68567 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;
68574 #if SQLITE_DEBUG
68575 if( aPermute ){
68576 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 );
68580 }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 );
68583 }
68584 #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);
68595 if( iCompare ){
68596 if( u.am.bRev ) iCompare = -iCompare;
68597 break;
68598 }
68599 }
68600 aPermute = 0;
68601 break;
@@ -68638,39 +68184,37 @@
68638 ** even if the other input is NULL. A NULL and false or two NULLs
68639 ** give a NULL output.
68640 */
68641 case OP_And: /* same as TK_AND, in1, in2, out3 */
68642 case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68643 #if 0 /* local variables moved into u.an */
68644 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68645 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68646 #endif /* local variables moved into u.an */
68647
68648 pIn1 = &aMem[pOp->p1];
68649 if( pIn1->flags & MEM_Null ){
68650 u.an.v1 = 2;
68651 }else{
68652 u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0;
68653 }
68654 pIn2 = &aMem[pOp->p2];
68655 if( pIn2->flags & MEM_Null ){
68656 u.an.v2 = 2;
68657 }else{
68658 u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0;
68659 }
68660 if( pOp->opcode==OP_And ){
68661 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];
68663 }else{
68664 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];
68666 }
68667 pOut = &aMem[pOp->p3];
68668 if( u.an.v1==2 ){
68669 MemSetTypeFlag(pOut, MEM_Null);
68670 }else{
68671 pOut->u.i = u.an.v1;
68672 MemSetTypeFlag(pOut, MEM_Int);
68673 }
68674 break;
68675 }
68676
@@ -68737,25 +68281,23 @@
68737 ** is considered false if it has a numeric value of zero. If the value
68738 ** in P1 is NULL then take the jump if P3 is zero.
68739 */
68740 case OP_If: /* jump, in1 */
68741 case OP_IfNot: { /* jump, in1 */
68742 #if 0 /* local variables moved into u.ao */
68743 int c;
68744 #endif /* local variables moved into u.ao */
68745 pIn1 = &aMem[pOp->p1];
68746 if( pIn1->flags & MEM_Null ){
68747 u.ao.c = pOp->p3;
68748 }else{
68749 #ifdef SQLITE_OMIT_FLOATING_POINT
68750 u.ao.c = sqlite3VdbeIntValue(pIn1)!=0;
68751 #else
68752 u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0;
68753 #endif
68754 if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c;
68755 }
68756 if( u.ao.c ){
68757 pc = pOp->p2-1;
68758 }
68759 break;
68760 }
68761
@@ -68809,11 +68351,10 @@
68809 ** the result is guaranteed to only be used as the argument of a length()
68810 ** or typeof() function, respectively. The loading of large blobs can be
68811 ** skipped for length() and all content loading can be skipped for typeof().
68812 */
68813 case OP_Column: {
68814 #if 0 /* local variables moved into u.ap */
68815 i64 payloadSize64; /* Number of bytes in the record */
68816 int p2; /* column number to retrieve */
68817 VdbeCursor *pC; /* The VDBE cursor */
68818 BtCursor *pCrsr; /* The BTree cursor */
68819 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
@@ -68828,89 +68369,88 @@
68828 u32 offset; /* Offset into the data */
68829 u32 szField; /* Number of bytes in the content of a field */
68830 u32 avail; /* Number of bytes of available data */
68831 u32 t; /* A type code from the record header */
68832 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;
68912 }
68913
68914 /* Make sure a corrupt database has not given us an oversize header.
68915 ** Do this now to avoid an oversize memory allocation.
68916 **
@@ -68918,154 +68458,154 @@
68918 ** types use so much data space that there can only be 4096 and 32 of
68919 ** them, respectively. So the maximum header length results from a
68920 ** 3-byte type for each of the maximum of 32768 columns plus three
68921 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68922 */
68923 if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){
68924 rc = SQLITE_CORRUPT_BKPT;
68925 goto op_column_error;
68926 }
68927 }
68928
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[].
68931 */
68932 if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
68933 /* 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
68935 */
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);
68942 if( rc!=SQLITE_OK ){
68943 goto op_column_error;
68944 }
68945 u.ap.zData = (u8*)u.ap.sMem.z;
68946 }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 );
68956 do{
68957 if( u.ap.zHdr[0]<0x80 ){
68958 u.ap.t = u.ap.zHdr[0];
68959 u.ap.zHdr++;
68960 }else{
68961 u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t);
68962 }
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 */
68968 break;
68969 }
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
68980 /* If we have read more header data than was contained in the header,
68981 ** or if the end of the last field appears to be past the end of the
68982 ** 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
68984 ** with a corrupt database.
68985 */
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)
68989 ){
68990 rc = SQLITE_CORRUPT_BKPT;
68991 goto op_column_error;
68992 }
68993 }
68994
68995 /* 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
68997 ** columns. So the result will be either the default value or a NULL.
68998 */
68999 if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
69000 if( pOp->p4type==P4_MEM ){
69001 sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
69002 }else{
69003 MemSetTypeFlag(u.ap.pDest, MEM_Null);
69004 }
69005 goto op_column_out;
69006 }
69007 }
69008
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
69011 ** all valid.
69012 */
69013 assert( u.ap.p2<u.ap.pC->nHdrParsed );
69014 assert( rc==SQLITE_OK );
69015 if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){
69016 /* This is the common case where the desired content fits on the original
69017 ** 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);
69020 }else{
69021 /* This branch happens only when content is on overflow pages */
69022 u.ap.t = u.ap.aType[u.ap.p2];
69023 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
69026 ){
69027 /* Content is irrelevant for the typeof() function and for
69028 ** the length(X) function if X is a blob. So we might as well use
69029 ** bogus content rather than reading content from disk. NULL works
69030 ** for text and blob and whatever is in the u.ap.payloadSize64 variable
69031 ** will work for everything else. Content is also irrelevant if
69032 ** the content length is 0. */
69033 u.ap.zData = u.ap.t<=13 ? (u8*)&u.ap.payloadSize64 : 0;
69034 u.ap.sMem.zMalloc = 0;
69035 }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);
69040 if( rc!=SQLITE_OK ){
69041 goto op_column_error;
69042 }
69043 u.ap.zData = (u8*)u.ap.sMem.z;
69044 }
69045 sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest);
69046 /* If we dynamically allocated space to hold the data (in the
69047 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
69048 ** dynamically allocated space over to the u.ap.pDest structure.
69049 ** 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;
69058 }
69059 }
69060 u.ap.pDest->enc = encoding;
69061
69062 op_column_out:
69063 rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
69064 op_column_error:
69065 UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69066 REGISTER_TRACE(pOp->p3, u.ap.pDest);
69067 break;
69068 }
69069
69070 /* Opcode: Affinity P1 P2 * P4 *
69071 ** Synopsis: affinity(r[P1@P2])
@@ -69075,24 +68615,22 @@
69075 ** P4 is a string that is P2 characters long. The nth character of the
69076 ** string indicates the column affinity that should be used for the nth
69077 ** memory cell in the range.
69078 */
69079 case OP_Affinity: {
69080 #if 0 /* local variables moved into u.aq */
69081 const char *zAffinity; /* The affinity to be applied */
69082 char cAff; /* A single character of affinity */
69083 #endif /* local variables moved into u.aq */
69084
69085 u.aq.zAffinity = pOp->p4.z;
69086 assert( u.aq.zAffinity!=0 );
69087 assert( u.aq.zAffinity[pOp->p2]==0 );
69088 pIn1 = &aMem[pOp->p1];
69089 while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){
69090 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
69091 assert( memIsValid(pIn1) );
69092 ExpandBlob(pIn1);
69093 applyAffinity(pIn1, u.aq.cAff, encoding);
69094 pIn1++;
69095 }
69096 break;
69097 }
69098
@@ -69111,11 +68649,10 @@
69111 ** macros defined in sqliteInt.h.
69112 **
69113 ** If P4 is NULL then all index fields have the affinity NONE.
69114 */
69115 case OP_MakeRecord: {
69116 #if 0 /* local variables moved into u.ar */
69117 u8 *zNewRecord; /* A buffer to hold the data for the new record */
69118 Mem *pRec; /* The new record */
69119 u64 nData; /* Number of bytes of data space */
69120 int nHdr; /* Number of bytes of header space */
69121 i64 nByte; /* Data space required for this record */
@@ -69125,106 +68662,123 @@
69125 Mem *pData0; /* First field to be combined into the record */
69126 Mem *pLast; /* Last field of the record */
69127 int nField; /* Number of fields in the record */
69128 char *zAffinity; /* The affinity string for the record */
69129 int file_format; /* File format to use for encoding */
69130 int i; /* Space used in zNewRecord[] */
 
69131 int len; /* Length of a field */
69132 #endif /* local variables moved into u.ar */
69133
69134 /* Assuming the record contains N fields, the record format looks
69135 ** like this:
69136 **
69137 ** ------------------------------------------------------------------------
69138 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
69139 ** ------------------------------------------------------------------------
69140 **
69141 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
69142 ** and so froth.
69143 **
69144 ** Each type field is a varint representing the serial type of the
69145 ** corresponding data element (see sqlite3VdbeSerialType()). The
69146 ** hdr-size field is also a varint which is the offset from the beginning
69147 ** of the record to data0.
69148 */
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;
69159
69160 /* Identify the output register */
69161 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
69162 pOut = &aMem[pOp->p3];
69163 memAboutToChange(p, pOut);
 
 
 
 
 
 
 
 
 
 
69164
69165 /* Loop through the elements that will make up the record to figure
69166 ** out how much space is required for the new record.
69167 */
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 }
69188
69189 /* 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++;
 
 
 
 
 
 
 
69193 }
69194 u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero;
69195 if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
69196 goto too_big;
69197 }
69198
69199 /* Make sure the output register has a buffer large enough to store
69200 ** the new record. The output register (pOp->p3) is not allowed to
69201 ** be one of the input registers (because the following call to
69202 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
69203 */
69204 if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){
69205 goto no_mem;
69206 }
69207 u.ar.zNewRecord = (u8 *)pOut->z;
69208
69209 /* 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 );
 
 
69219
69220 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69221 pOut->n = (int)u.ar.nByte;
69222 pOut->flags = MEM_Blob | MEM_Dyn;
69223 pOut->xDel = 0;
69224 if( u.ar.nZero ){
69225 pOut->u.nZero = u.ar.nZero;
69226 pOut->flags |= MEM_Zero;
69227 }
69228 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
69229 REGISTER_TRACE(pOp->p3, pOut);
69230 UPDATE_MAX_BLOBSIZE(pOut);
@@ -69237,19 +68791,18 @@
69237 ** Store the number of entries (an integer value) in the table or index
69238 ** opened by cursor P1 in register P2
69239 */
69240 #ifndef SQLITE_OMIT_BTREECOUNT
69241 case OP_Count: { /* out2-prerelease */
69242 #if 0 /* local variables moved into u.as */
69243 i64 nEntry;
69244 BtCursor *pCrsr;
69245 #endif /* local variables moved into u.as */
69246
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;
 
69251 break;
69252 }
69253 #endif
69254
69255 /* Opcode: Savepoint P1 * * P4 *
@@ -69257,43 +68810,41 @@
69257 ** Open, release or rollback the savepoint named by parameter P4, depending
69258 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
69259 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
69260 */
69261 case OP_Savepoint: {
69262 #if 0 /* local variables moved into u.at */
69263 int p1; /* Value of P1 operand */
69264 char *zName; /* Name of savepoint */
69265 int nName;
69266 Savepoint *pNew;
69267 Savepoint *pSavepoint;
69268 Savepoint *pTmp;
69269 int iSavepoint;
69270 int ii;
69271 #endif /* local variables moved into u.at */
69272
69273 u.at.p1 = pOp->p1;
69274 u.at.zName = pOp->p4.z;
69275
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.
69278 */
69279 assert( db->pSavepoint==0 || db->autoCommit==0 );
69280 assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK );
69281 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
69282 assert( checkSavepointCount(db) );
69283 assert( p->bIsReader );
69284
69285 if( u.at.p1==SAVEPOINT_BEGIN ){
69286 if( db->nVdbeWrite>0 ){
69287 /* A new savepoint cannot be created if there are active write
69288 ** statements (i.e. open read/write incremental blob handles).
69289 */
69290 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
69291 "SQL statements in progress");
69292 rc = SQLITE_BUSY;
69293 }else{
69294 u.at.nName = sqlite3Strlen30(u.at.zName);
69295
69296 #ifndef SQLITE_OMIT_VIRTUALTABLE
69297 /* This call is Ok even if this savepoint is actually a transaction
69298 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
69299 ** If this is a transaction savepoint being opened, it is guaranteed
@@ -69303,62 +68854,62 @@
69303 db->nStatement+db->nSavepoint);
69304 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69305 #endif
69306
69307 /* 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
69313 /* If there is no open transaction, then mark this as a special
69314 ** "transaction savepoint". */
69315 if( db->autoCommit ){
69316 db->autoCommit = 0;
69317 db->isTransactionSavepoint = 1;
69318 }else{
69319 db->nSavepoint++;
69320 }
69321
69322 /* 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;
69327 }
69328 }
69329 }else{
69330 u.at.iSavepoint = 0;
69331
69332 /* Find the named savepoint. If there is no such savepoint, then an
69333 ** an error is returned to the user. */
69334 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
69338 ){
69339 u.at.iSavepoint++;
69340 }
69341 if( !u.at.pSavepoint ){
69342 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName);
69343 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
69346 ** active write statements.
69347 */
69348 sqlite3SetString(&p->zErrMsg, db,
69349 "cannot release savepoint - SQL statements in progress"
69350 );
69351 rc = SQLITE_BUSY;
69352 }else{
69353
69354 /* 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.
69357 */
69358 int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint;
69359 if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){
69360 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69361 goto vdbe_return;
69362 }
69363 db->autoCommit = 1;
69364 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69368,56 +68919,56 @@
69368 goto vdbe_return;
69369 }
69370 db->isTransactionSavepoint = 0;
69371 rc = p->rc;
69372 }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);
69377 }
69378 }
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);
69381 if( rc!=SQLITE_OK ){
69382 goto abort_due_to_error;
69383 }
69384 }
69385 if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
69386 sqlite3ExpirePreparedStatements(db);
69387 sqlite3ResetAllSchemasOfConnection(db);
69388 db->flags = (db->flags | SQLITE_InternChanges);
69389 }
69390 }
69391
69392 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
69393 ** 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);
69398 db->nSavepoint--;
69399 }
69400
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
69403 ** constraint violations present in the database to the value stored
69404 ** 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);
69409 if( !isTransaction ){
69410 db->nSavepoint--;
69411 }
69412 }else{
69413 db->nDeferredCons = u.at.pSavepoint->nDeferredCons;
69414 db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons;
69415 }
69416
69417 if( !isTransaction ){
69418 rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint);
69419 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69420 }
69421 }
69422 }
69423
@@ -69432,54 +68983,52 @@
69432 ** there are active writing VMs or active VMs that use shared cache.
69433 **
69434 ** This instruction causes the VM to halt.
69435 */
69436 case OP_AutoCommit: {
69437 #if 0 /* local variables moved into u.au */
69438 int desiredAutoCommit;
69439 int iRollback;
69440 int turnOnAC;
69441 #endif /* local variables moved into u.au */
69442
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 );
69448 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
69449 assert( p->bIsReader );
69450
69451 #if 0
69452 if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){
69453 /* If this instruction implements a ROLLBACK and other VMs are
69454 ** still running, and a transaction is active, return an error indicating
69455 ** that the other VMs must complete first.
69456 */
69457 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
69458 "SQL statements in progress");
69459 rc = SQLITE_BUSY;
69460 }else
69461 #endif
69462 if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){
69463 /* If this instruction implements a COMMIT and other VMs are writing
69464 ** return an error indicating that the other VMs must complete first.
69465 */
69466 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
69467 "SQL statements in progress");
69468 rc = SQLITE_BUSY;
69469 }else if( u.au.desiredAutoCommit!=db->autoCommit ){
69470 if( u.au.iRollback ){
69471 assert( u.au.desiredAutoCommit==1 );
69472 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69473 db->autoCommit = 1;
69474 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69475 goto vdbe_return;
69476 }else{
69477 db->autoCommit = (u8)u.au.desiredAutoCommit;
69478 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
69479 p->pc = pc;
69480 db->autoCommit = (u8)(1-u.au.desiredAutoCommit);
69481 p->rc = rc = SQLITE_BUSY;
69482 goto vdbe_return;
69483 }
69484 }
69485 assert( db->nStatement==0 );
@@ -69490,14 +69039,14 @@
69490 rc = SQLITE_ERROR;
69491 }
69492 goto vdbe_return;
69493 }else{
69494 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":
69497 "cannot commit - no transaction is active"));
69498
69499 rc = SQLITE_ERROR;
69500 }
69501 break;
69502 }
69503
@@ -69531,48 +69080,46 @@
69531 ** will automatically commit when the VDBE halts.
69532 **
69533 ** If P2 is zero, then a read-lock is obtained on the database file.
69534 */
69535 case OP_Transaction: {
69536 #if 0 /* local variables moved into u.av */
69537 Btree *pBt;
69538 #endif /* local variables moved into u.av */
69539
69540 assert( p->bIsReader );
69541 assert( p->readOnly==0 || pOp->p2==0 );
69542 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69543 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69544 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
69545 rc = SQLITE_READONLY;
69546 goto abort_due_to_error;
69547 }
69548 u.av.pBt = db->aDb[pOp->p1].pBt;
69549
69550 if( u.av.pBt ){
69551 rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2);
69552 if( rc==SQLITE_BUSY ){
69553 p->pc = pc;
69554 p->rc = rc = SQLITE_BUSY;
69555 goto vdbe_return;
69556 }
69557 if( rc!=SQLITE_OK ){
69558 goto abort_due_to_error;
69559 }
69560
69561 if( pOp->p2 && p->usesStmtJournal
69562 && (db->autoCommit==0 || db->nVdbeRead>1)
69563 ){
69564 assert( sqlite3BtreeIsInTrans(u.av.pBt) );
69565 if( p->iStatement==0 ){
69566 assert( db->nStatement>=0 && db->nSavepoint>=0 );
69567 db->nStatement++;
69568 p->iStatement = db->nSavepoint + db->nStatement;
69569 }
69570
69571 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
69572 if( rc==SQLITE_OK ){
69573 rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement);
69574 }
69575
69576 /* Store the current value of the database handles deferred constraint
69577 ** counter. If the statement transaction needs to be rolled back,
69578 ** the value of this counter needs to be restored too. */
@@ -69594,26 +69141,24 @@
69594 ** There must be a read-lock on the database (either a transaction
69595 ** must be started or there must be an open cursor) before
69596 ** executing this instruction.
69597 */
69598 case OP_ReadCookie: { /* out2-prerelease */
69599 #if 0 /* local variables moved into u.aw */
69600 int iMeta;
69601 int iDb;
69602 int iCookie;
69603 #endif /* local variables moved into u.aw */
69604
69605 assert( p->bIsReader );
69606 u.aw.iDb = pOp->p1;
69607 u.aw.iCookie = pOp->p3;
69608 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 );
69612
69613 sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta);
69614 pOut->u.i = u.aw.iMeta;
69615 break;
69616 }
69617
69618 /* Opcode: SetCookie P1 P2 P3 * *
69619 **
@@ -69624,31 +69169,29 @@
69624 ** database file used to store temporary tables.
69625 **
69626 ** A transaction must be started before executing this opcode.
69627 */
69628 case OP_SetCookie: { /* in3 */
69629 #if 0 /* local variables moved into u.ax */
69630 Db *pDb;
69631 #endif /* local variables moved into u.ax */
69632 assert( pOp->p2<SQLITE_N_BTREE_META );
69633 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69634 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69635 assert( p->readOnly==0 );
69636 u.ax.pDb = &db->aDb[pOp->p1];
69637 assert( u.ax.pDb->pBt!=0 );
69638 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69639 pIn3 = &aMem[pOp->p3];
69640 sqlite3VdbeMemIntegerify(pIn3);
69641 /* See note about index shifting on OP_ReadCookie */
69642 rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i);
69643 if( pOp->p2==BTREE_SCHEMA_VERSION ){
69644 /* When the schema cookie changes, record the new cookie internally */
69645 u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69646 db->flags |= SQLITE_InternChanges;
69647 }else if( pOp->p2==BTREE_FILE_FORMAT ){
69648 /* Record changes in the file format */
69649 u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i;
69650 }
69651 if( pOp->p1==1 ){
69652 /* Invalidate all prepared statements whenever the TEMP database
69653 ** schema is changed. Ticket #1644 */
69654 sqlite3ExpirePreparedStatements(db);
@@ -69674,44 +69217,42 @@
69674 ** Either a transaction needs to have been started or an OP_Open needs
69675 ** to be executed (to establish a read lock) before this opcode is
69676 ** invoked.
69677 */
69678 case OP_VerifyCookie: {
69679 #if 0 /* local variables moved into u.ay */
69680 int iMeta;
69681 int iGen;
69682 Btree *pBt;
69683 #endif /* local variables moved into u.ay */
69684
69685 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69686 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69687 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69688 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;
69693 }else{
69694 u.ay.iGen = u.ay.iMeta = 0;
69695 }
69696 if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){
69697 sqlite3DbFree(db, p->zErrMsg);
69698 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69699 /* If the schema-cookie from the database file matches the cookie
69700 ** stored with the in-memory representation of the schema, do
69701 ** not reload the schema from the database file.
69702 **
69703 ** If virtual-tables are in use, this is not just an optimization.
69704 ** Often, v-tables store their data in other SQLite tables, which
69705 ** are queried from within xNext() and other v-table methods using
69706 ** prepared queries. If such a query is out-of-date, we do not want to
69707 ** discard the database schema, as the user code implementing the
69708 ** v-table would have to be ready for the sqlite3_vtab structure itself
69709 ** to be invalidated whenever sqlite3_step() is called from within
69710 ** a v-table method.
69711 */
69712 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){
69713 sqlite3ResetOneSchema(db, pOp->p1);
69714 }
69715
69716 p->expired = 1;
69717 rc = SQLITE_SCHEMA;
@@ -69770,20 +69311,18 @@
69770 **
69771 ** See also OpenRead.
69772 */
69773 case OP_OpenRead:
69774 case OP_OpenWrite: {
69775 #if 0 /* local variables moved into u.az */
69776 int nField;
69777 KeyInfo *pKeyInfo;
69778 int p2;
69779 int iDb;
69780 int wrFlag;
69781 Btree *pX;
69782 VdbeCursor *pCur;
69783 Db *pDb;
69784 #endif /* local variables moved into u.az */
69785
69786 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
69787 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
69788 assert( p->bIsReader );
69789 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69791,74 +69330,74 @@
69791 if( p->expired ){
69792 rc = SQLITE_ABORT;
69793 break;
69794 }
69795
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 );
69805 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;
69810 }
69811 }else{
69812 u.az.wrFlag = 0;
69813 }
69814 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];
69818 assert( memIsValid(pIn2) );
69819 assert( (pIn2->flags & MEM_Int)!=0 );
69820 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.
69824 ** If there were a failure, the prepared statement would have halted
69825 ** before reaching this instruction. */
69826 if( NEVER(u.az.p2<2) ) {
69827 rc = SQLITE_CORRUPT_BKPT;
69828 goto abort_due_to_error;
69829 }
69830 }
69831 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;
69836 }else if( pOp->p4type==P4_INT32 ){
69837 u.az.nField = pOp->p4.i;
69838 }
69839 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;
69848 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69849 sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69850
69851 /* Since it performs no memory allocation or IO, the only value that
69852 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69853 assert( rc==SQLITE_OK );
69854
69855 /* Set the VdbeCursor.isTable variable. Previous versions of
69856 ** SQLite used to check if the root-page flags were sane at this point
69857 ** 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;
69860 break;
69861 }
69862
69863 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69864 ** Synopsis: nColumn=P2
@@ -69886,55 +69425,53 @@
69886 ** by this opcode will be used for automatically created transient
69887 ** indices in joins.
69888 */
69889 case OP_OpenAutoindex:
69890 case OP_OpenEphemeral: {
69891 #if 0 /* local variables moved into u.ba */
69892 VdbeCursor *pCx;
69893 KeyInfo *pKeyInfo;
69894 #endif /* local variables moved into u.ba */
69895
69896 static const int vfsFlags =
69897 SQLITE_OPEN_READWRITE |
69898 SQLITE_OPEN_CREATE |
69899 SQLITE_OPEN_EXCLUSIVE |
69900 SQLITE_OPEN_DELETEONCLOSE |
69901 SQLITE_OPEN_TRANSIENT_DB;
69902 assert( pOp->p1>=0 );
69903 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,
69908 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
69909 if( rc==SQLITE_OK ){
69910 rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
69911 }
69912 if( rc==SQLITE_OK ){
69913 /* If a transient index is required, create it by calling
69914 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
69915 ** opening it. If a transient table is required, just use the
69916 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69917 */
69918 if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69919 int pgno;
69920 assert( pOp->p4type==P4_KEYINFO );
69921 rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69922 if( rc==SQLITE_OK ){
69923 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;
69933 }
69934 }
69935 u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69936 break;
69937 }
69938
69939 /* Opcode: SorterOpen P1 * * P4 *
69940 **
@@ -69941,22 +69478,20 @@
69941 ** This opcode works like OP_OpenEphemeral except that it opens
69942 ** a transient index that is specifically designed to sort large
69943 ** tables using an external merge-sort algorithm.
69944 */
69945 case OP_SorterOpen: {
69946 #if 0 /* local variables moved into u.bb */
69947 VdbeCursor *pCx;
69948 #endif /* local variables moved into u.bb */
69949
69950 assert( pOp->p1>=0 );
69951 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);
69958 break;
69959 }
69960
69961 /* Opcode: OpenPseudo P1 P2 P3 * P5
69962 ** Synopsis: content in r[P2@P3]
@@ -69974,22 +69509,20 @@
69974 **
69975 ** P3 is the number of fields in the records that will be stored by
69976 ** the pseudo-table.
69977 */
69978 case OP_OpenPseudo: {
69979 #if 0 /* local variables moved into u.bc */
69980 VdbeCursor *pCx;
69981 #endif /* local variables moved into u.bc */
69982
69983 assert( pOp->p1>=0 );
69984 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;
69991 break;
69992 }
69993
69994 /* Opcode: Close P1 * * * *
69995 **
@@ -70061,39 +69594,37 @@
70061 */
70062 case OP_SeekLt: /* jump, in3 */
70063 case OP_SeekLe: /* jump, in3 */
70064 case OP_SeekGe: /* jump, in3 */
70065 case OP_SeekGt: { /* jump, in3 */
70066 #if 0 /* local variables moved into u.bd */
70067 int res;
70068 int oc;
70069 VdbeCursor *pC;
70070 UnpackedRecord r;
70071 int nField;
70072 i64 iKey; /* The rowid we are to seek to */
70073 #endif /* local variables moved into u.bd */
70074
70075 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70076 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 );
70080 assert( OP_SeekLe == OP_SeekLt+1 );
70081 assert( OP_SeekGe == OP_SeekLt+2 );
70082 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 ){
70088 /* The input value in P3 might be of any type: integer, real, string,
70089 ** blob, or NULL. But it needs to be an integer before we can do
70090 ** the seek, so covert it. */
70091 pIn3 = &aMem[pOp->p3];
70092 applyNumericAffinity(pIn3);
70093 u.bd.iKey = sqlite3VdbeIntValue(pIn3);
70094 u.bd.pC->rowidIsValid = 0;
70095
70096 /* If the P3 value could not be converted into an integer without
70097 ** loss of information, then special processing is required... */
70098 if( (pIn3->flags & MEM_Int)==0 ){
70099 if( (pIn3->flags & MEM_Real)==0 ){
@@ -70101,100 +69632,100 @@
70101 ** then the seek is not possible, so jump to P2 */
70102 pc = pOp->p2 - 1;
70103 break;
70104 }
70105
70106 /* If the approximation u.bd.iKey is larger than the actual real search
70107 ** term, substitute >= for > and < for <=. e.g. if the search term
70108 ** is 4.9 and the integer approximation 5:
70109 **
70110 ** (x > 4.9) -> (x >= 5)
70111 ** (x <= 4.9) -> (x < 5)
70112 */
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 ){
70196 pc = pOp->p2 - 1;
70197 }
70198 break;
70199 }
70200
@@ -70207,24 +69738,22 @@
70207 ** This is actually a deferred seek. Nothing actually happens until
70208 ** the cursor is used to read a record. That way, if no reads
70209 ** occur, no unnecessary I/O happens.
70210 */
70211 case OP_Seek: { /* in2 */
70212 #if 0 /* local variables moved into u.be */
70213 VdbeCursor *pC;
70214 #endif /* local variables moved into u.be */
70215
70216 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;
70222 pIn2 = &aMem[pOp->p2];
70223 u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
70224 u.be.pC->rowidIsValid = 0;
70225 u.be.pC->deferredMoveto = 1;
70226 break;
70227 }
70228
70229
70230 /* Opcode: Found P1 P2 P3 P4 *
@@ -70275,85 +69804,83 @@
70275 ** See also: NotFound, Found, NotExists
70276 */
70277 case OP_NoConflict: /* jump, in3 */
70278 case OP_NotFound: /* jump, in3 */
70279 case OP_Found: { /* jump, in3 */
70280 #if 0 /* local variables moved into u.bf */
70281 int alreadyExists;
70282 int ii;
70283 VdbeCursor *pC;
70284 int res;
70285 char *pFree;
70286 UnpackedRecord *pIdxKey;
70287 UnpackedRecord r;
70288 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
70289 #endif /* local variables moved into u.bf */
70290
70291 #ifdef SQLITE_TEST
70292 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
70293 #endif
70294
70295 u.bf.alreadyExists = 0;
70296 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70297 assert( pOp->p4type==P4_INT32 );
70298 u.bf.pC = p->apCsr[pOp->p1];
70299 assert( u.bf.pC!=0 );
70300 pIn3 = &aMem[pOp->p3];
70301 assert( u.bf.pC->pCursor!=0 );
70302 assert( u.bf.pC->isTable==0 );
 
70303 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;
70307 #ifdef SQLITE_DEBUG
70308 {
70309 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]);
70313 }
70314 }
70315 #endif
70316 u.bf.r.flags = UNPACKED_PREFIX_MATCH;
70317 u.bf.pIdxKey = &u.bf.r;
70318 }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;
70323 assert( pIn3->flags & MEM_Blob );
70324 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;
70327 }
70328 if( pOp->opcode==OP_NoConflict ){
70329 /* For the OP_NoConflict opcode, take the jump if any of the
70330 ** input fields are NULL, since any key with a NULL will not
70331 ** 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 ){
70334 pc = pOp->p2 - 1;
70335 break;
70336 }
70337 }
70338 }
70339 rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res);
70340 if( pOp->p4.i==0 ){
70341 sqlite3DbFree(db, u.bf.pFree);
70342 }
70343 if( rc!=SQLITE_OK ){
70344 break;
70345 }
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;
70351 if( pOp->opcode==OP_Found ){
70352 if( u.bf.alreadyExists ) pc = pOp->p2 - 1;
70353 }else{
70354 if( !u.bf.alreadyExists ) pc = pOp->p2 - 1;
70355 }
70356 break;
70357 }
70358
70359 /* Opcode: NotExists P1 P2 P3 * *
@@ -70369,39 +69896,37 @@
70369 ** (with arbitrary multi-value keys).
70370 **
70371 ** See also: Found, NotFound, NoConflict
70372 */
70373 case OP_NotExists: { /* jump, in3 */
70374 #if 0 /* local variables moved into u.bg */
70375 VdbeCursor *pC;
70376 BtCursor *pCrsr;
70377 int res;
70378 u64 iKey;
70379 #endif /* local variables moved into u.bg */
70380
70381 pIn3 = &aMem[pOp->p3];
70382 assert( pIn3->flags & MEM_Int );
70383 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 ){
70399 pc = pOp->p2 - 1;
70400 assert( u.bg.pC->rowidIsValid==0 );
70401 }
70402 u.bg.pC->seekResult = u.bg.res;
70403 break;
70404 }
70405
70406 /* Opcode: Sequence P1 P2 * * *
70407 ** Synopsis: r[P2]=rowid
@@ -70433,25 +69958,23 @@
70433 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
70434 ** generated record number. This P3 mechanism is used to help implement the
70435 ** AUTOINCREMENT feature.
70436 */
70437 case OP_NewRowid: { /* out2-prerelease */
70438 #if 0 /* local variables moved into u.bh */
70439 i64 v; /* The new rowid */
70440 VdbeCursor *pC; /* Cursor of table to get the new rowid */
70441 int res; /* Result of an sqlite3BtreeLast() */
70442 int cnt; /* Counter to limit the number of searches */
70443 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
70444 VdbeFrame *pFrame; /* Root frame of VDBE */
70445 #endif /* local variables moved into u.bh */
70446
70447 u.bh.v = 0;
70448 u.bh.res = 0;
70449 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) ){
70453 /* The zero initialization above is all that is needed */
70454 }else{
70455 /* The next rowid or record number (different terms for the same
70456 ** thing) is obtained in a two-step algorithm.
70457 **
@@ -70463,11 +69986,11 @@
70463 ** The second algorithm is to select a rowid at random and see if
70464 ** it already exists in the table. If it does not exist, we have
70465 ** succeeded. If the random rowid does exist, we select a new one
70466 ** and try again, up to 100 times.
70467 */
70468 assert( u.bh.pC->isTable );
70469
70470 #ifdef SQLITE_32BIT_ROWID
70471 # define MAX_ROWID 0x7fffffff
70472 #else
70473 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70475,101 +69998,101 @@
70475 ** to provide the constant while making all compilers happy.
70476 */
70477 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70478 #endif
70479
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);
70484 if( rc!=SQLITE_OK ){
70485 goto abort_due_to_error;
70486 }
70487 if( u.bh.res ){
70488 u.bh.v = 1; /* IMP: R-61914-48074 */
70489 }else{
70490 assert( sqlite3BtreeCursorIsValid(u.bh.pC->pCursor) );
70491 rc = sqlite3BtreeKeySize(u.bh.pC->pCursor, &u.bh.v);
70492 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70493 if( u.bh.v>=MAX_ROWID ){
70494 u.bh.pC->useRandomRowid = 1;
70495 }else{
70496 u.bh.v++; /* IMP: R-29538-34987 */
70497 }
70498 }
70499 }
70500
70501 #ifndef SQLITE_OMIT_AUTOINCREMENT
70502 if( pOp->p3 ){
70503 /* Assert that P3 is a valid memory cell. */
70504 assert( pOp->p3>0 );
70505 if( p->pFrame ){
70506 for(u.bh.pFrame=p->pFrame; u.bh.pFrame->pParent; u.bh.pFrame=u.bh.pFrame->pParent);
70507 /* 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];
70510 }else{
70511 /* Assert that P3 is a valid memory cell. */
70512 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 ){
70522 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70523 goto abort_due_to_error;
70524 }
70525 if( u.bh.v<u.bh.pMem->u.i+1 ){
70526 u.bh.v = u.bh.pMem->u.i + 1;
70527 }
70528 u.bh.pMem->u.i = u.bh.v;
70529 }
70530 #endif
70531
70532 sqlite3BtreeSetCachedRowid(u.bh.pC->pCursor, u.bh.v<MAX_ROWID ? u.bh.v+1 : 0);
70533 }
70534 if( u.bh.pC->useRandomRowid ){
70535 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70536 ** largest possible integer (9223372036854775807) then the database
70537 ** engine starts picking positive candidate ROWIDs at random until
70538 ** it finds one that is not previously used. */
70539 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
70540 ** an AUTOINCREMENT table. */
70541 /* 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)){
70550 /* collision - try another random rowid */
70551 sqlite3_randomness(sizeof(u.bh.v), &u.bh.v);
70552 if( u.bh.cnt<5 ){
70553 /* try "small" random rowids for the initial attempts */
70554 u.bh.v &= 0xffffff;
70555 }else{
70556 u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70557 }
70558 u.bh.v++; /* ensure non-zero */
70559 }
70560 if( rc==SQLITE_OK && u.bh.res==0 ){
70561 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
70562 goto abort_due_to_error;
70563 }
70564 assert( u.bh.v>0 ); /* EV: R-40812-03570 */
70565 }
70566 u.bh.pC->rowidIsValid = 0;
70567 u.bh.pC->deferredMoveto = 0;
70568 u.bh.pC->cacheStatus = CACHE_STALE;
70569 }
70570 pOut->u.i = u.bh.v;
70571 break;
70572 }
70573
70574 /* Opcode: Insert P1 P2 P3 P4 P5
70575 ** Synopsis: intkey=r[P3] data=r[P2]
@@ -70617,74 +70140,72 @@
70617 ** This works exactly like OP_Insert except that the key is the
70618 ** integer value P3, not the value of the integer stored in register P3.
70619 */
70620 case OP_Insert:
70621 case OP_InsertInt: {
70622 #if 0 /* local variables moved into u.bi */
70623 Mem *pData; /* MEM cell holding data for the record to be inserted */
70624 Mem *pKey; /* MEM cell holding key for the record */
70625 i64 iKey; /* The integer ROWID or key for the record to be inserted */
70626 VdbeCursor *pC; /* Cursor to table into which insert is written */
70627 int nZero; /* Number of zero-bytes to append */
70628 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
70629 const char *zDb; /* database name - used by the update hook */
70630 const char *zTbl; /* Table name - used by the opdate hook */
70631 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
70632 #endif /* local variables moved into u.bi */
70633
70634 u.bi.pData = &aMem[pOp->p2];
70635 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);
70643
70644 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;
70650 }else{
70651 assert( pOp->opcode==OP_InsertInt );
70652 u.bi.iKey = pOp->p3;
70653 }
70654
70655 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
70673 );
70674 u.bi.pC->rowidIsValid = 0;
70675 u.bi.pC->deferredMoveto = 0;
70676 u.bi.pC->cacheStatus = CACHE_STALE;
70677
70678 /* Invoke the update-hook if required. */
70679 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 );
70686 }
70687 break;
70688 }
70689
70690 /* Opcode: Delete P1 P2 * P4 *
@@ -70706,41 +70227,39 @@
70706 ** pointing to. The update hook will be invoked, if it exists.
70707 ** If P4 is not NULL then the P1 cursor must have been positioned
70708 ** using OP_NotFound prior to invoking this opcode.
70709 */
70710 case OP_Delete: {
70711 #if 0 /* local variables moved into u.bj */
70712 i64 iKey;
70713 VdbeCursor *pC;
70714 #endif /* local variables moved into u.bj */
70715
70716 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 */
70721
70722 /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
70723 ** 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
70725 ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
70726 ** below is always a no-op and cannot fail. We will run it anyhow, though,
70727 ** to guard against future changes to the code generator.
70728 **/
70729 assert( u.bj.pC->deferredMoveto==0 );
70730 rc = sqlite3VdbeCursorMoveto(u.bj.pC);
70731 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70732
70733 sqlite3BtreeSetCachedRowid(u.bj.pC->pCursor, 0);
70734 rc = sqlite3BtreeDelete(u.bj.pC->pCursor);
70735 u.bj.pC->cacheStatus = CACHE_STALE;
70736
70737 /* Invoke the update-hook if required. */
70738 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && u.bj.pC->isTable ){
70739 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 );
70742 }
70743 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
70744 break;
70745 }
70746 /* Opcode: ResetCount * * * * *
@@ -70770,23 +70289,21 @@
70770 **
70771 ** Fall through to next instruction if the two records compare equal to
70772 ** each other. Jump to P2 if they are different.
70773 */
70774 case OP_SorterCompare: {
70775 #if 0 /* local variables moved into u.bk */
70776 VdbeCursor *pC;
70777 int res;
70778 int nIgnore;
70779 #endif /* local variables moved into u.bk */
70780
70781 u.bk.pC = p->apCsr[pOp->p1];
70782 assert( isSorter(u.bk.pC) );
70783 assert( pOp->p4type==P4_INT32 );
70784 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 ){
70788 pc = pOp->p2-1;
70789 }
70790 break;
70791 };
70792
@@ -70794,18 +70311,16 @@
70794 ** Synopsis: r[P2]=data
70795 **
70796 ** Write into register P2 the current sorter data for sorter cursor P1.
70797 */
70798 case OP_SorterData: {
70799 #if 0 /* local variables moved into u.bl */
70800 VdbeCursor *pC;
70801 #endif /* local variables moved into u.bl */
70802
70803 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);
70807 break;
70808 }
70809
70810 /* Opcode: RowData P1 P2 * * *
70811 ** Synopsis: r[P2]=data
@@ -70829,66 +70344,64 @@
70829 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70830 ** of a real table, not a pseudo-table.
70831 */
70832 case OP_RowKey:
70833 case OP_RowData: {
70834 #if 0 /* local variables moved into u.bm */
70835 VdbeCursor *pC;
70836 BtCursor *pCrsr;
70837 u32 n;
70838 i64 n64;
70839 #endif /* local variables moved into u.bm */
70840
70841 pOut = &aMem[pOp->p2];
70842 memAboutToChange(p, pOut);
70843
70844 /* Note that RowKey and RowData are really exactly the same instruction */
70845 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) );
70856
70857 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
70858 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
70859 ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
70860 ** a no-op and can never fail. But we leave it in place as a safety.
70861 */
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);
70890 }
70891 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
70892 UPDATE_MAX_BLOBSIZE(pOut);
70893 REGISTER_TRACE(pOp->p2, pOut);
70894 break;
@@ -70903,46 +70416,44 @@
70903 ** P1 can be either an ordinary table or a virtual table. There used to
70904 ** be a separate OP_VRowid opcode for use with virtual tables, but this
70905 ** one opcode now works for both table types.
70906 */
70907 case OP_Rowid: { /* out2-prerelease */
70908 #if 0 /* local variables moved into u.bn */
70909 VdbeCursor *pC;
70910 i64 v;
70911 sqlite3_vtab *pVtab;
70912 const sqlite3_module *pModule;
70913 #endif /* local variables moved into u.bn */
70914
70915 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 ){
70920 pOut->flags = MEM_Null;
70921 break;
70922 }else if( u.bn.pC->deferredMoveto ){
70923 u.bn.v = u.bn.pC->movetoTarget;
70924 #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);
70931 #endif /* SQLITE_OMIT_VIRTUALTABLE */
70932 }else{
70933 assert( u.bn.pC->pCursor!=0 );
70934 rc = sqlite3VdbeCursorMoveto(u.bn.pC);
70935 if( rc ) goto abort_due_to_error;
70936 if( u.bn.pC->rowidIsValid ){
70937 u.bn.v = u.bn.pC->lastRowid;
70938 }else{
70939 rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v);
70940 assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
70941 }
70942 }
70943 pOut->u.i = u.bn.v;
70944 break;
70945 }
70946
70947 /* Opcode: NullRow P1 * * * *
70948 **
@@ -70949,23 +70460,21 @@
70949 ** Move the cursor P1 to a null row. Any OP_Column operations
70950 ** that occur while the cursor is on the null row will always
70951 ** write a NULL.
70952 */
70953 case OP_NullRow: {
70954 #if 0 /* local variables moved into u.bo */
70955 VdbeCursor *pC;
70956 #endif /* local variables moved into u.bo */
70957
70958 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);
70967 }
70968 break;
70969 }
70970
70971 /* Opcode: Last P1 P2 * * *
@@ -70975,28 +70484,26 @@
70975 ** If the table or index is empty and P2>0, then jump immediately to P2.
70976 ** If P2 is 0 or if the table or index is not empty, fall through
70977 ** to the following instruction.
70978 */
70979 case OP_Last: { /* jump */
70980 #if 0 /* local variables moved into u.bp */
70981 VdbeCursor *pC;
70982 BtCursor *pCrsr;
70983 int res;
70984 #endif /* local variables moved into u.bp */
70985
70986 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 ){
70998 pc = pOp->p2 - 1;
70999 }
71000 break;
71001 }
71002
@@ -71029,34 +70536,32 @@
71029 ** If the table or index is empty and P2>0, then jump immediately to P2.
71030 ** If P2 is 0 or if the table or index is not empty, fall through
71031 ** to the following instruction.
71032 */
71033 case OP_Rewind: { /* jump */
71034 #if 0 /* local variables moved into u.bq */
71035 VdbeCursor *pC;
71036 BtCursor *pCrsr;
71037 int res;
71038 #endif /* local variables moved into u.bq */
71039
71040 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);
71047 }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;
71056 assert( pOp->p2>0 && pOp->p2<p->nOp );
71057 if( u.bq.res ){
71058 pc = pOp->p2 - 1;
71059 }
71060 break;
71061 }
71062
@@ -71103,49 +70608,47 @@
71103 **
71104 ** This opcode works just like OP_Prev except that if cursor P1 is not
71105 ** open it behaves a no-op.
71106 */
71107 case OP_SorterNext: { /* jump */
71108 #if 0 /* local variables moved into u.br */
71109 VdbeCursor *pC;
71110 int res;
71111 #endif /* local variables moved into u.br */
71112
71113 u.br.pC = p->apCsr[pOp->p1];
71114 assert( isSorter(u.br.pC) );
71115 rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res);
71116 goto next_tail;
71117 case OP_PrevIfOpen: /* jump */
71118 case OP_NextIfOpen: /* jump */
71119 if( p->apCsr[pOp->p1]==0 ) break;
71120 /* Fall through */
71121 case OP_Prev: /* jump */
71122 case OP_Next: /* jump */
71123 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71124 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 );
71129 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
71130 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
71131 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
71132 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
71133 rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res);
71134 next_tail:
71135 u.br.pC->cacheStatus = CACHE_STALE;
71136 if( u.br.res==0 ){
71137 u.br.pC->nullRow = 0;
71138 pc = pOp->p2 - 1;
71139 p->aCounter[pOp->p5]++;
71140 #ifdef SQLITE_TEST
71141 sqlite3_search_count++;
71142 #endif
71143 }else{
71144 u.br.pC->nullRow = 1;
71145 }
71146 u.br.pC->rowidIsValid = 0;
71147 goto check_for_interrupt;
71148 }
71149
71150 /* Opcode: IdxInsert P1 P2 P3 * P5
71151 ** Synopsis: key=r[P2]
@@ -71160,39 +70663,37 @@
71160 ** This instruction only works for indices. The equivalent instruction
71161 ** for tables is OP_Insert.
71162 */
71163 case OP_SorterInsert: /* in2 */
71164 case OP_IdxInsert: { /* in2 */
71165 #if 0 /* local variables moved into u.bs */
71166 VdbeCursor *pC;
71167 BtCursor *pCrsr;
71168 int nKey;
71169 const char *zKey;
71170 #endif /* local variables moved into u.bs */
71171
71172 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) );
71176 pIn2 = &aMem[pOp->p2];
71177 assert( pIn2->flags & MEM_Blob );
71178 u.bs.pCrsr = u.bs.pC->pCursor;
71179 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
71180 assert( u.bs.pCrsr!=0 );
71181 assert( u.bs.pC->isTable==0 );
71182 rc = ExpandBlob(pIn2);
71183 if( rc==SQLITE_OK ){
71184 if( isSorter(u.bs.pC) ){
71185 rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
71186 }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)
71191 );
71192 assert( u.bs.pC->deferredMoveto==0 );
71193 u.bs.pC->cacheStatus = CACHE_STALE;
71194 }
71195 }
71196 break;
71197 }
71198
@@ -71202,38 +70703,36 @@
71202 ** The content of P3 registers starting at register P2 form
71203 ** an unpacked index key. This opcode removes that entry from the
71204 ** index opened by cursor P1.
71205 */
71206 case OP_IdxDelete: {
71207 #if 0 /* local variables moved into u.bt */
71208 VdbeCursor *pC;
71209 BtCursor *pCrsr;
71210 int res;
71211 UnpackedRecord r;
71212 #endif /* local variables moved into u.bt */
71213
71214 assert( pOp->p3>0 );
71215 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
71216 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 );
71221 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];
71226 #ifdef SQLITE_DEBUG
71227 { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
71228 #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);
71232 }
71233 assert( u.bt.pC->deferredMoveto==0 );
71234 u.bt.pC->cacheStatus = CACHE_STALE;
71235 break;
71236 }
71237
71238 /* Opcode: IdxRowid P1 P2 * * *
71239 ** Synopsis: r[P2]=rowid
@@ -71243,32 +70742,31 @@
71243 ** the rowid of the table entry to which this index entry points.
71244 **
71245 ** See also: Rowid, MakeRecord.
71246 */
71247 case OP_IdxRowid: { /* out2-prerelease */
71248 #if 0 /* local variables moved into u.bu */
71249 BtCursor *pCrsr;
71250 VdbeCursor *pC;
71251 i64 rowid;
71252 #endif /* local variables moved into u.bu */
71253
71254 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 );
71259 pOut->flags = MEM_Null;
71260 rc = sqlite3VdbeCursorMoveto(u.bu.pC);
71261 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);
 
71266 if( rc!=SQLITE_OK ){
71267 goto abort_due_to_error;
71268 }
71269 pOut->u.i = u.bu.rowid;
71270 pOut->flags = MEM_Int;
71271 }
71272 break;
71273 }
71274
@@ -71300,43 +70798,42 @@
71300 ** If P5 is non-zero then the key value is increased by an epsilon prior
71301 ** to the comparison. This makes the opcode work like IdxLE.
71302 */
71303 case OP_IdxLT: /* jump */
71304 case OP_IdxGE: { /* jump */
71305 #if 0 /* local variables moved into u.bv */
71306 VdbeCursor *pC;
71307 int res;
71308 UnpackedRecord r;
71309 #endif /* local variables moved into u.bv */
71310
71311 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 );
71317 assert( pOp->p5==0 || pOp->p5==1 );
71318 assert( pOp->p4type==P4_INT32 );
71319 u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
71320 u.bv.r.nField = (u16)pOp->p4.i;
71321 if( pOp->p5 ){
71322 u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71323 }else{
71324 u.bv.r.flags = UNPACKED_PREFIX_MATCH;
71325 }
71326 u.bv.r.aMem = &aMem[pOp->p3];
71327 #ifdef SQLITE_DEBUG
71328 { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
71329 #endif
71330 rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
 
71331 if( pOp->opcode==OP_IdxLT ){
71332 u.bv.res = -u.bv.res;
71333 }else{
71334 assert( pOp->opcode==OP_IdxGE );
71335 u.bv.res++;
71336 }
71337 if( u.bv.res>0 ){
71338 pc = pOp->p2 - 1 ;
71339 }
71340 break;
71341 }
71342
@@ -71359,47 +70856,46 @@
71359 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
71360 **
71361 ** See also: Clear
71362 */
71363 case OP_Destroy: { /* out2-prerelease */
71364 #if 0 /* local variables moved into u.bw */
71365 int iMoved;
71366 int iCnt;
71367 Vdbe *pVdbe;
71368 int iDb;
71369 #endif /* local variables moved into u.bw */
71370
71371 assert( p->readOnly==0 );
71372 #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
71377 ){
71378 u.bw.iCnt++;
71379 }
71380 }
71381 #else
71382 u.bw.iCnt = db->nVdbeRead;
71383 #endif
71384 pOut->flags = MEM_Null;
71385 if( u.bw.iCnt>1 ){
71386 rc = SQLITE_LOCKED;
71387 p->errorAction = OE_Abort;
71388 }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);
 
71393 pOut->flags = MEM_Int;
71394 pOut->u.i = u.bw.iMoved;
71395 #ifndef SQLITE_OMIT_AUTOVACUUM
71396 if( rc==SQLITE_OK && u.bw.iMoved!=0 ){
71397 sqlite3RootPageMoved(db, u.bw.iDb, u.bw.iMoved, pOp->p1);
71398 /* All OP_Destroy operations occur on the same btree */
71399 assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.bw.iDb+1 );
71400 resetSchemaOnFault = u.bw.iDb+1;
71401 }
71402 #endif
71403 }
71404 break;
71405 }
@@ -71421,27 +70917,25 @@
71421 ** also incremented by the number of rows in the table being cleared.
71422 **
71423 ** See also: Destroy
71424 */
71425 case OP_Clear: {
71426 #if 0 /* local variables moved into u.bx */
71427 int nChange;
71428 #endif /* local variables moved into u.bx */
71429
71430 u.bx.nChange = 0;
71431 assert( p->readOnly==0 );
71432 assert( pOp->p1!=1 );
71433 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
71434 rc = sqlite3BtreeClearTable(
71435 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0)
71436 );
71437 if( pOp->p3 ){
71438 p->nChange += u.bx.nChange;
71439 if( pOp->p3>0 ){
71440 assert( memIsValid(&aMem[pOp->p3]) );
71441 memAboutToChange(p, &aMem[pOp->p3]);
71442 aMem[pOp->p3].u.i += u.bx.nChange;
71443 }
71444 }
71445 break;
71446 }
71447
@@ -71469,30 +70963,28 @@
71469 **
71470 ** See documentation on OP_CreateTable for additional information.
71471 */
71472 case OP_CreateIndex: /* out2-prerelease */
71473 case OP_CreateTable: { /* out2-prerelease */
71474 #if 0 /* local variables moved into u.by */
71475 int pgno;
71476 int flags;
71477 Db *pDb;
71478 #endif /* local variables moved into u.by */
71479
71480 u.by.pgno = 0;
71481 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71482 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
71483 assert( p->readOnly==0 );
71484 u.by.pDb = &db->aDb[pOp->p1];
71485 assert( u.by.pDb->pBt!=0 );
71486 if( pOp->opcode==OP_CreateTable ){
71487 /* u.by.flags = BTREE_INTKEY; */
71488 u.by.flags = BTREE_INTKEY;
71489 }else{
71490 u.by.flags = BTREE_BLOBKEY;
71491 }
71492 rc = sqlite3BtreeCreateTable(u.by.pDb->pBt, &u.by.pgno, u.by.flags);
71493 pOut->u.i = u.by.pgno;
71494 break;
71495 }
71496
71497 /* Opcode: ParseSchema P1 * * P4 *
71498 **
@@ -71501,56 +70993,54 @@
71501 **
71502 ** This opcode invokes the parser to create a new virtual machine,
71503 ** then runs the new virtual machine. It is thus a re-entrant opcode.
71504 */
71505 case OP_ParseSchema: {
71506 #if 0 /* local variables moved into u.bz */
71507 int iDb;
71508 const char *zMaster;
71509 char *zSql;
71510 InitData initData;
71511 #endif /* local variables moved into u.bz */
71512
71513 /* Any prepared statement that invokes this opcode will hold mutexes
71514 ** on every btree. This is a prerequisite for invoking
71515 ** sqlite3InitCallback().
71516 */
71517 #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) );
71520 }
71521 #endif
71522
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) );
71526 /* 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,
71532 "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 ){
71535 rc = SQLITE_NOMEM;
71536 }else{
71537 assert( db->init.busy==0 );
71538 db->init.busy = 1;
71539 u.bz.initData.rc = SQLITE_OK;
71540 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);
71544 db->init.busy = 0;
71545 }
71546 }
71547 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
71548 if( rc==SQLITE_NOMEM ){
71549 goto no_mem;
71550 }
71551 break;
71552 }
71553
71554 #if !defined(SQLITE_OMIT_ANALYZE)
71555 /* Opcode: LoadAnalysis P1 * * * *
71556 **
@@ -71622,46 +71112,44 @@
71622 ** file, not the main database file.
71623 **
71624 ** This opcode is used to implement the integrity_check pragma.
71625 */
71626 case OP_IntegrityCk: {
71627 #if 0 /* local variables moved into u.ca */
71628 int nRoot; /* Number of tables to check. (Number of root pages.) */
71629 int *aRoot; /* Array of rootpage numbers for tables to be checked */
71630 int j; /* Loop counter */
71631 int nErr; /* Number of errors reported */
71632 char *z; /* Text of the error report */
71633 Mem *pnErr; /* Register keeping track of errors remaining */
71634 #endif /* local variables moved into u.ca */
71635
71636 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;
71641 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 );
71645 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]);
71648 }
71649 u.ca.aRoot[u.ca.j] = 0;
71650 assert( pOp->p5<db->nDb );
71651 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;
71656 sqlite3VdbeMemSetNull(pIn1);
71657 if( u.ca.nErr==0 ){
71658 assert( u.ca.z==0 );
71659 }else if( u.ca.z==0 ){
71660 goto no_mem;
71661 }else{
71662 sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free);
71663 }
71664 UPDATE_MAX_BLOBSIZE(pIn1);
71665 sqlite3VdbeChangeEncoding(pIn1, encoding);
71666 break;
71667 }
@@ -71693,24 +71181,22 @@
71693 ** Extract the smallest value from boolean index P1 and put that value into
71694 ** register P3. Or, if boolean index P1 is initially empty, leave P3
71695 ** unchanged and jump to instruction P2.
71696 */
71697 case OP_RowSetRead: { /* jump, in1, out3 */
71698 #if 0 /* local variables moved into u.cb */
71699 i64 val;
71700 #endif /* local variables moved into u.cb */
71701
71702 pIn1 = &aMem[pOp->p1];
71703 if( (pIn1->flags & MEM_RowSet)==0
71704 || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0
71705 ){
71706 /* The boolean index is empty */
71707 sqlite3VdbeMemSetNull(pIn1);
71708 pc = pOp->p2 - 1;
71709 }else{
71710 /* A value was pulled from the index */
71711 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
71712 }
71713 goto check_for_interrupt;
71714 }
71715
71716 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71736,18 +71222,16 @@
71736 ** inserted, there is no need to search to see if the same value was
71737 ** previously inserted as part of set X (only if it was previously
71738 ** inserted as part of some other set).
71739 */
71740 case OP_RowSetTest: { /* jump, in1, in3 */
71741 #if 0 /* local variables moved into u.cc */
71742 int iSet;
71743 int exists;
71744 #endif /* local variables moved into u.cc */
71745
71746 pIn1 = &aMem[pOp->p1];
71747 pIn3 = &aMem[pOp->p3];
71748 u.cc.iSet = pOp->p4.i;
71749 assert( pIn3->flags&MEM_Int );
71750
71751 /* If there is anything other than a rowset object in memory cell P1,
71752 ** delete it now and initialize P1 with an empty rowset
71753 */
@@ -71755,21 +71239,21 @@
71755 sqlite3VdbeMemSetRowSet(pIn1);
71756 if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
71757 }
71758
71759 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),
71764 pIn3->u.i);
71765 if( u.cc.exists ){
71766 pc = pOp->p2 - 1;
71767 break;
71768 }
71769 }
71770 if( u.cc.iSet>=0 ){
71771 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
71772 }
71773 break;
71774 }
71775
@@ -71788,111 +71272,109 @@
71788 ** memory required by the sub-vdbe at runtime.
71789 **
71790 ** P4 is a pointer to the VM containing the trigger program.
71791 */
71792 case OP_Program: { /* jump */
71793 #if 0 /* local variables moved into u.cd */
71794 int nMem; /* Number of memory registers for sub-program */
71795 int nByte; /* Bytes of runtime space required for sub-program */
71796 Mem *pRt; /* Register to allocate runtime space */
71797 Mem *pMem; /* Used to iterate through memory cells */
71798 Mem *pEnd; /* Last memory cell in new array */
71799 VdbeFrame *pFrame; /* New vdbe frame to execute in */
71800 SubProgram *pProgram; /* Sub-program to execute */
71801 void *t; /* Token identifying trigger */
71802 #endif /* local variables moved into u.cd */
71803
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
71809 ** disabled for backwards compatibility (p5 is set if this sub-program
71810 ** is really a trigger, not a foreign key action, and the flag set
71811 ** 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
71816 ** ON CONFLICT algorithm). SubProgram structures associated with a
71817 ** single trigger all have the same value for the SubProgram.token
71818 ** variable. */
71819 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;
71823 }
71824
71825 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
71826 rc = SQLITE_ERROR;
71827 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
71828 break;
71829 }
71830
71831 /* Register u.cd.pRt is used to store the memory required to save the state
71832 ** 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
71834 ** 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
71837 ** program stored in SubProgram.aOp. As well as these, one memory
71838 ** cell is required for each cursor used by the program. Set local
71839 ** variable u.cd.nMem (and later, VdbeFrame.nChildMem) to this value.
71840 */
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 ){
71848 goto no_mem;
71849 }
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;
71872 }
71873 }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 );
71878 }
71879
71880 p->nFrame++;
71881 u.cd.pFrame->pParent = p->pFrame;
71882 u.cd.pFrame->lastRowid = lastRowid;
71883 u.cd.pFrame->nChange = p->nChange;
71884 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;
71889 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
71890 p->aOp = aOp = u.cd.pProgram->aOp;
71891 p->nOp = u.cd.pProgram->nOp;
71892 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71893 p->nOnceFlag = u.cd.pProgram->nOnce;
71894 pc = -1;
71895 memset(p->aOnceFlag, 0, p->nOnceFlag);
71896
71897 break;
71898 }
@@ -71908,17 +71390,15 @@
71908 ** The address of the cell in the parent frame is determined by adding
71909 ** the value of the P1 argument to the value of the P1 argument to the
71910 ** calling OP_Program instruction.
71911 */
71912 case OP_Param: { /* out2-prerelease */
71913 #if 0 /* local variables moved into u.ce */
71914 VdbeFrame *pFrame;
71915 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);
71920 break;
71921 }
71922
71923 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
71924
@@ -71975,26 +71455,23 @@
71975 **
71976 ** This instruction throws an error if the memory cell is not initially
71977 ** an integer.
71978 */
71979 case OP_MemMax: { /* in2 */
71980 #if 0 /* local variables moved into u.cf */
71981 Mem *pIn1;
71982 VdbeFrame *pFrame;
71983 #endif /* local variables moved into u.cf */
71984 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];
71987 }else{
71988 u.cf.pIn1 = &aMem[pOp->p1];
71989 }
71990 assert( memIsValid(u.cf.pIn1) );
71991 sqlite3VdbeMemIntegerify(u.cf.pIn1);
71992 pIn2 = &aMem[pOp->p2];
71993 sqlite3VdbeMemIntegerify(pIn2);
71994 if( u.cf.pIn1->u.i<pIn2->u.i){
71995 u.cf.pIn1->u.i = pIn2->u.i;
71996 }
71997 break;
71998 }
71999 #endif /* SQLITE_OMIT_AUTOINCREMENT */
72000
@@ -72061,60 +71538,58 @@
72061 **
72062 ** The P5 arguments are taken from register P2 and its
72063 ** successors.
72064 */
72065 case OP_AggStep: {
72066 #if 0 /* local variables moved into u.cg */
72067 int n;
72068 int i;
72069 Mem *pMem;
72070 Mem *pRec;
72071 sqlite3_context ctx;
72072 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;
72087 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 ){
72099 assert( pOp>p->aOp );
72100 assert( pOp[-1].p4type==P4_COLLSEQ );
72101 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 ){
72110 assert( pOp[-1].opcode==OP_CollSeq );
72111 u.cg.i = pOp[-1].p1;
72112 if( u.cg.i ) sqlite3VdbeMemSetInt64(&aMem[u.cg.i], 1);
72113 }
72114
72115 sqlite3VdbeMemRelease(&u.cg.ctx.s);
72116
72117 break;
72118 }
72119
72120 /* Opcode: AggFinal P1 P2 * P4 *
@@ -72129,23 +71604,21 @@
72129 ** functions that can take varying numbers of arguments. The
72130 ** P4 argument is only needed for the degenerate case where
72131 ** the step function was not previously called.
72132 */
72133 case OP_AggFinal: {
72134 #if 0 /* local variables moved into u.ch */
72135 Mem *pMem;
72136 #endif /* local variables moved into u.ch */
72137 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);
72141 if( rc ){
72142 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem));
72143 }
72144 sqlite3VdbeChangeEncoding(u.ch.pMem, encoding);
72145 UPDATE_MAX_BLOBSIZE(u.ch.pMem);
72146 if( sqlite3VdbeMemTooBig(u.ch.pMem) ){
72147 goto too_big;
72148 }
72149 break;
72150 }
72151
@@ -72160,31 +71633,29 @@
72160 ** in the WAL that have been checkpointed after the checkpoint
72161 ** completes into mem[P3+2]. However on an error, mem[P3+1] and
72162 ** mem[P3+2] are initialized to -1.
72163 */
72164 case OP_Checkpoint: {
72165 #if 0 /* local variables moved into u.ci */
72166 int i; /* Loop counter */
72167 int aRes[3]; /* Results */
72168 Mem *pMem; /* Write results here */
72169 #endif /* local variables moved into u.ci */
72170
72171 assert( p->readOnly==0 );
72172 u.ci.aRes[0] = 0;
72173 u.ci.aRes[1] = u.ci.aRes[2] = -1;
72174 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
72175 || pOp->p2==SQLITE_CHECKPOINT_FULL
72176 || pOp->p2==SQLITE_CHECKPOINT_RESTART
72177 );
72178 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ci.aRes[1], &u.ci.aRes[2]);
72179 if( rc==SQLITE_BUSY ){
72180 rc = SQLITE_OK;
72181 u.ci.aRes[0] = 1;
72182 }
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 }
72186 break;
72187 };
72188 #endif
72189
72190 #ifndef SQLITE_OMIT_PRAGMA
@@ -72198,98 +71669,96 @@
72198 ** If changing into or out of WAL mode the procedure is more complicated.
72199 **
72200 ** Write a string containing the final journal-mode to register P2.
72201 */
72202 case OP_JournalMode: { /* out2-prerelease */
72203 #if 0 /* local variables moved into u.cj */
72204 Btree *pBt; /* Btree to change journal mode of */
72205 Pager *pPager; /* Pager associated with pBt */
72206 int eNew; /* New journal mode */
72207 int eOld; /* The old journal mode */
72208 #ifndef SQLITE_OMIT_WAL
72209 const char *zFilename; /* Name of database file for pPager */
72210 #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
72221 );
72222 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72223 assert( p->readOnly==0 );
72224
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;
72230
72231 #ifndef SQLITE_OMIT_WAL
72232 u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1);
72233
72234 /* 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
72236 */
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 */
72240 ){
72241 u.cj.eNew = u.cj.eOld;
72242 }
72243
72244 if( (u.cj.eNew!=u.cj.eOld)
72245 && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL)
72246 ){
72247 if( !db->autoCommit || db->nVdbeRead>1 ){
72248 rc = SQLITE_ERROR;
72249 sqlite3SetString(&p->zErrMsg, db,
72250 "cannot change %s wal mode from within a transaction",
72251 (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
72252 );
72253 break;
72254 }else{
72255
72256 if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){
72257 /* 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.
72261 */
72262 rc = sqlite3PagerCloseWal(u.cj.pPager);
72263 if( rc==SQLITE_OK ){
72264 sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
72265 }
72266 }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){
72267 /* Cannot transition directly from MEMORY to WAL. Use mode OFF
72268 ** as an intermediate */
72269 sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF);
72270 }
72271
72272 /* Open a transaction on the database file. Regardless of the journal
72273 ** mode, this transaction always uses a rollback journal.
72274 */
72275 assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 );
72276 if( rc==SQLITE_OK ){
72277 rc = sqlite3BtreeSetVersion(u.cj.pBt, (u.cj.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
72278 }
72279 }
72280 }
72281 #endif /* ifndef SQLITE_OMIT_WAL */
72282
72283 if( rc ){
72284 u.cj.eNew = u.cj.eOld;
72285 }
72286 u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
72287
72288 pOut = &aMem[pOp->p2];
72289 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
72290 pOut->z = (char *)sqlite3JournalModename(u.cj.eNew);
72291 pOut->n = sqlite3Strlen30(pOut->z);
72292 pOut->enc = SQLITE_UTF8;
72293 sqlite3VdbeChangeEncoding(pOut, encoding);
72294 break;
72295 };
@@ -72315,19 +71784,17 @@
72315 ** Perform a single step of the incremental vacuum procedure on
72316 ** the P1 database. If the vacuum has finished, jump to instruction
72317 ** P2. Otherwise, fall through to the next instruction.
72318 */
72319 case OP_IncrVacuum: { /* jump */
72320 #if 0 /* local variables moved into u.ck */
72321 Btree *pBt;
72322 #endif /* local variables moved into u.ck */
72323
72324 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72325 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72326 assert( p->readOnly==0 );
72327 u.ck.pBt = db->aDb[pOp->p1].pBt;
72328 rc = sqlite3BtreeIncrVacuum(u.ck.pBt);
72329 if( rc==SQLITE_DONE ){
72330 pc = pOp->p2 - 1;
72331 rc = SQLITE_OK;
72332 }
72333 break;
@@ -72394,16 +71861,14 @@
72394 ** Also, whether or not P4 is set, check that this is not being called from
72395 ** within a callback to a virtual table xSync() method. If it is, the error
72396 ** code will be set to SQLITE_LOCKED.
72397 */
72398 case OP_VBegin: {
72399 #if 0 /* local variables moved into u.cl */
72400 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);
72405 break;
72406 }
72407 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72408
72409 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72438,36 +71903,34 @@
72438 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72439 ** P1 is a cursor number. This opcode opens a cursor to the virtual
72440 ** table and stores that cursor in P1.
72441 */
72442 case OP_VOpen: {
72443 #if 0 /* local variables moved into u.cm */
72444 VdbeCursor *pCur;
72445 sqlite3_vtab_cursor *pVtabCursor;
72446 sqlite3_vtab *pVtab;
72447 sqlite3_module *pModule;
72448 #endif /* local variables moved into u.cm */
72449
72450 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);
72458 if( SQLITE_OK==rc ){
72459 /* Initialize sqlite3_vtab_cursor base class */
72460 u.cm.pVtabCursor->pVtab = u.cm.pVtab;
72461
72462 /* 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;
72466 }else{
72467 db->mallocFailed = 1;
72468 u.cm.pModule->xClose(u.cm.pVtabCursor);
72469 }
72470 }
72471 break;
72472 }
72473 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72491,11 +71954,10 @@
72491 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
72492 **
72493 ** A jump is made to P2 if the result set after filtering would be empty.
72494 */
72495 case OP_VFilter: { /* jump */
72496 #if 0 /* local variables moved into u.cn */
72497 int nArg;
72498 int iQuery;
72499 const sqlite3_module *pModule;
72500 Mem *pQuery;
72501 Mem *pArgc;
@@ -72503,49 +71965,48 @@
72503 sqlite3_vtab *pVtab;
72504 VdbeCursor *pCur;
72505 int res;
72506 int i;
72507 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;
72519
72520 /* 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;
72524
72525 /* Invoke the xFilter method */
72526 {
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]);
72532 }
72533
72534 p->inVtabMethod = 1;
72535 rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg);
72536 p->inVtabMethod = 0;
72537 sqlite3VtabImportErrmsg(p, u.cn.pVtab);
72538 if( rc==SQLITE_OK ){
72539 u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
72540 }
72541
72542 if( u.cn.res ){
72543 pc = pOp->p2 - 1;
72544 }
72545 }
72546 u.cn.pCur->nullRow = 0;
72547
72548 break;
72549 }
72550 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72551
@@ -72556,55 +72017,53 @@
72556 ** Store the value of the P2-th column of
72557 ** the row of the virtual-table that the
72558 ** P1 cursor is pointing to into register P3.
72559 */
72560 case OP_VColumn: {
72561 #if 0 /* local variables moved into u.co */
72562 sqlite3_vtab *pVtab;
72563 const sqlite3_module *pModule;
72564 Mem *pDest;
72565 sqlite3_context sContext;
72566 #endif /* local variables moved into u.co */
72567
72568 VdbeCursor *pCur = p->apCsr[pOp->p1];
72569 assert( pCur->pVtabCursor );
72570 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72571 u.co.pDest = &aMem[pOp->p3];
72572 memAboutToChange(p, u.co.pDest);
72573 if( pCur->nullRow ){
72574 sqlite3VdbeMemSetNull(u.co.pDest);
72575 break;
72576 }
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));
72581
72582 /* 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
72585 ** new one.
72586 */
72587 sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest);
72588 MemSetTypeFlag(&u.co.sContext.s, MEM_Null);
72589
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;
72594 }
72595
72596 /* Copy the result of the function to the P3 register. We
72597 ** 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.
72599 */
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);
72604
72605 if( sqlite3VdbeMemTooBig(u.co.pDest) ){
72606 goto too_big;
72607 }
72608 break;
72609 }
72610 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72615,42 +72074,40 @@
72615 ** Advance virtual table P1 to the next row in its result set and
72616 ** jump to instruction P2. Or, if the virtual table has reached
72617 ** the end of its result set, then fall through to the next instruction.
72618 */
72619 case OP_VNext: { /* jump */
72620 #if 0 /* local variables moved into u.cp */
72621 sqlite3_vtab *pVtab;
72622 const sqlite3_module *pModule;
72623 int res;
72624 VdbeCursor *pCur;
72625 #endif /* local variables moved into u.cp */
72626
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 ){
72631 break;
72632 }
72633 u.cp.pVtab = u.cp.pCur->pVtabCursor->pVtab;
72634 u.cp.pModule = u.cp.pVtab->pModule;
72635 assert( u.cp.pModule->xNext );
72636
72637 /* Invoke the xNext() method of the module. There is no way for the
72638 ** underlying implementation to return an error if one occurs during
72639 ** xNext(). Instead, if an error occurs, true is returned (indicating that
72640 ** data is available) and the error code returned when xColumn or
72641 ** some other method is next invoked on the save virtual table cursor.
72642 */
72643 p->inVtabMethod = 1;
72644 rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
72645 p->inVtabMethod = 0;
72646 sqlite3VtabImportErrmsg(p, u.cp.pVtab);
72647 if( rc==SQLITE_OK ){
72648 u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
72649 }
72650
72651 if( !u.cp.res ){
72652 /* If there is data, jump to P2 */
72653 pc = pOp->p2 - 1;
72654 }
72655 goto check_for_interrupt;
72656 }
@@ -72662,29 +72119,27 @@
72662 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72663 ** This opcode invokes the corresponding xRename method. The value
72664 ** in register P1 is passed as the zName argument to the xRename method.
72665 */
72666 case OP_VRename: {
72667 #if 0 /* local variables moved into u.cq */
72668 sqlite3_vtab *pVtab;
72669 Mem *pName;
72670 #endif /* local variables moved into u.cq */
72671
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) );
72676 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);
72683 if( rc==SQLITE_OK ){
72684 rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z);
72685 sqlite3VtabImportErrmsg(p, u.cq.pVtab);
72686 p->expired = 0;
72687 }
72688 break;
72689 }
72690 #endif
@@ -72713,46 +72168,44 @@
72713 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72714 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72715 ** is set to the value of the rowid for the row just inserted.
72716 */
72717 case OP_VUpdate: {
72718 #if 0 /* local variables moved into u.cr */
72719 sqlite3_vtab *pVtab;
72720 sqlite3_module *pModule;
72721 int nArg;
72722 int i;
72723 sqlite_int64 rowid;
72724 Mem **apArg;
72725 Mem *pX;
72726 #endif /* local variables moved into u.cr */
72727
72728 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
72729 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
72730 );
72731 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;
72735 assert( pOp->p4type==P4_VTAB );
72736 if( ALWAYS(u.cr.pModule->xUpdate) ){
72737 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++;
72746 }
72747 db->vtabOnConflict = pOp->p5;
72748 rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid);
72749 db->vtabOnConflict = vtabOnConflict;
72750 sqlite3VtabImportErrmsg(p, u.cr.pVtab);
72751 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;
72754 }
72755 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
72756 if( pOp->p5==OE_Ignore ){
72757 rc = SQLITE_OK;
72758 }else{
@@ -72808,38 +72261,36 @@
72808 **
72809 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72810 ** the UTF-8 string contained in P4 is emitted on the trace callback.
72811 */
72812 case OP_Trace: {
72813 #if 0 /* local variables moved into u.cs */
72814 char *zTrace;
72815 char *z;
72816 #endif /* local variables moved into u.cs */
72817
72818 if( db->xTrace
72819 && !p->doingRerun
72820 && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72821 ){
72822 u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace);
72823 db->xTrace(db->pTraceArg, u.cs.z);
72824 sqlite3DbFree(db, u.cs.z);
72825 }
72826 #ifdef SQLITE_USE_FCNTL_TRACE
72827 u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72828 if( u.cs.zTrace ){
72829 int i;
72830 for(i=0; i<db->nDb; i++){
72831 if( ((1<<i) & p->btreeMask)==0 ) continue;
72832 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace);
72833 }
72834 }
72835 #endif /* SQLITE_USE_FCNTL_TRACE */
72836 #ifdef SQLITE_DEBUG
72837 if( (db->flags & SQLITE_SqlTrace)!=0
72838 && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72839 ){
72840 sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
72841 }
72842 #endif /* SQLITE_DEBUG */
72843 break;
72844 }
72845 #endif
@@ -72964,10 +72415,11 @@
72964 rc = SQLITE_INTERRUPT;
72965 p->rc = rc;
72966 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
72967 goto vdbe_error_halt;
72968 }
 
72969
72970 /************** End of vdbe.c ************************************************/
72971 /************** Begin file vdbeblob.c ****************************************/
72972 /*
72973 ** 2007 May 1
@@ -88225,13 +87677,13 @@
88225 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
88226 errMsg.db = pParse->db;
88227 for(j=0; j<pIdx->nKeyCol; j++){
88228 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
88229 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
88230 sqlite3StrAccumAppend(&errMsg, pTab->zName, -1);
88231 sqlite3StrAccumAppend(&errMsg, ".", 1);
88232 sqlite3StrAccumAppend(&errMsg, zCol, -1);
88233 }
88234 zErr = sqlite3StrAccumFinish(&errMsg);
88235 sqlite3HaltConstraint(pParse,
88236 (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
88237 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88419,12 +87871,13 @@
88419 }
88420 if( pKey ){
88421 assert( sqlite3KeyInfoIsWriteable(pKey) );
88422 for(i=0; i<nCol; i++){
88423 char *zColl = pIdx->azColl[i];
88424 if( NEVER(zColl==0) ) zColl = "BINARY";
88425 pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
 
88426 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
88427 }
88428 if( pParse->nErr ){
88429 sqlite3KeyInfoUnref(pKey);
88430 }else{
@@ -91238,15 +90691,15 @@
91238 nSep = sqlite3_value_bytes(argv[1]);
91239 }else{
91240 zSep = ",";
91241 nSep = 1;
91242 }
91243 sqlite3StrAccumAppend(pAccum, zSep, nSep);
91244 }
91245 zVal = (char*)sqlite3_value_text(argv[0]);
91246 nVal = sqlite3_value_bytes(argv[0]);
91247 sqlite3StrAccumAppend(pAccum, zVal, nVal);
91248 }
91249 }
91250 static void groupConcatFinalize(sqlite3_context *context){
91251 StrAccum *pAccum;
91252 pAccum = sqlite3_aggregate_context(context, 0);
@@ -110314,12 +109767,11 @@
110314 int res; /* Result of comparison operation */
110315
110316 #ifndef SQLITE_DEBUG
110317 UNUSED_PARAMETER( pParse );
110318 #endif
110319 assert( pRec!=0 || pParse->db->mallocFailed );
110320 if( pRec==0 ) return;
110321 iCol = pRec->nField - 1;
110322 assert( pIdx->nSample>0 );
110323 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
110324 do{
110325 iTest = (iMin+i)/2;
@@ -110978,11 +110430,11 @@
110978 int iTerm, /* Index of this term. First is zero */
110979 const char *zColumn, /* Name of the column */
110980 const char *zOp /* Name of the operator */
110981 ){
110982 if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110983 sqlite3StrAccumAppend(pStr, zColumn, -1);
110984 sqlite3StrAccumAppend(pStr, zOp, 1);
110985 sqlite3StrAccumAppend(pStr, "?", 1);
110986 }
110987
110988 /*
@@ -111024,11 +110476,11 @@
111024 if( i>=nSkip ){
111025 explainAppendTerm(&txt, i, z, "=");
111026 }else{
111027 if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
111028 sqlite3StrAccumAppend(&txt, "ANY(", 4);
111029 sqlite3StrAccumAppend(&txt, z, -1);
111030 sqlite3StrAccumAppend(&txt, ")", 1);
111031 }
111032 }
111033
111034 j = i;
@@ -119582,11 +119034,12 @@
119582 }
119583 db->lookaside.pEnd = p;
119584 db->lookaside.bEnabled = 1;
119585 db->lookaside.bMalloced = pBuf==0 ?1:0;
119586 }else{
119587 db->lookaside.pEnd = 0;
 
119588 db->lookaside.bEnabled = 0;
119589 db->lookaside.bMalloced = 0;
119590 }
119591 return SQLITE_OK;
119592 }
@@ -120080,10 +119533,11 @@
120080 case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
120081 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
120082 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
120083 case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
120084 case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
 
120085 case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
120086 case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
120087 case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
120088 case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
120089 case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
120090
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.3. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -133,13 +133,13 @@
133 **
134 ** See also: [sqlite3_libversion()],
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -517,10 +517,11 @@
517 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
522 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
523 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
524 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
525 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
526 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
527 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -584,11 +585,12 @@
585 ** information is written to disk in the same order as calls
586 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
587 ** after reboot following a crash or power loss, the only bytes in a
588 ** file that were written at the application level might have changed
589 ** and that adjacent bytes, even bytes within the same sector are
590 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
591 ** flag indicate that a file cannot be deleted when open.
592 */
593 #define SQLITE_IOCAP_ATOMIC 0x00000001
594 #define SQLITE_IOCAP_ATOMIC512 0x00000002
595 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
596 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -947,10 +949,16 @@
949 ** This file control is used by some VFS activity tracing [shims].
950 ** The argument is a zero-terminated string. Higher layers in the
951 ** SQLite stack may generate instances of this file control if
952 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
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 **
960 ** </ul>
961 */
962 #define SQLITE_FCNTL_LOCKSTATE 1
963 #define SQLITE_GET_LOCKPROXYFILE 2
964 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -967,10 +975,11 @@
975 #define SQLITE_FCNTL_PRAGMA 14
976 #define SQLITE_FCNTL_BUSYHANDLER 15
977 #define SQLITE_FCNTL_TEMPFILENAME 16
978 #define SQLITE_FCNTL_MMAP_SIZE 18
979 #define SQLITE_FCNTL_TRACE 19
980 #define SQLITE_FCNTL_HAS_MOVED 20
981
982 /*
983 ** CAPI3REF: Mutex Handle
984 **
985 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -12492,10 +12501,11 @@
12501 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
12502 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
12503
12504 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
12505 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
12506 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
12507 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
12508 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
12509 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
12510 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
12511 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -13322,10 +13332,13 @@
13332 "SMALL_STACK",
13333 #endif
13334 #ifdef SQLITE_SOUNDEX
13335 "SOUNDEX",
13336 #endif
13337 #ifdef SQLITE_SYSTEM_MALLOC
13338 "SYSTEM_MALLOC",
13339 #endif
13340 #ifdef SQLITE_TCL
13341 "TCL",
13342 #endif
13343 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
13344 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
@@ -13336,10 +13349,13 @@
13349 #if defined(SQLITE_THREADSAFE)
13350 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
13351 #endif
13352 #ifdef SQLITE_USE_ALLOCA
13353 "USE_ALLOCA",
13354 #endif
13355 #ifdef SQLITE_WIN32_MALLOC
13356 "WIN32_MALLOC",
13357 #endif
13358 #ifdef SQLITE_ZERO_MALLOC
13359 "ZERO_MALLOC"
13360 #endif
13361 };
@@ -13789,11 +13805,11 @@
13805 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
13806 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
13807 #endif
13808 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13809 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13810 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
13811 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13812 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
13813
13814 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13815 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -17518,11 +17534,11 @@
17534 ** works for chunks that are currently checked out.
17535 */
17536 static int memsys5Size(void *p){
17537 int iSize = 0;
17538 if( p ){
17539 int i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom);
17540 assert( i>=0 && i<mem5.nBlock );
17541 iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
17542 }
17543 return iSize;
17544 }
@@ -17605,11 +17621,11 @@
17621 int iBlock;
17622
17623 /* Set iBlock to the index of the block pointed to by pOld in
17624 ** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
17625 */
17626 iBlock = (int)(((u8 *)pOld-mem5.zPool)/mem5.szAtom);
17627
17628 /* Check that the pointer pOld points to a valid, non-free block. */
17629 assert( iBlock>=0 && iBlock<mem5.nBlock );
17630 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
17631 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
@@ -19374,11 +19390,11 @@
19390 /*
19391 ** TRUE if p is a lookaside memory allocation from db
19392 */
19393 #ifndef SQLITE_OMIT_LOOKASIDE
19394 static int isLookaside(sqlite3 *db, void *p){
19395 return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19396 }
19397 #else
19398 #define isLookaside(A,B) 0
19399 #endif
19400
@@ -19390,12 +19406,13 @@
19406 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
19407 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
19408 return sqlite3GlobalConfig.m.xSize(p);
19409 }
19410 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19411 assert( db!=0 );
19412 assert( sqlite3_mutex_held(db->mutex) );
19413 if( isLookaside(db, p) ){
19414 return db->lookaside.sz;
19415 }else{
19416 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
19417 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
19418 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19873,10 +19890,18 @@
19890 }
19891 if( N>0 ){
19892 sqlite3StrAccumAppend(pAccum, zSpaces, N);
19893 }
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 }
19903
19904 /*
19905 ** On machines with a small stack size, you can redefine the
19906 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19907 */
@@ -20085,11 +20110,11 @@
20110 zOut = buf;
20111 }else{
20112 nOut = precision + 10;
20113 zOut = zExtra = sqlite3Malloc( nOut );
20114 if( zOut==0 ){
20115 setStrAccumError(pAccum, STRACCUM_NOMEM);
20116 return;
20117 }
20118 }
20119 bufpt = &zOut[nOut-1];
20120 if( xtype==etORDINAL ){
@@ -20197,11 +20222,11 @@
20222 e2 = exp;
20223 }
20224 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
20225 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
20226 if( bufpt==0 ){
20227 setStrAccumError(pAccum, STRACCUM_NOMEM);
20228 return;
20229 }
20230 }
20231 zOut = bufpt;
20232 nsd = 16 + flag_altform2*10;
@@ -20332,11 +20357,11 @@
20357 needQuote = !isnull && xtype==etSQLESCAPE2;
20358 n += i + 1 + needQuote*2;
20359 if( n>etBUFSIZE ){
20360 bufpt = zExtra = sqlite3Malloc( n );
20361 if( bufpt==0 ){
20362 setStrAccumError(pAccum, STRACCUM_NOMEM);
20363 return;
20364 }
20365 }else{
20366 bufpt = buf;
20367 }
@@ -20355,11 +20380,11 @@
20380 ** if( precision>=0 && precision<length ) length = precision; */
20381 break;
20382 }
20383 case etTOKEN: {
20384 Token *pToken = va_arg(ap, Token*);
20385 if( pToken && pToken->n ){
20386 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
20387 }
20388 length = width = 0;
20389 break;
20390 }
@@ -20367,14 +20392,14 @@
20392 SrcList *pSrc = va_arg(ap, SrcList*);
20393 int k = va_arg(ap, int);
20394 struct SrcList_item *pItem = &pSrc->a[k];
20395 assert( k>=0 && k<pSrc->nSrc );
20396 if( pItem->zDatabase ){
20397 sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
20398 sqlite3StrAccumAppend(pAccum, ".", 1);
20399 }
20400 sqlite3StrAccumAppendAll(pAccum, pItem->zName);
20401 length = width = 0;
20402 break;
20403 }
20404 default: {
20405 assert( xtype==etINVALID );
@@ -20409,36 +20434,34 @@
20434
20435 /*
20436 ** Append N bytes of text from z to the StrAccum object.
20437 */
20438 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
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 );
 
 
 
 
 
 
 
20443 if( p->nChar+N >= p->nAlloc ){
20444 char *zNew;
20445 if( p->accError ){
20446 testcase(p->accError==STRACCUM_TOOBIG);
20447 testcase(p->accError==STRACCUM_NOMEM);
20448 return;
20449 }
20450 if( !p->useMalloc ){
 
20451 N = p->nAlloc - p->nChar - 1;
20452 setStrAccumError(p, STRACCUM_TOOBIG);
20453 if( N<=0 ){
20454 return;
20455 }
20456 }else{
20457 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
20458 i64 szNew = p->nChar;
20459 szNew += N + 1;
20460 if( szNew > p->mxAlloc ){
20461 sqlite3StrAccumReset(p);
20462 setStrAccumError(p, STRACCUM_TOOBIG);
20463 return;
20464 }else{
20465 p->nAlloc = (int)szNew;
20466 }
20467 if( p->useMalloc==1 ){
@@ -20448,20 +20471,28 @@
20471 }
20472 if( zNew ){
20473 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20474 p->zText = zNew;
20475 }else{
 
20476 sqlite3StrAccumReset(p);
20477 setStrAccumError(p, STRACCUM_NOMEM);
20478 return;
20479 }
20480 }
20481 }
20482 assert( p->zText );
20483 memcpy(&p->zText[p->nChar], z, N);
20484 p->nChar += N;
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
20494
20495 /*
20496 ** Finish off a string by making sure it is zero-terminated.
20497 ** Return a pointer to the resulting string. Return a NULL
20498 ** pointer if any kind of error was encountered.
@@ -20476,11 +20507,11 @@
20507 p->zText = sqlite3_malloc(p->nChar+1);
20508 }
20509 if( p->zText ){
20510 memcpy(p->zText, p->zBase, p->nChar+1);
20511 }else{
20512 setStrAccumError(p, STRACCUM_NOMEM);
20513 }
20514 }
20515 }
20516 return p->zText;
20517 }
@@ -22629,11 +22660,13 @@
22660 if( x<10 ) return 1;
22661 n = x%10;
22662 x /= 10;
22663 if( n>=5 ) n -= 2;
22664 else if( n>=1 ) n -= 1;
22665 if( x>=3 ){
22666 return x>60 ? (u64)LARGEST_INT64 : (n+8)<<(x-3);
22667 }
22668 return (n+8)>>(3-x);
22669 }
22670
22671 /************** End of util.c ************************************************/
22672 /************** Begin file hash.c ********************************************/
@@ -24611,10 +24644,19 @@
24644 }
24645 *ppInode = pInode;
24646 return SQLITE_OK;
24647 }
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
24658
24659 /*
24660 ** Check a unixFile that is a database. Verify the following:
24661 **
24662 ** (1) There is exactly one hard link on the file
@@ -24645,14 +24687,11 @@
24687 if( buf.st_nlink>1 ){
24688 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
24689 pFile->ctrlFlags |= UNIXFILE_WARNED;
24690 return;
24691 }
24692 if( fileHasMoved(pFile) ){
 
 
 
24693 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
24694 pFile->ctrlFlags |= UNIXFILE_WARNED;
24695 return;
24696 }
24697 }
@@ -27096,10 +27135,14 @@
27135 if( zTFile ){
27136 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
27137 *(char**)pArg = zTFile;
27138 }
27139 return SQLITE_OK;
27140 }
27141 case SQLITE_FCNTL_HAS_MOVED: {
27142 *(int*)pArg = fileHasMoved(pFile);
27143 return SQLITE_OK;
27144 }
27145 #if SQLITE_MAX_MMAP_SIZE>0
27146 case SQLITE_FCNTL_MMAP_SIZE: {
27147 i64 newLimit = *(i64*)pArg;
27148 int rc = SQLITE_OK;
@@ -27377,11 +27420,11 @@
27420
27421 /* Update the global lock state and do debug tracing */
27422 #ifdef SQLITE_DEBUG
27423 { u16 mask;
27424 OSTRACE(("SHM-LOCK "));
27425 mask = ofst>31 ? 0xffffffff : (1<<(ofst+n)) - (1<<ofst);
27426 if( rc==SQLITE_OK ){
27427 if( lockType==F_UNLCK ){
27428 OSTRACE(("unlock %d ok", ofst));
27429 pShmNode->exclMask &= ~mask;
27430 pShmNode->sharedMask &= ~mask;
@@ -43889,10 +43932,34 @@
43932 *ppPager = pPager;
43933 return SQLITE_OK;
43934 }
43935
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
43961
43962 /*
43963 ** This function is called after transitioning from PAGER_UNLOCK to
43964 ** PAGER_SHARED state. It tests if there is a hot journal present in
43965 ** the file-system for the given pager. A hot journal is one that
@@ -44360,11 +44427,11 @@
44427 if( bMmapOk && pagerUseWal(pPager) ){
44428 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
44429 if( rc!=SQLITE_OK ) goto pager_acquire_err;
44430 }
44431
44432 if( bMmapOk && iFrame==0 ){
44433 void *pData = 0;
44434
44435 rc = sqlite3OsFetch(pPager->fd,
44436 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
44437 );
@@ -44565,17 +44632,23 @@
44632 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
44633 (pPager->tempFile ?
44634 (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
44635 (SQLITE_OPEN_MAIN_JOURNAL)
44636 );
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 }
44650 }
44651 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
44652 }
44653
44654
@@ -44705,18 +44778,12 @@
44778 assert( pPager->eState==PAGER_WRITER_LOCKED
44779 || pPager->eState==PAGER_WRITER_CACHEMOD
44780 || pPager->eState==PAGER_WRITER_DBMOD
44781 );
44782 assert( assert_pager_state(pPager) );
44783 assert( pPager->errCode==0 );
44784 assert( pPager->readOnly==0 );
 
 
 
 
 
 
44785
44786 CHECK_PAGE(pPg);
44787
44788 /* The journal file needs to be opened. Higher level routines have already
44789 ** obtained the necessary locks to begin the write-transaction, but the
@@ -44841,23 +44908,23 @@
44908 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
44909 int rc = SQLITE_OK;
44910
44911 PgHdr *pPg = pDbPage;
44912 Pager *pPager = pPg->pPager;
 
44913
44914 assert( (pPg->flags & PGHDR_MMAP)==0 );
44915 assert( pPager->eState>=PAGER_WRITER_LOCKED );
44916 assert( pPager->eState!=PAGER_ERROR );
44917 assert( assert_pager_state(pPager) );
44918
44919 if( pPager->sectorSize > (u32)pPager->pageSize ){
44920 Pgno nPageCount; /* Total number of pages in database file */
44921 Pgno pg1; /* First page of the sector pPg is located on. */
44922 int nPage = 0; /* Number of pages starting at pg1 to journal */
44923 int ii; /* Loop counter */
44924 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
44925 Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
44926
44927 /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
44928 ** a journal header to be written between the pages journaled by
44929 ** this function.
44930 */
@@ -51991,11 +52058,11 @@
52058
52059 if( pgno>btreePagecount(pBt) ){
52060 rc = SQLITE_CORRUPT_BKPT;
52061 }else{
52062 rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
52063 if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
52064 rc = btreeInitPage(*ppPage);
52065 if( rc!=SQLITE_OK ){
52066 releasePage(*ppPage);
52067 }
52068 }
@@ -54531,14 +54598,14 @@
54598 }
54599
54600 /*
54601 ** Return a pointer to payload information from the entry that the
54602 ** pCur cursor is pointing to. The pointer is to the beginning of
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.
54607 **
54608 ** This routine is an optimization. It is common for the entire key
54609 ** and data to fit on the local page and for there to be no overflow
54610 ** pages. When that is so, this routine can be used to access the
54611 ** key and data without making a copy. If the key and/or data spills
@@ -54547,45 +54614,25 @@
54614 **
54615 ** The pointer returned by this routine looks directly into the cached
54616 ** page of the database. The data might change or move the next time
54617 ** any btree routine is called.
54618 */
54619 static const void *fetchPayload(
54620 BtCursor *pCur, /* Cursor pointing to entry to read from */
54621 u32 *pAmt /* Write the number of available bytes here */
 
54622 ){
 
 
 
 
 
54623 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
54624 assert( pCur->eState==CURSOR_VALID );
54625 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54626 assert( cursorHoldsMutex(pCur) );
54627 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
 
54628 if( pCur->info.nSize==0 ){
54629 btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
54630 &pCur->info);
54631 }
54632 *pAmt = pCur->info.nLocal;
54633 return (void*)(pCur->info.pCell + pCur->info.nHeader);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54634 }
54635
54636
54637 /*
54638 ** For the entry that cursor pCur is point to, return as
@@ -54600,26 +54647,14 @@
54647 **
54648 ** These routines is used to get quick access to key and data
54649 ** in the common case where no overflow pages are used.
54650 */
54651 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
54652 return fetchPayload(pCur, pAmt);
 
 
 
 
 
 
54653 }
54654 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
54655 return fetchPayload(pCur, pAmt);
 
 
 
 
 
 
54656 }
54657
54658
54659 /*
54660 ** Move the cursor down to a new child page. The newPgno argument is the
@@ -54734,12 +54769,10 @@
54769 ** b-tree).
54770 */
54771 static int moveToRoot(BtCursor *pCur){
54772 MemPage *pRoot;
54773 int rc = SQLITE_OK;
 
 
54774
54775 assert( cursorHoldsMutex(pCur) );
54776 assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
54777 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
54778 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54750,20 +54783,16 @@
54783 }
54784 sqlite3BtreeClearCursor(pCur);
54785 }
54786
54787 if( pCur->iPage>=0 ){
54788 while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]);
 
 
 
 
54789 }else if( pCur->pgnoRoot==0 ){
54790 pCur->eState = CURSOR_INVALID;
54791 return SQLITE_OK;
54792 }else{
54793 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
54794 pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
54795 if( rc!=SQLITE_OK ){
54796 pCur->eState = CURSOR_INVALID;
54797 return rc;
54798 }
@@ -54792,18 +54821,20 @@
54821 pCur->aiIdx[0] = 0;
54822 pCur->info.nSize = 0;
54823 pCur->atLast = 0;
54824 pCur->validNKey = 0;
54825
54826 if( pRoot->nCell>0 ){
54827 pCur->eState = CURSOR_VALID;
54828 }else if( !pRoot->leaf ){
54829 Pgno subpage;
54830 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
54831 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
54832 pCur->eState = CURSOR_VALID;
54833 rc = moveToChild(pCur, subpage);
54834 }else{
54835 pCur->eState = CURSOR_INVALID;
54836 }
54837 return rc;
54838 }
54839
54840 /*
@@ -55055,21 +55086,18 @@
55086 ** the entire cell by checking for the cases where the record is
55087 ** stored entirely within the b-tree page by inspecting the first
55088 ** 2 bytes of the cell.
55089 */
55090 nCell = pCell[0];
55091 if( nCell<=pPage->max1bytePayload ){
 
 
55092 /* This branch runs if the record-size field of the cell is a
55093 ** single byte varint and the record fits entirely on the main
55094 ** b-tree page. */
55095 testcase( pCell+nCell+1==pPage->aDataEnd );
55096 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55097 }else if( !(pCell[1] & 0x80)
55098 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
 
55099 ){
55100 /* The record-size field is a 2 byte varint and the record
55101 ** fits entirely on the main b-tree page. */
55102 testcase( pCell+nCell+2==pPage->aDataEnd );
55103 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -55889,11 +55917,11 @@
55917 nHeader = 0;
55918 if( !pPage->leaf ){
55919 nHeader += 4;
55920 }
55921 if( pPage->hasData ){
55922 nHeader += putVarint32(&pCell[nHeader], nData+nZero);
55923 }else{
55924 nData = nZero = 0;
55925 }
55926 nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
55927 btreeParseCellPtr(pPage, pCell, &info);
@@ -56017,11 +56045,10 @@
56045 */
56046 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
56047 u32 pc; /* Offset to cell content of cell being deleted */
56048 u8 *data; /* pPage->aData */
56049 u8 *ptr; /* Used to move bytes around within data[] */
 
56050 int rc; /* The return code */
56051 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
56052
56053 if( *pRC ) return;
56054
@@ -56042,17 +56069,12 @@
56069 rc = freeSpace(pPage, pc, sz);
56070 if( rc ){
56071 *pRC = rc;
56072 return;
56073 }
 
 
 
 
 
 
56074 pPage->nCell--;
56075 memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
56076 put2byte(&data[hdr+3], pPage->nCell);
56077 pPage->nFree += 2;
56078 }
56079
56080 /*
@@ -56085,13 +56107,10 @@
56107 int j; /* Loop counter */
56108 int end; /* First byte past the last cell pointer in data[] */
56109 int ins; /* Index in data[] where new cell pointer is inserted */
56110 int cellOffset; /* Address of first cell pointer in data[] */
56111 u8 *data; /* The content of the whole page */
 
 
 
56112 int nSkip = (iChild ? 4 : 0);
56113
56114 if( *pRC ) return;
56115
56116 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56138,17 +56157,11 @@
56157 pPage->nFree -= (u16)(2 + sz);
56158 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
56159 if( iChild ){
56160 put4byte(&data[idx], iChild);
56161 }
56162 memmove(&data[ins+2], &data[ins], end-ins);
 
 
 
 
 
 
56163 put2byte(&data[ins], idx);
56164 put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
56165 #ifndef SQLITE_OMIT_AUTOVACUUM
56166 if( pPage->pBt->autoVacuum ){
56167 /* The cell may contain a pointer to an overflow page. If so, write
@@ -58106,11 +58119,11 @@
58119 va_start(ap, zFormat);
58120 if( pCheck->errMsg.nChar ){
58121 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
58122 }
58123 if( zMsg1 ){
58124 sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1);
58125 }
58126 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
58127 va_end(ap);
58128 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
58129 pCheck->mallocFailed = 1;
@@ -59682,61 +59695,59 @@
59695 #endif
59696 }
59697
59698 /*
59699 ** Make sure pMem->z points to a writable allocation of at least
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){
 
 
 
 
59708 assert( 1 >=
59709 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
59710 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
59711 ((pMem->flags&MEM_Ephem) ? 1 : 0) +
59712 ((pMem->flags&MEM_Static) ? 1 : 0)
59713 );
59714 assert( (pMem->flags&MEM_RowSet)==0 );
59715
59716 /* If the bPreserve flag is set to true, then the memory cell must already
59717 ** contain a valid string or blob value. */
59718 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
59719 testcase( bPreserve && pMem->z==0 );
59720
59721 if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59722 if( n<32 ) n = 32;
59723 if( bPreserve && pMem->z==pMem->zMalloc ){
59724 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59725 bPreserve = 0;
59726 }else{
59727 sqlite3DbFree(pMem->db, pMem->zMalloc);
59728 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
59729 }
59730 if( pMem->zMalloc==0 ){
59731 sqlite3VdbeMemRelease(pMem);
59732 pMem->flags = MEM_Null;
59733 return SQLITE_NOMEM;
59734 }
59735 }
59736
59737 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
59738 memcpy(pMem->zMalloc, pMem->z, pMem->n);
59739 }
59740 if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
59741 assert( pMem->xDel!=SQLITE_DYNAMIC );
59742 pMem->xDel((void *)(pMem->z));
59743 }
59744
59745 pMem->z = pMem->zMalloc;
59746 pMem->flags &= ~(MEM_Ephem|MEM_Static);
 
 
 
 
59747 pMem->xDel = 0;
59748 return SQLITE_OK;
59749 }
59750
59751 /*
59752 ** Make the given Mem object MEM_Dyn. In other words, make it so
59753 ** that any TEXT or BLOB content is stored in memory obtained from
@@ -59918,14 +59929,16 @@
59929 ** inconsistent state, for example with (Mem.z==0) and
59930 ** (Mem.type==SQLITE_TEXT).
59931 */
59932 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
59933 VdbeMemRelease(p);
59934 if( p->zMalloc ){
59935 sqlite3DbFree(p->db, p->zMalloc);
59936 p->zMalloc = 0;
59937 }
59938 p->z = 0;
59939 assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */
 
59940 }
59941
59942 /*
59943 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
59944 ** If the double is out of range of a 64-bit signed integer then
@@ -60639,19 +60652,19 @@
60652 Index *pIdx = p->pIdx; /* Index being probed */
60653 int nByte; /* Bytes of space to allocate */
60654 int i; /* Counter variable */
60655 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
60656
60657 nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
60658 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
60659 if( pRec ){
60660 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
60661 if( pRec->pKeyInfo ){
60662 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
60663 assert( pRec->pKeyInfo->enc==ENC(db) );
60664 pRec->flags = UNPACKED_PREFIX_MATCH;
60665 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
60666 for(i=0; i<nCol; i++){
60667 pRec->aMem[i].flags = MEM_Null;
60668 pRec->aMem[i].type = SQLITE_NULL;
60669 pRec->aMem[i].db = db;
60670 }
@@ -60842,11 +60855,11 @@
60855 if( aRet==0 ){
60856 sqlite3_result_error_nomem(context);
60857 }else{
60858 aRet[0] = nSerial+1;
60859 sqlite3PutVarint(&aRet[1], iSerial);
60860 sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
60861 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
60862 sqlite3DbFree(db, aRet);
60863 }
60864 }
60865
@@ -60920,11 +60933,10 @@
60933
60934 if( !pExpr ){
60935 pVal = valueNew(db, &alloc);
60936 if( pVal ){
60937 sqlite3VdbeMemSetNull((Mem*)pVal);
 
60938 }
60939 }else if( pExpr->op==TK_VARIABLE
60940 || NEVER(pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
60941 ){
60942 Vdbe *v;
@@ -60936,20 +60948,17 @@
60948 rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
60949 if( rc==SQLITE_OK ){
60950 sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
60951 }
60952 pVal->db = pParse->db;
 
60953 sqlite3VdbeMemStoreType((Mem*)pVal);
60954 }
 
 
60955 }
60956 }else{
60957 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
 
60958 }
60959 *pbOk = (pVal!=0);
60960
60961 assert( pVal==0 || pVal->db==db );
60962 return rc;
60963 }
60964
@@ -63838,25 +63847,19 @@
63847 /*
63848 ** Write the serialized data blob for the value stored in pMem into
63849 ** buf. It is assumed that the caller has allocated sufficient space.
63850 ** Return the number of bytes written.
63851 **
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.
 
 
 
 
 
63855 **
63856 ** Return the number of bytes actually written into buf[]. The number
63857 ** of bytes in the zero-filled tail is included in the return value only
63858 ** if those bytes were zeroed in buf[].
63859 */
63860 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){
 
63861 u32 len;
63862
63863 /* Integer and Real */
63864 if( serial_type<=7 && serial_type>0 ){
63865 u64 v;
@@ -63867,11 +63870,10 @@
63870 swapMixedEndianFloat(v);
63871 }else{
63872 v = pMem->u.i;
63873 }
63874 len = i = sqlite3VdbeSerialTypeLen(serial_type);
 
63875 while( i-- ){
63876 buf[i] = (u8)(v&0xFF);
63877 v >>= 8;
63878 }
63879 return len;
@@ -63879,21 +63881,12 @@
63881
63882 /* String or blob */
63883 if( serial_type>=12 ){
63884 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
63885 == (int)sqlite3VdbeSerialTypeLen(serial_type) );
 
63886 len = pMem->n;
63887 memcpy(buf, pMem->z, len);
 
 
 
 
 
 
 
 
63888 return len;
63889 }
63890
63891 /* NULL or constants 0 or 1 */
63892 return 0;
@@ -65815,10 +65808,11 @@
65808 if( db->nVdbeExec>1 ){
65809 while( *zRawSql ){
65810 const char *zStart = zRawSql;
65811 while( *(zRawSql++)!='\n' && *zRawSql );
65812 sqlite3StrAccumAppend(&out, "-- ", 3);
65813 assert( (zRawSql - zStart) > 0 );
65814 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
65815 }
65816 }else{
65817 while( zRawSql[0] ){
65818 n = findNextHostParameter(zRawSql, &nToken);
@@ -66658,433 +66652,11 @@
66652 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
66653 #ifdef VDBE_PROFILE
66654 u64 start; /* CPU clock count at start of opcode */
66655 int origPc; /* Program counter at start of opcode */
66656 #endif
66657 /*** INSERT STACK UNION HERE ***/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66658
66659 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
66660 sqlite3VdbeEnter(p);
66661 if( p->rc==SQLITE_NOMEM ){
66662 /* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67326,20 +66898,18 @@
66898 /* Opcode: Yield P1 * * * *
66899 **
66900 ** Swap the program counter with the value in register P1.
66901 */
66902 case OP_Yield: { /* in1 */
 
66903 int pcDest;
 
66904 pIn1 = &aMem[pOp->p1];
66905 assert( (pIn1->flags & MEM_Dyn)==0 );
66906 pIn1->flags = MEM_Int;
66907 pcDest = (int)pIn1->u.i;
66908 pIn1->u.i = pc;
66909 REGISTER_TRACE(pOp->p1, pIn1);
66910 pc = pcDest;
66911 break;
66912 }
66913
66914 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
66915 ** Synopsis: if r[P3] null then halt
@@ -67384,14 +66954,12 @@
66954 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
66955 ** every program. So a jump past the last instruction of the program
66956 ** is the same as executing Halt.
66957 */
66958 case OP_Halt: {
 
66959 const char *zType;
66960 const char *zLogFmt;
 
66961
66962 if( pOp->p1==SQLITE_OK && p->pFrame ){
66963 /* Halt the sub-program. Return control to the parent frame. */
66964 VdbeFrame *pFrame = p->pFrame;
66965 p->pFrame = pFrame->pParent;
@@ -67398,11 +66966,11 @@
66966 p->nFrame--;
66967 sqlite3VdbeSetChanges(db, p->nChange);
66968 pc = sqlite3VdbeFrameRestore(pFrame);
66969 lastRowid = db->lastRowid;
66970 if( pOp->p2==OE_Ignore ){
66971 /* Instruction pc is the OP_Program that invoked the sub-program
66972 ** currently being halted. If the p2 instruction of this OP_Halt
66973 ** instruction is set to OE_Ignore, then the sub-program is throwing
66974 ** an IGNORE exception. In this case jump to the address specified
66975 ** as the p2 of the calling OP_Program. */
66976 pc = p->aOp[pc].p2-1;
@@ -67421,25 +66989,25 @@
66989 assert( pOp->p5>=1 && pOp->p5<=4 );
66990 testcase( pOp->p5==1 );
66991 testcase( pOp->p5==2 );
66992 testcase( pOp->p5==3 );
66993 testcase( pOp->p5==4 );
66994 zType = azType[pOp->p5-1];
66995 }else{
66996 zType = 0;
66997 }
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);
67003 }else if( pOp->p4.z ){
67004 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67005 }else{
67006 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
67007 }
67008 sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
67009 }
67010 rc = sqlite3VdbeHalt(p);
67011 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
67012 if( rc==SQLITE_BUSY ){
67013 p->rc = rc = SQLITE_BUSY;
@@ -67549,23 +67117,21 @@
67117 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
67118 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
67119 ** OP_Ne or OP_Eq.
67120 */
67121 case OP_Null: { /* out2-prerelease */
 
67122 int cnt;
67123 u16 nullFlag;
67124 cnt = pOp->p3-pOp->p2;
 
67125 assert( pOp->p3<=(p->nMem-p->nCursor) );
67126 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67127 while( cnt>0 ){
67128 pOut++;
67129 memAboutToChange(p, pOut);
67130 VdbeMemRelease(pOut);
67131 pOut->flags = nullFlag;
67132 cnt--;
67133 }
67134 break;
67135 }
67136
67137
@@ -67590,21 +67156,19 @@
67156 **
67157 ** If the parameter is named, then its name appears in P4 and P3==1.
67158 ** The P4 value is used by sqlite3_bind_parameter_name().
67159 */
67160 case OP_Variable: { /* out2-prerelease */
 
67161 Mem *pVar; /* Value being transferred */
 
67162
67163 assert( pOp->p1>0 && pOp->p1<=p->nVar );
67164 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67165 pVar = &p->aVar[pOp->p1 - 1];
67166 if( sqlite3VdbeMemTooBig(pVar) ){
67167 goto too_big;
67168 }
67169 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
67170 UPDATE_MAX_BLOBSIZE(pOut);
67171 break;
67172 }
67173
67174 /* Opcode: Move P1 P2 P3 * *
@@ -67614,43 +67178,41 @@
67178 ** registers P2..P2+P3. Registers P1..P1+P3 are
67179 ** left holding a NULL. It is an error for register ranges
67180 ** P1..P1+P3 and P2..P2+P3 to overlap.
67181 */
67182 case OP_Move: {
 
67183 char *zMalloc; /* Holding variable for allocated memory */
67184 int n; /* Number of registers left to copy */
67185 int p1; /* Register to copy from */
67186 int p2; /* Register to copy to */
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];
 
67196 do{
67197 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67198 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67199 assert( memIsValid(pIn1) );
67200 memAboutToChange(p, pOut);
67201 zMalloc = pOut->zMalloc;
67202 pOut->zMalloc = 0;
67203 sqlite3VdbeMemMove(pOut, pIn1);
67204 #ifdef SQLITE_DEBUG
67205 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
67206 pOut->pScopyFrom += p1 - pOp->p2;
67207 }
67208 #endif
67209 pIn1->zMalloc = zMalloc;
67210 REGISTER_TRACE(p2++, pOut);
67211 pIn1++;
67212 pOut++;
67213 }while( n-- );
67214 break;
67215 }
67216
67217 /* Opcode: Copy P1 P2 P3 * *
67218 ** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67659,26 +67221,24 @@
67221 **
67222 ** This instruction makes a deep copy of the value. A duplicate
67223 ** is made of any string or blob constant. See also OP_SCopy.
67224 */
67225 case OP_Copy: {
 
67226 int n;
 
67227
67228 n = pOp->p3;
67229 pIn1 = &aMem[pOp->p1];
67230 pOut = &aMem[pOp->p2];
67231 assert( pOut!=pIn1 );
67232 while( 1 ){
67233 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67234 Deephemeralize(pOut);
67235 #ifdef SQLITE_DEBUG
67236 pOut->pScopyFrom = 0;
67237 #endif
67238 REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
67239 if( (n--)==0 ) break;
67240 pOut++;
67241 pIn1++;
67242 }
67243 break;
67244 }
@@ -67715,14 +67275,12 @@
67275 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67276 ** structure to provide access to the top P1 values as the result
67277 ** row.
67278 */
67279 case OP_ResultRow: {
 
67280 Mem *pMem;
67281 int i;
 
67282 assert( p->nResColumn==pOp->p2 );
67283 assert( pOp->p1>0 );
67284 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67285
67286 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -67744,12 +67302,12 @@
67302 assert( db->flags&SQLITE_CountRows );
67303 assert( p->usesStmtJournal );
67304 break;
67305 }
67306
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
67309 ** modified to the user. This is the only way that a VM that
67310 ** opens a statement transaction may invoke this opcode.
67311 **
67312 ** In case this is such a statement, close any statement transaction
67313 ** opened by this VM before returning control to the user. This is to
@@ -67772,19 +67330,19 @@
67330
67331 /* Make sure the results of the current row are \000 terminated
67332 ** and have an assigned type. The results are de-ephemeralized as
67333 ** a side effect.
67334 */
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]);
67344 }
67345 if( db->mallocFailed ) goto no_mem;
67346
67347 /* Return SQLITE_ROW
67348 */
@@ -67805,13 +67363,11 @@
67363 ** It is illegal for P1 and P3 to be the same register. Sometimes,
67364 ** if P3 is the same register as P2, the implementation is able
67365 ** to avoid a memcpy().
67366 */
67367 case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
 
67368 i64 nByte;
 
67369
67370 pIn1 = &aMem[pOp->p1];
67371 pIn2 = &aMem[pOp->p2];
67372 pOut = &aMem[pOp->p3];
67373 assert( pIn1!=pOut );
@@ -67820,26 +67376,26 @@
67376 break;
67377 }
67378 if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
67379 Stringify(pIn1, encoding);
67380 Stringify(pIn2, encoding);
67381 nByte = pIn1->n + pIn2->n;
67382 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67383 goto too_big;
67384 }
67385 MemSetTypeFlag(pOut, MEM_Str);
67386 if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
67387 goto no_mem;
67388 }
67389 if( pOut!=pIn2 ){
67390 memcpy(pOut->z, pIn2->z, pIn2->n);
67391 }
67392 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67393 pOut->z[nByte]=0;
67394 pOut->z[nByte+1] = 0;
67395 pOut->flags |= MEM_Term;
67396 pOut->n = (int)nByte;
67397 pOut->enc = encoding;
67398 UPDATE_MAX_BLOBSIZE(pOut);
67399 break;
67400 }
67401
@@ -67884,83 +67440,81 @@
67440 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67441 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67442 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
67443 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
67444 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
 
67445 char bIntint; /* Started out as two integer operands */
67446 int flags; /* Combined MEM_* flags from both inputs */
67447 i64 iA; /* Integer value of left operand */
67448 i64 iB; /* Integer value of right operand */
67449 double rA; /* Real value of left operand */
67450 double rB; /* Real value of right operand */
 
67451
67452 pIn1 = &aMem[pOp->p1];
67453 applyNumericAffinity(pIn1);
67454 pIn2 = &aMem[pOp->p2];
67455 applyNumericAffinity(pIn2);
67456 pOut = &aMem[pOp->p3];
67457 flags = pIn1->flags | pIn2->flags;
67458 if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67459 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67460 iA = pIn1->u.i;
67461 iB = pIn2->u.i;
67462 bIntint = 1;
67463 switch( pOp->opcode ){
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;
67467 case OP_Divide: {
67468 if( iA==0 ) goto arithmetic_result_is_null;
67469 if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math;
67470 iB /= iA;
67471 break;
67472 }
67473 default: {
67474 if( iA==0 ) goto arithmetic_result_is_null;
67475 if( iA==-1 ) iA = 1;
67476 iB %= iA;
67477 break;
67478 }
67479 }
67480 pOut->u.i = iB;
67481 MemSetTypeFlag(pOut, MEM_Int);
67482 }else{
67483 bIntint = 0;
67484 fp_math:
67485 rA = sqlite3VdbeRealValue(pIn1);
67486 rB = sqlite3VdbeRealValue(pIn2);
67487 switch( pOp->opcode ){
67488 case OP_Add: rB += rA; break;
67489 case OP_Subtract: rB -= rA; break;
67490 case OP_Multiply: rB *= rA; break;
67491 case OP_Divide: {
67492 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67493 if( rA==(double)0 ) goto arithmetic_result_is_null;
67494 rB /= rA;
67495 break;
67496 }
67497 default: {
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);
67503 break;
67504 }
67505 }
67506 #ifdef SQLITE_OMIT_FLOATING_POINT
67507 pOut->u.i = rB;
67508 MemSetTypeFlag(pOut, MEM_Int);
67509 #else
67510 if( sqlite3IsNaN(rB) ){
67511 goto arithmetic_result_is_null;
67512 }
67513 pOut->r = rB;
67514 MemSetTypeFlag(pOut, MEM_Real);
67515 if( (flags & MEM_Real)==0 && !bIntint ){
67516 sqlite3VdbeIntegerAffinity(pOut);
67517 }
67518 #endif
67519 }
67520 break;
@@ -68009,85 +67563,83 @@
67563 ** invocation of this opcode.
67564 **
67565 ** See also: AggStep and AggFinal
67566 */
67567 case OP_Function: {
 
67568 int i;
67569 Mem *pArg;
67570 sqlite3_context ctx;
67571 sqlite3_value **apVal;
67572 int n;
 
67573
67574 n = pOp->p5;
67575 apVal = p->apArg;
67576 assert( apVal || n==0 );
67577 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
67578 pOut = &aMem[pOp->p3];
67579 memAboutToChange(p, pOut);
67580
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);
67590 }
67591
67592 assert( pOp->p4type==P4_FUNCDEF );
67593 ctx.pFunc = pOp->p4.pFunc;
67594 ctx.iOp = pc;
67595 ctx.pVdbe = p;
67596
67597 /* The output cell may already have a buffer allocated. Move
67598 ** the pointer to ctx.s so in case the user-function can use
67599 ** the already allocated buffer instead of allocating a new one.
67600 */
67601 memcpy(&ctx.s, pOut, sizeof(Mem));
67602 pOut->flags = MEM_Null;
67603 pOut->xDel = 0;
67604 pOut->zMalloc = 0;
67605 MemSetTypeFlag(&ctx.s, MEM_Null);
67606
67607 ctx.fErrorOrAux = 0;
67608 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67609 assert( pOp>aOp );
67610 assert( pOp[-1].p4type==P4_COLLSEQ );
67611 assert( pOp[-1].opcode==OP_CollSeq );
67612 ctx.pColl = pOp[-1].p4.pColl;
67613 }
67614 db->lastRowid = lastRowid;
67615 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
67616 lastRowid = db->lastRowid;
67617
67618 if( db->mallocFailed ){
67619 /* Even though a malloc() has failed, the implementation of the
67620 ** user function may have called an sqlite3_result_XXX() function
67621 ** to return a value. The following call releases any resources
67622 ** associated with such a value.
67623 */
67624 sqlite3VdbeMemRelease(&ctx.s);
67625 goto no_mem;
67626 }
67627
67628 /* If the function returned an error, throw an exception */
67629 if( ctx.fErrorOrAux ){
67630 if( ctx.isError ){
67631 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
67632 rc = ctx.isError;
67633 }
67634 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
67635 }
67636
67637 /* Copy the result of the function into register P3 */
67638 sqlite3VdbeChangeEncoding(&ctx.s, encoding);
67639 assert( pOut->flags==MEM_Null );
67640 memcpy(pOut, &ctx.s, sizeof(Mem));
67641 if( sqlite3VdbeMemTooBig(pOut) ){
67642 goto too_big;
67643 }
67644
67645 #if 0
@@ -68135,56 +67687,54 @@
67687 */
67688 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
67689 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
67690 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
67691 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
 
67692 i64 iA;
67693 u64 uA;
67694 i64 iB;
67695 u8 op;
 
67696
67697 pIn1 = &aMem[pOp->p1];
67698 pIn2 = &aMem[pOp->p2];
67699 pOut = &aMem[pOp->p3];
67700 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
67701 sqlite3VdbeMemSetNull(pOut);
67702 break;
67703 }
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 );
67713
67714 /* If shifting by a negative amount, shift in the other direction */
67715 if( iB<0 ){
67716 assert( OP_ShiftRight==OP_ShiftLeft+1 );
67717 op = 2*OP_ShiftLeft + 1 - op;
67718 iB = iB>(-64) ? -iB : 64;
67719 }
67720
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;
67729 /* Sign-extend on a right shift of a negative number */
67730 if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
67731 }
67732 memcpy(&iA, &uA, sizeof(iA));
67733 }
67734 }
67735 pOut->u.i = iA;
67736 MemSetTypeFlag(pOut, MEM_Int);
67737 break;
67738 }
67739
67740 /* Opcode: AddImm P1 P2 * * *
@@ -68434,37 +67984,35 @@
67984 case OP_Ne: /* same as TK_NE, jump, in1, in3 */
67985 case OP_Lt: /* same as TK_LT, jump, in1, in3 */
67986 case OP_Le: /* same as TK_LE, jump, in1, in3 */
67987 case OP_Gt: /* same as TK_GT, jump, in1, in3 */
67988 case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
 
67989 int res; /* Result of the comparison of pIn1 against pIn3 */
67990 char affinity; /* Affinity to use for comparison */
67991 u16 flags1; /* Copy of initial value of pIn1->flags */
67992 u16 flags3; /* Copy of initial value of pIn3->flags */
 
67993
67994 pIn1 = &aMem[pOp->p1];
67995 pIn3 = &aMem[pOp->p3];
67996 flags1 = pIn1->flags;
67997 flags3 = pIn3->flags;
67998 if( (flags1 | flags3)&MEM_Null ){
67999 /* One or both operands are NULL */
68000 if( pOp->p5 & SQLITE_NULLEQ ){
68001 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
68002 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68003 ** or not both operands are null.
68004 */
68005 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68006 assert( (flags1 & MEM_Cleared)==0 );
68007 if( (flags1&MEM_Null)!=0
68008 && (flags3&MEM_Null)!=0
68009 && (flags3&MEM_Cleared)==0
68010 ){
68011 res = 0; /* Results are equal */
68012 }else{
68013 res = 1; /* Results are not equal */
68014 }
68015 }else{
68016 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68017 ** then the result is always NULL.
68018 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68478,44 +68026,44 @@
68026 }
68027 break;
68028 }
68029 }else{
68030 /* Neither operand is NULL. Do a comparison. */
68031 affinity = pOp->p5 & SQLITE_AFF_MASK;
68032 if( affinity ){
68033 applyAffinity(pIn1, affinity, encoding);
68034 applyAffinity(pIn3, affinity, encoding);
68035 if( db->mallocFailed ) goto no_mem;
68036 }
68037
68038 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
68039 ExpandBlob(pIn1);
68040 ExpandBlob(pIn3);
68041 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68042 }
68043 switch( pOp->opcode ){
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;
68050 }
68051
68052 if( pOp->p5 & SQLITE_STOREP2 ){
68053 pOut = &aMem[pOp->p2];
68054 memAboutToChange(p, pOut);
68055 MemSetTypeFlag(pOut, MEM_Int);
68056 pOut->u.i = res;
68057 REGISTER_TRACE(pOp->p2, pOut);
68058 }else if( res ){
68059 pc = pOp->p2-1;
68060 }
68061
68062 /* Undo any changes made by applyAffinity() to the input registers. */
68063 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68064 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
68065 break;
68066 }
68067
68068 /* Opcode: Permutation * * * P4 *
68069 **
@@ -68551,51 +68099,49 @@
68099 ** The comparison is a sort comparison, so NULLs compare equal,
68100 ** NULLs are less than numbers, numbers are less than strings,
68101 ** and strings are less than blobs.
68102 */
68103 case OP_Compare: {
 
68104 int n;
68105 int i;
68106 int p1;
68107 int p2;
68108 const KeyInfo *pKeyInfo;
68109 int idx;
68110 CollSeq *pColl; /* Collating sequence to use on this term */
68111 int bRev; /* True for DESCENDING sort order */
 
68112
68113 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
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;
68120 #if SQLITE_DEBUG
68121 if( aPermute ){
68122 int k, mx = 0;
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 );
68126 }else{
68127 assert( p1>0 && p1+n<=(p->nMem-p->nCursor)+1 );
68128 assert( p2>0 && p2+n<=(p->nMem-p->nCursor)+1 );
68129 }
68130 #endif /* SQLITE_DEBUG */
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);
68141 if( iCompare ){
68142 if( bRev ) iCompare = -iCompare;
68143 break;
68144 }
68145 }
68146 aPermute = 0;
68147 break;
@@ -68638,39 +68184,37 @@
68184 ** even if the other input is NULL. A NULL and false or two NULLs
68185 ** give a NULL output.
68186 */
68187 case OP_And: /* same as TK_AND, in1, in2, out3 */
68188 case OP_Or: { /* same as TK_OR, in1, in2, out3 */
 
68189 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68190 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
 
68191
68192 pIn1 = &aMem[pOp->p1];
68193 if( pIn1->flags & MEM_Null ){
68194 v1 = 2;
68195 }else{
68196 v1 = sqlite3VdbeIntValue(pIn1)!=0;
68197 }
68198 pIn2 = &aMem[pOp->p2];
68199 if( pIn2->flags & MEM_Null ){
68200 v2 = 2;
68201 }else{
68202 v2 = sqlite3VdbeIntValue(pIn2)!=0;
68203 }
68204 if( pOp->opcode==OP_And ){
68205 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68206 v1 = and_logic[v1*3+v2];
68207 }else{
68208 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68209 v1 = or_logic[v1*3+v2];
68210 }
68211 pOut = &aMem[pOp->p3];
68212 if( v1==2 ){
68213 MemSetTypeFlag(pOut, MEM_Null);
68214 }else{
68215 pOut->u.i = v1;
68216 MemSetTypeFlag(pOut, MEM_Int);
68217 }
68218 break;
68219 }
68220
@@ -68737,25 +68281,23 @@
68281 ** is considered false if it has a numeric value of zero. If the value
68282 ** in P1 is NULL then take the jump if P3 is zero.
68283 */
68284 case OP_If: /* jump, in1 */
68285 case OP_IfNot: { /* jump, in1 */
 
68286 int c;
 
68287 pIn1 = &aMem[pOp->p1];
68288 if( pIn1->flags & MEM_Null ){
68289 c = pOp->p3;
68290 }else{
68291 #ifdef SQLITE_OMIT_FLOATING_POINT
68292 c = sqlite3VdbeIntValue(pIn1)!=0;
68293 #else
68294 c = sqlite3VdbeRealValue(pIn1)!=0.0;
68295 #endif
68296 if( pOp->opcode==OP_IfNot ) c = !c;
68297 }
68298 if( c ){
68299 pc = pOp->p2-1;
68300 }
68301 break;
68302 }
68303
@@ -68809,11 +68351,10 @@
68351 ** the result is guaranteed to only be used as the argument of a length()
68352 ** or typeof() function, respectively. The loading of large blobs can be
68353 ** skipped for length() and all content loading can be skipped for typeof().
68354 */
68355 case OP_Column: {
 
68356 i64 payloadSize64; /* Number of bytes in the record */
68357 int p2; /* column number to retrieve */
68358 VdbeCursor *pC; /* The VDBE cursor */
68359 BtCursor *pCrsr; /* The BTree cursor */
68360 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
@@ -68828,89 +68369,88 @@
68369 u32 offset; /* Offset into the data */
68370 u32 szField; /* Number of bytes in the content of a field */
68371 u32 avail; /* Number of bytes of available data */
68372 u32 t; /* A type code from the record header */
68373 Mem *pReg; /* PseudoTable input register */
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;
 
68452 }
68453
68454 /* Make sure a corrupt database has not given us an oversize header.
68455 ** Do this now to avoid an oversize memory allocation.
68456 **
@@ -68918,154 +68458,154 @@
68458 ** types use so much data space that there can only be 4096 and 32 of
68459 ** them, respectively. So the maximum header length results from a
68460 ** 3-byte type for each of the maximum of 32768 columns plus three
68461 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68462 */
68463 if( offset > 98307 || offset > pC->payloadSize ){
68464 rc = SQLITE_CORRUPT_BKPT;
68465 goto op_column_error;
68466 }
68467 }
68468
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[].
68471 */
68472 if( pC->nHdrParsed<=p2 ){
68473 /* If there is more header available for parsing in the record, try
68474 ** to extract additional fields up through the p2+1-th field
68475 */
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);
68482 if( rc!=SQLITE_OK ){
68483 goto op_column_error;
68484 }
68485 zData = (u8*)sMem.z;
68486 }else{
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 );
68496 do{
68497 if( zHdr[0]<0x80 ){
68498 t = zHdr[0];
68499 zHdr++;
68500 }else{
68501 zHdr += sqlite3GetVarint32(zHdr, &t);
68502 }
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 */
68508 break;
68509 }
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
68520 /* If we have read more header data than was contained in the header,
68521 ** or if the end of the last field appears to be past the end of the
68522 ** record, or if the end of the last field appears to be before the end
68523 ** of the record (when all fields present), then we must be dealing
68524 ** with a corrupt database.
68525 */
68526 if( (zHdr > zEndHdr)
68527 || (offset > pC->payloadSize)
68528 || (zHdr==zEndHdr && offset!=pC->payloadSize)
68529 ){
68530 rc = SQLITE_CORRUPT_BKPT;
68531 goto op_column_error;
68532 }
68533 }
68534
68535 /* If after trying to extra new entries from the header, nHdrParsed is
68536 ** still not up to p2, that means that the record has fewer than p2
68537 ** columns. So the result will be either the default value or a NULL.
68538 */
68539 if( pC->nHdrParsed<=p2 ){
68540 if( pOp->p4type==P4_MEM ){
68541 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
68542 }else{
68543 MemSetTypeFlag(pDest, MEM_Null);
68544 }
68545 goto op_column_out;
68546 }
68547 }
68548
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
68551 ** all valid.
68552 */
68553 assert( p2<pC->nHdrParsed );
68554 assert( rc==SQLITE_OK );
68555 if( pC->szRow>=aOffset[p2+1] ){
68556 /* This is the common case where the desired content fits on the original
68557 ** page - where the content is not on an overflow page */
68558 VdbeMemRelease(pDest);
68559 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
68560 }else{
68561 /* This branch happens only when content is on overflow pages */
68562 t = aType[p2];
68563 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68564 && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
68565 || (len = sqlite3VdbeSerialTypeLen(t))==0
68566 ){
68567 /* Content is irrelevant for the typeof() function and for
68568 ** the length(X) function if X is a blob. So we might as well use
68569 ** bogus content rather than reading content from disk. NULL works
68570 ** for text and blob and whatever is in the payloadSize64 variable
68571 ** will work for everything else. Content is also irrelevant if
68572 ** the content length is 0. */
68573 zData = t<=13 ? (u8*)&payloadSize64 : 0;
68574 sMem.zMalloc = 0;
68575 }else{
68576 memset(&sMem, 0, sizeof(sMem));
68577 sqlite3VdbeMemMove(&sMem, pDest);
68578 rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
68579 &sMem);
68580 if( rc!=SQLITE_OK ){
68581 goto op_column_error;
68582 }
68583 zData = (u8*)sMem.z;
68584 }
68585 sqlite3VdbeSerialGet(zData, t, pDest);
68586 /* If we dynamically allocated space to hold the data (in the
68587 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68588 ** dynamically allocated space over to the pDest structure.
68589 ** This prevents a memory copy. */
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;
68598 }
68599 }
68600 pDest->enc = encoding;
68601
68602 op_column_out:
68603 Deephemeralize(pDest);
68604 op_column_error:
68605 UPDATE_MAX_BLOBSIZE(pDest);
68606 REGISTER_TRACE(pOp->p3, pDest);
68607 break;
68608 }
68609
68610 /* Opcode: Affinity P1 P2 * P4 *
68611 ** Synopsis: affinity(r[P1@P2])
@@ -69075,24 +68615,22 @@
68615 ** P4 is a string that is P2 characters long. The nth character of the
68616 ** string indicates the column affinity that should be used for the nth
68617 ** memory cell in the range.
68618 */
68619 case OP_Affinity: {
 
68620 const char *zAffinity; /* The affinity to be applied */
68621 char cAff; /* A single character of affinity */
 
68622
68623 zAffinity = pOp->p4.z;
68624 assert( zAffinity!=0 );
68625 assert( zAffinity[pOp->p2]==0 );
68626 pIn1 = &aMem[pOp->p1];
68627 while( (cAff = *(zAffinity++))!=0 ){
68628 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
68629 assert( memIsValid(pIn1) );
68630 ExpandBlob(pIn1);
68631 applyAffinity(pIn1, cAff, encoding);
68632 pIn1++;
68633 }
68634 break;
68635 }
68636
@@ -69111,11 +68649,10 @@
68649 ** macros defined in sqliteInt.h.
68650 **
68651 ** If P4 is NULL then all index fields have the affinity NONE.
68652 */
68653 case OP_MakeRecord: {
 
68654 u8 *zNewRecord; /* A buffer to hold the data for the new record */
68655 Mem *pRec; /* The new record */
68656 u64 nData; /* Number of bytes of data space */
68657 int nHdr; /* Number of bytes of header space */
68658 i64 nByte; /* Data space required for this record */
@@ -69125,106 +68662,123 @@
68662 Mem *pData0; /* First field to be combined into the record */
68663 Mem *pLast; /* Last field of the record */
68664 int nField; /* Number of fields in the record */
68665 char *zAffinity; /* The affinity string for the record */
68666 int file_format; /* File format to use for encoding */
68667 int i; /* Space used in zNewRecord[] header */
68668 int j; /* Space used in zNewRecord[] content */
68669 int len; /* Length of a field */
 
68670
68671 /* Assuming the record contains N fields, the record format looks
68672 ** like this:
68673 **
68674 ** ------------------------------------------------------------------------
68675 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
68676 ** ------------------------------------------------------------------------
68677 **
68678 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
68679 ** and so froth.
68680 **
68681 ** Each type field is a varint representing the serial type of the
68682 ** corresponding data element (see sqlite3VdbeSerialType()). The
68683 ** hdr-size field is also a varint which is the offset from the beginning
68684 ** of the record to data0.
68685 */
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;
68696
68697 /* Identify the output register */
68698 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
68699 pOut = &aMem[pOp->p3];
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 }
68711
68712 /* Loop through the elements that will make up the record to figure
68713 ** out how much space is required for the new record.
68714 */
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 );
 
 
68733
68734 /* Add the initial header varint and total the size */
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++;
68745 }
68746 nByte = nHdr+nData;
68747 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
68748 goto too_big;
68749 }
68750
68751 /* Make sure the output register has a buffer large enough to store
68752 ** the new record. The output register (pOp->p3) is not allowed to
68753 ** be one of the input registers (because the following call to
68754 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
68755 */
68756 if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){
68757 goto no_mem;
68758 }
68759 zNewRecord = (u8 *)pOut->z;
68760
68761 /* Write the record */
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 );
68773
68774 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68775 pOut->n = (int)nByte;
68776 pOut->flags = MEM_Blob | MEM_Dyn;
68777 pOut->xDel = 0;
68778 if( nZero ){
68779 pOut->u.nZero = nZero;
68780 pOut->flags |= MEM_Zero;
68781 }
68782 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
68783 REGISTER_TRACE(pOp->p3, pOut);
68784 UPDATE_MAX_BLOBSIZE(pOut);
@@ -69237,19 +68791,18 @@
68791 ** Store the number of entries (an integer value) in the table or index
68792 ** opened by cursor P1 in register P2
68793 */
68794 #ifndef SQLITE_OMIT_BTREECOUNT
68795 case OP_Count: { /* out2-prerelease */
 
68796 i64 nEntry;
68797 BtCursor *pCrsr;
 
68798
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;
68804 break;
68805 }
68806 #endif
68807
68808 /* Opcode: Savepoint P1 * * P4 *
@@ -69257,43 +68810,41 @@
68810 ** Open, release or rollback the savepoint named by parameter P4, depending
68811 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
68812 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
68813 */
68814 case OP_Savepoint: {
 
68815 int p1; /* Value of P1 operand */
68816 char *zName; /* Name of savepoint */
68817 int nName;
68818 Savepoint *pNew;
68819 Savepoint *pSavepoint;
68820 Savepoint *pTmp;
68821 int iSavepoint;
68822 int ii;
 
68823
68824 p1 = pOp->p1;
68825 zName = pOp->p4.z;
68826
68827 /* Assert that the p1 parameter is valid. Also that if there is no open
68828 ** transaction, then there cannot be any savepoints.
68829 */
68830 assert( db->pSavepoint==0 || db->autoCommit==0 );
68831 assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK );
68832 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
68833 assert( checkSavepointCount(db) );
68834 assert( p->bIsReader );
68835
68836 if( p1==SAVEPOINT_BEGIN ){
68837 if( db->nVdbeWrite>0 ){
68838 /* A new savepoint cannot be created if there are active write
68839 ** statements (i.e. open read/write incremental blob handles).
68840 */
68841 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
68842 "SQL statements in progress");
68843 rc = SQLITE_BUSY;
68844 }else{
68845 nName = sqlite3Strlen30(zName);
68846
68847 #ifndef SQLITE_OMIT_VIRTUALTABLE
68848 /* This call is Ok even if this savepoint is actually a transaction
68849 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
68850 ** If this is a transaction savepoint being opened, it is guaranteed
@@ -69303,62 +68854,62 @@
68854 db->nStatement+db->nSavepoint);
68855 if( rc!=SQLITE_OK ) goto abort_due_to_error;
68856 #endif
68857
68858 /* Create a new savepoint structure. */
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
68864 /* If there is no open transaction, then mark this as a special
68865 ** "transaction savepoint". */
68866 if( db->autoCommit ){
68867 db->autoCommit = 0;
68868 db->isTransactionSavepoint = 1;
68869 }else{
68870 db->nSavepoint++;
68871 }
68872
68873 /* Link the new savepoint into the database handle's list. */
68874 pNew->pNext = db->pSavepoint;
68875 db->pSavepoint = pNew;
68876 pNew->nDeferredCons = db->nDeferredCons;
68877 pNew->nDeferredImmCons = db->nDeferredImmCons;
68878 }
68879 }
68880 }else{
68881 iSavepoint = 0;
68882
68883 /* Find the named savepoint. If there is no such savepoint, then an
68884 ** an error is returned to the user. */
68885 for(
68886 pSavepoint = db->pSavepoint;
68887 pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName);
68888 pSavepoint = pSavepoint->pNext
68889 ){
68890 iSavepoint++;
68891 }
68892 if( !pSavepoint ){
68893 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName);
68894 rc = SQLITE_ERROR;
68895 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
68896 /* It is not possible to release (commit) a savepoint if there are
68897 ** active write statements.
68898 */
68899 sqlite3SetString(&p->zErrMsg, db,
68900 "cannot release savepoint - SQL statements in progress"
68901 );
68902 rc = SQLITE_BUSY;
68903 }else{
68904
68905 /* Determine whether or not this is a transaction savepoint. If so,
68906 ** and this is a RELEASE command, then the current transaction
68907 ** is committed.
68908 */
68909 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
68910 if( isTransaction && p1==SAVEPOINT_RELEASE ){
68911 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
68912 goto vdbe_return;
68913 }
68914 db->autoCommit = 1;
68915 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69368,56 +68919,56 @@
68919 goto vdbe_return;
68920 }
68921 db->isTransactionSavepoint = 0;
68922 rc = p->rc;
68923 }else{
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);
68928 }
68929 }
68930 for(ii=0; ii<db->nDb; ii++){
68931 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
68932 if( rc!=SQLITE_OK ){
68933 goto abort_due_to_error;
68934 }
68935 }
68936 if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
68937 sqlite3ExpirePreparedStatements(db);
68938 sqlite3ResetAllSchemasOfConnection(db);
68939 db->flags = (db->flags | SQLITE_InternChanges);
68940 }
68941 }
68942
68943 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
68944 ** savepoints nested inside of the savepoint being operated on. */
68945 while( db->pSavepoint!=pSavepoint ){
68946 pTmp = db->pSavepoint;
68947 db->pSavepoint = pTmp->pNext;
68948 sqlite3DbFree(db, pTmp);
68949 db->nSavepoint--;
68950 }
68951
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
68954 ** constraint violations present in the database to the value stored
68955 ** when the savepoint was created. */
68956 if( p1==SAVEPOINT_RELEASE ){
68957 assert( pSavepoint==db->pSavepoint );
68958 db->pSavepoint = pSavepoint->pNext;
68959 sqlite3DbFree(db, pSavepoint);
68960 if( !isTransaction ){
68961 db->nSavepoint--;
68962 }
68963 }else{
68964 db->nDeferredCons = pSavepoint->nDeferredCons;
68965 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
68966 }
68967
68968 if( !isTransaction ){
68969 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
68970 if( rc!=SQLITE_OK ) goto abort_due_to_error;
68971 }
68972 }
68973 }
68974
@@ -69432,54 +68983,52 @@
68983 ** there are active writing VMs or active VMs that use shared cache.
68984 **
68985 ** This instruction causes the VM to halt.
68986 */
68987 case OP_AutoCommit: {
 
68988 int desiredAutoCommit;
68989 int iRollback;
68990 int turnOnAC;
 
68991
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 );
68997 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
68998 assert( p->bIsReader );
68999
69000 #if 0
69001 if( turnOnAC && iRollback && db->nVdbeActive>1 ){
69002 /* If this instruction implements a ROLLBACK and other VMs are
69003 ** still running, and a transaction is active, return an error indicating
69004 ** that the other VMs must complete first.
69005 */
69006 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
69007 "SQL statements in progress");
69008 rc = SQLITE_BUSY;
69009 }else
69010 #endif
69011 if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
69012 /* If this instruction implements a COMMIT and other VMs are writing
69013 ** return an error indicating that the other VMs must complete first.
69014 */
69015 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
69016 "SQL statements in progress");
69017 rc = SQLITE_BUSY;
69018 }else if( desiredAutoCommit!=db->autoCommit ){
69019 if( iRollback ){
69020 assert( desiredAutoCommit==1 );
69021 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69022 db->autoCommit = 1;
69023 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69024 goto vdbe_return;
69025 }else{
69026 db->autoCommit = (u8)desiredAutoCommit;
69027 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
69028 p->pc = pc;
69029 db->autoCommit = (u8)(1-desiredAutoCommit);
69030 p->rc = rc = SQLITE_BUSY;
69031 goto vdbe_return;
69032 }
69033 }
69034 assert( db->nStatement==0 );
@@ -69490,14 +69039,14 @@
69039 rc = SQLITE_ERROR;
69040 }
69041 goto vdbe_return;
69042 }else{
69043 sqlite3SetString(&p->zErrMsg, db,
69044 (!desiredAutoCommit)?"cannot start a transaction within a transaction":(
69045 (iRollback)?"cannot rollback - no transaction is active":
69046 "cannot commit - no transaction is active"));
69047
69048 rc = SQLITE_ERROR;
69049 }
69050 break;
69051 }
69052
@@ -69531,48 +69080,46 @@
69080 ** will automatically commit when the VDBE halts.
69081 **
69082 ** If P2 is zero, then a read-lock is obtained on the database file.
69083 */
69084 case OP_Transaction: {
 
69085 Btree *pBt;
 
69086
69087 assert( p->bIsReader );
69088 assert( p->readOnly==0 || pOp->p2==0 );
69089 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69090 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69091 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
69092 rc = SQLITE_READONLY;
69093 goto abort_due_to_error;
69094 }
69095 pBt = db->aDb[pOp->p1].pBt;
69096
69097 if( pBt ){
69098 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
69099 if( rc==SQLITE_BUSY ){
69100 p->pc = pc;
69101 p->rc = rc = SQLITE_BUSY;
69102 goto vdbe_return;
69103 }
69104 if( rc!=SQLITE_OK ){
69105 goto abort_due_to_error;
69106 }
69107
69108 if( pOp->p2 && p->usesStmtJournal
69109 && (db->autoCommit==0 || db->nVdbeRead>1)
69110 ){
69111 assert( sqlite3BtreeIsInTrans(pBt) );
69112 if( p->iStatement==0 ){
69113 assert( db->nStatement>=0 && db->nSavepoint>=0 );
69114 db->nStatement++;
69115 p->iStatement = db->nSavepoint + db->nStatement;
69116 }
69117
69118 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
69119 if( rc==SQLITE_OK ){
69120 rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
69121 }
69122
69123 /* Store the current value of the database handles deferred constraint
69124 ** counter. If the statement transaction needs to be rolled back,
69125 ** the value of this counter needs to be restored too. */
@@ -69594,26 +69141,24 @@
69141 ** There must be a read-lock on the database (either a transaction
69142 ** must be started or there must be an open cursor) before
69143 ** executing this instruction.
69144 */
69145 case OP_ReadCookie: { /* out2-prerelease */
 
69146 int iMeta;
69147 int iDb;
69148 int iCookie;
 
69149
69150 assert( p->bIsReader );
69151 iDb = pOp->p1;
69152 iCookie = pOp->p3;
69153 assert( pOp->p3<SQLITE_N_BTREE_META );
69154 assert( iDb>=0 && iDb<db->nDb );
69155 assert( db->aDb[iDb].pBt!=0 );
69156 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
69157
69158 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
69159 pOut->u.i = iMeta;
69160 break;
69161 }
69162
69163 /* Opcode: SetCookie P1 P2 P3 * *
69164 **
@@ -69624,31 +69169,29 @@
69169 ** database file used to store temporary tables.
69170 **
69171 ** A transaction must be started before executing this opcode.
69172 */
69173 case OP_SetCookie: { /* in3 */
 
69174 Db *pDb;
 
69175 assert( pOp->p2<SQLITE_N_BTREE_META );
69176 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69177 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69178 assert( p->readOnly==0 );
69179 pDb = &db->aDb[pOp->p1];
69180 assert( pDb->pBt!=0 );
69181 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69182 pIn3 = &aMem[pOp->p3];
69183 sqlite3VdbeMemIntegerify(pIn3);
69184 /* See note about index shifting on OP_ReadCookie */
69185 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
69186 if( pOp->p2==BTREE_SCHEMA_VERSION ){
69187 /* When the schema cookie changes, record the new cookie internally */
69188 pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69189 db->flags |= SQLITE_InternChanges;
69190 }else if( pOp->p2==BTREE_FILE_FORMAT ){
69191 /* Record changes in the file format */
69192 pDb->pSchema->file_format = (u8)pIn3->u.i;
69193 }
69194 if( pOp->p1==1 ){
69195 /* Invalidate all prepared statements whenever the TEMP database
69196 ** schema is changed. Ticket #1644 */
69197 sqlite3ExpirePreparedStatements(db);
@@ -69674,44 +69217,42 @@
69217 ** Either a transaction needs to have been started or an OP_Open needs
69218 ** to be executed (to establish a read lock) before this opcode is
69219 ** invoked.
69220 */
69221 case OP_VerifyCookie: {
 
69222 int iMeta;
69223 int iGen;
69224 Btree *pBt;
 
69225
69226 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69227 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69228 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69229 assert( p->bIsReader );
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;
69234 }else{
69235 iGen = iMeta = 0;
69236 }
69237 if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
69238 sqlite3DbFree(db, p->zErrMsg);
69239 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69240 /* If the schema-cookie from the database file matches the cookie
69241 ** stored with the in-memory representation of the schema, do
69242 ** not reload the schema from the database file.
69243 **
69244 ** If virtual-tables are in use, this is not just an optimization.
69245 ** Often, v-tables store their data in other SQLite tables, which
69246 ** are queried from within xNext() and other v-table methods using
69247 ** prepared queries. If such a query is out-of-date, we do not want to
69248 ** discard the database schema, as the user code implementing the
69249 ** v-table would have to be ready for the sqlite3_vtab structure itself
69250 ** to be invalidated whenever sqlite3_step() is called from within
69251 ** a v-table method.
69252 */
69253 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69254 sqlite3ResetOneSchema(db, pOp->p1);
69255 }
69256
69257 p->expired = 1;
69258 rc = SQLITE_SCHEMA;
@@ -69770,20 +69311,18 @@
69311 **
69312 ** See also OpenRead.
69313 */
69314 case OP_OpenRead:
69315 case OP_OpenWrite: {
 
69316 int nField;
69317 KeyInfo *pKeyInfo;
69318 int p2;
69319 int iDb;
69320 int wrFlag;
69321 Btree *pX;
69322 VdbeCursor *pCur;
69323 Db *pDb;
 
69324
69325 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
69326 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
69327 assert( p->bIsReader );
69328 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69791,74 +69330,74 @@
69330 if( p->expired ){
69331 rc = SQLITE_ABORT;
69332 break;
69333 }
69334
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 );
69344 if( pOp->opcode==OP_OpenWrite ){
69345 wrFlag = 1;
69346 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
69347 if( pDb->pSchema->file_format < p->minWriteFileFormat ){
69348 p->minWriteFileFormat = pDb->pSchema->file_format;
69349 }
69350 }else{
69351 wrFlag = 0;
69352 }
69353 if( pOp->p5 & OPFLAG_P2ISREG ){
69354 assert( p2>0 );
69355 assert( p2<=(p->nMem-p->nCursor) );
69356 pIn2 = &aMem[p2];
69357 assert( memIsValid(pIn2) );
69358 assert( (pIn2->flags & MEM_Int)!=0 );
69359 sqlite3VdbeMemIntegerify(pIn2);
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.
69363 ** If there were a failure, the prepared statement would have halted
69364 ** before reaching this instruction. */
69365 if( NEVER(p2<2) ) {
69366 rc = SQLITE_CORRUPT_BKPT;
69367 goto abort_due_to_error;
69368 }
69369 }
69370 if( pOp->p4type==P4_KEYINFO ){
69371 pKeyInfo = pOp->p4.pKeyInfo;
69372 assert( pKeyInfo->enc==ENC(db) );
69373 assert( pKeyInfo->db==db );
69374 nField = pKeyInfo->nField+pKeyInfo->nXField;
69375 }else if( pOp->p4type==P4_INT32 ){
69376 nField = pOp->p4.i;
69377 }
69378 assert( pOp->p1>=0 );
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;
69387 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69388 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69389
69390 /* Since it performs no memory allocation or IO, the only value that
69391 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69392 assert( rc==SQLITE_OK );
69393
69394 /* Set the VdbeCursor.isTable variable. Previous versions of
69395 ** SQLite used to check if the root-page flags were sane at this point
69396 ** and report database corruption if they were not, but this check has
69397 ** since moved into the btree layer. */
69398 pCur->isTable = pOp->p4type!=P4_KEYINFO;
69399 break;
69400 }
69401
69402 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69403 ** Synopsis: nColumn=P2
@@ -69886,55 +69425,53 @@
69425 ** by this opcode will be used for automatically created transient
69426 ** indices in joins.
69427 */
69428 case OP_OpenAutoindex:
69429 case OP_OpenEphemeral: {
 
69430 VdbeCursor *pCx;
69431 KeyInfo *pKeyInfo;
 
69432
69433 static const int vfsFlags =
69434 SQLITE_OPEN_READWRITE |
69435 SQLITE_OPEN_CREATE |
69436 SQLITE_OPEN_EXCLUSIVE |
69437 SQLITE_OPEN_DELETEONCLOSE |
69438 SQLITE_OPEN_TRANSIENT_DB;
69439 assert( pOp->p1>=0 );
69440 assert( pOp->p2>=0 );
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,
69445 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
69446 if( rc==SQLITE_OK ){
69447 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
69448 }
69449 if( rc==SQLITE_OK ){
69450 /* If a transient index is required, create it by calling
69451 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
69452 ** opening it. If a transient table is required, just use the
69453 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69454 */
69455 if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69456 int pgno;
69457 assert( pOp->p4type==P4_KEYINFO );
69458 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69459 if( rc==SQLITE_OK ){
69460 assert( pgno==MASTER_ROOT+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;
69470 }
69471 }
69472 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69473 break;
69474 }
69475
69476 /* Opcode: SorterOpen P1 * * P4 *
69477 **
@@ -69941,22 +69478,20 @@
69478 ** This opcode works like OP_OpenEphemeral except that it opens
69479 ** a transient index that is specifically designed to sort large
69480 ** tables using an external merge-sort algorithm.
69481 */
69482 case OP_SorterOpen: {
 
69483 VdbeCursor *pCx;
 
69484
69485 assert( pOp->p1>=0 );
69486 assert( pOp->p2>=0 );
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);
69493 break;
69494 }
69495
69496 /* Opcode: OpenPseudo P1 P2 P3 * P5
69497 ** Synopsis: content in r[P2@P3]
@@ -69974,22 +69509,20 @@
69509 **
69510 ** P3 is the number of fields in the records that will be stored by
69511 ** the pseudo-table.
69512 */
69513 case OP_OpenPseudo: {
 
69514 VdbeCursor *pCx;
 
69515
69516 assert( pOp->p1>=0 );
69517 assert( pOp->p3>=0 );
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;
69524 break;
69525 }
69526
69527 /* Opcode: Close P1 * * * *
69528 **
@@ -70061,39 +69594,37 @@
69594 */
69595 case OP_SeekLt: /* jump, in3 */
69596 case OP_SeekLe: /* jump, in3 */
69597 case OP_SeekGe: /* jump, in3 */
69598 case OP_SeekGt: { /* jump, in3 */
 
69599 int res;
69600 int oc;
69601 VdbeCursor *pC;
69602 UnpackedRecord r;
69603 int nField;
69604 i64 iKey; /* The rowid we are to seek to */
 
69605
69606 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69607 assert( pOp->p2!=0 );
69608 pC = p->apCsr[pOp->p1];
69609 assert( pC!=0 );
69610 assert( pC->pseudoTableReg==0 );
69611 assert( OP_SeekLe == OP_SeekLt+1 );
69612 assert( OP_SeekGe == OP_SeekLt+2 );
69613 assert( OP_SeekGt == OP_SeekLt+3 );
69614 assert( pC->isOrdered );
69615 assert( pC->pCursor!=0 );
69616 oc = pOp->opcode;
69617 pC->nullRow = 0;
69618 if( pC->isTable ){
69619 /* The input value in P3 might be of any type: integer, real, string,
69620 ** blob, or NULL. But it needs to be an integer before we can do
69621 ** the seek, so covert it. */
69622 pIn3 = &aMem[pOp->p3];
69623 applyNumericAffinity(pIn3);
69624 iKey = sqlite3VdbeIntValue(pIn3);
69625 pC->rowidIsValid = 0;
69626
69627 /* If the P3 value could not be converted into an integer without
69628 ** loss of information, then special processing is required... */
69629 if( (pIn3->flags & MEM_Int)==0 ){
69630 if( (pIn3->flags & MEM_Real)==0 ){
@@ -70101,100 +69632,100 @@
69632 ** then the seek is not possible, so jump to P2 */
69633 pc = pOp->p2 - 1;
69634 break;
69635 }
69636
69637 /* If the approximation iKey is larger than the actual real search
69638 ** term, substitute >= for > and < for <=. e.g. if the search term
69639 ** is 4.9 and the integer approximation 5:
69640 **
69641 ** (x > 4.9) -> (x >= 5)
69642 ** (x <= 4.9) -> (x < 5)
69643 */
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 ){
69727 pc = pOp->p2 - 1;
69728 }
69729 break;
69730 }
69731
@@ -70207,24 +69738,22 @@
69738 ** This is actually a deferred seek. Nothing actually happens until
69739 ** the cursor is used to read a record. That way, if no reads
69740 ** occur, no unnecessary I/O happens.
69741 */
69742 case OP_Seek: { /* in2 */
 
69743 VdbeCursor *pC;
 
69744
69745 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69746 pC = p->apCsr[pOp->p1];
69747 assert( pC!=0 );
69748 assert( pC->pCursor!=0 );
69749 assert( pC->isTable );
69750 pC->nullRow = 0;
69751 pIn2 = &aMem[pOp->p2];
69752 pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
69753 pC->rowidIsValid = 0;
69754 pC->deferredMoveto = 1;
69755 break;
69756 }
69757
69758
69759 /* Opcode: Found P1 P2 P3 P4 *
@@ -70275,85 +69804,83 @@
69804 ** See also: NotFound, Found, NotExists
69805 */
69806 case OP_NoConflict: /* jump, in3 */
69807 case OP_NotFound: /* jump, in3 */
69808 case OP_Found: { /* jump, in3 */
 
69809 int alreadyExists;
69810 int ii;
69811 VdbeCursor *pC;
69812 int res;
69813 char *pFree;
69814 UnpackedRecord *pIdxKey;
69815 UnpackedRecord r;
69816 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
 
69817
69818 #ifdef SQLITE_TEST
69819 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
69820 #endif
69821
 
69822 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69823 assert( pOp->p4type==P4_INT32 );
69824 pC = p->apCsr[pOp->p1];
69825 assert( pC!=0 );
69826 pIn3 = &aMem[pOp->p3];
69827 assert( pC->pCursor!=0 );
69828 assert( pC->isTable==0 );
69829 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
69830 if( pOp->p4.i>0 ){
69831 r.pKeyInfo = pC->pKeyInfo;
69832 r.nField = (u16)pOp->p4.i;
69833 r.aMem = pIn3;
69834 #ifdef SQLITE_DEBUG
69835 {
69836 int 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]);
69840 }
69841 }
69842 #endif
69843 r.flags = UNPACKED_PREFIX_MATCH;
69844 pIdxKey = &r;
69845 }else{
69846 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
69847 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
69848 );
69849 if( pIdxKey==0 ) goto no_mem;
69850 assert( pIn3->flags & MEM_Blob );
69851 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
69852 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
69853 pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
69854 }
69855 if( pOp->opcode==OP_NoConflict ){
69856 /* For the OP_NoConflict opcode, take the jump if any of the
69857 ** input fields are NULL, since any key with a NULL will not
69858 ** conflict */
69859 for(ii=0; ii<r.nField; ii++){
69860 if( r.aMem[ii].flags & MEM_Null ){
69861 pc = pOp->p2 - 1;
69862 break;
69863 }
69864 }
69865 }
69866 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
69867 if( pOp->p4.i==0 ){
69868 sqlite3DbFree(db, pFree);
69869 }
69870 if( rc!=SQLITE_OK ){
69871 break;
69872 }
69873 pC->seekResult = res;
69874 alreadyExists = (res==0);
69875 pC->nullRow = 1-alreadyExists;
69876 pC->deferredMoveto = 0;
69877 pC->cacheStatus = CACHE_STALE;
69878 if( pOp->opcode==OP_Found ){
69879 if( alreadyExists ) pc = pOp->p2 - 1;
69880 }else{
69881 if( !alreadyExists ) pc = pOp->p2 - 1;
69882 }
69883 break;
69884 }
69885
69886 /* Opcode: NotExists P1 P2 P3 * *
@@ -70369,39 +69896,37 @@
69896 ** (with arbitrary multi-value keys).
69897 **
69898 ** See also: Found, NotFound, NoConflict
69899 */
69900 case OP_NotExists: { /* jump, in3 */
 
69901 VdbeCursor *pC;
69902 BtCursor *pCrsr;
69903 int res;
69904 u64 iKey;
 
69905
69906 pIn3 = &aMem[pOp->p3];
69907 assert( pIn3->flags & MEM_Int );
69908 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
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 ){
69924 pc = pOp->p2 - 1;
69925 assert( pC->rowidIsValid==0 );
69926 }
69927 pC->seekResult = res;
69928 break;
69929 }
69930
69931 /* Opcode: Sequence P1 P2 * * *
69932 ** Synopsis: r[P2]=rowid
@@ -70433,25 +69958,23 @@
69958 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
69959 ** generated record number. This P3 mechanism is used to help implement the
69960 ** AUTOINCREMENT feature.
69961 */
69962 case OP_NewRowid: { /* out2-prerelease */
 
69963 i64 v; /* The new rowid */
69964 VdbeCursor *pC; /* Cursor of table to get the new rowid */
69965 int res; /* Result of an sqlite3BtreeLast() */
69966 int cnt; /* Counter to limit the number of searches */
69967 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
69968 VdbeFrame *pFrame; /* Root frame of VDBE */
 
69969
69970 v = 0;
69971 res = 0;
69972 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69973 pC = p->apCsr[pOp->p1];
69974 assert( pC!=0 );
69975 if( NEVER(pC->pCursor==0) ){
69976 /* The zero initialization above is all that is needed */
69977 }else{
69978 /* The next rowid or record number (different terms for the same
69979 ** thing) is obtained in a two-step algorithm.
69980 **
@@ -70463,11 +69986,11 @@
69986 ** The second algorithm is to select a rowid at random and see if
69987 ** it already exists in the table. If it does not exist, we have
69988 ** succeeded. If the random rowid does exist, we select a new one
69989 ** and try again, up to 100 times.
69990 */
69991 assert( pC->isTable );
69992
69993 #ifdef SQLITE_32BIT_ROWID
69994 # define MAX_ROWID 0x7fffffff
69995 #else
69996 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70475,101 +69998,101 @@
69998 ** to provide the constant while making all compilers happy.
69999 */
70000 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70001 #endif
70002
70003 if( !pC->useRandomRowid ){
70004 v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70005 if( v==0 ){
70006 rc = sqlite3BtreeLast(pC->pCursor, &res);
70007 if( rc!=SQLITE_OK ){
70008 goto abort_due_to_error;
70009 }
70010 if( res ){
70011 v = 1; /* IMP: R-61914-48074 */
70012 }else{
70013 assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70014 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70015 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70016 if( v>=MAX_ROWID ){
70017 pC->useRandomRowid = 1;
70018 }else{
70019 v++; /* IMP: R-29538-34987 */
70020 }
70021 }
70022 }
70023
70024 #ifndef SQLITE_OMIT_AUTOINCREMENT
70025 if( pOp->p3 ){
70026 /* Assert that P3 is a valid memory cell. */
70027 assert( pOp->p3>0 );
70028 if( p->pFrame ){
70029 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70030 /* Assert that P3 is a valid memory cell. */
70031 assert( pOp->p3<=pFrame->nMem );
70032 pMem = &pFrame->aMem[pOp->p3];
70033 }else{
70034 /* Assert that P3 is a valid memory cell. */
70035 assert( pOp->p3<=(p->nMem-p->nCursor) );
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 ){
70045 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70046 goto abort_due_to_error;
70047 }
70048 if( v<pMem->u.i+1 ){
70049 v = pMem->u.i + 1;
70050 }
70051 pMem->u.i = v;
70052 }
70053 #endif
70054
70055 sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
70056 }
70057 if( pC->useRandomRowid ){
70058 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70059 ** largest possible integer (9223372036854775807) then the database
70060 ** engine starts picking positive candidate ROWIDs at random until
70061 ** it finds one that is not previously used. */
70062 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
70063 ** an AUTOINCREMENT table. */
70064 /* on the first attempt, simply do one more than previous */
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)){
70073 /* collision - try another random rowid */
70074 sqlite3_randomness(sizeof(v), &v);
70075 if( cnt<5 ){
70076 /* try "small" random rowids for the initial attempts */
70077 v &= 0xffffff;
70078 }else{
70079 v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70080 }
70081 v++; /* ensure non-zero */
70082 }
70083 if( rc==SQLITE_OK && res==0 ){
70084 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
70085 goto abort_due_to_error;
70086 }
70087 assert( v>0 ); /* EV: R-40812-03570 */
70088 }
70089 pC->rowidIsValid = 0;
70090 pC->deferredMoveto = 0;
70091 pC->cacheStatus = CACHE_STALE;
70092 }
70093 pOut->u.i = v;
70094 break;
70095 }
70096
70097 /* Opcode: Insert P1 P2 P3 P4 P5
70098 ** Synopsis: intkey=r[P3] data=r[P2]
@@ -70617,74 +70140,72 @@
70140 ** This works exactly like OP_Insert except that the key is the
70141 ** integer value P3, not the value of the integer stored in register P3.
70142 */
70143 case OP_Insert:
70144 case OP_InsertInt: {
 
70145 Mem *pData; /* MEM cell holding data for the record to be inserted */
70146 Mem *pKey; /* MEM cell holding key for the record */
70147 i64 iKey; /* The integer ROWID or key for the record to be inserted */
70148 VdbeCursor *pC; /* Cursor to table into which insert is written */
70149 int nZero; /* Number of zero-bytes to append */
70150 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
70151 const char *zDb; /* database name - used by the update hook */
70152 const char *zTbl; /* Table name - used by the opdate hook */
70153 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
 
70154
70155 pData = &aMem[pOp->p2];
70156 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
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);
70164
70165 if( pOp->opcode==OP_Insert ){
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;
70171 }else{
70172 assert( pOp->opcode==OP_InsertInt );
70173 iKey = pOp->p3;
70174 }
70175
70176 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
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
70194 );
70195 pC->rowidIsValid = 0;
70196 pC->deferredMoveto = 0;
70197 pC->cacheStatus = CACHE_STALE;
70198
70199 /* Invoke the update-hook if required. */
70200 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
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 );
70207 }
70208 break;
70209 }
70210
70211 /* Opcode: Delete P1 P2 * P4 *
@@ -70706,41 +70227,39 @@
70227 ** pointing to. The update hook will be invoked, if it exists.
70228 ** If P4 is not NULL then the P1 cursor must have been positioned
70229 ** using OP_NotFound prior to invoking this opcode.
70230 */
70231 case OP_Delete: {
 
70232 i64 iKey;
70233 VdbeCursor *pC;
 
70234
70235 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
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 */
70240
70241 /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
70242 ** OP_Column on the same table without any intervening operations that
70243 ** might move or invalidate the cursor. Hence cursor pC is always pointing
70244 ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
70245 ** below is always a no-op and cannot fail. We will run it anyhow, though,
70246 ** to guard against future changes to the code generator.
70247 **/
70248 assert( pC->deferredMoveto==0 );
70249 rc = sqlite3VdbeCursorMoveto(pC);
70250 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70251
70252 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70253 rc = sqlite3BtreeDelete(pC->pCursor);
70254 pC->cacheStatus = CACHE_STALE;
70255
70256 /* Invoke the update-hook if required. */
70257 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
70258 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
70259 db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
70260 assert( pC->iDb>=0 );
70261 }
70262 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
70263 break;
70264 }
70265 /* Opcode: ResetCount * * * * *
@@ -70770,23 +70289,21 @@
70289 **
70290 ** Fall through to next instruction if the two records compare equal to
70291 ** each other. Jump to P2 if they are different.
70292 */
70293 case OP_SorterCompare: {
 
70294 VdbeCursor *pC;
70295 int res;
70296 int nIgnore;
 
70297
70298 pC = p->apCsr[pOp->p1];
70299 assert( isSorter(pC) );
70300 assert( pOp->p4type==P4_INT32 );
70301 pIn3 = &aMem[pOp->p3];
70302 nIgnore = pOp->p4.i;
70303 rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70304 if( res ){
70305 pc = pOp->p2-1;
70306 }
70307 break;
70308 };
70309
@@ -70794,18 +70311,16 @@
70311 ** Synopsis: r[P2]=data
70312 **
70313 ** Write into register P2 the current sorter data for sorter cursor P1.
70314 */
70315 case OP_SorterData: {
 
70316 VdbeCursor *pC;
 
70317
70318 pOut = &aMem[pOp->p2];
70319 pC = p->apCsr[pOp->p1];
70320 assert( isSorter(pC) );
70321 rc = sqlite3VdbeSorterRowkey(pC, pOut);
70322 break;
70323 }
70324
70325 /* Opcode: RowData P1 P2 * * *
70326 ** Synopsis: r[P2]=data
@@ -70829,66 +70344,64 @@
70344 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70345 ** of a real table, not a pseudo-table.
70346 */
70347 case OP_RowKey:
70348 case OP_RowData: {
 
70349 VdbeCursor *pC;
70350 BtCursor *pCrsr;
70351 u32 n;
70352 i64 n64;
 
70353
70354 pOut = &aMem[pOp->p2];
70355 memAboutToChange(p, pOut);
70356
70357 /* Note that RowKey and RowData are really exactly the same instruction */
70358 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
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) );
70369
70370 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
70371 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
70372 ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
70373 ** a no-op and can never fail. But we leave it in place as a safety.
70374 */
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);
70403 }
70404 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
70405 UPDATE_MAX_BLOBSIZE(pOut);
70406 REGISTER_TRACE(pOp->p2, pOut);
70407 break;
@@ -70903,46 +70416,44 @@
70416 ** P1 can be either an ordinary table or a virtual table. There used to
70417 ** be a separate OP_VRowid opcode for use with virtual tables, but this
70418 ** one opcode now works for both table types.
70419 */
70420 case OP_Rowid: { /* out2-prerelease */
 
70421 VdbeCursor *pC;
70422 i64 v;
70423 sqlite3_vtab *pVtab;
70424 const sqlite3_module *pModule;
 
70425
70426 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70427 pC = p->apCsr[pOp->p1];
70428 assert( pC!=0 );
70429 assert( pC->pseudoTableReg==0 || pC->nullRow );
70430 if( pC->nullRow ){
70431 pOut->flags = MEM_Null;
70432 break;
70433 }else if( pC->deferredMoveto ){
70434 v = pC->movetoTarget;
70435 #ifndef SQLITE_OMIT_VIRTUALTABLE
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);
70442 #endif /* SQLITE_OMIT_VIRTUALTABLE */
70443 }else{
70444 assert( pC->pCursor!=0 );
70445 rc = sqlite3VdbeCursorMoveto(pC);
70446 if( rc ) goto abort_due_to_error;
70447 if( pC->rowidIsValid ){
70448 v = pC->lastRowid;
70449 }else{
70450 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70451 assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
70452 }
70453 }
70454 pOut->u.i = v;
70455 break;
70456 }
70457
70458 /* Opcode: NullRow P1 * * * *
70459 **
@@ -70949,23 +70460,21 @@
70460 ** Move the cursor P1 to a null row. Any OP_Column operations
70461 ** that occur while the cursor is on the null row will always
70462 ** write a NULL.
70463 */
70464 case OP_NullRow: {
 
70465 VdbeCursor *pC;
 
70466
70467 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
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);
70476 }
70477 break;
70478 }
70479
70480 /* Opcode: Last P1 P2 * * *
@@ -70975,28 +70484,26 @@
70484 ** If the table or index is empty and P2>0, then jump immediately to P2.
70485 ** If P2 is 0 or if the table or index is not empty, fall through
70486 ** to the following instruction.
70487 */
70488 case OP_Last: { /* jump */
 
70489 VdbeCursor *pC;
70490 BtCursor *pCrsr;
70491 int res;
 
70492
70493 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
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 ){
70505 pc = pOp->p2 - 1;
70506 }
70507 break;
70508 }
70509
@@ -71029,34 +70536,32 @@
70536 ** If the table or index is empty and P2>0, then jump immediately to P2.
70537 ** If P2 is 0 or if the table or index is not empty, fall through
70538 ** to the following instruction.
70539 */
70540 case OP_Rewind: { /* jump */
 
70541 VdbeCursor *pC;
70542 BtCursor *pCrsr;
70543 int res;
 
70544
70545 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
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);
70552 }else{
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;
70561 assert( pOp->p2>0 && pOp->p2<p->nOp );
70562 if( res ){
70563 pc = pOp->p2 - 1;
70564 }
70565 break;
70566 }
70567
@@ -71103,49 +70608,47 @@
70608 **
70609 ** This opcode works just like OP_Prev except that if cursor P1 is not
70610 ** open it behaves a no-op.
70611 */
70612 case OP_SorterNext: { /* jump */
 
70613 VdbeCursor *pC;
70614 int res;
 
70615
70616 pC = p->apCsr[pOp->p1];
70617 assert( isSorter(pC) );
70618 rc = sqlite3VdbeSorterNext(db, pC, &res);
70619 goto next_tail;
70620 case OP_PrevIfOpen: /* jump */
70621 case OP_NextIfOpen: /* jump */
70622 if( p->apCsr[pOp->p1]==0 ) break;
70623 /* Fall through */
70624 case OP_Prev: /* jump */
70625 case OP_Next: /* jump */
70626 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70627 assert( pOp->p5<ArraySize(p->aCounter) );
70628 pC = p->apCsr[pOp->p1];
70629 assert( pC!=0 );
70630 assert( pC->deferredMoveto==0 );
70631 assert( pC->pCursor );
70632 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
70633 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
70634 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
70635 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
70636 rc = pOp->p4.xAdvance(pC->pCursor, &res);
70637 next_tail:
70638 pC->cacheStatus = CACHE_STALE;
70639 if( res==0 ){
70640 pC->nullRow = 0;
70641 pc = pOp->p2 - 1;
70642 p->aCounter[pOp->p5]++;
70643 #ifdef SQLITE_TEST
70644 sqlite3_search_count++;
70645 #endif
70646 }else{
70647 pC->nullRow = 1;
70648 }
70649 pC->rowidIsValid = 0;
70650 goto check_for_interrupt;
70651 }
70652
70653 /* Opcode: IdxInsert P1 P2 P3 * P5
70654 ** Synopsis: key=r[P2]
@@ -71160,39 +70663,37 @@
70663 ** This instruction only works for indices. The equivalent instruction
70664 ** for tables is OP_Insert.
70665 */
70666 case OP_SorterInsert: /* in2 */
70667 case OP_IdxInsert: { /* in2 */
 
70668 VdbeCursor *pC;
70669 BtCursor *pCrsr;
70670 int nKey;
70671 const char *zKey;
 
70672
70673 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70674 pC = p->apCsr[pOp->p1];
70675 assert( pC!=0 );
70676 assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) );
70677 pIn2 = &aMem[pOp->p2];
70678 assert( pIn2->flags & MEM_Blob );
70679 pCrsr = pC->pCursor;
70680 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70681 assert( pCrsr!=0 );
70682 assert( pC->isTable==0 );
70683 rc = ExpandBlob(pIn2);
70684 if( rc==SQLITE_OK ){
70685 if( isSorter(pC) ){
70686 rc = sqlite3VdbeSorterWrite(db, pC, pIn2);
70687 }else{
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)
70692 );
70693 assert( pC->deferredMoveto==0 );
70694 pC->cacheStatus = CACHE_STALE;
70695 }
70696 }
70697 break;
70698 }
70699
@@ -71202,38 +70703,36 @@
70703 ** The content of P3 registers starting at register P2 form
70704 ** an unpacked index key. This opcode removes that entry from the
70705 ** index opened by cursor P1.
70706 */
70707 case OP_IdxDelete: {
 
70708 VdbeCursor *pC;
70709 BtCursor *pCrsr;
70710 int res;
70711 UnpackedRecord r;
 
70712
70713 assert( pOp->p3>0 );
70714 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
70715 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70716 pC = p->apCsr[pOp->p1];
70717 assert( pC!=0 );
70718 pCrsr = pC->pCursor;
70719 assert( pCrsr!=0 );
70720 assert( pOp->p5==0 );
70721 r.pKeyInfo = pC->pKeyInfo;
70722 r.nField = (u16)pOp->p3;
70723 r.flags = UNPACKED_PREFIX_MATCH;
70724 r.aMem = &aMem[pOp->p2];
70725 #ifdef SQLITE_DEBUG
70726 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70727 #endif
70728 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
70729 if( rc==SQLITE_OK && res==0 ){
70730 rc = sqlite3BtreeDelete(pCrsr);
70731 }
70732 assert( pC->deferredMoveto==0 );
70733 pC->cacheStatus = CACHE_STALE;
70734 break;
70735 }
70736
70737 /* Opcode: IdxRowid P1 P2 * * *
70738 ** Synopsis: r[P2]=rowid
@@ -71243,32 +70742,31 @@
70742 ** the rowid of the table entry to which this index entry points.
70743 **
70744 ** See also: Rowid, MakeRecord.
70745 */
70746 case OP_IdxRowid: { /* out2-prerelease */
 
70747 BtCursor *pCrsr;
70748 VdbeCursor *pC;
70749 i64 rowid;
 
70750
70751 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70752 pC = p->apCsr[pOp->p1];
70753 assert( pC!=0 );
70754 pCrsr = pC->pCursor;
70755 assert( pCrsr!=0 );
70756 pOut->flags = MEM_Null;
70757 rc = sqlite3VdbeCursorMoveto(pC);
70758 if( NEVER(rc) ) goto abort_due_to_error;
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);
70764 if( rc!=SQLITE_OK ){
70765 goto abort_due_to_error;
70766 }
70767 pOut->u.i = rowid;
70768 pOut->flags = MEM_Int;
70769 }
70770 break;
70771 }
70772
@@ -71300,43 +70798,42 @@
70798 ** If P5 is non-zero then the key value is increased by an epsilon prior
70799 ** to the comparison. This makes the opcode work like IdxLE.
70800 */
70801 case OP_IdxLT: /* jump */
70802 case OP_IdxGE: { /* jump */
 
70803 VdbeCursor *pC;
70804 int res;
70805 UnpackedRecord r;
 
70806
70807 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70808 pC = p->apCsr[pOp->p1];
70809 assert( pC!=0 );
70810 assert( pC->isOrdered );
70811 assert( pC->pCursor!=0);
70812 assert( pC->deferredMoveto==0 );
70813 assert( pOp->p5==0 || pOp->p5==1 );
70814 assert( pOp->p4type==P4_INT32 );
70815 r.pKeyInfo = pC->pKeyInfo;
70816 r.nField = (u16)pOp->p4.i;
70817 if( pOp->p5 ){
70818 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
70819 }else{
70820 r.flags = UNPACKED_PREFIX_MATCH;
70821 }
70822 r.aMem = &aMem[pOp->p3];
70823 #ifdef SQLITE_DEBUG
70824 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70825 #endif
70826 res = 0; /* Not needed. Only used to silence a warning. */
70827 rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
70828 if( pOp->opcode==OP_IdxLT ){
70829 res = -res;
70830 }else{
70831 assert( pOp->opcode==OP_IdxGE );
70832 res++;
70833 }
70834 if( res>0 ){
70835 pc = pOp->p2 - 1 ;
70836 }
70837 break;
70838 }
70839
@@ -71359,47 +70856,46 @@
70856 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
70857 **
70858 ** See also: Clear
70859 */
70860 case OP_Destroy: { /* out2-prerelease */
 
70861 int iMoved;
70862 int iCnt;
70863 Vdbe *pVdbe;
70864 int iDb;
 
70865
70866 assert( p->readOnly==0 );
70867 #ifndef SQLITE_OMIT_VIRTUALTABLE
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
70872 ){
70873 iCnt++;
70874 }
70875 }
70876 #else
70877 iCnt = db->nVdbeRead;
70878 #endif
70879 pOut->flags = MEM_Null;
70880 if( iCnt>1 ){
70881 rc = SQLITE_LOCKED;
70882 p->errorAction = OE_Abort;
70883 }else{
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);
70889 pOut->flags = MEM_Int;
70890 pOut->u.i = iMoved;
70891 #ifndef SQLITE_OMIT_AUTOVACUUM
70892 if( rc==SQLITE_OK && iMoved!=0 ){
70893 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
70894 /* All OP_Destroy operations occur on the same btree */
70895 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
70896 resetSchemaOnFault = iDb+1;
70897 }
70898 #endif
70899 }
70900 break;
70901 }
@@ -71421,27 +70917,25 @@
70917 ** also incremented by the number of rows in the table being cleared.
70918 **
70919 ** See also: Destroy
70920 */
70921 case OP_Clear: {
 
70922 int nChange;
70923
70924 nChange = 0;
 
70925 assert( p->readOnly==0 );
70926 assert( pOp->p1!=1 );
70927 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
70928 rc = sqlite3BtreeClearTable(
70929 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
70930 );
70931 if( pOp->p3 ){
70932 p->nChange += nChange;
70933 if( pOp->p3>0 ){
70934 assert( memIsValid(&aMem[pOp->p3]) );
70935 memAboutToChange(p, &aMem[pOp->p3]);
70936 aMem[pOp->p3].u.i += nChange;
70937 }
70938 }
70939 break;
70940 }
70941
@@ -71469,30 +70963,28 @@
70963 **
70964 ** See documentation on OP_CreateTable for additional information.
70965 */
70966 case OP_CreateIndex: /* out2-prerelease */
70967 case OP_CreateTable: { /* out2-prerelease */
 
70968 int pgno;
70969 int flags;
70970 Db *pDb;
 
70971
70972 pgno = 0;
70973 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70974 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
70975 assert( p->readOnly==0 );
70976 pDb = &db->aDb[pOp->p1];
70977 assert( pDb->pBt!=0 );
70978 if( pOp->opcode==OP_CreateTable ){
70979 /* flags = BTREE_INTKEY; */
70980 flags = BTREE_INTKEY;
70981 }else{
70982 flags = BTREE_BLOBKEY;
70983 }
70984 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
70985 pOut->u.i = pgno;
70986 break;
70987 }
70988
70989 /* Opcode: ParseSchema P1 * * P4 *
70990 **
@@ -71501,56 +70993,54 @@
70993 **
70994 ** This opcode invokes the parser to create a new virtual machine,
70995 ** then runs the new virtual machine. It is thus a re-entrant opcode.
70996 */
70997 case OP_ParseSchema: {
 
70998 int iDb;
70999 const char *zMaster;
71000 char *zSql;
71001 InitData initData;
 
71002
71003 /* Any prepared statement that invokes this opcode will hold mutexes
71004 ** on every btree. This is a prerequisite for invoking
71005 ** sqlite3InitCallback().
71006 */
71007 #ifdef SQLITE_DEBUG
71008 for(iDb=0; iDb<db->nDb; iDb++){
71009 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
71010 }
71011 #endif
71012
71013 iDb = pOp->p1;
71014 assert( iDb>=0 && iDb<db->nDb );
71015 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
71016 /* Used to be a conditional */ {
71017 zMaster = SCHEMA_TABLE(iDb);
71018 initData.db = db;
71019 initData.iDb = pOp->p1;
71020 initData.pzErrMsg = &p->zErrMsg;
71021 zSql = sqlite3MPrintf(db,
71022 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
71023 db->aDb[iDb].zName, zMaster, pOp->p4.z);
71024 if( zSql==0 ){
71025 rc = SQLITE_NOMEM;
71026 }else{
71027 assert( db->init.busy==0 );
71028 db->init.busy = 1;
71029 initData.rc = SQLITE_OK;
71030 assert( !db->mallocFailed );
71031 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
71032 if( rc==SQLITE_OK ) rc = initData.rc;
71033 sqlite3DbFree(db, zSql);
71034 db->init.busy = 0;
71035 }
71036 }
71037 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
71038 if( rc==SQLITE_NOMEM ){
71039 goto no_mem;
71040 }
71041 break;
71042 }
71043
71044 #if !defined(SQLITE_OMIT_ANALYZE)
71045 /* Opcode: LoadAnalysis P1 * * * *
71046 **
@@ -71622,46 +71112,44 @@
71112 ** file, not the main database file.
71113 **
71114 ** This opcode is used to implement the integrity_check pragma.
71115 */
71116 case OP_IntegrityCk: {
 
71117 int nRoot; /* Number of tables to check. (Number of root pages.) */
71118 int *aRoot; /* Array of rootpage numbers for tables to be checked */
71119 int j; /* Loop counter */
71120 int nErr; /* Number of errors reported */
71121 char *z; /* Text of the error report */
71122 Mem *pnErr; /* Register keeping track of errors remaining */
 
71123
71124 assert( p->bIsReader );
71125 nRoot = pOp->p2;
71126 assert( nRoot>0 );
71127 aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) );
71128 if( aRoot==0 ) goto no_mem;
71129 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71130 pnErr = &aMem[pOp->p3];
71131 assert( (pnErr->flags & MEM_Int)!=0 );
71132 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
71133 pIn1 = &aMem[pOp->p1];
71134 for(j=0; j<nRoot; j++){
71135 aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
71136 }
71137 aRoot[j] = 0;
71138 assert( pOp->p5<db->nDb );
71139 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
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;
71144 sqlite3VdbeMemSetNull(pIn1);
71145 if( nErr==0 ){
71146 assert( z==0 );
71147 }else if( z==0 ){
71148 goto no_mem;
71149 }else{
71150 sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
71151 }
71152 UPDATE_MAX_BLOBSIZE(pIn1);
71153 sqlite3VdbeChangeEncoding(pIn1, encoding);
71154 break;
71155 }
@@ -71693,24 +71181,22 @@
71181 ** Extract the smallest value from boolean index P1 and put that value into
71182 ** register P3. Or, if boolean index P1 is initially empty, leave P3
71183 ** unchanged and jump to instruction P2.
71184 */
71185 case OP_RowSetRead: { /* jump, in1, out3 */
 
71186 i64 val;
 
71187
71188 pIn1 = &aMem[pOp->p1];
71189 if( (pIn1->flags & MEM_RowSet)==0
71190 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
71191 ){
71192 /* The boolean index is empty */
71193 sqlite3VdbeMemSetNull(pIn1);
71194 pc = pOp->p2 - 1;
71195 }else{
71196 /* A value was pulled from the index */
71197 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
71198 }
71199 goto check_for_interrupt;
71200 }
71201
71202 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71736,18 +71222,16 @@
71222 ** inserted, there is no need to search to see if the same value was
71223 ** previously inserted as part of set X (only if it was previously
71224 ** inserted as part of some other set).
71225 */
71226 case OP_RowSetTest: { /* jump, in1, in3 */
 
71227 int iSet;
71228 int exists;
 
71229
71230 pIn1 = &aMem[pOp->p1];
71231 pIn3 = &aMem[pOp->p3];
71232 iSet = pOp->p4.i;
71233 assert( pIn3->flags&MEM_Int );
71234
71235 /* If there is anything other than a rowset object in memory cell P1,
71236 ** delete it now and initialize P1 with an empty rowset
71237 */
@@ -71755,21 +71239,21 @@
71239 sqlite3VdbeMemSetRowSet(pIn1);
71240 if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
71241 }
71242
71243 assert( pOp->p4type==P4_INT32 );
71244 assert( iSet==-1 || iSet>=0 );
71245 if( iSet ){
71246 exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71247 (u8)(iSet>=0 ? iSet & 0xf : 0xff),
71248 pIn3->u.i);
71249 if( exists ){
71250 pc = pOp->p2 - 1;
71251 break;
71252 }
71253 }
71254 if( iSet>=0 ){
71255 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
71256 }
71257 break;
71258 }
71259
@@ -71788,111 +71272,109 @@
71272 ** memory required by the sub-vdbe at runtime.
71273 **
71274 ** P4 is a pointer to the VM containing the trigger program.
71275 */
71276 case OP_Program: { /* jump */
 
71277 int nMem; /* Number of memory registers for sub-program */
71278 int nByte; /* Bytes of runtime space required for sub-program */
71279 Mem *pRt; /* Register to allocate runtime space */
71280 Mem *pMem; /* Used to iterate through memory cells */
71281 Mem *pEnd; /* Last memory cell in new array */
71282 VdbeFrame *pFrame; /* New vdbe frame to execute in */
71283 SubProgram *pProgram; /* Sub-program to execute */
71284 void *t; /* Token identifying trigger */
 
71285
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
71291 ** disabled for backwards compatibility (p5 is set if this sub-program
71292 ** is really a trigger, not a foreign key action, and the flag set
71293 ** and cleared by the "PRAGMA recursive_triggers" command is clear).
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
71298 ** ON CONFLICT algorithm). SubProgram structures associated with a
71299 ** single trigger all have the same value for the SubProgram.token
71300 ** variable. */
71301 if( pOp->p5 ){
71302 t = pProgram->token;
71303 for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent);
71304 if( pFrame ) break;
71305 }
71306
71307 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
71308 rc = SQLITE_ERROR;
71309 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
71310 break;
71311 }
71312
71313 /* Register pRt is used to store the memory required to save the state
71314 ** of the current program, and the memory required at runtime to execute
71315 ** the trigger program. If this trigger has been fired before, then pRt
71316 ** is already allocated. Otherwise, it must be initialized. */
71317 if( (pRt->flags&MEM_Frame)==0 ){
71318 /* SubProgram.nMem is set to the number of memory cells used by the
71319 ** program stored in SubProgram.aOp. As well as these, one memory
71320 ** cell is required for each cursor used by the program. Set local
71321 ** variable nMem (and later, VdbeFrame.nChildMem) to this value.
71322 */
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 ){
71330 goto no_mem;
71331 }
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;
71354 }
71355 }else{
71356 pFrame = pRt->u.pFrame;
71357 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
71358 assert( pProgram->nCsr==pFrame->nChildCsr );
71359 assert( pc==pFrame->pc );
71360 }
71361
71362 p->nFrame++;
71363 pFrame->pParent = p->pFrame;
71364 pFrame->lastRowid = lastRowid;
71365 pFrame->nChange = p->nChange;
71366 p->nChange = 0;
71367 p->pFrame = pFrame;
71368 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
71369 p->nMem = pFrame->nChildMem;
71370 p->nCursor = (u16)pFrame->nChildCsr;
71371 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
71372 p->aOp = aOp = pProgram->aOp;
71373 p->nOp = pProgram->nOp;
71374 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71375 p->nOnceFlag = pProgram->nOnce;
71376 pc = -1;
71377 memset(p->aOnceFlag, 0, p->nOnceFlag);
71378
71379 break;
71380 }
@@ -71908,17 +71390,15 @@
71390 ** The address of the cell in the parent frame is determined by adding
71391 ** the value of the P1 argument to the value of the P1 argument to the
71392 ** calling OP_Program instruction.
71393 */
71394 case OP_Param: { /* out2-prerelease */
 
71395 VdbeFrame *pFrame;
71396 Mem *pIn;
71397 pFrame = p->pFrame;
71398 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
71399 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
 
71400 break;
71401 }
71402
71403 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
71404
@@ -71975,26 +71455,23 @@
71455 **
71456 ** This instruction throws an error if the memory cell is not initially
71457 ** an integer.
71458 */
71459 case OP_MemMax: { /* in2 */
 
 
71460 VdbeFrame *pFrame;
 
71461 if( p->pFrame ){
71462 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
71463 pIn1 = &pFrame->aMem[pOp->p1];
71464 }else{
71465 pIn1 = &aMem[pOp->p1];
71466 }
71467 assert( memIsValid(pIn1) );
71468 sqlite3VdbeMemIntegerify(pIn1);
71469 pIn2 = &aMem[pOp->p2];
71470 sqlite3VdbeMemIntegerify(pIn2);
71471 if( pIn1->u.i<pIn2->u.i){
71472 pIn1->u.i = pIn2->u.i;
71473 }
71474 break;
71475 }
71476 #endif /* SQLITE_OMIT_AUTOINCREMENT */
71477
@@ -72061,60 +71538,58 @@
71538 **
71539 ** The P5 arguments are taken from register P2 and its
71540 ** successors.
71541 */
71542 case OP_AggStep: {
 
71543 int n;
71544 int i;
71545 Mem *pMem;
71546 Mem *pRec;
71547 sqlite3_context ctx;
71548 sqlite3_value **apVal;
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;
 
71562 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
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 ){
71574 assert( pOp>p->aOp );
71575 assert( pOp[-1].p4type==P4_COLLSEQ );
71576 assert( pOp[-1].opcode==OP_CollSeq );
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 ){
71585 assert( pOp[-1].opcode==OP_CollSeq );
71586 i = pOp[-1].p1;
71587 if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1);
71588 }
71589
71590 sqlite3VdbeMemRelease(&ctx.s);
71591
71592 break;
71593 }
71594
71595 /* Opcode: AggFinal P1 P2 * P4 *
@@ -72129,23 +71604,21 @@
71604 ** functions that can take varying numbers of arguments. The
71605 ** P4 argument is only needed for the degenerate case where
71606 ** the step function was not previously called.
71607 */
71608 case OP_AggFinal: {
 
71609 Mem *pMem;
 
71610 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71611 pMem = &aMem[pOp->p1];
71612 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
71613 rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
71614 if( rc ){
71615 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem));
71616 }
71617 sqlite3VdbeChangeEncoding(pMem, encoding);
71618 UPDATE_MAX_BLOBSIZE(pMem);
71619 if( sqlite3VdbeMemTooBig(pMem) ){
71620 goto too_big;
71621 }
71622 break;
71623 }
71624
@@ -72160,31 +71633,29 @@
71633 ** in the WAL that have been checkpointed after the checkpoint
71634 ** completes into mem[P3+2]. However on an error, mem[P3+1] and
71635 ** mem[P3+2] are initialized to -1.
71636 */
71637 case OP_Checkpoint: {
 
71638 int i; /* Loop counter */
71639 int aRes[3]; /* Results */
71640 Mem *pMem; /* Write results here */
 
71641
71642 assert( p->readOnly==0 );
71643 aRes[0] = 0;
71644 aRes[1] = aRes[2] = -1;
71645 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
71646 || pOp->p2==SQLITE_CHECKPOINT_FULL
71647 || pOp->p2==SQLITE_CHECKPOINT_RESTART
71648 );
71649 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
71650 if( rc==SQLITE_BUSY ){
71651 rc = SQLITE_OK;
71652 aRes[0] = 1;
71653 }
71654 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
71655 sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]);
71656 }
71657 break;
71658 };
71659 #endif
71660
71661 #ifndef SQLITE_OMIT_PRAGMA
@@ -72198,98 +71669,96 @@
71669 ** If changing into or out of WAL mode the procedure is more complicated.
71670 **
71671 ** Write a string containing the final journal-mode to register P2.
71672 */
71673 case OP_JournalMode: { /* out2-prerelease */
 
71674 Btree *pBt; /* Btree to change journal mode of */
71675 Pager *pPager; /* Pager associated with pBt */
71676 int eNew; /* New journal mode */
71677 int eOld; /* The old journal mode */
71678 #ifndef SQLITE_OMIT_WAL
71679 const char *zFilename; /* Name of database file for pPager */
71680 #endif
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
 
71690 );
71691 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71692 assert( p->readOnly==0 );
71693
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;
71699
71700 #ifndef SQLITE_OMIT_WAL
71701 zFilename = sqlite3PagerFilename(pPager, 1);
71702
71703 /* Do not allow a transition to journal_mode=WAL for a database
71704 ** in temporary storage or if the VFS does not support shared memory
71705 */
71706 if( eNew==PAGER_JOURNALMODE_WAL
71707 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
71708 || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */
71709 ){
71710 eNew = eOld;
71711 }
71712
71713 if( (eNew!=eOld)
71714 && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL)
71715 ){
71716 if( !db->autoCommit || db->nVdbeRead>1 ){
71717 rc = SQLITE_ERROR;
71718 sqlite3SetString(&p->zErrMsg, db,
71719 "cannot change %s wal mode from within a transaction",
71720 (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
71721 );
71722 break;
71723 }else{
71724
71725 if( eOld==PAGER_JOURNALMODE_WAL ){
71726 /* If leaving WAL mode, close the log file. If successful, the call
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.
71730 */
71731 rc = sqlite3PagerCloseWal(pPager);
71732 if( rc==SQLITE_OK ){
71733 sqlite3PagerSetJournalMode(pPager, eNew);
71734 }
71735 }else if( eOld==PAGER_JOURNALMODE_MEMORY ){
71736 /* Cannot transition directly from MEMORY to WAL. Use mode OFF
71737 ** as an intermediate */
71738 sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF);
71739 }
71740
71741 /* Open a transaction on the database file. Regardless of the journal
71742 ** mode, this transaction always uses a rollback journal.
71743 */
71744 assert( sqlite3BtreeIsInTrans(pBt)==0 );
71745 if( rc==SQLITE_OK ){
71746 rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
71747 }
71748 }
71749 }
71750 #endif /* ifndef SQLITE_OMIT_WAL */
71751
71752 if( rc ){
71753 eNew = eOld;
71754 }
71755 eNew = sqlite3PagerSetJournalMode(pPager, eNew);
71756
71757 pOut = &aMem[pOp->p2];
71758 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71759 pOut->z = (char *)sqlite3JournalModename(eNew);
71760 pOut->n = sqlite3Strlen30(pOut->z);
71761 pOut->enc = SQLITE_UTF8;
71762 sqlite3VdbeChangeEncoding(pOut, encoding);
71763 break;
71764 };
@@ -72315,19 +71784,17 @@
71784 ** Perform a single step of the incremental vacuum procedure on
71785 ** the P1 database. If the vacuum has finished, jump to instruction
71786 ** P2. Otherwise, fall through to the next instruction.
71787 */
71788 case OP_IncrVacuum: { /* jump */
 
71789 Btree *pBt;
 
71790
71791 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71792 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
71793 assert( p->readOnly==0 );
71794 pBt = db->aDb[pOp->p1].pBt;
71795 rc = sqlite3BtreeIncrVacuum(pBt);
71796 if( rc==SQLITE_DONE ){
71797 pc = pOp->p2 - 1;
71798 rc = SQLITE_OK;
71799 }
71800 break;
@@ -72394,16 +71861,14 @@
71861 ** Also, whether or not P4 is set, check that this is not being called from
71862 ** within a callback to a virtual table xSync() method. If it is, the error
71863 ** code will be set to SQLITE_LOCKED.
71864 */
71865 case OP_VBegin: {
 
71866 VTable *pVTab;
71867 pVTab = pOp->p4.pVtab;
71868 rc = sqlite3VtabBegin(db, pVTab);
71869 if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab);
 
71870 break;
71871 }
71872 #endif /* SQLITE_OMIT_VIRTUALTABLE */
71873
71874 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72438,36 +71903,34 @@
71903 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
71904 ** P1 is a cursor number. This opcode opens a cursor to the virtual
71905 ** table and stores that cursor in P1.
71906 */
71907 case OP_VOpen: {
 
71908 VdbeCursor *pCur;
71909 sqlite3_vtab_cursor *pVtabCursor;
71910 sqlite3_vtab *pVtab;
71911 sqlite3_module *pModule;
 
71912
71913 assert( p->bIsReader );
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);
71921 if( SQLITE_OK==rc ){
71922 /* Initialize sqlite3_vtab_cursor base class */
71923 pVtabCursor->pVtab = pVtab;
71924
71925 /* Initialize vdbe cursor object */
71926 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
71927 if( pCur ){
71928 pCur->pVtabCursor = pVtabCursor;
71929 }else{
71930 db->mallocFailed = 1;
71931 pModule->xClose(pVtabCursor);
71932 }
71933 }
71934 break;
71935 }
71936 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72491,11 +71954,10 @@
71954 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
71955 **
71956 ** A jump is made to P2 if the result set after filtering would be empty.
71957 */
71958 case OP_VFilter: { /* jump */
 
71959 int nArg;
71960 int iQuery;
71961 const sqlite3_module *pModule;
71962 Mem *pQuery;
71963 Mem *pArgc;
@@ -72503,49 +71965,48 @@
71965 sqlite3_vtab *pVtab;
71966 VdbeCursor *pCur;
71967 int res;
71968 int i;
71969 Mem **apArg;
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;
 
71980
71981 /* Grab the index number and argc parameters */
71982 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
71983 nArg = (int)pArgc->u.i;
71984 iQuery = (int)pQuery->u.i;
71985
71986 /* Invoke the xFilter method */
71987 {
71988 res = 0;
71989 apArg = p->apArg;
71990 for(i = 0; i<nArg; i++){
71991 apArg[i] = &pArgc[i+1];
71992 sqlite3VdbeMemStoreType(apArg[i]);
71993 }
71994
71995 p->inVtabMethod = 1;
71996 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
71997 p->inVtabMethod = 0;
71998 sqlite3VtabImportErrmsg(p, pVtab);
71999 if( rc==SQLITE_OK ){
72000 res = pModule->xEof(pVtabCursor);
72001 }
72002
72003 if( res ){
72004 pc = pOp->p2 - 1;
72005 }
72006 }
72007 pCur->nullRow = 0;
72008
72009 break;
72010 }
72011 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72012
@@ -72556,55 +72017,53 @@
72017 ** Store the value of the P2-th column of
72018 ** the row of the virtual-table that the
72019 ** P1 cursor is pointing to into register P3.
72020 */
72021 case OP_VColumn: {
 
72022 sqlite3_vtab *pVtab;
72023 const sqlite3_module *pModule;
72024 Mem *pDest;
72025 sqlite3_context sContext;
 
72026
72027 VdbeCursor *pCur = p->apCsr[pOp->p1];
72028 assert( pCur->pVtabCursor );
72029 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72030 pDest = &aMem[pOp->p3];
72031 memAboutToChange(p, pDest);
72032 if( pCur->nullRow ){
72033 sqlite3VdbeMemSetNull(pDest);
72034 break;
72035 }
72036 pVtab = pCur->pVtabCursor->pVtab;
72037 pModule = pVtab->pModule;
72038 assert( pModule->xColumn );
72039 memset(&sContext, 0, sizeof(sContext));
72040
72041 /* The output cell may already have a buffer allocated. Move
72042 ** the current contents to sContext.s so in case the user-function
72043 ** can use the already allocated buffer instead of allocating a
72044 ** new one.
72045 */
72046 sqlite3VdbeMemMove(&sContext.s, pDest);
72047 MemSetTypeFlag(&sContext.s, MEM_Null);
72048
72049 rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
72050 sqlite3VtabImportErrmsg(p, pVtab);
72051 if( sContext.isError ){
72052 rc = sContext.isError;
72053 }
72054
72055 /* Copy the result of the function to the P3 register. We
72056 ** do this regardless of whether or not an error occurred to ensure any
72057 ** dynamic allocation in sContext.s (a Mem struct) is released.
72058 */
72059 sqlite3VdbeChangeEncoding(&sContext.s, encoding);
72060 sqlite3VdbeMemMove(pDest, &sContext.s);
72061 REGISTER_TRACE(pOp->p3, pDest);
72062 UPDATE_MAX_BLOBSIZE(pDest);
72063
72064 if( sqlite3VdbeMemTooBig(pDest) ){
72065 goto too_big;
72066 }
72067 break;
72068 }
72069 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72615,42 +72074,40 @@
72074 ** Advance virtual table P1 to the next row in its result set and
72075 ** jump to instruction P2. Or, if the virtual table has reached
72076 ** the end of its result set, then fall through to the next instruction.
72077 */
72078 case OP_VNext: { /* jump */
 
72079 sqlite3_vtab *pVtab;
72080 const sqlite3_module *pModule;
72081 int res;
72082 VdbeCursor *pCur;
 
72083
72084 res = 0;
72085 pCur = p->apCsr[pOp->p1];
72086 assert( pCur->pVtabCursor );
72087 if( pCur->nullRow ){
72088 break;
72089 }
72090 pVtab = pCur->pVtabCursor->pVtab;
72091 pModule = pVtab->pModule;
72092 assert( pModule->xNext );
72093
72094 /* Invoke the xNext() method of the module. There is no way for the
72095 ** underlying implementation to return an error if one occurs during
72096 ** xNext(). Instead, if an error occurs, true is returned (indicating that
72097 ** data is available) and the error code returned when xColumn or
72098 ** some other method is next invoked on the save virtual table cursor.
72099 */
72100 p->inVtabMethod = 1;
72101 rc = pModule->xNext(pCur->pVtabCursor);
72102 p->inVtabMethod = 0;
72103 sqlite3VtabImportErrmsg(p, pVtab);
72104 if( rc==SQLITE_OK ){
72105 res = pModule->xEof(pCur->pVtabCursor);
72106 }
72107
72108 if( !res ){
72109 /* If there is data, jump to P2 */
72110 pc = pOp->p2 - 1;
72111 }
72112 goto check_for_interrupt;
72113 }
@@ -72662,29 +72119,27 @@
72119 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72120 ** This opcode invokes the corresponding xRename method. The value
72121 ** in register P1 is passed as the zName argument to the xRename method.
72122 */
72123 case OP_VRename: {
 
72124 sqlite3_vtab *pVtab;
72125 Mem *pName;
 
72126
72127 pVtab = pOp->p4.pVtab->pVtab;
72128 pName = &aMem[pOp->p1];
72129 assert( pVtab->pModule->xRename );
72130 assert( memIsValid(pName) );
72131 assert( p->readOnly==0 );
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);
72138 if( rc==SQLITE_OK ){
72139 rc = pVtab->pModule->xRename(pVtab, pName->z);
72140 sqlite3VtabImportErrmsg(p, pVtab);
72141 p->expired = 0;
72142 }
72143 break;
72144 }
72145 #endif
@@ -72713,46 +72168,44 @@
72168 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72169 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72170 ** is set to the value of the rowid for the row just inserted.
72171 */
72172 case OP_VUpdate: {
 
72173 sqlite3_vtab *pVtab;
72174 sqlite3_module *pModule;
72175 int nArg;
72176 int i;
72177 sqlite_int64 rowid;
72178 Mem **apArg;
72179 Mem *pX;
 
72180
72181 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
72182 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
72183 );
72184 assert( p->readOnly==0 );
72185 pVtab = pOp->p4.pVtab->pVtab;
72186 pModule = (sqlite3_module *)pVtab->pModule;
72187 nArg = pOp->p2;
72188 assert( pOp->p4type==P4_VTAB );
72189 if( ALWAYS(pModule->xUpdate) ){
72190 u8 vtabOnConflict = db->vtabOnConflict;
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++;
72199 }
72200 db->vtabOnConflict = pOp->p5;
72201 rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
72202 db->vtabOnConflict = vtabOnConflict;
72203 sqlite3VtabImportErrmsg(p, pVtab);
72204 if( rc==SQLITE_OK && pOp->p1 ){
72205 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
72206 db->lastRowid = lastRowid = rowid;
72207 }
72208 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
72209 if( pOp->p5==OE_Ignore ){
72210 rc = SQLITE_OK;
72211 }else{
@@ -72808,38 +72261,36 @@
72261 **
72262 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72263 ** the UTF-8 string contained in P4 is emitted on the trace callback.
72264 */
72265 case OP_Trace: {
 
72266 char *zTrace;
72267 char *z;
 
72268
72269 if( db->xTrace
72270 && !p->doingRerun
72271 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72272 ){
72273 z = sqlite3VdbeExpandSql(p, zTrace);
72274 db->xTrace(db->pTraceArg, z);
72275 sqlite3DbFree(db, z);
72276 }
72277 #ifdef SQLITE_USE_FCNTL_TRACE
72278 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72279 if( zTrace ){
72280 int i;
72281 for(i=0; i<db->nDb; i++){
72282 if( ((1<<i) & p->btreeMask)==0 ) continue;
72283 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
72284 }
72285 }
72286 #endif /* SQLITE_USE_FCNTL_TRACE */
72287 #ifdef SQLITE_DEBUG
72288 if( (db->flags & SQLITE_SqlTrace)!=0
72289 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72290 ){
72291 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
72292 }
72293 #endif /* SQLITE_DEBUG */
72294 break;
72295 }
72296 #endif
@@ -72964,10 +72415,11 @@
72415 rc = SQLITE_INTERRUPT;
72416 p->rc = rc;
72417 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
72418 goto vdbe_error_halt;
72419 }
72420
72421
72422 /************** End of vdbe.c ************************************************/
72423 /************** Begin file vdbeblob.c ****************************************/
72424 /*
72425 ** 2007 May 1
@@ -88225,13 +87677,13 @@
87677 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
87678 errMsg.db = pParse->db;
87679 for(j=0; j<pIdx->nKeyCol; j++){
87680 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
87681 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
87682 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
87683 sqlite3StrAccumAppend(&errMsg, ".", 1);
87684 sqlite3StrAccumAppendAll(&errMsg, zCol);
87685 }
87686 zErr = sqlite3StrAccumFinish(&errMsg);
87687 sqlite3HaltConstraint(pParse,
87688 (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
87689 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88419,12 +87871,13 @@
87871 }
87872 if( pKey ){
87873 assert( sqlite3KeyInfoIsWriteable(pKey) );
87874 for(i=0; i<nCol; i++){
87875 char *zColl = pIdx->azColl[i];
87876 assert( zColl!=0 );
87877 pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
87878 sqlite3LocateCollSeq(pParse, zColl);
87879 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
87880 }
87881 if( pParse->nErr ){
87882 sqlite3KeyInfoUnref(pKey);
87883 }else{
@@ -91238,15 +90691,15 @@
90691 nSep = sqlite3_value_bytes(argv[1]);
90692 }else{
90693 zSep = ",";
90694 nSep = 1;
90695 }
90696 if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep);
90697 }
90698 zVal = (char*)sqlite3_value_text(argv[0]);
90699 nVal = sqlite3_value_bytes(argv[0]);
90700 if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal);
90701 }
90702 }
90703 static void groupConcatFinalize(sqlite3_context *context){
90704 StrAccum *pAccum;
90705 pAccum = sqlite3_aggregate_context(context, 0);
@@ -110314,12 +109767,11 @@
109767 int res; /* Result of comparison operation */
109768
109769 #ifndef SQLITE_DEBUG
109770 UNUSED_PARAMETER( pParse );
109771 #endif
109772 assert( pRec!=0 );
 
109773 iCol = pRec->nField - 1;
109774 assert( pIdx->nSample>0 );
109775 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
109776 do{
109777 iTest = (iMin+i)/2;
@@ -110978,11 +110430,11 @@
110430 int iTerm, /* Index of this term. First is zero */
110431 const char *zColumn, /* Name of the column */
110432 const char *zOp /* Name of the operator */
110433 ){
110434 if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110435 sqlite3StrAccumAppendAll(pStr, zColumn);
110436 sqlite3StrAccumAppend(pStr, zOp, 1);
110437 sqlite3StrAccumAppend(pStr, "?", 1);
110438 }
110439
110440 /*
@@ -111024,11 +110476,11 @@
110476 if( i>=nSkip ){
110477 explainAppendTerm(&txt, i, z, "=");
110478 }else{
110479 if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
110480 sqlite3StrAccumAppend(&txt, "ANY(", 4);
110481 sqlite3StrAccumAppendAll(&txt, z);
110482 sqlite3StrAccumAppend(&txt, ")", 1);
110483 }
110484 }
110485
110486 j = i;
@@ -119582,11 +119034,12 @@
119034 }
119035 db->lookaside.pEnd = p;
119036 db->lookaside.bEnabled = 1;
119037 db->lookaside.bMalloced = pBuf==0 ?1:0;
119038 }else{
119039 db->lookaside.pStart = db;
119040 db->lookaside.pEnd = db;
119041 db->lookaside.bEnabled = 0;
119042 db->lookaside.bMalloced = 0;
119043 }
119044 return SQLITE_OK;
119045 }
@@ -120080,10 +119533,11 @@
119533 case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
119534 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
119535 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
119536 case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
119537 case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
119538 case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
119539 case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
119540 case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
119541 case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
119542 case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
119543 case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
119544
+13 -4
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.8.2"
111
-#define SQLITE_VERSION_NUMBER 3008002
112
-#define SQLITE_SOURCE_ID "2013-12-03 10:35:00 e4164fd8f75ce1c8d63bec70db7049b68208c12c"
110
+#define SQLITE_VERSION "3.8.3"
111
+#define SQLITE_VERSION_NUMBER 3008003
112
+#define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -489,10 +489,11 @@
489489
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490490
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491491
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492492
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493493
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
494
+#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
494495
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
495496
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
496497
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
497498
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
498499
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -556,11 +557,12 @@
556557
** information is written to disk in the same order as calls
557558
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
558559
** after reboot following a crash or power loss, the only bytes in a
559560
** file that were written at the application level might have changed
560561
** and that adjacent bytes, even bytes within the same sector are
561
-** guaranteed to be unchanged.
562
+** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
563
+** flag indicate that a file cannot be deleted when open.
562564
*/
563565
#define SQLITE_IOCAP_ATOMIC 0x00000001
564566
#define SQLITE_IOCAP_ATOMIC512 0x00000002
565567
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
566568
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -919,10 +921,16 @@
919921
** This file control is used by some VFS activity tracing [shims].
920922
** The argument is a zero-terminated string. Higher layers in the
921923
** SQLite stack may generate instances of this file control if
922924
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
923925
**
926
+** <li>[[SQLITE_FCNTL_HAS_MOVED]]
927
+** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
928
+** pointer to an integer and it writes a boolean into that integer depending
929
+** on whether or not the file has been renamed, moved, or deleted since it
930
+** was first opened.
931
+**
924932
** </ul>
925933
*/
926934
#define SQLITE_FCNTL_LOCKSTATE 1
927935
#define SQLITE_GET_LOCKPROXYFILE 2
928936
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -939,10 +947,11 @@
939947
#define SQLITE_FCNTL_PRAGMA 14
940948
#define SQLITE_FCNTL_BUSYHANDLER 15
941949
#define SQLITE_FCNTL_TEMPFILENAME 16
942950
#define SQLITE_FCNTL_MMAP_SIZE 18
943951
#define SQLITE_FCNTL_TRACE 19
952
+#define SQLITE_FCNTL_HAS_MOVED 20
944953
945954
/*
946955
** CAPI3REF: Mutex Handle
947956
**
948957
** The mutex module within SQLite defines [sqlite3_mutex] to be an
949958
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-12-03 10:35:00 e4164fd8f75ce1c8d63bec70db7049b68208c12c"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -489,10 +489,11 @@
489 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
 
494 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
495 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
496 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
497 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
498 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -556,11 +557,12 @@
556 ** information is written to disk in the same order as calls
557 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
558 ** after reboot following a crash or power loss, the only bytes in a
559 ** file that were written at the application level might have changed
560 ** and that adjacent bytes, even bytes within the same sector are
561 ** guaranteed to be unchanged.
 
562 */
563 #define SQLITE_IOCAP_ATOMIC 0x00000001
564 #define SQLITE_IOCAP_ATOMIC512 0x00000002
565 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
566 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -919,10 +921,16 @@
919 ** This file control is used by some VFS activity tracing [shims].
920 ** The argument is a zero-terminated string. Higher layers in the
921 ** SQLite stack may generate instances of this file control if
922 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
923 **
 
 
 
 
 
 
924 ** </ul>
925 */
926 #define SQLITE_FCNTL_LOCKSTATE 1
927 #define SQLITE_GET_LOCKPROXYFILE 2
928 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -939,10 +947,11 @@
939 #define SQLITE_FCNTL_PRAGMA 14
940 #define SQLITE_FCNTL_BUSYHANDLER 15
941 #define SQLITE_FCNTL_TEMPFILENAME 16
942 #define SQLITE_FCNTL_MMAP_SIZE 18
943 #define SQLITE_FCNTL_TRACE 19
 
944
945 /*
946 ** CAPI3REF: Mutex Handle
947 **
948 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
949
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -489,10 +489,11 @@
489 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
494 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
495 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
496 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
497 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
498 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
499 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -556,11 +557,12 @@
557 ** information is written to disk in the same order as calls
558 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
559 ** after reboot following a crash or power loss, the only bytes in a
560 ** file that were written at the application level might have changed
561 ** and that adjacent bytes, even bytes within the same sector are
562 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
563 ** flag indicate that a file cannot be deleted when open.
564 */
565 #define SQLITE_IOCAP_ATOMIC 0x00000001
566 #define SQLITE_IOCAP_ATOMIC512 0x00000002
567 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
568 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -919,10 +921,16 @@
921 ** This file control is used by some VFS activity tracing [shims].
922 ** The argument is a zero-terminated string. Higher layers in the
923 ** SQLite stack may generate instances of this file control if
924 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
925 **
926 ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
927 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
928 ** pointer to an integer and it writes a boolean into that integer depending
929 ** on whether or not the file has been renamed, moved, or deleted since it
930 ** was first opened.
931 **
932 ** </ul>
933 */
934 #define SQLITE_FCNTL_LOCKSTATE 1
935 #define SQLITE_GET_LOCKPROXYFILE 2
936 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -939,10 +947,11 @@
947 #define SQLITE_FCNTL_PRAGMA 14
948 #define SQLITE_FCNTL_BUSYHANDLER 15
949 #define SQLITE_FCNTL_TEMPFILENAME 16
950 #define SQLITE_FCNTL_MMAP_SIZE 18
951 #define SQLITE_FCNTL_TRACE 19
952 #define SQLITE_FCNTL_HAS_MOVED 20
953
954 /*
955 ** CAPI3REF: Mutex Handle
956 **
957 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
958

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button