Fossil SCM

Update the built-in SQLite to the latest trunk check-in for testing.

drh 2025-09-24 19:29 trunk
Commit 3041904dae0a881cf57bf046b39ec17e9f2d3f2996a22f7a0ce389ca2cd5671e
+64 -43
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1154,11 +1154,11 @@
11541154
}
11551155
if( (z[0] & 0xf8)==0xf0 && (z[1] & 0xc0)==0x80 && (z[2] & 0xc0)==0x80
11561156
&& (z[3] & 0xc0)==0x80
11571157
){
11581158
*pU = ((z[0] & 0x0f)<<18) | ((z[1] & 0x3f)<<12) | ((z[2] & 0x3f))<<6
1159
- | (z[4] & 0x3f);
1159
+ | (z[3] & 0x3f);
11601160
return 4;
11611161
}
11621162
*pU = 0;
11631163
return 1;
11641164
}
@@ -1217,18 +1217,28 @@
12171217
** since with %*.*s the width is measured in bytes, not characters.
12181218
**
12191219
** Take into account zero-width and double-width Unicode characters.
12201220
** In other words, a zero-width character does not count toward the
12211221
** the w limit. A double-width character counts as two.
1222
+**
1223
+** w should normally be a small number. A couple hundred at most. This
1224
+** routine caps w at 100 million to avoid integer overflow issues.
12221225
*/
12231226
static void utf8_width_print(FILE *out, int w, const char *zUtf){
12241227
const unsigned char *a = (const unsigned char*)zUtf;
1228
+ static const int mxW = 10000000;
12251229
unsigned char c;
12261230
int i = 0;
12271231
int n = 0;
12281232
int k;
1229
- int aw = w<0 ? -w : w;
1233
+ int aw;
1234
+ if( w<-mxW ){
1235
+ w = -mxW;
1236
+ }else if( w>mxW ){
1237
+ w= mxW;
1238
+ }
1239
+ aw = w<0 ? -w : w;
12301240
if( zUtf==0 ) zUtf = "";
12311241
while( (c = a[i])!=0 ){
12321242
if( (c&0xc0)==0xc0 ){
12331243
int u;
12341244
int len = decodeUtf8(a+i, &u);
@@ -1449,14 +1459,18 @@
14491459
return -1;
14501460
}
14511461
14521462
/*
14531463
** Interpret zArg as an integer value, possibly with suffixes.
1464
+**
1465
+** If the value specified by zArg is outside the range of values that
1466
+** can be represented using a 64-bit twos-complement integer, then return
1467
+** the nearest representable value.
14541468
*/
14551469
static sqlite3_int64 integerValue(const char *zArg){
1456
- sqlite3_int64 v = 0;
1457
- static const struct { char *zSuffix; int iMult; } aMult[] = {
1470
+ sqlite3_uint64 v = 0;
1471
+ static const struct { char *zSuffix; unsigned int iMult; } aMult[] = {
14581472
{ "KiB", 1024 },
14591473
{ "MiB", 1024*1024 },
14601474
{ "GiB", 1024*1024*1024 },
14611475
{ "KB", 1000 },
14621476
{ "MB", 1000000 },
@@ -1475,26 +1489,34 @@
14751489
}
14761490
if( zArg[0]=='0' && zArg[1]=='x' ){
14771491
int x;
14781492
zArg += 2;
14791493
while( (x = hexDigitValue(zArg[0]))>=0 ){
1494
+ if( v > 0x0fffffffffffffffULL ) goto integer_overflow;
14801495
v = (v<<4) + x;
14811496
zArg++;
14821497
}
14831498
}else{
14841499
while( IsDigit(zArg[0]) ){
1485
- v = v*10 + zArg[0] - '0';
1500
+ if( v>=922337203685477580 ){
1501
+ if( v>922337203685477580 || zArg[0]>='8' ) goto integer_overflow;
1502
+ }
1503
+ v = v*10 + (zArg[0] - '0');
14861504
zArg++;
14871505
}
14881506
}
14891507
for(i=0; i<ArraySize(aMult); i++){
14901508
if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
1509
+ if( 0x7fffffffffffffffULL/aMult[i].iMult < v ) goto integer_overflow;
14911510
v *= aMult[i].iMult;
14921511
break;
14931512
}
14941513
}
1495
- return isNeg? -v : v;
1514
+ if( isNeg && v>0x7fffffffffffffffULL ) goto integer_overflow;
1515
+ return isNeg? -(sqlite3_int64)v : (sqlite3_int64)v;
1516
+integer_overflow:
1517
+ return isNeg ? 0x8000000000000000LL : 0x7fffffffffffffffLL;
14961518
}
14971519
14981520
/*
14991521
** A variable length string to which one can append text.
15001522
*/
@@ -3726,10 +3748,14 @@
37263748
memset(p->a, 0, iExp);
37273749
p->nDigit += iExp;
37283750
p->nFrac += iExp;
37293751
}
37303752
}
3753
+ if( p->sign ){
3754
+ for(i=0; i<p->nDigit && p->a[i]==0; i++){}
3755
+ if( i>=p->nDigit ) p->sign = 0;
3756
+ }
37313757
return p;
37323758
37333759
new_from_text_failed:
37343760
if( p ){
37353761
if( p->a ) sqlite3_free(p->a);
@@ -3928,17 +3954,25 @@
39283954
** pA!=0
39293955
** pA->isNull==0
39303956
** pB!=0
39313957
** pB->isNull==0
39323958
*/
3933
-static int decimal_cmp(const Decimal *pA, const Decimal *pB){
3959
+static int decimal_cmp(Decimal *pA, Decimal *pB){
39343960
int nASig, nBSig, rc, n;
3961
+ while( pA->nFrac>0 && pA->a[pA->nDigit-1]==0 ){
3962
+ pA->nDigit--;
3963
+ pA->nFrac--;
3964
+ }
3965
+ while( pB->nFrac>0 && pB->a[pB->nDigit-1]==0 ){
3966
+ pB->nDigit--;
3967
+ pB->nFrac--;
3968
+ }
39353969
if( pA->sign!=pB->sign ){
39363970
return pA->sign ? -1 : +1;
39373971
}
39383972
if( pA->sign ){
3939
- const Decimal *pTemp = pA;
3973
+ Decimal *pTemp = pA;
39403974
pA = pB;
39413975
pB = pTemp;
39423976
}
39433977
nASig = pA->nDigit - pA->nFrac;
39443978
nBSig = pB->nDigit - pB->nFrac;
@@ -4183,11 +4217,11 @@
41834217
r = -r;
41844218
}else{
41854219
isNeg = 0;
41864220
}
41874221
memcpy(&a,&r,sizeof(a));
4188
- if( a==0 ){
4222
+ if( a==0 || a==(sqlite3_int64)0x8000000000000000LL){
41894223
e = 0;
41904224
m = 0;
41914225
}else{
41924226
e = a>>52;
41934227
m = a & ((((sqlite3_int64)1)<<52)-1);
@@ -5176,20 +5210,21 @@
51765210
return pOut;
51775211
}
51785212
51795213
/* This function does the work for the SQLite base64(x) UDF. */
51805214
static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
5181
- int nb, nc, nv = sqlite3_value_bytes(av[0]);
5215
+ int nb, nv = sqlite3_value_bytes(av[0]);
5216
+ sqlite3_int64 nc;
51825217
int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
51835218
SQLITE_LIMIT_LENGTH, -1);
51845219
char *cBuf;
51855220
u8 *bBuf;
51865221
assert(na==1);
51875222
switch( sqlite3_value_type(av[0]) ){
51885223
case SQLITE_BLOB:
51895224
nb = nv;
5190
- nc = 4*(nv+2/3); /* quads needed */
5225
+ nc = 4*((nv+2)/3); /* quads needed */
51915226
nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
51925227
if( nvMax < nc ){
51935228
sqlite3_result_error(context, "blob expanded to base64 too big", -1);
51945229
return;
51955230
}
@@ -5861,10 +5896,13 @@
58615896
}
58625897
memcpy(&a,&r,sizeof(a));
58635898
if( a==0 ){
58645899
e = 0;
58655900
m = 0;
5901
+ }else if( a==(sqlite3_int64)0x8000000000000000LL ){
5902
+ e = -1996;
5903
+ m = -1;
58665904
}else{
58675905
e = a>>52;
58685906
m = a & ((((sqlite3_int64)1)<<52)-1);
58695907
if( e==0 ){
58705908
m <<= 1;
@@ -6621,10 +6659,14 @@
66216659
if( iOffset>0 ){
66226660
pCur->ss.iBase += pCur->ss.iStep*iOffset;
66236661
}
66246662
if( iLimit>=0 ){
66256663
sqlite3_int64 iTerm;
6664
+ sqlite3_int64 mxLimit;
6665
+ assert( pCur->ss.iStep>0 );
6666
+ mxLimit = (LARGEST_INT64 - pCur->ss.iBase)/pCur->ss.iStep;
6667
+ if( iLimit>mxLimit ) iLimit = mxLimit;
66266668
iTerm = pCur->ss.iBase + (iLimit - 1)*pCur->ss.iStep;
66276669
if( pCur->ss.iStep<0 ){
66286670
if( iTerm>pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
66296671
}else{
66306672
if( iTerm<pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
@@ -23328,32 +23370,16 @@
2332823370
** Set the destination table field of the ShellState structure to
2332923371
** the name of the table given. Escape any quote characters in the
2333023372
** table name.
2333123373
*/
2333223374
static void set_table_name(ShellState *p, const char *zName){
23333
- int i, n;
23334
- char cQuote;
23335
- char *z;
23336
-
2333723375
if( p->zDestTable ){
23338
- free(p->zDestTable);
23376
+ sqlite3_free(p->zDestTable);
2333923377
p->zDestTable = 0;
2334023378
}
2334123379
if( zName==0 ) return;
23342
- cQuote = quoteChar(zName);
23343
- n = strlen30(zName);
23344
- if( cQuote ) n += n+2;
23345
- z = p->zDestTable = malloc( n+1 );
23346
- shell_check_oom(z);
23347
- n = 0;
23348
- if( cQuote ) z[n++] = cQuote;
23349
- for(i=0; zName[i]; i++){
23350
- z[n++] = zName[i];
23351
- if( zName[i]==cQuote ) z[n++] = cQuote;
23352
- }
23353
- if( cQuote ) z[n++] = cQuote;
23354
- z[n] = 0;
23380
+ p->zDestTable = sqlite3_mprintf("\"%w\"", zName);
2335523381
}
2335623382
2335723383
/*
2335823384
** Maybe construct two lines of text that point out the position of a
2335923385
** syntax error. Return a pointer to the text, in memory obtained from
@@ -26879,14 +26905,17 @@
2687926905
#if SQLITE_SHELL_HAVE_RECOVER
2688026906
/*
2688126907
** Convert a 2-byte or 4-byte big-endian integer into a native integer
2688226908
*/
2688326909
static unsigned int get2byteInt(unsigned char *a){
26884
- return (a[0]<<8) + a[1];
26910
+ return ((unsigned int)a[0]<<8) + (unsigned int)a[1];
2688526911
}
2688626912
static unsigned int get4byteInt(unsigned char *a){
26887
- return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
26913
+ return ((unsigned int)a[0]<<24)
26914
+ + ((unsigned int)a[1]<<16)
26915
+ + ((unsigned int)a[2]<<8)
26916
+ + (unsigned int)a[3];
2688826917
}
2688926918
2689026919
/*
2689126920
** Implementation of the ".dbinfo" command.
2689226921
**
@@ -27019,11 +27048,11 @@
2701927048
if( sqlite3_step(pStmt)!=SQLITE_ROW ) goto dbtotxt_error;
2702027049
nPage = sqlite3_column_int64(pStmt, 0);
2702127050
sqlite3_finalize(pStmt);
2702227051
pStmt = 0;
2702327052
if( nPage<1 ) goto dbtotxt_error;
27024
- rc = sqlite3_prepare_v2(p->db, "PRAGMA databases", -1, &pStmt, 0);
27053
+ rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
2702527054
if( rc ) goto dbtotxt_error;
2702627055
if( sqlite3_step(pStmt)!=SQLITE_ROW ){
2702727056
zTail = "unk.db";
2702827057
}else{
2702927058
const char *zFilename = (const char*)sqlite3_column_text(pStmt, 2);
@@ -27030,10 +27059,11 @@
2703027059
if( zFilename==0 || zFilename[0]==0 ) zFilename = "unk.db";
2703127060
zTail = strrchr(zFilename, '/');
2703227061
#if defined(_WIN32)
2703327062
if( zTail==0 ) zTail = strrchr(zFilename, '\\');
2703427063
#endif
27064
+ if( zTail && zTail[1]!=0 ) zTail++;
2703527065
}
2703627066
zName = strdup(zTail);
2703727067
shell_check_oom(zName);
2703827068
sqlite3_fprintf(p->out, "| size %lld pagesize %d filename %s\n",
2703927069
nPage*pgSz, pgSz, zName);
@@ -29890,16 +29920,10 @@
2989029920
sqlite3_stmt *pStmt;
2989129921
int tnum = 0;
2989229922
int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
2989329923
int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
2989429924
int i;
29895
- if( !ShellHasFlag(p,SHFLG_TestingMode) ){
29896
- sqlite3_fprintf(stderr,".%s unavailable without --unsafe-testing\n",
29897
- "imposter");
29898
- rc = 1;
29899
- goto meta_command_exit;
29900
- }
2990129925
if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
2990229926
eputz("Usage: .imposter INDEX IMPOSTER\n"
2990329927
" .imposter off\n");
2990429928
/* Also allowed, but not documented:
2990529929
**
@@ -29967,22 +29991,19 @@
2996729991
if( lenPK==0 ) lenPK = 100000;
2996829992
zSql = sqlite3_mprintf(
2996929993
"CREATE TABLE \"%w\"(%s,PRIMARY KEY(%.*s))WITHOUT ROWID",
2997029994
azArg[2], zCollist, lenPK, zCollist);
2997129995
sqlite3_free(zCollist);
29972
- rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
29996
+ rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 2, tnum);
2997329997
if( rc==SQLITE_OK ){
2997429998
rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
2997529999
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
2997630000
if( rc ){
2997730001
sqlite3_fprintf(stderr,
2997830002
"Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
2997930003
}else{
2998030004
sqlite3_fprintf(stdout, "%s;\n", zSql);
29981
- sqlite3_fprintf(stdout,
29982
- "WARNING: writing to an imposter table will corrupt"
29983
- " the \"%s\" %s!\n", azArg[1], isWO ? "table" : "index");
2998430005
}
2998530006
}else{
2998630007
sqlite3_fprintf(stderr,"SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
2998730008
rc = 1;
2998830009
}
@@ -31868,11 +31889,11 @@
3186831889
{ 0x00000020, 1, "CoverIdxScan" },
3186931890
{ 0x00000040, 1, "OrderByIdxJoin" },
3187031891
{ 0x00000080, 1, "Transitive" },
3187131892
{ 0x00000100, 1, "OmitNoopJoin" },
3187231893
{ 0x00000200, 1, "CountOfView" },
31873
- { 0x00000400, 1, "CurosrHints" },
31894
+ { 0x00000400, 1, "CursorHints" },
3187431895
{ 0x00000800, 1, "Stat4" },
3187531896
{ 0x00001000, 1, "PushDown" },
3187631897
{ 0x00002000, 1, "SimplifyJoin" },
3187731898
{ 0x00004000, 1, "SkipScan" },
3187831899
{ 0x00008000, 1, "PropagateConst" },
3187931900
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1154,11 +1154,11 @@
1154 }
1155 if( (z[0] & 0xf8)==0xf0 && (z[1] & 0xc0)==0x80 && (z[2] & 0xc0)==0x80
1156 && (z[3] & 0xc0)==0x80
1157 ){
1158 *pU = ((z[0] & 0x0f)<<18) | ((z[1] & 0x3f)<<12) | ((z[2] & 0x3f))<<6
1159 | (z[4] & 0x3f);
1160 return 4;
1161 }
1162 *pU = 0;
1163 return 1;
1164 }
@@ -1217,18 +1217,28 @@
1217 ** since with %*.*s the width is measured in bytes, not characters.
1218 **
1219 ** Take into account zero-width and double-width Unicode characters.
1220 ** In other words, a zero-width character does not count toward the
1221 ** the w limit. A double-width character counts as two.
 
 
 
1222 */
1223 static void utf8_width_print(FILE *out, int w, const char *zUtf){
1224 const unsigned char *a = (const unsigned char*)zUtf;
 
1225 unsigned char c;
1226 int i = 0;
1227 int n = 0;
1228 int k;
1229 int aw = w<0 ? -w : w;
 
 
 
 
 
 
1230 if( zUtf==0 ) zUtf = "";
1231 while( (c = a[i])!=0 ){
1232 if( (c&0xc0)==0xc0 ){
1233 int u;
1234 int len = decodeUtf8(a+i, &u);
@@ -1449,14 +1459,18 @@
1449 return -1;
1450 }
1451
1452 /*
1453 ** Interpret zArg as an integer value, possibly with suffixes.
 
 
 
 
1454 */
1455 static sqlite3_int64 integerValue(const char *zArg){
1456 sqlite3_int64 v = 0;
1457 static const struct { char *zSuffix; int iMult; } aMult[] = {
1458 { "KiB", 1024 },
1459 { "MiB", 1024*1024 },
1460 { "GiB", 1024*1024*1024 },
1461 { "KB", 1000 },
1462 { "MB", 1000000 },
@@ -1475,26 +1489,34 @@
1475 }
1476 if( zArg[0]=='0' && zArg[1]=='x' ){
1477 int x;
1478 zArg += 2;
1479 while( (x = hexDigitValue(zArg[0]))>=0 ){
 
1480 v = (v<<4) + x;
1481 zArg++;
1482 }
1483 }else{
1484 while( IsDigit(zArg[0]) ){
1485 v = v*10 + zArg[0] - '0';
 
 
 
1486 zArg++;
1487 }
1488 }
1489 for(i=0; i<ArraySize(aMult); i++){
1490 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
 
1491 v *= aMult[i].iMult;
1492 break;
1493 }
1494 }
1495 return isNeg? -v : v;
 
 
 
1496 }
1497
1498 /*
1499 ** A variable length string to which one can append text.
1500 */
@@ -3726,10 +3748,14 @@
3726 memset(p->a, 0, iExp);
3727 p->nDigit += iExp;
3728 p->nFrac += iExp;
3729 }
3730 }
 
 
 
 
3731 return p;
3732
3733 new_from_text_failed:
3734 if( p ){
3735 if( p->a ) sqlite3_free(p->a);
@@ -3928,17 +3954,25 @@
3928 ** pA!=0
3929 ** pA->isNull==0
3930 ** pB!=0
3931 ** pB->isNull==0
3932 */
3933 static int decimal_cmp(const Decimal *pA, const Decimal *pB){
3934 int nASig, nBSig, rc, n;
 
 
 
 
 
 
 
 
3935 if( pA->sign!=pB->sign ){
3936 return pA->sign ? -1 : +1;
3937 }
3938 if( pA->sign ){
3939 const Decimal *pTemp = pA;
3940 pA = pB;
3941 pB = pTemp;
3942 }
3943 nASig = pA->nDigit - pA->nFrac;
3944 nBSig = pB->nDigit - pB->nFrac;
@@ -4183,11 +4217,11 @@
4183 r = -r;
4184 }else{
4185 isNeg = 0;
4186 }
4187 memcpy(&a,&r,sizeof(a));
4188 if( a==0 ){
4189 e = 0;
4190 m = 0;
4191 }else{
4192 e = a>>52;
4193 m = a & ((((sqlite3_int64)1)<<52)-1);
@@ -5176,20 +5210,21 @@
5176 return pOut;
5177 }
5178
5179 /* This function does the work for the SQLite base64(x) UDF. */
5180 static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
5181 int nb, nc, nv = sqlite3_value_bytes(av[0]);
 
5182 int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
5183 SQLITE_LIMIT_LENGTH, -1);
5184 char *cBuf;
5185 u8 *bBuf;
5186 assert(na==1);
5187 switch( sqlite3_value_type(av[0]) ){
5188 case SQLITE_BLOB:
5189 nb = nv;
5190 nc = 4*(nv+2/3); /* quads needed */
5191 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
5192 if( nvMax < nc ){
5193 sqlite3_result_error(context, "blob expanded to base64 too big", -1);
5194 return;
5195 }
@@ -5861,10 +5896,13 @@
5861 }
5862 memcpy(&a,&r,sizeof(a));
5863 if( a==0 ){
5864 e = 0;
5865 m = 0;
 
 
 
5866 }else{
5867 e = a>>52;
5868 m = a & ((((sqlite3_int64)1)<<52)-1);
5869 if( e==0 ){
5870 m <<= 1;
@@ -6621,10 +6659,14 @@
6621 if( iOffset>0 ){
6622 pCur->ss.iBase += pCur->ss.iStep*iOffset;
6623 }
6624 if( iLimit>=0 ){
6625 sqlite3_int64 iTerm;
 
 
 
 
6626 iTerm = pCur->ss.iBase + (iLimit - 1)*pCur->ss.iStep;
6627 if( pCur->ss.iStep<0 ){
6628 if( iTerm>pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
6629 }else{
6630 if( iTerm<pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
@@ -23328,32 +23370,16 @@
23328 ** Set the destination table field of the ShellState structure to
23329 ** the name of the table given. Escape any quote characters in the
23330 ** table name.
23331 */
23332 static void set_table_name(ShellState *p, const char *zName){
23333 int i, n;
23334 char cQuote;
23335 char *z;
23336
23337 if( p->zDestTable ){
23338 free(p->zDestTable);
23339 p->zDestTable = 0;
23340 }
23341 if( zName==0 ) return;
23342 cQuote = quoteChar(zName);
23343 n = strlen30(zName);
23344 if( cQuote ) n += n+2;
23345 z = p->zDestTable = malloc( n+1 );
23346 shell_check_oom(z);
23347 n = 0;
23348 if( cQuote ) z[n++] = cQuote;
23349 for(i=0; zName[i]; i++){
23350 z[n++] = zName[i];
23351 if( zName[i]==cQuote ) z[n++] = cQuote;
23352 }
23353 if( cQuote ) z[n++] = cQuote;
23354 z[n] = 0;
23355 }
23356
23357 /*
23358 ** Maybe construct two lines of text that point out the position of a
23359 ** syntax error. Return a pointer to the text, in memory obtained from
@@ -26879,14 +26905,17 @@
26879 #if SQLITE_SHELL_HAVE_RECOVER
26880 /*
26881 ** Convert a 2-byte or 4-byte big-endian integer into a native integer
26882 */
26883 static unsigned int get2byteInt(unsigned char *a){
26884 return (a[0]<<8) + a[1];
26885 }
26886 static unsigned int get4byteInt(unsigned char *a){
26887 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
 
 
 
26888 }
26889
26890 /*
26891 ** Implementation of the ".dbinfo" command.
26892 **
@@ -27019,11 +27048,11 @@
27019 if( sqlite3_step(pStmt)!=SQLITE_ROW ) goto dbtotxt_error;
27020 nPage = sqlite3_column_int64(pStmt, 0);
27021 sqlite3_finalize(pStmt);
27022 pStmt = 0;
27023 if( nPage<1 ) goto dbtotxt_error;
27024 rc = sqlite3_prepare_v2(p->db, "PRAGMA databases", -1, &pStmt, 0);
27025 if( rc ) goto dbtotxt_error;
27026 if( sqlite3_step(pStmt)!=SQLITE_ROW ){
27027 zTail = "unk.db";
27028 }else{
27029 const char *zFilename = (const char*)sqlite3_column_text(pStmt, 2);
@@ -27030,10 +27059,11 @@
27030 if( zFilename==0 || zFilename[0]==0 ) zFilename = "unk.db";
27031 zTail = strrchr(zFilename, '/');
27032 #if defined(_WIN32)
27033 if( zTail==0 ) zTail = strrchr(zFilename, '\\');
27034 #endif
 
27035 }
27036 zName = strdup(zTail);
27037 shell_check_oom(zName);
27038 sqlite3_fprintf(p->out, "| size %lld pagesize %d filename %s\n",
27039 nPage*pgSz, pgSz, zName);
@@ -29890,16 +29920,10 @@
29890 sqlite3_stmt *pStmt;
29891 int tnum = 0;
29892 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
29893 int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
29894 int i;
29895 if( !ShellHasFlag(p,SHFLG_TestingMode) ){
29896 sqlite3_fprintf(stderr,".%s unavailable without --unsafe-testing\n",
29897 "imposter");
29898 rc = 1;
29899 goto meta_command_exit;
29900 }
29901 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
29902 eputz("Usage: .imposter INDEX IMPOSTER\n"
29903 " .imposter off\n");
29904 /* Also allowed, but not documented:
29905 **
@@ -29967,22 +29991,19 @@
29967 if( lenPK==0 ) lenPK = 100000;
29968 zSql = sqlite3_mprintf(
29969 "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%.*s))WITHOUT ROWID",
29970 azArg[2], zCollist, lenPK, zCollist);
29971 sqlite3_free(zCollist);
29972 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
29973 if( rc==SQLITE_OK ){
29974 rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
29975 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
29976 if( rc ){
29977 sqlite3_fprintf(stderr,
29978 "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
29979 }else{
29980 sqlite3_fprintf(stdout, "%s;\n", zSql);
29981 sqlite3_fprintf(stdout,
29982 "WARNING: writing to an imposter table will corrupt"
29983 " the \"%s\" %s!\n", azArg[1], isWO ? "table" : "index");
29984 }
29985 }else{
29986 sqlite3_fprintf(stderr,"SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
29987 rc = 1;
29988 }
@@ -31868,11 +31889,11 @@
31868 { 0x00000020, 1, "CoverIdxScan" },
31869 { 0x00000040, 1, "OrderByIdxJoin" },
31870 { 0x00000080, 1, "Transitive" },
31871 { 0x00000100, 1, "OmitNoopJoin" },
31872 { 0x00000200, 1, "CountOfView" },
31873 { 0x00000400, 1, "CurosrHints" },
31874 { 0x00000800, 1, "Stat4" },
31875 { 0x00001000, 1, "PushDown" },
31876 { 0x00002000, 1, "SimplifyJoin" },
31877 { 0x00004000, 1, "SkipScan" },
31878 { 0x00008000, 1, "PropagateConst" },
31879
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1154,11 +1154,11 @@
1154 }
1155 if( (z[0] & 0xf8)==0xf0 && (z[1] & 0xc0)==0x80 && (z[2] & 0xc0)==0x80
1156 && (z[3] & 0xc0)==0x80
1157 ){
1158 *pU = ((z[0] & 0x0f)<<18) | ((z[1] & 0x3f)<<12) | ((z[2] & 0x3f))<<6
1159 | (z[3] & 0x3f);
1160 return 4;
1161 }
1162 *pU = 0;
1163 return 1;
1164 }
@@ -1217,18 +1217,28 @@
1217 ** since with %*.*s the width is measured in bytes, not characters.
1218 **
1219 ** Take into account zero-width and double-width Unicode characters.
1220 ** In other words, a zero-width character does not count toward the
1221 ** the w limit. A double-width character counts as two.
1222 **
1223 ** w should normally be a small number. A couple hundred at most. This
1224 ** routine caps w at 100 million to avoid integer overflow issues.
1225 */
1226 static void utf8_width_print(FILE *out, int w, const char *zUtf){
1227 const unsigned char *a = (const unsigned char*)zUtf;
1228 static const int mxW = 10000000;
1229 unsigned char c;
1230 int i = 0;
1231 int n = 0;
1232 int k;
1233 int aw;
1234 if( w<-mxW ){
1235 w = -mxW;
1236 }else if( w>mxW ){
1237 w= mxW;
1238 }
1239 aw = w<0 ? -w : w;
1240 if( zUtf==0 ) zUtf = "";
1241 while( (c = a[i])!=0 ){
1242 if( (c&0xc0)==0xc0 ){
1243 int u;
1244 int len = decodeUtf8(a+i, &u);
@@ -1449,14 +1459,18 @@
1459 return -1;
1460 }
1461
1462 /*
1463 ** Interpret zArg as an integer value, possibly with suffixes.
1464 **
1465 ** If the value specified by zArg is outside the range of values that
1466 ** can be represented using a 64-bit twos-complement integer, then return
1467 ** the nearest representable value.
1468 */
1469 static sqlite3_int64 integerValue(const char *zArg){
1470 sqlite3_uint64 v = 0;
1471 static const struct { char *zSuffix; unsigned int iMult; } aMult[] = {
1472 { "KiB", 1024 },
1473 { "MiB", 1024*1024 },
1474 { "GiB", 1024*1024*1024 },
1475 { "KB", 1000 },
1476 { "MB", 1000000 },
@@ -1475,26 +1489,34 @@
1489 }
1490 if( zArg[0]=='0' && zArg[1]=='x' ){
1491 int x;
1492 zArg += 2;
1493 while( (x = hexDigitValue(zArg[0]))>=0 ){
1494 if( v > 0x0fffffffffffffffULL ) goto integer_overflow;
1495 v = (v<<4) + x;
1496 zArg++;
1497 }
1498 }else{
1499 while( IsDigit(zArg[0]) ){
1500 if( v>=922337203685477580 ){
1501 if( v>922337203685477580 || zArg[0]>='8' ) goto integer_overflow;
1502 }
1503 v = v*10 + (zArg[0] - '0');
1504 zArg++;
1505 }
1506 }
1507 for(i=0; i<ArraySize(aMult); i++){
1508 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
1509 if( 0x7fffffffffffffffULL/aMult[i].iMult < v ) goto integer_overflow;
1510 v *= aMult[i].iMult;
1511 break;
1512 }
1513 }
1514 if( isNeg && v>0x7fffffffffffffffULL ) goto integer_overflow;
1515 return isNeg? -(sqlite3_int64)v : (sqlite3_int64)v;
1516 integer_overflow:
1517 return isNeg ? 0x8000000000000000LL : 0x7fffffffffffffffLL;
1518 }
1519
1520 /*
1521 ** A variable length string to which one can append text.
1522 */
@@ -3726,10 +3748,14 @@
3748 memset(p->a, 0, iExp);
3749 p->nDigit += iExp;
3750 p->nFrac += iExp;
3751 }
3752 }
3753 if( p->sign ){
3754 for(i=0; i<p->nDigit && p->a[i]==0; i++){}
3755 if( i>=p->nDigit ) p->sign = 0;
3756 }
3757 return p;
3758
3759 new_from_text_failed:
3760 if( p ){
3761 if( p->a ) sqlite3_free(p->a);
@@ -3928,17 +3954,25 @@
3954 ** pA!=0
3955 ** pA->isNull==0
3956 ** pB!=0
3957 ** pB->isNull==0
3958 */
3959 static int decimal_cmp(Decimal *pA, Decimal *pB){
3960 int nASig, nBSig, rc, n;
3961 while( pA->nFrac>0 && pA->a[pA->nDigit-1]==0 ){
3962 pA->nDigit--;
3963 pA->nFrac--;
3964 }
3965 while( pB->nFrac>0 && pB->a[pB->nDigit-1]==0 ){
3966 pB->nDigit--;
3967 pB->nFrac--;
3968 }
3969 if( pA->sign!=pB->sign ){
3970 return pA->sign ? -1 : +1;
3971 }
3972 if( pA->sign ){
3973 Decimal *pTemp = pA;
3974 pA = pB;
3975 pB = pTemp;
3976 }
3977 nASig = pA->nDigit - pA->nFrac;
3978 nBSig = pB->nDigit - pB->nFrac;
@@ -4183,11 +4217,11 @@
4217 r = -r;
4218 }else{
4219 isNeg = 0;
4220 }
4221 memcpy(&a,&r,sizeof(a));
4222 if( a==0 || a==(sqlite3_int64)0x8000000000000000LL){
4223 e = 0;
4224 m = 0;
4225 }else{
4226 e = a>>52;
4227 m = a & ((((sqlite3_int64)1)<<52)-1);
@@ -5176,20 +5210,21 @@
5210 return pOut;
5211 }
5212
5213 /* This function does the work for the SQLite base64(x) UDF. */
5214 static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
5215 int nb, nv = sqlite3_value_bytes(av[0]);
5216 sqlite3_int64 nc;
5217 int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
5218 SQLITE_LIMIT_LENGTH, -1);
5219 char *cBuf;
5220 u8 *bBuf;
5221 assert(na==1);
5222 switch( sqlite3_value_type(av[0]) ){
5223 case SQLITE_BLOB:
5224 nb = nv;
5225 nc = 4*((nv+2)/3); /* quads needed */
5226 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
5227 if( nvMax < nc ){
5228 sqlite3_result_error(context, "blob expanded to base64 too big", -1);
5229 return;
5230 }
@@ -5861,10 +5896,13 @@
5896 }
5897 memcpy(&a,&r,sizeof(a));
5898 if( a==0 ){
5899 e = 0;
5900 m = 0;
5901 }else if( a==(sqlite3_int64)0x8000000000000000LL ){
5902 e = -1996;
5903 m = -1;
5904 }else{
5905 e = a>>52;
5906 m = a & ((((sqlite3_int64)1)<<52)-1);
5907 if( e==0 ){
5908 m <<= 1;
@@ -6621,10 +6659,14 @@
6659 if( iOffset>0 ){
6660 pCur->ss.iBase += pCur->ss.iStep*iOffset;
6661 }
6662 if( iLimit>=0 ){
6663 sqlite3_int64 iTerm;
6664 sqlite3_int64 mxLimit;
6665 assert( pCur->ss.iStep>0 );
6666 mxLimit = (LARGEST_INT64 - pCur->ss.iBase)/pCur->ss.iStep;
6667 if( iLimit>mxLimit ) iLimit = mxLimit;
6668 iTerm = pCur->ss.iBase + (iLimit - 1)*pCur->ss.iStep;
6669 if( pCur->ss.iStep<0 ){
6670 if( iTerm>pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
6671 }else{
6672 if( iTerm<pCur->ss.iTerm ) pCur->ss.iTerm = iTerm;
@@ -23328,32 +23370,16 @@
23370 ** Set the destination table field of the ShellState structure to
23371 ** the name of the table given. Escape any quote characters in the
23372 ** table name.
23373 */
23374 static void set_table_name(ShellState *p, const char *zName){
 
 
 
 
23375 if( p->zDestTable ){
23376 sqlite3_free(p->zDestTable);
23377 p->zDestTable = 0;
23378 }
23379 if( zName==0 ) return;
23380 p->zDestTable = sqlite3_mprintf("\"%w\"", zName);
 
 
 
 
 
 
 
 
 
 
 
 
23381 }
23382
23383 /*
23384 ** Maybe construct two lines of text that point out the position of a
23385 ** syntax error. Return a pointer to the text, in memory obtained from
@@ -26879,14 +26905,17 @@
26905 #if SQLITE_SHELL_HAVE_RECOVER
26906 /*
26907 ** Convert a 2-byte or 4-byte big-endian integer into a native integer
26908 */
26909 static unsigned int get2byteInt(unsigned char *a){
26910 return ((unsigned int)a[0]<<8) + (unsigned int)a[1];
26911 }
26912 static unsigned int get4byteInt(unsigned char *a){
26913 return ((unsigned int)a[0]<<24)
26914 + ((unsigned int)a[1]<<16)
26915 + ((unsigned int)a[2]<<8)
26916 + (unsigned int)a[3];
26917 }
26918
26919 /*
26920 ** Implementation of the ".dbinfo" command.
26921 **
@@ -27019,11 +27048,11 @@
27048 if( sqlite3_step(pStmt)!=SQLITE_ROW ) goto dbtotxt_error;
27049 nPage = sqlite3_column_int64(pStmt, 0);
27050 sqlite3_finalize(pStmt);
27051 pStmt = 0;
27052 if( nPage<1 ) goto dbtotxt_error;
27053 rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
27054 if( rc ) goto dbtotxt_error;
27055 if( sqlite3_step(pStmt)!=SQLITE_ROW ){
27056 zTail = "unk.db";
27057 }else{
27058 const char *zFilename = (const char*)sqlite3_column_text(pStmt, 2);
@@ -27030,10 +27059,11 @@
27059 if( zFilename==0 || zFilename[0]==0 ) zFilename = "unk.db";
27060 zTail = strrchr(zFilename, '/');
27061 #if defined(_WIN32)
27062 if( zTail==0 ) zTail = strrchr(zFilename, '\\');
27063 #endif
27064 if( zTail && zTail[1]!=0 ) zTail++;
27065 }
27066 zName = strdup(zTail);
27067 shell_check_oom(zName);
27068 sqlite3_fprintf(p->out, "| size %lld pagesize %d filename %s\n",
27069 nPage*pgSz, pgSz, zName);
@@ -29890,16 +29920,10 @@
29920 sqlite3_stmt *pStmt;
29921 int tnum = 0;
29922 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
29923 int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
29924 int i;
 
 
 
 
 
 
29925 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
29926 eputz("Usage: .imposter INDEX IMPOSTER\n"
29927 " .imposter off\n");
29928 /* Also allowed, but not documented:
29929 **
@@ -29967,22 +29991,19 @@
29991 if( lenPK==0 ) lenPK = 100000;
29992 zSql = sqlite3_mprintf(
29993 "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%.*s))WITHOUT ROWID",
29994 azArg[2], zCollist, lenPK, zCollist);
29995 sqlite3_free(zCollist);
29996 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 2, tnum);
29997 if( rc==SQLITE_OK ){
29998 rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
29999 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
30000 if( rc ){
30001 sqlite3_fprintf(stderr,
30002 "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
30003 }else{
30004 sqlite3_fprintf(stdout, "%s;\n", zSql);
 
 
 
30005 }
30006 }else{
30007 sqlite3_fprintf(stderr,"SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
30008 rc = 1;
30009 }
@@ -31868,11 +31889,11 @@
31889 { 0x00000020, 1, "CoverIdxScan" },
31890 { 0x00000040, 1, "OrderByIdxJoin" },
31891 { 0x00000080, 1, "Transitive" },
31892 { 0x00000100, 1, "OmitNoopJoin" },
31893 { 0x00000200, 1, "CountOfView" },
31894 { 0x00000400, 1, "CursorHints" },
31895 { 0x00000800, 1, "Stat4" },
31896 { 0x00001000, 1, "PushDown" },
31897 { 0x00002000, 1, "SimplifyJoin" },
31898 { 0x00004000, 1, "SkipScan" },
31899 { 0x00008000, 1, "PropagateConst" },
31900
+343 -93
--- 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
-** 61d9e204c5801a94811fdb0afe2c04f9814e with changes in files:
21
+** 821cc0e421bc14a68ebaee507e38a900e0c8 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -168,11 +168,13 @@
168168
#define SQLITE_OMIT_LOAD_EXTENSION 1
169169
#define SQLITE_ENABLE_LOCKING_STYLE 0
170170
#define HAVE_UTIME 1
171171
#else
172172
/* This is not VxWorks. */
173
-#define OS_VXWORKS 0
173
+#ifndef OS_VXWORKS
174
+# define OS_VXWORKS 0
175
+#endif
174176
#define HAVE_FCHOWN 1
175177
#define HAVE_READLINK 1
176178
#define HAVE_LSTAT 1
177179
#endif /* defined(_WRS_KERNEL) */
178180
@@ -465,14 +467,14 @@
465467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466468
** [sqlite_version()] and [sqlite_source_id()].
467469
*/
468470
#define SQLITE_VERSION "3.51.0"
469471
#define SQLITE_VERSION_NUMBER 3051000
470
-#define SQLITE_SOURCE_ID "2025-09-10 14:28:07 61d9e204c5801a94811fdb0afe2c04f9814e08f2e141afa6dbda0fa45f026f70"
472
+#define SQLITE_SOURCE_ID "2025-09-24 19:10:58 821cc0e421bc14a68ebaee507e38a900e0c84ff6ba7ee95bf796cad387755232"
471473
#define SQLITE_SCM_BRANCH "trunk"
472474
#define SQLITE_SCM_TAGS ""
473
-#define SQLITE_SCM_DATETIME "2025-09-10T14:28:07.926Z"
475
+#define SQLITE_SCM_DATETIME "2025-09-24T19:10:58.215Z"
474476
475477
/*
476478
** CAPI3REF: Run-Time Library Version Numbers
477479
** KEYWORDS: sqlite3_version sqlite3_sourceid
478480
**
@@ -4523,10 +4525,38 @@
45234525
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
45244526
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
45254527
SQLITE_API const char *sqlite3_errstr(int);
45264528
SQLITE_API int sqlite3_error_offset(sqlite3 *db);
45274529
4530
+/*
4531
+** CAPI3REF: Set Error Codes And Message
4532
+** METHOD: sqlite3
4533
+**
4534
+** Set the error code of the database handle passed as the first argument
4535
+** to errcode, and the error message to a copy of nul-terminated string
4536
+** zErrMsg. If zErrMsg is passed NULL, then the error message is set to
4537
+** the default message associated with the supplied error code. Subsequent
4538
+** calls to [sqlite3_errcode()] and [sqlite3_errmsg()] and similar will
4539
+** return the values set by this routine in place of what was previously
4540
+** set by SQLite itself.
4541
+**
4542
+** This function returns SQLITE_OK if the error code and error message are
4543
+** successfully set, SQLITE_NOMEM if an OOM occurs, and SQLITE_MISUSE if
4544
+** the database handle is NULL or invalid.
4545
+**
4546
+** The error code and message set by this routine remains in effect until
4547
+** they are changed, either by another call to this routine or until they are
4548
+** changed to by SQLite itself to reflect the result of some subsquent
4549
+** API call.
4550
+**
4551
+** This function is intended for use by SQLite extensions or wrappers. The
4552
+** idea is that an extension or wrapper can use this routine to set error
4553
+** messages and error codes and thus behave more like a core SQLite
4554
+** feature from the point of view of an application.
4555
+*/
4556
+SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zErrMsg);
4557
+
45284558
/*
45294559
** CAPI3REF: Prepared Statement Object
45304560
** KEYWORDS: {prepared statement} {prepared statements}
45314561
**
45324562
** An instance of this object represents a single SQL statement that
@@ -12662,10 +12692,19 @@
1266212692
** CAPI3REF: Apply A Changeset To A Database
1266312693
**
1266412694
** Apply a changeset or patchset to a database. These functions attempt to
1266512695
** update the "main" database attached to handle db with the changes found in
1266612696
** the changeset passed via the second and third arguments.
12697
+**
12698
+** All changes made by these functions are enclosed in a savepoint transaction.
12699
+** If any other error (aside from a constraint failure when attempting to
12700
+** write to the target database) occurs, then the savepoint transaction is
12701
+** rolled back, restoring the target database to its original state, and an
12702
+** SQLite error code returned. Additionally, starting with version 3.51.0,
12703
+** an error code and error message that may be accessed using the
12704
+** [sqlite3_errcode()] and [sqlite3_errmsg()] APIs are left in the database
12705
+** handle.
1266712706
**
1266812707
** The fourth argument (xFilter) passed to these functions is the "filter
1266912708
** callback". This may be passed NULL, in which case all changes in the
1267012709
** changeset are applied to the database. For sqlite3changeset_apply() and
1267112710
** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
@@ -12800,16 +12839,10 @@
1280012839
** It is safe to execute SQL statements, including those that write to the
1280112840
** table that the callback related to, from within the xConflict callback.
1280212841
** This can be used to further customize the application's conflict
1280312842
** resolution strategy.
1280412843
**
12805
-** All changes made by these functions are enclosed in a savepoint transaction.
12806
-** If any other error (aside from a constraint failure when attempting to
12807
-** write to the target database) occurs, then the savepoint transaction is
12808
-** rolled back, restoring the target database to its original state, and an
12809
-** SQLite error code returned.
12810
-**
1281112844
** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
1281212845
** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
1281312846
** may set (*ppRebase) to point to a "rebase" that may be used with the
1281412847
** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
1281512848
** is set to the size of the buffer in bytes. It is the responsibility of the
@@ -18155,11 +18188,11 @@
1815518188
struct sqlite3InitInfo { /* Information used during initialization */
1815618189
Pgno newTnum; /* Rootpage of table being initialized */
1815718190
u8 iDb; /* Which db file is being initialized */
1815818191
u8 busy; /* TRUE if currently initializing */
1815918192
unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
18160
- unsigned imposterTable : 1; /* Building an imposter table */
18193
+ unsigned imposterTable : 2; /* Building an imposter table */
1816118194
unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
1816218195
const char **azInit; /* "type", "name", and "tbl_name" columns */
1816318196
} init;
1816418197
int nVdbeActive; /* Number of VDBEs currently running */
1816518198
int nVdbeRead; /* Number of active VDBEs that read or write */
@@ -18948,10 +18981,11 @@
1894818981
#define TF_Shadow 0x00001000 /* True for a shadow table */
1894918982
#define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
1895018983
#define TF_Ephemeral 0x00004000 /* An ephemeral table */
1895118984
#define TF_Eponymous 0x00008000 /* An eponymous virtual table */
1895218985
#define TF_Strict 0x00010000 /* STRICT mode */
18986
+#define TF_Imposter 0x00020000 /* An imposter table */
1895318987
1895418988
/*
1895518989
** Allowed values for Table.eTabType
1895618990
*/
1895718991
#define TABTYP_NORM 0 /* Ordinary table */
@@ -25009,10 +25043,14 @@
2500925043
if( getDigits(zDate, "20b:20e", &nHr, &nMn)!=2 ){
2501025044
return 1;
2501125045
}
2501225046
zDate += 5;
2501325047
p->tz = sgn*(nMn + nHr*60);
25048
+ if( p->tz==0 ){ /* Forum post 2025-09-17T10:12:14z */
25049
+ p->isLocal = 0;
25050
+ p->isUtc = 1;
25051
+ }
2501425052
zulu_time:
2501525053
while( sqlite3Isspace(*zDate) ){ zDate++; }
2501625054
return *zDate!=0;
2501725055
}
2501825056
@@ -38168,11 +38206,11 @@
3816838206
static int kvstorageDelete(const char*, const char *zKey);
3816938207
static int kvstorageRead(const char*, const char *zKey, char *zBuf, int nBuf);
3817038208
#define KVSTORAGE_KEY_SZ 32
3817138209
3817238210
/* Expand the key name with an appropriate prefix and put the result
38173
-** zKeyOut[]. The zKeyOut[] buffer is assumed to hold at least
38211
+** in zKeyOut[]. The zKeyOut[] buffer is assumed to hold at least
3817438212
** KVSTORAGE_KEY_SZ bytes.
3817538213
*/
3817638214
static void kvstorageMakeKey(
3817738215
const char *zClass,
3817838216
const char *zKeyIn,
@@ -38227,14 +38265,16 @@
3822738265
** enough to hold it all. The value put into zBuf must always be zero
3822838266
** terminated, even if it gets truncated because nBuf is not large enough.
3822938267
**
3823038268
** Return the total number of bytes in the data, without truncation, and
3823138269
** not counting the final zero terminator. Return -1 if the key does
38232
-** not exist.
38270
+** not exist or its key cannot be read.
3823338271
**
38234
-** If nBuf<=0 then this routine simply returns the size of the data without
38235
-** actually reading it.
38272
+** If nBuf<=0 then this routine simply returns the size of the data
38273
+** without actually reading it. Similarly, if nBuf==1 then it
38274
+** zero-terminates zBuf at zBuf[0] and returns the size of the data
38275
+** without reading it.
3823638276
*/
3823738277
static int kvstorageRead(
3823838278
const char *zClass,
3823938279
const char *zKey,
3824038280
char *zBuf,
@@ -38279,15 +38319,13 @@
3827938319
/*
3828038320
** An internal level of indirection which enables us to replace the
3828138321
** kvvfs i/o methods with JavaScript implementations in WASM builds.
3828238322
** Maintenance reminder: if this struct changes in any way, the JSON
3828338323
** rendering of its structure must be updated in
38284
-** sqlite3_wasm_enum_json(). There are no binary compatibility
38285
-** concerns, so it does not need an iVersion member. This file is
38286
-** necessarily always compiled together with sqlite3_wasm_enum_json(),
38287
-** and JS code dynamically creates the mapping of members based on
38288
-** that JSON description.
38324
+** sqlite3-wasm.c:sqlite3__wasm_enum_json(). There are no binary
38325
+** compatibility concerns, so it does not need an iVersion
38326
+** member.
3828938327
*/
3829038328
typedef struct sqlite3_kvvfs_methods sqlite3_kvvfs_methods;
3829138329
struct sqlite3_kvvfs_methods {
3829238330
int (*xRead)(const char *zClass, const char *zKey, char *zBuf, int nBuf);
3829338331
int (*xWrite)(const char *zClass, const char *zKey, const char *zData);
@@ -38300,12 +38338,12 @@
3830038338
** for JavaScript-side implementations in WASM builds. In such builds
3830138339
** it cannot be const, but in native builds it should be so that
3830238340
** the compiler can hopefully optimize this level of indirection out.
3830338341
** That said, kvvfs is intended primarily for use in WASM builds.
3830438342
**
38305
-** Note that this is not explicitly flagged as static because the
38306
-** amalgamation build will tag it with SQLITE_PRIVATE.
38343
+** This is not explicitly flagged as static because the amalgamation
38344
+** build will tag it with SQLITE_PRIVATE.
3830738345
*/
3830838346
#ifndef SQLITE_WASM
3830938347
const
3831038348
#endif
3831138349
SQLITE_PRIVATE sqlite3_kvvfs_methods sqlite3KvvfsMethods = {
@@ -39736,13 +39774,12 @@
3973639774
return fd;
3973739775
}
3973839776
3973939777
/*
3974039778
** Helper functions to obtain and relinquish the global mutex. The
39741
-** global mutex is used to protect the unixInodeInfo and
39742
-** vxworksFileId objects used by this file, all of which may be
39743
-** shared by multiple threads.
39779
+** global mutex is used to protect the unixInodeInfo objects used by
39780
+** this file, all of which may be shared by multiple threads.
3974439781
**
3974539782
** Function unixMutexHeld() is used to assert() that the global mutex
3974639783
** is held when required. This function is only used as part of assert()
3974739784
** statements. e.g.
3974839785
**
@@ -39940,10 +39977,11 @@
3994039977
/*
3994139978
** All unique filenames are held on a linked list headed by this
3994239979
** variable:
3994339980
*/
3994439981
static struct vxworksFileId *vxworksFileList = 0;
39982
+static sqlite3_mutex *vxworksMutex = 0;
3994539983
3994639984
/*
3994739985
** Simplify a filename into its canonical form
3994839986
** by making the following changes:
3994939987
**
@@ -40005,47 +40043,47 @@
4000540043
4000640044
/* Search for an existing entry that matching the canonical name.
4000740045
** If found, increment the reference count and return a pointer to
4000840046
** the existing file ID.
4000940047
*/
40010
- unixEnterMutex();
40048
+ sqlite3_mutex_enter(vxworksMutex);
4001140049
for(pCandidate=vxworksFileList; pCandidate; pCandidate=pCandidate->pNext){
4001240050
if( pCandidate->nName==n
4001340051
&& memcmp(pCandidate->zCanonicalName, pNew->zCanonicalName, n)==0
4001440052
){
4001540053
sqlite3_free(pNew);
4001640054
pCandidate->nRef++;
40017
- unixLeaveMutex();
40055
+ sqlite3_mutex_leave(vxworksMutex);
4001840056
return pCandidate;
4001940057
}
4002040058
}
4002140059
4002240060
/* No match was found. We will make a new file ID */
4002340061
pNew->nRef = 1;
4002440062
pNew->nName = n;
4002540063
pNew->pNext = vxworksFileList;
4002640064
vxworksFileList = pNew;
40027
- unixLeaveMutex();
40065
+ sqlite3_mutex_leave(vxworksMutex);
4002840066
return pNew;
4002940067
}
4003040068
4003140069
/*
4003240070
** Decrement the reference count on a vxworksFileId object. Free
4003340071
** the object when the reference count reaches zero.
4003440072
*/
4003540073
static void vxworksReleaseFileId(struct vxworksFileId *pId){
40036
- unixEnterMutex();
40074
+ sqlite3_mutex_enter(vxworksMutex);
4003740075
assert( pId->nRef>0 );
4003840076
pId->nRef--;
4003940077
if( pId->nRef==0 ){
4004040078
struct vxworksFileId **pp;
4004140079
for(pp=&vxworksFileList; *pp && *pp!=pId; pp = &((*pp)->pNext)){}
4004240080
assert( *pp==pId );
4004340081
*pp = pId->pNext;
4004440082
sqlite3_free(pId);
4004540083
}
40046
- unixLeaveMutex();
40084
+ sqlite3_mutex_leave(vxworksMutex);
4004740085
}
4004840086
#endif /* OS_VXWORKS */
4004940087
/*************** End of Unique File ID Utility Used By VxWorks ****************
4005040088
******************************************************************************/
4005140089
@@ -44958,14 +44996,21 @@
4495844996
#endif
4495944997
4496044998
storeLastErrno(pNew, 0);
4496144999
#if OS_VXWORKS
4496245000
if( rc!=SQLITE_OK ){
44963
- if( h>=0 ) robust_close(pNew, h, __LINE__);
44964
- h = -1;
44965
- osUnlink(zFilename);
44966
- pNew->ctrlFlags |= UNIXFILE_DELETE;
45001
+ if( h>=0 ){
45002
+ robust_close(pNew, h, __LINE__);
45003
+ h = -1;
45004
+ }
45005
+ if( pNew->ctrlFlags & UNIXFILE_DELETE ){
45006
+ osUnlink(zFilename);
45007
+ }
45008
+ if( pNew->pId ){
45009
+ vxworksReleaseFileId(pNew->pId);
45010
+ pNew->pId = 0;
45011
+ }
4496745012
}
4496845013
#endif
4496945014
if( rc!=SQLITE_OK ){
4497045015
if( h>=0 ) robust_close(pNew, h, __LINE__);
4497145016
}else{
@@ -45005,10 +45050,13 @@
4500545050
struct stat buf;
4500645051
const char *zDir = sqlite3_temp_directory;
4500745052
4500845053
while(1){
4500945054
if( zDir!=0
45055
+#if OS_VXWORKS
45056
+ && zDir[0]=='/'
45057
+#endif
4501045058
&& osStat(zDir, &buf)==0
4501145059
&& S_ISDIR(buf.st_mode)
4501245060
&& osAccess(zDir, 03)==0
4501345061
){
4501445062
return zDir;
@@ -45318,10 +45366,16 @@
4531845366
assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
4531945367
|| eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
4532045368
|| eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL
4532145369
|| eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
4532245370
);
45371
+
45372
+#if OS_VXWORKS
45373
+ /* The file-ID mechanism used in Vxworks requires that all pathnames
45374
+ ** provided to unixOpen must be absolute pathnames. */
45375
+ if( zPath!=0 && zPath[0]!='/' ){ return SQLITE_CANTOPEN; }
45376
+#endif
4532345377
4532445378
/* Detect a pid change and reset the PRNG. There is a race condition
4532545379
** here such that two or more threads all trying to open databases at
4532645380
** the same instant might all reset the PRNG. But multiple resets
4532745381
** are harmless.
@@ -45519,12 +45573,15 @@
4551945573
goto open_finished;
4552045574
}
4552145575
}
4552245576
#endif
4552345577
45524
- assert( zPath==0 || zPath[0]=='/'
45525
- || eType==SQLITE_OPEN_SUPER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
45578
+ assert( zPath==0
45579
+ || zPath[0]=='/'
45580
+ || eType==SQLITE_OPEN_SUPER_JOURNAL
45581
+ || eType==SQLITE_OPEN_MAIN_JOURNAL
45582
+ || eType==SQLITE_OPEN_TEMP_JOURNAL
4552645583
);
4552745584
rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
4552845585
4552945586
open_finished:
4553045587
if( rc!=SQLITE_OK ){
@@ -47249,10 +47306,13 @@
4724947306
}
4725047307
#ifdef SQLITE_OS_KV_OPTIONAL
4725147308
sqlite3KvvfsInit();
4725247309
#endif
4725347310
unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
47311
+#if OS_VXWORKS
47312
+ vxworksMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS2);
47313
+#endif
4725447314
4725547315
#ifndef SQLITE_OMIT_WAL
4725647316
/* Validate lock assumptions */
4725747317
assert( SQLITE_SHM_NLOCK==8 ); /* Number of available locks */
4725847318
assert( UNIX_SHM_BASE==120 ); /* Start of locking area */
@@ -47283,10 +47343,13 @@
4728347343
** to release dynamically allocated objects. But not on unix.
4728447344
** This routine is a no-op for unix.
4728547345
*/
4728647346
SQLITE_API int sqlite3_os_end(void){
4728747347
unixBigLock = 0;
47348
+#if OS_VXWORKS
47349
+ vxworksMutex = 0;
47350
+#endif
4728847351
return SQLITE_OK;
4728947352
}
4729047353
4729147354
#endif /* SQLITE_OS_UNIX */
4729247355
@@ -62006,18 +62069,31 @@
6200662069
SQLITE_PRIVATE void sqlite3PagerSetFlags(
6200762070
Pager *pPager, /* The pager to set safety level for */
6200862071
unsigned pgFlags /* Various flags */
6200962072
){
6201062073
unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK;
62011
- if( pPager->tempFile ){
62074
+ if( pPager->tempFile || level==PAGER_SYNCHRONOUS_OFF ){
6201262075
pPager->noSync = 1;
6201362076
pPager->fullSync = 0;
6201462077
pPager->extraSync = 0;
6201562078
}else{
62016
- pPager->noSync = level==PAGER_SYNCHRONOUS_OFF ?1:0;
62079
+ pPager->noSync = 0;
6201762080
pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
62018
- pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
62081
+
62082
+ /* Set Pager.extraSync if "PRAGMA synchronous=EXTRA" is requested, or
62083
+ ** if the file-system supports F2FS style atomic writes. If this flag
62084
+ ** is set, SQLite syncs the directory to disk immediately after deleting
62085
+ ** a journal file in "PRAGMA journal_mode=DELETE" mode. */
62086
+ if( level==PAGER_SYNCHRONOUS_EXTRA
62087
+#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
62088
+ || (sqlite3OsDeviceCharacteristics(pPager->fd) & SQLITE_IOCAP_BATCH_ATOMIC)
62089
+#endif
62090
+ ){
62091
+ pPager->extraSync = 1;
62092
+ }else{
62093
+ pPager->extraSync = 0;
62094
+ }
6201962095
}
6202062096
if( pPager->noSync ){
6202162097
pPager->syncFlags = 0;
6202262098
}else if( pgFlags & PAGER_FULLFSYNC ){
6202362099
pPager->syncFlags = SQLITE_SYNC_FULL;
@@ -113289,13 +113365,12 @@
113289113365
}
113290113366
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, pFree1);
113291113367
if( addrIsNull==0 ){
113292113368
/*
113293113369
** If the right operand contains a subquery and the left operand does not
113294
- ** and the left operand might be NULL, then check the left operand do
113295
- ** an IsNull check on the left operand before computing the right
113296
- ** operand.
113370
+ ** and the left operand might be NULL, then do an IsNull check
113371
+ ** check on the left operand before computing the right operand.
113297113372
*/
113298113373
if( ExprHasProperty(pExpr->pRight, EP_Subquery)
113299113374
&& sqlite3ExprCanBeNull(pExpr->pLeft)
113300113375
){
113301113376
addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, r1);
@@ -115660,10 +115735,82 @@
115660115735
}
115661115736
}
115662115737
return 0;
115663115738
}
115664115739
115740
+/*
115741
+** Generate code that evaluates an AND or OR operator leaving a
115742
+** boolean result in a register. pExpr is the AND/OR expression.
115743
+** Store the result in the "target" register. Use short-circuit
115744
+** evaluation to avoid computing both operands, if possible.
115745
+**
115746
+** The code generated might require the use of a temporary register.
115747
+** If it does, then write the number of that temporary register
115748
+** into *pTmpReg. If not, leave *pTmpReg unchanged.
115749
+*/
115750
+static SQLITE_NOINLINE int exprCodeTargetAndOr(
115751
+ Parse *pParse, /* Parsing context */
115752
+ Expr *pExpr, /* AND or OR expression to be coded */
115753
+ int target, /* Put result in this register, guaranteed */
115754
+ int *pTmpReg /* Write a temporary register here */
115755
+){
115756
+ int op; /* The opcode. TK_AND or TK_OR */
115757
+ int skipOp; /* Opcode for the branch that skips one operand */
115758
+ int addrSkip; /* Branch instruction that skips one of the operands */
115759
+ int regSS = 0; /* Register holding computed operand when other omitted */
115760
+ int r1, r2; /* Registers for left and right operands, respectively */
115761
+ Expr *pAlt; /* Alternative, simplified expression */
115762
+ Vdbe *v; /* statement being coded */
115763
+
115764
+ assert( pExpr!=0 );
115765
+ op = pExpr->op;
115766
+ assert( op==TK_AND || op==TK_OR );
115767
+ assert( TK_AND==OP_And ); testcase( op==TK_AND );
115768
+ assert( TK_OR==OP_Or ); testcase( op==TK_OR );
115769
+ pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
115770
+ if( pAlt!=pExpr ){
115771
+ return sqlite3ExprCodeTarget(pParse, pAlt, target);
115772
+ }
115773
+ assert( pParse->pVdbe!=0 );
115774
+ v = pParse->pVdbe;
115775
+ skipOp = op==TK_AND ? OP_IfNot : OP_If;
115776
+ if( exprEvalRhsFirst(pExpr) ){
115777
+ /* Compute the right operand first. Skip the computation of the left
115778
+ ** operand if the right operand fully determines the result */
115779
+ r2 = regSS = sqlite3ExprCodeTarget(pParse, pExpr->pRight, target);
115780
+ addrSkip = sqlite3VdbeAddOp1(v, skipOp, r2);
115781
+ VdbeComment((v, "skip left operand"));
115782
+ VdbeCoverage(v);
115783
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, pTmpReg);
115784
+ }else{
115785
+ /* Compute the left operand first */
115786
+ r1 = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
115787
+ if( ExprHasProperty(pExpr->pRight, EP_Subquery) ){
115788
+ /* Skip over the computation of the right operand if the right
115789
+ ** operand is a subquery and the left operand completely determines
115790
+ ** the result */
115791
+ regSS = r1;
115792
+ addrSkip = sqlite3VdbeAddOp1(v, skipOp, r1);
115793
+ VdbeComment((v, "skip right operand"));
115794
+ VdbeCoverage(v);
115795
+ }else{
115796
+ addrSkip = regSS = 0;
115797
+ }
115798
+ r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, pTmpReg);
115799
+ }
115800
+ sqlite3VdbeAddOp3(v, op, r2, r1, target);
115801
+ testcase( (*pTmpReg)==0 );
115802
+ if( addrSkip ){
115803
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
115804
+ sqlite3VdbeJumpHere(v, addrSkip);
115805
+ sqlite3VdbeAddOp3(v, OP_Or, regSS, regSS, target);
115806
+ VdbeComment((v, "short-circut value"));
115807
+ }
115808
+ return target;
115809
+}
115810
+
115811
+
115665115812
115666115813
/*
115667115814
** Generate code into the current Vdbe to evaluate the given
115668115815
** expression. Attempt to store the results in register "target".
115669115816
** Return the register where results are stored.
@@ -115948,16 +116095,18 @@
115948116095
sqlite3VdbeAddOp2(v, OP_Null, 0, inReg);
115949116096
}
115950116097
}
115951116098
testcase( regFree1==0 );
115952116099
testcase( regFree2==0 );
115953
-
115954116100
}
115955116101
break;
115956116102
}
115957116103
case TK_AND:
115958
- case TK_OR:
116104
+ case TK_OR: {
116105
+ inReg = exprCodeTargetAndOr(pParse, pExpr, target, &regFree1);
116106
+ break;
116107
+ }
115959116108
case TK_PLUS:
115960116109
case TK_STAR:
115961116110
case TK_MINUS:
115962116111
case TK_REM:
115963116112
case TK_BITAND:
@@ -115965,12 +116114,10 @@
115965116114
case TK_SLASH:
115966116115
case TK_LSHIFT:
115967116116
case TK_RSHIFT:
115968116117
case TK_CONCAT: {
115969116118
int addrIsNull;
115970
- assert( TK_AND==OP_And ); testcase( op==TK_AND );
115971
- assert( TK_OR==OP_Or ); testcase( op==TK_OR );
115972116119
assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
115973116120
assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
115974116121
assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
115975116122
assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND );
115976116123
assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
@@ -125050,10 +125197,13 @@
125050125197
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
125051125198
sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
125052125199
sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
125053125200
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
125054125201
sqlite3VdbeAddOp0(v, OP_Close);
125202
+ }else if( db->init.imposterTable ){
125203
+ pTable->tabFlags |= TF_Imposter;
125204
+ if( db->init.imposterTable>=2 ) pTable->tabFlags |= TF_Readonly;
125055125205
}
125056125206
125057125207
/* Normal (non-error) return. */
125058125208
return;
125059125209
@@ -139432,10 +139582,12 @@
139432139582
/* Version 3.44.0 and later */
139433139583
void *(*get_clientdata)(sqlite3*,const char*);
139434139584
int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*));
139435139585
/* Version 3.50.0 and later */
139436139586
int (*setlk_timeout)(sqlite3*,int,int);
139587
+ /* Version 3.51.0 and later */
139588
+ int (*set_errmsg)(sqlite3*,int,const char*);
139437139589
};
139438139590
139439139591
/*
139440139592
** This is the function signature used for all extension entry points. It
139441139593
** is also defined in the file "loadext.c".
@@ -139767,10 +139919,12 @@
139767139919
/* Version 3.44.0 and later */
139768139920
#define sqlite3_get_clientdata sqlite3_api->get_clientdata
139769139921
#define sqlite3_set_clientdata sqlite3_api->set_clientdata
139770139922
/* Version 3.50.0 and later */
139771139923
#define sqlite3_setlk_timeout sqlite3_api->setlk_timeout
139924
+/* Version 3.51.0 and later */
139925
+#define sqlite3_set_errmsg sqlite3_api->set_errmsg
139772139926
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
139773139927
139774139928
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
139775139929
/* This case when the file really is being compiled as a loadable
139776139930
** extension */
@@ -140290,11 +140444,13 @@
140290140444
sqlite3_stmt_explain,
140291140445
/* Version 3.44.0 and later */
140292140446
sqlite3_get_clientdata,
140293140447
sqlite3_set_clientdata,
140294140448
/* Version 3.50.0 and later */
140295
- sqlite3_setlk_timeout
140449
+ sqlite3_setlk_timeout,
140450
+ /* Version 3.51.0 and later */
140451
+ sqlite3_set_errmsg
140296140452
};
140297140453
140298140454
/* True if x is the directory separator character
140299140455
*/
140300140456
#if SQLITE_OS_WIN
@@ -141751,10 +141907,26 @@
141751141907
addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
141752141908
VdbeCoverage(v);
141753141909
sqlite3VdbeAddOp0(v, OP_Halt);
141754141910
return addr;
141755141911
}
141912
+
141913
+/*
141914
+** Should table pTab be skipped when doing an integrity_check?
141915
+** Return true or false.
141916
+**
141917
+** If pObjTab is not null, the return true if pTab matches pObjTab.
141918
+**
141919
+** If pObjTab is null, then return true only if pTab is an imposter table.
141920
+*/
141921
+static int tableSkipIntegrityCheck(const Table *pTab, const Table *pObjTab){
141922
+ if( pObjTab ){
141923
+ return pTab!=pObjTab;
141924
+ }else{
141925
+ return (pTab->tabFlags & TF_Imposter)!=0;
141926
+ }
141927
+}
141756141928
141757141929
/*
141758141930
** Process a pragma statement.
141759141931
**
141760141932
** Pragmas are of this form:
@@ -143097,11 +143269,11 @@
143097143269
pTbls = &db->aDb[i].pSchema->tblHash;
143098143270
for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143099143271
Table *pTab = sqliteHashData(x); /* Current table */
143100143272
Index *pIdx; /* An index on pTab */
143101143273
int nIdx; /* Number of indexes on pTab */
143102
- if( pObjTab && pObjTab!=pTab ) continue;
143274
+ if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143103143275
if( HasRowid(pTab) ) cnt++;
143104143276
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
143105143277
}
143106143278
if( cnt==0 ) continue;
143107143279
if( pObjTab ) cnt++;
@@ -143110,11 +143282,11 @@
143110143282
cnt = 0;
143111143283
if( pObjTab ) aRoot[++cnt] = 0;
143112143284
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143113143285
Table *pTab = sqliteHashData(x);
143114143286
Index *pIdx;
143115
- if( pObjTab && pObjTab!=pTab ) continue;
143287
+ if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143116143288
if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum;
143117143289
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
143118143290
aRoot[++cnt] = pIdx->tnum;
143119143291
}
143120143292
}
@@ -143141,11 +143313,11 @@
143141143313
sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
143142143314
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143143143315
int iTab = 0;
143144143316
Table *pTab = sqliteHashData(x);
143145143317
Index *pIdx;
143146
- if( pObjTab && pObjTab!=pTab ) continue;
143318
+ if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143147143319
if( HasRowid(pTab) ){
143148143320
iTab = cnt++;
143149143321
}else{
143150143322
iTab = cnt;
143151143323
for(pIdx=pTab->pIndex; ALWAYS(pIdx); pIdx=pIdx->pNext){
@@ -143177,11 +143349,11 @@
143177143349
int r1 = -1;
143178143350
int bStrict; /* True for a STRICT table */
143179143351
int r2; /* Previous key for WITHOUT ROWID tables */
143180143352
int mxCol; /* Maximum non-virtual column number */
143181143353
143182
- if( pObjTab && pObjTab!=pTab ) continue;
143354
+ if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143183143355
if( !IsOrdinaryTable(pTab) ) continue;
143184143356
if( isQuick || HasRowid(pTab) ){
143185143357
pPk = 0;
143186143358
r2 = 0;
143187143359
}else{
@@ -143501,11 +143673,11 @@
143501143673
*/
143502143674
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143503143675
Table *pTab = sqliteHashData(x);
143504143676
sqlite3_vtab *pVTab;
143505143677
int a1;
143506
- if( pObjTab && pObjTab!=pTab ) continue;
143678
+ if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143507143679
if( IsOrdinaryTable(pTab) ) continue;
143508143680
if( !IsVirtual(pTab) ) continue;
143509143681
if( pTab->nCol<=0 ){
143510143682
const char *zMod = pTab->u.vtab.azArg[0];
143511143683
if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
@@ -170516,10 +170688,14 @@
170516170688
if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
170517170689
if( pLoop->u.vtab.isOrdered
170518170690
&& ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY)
170519170691
){
170520170692
obSat = obDone;
170693
+ }else{
170694
+ /* No further ORDER BY terms may be matched. So this call should
170695
+ ** return >=0, not -1. Clear isOrderDistinct to ensure it does so. */
170696
+ isOrderDistinct = 0;
170521170697
}
170522170698
break;
170523170699
}
170524170700
iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
170525170701
@@ -171419,22 +171595,18 @@
171419171595
pFrom = aTo;
171420171596
aTo = aFrom;
171421171597
aFrom = pFrom;
171422171598
nFrom = nTo;
171423171599
}
171600
+ assert( nFrom==0 || nFrom==1 );
171424171601
171425171602
if( nFrom==0 ){
171426171603
sqlite3ErrorMsg(pParse, "no query solution");
171427171604
sqlite3StackFreeNN(pParse->db, pSpace);
171428171605
return SQLITE_ERROR;
171429171606
}
171430
-
171431
- /* Find the lowest cost path. pFrom will be left pointing to that path */
171432171607
pFrom = aFrom;
171433
- for(ii=1; ii<nFrom; ii++){
171434
- if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
171435
- }
171436171608
assert( pWInfo->nLevel==nLoop );
171437171609
/* Load the lowest cost path into pWInfo */
171438171610
for(iLoop=0; iLoop<nLoop; iLoop++){
171439171611
WhereLevel *pLevel = pWInfo->a + iLoop;
171440171612
pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -171563,11 +171735,14 @@
171563171735
int once = 0;
171564171736
#endif
171565171737
for(i=0; i<pWInfo->nLevel; i++){
171566171738
WhereLoop *p = pWInfo->a[i].pWLoop;
171567171739
if( p==0 ) break;
171568
- if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 ) continue;
171740
+ if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
171741
+ /* Treat a vtab scan as similar to a full-table scan */
171742
+ break;
171743
+ }
171569171744
if( (p->wsFlags & (WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0 ){
171570171745
u8 iTab = p->iTab;
171571171746
WhereLoop *pLoop;
171572171747
for(pLoop=pWInfo->pLoops; pLoop; pLoop=pLoop->pNextLoop){
171573171748
if( pLoop->iTab!=iTab ) continue;
@@ -175676,11 +175851,11 @@
175676175851
** RETURN_ROW
175677175852
**
175678175853
**
175679175854
** ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
175680175855
**
175681
-** ... loop started by sqlite3WhereBegin() ...
175856
+** ... loop started by sqlite3WhereBegin() ...
175682175857
** if( new partition ){
175683175858
** Gosub flush
175684175859
** }
175685175860
** Insert new row into eph table.
175686175861
** if( first row of partition ){
@@ -176194,10 +176369,16 @@
176194176369
addrStart = sqlite3VdbeCurrentAddr(v);
176195176370
addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regStart, 1);
176196176371
addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
176197176372
}else{
176198176373
assert( pMWin->eEnd==TK_FOLLOWING );
176374
+ /* assert( regStart>=0 );
176375
+ ** regEnd = regEnd - regStart;
176376
+ ** regStart = 0; */
176377
+ sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regEnd);
176378
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, regStart);
176379
+
176199176380
addrStart = sqlite3VdbeCurrentAddr(v);
176200176381
addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 1);
176201176382
addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
176202176383
}
176203176384
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
@@ -186322,10 +186503,33 @@
186322186503
}
186323186504
}
186324186505
sqlite3_mutex_leave(db->mutex);
186325186506
return z;
186326186507
}
186508
+
186509
+/*
186510
+** Set the error code and error message associated with the database handle.
186511
+**
186512
+** This routine is intended to be called by outside extensions (ex: the
186513
+** Session extension). Internal logic should invoke sqlite3Error() or
186514
+** sqlite3ErrorWithMsg() directly.
186515
+*/
186516
+SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zMsg){
186517
+ int rc = SQLITE_OK;
186518
+ if( !sqlite3SafetyCheckSickOrOk(db) ){
186519
+ return SQLITE_MISUSE_BKPT;
186520
+ }
186521
+ sqlite3_mutex_enter(db->mutex);
186522
+ if( zMsg ){
186523
+ sqlite3ErrorWithMsg(db, errcode, "%s", zMsg);
186524
+ }else{
186525
+ sqlite3Error(db, errcode);
186526
+ }
186527
+ rc = sqlite3ApiExit(db, rc);
186528
+ sqlite3_mutex_leave(db->mutex);
186529
+ return rc;
186530
+}
186327186531
186328186532
/*
186329186533
** Return the byte offset of the most recent error
186330186534
*/
186331186535
SQLITE_API int sqlite3_error_offset(sqlite3 *db){
@@ -188147,17 +188351,19 @@
188147188351
case SQLITE_TESTCTRL_ISINIT: {
188148188352
if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
188149188353
break;
188150188354
}
188151188355
188152
- /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
188356
+ /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, mode, tnum);
188153188357
**
188154188358
** This test control is used to create imposter tables. "db" is a pointer
188155188359
** to the database connection. dbName is the database name (ex: "main" or
188156
- ** "temp") which will receive the imposter. "onOff" turns imposter mode on
188157
- ** or off. "tnum" is the root page of the b-tree to which the imposter
188158
- ** table should connect.
188360
+ ** "temp") which will receive the imposter. "mode" turns imposter mode on
188361
+ ** or off. mode==0 means imposter mode is off. mode==1 means imposter mode
188362
+ ** is on. mode==2 means imposter mode is on but results in an imposter
188363
+ ** table that is read-only unless writable_schema is on. "tnum" is the
188364
+ ** root page of the b-tree to which the imposter table should connect.
188159188365
**
188160188366
** Enable imposter mode only when the schema has already been parsed. Then
188161188367
** run a single CREATE TABLE statement to construct the imposter table in
188162188368
** the parsed schema. Then turn imposter mode back off again.
188163188369
**
@@ -228653,11 +228859,11 @@
228653228859
typedef struct DbpageCursor DbpageCursor;
228654228860
228655228861
struct DbpageCursor {
228656228862
sqlite3_vtab_cursor base; /* Base class. Must be first */
228657228863
Pgno pgno; /* Current page number */
228658
- int mxPgno; /* Last page to visit on this scan */
228864
+ Pgno mxPgno; /* Last page to visit on this scan */
228659228865
Pager *pPager; /* Pager being read/written */
228660228866
DbPage *pPage1; /* Page 1 of the database */
228661228867
int iDb; /* Index of database to analyze */
228662228868
int szPage; /* Size of each page in bytes */
228663228869
};
@@ -231924,10 +232130,23 @@
231924232130
assert( (a - p->aRecord)==p->nRecord );
231925232131
}
231926232132
231927232133
return rc;
231928232134
}
232135
+
232136
+static int sessionPrepare(
232137
+ sqlite3 *db,
232138
+ sqlite3_stmt **pp,
232139
+ char **pzErrmsg,
232140
+ const char *zSql
232141
+){
232142
+ int rc = sqlite3_prepare_v2(db, zSql, -1, pp, 0);
232143
+ if( pzErrmsg && rc!=SQLITE_OK ){
232144
+ *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
232145
+ }
232146
+ return rc;
232147
+}
231929232148
231930232149
/*
231931232150
** Formulate and prepare a SELECT statement to retrieve a row from table
231932232151
** zTab in database zDb based on its primary key. i.e.
231933232152
**
@@ -231946,16 +232165,16 @@
231946232165
const char *zTab, /* Table name */
231947232166
int bRowid,
231948232167
int nCol, /* Number of columns in table */
231949232168
const char **azCol, /* Names of table columns */
231950232169
u8 *abPK, /* PRIMARY KEY array */
231951
- sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
232170
+ sqlite3_stmt **ppStmt, /* OUT: Prepared SELECT statement */
232171
+ char **pzErrmsg /* OUT: Error message */
231952232172
){
231953232173
int rc = SQLITE_OK;
231954232174
char *zSql = 0;
231955232175
const char *zSep = "";
231956
- int nSql = -1;
231957232176
int i;
231958232177
231959232178
SessionBuffer cols = {0, 0, 0};
231960232179
SessionBuffer nooptest = {0, 0, 0};
231961232180
SessionBuffer pkfield = {0, 0, 0};
@@ -232031,11 +232250,11 @@
232031232250
nSql = buf.nBuf;
232032232251
}
232033232252
#endif
232034232253
232035232254
if( rc==SQLITE_OK ){
232036
- rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, 0);
232255
+ rc = sessionPrepare(db, ppStmt, pzErrmsg, zSql);
232037232256
}
232038232257
sqlite3_free(zSql);
232039232258
sqlite3_free(nooptest.aBuf);
232040232259
sqlite3_free(pkfield.aBuf);
232041232260
sqlite3_free(pkvar.aBuf);
@@ -232195,11 +232414,11 @@
232195232414
sessionAppendTableHdr(&buf, bPatchset, pTab, &rc);
232196232415
232197232416
/* Build and compile a statement to execute: */
232198232417
if( rc==SQLITE_OK ){
232199232418
rc = sessionSelectStmt(db, 0, pSession->zDb,
232200
- zName, pTab->bRowid, pTab->nCol, pTab->azCol, pTab->abPK, &pSel
232419
+ zName, pTab->bRowid, pTab->nCol, pTab->azCol, pTab->abPK, &pSel, 0
232201232420
);
232202232421
}
232203232422
232204232423
nNoop = buf.nBuf;
232205232424
for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
@@ -233404,10 +233623,11 @@
233404233623
SessionBuffer rebase; /* Rebase information (if any) here */
233405233624
u8 bRebaseStarted; /* If table header is already in rebase */
233406233625
u8 bRebase; /* True to collect rebase information */
233407233626
u8 bIgnoreNoop; /* True to ignore no-op conflicts */
233408233627
int bRowid;
233628
+ char *zErr; /* Error message, if any */
233409233629
};
233410233630
233411233631
/* Number of prepared UPDATE statements to cache. */
233412233632
#define SESSION_UPDATE_CACHE_SZ 12
233413233633
@@ -233629,11 +233849,11 @@
233629233849
}
233630233850
sessionAppendStr(&buf, ")", &rc);
233631233851
}
233632233852
233633233853
if( rc==SQLITE_OK ){
233634
- rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pDelete, 0);
233854
+ rc = sessionPrepare(db, &p->pDelete, &p->zErr, (char*)buf.aBuf);
233635233855
}
233636233856
sqlite3_free(buf.aBuf);
233637233857
233638233858
return rc;
233639233859
}
@@ -233656,11 +233876,11 @@
233656233876
const char *zTab, /* Table name */
233657233877
SessionApplyCtx *p /* Session changeset-apply context */
233658233878
){
233659233879
/* TODO */
233660233880
return sessionSelectStmt(db, p->bIgnoreNoop,
233661
- "main", zTab, p->bRowid, p->nCol, p->azCol, p->abPK, &p->pSelect
233881
+ "main", zTab, p->bRowid, p->nCol, p->azCol, p->abPK, &p->pSelect, &p->zErr
233662233882
);
233663233883
}
233664233884
233665233885
/*
233666233886
** Formulate and prepare an INSERT statement to add a record to table zTab.
@@ -233693,37 +233913,33 @@
233693233913
sessionAppendStr(&buf, ", ?", &rc);
233694233914
}
233695233915
sessionAppendStr(&buf, ")", &rc);
233696233916
233697233917
if( rc==SQLITE_OK ){
233698
- rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pInsert, 0);
233918
+ rc = sessionPrepare(db, &p->pInsert, &p->zErr, (char*)buf.aBuf);
233699233919
}
233700233920
sqlite3_free(buf.aBuf);
233701233921
return rc;
233702233922
}
233703233923
233704
-static int sessionPrepare(sqlite3 *db, sqlite3_stmt **pp, const char *zSql){
233705
- return sqlite3_prepare_v2(db, zSql, -1, pp, 0);
233706
-}
233707
-
233708233924
/*
233709233925
** Prepare statements for applying changes to the sqlite_stat1 table.
233710233926
** These are similar to those created by sessionSelectRow(),
233711233927
** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for
233712233928
** other tables.
233713233929
*/
233714233930
static int sessionStat1Sql(sqlite3 *db, SessionApplyCtx *p){
233715233931
int rc = sessionSelectRow(db, "sqlite_stat1", p);
233716233932
if( rc==SQLITE_OK ){
233717
- rc = sessionPrepare(db, &p->pInsert,
233933
+ rc = sessionPrepare(db, &p->pInsert, 0,
233718233934
"INSERT INTO main.sqlite_stat1 VALUES(?1, "
233719233935
"CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
233720233936
"?3)"
233721233937
);
233722233938
}
233723233939
if( rc==SQLITE_OK ){
233724
- rc = sessionPrepare(db, &p->pDelete,
233940
+ rc = sessionPrepare(db, &p->pDelete, 0,
233725233941
"DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS "
233726233942
"CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
233727233943
"AND (?4 OR stat IS ?3)"
233728233944
);
233729233945
}
@@ -234502,10 +234718,15 @@
234502234718
if( (flags & SQLITE_CHANGESETAPPLY_FKNOACTION) && savedFlag==0 ){
234503234719
assert( db->flags & SQLITE_FkNoAction );
234504234720
db->flags &= ~((u64)SQLITE_FkNoAction);
234505234721
db->aDb[0].pSchema->schema_cookie -= 32;
234506234722
}
234723
+
234724
+ assert( rc!=SQLITE_OK || sApply.zErr==0 );
234725
+ sqlite3_set_errmsg(db, rc, sApply.zErr);
234726
+ sqlite3_free(sApply.zErr);
234727
+
234507234728
sqlite3_mutex_leave(sqlite3_db_mutex(db));
234508234729
return rc;
234509234730
}
234510234731
234511234732
/*
@@ -237466,11 +237687,11 @@
237466237687
** ){
237467237688
** // The document with rowid iRowid matches the expression!
237468237689
** i64 iRowid = sqlite3Fts5ExprRowid(pExpr);
237469237690
** }
237470237691
*/
237471
-static int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, int bDesc);
237692
+static int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, i64, int bDesc);
237472237693
static int sqlite3Fts5ExprNext(Fts5Expr*, i64 iMax);
237473237694
static int sqlite3Fts5ExprEof(Fts5Expr*);
237474237695
static i64 sqlite3Fts5ExprRowid(Fts5Expr*);
237475237696
237476237697
static void sqlite3Fts5ExprFree(Fts5Expr*);
@@ -243035,11 +243256,17 @@
243035243256
** equal to iFirst.
243036243257
**
243037243258
** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
243038243259
** is not considered an error if the query does not match any documents.
243039243260
*/
243040
-static int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){
243261
+static int sqlite3Fts5ExprFirst(
243262
+ Fts5Expr *p,
243263
+ Fts5Index *pIdx,
243264
+ i64 iFirst,
243265
+ i64 iLast,
243266
+ int bDesc
243267
+){
243041243268
Fts5ExprNode *pRoot = p->pRoot;
243042243269
int rc; /* Return code */
243043243270
243044243271
p->pIndex = pIdx;
243045243272
p->bDesc = bDesc;
@@ -243056,10 +243283,13 @@
243056243283
243057243284
/* If the iterator is not at a real match, skip forward until it is. */
243058243285
while( pRoot->bNomatch && rc==SQLITE_OK ){
243059243286
assert( pRoot->bEof==0 );
243060243287
rc = fts5ExprNodeNext(p, pRoot, 0, 0);
243288
+ }
243289
+ if( fts5RowidCmp(p, pRoot->iRowid, iLast)>0 ){
243290
+ pRoot->bEof = 1;
243061243291
}
243062243292
return rc;
243063243293
}
243064243294
243065243295
/*
@@ -255404,10 +255634,21 @@
255404255634
{
255405255635
pIdxInfo->idxFlags |= SQLITE_INDEX_SCAN_UNIQUE;
255406255636
}
255407255637
#endif
255408255638
}
255639
+
255640
+static void fts5SetEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
255641
+#if SQLITE_VERSION_NUMBER>=3008002
255642
+#ifndef SQLITE_CORE
255643
+ if( sqlite3_libversion_number()>=3008002 )
255644
+#endif
255645
+ {
255646
+ pIdxInfo->estimatedRows = nRow;
255647
+ }
255648
+#endif
255649
+}
255409255650
255410255651
static int fts5UsePatternMatch(
255411255652
Fts5Config *pConfig,
255412255653
struct sqlite3_index_constraint *p
255413255654
){
@@ -255540,11 +255781,11 @@
255540255781
bSeenRank = 1;
255541255782
}else{
255542255783
nSeenMatch++;
255543255784
idxStr[iIdxStr++] = 'M';
255544255785
sqlite3_snprintf(6, &idxStr[iIdxStr], "%d", iCol);
255545
- idxStr += strlen(&idxStr[iIdxStr]);
255786
+ iIdxStr += (int)strlen(&idxStr[iIdxStr]);
255546255787
assert( idxStr[iIdxStr]=='\0' );
255547255788
}
255548255789
pInfo->aConstraintUsage[i].argvIndex = ++iCons;
255549255790
pInfo->aConstraintUsage[i].omit = 1;
255550255791
}
@@ -255559,10 +255800,11 @@
255559255800
nSeenMatch++;
255560255801
}else if( bSeenEq==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol<0 ){
255561255802
idxStr[iIdxStr++] = '=';
255562255803
bSeenEq = 1;
255563255804
pInfo->aConstraintUsage[i].argvIndex = ++iCons;
255805
+ pInfo->aConstraintUsage[i].omit = 1;
255564255806
}
255565255807
}
255566255808
}
255567255809
255568255810
if( bSeenEq==0 ){
@@ -255606,21 +255848,25 @@
255606255848
}
255607255849
}
255608255850
255609255851
/* Calculate the estimated cost based on the flags set in idxFlags. */
255610255852
if( bSeenEq ){
255611
- pInfo->estimatedCost = nSeenMatch ? 1000.0 : 10.0;
255612
- if( nSeenMatch==0 ) fts5SetUniqueFlag(pInfo);
255613
- }else if( bSeenLt && bSeenGt ){
255614
- pInfo->estimatedCost = nSeenMatch ? 5000.0 : 250000.0;
255615
- }else if( bSeenLt || bSeenGt ){
255616
- pInfo->estimatedCost = nSeenMatch ? 7500.0 : 750000.0;
255853
+ pInfo->estimatedCost = nSeenMatch ? 1000.0 : 25.0;
255854
+ fts5SetUniqueFlag(pInfo);
255855
+ fts5SetEstimatedRows(pInfo, 1);
255617255856
}else{
255618
- pInfo->estimatedCost = nSeenMatch ? 10000.0 : 1000000.0;
255619
- }
255620
- for(i=1; i<nSeenMatch; i++){
255621
- pInfo->estimatedCost *= 0.4;
255857
+ if( bSeenLt && bSeenGt ){
255858
+ pInfo->estimatedCost = nSeenMatch ? 5000.0 : 750000.0;
255859
+ }else if( bSeenLt || bSeenGt ){
255860
+ pInfo->estimatedCost = nSeenMatch ? 7500.0 : 2250000.0;
255861
+ }else{
255862
+ pInfo->estimatedCost = nSeenMatch ? 10000.0 : 3000000.0;
255863
+ }
255864
+ for(i=1; i<nSeenMatch; i++){
255865
+ pInfo->estimatedCost *= 0.4;
255866
+ }
255867
+ fts5SetEstimatedRows(pInfo, (i64)(pInfo->estimatedCost / 4.0));
255622255868
}
255623255869
255624255870
pInfo->idxNum = idxFlags;
255625255871
return SQLITE_OK;
255626255872
}
@@ -255815,11 +256061,13 @@
255815256061
if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_RESEEK) ){
255816256062
Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
255817256063
int bDesc = pCsr->bDesc;
255818256064
i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr);
255819256065
255820
- rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->p.pIndex, iRowid, bDesc);
256066
+ rc = sqlite3Fts5ExprFirst(
256067
+ pCsr->pExpr, pTab->p.pIndex, iRowid, pCsr->iLastRowid, bDesc
256068
+ );
255821256069
if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){
255822256070
*pbSkip = 1;
255823256071
}
255824256072
255825256073
CsrFlagClear(pCsr, FTS5CSR_REQUIRE_RESEEK);
@@ -255987,11 +256235,13 @@
255987256235
}
255988256236
255989256237
static int fts5CursorFirst(Fts5FullTable *pTab, Fts5Cursor *pCsr, int bDesc){
255990256238
int rc;
255991256239
Fts5Expr *pExpr = pCsr->pExpr;
255992
- rc = sqlite3Fts5ExprFirst(pExpr, pTab->p.pIndex, pCsr->iFirstRowid, bDesc);
256240
+ rc = sqlite3Fts5ExprFirst(
256241
+ pExpr, pTab->p.pIndex, pCsr->iFirstRowid, pCsr->iLastRowid, bDesc
256242
+ );
255993256243
if( sqlite3Fts5ExprEof(pExpr) ){
255994256244
CsrFlagSet(pCsr, FTS5CSR_EOF);
255995256245
}
255996256246
fts5CsrNewrow(pCsr);
255997256247
return rc;
@@ -258472,11 +258722,11 @@
258472258722
int nArg, /* Number of args */
258473258723
sqlite3_value **apUnused /* Function arguments */
258474258724
){
258475258725
assert( nArg==0 );
258476258726
UNUSED_PARAM2(nArg, apUnused);
258477
- sqlite3_result_text(pCtx, "fts5: 2025-09-10 14:28:07 61d9e204c5801a94811fdb0afe2c04f9814e08f2e141afa6dbda0fa45f026f70", -1, SQLITE_TRANSIENT);
258727
+ sqlite3_result_text(pCtx, "fts5: 2025-09-24 19:10:58 821cc0e421bc14a68ebaee507e38a900e0c84ff6ba7ee95bf796cad387755232", -1, SQLITE_TRANSIENT);
258478258728
}
258479258729
258480258730
/*
258481258731
** Implementation of fts5_locale(LOCALE, TEXT) function.
258482258732
**
258483258733
--- 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 ** 61d9e204c5801a94811fdb0afe2c04f9814e with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -168,11 +168,13 @@
168 #define SQLITE_OMIT_LOAD_EXTENSION 1
169 #define SQLITE_ENABLE_LOCKING_STYLE 0
170 #define HAVE_UTIME 1
171 #else
172 /* This is not VxWorks. */
173 #define OS_VXWORKS 0
 
 
174 #define HAVE_FCHOWN 1
175 #define HAVE_READLINK 1
176 #define HAVE_LSTAT 1
177 #endif /* defined(_WRS_KERNEL) */
178
@@ -465,14 +467,14 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.51.0"
469 #define SQLITE_VERSION_NUMBER 3051000
470 #define SQLITE_SOURCE_ID "2025-09-10 14:28:07 61d9e204c5801a94811fdb0afe2c04f9814e08f2e141afa6dbda0fa45f026f70"
471 #define SQLITE_SCM_BRANCH "trunk"
472 #define SQLITE_SCM_TAGS ""
473 #define SQLITE_SCM_DATETIME "2025-09-10T14:28:07.926Z"
474
475 /*
476 ** CAPI3REF: Run-Time Library Version Numbers
477 ** KEYWORDS: sqlite3_version sqlite3_sourceid
478 **
@@ -4523,10 +4525,38 @@
4523 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
4524 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
4525 SQLITE_API const char *sqlite3_errstr(int);
4526 SQLITE_API int sqlite3_error_offset(sqlite3 *db);
4527
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4528 /*
4529 ** CAPI3REF: Prepared Statement Object
4530 ** KEYWORDS: {prepared statement} {prepared statements}
4531 **
4532 ** An instance of this object represents a single SQL statement that
@@ -12662,10 +12692,19 @@
12662 ** CAPI3REF: Apply A Changeset To A Database
12663 **
12664 ** Apply a changeset or patchset to a database. These functions attempt to
12665 ** update the "main" database attached to handle db with the changes found in
12666 ** the changeset passed via the second and third arguments.
 
 
 
 
 
 
 
 
 
12667 **
12668 ** The fourth argument (xFilter) passed to these functions is the "filter
12669 ** callback". This may be passed NULL, in which case all changes in the
12670 ** changeset are applied to the database. For sqlite3changeset_apply() and
12671 ** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
@@ -12800,16 +12839,10 @@
12800 ** It is safe to execute SQL statements, including those that write to the
12801 ** table that the callback related to, from within the xConflict callback.
12802 ** This can be used to further customize the application's conflict
12803 ** resolution strategy.
12804 **
12805 ** All changes made by these functions are enclosed in a savepoint transaction.
12806 ** If any other error (aside from a constraint failure when attempting to
12807 ** write to the target database) occurs, then the savepoint transaction is
12808 ** rolled back, restoring the target database to its original state, and an
12809 ** SQLite error code returned.
12810 **
12811 ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
12812 ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
12813 ** may set (*ppRebase) to point to a "rebase" that may be used with the
12814 ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
12815 ** is set to the size of the buffer in bytes. It is the responsibility of the
@@ -18155,11 +18188,11 @@
18155 struct sqlite3InitInfo { /* Information used during initialization */
18156 Pgno newTnum; /* Rootpage of table being initialized */
18157 u8 iDb; /* Which db file is being initialized */
18158 u8 busy; /* TRUE if currently initializing */
18159 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
18160 unsigned imposterTable : 1; /* Building an imposter table */
18161 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
18162 const char **azInit; /* "type", "name", and "tbl_name" columns */
18163 } init;
18164 int nVdbeActive; /* Number of VDBEs currently running */
18165 int nVdbeRead; /* Number of active VDBEs that read or write */
@@ -18948,10 +18981,11 @@
18948 #define TF_Shadow 0x00001000 /* True for a shadow table */
18949 #define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
18950 #define TF_Ephemeral 0x00004000 /* An ephemeral table */
18951 #define TF_Eponymous 0x00008000 /* An eponymous virtual table */
18952 #define TF_Strict 0x00010000 /* STRICT mode */
 
