| | @@ -1205,11 +1205,11 @@ |
| 1205 | 1205 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1206 | 1206 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1207 | 1207 | */ |
| 1208 | 1208 | #define SQLITE_VERSION "3.36.0" |
| 1209 | 1209 | #define SQLITE_VERSION_NUMBER 3036000 |
| 1210 | | -#define SQLITE_SOURCE_ID "2021-06-07 00:41:18 2aa9368b63b42ac7c700516f109edcc6098c12b850eae591afed4e51a3f41819" |
| 1210 | +#define SQLITE_SOURCE_ID "2021-06-14 20:41:20 e5a5acd6006133c5da4a7dd79726dbaa41c0d60ebeda890f848a6aafe5f9ef70" |
| 1211 | 1211 | |
| 1212 | 1212 | /* |
| 1213 | 1213 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1214 | 1214 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1215 | 1215 | ** |
| | @@ -16558,10 +16558,16 @@ |
| 16558 | 16558 | */ |
| 16559 | 16559 | #ifndef SET_FULLSYNC |
| 16560 | 16560 | # define SET_FULLSYNC(x,y) |
| 16561 | 16561 | #endif |
| 16562 | 16562 | |
| 16563 | +/* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h |
| 16564 | +*/ |
| 16565 | +#ifndef SQLITE_MAX_PATHLEN |
| 16566 | +# define SQLITE_MAX_PATHLEN FILENAME_MAX |
| 16567 | +#endif |
| 16568 | + |
| 16563 | 16569 | /* |
| 16564 | 16570 | ** The default size of a disk sector |
| 16565 | 16571 | */ |
| 16566 | 16572 | #ifndef SQLITE_DEFAULT_SECTOR_SIZE |
| 16567 | 16573 | # define SQLITE_DEFAULT_SECTOR_SIZE 4096 |
| | @@ -18795,10 +18801,11 @@ |
| 18795 | 18801 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 18796 | 18802 | #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 18797 | 18803 | #define SF_UpdateFrom 0x0800000 /* Statement is an UPDATE...FROM */ |
| 18798 | 18804 | #define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */ |
| 18799 | 18805 | #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ |
| 18806 | +#define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ |
| 18800 | 18807 | |
| 18801 | 18808 | /* |
| 18802 | 18809 | ** The results of a SELECT can be distributed in several ways, as defined |
| 18803 | 18810 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| 18804 | 18811 | ** Type". |
| | @@ -20158,10 +20165,11 @@ |
| 20158 | 20165 | SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void); |
| 20159 | 20166 | SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*); |
| 20160 | 20167 | SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*); |
| 20161 | 20168 | SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*); |
| 20162 | 20169 | SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int); |
| 20170 | +SQLITE_PRIVATE With *sqlite3WithDup(sqlite3 *db, With *p); |
| 20163 | 20171 | |
| 20164 | 20172 | #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) |
| 20165 | 20173 | SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,int); |
| 20166 | 20174 | #endif |
| 20167 | 20175 | |
| | @@ -20568,11 +20576,11 @@ |
| 20568 | 20576 | #ifndef SQLITE_OMIT_CTE |
| 20569 | 20577 | SQLITE_PRIVATE Cte *sqlite3CteNew(Parse*,Token*,ExprList*,Select*,u8); |
| 20570 | 20578 | SQLITE_PRIVATE void sqlite3CteDelete(sqlite3*,Cte*); |
| 20571 | 20579 | SQLITE_PRIVATE With *sqlite3WithAdd(Parse*,With*,Cte*); |
| 20572 | 20580 | SQLITE_PRIVATE void sqlite3WithDelete(sqlite3*,With*); |
| 20573 | | -SQLITE_PRIVATE void sqlite3WithPush(Parse*, With*, u8); |
| 20581 | +SQLITE_PRIVATE With *sqlite3WithPush(Parse*, With*, u8); |
| 20574 | 20582 | #else |
| 20575 | 20583 | # define sqlite3CteNew(P,T,E,S) ((void*)0) |
| 20576 | 20584 | # define sqlite3CteDelete(D,C) |
| 20577 | 20585 | # define sqlite3CteWithAdd(P,W,C) ((void*)0) |
| 20578 | 20586 | # define sqlite3WithDelete(x,y) |
| | @@ -21670,11 +21678,11 @@ |
| 21670 | 21678 | SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*); |
| 21671 | 21679 | SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem*, const Mem*); |
| 21672 | 21680 | SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int); |
| 21673 | 21681 | SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem*, Mem*); |
| 21674 | 21682 | SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem*); |
| 21675 | | -SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*)); |
| 21683 | +SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, i64, u8, void(*)(void*)); |
| 21676 | 21684 | SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem*, i64); |
| 21677 | 21685 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 21678 | 21686 | # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64 |
| 21679 | 21687 | #else |
| 21680 | 21688 | SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double); |
| | @@ -23667,10 +23675,12 @@ |
| 23667 | 23675 | zPathOut[0] = 0; |
| 23668 | 23676 | return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut); |
| 23669 | 23677 | } |
| 23670 | 23678 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 23671 | 23679 | SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ |
| 23680 | + assert( zPath!=0 ); |
| 23681 | + assert( strlen(zPath)<=SQLITE_MAX_PATHLEN ); /* tag-20210611-1 */ |
| 23672 | 23682 | return pVfs->xDlOpen(pVfs, zPath); |
| 23673 | 23683 | } |
| 23674 | 23684 | SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ |
| 23675 | 23685 | pVfs->xDlError(pVfs, nByte, zBufOut); |
| 23676 | 23686 | } |
| | @@ -66965,11 +66975,11 @@ |
| 66965 | 66975 | testcase( pc+size==usableSize ); |
| 66966 | 66976 | put2byte(pAddr, cbrk); |
| 66967 | 66977 | if( temp==0 ){ |
| 66968 | 66978 | if( cbrk==pc ) continue; |
| 66969 | 66979 | temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 66970 | | - memcpy(&temp[iCellStart], &data[iCellStart], (cbrk+size) - iCellStart); |
| 66980 | + memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart); |
| 66971 | 66981 | src = temp; |
| 66972 | 66982 | } |
| 66973 | 66983 | memcpy(&data[cbrk], &src[pc], size); |
| 66974 | 66984 | } |
| 66975 | 66985 | data[hdr+7] = 0; |
| | @@ -78047,15 +78057,15 @@ |
| 78047 | 78057 | ** either case, SQLITE_TOOBIG is returned. |
| 78048 | 78058 | */ |
| 78049 | 78059 | SQLITE_PRIVATE int sqlite3VdbeMemSetStr( |
| 78050 | 78060 | Mem *pMem, /* Memory cell to set to string value */ |
| 78051 | 78061 | const char *z, /* String pointer */ |
| 78052 | | - int n, /* Bytes in string, or negative */ |
| 78062 | + i64 n, /* Bytes in string, or negative */ |
| 78053 | 78063 | u8 enc, /* Encoding of z. 0 for BLOBs */ |
| 78054 | 78064 | void (*xDel)(void*) /* Destructor function */ |
| 78055 | 78065 | ){ |
| 78056 | | - int nByte = n; /* New value for pMem->n */ |
| 78066 | + i64 nByte = n; /* New value for pMem->n */ |
| 78057 | 78067 | int iLimit; /* Maximum allowed string or blob size */ |
| 78058 | 78068 | u16 flags = 0; /* New value for pMem->flags */ |
| 78059 | 78069 | |
| 78060 | 78070 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 78061 | 78071 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| | @@ -78073,11 +78083,11 @@ |
| 78073 | 78083 | } |
| 78074 | 78084 | flags = (enc==0?MEM_Blob:MEM_Str); |
| 78075 | 78085 | if( nByte<0 ){ |
| 78076 | 78086 | assert( enc!=0 ); |
| 78077 | 78087 | if( enc==SQLITE_UTF8 ){ |
| 78078 | | - nByte = 0x7fffffff & (int)strlen(z); |
| 78088 | + nByte = strlen(z); |
| 78079 | 78089 | }else{ |
| 78080 | 78090 | for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){} |
| 78081 | 78091 | } |
| 78082 | 78092 | flags |= MEM_Term; |
| 78083 | 78093 | } |
| | @@ -78085,11 +78095,11 @@ |
| 78085 | 78095 | /* The following block sets the new values of Mem.z and Mem.xDel. It |
| 78086 | 78096 | ** also sets a flag in local variable "flags" to indicate the memory |
| 78087 | 78097 | ** management (one of MEM_Dyn or MEM_Static). |
| 78088 | 78098 | */ |
| 78089 | 78099 | if( xDel==SQLITE_TRANSIENT ){ |
| 78090 | | - u32 nAlloc = nByte; |
| 78100 | + i64 nAlloc = nByte; |
| 78091 | 78101 | if( flags&MEM_Term ){ |
| 78092 | 78102 | nAlloc += (enc==SQLITE_UTF8?1:2); |
| 78093 | 78103 | } |
| 78094 | 78104 | if( nByte>iLimit ){ |
| 78095 | 78105 | return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG); |
| | @@ -78111,11 +78121,11 @@ |
| 78111 | 78121 | pMem->xDel = xDel; |
| 78112 | 78122 | flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn); |
| 78113 | 78123 | } |
| 78114 | 78124 | } |
| 78115 | 78125 | |
| 78116 | | - pMem->n = nByte; |
| 78126 | + pMem->n = (int)(nByte & 0x7fffffff); |
| 78117 | 78127 | pMem->flags = flags; |
| 78118 | 78128 | if( enc ){ |
| 78119 | 78129 | pMem->enc = enc; |
| 78120 | 78130 | #ifdef SQLITE_ENABLE_SESSION |
| 78121 | 78131 | }else if( pMem->db==0 ){ |
| | @@ -78131,11 +78141,11 @@ |
| 78131 | 78141 | return SQLITE_NOMEM_BKPT; |
| 78132 | 78142 | } |
| 78133 | 78143 | #endif |
| 78134 | 78144 | |
| 78135 | 78145 | if( nByte>iLimit ){ |
| 78136 | | - return SQLITE_TOOBIG; |
| 78146 | + return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG); |
| 78137 | 78147 | } |
| 78138 | 78148 | |
| 78139 | 78149 | return SQLITE_OK; |
| 78140 | 78150 | } |
| 78141 | 78151 | |
| | @@ -84527,11 +84537,11 @@ |
| 84527 | 84537 | }else if( xDel==SQLITE_TRANSIENT ){ |
| 84528 | 84538 | /* noop */ |
| 84529 | 84539 | }else{ |
| 84530 | 84540 | xDel((void*)p); |
| 84531 | 84541 | } |
| 84532 | | - if( pCtx ) sqlite3_result_error_toobig(pCtx); |
| 84542 | + sqlite3_result_error_toobig(pCtx); |
| 84533 | 84543 | return SQLITE_TOOBIG; |
| 84534 | 84544 | } |
| 84535 | 84545 | SQLITE_API void sqlite3_result_blob( |
| 84536 | 84546 | sqlite3_context *pCtx, |
| 84537 | 84547 | const void *z, |
| | @@ -85509,11 +85519,11 @@ |
| 85509 | 85519 | */ |
| 85510 | 85520 | static int bindText( |
| 85511 | 85521 | sqlite3_stmt *pStmt, /* The statement to bind against */ |
| 85512 | 85522 | int i, /* Index of the parameter to bind */ |
| 85513 | 85523 | const void *zData, /* Pointer to the data to be bound */ |
| 85514 | | - int nData, /* Number of bytes of data to be bound */ |
| 85524 | + i64 nData, /* Number of bytes of data to be bound */ |
| 85515 | 85525 | void (*xDel)(void*), /* Destructor for the data */ |
| 85516 | 85526 | u8 encoding /* Encoding for the data */ |
| 85517 | 85527 | ){ |
| 85518 | 85528 | Vdbe *p = (Vdbe *)pStmt; |
| 85519 | 85529 | Mem *pVar; |
| | @@ -85561,15 +85571,11 @@ |
| 85561 | 85571 | const void *zData, |
| 85562 | 85572 | sqlite3_uint64 nData, |
| 85563 | 85573 | void (*xDel)(void*) |
| 85564 | 85574 | ){ |
| 85565 | 85575 | assert( xDel!=SQLITE_DYNAMIC ); |
| 85566 | | - if( nData>0x7fffffff ){ |
| 85567 | | - return invokeValueDestructor(zData, xDel, 0); |
| 85568 | | - }else{ |
| 85569 | | - return bindText(pStmt, i, zData, (int)nData, xDel, 0); |
| 85570 | | - } |
| 85576 | + return bindText(pStmt, i, zData, nData, xDel, 0); |
| 85571 | 85577 | } |
| 85572 | 85578 | SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){ |
| 85573 | 85579 | int rc; |
| 85574 | 85580 | Vdbe *p = (Vdbe *)pStmt; |
| 85575 | 85581 | rc = vdbeUnbind(p, i); |
| | @@ -85635,16 +85641,12 @@ |
| 85635 | 85641 | sqlite3_uint64 nData, |
| 85636 | 85642 | void (*xDel)(void*), |
| 85637 | 85643 | unsigned char enc |
| 85638 | 85644 | ){ |
| 85639 | 85645 | assert( xDel!=SQLITE_DYNAMIC ); |
| 85640 | | - if( nData>0x7fffffff ){ |
| 85641 | | - return invokeValueDestructor(zData, xDel, 0); |
| 85642 | | - }else{ |
| 85643 | | - if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE; |
| 85644 | | - return bindText(pStmt, i, zData, (int)nData, xDel, enc); |
| 85645 | | - } |
| 85646 | + if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE; |
| 85647 | + return bindText(pStmt, i, zData, nData, xDel, enc); |
| 85646 | 85648 | } |
| 85647 | 85649 | #ifndef SQLITE_OMIT_UTF16 |
| 85648 | 85650 | SQLITE_API int sqlite3_bind_text16( |
| 85649 | 85651 | sqlite3_stmt *pStmt, |
| 85650 | 85652 | int i, |
| | @@ -90957,11 +90959,12 @@ |
| 90957 | 90959 | assert( pOp[1].opcode==OP_SeekGE ); |
| 90958 | 90960 | |
| 90959 | 90961 | /* pOp->p2 points to the first instruction past the OP_IdxGT that |
| 90960 | 90962 | ** follows the OP_SeekGE. */ |
| 90961 | 90963 | assert( pOp->p2>=(int)(pOp-aOp)+2 ); |
| 90962 | | - assert( aOp[pOp->p2-1].opcode==OP_IdxGT ); |
| 90964 | + assert( aOp[pOp->p2-1].opcode==OP_IdxGT || aOp[pOp->p2-1].opcode==OP_IdxGE ); |
| 90965 | + testcase( aOp[pOp->p2-1].opcode==OP_IdxGE ); |
| 90963 | 90966 | assert( pOp[1].p1==aOp[pOp->p2-1].p1 ); |
| 90964 | 90967 | assert( pOp[1].p2==aOp[pOp->p2-1].p2 ); |
| 90965 | 90968 | assert( pOp[1].p3==aOp[pOp->p2-1].p3 ); |
| 90966 | 90969 | |
| 90967 | 90970 | assert( pOp->p1>0 ); |
| | @@ -92847,11 +92850,13 @@ |
| 92847 | 92850 | } |
| 92848 | 92851 | #endif |
| 92849 | 92852 | |
| 92850 | 92853 | iDb = pOp->p1; |
| 92851 | 92854 | assert( iDb>=0 && iDb<db->nDb ); |
| 92852 | | - assert( DbHasProperty(db, iDb, DB_SchemaLoaded) || db->mallocFailed ); |
| 92855 | + assert( DbHasProperty(db, iDb, DB_SchemaLoaded) |
| 92856 | + || db->mallocFailed |
| 92857 | + || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) ); |
| 92853 | 92858 | |
| 92854 | 92859 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 92855 | 92860 | if( pOp->p4.z==0 ){ |
| 92856 | 92861 | sqlite3SchemaClear(db->aDb[iDb].pSchema); |
| 92857 | 92862 | db->mDbFlags &= ~DBFLAG_SchemaKnownOk; |
| | @@ -102622,11 +102627,11 @@ |
| 102622 | 102627 | ** Create and return a deep copy of the object passed as the second |
| 102623 | 102628 | ** argument. If an OOM condition is encountered, NULL is returned |
| 102624 | 102629 | ** and the db->mallocFailed flag set. |
| 102625 | 102630 | */ |
| 102626 | 102631 | #ifndef SQLITE_OMIT_CTE |
| 102627 | | -static With *withDup(sqlite3 *db, With *p){ |
| 102632 | +SQLITE_PRIVATE With *sqlite3WithDup(sqlite3 *db, With *p){ |
| 102628 | 102633 | With *pRet = 0; |
| 102629 | 102634 | if( p ){ |
| 102630 | 102635 | sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1); |
| 102631 | 102636 | pRet = sqlite3DbMallocZero(db, nByte); |
| 102632 | 102637 | if( pRet ){ |
| | @@ -102640,11 +102645,11 @@ |
| 102640 | 102645 | } |
| 102641 | 102646 | } |
| 102642 | 102647 | return pRet; |
| 102643 | 102648 | } |
| 102644 | 102649 | #else |
| 102645 | | -# define withDup(x,y) 0 |
| 102650 | +# define sqlite3WithDup(x,y) 0 |
| 102646 | 102651 | #endif |
| 102647 | 102652 | |
| 102648 | 102653 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 102649 | 102654 | /* |
| 102650 | 102655 | ** The gatherSelectWindows() procedure and its helper routine |
| | @@ -102844,11 +102849,11 @@ |
| 102844 | 102849 | pNew->iOffset = 0; |
| 102845 | 102850 | pNew->selFlags = p->selFlags & ~SF_UsesEphemeral; |
| 102846 | 102851 | pNew->addrOpenEphm[0] = -1; |
| 102847 | 102852 | pNew->addrOpenEphm[1] = -1; |
| 102848 | 102853 | pNew->nSelectRow = p->nSelectRow; |
| 102849 | | - pNew->pWith = withDup(db, p->pWith); |
| 102854 | + pNew->pWith = sqlite3WithDup(db, p->pWith); |
| 102850 | 102855 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 102851 | 102856 | pNew->pWin = 0; |
| 102852 | 102857 | pNew->pWinDefn = sqlite3WindowListDup(db, p->pWinDefn); |
| 102853 | 102858 | if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew); |
| 102854 | 102859 | #endif |
| | @@ -108184,19 +108189,34 @@ |
| 108184 | 108189 | ** to select statement pSelect. |
| 108185 | 108190 | */ |
| 108186 | 108191 | static void renameWalkWith(Walker *pWalker, Select *pSelect){ |
| 108187 | 108192 | With *pWith = pSelect->pWith; |
| 108188 | 108193 | if( pWith ){ |
| 108194 | + Parse *pParse = pWalker->pParse; |
| 108189 | 108195 | int i; |
| 108196 | + With *pCopy = 0; |
| 108197 | + assert( pWith->nCte>0 ); |
| 108198 | + if( (pWith->a[0].pSelect->selFlags & SF_Expanded)==0 ){ |
| 108199 | + /* Push a copy of the With object onto the with-stack. We use a copy |
| 108200 | + ** here as the original will be expanded and resolved (flags SF_Expanded |
| 108201 | + ** and SF_Resolved) below. And the parser code that uses the with-stack |
| 108202 | + ** fails if the Select objects on it have already been expanded and |
| 108203 | + ** resolved. */ |
| 108204 | + pCopy = sqlite3WithDup(pParse->db, pWith); |
| 108205 | + pCopy = sqlite3WithPush(pParse, pCopy, 1); |
| 108206 | + } |
| 108190 | 108207 | for(i=0; i<pWith->nCte; i++){ |
| 108191 | 108208 | Select *p = pWith->a[i].pSelect; |
| 108192 | 108209 | NameContext sNC; |
| 108193 | 108210 | memset(&sNC, 0, sizeof(sNC)); |
| 108194 | | - sNC.pParse = pWalker->pParse; |
| 108195 | | - sqlite3SelectPrep(sNC.pParse, p, &sNC); |
| 108211 | + sNC.pParse = pParse; |
| 108212 | + if( pCopy ) sqlite3SelectPrep(sNC.pParse, p, &sNC); |
| 108196 | 108213 | sqlite3WalkSelect(pWalker, p); |
| 108197 | | - sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols); |
| 108214 | + sqlite3RenameExprlistUnmap(pParse, pWith->a[i].pCols); |
| 108215 | + } |
| 108216 | + if( pCopy && pParse->pWith==pCopy ){ |
| 108217 | + pParse->pWith = pCopy->pOuter; |
| 108198 | 108218 | } |
| 108199 | 108219 | } |
| 108200 | 108220 | } |
| 108201 | 108221 | |
| 108202 | 108222 | /* |
| | @@ -108219,11 +108239,15 @@ |
| 108219 | 108239 | */ |
| 108220 | 108240 | static int renameUnmapSelectCb(Walker *pWalker, Select *p){ |
| 108221 | 108241 | Parse *pParse = pWalker->pParse; |
| 108222 | 108242 | int i; |
| 108223 | 108243 | if( pParse->nErr ) return WRC_Abort; |
| 108224 | | - if( p->selFlags & SF_View ) return WRC_Prune; |
| 108244 | + if( p->selFlags & (SF_View|SF_CopyCte) ){ |
| 108245 | + testcase( pSelect->selFlags & SF_View ); |
| 108246 | + testcase( pSelect->selFlags & SF_CopyCte ); |
| 108247 | + return WRC_Prune; |
| 108248 | + } |
| 108225 | 108249 | if( ALWAYS(p->pEList) ){ |
| 108226 | 108250 | ExprList *pList = p->pEList; |
| 108227 | 108251 | for(i=0; i<pList->nExpr; i++){ |
| 108228 | 108252 | if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){ |
| 108229 | 108253 | sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName); |
| | @@ -108327,11 +108351,15 @@ |
| 108327 | 108351 | ** This is a Walker select callback. It does nothing. It is only required |
| 108328 | 108352 | ** because without a dummy callback, sqlite3WalkExpr() and similar do not |
| 108329 | 108353 | ** descend into sub-select statements. |
| 108330 | 108354 | */ |
| 108331 | 108355 | static int renameColumnSelectCb(Walker *pWalker, Select *p){ |
| 108332 | | - if( p->selFlags & SF_View ) return WRC_Prune; |
| 108356 | + if( p->selFlags & (SF_View|SF_CopyCte) ){ |
| 108357 | + testcase( pSelect->selFlags & SF_View ); |
| 108358 | + testcase( pSelect->selFlags & SF_CopyCte ); |
| 108359 | + return WRC_Prune; |
| 108360 | + } |
| 108333 | 108361 | renameWalkWith(pWalker, p); |
| 108334 | 108362 | return WRC_Continue; |
| 108335 | 108363 | } |
| 108336 | 108364 | |
| 108337 | 108365 | /* |
| | @@ -108963,11 +108991,15 @@ |
| 108963 | 108991 | */ |
| 108964 | 108992 | static int renameTableSelectCb(Walker *pWalker, Select *pSelect){ |
| 108965 | 108993 | int i; |
| 108966 | 108994 | RenameCtx *p = pWalker->u.pRename; |
| 108967 | 108995 | SrcList *pSrc = pSelect->pSrc; |
| 108968 | | - if( pSelect->selFlags & SF_View ) return WRC_Prune; |
| 108996 | + if( pSelect->selFlags & (SF_View|SF_CopyCte) ){ |
| 108997 | + testcase( pSelect->selFlags & SF_View ); |
| 108998 | + testcase( pSelect->selFlags & SF_CopyCte ); |
| 108999 | + return WRC_Prune; |
| 109000 | + } |
| 108969 | 109001 | if( NEVER(pSrc==0) ){ |
| 108970 | 109002 | assert( pWalker->pParse->db->mallocFailed ); |
| 108971 | 109003 | return WRC_Abort; |
| 108972 | 109004 | } |
| 108973 | 109005 | for(i=0; i<pSrc->nSrc; i++){ |
| | @@ -116705,11 +116737,11 @@ |
| 116705 | 116737 | const char *zDb = db->aDb[iDb].zDbSName; |
| 116706 | 116738 | const char *zTab = SCHEMA_TABLE(iDb); |
| 116707 | 116739 | if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){ |
| 116708 | 116740 | goto exit_drop_index; |
| 116709 | 116741 | } |
| 116710 | | - if( !OMIT_TEMPDB && iDb ) code = SQLITE_DROP_TEMP_INDEX; |
| 116742 | + if( !OMIT_TEMPDB && iDb==1 ) code = SQLITE_DROP_TEMP_INDEX; |
| 116711 | 116743 | if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){ |
| 116712 | 116744 | goto exit_drop_index; |
| 116713 | 116745 | } |
| 116714 | 116746 | } |
| 116715 | 116747 | #endif |
| | @@ -119237,17 +119269,19 @@ |
| 119237 | 119269 | ){ |
| 119238 | 119270 | /* This column was already computed by the previous index */ |
| 119239 | 119271 | continue; |
| 119240 | 119272 | } |
| 119241 | 119273 | sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j); |
| 119242 | | - /* If the column affinity is REAL but the number is an integer, then it |
| 119243 | | - ** might be stored in the table as an integer (using a compact |
| 119244 | | - ** representation) then converted to REAL by an OP_RealAffinity opcode. |
| 119245 | | - ** But we are getting ready to store this value back into an index, where |
| 119246 | | - ** it should be converted by to INTEGER again. So omit the OP_RealAffinity |
| 119247 | | - ** opcode if it is present */ |
| 119248 | | - sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity); |
| 119274 | + if( pIdx->aiColumn[j]>=0 ){ |
| 119275 | + /* If the column affinity is REAL but the number is an integer, then it |
| 119276 | + ** might be stored in the table as an integer (using a compact |
| 119277 | + ** representation) then converted to REAL by an OP_RealAffinity opcode. |
| 119278 | + ** But we are getting ready to store this value back into an index, where |
| 119279 | + ** it should be converted by to INTEGER again. So omit the |
| 119280 | + ** OP_RealAffinity opcode if it is present */ |
| 119281 | + sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity); |
| 119282 | + } |
| 119249 | 119283 | } |
| 119250 | 119284 | if( regOut ){ |
| 119251 | 119285 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 119252 | 119286 | } |
| 119253 | 119287 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| | @@ -127401,11 +127435,11 @@ |
| 127401 | 127435 | sqlite3_loadext_entry xInit; |
| 127402 | 127436 | char *zErrmsg = 0; |
| 127403 | 127437 | const char *zEntry; |
| 127404 | 127438 | char *zAltEntry = 0; |
| 127405 | 127439 | void **aHandle; |
| 127406 | | - u64 nMsg = 300 + sqlite3Strlen30(zFile); |
| 127440 | + u64 nMsg = strlen(zFile); |
| 127407 | 127441 | int ii; |
| 127408 | 127442 | int rc; |
| 127409 | 127443 | |
| 127410 | 127444 | /* Shared library endings to try if zFile cannot be loaded as written */ |
| 127411 | 127445 | static const char *azEndings[] = { |
| | @@ -127435,30 +127469,26 @@ |
| 127435 | 127469 | return SQLITE_ERROR; |
| 127436 | 127470 | } |
| 127437 | 127471 | |
| 127438 | 127472 | zEntry = zProc ? zProc : "sqlite3_extension_init"; |
| 127439 | 127473 | |
| 127474 | + /* tag-20210611-1. Some dlopen() implementations will segfault if given |
| 127475 | + ** an oversize filename. Most filesystems have a pathname limit of 4K, |
| 127476 | + ** so limit the extension filename length to about twice that. |
| 127477 | + ** https://sqlite.org/forum/forumpost/08a0d6d9bf */ |
| 127478 | + if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found; |
| 127479 | + |
| 127440 | 127480 | handle = sqlite3OsDlOpen(pVfs, zFile); |
| 127441 | 127481 | #if SQLITE_OS_UNIX || SQLITE_OS_WIN |
| 127442 | 127482 | for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){ |
| 127443 | 127483 | char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]); |
| 127444 | 127484 | if( zAltFile==0 ) return SQLITE_NOMEM_BKPT; |
| 127445 | 127485 | handle = sqlite3OsDlOpen(pVfs, zAltFile); |
| 127446 | 127486 | sqlite3_free(zAltFile); |
| 127447 | 127487 | } |
| 127448 | 127488 | #endif |
| 127449 | | - if( handle==0 ){ |
| 127450 | | - if( pzErrMsg ){ |
| 127451 | | - *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); |
| 127452 | | - if( zErrmsg ){ |
| 127453 | | - sqlite3_snprintf(nMsg, zErrmsg, |
| 127454 | | - "unable to open shared library [%s]", zFile); |
| 127455 | | - sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 127456 | | - } |
| 127457 | | - } |
| 127458 | | - return SQLITE_ERROR; |
| 127459 | | - } |
| 127489 | + if( handle==0 ) goto extension_not_found; |
| 127460 | 127490 | xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry); |
| 127461 | 127491 | |
| 127462 | 127492 | /* If no entry point was specified and the default legacy |
| 127463 | 127493 | ** entry point name "sqlite3_extension_init" was not found, then |
| 127464 | 127494 | ** construct an entry point name "sqlite3_X_init" where the X is |
| | @@ -127491,14 +127521,15 @@ |
| 127491 | 127521 | zEntry = zAltEntry; |
| 127492 | 127522 | xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry); |
| 127493 | 127523 | } |
| 127494 | 127524 | if( xInit==0 ){ |
| 127495 | 127525 | if( pzErrMsg ){ |
| 127496 | | - nMsg += sqlite3Strlen30(zEntry); |
| 127526 | + nMsg += strlen(zEntry) + 300; |
| 127497 | 127527 | *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); |
| 127498 | 127528 | if( zErrmsg ){ |
| 127499 | | - sqlite3_snprintf(nMsg, zErrmsg, |
| 127529 | + assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */ |
| 127530 | + sqlite3_snprintf((int)nMsg, zErrmsg, |
| 127500 | 127531 | "no entry point [%s] in shared library [%s]", zEntry, zFile); |
| 127501 | 127532 | sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 127502 | 127533 | } |
| 127503 | 127534 | } |
| 127504 | 127535 | sqlite3OsDlClose(pVfs, handle); |
| | @@ -127528,10 +127559,23 @@ |
| 127528 | 127559 | sqlite3DbFree(db, db->aExtension); |
| 127529 | 127560 | db->aExtension = aHandle; |
| 127530 | 127561 | |
| 127531 | 127562 | db->aExtension[db->nExtension++] = handle; |
| 127532 | 127563 | return SQLITE_OK; |
| 127564 | + |
| 127565 | +extension_not_found: |
| 127566 | + if( pzErrMsg ){ |
| 127567 | + nMsg += 300; |
| 127568 | + *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg); |
| 127569 | + if( zErrmsg ){ |
| 127570 | + assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */ |
| 127571 | + sqlite3_snprintf((int)nMsg, zErrmsg, |
| 127572 | + "unable to open shared library [%.*s]", SQLITE_MAX_PATHLEN, zFile); |
| 127573 | + sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); |
| 127574 | + } |
| 127575 | + } |
| 127576 | + return SQLITE_ERROR; |
| 127533 | 127577 | } |
| 127534 | 127578 | SQLITE_API int sqlite3_load_extension( |
| 127535 | 127579 | sqlite3 *db, /* Load the extension into this database connection */ |
| 127536 | 127580 | const char *zFile, /* Name of the shared library containing extension */ |
| 127537 | 127581 | const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */ |
| | @@ -131368,13 +131412,15 @@ |
| 131368 | 131412 | if( rc==SQLITE_OK ){ |
| 131369 | 131413 | sqlite3AnalysisLoad(db, iDb); |
| 131370 | 131414 | } |
| 131371 | 131415 | #endif |
| 131372 | 131416 | } |
| 131417 | + assert( pDb == &(db->aDb[iDb]) ); |
| 131373 | 131418 | if( db->mallocFailed ){ |
| 131374 | 131419 | rc = SQLITE_NOMEM_BKPT; |
| 131375 | 131420 | sqlite3ResetAllSchemasOfConnection(db); |
| 131421 | + pDb = &db->aDb[iDb]; |
| 131376 | 131422 | }else |
| 131377 | 131423 | if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){ |
| 131378 | 131424 | /* Hack: If the SQLITE_NoSchemaError flag is set, then consider |
| 131379 | 131425 | ** the schema loaded, even if errors (other than OOM) occurred. In |
| 131380 | 131426 | ** this situation the current sqlite3_prepare() operation will fail, |
| | @@ -136426,10 +136472,11 @@ |
| 136426 | 136472 | ** a known value due to WHERE clause constraints of the form COLUMN=VALUE. |
| 136427 | 136473 | */ |
| 136428 | 136474 | typedef struct WhereConst WhereConst; |
| 136429 | 136475 | struct WhereConst { |
| 136430 | 136476 | Parse *pParse; /* Parsing context */ |
| 136477 | + u8 *pOomFault; /* Pointer to pParse->db->mallocFailed */ |
| 136431 | 136478 | int nConst; /* Number for COLUMN=CONSTANT terms */ |
| 136432 | 136479 | int nChng; /* Number of times a constant is propagated */ |
| 136433 | 136480 | int bHasAffBlob; /* At least one column in apExpr[] as affinity BLOB */ |
| 136434 | 136481 | Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */ |
| 136435 | 136482 | }; |
| | @@ -136525,10 +136572,11 @@ |
| 136525 | 136572 | WhereConst *pConst, |
| 136526 | 136573 | Expr *pExpr, |
| 136527 | 136574 | int bIgnoreAffBlob |
| 136528 | 136575 | ){ |
| 136529 | 136576 | int i; |
| 136577 | + if( pConst->pOomFault[0] ) return WRC_Prune; |
| 136530 | 136578 | if( pExpr->op!=TK_COLUMN ) return WRC_Continue; |
| 136531 | 136579 | if( ExprHasProperty(pExpr, EP_FixedCol|EP_FromJoin) ){ |
| 136532 | 136580 | testcase( ExprHasProperty(pExpr, EP_FixedCol) ); |
| 136533 | 136581 | testcase( ExprHasProperty(pExpr, EP_FromJoin) ); |
| 136534 | 136582 | return WRC_Continue; |
| | @@ -136545,10 +136593,11 @@ |
| 136545 | 136593 | pConst->nChng++; |
| 136546 | 136594 | ExprClearProperty(pExpr, EP_Leaf); |
| 136547 | 136595 | ExprSetProperty(pExpr, EP_FixedCol); |
| 136548 | 136596 | assert( pExpr->pLeft==0 ); |
| 136549 | 136597 | pExpr->pLeft = sqlite3ExprDup(pConst->pParse->db, pConst->apExpr[i*2+1], 0); |
| 136598 | + if( pConst->pParse->db->mallocFailed ) return WRC_Prune; |
| 136550 | 136599 | break; |
| 136551 | 136600 | } |
| 136552 | 136601 | return WRC_Prune; |
| 136553 | 136602 | } |
| 136554 | 136603 | |
| | @@ -136577,10 +136626,11 @@ |
| 136577 | 136626 | if( pConst->bHasAffBlob ){ |
| 136578 | 136627 | if( (pExpr->op>=TK_EQ && pExpr->op<=TK_GE) |
| 136579 | 136628 | || pExpr->op==TK_IS |
| 136580 | 136629 | ){ |
| 136581 | 136630 | propagateConstantExprRewriteOne(pConst, pExpr->pLeft, 0); |
| 136631 | + if( pConst->pOomFault[0] ) return WRC_Prune; |
| 136582 | 136632 | if( sqlite3ExprAffinity(pExpr->pLeft)!=SQLITE_AFF_TEXT ){ |
| 136583 | 136633 | propagateConstantExprRewriteOne(pConst, pExpr->pRight, 0); |
| 136584 | 136634 | } |
| 136585 | 136635 | } |
| 136586 | 136636 | } |
| | @@ -136644,10 +136694,11 @@ |
| 136644 | 136694 | ){ |
| 136645 | 136695 | WhereConst x; |
| 136646 | 136696 | Walker w; |
| 136647 | 136697 | int nChng = 0; |
| 136648 | 136698 | x.pParse = pParse; |
| 136699 | + x.pOomFault = &pParse->db->mallocFailed; |
| 136649 | 136700 | do{ |
| 136650 | 136701 | x.nConst = 0; |
| 136651 | 136702 | x.nChng = 0; |
| 136652 | 136703 | x.apExpr = 0; |
| 136653 | 136704 | x.bHasAffBlob = 0; |
| | @@ -137099,25 +137150,33 @@ |
| 137099 | 137150 | ** onto the top of the stack. If argument bFree is true, then this |
| 137100 | 137151 | ** WITH clause will never be popped from the stack but should instead |
| 137101 | 137152 | ** be freed along with the Parse object. In other cases, when |
| 137102 | 137153 | ** bFree==0, the With object will be freed along with the SELECT |
| 137103 | 137154 | ** statement with which it is associated. |
| 137155 | +** |
| 137156 | +** This routine returns a copy of pWith. Or, if bFree is true and |
| 137157 | +** the pWith object is destroyed immediately due to an OOM condition, |
| 137158 | +** then this routine return NULL. |
| 137159 | +** |
| 137160 | +** If bFree is true, do not continue to use the pWith pointer after |
| 137161 | +** calling this routine, Instead, use only the return value. |
| 137104 | 137162 | */ |
| 137105 | | -SQLITE_PRIVATE void sqlite3WithPush(Parse *pParse, With *pWith, u8 bFree){ |
| 137163 | +SQLITE_PRIVATE With *sqlite3WithPush(Parse *pParse, With *pWith, u8 bFree){ |
| 137106 | 137164 | if( pWith ){ |
| 137165 | + if( bFree ){ |
| 137166 | + pWith = (With*)sqlite3ParserAddCleanup(pParse, |
| 137167 | + (void(*)(sqlite3*,void*))sqlite3WithDelete, |
| 137168 | + pWith); |
| 137169 | + if( pWith==0 ) return 0; |
| 137170 | + } |
| 137107 | 137171 | if( pParse->nErr==0 ){ |
| 137108 | 137172 | assert( pParse->pWith!=pWith ); |
| 137109 | 137173 | pWith->pOuter = pParse->pWith; |
| 137110 | 137174 | pParse->pWith = pWith; |
| 137111 | 137175 | } |
| 137112 | | - if( bFree ){ |
| 137113 | | - sqlite3ParserAddCleanup(pParse, |
| 137114 | | - (void(*)(sqlite3*,void*))sqlite3WithDelete, |
| 137115 | | - pWith); |
| 137116 | | - testcase( pParse->earlyCleanup ); |
| 137117 | | - } |
| 137118 | 137176 | } |
| 137177 | + return pWith; |
| 137119 | 137178 | } |
| 137120 | 137179 | |
| 137121 | 137180 | /* |
| 137122 | 137181 | ** This function checks if argument pFrom refers to a CTE declared by |
| 137123 | 137182 | ** a WITH clause on the stack currently maintained by the parser (on the |
| | @@ -137206,10 +137265,11 @@ |
| 137206 | 137265 | pTab->iPKey = -1; |
| 137207 | 137266 | pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) ); |
| 137208 | 137267 | pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid; |
| 137209 | 137268 | pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0); |
| 137210 | 137269 | if( db->mallocFailed ) return 2; |
| 137270 | + pFrom->pSelect->selFlags |= SF_CopyCte; |
| 137211 | 137271 | assert( pFrom->pSelect ); |
| 137212 | 137272 | pFrom->fg.isCte = 1; |
| 137213 | 137273 | pFrom->u2.pCteUse = pCteUse; |
| 137214 | 137274 | pCteUse->nUse++; |
| 137215 | 137275 | if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){ |
| | @@ -137474,10 +137534,11 @@ |
| 137474 | 137534 | ){ |
| 137475 | 137535 | sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited", |
| 137476 | 137536 | pTab->zName); |
| 137477 | 137537 | } |
| 137478 | 137538 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 137539 | + assert( SQLITE_VTABRISK_Normal==1 && SQLITE_VTABRISK_High==2 ); |
| 137479 | 137540 | if( IsVirtual(pTab) |
| 137480 | 137541 | && pFrom->fg.fromDDL |
| 137481 | 137542 | && ALWAYS(pTab->pVTable!=0) |
| 137482 | 137543 | && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0) |
| 137483 | 137544 | ){ |
| | @@ -183221,12 +183282,12 @@ |
| 183221 | 183282 | int nPrev, /* Size of buffer zPrev in bytes */ |
| 183222 | 183283 | const char *zNext, /* Buffer containing next term */ |
| 183223 | 183284 | int nNext /* Size of buffer zNext in bytes */ |
| 183224 | 183285 | ){ |
| 183225 | 183286 | int n; |
| 183226 | | - UNUSED_PARAMETER(nNext); |
| 183227 | | - for(n=0; n<nPrev && zPrev[n]==zNext[n]; n++); |
| 183287 | + for(n=0; n<nPrev && n<nNext && zPrev[n]==zNext[n]; n++); |
| 183288 | + assert_fts3_nc( n<nNext ); |
| 183228 | 183289 | return n; |
| 183229 | 183290 | } |
| 183230 | 183291 | |
| 183231 | 183292 | /* |
| 183232 | 183293 | ** Add term zTerm to the SegmentNode. It is guaranteed that zTerm is larger |
| | @@ -184221,11 +184282,11 @@ |
| 184221 | 184282 | iDelta = (i64)((u64)iDocid - (u64)iPrev); |
| 184222 | 184283 | } |
| 184223 | 184284 | |
| 184224 | 184285 | nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0); |
| 184225 | 184286 | |
| 184226 | | - rc = fts3GrowSegReaderBuffer(pCsr, nByte+nDoclist); |
| 184287 | + rc = fts3GrowSegReaderBuffer(pCsr, nByte+nDoclist+FTS3_NODE_PADDING); |
| 184227 | 184288 | if( rc ) return rc; |
| 184228 | 184289 | |
| 184229 | 184290 | if( isFirst ){ |
| 184230 | 184291 | char *a = &pCsr->aBuffer[nDoclist]; |
| 184231 | 184292 | int nWrite; |
| | @@ -216164,10 +216225,11 @@ |
| 216164 | 216225 | return 1; |
| 216165 | 216226 | }else{ |
| 216166 | 216227 | i64 iOff = *piOff; |
| 216167 | 216228 | int iVal; |
| 216168 | 216229 | fts5FastGetVarint32(a, i, iVal); |
| 216230 | + assert( iVal>=0 ); |
| 216169 | 216231 | if( iVal<=1 ){ |
| 216170 | 216232 | if( iVal==0 ){ |
| 216171 | 216233 | *pi = i; |
| 216172 | 216234 | return 0; |
| 216173 | 216235 | } |
| | @@ -216177,13 +216239,16 @@ |
| 216177 | 216239 | if( iVal<2 ){ |
| 216178 | 216240 | /* This is a corrupt record. So stop parsing it here. */ |
| 216179 | 216241 | *piOff = -1; |
| 216180 | 216242 | return 1; |
| 216181 | 216243 | } |
| 216244 | + *piOff = iOff + ((iVal-2) & 0x7FFFFFFF); |
| 216245 | + }else{ |
| 216246 | + *piOff = (iOff & (i64)0x7FFFFFFF<<32)+((iOff + (iVal-2)) & 0x7FFFFFFF); |
| 216182 | 216247 | } |
| 216183 | | - *piOff = iOff + ((iVal-2) & 0x7FFFFFFF); |
| 216184 | 216248 | *pi = i; |
| 216249 | + assert( *piOff>=iOff ); |
| 216185 | 216250 | return 0; |
| 216186 | 216251 | } |
| 216187 | 216252 | } |
| 216188 | 216253 | |
| 216189 | 216254 | |
| | @@ -216218,18 +216283,20 @@ |
| 216218 | 216283 | static void sqlite3Fts5PoslistSafeAppend( |
| 216219 | 216284 | Fts5Buffer *pBuf, |
| 216220 | 216285 | i64 *piPrev, |
| 216221 | 216286 | i64 iPos |
| 216222 | 216287 | ){ |
| 216223 | | - static const i64 colmask = ((i64)(0x7FFFFFFF)) << 32; |
| 216224 | | - if( (iPos & colmask) != (*piPrev & colmask) ){ |
| 216225 | | - pBuf->p[pBuf->n++] = 1; |
| 216226 | | - pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], (iPos>>32)); |
| 216227 | | - *piPrev = (iPos & colmask); |
| 216228 | | - } |
| 216229 | | - pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], (iPos-*piPrev)+2); |
| 216230 | | - *piPrev = iPos; |
| 216288 | + if( iPos>=*piPrev ){ |
| 216289 | + static const i64 colmask = ((i64)(0x7FFFFFFF)) << 32; |
| 216290 | + if( (iPos & colmask) != (*piPrev & colmask) ){ |
| 216291 | + pBuf->p[pBuf->n++] = 1; |
| 216292 | + pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], (iPos>>32)); |
| 216293 | + *piPrev = (iPos & colmask); |
| 216294 | + } |
| 216295 | + pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], (iPos-*piPrev)+2); |
| 216296 | + *piPrev = iPos; |
| 216297 | + } |
| 216231 | 216298 | } |
| 216232 | 216299 | |
| 216233 | 216300 | static int sqlite3Fts5PoslistWriterAppend( |
| 216234 | 216301 | Fts5Buffer *pBuf, |
| 216235 | 216302 | Fts5PoslistWriter *pWriter, |
| | @@ -224157,11 +224224,11 @@ |
| 224157 | 224224 | pIter->base.nData = p-aCopy; |
| 224158 | 224225 | return; |
| 224159 | 224226 | } |
| 224160 | 224227 | fts5BufferSafeAppendBlob(&pIter->poslist, aCopy, p-aCopy); |
| 224161 | 224228 | } |
| 224162 | | - if( p==pEnd ){ |
| 224229 | + if( p>=pEnd ){ |
| 224163 | 224230 | pIter->base.pData = pIter->poslist.p; |
| 224164 | 224231 | pIter->base.nData = pIter->poslist.n; |
| 224165 | 224232 | return; |
| 224166 | 224233 | } |
| 224167 | 224234 | aCopy = p++; |
| | @@ -225953,11 +226020,11 @@ |
| 225953 | 226020 | Fts5Buffer *p1, /* First list to merge */ |
| 225954 | 226021 | int nBuf, /* Number of buffers in array aBuf[] */ |
| 225955 | 226022 | Fts5Buffer *aBuf /* Other lists to merge in */ |
| 225956 | 226023 | ){ |
| 225957 | 226024 | #define fts5PrefixMergerNextPosition(p) \ |
| 225958 | | - sqlite3Fts5PoslistNext64((p)->aPos,(p)->iter.nPoslist,&(p)->iOff,&(p)->iPos); |
| 226025 | + sqlite3Fts5PoslistNext64((p)->aPos,(p)->iter.nPoslist,&(p)->iOff,&(p)->iPos) |
| 225959 | 226026 | #define FTS5_MERGE_NLIST 16 |
| 225960 | 226027 | PrefixMerger aMerger[FTS5_MERGE_NLIST]; |
| 225961 | 226028 | PrefixMerger *pHead = 0; |
| 225962 | 226029 | int i; |
| 225963 | 226030 | int nOut = 0; |
| | @@ -230501,11 +230568,11 @@ |
| 230501 | 230568 | int nArg, /* Number of args */ |
| 230502 | 230569 | sqlite3_value **apUnused /* Function arguments */ |
| 230503 | 230570 | ){ |
| 230504 | 230571 | assert( nArg==0 ); |
| 230505 | 230572 | UNUSED_PARAM2(nArg, apUnused); |
| 230506 | | - sqlite3_result_text(pCtx, "fts5: 2021-06-04 23:26:56 1c71de43dbc68002c4a6229e7efffb019655baff67a51fe922571fe420c95835", -1, SQLITE_TRANSIENT); |
| 230573 | + sqlite3_result_text(pCtx, "fts5: 2021-06-14 20:41:20 e5a5acd6006133c5da4a7dd79726dbaa41c0d60ebeda890f848a6aafe5f9ef70", -1, SQLITE_TRANSIENT); |
| 230507 | 230574 | } |
| 230508 | 230575 | |
| 230509 | 230576 | /* |
| 230510 | 230577 | ** Return true if zName is the extension on one of the shadow tables used |
| 230511 | 230578 | ** by this module. |
| | @@ -235427,12 +235494,12 @@ |
| 235427 | 235494 | } |
| 235428 | 235495 | #endif /* SQLITE_CORE */ |
| 235429 | 235496 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 235430 | 235497 | |
| 235431 | 235498 | /************** End of stmt.c ************************************************/ |
| 235432 | | -#if __LINE__!=235432 |
| 235499 | +#if __LINE__!=235499 |
| 235433 | 235500 | #undef SQLITE_SOURCE_ID |
| 235434 | | -#define SQLITE_SOURCE_ID "2021-06-07 00:41:18 2aa9368b63b42ac7c700516f109edcc6098c12b850eae591afed4e51a3f4alt2" |
| 235501 | +#define SQLITE_SOURCE_ID "2021-06-14 20:41:20 e5a5acd6006133c5da4a7dd79726dbaa41c0d60ebeda890f848a6aafe5f9alt2" |
| 235435 | 235502 | #endif |
| 235436 | 235503 | /* Return the source-id for this library */ |
| 235437 | 235504 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 235438 | 235505 | /************************** End of sqlite3.c ******************************/ |
| 235439 | 235506 | |