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.

drh 2021-02-05 18:27 trunk
Commit 1ba06268ada456d5059e325c0d18fc06362871b43384ba74c7baf5583eeeb678
2 files changed +204 -139 +1 -1
+204 -139
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
11861186
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11871187
** [sqlite_version()] and [sqlite_source_id()].
11881188
*/
11891189
#define SQLITE_VERSION "3.35.0"
11901190
#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"
11921192
11931193
/*
11941194
** CAPI3REF: Run-Time Library Version Numbers
11951195
** KEYWORDS: sqlite3_version sqlite3_sourceid
11961196
**
@@ -16002,11 +16002,10 @@
1600216002
#endif
1600316003
SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
1600416004
SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
1600516005
SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
1600616006
SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
16007
-SQLITE_PRIVATE void sqlite3VdbeColumnInfoXfer(Vdbe*,Vdbe*);
1600816007
SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
1600916008
SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
1601016009
SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
1601116010
SQLITE_PRIVATE u8 sqlite3VdbePrepareFlags(Vdbe*);
1601216011
SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, u8);
@@ -18223,11 +18222,11 @@
1822318222
#define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */
1822418223
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
1822518224
#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
1822618225
#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
1822718226
#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 */
1822918228
#define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
1823018229
#define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
1823118230
#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
1823218231
#define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
1823318232
#define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
@@ -18498,10 +18497,11 @@
1849818497
SrcList *pSrcList; /* One or more tables used to resolve names */
1849918498
union {
1850018499
ExprList *pEList; /* Optional list of result-set columns */
1850118500
AggInfo *pAggInfo; /* Information about aggregates at this level */
1850218501
Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */
18502
+ int iBaseReg; /* For TK_REGISTER when parsing RETURNING */
1850318503
} uNC;
1850418504
NameContext *pNext; /* Next outer name context. NULL for outermost */
1850518505
int nRef; /* Number of names resolved by this context */
1850618506
int nErr; /* Number of errors encountered while resolving names */
1850718507
int ncFlags; /* Zero or more NC_* flags defined below */
@@ -18526,10 +18526,11 @@
1852618526
#define NC_SelfRef 0x0002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */
1852718527
#define NC_VarSelect 0x00040 /* A correlated subquery has been seen */
1852818528
#define NC_UEList 0x00080 /* True if uNC.pEList is used */
1852918529
#define NC_UAggInfo 0x00100 /* True if uNC.pAggInfo is used */
1853018530
#define NC_UUpsert 0x00200 /* True if uNC.pUpsert is used */
18531
+#define NC_UBaseReg 0x00400 /* True if uNC.iBaseReg is used */
1853118532
#define NC_MinMaxAgg 0x01000 /* min/max aggregates seen. See note above */
1853218533
#define NC_Complex 0x02000 /* True if a function or subquery seen */
1853318534
#define NC_AllowWin 0x04000 /* Window functions are allowed here */
1853418535
#define NC_HasWin 0x08000 /* One or more window functions seen */
1853518536
#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
@@ -18886,11 +18887,14 @@
1888618887
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
1888718888
Parse *pToplevel; /* Parse structure for main program (or NULL) */
1888818889
Table *pTriggerTab; /* Table triggers are being coded for */
1888918890
Parse *pParentParse; /* Parent parser if this parser is nested */
1889018891
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;
1889218896
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
1889318897
u32 oldmask; /* Mask of old.* columns referenced */
1889418898
u32 newmask; /* Mask of new.* columns referenced */
1889518899
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
1889618900
u8 bReturning; /* Coding a RETURNING trigger */
@@ -19108,11 +19112,11 @@
1910819112
Trigger *pTrig; /* The trigger that this step is a part of */
1910919113
Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
1911019114
char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
1911119115
SrcList *pFrom; /* FROM clause for UPDATE statement (if any) */
1911219116
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 */
1911419118
IdList *pIdList; /* Column names for INSERT */
1911519119
Upsert *pUpsert; /* Upsert clauses on an INSERT */
1911619120
char *zSpan; /* Original SQL text of this command */
1911719121
TriggerStep *pNext; /* Next in the link-list */
1911819122
TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
@@ -19124,12 +19128,13 @@
1912419128
struct Returning {
1912519129
Parse *pParse; /* The parse that includes the RETURNING clause */
1912619130
ExprList *pReturnEL; /* List of expressions to return */
1912719131
Trigger retTrig; /* The transient trigger that implements RETURNING */
1912819132
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 */
1913119136
};
1913219137
1913319138
/*
1913419139
** An objected used to accumulate the text of a string where we
1913519140
** do not necessarily know how big the string will be in the end.
@@ -21275,11 +21280,11 @@
2127521280
struct Vdbe {
2127621281
sqlite3 *db; /* The database connection that owns this statement */
2127721282
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
2127821283
Parse *pParse; /* Parsing context used to create this Vdbe */
2127921284
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 */
2128121286
int nMem; /* Number of memory locations currently allocated */
2128221287
int nCursor; /* Number of slots in apCsr[] */
2128321288
u32 cacheCtr; /* VdbeCursor row cache generation counter */
2128421289
int pc; /* The program counter */
2128521290
int rc; /* Value to return */
@@ -72861,11 +72866,11 @@
7286172866
*/
7286272867
for(i=0; i<nNew; i++){
7286372868
aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
7286472869
aPgFlags[i] = apNew[i]->pDbPage->flags;
7286572870
for(j=0; j<i; j++){
72866
- if( aPgno[j]==aPgno[i] ){
72871
+ if( NEVER(aPgno[j]==aPgno[i]) ){
7286772872
/* This branch is taken if the set of sibling pages somehow contains
7286872873
** duplicate entries. This can happen if the database is corrupt.
7286972874
** It would be simpler to detect this as part of the loop below, but
7287072875
** we do the detection here in order to avoid populating the pager
7287172876
** cache with two separate objects associated with the same
@@ -78292,11 +78297,11 @@
7829278297
db->pVdbe->pPrev = p;
7829378298
}
7829478299
p->pNext = db->pVdbe;
7829578300
p->pPrev = 0;
7829678301
db->pVdbe = p;
78297
- p->magic = VDBE_MAGIC_INIT;
78302
+ p->iVdbeMagic = VDBE_MAGIC_INIT;
7829878303
p->pParse = pParse;
7829978304
pParse->pVdbe = p;
7830078305
assert( pParse->aLabel==0 );
7830178306
assert( pParse->nLabel==0 );
7830278307
assert( p->nOpAlloc==0 );
@@ -78493,11 +78498,11 @@
7849378498
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
7849478499
int i;
7849578500
VdbeOp *pOp;
7849678501
7849778502
i = p->nOp;
78498
- assert( p->magic==VDBE_MAGIC_INIT );
78503
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
7849978504
assert( op>=0 && op<0xff );
7850078505
if( p->nOpAlloc<=i ){
7850178506
return growOp3(p, op, p1, p2, p3);
7850278507
}
7850378508
p->nOp++;
@@ -78822,11 +78827,11 @@
7882278827
}
7882378828
}
7882478829
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
7882578830
Parse *p = v->pParse;
7882678831
int j = ADDR(x);
78827
- assert( v->magic==VDBE_MAGIC_INIT );
78832
+ assert( v->iVdbeMagic==VDBE_MAGIC_INIT );
7882878833
assert( j<-p->nLabel );
7882978834
assert( j>=0 );
7883078835
#ifdef SQLITE_DEBUG
7883178836
if( p->db->flags & SQLITE_VdbeAddopTrace ){
7883278837
printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
@@ -79147,11 +79152,11 @@
7914779152
7914879153
/*
7914979154
** Return the address of the next instruction to be inserted.
7915079155
*/
7915179156
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
79152
- assert( p->magic==VDBE_MAGIC_INIT );
79157
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
7915379158
return p->nOp;
7915479159
}
7915579160
7915679161
/*
7915779162
** Verify that at least N opcode slots are available in p without
@@ -79232,11 +79237,11 @@
7923279237
int iLineno /* Source-file line number of first opcode */
7923379238
){
7923479239
int i;
7923579240
VdbeOp *pOut, *pFirst;
7923679241
assert( nOp>0 );
79237
- assert( p->magic==VDBE_MAGIC_INIT );
79242
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
7923879243
if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
7923979244
return 0;
7924079245
}
7924179246
pFirst = pOut = &p->aOp[p->nOp];
7924279247
for(i=0; i<nOp; i++, aOp++, pOut++){
@@ -79556,11 +79561,11 @@
7955679561
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
7955779562
Op *pOp;
7955879563
sqlite3 *db;
7955979564
assert( p!=0 );
7956079565
db = p->db;
79561
- assert( p->magic==VDBE_MAGIC_INIT );
79566
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
7956279567
assert( p->aOp!=0 || db->mallocFailed );
7956379568
if( db->mallocFailed ){
7956479569
if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4);
7956579570
return;
7956679571
}
@@ -79685,11 +79690,11 @@
7968579690
*/
7968679691
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
7968779692
/* C89 specifies that the constant "dummy" will be initialized to all
7968879693
** zeros, which is correct. MSVC generates a warning, nevertheless. */
7968979694
static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
79690
- assert( p->magic==VDBE_MAGIC_INIT );
79695
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
7969179696
if( addr<0 ){
7969279697
addr = p->nOp - 1;
7969379698
}
7969479699
assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
7969579700
if( p->db->mallocFailed ){
@@ -80370,11 +80375,11 @@
8037080375
int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
8037180376
Op *aOp; /* Array of opcodes */
8037280377
Op *pOp; /* Current opcode */
8037380378
8037480379
assert( p->explain );
80375
- assert( p->magic==VDBE_MAGIC_RUN );
80380
+ assert( p->iVdbeMagic==VDBE_MAGIC_RUN );
8037680381
assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
8037780382
8037880383
/* Even though this opcode does not use dynamic strings for
8037980384
** the result, result columns may become dynamic if the user calls
8038080385
** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
@@ -80550,18 +80555,18 @@
8055080555
SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
8055180556
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
8055280557
int i;
8055380558
#endif
8055480559
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 );
8055680561
8055780562
/* There should be at least one opcode.
8055880563
*/
8055980564
assert( p->nOp>0 );
8056080565
8056180566
/* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
80562
- p->magic = VDBE_MAGIC_RUN;
80567
+ p->iVdbeMagic = VDBE_MAGIC_RUN;
8056380568
8056480569
#ifdef SQLITE_DEBUG
8056580570
for(i=0; i<p->nMem; i++){
8056680571
assert( p->aMem[i].db==p->db );
8056780572
}
@@ -80613,11 +80618,11 @@
8061380618
struct ReusableSpace x; /* Reusable bulk memory */
8061480619
8061580620
assert( p!=0 );
8061680621
assert( p->nOp>0 );
8061780622
assert( pParse!=0 );
80618
- assert( p->magic==VDBE_MAGIC_INIT );
80623
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
8061980624
assert( pParse==p->pParse );
8062080625
p->pVList = pParse->pVList;
8062180626
pParse->pVList = 0;
8062280627
db = p->db;
8062380628
assert( db->mallocFailed==0 );
@@ -80852,27 +80857,10 @@
8085280857
p->aColName = (Mem*)sqlite3DbMallocRawNN(db, sizeof(Mem)*n );
8085380858
if( p->aColName==0 ) return;
8085480859
initMemArray(p->aColName, n, db, MEM_Null);
8085580860
}
8085680861
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
-
8087480862
/*
8087580863
** Set the name of the idx'th column to be returned by the SQL statement.
8087680864
** zName must be a pointer to a nul terminated string.
8087780865
**
8087880866
** This call must be made after a call to sqlite3VdbeSetNumCols().
@@ -81315,11 +81303,11 @@
8131581303
** Then the internal cache might have been left in an inconsistent
8131681304
** state. We need to rollback the statement transaction, if there is
8131781305
** one, or the complete transaction if there is no statement transaction.
8131881306
*/
8131981307
81320
- if( p->magic!=VDBE_MAGIC_RUN ){
81308
+ if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){
8132181309
return SQLITE_OK;
8132281310
}
8132381311
if( db->mallocFailed ){
8132481312
p->rc = SQLITE_NOMEM_BKPT;
8132581313
}
@@ -81473,11 +81461,11 @@
8147381461
if( p->bIsReader ) db->nVdbeRead--;
8147481462
assert( db->nVdbeActive>=db->nVdbeRead );
8147581463
assert( db->nVdbeRead>=db->nVdbeWrite );
8147681464
assert( db->nVdbeWrite>=0 );
8147781465
}
81478
- p->magic = VDBE_MAGIC_HALT;
81466
+ p->iVdbeMagic = VDBE_MAGIC_HALT;
8147981467
checkActiveVdbeCnt(db);
8148081468
if( db->mallocFailed ){
8148181469
p->rc = SQLITE_NOMEM_BKPT;
8148281470
}
8148381471
@@ -81646,21 +81634,21 @@
8164681634
}
8164781635
fclose(out);
8164881636
}
8164981637
}
8165081638
#endif
81651
- p->magic = VDBE_MAGIC_RESET;
81639
+ p->iVdbeMagic = VDBE_MAGIC_RESET;
8165281640
return p->rc & db->errMask;
8165381641
}
8165481642
8165581643
/*
8165681644
** Clean up and delete a VDBE after execution. Return an integer which is
8165781645
** the result code. Write any error message text into *pzErrMsg.
8165881646
*/
8165981647
SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){
8166081648
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 ){
8166281650
rc = sqlite3VdbeReset(p);
8166381651
assert( (rc & p->db->errMask)==rc );
8166481652
}
8166581653
sqlite3VdbeDelete(p);
8166681654
return rc;
@@ -81717,11 +81705,11 @@
8171781705
for(pSub=p->pProgram; pSub; pSub=pNext){
8171881706
pNext = pSub->pNext;
8171981707
vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
8172081708
sqlite3DbFree(db, pSub);
8172181709
}
81722
- if( p->magic!=VDBE_MAGIC_INIT ){
81710
+ if( p->iVdbeMagic!=VDBE_MAGIC_INIT ){
8172381711
releaseMemArray(p->aVar, p->nVar);
8172481712
sqlite3DbFree(db, p->pVList);
8172581713
sqlite3DbFree(db, p->pFree);
8172681714
}
8172781715
vdbeFreeOpArray(db, p->aOp, p->nOp);
@@ -81765,11 +81753,11 @@
8176581753
db->pVdbe = p->pNext;
8176681754
}
8176781755
if( p->pNext ){
8176881756
p->pNext->pPrev = p->pPrev;
8176981757
}
81770
- p->magic = VDBE_MAGIC_DEAD;
81758
+ p->iVdbeMagic = VDBE_MAGIC_DEAD;
8177181759
p->db = 0;
8177281760
sqlite3DbFreeNN(db, p);
8177381761
}
8177481762
8177581763
/*
@@ -84144,11 +84132,11 @@
8414484132
static int sqlite3Step(Vdbe *p){
8414584133
sqlite3 *db;
8414684134
int rc;
8414784135
8414884136
assert(p);
84149
- if( p->magic!=VDBE_MAGIC_RUN ){
84137
+ if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){
8415084138
/* We used to require that sqlite3_reset() be called before retrying
8415184139
** sqlite3_step() after any error or after SQLITE_DONE. But beginning
8415284140
** with version 3.7.0, we changed this so that sqlite3_reset() would
8415384141
** be called automatically instead of throwing the SQLITE_MISUSE error.
8415484142
** This "automatic-reset" change is not technically an incompatibility,
@@ -84860,11 +84848,11 @@
8486084848
Mem *pVar;
8486184849
if( vdbeSafetyNotNull(p) ){
8486284850
return SQLITE_MISUSE_BKPT;
8486384851
}
8486484852
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 ){
8486684854
sqlite3Error(p->db, SQLITE_MISUSE);
8486784855
sqlite3_mutex_leave(p->db->mutex);
8486884856
sqlite3_log(SQLITE_MISUSE,
8486984857
"bind on a busy prepared statement: [%s]", p->zSql);
8487084858
return SQLITE_MISUSE_BKPT;
@@ -85214,11 +85202,11 @@
8521485202
/*
8521585203
** Return true if the prepared statement is in need of being reset.
8521685204
*/
8521785205
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
8521885206
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;
8522085208
}
8522185209
8522285210
/*
8522385211
** Return a pointer to the next prepared statement after pStmt associated
8522485212
** with database connection pDb. If pStmt is NULL, return the first
@@ -86552,11 +86540,11 @@
8655286540
#ifdef VDBE_PROFILE
8655386541
u64 start; /* CPU clock count at start of opcode */
8655486542
#endif
8655586543
/*** INSERT STACK UNION HERE ***/
8655686544
86557
- assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
86545
+ assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
8655886546
sqlite3VdbeEnter(p);
8655986547
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
8656086548
if( db->xProgress ){
8656186549
u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
8656286550
assert( 0 < db->nProgressOps );
@@ -98629,11 +98617,10 @@
9862998617
assert( db->mallocFailed );
9863098618
}
9863198619
}
9863298620
sqlite3DbFree(db, pDup);
9863398621
}
98634
- ExprSetProperty(pExpr, EP_Alias);
9863598622
}
9863698623
9863798624
9863898625
/*
9863998626
** Return TRUE if the name zCol occurs anywhere in the USING clause.
@@ -98888,11 +98875,11 @@
9888898875
#if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT)
9888998876
/* If we have not already resolved the name, then maybe
9889098877
** it is a new.* or old.* trigger argument reference. Or
9889198878
** maybe it is an excluded.* from an upsert.
9889298879
*/
98893
- if( zDb==0 && cntTab==0 ){
98880
+ if( cntTab==0 && zDb==0 ){
9889498881
pTab = 0;
9889598882
#ifndef SQLITE_OMIT_TRIGGER
9889698883
if( pParse->pTriggerTab!=0 ){
9889798884
int op = pParse->eTriggerOp;
9889898885
assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
@@ -98946,31 +98933,35 @@
9894698933
eNewExprOp = TK_COLUMN;
9894798934
}else{
9894898935
pExpr->iTable = pNC->uNC.pUpsert->regData +
9894998936
sqlite3TableColumnToStorage(pTab, iCol);
9895098937
eNewExprOp = TK_REGISTER;
98951
- ExprSetProperty(pExpr, EP_Alias);
9895298938
}
9895398939
}else
9895498940
#endif /* SQLITE_OMIT_UPSERT */
9895598941
{
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
- }
9896898942
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
+ }
9897198961
#endif /* SQLITE_OMIT_TRIGGER */
98962
+ }
9897298963
}
9897398964
}
9897498965
}
9897598966
}
9897698967
#endif /* !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) */
@@ -99147,11 +99138,13 @@
9914799138
pExpr->op = eNewExprOp;
9914899139
ExprSetProperty(pExpr, EP_Leaf);
9914999140
lookupname_end:
9915099141
if( cnt==1 ){
9915199142
assert( pNC!=0 );
99152
- if( !ExprHasProperty(pExpr, EP_Alias) ){
99143
+ if( pParse->db->xAuth
99144
+ && (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER)
99145
+ ){
9915399146
sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
9915499147
}
9915599148
/* Increment the nRef value on all name contexts from TopNC up to
9915699149
** the point where the name matched. */
9915799150
for(;;){
@@ -111033,20 +111026,19 @@
111033111026
Parse *pParse, /* The parser context */
111034111027
Expr *pExpr, /* The expression to check authorization on */
111035111028
Schema *pSchema, /* The schema of the expression */
111036111029
SrcList *pTabList /* All table that pExpr might refer to */
111037111030
){
111038
- sqlite3 *db = pParse->db;
111039111031
Table *pTab = 0; /* The table being read */
111040111032
const char *zCol; /* Name of the column of the table */
111041111033
int iSrc; /* Index in pTabList->a[] of table being read */
111042111034
int iDb; /* The index of the database the expression refers to */
111043111035
int iCol; /* Index of column in table */
111044111036
111045111037
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 );
111048111040
iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
111049111041
if( iDb<0 ){
111050111042
/* An attempt to read a column out of a subquery or other
111051111043
** temporary table. */
111052111044
return;
@@ -111073,11 +111065,11 @@
111073111065
assert( pTab->iPKey<pTab->nCol );
111074111066
zCol = pTab->aCol[pTab->iPKey].zName;
111075111067
}else{
111076111068
zCol = "ROWID";
111077111069
}
111078
- assert( iDb>=0 && iDb<db->nDb );
111070
+ assert( iDb>=0 && iDb<pParse->db->nDb );
111079111071
if( SQLITE_IGNORE==sqlite3AuthReadCol(pParse, pTab->zName, zCol, iDb) ){
111080111072
pExpr->op = TK_NULL;
111081111073
}
111082111074
}
111083111075
@@ -111305,18 +111297,38 @@
111305111297
}
111306111298
111307111299
/* Begin by generating some termination code at the end of the
111308111300
** vdbe program
111309111301
*/
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;
111313111310
}
111314
- v = sqlite3GetVdbe(pParse);
111315111311
assert( !pParse->isMultiWrite
111316111312
|| sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
111317111313
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
+ }
111318111330
sqlite3VdbeAddOp0(v, OP_Halt);
111319111331
111320111332
#if SQLITE_USER_AUTHENTICATION
111321111333
if( pParse->nTableLock>0 && db->init.busy==0 ){
111322111334
sqlite3UserAuthInit(db);
@@ -111389,16 +111401,20 @@
111389111401
if( iReg>0 ){
111390111402
sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
111391111403
}
111392111404
}
111393111405
}
111406
+
111407
+ if( pParse->bReturning ){
111408
+ Returning *pRet = pParse->u1.pReturning;
111409
+ sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
111410
+ }
111394111411
111395111412
/* Finally, jump back to the beginning of the executable code. */
111396111413
sqlite3VdbeGoto(v, 1);
111397111414
}
111398111415
}
111399
-
111400111416
111401111417
/* Get the VDBE program ready for execution
111402111418
*/
111403111419
if( v && pParse->nErr==0 && !db->mallocFailed ){
111404111420
/* A minimum of one cursor is required if autoincrement is used
@@ -112372,11 +112388,12 @@
112372112388
if( isView || isVirtual ){
112373112389
sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
112374112390
}else
112375112391
#endif
112376112392
{
112377
- pParse->addrCrTab =
112393
+ assert( !pParse->bReturning );
112394
+ pParse->u1.addrCrTab =
112378112395
sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
112379112396
}
112380112397
sqlite3OpenSchemaTable(pParse, iDb);
112381112398
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
112382112399
sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
@@ -112450,10 +112467,11 @@
112450112467
pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
112451112468
if( pRet==0 ){
112452112469
sqlite3ExprListDelete(db, pList);
112453112470
return;
112454112471
}
112472
+ pParse->u1.pReturning = pRet;
112455112473
pRet->pParse = pParse;
112456112474
pRet->pReturnEL = pList;
112457112475
sqlite3ParserAddCleanup(pParse,
112458112476
(void(*)(sqlite3*,void*))sqlite3DeleteReturning, pRet);
112459112477
if( db->mallocFailed ) return;
@@ -112463,14 +112481,11 @@
112463112481
pRet->retTrig.bReturning = 1;
112464112482
pRet->retTrig.pSchema = db->aDb[1].pSchema;
112465112483
pRet->retTrig.step_list = &pRet->retTStep;
112466112484
pRet->retTStep.op = TK_RETURNING;
112467112485
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;
112472112487
pHash = &(db->aDb[1].pSchema->trigHash);
112473112488
assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0 );
112474112489
if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig)
112475112490
==&pRet->retTrig ){
112476112491
sqlite3OomFault(db);
@@ -113306,13 +113321,14 @@
113306113321
}
113307113322
113308113323
/* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
113309113324
** into BTREE_BLOBKEY.
113310113325
*/
113311
- if( pParse->addrCrTab ){
113326
+ assert( !pParse->bReturning );
113327
+ if( pParse->u1.addrCrTab ){
113312113328
assert( v );
113313
- sqlite3VdbeChangeP3(v, pParse->addrCrTab, BTREE_BLOBKEY);
113329
+ sqlite3VdbeChangeP3(v, pParse->u1.addrCrTab, BTREE_BLOBKEY);
113314113330
}
113315113331
113316113332
/* Locate the PRIMARY KEY index. Or, if this table was originally
113317113333
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
113318113334
*/
@@ -121313,11 +121329,13 @@
121313121329
** non-zero. If there is no foreign key related processing, this function
121314121330
** returns zero.
121315121331
**
121316121332
** For an UPDATE, this function returns 2 if:
121317121333
**
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
+**
121319121337
** * the UPDATE modifies one or more parent keys for which the action is
121320121338
** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
121321121339
**
121322121340
** Or, assuming some other foreign key processing is required, 1.
121323121341
*/
@@ -121325,40 +121343,41 @@
121325121343
Parse *pParse, /* Parse context */
121326121344
Table *pTab, /* Table being modified */
121327121345
int *aChange, /* Non-NULL for UPDATE operations */
121328121346
int chngRowid /* True for UPDATE that affects rowid */
121329121347
){
121330
- int eRet = 0;
121348
+ int eRet = 1; /* Value to return if bHaveFK is true */
121349
+ int bHaveFK = 0; /* If FK processing is required */
121331121350
if( pParse->db->flags&SQLITE_ForeignKeys ){
121332121351
if( !aChange ){
121333121352
/* A DELETE operation. Foreign key processing is required if the
121334121353
** table in question is either the child or parent table for any
121335121354
** foreign key constraint. */
121336
- eRet = (sqlite3FkReferences(pTab) || pTab->pFKey);
121355
+ bHaveFK = (sqlite3FkReferences(pTab) || pTab->pFKey);
121337121356
}else{
121338121357
/* This is an UPDATE. Foreign key processing is only required if the
121339121358
** operation modifies one or more child or parent key columns. */
121340121359
FKey *p;
121341121360
121342121361
/* Check if any child key columns are being modified. */
121343121362
for(p=pTab->pFKey; p; p=p->pNextFrom){
121344
- if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2;
121345121363
if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
121346
- eRet = 1;
121364
+ if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) eRet = 2;
121365
+ bHaveFK = 1;
121347121366
}
121348121367
}
121349121368
121350121369
/* Check if any parent key columns are being modified. */
121351121370
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
121352121371
if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
121353121372
if( p->aAction[1]!=OE_None ) return 2;
121354
- eRet = 1;
121373
+ bHaveFK = 1;
121355121374
}
121356121375
}
121357121376
}
121358121377
}
121359
- return eRet;
121378
+ return bHaveFK ? eRet : 0;
121360121379
}
121361121380
121362121381
/*
121363121382
** This function is called when an UPDATE or DELETE operation is being
121364121383
** compiled on table pTab, which is the parent table of foreign-key pFKey.
@@ -122796,15 +122815,10 @@
122796122815
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
122797122816
sqlite3VdbeJumpHere(v, addr1);
122798122817
sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
122799122818
}
122800122819
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
-
122806122820
/* Copy the new data already generated. */
122807122821
assert( pTab->nNVCol>0 );
122808122822
sqlite3VdbeAddOp3(v, OP_Copy, regRowid+1, regCols+1, pTab->nNVCol-1);
122809122823
122810122824
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
@@ -137898,10 +137912,12 @@
137898137912
&& 0==sqlite3StrICmp(pTrig->table, pTab->zName)
137899137913
){
137900137914
pTrig->pNext = pList;
137901137915
pList = pTrig;
137902137916
}else if( pTrig->op==TK_RETURNING ){
137917
+ assert( pParse->bReturning );
137918
+ assert( &(pParse->u1.pReturning->retTrig) == pTrig );
137903137919
pTrig->table = pTab->zName;
137904137920
pTrig->pTabSchema = pTab->pSchema;
137905137921
pTrig->pNext = pList;
137906137922
pList = pTrig;
137907137923
}
@@ -138587,20 +138603,25 @@
138587138603
}else if( p->op==TK_RETURNING ){
138588138604
/* The first time a RETURNING trigger is seen, the "op" value tells
138589138605
** us what time of trigger it should be. */
138590138606
assert( sqlite3IsToplevel(pParse) );
138591138607
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;
138597138617
}
138618
+ mask |= p->tr_tm;
138598138619
}else if( p->bReturning && p->op==TK_INSERT && op==TK_UPDATE
138599138620
&& sqlite3IsToplevel(pParse) ){
138600138621
/* Also fire a RETURNING trigger for an UPSERT */
138601
- mask |= TRIGGER_AFTER;
138622
+ mask |= p->tr_tm;
138602138623
}
138603138624
p = p->pNext;
138604138625
}while( p );
138605138626
}
138606138627
exit_triggers_exist:
@@ -138658,10 +138679,11 @@
138658138679
Table *pTab /* The table being updated */
138659138680
){
138660138681
ExprList *pNew = 0;
138661138682
sqlite3 *db = pParse->db;
138662138683
int i;
138684
+
138663138685
for(i=0; i<pList->nExpr; i++){
138664138686
Expr *pOldExpr = pList->a[i].pExpr;
138665138687
if( ALWAYS(pOldExpr!=0) && pOldExpr->op==TK_ASTERISK ){
138666138688
int jj;
138667138689
for(jj=0; jj<pTab->nCol; jj++){
@@ -138681,13 +138703,75 @@
138681138703
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
138682138704
pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
138683138705
pItem->eEName = pList->a[i].eEName;
138684138706
}
138685138707
}
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
+ }
138686138717
}
138687138718
return pNew;
138688138719
}
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
+
138689138773
138690138774
/*
138691138775
** Generate VDBE code for the statements inside the body of a single
138692138776
** trigger.
138693138777
*/
@@ -138756,38 +138840,18 @@
138756138840
sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0
138757138841
);
138758138842
sqlite3VdbeAddOp0(v, OP_ResetCount);
138759138843
break;
138760138844
}
138761
- case TK_SELECT: {
138845
+ default: assert( pStep->op==TK_SELECT ); {
138762138846
SelectDest sDest;
138763138847
Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
138764138848
sqlite3SelectDestInit(&sDest, SRT_Discard, 0);
138765138849
sqlite3Select(pParse, pSelect, &sDest);
138766138850
sqlite3SelectDelete(db, pSelect);
138767138851
break;
138768138852
}
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
- }
138789138853
}
138790138854
}
138791138855
138792138856
return 0;
138793138857
}
@@ -138874,11 +138938,10 @@
138874138938
pSubParse->db = db;
138875138939
pSubParse->pTriggerTab = pTab;
138876138940
pSubParse->pToplevel = pTop;
138877138941
pSubParse->zAuthContext = pTrigger->zName;
138878138942
pSubParse->eTriggerOp = pTrigger->op;
138879
- pSubParse->bReturning = pTrigger->bReturning;
138880138943
pSubParse->nQueryLoop = pParse->nQueryLoop;
138881138944
pSubParse->disableVtab = pParse->disableVtab;
138882138945
138883138946
v = sqlite3GetVdbe(pSubParse);
138884138947
if( v ){
@@ -138924,13 +138987,10 @@
138924138987
138925138988
transferParseError(pParse, pSubParse);
138926138989
if( db->mallocFailed==0 && pParse->nErr==0 ){
138927138990
pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
138928138991
}
138929
- if( pTrigger->bReturning ){
138930
- sqlite3VdbeColumnInfoXfer(sqlite3ParseToplevel(pParse)->pVdbe, v);
138931
- }
138932138992
pProgram->nMem = pSubParse->nMem;
138933138993
pProgram->nCsr = pSubParse->nTab;
138934138994
pProgram->token = (void *)pTrigger;
138935138995
pPrg->aColmask[0] = pSubParse->oldmask;
138936138996
pPrg->aColmask[1] = pSubParse->newmask;
@@ -139036,11 +139096,11 @@
139036139096
** reg+0 OLD.rowid
139037139097
** reg+1 OLD.* value of left-most column of pTab
139038139098
** ... ...
139039139099
** reg+N OLD.* value of right-most column of pTab
139040139100
** 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
139042139102
** ... ...
139043139103
** reg+N+N+1 NEW.* value of right-most column of pTab
139044139104
**
139045139105
** For ON DELETE triggers, the registers containing the NEW.* values will
139046139106
** never be accessed by the trigger program, so they are not allocated or
@@ -139089,16 +139149,16 @@
139089139149
** doing the UPDATE part of an UPSERT.
139090139150
*/
139091139151
if( (p->op==op || (p->bReturning && p->op==TK_INSERT && op==TK_UPDATE))
139092139152
&& p->tr_tm==tr_tm
139093139153
&& checkColumnOverlap(p->pColumns, pChanges)
139094
- && (sqlite3IsToplevel(pParse) || !p->bReturning)
139095139154
){
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
+ }
139100139160
}
139101139161
}
139102139162
}
139103139163
139104139164
/*
@@ -139139,17 +139199,22 @@
139139139199
u32 mask = 0;
139140139200
Trigger *p;
139141139201
139142139202
assert( isNew==1 || isNew==0 );
139143139203
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)
139145139206
&& checkColumnOverlap(p->pColumns,pChanges)
139146139207
){
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
+ }
139151139216
}
139152139217
}
139153139218
}
139154139219
139155139220
return mask;
@@ -142036,11 +142101,11 @@
142036142101
){
142037142102
if( !pTab->aCol ){
142038142103
Table *pNew = sParse.pNewTable;
142039142104
Index *pIdx;
142040142105
pTab->aCol = pNew->aCol;
142041
- pTab->nCol = pNew->nCol;
142106
+ pTab->nNVCol = pTab->nCol = pNew->nCol;
142042142107
pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid);
142043142108
pNew->nCol = 0;
142044142109
pNew->aCol = 0;
142045142110
assert( pTab->pIndex==0 );
142046142111
assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 );
@@ -228415,11 +228480,11 @@
228415228480
int nArg, /* Number of args */
228416228481
sqlite3_value **apUnused /* Function arguments */
228417228482
){
228418228483
assert( nArg==0 );
228419228484
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);
228421228486
}
228422228487
228423228488
/*
228424228489
** Return true if zName is the extension on one of the shadow tables used
228425228490
** by this module.
@@ -233341,12 +233406,12 @@
233341233406
}
233342233407
#endif /* SQLITE_CORE */
233343233408
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
233344233409
233345233410
/************** End of stmt.c ************************************************/
233346
-#if __LINE__!=233346
233411
+#if __LINE__!=233411
233347233412
#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"
233349233414
#endif
233350233415
/* Return the source-id for this library */
233351233416
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
233352233417
/************************** End of sqlite3.c ******************************/
233353233418
--- 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 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.35.0"
127127
#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"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button