Fossil SCM

Update the built-in SQLite to the latest 3.39.0 alpha for testing.

drh 2022-04-01 17:33 trunk
Commit aa2066b5d257674854695b12b8a98caa9fdc4fd824db355657a5275fc69e53c3
2 files changed +242 -180 +1 -1
+242 -180
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.39.0"
456456
#define SQLITE_VERSION_NUMBER 3039000
457
-#define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc"
457
+#define SQLITE_SOURCE_ID "2022-04-01 17:23:17 a7d79560a0efd6221ba59ce84bcb4fa94024a901ac4a45e192ddecc6e1b5c78c"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -22410,10 +22410,11 @@
2241022410
FuncDef *pFunc; /* Pointer to function information */
2241122411
Mem *pMem; /* Memory cell used to store aggregate context */
2241222412
Vdbe *pVdbe; /* The VM that owns this context */
2241322413
int iOp; /* Instruction number of OP_Function */
2241422414
int isError; /* Error code returned by the function. */
22415
+ u8 enc; /* Encoding to use for results */
2241522416
u8 skipFlag; /* Skip accumulator loading if true */
2241622417
u8 argc; /* Number of arguments */
2241722418
sqlite3_value *argv[1]; /* Argument set */
2241822419
};
2241922420
@@ -22458,11 +22459,10 @@
2245822459
struct Vdbe {
2245922460
sqlite3 *db; /* The database connection that owns this statement */
2246022461
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
2246122462
Parse *pParse; /* Parsing context used to create this Vdbe */
2246222463
ynVar nVar; /* Number of entries in aVar[] */
22463
- u32 iVdbeMagic; /* Magic number defining state of the SQL statement */
2246422464
int nMem; /* Number of memory locations currently allocated */
2246522465
int nCursor; /* Number of slots in apCsr[] */
2246622466
u32 cacheCtr; /* VdbeCursor row cache generation counter */
2246722467
int pc; /* The program counter */
2246822468
int rc; /* Value to return */
@@ -22497,10 +22497,11 @@
2249722497
u16 nResColumn; /* Number of columns in one row of the result set */
2249822498
u8 errorAction; /* Recovery action to do in case of an error */
2249922499
u8 minWriteFileFormat; /* Minimum file format for writable database files */
2250022500
u8 prepFlags; /* SQLITE_PREPARE_* flags */
2250122501
u8 doingRerun; /* True if rerunning after an auto-reprepare */
22502
+ u8 eVdbeState; /* On of the VDBE_*_STATE values */
2250222503
bft expired:2; /* 1: recompile VM immediately 2: when convenient */
2250322504
bft explain:2; /* True if EXPLAIN present on SQL command */
2250422505
bft changeCntOn:1; /* True to update the change-counter */
2250522506
bft runOnlyOnce:1; /* Automatically expire on reset */
2250622507
bft usesStmtJournal:1; /* True if uses a statement journal */
@@ -22527,17 +22528,16 @@
2252722528
ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
2252822529
#endif
2252922530
};
2253022531
2253122532
/*
22532
-** The following are allowed values for Vdbe.magic
22533
+** The following are allowed values for Vdbe.eVdbeState
2253322534
*/
22534
-#define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */
22535
-#define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */
22536
-#define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */
22537
-#define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */
22538
-#define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */
22535
+#define VDBE_INIT_STATE 0 /* Prepared statement under construction */
22536
+#define VDBE_READY_STATE 1 /* Ready to run but not yet started */
22537
+#define VDBE_RUN_STATE 2 /* Run in progress */
22538
+#define VDBE_HALT_STATE 3 /* Finished. Need reset() or finalize() */
2253922539
2254022540
/*
2254122541
** Structure used to store the context required by the
2254222542
** sqlite3_preupdate_*() API functions.
2254322543
*/
@@ -27002,12 +27002,17 @@
2700227002
** 32-bit signed integer. Hence the largest allocation is 0x40000000
2700327003
** or 1073741824 bytes.
2700427004
*/
2700527005
static int memsys5Roundup(int n){
2700627006
int iFullSz;
27007
- if( n > 0x40000000 ) return 0;
27008
- for(iFullSz=mem5.szAtom; iFullSz<n; iFullSz *= 2);
27007
+ if( n<=mem5.szAtom*2 ){
27008
+ if( n<=mem5.szAtom ) return mem5.szAtom;
27009
+ return mem5.szAtom*2;
27010
+ }
27011
+ if( n>0x40000000 ) return 0;
27012
+ for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27013
+ if( (iFullSz/2)>=n ) return iFullSz/2;
2700927014
return iFullSz;
2701027015
}
2701127016
2701227017
/*
2701327018
** Return the ceiling of the logarithm base 2 of iValue.
@@ -74949,11 +74954,10 @@
7494974954
** balance_deeper()
7495074955
** balance_nonroot()
7495174956
*/
7495274957
static int balance(BtCursor *pCur){
7495374958
int rc = SQLITE_OK;
74954
- const int nMin = pCur->pBt->usableSize * 2 / 3;
7495574959
u8 aBalanceQuickSpace[13];
7495674960
u8 *pFree = 0;
7495774961
7495874962
VVA_ONLY( int balance_quick_called = 0 );
7495974963
VVA_ONLY( int balance_deeper_called = 0 );
@@ -74961,11 +74965,15 @@
7496174965
do {
7496274966
int iPage;
7496374967
MemPage *pPage = pCur->pPage;
7496474968
7496574969
if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
74966
- if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
74970
+ if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
74971
+ /* No rebalance required as long as:
74972
+ ** (1) There are no overflow cells
74973
+ ** (2) The amount of free space on the page is less than 2/3rds of
74974
+ ** the total usable space on the page. */
7496774975
break;
7496874976
}else if( (iPage = pCur->iPage)==0 ){
7496974977
if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
7497074978
/* The root page of the b-tree is overfull. In this case call the
7497174979
** balance_deeper() function to create a new child for the root-page
@@ -75775,11 +75783,19 @@
7577575783
** on the leaf node first. If the balance proceeds far enough up the
7577675784
** tree that we can be sure that any problem in the internal node has
7577775785
** been corrected, so be it. Otherwise, after balancing the leaf node,
7577875786
** walk the cursor up the tree to the internal node and balance it as
7577975787
** well. */
75780
- rc = balance(pCur);
75788
+ assert( pCur->pPage->nOverflow==0 );
75789
+ assert( pCur->pPage->nFree>=0 );
75790
+ if( pCur->pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
75791
+ /* Optimization: If the free space is less than 2/3rds of the page,
75792
+ ** then balance() will always be a no-op. No need to invoke it. */
75793
+ rc = SQLITE_OK;
75794
+ }else{
75795
+ rc = balance(pCur);
75796
+ }
7578175797
if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
7578275798
releasePageNotNull(pCur->pPage);
7578375799
pCur->iPage--;
7578475800
while( pCur->iPage>iCellDepth ){
7578575801
releasePage(pCur->apPage[pCur->iPage--]);
@@ -78270,11 +78286,15 @@
7827078286
#endif
7827178287
assert( pMem!=0 );
7827278288
assert( !sqlite3VdbeMemIsRowSet(pMem) );
7827378289
assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
7827478290
|| desiredEnc==SQLITE_UTF16BE );
78275
- if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
78291
+ if( !(pMem->flags&MEM_Str) ){
78292
+ pMem->enc = desiredEnc;
78293
+ return SQLITE_OK;
78294
+ }
78295
+ if( pMem->enc==desiredEnc ){
7827678296
return SQLITE_OK;
7827778297
}
7827878298
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
7827978299
#ifdef SQLITE_OMIT_UTF16
7828078300
return SQLITE_ERROR;
@@ -78529,10 +78549,11 @@
7852978549
t.flags = MEM_Null;
7853078550
t.db = pMem->db;
7853178551
ctx.pOut = &t;
7853278552
ctx.pMem = pMem;
7853378553
ctx.pFunc = pFunc;
78554
+ ctx.enc = ENC(t.db);
7853478555
pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
7853578556
assert( (pMem->flags & MEM_Dyn)==0 );
7853678557
if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
7853778558
memcpy(pMem, &t, sizeof(t));
7853878559
return ctx.isError;
@@ -78556,10 +78577,11 @@
7855678577
memset(&ctx, 0, sizeof(ctx));
7855778578
sqlite3VdbeMemSetNull(pOut);
7855878579
ctx.pOut = pOut;
7855978580
ctx.pMem = pAccum;
7856078581
ctx.pFunc = pFunc;
78582
+ ctx.enc = ENC(pAccum->db);
7856178583
pFunc->xValue(&ctx);
7856278584
return ctx.isError;
7856378585
}
7856478586
#endif /* SQLITE_OMIT_WINDOWFUNC */
7856578587
@@ -79173,10 +79195,17 @@
7917379195
** If the string is too large (if it exceeds the SQLITE_LIMIT_LENGTH
7917479196
** size limit) then no memory allocation occurs. If the string can be
7917579197
** stored without allocating memory, then it is. If a memory allocation
7917679198
** is required to store the string, then value of pMem is unchanged. In
7917779199
** either case, SQLITE_TOOBIG is returned.
79200
+**
79201
+** The "enc" parameter is the text encoding for the string, or zero
79202
+** to store a blob.
79203
+**
79204
+** If n is negative, then the string consists of all bytes up to but
79205
+** excluding the first zero character. The n parameter must be
79206
+** non-negative for blobs.
7917879207
*/
7917979208
SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
7918079209
Mem *pMem, /* Memory cell to set to string value */
7918179210
const char *z, /* String pointer */
7918279211
i64 n, /* Bytes in string, or negative */
@@ -79183,15 +79212,16 @@
7918379212
u8 enc, /* Encoding of z. 0 for BLOBs */
7918479213
void (*xDel)(void*) /* Destructor function */
7918579214
){
7918679215
i64 nByte = n; /* New value for pMem->n */
7918779216
int iLimit; /* Maximum allowed string or blob size */
79188
- u16 flags = 0; /* New value for pMem->flags */
79217
+ u16 flags; /* New value for pMem->flags */
7918979218
7919079219
assert( pMem!=0 );
7919179220
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
7919279221
assert( !sqlite3VdbeMemIsRowSet(pMem) );
79222
+ assert( enc!=0 || n>=0 );
7919379223
7919479224
/* If z is a NULL pointer, set pMem to contain an SQL NULL. */
7919579225
if( !z ){
7919679226
sqlite3VdbeMemSetNull(pMem);
7919779227
return SQLITE_OK;
@@ -79200,19 +79230,34 @@
7920079230
if( pMem->db ){
7920179231
iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
7920279232
}else{
7920379233
iLimit = SQLITE_MAX_LENGTH;
7920479234
}
79205
- flags = (enc==0?MEM_Blob:MEM_Str);
7920679235
if( nByte<0 ){
7920779236
assert( enc!=0 );
7920879237
if( enc==SQLITE_UTF8 ){
7920979238
nByte = strlen(z);
7921079239
}else{
7921179240
for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
7921279241
}
79213
- flags |= MEM_Term;
79242
+ flags= MEM_Str|MEM_Term;
79243
+ }else if( enc==0 ){
79244
+ flags = MEM_Blob;
79245
+ enc = SQLITE_UTF8;
79246
+ }else{
79247
+ flags = MEM_Str;
79248
+ }
79249
+ if( nByte>iLimit ){
79250
+ if( xDel && xDel!=SQLITE_TRANSIENT ){
79251
+ if( xDel==SQLITE_DYNAMIC ){
79252
+ sqlite3DbFree(pMem->db, (void*)z);
79253
+ }else{
79254
+ xDel((void*)z);
79255
+ }
79256
+ }
79257
+ sqlite3VdbeMemSetNull(pMem);
79258
+ return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
7921479259
}
7921579260
7921679261
/* The following block sets the new values of Mem.z and Mem.xDel. It
7921779262
** also sets a flag in local variable "flags" to indicate the memory
7921879263
** management (one of MEM_Dyn or MEM_Static).
@@ -79220,13 +79265,10 @@
7922079265
if( xDel==SQLITE_TRANSIENT ){
7922179266
i64 nAlloc = nByte;
7922279267
if( flags&MEM_Term ){
7922379268
nAlloc += (enc==SQLITE_UTF8?1:2);
7922479269
}
79225
- if( nByte>iLimit ){
79226
- return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
79227
- }
7922879270
testcase( nAlloc==0 );
7922979271
testcase( nAlloc==31 );
7923079272
testcase( nAlloc==32 );
7923179273
if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
7923279274
return SQLITE_NOMEM_BKPT;
@@ -79244,30 +79286,18 @@
7924479286
}
7924579287
}
7924679288
7924779289
pMem->n = (int)(nByte & 0x7fffffff);
7924879290
pMem->flags = flags;
79249
- if( enc ){
79250
- pMem->enc = enc;
79251
-#ifdef SQLITE_ENABLE_SESSION
79252
- }else if( pMem->db==0 ){
79253
- pMem->enc = SQLITE_UTF8;
79254
-#endif
79255
- }else{
79256
- assert( pMem->db!=0 );
79257
- pMem->enc = ENC(pMem->db);
79258
- }
79291
+ pMem->enc = enc;
7925979292
7926079293
#ifndef SQLITE_OMIT_UTF16
7926179294
if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
7926279295
return SQLITE_NOMEM_BKPT;
7926379296
}
7926479297
#endif
7926579298
79266
- if( nByte>iLimit ){
79267
- return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
79268
- }
7926979299
7927079300
return SQLITE_OK;
7927179301
}
7927279302
7927379303
/*
@@ -79545,10 +79575,11 @@
7954579575
7954679576
assert( pCtx->pParse->rc==SQLITE_OK );
7954779577
memset(&ctx, 0, sizeof(ctx));
7954879578
ctx.pOut = pVal;
7954979579
ctx.pFunc = pFunc;
79580
+ ctx.enc = ENC(db);
7955079581
pFunc->xSFunc(&ctx, nVal, apVal);
7955179582
if( ctx.isError ){
7955279583
rc = ctx.isError;
7955379584
sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
7955479585
}else{
@@ -80055,11 +80086,11 @@
8005580086
db->pVdbe->pPrev = p;
8005680087
}
8005780088
p->pNext = db->pVdbe;
8005880089
p->pPrev = 0;
8005980090
db->pVdbe = p;
80060
- p->iVdbeMagic = VDBE_MAGIC_INIT;
80091
+ assert( p->eVdbeState==VDBE_INIT_STATE );
8006180092
p->pParse = pParse;
8006280093
pParse->pVdbe = p;
8006380094
assert( pParse->aLabel==0 );
8006480095
assert( pParse->nLabel==0 );
8006580096
assert( p->nOpAlloc==0 );
@@ -80256,11 +80287,11 @@
8025680287
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
8025780288
int i;
8025880289
VdbeOp *pOp;
8025980290
8026080291
i = p->nOp;
80261
- assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
80292
+ assert( p->eVdbeState==VDBE_INIT_STATE );
8026280293
assert( op>=0 && op<0xff );
8026380294
if( p->nOpAlloc<=i ){
8026480295
return growOp3(p, op, p1, p2, p3);
8026580296
}
8026680297
assert( p->aOp!=0 );
@@ -80588,11 +80619,11 @@
8058880619
}
8058980620
}
8059080621
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
8059180622
Parse *p = v->pParse;
8059280623
int j = ADDR(x);
80593
- assert( v->iVdbeMagic==VDBE_MAGIC_INIT );
80624
+ assert( v->eVdbeState==VDBE_INIT_STATE );
8059480625
assert( j<-p->nLabel );
8059580626
assert( j>=0 );
8059680627
#ifdef SQLITE_DEBUG
8059780628
if( p->db->flags & SQLITE_VdbeAddopTrace ){
8059880629
printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
@@ -80719,10 +80750,12 @@
8071980750
int hasCreateTable = 0;
8072080751
int hasCreateIndex = 0;
8072180752
int hasInitCoroutine = 0;
8072280753
Op *pOp;
8072380754
VdbeOpIter sIter;
80755
+
80756
+ if( v==0 ) return 0;
8072480757
memset(&sIter, 0, sizeof(sIter));
8072580758
sIter.v = v;
8072680759
8072780760
while( (pOp = opIterNext(&sIter))!=0 ){
8072880761
int opcode = pOp->opcode;
@@ -80883,22 +80916,24 @@
8088380916
assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
8088480917
}
8088580918
if( pOp==p->aOp ) break;
8088680919
pOp--;
8088780920
}
80888
- sqlite3DbFree(p->db, pParse->aLabel);
80889
- pParse->aLabel = 0;
80921
+ if( aLabel ){
80922
+ sqlite3DbFreeNN(p->db, pParse->aLabel);
80923
+ pParse->aLabel = 0;
80924
+ }
8089080925
pParse->nLabel = 0;
8089180926
*pMaxFuncArgs = nMaxArgs;
8089280927
assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
8089380928
}
8089480929
8089580930
/*
8089680931
** Return the address of the next instruction to be inserted.
8089780932
*/
8089880933
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
80899
- assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
80934
+ assert( p->eVdbeState==VDBE_INIT_STATE );
8090080935
return p->nOp;
8090180936
}
8090280937
8090380938
/*
8090480939
** Verify that at least N opcode slots are available in p without
@@ -80979,11 +81014,11 @@
8097981014
int iLineno /* Source-file line number of first opcode */
8098081015
){
8098181016
int i;
8098281017
VdbeOp *pOut, *pFirst;
8098381018
assert( nOp>0 );
80984
- assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
81019
+ assert( p->eVdbeState==VDBE_INIT_STATE );
8098581020
if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
8098681021
return 0;
8098781022
}
8098881023
pFirst = pOut = &p->aOp[p->nOp];
8098981024
for(i=0; i<nOp; i++, aOp++, pOut++){
@@ -81170,17 +81205,20 @@
8117081205
** Free the space allocated for aOp and any p4 values allocated for the
8117181206
** opcodes contained within. If aOp is not NULL it is assumed to contain
8117281207
** nOp entries.
8117381208
*/
8117481209
static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
81210
+ assert( nOp>=0 );
8117581211
if( aOp ){
81176
- Op *pOp;
81177
- for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
81212
+ Op *pOp = &aOp[nOp-1];
81213
+ while(1){ /* Exit via break */
8117881214
if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p);
8117981215
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
8118081216
sqlite3DbFree(db, pOp->zComment);
8118181217
#endif
81218
+ if( pOp==aOp ) break;
81219
+ pOp--;
8118281220
}
8118381221
sqlite3DbFreeNN(db, aOp);
8118481222
}
8118581223
}
8118681224
@@ -81302,11 +81340,11 @@
8130281340
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
8130381341
Op *pOp;
8130481342
sqlite3 *db;
8130581343
assert( p!=0 );
8130681344
db = p->db;
81307
- assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
81345
+ assert( p->eVdbeState==VDBE_INIT_STATE );
8130881346
assert( p->aOp!=0 || db->mallocFailed );
8130981347
if( db->mallocFailed ){
8131081348
if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4);
8131181349
return;
8131281350
}
@@ -81430,11 +81468,11 @@
8143081468
*/
8143181469
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
8143281470
/* C89 specifies that the constant "dummy" will be initialized to all
8143381471
** zeros, which is correct. MSVC generates a warning, nevertheless. */
8143481472
static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
81435
- assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
81473
+ assert( p->eVdbeState==VDBE_INIT_STATE );
8143681474
if( addr<0 ){
8143781475
addr = p->nOp - 1;
8143881476
}
8143981477
assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
8144081478
if( p->db->mallocFailed ){
@@ -82132,11 +82170,11 @@
8213282170
int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
8213382171
Op *aOp; /* Array of opcodes */
8213482172
Op *pOp; /* Current opcode */
8213582173
8213682174
assert( p->explain );
82137
- assert( p->iVdbeMagic==VDBE_MAGIC_RUN );
82175
+ assert( p->eVdbeState==VDBE_RUN_STATE );
8213882176
assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
8213982177
8214082178
/* Even though this opcode does not use dynamic strings for
8214182179
** the result, result columns may become dynamic if the user calls
8214282180
** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
@@ -82312,18 +82350,19 @@
8231282350
SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
8231382351
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
8231482352
int i;
8231582353
#endif
8231682354
assert( p!=0 );
82317
- assert( p->iVdbeMagic==VDBE_MAGIC_INIT || p->iVdbeMagic==VDBE_MAGIC_RESET );
82355
+ assert( p->eVdbeState==VDBE_INIT_STATE
82356
+ || p->eVdbeState==VDBE_READY_STATE
82357
+ || p->eVdbeState==VDBE_HALT_STATE );
8231882358
8231982359
/* There should be at least one opcode.
8232082360
*/
8232182361
assert( p->nOp>0 );
8232282362
82323
- /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
82324
- p->iVdbeMagic = VDBE_MAGIC_RUN;
82363
+ p->eVdbeState = VDBE_READY_STATE;
8232582364
8232682365
#ifdef SQLITE_DEBUG
8232782366
for(i=0; i<p->nMem; i++){
8232882367
assert( p->aMem[i].db==p->db );
8232982368
}
@@ -82375,11 +82414,11 @@
8237582414
struct ReusableSpace x; /* Reusable bulk memory */
8237682415
8237782416
assert( p!=0 );
8237882417
assert( p->nOp>0 );
8237982418
assert( pParse!=0 );
82380
- assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
82419
+ assert( p->eVdbeState==VDBE_INIT_STATE );
8238182420
assert( pParse==p->pParse );
8238282421
p->pVList = pParse->pVList;
8238382422
pParse->pVList = 0;
8238482423
db = p->db;
8238582424
assert( db->mallocFailed==0 );
@@ -82516,18 +82555,16 @@
8251682555
8251782556
/*
8251882557
** Close all cursors in the current frame.
8251982558
*/
8252082559
static void closeCursorsInFrame(Vdbe *p){
82521
- if( p->apCsr ){
82522
- int i;
82523
- for(i=0; i<p->nCursor; i++){
82524
- VdbeCursor *pC = p->apCsr[i];
82525
- if( pC ){
82526
- sqlite3VdbeFreeCursor(p, pC);
82527
- p->apCsr[i] = 0;
82528
- }
82560
+ int i;
82561
+ for(i=0; i<p->nCursor; i++){
82562
+ VdbeCursor *pC = p->apCsr[i];
82563
+ if( pC ){
82564
+ sqlite3VdbeFreeCursor(p, pC);
82565
+ p->apCsr[i] = 0;
8252982566
}
8253082567
}
8253182568
}
8253282569
8253382570
/*
@@ -82572,13 +82609,11 @@
8257282609
p->pFrame = 0;
8257382610
p->nFrame = 0;
8257482611
}
8257582612
assert( p->nFrame==0 );
8257682613
closeCursorsInFrame(p);
82577
- if( p->aMem ){
82578
- releaseMemArray(p->aMem, p->nMem);
82579
- }
82614
+ releaseMemArray(p->aMem, p->nMem);
8258082615
while( p->pDelFrame ){
8258182616
VdbeFrame *pDel = p->pDelFrame;
8258282617
p->pDelFrame = pDel->pParent;
8258382618
sqlite3VdbeFrameDelete(pDel);
8258482619
}
@@ -83014,10 +83049,11 @@
8301483049
|| (!deferred && p->nFkConstraint>0)
8301583050
){
8301683051
p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
8301783052
p->errorAction = OE_Abort;
8301883053
sqlite3VdbeError(p, "FOREIGN KEY constraint failed");
83054
+ if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ) return SQLITE_ERROR;
8301983055
return SQLITE_CONSTRAINT_FOREIGNKEY;
8302083056
}
8302183057
return SQLITE_OK;
8302283058
}
8302383059
#endif
@@ -83053,11 +83089,11 @@
8305383089
** Then the internal cache might have been left in an inconsistent
8305483090
** state. We need to rollback the statement transaction, if there is
8305583091
** one, or the complete transaction if there is no statement transaction.
8305683092
*/
8305783093
83058
- if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){
83094
+ if( p->eVdbeState!=VDBE_RUN_STATE ){
8305983095
return SQLITE_OK;
8306083096
}
8306183097
if( db->mallocFailed ){
8306283098
p->rc = SQLITE_NOMEM_BKPT;
8306383099
}
@@ -83064,11 +83100,11 @@
8306483100
closeAllCursors(p);
8306583101
checkActiveVdbeCnt(db);
8306683102
8306783103
/* No commit or rollback needed if the program never started or if the
8306883104
** SQL statement does not read or write a database file. */
83069
- if( p->pc>=0 && p->bIsReader ){
83105
+ if( p->bIsReader ){
8307083106
int mrc; /* Primary error code from p->rc */
8307183107
int eStatementOp = 0;
8307283108
int isSpecialError; /* Set to true if a 'special' error */
8307383109
8307483110
/* Lock all btrees used by the statement */
@@ -83212,19 +83248,17 @@
8321283248
/* Release the locks */
8321383249
sqlite3VdbeLeave(p);
8321483250
}
8321583251
8321683252
/* We have successfully halted and closed the VM. Record this fact. */
83217
- if( p->pc>=0 ){
83218
- db->nVdbeActive--;
83219
- if( !p->readOnly ) db->nVdbeWrite--;
83220
- if( p->bIsReader ) db->nVdbeRead--;
83221
- assert( db->nVdbeActive>=db->nVdbeRead );
83222
- assert( db->nVdbeRead>=db->nVdbeWrite );
83223
- assert( db->nVdbeWrite>=0 );
83224
- }
83225
- p->iVdbeMagic = VDBE_MAGIC_HALT;
83253
+ db->nVdbeActive--;
83254
+ if( !p->readOnly ) db->nVdbeWrite--;
83255
+ if( p->bIsReader ) db->nVdbeRead--;
83256
+ assert( db->nVdbeActive>=db->nVdbeRead );
83257
+ assert( db->nVdbeRead>=db->nVdbeWrite );
83258
+ assert( db->nVdbeWrite>=0 );
83259
+ p->eVdbeState = VDBE_HALT_STATE;
8322683260
checkActiveVdbeCnt(db);
8322783261
if( db->mallocFailed ){
8322883262
p->rc = SQLITE_NOMEM_BKPT;
8322983263
}
8323083264
@@ -83302,12 +83336,12 @@
8330283336
**
8330383337
** After this routine is run, the VDBE should be ready to be executed
8330483338
** again.
8330583339
**
8330683340
** To look at it another way, this routine resets the state of the
83307
-** virtual machine from VDBE_MAGIC_RUN or VDBE_MAGIC_HALT back to
83308
-** VDBE_MAGIC_INIT.
83341
+** virtual machine from VDBE_RUN_STATE or VDBE_HALT_STATE back to
83342
+** VDBE_READY_STATE.
8330983343
*/
8331083344
SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
8331183345
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
8331283346
int i;
8331383347
#endif
@@ -83332,16 +83366,10 @@
8333283366
sqlite3VdbeTransferError(p);
8333383367
}else{
8333483368
db->errCode = p->rc;
8333583369
}
8333683370
if( p->runOnlyOnce ) p->expired = 1;
83337
- }else if( p->rc && p->expired ){
83338
- /* The expired flag was set on the VDBE before the first call
83339
- ** to sqlite3_step(). For consistency (since sqlite3_step() was
83340
- ** called), set the database error in this case as well.
83341
- */
83342
- sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
8334383371
}
8334483372
8334583373
/* Reset register contents and reclaim error message memory.
8334683374
*/
8334783375
#ifdef SQLITE_DEBUG
@@ -83394,21 +83422,23 @@
8339483422
}
8339583423
fclose(out);
8339683424
}
8339783425
}
8339883426
#endif
83399
- p->iVdbeMagic = VDBE_MAGIC_RESET;
8340083427
return p->rc & db->errMask;
8340183428
}
8340283429
8340383430
/*
8340483431
** Clean up and delete a VDBE after execution. Return an integer which is
8340583432
** the result code. Write any error message text into *pzErrMsg.
8340683433
*/
8340783434
SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){
8340883435
int rc = SQLITE_OK;
83409
- if( p->iVdbeMagic==VDBE_MAGIC_RUN || p->iVdbeMagic==VDBE_MAGIC_HALT ){
83436
+ assert( VDBE_RUN_STATE>VDBE_READY_STATE );
83437
+ assert( VDBE_HALT_STATE>VDBE_READY_STATE );
83438
+ assert( VDBE_INIT_STATE<VDBE_READY_STATE );
83439
+ if( p->eVdbeState>=VDBE_READY_STATE ){
8341083440
rc = sqlite3VdbeReset(p);
8341183441
assert( (rc & p->db->errMask)==rc );
8341283442
}
8341383443
sqlite3VdbeDelete(p);
8341483444
return rc;
@@ -83459,23 +83489,25 @@
8345983489
** the database connection and frees the object itself.
8346083490
*/
8346183491
SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
8346283492
SubProgram *pSub, *pNext;
8346383493
assert( p->db==0 || p->db==db );
83464
- releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
83494
+ if( p->aColName ){
83495
+ releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
83496
+ sqlite3DbFreeNN(db, p->aColName);
83497
+ }
8346583498
for(pSub=p->pProgram; pSub; pSub=pNext){
8346683499
pNext = pSub->pNext;
8346783500
vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
8346883501
sqlite3DbFree(db, pSub);
8346983502
}
83470
- if( p->iVdbeMagic!=VDBE_MAGIC_INIT ){
83503
+ if( p->eVdbeState!=VDBE_INIT_STATE ){
8347183504
releaseMemArray(p->aVar, p->nVar);
83472
- sqlite3DbFree(db, p->pVList);
83473
- sqlite3DbFree(db, p->pFree);
83505
+ if( p->pVList ) sqlite3DbFreeNN(db, p->pVList);
83506
+ if( p->pFree ) sqlite3DbFreeNN(db, p->pFree);
8347483507
}
8347583508
vdbeFreeOpArray(db, p->aOp, p->nOp);
83476
- sqlite3DbFree(db, p->aColName);
8347783509
sqlite3DbFree(db, p->zSql);
8347883510
#ifdef SQLITE_ENABLE_NORMALIZE
8347983511
sqlite3DbFree(db, p->zNormSql);
8348083512
{
8348183513
DblquoteStr *pThis, *pNext;
@@ -83513,12 +83545,10 @@
8351383545
db->pVdbe = p->pNext;
8351483546
}
8351583547
if( p->pNext ){
8351683548
p->pNext->pPrev = p->pPrev;
8351783549
}
83518
- p->iVdbeMagic = VDBE_MAGIC_DEAD;
83519
- p->db = 0;
8352083550
sqlite3DbFreeNN(db, p);
8352183551
}
8352283552
8352383553
/*
8352483554
** The cursor "p" has a pending seek operation that has not yet been
@@ -85638,20 +85668,26 @@
8563885668
const char *z, /* String pointer */
8563985669
int n, /* Bytes in string, or negative */
8564085670
u8 enc, /* Encoding of z. 0 for BLOBs */
8564185671
void (*xDel)(void*) /* Destructor function */
8564285672
){
85643
- int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel);
85673
+ Mem *pOut = pCtx->pOut;
85674
+ int rc = sqlite3VdbeMemSetStr(pOut, z, n, enc, xDel);
8564485675
if( rc ){
8564585676
if( rc==SQLITE_TOOBIG ){
8564685677
sqlite3_result_error_toobig(pCtx);
8564785678
}else{
8564885679
/* The only errors possible from sqlite3VdbeMemSetStr are
8564985680
** SQLITE_TOOBIG and SQLITE_NOMEM */
8565085681
assert( rc==SQLITE_NOMEM );
8565185682
sqlite3_result_error_nomem(pCtx);
8565285683
}
85684
+ return;
85685
+ }
85686
+ sqlite3VdbeChangeEncoding(pOut, pCtx->enc);
85687
+ if( sqlite3VdbeMemTooBig(pOut) ){
85688
+ sqlite3_result_error_toobig(pCtx);
8565385689
}
8565485690
}
8565585691
static int invokeValueDestructor(
8565685692
const void *p, /* Value to destroy */
8565785693
void (*xDel)(void*), /* The destructor */
@@ -85791,21 +85827,26 @@
8579185827
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
8579285828
setResultStrOrError(pCtx, z, n, SQLITE_UTF16LE, xDel);
8579385829
}
8579485830
#endif /* SQLITE_OMIT_UTF16 */
8579585831
SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
85832
+ Mem *pOut = pCtx->pOut;
8579685833
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
85797
- sqlite3VdbeMemCopy(pCtx->pOut, pValue);
85834
+ sqlite3VdbeMemCopy(pOut, pValue);
85835
+ sqlite3VdbeChangeEncoding(pOut, pCtx->enc);
85836
+ if( sqlite3VdbeMemTooBig(pOut) ){
85837
+ sqlite3_result_error_toobig(pCtx);
85838
+ }
8579885839
}
8579985840
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
85800
- assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
85801
- sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
85841
+ sqlite3_result_zeroblob64(pCtx, n>0 ? n : 0);
8580285842
}
8580385843
SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
8580485844
Mem *pOut = pCtx->pOut;
8580585845
assert( sqlite3_mutex_held(pOut->db->mutex) );
8580685846
if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
85847
+ sqlite3_result_error_toobig(pCtx);
8580785848
return SQLITE_TOOBIG;
8580885849
}
8580985850
#ifndef SQLITE_OMIT_INCRBLOB
8581085851
sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n);
8581185852
return SQLITE_OK;
@@ -85817,12 +85858,12 @@
8581785858
pCtx->isError = errCode ? errCode : -1;
8581885859
#ifdef SQLITE_DEBUG
8581985860
if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
8582085861
#endif
8582185862
if( pCtx->pOut->flags & MEM_Null ){
85822
- sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,
85823
- SQLITE_UTF8, SQLITE_STATIC);
85863
+ setResultStrOrError(pCtx, sqlite3ErrStr(errCode), -1, SQLITE_UTF8,
85864
+ SQLITE_STATIC);
8582485865
}
8582585866
}
8582685867
8582785868
/* Force an SQLITE_TOOBIG error. */
8582885869
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){
@@ -85891,85 +85932,94 @@
8589185932
*/
8589285933
static int sqlite3Step(Vdbe *p){
8589385934
sqlite3 *db;
8589485935
int rc;
8589585936
85896
- assert(p);
85897
- if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){
85898
- /* We used to require that sqlite3_reset() be called before retrying
85899
- ** sqlite3_step() after any error or after SQLITE_DONE. But beginning
85900
- ** with version 3.7.0, we changed this so that sqlite3_reset() would
85901
- ** be called automatically instead of throwing the SQLITE_MISUSE error.
85902
- ** This "automatic-reset" change is not technically an incompatibility,
85903
- ** since any application that receives an SQLITE_MISUSE is broken by
85904
- ** definition.
85905
- **
85906
- ** Nevertheless, some published applications that were originally written
85907
- ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
85908
- ** returns, and those were broken by the automatic-reset change. As a
85909
- ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
85910
- ** legacy behavior of returning SQLITE_MISUSE for cases where the
85911
- ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
85912
- ** or SQLITE_BUSY error.
85913
- */
85914
-#ifdef SQLITE_OMIT_AUTORESET
85915
- if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
85916
- sqlite3_reset((sqlite3_stmt*)p);
85917
- }else{
85918
- return SQLITE_MISUSE_BKPT;
85919
- }
85920
-#else
85921
- sqlite3_reset((sqlite3_stmt*)p);
85922
-#endif
85923
- }
85924
-
8592585937
/* Check that malloc() has not failed. If it has, return early. */
8592685938
db = p->db;
8592785939
if( db->mallocFailed ){
8592885940
p->rc = SQLITE_NOMEM;
8592985941
return SQLITE_NOMEM_BKPT;
8593085942
}
8593185943
85932
- if( p->pc<0 && p->expired ){
85933
- p->rc = SQLITE_SCHEMA;
85934
- rc = SQLITE_ERROR;
85935
- if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
85936
- /* If this statement was prepared using saved SQL and an
85937
- ** error has occurred, then return the error code in p->rc to the
85938
- ** caller. Set the error code in the database handle to the same value.
85939
- */
85940
- rc = sqlite3VdbeTransferError(p);
85941
- }
85942
- goto end_of_step;
85943
- }
85944
- if( p->pc<0 ){
85945
- /* If there are no other statements currently running, then
85946
- ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
85947
- ** from interrupting a statement that has not yet started.
85948
- */
85949
- if( db->nVdbeActive==0 ){
85950
- AtomicStore(&db->u1.isInterrupted, 0);
85951
- }
85952
-
85953
- assert( db->nVdbeWrite>0 || db->autoCommit==0
85954
- || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
85955
- );
85944
+ assert(p);
85945
+ if( p->eVdbeState!=VDBE_RUN_STATE ){
85946
+ restart_step:
85947
+ if( p->eVdbeState==VDBE_READY_STATE ){
85948
+ if( p->expired ){
85949
+ p->rc = SQLITE_SCHEMA;
85950
+ rc = SQLITE_ERROR;
85951
+ if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
85952
+ /* If this statement was prepared using saved SQL and an
85953
+ ** error has occurred, then return the error code in p->rc to the
85954
+ ** caller. Set the error code in the database handle to the same
85955
+ ** value.
85956
+ */
85957
+ rc = sqlite3VdbeTransferError(p);
85958
+ }
85959
+ goto end_of_step;
85960
+ }
85961
+
85962
+ /* If there are no other statements currently running, then
85963
+ ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
85964
+ ** from interrupting a statement that has not yet started.
85965
+ */
85966
+ if( db->nVdbeActive==0 ){
85967
+ AtomicStore(&db->u1.isInterrupted, 0);
85968
+ }
85969
+
85970
+ assert( db->nVdbeWrite>0 || db->autoCommit==0
85971
+ || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
85972
+ );
8595685973
8595785974
#ifndef SQLITE_OMIT_TRACE
85958
- if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
85959
- && !db->init.busy && p->zSql ){
85960
- sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
85961
- }else{
85962
- assert( p->startTime==0 );
85963
- }
85975
+ if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
85976
+ && !db->init.busy && p->zSql ){
85977
+ sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
85978
+ }else{
85979
+ assert( p->startTime==0 );
85980
+ }
8596485981
#endif
8596585982
85966
- db->nVdbeActive++;
85967
- if( p->readOnly==0 ) db->nVdbeWrite++;
85968
- if( p->bIsReader ) db->nVdbeRead++;
85969
- p->pc = 0;
85983
+ db->nVdbeActive++;
85984
+ if( p->readOnly==0 ) db->nVdbeWrite++;
85985
+ if( p->bIsReader ) db->nVdbeRead++;
85986
+ p->pc = 0;
85987
+ p->eVdbeState = VDBE_RUN_STATE;
85988
+ }else
85989
+
85990
+ if( ALWAYS(p->eVdbeState==VDBE_HALT_STATE) ){
85991
+ /* We used to require that sqlite3_reset() be called before retrying
85992
+ ** sqlite3_step() after any error or after SQLITE_DONE. But beginning
85993
+ ** with version 3.7.0, we changed this so that sqlite3_reset() would
85994
+ ** be called automatically instead of throwing the SQLITE_MISUSE error.
85995
+ ** This "automatic-reset" change is not technically an incompatibility,
85996
+ ** since any application that receives an SQLITE_MISUSE is broken by
85997
+ ** definition.
85998
+ **
85999
+ ** Nevertheless, some published applications that were originally written
86000
+ ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
86001
+ ** returns, and those were broken by the automatic-reset change. As a
86002
+ ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
86003
+ ** legacy behavior of returning SQLITE_MISUSE for cases where the
86004
+ ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
86005
+ ** or SQLITE_BUSY error.
86006
+ */
86007
+#ifdef SQLITE_OMIT_AUTORESET
86008
+ if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
86009
+ sqlite3_reset((sqlite3_stmt*)p);
86010
+ }else{
86011
+ return SQLITE_MISUSE_BKPT;
86012
+ }
86013
+#else
86014
+ sqlite3_reset((sqlite3_stmt*)p);
86015
+#endif
86016
+ assert( p->eVdbeState==VDBE_READY_STATE );
86017
+ goto restart_step;
86018
+ }
8597086019
}
86020
+
8597186021
#ifdef SQLITE_DEBUG
8597286022
p->rcApp = SQLITE_OK;
8597386023
#endif
8597486024
#ifndef SQLITE_OMIT_EXPLAIN
8597586025
if( p->explain ){
@@ -85980,11 +86030,16 @@
8598086030
db->nVdbeExec++;
8598186031
rc = sqlite3VdbeExec(p);
8598286032
db->nVdbeExec--;
8598386033
}
8598486034
85985
- if( rc!=SQLITE_ROW ){
86035
+ if( rc==SQLITE_ROW ){
86036
+ assert( p->rc==SQLITE_OK );
86037
+ assert( db->mallocFailed==0 );
86038
+ db->errCode = SQLITE_ROW;
86039
+ return SQLITE_ROW;
86040
+ }else{
8598686041
#ifndef SQLITE_OMIT_TRACE
8598786042
/* If the statement completed successfully, invoke the profile callback */
8598886043
checkProfileCallback(db, p);
8598986044
#endif
8599086045
@@ -86672,11 +86727,11 @@
8667286727
Mem *pVar;
8667386728
if( vdbeSafetyNotNull(p) ){
8667486729
return SQLITE_MISUSE_BKPT;
8667586730
}
8667686731
sqlite3_mutex_enter(p->db->mutex);
86677
- if( p->iVdbeMagic!=VDBE_MAGIC_RUN || p->pc>=0 ){
86732
+ if( p->eVdbeState!=VDBE_READY_STATE ){
8667886733
sqlite3Error(p->db, SQLITE_MISUSE);
8667986734
sqlite3_mutex_leave(p->db->mutex);
8668086735
sqlite3_log(SQLITE_MISUSE,
8668186736
"bind on a busy prepared statement: [%s]", p->zSql);
8668286737
return SQLITE_MISUSE_BKPT;
@@ -87025,11 +87080,11 @@
8702587080
/*
8702687081
** Return true if the prepared statement is in need of being reset.
8702787082
*/
8702887083
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
8702987084
Vdbe *v = (Vdbe*)pStmt;
87030
- return v!=0 && v->iVdbeMagic==VDBE_MAGIC_RUN && v->pc>=0;
87085
+ return v!=0 && v->eVdbeState==VDBE_RUN_STATE;
8703187086
}
8703287087
8703387088
/*
8703487089
** Return a pointer to the next prepared statement after pStmt associated
8703587090
** with database connection pDb. If pStmt is NULL, return the first
@@ -88339,11 +88394,11 @@
8833988394
#ifdef VDBE_PROFILE
8834088395
u64 start; /* CPU clock count at start of opcode */
8834188396
#endif
8834288397
/*** INSERT STACK UNION HERE ***/
8834388398
88344
- assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
88399
+ assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
8834588400
sqlite3VdbeEnter(p);
8834688401
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
8834788402
if( db->xProgress ){
8834888403
u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
8834988404
assert( 0 < db->nProgressOps );
@@ -94848,10 +94903,11 @@
9484894903
pCtx->pFunc = pOp->p4.pFunc;
9484994904
pCtx->iOp = (int)(pOp - aOp);
9485094905
pCtx->pVdbe = p;
9485194906
pCtx->skipFlag = 0;
9485294907
pCtx->isError = 0;
94908
+ pCtx->enc = encoding;
9485394909
pCtx->argc = n;
9485494910
pOp->p4type = P4_FUNCCTX;
9485594911
pOp->p4.pCtx = pCtx;
9485694912
9485794913
/* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
@@ -94977,13 +95033,10 @@
9497795033
sqlite3VdbeError(p, "%s", sqlite3_value_text(pMem));
9497895034
goto abort_due_to_error;
9497995035
}
9498095036
sqlite3VdbeChangeEncoding(pMem, encoding);
9498195037
UPDATE_MAX_BLOBSIZE(pMem);
94982
- if( sqlite3VdbeMemTooBig(pMem) ){
94983
- goto too_big;
94984
- }
9498595038
break;
9498695039
}
9498795040
9498895041
#ifndef SQLITE_OMIT_WAL
9498995042
/* Opcode: Checkpoint P1 P2 P3 * *
@@ -95500,10 +95553,11 @@
9550095553
pVtab = pCur->uc.pVCur->pVtab;
9550195554
pModule = pVtab->pModule;
9550295555
assert( pModule->xColumn );
9550395556
memset(&sContext, 0, sizeof(sContext));
9550495557
sContext.pOut = pDest;
95558
+ sContext.enc = encoding;
9550595559
assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
9550695560
if( pOp->p5 & OPFLAG_NOCHNG ){
9550795561
sqlite3VdbeMemSetNull(pDest);
9550895562
pDest->flags = MEM_Null|MEM_Zero;
9550995563
pDest->u.nZero = 0;
@@ -95518,13 +95572,10 @@
9551895572
}
9551995573
sqlite3VdbeChangeEncoding(pDest, encoding);
9552095574
REGISTER_TRACE(pOp->p3, pDest);
9552195575
UPDATE_MAX_BLOBSIZE(pDest);
9552295576
95523
- if( sqlite3VdbeMemTooBig(pDest) ){
95524
- goto too_big;
95525
- }
9552695577
if( rc ) goto abort_due_to_error;
9552795578
break;
9552895579
}
9552995580
#endif /* SQLITE_OMIT_VIRTUALTABLE */
9553095581
@@ -95787,10 +95838,11 @@
9578795838
** reinitializes the relavant parts of the sqlite3_context object */
9578895839
pOut = &aMem[pOp->p3];
9578995840
if( pCtx->pOut != pOut ){
9579095841
pCtx->pVdbe = p;
9579195842
pCtx->pOut = pOut;
95843
+ pCtx->enc = encoding;
9579295844
for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
9579395845
}
9579495846
assert( pCtx->pVdbe==p );
9579595847
9579695848
memAboutToChange(p, pOut);
@@ -95813,15 +95865,14 @@
9581395865
sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
9581495866
pCtx->isError = 0;
9581595867
if( rc ) goto abort_due_to_error;
9581695868
}
9581795869
95818
- /* Copy the result of the function into register P3 */
95819
- if( pOut->flags & (MEM_Str|MEM_Blob) ){
95820
- sqlite3VdbeChangeEncoding(pOut, encoding);
95821
- if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
95822
- }
95870
+ assert( (pOut->flags&MEM_Str)==0
95871
+ || pOut->enc==encoding
95872
+ || db->mallocFailed );
95873
+ assert( !sqlite3VdbeMemTooBig(pOut) );
9582395874
9582495875
REGISTER_TRACE(pOp->p3, pOut);
9582595876
UPDATE_MAX_BLOBSIZE(pOut);
9582695877
break;
9582795878
}
@@ -114347,11 +114398,13 @@
114347114398
&& (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
114348114399
){
114349114400
int iDb, i;
114350114401
assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
114351114402
sqlite3VdbeJumpHere(v, 0);
114352
- for(iDb=0; iDb<db->nDb; iDb++){
114403
+ assert( db->nDb>0 );
114404
+ iDb = 0;
114405
+ do{
114353114406
Schema *pSchema;
114354114407
if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
114355114408
sqlite3VdbeUsesBtree(v, iDb);
114356114409
pSchema = db->aDb[iDb].pSchema;
114357114410
sqlite3VdbeAddOp4Int(v,
@@ -114362,11 +114415,11 @@
114362114415
pSchema->iGeneration /* P4 */
114363114416
);
114364114417
if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
114365114418
VdbeComment((v,
114366114419
"usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
114367
- }
114420
+ }while( ++iDb<db->nDb );
114368114421
#ifndef SQLITE_OMIT_VIRTUALTABLE
114369114422
for(i=0; i<pParse->nVtabLock; i++){
114370114423
char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
114371114424
sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
114372114425
}
@@ -131503,11 +131556,11 @@
131503131556
**
131504131557
** Do N steps of incremental vacuuming on a database.
131505131558
*/
131506131559
#ifndef SQLITE_OMIT_AUTOVACUUM
131507131560
case PragTyp_INCREMENTAL_VACUUM: {
131508
- int iLimit, addr;
131561
+ int iLimit = 0, addr;
131509131562
if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
131510131563
iLimit = 0x7fffffff;
131511131564
}
131512131565
sqlite3BeginWriteOperation(pParse, 0, iDb);
131513131566
sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
@@ -133807,11 +133860,11 @@
133807133860
if( db->mallocFailed ){
133808133861
rc = SQLITE_NOMEM_BKPT;
133809133862
sqlite3ResetAllSchemasOfConnection(db);
133810133863
pDb = &db->aDb[iDb];
133811133864
}else
133812
- if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
133865
+ if( rc==SQLITE_OK || ((db->flags&SQLITE_NoSchemaError) && rc!=SQLITE_NOMEM)){
133813133866
/* Hack: If the SQLITE_NoSchemaError flag is set, then consider
133814133867
** the schema loaded, even if errors (other than OOM) occurred. In
133815133868
** this situation the current sqlite3_prepare() operation will fail,
133816133869
** but the following one will attempt to compile the supplied statement
133817133870
** against whatever subset of the schema was loaded before the error
@@ -154862,12 +154915,21 @@
154862154915
if( j<0 ){
154863154916
if( pLoop->maskSelf==pTerm->prereqAll ){
154864154917
/* If there are extra terms in the WHERE clause not used by an index
154865154918
** that depend only on the table being scanned, and that will tend to
154866154919
** cause many rows to be omitted, then mark that table as
154867
- ** "self-culling". */
154868
- pLoop->wsFlags |= WHERE_SELFCULL;
154920
+ ** "self-culling".
154921
+ **
154922
+ ** 2022-03-24: Self-culling only applies if either the extra terms
154923
+ ** are straight comparison operators that are non-true with NULL
154924
+ ** operand, or if the loop is not a LEFT JOIN.
154925
+ */
154926
+ if( (pTerm->eOperator & 0x3f)!=0
154927
+ || (pWC->pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0
154928
+ ){
154929
+ pLoop->wsFlags |= WHERE_SELFCULL;
154930
+ }
154869154931
}
154870154932
if( pTerm->truthProb<=0 ){
154871154933
/* If a truth probability is specified using the likelihood() hints,
154872154934
** then use the probability provided by the application. */
154873154935
pLoop->nOut += pTerm->truthProb;
@@ -168198,11 +168260,11 @@
168198168260
sqlite3DeleteTable(db, pParse->pNewTable);
168199168261
}
168200168262
if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){
168201168263
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
168202168264
}
168203
- sqlite3DbFree(db, pParse->pVList);
168265
+ if( pParse->pVList ) sqlite3DbFreeNN(db, pParse->pVList);
168204168266
db->pParse = pParentParse;
168205168267
assert( nErr==0 || pParse->rc!=SQLITE_OK );
168206168268
return nErr;
168207168269
}
168208168270
@@ -234692,11 +234754,11 @@
234692234754
int nArg, /* Number of args */
234693234755
sqlite3_value **apUnused /* Function arguments */
234694234756
){
234695234757
assert( nArg==0 );
234696234758
UNUSED_PARAM2(nArg, apUnused);
234697
- sqlite3_result_text(pCtx, "fts5: 2022-03-14 20:31:57 387ab17b8a0a4b87903aab52abc7da79098b882aff2ab687a554d5794e9d183e", -1, SQLITE_TRANSIENT);
234759
+ sqlite3_result_text(pCtx, "fts5: 2022-03-31 11:12:56 f2d9262e4427ab37ba26c004fc7a4790c86c1856d695a6b4ec3e72732ea54c09", -1, SQLITE_TRANSIENT);
234698234760
}
234699234761
234700234762
/*
234701234763
** Return true if zName is the extension on one of the shadow tables used
234702234764
** by this module.
234703234765
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -22410,10 +22410,11 @@
22410 FuncDef *pFunc; /* Pointer to function information */
22411 Mem *pMem; /* Memory cell used to store aggregate context */
22412 Vdbe *pVdbe; /* The VM that owns this context */
22413 int iOp; /* Instruction number of OP_Function */
22414 int isError; /* Error code returned by the function. */
 
22415 u8 skipFlag; /* Skip accumulator loading if true */
22416 u8 argc; /* Number of arguments */
22417 sqlite3_value *argv[1]; /* Argument set */
22418 };
22419
@@ -22458,11 +22459,10 @@
22458 struct Vdbe {
22459 sqlite3 *db; /* The database connection that owns this statement */
22460 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
22461 Parse *pParse; /* Parsing context used to create this Vdbe */
22462 ynVar nVar; /* Number of entries in aVar[] */
22463 u32 iVdbeMagic; /* Magic number defining state of the SQL statement */
22464 int nMem; /* Number of memory locations currently allocated */
22465 int nCursor; /* Number of slots in apCsr[] */
22466 u32 cacheCtr; /* VdbeCursor row cache generation counter */
22467 int pc; /* The program counter */
22468 int rc; /* Value to return */
@@ -22497,10 +22497,11 @@
22497 u16 nResColumn; /* Number of columns in one row of the result set */
22498 u8 errorAction; /* Recovery action to do in case of an error */
22499 u8 minWriteFileFormat; /* Minimum file format for writable database files */
22500 u8 prepFlags; /* SQLITE_PREPARE_* flags */
22501 u8 doingRerun; /* True if rerunning after an auto-reprepare */
 
22502 bft expired:2; /* 1: recompile VM immediately 2: when convenient */
22503 bft explain:2; /* True if EXPLAIN present on SQL command */
22504 bft changeCntOn:1; /* True to update the change-counter */
22505 bft runOnlyOnce:1; /* Automatically expire on reset */
22506 bft usesStmtJournal:1; /* True if uses a statement journal */
@@ -22527,17 +22528,16 @@
22527 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
22528 #endif
22529 };
22530
22531 /*
22532 ** The following are allowed values for Vdbe.magic
22533 */
22534 #define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */
22535 #define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */
22536 #define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */
22537 #define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */
22538 #define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */
22539
22540 /*
22541 ** Structure used to store the context required by the
22542 ** sqlite3_preupdate_*() API functions.
22543 */
@@ -27002,12 +27002,17 @@
27002 ** 32-bit signed integer. Hence the largest allocation is 0x40000000
27003 ** or 1073741824 bytes.
27004 */
27005 static int memsys5Roundup(int n){
27006 int iFullSz;
27007 if( n > 0x40000000 ) return 0;
27008 for(iFullSz=mem5.szAtom; iFullSz<n; iFullSz *= 2);
 
 
 
 
 
27009 return iFullSz;
27010 }
27011
27012 /*
27013 ** Return the ceiling of the logarithm base 2 of iValue.
@@ -74949,11 +74954,10 @@
74949 ** balance_deeper()
74950 ** balance_nonroot()
74951 */
74952 static int balance(BtCursor *pCur){
74953 int rc = SQLITE_OK;
74954 const int nMin = pCur->pBt->usableSize * 2 / 3;
74955 u8 aBalanceQuickSpace[13];
74956 u8 *pFree = 0;
74957
74958 VVA_ONLY( int balance_quick_called = 0 );
74959 VVA_ONLY( int balance_deeper_called = 0 );
@@ -74961,11 +74965,15 @@
74961 do {
74962 int iPage;
74963 MemPage *pPage = pCur->pPage;
74964
74965 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
74966 if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
 
 
 
 
74967 break;
74968 }else if( (iPage = pCur->iPage)==0 ){
74969 if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
74970 /* The root page of the b-tree is overfull. In this case call the
74971 ** balance_deeper() function to create a new child for the root-page
@@ -75775,11 +75783,19 @@
75775 ** on the leaf node first. If the balance proceeds far enough up the
75776 ** tree that we can be sure that any problem in the internal node has
75777 ** been corrected, so be it. Otherwise, after balancing the leaf node,
75778 ** walk the cursor up the tree to the internal node and balance it as
75779 ** well. */
75780 rc = balance(pCur);
 
 
 
 
 
 
 
 
75781 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
75782 releasePageNotNull(pCur->pPage);
75783 pCur->iPage--;
75784 while( pCur->iPage>iCellDepth ){
75785 releasePage(pCur->apPage[pCur->iPage--]);
@@ -78270,11 +78286,15 @@
78270 #endif
78271 assert( pMem!=0 );
78272 assert( !sqlite3VdbeMemIsRowSet(pMem) );
78273 assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
78274 || desiredEnc==SQLITE_UTF16BE );
78275 if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
 
 
 
 
78276 return SQLITE_OK;
78277 }
78278 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
78279 #ifdef SQLITE_OMIT_UTF16
78280 return SQLITE_ERROR;
@@ -78529,10 +78549,11 @@
78529 t.flags = MEM_Null;
78530 t.db = pMem->db;
78531 ctx.pOut = &t;
78532 ctx.pMem = pMem;
78533 ctx.pFunc = pFunc;
 
78534 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
78535 assert( (pMem->flags & MEM_Dyn)==0 );
78536 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
78537 memcpy(pMem, &t, sizeof(t));
78538 return ctx.isError;
@@ -78556,10 +78577,11 @@
78556 memset(&ctx, 0, sizeof(ctx));
78557 sqlite3VdbeMemSetNull(pOut);
78558 ctx.pOut = pOut;
78559 ctx.pMem = pAccum;
78560 ctx.pFunc = pFunc;
 
78561 pFunc->xValue(&ctx);
78562 return ctx.isError;
78563 }
78564 #endif /* SQLITE_OMIT_WINDOWFUNC */
78565
@@ -79173,10 +79195,17 @@
79173 ** If the string is too large (if it exceeds the SQLITE_LIMIT_LENGTH
79174 ** size limit) then no memory allocation occurs. If the string can be
79175 ** stored without allocating memory, then it is. If a memory allocation
79176 ** is required to store the string, then value of pMem is unchanged. In
79177 ** either case, SQLITE_TOOBIG is returned.
 
 
 
 
 
 
 
79178 */
79179 SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
79180 Mem *pMem, /* Memory cell to set to string value */
79181 const char *z, /* String pointer */
79182 i64 n, /* Bytes in string, or negative */
@@ -79183,15 +79212,16 @@
79183 u8 enc, /* Encoding of z. 0 for BLOBs */
79184 void (*xDel)(void*) /* Destructor function */
79185 ){
79186 i64 nByte = n; /* New value for pMem->n */
79187 int iLimit; /* Maximum allowed string or blob size */
79188 u16 flags = 0; /* New value for pMem->flags */
79189
79190 assert( pMem!=0 );
79191 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
79192 assert( !sqlite3VdbeMemIsRowSet(pMem) );
 
79193
79194 /* If z is a NULL pointer, set pMem to contain an SQL NULL. */
79195 if( !z ){
79196 sqlite3VdbeMemSetNull(pMem);
79197 return SQLITE_OK;
@@ -79200,19 +79230,34 @@
79200 if( pMem->db ){
79201 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
79202 }else{
79203 iLimit = SQLITE_MAX_LENGTH;
79204 }
79205 flags = (enc==0?MEM_Blob:MEM_Str);
79206 if( nByte<0 ){
79207 assert( enc!=0 );
79208 if( enc==SQLITE_UTF8 ){
79209 nByte = strlen(z);
79210 }else{
79211 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
79212 }
79213 flags |= MEM_Term;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79214 }
79215
79216 /* The following block sets the new values of Mem.z and Mem.xDel. It
79217 ** also sets a flag in local variable "flags" to indicate the memory
79218 ** management (one of MEM_Dyn or MEM_Static).
@@ -79220,13 +79265,10 @@
79220 if( xDel==SQLITE_TRANSIENT ){
79221 i64 nAlloc = nByte;
79222 if( flags&MEM_Term ){
79223 nAlloc += (enc==SQLITE_UTF8?1:2);
79224 }
79225 if( nByte>iLimit ){
79226 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
79227 }
79228 testcase( nAlloc==0 );
79229 testcase( nAlloc==31 );
79230 testcase( nAlloc==32 );
79231 if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
79232 return SQLITE_NOMEM_BKPT;
@@ -79244,30 +79286,18 @@
79244 }
79245 }
79246
79247 pMem->n = (int)(nByte & 0x7fffffff);
79248 pMem->flags = flags;
79249 if( enc ){
79250 pMem->enc = enc;
79251 #ifdef SQLITE_ENABLE_SESSION
79252 }else if( pMem->db==0 ){
79253 pMem->enc = SQLITE_UTF8;
79254 #endif
79255 }else{
79256 assert( pMem->db!=0 );
79257 pMem->enc = ENC(pMem->db);
79258 }
79259
79260 #ifndef SQLITE_OMIT_UTF16
79261 if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
79262 return SQLITE_NOMEM_BKPT;
79263 }
79264 #endif
79265
79266 if( nByte>iLimit ){
79267 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
79268 }
79269
79270 return SQLITE_OK;
79271 }
79272
79273 /*
@@ -79545,10 +79575,11 @@
79545
79546 assert( pCtx->pParse->rc==SQLITE_OK );
79547 memset(&ctx, 0, sizeof(ctx));
79548 ctx.pOut = pVal;
79549 ctx.pFunc = pFunc;
 
79550 pFunc->xSFunc(&ctx, nVal, apVal);
79551 if( ctx.isError ){
79552 rc = ctx.isError;
79553 sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
79554 }else{
@@ -80055,11 +80086,11 @@
80055 db->pVdbe->pPrev = p;
80056 }
80057 p->pNext = db->pVdbe;
80058 p->pPrev = 0;
80059 db->pVdbe = p;
80060 p->iVdbeMagic = VDBE_MAGIC_INIT;
80061 p->pParse = pParse;
80062 pParse->pVdbe = p;
80063 assert( pParse->aLabel==0 );
80064 assert( pParse->nLabel==0 );
80065 assert( p->nOpAlloc==0 );
@@ -80256,11 +80287,11 @@
80256 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
80257 int i;
80258 VdbeOp *pOp;
80259
80260 i = p->nOp;
80261 assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
80262 assert( op>=0 && op<0xff );
80263 if( p->nOpAlloc<=i ){
80264 return growOp3(p, op, p1, p2, p3);
80265 }
80266 assert( p->aOp!=0 );
@@ -80588,11 +80619,11 @@
80588 }
80589 }
80590 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
80591 Parse *p = v->pParse;
80592 int j = ADDR(x);
80593 assert( v->iVdbeMagic==VDBE_MAGIC_INIT );
80594 assert( j<-p->nLabel );
80595 assert( j>=0 );
80596 #ifdef SQLITE_DEBUG
80597 if( p->db->flags & SQLITE_VdbeAddopTrace ){
80598 printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
@@ -80719,10 +80750,12 @@
80719 int hasCreateTable = 0;
80720 int hasCreateIndex = 0;
80721 int hasInitCoroutine = 0;
80722 Op *pOp;
80723 VdbeOpIter sIter;
 
 
80724 memset(&sIter, 0, sizeof(sIter));
80725 sIter.v = v;
80726
80727 while( (pOp = opIterNext(&sIter))!=0 ){
80728 int opcode = pOp->opcode;
@@ -80883,22 +80916,24 @@
80883 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
80884 }
80885 if( pOp==p->aOp ) break;
80886 pOp--;
80887 }
80888 sqlite3DbFree(p->db, pParse->aLabel);
80889 pParse->aLabel = 0;
 
 
80890 pParse->nLabel = 0;
80891 *pMaxFuncArgs = nMaxArgs;
80892 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
80893 }
80894
80895 /*
80896 ** Return the address of the next instruction to be inserted.
80897 */
80898 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
80899 assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
80900 return p->nOp;
80901 }
80902
80903 /*
80904 ** Verify that at least N opcode slots are available in p without
@@ -80979,11 +81014,11 @@
80979 int iLineno /* Source-file line number of first opcode */
80980 ){
80981 int i;
80982 VdbeOp *pOut, *pFirst;
80983 assert( nOp>0 );
80984 assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
80985 if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
80986 return 0;
80987 }
80988 pFirst = pOut = &p->aOp[p->nOp];
80989 for(i=0; i<nOp; i++, aOp++, pOut++){
@@ -81170,17 +81205,20 @@
81170 ** Free the space allocated for aOp and any p4 values allocated for the
81171 ** opcodes contained within. If aOp is not NULL it is assumed to contain
81172 ** nOp entries.
81173 */
81174 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
 
81175 if( aOp ){
81176 Op *pOp;
81177 for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
81178 if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p);
81179 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
81180 sqlite3DbFree(db, pOp->zComment);
81181 #endif
 
 
81182 }
81183 sqlite3DbFreeNN(db, aOp);
81184 }
81185 }
81186
@@ -81302,11 +81340,11 @@
81302 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
81303 Op *pOp;
81304 sqlite3 *db;
81305 assert( p!=0 );
81306 db = p->db;
81307 assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
81308 assert( p->aOp!=0 || db->mallocFailed );
81309 if( db->mallocFailed ){
81310 if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4);
81311 return;
81312 }
@@ -81430,11 +81468,11 @@
81430 */
81431 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
81432 /* C89 specifies that the constant "dummy" will be initialized to all
81433 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
81434 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
81435 assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
81436 if( addr<0 ){
81437 addr = p->nOp - 1;
81438 }
81439 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
81440 if( p->db->mallocFailed ){
@@ -82132,11 +82170,11 @@
82132 int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
82133 Op *aOp; /* Array of opcodes */
82134 Op *pOp; /* Current opcode */
82135
82136 assert( p->explain );
82137 assert( p->iVdbeMagic==VDBE_MAGIC_RUN );
82138 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
82139
82140 /* Even though this opcode does not use dynamic strings for
82141 ** the result, result columns may become dynamic if the user calls
82142 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
@@ -82312,18 +82350,19 @@
82312 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
82313 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
82314 int i;
82315 #endif
82316 assert( p!=0 );
82317 assert( p->iVdbeMagic==VDBE_MAGIC_INIT || p->iVdbeMagic==VDBE_MAGIC_RESET );
 
 
82318
82319 /* There should be at least one opcode.
82320 */
82321 assert( p->nOp>0 );
82322
82323 /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
82324 p->iVdbeMagic = VDBE_MAGIC_RUN;
82325
82326 #ifdef SQLITE_DEBUG
82327 for(i=0; i<p->nMem; i++){
82328 assert( p->aMem[i].db==p->db );
82329 }
@@ -82375,11 +82414,11 @@
82375 struct ReusableSpace x; /* Reusable bulk memory */
82376
82377 assert( p!=0 );
82378 assert( p->nOp>0 );
82379 assert( pParse!=0 );
82380 assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
82381 assert( pParse==p->pParse );
82382 p->pVList = pParse->pVList;
82383 pParse->pVList = 0;
82384 db = p->db;
82385 assert( db->mallocFailed==0 );
@@ -82516,18 +82555,16 @@
82516
82517 /*
82518 ** Close all cursors in the current frame.
82519 */
82520 static void closeCursorsInFrame(Vdbe *p){
82521 if( p->apCsr ){
82522 int i;
82523 for(i=0; i<p->nCursor; i++){
82524 VdbeCursor *pC = p->apCsr[i];
82525 if( pC ){
82526 sqlite3VdbeFreeCursor(p, pC);
82527 p->apCsr[i] = 0;
82528 }
82529 }
82530 }
82531 }
82532
82533 /*
@@ -82572,13 +82609,11 @@
82572 p->pFrame = 0;
82573 p->nFrame = 0;
82574 }
82575 assert( p->nFrame==0 );
82576 closeCursorsInFrame(p);
82577 if( p->aMem ){
82578 releaseMemArray(p->aMem, p->nMem);
82579 }
82580 while( p->pDelFrame ){
82581 VdbeFrame *pDel = p->pDelFrame;
82582 p->pDelFrame = pDel->pParent;
82583 sqlite3VdbeFrameDelete(pDel);
82584 }
@@ -83014,10 +83049,11 @@
83014 || (!deferred && p->nFkConstraint>0)
83015 ){
83016 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
83017 p->errorAction = OE_Abort;
83018 sqlite3VdbeError(p, "FOREIGN KEY constraint failed");
 
83019 return SQLITE_CONSTRAINT_FOREIGNKEY;
83020 }
83021 return SQLITE_OK;
83022 }
83023 #endif
@@ -83053,11 +83089,11 @@
83053 ** Then the internal cache might have been left in an inconsistent
83054 ** state. We need to rollback the statement transaction, if there is
83055 ** one, or the complete transaction if there is no statement transaction.
83056 */
83057
83058 if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){
83059 return SQLITE_OK;
83060 }
83061 if( db->mallocFailed ){
83062 p->rc = SQLITE_NOMEM_BKPT;
83063 }
@@ -83064,11 +83100,11 @@
83064 closeAllCursors(p);
83065 checkActiveVdbeCnt(db);
83066
83067 /* No commit or rollback needed if the program never started or if the
83068 ** SQL statement does not read or write a database file. */
83069 if( p->pc>=0 && p->bIsReader ){
83070 int mrc; /* Primary error code from p->rc */
83071 int eStatementOp = 0;
83072 int isSpecialError; /* Set to true if a 'special' error */
83073
83074 /* Lock all btrees used by the statement */
@@ -83212,19 +83248,17 @@
83212 /* Release the locks */
83213 sqlite3VdbeLeave(p);
83214 }
83215
83216 /* We have successfully halted and closed the VM. Record this fact. */
83217 if( p->pc>=0 ){
83218 db->nVdbeActive--;
83219 if( !p->readOnly ) db->nVdbeWrite--;
83220 if( p->bIsReader ) db->nVdbeRead--;
83221 assert( db->nVdbeActive>=db->nVdbeRead );
83222 assert( db->nVdbeRead>=db->nVdbeWrite );
83223 assert( db->nVdbeWrite>=0 );
83224 }
83225 p->iVdbeMagic = VDBE_MAGIC_HALT;
83226 checkActiveVdbeCnt(db);
83227 if( db->mallocFailed ){
83228 p->rc = SQLITE_NOMEM_BKPT;
83229 }
83230
@@ -83302,12 +83336,12 @@
83302 **
83303 ** After this routine is run, the VDBE should be ready to be executed
83304 ** again.
83305 **
83306 ** To look at it another way, this routine resets the state of the
83307 ** virtual machine from VDBE_MAGIC_RUN or VDBE_MAGIC_HALT back to
83308 ** VDBE_MAGIC_INIT.
83309 */
83310 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
83311 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
83312 int i;
83313 #endif
@@ -83332,16 +83366,10 @@
83332 sqlite3VdbeTransferError(p);
83333 }else{
83334 db->errCode = p->rc;
83335 }
83336 if( p->runOnlyOnce ) p->expired = 1;
83337 }else if( p->rc && p->expired ){
83338 /* The expired flag was set on the VDBE before the first call
83339 ** to sqlite3_step(). For consistency (since sqlite3_step() was
83340 ** called), set the database error in this case as well.
83341 */
83342 sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
83343 }
83344
83345 /* Reset register contents and reclaim error message memory.
83346 */
83347 #ifdef SQLITE_DEBUG
@@ -83394,21 +83422,23 @@
83394 }
83395 fclose(out);
83396 }
83397 }
83398 #endif
83399 p->iVdbeMagic = VDBE_MAGIC_RESET;
83400 return p->rc & db->errMask;
83401 }
83402
83403 /*
83404 ** Clean up and delete a VDBE after execution. Return an integer which is
83405 ** the result code. Write any error message text into *pzErrMsg.
83406 */
83407 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){
83408 int rc = SQLITE_OK;
83409 if( p->iVdbeMagic==VDBE_MAGIC_RUN || p->iVdbeMagic==VDBE_MAGIC_HALT ){
 
 
 
83410 rc = sqlite3VdbeReset(p);
83411 assert( (rc & p->db->errMask)==rc );
83412 }
83413 sqlite3VdbeDelete(p);
83414 return rc;
@@ -83459,23 +83489,25 @@
83459 ** the database connection and frees the object itself.
83460 */
83461 SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
83462 SubProgram *pSub, *pNext;
83463 assert( p->db==0 || p->db==db );
83464 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
 
 
 
83465 for(pSub=p->pProgram; pSub; pSub=pNext){
83466 pNext = pSub->pNext;
83467 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
83468 sqlite3DbFree(db, pSub);
83469 }
83470 if( p->iVdbeMagic!=VDBE_MAGIC_INIT ){
83471 releaseMemArray(p->aVar, p->nVar);
83472 sqlite3DbFree(db, p->pVList);
83473 sqlite3DbFree(db, p->pFree);
83474 }
83475 vdbeFreeOpArray(db, p->aOp, p->nOp);
83476 sqlite3DbFree(db, p->aColName);
83477 sqlite3DbFree(db, p->zSql);
83478 #ifdef SQLITE_ENABLE_NORMALIZE
83479 sqlite3DbFree(db, p->zNormSql);
83480 {
83481 DblquoteStr *pThis, *pNext;
@@ -83513,12 +83545,10 @@
83513 db->pVdbe = p->pNext;
83514 }
83515 if( p->pNext ){
83516 p->pNext->pPrev = p->pPrev;
83517 }
83518 p->iVdbeMagic = VDBE_MAGIC_DEAD;
83519 p->db = 0;
83520 sqlite3DbFreeNN(db, p);
83521 }
83522
83523 /*
83524 ** The cursor "p" has a pending seek operation that has not yet been
@@ -85638,20 +85668,26 @@
85638 const char *z, /* String pointer */
85639 int n, /* Bytes in string, or negative */
85640 u8 enc, /* Encoding of z. 0 for BLOBs */
85641 void (*xDel)(void*) /* Destructor function */
85642 ){
85643 int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel);
 
