Fossil SCM
Update the built-in SQLite to a 3.35.0 alpha that includes the revised RETURNING clause prototype that embargoes output until all changes have completed. This is for testing of SQLite. The change should not affect Fossil in any way.
Commit
1ba06268ada456d5059e325c0d18fc06362871b43384ba74c7baf5583eeeb678
Parent
7f3c728db3da63a…
2 files changed
+204
-139
+1
-1
+204
-139
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -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-02-03 13:20:12 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644d0902" | |
| 1191 | +#define SQLITE_SOURCE_ID "2021-02-05 17:34:47 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4c30c" | |
| 1192 | 1192 | |
| 1193 | 1193 | /* |
| 1194 | 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | 1196 | ** |
| @@ -16002,11 +16002,10 @@ | ||
| 16002 | 16002 | #endif |
| 16003 | 16003 | SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*); |
| 16004 | 16004 | SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*); |
| 16005 | 16005 | SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*); |
| 16006 | 16006 | SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int); |
| 16007 | -SQLITE_PRIVATE void sqlite3VdbeColumnInfoXfer(Vdbe*,Vdbe*); | |
| 16008 | 16007 | SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*)); |
| 16009 | 16008 | SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*); |
| 16010 | 16009 | SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*); |
| 16011 | 16010 | SQLITE_PRIVATE u8 sqlite3VdbePrepareFlags(Vdbe*); |
| 16012 | 16011 | SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, u8); |
| @@ -18223,11 +18222,11 @@ | ||
| 18223 | 18222 | #define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */ |
| 18224 | 18223 | #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 18225 | 18224 | #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ |
| 18226 | 18225 | #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ |
| 18227 | 18226 | #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ |
| 18228 | -#define EP_Alias 0x400000 /* Is an alias for a result set column */ | |
| 18227 | + /* 0x400000 // Available */ | |
| 18229 | 18228 | #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */ |
| 18230 | 18229 | #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */ |
| 18231 | 18230 | #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ |
| 18232 | 18231 | #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ |
| 18233 | 18232 | #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ |
| @@ -18498,10 +18497,11 @@ | ||
| 18498 | 18497 | SrcList *pSrcList; /* One or more tables used to resolve names */ |
| 18499 | 18498 | union { |
| 18500 | 18499 | ExprList *pEList; /* Optional list of result-set columns */ |
| 18501 | 18500 | AggInfo *pAggInfo; /* Information about aggregates at this level */ |
| 18502 | 18501 | Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */ |
| 18502 | + int iBaseReg; /* For TK_REGISTER when parsing RETURNING */ | |
| 18503 | 18503 | } uNC; |
| 18504 | 18504 | NameContext *pNext; /* Next outer name context. NULL for outermost */ |
| 18505 | 18505 | int nRef; /* Number of names resolved by this context */ |
| 18506 | 18506 | int nErr; /* Number of errors encountered while resolving names */ |
| 18507 | 18507 | int ncFlags; /* Zero or more NC_* flags defined below */ |
| @@ -18526,10 +18526,11 @@ | ||
| 18526 | 18526 | #define NC_SelfRef 0x0002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */ |
| 18527 | 18527 | #define NC_VarSelect 0x00040 /* A correlated subquery has been seen */ |
| 18528 | 18528 | #define NC_UEList 0x00080 /* True if uNC.pEList is used */ |
| 18529 | 18529 | #define NC_UAggInfo 0x00100 /* True if uNC.pAggInfo is used */ |
| 18530 | 18530 | #define NC_UUpsert 0x00200 /* True if uNC.pUpsert is used */ |
| 18531 | +#define NC_UBaseReg 0x00400 /* True if uNC.iBaseReg is used */ | |
| 18531 | 18532 | #define NC_MinMaxAgg 0x01000 /* min/max aggregates seen. See note above */ |
| 18532 | 18533 | #define NC_Complex 0x02000 /* True if a function or subquery seen */ |
| 18533 | 18534 | #define NC_AllowWin 0x04000 /* Window functions are allowed here */ |
| 18534 | 18535 | #define NC_HasWin 0x08000 /* One or more window functions seen */ |
| 18535 | 18536 | #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */ |
| @@ -18886,11 +18887,14 @@ | ||
| 18886 | 18887 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| 18887 | 18888 | Parse *pToplevel; /* Parse structure for main program (or NULL) */ |
| 18888 | 18889 | Table *pTriggerTab; /* Table triggers are being coded for */ |
| 18889 | 18890 | Parse *pParentParse; /* Parent parser if this parser is nested */ |
| 18890 | 18891 | AggInfo *pAggList; /* List of all AggInfo objects */ |
| 18891 | - int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */ | |
| 18892 | + union { | |
| 18893 | + int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */ | |
| 18894 | + Returning *pReturning; /* The RETURNING clause */ | |
| 18895 | + } u1; | |
| 18892 | 18896 | u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ |
| 18893 | 18897 | u32 oldmask; /* Mask of old.* columns referenced */ |
| 18894 | 18898 | u32 newmask; /* Mask of new.* columns referenced */ |
| 18895 | 18899 | u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ |
| 18896 | 18900 | u8 bReturning; /* Coding a RETURNING trigger */ |
| @@ -19108,11 +19112,11 @@ | ||
| 19108 | 19112 | Trigger *pTrig; /* The trigger that this step is a part of */ |
| 19109 | 19113 | Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ |
| 19110 | 19114 | char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ |
| 19111 | 19115 | SrcList *pFrom; /* FROM clause for UPDATE statement (if any) */ |
| 19112 | 19116 | Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ |
| 19113 | - ExprList *pExprList; /* SET clause for UPDATE */ | |
| 19117 | + ExprList *pExprList; /* SET clause for UPDATE, or RETURNING clause */ | |
| 19114 | 19118 | IdList *pIdList; /* Column names for INSERT */ |
| 19115 | 19119 | Upsert *pUpsert; /* Upsert clauses on an INSERT */ |
| 19116 | 19120 | char *zSpan; /* Original SQL text of this command */ |
| 19117 | 19121 | TriggerStep *pNext; /* Next in the link-list */ |
| 19118 | 19122 | TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
| @@ -19124,12 +19128,13 @@ | ||
| 19124 | 19128 | struct Returning { |
| 19125 | 19129 | Parse *pParse; /* The parse that includes the RETURNING clause */ |
| 19126 | 19130 | ExprList *pReturnEL; /* List of expressions to return */ |
| 19127 | 19131 | Trigger retTrig; /* The transient trigger that implements RETURNING */ |
| 19128 | 19132 | TriggerStep retTStep; /* The trigger step */ |
| 19129 | - Select retSel; /* The SELECT statement that implements RETURNING */ | |
| 19130 | - u64 retSrcList; /* The empty FROM clause of the SELECT */ | |
| 19133 | + int iRetCur; /* Transient table holding RETURNING results */ | |
| 19134 | + int nRetCol; /* Number of in pReturnEL after expansion */ | |
| 19135 | + int iRetReg; /* Register array for holding a row of RETURNING */ | |
| 19131 | 19136 | }; |
| 19132 | 19137 | |
| 19133 | 19138 | /* |
| 19134 | 19139 | ** An objected used to accumulate the text of a string where we |
| 19135 | 19140 | ** do not necessarily know how big the string will be in the end. |
| @@ -21275,11 +21280,11 @@ | ||
| 21275 | 21280 | struct Vdbe { |
| 21276 | 21281 | sqlite3 *db; /* The database connection that owns this statement */ |
| 21277 | 21282 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 21278 | 21283 | Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 21279 | 21284 | ynVar nVar; /* Number of entries in aVar[] */ |
| 21280 | - u32 magic; /* Magic number for sanity checking */ | |
| 21285 | + u32 iVdbeMagic; /* Magic number defining state of the SQL statement */ | |
| 21281 | 21286 | int nMem; /* Number of memory locations currently allocated */ |
| 21282 | 21287 | int nCursor; /* Number of slots in apCsr[] */ |
| 21283 | 21288 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 21284 | 21289 | int pc; /* The program counter */ |
| 21285 | 21290 | int rc; /* Value to return */ |
| @@ -72861,11 +72866,11 @@ | ||
| 72861 | 72866 | */ |
| 72862 | 72867 | for(i=0; i<nNew; i++){ |
| 72863 | 72868 | aPgOrder[i] = aPgno[i] = apNew[i]->pgno; |
| 72864 | 72869 | aPgFlags[i] = apNew[i]->pDbPage->flags; |
| 72865 | 72870 | for(j=0; j<i; j++){ |
| 72866 | - if( aPgno[j]==aPgno[i] ){ | |
| 72871 | + if( NEVER(aPgno[j]==aPgno[i]) ){ | |
| 72867 | 72872 | /* This branch is taken if the set of sibling pages somehow contains |
| 72868 | 72873 | ** duplicate entries. This can happen if the database is corrupt. |
| 72869 | 72874 | ** It would be simpler to detect this as part of the loop below, but |
| 72870 | 72875 | ** we do the detection here in order to avoid populating the pager |
| 72871 | 72876 | ** cache with two separate objects associated with the same |
| @@ -78292,11 +78297,11 @@ | ||
| 78292 | 78297 | db->pVdbe->pPrev = p; |
| 78293 | 78298 | } |
| 78294 | 78299 | p->pNext = db->pVdbe; |
| 78295 | 78300 | p->pPrev = 0; |
| 78296 | 78301 | db->pVdbe = p; |
| 78297 | - p->magic = VDBE_MAGIC_INIT; | |
| 78302 | + p->iVdbeMagic = VDBE_MAGIC_INIT; | |
| 78298 | 78303 | p->pParse = pParse; |
| 78299 | 78304 | pParse->pVdbe = p; |
| 78300 | 78305 | assert( pParse->aLabel==0 ); |
| 78301 | 78306 | assert( pParse->nLabel==0 ); |
| 78302 | 78307 | assert( p->nOpAlloc==0 ); |
| @@ -78493,11 +78498,11 @@ | ||
| 78493 | 78498 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ |
| 78494 | 78499 | int i; |
| 78495 | 78500 | VdbeOp *pOp; |
| 78496 | 78501 | |
| 78497 | 78502 | i = p->nOp; |
| 78498 | - assert( p->magic==VDBE_MAGIC_INIT ); | |
| 78503 | + assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); | |
| 78499 | 78504 | assert( op>=0 && op<0xff ); |
| 78500 | 78505 | if( p->nOpAlloc<=i ){ |
| 78501 | 78506 | return growOp3(p, op, p1, p2, p3); |
| 78502 | 78507 | } |
| 78503 | 78508 | p->nOp++; |
| @@ -78822,11 +78827,11 @@ | ||
| 78822 | 78827 | } |
| 78823 | 78828 | } |
| 78824 | 78829 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ |
| 78825 | 78830 | Parse *p = v->pParse; |
| 78826 | 78831 | int j = ADDR(x); |
| 78827 | - assert( v->magic==VDBE_MAGIC_INIT ); | |
| 78832 | + assert( v->iVdbeMagic==VDBE_MAGIC_INIT ); | |
| 78828 | 78833 | assert( j<-p->nLabel ); |
| 78829 | 78834 | assert( j>=0 ); |
| 78830 | 78835 | #ifdef SQLITE_DEBUG |
| 78831 | 78836 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 78832 | 78837 | printf("RESOLVE LABEL %d to %d\n", x, v->nOp); |
| @@ -79147,11 +79152,11 @@ | ||
| 79147 | 79152 | |
| 79148 | 79153 | /* |
| 79149 | 79154 | ** Return the address of the next instruction to be inserted. |
| 79150 | 79155 | */ |
| 79151 | 79156 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ |
| 79152 | - assert( p->magic==VDBE_MAGIC_INIT ); | |
| 79157 | + assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); | |
| 79153 | 79158 | return p->nOp; |
| 79154 | 79159 | } |
| 79155 | 79160 | |
| 79156 | 79161 | /* |
| 79157 | 79162 | ** Verify that at least N opcode slots are available in p without |
| @@ -79232,11 +79237,11 @@ | ||
| 79232 | 79237 | int iLineno /* Source-file line number of first opcode */ |
| 79233 | 79238 | ){ |
| 79234 | 79239 | int i; |
| 79235 | 79240 | VdbeOp *pOut, *pFirst; |
| 79236 | 79241 | assert( nOp>0 ); |
| 79237 | - assert( p->magic==VDBE_MAGIC_INIT ); | |
| 79242 | + assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); | |
| 79238 | 79243 | if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){ |
| 79239 | 79244 | return 0; |
| 79240 | 79245 | } |
| 79241 | 79246 | pFirst = pOut = &p->aOp[p->nOp]; |
| 79242 | 79247 | for(i=0; i<nOp; i++, aOp++, pOut++){ |
| @@ -79556,11 +79561,11 @@ | ||
| 79556 | 79561 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){ |
| 79557 | 79562 | Op *pOp; |
| 79558 | 79563 | sqlite3 *db; |
| 79559 | 79564 | assert( p!=0 ); |
| 79560 | 79565 | db = p->db; |
| 79561 | - assert( p->magic==VDBE_MAGIC_INIT ); | |
| 79566 | + assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); | |
| 79562 | 79567 | assert( p->aOp!=0 || db->mallocFailed ); |
| 79563 | 79568 | if( db->mallocFailed ){ |
| 79564 | 79569 | if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4); |
| 79565 | 79570 | return; |
| 79566 | 79571 | } |
| @@ -79685,11 +79690,11 @@ | ||
| 79685 | 79690 | */ |
| 79686 | 79691 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ |
| 79687 | 79692 | /* C89 specifies that the constant "dummy" will be initialized to all |
| 79688 | 79693 | ** zeros, which is correct. MSVC generates a warning, nevertheless. */ |
| 79689 | 79694 | static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */ |
| 79690 | - assert( p->magic==VDBE_MAGIC_INIT ); | |
| 79695 | + assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); | |
| 79691 | 79696 | if( addr<0 ){ |
| 79692 | 79697 | addr = p->nOp - 1; |
| 79693 | 79698 | } |
| 79694 | 79699 | assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed ); |
| 79695 | 79700 | if( p->db->mallocFailed ){ |
| @@ -80370,11 +80375,11 @@ | ||
| 80370 | 80375 | int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0); |
| 80371 | 80376 | Op *aOp; /* Array of opcodes */ |
| 80372 | 80377 | Op *pOp; /* Current opcode */ |
| 80373 | 80378 | |
| 80374 | 80379 | assert( p->explain ); |
| 80375 | - assert( p->magic==VDBE_MAGIC_RUN ); | |
| 80380 | + assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); | |
| 80376 | 80381 | assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM ); |
| 80377 | 80382 | |
| 80378 | 80383 | /* Even though this opcode does not use dynamic strings for |
| 80379 | 80384 | ** the result, result columns may become dynamic if the user calls |
| 80380 | 80385 | ** sqlite3_column_text16(), causing a translation to UTF-16 encoding. |
| @@ -80550,18 +80555,18 @@ | ||
| 80550 | 80555 | SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){ |
| 80551 | 80556 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 80552 | 80557 | int i; |
| 80553 | 80558 | #endif |
| 80554 | 80559 | assert( p!=0 ); |
| 80555 | - assert( p->magic==VDBE_MAGIC_INIT || p->magic==VDBE_MAGIC_RESET ); | |
| 80560 | + assert( p->iVdbeMagic==VDBE_MAGIC_INIT || p->iVdbeMagic==VDBE_MAGIC_RESET ); | |
| 80556 | 80561 | |
| 80557 | 80562 | /* There should be at least one opcode. |
| 80558 | 80563 | */ |
| 80559 | 80564 | assert( p->nOp>0 ); |
| 80560 | 80565 | |
| 80561 | 80566 | /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */ |
| 80562 | - p->magic = VDBE_MAGIC_RUN; | |
| 80567 | + p->iVdbeMagic = VDBE_MAGIC_RUN; | |
| 80563 | 80568 | |
| 80564 | 80569 | #ifdef SQLITE_DEBUG |
| 80565 | 80570 | for(i=0; i<p->nMem; i++){ |
| 80566 | 80571 | assert( p->aMem[i].db==p->db ); |
| 80567 | 80572 | } |
| @@ -80613,11 +80618,11 @@ | ||
| 80613 | 80618 | struct ReusableSpace x; /* Reusable bulk memory */ |
| 80614 | 80619 | |
| 80615 | 80620 | assert( p!=0 ); |
| 80616 | 80621 | assert( p->nOp>0 ); |
| 80617 | 80622 | assert( pParse!=0 ); |
| 80618 | - assert( p->magic==VDBE_MAGIC_INIT ); | |
| 80623 | + assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); | |
| 80619 | 80624 | assert( pParse==p->pParse ); |
| 80620 | 80625 | p->pVList = pParse->pVList; |
| 80621 | 80626 | pParse->pVList = 0; |
| 80622 | 80627 | db = p->db; |
| 80623 | 80628 | assert( db->mallocFailed==0 ); |
| @@ -80852,27 +80857,10 @@ | ||
| 80852 | 80857 | p->aColName = (Mem*)sqlite3DbMallocRawNN(db, sizeof(Mem)*n ); |
| 80853 | 80858 | if( p->aColName==0 ) return; |
| 80854 | 80859 | initMemArray(p->aColName, n, db, MEM_Null); |
| 80855 | 80860 | } |
| 80856 | 80861 | |
| 80857 | -/* | |
| 80858 | -** Transfer the column count and name information from one Vdbe to | |
| 80859 | -** another. | |
| 80860 | -*/ | |
| 80861 | -SQLITE_PRIVATE void sqlite3VdbeColumnInfoXfer(Vdbe *pTo, Vdbe *pFrom){ | |
| 80862 | - sqlite3 *db = pTo->db; | |
| 80863 | - assert( db==pFrom->db ); | |
| 80864 | - if( pTo->nResColumn ){ | |
| 80865 | - releaseMemArray(pTo->aColName, pTo->nResColumn*COLNAME_N); | |
| 80866 | - sqlite3DbFree(db, pTo->aColName); | |
| 80867 | - } | |
| 80868 | - pTo->aColName = pFrom->aColName; | |
| 80869 | - pFrom->aColName = 0; | |
| 80870 | - pTo->nResColumn = pFrom->nResColumn; | |
| 80871 | - pFrom->nResColumn = 0; | |
| 80872 | -} | |
| 80873 | - | |
| 80874 | 80862 | /* |
| 80875 | 80863 | ** Set the name of the idx'th column to be returned by the SQL statement. |
| 80876 | 80864 | ** zName must be a pointer to a nul terminated string. |
| 80877 | 80865 | ** |
| 80878 | 80866 | ** This call must be made after a call to sqlite3VdbeSetNumCols(). |
| @@ -81315,11 +81303,11 @@ | ||
| 81315 | 81303 | ** Then the internal cache might have been left in an inconsistent |
| 81316 | 81304 | ** state. We need to rollback the statement transaction, if there is |
| 81317 | 81305 | ** one, or the complete transaction if there is no statement transaction. |
| 81318 | 81306 | */ |
| 81319 | 81307 | |
| 81320 | - if( p->magic!=VDBE_MAGIC_RUN ){ | |
| 81308 | + if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){ | |
| 81321 | 81309 | return SQLITE_OK; |
| 81322 | 81310 | } |
| 81323 | 81311 | if( db->mallocFailed ){ |
| 81324 | 81312 | p->rc = SQLITE_NOMEM_BKPT; |
| 81325 | 81313 | } |
| @@ -81473,11 +81461,11 @@ | ||
| 81473 | 81461 | if( p->bIsReader ) db->nVdbeRead--; |
| 81474 | 81462 | assert( db->nVdbeActive>=db->nVdbeRead ); |
| 81475 | 81463 | assert( db->nVdbeRead>=db->nVdbeWrite ); |
| 81476 | 81464 | assert( db->nVdbeWrite>=0 ); |
| 81477 | 81465 | } |
| 81478 | - p->magic = VDBE_MAGIC_HALT; | |
| 81466 | + p->iVdbeMagic = VDBE_MAGIC_HALT; | |
| 81479 | 81467 | checkActiveVdbeCnt(db); |
| 81480 | 81468 | if( db->mallocFailed ){ |
| 81481 | 81469 | p->rc = SQLITE_NOMEM_BKPT; |
| 81482 | 81470 | } |
| 81483 | 81471 | |
| @@ -81646,21 +81634,21 @@ | ||
| 81646 | 81634 | } |
| 81647 | 81635 | fclose(out); |
| 81648 | 81636 | } |
| 81649 | 81637 | } |
| 81650 | 81638 | #endif |
| 81651 | - p->magic = VDBE_MAGIC_RESET; | |
| 81639 | + p->iVdbeMagic = VDBE_MAGIC_RESET; | |
| 81652 | 81640 | return p->rc & db->errMask; |
| 81653 | 81641 | } |
| 81654 | 81642 | |
| 81655 | 81643 | /* |
| 81656 | 81644 | ** Clean up and delete a VDBE after execution. Return an integer which is |
| 81657 | 81645 | ** the result code. Write any error message text into *pzErrMsg. |
| 81658 | 81646 | */ |
| 81659 | 81647 | SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){ |
| 81660 | 81648 | int rc = SQLITE_OK; |
| 81661 | - if( p->magic==VDBE_MAGIC_RUN || p->magic==VDBE_MAGIC_HALT ){ | |
| 81649 | + if( p->iVdbeMagic==VDBE_MAGIC_RUN || p->iVdbeMagic==VDBE_MAGIC_HALT ){ | |
| 81662 | 81650 | rc = sqlite3VdbeReset(p); |
| 81663 | 81651 | assert( (rc & p->db->errMask)==rc ); |
| 81664 | 81652 | } |
| 81665 | 81653 | sqlite3VdbeDelete(p); |
| 81666 | 81654 | return rc; |
| @@ -81717,11 +81705,11 @@ | ||
| 81717 | 81705 | for(pSub=p->pProgram; pSub; pSub=pNext){ |
| 81718 | 81706 | pNext = pSub->pNext; |
| 81719 | 81707 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 81720 | 81708 | sqlite3DbFree(db, pSub); |
| 81721 | 81709 | } |
| 81722 | - if( p->magic!=VDBE_MAGIC_INIT ){ | |
| 81710 | + if( p->iVdbeMagic!=VDBE_MAGIC_INIT ){ | |
| 81723 | 81711 | releaseMemArray(p->aVar, p->nVar); |
| 81724 | 81712 | sqlite3DbFree(db, p->pVList); |
| 81725 | 81713 | sqlite3DbFree(db, p->pFree); |
| 81726 | 81714 | } |
| 81727 | 81715 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| @@ -81765,11 +81753,11 @@ | ||
| 81765 | 81753 | db->pVdbe = p->pNext; |
| 81766 | 81754 | } |
| 81767 | 81755 | if( p->pNext ){ |
| 81768 | 81756 | p->pNext->pPrev = p->pPrev; |
| 81769 | 81757 | } |
| 81770 | - p->magic = VDBE_MAGIC_DEAD; | |
| 81758 | + p->iVdbeMagic = VDBE_MAGIC_DEAD; | |
| 81771 | 81759 | p->db = 0; |
| 81772 | 81760 | sqlite3DbFreeNN(db, p); |
| 81773 | 81761 | } |
| 81774 | 81762 | |
| 81775 | 81763 | /* |
| @@ -84144,11 +84132,11 @@ | ||
| 84144 | 84132 | static int sqlite3Step(Vdbe *p){ |
| 84145 | 84133 | sqlite3 *db; |
| 84146 | 84134 | int rc; |
| 84147 | 84135 | |
| 84148 | 84136 | assert(p); |
| 84149 | - if( p->magic!=VDBE_MAGIC_RUN ){ | |
| 84137 | + if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){ | |
| 84150 | 84138 | /* We used to require that sqlite3_reset() be called before retrying |
| 84151 | 84139 | ** sqlite3_step() after any error or after SQLITE_DONE. But beginning |
| 84152 | 84140 | ** with version 3.7.0, we changed this so that sqlite3_reset() would |
| 84153 | 84141 | ** be called automatically instead of throwing the SQLITE_MISUSE error. |
| 84154 | 84142 | ** This "automatic-reset" change is not technically an incompatibility, |
| @@ -84860,11 +84848,11 @@ | ||
| 84860 | 84848 | Mem *pVar; |
| 84861 | 84849 | if( vdbeSafetyNotNull(p) ){ |
| 84862 | 84850 | return SQLITE_MISUSE_BKPT; |
| 84863 | 84851 | } |
| 84864 | 84852 | sqlite3_mutex_enter(p->db->mutex); |
| 84865 | - if( p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){ | |
| 84853 | + if( p->iVdbeMagic!=VDBE_MAGIC_RUN || p->pc>=0 ){ | |
| 84866 | 84854 | sqlite3Error(p->db, SQLITE_MISUSE); |
| 84867 | 84855 | sqlite3_mutex_leave(p->db->mutex); |
| 84868 | 84856 | sqlite3_log(SQLITE_MISUSE, |
| 84869 | 84857 | "bind on a busy prepared statement: [%s]", p->zSql); |
| 84870 | 84858 | return SQLITE_MISUSE_BKPT; |
| @@ -85214,11 +85202,11 @@ | ||
| 85214 | 85202 | /* |
| 85215 | 85203 | ** Return true if the prepared statement is in need of being reset. |
| 85216 | 85204 | */ |
| 85217 | 85205 | SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ |
| 85218 | 85206 | Vdbe *v = (Vdbe*)pStmt; |
| 85219 | - return v!=0 && v->magic==VDBE_MAGIC_RUN && v->pc>=0; | |
| 85207 | + return v!=0 && v->iVdbeMagic==VDBE_MAGIC_RUN && v->pc>=0; | |
| 85220 | 85208 | } |
| 85221 | 85209 | |
| 85222 | 85210 | /* |
| 85223 | 85211 | ** Return a pointer to the next prepared statement after pStmt associated |
| 85224 | 85212 | ** with database connection pDb. If pStmt is NULL, return the first |
| @@ -86552,11 +86540,11 @@ | ||
| 86552 | 86540 | #ifdef VDBE_PROFILE |
| 86553 | 86541 | u64 start; /* CPU clock count at start of opcode */ |
| 86554 | 86542 | #endif |
| 86555 | 86543 | /*** INSERT STACK UNION HERE ***/ |
| 86556 | 86544 | |
| 86557 | - assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ | |
| 86545 | + assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ | |
| 86558 | 86546 | sqlite3VdbeEnter(p); |
| 86559 | 86547 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 86560 | 86548 | if( db->xProgress ){ |
| 86561 | 86549 | u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; |
| 86562 | 86550 | assert( 0 < db->nProgressOps ); |
| @@ -98629,11 +98617,10 @@ | ||
| 98629 | 98617 | assert( db->mallocFailed ); |
| 98630 | 98618 | } |
| 98631 | 98619 | } |
| 98632 | 98620 | sqlite3DbFree(db, pDup); |
| 98633 | 98621 | } |
| 98634 | - ExprSetProperty(pExpr, EP_Alias); | |
| 98635 | 98622 | } |
| 98636 | 98623 | |
| 98637 | 98624 | |
| 98638 | 98625 | /* |
| 98639 | 98626 | ** Return TRUE if the name zCol occurs anywhere in the USING clause. |
| @@ -98888,11 +98875,11 @@ | ||
| 98888 | 98875 | #if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) |
| 98889 | 98876 | /* If we have not already resolved the name, then maybe |
| 98890 | 98877 | ** it is a new.* or old.* trigger argument reference. Or |
| 98891 | 98878 | ** maybe it is an excluded.* from an upsert. |
| 98892 | 98879 | */ |
| 98893 | - if( zDb==0 && cntTab==0 ){ | |
| 98880 | + if( cntTab==0 && zDb==0 ){ | |
| 98894 | 98881 | pTab = 0; |
| 98895 | 98882 | #ifndef SQLITE_OMIT_TRIGGER |
| 98896 | 98883 | if( pParse->pTriggerTab!=0 ){ |
| 98897 | 98884 | int op = pParse->eTriggerOp; |
| 98898 | 98885 | assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT ); |
| @@ -98946,31 +98933,35 @@ | ||
| 98946 | 98933 | eNewExprOp = TK_COLUMN; |
| 98947 | 98934 | }else{ |
| 98948 | 98935 | pExpr->iTable = pNC->uNC.pUpsert->regData + |
| 98949 | 98936 | sqlite3TableColumnToStorage(pTab, iCol); |
| 98950 | 98937 | eNewExprOp = TK_REGISTER; |
| 98951 | - ExprSetProperty(pExpr, EP_Alias); | |
| 98952 | 98938 | } |
| 98953 | 98939 | }else |
| 98954 | 98940 | #endif /* SQLITE_OMIT_UPSERT */ |
| 98955 | 98941 | { |
| 98956 | -#ifndef SQLITE_OMIT_TRIGGER | |
| 98957 | - if( iCol<0 ){ | |
| 98958 | - pExpr->affExpr = SQLITE_AFF_INTEGER; | |
| 98959 | - }else if( pExpr->iTable==0 ){ | |
| 98960 | - testcase( iCol==31 ); | |
| 98961 | - testcase( iCol==32 ); | |
| 98962 | - pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); | |
| 98963 | - }else{ | |
| 98964 | - testcase( iCol==31 ); | |
| 98965 | - testcase( iCol==32 ); | |
| 98966 | - pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); | |
| 98967 | - } | |
| 98968 | 98942 | pExpr->y.pTab = pTab; |
| 98969 | - pExpr->iColumn = (i16)iCol; | |
| 98970 | - eNewExprOp = TK_TRIGGER; | |
| 98943 | + if( iCol<0 ) pExpr->affExpr = SQLITE_AFF_INTEGER; | |
| 98944 | + if( pParse->bReturning ){ | |
| 98945 | + eNewExprOp = TK_REGISTER; | |
| 98946 | + pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable | |
| 98947 | + + iCol + 1; | |
| 98948 | + }else{ | |
| 98949 | + pExpr->iColumn = (i16)iCol; | |
| 98950 | + eNewExprOp = TK_TRIGGER; | |
| 98951 | +#ifndef SQLITE_OMIT_TRIGGER | |
| 98952 | + if( pExpr->iTable==0 ){ | |
| 98953 | + testcase( iCol==31 ); | |
| 98954 | + testcase( iCol==32 ); | |
| 98955 | + pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); | |
| 98956 | + }else{ | |
| 98957 | + testcase( iCol==31 ); | |
| 98958 | + testcase( iCol==32 ); | |
| 98959 | + pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); | |
| 98960 | + } | |
| 98971 | 98961 | #endif /* SQLITE_OMIT_TRIGGER */ |
| 98962 | + } | |
| 98972 | 98963 | } |
| 98973 | 98964 | } |
| 98974 | 98965 | } |
| 98975 | 98966 | } |
| 98976 | 98967 | #endif /* !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) */ |
| @@ -99147,11 +99138,13 @@ | ||
| 99147 | 99138 | pExpr->op = eNewExprOp; |
| 99148 | 99139 | ExprSetProperty(pExpr, EP_Leaf); |
| 99149 | 99140 | lookupname_end: |
| 99150 | 99141 | if( cnt==1 ){ |
| 99151 | 99142 | assert( pNC!=0 ); |
| 99152 | - if( !ExprHasProperty(pExpr, EP_Alias) ){ | |
| 99143 | + if( pParse->db->xAuth | |
| 99144 | + && (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER) | |
| 99145 | + ){ | |
| 99153 | 99146 | sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); |
| 99154 | 99147 | } |
| 99155 | 99148 | /* Increment the nRef value on all name contexts from TopNC up to |
| 99156 | 99149 | ** the point where the name matched. */ |
| 99157 | 99150 | for(;;){ |
| @@ -111033,20 +111026,19 @@ | ||
| 111033 | 111026 | Parse *pParse, /* The parser context */ |
| 111034 | 111027 | Expr *pExpr, /* The expression to check authorization on */ |
| 111035 | 111028 | Schema *pSchema, /* The schema of the expression */ |
| 111036 | 111029 | SrcList *pTabList /* All table that pExpr might refer to */ |
| 111037 | 111030 | ){ |
| 111038 | - sqlite3 *db = pParse->db; | |
| 111039 | 111031 | Table *pTab = 0; /* The table being read */ |
| 111040 | 111032 | const char *zCol; /* Name of the column of the table */ |
| 111041 | 111033 | int iSrc; /* Index in pTabList->a[] of table being read */ |
| 111042 | 111034 | int iDb; /* The index of the database the expression refers to */ |
| 111043 | 111035 | int iCol; /* Index of column in table */ |
| 111044 | 111036 | |
| 111045 | 111037 | assert( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ); |
| 111046 | - assert( !IN_RENAME_OBJECT || db->xAuth==0 ); | |
| 111047 | - if( db->xAuth==0 ) return; | |
| 111038 | + assert( !IN_RENAME_OBJECT ); | |
| 111039 | + assert( pParse->db->xAuth!=0 ); | |
| 111048 | 111040 | iDb = sqlite3SchemaToIndex(pParse->db, pSchema); |
| 111049 | 111041 | if( iDb<0 ){ |
| 111050 | 111042 | /* An attempt to read a column out of a subquery or other |
| 111051 | 111043 | ** temporary table. */ |
| 111052 | 111044 | return; |
| @@ -111073,11 +111065,11 @@ | ||
| 111073 | 111065 | assert( pTab->iPKey<pTab->nCol ); |
| 111074 | 111066 | zCol = pTab->aCol[pTab->iPKey].zName; |
| 111075 | 111067 | }else{ |
| 111076 | 111068 | zCol = "ROWID"; |
| 111077 | 111069 | } |
| 111078 | - assert( iDb>=0 && iDb<db->nDb ); | |
| 111070 | + assert( iDb>=0 && iDb<pParse->db->nDb ); | |
| 111079 | 111071 | if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){ |
| 111080 | 111072 | pExpr->op = TK_NULL; |
| 111081 | 111073 | } |
| 111082 | 111074 | } |
| 111083 | 111075 | |
| @@ -111305,18 +111297,38 @@ | ||
| 111305 | 111297 | } |
| 111306 | 111298 | |
| 111307 | 111299 | /* Begin by generating some termination code at the end of the |
| 111308 | 111300 | ** vdbe program |
| 111309 | 111301 | */ |
| 111310 | - if( pParse->pVdbe==0 && db->init.busy ){ | |
| 111311 | - pParse->rc = SQLITE_DONE; | |
| 111312 | - return; | |
| 111302 | + v = pParse->pVdbe; | |
| 111303 | + if( v==0 ){ | |
| 111304 | + if( db->init.busy ){ | |
| 111305 | + pParse->rc = SQLITE_DONE; | |
| 111306 | + return; | |
| 111307 | + } | |
| 111308 | + v = sqlite3GetVdbe(pParse); | |
| 111309 | + if( v==0 ) pParse->rc = SQLITE_ERROR; | |
| 111313 | 111310 | } |
| 111314 | - v = sqlite3GetVdbe(pParse); | |
| 111315 | 111311 | assert( !pParse->isMultiWrite |
| 111316 | 111312 | || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort)); |
| 111317 | 111313 | if( v ){ |
| 111314 | + if( pParse->bReturning ){ | |
| 111315 | + Returning *pReturning = pParse->u1.pReturning; | |
| 111316 | + int addrRewind; | |
| 111317 | + int i; | |
| 111318 | + int reg; | |
| 111319 | + | |
| 111320 | + addrRewind = | |
| 111321 | + sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); | |
| 111322 | + reg = pReturning->iRetReg; | |
| 111323 | + for(i=0; i<pReturning->nRetCol; i++){ | |
| 111324 | + sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i); | |
| 111325 | + } | |
| 111326 | + sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i); | |
| 111327 | + sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1); | |
| 111328 | + sqlite3VdbeJumpHere(v, addrRewind); | |
| 111329 | + } | |
| 111318 | 111330 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 111319 | 111331 | |
| 111320 | 111332 | #if SQLITE_USER_AUTHENTICATION |
| 111321 | 111333 | if( pParse->nTableLock>0 && db->init.busy==0 ){ |
| 111322 | 111334 | sqlite3UserAuthInit(db); |
| @@ -111389,16 +111401,20 @@ | ||
| 111389 | 111401 | if( iReg>0 ){ |
| 111390 | 111402 | sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg); |
| 111391 | 111403 | } |
| 111392 | 111404 | } |
| 111393 | 111405 | } |
| 111406 | + | |
| 111407 | + if( pParse->bReturning ){ | |
| 111408 | + Returning *pRet = pParse->u1.pReturning; | |
| 111409 | + sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); | |
| 111410 | + } | |
| 111394 | 111411 | |
| 111395 | 111412 | /* Finally, jump back to the beginning of the executable code. */ |
| 111396 | 111413 | sqlite3VdbeGoto(v, 1); |
| 111397 | 111414 | } |
| 111398 | 111415 | } |
| 111399 | - | |
| 111400 | 111416 | |
| 111401 | 111417 | /* Get the VDBE program ready for execution |
| 111402 | 111418 | */ |
| 111403 | 111419 | if( v && pParse->nErr==0 && !db->mallocFailed ){ |
| 111404 | 111420 | /* A minimum of one cursor is required if autoincrement is used |
| @@ -112372,11 +112388,12 @@ | ||
| 112372 | 112388 | if( isView || isVirtual ){ |
| 112373 | 112389 | sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2); |
| 112374 | 112390 | }else |
| 112375 | 112391 | #endif |
| 112376 | 112392 | { |
| 112377 | - pParse->addrCrTab = | |
| 112393 | + assert( !pParse->bReturning ); | |
| 112394 | + pParse->u1.addrCrTab = | |
| 112378 | 112395 | sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY); |
| 112379 | 112396 | } |
| 112380 | 112397 | sqlite3OpenSchemaTable(pParse, iDb); |
| 112381 | 112398 | sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1); |
| 112382 | 112399 | sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC); |
| @@ -112450,10 +112467,11 @@ | ||
| 112450 | 112467 | pRet = sqlite3DbMallocZero(db, sizeof(*pRet)); |
| 112451 | 112468 | if( pRet==0 ){ |
| 112452 | 112469 | sqlite3ExprListDelete(db, pList); |
| 112453 | 112470 | return; |
| 112454 | 112471 | } |
| 112472 | + pParse->u1.pReturning = pRet; | |
| 112455 | 112473 | pRet->pParse = pParse; |
| 112456 | 112474 | pRet->pReturnEL = pList; |
| 112457 | 112475 | sqlite3ParserAddCleanup(pParse, |
| 112458 | 112476 | (void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet); |
| 112459 | 112477 | if( db->mallocFailed ) return; |
| @@ -112463,14 +112481,11 @@ | ||
| 112463 | 112481 | pRet->retTrig.bReturning = 1; |
| 112464 | 112482 | pRet->retTrig.pSchema = db->aDb[1].pSchema; |
| 112465 | 112483 | pRet->retTrig.step_list = &pRet->retTStep; |
| 112466 | 112484 | pRet->retTStep.op = TK_RETURNING; |
| 112467 | 112485 | pRet->retTStep.pTrig = &pRet->retTrig; |
| 112468 | - pRet->retTStep.pSelect = &pRet->retSel; | |
| 112469 | - pRet->retSel.op = TK_ALL; | |
| 112470 | - pRet->retSel.pEList = pList; | |
| 112471 | - pRet->retSel.pSrc = (SrcList*)&pRet->retSrcList; | |
| 112486 | + pRet->retTStep.pExprList = pList; | |
| 112472 | 112487 | pHash = &(db->aDb[1].pSchema->trigHash); |
| 112473 | 112488 | assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0 ); |
| 112474 | 112489 | if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig) |
| 112475 | 112490 | ==&pRet->retTrig ){ |
| 112476 | 112491 | sqlite3OomFault(db); |
| @@ -113306,13 +113321,14 @@ | ||
| 113306 | 113321 | } |
| 113307 | 113322 | |
| 113308 | 113323 | /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY |
| 113309 | 113324 | ** into BTREE_BLOBKEY. |
| 113310 | 113325 | */ |
| 113311 | - if( pParse->addrCrTab ){ | |
| 113326 | + assert( !pParse->bReturning ); | |
| 113327 | + if( pParse->u1.addrCrTab ){ | |
| 113312 | 113328 | assert( v ); |
| 113313 | - sqlite3VdbeChangeP3(v, pParse->addrCrTab, BTREE_BLOBKEY); | |
| 113329 | + sqlite3VdbeChangeP3(v, pParse->u1.addrCrTab, BTREE_BLOBKEY); | |
| 113314 | 113330 | } |
| 113315 | 113331 | |
| 113316 | 113332 | /* Locate the PRIMARY KEY index. Or, if this table was originally |
| 113317 | 113333 | ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. |
| 113318 | 113334 | */ |
| @@ -121313,11 +121329,13 @@ | ||
| 121313 | 121329 | ** non-zero. If there is no foreign key related processing, this function |
| 121314 | 121330 | ** returns zero. |
| 121315 | 121331 | ** |
| 121316 | 121332 | ** For an UPDATE, this function returns 2 if: |
| 121317 | 121333 | ** |
| 121318 | -** * There are any FKs for which pTab is the child and the parent table, or | |
| 121334 | +** * There are any FKs for which pTab is the child and the parent table | |
| 121335 | +** and any FK processing at all is required (even of a different FK), or | |
| 121336 | +** | |
| 121319 | 121337 | ** * the UPDATE modifies one or more parent keys for which the action is |
| 121320 | 121338 | ** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL). |
| 121321 | 121339 | ** |
| 121322 | 121340 | ** Or, assuming some other foreign key processing is required, 1. |
| 121323 | 121341 | */ |
| @@ -121325,40 +121343,41 @@ | ||
| 121325 | 121343 | Parse *pParse, /* Parse context */ |
| 121326 | 121344 | Table *pTab, /* Table being modified */ |
| 121327 | 121345 | int *aChange, /* Non-NULL for UPDATE operations */ |
| 121328 | 121346 | int chngRowid /* True for UPDATE that affects rowid */ |
| 121329 | 121347 | ){ |
| 121330 | - int eRet = 0; | |
| 121348 | + int eRet = 1; /* Value to return if bHaveFK is true */ | |
| 121349 | + int bHaveFK = 0; /* If FK processing is required */ | |
| 121331 | 121350 | if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 121332 | 121351 | if( !aChange ){ |
| 121333 | 121352 | /* A DELETE operation. Foreign key processing is required if the |
| 121334 | 121353 | ** table in question is either the child or parent table for any |
| 121335 | 121354 | ** foreign key constraint. */ |
| 121336 | - eRet = (sqlite3FkReferences(pTab) || pTab->pFKey); | |
| 121355 | + bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey); | |
| 121337 | 121356 | }else{ |
| 121338 | 121357 | /* This is an UPDATE. Foreign key processing is only required if the |
| 121339 | 121358 | ** operation modifies one or more child or parent key columns. */ |
| 121340 | 121359 | FKey *p; |
| 121341 | 121360 | |
| 121342 | 121361 | /* Check if any child key columns are being modified. */ |
| 121343 | 121362 | for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 121344 | - if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2; | |
| 121345 | 121363 | if( fkChildIsModified(pTab, p, aChange, chngRowid) ){ |
| 121346 | - eRet = 1; | |
| 121364 | + if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2; | |
| 121365 | + bHaveFK = 1; | |
| 121347 | 121366 | } |
| 121348 | 121367 | } |
| 121349 | 121368 | |
| 121350 | 121369 | /* Check if any parent key columns are being modified. */ |
| 121351 | 121370 | for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ |
| 121352 | 121371 | if( fkParentIsModified(pTab, p, aChange, chngRowid) ){ |
| 121353 | 121372 | if( p->aAction[1]!=OE_None ) return 2; |
| 121354 | - eRet = 1; | |
| 121373 | + bHaveFK = 1; | |
| 121355 | 121374 | } |
| 121356 | 121375 | } |
| 121357 | 121376 | } |
| 121358 | 121377 | } |
| 121359 | - return eRet; | |
| 121378 | + return bHaveFK ? eRet : 0; | |
| 121360 | 121379 | } |
| 121361 | 121380 | |
| 121362 | 121381 | /* |
| 121363 | 121382 | ** This function is called when an UPDATE or DELETE operation is being |
| 121364 | 121383 | ** compiled on table pTab, which is the parent table of foreign-key pFKey. |
| @@ -122796,15 +122815,10 @@ | ||
| 122796 | 122815 | sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols); |
| 122797 | 122816 | sqlite3VdbeJumpHere(v, addr1); |
| 122798 | 122817 | sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v); |
| 122799 | 122818 | } |
| 122800 | 122819 | |
| 122801 | - /* Cannot have triggers on a virtual table. If it were possible, | |
| 122802 | - ** this block would have to account for hidden column. | |
| 122803 | - */ | |
| 122804 | - assert( !IsVirtual(pTab) ); | |
| 122805 | - | |
| 122806 | 122820 | /* Copy the new data already generated. */ |
| 122807 | 122821 | assert( pTab->nNVCol>0 ); |
| 122808 | 122822 | sqlite3VdbeAddOp3(v, OP_Copy, regRowid+1, regCols+1, pTab->nNVCol-1); |
| 122809 | 122823 | |
| 122810 | 122824 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| @@ -137898,10 +137912,12 @@ | ||
| 137898 | 137912 | && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 137899 | 137913 | ){ |
| 137900 | 137914 | pTrig->pNext = pList; |
| 137901 | 137915 | pList = pTrig; |
| 137902 | 137916 | }else if( pTrig->op==TK_RETURNING ){ |
| 137917 | + assert( pParse->bReturning ); | |
| 137918 | + assert( &(pParse->u1.pReturning->retTrig) == pTrig ); | |
| 137903 | 137919 | pTrig->table = pTab->zName; |
| 137904 | 137920 | pTrig->pTabSchema = pTab->pSchema; |
| 137905 | 137921 | pTrig->pNext = pList; |
| 137906 | 137922 | pList = pTrig; |
| 137907 | 137923 | } |
| @@ -138587,20 +138603,25 @@ | ||
| 138587 | 138603 | }else if( p->op==TK_RETURNING ){ |
| 138588 | 138604 | /* The first time a RETURNING trigger is seen, the "op" value tells |
| 138589 | 138605 | ** us what time of trigger it should be. */ |
| 138590 | 138606 | assert( sqlite3IsToplevel(pParse) ); |
| 138591 | 138607 | p->op = op; |
| 138592 | - mask |= TRIGGER_AFTER; | |
| 138593 | - if( IsVirtual(pTab) && op!=TK_INSERT ){ | |
| 138594 | - sqlite3ErrorMsg(pParse, | |
| 138595 | - "%s RETURNING is not available on virtual tables", | |
| 138596 | - op==TK_DELETE ? "DELETE" : "UPDATE"); | |
| 138608 | + if( IsVirtual(pTab) ){ | |
| 138609 | + if( op!=TK_INSERT ){ | |
| 138610 | + sqlite3ErrorMsg(pParse, | |
| 138611 | + "%s RETURNING is not available on virtual tables", | |
| 138612 | + op==TK_DELETE ? "DELETE" : "UPDATE"); | |
| 138613 | + } | |
| 138614 | + p->tr_tm = TRIGGER_BEFORE; | |
| 138615 | + }else{ | |
| 138616 | + p->tr_tm = TRIGGER_AFTER; | |
| 138597 | 138617 | } |
| 138618 | + mask |= p->tr_tm; | |
| 138598 | 138619 | }else if( p->bReturning && p->op==TK_INSERT && op==TK_UPDATE |
| 138599 | 138620 | && sqlite3IsToplevel(pParse) ){ |
| 138600 | 138621 | /* Also fire a RETURNING trigger for an UPSERT */ |
| 138601 | - mask |= TRIGGER_AFTER; | |
| 138622 | + mask |= p->tr_tm; | |
| 138602 | 138623 | } |
| 138603 | 138624 | p = p->pNext; |
| 138604 | 138625 | }while( p ); |
| 138605 | 138626 | } |
| 138606 | 138627 | exit_triggers_exist: |
| @@ -138658,10 +138679,11 @@ | ||
| 138658 | 138679 | Table *pTab /* The table being updated */ |
| 138659 | 138680 | ){ |
| 138660 | 138681 | ExprList *pNew = 0; |
| 138661 | 138682 | sqlite3 *db = pParse->db; |
| 138662 | 138683 | int i; |
| 138684 | + | |
| 138663 | 138685 | for(i=0; i<pList->nExpr; i++){ |
| 138664 | 138686 | Expr *pOldExpr = pList->a[i].pExpr; |
| 138665 | 138687 | if( ALWAYS(pOldExpr!=0) && pOldExpr->op==TK_ASTERISK ){ |
| 138666 | 138688 | int jj; |
| 138667 | 138689 | for(jj=0; jj<pTab->nCol; jj++){ |
| @@ -138681,13 +138703,75 @@ | ||
| 138681 | 138703 | struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; |
| 138682 | 138704 | pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName); |
| 138683 | 138705 | pItem->eEName = pList->a[i].eEName; |
| 138684 | 138706 | } |
| 138685 | 138707 | } |
| 138708 | + } | |
| 138709 | + if( !db->mallocFailed ){ | |
| 138710 | + Vdbe *v = pParse->pVdbe; | |
| 138711 | + assert( v!=0 ); | |
| 138712 | + sqlite3VdbeSetNumCols(v, pNew->nExpr); | |
| 138713 | + for(i=0; i<pNew->nExpr; i++){ | |
| 138714 | + sqlite3VdbeSetColName(v, i, COLNAME_NAME, pNew->a[i].zEName, | |
| 138715 | + SQLITE_TRANSIENT); | |
| 138716 | + } | |
| 138686 | 138717 | } |
| 138687 | 138718 | return pNew; |
| 138688 | 138719 | } |
| 138720 | + | |
| 138721 | +/* | |
| 138722 | +** Generate code for the RETURNING trigger. Unlike other triggers | |
| 138723 | +** that invoke a subprogram in the bytecode, the code for RETURNING | |
| 138724 | +** is generated in-line. | |
| 138725 | +*/ | |
| 138726 | +static void codeReturningTrigger( | |
| 138727 | + Parse *pParse, /* Parse context */ | |
| 138728 | + Trigger *pTrigger, /* The trigger step that defines the RETURNING */ | |
| 138729 | + Table *pTab, /* The table to code triggers from */ | |
| 138730 | + int regIn /* The first in an array of registers */ | |
| 138731 | +){ | |
| 138732 | + Vdbe *v = pParse->pVdbe; | |
| 138733 | + ExprList *pNew; | |
| 138734 | + Returning *pReturning; | |
| 138735 | + | |
| 138736 | + assert( v!=0 ); | |
| 138737 | + assert( pParse->bReturning ); | |
| 138738 | + pReturning = pParse->u1.pReturning; | |
| 138739 | + assert( pTrigger == &(pReturning->retTrig) ); | |
| 138740 | + pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab); | |
| 138741 | + if( pNew ){ | |
| 138742 | + NameContext sNC; | |
| 138743 | + memset(&sNC, 0, sizeof(sNC)); | |
| 138744 | + if( pReturning->nRetCol==0 ){ | |
| 138745 | + pReturning->nRetCol = pNew->nExpr; | |
| 138746 | + pReturning->iRetCur = pParse->nTab++; | |
| 138747 | + } | |
| 138748 | + sNC.pParse = pParse; | |
| 138749 | + sNC.uNC.iBaseReg = regIn; | |
| 138750 | + sNC.ncFlags = NC_UBaseReg; | |
| 138751 | + pParse->eTriggerOp = pTrigger->op; | |
| 138752 | + pParse->pTriggerTab = pTab; | |
| 138753 | + if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK ){ | |
| 138754 | + int i; | |
| 138755 | + int nCol = pNew->nExpr; | |
| 138756 | + int reg = pParse->nMem+1; | |
| 138757 | + pParse->nMem += nCol+2; | |
| 138758 | + pReturning->iRetReg = reg; | |
| 138759 | + for(i=0; i<nCol; i++){ | |
| 138760 | + sqlite3ExprCodeFactorable(pParse, pNew->a[i].pExpr, reg+i); | |
| 138761 | + } | |
| 138762 | + sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, i, reg+i); | |
| 138763 | + sqlite3VdbeAddOp2(v, OP_NewRowid, pReturning->iRetCur, reg+i+1); | |
| 138764 | + sqlite3VdbeAddOp3(v, OP_Insert, pReturning->iRetCur, reg+i, reg+i+1); | |
| 138765 | + } | |
| 138766 | + sqlite3ExprListDelete(pParse->db, pNew); | |
| 138767 | + pParse->eTriggerOp = 0; | |
| 138768 | + pParse->pTriggerTab = 0; | |
| 138769 | + } | |
| 138770 | +} | |
| 138771 | + | |
| 138772 | + | |
| 138689 | 138773 | |
| 138690 | 138774 | /* |
| 138691 | 138775 | ** Generate VDBE code for the statements inside the body of a single |
| 138692 | 138776 | ** trigger. |
| 138693 | 138777 | */ |
| @@ -138756,38 +138840,18 @@ | ||
| 138756 | 138840 | sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0 |
| 138757 | 138841 | ); |
| 138758 | 138842 | sqlite3VdbeAddOp0(v, OP_ResetCount); |
| 138759 | 138843 | break; |
| 138760 | 138844 | } |
| 138761 | - case TK_SELECT: { | |
| 138845 | + default: assert( pStep->op==TK_SELECT ); { | |
| 138762 | 138846 | SelectDest sDest; |
| 138763 | 138847 | Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0); |
| 138764 | 138848 | sqlite3SelectDestInit(&sDest, SRT_Discard, 0); |
| 138765 | 138849 | sqlite3Select(pParse, pSelect, &sDest); |
| 138766 | 138850 | sqlite3SelectDelete(db, pSelect); |
| 138767 | 138851 | break; |
| 138768 | 138852 | } |
| 138769 | - default: assert( pStep->op==TK_RETURNING ); { | |
| 138770 | - Select *pSelect = pStep->pSelect; | |
| 138771 | - ExprList *pList = pSelect->pEList; | |
| 138772 | - SelectDest sDest; | |
| 138773 | - Select *pNew; | |
| 138774 | - pSelect->pEList = | |
| 138775 | - sqlite3ExpandReturning(pParse, pList, pParse->pTriggerTab); | |
| 138776 | - sqlite3SelectDestInit(&sDest, SRT_Output, 0); | |
| 138777 | - pNew = sqlite3SelectDup(db, pSelect, 0); | |
| 138778 | - if( pNew ){ | |
| 138779 | - sqlite3Select(pParse, pNew, &sDest); | |
| 138780 | - if( pNew->selFlags & (SF_Aggregate|SF_HasAgg|SF_WinRewrite) ){ | |
| 138781 | - sqlite3ErrorMsg(pParse, "aggregates not allowed in RETURNING"); | |
| 138782 | - } | |
| 138783 | - sqlite3SelectDelete(db, pNew); | |
| 138784 | - } | |
| 138785 | - sqlite3ExprListDelete(db, pSelect->pEList); | |
| 138786 | - pStep->pSelect->pEList = pList; | |
| 138787 | - break; | |
| 138788 | - } | |
| 138789 | 138853 | } |
| 138790 | 138854 | } |
| 138791 | 138855 | |
| 138792 | 138856 | return 0; |
| 138793 | 138857 | } |
| @@ -138874,11 +138938,10 @@ | ||
| 138874 | 138938 | pSubParse->db = db; |
| 138875 | 138939 | pSubParse->pTriggerTab = pTab; |
| 138876 | 138940 | pSubParse->pToplevel = pTop; |
| 138877 | 138941 | pSubParse->zAuthContext = pTrigger->zName; |
| 138878 | 138942 | pSubParse->eTriggerOp = pTrigger->op; |
| 138879 | - pSubParse->bReturning = pTrigger->bReturning; | |
| 138880 | 138943 | pSubParse->nQueryLoop = pParse->nQueryLoop; |
| 138881 | 138944 | pSubParse->disableVtab = pParse->disableVtab; |
| 138882 | 138945 | |
| 138883 | 138946 | v = sqlite3GetVdbe(pSubParse); |
| 138884 | 138947 | if( v ){ |
| @@ -138924,13 +138987,10 @@ | ||
| 138924 | 138987 | |
| 138925 | 138988 | transferParseError(pParse, pSubParse); |
| 138926 | 138989 | if( db->mallocFailed==0 && pParse->nErr==0 ){ |
| 138927 | 138990 | pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg); |
| 138928 | 138991 | } |
| 138929 | - if( pTrigger->bReturning ){ | |
| 138930 | - sqlite3VdbeColumnInfoXfer(sqlite3ParseToplevel(pParse)->pVdbe, v); | |
| 138931 | - } | |
| 138932 | 138992 | pProgram->nMem = pSubParse->nMem; |
| 138933 | 138993 | pProgram->nCsr = pSubParse->nTab; |
| 138934 | 138994 | pProgram->token = (void *)pTrigger; |
| 138935 | 138995 | pPrg->aColmask[0] = pSubParse->oldmask; |
| 138936 | 138996 | pPrg->aColmask[1] = pSubParse->newmask; |
| @@ -139036,11 +139096,11 @@ | ||
| 139036 | 139096 | ** reg+0 OLD.rowid |
| 139037 | 139097 | ** reg+1 OLD.* value of left-most column of pTab |
| 139038 | 139098 | ** ... ... |
| 139039 | 139099 | ** reg+N OLD.* value of right-most column of pTab |
| 139040 | 139100 | ** reg+N+1 NEW.rowid |
| 139041 | -** reg+N+2 OLD.* value of left-most column of pTab | |
| 139101 | +** reg+N+2 NEW.* value of left-most column of pTab | |
| 139042 | 139102 | ** ... ... |
| 139043 | 139103 | ** reg+N+N+1 NEW.* value of right-most column of pTab |
| 139044 | 139104 | ** |
| 139045 | 139105 | ** For ON DELETE triggers, the registers containing the NEW.* values will |
| 139046 | 139106 | ** never be accessed by the trigger program, so they are not allocated or |
| @@ -139089,16 +139149,16 @@ | ||
| 139089 | 139149 | ** doing the UPDATE part of an UPSERT. |
| 139090 | 139150 | */ |
| 139091 | 139151 | if( (p->op==op || (p->bReturning && p->op==TK_INSERT && op==TK_UPDATE)) |
| 139092 | 139152 | && p->tr_tm==tr_tm |
| 139093 | 139153 | && checkColumnOverlap(p->pColumns, pChanges) |
| 139094 | - && (sqlite3IsToplevel(pParse) || !p->bReturning) | |
| 139095 | 139154 | ){ |
| 139096 | - u8 origOp = p->op; | |
| 139097 | - p->op = op; | |
| 139098 | - sqlite3CodeRowTriggerDirect(pParse, p, pTab, reg, orconf, ignoreJump); | |
| 139099 | - p->op = origOp; | |
| 139155 | + if( !p->bReturning ){ | |
| 139156 | + sqlite3CodeRowTriggerDirect(pParse, p, pTab, reg, orconf, ignoreJump); | |
| 139157 | + }else if( sqlite3IsToplevel(pParse) ){ | |
| 139158 | + codeReturningTrigger(pParse, p, pTab, reg); | |
| 139159 | + } | |
| 139100 | 139160 | } |
| 139101 | 139161 | } |
| 139102 | 139162 | } |
| 139103 | 139163 | |
| 139104 | 139164 | /* |
| @@ -139139,17 +139199,22 @@ | ||
| 139139 | 139199 | u32 mask = 0; |
| 139140 | 139200 | Trigger *p; |
| 139141 | 139201 | |
| 139142 | 139202 | assert( isNew==1 || isNew==0 ); |
| 139143 | 139203 | for(p=pTrigger; p; p=p->pNext){ |
| 139144 | - if( p->op==op && (tr_tm&p->tr_tm) | |
| 139204 | + if( p->op==op | |
| 139205 | + && (tr_tm&p->tr_tm) | |
| 139145 | 139206 | && checkColumnOverlap(p->pColumns,pChanges) |
| 139146 | 139207 | ){ |
| 139147 | - TriggerPrg *pPrg; | |
| 139148 | - pPrg = getRowTrigger(pParse, p, pTab, orconf); | |
| 139149 | - if( pPrg ){ | |
| 139150 | - mask |= pPrg->aColmask[isNew]; | |
| 139208 | + if( p->bReturning ){ | |
| 139209 | + mask = 0xffffffff; | |
| 139210 | + }else{ | |
| 139211 | + TriggerPrg *pPrg; | |
| 139212 | + pPrg = getRowTrigger(pParse, p, pTab, orconf); | |
| 139213 | + if( pPrg ){ | |
| 139214 | + mask |= pPrg->aColmask[isNew]; | |
| 139215 | + } | |
| 139151 | 139216 | } |
| 139152 | 139217 | } |
| 139153 | 139218 | } |
| 139154 | 139219 | |
| 139155 | 139220 | return mask; |
| @@ -142036,11 +142101,11 @@ | ||
| 142036 | 142101 | ){ |
| 142037 | 142102 | if( !pTab->aCol ){ |
| 142038 | 142103 | Table *pNew = sParse.pNewTable; |
| 142039 | 142104 | Index *pIdx; |
| 142040 | 142105 | pTab->aCol = pNew->aCol; |
| 142041 | - pTab->nCol = pNew->nCol; | |
| 142106 | + pTab->nNVCol = pTab->nCol = pNew->nCol; | |
| 142042 | 142107 | pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid); |
| 142043 | 142108 | pNew->nCol = 0; |
| 142044 | 142109 | pNew->aCol = 0; |
| 142045 | 142110 | assert( pTab->pIndex==0 ); |
| 142046 | 142111 | assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 ); |
| @@ -228415,11 +228480,11 @@ | ||
| 228415 | 228480 | int nArg, /* Number of args */ |
| 228416 | 228481 | sqlite3_value **apUnused /* Function arguments */ |
| 228417 | 228482 | ){ |
| 228418 | 228483 | assert( nArg==0 ); |
| 228419 | 228484 | UNUSED_PARAM2(nArg, apUnused); |
| 228420 | - sqlite3_result_text(pCtx, "fts5: 2021-02-03 13:20:12 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644d0902", -1, SQLITE_TRANSIENT); | |
| 228485 | + sqlite3_result_text(pCtx, "fts5: 2021-02-05 17:34:47 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4c30c", -1, SQLITE_TRANSIENT); | |
| 228421 | 228486 | } |
| 228422 | 228487 | |
| 228423 | 228488 | /* |
| 228424 | 228489 | ** Return true if zName is the extension on one of the shadow tables used |
| 228425 | 228490 | ** by this module. |
| @@ -233341,12 +233406,12 @@ | ||
| 233341 | 233406 | } |
| 233342 | 233407 | #endif /* SQLITE_CORE */ |
| 233343 | 233408 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 233344 | 233409 | |
| 233345 | 233410 | /************** End of stmt.c ************************************************/ |
| 233346 | -#if __LINE__!=233346 | |
| 233411 | +#if __LINE__!=233411 | |
| 233347 | 233412 | #undef SQLITE_SOURCE_ID |
| 233348 | -#define SQLITE_SOURCE_ID "2021-02-03 13:20:12 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644dalt2" | |
| 233413 | +#define SQLITE_SOURCE_ID "2021-02-05 17:34:47 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4alt2" | |
| 233349 | 233414 | #endif |
| 233350 | 233415 | /* Return the source-id for this library */ |
| 233351 | 233416 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 233352 | 233417 | /************************** End of sqlite3.c ******************************/ |
| 233353 | 233418 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1186,11 +1186,11 @@ | |
| 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | */ |
| 1189 | #define SQLITE_VERSION "3.35.0" |
| 1190 | #define SQLITE_VERSION_NUMBER 3035000 |
| 1191 | #define SQLITE_SOURCE_ID "2021-02-03 13:20:12 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644d0902" |
| 1192 | |
| 1193 | /* |
| 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | ** |
| @@ -16002,11 +16002,10 @@ | |
| 16002 | #endif |
| 16003 | SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*); |
| 16004 | SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*); |
| 16005 | SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*); |
| 16006 | SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int); |
| 16007 | SQLITE_PRIVATE void sqlite3VdbeColumnInfoXfer(Vdbe*,Vdbe*); |
| 16008 | SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*)); |
| 16009 | SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*); |
| 16010 | SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*); |
| 16011 | SQLITE_PRIVATE u8 sqlite3VdbePrepareFlags(Vdbe*); |
| 16012 | SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, u8); |
| @@ -18223,11 +18222,11 @@ | |
| 18223 | #define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */ |
| 18224 | #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 18225 | #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ |
| 18226 | #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ |
| 18227 | #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ |
| 18228 | #define EP_Alias 0x400000 /* Is an alias for a result set column */ |
| 18229 | #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */ |
| 18230 | #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */ |
| 18231 | #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ |
| 18232 | #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ |
| 18233 | #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ |
| @@ -18498,10 +18497,11 @@ | |
| 18498 | SrcList *pSrcList; /* One or more tables used to resolve names */ |
| 18499 | union { |
| 18500 | ExprList *pEList; /* Optional list of result-set columns */ |
| 18501 | AggInfo *pAggInfo; /* Information about aggregates at this level */ |
| 18502 | Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */ |
| 18503 | } uNC; |
| 18504 | NameContext *pNext; /* Next outer name context. NULL for outermost */ |
| 18505 | int nRef; /* Number of names resolved by this context */ |
| 18506 | int nErr; /* Number of errors encountered while resolving names */ |
| 18507 | int ncFlags; /* Zero or more NC_* flags defined below */ |
| @@ -18526,10 +18526,11 @@ | |
| 18526 | #define NC_SelfRef 0x0002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */ |
| 18527 | #define NC_VarSelect 0x00040 /* A correlated subquery has been seen */ |
| 18528 | #define NC_UEList 0x00080 /* True if uNC.pEList is used */ |
| 18529 | #define NC_UAggInfo 0x00100 /* True if uNC.pAggInfo is used */ |
| 18530 | #define NC_UUpsert 0x00200 /* True if uNC.pUpsert is used */ |
| 18531 | #define NC_MinMaxAgg 0x01000 /* min/max aggregates seen. See note above */ |
| 18532 | #define NC_Complex 0x02000 /* True if a function or subquery seen */ |
| 18533 | #define NC_AllowWin 0x04000 /* Window functions are allowed here */ |
| 18534 | #define NC_HasWin 0x08000 /* One or more window functions seen */ |
| 18535 | #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */ |
| @@ -18886,11 +18887,14 @@ | |
| 18886 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| 18887 | Parse *pToplevel; /* Parse structure for main program (or NULL) */ |
| 18888 | Table *pTriggerTab; /* Table triggers are being coded for */ |
| 18889 | Parse *pParentParse; /* Parent parser if this parser is nested */ |
| 18890 | AggInfo *pAggList; /* List of all AggInfo objects */ |
| 18891 | int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */ |
| 18892 | u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ |
| 18893 | u32 oldmask; /* Mask of old.* columns referenced */ |
| 18894 | u32 newmask; /* Mask of new.* columns referenced */ |
| 18895 | u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ |
| 18896 | u8 bReturning; /* Coding a RETURNING trigger */ |
| @@ -19108,11 +19112,11 @@ | |
| 19108 | Trigger *pTrig; /* The trigger that this step is a part of */ |
| 19109 | Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ |
| 19110 | char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ |
| 19111 | SrcList *pFrom; /* FROM clause for UPDATE statement (if any) */ |
| 19112 | Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ |
| 19113 | ExprList *pExprList; /* SET clause for UPDATE */ |
| 19114 | IdList *pIdList; /* Column names for INSERT */ |
| 19115 | Upsert *pUpsert; /* Upsert clauses on an INSERT */ |
| 19116 | char *zSpan; /* Original SQL text of this command */ |
| 19117 | TriggerStep *pNext; /* Next in the link-list */ |
| 19118 | TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
| @@ -19124,12 +19128,13 @@ | |
| 19124 | struct Returning { |
| 19125 | Parse *pParse; /* The parse that includes the RETURNING clause */ |
| 19126 | ExprList *pReturnEL; /* List of expressions to return */ |
| 19127 | Trigger retTrig; /* The transient trigger that implements RETURNING */ |
| 19128 | TriggerStep retTStep; /* The trigger step */ |
| 19129 | Select retSel; /* The SELECT statement that implements RETURNING */ |
| 19130 | u64 retSrcList; /* The empty FROM clause of the SELECT */ |
| 19131 | }; |
| 19132 | |
| 19133 | /* |
| 19134 | ** An objected used to accumulate the text of a string where we |
| 19135 | ** do not necessarily know how big the string will be in the end. |
| @@ -21275,11 +21280,11 @@ | |
| 21275 | struct Vdbe { |
| 21276 | sqlite3 *db; /* The database connection that owns this statement */ |
| 21277 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 21278 | Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 21279 | ynVar nVar; /* Number of entries in aVar[] */ |
| 21280 | u32 magic; /* Magic number for sanity checking */ |
| 21281 | int nMem; /* Number of memory locations currently allocated */ |
| 21282 | int nCursor; /* Number of slots in apCsr[] */ |
| 21283 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 21284 | int pc; /* The program counter */ |
| 21285 | int rc; /* Value to return */ |
| @@ -72861,11 +72866,11 @@ | |
| 72861 | */ |
| 72862 | for(i=0; i<nNew; i++){ |
| 72863 | aPgOrder[i] = aPgno[i] = apNew[i]->pgno; |
| 72864 | aPgFlags[i] = apNew[i]->pDbPage->flags; |
| 72865 | for(j=0; j<i; j++){ |
| 72866 | if( aPgno[j]==aPgno[i] ){ |
| 72867 | /* This branch is taken if the set of sibling pages somehow contains |
| 72868 | ** duplicate entries. This can happen if the database is corrupt. |
| 72869 | ** It would be simpler to detect this as part of the loop below, but |
| 72870 | ** we do the detection here in order to avoid populating the pager |
| 72871 | ** cache with two separate objects associated with the same |
| @@ -78292,11 +78297,11 @@ | |
| 78292 | db->pVdbe->pPrev = p; |
| 78293 | } |
| 78294 | p->pNext = db->pVdbe; |
| 78295 | p->pPrev = 0; |
| 78296 | db->pVdbe = p; |
| 78297 | p->magic = VDBE_MAGIC_INIT; |
| 78298 | p->pParse = pParse; |
| 78299 | pParse->pVdbe = p; |
| 78300 | assert( pParse->aLabel==0 ); |
| 78301 | assert( pParse->nLabel==0 ); |
| 78302 | assert( p->nOpAlloc==0 ); |
| @@ -78493,11 +78498,11 @@ | |
| 78493 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ |
| 78494 | int i; |
| 78495 | VdbeOp *pOp; |
| 78496 | |
| 78497 | i = p->nOp; |
| 78498 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 78499 | assert( op>=0 && op<0xff ); |
| 78500 | if( p->nOpAlloc<=i ){ |
| 78501 | return growOp3(p, op, p1, p2, p3); |
| 78502 | } |
| 78503 | p->nOp++; |
| @@ -78822,11 +78827,11 @@ | |
| 78822 | } |
| 78823 | } |
| 78824 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ |
| 78825 | Parse *p = v->pParse; |
| 78826 | int j = ADDR(x); |
| 78827 | assert( v->magic==VDBE_MAGIC_INIT ); |
| 78828 | assert( j<-p->nLabel ); |
| 78829 | assert( j>=0 ); |
| 78830 | #ifdef SQLITE_DEBUG |
| 78831 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 78832 | printf("RESOLVE LABEL %d to %d\n", x, v->nOp); |
| @@ -79147,11 +79152,11 @@ | |
| 79147 | |
| 79148 | /* |
| 79149 | ** Return the address of the next instruction to be inserted. |
| 79150 | */ |
| 79151 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ |
| 79152 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 79153 | return p->nOp; |
| 79154 | } |
| 79155 | |
| 79156 | /* |
| 79157 | ** Verify that at least N opcode slots are available in p without |
| @@ -79232,11 +79237,11 @@ | |
| 79232 | int iLineno /* Source-file line number of first opcode */ |
| 79233 | ){ |
| 79234 | int i; |
| 79235 | VdbeOp *pOut, *pFirst; |
| 79236 | assert( nOp>0 ); |
| 79237 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 79238 | if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){ |
| 79239 | return 0; |
| 79240 | } |
| 79241 | pFirst = pOut = &p->aOp[p->nOp]; |
| 79242 | for(i=0; i<nOp; i++, aOp++, pOut++){ |
| @@ -79556,11 +79561,11 @@ | |
| 79556 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){ |
| 79557 | Op *pOp; |
| 79558 | sqlite3 *db; |
| 79559 | assert( p!=0 ); |
| 79560 | db = p->db; |
| 79561 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 79562 | assert( p->aOp!=0 || db->mallocFailed ); |
| 79563 | if( db->mallocFailed ){ |
| 79564 | if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4); |
| 79565 | return; |
| 79566 | } |
| @@ -79685,11 +79690,11 @@ | |
| 79685 | */ |
| 79686 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ |
| 79687 | /* C89 specifies that the constant "dummy" will be initialized to all |
| 79688 | ** zeros, which is correct. MSVC generates a warning, nevertheless. */ |
| 79689 | static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */ |
| 79690 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 79691 | if( addr<0 ){ |
| 79692 | addr = p->nOp - 1; |
| 79693 | } |
| 79694 | assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed ); |
| 79695 | if( p->db->mallocFailed ){ |
| @@ -80370,11 +80375,11 @@ | |
| 80370 | int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0); |
| 80371 | Op *aOp; /* Array of opcodes */ |
| 80372 | Op *pOp; /* Current opcode */ |
| 80373 | |
| 80374 | assert( p->explain ); |
| 80375 | assert( p->magic==VDBE_MAGIC_RUN ); |
| 80376 | assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM ); |
| 80377 | |
| 80378 | /* Even though this opcode does not use dynamic strings for |
| 80379 | ** the result, result columns may become dynamic if the user calls |
| 80380 | ** sqlite3_column_text16(), causing a translation to UTF-16 encoding. |
| @@ -80550,18 +80555,18 @@ | |
| 80550 | SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){ |
| 80551 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 80552 | int i; |
| 80553 | #endif |
| 80554 | assert( p!=0 ); |
| 80555 | assert( p->magic==VDBE_MAGIC_INIT || p->magic==VDBE_MAGIC_RESET ); |
| 80556 | |
| 80557 | /* There should be at least one opcode. |
| 80558 | */ |
| 80559 | assert( p->nOp>0 ); |
| 80560 | |
| 80561 | /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */ |
| 80562 | p->magic = VDBE_MAGIC_RUN; |
| 80563 | |
| 80564 | #ifdef SQLITE_DEBUG |
| 80565 | for(i=0; i<p->nMem; i++){ |
| 80566 | assert( p->aMem[i].db==p->db ); |
| 80567 | } |
| @@ -80613,11 +80618,11 @@ | |
| 80613 | struct ReusableSpace x; /* Reusable bulk memory */ |
| 80614 | |
| 80615 | assert( p!=0 ); |
| 80616 | assert( p->nOp>0 ); |
| 80617 | assert( pParse!=0 ); |
| 80618 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 80619 | assert( pParse==p->pParse ); |
| 80620 | p->pVList = pParse->pVList; |
| 80621 | pParse->pVList = 0; |
| 80622 | db = p->db; |
| 80623 | assert( db->mallocFailed==0 ); |
| @@ -80852,27 +80857,10 @@ | |
| 80852 | p->aColName = (Mem*)sqlite3DbMallocRawNN(db, sizeof(Mem)*n ); |
| 80853 | if( p->aColName==0 ) return; |
| 80854 | initMemArray(p->aColName, n, db, MEM_Null); |
| 80855 | } |
| 80856 | |
| 80857 | /* |
| 80858 | ** Transfer the column count and name information from one Vdbe to |
| 80859 | ** another. |
| 80860 | */ |
| 80861 | SQLITE_PRIVATE void sqlite3VdbeColumnInfoXfer(Vdbe *pTo, Vdbe *pFrom){ |
| 80862 | sqlite3 *db = pTo->db; |
| 80863 | assert( db==pFrom->db ); |
| 80864 | if( pTo->nResColumn ){ |
| 80865 | releaseMemArray(pTo->aColName, pTo->nResColumn*COLNAME_N); |
| 80866 | sqlite3DbFree(db, pTo->aColName); |
| 80867 | } |
| 80868 | pTo->aColName = pFrom->aColName; |
| 80869 | pFrom->aColName = 0; |
| 80870 | pTo->nResColumn = pFrom->nResColumn; |
| 80871 | pFrom->nResColumn = 0; |
| 80872 | } |
| 80873 | |
| 80874 | /* |
| 80875 | ** Set the name of the idx'th column to be returned by the SQL statement. |
| 80876 | ** zName must be a pointer to a nul terminated string. |
| 80877 | ** |
| 80878 | ** This call must be made after a call to sqlite3VdbeSetNumCols(). |
| @@ -81315,11 +81303,11 @@ | |
| 81315 | ** Then the internal cache might have been left in an inconsistent |
| 81316 | ** state. We need to rollback the statement transaction, if there is |
| 81317 | ** one, or the complete transaction if there is no statement transaction. |
| 81318 | */ |
| 81319 | |
| 81320 | if( p->magic!=VDBE_MAGIC_RUN ){ |
| 81321 | return SQLITE_OK; |
| 81322 | } |
| 81323 | if( db->mallocFailed ){ |
| 81324 | p->rc = SQLITE_NOMEM_BKPT; |
| 81325 | } |
| @@ -81473,11 +81461,11 @@ | |
| 81473 | if( p->bIsReader ) db->nVdbeRead--; |
| 81474 | assert( db->nVdbeActive>=db->nVdbeRead ); |
| 81475 | assert( db->nVdbeRead>=db->nVdbeWrite ); |
| 81476 | assert( db->nVdbeWrite>=0 ); |
| 81477 | } |
| 81478 | p->magic = VDBE_MAGIC_HALT; |
| 81479 | checkActiveVdbeCnt(db); |
| 81480 | if( db->mallocFailed ){ |
| 81481 | p->rc = SQLITE_NOMEM_BKPT; |
| 81482 | } |
| 81483 | |
| @@ -81646,21 +81634,21 @@ | |
| 81646 | } |
| 81647 | fclose(out); |
| 81648 | } |
| 81649 | } |
| 81650 | #endif |
| 81651 | p->magic = VDBE_MAGIC_RESET; |
| 81652 | return p->rc & db->errMask; |
| 81653 | } |
| 81654 | |
| 81655 | /* |
| 81656 | ** Clean up and delete a VDBE after execution. Return an integer which is |
| 81657 | ** the result code. Write any error message text into *pzErrMsg. |
| 81658 | */ |
| 81659 | SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){ |
| 81660 | int rc = SQLITE_OK; |
| 81661 | if( p->magic==VDBE_MAGIC_RUN || p->magic==VDBE_MAGIC_HALT ){ |
| 81662 | rc = sqlite3VdbeReset(p); |
| 81663 | assert( (rc & p->db->errMask)==rc ); |
| 81664 | } |
| 81665 | sqlite3VdbeDelete(p); |
| 81666 | return rc; |
| @@ -81717,11 +81705,11 @@ | |
| 81717 | for(pSub=p->pProgram; pSub; pSub=pNext){ |
| 81718 | pNext = pSub->pNext; |
| 81719 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 81720 | sqlite3DbFree(db, pSub); |
| 81721 | } |
| 81722 | if( p->magic!=VDBE_MAGIC_INIT ){ |
| 81723 | releaseMemArray(p->aVar, p->nVar); |
| 81724 | sqlite3DbFree(db, p->pVList); |
| 81725 | sqlite3DbFree(db, p->pFree); |
| 81726 | } |
| 81727 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| @@ -81765,11 +81753,11 @@ | |
| 81765 | db->pVdbe = p->pNext; |
| 81766 | } |
| 81767 | if( p->pNext ){ |
| 81768 | p->pNext->pPrev = p->pPrev; |
| 81769 | } |
| 81770 | p->magic = VDBE_MAGIC_DEAD; |
| 81771 | p->db = 0; |
| 81772 | sqlite3DbFreeNN(db, p); |
| 81773 | } |
| 81774 | |
| 81775 | /* |
| @@ -84144,11 +84132,11 @@ | |
| 84144 | static int sqlite3Step(Vdbe *p){ |
| 84145 | sqlite3 *db; |
| 84146 | int rc; |
| 84147 | |
| 84148 | assert(p); |
| 84149 | if( p->magic!=VDBE_MAGIC_RUN ){ |
| 84150 | /* We used to require that sqlite3_reset() be called before retrying |
| 84151 | ** sqlite3_step() after any error or after SQLITE_DONE. But beginning |
| 84152 | ** with version 3.7.0, we changed this so that sqlite3_reset() would |
| 84153 | ** be called automatically instead of throwing the SQLITE_MISUSE error. |
| 84154 | ** This "automatic-reset" change is not technically an incompatibility, |
| @@ -84860,11 +84848,11 @@ | |
| 84860 | Mem *pVar; |
| 84861 | if( vdbeSafetyNotNull(p) ){ |
| 84862 | return SQLITE_MISUSE_BKPT; |
| 84863 | } |
| 84864 | sqlite3_mutex_enter(p->db->mutex); |
| 84865 | if( p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){ |
| 84866 | sqlite3Error(p->db, SQLITE_MISUSE); |
| 84867 | sqlite3_mutex_leave(p->db->mutex); |
| 84868 | sqlite3_log(SQLITE_MISUSE, |
| 84869 | "bind on a busy prepared statement: [%s]", p->zSql); |
| 84870 | return SQLITE_MISUSE_BKPT; |
| @@ -85214,11 +85202,11 @@ | |
| 85214 | /* |
| 85215 | ** Return true if the prepared statement is in need of being reset. |
| 85216 | */ |
| 85217 | SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ |
| 85218 | Vdbe *v = (Vdbe*)pStmt; |
| 85219 | return v!=0 && v->magic==VDBE_MAGIC_RUN && v->pc>=0; |
| 85220 | } |
| 85221 | |
| 85222 | /* |
| 85223 | ** Return a pointer to the next prepared statement after pStmt associated |
| 85224 | ** with database connection pDb. If pStmt is NULL, return the first |
| @@ -86552,11 +86540,11 @@ | |
| 86552 | #ifdef VDBE_PROFILE |
| 86553 | u64 start; /* CPU clock count at start of opcode */ |
| 86554 | #endif |
| 86555 | /*** INSERT STACK UNION HERE ***/ |
| 86556 | |
| 86557 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 86558 | sqlite3VdbeEnter(p); |
| 86559 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 86560 | if( db->xProgress ){ |
| 86561 | u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; |
| 86562 | assert( 0 < db->nProgressOps ); |
| @@ -98629,11 +98617,10 @@ | |
| 98629 | assert( db->mallocFailed ); |
| 98630 | } |
| 98631 | } |
| 98632 | sqlite3DbFree(db, pDup); |
| 98633 | } |
| 98634 | ExprSetProperty(pExpr, EP_Alias); |
| 98635 | } |
| 98636 | |
| 98637 | |
| 98638 | /* |
| 98639 | ** Return TRUE if the name zCol occurs anywhere in the USING clause. |
| @@ -98888,11 +98875,11 @@ | |
| 98888 | #if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) |
| 98889 | /* If we have not already resolved the name, then maybe |
| 98890 | ** it is a new.* or old.* trigger argument reference. Or |
| 98891 | ** maybe it is an excluded.* from an upsert. |
| 98892 | */ |
| 98893 | if( zDb==0 && cntTab==0 ){ |
| 98894 | pTab = 0; |
| 98895 | #ifndef SQLITE_OMIT_TRIGGER |
| 98896 | if( pParse->pTriggerTab!=0 ){ |
| 98897 | int op = pParse->eTriggerOp; |
| 98898 | assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT ); |
| @@ -98946,31 +98933,35 @@ | |
| 98946 | eNewExprOp = TK_COLUMN; |
| 98947 | }else{ |
| 98948 | pExpr->iTable = pNC->uNC.pUpsert->regData + |
| 98949 | sqlite3TableColumnToStorage(pTab, iCol); |
| 98950 | eNewExprOp = TK_REGISTER; |
| 98951 | ExprSetProperty(pExpr, EP_Alias); |
| 98952 | } |
| 98953 | }else |
| 98954 | #endif /* SQLITE_OMIT_UPSERT */ |
| 98955 | { |
| 98956 | #ifndef SQLITE_OMIT_TRIGGER |
| 98957 | if( iCol<0 ){ |
| 98958 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 98959 | }else if( pExpr->iTable==0 ){ |
| 98960 | testcase( iCol==31 ); |
| 98961 | testcase( iCol==32 ); |
| 98962 | pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); |
| 98963 | }else{ |
| 98964 | testcase( iCol==31 ); |
| 98965 | testcase( iCol==32 ); |
| 98966 | pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); |
| 98967 | } |
| 98968 | pExpr->y.pTab = pTab; |
| 98969 | pExpr->iColumn = (i16)iCol; |
| 98970 | eNewExprOp = TK_TRIGGER; |
| 98971 | #endif /* SQLITE_OMIT_TRIGGER */ |
| 98972 | } |
| 98973 | } |
| 98974 | } |
| 98975 | } |
| 98976 | #endif /* !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) */ |
| @@ -99147,11 +99138,13 @@ | |
| 99147 | pExpr->op = eNewExprOp; |
| 99148 | ExprSetProperty(pExpr, EP_Leaf); |
| 99149 | lookupname_end: |
| 99150 | if( cnt==1 ){ |
| 99151 | assert( pNC!=0 ); |
| 99152 | if( !ExprHasProperty(pExpr, EP_Alias) ){ |
| 99153 | sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); |
| 99154 | } |
| 99155 | /* Increment the nRef value on all name contexts from TopNC up to |
| 99156 | ** the point where the name matched. */ |
| 99157 | for(;;){ |
| @@ -111033,20 +111026,19 @@ | |
| 111033 | Parse *pParse, /* The parser context */ |
| 111034 | Expr *pExpr, /* The expression to check authorization on */ |
| 111035 | Schema *pSchema, /* The schema of the expression */ |
| 111036 | SrcList *pTabList /* All table that pExpr might refer to */ |
| 111037 | ){ |
| 111038 | sqlite3 *db = pParse->db; |
| 111039 | Table *pTab = 0; /* The table being read */ |
| 111040 | const char *zCol; /* Name of the column of the table */ |
| 111041 | int iSrc; /* Index in pTabList->a[] of table being read */ |
| 111042 | int iDb; /* The index of the database the expression refers to */ |
| 111043 | int iCol; /* Index of column in table */ |
| 111044 | |
| 111045 | assert( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ); |
| 111046 | assert( !IN_RENAME_OBJECT || db->xAuth==0 ); |
| 111047 | if( db->xAuth==0 ) return; |
| 111048 | iDb = sqlite3SchemaToIndex(pParse->db, pSchema); |
| 111049 | if( iDb<0 ){ |
| 111050 | /* An attempt to read a column out of a subquery or other |
| 111051 | ** temporary table. */ |
| 111052 | return; |
| @@ -111073,11 +111065,11 @@ | |
| 111073 | assert( pTab->iPKey<pTab->nCol ); |
| 111074 | zCol = pTab->aCol[pTab->iPKey].zName; |
| 111075 | }else{ |
| 111076 | zCol = "ROWID"; |
| 111077 | } |
| 111078 | assert( iDb>=0 && iDb<db->nDb ); |
| 111079 | if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){ |
| 111080 | pExpr->op = TK_NULL; |
| 111081 | } |
| 111082 | } |
| 111083 | |
| @@ -111305,18 +111297,38 @@ | |
| 111305 | } |
| 111306 | |
| 111307 | /* Begin by generating some termination code at the end of the |
| 111308 | ** vdbe program |
| 111309 | */ |
| 111310 | if( pParse->pVdbe==0 && db->init.busy ){ |
| 111311 | pParse->rc = SQLITE_DONE; |
| 111312 | return; |
| 111313 | } |
| 111314 | v = sqlite3GetVdbe(pParse); |
| 111315 | assert( !pParse->isMultiWrite |
| 111316 | || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort)); |
| 111317 | if( v ){ |
| 111318 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 111319 | |
| 111320 | #if SQLITE_USER_AUTHENTICATION |
| 111321 | if( pParse->nTableLock>0 && db->init.busy==0 ){ |
| 111322 | sqlite3UserAuthInit(db); |
| @@ -111389,16 +111401,20 @@ | |
| 111389 | if( iReg>0 ){ |
| 111390 | sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg); |
| 111391 | } |
| 111392 | } |
| 111393 | } |
| 111394 | |
| 111395 | /* Finally, jump back to the beginning of the executable code. */ |
| 111396 | sqlite3VdbeGoto(v, 1); |
| 111397 | } |
| 111398 | } |
| 111399 | |
| 111400 | |
| 111401 | /* Get the VDBE program ready for execution |
| 111402 | */ |
| 111403 | if( v && pParse->nErr==0 && !db->mallocFailed ){ |
| 111404 | /* A minimum of one cursor is required if autoincrement is used |
| @@ -112372,11 +112388,12 @@ | |
| 112372 | if( isView || isVirtual ){ |
| 112373 | sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2); |
| 112374 | }else |
| 112375 | #endif |
| 112376 | { |
| 112377 | pParse->addrCrTab = |
| 112378 | sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY); |
| 112379 | } |
| 112380 | sqlite3OpenSchemaTable(pParse, iDb); |
| 112381 | sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1); |
| 112382 | sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC); |
| @@ -112450,10 +112467,11 @@ | |
| 112450 | pRet = sqlite3DbMallocZero(db, sizeof(*pRet)); |
| 112451 | if( pRet==0 ){ |
| 112452 | sqlite3ExprListDelete(db, pList); |
| 112453 | return; |
| 112454 | } |
| 112455 | pRet->pParse = pParse; |
| 112456 | pRet->pReturnEL = pList; |
| 112457 | sqlite3ParserAddCleanup(pParse, |
| 112458 | (void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet); |
| 112459 | if( db->mallocFailed ) return; |
| @@ -112463,14 +112481,11 @@ | |
| 112463 | pRet->retTrig.bReturning = 1; |
| 112464 | pRet->retTrig.pSchema = db->aDb[1].pSchema; |
| 112465 | pRet->retTrig.step_list = &pRet->retTStep; |
| 112466 | pRet->retTStep.op = TK_RETURNING; |
| 112467 | pRet->retTStep.pTrig = &pRet->retTrig; |
| 112468 | pRet->retTStep.pSelect = &pRet->retSel; |
| 112469 | pRet->retSel.op = TK_ALL; |
| 112470 | pRet->retSel.pEList = pList; |
| 112471 | pRet->retSel.pSrc = (SrcList*)&pRet->retSrcList; |
| 112472 | pHash = &(db->aDb[1].pSchema->trigHash); |
| 112473 | assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0 ); |
| 112474 | if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig) |
| 112475 | ==&pRet->retTrig ){ |
| 112476 | sqlite3OomFault(db); |
| @@ -113306,13 +113321,14 @@ | |
| 113306 | } |
| 113307 | |
| 113308 | /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY |
| 113309 | ** into BTREE_BLOBKEY. |
| 113310 | */ |
| 113311 | if( pParse->addrCrTab ){ |
| 113312 | assert( v ); |
| 113313 | sqlite3VdbeChangeP3(v, pParse->addrCrTab, BTREE_BLOBKEY); |
| 113314 | } |
| 113315 | |
| 113316 | /* Locate the PRIMARY KEY index. Or, if this table was originally |
| 113317 | ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. |
| 113318 | */ |
| @@ -121313,11 +121329,13 @@ | |
| 121313 | ** non-zero. If there is no foreign key related processing, this function |
| 121314 | ** returns zero. |
| 121315 | ** |
| 121316 | ** For an UPDATE, this function returns 2 if: |
| 121317 | ** |
| 121318 | ** * There are any FKs for which pTab is the child and the parent table, or |
| 121319 | ** * the UPDATE modifies one or more parent keys for which the action is |
| 121320 | ** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL). |
| 121321 | ** |
| 121322 | ** Or, assuming some other foreign key processing is required, 1. |
| 121323 | */ |
| @@ -121325,40 +121343,41 @@ | |
| 121325 | Parse *pParse, /* Parse context */ |
| 121326 | Table *pTab, /* Table being modified */ |
| 121327 | int *aChange, /* Non-NULL for UPDATE operations */ |
| 121328 | int chngRowid /* True for UPDATE that affects rowid */ |
| 121329 | ){ |
| 121330 | int eRet = 0; |
| 121331 | if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 121332 | if( !aChange ){ |
| 121333 | /* A DELETE operation. Foreign key processing is required if the |
| 121334 | ** table in question is either the child or parent table for any |
| 121335 | ** foreign key constraint. */ |
| 121336 | eRet = (sqlite3FkReferences(pTab) || pTab->pFKey); |
| 121337 | }else{ |
| 121338 | /* This is an UPDATE. Foreign key processing is only required if the |
| 121339 | ** operation modifies one or more child or parent key columns. */ |
| 121340 | FKey *p; |
| 121341 | |
| 121342 | /* Check if any child key columns are being modified. */ |
| 121343 | for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 121344 | if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2; |
| 121345 | if( fkChildIsModified(pTab, p, aChange, chngRowid) ){ |
| 121346 | eRet = 1; |
| 121347 | } |
| 121348 | } |
| 121349 | |
| 121350 | /* Check if any parent key columns are being modified. */ |
| 121351 | for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ |
| 121352 | if( fkParentIsModified(pTab, p, aChange, chngRowid) ){ |
| 121353 | if( p->aAction[1]!=OE_None ) return 2; |
| 121354 | eRet = 1; |
| 121355 | } |
| 121356 | } |
| 121357 | } |
| 121358 | } |
| 121359 | return eRet; |
| 121360 | } |
| 121361 | |
| 121362 | /* |
| 121363 | ** This function is called when an UPDATE or DELETE operation is being |
| 121364 | ** compiled on table pTab, which is the parent table of foreign-key pFKey. |
| @@ -122796,15 +122815,10 @@ | |
| 122796 | sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols); |
| 122797 | sqlite3VdbeJumpHere(v, addr1); |
| 122798 | sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v); |
| 122799 | } |
| 122800 | |
| 122801 | /* Cannot have triggers on a virtual table. If it were possible, |
| 122802 | ** this block would have to account for hidden column. |
| 122803 | */ |
| 122804 | assert( !IsVirtual(pTab) ); |
| 122805 | |
| 122806 | /* Copy the new data already generated. */ |
| 122807 | assert( pTab->nNVCol>0 ); |
| 122808 | sqlite3VdbeAddOp3(v, OP_Copy, regRowid+1, regCols+1, pTab->nNVCol-1); |
| 122809 | |
| 122810 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| @@ -137898,10 +137912,12 @@ | |
| 137898 | && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 137899 | ){ |
| 137900 | pTrig->pNext = pList; |
| 137901 | pList = pTrig; |
| 137902 | }else if( pTrig->op==TK_RETURNING ){ |
| 137903 | pTrig->table = pTab->zName; |
| 137904 | pTrig->pTabSchema = pTab->pSchema; |
| 137905 | pTrig->pNext = pList; |
| 137906 | pList = pTrig; |
| 137907 | } |
| @@ -138587,20 +138603,25 @@ | |
| 138587 | }else if( p->op==TK_RETURNING ){ |
| 138588 | /* The first time a RETURNING trigger is seen, the "op" value tells |
| 138589 | ** us what time of trigger it should be. */ |
| 138590 | assert( sqlite3IsToplevel(pParse) ); |
| 138591 | p->op = op; |
| 138592 | mask |= TRIGGER_AFTER; |
| 138593 | if( IsVirtual(pTab) && op!=TK_INSERT ){ |
| 138594 | sqlite3ErrorMsg(pParse, |
| 138595 | "%s RETURNING is not available on virtual tables", |
| 138596 | op==TK_DELETE ? "DELETE" : "UPDATE"); |
| 138597 | } |
| 138598 | }else if( p->bReturning && p->op==TK_INSERT && op==TK_UPDATE |
| 138599 | && sqlite3IsToplevel(pParse) ){ |
| 138600 | /* Also fire a RETURNING trigger for an UPSERT */ |
| 138601 | mask |= TRIGGER_AFTER; |
| 138602 | } |
| 138603 | p = p->pNext; |
| 138604 | }while( p ); |
| 138605 | } |
| 138606 | exit_triggers_exist: |
| @@ -138658,10 +138679,11 @@ | |
| 138658 | Table *pTab /* The table being updated */ |
| 138659 | ){ |
| 138660 | ExprList *pNew = 0; |
| 138661 | sqlite3 *db = pParse->db; |
| 138662 | int i; |
| 138663 | for(i=0; i<pList->nExpr; i++){ |
| 138664 | Expr *pOldExpr = pList->a[i].pExpr; |
| 138665 | if( ALWAYS(pOldExpr!=0) && pOldExpr->op==TK_ASTERISK ){ |
| 138666 | int jj; |
| 138667 | for(jj=0; jj<pTab->nCol; jj++){ |
| @@ -138681,13 +138703,75 @@ | |
| 138681 | struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; |
| 138682 | pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName); |
| 138683 | pItem->eEName = pList->a[i].eEName; |
| 138684 | } |
| 138685 | } |
| 138686 | } |
| 138687 | return pNew; |
| 138688 | } |
| 138689 | |
| 138690 | /* |
| 138691 | ** Generate VDBE code for the statements inside the body of a single |
| 138692 | ** trigger. |
| 138693 | */ |
| @@ -138756,38 +138840,18 @@ | |
| 138756 | sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0 |
| 138757 | ); |
| 138758 | sqlite3VdbeAddOp0(v, OP_ResetCount); |
| 138759 | break; |
| 138760 | } |
| 138761 | case TK_SELECT: { |
| 138762 | SelectDest sDest; |
| 138763 | Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0); |
| 138764 | sqlite3SelectDestInit(&sDest, SRT_Discard, 0); |
| 138765 | sqlite3Select(pParse, pSelect, &sDest); |
| 138766 | sqlite3SelectDelete(db, pSelect); |
| 138767 | break; |
| 138768 | } |
| 138769 | default: assert( pStep->op==TK_RETURNING ); { |
| 138770 | Select *pSelect = pStep->pSelect; |
| 138771 | ExprList *pList = pSelect->pEList; |
| 138772 | SelectDest sDest; |
| 138773 | Select *pNew; |
| 138774 | pSelect->pEList = |
| 138775 | sqlite3ExpandReturning(pParse, pList, pParse->pTriggerTab); |
| 138776 | sqlite3SelectDestInit(&sDest, SRT_Output, 0); |
| 138777 | pNew = sqlite3SelectDup(db, pSelect, 0); |
| 138778 | if( pNew ){ |
| 138779 | sqlite3Select(pParse, pNew, &sDest); |
| 138780 | if( pNew->selFlags & (SF_Aggregate|SF_HasAgg|SF_WinRewrite) ){ |
| 138781 | sqlite3ErrorMsg(pParse, "aggregates not allowed in RETURNING"); |
| 138782 | } |
| 138783 | sqlite3SelectDelete(db, pNew); |
| 138784 | } |
| 138785 | sqlite3ExprListDelete(db, pSelect->pEList); |
| 138786 | pStep->pSelect->pEList = pList; |
| 138787 | break; |
| 138788 | } |
| 138789 | } |
| 138790 | } |
| 138791 | |
| 138792 | return 0; |
| 138793 | } |
| @@ -138874,11 +138938,10 @@ | |
| 138874 | pSubParse->db = db; |
| 138875 | pSubParse->pTriggerTab = pTab; |
| 138876 | pSubParse->pToplevel = pTop; |
| 138877 | pSubParse->zAuthContext = pTrigger->zName; |
| 138878 | pSubParse->eTriggerOp = pTrigger->op; |
| 138879 | pSubParse->bReturning = pTrigger->bReturning; |
| 138880 | pSubParse->nQueryLoop = pParse->nQueryLoop; |
| 138881 | pSubParse->disableVtab = pParse->disableVtab; |
| 138882 | |
| 138883 | v = sqlite3GetVdbe(pSubParse); |
| 138884 | if( v ){ |
| @@ -138924,13 +138987,10 @@ | |
| 138924 | |
| 138925 | transferParseError(pParse, pSubParse); |
| 138926 | if( db->mallocFailed==0 && pParse->nErr==0 ){ |
| 138927 | pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg); |
| 138928 | } |
| 138929 | if( pTrigger->bReturning ){ |
| 138930 | sqlite3VdbeColumnInfoXfer(sqlite3ParseToplevel(pParse)->pVdbe, v); |
| 138931 | } |
| 138932 | pProgram->nMem = pSubParse->nMem; |
| 138933 | pProgram->nCsr = pSubParse->nTab; |
| 138934 | pProgram->token = (void *)pTrigger; |
| 138935 | pPrg->aColmask[0] = pSubParse->oldmask; |
| 138936 | pPrg->aColmask[1] = pSubParse->newmask; |
| @@ -139036,11 +139096,11 @@ | |
| 139036 | ** reg+0 OLD.rowid |
| 139037 | ** reg+1 OLD.* value of left-most column of pTab |
| 139038 | ** ... ... |
| 139039 | ** reg+N OLD.* value of right-most column of pTab |
| 139040 | ** reg+N+1 NEW.rowid |
| 139041 | ** reg+N+2 OLD.* value of left-most column of pTab |
| 139042 | ** ... ... |
| 139043 | ** reg+N+N+1 NEW.* value of right-most column of pTab |
| 139044 | ** |
| 139045 | ** For ON DELETE triggers, the registers containing the NEW.* values will |
| 139046 | ** never be accessed by the trigger program, so they are not allocated or |
| @@ -139089,16 +139149,16 @@ | |
| 139089 | ** doing the UPDATE part of an UPSERT. |
| 139090 | */ |
| 139091 | if( (p->op==op || (p->bReturning && p->op==TK_INSERT && op==TK_UPDATE)) |
| 139092 | && p->tr_tm==tr_tm |
| 139093 | && checkColumnOverlap(p->pColumns, pChanges) |
| 139094 | && (sqlite3IsToplevel(pParse) || !p->bReturning) |
| 139095 | ){ |
| 139096 | u8 origOp = p->op; |
| 139097 | p->op = op; |
| 139098 | sqlite3CodeRowTriggerDirect(pParse, p, pTab, reg, orconf, ignoreJump); |
| 139099 | p->op = origOp; |
| 139100 | } |
| 139101 | } |
| 139102 | } |
| 139103 | |
| 139104 | /* |
| @@ -139139,17 +139199,22 @@ | |
| 139139 | u32 mask = 0; |
| 139140 | Trigger *p; |
| 139141 | |
| 139142 | assert( isNew==1 || isNew==0 ); |
| 139143 | for(p=pTrigger; p; p=p->pNext){ |
| 139144 | if( p->op==op && (tr_tm&p->tr_tm) |
| 139145 | && checkColumnOverlap(p->pColumns,pChanges) |
| 139146 | ){ |
| 139147 | TriggerPrg *pPrg; |
| 139148 | pPrg = getRowTrigger(pParse, p, pTab, orconf); |
| 139149 | if( pPrg ){ |
| 139150 | mask |= pPrg->aColmask[isNew]; |
| 139151 | } |
| 139152 | } |
| 139153 | } |
| 139154 | |
| 139155 | return mask; |
| @@ -142036,11 +142101,11 @@ | |
| 142036 | ){ |
| 142037 | if( !pTab->aCol ){ |
| 142038 | Table *pNew = sParse.pNewTable; |
| 142039 | Index *pIdx; |
| 142040 | pTab->aCol = pNew->aCol; |
| 142041 | pTab->nCol = pNew->nCol; |
| 142042 | pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid); |
| 142043 | pNew->nCol = 0; |
| 142044 | pNew->aCol = 0; |
| 142045 | assert( pTab->pIndex==0 ); |
| 142046 | assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 ); |
| @@ -228415,11 +228480,11 @@ | |
| 228415 | int nArg, /* Number of args */ |
| 228416 | sqlite3_value **apUnused /* Function arguments */ |
| 228417 | ){ |
| 228418 | assert( nArg==0 ); |
| 228419 | UNUSED_PARAM2(nArg, apUnused); |
| 228420 | sqlite3_result_text(pCtx, "fts5: 2021-02-03 13:20:12 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644d0902", -1, SQLITE_TRANSIENT); |
| 228421 | } |
| 228422 | |
| 228423 | /* |
| 228424 | ** Return true if zName is the extension on one of the shadow tables used |
| 228425 | ** by this module. |
| @@ -233341,12 +233406,12 @@ | |
| 233341 | } |
| 233342 | #endif /* SQLITE_CORE */ |
| 233343 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 233344 | |
| 233345 | /************** End of stmt.c ************************************************/ |
| 233346 | #if __LINE__!=233346 |
| 233347 | #undef SQLITE_SOURCE_ID |
| 233348 | #define SQLITE_SOURCE_ID "2021-02-03 13:20:12 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644dalt2" |
| 233349 | #endif |
| 233350 | /* Return the source-id for this library */ |
| 233351 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 233352 | /************************** End of sqlite3.c ******************************/ |
| 233353 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1186,11 +1186,11 @@ | |
| 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | */ |
| 1189 | #define SQLITE_VERSION "3.35.0" |
| 1190 | #define SQLITE_VERSION_NUMBER 3035000 |
| 1191 | #define SQLITE_SOURCE_ID "2021-02-05 17:34:47 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4c30c" |
| 1192 | |
| 1193 | /* |
| 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | ** |
| @@ -16002,11 +16002,10 @@ | |
| 16002 | #endif |
| 16003 | SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*); |
| 16004 | SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*); |
| 16005 | SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*); |
| 16006 | SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int); |
| 16007 | SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*)); |
| 16008 | SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*); |
| 16009 | SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*); |
| 16010 | SQLITE_PRIVATE u8 sqlite3VdbePrepareFlags(Vdbe*); |
| 16011 | SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, u8); |
| @@ -18223,11 +18222,11 @@ | |
| 18222 | #define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */ |
| 18223 | #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 18224 | #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ |
| 18225 | #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ |
| 18226 | #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ |
| 18227 | /* 0x400000 // Available */ |
| 18228 | #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */ |
| 18229 | #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */ |
| 18230 | #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ |
| 18231 | #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ |
| 18232 | #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ |
| @@ -18498,10 +18497,11 @@ | |
| 18497 | SrcList *pSrcList; /* One or more tables used to resolve names */ |
| 18498 | union { |
| 18499 | ExprList *pEList; /* Optional list of result-set columns */ |
| 18500 | AggInfo *pAggInfo; /* Information about aggregates at this level */ |
| 18501 | Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */ |
| 18502 | int iBaseReg; /* For TK_REGISTER when parsing RETURNING */ |
| 18503 | } uNC; |
| 18504 | NameContext *pNext; /* Next outer name context. NULL for outermost */ |
| 18505 | int nRef; /* Number of names resolved by this context */ |
| 18506 | int nErr; /* Number of errors encountered while resolving names */ |
| 18507 | int ncFlags; /* Zero or more NC_* flags defined below */ |
| @@ -18526,10 +18526,11 @@ | |
| 18526 | #define NC_SelfRef 0x0002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */ |
| 18527 | #define NC_VarSelect 0x00040 /* A correlated subquery has been seen */ |
| 18528 | #define NC_UEList 0x00080 /* True if uNC.pEList is used */ |
| 18529 | #define NC_UAggInfo 0x00100 /* True if uNC.pAggInfo is used */ |
| 18530 | #define NC_UUpsert 0x00200 /* True if uNC.pUpsert is used */ |
| 18531 | #define NC_UBaseReg 0x00400 /* True if uNC.iBaseReg is used */ |
| 18532 | #define NC_MinMaxAgg 0x01000 /* min/max aggregates seen. See note above */ |
| 18533 | #define NC_Complex 0x02000 /* True if a function or subquery seen */ |
| 18534 | #define NC_AllowWin 0x04000 /* Window functions are allowed here */ |
| 18535 | #define NC_HasWin 0x08000 /* One or more window functions seen */ |
| 18536 | #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */ |
| @@ -18886,11 +18887,14 @@ | |
| 18887 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| 18888 | Parse *pToplevel; /* Parse structure for main program (or NULL) */ |
| 18889 | Table *pTriggerTab; /* Table triggers are being coded for */ |
| 18890 | Parse *pParentParse; /* Parent parser if this parser is nested */ |
| 18891 | AggInfo *pAggList; /* List of all AggInfo objects */ |
| 18892 | union { |
| 18893 | int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */ |
| 18894 | Returning *pReturning; /* The RETURNING clause */ |
| 18895 | } u1; |
| 18896 | u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ |
| 18897 | u32 oldmask; /* Mask of old.* columns referenced */ |
| 18898 | u32 newmask; /* Mask of new.* columns referenced */ |
| 18899 | u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ |
| 18900 | u8 bReturning; /* Coding a RETURNING trigger */ |
| @@ -19108,11 +19112,11 @@ | |
| 19112 | Trigger *pTrig; /* The trigger that this step is a part of */ |
| 19113 | Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ |
| 19114 | char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ |
| 19115 | SrcList *pFrom; /* FROM clause for UPDATE statement (if any) */ |
| 19116 | Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ |
| 19117 | ExprList *pExprList; /* SET clause for UPDATE, or RETURNING clause */ |
| 19118 | IdList *pIdList; /* Column names for INSERT */ |
| 19119 | Upsert *pUpsert; /* Upsert clauses on an INSERT */ |
| 19120 | char *zSpan; /* Original SQL text of this command */ |
| 19121 | TriggerStep *pNext; /* Next in the link-list */ |
| 19122 | TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
| @@ -19124,12 +19128,13 @@ | |
| 19128 | struct Returning { |
| 19129 | Parse *pParse; /* The parse that includes the RETURNING clause */ |
| 19130 | ExprList *pReturnEL; /* List of expressions to return */ |
| 19131 | Trigger retTrig; /* The transient trigger that implements RETURNING */ |
| 19132 | TriggerStep retTStep; /* The trigger step */ |
| 19133 | int iRetCur; /* Transient table holding RETURNING results */ |
| 19134 | int nRetCol; /* Number of in pReturnEL after expansion */ |
| 19135 | int iRetReg; /* Register array for holding a row of RETURNING */ |
| 19136 | }; |
| 19137 | |
| 19138 | /* |
| 19139 | ** An objected used to accumulate the text of a string where we |
| 19140 | ** do not necessarily know how big the string will be in the end. |
| @@ -21275,11 +21280,11 @@ | |
| 21280 | struct Vdbe { |
| 21281 | sqlite3 *db; /* The database connection that owns this statement */ |
| 21282 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 21283 | Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 21284 | ynVar nVar; /* Number of entries in aVar[] */ |
| 21285 | u32 iVdbeMagic; /* Magic number defining state of the SQL statement */ |
| 21286 | int nMem; /* Number of memory locations currently allocated */ |
| 21287 | int nCursor; /* Number of slots in apCsr[] */ |
| 21288 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 21289 | int pc; /* The program counter */ |
| 21290 | int rc; /* Value to return */ |
| @@ -72861,11 +72866,11 @@ | |
| 72866 | */ |
| 72867 | for(i=0; i<nNew; i++){ |
| 72868 | aPgOrder[i] = aPgno[i] = apNew[i]->pgno; |
| 72869 | aPgFlags[i] = apNew[i]->pDbPage->flags; |
| 72870 | for(j=0; j<i; j++){ |
| 72871 | if( NEVER(aPgno[j]==aPgno[i]) ){ |
| 72872 | /* This branch is taken if the set of sibling pages somehow contains |
| 72873 | ** duplicate entries. This can happen if the database is corrupt. |
| 72874 | ** It would be simpler to detect this as part of the loop below, but |
| 72875 | ** we do the detection here in order to avoid populating the pager |
| 72876 | ** cache with two separate objects associated with the same |
| @@ -78292,11 +78297,11 @@ | |
| 78297 | db->pVdbe->pPrev = p; |
| 78298 | } |
| 78299 | p->pNext = db->pVdbe; |
| 78300 | p->pPrev = 0; |
| 78301 | db->pVdbe = p; |
| 78302 | p->iVdbeMagic = VDBE_MAGIC_INIT; |
| 78303 | p->pParse = pParse; |
| 78304 | pParse->pVdbe = p; |
| 78305 | assert( pParse->aLabel==0 ); |
| 78306 | assert( pParse->nLabel==0 ); |
| 78307 | assert( p->nOpAlloc==0 ); |
| @@ -78493,11 +78498,11 @@ | |
| 78498 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ |
| 78499 | int i; |
| 78500 | VdbeOp *pOp; |
| 78501 | |
| 78502 | i = p->nOp; |
| 78503 | assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 78504 | assert( op>=0 && op<0xff ); |
| 78505 | if( p->nOpAlloc<=i ){ |
| 78506 | return growOp3(p, op, p1, p2, p3); |
| 78507 | } |
| 78508 | p->nOp++; |
| @@ -78822,11 +78827,11 @@ | |
| 78827 | } |
| 78828 | } |
| 78829 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ |
| 78830 | Parse *p = v->pParse; |
| 78831 | int j = ADDR(x); |
| 78832 | assert( v->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 78833 | assert( j<-p->nLabel ); |
| 78834 | assert( j>=0 ); |
| 78835 | #ifdef SQLITE_DEBUG |
| 78836 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 78837 | printf("RESOLVE LABEL %d to %d\n", x, v->nOp); |
| @@ -79147,11 +79152,11 @@ | |
| 79152 | |
| 79153 | /* |
| 79154 | ** Return the address of the next instruction to be inserted. |
| 79155 | */ |
| 79156 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ |
| 79157 | assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 79158 | return p->nOp; |
| 79159 | } |
| 79160 | |
| 79161 | /* |
| 79162 | ** Verify that at least N opcode slots are available in p without |
| @@ -79232,11 +79237,11 @@ | |
| 79237 | int iLineno /* Source-file line number of first opcode */ |
| 79238 | ){ |
| 79239 | int i; |
| 79240 | VdbeOp *pOut, *pFirst; |
| 79241 | assert( nOp>0 ); |
| 79242 | assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 79243 | if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){ |
| 79244 | return 0; |
| 79245 | } |
| 79246 | pFirst = pOut = &p->aOp[p->nOp]; |
| 79247 | for(i=0; i<nOp; i++, aOp++, pOut++){ |
| @@ -79556,11 +79561,11 @@ | |
| 79561 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){ |
| 79562 | Op *pOp; |
| 79563 | sqlite3 *db; |
| 79564 | assert( p!=0 ); |
| 79565 | db = p->db; |
| 79566 | assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 79567 | assert( p->aOp!=0 || db->mallocFailed ); |
| 79568 | if( db->mallocFailed ){ |
| 79569 | if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4); |
| 79570 | return; |
| 79571 | } |
| @@ -79685,11 +79690,11 @@ | |
| 79690 | */ |
| 79691 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ |
| 79692 | /* C89 specifies that the constant "dummy" will be initialized to all |
| 79693 | ** zeros, which is correct. MSVC generates a warning, nevertheless. */ |
| 79694 | static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */ |
| 79695 | assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 79696 | if( addr<0 ){ |
| 79697 | addr = p->nOp - 1; |
| 79698 | } |
| 79699 | assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed ); |
| 79700 | if( p->db->mallocFailed ){ |
| @@ -80370,11 +80375,11 @@ | |
| 80375 | int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0); |
| 80376 | Op *aOp; /* Array of opcodes */ |
| 80377 | Op *pOp; /* Current opcode */ |
| 80378 | |
| 80379 | assert( p->explain ); |
| 80380 | assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); |
| 80381 | assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM ); |
| 80382 | |
| 80383 | /* Even though this opcode does not use dynamic strings for |
| 80384 | ** the result, result columns may become dynamic if the user calls |
| 80385 | ** sqlite3_column_text16(), causing a translation to UTF-16 encoding. |
| @@ -80550,18 +80555,18 @@ | |
| 80555 | SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){ |
| 80556 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 80557 | int i; |
| 80558 | #endif |
| 80559 | assert( p!=0 ); |
| 80560 | assert( p->iVdbeMagic==VDBE_MAGIC_INIT || p->iVdbeMagic==VDBE_MAGIC_RESET ); |
| 80561 | |
| 80562 | /* There should be at least one opcode. |
| 80563 | */ |
| 80564 | assert( p->nOp>0 ); |
| 80565 | |
| 80566 | /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */ |
| 80567 | p->iVdbeMagic = VDBE_MAGIC_RUN; |
| 80568 | |
| 80569 | #ifdef SQLITE_DEBUG |
| 80570 | for(i=0; i<p->nMem; i++){ |
| 80571 | assert( p->aMem[i].db==p->db ); |
| 80572 | } |
| @@ -80613,11 +80618,11 @@ | |
| 80618 | struct ReusableSpace x; /* Reusable bulk memory */ |
| 80619 | |
| 80620 | assert( p!=0 ); |
| 80621 | assert( p->nOp>0 ); |
| 80622 | assert( pParse!=0 ); |
| 80623 | assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 80624 | assert( pParse==p->pParse ); |
| 80625 | p->pVList = pParse->pVList; |
| 80626 | pParse->pVList = 0; |
| 80627 | db = p->db; |
| 80628 | assert( db->mallocFailed==0 ); |
| @@ -80852,27 +80857,10 @@ | |
| 80857 | p->aColName = (Mem*)sqlite3DbMallocRawNN(db, sizeof(Mem)*n ); |
| 80858 | if( p->aColName==0 ) return; |
| 80859 | initMemArray(p->aColName, n, db, MEM_Null); |
| 80860 | } |
| 80861 | |
| 80862 | /* |
| 80863 | ** Set the name of the idx'th column to be returned by the SQL statement. |
| 80864 | ** zName must be a pointer to a nul terminated string. |
| 80865 | ** |
| 80866 | ** This call must be made after a call to sqlite3VdbeSetNumCols(). |
| @@ -81315,11 +81303,11 @@ | |
| 81303 | ** Then the internal cache might have been left in an inconsistent |
| 81304 | ** state. We need to rollback the statement transaction, if there is |
| 81305 | ** one, or the complete transaction if there is no statement transaction. |
| 81306 | */ |
| 81307 | |
| 81308 | if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){ |
| 81309 | return SQLITE_OK; |
| 81310 | } |
| 81311 | if( db->mallocFailed ){ |
| 81312 | p->rc = SQLITE_NOMEM_BKPT; |
| 81313 | } |
| @@ -81473,11 +81461,11 @@ | |
| 81461 | if( p->bIsReader ) db->nVdbeRead--; |
| 81462 | assert( db->nVdbeActive>=db->nVdbeRead ); |
| 81463 | assert( db->nVdbeRead>=db->nVdbeWrite ); |
| 81464 | assert( db->nVdbeWrite>=0 ); |
| 81465 | } |
| 81466 | p->iVdbeMagic = VDBE_MAGIC_HALT; |
| 81467 | checkActiveVdbeCnt(db); |
| 81468 | if( db->mallocFailed ){ |
| 81469 | p->rc = SQLITE_NOMEM_BKPT; |
| 81470 | } |
| 81471 | |
| @@ -81646,21 +81634,21 @@ | |
| 81634 | } |
| 81635 | fclose(out); |
| 81636 | } |
| 81637 | } |
| 81638 | #endif |
| 81639 | p->iVdbeMagic = VDBE_MAGIC_RESET; |
| 81640 | return p->rc & db->errMask; |
| 81641 | } |
| 81642 | |
| 81643 | /* |
| 81644 | ** Clean up and delete a VDBE after execution. Return an integer which is |
| 81645 | ** the result code. Write any error message text into *pzErrMsg. |
| 81646 | */ |
| 81647 | SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){ |
| 81648 | int rc = SQLITE_OK; |
| 81649 | if( p->iVdbeMagic==VDBE_MAGIC_RUN || p->iVdbeMagic==VDBE_MAGIC_HALT ){ |
| 81650 | rc = sqlite3VdbeReset(p); |
| 81651 | assert( (rc & p->db->errMask)==rc ); |
| 81652 | } |
| 81653 | sqlite3VdbeDelete(p); |
| 81654 | return rc; |
| @@ -81717,11 +81705,11 @@ | |
| 81705 | for(pSub=p->pProgram; pSub; pSub=pNext){ |
| 81706 | pNext = pSub->pNext; |
| 81707 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 81708 | sqlite3DbFree(db, pSub); |
| 81709 | } |
| 81710 | if( p->iVdbeMagic!=VDBE_MAGIC_INIT ){ |
| 81711 | releaseMemArray(p->aVar, p->nVar); |
| 81712 | sqlite3DbFree(db, p->pVList); |
| 81713 | sqlite3DbFree(db, p->pFree); |
| 81714 | } |
| 81715 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| @@ -81765,11 +81753,11 @@ | |
| 81753 | db->pVdbe = p->pNext; |
| 81754 | } |
| 81755 | if( p->pNext ){ |
| 81756 | p->pNext->pPrev = p->pPrev; |
| 81757 | } |
| 81758 | p->iVdbeMagic = VDBE_MAGIC_DEAD; |
| 81759 | p->db = 0; |
| 81760 | sqlite3DbFreeNN(db, p); |
| 81761 | } |
| 81762 | |
| 81763 | /* |
| @@ -84144,11 +84132,11 @@ | |
| 84132 | static int sqlite3Step(Vdbe *p){ |
| 84133 | sqlite3 *db; |
| 84134 | int rc; |
| 84135 | |
| 84136 | assert(p); |
| 84137 | if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){ |
| 84138 | /* We used to require that sqlite3_reset() be called before retrying |
| 84139 | ** sqlite3_step() after any error or after SQLITE_DONE. But beginning |
| 84140 | ** with version 3.7.0, we changed this so that sqlite3_reset() would |
| 84141 | ** be called automatically instead of throwing the SQLITE_MISUSE error. |
| 84142 | ** This "automatic-reset" change is not technically an incompatibility, |
| @@ -84860,11 +84848,11 @@ | |
| 84848 | Mem *pVar; |
| 84849 | if( vdbeSafetyNotNull(p) ){ |
| 84850 | return SQLITE_MISUSE_BKPT; |
| 84851 | } |
| 84852 | sqlite3_mutex_enter(p->db->mutex); |
| 84853 | if( p->iVdbeMagic!=VDBE_MAGIC_RUN || p->pc>=0 ){ |
| 84854 | sqlite3Error(p->db, SQLITE_MISUSE); |
| 84855 | sqlite3_mutex_leave(p->db->mutex); |
| 84856 | sqlite3_log(SQLITE_MISUSE, |
| 84857 | "bind on a busy prepared statement: [%s]", p->zSql); |
| 84858 | return SQLITE_MISUSE_BKPT; |
| @@ -85214,11 +85202,11 @@ | |
| 85202 | /* |
| 85203 | ** Return true if the prepared statement is in need of being reset. |
| 85204 | */ |
| 85205 | SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ |
| 85206 | Vdbe *v = (Vdbe*)pStmt; |
| 85207 | return v!=0 && v->iVdbeMagic==VDBE_MAGIC_RUN && v->pc>=0; |
| 85208 | } |
| 85209 | |
| 85210 | /* |
| 85211 | ** Return a pointer to the next prepared statement after pStmt associated |
| 85212 | ** with database connection pDb. If pStmt is NULL, return the first |
| @@ -86552,11 +86540,11 @@ | |
| 86540 | #ifdef VDBE_PROFILE |
| 86541 | u64 start; /* CPU clock count at start of opcode */ |
| 86542 | #endif |
| 86543 | /*** INSERT STACK UNION HERE ***/ |
| 86544 | |
| 86545 | assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 86546 | sqlite3VdbeEnter(p); |
| 86547 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 86548 | if( db->xProgress ){ |
| 86549 | u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; |
| 86550 | assert( 0 < db->nProgressOps ); |
| @@ -98629,11 +98617,10 @@ | |
| 98617 | assert( db->mallocFailed ); |
| 98618 | } |
| 98619 | } |
| 98620 | sqlite3DbFree(db, pDup); |
| 98621 | } |
| 98622 | } |
| 98623 | |
| 98624 | |
| 98625 | /* |
| 98626 | ** Return TRUE if the name zCol occurs anywhere in the USING clause. |
| @@ -98888,11 +98875,11 @@ | |
| 98875 | #if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) |
| 98876 | /* If we have not already resolved the name, then maybe |
| 98877 | ** it is a new.* or old.* trigger argument reference. Or |
| 98878 | ** maybe it is an excluded.* from an upsert. |
| 98879 | */ |
| 98880 | if( cntTab==0 && zDb==0 ){ |
| 98881 | pTab = 0; |
| 98882 | #ifndef SQLITE_OMIT_TRIGGER |
| 98883 | if( pParse->pTriggerTab!=0 ){ |
| 98884 | int op = pParse->eTriggerOp; |
| 98885 | assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT ); |
| @@ -98946,31 +98933,35 @@ | |
| 98933 | eNewExprOp = TK_COLUMN; |
| 98934 | }else{ |
| 98935 | pExpr->iTable = pNC->uNC.pUpsert->regData + |
| 98936 | sqlite3TableColumnToStorage(pTab, iCol); |
| 98937 | eNewExprOp = TK_REGISTER; |
| 98938 | } |
| 98939 | }else |
| 98940 | #endif /* SQLITE_OMIT_UPSERT */ |
| 98941 | { |
| 98942 | pExpr->y.pTab = pTab; |
| 98943 | if( iCol<0 ) pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 98944 | if( pParse->bReturning ){ |
| 98945 | eNewExprOp = TK_REGISTER; |
| 98946 | pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable |
| 98947 | + iCol + 1; |
| 98948 | }else{ |
| 98949 | pExpr->iColumn = (i16)iCol; |
| 98950 | eNewExprOp = TK_TRIGGER; |
| 98951 | #ifndef SQLITE_OMIT_TRIGGER |
| 98952 | if( pExpr->iTable==0 ){ |
| 98953 | testcase( iCol==31 ); |
| 98954 | testcase( iCol==32 ); |
| 98955 | pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); |
| 98956 | }else{ |
| 98957 | testcase( iCol==31 ); |
| 98958 | testcase( iCol==32 ); |
| 98959 | pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); |
| 98960 | } |
| 98961 | #endif /* SQLITE_OMIT_TRIGGER */ |
| 98962 | } |
| 98963 | } |
| 98964 | } |
| 98965 | } |
| 98966 | } |
| 98967 | #endif /* !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) */ |
| @@ -99147,11 +99138,13 @@ | |
| 99138 | pExpr->op = eNewExprOp; |
| 99139 | ExprSetProperty(pExpr, EP_Leaf); |
| 99140 | lookupname_end: |
| 99141 | if( cnt==1 ){ |
| 99142 | assert( pNC!=0 ); |
| 99143 | if( pParse->db->xAuth |
| 99144 | && (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER) |
| 99145 | ){ |
| 99146 | sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); |
| 99147 | } |
| 99148 | /* Increment the nRef value on all name contexts from TopNC up to |
| 99149 | ** the point where the name matched. */ |
| 99150 | for(;;){ |
| @@ -111033,20 +111026,19 @@ | |
| 111026 | Parse *pParse, /* The parser context */ |
| 111027 | Expr *pExpr, /* The expression to check authorization on */ |
| 111028 | Schema *pSchema, /* The schema of the expression */ |
| 111029 | SrcList *pTabList /* All table that pExpr might refer to */ |
| 111030 | ){ |
| 111031 | Table *pTab = 0; /* The table being read */ |
| 111032 | const char *zCol; /* Name of the column of the table */ |
| 111033 | int iSrc; /* Index in pTabList->a[] of table being read */ |
| 111034 | int iDb; /* The index of the database the expression refers to */ |
| 111035 | int iCol; /* Index of column in table */ |
| 111036 | |
| 111037 | assert( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ); |
| 111038 | assert( !IN_RENAME_OBJECT ); |
| 111039 | assert( pParse->db->xAuth!=0 ); |
| 111040 | iDb = sqlite3SchemaToIndex(pParse->db, pSchema); |
| 111041 | if( iDb<0 ){ |
| 111042 | /* An attempt to read a column out of a subquery or other |
| 111043 | ** temporary table. */ |
| 111044 | return; |
| @@ -111073,11 +111065,11 @@ | |
| 111065 | assert( pTab->iPKey<pTab->nCol ); |
| 111066 | zCol = pTab->aCol[pTab->iPKey].zName; |
| 111067 | }else{ |
| 111068 | zCol = "ROWID"; |
| 111069 | } |
| 111070 | assert( iDb>=0 && iDb<pParse->db->nDb ); |
| 111071 | if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){ |
| 111072 | pExpr->op = TK_NULL; |
| 111073 | } |
| 111074 | } |
| 111075 | |
| @@ -111305,18 +111297,38 @@ | |
| 111297 | } |
| 111298 | |
| 111299 | /* Begin by generating some termination code at the end of the |
| 111300 | ** vdbe program |
| 111301 | */ |
| 111302 | v = pParse->pVdbe; |
| 111303 | if( v==0 ){ |
| 111304 | if( db->init.busy ){ |
| 111305 | pParse->rc = SQLITE_DONE; |
| 111306 | return; |
| 111307 | } |
| 111308 | v = sqlite3GetVdbe(pParse); |
| 111309 | if( v==0 ) pParse->rc = SQLITE_ERROR; |
| 111310 | } |
| 111311 | assert( !pParse->isMultiWrite |
| 111312 | || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort)); |
| 111313 | if( v ){ |
| 111314 | if( pParse->bReturning ){ |
| 111315 | Returning *pReturning = pParse->u1.pReturning; |
| 111316 | int addrRewind; |
| 111317 | int i; |
| 111318 | int reg; |
| 111319 | |
| 111320 | addrRewind = |
| 111321 | sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); |
| 111322 | reg = pReturning->iRetReg; |
| 111323 | for(i=0; i<pReturning->nRetCol; i++){ |
| 111324 | sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i); |
| 111325 | } |
| 111326 | sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i); |
| 111327 | sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1); |
| 111328 | sqlite3VdbeJumpHere(v, addrRewind); |
| 111329 | } |
| 111330 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 111331 | |
| 111332 | #if SQLITE_USER_AUTHENTICATION |
| 111333 | if( pParse->nTableLock>0 && db->init.busy==0 ){ |
| 111334 | sqlite3UserAuthInit(db); |
| @@ -111389,16 +111401,20 @@ | |
| 111401 | if( iReg>0 ){ |
| 111402 | sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg); |
| 111403 | } |
| 111404 | } |
| 111405 | } |
| 111406 | |
| 111407 | if( pParse->bReturning ){ |
| 111408 | Returning *pRet = pParse->u1.pReturning; |
| 111409 | sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); |
| 111410 | } |
| 111411 | |
| 111412 | /* Finally, jump back to the beginning of the executable code. */ |
| 111413 | sqlite3VdbeGoto(v, 1); |
| 111414 | } |
| 111415 | } |
| 111416 | |
| 111417 | /* Get the VDBE program ready for execution |
| 111418 | */ |
| 111419 | if( v && pParse->nErr==0 && !db->mallocFailed ){ |
| 111420 | /* A minimum of one cursor is required if autoincrement is used |
| @@ -112372,11 +112388,12 @@ | |
| 112388 | if( isView || isVirtual ){ |
| 112389 | sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2); |
| 112390 | }else |
| 112391 | #endif |
| 112392 | { |
| 112393 | assert( !pParse->bReturning ); |
| 112394 | pParse->u1.addrCrTab = |
| 112395 | sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY); |
| 112396 | } |
| 112397 | sqlite3OpenSchemaTable(pParse, iDb); |
| 112398 | sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1); |
| 112399 | sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC); |
| @@ -112450,10 +112467,11 @@ | |
| 112467 | pRet = sqlite3DbMallocZero(db, sizeof(*pRet)); |
| 112468 | if( pRet==0 ){ |
| 112469 | sqlite3ExprListDelete(db, pList); |
| 112470 | return; |
| 112471 | } |
| 112472 | pParse->u1.pReturning = pRet; |
| 112473 | pRet->pParse = pParse; |
| 112474 | pRet->pReturnEL = pList; |
| 112475 | sqlite3ParserAddCleanup(pParse, |
| 112476 | (void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet); |
| 112477 | if( db->mallocFailed ) return; |
| @@ -112463,14 +112481,11 @@ | |
| 112481 | pRet->retTrig.bReturning = 1; |
| 112482 | pRet->retTrig.pSchema = db->aDb[1].pSchema; |
| 112483 | pRet->retTrig.step_list = &pRet->retTStep; |
| 112484 | pRet->retTStep.op = TK_RETURNING; |
| 112485 | pRet->retTStep.pTrig = &pRet->retTrig; |
| 112486 | pRet->retTStep.pExprList = pList; |
| 112487 | pHash = &(db->aDb[1].pSchema->trigHash); |
| 112488 | assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0 ); |
| 112489 | if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig) |
| 112490 | ==&pRet->retTrig ){ |
| 112491 | sqlite3OomFault(db); |
| @@ -113306,13 +113321,14 @@ | |
| 113321 | } |
| 113322 | |
| 113323 | /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY |
| 113324 | ** into BTREE_BLOBKEY. |
| 113325 | */ |
| 113326 | assert( !pParse->bReturning ); |
| 113327 | if( pParse->u1.addrCrTab ){ |
| 113328 | assert( v ); |
| 113329 | sqlite3VdbeChangeP3(v, pParse->u1.addrCrTab, BTREE_BLOBKEY); |
| 113330 | } |
| 113331 | |
| 113332 | /* Locate the PRIMARY KEY index. Or, if this table was originally |
| 113333 | ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. |
| 113334 | */ |
| @@ -121313,11 +121329,13 @@ | |
| 121329 | ** non-zero. If there is no foreign key related processing, this function |
| 121330 | ** returns zero. |
| 121331 | ** |
| 121332 | ** For an UPDATE, this function returns 2 if: |
| 121333 | ** |
| 121334 | ** * There are any FKs for which pTab is the child and the parent table |
| 121335 | ** and any FK processing at all is required (even of a different FK), or |
| 121336 | ** |
| 121337 | ** * the UPDATE modifies one or more parent keys for which the action is |
| 121338 | ** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL). |
| 121339 | ** |
| 121340 | ** Or, assuming some other foreign key processing is required, 1. |
| 121341 | */ |
| @@ -121325,40 +121343,41 @@ | |
| 121343 | Parse *pParse, /* Parse context */ |
| 121344 | Table *pTab, /* Table being modified */ |
| 121345 | int *aChange, /* Non-NULL for UPDATE operations */ |
| 121346 | int chngRowid /* True for UPDATE that affects rowid */ |
| 121347 | ){ |
| 121348 | int eRet = 1; /* Value to return if bHaveFK is true */ |
| 121349 | int bHaveFK = 0; /* If FK processing is required */ |
| 121350 | if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 121351 | if( !aChange ){ |
| 121352 | /* A DELETE operation. Foreign key processing is required if the |
| 121353 | ** table in question is either the child or parent table for any |
| 121354 | ** foreign key constraint. */ |
| 121355 | bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey); |
| 121356 | }else{ |
| 121357 | /* This is an UPDATE. Foreign key processing is only required if the |
| 121358 | ** operation modifies one or more child or parent key columns. */ |
| 121359 | FKey *p; |
| 121360 | |
| 121361 | /* Check if any child key columns are being modified. */ |
| 121362 | for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 121363 | if( fkChildIsModified(pTab, p, aChange, chngRowid) ){ |
| 121364 | if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2; |
| 121365 | bHaveFK = 1; |
| 121366 | } |
| 121367 | } |
| 121368 | |
| 121369 | /* Check if any parent key columns are being modified. */ |
| 121370 | for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ |
| 121371 | if( fkParentIsModified(pTab, p, aChange, chngRowid) ){ |
| 121372 | if( p->aAction[1]!=OE_None ) return 2; |
| 121373 | bHaveFK = 1; |
| 121374 | } |
| 121375 | } |
| 121376 | } |
| 121377 | } |
| 121378 | return bHaveFK ? eRet : 0; |
| 121379 | } |
| 121380 | |
| 121381 | /* |
| 121382 | ** This function is called when an UPDATE or DELETE operation is being |
| 121383 | ** compiled on table pTab, which is the parent table of foreign-key pFKey. |
| @@ -122796,15 +122815,10 @@ | |
| 122815 | sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols); |
| 122816 | sqlite3VdbeJumpHere(v, addr1); |
| 122817 | sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v); |
| 122818 | } |
| 122819 | |
| 122820 | /* Copy the new data already generated. */ |
| 122821 | assert( pTab->nNVCol>0 ); |
| 122822 | sqlite3VdbeAddOp3(v, OP_Copy, regRowid+1, regCols+1, pTab->nNVCol-1); |
| 122823 | |
| 122824 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| @@ -137898,10 +137912,12 @@ | |
| 137912 | && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 137913 | ){ |
| 137914 | pTrig->pNext = pList; |
| 137915 | pList = pTrig; |
| 137916 | }else if( pTrig->op==TK_RETURNING ){ |
| 137917 | assert( pParse->bReturning ); |
| 137918 | assert( &(pParse->u1.pReturning->retTrig) == pTrig ); |
| 137919 | pTrig->table = pTab->zName; |
| 137920 | pTrig->pTabSchema = pTab->pSchema; |
| 137921 | pTrig->pNext = pList; |
| 137922 | pList = pTrig; |
| 137923 | } |
| @@ -138587,20 +138603,25 @@ | |
| 138603 | }else if( p->op==TK_RETURNING ){ |
| 138604 | /* The first time a RETURNING trigger is seen, the "op" value tells |
| 138605 | ** us what time of trigger it should be. */ |
| 138606 | assert( sqlite3IsToplevel(pParse) ); |
| 138607 | p->op = op; |
| 138608 | if( IsVirtual(pTab) ){ |
| 138609 | if( op!=TK_INSERT ){ |
| 138610 | sqlite3ErrorMsg(pParse, |
| 138611 | "%s RETURNING is not available on virtual tables", |
| 138612 | op==TK_DELETE ? "DELETE" : "UPDATE"); |
| 138613 | } |
| 138614 | p->tr_tm = TRIGGER_BEFORE; |
| 138615 | }else{ |
| 138616 | p->tr_tm = TRIGGER_AFTER; |
| 138617 | } |
| 138618 | mask |= p->tr_tm; |
| 138619 | }else if( p->bReturning && p->op==TK_INSERT && op==TK_UPDATE |
| 138620 | && sqlite3IsToplevel(pParse) ){ |
| 138621 | /* Also fire a RETURNING trigger for an UPSERT */ |
| 138622 | mask |= p->tr_tm; |
| 138623 | } |
| 138624 | p = p->pNext; |
| 138625 | }while( p ); |
| 138626 | } |
| 138627 | exit_triggers_exist: |
| @@ -138658,10 +138679,11 @@ | |
| 138679 | Table *pTab /* The table being updated */ |
| 138680 | ){ |
| 138681 | ExprList *pNew = 0; |
| 138682 | sqlite3 *db = pParse->db; |
| 138683 | int i; |
| 138684 | |
| 138685 | for(i=0; i<pList->nExpr; i++){ |
| 138686 | Expr *pOldExpr = pList->a[i].pExpr; |
| 138687 | if( ALWAYS(pOldExpr!=0) && pOldExpr->op==TK_ASTERISK ){ |
| 138688 | int jj; |
| 138689 | for(jj=0; jj<pTab->nCol; jj++){ |
| @@ -138681,13 +138703,75 @@ | |
| 138703 | struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; |
| 138704 | pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName); |
| 138705 | pItem->eEName = pList->a[i].eEName; |
| 138706 | } |
| 138707 | } |
| 138708 | } |
| 138709 | if( !db->mallocFailed ){ |
| 138710 | Vdbe *v = pParse->pVdbe; |
| 138711 | assert( v!=0 ); |
| 138712 | sqlite3VdbeSetNumCols(v, pNew->nExpr); |
| 138713 | for(i=0; i<pNew->nExpr; i++){ |
| 138714 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, pNew->a[i].zEName, |
| 138715 | SQLITE_TRANSIENT); |
| 138716 | } |
| 138717 | } |
| 138718 | return pNew; |
| 138719 | } |
| 138720 | |
| 138721 | /* |
| 138722 | ** Generate code for the RETURNING trigger. Unlike other triggers |
| 138723 | ** that invoke a subprogram in the bytecode, the code for RETURNING |
| 138724 | ** is generated in-line. |
| 138725 | */ |
| 138726 | static void codeReturningTrigger( |
| 138727 | Parse *pParse, /* Parse context */ |
| 138728 | Trigger *pTrigger, /* The trigger step that defines the RETURNING */ |
| 138729 | Table *pTab, /* The table to code triggers from */ |
| 138730 | int regIn /* The first in an array of registers */ |
| 138731 | ){ |
| 138732 | Vdbe *v = pParse->pVdbe; |
| 138733 | ExprList *pNew; |
| 138734 | Returning *pReturning; |
| 138735 | |
| 138736 | assert( v!=0 ); |
| 138737 | assert( pParse->bReturning ); |
| 138738 | pReturning = pParse->u1.pReturning; |
| 138739 | assert( pTrigger == &(pReturning->retTrig) ); |
| 138740 | pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab); |
| 138741 | if( pNew ){ |
| 138742 | NameContext sNC; |
| 138743 | memset(&sNC, 0, sizeof(sNC)); |
| 138744 | if( pReturning->nRetCol==0 ){ |
| 138745 | pReturning->nRetCol = pNew->nExpr; |
| 138746 | pReturning->iRetCur = pParse->nTab++; |
| 138747 | } |
| 138748 | sNC.pParse = pParse; |
| 138749 | sNC.uNC.iBaseReg = regIn; |
| 138750 | sNC.ncFlags = NC_UBaseReg; |
| 138751 | pParse->eTriggerOp = pTrigger->op; |
| 138752 | pParse->pTriggerTab = pTab; |
| 138753 | if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK ){ |
| 138754 | int i; |
| 138755 | int nCol = pNew->nExpr; |
| 138756 | int reg = pParse->nMem+1; |
| 138757 | pParse->nMem += nCol+2; |
| 138758 | pReturning->iRetReg = reg; |
| 138759 | for(i=0; i<nCol; i++){ |
| 138760 | sqlite3ExprCodeFactorable(pParse, pNew->a[i].pExpr, reg+i); |
| 138761 | } |
| 138762 | sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, i, reg+i); |
| 138763 | sqlite3VdbeAddOp2(v, OP_NewRowid, pReturning->iRetCur, reg+i+1); |
| 138764 | sqlite3VdbeAddOp3(v, OP_Insert, pReturning->iRetCur, reg+i, reg+i+1); |
| 138765 | } |
| 138766 | sqlite3ExprListDelete(pParse->db, pNew); |
| 138767 | pParse->eTriggerOp = 0; |
| 138768 | pParse->pTriggerTab = 0; |
| 138769 | } |
| 138770 | } |
| 138771 | |
| 138772 | |
| 138773 | |
| 138774 | /* |
| 138775 | ** Generate VDBE code for the statements inside the body of a single |
| 138776 | ** trigger. |
| 138777 | */ |
| @@ -138756,38 +138840,18 @@ | |
| 138840 | sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0 |
| 138841 | ); |
| 138842 | sqlite3VdbeAddOp0(v, OP_ResetCount); |
| 138843 | break; |
| 138844 | } |
| 138845 | default: assert( pStep->op==TK_SELECT ); { |
| 138846 | SelectDest sDest; |
| 138847 | Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0); |
| 138848 | sqlite3SelectDestInit(&sDest, SRT_Discard, 0); |
| 138849 | sqlite3Select(pParse, pSelect, &sDest); |
| 138850 | sqlite3SelectDelete(db, pSelect); |
| 138851 | break; |
| 138852 | } |
| 138853 | } |
| 138854 | } |
| 138855 | |
| 138856 | return 0; |
| 138857 | } |
| @@ -138874,11 +138938,10 @@ | |
| 138938 | pSubParse->db = db; |
| 138939 | pSubParse->pTriggerTab = pTab; |
| 138940 | pSubParse->pToplevel = pTop; |
| 138941 | pSubParse->zAuthContext = pTrigger->zName; |
| 138942 | pSubParse->eTriggerOp = pTrigger->op; |
| 138943 | pSubParse->nQueryLoop = pParse->nQueryLoop; |
| 138944 | pSubParse->disableVtab = pParse->disableVtab; |
| 138945 | |
| 138946 | v = sqlite3GetVdbe(pSubParse); |
| 138947 | if( v ){ |
| @@ -138924,13 +138987,10 @@ | |
| 138987 | |
| 138988 | transferParseError(pParse, pSubParse); |
| 138989 | if( db->mallocFailed==0 && pParse->nErr==0 ){ |
| 138990 | pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg); |
| 138991 | } |
| 138992 | pProgram->nMem = pSubParse->nMem; |
| 138993 | pProgram->nCsr = pSubParse->nTab; |
| 138994 | pProgram->token = (void *)pTrigger; |
| 138995 | pPrg->aColmask[0] = pSubParse->oldmask; |
| 138996 | pPrg->aColmask[1] = pSubParse->newmask; |
| @@ -139036,11 +139096,11 @@ | |
| 139096 | ** reg+0 OLD.rowid |
| 139097 | ** reg+1 OLD.* value of left-most column of pTab |
| 139098 | ** ... ... |
| 139099 | ** reg+N OLD.* value of right-most column of pTab |
| 139100 | ** reg+N+1 NEW.rowid |
| 139101 | ** reg+N+2 NEW.* value of left-most column of pTab |
| 139102 | ** ... ... |
| 139103 | ** reg+N+N+1 NEW.* value of right-most column of pTab |
| 139104 | ** |
| 139105 | ** For ON DELETE triggers, the registers containing the NEW.* values will |
| 139106 | ** never be accessed by the trigger program, so they are not allocated or |
| @@ -139089,16 +139149,16 @@ | |
| 139149 | ** doing the UPDATE part of an UPSERT. |
| 139150 | */ |
| 139151 | if( (p->op==op || (p->bReturning && p->op==TK_INSERT && op==TK_UPDATE)) |
| 139152 | && p->tr_tm==tr_tm |
| 139153 | && checkColumnOverlap(p->pColumns, pChanges) |
| 139154 | ){ |
| 139155 | if( !p->bReturning ){ |
| 139156 | sqlite3CodeRowTriggerDirect(pParse, p, pTab, reg, orconf, ignoreJump); |
| 139157 | }else if( sqlite3IsToplevel(pParse) ){ |
| 139158 | codeReturningTrigger(pParse, p, pTab, reg); |
| 139159 | } |
| 139160 | } |
| 139161 | } |
| 139162 | } |
| 139163 | |
| 139164 | /* |
| @@ -139139,17 +139199,22 @@ | |
| 139199 | u32 mask = 0; |
| 139200 | Trigger *p; |
| 139201 | |
| 139202 | assert( isNew==1 || isNew==0 ); |
| 139203 | for(p=pTrigger; p; p=p->pNext){ |
| 139204 | if( p->op==op |
| 139205 | && (tr_tm&p->tr_tm) |
| 139206 | && checkColumnOverlap(p->pColumns,pChanges) |
| 139207 | ){ |
| 139208 | if( p->bReturning ){ |
| 139209 | mask = 0xffffffff; |
| 139210 | }else{ |
| 139211 | TriggerPrg *pPrg; |
| 139212 | pPrg = getRowTrigger(pParse, p, pTab, orconf); |
| 139213 | if( pPrg ){ |
| 139214 | mask |= pPrg->aColmask[isNew]; |
| 139215 | } |
| 139216 | } |
| 139217 | } |
| 139218 | } |
| 139219 | |
| 139220 | return mask; |
| @@ -142036,11 +142101,11 @@ | |
| 142101 | ){ |
| 142102 | if( !pTab->aCol ){ |
| 142103 | Table *pNew = sParse.pNewTable; |
| 142104 | Index *pIdx; |
| 142105 | pTab->aCol = pNew->aCol; |
| 142106 | pTab->nNVCol = pTab->nCol = pNew->nCol; |
| 142107 | pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid); |
| 142108 | pNew->nCol = 0; |
| 142109 | pNew->aCol = 0; |
| 142110 | assert( pTab->pIndex==0 ); |
| 142111 | assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 ); |
| @@ -228415,11 +228480,11 @@ | |
| 228480 | int nArg, /* Number of args */ |
| 228481 | sqlite3_value **apUnused /* Function arguments */ |
| 228482 | ){ |
| 228483 | assert( nArg==0 ); |
| 228484 | UNUSED_PARAM2(nArg, apUnused); |
| 228485 | sqlite3_result_text(pCtx, "fts5: 2021-02-05 17:34:47 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4c30c", -1, SQLITE_TRANSIENT); |
| 228486 | } |
| 228487 | |
| 228488 | /* |
| 228489 | ** Return true if zName is the extension on one of the shadow tables used |
| 228490 | ** by this module. |
| @@ -233341,12 +233406,12 @@ | |
| 233406 | } |
| 233407 | #endif /* SQLITE_CORE */ |
| 233408 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 233409 | |
| 233410 | /************** End of stmt.c ************************************************/ |
| 233411 | #if __LINE__!=233411 |
| 233412 | #undef SQLITE_SOURCE_ID |
| 233413 | #define SQLITE_SOURCE_ID "2021-02-05 17:34:47 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4alt2" |
| 233414 | #endif |
| 233415 | /* Return the source-id for this library */ |
| 233416 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 233417 | /************************** End of sqlite3.c ******************************/ |
| 233418 |
+1
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -123,11 +123,11 @@ | ||
| 123 | 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | 125 | */ |
| 126 | 126 | #define SQLITE_VERSION "3.35.0" |
| 127 | 127 | #define SQLITE_VERSION_NUMBER 3035000 |
| 128 | -#define SQLITE_SOURCE_ID "2021-02-03 13:20:12 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644d0902" | |
| 128 | +#define SQLITE_SOURCE_ID "2021-02-05 17:34:47 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4c30c" | |
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | 133 | ** |
| 134 | 134 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.35.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3035000 |
| 128 | #define SQLITE_SOURCE_ID "2021-02-03 13:20:12 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644d0902" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| 134 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.35.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3035000 |
| 128 | #define SQLITE_SOURCE_ID "2021-02-05 17:34:47 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4c30c" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| 134 |