| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.39.0" |
| 456 | 456 | #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" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -22410,10 +22410,11 @@ |
| 22410 | 22410 | FuncDef *pFunc; /* Pointer to function information */ |
| 22411 | 22411 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 22412 | 22412 | Vdbe *pVdbe; /* The VM that owns this context */ |
| 22413 | 22413 | int iOp; /* Instruction number of OP_Function */ |
| 22414 | 22414 | int isError; /* Error code returned by the function. */ |
| 22415 | + u8 enc; /* Encoding to use for results */ |
| 22415 | 22416 | u8 skipFlag; /* Skip accumulator loading if true */ |
| 22416 | 22417 | u8 argc; /* Number of arguments */ |
| 22417 | 22418 | sqlite3_value *argv[1]; /* Argument set */ |
| 22418 | 22419 | }; |
| 22419 | 22420 | |
| | @@ -22458,11 +22459,10 @@ |
| 22458 | 22459 | struct Vdbe { |
| 22459 | 22460 | sqlite3 *db; /* The database connection that owns this statement */ |
| 22460 | 22461 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 22461 | 22462 | Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 22462 | 22463 | ynVar nVar; /* Number of entries in aVar[] */ |
| 22463 | | - u32 iVdbeMagic; /* Magic number defining state of the SQL statement */ |
| 22464 | 22464 | int nMem; /* Number of memory locations currently allocated */ |
| 22465 | 22465 | int nCursor; /* Number of slots in apCsr[] */ |
| 22466 | 22466 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 22467 | 22467 | int pc; /* The program counter */ |
| 22468 | 22468 | int rc; /* Value to return */ |
| | @@ -22497,10 +22497,11 @@ |
| 22497 | 22497 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 22498 | 22498 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 22499 | 22499 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 22500 | 22500 | u8 prepFlags; /* SQLITE_PREPARE_* flags */ |
| 22501 | 22501 | u8 doingRerun; /* True if rerunning after an auto-reprepare */ |
| 22502 | + u8 eVdbeState; /* On of the VDBE_*_STATE values */ |
| 22502 | 22503 | bft expired:2; /* 1: recompile VM immediately 2: when convenient */ |
| 22503 | 22504 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 22504 | 22505 | bft changeCntOn:1; /* True to update the change-counter */ |
| 22505 | 22506 | bft runOnlyOnce:1; /* Automatically expire on reset */ |
| 22506 | 22507 | bft usesStmtJournal:1; /* True if uses a statement journal */ |
| | @@ -22527,17 +22528,16 @@ |
| 22527 | 22528 | ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */ |
| 22528 | 22529 | #endif |
| 22529 | 22530 | }; |
| 22530 | 22531 | |
| 22531 | 22532 | /* |
| 22532 | | -** The following are allowed values for Vdbe.magic |
| 22533 | +** The following are allowed values for Vdbe.eVdbeState |
| 22533 | 22534 | */ |
| 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() */ |
| 22539 | 22539 | |
| 22540 | 22540 | /* |
| 22541 | 22541 | ** Structure used to store the context required by the |
| 22542 | 22542 | ** sqlite3_preupdate_*() API functions. |
| 22543 | 22543 | */ |
| | @@ -27002,12 +27002,17 @@ |
| 27002 | 27002 | ** 32-bit signed integer. Hence the largest allocation is 0x40000000 |
| 27003 | 27003 | ** or 1073741824 bytes. |
| 27004 | 27004 | */ |
| 27005 | 27005 | static int memsys5Roundup(int n){ |
| 27006 | 27006 | 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; |
| 27009 | 27014 | return iFullSz; |
| 27010 | 27015 | } |
| 27011 | 27016 | |
| 27012 | 27017 | /* |
| 27013 | 27018 | ** Return the ceiling of the logarithm base 2 of iValue. |
| | @@ -74949,11 +74954,10 @@ |
| 74949 | 74954 | ** balance_deeper() |
| 74950 | 74955 | ** balance_nonroot() |
| 74951 | 74956 | */ |
| 74952 | 74957 | static int balance(BtCursor *pCur){ |
| 74953 | 74958 | int rc = SQLITE_OK; |
| 74954 | | - const int nMin = pCur->pBt->usableSize * 2 / 3; |
| 74955 | 74959 | u8 aBalanceQuickSpace[13]; |
| 74956 | 74960 | u8 *pFree = 0; |
| 74957 | 74961 | |
| 74958 | 74962 | VVA_ONLY( int balance_quick_called = 0 ); |
| 74959 | 74963 | VVA_ONLY( int balance_deeper_called = 0 ); |
| | @@ -74961,11 +74965,15 @@ |
| 74961 | 74965 | do { |
| 74962 | 74966 | int iPage; |
| 74963 | 74967 | MemPage *pPage = pCur->pPage; |
| 74964 | 74968 | |
| 74965 | 74969 | 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. */ |
| 74967 | 74975 | break; |
| 74968 | 74976 | }else if( (iPage = pCur->iPage)==0 ){ |
| 74969 | 74977 | if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){ |
| 74970 | 74978 | /* The root page of the b-tree is overfull. In this case call the |
| 74971 | 74979 | ** balance_deeper() function to create a new child for the root-page |
| | @@ -75775,11 +75783,19 @@ |
| 75775 | 75783 | ** on the leaf node first. If the balance proceeds far enough up the |
| 75776 | 75784 | ** tree that we can be sure that any problem in the internal node has |
| 75777 | 75785 | ** been corrected, so be it. Otherwise, after balancing the leaf node, |
| 75778 | 75786 | ** walk the cursor up the tree to the internal node and balance it as |
| 75779 | 75787 | ** 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 | + } |
| 75781 | 75797 | if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){ |
| 75782 | 75798 | releasePageNotNull(pCur->pPage); |
| 75783 | 75799 | pCur->iPage--; |
| 75784 | 75800 | while( pCur->iPage>iCellDepth ){ |
| 75785 | 75801 | releasePage(pCur->apPage[pCur->iPage--]); |
| | @@ -78270,11 +78286,15 @@ |
| 78270 | 78286 | #endif |
| 78271 | 78287 | assert( pMem!=0 ); |
| 78272 | 78288 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 78273 | 78289 | assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE |
| 78274 | 78290 | || 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 ){ |
| 78276 | 78296 | return SQLITE_OK; |
| 78277 | 78297 | } |
| 78278 | 78298 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 78279 | 78299 | #ifdef SQLITE_OMIT_UTF16 |
| 78280 | 78300 | return SQLITE_ERROR; |
| | @@ -78529,10 +78549,11 @@ |
| 78529 | 78549 | t.flags = MEM_Null; |
| 78530 | 78550 | t.db = pMem->db; |
| 78531 | 78551 | ctx.pOut = &t; |
| 78532 | 78552 | ctx.pMem = pMem; |
| 78533 | 78553 | ctx.pFunc = pFunc; |
| 78554 | + ctx.enc = ENC(t.db); |
| 78534 | 78555 | pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */ |
| 78535 | 78556 | assert( (pMem->flags & MEM_Dyn)==0 ); |
| 78536 | 78557 | if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc); |
| 78537 | 78558 | memcpy(pMem, &t, sizeof(t)); |
| 78538 | 78559 | return ctx.isError; |
| | @@ -78556,10 +78577,11 @@ |
| 78556 | 78577 | memset(&ctx, 0, sizeof(ctx)); |
| 78557 | 78578 | sqlite3VdbeMemSetNull(pOut); |
| 78558 | 78579 | ctx.pOut = pOut; |
| 78559 | 78580 | ctx.pMem = pAccum; |
| 78560 | 78581 | ctx.pFunc = pFunc; |
| 78582 | + ctx.enc = ENC(pAccum->db); |
| 78561 | 78583 | pFunc->xValue(&ctx); |
| 78562 | 78584 | return ctx.isError; |
| 78563 | 78585 | } |
| 78564 | 78586 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 78565 | 78587 | |
| | @@ -79173,10 +79195,17 @@ |
| 79173 | 79195 | ** If the string is too large (if it exceeds the SQLITE_LIMIT_LENGTH |
| 79174 | 79196 | ** size limit) then no memory allocation occurs. If the string can be |
| 79175 | 79197 | ** stored without allocating memory, then it is. If a memory allocation |
| 79176 | 79198 | ** is required to store the string, then value of pMem is unchanged. In |
| 79177 | 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. |
| 79178 | 79207 | */ |
| 79179 | 79208 | SQLITE_PRIVATE int sqlite3VdbeMemSetStr( |
| 79180 | 79209 | Mem *pMem, /* Memory cell to set to string value */ |
| 79181 | 79210 | const char *z, /* String pointer */ |
| 79182 | 79211 | i64 n, /* Bytes in string, or negative */ |
| | @@ -79183,15 +79212,16 @@ |
| 79183 | 79212 | u8 enc, /* Encoding of z. 0 for BLOBs */ |
| 79184 | 79213 | void (*xDel)(void*) /* Destructor function */ |
| 79185 | 79214 | ){ |
| 79186 | 79215 | i64 nByte = n; /* New value for pMem->n */ |
| 79187 | 79216 | 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 */ |
| 79189 | 79218 | |
| 79190 | 79219 | assert( pMem!=0 ); |
| 79191 | 79220 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 79192 | 79221 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 79222 | + assert( enc!=0 || n>=0 ); |
| 79193 | 79223 | |
| 79194 | 79224 | /* If z is a NULL pointer, set pMem to contain an SQL NULL. */ |
| 79195 | 79225 | if( !z ){ |
| 79196 | 79226 | sqlite3VdbeMemSetNull(pMem); |
| 79197 | 79227 | return SQLITE_OK; |
| | @@ -79200,19 +79230,34 @@ |
| 79200 | 79230 | if( pMem->db ){ |
| 79201 | 79231 | iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH]; |
| 79202 | 79232 | }else{ |
| 79203 | 79233 | iLimit = SQLITE_MAX_LENGTH; |
| 79204 | 79234 | } |
| 79205 | | - flags = (enc==0?MEM_Blob:MEM_Str); |
| 79206 | 79235 | if( nByte<0 ){ |
| 79207 | 79236 | assert( enc!=0 ); |
| 79208 | 79237 | if( enc==SQLITE_UTF8 ){ |
| 79209 | 79238 | nByte = strlen(z); |
| 79210 | 79239 | }else{ |
| 79211 | 79240 | for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){} |
| 79212 | 79241 | } |
| 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); |
| 79214 | 79259 | } |
| 79215 | 79260 | |
| 79216 | 79261 | /* The following block sets the new values of Mem.z and Mem.xDel. It |
| 79217 | 79262 | ** also sets a flag in local variable "flags" to indicate the memory |
| 79218 | 79263 | ** management (one of MEM_Dyn or MEM_Static). |
| | @@ -79220,13 +79265,10 @@ |
| 79220 | 79265 | if( xDel==SQLITE_TRANSIENT ){ |
| 79221 | 79266 | i64 nAlloc = nByte; |
| 79222 | 79267 | if( flags&MEM_Term ){ |
| 79223 | 79268 | nAlloc += (enc==SQLITE_UTF8?1:2); |
| 79224 | 79269 | } |
| 79225 | | - if( nByte>iLimit ){ |
| 79226 | | - return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG); |
| 79227 | | - } |
| 79228 | 79270 | testcase( nAlloc==0 ); |
| 79229 | 79271 | testcase( nAlloc==31 ); |
| 79230 | 79272 | testcase( nAlloc==32 ); |
| 79231 | 79273 | if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){ |
| 79232 | 79274 | return SQLITE_NOMEM_BKPT; |
| | @@ -79244,30 +79286,18 @@ |
| 79244 | 79286 | } |
| 79245 | 79287 | } |
| 79246 | 79288 | |
| 79247 | 79289 | pMem->n = (int)(nByte & 0x7fffffff); |
| 79248 | 79290 | 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; |
| 79259 | 79292 | |
| 79260 | 79293 | #ifndef SQLITE_OMIT_UTF16 |
| 79261 | 79294 | if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){ |
| 79262 | 79295 | return SQLITE_NOMEM_BKPT; |
| 79263 | 79296 | } |
| 79264 | 79297 | #endif |
| 79265 | 79298 | |
| 79266 | | - if( nByte>iLimit ){ |
| 79267 | | - return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG); |
| 79268 | | - } |
| 79269 | 79299 | |
| 79270 | 79300 | return SQLITE_OK; |
| 79271 | 79301 | } |
| 79272 | 79302 | |
| 79273 | 79303 | /* |
| | @@ -79545,10 +79575,11 @@ |
| 79545 | 79575 | |
| 79546 | 79576 | assert( pCtx->pParse->rc==SQLITE_OK ); |
| 79547 | 79577 | memset(&ctx, 0, sizeof(ctx)); |
| 79548 | 79578 | ctx.pOut = pVal; |
| 79549 | 79579 | ctx.pFunc = pFunc; |
| 79580 | + ctx.enc = ENC(db); |
| 79550 | 79581 | pFunc->xSFunc(&ctx, nVal, apVal); |
| 79551 | 79582 | if( ctx.isError ){ |
| 79552 | 79583 | rc = ctx.isError; |
| 79553 | 79584 | sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); |
| 79554 | 79585 | }else{ |
| | @@ -80055,11 +80086,11 @@ |
| 80055 | 80086 | db->pVdbe->pPrev = p; |
| 80056 | 80087 | } |
| 80057 | 80088 | p->pNext = db->pVdbe; |
| 80058 | 80089 | p->pPrev = 0; |
| 80059 | 80090 | db->pVdbe = p; |
| 80060 | | - p->iVdbeMagic = VDBE_MAGIC_INIT; |
| 80091 | + assert( p->eVdbeState==VDBE_INIT_STATE ); |
| 80061 | 80092 | p->pParse = pParse; |
| 80062 | 80093 | pParse->pVdbe = p; |
| 80063 | 80094 | assert( pParse->aLabel==0 ); |
| 80064 | 80095 | assert( pParse->nLabel==0 ); |
| 80065 | 80096 | assert( p->nOpAlloc==0 ); |
| | @@ -80256,11 +80287,11 @@ |
| 80256 | 80287 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ |
| 80257 | 80288 | int i; |
| 80258 | 80289 | VdbeOp *pOp; |
| 80259 | 80290 | |
| 80260 | 80291 | i = p->nOp; |
| 80261 | | - assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 80292 | + assert( p->eVdbeState==VDBE_INIT_STATE ); |
| 80262 | 80293 | assert( op>=0 && op<0xff ); |
| 80263 | 80294 | if( p->nOpAlloc<=i ){ |
| 80264 | 80295 | return growOp3(p, op, p1, p2, p3); |
| 80265 | 80296 | } |
| 80266 | 80297 | assert( p->aOp!=0 ); |
| | @@ -80588,11 +80619,11 @@ |
| 80588 | 80619 | } |
| 80589 | 80620 | } |
| 80590 | 80621 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ |
| 80591 | 80622 | Parse *p = v->pParse; |
| 80592 | 80623 | int j = ADDR(x); |
| 80593 | | - assert( v->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 80624 | + assert( v->eVdbeState==VDBE_INIT_STATE ); |
| 80594 | 80625 | assert( j<-p->nLabel ); |
| 80595 | 80626 | assert( j>=0 ); |
| 80596 | 80627 | #ifdef SQLITE_DEBUG |
| 80597 | 80628 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 80598 | 80629 | printf("RESOLVE LABEL %d to %d\n", x, v->nOp); |
| | @@ -80719,10 +80750,12 @@ |
| 80719 | 80750 | int hasCreateTable = 0; |
| 80720 | 80751 | int hasCreateIndex = 0; |
| 80721 | 80752 | int hasInitCoroutine = 0; |
| 80722 | 80753 | Op *pOp; |
| 80723 | 80754 | VdbeOpIter sIter; |
| 80755 | + |
| 80756 | + if( v==0 ) return 0; |
| 80724 | 80757 | memset(&sIter, 0, sizeof(sIter)); |
| 80725 | 80758 | sIter.v = v; |
| 80726 | 80759 | |
| 80727 | 80760 | while( (pOp = opIterNext(&sIter))!=0 ){ |
| 80728 | 80761 | int opcode = pOp->opcode; |
| | @@ -80883,22 +80916,24 @@ |
| 80883 | 80916 | assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0); |
| 80884 | 80917 | } |
| 80885 | 80918 | if( pOp==p->aOp ) break; |
| 80886 | 80919 | pOp--; |
| 80887 | 80920 | } |
| 80888 | | - sqlite3DbFree(p->db, pParse->aLabel); |
| 80889 | | - pParse->aLabel = 0; |
| 80921 | + if( aLabel ){ |
| 80922 | + sqlite3DbFreeNN(p->db, pParse->aLabel); |
| 80923 | + pParse->aLabel = 0; |
| 80924 | + } |
| 80890 | 80925 | pParse->nLabel = 0; |
| 80891 | 80926 | *pMaxFuncArgs = nMaxArgs; |
| 80892 | 80927 | assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) ); |
| 80893 | 80928 | } |
| 80894 | 80929 | |
| 80895 | 80930 | /* |
| 80896 | 80931 | ** Return the address of the next instruction to be inserted. |
| 80897 | 80932 | */ |
| 80898 | 80933 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ |
| 80899 | | - assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 80934 | + assert( p->eVdbeState==VDBE_INIT_STATE ); |
| 80900 | 80935 | return p->nOp; |
| 80901 | 80936 | } |
| 80902 | 80937 | |
| 80903 | 80938 | /* |
| 80904 | 80939 | ** Verify that at least N opcode slots are available in p without |
| | @@ -80979,11 +81014,11 @@ |
| 80979 | 81014 | int iLineno /* Source-file line number of first opcode */ |
| 80980 | 81015 | ){ |
| 80981 | 81016 | int i; |
| 80982 | 81017 | VdbeOp *pOut, *pFirst; |
| 80983 | 81018 | assert( nOp>0 ); |
| 80984 | | - assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 81019 | + assert( p->eVdbeState==VDBE_INIT_STATE ); |
| 80985 | 81020 | if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){ |
| 80986 | 81021 | return 0; |
| 80987 | 81022 | } |
| 80988 | 81023 | pFirst = pOut = &p->aOp[p->nOp]; |
| 80989 | 81024 | for(i=0; i<nOp; i++, aOp++, pOut++){ |
| | @@ -81170,17 +81205,20 @@ |
| 81170 | 81205 | ** Free the space allocated for aOp and any p4 values allocated for the |
| 81171 | 81206 | ** opcodes contained within. If aOp is not NULL it is assumed to contain |
| 81172 | 81207 | ** nOp entries. |
| 81173 | 81208 | */ |
| 81174 | 81209 | static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){ |
| 81210 | + assert( nOp>=0 ); |
| 81175 | 81211 | 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 */ |
| 81178 | 81214 | if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p); |
| 81179 | 81215 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 81180 | 81216 | sqlite3DbFree(db, pOp->zComment); |
| 81181 | 81217 | #endif |
| 81218 | + if( pOp==aOp ) break; |
| 81219 | + pOp--; |
| 81182 | 81220 | } |
| 81183 | 81221 | sqlite3DbFreeNN(db, aOp); |
| 81184 | 81222 | } |
| 81185 | 81223 | } |
| 81186 | 81224 | |
| | @@ -81302,11 +81340,11 @@ |
| 81302 | 81340 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){ |
| 81303 | 81341 | Op *pOp; |
| 81304 | 81342 | sqlite3 *db; |
| 81305 | 81343 | assert( p!=0 ); |
| 81306 | 81344 | db = p->db; |
| 81307 | | - assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 81345 | + assert( p->eVdbeState==VDBE_INIT_STATE ); |
| 81308 | 81346 | assert( p->aOp!=0 || db->mallocFailed ); |
| 81309 | 81347 | if( db->mallocFailed ){ |
| 81310 | 81348 | if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4); |
| 81311 | 81349 | return; |
| 81312 | 81350 | } |
| | @@ -81430,11 +81468,11 @@ |
| 81430 | 81468 | */ |
| 81431 | 81469 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ |
| 81432 | 81470 | /* C89 specifies that the constant "dummy" will be initialized to all |
| 81433 | 81471 | ** zeros, which is correct. MSVC generates a warning, nevertheless. */ |
| 81434 | 81472 | static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */ |
| 81435 | | - assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 81473 | + assert( p->eVdbeState==VDBE_INIT_STATE ); |
| 81436 | 81474 | if( addr<0 ){ |
| 81437 | 81475 | addr = p->nOp - 1; |
| 81438 | 81476 | } |
| 81439 | 81477 | assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed ); |
| 81440 | 81478 | if( p->db->mallocFailed ){ |
| | @@ -82132,11 +82170,11 @@ |
| 82132 | 82170 | int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0); |
| 82133 | 82171 | Op *aOp; /* Array of opcodes */ |
| 82134 | 82172 | Op *pOp; /* Current opcode */ |
| 82135 | 82173 | |
| 82136 | 82174 | assert( p->explain ); |
| 82137 | | - assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); |
| 82175 | + assert( p->eVdbeState==VDBE_RUN_STATE ); |
| 82138 | 82176 | assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM ); |
| 82139 | 82177 | |
| 82140 | 82178 | /* Even though this opcode does not use dynamic strings for |
| 82141 | 82179 | ** the result, result columns may become dynamic if the user calls |
| 82142 | 82180 | ** sqlite3_column_text16(), causing a translation to UTF-16 encoding. |
| | @@ -82312,18 +82350,19 @@ |
| 82312 | 82350 | SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){ |
| 82313 | 82351 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 82314 | 82352 | int i; |
| 82315 | 82353 | #endif |
| 82316 | 82354 | 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 ); |
| 82318 | 82358 | |
| 82319 | 82359 | /* There should be at least one opcode. |
| 82320 | 82360 | */ |
| 82321 | 82361 | assert( p->nOp>0 ); |
| 82322 | 82362 | |
| 82323 | | - /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */ |
| 82324 | | - p->iVdbeMagic = VDBE_MAGIC_RUN; |
| 82363 | + p->eVdbeState = VDBE_READY_STATE; |
| 82325 | 82364 | |
| 82326 | 82365 | #ifdef SQLITE_DEBUG |
| 82327 | 82366 | for(i=0; i<p->nMem; i++){ |
| 82328 | 82367 | assert( p->aMem[i].db==p->db ); |
| 82329 | 82368 | } |
| | @@ -82375,11 +82414,11 @@ |
| 82375 | 82414 | struct ReusableSpace x; /* Reusable bulk memory */ |
| 82376 | 82415 | |
| 82377 | 82416 | assert( p!=0 ); |
| 82378 | 82417 | assert( p->nOp>0 ); |
| 82379 | 82418 | assert( pParse!=0 ); |
| 82380 | | - assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 82419 | + assert( p->eVdbeState==VDBE_INIT_STATE ); |
| 82381 | 82420 | assert( pParse==p->pParse ); |
| 82382 | 82421 | p->pVList = pParse->pVList; |
| 82383 | 82422 | pParse->pVList = 0; |
| 82384 | 82423 | db = p->db; |
| 82385 | 82424 | assert( db->mallocFailed==0 ); |
| | @@ -82516,18 +82555,16 @@ |
| 82516 | 82555 | |
| 82517 | 82556 | /* |
| 82518 | 82557 | ** Close all cursors in the current frame. |
| 82519 | 82558 | */ |
| 82520 | 82559 | 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; |
| 82529 | 82566 | } |
| 82530 | 82567 | } |
| 82531 | 82568 | } |
| 82532 | 82569 | |
| 82533 | 82570 | /* |
| | @@ -82572,13 +82609,11 @@ |
| 82572 | 82609 | p->pFrame = 0; |
| 82573 | 82610 | p->nFrame = 0; |
| 82574 | 82611 | } |
| 82575 | 82612 | assert( p->nFrame==0 ); |
| 82576 | 82613 | closeCursorsInFrame(p); |
| 82577 | | - if( p->aMem ){ |
| 82578 | | - releaseMemArray(p->aMem, p->nMem); |
| 82579 | | - } |
| 82614 | + releaseMemArray(p->aMem, p->nMem); |
| 82580 | 82615 | while( p->pDelFrame ){ |
| 82581 | 82616 | VdbeFrame *pDel = p->pDelFrame; |
| 82582 | 82617 | p->pDelFrame = pDel->pParent; |
| 82583 | 82618 | sqlite3VdbeFrameDelete(pDel); |
| 82584 | 82619 | } |
| | @@ -83014,10 +83049,11 @@ |
| 83014 | 83049 | || (!deferred && p->nFkConstraint>0) |
| 83015 | 83050 | ){ |
| 83016 | 83051 | p->rc = SQLITE_CONSTRAINT_FOREIGNKEY; |
| 83017 | 83052 | p->errorAction = OE_Abort; |
| 83018 | 83053 | sqlite3VdbeError(p, "FOREIGN KEY constraint failed"); |
| 83054 | + if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ) return SQLITE_ERROR; |
| 83019 | 83055 | return SQLITE_CONSTRAINT_FOREIGNKEY; |
| 83020 | 83056 | } |
| 83021 | 83057 | return SQLITE_OK; |
| 83022 | 83058 | } |
| 83023 | 83059 | #endif |
| | @@ -83053,11 +83089,11 @@ |
| 83053 | 83089 | ** Then the internal cache might have been left in an inconsistent |
| 83054 | 83090 | ** state. We need to rollback the statement transaction, if there is |
| 83055 | 83091 | ** one, or the complete transaction if there is no statement transaction. |
| 83056 | 83092 | */ |
| 83057 | 83093 | |
| 83058 | | - if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){ |
| 83094 | + if( p->eVdbeState!=VDBE_RUN_STATE ){ |
| 83059 | 83095 | return SQLITE_OK; |
| 83060 | 83096 | } |
| 83061 | 83097 | if( db->mallocFailed ){ |
| 83062 | 83098 | p->rc = SQLITE_NOMEM_BKPT; |
| 83063 | 83099 | } |
| | @@ -83064,11 +83100,11 @@ |
| 83064 | 83100 | closeAllCursors(p); |
| 83065 | 83101 | checkActiveVdbeCnt(db); |
| 83066 | 83102 | |
| 83067 | 83103 | /* No commit or rollback needed if the program never started or if the |
| 83068 | 83104 | ** SQL statement does not read or write a database file. */ |
| 83069 | | - if( p->pc>=0 && p->bIsReader ){ |
| 83105 | + if( p->bIsReader ){ |
| 83070 | 83106 | int mrc; /* Primary error code from p->rc */ |
| 83071 | 83107 | int eStatementOp = 0; |
| 83072 | 83108 | int isSpecialError; /* Set to true if a 'special' error */ |
| 83073 | 83109 | |
| 83074 | 83110 | /* Lock all btrees used by the statement */ |
| | @@ -83212,19 +83248,17 @@ |
| 83212 | 83248 | /* Release the locks */ |
| 83213 | 83249 | sqlite3VdbeLeave(p); |
| 83214 | 83250 | } |
| 83215 | 83251 | |
| 83216 | 83252 | /* 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; |
| 83226 | 83260 | checkActiveVdbeCnt(db); |
| 83227 | 83261 | if( db->mallocFailed ){ |
| 83228 | 83262 | p->rc = SQLITE_NOMEM_BKPT; |
| 83229 | 83263 | } |
| 83230 | 83264 | |
| | @@ -83302,12 +83336,12 @@ |
| 83302 | 83336 | ** |
| 83303 | 83337 | ** After this routine is run, the VDBE should be ready to be executed |
| 83304 | 83338 | ** again. |
| 83305 | 83339 | ** |
| 83306 | 83340 | ** 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. |
| 83309 | 83343 | */ |
| 83310 | 83344 | SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){ |
| 83311 | 83345 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 83312 | 83346 | int i; |
| 83313 | 83347 | #endif |
| | @@ -83332,16 +83366,10 @@ |
| 83332 | 83366 | sqlite3VdbeTransferError(p); |
| 83333 | 83367 | }else{ |
| 83334 | 83368 | db->errCode = p->rc; |
| 83335 | 83369 | } |
| 83336 | 83370 | 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 | 83371 | } |
| 83344 | 83372 | |
| 83345 | 83373 | /* Reset register contents and reclaim error message memory. |
| 83346 | 83374 | */ |
| 83347 | 83375 | #ifdef SQLITE_DEBUG |
| | @@ -83394,21 +83422,23 @@ |
| 83394 | 83422 | } |
| 83395 | 83423 | fclose(out); |
| 83396 | 83424 | } |
| 83397 | 83425 | } |
| 83398 | 83426 | #endif |
| 83399 | | - p->iVdbeMagic = VDBE_MAGIC_RESET; |
| 83400 | 83427 | return p->rc & db->errMask; |
| 83401 | 83428 | } |
| 83402 | 83429 | |
| 83403 | 83430 | /* |
| 83404 | 83431 | ** Clean up and delete a VDBE after execution. Return an integer which is |
| 83405 | 83432 | ** the result code. Write any error message text into *pzErrMsg. |
| 83406 | 83433 | */ |
| 83407 | 83434 | SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){ |
| 83408 | 83435 | 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 ){ |
| 83410 | 83440 | rc = sqlite3VdbeReset(p); |
| 83411 | 83441 | assert( (rc & p->db->errMask)==rc ); |
| 83412 | 83442 | } |
| 83413 | 83443 | sqlite3VdbeDelete(p); |
| 83414 | 83444 | return rc; |
| | @@ -83459,23 +83489,25 @@ |
| 83459 | 83489 | ** the database connection and frees the object itself. |
| 83460 | 83490 | */ |
| 83461 | 83491 | SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){ |
| 83462 | 83492 | SubProgram *pSub, *pNext; |
| 83463 | 83493 | 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 | + } |
| 83465 | 83498 | for(pSub=p->pProgram; pSub; pSub=pNext){ |
| 83466 | 83499 | pNext = pSub->pNext; |
| 83467 | 83500 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 83468 | 83501 | sqlite3DbFree(db, pSub); |
| 83469 | 83502 | } |
| 83470 | | - if( p->iVdbeMagic!=VDBE_MAGIC_INIT ){ |
| 83503 | + if( p->eVdbeState!=VDBE_INIT_STATE ){ |
| 83471 | 83504 | 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); |
| 83474 | 83507 | } |
| 83475 | 83508 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 83476 | | - sqlite3DbFree(db, p->aColName); |
| 83477 | 83509 | sqlite3DbFree(db, p->zSql); |
| 83478 | 83510 | #ifdef SQLITE_ENABLE_NORMALIZE |
| 83479 | 83511 | sqlite3DbFree(db, p->zNormSql); |
| 83480 | 83512 | { |
| 83481 | 83513 | DblquoteStr *pThis, *pNext; |
| | @@ -83513,12 +83545,10 @@ |
| 83513 | 83545 | db->pVdbe = p->pNext; |
| 83514 | 83546 | } |
| 83515 | 83547 | if( p->pNext ){ |
| 83516 | 83548 | p->pNext->pPrev = p->pPrev; |
| 83517 | 83549 | } |
| 83518 | | - p->iVdbeMagic = VDBE_MAGIC_DEAD; |
| 83519 | | - p->db = 0; |
| 83520 | 83550 | sqlite3DbFreeNN(db, p); |
| 83521 | 83551 | } |
| 83522 | 83552 | |
| 83523 | 83553 | /* |
| 83524 | 83554 | ** The cursor "p" has a pending seek operation that has not yet been |
| | @@ -85638,20 +85668,26 @@ |
| 85638 | 85668 | const char *z, /* String pointer */ |
| 85639 | 85669 | int n, /* Bytes in string, or negative */ |
| 85640 | 85670 | u8 enc, /* Encoding of z. 0 for BLOBs */ |
| 85641 | 85671 | void (*xDel)(void*) /* Destructor function */ |
| 85642 | 85672 | ){ |
| 85643 | | - int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel); |
| 85673 | + Mem *pOut = pCtx->pOut; |
| 85674 | + int rc = sqlite3VdbeMemSetStr(pOut, z, n, enc, xDel); |
| 85644 | 85675 | if( rc ){ |
| 85645 | 85676 | if( rc==SQLITE_TOOBIG ){ |
| 85646 | 85677 | sqlite3_result_error_toobig(pCtx); |
| 85647 | 85678 | }else{ |
| 85648 | 85679 | /* The only errors possible from sqlite3VdbeMemSetStr are |
| 85649 | 85680 | ** SQLITE_TOOBIG and SQLITE_NOMEM */ |
| 85650 | 85681 | assert( rc==SQLITE_NOMEM ); |
| 85651 | 85682 | sqlite3_result_error_nomem(pCtx); |
| 85652 | 85683 | } |
| 85684 | + return; |
| 85685 | + } |
| 85686 | + sqlite3VdbeChangeEncoding(pOut, pCtx->enc); |
| 85687 | + if( sqlite3VdbeMemTooBig(pOut) ){ |
| 85688 | + sqlite3_result_error_toobig(pCtx); |
| 85653 | 85689 | } |
| 85654 | 85690 | } |
| 85655 | 85691 | static int invokeValueDestructor( |
| 85656 | 85692 | const void *p, /* Value to destroy */ |
| 85657 | 85693 | void (*xDel)(void*), /* The destructor */ |
| | @@ -85791,21 +85827,26 @@ |
| 85791 | 85827 | assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); |
| 85792 | 85828 | setResultStrOrError(pCtx, z, n, SQLITE_UTF16LE, xDel); |
| 85793 | 85829 | } |
| 85794 | 85830 | #endif /* SQLITE_OMIT_UTF16 */ |
| 85795 | 85831 | SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){ |
| 85832 | + Mem *pOut = pCtx->pOut; |
| 85796 | 85833 | 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 | + } |
| 85798 | 85839 | } |
| 85799 | 85840 | 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); |
| 85802 | 85842 | } |
| 85803 | 85843 | SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){ |
| 85804 | 85844 | Mem *pOut = pCtx->pOut; |
| 85805 | 85845 | assert( sqlite3_mutex_held(pOut->db->mutex) ); |
| 85806 | 85846 | if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 85847 | + sqlite3_result_error_toobig(pCtx); |
| 85807 | 85848 | return SQLITE_TOOBIG; |
| 85808 | 85849 | } |
| 85809 | 85850 | #ifndef SQLITE_OMIT_INCRBLOB |
| 85810 | 85851 | sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n); |
| 85811 | 85852 | return SQLITE_OK; |
| | @@ -85817,12 +85858,12 @@ |
| 85817 | 85858 | pCtx->isError = errCode ? errCode : -1; |
| 85818 | 85859 | #ifdef SQLITE_DEBUG |
| 85819 | 85860 | if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; |
| 85820 | 85861 | #endif |
| 85821 | 85862 | 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); |
| 85824 | 85865 | } |
| 85825 | 85866 | } |
| 85826 | 85867 | |
| 85827 | 85868 | /* Force an SQLITE_TOOBIG error. */ |
| 85828 | 85869 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){ |
| | @@ -85891,85 +85932,94 @@ |
| 85891 | 85932 | */ |
| 85892 | 85933 | static int sqlite3Step(Vdbe *p){ |
| 85893 | 85934 | sqlite3 *db; |
| 85894 | 85935 | int rc; |
| 85895 | 85936 | |
| 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 | 85937 | /* Check that malloc() has not failed. If it has, return early. */ |
| 85926 | 85938 | db = p->db; |
| 85927 | 85939 | if( db->mallocFailed ){ |
| 85928 | 85940 | p->rc = SQLITE_NOMEM; |
| 85929 | 85941 | return SQLITE_NOMEM_BKPT; |
| 85930 | 85942 | } |
| 85931 | 85943 | |
| 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 | + ); |
| 85956 | 85973 | |
| 85957 | 85974 | #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 | + } |
| 85964 | 85981 | #endif |
| 85965 | 85982 | |
| 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 | + } |
| 85970 | 86019 | } |
| 86020 | + |
| 85971 | 86021 | #ifdef SQLITE_DEBUG |
| 85972 | 86022 | p->rcApp = SQLITE_OK; |
| 85973 | 86023 | #endif |
| 85974 | 86024 | #ifndef SQLITE_OMIT_EXPLAIN |
| 85975 | 86025 | if( p->explain ){ |
| | @@ -85980,11 +86030,16 @@ |
| 85980 | 86030 | db->nVdbeExec++; |
| 85981 | 86031 | rc = sqlite3VdbeExec(p); |
| 85982 | 86032 | db->nVdbeExec--; |
| 85983 | 86033 | } |
| 85984 | 86034 | |
| 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{ |
| 85986 | 86041 | #ifndef SQLITE_OMIT_TRACE |
| 85987 | 86042 | /* If the statement completed successfully, invoke the profile callback */ |
| 85988 | 86043 | checkProfileCallback(db, p); |
| 85989 | 86044 | #endif |
| 85990 | 86045 | |
| | @@ -86672,11 +86727,11 @@ |
| 86672 | 86727 | Mem *pVar; |
| 86673 | 86728 | if( vdbeSafetyNotNull(p) ){ |
| 86674 | 86729 | return SQLITE_MISUSE_BKPT; |
| 86675 | 86730 | } |
| 86676 | 86731 | sqlite3_mutex_enter(p->db->mutex); |
| 86677 | | - if( p->iVdbeMagic!=VDBE_MAGIC_RUN || p->pc>=0 ){ |
| 86732 | + if( p->eVdbeState!=VDBE_READY_STATE ){ |
| 86678 | 86733 | sqlite3Error(p->db, SQLITE_MISUSE); |
| 86679 | 86734 | sqlite3_mutex_leave(p->db->mutex); |
| 86680 | 86735 | sqlite3_log(SQLITE_MISUSE, |
| 86681 | 86736 | "bind on a busy prepared statement: [%s]", p->zSql); |
| 86682 | 86737 | return SQLITE_MISUSE_BKPT; |
| | @@ -87025,11 +87080,11 @@ |
| 87025 | 87080 | /* |
| 87026 | 87081 | ** Return true if the prepared statement is in need of being reset. |
| 87027 | 87082 | */ |
| 87028 | 87083 | SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ |
| 87029 | 87084 | 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; |
| 87031 | 87086 | } |
| 87032 | 87087 | |
| 87033 | 87088 | /* |
| 87034 | 87089 | ** Return a pointer to the next prepared statement after pStmt associated |
| 87035 | 87090 | ** with database connection pDb. If pStmt is NULL, return the first |
| | @@ -88339,11 +88394,11 @@ |
| 88339 | 88394 | #ifdef VDBE_PROFILE |
| 88340 | 88395 | u64 start; /* CPU clock count at start of opcode */ |
| 88341 | 88396 | #endif |
| 88342 | 88397 | /*** INSERT STACK UNION HERE ***/ |
| 88343 | 88398 | |
| 88344 | | - assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 88399 | + assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */ |
| 88345 | 88400 | sqlite3VdbeEnter(p); |
| 88346 | 88401 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 88347 | 88402 | if( db->xProgress ){ |
| 88348 | 88403 | u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; |
| 88349 | 88404 | assert( 0 < db->nProgressOps ); |
| | @@ -94848,10 +94903,11 @@ |
| 94848 | 94903 | pCtx->pFunc = pOp->p4.pFunc; |
| 94849 | 94904 | pCtx->iOp = (int)(pOp - aOp); |
| 94850 | 94905 | pCtx->pVdbe = p; |
| 94851 | 94906 | pCtx->skipFlag = 0; |
| 94852 | 94907 | pCtx->isError = 0; |
| 94908 | + pCtx->enc = encoding; |
| 94853 | 94909 | pCtx->argc = n; |
| 94854 | 94910 | pOp->p4type = P4_FUNCCTX; |
| 94855 | 94911 | pOp->p4.pCtx = pCtx; |
| 94856 | 94912 | |
| 94857 | 94913 | /* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */ |
| | @@ -94977,13 +95033,10 @@ |
| 94977 | 95033 | sqlite3VdbeError(p, "%s", sqlite3_value_text(pMem)); |
| 94978 | 95034 | goto abort_due_to_error; |
| 94979 | 95035 | } |
| 94980 | 95036 | sqlite3VdbeChangeEncoding(pMem, encoding); |
| 94981 | 95037 | UPDATE_MAX_BLOBSIZE(pMem); |
| 94982 | | - if( sqlite3VdbeMemTooBig(pMem) ){ |
| 94983 | | - goto too_big; |
| 94984 | | - } |
| 94985 | 95038 | break; |
| 94986 | 95039 | } |
| 94987 | 95040 | |
| 94988 | 95041 | #ifndef SQLITE_OMIT_WAL |
| 94989 | 95042 | /* Opcode: Checkpoint P1 P2 P3 * * |
| | @@ -95500,10 +95553,11 @@ |
| 95500 | 95553 | pVtab = pCur->uc.pVCur->pVtab; |
| 95501 | 95554 | pModule = pVtab->pModule; |
| 95502 | 95555 | assert( pModule->xColumn ); |
| 95503 | 95556 | memset(&sContext, 0, sizeof(sContext)); |
| 95504 | 95557 | sContext.pOut = pDest; |
| 95558 | + sContext.enc = encoding; |
| 95505 | 95559 | assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 ); |
| 95506 | 95560 | if( pOp->p5 & OPFLAG_NOCHNG ){ |
| 95507 | 95561 | sqlite3VdbeMemSetNull(pDest); |
| 95508 | 95562 | pDest->flags = MEM_Null|MEM_Zero; |
| 95509 | 95563 | pDest->u.nZero = 0; |
| | @@ -95518,13 +95572,10 @@ |
| 95518 | 95572 | } |
| 95519 | 95573 | sqlite3VdbeChangeEncoding(pDest, encoding); |
| 95520 | 95574 | REGISTER_TRACE(pOp->p3, pDest); |
| 95521 | 95575 | UPDATE_MAX_BLOBSIZE(pDest); |
| 95522 | 95576 | |
| 95523 | | - if( sqlite3VdbeMemTooBig(pDest) ){ |
| 95524 | | - goto too_big; |
| 95525 | | - } |
| 95526 | 95577 | if( rc ) goto abort_due_to_error; |
| 95527 | 95578 | break; |
| 95528 | 95579 | } |
| 95529 | 95580 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 95530 | 95581 | |
| | @@ -95787,10 +95838,11 @@ |
| 95787 | 95838 | ** reinitializes the relavant parts of the sqlite3_context object */ |
| 95788 | 95839 | pOut = &aMem[pOp->p3]; |
| 95789 | 95840 | if( pCtx->pOut != pOut ){ |
| 95790 | 95841 | pCtx->pVdbe = p; |
| 95791 | 95842 | pCtx->pOut = pOut; |
| 95843 | + pCtx->enc = encoding; |
| 95792 | 95844 | for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; |
| 95793 | 95845 | } |
| 95794 | 95846 | assert( pCtx->pVdbe==p ); |
| 95795 | 95847 | |
| 95796 | 95848 | memAboutToChange(p, pOut); |
| | @@ -95813,15 +95865,14 @@ |
| 95813 | 95865 | sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1); |
| 95814 | 95866 | pCtx->isError = 0; |
| 95815 | 95867 | if( rc ) goto abort_due_to_error; |
| 95816 | 95868 | } |
| 95817 | 95869 | |
| 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) ); |
| 95823 | 95874 | |
| 95824 | 95875 | REGISTER_TRACE(pOp->p3, pOut); |
| 95825 | 95876 | UPDATE_MAX_BLOBSIZE(pOut); |
| 95826 | 95877 | break; |
| 95827 | 95878 | } |
| | @@ -114347,11 +114398,13 @@ |
| 114347 | 114398 | && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr) |
| 114348 | 114399 | ){ |
| 114349 | 114400 | int iDb, i; |
| 114350 | 114401 | assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init ); |
| 114351 | 114402 | sqlite3VdbeJumpHere(v, 0); |
| 114352 | | - for(iDb=0; iDb<db->nDb; iDb++){ |
| 114403 | + assert( db->nDb>0 ); |
| 114404 | + iDb = 0; |
| 114405 | + do{ |
| 114353 | 114406 | Schema *pSchema; |
| 114354 | 114407 | if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue; |
| 114355 | 114408 | sqlite3VdbeUsesBtree(v, iDb); |
| 114356 | 114409 | pSchema = db->aDb[iDb].pSchema; |
| 114357 | 114410 | sqlite3VdbeAddOp4Int(v, |
| | @@ -114362,11 +114415,11 @@ |
| 114362 | 114415 | pSchema->iGeneration /* P4 */ |
| 114363 | 114416 | ); |
| 114364 | 114417 | if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1); |
| 114365 | 114418 | VdbeComment((v, |
| 114366 | 114419 | "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite)); |
| 114367 | | - } |
| 114420 | + }while( ++iDb<db->nDb ); |
| 114368 | 114421 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 114369 | 114422 | for(i=0; i<pParse->nVtabLock; i++){ |
| 114370 | 114423 | char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]); |
| 114371 | 114424 | sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB); |
| 114372 | 114425 | } |
| | @@ -131503,11 +131556,11 @@ |
| 131503 | 131556 | ** |
| 131504 | 131557 | ** Do N steps of incremental vacuuming on a database. |
| 131505 | 131558 | */ |
| 131506 | 131559 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 131507 | 131560 | case PragTyp_INCREMENTAL_VACUUM: { |
| 131508 | | - int iLimit, addr; |
| 131561 | + int iLimit = 0, addr; |
| 131509 | 131562 | if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
| 131510 | 131563 | iLimit = 0x7fffffff; |
| 131511 | 131564 | } |
| 131512 | 131565 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 131513 | 131566 | sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); |
| | @@ -133807,11 +133860,11 @@ |
| 133807 | 133860 | if( db->mallocFailed ){ |
| 133808 | 133861 | rc = SQLITE_NOMEM_BKPT; |
| 133809 | 133862 | sqlite3ResetAllSchemasOfConnection(db); |
| 133810 | 133863 | pDb = &db->aDb[iDb]; |
| 133811 | 133864 | }else |
| 133812 | | - if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){ |
| 133865 | + if( rc==SQLITE_OK || ((db->flags&SQLITE_NoSchemaError) && rc!=SQLITE_NOMEM)){ |
| 133813 | 133866 | /* Hack: If the SQLITE_NoSchemaError flag is set, then consider |
| 133814 | 133867 | ** the schema loaded, even if errors (other than OOM) occurred. In |
| 133815 | 133868 | ** this situation the current sqlite3_prepare() operation will fail, |
| 133816 | 133869 | ** but the following one will attempt to compile the supplied statement |
| 133817 | 133870 | ** against whatever subset of the schema was loaded before the error |
| | @@ -154862,12 +154915,21 @@ |
| 154862 | 154915 | if( j<0 ){ |
| 154863 | 154916 | if( pLoop->maskSelf==pTerm->prereqAll ){ |
| 154864 | 154917 | /* If there are extra terms in the WHERE clause not used by an index |
| 154865 | 154918 | ** that depend only on the table being scanned, and that will tend to |
| 154866 | 154919 | ** 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 | + } |
| 154869 | 154931 | } |
| 154870 | 154932 | if( pTerm->truthProb<=0 ){ |
| 154871 | 154933 | /* If a truth probability is specified using the likelihood() hints, |
| 154872 | 154934 | ** then use the probability provided by the application. */ |
| 154873 | 154935 | pLoop->nOut += pTerm->truthProb; |
| | @@ -168198,11 +168260,11 @@ |
| 168198 | 168260 | sqlite3DeleteTable(db, pParse->pNewTable); |
| 168199 | 168261 | } |
| 168200 | 168262 | if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){ |
| 168201 | 168263 | sqlite3DeleteTrigger(db, pParse->pNewTrigger); |
| 168202 | 168264 | } |
| 168203 | | - sqlite3DbFree(db, pParse->pVList); |
| 168265 | + if( pParse->pVList ) sqlite3DbFreeNN(db, pParse->pVList); |
| 168204 | 168266 | db->pParse = pParentParse; |
| 168205 | 168267 | assert( nErr==0 || pParse->rc!=SQLITE_OK ); |
| 168206 | 168268 | return nErr; |
| 168207 | 168269 | } |
| 168208 | 168270 | |
| | @@ -234692,11 +234754,11 @@ |
| 234692 | 234754 | int nArg, /* Number of args */ |
| 234693 | 234755 | sqlite3_value **apUnused /* Function arguments */ |
| 234694 | 234756 | ){ |
| 234695 | 234757 | assert( nArg==0 ); |
| 234696 | 234758 | 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); |
| 234698 | 234760 | } |
| 234699 | 234761 | |
| 234700 | 234762 | /* |
| 234701 | 234763 | ** Return true if zName is the extension on one of the shadow tables used |
| 234702 | 234764 | ** by this module. |
| 234703 | 234765 | |