85644 if( rc ){
85645 if( rc==SQLITE_TOOBIG ){
85646 sqlite3_result_error_toobig(pCtx);
85647 }else{
85648 /* The only errors possible from sqlite3VdbeMemSetStr are
85649 ** SQLITE_TOOBIG and SQLITE_NOMEM */
85650 assert( rc==SQLITE_NOMEM );
85651 sqlite3_result_error_nomem(pCtx);
85652 }
 
 
 
 
 
85653 }
85654 }
85655 static int invokeValueDestructor(
85656 const void *p, /* Value to destroy */
85657 void (*xDel)(void*), /* The destructor */
@@ -85791,21 +85827,26 @@
85791 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
85792 setResultStrOrError(pCtx, z, n, SQLITE_UTF16LE, xDel);
85793 }
85794 #endif /* SQLITE_OMIT_UTF16 */
85795 SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
 
85796 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
85797 sqlite3VdbeMemCopy(pCtx->pOut, pValue);
 
 
 
 
85798 }
85799 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
85800 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
85801 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
85802 }
85803 SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
85804 Mem *pOut = pCtx->pOut;
85805 assert( sqlite3_mutex_held(pOut->db->mutex) );
85806 if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
 
85807 return SQLITE_TOOBIG;
85808 }
85809 #ifndef SQLITE_OMIT_INCRBLOB
85810 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n);
85811 return SQLITE_OK;
@@ -85817,12 +85858,12 @@
85817 pCtx->isError = errCode ? errCode : -1;
85818 #ifdef SQLITE_DEBUG
85819 if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
85820 #endif
85821 if( pCtx->pOut->flags & MEM_Null ){
85822 sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,
85823 SQLITE_UTF8, SQLITE_STATIC);
85824 }
85825 }
85826
85827 /* Force an SQLITE_TOOBIG error. */
85828 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){
@@ -85891,85 +85932,94 @@
85891 */
85892 static int sqlite3Step(Vdbe *p){
85893 sqlite3 *db;
85894 int rc;
85895
85896 assert(p);
85897 if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){
85898 /* We used to require that sqlite3_reset() be called before retrying
85899 ** sqlite3_step() after any error or after SQLITE_DONE. But beginning
85900 ** with version 3.7.0, we changed this so that sqlite3_reset() would
85901 ** be called automatically instead of throwing the SQLITE_MISUSE error.
85902 ** This "automatic-reset" change is not technically an incompatibility,
85903 ** since any application that receives an SQLITE_MISUSE is broken by
85904 ** definition.
85905 **
85906 ** Nevertheless, some published applications that were originally written
85907 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
85908 ** returns, and those were broken by the automatic-reset change. As a
85909 ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
85910 ** legacy behavior of returning SQLITE_MISUSE for cases where the
85911 ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
85912 ** or SQLITE_BUSY error.
85913 */
85914 #ifdef SQLITE_OMIT_AUTORESET
85915 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
85916 sqlite3_reset((sqlite3_stmt*)p);
85917 }else{
85918 return SQLITE_MISUSE_BKPT;
85919 }
85920 #else
85921 sqlite3_reset((sqlite3_stmt*)p);
85922 #endif
85923 }
85924
85925 /* Check that malloc() has not failed. If it has, return early. */
85926 db = p->db;
85927 if( db->mallocFailed ){
85928 p->rc = SQLITE_NOMEM;
85929 return SQLITE_NOMEM_BKPT;
85930 }
85931
85932 if( p->pc<0 && p->expired ){
85933 p->rc = SQLITE_SCHEMA;
85934 rc = SQLITE_ERROR;
85935 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
85936 /* If this statement was prepared using saved SQL and an
85937 ** error has occurred, then return the error code in p->rc to the
85938 ** caller. Set the error code in the database handle to the same value.
85939 */
85940 rc = sqlite3VdbeTransferError(p);
85941 }
85942 goto end_of_step;
85943 }
85944 if( p->pc<0 ){
85945 /* If there are no other statements currently running, then
85946 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
85947 ** from interrupting a statement that has not yet started.
85948 */
85949 if( db->nVdbeActive==0 ){
85950 AtomicStore(&db->u1.isInterrupted, 0);
85951 }
85952
85953 assert( db->nVdbeWrite>0 || db->autoCommit==0
85954 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
85955 );
 
 
 
 
 
85956
85957 #ifndef SQLITE_OMIT_TRACE
85958 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
85959 && !db->init.busy && p->zSql ){
85960 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
85961 }else{
85962 assert( p->startTime==0 );
85963 }
85964 #endif
85965
85966 db->nVdbeActive++;
85967 if( p->readOnly==0 ) db->nVdbeWrite++;
85968 if( p->bIsReader ) db->nVdbeRead++;
85969 p->pc = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85970 }
 
