| | @@ -1186,11 +1186,11 @@ |
| 1186 | 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | 1188 | */ |
| 1189 | 1189 | #define SQLITE_VERSION "3.35.0" |
| 1190 | 1190 | #define SQLITE_VERSION_NUMBER 3035000 |
| 1191 | | -#define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092" |
| 1191 | +#define SQLITE_SOURCE_ID "2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303bf8b" |
| 1192 | 1192 | |
| 1193 | 1193 | /* |
| 1194 | 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | 1196 | ** |
| | @@ -3193,11 +3193,17 @@ |
| 3193 | 3193 | ** The first argument is an integer which is 0 to disable views, |
| 3194 | 3194 | ** positive to enable views or negative to leave the setting unchanged. |
| 3195 | 3195 | ** The second parameter is a pointer to an integer into which |
| 3196 | 3196 | ** is written 0 or 1 to indicate whether views are disabled or enabled |
| 3197 | 3197 | ** following this call. The second parameter may be a NULL pointer, in |
| 3198 | | -** which case the view setting is not reported back. </dd> |
| 3198 | +** which case the view setting is not reported back. |
| 3199 | +** |
| 3200 | +** <p>Originally this option disabled all views. ^(However, since |
| 3201 | +** SQLite version 3.35.0, TEMP views are still allowed even if |
| 3202 | +** this option is off. So, in other words, this option now only disables |
| 3203 | +** views in the main database schema or in the schemas of ATTACH-ed |
| 3204 | +** databases.)^ </dd> |
| 3199 | 3205 | ** |
| 3200 | 3206 | ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]] |
| 3201 | 3207 | ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> |
| 3202 | 3208 | ** <dd> ^This option is used to enable or disable the |
| 3203 | 3209 | ** [fts3_tokenizer()] function which is part of the |
| | @@ -15368,11 +15374,11 @@ |
| 15368 | 15374 | |
| 15369 | 15375 | /* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */ |
| 15370 | 15376 | #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */ |
| 15371 | 15377 | #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */ |
| 15372 | 15378 | #define BTREE_APPEND 0x08 /* Insert is likely an append */ |
| 15373 | | -#define BTREE_PREFORMAT 0x80 /* Insert is likely an append */ |
| 15379 | +#define BTREE_PREFORMAT 0x80 /* Inserted data is a preformated cell */ |
| 15374 | 15380 | |
| 15375 | 15381 | /* An instance of the BtreePayload object describes the content of a single |
| 15376 | 15382 | ** entry in either an index or table btree. |
| 15377 | 15383 | ** |
| 15378 | 15384 | ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain |
| | @@ -20256,10 +20262,11 @@ |
| 20256 | 20262 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int); |
| 20257 | 20263 | SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*); |
| 20258 | 20264 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*); |
| 20259 | 20265 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*); |
| 20260 | 20266 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int); |
| 20267 | +SQLITE_PRIVATE const char *sqlite3SelectOpName(int); |
| 20261 | 20268 | SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse*, ExprList*); |
| 20262 | 20269 | |
| 20263 | 20270 | #ifdef SQLITE_DEBUG |
| 20264 | 20271 | SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo*); |
| 20265 | 20272 | #endif |
| | @@ -29330,11 +29337,11 @@ |
| 29330 | 29337 | setStrAccumError(p, SQLITE_TOOBIG); |
| 29331 | 29338 | return p->nAlloc - p->nChar - 1; |
| 29332 | 29339 | }else{ |
| 29333 | 29340 | char *zOld = isMalloced(p) ? p->zText : 0; |
| 29334 | 29341 | i64 szNew = p->nChar; |
| 29335 | | - szNew += N + 1; |
| 29342 | + szNew += (sqlite3_int64)N + 1; |
| 29336 | 29343 | if( szNew+p->nChar<=p->mxAlloc ){ |
| 29337 | 29344 | /* Force exponential buffer size growth as long as it does not overflow, |
| 29338 | 29345 | ** to avoid having to call this routine too often */ |
| 29339 | 29346 | szNew += p->nChar; |
| 29340 | 29347 | } |
| | @@ -87395,11 +87402,11 @@ |
| 87395 | 87402 | case OP_ChngCntRow: { |
| 87396 | 87403 | assert( pOp->p2==1 ); |
| 87397 | 87404 | if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){ |
| 87398 | 87405 | goto abort_due_to_error; |
| 87399 | 87406 | } |
| 87400 | | - /* Fall through to the next case, OP_String */ |
| 87407 | + /* Fall through to the next case, OP_ResultRow */ |
| 87401 | 87408 | /* no break */ deliberate_fall_through |
| 87402 | 87409 | } |
| 87403 | 87410 | |
| 87404 | 87411 | /* Opcode: ResultRow P1 P2 * * * |
| 87405 | 87412 | ** Synopsis: output=r[P1@P2] |
| | @@ -98169,11 +98176,11 @@ |
| 98169 | 98176 | }else{ |
| 98170 | 98177 | i64 iOff = p->nChunkSize; |
| 98171 | 98178 | for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){ |
| 98172 | 98179 | iOff += p->nChunkSize; |
| 98173 | 98180 | } |
| 98174 | | - if( pIter ){ |
| 98181 | + if( ALWAYS(pIter) ){ |
| 98175 | 98182 | memjrnlFreeChunks(pIter->pNext); |
| 98176 | 98183 | pIter->pNext = 0; |
| 98177 | 98184 | } |
| 98178 | 98185 | } |
| 98179 | 98186 | |
| | @@ -99006,10 +99013,11 @@ |
| 99006 | 99013 | /* IMP: R-51414-32910 */ |
| 99007 | 99014 | iCol = -1; |
| 99008 | 99015 | } |
| 99009 | 99016 | if( iCol<pTab->nCol ){ |
| 99010 | 99017 | cnt++; |
| 99018 | + pMatch = 0; |
| 99011 | 99019 | #ifndef SQLITE_OMIT_UPSERT |
| 99012 | 99020 | if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){ |
| 99013 | 99021 | testcase( iCol==(-1) ); |
| 99014 | 99022 | if( IN_RENAME_OBJECT ){ |
| 99015 | 99023 | pExpr->iColumn = iCol; |
| | @@ -99024,12 +99032,12 @@ |
| 99024 | 99032 | #endif /* SQLITE_OMIT_UPSERT */ |
| 99025 | 99033 | { |
| 99026 | 99034 | pExpr->y.pTab = pTab; |
| 99027 | 99035 | if( pParse->bReturning ){ |
| 99028 | 99036 | eNewExprOp = TK_REGISTER; |
| 99029 | | - pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable |
| 99030 | | - + iCol + 1; |
| 99037 | + pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable + |
| 99038 | + sqlite3TableColumnToStorage(pTab, iCol) + 1; |
| 99031 | 99039 | }else{ |
| 99032 | 99040 | pExpr->iColumn = (i16)iCol; |
| 99033 | 99041 | eNewExprOp = TK_TRIGGER; |
| 99034 | 99042 | #ifndef SQLITE_OMIT_TRIGGER |
| 99035 | 99043 | if( iCol<0 ){ |
| | @@ -99225,15 +99233,17 @@ |
| 99225 | 99233 | pExpr->op = eNewExprOp; |
| 99226 | 99234 | ExprSetProperty(pExpr, EP_Leaf); |
| 99227 | 99235 | lookupname_end: |
| 99228 | 99236 | if( cnt==1 ){ |
| 99229 | 99237 | assert( pNC!=0 ); |
| 99238 | +#ifndef SQLITE_OMIT_AUTHORIZATION |
| 99230 | 99239 | if( pParse->db->xAuth |
| 99231 | 99240 | && (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER) |
| 99232 | 99241 | ){ |
| 99233 | 99242 | sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); |
| 99234 | 99243 | } |
| 99244 | +#endif |
| 99235 | 99245 | /* Increment the nRef value on all name contexts from TopNC up to |
| 99236 | 99246 | ** the point where the name matched. */ |
| 99237 | 99247 | for(;;){ |
| 99238 | 99248 | assert( pTopNC!=0 ); |
| 99239 | 99249 | pTopNC->nRef++; |
| | @@ -99374,20 +99384,23 @@ |
| 99374 | 99384 | pExpr->iColumn--; |
| 99375 | 99385 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 99376 | 99386 | break; |
| 99377 | 99387 | } |
| 99378 | 99388 | |
| 99379 | | - /* An "<expr> IS NOT NULL" or "<expr> IS NULL". After resolving the |
| 99380 | | - ** LHS, check if there is a NOT NULL constraint in the schema that |
| 99381 | | - ** means the value of the expression can be determined immediately. |
| 99382 | | - ** If that is the case, replace the current expression node with |
| 99383 | | - ** a TK_TRUEFALSE node. |
| 99389 | + /* An optimization: Attempt to convert |
| 99384 | 99390 | ** |
| 99385 | | - ** If the node is replaced with a TK_TRUEFALSE node, then also restore |
| 99386 | | - ** the NameContext ref-counts to the state they where in before the |
| 99387 | | - ** LHS expression was resolved. This prevents the current select |
| 99388 | | - ** from being erroneously marked as correlated in some cases. |
| 99391 | + ** "expr IS NOT NULL" --> "TRUE" |
| 99392 | + ** "expr IS NULL" --> "FALSE" |
| 99393 | + ** |
| 99394 | + ** if we can prove that "expr" is never NULL. Call this the |
| 99395 | + ** "NOT NULL strength reduction optimization". |
| 99396 | + ** |
| 99397 | + ** If this optimization occurs, also restore the NameContext ref-counts |
| 99398 | + ** to the state they where in before the "column" LHS expression was |
| 99399 | + ** resolved. This prevents "column" from being counted as having been |
| 99400 | + ** referenced, which might prevent a SELECT from being erroneously |
| 99401 | + ** marked as correlated. |
| 99389 | 99402 | */ |
| 99390 | 99403 | case TK_NOTNULL: |
| 99391 | 99404 | case TK_ISNULL: { |
| 99392 | 99405 | int anRef[8]; |
| 99393 | 99406 | NameContext *p; |
| | @@ -99394,11 +99407,11 @@ |
| 99394 | 99407 | int i; |
| 99395 | 99408 | for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){ |
| 99396 | 99409 | anRef[i] = p->nRef; |
| 99397 | 99410 | } |
| 99398 | 99411 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 99399 | | - if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) ){ |
| 99412 | + if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){ |
| 99400 | 99413 | if( pExpr->op==TK_NOTNULL ){ |
| 99401 | 99414 | pExpr->u.zToken = "true"; |
| 99402 | 99415 | ExprSetProperty(pExpr, EP_IsTrue); |
| 99403 | 99416 | }else{ |
| 99404 | 99417 | pExpr->u.zToken = "false"; |
| | @@ -99639,10 +99652,11 @@ |
| 99639 | 99652 | if( pWin ){ |
| 99640 | 99653 | Select *pSel = pNC->pWinSelect; |
| 99641 | 99654 | assert( pWin==pExpr->y.pWin ); |
| 99642 | 99655 | if( IN_RENAME_OBJECT==0 ){ |
| 99643 | 99656 | sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef); |
| 99657 | + if( pParse->db->mallocFailed ) break; |
| 99644 | 99658 | } |
| 99645 | 99659 | sqlite3WalkExprList(pWalker, pWin->pPartition); |
| 99646 | 99660 | sqlite3WalkExprList(pWalker, pWin->pOrderBy); |
| 99647 | 99661 | sqlite3WalkExpr(pWalker, pWin->pFilter); |
| 99648 | 99662 | sqlite3WindowLink(pSel, pWin); |
| | @@ -99713,11 +99727,11 @@ |
| 99713 | 99727 | case TK_ISNOT: { |
| 99714 | 99728 | Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight); |
| 99715 | 99729 | assert( !ExprHasProperty(pExpr, EP_Reduced) ); |
| 99716 | 99730 | /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE", |
| 99717 | 99731 | ** and "x IS NOT FALSE". */ |
| 99718 | | - if( pRight && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){ |
| 99732 | + if( ALWAYS(pRight) && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){ |
| 99719 | 99733 | int rc = resolveExprStep(pWalker, pRight); |
| 99720 | 99734 | if( rc==WRC_Abort ) return WRC_Abort; |
| 99721 | 99735 | if( pRight->op==TK_TRUEFALSE ){ |
| 99722 | 99736 | pExpr->op2 = pExpr->op; |
| 99723 | 99737 | pExpr->op = TK_TRUTH; |
| | @@ -107942,13 +107956,12 @@ |
| 107942 | 107956 | } |
| 107943 | 107957 | if( rc==SQLITE_OK ){ |
| 107944 | 107958 | rc = sqlite3ResolveExprListNames(&sNC, pStep->pExprList); |
| 107945 | 107959 | } |
| 107946 | 107960 | assert( !pStep->pUpsert || (!pStep->pWhere && !pStep->pExprList) ); |
| 107947 | | - if( pStep->pUpsert ){ |
| 107961 | + if( pStep->pUpsert && rc==SQLITE_OK ){ |
| 107948 | 107962 | Upsert *pUpsert = pStep->pUpsert; |
| 107949 | | - assert( rc==SQLITE_OK ); |
| 107950 | 107963 | pUpsert->pUpsertSrc = pSrc; |
| 107951 | 107964 | sNC.uNC.pUpsert = pUpsert; |
| 107952 | 107965 | sNC.ncFlags = NC_UUpsert; |
| 107953 | 107966 | rc = sqlite3ResolveExprListNames(&sNC, pUpsert->pUpsertTarget); |
| 107954 | 107967 | if( rc==SQLITE_OK ){ |
| | @@ -108504,14 +108517,15 @@ |
| 108504 | 108517 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 108505 | 108518 | sqlite3_xauth xAuth = db->xAuth; |
| 108506 | 108519 | db->xAuth = 0; |
| 108507 | 108520 | #endif |
| 108508 | 108521 | |
| 108522 | + UNUSED_PARAMETER(NotUsed); |
| 108509 | 108523 | rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1); |
| 108510 | 108524 | if( rc!=SQLITE_OK ) goto drop_column_done; |
| 108511 | 108525 | pTab = sParse.pNewTable; |
| 108512 | | - if( pTab->nCol==1 || iCol>=pTab->nCol ){ |
| 108526 | + if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){ |
| 108513 | 108527 | /* This can happen if the sqlite_schema table is corrupt */ |
| 108514 | 108528 | rc = SQLITE_CORRUPT_BKPT; |
| 108515 | 108529 | goto drop_column_done; |
| 108516 | 108530 | } |
| 108517 | 108531 | |
| | @@ -112815,10 +112829,11 @@ |
| 112815 | 112829 | pParse->u1.pReturning = pRet; |
| 112816 | 112830 | pRet->pParse = pParse; |
| 112817 | 112831 | pRet->pReturnEL = pList; |
| 112818 | 112832 | sqlite3ParserAddCleanup(pParse, |
| 112819 | 112833 | (void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet); |
| 112834 | + testcase( pParse->earlyCleanup ); |
| 112820 | 112835 | if( db->mallocFailed ) return; |
| 112821 | 112836 | pRet->retTrig.zName = RETURNING_TRIGGER_NAME; |
| 112822 | 112837 | pRet->retTrig.op = TK_RETURNING; |
| 112823 | 112838 | pRet->retTrig.tr_tm = TRIGGER_AFTER; |
| 112824 | 112839 | pRet->retTrig.bReturning = 1; |
| | @@ -130625,17 +130640,25 @@ |
| 130625 | 130640 | ** for common cleanups that happen on most calls. But for less |
| 130626 | 130641 | ** common cleanups, we save a single NULL-pointer comparison in |
| 130627 | 130642 | ** sqlite3ParserReset(), which reduces the total CPU cycle count. |
| 130628 | 130643 | ** |
| 130629 | 130644 | ** If a memory allocation error occurs, then the cleanup happens immediately. |
| 130630 | | -** When eithr SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the |
| 130645 | +** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the |
| 130631 | 130646 | ** pParse->earlyCleanup flag is set in that case. Calling code show verify |
| 130632 | 130647 | ** that test cases exist for which this happens, to guard against possible |
| 130633 | 130648 | ** use-after-free errors following an OOM. The preferred way to do this is |
| 130634 | 130649 | ** to immediately follow the call to this routine with: |
| 130635 | 130650 | ** |
| 130636 | 130651 | ** testcase( pParse->earlyCleanup ); |
| 130652 | +** |
| 130653 | +** This routine returns a copy of its pPtr input (the third parameter) |
| 130654 | +** except if an early cleanup occurs, in which case it returns NULL. So |
| 130655 | +** another way to check for early cleanup is to check the return value. |
| 130656 | +** Or, stop using the pPtr parameter with this call and use only its |
| 130657 | +** return value thereafter. Something like this: |
| 130658 | +** |
| 130659 | +** pObj = sqlite3ParserAddCleanup(pParse, destructor, pObj); |
| 130637 | 130660 | */ |
| 130638 | 130661 | SQLITE_PRIVATE void *sqlite3ParserAddCleanup( |
| 130639 | 130662 | Parse *pParse, /* Destroy when this Parser finishes */ |
| 130640 | 130663 | void (*xCleanup)(sqlite3*,void*), /* The cleanup routine */ |
| 130641 | 130664 | void *pPtr /* Pointer to object to be cleaned up */ |
| | @@ -131129,16 +131152,20 @@ |
| 131129 | 131152 | sqlite3ExprDelete(db, p->pWhere); |
| 131130 | 131153 | sqlite3ExprListDelete(db, p->pGroupBy); |
| 131131 | 131154 | sqlite3ExprDelete(db, p->pHaving); |
| 131132 | 131155 | sqlite3ExprListDelete(db, p->pOrderBy); |
| 131133 | 131156 | sqlite3ExprDelete(db, p->pLimit); |
| 131157 | + if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith); |
| 131134 | 131158 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 131135 | 131159 | if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){ |
| 131136 | 131160 | sqlite3WindowListDelete(db, p->pWinDefn); |
| 131137 | 131161 | } |
| 131162 | + while( p->pWin ){ |
| 131163 | + assert( p->pWin->ppThis==&p->pWin ); |
| 131164 | + sqlite3WindowUnlinkFromSelect(p->pWin); |
| 131165 | + } |
| 131138 | 131166 | #endif |
| 131139 | | - if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith); |
| 131140 | 131167 | if( bFree ) sqlite3DbFreeNN(db, p); |
| 131141 | 131168 | p = pPrior; |
| 131142 | 131169 | bFree = 1; |
| 131143 | 131170 | } |
| 131144 | 131171 | } |
| | @@ -132430,11 +132457,11 @@ |
| 132430 | 132457 | } |
| 132431 | 132458 | |
| 132432 | 132459 | /* |
| 132433 | 132460 | ** Name of the connection operator, used for error messages. |
| 132434 | 132461 | */ |
| 132435 | | -static const char *selectOpName(int id){ |
| 132462 | +SQLITE_PRIVATE const char *sqlite3SelectOpName(int id){ |
| 132436 | 132463 | char *z; |
| 132437 | 132464 | switch( id ){ |
| 132438 | 132465 | case TK_ALL: z = "UNION ALL"; break; |
| 132439 | 132466 | case TK_INTERSECT: z = "INTERSECT"; break; |
| 132440 | 132467 | case TK_EXCEPT: z = "EXCEPT"; break; |
| | @@ -133649,16 +133676,12 @@ |
| 133649 | 133676 | assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION ); |
| 133650 | 133677 | assert( p->selFlags & SF_Compound ); |
| 133651 | 133678 | db = pParse->db; |
| 133652 | 133679 | pPrior = p->pPrior; |
| 133653 | 133680 | dest = *pDest; |
| 133654 | | - if( pPrior->pOrderBy || pPrior->pLimit ){ |
| 133655 | | - sqlite3ErrorMsg(pParse,"%s clause should come after %s not before", |
| 133656 | | - pPrior->pOrderBy!=0 ? "ORDER BY" : "LIMIT", selectOpName(p->op)); |
| 133657 | | - rc = 1; |
| 133658 | | - goto multi_select_end; |
| 133659 | | - } |
| 133681 | + assert( pPrior->pOrderBy==0 ); |
| 133682 | + assert( pPrior->pLimit==0 ); |
| 133660 | 133683 | |
| 133661 | 133684 | v = sqlite3GetVdbe(pParse); |
| 133662 | 133685 | assert( v!=0 ); /* The VDBE already created by calling function */ |
| 133663 | 133686 | |
| 133664 | 133687 | /* Create the destination temporary table if necessary |
| | @@ -133711,11 +133734,11 @@ |
| 133711 | 133734 | assert( !pPrior->pLimit ); |
| 133712 | 133735 | pPrior->iLimit = p->iLimit; |
| 133713 | 133736 | pPrior->iOffset = p->iOffset; |
| 133714 | 133737 | pPrior->pLimit = p->pLimit; |
| 133715 | 133738 | rc = sqlite3Select(pParse, pPrior, &dest); |
| 133716 | | - p->pLimit = 0; |
| 133739 | + pPrior->pLimit = 0; |
| 133717 | 133740 | if( rc ){ |
| 133718 | 133741 | goto multi_select_end; |
| 133719 | 133742 | } |
| 133720 | 133743 | p->pPrior = 0; |
| 133721 | 133744 | p->iLimit = pPrior->iLimit; |
| | @@ -133732,12 +133755,12 @@ |
| 133732 | 133755 | rc = sqlite3Select(pParse, p, &dest); |
| 133733 | 133756 | testcase( rc!=SQLITE_OK ); |
| 133734 | 133757 | pDelete = p->pPrior; |
| 133735 | 133758 | p->pPrior = pPrior; |
| 133736 | 133759 | p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow); |
| 133737 | | - if( pPrior->pLimit |
| 133738 | | - && sqlite3ExprIsInteger(pPrior->pLimit->pLeft, &nLimit) |
| 133760 | + if( p->pLimit |
| 133761 | + && sqlite3ExprIsInteger(p->pLimit->pLeft, &nLimit) |
| 133739 | 133762 | && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit) |
| 133740 | 133763 | ){ |
| 133741 | 133764 | p->nSelectRow = sqlite3LogEst((u64)nLimit); |
| 133742 | 133765 | } |
| 133743 | 133766 | if( addr ){ |
| | @@ -133797,11 +133820,11 @@ |
| 133797 | 133820 | p->pPrior = 0; |
| 133798 | 133821 | pLimit = p->pLimit; |
| 133799 | 133822 | p->pLimit = 0; |
| 133800 | 133823 | uniondest.eDest = op; |
| 133801 | 133824 | ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE", |
| 133802 | | - selectOpName(p->op))); |
| 133825 | + sqlite3SelectOpName(p->op))); |
| 133803 | 133826 | rc = sqlite3Select(pParse, p, &uniondest); |
| 133804 | 133827 | testcase( rc!=SQLITE_OK ); |
| 133805 | 133828 | assert( p->pOrderBy==0 ); |
| 133806 | 133829 | pDelete = p->pPrior; |
| 133807 | 133830 | p->pPrior = pPrior; |
| | @@ -133873,11 +133896,11 @@ |
| 133873 | 133896 | p->pPrior = 0; |
| 133874 | 133897 | pLimit = p->pLimit; |
| 133875 | 133898 | p->pLimit = 0; |
| 133876 | 133899 | intersectdest.iSDParm = tab2; |
| 133877 | 133900 | ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE", |
| 133878 | | - selectOpName(p->op))); |
| 133901 | + sqlite3SelectOpName(p->op))); |
| 133879 | 133902 | rc = sqlite3Select(pParse, p, &intersectdest); |
| 133880 | 133903 | testcase( rc!=SQLITE_OK ); |
| 133881 | 133904 | pDelete = p->pPrior; |
| 133882 | 133905 | p->pPrior = pPrior; |
| 133883 | 133906 | if( p->nSelectRow>pPrior->nSelectRow ){ |
| | @@ -133982,11 +134005,12 @@ |
| 133982 | 134005 | SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p){ |
| 133983 | 134006 | if( p->selFlags & SF_Values ){ |
| 133984 | 134007 | sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms"); |
| 133985 | 134008 | }else{ |
| 133986 | 134009 | sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s" |
| 133987 | | - " do not have the same number of result columns", selectOpName(p->op)); |
| 134010 | + " do not have the same number of result columns", |
| 134011 | + sqlite3SelectOpName(p->op)); |
| 133988 | 134012 | } |
| 133989 | 134013 | } |
| 133990 | 134014 | |
| 133991 | 134015 | /* |
| 133992 | 134016 | ** Code an output subroutine for a coroutine implementation of a |
| | @@ -134079,14 +134103,12 @@ |
| 134079 | 134103 | ** store the results in the appropriate memory cell and break out |
| 134080 | 134104 | ** of the scan loop. Note that the select might return multiple columns |
| 134081 | 134105 | ** if it is the RHS of a row-value IN operator. |
| 134082 | 134106 | */ |
| 134083 | 134107 | case SRT_Mem: { |
| 134084 | | - if( pParse->nErr==0 ){ |
| 134085 | | - testcase( pIn->nSdst>1 ); |
| 134086 | | - sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, pIn->nSdst); |
| 134087 | | - } |
| 134108 | + testcase( pIn->nSdst>1 ); |
| 134109 | + sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, pIn->nSdst); |
| 134088 | 134110 | /* The LIMIT clause will jump out of the loop for us */ |
| 134089 | 134111 | break; |
| 134090 | 134112 | } |
| 134091 | 134113 | #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ |
| 134092 | 134114 | |
| | @@ -134374,11 +134396,11 @@ |
| 134374 | 134396 | regOutA = ++pParse->nMem; |
| 134375 | 134397 | regOutB = ++pParse->nMem; |
| 134376 | 134398 | sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA); |
| 134377 | 134399 | sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB); |
| 134378 | 134400 | |
| 134379 | | - ExplainQueryPlan((pParse, 1, "MERGE (%s)", selectOpName(p->op))); |
| 134401 | + ExplainQueryPlan((pParse, 1, "MERGE (%s)", sqlite3SelectOpName(p->op))); |
| 134380 | 134402 | |
| 134381 | 134403 | /* Generate a coroutine to evaluate the SELECT statement to the |
| 134382 | 134404 | ** left of the compound operator - the "A" select. |
| 134383 | 134405 | */ |
| 134384 | 134406 | addrSelectA = sqlite3VdbeCurrentAddr(v) + 1; |
| | @@ -136299,11 +136321,14 @@ |
| 136299 | 136321 | if( IsVirtual(pTab) || pTab->pSelect ){ |
| 136300 | 136322 | i16 nCol; |
| 136301 | 136323 | u8 eCodeOrig = pWalker->eCode; |
| 136302 | 136324 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| 136303 | 136325 | assert( pFrom->pSelect==0 ); |
| 136304 | | - if( pTab->pSelect && (db->flags & SQLITE_EnableView)==0 ){ |
| 136326 | + if( pTab->pSelect |
| 136327 | + && (db->flags & SQLITE_EnableView)==0 |
| 136328 | + && pTab->pSchema!=db->aDb[1].pSchema |
| 136329 | + ){ |
| 136305 | 136330 | sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited", |
| 136306 | 136331 | pTab->zName); |
| 136307 | 136332 | } |
| 136308 | 136333 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 136309 | 136334 | if( IsVirtual(pTab) |
| | @@ -137078,12 +137103,23 @@ |
| 137078 | 137103 | if( IgnorableDistinct(pDest) ){ |
| 137079 | 137104 | assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union || |
| 137080 | 137105 | pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard || |
| 137081 | 137106 | pDest->eDest==SRT_DistQueue || pDest->eDest==SRT_DistFifo ); |
| 137082 | 137107 | /* All of these destinations are also able to ignore the ORDER BY clause */ |
| 137083 | | - sqlite3ExprListDelete(db, p->pOrderBy); |
| 137084 | | - p->pOrderBy = 0; |
| 137108 | + if( p->pOrderBy ){ |
| 137109 | +#if SELECTTRACE_ENABLED |
| 137110 | + SELECTTRACE(1,pParse,p, ("dropping superfluous ORDER BY:\n")); |
| 137111 | + if( sqlite3SelectTrace & 0x100 ){ |
| 137112 | + sqlite3TreeViewExprList(0, p->pOrderBy, 0, "ORDERBY"); |
| 137113 | + } |
| 137114 | +#endif |
| 137115 | + sqlite3ParserAddCleanup(pParse, |
| 137116 | + (void(*)(sqlite3*,void*))sqlite3ExprListDelete, |
| 137117 | + p->pOrderBy); |
| 137118 | + testcase( pParse->earlyCleanup ); |
| 137119 | + p->pOrderBy = 0; |
| 137120 | + } |
| 137085 | 137121 | p->selFlags &= ~SF_Distinct; |
| 137086 | 137122 | p->selFlags |= SF_NoopOrderBy; |
| 137087 | 137123 | } |
| 137088 | 137124 | sqlite3SelectPrep(pParse, p, 0); |
| 137089 | 137125 | if( pParse->nErr || db->mallocFailed ){ |
| | @@ -137698,10 +137734,11 @@ |
| 137698 | 137734 | */ |
| 137699 | 137735 | pAggInfo = sqlite3DbMallocZero(db, sizeof(*pAggInfo) ); |
| 137700 | 137736 | if( pAggInfo ){ |
| 137701 | 137737 | sqlite3ParserAddCleanup(pParse, |
| 137702 | 137738 | (void(*)(sqlite3*,void*))agginfoFree, pAggInfo); |
| 137739 | + testcase( pParse->earlyCleanup ); |
| 137703 | 137740 | } |
| 137704 | 137741 | if( db->mallocFailed ){ |
| 137705 | 137742 | goto select_end; |
| 137706 | 137743 | } |
| 137707 | 137744 | pAggInfo->selId = p->selId; |
| | @@ -147454,11 +147491,14 @@ |
| 147454 | 147491 | sqlite3 *db = pParse->db; |
| 147455 | 147492 | |
| 147456 | 147493 | assert( pExpr->op==TK_EXISTS ); |
| 147457 | 147494 | assert( (pExpr->flags & EP_VarSelect) && (pExpr->flags & EP_xIsSelect) ); |
| 147458 | 147495 | |
| 147459 | | - if( (pSel->selFlags & SF_Aggregate) || pSel->pWin ) return; |
| 147496 | + if( pSel->selFlags & SF_Aggregate ) return; |
| 147497 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 147498 | + if( pSel->pWin ) return; |
| 147499 | +#endif |
| 147460 | 147500 | if( pSel->pPrior ) return; |
| 147461 | 147501 | if( pSel->pWhere==0 ) return; |
| 147462 | 147502 | if( 0==exprAnalyzeExistsFindEq(pSel, 0, 0) ) return; |
| 147463 | 147503 | |
| 147464 | 147504 | pDup = sqlite3ExprDup(db, pExpr, 0); |
| | @@ -155837,10 +155877,11 @@ |
| 155837 | 155877 | int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */ |
| 155838 | 155878 | int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */ |
| 155839 | 155879 | int regString = ++pParse->nMem; /* Reg. for constant value '' */ |
| 155840 | 155880 | int arith = OP_Add; /* OP_Add or OP_Subtract */ |
| 155841 | 155881 | int addrGe; /* Jump destination */ |
| 155882 | + CollSeq *pColl; |
| 155842 | 155883 | |
| 155843 | 155884 | assert( op==OP_Ge || op==OP_Gt || op==OP_Le ); |
| 155844 | 155885 | assert( pOrderBy && pOrderBy->nExpr==1 ); |
| 155845 | 155886 | if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){ |
| 155846 | 155887 | switch( op ){ |
| | @@ -155927,10 +155968,12 @@ |
| 155927 | 155968 | |
| 155928 | 155969 | /* Compare registers reg2 and reg1, taking the jump if required. Note that |
| 155929 | 155970 | ** control skips over this test if the BIGNULL flag is set and either |
| 155930 | 155971 | ** reg1 or reg2 contain a NULL value. */ |
| 155931 | 155972 | sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v); |
| 155973 | + pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr); |
| 155974 | + sqlite3VdbeAppendP4(v, (void*)pColl, P4_COLLSEQ); |
| 155932 | 155975 | sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); |
| 155933 | 155976 | |
| 155934 | 155977 | assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le ); |
| 155935 | 155978 | testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge); |
| 155936 | 155979 | testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt); |
| | @@ -156933,15 +156976,25 @@ |
| 156933 | 156976 | ** SQLITE_LIMIT_COMPOUND_SELECT. |
| 156934 | 156977 | */ |
| 156935 | 156978 | static void parserDoubleLinkSelect(Parse *pParse, Select *p){ |
| 156936 | 156979 | assert( p!=0 ); |
| 156937 | 156980 | if( p->pPrior ){ |
| 156938 | | - Select *pNext = 0, *pLoop; |
| 156939 | | - int mxSelect, cnt = 0; |
| 156940 | | - for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ |
| 156981 | + Select *pNext = 0, *pLoop = p; |
| 156982 | + int mxSelect, cnt = 1; |
| 156983 | + while(1){ |
| 156941 | 156984 | pLoop->pNext = pNext; |
| 156942 | 156985 | pLoop->selFlags |= SF_Compound; |
| 156986 | + pNext = pLoop; |
| 156987 | + pLoop = pLoop->pPrior; |
| 156988 | + if( pLoop==0 ) break; |
| 156989 | + cnt++; |
| 156990 | + if( pLoop->pOrderBy || pLoop->pLimit ){ |
| 156991 | + sqlite3ErrorMsg(pParse,"%s clause should come after %s not before", |
| 156992 | + pLoop->pOrderBy!=0 ? "ORDER BY" : "LIMIT", |
| 156993 | + sqlite3SelectOpName(pNext->op)); |
| 156994 | + break; |
| 156995 | + } |
| 156943 | 156996 | } |
| 156944 | 156997 | if( (p->selFlags & SF_MultiValue)==0 && |
| 156945 | 156998 | (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 && |
| 156946 | 156999 | cnt>mxSelect |
| 156947 | 157000 | ){ |
| | @@ -175033,13 +175086,13 @@ |
| 175033 | 175086 | res = fts3PoslistNearMerge( |
| 175034 | 175087 | &pOut, aTmp, nParam1, nParam2, paPoslist, &p2 |
| 175035 | 175088 | ); |
| 175036 | 175089 | if( res ){ |
| 175037 | 175090 | nNew = (int)(pOut - pPhrase->doclist.pList) - 1; |
| 175038 | | - if( nNew>=0 ){ |
| 175091 | + assert_fts3_nc( nNew<=pPhrase->doclist.nList && nNew>0 ); |
| 175092 | + if( nNew>=0 && nNew<=pPhrase->doclist.nList ){ |
| 175039 | 175093 | assert( pPhrase->doclist.pList[nNew]=='\0' ); |
| 175040 | | - assert( nNew<=pPhrase->doclist.nList && nNew>0 ); |
| 175041 | 175094 | memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew); |
| 175042 | 175095 | pPhrase->doclist.nList = nNew; |
| 175043 | 175096 | } |
| 175044 | 175097 | *paPoslist = pPhrase->doclist.pList; |
| 175045 | 175098 | *pnToken = pPhrase->nToken; |
| | @@ -176969,10 +177022,15 @@ |
| 176969 | 177022 | |
| 176970 | 177023 | if( sqlite3_fts3_enable_parentheses ){ |
| 176971 | 177024 | if( *zInput=='(' ){ |
| 176972 | 177025 | int nConsumed = 0; |
| 176973 | 177026 | pParse->nNest++; |
| 177027 | +#if !defined(SQLITE_MAX_EXPR_DEPTH) |
| 177028 | + if( pParse->nNest>1000 ) return SQLITE_ERROR; |
| 177029 | +#elif SQLITE_MAX_EXPR_DEPTH>0 |
| 177030 | + if( pParse->nNest>SQLITE_MAX_EXPR_DEPTH ) return SQLITE_ERROR; |
| 177031 | +#endif |
| 176974 | 177032 | rc = fts3ExprParse(pParse, zInput+1, nInput-1, ppExpr, &nConsumed); |
| 176975 | 177033 | *pnConsumed = (int)(zInput - z) + 1 + nConsumed; |
| 176976 | 177034 | return rc; |
| 176977 | 177035 | }else if( *zInput==')' ){ |
| 176978 | 177036 | pParse->nNest--; |
| | @@ -184372,31 +184430,30 @@ |
| 184372 | 184430 | if( pNode->block.a){ |
| 184373 | 184431 | rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n); |
| 184374 | 184432 | while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader); |
| 184375 | 184433 | blobGrowBuffer(&pNode->key, reader.term.n, &rc); |
| 184376 | 184434 | if( rc==SQLITE_OK ){ |
| 184377 | | - if( reader.term.n<=0 ){ |
| 184378 | | - rc = FTS_CORRUPT_VTAB; |
| 184379 | | - }else{ |
| 184435 | + assert_fts3_nc( reader.term.n>0 || reader.aNode==0 ); |
| 184436 | + if( reader.term.n>0 ){ |
| 184380 | 184437 | memcpy(pNode->key.a, reader.term.a, reader.term.n); |
| 184381 | | - pNode->key.n = reader.term.n; |
| 184382 | | - if( i>0 ){ |
| 184383 | | - char *aBlock = 0; |
| 184384 | | - int nBlock = 0; |
| 184385 | | - pNode = &pWriter->aNodeWriter[i-1]; |
| 184386 | | - pNode->iBlock = reader.iChild; |
| 184387 | | - rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0); |
| 184388 | | - blobGrowBuffer(&pNode->block, |
| 184389 | | - MAX(nBlock, p->nNodeSize)+FTS3_NODE_PADDING, &rc |
| 184390 | | - ); |
| 184391 | | - if( rc==SQLITE_OK ){ |
| 184392 | | - memcpy(pNode->block.a, aBlock, nBlock); |
| 184393 | | - pNode->block.n = nBlock; |
| 184394 | | - memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING); |
| 184395 | | - } |
| 184396 | | - sqlite3_free(aBlock); |
| 184397 | | - } |
| 184438 | + } |
| 184439 | + pNode->key.n = reader.term.n; |
| 184440 | + if( i>0 ){ |
| 184441 | + char *aBlock = 0; |
| 184442 | + int nBlock = 0; |
| 184443 | + pNode = &pWriter->aNodeWriter[i-1]; |
| 184444 | + pNode->iBlock = reader.iChild; |
| 184445 | + rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock,0); |
| 184446 | + blobGrowBuffer(&pNode->block, |
| 184447 | + MAX(nBlock, p->nNodeSize)+FTS3_NODE_PADDING, &rc |
| 184448 | + ); |
| 184449 | + if( rc==SQLITE_OK ){ |
| 184450 | + memcpy(pNode->block.a, aBlock, nBlock); |
| 184451 | + pNode->block.n = nBlock; |
| 184452 | + memset(&pNode->block.a[nBlock], 0, FTS3_NODE_PADDING); |
| 184453 | + } |
| 184454 | + sqlite3_free(aBlock); |
| 184398 | 184455 | } |
| 184399 | 184456 | } |
| 184400 | 184457 | } |
| 184401 | 184458 | nodeReaderRelease(&reader); |
| 184402 | 184459 | } |
| | @@ -224442,10 +224499,13 @@ |
| 224442 | 224499 | pIter->nPoslist = ((int)(p[0])) >> 1; |
| 224443 | 224500 | pIter->nSize = 1; |
| 224444 | 224501 | } |
| 224445 | 224502 | |
| 224446 | 224503 | pIter->aPoslist = p; |
| 224504 | + if( &pIter->aPoslist[pIter->nPoslist]>pIter->aEof ){ |
| 224505 | + pIter->aPoslist = 0; |
| 224506 | + } |
| 224447 | 224507 | } |
| 224448 | 224508 | } |
| 224449 | 224509 | |
| 224450 | 224510 | static void fts5DoclistIterInit( |
| 224451 | 224511 | Fts5Buffer *pBuf, |
| | @@ -229109,11 +229169,11 @@ |
| 229109 | 229169 | int nArg, /* Number of args */ |
| 229110 | 229170 | sqlite3_value **apUnused /* Function arguments */ |
| 229111 | 229171 | ){ |
| 229112 | 229172 | assert( nArg==0 ); |
| 229113 | 229173 | UNUSED_PARAM2(nArg, apUnused); |
| 229114 | | - sqlite3_result_text(pCtx, "fts5: 2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9c092", -1, SQLITE_TRANSIENT); |
| 229174 | + sqlite3_result_text(pCtx, "fts5: 2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303bf8b", -1, SQLITE_TRANSIENT); |
| 229115 | 229175 | } |
| 229116 | 229176 | |
| 229117 | 229177 | /* |
| 229118 | 229178 | ** Return true if zName is the extension on one of the shadow tables used |
| 229119 | 229179 | ** by this module. |
| | @@ -234035,12 +234095,12 @@ |
| 234035 | 234095 | } |
| 234036 | 234096 | #endif /* SQLITE_CORE */ |
| 234037 | 234097 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 234038 | 234098 | |
| 234039 | 234099 | /************** End of stmt.c ************************************************/ |
| 234040 | | -#if __LINE__!=234040 |
| 234100 | +#if __LINE__!=234100 |
| 234041 | 234101 | #undef SQLITE_SOURCE_ID |
| 234042 | | -#define SQLITE_SOURCE_ID "2021-03-01 16:16:59 39c8686cabe6c437ba4860aade49a701c4f5772b97d9fbe6cb9a394e85b9alt2" |
| 234102 | +#define SQLITE_SOURCE_ID "2021-03-09 21:20:12 9645fe1a050e8b61aea1fba2f142819c387ecb043741392c5719bf7ad303alt2" |
| 234043 | 234103 | #endif |
| 234044 | 234104 | /* Return the source-id for this library */ |
| 234045 | 234105 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 234046 | 234106 | /************************** End of sqlite3.c ******************************/ |
| 234047 | 234107 | |