Fossil SCM

Update the built-in SQLite to the latest 3.54.0 beta, for testing.

drh 2026-10-05 14:36 UTC trunk
Commit e6e6a32c2c3cdcf16bcf6c65da9b1f34971303111cb33f47f0be46053966939f
+7 -7
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -3806,10 +3806,13 @@
38063806
if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
38073807
if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
38083808
if( p->spec.eTitle>QRF_TEXT_Relaxed ) p->spec.eTitle = QRF_Auto;
38093809
if( p->spec.eBlob>QRF_BLOB_Size ) p->spec.eBlob = QRF_Auto;
38103810
qrf_reinit:
3811
+ if( p->spec.zFpFmt && sqlite3_qrf_ckformat(p->spec.zFpFmt)!=2 ){
3812
+ p->spec.zFpFmt = 0;
3813
+ }
38113814
switch( p->spec.eStyle ){
38123815
case QRF_Auto: {
38133816
switch( sqlite3_stmt_isexplain(pStmt) ){
38143817
case 0: p->spec.eStyle = QRF_STYLE_Box; break;
38153818
case 1: p->spec.eStyle = QRF_STYLE_Explain; break;
@@ -3824,10 +3827,11 @@
38243827
}
38253828
case QRF_STYLE_JObject:
38263829
case QRF_STYLE_Json: {
38273830
p->spec.eText = QRF_TEXT_Json;
38283831
p->spec.zNull = "null";
3832
+ if( p->spec.zFpFmt==0 ) p->spec.zFpFmt = "%0.16g";
38293833
break;
38303834
}
38313835
case QRF_STYLE_Html: {
38323836
p->spec.eText = QRF_TEXT_Html;
38333837
p->spec.zNull = "null";
@@ -3837,10 +3841,11 @@
38373841
p->spec.eText = QRF_TEXT_Sql;
38383842
p->spec.zNull = "NULL";
38393843
if( p->spec.zTableName==0 || p->spec.zTableName[0]==0 ){
38403844
p->spec.zTableName = "tab";
38413845
}
3846
+ if( p->spec.zFpFmt==0 ) p->spec.zFpFmt = "%0.16g";
38423847
p->u.nIns = 0;
38433848
break;
38443849
}
38453850
case QRF_STYLE_Line: {
38463851
if( p->spec.zColumnSep==0 ){
@@ -3941,13 +3946,10 @@
39413946
p->zFmt[n] = 'l';
39423947
p->zFmt[n+1] = p->spec.zIFmt[n-1];
39433948
p->zFmt[n+2] = 0;
39443949
p->spec.zIFmt = p->zFmt;
39453950
}
3946
- if( p->spec.zFpFmt && sqlite3_qrf_ckformat(p->spec.zFpFmt)!=2 ){
3947
- p->spec.zFpFmt = 0;
3948
- }
39493951
}
39503952
39513953
/*
39523954
** Finish rendering the results
39533955
*/
@@ -25993,14 +25995,12 @@
2599325995
if( !mOff ){
2599425996
sqlite3_int64 R = zPrior ? sqlite3_incomplete(zPrior) : 0;
2599525997
int cc = (R>>16)&0xff;
2599625998
int nParen = R>>32;
2599725999
int eSemi = (R>>8)&0xff;
25998
- if( cc==0 ){
26000
+ if( cc==0 || cc=='-' ){
2599926001
/* no-op */
26000
- }else if( cc=='-' ){
26001
- sqlite3_str_append(pOut,"\\n",3);
2600226002
}else if( cc=='/' ){
2600326003
sqlite3_str_append(pOut,"*/",2);
2600426004
}else{
2600526005
sqlite3_str_appendchar(pOut, 1, cc);
2600626006
}
@@ -33301,11 +33301,11 @@
3330133301
while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
3330233302
}
3330333303
import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
3330433304
if( sqlite3_table_column_metadata(p->db, zSchema, zTable,0,0,0,0,0,0)
3330533305
&& 0==db_int(p->db, "SELECT count(*) FROM \"%w\".sqlite_schema"
33306
- " WHERE name=%Q AND type='view'",
33306
+ " WHERE name=%Q COLLATE nocase AND type='view'",
3330733307
zSchema ? zSchema : "main", zTable)
3330833308
){
3330933309
/* Table does not exist. Create it. */
3331033310
sqlite3 *dbCols = 0;
3331133311
char *zRenames = 0;
3331233312
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -3806,10 +3806,13 @@
3806 if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
3807 if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
3808 if( p->spec.eTitle>QRF_TEXT_Relaxed ) p->spec.eTitle = QRF_Auto;
3809 if( p->spec.eBlob>QRF_BLOB_Size ) p->spec.eBlob = QRF_Auto;
3810 qrf_reinit:
 
 
 
3811 switch( p->spec.eStyle ){
3812 case QRF_Auto: {
3813 switch( sqlite3_stmt_isexplain(pStmt) ){
3814 case 0: p->spec.eStyle = QRF_STYLE_Box; break;
3815 case 1: p->spec.eStyle = QRF_STYLE_Explain; break;
@@ -3824,10 +3827,11 @@
3824 }
3825 case QRF_STYLE_JObject:
3826 case QRF_STYLE_Json: {
3827 p->spec.eText = QRF_TEXT_Json;
3828 p->spec.zNull = "null";
 
3829 break;
3830 }
3831 case QRF_STYLE_Html: {
3832 p->spec.eText = QRF_TEXT_Html;
3833 p->spec.zNull = "null";
@@ -3837,10 +3841,11 @@
3837 p->spec.eText = QRF_TEXT_Sql;
3838 p->spec.zNull = "NULL";
3839 if( p->spec.zTableName==0 || p->spec.zTableName[0]==0 ){
3840 p->spec.zTableName = "tab";
3841 }
 
3842 p->u.nIns = 0;
3843 break;
3844 }
3845 case QRF_STYLE_Line: {
3846 if( p->spec.zColumnSep==0 ){
@@ -3941,13 +3946,10 @@
3941 p->zFmt[n] = 'l';
3942 p->zFmt[n+1] = p->spec.zIFmt[n-1];
3943 p->zFmt[n+2] = 0;
3944 p->spec.zIFmt = p->zFmt;
3945 }
3946 if( p->spec.zFpFmt && sqlite3_qrf_ckformat(p->spec.zFpFmt)!=2 ){
3947 p->spec.zFpFmt = 0;
3948 }
3949 }
3950
3951 /*
3952 ** Finish rendering the results
3953 */
@@ -25993,14 +25995,12 @@
25993 if( !mOff ){
25994 sqlite3_int64 R = zPrior ? sqlite3_incomplete(zPrior) : 0;
25995 int cc = (R>>16)&0xff;
25996 int nParen = R>>32;
25997 int eSemi = (R>>8)&0xff;
25998 if( cc==0 ){
25999 /* no-op */
26000 }else if( cc=='-' ){
26001 sqlite3_str_append(pOut,"\\n",3);
26002 }else if( cc=='/' ){
26003 sqlite3_str_append(pOut,"*/",2);
26004 }else{
26005 sqlite3_str_appendchar(pOut, 1, cc);
26006 }
@@ -33301,11 +33301,11 @@
33301 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
33302 }
33303 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
33304 if( sqlite3_table_column_metadata(p->db, zSchema, zTable,0,0,0,0,0,0)
33305 && 0==db_int(p->db, "SELECT count(*) FROM \"%w\".sqlite_schema"
33306 " WHERE name=%Q AND type='view'",
33307 zSchema ? zSchema : "main", zTable)
33308 ){
33309 /* Table does not exist. Create it. */
33310 sqlite3 *dbCols = 0;
33311 char *zRenames = 0;
33312
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -3806,10 +3806,13 @@
3806 if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
3807 if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
3808 if( p->spec.eTitle>QRF_TEXT_Relaxed ) p->spec.eTitle = QRF_Auto;
3809 if( p->spec.eBlob>QRF_BLOB_Size ) p->spec.eBlob = QRF_Auto;
3810 qrf_reinit:
3811 if( p->spec.zFpFmt && sqlite3_qrf_ckformat(p->spec.zFpFmt)!=2 ){
3812 p->spec.zFpFmt = 0;
3813 }
3814 switch( p->spec.eStyle ){
3815 case QRF_Auto: {
3816 switch( sqlite3_stmt_isexplain(pStmt) ){
3817 case 0: p->spec.eStyle = QRF_STYLE_Box; break;
3818 case 1: p->spec.eStyle = QRF_STYLE_Explain; break;
@@ -3824,10 +3827,11 @@
3827 }
3828 case QRF_STYLE_JObject:
3829 case QRF_STYLE_Json: {
3830 p->spec.eText = QRF_TEXT_Json;
3831 p->spec.zNull = "null";
3832 if( p->spec.zFpFmt==0 ) p->spec.zFpFmt = "%0.16g";
3833 break;
3834 }
3835 case QRF_STYLE_Html: {
3836 p->spec.eText = QRF_TEXT_Html;
3837 p->spec.zNull = "null";
@@ -3837,10 +3841,11 @@
3841 p->spec.eText = QRF_TEXT_Sql;
3842 p->spec.zNull = "NULL";
3843 if( p->spec.zTableName==0 || p->spec.zTableName[0]==0 ){
3844 p->spec.zTableName = "tab";
3845 }
3846 if( p->spec.zFpFmt==0 ) p->spec.zFpFmt = "%0.16g";
3847 p->u.nIns = 0;
3848 break;
3849 }
3850 case QRF_STYLE_Line: {
3851 if( p->spec.zColumnSep==0 ){
@@ -3941,13 +3946,10 @@
3946 p->zFmt[n] = 'l';
3947 p->zFmt[n+1] = p->spec.zIFmt[n-1];
3948 p->zFmt[n+2] = 0;
3949 p->spec.zIFmt = p->zFmt;
3950 }
 
 
 
3951 }
3952
3953 /*
3954 ** Finish rendering the results
3955 */
@@ -25993,14 +25995,12 @@
25995 if( !mOff ){
25996 sqlite3_int64 R = zPrior ? sqlite3_incomplete(zPrior) : 0;
25997 int cc = (R>>16)&0xff;
25998 int nParen = R>>32;
25999 int eSemi = (R>>8)&0xff;
26000 if( cc==0 || cc=='-' ){
26001 /* no-op */
 
 
26002 }else if( cc=='/' ){
26003 sqlite3_str_append(pOut,"*/",2);
26004 }else{
26005 sqlite3_str_appendchar(pOut, 1, cc);
26006 }
@@ -33301,11 +33301,11 @@
33301 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
33302 }
33303 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
33304 if( sqlite3_table_column_metadata(p->db, zSchema, zTable,0,0,0,0,0,0)
33305 && 0==db_int(p->db, "SELECT count(*) FROM \"%w\".sqlite_schema"
33306 " WHERE name=%Q COLLATE nocase AND type='view'",
33307 zSchema ? zSchema : "main", zTable)
33308 ){
33309 /* Table does not exist. Create it. */
33310 sqlite3 *dbCols = 0;
33311 char *zRenames = 0;
33312
+357 -184
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 92709f54d4c58cf174f305b58971a01878af with changes in files:
21
+** 4bfc6e53a95d710b7f40fa9c80d8cdd1df50 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.54.0"
471471
#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c"
472
+#define SQLITE_SOURCE_ID "2026-10-05 14:22:13 4bfc6e53a95d710b7f40fa9c80d8cdd1df50d69ed8614e9800f7e6a1ca5a3c29"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-10-01T11:21:02.802Z"
475
+#define SQLITE_SCM_DATETIME "2026-10-05T14:22:13.597Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -782,11 +782,11 @@
782782
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
783783
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
784784
#define SQLITE_FULL 13 /* Insertion failed because database is full */
785785
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
786786
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
787
-#define SQLITE_EMPTY 16 /* Internal use only */
787
+#define SQLITE_EMPTY 16 /* No content */
788788
#define SQLITE_SCHEMA 17 /* The database schema changed */
789789
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
790790
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
791791
#define SQLITE_MISMATCH 20 /* Data type mismatch */
792792
#define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -3294,14 +3294,18 @@
32943294
** ^The sqlite3_complete(X) and sqlite3_complete16(X) routines return 0
32953295
** if the statement is incomplete. ^If a memory allocation fails, then
32963296
** SQLITE_NOMEM is returned.
32973297
**
32983298
** The [sqlite3_incomplete(X)] routine is similar to [sqlite3_complete(X)]
3299
-** except that sqlite3_incomplete(X) returns 0 if the input X is complete
3300
-** and non-zero if X is incomplete. The non-zero return from
3299
+** except that sqlite3_incomplete(X) returns SQLITE_OK if the input X is
3300
+** complete, SQLITE_EMPTY if input X consists entirely of whitespace and/or
3301
+** comments, SQLITE_MISUSE if X is a NULL pointer, and some other non-zero
3302
+** value if X is incomplete. The non-zero return from
33013303
** sqlite3_incomplete(X) contains additional information about what is
3302
-** needed to complete the input X. The sqlite3_incomplete(X) interface
3304
+** needed to complete the input X. See the header comment on the
3305
+** implemenation of the sqlite3_incomplete() routine for a full description
3306
+** of its non-zero return values. The sqlite3_incomplete(X) interface
33033307
** is only available for UTF-8 text.
33043308
**
33053309
** ^None of these routines do a full parse the SQL statements and thus
33063310
** will not detect syntactically incorrect SQL. They only determine if
33073311
** input text has properly terminated comments, string literals, and
@@ -22669,12 +22673,12 @@
2266922673
SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
2267022674
SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8);
2267122675
SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr);
2267222676
SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr);
2267322677
SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*);
22674
-SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(const Parse *pParse, Expr*, const Token*, int);
22675
-SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(const Parse*,Expr*,const char*);
22678
+SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int);
22679
+SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);
2267622680
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*);
2267722681
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr*);
2267822682
SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
2267922683
SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3*);
2268022684
SQLITE_PRIVATE int sqlite3CheckObjectName(Parse*, const char*,const char*,const char*);
@@ -22912,14 +22916,16 @@
2291222916
SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db);
2291322917
#ifndef SQLITE_OMIT_VIRTUALTABLE
2291422918
SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName);
2291522919
SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*);
2291622920
SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3*, Table*);
22921
+SQLITE_PRIVATE void sqlite3VtabEponymousTableClearAll(sqlite3*);
2291722922
#else
2291822923
# define sqlite3ShadowTableName(A,B) 0
2291922924
# define sqlite3IsShadowTableOf(A,B,C) 0
2292022925
# define sqlite3MarkAllShadowTablesOf(A,B)
22926
+# define sqlite3VtabEponymousTableClearAll(X)
2292122927
#endif
2292222928
SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
2292322929
SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
2292422930
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
2292522931
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -88204,10 +88210,11 @@
8820488210
|| opcode==OP_VCreate
8820588211
|| opcode==OP_ParseSchema
8820688212
|| opcode==OP_Function || opcode==OP_PureFunc
8820788213
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
8820888214
&& ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
88215
+ || (opcode==OP_MustBeInt && pOp->p2==0)
8820988216
){
8821088217
hasAbort = 1;
8821188218
break;
8821288219
}
8821388220
if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
@@ -95696,10 +95703,15 @@
9569695703
pMem = &pUnpack->aMem[iStore];
9569795704
if( iIdx==p->pTab->iPKey ){
9569895705
sqlite3VdbeMemSetInt64(pMem, p->iKey2);
9569995706
}else if( iStore>=pUnpack->nField ){
9570095707
pMem = (sqlite3_value *)columnNullValue();
95708
+ }else if( (p->pTab->aCol)
95709
+ && (p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL)
95710
+ && (pMem->flags & (MEM_Int|MEM_IntReal))
95711
+ ){
95712
+ sqlite3VdbeMemRealify(pMem);
9570195713
}
9570295714
}else{
9570395715
/* For an UPDATE, memory cell (p->iNewReg+1+iStore) contains the required
9570495716
** value. Make a copy of the cell contents and return a pointer to it.
9570595717
** It is not safe to return a pointer to the memory cell itself as the
@@ -112968,27 +112980,33 @@
112968112980
**
112969112981
** If a memory allocation error occurs, that fact is recorded in pParse->db
112970112982
** and the pExpr parameter is returned unchanged.
112971112983
*/
112972112984
SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(
112973
- const Parse *pParse, /* Parsing context */
112985
+ Parse *pParse, /* Parsing context */
112974112986
Expr *pExpr, /* Add the "COLLATE" clause to this expression */
112975112987
const Token *pCollName, /* Name of collating sequence */
112976112988
int dequote /* True to dequote pCollName */
112977112989
){
112978
- if( pCollName->n>0 ){
112990
+ if( pCollName->n>0 && pParse->nErr==0 ){
112979112991
Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
112992
+ assert( pExpr!=0 );
112980112993
if( pNew ){
112981112994
pNew->pLeft = pExpr;
112982112995
pNew->flags |= EP_Collate|EP_Skip;
112996
+#if SQLITE_MAX_EXPR_DEPTH>0
112997
+ pNew->nHeight = pExpr->nHeight+1;
112998
+ sqlite3ExprCheckHeight(pParse, pNew->nHeight);
112999
+ testcase( pParse->nErr>0 );
113000
+#endif
112983113001
pExpr = pNew;
112984113002
}
112985113003
}
112986113004
return pExpr;
112987113005
}
112988113006
SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(
112989
- const Parse *pParse, /* Parsing context */
113007
+ Parse *pParse, /* Parsing context */
112990113008
Expr *pExpr, /* Add the "COLLATE" clause to this expression */
112991113009
const char *zC /* The collating sequence name */
112992113010
){
112993113011
Token s;
112994113012
assert( zC!=0 );
@@ -123703,11 +123721,11 @@
123703123721
}
123704123722
123705123723
/* Search for a constraint violation. Throw an exception if one is found. */
123706123724
sqlite3NestedParse(pParse,
123707123725
"SELECT sqlite_fail('constraint failed', %d) "
123708
- "FROM %Q.%Q WHERE (%.*s) IS NOT TRUE",
123726
+ "FROM %Q.%Q WHERE (%.*s) IS FALSE",
123709123727
SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, zExpr
123710123728
);
123711123729
123712123730
/* Edit the SQL for the named table. */
123713123731
pCons = pFirst->z;
@@ -125888,10 +125906,15 @@
125888125906
** Close the old db and update the aDb[] slot with the new memdb
125889125907
** values. */
125890125908
sqlite3BtreeClose(pNew->pBt);
125891125909
pNew->pBt = pNewBt;
125892125910
pNew->pSchema = pNewSchema;
125911
+ if( db->init.iDb==0 ){
125912
+ /* Clear all eponymous virtual table instances, as they are holding
125913
+ ** pointers to the schema object just freed by sqlite3BtreeClose() */
125914
+ sqlite3VtabEponymousTableClearAll(db);
125915
+ }
125893125916
}else{
125894125917
sqlite3BtreeClose(pNewBt);
125895125918
rc = SQLITE_NOMEM;
125896125919
}
125897125920
}
@@ -140684,10 +140707,11 @@
140684140707
}
140685140708
addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
140686140709
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
140687140710
sqlite3VdbeJumpHere(v, addr1);
140688140711
sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
140712
+ sqlite3MayAbort(pParse);
140689140713
}
140690140714
140691140715
/* Copy the new data already generated. */
140692140716
assert( pTab->nNVCol>0 || pParse->nErr>0 );
140693140717
sqlite3VdbeAddOp3(v, OP_Copy, regRowid+1, regCols+1, pTab->nNVCol-1);
@@ -140752,10 +140776,11 @@
140752140776
}else{
140753140777
addr1 = sqlite3VdbeCurrentAddr(v);
140754140778
sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, addr1+2); VdbeCoverage(v);
140755140779
}
140756140780
sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
140781
+ sqlite3MayAbort(pParse);
140757140782
}
140758140783
}else if( IsVirtual(pTab) || withoutRowid ){
140759140784
sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
140760140785
}else{
140761140786
sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -147862,13 +147887,14 @@
147862147887
** if one is set. If no busy handler or a different busy handler is set
147863147888
** then 0 is returned. Setting the busy_timeout to 0 or negative
147864147889
** disables the timeout.
147865147890
*/
147866147891
/*case PragTyp_BUSY_TIMEOUT*/ default: {
147892
+ int n = 0;
147867147893
assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
147868
- if( zRight ){
147869
- sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
147894
+ if( zRight && sqlite3GetInt32(zRight,&n) ){
147895
+ sqlite3_busy_timeout(db, n);
147870147896
}
147871147897
returnSingleInt(v, db->busyTimeout);
147872147898
break;
147873147899
}
147874147900
@@ -148450,10 +148476,11 @@
148450148476
** schema.
148451148477
*/
148452148478
int rc;
148453148479
u8 saved_iDb = db->init.iDb;
148454148480
sqlite3_stmt *pStmt;
148481
+ const char *zEnd;
148455148482
TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
148456148483
148457148484
assert( db->init.busy );
148458148485
db->init.iDb = iDb;
148459148486
if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
@@ -148464,11 +148491,11 @@
148464148491
}
148465148492
}
148466148493
db->init.orphanTrigger = 0;
148467148494
db->init.azInit = (const char**)argv;
148468148495
pStmt = 0;
148469
- TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
148496
+ TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, &zEnd);
148470148497
rc = db->errCode;
148471148498
assert( (rc&0xFF)==(rcp&0xFF) );
148472148499
db->init.iDb = saved_iDb;
148473148500
/* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
148474148501
if( SQLITE_OK!=rc ){
@@ -148480,10 +148507,12 @@
148480148507
sqlite3OomFault(db);
148481148508
}else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
148482148509
corruptSchema(pData, argv, sqlite3_errmsg(db));
148483148510
}
148484148511
}
148512
+ }else if( zEnd[0] ){
148513
+ corruptSchema(pData, argv, 0);
148485148514
}
148486148515
db->init.azInit = sqlite3StdType; /* Any array of string ptrs will do */
148487148516
sqlite3_finalize(pStmt);
148488148517
}else if( argv[1]==0 || (argv[4]!=0 && argv[4][0]!=0) ){
148489148518
corruptSchema(pData, argv, 0);
@@ -151924,10 +151953,24 @@
151924151953
sqlite3ColumnSetColl(db, pCol, pColl->zName);
151925151954
}
151926151955
}
151927151956
pTab->szTabRow = 1; /* Any non-zero value works */
151928151957
}
151958
+
151959
+/*
151960
+** Check the current subquery nesting depth. Return true and set an
151961
+** error if it has gone too deep.
151962
+*/
151963
+static int checkSubqueryNestingDepth(Parse *pParse){
151964
+#if SQLITE_MAX_EXPR_DEPTH>0
151965
+ if( pParse->nNestSel >= pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){
151966
+ sqlite3ErrorMsg(pParse, "VIEWs and/or subqueries nested too deep");
151967
+ return 1;
151968
+ }
151969
+#endif
151970
+ return 0;
151971
+}
151929151972
151930151973
/*
151931151974
** Given a SELECT statement, generate a Table structure that describes
151932151975
** the result set of that SELECT.
151933151976
*/
@@ -151935,16 +151978,11 @@
151935151978
Table *pTab;
151936151979
sqlite3 *db = pParse->db;
151937151980
u64 savedFlags;
151938151981
151939151982
pParse->nNestSel++;
151940
-#if SQLITE_MAX_EXPR_DEPTH>0
151941
- if( pParse->nNestSel >= db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){
151942
- sqlite3ErrorMsg(pParse, "VIEWs and/or subqueries nested too deep");
151943
- return 0;
151944
- }
151945
-#endif
151983
+ if( checkSubqueryNestingDepth(pParse) ) return 0;
151946151984
savedFlags = db->flags;
151947151985
db->flags &= ~(u64)SQLITE_FullColNames;
151948151986
db->flags |= SQLITE_ShortColNames;
151949151987
sqlite3SelectPrep(pParse, pSelect, 0);
151950151988
db->flags = savedFlags;
@@ -152039,17 +152077,19 @@
152039152077
}
152040152078
}else{
152041152079
sqlite3ExprCode(pParse, pLimit->pLeft, iLimit);
152042152080
sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
152043152081
VdbeComment((v, "LIMIT counter"));
152082
+ sqlite3MayAbort(pParse);
152044152083
sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
152045152084
}
152046152085
if( pLimit->pRight ){
152047152086
p->iOffset = iOffset = ++pParse->nMem;
152048152087
pParse->nMem++; /* Allocate an extra register for limit+offset */
152049152088
sqlite3ExprCode(pParse, pLimit->pRight, iOffset);
152050152089
sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
152090
+ sqlite3MayAbort(pParse);
152051152091
VdbeComment((v, "OFFSET counter"));
152052152092
sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset);
152053152093
VdbeComment((v, "LIMIT+OFFSET"));
152054152094
}
152055152095
}
@@ -155187,18 +155227,17 @@
155187155227
}
155188155228
return pWith;
155189155229
}
155190155230
155191155231
/*
155192
-** This function checks if argument pFrom refers to a CTE declared by
155232
+** This function checks to see if argument pFrom refers to a CTE declared by
155193155233
** a WITH clause on the stack currently maintained by the parser (on the
155194
-** pParse->pWith linked list). And if currently processing a CTE
155195
-** CTE expression, through routine checks to see if the reference is
155196
-** a recursive reference to the CTE.
155234
+** pParse->pWith linked list). And if currently processing a CTE expression,
155235
+** it also checks to see if the reference is a recursive reference to the CTE.
155197155236
**
155198
-** If pFrom matches a CTE according to either of these two above, pFrom->pSTab
155199
-** and other fields are populated accordingly.
155237
+** If pFrom matches a CTE, pFrom->pSTab and other fields are populated
155238
+** accordingly.
155200155239
**
155201155240
** Return 0 if no match is found.
155202155241
** Return 1 if a match is found.
155203155242
** Return 2 if an error condition is detected.
155204155243
*/
@@ -155323,10 +155362,22 @@
155323155362
}
155324155363
if( (pRecTerm->selFlags & SF_Recursive)==0 ) break;
155325155364
pRecTerm = pRecTerm->pPrior;
155326155365
}
155327155366
155367
+#if SQLITE_MAX_EXPR_DEPTH>0
155368
+ if( pParse->nTab>=db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){
155369
+ /* Bug 2026-10-04T05:35:14Z: Prevent nested CTEs from generating
155370
+ ** an exponential number of cursors. The error message here will
155371
+ ** be "Nested too deep", which isn't exactly correct, but it is
155372
+ ** sufficient, and we don't want to use extra code space for more
155373
+ ** detail on such an obscure error. */
155374
+ pParse->nNestSel = pParse->nTab;
155375
+ }
155376
+ pParse->nNestSel++;
155377
+ if( checkSubqueryNestingDepth(pParse) ) return 2;
155378
+#endif
155328155379
pCte->zCteErr = "circular reference: %s";
155329155380
pSavedWith = pParse->pWith;
155330155381
pParse->pWith = pWith;
155331155382
if( pSel->selFlags & SF_Recursive ){
155332155383
int rc;
@@ -155347,10 +155398,14 @@
155347155398
pParse->pWith = pSavedWith;
155348155399
return 2;
155349155400
}
155350155401
}
155351155402
pParse->pWith = pWith;
155403
+#if SQLITE_MAX_EXPR_DEPTH>0
155404
+ pParse->nNestSel--;
155405
+ assert( pParse->nNestSel>=0 );
155406
+#endif
155352155407
155353155408
for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
155354155409
pEList = pLeft->pEList;
155355155410
if( pCte->pCols ){
155356155411
if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){
@@ -156722,10 +156777,14 @@
156722156777
sqlite3PExprAddSelect(pParse, pTerm, pSub);
156723156778
if( pExpr==0 ){
156724156779
pExpr = pTerm;
156725156780
}else{
156726156781
pExpr = sqlite3PExpr(pParse, TK_PLUS, pTerm, pExpr);
156782
+ }
156783
+ if( pParse->nErr ){
156784
+ sqlite3ExprDelete(db, pExpr);
156785
+ pExpr = 0;
156727156786
}
156728156787
pSub = pPrior;
156729156788
}
156730156789
p->pEList->a[0].pExpr = pExpr;
156731156790
p->selFlags &= ~(u32)SF_Aggregate;
@@ -161221,10 +161280,11 @@
161221161280
sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
161222161281
}else{
161223161282
sqlite3VdbeAddOp3(v, OP_Column, iEph, iRowidExpr, regNewRowid);
161224161283
}
161225161284
sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
161285
+ sqlite3MayAbort(pParse);
161226161286
}
161227161287
161228161288
/* Compute the old pre-UPDATE content of the row being changed, if that
161229161289
** information is needed */
161230161290
if( chngPk || hasFK || pTrigger ){
@@ -163769,10 +163829,21 @@
163769163829
pTab->tabFlags |= TF_Ephemeral;
163770163830
sqlite3DeleteTable(db, pTab);
163771163831
pMod->pEpoTab = 0;
163772163832
}
163773163833
}
163834
+
163835
+/*
163836
+** Erase all eponymous virtual table instances associated with database
163837
+** handle db.
163838
+*/
163839
+SQLITE_PRIVATE void sqlite3VtabEponymousTableClearAll(sqlite3 *db){
163840
+ HashElem *pElem;
163841
+ for(pElem=sqliteHashFirst(&db->aModule); pElem; pElem=sqliteHashNext(pElem)){
163842
+ sqlite3VtabEponymousTableClear(db, (Module*)sqliteHashData(pElem));
163843
+ }
163844
+}
163774163845
163775163846
/*
163776163847
** Return the ON CONFLICT resolution mode in effect for the virtual
163777163848
** table update operation currently in progress.
163778163849
**
@@ -187762,14 +187833,14 @@
187762187833
#endif
187763187834
187764187835
/*
187765187836
** Return zero if the given SQL string is complete - if all comments,
187766187837
** string and blob literals, and quoted identifiers have been closed and
187767
-** if the entire string ends with ";" and possible with ";END;" if the
187838
+** if the entire string ends with ";" and possibly with ";END;" if the
187768187839
** string is a CREATE TRIGGER statement. A non-zero return indicates
187769
-** that the string is incomplete. Bits of the return value indicate
187770
-** what is missing and is needed to close out the statement.
187840
+** that the string is empty or incomplete. Bits of the return value
187841
+** indicate what is missing and is needed to close out the statement.
187771187842
**
187772187843
** Special handling is require for CREATE TRIGGER statements.
187773187844
** Whenever the CREATE TRIGGER keywords are seen, the statement
187774187845
** must end with ";END;".
187775187846
**
@@ -187777,15 +187848,16 @@
187777187848
** subfields, at byte boundaries:
187778187849
**
187779187850
** R = 0xwwwwwwww00xxyyzz
187780187851
**
187781187852
** In other words, zz is the least significant byte, yy is the next
187782
-** most significant byte, xx is the third byte, wwwwwwww is a 32-bit
187783
-** value from the middle.
187853
+** most significant byte, xx is the third byte, wwwwwwww is the upper
187854
+** four bytes of the return value.
187784187855
**
187785187856
** zz == SQLITE_OK Input is complete
187786187857
** zz == SQLITE_ERROR Input is incomplete
187858
+** zz == SQLITE_EMPTY Input contains only whitespace
187787187859
** zz == SQLITE_MISUSE Input is a NULL pointer
187788187860
** zz != 0 New values for zz may be added in the future
187789187861
**
187790187862
** yy == 0x01 Need a semicolon at the end
187791187863
** yy == 0x02 Need "END" and a semicolon
@@ -187807,11 +187879,11 @@
187807187879
** ((R>>24)&0xff)!=0 New uses for the 4th byte may be added
187808187880
** in the future
187809187881
**
187810187882
** This implementation uses a state machine with 8 states:
187811187883
**
187812
-** (0) INVALID We have not yet seen a non-whitespace character.
187884
+** (0) NOTHING We have not yet seen a non-whitespace character.
187813187885
**
187814187886
** (1) START At the beginning or end of an SQL statement. This routine
187815187887
** returns 1 if it ends in the START state and 0 if it ends
187816187888
** in any other state.
187817187889
**
@@ -187864,11 +187936,11 @@
187864187936
** statement. This is the normal case.
187865187937
*/
187866187938
static const u8 trans[8][8] = {
187867187939
/* Token: */
187868187940
/* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
187869
- /* 0 INVALID: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
187941
+ /* 0 NOTHING: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
187870187942
/* 1 START: */ { 1, 1, 2, 3, 4, 2, 2, 2, },
187871187943
/* 2 NORMAL: */ { 1, 2, 2, 2, 2, 2, 2, 2, },
187872187944
/* 3 EXPLAIN: */ { 1, 3, 3, 2, 4, 2, 2, 2, },
187873187945
/* 4 CREATE: */ { 1, 4, 2, 2, 2, 4, 5, 2, },
187874187946
/* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, },
@@ -187880,18 +187952,18 @@
187880187952
** used to detect the end of a statement is much simpler
187881187953
*/
187882187954
static const u8 trans[3][3] = {
187883187955
/* Token: */
187884187956
/* State: ** SEMI WS OTHER */
187885
- /* 0 INVALID: */ { 1, 0, 2, },
187957
+ /* 0 NOTHING: */ { 1, 0, 2, },
187886187958
/* 1 START: */ { 1, 1, 2, },
187887187959
/* 2 NORMAL: */ { 1, 2, 2, },
187888187960
};
187889187961
#endif /* SQLITE_OMIT_TRIGGER */
187890187962
/* Mapping state number to yy value for the return */
187891187963
static const u8 statemap[8] = {
187892
- /* 0 INVALID */ 1,
187964
+ /* 0 NOTHING */ 0,
187893187965
/* 1 START */ 0,
187894187966
/* 2 NORMAL */ 1,
187895187967
/* 3 EXPLAIN */ 1,
187896187968
/* 4 CREATE */ 1,
187897187969
/* 5 TRIGGER */ 3,
@@ -187925,10 +187997,11 @@
187925187997
break;
187926187998
}
187927187999
zSql += 2;
187928188000
while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
187929188001
if( zSql[0]==0 ){
188002
+ if( state==0 ) state = 2;
187930188003
pending = '/';
187931188004
goto incomplete_finish;
187932188005
}
187933188006
zSql++;
187934188007
token = tkWS;
@@ -188042,10 +188115,11 @@
188042188115
}
188043188116
state = trans[state][token];
188044188117
zSql++;
188045188118
}
188046188119
incomplete_finish:
188120
+ if( state==0 ) return SQLITE_EMPTY;
188047188121
if( state==1 ) nParen = 0;
188048188122
return (i64)((((u64)nParen)<<32) |
188049188123
((u64)pending<<16) |
188050188124
((u64)statemap[state]<<8) |
188051188125
(state!=1));
@@ -210496,10 +210570,11 @@
210496210570
SQLITE_PRIVATE int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk){
210497210571
int rc = SQLITE_OK; /* Return code */
210498210572
u64 cksum1 = 0; /* Checksum based on FTS index contents */
210499210573
u64 cksum2 = 0; /* Checksum based on %_content contents */
210500210574
sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
210575
+ int bContentless = (p->zContentTbl && p->zContentTbl[0]=='\0');
210501210576
210502210577
/* This block calculates the checksum according to the FTS index. */
210503210578
rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
210504210579
if( rc==SQLITE_OK ){
210505210580
int rc2;
@@ -210515,11 +210590,11 @@
210515210590
rc2 = sqlite3_reset(pAllLangid);
210516210591
if( rc==SQLITE_OK ) rc = rc2;
210517210592
}
210518210593
210519210594
/* This block calculates the checksum according to the %_content table */
210520
- if( rc==SQLITE_OK ){
210595
+ if( rc==SQLITE_OK && !bContentless ){
210521210596
sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
210522210597
sqlite3_stmt *pStmt = 0;
210523210598
char *zSql;
210524210599
210525210600
zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
@@ -210573,11 +210648,11 @@
210573210648
210574210649
if( rc==SQLITE_CORRUPT_VTAB ){
210575210650
rc = SQLITE_OK;
210576210651
*pbOk = 0;
210577210652
}else{
210578
- *pbOk = (rc==SQLITE_OK && cksum1==cksum2);
210653
+ *pbOk = (rc==SQLITE_OK && (bContentless || cksum1==cksum2));
210579210654
}
210580210655
return rc;
210581210656
}
210582210657
210583210658
/*
@@ -224142,11 +224217,11 @@
224142224217
continue;
224143224218
}
224144224219
break;
224145224220
}
224146224221
if( geopolySkipSpace(&s)==']'
224147
- && s.nVertex>=4
224222
+ && s.nVertex>=4 && s.nVertex<16777216
224148224223
&& s.a[0]==s.a[s.nVertex*2-2]
224149224224
&& s.a[1]==s.a[s.nVertex*2-1]
224150224225
&& (s.z++, geopolySkipSpace(&s)==0)
224151224226
){
224152224227
GeoPoly *pOut;
@@ -224479,11 +224554,11 @@
224479224554
sqlite3_value **argv
224480224555
){
224481224556
double x = sqlite3_value_double(argv[0]);
224482224557
double y = sqlite3_value_double(argv[1]);
224483224558
double r = sqlite3_value_double(argv[2]);
224484
- int n = sqlite3_value_int(argv[3]);
224559
+ i64 n = sqlite3_value_int64(argv[3]);
224485224560
int i;
224486224561
GeoPoly *p;
224487224562
(void)argc;
224488224563
224489224564
if( n<3 || r<=0.0 || r>=1e300 ) return;
@@ -237743,10 +237818,37 @@
237743237818
if( pzErrmsg && rc!=SQLITE_OK ){
237744237819
*pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
237745237820
}
237746237821
return rc;
237747237822
}
237823
+
237824
+/*
237825
+** Prepare the statement specified by printf format zFmt and its trailing
237826
+** arguments.
237827
+*/
237828
+static void sessionPrepareMprintf(
237829
+ int *pRc,
237830
+ sqlite3 *db,
237831
+ sqlite3_stmt **pp,
237832
+ char **pzErrmsg,
237833
+ const char *zFmt,
237834
+ ...
237835
+){
237836
+ if( *pRc==SQLITE_OK ){
237837
+ char *zSql;
237838
+ va_list ap;
237839
+ va_start(ap, zFmt);
237840
+ zSql = sqlite3_vmprintf(zFmt, ap);
237841
+ if( zSql==0 ){
237842
+ *pRc = SQLITE_NOMEM;
237843
+ }else{
237844
+ *pRc = sessionPrepare(db, pp, pzErrmsg, zSql);
237845
+ sqlite3_free(zSql);
237846
+ }
237847
+ va_end(ap);
237848
+ }
237849
+}
237748237850
237749237851
/*
237750237852
** Formulate and prepare a SELECT statement to retrieve a row from table
237751237853
** zTab in database zDb based on its primary key. i.e.
237752237854
**
@@ -240147,165 +240249,219 @@
240147240249
240148240250
return rc;
240149240251
}
240150240252
240151240253
/*
240152
-** Check if table zTab in the "main" database of db is a WITHOUT ROWID
240153
-** table.
240254
+** Buffer aUnique[] is pApply->nCol entries in size. This function sets
240255
+** aUnique[i] to true if column i of table zTab in the "main" database
240256
+** of db is part of at least one UNIQUE constraint, or to false otherwise.
240154240257
**
240155
-** If no error occurs, return SQLITE_OK and set output variable (*pbWR) to
240156
-** true if zTab is a WITHOUT ROWID table, or false otherwise. Or, if an
240157
-** error does occur, return an SQLite error code. The final value of (*pbWR)
240158
-** is undefined in this case.
240258
+** If the table has a unique index on an expression, or a partial unique
240259
+** index, all entries of aUnique[] are set to true.
240260
+**
240261
+** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
240159240262
*/
240160
-static int sessionTableIsWithoutRowid(sqlite3 *db, const char *zTab, int *pbWR){
240161
- sqlite3_stmt *pList = 0;
240162
- char *zSql = 0;
240263
+static int sessionUniqueColumns(
240264
+ sqlite3 *db, /* Database handle */
240265
+ const char *zTab, /* Table name */
240266
+ SessionApplyCtx *pApply, /* Apply context */
240267
+ u8 *aUnique /* OUT: Array of pApply->nCol flags */
240268
+){
240269
+ sqlite3_stmt *pList = 0; /* PRAGMA index_list */
240163240270
int rc = SQLITE_OK;
240164240271
240165
- zSql = sqlite3_mprintf("PRAGMA table_list = %Q", zTab);
240166
- if( zSql==0 ){
240167
- rc = SQLITE_NOMEM;
240168
- }else{
240169
- rc = sqlite3_prepare_v2(db, zSql, -1, &pList, 0);
240170
- sqlite3_free(zSql);
240171
- }
240172
-
240173
- if( rc==SQLITE_OK ){
240174
- sqlite3_step(pList);
240175
- *pbWR = sqlite3_column_int(pList, 4);
240272
+ /* Ordinary PRAGMA statements are used here instead of the equivalent
240273
+ ** table-valued functions (pragma_index_list() etc.) so that this works
240274
+ ** in builds with SQLITE_OMIT_VIRTUALTABLE defined. */
240275
+ memset(aUnique, 0, pApply->nCol);
240276
+ sessionPrepareMprintf(&rc, db, &pList, &pApply->zErr,
240277
+ "PRAGMA main.index_list(%Q)", zTab
240278
+ );
240279
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
240280
+ /* Columns of PRAGMA index_list are (seq, name, unique, origin, partial) */
240281
+ const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
240282
+ int bUnique = sqlite3_column_int(pList, 2);
240283
+ int bPartial = sqlite3_column_int(pList, 4);
240284
+ sqlite3_stmt *pInfo = 0; /* PRAGMA index_xinfo */
240285
+
240286
+ if( bUnique==0 ) continue;
240287
+ sessionPrepareMprintf(&rc, db, &pInfo, &pApply->zErr,
240288
+ "PRAGMA main.index_xinfo(%Q)", zIdx
240289
+ );
240290
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pInfo) ){
240291
+ /* Columns of PRAGMA index_xinfo are (seqno, cid, name, desc, coll, key)*/
240292
+ int iCid = sqlite3_column_int(pInfo, 1);
240293
+ const char *zCol = (const char*)sqlite3_column_text(pInfo, 2);
240294
+ int bKey = sqlite3_column_int(pInfo, 5);
240295
+ int ii;
240296
+ if( bKey==0 ) continue;
240297
+ for(ii=0; ii<pApply->nCol; ii++){
240298
+ if( bPartial
240299
+ || iCid==-2
240300
+ || (zCol && 0==sqlite3_stricmp(zCol, pApply->azCol[ii]))
240301
+ ){
240302
+ aUnique[ii] = 1;
240303
+ }
240304
+ }
240305
+ }
240306
+ if( rc==SQLITE_OK ){
240307
+ rc = sqlite3_finalize(pInfo);
240308
+ }else{
240309
+ sqlite3_finalize(pInfo);
240310
+ }
240311
+ }
240312
+ if( rc==SQLITE_OK ){
240176240313
rc = sqlite3_finalize(pList);
240314
+ }else{
240315
+ sqlite3_finalize(pList);
240177240316
}
240178240317
240179240318
return rc;
240180240319
}
240181240320
240182240321
/*
240183
-** Iterator pUp points to an UPDATE change. This function deletes the
240184
-** affected row from the database and creates an INSERT statement that
240185
-** may be used to reinsert the row as it is after the UPDATE change
240186
-** has been applied.
240322
+** Iterator pUp points to an UPDATE change. This function updates the
240323
+** affected row to set each column modified by the UPDATE change that
240324
+** is also part of at least one UNIQUE constraint to a "random" value,
240325
+** and creates another UPDATE statement that may be used to later set
240326
+** all columns modified by pUp to the actual values required by pUp.
240187240327
**
240188
-** If successful, SQLITE_OK is returned and output variable (*ppInsert)
240189
-** is left pointing to a prepared INSERT statement. It is the responsibility
240328
+** Each random value has the same type as the final value required by
240329
+** pUp for the same column:
240330
+**
240331
+** NULL -> NULL
240332
+** INTEGER -> random()
240333
+** REAL -> random()
240334
+** TEXT -> CAST(random() AS TEXT)
240335
+** BLOB -> unhex(hex(random()))
240336
+**
240337
+** If none of the columns modified by pUp are part of a UNIQUE constraint,
240338
+** then SQLITE_CONSTRAINT is returned.
240339
+**
240340
+** If successful, SQLITE_OK is returned and output variable (*ppUpdate)
240341
+** is left pointing to a prepared UPDATE statement. It is the responsibility
240190240342
** of the caller to eventually free this statement using sqlite3_finalize().
240191
-** Or, if an error occurs, an SQLite error code is returned and (*ppInsert)
240343
+** Or, if an error occurs, an SQLite error code is returned and (*ppUpdate)
240192240344
** set to NULL. pApply->zErr may be set to an error message in this case.
240345
+** Except - it is guaranteed that pApply->zErr is not set if SQLITE_CONSTRAINT
240346
+** is returned.
240193240347
*/
240194
-static int sessionUpdateToDeleteInsert(
240348
+static int sessionUpdateToUpdate(
240195240349
sqlite3 *db, /* Database to write to */
240196240350
const char *zTab, /* Table name */
240197240351
SessionApplyCtx *pApply, /* Apply context */
240198240352
sqlite3_changeset_iter *pUp, /* Iterator pointing to UPDATE change */
240199
- sqlite3_stmt **ppInsert /* OUT: INSERT statement */
240200
-){
240201
- sqlite3_stmt *pRet = 0; /* The INSERT statement */
240202
- sqlite3_stmt *pSelect = 0; /* SELECT to read current values of row */
240203
- int rc = SQLITE_OK;
240204
- int bWR = 0;
240205
-
240206
- rc = sessionTableIsWithoutRowid(db, zTab, &bWR);
240207
- if( rc==SQLITE_OK ){
240208
- char *zSelect = 0;
240209
- char *zInsert = 0;
240210
- SessionBuffer cols = {0, 0, 0};
240211
- SessionBuffer insbind = {0, 0, 0};
240212
- SessionBuffer pkcols = {0, 0, 0};
240213
- SessionBuffer selbind = {0, 0, 0};
240214
-
240215
- const char *zComma = "";
240216
- const char *zComma2 = "";
240217
- int ii;
240218
- for(ii=0; ii<pApply->nCol; ii++){
240219
- sessionAppendStr(&cols, zComma, &rc);
240220
- sessionAppendIdent(&cols, pApply->azCol[ii], &rc);
240221
- sessionAppendStr(&insbind, zComma, &rc);
240222
- sessionAppendStr(&insbind, "?", &rc);
240223
- zComma = ", ";
240224
-
240225
- if( pApply->abPK[ii] ){
240226
- sessionAppendStr(&pkcols, zComma2, &rc);
240227
- sessionAppendIdent(&pkcols, pApply->azCol[ii], &rc);
240228
- sessionAppendStr(&selbind, zComma2, &rc);
240229
- sessionAppendPrintf(&selbind, &rc, "?%d", ii+1);
240230
- zComma2 = ", ";
240231
- }
240232
- }
240233
- if( bWR==0 ){
240234
- sessionAppendStr(&cols, zComma, &rc);
240235
- sessionAppendStr(&cols, SESSIONS_ROWID, &rc);
240236
- sessionAppendStr(&insbind, zComma, &rc);
240237
- sessionAppendStr(&insbind, "?", &rc);
240238
- }
240239
-
240240
- if( rc==SQLITE_OK ){
240241
- zSelect = sqlite3_mprintf("SELECT %s FROM %Q WHERE (%s) IS (%s)",
240242
- cols.aBuf, zTab, pkcols.aBuf, selbind.aBuf
240243
- );
240244
- if( zSelect==0 ) rc = SQLITE_NOMEM;
240245
- }
240246
- if( rc==SQLITE_OK ){
240247
- zInsert = sqlite3_mprintf("INSERT INTO %Q(%s) VALUES(%s)",
240248
- zTab, cols.aBuf, insbind.aBuf
240249
- );
240250
- if( zInsert==0 ) rc = SQLITE_NOMEM;
240251
- }
240252
-
240253
- if( rc==SQLITE_OK ){
240254
- rc = sessionPrepare(db, &pSelect, &pApply->zErr, zSelect);
240255
- }
240256
- if( rc==SQLITE_OK ){
240257
- rc = sessionPrepare(db, &pRet, &pApply->zErr, zInsert);
240258
- }
240259
-
240260
- sqlite3_free(zSelect);
240261
- sqlite3_free(zInsert);
240262
- sqlite3_free(cols.aBuf);
240263
- sqlite3_free(insbind.aBuf);
240264
- sqlite3_free(pkcols.aBuf);
240265
- sqlite3_free(selbind.aBuf);
240266
- }
240267
-
240268
- if( rc==SQLITE_OK ){
240269
- rc = sessionBindRow(
240270
- pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pSelect
240271
- );
240272
- }
240273
-
240274
- if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){
240275
- int iCol;
240276
- for(iCol=0; iCol<pApply->nCol; iCol++){
240277
- sqlite3_value *pVal = pUp->apValue[iCol+pApply->nCol];
240278
- if( pVal==0 ){
240279
- pVal = sqlite3_column_value(pSelect, iCol);
240280
- }
240281
- rc = sqlite3_bind_value(pRet, iCol+1, pVal);
240282
- }
240283
- if( bWR==0 ){
240284
- sqlite3_bind_int64(pRet, iCol+1, sqlite3_column_int64(pSelect, iCol));
240285
- }
240286
- }
240287
- sessionFinalizeStmt(pSelect, &rc);
240288
-
240289
- /* Delete the row from the database. */
240290
- if( rc==SQLITE_OK ){
240291
- rc = sessionBindRow(
240292
- pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pApply->pDelete
240293
- );
240294
- sqlite3_bind_int(pApply->pDelete, pApply->nCol+1, 1);
240295
- }
240296
- if( rc==SQLITE_OK ){
240297
- sqlite3_step(pApply->pDelete);
240298
- rc = sqlite3_reset(pApply->pDelete);
240299
- }
240353
+ sqlite3_stmt **ppUpdate /* OUT: UPDATE statement */
240354
+){
240355
+ sqlite3_stmt *pRet = 0; /* UPDATE to set the final values */
240356
+ sqlite3_stmt *pRand = 0; /* UPDATE to set random values */
240357
+ int rc = SQLITE_OK;
240358
+ u8 *aUnique = 0; /* aUnique[i] true if col i is UNIQUE */
240359
+ SessionBuffer randset = {0, 0, 0};
240360
+ SessionBuffer upset = {0, 0, 0};
240361
+ SessionBuffer where = {0, 0, 0};
240362
+ int ii;
240363
+
240364
+ aUnique = (u8*)sqlite3_malloc64(pApply->nCol);
240365
+ if( aUnique==0 ){
240366
+ rc = SQLITE_NOMEM;
240367
+ }else{
240368
+ rc = sessionUniqueColumns(db, zTab, pApply, aUnique);
240369
+ }
240370
+
240371
+ /* Assuming a table structure like this:
240372
+ **
240373
+ ** CREATE TABLE x(a, b UNIQUE, c, d UNIQUE, e, PRIMARY KEY(a, c));
240374
+ **
240375
+ ** and an UPDATE change that sets column b to an integer, column d to
240376
+ ** a text value and column e to any value, the two statements prepared
240377
+ ** are:
240378
+ **
240379
+ ** UPDATE main.x SET b = random(), d = CAST(random() AS TEXT)
240380
+ ** WHERE a IS ?1 AND c IS ?3
240381
+ ** UPDATE main.x SET b = ?2, d = ?4, e = ?5 WHERE a IS ?1 AND c IS ?3
240382
+ */
240383
+ for(ii=0; rc==SQLITE_OK && ii<pApply->nCol; ii++){
240384
+ sqlite3_value *pNew = 0;
240385
+ if( pApply->abPK[ii] ){
240386
+ if( where.nBuf>0 ) sessionAppendStr(&where, " AND ", &rc);
240387
+ sessionAppendIdent(&where, pApply->azCol[ii], &rc);
240388
+ sessionAppendPrintf(&where, &rc, " IS ?%d", ii+1);
240389
+ }else if( (pNew = sessionChangesetNew(pUp, ii))!=0 ){
240390
+ if( aUnique[ii] ){
240391
+ const char *zRand = 0;
240392
+ switch( sqlite3_value_type(pNew) ){
240393
+ case SQLITE_NULL: zRand = "NULL"; break;
240394
+ case SQLITE_TEXT: zRand = "CAST(random() AS TEXT)"; break;
240395
+ case SQLITE_BLOB: zRand = "unhex(hex(random()))"; break;
240396
+ default: zRand = "random()"; break;
240397
+ }
240398
+ if( randset.nBuf>0 ) sessionAppendStr(&randset, ", ", &rc);
240399
+ sessionAppendIdent(&randset, pApply->azCol[ii], &rc);
240400
+ sessionAppendStr(&randset, " = ", &rc);
240401
+ sessionAppendStr(&randset, zRand, &rc);
240402
+ }
240403
+ if( upset.nBuf>0 ) sessionAppendStr(&upset, ", ", &rc);
240404
+ sessionAppendIdent(&upset, pApply->azCol[ii], &rc);
240405
+ sessionAppendPrintf(&upset, &rc, " = ?%d", ii+1);
240406
+ }
240407
+ }
240408
+
240409
+ if( rc==SQLITE_OK && randset.nBuf==0 ){
240410
+ /* None of the columns modified by this change are part of a UNIQUE
240411
+ ** constraint. So setting them to random values cannot help resolve
240412
+ ** a constraint conflict. Report this as a constraint failure. */
240413
+ rc = SQLITE_CONSTRAINT;
240414
+ }
240415
+
240416
+ sessionPrepareMprintf(&rc, db, &pRand, &pApply->zErr,
240417
+ "UPDATE main.\"%w\" SET %s WHERE %s",
240418
+ zTab, (char*)randset.aBuf, (char*)where.aBuf
240419
+ );
240420
+ sessionPrepareMprintf(&rc, db, &pRet, &pApply->zErr,
240421
+ "UPDATE main.\"%w\" SET %s WHERE %s",
240422
+ zTab, (char*)upset.aBuf, (char*)where.aBuf
240423
+ );
240424
+
240425
+ /* Bind the PK values to both statements, and the new.* values to pRet. */
240426
+ if( rc==SQLITE_OK ){
240427
+ rc = sessionBindRow(
240428
+ pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pRand
240429
+ );
240430
+ }
240431
+ if( rc==SQLITE_OK ){
240432
+ rc = sessionBindRow(
240433
+ pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pRet
240434
+ );
240435
+ }
240436
+ for(ii=0; rc==SQLITE_OK && ii<pApply->nCol; ii++){
240437
+ sqlite3_value *pNew = sessionChangesetNew(pUp, ii);
240438
+ if( pApply->abPK[ii]==0 && pNew ){
240439
+ rc = sessionBindValue(pRet, ii+1, pNew);
240440
+ }
240441
+ }
240442
+
240443
+ /* Evaluate the statement to set each modified column of the row to a random
240444
+ ** value. If this fails with a constraint error, SQLITE_CONSTRAINT is
240445
+ ** returned to the caller, but pApply->zErr is not set. */
240446
+ if( rc==SQLITE_OK ){
240447
+ sqlite3_step(pRand);
240448
+ rc = sqlite3_reset(pRand);
240449
+ }
240450
+ sqlite3_finalize(pRand);
240300240451
240301240452
if( rc!=SQLITE_OK ){
240302240453
sqlite3_finalize(pRet);
240303240454
pRet = 0;
240304240455
}
240456
+ *ppUpdate = pRet;
240305240457
240306
- *ppInsert = pRet;
240458
+ sqlite3_free(aUnique);
240459
+ sqlite3_free(randset.aBuf);
240460
+ sqlite3_free(upset.aBuf);
240461
+ sqlite3_free(where.aBuf);
240462
+
240307240463
return rc;
240308240464
}
240309240465
240310240466
/*
240311240467
** Retry the changes accumulated in the pApply->constraints buffer. The
@@ -240318,18 +240474,21 @@
240318240474
** is repeated until no further progress can be made.
240319240475
**
240320240476
** 2) For each UPDATE change in the buffer, try the following in a
240321240477
** savepoint transaction:
240322240478
**
240323
-** a) DELETE the affected row,
240479
+** a) UPDATE the affected row, setting each column modified by the
240480
+** UPDATE change to a random value,
240324240481
** b) Attempt step (1) with remaining changes,
240325
-** c) Attempt to INSERT a row equivalent to the one that would be
240326
-** created by applying this UPDATE change.
240482
+** c) Attempt to UPDATE the affected row again, this time setting
240483
+** each modified column to the value required by the UPDATE change.
240327240484
**
240328
-** If the INSERT in (c) succeeds, the savepoint is committed and all
240485
+** If both (a) and (c) succeed, the savepoint is committed and all
240329240486
** successfully applied changes are removed from the buffer. Step (2)
240330
-** is then repeated.
240487
+** is then repeated. Otherwise, if either (a) or (c) fails with
240488
+** SQLITE_CONSTRAINT, the savepoint is rolled back and the next UPDATE
240489
+** in the buffer is tried.
240331240490
**
240332240491
** 3) Once step (2) has been attempted for each UPDATE in the change,
240333240492
** a final attempt is made to apply each remaining change. This time,
240334240493
** if an SQLITE_CONSTRAINT error is encountered, the conflict handler
240335240494
** is invoked and the user has to decide whether to omit the change
@@ -240364,12 +240523,13 @@
240364240523
240365240524
/* Step (2) */
240366240525
while( rc==SQLITE_OK && pApply->constraints.nBuf && !pApply->bNoUpdateLoop ){
240367240526
SessionBuffer cons = {0, 0, 0};
240368240527
sqlite3_changeset_iter *pUp = 0;
240369
- sqlite3_stmt *pInsert = 0;
240528
+ sqlite3_stmt *pUpdate = 0;
240370240529
int iSkip = 0;
240530
+ int bConstraint = 0; /* True if an SQLITE_CONSTRAINT occurs */
240371240531
240372240532
rc = sessionRetryIterInit(
240373240533
&pApply->constraints, bPatchset, zTab, pApply, &pUp
240374240534
);
240375240535
if( rc==SQLITE_OK ){
@@ -240380,19 +240540,26 @@
240380240540
iSkip++;
240381240541
}
240382240542
if( iThis==iUpdate ){
240383240543
rc = sqlite3_exec(db, "SAVEPOINT update_op", 0, 0, 0);
240384240544
if( rc==SQLITE_OK ){
240385
- rc = sessionUpdateToDeleteInsert(db, zTab, pApply, pUp, &pInsert);
240545
+ rc = sessionUpdateToUpdate(db, zTab, pApply, pUp, &pUpdate);
240546
+ if( (rc&0xff)==SQLITE_CONSTRAINT ){
240547
+ bConstraint = 1;
240548
+ rc = SQLITE_OK;
240549
+ }
240386240550
}
240387240551
}
240388240552
sqlite3changeset_finalize(pUp);
240389240553
if( iThis!=iUpdate ) break;
240390240554
}
240391240555
240392240556
if( rc==SQLITE_OK ){
240393240557
cons = pApply->constraints;
240558
+ if( bConstraint ){
240559
+ memset(&pApply->constraints, 0, sizeof(SessionBuffer));
240560
+ }
240394240561
240395240562
while( rc==SQLITE_OK && pApply->constraints.nBuf>0 ){
240396240563
SessionBuffer app = pApply->constraints;
240397240564
memset(&pApply->constraints, 0, sizeof(SessionBuffer));
240398240565
rc = sessionApplyRetryBuffer(
@@ -240408,13 +240575,20 @@
240408240575
}
240409240576
}
240410240577
240411240578
iUpdate++;
240412240579
if( rc==SQLITE_OK ){
240413
- sqlite3_step(pInsert);
240414
- rc = sqlite3_finalize(pInsert);
240415
- if( (rc&0xff)==SQLITE_CONSTRAINT ){
240580
+ if( bConstraint==0 ){
240581
+ sqlite3_step(pUpdate);
240582
+ rc = sqlite3_finalize(pUpdate);
240583
+ pUpdate = 0;
240584
+ if( (rc&0xff)==SQLITE_CONSTRAINT ){
240585
+ bConstraint = 1;
240586
+ rc = SQLITE_OK;
240587
+ }
240588
+ }
240589
+ if( bConstraint ){
240416240590
rc = sqlite3_exec(db, "ROLLBACK TO update_op", 0, 0, 0);
240417240591
sqlite3_free(pApply->constraints.aBuf);
240418240592
pApply->constraints = cons;
240419240593
memset(&cons, 0, sizeof(cons));
240420240594
}else if( rc==SQLITE_OK ){
@@ -240421,13 +240595,12 @@
240421240595
iUpdate = 0;
240422240596
}
240423240597
if( rc==SQLITE_OK ){
240424240598
rc = sqlite3_exec(db, "RELEASE update_op", 0, 0, 0);
240425240599
}
240426
- }else{
240427
- sqlite3_finalize(pInsert);
240428240600
}
240601
+ sqlite3_finalize(pUpdate);
240429240602
240430240603
sqlite3_free(cons.aBuf);
240431240604
}
240432240605
240433240606
/* Step (3) */
@@ -265203,11 +265376,11 @@
265203265376
int nArg, /* Number of args */
265204265377
sqlite3_value **apUnused /* Function arguments */
265205265378
){
265206265379
assert( nArg==0 );
265207265380
UNUSED_PARAM2(nArg, apUnused);
265208
- sqlite3_result_text(pCtx, "fts5: 2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c", -1, SQLITE_TRANSIENT);
265381
+ sqlite3_result_text(pCtx, "fts5: 2026-10-05 14:22:13 4bfc6e53a95d710b7f40fa9c80d8cdd1df50d69ed8614e9800f7e6a1ca5a3c29", -1, SQLITE_TRANSIENT);
265209265382
}
265210265383
265211265384
/*
265212265385
** Implementation of fts5_locale(LOCALE, TEXT) function.
265213265386
**
265214265387
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 92709f54d4c58cf174f305b58971a01878af with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-10-01T11:21:02.802Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -782,11 +782,11 @@
782 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
783 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
784 #define SQLITE_FULL 13 /* Insertion failed because database is full */
785 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
786 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
787 #define SQLITE_EMPTY 16 /* Internal use only */
788 #define SQLITE_SCHEMA 17 /* The database schema changed */
789 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
790 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
791 #define SQLITE_MISMATCH 20 /* Data type mismatch */
792 #define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -3294,14 +3294,18 @@
3294 ** ^The sqlite3_complete(X) and sqlite3_complete16(X) routines return 0
3295 ** if the statement is incomplete. ^If a memory allocation fails, then
3296 ** SQLITE_NOMEM is returned.
3297 **
3298 ** The [sqlite3_incomplete(X)] routine is similar to [sqlite3_complete(X)]
3299 ** except that sqlite3_incomplete(X) returns 0 if the input X is complete
3300 ** and non-zero if X is incomplete. The non-zero return from
 
 
3301 ** sqlite3_incomplete(X) contains additional information about what is
3302 ** needed to complete the input X. The sqlite3_incomplete(X) interface
 
 
3303 ** is only available for UTF-8 text.
3304 **
3305 ** ^None of these routines do a full parse the SQL statements and thus
3306 ** will not detect syntactically incorrect SQL. They only determine if
3307 ** input text has properly terminated comments, string literals, and
@@ -22669,12 +22673,12 @@
22669 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
22670 SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8);
22671 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr);
22672 SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr);
22673 SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*);
22674 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(const Parse *pParse, Expr*, const Token*, int);
22675 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(const Parse*,Expr*,const char*);
22676 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*);
22677 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr*);
22678 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
22679 SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3*);
22680 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse*, const char*,const char*,const char*);
@@ -22912,14 +22916,16 @@
22912 SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db);
22913 #ifndef SQLITE_OMIT_VIRTUALTABLE
22914 SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName);
22915 SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*);
22916 SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3*, Table*);
 