85971 #ifdef SQLITE_DEBUG
85972 p->rcApp = SQLITE_OK;
85973 #endif
85974 #ifndef SQLITE_OMIT_EXPLAIN
85975 if( p->explain ){
@@ -85980,11 +86030,16 @@
85980 db->nVdbeExec++;
85981 rc = sqlite3VdbeExec(p);
85982 db->nVdbeExec--;
85983 }
85984
85985 if( rc!=SQLITE_ROW ){
 
 
 
 
 
85986 #ifndef SQLITE_OMIT_TRACE
85987 /* If the statement completed successfully, invoke the profile callback */
85988 checkProfileCallback(db, p);
85989 #endif
85990
@@ -86672,11 +86727,11 @@
86672 Mem *pVar;
86673 if( vdbeSafetyNotNull(p) ){
86674 return SQLITE_MISUSE_BKPT;
86675 }
86676 sqlite3_mutex_enter(p->db->mutex);
86677 if( p->iVdbeMagic!=VDBE_MAGIC_RUN || p->pc>=0 ){
86678 sqlite3Error(p->db, SQLITE_MISUSE);
86679 sqlite3_mutex_leave(p->db->mutex);
86680 sqlite3_log(SQLITE_MISUSE,
86681 "bind on a busy prepared statement: [%s]", p->zSql);
86682 return SQLITE_MISUSE_BKPT;
@@ -87025,11 +87080,11 @@
87025 /*
87026 ** Return true if the prepared statement is in need of being reset.
87027 */
87028 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
87029 Vdbe *v = (Vdbe*)pStmt;
87030 return v!=0 && v->iVdbeMagic==VDBE_MAGIC_RUN && v->pc>=0;
87031 }
87032
87033 /*
87034 ** Return a pointer to the next prepared statement after pStmt associated
87035 ** with database connection pDb. If pStmt is NULL, return the first
@@ -88339,11 +88394,11 @@
88339 #ifdef VDBE_PROFILE
88340 u64 start; /* CPU clock count at start of opcode */
88341 #endif
88342 /*** INSERT STACK UNION HERE ***/
88343
88344 assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
88345 sqlite3VdbeEnter(p);
88346 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
88347 if( db->xProgress ){
88348 u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
88349 assert( 0 < db->nProgressOps );
@@ -94848,10 +94903,11 @@
94848 pCtx->pFunc = pOp->p4.pFunc;
94849 pCtx->iOp = (int)(pOp - aOp);
94850 pCtx->pVdbe = p;
94851 pCtx->skipFlag = 0;
94852 pCtx->isError = 0;
 
94853 pCtx->argc = n;
94854 pOp->p4type = P4_FUNCCTX;
94855 pOp->p4.pCtx = pCtx;
94856
94857 /* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
@@ -94977,13 +95033,10 @@
94977 sqlite3VdbeError(p, "%s", sqlite3_value_text(pMem));
94978 goto abort_due_to_error;
94979 }
94980 sqlite3VdbeChangeEncoding(pMem, encoding);
94981 UPDATE_MAX_BLOBSIZE(pMem);
94982 if( sqlite3VdbeMemTooBig(pMem) ){
94983 goto too_big;
94984 }
94985 break;
94986 }
94987
94988 #ifndef SQLITE_OMIT_WAL
94989 /* Opcode: Checkpoint P1 P2 P3 * *
@@ -95500,10 +95553,11 @@
95500 pVtab = pCur->uc.pVCur->pVtab;
95501 pModule = pVtab->pModule;
95502 assert( pModule->xColumn );
95503 memset(&sContext, 0, sizeof(sContext));
95504 sContext.pOut = pDest;
 
95505 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
95506 if( pOp->p5 & OPFLAG_NOCHNG ){
95507 sqlite3VdbeMemSetNull(pDest);
95508 pDest->flags = MEM_Null|MEM_Zero;
95509 pDest->u.nZero = 0;
@@ -95518,13 +95572,10 @@
95518 }
95519 sqlite3VdbeChangeEncoding(pDest, encoding);
95520 REGISTER_TRACE(pOp->p3, pDest);
95521 UPDATE_MAX_BLOBSIZE(pDest);
95522
95523 if( sqlite3VdbeMemTooBig(pDest) ){
95524 goto too_big;
95525 }
95526 if( rc ) goto abort_due_to_error;
95527 break;
95528 }
95529 #endif /* SQLITE_OMIT_VIRTUALTABLE */
95530
@@ -95787,10 +95838,11 @@
95787 ** reinitializes the relavant parts of the sqlite3_context object */
95788 pOut = &aMem[pOp->p3];
95789 if( pCtx->pOut != pOut ){
95790 pCtx->pVdbe = p;
95791 pCtx->pOut = pOut;
 
95792 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
95793 }
95794 assert( pCtx->pVdbe==p );
95795
95796 memAboutToChange(p, pOut);
@@ -95813,15 +95865,14 @@
95813 sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
95814 pCtx->isError = 0;
95815 if( rc ) goto abort_due_to_error;
95816 }
95817
95818 /* Copy the result of the function into register P3 */
95819 if( pOut->flags & (MEM_Str|MEM_Blob) ){
95820 sqlite3VdbeChangeEncoding(pOut, encoding);
95821 if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
95822 }
95823
95824 REGISTER_TRACE(pOp->p3, pOut);
95825 UPDATE_MAX_BLOBSIZE(pOut);
95826 break;
95827 }
@@ -114347,11 +114398,13 @@
114347 && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
114348 ){
114349 int iDb, i;
114350 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
114351 sqlite3VdbeJumpHere(v, 0);
114352 for(iDb=0; iDb<db->nDb; iDb++){
 
 
114353 Schema *pSchema;
114354 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
114355 sqlite3VdbeUsesBtree(v, iDb);
114356 pSchema = db->aDb[iDb].pSchema;
114357 sqlite3VdbeAddOp4Int(v,
@@ -114362,11 +114415,11 @@
114362 pSchema->iGeneration /* P4 */
114363 );
114364 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
114365 VdbeComment((v,
114366 "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
114367 }
114368 #ifndef SQLITE_OMIT_VIRTUALTABLE
114369 for(i=0; i<pParse->nVtabLock; i++){
114370 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
114371 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
114372 }
@@ -131503,11 +131556,11 @@
131503 **
131504 ** Do N steps of incremental vacuuming on a database.
131505 */
131506 #ifndef SQLITE_OMIT_AUTOVACUUM
131507 case PragTyp_INCREMENTAL_VACUUM: {
131508 int iLimit, addr;
131509 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
131510 iLimit = 0x7fffffff;
131511 }
131512 sqlite3BeginWriteOperation(pParse, 0, iDb);
131513 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
@@ -133807,11 +133860,11 @@
133807 if( db->mallocFailed ){
133808 rc = SQLITE_NOMEM_BKPT;
133809 sqlite3ResetAllSchemasOfConnection(db);
133810 pDb = &db->aDb[iDb];
133811 }else
133812 if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
133813 /* Hack: If the SQLITE_NoSchemaError flag is set, then consider
133814 ** the schema loaded, even if errors (other than OOM) occurred. In
133815 ** this situation the current sqlite3_prepare() operation will fail,
133816 ** but the following one will attempt to compile the supplied statement
133817 ** against whatever subset of the schema was loaded before the error
@@ -154862,12 +154915,21 @@
154862 if( j<0 ){
154863 if( pLoop->maskSelf==pTerm->prereqAll ){
154864 /* If there are extra terms in the WHERE clause not used by an index
154865 ** that depend only on the table being scanned, and that will tend to
154866 ** cause many rows to be omitted, then mark that table as
154867 ** "self-culling". */
154868 pLoop->wsFlags |= WHERE_SELFCULL;
 
 
 
 
 
 
 
 
 
154869 }
154870 if( pTerm->truthProb<=0 ){
154871 /* If a truth probability is specified using the likelihood() hints,
154872 ** then use the probability provided by the application. */
154873 pLoop->nOut += pTerm->truthProb;
@@ -168198,11 +168260,11 @@
168198 sqlite3DeleteTable(db, pParse->pNewTable);
168199 }
168200 if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){
168201 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
168202 }
168203 sqlite3DbFree(db, pParse->pVList);
168204 db->pParse = pParentParse;
168205 assert( nErr==0 || pParse->rc!=SQLITE_OK );
168206 return nErr;
168207 }
168208
@@ -234692,11 +234754,11 @@
234692 int nArg, /* Number of args */
234693 sqlite3_value **apUnused /* Function arguments */
234694 ){
234695 assert( nArg==0 );
234696 UNUSED_PARAM2(nArg, apUnused);
234697 sqlite3_result_text(pCtx, "fts5: 2022-03-14 20:31:57 387ab17b8a0a4b87903aab52abc7da79098b882aff2ab687a554d5794e9d183e", -1, SQLITE_TRANSIENT);
234698 }
234699
234700 /*
234701 ** Return true if zName is the extension on one of the shadow tables used
234702 ** by this module.
234703
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-04-01 17:23:17 a7d79560a0efd6221ba59ce84bcb4fa94024a901ac4a45e192ddecc6e1b5c78c"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -22410,10 +22410,11 @@
22410 FuncDef *pFunc; /* Pointer to function information */
22411 Mem *pMem; /* Memory cell used to store aggregate context */
22412 Vdbe *pVdbe; /* The VM that owns this context */
22413 int iOp; /* Instruction number of OP_Function */
22414 int isError; /* Error code returned by the function. */
22415 u8 enc; /* Encoding to use for results */
22416 u8 skipFlag; /* Skip accumulator loading if true */
22417 u8 argc; /* Number of arguments */
22418 sqlite3_value *argv[1]; /* Argument set */
22419 };
22420
@@ -22458,11 +22459,10 @@
22459 struct Vdbe {
22460 sqlite3 *db; /* The database connection that owns this statement */
22461 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
22462 Parse *pParse; /* Parsing context used to create this Vdbe */
22463 ynVar nVar; /* Number of entries in aVar[] */
 
22464 int nMem; /* Number of memory locations currently allocated */
22465 int nCursor; /* Number of slots in apCsr[] */
22466 u32 cacheCtr; /* VdbeCursor row cache generation counter */
22467 int pc; /* The program counter */
22468 int rc; /* Value to return */
@@ -22497,10 +22497,11 @@
22497 u16 nResColumn; /* Number of columns in one row of the result set */
22498 u8 errorAction; /* Recovery action to do in case of an error */
22499 u8 minWriteFileFormat; /* Minimum file format for writable database files */
22500 u8 prepFlags; /* SQLITE_PREPARE_* flags */
22501 u8 doingRerun; /* True if rerunning after an auto-reprepare */
22502 u8 eVdbeState; /* On of the VDBE_*_STATE values */
22503 bft expired:2; /* 1: recompile VM immediately 2: when convenient */
22504 bft explain:2; /* True if EXPLAIN present on SQL command */
22505 bft changeCntOn:1; /* True to update the change-counter */
22506 bft runOnlyOnce:1; /* Automatically expire on reset */
22507 bft usesStmtJournal:1; /* True if uses a statement journal */
@@ -22527,17 +22528,16 @@
22528 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
22529 #endif
22530 };
22531
22532 /*
22533 ** The following are allowed values for Vdbe.eVdbeState
22534 */
22535 #define VDBE_INIT_STATE 0 /* Prepared statement under construction */
22536 #define VDBE_READY_STATE 1 /* Ready to run but not yet started */
22537 #define VDBE_RUN_STATE 2 /* Run in progress */
22538 #define VDBE_HALT_STATE 3 /* Finished. Need reset() or finalize() */
 