18953
18954 /*
18955 ** Allowed values for Table.eTabType
18956 */
18957 #define TABTYP_NORM 0 /* Ordinary table */
@@ -25009,10 +25043,14 @@
25009 if( getDigits(zDate, "20b:20e", &nHr, &nMn)!=2 ){
25010 return 1;
25011 }
25012 zDate += 5;
25013 p->tz = sgn*(nMn + nHr*60);
 
 
 
 
25014 zulu_time:
25015 while( sqlite3Isspace(*zDate) ){ zDate++; }
25016 return *zDate!=0;
25017 }
25018
@@ -38168,11 +38206,11 @@
38168 static int kvstorageDelete(const char*, const char *zKey);
38169 static int kvstorageRead(const char*, const char *zKey, char *zBuf, int nBuf);
38170 #define KVSTORAGE_KEY_SZ 32
38171
38172 /* Expand the key name with an appropriate prefix and put the result
38173 ** zKeyOut[]. The zKeyOut[] buffer is assumed to hold at least
38174 ** KVSTORAGE_KEY_SZ bytes.
38175 */
38176 static void kvstorageMakeKey(
38177 const char *zClass,
38178 const char *zKeyIn,
@@ -38227,14 +38265,16 @@
38227 ** enough to hold it all. The value put into zBuf must always be zero
38228 ** terminated, even if it gets truncated because nBuf is not large enough.
38229 **
38230 ** Return the total number of bytes in the data, without truncation, and
38231 ** not counting the final zero terminator. Return -1 if the key does
38232 ** not exist.
38233 **
38234 ** If nBuf<=0 then this routine simply returns the size of the data without
38235 ** actually reading it.
 
 
38236 */
38237 static int kvstorageRead(
38238 const char *zClass,
38239 const char *zKey,
38240 char *zBuf,
@@ -38279,15 +38319,13 @@
38279 /*
38280 ** An internal level of indirection which enables us to replace the
38281 ** kvvfs i/o methods with JavaScript implementations in WASM builds.
38282 ** Maintenance reminder: if this struct changes in any way, the JSON
38283 ** rendering of its structure must be updated in
38284 ** sqlite3_wasm_enum_json(). There are no binary compatibility
38285 ** concerns, so it does not need an iVersion member. This file is
38286 ** necessarily always compiled together with sqlite3_wasm_enum_json(),
38287 ** and JS code dynamically creates the mapping of members based on
38288 ** that JSON description.
38289 */
38290 typedef struct sqlite3_kvvfs_methods sqlite3_kvvfs_methods;
38291 struct sqlite3_kvvfs_methods {
38292 int (*xRead)(const char *zClass, const char *zKey, char *zBuf, int nBuf);
38293 int (*xWrite)(const char *zClass, const char *zKey, const char *zData);
@@ -38300,12 +38338,12 @@
38300 ** for JavaScript-side implementations in WASM builds. In such builds
38301 ** it cannot be const, but in native builds it should be so that
38302 ** the compiler can hopefully optimize this level of indirection out.
38303 ** That said, kvvfs is intended primarily for use in WASM builds.
38304 **
38305 ** Note that this is not explicitly flagged as static because the
38306 ** amalgamation build will tag it with SQLITE_PRIVATE.
38307 */
38308 #ifndef SQLITE_WASM
38309 const
38310 #endif
38311 SQLITE_PRIVATE sqlite3_kvvfs_methods sqlite3KvvfsMethods = {
@@ -39736,13 +39774,12 @@
39736 return fd;
39737 }
39738
39739 /*
39740 ** Helper functions to obtain and relinquish the global mutex. The
39741 ** global mutex is used to protect the unixInodeInfo and
39742 ** vxworksFileId objects used by this file, all of which may be
39743 ** shared by multiple threads.
39744 **
39745 ** Function unixMutexHeld() is used to assert() that the global mutex
39746 ** is held when required. This function is only used as part of assert()
39747 ** statements. e.g.
39748 **
@@ -39940,10 +39977,11 @@
39940 /*
39941 ** All unique filenames are held on a linked list headed by this
39942 ** variable:
39943 */
39944 static struct vxworksFileId *vxworksFileList = 0;
 
39945
39946 /*
39947 ** Simplify a filename into its canonical form
39948 ** by making the following changes:
39949 **
@@ -40005,47 +40043,47 @@
40005
40006 /* Search for an existing entry that matching the canonical name.
40007 ** If found, increment the reference count and return a pointer to
40008 ** the existing file ID.
40009 */
40010 unixEnterMutex();
40011 for(pCandidate=vxworksFileList; pCandidate; pCandidate=pCandidate->pNext){
40012 if( pCandidate->nName==n
40013 && memcmp(pCandidate->zCanonicalName, pNew->zCanonicalName, n)==0
40014 ){
40015 sqlite3_free(pNew);
40016 pCandidate->nRef++;
40017 unixLeaveMutex();
40018 return pCandidate;
40019 }
40020 }
40021
40022 /* No match was found. We will make a new file ID */
40023 pNew->nRef = 1;
40024 pNew->nName = n;
40025 pNew->pNext = vxworksFileList;
40026 vxworksFileList = pNew;
40027 unixLeaveMutex();
40028 return pNew;
40029 }
40030
40031 /*
40032 ** Decrement the reference count on a vxworksFileId object. Free
40033 ** the object when the reference count reaches zero.
40034 */
40035 static void vxworksReleaseFileId(struct vxworksFileId *pId){
40036 unixEnterMutex();
40037 assert( pId->nRef>0 );
40038 pId->nRef--;
40039 if( pId->nRef==0 ){
40040 struct vxworksFileId **pp;
40041 for(pp=&vxworksFileList; *pp && *pp!=pId; pp = &((*pp)->pNext)){}
40042 assert( *pp==pId );
40043 *pp = pId->pNext;
40044 sqlite3_free(pId);
40045 }
40046 unixLeaveMutex();
40047 }
40048 #endif /* OS_VXWORKS */
40049 /*************** End of Unique File ID Utility Used By VxWorks ****************
40050 ******************************************************************************/
40051
@@ -44958,14 +44996,21 @@
44958 #endif
44959
44960 storeLastErrno(pNew, 0);
44961 #if OS_VXWORKS
44962 if( rc!=SQLITE_OK ){
44963 if( h>=0 ) robust_close(pNew, h, __LINE__);
44964 h = -1;
44965 osUnlink(zFilename);
44966 pNew->ctrlFlags |= UNIXFILE_DELETE;
 
 
 
 
 
 
 
44967 }
44968 #endif
44969 if( rc!=SQLITE_OK ){
44970 if( h>=0 ) robust_close(pNew, h, __LINE__);
44971 }else{
@@ -45005,10 +45050,13 @@
45005 struct stat buf;
45006 const char *zDir = sqlite3_temp_directory;
45007
45008 while(1){
45009 if( zDir!=0
 
 
 
45010 && osStat(zDir, &buf)==0
45011 && S_ISDIR(buf.st_mode)
45012 && osAccess(zDir, 03)==0
45013 ){
45014 return zDir;
@@ -45318,10 +45366,16 @@
45318 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
45319 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
45320 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL
45321 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
45322 );
 
 
 
 
 
 
45323
45324 /* Detect a pid change and reset the PRNG. There is a race condition
45325 ** here such that two or more threads all trying to open databases at
45326 ** the same instant might all reset the PRNG. But multiple resets
45327 ** are harmless.
@@ -45519,12 +45573,15 @@
45519 goto open_finished;
45520 }
45521 }
45522 #endif
45523
45524 assert( zPath==0 || zPath[0]=='/'
45525 || eType==SQLITE_OPEN_SUPER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
 
 
 
45526 );
45527 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
45528
45529 open_finished:
45530 if( rc!=SQLITE_OK ){
@@ -47249,10 +47306,13 @@
47249 }
47250 #ifdef SQLITE_OS_KV_OPTIONAL
47251 sqlite3KvvfsInit();
47252 #endif
47253 unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
 
 
 
47254
47255 #ifndef SQLITE_OMIT_WAL
47256 /* Validate lock assumptions */
47257 assert( SQLITE_SHM_NLOCK==8 ); /* Number of available locks */
47258 assert( UNIX_SHM_BASE==120 ); /* Start of locking area */
@@ -47283,10 +47343,13 @@
47283 ** to release dynamically allocated objects. But not on unix.
47284 ** This routine is a no-op for unix.
47285 */
47286 SQLITE_API int sqlite3_os_end(void){
47287 unixBigLock = 0;
 
 
 
47288 return SQLITE_OK;
47289 }
47290
47291 #endif /* SQLITE_OS_UNIX */
47292
@@ -62006,18 +62069,31 @@
62006 SQLITE_PRIVATE void sqlite3PagerSetFlags(
62007 Pager *pPager, /* The pager to set safety level for */
62008 unsigned pgFlags /* Various flags */
62009 ){
62010 unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK;
62011 if( pPager->tempFile ){
62012 pPager->noSync = 1;
62013 pPager->fullSync = 0;
62014 pPager->extraSync = 0;
62015 }else{
62016 pPager->noSync = level==PAGER_SYNCHRONOUS_OFF ?1:0;
62017 pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
62018 pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
 
 
 
 
 
 
 
 
 
 
 
 
 
62019 }
62020 if( pPager->noSync ){
62021 pPager->syncFlags = 0;
62022 }else if( pgFlags & PAGER_FULLFSYNC ){
62023 pPager->syncFlags = SQLITE_SYNC_FULL;
@@ -113289,13 +113365,12 @@
113289 }
113290 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, pFree1);
113291 if( addrIsNull==0 ){
113292 /*
113293 ** If the right operand contains a subquery and the left operand does not
113294 ** and the left operand might be NULL, then check the left operand do
113295 ** an IsNull check on the left operand before computing the right
113296 ** operand.
113297 */
113298 if( ExprHasProperty(pExpr->pRight, EP_Subquery)
113299 && sqlite3ExprCanBeNull(pExpr->pLeft)
113300 ){
113301 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, r1);
@@ -115660,10 +115735,82 @@
115660 }
115661 }
115662 return 0;
115663 }
115664
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115665
115666 /*
115667 ** Generate code into the current Vdbe to evaluate the given
115668 ** expression. Attempt to store the results in register "target".
115669 ** Return the register where results are stored.
@@ -115948,16 +116095,18 @@
115948 sqlite3VdbeAddOp2(v, OP_Null, 0, inReg);
115949 }
115950 }
115951 testcase( regFree1==0 );
115952 testcase( regFree2==0 );
115953
115954 }
115955 break;
115956 }
115957 case TK_AND:
115958 case TK_OR:
 
 
 
115959 case TK_PLUS:
115960 case TK_STAR:
115961 case TK_MINUS:
115962 case TK_REM:
115963 case TK_BITAND:
@@ -115965,12 +116114,10 @@
115965 case TK_SLASH:
115966 case TK_LSHIFT:
115967 case TK_RSHIFT:
115968 case TK_CONCAT: {
115969 int addrIsNull;
115970 assert( TK_AND==OP_And ); testcase( op==TK_AND );
115971 assert( TK_OR==OP_Or ); testcase( op==TK_OR );
115972 assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
115973 assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
115974 assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
115975 assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND );
115976 assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
@@ -125050,10 +125197,13 @@
125050 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
125051 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
125052 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
125053 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
125054 sqlite3VdbeAddOp0(v, OP_Close);
 
 
 
125055 }
125056
125057 /* Normal (non-error) return. */
125058 return;
125059
@@ -139432,10 +139582,12 @@
139432 /* Version 3.44.0 and later */
139433 void *(*get_clientdata)(sqlite3*,const char*);
139434 int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*));
139435 /* Version 3.50.0 and later */
139436 int (*setlk_timeout)(sqlite3*,int,int);
 
 
139437 };
139438
139439 /*
139440 ** This is the function signature used for all extension entry points. It
139441 ** is also defined in the file "loadext.c".
@@ -139767,10 +139919,12 @@
139767 /* Version 3.44.0 and later */
139768 #define sqlite3_get_clientdata sqlite3_api->get_clientdata
139769 #define sqlite3_set_clientdata sqlite3_api->set_clientdata
139770 /* Version 3.50.0 and later */
139771 #define sqlite3_setlk_timeout sqlite3_api->setlk_timeout
 
 
139772 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
139773
139774 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
139775 /* This case when the file really is being compiled as a loadable
139776 ** extension */
@@ -140290,11 +140444,13 @@
140290 sqlite3_stmt_explain,
140291 /* Version 3.44.0 and later */
140292 sqlite3_get_clientdata,
140293 sqlite3_set_clientdata,
140294 /* Version 3.50.0 and later */
140295 sqlite3_setlk_timeout
 
 
140296 };
140297
140298 /* True if x is the directory separator character
140299 */
140300 #if SQLITE_OS_WIN
@@ -141751,10 +141907,26 @@
141751 addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
141752 VdbeCoverage(v);
141753 sqlite3VdbeAddOp0(v, OP_Halt);
141754 return addr;
141755 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141756
141757 /*
141758 ** Process a pragma statement.
141759 **
141760 ** Pragmas are of this form:
@@ -143097,11 +143269,11 @@
143097 pTbls = &db->aDb[i].pSchema->tblHash;
143098 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143099 Table *pTab = sqliteHashData(x); /* Current table */
143100 Index *pIdx; /* An index on pTab */
143101 int nIdx; /* Number of indexes on pTab */
143102 if( pObjTab && pObjTab!=pTab ) continue;
143103 if( HasRowid(pTab) ) cnt++;
143104 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
143105 }
143106 if( cnt==0 ) continue;
143107 if( pObjTab ) cnt++;
@@ -143110,11 +143282,11 @@
143110 cnt = 0;
143111 if( pObjTab ) aRoot[++cnt] = 0;
143112 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143113 Table *pTab = sqliteHashData(x);
143114 Index *pIdx;
143115 if( pObjTab && pObjTab!=pTab ) continue;
143116 if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum;
143117 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
143118 aRoot[++cnt] = pIdx->tnum;
143119 }
143120 }
@@ -143141,11 +143313,11 @@
143141 sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
143142 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143143 int iTab = 0;
143144 Table *pTab = sqliteHashData(x);
143145 Index *pIdx;
143146 if( pObjTab && pObjTab!=pTab ) continue;
143147 if( HasRowid(pTab) ){
143148 iTab = cnt++;
143149 }else{
143150 iTab = cnt;
143151 for(pIdx=pTab->pIndex; ALWAYS(pIdx); pIdx=pIdx->pNext){
@@ -143177,11 +143349,11 @@
143177 int r1 = -1;
143178 int bStrict; /* True for a STRICT table */
143179 int r2; /* Previous key for WITHOUT ROWID tables */
143180 int mxCol; /* Maximum non-virtual column number */
143181
143182 if( pObjTab && pObjTab!=pTab ) continue;
143183 if( !IsOrdinaryTable(pTab) ) continue;
143184 if( isQuick || HasRowid(pTab) ){
143185 pPk = 0;
143186 r2 = 0;
143187 }else{
@@ -143501,11 +143673,11 @@
143501 */
143502 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143503 Table *pTab = sqliteHashData(x);
143504 sqlite3_vtab *pVTab;
143505 int a1;
143506 if( pObjTab && pObjTab!=pTab ) continue;
143507 if( IsOrdinaryTable(pTab) ) continue;
143508 if( !IsVirtual(pTab) ) continue;
143509 if( pTab->nCol<=0 ){
143510 const char *zMod = pTab->u.vtab.azArg[0];
143511 if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
@@ -170516,10 +170688,14 @@
170516 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
170517 if( pLoop->u.vtab.isOrdered
170518 && ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY)
170519 ){
170520 obSat = obDone;
 
 
 
 
170521 }
170522 break;
170523 }
170524 iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
170525
@@ -171419,22 +171595,18 @@
171419 pFrom = aTo;
171420 aTo = aFrom;
171421 aFrom = pFrom;
171422 nFrom = nTo;
171423 }
 
171424
171425 if( nFrom==0 ){
171426 sqlite3ErrorMsg(pParse, "no query solution");
171427 sqlite3StackFreeNN(pParse->db, pSpace);
171428 return SQLITE_ERROR;
171429 }
171430
171431 /* Find the lowest cost path. pFrom will be left pointing to that path */
171432 pFrom = aFrom;
171433 for(ii=1; ii<nFrom; ii++){
171434 if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
171435 }
171436 assert( pWInfo->nLevel==nLoop );
171437 /* Load the lowest cost path into pWInfo */
171438 for(iLoop=0; iLoop<nLoop; iLoop++){
171439 WhereLevel *pLevel = pWInfo->a + iLoop;
171440 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -171563,11 +171735,14 @@
171563 int once = 0;
171564 #endif
171565 for(i=0; i<pWInfo->nLevel; i++){
171566 WhereLoop *p = pWInfo->a[i].pWLoop;
171567 if( p==0 ) break;
171568 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 ) continue;
 
 
 
171569 if( (p->wsFlags & (WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0 ){
171570 u8 iTab = p->iTab;
171571 WhereLoop *pLoop;
171572 for(pLoop=pWInfo->pLoops; pLoop; pLoop=pLoop->pNextLoop){
171573 if( pLoop->iTab!=iTab ) continue;
@@ -175676,11 +175851,11 @@
175676 ** RETURN_ROW
175677 **
175678 **
175679 ** ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
175680 **
175681 ** ... loop started by sqlite3WhereBegin() ...
175682 ** if( new partition ){
175683 ** Gosub flush
175684 ** }
175685 ** Insert new row into eph table.
175686 ** if( first row of partition ){
@@ -176194,10 +176369,16 @@
176194 addrStart = sqlite3VdbeCurrentAddr(v);
176195 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regStart, 1);
176196 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
176197 }else{
176198 assert( pMWin->eEnd==TK_FOLLOWING );
 
 
 
 
 
 
176199 addrStart = sqlite3VdbeCurrentAddr(v);
176200 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 1);
176201 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
176202 }
176203 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
@@ -186322,10 +186503,33 @@
186322 }
186323 }
186324 sqlite3_mutex_leave(db->mutex);
186325 return z;
186326 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186327
186328 /*
186329 ** Return the byte offset of the most recent error
186330 */
186331 SQLITE_API int sqlite3_error_offset(sqlite3 *db){
@@ -188147,17 +188351,19 @@
188147 case SQLITE_TESTCTRL_ISINIT: {
188148 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
188149 break;
188150 }
188151
188152 /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
188153 **
188154 ** This test control is used to create imposter tables. "db" is a pointer
188155 ** to the database connection. dbName is the database name (ex: "main" or
188156 ** "temp") which will receive the imposter. "onOff" turns imposter mode on
188157 ** or off. "tnum" is the root page of the b-tree to which the imposter
188158 ** table should connect.
 
 
188159 **
188160 ** Enable imposter mode only when the schema has already been parsed. Then
188161 ** run a single CREATE TABLE statement to construct the imposter table in
188162 ** the parsed schema. Then turn imposter mode back off again.
188163 **
@@ -228653,11 +228859,11 @@
228653 typedef struct DbpageCursor DbpageCursor;
228654
228655 struct DbpageCursor {
228656 sqlite3_vtab_cursor base; /* Base class. Must be first */
228657 Pgno pgno; /* Current page number */
228658 int mxPgno; /* Last page to visit on this scan */
228659 Pager *pPager; /* Pager being read/written */
228660 DbPage *pPage1; /* Page 1 of the database */
228661 int iDb; /* Index of database to analyze */
228662 int szPage; /* Size of each page in bytes */
228663 };
@@ -231924,10 +232130,23 @@
231924 assert( (a - p->aRecord)==p->nRecord );
231925 }
231926
231927 return rc;
231928 }
 
 
 
 
 
 
 
 
 
 
 
 
 
231929
231930 /*
231931 ** Formulate and prepare a SELECT statement to retrieve a row from table
231932 ** zTab in database zDb based on its primary key. i.e.
231933 **
@@ -231946,16 +232165,16 @@
231946 const char *zTab, /* Table name */
231947 int bRowid,
231948 int nCol, /* Number of columns in table */
231949 const char **azCol, /* Names of table columns */
231950 u8 *abPK, /* PRIMARY KEY array */
231951 sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
 
231952 ){
231953 int rc = SQLITE_OK;
231954 char *zSql = 0;
231955 const char *zSep = "";
231956 int nSql = -1;
231957 int i;
231958
231959 SessionBuffer cols = {0, 0, 0};
231960 SessionBuffer nooptest = {0, 0, 0};
231961 SessionBuffer pkfield = {0, 0, 0};
@@ -232031,11 +232250,11 @@
232031 nSql = buf.nBuf;
232032 }
232033 #endif
232034
232035 if( rc==SQLITE_OK ){
232036 rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, 0);
232037 }
232038 sqlite3_free(zSql);
232039 sqlite3_free(nooptest.aBuf);
232040 sqlite3_free(pkfield.aBuf);
232041 sqlite3_free(pkvar.aBuf);
@@ -232195,11 +232414,11 @@
232195 sessionAppendTableHdr(&buf, bPatchset, pTab, &rc);
232196
232197 /* Build and compile a statement to execute: */
232198 if( rc==SQLITE_OK ){
232199 rc = sessionSelectStmt(db, 0, pSession->zDb,
232200 zName, pTab->bRowid, pTab->nCol, pTab->azCol, pTab->abPK, &pSel
232201 );
232202 }
232203
232204 nNoop = buf.nBuf;
232205 for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
@@ -233404,10 +233623,11 @@
233404 SessionBuffer rebase; /* Rebase information (if any) here */
233405 u8 bRebaseStarted; /* If table header is already in rebase */
233406 u8 bRebase; /* True to collect rebase information */
233407 u8 bIgnoreNoop; /* True to ignore no-op conflicts */
233408 int bRowid;
 