22917 #else
22918 # define sqlite3ShadowTableName(A,B) 0
22919 # define sqlite3IsShadowTableOf(A,B,C) 0
22920 # define sqlite3MarkAllShadowTablesOf(A,B)
 
22921 #endif
22922 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
22923 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
22924 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
22925 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -88204,10 +88210,11 @@
88204 || opcode==OP_VCreate
88205 || opcode==OP_ParseSchema
88206 || opcode==OP_Function || opcode==OP_PureFunc
88207 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
88208 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
 
88209 ){
88210 hasAbort = 1;
88211 break;
88212 }
88213 if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
@@ -95696,10 +95703,15 @@
95696 pMem = &pUnpack->aMem[iStore];
95697 if( iIdx==p->pTab->iPKey ){
95698 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
95699 }else if( iStore>=pUnpack->nField ){
95700 pMem = (sqlite3_value *)columnNullValue();
 
 
 
 
 
95701 }
95702 }else{
95703 /* For an UPDATE, memory cell (p->iNewReg+1+iStore) contains the required
95704 ** value. Make a copy of the cell contents and return a pointer to it.
95705 ** It is not safe to return a pointer to the memory cell itself as the
@@ -112968,27 +112980,33 @@
112968 **
112969 ** If a memory allocation error occurs, that fact is recorded in pParse->db
112970 ** and the pExpr parameter is returned unchanged.
112971 */
112972 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(
112973 const Parse *pParse, /* Parsing context */
112974 Expr *pExpr, /* Add the "COLLATE" clause to this expression */
112975 const Token *pCollName, /* Name of collating sequence */
112976 int dequote /* True to dequote pCollName */
112977 ){
112978 if( pCollName->n>0 ){
112979 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
 
112980 if( pNew ){
112981 pNew->pLeft = pExpr;
112982 pNew->flags |= EP_Collate|EP_Skip;
 
 
 
 
 
112983 pExpr = pNew;
112984 }
112985 }
112986 return pExpr;
112987 }
112988 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(
112989 const Parse *pParse, /* Parsing context */
112990 Expr *pExpr, /* Add the "COLLATE" clause to this expression */
112991 const char *zC /* The collating sequence name */
112992 ){
112993 Token s;
112994 assert( zC!=0 );
@@ -123703,11 +123721,11 @@
123703 }
123704
123705 /* Search for a constraint violation. Throw an exception if one is found. */
123706 sqlite3NestedParse(pParse,
123707 "SELECT sqlite_fail('constraint failed', %d) "
123708 "FROM %Q.%Q WHERE (%.*s) IS NOT TRUE",
123709 SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, zExpr
123710 );
123711
123712 /* Edit the SQL for the named table. */
123713 pCons = pFirst->z;
@@ -125888,10 +125906,15 @@
125888 ** Close the old db and update the aDb[] slot with the new memdb
125889 ** values. */
125890 sqlite3BtreeClose(pNew->pBt);
125891 pNew->pBt = pNewBt;
125892 pNew->pSchema = pNewSchema;
 
 
 
 
 
125893 }else{
125894 sqlite3BtreeClose(pNewBt);
125895 rc = SQLITE_NOMEM;
125896 }
125897 }
@@ -140684,10 +140707,11 @@
140684 }
140685 addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
140686 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
140687 sqlite3VdbeJumpHere(v, addr1);
140688 sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
 