22539
22540 /*
22541 ** Structure used to store the context required by the
22542 ** sqlite3_preupdate_*() API functions.
22543 */
@@ -27002,12 +27002,17 @@
27002 ** 32-bit signed integer. Hence the largest allocation is 0x40000000
27003 ** or 1073741824 bytes.
27004 */
27005 static int memsys5Roundup(int n){
27006 int iFullSz;
27007 if( n<=mem5.szAtom*2 ){
27008 if( n<=mem5.szAtom ) return mem5.szAtom;
27009 return mem5.szAtom*2;
27010 }
27011 if( n>0x40000000 ) return 0;
27012 for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27013 if( (iFullSz/2)>=n ) return iFullSz/2;
27014 return iFullSz;
27015 }
27016
27017 /*
27018 ** Return the ceiling of the logarithm base 2 of iValue.
@@ -74949,11 +74954,10 @@
74954 ** balance_deeper()
74955 ** balance_nonroot()
74956 */
74957 static int balance(BtCursor *pCur){
74958 int rc = SQLITE_OK;
 
74959 u8 aBalanceQuickSpace[13];
74960 u8 *pFree = 0;
74961
74962 VVA_ONLY( int balance_quick_called = 0 );
74963 VVA_ONLY( int balance_deeper_called = 0 );
@@ -74961,11 +74965,15 @@
74965 do {
74966 int iPage;
74967 MemPage *pPage = pCur->pPage;
74968
74969 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
74970 if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
74971 /* No rebalance required as long as:
74972 ** (1) There are no overflow cells
74973 ** (2) The amount of free space on the page is less than 2/3rds of
74974 ** the total usable space on the page. */
74975 break;
74976 }else if( (iPage = pCur->iPage)==0 ){
74977 if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
74978 /* The root page of the b-tree is overfull. In this case call the
74979 ** balance_deeper() function to create a new child for the root-page
@@ -75775,11 +75783,19 @@
75783 ** on the leaf node first. If the balance proceeds far enough up the
75784 ** tree that we can be sure that any problem in the internal node has
75785 ** been corrected, so be it. Otherwise, after balancing the leaf node,
75786 ** walk the cursor up the tree to the internal node and balance it as
75787 ** well. */
75788 assert( pCur->pPage->nOverflow==0 );
75789 assert( pCur->pPage->nFree>=0 );
75790 if( pCur->pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
75791 /* Optimization: If the free space is less than 2/3rds of the page,
75792 ** then balance() will always be a no-op. No need to invoke it. */
75793 rc = SQLITE_OK;
75794 }else{
75795 rc = balance(pCur);
75796 }
75797 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
75798 releasePageNotNull(pCur->pPage);
75799 pCur->iPage--;
75800 while( pCur->iPage>iCellDepth ){
75801 releasePage(pCur->apPage[pCur->iPage--]);
@@ -78270,11 +78286,15 @@
78286 #endif
78287 assert( pMem!=0 );
78288 assert( !sqlite3VdbeMemIsRowSet(pMem) );
78289 assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
78290 || desiredEnc==SQLITE_UTF16BE );
78291 if( !(pMem->flags&MEM_Str) ){
78292 pMem->enc = desiredEnc;
78293 return SQLITE_OK;
78294 }
78295 if( pMem->enc==desiredEnc ){
78296 return SQLITE_OK;
78297 }
78298 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
78299 #ifdef SQLITE_OMIT_UTF16
78300 return SQLITE_ERROR;
@@ -78529,10 +78549,11 @@
78549 t.flags = MEM_Null;
78550 t.db = pMem->db;
78551 ctx.pOut = &t;
78552 ctx.pMem = pMem;
78553 ctx.pFunc = pFunc;
78554 ctx.enc = ENC(t.db);
78555 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
78556 assert( (pMem->flags & MEM_Dyn)==0 );
78557 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
78558 memcpy(pMem, &t, sizeof(t));
78559 return ctx.isError;
@@ -78556,10 +78577,11 @@
78577 memset(&ctx, 0, sizeof(ctx));
78578 sqlite3VdbeMemSetNull(pOut);
78579 ctx.pOut = pOut;
78580 ctx.pMem = pAccum;
78581 ctx.pFunc = pFunc;
78582 ctx.enc = ENC(pAccum->db);
78583 pFunc->xValue(&ctx);
78584 return ctx.isError;
78585 }
78586 #endif /* SQLITE_OMIT_WINDOWFUNC */
78587
@@ -79173,10 +79195,17 @@
79195 ** If the string is too large (if it exceeds the SQLITE_LIMIT_LENGTH
79196 ** size limit) then no memory allocation occurs. If the string can be
79197 ** stored without allocating memory, then it is. If a memory allocation
79198 ** is required to store the string, then value of pMem is unchanged. In
79199 ** either case, SQLITE_TOOBIG is returned.
79200 **
79201 ** The "enc" parameter is the text encoding for the string, or zero
79202 ** to store a blob.
79203 **
79204 ** If n is negative, then the string consists of all bytes up to but
79205 ** excluding the first zero character. The n parameter must be
79206 ** non-negative for blobs.
79207 */
79208 SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
79209 Mem *pMem, /* Memory cell to set to string value */
79210 const char *z, /* String pointer */
79211 i64 n, /* Bytes in string, or negative */
@@ -79183,15 +79212,16 @@
79212 u8 enc, /* Encoding of z. 0 for BLOBs */
79213 void (*xDel)(void*) /* Destructor function */
79214 ){
79215 i64 nByte = n; /* New value for pMem->n */
79216 int iLimit; /* Maximum allowed string or blob size */
79217 u16 flags; /* New value for pMem->flags */
79218
79219 assert( pMem!=0 );
79220 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
79221 assert( !sqlite3VdbeMemIsRowSet(pMem) );
79222 assert( enc!=0 || n>=0 );
79223
79224 /* If z is a NULL pointer, set pMem to contain an SQL NULL. */
79225 if( !z ){
79226 sqlite3VdbeMemSetNull(pMem);
79227 return SQLITE_OK;
@@ -79200,19 +79230,34 @@
79230 if( pMem->db ){
79231 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
79232 }else{
79233 iLimit = SQLITE_MAX_LENGTH;
79234 }
 
79235 if( nByte<0 ){
79236 assert( enc!=0 );
79237 if( enc==SQLITE_UTF8 ){
79238 nByte = strlen(z);
79239 }else{
79240 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
79241 }
79242 flags= MEM_Str|MEM_Term;
79243 }else if( enc==0 ){
79244 flags = MEM_Blob;
79245 enc = SQLITE_UTF8;
79246 }else{
79247 flags = MEM_Str;
79248 }
79249 if( nByte>iLimit ){
79250 if( xDel && xDel!=SQLITE_TRANSIENT ){
79251 if( xDel==SQLITE_DYNAMIC ){
79252 sqlite3DbFree(pMem->db, (void*)z);
79253 }else{
79254 xDel((void*)z);
79255 }
79256 }
79257 sqlite3VdbeMemSetNull(pMem);
79258 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
79259 }
79260
79261 /* The following block sets the new values of Mem.z and Mem.xDel. It
79262 ** also sets a flag in local variable "flags" to indicate the memory
79263 ** management (one of MEM_Dyn or MEM_Static).
@@ -79220,13 +79265,10 @@
79265 if( xDel==SQLITE_TRANSIENT ){
79266 i64 nAlloc = nByte;
79267 if( flags&MEM_Term ){
79268 nAlloc += (enc==SQLITE_UTF8?1:2);
79269 }
 
 
 
79270 testcase( nAlloc==0 );
79271 testcase( nAlloc==31 );
79272 testcase( nAlloc==32 );
79273 if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
79274 return SQLITE_NOMEM_BKPT;
@@ -79244,30 +79286,18 @@
79286 }
79287 }
79288
79289 pMem->n = (int)(nByte & 0x7fffffff);
79290 pMem->flags = flags;
79291 pMem->enc = enc;
 
 
 
 
 
 
 
 
 
79292
79293 #ifndef SQLITE_OMIT_UTF16
79294 if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
79295 return SQLITE_NOMEM_BKPT;
79296 }
79297 #endif
79298
 
 
 
79299
79300 return SQLITE_OK;
79301 }
79302
79303 /*
@@ -79545,10 +79575,11 @@
79575
79576 assert( pCtx->pParse->rc==SQLITE_OK );
79577 memset(&ctx, 0, sizeof(ctx));
79578 ctx.pOut = pVal;
79579 ctx.pFunc = pFunc;
79580 ctx.enc = ENC(db);
79581 pFunc->xSFunc(&ctx, nVal, apVal);
79582 if( ctx.isError ){
79583 rc = ctx.isError;
79584 sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
79585 }else{
@@ -80055,11 +80086,11 @@
80086 db->pVdbe->pPrev = p;
80087 }
80088 p->pNext = db->pVdbe;
80089 p->pPrev = 0;
80090 db->pVdbe = p;
80091 assert( p->eVdbeState==VDBE_INIT_STATE );
80092 p->pParse = pParse;
80093 pParse->pVdbe = p;
80094 assert( pParse->aLabel==0 );
80095 assert( pParse->nLabel==0 );
80096 assert( p->nOpAlloc==0 );
@@ -80256,11 +80287,11 @@
80287 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
80288 int i;
80289 VdbeOp *pOp;
80290
80291 i = p->nOp;
80292 assert( p->eVdbeState==VDBE_INIT_STATE );
80293 assert( op>=0 && op<0xff );
80294 if( p->nOpAlloc<=i ){
80295 return growOp3(p, op, p1, p2, p3);
80296 }
80297 assert( p->aOp!=0 );
@@ -80588,11 +80619,11 @@
80619 }
80620 }
80621 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
80622 Parse *p = v->pParse;
80623 int j = ADDR(x);
80624 assert( v->eVdbeState==VDBE_INIT_STATE );
80625 assert( j<-p->nLabel );
80626 assert( j>=0 );
80627 #ifdef SQLITE_DEBUG
80628 if( p->db->flags & SQLITE_VdbeAddopTrace ){
80629 printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
@@ -80719,10 +80750,12 @@
80750 int hasCreateTable = 0;
80751 int hasCreateIndex = 0;
80752 int hasInitCoroutine = 0;
80753 Op *pOp;
80754 VdbeOpIter sIter;
80755
80756 if( v==0 ) return 0;
80757 memset(&sIter, 0, sizeof(sIter));
80758 sIter.v = v;
80759
80760 while( (pOp = opIterNext(&sIter))!=0 ){
80761 int opcode = pOp->opcode;
@@ -80883,22 +80916,24 @@
80916 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
80917 }
80918 if( pOp==p->aOp ) break;
80919 pOp--;
80920 }
80921 if( aLabel ){
80922 sqlite3DbFreeNN(p->db, pParse->aLabel);
80923 pParse->aLabel = 0;
80924 }
80925 pParse->nLabel = 0;
80926 *pMaxFuncArgs = nMaxArgs;
80927 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
80928 }
80929
80930 /*
80931 ** Return the address of the next instruction to be inserted.
80932 */
80933 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
80934 assert( p->eVdbeState==VDBE_INIT_STATE );
80935 return p->nOp;
80936 }
80937
80938 /*
80939 ** Verify that at least N opcode slots are available in p without
@@ -80979,11 +81014,11 @@
81014 int iLineno /* Source-file line number of first opcode */
81015 ){
81016 int i;
81017 VdbeOp *pOut, *pFirst;
81018 assert( nOp>0 );
81019 assert( p->eVdbeState==VDBE_INIT_STATE );
81020 if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
81021 return 0;
81022 }
81023 pFirst = pOut = &p->aOp[p->nOp];
81024 for(i=0; i<nOp; i++, aOp++, pOut++){
@@ -81170,17 +81205,20 @@
81205 ** Free the space allocated for aOp and any p4 values allocated for the
81206 ** opcodes contained within. If aOp is not NULL it is assumed to contain
81207 ** nOp entries.
81208 */
81209 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
81210 assert( nOp>=0 );
81211 if( aOp ){
81212 Op *pOp = &aOp[nOp-1];
81213 while(1){ /* Exit via break */
81214 if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p);
81215 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
81216 sqlite3DbFree(db, pOp->zComment);
81217 #endif
81218 if( pOp==aOp ) break;
81219 pOp--;
81220 }
81221 sqlite3DbFreeNN(db, aOp);
81222 }
81223 }
81224
@@ -81302,11 +81340,11 @@
81340 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
81341 Op *pOp;
81342 sqlite3 *db;
81343 assert( p!=0 );
81344 db = p->db;
81345 assert( p->eVdbeState==VDBE_INIT_STATE );
81346 assert( p->aOp!=0 || db->mallocFailed );
81347 if( db->mallocFailed ){
81348 if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4);
81349 return;
81350 }
@@ -81430,11 +81468,11 @@
81468 */
81469 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
81470 /* C89 specifies that the constant "dummy" will be initialized to all
81471 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
81472 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
81473 assert( p->eVdbeState==VDBE_INIT_STATE );
81474 if( addr<0 ){
81475 addr = p->nOp - 1;
81476 }
81477 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
81478 if( p->db->mallocFailed ){
@@ -82132,11 +82170,11 @@
82170 int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
82171 Op *aOp; /* Array of opcodes */
82172 Op *pOp; /* Current opcode */
82173
82174 assert( p->explain );
82175 assert( p->eVdbeState==VDBE_RUN_STATE );
82176 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
82177
82178 /* Even though this opcode does not use dynamic strings for
82179 ** the result, result columns may become dynamic if the user calls
82180 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
@@ -82312,18 +82350,19 @@
82350 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
82351 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
82352 int i;
82353 #endif
82354 assert( p!=0 );
82355 assert( p->eVdbeState==VDBE_INIT_STATE
82356 || p->eVdbeState==VDBE_READY_STATE
82357 || p->eVdbeState==VDBE_HALT_STATE );
82358
82359 /* There should be at least one opcode.
82360 */
82361 assert( p->nOp>0 );
82362
82363 p->eVdbeState = VDBE_READY_STATE;
 
