Fossil SCM

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

drh 2026-10-01 12:01 UTC trunk
Commit 51267fb4c372a6575a7938816b68d50fbf067ba2212e40101f19a7604af4fbee
+39 -24
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -3852,10 +3852,11 @@
38523852
p->spec.eStyle = QRF_STYLE_List;
38533853
p->spec.eText = QRF_TEXT_Csv;
38543854
p->spec.zColumnSep = ",";
38553855
p->spec.zRowSep = "\r\n";
38563856
p->spec.zNull = "";
3857
+ if( p->spec.eEsc==QRF_Auto ) p->spec.eEsc = QRF_ESC_Off;
38573858
break;
38583859
}
38593860
case QRF_STYLE_Quote: {
38603861
p->spec.eText = QRF_TEXT_Sql;
38613862
p->spec.zNull = "NULL";
@@ -16673,11 +16674,14 @@
1667316674
struct IdxRemSlot *pSlot;
1667416675
int iSlot;
1667516676
assert( argc==2 );
1667616677
1667716678
iSlot = sqlite3_value_int(argv[0]);
16678
- assert( iSlot<p->nSlot );
16679
+ if( iSlot<0 || iSlot>=p->nSlot ){
16680
+ sqlite3_result_error(pCtx, "index out of range.", -1);
16681
+ return;
16682
+ }
1667916683
pSlot = &p->aSlot[iSlot];
1668016684
1668116685
switch( pSlot->eType ){
1668216686
case SQLITE_NULL:
1668316687
/* no-op */
@@ -18448,19 +18452,15 @@
1844818452
** Return the SQL statement used to check object zObj. Or, if zObj is
1844918453
** NULL, the current SQL statement.
1845018454
*/
1845118455
const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){
1845218456
sqlite3_free(p->zTestSql);
18457
+ p->zTestSql = 0;
1845318458
if( zObj ){
1845418459
p->zTestSql = intckCheckObjectSql(p, zObj, 0, 0);
18455
- }else{
18456
- if( p->zObj ){
18457
- p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey, 0);
18458
- }else{
18459
- sqlite3_free(p->zTestSql);
18460
- p->zTestSql = 0;
18461
- }
18460
+ }else if( p->zObj ){
18461
+ p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey, 0);
1846218462
}
1846318463
return p->zTestSql;
1846418464
}
1846518465
1846618466
/************************* End ext/intck/sqlite3intck.c ********************/
@@ -20693,10 +20693,18 @@
2069320693
/* #include "sqlite3ext.h" */
2069420694
SQLITE_EXTENSION_INIT1
2069520695
#include <assert.h>
2069620696
#include <string.h>
2069720697
#include <stdlib.h>
20698
+
20699
+/*
20700
+** No-op wrapper around free() to work around problems with non-CDECL
20701
+** calling conventions on 32-bit Windows builds.
20702
+*/
20703
+static void strdupFree(void *p){
20704
+ free(p);
20705
+}
2069820706
2069920707
/*
2070020708
** Make a copy of a string or BLOB in memory obtained from malloc().
2070120709
*/
2070220710
static void strdupfunc(
@@ -20717,11 +20725,11 @@
2071720725
if( zOut==0 ){
2071820726
sqlite3_result_error_nomem(context);
2071920727
return;
2072020728
}
2072120729
if( nIn>0 ) memcpy(zOut, zIn, nIn);
20722
- sqlite3_result_blob(context, zOut, nIn, free);
20730
+ sqlite3_result_blob(context, zOut, nIn, strdupFree);
2072320731
}else{
2072420732
zIn = (const unsigned char*)sqlite3_value_text(argv[0]);
2072520733
if( zIn==0 ) return;
2072620734
nIn = (int)strlen((char*)zIn);
2072720735
zOut = malloc( nIn+1 );
@@ -20729,11 +20737,11 @@
2072920737
sqlite3_result_error_nomem(context);
2073020738
return;
2073120739
}
2073220740
memcpy(zOut, zIn, nIn);
2073320741
zOut[nIn] = 0;
20734
- sqlite3_result_text64(context, (char*)zOut, nIn, free,
20742
+ sqlite3_result_text64(context, (char*)zOut, nIn, strdupFree,
2073520743
SQLITE_UTF8_ZT);
2073620744
}
2073720745
}
2073820746
2073920747
#ifdef _WIN32
@@ -25263,11 +25271,11 @@
2526325271
{ "ascii", 7, 6, 9, 1, 1, 0, 1, 12, 0, 0 },
2526425272
{ "box", 0, 0, 9, 1, 1, 0, 3, 1, 2, 0 },
2526525273
{ "c", 4, 1, 10, 5, 5, 4, 1, 12, 0, 0 },
2526625274
{ "column", 0, 0, 9, 1, 1, 0, 3, 2, 2, 0 },
2526725275
{ "count", 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 },
25268
- { "csv", 4, 5, 9, 3, 3, 0, 1, 12, 0, 0 },
25276
+ { "csv", 4, 5, 9, 3, 3, 0, 1, 4, 0, 0 },
2526925277
{ "html", 0, 0, 9, 4, 4, 0, 3, 7, 0, 0 },
2527025278
{ "insert", 0, 0, 10, 2, 2, 0, 1, 8, 0, 0 },
2527125279
{ "jatom", 4, 1, 11, 6, 6, 0, 1, 12, 0, 0 },
2527225280
{ "jobject", 0, 1, 11, 6, 6, 0, 0, 10, 0, 0 },
2527325281
{ "json", 0, 0, 11, 6, 6, 0, 0, 9, 0, 0 },
@@ -26327,11 +26335,11 @@
2632726335
sqlite3 *db, /* The database connection containing the vtab */
2632826336
const char *zSchema, /* Schema of the database holding the vtab */
2632926337
const char *zName /* The name of the virtual table */
2633026338
){
2633126339
sqlite3_stmt *pStmt = 0;
26332
- char *zSql;
26340
+ char *zSql, *zCom;
2633326341
ShellText s;
2633426342
char cQuote;
2633526343
char *zDiv = "(";
2633626344
int nRow = 0;
2633726345
@@ -26361,10 +26369,12 @@
2636126369
appendText(&s, ")", 0);
2636226370
sqlite3_finalize(pStmt);
2636326371
if( nRow==0 ){
2636426372
freeText(&s);
2636526373
s.zTxt = 0;
26374
+ }else{
26375
+ while( s.zTxt && (zCom = strstr(s.zTxt,"*/"))!=0 ){ zCom[1] = '*'; }
2636626376
}
2636726377
return s.zTxt;
2636826378
}
2636926379
2637026380
/*
@@ -26461,10 +26471,11 @@
2646126471
}
2646226472
if( zName
2646326473
&& aPrefix[i][0]=='V'
2646426474
&& (zFake = shellFakeSchema(db, zSchema, zName))!=0
2646526475
){
26476
+ assert( strstr(zFake,"*/")==0 );
2646626477
if( z==0 ){
2646726478
z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
2646826479
}else{
2646926480
z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
2647026481
}
@@ -28544,11 +28555,11 @@
2854428555
}
2854528556
2854628557
bind_prepared_stmt(pArg, pStmt);
2854728558
if( isExplain && pArg->mode.autoExplain ){
2854828559
spec.eStyle = isExplain==1 ? QRF_STYLE_Explain : QRF_STYLE_Eqp;
28549
- sqlite3_format_query_result(pStmt, &spec, pzErrMsg);
28560
+ rc = sqlite3_format_query_result(pStmt, &spec, pzErrMsg);
2855028561
}else if( pArg->mode.eMode==MODE_Www ){
2855128562
cli_printf(pArg->out,
2855228563
"</PRE>\n"
2855328564
"<TABLE border='1' cellspacing='0' cellpadding='2'>\n");
2855428565
spec.eStyle = QRF_STYLE_Html;
@@ -28556,11 +28567,11 @@
2855628567
cli_printf(pArg->out,
2855728568
"</TABLE>\n"
2855828569
"<PRE>");
2855928570
}else{
2856028571
spec.eStyle = eStyle;
28561
- sqlite3_format_query_result(pStmt, &spec, pzErrMsg);
28572
+ rc = sqlite3_format_query_result(pStmt, &spec, pzErrMsg);
2856228573
}
2856328574
2856428575
/* print usage stats if stats on */
2856528576
if( pArg && pArg->mStats!=0 ){
2856628577
display_stats(db, pArg);
@@ -28584,15 +28595,15 @@
2858428595
2858528596
/* Finalize the statement just executed. If this fails, save a
2858628597
** copy of the error message. Otherwise, set zSql to point to the
2858728598
** next statement to execute. */
2858828599
rc2 = sqlite3_finalize(pStmt);
28589
- if( rc!=SQLITE_NOMEM ) rc = rc2;
28600
+ if( rc2 && rc!=SQLITE_NOMEM ) rc = rc2;
2859028601
if( rc==SQLITE_OK ){
2859128602
zSql = zLeftover;
2859228603
while( IsSpace(zSql[0]) ) zSql++;
28593
- }else if( pzErrMsg ){
28604
+ }else if( pzErrMsg && pzErrMsg[0]==0 ){
2859428605
*pzErrMsg = save_err_msg(db, "stepping", rc, 0);
2859528606
}
2859628607
2859728608
/* clear saved stmt handle */
2859828609
if( pArg ){
@@ -29253,12 +29264,12 @@
2925329264
" --charlimit N Set the maximum number of output characters to\n"
2925429265
" show for any single SQL value to N. Longer values\n"
2925529266
" truncated. Zero means \"no limit\".\n"
2925629267
" --colsep STRING Use STRING as the column separator\n"
2925729268
" --escape ESC Enable/disable escaping of control characters\n"
29258
-" found in the output. ESC can be \"off\", \"ascii\",\n"
29259
-" or \"symbol\".\n"
29269
+" found in the output. ESC can be \"auto\", \"off\",\n"
29270
+" \"ascii\", or \"symbol\". Default is \"auto\"\n"
2926029271
" --fpfmt STRING String is a printf-style format string used to\n"
2926129272
" render floating-point values.\n"
2926229273
" --ifmt STRING String is a printf-style format string used to\n"
2926329274
" render integer values.\n"
2926429275
" --linelimit N Set the maximum number of output lines to show for\n"
@@ -29890,10 +29901,11 @@
2989029901
p->pLog = 0;
2989129902
zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
2989229903
p->pLog = pSavedLog;
2989329904
2989429905
if( zFake ){
29906
+ assert( strstr(zFake,"*/")==0 );
2989529907
sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
2989629908
-1, sqlite3_free);
2989729909
sqlite3_free(zFake);
2989829910
}
2989929911
}
@@ -33559,12 +33571,12 @@
3355933571
** --charlimit N Set the maximum number of output characters to
3356033572
** show for any single SQL value to N. Longer values
3356133573
** truncated. Zero means "no limit".
3356233574
** --colsep STRING Use STRING as the column separator
3356333575
** --escape ESC Enable/disable escaping of control characters
33564
-** found in the output. ESC can be "off", "ascii",
33565
-** or "symbol".
33576
+** found in the output. ESC can be "auto", "off",
33577
+** "ascii", or "symbol". Default is "auto"
3356633578
** --fpfmt STRING String is a printf-style format string used to
3356733579
** render floating-point values.
3356833580
** --ifmt STRING String is a printf-style format string used to
3356933581
** render integer values.
3357033582
** --linelimit N Set the maximum number of output lines to show for
@@ -33728,18 +33740,18 @@
3372833740
/* See similar code at tag-20250224-1 */
3372933741
char *zErr = 0;
3373033742
if( (++i)>=nArg ){
3373133743
dotCmdError(p, i-1, "missing argument", 0);
3373233744
return 1;
33733
- } /* 0 1 2 <-- One less than QRF_ESC_ */
33734
- k = pickStr(azArg[i],&zErr,"off","ascii","symbol","");
33745
+ } /* 0 1 2 3 */
33746
+ k = pickStr(azArg[i],&zErr,"auto", "off","ascii","symbol","");
3373533747
if( k<0 ){
3373633748
dotCmdError(p, i, "unknown escape type", "%s", zErr);
3373733749
sqlite3_free(zErr);
3373833750
return 1;
3373933751
}
33740
- p->mode.spec.eEsc = k+1;
33752
+ p->mode.spec.eEsc = k;
3374133753
chng = 1;
3374233754
}else if( optionMatch(z,"limits") ){
3374333755
if( (++i)>=nArg ){
3374433756
dotCmdError(p, i-1, "missing argument", 0);
3374533757
return 1;
@@ -35338,11 +35350,11 @@
3533835350
p->writableSchema = 0;
3533935351
}
3534035352
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
3534135353
sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
3534235354
if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
35343
- cli_puts(p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n", p->out);
35355
+ cli_puts(p->nErr?";\nROLLBACK; -- due to errors\n":"COMMIT;\n", p->out);
3534435356
}
3534535357
p->shellFlgs = savedShellFlags;
3534635358
modeFree(&p->mode);
3534735359
p->mode = saved_mode;
3534835360
rc = p->nErr>0;
@@ -38264,12 +38276,15 @@
3826438276
return 0;
3826538277
}
3826638278
3826738279
static void echo_group_input(ShellState *p, const char *zDo){
3826838280
if( p->mode.mFlags & MFLG_ECHO ){
38281
+ sqlite3_str *savedCliCapture = cli_output_capture;
38282
+ cli_output_capture = 0; /* .echo should not be captured by .testcase */
3826938283
cli_printf(p->out, "%s\n", zDo);
3827038284
fflush(p->out);
38285
+ cli_output_capture = savedCliCapture;
3827138286
}
3827238287
}
3827338288
3827438289
#ifdef SQLITE_SHELL_FIDDLE
3827538290
/*
3827638291
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -3852,10 +3852,11 @@
3852 p->spec.eStyle = QRF_STYLE_List;
3853 p->spec.eText = QRF_TEXT_Csv;
3854 p->spec.zColumnSep = ",";
3855 p->spec.zRowSep = "\r\n";
3856 p->spec.zNull = "";
 
3857 break;
3858 }
3859 case QRF_STYLE_Quote: {
3860 p->spec.eText = QRF_TEXT_Sql;
3861 p->spec.zNull = "NULL";
@@ -16673,11 +16674,14 @@
16673 struct IdxRemSlot *pSlot;
16674 int iSlot;
16675 assert( argc==2 );
16676
16677 iSlot = sqlite3_value_int(argv[0]);
16678 assert( iSlot<p->nSlot );
 
 
 
16679 pSlot = &p->aSlot[iSlot];
16680
16681 switch( pSlot->eType ){
16682 case SQLITE_NULL:
16683 /* no-op */
@@ -18448,19 +18452,15 @@
18448 ** Return the SQL statement used to check object zObj. Or, if zObj is
18449 ** NULL, the current SQL statement.
18450 */
18451 const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){
18452 sqlite3_free(p->zTestSql);
 
18453 if( zObj ){
18454 p->zTestSql = intckCheckObjectSql(p, zObj, 0, 0);
18455 }else{
18456 if( p->zObj ){
18457 p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey, 0);
18458 }else{
18459 sqlite3_free(p->zTestSql);
18460 p->zTestSql = 0;
18461 }
18462 }
18463 return p->zTestSql;
18464 }
18465
18466 /************************* End ext/intck/sqlite3intck.c ********************/
@@ -20693,10 +20693,18 @@
20693 /* #include "sqlite3ext.h" */
20694 SQLITE_EXTENSION_INIT1
20695 #include <assert.h>
20696 #include <string.h>
20697 #include <stdlib.h>
 
 
 
 
 
 
 
 
20698
20699 /*
20700 ** Make a copy of a string or BLOB in memory obtained from malloc().
20701 */
20702 static void strdupfunc(
@@ -20717,11 +20725,11 @@
20717 if( zOut==0 ){
20718 sqlite3_result_error_nomem(context);
20719 return;
20720 }
20721 if( nIn>0 ) memcpy(zOut, zIn, nIn);
20722 sqlite3_result_blob(context, zOut, nIn, free);
20723 }else{
20724 zIn = (const unsigned char*)sqlite3_value_text(argv[0]);
20725 if( zIn==0 ) return;
20726 nIn = (int)strlen((char*)zIn);
20727 zOut = malloc( nIn+1 );
@@ -20729,11 +20737,11 @@
20729 sqlite3_result_error_nomem(context);
20730 return;
20731 }
20732 memcpy(zOut, zIn, nIn);
20733 zOut[nIn] = 0;
20734 sqlite3_result_text64(context, (char*)zOut, nIn, free,
20735 SQLITE_UTF8_ZT);
20736 }
20737 }
20738
20739 #ifdef _WIN32
@@ -25263,11 +25271,11 @@
25263 { "ascii", 7, 6, 9, 1, 1, 0, 1, 12, 0, 0 },
25264 { "box", 0, 0, 9, 1, 1, 0, 3, 1, 2, 0 },
25265 { "c", 4, 1, 10, 5, 5, 4, 1, 12, 0, 0 },
25266 { "column", 0, 0, 9, 1, 1, 0, 3, 2, 2, 0 },
25267 { "count", 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 },
25268 { "csv", 4, 5, 9, 3, 3, 0, 1, 12, 0, 0 },
25269 { "html", 0, 0, 9, 4, 4, 0, 3, 7, 0, 0 },
25270 { "insert", 0, 0, 10, 2, 2, 0, 1, 8, 0, 0 },
25271 { "jatom", 4, 1, 11, 6, 6, 0, 1, 12, 0, 0 },
25272 { "jobject", 0, 1, 11, 6, 6, 0, 0, 10, 0, 0 },
25273 { "json", 0, 0, 11, 6, 6, 0, 0, 9, 0, 0 },
@@ -26327,11 +26335,11 @@
26327 sqlite3 *db, /* The database connection containing the vtab */
26328 const char *zSchema, /* Schema of the database holding the vtab */
26329 const char *zName /* The name of the virtual table */
26330 ){
26331 sqlite3_stmt *pStmt = 0;
26332 char *zSql;
26333 ShellText s;
26334 char cQuote;
26335 char *zDiv = "(";
26336 int nRow = 0;
26337
@@ -26361,10 +26369,12 @@
26361 appendText(&s, ")", 0);
26362 sqlite3_finalize(pStmt);
26363 if( nRow==0 ){
26364 freeText(&s);
26365 s.zTxt = 0;
 
 
26366 }
26367 return s.zTxt;
26368 }
26369
26370 /*
@@ -26461,10 +26471,11 @@
26461 }
26462 if( zName
26463 && aPrefix[i][0]=='V'
26464 && (zFake = shellFakeSchema(db, zSchema, zName))!=0
26465 ){
 
26466 if( z==0 ){
26467 z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
26468 }else{
26469 z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
26470 }
@@ -28544,11 +28555,11 @@
28544 }
28545
28546 bind_prepared_stmt(pArg, pStmt);
28547 if( isExplain && pArg->mode.autoExplain ){
28548 spec.eStyle = isExplain==1 ? QRF_STYLE_Explain : QRF_STYLE_Eqp;
28549 sqlite3_format_query_result(pStmt, &spec, pzErrMsg);
28550 }else if( pArg->mode.eMode==MODE_Www ){
28551 cli_printf(pArg->out,
28552 "</PRE>\n"
28553 "<TABLE border='1' cellspacing='0' cellpadding='2'>\n");
28554 spec.eStyle = QRF_STYLE_Html;
@@ -28556,11 +28567,11 @@
28556 cli_printf(pArg->out,
28557 "</TABLE>\n"
28558 "<PRE>");
28559 }else{
28560 spec.eStyle = eStyle;
28561 sqlite3_format_query_result(pStmt, &spec, pzErrMsg);
28562 }
28563
28564 /* print usage stats if stats on */
28565 if( pArg && pArg->mStats!=0 ){
28566 display_stats(db, pArg);
@@ -28584,15 +28595,15 @@
28584
28585 /* Finalize the statement just executed. If this fails, save a
28586 ** copy of the error message. Otherwise, set zSql to point to the
28587 ** next statement to execute. */
28588 rc2 = sqlite3_finalize(pStmt);
28589 if( rc!=SQLITE_NOMEM ) rc = rc2;
28590 if( rc==SQLITE_OK ){
28591 zSql = zLeftover;
28592 while( IsSpace(zSql[0]) ) zSql++;
28593 }else if( pzErrMsg ){
28594 *pzErrMsg = save_err_msg(db, "stepping", rc, 0);
28595 }
28596
28597 /* clear saved stmt handle */
28598 if( pArg ){
@@ -29253,12 +29264,12 @@
29253 " --charlimit N Set the maximum number of output characters to\n"
29254 " show for any single SQL value to N. Longer values\n"
29255 " truncated. Zero means \"no limit\".\n"
29256 " --colsep STRING Use STRING as the column separator\n"
29257 " --escape ESC Enable/disable escaping of control characters\n"
29258 " found in the output. ESC can be \"off\", \"ascii\",\n"
29259 " or \"symbol\".\n"
29260 " --fpfmt STRING String is a printf-style format string used to\n"
29261 " render floating-point values.\n"
29262 " --ifmt STRING String is a printf-style format string used to\n"
29263 " render integer values.\n"
29264 " --linelimit N Set the maximum number of output lines to show for\n"
@@ -29890,10 +29901,11 @@
29890 p->pLog = 0;
29891 zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
29892 p->pLog = pSavedLog;
29893
29894 if( zFake ){
 
29895 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
29896 -1, sqlite3_free);
29897 sqlite3_free(zFake);
29898 }
29899 }
@@ -33559,12 +33571,12 @@
33559 ** --charlimit N Set the maximum number of output characters to
33560 ** show for any single SQL value to N. Longer values
33561 ** truncated. Zero means "no limit".
33562 ** --colsep STRING Use STRING as the column separator
33563 ** --escape ESC Enable/disable escaping of control characters
33564 ** found in the output. ESC can be "off", "ascii",
33565 ** or "symbol".
33566 ** --fpfmt STRING String is a printf-style format string used to
33567 ** render floating-point values.
33568 ** --ifmt STRING String is a printf-style format string used to
33569 ** render integer values.
33570 ** --linelimit N Set the maximum number of output lines to show for
@@ -33728,18 +33740,18 @@
33728 /* See similar code at tag-20250224-1 */
33729 char *zErr = 0;
33730 if( (++i)>=nArg ){
33731 dotCmdError(p, i-1, "missing argument", 0);
33732 return 1;
33733 } /* 0 1 2 <-- One less than QRF_ESC_ */
33734 k = pickStr(azArg[i],&zErr,"off","ascii","symbol","");
33735 if( k<0 ){
33736 dotCmdError(p, i, "unknown escape type", "%s", zErr);
33737 sqlite3_free(zErr);
33738 return 1;
33739 }
33740 p->mode.spec.eEsc = k+1;
33741 chng = 1;
33742 }else if( optionMatch(z,"limits") ){
33743 if( (++i)>=nArg ){
33744 dotCmdError(p, i-1, "missing argument", 0);
33745 return 1;
@@ -35338,11 +35350,11 @@
35338 p->writableSchema = 0;
35339 }
35340 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
35341 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
35342 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
35343 cli_puts(p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n", p->out);
35344 }
35345 p->shellFlgs = savedShellFlags;
35346 modeFree(&p->mode);
35347 p->mode = saved_mode;
35348 rc = p->nErr>0;
@@ -38264,12 +38276,15 @@
38264 return 0;
38265 }
38266
38267 static void echo_group_input(ShellState *p, const char *zDo){
38268 if( p->mode.mFlags & MFLG_ECHO ){
 
 
38269 cli_printf(p->out, "%s\n", zDo);
38270 fflush(p->out);
 
38271 }
38272 }
38273
38274 #ifdef SQLITE_SHELL_FIDDLE
38275 /*
38276
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -3852,10 +3852,11 @@
3852 p->spec.eStyle = QRF_STYLE_List;
3853 p->spec.eText = QRF_TEXT_Csv;
3854 p->spec.zColumnSep = ",";
3855 p->spec.zRowSep = "\r\n";
3856 p->spec.zNull = "";
3857 if( p->spec.eEsc==QRF_Auto ) p->spec.eEsc = QRF_ESC_Off;
3858 break;
3859 }
3860 case QRF_STYLE_Quote: {
3861 p->spec.eText = QRF_TEXT_Sql;
3862 p->spec.zNull = "NULL";
@@ -16673,11 +16674,14 @@
16674 struct IdxRemSlot *pSlot;
16675 int iSlot;
16676 assert( argc==2 );
16677
16678 iSlot = sqlite3_value_int(argv[0]);
16679 if( iSlot<0 || iSlot>=p->nSlot ){
16680 sqlite3_result_error(pCtx, "index out of range.", -1);
16681 return;
16682 }
16683 pSlot = &p->aSlot[iSlot];
16684
16685 switch( pSlot->eType ){
16686 case SQLITE_NULL:
16687 /* no-op */
@@ -18448,19 +18452,15 @@
18452 ** Return the SQL statement used to check object zObj. Or, if zObj is
18453 ** NULL, the current SQL statement.
18454 */
18455 const char *sqlite3_intck_test_sql(sqlite3_intck *p, const char *zObj){
18456 sqlite3_free(p->zTestSql);
18457 p->zTestSql = 0;
18458 if( zObj ){
18459 p->zTestSql = intckCheckObjectSql(p, zObj, 0, 0);
18460 }else if( p->zObj ){
18461 p->zTestSql = intckCheckObjectSql(p, p->zObj, p->zKey, 0);
 
 
 
 
 
18462 }
18463 return p->zTestSql;
18464 }
18465
18466 /************************* End ext/intck/sqlite3intck.c ********************/
@@ -20693,10 +20693,18 @@
20693 /* #include "sqlite3ext.h" */
20694 SQLITE_EXTENSION_INIT1
20695 #include <assert.h>
20696 #include <string.h>
20697 #include <stdlib.h>
20698
20699 /*
20700 ** No-op wrapper around free() to work around problems with non-CDECL
20701 ** calling conventions on 32-bit Windows builds.
20702 */
20703 static void strdupFree(void *p){
20704 free(p);
20705 }
20706
20707 /*
20708 ** Make a copy of a string or BLOB in memory obtained from malloc().
20709 */
20710 static void strdupfunc(
@@ -20717,11 +20725,11 @@
20725 if( zOut==0 ){
20726 sqlite3_result_error_nomem(context);
20727 return;
20728 }
20729 if( nIn>0 ) memcpy(zOut, zIn, nIn);
20730 sqlite3_result_blob(context, zOut, nIn, strdupFree);
20731 }else{
20732 zIn = (const unsigned char*)sqlite3_value_text(argv[0]);
20733 if( zIn==0 ) return;
20734 nIn = (int)strlen((char*)zIn);
20735 zOut = malloc( nIn+1 );
@@ -20729,11 +20737,11 @@
20737 sqlite3_result_error_nomem(context);
20738 return;
20739 }
20740 memcpy(zOut, zIn, nIn);
20741 zOut[nIn] = 0;
20742 sqlite3_result_text64(context, (char*)zOut, nIn, strdupFree,
20743 SQLITE_UTF8_ZT);
20744 }
20745 }
20746
20747 #ifdef _WIN32
@@ -25263,11 +25271,11 @@
25271 { "ascii", 7, 6, 9, 1, 1, 0, 1, 12, 0, 0 },
25272 { "box", 0, 0, 9, 1, 1, 0, 3, 1, 2, 0 },
25273 { "c", 4, 1, 10, 5, 5, 4, 1, 12, 0, 0 },
25274 { "column", 0, 0, 9, 1, 1, 0, 3, 2, 2, 0 },
25275 { "count", 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 },
25276 { "csv", 4, 5, 9, 3, 3, 0, 1, 4, 0, 0 },
25277 { "html", 0, 0, 9, 4, 4, 0, 3, 7, 0, 0 },
25278 { "insert", 0, 0, 10, 2, 2, 0, 1, 8, 0, 0 },
25279 { "jatom", 4, 1, 11, 6, 6, 0, 1, 12, 0, 0 },
25280 { "jobject", 0, 1, 11, 6, 6, 0, 0, 10, 0, 0 },
25281 { "json", 0, 0, 11, 6, 6, 0, 0, 9, 0, 0 },
@@ -26327,11 +26335,11 @@
26335 sqlite3 *db, /* The database connection containing the vtab */
26336 const char *zSchema, /* Schema of the database holding the vtab */
26337 const char *zName /* The name of the virtual table */
26338 ){
26339 sqlite3_stmt *pStmt = 0;
26340 char *zSql, *zCom;
26341 ShellText s;
26342 char cQuote;
26343 char *zDiv = "(";
26344 int nRow = 0;
26345
@@ -26361,10 +26369,12 @@
26369 appendText(&s, ")", 0);
26370 sqlite3_finalize(pStmt);
26371 if( nRow==0 ){
26372 freeText(&s);
26373 s.zTxt = 0;
26374 }else{
26375 while( s.zTxt && (zCom = strstr(s.zTxt,"*/"))!=0 ){ zCom[1] = '*'; }
26376 }
26377 return s.zTxt;
26378 }
26379
26380 /*
@@ -26461,10 +26471,11 @@
26471 }
26472 if( zName
26473 && aPrefix[i][0]=='V'
26474 && (zFake = shellFakeSchema(db, zSchema, zName))!=0
26475 ){
26476 assert( strstr(zFake,"*/")==0 );
26477 if( z==0 ){
26478 z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
26479 }else{
26480 z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
26481 }
@@ -28544,11 +28555,11 @@
28555 }
28556
28557 bind_prepared_stmt(pArg, pStmt);
28558 if( isExplain && pArg->mode.autoExplain ){
28559 spec.eStyle = isExplain==1 ? QRF_STYLE_Explain : QRF_STYLE_Eqp;
28560 rc = sqlite3_format_query_result(pStmt, &spec, pzErrMsg);
28561 }else if( pArg->mode.eMode==MODE_Www ){
28562 cli_printf(pArg->out,
28563 "</PRE>\n"
28564 "<TABLE border='1' cellspacing='0' cellpadding='2'>\n");
28565 spec.eStyle = QRF_STYLE_Html;
@@ -28556,11 +28567,11 @@
28567 cli_printf(pArg->out,
28568 "</TABLE>\n"
28569 "<PRE>");
28570 }else{
28571 spec.eStyle = eStyle;
28572 rc = sqlite3_format_query_result(pStmt, &spec, pzErrMsg);
28573 }
28574
28575 /* print usage stats if stats on */
28576 if( pArg && pArg->mStats!=0 ){
28577 display_stats(db, pArg);
@@ -28584,15 +28595,15 @@
28595
28596 /* Finalize the statement just executed. If this fails, save a
28597 ** copy of the error message. Otherwise, set zSql to point to the
28598 ** next statement to execute. */
28599 rc2 = sqlite3_finalize(pStmt);
28600 if( rc2 && rc!=SQLITE_NOMEM ) rc = rc2;
28601 if( rc==SQLITE_OK ){
28602 zSql = zLeftover;
28603 while( IsSpace(zSql[0]) ) zSql++;
28604 }else if( pzErrMsg && pzErrMsg[0]==0 ){
28605 *pzErrMsg = save_err_msg(db, "stepping", rc, 0);
28606 }
28607
28608 /* clear saved stmt handle */
28609 if( pArg ){
@@ -29253,12 +29264,12 @@
29264 " --charlimit N Set the maximum number of output characters to\n"
29265 " show for any single SQL value to N. Longer values\n"
29266 " truncated. Zero means \"no limit\".\n"
29267 " --colsep STRING Use STRING as the column separator\n"
29268 " --escape ESC Enable/disable escaping of control characters\n"
29269 " found in the output. ESC can be \"auto\", \"off\",\n"
29270 " \"ascii\", or \"symbol\". Default is \"auto\"\n"
29271 " --fpfmt STRING String is a printf-style format string used to\n"
29272 " render floating-point values.\n"
29273 " --ifmt STRING String is a printf-style format string used to\n"
29274 " render integer values.\n"
29275 " --linelimit N Set the maximum number of output lines to show for\n"
@@ -29890,10 +29901,11 @@
29901 p->pLog = 0;
29902 zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
29903 p->pLog = pSavedLog;
29904
29905 if( zFake ){
29906 assert( strstr(zFake,"*/")==0 );
29907 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
29908 -1, sqlite3_free);
29909 sqlite3_free(zFake);
29910 }
29911 }
@@ -33559,12 +33571,12 @@
33571 ** --charlimit N Set the maximum number of output characters to
33572 ** show for any single SQL value to N. Longer values
33573 ** truncated. Zero means "no limit".
33574 ** --colsep STRING Use STRING as the column separator
33575 ** --escape ESC Enable/disable escaping of control characters
33576 ** found in the output. ESC can be "auto", "off",
33577 ** "ascii", or "symbol". Default is "auto"
33578 ** --fpfmt STRING String is a printf-style format string used to
33579 ** render floating-point values.
33580 ** --ifmt STRING String is a printf-style format string used to
33581 ** render integer values.
33582 ** --linelimit N Set the maximum number of output lines to show for
@@ -33728,18 +33740,18 @@
33740 /* See similar code at tag-20250224-1 */
33741 char *zErr = 0;
33742 if( (++i)>=nArg ){
33743 dotCmdError(p, i-1, "missing argument", 0);
33744 return 1;
33745 } /* 0 1 2 3 */
33746 k = pickStr(azArg[i],&zErr,"auto", "off","ascii","symbol","");
33747 if( k<0 ){
33748 dotCmdError(p, i, "unknown escape type", "%s", zErr);
33749 sqlite3_free(zErr);
33750 return 1;
33751 }
33752 p->mode.spec.eEsc = k;
33753 chng = 1;
33754 }else if( optionMatch(z,"limits") ){
33755 if( (++i)>=nArg ){
33756 dotCmdError(p, i-1, "missing argument", 0);
33757 return 1;
@@ -35338,11 +35350,11 @@
35350 p->writableSchema = 0;
35351 }
35352 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
35353 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
35354 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
35355 cli_puts(p->nErr?";\nROLLBACK; -- due to errors\n":"COMMIT;\n", p->out);
35356 }
35357 p->shellFlgs = savedShellFlags;
35358 modeFree(&p->mode);
35359 p->mode = saved_mode;
35360 rc = p->nErr>0;
@@ -38264,12 +38276,15 @@
38276 return 0;
38277 }
38278
38279 static void echo_group_input(ShellState *p, const char *zDo){
38280 if( p->mode.mFlags & MFLG_ECHO ){
38281 sqlite3_str *savedCliCapture = cli_output_capture;
38282 cli_output_capture = 0; /* .echo should not be captured by .testcase */
38283 cli_printf(p->out, "%s\n", zDo);
38284 fflush(p->out);
38285 cli_output_capture = savedCliCapture;
38286 }
38287 }
38288
38289 #ifdef SQLITE_SHELL_FIDDLE
38290 /*
38291
+796 -384
--- 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
-** 555f31c64d3fcc55df2715a7c8c1cb28503b with changes in files:
21
+** 92709f54d4c58cf174f305b58971a01878af with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.54.0"
471471
#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-08-27 10:58:16 555f31c64d3fcc55df2715a7c8c1cb28503b2c0eb21d950ccdcbf6f577593dd5"
472
+#define SQLITE_SOURCE_ID "2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-08-27T10:58:16.680Z"
475
+#define SQLITE_SCM_DATETIME "2026-10-01T11:21:02.802Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -3842,10 +3842,15 @@
38423842
** authorizer callback is the name of the database ("main", "temp",
38433843
** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
38443844
** is the name of the inner-most trigger or view that is responsible for
38453845
** the access attempt or NULL if this access attempt is directly from
38463846
** top-level SQL code.
3847
+**
3848
+** The case of strings in the 3rd through the 6th argument to the
3849
+** authorization callback is arbitrary. Authorization callbacks
3850
+** implementations should use [sqlite3_stricmp()] or similar when
3851
+** doing comparisons against those values.
38473852
*/
38483853
/******************************************* 3rd ************ 4th ***********/
38493854
#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
38503855
#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
38513856
#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
@@ -17208,10 +17213,14 @@
1720817213
#endif
1720917214
1721017215
#if defined(SQLITE_USE_SEH) && !defined(SQLITE_OMIT_WAL)
1721117216
SQLITE_PRIVATE int sqlite3PagerWalSystemErrno(Pager*);
1721217217
#endif
17218
+
17219
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
17220
+SQLITE_PRIVATE void sqlite3PagerWalStat(Pager*,sqlite3_str*);
17221
+#endif
1721317222
1721417223
#endif /* SQLITE_PAGER_H */
1721517224
1721617225
/************** End of pager.h ***********************************************/
1721717226
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -18590,11 +18599,11 @@
1859018599
*/
1859118600
#if !SQLITE_THREADSAFE
1859218601
# define SQLITE_MUTEX_OMIT
1859318602
#endif
1859418603
#if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
18595
-# if SQLITE_OS_UNIX
18604
+# if SQLITE_OS_UNIX || defined(__CYGWIN__)
1859618605
# define SQLITE_MUTEX_PTHREADS
1859718606
# elif SQLITE_OS_WIN
1859818607
# define SQLITE_MUTEX_W32
1859918608
# else
1860018609
# define SQLITE_MUTEX_NOOP
@@ -22645,11 +22654,20 @@
2264522654
#endif
2264622655
2264722656
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
2264822657
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
2264922658
SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
22659
+SQLITE_PRIVATE int sqlite3BinaryCompare(void*,int,const void*,int,const void*);
22660
+#if SQLITE_USES_INLINE
22661
+static SQLITE_INLINE int sqlite3IsBinary(const CollSeq *p){
22662
+ assert( p==0 || p->xCmp!=sqlite3BinaryCompare
22663
+ || strcmp(p->zName,"BINARY")==0 );
22664
+ return p==0 || p->xCmp==sqlite3BinaryCompare;
22665
+}
22666
+#else
2265022667
SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq*);
22668
+#endif
2265122669
SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
2265222670
SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8);
2265322671
SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr);
2265422672
SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr);
2265522673
SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*);
@@ -25965,10 +25983,11 @@
2596525983
if( ms>0.999 ) ms = 0.999;
2596625984
}
2596725985
}else{
2596825986
s = 0;
2596925987
}
25988
+ if( h==24 && (m!=0 || s!=0 || ms!=0.0) ) return 1;
2597025989
p->validJD = 0;
2597125990
p->rawS = 0;
2597225991
p->validHMS = 1;
2597325992
p->h = h;
2597425993
p->m = m;
@@ -26001,10 +26020,14 @@
2600126020
D = p->D;
2600226021
}else{
2600326022
Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
2600426023
M = 1;
2600526024
D = 1;
26025
+ if( p->validHMS && p->h==24 ){
26026
+ p->h = 0;
26027
+ D = 2;
26028
+ }
2600626029
}
2600726030
if( Y<-4713 || Y>9999 || p->rawS ){
2600826031
datetimeError(p);
2600926032
return;
2601026033
}
@@ -26039,10 +26062,14 @@
2603926062
*/
2604026063
static void computeFloor(DateTime *p){
2604126064
assert( p->validYMD || p->isError );
2604226065
assert( p->D>=0 && p->D<=31 );
2604326066
assert( p->M>=0 && p->M<=12 );
26067
+ if( p->validHMS && p->h==24 ){
26068
+ p->h = 0;
26069
+ p->D++;
26070
+ }
2604426071
if( p->D<=28 ){
2604526072
p->nFloor = 0;
2604626073
}else if( (1<<p->M) & 0x15aa ){
2604726074
p->nFloor = 0;
2604826075
}else if( p->M!=2 ){
@@ -31422,12 +31449,15 @@
3142231449
# define ALIGN128 __declspec(align(128))
3142331450
#else
3142431451
# define ALIGN128
3142531452
#endif
3142631453
31454
+#ifdef _MSC_VER
3142731455
#pragma warning(push)
3142831456
#pragma warning(disable: 4324)
31457
+#endif /* _MSC_VER */
31458
+
3142931459
/*
3143031460
** Each SQLite mutex is an instance of the following structure.
3143131461
**
3143231462
** The ALIGN128 macro attempts to force 128-byte alignment on mutexes,
3143331463
** so that adjacent mutex objects are always on different cache lines
@@ -31446,11 +31476,13 @@
3144631476
volatile int nRef; /* Number of entrances */
3144731477
volatile DWORD owner; /* Thread holding this mutex */
3144831478
volatile LONG trace; /* True to trace changes */
3144931479
#endif
3145031480
};
31481
+#ifdef _MSC_VER
3145131482
#pragma warning(pop)
31483
+#endif /* _MSC_VER */
3145231484
3145331485
#ifdef SQLITE_DEBUG
3145431486
/*
3145531487
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
3145631488
** intended for use only inside assert() statements.
@@ -32860,13 +32892,20 @@
3286032892
# define SQLITE_PRINT_BUF_SIZE 70
3286132893
#endif
3286232894
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
3286332895
3286432896
/*
32865
-** Hard limit on the precision of floating-point conversions.
32897
+** Hard limit on the precision of floating-point conversions to
32898
+** the minimum of SQLITE_PRINTF_PRECISION_LIMIT and 100 million.
3286632899
*/
32867
-#ifndef SQLITE_PRINTF_PRECISION_LIMIT
32900
+#ifdef SQLITE_PRINTF_PRECISION_LIMIT
32901
+# if SQLITE_PRINTF_PRECISION_LIMIT<100000000
32902
+# define SQLITE_FP_PRECISION_LIMIT SQLITE_PRINTF_PRECISION_LIMIT
32903
+# else
32904
+# define SQLITE_FP_PRECISION_LIMIT 100000000
32905
+# endif
32906
+#else
3286832907
# define SQLITE_FP_PRECISION_LIMIT 100000000
3286932908
#endif
3287032909
3287132910
/* Forward reference */
3287232911
static void sqlite3StrAppend64(sqlite3_str *p, const char *z, i64 N);
@@ -33222,15 +33261,13 @@
3322233261
realvalue = getDoubleArg(pArgList);
3322333262
}else{
3322433263
realvalue = va_arg(ap,double);
3322533264
}
3322633265
if( precision<0 ) precision = 6; /* Set default precision */
33227
-#ifdef SQLITE_FP_PRECISION_LIMIT
3322833266
if( precision>SQLITE_FP_PRECISION_LIMIT ){
3322933267
precision = SQLITE_FP_PRECISION_LIMIT;
3323033268
}
33231
-#endif
3323233269
if( xtype==etFLOAT ){
3323333270
iRound = -precision;
3323433271
}else if( xtype==etGENERIC ){
3323533272
if( precision==0 ) precision = 1;
3323633273
iRound = precision;
@@ -33316,11 +33353,11 @@
3331633353
if( szBufNeeded + pAccum->nChar >= pAccum->nAlloc ){
3331733354
if( pAccum->mxAlloc==0 && pAccum->accError==0 ){
3331833355
/* Unable to allocate space in pAccum, perhaps because it
3331933356
** is coming from sqlite3_snprintf() or similar. We'll have
3332033357
** to render into temporary space and the memcpy() it over. */
33321
- bufpt = sqlite3_malloc(szBufNeeded);
33358
+ bufpt = sqlite3_malloc64(szBufNeeded);
3332233359
if( bufpt==0 ){
3332333360
sqlite3StrAccumSetError(pAccum, SQLITE_NOMEM);
3332433361
return;
3332533362
}
3332633363
zExtra = bufpt;
@@ -36345,13 +36382,11 @@
3634536382
if( c>=0xc0 ){ \
3634636383
c = sqlite3Utf8Trans1[c-0xc0]; \
3634736384
while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
3634836385
c = (c<<6) + (0x3f & *(zIn++)); \
3634936386
} \
36350
- if( c<0x80 \
36351
- || (c&0xFFFFF800)==0xD800 \
36352
- || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
36387
+ if( c<0x80 || (c&0xFFFFF800)==0xD800 ){ c = 0xFFFD; } \
3635336388
}
3635436389
SQLITE_PRIVATE u32 sqlite3Utf8Read(
3635536390
const unsigned char **pz /* Pointer to string from which to read char */
3635636391
){
3635736392
unsigned int c;
@@ -36363,13 +36398,11 @@
3636336398
if( c>=0xc0 ){
3636436399
c = sqlite3Utf8Trans1[c-0xc0];
3636536400
while( (*(*pz) & 0xc0)==0x80 ){
3636636401
c = (c<<6) + (0x3f & *((*pz)++));
3636736402
}
36368
- if( c<0x80
36369
- || (c&0xFFFFF800)==0xD800
36370
- || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; }
36403
+ if( c<0x80 || (c&0xFFFFF800)==0xD800 ){ c = 0xFFFD; }
3637136404
}
3637236405
return c;
3637336406
}
3637436407
3637536408
/*
@@ -36765,11 +36798,10 @@
3676536798
z[0] = 0;
3676636799
z = zBuf;
3676736800
c = sqlite3Utf8Read((const u8**)&z);
3676836801
t = i;
3676936802
if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
36770
- if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
3677136803
assert( c==t );
3677236804
assert( (z-zBuf)==n );
3677336805
}
3677436806
}
3677536807
#endif /* SQLITE_TEST */
@@ -38324,11 +38356,11 @@
3832438356
SQLITE_PRIVATE int sqlite3GetUInt32(const char *z, u32 *pI){
3832538357
u64 v = 0;
3832638358
int i;
3832738359
for(i=0; sqlite3Isdigit(z[i]); i++){
3832838360
v = v*10 + z[i] - '0';
38329
- if( v>4294967296LL ){ *pI = 0; return 0; }
38361
+ if( v>4294967295LL ){ *pI = 0; return 0; }
3833038362
}
3833138363
if( i==0 || z[i]!=0 ){ *pI = 0; return 0; }
3833238364
*pI = (u32)v;
3833338365
return 1;
3833438366
}
@@ -49206,11 +49238,10 @@
4920649238
4920749239
/*
4920849240
** Include the header file for the Windows VFS.
4920949241
*/
4921049242
/* #include "os_win.h" */
49211
-#define SQLITE_WIN32_HAS_WIDE 1
4921249243
4921349244
/*
4921449245
** This constant should already be defined (in the "WinDef.h" SDK file).
4921549246
*/
4921649247
#ifndef MAX_PATH
@@ -49521,28 +49552,10 @@
4952149552
static void winMemShutdown(void *pAppData);
4952249553
4952349554
SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void);
4952449555
#endif /* SQLITE_WIN32_MALLOC */
4952549556
49526
-/*
49527
-** The following variable is (normally) set once and never changes
49528
-** thereafter. It records whether the operating system is Win9x
49529
-** or WinNT.
49530
-**
49531
-** 0: Operating system unknown.
49532
-** 1: Operating system is Win9x.
49533
-** 2: Operating system is WinNT.
49534
-**
49535
-** In order to facilitate testing on a WinNT system, the test fixture
49536
-** can manually set this value to 1 to emulate Win98 behavior.
49537
-*/
49538
-#ifdef SQLITE_TEST
49539
-SQLITE_API LONG volatile sqlite3_os_type = 0;
49540
-#else
49541
-static LONG volatile sqlite3_os_type = 0;
49542
-#endif
49543
-
4954449557
#ifndef SYSCALL
4954549558
# define SYSCALL sqlite3_syscall_ptr
4954649559
#endif
4954749560
4954849561
/*
@@ -49890,10 +49903,13 @@
4989049903
{ "cygwin_conv_path", (SYSCALL)0, 0 },
4989149904
#endif
4989249905
#define osCygwin_conv_path ((size_t(*)(unsigned int, \
4989349906
const void *, void *, size_t))aSyscall[58].pCurrent)
4989449907
49908
+ { "GetDriveTypeW", (SYSCALL)GetDriveTypeW, 0 },
49909
+#define osGetDriveTypeW ((UINT(WINAPI*)(LPCWSTR))aSyscall[59].pCurrent)
49910
+
4989549911
}; /* End of the overrideable system calls */
4989649912
4989749913
/*
4989849914
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
4989949915
** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -50060,10 +50076,11 @@
5006050076
sqlite3_mutex_leave(pMainMtx);
5006150077
return rc;
5006250078
}
5006350079
#endif /* SQLITE_WIN32_MALLOC */
5006450080
50081
+#ifdef _WIN32
5006550082
/*
5006650083
** This function outputs the specified (ANSI) string to the Win32 debugger
5006750084
** (if available). Undocumented. Might go away at any moment.
5006850085
*/
5006950086
SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
@@ -50096,10 +50113,11 @@
5009650113
while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
5009750114
TRUE))==WAIT_IO_COMPLETION ){}
5009850115
return rc;
5009950116
}
5010050117
#endif
50118
+#endif /* _WIN32 */
5010150119
5010250120
#ifdef SQLITE_WIN32_MALLOC
5010350121
/*
5010450122
** Allocate nBytes of memory.
5010550123
*/
@@ -50356,10 +50374,11 @@
5035650374
zText = 0;
5035750375
}
5035850376
return zText;
5035950377
}
5036050378
50379
+#ifdef _WIN32
5036150380
/*
5036250381
** Convert an ANSI string to Microsoft Unicode, using the ANSI or OEM
5036350382
** code page.
5036450383
**
5036550384
** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50385,11 +50404,10 @@
5038550404
zMbcsText = 0;
5038650405
}
5038750406
return zMbcsText;
5038850407
}
5038950408
50390
-#ifdef _WIN32
5039150409
/*
5039250410
** Convert a Microsoft Unicode string to a multi-byte character string,
5039350411
** using the ANSI or OEM code page.
5039450412
**
5039550413
** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50413,11 +50431,10 @@
5041350431
sqlite3_free(zText);
5041450432
zText = 0;
5041550433
}
5041650434
return zText;
5041750435
}
50418
-#endif /* _WIN32 */
5041950436
5042050437
/*
5042150438
** Convert a multi-byte character string to UTF-8.
5042250439
**
5042350440
** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50433,11 +50450,10 @@
5043350450
zTextUtf8 = winUnicodeToUtf8(zTmpWide);
5043450451
sqlite3_free(zTmpWide);
5043550452
return zTextUtf8;
5043650453
}
5043750454
50438
-#ifdef _WIN32
5043950455
/*
5044050456
** Convert a UTF-8 string to a multi-byte character string.
5044150457
**
5044250458
** Space to hold the returned string is obtained from sqlite3_malloc().
5044350459
*/
@@ -50483,11 +50499,10 @@
5048350499
#ifndef SQLITE_OMIT_AUTOINIT
5048450500
if( sqlite3_initialize() ) return 0;
5048550501
#endif
5048650502
return winUnicodeToUtf8(zWideText);
5048750503
}
50488
-#endif /* _WIN32 */
5048950504
5049050505
/*
5049150506
** This is a public wrapper for the winMbcsToUtf8() function.
5049250507
*/
5049350508
SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zText){
@@ -50501,11 +50516,10 @@
5050150516
if( sqlite3_initialize() ) return 0;
5050250517
#endif
5050350518
return winMbcsToUtf8(zText, osAreFileApisANSI());
5050450519
}
5050550520
50506
-#ifdef _WIN32
5050750521
/*
5050850522
** This is a public wrapper for the winMbcsToUtf8() function.
5050950523
*/
5051050524
SQLITE_API char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
5051150525
#ifdef SQLITE_ENABLE_API_ARMOR
@@ -50764,17 +50778,17 @@
5076450778
*pError = e;
5076550779
}
5076650780
return 0;
5076750781
}
5076850782
if( winIoerrCanRetry1(e) ){
50769
- sqlite3_win32_sleep(winIoerrRetryDelay*(1+*pnRetry));
50783
+ osSleep(winIoerrRetryDelay*(1+*pnRetry));
5077050784
++*pnRetry;
5077150785
return 1;
5077250786
}
5077350787
#if defined(winIoerrCanRetry2)
5077450788
else if( winIoerrCanRetry2(e) ){
50775
- sqlite3_win32_sleep(winIoerrRetryDelay*(1+*pnRetry));
50789
+ osSleep(winIoerrRetryDelay*(1+*pnRetry));
5077650790
++*pnRetry;
5077750791
return 1;
5077850792
}
5077950793
#endif
5078050794
if( pError ){
@@ -51000,11 +51014,11 @@
5100051014
#endif
5100151015
5100251016
do{
5100351017
rc = osCloseHandle(pFile->h);
5100451018
/* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
51005
- }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
51019
+ }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (osSleep(100), 1) );
5100651020
if( rc ){
5100751021
pFile->h = NULL;
5100851022
}
5100951023
OpenCounter(-1);
5101051024
OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
@@ -51614,11 +51628,11 @@
5161451628
));
5161551629
return rc;
5161651630
}
5161751631
5161851632
cnt--;
51619
- if( cnt>0 ) sqlite3_win32_sleep(1);
51633
+ if( cnt>0 ) osSleep(1);
5162051634
}
5162151635
gotPendingLock = res;
5162251636
}
5162351637
5162451638
/* Acquire a shared lock
@@ -51823,11 +51837,11 @@
5182351837
}
5182451838
}
5182551839
5182651840
/* Forward references to VFS helper methods used for temporary files */
5182751841
static int winGetTempname(sqlite3_vfs *, char **);
51828
-static int winIsDir(const void *);
51842
+static int winIsDir(LPCWSTR);
5182951843
static BOOL winIsLongPathPrefix(const char *);
5183051844
static BOOL winIsDriveLetterAndColon(const char *);
5183151845
5183251846
/*
5183351847
** Control and query of the open file handle.
@@ -52055,15 +52069,14 @@
5205552069
** Note: If the function cygwin_conv_path() fails, only
5205652070
** UTF-8 -> UTF-16 conversion will be done. This can only
5205752071
** happen when the file path >32k, in which case winUtf8ToUnicode()
5205852072
** will fail too.
5205952073
*/
52060
-static void *winConvertFromUtf8Filename(const char *zFilename){
52061
- void *zConverted = 0;
52074
+static LPWSTR winConvertFromUtf8Filename(const char *zFilename){
52075
+ LPWSTR zConverted = 0;
5206252076
#ifdef __CYGWIN__
5206352077
int nChar;
52064
- LPWSTR zWideFilename;
5206552078
5206652079
if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
5206752080
&& winIsDirSep(zFilename[2])) ){
5206852081
i64 nByte;
5206952082
int convertflag = CCP_POSIX_TO_WIN_W;
@@ -52073,24 +52086,23 @@
5207352086
if( nByte>0 ){
5207452087
zConverted = sqlite3MallocZero(12+(u64)nByte);
5207552088
if ( zConverted==0 ){
5207652089
return zConverted;
5207752090
}
52078
- zWideFilename = zConverted;
5207952091
/* Filenames should be prefixed, except when converted
5208052092
* full path already starts with "\\?\". */
5208152093
if( osCygwin_conv_path(convertflag, zFilename,
52082
- zWideFilename+4, nByte)==0 ){
52094
+ zConverted+4, nByte)==0 ){
5208352095
if( (convertflag&CCP_RELATIVE) ){
52084
- memmove(zWideFilename, zWideFilename+4, nByte);
52085
- }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){
52086
- memcpy(zWideFilename, L"\\\\?\\", 8);
52087
- }else if( zWideFilename[6]!='?' ){
52088
- memmove(zWideFilename+6, zWideFilename+4, nByte);
52089
- memcpy(zWideFilename, L"\\\\?\\UNC", 14);
52096
+ memmove(zConverted, zConverted+4, nByte);
52097
+ }else if( memcmp(zConverted+4, L"\\\\", 4) ){
52098
+ memcpy(zConverted, L"\\\\?\\", 8);
52099
+ }else if( zConverted[6]!='?' ){
52100
+ memmove(zConverted+6, zConverted+4, nByte);
52101
+ memcpy(zConverted, L"\\\\?\\UNC", 14);
5209052102
}else{
52091
- memmove(zWideFilename, zWideFilename+4, nByte);
52103
+ memmove(zConverted, zConverted+4, nByte);
5209252104
}
5209352105
return zConverted;
5209452106
}
5209552107
sqlite3_free(zConverted);
5209652108
}
@@ -52097,32 +52109,31 @@
5209752109
}
5209852110
nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
5209952111
if( nChar==0 ){
5210052112
return 0;
5210152113
}
52102
- zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 );
52103
- if( zWideFilename==0 ){
52114
+ zConverted = sqlite3MallocZero( ((u64)nChar+6)*sizeof(WCHAR) );
52115
+ if( zConverted==0 ){
5210452116
return 0;
5210552117
}
5210652118
nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
52107
- zWideFilename, nChar);
52119
+ zConverted, nChar);
5210852120
if( nChar==0 ){
52109
- sqlite3_free(zWideFilename);
52110
- zWideFilename = 0;
52121
+ sqlite3_free(zConverted);
52122
+ zConverted = 0;
5211152123
}else if( nChar>MAX_PATH
5211252124
&& winIsDriveLetterAndColon(zFilename)
5211352125
&& winIsDirSep(zFilename[2]) ){
52114
- memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR));
52115
- zWideFilename[2] = '\\';
52116
- memcpy(zWideFilename, L"\\\\?\\", 8);
52126
+ memmove(zConverted+4, zConverted, nChar*sizeof(WCHAR));
52127
+ zConverted[2] = '\\';
52128
+ memcpy(zConverted, L"\\\\?\\", 8);
5211752129
}else if( nChar>MAX_PATH
5211852130
&& winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
5211952131
&& zFilename[2] != '?' ){
52120
- memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR));
52121
- memcpy(zWideFilename, L"\\\\?\\UNC", 14);
52132
+ memmove(zConverted+6, zConverted, nChar*sizeof(WCHAR));
52133
+ memcpy(zConverted, L"\\\\?\\UNC", 14);
5212252134
}
52123
- zConverted = zWideFilename;
5212452135
#else /* if !defined(__CYGWIN__) */
5212552136
zConverted = winUtf8ToUnicode(zFilename);
5212652137
#endif /* __CYGWIN__ */
5212752138
/* caller will handle out of memory */
5212852139
return zConverted;
@@ -52340,11 +52351,11 @@
5234052351
const char *zUtf8, /* File to open */
5234152352
int *pbReadonly, /* IN/OUT: True for readonly handle */
5234252353
HANDLE *ph /* OUT: New HANDLE for file */
5234352354
){
5234452355
int rc = SQLITE_OK;
52345
- void *zConverted = 0;
52356
+ LPWSTR zConverted = 0;
5234652357
int bReadonly = *pbReadonly;
5234752358
HANDLE h = INVALID_HANDLE_VALUE;
5234852359
5234952360
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
5235052361
const DWORD flag_overlapped = FILE_FLAG_OVERLAPPED;
@@ -52368,11 +52379,11 @@
5236852379
}
5236952380
5237052381
/* TODO: platforms.
5237152382
** TODO: retry-on-ioerr.
5237252383
*/
52373
- h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */
52384
+ h = osCreateFileW(zConverted, /* lpFileName */
5237452385
(GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
5237552386
FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
5237652387
NULL, /* lpSecurityAttributes */
5237752388
OPEN_ALWAYS, /* dwCreationDisposition */
5237852389
FILE_ATTRIBUTE_NORMAL|flag_overlapped,
@@ -52465,10 +52476,27 @@
5246552476
return 1;
5246652477
}
5246752478
}
5246852479
return sqlite3_win_test_unc_locking;
5246952480
}
52481
+
52482
+/*
52483
+** Return true if the string passed in is the name of a file on a
52484
+** remote (network-mounted) volume.
52485
+*/
52486
+static int winIsRemoteVolume(const char *zFile){
52487
+ WCHAR zRoot[4];
52488
+ if( strncmp(zFile, "\\\\?\\",4)==0 ) zFile += 4;
52489
+ if( !sqlite3Isalpha(zFile[0]) ) return 0;
52490
+ if( zFile[1]!=':' ) return 0;
52491
+ if( !winIsDirSep(zFile[2]) ) return 0;
52492
+ zRoot[0] = (WCHAR)zFile[0];
52493
+ zRoot[1] = ':';
52494
+ zRoot[2] = '\\';
52495
+ zRoot[3] = 0;
52496
+ return osGetDriveTypeW(zRoot)==DRIVE_REMOTE;
52497
+}
5247052498
5247152499
/*
5247252500
** Open the shared-memory area associated with database file pDbFd.
5247352501
*/
5247452502
static int winOpenSharedMemory(winFile *pDbFd){
@@ -52491,11 +52519,15 @@
5249152519
return SQLITE_IOERR_NOMEM_BKPT;
5249252520
}
5249352521
pNew->zFilename = (char*)&pNew[1];
5249452522
pNew->hSharedShm = INVALID_HANDLE_VALUE;
5249552523
pNew->isUnlocked = 1;
52496
- pNew->bUseSharedLockHandle = winIsUNCPath(pDbFd->zPath);
52524
+ if( winIsUNCPath(pDbFd->zPath) || winIsRemoteVolume(pDbFd->zPath) ){
52525
+ pNew->bUseSharedLockHandle = 1;
52526
+ }else{
52527
+ pNew->bUseSharedLockHandle = 0;
52528
+ }
5249752529
sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
5249852530
sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
5249952531
5250052532
/* Look to see if there is an existing winShmNode that can be used.
5250152533
** If no matching winShmNode currently exists, then create a new one. */
@@ -53331,11 +53363,11 @@
5333153363
if( !azDirs[1] ) azDirs[1] = osGetenv("TMPDIR");
5333253364
if( !azDirs[2] ) azDirs[2] = osGetenv("TMP");
5333353365
if( !azDirs[3] ) azDirs[3] = osGetenv("TEMP");
5333453366
if( !azDirs[4] ) azDirs[4] = osGetenv("USERPROFILE");
5333553367
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
53336
- void *zConverted;
53368
+ LPWSTR zConverted;
5333753369
if( zDir==0 ) continue;
5333853370
/* If the path starts with a drive letter followed by the colon
5333953371
** character, assume it is already a native Win32 path; otherwise,
5334053372
** it must be converted to a native Win32 path via the Cygwin API
5334153373
** prior to using it.
@@ -53372,16 +53404,15 @@
5337253404
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
5337353405
return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
5337453406
"winGetTempname2", 0);
5337553407
}
5337653408
zMulti = winUnicodeToUtf8(zWidePath);
53409
+ sqlite3_free(zWidePath);
5337753410
if( zMulti ){
5337853411
sqlite3_snprintf(nMax, zBuf, "%s", zMulti);
5337953412
sqlite3_free(zMulti);
53380
- sqlite3_free(zWidePath);
5338153413
}else{
53382
- sqlite3_free(zWidePath);
5338353414
sqlite3_free(zBuf);
5338453415
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
5338553416
return SQLITE_IOERR_NOMEM_BKPT;
5338653417
}
5338753418
}
@@ -53436,18 +53467,18 @@
5343653467
/*
5343753468
** Return TRUE if the named file is really a directory. Return false if
5343853469
** it is something other than a directory, or if there is any kind of memory
5343953470
** allocation failure.
5344053471
*/
53441
-static int winIsDir(const void *zConverted){
53472
+static int winIsDir(LPCWSTR zConverted){
5344253473
DWORD attr;
5344353474
int rc = 0;
5344453475
DWORD lastErrno;
5344553476
int cnt = 0;
5344653477
WIN32_FILE_ATTRIBUTE_DATA sAttrData;
5344753478
memset(&sAttrData, 0, sizeof(sAttrData));
53448
- while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
53479
+ while( !(rc = osGetFileAttributesExW(zConverted,
5344953480
GetFileExInfoStandard,
5345053481
&sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
5345153482
if( !rc ){
5345253483
return 0; /* Invalid name? */
5345353484
}
@@ -53485,11 +53516,11 @@
5348553516
DWORD dwShareMode;
5348653517
DWORD dwCreationDisposition;
5348753518
DWORD dwFlagsAndAttributes = 0;
5348853519
winVfsAppData *pAppData;
5348953520
winFile *pFile = (winFile*)id;
53490
- void *zConverted; /* Filename in OS encoding */
53521
+ LPWSTR zConverted; /* Filename in OS encoding */
5349153522
const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
5349253523
int cnt = 0;
5349353524
int isRO = 0; /* file is known to be accessible readonly */
5349453525
5349553526
/* If argument zPath is a NULL pointer, this function is required to open
@@ -53618,11 +53649,11 @@
5361853649
| FILE_FLAG_DELETE_ON_CLOSE;
5361953650
}else{
5362053651
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
5362153652
}
5362253653
do{
53623
- h = osCreateFileW((LPCWSTR)zConverted,
53654
+ h = osCreateFileW(zConverted,
5362453655
dwDesiredAccess,
5362553656
dwShareMode, NULL,
5362653657
dwCreationDisposition,
5362753658
dwFlagsAndAttributes,
5362853659
NULL);
@@ -53714,11 +53745,11 @@
5371453745
){
5371553746
int cnt = 0;
5371653747
int rc;
5371753748
DWORD attr;
5371853749
DWORD lastErrno = 0;
53719
- void *zConverted;
53750
+ LPWSTR zConverted;
5372053751
UNUSED_PARAMETER(pVfs);
5372153752
UNUSED_PARAMETER(syncDir);
5372253753
5372353754
SimulateIOError(return SQLITE_IOERR_DELETE);
5372453755
OSTRACE(("DELETE name=%s, syncDir=%d\n", zFilename, syncDir));
@@ -53774,11 +53805,11 @@
5377453805
){
5377553806
DWORD attr;
5377653807
int rc = 0;
5377753808
int cnt = 0;
5377853809
DWORD lastErrno = 0;
53779
- void *zConverted;
53810
+ LPWSTR zConverted;
5378053811
int noRetry = 0; /* Do not use winRetryIoerr() */
5378153812
WIN32_FILE_ATTRIBUTE_DATA sAttrData;
5378253813
UNUSED_PARAMETER(pVfs);
5378353814
5378453815
if( (flags & NORETRY)!=0 ){
@@ -53801,11 +53832,11 @@
5380153832
if( zConverted==0 ){
5380253833
OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
5380353834
return SQLITE_IOERR_NOMEM_BKPT;
5380453835
}
5380553836
memset(&sAttrData, 0, sizeof(sAttrData));
53806
- while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
53837
+ while( !(rc = osGetFileAttributesExW(zConverted,
5380753838
GetFileExInfoStandard,
5380853839
&sAttrData))
5380953840
&& !noRetry
5381053841
&& winRetryIoerr(&cnt, &lastErrno)
5381153842
){ /* Loop until true */}
@@ -53983,11 +54014,11 @@
5398354014
const char *zRelative, /* Possibly relative input path */
5398454015
int nFull, /* Size of output buffer in bytes */
5398554016
char *zFull /* Output buffer */
5398654017
){
5398754018
int nByte;
53988
- void *zConverted;
54019
+ LPWSTR zConverted;
5398954020
char *zOut;
5399054021
5399154022
/* If this path name begins with "/X:" or "\\?\", where "X" is any
5399254023
** alphabetic character, discard the initial "/" from the pathname.
5399354024
*/
@@ -54096,23 +54127,23 @@
5409654127
if( zConverted==0 ){
5409754128
return SQLITE_IOERR_NOMEM_BKPT;
5409854129
}
5409954130
{
5410054131
LPWSTR zTemp;
54101
- nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
54132
+ nByte = osGetFullPathNameW(zConverted, 0, 0, 0);
5410254133
if( nByte==0 ){
5410354134
sqlite3_free(zConverted);
5410454135
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
5410554136
"winFullPathname1", zRelative);
5410654137
}
5410754138
nByte += 3;
54108
- zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
54139
+ zTemp = sqlite3MallocZero( (u64)nByte*sizeof(WCHAR) );
5410954140
if( zTemp==0 ){
5411054141
sqlite3_free(zConverted);
5411154142
return SQLITE_IOERR_NOMEM_BKPT;
5411254143
}
54113
- nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
54144
+ nByte = osGetFullPathNameW(zConverted, nByte, zTemp, 0);
5411454145
if( nByte==0 ){
5411554146
sqlite3_free(zConverted);
5411654147
sqlite3_free(zTemp);
5411754148
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
5411854149
"winFullPathname2", zRelative);
@@ -54168,17 +54199,17 @@
5416854199
** Interfaces for opening a shared library, finding entry points
5416954200
** within the shared library, and closing the shared library.
5417054201
*/
5417154202
static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
5417254203
HANDLE h = 0;
54173
- void *zConverted = winConvertFromUtf8Filename(zFilename);
54204
+ LPWSTR zConverted = winConvertFromUtf8Filename(zFilename);
5417454205
UNUSED_PARAMETER(pVfs);
5417554206
if( zConverted==0 ){
5417654207
OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
5417754208
return 0;
5417854209
}
54179
- h = osLoadLibraryW ? osLoadLibraryW((LPCWSTR)zConverted) : 0;
54210
+ h = osLoadLibraryW ? osLoadLibraryW(zConverted) : 0;
5418054211
OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
5418154212
sqlite3_free(zConverted);
5418254213
return (void*)h;
5418354214
}
5418454215
static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
@@ -54282,11 +54313,11 @@
5428254313
5428354314
/*
5428454315
** Sleep for a little while. Return the amount of time slept.
5428554316
*/
5428654317
static int winSleep(sqlite3_vfs *pVfs, int microsec){
54287
- sqlite3_win32_sleep((microsec+999)/1000);
54318
+ osSleep((microsec+999)/1000);
5428854319
UNUSED_PARAMETER(pVfs);
5428954320
return ((microsec+999)/1000)*1000;
5429054321
}
5429154322
5429254323
/*
@@ -54489,11 +54520,11 @@
5448954520
winNextSystemCall, /* xNextSystemCall */
5449054521
};
5449154522
5449254523
/* Double-check that the aSyscall[] array has been constructed
5449354524
** correctly. See ticket [bb3a86e890c8e96ab] */
54494
- assert( ArraySize(aSyscall)==59 );
54525
+ assert( ArraySize(aSyscall)==60 );
5449554526
assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
5449654527
assert( strcmp(aSyscall[8].zName,"FreeLibrary")==0 );
5449754528
assert( strcmp(aSyscall[16].zName,"GetSystemInfo")==0 );
5449854529
assert( strcmp(aSyscall[24].zName,"HeapReAlloc")==0 );
5449954530
assert( strcmp(aSyscall[32].zName,"MapViewOfFileFromApp")==0 );
@@ -58880,10 +58911,14 @@
5888058911
#endif
5888158912
5888258913
#ifdef SQLITE_USE_SEH
5888358914
SQLITE_PRIVATE int sqlite3WalSystemErrno(Wal*);
5888458915
#endif
58916
+
58917
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
58918
+SQLITE_PRIVATE void sqlite3WalStat(Wal*,sqlite3_str*);
58919
+#endif
5888558920
5888658921
#endif /* ifndef SQLITE_OMIT_WAL */
5888758922
#endif /* SQLITE_WAL_H */
5888858923
5888958924
/************** End of wal.h *************************************************/
@@ -65755,10 +65790,24 @@
6575565790
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
6575665791
return sqlite3PcacheRefCount(pPager->pPCache);
6575765792
}
6575865793
#endif
6575965794
65795
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
65796
+/*
65797
+** Append JSON structure elements describing the current state of
65798
+** the write-ahead log to pStr.
65799
+*/
65800
+SQLITE_PRIVATE void sqlite3PagerWalStat(Pager *pPager, sqlite3_str *pStr){
65801
+#ifndef SQLITE_OMIT_WAL
65802
+ if( pPager->pWal ){
65803
+ sqlite3WalStat(pPager->pWal, pStr);
65804
+ }
65805
+#endif
65806
+}
65807
+#endif
65808
+
6576065809
/*
6576165810
** Return the approximate number of bytes of memory currently
6576265811
** used by the pager and its associated cache.
6576365812
*/
6576465813
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
@@ -67351,14 +67400,45 @@
6735167400
** walIteratorInit() - Create a new iterator,
6735267401
** walIteratorNext() - Step an iterator,
6735367402
** walIteratorFree() - Free an iterator.
6735467403
**
6735567404
** This functionality is used by the checkpoint code (see walCheckpoint()).
67405
+**
67406
+** There are two possible algorithms:
67407
+**
67408
+** WALITER-1 Load all pages mentioned in the WAL file and sort them,
67409
+** then hand them back out in sorted order as requested by
67410
+** walIteratorNext(). nPagemap==0 for this algorithm.
67411
+**
67412
+** WALITER-2 Create a map of all database file pages and record the
67413
+** last WAL file frame that updates that page. Then walk
67414
+** through the map in acsending order and return all
67415
+** non-zero entries. nPagemap is positive for this algorithm.
67416
+**
67417
+** Either algorithm should work for any database and WAL file, however
67418
+** algorithm WALITER-1 is faster and uses less memory when the database is
67419
+** larger than the WAL file and algorithm WALITER-2 is faster and uses
67420
+** less memory when the WAL file is larger than the database, modulo a
67421
+** constant of proportionality. The walIteratorInit() routine selects
67422
+** the best algorithm for each situation. WALITER-2 was added for
67423
+** SQLite 3.54.0. Prior to that, WALITER-1 was used always.
67424
+**
67425
+** For algorithm WALITER-2, nPagemap stores the number of pages in the
67426
+** database file, nSegment==1, and aSegment[0].aPgno[] is the page map array
67427
+** that is nPagemap+1 entries in length. The value of aSegment[0].aPgno[PGNO]
67428
+** is the frame number of the last (newest) entry for page PGNO in the WAL
67429
+** file, or 0 if PGNO is not in the WAL file. (Aside: There is no page
67430
+** number 0 in a well-formed database, so the memory allocation is arranged
67431
+** such that aSegment[0].aPgno[0] and aSegment[0].iZero are aliases for the
67432
+** same four bits of memory. This saves us from having to use -1 and +1
67433
+** offsets to translate between 1-based SQLite page numbers and 0-based
67434
+** C-language index numbers. tag-20260903-1)
6735667435
*/
6735767436
struct WalIterator {
6735867437
u32 iPrior; /* Last result returned from the iterator */
6735967438
int nSegment; /* Number of entries in aSegment[] */
67439
+ u32 nPagemap; /* Non-zero in "page-map" mode */
6736067440
struct WalSegment {
6736167441
int iNext; /* Next slot in aIndex[] not yet returned */
6736267442
ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
6736367443
u32 *aPgno; /* Array of page numbers. */
6736467444
int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
@@ -67367,10 +67447,11 @@
6736767447
};
6736867448
6736967449
/* Size (in bytes) of a WalIterator object suitable for N or fewer segments */
6737067450
#define SZ_WALITERATOR(N) \
6737167451
(offsetof(WalIterator,aSegment)+(N)*sizeof(struct WalSegment))
67452
+
6737267453
6737367454
/*
6737467455
** Define the parameters of the hash tables in the wal-index file. There
6737567456
** is a hash-table following every HASHTABLE_NPAGE page numbers in the
6737667457
** wal-index.
@@ -68530,28 +68611,42 @@
6853068611
static int walIteratorNext(
6853168612
WalIterator *p, /* Iterator */
6853268613
u32 *piPage, /* OUT: The page number of the next page */
6853368614
u32 *piFrame /* OUT: Wal frame index of next page */
6853468615
){
68535
- u32 iMin; /* Result pgno must be greater than iMin */
6853668616
u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
68537
- int i; /* For looping through segments */
68538
-
68539
- iMin = p->iPrior;
68540
- assert( iMin<0xffffffff );
68541
- for(i=p->nSegment-1; i>=0; i--){
68542
- struct WalSegment *pSegment = &p->aSegment[i];
68543
- while( pSegment->iNext<pSegment->nEntry ){
68544
- u32 iPg = pSegment->aPgno[pSegment->aIndex[pSegment->iNext]];
68545
- if( iPg>iMin ){
68546
- if( iPg<iRet ){
68547
- iRet = iPg;
68548
- *piFrame = pSegment->iZero + pSegment->aIndex[pSegment->iNext];
68549
- }
68617
+
68618
+ if( p->nPagemap ){
68619
+ /* Algorithm WALITER-2 */
68620
+ while( p->iPrior<p->nPagemap ){
68621
+ p->iPrior++;
68622
+ if( p->aSegment[0].aPgno[p->iPrior] ){
68623
+ iRet = p->iPrior;
68624
+ *piFrame = p->aSegment[0].aPgno[p->iPrior];
6855068625
break;
6855168626
}
68552
- pSegment->iNext++;
68627
+ }
68628
+ }else{
68629
+ /* Algorithm WALITER-1 */
68630
+ u32 iMin; /* Result pgno must be greater than iMin */
68631
+ int i; /* For looping through segments */
68632
+
68633
+ iMin = p->iPrior;
68634
+ assert( iMin<0xffffffff );
68635
+ for(i=p->nSegment-1; i>=0; i--){
68636
+ struct WalSegment *pSegment = &p->aSegment[i];
68637
+ while( pSegment->iNext<pSegment->nEntry ){
68638
+ u32 iPg = pSegment->aPgno[pSegment->aIndex[pSegment->iNext]];
68639
+ if( iPg>iMin ){
68640
+ if( iPg<iRet ){
68641
+ iRet = iPg;
68642
+ *piFrame = pSegment->iZero + pSegment->aIndex[pSegment->iNext];
68643
+ }
68644
+ break;
68645
+ }
68646
+ pSegment->iNext++;
68647
+ }
6855368648
}
6855468649
}
6855568650
6855668651
*piPage = p->iPrior = iRet;
6855768652
return (iRet==0xFFFFFFFF);
@@ -68716,63 +68811,99 @@
6871668811
**
6871768812
** The calling routine should invoke walIteratorFree() to destroy the
6871868813
** WalIterator object when it has finished with it.
6871968814
*/
6872068815
static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
68816
+ int iFirstPage; /* First 32KB *-shm page to visit */
68817
+ int iLastPage; /* Last 32KB *-shm page to visit */
68818
+ u32 iZero; /* Frame before first frame to visit */
6872168819
WalIterator *p; /* Return value */
6872268820
int nSegment; /* Number of segments to merge */
6872368821
u32 iLast; /* Last frame in log */
6872468822
sqlite3_int64 nByte; /* Number of bytes to allocate */
68823
+ sqlite3_int64 nExtra; /* Number of bytes to allocate */
6872568824
int i; /* Iterator variable */
68726
- ht_slot *aTmp; /* Temp space used by merge-sort */
68825
+ ht_slot *aTmp = 0; /* Temp space used by merge-sort */
6872768826
int rc = SQLITE_OK; /* Return Code */
68827
+ int eAlg; /* Which algorithm to use. 1 or 2 */
6872868828
6872968829
/* This routine only runs while holding the checkpoint lock. And
68730
- ** it only runs if there is actually content in the log (mxFrame>0).
68731
- */
68830
+ ** it only runs if there is actually content in the log (mxFrame>0). */
6873268831
assert( pWal->ckptLock && pWal->hdr.mxFrame>0 );
68832
+
6873368833
iLast = pWal->hdr.mxFrame;
68834
+ iFirstPage = walFramePage(nBackfill+1);
68835
+ iLastPage = walFramePage(iLast);
68836
+ iZero = iFirstPage ? (HASHTABLE_NPAGE_ONE+(iFirstPage-1)*HASHTABLE_NPAGE) : 0;
68837
+
68838
+ if( (iLast-iZero)*sizeof(ht_slot)>pWal->hdr.nPage*sizeof(u32) ){
68839
+ /* Algorithm WALITER-2 */
68840
+ nSegment = 1;
68841
+ eAlg = 2;
68842
+ nByte = SZ_WALITERATOR(nSegment) + pWal->hdr.nPage * sizeof(u32);
68843
+ nExtra = 0;
68844
+ }else{
68845
+ /* Algorithm WALITER-1 */
68846
+ nSegment = iLastPage - iFirstPage + 1;
68847
+ eAlg = 1;
68848
+ nByte = SZ_WALITERATOR(nSegment) + (iLast-iZero)*sizeof(ht_slot);
68849
+ nExtra = sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast);
68850
+ }
6873468851
6873568852
/* Allocate space for the WalIterator object. */
68736
- nSegment = walFramePage(iLast) + 1;
68737
- nByte = SZ_WALITERATOR(nSegment)
68738
- + iLast*sizeof(ht_slot);
68739
- p = (WalIterator *)sqlite3_malloc64(nByte
68740
- + sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
68741
- );
68853
+ p = (WalIterator *)sqlite3_malloc64(nByte + nExtra);
6874268854
if( !p ){
6874368855
return SQLITE_NOMEM_BKPT;
6874468856
}
6874568857
memset(p, 0, nByte);
6874668858
p->nSegment = nSegment;
68747
- aTmp = (ht_slot*)&(((u8*)p)[nByte]);
68859
+ if( eAlg==2 ){
68860
+ p->nPagemap = pWal->hdr.nPage;
68861
+ p->aSegment[0].aPgno = ((u32*)&p->aSegment[1]) - 1;
68862
+ assert( (u8*)&(p->aSegment[0].aPgno[0]) == (u8*)&(p->aSegment[0].iZero) );
68863
+ /* ^-- verifies tag-20260903-1 */
68864
+ }else{
68865
+ aTmp = (ht_slot*)&(((u8*)p)[nByte]);
68866
+ }
6874868867
SEH_FREE_ON_ERROR(0, p);
68749
- for(i=walFramePage(nBackfill+1); rc==SQLITE_OK && i<nSegment; i++){
68868
+ for(i=iFirstPage; rc==SQLITE_OK && i<=iLastPage; i++){
6875068869
WalHashLoc sLoc;
6875168870
6875268871
rc = walHashGet(pWal, i, &sLoc);
6875368872
if( rc==SQLITE_OK ){
6875468873
int j; /* Counter variable */
6875568874
int nEntry; /* Number of entries in this segment */
6875668875
ht_slot *aIndex; /* Sorted index for this segment */
6875768876
68758
- if( (i+1)==nSegment ){
68877
+ if( i==iLastPage ){
6875968878
nEntry = (int)(iLast - sLoc.iZero);
6876068879
}else{
6876168880
nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno);
6876268881
}
68763
- aIndex = &((ht_slot *)&p->aSegment[p->nSegment])[sLoc.iZero];
68764
- sLoc.iZero++;
68765
-
68766
- for(j=0; j<nEntry; j++){
68767
- aIndex[j] = (ht_slot)j;
68768
- }
68769
- walMergesort((u32 *)sLoc.aPgno, aTmp, aIndex, &nEntry);
68770
- p->aSegment[i].iZero = sLoc.iZero;
68771
- p->aSegment[i].nEntry = nEntry;
68772
- p->aSegment[i].aIndex = aIndex;
68773
- p->aSegment[i].aPgno = (u32 *)sLoc.aPgno;
68882
+
68883
+ if( eAlg==2 ){
68884
+ u32 *aPagemap = p->aSegment[0].aPgno;
68885
+ for(j=0; j<nEntry; j++){
68886
+ u32 pgno = sLoc.aPgno[ j ];
68887
+ if( pgno<=p->nPagemap ){
68888
+ aPagemap[pgno] = sLoc.iZero + j + 1;
68889
+ }
68890
+ }
68891
+ }else{
68892
+ assert( i!=iFirstPage || iZero==sLoc.iZero );
68893
+ aIndex = &((ht_slot *)&p->aSegment[p->nSegment])[sLoc.iZero - iZero];
68894
+ sLoc.iZero++;
68895
+
68896
+ for(j=0; j<nEntry; j++){
68897
+ aIndex[j] = (ht_slot)j;
68898
+ }
68899
+ walMergesort((u32 *)sLoc.aPgno, aTmp, aIndex, &nEntry);
68900
+ p->aSegment[i-iFirstPage].iZero = sLoc.iZero;
68901
+ p->aSegment[i-iFirstPage].nEntry = nEntry;
68902
+ p->aSegment[i-iFirstPage].aIndex = aIndex;
68903
+ p->aSegment[i-iFirstPage].aPgno = (u32 *)sLoc.aPgno;
68904
+ }
6877468905
}
6877568906
}
6877668907
if( rc!=SQLITE_OK ){
6877768908
SEH_FREE_ON_ERROR(p, 0);
6877868909
walIteratorFree(p);
@@ -71409,10 +71540,68 @@
7140971540
/* Return the sqlite3_file object for the WAL file
7141071541
*/
7141171542
SQLITE_PRIVATE sqlite3_file *sqlite3WalFile(Wal *pWal){
7141271543
return pWal->pWalFd;
7141371544
}
71545
+
71546
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
71547
+/*
71548
+** Helper function to sqlite3WalStat().
71549
+**
71550
+** Append JSON-5 structure elements onto describing the current state
71551
+** of pWal onto the end of pStr. This function is for debugging and
71552
+** analysis only and is not included in production builds.
71553
+*/
71554
+static void walIndexHdrStat(volatile WalIndexHdr *pHdr, sqlite3_str *pStr){
71555
+ sqlite3_str_appendf(pStr, "iVersion:%u",pHdr->iVersion);
71556
+ sqlite3_str_appendf(pStr, ",iChange:%u",pHdr->iChange);
71557
+ sqlite3_str_appendf(pStr, ",isInit:%u",pHdr->isInit);
71558
+ sqlite3_str_appendf(pStr, ",bigEndCksum:%u",pHdr->bigEndCksum);
71559
+ sqlite3_str_appendf(pStr, ",szPage:%u",pHdr->szPage);
71560
+ sqlite3_str_appendf(pStr, ",mxFrame:%u",pHdr->mxFrame);
71561
+ sqlite3_str_appendf(pStr, ",nPage:%u",pHdr->nPage);
71562
+#if 0 /* Not often needed. Declutter. */
71563
+ sqlite3_str_appendf(pStr, ",aFrameCksum:[0x%08x,0x%08x]",
71564
+ pHdr->aFrameCksum[0], pHdr->aFrameCksum[1]);
71565
+ sqlite3_str_appendf(pStr, ",aSalt:[0x%08x,0x%08x]",
71566
+ pHdr->aSalt[0], pHdr->aSalt[1]);
71567
+ sqlite3_str_appendf(pStr, ",aCksum:[0x%08x,0x%08x]",
71568
+ pHdr->aCksum[0], pHdr->aCksum[1]);
71569
+#endif
71570
+}
71571
+#endif /* SQLITE_DEBUG || SQLITE_ENABLE_WALSTAT */
71572
+
71573
+
71574
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
71575
+/*
71576
+** Append JSON-5 structure elements onto describing the current state
71577
+** of pWal onto the end of pStr. This function is for debugging and
71578
+** analysis only and is not included in production builds.
71579
+*/
71580
+SQLITE_PRIVATE void sqlite3WalStat(Wal *pWal, sqlite3_str *pStr){
71581
+ SEH_TRY {
71582
+ int i;
71583
+ volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
71584
+ volatile WalIndexHdr *pHdr = walIndexHdr(pWal);
71585
+ sqlite3_str_appendf(pStr, "hdr0:{");
71586
+ walIndexHdrStat(pHdr,pStr);
71587
+ sqlite3_str_appendf(pStr, "},ckpt:{");
71588
+ sqlite3_str_appendf(pStr, "nBackfill:%u",pInfo->nBackfill);
71589
+ sqlite3_str_appendf(pStr, ",aReadMark:[%u", pInfo->aReadMark[0]);
71590
+ for(i=1; i<WAL_NREADER; i++){
71591
+ sqlite3_str_appendf(pStr, ",%u", pInfo->aReadMark[i]);
71592
+ }
71593
+ sqlite3_str_appendf(pStr, "],nBackfillAttempted:%u}",
71594
+ pInfo->nBackfillAttempted);
71595
+
71596
+ sqlite3_str_appendf(pStr, ",nWiData:%d", pWal->nWiData);
71597
+ sqlite3_str_appendf(pStr, ",readLock:%d", pWal->readLock);
71598
+ sqlite3_str_appendf(pStr, ",minFrame:%u", pWal->minFrame);
71599
+ }
71600
+ SEH_EXCEPT( ; )
71601
+}
71602
+#endif /* SQLITE_DEBUG || SQLITE_ENABLE_WALSTAT */
7141471603
7141571604
#endif /* #ifndef SQLITE_OMIT_WAL */
7141671605
7141771606
/************** End of wal.c *************************************************/
7141871607
/************** Begin file btmutex.c *****************************************/
@@ -74646,11 +74835,11 @@
7464674835
}
7464774836
next = get2byte(&data[pc]);
7464874837
size = get2byte(&data[pc+2]);
7464974838
if( size<4 && sqlite3FaultSim(422)==SQLITE_OK ){
7465074839
/* Minimum freeblock size is 4. Enable fault-sim 422 to disable this
74651
- ** check to reach interesting error stats. However, disabling this
74840
+ ** check to reach interesting error states. However, disabling this
7465274841
** check can cause assertion faults due to min-heap overflow. All
7465374842
** fault-sims are for testing use only, but this one especially so. */
7465474843
return SQLITE_CORRUPT_PAGE(pPage);
7465574844
}
7465674845
nFree = nFree + size;
@@ -82907,10 +83096,13 @@
8290783096
if( rc!=SQLITE_OK ){
8290883097
return rc;
8290983098
}
8291083099
pMove = 0;
8291183100
rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
83101
+ if( rc==SQLITE_OK ){
83102
+ rc = sqlite3PagerWrite(pMove->pDbPage);
83103
+ }
8291283104
freePage(pMove, &rc);
8291383105
releasePage(pMove);
8291483106
if( rc!=SQLITE_OK ){
8291583107
return rc;
8291683108
}
@@ -83727,13 +83919,13 @@
8372783919
sCheck.aPgRef = sqlite3MallocZero((sCheck.nCkPage / 8)+ 1);
8372883920
if( !sCheck.aPgRef ){
8372983921
checkOom(&sCheck);
8373083922
goto integrity_ck_cleanup;
8373183923
}
83732
- sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
83924
+ sCheck.heap = (u32*)sqlite3Malloc( pBt->pageSize*2 );
8373383925
#ifdef SQLITE_DEBUG
83734
- sCheck.mxHeap = pBt->pageSize/4 - 1;
83926
+ sCheck.mxHeap = pBt->pageSize/2 - 1;
8373583927
#endif
8373683928
if( sCheck.heap==0 ){
8373783929
checkOom(&sCheck);
8373883930
goto integrity_ck_cleanup;
8373983931
}
@@ -83817,11 +84009,11 @@
8381784009
}
8381884010
8381984011
/* Clean up and report errors.
8382084012
*/
8382184013
integrity_ck_cleanup:
83822
- sqlite3PageFree(sCheck.heap);
84014
+ sqlite3_free(sCheck.heap);
8382384015
sqlite3_free(sCheck.aPgRef);
8382484016
*pnErr = sCheck.nErr;
8382584017
if( sCheck.nErr==0 ){
8382684018
sqlite3_str_reset(&sCheck.errMsg);
8382784019
*pzOut = 0;
@@ -86925,11 +87117,11 @@
8692587117
if( pExpr ){
8692687118
rc = valueFromExpr(db, pExpr, enc, affinity, &pVal, 0);
8692787119
if( rc==SQLITE_OK && pVal
8692887120
&& affinity==SQLITE_AFF_REAL
8692987121
&& (pVal->flags & MEM_Int)
86930
- && (u64)(pVal->u.i<0 ? pVal->u.i : pVal->u.i)>140737488355327LL
87122
+ && (pVal->u.i<-140737488355328LL || pVal->u.i>140737488355327LL)
8693187123
){
8693287124
/* If the integer value is too large to fit in a 6-byte integer and
8693387125
** the affinity is REAL, convert it to a real value now. In most
8693487126
** cases an OP_RealAffinity opcode will be used to convert the
8693587127
** value to an actual real, but this opcode is omitted if the values
@@ -92336,11 +92528,11 @@
9233692528
}
9233792529
testcase( flags & MEM_Real );
9233892530
testcase( flags & MEM_Null );
9233992531
testcase( flags & MEM_Blob );
9234092532
if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0
92341
- && p->pKeyInfo->aColl[0]==0
92533
+ && sqlite3IsBinary(p->pKeyInfo->aColl[0])
9234292534
){
9234392535
assert( flags & MEM_Str );
9234492536
p->u.z = p->aMem[0].z;
9234592537
p->n = p->aMem[0].n;
9234692538
return vdbeRecordCompareString;
@@ -101668,11 +101860,13 @@
101668101860
if( x.flags & MEM_Int ){
101669101861
iKey = x.u.i;
101670101862
}else
101671101863
if( (x.flags & MEM_Real)==0
101672101864
|| x.u.r < -9223372036854775808.0
101673
- || x.u.r > 9223372036854775807.0
101865
+ || x.u.r > 9223372036854774784.0
101866
+ /* ^^^^^^^^^^^^^^^^^^^^^-- same value as every other double
101867
+ ** between 9223372036854774263.0 and 923372036854775295.0 */
101674101868
|| (double)(iKey = sqlite3RealToI64(x.u.r))!=x.u.r
101675101869
){
101676101870
goto jump_to_p2;
101677101871
}
101678101872
goto notExistsWithKey;
@@ -102352,18 +102546,21 @@
102352102546
}
102353102547
pOut->u.i = v;
102354102548
break;
102355102549
}
102356102550
102357
-/* Opcode: NullRow P1 * * * *
102551
+/* Opcode: NullRow P1 P2 * * *
102358102552
**
102359
-** Move the cursor P1 to a null row. Any OP_Column operations
102553
+** Move the cursor P1 to a null row if P2 is 0. Any OP_Column operations
102360102554
** that occur while the cursor is on the null row will always
102361102555
** write a NULL.
102362102556
**
102363102557
** If cursor P1 is not previously opened, open it now to a special
102364102558
** pseudo-cursor that always returns NULL for every column.
102559
+**
102560
+** If P2 is not 0, then the nullRow flag on the pseudo-cursor is
102561
+** turned off.
102365102562
*/
102366102563
case OP_NullRow: {
102367102564
VdbeCursor *pC;
102368102565
102369102566
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -102376,11 +102573,11 @@
102376102573
pC->seekResult = 0;
102377102574
pC->isTable = 1;
102378102575
pC->noReuse = 1;
102379102576
pC->uc.pCursor = sqlite3BtreeFakeValidCursor();
102380102577
}
102381
- pC->nullRow = 1;
102578
+ pC->nullRow = (pOp->p2==0);
102382102579
pC->cacheStatus = CACHE_STALE;
102383102580
if( pC->eCurType==CURTYPE_BTREE ){
102384102581
assert( pC->uc.pCursor!=0 );
102385102582
sqlite3BtreeClearCursor(pC->uc.pCursor);
102386102583
}
@@ -120900,10 +121097,11 @@
120900121097
/* Verify that constraints are still satisfied */
120901121098
if( pNew->pCheck!=0
120902121099
|| (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
120903121100
|| (pTab->tabFlags & TF_Strict)!=0
120904121101
){
121102
+ pParse->colNamesSet = 1;
120905121103
sqlite3NestedParse(pParse,
120906121104
"SELECT CASE WHEN quick_check GLOB 'CHECK*'"
120907121105
" THEN raise(ABORT,'CHECK constraint failed')"
120908121106
" WHEN quick_check GLOB 'non-* value in*'"
120909121107
" THEN raise(ABORT,'type mismatch on DEFAULT')"
@@ -134337,11 +134535,11 @@
134337134535
}
134338134536
if( argc==3 ){
134339134537
p2 = sqlite3_value_int64(argv[2]);
134340134538
if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
134341134539
}else{
134342
- p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
134540
+ p2 = LARGEST_INT64;
134343134541
}
134344134542
if( p1==0 ){
134345134543
#ifdef SQLITE_SUBSTR_COMPATIBILITY
134346134544
/* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
134347134545
** as substr(X,1,N) - it returns the first N characters of X. This
@@ -135776,10 +135974,25 @@
135776135974
sqlite3_result_text(context, "?000", 4, SQLITE_STATIC);
135777135975
}
135778135976
}
135779135977
#endif /* SQLITE_SOUNDEX */
135780135978
135979
+#if defined(SQLITE_DEBUG) || defined(SQLITE_BUILTIN_OOM_FUNCTION)
135980
+/*
135981
+** This SQL function just invokes sqlite3OomFault() and then returns
135982
+** NULL. Used for testing only.
135983
+*/
135984
+static void oomFunc(
135985
+ sqlite3_context *context,
135986
+ int argc,
135987
+ sqlite3_value **argv
135988
+){
135989
+ sqlite3 *db = sqlite3_context_db_handle(context);
135990
+ sqlite3OomFault(db);
135991
+}
135992
+#endif /* SQLITE_DEBUG || SQLITE_BUILTIN_OOM_FUNCTION */
135993
+
135781135994
#ifndef SQLITE_OMIT_LOAD_EXTENSION
135782135995
/*
135783135996
** A function that loads a shared-library extension then returns NULL.
135784135997
*/
135785135998
static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
@@ -137146,10 +137359,52 @@
137146137359
sqlite3_result_text(context, "{}", 2, SQLITE_STATIC);
137147137360
}
137148137361
}
137149137362
#endif /* SQLITE_DEBUG || SQLITE_ENABLE_FILESTAT */
137150137363
137364
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
137365
+/*
137366
+** Implementation of sqlite_walstat(SCHEMA).
137367
+**
137368
+** Return JSON text that describes the current state of a WAL file.
137369
+** This function is for debugging and analysis only. It is not part
137370
+** of production builds. This function is not part of the SQLite API
137371
+** and is likely to change or be removed in future versions of SQLite.
137372
+*/
137373
+static void walstatFunc(
137374
+ sqlite3_context *context,
137375
+ int argc,
137376
+ sqlite3_value **argv
137377
+){
137378
+ sqlite3 *db = sqlite3_context_db_handle(context);
137379
+ const char *zDbName;
137380
+ sqlite3_str *pStr;
137381
+ Btree *pBtree;
137382
+
137383
+ zDbName = (const char*)sqlite3_value_text(argv[0]);
137384
+ pBtree = sqlite3DbNameToBtree(db, zDbName);
137385
+ if( pBtree ){
137386
+ Pager *pPager;
137387
+ sqlite3BtreeEnter(pBtree);
137388
+ pPager = sqlite3BtreePager(pBtree);
137389
+ assert( pPager!=0 );
137390
+ pStr = sqlite3_str_new(db);
137391
+ if( sqlite3_str_errcode(pStr) ){
137392
+ sqlite3_result_error_nomem(context);
137393
+ }else{
137394
+ sqlite3_str_append(pStr, "{", 1);
137395
+ sqlite3PagerWalStat(pPager, pStr);
137396
+ sqlite3_str_append(pStr, "}", 1);
137397
+ sqlite3_result_str(context, pStr, SQLITE_FINISH);
137398
+ }
137399
+ sqlite3BtreeLeave(pBtree);
137400
+ }else{
137401
+ sqlite3_result_text(context, "{}", 2, SQLITE_STATIC);
137402
+ }
137403
+}
137404
+#endif /* SQLITE_DEBUG || SQLITE_ENABLE_WALSTAT */
137405
+
137151137406
#ifdef SQLITE_DEBUG
137152137407
/*
137153137408
** Implementation of fpdecode(x,y,z) function.
137154137409
**
137155137410
** x is a real number that is to be decoded. y is the precision.
@@ -137306,10 +137561,11 @@
137306137561
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
137307137562
INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
137308137563
#endif
137309137564
#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_FILESTAT)
137310137565
FUNCTION(sqlite_filestat, 1, 0, 0, filestatFunc ),
137566
+ FUNCTION(sqlite_walstat, 1, 0, 0, walstatFunc ),
137311137567
#endif
137312137568
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
137313137569
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
137314137570
FUNCTION(rtrim, 1, 2, 0, trimFunc ),
137315137571
FUNCTION(rtrim, 2, 2, 0, trimFunc ),
@@ -137333,10 +137589,13 @@
137333137589
FUNCTION(char, -1, 0, 0, charFunc ),
137334137590
FUNCTION(abs, 1, 0, 0, absFunc ),
137335137591
#ifdef SQLITE_DEBUG
137336137592
FUNCTION(fpdecode, 3, 0, 0, fpdecodeFunc ),
137337137593
FUNCTION(parseuri, -1, 0, 0, parseuriFunc ),
137594
+#endif
137595
+#if defined(SQLITE_DEBUG) || defined(SQLITE_BUILTIN_OOM_FUNCTION)
137596
+ FUNCTION(oom, -1, 0, 0, oomFunc ),
137338137597
#endif
137339137598
#ifndef SQLITE_OMIT_FLOATING_POINT
137340137599
FUNCTION(round, 1, 0, 0, roundFunc ),
137341137600
FUNCTION(round, 2, 0, 0, roundFunc ),
137342137601
#endif
@@ -142714,11 +142973,11 @@
142714142973
void (*interruptx)(sqlite3*);
142715142974
sqlite_int64 (*last_insert_rowid)(sqlite3*);
142716142975
const char * (*libversion)(void);
142717142976
int (*libversion_number)(void);
142718142977
void *(*malloc)(int);
142719
- char * (*mprintf)(const char*,...);
142978
+ char *(SQLITE_CDECL*mprintf)(const char*,...);
142720142979
int (*open)(const char*,sqlite3**);
142721142980
int (*open16)(const void*,sqlite3**);
142722142981
int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
142723142982
int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
142724142983
void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
@@ -142735,15 +142994,15 @@
142735142994
void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
142736142995
void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
142737142996
void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
142738142997
void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
142739142998
void (*result_value)(sqlite3_context*,sqlite3_value*);
142740
- void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
142999
+ void *(*rollback_hook)(sqlite3*,void(*)(void*),void*);
142741143000
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
142742143001
const char*,const char*),void*);
142743143002
void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
142744
- char * (*xsnprintf)(int,char*,const char*,...);
143003
+ char *(SQLITE_CDECL*xsnprintf)(int,char*,const char*,...);
142745143004
int (*step)(sqlite3_stmt*);
142746143005
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
142747143006
char const**,char const**,int*,int*,int*);
142748143007
void (*thread_cleanup)(void);
142749143008
int (*total_changes)(sqlite3*);
@@ -142803,11 +143062,11 @@
142803143062
int (*vfs_register)(sqlite3_vfs*,int);
142804143063
int (*vfs_unregister)(sqlite3_vfs*);
142805143064
int (*xthreadsafe)(void);
142806143065
void (*result_zeroblob)(sqlite3_context*,int);
142807143066
void (*result_error_code)(sqlite3_context*,int);
142808
- int (*test_control)(int, ...);
143067
+ int (SQLITE_CDECL*test_control)(int, ...);
142809143068
void (*randomness)(int,void*);
142810143069
sqlite3 *(*context_db_handle)(sqlite3_context*);
142811143070
int (*extended_result_codes)(sqlite3*,int);
142812143071
int (*limit)(sqlite3*,int,int);
142813143072
sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
@@ -142823,25 +143082,25 @@
142823143082
int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
142824143083
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
142825143084
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
142826143085
void (*xFinal)(sqlite3_context*),
142827143086
void(*xDestroy)(void*));
142828
- int (*db_config)(sqlite3*,int,...);
143087
+ int (SQLITE_CDECL*db_config)(sqlite3*,int,...);
142829143088
sqlite3_mutex *(*db_mutex)(sqlite3*);
142830143089
int (*db_status)(sqlite3*,int,int*,int*,int);
142831143090
int (*extended_errcode)(sqlite3*);
142832
- void (*log)(int,const char*,...);
143091
+ void (SQLITE_CDECL*log)(int,const char*,...);
142833143092
sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
142834143093
const char *(*sourceid)(void);
142835143094
int (*stmt_status)(sqlite3_stmt*,int,int);
142836143095
int (*strnicmp)(const char*,const char*,int);
142837143096
int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
142838143097
int (*wal_autocheckpoint)(sqlite3*,int);
142839143098
int (*wal_checkpoint)(sqlite3*,const char*);
142840143099
void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
142841143100
int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
142842
- int (*vtab_config)(sqlite3*,int op,...);
143101
+ int (SQLITE_CDECL*vtab_config)(sqlite3*,int op,...);
142843143102
int (*vtab_on_conflict)(sqlite3*);
142844143103
/* Version 3.7.16 and later */
142845143104
int (*close_v2)(sqlite3*);
142846143105
const char *(*db_filename)(sqlite3*,const char*);
142847143106
int (*db_readonly)(sqlite3*,const char*);
@@ -142906,11 +143165,11 @@
142906143165
int (*keyword_count)(void);
142907143166
int (*keyword_name)(int,const char**,int*);
142908143167
int (*keyword_check)(const char*,int);
142909143168
sqlite3_str *(*str_new)(sqlite3*);
142910143169
char *(*str_finish)(sqlite3_str*);
142911
- void (*str_appendf)(sqlite3_str*, const char *zFormat, ...);
143170
+ void (SQLITE_CDECL*str_appendf)(sqlite3_str*, const char *zFormat, ...);
142912143171
void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list);
142913143172
void (*str_append)(sqlite3_str*, const char *zIn, int N);
142914143173
void (*str_appendall)(sqlite3_str*, const char *zIn);
142915143174
void (*str_appendchar)(sqlite3_str*, int N, char C);
142916143175
void (*str_reset)(sqlite3_str*);
@@ -144551,11 +144810,11 @@
144551144810
/* ePragTyp: */ PragTyp_FLAG,
144552144811
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
144553144812
/* ColNames: */ 0, 0,
144554144813
/* iArg: */ SQLITE_CountRows },
144555144814
#endif
144556
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
144815
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && defined(_WIN32)
144557144816
{/* zName: */ "data_store_directory",
144558144817
/* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
144559144818
/* ePragFlg: */ PragFlg_NoColumns1,
144560144819
/* ColNames: */ 0, 0,
144561144820
/* iArg: */ 0 },
@@ -144974,11 +145233,11 @@
144974145233
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
144975145234
/* ColNames: */ 0, 0,
144976145235
/* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
144977145236
#endif
144978145237
};
144979
-/* Number of pragmas: 68 on by default, 78 total. */
145238
+/* Number of pragmas: 67 on by default, 78 total. */
144980145239
144981145240
/************** End of pragma.h **********************************************/
144982145241
/************** Continuing where we left off in pragma.c *********************/
144983145242
144984145243
/*
@@ -145027,11 +145286,11 @@
145027145286
static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 5, 4};
145028145287
static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 3, 2};
145029145288
/* on no off false yes true extra full */
145030145289
int i, n;
145031145290
if( sqlite3Isdigit(*z) ){
145032
- return (u8)sqlite3Atoi(z);
145291
+ return sqlite3Atoi(z)!=0;
145033145292
}
145034145293
n = sqlite3Strlen30(z);
145035145294
for(i=0; i<ArraySize(iLength); i++){
145036145295
if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0
145037145296
&& (!omitFull || iValue[i]<=1)
@@ -146086,11 +146345,17 @@
146086146345
}else{
146087146346
if( !db->autoCommit ){
146088146347
sqlite3ErrorMsg(pParse,
146089146348
"Safety level may not be changed inside a transaction");
146090146349
}else if( iDb!=1 ){
146091
- int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
146350
+ int iLevel;
146351
+ if( sqlite3Isdigit(zRight[0]) ){
146352
+ iLevel = sqlite3Atoi(zRight);
146353
+ }else{
146354
+ iLevel = getSafetyLevel(zRight,0,1);
146355
+ }
146356
+ iLevel = (iLevel+1) & PAGER_SYNCHRONOUS_MASK;
146092146357
if( iLevel==0 ) iLevel = 1;
146093146358
pDb->safety_level = iLevel;
146094146359
pDb->bSyncSet = 1;
146095146360
setAllPagerFlags(db);
146096146361
}
@@ -149688,10 +149953,11 @@
149688149953
static int sqlite3ProcessJoin(Parse *pParse, Select *p){
149689149954
SrcList *pSrc; /* All tables in the FROM clause */
149690149955
int i, j; /* Loop counters */
149691149956
SrcItem *pLeft; /* Left table being joined */
149692149957
SrcItem *pRight; /* Right table being joined */
149958
+ int bSeenTFunc = 0; /* True if have seen table-valued function */
149693149959
149694149960
pSrc = p->pSrc;
149695149961
pLeft = &pSrc->a[0];
149696149962
pRight = &pLeft[1];
149697149963
for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
@@ -149830,11 +150096,22 @@
149830150096
pRight->u3.pOn = 0;
149831150097
pRight->fg.isOn = 1;
149832150098
p->selFlags |= SF_OnToWhere;
149833150099
}
149834150100
149835
- if( pRight->fg.isTabFunc && joinType==EP_OuterON && pRight->u1.pFuncArg ){
150101
+ if( bSeenTFunc==0 ){
150102
+ bSeenTFunc = (pLeft->fg.isTabFunc && pLeft->u1.pFuncArg);
150103
+ }
150104
+
150105
+ /* We also need to call sqlite3SelectCheckOnClauses() to verify that
150106
+ ** table-valued function arguments do not illegally refer to any tables to
150107
+ ** their right. This test is required if either (a) there is a RIGHT JOIN
150108
+ ** in the SrcList, or (b) there is a LEFT JOIN to the right of a
150109
+ ** table-valued function. */
150110
+ if( (pRight->fg.isTabFunc && joinType==EP_OuterON && pRight->u1.pFuncArg)
150111
+ || (bSeenTFunc && joinType==EP_OuterON)
150112
+ ){
149836150113
p->selFlags |= SF_OnToWhere;
149837150114
}
149838150115
}
149839150116
return 0;
149840150117
}
@@ -150939,10 +151216,13 @@
150939151216
/* Open any cursors needed for sorter-reference expressions */
150940151217
for(i=0; i<pSort->nDefer; i++){
150941151218
Table *pTab = pSort->aDefer[i].pTab;
150942151219
int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
150943151220
sqlite3OpenTable(pParse, pSort->aDefer[i].iCsr, iDb, pTab, OP_OpenRead);
151221
+ sqlite3VdbeAddOp2(v, OP_Rewind, pSort->aDefer[i].iCsr,
151222
+ sqlite3VdbeCurrentAddr(v)+1);
151223
+ VdbeCoverage(v);
150944151224
nRefKey = MAX(nRefKey, pSort->aDefer[i].nKey);
150945151225
}
150946151226
#endif
150947151227
150948151228
iTab = pSort->iECursor;
@@ -156638,11 +156918,11 @@
156638156918
** Type used for Walker callbacks by selectCheckOnClauses().
156639156919
*/
156640156920
typedef struct CheckOnCtx CheckOnCtx;
156641156921
struct CheckOnCtx {
156642156922
SrcList *pSrc; /* SrcList for this context */
156643
- int iJoin; /* Cursors must be left of this one, if not zero */
156923
+ int iJoin; /* Cursors must be left of this one, if not negative */
156644156924
int bFuncArg; /* True for table-function arg */
156645156925
CheckOnCtx *pParent; /* Parent context */
156646156926
};
156647156927
156648156928
/*
@@ -156671,15 +156951,15 @@
156671156951
/* If CheckOnCtx.iJoin is already set, then fall through and process
156672156952
** this expression node as normal. Or, if CheckOnCtx.iJoin is still 0,
156673156953
** set it to the cursor number of the RHS of the join to which this
156674156954
** ON expression was attached and then iterate through the entire
156675156955
** expression. */
156676
- assert( pCtx->iJoin==0 || pCtx->iJoin==pExpr->w.iJoin );
156677
- if( pCtx->iJoin==0 ){
156956
+ assert( pCtx->iJoin<0 || pCtx->iJoin==pExpr->w.iJoin );
156957
+ if( pCtx->iJoin<0 ){
156678156958
pCtx->iJoin = pExpr->w.iJoin;
156679156959
sqlite3WalkExprNN(pWalker, pExpr);
156680
- pCtx->iJoin = 0;
156960
+ pCtx->iJoin = -1;
156681156961
return WRC_Prune;
156682156962
}
156683156963
}
156684156964
156685156965
if( pExpr->op==TK_COLUMN ){
@@ -156693,11 +156973,11 @@
156693156973
int nSrc = pSrc->nSrc;
156694156974
int ii;
156695156975
for(ii=0; ii<nSrc && pSrc->a[ii].iCursor!=iTab; ii++){}
156696156976
if( ii<nSrc ){
156697156977
/* pSrc is the FROM clause that contains iTab */
156698
- if( pCtx->iJoin ){
156978
+ if( pCtx->iJoin>=0 ){
156699156979
for(ii--; ii>=0 && pSrc->a[ii].iCursor!=pCtx->iJoin; ii--){}
156700156980
if( ii>=0 ){
156701156981
/* Table iJoin appears to the left of table iTab in the SrcList.
156702156982
** Therefore the expression refers to a table to its right. */
156703156983
sqlite3ErrorMsg(pWalker->pParse,
@@ -156725,10 +157005,11 @@
156725157005
}else{
156726157006
CheckOnCtx sCtx;
156727157007
memset(&sCtx, 0, sizeof(sCtx));
156728157008
sCtx.pSrc = pSelect->pSrc;
156729157009
sCtx.pParent = pCtx;
157010
+ sCtx.iJoin = -1;
156730157011
pWalker->u.pCheckOnCtx = &sCtx;
156731157012
sqlite3WalkSelect(pWalker, pSelect);
156732157013
pWalker->u.pCheckOnCtx = pCtx;
156733157014
pSelect->selFlags &= ~SF_OnToWhere;
156734157015
return WRC_Prune;
@@ -156750,24 +157031,45 @@
156750157031
w.xExprCallback = selectCheckOnClausesExpr;
156751157032
w.xSelectCallback = selectCheckOnClausesSelect;
156752157033
w.u.pCheckOnCtx = &sCtx;
156753157034
memset(&sCtx, 0, sizeof(sCtx));
156754157035
sCtx.pSrc = pSelect->pSrc;
157036
+ sCtx.iJoin = -1;
156755157037
sqlite3WalkExpr(&w, pSelect->pWhere);
156756157038
pSelect->selFlags &= ~SF_OnToWhere;
156757157039
156758157040
/* Check for any table-function args that are attached to virtual tables
156759
- ** on the RHS of an outer join. They are subject to the same constraints
156760
- ** as ON clauses. */
157041
+ ** on the RHS of an outer join. They are subject to similar constraints
157042
+ ** as ON clauses. Specifically:
157043
+ **
157044
+ ** * If the table-valued function is to the left of any RIGHT JOIN, or if
157045
+ ** it is the RHS of a RIGHT JOIN, then the table-valued function arguments
157046
+ ** may not refer to any tables to the right of this one.
157047
+ **
157048
+ ** * If the table-valued function is to the left of a LEFT JOIN, then it
157049
+ ** may not refer to any table that occurs to the right of the LEFT JOIN.
157050
+ */
156761157051
sCtx.bFuncArg = 1;
156762157052
for(ii=0; ii<pSelect->pSrc->nSrc; ii++){
156763157053
SrcItem *pItem = &pSelect->pSrc->a[ii];
156764
- if( pItem->fg.isTabFunc
156765
- && (pItem->fg.jointype & JT_OUTER)
156766
- ){
156767
- sCtx.iJoin = pItem->iCursor;
156768
- sqlite3WalkExprList(&w, pItem->u1.pFuncArg);
157054
+ if( pItem->fg.isTabFunc ){
157055
+ sCtx.iJoin = -1;
157056
+ if( (pItem->fg.jointype & (JT_LTORJ|JT_RIGHT)) ){
157057
+ sCtx.iJoin = pItem->iCursor;
157058
+ }else{
157059
+ int jj;
157060
+ for(jj=ii+1; jj<pSelect->pSrc->nSrc; jj++){
157061
+ SrcItem *pItem2 = &pSelect->pSrc->a[jj];
157062
+ if( pItem2->fg.jointype & JT_OUTER ){
157063
+ sCtx.iJoin = pItem2[-1].iCursor;
157064
+ break;
157065
+ }
157066
+ }
157067
+ }
157068
+ if( sCtx.iJoin>=0 ){
157069
+ sqlite3WalkExprList(&w, pItem->u1.pFuncArg);
157070
+ }
156769157071
}
156770157072
}
156771157073
}
156772157074
156773157075
/*
@@ -160077,12 +160379,11 @@
160077160379
** it has been converted into REAL.
160078160380
*/
160079160381
static SQLITE_NOINLINE void columnDefaultUncommonCase(
160080160382
Vdbe *v, /* Byte code under construction */
160081160383
Table *pTab, /* The table */
160082
- Column *pCol, /* Which column of the table */
160083
- int iReg /* Register in which results are stored */
160384
+ Column *pCol /* Which column of the table */
160084160385
){
160085160386
sqlite3_value *pValue = 0;
160086160387
u8 enc = ENC(sqlite3VdbeDb(v));
160087160388
Parse *pParse = sqlite3VdbeParser(v);
160088160389
assert( !IsView(pTab) );
@@ -160090,15 +160391,10 @@
160090160391
sqlite3ColumnExprAuth(pTab,pCol,pParse), enc,
160091160392
pCol->affinity, &pValue);
160092160393
if( pValue ){
160093160394
sqlite3VdbeAppendP4(v, pValue, P4_MEM);
160094160395
}
160095
-#ifndef SQLITE_OMIT_FLOATING_POINT
160096
- if( pCol->affinity==SQLITE_AFF_REAL ){
160097
- sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
160098
- }
160099
-#endif
160100160396
}
160101160397
SQLITE_PRIVATE void sqlite3ColumnDefault(
160102160398
Vdbe *v, /* Byte code under construction */
160103160399
Table *pTab, /* The table */
160104160400
int i, /* Which column of the table */
@@ -160107,11 +160403,11 @@
160107160403
Column *pCol;
160108160404
assert( pTab!=0 );
160109160405
assert( pTab->nCol>i );
160110160406
pCol = &pTab->aCol[i];
160111160407
if( pCol->iDflt ){
160112
- columnDefaultUncommonCase(v,pTab,pCol,iReg);
160408
+ columnDefaultUncommonCase(v,pTab,pCol);
160113160409
}
160114160410
#ifndef SQLITE_OMIT_FLOATING_POINT
160115160411
if( pCol->affinity==SQLITE_AFF_REAL ){
160116160412
sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
160117160413
}
@@ -165194,21 +165490,11 @@
165194165490
** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
165195165491
testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
165196165492
testcase( pTerm->wtFlags & TERM_VIRTUAL );
165197165493
r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
165198165494
if( r1!=regBase+j ){
165199
- /* If this routine is being called as part of a RIGHT JOIN loop, then
165200
- ** register r1 may be used by the body of the loop that the RIGHT JOIN
165201
- ** will jump back into (e.g. if pTerm is a sub-query). This can cause
165202
- ** problems if (say) the affinity of r1 is modified by the caller of
165203
- ** this routine. So, always take a copy of the value in this case. */
165204
- if( nReg==1 && pParse->withinRJSubrtn==0 ){
165205
- sqlite3ReleaseTempReg(pParse, regBase);
165206
- regBase = r1;
165207
- }else{
165208
- sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
165209
- }
165495
+ sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
165210165496
}
165211165497
if( pTerm->eOperator & WO_IN ){
165212165498
if( pTerm->pExpr->flags & EP_xIsSelect ){
165213165499
/* No affinity ever needs to be (or should be) applied to a value
165214165500
** from the RHS of an "? IN (SELECT ...)" expression. The
@@ -165824,10 +166110,13 @@
165824166110
);
165825166111
if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
165826166112
pLevel->iLeftJoin = ++pParse->nMem;
165827166113
sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
165828166114
VdbeComment((v, "init LEFT JOIN match flag"));
166115
+ if( pTabItem->fg.viaCoroutine ){
166116
+ sqlite3VdbeAddOp2(v, OP_NullRow, pTabItem->iCursor, 1);
166117
+ }
165829166118
}
165830166119
165831166120
/* Special case of a FROM clause subquery implemented as a co-routine */
165832166121
if( pTabItem->fg.viaCoroutine ){
165833166122
int regYield;
@@ -176880,21 +177169,21 @@
176880177169
sqlite3VdbeChangeP5(v, pLevel->p5);
176881177170
VdbeCoverage(v);
176882177171
VdbeCoverageIf(v, pLevel->op==OP_Next);
176883177172
VdbeCoverageIf(v, pLevel->op==OP_Prev);
176884177173
VdbeCoverageIf(v, pLevel->op==OP_VNext);
176885
- if( pLevel->regBignull ){
176886
- sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
176887
- sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1);
176888
- VdbeCoverage(v);
176889
- }
176890177174
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
176891177175
if( addrSeek ){
176892177176
sqlite3VdbeJumpHere(v, addrSeek);
176893177177
addrSeek = 0;
176894177178
}
176895177179
#endif
177180
+ if( pLevel->regBignull ){
177181
+ sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
177182
+ sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1);
177183
+ VdbeCoverage(v);
177184
+ }
176896177185
}
176897177186
if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
176898177187
struct InLoop *pIn;
176899177188
int j;
176900177189
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
@@ -177517,10 +177806,11 @@
177517177806
){
177518177807
struct CallCount *p;
177519177808
UNUSED_PARAMETER(nArg); assert( nArg==0 );
177520177809
UNUSED_PARAMETER(apArg);
177521177810
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
177811
+ assert( p!=0 );
177522177812
p->nStep++;
177523177813
}
177524177814
static void percent_rankValueFunc(sqlite3_context *pCtx){
177525177815
struct CallCount *p;
177526177816
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
@@ -177562,10 +177852,11 @@
177562177852
){
177563177853
struct CallCount *p;
177564177854
UNUSED_PARAMETER(nArg); assert( nArg==0 );
177565177855
UNUSED_PARAMETER(apArg);
177566177856
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
177857
+ assert( p!=0 );
177567177858
p->nStep++;
177568177859
}
177569177860
static void cume_distValueFunc(sqlite3_context *pCtx){
177570177861
struct CallCount *p;
177571177862
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
@@ -177618,10 +177909,11 @@
177618177909
){
177619177910
struct NtileCtx *p;
177620177911
assert( nArg==1 ); UNUSED_PARAMETER(nArg);
177621177912
UNUSED_PARAMETER(apArg);
177622177913
p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
177914
+ assert( p!=0 );
177623177915
p->iRow++;
177624177916
}
177625177917
static void ntileValueFunc(sqlite3_context *pCtx){
177626177918
struct NtileCtx *p;
177627177919
p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
@@ -184558,10 +184850,11 @@
184558184850
if( yymsp[-5].minor.yy203 ){
184559184851
SrcItem *pNew = &yymsp[-5].minor.yy203->a[yymsp[-5].minor.yy203->nSrc-1];
184560184852
SrcItem *pOld = yymsp[-3].minor.yy203->a;
184561184853
assert( pOld->fg.fixedSchema==0 );
184562184854
pNew->zName = pOld->zName;
184855
+ pOld->zName = 0;
184563184856
assert( pOld->fg.fixedSchema==0 );
184564184857
if( pOld->fg.isSubquery ){
184565184858
pNew->fg.isSubquery = 1;
184566184859
pNew->u4.pSubq = pOld->u4.pSubq;
184567184860
pOld->u4.pSubq = 0;
@@ -184577,12 +184870,17 @@
184577184870
if( pOld->fg.isTabFunc ){
184578184871
pNew->u1.pFuncArg = pOld->u1.pFuncArg;
184579184872
pOld->u1.pFuncArg = 0;
184580184873
pOld->fg.isTabFunc = 0;
184581184874
pNew->fg.isTabFunc = 1;
184875
+ }else if( pOld->fg.isIndexedBy ){
184876
+ pNew->u1.zIndexedBy = pOld->u1.zIndexedBy;
184877
+ pOld->u1.zIndexedBy = 0;
184878
+ pOld->fg.isIndexedBy = 0;
184879
+ pNew->fg.isIndexedBy = 1;
184582184880
}
184583
- pOld->zName = 0;
184881
+ pNew->fg.notIndexed = pOld->fg.notIndexed;
184584184882
}
184585184883
sqlite3SrcListDelete(pParse->db, yymsp[-3].minor.yy203);
184586184884
}else{
184587184885
Select *pSubquery;
184588184886
sqlite3SrcListShiftJoinType(pParse,yymsp[-3].minor.yy203);
@@ -188939,11 +189237,11 @@
188939189237
188940189238
/*
188941189239
** This is the default collating function named "BINARY" which is always
188942189240
** available.
188943189241
*/
188944
-static int binCollFunc(
189242
+SQLITE_PRIVATE int sqlite3BinaryCompare(
188945189243
void *NotUsed,
188946189244
int nKey1, const void *pKey1,
188947189245
int nKey2, const void *pKey2
188948189246
){
188949189247
int rc, n;
@@ -188971,20 +189269,23 @@
188971189269
){
188972189270
const u8 *pK1 = (const u8*)pKey1;
188973189271
const u8 *pK2 = (const u8*)pKey2;
188974189272
while( nKey1 && pK1[nKey1-1]==' ' ) nKey1--;
188975189273
while( nKey2 && pK2[nKey2-1]==' ' ) nKey2--;
188976
- return binCollFunc(pUser, nKey1, pKey1, nKey2, pKey2);
189274
+ return sqlite3BinaryCompare(pUser, nKey1, pKey1, nKey2, pKey2);
188977189275
}
188978189276
188979189277
/*
188980189278
** Return true if CollSeq is the default built-in BINARY.
188981189279
*/
189280
+#if !SQLITE_USES_INLINE
188982189281
SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq *p){
188983
- assert( p==0 || p->xCmp!=binCollFunc || strcmp(p->zName,"BINARY")==0 );
188984
- return p==0 || p->xCmp==binCollFunc;
189282
+ assert( p==0 || p->xCmp!=sqlite3BinaryCompare
189283
+ || strcmp(p->zName,"BINARY")==0 );
189284
+ return p==0 || p->xCmp==sqlite3BinaryCompare;
188985189285
}
189286
+#endif
188986189287
188987189288
/*
188988189289
** Another built-in collating sequence: NOCASE.
188989189290
**
188990189291
** This collating sequence is intended to be used for "case independent
@@ -189932,11 +190233,11 @@
189932190233
p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
189933190234
if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==(u32)enc && p->nArg==nArg ){
189934190235
if( db->nVdbeActive ){
189935190236
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
189936190237
"unable to delete/modify user-function due to active statements");
189937
- assert( !db->mallocFailed );
190238
+ assert( !db->mallocFailed || db->nVdbeExec>0 );
189938190239
return SQLITE_BUSY;
189939190240
}else{
189940190241
sqlite3ExpirePreparedStatements(db, 0);
189941190242
}
189942190243
}else if( xSFunc==0 && xFinal==0 ){
@@ -191454,13 +191755,16 @@
191454191755
** conversions. The only error that can occur here is a malloc() failure.
191455191756
**
191456191757
** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
191457191758
** functions:
191458191759
*/
191459
- createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0, binCollFunc, 0);
191460
- createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0, binCollFunc, 0);
191461
- createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0, binCollFunc, 0);
191760
+ createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0,
191761
+ sqlite3BinaryCompare, 0);
191762
+ createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0,
191763
+ sqlite3BinaryCompare, 0);
191764
+ createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0,
191765
+ sqlite3BinaryCompare, 0);
191462191766
createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
191463191767
createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0);
191464191768
if( db->mallocFailed ){
191465191769
goto opendb_out;
191466191770
}
@@ -198200,12 +198504,12 @@
198200198504
Fts3Table *pTab = 0;
198201198505
Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
198202198506
const char *zStart = "<b>";
198203198507
const char *zEnd = "</b>";
198204198508
const char *zEllipsis = "<b>...</b>";
198205
- int iCol = -1;
198206
- int nToken = 15; /* Default number of tokens in snippet */
198509
+ i64 iCol = -1;
198510
+ i64 nToken = 15; /* Default number of tokens in snippet */
198207198511
198208198512
/* There must be at least one argument passed to this function (otherwise
198209198513
** the non-overloaded version would have been called instead of this one).
198210198514
*/
198211198515
assert( nVal>=1 );
@@ -198217,13 +198521,13 @@
198217198521
}
198218198522
if( fts3FunctionArg(pContext, "snippet", apVal[0], &pCsr) ) return;
198219198523
pTab = (Fts3Table *)pCsr->base.pVtab;
198220198524
198221198525
switch( nVal ){
198222
- case 6: nToken = sqlite3_value_int(apVal[5]);
198526
+ case 6: nToken = sqlite3_value_int64(apVal[5]);
198223198527
/* no break */ deliberate_fall_through
198224
- case 5: iCol = sqlite3_value_int(apVal[4]);
198528
+ case 5: iCol = sqlite3_value_int64(apVal[4]);
198225198529
/* no break */ deliberate_fall_through
198226198530
case 4: zEllipsis = (const char*)sqlite3_value_text(apVal[3]);
198227198531
/* no break */ deliberate_fall_through
198228198532
case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
198229198533
/* no break */ deliberate_fall_through
@@ -198232,10 +198536,13 @@
198232198536
if( !zEllipsis || !zEnd || !zStart ){
198233198537
sqlite3_result_error_nomem(pContext);
198234198538
}else if( nToken==0 || iCol>=pTab->nColumn ){
198235198539
sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
198236198540
}else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
198541
+ if( iCol<0 ) iCol = -1;
198542
+ if( nToken<-64 ) nToken = -64;
198543
+ if( nToken>64 ) nToken = 64;
198237198544
sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
198238198545
}
198239198546
}
198240198547
198241198548
/*
@@ -203595,14 +203902,15 @@
203595203902
}
203596203903
203597203904
if( c->iOffset>iStartOffset ){
203598203905
int n = c->iOffset-iStartOffset;
203599203906
if( n>c->nAllocated ){
203907
+ i64 nNew = n + 20;
203600203908
char *pNew;
203601
- c->nAllocated = n+20;
203602
- pNew = sqlite3_realloc64(c->zToken, c->nAllocated);
203909
+ pNew = sqlite3_realloc64(c->zToken, nNew);
203603203910
if( !pNew ) return SQLITE_NOMEM;
203911
+ c->nAllocated = (int)nNew;
203604203912
c->zToken = pNew;
203605203913
}
203606203914
porter_stemmer(&z[iStartOffset], n, c->zToken, pnBytes);
203607203915
*pzToken = c->zToken;
203608203916
*piStartOffset = iStartOffset;
@@ -210126,42 +210434,46 @@
210126210434
);
210127210435
if( rc==SQLITE_OK ){
210128210436
rc = sqlite3Fts3SegReaderStart(p, &csr, &filter);
210129210437
}
210130210438
210131
- if( rc==SQLITE_OK ){
210132
- while( SQLITE_ROW==(rc = sqlite3Fts3SegReaderStep(p, &csr)) ){
210133
- char *pCsr = csr.aDoclist;
210134
- char *pEnd = &pCsr[csr.nDoclist];
210135
-
210136
- i64 iDocid = 0;
210137
- i64 iCol = 0;
210138
- u64 iPos = 0;
210139
-
210140
- pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid);
210141
- while( pCsr<pEnd ){
210142
- u64 iVal = 0;
210143
- pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
210144
- if( pCsr<pEnd ){
210145
- if( iVal==0 || iVal==1 ){
210146
- iCol = 0;
210147
- iPos = 0;
210148
- if( iVal ){
210149
- pCsr += sqlite3Fts3GetVarint(pCsr, &iCol);
210150
- }else{
210151
- pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
210152
- if( p->bDescIdx ){
210153
- iDocid = (i64)((u64)iDocid - iVal);
210154
- }else{
210155
- iDocid = (i64)((u64)iDocid + iVal);
210156
- }
210157
- }
210158
- }else{
210159
- iPos += (iVal - 2);
210439
+ while( rc==SQLITE_OK && SQLITE_ROW==(rc = sqlite3Fts3SegReaderStep(p,&csr)) ){
210440
+ char *pCsr = csr.aDoclist;
210441
+ char *pEnd = &pCsr[csr.nDoclist];
210442
+
210443
+ i64 iDocid = 0;
210444
+ int iCol = 0;
210445
+ u64 iPos = 0;
210446
+
210447
+ rc = SQLITE_OK;
210448
+ pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid);
210449
+ while( pCsr<pEnd ){
210450
+ u64 iVal = 0;
210451
+ pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
210452
+ if( pCsr<pEnd ){
210453
+ if( iVal==0 || iVal==1 ){
210454
+ iCol = 0;
210455
+ iPos = 0;
210456
+ if( iVal ){
210457
+ pCsr += fts3GetVarint32(pCsr, &iCol);
210458
+ }else{
210459
+ pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
210460
+ if( p->bDescIdx ){
210461
+ iDocid = (i64)((u64)iDocid - iVal);
210462
+ }else{
210463
+ iDocid = (i64)((u64)iDocid + iVal);
210464
+ }
210465
+ }
210466
+ }else{
210467
+ iPos += (iVal - 2);
210468
+ if( iPos>0x7FFFFFFF ){
210469
+ rc = SQLITE_CORRUPT_VTAB;
210470
+ break;
210471
+ }else{
210160210472
cksum = cksum ^ fts3ChecksumEntry(
210161210473
csr.zTerm, csr.nTerm, iLangid, iIndex, iDocid,
210162
- (int)iCol, (int)iPos
210474
+ iCol, (int)iPos
210163210475
);
210164210476
}
210165210477
}
210166210478
}
210167210479
}
@@ -212193,13 +212505,12 @@
212193212505
if( !pCsr->pExpr ){
212194212506
sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
212195212507
return;
212196212508
}
212197212509
212198
- /* Limit the snippet length to 64 tokens. */
212199
- if( nToken<-64 ) nToken = -64;
212200
- if( nToken>+64 ) nToken = +64;
212510
+ /* The snippet length should already have been limited to 64 tokens. */
212511
+ assert( nToken>=-64 && nToken<=64 );
212201212512
212202212513
for(nSnippet=1; 1; nSnippet++){
212203212514
212204212515
int iSnip; /* Loop counter 0..nSnippet-1 */
212205212516
u64 mCovered = 0; /* Bitmask of phrases covered by snippet */
@@ -215936,11 +216247,14 @@
215936216247
jsonStringTooDeep(pOut);
215937216248
}
215938216249
while( pOut->eErr==0 ){
215939216250
jsonPrettyIndent(pPretty);
215940216251
j = jsonTranslateBlobToPrettyText(pPretty, j);
215941
- if( j>=iEnd ) break;
216252
+ if( j>=iEnd ){
216253
+ if( j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
216254
+ break;
216255
+ }
215942216256
jsonAppendRawNZ(pOut, ",\n", 2);
215943216257
}
215944216258
jsonAppendChar(pOut, '\n');
215945216259
pPretty->nIndent--;
215946216260
jsonPrettyIndent(pPretty);
@@ -218896,11 +219210,11 @@
218896219210
sqlite3_result_text64(ctx, p->path.zBuf, n,
218897219211
SQLITE_TRANSIENT, SQLITE_UTF8);
218898219212
break;
218899219213
}
218900219214
default: {
218901
- sqlite3_result_text(ctx, p->path.zBuf, p->nRoot, SQLITE_STATIC);
219215
+ sqlite3_result_text(ctx, p->path.zBuf, p->nRoot, SQLITE_TRANSIENT);
218902219216
break;
218903219217
}
218904219218
case JEACH_JSON: {
218905219219
if( p->sParse.zJson==0 ){
218906219220
sqlite3_result_blob(ctx, p->sParse.aBlob, p->sParse.nBlob,
@@ -219828,10 +220142,22 @@
219828220142
p[6] = (i>> 8)&0xFF;
219829220143
p[7] = (i>> 0)&0xFF;
219830220144
#endif
219831220145
return 8;
219832220146
}
220147
+
220148
+/*
220149
+** Translate pVal into a 32-bit integer. If pVal is an integer
220150
+** that is larger than 32 bits, the cap it at the largest or
220151
+** smallest 32-bit integer.
220152
+*/
220153
+static int rtreeValueInt32(sqlite3_value *pVal){
220154
+ i64 v64 = sqlite3_value_int64(pVal);
220155
+ if( v64>2147483647 ) return 2147483647;
220156
+ if( v64<-2147483648LL ) return (int)-2147483648LL;
220157
+ return (int)v64;
220158
+}
219833220159
219834220160
/*
219835220161
** Increment the reference count of node p.
219836220162
*/
219837220163
static void nodeReference(RtreeNode *p){
@@ -220109,11 +220435,21 @@
220109220435
pNode->isDirty = 0;
220110220436
rc = sqlite3_reset(p);
220111220437
sqlite3_bind_null(p, 2);
220112220438
if( pNode->iNode==0 && rc==SQLITE_OK ){
220113220439
pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
220114
- nodeHashInsert(pRtree, pNode);
220440
+ if( pNode->iNode==0 ){
220441
+ /* If the SQL statement has succeeded but sqlite3_last_insert_rowid()
220442
+ ** returns 0, then the shadow table schema has been corrupted somehow
220443
+ ** (e.g. the %_node table has been replaced by a WITHOUT ROWID table).
220444
+ ** It would be dangerous to continue in this case as the hash table
220445
+ ** implementation assumes iNode==0 means that the node is not part
220446
+ ** of the hash table. */
220447
+ rc = SQLITE_CORRUPT_VTAB;
220448
+ }else{
220449
+ nodeHashInsert(pRtree, pNode);
220450
+ }
220115220451
}
220116220452
}
220117220453
return rc;
220118220454
}
220119220455
@@ -222232,39 +222568,64 @@
222232222568
}
222233222569
222234222570
return rc;
222235222571
}
222236222572
222237
-/*
222238
-** Rounding constants for float->double conversion.
222239
-*/
222240
-#define RNDTOWARDS (1.0 - 1.0/8388608.0) /* Round towards zero */
222241
-#define RNDAWAY (1.0 + 1.0/8388608.0) /* Round away from zero */
222242
-
222243222573
#if !defined(SQLITE_RTREE_INT_ONLY)
222244222574
/*
222245222575
** Convert an sqlite3_value into an RtreeValue (presumably a float)
222246222576
** while taking care to round toward negative or positive, respectively.
222247222577
*/
222248222578
static RtreeValue rtreeValueDown(sqlite3_value *v){
222249222579
double d = sqlite3_value_double(v);
222250222580
float f = (float)d;
222251222581
if( f>d ){
222252
- f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS));
222582
+ unsigned int x;
222583
+ memcpy(&x, &f, 4);
222584
+ x = (x & 0x80000000)!=0 ? x+1 : x-1;
222585
+ memcpy(&f, &x, 4);
222253222586
}
222254222587
return f;
222255222588
}
222256222589
static RtreeValue rtreeValueUp(sqlite3_value *v){
222257222590
double d = sqlite3_value_double(v);
222258222591
float f = (float)d;
222259222592
if( f<d ){
222260
- f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY));
222593
+ unsigned int x;
222594
+ memcpy(&x, &f, 4);
222595
+ x = (x & 0x80000000)!=0 ? x-1 : x+1;
222596
+ memcpy(&f, &x, 4);
222261222597
}
222262222598
return f;
222263222599
}
222264222600
#endif /* !defined(SQLITE_RTREE_INT_ONLY) */
222265222601
222602
+#if !defined(SQLITE_RTREE_INT_ONLY) && defined(SQLITE_DEBUG)
222603
+/*
222604
+** SQL function: rtree_round32(V,F)
222605
+**
222606
+** Convert the floating point value V to the nearest 32-bit float
222607
+** and return that 32-bit float value. Round up if F is true, or
222608
+** down if F is falsed.
222609
+**
222610
+** Debugging and testing use only.
222611
+*/
222612
+static void rtreeRoundFunc(
222613
+ sqlite3_context *ctx,
222614
+ int nArg,
222615
+ sqlite3_value **apArg
222616
+){
222617
+ float f;
222618
+ if( sqlite3_value_int(apArg[1]) ){
222619
+ f = rtreeValueUp(apArg[0]);
222620
+ }else{
222621
+ f = rtreeValueDown(apArg[0]);
222622
+ }
222623
+ sqlite3_result_double(ctx, (double)f);
222624
+}
222625
+#endif /* !defined(SQLITE_RTREE_INT_ONLY) && defined(SQLITE_DEBUG) */
222626
+
222266222627
/*
222267222628
** A constraint has failed while inserting a row into an rtree table.
222268222629
** Assuming no OOM error occurs, this function sets the error message
222269222630
** (at pRtree->base.zErrMsg) to an appropriate value and returns
222270222631
** SQLITE_CONSTRAINT.
@@ -222373,12 +222734,12 @@
222373222734
}
222374222735
}else
222375222736
#endif
222376222737
{
222377222738
for(ii=0; ii<nn; ii+=2){
222378
- cell.aCoord[ii].i = sqlite3_value_int(aData[ii+3]);
222379
- cell.aCoord[ii+1].i = sqlite3_value_int(aData[ii+4]);
222739
+ cell.aCoord[ii].i = rtreeValueInt32(aData[ii+3]);
222740
+ cell.aCoord[ii+1].i = rtreeValueInt32(aData[ii+4]);
222380222741
if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
222381222742
rc = rtreeConstraintError(pRtree, ii+1);
222382222743
goto constraint;
222383222744
}
222384222745
}
@@ -222976,16 +223337,18 @@
222976223337
Rtree tree;
222977223338
int ii;
222978223339
int nData;
222979223340
int errCode;
222980223341
sqlite3_str *pOut;
223342
+ i64 nDim64;
222981223343
222982223344
UNUSED_PARAMETER(nArg);
222983223345
memset(&node, 0, sizeof(RtreeNode));
222984223346
memset(&tree, 0, sizeof(Rtree));
222985
- tree.nDim = (u8)sqlite3_value_int(apArg[0]);
222986
- if( tree.nDim<1 || tree.nDim>5 ) return;
223347
+ nDim64 = sqlite3_value_int64(apArg[0]);
223348
+ if( nDim64<1 || nDim64>5 ) return;
223349
+ tree.nDim = (u8)nDim64;
222987223350
tree.nDim2 = tree.nDim*2;
222988223351
tree.nBytesPerCell = 8 + 8 * tree.nDim;
222989223352
node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
222990223353
if( node.zData==0 ) return;
222991223354
nData = sqlite3_value_bytes(apArg[1]);
@@ -225386,10 +225749,16 @@
225386225749
rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
225387225750
}
225388225751
if( rc==SQLITE_OK ){
225389225752
rc = sqlite3_create_function(db, "rtreecheck", -1, utf8, 0,rtreecheck, 0,0);
225390225753
}
225754
+#if defined(SQLITE_DEBUG) && !defined(SQLITE_RTREE_INT_ONLY)
225755
+ if( rc==SQLITE_OK ){
225756
+ rc = sqlite3_create_function(db, "rtree_round", 2, utf8, 0,
225757
+ rtreeRoundFunc, 0, 0);
225758
+ }
225759
+#endif /* SQLITE_DEBUG && !SQLITE_RTREE_INT_ONLY */
225391225760
if( rc==SQLITE_OK ){
225392225761
#ifdef SQLITE_RTREE_INT_ONLY
225393225762
void *c = (void *)RTREE_COORD_INT32;
225394225763
#else
225395225764
void *c = (void *)RTREE_COORD_REAL32;
@@ -228466,19 +228835,31 @@
228466228835
);
228467228836
}
228468228837
228469228838
/* Check that all non-HIDDEN columns in the destination table are also
228470228839
** present in the input table. Populate the abTblPk[], azTblType[] and
228471
- ** aiTblOrder[] arrays at the same time. */
228840
+ ** aiTblOrder[] arrays at the same time.
228841
+ **
228842
+ ** RBU does not support tables with GENERATED columns. If the target
228843
+ ** table has any, return an error. */
228472228844
if( p->rc==SQLITE_OK ){
228473228845
p->rc = prepareFreeAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
228474
- sqlite3_mprintf("PRAGMA table_info(%Q)", pIter->zTbl)
228846
+ sqlite3_mprintf("PRAGMA table_xinfo(%Q)", pIter->zTbl)
228475228847
);
228476228848
}
228477228849
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
228478228850
const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
228479
- if( zName==0 ) break; /* An OOM - finalize() below returns S_NOMEM */
228851
+ int eHidden = sqlite3_column_int(pStmt, 6);
228852
+ if( zName==0 ) break; /* An OOM. Bail out */
228853
+ if( eHidden==1 ) continue; /* Hidden column. Ignore */
228854
+ if( eHidden!=0 ){
228855
+ p->rc = SQLITE_ERROR;
228856
+ p->zErrmsg = sqlite3_mprintf(
228857
+ "generated columns not supported: %s.%s", pIter->zTbl, zName
228858
+ );
228859
+ break;
228860
+ }
228480228861
for(i=iOrder; i<pIter->nTblCol; i++){
228481228862
if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
228482228863
}
228483228864
if( i==pIter->nTblCol ){
228484228865
p->rc = SQLITE_ERROR;
@@ -229327,11 +229708,11 @@
229327229708
int nIdxAlloc = 0;
229328229709
for(i=0; zSql[i]; i++){
229329229710
char c = zSql[i];
229330229711
229331229712
/* If necessary, grow the pIter->aIdxCol[] array */
229332
- if( iIdxCol==nIdxAlloc ){
229713
+ if( iIdxCol>=(nIdxAlloc-1) ){
229333229714
RbuSpan *aIdxCol = (RbuSpan*)sqlite3_realloc64(
229334229715
pIter->aIdxCol, nIdxAlloc*sizeof(RbuSpan) + 16*sizeof(RbuSpan)
229335229716
);
229336229717
if( aIdxCol==0 ){
229337229718
rc = SQLITE_NOMEM;
@@ -233129,28 +233510,28 @@
233129233510
StatPage *p = &pCsr->aPage[pCsr->iPage];
233130233511
if( !pCsr->isAgg ) statResetCounts(pCsr);
233131233512
while( p->iCell<p->nCell ){
233132233513
StatCell *pCell = &p->aCell[p->iCell];
233133233514
while( pCell->iOvfl<pCell->nOvfl ){
233134
- int nUsable, iOvfl;
233515
+ int nUsable;
233516
+ int iOvfl = pCell->iOvfl;
233135233517
sqlite3BtreeEnter(pBt);
233136233518
nUsable = sqlite3BtreeGetPageSize(pBt) -
233137233519
sqlite3BtreeGetReserveNoMutex(pBt);
233138233520
sqlite3BtreeLeave(pBt);
233139233521
pCsr->nPage++;
233522
+ pCsr->iPageno = pCell->aOvfl[iOvfl];
233140233523
statSizeAndOffset(pCsr);
233141233524
if( pCell->iOvfl<pCell->nOvfl-1 ){
233142233525
pCsr->nPayload += nUsable - 4;
233143233526
}else{
233144233527
pCsr->nPayload += pCell->nLastOvfl;
233145233528
pCsr->nUnused += nUsable - 4 - pCell->nLastOvfl;
233146233529
}
233147
- iOvfl = pCell->iOvfl;
233148233530
pCell->iOvfl++;
233149233531
if( !pCsr->isAgg ){
233150233532
pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
233151
- pCsr->iPageno = pCell->aOvfl[iOvfl];
233152233533
pCsr->zPagetype = "overflow";
233153233534
pCsr->zPath = z = sqlite3_mprintf(
233154233535
"%s%.3x+%.6x", p->zPath, p->iCell, iOvfl
233155233536
);
233156233537
return z==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
@@ -240890,11 +241271,11 @@
240890241271
240891241272
240892241273
if( pIter ){
240893241274
sqlite3changeset_pk(pIter, &abPK, &nCol);
240894241275
}else if( !pTab && !pGrp->db ){
240895
- return SQLITE_OK;
241276
+ return SQLITE_ERROR;
240896241277
}
240897241278
240898241279
/* If one was not found above, create a new table now */
240899241280
if( !pTab ){
240900241281
SessionTable **ppNew;
@@ -240916,11 +241297,11 @@
240916241297
pTab->nCol = 0;
240917241298
rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb);
240918241299
if( rc || pTab->nCol==0 ){
240919241300
sqlite3_free(pTab->azCol);
240920241301
sqlite3_free(pTab);
240921
- return rc;
241302
+ return rc ? rc : SQLITE_ERROR;
240922241303
}
240923241304
}
240924241305
240925241306
/* The new object must be linked on to the end of the list, not
240926241307
** simply added to the start of it. This is to ensure that the
@@ -241754,48 +242135,44 @@
241754242135
rc = SQLITE_MISUSE;
241755242136
}else if( eOp!=SQLITE_INSERT && eOp!=SQLITE_UPDATE && eOp!=SQLITE_DELETE ){
241756242137
rc = SQLITE_ERROR;
241757242138
}else{
241758242139
rc = sessionChangesetFindTable(pGrp, zTab, 0, &pTab);
241759
- }
241760
- if( rc==SQLITE_OK ){
241761
- if( pTab==0 ){
241762
- if( pzErr ){
241763
- *pzErr = sqlite3_mprintf("no such table: %s", zTab);
241764
- }
241765
- rc = SQLITE_ERROR;
241766
- }else{
241767
- int nReq = pTab->nCol * (eOp==SQLITE_UPDATE ? 2 : 1);
241768
- pGrp->cd.pTab = pTab;
241769
- pGrp->cd.eOp = eOp;
241770
- pGrp->cd.bIndirect = bIndirect;
241771
-
241772
- if( pGrp->cd.nBufAlloc<nReq ){
241773
- SessionBuffer *aBuf = (SessionBuffer*)sqlite3_realloc(
241774
- pGrp->cd.aBuf, nReq * sizeof(SessionBuffer)
241775
- );
241776
- if( aBuf==0 ){
241777
- rc = SQLITE_NOMEM;
241778
- }else{
241779
- memset(&aBuf[pGrp->cd.nBufAlloc], 0,
241780
- sizeof(SessionBuffer) * (nReq - pGrp->cd.nBufAlloc)
241781
- );
241782
- pGrp->cd.aBuf = aBuf;
241783
- pGrp->cd.nBufAlloc = nReq;
241784
- }
241785
- }
242140
+ if( pTab==0 && pzErr ){
242141
+ *pzErr = sqlite3_mprintf("no such table: %s", zTab);
242142
+ }
242143
+ }
242144
+ if( rc==SQLITE_OK ){
242145
+ int nReq = pTab->nCol * (eOp==SQLITE_UPDATE ? 2 : 1);
242146
+ pGrp->cd.pTab = pTab;
242147
+ pGrp->cd.eOp = eOp;
242148
+ pGrp->cd.bIndirect = bIndirect;
242149
+
242150
+ if( pGrp->cd.nBufAlloc<nReq ){
242151
+ SessionBuffer *aBuf = (SessionBuffer*)sqlite3_realloc(
242152
+ pGrp->cd.aBuf, nReq * sizeof(SessionBuffer)
242153
+ );
242154
+ if( aBuf==0 ){
242155
+ rc = SQLITE_NOMEM;
242156
+ }else{
242157
+ memset(&aBuf[pGrp->cd.nBufAlloc], 0,
242158
+ sizeof(SessionBuffer) * (nReq - pGrp->cd.nBufAlloc)
242159
+ );
242160
+ pGrp->cd.aBuf = aBuf;
242161
+ pGrp->cd.nBufAlloc = nReq;
242162
+ }
242163
+ }
241786242164
241787242165
#ifdef SQLITE_DEBUG
241788
- {
241789
- /* Assert that all column values are currently undefined */
241790
- int ii;
241791
- for(ii=0; ii<pGrp->cd.nBufAlloc; ii++){
241792
- assert( pGrp->cd.aBuf[ii].nBuf==0 );
241793
- }
241794
- }
241795
-#endif
241796
- }
242166
+ {
242167
+ /* Assert that all column values are currently undefined */
242168
+ int ii;
242169
+ for(ii=0; ii<pGrp->cd.nBufAlloc; ii++){
242170
+ assert( pGrp->cd.aBuf[ii].nBuf==0 );
242171
+ }
242172
+ }
242173
+#endif
241797242174
}
241798242175
241799242176
return rc;
241800242177
}
241801242178
@@ -245585,10 +245962,20 @@
245585245962
}
245586245963
245587245964
return rc;
245588245965
}
245589245966
245967
+/*
245968
+** Return the integer value of pVal, clamped to the range [-1, 0x7FFFFFFF].
245969
+** This is used for the column-number arguments of auxiliary functions,
245970
+** so that 64-bit values that are too large or too small to fit in a
245971
+** 32-bit signed integer are not truncated to what might be a valid
245972
+** column number.
245973
+*/
245974
+static int fts5ValueClampedInt(sqlite3_value *pVal){
245975
+ return (int)MIN(MAX(sqlite3_value_int64(pVal), -1), 0x7FFFFFFF);
245976
+}
245590245977
245591245978
/*
245592245979
** Implementation of highlight() function.
245593245980
*/
245594245981
static void fts5HighlightFunction(
@@ -245606,11 +245993,11 @@
245606245993
const char *zErr = "wrong number of arguments to function highlight()";
245607245994
sqlite3_result_error(pCtx, zErr, -1);
245608245995
return;
245609245996
}
245610245997
245611
- iCol = sqlite3_value_int(apVal[0]);
245998
+ iCol = fts5ValueClampedInt(apVal[0]);
245612245999
memset(&ctx, 0, sizeof(HighlightContext));
245613246000
ctx.zOpen = (const char*)sqlite3_value_text(apVal[1]);
245614246001
ctx.zClose = (const char*)sqlite3_value_text(apVal[2]);
245615246002
ctx.iRangeEnd = -1;
245616246003
rc = pApi->xColumnText(pFts, iCol, &ctx.zIn, &ctx.nIn);
@@ -245805,11 +246192,11 @@
245805246192
return;
245806246193
}
245807246194
245808246195
nCol = pApi->xColumnCount(pFts);
245809246196
memset(&ctx, 0, sizeof(HighlightContext));
245810
- iCol = sqlite3_value_int(apVal[0]);
246197
+ iCol = fts5ValueClampedInt(apVal[0]);
245811246198
ctx.zOpen = fts5ValueToText(apVal[1]);
245812246199
ctx.zClose = fts5ValueToText(apVal[2]);
245813246200
ctx.iRangeEnd = -1;
245814246201
zEllips = fts5ValueToText(apVal[3]);
245815246202
nToken = (int)(MIN( MAX(sqlite3_value_int64(apVal[4]), 0), 64));
@@ -246137,11 +246524,11 @@
246137246524
const char *z = "non-integer argument passed to function fts5_get_locale()";
246138246525
sqlite3_result_error(pCtx, z, -1);
246139246526
return;
246140246527
}
246141246528
246142
- iCol = sqlite3_value_int(apVal[0]);
246529
+ iCol = fts5ValueClampedInt(apVal[0]);
246143246530
if( iCol<0 || iCol>=pApi->xColumnCount(pFts) ){
246144246531
sqlite3_result_error_code(pCtx, SQLITE_RANGE);
246145246532
return;
246146246533
}
246147246534
@@ -259897,10 +260284,13 @@
259897260284
*pCksum = cksum;
259898260285
return rc;
259899260286
}
259900260287
259901260288
/*
260289
+** This function is purely an internal test. It does not contribute to
260290
+** FTS functionality, or even the integrity-check, in any way.
260291
+**
259902260292
** Check if buffer z[], size n bytes, contains as series of valid utf-8
259903260293
** encoded codepoints. If so, return 0. Otherwise, if the buffer does not
259904260294
** contain valid utf-8, return non-zero.
259905260295
*/
259906260296
static int fts5TestUtf8(const char *z, int n){
@@ -259918,12 +260308,12 @@
259918260308
if( i+2>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
259919260309
i += 3;
259920260310
}else
259921260311
if( (z[i] & 0xF8)==0xF0 ){
259922260312
if( i+3>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
259923
- if( (z[i+2] & 0xC0)!=0x80 ) return 1;
259924
- i += 3;
260313
+ if( (z[i+3] & 0xC0)!=0x80 ) return 1;
260314
+ i += 4;
259925260315
}else{
259926260316
return 1;
259927260317
}
259928260318
}
259929260319
@@ -264813,11 +265203,11 @@
264813265203
int nArg, /* Number of args */
264814265204
sqlite3_value **apUnused /* Function arguments */
264815265205
){
264816265206
assert( nArg==0 );
264817265207
UNUSED_PARAM2(nArg, apUnused);
264818
- sqlite3_result_text(pCtx, "fts5: 2026-08-27 10:58:16 555f31c64d3fcc55df2715a7c8c1cb28503b2c0eb21d950ccdcbf6f577593dd5", -1, SQLITE_TRANSIENT);
265208
+ sqlite3_result_text(pCtx, "fts5: 2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c", -1, SQLITE_TRANSIENT);
264819265209
}
264820265210
264821265211
/*
264822265212
** Implementation of fts5_locale(LOCALE, TEXT) function.
264823265213
**
@@ -265706,79 +266096,10 @@
265706266096
);
265707266097
sqlite3_reset(pStorage->pSavedRow);
265708266098
pStorage->pSavedRow = 0;
265709266099
}
265710266100
265711
-/*
265712
-** This function is called to process a DELETE on a contentless_delete=1
265713
-** table. It adds the tombstone required to delete the entry with rowid
265714
-** iDel. If successful, SQLITE_OK is returned. Or, if an error occurs,
265715
-** an SQLite error code.
265716
-*/
265717
-static int fts5StorageContentlessDelete(Fts5Storage *p, i64 iDel){
265718
- i64 iOrigin = 0;
265719
- sqlite3_stmt *pLookup = 0;
265720
- int rc = SQLITE_OK;
265721
-
265722
- assert( p->pConfig->bContentlessDelete );
265723
- assert( p->pConfig->eContent==FTS5_CONTENT_NONE
265724
- || p->pConfig->eContent==FTS5_CONTENT_UNINDEXED
265725
- );
265726
-
265727
- /* Look up the origin of the document in the %_docsize table. Store
265728
- ** this in stack variable iOrigin. */
265729
- rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
265730
- if( rc==SQLITE_OK ){
265731
- sqlite3_bind_int64(pLookup, 1, iDel);
265732
- if( SQLITE_ROW==sqlite3_step(pLookup) ){
265733
- iOrigin = sqlite3_column_int64(pLookup, 1);
265734
- }
265735
- rc = sqlite3_reset(pLookup);
265736
- }
265737
-
265738
- if( rc==SQLITE_OK && iOrigin!=0 ){
265739
- rc = sqlite3Fts5IndexContentlessDelete(p->pIndex, iOrigin, iDel);
265740
- }
265741
-
265742
- return rc;
265743
-}
265744
-
265745
-/*
265746
-** Insert a record into the %_docsize table. Specifically, do:
265747
-**
265748
-** INSERT OR REPLACE INTO %_docsize(id, sz) VALUES(iRowid, pBuf);
265749
-**
265750
-** If there is no %_docsize table (as happens if the columnsize=0 option
265751
-** is specified when the FTS5 table is created), this function is a no-op.
265752
-*/
265753
-static int fts5StorageInsertDocsize(
265754
- Fts5Storage *p, /* Storage module to write to */
265755
- i64 iRowid, /* id value */
265756
- Fts5Buffer *pBuf /* sz value */
265757
-){
265758
- int rc = SQLITE_OK;
265759
- if( p->pConfig->bColumnsize ){
265760
- sqlite3_stmt *pReplace = 0;
265761
- rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
265762
- if( rc==SQLITE_OK ){
265763
- sqlite3_bind_int64(pReplace, 1, iRowid);
265764
- if( p->pConfig->bContentlessDelete ){
265765
- i64 iOrigin = 0;
265766
- rc = sqlite3Fts5IndexGetOrigin(p->pIndex, &iOrigin);
265767
- sqlite3_bind_int64(pReplace, 3, iOrigin);
265768
- }
265769
- }
265770
- if( rc==SQLITE_OK ){
265771
- sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC);
265772
- sqlite3_step(pReplace);
265773
- rc = sqlite3_reset(pReplace);
265774
- sqlite3_bind_null(pReplace, 2);
265775
- }
265776
- }
265777
- return rc;
265778
-}
265779
-
265780266101
/*
265781266102
** Load the contents of the "averages" record from disk into the
265782266103
** p->nTotalRow and p->aTotalSize[] variables. If successful, and if
265783266104
** argument bCache is true, set the p->bTotalsValid flag to indicate
265784266105
** that the contents of aTotalSize[] and nTotalRow are valid until
@@ -265819,10 +266140,114 @@
265819266140
}
265820266141
sqlite3_free(buf.p);
265821266142
265822266143
return rc;
265823266144
}
266145
+
266146
+static int fts5StorageDecodeSizeArray(
266147
+ int *aCol, int nCol, /* Array to populate */
266148
+ const u8 *aBlob, int nBlob /* Record to read varints from */
266149
+){
266150
+ int i;
266151
+ int iOff = 0;
266152
+ for(i=0; i<nCol; i++){
266153
+ if( iOff>=nBlob ) return 1;
266154
+ iOff += fts5GetVarint32(&aBlob[iOff], aCol[i]);
266155
+ }
266156
+ return (iOff!=nBlob);
266157
+}
266158
+
266159
+/*
266160
+** This function is called to process a DELETE on a contentless_delete=1
266161
+** table. It adds the tombstone required to delete the entry with rowid
266162
+** iDel. If successful, SQLITE_OK is returned. Or, if an error occurs,
266163
+** an SQLite error code.
266164
+*/
266165
+static int fts5StorageContentlessDelete(Fts5Storage *p, i64 iDel){
266166
+ i64 iOrigin = 0;
266167
+ sqlite3_stmt *pLookup = 0;
266168
+ int rc = SQLITE_OK;
266169
+
266170
+ assert( p->pConfig->bContentlessDelete );
266171
+ assert( p->pConfig->eContent==FTS5_CONTENT_NONE
266172
+ || p->pConfig->eContent==FTS5_CONTENT_UNINDEXED
266173
+ );
266174
+
266175
+ rc = fts5StorageLoadTotals(p, 1);
266176
+ if( rc!=SQLITE_OK ) return rc;
266177
+
266178
+ /* Look up the origin of the document in the %_docsize table. Store
266179
+ ** this in stack variable iOrigin. */
266180
+ rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
266181
+ if( rc==SQLITE_OK ){
266182
+ int rc2;
266183
+ sqlite3_bind_int64(pLookup, 1, iDel);
266184
+ if( SQLITE_ROW==sqlite3_step(pLookup) ){
266185
+ int *aCol = (int*)sqlite3_malloc64(p->pConfig->nCol * sizeof(int));
266186
+ if( aCol==0 ){
266187
+ rc = SQLITE_NOMEM;
266188
+ }else{
266189
+ const u8 *aBlob = sqlite3_column_blob(pLookup, 0);
266190
+ int nBlob = sqlite3_column_bytes(pLookup, 0);
266191
+ int ii;
266192
+ if( fts5StorageDecodeSizeArray(aCol, p->pConfig->nCol, aBlob, nBlob) ){
266193
+ rc = SQLITE_CORRUPT_VTAB;
266194
+ }else{
266195
+ for(ii=0; ii<p->pConfig->nCol; ii++){
266196
+ p->aTotalSize[ii] -= aCol[ii];
266197
+ }
266198
+ }
266199
+ sqlite3_free(aCol);
266200
+ }
266201
+ iOrigin = sqlite3_column_int(pLookup, 1);
266202
+ }
266203
+ rc2 = sqlite3_reset(pLookup);
266204
+ if( rc==SQLITE_OK ) rc = rc2;
266205
+ }
266206
+
266207
+ if( rc==SQLITE_OK && iOrigin!=0 ){
266208
+ rc = sqlite3Fts5IndexContentlessDelete(p->pIndex, iOrigin, iDel);
266209
+ p->nTotalRow--;
266210
+ }
266211
+
266212
+ return rc;
266213
+}
266214
+
266215
+/*
266216
+** Insert a record into the %_docsize table. Specifically, do:
266217
+**
266218
+** INSERT OR REPLACE INTO %_docsize(id, sz) VALUES(iRowid, pBuf);
266219
+**
266220
+** If there is no %_docsize table (as happens if the columnsize=0 option
266221
+** is specified when the FTS5 table is created), this function is a no-op.
266222
+*/
266223
+static int fts5StorageInsertDocsize(
266224
+ Fts5Storage *p, /* Storage module to write to */
266225
+ i64 iRowid, /* id value */
266226
+ Fts5Buffer *pBuf /* sz value */
266227
+){
266228
+ int rc = SQLITE_OK;
266229
+ if( p->pConfig->bColumnsize ){
266230
+ sqlite3_stmt *pReplace = 0;
266231
+ rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
266232
+ if( rc==SQLITE_OK ){
266233
+ sqlite3_bind_int64(pReplace, 1, iRowid);
266234
+ if( p->pConfig->bContentlessDelete ){
266235
+ i64 iOrigin = 0;
266236
+ rc = sqlite3Fts5IndexGetOrigin(p->pIndex, &iOrigin);
266237
+ sqlite3_bind_int64(pReplace, 3, iOrigin);
266238
+ }
266239
+ }
266240
+ if( rc==SQLITE_OK ){
266241
+ sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC);
266242
+ sqlite3_step(pReplace);
266243
+ rc = sqlite3_reset(pReplace);
266244
+ sqlite3_bind_null(pReplace, 2);
266245
+ }
266246
+ }
266247
+ return rc;
266248
+}
265824266249
265825266250
/*
265826266251
** Remove a row from the FTS table.
265827266252
*/
265828266253
static int sqlite3Fts5StorageDelete(
@@ -266481,23 +266906,10 @@
266481266906
}else{
266482266907
sqlite3_finalize(pStmt);
266483266908
}
266484266909
}
266485266910
266486
-static int fts5StorageDecodeSizeArray(
266487
- int *aCol, int nCol, /* Array to populate */
266488
- const u8 *aBlob, int nBlob /* Record to read varints from */
266489
-){
266490
- int i;
266491
- int iOff = 0;
266492
- for(i=0; i<nCol; i++){
266493
- if( iOff>=nBlob ) return 1;
266494
- iOff += fts5GetVarint32(&aBlob[iOff], aCol[i]);
266495
- }
266496
- return (iOff!=nBlob);
266497
-}
266498
-
266499266911
/*
266500266912
** Argument aCol points to an array of integers containing one entry for
266501266913
** each table column. This function reads the %_docsize record for the
266502266914
** specified rowid and populates aCol[] with the results.
266503266915
**
266504266916
--- 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 ** 555f31c64d3fcc55df2715a7c8c1cb28503b with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-08-27 10:58:16 555f31c64d3fcc55df2715a7c8c1cb28503b2c0eb21d950ccdcbf6f577593dd5"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-08-27T10:58:16.680Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -3842,10 +3842,15 @@
3842 ** authorizer callback is the name of the database ("main", "temp",
3843 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
3844 ** is the name of the inner-most trigger or view that is responsible for
3845 ** the access attempt or NULL if this access attempt is directly from
3846 ** top-level SQL code.
 
 
 
 
 
3847 */
3848 /******************************************* 3rd ************ 4th ***********/
3849 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
3850 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
3851 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
@@ -17208,10 +17213,14 @@
17208 #endif
17209
17210 #if defined(SQLITE_USE_SEH) && !defined(SQLITE_OMIT_WAL)
17211 SQLITE_PRIVATE int sqlite3PagerWalSystemErrno(Pager*);
17212 #endif
 
 
 
 
17213
17214 #endif /* SQLITE_PAGER_H */
17215
17216 /************** End of pager.h ***********************************************/
17217 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -18590,11 +18599,11 @@
18590 */
18591 #if !SQLITE_THREADSAFE
18592 # define SQLITE_MUTEX_OMIT
18593 #endif
18594 #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
18595 # if SQLITE_OS_UNIX
18596 # define SQLITE_MUTEX_PTHREADS
18597 # elif SQLITE_OS_WIN
18598 # define SQLITE_MUTEX_W32
18599 # else
18600 # define SQLITE_MUTEX_NOOP
@@ -22645,11 +22654,20 @@
22645 #endif
22646
22647 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
22648 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
22649 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
 
 
 
 
 
 
 
 
22650 SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq*);
 
22651 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
22652 SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8);
22653 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr);
22654 SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr);
22655 SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*);
@@ -25965,10 +25983,11 @@
25965 if( ms>0.999 ) ms = 0.999;
25966 }
25967 }else{
25968 s = 0;
25969 }
 
25970 p->validJD = 0;
25971 p->rawS = 0;
25972 p->validHMS = 1;
25973 p->h = h;
25974 p->m = m;
@@ -26001,10 +26020,14 @@
26001 D = p->D;
26002 }else{
26003 Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
26004 M = 1;
26005 D = 1;
 
 
 
 
26006 }
26007 if( Y<-4713 || Y>9999 || p->rawS ){
26008 datetimeError(p);
26009 return;
26010 }
@@ -26039,10 +26062,14 @@
26039 */
26040 static void computeFloor(DateTime *p){
26041 assert( p->validYMD || p->isError );
26042 assert( p->D>=0 && p->D<=31 );
26043 assert( p->M>=0 && p->M<=12 );
 
 
 
 
26044 if( p->D<=28 ){
26045 p->nFloor = 0;
26046 }else if( (1<<p->M) & 0x15aa ){
26047 p->nFloor = 0;
26048 }else if( p->M!=2 ){
@@ -31422,12 +31449,15 @@
31422 # define ALIGN128 __declspec(align(128))
31423 #else
31424 # define ALIGN128
31425 #endif
31426
 
31427 #pragma warning(push)
31428 #pragma warning(disable: 4324)
 
 
31429 /*
31430 ** Each SQLite mutex is an instance of the following structure.
31431 **
31432 ** The ALIGN128 macro attempts to force 128-byte alignment on mutexes,
31433 ** so that adjacent mutex objects are always on different cache lines
@@ -31446,11 +31476,13 @@
31446 volatile int nRef; /* Number of entrances */
31447 volatile DWORD owner; /* Thread holding this mutex */
31448 volatile LONG trace; /* True to trace changes */
31449 #endif
31450 };
 
31451 #pragma warning(pop)
 
31452
31453 #ifdef SQLITE_DEBUG
31454 /*
31455 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
31456 ** intended for use only inside assert() statements.
@@ -32860,13 +32892,20 @@
32860 # define SQLITE_PRINT_BUF_SIZE 70
32861 #endif
32862 #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
32863
32864 /*
32865 ** Hard limit on the precision of floating-point conversions.
 
32866 */
32867 #ifndef SQLITE_PRINTF_PRECISION_LIMIT
 
 
 
 
 
 
32868 # define SQLITE_FP_PRECISION_LIMIT 100000000
32869 #endif
32870
32871 /* Forward reference */
32872 static void sqlite3StrAppend64(sqlite3_str *p, const char *z, i64 N);
@@ -33222,15 +33261,13 @@
33222 realvalue = getDoubleArg(pArgList);
33223 }else{
33224 realvalue = va_arg(ap,double);
33225 }
33226 if( precision<0 ) precision = 6; /* Set default precision */
33227 #ifdef SQLITE_FP_PRECISION_LIMIT
33228 if( precision>SQLITE_FP_PRECISION_LIMIT ){
33229 precision = SQLITE_FP_PRECISION_LIMIT;
33230 }
33231 #endif
33232 if( xtype==etFLOAT ){
33233 iRound = -precision;
33234 }else if( xtype==etGENERIC ){
33235 if( precision==0 ) precision = 1;
33236 iRound = precision;
@@ -33316,11 +33353,11 @@
33316 if( szBufNeeded + pAccum->nChar >= pAccum->nAlloc ){
33317 if( pAccum->mxAlloc==0 && pAccum->accError==0 ){
33318 /* Unable to allocate space in pAccum, perhaps because it
33319 ** is coming from sqlite3_snprintf() or similar. We'll have
33320 ** to render into temporary space and the memcpy() it over. */
33321 bufpt = sqlite3_malloc(szBufNeeded);
33322 if( bufpt==0 ){
33323 sqlite3StrAccumSetError(pAccum, SQLITE_NOMEM);
33324 return;
33325 }
33326 zExtra = bufpt;
@@ -36345,13 +36382,11 @@
36345 if( c>=0xc0 ){ \
36346 c = sqlite3Utf8Trans1[c-0xc0]; \
36347 while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
36348 c = (c<<6) + (0x3f & *(zIn++)); \
36349 } \
36350 if( c<0x80 \
36351 || (c&0xFFFFF800)==0xD800 \
36352 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
36353 }
36354 SQLITE_PRIVATE u32 sqlite3Utf8Read(
36355 const unsigned char **pz /* Pointer to string from which to read char */
36356 ){
36357 unsigned int c;
@@ -36363,13 +36398,11 @@
36363 if( c>=0xc0 ){
36364 c = sqlite3Utf8Trans1[c-0xc0];
36365 while( (*(*pz) & 0xc0)==0x80 ){
36366 c = (c<<6) + (0x3f & *((*pz)++));
36367 }
36368 if( c<0x80
36369 || (c&0xFFFFF800)==0xD800
36370 || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; }
36371 }
36372 return c;
36373 }
36374
36375 /*
@@ -36765,11 +36798,10 @@
36765 z[0] = 0;
36766 z = zBuf;
36767 c = sqlite3Utf8Read((const u8**)&z);
36768 t = i;
36769 if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
36770 if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
36771 assert( c==t );
36772 assert( (z-zBuf)==n );
36773 }
36774 }
36775 #endif /* SQLITE_TEST */
@@ -38324,11 +38356,11 @@
38324 SQLITE_PRIVATE int sqlite3GetUInt32(const char *z, u32 *pI){
38325 u64 v = 0;
38326 int i;
38327 for(i=0; sqlite3Isdigit(z[i]); i++){
38328 v = v*10 + z[i] - '0';
38329 if( v>4294967296LL ){ *pI = 0; return 0; }
38330 }
38331 if( i==0 || z[i]!=0 ){ *pI = 0; return 0; }
38332 *pI = (u32)v;
38333 return 1;
38334 }
@@ -49206,11 +49238,10 @@
49206
49207 /*
49208 ** Include the header file for the Windows VFS.
49209 */
49210 /* #include "os_win.h" */
49211 #define SQLITE_WIN32_HAS_WIDE 1
49212
49213 /*
49214 ** This constant should already be defined (in the "WinDef.h" SDK file).
49215 */
49216 #ifndef MAX_PATH
@@ -49521,28 +49552,10 @@
49521 static void winMemShutdown(void *pAppData);
49522
49523 SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void);
49524 #endif /* SQLITE_WIN32_MALLOC */
49525
49526 /*
49527 ** The following variable is (normally) set once and never changes
49528 ** thereafter. It records whether the operating system is Win9x
49529 ** or WinNT.
49530 **
49531 ** 0: Operating system unknown.
49532 ** 1: Operating system is Win9x.
49533 ** 2: Operating system is WinNT.
49534 **
49535 ** In order to facilitate testing on a WinNT system, the test fixture
49536 ** can manually set this value to 1 to emulate Win98 behavior.
49537 */
49538 #ifdef SQLITE_TEST
49539 SQLITE_API LONG volatile sqlite3_os_type = 0;
49540 #else
49541 static LONG volatile sqlite3_os_type = 0;
49542 #endif
49543
49544 #ifndef SYSCALL
49545 # define SYSCALL sqlite3_syscall_ptr
49546 #endif
49547
49548 /*
@@ -49890,10 +49903,13 @@
49890 { "cygwin_conv_path", (SYSCALL)0, 0 },
49891 #endif
49892 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
49893 const void *, void *, size_t))aSyscall[58].pCurrent)
49894
 
 
 
49895 }; /* End of the overrideable system calls */
49896
49897 /*
49898 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
49899 ** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -50060,10 +50076,11 @@
50060 sqlite3_mutex_leave(pMainMtx);
50061 return rc;
50062 }
50063 #endif /* SQLITE_WIN32_MALLOC */
50064
 
50065 /*
50066 ** This function outputs the specified (ANSI) string to the Win32 debugger
50067 ** (if available). Undocumented. Might go away at any moment.
50068 */
50069 SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
@@ -50096,10 +50113,11 @@
50096 while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
50097 TRUE))==WAIT_IO_COMPLETION ){}
50098 return rc;
50099 }
50100 #endif
 
50101
50102 #ifdef SQLITE_WIN32_MALLOC
50103 /*
50104 ** Allocate nBytes of memory.
50105 */
@@ -50356,10 +50374,11 @@
50356 zText = 0;
50357 }
50358 return zText;
50359 }
50360
 
50361 /*
50362 ** Convert an ANSI string to Microsoft Unicode, using the ANSI or OEM
50363 ** code page.
50364 **
50365 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50385,11 +50404,10 @@
50385 zMbcsText = 0;
50386 }
50387 return zMbcsText;
50388 }
50389
50390 #ifdef _WIN32
50391 /*
50392 ** Convert a Microsoft Unicode string to a multi-byte character string,
50393 ** using the ANSI or OEM code page.
50394 **
50395 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50413,11 +50431,10 @@
50413 sqlite3_free(zText);
50414 zText = 0;
50415 }
50416 return zText;
50417 }
50418 #endif /* _WIN32 */
50419
50420 /*
50421 ** Convert a multi-byte character string to UTF-8.
50422 **
50423 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50433,11 +50450,10 @@
50433 zTextUtf8 = winUnicodeToUtf8(zTmpWide);
50434 sqlite3_free(zTmpWide);
50435 return zTextUtf8;
50436 }
50437
50438 #ifdef _WIN32
50439 /*
50440 ** Convert a UTF-8 string to a multi-byte character string.
50441 **
50442 ** Space to hold the returned string is obtained from sqlite3_malloc().
50443 */
@@ -50483,11 +50499,10 @@
50483 #ifndef SQLITE_OMIT_AUTOINIT
50484 if( sqlite3_initialize() ) return 0;
50485 #endif
50486 return winUnicodeToUtf8(zWideText);
50487 }
50488 #endif /* _WIN32 */
50489
50490 /*
50491 ** This is a public wrapper for the winMbcsToUtf8() function.
50492 */
50493 SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zText){
@@ -50501,11 +50516,10 @@
50501 if( sqlite3_initialize() ) return 0;
50502 #endif
50503 return winMbcsToUtf8(zText, osAreFileApisANSI());
50504 }
50505
50506 #ifdef _WIN32
50507 /*
50508 ** This is a public wrapper for the winMbcsToUtf8() function.
50509 */
50510 SQLITE_API char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
50511 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -50764,17 +50778,17 @@
50764 *pError = e;
50765 }
50766 return 0;
50767 }
50768 if( winIoerrCanRetry1(e) ){
50769 sqlite3_win32_sleep(winIoerrRetryDelay*(1+*pnRetry));
50770 ++*pnRetry;
50771 return 1;
50772 }
50773 #if defined(winIoerrCanRetry2)
50774 else if( winIoerrCanRetry2(e) ){
50775 sqlite3_win32_sleep(winIoerrRetryDelay*(1+*pnRetry));
50776 ++*pnRetry;
50777 return 1;
50778 }
50779 #endif
50780 if( pError ){
@@ -51000,11 +51014,11 @@
51000 #endif
51001
51002 do{
51003 rc = osCloseHandle(pFile->h);
51004 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
51005 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
51006 if( rc ){
51007 pFile->h = NULL;
51008 }
51009 OpenCounter(-1);
51010 OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
@@ -51614,11 +51628,11 @@
51614 ));
51615 return rc;
51616 }
51617
51618 cnt--;
51619 if( cnt>0 ) sqlite3_win32_sleep(1);
51620 }
51621 gotPendingLock = res;
51622 }
51623
51624 /* Acquire a shared lock
@@ -51823,11 +51837,11 @@
51823 }
51824 }
51825
51826 /* Forward references to VFS helper methods used for temporary files */
51827 static int winGetTempname(sqlite3_vfs *, char **);
51828 static int winIsDir(const void *);
51829 static BOOL winIsLongPathPrefix(const char *);
51830 static BOOL winIsDriveLetterAndColon(const char *);
51831
51832 /*
51833 ** Control and query of the open file handle.
@@ -52055,15 +52069,14 @@
52055 ** Note: If the function cygwin_conv_path() fails, only
52056 ** UTF-8 -> UTF-16 conversion will be done. This can only
52057 ** happen when the file path >32k, in which case winUtf8ToUnicode()
52058 ** will fail too.
52059 */
52060 static void *winConvertFromUtf8Filename(const char *zFilename){
52061 void *zConverted = 0;
52062 #ifdef __CYGWIN__
52063 int nChar;
52064 LPWSTR zWideFilename;
52065
52066 if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
52067 && winIsDirSep(zFilename[2])) ){
52068 i64 nByte;
52069 int convertflag = CCP_POSIX_TO_WIN_W;
@@ -52073,24 +52086,23 @@
52073 if( nByte>0 ){
52074 zConverted = sqlite3MallocZero(12+(u64)nByte);
52075 if ( zConverted==0 ){
52076 return zConverted;
52077 }
52078 zWideFilename = zConverted;
52079 /* Filenames should be prefixed, except when converted
52080 * full path already starts with "\\?\". */
52081 if( osCygwin_conv_path(convertflag, zFilename,
52082 zWideFilename+4, nByte)==0 ){
52083 if( (convertflag&CCP_RELATIVE) ){
52084 memmove(zWideFilename, zWideFilename+4, nByte);
52085 }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){
52086 memcpy(zWideFilename, L"\\\\?\\", 8);
52087 }else if( zWideFilename[6]!='?' ){
52088 memmove(zWideFilename+6, zWideFilename+4, nByte);
52089 memcpy(zWideFilename, L"\\\\?\\UNC", 14);
52090 }else{
52091 memmove(zWideFilename, zWideFilename+4, nByte);
52092 }
52093 return zConverted;
52094 }
52095 sqlite3_free(zConverted);
52096 }
@@ -52097,32 +52109,31 @@
52097 }
52098 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
52099 if( nChar==0 ){
52100 return 0;
52101 }
52102 zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 );
52103 if( zWideFilename==0 ){
52104 return 0;
52105 }
52106 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
52107 zWideFilename, nChar);
52108 if( nChar==0 ){
52109 sqlite3_free(zWideFilename);
52110 zWideFilename = 0;
52111 }else if( nChar>MAX_PATH
52112 && winIsDriveLetterAndColon(zFilename)
52113 && winIsDirSep(zFilename[2]) ){
52114 memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR));
52115 zWideFilename[2] = '\\';
52116 memcpy(zWideFilename, L"\\\\?\\", 8);
52117 }else if( nChar>MAX_PATH
52118 && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
52119 && zFilename[2] != '?' ){
52120 memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR));
52121 memcpy(zWideFilename, L"\\\\?\\UNC", 14);
52122 }
52123 zConverted = zWideFilename;
52124 #else /* if !defined(__CYGWIN__) */
52125 zConverted = winUtf8ToUnicode(zFilename);
52126 #endif /* __CYGWIN__ */
52127 /* caller will handle out of memory */
52128 return zConverted;
@@ -52340,11 +52351,11 @@
52340 const char *zUtf8, /* File to open */
52341 int *pbReadonly, /* IN/OUT: True for readonly handle */
52342 HANDLE *ph /* OUT: New HANDLE for file */
52343 ){
52344 int rc = SQLITE_OK;
52345 void *zConverted = 0;
52346 int bReadonly = *pbReadonly;
52347 HANDLE h = INVALID_HANDLE_VALUE;
52348
52349 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
52350 const DWORD flag_overlapped = FILE_FLAG_OVERLAPPED;
@@ -52368,11 +52379,11 @@
52368 }
52369
52370 /* TODO: platforms.
52371 ** TODO: retry-on-ioerr.
52372 */
52373 h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */
52374 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
52375 FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
52376 NULL, /* lpSecurityAttributes */
52377 OPEN_ALWAYS, /* dwCreationDisposition */
52378 FILE_ATTRIBUTE_NORMAL|flag_overlapped,
@@ -52465,10 +52476,27 @@
52465 return 1;
52466 }
52467 }
52468 return sqlite3_win_test_unc_locking;
52469 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52470
52471 /*
52472 ** Open the shared-memory area associated with database file pDbFd.
52473 */
52474 static int winOpenSharedMemory(winFile *pDbFd){
@@ -52491,11 +52519,15 @@
52491 return SQLITE_IOERR_NOMEM_BKPT;
52492 }
52493 pNew->zFilename = (char*)&pNew[1];
52494 pNew->hSharedShm = INVALID_HANDLE_VALUE;
52495 pNew->isUnlocked = 1;
52496 pNew->bUseSharedLockHandle = winIsUNCPath(pDbFd->zPath);
 
 
 
 
52497 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
52498 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
52499
52500 /* Look to see if there is an existing winShmNode that can be used.
52501 ** If no matching winShmNode currently exists, then create a new one. */
@@ -53331,11 +53363,11 @@
53331 if( !azDirs[1] ) azDirs[1] = osGetenv("TMPDIR");
53332 if( !azDirs[2] ) azDirs[2] = osGetenv("TMP");
53333 if( !azDirs[3] ) azDirs[3] = osGetenv("TEMP");
53334 if( !azDirs[4] ) azDirs[4] = osGetenv("USERPROFILE");
53335 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
53336 void *zConverted;
53337 if( zDir==0 ) continue;
53338 /* If the path starts with a drive letter followed by the colon
53339 ** character, assume it is already a native Win32 path; otherwise,
53340 ** it must be converted to a native Win32 path via the Cygwin API
53341 ** prior to using it.
@@ -53372,16 +53404,15 @@
53372 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
53373 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
53374 "winGetTempname2", 0);
53375 }
53376 zMulti = winUnicodeToUtf8(zWidePath);
 
53377 if( zMulti ){
53378 sqlite3_snprintf(nMax, zBuf, "%s", zMulti);
53379 sqlite3_free(zMulti);
53380 sqlite3_free(zWidePath);
53381 }else{
53382 sqlite3_free(zWidePath);
53383 sqlite3_free(zBuf);
53384 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
53385 return SQLITE_IOERR_NOMEM_BKPT;
53386 }
53387 }
@@ -53436,18 +53467,18 @@
53436 /*
53437 ** Return TRUE if the named file is really a directory. Return false if
53438 ** it is something other than a directory, or if there is any kind of memory
53439 ** allocation failure.
53440 */
53441 static int winIsDir(const void *zConverted){
53442 DWORD attr;
53443 int rc = 0;
53444 DWORD lastErrno;
53445 int cnt = 0;
53446 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
53447 memset(&sAttrData, 0, sizeof(sAttrData));
53448 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
53449 GetFileExInfoStandard,
53450 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
53451 if( !rc ){
53452 return 0; /* Invalid name? */
53453 }
@@ -53485,11 +53516,11 @@
53485 DWORD dwShareMode;
53486 DWORD dwCreationDisposition;
53487 DWORD dwFlagsAndAttributes = 0;
53488 winVfsAppData *pAppData;
53489 winFile *pFile = (winFile*)id;
53490 void *zConverted; /* Filename in OS encoding */
53491 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
53492 int cnt = 0;
53493 int isRO = 0; /* file is known to be accessible readonly */
53494
53495 /* If argument zPath is a NULL pointer, this function is required to open
@@ -53618,11 +53649,11 @@
53618 | FILE_FLAG_DELETE_ON_CLOSE;
53619 }else{
53620 dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
53621 }
53622 do{
53623 h = osCreateFileW((LPCWSTR)zConverted,
53624 dwDesiredAccess,
53625 dwShareMode, NULL,
53626 dwCreationDisposition,
53627 dwFlagsAndAttributes,
53628 NULL);
@@ -53714,11 +53745,11 @@
53714 ){
53715 int cnt = 0;
53716 int rc;
53717 DWORD attr;
53718 DWORD lastErrno = 0;
53719 void *zConverted;
53720 UNUSED_PARAMETER(pVfs);
53721 UNUSED_PARAMETER(syncDir);
53722
53723 SimulateIOError(return SQLITE_IOERR_DELETE);
53724 OSTRACE(("DELETE name=%s, syncDir=%d\n", zFilename, syncDir));
@@ -53774,11 +53805,11 @@
53774 ){
53775 DWORD attr;
53776 int rc = 0;
53777 int cnt = 0;
53778 DWORD lastErrno = 0;
53779 void *zConverted;
53780 int noRetry = 0; /* Do not use winRetryIoerr() */
53781 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
53782 UNUSED_PARAMETER(pVfs);
53783
53784 if( (flags & NORETRY)!=0 ){
@@ -53801,11 +53832,11 @@
53801 if( zConverted==0 ){
53802 OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
53803 return SQLITE_IOERR_NOMEM_BKPT;
53804 }
53805 memset(&sAttrData, 0, sizeof(sAttrData));
53806 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
53807 GetFileExInfoStandard,
53808 &sAttrData))
53809 && !noRetry
53810 && winRetryIoerr(&cnt, &lastErrno)
53811 ){ /* Loop until true */}
@@ -53983,11 +54014,11 @@
53983 const char *zRelative, /* Possibly relative input path */
53984 int nFull, /* Size of output buffer in bytes */
53985 char *zFull /* Output buffer */
53986 ){
53987 int nByte;
53988 void *zConverted;
53989 char *zOut;
53990
53991 /* If this path name begins with "/X:" or "\\?\", where "X" is any
53992 ** alphabetic character, discard the initial "/" from the pathname.
53993 */
@@ -54096,23 +54127,23 @@
54096 if( zConverted==0 ){
54097 return SQLITE_IOERR_NOMEM_BKPT;
54098 }
54099 {
54100 LPWSTR zTemp;
54101 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
54102 if( nByte==0 ){
54103 sqlite3_free(zConverted);
54104 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
54105 "winFullPathname1", zRelative);
54106 }
54107 nByte += 3;
54108 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
54109 if( zTemp==0 ){
54110 sqlite3_free(zConverted);
54111 return SQLITE_IOERR_NOMEM_BKPT;
54112 }
54113 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
54114 if( nByte==0 ){
54115 sqlite3_free(zConverted);
54116 sqlite3_free(zTemp);
54117 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
54118 "winFullPathname2", zRelative);
@@ -54168,17 +54199,17 @@
54168 ** Interfaces for opening a shared library, finding entry points
54169 ** within the shared library, and closing the shared library.
54170 */
54171 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
54172 HANDLE h = 0;
54173 void *zConverted = winConvertFromUtf8Filename(zFilename);
54174 UNUSED_PARAMETER(pVfs);
54175 if( zConverted==0 ){
54176 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
54177 return 0;
54178 }
54179 h = osLoadLibraryW ? osLoadLibraryW((LPCWSTR)zConverted) : 0;
54180 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
54181 sqlite3_free(zConverted);
54182 return (void*)h;
54183 }
54184 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
@@ -54282,11 +54313,11 @@
54282
54283 /*
54284 ** Sleep for a little while. Return the amount of time slept.
54285 */
54286 static int winSleep(sqlite3_vfs *pVfs, int microsec){
54287 sqlite3_win32_sleep((microsec+999)/1000);
54288 UNUSED_PARAMETER(pVfs);
54289 return ((microsec+999)/1000)*1000;
54290 }
54291
54292 /*
@@ -54489,11 +54520,11 @@
54489 winNextSystemCall, /* xNextSystemCall */
54490 };
54491
54492 /* Double-check that the aSyscall[] array has been constructed
54493 ** correctly. See ticket [bb3a86e890c8e96ab] */
54494 assert( ArraySize(aSyscall)==59 );
54495 assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
54496 assert( strcmp(aSyscall[8].zName,"FreeLibrary")==0 );
54497 assert( strcmp(aSyscall[16].zName,"GetSystemInfo")==0 );
54498 assert( strcmp(aSyscall[24].zName,"HeapReAlloc")==0 );
54499 assert( strcmp(aSyscall[32].zName,"MapViewOfFileFromApp")==0 );
@@ -58880,10 +58911,14 @@
58880 #endif
58881
58882 #ifdef SQLITE_USE_SEH
58883 SQLITE_PRIVATE int sqlite3WalSystemErrno(Wal*);
58884 #endif
 
 
 
 
58885
58886 #endif /* ifndef SQLITE_OMIT_WAL */
58887 #endif /* SQLITE_WAL_H */
58888
58889 /************** End of wal.h *************************************************/
@@ -65755,10 +65790,24 @@
65755 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
65756 return sqlite3PcacheRefCount(pPager->pPCache);
65757 }
65758 #endif
65759
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65760 /*
65761 ** Return the approximate number of bytes of memory currently
65762 ** used by the pager and its associated cache.
65763 */
65764 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
@@ -67351,14 +67400,45 @@
67351 ** walIteratorInit() - Create a new iterator,
67352 ** walIteratorNext() - Step an iterator,
67353 ** walIteratorFree() - Free an iterator.
67354 **
67355 ** This functionality is used by the checkpoint code (see walCheckpoint()).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67356 */
67357 struct WalIterator {
67358 u32 iPrior; /* Last result returned from the iterator */
67359 int nSegment; /* Number of entries in aSegment[] */
 
67360 struct WalSegment {
67361 int iNext; /* Next slot in aIndex[] not yet returned */
67362 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
67363 u32 *aPgno; /* Array of page numbers. */
67364 int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
@@ -67367,10 +67447,11 @@
67367 };
67368
67369 /* Size (in bytes) of a WalIterator object suitable for N or fewer segments */
67370 #define SZ_WALITERATOR(N) \
67371 (offsetof(WalIterator,aSegment)+(N)*sizeof(struct WalSegment))
 
67372
67373 /*
67374 ** Define the parameters of the hash tables in the wal-index file. There
67375 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
67376 ** wal-index.
@@ -68530,28 +68611,42 @@
68530 static int walIteratorNext(
68531 WalIterator *p, /* Iterator */
68532 u32 *piPage, /* OUT: The page number of the next page */
68533 u32 *piFrame /* OUT: Wal frame index of next page */
68534 ){
68535 u32 iMin; /* Result pgno must be greater than iMin */
68536 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
68537 int i; /* For looping through segments */
68538
68539 iMin = p->iPrior;
68540 assert( iMin<0xffffffff );
68541 for(i=p->nSegment-1; i>=0; i--){
68542 struct WalSegment *pSegment = &p->aSegment[i];
68543 while( pSegment->iNext<pSegment->nEntry ){
68544 u32 iPg = pSegment->aPgno[pSegment->aIndex[pSegment->iNext]];
68545 if( iPg>iMin ){
68546 if( iPg<iRet ){
68547 iRet = iPg;
68548 *piFrame = pSegment->iZero + pSegment->aIndex[pSegment->iNext];
68549 }
68550 break;
68551 }
68552 pSegment->iNext++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68553 }
68554 }
68555
68556 *piPage = p->iPrior = iRet;
68557 return (iRet==0xFFFFFFFF);
@@ -68716,63 +68811,99 @@
68716 **
68717 ** The calling routine should invoke walIteratorFree() to destroy the
68718 ** WalIterator object when it has finished with it.
68719 */
68720 static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
 
 
 
68721 WalIterator *p; /* Return value */
68722 int nSegment; /* Number of segments to merge */
68723 u32 iLast; /* Last frame in log */
68724 sqlite3_int64 nByte; /* Number of bytes to allocate */
 
68725 int i; /* Iterator variable */
68726 ht_slot *aTmp; /* Temp space used by merge-sort */
68727 int rc = SQLITE_OK; /* Return Code */
 
68728
68729 /* This routine only runs while holding the checkpoint lock. And
68730 ** it only runs if there is actually content in the log (mxFrame>0).
68731 */
68732 assert( pWal->ckptLock && pWal->hdr.mxFrame>0 );
 
68733 iLast = pWal->hdr.mxFrame;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68734
68735 /* Allocate space for the WalIterator object. */
68736 nSegment = walFramePage(iLast) + 1;
68737 nByte = SZ_WALITERATOR(nSegment)
68738 + iLast*sizeof(ht_slot);
68739 p = (WalIterator *)sqlite3_malloc64(nByte
68740 + sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
68741 );
68742 if( !p ){
68743 return SQLITE_NOMEM_BKPT;
68744 }
68745 memset(p, 0, nByte);
68746 p->nSegment = nSegment;
68747 aTmp = (ht_slot*)&(((u8*)p)[nByte]);
 
 
 
 
 
 
 
68748 SEH_FREE_ON_ERROR(0, p);
68749 for(i=walFramePage(nBackfill+1); rc==SQLITE_OK && i<nSegment; i++){
68750 WalHashLoc sLoc;
68751
68752 rc = walHashGet(pWal, i, &sLoc);
68753 if( rc==SQLITE_OK ){
68754 int j; /* Counter variable */
68755 int nEntry; /* Number of entries in this segment */
68756 ht_slot *aIndex; /* Sorted index for this segment */
68757
68758 if( (i+1)==nSegment ){
68759 nEntry = (int)(iLast - sLoc.iZero);
68760 }else{
68761 nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno);
68762 }
68763 aIndex = &((ht_slot *)&p->aSegment[p->nSegment])[sLoc.iZero];
68764 sLoc.iZero++;
68765
68766 for(j=0; j<nEntry; j++){
68767 aIndex[j] = (ht_slot)j;
68768 }
68769 walMergesort((u32 *)sLoc.aPgno, aTmp, aIndex, &nEntry);
68770 p->aSegment[i].iZero = sLoc.iZero;
68771 p->aSegment[i].nEntry = nEntry;
68772 p->aSegment[i].aIndex = aIndex;
68773 p->aSegment[i].aPgno = (u32 *)sLoc.aPgno;
 
 
 
 
 
 
 
 
 
 
 
 
68774 }
68775 }
68776 if( rc!=SQLITE_OK ){
68777 SEH_FREE_ON_ERROR(p, 0);
68778 walIteratorFree(p);
@@ -71409,10 +71540,68 @@
71409 /* Return the sqlite3_file object for the WAL file
71410 */
71411 SQLITE_PRIVATE sqlite3_file *sqlite3WalFile(Wal *pWal){
71412 return pWal->pWalFd;
71413 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71414
71415 #endif /* #ifndef SQLITE_OMIT_WAL */
71416
71417 /************** End of wal.c *************************************************/
71418 /************** Begin file btmutex.c *****************************************/
@@ -74646,11 +74835,11 @@
74646 }
74647 next = get2byte(&data[pc]);
74648 size = get2byte(&data[pc+2]);
74649 if( size<4 && sqlite3FaultSim(422)==SQLITE_OK ){
74650 /* Minimum freeblock size is 4. Enable fault-sim 422 to disable this
74651 ** check to reach interesting error stats. However, disabling this
74652 ** check can cause assertion faults due to min-heap overflow. All
74653 ** fault-sims are for testing use only, but this one especially so. */
74654 return SQLITE_CORRUPT_PAGE(pPage);
74655 }
74656 nFree = nFree + size;
@@ -82907,10 +83096,13 @@
82907 if( rc!=SQLITE_OK ){
82908 return rc;
82909 }
82910 pMove = 0;
82911 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
 
 
 
82912 freePage(pMove, &rc);
82913 releasePage(pMove);
82914 if( rc!=SQLITE_OK ){
82915 return rc;
82916 }
@@ -83727,13 +83919,13 @@
83727 sCheck.aPgRef = sqlite3MallocZero((sCheck.nCkPage / 8)+ 1);
83728 if( !sCheck.aPgRef ){
83729 checkOom(&sCheck);
83730 goto integrity_ck_cleanup;
83731 }
83732 sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
83733 #ifdef SQLITE_DEBUG
83734 sCheck.mxHeap = pBt->pageSize/4 - 1;
83735 #endif
83736 if( sCheck.heap==0 ){
83737 checkOom(&sCheck);
83738 goto integrity_ck_cleanup;
83739 }
@@ -83817,11 +84009,11 @@
83817 }
83818
83819 /* Clean up and report errors.
83820 */
83821 integrity_ck_cleanup:
83822 sqlite3PageFree(sCheck.heap);
83823 sqlite3_free(sCheck.aPgRef);
83824 *pnErr = sCheck.nErr;
83825 if( sCheck.nErr==0 ){
83826 sqlite3_str_reset(&sCheck.errMsg);
83827 *pzOut = 0;
@@ -86925,11 +87117,11 @@
86925 if( pExpr ){
86926 rc = valueFromExpr(db, pExpr, enc, affinity, &pVal, 0);
86927 if( rc==SQLITE_OK && pVal
86928 && affinity==SQLITE_AFF_REAL
86929 && (pVal->flags & MEM_Int)
86930 && (u64)(pVal->u.i<0 ? pVal->u.i : pVal->u.i)>140737488355327LL
86931 ){
86932 /* If the integer value is too large to fit in a 6-byte integer and
86933 ** the affinity is REAL, convert it to a real value now. In most
86934 ** cases an OP_RealAffinity opcode will be used to convert the
86935 ** value to an actual real, but this opcode is omitted if the values
@@ -92336,11 +92528,11 @@
92336 }
92337 testcase( flags & MEM_Real );
92338 testcase( flags & MEM_Null );
92339 testcase( flags & MEM_Blob );
92340 if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0
92341 && p->pKeyInfo->aColl[0]==0
92342 ){
92343 assert( flags & MEM_Str );
92344 p->u.z = p->aMem[0].z;
92345 p->n = p->aMem[0].n;
92346 return vdbeRecordCompareString;
@@ -101668,11 +101860,13 @@
101668 if( x.flags & MEM_Int ){
101669 iKey = x.u.i;
101670 }else
101671 if( (x.flags & MEM_Real)==0
101672 || x.u.r < -9223372036854775808.0
101673 || x.u.r > 9223372036854775807.0
 
 
101674 || (double)(iKey = sqlite3RealToI64(x.u.r))!=x.u.r
101675 ){
101676 goto jump_to_p2;
101677 }
101678 goto notExistsWithKey;
@@ -102352,18 +102546,21 @@
102352 }
102353 pOut->u.i = v;
102354 break;
102355 }
102356
102357 /* Opcode: NullRow P1 * * * *
102358 **
102359 ** Move the cursor P1 to a null row. Any OP_Column operations
102360 ** that occur while the cursor is on the null row will always
102361 ** write a NULL.
102362 **
102363 ** If cursor P1 is not previously opened, open it now to a special
102364 ** pseudo-cursor that always returns NULL for every column.
 
 
 
102365 */
102366 case OP_NullRow: {
102367 VdbeCursor *pC;
102368
102369 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -102376,11 +102573,11 @@
102376 pC->seekResult = 0;
102377 pC->isTable = 1;
102378 pC->noReuse = 1;
102379 pC->uc.pCursor = sqlite3BtreeFakeValidCursor();
102380 }
102381 pC->nullRow = 1;
102382 pC->cacheStatus = CACHE_STALE;
102383 if( pC->eCurType==CURTYPE_BTREE ){
102384 assert( pC->uc.pCursor!=0 );
102385 sqlite3BtreeClearCursor(pC->uc.pCursor);
102386 }
@@ -120900,10 +121097,11 @@
120900 /* Verify that constraints are still satisfied */
120901 if( pNew->pCheck!=0
120902 || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
120903 || (pTab->tabFlags & TF_Strict)!=0
120904 ){
 
120905 sqlite3NestedParse(pParse,
120906 "SELECT CASE WHEN quick_check GLOB 'CHECK*'"
120907 " THEN raise(ABORT,'CHECK constraint failed')"
120908 " WHEN quick_check GLOB 'non-* value in*'"
120909 " THEN raise(ABORT,'type mismatch on DEFAULT')"
@@ -134337,11 +134535,11 @@
134337 }
134338 if( argc==3 ){
134339 p2 = sqlite3_value_int64(argv[2]);
134340 if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
134341 }else{
134342 p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
134343 }
134344 if( p1==0 ){
134345 #ifdef SQLITE_SUBSTR_COMPATIBILITY
134346 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
134347 ** as substr(X,1,N) - it returns the first N characters of X. This
@@ -135776,10 +135974,25 @@
135776 sqlite3_result_text(context, "?000", 4, SQLITE_STATIC);
135777 }
135778 }
135779 #endif /* SQLITE_SOUNDEX */
135780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135781 #ifndef SQLITE_OMIT_LOAD_EXTENSION
135782 /*
135783 ** A function that loads a shared-library extension then returns NULL.
135784 */
135785 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
@@ -137146,10 +137359,52 @@
137146 sqlite3_result_text(context, "{}", 2, SQLITE_STATIC);
137147 }
137148 }
137149 #endif /* SQLITE_DEBUG || SQLITE_ENABLE_FILESTAT */
137150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137151 #ifdef SQLITE_DEBUG
137152 /*
137153 ** Implementation of fpdecode(x,y,z) function.
137154 **
137155 ** x is a real number that is to be decoded. y is the precision.
@@ -137306,10 +137561,11 @@
137306 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
137307 INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
137308 #endif
137309 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_FILESTAT)
137310 FUNCTION(sqlite_filestat, 1, 0, 0, filestatFunc ),
 
137311 #endif
137312 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
137313 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
137314 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
137315 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
@@ -137333,10 +137589,13 @@
137333 FUNCTION(char, -1, 0, 0, charFunc ),
137334 FUNCTION(abs, 1, 0, 0, absFunc ),
137335 #ifdef SQLITE_DEBUG
137336 FUNCTION(fpdecode, 3, 0, 0, fpdecodeFunc ),
137337 FUNCTION(parseuri, -1, 0, 0, parseuriFunc ),
 
 
 
137338 #endif
137339 #ifndef SQLITE_OMIT_FLOATING_POINT
137340 FUNCTION(round, 1, 0, 0, roundFunc ),
137341 FUNCTION(round, 2, 0, 0, roundFunc ),
137342 #endif
@@ -142714,11 +142973,11 @@
142714 void (*interruptx)(sqlite3*);
142715 sqlite_int64 (*last_insert_rowid)(sqlite3*);
142716 const char * (*libversion)(void);
142717 int (*libversion_number)(void);
142718 void *(*malloc)(int);
142719 char * (*mprintf)(const char*,...);
142720 int (*open)(const char*,sqlite3**);
142721 int (*open16)(const void*,sqlite3**);
142722 int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
142723 int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
142724 void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
@@ -142735,15 +142994,15 @@
142735 void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
142736 void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
142737 void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
142738 void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
142739 void (*result_value)(sqlite3_context*,sqlite3_value*);
142740 void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
142741 int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
142742 const char*,const char*),void*);
142743 void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
142744 char * (*xsnprintf)(int,char*,const char*,...);
142745 int (*step)(sqlite3_stmt*);
142746 int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
142747 char const**,char const**,int*,int*,int*);
142748 void (*thread_cleanup)(void);
142749 int (*total_changes)(sqlite3*);
@@ -142803,11 +143062,11 @@
142803 int (*vfs_register)(sqlite3_vfs*,int);
142804 int (*vfs_unregister)(sqlite3_vfs*);
142805 int (*xthreadsafe)(void);
142806 void (*result_zeroblob)(sqlite3_context*,int);
142807 void (*result_error_code)(sqlite3_context*,int);
142808 int (*test_control)(int, ...);
142809 void (*randomness)(int,void*);
142810 sqlite3 *(*context_db_handle)(sqlite3_context*);
142811 int (*extended_result_codes)(sqlite3*,int);
142812 int (*limit)(sqlite3*,int,int);
142813 sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
@@ -142823,25 +143082,25 @@
142823 int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
142824 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
142825 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
142826 void (*xFinal)(sqlite3_context*),
142827 void(*xDestroy)(void*));
142828 int (*db_config)(sqlite3*,int,...);
142829 sqlite3_mutex *(*db_mutex)(sqlite3*);
142830 int (*db_status)(sqlite3*,int,int*,int*,int);
142831 int (*extended_errcode)(sqlite3*);
142832 void (*log)(int,const char*,...);
142833 sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
142834 const char *(*sourceid)(void);
142835 int (*stmt_status)(sqlite3_stmt*,int,int);
142836 int (*strnicmp)(const char*,const char*,int);
142837 int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
142838 int (*wal_autocheckpoint)(sqlite3*,int);
142839 int (*wal_checkpoint)(sqlite3*,const char*);
142840 void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
142841 int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
142842 int (*vtab_config)(sqlite3*,int op,...);
142843 int (*vtab_on_conflict)(sqlite3*);
142844 /* Version 3.7.16 and later */
142845 int (*close_v2)(sqlite3*);
142846 const char *(*db_filename)(sqlite3*,const char*);
142847 int (*db_readonly)(sqlite3*,const char*);
@@ -142906,11 +143165,11 @@
142906 int (*keyword_count)(void);
142907 int (*keyword_name)(int,const char**,int*);
142908 int (*keyword_check)(const char*,int);
142909 sqlite3_str *(*str_new)(sqlite3*);
142910 char *(*str_finish)(sqlite3_str*);
142911 void (*str_appendf)(sqlite3_str*, const char *zFormat, ...);
142912 void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list);
142913 void (*str_append)(sqlite3_str*, const char *zIn, int N);
142914 void (*str_appendall)(sqlite3_str*, const char *zIn);
142915 void (*str_appendchar)(sqlite3_str*, int N, char C);
142916 void (*str_reset)(sqlite3_str*);
@@ -144551,11 +144810,11 @@
144551 /* ePragTyp: */ PragTyp_FLAG,
144552 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
144553 /* ColNames: */ 0, 0,
144554 /* iArg: */ SQLITE_CountRows },
144555 #endif
144556 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
144557 {/* zName: */ "data_store_directory",
144558 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
144559 /* ePragFlg: */ PragFlg_NoColumns1,
144560 /* ColNames: */ 0, 0,
144561 /* iArg: */ 0 },
@@ -144974,11 +145233,11 @@
144974 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
144975 /* ColNames: */ 0, 0,
144976 /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
144977 #endif
144978 };
144979 /* Number of pragmas: 68 on by default, 78 total. */
144980
144981 /************** End of pragma.h **********************************************/
144982 /************** Continuing where we left off in pragma.c *********************/
144983
144984 /*
@@ -145027,11 +145286,11 @@
145027 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 5, 4};
145028 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 3, 2};
145029 /* on no off false yes true extra full */
145030 int i, n;
145031 if( sqlite3Isdigit(*z) ){
145032 return (u8)sqlite3Atoi(z);
145033 }
145034 n = sqlite3Strlen30(z);
145035 for(i=0; i<ArraySize(iLength); i++){
145036 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0
145037 && (!omitFull || iValue[i]<=1)
@@ -146086,11 +146345,17 @@
146086 }else{
146087 if( !db->autoCommit ){
146088 sqlite3ErrorMsg(pParse,
146089 "Safety level may not be changed inside a transaction");
146090 }else if( iDb!=1 ){
146091 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
 
 
 
 
 
 
146092 if( iLevel==0 ) iLevel = 1;
146093 pDb->safety_level = iLevel;
146094 pDb->bSyncSet = 1;
146095 setAllPagerFlags(db);
146096 }
@@ -149688,10 +149953,11 @@
149688 static int sqlite3ProcessJoin(Parse *pParse, Select *p){
149689 SrcList *pSrc; /* All tables in the FROM clause */
149690 int i, j; /* Loop counters */
149691 SrcItem *pLeft; /* Left table being joined */
149692 SrcItem *pRight; /* Right table being joined */
 
149693
149694 pSrc = p->pSrc;
149695 pLeft = &pSrc->a[0];
149696 pRight = &pLeft[1];
149697 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
@@ -149830,11 +150096,22 @@
149830 pRight->u3.pOn = 0;
149831 pRight->fg.isOn = 1;
149832 p->selFlags |= SF_OnToWhere;
149833 }
149834
149835 if( pRight->fg.isTabFunc && joinType==EP_OuterON && pRight->u1.pFuncArg ){
 
 
 
 
 
 
 
 
 
 
 
149836 p->selFlags |= SF_OnToWhere;
149837 }
149838 }
149839 return 0;
149840 }
@@ -150939,10 +151216,13 @@
150939 /* Open any cursors needed for sorter-reference expressions */
150940 for(i=0; i<pSort->nDefer; i++){
150941 Table *pTab = pSort->aDefer[i].pTab;
150942 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
150943 sqlite3OpenTable(pParse, pSort->aDefer[i].iCsr, iDb, pTab, OP_OpenRead);
 
 
 
150944 nRefKey = MAX(nRefKey, pSort->aDefer[i].nKey);
150945 }
150946 #endif
150947
150948 iTab = pSort->iECursor;
@@ -156638,11 +156918,11 @@
156638 ** Type used for Walker callbacks by selectCheckOnClauses().
156639 */
156640 typedef struct CheckOnCtx CheckOnCtx;
156641 struct CheckOnCtx {
156642 SrcList *pSrc; /* SrcList for this context */
156643 int iJoin; /* Cursors must be left of this one, if not zero */
156644 int bFuncArg; /* True for table-function arg */
156645 CheckOnCtx *pParent; /* Parent context */
156646 };
156647
156648 /*
@@ -156671,15 +156951,15 @@
156671 /* If CheckOnCtx.iJoin is already set, then fall through and process
156672 ** this expression node as normal. Or, if CheckOnCtx.iJoin is still 0,
156673 ** set it to the cursor number of the RHS of the join to which this
156674 ** ON expression was attached and then iterate through the entire
156675 ** expression. */
156676 assert( pCtx->iJoin==0 || pCtx->iJoin==pExpr->w.iJoin );
156677 if( pCtx->iJoin==0 ){
156678 pCtx->iJoin = pExpr->w.iJoin;
156679 sqlite3WalkExprNN(pWalker, pExpr);
156680 pCtx->iJoin = 0;
156681 return WRC_Prune;
156682 }
156683 }
156684
156685 if( pExpr->op==TK_COLUMN ){
@@ -156693,11 +156973,11 @@
156693 int nSrc = pSrc->nSrc;
156694 int ii;
156695 for(ii=0; ii<nSrc && pSrc->a[ii].iCursor!=iTab; ii++){}
156696 if( ii<nSrc ){
156697 /* pSrc is the FROM clause that contains iTab */
156698 if( pCtx->iJoin ){
156699 for(ii--; ii>=0 && pSrc->a[ii].iCursor!=pCtx->iJoin; ii--){}
156700 if( ii>=0 ){
156701 /* Table iJoin appears to the left of table iTab in the SrcList.
156702 ** Therefore the expression refers to a table to its right. */
156703 sqlite3ErrorMsg(pWalker->pParse,
@@ -156725,10 +157005,11 @@
156725 }else{
156726 CheckOnCtx sCtx;
156727 memset(&sCtx, 0, sizeof(sCtx));
156728 sCtx.pSrc = pSelect->pSrc;
156729 sCtx.pParent = pCtx;
 
156730 pWalker->u.pCheckOnCtx = &sCtx;
156731 sqlite3WalkSelect(pWalker, pSelect);
156732 pWalker->u.pCheckOnCtx = pCtx;
156733 pSelect->selFlags &= ~SF_OnToWhere;
156734 return WRC_Prune;
@@ -156750,24 +157031,45 @@
156750 w.xExprCallback = selectCheckOnClausesExpr;
156751 w.xSelectCallback = selectCheckOnClausesSelect;
156752 w.u.pCheckOnCtx = &sCtx;
156753 memset(&sCtx, 0, sizeof(sCtx));
156754 sCtx.pSrc = pSelect->pSrc;
 
156755 sqlite3WalkExpr(&w, pSelect->pWhere);
156756 pSelect->selFlags &= ~SF_OnToWhere;
156757
156758 /* Check for any table-function args that are attached to virtual tables
156759 ** on the RHS of an outer join. They are subject to the same constraints
156760 ** as ON clauses. */
 
 
 
 
 
 
 
 
156761 sCtx.bFuncArg = 1;
156762 for(ii=0; ii<pSelect->pSrc->nSrc; ii++){
156763 SrcItem *pItem = &pSelect->pSrc->a[ii];
156764 if( pItem->fg.isTabFunc
156765 && (pItem->fg.jointype & JT_OUTER)
156766 ){
156767 sCtx.iJoin = pItem->iCursor;
156768 sqlite3WalkExprList(&w, pItem->u1.pFuncArg);
 
 
 
 
 
 
 
 
 
 
 
 
156769 }
156770 }
156771 }
156772
156773 /*
@@ -160077,12 +160379,11 @@
160077 ** it has been converted into REAL.
160078 */
160079 static SQLITE_NOINLINE void columnDefaultUncommonCase(
160080 Vdbe *v, /* Byte code under construction */
160081 Table *pTab, /* The table */
160082 Column *pCol, /* Which column of the table */
160083 int iReg /* Register in which results are stored */
160084 ){
160085 sqlite3_value *pValue = 0;
160086 u8 enc = ENC(sqlite3VdbeDb(v));
160087 Parse *pParse = sqlite3VdbeParser(v);
160088 assert( !IsView(pTab) );
@@ -160090,15 +160391,10 @@
160090 sqlite3ColumnExprAuth(pTab,pCol,pParse), enc,
160091 pCol->affinity, &pValue);
160092 if( pValue ){
160093 sqlite3VdbeAppendP4(v, pValue, P4_MEM);
160094 }
160095 #ifndef SQLITE_OMIT_FLOATING_POINT
160096 if( pCol->affinity==SQLITE_AFF_REAL ){
160097 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
160098 }
160099 #endif
160100 }
160101 SQLITE_PRIVATE void sqlite3ColumnDefault(
160102 Vdbe *v, /* Byte code under construction */
160103 Table *pTab, /* The table */
160104 int i, /* Which column of the table */
@@ -160107,11 +160403,11 @@
160107 Column *pCol;
160108 assert( pTab!=0 );
160109 assert( pTab->nCol>i );
160110 pCol = &pTab->aCol[i];
160111 if( pCol->iDflt ){
160112 columnDefaultUncommonCase(v,pTab,pCol,iReg);
160113 }
160114 #ifndef SQLITE_OMIT_FLOATING_POINT
160115 if( pCol->affinity==SQLITE_AFF_REAL ){
160116 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
160117 }
@@ -165194,21 +165490,11 @@
165194 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
165195 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
165196 testcase( pTerm->wtFlags & TERM_VIRTUAL );
165197 r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
165198 if( r1!=regBase+j ){
165199 /* If this routine is being called as part of a RIGHT JOIN loop, then
165200 ** register r1 may be used by the body of the loop that the RIGHT JOIN
165201 ** will jump back into (e.g. if pTerm is a sub-query). This can cause
165202 ** problems if (say) the affinity of r1 is modified by the caller of
165203 ** this routine. So, always take a copy of the value in this case. */
165204 if( nReg==1 && pParse->withinRJSubrtn==0 ){
165205 sqlite3ReleaseTempReg(pParse, regBase);
165206 regBase = r1;
165207 }else{
165208 sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
165209 }
165210 }
165211 if( pTerm->eOperator & WO_IN ){
165212 if( pTerm->pExpr->flags & EP_xIsSelect ){
165213 /* No affinity ever needs to be (or should be) applied to a value
165214 ** from the RHS of an "? IN (SELECT ...)" expression. The
@@ -165824,10 +166110,13 @@
165824 );
165825 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
165826 pLevel->iLeftJoin = ++pParse->nMem;
165827 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
165828 VdbeComment((v, "init LEFT JOIN match flag"));
 
 
 
165829 }
165830
165831 /* Special case of a FROM clause subquery implemented as a co-routine */
165832 if( pTabItem->fg.viaCoroutine ){
165833 int regYield;
@@ -176880,21 +177169,21 @@
176880 sqlite3VdbeChangeP5(v, pLevel->p5);
176881 VdbeCoverage(v);
176882 VdbeCoverageIf(v, pLevel->op==OP_Next);
176883 VdbeCoverageIf(v, pLevel->op==OP_Prev);
176884 VdbeCoverageIf(v, pLevel->op==OP_VNext);
176885 if( pLevel->regBignull ){
176886 sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
176887 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1);
176888 VdbeCoverage(v);
176889 }
176890 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
176891 if( addrSeek ){
176892 sqlite3VdbeJumpHere(v, addrSeek);
176893 addrSeek = 0;
176894 }
176895 #endif
 
 
 
 
 
176896 }
176897 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
176898 struct InLoop *pIn;
176899 int j;
176900 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
@@ -177517,10 +177806,11 @@
177517 ){
177518 struct CallCount *p;
177519 UNUSED_PARAMETER(nArg); assert( nArg==0 );
177520 UNUSED_PARAMETER(apArg);
177521 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
 
177522 p->nStep++;
177523 }
177524 static void percent_rankValueFunc(sqlite3_context *pCtx){
177525 struct CallCount *p;
177526 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
@@ -177562,10 +177852,11 @@
177562 ){
177563 struct CallCount *p;
177564 UNUSED_PARAMETER(nArg); assert( nArg==0 );
177565 UNUSED_PARAMETER(apArg);
177566 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
 
177567 p->nStep++;
177568 }
177569 static void cume_distValueFunc(sqlite3_context *pCtx){
177570 struct CallCount *p;
177571 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
@@ -177618,10 +177909,11 @@
177618 ){
177619 struct NtileCtx *p;
177620 assert( nArg==1 ); UNUSED_PARAMETER(nArg);
177621 UNUSED_PARAMETER(apArg);
177622 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
 
177623 p->iRow++;
177624 }
177625 static void ntileValueFunc(sqlite3_context *pCtx){
177626 struct NtileCtx *p;
177627 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
@@ -184558,10 +184850,11 @@
184558 if( yymsp[-5].minor.yy203 ){
184559 SrcItem *pNew = &yymsp[-5].minor.yy203->a[yymsp[-5].minor.yy203->nSrc-1];
184560 SrcItem *pOld = yymsp[-3].minor.yy203->a;
184561 assert( pOld->fg.fixedSchema==0 );
184562 pNew->zName = pOld->zName;
 
184563 assert( pOld->fg.fixedSchema==0 );
184564 if( pOld->fg.isSubquery ){
184565 pNew->fg.isSubquery = 1;
184566 pNew->u4.pSubq = pOld->u4.pSubq;
184567 pOld->u4.pSubq = 0;
@@ -184577,12 +184870,17 @@
184577 if( pOld->fg.isTabFunc ){
184578 pNew->u1.pFuncArg = pOld->u1.pFuncArg;
184579 pOld->u1.pFuncArg = 0;
184580 pOld->fg.isTabFunc = 0;
184581 pNew->fg.isTabFunc = 1;
 
 
 
 
 
184582 }
184583 pOld->zName = 0;
184584 }
184585 sqlite3SrcListDelete(pParse->db, yymsp[-3].minor.yy203);
184586 }else{
184587 Select *pSubquery;
184588 sqlite3SrcListShiftJoinType(pParse,yymsp[-3].minor.yy203);
@@ -188939,11 +189237,11 @@
188939
188940 /*
188941 ** This is the default collating function named "BINARY" which is always
188942 ** available.
188943 */
188944 static int binCollFunc(
188945 void *NotUsed,
188946 int nKey1, const void *pKey1,
188947 int nKey2, const void *pKey2
188948 ){
188949 int rc, n;
@@ -188971,20 +189269,23 @@
188971 ){
188972 const u8 *pK1 = (const u8*)pKey1;
188973 const u8 *pK2 = (const u8*)pKey2;
188974 while( nKey1 && pK1[nKey1-1]==' ' ) nKey1--;
188975 while( nKey2 && pK2[nKey2-1]==' ' ) nKey2--;
188976 return binCollFunc(pUser, nKey1, pKey1, nKey2, pKey2);
188977 }
188978
188979 /*
188980 ** Return true if CollSeq is the default built-in BINARY.
188981 */
 
188982 SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq *p){
188983 assert( p==0 || p->xCmp!=binCollFunc || strcmp(p->zName,"BINARY")==0 );
188984 return p==0 || p->xCmp==binCollFunc;
 
188985 }
 
188986
188987 /*
188988 ** Another built-in collating sequence: NOCASE.
188989 **
188990 ** This collating sequence is intended to be used for "case independent
@@ -189932,11 +190233,11 @@
189932 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
189933 if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==(u32)enc && p->nArg==nArg ){
189934 if( db->nVdbeActive ){
189935 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
189936 "unable to delete/modify user-function due to active statements");
189937 assert( !db->mallocFailed );
189938 return SQLITE_BUSY;
189939 }else{
189940 sqlite3ExpirePreparedStatements(db, 0);
189941 }
189942 }else if( xSFunc==0 && xFinal==0 ){
@@ -191454,13 +191755,16 @@
191454 ** conversions. The only error that can occur here is a malloc() failure.
191455 **
191456 ** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
191457 ** functions:
191458 */
191459 createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0, binCollFunc, 0);
191460 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0, binCollFunc, 0);
191461 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0, binCollFunc, 0);
 
 
 
191462 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
191463 createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0);
191464 if( db->mallocFailed ){
191465 goto opendb_out;
191466 }
@@ -198200,12 +198504,12 @@
198200 Fts3Table *pTab = 0;
198201 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
198202 const char *zStart = "<b>";
198203 const char *zEnd = "</b>";
198204 const char *zEllipsis = "<b>...</b>";
198205 int iCol = -1;
198206 int nToken = 15; /* Default number of tokens in snippet */
198207
198208 /* There must be at least one argument passed to this function (otherwise
198209 ** the non-overloaded version would have been called instead of this one).
198210 */
198211 assert( nVal>=1 );
@@ -198217,13 +198521,13 @@
198217 }
198218 if( fts3FunctionArg(pContext, "snippet", apVal[0], &pCsr) ) return;
198219 pTab = (Fts3Table *)pCsr->base.pVtab;
198220
198221 switch( nVal ){
198222 case 6: nToken = sqlite3_value_int(apVal[5]);
198223 /* no break */ deliberate_fall_through
198224 case 5: iCol = sqlite3_value_int(apVal[4]);
198225 /* no break */ deliberate_fall_through
198226 case 4: zEllipsis = (const char*)sqlite3_value_text(apVal[3]);
198227 /* no break */ deliberate_fall_through
198228 case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
198229 /* no break */ deliberate_fall_through
@@ -198232,10 +198536,13 @@
198232 if( !zEllipsis || !zEnd || !zStart ){
198233 sqlite3_result_error_nomem(pContext);
198234 }else if( nToken==0 || iCol>=pTab->nColumn ){
198235 sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
198236 }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
 
 
 
198237 sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
198238 }
198239 }
198240
198241 /*
@@ -203595,14 +203902,15 @@
203595 }
203596
203597 if( c->iOffset>iStartOffset ){
203598 int n = c->iOffset-iStartOffset;
203599 if( n>c->nAllocated ){
 
203600 char *pNew;
203601 c->nAllocated = n+20;
203602 pNew = sqlite3_realloc64(c->zToken, c->nAllocated);
203603 if( !pNew ) return SQLITE_NOMEM;
 
203604 c->zToken = pNew;
203605 }
203606 porter_stemmer(&z[iStartOffset], n, c->zToken, pnBytes);
203607 *pzToken = c->zToken;
203608 *piStartOffset = iStartOffset;
@@ -210126,42 +210434,46 @@
210126 );
210127 if( rc==SQLITE_OK ){
210128 rc = sqlite3Fts3SegReaderStart(p, &csr, &filter);
210129 }
210130
210131 if( rc==SQLITE_OK ){
210132 while( SQLITE_ROW==(rc = sqlite3Fts3SegReaderStep(p, &csr)) ){
210133 char *pCsr = csr.aDoclist;
210134 char *pEnd = &pCsr[csr.nDoclist];
210135
210136 i64 iDocid = 0;
210137 i64 iCol = 0;
210138 u64 iPos = 0;
210139
210140 pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid);
210141 while( pCsr<pEnd ){
210142 u64 iVal = 0;
210143 pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
210144 if( pCsr<pEnd ){
210145 if( iVal==0 || iVal==1 ){
210146 iCol = 0;
210147 iPos = 0;
210148 if( iVal ){
210149 pCsr += sqlite3Fts3GetVarint(pCsr, &iCol);
210150 }else{
210151 pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
210152 if( p->bDescIdx ){
210153 iDocid = (i64)((u64)iDocid - iVal);
210154 }else{
210155 iDocid = (i64)((u64)iDocid + iVal);
210156 }
210157 }
210158 }else{
210159 iPos += (iVal - 2);
 
 
 
 
210160 cksum = cksum ^ fts3ChecksumEntry(
210161 csr.zTerm, csr.nTerm, iLangid, iIndex, iDocid,
210162 (int)iCol, (int)iPos
210163 );
210164 }
210165 }
210166 }
210167 }
@@ -212193,13 +212505,12 @@
212193 if( !pCsr->pExpr ){
212194 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
212195 return;
212196 }
212197
212198 /* Limit the snippet length to 64 tokens. */
212199 if( nToken<-64 ) nToken = -64;
212200 if( nToken>+64 ) nToken = +64;
212201
212202 for(nSnippet=1; 1; nSnippet++){
212203
212204 int iSnip; /* Loop counter 0..nSnippet-1 */
212205 u64 mCovered = 0; /* Bitmask of phrases covered by snippet */
@@ -215936,11 +216247,14 @@
215936 jsonStringTooDeep(pOut);
215937 }
215938 while( pOut->eErr==0 ){
215939 jsonPrettyIndent(pPretty);
215940 j = jsonTranslateBlobToPrettyText(pPretty, j);
215941 if( j>=iEnd ) break;
 
 
 
215942 jsonAppendRawNZ(pOut, ",\n", 2);
215943 }
215944 jsonAppendChar(pOut, '\n');
215945 pPretty->nIndent--;
215946 jsonPrettyIndent(pPretty);
@@ -218896,11 +219210,11 @@
218896 sqlite3_result_text64(ctx, p->path.zBuf, n,
218897 SQLITE_TRANSIENT, SQLITE_UTF8);
218898 break;
218899 }
218900 default: {
218901 sqlite3_result_text(ctx, p->path.zBuf, p->nRoot, SQLITE_STATIC);
218902 break;
218903 }
218904 case JEACH_JSON: {
218905 if( p->sParse.zJson==0 ){
218906 sqlite3_result_blob(ctx, p->sParse.aBlob, p->sParse.nBlob,
@@ -219828,10 +220142,22 @@
219828 p[6] = (i>> 8)&0xFF;
219829 p[7] = (i>> 0)&0xFF;
219830 #endif
219831 return 8;
219832 }
 
 
 
 
 
 
 
 
 
 
 
 
219833
219834 /*
219835 ** Increment the reference count of node p.
219836 */
219837 static void nodeReference(RtreeNode *p){
@@ -220109,11 +220435,21 @@
220109 pNode->isDirty = 0;
220110 rc = sqlite3_reset(p);
220111 sqlite3_bind_null(p, 2);
220112 if( pNode->iNode==0 && rc==SQLITE_OK ){
220113 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
220114 nodeHashInsert(pRtree, pNode);
 
 
 
 
 
 
 
 
 
 
220115 }
220116 }
220117 return rc;
220118 }
220119
@@ -222232,39 +222568,64 @@
222232 }
222233
222234 return rc;
222235 }
222236
222237 /*
222238 ** Rounding constants for float->double conversion.
222239 */
222240 #define RNDTOWARDS (1.0 - 1.0/8388608.0) /* Round towards zero */
222241 #define RNDAWAY (1.0 + 1.0/8388608.0) /* Round away from zero */
222242
222243 #if !defined(SQLITE_RTREE_INT_ONLY)
222244 /*
222245 ** Convert an sqlite3_value into an RtreeValue (presumably a float)
222246 ** while taking care to round toward negative or positive, respectively.
222247 */
222248 static RtreeValue rtreeValueDown(sqlite3_value *v){
222249 double d = sqlite3_value_double(v);
222250 float f = (float)d;
222251 if( f>d ){
222252 f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS));
 
 
 
222253 }
222254 return f;
222255 }
222256 static RtreeValue rtreeValueUp(sqlite3_value *v){
222257 double d = sqlite3_value_double(v);
222258 float f = (float)d;
222259 if( f<d ){
222260 f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY));
 
 
 
222261 }
222262 return f;
222263 }
222264 #endif /* !defined(SQLITE_RTREE_INT_ONLY) */
222265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222266 /*
222267 ** A constraint has failed while inserting a row into an rtree table.
222268 ** Assuming no OOM error occurs, this function sets the error message
222269 ** (at pRtree->base.zErrMsg) to an appropriate value and returns
222270 ** SQLITE_CONSTRAINT.
@@ -222373,12 +222734,12 @@
222373 }
222374 }else
222375 #endif
222376 {
222377 for(ii=0; ii<nn; ii+=2){
222378 cell.aCoord[ii].i = sqlite3_value_int(aData[ii+3]);
222379 cell.aCoord[ii+1].i = sqlite3_value_int(aData[ii+4]);
222380 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
222381 rc = rtreeConstraintError(pRtree, ii+1);
222382 goto constraint;
222383 }
222384 }
@@ -222976,16 +223337,18 @@
222976 Rtree tree;
222977 int ii;
222978 int nData;
222979 int errCode;
222980 sqlite3_str *pOut;
 
222981
222982 UNUSED_PARAMETER(nArg);
222983 memset(&node, 0, sizeof(RtreeNode));
222984 memset(&tree, 0, sizeof(Rtree));
222985 tree.nDim = (u8)sqlite3_value_int(apArg[0]);
222986 if( tree.nDim<1 || tree.nDim>5 ) return;
 
222987 tree.nDim2 = tree.nDim*2;
222988 tree.nBytesPerCell = 8 + 8 * tree.nDim;
222989 node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
222990 if( node.zData==0 ) return;
222991 nData = sqlite3_value_bytes(apArg[1]);
@@ -225386,10 +225749,16 @@
225386 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
225387 }
225388 if( rc==SQLITE_OK ){
225389 rc = sqlite3_create_function(db, "rtreecheck", -1, utf8, 0,rtreecheck, 0,0);
225390 }
 
 
 
 
 
 
225391 if( rc==SQLITE_OK ){
225392 #ifdef SQLITE_RTREE_INT_ONLY
225393 void *c = (void *)RTREE_COORD_INT32;
225394 #else
225395 void *c = (void *)RTREE_COORD_REAL32;
@@ -228466,19 +228835,31 @@
228466 );
228467 }
228468
228469 /* Check that all non-HIDDEN columns in the destination table are also
228470 ** present in the input table. Populate the abTblPk[], azTblType[] and
228471 ** aiTblOrder[] arrays at the same time. */
 
 
 
228472 if( p->rc==SQLITE_OK ){
228473 p->rc = prepareFreeAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
228474 sqlite3_mprintf("PRAGMA table_info(%Q)", pIter->zTbl)
228475 );
228476 }
228477 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
228478 const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
228479 if( zName==0 ) break; /* An OOM - finalize() below returns S_NOMEM */
 
 
 
 
 
 
 
 
 
228480 for(i=iOrder; i<pIter->nTblCol; i++){
228481 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
228482 }
228483 if( i==pIter->nTblCol ){
228484 p->rc = SQLITE_ERROR;
@@ -229327,11 +229708,11 @@
229327 int nIdxAlloc = 0;
229328 for(i=0; zSql[i]; i++){
229329 char c = zSql[i];
229330
229331 /* If necessary, grow the pIter->aIdxCol[] array */
229332 if( iIdxCol==nIdxAlloc ){
229333 RbuSpan *aIdxCol = (RbuSpan*)sqlite3_realloc64(
229334 pIter->aIdxCol, nIdxAlloc*sizeof(RbuSpan) + 16*sizeof(RbuSpan)
229335 );
229336 if( aIdxCol==0 ){
229337 rc = SQLITE_NOMEM;
@@ -233129,28 +233510,28 @@
233129 StatPage *p = &pCsr->aPage[pCsr->iPage];
233130 if( !pCsr->isAgg ) statResetCounts(pCsr);
233131 while( p->iCell<p->nCell ){
233132 StatCell *pCell = &p->aCell[p->iCell];
233133 while( pCell->iOvfl<pCell->nOvfl ){
233134 int nUsable, iOvfl;
 
233135 sqlite3BtreeEnter(pBt);
233136 nUsable = sqlite3BtreeGetPageSize(pBt) -
233137 sqlite3BtreeGetReserveNoMutex(pBt);
233138 sqlite3BtreeLeave(pBt);
233139 pCsr->nPage++;
 
233140 statSizeAndOffset(pCsr);
233141 if( pCell->iOvfl<pCell->nOvfl-1 ){
233142 pCsr->nPayload += nUsable - 4;
233143 }else{
233144 pCsr->nPayload += pCell->nLastOvfl;
233145 pCsr->nUnused += nUsable - 4 - pCell->nLastOvfl;
233146 }
233147 iOvfl = pCell->iOvfl;
233148 pCell->iOvfl++;
233149 if( !pCsr->isAgg ){
233150 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
233151 pCsr->iPageno = pCell->aOvfl[iOvfl];
233152 pCsr->zPagetype = "overflow";
233153 pCsr->zPath = z = sqlite3_mprintf(
233154 "%s%.3x+%.6x", p->zPath, p->iCell, iOvfl
233155 );
233156 return z==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
@@ -240890,11 +241271,11 @@
240890
240891
240892 if( pIter ){
240893 sqlite3changeset_pk(pIter, &abPK, &nCol);
240894 }else if( !pTab && !pGrp->db ){
240895 return SQLITE_OK;
240896 }
240897
240898 /* If one was not found above, create a new table now */
240899 if( !pTab ){
240900 SessionTable **ppNew;
@@ -240916,11 +241297,11 @@
240916 pTab->nCol = 0;
240917 rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb);
240918 if( rc || pTab->nCol==0 ){
240919 sqlite3_free(pTab->azCol);
240920 sqlite3_free(pTab);
240921 return rc;
240922 }
240923 }
240924
240925 /* The new object must be linked on to the end of the list, not
240926 ** simply added to the start of it. This is to ensure that the
@@ -241754,48 +242135,44 @@
241754 rc = SQLITE_MISUSE;
241755 }else if( eOp!=SQLITE_INSERT && eOp!=SQLITE_UPDATE && eOp!=SQLITE_DELETE ){
241756 rc = SQLITE_ERROR;
241757 }else{
241758 rc = sessionChangesetFindTable(pGrp, zTab, 0, &pTab);
241759 }
241760 if( rc==SQLITE_OK ){
241761 if( pTab==0 ){
241762 if( pzErr ){
241763 *pzErr = sqlite3_mprintf("no such table: %s", zTab);
241764 }
241765 rc = SQLITE_ERROR;
241766 }else{
241767 int nReq = pTab->nCol * (eOp==SQLITE_UPDATE ? 2 : 1);
241768 pGrp->cd.pTab = pTab;
241769 pGrp->cd.eOp = eOp;
241770 pGrp->cd.bIndirect = bIndirect;
241771
241772 if( pGrp->cd.nBufAlloc<nReq ){
241773 SessionBuffer *aBuf = (SessionBuffer*)sqlite3_realloc(
241774 pGrp->cd.aBuf, nReq * sizeof(SessionBuffer)
241775 );
241776 if( aBuf==0 ){
241777 rc = SQLITE_NOMEM;
241778 }else{
241779 memset(&aBuf[pGrp->cd.nBufAlloc], 0,
241780 sizeof(SessionBuffer) * (nReq - pGrp->cd.nBufAlloc)
241781 );
241782 pGrp->cd.aBuf = aBuf;
241783 pGrp->cd.nBufAlloc = nReq;
241784 }
241785 }
241786
241787 #ifdef SQLITE_DEBUG
241788 {
241789 /* Assert that all column values are currently undefined */
241790 int ii;
241791 for(ii=0; ii<pGrp->cd.nBufAlloc; ii++){
241792 assert( pGrp->cd.aBuf[ii].nBuf==0 );
241793 }
241794 }
241795 #endif
241796 }
241797 }
241798
241799 return rc;
241800 }
241801
@@ -245585,10 +245962,20 @@
245585 }
245586
245587 return rc;
245588 }
245589
 
 
 
 
 
 
 
 
 
 
245590
245591 /*
245592 ** Implementation of highlight() function.
245593 */
245594 static void fts5HighlightFunction(
@@ -245606,11 +245993,11 @@
245606 const char *zErr = "wrong number of arguments to function highlight()";
245607 sqlite3_result_error(pCtx, zErr, -1);
245608 return;
245609 }
245610
245611 iCol = sqlite3_value_int(apVal[0]);
245612 memset(&ctx, 0, sizeof(HighlightContext));
245613 ctx.zOpen = (const char*)sqlite3_value_text(apVal[1]);
245614 ctx.zClose = (const char*)sqlite3_value_text(apVal[2]);
245615 ctx.iRangeEnd = -1;
245616 rc = pApi->xColumnText(pFts, iCol, &ctx.zIn, &ctx.nIn);
@@ -245805,11 +246192,11 @@
245805 return;
245806 }
245807
245808 nCol = pApi->xColumnCount(pFts);
245809 memset(&ctx, 0, sizeof(HighlightContext));
245810 iCol = sqlite3_value_int(apVal[0]);
245811 ctx.zOpen = fts5ValueToText(apVal[1]);
245812 ctx.zClose = fts5ValueToText(apVal[2]);
245813 ctx.iRangeEnd = -1;
245814 zEllips = fts5ValueToText(apVal[3]);
245815 nToken = (int)(MIN( MAX(sqlite3_value_int64(apVal[4]), 0), 64));
@@ -246137,11 +246524,11 @@
246137 const char *z = "non-integer argument passed to function fts5_get_locale()";
246138 sqlite3_result_error(pCtx, z, -1);
246139 return;
246140 }
246141
246142 iCol = sqlite3_value_int(apVal[0]);
246143 if( iCol<0 || iCol>=pApi->xColumnCount(pFts) ){
246144 sqlite3_result_error_code(pCtx, SQLITE_RANGE);
246145 return;
246146 }
246147
@@ -259897,10 +260284,13 @@
259897 *pCksum = cksum;
259898 return rc;
259899 }
259900
259901 /*
 
 
 
259902 ** Check if buffer z[], size n bytes, contains as series of valid utf-8
259903 ** encoded codepoints. If so, return 0. Otherwise, if the buffer does not
259904 ** contain valid utf-8, return non-zero.
259905 */
259906 static int fts5TestUtf8(const char *z, int n){
@@ -259918,12 +260308,12 @@
259918 if( i+2>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
259919 i += 3;
259920 }else
259921 if( (z[i] & 0xF8)==0xF0 ){
259922 if( i+3>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
259923 if( (z[i+2] & 0xC0)!=0x80 ) return 1;
259924 i += 3;
259925 }else{
259926 return 1;
259927 }
259928 }
259929
@@ -264813,11 +265203,11 @@
264813 int nArg, /* Number of args */
264814 sqlite3_value **apUnused /* Function arguments */
264815 ){
264816 assert( nArg==0 );
264817 UNUSED_PARAM2(nArg, apUnused);
264818 sqlite3_result_text(pCtx, "fts5: 2026-08-27 10:58:16 555f31c64d3fcc55df2715a7c8c1cb28503b2c0eb21d950ccdcbf6f577593dd5", -1, SQLITE_TRANSIENT);
264819 }
264820
264821 /*
264822 ** Implementation of fts5_locale(LOCALE, TEXT) function.
264823 **
@@ -265706,79 +266096,10 @@
265706 );
265707 sqlite3_reset(pStorage->pSavedRow);
265708 pStorage->pSavedRow = 0;
265709 }
265710
265711 /*
265712 ** This function is called to process a DELETE on a contentless_delete=1
265713 ** table. It adds the tombstone required to delete the entry with rowid
265714 ** iDel. If successful, SQLITE_OK is returned. Or, if an error occurs,
265715 ** an SQLite error code.
265716 */
265717 static int fts5StorageContentlessDelete(Fts5Storage *p, i64 iDel){
265718 i64 iOrigin = 0;
265719 sqlite3_stmt *pLookup = 0;
265720 int rc = SQLITE_OK;
265721
265722 assert( p->pConfig->bContentlessDelete );
265723 assert( p->pConfig->eContent==FTS5_CONTENT_NONE
265724 || p->pConfig->eContent==FTS5_CONTENT_UNINDEXED
265725 );
265726
265727 /* Look up the origin of the document in the %_docsize table. Store
265728 ** this in stack variable iOrigin. */
265729 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
265730 if( rc==SQLITE_OK ){
265731 sqlite3_bind_int64(pLookup, 1, iDel);
265732 if( SQLITE_ROW==sqlite3_step(pLookup) ){
265733 iOrigin = sqlite3_column_int64(pLookup, 1);
265734 }
265735 rc = sqlite3_reset(pLookup);
265736 }
265737
265738 if( rc==SQLITE_OK && iOrigin!=0 ){
265739 rc = sqlite3Fts5IndexContentlessDelete(p->pIndex, iOrigin, iDel);
265740 }
265741
265742 return rc;
265743 }
265744
265745 /*
265746 ** Insert a record into the %_docsize table. Specifically, do:
265747 **
265748 ** INSERT OR REPLACE INTO %_docsize(id, sz) VALUES(iRowid, pBuf);
265749 **
265750 ** If there is no %_docsize table (as happens if the columnsize=0 option
265751 ** is specified when the FTS5 table is created), this function is a no-op.
265752 */
265753 static int fts5StorageInsertDocsize(
265754 Fts5Storage *p, /* Storage module to write to */
265755 i64 iRowid, /* id value */
265756 Fts5Buffer *pBuf /* sz value */
265757 ){
265758 int rc = SQLITE_OK;
265759 if( p->pConfig->bColumnsize ){
265760 sqlite3_stmt *pReplace = 0;
265761 rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
265762 if( rc==SQLITE_OK ){
265763 sqlite3_bind_int64(pReplace, 1, iRowid);
265764 if( p->pConfig->bContentlessDelete ){
265765 i64 iOrigin = 0;
265766 rc = sqlite3Fts5IndexGetOrigin(p->pIndex, &iOrigin);
265767 sqlite3_bind_int64(pReplace, 3, iOrigin);
265768 }
265769 }
265770 if( rc==SQLITE_OK ){
265771 sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC);
265772 sqlite3_step(pReplace);
265773 rc = sqlite3_reset(pReplace);
265774 sqlite3_bind_null(pReplace, 2);
265775 }
265776 }
265777 return rc;
265778 }
265779
265780 /*
265781 ** Load the contents of the "averages" record from disk into the
265782 ** p->nTotalRow and p->aTotalSize[] variables. If successful, and if
265783 ** argument bCache is true, set the p->bTotalsValid flag to indicate
265784 ** that the contents of aTotalSize[] and nTotalRow are valid until
@@ -265819,10 +266140,114 @@
265819 }
265820 sqlite3_free(buf.p);
265821
265822 return rc;
265823 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265824
265825 /*
265826 ** Remove a row from the FTS table.
265827 */
265828 static int sqlite3Fts5StorageDelete(
@@ -266481,23 +266906,10 @@
266481 }else{
266482 sqlite3_finalize(pStmt);
266483 }
266484 }
266485
266486 static int fts5StorageDecodeSizeArray(
266487 int *aCol, int nCol, /* Array to populate */
266488 const u8 *aBlob, int nBlob /* Record to read varints from */
266489 ){
266490 int i;
266491 int iOff = 0;
266492 for(i=0; i<nCol; i++){
266493 if( iOff>=nBlob ) return 1;
266494 iOff += fts5GetVarint32(&aBlob[iOff], aCol[i]);
266495 }
266496 return (iOff!=nBlob);
266497 }
266498
266499 /*
266500 ** Argument aCol points to an array of integers containing one entry for
266501 ** each table column. This function reads the %_docsize record for the
266502 ** specified rowid and populates aCol[] with the results.
266503 **
266504
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 92709f54d4c58cf174f305b58971a01878af with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-10-01T11:21:02.802Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -3842,10 +3842,15 @@
3842 ** authorizer callback is the name of the database ("main", "temp",
3843 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
3844 ** is the name of the inner-most trigger or view that is responsible for
3845 ** the access attempt or NULL if this access attempt is directly from
3846 ** top-level SQL code.
3847 **
3848 ** The case of strings in the 3rd through the 6th argument to the
3849 ** authorization callback is arbitrary. Authorization callbacks
3850 ** implementations should use [sqlite3_stricmp()] or similar when
3851 ** doing comparisons against those values.
3852 */
3853 /******************************************* 3rd ************ 4th ***********/
3854 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
3855 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
3856 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
@@ -17208,10 +17213,14 @@
17213 #endif
17214
17215 #if defined(SQLITE_USE_SEH) && !defined(SQLITE_OMIT_WAL)
17216 SQLITE_PRIVATE int sqlite3PagerWalSystemErrno(Pager*);
17217 #endif
17218
17219 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
17220 SQLITE_PRIVATE void sqlite3PagerWalStat(Pager*,sqlite3_str*);
17221 #endif
17222
17223 #endif /* SQLITE_PAGER_H */
17224
17225 /************** End of pager.h ***********************************************/
17226 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -18590,11 +18599,11 @@
18599 */
18600 #if !SQLITE_THREADSAFE
18601 # define SQLITE_MUTEX_OMIT
18602 #endif
18603 #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
18604 # if SQLITE_OS_UNIX || defined(__CYGWIN__)
18605 # define SQLITE_MUTEX_PTHREADS
18606 # elif SQLITE_OS_WIN
18607 # define SQLITE_MUTEX_W32
18608 # else
18609 # define SQLITE_MUTEX_NOOP
@@ -22645,11 +22654,20 @@
22654 #endif
22655
22656 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
22657 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
22658 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
22659 SQLITE_PRIVATE int sqlite3BinaryCompare(void*,int,const void*,int,const void*);
22660 #if SQLITE_USES_INLINE
22661 static SQLITE_INLINE int sqlite3IsBinary(const CollSeq *p){
22662 assert( p==0 || p->xCmp!=sqlite3BinaryCompare
22663 || strcmp(p->zName,"BINARY")==0 );
22664 return p==0 || p->xCmp==sqlite3BinaryCompare;
22665 }
22666 #else
22667 SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq*);
22668 #endif
22669 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
22670 SQLITE_PRIVATE void sqlite3SetTextEncoding(sqlite3 *db, u8);
22671 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr);
22672 SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr);
22673 SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*);
@@ -25965,10 +25983,11 @@
25983 if( ms>0.999 ) ms = 0.999;
25984 }
25985 }else{
25986 s = 0;
25987 }
25988 if( h==24 && (m!=0 || s!=0 || ms!=0.0) ) return 1;
25989 p->validJD = 0;
25990 p->rawS = 0;
25991 p->validHMS = 1;
25992 p->h = h;
25993 p->m = m;
@@ -26001,10 +26020,14 @@
26020 D = p->D;
26021 }else{
26022 Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
26023 M = 1;
26024 D = 1;
26025 if( p->validHMS && p->h==24 ){
26026 p->h = 0;
26027 D = 2;
26028 }
26029 }
26030 if( Y<-4713 || Y>9999 || p->rawS ){
26031 datetimeError(p);
26032 return;
26033 }
@@ -26039,10 +26062,14 @@
26062 */
26063 static void computeFloor(DateTime *p){
26064 assert( p->validYMD || p->isError );
26065 assert( p->D>=0 && p->D<=31 );
26066 assert( p->M>=0 && p->M<=12 );
26067 if( p->validHMS && p->h==24 ){
26068 p->h = 0;
26069 p->D++;
26070 }
26071 if( p->D<=28 ){
26072 p->nFloor = 0;
26073 }else if( (1<<p->M) & 0x15aa ){
26074 p->nFloor = 0;
26075 }else if( p->M!=2 ){
@@ -31422,12 +31449,15 @@
31449 # define ALIGN128 __declspec(align(128))
31450 #else
31451 # define ALIGN128
31452 #endif
31453
31454 #ifdef _MSC_VER
31455 #pragma warning(push)
31456 #pragma warning(disable: 4324)
31457 #endif /* _MSC_VER */
31458
31459 /*
31460 ** Each SQLite mutex is an instance of the following structure.
31461 **
31462 ** The ALIGN128 macro attempts to force 128-byte alignment on mutexes,
31463 ** so that adjacent mutex objects are always on different cache lines
@@ -31446,11 +31476,13 @@
31476 volatile int nRef; /* Number of entrances */
31477 volatile DWORD owner; /* Thread holding this mutex */
31478 volatile LONG trace; /* True to trace changes */
31479 #endif
31480 };
31481 #ifdef _MSC_VER
31482 #pragma warning(pop)
31483 #endif /* _MSC_VER */
31484
31485 #ifdef SQLITE_DEBUG
31486 /*
31487 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
31488 ** intended for use only inside assert() statements.
@@ -32860,13 +32892,20 @@
32892 # define SQLITE_PRINT_BUF_SIZE 70
32893 #endif
32894 #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
32895
32896 /*
32897 ** Hard limit on the precision of floating-point conversions to
32898 ** the minimum of SQLITE_PRINTF_PRECISION_LIMIT and 100 million.
32899 */
32900 #ifdef SQLITE_PRINTF_PRECISION_LIMIT
32901 # if SQLITE_PRINTF_PRECISION_LIMIT<100000000
32902 # define SQLITE_FP_PRECISION_LIMIT SQLITE_PRINTF_PRECISION_LIMIT
32903 # else
32904 # define SQLITE_FP_PRECISION_LIMIT 100000000
32905 # endif
32906 #else
32907 # define SQLITE_FP_PRECISION_LIMIT 100000000
32908 #endif
32909
32910 /* Forward reference */
32911 static void sqlite3StrAppend64(sqlite3_str *p, const char *z, i64 N);
@@ -33222,15 +33261,13 @@
33261 realvalue = getDoubleArg(pArgList);
33262 }else{
33263 realvalue = va_arg(ap,double);
33264 }
33265 if( precision<0 ) precision = 6; /* Set default precision */
 
33266 if( precision>SQLITE_FP_PRECISION_LIMIT ){
33267 precision = SQLITE_FP_PRECISION_LIMIT;
33268 }
 
33269 if( xtype==etFLOAT ){
33270 iRound = -precision;
33271 }else if( xtype==etGENERIC ){
33272 if( precision==0 ) precision = 1;
33273 iRound = precision;
@@ -33316,11 +33353,11 @@
33353 if( szBufNeeded + pAccum->nChar >= pAccum->nAlloc ){
33354 if( pAccum->mxAlloc==0 && pAccum->accError==0 ){
33355 /* Unable to allocate space in pAccum, perhaps because it
33356 ** is coming from sqlite3_snprintf() or similar. We'll have
33357 ** to render into temporary space and the memcpy() it over. */
33358 bufpt = sqlite3_malloc64(szBufNeeded);
33359 if( bufpt==0 ){
33360 sqlite3StrAccumSetError(pAccum, SQLITE_NOMEM);
33361 return;
33362 }
33363 zExtra = bufpt;
@@ -36345,13 +36382,11 @@
36382 if( c>=0xc0 ){ \
36383 c = sqlite3Utf8Trans1[c-0xc0]; \
36384 while( zIn<zTerm && (*zIn & 0xc0)==0x80 ){ \
36385 c = (c<<6) + (0x3f & *(zIn++)); \
36386 } \
36387 if( c<0x80 || (c&0xFFFFF800)==0xD800 ){ c = 0xFFFD; } \
 
 
36388 }
36389 SQLITE_PRIVATE u32 sqlite3Utf8Read(
36390 const unsigned char **pz /* Pointer to string from which to read char */
36391 ){
36392 unsigned int c;
@@ -36363,13 +36398,11 @@
36398 if( c>=0xc0 ){
36399 c = sqlite3Utf8Trans1[c-0xc0];
36400 while( (*(*pz) & 0xc0)==0x80 ){
36401 c = (c<<6) + (0x3f & *((*pz)++));
36402 }
36403 if( c<0x80 || (c&0xFFFFF800)==0xD800 ){ c = 0xFFFD; }
 
 
36404 }
36405 return c;
36406 }
36407
36408 /*
@@ -36765,11 +36798,10 @@
36798 z[0] = 0;
36799 z = zBuf;
36800 c = sqlite3Utf8Read((const u8**)&z);
36801 t = i;
36802 if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
 
36803 assert( c==t );
36804 assert( (z-zBuf)==n );
36805 }
36806 }
36807 #endif /* SQLITE_TEST */
@@ -38324,11 +38356,11 @@
38356 SQLITE_PRIVATE int sqlite3GetUInt32(const char *z, u32 *pI){
38357 u64 v = 0;
38358 int i;
38359 for(i=0; sqlite3Isdigit(z[i]); i++){
38360 v = v*10 + z[i] - '0';
38361 if( v>4294967295LL ){ *pI = 0; return 0; }
38362 }
38363 if( i==0 || z[i]!=0 ){ *pI = 0; return 0; }
38364 *pI = (u32)v;
38365 return 1;
38366 }
@@ -49206,11 +49238,10 @@
49238
49239 /*
49240 ** Include the header file for the Windows VFS.
49241 */
49242 /* #include "os_win.h" */
 
49243
49244 /*
49245 ** This constant should already be defined (in the "WinDef.h" SDK file).
49246 */
49247 #ifndef MAX_PATH
@@ -49521,28 +49552,10 @@
49552 static void winMemShutdown(void *pAppData);
49553
49554 SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void);
49555 #endif /* SQLITE_WIN32_MALLOC */
49556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49557 #ifndef SYSCALL
49558 # define SYSCALL sqlite3_syscall_ptr
49559 #endif
49560
49561 /*
@@ -49890,10 +49903,13 @@
49903 { "cygwin_conv_path", (SYSCALL)0, 0 },
49904 #endif
49905 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
49906 const void *, void *, size_t))aSyscall[58].pCurrent)
49907
49908 { "GetDriveTypeW", (SYSCALL)GetDriveTypeW, 0 },
49909 #define osGetDriveTypeW ((UINT(WINAPI*)(LPCWSTR))aSyscall[59].pCurrent)
49910
49911 }; /* End of the overrideable system calls */
49912
49913 /*
49914 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
49915 ** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -50060,10 +50076,11 @@
50076 sqlite3_mutex_leave(pMainMtx);
50077 return rc;
50078 }
50079 #endif /* SQLITE_WIN32_MALLOC */
50080
50081 #ifdef _WIN32
50082 /*
50083 ** This function outputs the specified (ANSI) string to the Win32 debugger
50084 ** (if available). Undocumented. Might go away at any moment.
50085 */
50086 SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
@@ -50096,10 +50113,11 @@
50113 while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
50114 TRUE))==WAIT_IO_COMPLETION ){}
50115 return rc;
50116 }
50117 #endif
50118 #endif /* _WIN32 */
50119
50120 #ifdef SQLITE_WIN32_MALLOC
50121 /*
50122 ** Allocate nBytes of memory.
50123 */
@@ -50356,10 +50374,11 @@
50374 zText = 0;
50375 }
50376 return zText;
50377 }
50378
50379 #ifdef _WIN32
50380 /*
50381 ** Convert an ANSI string to Microsoft Unicode, using the ANSI or OEM
50382 ** code page.
50383 **
50384 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50385,11 +50404,10 @@
50404 zMbcsText = 0;
50405 }
50406 return zMbcsText;
50407 }
50408
 
50409 /*
50410 ** Convert a Microsoft Unicode string to a multi-byte character string,
50411 ** using the ANSI or OEM code page.
50412 **
50413 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50413,11 +50431,10 @@
50431 sqlite3_free(zText);
50432 zText = 0;
50433 }
50434 return zText;
50435 }
 
50436
50437 /*
50438 ** Convert a multi-byte character string to UTF-8.
50439 **
50440 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -50433,11 +50450,10 @@
50450 zTextUtf8 = winUnicodeToUtf8(zTmpWide);
50451 sqlite3_free(zTmpWide);
50452 return zTextUtf8;
50453 }
50454
 
50455 /*
50456 ** Convert a UTF-8 string to a multi-byte character string.
50457 **
50458 ** Space to hold the returned string is obtained from sqlite3_malloc().
50459 */
@@ -50483,11 +50499,10 @@
50499 #ifndef SQLITE_OMIT_AUTOINIT
50500 if( sqlite3_initialize() ) return 0;
50501 #endif
50502 return winUnicodeToUtf8(zWideText);
50503 }
 
50504
50505 /*
50506 ** This is a public wrapper for the winMbcsToUtf8() function.
50507 */
50508 SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zText){
@@ -50501,11 +50516,10 @@
50516 if( sqlite3_initialize() ) return 0;
50517 #endif
50518 return winMbcsToUtf8(zText, osAreFileApisANSI());
50519 }
50520
 
50521 /*
50522 ** This is a public wrapper for the winMbcsToUtf8() function.
50523 */
50524 SQLITE_API char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
50525 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -50764,17 +50778,17 @@
50778 *pError = e;
50779 }
50780 return 0;
50781 }
50782 if( winIoerrCanRetry1(e) ){
50783 osSleep(winIoerrRetryDelay*(1+*pnRetry));
50784 ++*pnRetry;
50785 return 1;
50786 }
50787 #if defined(winIoerrCanRetry2)
50788 else if( winIoerrCanRetry2(e) ){
50789 osSleep(winIoerrRetryDelay*(1+*pnRetry));
50790 ++*pnRetry;
50791 return 1;
50792 }
50793 #endif
50794 if( pError ){
@@ -51000,11 +51014,11 @@
51014 #endif
51015
51016 do{
51017 rc = osCloseHandle(pFile->h);
51018 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
51019 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (osSleep(100), 1) );
51020 if( rc ){
51021 pFile->h = NULL;
51022 }
51023 OpenCounter(-1);
51024 OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
@@ -51614,11 +51628,11 @@
51628 ));
51629 return rc;
51630 }
51631
51632 cnt--;
51633 if( cnt>0 ) osSleep(1);
51634 }
51635 gotPendingLock = res;
51636 }
51637
51638 /* Acquire a shared lock
@@ -51823,11 +51837,11 @@
51837 }
51838 }
51839
51840 /* Forward references to VFS helper methods used for temporary files */
51841 static int winGetTempname(sqlite3_vfs *, char **);
51842 static int winIsDir(LPCWSTR);
51843 static BOOL winIsLongPathPrefix(const char *);
51844 static BOOL winIsDriveLetterAndColon(const char *);
51845
51846 /*
51847 ** Control and query of the open file handle.
@@ -52055,15 +52069,14 @@
52069 ** Note: If the function cygwin_conv_path() fails, only
52070 ** UTF-8 -> UTF-16 conversion will be done. This can only
52071 ** happen when the file path >32k, in which case winUtf8ToUnicode()
52072 ** will fail too.
52073 */
52074 static LPWSTR winConvertFromUtf8Filename(const char *zFilename){
52075 LPWSTR zConverted = 0;
52076 #ifdef __CYGWIN__
52077 int nChar;
 
52078
52079 if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
52080 && winIsDirSep(zFilename[2])) ){
52081 i64 nByte;
52082 int convertflag = CCP_POSIX_TO_WIN_W;
@@ -52073,24 +52086,23 @@
52086 if( nByte>0 ){
52087 zConverted = sqlite3MallocZero(12+(u64)nByte);
52088 if ( zConverted==0 ){
52089 return zConverted;
52090 }
 
52091 /* Filenames should be prefixed, except when converted
52092 * full path already starts with "\\?\". */
52093 if( osCygwin_conv_path(convertflag, zFilename,
52094 zConverted+4, nByte)==0 ){
52095 if( (convertflag&CCP_RELATIVE) ){
52096 memmove(zConverted, zConverted+4, nByte);
52097 }else if( memcmp(zConverted+4, L"\\\\", 4) ){
52098 memcpy(zConverted, L"\\\\?\\", 8);
52099 }else if( zConverted[6]!='?' ){
52100 memmove(zConverted+6, zConverted+4, nByte);
52101 memcpy(zConverted, L"\\\\?\\UNC", 14);
52102 }else{
52103 memmove(zConverted, zConverted+4, nByte);
52104 }
52105 return zConverted;
52106 }
52107 sqlite3_free(zConverted);
52108 }
@@ -52097,32 +52109,31 @@
52109 }
52110 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
52111 if( nChar==0 ){
52112 return 0;
52113 }
52114 zConverted = sqlite3MallocZero( ((u64)nChar+6)*sizeof(WCHAR) );
52115 if( zConverted==0 ){
52116 return 0;
52117 }
52118 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
52119 zConverted, nChar);
52120 if( nChar==0 ){
52121 sqlite3_free(zConverted);
52122 zConverted = 0;
52123 }else if( nChar>MAX_PATH
52124 && winIsDriveLetterAndColon(zFilename)
52125 && winIsDirSep(zFilename[2]) ){
52126 memmove(zConverted+4, zConverted, nChar*sizeof(WCHAR));
52127 zConverted[2] = '\\';
52128 memcpy(zConverted, L"\\\\?\\", 8);
52129 }else if( nChar>MAX_PATH
52130 && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
52131 && zFilename[2] != '?' ){
52132 memmove(zConverted+6, zConverted, nChar*sizeof(WCHAR));
52133 memcpy(zConverted, L"\\\\?\\UNC", 14);
52134 }
 
52135 #else /* if !defined(__CYGWIN__) */
52136 zConverted = winUtf8ToUnicode(zFilename);
52137 #endif /* __CYGWIN__ */
52138 /* caller will handle out of memory */
52139 return zConverted;
@@ -52340,11 +52351,11 @@
52351 const char *zUtf8, /* File to open */
52352 int *pbReadonly, /* IN/OUT: True for readonly handle */
52353 HANDLE *ph /* OUT: New HANDLE for file */
52354 ){
52355 int rc = SQLITE_OK;
52356 LPWSTR zConverted = 0;
52357 int bReadonly = *pbReadonly;
52358 HANDLE h = INVALID_HANDLE_VALUE;
52359
52360 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
52361 const DWORD flag_overlapped = FILE_FLAG_OVERLAPPED;
@@ -52368,11 +52379,11 @@
52379 }
52380
52381 /* TODO: platforms.
52382 ** TODO: retry-on-ioerr.
52383 */
52384 h = osCreateFileW(zConverted, /* lpFileName */
52385 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
52386 FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
52387 NULL, /* lpSecurityAttributes */
52388 OPEN_ALWAYS, /* dwCreationDisposition */
52389 FILE_ATTRIBUTE_NORMAL|flag_overlapped,
@@ -52465,10 +52476,27 @@
52476 return 1;
52477 }
52478 }
52479 return sqlite3_win_test_unc_locking;
52480 }
52481
52482 /*
52483 ** Return true if the string passed in is the name of a file on a
52484 ** remote (network-mounted) volume.
52485 */
52486 static int winIsRemoteVolume(const char *zFile){
52487 WCHAR zRoot[4];
52488 if( strncmp(zFile, "\\\\?\\",4)==0 ) zFile += 4;
52489 if( !sqlite3Isalpha(zFile[0]) ) return 0;
52490 if( zFile[1]!=':' ) return 0;
52491 if( !winIsDirSep(zFile[2]) ) return 0;
52492 zRoot[0] = (WCHAR)zFile[0];
52493 zRoot[1] = ':';
52494 zRoot[2] = '\\';
52495 zRoot[3] = 0;
52496 return osGetDriveTypeW(zRoot)==DRIVE_REMOTE;
52497 }
52498
52499 /*
52500 ** Open the shared-memory area associated with database file pDbFd.
52501 */
52502 static int winOpenSharedMemory(winFile *pDbFd){
@@ -52491,11 +52519,15 @@
52519 return SQLITE_IOERR_NOMEM_BKPT;
52520 }
52521 pNew->zFilename = (char*)&pNew[1];
52522 pNew->hSharedShm = INVALID_HANDLE_VALUE;
52523 pNew->isUnlocked = 1;
52524 if( winIsUNCPath(pDbFd->zPath) || winIsRemoteVolume(pDbFd->zPath) ){
52525 pNew->bUseSharedLockHandle = 1;
52526 }else{
52527 pNew->bUseSharedLockHandle = 0;
52528 }
52529 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
52530 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
52531
52532 /* Look to see if there is an existing winShmNode that can be used.
52533 ** If no matching winShmNode currently exists, then create a new one. */
@@ -53331,11 +53363,11 @@
53363 if( !azDirs[1] ) azDirs[1] = osGetenv("TMPDIR");
53364 if( !azDirs[2] ) azDirs[2] = osGetenv("TMP");
53365 if( !azDirs[3] ) azDirs[3] = osGetenv("TEMP");
53366 if( !azDirs[4] ) azDirs[4] = osGetenv("USERPROFILE");
53367 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
53368 LPWSTR zConverted;
53369 if( zDir==0 ) continue;
53370 /* If the path starts with a drive letter followed by the colon
53371 ** character, assume it is already a native Win32 path; otherwise,
53372 ** it must be converted to a native Win32 path via the Cygwin API
53373 ** prior to using it.
@@ -53372,16 +53404,15 @@
53404 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
53405 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
53406 "winGetTempname2", 0);
53407 }
53408 zMulti = winUnicodeToUtf8(zWidePath);
53409 sqlite3_free(zWidePath);
53410 if( zMulti ){
53411 sqlite3_snprintf(nMax, zBuf, "%s", zMulti);
53412 sqlite3_free(zMulti);
 
53413 }else{
 
53414 sqlite3_free(zBuf);
53415 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
53416 return SQLITE_IOERR_NOMEM_BKPT;
53417 }
53418 }
@@ -53436,18 +53467,18 @@
53467 /*
53468 ** Return TRUE if the named file is really a directory. Return false if
53469 ** it is something other than a directory, or if there is any kind of memory
53470 ** allocation failure.
53471 */
53472 static int winIsDir(LPCWSTR zConverted){
53473 DWORD attr;
53474 int rc = 0;
53475 DWORD lastErrno;
53476 int cnt = 0;
53477 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
53478 memset(&sAttrData, 0, sizeof(sAttrData));
53479 while( !(rc = osGetFileAttributesExW(zConverted,
53480 GetFileExInfoStandard,
53481 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
53482 if( !rc ){
53483 return 0; /* Invalid name? */
53484 }
@@ -53485,11 +53516,11 @@
53516 DWORD dwShareMode;
53517 DWORD dwCreationDisposition;
53518 DWORD dwFlagsAndAttributes = 0;
53519 winVfsAppData *pAppData;
53520 winFile *pFile = (winFile*)id;
53521 LPWSTR zConverted; /* Filename in OS encoding */
53522 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
53523 int cnt = 0;
53524 int isRO = 0; /* file is known to be accessible readonly */
53525
53526 /* If argument zPath is a NULL pointer, this function is required to open
@@ -53618,11 +53649,11 @@
53649 | FILE_FLAG_DELETE_ON_CLOSE;
53650 }else{
53651 dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
53652 }
53653 do{
53654 h = osCreateFileW(zConverted,
53655 dwDesiredAccess,
53656 dwShareMode, NULL,
53657 dwCreationDisposition,
53658 dwFlagsAndAttributes,
53659 NULL);
@@ -53714,11 +53745,11 @@
53745 ){
53746 int cnt = 0;
53747 int rc;
53748 DWORD attr;
53749 DWORD lastErrno = 0;
53750 LPWSTR zConverted;
53751 UNUSED_PARAMETER(pVfs);
53752 UNUSED_PARAMETER(syncDir);
53753
53754 SimulateIOError(return SQLITE_IOERR_DELETE);
53755 OSTRACE(("DELETE name=%s, syncDir=%d\n", zFilename, syncDir));
@@ -53774,11 +53805,11 @@
53805 ){
53806 DWORD attr;
53807 int rc = 0;
53808 int cnt = 0;
53809 DWORD lastErrno = 0;
53810 LPWSTR zConverted;
53811 int noRetry = 0; /* Do not use winRetryIoerr() */
53812 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
53813 UNUSED_PARAMETER(pVfs);
53814
53815 if( (flags & NORETRY)!=0 ){
@@ -53801,11 +53832,11 @@
53832 if( zConverted==0 ){
53833 OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
53834 return SQLITE_IOERR_NOMEM_BKPT;
53835 }
53836 memset(&sAttrData, 0, sizeof(sAttrData));
53837 while( !(rc = osGetFileAttributesExW(zConverted,
53838 GetFileExInfoStandard,
53839 &sAttrData))
53840 && !noRetry
53841 && winRetryIoerr(&cnt, &lastErrno)
53842 ){ /* Loop until true */}
@@ -53983,11 +54014,11 @@
54014 const char *zRelative, /* Possibly relative input path */
54015 int nFull, /* Size of output buffer in bytes */
54016 char *zFull /* Output buffer */
54017 ){
54018 int nByte;
54019 LPWSTR zConverted;
54020 char *zOut;
54021
54022 /* If this path name begins with "/X:" or "\\?\", where "X" is any
54023 ** alphabetic character, discard the initial "/" from the pathname.
54024 */
@@ -54096,23 +54127,23 @@
54127 if( zConverted==0 ){
54128 return SQLITE_IOERR_NOMEM_BKPT;
54129 }
54130 {
54131 LPWSTR zTemp;
54132 nByte = osGetFullPathNameW(zConverted, 0, 0, 0);
54133 if( nByte==0 ){
54134 sqlite3_free(zConverted);
54135 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
54136 "winFullPathname1", zRelative);
54137 }
54138 nByte += 3;
54139 zTemp = sqlite3MallocZero( (u64)nByte*sizeof(WCHAR) );
54140 if( zTemp==0 ){
54141 sqlite3_free(zConverted);
54142 return SQLITE_IOERR_NOMEM_BKPT;
54143 }
54144 nByte = osGetFullPathNameW(zConverted, nByte, zTemp, 0);
54145 if( nByte==0 ){
54146 sqlite3_free(zConverted);
54147 sqlite3_free(zTemp);
54148 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
54149 "winFullPathname2", zRelative);
@@ -54168,17 +54199,17 @@
54199 ** Interfaces for opening a shared library, finding entry points
54200 ** within the shared library, and closing the shared library.
54201 */
54202 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
54203 HANDLE h = 0;
54204 LPWSTR zConverted = winConvertFromUtf8Filename(zFilename);
54205 UNUSED_PARAMETER(pVfs);
54206 if( zConverted==0 ){
54207 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
54208 return 0;
54209 }
54210 h = osLoadLibraryW ? osLoadLibraryW(zConverted) : 0;
54211 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
54212 sqlite3_free(zConverted);
54213 return (void*)h;
54214 }
54215 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
@@ -54282,11 +54313,11 @@
54313
54314 /*
54315 ** Sleep for a little while. Return the amount of time slept.
54316 */
54317 static int winSleep(sqlite3_vfs *pVfs, int microsec){
54318 osSleep((microsec+999)/1000);
54319 UNUSED_PARAMETER(pVfs);
54320 return ((microsec+999)/1000)*1000;
54321 }
54322
54323 /*
@@ -54489,11 +54520,11 @@
54520 winNextSystemCall, /* xNextSystemCall */
54521 };
54522
54523 /* Double-check that the aSyscall[] array has been constructed
54524 ** correctly. See ticket [bb3a86e890c8e96ab] */
54525 assert( ArraySize(aSyscall)==60 );
54526 assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
54527 assert( strcmp(aSyscall[8].zName,"FreeLibrary")==0 );
54528 assert( strcmp(aSyscall[16].zName,"GetSystemInfo")==0 );
54529 assert( strcmp(aSyscall[24].zName,"HeapReAlloc")==0 );
54530 assert( strcmp(aSyscall[32].zName,"MapViewOfFileFromApp")==0 );
@@ -58880,10 +58911,14 @@
58911 #endif
58912
58913 #ifdef SQLITE_USE_SEH
58914 SQLITE_PRIVATE int sqlite3WalSystemErrno(Wal*);
58915 #endif
58916
58917 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
58918 SQLITE_PRIVATE void sqlite3WalStat(Wal*,sqlite3_str*);
58919 #endif
58920
58921 #endif /* ifndef SQLITE_OMIT_WAL */
58922 #endif /* SQLITE_WAL_H */
58923
58924 /************** End of wal.h *************************************************/
@@ -65755,10 +65790,24 @@
65790 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
65791 return sqlite3PcacheRefCount(pPager->pPCache);
65792 }
65793 #endif
65794
65795 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
65796 /*
65797 ** Append JSON structure elements describing the current state of
65798 ** the write-ahead log to pStr.
65799 */
65800 SQLITE_PRIVATE void sqlite3PagerWalStat(Pager *pPager, sqlite3_str *pStr){
65801 #ifndef SQLITE_OMIT_WAL
65802 if( pPager->pWal ){
65803 sqlite3WalStat(pPager->pWal, pStr);
65804 }
65805 #endif
65806 }
65807 #endif
65808
65809 /*
65810 ** Return the approximate number of bytes of memory currently
65811 ** used by the pager and its associated cache.
65812 */
65813 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
@@ -67351,14 +67400,45 @@
67400 ** walIteratorInit() - Create a new iterator,
67401 ** walIteratorNext() - Step an iterator,
67402 ** walIteratorFree() - Free an iterator.
67403 **
67404 ** This functionality is used by the checkpoint code (see walCheckpoint()).
67405 **
67406 ** There are two possible algorithms:
67407 **
67408 ** WALITER-1 Load all pages mentioned in the WAL file and sort them,
67409 ** then hand them back out in sorted order as requested by
67410 ** walIteratorNext(). nPagemap==0 for this algorithm.
67411 **
67412 ** WALITER-2 Create a map of all database file pages and record the
67413 ** last WAL file frame that updates that page. Then walk
67414 ** through the map in acsending order and return all
67415 ** non-zero entries. nPagemap is positive for this algorithm.
67416 **
67417 ** Either algorithm should work for any database and WAL file, however
67418 ** algorithm WALITER-1 is faster and uses less memory when the database is
67419 ** larger than the WAL file and algorithm WALITER-2 is faster and uses
67420 ** less memory when the WAL file is larger than the database, modulo a
67421 ** constant of proportionality. The walIteratorInit() routine selects
67422 ** the best algorithm for each situation. WALITER-2 was added for
67423 ** SQLite 3.54.0. Prior to that, WALITER-1 was used always.
67424 **
67425 ** For algorithm WALITER-2, nPagemap stores the number of pages in the
67426 ** database file, nSegment==1, and aSegment[0].aPgno[] is the page map array
67427 ** that is nPagemap+1 entries in length. The value of aSegment[0].aPgno[PGNO]
67428 ** is the frame number of the last (newest) entry for page PGNO in the WAL
67429 ** file, or 0 if PGNO is not in the WAL file. (Aside: There is no page
67430 ** number 0 in a well-formed database, so the memory allocation is arranged
67431 ** such that aSegment[0].aPgno[0] and aSegment[0].iZero are aliases for the
67432 ** same four bits of memory. This saves us from having to use -1 and +1
67433 ** offsets to translate between 1-based SQLite page numbers and 0-based
67434 ** C-language index numbers. tag-20260903-1)
67435 */
67436 struct WalIterator {
67437 u32 iPrior; /* Last result returned from the iterator */
67438 int nSegment; /* Number of entries in aSegment[] */
67439 u32 nPagemap; /* Non-zero in "page-map" mode */
67440 struct WalSegment {
67441 int iNext; /* Next slot in aIndex[] not yet returned */
67442 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
67443 u32 *aPgno; /* Array of page numbers. */
67444 int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
@@ -67367,10 +67447,11 @@
67447 };
67448
67449 /* Size (in bytes) of a WalIterator object suitable for N or fewer segments */
67450 #define SZ_WALITERATOR(N) \
67451 (offsetof(WalIterator,aSegment)+(N)*sizeof(struct WalSegment))
67452
67453
67454 /*
67455 ** Define the parameters of the hash tables in the wal-index file. There
67456 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
67457 ** wal-index.
@@ -68530,28 +68611,42 @@
68611 static int walIteratorNext(
68612 WalIterator *p, /* Iterator */
68613 u32 *piPage, /* OUT: The page number of the next page */
68614 u32 *piFrame /* OUT: Wal frame index of next page */
68615 ){
 
68616 u32 iRet = 0xFFFFFFFF; /* 0xffffffff is never a valid page number */
68617
68618 if( p->nPagemap ){
68619 /* Algorithm WALITER-2 */
68620 while( p->iPrior<p->nPagemap ){
68621 p->iPrior++;
68622 if( p->aSegment[0].aPgno[p->iPrior] ){
68623 iRet = p->iPrior;
68624 *piFrame = p->aSegment[0].aPgno[p->iPrior];
 
 
 
 
 
68625 break;
68626 }
68627 }
68628 }else{
68629 /* Algorithm WALITER-1 */
68630 u32 iMin; /* Result pgno must be greater than iMin */
68631 int i; /* For looping through segments */
68632
68633 iMin = p->iPrior;
68634 assert( iMin<0xffffffff );
68635 for(i=p->nSegment-1; i>=0; i--){
68636 struct WalSegment *pSegment = &p->aSegment[i];
68637 while( pSegment->iNext<pSegment->nEntry ){
68638 u32 iPg = pSegment->aPgno[pSegment->aIndex[pSegment->iNext]];
68639 if( iPg>iMin ){
68640 if( iPg<iRet ){
68641 iRet = iPg;
68642 *piFrame = pSegment->iZero + pSegment->aIndex[pSegment->iNext];
68643 }
68644 break;
68645 }
68646 pSegment->iNext++;
68647 }
68648 }
68649 }
68650
68651 *piPage = p->iPrior = iRet;
68652 return (iRet==0xFFFFFFFF);
@@ -68716,63 +68811,99 @@
68811 **
68812 ** The calling routine should invoke walIteratorFree() to destroy the
68813 ** WalIterator object when it has finished with it.
68814 */
68815 static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
68816 int iFirstPage; /* First 32KB *-shm page to visit */
68817 int iLastPage; /* Last 32KB *-shm page to visit */
68818 u32 iZero; /* Frame before first frame to visit */
68819 WalIterator *p; /* Return value */
68820 int nSegment; /* Number of segments to merge */
68821 u32 iLast; /* Last frame in log */
68822 sqlite3_int64 nByte; /* Number of bytes to allocate */
68823 sqlite3_int64 nExtra; /* Number of bytes to allocate */
68824 int i; /* Iterator variable */
68825 ht_slot *aTmp = 0; /* Temp space used by merge-sort */
68826 int rc = SQLITE_OK; /* Return Code */
68827 int eAlg; /* Which algorithm to use. 1 or 2 */
68828
68829 /* This routine only runs while holding the checkpoint lock. And
68830 ** it only runs if there is actually content in the log (mxFrame>0). */
 
68831 assert( pWal->ckptLock && pWal->hdr.mxFrame>0 );
68832
68833 iLast = pWal->hdr.mxFrame;
68834 iFirstPage = walFramePage(nBackfill+1);
68835 iLastPage = walFramePage(iLast);
68836 iZero = iFirstPage ? (HASHTABLE_NPAGE_ONE+(iFirstPage-1)*HASHTABLE_NPAGE) : 0;
68837
68838 if( (iLast-iZero)*sizeof(ht_slot)>pWal->hdr.nPage*sizeof(u32) ){
68839 /* Algorithm WALITER-2 */
68840 nSegment = 1;
68841 eAlg = 2;
68842 nByte = SZ_WALITERATOR(nSegment) + pWal->hdr.nPage * sizeof(u32);
68843 nExtra = 0;
68844 }else{
68845 /* Algorithm WALITER-1 */
68846 nSegment = iLastPage - iFirstPage + 1;
68847 eAlg = 1;
68848 nByte = SZ_WALITERATOR(nSegment) + (iLast-iZero)*sizeof(ht_slot);
68849 nExtra = sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast);
68850 }
68851
68852 /* Allocate space for the WalIterator object. */
68853 p = (WalIterator *)sqlite3_malloc64(nByte + nExtra);
 
 
 
 
 
68854 if( !p ){
68855 return SQLITE_NOMEM_BKPT;
68856 }
68857 memset(p, 0, nByte);
68858 p->nSegment = nSegment;
68859 if( eAlg==2 ){
68860 p->nPagemap = pWal->hdr.nPage;
68861 p->aSegment[0].aPgno = ((u32*)&p->aSegment[1]) - 1;
68862 assert( (u8*)&(p->aSegment[0].aPgno[0]) == (u8*)&(p->aSegment[0].iZero) );
68863 /* ^-- verifies tag-20260903-1 */
68864 }else{
68865 aTmp = (ht_slot*)&(((u8*)p)[nByte]);
68866 }
68867 SEH_FREE_ON_ERROR(0, p);
68868 for(i=iFirstPage; rc==SQLITE_OK && i<=iLastPage; i++){
68869 WalHashLoc sLoc;
68870
68871 rc = walHashGet(pWal, i, &sLoc);
68872 if( rc==SQLITE_OK ){
68873 int j; /* Counter variable */
68874 int nEntry; /* Number of entries in this segment */
68875 ht_slot *aIndex; /* Sorted index for this segment */
68876
68877 if( i==iLastPage ){
68878 nEntry = (int)(iLast - sLoc.iZero);
68879 }else{
68880 nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno);
68881 }
68882
68883 if( eAlg==2 ){
68884 u32 *aPagemap = p->aSegment[0].aPgno;
68885 for(j=0; j<nEntry; j++){
68886 u32 pgno = sLoc.aPgno[ j ];
68887 if( pgno<=p->nPagemap ){
68888 aPagemap[pgno] = sLoc.iZero + j + 1;
68889 }
68890 }
68891 }else{
68892 assert( i!=iFirstPage || iZero==sLoc.iZero );
68893 aIndex = &((ht_slot *)&p->aSegment[p->nSegment])[sLoc.iZero - iZero];
68894 sLoc.iZero++;
68895
68896 for(j=0; j<nEntry; j++){
68897 aIndex[j] = (ht_slot)j;
68898 }
68899 walMergesort((u32 *)sLoc.aPgno, aTmp, aIndex, &nEntry);
68900 p->aSegment[i-iFirstPage].iZero = sLoc.iZero;
68901 p->aSegment[i-iFirstPage].nEntry = nEntry;
68902 p->aSegment[i-iFirstPage].aIndex = aIndex;
68903 p->aSegment[i-iFirstPage].aPgno = (u32 *)sLoc.aPgno;
68904 }
68905 }
68906 }
68907 if( rc!=SQLITE_OK ){
68908 SEH_FREE_ON_ERROR(p, 0);
68909 walIteratorFree(p);
@@ -71409,10 +71540,68 @@
71540 /* Return the sqlite3_file object for the WAL file
71541 */
71542 SQLITE_PRIVATE sqlite3_file *sqlite3WalFile(Wal *pWal){
71543 return pWal->pWalFd;
71544 }
71545
71546 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
71547 /*
71548 ** Helper function to sqlite3WalStat().
71549 **
71550 ** Append JSON-5 structure elements onto describing the current state
71551 ** of pWal onto the end of pStr. This function is for debugging and
71552 ** analysis only and is not included in production builds.
71553 */
71554 static void walIndexHdrStat(volatile WalIndexHdr *pHdr, sqlite3_str *pStr){
71555 sqlite3_str_appendf(pStr, "iVersion:%u",pHdr->iVersion);
71556 sqlite3_str_appendf(pStr, ",iChange:%u",pHdr->iChange);
71557 sqlite3_str_appendf(pStr, ",isInit:%u",pHdr->isInit);
71558 sqlite3_str_appendf(pStr, ",bigEndCksum:%u",pHdr->bigEndCksum);
71559 sqlite3_str_appendf(pStr, ",szPage:%u",pHdr->szPage);
71560 sqlite3_str_appendf(pStr, ",mxFrame:%u",pHdr->mxFrame);
71561 sqlite3_str_appendf(pStr, ",nPage:%u",pHdr->nPage);
71562 #if 0 /* Not often needed. Declutter. */
71563 sqlite3_str_appendf(pStr, ",aFrameCksum:[0x%08x,0x%08x]",
71564 pHdr->aFrameCksum[0], pHdr->aFrameCksum[1]);
71565 sqlite3_str_appendf(pStr, ",aSalt:[0x%08x,0x%08x]",
71566 pHdr->aSalt[0], pHdr->aSalt[1]);
71567 sqlite3_str_appendf(pStr, ",aCksum:[0x%08x,0x%08x]",
71568 pHdr->aCksum[0], pHdr->aCksum[1]);
71569 #endif
71570 }
71571 #endif /* SQLITE_DEBUG || SQLITE_ENABLE_WALSTAT */
71572
71573
71574 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
71575 /*
71576 ** Append JSON-5 structure elements onto describing the current state
71577 ** of pWal onto the end of pStr. This function is for debugging and
71578 ** analysis only and is not included in production builds.
71579 */
71580 SQLITE_PRIVATE void sqlite3WalStat(Wal *pWal, sqlite3_str *pStr){
71581 SEH_TRY {
71582 int i;
71583 volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
71584 volatile WalIndexHdr *pHdr = walIndexHdr(pWal);
71585 sqlite3_str_appendf(pStr, "hdr0:{");
71586 walIndexHdrStat(pHdr,pStr);
71587 sqlite3_str_appendf(pStr, "},ckpt:{");
71588 sqlite3_str_appendf(pStr, "nBackfill:%u",pInfo->nBackfill);
71589 sqlite3_str_appendf(pStr, ",aReadMark:[%u", pInfo->aReadMark[0]);
71590 for(i=1; i<WAL_NREADER; i++){
71591 sqlite3_str_appendf(pStr, ",%u", pInfo->aReadMark[i]);
71592 }
71593 sqlite3_str_appendf(pStr, "],nBackfillAttempted:%u}",
71594 pInfo->nBackfillAttempted);
71595
71596 sqlite3_str_appendf(pStr, ",nWiData:%d", pWal->nWiData);
71597 sqlite3_str_appendf(pStr, ",readLock:%d", pWal->readLock);
71598 sqlite3_str_appendf(pStr, ",minFrame:%u", pWal->minFrame);
71599 }
71600 SEH_EXCEPT( ; )
71601 }
71602 #endif /* SQLITE_DEBUG || SQLITE_ENABLE_WALSTAT */
71603
71604 #endif /* #ifndef SQLITE_OMIT_WAL */
71605
71606 /************** End of wal.c *************************************************/
71607 /************** Begin file btmutex.c *****************************************/
@@ -74646,11 +74835,11 @@
74835 }
74836 next = get2byte(&data[pc]);
74837 size = get2byte(&data[pc+2]);
74838 if( size<4 && sqlite3FaultSim(422)==SQLITE_OK ){
74839 /* Minimum freeblock size is 4. Enable fault-sim 422 to disable this
74840 ** check to reach interesting error states. However, disabling this
74841 ** check can cause assertion faults due to min-heap overflow. All
74842 ** fault-sims are for testing use only, but this one especially so. */
74843 return SQLITE_CORRUPT_PAGE(pPage);
74844 }
74845 nFree = nFree + size;
@@ -82907,10 +83096,13 @@
83096 if( rc!=SQLITE_OK ){
83097 return rc;
83098 }
83099 pMove = 0;
83100 rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
83101 if( rc==SQLITE_OK ){
83102 rc = sqlite3PagerWrite(pMove->pDbPage);
83103 }
83104 freePage(pMove, &rc);
83105 releasePage(pMove);
83106 if( rc!=SQLITE_OK ){
83107 return rc;
83108 }
@@ -83727,13 +83919,13 @@
83919 sCheck.aPgRef = sqlite3MallocZero((sCheck.nCkPage / 8)+ 1);
83920 if( !sCheck.aPgRef ){
83921 checkOom(&sCheck);
83922 goto integrity_ck_cleanup;
83923 }
83924 sCheck.heap = (u32*)sqlite3Malloc( pBt->pageSize*2 );
83925 #ifdef SQLITE_DEBUG
83926 sCheck.mxHeap = pBt->pageSize/2 - 1;
83927 #endif
83928 if( sCheck.heap==0 ){
83929 checkOom(&sCheck);
83930 goto integrity_ck_cleanup;
83931 }
@@ -83817,11 +84009,11 @@
84009 }
84010
84011 /* Clean up and report errors.
84012 */
84013 integrity_ck_cleanup:
84014 sqlite3_free(sCheck.heap);
84015 sqlite3_free(sCheck.aPgRef);
84016 *pnErr = sCheck.nErr;
84017 if( sCheck.nErr==0 ){
84018 sqlite3_str_reset(&sCheck.errMsg);
84019 *pzOut = 0;
@@ -86925,11 +87117,11 @@
87117 if( pExpr ){
87118 rc = valueFromExpr(db, pExpr, enc, affinity, &pVal, 0);
87119 if( rc==SQLITE_OK && pVal
87120 && affinity==SQLITE_AFF_REAL
87121 && (pVal->flags & MEM_Int)
87122 && (pVal->u.i<-140737488355328LL || pVal->u.i>140737488355327LL)
87123 ){
87124 /* If the integer value is too large to fit in a 6-byte integer and
87125 ** the affinity is REAL, convert it to a real value now. In most
87126 ** cases an OP_RealAffinity opcode will be used to convert the
87127 ** value to an actual real, but this opcode is omitted if the values
@@ -92336,11 +92528,11 @@
92528 }
92529 testcase( flags & MEM_Real );
92530 testcase( flags & MEM_Null );
92531 testcase( flags & MEM_Blob );
92532 if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0
92533 && sqlite3IsBinary(p->pKeyInfo->aColl[0])
92534 ){
92535 assert( flags & MEM_Str );
92536 p->u.z = p->aMem[0].z;
92537 p->n = p->aMem[0].n;
92538 return vdbeRecordCompareString;
@@ -101668,11 +101860,13 @@
101860 if( x.flags & MEM_Int ){
101861 iKey = x.u.i;
101862 }else
101863 if( (x.flags & MEM_Real)==0
101864 || x.u.r < -9223372036854775808.0
101865 || x.u.r > 9223372036854774784.0
101866 /* ^^^^^^^^^^^^^^^^^^^^^-- same value as every other double
101867 ** between 9223372036854774263.0 and 923372036854775295.0 */
101868 || (double)(iKey = sqlite3RealToI64(x.u.r))!=x.u.r
101869 ){
101870 goto jump_to_p2;
101871 }
101872 goto notExistsWithKey;
@@ -102352,18 +102546,21 @@
102546 }
102547 pOut->u.i = v;
102548 break;
102549 }
102550
102551 /* Opcode: NullRow P1 P2 * * *
102552 **
102553 ** Move the cursor P1 to a null row if P2 is 0. Any OP_Column operations
102554 ** that occur while the cursor is on the null row will always
102555 ** write a NULL.
102556 **
102557 ** If cursor P1 is not previously opened, open it now to a special
102558 ** pseudo-cursor that always returns NULL for every column.
102559 **
102560 ** If P2 is not 0, then the nullRow flag on the pseudo-cursor is
102561 ** turned off.
102562 */
102563 case OP_NullRow: {
102564 VdbeCursor *pC;
102565
102566 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -102376,11 +102573,11 @@
102573 pC->seekResult = 0;
102574 pC->isTable = 1;
102575 pC->noReuse = 1;
102576 pC->uc.pCursor = sqlite3BtreeFakeValidCursor();
102577 }
102578 pC->nullRow = (pOp->p2==0);
102579 pC->cacheStatus = CACHE_STALE;
102580 if( pC->eCurType==CURTYPE_BTREE ){
102581 assert( pC->uc.pCursor!=0 );
102582 sqlite3BtreeClearCursor(pC->uc.pCursor);
102583 }
@@ -120900,10 +121097,11 @@
121097 /* Verify that constraints are still satisfied */
121098 if( pNew->pCheck!=0
121099 || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0)
121100 || (pTab->tabFlags & TF_Strict)!=0
121101 ){
121102 pParse->colNamesSet = 1;
121103 sqlite3NestedParse(pParse,
121104 "SELECT CASE WHEN quick_check GLOB 'CHECK*'"
121105 " THEN raise(ABORT,'CHECK constraint failed')"
121106 " WHEN quick_check GLOB 'non-* value in*'"
121107 " THEN raise(ABORT,'type mismatch on DEFAULT')"
@@ -134337,11 +134535,11 @@
134535 }
134536 if( argc==3 ){
134537 p2 = sqlite3_value_int64(argv[2]);
134538 if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
134539 }else{
134540 p2 = LARGEST_INT64;
134541 }
134542 if( p1==0 ){
134543 #ifdef SQLITE_SUBSTR_COMPATIBILITY
134544 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
134545 ** as substr(X,1,N) - it returns the first N characters of X. This
@@ -135776,10 +135974,25 @@
135974 sqlite3_result_text(context, "?000", 4, SQLITE_STATIC);
135975 }
135976 }
135977 #endif /* SQLITE_SOUNDEX */
135978
135979 #if defined(SQLITE_DEBUG) || defined(SQLITE_BUILTIN_OOM_FUNCTION)
135980 /*
135981 ** This SQL function just invokes sqlite3OomFault() and then returns
135982 ** NULL. Used for testing only.
135983 */
135984 static void oomFunc(
135985 sqlite3_context *context,
135986 int argc,
135987 sqlite3_value **argv
135988 ){
135989 sqlite3 *db = sqlite3_context_db_handle(context);
135990 sqlite3OomFault(db);
135991 }
135992 #endif /* SQLITE_DEBUG || SQLITE_BUILTIN_OOM_FUNCTION */
135993
135994 #ifndef SQLITE_OMIT_LOAD_EXTENSION
135995 /*
135996 ** A function that loads a shared-library extension then returns NULL.
135997 */
135998 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
@@ -137146,10 +137359,52 @@
137359 sqlite3_result_text(context, "{}", 2, SQLITE_STATIC);
137360 }
137361 }
137362 #endif /* SQLITE_DEBUG || SQLITE_ENABLE_FILESTAT */
137363
137364 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_WALSTAT)
137365 /*
137366 ** Implementation of sqlite_walstat(SCHEMA).
137367 **
137368 ** Return JSON text that describes the current state of a WAL file.
137369 ** This function is for debugging and analysis only. It is not part
137370 ** of production builds. This function is not part of the SQLite API
137371 ** and is likely to change or be removed in future versions of SQLite.
137372 */
137373 static void walstatFunc(
137374 sqlite3_context *context,
137375 int argc,
137376 sqlite3_value **argv
137377 ){
137378 sqlite3 *db = sqlite3_context_db_handle(context);
137379 const char *zDbName;
137380 sqlite3_str *pStr;
137381 Btree *pBtree;
137382
137383 zDbName = (const char*)sqlite3_value_text(argv[0]);
137384 pBtree = sqlite3DbNameToBtree(db, zDbName);
137385 if( pBtree ){
137386 Pager *pPager;
137387 sqlite3BtreeEnter(pBtree);
137388 pPager = sqlite3BtreePager(pBtree);
137389 assert( pPager!=0 );
137390 pStr = sqlite3_str_new(db);
137391 if( sqlite3_str_errcode(pStr) ){
137392 sqlite3_result_error_nomem(context);
137393 }else{
137394 sqlite3_str_append(pStr, "{", 1);
137395 sqlite3PagerWalStat(pPager, pStr);
137396 sqlite3_str_append(pStr, "}", 1);
137397 sqlite3_result_str(context, pStr, SQLITE_FINISH);
137398 }
137399 sqlite3BtreeLeave(pBtree);
137400 }else{
137401 sqlite3_result_text(context, "{}", 2, SQLITE_STATIC);
137402 }
137403 }
137404 #endif /* SQLITE_DEBUG || SQLITE_ENABLE_WALSTAT */
137405
137406 #ifdef SQLITE_DEBUG
137407 /*
137408 ** Implementation of fpdecode(x,y,z) function.
137409 **
137410 ** x is a real number that is to be decoded. y is the precision.
@@ -137306,10 +137561,11 @@
137561 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
137562 INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
137563 #endif
137564 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_FILESTAT)
137565 FUNCTION(sqlite_filestat, 1, 0, 0, filestatFunc ),
137566 FUNCTION(sqlite_walstat, 1, 0, 0, walstatFunc ),
137567 #endif
137568 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
137569 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
137570 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
137571 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
@@ -137333,10 +137589,13 @@
137589 FUNCTION(char, -1, 0, 0, charFunc ),
137590 FUNCTION(abs, 1, 0, 0, absFunc ),
137591 #ifdef SQLITE_DEBUG
137592 FUNCTION(fpdecode, 3, 0, 0, fpdecodeFunc ),
137593 FUNCTION(parseuri, -1, 0, 0, parseuriFunc ),
137594 #endif
137595 #if defined(SQLITE_DEBUG) || defined(SQLITE_BUILTIN_OOM_FUNCTION)
137596 FUNCTION(oom, -1, 0, 0, oomFunc ),
137597 #endif
137598 #ifndef SQLITE_OMIT_FLOATING_POINT
137599 FUNCTION(round, 1, 0, 0, roundFunc ),
137600 FUNCTION(round, 2, 0, 0, roundFunc ),
137601 #endif
@@ -142714,11 +142973,11 @@
142973 void (*interruptx)(sqlite3*);
142974 sqlite_int64 (*last_insert_rowid)(sqlite3*);
142975 const char * (*libversion)(void);
142976 int (*libversion_number)(void);
142977 void *(*malloc)(int);
142978 char *(SQLITE_CDECL*mprintf)(const char*,...);
142979 int (*open)(const char*,sqlite3**);
142980 int (*open16)(const void*,sqlite3**);
142981 int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
142982 int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
142983 void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
@@ -142735,15 +142994,15 @@
142994 void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
142995 void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
142996 void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
142997 void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
142998 void (*result_value)(sqlite3_context*,sqlite3_value*);
142999 void *(*rollback_hook)(sqlite3*,void(*)(void*),void*);
143000 int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
143001 const char*,const char*),void*);
143002 void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
143003 char *(SQLITE_CDECL*xsnprintf)(int,char*,const char*,...);
143004 int (*step)(sqlite3_stmt*);
143005 int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
143006 char const**,char const**,int*,int*,int*);
143007 void (*thread_cleanup)(void);
143008 int (*total_changes)(sqlite3*);
@@ -142803,11 +143062,11 @@
143062 int (*vfs_register)(sqlite3_vfs*,int);
143063 int (*vfs_unregister)(sqlite3_vfs*);
143064 int (*xthreadsafe)(void);
143065 void (*result_zeroblob)(sqlite3_context*,int);
143066 void (*result_error_code)(sqlite3_context*,int);
143067 int (SQLITE_CDECL*test_control)(int, ...);
143068 void (*randomness)(int,void*);
143069 sqlite3 *(*context_db_handle)(sqlite3_context*);
143070 int (*extended_result_codes)(sqlite3*,int);
143071 int (*limit)(sqlite3*,int,int);
143072 sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
@@ -142823,25 +143082,25 @@
143082 int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
143083 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
143084 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
143085 void (*xFinal)(sqlite3_context*),
143086 void(*xDestroy)(void*));
143087 int (SQLITE_CDECL*db_config)(sqlite3*,int,...);
143088 sqlite3_mutex *(*db_mutex)(sqlite3*);
143089 int (*db_status)(sqlite3*,int,int*,int*,int);
143090 int (*extended_errcode)(sqlite3*);
143091 void (SQLITE_CDECL*log)(int,const char*,...);
143092 sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
143093 const char *(*sourceid)(void);
143094 int (*stmt_status)(sqlite3_stmt*,int,int);
143095 int (*strnicmp)(const char*,const char*,int);
143096 int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
143097 int (*wal_autocheckpoint)(sqlite3*,int);
143098 int (*wal_checkpoint)(sqlite3*,const char*);
143099 void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
143100 int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
143101 int (SQLITE_CDECL*vtab_config)(sqlite3*,int op,...);
143102 int (*vtab_on_conflict)(sqlite3*);
143103 /* Version 3.7.16 and later */
143104 int (*close_v2)(sqlite3*);
143105 const char *(*db_filename)(sqlite3*,const char*);
143106 int (*db_readonly)(sqlite3*,const char*);
@@ -142906,11 +143165,11 @@
143165 int (*keyword_count)(void);
143166 int (*keyword_name)(int,const char**,int*);
143167 int (*keyword_check)(const char*,int);
143168 sqlite3_str *(*str_new)(sqlite3*);
143169 char *(*str_finish)(sqlite3_str*);
143170 void (SQLITE_CDECL*str_appendf)(sqlite3_str*, const char *zFormat, ...);
143171 void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list);
143172 void (*str_append)(sqlite3_str*, const char *zIn, int N);
143173 void (*str_appendall)(sqlite3_str*, const char *zIn);
143174 void (*str_appendchar)(sqlite3_str*, int N, char C);
143175 void (*str_reset)(sqlite3_str*);
@@ -144551,11 +144810,11 @@
144810 /* ePragTyp: */ PragTyp_FLAG,
144811 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
144812 /* ColNames: */ 0, 0,
144813 /* iArg: */ SQLITE_CountRows },
144814 #endif
144815 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && defined(_WIN32)
144816 {/* zName: */ "data_store_directory",
144817 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
144818 /* ePragFlg: */ PragFlg_NoColumns1,
144819 /* ColNames: */ 0, 0,
144820 /* iArg: */ 0 },
@@ -144974,11 +145233,11 @@
145233 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
145234 /* ColNames: */ 0, 0,
145235 /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
145236 #endif
145237 };
145238 /* Number of pragmas: 67 on by default, 78 total. */
145239
145240 /************** End of pragma.h **********************************************/
145241 /************** Continuing where we left off in pragma.c *********************/
145242
145243 /*
@@ -145027,11 +145286,11 @@
145286 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 5, 4};
145287 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 3, 2};
145288 /* on no off false yes true extra full */
145289 int i, n;
145290 if( sqlite3Isdigit(*z) ){
145291 return sqlite3Atoi(z)!=0;
145292 }
145293 n = sqlite3Strlen30(z);
145294 for(i=0; i<ArraySize(iLength); i++){
145295 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0
145296 && (!omitFull || iValue[i]<=1)
@@ -146086,11 +146345,17 @@
146345 }else{
146346 if( !db->autoCommit ){
146347 sqlite3ErrorMsg(pParse,
146348 "Safety level may not be changed inside a transaction");
146349 }else if( iDb!=1 ){
146350 int iLevel;
146351 if( sqlite3Isdigit(zRight[0]) ){
146352 iLevel = sqlite3Atoi(zRight);
146353 }else{
146354 iLevel = getSafetyLevel(zRight,0,1);
146355 }
146356 iLevel = (iLevel+1) & PAGER_SYNCHRONOUS_MASK;
146357 if( iLevel==0 ) iLevel = 1;
146358 pDb->safety_level = iLevel;
146359 pDb->bSyncSet = 1;
146360 setAllPagerFlags(db);
146361 }
@@ -149688,10 +149953,11 @@
149953 static int sqlite3ProcessJoin(Parse *pParse, Select *p){
149954 SrcList *pSrc; /* All tables in the FROM clause */
149955 int i, j; /* Loop counters */
149956 SrcItem *pLeft; /* Left table being joined */
149957 SrcItem *pRight; /* Right table being joined */
149958 int bSeenTFunc = 0; /* True if have seen table-valued function */
149959
149960 pSrc = p->pSrc;
149961 pLeft = &pSrc->a[0];
149962 pRight = &pLeft[1];
149963 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
@@ -149830,11 +150096,22 @@
150096 pRight->u3.pOn = 0;
150097 pRight->fg.isOn = 1;
150098 p->selFlags |= SF_OnToWhere;
150099 }
150100
150101 if( bSeenTFunc==0 ){
150102 bSeenTFunc = (pLeft->fg.isTabFunc && pLeft->u1.pFuncArg);
150103 }
150104
150105 /* We also need to call sqlite3SelectCheckOnClauses() to verify that
150106 ** table-valued function arguments do not illegally refer to any tables to
150107 ** their right. This test is required if either (a) there is a RIGHT JOIN
150108 ** in the SrcList, or (b) there is a LEFT JOIN to the right of a
150109 ** table-valued function. */
150110 if( (pRight->fg.isTabFunc && joinType==EP_OuterON && pRight->u1.pFuncArg)
150111 || (bSeenTFunc && joinType==EP_OuterON)
150112 ){
150113 p->selFlags |= SF_OnToWhere;
150114 }
150115 }
150116 return 0;
150117 }
@@ -150939,10 +151216,13 @@
151216 /* Open any cursors needed for sorter-reference expressions */
151217 for(i=0; i<pSort->nDefer; i++){
151218 Table *pTab = pSort->aDefer[i].pTab;
151219 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
151220 sqlite3OpenTable(pParse, pSort->aDefer[i].iCsr, iDb, pTab, OP_OpenRead);
151221 sqlite3VdbeAddOp2(v, OP_Rewind, pSort->aDefer[i].iCsr,
151222 sqlite3VdbeCurrentAddr(v)+1);
151223 VdbeCoverage(v);
151224 nRefKey = MAX(nRefKey, pSort->aDefer[i].nKey);
151225 }
151226 #endif
151227
151228 iTab = pSort->iECursor;
@@ -156638,11 +156918,11 @@
156918 ** Type used for Walker callbacks by selectCheckOnClauses().
156919 */
156920 typedef struct CheckOnCtx CheckOnCtx;
156921 struct CheckOnCtx {
156922 SrcList *pSrc; /* SrcList for this context */
156923 int iJoin; /* Cursors must be left of this one, if not negative */
156924 int bFuncArg; /* True for table-function arg */
156925 CheckOnCtx *pParent; /* Parent context */
156926 };
156927
156928 /*
@@ -156671,15 +156951,15 @@
156951 /* If CheckOnCtx.iJoin is already set, then fall through and process
156952 ** this expression node as normal. Or, if CheckOnCtx.iJoin is still 0,
156953 ** set it to the cursor number of the RHS of the join to which this
156954 ** ON expression was attached and then iterate through the entire
156955 ** expression. */
156956 assert( pCtx->iJoin<0 || pCtx->iJoin==pExpr->w.iJoin );
156957 if( pCtx->iJoin<0 ){
156958 pCtx->iJoin = pExpr->w.iJoin;
156959 sqlite3WalkExprNN(pWalker, pExpr);
156960 pCtx->iJoin = -1;
156961 return WRC_Prune;
156962 }
156963 }
156964
156965 if( pExpr->op==TK_COLUMN ){
@@ -156693,11 +156973,11 @@
156973 int nSrc = pSrc->nSrc;
156974 int ii;
156975 for(ii=0; ii<nSrc && pSrc->a[ii].iCursor!=iTab; ii++){}
156976 if( ii<nSrc ){
156977 /* pSrc is the FROM clause that contains iTab */
156978 if( pCtx->iJoin>=0 ){
156979 for(ii--; ii>=0 && pSrc->a[ii].iCursor!=pCtx->iJoin; ii--){}
156980 if( ii>=0 ){
156981 /* Table iJoin appears to the left of table iTab in the SrcList.
156982 ** Therefore the expression refers to a table to its right. */
156983 sqlite3ErrorMsg(pWalker->pParse,
@@ -156725,10 +157005,11 @@
157005 }else{
157006 CheckOnCtx sCtx;
157007 memset(&sCtx, 0, sizeof(sCtx));
157008 sCtx.pSrc = pSelect->pSrc;
157009 sCtx.pParent = pCtx;
157010 sCtx.iJoin = -1;
157011 pWalker->u.pCheckOnCtx = &sCtx;
157012 sqlite3WalkSelect(pWalker, pSelect);
157013 pWalker->u.pCheckOnCtx = pCtx;
157014 pSelect->selFlags &= ~SF_OnToWhere;
157015 return WRC_Prune;
@@ -156750,24 +157031,45 @@
157031 w.xExprCallback = selectCheckOnClausesExpr;
157032 w.xSelectCallback = selectCheckOnClausesSelect;
157033 w.u.pCheckOnCtx = &sCtx;
157034 memset(&sCtx, 0, sizeof(sCtx));
157035 sCtx.pSrc = pSelect->pSrc;
157036 sCtx.iJoin = -1;
157037 sqlite3WalkExpr(&w, pSelect->pWhere);
157038 pSelect->selFlags &= ~SF_OnToWhere;
157039
157040 /* Check for any table-function args that are attached to virtual tables
157041 ** on the RHS of an outer join. They are subject to similar constraints
157042 ** as ON clauses. Specifically:
157043 **
157044 ** * If the table-valued function is to the left of any RIGHT JOIN, or if
157045 ** it is the RHS of a RIGHT JOIN, then the table-valued function arguments
157046 ** may not refer to any tables to the right of this one.
157047 **
157048 ** * If the table-valued function is to the left of a LEFT JOIN, then it
157049 ** may not refer to any table that occurs to the right of the LEFT JOIN.
157050 */
157051 sCtx.bFuncArg = 1;
157052 for(ii=0; ii<pSelect->pSrc->nSrc; ii++){
157053 SrcItem *pItem = &pSelect->pSrc->a[ii];
157054 if( pItem->fg.isTabFunc ){
157055 sCtx.iJoin = -1;
157056 if( (pItem->fg.jointype & (JT_LTORJ|JT_RIGHT)) ){
157057 sCtx.iJoin = pItem->iCursor;
157058 }else{
157059 int jj;
157060 for(jj=ii+1; jj<pSelect->pSrc->nSrc; jj++){
157061 SrcItem *pItem2 = &pSelect->pSrc->a[jj];
157062 if( pItem2->fg.jointype & JT_OUTER ){
157063 sCtx.iJoin = pItem2[-1].iCursor;
157064 break;
157065 }
157066 }
157067 }
157068 if( sCtx.iJoin>=0 ){
157069 sqlite3WalkExprList(&w, pItem->u1.pFuncArg);
157070 }
157071 }
157072 }
157073 }
157074
157075 /*
@@ -160077,12 +160379,11 @@
160379 ** it has been converted into REAL.
160380 */
160381 static SQLITE_NOINLINE void columnDefaultUncommonCase(
160382 Vdbe *v, /* Byte code under construction */
160383 Table *pTab, /* The table */
160384 Column *pCol /* Which column of the table */
 
160385 ){
160386 sqlite3_value *pValue = 0;
160387 u8 enc = ENC(sqlite3VdbeDb(v));
160388 Parse *pParse = sqlite3VdbeParser(v);
160389 assert( !IsView(pTab) );
@@ -160090,15 +160391,10 @@
160391 sqlite3ColumnExprAuth(pTab,pCol,pParse), enc,
160392 pCol->affinity, &pValue);
160393 if( pValue ){
160394 sqlite3VdbeAppendP4(v, pValue, P4_MEM);
160395 }
 
 
 
 
 
160396 }
160397 SQLITE_PRIVATE void sqlite3ColumnDefault(
160398 Vdbe *v, /* Byte code under construction */
160399 Table *pTab, /* The table */
160400 int i, /* Which column of the table */
@@ -160107,11 +160403,11 @@
160403 Column *pCol;
160404 assert( pTab!=0 );
160405 assert( pTab->nCol>i );
160406 pCol = &pTab->aCol[i];
160407 if( pCol->iDflt ){
160408 columnDefaultUncommonCase(v,pTab,pCol);
160409 }
160410 #ifndef SQLITE_OMIT_FLOATING_POINT
160411 if( pCol->affinity==SQLITE_AFF_REAL ){
160412 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
160413 }
@@ -165194,21 +165490,11 @@
165490 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
165491 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
165492 testcase( pTerm->wtFlags & TERM_VIRTUAL );
165493 r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
165494 if( r1!=regBase+j ){
165495 sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
 
 
 
 
 
 
 
 
 
 
165496 }
165497 if( pTerm->eOperator & WO_IN ){
165498 if( pTerm->pExpr->flags & EP_xIsSelect ){
165499 /* No affinity ever needs to be (or should be) applied to a value
165500 ** from the RHS of an "? IN (SELECT ...)" expression. The
@@ -165824,10 +166110,13 @@
166110 );
166111 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
166112 pLevel->iLeftJoin = ++pParse->nMem;
166113 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
166114 VdbeComment((v, "init LEFT JOIN match flag"));
166115 if( pTabItem->fg.viaCoroutine ){
166116 sqlite3VdbeAddOp2(v, OP_NullRow, pTabItem->iCursor, 1);
166117 }
166118 }
166119
166120 /* Special case of a FROM clause subquery implemented as a co-routine */
166121 if( pTabItem->fg.viaCoroutine ){
166122 int regYield;
@@ -176880,21 +177169,21 @@
177169 sqlite3VdbeChangeP5(v, pLevel->p5);
177170 VdbeCoverage(v);
177171 VdbeCoverageIf(v, pLevel->op==OP_Next);
177172 VdbeCoverageIf(v, pLevel->op==OP_Prev);
177173 VdbeCoverageIf(v, pLevel->op==OP_VNext);
 
 
 
 
 
177174 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
177175 if( addrSeek ){
177176 sqlite3VdbeJumpHere(v, addrSeek);
177177 addrSeek = 0;
177178 }
177179 #endif
177180 if( pLevel->regBignull ){
177181 sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
177182 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1);
177183 VdbeCoverage(v);
177184 }
177185 }
177186 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
177187 struct InLoop *pIn;
177188 int j;
177189 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
@@ -177517,10 +177806,11 @@
177806 ){
177807 struct CallCount *p;
177808 UNUSED_PARAMETER(nArg); assert( nArg==0 );
177809 UNUSED_PARAMETER(apArg);
177810 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
177811 assert( p!=0 );
177812 p->nStep++;
177813 }
177814 static void percent_rankValueFunc(sqlite3_context *pCtx){
177815 struct CallCount *p;
177816 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
@@ -177562,10 +177852,11 @@
177852 ){
177853 struct CallCount *p;
177854 UNUSED_PARAMETER(nArg); assert( nArg==0 );
177855 UNUSED_PARAMETER(apArg);
177856 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
177857 assert( p!=0 );
177858 p->nStep++;
177859 }
177860 static void cume_distValueFunc(sqlite3_context *pCtx){
177861 struct CallCount *p;
177862 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
@@ -177618,10 +177909,11 @@
177909 ){
177910 struct NtileCtx *p;
177911 assert( nArg==1 ); UNUSED_PARAMETER(nArg);
177912 UNUSED_PARAMETER(apArg);
177913 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
177914 assert( p!=0 );
177915 p->iRow++;
177916 }
177917 static void ntileValueFunc(sqlite3_context *pCtx){
177918 struct NtileCtx *p;
177919 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
@@ -184558,10 +184850,11 @@
184850 if( yymsp[-5].minor.yy203 ){
184851 SrcItem *pNew = &yymsp[-5].minor.yy203->a[yymsp[-5].minor.yy203->nSrc-1];
184852 SrcItem *pOld = yymsp[-3].minor.yy203->a;
184853 assert( pOld->fg.fixedSchema==0 );
184854 pNew->zName = pOld->zName;
184855 pOld->zName = 0;
184856 assert( pOld->fg.fixedSchema==0 );
184857 if( pOld->fg.isSubquery ){
184858 pNew->fg.isSubquery = 1;
184859 pNew->u4.pSubq = pOld->u4.pSubq;
184860 pOld->u4.pSubq = 0;
@@ -184577,12 +184870,17 @@
184870 if( pOld->fg.isTabFunc ){
184871 pNew->u1.pFuncArg = pOld->u1.pFuncArg;
184872 pOld->u1.pFuncArg = 0;
184873 pOld->fg.isTabFunc = 0;
184874 pNew->fg.isTabFunc = 1;
184875 }else if( pOld->fg.isIndexedBy ){
184876 pNew->u1.zIndexedBy = pOld->u1.zIndexedBy;
184877 pOld->u1.zIndexedBy = 0;
184878 pOld->fg.isIndexedBy = 0;
184879 pNew->fg.isIndexedBy = 1;
184880 }
184881 pNew->fg.notIndexed = pOld->fg.notIndexed;
184882 }
184883 sqlite3SrcListDelete(pParse->db, yymsp[-3].minor.yy203);
184884 }else{
184885 Select *pSubquery;
184886 sqlite3SrcListShiftJoinType(pParse,yymsp[-3].minor.yy203);
@@ -188939,11 +189237,11 @@
189237
189238 /*
189239 ** This is the default collating function named "BINARY" which is always
189240 ** available.
189241 */
189242 SQLITE_PRIVATE int sqlite3BinaryCompare(
189243 void *NotUsed,
189244 int nKey1, const void *pKey1,
189245 int nKey2, const void *pKey2
189246 ){
189247 int rc, n;
@@ -188971,20 +189269,23 @@
189269 ){
189270 const u8 *pK1 = (const u8*)pKey1;
189271 const u8 *pK2 = (const u8*)pKey2;
189272 while( nKey1 && pK1[nKey1-1]==' ' ) nKey1--;
189273 while( nKey2 && pK2[nKey2-1]==' ' ) nKey2--;
189274 return sqlite3BinaryCompare(pUser, nKey1, pKey1, nKey2, pKey2);
189275 }
189276
189277 /*
189278 ** Return true if CollSeq is the default built-in BINARY.
189279 */
189280 #if !SQLITE_USES_INLINE
189281 SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq *p){
189282 assert( p==0 || p->xCmp!=sqlite3BinaryCompare
189283 || strcmp(p->zName,"BINARY")==0 );
189284 return p==0 || p->xCmp==sqlite3BinaryCompare;
189285 }
189286 #endif
189287
189288 /*
189289 ** Another built-in collating sequence: NOCASE.
189290 **
189291 ** This collating sequence is intended to be used for "case independent
@@ -189932,11 +190233,11 @@
190233 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0);
190234 if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==(u32)enc && p->nArg==nArg ){
190235 if( db->nVdbeActive ){
190236 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
190237 "unable to delete/modify user-function due to active statements");
190238 assert( !db->mallocFailed || db->nVdbeExec>0 );
190239 return SQLITE_BUSY;
190240 }else{
190241 sqlite3ExpirePreparedStatements(db, 0);
190242 }
190243 }else if( xSFunc==0 && xFinal==0 ){
@@ -191454,13 +191755,16 @@
191755 ** conversions. The only error that can occur here is a malloc() failure.
191756 **
191757 ** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
191758 ** functions:
191759 */
191760 createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0,
191761 sqlite3BinaryCompare, 0);
191762 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0,
191763 sqlite3BinaryCompare, 0);
191764 createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0,
191765 sqlite3BinaryCompare, 0);
191766 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
191767 createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0);
191768 if( db->mallocFailed ){
191769 goto opendb_out;
191770 }
@@ -198200,12 +198504,12 @@
198504 Fts3Table *pTab = 0;
198505 Fts3Cursor *pCsr; /* Cursor handle passed through apVal[0] */
198506 const char *zStart = "<b>";
198507 const char *zEnd = "</b>";
198508 const char *zEllipsis = "<b>...</b>";
198509 i64 iCol = -1;
198510 i64 nToken = 15; /* Default number of tokens in snippet */
198511
198512 /* There must be at least one argument passed to this function (otherwise
198513 ** the non-overloaded version would have been called instead of this one).
198514 */
198515 assert( nVal>=1 );
@@ -198217,13 +198521,13 @@
198521 }
198522 if( fts3FunctionArg(pContext, "snippet", apVal[0], &pCsr) ) return;
198523 pTab = (Fts3Table *)pCsr->base.pVtab;
198524
198525 switch( nVal ){
198526 case 6: nToken = sqlite3_value_int64(apVal[5]);
198527 /* no break */ deliberate_fall_through
198528 case 5: iCol = sqlite3_value_int64(apVal[4]);
198529 /* no break */ deliberate_fall_through
198530 case 4: zEllipsis = (const char*)sqlite3_value_text(apVal[3]);
198531 /* no break */ deliberate_fall_through
198532 case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
198533 /* no break */ deliberate_fall_through
@@ -198232,10 +198536,13 @@
198536 if( !zEllipsis || !zEnd || !zStart ){
198537 sqlite3_result_error_nomem(pContext);
198538 }else if( nToken==0 || iCol>=pTab->nColumn ){
198539 sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
198540 }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
198541 if( iCol<0 ) iCol = -1;
198542 if( nToken<-64 ) nToken = -64;
198543 if( nToken>64 ) nToken = 64;
198544 sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken);
198545 }
198546 }
198547
198548 /*
@@ -203595,14 +203902,15 @@
203902 }
203903
203904 if( c->iOffset>iStartOffset ){
203905 int n = c->iOffset-iStartOffset;
203906 if( n>c->nAllocated ){
203907 i64 nNew = n + 20;
203908 char *pNew;
203909 pNew = sqlite3_realloc64(c->zToken, nNew);
 
203910 if( !pNew ) return SQLITE_NOMEM;
203911 c->nAllocated = (int)nNew;
203912 c->zToken = pNew;
203913 }
203914 porter_stemmer(&z[iStartOffset], n, c->zToken, pnBytes);
203915 *pzToken = c->zToken;
203916 *piStartOffset = iStartOffset;
@@ -210126,42 +210434,46 @@
210434 );
210435 if( rc==SQLITE_OK ){
210436 rc = sqlite3Fts3SegReaderStart(p, &csr, &filter);
210437 }
210438
210439 while( rc==SQLITE_OK && SQLITE_ROW==(rc = sqlite3Fts3SegReaderStep(p,&csr)) ){
210440 char *pCsr = csr.aDoclist;
210441 char *pEnd = &pCsr[csr.nDoclist];
210442
210443 i64 iDocid = 0;
210444 int iCol = 0;
210445 u64 iPos = 0;
210446
210447 rc = SQLITE_OK;
210448 pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid);
210449 while( pCsr<pEnd ){
210450 u64 iVal = 0;
210451 pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
210452 if( pCsr<pEnd ){
210453 if( iVal==0 || iVal==1 ){
210454 iCol = 0;
210455 iPos = 0;
210456 if( iVal ){
210457 pCsr += fts3GetVarint32(pCsr, &iCol);
210458 }else{
210459 pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
210460 if( p->bDescIdx ){
210461 iDocid = (i64)((u64)iDocid - iVal);
210462 }else{
210463 iDocid = (i64)((u64)iDocid + iVal);
210464 }
210465 }
210466 }else{
210467 iPos += (iVal - 2);
210468 if( iPos>0x7FFFFFFF ){
210469 rc = SQLITE_CORRUPT_VTAB;
210470 break;
210471 }else{
210472 cksum = cksum ^ fts3ChecksumEntry(
210473 csr.zTerm, csr.nTerm, iLangid, iIndex, iDocid,
210474 iCol, (int)iPos
210475 );
210476 }
210477 }
210478 }
210479 }
@@ -212193,13 +212505,12 @@
212505 if( !pCsr->pExpr ){
212506 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
212507 return;
212508 }
212509
212510 /* The snippet length should already have been limited to 64 tokens. */
212511 assert( nToken>=-64 && nToken<=64 );
 
212512
212513 for(nSnippet=1; 1; nSnippet++){
212514
212515 int iSnip; /* Loop counter 0..nSnippet-1 */
212516 u64 mCovered = 0; /* Bitmask of phrases covered by snippet */
@@ -215936,11 +216247,14 @@
216247 jsonStringTooDeep(pOut);
216248 }
216249 while( pOut->eErr==0 ){
216250 jsonPrettyIndent(pPretty);
216251 j = jsonTranslateBlobToPrettyText(pPretty, j);
216252 if( j>=iEnd ){
216253 if( j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
216254 break;
216255 }
216256 jsonAppendRawNZ(pOut, ",\n", 2);
216257 }
216258 jsonAppendChar(pOut, '\n');
216259 pPretty->nIndent--;
216260 jsonPrettyIndent(pPretty);
@@ -218896,11 +219210,11 @@
219210 sqlite3_result_text64(ctx, p->path.zBuf, n,
219211 SQLITE_TRANSIENT, SQLITE_UTF8);
219212 break;
219213 }
219214 default: {
219215 sqlite3_result_text(ctx, p->path.zBuf, p->nRoot, SQLITE_TRANSIENT);
219216 break;
219217 }
219218 case JEACH_JSON: {
219219 if( p->sParse.zJson==0 ){
219220 sqlite3_result_blob(ctx, p->sParse.aBlob, p->sParse.nBlob,
@@ -219828,10 +220142,22 @@
220142 p[6] = (i>> 8)&0xFF;
220143 p[7] = (i>> 0)&0xFF;
220144 #endif
220145 return 8;
220146 }
220147
220148 /*
220149 ** Translate pVal into a 32-bit integer. If pVal is an integer
220150 ** that is larger than 32 bits, the cap it at the largest or
220151 ** smallest 32-bit integer.
220152 */
220153 static int rtreeValueInt32(sqlite3_value *pVal){
220154 i64 v64 = sqlite3_value_int64(pVal);
220155 if( v64>2147483647 ) return 2147483647;
220156 if( v64<-2147483648LL ) return (int)-2147483648LL;
220157 return (int)v64;
220158 }
220159
220160 /*
220161 ** Increment the reference count of node p.
220162 */
220163 static void nodeReference(RtreeNode *p){
@@ -220109,11 +220435,21 @@
220435 pNode->isDirty = 0;
220436 rc = sqlite3_reset(p);
220437 sqlite3_bind_null(p, 2);
220438 if( pNode->iNode==0 && rc==SQLITE_OK ){
220439 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
220440 if( pNode->iNode==0 ){
220441 /* If the SQL statement has succeeded but sqlite3_last_insert_rowid()
220442 ** returns 0, then the shadow table schema has been corrupted somehow
220443 ** (e.g. the %_node table has been replaced by a WITHOUT ROWID table).
220444 ** It would be dangerous to continue in this case as the hash table
220445 ** implementation assumes iNode==0 means that the node is not part
220446 ** of the hash table. */
220447 rc = SQLITE_CORRUPT_VTAB;
220448 }else{
220449 nodeHashInsert(pRtree, pNode);
220450 }
220451 }
220452 }
220453 return rc;
220454 }
220455
@@ -222232,39 +222568,64 @@
222568 }
222569
222570 return rc;
222571 }
222572
 
 
 
 
 
 
222573 #if !defined(SQLITE_RTREE_INT_ONLY)
222574 /*
222575 ** Convert an sqlite3_value into an RtreeValue (presumably a float)
222576 ** while taking care to round toward negative or positive, respectively.
222577 */
222578 static RtreeValue rtreeValueDown(sqlite3_value *v){
222579 double d = sqlite3_value_double(v);
222580 float f = (float)d;
222581 if( f>d ){
222582 unsigned int x;
222583 memcpy(&x, &f, 4);
222584 x = (x & 0x80000000)!=0 ? x+1 : x-1;
222585 memcpy(&f, &x, 4);
222586 }
222587 return f;
222588 }
222589 static RtreeValue rtreeValueUp(sqlite3_value *v){
222590 double d = sqlite3_value_double(v);
222591 float f = (float)d;
222592 if( f<d ){
222593 unsigned int x;
222594 memcpy(&x, &f, 4);
222595 x = (x & 0x80000000)!=0 ? x-1 : x+1;
222596 memcpy(&f, &x, 4);
222597 }
222598 return f;
222599 }
222600 #endif /* !defined(SQLITE_RTREE_INT_ONLY) */
222601
222602 #if !defined(SQLITE_RTREE_INT_ONLY) && defined(SQLITE_DEBUG)
222603 /*
222604 ** SQL function: rtree_round32(V,F)
222605 **
222606 ** Convert the floating point value V to the nearest 32-bit float
222607 ** and return that 32-bit float value. Round up if F is true, or
222608 ** down if F is falsed.
222609 **
222610 ** Debugging and testing use only.
222611 */
222612 static void rtreeRoundFunc(
222613 sqlite3_context *ctx,
222614 int nArg,
222615 sqlite3_value **apArg
222616 ){
222617 float f;
222618 if( sqlite3_value_int(apArg[1]) ){
222619 f = rtreeValueUp(apArg[0]);
222620 }else{
222621 f = rtreeValueDown(apArg[0]);
222622 }
222623 sqlite3_result_double(ctx, (double)f);
222624 }
222625 #endif /* !defined(SQLITE_RTREE_INT_ONLY) && defined(SQLITE_DEBUG) */
222626
222627 /*
222628 ** A constraint has failed while inserting a row into an rtree table.
222629 ** Assuming no OOM error occurs, this function sets the error message
222630 ** (at pRtree->base.zErrMsg) to an appropriate value and returns
222631 ** SQLITE_CONSTRAINT.
@@ -222373,12 +222734,12 @@
222734 }
222735 }else
222736 #endif
222737 {
222738 for(ii=0; ii<nn; ii+=2){
222739 cell.aCoord[ii].i = rtreeValueInt32(aData[ii+3]);
222740 cell.aCoord[ii+1].i = rtreeValueInt32(aData[ii+4]);
222741 if( cell.aCoord[ii].i>cell.aCoord[ii+1].i ){
222742 rc = rtreeConstraintError(pRtree, ii+1);
222743 goto constraint;
222744 }
222745 }
@@ -222976,16 +223337,18 @@
223337 Rtree tree;
223338 int ii;
223339 int nData;
223340 int errCode;
223341 sqlite3_str *pOut;
223342 i64 nDim64;
223343
223344 UNUSED_PARAMETER(nArg);
223345 memset(&node, 0, sizeof(RtreeNode));
223346 memset(&tree, 0, sizeof(Rtree));
223347 nDim64 = sqlite3_value_int64(apArg[0]);
223348 if( nDim64<1 || nDim64>5 ) return;
223349 tree.nDim = (u8)nDim64;
223350 tree.nDim2 = tree.nDim*2;
223351 tree.nBytesPerCell = 8 + 8 * tree.nDim;
223352 node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
223353 if( node.zData==0 ) return;
223354 nData = sqlite3_value_bytes(apArg[1]);
@@ -225386,10 +225749,16 @@
225749 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
225750 }
225751 if( rc==SQLITE_OK ){
225752 rc = sqlite3_create_function(db, "rtreecheck", -1, utf8, 0,rtreecheck, 0,0);
225753 }
225754 #if defined(SQLITE_DEBUG) && !defined(SQLITE_RTREE_INT_ONLY)
225755 if( rc==SQLITE_OK ){
225756 rc = sqlite3_create_function(db, "rtree_round", 2, utf8, 0,
225757 rtreeRoundFunc, 0, 0);
225758 }
225759 #endif /* SQLITE_DEBUG && !SQLITE_RTREE_INT_ONLY */
225760 if( rc==SQLITE_OK ){
225761 #ifdef SQLITE_RTREE_INT_ONLY
225762 void *c = (void *)RTREE_COORD_INT32;
225763 #else
225764 void *c = (void *)RTREE_COORD_REAL32;
@@ -228466,19 +228835,31 @@
228835 );
228836 }
228837
228838 /* Check that all non-HIDDEN columns in the destination table are also
228839 ** present in the input table. Populate the abTblPk[], azTblType[] and
228840 ** aiTblOrder[] arrays at the same time.
228841 **
228842 ** RBU does not support tables with GENERATED columns. If the target
228843 ** table has any, return an error. */
228844 if( p->rc==SQLITE_OK ){
228845 p->rc = prepareFreeAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
228846 sqlite3_mprintf("PRAGMA table_xinfo(%Q)", pIter->zTbl)
228847 );
228848 }
228849 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
228850 const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
228851 int eHidden = sqlite3_column_int(pStmt, 6);
228852 if( zName==0 ) break; /* An OOM. Bail out */
228853 if( eHidden==1 ) continue; /* Hidden column. Ignore */
228854 if( eHidden!=0 ){
228855 p->rc = SQLITE_ERROR;
228856 p->zErrmsg = sqlite3_mprintf(
228857 "generated columns not supported: %s.%s", pIter->zTbl, zName
228858 );
228859 break;
228860 }
228861 for(i=iOrder; i<pIter->nTblCol; i++){
228862 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
228863 }
228864 if( i==pIter->nTblCol ){
228865 p->rc = SQLITE_ERROR;
@@ -229327,11 +229708,11 @@
229708 int nIdxAlloc = 0;
229709 for(i=0; zSql[i]; i++){
229710 char c = zSql[i];
229711
229712 /* If necessary, grow the pIter->aIdxCol[] array */
229713 if( iIdxCol>=(nIdxAlloc-1) ){
229714 RbuSpan *aIdxCol = (RbuSpan*)sqlite3_realloc64(
229715 pIter->aIdxCol, nIdxAlloc*sizeof(RbuSpan) + 16*sizeof(RbuSpan)
229716 );
229717 if( aIdxCol==0 ){
229718 rc = SQLITE_NOMEM;
@@ -233129,28 +233510,28 @@
233510 StatPage *p = &pCsr->aPage[pCsr->iPage];
233511 if( !pCsr->isAgg ) statResetCounts(pCsr);
233512 while( p->iCell<p->nCell ){
233513 StatCell *pCell = &p->aCell[p->iCell];
233514 while( pCell->iOvfl<pCell->nOvfl ){
233515 int nUsable;
233516 int iOvfl = pCell->iOvfl;
233517 sqlite3BtreeEnter(pBt);
233518 nUsable = sqlite3BtreeGetPageSize(pBt) -
233519 sqlite3BtreeGetReserveNoMutex(pBt);
233520 sqlite3BtreeLeave(pBt);
233521 pCsr->nPage++;
233522 pCsr->iPageno = pCell->aOvfl[iOvfl];
233523 statSizeAndOffset(pCsr);
233524 if( pCell->iOvfl<pCell->nOvfl-1 ){
233525 pCsr->nPayload += nUsable - 4;
233526 }else{
233527 pCsr->nPayload += pCell->nLastOvfl;
233528 pCsr->nUnused += nUsable - 4 - pCell->nLastOvfl;
233529 }
 
233530 pCell->iOvfl++;
233531 if( !pCsr->isAgg ){
233532 pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
 
233533 pCsr->zPagetype = "overflow";
233534 pCsr->zPath = z = sqlite3_mprintf(
233535 "%s%.3x+%.6x", p->zPath, p->iCell, iOvfl
233536 );
233537 return z==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
@@ -240890,11 +241271,11 @@
241271
241272
241273 if( pIter ){
241274 sqlite3changeset_pk(pIter, &abPK, &nCol);
241275 }else if( !pTab && !pGrp->db ){
241276 return SQLITE_ERROR;
241277 }
241278
241279 /* If one was not found above, create a new table now */
241280 if( !pTab ){
241281 SessionTable **ppNew;
@@ -240916,11 +241297,11 @@
241297 pTab->nCol = 0;
241298 rc = sessionInitTable(0, pTab, pGrp->db, pGrp->zDb);
241299 if( rc || pTab->nCol==0 ){
241300 sqlite3_free(pTab->azCol);
241301 sqlite3_free(pTab);
241302 return rc ? rc : SQLITE_ERROR;
241303 }
241304 }
241305
241306 /* The new object must be linked on to the end of the list, not
241307 ** simply added to the start of it. This is to ensure that the
@@ -241754,48 +242135,44 @@
242135 rc = SQLITE_MISUSE;
242136 }else if( eOp!=SQLITE_INSERT && eOp!=SQLITE_UPDATE && eOp!=SQLITE_DELETE ){
242137 rc = SQLITE_ERROR;
242138 }else{
242139 rc = sessionChangesetFindTable(pGrp, zTab, 0, &pTab);
242140 if( pTab==0 && pzErr ){
242141 *pzErr = sqlite3_mprintf("no such table: %s", zTab);
242142 }
242143 }
242144 if( rc==SQLITE_OK ){
242145 int nReq = pTab->nCol * (eOp==SQLITE_UPDATE ? 2 : 1);
242146 pGrp->cd.pTab = pTab;
242147 pGrp->cd.eOp = eOp;
242148 pGrp->cd.bIndirect = bIndirect;
242149
242150 if( pGrp->cd.nBufAlloc<nReq ){
242151 SessionBuffer *aBuf = (SessionBuffer*)sqlite3_realloc(
242152 pGrp->cd.aBuf, nReq * sizeof(SessionBuffer)
242153 );
242154 if( aBuf==0 ){
242155 rc = SQLITE_NOMEM;
242156 }else{
242157 memset(&aBuf[pGrp->cd.nBufAlloc], 0,
242158 sizeof(SessionBuffer) * (nReq - pGrp->cd.nBufAlloc)
242159 );
242160 pGrp->cd.aBuf = aBuf;
242161 pGrp->cd.nBufAlloc = nReq;
242162 }
242163 }
 
 
 
242164
242165 #ifdef SQLITE_DEBUG
242166 {
242167 /* Assert that all column values are currently undefined */
242168 int ii;
242169 for(ii=0; ii<pGrp->cd.nBufAlloc; ii++){
242170 assert( pGrp->cd.aBuf[ii].nBuf==0 );
242171 }
242172 }
242173 #endif
 
242174 }
242175
242176 return rc;
242177 }
242178
@@ -245585,10 +245962,20 @@
245962 }
245963
245964 return rc;
245965 }
245966
245967 /*
245968 ** Return the integer value of pVal, clamped to the range [-1, 0x7FFFFFFF].
245969 ** This is used for the column-number arguments of auxiliary functions,
245970 ** so that 64-bit values that are too large or too small to fit in a
245971 ** 32-bit signed integer are not truncated to what might be a valid
245972 ** column number.
245973 */
245974 static int fts5ValueClampedInt(sqlite3_value *pVal){
245975 return (int)MIN(MAX(sqlite3_value_int64(pVal), -1), 0x7FFFFFFF);
245976 }
245977
245978 /*
245979 ** Implementation of highlight() function.
245980 */
245981 static void fts5HighlightFunction(
@@ -245606,11 +245993,11 @@
245993 const char *zErr = "wrong number of arguments to function highlight()";
245994 sqlite3_result_error(pCtx, zErr, -1);
245995 return;
245996 }
245997
245998 iCol = fts5ValueClampedInt(apVal[0]);
245999 memset(&ctx, 0, sizeof(HighlightContext));
246000 ctx.zOpen = (const char*)sqlite3_value_text(apVal[1]);
246001 ctx.zClose = (const char*)sqlite3_value_text(apVal[2]);
246002 ctx.iRangeEnd = -1;
246003 rc = pApi->xColumnText(pFts, iCol, &ctx.zIn, &ctx.nIn);
@@ -245805,11 +246192,11 @@
246192 return;
246193 }
246194
246195 nCol = pApi->xColumnCount(pFts);
246196 memset(&ctx, 0, sizeof(HighlightContext));
246197 iCol = fts5ValueClampedInt(apVal[0]);
246198 ctx.zOpen = fts5ValueToText(apVal[1]);
246199 ctx.zClose = fts5ValueToText(apVal[2]);
246200 ctx.iRangeEnd = -1;
246201 zEllips = fts5ValueToText(apVal[3]);
246202 nToken = (int)(MIN( MAX(sqlite3_value_int64(apVal[4]), 0), 64));
@@ -246137,11 +246524,11 @@
246524 const char *z = "non-integer argument passed to function fts5_get_locale()";
246525 sqlite3_result_error(pCtx, z, -1);
246526 return;
246527 }
246528
246529 iCol = fts5ValueClampedInt(apVal[0]);
246530 if( iCol<0 || iCol>=pApi->xColumnCount(pFts) ){
246531 sqlite3_result_error_code(pCtx, SQLITE_RANGE);
246532 return;
246533 }
246534
@@ -259897,10 +260284,13 @@
260284 *pCksum = cksum;
260285 return rc;
260286 }
260287
260288 /*
260289 ** This function is purely an internal test. It does not contribute to
260290 ** FTS functionality, or even the integrity-check, in any way.
260291 **
260292 ** Check if buffer z[], size n bytes, contains as series of valid utf-8
260293 ** encoded codepoints. If so, return 0. Otherwise, if the buffer does not
260294 ** contain valid utf-8, return non-zero.
260295 */
260296 static int fts5TestUtf8(const char *z, int n){
@@ -259918,12 +260308,12 @@
260308 if( i+2>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
260309 i += 3;
260310 }else
260311 if( (z[i] & 0xF8)==0xF0 ){
260312 if( i+3>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
260313 if( (z[i+3] & 0xC0)!=0x80 ) return 1;
260314 i += 4;
260315 }else{
260316 return 1;
260317 }
260318 }
260319
@@ -264813,11 +265203,11 @@
265203 int nArg, /* Number of args */
265204 sqlite3_value **apUnused /* Function arguments */
265205 ){
265206 assert( nArg==0 );
265207 UNUSED_PARAM2(nArg, apUnused);
265208 sqlite3_result_text(pCtx, "fts5: 2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c", -1, SQLITE_TRANSIENT);
265209 }
265210
265211 /*
265212 ** Implementation of fts5_locale(LOCALE, TEXT) function.
265213 **
@@ -265706,79 +266096,10 @@
266096 );
266097 sqlite3_reset(pStorage->pSavedRow);
266098 pStorage->pSavedRow = 0;
266099 }
266100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266101 /*
266102 ** Load the contents of the "averages" record from disk into the
266103 ** p->nTotalRow and p->aTotalSize[] variables. If successful, and if
266104 ** argument bCache is true, set the p->bTotalsValid flag to indicate
266105 ** that the contents of aTotalSize[] and nTotalRow are valid until
@@ -265819,10 +266140,114 @@
266140 }
266141 sqlite3_free(buf.p);
266142
266143 return rc;
266144 }
266145
266146 static int fts5StorageDecodeSizeArray(
266147 int *aCol, int nCol, /* Array to populate */
266148 const u8 *aBlob, int nBlob /* Record to read varints from */
266149 ){
266150 int i;
266151 int iOff = 0;
266152 for(i=0; i<nCol; i++){
266153 if( iOff>=nBlob ) return 1;
266154 iOff += fts5GetVarint32(&aBlob[iOff], aCol[i]);
266155 }
266156 return (iOff!=nBlob);
266157 }
266158
266159 /*
266160 ** This function is called to process a DELETE on a contentless_delete=1
266161 ** table. It adds the tombstone required to delete the entry with rowid
266162 ** iDel. If successful, SQLITE_OK is returned. Or, if an error occurs,
266163 ** an SQLite error code.
266164 */
266165 static int fts5StorageContentlessDelete(Fts5Storage *p, i64 iDel){
266166 i64 iOrigin = 0;
266167 sqlite3_stmt *pLookup = 0;
266168 int rc = SQLITE_OK;
266169
266170 assert( p->pConfig->bContentlessDelete );
266171 assert( p->pConfig->eContent==FTS5_CONTENT_NONE
266172 || p->pConfig->eContent==FTS5_CONTENT_UNINDEXED
266173 );
266174
266175 rc = fts5StorageLoadTotals(p, 1);
266176 if( rc!=SQLITE_OK ) return rc;
266177
266178 /* Look up the origin of the document in the %_docsize table. Store
266179 ** this in stack variable iOrigin. */
266180 rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
266181 if( rc==SQLITE_OK ){
266182 int rc2;
266183 sqlite3_bind_int64(pLookup, 1, iDel);
266184 if( SQLITE_ROW==sqlite3_step(pLookup) ){
266185 int *aCol = (int*)sqlite3_malloc64(p->pConfig->nCol * sizeof(int));
266186 if( aCol==0 ){
266187 rc = SQLITE_NOMEM;
266188 }else{
266189 const u8 *aBlob = sqlite3_column_blob(pLookup, 0);
266190 int nBlob = sqlite3_column_bytes(pLookup, 0);
266191 int ii;
266192 if( fts5StorageDecodeSizeArray(aCol, p->pConfig->nCol, aBlob, nBlob) ){
266193 rc = SQLITE_CORRUPT_VTAB;
266194 }else{
266195 for(ii=0; ii<p->pConfig->nCol; ii++){
266196 p->aTotalSize[ii] -= aCol[ii];
266197 }
266198 }
266199 sqlite3_free(aCol);
266200 }
266201 iOrigin = sqlite3_column_int(pLookup, 1);
266202 }
266203 rc2 = sqlite3_reset(pLookup);
266204 if( rc==SQLITE_OK ) rc = rc2;
266205 }
266206
266207 if( rc==SQLITE_OK && iOrigin!=0 ){
266208 rc = sqlite3Fts5IndexContentlessDelete(p->pIndex, iOrigin, iDel);
266209 p->nTotalRow--;
266210 }
266211
266212 return rc;
266213 }
266214
266215 /*
266216 ** Insert a record into the %_docsize table. Specifically, do:
266217 **
266218 ** INSERT OR REPLACE INTO %_docsize(id, sz) VALUES(iRowid, pBuf);
266219 **
266220 ** If there is no %_docsize table (as happens if the columnsize=0 option
266221 ** is specified when the FTS5 table is created), this function is a no-op.
266222 */
266223 static int fts5StorageInsertDocsize(
266224 Fts5Storage *p, /* Storage module to write to */
266225 i64 iRowid, /* id value */
266226 Fts5Buffer *pBuf /* sz value */
266227 ){
266228 int rc = SQLITE_OK;
266229 if( p->pConfig->bColumnsize ){
266230 sqlite3_stmt *pReplace = 0;
266231 rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
266232 if( rc==SQLITE_OK ){
266233 sqlite3_bind_int64(pReplace, 1, iRowid);
266234 if( p->pConfig->bContentlessDelete ){
266235 i64 iOrigin = 0;
266236 rc = sqlite3Fts5IndexGetOrigin(p->pIndex, &iOrigin);
266237 sqlite3_bind_int64(pReplace, 3, iOrigin);
266238 }
266239 }
266240 if( rc==SQLITE_OK ){
266241 sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC);
266242 sqlite3_step(pReplace);
266243 rc = sqlite3_reset(pReplace);
266244 sqlite3_bind_null(pReplace, 2);
266245 }
266246 }
266247 return rc;
266248 }
266249
266250 /*
266251 ** Remove a row from the FTS table.
266252 */
266253 static int sqlite3Fts5StorageDelete(
@@ -266481,23 +266906,10 @@
266906 }else{
266907 sqlite3_finalize(pStmt);
266908 }
266909 }
266910
 
 
 
 
 
 
 
 
 
 
 
 
 
266911 /*
266912 ** Argument aCol points to an array of integers containing one entry for
266913 ** each table column. This function reads the %_docsize record for the
266914 ** specified rowid and populates aCol[] with the results.
266915 **
266916
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.54.0"
150150
#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-08-27 10:58:16 555f31c64d3fcc55df2715a7c8c1cb28503b2c0eb21d950ccdcbf6f577593dd5"
151
+#define SQLITE_SOURCE_ID "2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-08-27T10:58:16.680Z"
154
+#define SQLITE_SCM_DATETIME "2026-10-01T11:21:02.802Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -3521,10 +3521,15 @@
35213521
** authorizer callback is the name of the database ("main", "temp",
35223522
** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
35233523
** is the name of the inner-most trigger or view that is responsible for
35243524
** the access attempt or NULL if this access attempt is directly from
35253525
** top-level SQL code.
3526
+**
3527
+** The case of strings in the 3rd through the 6th argument to the
3528
+** authorization callback is arbitrary. Authorization callbacks
3529
+** implementations should use [sqlite3_stricmp()] or similar when
3530
+** doing comparisons against those values.
35263531
*/
35273532
/******************************************* 3rd ************ 4th ***********/
35283533
#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
35293534
#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
35303535
#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
35313536
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-08-27 10:58:16 555f31c64d3fcc55df2715a7c8c1cb28503b2c0eb21d950ccdcbf6f577593dd5"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-08-27T10:58:16.680Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -3521,10 +3521,15 @@
3521 ** authorizer callback is the name of the database ("main", "temp",
3522 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
3523 ** is the name of the inner-most trigger or view that is responsible for
3524 ** the access attempt or NULL if this access attempt is directly from
3525 ** top-level SQL code.
 
 
 
 
 
3526 */
3527 /******************************************* 3rd ************ 4th ***********/
3528 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
3529 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
3530 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
3531
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-10-01 11:21:02 92709f54d4c58cf174f305b58971a01878af313157a11549b588a25216701f5c"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-10-01T11:21:02.802Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -3521,10 +3521,15 @@
3521 ** authorizer callback is the name of the database ("main", "temp",
3522 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
3523 ** is the name of the inner-most trigger or view that is responsible for
3524 ** the access attempt or NULL if this access attempt is directly from
3525 ** top-level SQL code.
3526 **
3527 ** The case of strings in the 3rd through the 6th argument to the
3528 ** authorization callback is arbitrary. Authorization callbacks
3529 ** implementations should use [sqlite3_stricmp()] or similar when
3530 ** doing comparisons against those values.
3531 */
3532 /******************************************* 3rd ************ 4th ***********/
3533 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
3534 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
3535 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
3536

Keyboard Shortcuts

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