140689 }
140690
140691 /* Copy the new data already generated. */
140692 assert( pTab->nNVCol>0 || pParse->nErr>0 );
140693 sqlite3VdbeAddOp3(v, OP_Copy, regRowid+1, regCols+1, pTab->nNVCol-1);
@@ -140752,10 +140776,11 @@
140752 }else{
140753 addr1 = sqlite3VdbeCurrentAddr(v);
140754 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, addr1+2); VdbeCoverage(v);
140755 }
140756 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
 
140757 }
140758 }else if( IsVirtual(pTab) || withoutRowid ){
140759 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
140760 }else{
140761 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -147862,13 +147887,14 @@
147862 ** if one is set. If no busy handler or a different busy handler is set
147863 ** then 0 is returned. Setting the busy_timeout to 0 or negative
147864 ** disables the timeout.
147865 */
147866 /*case PragTyp_BUSY_TIMEOUT*/ default: {
 
147867 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
147868 if( zRight ){
147869 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
147870 }
147871 returnSingleInt(v, db->busyTimeout);
147872 break;
147873 }
147874
@@ -148450,10 +148476,11 @@
148450 ** schema.
148451 */
148452 int rc;
148453 u8 saved_iDb = db->init.iDb;
148454 sqlite3_stmt *pStmt;
 
148455 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
148456
148457 assert( db->init.busy );
148458 db->init.iDb = iDb;
148459 if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
@@ -148464,11 +148491,11 @@
148464 }
148465 }
148466 db->init.orphanTrigger = 0;
148467 db->init.azInit = (const char**)argv;
148468 pStmt = 0;
148469 TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, 0);
148470 rc = db->errCode;
148471 assert( (rc&0xFF)==(rcp&0xFF) );
148472 db->init.iDb = saved_iDb;
148473 /* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
148474 if( SQLITE_OK!=rc ){
@@ -148480,10 +148507,12 @@
148480 sqlite3OomFault(db);
148481 }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
148482 corruptSchema(pData, argv, sqlite3_errmsg(db));
148483 }
148484 }
 
 
148485 }
148486 db->init.azInit = sqlite3StdType; /* Any array of string ptrs will do */
148487 sqlite3_finalize(pStmt);
148488 }else if( argv[1]==0 || (argv[4]!=0 && argv[4][0]!=0) ){
148489 corruptSchema(pData, argv, 0);
@@ -151924,10 +151953,24 @@
151924 sqlite3ColumnSetColl(db, pCol, pColl->zName);
151925 }
151926 }
151927 pTab->szTabRow = 1; /* Any non-zero value works */
151928 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151929
151930 /*
151931 ** Given a SELECT statement, generate a Table structure that describes
151932 ** the result set of that SELECT.
151933 */
@@ -151935,16 +151978,11 @@
151935 Table *pTab;
151936 sqlite3 *db = pParse->db;
151937 u64 savedFlags;
151938
151939 pParse->nNestSel++;
151940 #if SQLITE_MAX_EXPR_DEPTH>0
151941 if( pParse->nNestSel >= db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){
151942 sqlite3ErrorMsg(pParse, "VIEWs and/or subqueries nested too deep");
151943 return 0;
151944 }
151945 #endif
151946 savedFlags = db->flags;
151947 db->flags &= ~(u64)SQLITE_FullColNames;
151948 db->flags |= SQLITE_ShortColNames;
151949 sqlite3SelectPrep(pParse, pSelect, 0);
151950 db->flags = savedFlags;
@@ -152039,17 +152077,19 @@
152039 }
152040 }else{
152041 sqlite3ExprCode(pParse, pLimit->pLeft, iLimit);
152042 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
152043 VdbeComment((v, "LIMIT counter"));
 
152044 sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
152045 }
152046 if( pLimit->pRight ){
152047 p->iOffset = iOffset = ++pParse->nMem;
152048 pParse->nMem++; /* Allocate an extra register for limit+offset */
152049 sqlite3ExprCode(pParse, pLimit->pRight, iOffset);
152050 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
 
152051 VdbeComment((v, "OFFSET counter"));
152052 sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset);
152053 VdbeComment((v, "LIMIT+OFFSET"));
152054 }
152055 }
@@ -155187,18 +155227,17 @@
155187 }
155188 return pWith;
155189 }
155190
155191 /*
155192 ** This function checks if argument pFrom refers to a CTE declared by
155193 ** a WITH clause on the stack currently maintained by the parser (on the
155194 ** pParse->pWith linked list). And if currently processing a CTE
155195 ** CTE expression, through routine checks to see if the reference is
155196 ** a recursive reference to the CTE.
155197 **
155198 ** If pFrom matches a CTE according to either of these two above, pFrom->pSTab
155199 ** and other fields are populated accordingly.
155200 **
155201 ** Return 0 if no match is found.
155202 ** Return 1 if a match is found.
155203 ** Return 2 if an error condition is detected.
155204 */
@@ -155323,10 +155362,22 @@
155323 }
155324 if( (pRecTerm->selFlags & SF_Recursive)==0 ) break;
155325 pRecTerm = pRecTerm->pPrior;
155326 }
155327
 
 
 
 
 
 
 
 
 
 
 
 
155328 pCte->zCteErr = "circular reference: %s";
155329 pSavedWith = pParse->pWith;
155330 pParse->pWith = pWith;
155331 if( pSel->selFlags & SF_Recursive ){
155332 int rc;
@@ -155347,10 +155398,14 @@
155347 pParse->pWith = pSavedWith;
155348 return 2;
155349 }
155350 }
155351 pParse->pWith = pWith;
 
 
 
 
155352
155353 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
155354 pEList = pLeft->pEList;
155355 if( pCte->pCols ){
155356 if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){
@@ -156722,10 +156777,14 @@
156722 sqlite3PExprAddSelect(pParse, pTerm, pSub);
156723 if( pExpr==0 ){
156724 pExpr = pTerm;
156725 }else{
156726 pExpr = sqlite3PExpr(pParse, TK_PLUS, pTerm, pExpr);
 
 
 
 
156727 }
156728 pSub = pPrior;
156729 }
156730 p->pEList->a[0].pExpr = pExpr;
156731 p->selFlags &= ~(u32)SF_Aggregate;
@@ -161221,10 +161280,11 @@
161221 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
161222 }else{
161223 sqlite3VdbeAddOp3(v, OP_Column, iEph, iRowidExpr, regNewRowid);
161224 }
161225 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
 