82364
82365 #ifdef SQLITE_DEBUG
82366 for(i=0; i<p->nMem; i++){
82367 assert( p->aMem[i].db==p->db );
82368 }
@@ -82375,11 +82414,11 @@
82414 struct ReusableSpace x; /* Reusable bulk memory */
82415
82416 assert( p!=0 );
82417 assert( p->nOp>0 );
82418 assert( pParse!=0 );
82419 assert( p->eVdbeState==VDBE_INIT_STATE );
82420 assert( pParse==p->pParse );
82421 p->pVList = pParse->pVList;
82422 pParse->pVList = 0;
82423 db = p->db;
82424 assert( db->mallocFailed==0 );
@@ -82516,18 +82555,16 @@
82555
82556 /*
82557 ** Close all cursors in the current frame.
82558 */
82559 static void closeCursorsInFrame(Vdbe *p){
82560 int i;
82561 for(i=0; i<p->nCursor; i++){
82562 VdbeCursor *pC = p->apCsr[i];
82563 if( pC ){
82564 sqlite3VdbeFreeCursor(p, pC);
82565 p->apCsr[i] = 0;
 
 
82566 }
82567 }
82568 }
82569
82570 /*
@@ -82572,13 +82609,11 @@
82609 p->pFrame = 0;
82610 p->nFrame = 0;
82611 }
82612 assert( p->nFrame==0 );
82613 closeCursorsInFrame(p);
82614 releaseMemArray(p->aMem, p->nMem);
 
 
82615 while( p->pDelFrame ){
82616 VdbeFrame *pDel = p->pDelFrame;
82617 p->pDelFrame = pDel->pParent;
82618 sqlite3VdbeFrameDelete(pDel);
82619 }
@@ -83014,10 +83049,11 @@
83049 || (!deferred && p->nFkConstraint>0)
83050 ){
83051 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
83052 p->errorAction = OE_Abort;
83053 sqlite3VdbeError(p, "FOREIGN KEY constraint failed");
83054 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ) return SQLITE_ERROR;
83055 return SQLITE_CONSTRAINT_FOREIGNKEY;
83056 }
83057 return SQLITE_OK;
83058 }
83059 #endif
@@ -83053,11 +83089,11 @@
83089 ** Then the internal cache might have been left in an inconsistent
83090 ** state. We need to rollback the statement transaction, if there is
83091 ** one, or the complete transaction if there is no statement transaction.
83092 */
83093
83094 if( p->eVdbeState!=VDBE_RUN_STATE ){
83095 return SQLITE_OK;
83096 }
83097 if( db->mallocFailed ){
83098 p->rc = SQLITE_NOMEM_BKPT;
83099 }
@@ -83064,11 +83100,11 @@
83100 closeAllCursors(p);
83101 checkActiveVdbeCnt(db);
83102
83103 /* No commit or rollback needed if the program never started or if the
83104 ** SQL statement does not read or write a database file. */
83105 if( p->bIsReader ){
83106 int mrc; /* Primary error code from p->rc */
83107 int eStatementOp = 0;
83108 int isSpecialError; /* Set to true if a 'special' error */
83109
83110 /* Lock all btrees used by the statement */
@@ -83212,19 +83248,17 @@
83248 /* Release the locks */
83249 sqlite3VdbeLeave(p);
83250 }
83251
83252 /* We have successfully halted and closed the VM. Record this fact. */
83253 db->nVdbeActive--;
83254 if( !p->readOnly ) db->nVdbeWrite--;
83255 if( p->bIsReader ) db->nVdbeRead--;
83256 assert( db->nVdbeActive>=db->nVdbeRead );
83257 assert( db->nVdbeRead>=db->nVdbeWrite );
83258 assert( db->nVdbeWrite>=0 );
83259 p->eVdbeState = VDBE_HALT_STATE;
 
 
83260 checkActiveVdbeCnt(db);
83261 if( db->mallocFailed ){
83262 p->rc = SQLITE_NOMEM_BKPT;
83263 }
83264
@@ -83302,12 +83336,12 @@
83336 **
83337 ** After this routine is run, the VDBE should be ready to be executed
83338 ** again.
83339 **
83340 ** To look at it another way, this routine resets the state of the
83341 ** virtual machine from VDBE_RUN_STATE or VDBE_HALT_STATE back to
83342 ** VDBE_READY_STATE.
83343 */
83344 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
83345 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
83346 int i;
83347 #endif
@@ -83332,16 +83366,10 @@
83366 sqlite3VdbeTransferError(p);
83367 }else{
83368 db->errCode = p->rc;
83369 }
83370 if( p->runOnlyOnce ) p->expired = 1;
 
 
 
 
 
 
83371 }
83372
83373 /* Reset register contents and reclaim error message memory.
83374 */
83375 #ifdef SQLITE_DEBUG
@@ -83394,21 +83422,23 @@
83422 }
83423 fclose(out);
83424 }
83425 }
83426 #endif
 