233409 };
233410
233411 /* Number of prepared UPDATE statements to cache. */
233412 #define SESSION_UPDATE_CACHE_SZ 12
233413
@@ -233629,11 +233849,11 @@
233629 }
233630 sessionAppendStr(&buf, ")", &rc);
233631 }
233632
233633 if( rc==SQLITE_OK ){
233634 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pDelete, 0);
233635 }
233636 sqlite3_free(buf.aBuf);
233637
233638 return rc;
233639 }
@@ -233656,11 +233876,11 @@
233656 const char *zTab, /* Table name */
233657 SessionApplyCtx *p /* Session changeset-apply context */
233658 ){
233659 /* TODO */
233660 return sessionSelectStmt(db, p->bIgnoreNoop,
233661 "main", zTab, p->bRowid, p->nCol, p->azCol, p->abPK, &p->pSelect
233662 );
233663 }
233664
233665 /*
233666 ** Formulate and prepare an INSERT statement to add a record to table zTab.
@@ -233693,37 +233913,33 @@
233693 sessionAppendStr(&buf, ", ?", &rc);
233694 }
233695 sessionAppendStr(&buf, ")", &rc);
233696
233697 if( rc==SQLITE_OK ){
233698 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pInsert, 0);
233699 }
233700 sqlite3_free(buf.aBuf);
233701 return rc;
233702 }
233703
233704 static int sessionPrepare(sqlite3 *db, sqlite3_stmt **pp, const char *zSql){
233705 return sqlite3_prepare_v2(db, zSql, -1, pp, 0);
233706 }
233707
233708 /*
233709 ** Prepare statements for applying changes to the sqlite_stat1 table.
233710 ** These are similar to those created by sessionSelectRow(),
233711 ** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for
233712 ** other tables.
233713 */
233714 static int sessionStat1Sql(sqlite3 *db, SessionApplyCtx *p){
233715 int rc = sessionSelectRow(db, "sqlite_stat1", p);
233716 if( rc==SQLITE_OK ){
233717 rc = sessionPrepare(db, &p->pInsert,
233718 "INSERT INTO main.sqlite_stat1 VALUES(?1, "
233719 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
233720 "?3)"
233721 );
233722 }
233723 if( rc==SQLITE_OK ){
233724 rc = sessionPrepare(db, &p->pDelete,
233725 "DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS "
233726 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
233727 "AND (?4 OR stat IS ?3)"
233728 );
233729 }
@@ -234502,10 +234718,15 @@
234502 if( (flags & SQLITE_CHANGESETAPPLY_FKNOACTION) && savedFlag==0 ){
234503 assert( db->flags & SQLITE_FkNoAction );
234504 db->flags &= ~((u64)SQLITE_FkNoAction);
234505 db->aDb[0].pSchema->schema_cookie -= 32;
234506 }
 
 
 
 
 
234507 sqlite3_mutex_leave(sqlite3_db_mutex(db));
234508 return rc;
234509 }
234510
234511 /*
@@ -237466,11 +237687,11 @@
237466 ** ){
237467 ** // The document with rowid iRowid matches the expression!
237468 ** i64 iRowid = sqlite3Fts5ExprRowid(pExpr);
237469 ** }
237470 */
237471 static int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, int bDesc);
237472 static int sqlite3Fts5ExprNext(Fts5Expr*, i64 iMax);
237473 static int sqlite3Fts5ExprEof(Fts5Expr*);
237474 static i64 sqlite3Fts5ExprRowid(Fts5Expr*);
237475
237476 static void sqlite3Fts5ExprFree(Fts5Expr*);
@@ -243035,11 +243256,17 @@
243035 ** equal to iFirst.
243036 **
243037 ** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
243038 ** is not considered an error if the query does not match any documents.
243039 */
243040 static int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){
 
 
 
 
 
 
243041 Fts5ExprNode *pRoot = p->pRoot;
243042 int rc; /* Return code */
243043
243044 p->pIndex = pIdx;
243045 p->bDesc = bDesc;
@@ -243056,10 +243283,13 @@
243056
243057 /* If the iterator is not at a real match, skip forward until it is. */
243058 while( pRoot->bNomatch && rc==SQLITE_OK ){
243059 assert( pRoot->bEof==0 );
243060 rc = fts5ExprNodeNext(p, pRoot, 0, 0);
 
 
 
243061 }
243062 return rc;
243063 }
243064
243065 /*
@@ -255404,10 +255634,21 @@
255404 {
255405 pIdxInfo->idxFlags |= SQLITE_INDEX_SCAN_UNIQUE;
255406 }
255407 #endif
255408 }
 
 
 
 
 
 
 
 
 
 
 
255409
255410 static int fts5UsePatternMatch(
255411 Fts5Config *pConfig,
255412 struct sqlite3_index_constraint *p
255413 ){
@@ -255540,11 +255781,11 @@
255540 bSeenRank = 1;
255541 }else{
255542 nSeenMatch++;
255543 idxStr[iIdxStr++] = 'M';
255544 sqlite3_snprintf(6, &idxStr[iIdxStr], "%d", iCol);
255545 idxStr += strlen(&idxStr[iIdxStr]);
255546 assert( idxStr[iIdxStr]=='\0' );
255547 }
255548 pInfo->aConstraintUsage[i].argvIndex = ++iCons;
255549 pInfo->aConstraintUsage[i].omit = 1;
255550 }
@@ -255559,10 +255800,11 @@
255559 nSeenMatch++;
255560 }else if( bSeenEq==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol<0 ){
255561 idxStr[iIdxStr++] = '=';
255562 bSeenEq = 1;
255563 pInfo->aConstraintUsage[i].argvIndex = ++iCons;
 
255564 }
255565 }
255566 }
255567
255568 if( bSeenEq==0 ){
@@ -255606,21 +255848,25 @@
255606 }
255607 }
255608
255609 /* Calculate the estimated cost based on the flags set in idxFlags. */
255610 if( bSeenEq ){
255611 pInfo->estimatedCost = nSeenMatch ? 1000.0 : 10.0;
255612 if( nSeenMatch==0 ) fts5SetUniqueFlag(pInfo);
255613 }else if( bSeenLt && bSeenGt ){
255614 pInfo->estimatedCost = nSeenMatch ? 5000.0 : 250000.0;
255615 }else if( bSeenLt || bSeenGt ){
255616 pInfo->estimatedCost = nSeenMatch ? 7500.0 : 750000.0;
255617 }else{
255618 pInfo->estimatedCost = nSeenMatch ? 10000.0 : 1000000.0;
255619 }
255620 for(i=1; i<nSeenMatch; i++){
255621 pInfo->estimatedCost *= 0.4;
 
 
 
 
 
 
 
255622 }
255623
255624 pInfo->idxNum = idxFlags;
255625 return SQLITE_OK;
255626 }
@@ -255815,11 +256061,13 @@
255815 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_RESEEK) ){
255816 Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
255817 int bDesc = pCsr->bDesc;
255818 i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr);
255819
255820 rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->p.pIndex, iRowid, bDesc);
 
 
255821 if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){
255822 *pbSkip = 1;
255823 }
255824
255825 CsrFlagClear(pCsr, FTS5CSR_REQUIRE_RESEEK);
@@ -255987,11 +256235,13 @@
255987 }
255988
255989 static int fts5CursorFirst(Fts5FullTable *pTab, Fts5Cursor *pCsr, int bDesc){
255990 int rc;
255991 Fts5Expr *pExpr = pCsr->pExpr;
255992 rc = sqlite3Fts5ExprFirst(pExpr, pTab->p.pIndex, pCsr->iFirstRowid, bDesc);
 
 
255993 if( sqlite3Fts5ExprEof(pExpr) ){
255994 CsrFlagSet(pCsr, FTS5CSR_EOF);
255995 }
255996 fts5CsrNewrow(pCsr);
255997 return rc;
@@ -258472,11 +258722,11 @@
258472 int nArg, /* Number of args */
258473 sqlite3_value **apUnused /* Function arguments */
258474 ){
258475 assert( nArg==0 );
258476 UNUSED_PARAM2(nArg, apUnused);
258477 sqlite3_result_text(pCtx, "fts5: 2025-09-10 14:28:07 61d9e204c5801a94811fdb0afe2c04f9814e08f2e141afa6dbda0fa45f026f70", -1, SQLITE_TRANSIENT);
258478 }
258479
258480 /*
258481 ** Implementation of fts5_locale(LOCALE, TEXT) function.
258482 **
258483
--- 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 ** 821cc0e421bc14a68ebaee507e38a900e0c8 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -168,11 +168,13 @@
168 #define SQLITE_OMIT_LOAD_EXTENSION 1
169 #define SQLITE_ENABLE_LOCKING_STYLE 0
170 #define HAVE_UTIME 1
171 #else
172 /* This is not VxWorks. */
173 #ifndef OS_VXWORKS
174 # define OS_VXWORKS 0
175 #endif
176 #define HAVE_FCHOWN 1
177 #define HAVE_READLINK 1
178 #define HAVE_LSTAT 1
179 #endif /* defined(_WRS_KERNEL) */
180
@@ -465,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.51.0"
471 #define SQLITE_VERSION_NUMBER 3051000
472 #define SQLITE_SOURCE_ID "2025-09-24 19:10:58 821cc0e421bc14a68ebaee507e38a900e0c84ff6ba7ee95bf796cad387755232"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-09-24T19:10:58.215Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4523,10 +4525,38 @@
4525 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
4526 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
4527 SQLITE_API const char *sqlite3_errstr(int);
4528 SQLITE_API int sqlite3_error_offset(sqlite3 *db);
4529
4530 /*
4531 ** CAPI3REF: Set Error Codes And Message
4532 ** METHOD: sqlite3
4533 **
4534 ** Set the error code of the database handle passed as the first argument
4535 ** to errcode, and the error message to a copy of nul-terminated string
4536 ** zErrMsg. If zErrMsg is passed NULL, then the error message is set to
4537 ** the default message associated with the supplied error code. Subsequent
4538 ** calls to [sqlite3_errcode()] and [sqlite3_errmsg()] and similar will
4539 ** return the values set by this routine in place of what was previously
4540 ** set by SQLite itself.
4541 **
4542 ** This function returns SQLITE_OK if the error code and error message are
4543 ** successfully set, SQLITE_NOMEM if an OOM occurs, and SQLITE_MISUSE if
4544 ** the database handle is NULL or invalid.
4545 **
4546 ** The error code and message set by this routine remains in effect until
4547 ** they are changed, either by another call to this routine or until they are
4548 ** changed to by SQLite itself to reflect the result of some subsquent
4549 ** API call.
4550 **
4551 ** This function is intended for use by SQLite extensions or wrappers. The
4552 ** idea is that an extension or wrapper can use this routine to set error
4553 ** messages and error codes and thus behave more like a core SQLite
4554 ** feature from the point of view of an application.
4555 */
4556 SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zErrMsg);
4557
4558 /*
4559 ** CAPI3REF: Prepared Statement Object
4560 ** KEYWORDS: {prepared statement} {prepared statements}
4561 **
4562 ** An instance of this object represents a single SQL statement that
@@ -12662,10 +12692,19 @@
12692 ** CAPI3REF: Apply A Changeset To A Database
12693 **
12694 ** Apply a changeset or patchset to a database. These functions attempt to
12695 ** update the "main" database attached to handle db with the changes found in
12696 ** the changeset passed via the second and third arguments.
12697 **
12698 ** All changes made by these functions are enclosed in a savepoint transaction.
12699 ** If any other error (aside from a constraint failure when attempting to
12700 ** write to the target database) occurs, then the savepoint transaction is
12701 ** rolled back, restoring the target database to its original state, and an
12702 ** SQLite error code returned. Additionally, starting with version 3.51.0,
12703 ** an error code and error message that may be accessed using the
12704 ** [sqlite3_errcode()] and [sqlite3_errmsg()] APIs are left in the database
12705 ** handle.
12706 **
12707 ** The fourth argument (xFilter) passed to these functions is the "filter
12708 ** callback". This may be passed NULL, in which case all changes in the
12709 ** changeset are applied to the database. For sqlite3changeset_apply() and
12710 ** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
@@ -12800,16 +12839,10 @@
12839 ** It is safe to execute SQL statements, including those that write to the
12840 ** table that the callback related to, from within the xConflict callback.
12841 ** This can be used to further customize the application's conflict
12842 ** resolution strategy.
12843 **
 
 
 
 
 
 
12844 ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
12845 ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
12846 ** may set (*ppRebase) to point to a "rebase" that may be used with the
12847 ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
12848 ** is set to the size of the buffer in bytes. It is the responsibility of the
@@ -18155,11 +18188,11 @@
18188 struct sqlite3InitInfo { /* Information used during initialization */
18189 Pgno newTnum; /* Rootpage of table being initialized */
18190 u8 iDb; /* Which db file is being initialized */
18191 u8 busy; /* TRUE if currently initializing */
18192 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
18193 unsigned imposterTable : 2; /* Building an imposter table */
18194 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
18195 const char **azInit; /* "type", "name", and "tbl_name" columns */
18196 } init;
18197 int nVdbeActive; /* Number of VDBEs currently running */
18198 int nVdbeRead; /* Number of active VDBEs that read or write */
@@ -18948,10 +18981,11 @@
18981 #define TF_Shadow 0x00001000 /* True for a shadow table */
18982 #define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
18983 #define TF_Ephemeral 0x00004000 /* An ephemeral table */
18984 #define TF_Eponymous 0x00008000 /* An eponymous virtual table */
18985 #define TF_Strict 0x00010000 /* STRICT mode */
18986 #define TF_Imposter 0x00020000 /* An imposter table */
18987
18988 /*
18989 ** Allowed values for Table.eTabType
18990 */
18991 #define TABTYP_NORM 0 /* Ordinary table */
@@ -25009,10 +25043,14 @@
25043 if( getDigits(zDate, "20b:20e", &nHr, &nMn)!=2 ){
25044 return 1;
25045 }
25046 zDate += 5;
25047 p->tz = sgn*(nMn + nHr*60);
25048 if( p->tz==0 ){ /* Forum post 2025-09-17T10:12:14z */
25049 p->isLocal = 0;
25050 p->isUtc = 1;
25051 }
25052 zulu_time:
25053 while( sqlite3Isspace(*zDate) ){ zDate++; }
25054 return *zDate!=0;
25055 }
25056
@@ -38168,11 +38206,11 @@
38206 static int kvstorageDelete(const char*, const char *zKey);
38207 static int kvstorageRead(const char*, const char *zKey, char *zBuf, int nBuf);
38208 #define KVSTORAGE_KEY_SZ 32
38209
38210 /* Expand the key name with an appropriate prefix and put the result
38211 ** in zKeyOut[]. The zKeyOut[] buffer is assumed to hold at least
38212 ** KVSTORAGE_KEY_SZ bytes.
38213 */
38214 static void kvstorageMakeKey(
38215 const char *zClass,
38216 const char *zKeyIn,
@@ -38227,14 +38265,16 @@
38265 ** enough to hold it all. The value put into zBuf must always be zero
38266 ** terminated, even if it gets truncated because nBuf is not large enough.
38267 **
38268 ** Return the total number of bytes in the data, without truncation, and
38269 ** not counting the final zero terminator. Return -1 if the key does
38270 ** not exist or its key cannot be read.
38271 **
38272 ** If nBuf<=0 then this routine simply returns the size of the data
38273 ** without actually reading it. Similarly, if nBuf==1 then it
38274 ** zero-terminates zBuf at zBuf[0] and returns the size of the data
38275 ** without reading it.
38276 */
38277 static int kvstorageRead(
38278 const char *zClass,
38279 const char *zKey,
38280 char *zBuf,
@@ -38279,15 +38319,13 @@
38319 /*
38320 ** An internal level of indirection which enables us to replace the
38321 ** kvvfs i/o methods with JavaScript implementations in WASM builds.
38322 ** Maintenance reminder: if this struct changes in any way, the JSON
38323 ** rendering of its structure must be updated in
38324 ** sqlite3-wasm.c:sqlite3__wasm_enum_json(). There are no binary
38325 ** compatibility concerns, so it does not need an iVersion
38326 ** member.
 
 
38327 */
38328 typedef struct sqlite3_kvvfs_methods sqlite3_kvvfs_methods;
38329 struct sqlite3_kvvfs_methods {
38330 int (*xRead)(const char *zClass, const char *zKey, char *zBuf, int nBuf);
38331 int (*xWrite)(const char *zClass, const char *zKey, const char *zData);
@@ -38300,12 +38338,12 @@
38338 ** for JavaScript-side implementations in WASM builds. In such builds
38339 ** it cannot be const, but in native builds it should be so that
38340 ** the compiler can hopefully optimize this level of indirection out.
38341 ** That said, kvvfs is intended primarily for use in WASM builds.
38342 **
38343 ** This is not explicitly flagged as static because the amalgamation
38344 ** build will tag it with SQLITE_PRIVATE.
38345 */
38346 #ifndef SQLITE_WASM
38347 const
38348 #endif
38349 SQLITE_PRIVATE sqlite3_kvvfs_methods sqlite3KvvfsMethods = {
@@ -39736,13 +39774,12 @@
39774 return fd;
39775 }
39776
39777 /*
39778 ** Helper functions to obtain and relinquish the global mutex. The
39779 ** global mutex is used to protect the unixInodeInfo objects used by
39780 ** this file, all of which may be shared by multiple threads.
 
39781 **
39782 ** Function unixMutexHeld() is used to assert() that the global mutex
39783 ** is held when required. This function is only used as part of assert()
39784 ** statements. e.g.
39785 **
@@ -39940,10 +39977,11 @@
39977 /*
39978 ** All unique filenames are held on a linked list headed by this
39979 ** variable:
39980 */
39981 static struct vxworksFileId *vxworksFileList = 0;
39982 static sqlite3_mutex *vxworksMutex = 0;
39983
39984 /*
39985 ** Simplify a filename into its canonical form
39986 ** by making the following changes:
39987 **
@@ -40005,47 +40043,47 @@
40043
40044 /* Search for an existing entry that matching the canonical name.
40045 ** If found, increment the reference count and return a pointer to
40046 ** the existing file ID.
40047 */
40048 sqlite3_mutex_enter(vxworksMutex);
40049 for(pCandidate=vxworksFileList; pCandidate; pCandidate=pCandidate->pNext){
40050 if( pCandidate->nName==n
40051 && memcmp(pCandidate->zCanonicalName, pNew->zCanonicalName, n)==0
40052 ){
40053 sqlite3_free(pNew);
40054 pCandidate->nRef++;
40055 sqlite3_mutex_leave(vxworksMutex);
40056 return pCandidate;
40057 }
40058 }
40059
40060 /* No match was found. We will make a new file ID */
40061 pNew->nRef = 1;
40062 pNew->nName = n;
40063 pNew->pNext = vxworksFileList;
40064 vxworksFileList = pNew;
40065 sqlite3_mutex_leave(vxworksMutex);
40066 return pNew;
40067 }
40068
40069 /*
40070 ** Decrement the reference count on a vxworksFileId object. Free
40071 ** the object when the reference count reaches zero.
40072 */
40073 static void vxworksReleaseFileId(struct vxworksFileId *pId){
40074 sqlite3_mutex_enter(vxworksMutex);
40075 assert( pId->nRef>0 );
40076 pId->nRef--;
40077 if( pId->nRef==0 ){
40078 struct vxworksFileId **pp;
40079 for(pp=&vxworksFileList; *pp && *pp!=pId; pp = &((*pp)->pNext)){}
40080 assert( *pp==pId );
40081 *pp = pId->pNext;
40082 sqlite3_free(pId);
40083 }
40084 sqlite3_mutex_leave(vxworksMutex);
40085 }
40086 #endif /* OS_VXWORKS */
40087 /*************** End of Unique File ID Utility Used By VxWorks ****************
40088 ******************************************************************************/
40089
@@ -44958,14 +44996,21 @@
44996 #endif
44997
44998 storeLastErrno(pNew, 0);
44999 #if OS_VXWORKS
45000 if( rc!=SQLITE_OK ){
45001 if( h>=0 ){
45002 robust_close(pNew, h, __LINE__);
45003 h = -1;
45004 }
45005 if( pNew->ctrlFlags & UNIXFILE_DELETE ){
45006 osUnlink(zFilename);
45007 }
45008 if( pNew->pId ){
45009 vxworksReleaseFileId(pNew->pId);
45010 pNew->pId = 0;
45011 }
45012 }
45013 #endif
45014 if( rc!=SQLITE_OK ){
45015 if( h>=0 ) robust_close(pNew, h, __LINE__);
45016 }else{
@@ -45005,10 +45050,13 @@
45050 struct stat buf;
45051 const char *zDir = sqlite3_temp_directory;
45052
45053 while(1){
45054 if( zDir!=0
45055 #if OS_VXWORKS
45056 && zDir[0]=='/'
45057 #endif
45058 && osStat(zDir, &buf)==0
45059 && S_ISDIR(buf.st_mode)
45060 && osAccess(zDir, 03)==0
45061 ){
45062 return zDir;
@@ -45318,10 +45366,16 @@
45366 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
45367 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
45368 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL
45369 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
45370 );
45371
45372 #if OS_VXWORKS
45373 /* The file-ID mechanism used in Vxworks requires that all pathnames
45374 ** provided to unixOpen must be absolute pathnames. */
45375 if( zPath!=0 && zPath[0]!='/' ){ return SQLITE_CANTOPEN; }
45376 #endif
45377
45378 /* Detect a pid change and reset the PRNG. There is a race condition
45379 ** here such that two or more threads all trying to open databases at
45380 ** the same instant might all reset the PRNG. But multiple resets
45381 ** are harmless.
@@ -45519,12 +45573,15 @@
45573 goto open_finished;
45574 }
45575 }
45576 #endif
45577
45578 assert( zPath==0
45579 || zPath[0]=='/'
45580 || eType==SQLITE_OPEN_SUPER_JOURNAL
45581 || eType==SQLITE_OPEN_MAIN_JOURNAL
45582 || eType==SQLITE_OPEN_TEMP_JOURNAL
45583 );
45584 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
45585
45586 open_finished:
45587 if( rc!=SQLITE_OK ){
@@ -47249,10 +47306,13 @@
47306 }
47307 #ifdef SQLITE_OS_KV_OPTIONAL
47308 sqlite3KvvfsInit();
47309 #endif
47310 unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
47311 #if OS_VXWORKS
47312 vxworksMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS2);
47313 #endif
47314
47315 #ifndef SQLITE_OMIT_WAL
47316 /* Validate lock assumptions */
47317 assert( SQLITE_SHM_NLOCK==8 ); /* Number of available locks */
47318 assert( UNIX_SHM_BASE==120 ); /* Start of locking area */
@@ -47283,10 +47343,13 @@
47343 ** to release dynamically allocated objects. But not on unix.
47344 ** This routine is a no-op for unix.
47345 */
47346 SQLITE_API int sqlite3_os_end(void){
47347 unixBigLock = 0;
47348 #if OS_VXWORKS
47349 vxworksMutex = 0;
47350 #endif
47351 return SQLITE_OK;
47352 }
47353
47354 #endif /* SQLITE_OS_UNIX */
47355
@@ -62006,18 +62069,31 @@
62069 SQLITE_PRIVATE void sqlite3PagerSetFlags(
62070 Pager *pPager, /* The pager to set safety level for */
62071 unsigned pgFlags /* Various flags */
62072 ){
62073 unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK;
62074 if( pPager->tempFile || level==PAGER_SYNCHRONOUS_OFF ){
62075 pPager->noSync = 1;
62076 pPager->fullSync = 0;
62077 pPager->extraSync = 0;
62078 }else{
62079 pPager->noSync = 0;
62080 pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
62081
62082 /* Set Pager.extraSync if "PRAGMA synchronous=EXTRA" is requested, or
62083 ** if the file-system supports F2FS style atomic writes. If this flag
62084 ** is set, SQLite syncs the directory to disk immediately after deleting
62085 ** a journal file in "PRAGMA journal_mode=DELETE" mode. */
62086 if( level==PAGER_SYNCHRONOUS_EXTRA
62087 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
62088 || (sqlite3OsDeviceCharacteristics(pPager->fd) & SQLITE_IOCAP_BATCH_ATOMIC)
62089 #endif
62090 ){
62091 pPager->extraSync = 1;
62092 }else{
62093 pPager->extraSync = 0;
62094 }
62095 }
62096 if( pPager->noSync ){
62097 pPager->syncFlags = 0;
62098 }else if( pgFlags & PAGER_FULLFSYNC ){
62099 pPager->syncFlags = SQLITE_SYNC_FULL;
@@ -113289,13 +113365,12 @@
113365 }
113366 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, pFree1);
113367 if( addrIsNull==0 ){
113368 /*
113369 ** If the right operand contains a subquery and the left operand does not
113370 ** and the left operand might be NULL, then do an IsNull check
113371 ** check on the left operand before computing the right operand.
 
113372 */
113373 if( ExprHasProperty(pExpr->pRight, EP_Subquery)
113374 && sqlite3ExprCanBeNull(pExpr->pLeft)
113375 ){
113376 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, r1);
@@ -115660,10 +115735,82 @@
115735 }
115736 }
115737 return 0;
115738 }
115739
115740 /*
115741 ** Generate code that evaluates an AND or OR operator leaving a
115742 ** boolean result in a register. pExpr is the AND/OR expression.
115743 ** Store the result in the "target" register. Use short-circuit
115744 ** evaluation to avoid computing both operands, if possible.
115745 **
115746 ** The code generated might require the use of a temporary register.
115747 ** If it does, then write the number of that temporary register
115748 ** into *pTmpReg. If not, leave *pTmpReg unchanged.
115749 */
115750 static SQLITE_NOINLINE int exprCodeTargetAndOr(
115751 Parse *pParse, /* Parsing context */
115752 Expr *pExpr, /* AND or OR expression to be coded */
115753 int target, /* Put result in this register, guaranteed */
115754 int *pTmpReg /* Write a temporary register here */
115755 ){
115756 int op; /* The opcode. TK_AND or TK_OR */
115757 int skipOp; /* Opcode for the branch that skips one operand */
115758 int addrSkip; /* Branch instruction that skips one of the operands */
115759 int regSS = 0; /* Register holding computed operand when other omitted */
115760 int r1, r2; /* Registers for left and right operands, respectively */
115761 Expr *pAlt; /* Alternative, simplified expression */
115762 Vdbe *v; /* statement being coded */
115763
115764 assert( pExpr!=0 );
115765 op = pExpr->op;
115766 assert( op==TK_AND || op==TK_OR );
115767 assert( TK_AND==OP_And ); testcase( op==TK_AND );
115768 assert( TK_OR==OP_Or ); testcase( op==TK_OR );
115769 pAlt = sqlite3ExprSimplifiedAndOr(pExpr);
115770 if( pAlt!=pExpr ){
115771 return sqlite3ExprCodeTarget(pParse, pAlt, target);
115772 }
115773 assert( pParse->pVdbe!=0 );
115774 v = pParse->pVdbe;
115775 skipOp = op==TK_AND ? OP_IfNot : OP_If;
115776 if( exprEvalRhsFirst(pExpr) ){
115777 /* Compute the right operand first. Skip the computation of the left
115778 ** operand if the right operand fully determines the result */
115779 r2 = regSS = sqlite3ExprCodeTarget(pParse, pExpr->pRight, target);
115780 addrSkip = sqlite3VdbeAddOp1(v, skipOp, r2);
115781 VdbeComment((v, "skip left operand"));
115782 VdbeCoverage(v);
115783 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, pTmpReg);
115784 }else{
115785 /* Compute the left operand first */
115786 r1 = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
115787 if( ExprHasProperty(pExpr->pRight, EP_Subquery) ){
115788 /* Skip over the computation of the right operand if the right
115789 ** operand is a subquery and the left operand completely determines
115790 ** the result */
115791 regSS = r1;
115792 addrSkip = sqlite3VdbeAddOp1(v, skipOp, r1);
115793 VdbeComment((v, "skip right operand"));
115794 VdbeCoverage(v);
115795 }else{
115796 addrSkip = regSS = 0;
115797 }
115798 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, pTmpReg);
115799 }
115800 sqlite3VdbeAddOp3(v, op, r2, r1, target);
115801 testcase( (*pTmpReg)==0 );
115802 if( addrSkip ){
115803 sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
115804 sqlite3VdbeJumpHere(v, addrSkip);
115805 sqlite3VdbeAddOp3(v, OP_Or, regSS, regSS, target);
115806 VdbeComment((v, "short-circut value"));
115807 }
115808 return target;
115809 }
115810
115811
115812
115813 /*
115814 ** Generate code into the current Vdbe to evaluate the given
115815 ** expression. Attempt to store the results in register "target".
115816 ** Return the register where results are stored.
@@ -115948,16 +116095,18 @@
116095 sqlite3VdbeAddOp2(v, OP_Null, 0, inReg);
116096 }
116097 }
116098 testcase( regFree1==0 );
116099 testcase( regFree2==0 );
 
116100 }
116101 break;
116102 }
116103 case TK_AND:
116104 case TK_OR: {
116105 inReg = exprCodeTargetAndOr(pParse, pExpr, target, &regFree1);
116106 break;
116107 }
116108 case TK_PLUS:
116109 case TK_STAR:
116110 case TK_MINUS:
116111 case TK_REM:
116112 case TK_BITAND:
@@ -115965,12 +116114,10 @@
116114 case TK_SLASH:
116115 case TK_LSHIFT:
116116 case TK_RSHIFT:
116117 case TK_CONCAT: {
116118 int addrIsNull;
 
 
116119 assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
116120 assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
116121 assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
116122 assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND );
116123 assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
@@ -125050,10 +125197,13 @@
125197 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
125198 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
125199 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
125200 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
125201 sqlite3VdbeAddOp0(v, OP_Close);
125202 }else if( db->init.imposterTable ){
125203 pTable->tabFlags |= TF_Imposter;
125204 if( db->init.imposterTable>=2 ) pTable->tabFlags |= TF_Readonly;
125205 }
125206
125207 /* Normal (non-error) return. */
125208 return;
125209
@@ -139432,10 +139582,12 @@
139582 /* Version 3.44.0 and later */
139583 void *(*get_clientdata)(sqlite3*,const char*);
139584 int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*));
139585 /* Version 3.50.0 and later */
139586 int (*setlk_timeout)(sqlite3*,int,int);
139587 /* Version 3.51.0 and later */
139588 int (*set_errmsg)(sqlite3*,int,const char*);
139589 };
139590
139591 /*
139592 ** This is the function signature used for all extension entry points. It
139593 ** is also defined in the file "loadext.c".
@@ -139767,10 +139919,12 @@
139919 /* Version 3.44.0 and later */
139920 #define sqlite3_get_clientdata sqlite3_api->get_clientdata
139921 #define sqlite3_set_clientdata sqlite3_api->set_clientdata
139922 /* Version 3.50.0 and later */
139923 #define sqlite3_setlk_timeout sqlite3_api->setlk_timeout
139924 /* Version 3.51.0 and later */
139925 #define sqlite3_set_errmsg sqlite3_api->set_errmsg
139926 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
139927
139928 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
139929 /* This case when the file really is being compiled as a loadable
139930 ** extension */
@@ -140290,11 +140444,13 @@
140444 sqlite3_stmt_explain,
140445 /* Version 3.44.0 and later */
140446 sqlite3_get_clientdata,
140447 sqlite3_set_clientdata,
140448 /* Version 3.50.0 and later */
140449 sqlite3_setlk_timeout,
140450 /* Version 3.51.0 and later */
140451 sqlite3_set_errmsg
140452 };
140453
140454 /* True if x is the directory separator character
140455 */
140456 #if SQLITE_OS_WIN
@@ -141751,10 +141907,26 @@
141907 addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
141908 VdbeCoverage(v);
141909 sqlite3VdbeAddOp0(v, OP_Halt);
141910 return addr;
141911 }
141912
141913 /*
141914 ** Should table pTab be skipped when doing an integrity_check?
141915 ** Return true or false.
141916 **
141917 ** If pObjTab is not null, the return true if pTab matches pObjTab.
141918 **
141919 ** If pObjTab is null, then return true only if pTab is an imposter table.
141920 */
141921 static int tableSkipIntegrityCheck(const Table *pTab, const Table *pObjTab){
141922 if( pObjTab ){
141923 return pTab!=pObjTab;
141924 }else{
141925 return (pTab->tabFlags & TF_Imposter)!=0;
141926 }
141927 }
141928
141929 /*
141930 ** Process a pragma statement.
141931 **
141932 ** Pragmas are of this form:
@@ -143097,11 +143269,11 @@
143269 pTbls = &db->aDb[i].pSchema->tblHash;
143270 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143271 Table *pTab = sqliteHashData(x); /* Current table */
143272 Index *pIdx; /* An index on pTab */
143273 int nIdx; /* Number of indexes on pTab */
143274 if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143275 if( HasRowid(pTab) ) cnt++;
143276 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
143277 }
143278 if( cnt==0 ) continue;
143279 if( pObjTab ) cnt++;
@@ -143110,11 +143282,11 @@
143282 cnt = 0;
143283 if( pObjTab ) aRoot[++cnt] = 0;
143284 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143285 Table *pTab = sqliteHashData(x);
143286 Index *pIdx;
143287 if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143288 if( HasRowid(pTab) ) aRoot[++cnt] = pTab->tnum;
143289 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
143290 aRoot[++cnt] = pIdx->tnum;
143291 }
143292 }
@@ -143141,11 +143313,11 @@
143313 sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
143314 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143315 int iTab = 0;
143316 Table *pTab = sqliteHashData(x);
143317 Index *pIdx;
143318 if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143319 if( HasRowid(pTab) ){
143320 iTab = cnt++;
143321 }else{
143322 iTab = cnt;
143323 for(pIdx=pTab->pIndex; ALWAYS(pIdx); pIdx=pIdx->pNext){
@@ -143177,11 +143349,11 @@
143349 int r1 = -1;
143350 int bStrict; /* True for a STRICT table */
143351 int r2; /* Previous key for WITHOUT ROWID tables */
143352 int mxCol; /* Maximum non-virtual column number */
143353
143354 if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143355 if( !IsOrdinaryTable(pTab) ) continue;
143356 if( isQuick || HasRowid(pTab) ){
143357 pPk = 0;
143358 r2 = 0;
143359 }else{
@@ -143501,11 +143673,11 @@
143673 */
143674 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
143675 Table *pTab = sqliteHashData(x);
143676 sqlite3_vtab *pVTab;
143677 int a1;
143678 if( tableSkipIntegrityCheck(pTab,pObjTab) ) continue;
143679 if( IsOrdinaryTable(pTab) ) continue;
143680 if( !IsVirtual(pTab) ) continue;
143681 if( pTab->nCol<=0 ){
143682 const char *zMod = pTab->u.vtab.azArg[0];
143683 if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
@@ -170516,10 +170688,14 @@
170688 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
170689 if( pLoop->u.vtab.isOrdered
170690 && ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY)
170691 ){
170692 obSat = obDone;
170693 }else{
170694 /* No further ORDER BY terms may be matched. So this call should
170695 ** return >=0, not -1. Clear isOrderDistinct to ensure it does so. */
170696 isOrderDistinct = 0;
170697 }
170698 break;
170699 }
170700 iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
170701
@@ -171419,22 +171595,18 @@
171595 pFrom = aTo;
171596 aTo = aFrom;
171597 aFrom = pFrom;
171598 nFrom = nTo;
171599 }
171600 assert( nFrom==0 || nFrom==1 );
171601
171602 if( nFrom==0 ){
171603 sqlite3ErrorMsg(pParse, "no query solution");
171604 sqlite3StackFreeNN(pParse->db, pSpace);
171605 return SQLITE_ERROR;
171606 }
 
 
171607 pFrom = aFrom;
 
 
 
171608 assert( pWInfo->nLevel==nLoop );
171609 /* Load the lowest cost path into pWInfo */
171610 for(iLoop=0; iLoop<nLoop; iLoop++){
171611 WhereLevel *pLevel = pWInfo->a + iLoop;
171612 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -171563,11 +171735,14 @@
171735 int once = 0;
171736 #endif
171737 for(i=0; i<pWInfo->nLevel; i++){
171738 WhereLoop *p = pWInfo->a[i].pWLoop;
171739 if( p==0 ) break;
171740 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
171741 /* Treat a vtab scan as similar to a full-table scan */
171742 break;
171743 }
171744 if( (p->wsFlags & (WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0 ){
171745 u8 iTab = p->iTab;
171746 WhereLoop *pLoop;
171747 for(pLoop=pWInfo->pLoops; pLoop; pLoop=pLoop->pNextLoop){
171748 if( pLoop->iTab!=iTab ) continue;
@@ -175676,11 +175851,11 @@
175851 ** RETURN_ROW
175852 **
175853 **
175854 ** ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
175855 **
175856 ** ... loop started by sqlite3WhereBegin() ...
175857 ** if( new partition ){
175858 ** Gosub flush
175859 ** }
175860 ** Insert new row into eph table.
175861 ** if( first row of partition ){
@@ -176194,10 +176369,16 @@
176369 addrStart = sqlite3VdbeCurrentAddr(v);
176370 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regStart, 1);
176371 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
176372 }else{
176373 assert( pMWin->eEnd==TK_FOLLOWING );
176374 /* assert( regStart>=0 );
176375 ** regEnd = regEnd - regStart;
176376 ** regStart = 0; */
176377 sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regEnd);
176378 sqlite3VdbeAddOp2(v, OP_Integer, 0, regStart);
176379
176380 addrStart = sqlite3VdbeCurrentAddr(v);
176381 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 1);
176382 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
176383 }
176384 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
@@ -186322,10 +186503,33 @@
186503 }
186504 }
186505 sqlite3_mutex_leave(db->mutex);
186506 return z;
186507 }
186508
186509 /*
186510 ** Set the error code and error message associated with the database handle.
186511 **
186512 ** This routine is intended to be called by outside extensions (ex: the
186513 ** Session extension). Internal logic should invoke sqlite3Error() or
186514 ** sqlite3ErrorWithMsg() directly.
186515 */
186516 SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zMsg){
186517 int rc = SQLITE_OK;
186518 if( !sqlite3SafetyCheckSickOrOk(db) ){
186519 return SQLITE_MISUSE_BKPT;
186520 }
186521 sqlite3_mutex_enter(db->mutex);
186522 if( zMsg ){
186523 sqlite3ErrorWithMsg(db, errcode, "%s", zMsg);
186524 }else{
186525 sqlite3Error(db, errcode);
186526 }
186527 rc = sqlite3ApiExit(db, rc);
186528 sqlite3_mutex_leave(db->mutex);
186529 return rc;
186530 }
186531
186532 /*
186533 ** Return the byte offset of the most recent error
186534 */
186535 SQLITE_API int sqlite3_error_offset(sqlite3 *db){
@@ -188147,17 +188351,19 @@
188351 case SQLITE_TESTCTRL_ISINIT: {
188352 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
188353 break;
188354 }
188355
188356 /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, mode, tnum);
188357 **
188358 ** This test control is used to create imposter tables. "db" is a pointer
188359 ** to the database connection. dbName is the database name (ex: "main" or
188360 ** "temp") which will receive the imposter. "mode" turns imposter mode on
188361 ** or off. mode==0 means imposter mode is off. mode==1 means imposter mode
188362 ** is on. mode==2 means imposter mode is on but results in an imposter
188363 ** table that is read-only unless writable_schema is on. "tnum" is the
188364 ** root page of the b-tree to which the imposter table should connect.
188365 **
188366 ** Enable imposter mode only when the schema has already been parsed. Then
188367 ** run a single CREATE TABLE statement to construct the imposter table in
188368 ** the parsed schema. Then turn imposter mode back off again.
188369 **
@@ -228653,11 +228859,11 @@
228859 typedef struct DbpageCursor DbpageCursor;
228860
228861 struct DbpageCursor {
228862 sqlite3_vtab_cursor base; /* Base class. Must be first */
228863 Pgno pgno; /* Current page number */
228864 Pgno mxPgno; /* Last page to visit on this scan */
228865 Pager *pPager; /* Pager being read/written */
228866 DbPage *pPage1; /* Page 1 of the database */
228867 int iDb; /* Index of database to analyze */
228868 int szPage; /* Size of each page in bytes */
228869 };
@@ -231924,10 +232130,23 @@
232130 assert( (a - p->aRecord)==p->nRecord );
232131 }
232132
232133 return rc;
232134 }
232135
232136 static int sessionPrepare(
232137 sqlite3 *db,
232138 sqlite3_stmt **pp,
232139 char **pzErrmsg,
232140 const char *zSql
232141 ){
232142 int rc = sqlite3_prepare_v2(db, zSql, -1, pp, 0);
232143 if( pzErrmsg && rc!=SQLITE_OK ){
232144 *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
232145 }
232146 return rc;
232147 }
232148
232149 /*
232150 ** Formulate and prepare a SELECT statement to retrieve a row from table
232151 ** zTab in database zDb based on its primary key. i.e.
232152 **
@@ -231946,16 +232165,16 @@
232165 const char *zTab, /* Table name */
232166 int bRowid,
232167 int nCol, /* Number of columns in table */
232168 const char **azCol, /* Names of table columns */
232169 u8 *abPK, /* PRIMARY KEY array */
232170 sqlite3_stmt **ppStmt, /* OUT: Prepared SELECT statement */
232171 char **pzErrmsg /* OUT: Error message */
232172 ){
232173 int rc = SQLITE_OK;
232174 char *zSql = 0;
232175 const char *zSep = "";
 
232176 int i;
232177
232178 SessionBuffer cols = {0, 0, 0};
232179 SessionBuffer nooptest = {0, 0, 0};
232180 SessionBuffer pkfield = {0, 0, 0};
@@ -232031,11 +232250,11 @@
232250 nSql = buf.nBuf;
232251 }
232252 #endif
232253
232254 if( rc==SQLITE_OK ){
232255 rc = sessionPrepare(db, ppStmt, pzErrmsg, zSql);
232256 }
232257 sqlite3_free(zSql);
232258 sqlite3_free(nooptest.aBuf);
232259 sqlite3_free(pkfield.aBuf);
232260 sqlite3_free(pkvar.aBuf);
@@ -232195,11 +232414,11 @@
232414 sessionAppendTableHdr(&buf, bPatchset, pTab, &rc);
232415
232416 /* Build and compile a statement to execute: */
232417 if( rc==SQLITE_OK ){
232418 rc = sessionSelectStmt(db, 0, pSession->zDb,
232419 zName, pTab->bRowid, pTab->nCol, pTab->azCol, pTab->abPK, &pSel, 0
232420 );
232421 }
232422
232423 nNoop = buf.nBuf;
232424 for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
@@ -233404,10 +233623,11 @@
233623 SessionBuffer rebase; /* Rebase information (if any) here */
233624 u8 bRebaseStarted; /* If table header is already in rebase */
233625 u8 bRebase; /* True to collect rebase information */
233626 u8 bIgnoreNoop; /* True to ignore no-op conflicts */
233627 int bRowid;
233628 char *zErr; /* Error message, if any */
233629 };
233630
233631 /* Number of prepared UPDATE statements to cache. */
233632 #define SESSION_UPDATE_CACHE_SZ 12
233633
@@ -233629,11 +233849,11 @@
233849 }
233850 sessionAppendStr(&buf, ")", &rc);
233851 }
233852
233853 if( rc==SQLITE_OK ){
233854 rc = sessionPrepare(db, &p->pDelete, &p->zErr, (char*)buf.aBuf);
233855 }
233856 sqlite3_free(buf.aBuf);
233857
233858 return rc;
233859 }
@@ -233656,11 +233876,11 @@
233876 const char *zTab, /* Table name */
233877 SessionApplyCtx *p /* Session changeset-apply context */
233878 ){
233879 /* TODO */
233880 return sessionSelectStmt(db, p->bIgnoreNoop,
233881 "main", zTab, p->bRowid, p->nCol, p->azCol, p->abPK, &p->pSelect, &p->zErr
233882 );
233883 }
233884
233885 /*
233886 ** Formulate and prepare an INSERT statement to add a record to table zTab.
@@ -233693,37 +233913,33 @@
233913 sessionAppendStr(&buf, ", ?", &rc);
233914 }
233915 sessionAppendStr(&buf, ")", &rc);
233916
233917 if( rc==SQLITE_OK ){
233918 rc = sessionPrepare(db, &p->pInsert, &p->zErr, (char*)buf.aBuf);
233919 }
233920 sqlite3_free(buf.aBuf);
233921 return rc;
233922 }
233923
 
 
 
 
233924 /*
233925 ** Prepare statements for applying changes to the sqlite_stat1 table.
233926 ** These are similar to those created by sessionSelectRow(),
233927 ** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for
233928 ** other tables.
233929 */
233930 static int sessionStat1Sql(sqlite3 *db, SessionApplyCtx *p){
233931 int rc = sessionSelectRow(db, "sqlite_stat1", p);
233932 if( rc==SQLITE_OK ){
233933 rc = sessionPrepare(db, &p->pInsert, 0,
233934 "INSERT INTO main.sqlite_stat1 VALUES(?1, "
233935 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
233936 "?3)"
233937 );
233938 }
233939 if( rc==SQLITE_OK ){
233940 rc = sessionPrepare(db, &p->pDelete, 0,
233941 "DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS "
233942 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
233943 "AND (?4 OR stat IS ?3)"
233944 );
233945 }
@@ -234502,10 +234718,15 @@
234718 if( (flags & SQLITE_CHANGESETAPPLY_FKNOACTION) && savedFlag==0 ){
234719 assert( db->flags & SQLITE_FkNoAction );
234720 db->flags &= ~((u64)SQLITE_FkNoAction);
234721 db->aDb[0].pSchema->schema_cookie -= 32;
234722 }
234723
234724 assert( rc!=SQLITE_OK || sApply.zErr==0 );
234725 sqlite3_set_errmsg(db, rc, sApply.zErr);
234726 sqlite3_free(sApply.zErr);
234727
234728 sqlite3_mutex_leave(sqlite3_db_mutex(db));
234729 return rc;
234730 }
234731
234732 /*
@@ -237466,11 +237687,11 @@
237687 ** ){
237688 ** // The document with rowid iRowid matches the expression!
237689 ** i64 iRowid = sqlite3Fts5ExprRowid(pExpr);
237690 ** }
237691 */
237692 static int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, i64, int bDesc);
237693 static int sqlite3Fts5ExprNext(Fts5Expr*, i64 iMax);
237694 static int sqlite3Fts5ExprEof(Fts5Expr*);
237695 static i64 sqlite3Fts5ExprRowid(Fts5Expr*);
237696
237697 static void sqlite3Fts5ExprFree(Fts5Expr*);
@@ -243035,11 +243256,17 @@
243256 ** equal to iFirst.
243257 **
243258 ** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
243259 ** is not considered an error if the query does not match any documents.
243260 */
243261 static int sqlite3Fts5ExprFirst(
243262 Fts5Expr *p,
243263 Fts5Index *pIdx,
243264 i64 iFirst,
243265 i64 iLast,
243266 int bDesc
243267 ){
243268 Fts5ExprNode *pRoot = p->pRoot;
243269 int rc; /* Return code */
243270
243271 p->pIndex = pIdx;
243272 p->bDesc = bDesc;
@@ -243056,10 +243283,13 @@
243283
243284 /* If the iterator is not at a real match, skip forward until it is. */
243285 while( pRoot->bNomatch && rc==SQLITE_OK ){
243286 assert( pRoot->bEof==0 );
243287 rc = fts5ExprNodeNext(p, pRoot, 0, 0);
243288 }
243289 if( fts5RowidCmp(p, pRoot->iRowid, iLast)>0 ){
243290 pRoot->bEof = 1;
243291 }
243292 return rc;
243293 }
243294
243295 /*
@@ -255404,10 +255634,21 @@
255634 {
255635 pIdxInfo->idxFlags |= SQLITE_INDEX_SCAN_UNIQUE;
255636 }
255637 #endif
255638 }
255639
255640 static void fts5SetEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
255641 #if SQLITE_VERSION_NUMBER>=3008002
255642 #ifndef SQLITE_CORE
255643 if( sqlite3_libversion_number()>=3008002 )
255644 #endif
255645 {
255646 pIdxInfo->estimatedRows = nRow;
255647 }
255648 #endif
255649 }
255650
255651 static int fts5UsePatternMatch(
255652 Fts5Config *pConfig,
255653 struct sqlite3_index_constraint *p
255654 ){
@@ -255540,11 +255781,11 @@
255781 bSeenRank = 1;
255782 }else{
255783 nSeenMatch++;
255784 idxStr[iIdxStr++] = 'M';
255785 sqlite3_snprintf(6, &idxStr[iIdxStr], "%d", iCol);
255786 iIdxStr += (int)strlen(&idxStr[iIdxStr]);
255787 assert( idxStr[iIdxStr]=='\0' );
255788 }
255789 pInfo->aConstraintUsage[i].argvIndex = ++iCons;
255790 pInfo->aConstraintUsage[i].omit = 1;
255791 }
@@ -255559,10 +255800,11 @@
255800 nSeenMatch++;
255801 }else if( bSeenEq==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol<0 ){
255802 idxStr[iIdxStr++] = '=';
255803 bSeenEq = 1;
255804 pInfo->aConstraintUsage[i].argvIndex = ++iCons;
255805 pInfo->aConstraintUsage[i].omit = 1;
255806 }
255807 }
255808 }
255809
255810 if( bSeenEq==0 ){
@@ -255606,21 +255848,25 @@
255848 }
255849 }
255850
255851 /* Calculate the estimated cost based on the flags set in idxFlags. */
255852 if( bSeenEq ){
255853 pInfo->estimatedCost = nSeenMatch ? 1000.0 : 25.0;
255854 fts5SetUniqueFlag(pInfo);
255855 fts5SetEstimatedRows(pInfo, 1);
 
 
 
255856 }else{
255857 if( bSeenLt && bSeenGt ){
255858 pInfo->estimatedCost = nSeenMatch ? 5000.0 : 750000.0;
255859 }else if( bSeenLt || bSeenGt ){
255860 pInfo->estimatedCost = nSeenMatch ? 7500.0 : 2250000.0;
255861 }else{
255862 pInfo->estimatedCost = nSeenMatch ? 10000.0 : 3000000.0;
255863 }
255864 for(i=1; i<nSeenMatch; i++){
255865 pInfo->estimatedCost *= 0.4;
255866 }
255867 fts5SetEstimatedRows(pInfo, (i64)(pInfo->estimatedCost / 4.0));
255868 }
255869
255870 pInfo->idxNum = idxFlags;
255871 return SQLITE_OK;
255872 }
@@ -255815,11 +256061,13 @@
256061 if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_RESEEK) ){
256062 Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
256063 int bDesc = pCsr->bDesc;
256064 i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr);
256065
256066 rc = sqlite3Fts5ExprFirst(
256067 pCsr->pExpr, pTab->p.pIndex, iRowid, pCsr->iLastRowid, bDesc
256068 );
256069 if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){
256070 *pbSkip = 1;
256071 }
256072
256073 CsrFlagClear(pCsr, FTS5CSR_REQUIRE_RESEEK);
@@ -255987,11 +256235,13 @@
256235 }
256236
256237 static int fts5CursorFirst(Fts5FullTable *pTab, Fts5Cursor *pCsr, int bDesc){
256238 int rc;
256239 Fts5Expr *pExpr = pCsr->pExpr;
256240 rc = sqlite3Fts5ExprFirst(
256241 pExpr, pTab->p.pIndex, pCsr->iFirstRowid, pCsr->iLastRowid, bDesc
256242 );
256243 if( sqlite3Fts5ExprEof(pExpr) ){
256244 CsrFlagSet(pCsr, FTS5CSR_EOF);
256245 }
256246 fts5CsrNewrow(pCsr);
256247 return rc;
@@ -258472,11 +258722,11 @@
258722 int nArg, /* Number of args */
258723 sqlite3_value **apUnused /* Function arguments */
258724 ){
258725 assert( nArg==0 );
258726 UNUSED_PARAM2(nArg, apUnused);
258727 sqlite3_result_text(pCtx, "fts5: 2025-09-24 19:10:58 821cc0e421bc14a68ebaee507e38a900e0c84ff6ba7ee95bf796cad387755232", -1, SQLITE_TRANSIENT);
258728 }
258729
258730 /*
258731 ** Implementation of fts5_locale(LOCALE, TEXT) function.
258732 **
258733
+39 -8
--- 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.51.0"
150150
#define SQLITE_VERSION_NUMBER 3051000
151
-#define SQLITE_SOURCE_ID "2025-09-10 14:28:07 61d9e204c5801a94811fdb0afe2c04f9814e08f2e141afa6dbda0fa45f026f70"
151
+#define SQLITE_SOURCE_ID "2025-09-24 19:10:58 821cc0e421bc14a68ebaee507e38a900e0c84ff6ba7ee95bf796cad387755232"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2025-09-10T14:28:07.926Z"
154
+#define SQLITE_SCM_DATETIME "2025-09-24T19:10:58.215Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -4204,10 +4204,38 @@
42044204
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
42054205
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
42064206
SQLITE_API const char *sqlite3_errstr(int);
42074207
SQLITE_API int sqlite3_error_offset(sqlite3 *db);
42084208
4209
+/*
4210
+** CAPI3REF: Set Error Codes And Message
4211
+** METHOD: sqlite3
4212
+**
4213
+** Set the error code of the database handle passed as the first argument
4214
+** to errcode, and the error message to a copy of nul-terminated string
4215
+** zErrMsg. If zErrMsg is passed NULL, then the error message is set to
4216
+** the default message associated with the supplied error code. Subsequent
4217
+** calls to [sqlite3_errcode()] and [sqlite3_errmsg()] and similar will
4218
+** return the values set by this routine in place of what was previously
4219
+** set by SQLite itself.
4220
+**
4221
+** This function returns SQLITE_OK if the error code and error message are
4222
+** successfully set, SQLITE_NOMEM if an OOM occurs, and SQLITE_MISUSE if
4223
+** the database handle is NULL or invalid.
4224
+**
4225
+** The error code and message set by this routine remains in effect until
4226
+** they are changed, either by another call to this routine or until they are
4227
+** changed to by SQLite itself to reflect the result of some subsquent
4228
+** API call.
4229
+**
4230
+** This function is intended for use by SQLite extensions or wrappers. The
4231
+** idea is that an extension or wrapper can use this routine to set error
4232
+** messages and error codes and thus behave more like a core SQLite
4233
+** feature from the point of view of an application.
4234
+*/
4235
+SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zErrMsg);
4236
+
42094237
/*
42104238
** CAPI3REF: Prepared Statement Object
42114239
** KEYWORDS: {prepared statement} {prepared statements}
42124240
**
42134241
** An instance of this object represents a single SQL statement that
@@ -12343,10 +12371,19 @@
1234312371
** CAPI3REF: Apply A Changeset To A Database
1234412372
**
1234512373
** Apply a changeset or patchset to a database. These functions attempt to
1234612374
** update the "main" database attached to handle db with the changes found in
1234712375
** the changeset passed via the second and third arguments.
12376
+**
12377
+** All changes made by these functions are enclosed in a savepoint transaction.
12378
+** If any other error (aside from a constraint failure when attempting to
12379
+** write to the target database) occurs, then the savepoint transaction is
12380
+** rolled back, restoring the target database to its original state, and an
12381
+** SQLite error code returned. Additionally, starting with version 3.51.0,
12382
+** an error code and error message that may be accessed using the
12383
+** [sqlite3_errcode()] and [sqlite3_errmsg()] APIs are left in the database
12384
+** handle.
1234812385
**
1234912386
** The fourth argument (xFilter) passed to these functions is the "filter
1235012387
** callback". This may be passed NULL, in which case all changes in the
1235112388
** changeset are applied to the database. For sqlite3changeset_apply() and
1235212389
** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
@@ -12481,16 +12518,10 @@
1248112518
** It is safe to execute SQL statements, including those that write to the
1248212519
** table that the callback related to, from within the xConflict callback.
1248312520
** This can be used to further customize the application's conflict
1248412521
** resolution strategy.
1248512522
**
12486
-** All changes made by these functions are enclosed in a savepoint transaction.
12487
-** If any other error (aside from a constraint failure when attempting to
12488
-** write to the target database) occurs, then the savepoint transaction is
12489
-** rolled back, restoring the target database to its original state, and an
12490
-** SQLite error code returned.
12491
-**
1249212523
** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
1249312524
** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
1249412525
** may set (*ppRebase) to point to a "rebase" that may be used with the
1249512526
** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
1249612527
** is set to the size of the buffer in bytes. It is the responsibility of the
1249712528
--- 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.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-09-10 14:28:07 61d9e204c5801a94811fdb0afe2c04f9814e08f2e141afa6dbda0fa45f026f70"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-09-10T14:28:07.926Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4204,10 +4204,38 @@
4204 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
4205 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
4206 SQLITE_API const char *sqlite3_errstr(int);
4207 SQLITE_API int sqlite3_error_offset(sqlite3 *db);
4208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4209 /*
4210 ** CAPI3REF: Prepared Statement Object
4211 ** KEYWORDS: {prepared statement} {prepared statements}
4212 **
4213 ** An instance of this object represents a single SQL statement that
@@ -12343,10 +12371,19 @@
12343 ** CAPI3REF: Apply A Changeset To A Database
12344 **
12345 ** Apply a changeset or patchset to a database. These functions attempt to
12346 ** update the "main" database attached to handle db with the changes found in
12347 ** the changeset passed via the second and third arguments.
 
 
 
 
 
 
 
 
 
12348 **
12349 ** The fourth argument (xFilter) passed to these functions is the "filter
12350 ** callback". This may be passed NULL, in which case all changes in the
12351 ** changeset are applied to the database. For sqlite3changeset_apply() and
12352 ** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
@@ -12481,16 +12518,10 @@
12481 ** It is safe to execute SQL statements, including those that write to the
12482 ** table that the callback related to, from within the xConflict callback.
12483 ** This can be used to further customize the application's conflict
12484 ** resolution strategy.
12485 **
12486 ** All changes made by these functions are enclosed in a savepoint transaction.
12487 ** If any other error (aside from a constraint failure when attempting to
12488 ** write to the target database) occurs, then the savepoint transaction is
12489 ** rolled back, restoring the target database to its original state, and an
12490 ** SQLite error code returned.
12491 **
12492 ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
12493 ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
12494 ** may set (*ppRebase) to point to a "rebase" that may be used with the
12495 ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
12496 ** is set to the size of the buffer in bytes. It is the responsibility of the
12497
--- 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.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-09-24 19:10:58 821cc0e421bc14a68ebaee507e38a900e0c84ff6ba7ee95bf796cad387755232"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-09-24T19:10:58.215Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4204,10 +4204,38 @@
4204 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
4205 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
4206 SQLITE_API const char *sqlite3_errstr(int);
4207 SQLITE_API int sqlite3_error_offset(sqlite3 *db);
4208
4209 /*
4210 ** CAPI3REF: Set Error Codes And Message
4211 ** METHOD: sqlite3
4212 **
4213 ** Set the error code of the database handle passed as the first argument
4214 ** to errcode, and the error message to a copy of nul-terminated string
4215 ** zErrMsg. If zErrMsg is passed NULL, then the error message is set to
4216 ** the default message associated with the supplied error code. Subsequent
4217 ** calls to [sqlite3_errcode()] and [sqlite3_errmsg()] and similar will
4218 ** return the values set by this routine in place of what was previously
4219 ** set by SQLite itself.
4220 **
4221 ** This function returns SQLITE_OK if the error code and error message are
4222 ** successfully set, SQLITE_NOMEM if an OOM occurs, and SQLITE_MISUSE if
4223 ** the database handle is NULL or invalid.
4224 **
4225 ** The error code and message set by this routine remains in effect until
4226 ** they are changed, either by another call to this routine or until they are
4227 ** changed to by SQLite itself to reflect the result of some subsquent
4228 ** API call.
4229 **
4230 ** This function is intended for use by SQLite extensions or wrappers. The
4231 ** idea is that an extension or wrapper can use this routine to set error
4232 ** messages and error codes and thus behave more like a core SQLite
4233 ** feature from the point of view of an application.
4234 */
4235 SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zErrMsg);
4236
4237 /*
4238 ** CAPI3REF: Prepared Statement Object
4239 ** KEYWORDS: {prepared statement} {prepared statements}
4240 **
4241 ** An instance of this object represents a single SQL statement that
@@ -12343,10 +12371,19 @@
12371 ** CAPI3REF: Apply A Changeset To A Database
12372 **
12373 ** Apply a changeset or patchset to a database. These functions attempt to
12374 ** update the "main" database attached to handle db with the changes found in
12375 ** the changeset passed via the second and third arguments.
12376 **
12377 ** All changes made by these functions are enclosed in a savepoint transaction.
12378 ** If any other error (aside from a constraint failure when attempting to
12379 ** write to the target database) occurs, then the savepoint transaction is
12380 ** rolled back, restoring the target database to its original state, and an
12381 ** SQLite error code returned. Additionally, starting with version 3.51.0,
12382 ** an error code and error message that may be accessed using the
12383 ** [sqlite3_errcode()] and [sqlite3_errmsg()] APIs are left in the database
12384 ** handle.
12385 **
12386 ** The fourth argument (xFilter) passed to these functions is the "filter
12387 ** callback". This may be passed NULL, in which case all changes in the
12388 ** changeset are applied to the database. For sqlite3changeset_apply() and
12389 ** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once
@@ -12481,16 +12518,10 @@
12518 ** It is safe to execute SQL statements, including those that write to the
12519 ** table that the callback related to, from within the xConflict callback.
12520 ** This can be used to further customize the application's conflict
12521 ** resolution strategy.
12522 **
 
 
 
 
 
 
12523 ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
12524 ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
12525 ** may set (*ppRebase) to point to a "rebase" that may be used with the
12526 ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
12527 ** is set to the size of the buffer in bytes. It is the responsibility of the
12528

Keyboard Shortcuts

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