161226 }
161227
161228 /* Compute the old pre-UPDATE content of the row being changed, if that
161229 ** information is needed */
161230 if( chngPk || hasFK || pTrigger ){
@@ -163769,10 +163829,21 @@
163769 pTab->tabFlags |= TF_Ephemeral;
163770 sqlite3DeleteTable(db, pTab);
163771 pMod->pEpoTab = 0;
163772 }
163773 }
 
 
 
 
 
 
 
 
 
 
 
163774
163775 /*
163776 ** Return the ON CONFLICT resolution mode in effect for the virtual
163777 ** table update operation currently in progress.
163778 **
@@ -187762,14 +187833,14 @@
187762 #endif
187763
187764 /*
187765 ** Return zero if the given SQL string is complete - if all comments,
187766 ** string and blob literals, and quoted identifiers have been closed and
187767 ** if the entire string ends with ";" and possible with ";END;" if the
187768 ** string is a CREATE TRIGGER statement. A non-zero return indicates
187769 ** that the string is incomplete. Bits of the return value indicate
187770 ** what is missing and is needed to close out the statement.
187771 **
187772 ** Special handling is require for CREATE TRIGGER statements.
187773 ** Whenever the CREATE TRIGGER keywords are seen, the statement
187774 ** must end with ";END;".
187775 **
@@ -187777,15 +187848,16 @@
187777 ** subfields, at byte boundaries:
187778 **
187779 ** R = 0xwwwwwwww00xxyyzz
187780 **
187781 ** In other words, zz is the least significant byte, yy is the next
187782 ** most significant byte, xx is the third byte, wwwwwwww is a 32-bit
187783 ** value from the middle.
187784 **
187785 ** zz == SQLITE_OK Input is complete
187786 ** zz == SQLITE_ERROR Input is incomplete
 
187787 ** zz == SQLITE_MISUSE Input is a NULL pointer
187788 ** zz != 0 New values for zz may be added in the future
187789 **
187790 ** yy == 0x01 Need a semicolon at the end
187791 ** yy == 0x02 Need "END" and a semicolon
@@ -187807,11 +187879,11 @@
187807 ** ((R>>24)&0xff)!=0 New uses for the 4th byte may be added
187808 ** in the future
187809 **
187810 ** This implementation uses a state machine with 8 states:
187811 **
187812 ** (0) INVALID We have not yet seen a non-whitespace character.
187813 **
187814 ** (1) START At the beginning or end of an SQL statement. This routine
187815 ** returns 1 if it ends in the START state and 0 if it ends
187816 ** in any other state.
187817 **
@@ -187864,11 +187936,11 @@
187864 ** statement. This is the normal case.
187865 */
187866 static const u8 trans[8][8] = {
187867 /* Token: */
187868 /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
187869 /* 0 INVALID: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
187870 /* 1 START: */ { 1, 1, 2, 3, 4, 2, 2, 2, },
187871 /* 2 NORMAL: */ { 1, 2, 2, 2, 2, 2, 2, 2, },
187872 /* 3 EXPLAIN: */ { 1, 3, 3, 2, 4, 2, 2, 2, },
187873 /* 4 CREATE: */ { 1, 4, 2, 2, 2, 4, 5, 2, },
187874 /* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, },
@@ -187880,18 +187952,18 @@
187880 ** used to detect the end of a statement is much simpler
187881 */
187882 static const u8 trans[3][3] = {
187883 /* Token: */
187884 /* State: ** SEMI WS OTHER */
187885 /* 0 INVALID: */ { 1, 0, 2, },
187886 /* 1 START: */ { 1, 1, 2, },
187887 /* 2 NORMAL: */ { 1, 2, 2, },
187888 };
187889 #endif /* SQLITE_OMIT_TRIGGER */
187890 /* Mapping state number to yy value for the return */
187891 static const u8 statemap[8] = {
187892 /* 0 INVALID */ 1,
187893 /* 1 START */ 0,
187894 /* 2 NORMAL */ 1,
187895 /* 3 EXPLAIN */ 1,
187896 /* 4 CREATE */ 1,
187897 /* 5 TRIGGER */ 3,
@@ -187925,10 +187997,11 @@
187925 break;
187926 }
187927 zSql += 2;
187928 while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
187929 if( zSql[0]==0 ){
 
187930 pending = '/';
187931 goto incomplete_finish;
187932 }
187933 zSql++;
187934 token = tkWS;
@@ -188042,10 +188115,11 @@
188042 }
188043 state = trans[state][token];
188044 zSql++;
188045 }
188046 incomplete_finish:
 