83427 return p->rc & db->errMask;
83428 }
83429
83430 /*
83431 ** Clean up and delete a VDBE after execution. Return an integer which is
83432 ** the result code. Write any error message text into *pzErrMsg.
83433 */
83434 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){
83435 int rc = SQLITE_OK;
83436 assert( VDBE_RUN_STATE>VDBE_READY_STATE );
83437 assert( VDBE_HALT_STATE>VDBE_READY_STATE );
83438 assert( VDBE_INIT_STATE<VDBE_READY_STATE );
83439 if( p->eVdbeState>=VDBE_READY_STATE ){
83440 rc = sqlite3VdbeReset(p);
83441 assert( (rc & p->db->errMask)==rc );
83442 }
83443 sqlite3VdbeDelete(p);
83444 return rc;
@@ -83459,23 +83489,25 @@
83489 ** the database connection and frees the object itself.
83490 */
83491 SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
83492 SubProgram *pSub, *pNext;
83493 assert( p->db==0 || p->db==db );
83494 if( p->aColName ){
83495 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
83496 sqlite3DbFreeNN(db, p->aColName);
83497 }
83498 for(pSub=p->pProgram; pSub; pSub=pNext){
83499 pNext = pSub->pNext;
83500 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
83501 sqlite3DbFree(db, pSub);
83502 }
83503 if( p->eVdbeState!=VDBE_INIT_STATE ){
83504 releaseMemArray(p->aVar, p->nVar);
83505 if( p->pVList ) sqlite3DbFreeNN(db, p->pVList);
83506 if( p->pFree ) sqlite3DbFreeNN(db, p->pFree);
83507 }
83508 vdbeFreeOpArray(db, p->aOp, p->nOp);
 
83509 sqlite3DbFree(db, p->zSql);
83510 #ifdef SQLITE_ENABLE_NORMALIZE
83511 sqlite3DbFree(db, p->zNormSql);
83512 {
83513 DblquoteStr *pThis, *pNext;
@@ -83513,12 +83545,10 @@
83545 db->pVdbe = p->pNext;
83546 }
83547 if( p->pNext ){
83548 p->pNext->pPrev = p->pPrev;
83549 }
 
 
83550 sqlite3DbFreeNN(db, p);
83551 }
83552
83553 /*
83554 ** The cursor "p" has a pending seek operation that has not yet been
@@ -85638,20 +85668,26 @@
85668 const char *z, /* String pointer */
85669 int n, /* Bytes in string, or negative */
85670 u8 enc, /* Encoding of z. 0 for BLOBs */
85671 void (*xDel)(void*) /* Destructor function */
85672 ){
85673 Mem *pOut = pCtx->pOut;
85674 int rc = sqlite3VdbeMemSetStr(pOut, z, n, enc, xDel);
85675 if( rc ){
85676 if( rc==SQLITE_TOOBIG ){
85677 sqlite3_result_error_toobig(pCtx);
85678 }else{
85679 /* The only errors possible from sqlite3VdbeMemSetStr are
85680 ** SQLITE_TOOBIG and SQLITE_NOMEM */
85681 assert( rc==SQLITE_NOMEM );
85682 sqlite3_result_error_nomem(pCtx);
85683 }
85684 return;
85685 }
85686 sqlite3VdbeChangeEncoding(pOut, pCtx->enc);
85687 if( sqlite3VdbeMemTooBig(pOut) ){
85688 sqlite3_result_error_toobig(pCtx);
85689 }
85690 }
85691 static int invokeValueDestructor(
85692 const void *p, /* Value to destroy */
85693 void (*xDel)(void*), /* The destructor */
@@ -85791,21 +85827,26 @@
85827 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
85828 setResultStrOrError(pCtx, z, n, SQLITE_UTF16LE, xDel);
85829 }
85830 #endif /* SQLITE_OMIT_UTF16 */
85831 SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
85832 Mem *pOut = pCtx->pOut;
85833 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
85834 sqlite3VdbeMemCopy(pOut, pValue);
85835 sqlite3VdbeChangeEncoding(pOut, pCtx->enc);
85836 if( sqlite3VdbeMemTooBig(pOut) ){
85837 sqlite3_result_error_toobig(pCtx);
85838 }
85839 }
85840 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
85841 sqlite3_result_zeroblob64(pCtx, n>0 ? n : 0);
 
