| | @@ -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.37.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3037000 |
| 457 | | -#define SQLITE_SOURCE_ID "2021-11-04 14:04:20 9147390d9885a37a62edc1058f313434627f1b59965c890877d2cb119e355c78" |
| 457 | +#define SQLITE_SOURCE_ID "2021-11-15 19:10:13 bd66ab8a1bc3c43a57c7caff5f54545b0feb0177f1f51492f30d308c123c43ba" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -913,10 +913,11 @@ |
| 913 | 913 | #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ |
| 914 | 914 | #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ |
| 915 | 915 | #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ |
| 916 | 916 | #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ |
| 917 | 917 | #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ |
| 918 | +#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ |
| 918 | 919 | |
| 919 | 920 | /* Reserved: 0x00F00000 */ |
| 920 | 921 | /* Legacy compatibility: */ |
| 921 | 922 | #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ |
| 922 | 923 | |
| | @@ -3732,10 +3733,18 @@ |
| 3732 | 3733 | ** |
| 3733 | 3734 | ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt> |
| 3734 | 3735 | ** <dd>The database is opened [shared cache] disabled, overriding |
| 3735 | 3736 | ** the default shared cache setting provided by |
| 3736 | 3737 | ** [sqlite3_enable_shared_cache()].)^ |
| 3738 | +** |
| 3739 | +** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt> |
| 3740 | +** <dd>The database connection comes up in "extended result code mode". |
| 3741 | +** In other words, the database behaves has if |
| 3742 | +** [sqlite3_extended_result_codes(db,1)] where called on the database |
| 3743 | +** connection as soon as the connection is created. In addition to setting |
| 3744 | +** the extended result code mode, this flag also causes [sqlite3_open_v2()] |
| 3745 | +** to return an extended result code.</dd> |
| 3737 | 3746 | ** |
| 3738 | 3747 | ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt> |
| 3739 | 3748 | ** <dd>The database filename is not allowed to be a symbolic link</dd> |
| 3740 | 3749 | ** </dl>)^ |
| 3741 | 3750 | ** |
| | @@ -16649,10 +16658,11 @@ |
| 16649 | 16658 | #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/ |
| 16650 | 16659 | #define SQLITE_EnableView 0x80000000 /* Enable the use of views */ |
| 16651 | 16660 | #define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */ |
| 16652 | 16661 | /* DELETE, or UPDATE and return */ |
| 16653 | 16662 | /* the count using a callback. */ |
| 16663 | +#define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */ |
| 16654 | 16664 | |
| 16655 | 16665 | /* Flags used only if debugging */ |
| 16656 | 16666 | #ifdef SQLITE_DEBUG |
| 16657 | 16667 | #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */ |
| 16658 | 16668 | #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */ |
| | @@ -18901,12 +18911,12 @@ |
| 18901 | 18911 | union { /* Extra data for callback */ |
| 18902 | 18912 | NameContext *pNC; /* Naming context */ |
| 18903 | 18913 | int n; /* A counter */ |
| 18904 | 18914 | int iCur; /* A cursor number */ |
| 18905 | 18915 | SrcList *pSrcList; /* FROM clause */ |
| 18906 | | - struct SrcCount *pSrcCount; /* Counting column references */ |
| 18907 | 18916 | struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ |
| 18917 | + struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */ |
| 18908 | 18918 | int *aiCol; /* array of column indexes */ |
| 18909 | 18919 | struct IdxCover *pIdxCover; /* Check for index coverage */ |
| 18910 | 18920 | struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */ |
| 18911 | 18921 | ExprList *pGroupBy; /* GROUP BY clause */ |
| 18912 | 18922 | Select *pSelect; /* HAVING to WHERE clause ctx */ |
| | @@ -19560,11 +19570,11 @@ |
| 19560 | 19570 | SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int); |
| 19561 | 19571 | SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*); |
| 19562 | 19572 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 19563 | 19573 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 19564 | 19574 | SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| 19565 | | -SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 19575 | +SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*); |
| 19566 | 19576 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 19567 | 19577 | #ifndef SQLITE_UNTESTABLE |
| 19568 | 19578 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 19569 | 19579 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 19570 | 19580 | #endif |
| | @@ -22193,11 +22203,15 @@ |
| 22193 | 22203 | SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double); |
| 22194 | 22204 | #endif |
| 22195 | 22205 | SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*)); |
| 22196 | 22206 | SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16); |
| 22197 | 22207 | SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*); |
| 22208 | +#ifndef SQLITE_OMIT_INCRBLOB |
| 22198 | 22209 | SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int); |
| 22210 | +#else |
| 22211 | +SQLITE_PRIVATE int sqlite3VdbeMemSetZeroBlob(Mem*,int); |
| 22212 | +#endif |
| 22199 | 22213 | #ifdef SQLITE_DEBUG |
| 22200 | 22214 | SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem*); |
| 22201 | 22215 | #endif |
| 22202 | 22216 | SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem*); |
| 22203 | 22217 | SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*); |
| | @@ -48826,12 +48840,13 @@ |
| 48826 | 48840 | */ |
| 48827 | 48841 | static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ |
| 48828 | 48842 | MemStore *p = ((MemFile*)pFile)->pStore; |
| 48829 | 48843 | int rc = SQLITE_OK; |
| 48830 | 48844 | memdbEnter(p); |
| 48831 | | - if( NEVER(size>p->sz) ){ |
| 48832 | | - rc = SQLITE_FULL; |
| 48845 | + if( size>p->sz ){ |
| 48846 | + /* This can only happen with a corrupt wal mode db */ |
| 48847 | + rc = SQLITE_CORRUPT; |
| 48833 | 48848 | }else{ |
| 48834 | 48849 | p->sz = size; |
| 48835 | 48850 | } |
| 48836 | 48851 | memdbLeave(p); |
| 48837 | 48852 | return rc; |
| | @@ -67031,11 +67046,11 @@ |
| 67031 | 67046 | if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 67032 | 67047 | sz2 = get2byte(&data[iFree2+2]); |
| 67033 | 67048 | if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage); |
| 67034 | 67049 | memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); |
| 67035 | 67050 | sz += sz2; |
| 67036 | | - }else if( iFree+sz>usableSize ){ |
| 67051 | + }else if( NEVER(iFree+sz>usableSize) ){ |
| 67037 | 67052 | return SQLITE_CORRUPT_PAGE(pPage); |
| 67038 | 67053 | } |
| 67039 | 67054 | |
| 67040 | 67055 | cbrk = top+sz; |
| 67041 | 67056 | assert( cbrk+(iFree-top) <= usableSize ); |
| | @@ -72654,11 +72669,11 @@ |
| 72654 | 72669 | int k; /* Current slot in pCArray->apEnd[] */ |
| 72655 | 72670 | u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */ |
| 72656 | 72671 | |
| 72657 | 72672 | assert( i<iEnd ); |
| 72658 | 72673 | j = get2byte(&aData[hdr+5]); |
| 72659 | | - if( j>(u32)usableSize ){ j = 0; } |
| 72674 | + if( NEVER(j>(u32)usableSize) ){ j = 0; } |
| 72660 | 72675 | memcpy(&pTmp[j], &aData[j], usableSize - j); |
| 72661 | 72676 | |
| 72662 | 72677 | for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){} |
| 72663 | 72678 | pSrcEnd = pCArray->apEnd[k]; |
| 72664 | 72679 | |
| | @@ -78041,19 +78056,35 @@ |
| 78041 | 78056 | |
| 78042 | 78057 | /* |
| 78043 | 78058 | ** Delete any previous value and set the value to be a BLOB of length |
| 78044 | 78059 | ** n containing all zeros. |
| 78045 | 78060 | */ |
| 78061 | +#ifndef SQLITE_OMIT_INCRBLOB |
| 78046 | 78062 | SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){ |
| 78047 | 78063 | sqlite3VdbeMemRelease(pMem); |
| 78048 | 78064 | pMem->flags = MEM_Blob|MEM_Zero; |
| 78049 | 78065 | pMem->n = 0; |
| 78050 | 78066 | if( n<0 ) n = 0; |
| 78051 | 78067 | pMem->u.nZero = n; |
| 78052 | 78068 | pMem->enc = SQLITE_UTF8; |
| 78053 | 78069 | pMem->z = 0; |
| 78054 | 78070 | } |
| 78071 | +#else |
| 78072 | +SQLITE_PRIVATE int sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){ |
| 78073 | + int nByte = n>0?n:1; |
| 78074 | + if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){ |
| 78075 | + return SQLITE_NOMEM_BKPT; |
| 78076 | + } |
| 78077 | + assert( pMem->z!=0 ); |
| 78078 | + assert( sqlite3DbMallocSize(pMem->db, pMem->z)>=nByte ); |
| 78079 | + memset(pMem->z, 0, nByte); |
| 78080 | + pMem->n = n>0?n:0; |
| 78081 | + pMem->flags = MEM_Blob; |
| 78082 | + pMem->enc = SQLITE_UTF8; |
| 78083 | + return SQLITE_OK; |
| 78084 | +} |
| 78085 | +#endif |
| 78055 | 78086 | |
| 78056 | 78087 | /* |
| 78057 | 78088 | ** The pMem is known to contain content that needs to be destroyed prior |
| 78058 | 78089 | ** to a value change. So invoke the destructor, then set the value to |
| 78059 | 78090 | ** a 64-bit integer. |
| | @@ -82178,13 +82209,19 @@ |
| 82178 | 82209 | |
| 82179 | 82210 | /* Lock all btrees used by the statement */ |
| 82180 | 82211 | sqlite3VdbeEnter(p); |
| 82181 | 82212 | |
| 82182 | 82213 | /* Check for one of the special errors */ |
| 82183 | | - mrc = p->rc & 0xff; |
| 82184 | | - isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR |
| 82185 | | - || mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL; |
| 82214 | + if( p->rc ){ |
| 82215 | + mrc = p->rc & 0xff; |
| 82216 | + isSpecialError = mrc==SQLITE_NOMEM |
| 82217 | + || mrc==SQLITE_IOERR |
| 82218 | + || mrc==SQLITE_INTERRUPT |
| 82219 | + || mrc==SQLITE_FULL; |
| 82220 | + }else{ |
| 82221 | + mrc = isSpecialError = 0; |
| 82222 | + } |
| 82186 | 82223 | if( isSpecialError ){ |
| 82187 | 82224 | /* If the query was read-only and the error code is SQLITE_INTERRUPT, |
| 82188 | 82225 | ** no rollback is necessary. Otherwise, at least a savepoint |
| 82189 | 82226 | ** transaction must be rolled back to restore the database to a |
| 82190 | 82227 | ** consistent state. |
| | @@ -82232,10 +82269,13 @@ |
| 82232 | 82269 | if( NEVER(p->readOnly) ){ |
| 82233 | 82270 | sqlite3VdbeLeave(p); |
| 82234 | 82271 | return SQLITE_ERROR; |
| 82235 | 82272 | } |
| 82236 | 82273 | rc = SQLITE_CONSTRAINT_FOREIGNKEY; |
| 82274 | + }else if( db->flags & SQLITE_CorruptRdOnly ){ |
| 82275 | + rc = SQLITE_CORRUPT; |
| 82276 | + db->flags &= ~SQLITE_CorruptRdOnly; |
| 82237 | 82277 | }else{ |
| 82238 | 82278 | /* The auto-commit flag is true, the vdbe program was successful |
| 82239 | 82279 | ** or hit an 'OR FAIL' constraint and there are no deferred foreign |
| 82240 | 82280 | ** key constraints to hold up the transaction. This means a commit |
| 82241 | 82281 | ** is required. */ |
| | @@ -84336,10 +84376,12 @@ |
| 84336 | 84376 | }else{ |
| 84337 | 84377 | iKey2 = iKey1; |
| 84338 | 84378 | } |
| 84339 | 84379 | } |
| 84340 | 84380 | |
| 84381 | + assert( pCsr!=0 ); |
| 84382 | + assert( pCsr->eCurType==CURTYPE_BTREE ); |
| 84341 | 84383 | assert( pCsr->nField==pTab->nCol |
| 84342 | 84384 | || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1) |
| 84343 | 84385 | ); |
| 84344 | 84386 | |
| 84345 | 84387 | preupdate.v = v; |
| | @@ -84914,12 +84956,16 @@ |
| 84914 | 84956 | Mem *pOut = pCtx->pOut; |
| 84915 | 84957 | assert( sqlite3_mutex_held(pOut->db->mutex) ); |
| 84916 | 84958 | if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 84917 | 84959 | return SQLITE_TOOBIG; |
| 84918 | 84960 | } |
| 84961 | +#ifndef SQLITE_OMIT_INCRBLOB |
| 84919 | 84962 | sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n); |
| 84920 | 84963 | return SQLITE_OK; |
| 84964 | +#else |
| 84965 | + return sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n); |
| 84966 | +#endif |
| 84921 | 84967 | } |
| 84922 | 84968 | SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ |
| 84923 | 84969 | pCtx->isError = errCode ? errCode : -1; |
| 84924 | 84970 | #ifdef SQLITE_DEBUG |
| 84925 | 84971 | if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; |
| | @@ -85927,11 +85973,15 @@ |
| 85927 | 85973 | SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){ |
| 85928 | 85974 | int rc; |
| 85929 | 85975 | Vdbe *p = (Vdbe *)pStmt; |
| 85930 | 85976 | rc = vdbeUnbind(p, i); |
| 85931 | 85977 | if( rc==SQLITE_OK ){ |
| 85978 | +#ifndef SQLITE_OMIT_INCRBLOB |
| 85932 | 85979 | sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n); |
| 85980 | +#else |
| 85981 | + rc = sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n); |
| 85982 | +#endif |
| 85933 | 85983 | sqlite3_mutex_leave(p->db->mutex); |
| 85934 | 85984 | } |
| 85935 | 85985 | return rc; |
| 85936 | 85986 | } |
| 85937 | 85987 | SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt *pStmt, int i, sqlite3_uint64 n){ |
| | @@ -86215,10 +86265,11 @@ |
| 86215 | 86265 | /* If the old.* record has not yet been loaded into memory, do so now. */ |
| 86216 | 86266 | if( p->pUnpacked==0 ){ |
| 86217 | 86267 | u32 nRec; |
| 86218 | 86268 | u8 *aRec; |
| 86219 | 86269 | |
| 86270 | + assert( p->pCsr->eCurType==CURTYPE_BTREE ); |
| 86220 | 86271 | nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor); |
| 86221 | 86272 | aRec = sqlite3DbMallocRaw(db, nRec); |
| 86222 | 86273 | if( !aRec ) goto preupdate_old_out; |
| 86223 | 86274 | rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec); |
| 86224 | 86275 | if( rc==SQLITE_OK ){ |
| | @@ -90298,12 +90349,19 @@ |
| 90298 | 90349 | assert( p->readOnly==0 || pOp->p2==0 ); |
| 90299 | 90350 | assert( pOp->p2>=0 && pOp->p2<=2 ); |
| 90300 | 90351 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 90301 | 90352 | assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 90302 | 90353 | assert( rc==SQLITE_OK ); |
| 90303 | | - if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ |
| 90304 | | - rc = SQLITE_READONLY; |
| 90354 | + if( pOp->p2 && (db->flags & (SQLITE_QueryOnly|SQLITE_CorruptRdOnly))!=0 ){ |
| 90355 | + if( db->flags & SQLITE_QueryOnly ){ |
| 90356 | + /* Writes prohibited by the "PRAGMA query_only=TRUE" statement */ |
| 90357 | + rc = SQLITE_READONLY; |
| 90358 | + }else{ |
| 90359 | + /* Writes prohibited due to a prior SQLITE_CORRUPT in the current |
| 90360 | + ** transaction */ |
| 90361 | + rc = SQLITE_CORRUPT; |
| 90362 | + } |
| 90305 | 90363 | goto abort_due_to_error; |
| 90306 | 90364 | } |
| 90307 | 90365 | pBt = db->aDb[pOp->p1].pBt; |
| 90308 | 90366 | |
| 90309 | 90367 | if( pBt ){ |
| | @@ -94368,10 +94426,11 @@ |
| 94368 | 94426 | pQuery = &aMem[pOp->p3]; |
| 94369 | 94427 | pArgc = &pQuery[1]; |
| 94370 | 94428 | pCur = p->apCsr[pOp->p1]; |
| 94371 | 94429 | assert( memIsValid(pQuery) ); |
| 94372 | 94430 | REGISTER_TRACE(pOp->p3, pQuery); |
| 94431 | + assert( pCur!=0 ); |
| 94373 | 94432 | assert( pCur->eCurType==CURTYPE_VTAB ); |
| 94374 | 94433 | pVCur = pCur->uc.pVCur; |
| 94375 | 94434 | pVtab = pVCur->pVtab; |
| 94376 | 94435 | pModule = pVtab->pModule; |
| 94377 | 94436 | |
| | @@ -94416,10 +94475,11 @@ |
| 94416 | 94475 | const sqlite3_module *pModule; |
| 94417 | 94476 | Mem *pDest; |
| 94418 | 94477 | sqlite3_context sContext; |
| 94419 | 94478 | |
| 94420 | 94479 | VdbeCursor *pCur = p->apCsr[pOp->p1]; |
| 94480 | + assert( pCur!=0 ); |
| 94421 | 94481 | assert( pCur->eCurType==CURTYPE_VTAB ); |
| 94422 | 94482 | assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 94423 | 94483 | pDest = &aMem[pOp->p3]; |
| 94424 | 94484 | memAboutToChange(p, pDest); |
| 94425 | 94485 | if( pCur->nullRow ){ |
| | @@ -94469,10 +94529,11 @@ |
| 94469 | 94529 | const sqlite3_module *pModule; |
| 94470 | 94530 | int res; |
| 94471 | 94531 | VdbeCursor *pCur; |
| 94472 | 94532 | |
| 94473 | 94533 | pCur = p->apCsr[pOp->p1]; |
| 94534 | + assert( pCur!=0 ); |
| 94474 | 94535 | assert( pCur->eCurType==CURTYPE_VTAB ); |
| 94475 | 94536 | if( pCur->nullRow ){ |
| 94476 | 94537 | break; |
| 94477 | 94538 | } |
| 94478 | 94539 | pVtab = pCur->uc.pVCur->pVtab; |
| | @@ -94564,11 +94625,11 @@ |
| 94564 | 94625 | case OP_VUpdate: { |
| 94565 | 94626 | sqlite3_vtab *pVtab; |
| 94566 | 94627 | const sqlite3_module *pModule; |
| 94567 | 94628 | int nArg; |
| 94568 | 94629 | int i; |
| 94569 | | - sqlite_int64 rowid; |
| 94630 | + sqlite_int64 rowid = 0; |
| 94570 | 94631 | Mem **apArg; |
| 94571 | 94632 | Mem *pX; |
| 94572 | 94633 | |
| 94573 | 94634 | assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 94574 | 94635 | || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| | @@ -95011,11 +95072,18 @@ |
| 95011 | 95072 | rc = SQLITE_CORRUPT_BKPT; |
| 95012 | 95073 | } |
| 95013 | 95074 | assert( rc ); |
| 95014 | 95075 | #ifdef SQLITE_DEBUG |
| 95015 | 95076 | if( db->flags & SQLITE_VdbeTrace ){ |
| 95016 | | - printf("ABORT-due-to-error. rc=%d\n", rc); |
| 95077 | + const char *zTrace = p->zSql; |
| 95078 | + if( zTrace==0 ){ |
| 95079 | + if( aOp[0].opcode==OP_Trace ){ |
| 95080 | + zTrace = aOp[0].p4.z; |
| 95081 | + } |
| 95082 | + if( zTrace==0 ) zTrace = "???"; |
| 95083 | + } |
| 95084 | + printf("ABORT-due-to-error (rc=%d): %s\n", rc, zTrace); |
| 95017 | 95085 | } |
| 95018 | 95086 | #endif |
| 95019 | 95087 | if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){ |
| 95020 | 95088 | sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc)); |
| 95021 | 95089 | } |
| | @@ -95024,10 +95092,13 @@ |
| 95024 | 95092 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 95025 | 95093 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 95026 | 95094 | (int)(pOp - aOp), p->zSql, p->zErrMsg); |
| 95027 | 95095 | sqlite3VdbeHalt(p); |
| 95028 | 95096 | if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db); |
| 95097 | + if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){ |
| 95098 | + db->flags |= SQLITE_CorruptRdOnly; |
| 95099 | + } |
| 95029 | 95100 | rc = SQLITE_ERROR; |
| 95030 | 95101 | if( resetSchemaOnFault>0 ){ |
| 95031 | 95102 | sqlite3ResetOneSchema(db, resetSchemaOnFault-1); |
| 95032 | 95103 | } |
| 95033 | 95104 | |
| | @@ -95155,11 +95226,14 @@ |
| 95155 | 95226 | }else{ |
| 95156 | 95227 | rc = sqlite3_step(p->pStmt); |
| 95157 | 95228 | } |
| 95158 | 95229 | if( rc==SQLITE_ROW ){ |
| 95159 | 95230 | VdbeCursor *pC = v->apCsr[0]; |
| 95160 | | - u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0; |
| 95231 | + u32 type; |
| 95232 | + assert( pC!=0 ); |
| 95233 | + assert( pC->eCurType==CURTYPE_BTREE ); |
| 95234 | + type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0; |
| 95161 | 95235 | testcase( pC->nHdrParsed==p->iCol ); |
| 95162 | 95236 | testcase( pC->nHdrParsed==p->iCol+1 ); |
| 95163 | 95237 | if( type<12 ){ |
| 95164 | 95238 | zErr = sqlite3MPrintf(p->db, "cannot open value of type %s", |
| 95165 | 95239 | type==0?"null": type==7?"real": "integer" |
| | @@ -95500,10 +95574,12 @@ |
| 95500 | 95574 | ** using the incremental-blob API, this works. For the sessions module |
| 95501 | 95575 | ** anyhow. |
| 95502 | 95576 | */ |
| 95503 | 95577 | sqlite3_int64 iKey; |
| 95504 | 95578 | iKey = sqlite3BtreeIntegerKey(p->pCsr); |
| 95579 | + assert( v->apCsr[0]!=0 ); |
| 95580 | + assert( v->apCsr[0]->eCurType==CURTYPE_BTREE ); |
| 95505 | 95581 | sqlite3VdbePreUpdateHook( |
| 95506 | 95582 | v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol |
| 95507 | 95583 | ); |
| 95508 | 95584 | } |
| 95509 | 95585 | #endif |
| | @@ -100579,19 +100655,22 @@ |
| 100579 | 100655 | sqlite3WindowLink(pSel, pWin); |
| 100580 | 100656 | pNC->ncFlags |= NC_HasWin; |
| 100581 | 100657 | }else |
| 100582 | 100658 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 100583 | 100659 | { |
| 100584 | | - NameContext *pNC2 = pNC; |
| 100660 | + NameContext *pNC2; /* For looping up thru outer contexts */ |
| 100585 | 100661 | pExpr->op = TK_AGG_FUNCTION; |
| 100586 | 100662 | pExpr->op2 = 0; |
| 100587 | 100663 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 100588 | 100664 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 100589 | 100665 | sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter); |
| 100590 | 100666 | } |
| 100591 | 100667 | #endif |
| 100592 | | - while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){ |
| 100668 | + pNC2 = pNC; |
| 100669 | + while( pNC2 |
| 100670 | + && sqlite3ReferencesSrcList(pParse, pExpr, pNC2->pSrcList)==0 |
| 100671 | + ){ |
| 100593 | 100672 | pExpr->op2++; |
| 100594 | 100673 | pNC2 = pNC2->pNext; |
| 100595 | 100674 | } |
| 100596 | 100675 | assert( pDef!=0 || IN_RENAME_OBJECT ); |
| 100597 | 100676 | if( pNC2 && pDef ){ |
| | @@ -101557,12 +101636,12 @@ |
| 101557 | 101636 | |
| 101558 | 101637 | /* |
| 101559 | 101638 | ** Return the affinity character for a single column of a table. |
| 101560 | 101639 | */ |
| 101561 | 101640 | SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table *pTab, int iCol){ |
| 101562 | | - assert( iCol<pTab->nCol ); |
| 101563 | | - return iCol>=0 ? pTab->aCol[iCol].affinity : SQLITE_AFF_INTEGER; |
| 101641 | + if( iCol<0 || NEVER(iCol>=pTab->nCol) ) return SQLITE_AFF_INTEGER; |
| 101642 | + return pTab->aCol[iCol].affinity; |
| 101564 | 101643 | } |
| 101565 | 101644 | |
| 101566 | 101645 | /* |
| 101567 | 101646 | ** Return the 'affinity' of the expression pExpr if any. |
| 101568 | 101647 | ** |
| | @@ -104338,11 +104417,12 @@ |
| 104338 | 104417 | Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i); |
| 104339 | 104418 | Expr *pRhs = pEList->a[i].pExpr; |
| 104340 | 104419 | CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs); |
| 104341 | 104420 | int j; |
| 104342 | 104421 | |
| 104343 | | - assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr ); |
| 104422 | + assert( pReq!=0 || pRhs->iColumn==XN_ROWID |
| 104423 | + || pParse->nErr || db->mallocFailed ); |
| 104344 | 104424 | for(j=0; j<nExpr; j++){ |
| 104345 | 104425 | if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue; |
| 104346 | 104426 | assert( pIdx->azColl[j] ); |
| 104347 | 104427 | if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){ |
| 104348 | 104428 | continue; |
| | @@ -107414,93 +107494,128 @@ |
| 107414 | 107494 | sqlite3WalkExpr(&w, pExpr); |
| 107415 | 107495 | return !w.eCode; |
| 107416 | 107496 | } |
| 107417 | 107497 | |
| 107418 | 107498 | |
| 107419 | | -/* |
| 107420 | | -** An instance of the following structure is used by the tree walker |
| 107421 | | -** to count references to table columns in the arguments of an |
| 107422 | | -** aggregate function, in order to implement the |
| 107423 | | -** sqlite3FunctionThisSrc() routine. |
| 107499 | +/* Structure used to pass information throught the Walker in order to |
| 107500 | +** implement sqlite3ReferencesSrcList(). |
| 107424 | 107501 | */ |
| 107425 | | -struct SrcCount { |
| 107426 | | - SrcList *pSrc; /* One particular FROM clause in a nested query */ |
| 107427 | | - int iSrcInner; /* Smallest cursor number in this context */ |
| 107428 | | - int nThis; /* Number of references to columns in pSrcList */ |
| 107429 | | - int nOther; /* Number of references to columns in other FROM clauses */ |
| 107502 | +struct RefSrcList { |
| 107503 | + sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */ |
| 107504 | + SrcList *pRef; /* Looking for references to these tables */ |
| 107505 | + int nExclude; /* Number of tables to exclude from the search */ |
| 107506 | + int *aiExclude; /* Cursor IDs for tables to exclude from the search */ |
| 107430 | 107507 | }; |
| 107431 | 107508 | |
| 107432 | 107509 | /* |
| 107433 | | -** xSelect callback for sqlite3FunctionUsesThisSrc(). If this is the first |
| 107434 | | -** SELECT with a FROM clause encountered during this iteration, set |
| 107435 | | -** SrcCount.iSrcInner to the cursor number of the leftmost object in |
| 107436 | | -** the FROM cause. |
| 107510 | +** Walker SELECT callbacks for sqlite3ReferencesSrcList(). |
| 107511 | +** |
| 107512 | +** When entering a new subquery on the pExpr argument, add all FROM clause |
| 107513 | +** entries for that subquery to the exclude list. |
| 107514 | +** |
| 107515 | +** When leaving the subquery, remove those entries from the exclude list. |
| 107437 | 107516 | */ |
| 107438 | | -static int selectSrcCount(Walker *pWalker, Select *pSel){ |
| 107439 | | - struct SrcCount *p = pWalker->u.pSrcCount; |
| 107440 | | - if( p->iSrcInner==0x7FFFFFFF && ALWAYS(pSel->pSrc) && pSel->pSrc->nSrc ){ |
| 107441 | | - pWalker->u.pSrcCount->iSrcInner = pSel->pSrc->a[0].iCursor; |
| 107517 | +static int selectRefEnter(Walker *pWalker, Select *pSelect){ |
| 107518 | + struct RefSrcList *p = pWalker->u.pRefSrcList; |
| 107519 | + SrcList *pSrc = pSelect->pSrc; |
| 107520 | + int i, j, *piNew; |
| 107521 | + if( pSrc->nSrc==0 ) return WRC_Continue; |
| 107522 | + j = p->nExclude; |
| 107523 | + p->nExclude += pSrc->nSrc; |
| 107524 | + piNew = sqlite3DbRealloc(p->db, p->aiExclude, p->nExclude*sizeof(int)); |
| 107525 | + if( piNew==0 ){ |
| 107526 | + p->nExclude = 0; |
| 107527 | + return WRC_Abort; |
| 107528 | + }else{ |
| 107529 | + p->aiExclude = piNew; |
| 107530 | + } |
| 107531 | + for(i=0; i<pSrc->nSrc; i++, j++){ |
| 107532 | + p->aiExclude[j] = pSrc->a[i].iCursor; |
| 107442 | 107533 | } |
| 107443 | 107534 | return WRC_Continue; |
| 107444 | 107535 | } |
| 107445 | | - |
| 107446 | | -/* |
| 107447 | | -** Count the number of references to columns. |
| 107448 | | -*/ |
| 107449 | | -static int exprSrcCount(Walker *pWalker, Expr *pExpr){ |
| 107450 | | - /* There was once a NEVER() on the second term on the grounds that |
| 107451 | | - ** sqlite3FunctionUsesThisSrc() was always called before |
| 107452 | | - ** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet |
| 107453 | | - ** been converted into TK_AGG_COLUMN. But this is no longer true due |
| 107454 | | - ** to window functions - sqlite3WindowRewrite() may now indirectly call |
| 107455 | | - ** FunctionUsesThisSrc() when creating a new sub-select. */ |
| 107456 | | - if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){ |
| 107457 | | - int i; |
| 107458 | | - struct SrcCount *p = pWalker->u.pSrcCount; |
| 107459 | | - SrcList *pSrc = p->pSrc; |
| 107536 | +static void selectRefLeave(Walker *pWalker, Select *pSelect){ |
| 107537 | + struct RefSrcList *p = pWalker->u.pRefSrcList; |
| 107538 | + SrcList *pSrc = pSelect->pSrc; |
| 107539 | + if( p->nExclude ){ |
| 107540 | + assert( p->nExclude>=pSrc->nSrc ); |
| 107541 | + p->nExclude -= pSrc->nSrc; |
| 107542 | + } |
| 107543 | +} |
| 107544 | + |
| 107545 | +/* This is the Walker EXPR callback for sqlite3ReferencesSrcList(). |
| 107546 | +** |
| 107547 | +** Set the 0x01 bit of pWalker->eCode if there is a reference to any |
| 107548 | +** of the tables shown in RefSrcList.pRef. |
| 107549 | +** |
| 107550 | +** Set the 0x02 bit of pWalker->eCode if there is a reference to a |
| 107551 | +** table is in neither RefSrcList.pRef nor RefSrcList.aiExclude. |
| 107552 | +*/ |
| 107553 | +static int exprRefToSrcList(Walker *pWalker, Expr *pExpr){ |
| 107554 | + if( pExpr->op==TK_COLUMN |
| 107555 | + || pExpr->op==TK_AGG_COLUMN |
| 107556 | + ){ |
| 107557 | + int i; |
| 107558 | + struct RefSrcList *p = pWalker->u.pRefSrcList; |
| 107559 | + SrcList *pSrc = p->pRef; |
| 107460 | 107560 | int nSrc = pSrc ? pSrc->nSrc : 0; |
| 107461 | 107561 | for(i=0; i<nSrc; i++){ |
| 107462 | | - if( pExpr->iTable==pSrc->a[i].iCursor ) break; |
| 107463 | | - } |
| 107464 | | - if( i<nSrc ){ |
| 107465 | | - p->nThis++; |
| 107466 | | - }else if( pExpr->iTable<p->iSrcInner ){ |
| 107467 | | - /* In a well-formed parse tree (no name resolution errors), |
| 107468 | | - ** TK_COLUMN nodes with smaller Expr.iTable values are in an |
| 107469 | | - ** outer context. Those are the only ones to count as "other" */ |
| 107470 | | - p->nOther++; |
| 107562 | + if( pExpr->iTable==pSrc->a[i].iCursor ){ |
| 107563 | + pWalker->eCode |= 1; |
| 107564 | + return WRC_Continue; |
| 107565 | + } |
| 107566 | + } |
| 107567 | + for(i=0; i<p->nExclude && p->aiExclude[i]!=pExpr->iTable; i++){} |
| 107568 | + if( i>=p->nExclude ){ |
| 107569 | + pWalker->eCode |= 2; |
| 107471 | 107570 | } |
| 107472 | 107571 | } |
| 107473 | 107572 | return WRC_Continue; |
| 107474 | 107573 | } |
| 107475 | 107574 | |
| 107476 | 107575 | /* |
| 107477 | | -** Determine if any of the arguments to the pExpr Function reference |
| 107478 | | -** pSrcList. Return true if they do. Also return true if the function |
| 107479 | | -** has no arguments or has only constant arguments. Return false if pExpr |
| 107480 | | -** references columns but not columns of tables found in pSrcList. |
| 107576 | +** Check to see if pExpr references any tables in pSrcList. |
| 107577 | +** Possible return values: |
| 107578 | +** |
| 107579 | +** 1 pExpr does references a table in pSrcList. |
| 107580 | +** |
| 107581 | +** 0 pExpr references some table that is not defined in either |
| 107582 | +** pSrcList or in subqueries of pExpr itself. |
| 107583 | +** |
| 107584 | +** -1 pExpr only references no tables at all, or it only |
| 107585 | +** references tables defined in subqueries of pExpr itself. |
| 107586 | +** |
| 107587 | +** As currently used, pExpr is always an aggregate function call. That |
| 107588 | +** fact is exploited for efficiency. |
| 107481 | 107589 | */ |
| 107482 | | -SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *pExpr, SrcList *pSrcList){ |
| 107590 | +SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList *pSrcList){ |
| 107483 | 107591 | Walker w; |
| 107484 | | - struct SrcCount cnt; |
| 107485 | | - assert( pExpr->op==TK_AGG_FUNCTION ); |
| 107592 | + struct RefSrcList x; |
| 107486 | 107593 | memset(&w, 0, sizeof(w)); |
| 107487 | | - w.xExprCallback = exprSrcCount; |
| 107488 | | - w.xSelectCallback = selectSrcCount; |
| 107489 | | - w.u.pSrcCount = &cnt; |
| 107490 | | - cnt.pSrc = pSrcList; |
| 107491 | | - cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF; |
| 107492 | | - cnt.nThis = 0; |
| 107493 | | - cnt.nOther = 0; |
| 107594 | + memset(&x, 0, sizeof(x)); |
| 107595 | + w.xExprCallback = exprRefToSrcList; |
| 107596 | + w.xSelectCallback = selectRefEnter; |
| 107597 | + w.xSelectCallback2 = selectRefLeave; |
| 107598 | + w.u.pRefSrcList = &x; |
| 107599 | + x.db = pParse->db; |
| 107600 | + x.pRef = pSrcList; |
| 107601 | + assert( pExpr->op==TK_AGG_FUNCTION ); |
| 107494 | 107602 | assert( ExprUseXList(pExpr) ); |
| 107495 | 107603 | sqlite3WalkExprList(&w, pExpr->x.pList); |
| 107496 | 107604 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 107497 | 107605 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 107498 | 107606 | sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter); |
| 107499 | 107607 | } |
| 107500 | 107608 | #endif |
| 107501 | | - return cnt.nThis>0 || cnt.nOther==0; |
| 107609 | + sqlite3DbFree(pParse->db, x.aiExclude); |
| 107610 | + if( w.eCode & 0x01 ){ |
| 107611 | + return 1; |
| 107612 | + }else if( w.eCode ){ |
| 107613 | + return 0; |
| 107614 | + }else{ |
| 107615 | + return -1; |
| 107616 | + } |
| 107502 | 107617 | } |
| 107503 | 107618 | |
| 107504 | 107619 | /* |
| 107505 | 107620 | ** This is a Walker expression node callback. |
| 107506 | 107621 | ** |
| | @@ -115414,10 +115529,11 @@ |
| 115414 | 115529 | |
| 115415 | 115530 | assert( IsVirtual(pTab) ); |
| 115416 | 115531 | pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]); |
| 115417 | 115532 | if( pMod==0 ) return; |
| 115418 | 115533 | if( NEVER(pMod->pModule==0) ) return; |
| 115534 | + if( pMod->pModule->iVersion<3 ) return; |
| 115419 | 115535 | if( pMod->pModule->xShadowName==0 ) return; |
| 115420 | 115536 | assert( pTab->zName!=0 ); |
| 115421 | 115537 | nName = sqlite3Strlen30(pTab->zName); |
| 115422 | 115538 | for(k=sqliteHashFirst(&pTab->pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 115423 | 115539 | Table *pOther = sqliteHashData(k); |
| | @@ -116321,10 +116437,13 @@ |
| 116321 | 116437 | if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0; |
| 116322 | 116438 | return 1; |
| 116323 | 116439 | } |
| 116324 | 116440 | if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){ |
| 116325 | 116441 | return 1; |
| 116442 | + } |
| 116443 | + if( pTab->tabFlags & TF_Eponymous ){ |
| 116444 | + return 1; |
| 116326 | 116445 | } |
| 116327 | 116446 | return 0; |
| 116328 | 116447 | } |
| 116329 | 116448 | |
| 116330 | 116449 | /* |
| | @@ -127801,11 +127920,11 @@ |
| 127801 | 127920 | /* Version 3.34.0 and later */ |
| 127802 | 127921 | #define sqlite3_txn_state sqlite3_api->txn_state |
| 127803 | 127922 | /* Version 3.36.1 and later */ |
| 127804 | 127923 | #define sqlite3_changes64 sqlite3_api->changes64 |
| 127805 | 127924 | #define sqlite3_total_changes64 sqlite3_api->total_changes64 |
| 127806 | | -* Version 3.37.0 and later */ |
| 127925 | +/* Version 3.37.0 and later */ |
| 127807 | 127926 | #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages |
| 127808 | 127927 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 127809 | 127928 | |
| 127810 | 127929 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 127811 | 127930 | /* This case when the file really is being compiled as a loadable |
| | @@ -135298,10 +135417,13 @@ |
| 135298 | 135417 | n = sqlite3Strlen30(pCol->zCnName); |
| 135299 | 135418 | pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2); |
| 135300 | 135419 | if( pCol->zCnName ){ |
| 135301 | 135420 | memcpy(&pCol->zCnName[n+1], zType, m+1); |
| 135302 | 135421 | pCol->colFlags |= COLFLAG_HASTYPE; |
| 135422 | + }else{ |
| 135423 | + testcase( pCol->colFlags & COLFLAG_HASTYPE ); |
| 135424 | + pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL); |
| 135303 | 135425 | } |
| 135304 | 135426 | } |
| 135305 | 135427 | if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff; |
| 135306 | 135428 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 135307 | 135429 | if( pColl ){ |
| | @@ -138037,31 +138159,44 @@ |
| 138037 | 138159 | ** |
| 138038 | 138160 | ** SELECT count(*) FROM <tbl> |
| 138039 | 138161 | ** |
| 138040 | 138162 | ** where table is a database table, not a sub-select or view. If the query |
| 138041 | 138163 | ** does match this pattern, then a pointer to the Table object representing |
| 138042 | | -** <tbl> is returned. Otherwise, 0 is returned. |
| 138164 | +** <tbl> is returned. Otherwise, NULL is returned. |
| 138165 | +** |
| 138166 | +** This routine a condition for the count optimization. A correct answer |
| 138167 | +** is obtained (though perhaps more slowly) if this routine returns NULL when |
| 138168 | +** it could have returned a table pointer. But returning the pointer when |
| 138169 | +** NULL should have been returned can result in incorrect answers and/or |
| 138170 | +** crashes. So, when in doubt, return NULL. |
| 138043 | 138171 | */ |
| 138044 | 138172 | static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){ |
| 138045 | 138173 | Table *pTab; |
| 138046 | 138174 | Expr *pExpr; |
| 138047 | 138175 | |
| 138048 | 138176 | assert( !p->pGroupBy ); |
| 138049 | 138177 | |
| 138050 | | - if( p->pWhere || p->pEList->nExpr!=1 |
| 138051 | | - || p->pSrc->nSrc!=1 || p->pSrc->a[0].pSelect |
| 138178 | + if( p->pWhere |
| 138179 | + || p->pEList->nExpr!=1 |
| 138180 | + || p->pSrc->nSrc!=1 |
| 138181 | + || p->pSrc->a[0].pSelect |
| 138182 | + || pAggInfo->nFunc!=1 |
| 138052 | 138183 | ){ |
| 138053 | 138184 | return 0; |
| 138054 | 138185 | } |
| 138055 | 138186 | pTab = p->pSrc->a[0].pTab; |
| 138187 | + assert( pTab!=0 ); |
| 138188 | + assert( !IsView(pTab) ); |
| 138189 | + if( !IsOrdinaryTable(pTab) ) return 0; |
| 138056 | 138190 | pExpr = p->pEList->a[0].pExpr; |
| 138057 | | - assert( pTab && !IsView(pTab) && pExpr ); |
| 138058 | | - |
| 138059 | | - if( IsVirtual(pTab) ) return 0; |
| 138191 | + assert( pExpr!=0 ); |
| 138060 | 138192 | if( pExpr->op!=TK_AGG_FUNCTION ) return 0; |
| 138061 | | - if( NEVER(pAggInfo->nFunc==0) ) return 0; |
| 138193 | + if( pExpr->pAggInfo!=pAggInfo ) return 0; |
| 138062 | 138194 | if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0; |
| 138195 | + assert( pAggInfo->aFunc[0].pFExpr==pExpr ); |
| 138196 | + testcase( ExprHasProperty(pExpr, EP_Distinct) ); |
| 138197 | + testcase( ExprHasProperty(pExpr, EP_WinFunc) ); |
| 138063 | 138198 | if( ExprHasProperty(pExpr, EP_Distinct|EP_WinFunc) ) return 0; |
| 138064 | 138199 | |
| 138065 | 138200 | return pTab; |
| 138066 | 138201 | } |
| 138067 | 138202 | |
| | @@ -145189,11 +145324,14 @@ |
| 145189 | 145324 | SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ |
| 145190 | 145325 | int rc = SQLITE_OK; |
| 145191 | 145326 | Table *pTab; |
| 145192 | 145327 | |
| 145193 | 145328 | pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); |
| 145194 | | - if( pTab!=0 && ALWAYS(IsVirtual(pTab)) && ALWAYS(pTab->u.vtab.p!=0) ){ |
| 145329 | + if( ALWAYS(pTab!=0) |
| 145330 | + && ALWAYS(IsVirtual(pTab)) |
| 145331 | + && ALWAYS(pTab->u.vtab.p!=0) |
| 145332 | + ){ |
| 145195 | 145333 | VTable *p; |
| 145196 | 145334 | int (*xDestroy)(sqlite3_vtab *); |
| 145197 | 145335 | for(p=pTab->u.vtab.p; p; p=p->pNext){ |
| 145198 | 145336 | assert( p->pVtab ); |
| 145199 | 145337 | if( p->pVtab->nRef>0 ){ |
| | @@ -155813,10 +155951,11 @@ |
| 155813 | 155951 | ** program. |
| 155814 | 155952 | */ |
| 155815 | 155953 | for(ii=0; ii<nTabList; ii++){ |
| 155816 | 155954 | int addrExplain; |
| 155817 | 155955 | int wsFlags; |
| 155956 | + if( pParse->nErr ) goto whereBeginError; |
| 155818 | 155957 | pLevel = &pWInfo->a[ii]; |
| 155819 | 155958 | wsFlags = pLevel->pWLoop->wsFlags; |
| 155820 | 155959 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 155821 | 155960 | if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 155822 | 155961 | constructAutomaticIndex(pParse, &pWInfo->sWC, |
| | @@ -157266,11 +157405,15 @@ |
| 157266 | 157405 | } |
| 157267 | 157406 | }else{ |
| 157268 | 157407 | sqlite3SelectDelete(db, pSub); |
| 157269 | 157408 | } |
| 157270 | 157409 | if( db->mallocFailed ) rc = SQLITE_NOMEM; |
| 157271 | | - sqlite3DbFree(db, pTab); |
| 157410 | + |
| 157411 | + /* Defer deleting the temporary table pTab because if an error occurred, |
| 157412 | + ** there could still be references to that table embedded in the |
| 157413 | + ** result-set or ORDER BY clause of the SELECT statement p. */ |
| 157414 | + sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab); |
| 157272 | 157415 | } |
| 157273 | 157416 | |
| 157274 | 157417 | if( rc ){ |
| 157275 | 157418 | if( pParse->nErr==0 ){ |
| 157276 | 157419 | assert( pParse->db->mallocFailed ); |
| | @@ -160713,13 +160856,13 @@ |
| 160713 | 160856 | yyStackEntry *yystackEnd; /* Last entry in the stack */ |
| 160714 | 160857 | #endif |
| 160715 | 160858 | }; |
| 160716 | 160859 | typedef struct yyParser yyParser; |
| 160717 | 160860 | |
| 160861 | +/* #include <assert.h> */ |
| 160718 | 160862 | #ifndef NDEBUG |
| 160719 | 160863 | /* #include <stdio.h> */ |
| 160720 | | -/* #include <assert.h> */ |
| 160721 | 160864 | static FILE *yyTraceFILE = 0; |
| 160722 | 160865 | static char *yyTracePrompt = 0; |
| 160723 | 160866 | #endif /* NDEBUG */ |
| 160724 | 160867 | |
| 160725 | 160868 | #ifndef NDEBUG |
| | @@ -164464,12 +164607,12 @@ |
| 164464 | 164607 | assert( yypParser->yytos>=yypParser->yystack ); |
| 164465 | 164608 | assert( yyact==yypParser->yytos->stateno ); |
| 164466 | 164609 | yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); |
| 164467 | 164610 | if( yyact >= YY_MIN_REDUCE ){ |
| 164468 | 164611 | unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */ |
| 164469 | | - assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); |
| 164470 | 164612 | #ifndef NDEBUG |
| 164613 | + assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); |
| 164471 | 164614 | if( yyTraceFILE ){ |
| 164472 | 164615 | int yysize = yyRuleInfoNRhs[yyruleno]; |
| 164473 | 164616 | if( yysize ){ |
| 164474 | 164617 | fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", |
| 164475 | 164618 | yyTracePrompt, |
| | @@ -167854,11 +167997,11 @@ |
| 167854 | 167997 | sqlite3BtreeLeaveAll(db); |
| 167855 | 167998 | |
| 167856 | 167999 | /* Any deferred constraint violations have now been resolved. */ |
| 167857 | 168000 | db->nDeferredCons = 0; |
| 167858 | 168001 | db->nDeferredImmCons = 0; |
| 167859 | | - db->flags &= ~(u64)SQLITE_DeferFKs; |
| 168002 | + db->flags &= ~(u64)(SQLITE_DeferFKs|SQLITE_CorruptRdOnly); |
| 167860 | 168003 | |
| 167861 | 168004 | /* If one has been configured, invoke the rollback-hook callback */ |
| 167862 | 168005 | if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){ |
| 167863 | 168006 | db->xRollbackCallback(db->pRollbackArg); |
| 167864 | 168007 | } |
| | @@ -169582,12 +169725,12 @@ |
| 169582 | 169725 | ** |
| 169583 | 169726 | ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were |
| 169584 | 169727 | ** dealt with in the previous code block. Besides these, the only |
| 169585 | 169728 | ** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY, |
| 169586 | 169729 | ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE, |
| 169587 | | - ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask |
| 169588 | | - ** off all other flags. |
| 169730 | + ** SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_EXRESCODE, and some reserved |
| 169731 | + ** bits. Silently mask off all other flags. |
| 169589 | 169732 | */ |
| 169590 | 169733 | flags &= ~( SQLITE_OPEN_DELETEONCLOSE | |
| 169591 | 169734 | SQLITE_OPEN_EXCLUSIVE | |
| 169592 | 169735 | SQLITE_OPEN_MAIN_DB | |
| 169593 | 169736 | SQLITE_OPEN_TEMP_DB | |
| | @@ -169618,11 +169761,11 @@ |
| 169618 | 169761 | if( isThreadsafe==0 ){ |
| 169619 | 169762 | sqlite3MutexWarnOnContention(db->mutex); |
| 169620 | 169763 | } |
| 169621 | 169764 | } |
| 169622 | 169765 | sqlite3_mutex_enter(db->mutex); |
| 169623 | | - db->errMask = 0xff; |
| 169766 | + db->errMask = (flags & SQLITE_OPEN_EXRESCODE)!=0 ? 0xffffffff : 0xff; |
| 169624 | 169767 | db->nDb = 2; |
| 169625 | 169768 | db->eOpenState = SQLITE_STATE_BUSY; |
| 169626 | 169769 | db->aDb = db->aDbStatic; |
| 169627 | 169770 | db->lookaside.bDisable = 1; |
| 169628 | 169771 | db->lookaside.sz = 0; |
| | @@ -169850,12 +169993,12 @@ |
| 169850 | 169993 | assert( db->mutex!=0 || isThreadsafe==0 |
| 169851 | 169994 | || sqlite3GlobalConfig.bFullMutex==0 ); |
| 169852 | 169995 | sqlite3_mutex_leave(db->mutex); |
| 169853 | 169996 | } |
| 169854 | 169997 | rc = sqlite3_errcode(db); |
| 169855 | | - assert( db!=0 || rc==SQLITE_NOMEM ); |
| 169856 | | - if( rc==SQLITE_NOMEM ){ |
| 169998 | + assert( db!=0 || (rc&0xff)==SQLITE_NOMEM ); |
| 169999 | + if( (rc&0xff)==SQLITE_NOMEM ){ |
| 169857 | 170000 | sqlite3_close(db); |
| 169858 | 170001 | db = 0; |
| 169859 | 170002 | }else if( rc!=SQLITE_OK ){ |
| 169860 | 170003 | db->eOpenState = SQLITE_STATE_SICK; |
| 169861 | 170004 | } |
| | @@ -169866,11 +170009,11 @@ |
| 169866 | 170009 | void *pArg = sqlite3GlobalConfig.pSqllogArg; |
| 169867 | 170010 | sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); |
| 169868 | 170011 | } |
| 169869 | 170012 | #endif |
| 169870 | 170013 | sqlite3_free_filename(zOpen); |
| 169871 | | - return rc & 0xff; |
| 170014 | + return rc; |
| 169872 | 170015 | } |
| 169873 | 170016 | |
| 169874 | 170017 | |
| 169875 | 170018 | /* |
| 169876 | 170019 | ** Open a new database handle. |
| | @@ -178416,10 +178559,13 @@ |
| 178416 | 178559 | while( rc==SQLITE_OK && !pNear->bEof ){ |
| 178417 | 178560 | fts3EvalNextRow(pCsr, pNear, &rc); |
| 178418 | 178561 | if( bEofSave==0 && pNear->iDocid==iDocid ) break; |
| 178419 | 178562 | } |
| 178420 | 178563 | assert( rc!=SQLITE_OK || pPhrase->bIncr==0 ); |
| 178564 | + if( rc==SQLITE_OK && pNear->bEof!=bEofSave ){ |
| 178565 | + rc = FTS_CORRUPT_VTAB; |
| 178566 | + } |
| 178421 | 178567 | } |
| 178422 | 178568 | if( bTreeEof ){ |
| 178423 | 178569 | while( rc==SQLITE_OK && !pNear->bEof ){ |
| 178424 | 178570 | fts3EvalNextRow(pCsr, pNear, &rc); |
| 178425 | 178571 | } |
| | @@ -190106,17 +190252,17 @@ |
| 190106 | 190252 | int iEnd = 0; |
| 190107 | 190253 | int iCurrent = 0; |
| 190108 | 190254 | const char *zDoc; |
| 190109 | 190255 | int nDoc; |
| 190110 | 190256 | |
| 190111 | | - /* Initialize the contents of sCtx.aTerm[] for column iCol. There is |
| 190112 | | - ** no way that this operation can fail, so the return code from |
| 190113 | | - ** fts3ExprIterate() can be discarded. |
| 190257 | + /* Initialize the contents of sCtx.aTerm[] for column iCol. This |
| 190258 | + ** operation may fail if the database contains corrupt records. |
| 190114 | 190259 | */ |
| 190115 | 190260 | sCtx.iCol = iCol; |
| 190116 | 190261 | sCtx.iTerm = 0; |
| 190117 | | - (void)fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx); |
| 190262 | + rc = fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx); |
| 190263 | + if( rc!=SQLITE_OK ) goto offsets_out; |
| 190118 | 190264 | |
| 190119 | 190265 | /* Retreive the text stored in column iCol. If an SQL NULL is stored |
| 190120 | 190266 | ** in column iCol, jump immediately to the next iteration of the loop. |
| 190121 | 190267 | ** If an OOM occurs while retrieving the data (this can happen if SQLite |
| 190122 | 190268 | ** needs to transform the data from utf-16 to utf-8), return SQLITE_NOMEM |
| | @@ -192676,12 +192822,15 @@ |
| 192676 | 192822 | }else{ |
| 192677 | 192823 | JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]); |
| 192678 | 192824 | if( pNew==0 ) return 0; |
| 192679 | 192825 | pTarget = &pParse->aNode[iTarget]; |
| 192680 | 192826 | if( pNew!=&pTarget[j+1] ){ |
| 192681 | | - assert( pTarget[j+1].eU==0 || pTarget[j+1].eU==1 ); |
| 192827 | + assert( pTarget[j+1].eU==0 |
| 192828 | + || pTarget[j+1].eU==1 |
| 192829 | + || pTarget[j+1].eU==2 ); |
| 192682 | 192830 | testcase( pTarget[j+1].eU==1 ); |
| 192831 | + testcase( pTarget[j+1].eU==2 ); |
| 192683 | 192832 | VVA( pTarget[j+1].eU = 5 ); |
| 192684 | 192833 | pTarget[j+1].u.pPatch = pNew; |
| 192685 | 192834 | pTarget[j+1].jnFlags |= JNODE_PATCH; |
| 192686 | 192835 | } |
| 192687 | 192836 | } |
| | @@ -201672,10 +201821,17 @@ |
| 201672 | 201821 | ** Swap two objects of type TYPE. |
| 201673 | 201822 | */ |
| 201674 | 201823 | #if !defined(SQLITE_AMALGAMATION) |
| 201675 | 201824 | # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} |
| 201676 | 201825 | #endif |
| 201826 | + |
| 201827 | +/* |
| 201828 | +** Name of the URI option that causes RBU to take an exclusive lock as |
| 201829 | +** part of the incremental checkpoint operation. |
| 201830 | +*/ |
| 201831 | +#define RBU_EXCLUSIVE_CHECKPOINT "rbu_exclusive_checkpoint" |
| 201832 | + |
| 201677 | 201833 | |
| 201678 | 201834 | /* |
| 201679 | 201835 | ** The rbu_state table is used to save the state of a partially applied |
| 201680 | 201836 | ** update so that it can be resumed later. The table consists of integer |
| 201681 | 201837 | ** keys mapped to values as follows: |
| | @@ -204319,17 +204475,23 @@ |
| 204319 | 204475 | |
| 204320 | 204476 | |
| 204321 | 204477 | /* |
| 204322 | 204478 | ** Open the database handle and attach the RBU database as "rbu". If an |
| 204323 | 204479 | ** error occurs, leave an error code and message in the RBU handle. |
| 204480 | +** |
| 204481 | +** If argument dbMain is not NULL, then it is a database handle already |
| 204482 | +** open on the target database. Use this handle instead of opening a new |
| 204483 | +** one. |
| 204324 | 204484 | */ |
| 204325 | | -static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){ |
| 204485 | +static void rbuOpenDatabase(sqlite3rbu *p, sqlite3 *dbMain, int *pbRetry){ |
| 204326 | 204486 | assert( p->rc || (p->dbMain==0 && p->dbRbu==0) ); |
| 204327 | 204487 | assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 ); |
| 204488 | + assert( dbMain==0 || rbuIsVacuum(p)==0 ); |
| 204328 | 204489 | |
| 204329 | 204490 | /* Open the RBU database */ |
| 204330 | 204491 | p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1); |
| 204492 | + p->dbMain = dbMain; |
| 204331 | 204493 | |
| 204332 | 204494 | if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){ |
| 204333 | 204495 | sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p); |
| 204334 | 204496 | if( p->zState==0 ){ |
| 204335 | 204497 | const char *zFile = sqlite3_db_filename(p->dbRbu, "main"); |
| | @@ -204691,19 +204853,35 @@ |
| 204691 | 204853 | p->rc = pDb->pMethods->xWrite(pDb, p->aBuf, p->pgsz, iOff); |
| 204692 | 204854 | } |
| 204693 | 204855 | |
| 204694 | 204856 | |
| 204695 | 204857 | /* |
| 204696 | | -** Take an EXCLUSIVE lock on the database file. |
| 204858 | +** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if |
| 204859 | +** successful, or an SQLite error code otherwise. |
| 204697 | 204860 | */ |
| 204698 | | -static void rbuLockDatabase(sqlite3rbu *p){ |
| 204699 | | - sqlite3_file *pReal = p->pTargetFd->pReal; |
| 204700 | | - assert( p->rc==SQLITE_OK ); |
| 204701 | | - p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED); |
| 204702 | | - if( p->rc==SQLITE_OK ){ |
| 204703 | | - p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE); |
| 204861 | +static int rbuLockDatabase(sqlite3 *db){ |
| 204862 | + int rc = SQLITE_OK; |
| 204863 | + sqlite3_file *fd = 0; |
| 204864 | + sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd); |
| 204865 | + |
| 204866 | + if( fd->pMethods ){ |
| 204867 | + rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED); |
| 204868 | + if( rc==SQLITE_OK ){ |
| 204869 | + rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE); |
| 204870 | + } |
| 204704 | 204871 | } |
| 204872 | + return rc; |
| 204873 | +} |
| 204874 | + |
| 204875 | +/* |
| 204876 | +** Return true if the database handle passed as the only argument |
| 204877 | +** was opened with the rbu_exclusive_checkpoint=1 URI parameter |
| 204878 | +** specified. Or false otherwise. |
| 204879 | +*/ |
| 204880 | +static int rbuExclusiveCheckpoint(sqlite3 *db){ |
| 204881 | + const char *zUri = sqlite3_db_filename(db, 0); |
| 204882 | + return sqlite3_uri_boolean(zUri, RBU_EXCLUSIVE_CHECKPOINT, 0); |
| 204705 | 204883 | } |
| 204706 | 204884 | |
| 204707 | 204885 | #if defined(_WIN32_WCE) |
| 204708 | 204886 | static LPWSTR rbuWinUtf8ToUnicode(const char *zFilename){ |
| 204709 | 204887 | int nChar; |
| | @@ -204757,22 +204935,28 @@ |
| 204757 | 204935 | ** in WAL mode). So no other connection may be writing the db. |
| 204758 | 204936 | ** |
| 204759 | 204937 | ** In order to ensure that there are no database readers, an EXCLUSIVE |
| 204760 | 204938 | ** lock is obtained here before the *-oal is moved to *-wal. |
| 204761 | 204939 | */ |
| 204762 | | - rbuLockDatabase(p); |
| 204940 | + sqlite3 *dbMain = 0; |
| 204941 | + rbuFileSuffix3(zBase, zWal); |
| 204942 | + rbuFileSuffix3(zBase, zOal); |
| 204943 | + |
| 204944 | + /* Re-open the databases. */ |
| 204945 | + rbuObjIterFinalize(&p->objiter); |
| 204946 | + sqlite3_close(p->dbRbu); |
| 204947 | + sqlite3_close(p->dbMain); |
| 204948 | + p->dbMain = 0; |
| 204949 | + p->dbRbu = 0; |
| 204950 | + |
| 204951 | + dbMain = rbuOpenDbhandle(p, p->zTarget, 1); |
| 204952 | + if( dbMain ){ |
| 204953 | + assert( p->rc==SQLITE_OK ); |
| 204954 | + p->rc = rbuLockDatabase(dbMain); |
| 204955 | + } |
| 204956 | + |
| 204763 | 204957 | if( p->rc==SQLITE_OK ){ |
| 204764 | | - rbuFileSuffix3(zBase, zWal); |
| 204765 | | - rbuFileSuffix3(zBase, zOal); |
| 204766 | | - |
| 204767 | | - /* Re-open the databases. */ |
| 204768 | | - rbuObjIterFinalize(&p->objiter); |
| 204769 | | - sqlite3_close(p->dbRbu); |
| 204770 | | - sqlite3_close(p->dbMain); |
| 204771 | | - p->dbMain = 0; |
| 204772 | | - p->dbRbu = 0; |
| 204773 | | - |
| 204774 | 204958 | #if defined(_WIN32_WCE) |
| 204775 | 204959 | { |
| 204776 | 204960 | LPWSTR zWideOal; |
| 204777 | 204961 | LPWSTR zWideWal; |
| 204778 | 204962 | |
| | @@ -204795,15 +204979,23 @@ |
| 204795 | 204979 | } |
| 204796 | 204980 | } |
| 204797 | 204981 | #else |
| 204798 | 204982 | p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; |
| 204799 | 204983 | #endif |
| 204984 | + } |
| 204800 | 204985 | |
| 204801 | | - if( p->rc==SQLITE_OK ){ |
| 204802 | | - rbuOpenDatabase(p, 0); |
| 204803 | | - rbuSetupCheckpoint(p, 0); |
| 204804 | | - } |
| 204986 | + if( p->rc!=SQLITE_OK |
| 204987 | + || rbuIsVacuum(p) |
| 204988 | + || rbuExclusiveCheckpoint(dbMain)==0 |
| 204989 | + ){ |
| 204990 | + sqlite3_close(dbMain); |
| 204991 | + dbMain = 0; |
| 204992 | + } |
| 204993 | + |
| 204994 | + if( p->rc==SQLITE_OK ){ |
| 204995 | + rbuOpenDatabase(p, dbMain, 0); |
| 204996 | + rbuSetupCheckpoint(p, 0); |
| 204805 | 204997 | } |
| 204806 | 204998 | } |
| 204807 | 204999 | |
| 204808 | 205000 | sqlite3_free(zWal); |
| 204809 | 205001 | sqlite3_free(zOal); |
| | @@ -205550,13 +205742,13 @@ |
| 205550 | 205742 | ** to be a wal-mode db. But, this may have happened due to an earlier |
| 205551 | 205743 | ** RBU vacuum operation leaving an old wal file in the directory. |
| 205552 | 205744 | ** If this is the case, it will have been checkpointed and deleted |
| 205553 | 205745 | ** when the handle was closed and a second attempt to open the |
| 205554 | 205746 | ** database may succeed. */ |
| 205555 | | - rbuOpenDatabase(p, &bRetry); |
| 205747 | + rbuOpenDatabase(p, 0, &bRetry); |
| 205556 | 205748 | if( bRetry ){ |
| 205557 | | - rbuOpenDatabase(p, 0); |
| 205749 | + rbuOpenDatabase(p, 0, 0); |
| 205558 | 205750 | } |
| 205559 | 205751 | } |
| 205560 | 205752 | |
| 205561 | 205753 | if( p->rc==SQLITE_OK ){ |
| 205562 | 205754 | pState = rbuLoadState(p); |
| | @@ -205647,10 +205839,18 @@ |
| 205647 | 205839 | } |
| 205648 | 205840 | } |
| 205649 | 205841 | }else if( p->eStage==RBU_STAGE_MOVE ){ |
| 205650 | 205842 | /* no-op */ |
| 205651 | 205843 | }else if( p->eStage==RBU_STAGE_CKPT ){ |
| 205844 | + if( !rbuIsVacuum(p) && rbuExclusiveCheckpoint(p->dbMain) ){ |
| 205845 | + /* If the rbu_exclusive_checkpoint=1 URI parameter was specified |
| 205846 | + ** and an incremental checkpoint is being resumed, attempt an |
| 205847 | + ** exclusive lock on the db file. If this fails, so be it. */ |
| 205848 | + p->eStage = RBU_STAGE_DONE; |
| 205849 | + rbuLockDatabase(p->dbMain); |
| 205850 | + p->eStage = RBU_STAGE_CKPT; |
| 205851 | + } |
| 205652 | 205852 | rbuSetupCheckpoint(p, pState); |
| 205653 | 205853 | }else if( p->eStage==RBU_STAGE_DONE ){ |
| 205654 | 205854 | p->rc = SQLITE_DONE; |
| 205655 | 205855 | }else{ |
| 205656 | 205856 | p->rc = SQLITE_CORRUPT; |
| | @@ -205684,11 +205884,10 @@ |
| 205684 | 205884 | const char *zTarget, |
| 205685 | 205885 | const char *zRbu, |
| 205686 | 205886 | const char *zState |
| 205687 | 205887 | ){ |
| 205688 | 205888 | if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); } |
| 205689 | | - /* TODO: Check that zTarget and zRbu are non-NULL */ |
| 205690 | 205889 | return openRbuHandle(zTarget, zRbu, zState); |
| 205691 | 205890 | } |
| 205692 | 205891 | |
| 205693 | 205892 | /* |
| 205694 | 205893 | ** Open a handle to begin or resume an RBU VACUUM operation. |
| | @@ -215805,13 +216004,13 @@ |
| 215805 | 216004 | fts5yyStackEntry *fts5yystackEnd; /* Last entry in the stack */ |
| 215806 | 216005 | #endif |
| 215807 | 216006 | }; |
| 215808 | 216007 | typedef struct fts5yyParser fts5yyParser; |
| 215809 | 216008 | |
| 215810 | | -#ifndef NDEBUG |
| 215811 | | -/* #include <stdio.h> */ |
| 215812 | 216009 | /* #include <assert.h> */ |
| 216010 | +#ifndef NDEBUG |
| 216011 | +/* #include <stdio.h> */ |
| 215813 | 216012 | static FILE *fts5yyTraceFILE = 0; |
| 215814 | 216013 | static char *fts5yyTracePrompt = 0; |
| 215815 | 216014 | #endif /* NDEBUG */ |
| 215816 | 216015 | |
| 215817 | 216016 | #ifndef NDEBUG |
| | @@ -216744,12 +216943,12 @@ |
| 216744 | 216943 | assert( fts5yypParser->fts5yytos>=fts5yypParser->fts5yystack ); |
| 216745 | 216944 | assert( fts5yyact==fts5yypParser->fts5yytos->stateno ); |
| 216746 | 216945 | fts5yyact = fts5yy_find_shift_action((fts5YYCODETYPE)fts5yymajor,fts5yyact); |
| 216747 | 216946 | if( fts5yyact >= fts5YY_MIN_REDUCE ){ |
| 216748 | 216947 | unsigned int fts5yyruleno = fts5yyact - fts5YY_MIN_REDUCE; /* Reduce by this rule */ |
| 216749 | | - assert( fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ); |
| 216750 | 216948 | #ifndef NDEBUG |
| 216949 | + assert( fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ); |
| 216751 | 216950 | if( fts5yyTraceFILE ){ |
| 216752 | 216951 | int fts5yysize = fts5yyRuleInfoNRhs[fts5yyruleno]; |
| 216753 | 216952 | if( fts5yysize ){ |
| 216754 | 216953 | fprintf(fts5yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", |
| 216755 | 216954 | fts5yyTracePrompt, |
| | @@ -232260,11 +232459,11 @@ |
| 232260 | 232459 | int nArg, /* Number of args */ |
| 232261 | 232460 | sqlite3_value **apUnused /* Function arguments */ |
| 232262 | 232461 | ){ |
| 232263 | 232462 | assert( nArg==0 ); |
| 232264 | 232463 | UNUSED_PARAM2(nArg, apUnused); |
| 232265 | | - sqlite3_result_text(pCtx, "fts5: 2021-11-02 17:55:01 1d9004cd015073853ce0ca811a68ea5411733eedee993b97a38a42ba139d7590", -1, SQLITE_TRANSIENT); |
| 232464 | + sqlite3_result_text(pCtx, "fts5: 2021-11-15 19:10:13 bd66ab8a1bc3c43a57c7caff5f54545b0feb0177f1f51492f30d308c123c43ba", -1, SQLITE_TRANSIENT); |
| 232266 | 232465 | } |
| 232267 | 232466 | |
| 232268 | 232467 | /* |
| 232269 | 232468 | ** Return true if zName is the extension on one of the shadow tables used |
| 232270 | 232469 | ** by this module. |
| 232271 | 232470 | |