188047 if( state==1 ) nParen = 0;
188048 return (i64)((((u64)nParen)<<32) |
188049 ((u64)pending<<16) |
188050 ((u64)statemap[state]<<8) |
188051 (state!=1));
@@ -210496,10 +210570,11 @@
210496 SQLITE_PRIVATE int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk){
210497 int rc = SQLITE_OK; /* Return code */
210498 u64 cksum1 = 0; /* Checksum based on FTS index contents */
210499 u64 cksum2 = 0; /* Checksum based on %_content contents */
210500 sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
 
210501
210502 /* This block calculates the checksum according to the FTS index. */
210503 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
210504 if( rc==SQLITE_OK ){
210505 int rc2;
@@ -210515,11 +210590,11 @@
210515 rc2 = sqlite3_reset(pAllLangid);
210516 if( rc==SQLITE_OK ) rc = rc2;
210517 }
210518
210519 /* This block calculates the checksum according to the %_content table */
210520 if( rc==SQLITE_OK ){
210521 sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
210522 sqlite3_stmt *pStmt = 0;
210523 char *zSql;
210524
210525 zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
@@ -210573,11 +210648,11 @@
210573
210574 if( rc==SQLITE_CORRUPT_VTAB ){
210575 rc = SQLITE_OK;
210576 *pbOk = 0;
210577 }else{
210578 *pbOk = (rc==SQLITE_OK && cksum1==cksum2);
210579 }
210580 return rc;
210581 }
210582
210583 /*
@@ -224142,11 +224217,11 @@
224142 continue;
224143 }
224144 break;
224145 }
224146 if( geopolySkipSpace(&s)==']'
224147 && s.nVertex>=4
224148 && s.a[0]==s.a[s.nVertex*2-2]
224149 && s.a[1]==s.a[s.nVertex*2-1]
224150 && (s.z++, geopolySkipSpace(&s)==0)
224151 ){
224152 GeoPoly *pOut;
@@ -224479,11 +224554,11 @@
224479 sqlite3_value **argv
224480 ){
224481 double x = sqlite3_value_double(argv[0]);
224482 double y = sqlite3_value_double(argv[1]);
224483 double r = sqlite3_value_double(argv[2]);
224484 int n = sqlite3_value_int(argv[3]);
224485 int i;
224486 GeoPoly *p;
224487 (void)argc;
224488
224489 if( n<3 || r<=0.0 || r>=1e300 ) return;
@@ -237743,10 +237818,37 @@
237743 if( pzErrmsg && rc!=SQLITE_OK ){
237744 *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
237745 }
237746 return rc;
237747 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237748
237749 /*
237750 ** Formulate and prepare a SELECT statement to retrieve a row from table
237751 ** zTab in database zDb based on its primary key. i.e.
237752 **
@@ -240147,165 +240249,219 @@
240147
240148 return rc;
240149 }
240150
240151 /*
240152 ** Check if table zTab in the "main" database of db is a WITHOUT ROWID
240153 ** table.
 
240154 **
240155 ** If no error occurs, return SQLITE_OK and set output variable (*pbWR) to
240156 ** true if zTab is a WITHOUT ROWID table, or false otherwise. Or, if an
240157 ** error does occur, return an SQLite error code. The final value of (*pbWR)
240158 ** is undefined in this case.
240159 */
240160 static int sessionTableIsWithoutRowid(sqlite3 *db, const char *zTab, int *pbWR){
240161 sqlite3_stmt *pList = 0;
240162 char *zSql = 0;
 
 
 
 
240163 int rc = SQLITE_OK;
240164
240165 zSql = sqlite3_mprintf("PRAGMA table_list = %Q", zTab);
240166 if( zSql==0 ){
240167 rc = SQLITE_NOMEM;
240168 }else{
240169 rc = sqlite3_prepare_v2(db, zSql, -1, &pList, 0);
240170 sqlite3_free(zSql);
240171 }
240172
240173 if( rc==SQLITE_OK ){
240174 sqlite3_step(pList);
240175 *pbWR = sqlite3_column_int(pList, 4);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240176 rc = sqlite3_finalize(pList);
 
 
240177 }
240178
240179 return rc;
240180 }
240181
240182 /*
240183 ** Iterator pUp points to an UPDATE change. This function deletes the
240184 ** affected row from the database and creates an INSERT statement that
240185 ** may be used to reinsert the row as it is after the UPDATE change
240186 ** has been applied.
 
240187 **
240188 ** If successful, SQLITE_OK is returned and output variable (*ppInsert)
240189 ** is left pointing to a prepared INSERT statement. It is the responsibility
 
 
 
 
 
 
 
 
 
 
 
 
240190 ** of the caller to eventually free this statement using sqlite3_finalize().
240191 ** Or, if an error occurs, an SQLite error code is returned and (*ppInsert)
240192 ** set to NULL. pApply->zErr may be set to an error message in this case.
 
 
240193 */
240194 static int sessionUpdateToDeleteInsert(
240195 sqlite3 *db, /* Database to write to */
240196 const char *zTab, /* Table name */
240197 SessionApplyCtx *pApply, /* Apply context */
240198 sqlite3_changeset_iter *pUp, /* Iterator pointing to UPDATE change */
240199 sqlite3_stmt **ppInsert /* OUT: INSERT statement */
240200 ){
240201 sqlite3_stmt *pRet = 0; /* The INSERT statement */
240202 sqlite3_stmt *pSelect = 0; /* SELECT to read current values of row */
240203 int rc = SQLITE_OK;
240204 int bWR = 0;
240205
240206 rc = sessionTableIsWithoutRowid(db, zTab, &bWR);
240207 if( rc==SQLITE_OK ){
240208 char *zSelect = 0;
240209 char *zInsert = 0;
240210 SessionBuffer cols = {0, 0, 0};
240211 SessionBuffer insbind = {0, 0, 0};
240212 SessionBuffer pkcols = {0, 0, 0};
240213 SessionBuffer selbind = {0, 0, 0};
240214
240215 const char *zComma = "";
240216 const char *zComma2 = "";
240217 int ii;
240218 for(ii=0; ii<pApply->nCol; ii++){
240219 sessionAppendStr(&cols, zComma, &rc);
240220 sessionAppendIdent(&cols, pApply->azCol[ii], &rc);
240221 sessionAppendStr(&insbind, zComma, &rc);
240222 sessionAppendStr(&insbind, "?", &rc);
240223 zComma = ", ";
240224
240225 if( pApply->abPK[ii] ){
240226 sessionAppendStr(&pkcols, zComma2, &rc);
240227 sessionAppendIdent(&pkcols, pApply->azCol[ii], &rc);
240228 sessionAppendStr(&selbind, zComma2, &rc);
240229 sessionAppendPrintf(&selbind, &rc, "?%d", ii+1);
240230 zComma2 = ", ";
240231 }
240232 }
240233 if( bWR==0 ){
240234 sessionAppendStr(&cols, zComma, &rc);
240235 sessionAppendStr(&cols, SESSIONS_ROWID, &rc);
240236 sessionAppendStr(&insbind, zComma, &rc);
240237 sessionAppendStr(&insbind, "?", &rc);
240238 }
240239
240240 if( rc==SQLITE_OK ){
240241 zSelect = sqlite3_mprintf("SELECT %s FROM %Q WHERE (%s) IS (%s)",
240242 cols.aBuf, zTab, pkcols.aBuf, selbind.aBuf
240243 );
240244 if( zSelect==0 ) rc = SQLITE_NOMEM;
240245 }
240246 if( rc==SQLITE_OK ){
240247 zInsert = sqlite3_mprintf("INSERT INTO %Q(%s) VALUES(%s)",
240248 zTab, cols.aBuf, insbind.aBuf
240249 );
240250 if( zInsert==0 ) rc = SQLITE_NOMEM;
240251 }
240252
240253 if( rc==SQLITE_OK ){
240254 rc = sessionPrepare(db, &pSelect, &pApply->zErr, zSelect);
240255 }
240256 if( rc==SQLITE_OK ){
240257 rc = sessionPrepare(db, &pRet, &pApply->zErr, zInsert);
240258 }
240259
240260 sqlite3_free(zSelect);
240261 sqlite3_free(zInsert);
240262 sqlite3_free(cols.aBuf);
240263 sqlite3_free(insbind.aBuf);
240264 sqlite3_free(pkcols.aBuf);
240265 sqlite3_free(selbind.aBuf);
240266 }
240267
240268 if( rc==SQLITE_OK ){
240269 rc = sessionBindRow(
240270 pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pSelect
240271 );
240272 }
240273
240274 if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){
240275 int iCol;
240276 for(iCol=0; iCol<pApply->nCol; iCol++){
240277 sqlite3_value *pVal = pUp->apValue[iCol+pApply->nCol];
240278 if( pVal==0 ){
240279 pVal = sqlite3_column_value(pSelect, iCol);
240280 }
240281 rc = sqlite3_bind_value(pRet, iCol+1, pVal);
240282 }
240283 if( bWR==0 ){
240284 sqlite3_bind_int64(pRet, iCol+1, sqlite3_column_int64(pSelect, iCol));
240285 }
240286 }
240287 sessionFinalizeStmt(pSelect, &rc);
240288
240289 /* Delete the row from the database. */
240290 if( rc==SQLITE_OK ){
240291 rc = sessionBindRow(
240292 pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pApply->pDelete
240293 );
240294 sqlite3_bind_int(pApply->pDelete, pApply->nCol+1, 1);
240295 }
240296 if( rc==SQLITE_OK ){
240297 sqlite3_step(pApply->pDelete);
240298 rc = sqlite3_reset(pApply->pDelete);
240299 }
240300
240301 if( rc!=SQLITE_OK ){
240302 sqlite3_finalize(pRet);
240303 pRet = 0;
240304 }
 
240305
240306 *ppInsert = pRet;
 
 
 
 
240307 return rc;
240308 }
240309
240310 /*
240311 ** Retry the changes accumulated in the pApply->constraints buffer. The
@@ -240318,18 +240474,21 @@
240318 ** is repeated until no further progress can be made.
240319 **
240320 ** 2) For each UPDATE change in the buffer, try the following in a
240321 ** savepoint transaction:
240322 **
240323 ** a) DELETE the affected row,
 
240324 ** b) Attempt step (1) with remaining changes,
240325 ** c) Attempt to INSERT a row equivalent to the one that would be
240326 ** created by applying this UPDATE change.
240327 **
240328 ** If the INSERT in (c) succeeds, the savepoint is committed and all
240329 ** successfully applied changes are removed from the buffer. Step (2)
240330 ** is then repeated.
 
 
240331 **
240332 ** 3) Once step (2) has been attempted for each UPDATE in the change,
240333 ** a final attempt is made to apply each remaining change. This time,
240334 ** if an SQLITE_CONSTRAINT error is encountered, the conflict handler
240335 ** is invoked and the user has to decide whether to omit the change
@@ -240364,12 +240523,13 @@
240364
240365 /* Step (2) */
240366 while( rc==SQLITE_OK && pApply->constraints.nBuf && !pApply->bNoUpdateLoop ){
240367 SessionBuffer cons = {0, 0, 0};
240368 sqlite3_changeset_iter *pUp = 0;
240369 sqlite3_stmt *pInsert = 0;
240370 int iSkip = 0;
 
240371
240372 rc = sessionRetryIterInit(
240373 &pApply->constraints, bPatchset, zTab, pApply, &pUp
240374 );
240375 if( rc==SQLITE_OK ){
@@ -240380,19 +240540,26 @@
240380 iSkip++;
240381 }
240382 if( iThis==iUpdate ){
240383 rc = sqlite3_exec(db, "SAVEPOINT update_op", 0, 0, 0);
240384 if( rc==SQLITE_OK ){
240385 rc = sessionUpdateToDeleteInsert(db, zTab, pApply, pUp, &pInsert);
 
 
 
 
240386 }
240387 }
240388 sqlite3changeset_finalize(pUp);
240389 if( iThis!=iUpdate ) break;
240390 }
240391
240392 if( rc==SQLITE_OK ){
240393 cons = pApply->constraints;
 
 
 
240394
240395 while( rc==SQLITE_OK && pApply->constraints.nBuf>0 ){
240396 SessionBuffer app = pApply->constraints;
240397 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
240398 rc = sessionApplyRetryBuffer(
@@ -240408,13 +240575,20 @@
240408 }
240409 }
240410
240411 iUpdate++;
240412 if( rc==SQLITE_OK ){
240413 sqlite3_step(pInsert);
240414 rc = sqlite3_finalize(pInsert);
240415 if( (rc&0xff)==SQLITE_CONSTRAINT ){
 
 
 
 
 
 
 
240416 rc = sqlite3_exec(db, "ROLLBACK TO update_op", 0, 0, 0);
240417 sqlite3_free(pApply->constraints.aBuf);
240418 pApply->constraints = cons;
240419 memset(&cons, 0, sizeof(cons));
240420 }else if( rc==SQLITE_OK ){
@@ -240421,13 +240595,12 @@
240421 iUpdate = 0;
240422 }
240423 if( rc==SQLITE_OK ){
240424 rc = sqlite3_exec(db, "RELEASE update_op", 0, 0, 0);
240425 }
240426 }else{
240427 sqlite3_finalize(pInsert);
240428 }
 
240429
240430 sqlite3_free(cons.aBuf);
240431 }
240432
240433 /* Step (3) */
@@ -265203,11 +265376,11 @@
265203 int nArg, /* Number of args */
265204 sqlite3_value **apUnused /* Function arguments */
265205 ){
265206 assert( nArg==0 );
265207 UNUSED_PARAM2(nArg, apUnused);
265208 sqlite3_result_text(pCtx, "fts5: 2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c", -1, SQLITE_TRANSIENT);
265209 }
265210
265211 /*
265212 ** Implementation of fts5_locale(LOCALE, TEXT) function.
265213 **
265214
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 4bfc6e53a95d710b7f40fa9c80d8cdd1df50 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-10-05 14:22:13 4bfc6e53a95d710b7f40fa9c80d8cdd1df50d69ed8614e9800f7e6a1ca5a3c29"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-10-05T14:22:13.597Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -782,11 +782,11 @@
782 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
783 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
784 #define SQLITE_FULL 13 /* Insertion failed because database is full */
785 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
786 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
787 #define SQLITE_EMPTY 16 /* No content */
788 #define SQLITE_SCHEMA 17 /* The database schema changed */
789 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
790 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
791 #define SQLITE_MISMATCH 20 /* Data type mismatch */
792 #define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -3294,14 +3294,18 @@
3294 ** ^The sqlite3_complete(X) and sqlite3_complete16(X) routines return 0
3295 ** if the statement is incomplete. ^If a memory allocation fails, then
3296 ** SQLITE_NOMEM is returned.
3297 **
3298 ** The [sqlite3_incomplete(X)] routine is similar to [sqlite3_complete(X)]
3299 ** except that sqlite3_incomplete(X) returns SQLITE_OK if the input X is
3300 ** complete, SQLITE_EMPTY if input X consists entirely of whitespace and/or
3301 ** comments, SQLITE_MISUSE if X is a NULL pointer, and some other non-zero
3302 ** value if X is incomplete. The non-zero return from
3303 ** sqlite3_incomplete(X) contains additional information about what is
3304 ** needed to complete the input X. See the header comment on the
3305 ** implemenation of the sqlite3_incomplete() routine for a full description
3306 ** of its non-zero return values. The sqlite3_incomplete(X) interface
3307 ** is only available for UTF-8 text.
3308 **
3309 ** ^None of these routines do a full parse the SQL statements and thus
3310 ** will not detect syntactically incorrect SQL. They only determine if
3311 ** input text has properly terminated comments, string literals, and
@@ -22669,12 +22673,12 @@
22673 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
22674 SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8);
22675 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr);
22676 SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr);
22677 SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*);
22678 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int);
22679 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);
22680 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*);
22681 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr*);
22682 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
22683 SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3*);
22684 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse*, const char*,const char*,const char*);
@@ -22912,14 +22916,16 @@
22916 SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db);
22917 #ifndef SQLITE_OMIT_VIRTUALTABLE
22918 SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName);
22919 SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*);
22920 SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3*, Table*);
22921 SQLITE_PRIVATE void sqlite3VtabEponymousTableClearAll(sqlite3*);
22922 #else
22923 # define sqlite3ShadowTableName(A,B) 0
22924 # define sqlite3IsShadowTableOf(A,B,C) 0
22925 # define sqlite3MarkAllShadowTablesOf(A,B)
22926 # define sqlite3VtabEponymousTableClearAll(X)
22927 #endif
22928 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
22929 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
22930 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
22931 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -88204,10 +88210,11 @@
88210 || opcode==OP_VCreate
88211 || opcode==OP_ParseSchema
88212 || opcode==OP_Function || opcode==OP_PureFunc
88213 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
88214 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
88215 || (opcode==OP_MustBeInt && pOp->p2==0)
88216 ){
88217 hasAbort = 1;
88218 break;
88219 }
88220 if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
@@ -95696,10 +95703,15 @@
95703 pMem = &pUnpack->aMem[iStore];
95704 if( iIdx==p->pTab->iPKey ){
95705 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
95706 }else if( iStore>=pUnpack->nField ){
95707 pMem = (sqlite3_value *)columnNullValue();
95708 }else if( (p->pTab->aCol)
95709 && (p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL)
95710 && (pMem->flags & (MEM_Int|MEM_IntReal))
95711 ){
95712 sqlite3VdbeMemRealify(pMem);
95713 }
95714 }else{
95715 /* For an UPDATE, memory cell (p->iNewReg+1+iStore) contains the required
95716 ** value. Make a copy of the cell contents and return a pointer to it.
95717 ** It is not safe to return a pointer to the memory cell itself as the
@@ -112968,27 +112980,33 @@
112980 **
112981 ** If a memory allocation error occurs, that fact is recorded in pParse->db
112982 ** and the pExpr parameter is returned unchanged.
112983 */
112984 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(
112985 Parse *pParse, /* Parsing context */
112986 Expr *pExpr, /* Add the "COLLATE" clause to this expression */
112987 const Token *pCollName, /* Name of collating sequence */
112988 int dequote /* True to dequote pCollName */
112989 ){
112990 if( pCollName->n>0 && pParse->nErr==0 ){
112991 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
112992 assert( pExpr!=0 );
112993 if( pNew ){
112994 pNew->pLeft = pExpr;
112995 pNew->flags |= EP_Collate|EP_Skip;
112996 #if SQLITE_MAX_EXPR_DEPTH>0
112997 pNew->nHeight = pExpr->nHeight+1;
112998 sqlite3ExprCheckHeight(pParse, pNew->nHeight);
112999 testcase( pParse->nErr>0 );
113000 #endif
113001 pExpr = pNew;
113002 }
113003 }
113004 return pExpr;
113005 }
113006 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(
113007 Parse *pParse, /* Parsing context */
113008 Expr *pExpr, /* Add the "COLLATE" clause to this expression */
113009 const char *zC /* The collating sequence name */
113010 ){
113011 Token s;
113012 assert( zC!=0 );
@@ -123703,11 +123721,11 @@
123721 }
123722
123723 /* Search for a constraint violation. Throw an exception if one is found. */
123724 sqlite3NestedParse(pParse,
123725 "SELECT sqlite_fail('constraint failed', %d) "
123726 "FROM %Q.%Q WHERE (%.*s) IS FALSE",
123727 SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, zExpr
123728 );
123729
123730 /* Edit the SQL for the named table. */
123731 pCons = pFirst->z;
@@ -125888,10 +125906,15 @@
125906 ** Close the old db and update the aDb[] slot with the new memdb
125907 ** values. */
125908 sqlite3BtreeClose(pNew->pBt);
125909 pNew->pBt = pNewBt;
125910 pNew->pSchema = pNewSchema;
125911 if( db->init.iDb==0 ){
125912 /* Clear all eponymous virtual table instances, as they are holding
125913 ** pointers to the schema object just freed by sqlite3BtreeClose() */
125914 sqlite3VtabEponymousTableClearAll(db);
125915 }
125916 }else{
125917 sqlite3BtreeClose(pNewBt);
125918 rc = SQLITE_NOMEM;
125919 }
125920 }
@@ -140684,10 +140707,11 @@
140707 }
140708 addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
140709 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
140710 sqlite3VdbeJumpHere(v, addr1);
140711 sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
140712 sqlite3MayAbort(pParse);
140713 }
140714
140715 /* Copy the new data already generated. */
140716 assert( pTab->nNVCol>0 || pParse->nErr>0 );
140717 sqlite3VdbeAddOp3(v, OP_Copy, regRowid+1, regCols+1, pTab->nNVCol-1);
@@ -140752,10 +140776,11 @@
140776 }else{
140777 addr1 = sqlite3VdbeCurrentAddr(v);
140778 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, addr1+2); VdbeCoverage(v);
140779 }
140780 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
140781 sqlite3MayAbort(pParse);
140782 }
140783 }else if( IsVirtual(pTab) || withoutRowid ){
140784 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
140785 }else{
140786 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -147862,13 +147887,14 @@
147887 ** if one is set. If no busy handler or a different busy handler is set
147888 ** then 0 is returned. Setting the busy_timeout to 0 or negative
147889 ** disables the timeout.
147890 */
147891 /*case PragTyp_BUSY_TIMEOUT*/ default: {
147892 int n = 0;
147893 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
147894 if( zRight && sqlite3GetInt32(zRight,&n) ){
147895 sqlite3_busy_timeout(db, n);
147896 }
147897 returnSingleInt(v, db->busyTimeout);
147898 break;
147899 }
147900
@@ -148450,10 +148476,11 @@
148476 ** schema.
148477 */
148478 int rc;
148479 u8 saved_iDb = db->init.iDb;
148480 sqlite3_stmt *pStmt;
148481 const char *zEnd;
148482 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
148483
148484 assert( db->init.busy );
148485 db->init.iDb = iDb;
148486 if( sqlite3GetUInt32(argv[3], &db->init.newTnum)==0
@@ -148464,11 +148491,11 @@
148491 }
148492 }
148493 db->init.orphanTrigger = 0;
148494 db->init.azInit = (const char**)argv;
148495 pStmt = 0;
148496 TESTONLY(rcp = ) sqlite3Prepare(db, argv[4], -1, 0, 0, &pStmt, &zEnd);
148497 rc = db->errCode;
148498 assert( (rc&0xFF)==(rcp&0xFF) );
148499 db->init.iDb = saved_iDb;
148500 /* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
148501 if( SQLITE_OK!=rc ){
@@ -148480,10 +148507,12 @@
148507 sqlite3OomFault(db);
148508 }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
148509 corruptSchema(pData, argv, sqlite3_errmsg(db));
148510 }
148511 }
148512 }else if( zEnd[0] ){
148513 corruptSchema(pData, argv, 0);
148514 }
148515 db->init.azInit = sqlite3StdType; /* Any array of string ptrs will do */
148516 sqlite3_finalize(pStmt);
148517 }else if( argv[1]==0 || (argv[4]!=0 && argv[4][0]!=0) ){
148518 corruptSchema(pData, argv, 0);
@@ -151924,10 +151953,24 @@
151953 sqlite3ColumnSetColl(db, pCol, pColl->zName);
151954 }
151955 }
151956 pTab->szTabRow = 1; /* Any non-zero value works */
151957 }
151958
151959 /*
151960 ** Check the current subquery nesting depth. Return true and set an
151961 ** error if it has gone too deep.
151962 */
151963 static int checkSubqueryNestingDepth(Parse *pParse){
151964 #if SQLITE_MAX_EXPR_DEPTH>0
151965 if( pParse->nNestSel >= pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){
151966 sqlite3ErrorMsg(pParse, "VIEWs and/or subqueries nested too deep");
151967 return 1;
151968 }
151969 #endif
151970 return 0;
151971 }
151972
151973 /*
151974 ** Given a SELECT statement, generate a Table structure that describes
151975 ** the result set of that SELECT.
151976 */
@@ -151935,16 +151978,11 @@
151978 Table *pTab;
151979 sqlite3 *db = pParse->db;
151980 u64 savedFlags;
151981
151982 pParse->nNestSel++;
151983 if( checkSubqueryNestingDepth(pParse) ) return 0;
 
 
 
 
 
