| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.35.2. By combining all the individual C code files into this |
| 3 | +** version 3.35.3. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -1184,13 +1184,13 @@ |
| 1184 | 1184 | ** |
| 1185 | 1185 | ** See also: [sqlite3_libversion()], |
| 1186 | 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | 1188 | */ |
| 1189 | | -#define SQLITE_VERSION "3.35.2" |
| 1190 | | -#define SQLITE_VERSION_NUMBER 3035002 |
| 1191 | | -#define SQLITE_SOURCE_ID "2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50c3827" |
| 1189 | +#define SQLITE_VERSION "3.35.3" |
| 1190 | +#define SQLITE_VERSION_NUMBER 3035003 |
| 1191 | +#define SQLITE_SOURCE_ID "2021-03-21 18:23:48 6bb2134027a12801de8e0c73482d94682f902024800a7e426614f65a2fe4f64c" |
| 1192 | 1192 | |
| 1193 | 1193 | /* |
| 1194 | 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | 1196 | ** |
| | @@ -21069,10 +21069,11 @@ |
| 21069 | 21069 | u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */ |
| 21070 | 21070 | #endif |
| 21071 | 21071 | Bool isEphemeral:1; /* True for an ephemeral table */ |
| 21072 | 21072 | Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */ |
| 21073 | 21073 | Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */ |
| 21074 | + Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */ |
| 21074 | 21075 | u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */ |
| 21075 | 21076 | Btree *pBtx; /* Separate file holding temporary table */ |
| 21076 | 21077 | i64 seqCount; /* Sequence counter */ |
| 21077 | 21078 | u32 *aAltMap; /* Mapping from table to index column numbers */ |
| 21078 | 21079 | |
| | @@ -40218,11 +40219,12 @@ |
| 40218 | 40219 | */ |
| 40219 | 40220 | static int unixBackupDir(const char *z, int *pJ){ |
| 40220 | 40221 | int j = *pJ; |
| 40221 | 40222 | int i; |
| 40222 | 40223 | if( j<=0 ) return 0; |
| 40223 | | - for(i=j-1; ALWAYS(i>0) && z[i-1]!='/'; i--){} |
| 40224 | + for(i=j-1; i>0 && z[i-1]!='/'; i--){} |
| 40225 | + if( i==0 ) return 0; |
| 40224 | 40226 | if( z[i]=='.' && i==j-2 && z[i+1]=='.' ) return 0; |
| 40225 | 40227 | *pJ = i-1; |
| 40226 | 40228 | return 1; |
| 40227 | 40229 | } |
| 40228 | 40230 | |
| | @@ -64275,11 +64277,11 @@ |
| 64275 | 64277 | u8 sharable; /* True if we can share pBt with another db */ |
| 64276 | 64278 | u8 locked; /* True if db currently has pBt locked */ |
| 64277 | 64279 | u8 hasIncrblobCur; /* True if there are one or more Incrblob cursors */ |
| 64278 | 64280 | int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */ |
| 64279 | 64281 | int nBackup; /* Number of backup operations reading this btree */ |
| 64280 | | - u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */ |
| 64282 | + u32 iBDataVersion; /* Combines with pBt->pPager->iDataVersion */ |
| 64281 | 64283 | Btree *pNext; /* List of other sharable Btrees from the same db */ |
| 64282 | 64284 | Btree *pPrev; /* Back pointer of the same list */ |
| 64283 | 64285 | #ifdef SQLITE_DEBUG |
| 64284 | 64286 | u64 nSeek; /* Calls to sqlite3BtreeMovetoUnpacked() */ |
| 64285 | 64287 | #endif |
| | @@ -67688,23 +67690,27 @@ |
| 67688 | 67690 | /* |
| 67689 | 67691 | ** Close an open database and invalidate all cursors. |
| 67690 | 67692 | */ |
| 67691 | 67693 | SQLITE_PRIVATE int sqlite3BtreeClose(Btree *p){ |
| 67692 | 67694 | BtShared *pBt = p->pBt; |
| 67693 | | - BtCursor *pCur; |
| 67694 | 67695 | |
| 67695 | 67696 | /* Close all cursors opened via this handle. */ |
| 67696 | 67697 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 67697 | 67698 | sqlite3BtreeEnter(p); |
| 67698 | | - pCur = pBt->pCursor; |
| 67699 | | - while( pCur ){ |
| 67700 | | - BtCursor *pTmp = pCur; |
| 67701 | | - pCur = pCur->pNext; |
| 67702 | | - if( pTmp->pBtree==p ){ |
| 67703 | | - sqlite3BtreeCloseCursor(pTmp); |
| 67699 | + |
| 67700 | + /* Verify that no other cursors have this Btree open */ |
| 67701 | +#ifdef SQLITE_DEBUG |
| 67702 | + { |
| 67703 | + BtCursor *pCur = pBt->pCursor; |
| 67704 | + while( pCur ){ |
| 67705 | + BtCursor *pTmp = pCur; |
| 67706 | + pCur = pCur->pNext; |
| 67707 | + assert( pTmp->pBtree!=p ); |
| 67708 | + |
| 67704 | 67709 | } |
| 67705 | 67710 | } |
| 67711 | +#endif |
| 67706 | 67712 | |
| 67707 | 67713 | /* Rollback any active transaction and free the handle structure. |
| 67708 | 67714 | ** The call to sqlite3BtreeRollback() drops any table-locks held by |
| 67709 | 67715 | ** this handle. |
| 67710 | 67716 | */ |
| | @@ -69082,11 +69088,11 @@ |
| 69082 | 69088 | rc = sqlite3PagerCommitPhaseTwo(pBt->pPager); |
| 69083 | 69089 | if( rc!=SQLITE_OK && bCleanup==0 ){ |
| 69084 | 69090 | sqlite3BtreeLeave(p); |
| 69085 | 69091 | return rc; |
| 69086 | 69092 | } |
| 69087 | | - p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */ |
| 69093 | + p->iBDataVersion--; /* Compensate for pPager->iDataVersion++; */ |
| 69088 | 69094 | pBt->inTransaction = TRANS_READ; |
| 69089 | 69095 | btreeClearHasContent(pBt); |
| 69090 | 69096 | } |
| 69091 | 69097 | |
| 69092 | 69098 | btreeEndTransaction(p); |
| | @@ -69492,11 +69498,18 @@ |
| 69492 | 69498 | } |
| 69493 | 69499 | btreeReleaseAllCursorPages(pCur); |
| 69494 | 69500 | unlockBtreeIfUnused(pBt); |
| 69495 | 69501 | sqlite3_free(pCur->aOverflow); |
| 69496 | 69502 | sqlite3_free(pCur->pKey); |
| 69497 | | - sqlite3BtreeLeave(pBtree); |
| 69503 | + if( (pBt->openFlags & BTREE_SINGLE) && pBt->pCursor==0 ){ |
| 69504 | + /* Since the BtShared is not sharable, there is no need to |
| 69505 | + ** worry about the missing sqlite3BtreeLeave() call here. */ |
| 69506 | + assert( pBtree->sharable==0 ); |
| 69507 | + sqlite3BtreeClose(pBtree); |
| 69508 | + }else{ |
| 69509 | + sqlite3BtreeLeave(pBtree); |
| 69510 | + } |
| 69498 | 69511 | pCur->pBtree = 0; |
| 69499 | 69512 | } |
| 69500 | 69513 | return SQLITE_OK; |
| 69501 | 69514 | } |
| 69502 | 69515 | |
| | @@ -74605,11 +74618,11 @@ |
| 74605 | 74618 | assert( SQLITE_OK==querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK) ); |
| 74606 | 74619 | assert( pBt->pPage1 ); |
| 74607 | 74620 | assert( idx>=0 && idx<=15 ); |
| 74608 | 74621 | |
| 74609 | 74622 | if( idx==BTREE_DATA_VERSION ){ |
| 74610 | | - *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion; |
| 74623 | + *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iBDataVersion; |
| 74611 | 74624 | }else{ |
| 74612 | 74625 | *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]); |
| 74613 | 74626 | } |
| 74614 | 74627 | |
| 74615 | 74628 | /* If auto-vacuum is disabled in this build and this is an auto-vacuum |
| | @@ -80833,24 +80846,19 @@ |
| 80833 | 80846 | SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ |
| 80834 | 80847 | if( pCx==0 ){ |
| 80835 | 80848 | return; |
| 80836 | 80849 | } |
| 80837 | 80850 | assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE ); |
| 80851 | + assert( pCx->pBtx==0 || pCx->isEphemeral ); |
| 80838 | 80852 | switch( pCx->eCurType ){ |
| 80839 | 80853 | case CURTYPE_SORTER: { |
| 80840 | 80854 | sqlite3VdbeSorterClose(p->db, pCx); |
| 80841 | 80855 | break; |
| 80842 | 80856 | } |
| 80843 | 80857 | case CURTYPE_BTREE: { |
| 80844 | | - if( pCx->isEphemeral ){ |
| 80845 | | - if( pCx->pBtx ) sqlite3BtreeClose(pCx->pBtx); |
| 80846 | | - /* The pCx->pCursor will be close automatically, if it exists, by |
| 80847 | | - ** the call above. */ |
| 80848 | | - }else{ |
| 80849 | | - assert( pCx->uc.pCursor!=0 ); |
| 80850 | | - sqlite3BtreeCloseCursor(pCx->uc.pCursor); |
| 80851 | | - } |
| 80858 | + assert( pCx->uc.pCursor!=0 ); |
| 80859 | + sqlite3BtreeCloseCursor(pCx->uc.pCursor); |
| 80852 | 80860 | break; |
| 80853 | 80861 | } |
| 80854 | 80862 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 80855 | 80863 | case CURTYPE_VTAB: { |
| 80856 | 80864 | sqlite3_vtab_cursor *pVCur = pCx->uc.pVCur; |
| | @@ -81930,10 +81938,11 @@ |
| 81930 | 81938 | SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){ |
| 81931 | 81939 | VdbeCursor *p = *pp; |
| 81932 | 81940 | assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); |
| 81933 | 81941 | if( p->deferredMoveto ){ |
| 81934 | 81942 | u32 iMap; |
| 81943 | + assert( !p->isEphemeral ); |
| 81935 | 81944 | if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){ |
| 81936 | 81945 | *pp = p->pAltCursor; |
| 81937 | 81946 | *piCol = iMap - 1; |
| 81938 | 81947 | return SQLITE_OK; |
| 81939 | 81948 | } |
| | @@ -86138,15 +86147,10 @@ |
| 86138 | 86147 | ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + |
| 86139 | 86148 | (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0); |
| 86140 | 86149 | |
| 86141 | 86150 | assert( iCur>=0 && iCur<p->nCursor ); |
| 86142 | 86151 | if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/ |
| 86143 | | - /* Before calling sqlite3VdbeFreeCursor(), ensure the isEphemeral flag |
| 86144 | | - ** is clear. Otherwise, if this is an ephemeral cursor created by |
| 86145 | | - ** OP_OpenDup, the cursor will not be closed and will still be part |
| 86146 | | - ** of a BtShared.pCursor list. */ |
| 86147 | | - if( p->apCsr[iCur]->pBtx==0 ) p->apCsr[iCur]->isEphemeral = 0; |
| 86148 | 86152 | sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); |
| 86149 | 86153 | p->apCsr[iCur] = 0; |
| 86150 | 86154 | } |
| 86151 | 86155 | if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){ |
| 86152 | 86156 | p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; |
| | @@ -89828,21 +89832,24 @@ |
| 89828 | 89832 | VdbeCursor *pOrig; /* The original cursor to be duplicated */ |
| 89829 | 89833 | VdbeCursor *pCx; /* The new cursor */ |
| 89830 | 89834 | |
| 89831 | 89835 | pOrig = p->apCsr[pOp->p2]; |
| 89832 | 89836 | assert( pOrig ); |
| 89833 | | - assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */ |
| 89837 | + assert( pOrig->isEphemeral ); /* Only ephemeral cursors can be duplicated */ |
| 89834 | 89838 | |
| 89835 | 89839 | pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE); |
| 89836 | 89840 | if( pCx==0 ) goto no_mem; |
| 89837 | 89841 | pCx->nullRow = 1; |
| 89838 | 89842 | pCx->isEphemeral = 1; |
| 89839 | 89843 | pCx->pKeyInfo = pOrig->pKeyInfo; |
| 89840 | 89844 | pCx->isTable = pOrig->isTable; |
| 89841 | 89845 | pCx->pgnoRoot = pOrig->pgnoRoot; |
| 89842 | 89846 | pCx->isOrdered = pOrig->isOrdered; |
| 89843 | | - rc = sqlite3BtreeCursor(pOrig->pBtx, pCx->pgnoRoot, BTREE_WRCSR, |
| 89847 | + pCx->pBtx = pOrig->pBtx; |
| 89848 | + pCx->hasBeenDuped = 1; |
| 89849 | + pOrig->hasBeenDuped = 1; |
| 89850 | + rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR, |
| 89844 | 89851 | pCx->pKeyInfo, pCx->uc.pCursor); |
| 89845 | 89852 | /* The sqlite3BtreeCursor() routine can only fail for the first cursor |
| 89846 | 89853 | ** opened for a database. Since there is already an open cursor when this |
| 89847 | 89854 | ** opcode is run, the sqlite3BtreeCursor() cannot fail */ |
| 89848 | 89855 | assert( rc==SQLITE_OK ); |
| | @@ -89904,13 +89911,14 @@ |
| 89904 | 89911 | assert( aMem[pOp->p3].flags & MEM_Null ); |
| 89905 | 89912 | aMem[pOp->p3].n = 0; |
| 89906 | 89913 | aMem[pOp->p3].z = ""; |
| 89907 | 89914 | } |
| 89908 | 89915 | pCx = p->apCsr[pOp->p1]; |
| 89909 | | - if( pCx && ALWAYS(pCx->pBtx) ){ |
| 89910 | | - /* If the ephermeral table is already open, erase all existing content |
| 89911 | | - ** so that the table is empty again, rather than creating a new table. */ |
| 89916 | + if( pCx && !pCx->hasBeenDuped ){ |
| 89917 | + /* If the ephermeral table is already open and has no duplicates from |
| 89918 | + ** OP_OpenDup, then erase all existing content so that the table is |
| 89919 | + ** empty again, rather than creating a new table. */ |
| 89912 | 89920 | assert( pCx->isEphemeral ); |
| 89913 | 89921 | pCx->seqCount = 0; |
| 89914 | 89922 | pCx->cacheStatus = CACHE_STALE; |
| 89915 | 89923 | rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0); |
| 89916 | 89924 | }else{ |
| | @@ -89920,37 +89928,40 @@ |
| 89920 | 89928 | rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, |
| 89921 | 89929 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, |
| 89922 | 89930 | vfsFlags); |
| 89923 | 89931 | if( rc==SQLITE_OK ){ |
| 89924 | 89932 | rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0); |
| 89925 | | - } |
| 89926 | | - if( rc==SQLITE_OK ){ |
| 89927 | | - /* If a transient index is required, create it by calling |
| 89928 | | - ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before |
| 89929 | | - ** opening it. If a transient table is required, just use the |
| 89930 | | - ** automatically created table with root-page 1 (an BLOB_INTKEY table). |
| 89931 | | - */ |
| 89932 | | - if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 89933 | | - assert( pOp->p4type==P4_KEYINFO ); |
| 89934 | | - rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot, |
| 89935 | | - BTREE_BLOBKEY | pOp->p5); |
| 89936 | | - if( rc==SQLITE_OK ){ |
| 89937 | | - assert( pCx->pgnoRoot==SCHEMA_ROOT+1 ); |
| 89938 | | - assert( pKeyInfo->db==db ); |
| 89939 | | - assert( pKeyInfo->enc==ENC(db) ); |
| 89940 | | - rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR, |
| 89941 | | - pKeyInfo, pCx->uc.pCursor); |
| 89942 | | - } |
| 89943 | | - pCx->isTable = 0; |
| 89944 | | - }else{ |
| 89945 | | - pCx->pgnoRoot = SCHEMA_ROOT; |
| 89946 | | - rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR, |
| 89947 | | - 0, pCx->uc.pCursor); |
| 89948 | | - pCx->isTable = 1; |
| 89949 | | - } |
| 89950 | | - } |
| 89951 | | - pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 89933 | + if( rc==SQLITE_OK ){ |
| 89934 | + /* If a transient index is required, create it by calling |
| 89935 | + ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before |
| 89936 | + ** opening it. If a transient table is required, just use the |
| 89937 | + ** automatically created table with root-page 1 (an BLOB_INTKEY table). |
| 89938 | + */ |
| 89939 | + if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 89940 | + assert( pOp->p4type==P4_KEYINFO ); |
| 89941 | + rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot, |
| 89942 | + BTREE_BLOBKEY | pOp->p5); |
| 89943 | + if( rc==SQLITE_OK ){ |
| 89944 | + assert( pCx->pgnoRoot==SCHEMA_ROOT+1 ); |
| 89945 | + assert( pKeyInfo->db==db ); |
| 89946 | + assert( pKeyInfo->enc==ENC(db) ); |
| 89947 | + rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR, |
| 89948 | + pKeyInfo, pCx->uc.pCursor); |
| 89949 | + } |
| 89950 | + pCx->isTable = 0; |
| 89951 | + }else{ |
| 89952 | + pCx->pgnoRoot = SCHEMA_ROOT; |
| 89953 | + rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR, |
| 89954 | + 0, pCx->uc.pCursor); |
| 89955 | + pCx->isTable = 1; |
| 89956 | + } |
| 89957 | + } |
| 89958 | + pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 89959 | + if( rc ){ |
| 89960 | + sqlite3BtreeClose(pCx->pBtx); |
| 89961 | + } |
| 89962 | + } |
| 89952 | 89963 | } |
| 89953 | 89964 | if( rc ) goto abort_due_to_error; |
| 89954 | 89965 | pCx->nullRow = 1; |
| 89955 | 89966 | break; |
| 89956 | 89967 | } |
| | @@ -90380,17 +90391,17 @@ |
| 90380 | 90391 | ** row by, perhaps by invoking sqlite3BtreeStep() on the cursor |
| 90381 | 90392 | ** between 0 and This.P1 times. |
| 90382 | 90393 | ** |
| 90383 | 90394 | ** There are three possible outcomes from this opcode:<ol> |
| 90384 | 90395 | ** |
| 90385 | | -** <li> If after This.P1 steps, the cursor is still point to a place that |
| 90386 | | -** is earlier in the btree than the target row, |
| 90387 | | -** then fall through into the subsquence OP_SeekGE opcode. |
| 90396 | +** <li> If after This.P1 steps, the cursor is still pointing to a place that |
| 90397 | +** is earlier in the btree than the target row, then fall through |
| 90398 | +** into the subsquence OP_SeekGE opcode. |
| 90388 | 90399 | ** |
| 90389 | 90400 | ** <li> If the cursor is successfully moved to the target row by 0 or more |
| 90390 | 90401 | ** sqlite3BtreeNext() calls, then jump to This.P2, which will land just |
| 90391 | | -** past the OP_IdxGT opcode that follows the OP_SeekGE. |
| 90402 | +** past the OP_IdxGT or OP_IdxGE opcode that follows the OP_SeekGE. |
| 90392 | 90403 | ** |
| 90393 | 90404 | ** <li> If the cursor ends up past the target row (indicating the the target |
| 90394 | 90405 | ** row does not exist in the btree) then jump to SeekOP.P2. |
| 90395 | 90406 | ** </ol> |
| 90396 | 90407 | */ |
| | @@ -90403,11 +90414,12 @@ |
| 90403 | 90414 | assert( pOp[1].opcode==OP_SeekGE ); |
| 90404 | 90415 | |
| 90405 | 90416 | /* pOp->p2 points to the first instruction past the OP_IdxGT that |
| 90406 | 90417 | ** follows the OP_SeekGE. */ |
| 90407 | 90418 | assert( pOp->p2>=(int)(pOp-aOp)+2 ); |
| 90408 | | - assert( aOp[pOp->p2-1].opcode==OP_IdxGT ); |
| 90419 | + assert( aOp[pOp->p2-1].opcode==OP_IdxGT || aOp[pOp->p2-1].opcode==OP_IdxGE ); |
| 90420 | + testcase( aOp[pOp->p2-1].opcode==OP_IdxGE ); |
| 90409 | 90421 | assert( pOp[1].p1==aOp[pOp->p2-1].p1 ); |
| 90410 | 90422 | assert( pOp[1].p2==aOp[pOp->p2-1].p2 ); |
| 90411 | 90423 | assert( pOp[1].p3==aOp[pOp->p2-1].p3 ); |
| 90412 | 90424 | |
| 90413 | 90425 | assert( pOp->p1>0 ); |
| | @@ -91938,10 +91950,12 @@ |
| 91938 | 91950 | pTabCur->nullRow = 0; |
| 91939 | 91951 | pTabCur->movetoTarget = rowid; |
| 91940 | 91952 | pTabCur->deferredMoveto = 1; |
| 91941 | 91953 | assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); |
| 91942 | 91954 | pTabCur->aAltMap = pOp->p4.ai; |
| 91955 | + assert( !pC->isEphemeral ); |
| 91956 | + assert( !pTabCur->isEphemeral ); |
| 91943 | 91957 | pTabCur->pAltCursor = pC; |
| 91944 | 91958 | }else{ |
| 91945 | 91959 | pOut = out2Prerelease(p, pOp); |
| 91946 | 91960 | pOut->u.i = rowid; |
| 91947 | 91961 | } |
| | @@ -115682,11 +115696,15 @@ |
| 115682 | 115696 | } |
| 115683 | 115697 | |
| 115684 | 115698 | /* Clean up before exiting */ |
| 115685 | 115699 | exit_create_index: |
| 115686 | 115700 | if( pIndex ) sqlite3FreeIndex(db, pIndex); |
| 115687 | | - if( pTab ){ /* Ensure all REPLACE indexes are at the end of the list */ |
| 115701 | + if( pTab ){ |
| 115702 | + /* Ensure all REPLACE indexes on pTab are at the end of the pIndex list. |
| 115703 | + ** The list was already ordered when this routine was entered, so at this |
| 115704 | + ** point at most a single index (the newly added index) will be out of |
| 115705 | + ** order. So we have to reorder at most one index. */ |
| 115688 | 115706 | Index **ppFrom = &pTab->pIndex; |
| 115689 | 115707 | Index *pThis; |
| 115690 | 115708 | for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){ |
| 115691 | 115709 | Index *pNext; |
| 115692 | 115710 | if( pThis->onError!=OE_Replace ) continue; |
| | @@ -115696,10 +115714,20 @@ |
| 115696 | 115714 | pNext->pNext = pThis; |
| 115697 | 115715 | ppFrom = &pNext->pNext; |
| 115698 | 115716 | } |
| 115699 | 115717 | break; |
| 115700 | 115718 | } |
| 115719 | +#ifdef SQLITE_DEBUG |
| 115720 | + /* Verify that all REPLACE indexes really are now at the end |
| 115721 | + ** of the index list. In other words, no other index type ever |
| 115722 | + ** comes after a REPLACE index on the list. */ |
| 115723 | + for(pThis = pTab->pIndex; pThis; pThis=pThis->pNext){ |
| 115724 | + assert( pThis->onError!=OE_Replace |
| 115725 | + || pThis->pNext==0 |
| 115726 | + || pThis->pNext->onError==OE_Replace ); |
| 115727 | + } |
| 115728 | +#endif |
| 115701 | 115729 | } |
| 115702 | 115730 | sqlite3ExprDelete(db, pPIWhere); |
| 115703 | 115731 | sqlite3ExprListDelete(db, pList); |
| 115704 | 115732 | sqlite3SrcListDelete(db, pTblName); |
| 115705 | 115733 | sqlite3DbFree(db, zName); |
| | @@ -123112,11 +123140,13 @@ |
| 123112 | 123140 | pNx->pUpsertSrc = pTabList; |
| 123113 | 123141 | pNx->regData = regData; |
| 123114 | 123142 | pNx->iDataCur = iDataCur; |
| 123115 | 123143 | pNx->iIdxCur = iIdxCur; |
| 123116 | 123144 | if( pNx->pUpsertTarget ){ |
| 123117 | | - sqlite3UpsertAnalyzeTarget(pParse, pTabList, pNx); |
| 123145 | + if( sqlite3UpsertAnalyzeTarget(pParse, pTabList, pNx) ){ |
| 123146 | + goto insert_cleanup; |
| 123147 | + } |
| 123118 | 123148 | } |
| 123119 | 123149 | pNx = pNx->pNextUpsert; |
| 123120 | 123150 | }while( pNx!=0 ); |
| 123121 | 123151 | } |
| 123122 | 123152 | #endif |
| | @@ -124534,11 +124564,11 @@ |
| 124534 | 124564 | int regData /* Data containing new record */ |
| 124535 | 124565 | ){ |
| 124536 | 124566 | Vdbe *v = pParse->pVdbe; |
| 124537 | 124567 | int r = sqlite3GetTempReg(pParse); |
| 124538 | 124568 | assert( !HasRowid(pTab) ); |
| 124539 | | - assert( 0==(pParse->db->mDbFlags & DBFLAG_Vacuum) ); |
| 124569 | + assert( 0==(pParse->db->mDbFlags & DBFLAG_Vacuum) || CORRUPT_DB ); |
| 124540 | 124570 | sqlite3VdbeAddOp2(v, OP_Integer, 0, r); |
| 124541 | 124571 | sqlite3VdbeAddOp4(v, OP_Insert, iCur, regData, r, (char*)pTab, P4_TABLE); |
| 124542 | 124572 | sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP); |
| 124543 | 124573 | sqlite3ReleaseTempReg(pParse, r); |
| 124544 | 124574 | } |
| | @@ -133082,11 +133112,11 @@ |
| 133082 | 133112 | sqlite3HashInit(&ht); |
| 133083 | 133113 | if( pEList ){ |
| 133084 | 133114 | nCol = pEList->nExpr; |
| 133085 | 133115 | aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol); |
| 133086 | 133116 | testcase( aCol==0 ); |
| 133087 | | - if( nCol>32767 ) nCol = 32767; |
| 133117 | + if( NEVER(nCol>32767) ) nCol = 32767; |
| 133088 | 133118 | }else{ |
| 133089 | 133119 | nCol = 0; |
| 133090 | 133120 | aCol = 0; |
| 133091 | 133121 | } |
| 133092 | 133122 | assert( nCol==(i16)nCol ); |
| | @@ -136156,20 +136186,28 @@ |
| 136156 | 136186 | |
| 136157 | 136187 | pCte->zCteErr = "circular reference: %s"; |
| 136158 | 136188 | pSavedWith = pParse->pWith; |
| 136159 | 136189 | pParse->pWith = pWith; |
| 136160 | 136190 | if( pSel->selFlags & SF_Recursive ){ |
| 136191 | + int rc; |
| 136161 | 136192 | assert( pRecTerm!=0 ); |
| 136162 | 136193 | assert( (pRecTerm->selFlags & SF_Recursive)==0 ); |
| 136163 | 136194 | assert( pRecTerm->pNext!=0 ); |
| 136164 | 136195 | assert( (pRecTerm->pNext->selFlags & SF_Recursive)!=0 ); |
| 136165 | 136196 | assert( pRecTerm->pWith==0 ); |
| 136166 | 136197 | pRecTerm->pWith = pSel->pWith; |
| 136167 | | - sqlite3WalkSelect(pWalker, pRecTerm); |
| 136198 | + rc = sqlite3WalkSelect(pWalker, pRecTerm); |
| 136168 | 136199 | pRecTerm->pWith = 0; |
| 136200 | + if( rc ){ |
| 136201 | + pParse->pWith = pSavedWith; |
| 136202 | + return 2; |
| 136203 | + } |
| 136169 | 136204 | }else{ |
| 136170 | | - sqlite3WalkSelect(pWalker, pSel); |
| 136205 | + if( sqlite3WalkSelect(pWalker, pSel) ){ |
| 136206 | + pParse->pWith = pSavedWith; |
| 136207 | + return 2; |
| 136208 | + } |
| 136171 | 136209 | } |
| 136172 | 136210 | pParse->pWith = pWith; |
| 136173 | 136211 | |
| 136174 | 136212 | for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); |
| 136175 | 136213 | pEList = pLeft->pEList; |
| | @@ -137474,11 +137512,13 @@ |
| 137474 | 137512 | sqlite3VdbeAddOp2(v, OP_Gosub, pPrior->regReturn, pPrior->addrFillSub); |
| 137475 | 137513 | } |
| 137476 | 137514 | sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor); |
| 137477 | 137515 | pSub->nSelectRow = pPrior->pSelect->nSelectRow; |
| 137478 | 137516 | }else{ |
| 137479 | | - /* Generate a subroutine that will materialize the view. */ |
| 137517 | + /* Materalize the view. If the view is not correlated, generate a |
| 137518 | + ** subroutine to do the materialization so that subsequent uses of |
| 137519 | + ** the same view can reuse the materialization. */ |
| 137480 | 137520 | int topAddr; |
| 137481 | 137521 | int onceAddr = 0; |
| 137482 | 137522 | int retAddr; |
| 137483 | 137523 | |
| 137484 | 137524 | testcase( pItem->addrFillSub==0 ); /* Ticket c52b09c7f38903b1311 */ |
| | @@ -137501,11 +137541,11 @@ |
| 137501 | 137541 | if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr); |
| 137502 | 137542 | retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn); |
| 137503 | 137543 | VdbeComment((v, "end %s", pItem->pTab->zName)); |
| 137504 | 137544 | sqlite3VdbeChangeP1(v, topAddr, retAddr); |
| 137505 | 137545 | sqlite3ClearTempRegCache(pParse); |
| 137506 | | - if( pItem->fg.isCte ){ |
| 137546 | + if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){ |
| 137507 | 137547 | CteUse *pCteUse = pItem->u2.pCteUse; |
| 137508 | 137548 | pCteUse->addrM9e = pItem->addrFillSub; |
| 137509 | 137549 | pCteUse->regRtn = pItem->regReturn; |
| 137510 | 137550 | pCteUse->iCur = pItem->iCursor; |
| 137511 | 137551 | pCteUse->nRowEst = pSub->nSelectRow; |
| | @@ -162306,11 +162346,11 @@ |
| 162306 | 162346 | /* Fx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
| 162307 | 162347 | #endif |
| 162308 | 162348 | #ifdef SQLITE_EBCDIC |
| 162309 | 162349 | /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */ |
| 162310 | 162350 | /* 0x */ 29, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 7, 7, 28, 28, |
| 162311 | | -/* 1x */ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
| 162351 | +/* 1x */ 28, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
| 162312 | 162352 | /* 2x */ 28, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
| 162313 | 162353 | /* 3x */ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
| 162314 | 162354 | /* 4x */ 7, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 12, 17, 20, 10, |
| 162315 | 162355 | /* 5x */ 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 15, 4, 21, 18, 19, 28, |
| 162316 | 162356 | /* 6x */ 11, 16, 28, 28, 28, 28, 28, 28, 28, 28, 28, 23, 22, 2, 13, 6, |
| | @@ -229211,11 +229251,11 @@ |
| 229211 | 229251 | int nArg, /* Number of args */ |
| 229212 | 229252 | sqlite3_value **apUnused /* Function arguments */ |
| 229213 | 229253 | ){ |
| 229214 | 229254 | assert( nArg==0 ); |
| 229215 | 229255 | UNUSED_PARAM2(nArg, apUnused); |
| 229216 | | - sqlite3_result_text(pCtx, "fts5: 2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50c3827", -1, SQLITE_TRANSIENT); |
| 229256 | + sqlite3_result_text(pCtx, "fts5: 2021-03-21 18:23:48 6bb2134027a12801de8e0c73482d94682f902024800a7e426614f65a2fe4f64c", -1, SQLITE_TRANSIENT); |
| 229217 | 229257 | } |
| 229218 | 229258 | |
| 229219 | 229259 | /* |
| 229220 | 229260 | ** Return true if zName is the extension on one of the shadow tables used |
| 229221 | 229261 | ** by this module. |
| | @@ -234137,12 +234177,12 @@ |
| 234137 | 234177 | } |
| 234138 | 234178 | #endif /* SQLITE_CORE */ |
| 234139 | 234179 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 234140 | 234180 | |
| 234141 | 234181 | /************** End of stmt.c ************************************************/ |
| 234142 | | -#if __LINE__!=234142 |
| 234182 | +#if __LINE__!=234182 |
| 234143 | 234183 | #undef SQLITE_SOURCE_ID |
| 234144 | | -#define SQLITE_SOURCE_ID "2021-03-17 19:07:21 ea80f3002f4120f5dcee76e8779dfdc88e1e096c5cdd06904c20fd26d50calt2" |
| 234184 | +#define SQLITE_SOURCE_ID "2021-03-21 18:23:48 6bb2134027a12801de8e0c73482d94682f902024800a7e426614f65a2fe4alt2" |
| 234145 | 234185 | #endif |
| 234146 | 234186 | /* Return the source-id for this library */ |
| 234147 | 234187 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 234148 | 234188 | /************************** End of sqlite3.c ******************************/ |
| 234149 | 234189 | |