85842 }
85843 SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
85844 Mem *pOut = pCtx->pOut;
85845 assert( sqlite3_mutex_held(pOut->db->mutex) );
85846 if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
85847 sqlite3_result_error_toobig(pCtx);
85848 return SQLITE_TOOBIG;
85849 }
85850 #ifndef SQLITE_OMIT_INCRBLOB
85851 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n);
85852 return SQLITE_OK;
@@ -85817,12 +85858,12 @@
85858 pCtx->isError = errCode ? errCode : -1;
85859 #ifdef SQLITE_DEBUG
85860 if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
85861 #endif
85862 if( pCtx->pOut->flags & MEM_Null ){
85863 setResultStrOrError(pCtx, sqlite3ErrStr(errCode), -1, SQLITE_UTF8,
85864 SQLITE_STATIC);
85865 }
85866 }
85867
85868 /* Force an SQLITE_TOOBIG error. */
85869 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){
@@ -85891,85 +85932,94 @@
85932 */
85933 static int sqlite3Step(Vdbe *p){
85934 sqlite3 *db;
85935 int rc;
85936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85937 /* Check that malloc() has not failed. If it has, return early. */
85938 db = p->db;
85939 if( db->mallocFailed ){
85940 p->rc = SQLITE_NOMEM;
85941 return SQLITE_NOMEM_BKPT;
85942 }
85943
85944 assert(p);
85945 if( p->eVdbeState!=VDBE_RUN_STATE ){
85946 restart_step:
85947 if( p->eVdbeState==VDBE_READY_STATE ){
85948 if( p->expired ){
85949 p->rc = SQLITE_SCHEMA;
85950 rc = SQLITE_ERROR;
85951 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
85952 /* If this statement was prepared using saved SQL and an
85953 ** error has occurred, then return the error code in p->rc to the
85954 ** caller. Set the error code in the database handle to the same
85955 ** value.
85956 */
85957 rc = sqlite3VdbeTransferError(p);
85958 }
85959 goto end_of_step;
85960 }
85961
85962 /* If there are no other statements currently running, then
85963 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
85964 ** from interrupting a statement that has not yet started.
85965 */
85966 if( db->nVdbeActive==0 ){
85967 AtomicStore(&db->u1.isInterrupted, 0);
85968 }
85969
85970 assert( db->nVdbeWrite>0 || db->autoCommit==0
85971 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
85972 );
85973
85974 #ifndef SQLITE_OMIT_TRACE
85975 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
85976 && !db->init.busy && p->zSql ){
85977 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
85978 }else{
85979 assert( p->startTime==0 );
85980 }
85981 #endif
85982
85983 db->nVdbeActive++;
85984 if( p->readOnly==0 ) db->nVdbeWrite++;
85985 if( p->bIsReader ) db->nVdbeRead++;
85986 p->pc = 0;
85987 p->eVdbeState = VDBE_RUN_STATE;
85988 }else
85989
85990 if( ALWAYS(p->eVdbeState==VDBE_HALT_STATE) ){
85991 /* We used to require that sqlite3_reset() be called before retrying
85992 ** sqlite3_step() after any error or after SQLITE_DONE. But beginning
85993 ** with version 3.7.0, we changed this so that sqlite3_reset() would
85994 ** be called automatically instead of throwing the SQLITE_MISUSE error.
85995 ** This "automatic-reset" change is not technically an incompatibility,
85996 ** since any application that receives an SQLITE_MISUSE is broken by
85997 ** definition.
85998 **
85999 ** Nevertheless, some published applications that were originally written
86000 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
86001 ** returns, and those were broken by the automatic-reset change. As a
86002 ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
86003 ** legacy behavior of returning SQLITE_MISUSE for cases where the
86004 ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
86005 ** or SQLITE_BUSY error.
86006 */
86007 #ifdef SQLITE_OMIT_AUTORESET
86008 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
86009 sqlite3_reset((sqlite3_stmt*)p);
86010 }else{
86011 return SQLITE_MISUSE_BKPT;
86012 }
86013 #else
86014 sqlite3_reset((sqlite3_stmt*)p);
86015 #endif
86016 assert( p->eVdbeState==VDBE_READY_STATE );
86017 goto restart_step;
86018 }
86019 }
86020
86021 #ifdef SQLITE_DEBUG
86022 p->rcApp = SQLITE_OK;
86023 #endif
86024 #ifndef SQLITE_OMIT_EXPLAIN
86025 if( p->explain ){
@@ -85980,11 +86030,16 @@
86030 db->nVdbeExec++;
86031 rc = sqlite3VdbeExec(p);
86032 db->nVdbeExec--;
86033 }
86034
86035 if( rc==SQLITE_ROW ){
86036 assert( p->rc==SQLITE_OK );
86037 assert( db->mallocFailed==0 );
86038 db->errCode = SQLITE_ROW;
86039 return SQLITE_ROW;
86040 }else{
86041 #ifndef SQLITE_OMIT_TRACE
86042 /* If the statement completed successfully, invoke the profile callback */
86043 checkProfileCallback(db, p);
86044 #endif
86045
@@ -86672,11 +86727,11 @@
86727 Mem *pVar;
86728 if( vdbeSafetyNotNull(p) ){
86729 return SQLITE_MISUSE_BKPT;
86730 }
86731 sqlite3_mutex_enter(p->db->mutex);
86732 if( p->eVdbeState!=VDBE_READY_STATE ){
86733 sqlite3Error(p->db, SQLITE_MISUSE);
86734 sqlite3_mutex_leave(p->db->mutex);
86735 sqlite3_log(SQLITE_MISUSE,
86736 "bind on a busy prepared statement: [%s]", p->zSql);
86737 return SQLITE_MISUSE_BKPT;
@@ -87025,11 +87080,11 @@
87080 /*
87081 ** Return true if the prepared statement is in need of being reset.
87082 */
87083 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
87084 Vdbe *v = (Vdbe*)pStmt;
87085 return v!=0 && v->eVdbeState==VDBE_RUN_STATE;
87086 }
87087
87088 /*
87089 ** Return a pointer to the next prepared statement after pStmt associated
87090 ** with database connection pDb. If pStmt is NULL, return the first
@@ -88339,11 +88394,11 @@
88394 #ifdef VDBE_PROFILE
88395 u64 start; /* CPU clock count at start of opcode */
88396 #endif
88397 /*** INSERT STACK UNION HERE ***/
88398
88399 assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
88400 sqlite3VdbeEnter(p);
88401 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
88402 if( db->xProgress ){
88403 u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
88404 assert( 0 < db->nProgressOps );
@@ -94848,10 +94903,11 @@
94903 pCtx->pFunc = pOp->p4.pFunc;
94904 pCtx->iOp = (int)(pOp - aOp);
94905 pCtx->pVdbe = p;
94906 pCtx->skipFlag = 0;
94907 pCtx->isError = 0;
94908 pCtx->enc = encoding;
94909 pCtx->argc = n;
94910 pOp->p4type = P4_FUNCCTX;
94911 pOp->p4.pCtx = pCtx;
94912
94913 /* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
@@ -94977,13 +95033,10 @@
95033 sqlite3VdbeError(p, "%s", sqlite3_value_text(pMem));
95034 goto abort_due_to_error;
95035 }
95036 sqlite3VdbeChangeEncoding(pMem, encoding);
95037 UPDATE_MAX_BLOBSIZE(pMem);
 
 
 
95038 break;
95039 }
95040
95041 #ifndef SQLITE_OMIT_WAL
95042 /* Opcode: Checkpoint P1 P2 P3 * *
@@ -95500,10 +95553,11 @@
95553 pVtab = pCur->uc.pVCur->pVtab;
95554 pModule = pVtab->pModule;
95555 assert( pModule->xColumn );
95556 memset(&sContext, 0, sizeof(sContext));
95557 sContext.pOut = pDest;
95558 sContext.enc = encoding;
95559 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
95560 if( pOp->p5 & OPFLAG_NOCHNG ){
95561 sqlite3VdbeMemSetNull(pDest);
95562 pDest->flags = MEM_Null|MEM_Zero;
95563 pDest->u.nZero = 0;
@@ -95518,13 +95572,10 @@
95572 }
95573 sqlite3VdbeChangeEncoding(pDest, encoding);
95574 REGISTER_TRACE(pOp->p3, pDest);
95575 UPDATE_MAX_BLOBSIZE(pDest);
95576
 
 
 
95577 if( rc ) goto abort_due_to_error;
95578 break;
95579 }
95580 #endif /* SQLITE_OMIT_VIRTUALTABLE */
95581
@@ -95787,10 +95838,11 @@
95838 ** reinitializes the relavant parts of the sqlite3_context object */
95839 pOut = &aMem[pOp->p3];
95840 if( pCtx->pOut != pOut ){
95841 pCtx->pVdbe = p;
95842 pCtx->pOut = pOut;
95843 pCtx->enc = encoding;
95844 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
95845 }
95846 assert( pCtx->pVdbe==p );
95847
95848 memAboutToChange(p, pOut);
@@ -95813,15 +95865,14 @@
95865 sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
95866 pCtx->isError = 0;
95867 if( rc ) goto abort_due_to_error;
95868 }
95869
95870 assert( (pOut->flags&MEM_Str)==0
95871 || pOut->enc==encoding
95872 || db->mallocFailed );
95873 assert( !sqlite3VdbeMemTooBig(pOut) );
 
95874
95875 REGISTER_TRACE(pOp->p3, pOut);
95876 UPDATE_MAX_BLOBSIZE(pOut);
95877 break;
95878 }
@@ -114347,11 +114398,13 @@
114398 && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
114399 ){
114400 int iDb, i;
114401 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
114402 sqlite3VdbeJumpHere(v, 0);
114403 assert( db->nDb>0 );
114404 iDb = 0;
114405 do{
114406 Schema *pSchema;
114407 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
114408 sqlite3VdbeUsesBtree(v, iDb);
114409 pSchema = db->aDb[iDb].pSchema;
114410 sqlite3VdbeAddOp4Int(v,
@@ -114362,11 +114415,11 @@
114415 pSchema->iGeneration /* P4 */
114416 );
114417 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
114418 VdbeComment((v,
114419 "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
114420 }while( ++iDb<db->nDb );
114421 #ifndef SQLITE_OMIT_VIRTUALTABLE
114422 for(i=0; i<pParse->nVtabLock; i++){
114423 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
114424 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
114425 }
@@ -131503,11 +131556,11 @@
131556 **
131557 ** Do N steps of incremental vacuuming on a database.
131558 */
131559 #ifndef SQLITE_OMIT_AUTOVACUUM
131560 case PragTyp_INCREMENTAL_VACUUM: {
131561 int iLimit = 0, addr;
131562 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
131563 iLimit = 0x7fffffff;
131564 }
131565 sqlite3BeginWriteOperation(pParse, 0, iDb);
131566 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
@@ -133807,11 +133860,11 @@
133860 if( db->mallocFailed ){
133861 rc = SQLITE_NOMEM_BKPT;
133862 sqlite3ResetAllSchemasOfConnection(db);
133863 pDb = &db->aDb[iDb];
133864 }else
133865 if( rc==SQLITE_OK || ((db->flags&SQLITE_NoSchemaError) && rc!=SQLITE_NOMEM)){
133866 /* Hack: If the SQLITE_NoSchemaError flag is set, then consider
133867 ** the schema loaded, even if errors (other than OOM) occurred. In
133868 ** this situation the current sqlite3_prepare() operation will fail,
133869 ** but the following one will attempt to compile the supplied statement
133870 ** against whatever subset of the schema was loaded before the error
@@ -154862,12 +154915,21 @@
154915 if( j<0 ){
154916 if( pLoop->maskSelf==pTerm->prereqAll ){
154917 /* If there are extra terms in the WHERE clause not used by an index
154918 ** that depend only on the table being scanned, and that will tend to
154919 ** cause many rows to be omitted, then mark that table as
154920 ** "self-culling".
154921 **
154922 ** 2022-03-24: Self-culling only applies if either the extra terms
154923 ** are straight comparison operators that are non-true with NULL
154924 ** operand, or if the loop is not a LEFT JOIN.
154925 */
154926 if( (pTerm->eOperator & 0x3f)!=0
154927 || (pWC->pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0
154928 ){
154929 pLoop->wsFlags |= WHERE_SELFCULL;
154930 }
154931 }
154932 if( pTerm->truthProb<=0 ){
154933 /* If a truth probability is specified using the likelihood() hints,
154934 ** then use the probability provided by the application. */
154935 pLoop->nOut += pTerm->truthProb;
@@ -168198,11 +168260,11 @@
168260 sqlite3DeleteTable(db, pParse->pNewTable);
168261 }
168262 if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){
168263 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
168264 }
168265 if( pParse->pVList ) sqlite3DbFreeNN(db, pParse->pVList);
168266 db->pParse = pParentParse;
168267 assert( nErr==0 || pParse->rc!=SQLITE_OK );
168268 return nErr;
168269 }
168270
@@ -234692,11 +234754,11 @@
234754 int nArg, /* Number of args */
234755 sqlite3_value **apUnused /* Function arguments */
234756 ){
234757 assert( nArg==0 );
234758 UNUSED_PARAM2(nArg, apUnused);
234759 sqlite3_result_text(pCtx, "fts5: 2022-03-31 11:12:56 f2d9262e4427ab37ba26c004fc7a4790c86c1856d695a6b4ec3e72732ea54c09", -1, SQLITE_TRANSIENT);
234760 }
234761
234762 /*
234763 ** Return true if zName is the extension on one of the shadow tables used
234764 ** by this module.
234765
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.39.0"
150150
#define SQLITE_VERSION_NUMBER 3039000
151
-#define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc"
151
+#define SQLITE_SOURCE_ID "2022-04-01 17:23:17 a7d79560a0efd6221ba59ce84bcb4fa94024a901ac4a45e192ddecc6e1b5c78c"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-04-01 17:23:17 a7d79560a0efd6221ba59ce84bcb4fa94024a901ac4a45e192ddecc6e1b5c78c"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

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