151984 savedFlags = db->flags;
151985 db->flags &= ~(u64)SQLITE_FullColNames;
151986 db->flags |= SQLITE_ShortColNames;
151987 sqlite3SelectPrep(pParse, pSelect, 0);
151988 db->flags = savedFlags;
@@ -152039,17 +152077,19 @@
152077 }
152078 }else{
152079 sqlite3ExprCode(pParse, pLimit->pLeft, iLimit);
152080 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
152081 VdbeComment((v, "LIMIT counter"));
152082 sqlite3MayAbort(pParse);
152083 sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
152084 }
152085 if( pLimit->pRight ){
152086 p->iOffset = iOffset = ++pParse->nMem;
152087 pParse->nMem++; /* Allocate an extra register for limit+offset */
152088 sqlite3ExprCode(pParse, pLimit->pRight, iOffset);
152089 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
152090 sqlite3MayAbort(pParse);
152091 VdbeComment((v, "OFFSET counter"));
152092 sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset);
152093 VdbeComment((v, "LIMIT+OFFSET"));
152094 }
152095 }
@@ -155187,18 +155227,17 @@
155227 }
155228 return pWith;
155229 }
155230
155231 /*
155232 ** This function checks to see if argument pFrom refers to a CTE declared by
155233 ** a WITH clause on the stack currently maintained by the parser (on the
155234 ** pParse->pWith linked list). And if currently processing a CTE expression,
155235 ** it also checks to see if the reference is a recursive reference to the CTE.
 
155236 **
155237 ** If pFrom matches a CTE, pFrom->pSTab and other fields are populated
155238 ** accordingly.
155239 **
155240 ** Return 0 if no match is found.
155241 ** Return 1 if a match is found.
155242 ** Return 2 if an error condition is detected.
155243 */
@@ -155323,10 +155362,22 @@
155362 }
155363 if( (pRecTerm->selFlags & SF_Recursive)==0 ) break;
155364 pRecTerm = pRecTerm->pPrior;
155365 }
155366
155367 #if SQLITE_MAX_EXPR_DEPTH>0
155368 if( pParse->nTab>=db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){
155369 /* Bug 2026-10-04T05:35:14Z: Prevent nested CTEs from generating
155370 ** an exponential number of cursors. The error message here will
155371 ** be "Nested too deep", which isn't exactly correct, but it is
155372 ** sufficient, and we don't want to use extra code space for more
155373 ** detail on such an obscure error. */
155374 pParse->nNestSel = pParse->nTab;
155375 }
155376 pParse->nNestSel++;
155377 if( checkSubqueryNestingDepth(pParse) ) return 2;
155378 #endif
155379 pCte->zCteErr = "circular reference: %s";
155380 pSavedWith = pParse->pWith;
155381 pParse->pWith = pWith;
155382 if( pSel->selFlags & SF_Recursive ){
155383 int rc;
@@ -155347,10 +155398,14 @@
155398 pParse->pWith = pSavedWith;
155399 return 2;
155400 }
155401 }
155402 pParse->pWith = pWith;
155403 #if SQLITE_MAX_EXPR_DEPTH>0
155404 pParse->nNestSel--;
155405 assert( pParse->nNestSel>=0 );
155406 #endif
155407
155408 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
155409 pEList = pLeft->pEList;
155410 if( pCte->pCols ){
155411 if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){
@@ -156722,10 +156777,14 @@
156777 sqlite3PExprAddSelect(pParse, pTerm, pSub);
156778 if( pExpr==0 ){
156779 pExpr = pTerm;
156780 }else{
156781 pExpr = sqlite3PExpr(pParse, TK_PLUS, pTerm, pExpr);
156782 }
156783 if( pParse->nErr ){
156784 sqlite3ExprDelete(db, pExpr);
156785 pExpr = 0;
156786 }
156787 pSub = pPrior;
156788 }
156789 p->pEList->a[0].pExpr = pExpr;
156790 p->selFlags &= ~(u32)SF_Aggregate;
@@ -161221,10 +161280,11 @@
161280 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
161281 }else{
161282 sqlite3VdbeAddOp3(v, OP_Column, iEph, iRowidExpr, regNewRowid);
161283 }
161284 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
161285 sqlite3MayAbort(pParse);
161286 }
161287
161288 /* Compute the old pre-UPDATE content of the row being changed, if that
161289 ** information is needed */
161290 if( chngPk || hasFK || pTrigger ){
@@ -163769,10 +163829,21 @@
163829 pTab->tabFlags |= TF_Ephemeral;
163830 sqlite3DeleteTable(db, pTab);
163831 pMod->pEpoTab = 0;
163832 }
163833 }
163834
163835 /*
163836 ** Erase all eponymous virtual table instances associated with database
163837 ** handle db.
163838 */
163839 SQLITE_PRIVATE void sqlite3VtabEponymousTableClearAll(sqlite3 *db){
163840 HashElem *pElem;
163841 for(pElem=sqliteHashFirst(&db->aModule); pElem; pElem=sqliteHashNext(pElem)){
163842 sqlite3VtabEponymousTableClear(db, (Module*)sqliteHashData(pElem));
163843 }
163844 }
163845
163846 /*
163847 ** Return the ON CONFLICT resolution mode in effect for the virtual
163848 ** table update operation currently in progress.
163849 **
@@ -187762,14 +187833,14 @@
187833 #endif
187834
187835 /*
187836 ** Return zero if the given SQL string is complete - if all comments,
187837 ** string and blob literals, and quoted identifiers have been closed and
187838 ** if the entire string ends with ";" and possibly with ";END;" if the
187839 ** string is a CREATE TRIGGER statement. A non-zero return indicates
187840 ** that the string is empty or incomplete. Bits of the return value
187841 ** indicate what is missing and is needed to close out the statement.
187842 **
187843 ** Special handling is require for CREATE TRIGGER statements.
187844 ** Whenever the CREATE TRIGGER keywords are seen, the statement
187845 ** must end with ";END;".
187846 **
@@ -187777,15 +187848,16 @@
187848 ** subfields, at byte boundaries:
187849 **
187850 ** R = 0xwwwwwwww00xxyyzz
187851 **
187852 ** In other words, zz is the least significant byte, yy is the next
187853 ** most significant byte, xx is the third byte, wwwwwwww is the upper
187854 ** four bytes of the return value.
187855 **
187856 ** zz == SQLITE_OK Input is complete
187857 ** zz == SQLITE_ERROR Input is incomplete
187858 ** zz == SQLITE_EMPTY Input contains only whitespace
187859 ** zz == SQLITE_MISUSE Input is a NULL pointer
187860 ** zz != 0 New values for zz may be added in the future
187861 **
187862 ** yy == 0x01 Need a semicolon at the end
187863 ** yy == 0x02 Need "END" and a semicolon
@@ -187807,11 +187879,11 @@
187879 ** ((R>>24)&0xff)!=0 New uses for the 4th byte may be added
187880 ** in the future
187881 **
187882 ** This implementation uses a state machine with 8 states:
187883 **
187884 ** (0) NOTHING We have not yet seen a non-whitespace character.
187885 **
187886 ** (1) START At the beginning or end of an SQL statement. This routine
187887 ** returns 1 if it ends in the START state and 0 if it ends
187888 ** in any other state.
187889 **
@@ -187864,11 +187936,11 @@
187936 ** statement. This is the normal case.
187937 */
187938 static const u8 trans[8][8] = {
187939 /* Token: */
187940 /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
187941 /* 0 NOTHING: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
187942 /* 1 START: */ { 1, 1, 2, 3, 4, 2, 2, 2, },
187943 /* 2 NORMAL: */ { 1, 2, 2, 2, 2, 2, 2, 2, },
187944 /* 3 EXPLAIN: */ { 1, 3, 3, 2, 4, 2, 2, 2, },
187945 /* 4 CREATE: */ { 1, 4, 2, 2, 2, 4, 5, 2, },
187946 /* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, },
@@ -187880,18 +187952,18 @@
187952 ** used to detect the end of a statement is much simpler
187953 */
187954 static const u8 trans[3][3] = {
187955 /* Token: */
187956 /* State: ** SEMI WS OTHER */
187957 /* 0 NOTHING: */ { 1, 0, 2, },
187958 /* 1 START: */ { 1, 1, 2, },
187959 /* 2 NORMAL: */ { 1, 2, 2, },
187960 };
187961 #endif /* SQLITE_OMIT_TRIGGER */
187962 /* Mapping state number to yy value for the return */
187963 static const u8 statemap[8] = {
187964 /* 0 NOTHING */ 0,
187965 /* 1 START */ 0,
187966 /* 2 NORMAL */ 1,
187967 /* 3 EXPLAIN */ 1,
187968 /* 4 CREATE */ 1,
187969 /* 5 TRIGGER */ 3,
@@ -187925,10 +187997,11 @@
187997 break;
187998 }
187999 zSql += 2;
188000 while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
188001 if( zSql[0]==0 ){
188002 if( state==0 ) state = 2;
188003 pending = '/';
188004 goto incomplete_finish;
188005 }
188006 zSql++;
188007 token = tkWS;
@@ -188042,10 +188115,11 @@
188115 }
188116 state = trans[state][token];
188117 zSql++;
188118 }
188119 incomplete_finish:
188120 if( state==0 ) return SQLITE_EMPTY;
188121 if( state==1 ) nParen = 0;
188122 return (i64)((((u64)nParen)<<32) |
188123 ((u64)pending<<16) |
188124 ((u64)statemap[state]<<8) |
188125 (state!=1));
@@ -210496,10 +210570,11 @@
210570 SQLITE_PRIVATE int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk){
210571 int rc = SQLITE_OK; /* Return code */
210572 u64 cksum1 = 0; /* Checksum based on FTS index contents */
210573 u64 cksum2 = 0; /* Checksum based on %_content contents */
210574 sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
210575 int bContentless = (p->zContentTbl && p->zContentTbl[0]=='\0');
210576
210577 /* This block calculates the checksum according to the FTS index. */
210578 rc = fts3SqlStmt(p, SQL_SELECT_ALL_LANGID, &pAllLangid, 0);
210579 if( rc==SQLITE_OK ){
210580 int rc2;
@@ -210515,11 +210590,11 @@
210590 rc2 = sqlite3_reset(pAllLangid);
210591 if( rc==SQLITE_OK ) rc = rc2;
210592 }
210593
210594 /* This block calculates the checksum according to the %_content table */
210595 if( rc==SQLITE_OK && !bContentless ){
210596 sqlite3_tokenizer_module const *pModule = p->pTokenizer->pModule;
210597 sqlite3_stmt *pStmt = 0;
210598 char *zSql;
210599
210600 zSql = sqlite3_mprintf("SELECT %s" , p->zReadExprlist);
@@ -210573,11 +210648,11 @@
210648
210649 if( rc==SQLITE_CORRUPT_VTAB ){
210650 rc = SQLITE_OK;
210651 *pbOk = 0;
210652 }else{
210653 *pbOk = (rc==SQLITE_OK && (bContentless || cksum1==cksum2));
210654 }
210655 return rc;
210656 }
210657
210658 /*
@@ -224142,11 +224217,11 @@
224217 continue;
224218 }
224219 break;
224220 }
224221 if( geopolySkipSpace(&s)==']'
224222 && s.nVertex>=4 && s.nVertex<16777216
224223 && s.a[0]==s.a[s.nVertex*2-2]
224224 && s.a[1]==s.a[s.nVertex*2-1]
224225 && (s.z++, geopolySkipSpace(&s)==0)
224226 ){
224227 GeoPoly *pOut;
@@ -224479,11 +224554,11 @@
224554 sqlite3_value **argv
224555 ){
224556 double x = sqlite3_value_double(argv[0]);
224557 double y = sqlite3_value_double(argv[1]);
224558 double r = sqlite3_value_double(argv[2]);
224559 i64 n = sqlite3_value_int64(argv[3]);
224560 int i;
224561 GeoPoly *p;
224562 (void)argc;
224563
224564 if( n<3 || r<=0.0 || r>=1e300 ) return;
@@ -237743,10 +237818,37 @@
237818 if( pzErrmsg && rc!=SQLITE_OK ){
237819 *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
237820 }
237821 return rc;
237822 }
237823
237824 /*
237825 ** Prepare the statement specified by printf format zFmt and its trailing
237826 ** arguments.
237827 */
237828 static void sessionPrepareMprintf(
237829 int *pRc,
237830 sqlite3 *db,
237831 sqlite3_stmt **pp,
237832 char **pzErrmsg,
237833 const char *zFmt,
237834 ...
237835 ){
237836 if( *pRc==SQLITE_OK ){
237837 char *zSql;
237838 va_list ap;
237839 va_start(ap, zFmt);
237840 zSql = sqlite3_vmprintf(zFmt, ap);
237841 if( zSql==0 ){
237842 *pRc = SQLITE_NOMEM;
237843 }else{
237844 *pRc = sessionPrepare(db, pp, pzErrmsg, zSql);
237845 sqlite3_free(zSql);
237846 }
237847 va_end(ap);
237848 }
237849 }
237850
237851 /*
237852 ** Formulate and prepare a SELECT statement to retrieve a row from table
237853 ** zTab in database zDb based on its primary key. i.e.
237854 **
@@ -240147,165 +240249,219 @@
240249
240250 return rc;
240251 }
240252
240253 /*
240254 ** Buffer aUnique[] is pApply->nCol entries in size. This function sets
240255 ** aUnique[i] to true if column i of table zTab in the "main" database
240256 ** of db is part of at least one UNIQUE constraint, or to false otherwise.
240257 **
240258 ** If the table has a unique index on an expression, or a partial unique
240259 ** index, all entries of aUnique[] are set to true.
240260 **
240261 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
240262 */
240263 static int sessionUniqueColumns(
240264 sqlite3 *db, /* Database handle */
240265 const char *zTab, /* Table name */
240266 SessionApplyCtx *pApply, /* Apply context */
240267 u8 *aUnique /* OUT: Array of pApply->nCol flags */
240268 ){
240269 sqlite3_stmt *pList = 0; /* PRAGMA index_list */
240270 int rc = SQLITE_OK;
240271
240272 /* Ordinary PRAGMA statements are used here instead of the equivalent
240273 ** table-valued functions (pragma_index_list() etc.) so that this works
240274 ** in builds with SQLITE_OMIT_VIRTUALTABLE defined. */
240275 memset(aUnique, 0, pApply->nCol);
240276 sessionPrepareMprintf(&rc, db, &pList, &pApply->zErr,
240277 "PRAGMA main.index_list(%Q)", zTab
240278 );
240279 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
240280 /* Columns of PRAGMA index_list are (seq, name, unique, origin, partial) */
240281 const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
240282 int bUnique = sqlite3_column_int(pList, 2);
240283 int bPartial = sqlite3_column_int(pList, 4);
240284 sqlite3_stmt *pInfo = 0; /* PRAGMA index_xinfo */
240285
240286 if( bUnique==0 ) continue;
240287 sessionPrepareMprintf(&rc, db, &pInfo, &pApply->zErr,
240288 "PRAGMA main.index_xinfo(%Q)", zIdx
240289 );
240290 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pInfo) ){
240291 /* Columns of PRAGMA index_xinfo are (seqno, cid, name, desc, coll, key)*/
240292 int iCid = sqlite3_column_int(pInfo, 1);
240293 const char *zCol = (const char*)sqlite3_column_text(pInfo, 2);
240294 int bKey = sqlite3_column_int(pInfo, 5);
240295 int ii;
240296 if( bKey==0 ) continue;
240297 for(ii=0; ii<pApply->nCol; ii++){
240298 if( bPartial
240299 || iCid==-2
240300 || (zCol && 0==sqlite3_stricmp(zCol, pApply->azCol[ii]))
240301 ){
240302 aUnique[ii] = 1;
240303 }
240304 }
240305 }
240306 if( rc==SQLITE_OK ){
240307 rc = sqlite3_finalize(pInfo);
240308 }else{
240309 sqlite3_finalize(pInfo);
240310 }
240311 }
240312 if( rc==SQLITE_OK ){
240313 rc = sqlite3_finalize(pList);
240314 }else{
240315 sqlite3_finalize(pList);
240316 }
240317
240318 return rc;
240319 }
240320
240321 /*
240322 ** Iterator pUp points to an UPDATE change. This function updates the
240323 ** affected row to set each column modified by the UPDATE change that
240324 ** is also part of at least one UNIQUE constraint to a "random" value,
240325 ** and creates another UPDATE statement that may be used to later set
240326 ** all columns modified by pUp to the actual values required by pUp.
240327 **
240328 ** Each random value has the same type as the final value required by
240329 ** pUp for the same column:
240330 **
240331 ** NULL -> NULL
240332 ** INTEGER -> random()
240333 ** REAL -> random()
240334 ** TEXT -> CAST(random() AS TEXT)
240335 ** BLOB -> unhex(hex(random()))
240336 **
240337 ** If none of the columns modified by pUp are part of a UNIQUE constraint,
240338 ** then SQLITE_CONSTRAINT is returned.
240339 **
240340 ** If successful, SQLITE_OK is returned and output variable (*ppUpdate)
240341 ** is left pointing to a prepared UPDATE statement. It is the responsibility
240342 ** of the caller to eventually free this statement using sqlite3_finalize().
240343 ** Or, if an error occurs, an SQLite error code is returned and (*ppUpdate)
240344 ** set to NULL. pApply->zErr may be set to an error message in this case.
240345 ** Except - it is guaranteed that pApply->zErr is not set if SQLITE_CONSTRAINT
240346 ** is returned.
240347 */
240348 static int sessionUpdateToUpdate(
240349 sqlite3 *db, /* Database to write to */
240350 const char *zTab, /* Table name */
240351 SessionApplyCtx *pApply, /* Apply context */
240352 sqlite3_changeset_iter *pUp, /* Iterator pointing to UPDATE change */
240353 sqlite3_stmt **ppUpdate /* OUT: UPDATE statement */
240354 ){
240355 sqlite3_stmt *pRet = 0; /* UPDATE to set the final values */
240356 sqlite3_stmt *pRand = 0; /* UPDATE to set random values */
240357 int rc = SQLITE_OK;
240358 u8 *aUnique = 0; /* aUnique[i] true if col i is UNIQUE */
240359 SessionBuffer randset = {0, 0, 0};
240360 SessionBuffer upset = {0, 0, 0};
240361 SessionBuffer where = {0, 0, 0};
240362 int ii;
240363
240364 aUnique = (u8*)sqlite3_malloc64(pApply->nCol);
240365 if( aUnique==0 ){
240366 rc = SQLITE_NOMEM;
240367 }else{
240368 rc = sessionUniqueColumns(db, zTab, pApply, aUnique);
240369 }
240370
240371 /* Assuming a table structure like this:
240372 **
240373 ** CREATE TABLE x(a, b UNIQUE, c, d UNIQUE, e, PRIMARY KEY(a, c));
240374 **
240375 ** and an UPDATE change that sets column b to an integer, column d to
240376 ** a text value and column e to any value, the two statements prepared
240377 ** are:
240378 **
240379 ** UPDATE main.x SET b = random(), d = CAST(random() AS TEXT)
240380 ** WHERE a IS ?1 AND c IS ?3
240381 ** UPDATE main.x SET b = ?2, d = ?4, e = ?5 WHERE a IS ?1 AND c IS ?3
240382 */
240383 for(ii=0; rc==SQLITE_OK && ii<pApply->nCol; ii++){
240384 sqlite3_value *pNew = 0;
240385 if( pApply->abPK[ii] ){
240386 if( where.nBuf>0 ) sessionAppendStr(&where, " AND ", &rc);
240387 sessionAppendIdent(&where, pApply->azCol[ii], &rc);
240388 sessionAppendPrintf(&where, &rc, " IS ?%d", ii+1);
240389 }else if( (pNew = sessionChangesetNew(pUp, ii))!=0 ){
240390 if( aUnique[ii] ){
240391 const char *zRand = 0;
240392 switch( sqlite3_value_type(pNew) ){
240393 case SQLITE_NULL: zRand = "NULL"; break;
240394 case SQLITE_TEXT: zRand = "CAST(random() AS TEXT)"; break;
240395 case SQLITE_BLOB: zRand = "unhex(hex(random()))"; break;
240396 default: zRand = "random()"; break;
240397 }
240398 if( randset.nBuf>0 ) sessionAppendStr(&randset, ", ", &rc);
240399 sessionAppendIdent(&randset, pApply->azCol[ii], &rc);
240400 sessionAppendStr(&randset, " = ", &rc);
240401 sessionAppendStr(&randset, zRand, &rc);
240402 }
240403 if( upset.nBuf>0 ) sessionAppendStr(&upset, ", ", &rc);
240404 sessionAppendIdent(&upset, pApply->azCol[ii], &rc);
240405 sessionAppendPrintf(&upset, &rc, " = ?%d", ii+1);
240406 }
240407 }
240408
240409 if( rc==SQLITE_OK && randset.nBuf==0 ){
240410 /* None of the columns modified by this change are part of a UNIQUE
240411 ** constraint. So setting them to random values cannot help resolve
240412 ** a constraint conflict. Report this as a constraint failure. */
240413 rc = SQLITE_CONSTRAINT;
240414 }
240415
240416 sessionPrepareMprintf(&rc, db, &pRand, &pApply->zErr,
240417 "UPDATE main.\"%w\" SET %s WHERE %s",
240418 zTab, (char*)randset.aBuf, (char*)where.aBuf
240419 );
240420 sessionPrepareMprintf(&rc, db, &pRet, &pApply->zErr,
240421 "UPDATE main.\"%w\" SET %s WHERE %s",
240422 zTab, (char*)upset.aBuf, (char*)where.aBuf
240423 );
240424
240425 /* Bind the PK values to both statements, and the new.* values to pRet. */
240426 if( rc==SQLITE_OK ){
240427 rc = sessionBindRow(
240428 pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pRand
240429 );
240430 }
240431 if( rc==SQLITE_OK ){
240432 rc = sessionBindRow(
240433 pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pRet
240434 );
240435 }
240436 for(ii=0; rc==SQLITE_OK && ii<pApply->nCol; ii++){
240437 sqlite3_value *pNew = sessionChangesetNew(pUp, ii);
240438 if( pApply->abPK[ii]==0 && pNew ){
240439 rc = sessionBindValue(pRet, ii+1, pNew);
240440 }
240441 }
240442
240443 /* Evaluate the statement to set each modified column of the row to a random
240444 ** value. If this fails with a constraint error, SQLITE_CONSTRAINT is
240445 ** returned to the caller, but pApply->zErr is not set. */
240446 if( rc==SQLITE_OK ){
240447 sqlite3_step(pRand);
240448 rc = sqlite3_reset(pRand);
240449 }
240450 sqlite3_finalize(pRand);
 
 
 
240451
240452 if( rc!=SQLITE_OK ){
240453 sqlite3_finalize(pRet);
240454 pRet = 0;
240455 }
240456 *ppUpdate = pRet;
240457
240458 sqlite3_free(aUnique);
240459 sqlite3_free(randset.aBuf);
240460 sqlite3_free(upset.aBuf);
240461 sqlite3_free(where.aBuf);
240462
240463 return rc;
240464 }
240465
240466 /*
240467 ** Retry the changes accumulated in the pApply->constraints buffer. The
@@ -240318,18 +240474,21 @@
240474 ** is repeated until no further progress can be made.
240475 **
240476 ** 2) For each UPDATE change in the buffer, try the following in a
240477 ** savepoint transaction:
240478 **
240479 ** a) UPDATE the affected row, setting each column modified by the
240480 ** UPDATE change to a random value,
240481 ** b) Attempt step (1) with remaining changes,
240482 ** c) Attempt to UPDATE the affected row again, this time setting
240483 ** each modified column to the value required by the UPDATE change.
240484 **
240485 ** If both (a) and (c) succeed, the savepoint is committed and all
240486 ** successfully applied changes are removed from the buffer. Step (2)
240487 ** is then repeated. Otherwise, if either (a) or (c) fails with
240488 ** SQLITE_CONSTRAINT, the savepoint is rolled back and the next UPDATE
240489 ** in the buffer is tried.
240490 **
240491 ** 3) Once step (2) has been attempted for each UPDATE in the change,
240492 ** a final attempt is made to apply each remaining change. This time,
240493 ** if an SQLITE_CONSTRAINT error is encountered, the conflict handler
240494 ** is invoked and the user has to decide whether to omit the change
@@ -240364,12 +240523,13 @@
240523
240524 /* Step (2) */
240525 while( rc==SQLITE_OK && pApply->constraints.nBuf && !pApply->bNoUpdateLoop ){
240526 SessionBuffer cons = {0, 0, 0};
240527 sqlite3_changeset_iter *pUp = 0;
240528 sqlite3_stmt *pUpdate = 0;
240529 int iSkip = 0;
240530 int bConstraint = 0; /* True if an SQLITE_CONSTRAINT occurs */
240531
240532 rc = sessionRetryIterInit(
240533 &pApply->constraints, bPatchset, zTab, pApply, &pUp
240534 );
240535 if( rc==SQLITE_OK ){
@@ -240380,19 +240540,26 @@
240540 iSkip++;
240541 }
240542 if( iThis==iUpdate ){
240543 rc = sqlite3_exec(db, "SAVEPOINT update_op", 0, 0, 0);
240544 if( rc==SQLITE_OK ){
240545 rc = sessionUpdateToUpdate(db, zTab, pApply, pUp, &pUpdate);
240546 if( (rc&0xff)==SQLITE_CONSTRAINT ){
240547 bConstraint = 1;
240548 rc = SQLITE_OK;
240549 }
240550 }
240551 }
240552 sqlite3changeset_finalize(pUp);
240553 if( iThis!=iUpdate ) break;
240554 }
240555
240556 if( rc==SQLITE_OK ){
240557 cons = pApply->constraints;
240558 if( bConstraint ){
240559 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
240560 }
240561
240562 while( rc==SQLITE_OK && pApply->constraints.nBuf>0 ){
240563 SessionBuffer app = pApply->constraints;
240564 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
240565 rc = sessionApplyRetryBuffer(
@@ -240408,13 +240575,20 @@
240575 }
240576 }
240577
240578 iUpdate++;
240579 if( rc==SQLITE_OK ){
240580 if( bConstraint==0 ){
240581 sqlite3_step(pUpdate);
240582 rc = sqlite3_finalize(pUpdate);
240583 pUpdate = 0;
240584 if( (rc&0xff)==SQLITE_CONSTRAINT ){
240585 bConstraint = 1;
240586 rc = SQLITE_OK;
240587 }
240588 }
240589 if( bConstraint ){
240590 rc = sqlite3_exec(db, "ROLLBACK TO update_op", 0, 0, 0);
240591 sqlite3_free(pApply->constraints.aBuf);
240592 pApply->constraints = cons;
240593 memset(&cons, 0, sizeof(cons));
240594 }else if( rc==SQLITE_OK ){
@@ -240421,13 +240595,12 @@
240595 iUpdate = 0;
240596 }
240597 if( rc==SQLITE_OK ){
240598 rc = sqlite3_exec(db, "RELEASE update_op", 0, 0, 0);
240599 }
 
 
240600 }
240601 sqlite3_finalize(pUpdate);
240602
240603 sqlite3_free(cons.aBuf);
240604 }
240605
240606 /* Step (3) */
@@ -265203,11 +265376,11 @@
265376 int nArg, /* Number of args */
265377 sqlite3_value **apUnused /* Function arguments */
265378 ){
265379 assert( nArg==0 );
265380 UNUSED_PARAM2(nArg, apUnused);
265381 sqlite3_result_text(pCtx, "fts5: 2026-10-05 14:22:13 4bfc6e53a95d710b7f40fa9c80d8cdd1df50d69ed8614e9800f7e6a1ca5a3c29", -1, SQLITE_TRANSIENT);
265382 }
265383
265384 /*
265385 ** Implementation of fts5_locale(LOCALE, TEXT) function.
265386 **
265387
+10 -6
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.54.0"
150150
#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c"
151
+#define SQLITE_SOURCE_ID "2026-10-05 14:22:13 4bfc6e53a95d710b7f40fa9c80d8cdd1df50d69ed8614e9800f7e6a1ca5a3c29"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-10-01T11:21:02.802Z"
154
+#define SQLITE_SCM_DATETIME "2026-10-05T14:22:13.597Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -461,11 +461,11 @@
461461
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
462462
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
463463
#define SQLITE_FULL 13 /* Insertion failed because database is full */
464464
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
465465
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
466
-#define SQLITE_EMPTY 16 /* Internal use only */
466
+#define SQLITE_EMPTY 16 /* No content */
467467
#define SQLITE_SCHEMA 17 /* The database schema changed */
468468
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
469469
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
470470
#define SQLITE_MISMATCH 20 /* Data type mismatch */
471471
#define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -2973,14 +2973,18 @@
29732973
** ^The sqlite3_complete(X) and sqlite3_complete16(X) routines return 0
29742974
** if the statement is incomplete. ^If a memory allocation fails, then
29752975
** SQLITE_NOMEM is returned.
29762976
**
29772977
** The [sqlite3_incomplete(X)] routine is similar to [sqlite3_complete(X)]
2978
-** except that sqlite3_incomplete(X) returns 0 if the input X is complete
2979
-** and non-zero if X is incomplete. The non-zero return from
2978
+** except that sqlite3_incomplete(X) returns SQLITE_OK if the input X is
2979
+** complete, SQLITE_EMPTY if input X consists entirely of whitespace and/or
2980
+** comments, SQLITE_MISUSE if X is a NULL pointer, and some other non-zero
2981
+** value if X is incomplete. The non-zero return from
29802982
** sqlite3_incomplete(X) contains additional information about what is
2981
-** needed to complete the input X. The sqlite3_incomplete(X) interface
2983
+** needed to complete the input X. See the header comment on the
2984
+** implemenation of the sqlite3_incomplete() routine for a full description
2985
+** of its non-zero return values. The sqlite3_incomplete(X) interface
29822986
** is only available for UTF-8 text.
29832987
**
29842988
** ^None of these routines do a full parse the SQL statements and thus
29852989
** will not detect syntactically incorrect SQL. They only determine if
29862990
** input text has properly terminated comments, string literals, and
29872991
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-10-01T11:21:02.802Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -461,11 +461,11 @@
461 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
462 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
463 #define SQLITE_FULL 13 /* Insertion failed because database is full */
464 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
465 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
466 #define SQLITE_EMPTY 16 /* Internal use only */
467 #define SQLITE_SCHEMA 17 /* The database schema changed */
468 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
469 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
470 #define SQLITE_MISMATCH 20 /* Data type mismatch */
471 #define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -2973,14 +2973,18 @@
2973 ** ^The sqlite3_complete(X) and sqlite3_complete16(X) routines return 0
2974 ** if the statement is incomplete. ^If a memory allocation fails, then
2975 ** SQLITE_NOMEM is returned.
2976 **
2977 ** The [sqlite3_incomplete(X)] routine is similar to [sqlite3_complete(X)]
2978 ** except that sqlite3_incomplete(X) returns 0 if the input X is complete
2979 ** and non-zero if X is incomplete. The non-zero return from
 
 
2980 ** sqlite3_incomplete(X) contains additional information about what is
2981 ** needed to complete the input X. The sqlite3_incomplete(X) interface
 
 
2982 ** is only available for UTF-8 text.
2983 **
2984 ** ^None of these routines do a full parse the SQL statements and thus
2985 ** will not detect syntactically incorrect SQL. They only determine if
2986 ** input text has properly terminated comments, string literals, and
2987
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-10-05 14:22:13 4bfc6e53a95d710b7f40fa9c80d8cdd1df50d69ed8614e9800f7e6a1ca5a3c29"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-10-05T14:22:13.597Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -461,11 +461,11 @@
461 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
462 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
463 #define SQLITE_FULL 13 /* Insertion failed because database is full */
464 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
465 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
466 #define SQLITE_EMPTY 16 /* No content */
467 #define SQLITE_SCHEMA 17 /* The database schema changed */
468 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
469 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
470 #define SQLITE_MISMATCH 20 /* Data type mismatch */
471 #define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -2973,14 +2973,18 @@
2973 ** ^The sqlite3_complete(X) and sqlite3_complete16(X) routines return 0
2974 ** if the statement is incomplete. ^If a memory allocation fails, then
2975 ** SQLITE_NOMEM is returned.
2976 **
2977 ** The [sqlite3_incomplete(X)] routine is similar to [sqlite3_complete(X)]
2978 ** except that sqlite3_incomplete(X) returns SQLITE_OK if the input X is
2979 ** complete, SQLITE_EMPTY if input X consists entirely of whitespace and/or
2980 ** comments, SQLITE_MISUSE if X is a NULL pointer, and some other non-zero
2981 ** value if X is incomplete. The non-zero return from
2982 ** sqlite3_incomplete(X) contains additional information about what is
2983 ** needed to complete the input X. See the header comment on the
2984 ** implemenation of the sqlite3_incomplete() routine for a full description
2985 ** of its non-zero return values. The sqlite3_incomplete(X) interface
2986 ** is only available for UTF-8 text.
2987 **
2988 ** ^None of these routines do a full parse the SQL statements and thus
2989 ** will not detect syntactically incorrect SQL. They only determine if
2990 ** input text has properly terminated comments, string literals, and
2991

Keyboard Shortcuts

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