Fossil SCM

Update the built-in SQLite to the latest 3.46.0 alpha that includes the enhanced "PRAGMA optimize" logic. The interface to "PRAGMA optimize" is unchanged, so the minimum SQLite version did not need to be updated.

drh 2024-02-21 11:56 trunk
Commit aa33292ccdfb47b5cad35618d0738502a8391fb9d03e6ff32a5a377f22a7d674
3 files changed +129 -14 +867 -381 +5 -3
+129 -14
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -578,10 +578,13 @@
578578
/* # include "sqlite3.h" */
579579
#endif
580580
#ifndef HAVE_CONSOLE_IO_H
581581
# include "console_io.h"
582582
#endif
583
+#if defined(_MSC_VER)
584
+# pragma warning(disable : 4204)
585
+#endif
583586
584587
#ifndef SQLITE_CIO_NO_TRANSLATE
585588
# if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
586589
# ifndef SHELL_NO_SYSINC
587590
# include <io.h>
@@ -675,10 +678,14 @@
675678
ppst->pf = pf;
676679
ppst->reachesConsole = ( (short)isatty(fileno(pf)) );
677680
return ppst->reachesConsole;
678681
# endif
679682
}
683
+
684
+# ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
685
+# define ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
686
+# endif
680687
681688
# if CIO_WIN_WC_XLATE
682689
/* Define console modes for use with the Windows Console API. */
683690
# define SHELL_CONI_MODE \
684691
(ENABLE_ECHO_INPUT | ENABLE_INSERT_MODE | ENABLE_LINE_INPUT | 0x80 \
@@ -1225,10 +1232,14 @@
12251232
# if CIO_WIN_WC_XLATE
12261233
}
12271234
# endif
12281235
}
12291236
#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */
1237
+
1238
+#if defined(_MSC_VER)
1239
+# pragma warning(default : 4204)
1240
+#endif
12301241
12311242
#undef SHELL_INVALID_FILE_PTR
12321243
12331244
/************************* End ../ext/consio/console_io.c ********************/
12341245
@@ -1248,10 +1259,13 @@
12481259
*
12491260
* Note that the default stream is whatever has been last set via:
12501261
* setOutputStream(FILE *pf)
12511262
* This is normally the stream that CLI normal output goes to.
12521263
* For the stand-alone CLI, it is stdout with no .output redirect.
1264
+ *
1265
+ * The ?putz(z) forms are required for the Fiddle builds for string literal
1266
+ * output, in aid of enforcing format string to argument correspondence.
12531267
*/
12541268
# define sputz(s,z) fPutsUtf8(z,s)
12551269
# define sputf fPrintfUtf8
12561270
# define oputz(z) oPutsUtf8(z)
12571271
# define oputf oPrintfUtf8
@@ -1259,16 +1273,22 @@
12591273
# define eputf ePrintfUtf8
12601274
# define oputb(buf,na) oPutbUtf8(buf,na)
12611275
12621276
#else
12631277
/* For Fiddle, all console handling and emit redirection is omitted. */
1264
-# define sputz(fp,z) fputs(z,fp)
1265
-# define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__)
1266
-# define oputz(z) fputs(z,stdout)
1278
+/* These next 3 macros are for emitting formatted output. When complaints
1279
+ * from the WASM build are issued for non-formatted output, (when a mere
1280
+ * string literal is to be emitted, the ?putz(z) forms should be used.
1281
+ * (This permits compile-time checking of format string / argument mismatch.)
1282
+ */
12671283
# define oputf(fmt, ...) printf(fmt,__VA_ARGS__)
1268
-# define eputz(z) fputs(z,stderr)
12691284
# define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__)
1285
+# define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__)
1286
+/* These next 3 macros are for emitting simple string literals. */
1287
+# define oputz(z) fputs(z,stdout)
1288
+# define eputz(z) fputs(z,stderr)
1289
+# define sputz(fp,z) fputs(z,fp)
12701290
# define oputb(buf,na) fwrite(buf,1,na,stdout)
12711291
#endif
12721292
12731293
/* True if the timer is enabled */
12741294
static int enableTimer = 0;
@@ -5709,20 +5729,24 @@
57095729
/*
57105730
** Return that member of a generate_series(...) sequence whose 0-based
57115731
** index is ix. The 0th member is given by smBase. The sequence members
57125732
** progress per ix increment by smStep.
57135733
*/
5714
-static sqlite3_int64 genSeqMember(sqlite3_int64 smBase,
5715
- sqlite3_int64 smStep,
5716
- sqlite3_uint64 ix){
5717
- if( ix>=(sqlite3_uint64)LLONG_MAX ){
5734
+static sqlite3_int64 genSeqMember(
5735
+ sqlite3_int64 smBase,
5736
+ sqlite3_int64 smStep,
5737
+ sqlite3_uint64 ix
5738
+){
5739
+ static const sqlite3_uint64 mxI64 =
5740
+ ((sqlite3_uint64)0x7fffffff)<<32 | 0xffffffff;
5741
+ if( ix>=mxI64 ){
57185742
/* Get ix into signed i64 range. */
5719
- ix -= (sqlite3_uint64)LLONG_MAX;
5743
+ ix -= mxI64;
57205744
/* With 2's complement ALU, this next can be 1 step, but is split into
57215745
* 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
5722
- smBase += (LLONG_MAX/2) * smStep;
5723
- smBase += (LLONG_MAX - LLONG_MAX/2) * smStep;
5746
+ smBase += (mxI64/2) * smStep;
5747
+ smBase += (mxI64 - mxI64/2) * smStep;
57245748
}
57255749
/* Under UBSAN (or on 1's complement machines), must do this last term
57265750
* in steps to avoid the dreaded (and harmless) signed multiply overlow. */
57275751
if( ix>=2 ){
57285752
sqlite3_int64 ix2 = (sqlite3_int64)ix/2;
@@ -24736,10 +24760,42 @@
2473624760
);
2473724761
}
2473824762
shellFinalize(&rc, pStmt);
2473924763
return rc;
2474024764
}
24765
+
24766
+/*
24767
+** Fault-Simulator state and logic.
24768
+*/
24769
+static struct {
24770
+ int iId; /* ID that triggers a simulated fault. -1 means "any" */
24771
+ int iErr; /* The error code to return on a fault */
24772
+ int iCnt; /* Trigger the fault only if iCnt is already zero */
24773
+ int iInterval; /* Reset iCnt to this value after each fault */
24774
+ int eVerbose; /* When to print output */
24775
+} faultsim_state = {-1, 0, 0, 0, 0};
24776
+
24777
+/*
24778
+** This is the fault-sim callback
24779
+*/
24780
+static int faultsim_callback(int iArg){
24781
+ if( faultsim_state.iId>0 && faultsim_state.iId!=iArg ){
24782
+ return SQLITE_OK;
24783
+ }
24784
+ if( faultsim_state.iCnt>0 ){
24785
+ faultsim_state.iCnt--;
24786
+ if( faultsim_state.eVerbose>=2 ){
24787
+ oputf("FAULT-SIM id=%d no-fault (cnt=%d)\n", iArg, faultsim_state.iCnt);
24788
+ }
24789
+ return SQLITE_OK;
24790
+ }
24791
+ if( faultsim_state.eVerbose>=1 ){
24792
+ oputf("FAULT-SIM id=%d returns %d\n", iArg, faultsim_state.iErr);
24793
+ }
24794
+ faultsim_state.iCnt = faultsim_state.iInterval;
24795
+ return faultsim_state.iErr;
24796
+}
2474124797
2474224798
/*
2474324799
** If an input line begins with "." then invoke this routine to
2474424800
** process that line.
2474524801
**
@@ -25228,11 +25284,12 @@
2522825284
sqlite3_free(zSql);
2522925285
if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
2523025286
zSql = sqlite3_mprintf(
2523125287
"SELECT sql FROM sqlite_schema AS o "
2523225288
"WHERE (%s) AND sql NOT NULL"
25233
- " AND type IN ('index','trigger','view')",
25289
+ " AND type IN ('index','trigger','view') "
25290
+ "ORDER BY type COLLATE NOCASE DESC",
2523425291
zLike
2523525292
);
2523625293
run_table_dump_query(p, zSql);
2523725294
sqlite3_free(zSql);
2523825295
}
@@ -27624,11 +27681,11 @@
2762427681
{"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
2762527682
/*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
2762627683
/*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
2762727684
{"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
2762827685
{"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
27629
- /*{"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"" },*/
27686
+ {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
2763027687
{"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
2763127688
{"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
2763227689
{"internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" },
2763327690
{"json_selfcheck", SQLITE_TESTCTRL_JSON_SELFCHECK ,0,"BOOLEAN" },
2763427691
{"localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" },
@@ -27857,10 +27914,68 @@
2785727914
rc2 = booleanValue(azArg[2]);
2785827915
isOk = 3;
2785927916
}
2786027917
sqlite3_test_control(testctrl, &rc2);
2786127918
break;
27919
+ case SQLITE_TESTCTRL_FAULT_INSTALL: {
27920
+ int kk;
27921
+ int bShowHelp = nArg<=2;
27922
+ isOk = 3;
27923
+ for(kk=2; kk<nArg; kk++){
27924
+ const char *z = azArg[kk];
27925
+ if( z[0]=='-' && z[1]=='-' ) z++;
27926
+ if( cli_strcmp(z,"off")==0 ){
27927
+ sqlite3_test_control(testctrl, 0);
27928
+ }else if( cli_strcmp(z,"on")==0 ){
27929
+ faultsim_state.iCnt = faultsim_state.iInterval;
27930
+ if( faultsim_state.iErr==0 ) faultsim_state.iErr = 1;
27931
+ sqlite3_test_control(testctrl, faultsim_callback);
27932
+ }else if( cli_strcmp(z,"reset")==0 ){
27933
+ faultsim_state.iCnt = faultsim_state.iInterval;
27934
+ }else if( cli_strcmp(z,"status")==0 ){
27935
+ oputf("faultsim.iId: %d\n", faultsim_state.iId);
27936
+ oputf("faultsim.iErr: %d\n", faultsim_state.iErr);
27937
+ oputf("faultsim.iCnt: %d\n", faultsim_state.iCnt);
27938
+ oputf("faultsim.iInterval: %d\n", faultsim_state.iInterval);
27939
+ oputf("faultsim.eVerbose: %d\n", faultsim_state.eVerbose);
27940
+ }else if( cli_strcmp(z,"-v")==0 ){
27941
+ if( faultsim_state.eVerbose<2 ) faultsim_state.eVerbose++;
27942
+ }else if( cli_strcmp(z,"-q")==0 ){
27943
+ if( faultsim_state.eVerbose>0 ) faultsim_state.eVerbose--;
27944
+ }else if( cli_strcmp(z,"-id")==0 && kk+1<nArg ){
27945
+ faultsim_state.iId = atoi(azArg[++kk]);
27946
+ }else if( cli_strcmp(z,"-errcode")==0 && kk+1<nArg ){
27947
+ faultsim_state.iErr = atoi(azArg[++kk]);
27948
+ }else if( cli_strcmp(z,"-interval")==0 && kk+1<nArg ){
27949
+ faultsim_state.iInterval = atoi(azArg[++kk]);
27950
+ }else if( cli_strcmp(z,"-?")==0 || sqlite3_strglob("*help*",z)==0){
27951
+ bShowHelp = 1;
27952
+ }else{
27953
+ eputf("Unrecognized fault_install argument: \"%s\"\n",
27954
+ azArg[kk]);
27955
+ rc = 1;
27956
+ bShowHelp = 1;
27957
+ break;
27958
+ }
27959
+ }
27960
+ if( bShowHelp ){
27961
+ oputz(
27962
+ "Usage: .testctrl fault_install ARGS\n"
27963
+ "Possible arguments:\n"
27964
+ " off Disable faultsim\n"
27965
+ " on Activate faultsim\n"
27966
+ " reset Reset the trigger counter\n"
27967
+ " status Show current status\n"
27968
+ " -v Increase verbosity\n"
27969
+ " -q Decrease verbosity\n"
27970
+ " --errcode N When triggered, return N as error code\n"
27971
+ " --id ID Trigger only for the ID specified\n"
27972
+ " --interval N Trigger only after every N-th call\n"
27973
+ );
27974
+ }
27975
+ break;
27976
+ }
2786227977
}
2786327978
}
2786427979
if( isOk==0 && iCtrl>=0 ){
2786527980
oputf("Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
2786627981
rc = 1;
@@ -28778,11 +28893,11 @@
2877828893
if( showDetail ){
2877928894
eputf("OPTIONS include:\n%s", zOptions);
2878028895
}else{
2878128896
eputz("Use the -help option for additional information\n");
2878228897
}
28783
- exit(1);
28898
+ exit(0);
2878428899
}
2878528900
2878628901
/*
2878728902
** Internal check: Verify that the SQLite is uninitialized. Print a
2878828903
** error message if it is initialized.
2878928904
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -578,10 +578,13 @@
578 /* # include "sqlite3.h" */
579 #endif
580 #ifndef HAVE_CONSOLE_IO_H
581 # include "console_io.h"
582 #endif
 
 
 
583
584 #ifndef SQLITE_CIO_NO_TRANSLATE
585 # if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
586 # ifndef SHELL_NO_SYSINC
587 # include <io.h>
@@ -675,10 +678,14 @@
675 ppst->pf = pf;
676 ppst->reachesConsole = ( (short)isatty(fileno(pf)) );
677 return ppst->reachesConsole;
678 # endif
679 }
 
 
 
 
680
681 # if CIO_WIN_WC_XLATE
682 /* Define console modes for use with the Windows Console API. */
683 # define SHELL_CONI_MODE \
684 (ENABLE_ECHO_INPUT | ENABLE_INSERT_MODE | ENABLE_LINE_INPUT | 0x80 \
@@ -1225,10 +1232,14 @@
1225 # if CIO_WIN_WC_XLATE
1226 }
1227 # endif
1228 }
1229 #endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */
 
 
 
 
1230
1231 #undef SHELL_INVALID_FILE_PTR
1232
1233 /************************* End ../ext/consio/console_io.c ********************/
1234
@@ -1248,10 +1259,13 @@
1248 *
1249 * Note that the default stream is whatever has been last set via:
1250 * setOutputStream(FILE *pf)
1251 * This is normally the stream that CLI normal output goes to.
1252 * For the stand-alone CLI, it is stdout with no .output redirect.
 
 
 
1253 */
1254 # define sputz(s,z) fPutsUtf8(z,s)
1255 # define sputf fPrintfUtf8
1256 # define oputz(z) oPutsUtf8(z)
1257 # define oputf oPrintfUtf8
@@ -1259,16 +1273,22 @@
1259 # define eputf ePrintfUtf8
1260 # define oputb(buf,na) oPutbUtf8(buf,na)
1261
1262 #else
1263 /* For Fiddle, all console handling and emit redirection is omitted. */
1264 # define sputz(fp,z) fputs(z,fp)
1265 # define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__)
1266 # define oputz(z) fputs(z,stdout)
 
 
1267 # define oputf(fmt, ...) printf(fmt,__VA_ARGS__)
1268 # define eputz(z) fputs(z,stderr)
1269 # define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__)
 
 
 
 
 
1270 # define oputb(buf,na) fwrite(buf,1,na,stdout)
1271 #endif
1272
1273 /* True if the timer is enabled */
1274 static int enableTimer = 0;
@@ -5709,20 +5729,24 @@
5709 /*
5710 ** Return that member of a generate_series(...) sequence whose 0-based
5711 ** index is ix. The 0th member is given by smBase. The sequence members
5712 ** progress per ix increment by smStep.
5713 */
5714 static sqlite3_int64 genSeqMember(sqlite3_int64 smBase,
5715 sqlite3_int64 smStep,
5716 sqlite3_uint64 ix){
5717 if( ix>=(sqlite3_uint64)LLONG_MAX ){
 
 
 
 
5718 /* Get ix into signed i64 range. */
5719 ix -= (sqlite3_uint64)LLONG_MAX;
5720 /* With 2's complement ALU, this next can be 1 step, but is split into
5721 * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
5722 smBase += (LLONG_MAX/2) * smStep;
5723 smBase += (LLONG_MAX - LLONG_MAX/2) * smStep;
5724 }
5725 /* Under UBSAN (or on 1's complement machines), must do this last term
5726 * in steps to avoid the dreaded (and harmless) signed multiply overlow. */
5727 if( ix>=2 ){
5728 sqlite3_int64 ix2 = (sqlite3_int64)ix/2;
@@ -24736,10 +24760,42 @@
24736 );
24737 }
24738 shellFinalize(&rc, pStmt);
24739 return rc;
24740 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24741
24742 /*
24743 ** If an input line begins with "." then invoke this routine to
24744 ** process that line.
24745 **
@@ -25228,11 +25284,12 @@
25228 sqlite3_free(zSql);
25229 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
25230 zSql = sqlite3_mprintf(
25231 "SELECT sql FROM sqlite_schema AS o "
25232 "WHERE (%s) AND sql NOT NULL"
25233 " AND type IN ('index','trigger','view')",
 
25234 zLike
25235 );
25236 run_table_dump_query(p, zSql);
25237 sqlite3_free(zSql);
25238 }
@@ -27624,11 +27681,11 @@
27624 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
27625 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
27626 /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
27627 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
27628 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
27629 /*{"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"" },*/
27630 {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
27631 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
27632 {"internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" },
27633 {"json_selfcheck", SQLITE_TESTCTRL_JSON_SELFCHECK ,0,"BOOLEAN" },
27634 {"localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" },
@@ -27857,10 +27914,68 @@
27857 rc2 = booleanValue(azArg[2]);
27858 isOk = 3;
27859 }
27860 sqlite3_test_control(testctrl, &rc2);
27861 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27862 }
27863 }
27864 if( isOk==0 && iCtrl>=0 ){
27865 oputf("Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
27866 rc = 1;
@@ -28778,11 +28893,11 @@
28778 if( showDetail ){
28779 eputf("OPTIONS include:\n%s", zOptions);
28780 }else{
28781 eputz("Use the -help option for additional information\n");
28782 }
28783 exit(1);
28784 }
28785
28786 /*
28787 ** Internal check: Verify that the SQLite is uninitialized. Print a
28788 ** error message if it is initialized.
28789
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -578,10 +578,13 @@
578 /* # include "sqlite3.h" */
579 #endif
580 #ifndef HAVE_CONSOLE_IO_H
581 # include "console_io.h"
582 #endif
583 #if defined(_MSC_VER)
584 # pragma warning(disable : 4204)
585 #endif
586
587 #ifndef SQLITE_CIO_NO_TRANSLATE
588 # if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
589 # ifndef SHELL_NO_SYSINC
590 # include <io.h>
@@ -675,10 +678,14 @@
678 ppst->pf = pf;
679 ppst->reachesConsole = ( (short)isatty(fileno(pf)) );
680 return ppst->reachesConsole;
681 # endif
682 }
683
684 # ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
685 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
686 # endif
687
688 # if CIO_WIN_WC_XLATE
689 /* Define console modes for use with the Windows Console API. */
690 # define SHELL_CONI_MODE \
691 (ENABLE_ECHO_INPUT | ENABLE_INSERT_MODE | ENABLE_LINE_INPUT | 0x80 \
@@ -1225,10 +1232,14 @@
1232 # if CIO_WIN_WC_XLATE
1233 }
1234 # endif
1235 }
1236 #endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */
1237
1238 #if defined(_MSC_VER)
1239 # pragma warning(default : 4204)
1240 #endif
1241
1242 #undef SHELL_INVALID_FILE_PTR
1243
1244 /************************* End ../ext/consio/console_io.c ********************/
1245
@@ -1248,10 +1259,13 @@
1259 *
1260 * Note that the default stream is whatever has been last set via:
1261 * setOutputStream(FILE *pf)
1262 * This is normally the stream that CLI normal output goes to.
1263 * For the stand-alone CLI, it is stdout with no .output redirect.
1264 *
1265 * The ?putz(z) forms are required for the Fiddle builds for string literal
1266 * output, in aid of enforcing format string to argument correspondence.
1267 */
1268 # define sputz(s,z) fPutsUtf8(z,s)
1269 # define sputf fPrintfUtf8
1270 # define oputz(z) oPutsUtf8(z)
1271 # define oputf oPrintfUtf8
@@ -1259,16 +1273,22 @@
1273 # define eputf ePrintfUtf8
1274 # define oputb(buf,na) oPutbUtf8(buf,na)
1275
1276 #else
1277 /* For Fiddle, all console handling and emit redirection is omitted. */
1278 /* These next 3 macros are for emitting formatted output. When complaints
1279 * from the WASM build are issued for non-formatted output, (when a mere
1280 * string literal is to be emitted, the ?putz(z) forms should be used.
1281 * (This permits compile-time checking of format string / argument mismatch.)
1282 */
1283 # define oputf(fmt, ...) printf(fmt,__VA_ARGS__)
 
1284 # define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__)
1285 # define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__)
1286 /* These next 3 macros are for emitting simple string literals. */
1287 # define oputz(z) fputs(z,stdout)
1288 # define eputz(z) fputs(z,stderr)
1289 # define sputz(fp,z) fputs(z,fp)
1290 # define oputb(buf,na) fwrite(buf,1,na,stdout)
1291 #endif
1292
1293 /* True if the timer is enabled */
1294 static int enableTimer = 0;
@@ -5709,20 +5729,24 @@
5729 /*
5730 ** Return that member of a generate_series(...) sequence whose 0-based
5731 ** index is ix. The 0th member is given by smBase. The sequence members
5732 ** progress per ix increment by smStep.
5733 */
5734 static sqlite3_int64 genSeqMember(
5735 sqlite3_int64 smBase,
5736 sqlite3_int64 smStep,
5737 sqlite3_uint64 ix
5738 ){
5739 static const sqlite3_uint64 mxI64 =
5740 ((sqlite3_uint64)0x7fffffff)<<32 | 0xffffffff;
5741 if( ix>=mxI64 ){
5742 /* Get ix into signed i64 range. */
5743 ix -= mxI64;
5744 /* With 2's complement ALU, this next can be 1 step, but is split into
5745 * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
5746 smBase += (mxI64/2) * smStep;
5747 smBase += (mxI64 - mxI64/2) * smStep;
5748 }
5749 /* Under UBSAN (or on 1's complement machines), must do this last term
5750 * in steps to avoid the dreaded (and harmless) signed multiply overlow. */
5751 if( ix>=2 ){
5752 sqlite3_int64 ix2 = (sqlite3_int64)ix/2;
@@ -24736,10 +24760,42 @@
24760 );
24761 }
24762 shellFinalize(&rc, pStmt);
24763 return rc;
24764 }
24765
24766 /*
24767 ** Fault-Simulator state and logic.
24768 */
24769 static struct {
24770 int iId; /* ID that triggers a simulated fault. -1 means "any" */
24771 int iErr; /* The error code to return on a fault */
24772 int iCnt; /* Trigger the fault only if iCnt is already zero */
24773 int iInterval; /* Reset iCnt to this value after each fault */
24774 int eVerbose; /* When to print output */
24775 } faultsim_state = {-1, 0, 0, 0, 0};
24776
24777 /*
24778 ** This is the fault-sim callback
24779 */
24780 static int faultsim_callback(int iArg){
24781 if( faultsim_state.iId>0 && faultsim_state.iId!=iArg ){
24782 return SQLITE_OK;
24783 }
24784 if( faultsim_state.iCnt>0 ){
24785 faultsim_state.iCnt--;
24786 if( faultsim_state.eVerbose>=2 ){
24787 oputf("FAULT-SIM id=%d no-fault (cnt=%d)\n", iArg, faultsim_state.iCnt);
24788 }
24789 return SQLITE_OK;
24790 }
24791 if( faultsim_state.eVerbose>=1 ){
24792 oputf("FAULT-SIM id=%d returns %d\n", iArg, faultsim_state.iErr);
24793 }
24794 faultsim_state.iCnt = faultsim_state.iInterval;
24795 return faultsim_state.iErr;
24796 }
24797
24798 /*
24799 ** If an input line begins with "." then invoke this routine to
24800 ** process that line.
24801 **
@@ -25228,11 +25284,12 @@
25284 sqlite3_free(zSql);
25285 if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){
25286 zSql = sqlite3_mprintf(
25287 "SELECT sql FROM sqlite_schema AS o "
25288 "WHERE (%s) AND sql NOT NULL"
25289 " AND type IN ('index','trigger','view') "
25290 "ORDER BY type COLLATE NOCASE DESC",
25291 zLike
25292 );
25293 run_table_dump_query(p, zSql);
25294 sqlite3_free(zSql);
25295 }
@@ -27624,11 +27681,11 @@
27681 {"assert", SQLITE_TESTCTRL_ASSERT, 1, "BOOLEAN" },
27682 /*{"benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,1, "" },*/
27683 /*{"bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST, 1, "" },*/
27684 {"byteorder", SQLITE_TESTCTRL_BYTEORDER, 0, "" },
27685 {"extra_schema_checks",SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS,0,"BOOLEAN" },
27686 {"fault_install", SQLITE_TESTCTRL_FAULT_INSTALL, 1,"args..." },
27687 {"fk_no_action", SQLITE_TESTCTRL_FK_NO_ACTION, 0, "BOOLEAN" },
27688 {"imposter", SQLITE_TESTCTRL_IMPOSTER,1,"SCHEMA ON/OFF ROOTPAGE"},
27689 {"internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS,0,"" },
27690 {"json_selfcheck", SQLITE_TESTCTRL_JSON_SELFCHECK ,0,"BOOLEAN" },
27691 {"localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,0,"BOOLEAN" },
@@ -27857,10 +27914,68 @@
27914 rc2 = booleanValue(azArg[2]);
27915 isOk = 3;
27916 }
27917 sqlite3_test_control(testctrl, &rc2);
27918 break;
27919 case SQLITE_TESTCTRL_FAULT_INSTALL: {
27920 int kk;
27921 int bShowHelp = nArg<=2;
27922 isOk = 3;
27923 for(kk=2; kk<nArg; kk++){
27924 const char *z = azArg[kk];
27925 if( z[0]=='-' && z[1]=='-' ) z++;
27926 if( cli_strcmp(z,"off")==0 ){
27927 sqlite3_test_control(testctrl, 0);
27928 }else if( cli_strcmp(z,"on")==0 ){
27929 faultsim_state.iCnt = faultsim_state.iInterval;
27930 if( faultsim_state.iErr==0 ) faultsim_state.iErr = 1;
27931 sqlite3_test_control(testctrl, faultsim_callback);
27932 }else if( cli_strcmp(z,"reset")==0 ){
27933 faultsim_state.iCnt = faultsim_state.iInterval;
27934 }else if( cli_strcmp(z,"status")==0 ){
27935 oputf("faultsim.iId: %d\n", faultsim_state.iId);
27936 oputf("faultsim.iErr: %d\n", faultsim_state.iErr);
27937 oputf("faultsim.iCnt: %d\n", faultsim_state.iCnt);
27938 oputf("faultsim.iInterval: %d\n", faultsim_state.iInterval);
27939 oputf("faultsim.eVerbose: %d\n", faultsim_state.eVerbose);
27940 }else if( cli_strcmp(z,"-v")==0 ){
27941 if( faultsim_state.eVerbose<2 ) faultsim_state.eVerbose++;
27942 }else if( cli_strcmp(z,"-q")==0 ){
27943 if( faultsim_state.eVerbose>0 ) faultsim_state.eVerbose--;
27944 }else if( cli_strcmp(z,"-id")==0 && kk+1<nArg ){
27945 faultsim_state.iId = atoi(azArg[++kk]);
27946 }else if( cli_strcmp(z,"-errcode")==0 && kk+1<nArg ){
27947 faultsim_state.iErr = atoi(azArg[++kk]);
27948 }else if( cli_strcmp(z,"-interval")==0 && kk+1<nArg ){
27949 faultsim_state.iInterval = atoi(azArg[++kk]);
27950 }else if( cli_strcmp(z,"-?")==0 || sqlite3_strglob("*help*",z)==0){
27951 bShowHelp = 1;
27952 }else{
27953 eputf("Unrecognized fault_install argument: \"%s\"\n",
27954 azArg[kk]);
27955 rc = 1;
27956 bShowHelp = 1;
27957 break;
27958 }
27959 }
27960 if( bShowHelp ){
27961 oputz(
27962 "Usage: .testctrl fault_install ARGS\n"
27963 "Possible arguments:\n"
27964 " off Disable faultsim\n"
27965 " on Activate faultsim\n"
27966 " reset Reset the trigger counter\n"
27967 " status Show current status\n"
27968 " -v Increase verbosity\n"
27969 " -q Decrease verbosity\n"
27970 " --errcode N When triggered, return N as error code\n"
27971 " --id ID Trigger only for the ID specified\n"
27972 " --interval N Trigger only after every N-th call\n"
27973 );
27974 }
27975 break;
27976 }
27977 }
27978 }
27979 if( isOk==0 && iCtrl>=0 ){
27980 oputf("Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage);
27981 rc = 1;
@@ -28778,11 +28893,11 @@
28893 if( showDetail ){
28894 eputf("OPTIONS include:\n%s", zOptions);
28895 }else{
28896 eputz("Use the -help option for additional information\n");
28897 }
28898 exit(0);
28899 }
28900
28901 /*
28902 ** Internal check: Verify that the SQLite is uninitialized. Print a
28903 ** error message if it is initialized.
28904
+867 -381
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.45.1. By combining all the individual C code files into this
3
+** version 3.46.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -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
-** e876e51a0ed5c5b3126f52e532044363a014.
21
+** 27a2113d78b35e324e9aedda7403c96c56ad.
2222
*/
2323
#define SQLITE_CORE 1
2424
#define SQLITE_AMALGAMATION 1
2525
#ifndef SQLITE_PRIVATE
2626
# define SQLITE_PRIVATE static
@@ -457,13 +457,13 @@
457457
**
458458
** See also: [sqlite3_libversion()],
459459
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460460
** [sqlite_version()] and [sqlite_source_id()].
461461
*/
462
-#define SQLITE_VERSION "3.45.1"
463
-#define SQLITE_VERSION_NUMBER 3045001
464
-#define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
462
+#define SQLITE_VERSION "3.46.0"
463
+#define SQLITE_VERSION_NUMBER 3046000
464
+#define SQLITE_SOURCE_ID "2024-02-20 15:38:36 27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109"
465465
466466
/*
467467
** CAPI3REF: Run-Time Library Version Numbers
468468
** KEYWORDS: sqlite3_version sqlite3_sourceid
469469
**
@@ -731,10 +731,12 @@
731731
** is a valid and open [database connection].
732732
** <li> The application must not close the [database connection] specified by
733733
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
734734
** <li> The application must not modify the SQL statement text passed into
735735
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
736
+** <li> The application must not dereference the arrays or string pointers
737
+** passed as the 3rd and 4th callback parameters after it returns.
736738
** </ul>
737739
*/
738740
SQLITE_API int sqlite3_exec(
739741
sqlite3*, /* An open database */
740742
const char *sql, /* SQL to be evaluated */
@@ -14858,11 +14860,11 @@
1485814860
#ifndef SQLITE_PTRSIZE
1485914861
# if defined(__SIZEOF_POINTER__)
1486014862
# define SQLITE_PTRSIZE __SIZEOF_POINTER__
1486114863
# elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
1486214864
defined(_M_ARM) || defined(__arm__) || defined(__x86) || \
14863
- (defined(__APPLE__) && defined(__POWERPC__)) || \
14865
+ (defined(__APPLE__) && defined(__ppc__)) || \
1486414866
(defined(__TOS_AIX__) && !defined(__64BIT__))
1486514867
# define SQLITE_PTRSIZE 4
1486614868
# else
1486714869
# define SQLITE_PTRSIZE 8
1486814870
# endif
@@ -16569,11 +16571,11 @@
1656916571
#define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
1657016572
#define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
1657116573
#define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
1657216574
#define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
1657316575
#define OP_Last 32 /* jump */
16574
-#define OP_IfSmaller 33 /* jump */
16576
+#define OP_IfSizeBetween 33 /* jump */
1657516577
#define OP_SorterSort 34 /* jump */
1657616578
#define OP_Sort 35 /* jump */
1657716579
#define OP_Rewind 36 /* jump */
1657816580
#define OP_SorterNext 37 /* jump */
1657916581
#define OP_Prev 38 /* jump */
@@ -17492,10 +17494,14 @@
1749217494
struct FuncDefHash {
1749317495
FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */
1749417496
};
1749517497
#define SQLITE_FUNC_HASH(C,L) (((C)+(L))%SQLITE_FUNC_HASH_SZ)
1749617498
17499
+#if defined(SQLITE_USER_AUTHENTICATION)
17500
+# warning "The SQLITE_USER_AUTHENTICATION extension is deprecated. \
17501
+ See ext/userauth/user-auth.txt for details."
17502
+#endif
1749717503
#ifdef SQLITE_USER_AUTHENTICATION
1749817504
/*
1749917505
** Information held in the "sqlite3" database connection object and used
1750017506
** to manage user authentication.
1750117507
*/
@@ -18368,12 +18374,11 @@
1836818374
#define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */
1836918375
#define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */
1837018376
#define TF_HasStored 0x00000040 /* Has one or more STORED columns */
1837118377
#define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */
1837218378
#define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */
18373
-#define TF_StatsUsed 0x00000100 /* Query planner decisions affected by
18374
- ** Index.aiRowLogEst[] values */
18379
+#define TF_MaybeReanalyze 0x00000100 /* Maybe run ANALYZE on this table */
1837518380
#define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */
1837618381
#define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */
1837718382
#define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */
1837818383
#define TF_Shadow 0x00001000 /* True for a shadow table */
1837918384
#define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
@@ -25336,27 +25341,88 @@
2533625341
}else{
2533725342
sqlite3_result_text(context, &zBuf[1], 10, SQLITE_TRANSIENT);
2533825343
}
2533925344
}
2534025345
}
25346
+
25347
+/*
25348
+** Compute the number of days after the most recent January 1.
25349
+**
25350
+** In other words, compute the zero-based day number for the
25351
+** current year:
25352
+**
25353
+** Jan01 = 0, Jan02 = 1, ..., Jan31 = 30, Feb01 = 31, ...
25354
+** Dec31 = 364 or 365.
25355
+*/
25356
+static int daysAfterJan01(DateTime *pDate){
25357
+ DateTime jan01 = *pDate;
25358
+ assert( jan01.validYMD );
25359
+ assert( jan01.validHMS );
25360
+ assert( pDate->validJD );
25361
+ jan01.validJD = 0;
25362
+ jan01.M = 1;
25363
+ jan01.D = 1;
25364
+ computeJD(&jan01);
25365
+ return (int)((pDate->iJD-jan01.iJD+43200000)/86400000);
25366
+}
25367
+
25368
+/*
25369
+** Return the number of days after the most recent Monday.
25370
+**
25371
+** In other words, return the day of the week according
25372
+** to this code:
25373
+**
25374
+** 0=Monday, 1=Tuesday, 2=Wednesday, ..., 6=Sunday.
25375
+*/
25376
+static int daysAfterMonday(DateTime *pDate){
25377
+ assert( pDate->validJD );
25378
+ return (int)((pDate->iJD+43200000)/86400000) % 7;
25379
+}
25380
+
25381
+/*
25382
+** Return the number of days after the most recent Sunday.
25383
+**
25384
+** In other words, return the day of the week according
25385
+** to this code:
25386
+**
25387
+** 0=Sunday, 1=Monday, 2=Tues, ..., 6=Saturday
25388
+*/
25389
+static int daysAfterSunday(DateTime *pDate){
25390
+ assert( pDate->validJD );
25391
+ return (int)((pDate->iJD+129600000)/86400000) % 7;
25392
+}
2534125393
2534225394
/*
2534325395
** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
2534425396
**
2534525397
** Return a string described by FORMAT. Conversions as follows:
2534625398
**
25347
-** %d day of month
25399
+** %d day of month 01-31
25400
+** %e day of month 1-31
2534825401
** %f ** fractional seconds SS.SSS
25402
+** %F ISO date. YYYY-MM-DD
25403
+** %G ISO year corresponding to %V 0000-9999.
25404
+** %g 2-digit ISO year corresponding to %V 00-99
2534925405
** %H hour 00-24
25350
-** %j day of year 000-366
25406
+** %k hour 0-24 (leading zero converted to space)
25407
+** %I hour 01-12
25408
+** %j day of year 001-366
2535125409
** %J ** julian day number
25410
+** %l hour 1-12 (leading zero converted to space)
2535225411
** %m month 01-12
2535325412
** %M minute 00-59
25413
+** %p "am" or "pm"
25414
+** %P "AM" or "PM"
25415
+** %R time as HH:MM
2535425416
** %s seconds since 1970-01-01
2535525417
** %S seconds 00-59
25356
-** %w day of week 0-6 Sunday==0
25357
-** %W week of year 00-53
25418
+** %T time as HH:MM:SS
25419
+** %u day of week 1-7 Monday==1, Sunday==7
25420
+** %w day of week 0-6 Sunday==0, Monday==1
25421
+** %U week of year 00-53 (First Sunday is start of week 01)
25422
+** %V week of year 01-53 (First week containing Thursday is week 01)
25423
+** %W week of year 00-53 (First Monday is start of week 01)
2535825424
** %Y year 0000-9999
2535925425
** %% %
2536025426
*/
2536125427
static void strftimeFunc(
2536225428
sqlite3_context *context,
@@ -25389,19 +25455,34 @@
2538925455
case 'd': /* Fall thru */
2539025456
case 'e': {
2539125457
sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D);
2539225458
break;
2539325459
}
25394
- case 'f': {
25460
+ case 'f': { /* Fractional seconds. (Non-standard) */
2539525461
double s = x.s;
2539625462
if( s>59.999 ) s = 59.999;
2539725463
sqlite3_str_appendf(&sRes, "%06.3f", s);
2539825464
break;
2539925465
}
2540025466
case 'F': {
2540125467
sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
2540225468
break;
25469
+ }
25470
+ case 'G': /* Fall thru */
25471
+ case 'g': {
25472
+ DateTime y = x;
25473
+ assert( y.validJD );
25474
+ /* Move y so that it is the Thursday in the same week as x */
25475
+ y.iJD += (3 - daysAfterMonday(&x))*86400000;
25476
+ y.validYMD = 0;
25477
+ computeYMD(&y);
25478
+ if( cf=='g' ){
25479
+ sqlite3_str_appendf(&sRes, "%02d", y.Y%100);
25480
+ }else{
25481
+ sqlite3_str_appendf(&sRes, "%04d", y.Y);
25482
+ }
25483
+ break;
2540325484
}
2540425485
case 'H':
2540525486
case 'k': {
2540625487
sqlite3_str_appendf(&sRes, cf=='H' ? "%02d" : "%2d", x.h);
2540725488
break;
@@ -25412,29 +25493,15 @@
2541225493
if( h>12 ) h -= 12;
2541325494
if( h==0 ) h = 12;
2541425495
sqlite3_str_appendf(&sRes, cf=='I' ? "%02d" : "%2d", h);
2541525496
break;
2541625497
}
25417
- case 'W': /* Fall thru */
25418
- case 'j': {
25419
- int nDay; /* Number of days since 1st day of year */
25420
- DateTime y = x;
25421
- y.validJD = 0;
25422
- y.M = 1;
25423
- y.D = 1;
25424
- computeJD(&y);
25425
- nDay = (int)((x.iJD-y.iJD+43200000)/86400000);
25426
- if( cf=='W' ){
25427
- int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
25428
- wd = (int)(((x.iJD+43200000)/86400000)%7);
25429
- sqlite3_str_appendf(&sRes,"%02d",(nDay+7-wd)/7);
25430
- }else{
25431
- sqlite3_str_appendf(&sRes,"%03d",nDay+1);
25432
- }
25498
+ case 'j': { /* Day of year. Jan01==1, Jan02==2, and so forth */
25499
+ sqlite3_str_appendf(&sRes,"%03d",daysAfterJan01(&x)+1);
2543325500
break;
2543425501
}
25435
- case 'J': {
25502
+ case 'J': { /* Julian day number. (Non-standard) */
2543625503
sqlite3_str_appendf(&sRes,"%.16g",x.iJD/86400000.0);
2543725504
break;
2543825505
}
2543925506
case 'm': {
2544025507
sqlite3_str_appendf(&sRes,"%02d",x.M);
@@ -25473,16 +25540,36 @@
2547325540
}
2547425541
case 'T': {
2547525542
sqlite3_str_appendf(&sRes,"%02d:%02d:%02d", x.h, x.m, (int)x.s);
2547625543
break;
2547725544
}
25478
- case 'u': /* Fall thru */
25479
- case 'w': {
25480
- char c = (char)(((x.iJD+129600000)/86400000) % 7) + '0';
25545
+ case 'u': /* Day of week. 1 to 7. Monday==1, Sunday==7 */
25546
+ case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */
25547
+ char c = (char)daysAfterSunday(&x) + '0';
2548125548
if( c=='0' && cf=='u' ) c = '7';
2548225549
sqlite3_str_appendchar(&sRes, 1, c);
2548325550
break;
25551
+ }
25552
+ case 'U': { /* Week num. 00-53. First Sun of the year is week 01 */
25553
+ sqlite3_str_appendf(&sRes,"%02d",
25554
+ (daysAfterJan01(&x)-daysAfterSunday(&x)+7)/7);
25555
+ break;
25556
+ }
25557
+ case 'V': { /* Week num. 01-53. First week with a Thur is week 01 */
25558
+ DateTime y = x;
25559
+ /* Adjust y so that is the Thursday in the same week as x */
25560
+ assert( y.validJD );
25561
+ y.iJD += (3 - daysAfterMonday(&x))*86400000;
25562
+ y.validYMD = 0;
25563
+ computeYMD(&y);
25564
+ sqlite3_str_appendf(&sRes,"%02d", daysAfterJan01(&y)/7+1);
25565
+ break;
25566
+ }
25567
+ case 'W': { /* Week num. 00-53. First Mon of the year is week 01 */
25568
+ sqlite3_str_appendf(&sRes,"%02d",
25569
+ (daysAfterJan01(&x)-daysAfterMonday(&x)+7)/7);
25570
+ break;
2548425571
}
2548525572
case 'Y': {
2548625573
sqlite3_str_appendf(&sRes,"%04d",x.Y);
2548725574
break;
2548825575
}
@@ -30127,10 +30214,28 @@
3012730214
sqlite3_mutex_leave(mem0.mutex);
3012830215
sqlite3_release_memory(nByte);
3012930216
sqlite3_mutex_enter(mem0.mutex);
3013030217
}
3013130218
30219
+#ifdef SQLITE_DEBUG
30220
+/*
30221
+** This routine is called whenever an out-of-memory condition is seen,
30222
+** It's only purpose to to serve as a breakpoint for gdb or similar
30223
+** code debuggers when working on out-of-memory conditions, for example
30224
+** caused by PRAGMA hard_heap_limit=N.
30225
+*/
30226
+static SQLITE_NOINLINE void test_oom_breakpoint(void){
30227
+ static u64 nOomFault = 0;
30228
+ nOomFault++;
30229
+ /* The assert() is never reached in a human lifetime. It is here mostly
30230
+ ** to prevent code optimizers from optimizing out this function. */
30231
+ assert( (nOomFault>>32) < 0xffffffff );
30232
+}
30233
+#else
30234
+# define test_oom_breakpoint(X) /* No-op for production builds */
30235
+#endif
30236
+
3013230237
/*
3013330238
** Do a memory allocation with statistics and alarms. Assume the
3013430239
** lock is already held.
3013530240
*/
3013630241
static void mallocWithAlarm(int n, void **pp){
@@ -30153,10 +30258,11 @@
3015330258
AtomicStore(&mem0.nearlyFull, 1);
3015430259
sqlite3MallocAlarm(nFull);
3015530260
if( mem0.hardLimit ){
3015630261
nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
3015730262
if( nUsed >= mem0.hardLimit - nFull ){
30263
+ test_oom_breakpoint();
3015830264
*pp = 0;
3015930265
return;
3016030266
}
3016130267
}
3016230268
}else{
@@ -30441,10 +30547,11 @@
3044130547
if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >=
3044230548
mem0.alarmThreshold-nDiff ){
3044330549
sqlite3MallocAlarm(nDiff);
3044430550
if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){
3044530551
sqlite3_mutex_leave(mem0.mutex);
30552
+ test_oom_breakpoint();
3044630553
return 0;
3044730554
}
3044830555
}
3044930556
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
3045030557
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
@@ -31307,10 +31414,11 @@
3130731414
}
3130831415
#endif
3130931416
if( xtype==etFLOAT ){
3131031417
iRound = -precision;
3131131418
}else if( xtype==etGENERIC ){
31419
+ if( precision==0 ) precision = 1;
3131231420
iRound = precision;
3131331421
}else{
3131431422
iRound = precision+1;
3131531423
}
3131631424
sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 26 : 16);
@@ -31342,17 +31450,18 @@
3134231450
}else{
3134331451
prefix = flag_prefix;
3134431452
}
3134531453
3134631454
exp = s.iDP-1;
31347
- if( xtype==etGENERIC && precision>0 ) precision--;
3134831455
3134931456
/*
3135031457
** If the field type is etGENERIC, then convert to either etEXP
3135131458
** or etFLOAT, as appropriate.
3135231459
*/
3135331460
if( xtype==etGENERIC ){
31461
+ assert( precision>0 );
31462
+ precision--;
3135431463
flag_rtz = !flag_alternateform;
3135531464
if( exp<-4 || exp>precision ){
3135631465
xtype = etEXP;
3135731466
}else{
3135831467
precision = precision - exp;
@@ -35639,11 +35748,11 @@
3563935748
assert( i>=0 && i<sizeof(p->zBuf)-1 );
3564035749
p->n = sizeof(p->zBuf) - 1 - i;
3564135750
assert( p->n>0 );
3564235751
assert( p->n<sizeof(p->zBuf) );
3564335752
p->iDP = p->n + exp;
35644
- if( iRound<0 ){
35753
+ if( iRound<=0 ){
3564535754
iRound = p->iDP - iRound;
3564635755
if( iRound==0 && p->zBuf[i+1]>='5' ){
3564735756
iRound = 1;
3564835757
p->zBuf[i--] = '0';
3564935758
p->n++;
@@ -36817,11 +36926,11 @@
3681736926
/* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
3681836927
/* 29 */ "Found" OpHelp("key=r[P3@P4]"),
3681936928
/* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
3682036929
/* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
3682136930
/* 32 */ "Last" OpHelp(""),
36822
- /* 33 */ "IfSmaller" OpHelp(""),
36931
+ /* 33 */ "IfSizeBetween" OpHelp(""),
3682336932
/* 34 */ "SorterSort" OpHelp(""),
3682436933
/* 35 */ "Sort" OpHelp(""),
3682536934
/* 36 */ "Rewind" OpHelp(""),
3682636935
/* 37 */ "SorterNext" OpHelp(""),
3682736936
/* 38 */ "Prev" OpHelp(""),
@@ -39260,12 +39369,16 @@
3926039369
**
3926139370
** If the code incorrectly assumes that it is the POSIX version that is
3926239371
** available, the error message will often be an empty string. Not a
3926339372
** huge problem. Incorrectly concluding that the GNU version is available
3926439373
** could lead to a segfault though.
39374
+ **
39375
+ ** Forum post 3f13857fa4062301 reports that the Android SDK may use
39376
+ ** int-type return, depending on its version.
3926539377
*/
39266
-#if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
39378
+#if (defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)) \
39379
+ && !defined(ANDROID) && !defined(__ANDROID__)
3926739380
zErr =
3926839381
# endif
3926939382
strerror_r(iErrno, aErr, sizeof(aErr)-1);
3927039383
3927139384
#elif SQLITE_THREADSAFE
@@ -53260,10 +53373,18 @@
5326053373
rc = sqlite3_step(pStmt);
5326153374
if( rc!=SQLITE_ROW ){
5326253375
pOut = 0;
5326353376
}else{
5326453377
sz = sqlite3_column_int64(pStmt, 0)*szPage;
53378
+ if( sz==0 ){
53379
+ sqlite3_reset(pStmt);
53380
+ sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
53381
+ rc = sqlite3_step(pStmt);
53382
+ if( rc==SQLITE_ROW ){
53383
+ sz = sqlite3_column_int64(pStmt, 0)*szPage;
53384
+ }
53385
+ }
5326553386
if( piSize ) *piSize = sz;
5326653387
if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
5326753388
pOut = 0;
5326853389
}else{
5326953390
pOut = sqlite3_malloc64( sz );
@@ -70281,12 +70402,51 @@
7028170402
# define SQLITE_CORRUPT_PAGE(pMemPage) corruptPageError(__LINE__, pMemPage)
7028270403
#else
7028370404
# define SQLITE_CORRUPT_PAGE(pMemPage) SQLITE_CORRUPT_PGNO(pMemPage->pgno)
7028470405
#endif
7028570406
70407
+/* Default value for SHARED_LOCK_TRACE macro if shared-cache is disabled
70408
+** or if the lock tracking is disabled. This is always the value for
70409
+** release builds.
70410
+*/
70411
+#define SHARED_LOCK_TRACE(X,MSG,TAB,TYPE) /*no-op*/
70412
+
7028670413
#ifndef SQLITE_OMIT_SHARED_CACHE
7028770414
70415
+#if 0
70416
+/* ^---- Change to 1 and recompile to enable shared-lock tracing
70417
+** for debugging purposes.
70418
+**
70419
+** Print all shared-cache locks on a BtShared. Debugging use only.
70420
+*/
70421
+static void sharedLockTrace(
70422
+ BtShared *pBt,
70423
+ const char *zMsg,
70424
+ int iRoot,
70425
+ int eLockType
70426
+){
70427
+ BtLock *pLock;
70428
+ if( iRoot>0 ){
70429
+ printf("%s-%p %u%s:", zMsg, pBt, iRoot, eLockType==READ_LOCK?"R":"W");
70430
+ }else{
70431
+ printf("%s-%p:", zMsg, pBt);
70432
+ }
70433
+ for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
70434
+ printf(" %p/%u%s", pLock->pBtree, pLock->iTable,
70435
+ pLock->eLock==READ_LOCK ? "R" : "W");
70436
+ while( pLock->pNext && pLock->pBtree==pLock->pNext->pBtree ){
70437
+ pLock = pLock->pNext;
70438
+ printf(",%u%s", pLock->iTable, pLock->eLock==READ_LOCK ? "R" : "W");
70439
+ }
70440
+ }
70441
+ printf("\n");
70442
+ fflush(stdout);
70443
+}
70444
+#undef SHARED_LOCK_TRACE
70445
+#define SHARED_LOCK_TRACE(X,MSG,TAB,TYPE) sharedLockTrace(X,MSG,TAB,TYPE)
70446
+#endif /* Shared-lock tracing */
70447
+
7028870448
#ifdef SQLITE_DEBUG
7028970449
/*
7029070450
**** This function is only used as part of an assert() statement. ***
7029170451
**
7029270452
** Check to see if pBtree holds the required locks to read or write to the
@@ -70358,10 +70518,12 @@
7035870518
}
7035970519
}
7036070520
}else{
7036170521
iTab = iRoot;
7036270522
}
70523
+
70524
+ SHARED_LOCK_TRACE(pBtree->pBt,"hasLock",iRoot,eLockType);
7036370525
7036470526
/* Search for the required lock. Either a write-lock on root-page iTab, a
7036570527
** write-lock on the schema table, or (if the client is reading) a
7036670528
** read-lock on iTab will suffice. Return 1 if any of these are found. */
7036770529
for(pLock=pBtree->pBt->pLock; pLock; pLock=pLock->pNext){
@@ -70492,10 +70654,12 @@
7049270654
static int setSharedCacheTableLock(Btree *p, Pgno iTable, u8 eLock){
7049370655
BtShared *pBt = p->pBt;
7049470656
BtLock *pLock = 0;
7049570657
BtLock *pIter;
7049670658
70659
+ SHARED_LOCK_TRACE(pBt,"setLock", iTable, eLock);
70660
+
7049770661
assert( sqlite3BtreeHoldsMutex(p) );
7049870662
assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
7049970663
assert( p->db!=0 );
7050070664
7050170665
/* A connection with the read-uncommitted flag set will never try to
@@ -70559,10 +70723,12 @@
7055970723
7056070724
assert( sqlite3BtreeHoldsMutex(p) );
7056170725
assert( p->sharable || 0==*ppIter );
7056270726
assert( p->inTrans>0 );
7056370727
70728
+ SHARED_LOCK_TRACE(pBt, "clearAllLocks", 0, 0);
70729
+
7056470730
while( *ppIter ){
7056570731
BtLock *pLock = *ppIter;
7056670732
assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
7056770733
assert( pLock->pBtree->inTrans>=pLock->eLock );
7056870734
if( pLock->pBtree==p ){
@@ -70597,10 +70763,13 @@
7059770763
/*
7059870764
** This function changes all write-locks held by Btree p into read-locks.
7059970765
*/
7060070766
static void downgradeAllSharedCacheTableLocks(Btree *p){
7060170767
BtShared *pBt = p->pBt;
70768
+
70769
+ SHARED_LOCK_TRACE(pBt, "downgradeLocks", 0, 0);
70770
+
7060270771
if( pBt->pWriter==p ){
7060370772
BtLock *pLock;
7060470773
pBt->pWriter = 0;
7060570774
pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
7060670775
for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
@@ -75210,13 +75379,16 @@
7521075379
if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
7521175380
int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
7521275381
if( pCur->aOverflow==0
7521375382
|| nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow)
7521475383
){
75215
- Pgno *aNew = (Pgno*)sqlite3Realloc(
75216
- pCur->aOverflow, nOvfl*2*sizeof(Pgno)
75217
- );
75384
+ Pgno *aNew;
75385
+ if( sqlite3FaultSim(413) ){
75386
+ aNew = 0;
75387
+ }else{
75388
+ aNew = (Pgno*)sqlite3Realloc(pCur->aOverflow, nOvfl*2*sizeof(Pgno));
75389
+ }
7521875390
if( aNew==0 ){
7521975391
return SQLITE_NOMEM_BKPT;
7522075392
}else{
7522175393
pCur->aOverflow = aNew;
7522275394
}
@@ -76261,14 +76433,14 @@
7626176433
u8 i;
7626276434
7626376435
assert( cursorOwnsBtShared(pCur) );
7626476436
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
7626576437
76266
- /* Currently this interface is only called by the OP_IfSmaller
76267
- ** opcode, and it that case the cursor will always be valid and
76268
- ** will always point to a leaf node. */
76269
- if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1;
76438
+ /* Currently this interface is only called by the OP_IfSizeBetween
76439
+ ** opcode and the OP_Count opcode with P3=1. In either case,
76440
+ ** the cursor will always be valid unless the btree is empty. */
76441
+ if( pCur->eState!=CURSOR_VALID ) return 0;
7627076442
if( NEVER(pCur->pPage->leaf==0) ) return -1;
7627176443
7627276444
n = pCur->pPage->nCell;
7627376445
for(i=0; i<pCur->iPage; i++){
7627476446
n *= pCur->apPage[i]->nCell;
@@ -78392,11 +78564,11 @@
7839278564
7839378565
/* Verify that all sibling pages are of the same "type" (table-leaf,
7839478566
** table-interior, index-leaf, or index-interior).
7839578567
*/
7839678568
if( pOld->aData[0]!=apOld[0]->aData[0] ){
78397
- rc = SQLITE_CORRUPT_BKPT;
78569
+ rc = SQLITE_CORRUPT_PAGE(pOld);
7839878570
goto balance_cleanup;
7839978571
}
7840078572
7840178573
/* Load b.apCell[] with pointers to all cells in pOld. If pOld
7840278574
** contains overflow cells, include them in the b.apCell[] array
@@ -78416,11 +78588,11 @@
7841678588
** first.
7841778589
*/
7841878590
memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow));
7841978591
if( pOld->nOverflow>0 ){
7842078592
if( NEVER(limit<pOld->aiOvfl[0]) ){
78421
- rc = SQLITE_CORRUPT_BKPT;
78593
+ rc = SQLITE_CORRUPT_PAGE(pOld);
7842278594
goto balance_cleanup;
7842378595
}
7842478596
limit = pOld->aiOvfl[0];
7842578597
for(j=0; j<limit; j++){
7842678598
b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
@@ -79059,11 +79231,11 @@
7905979231
for(pOther=pCur->pBt->pCursor; pOther; pOther=pOther->pNext){
7906079232
if( pOther!=pCur
7906179233
&& pOther->eState==CURSOR_VALID
7906279234
&& pOther->pPage==pCur->pPage
7906379235
){
79064
- return SQLITE_CORRUPT_BKPT;
79236
+ return SQLITE_CORRUPT_PAGE(pCur->pPage);
7906579237
}
7906679238
}
7906779239
return SQLITE_OK;
7906879240
}
7906979241
@@ -79119,11 +79291,11 @@
7911979291
}
7912079292
}else if( sqlite3PagerPageRefcount(pPage->pDbPage)>1 ){
7912179293
/* The page being written is not a root page, and there is currently
7912279294
** more than one reference to it. This only happens if the page is one
7912379295
** of its own ancestor pages. Corruption. */
79124
- rc = SQLITE_CORRUPT_BKPT;
79296
+ rc = SQLITE_CORRUPT_PAGE(pPage);
7912579297
}else{
7912679298
MemPage * const pParent = pCur->apPage[iPage-1];
7912779299
int const iIdx = pCur->aiIdx[iPage-1];
7912879300
7912979301
rc = sqlite3PagerWrite(pParent->pDbPage);
@@ -79283,11 +79455,11 @@
7928379455
ovflPageSize = pBt->usableSize - 4;
7928479456
do{
7928579457
rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
7928679458
if( rc ) return rc;
7928779459
if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){
79288
- rc = SQLITE_CORRUPT_BKPT;
79460
+ rc = SQLITE_CORRUPT_PAGE(pPage);
7928979461
}else{
7929079462
if( iOffset+ovflPageSize<(u32)nTotal ){
7929179463
ovflPgno = get4byte(pPage->aData);
7929279464
}else{
7929379465
ovflPageSize = nTotal - iOffset;
@@ -79311,11 +79483,11 @@
7931179483
MemPage *pPage = pCur->pPage; /* Page being written */
7931279484
7931379485
if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
7931479486
|| pCur->info.pPayload < pPage->aData + pPage->cellOffset
7931579487
){
79316
- return SQLITE_CORRUPT_BKPT;
79488
+ return SQLITE_CORRUPT_PAGE(pPage);
7931779489
}
7931879490
if( pCur->info.nLocal==nTotal ){
7931979491
/* The entire cell is local */
7932079492
return btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
7932179493
0, pCur->info.nLocal);
@@ -79392,11 +79564,11 @@
7939279564
/* This can only happen if the schema is corrupt such that there is more
7939379565
** than one table or index with the same root page as used by the cursor.
7939479566
** Which can only happen if the SQLITE_NoSchemaError flag was set when
7939579567
** the schema was loaded. This cannot be asserted though, as a user might
7939679568
** set the flag, load the schema, and then unset the flag. */
79397
- return SQLITE_CORRUPT_BKPT;
79569
+ return SQLITE_CORRUPT_PGNO(pCur->pgnoRoot);
7939879570
}
7939979571
}
7940079572
7940179573
/* Ensure that the cursor is not in the CURSOR_FAULT state and that it
7940279574
** points to a valid cell.
@@ -79515,11 +79687,11 @@
7951579687
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
7951679688
assert( pPage->leaf || !pPage->intKey );
7951779689
if( pPage->nFree<0 ){
7951879690
if( NEVER(pCur->eState>CURSOR_INVALID) ){
7951979691
/* ^^^^^--- due to the moveToRoot() call above */
79520
- rc = SQLITE_CORRUPT_BKPT;
79692
+ rc = SQLITE_CORRUPT_PAGE(pPage);
7952179693
}else{
7952279694
rc = btreeComputeFreeSpace(pPage);
7952379695
}
7952479696
if( rc ) return rc;
7952579697
}
@@ -79554,11 +79726,11 @@
7955479726
pCur->info.nSize = 0;
7955579727
if( loc==0 ){
7955679728
CellInfo info;
7955779729
assert( idx>=0 );
7955879730
if( idx>=pPage->nCell ){
79559
- return SQLITE_CORRUPT_BKPT;
79731
+ return SQLITE_CORRUPT_PAGE(pPage);
7956079732
}
7956179733
rc = sqlite3PagerWrite(pPage->pDbPage);
7956279734
if( rc ){
7956379735
goto end_insert;
7956479736
}
@@ -79581,14 +79753,14 @@
7958179753
** This optimization cannot be used on an autovacuum database if the
7958279754
** new entry uses overflow pages, as the insertCell() call below is
7958379755
** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry. */
7958479756
assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */
7958579757
if( oldCell < pPage->aData+pPage->hdrOffset+10 ){
79586
- return SQLITE_CORRUPT_BKPT;
79758
+ return SQLITE_CORRUPT_PAGE(pPage);
7958779759
}
7958879760
if( oldCell+szNew > pPage->aDataEnd ){
79589
- return SQLITE_CORRUPT_BKPT;
79761
+ return SQLITE_CORRUPT_PAGE(pPage);
7959079762
}
7959179763
memcpy(oldCell, newCell, szNew);
7959279764
return SQLITE_OK;
7959379765
}
7959479766
dropCell(pPage, idx, info.nSize, &rc);
@@ -79686,11 +79858,11 @@
7968679858
}
7968779859
if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
7968879860
nIn = pSrc->info.nLocal;
7968979861
aIn = pSrc->info.pPayload;
7969079862
if( aIn+nIn>pSrc->pPage->aDataEnd ){
79691
- return SQLITE_CORRUPT_BKPT;
79863
+ return SQLITE_CORRUPT_PAGE(pSrc->pPage);
7969279864
}
7969379865
nRem = pSrc->info.nPayload;
7969479866
if( nIn==nRem && nIn<pDest->pPage->maxLocal ){
7969579867
memcpy(aOut, aIn, nIn);
7969679868
pBt->nPreformatSize = nIn + (aOut - pBt->pTmpSpace);
@@ -79711,11 +79883,11 @@
7971179883
pBt->nPreformatSize += 4;
7971279884
}
7971379885
7971479886
if( nRem>nIn ){
7971579887
if( aIn+nIn+4>pSrc->pPage->aDataEnd ){
79716
- return SQLITE_CORRUPT_BKPT;
79888
+ return SQLITE_CORRUPT_PAGE(pSrc->pPage);
7971779889
}
7971879890
ovflIn = get4byte(&pSrc->info.pPayload[nIn]);
7971979891
}
7972079892
7972179893
do {
@@ -79807,27 +79979,27 @@
7980779979
if( pCur->eState>=CURSOR_REQUIRESEEK ){
7980879980
rc = btreeRestoreCursorPosition(pCur);
7980979981
assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
7981079982
if( rc || pCur->eState!=CURSOR_VALID ) return rc;
7981179983
}else{
79812
- return SQLITE_CORRUPT_BKPT;
79984
+ return SQLITE_CORRUPT_PGNO(pCur->pgnoRoot);
7981379985
}
7981479986
}
7981579987
assert( pCur->eState==CURSOR_VALID );
7981679988
7981779989
iCellDepth = pCur->iPage;
7981879990
iCellIdx = pCur->ix;
7981979991
pPage = pCur->pPage;
7982079992
if( pPage->nCell<=iCellIdx ){
79821
- return SQLITE_CORRUPT_BKPT;
79993
+ return SQLITE_CORRUPT_PAGE(pPage);
7982279994
}
7982379995
pCell = findCell(pPage, iCellIdx);
7982479996
if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
79825
- return SQLITE_CORRUPT_BKPT;
79997
+ return SQLITE_CORRUPT_PAGE(pPage);
7982679998
}
7982779999
if( pCell<&pPage->aCellIdx[pPage->nCell] ){
79828
- return SQLITE_CORRUPT_BKPT;
80000
+ return SQLITE_CORRUPT_PAGE(pPage);
7982980001
}
7983080002
7983180003
/* If the BTREE_SAVEPOSITION bit is on, then the cursor position must
7983280004
** be preserved following this delete operation. If the current delete
7983380005
** will cause a b-tree rebalance, then this is done by saving the cursor
@@ -79914,11 +80086,11 @@
7991480086
n = pCur->apPage[iCellDepth+1]->pgno;
7991580087
}else{
7991680088
n = pCur->pPage->pgno;
7991780089
}
7991880090
pCell = findCell(pLeaf, pLeaf->nCell-1);
79919
- if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
80091
+ if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_PAGE(pLeaf);
7992080092
nCell = pLeaf->xCellSize(pLeaf, pCell);
7992180093
assert( MX_CELL_SIZE(pBt) >= nCell );
7992280094
pTmp = pBt->pTmpSpace;
7992380095
assert( pTmp!=0 );
7992480096
rc = sqlite3PagerWrite(pLeaf->pDbPage);
@@ -80030,11 +80202,11 @@
8003080202
** root page of the new table should go. meta[3] is the largest root-page
8003180203
** created so far, so the new root-page is (meta[3]+1).
8003280204
*/
8003380205
sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
8003480206
if( pgnoRoot>btreePagecount(pBt) ){
80035
- return SQLITE_CORRUPT_BKPT;
80207
+ return SQLITE_CORRUPT_PGNO(pgnoRoot);
8003680208
}
8003780209
pgnoRoot++;
8003880210
8003980211
/* The new root-page may not be allocated on a pointer-map page, or the
8004080212
** PENDING_BYTE page.
@@ -80078,11 +80250,11 @@
8007880250
if( rc!=SQLITE_OK ){
8007980251
return rc;
8008080252
}
8008180253
rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
8008280254
if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
80083
- rc = SQLITE_CORRUPT_BKPT;
80255
+ rc = SQLITE_CORRUPT_PGNO(pgnoRoot);
8008480256
}
8008580257
if( rc!=SQLITE_OK ){
8008680258
releasePage(pRoot);
8008780259
return rc;
8008880260
}
@@ -80168,18 +80340,18 @@
8016880340
int hdr;
8016980341
CellInfo info;
8017080342
8017180343
assert( sqlite3_mutex_held(pBt->mutex) );
8017280344
if( pgno>btreePagecount(pBt) ){
80173
- return SQLITE_CORRUPT_BKPT;
80345
+ return SQLITE_CORRUPT_PGNO(pgno);
8017480346
}
8017580347
rc = getAndInitPage(pBt, pgno, &pPage, 0);
8017680348
if( rc ) return rc;
8017780349
if( (pBt->openFlags & BTREE_SINGLE)==0
8017880350
&& sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
8017980351
){
80180
- rc = SQLITE_CORRUPT_BKPT;
80352
+ rc = SQLITE_CORRUPT_PAGE(pPage);
8018180353
goto cleardatabasepage_out;
8018280354
}
8018380355
hdr = pPage->hdrOffset;
8018480356
for(i=0; i<pPage->nCell; i++){
8018580357
pCell = findCell(pPage, i);
@@ -80279,11 +80451,11 @@
8027980451
8028080452
assert( sqlite3BtreeHoldsMutex(p) );
8028180453
assert( p->inTrans==TRANS_WRITE );
8028280454
assert( iTable>=2 );
8028380455
if( iTable>btreePagecount(pBt) ){
80284
- return SQLITE_CORRUPT_BKPT;
80456
+ return SQLITE_CORRUPT_PGNO(iTable);
8028580457
}
8028680458
8028780459
rc = sqlite3BtreeClearTable(p, iTable, 0);
8028880460
if( rc ) return rc;
8028980461
rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
@@ -83920,32 +84092,52 @@
8392084092
}
8392184093
return rc;
8392284094
}
8392384095
8392484096
/* Handle negative integers in a single step. This is needed in the
83925
- ** case when the value is -9223372036854775808.
83926
- */
83927
- if( op==TK_UMINUS
83928
- && (pExpr->pLeft->op==TK_INTEGER || pExpr->pLeft->op==TK_FLOAT) ){
83929
- pExpr = pExpr->pLeft;
83930
- op = pExpr->op;
83931
- negInt = -1;
83932
- zNeg = "-";
84097
+ ** case when the value is -9223372036854775808. Except - do not do this
84098
+ ** for hexadecimal literals. */
84099
+ if( op==TK_UMINUS ){
84100
+ Expr *pLeft = pExpr->pLeft;
84101
+ if( (pLeft->op==TK_INTEGER || pLeft->op==TK_FLOAT) ){
84102
+ if( ExprHasProperty(pLeft, EP_IntValue)
84103
+ || pLeft->u.zToken[0]!='0' || (pLeft->u.zToken[1] & ~0x20)!='X'
84104
+ ){
84105
+ pExpr = pLeft;
84106
+ op = pExpr->op;
84107
+ negInt = -1;
84108
+ zNeg = "-";
84109
+ }
84110
+ }
8393384111
}
8393484112
8393584113
if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
8393684114
pVal = valueNew(db, pCtx);
8393784115
if( pVal==0 ) goto no_mem;
8393884116
if( ExprHasProperty(pExpr, EP_IntValue) ){
8393984117
sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
8394084118
}else{
83941
- zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
83942
- if( zVal==0 ) goto no_mem;
83943
- sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
84119
+ i64 iVal;
84120
+ if( op==TK_INTEGER && 0==sqlite3DecOrHexToI64(pExpr->u.zToken, &iVal) ){
84121
+ sqlite3VdbeMemSetInt64(pVal, iVal*negInt);
84122
+ }else{
84123
+ zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
84124
+ if( zVal==0 ) goto no_mem;
84125
+ sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
84126
+ }
8394484127
}
83945
- if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_BLOB ){
83946
- sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
84128
+ if( affinity==SQLITE_AFF_BLOB ){
84129
+ if( op==TK_FLOAT ){
84130
+ assert( pVal && pVal->z && pVal->flags==(MEM_Str|MEM_Term) );
84131
+ sqlite3AtoF(pVal->z, &pVal->u.r, pVal->n, SQLITE_UTF8);
84132
+ pVal->flags = MEM_Real;
84133
+ }else if( op==TK_INTEGER ){
84134
+ /* This case is required by -9223372036854775808 and other strings
84135
+ ** that look like integers but cannot be handled by the
84136
+ ** sqlite3DecOrHexToI64() call above. */
84137
+ sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
84138
+ }
8394784139
}else{
8394884140
sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
8394984141
}
8395084142
assert( (pVal->flags & MEM_IntReal)==0 );
8395184143
if( pVal->flags & (MEM_Int|MEM_IntReal|MEM_Real) ){
@@ -94641,11 +94833,11 @@
9464194833
}
9464294834
break;
9464394835
}
9464494836
#endif
9464594837
94646
-#ifndef SQLITE_OMIT_CAST
94838
+#if !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_ANALYZE)
9464794839
/* Opcode: Cast P1 P2 * * *
9464894840
** Synopsis: affinity(r[P1])
9464994841
**
9465094842
** Force the value in register P1 to be the type defined by P2.
9465194843
**
@@ -94856,20 +95048,24 @@
9485695048
if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
9485795049
applyNumericAffinity(pIn3,0);
9485895050
}
9485995051
}
9486095052
}else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
94861
- if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95053
+ if( (flags1 & MEM_Str)!=0 ){
95054
+ pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
95055
+ }else if( (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
9486295056
testcase( pIn1->flags & MEM_Int );
9486395057
testcase( pIn1->flags & MEM_Real );
9486495058
testcase( pIn1->flags & MEM_IntReal );
9486595059
sqlite3VdbeMemStringify(pIn1, encoding, 1);
9486695060
testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
9486795061
flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
9486895062
if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
9486995063
}
94870
- if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95064
+ if( (flags3 & MEM_Str)!=0 ){
95065
+ pIn3->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
95066
+ }else if( (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
9487195067
testcase( pIn3->flags & MEM_Int );
9487295068
testcase( pIn3->flags & MEM_Real );
9487395069
testcase( pIn3->flags & MEM_IntReal );
9487495070
sqlite3VdbeMemStringify(pIn3, encoding, 1);
9487595071
testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) );
@@ -96209,15 +96405,20 @@
9620996405
len = sqlite3SmallTypeSizes[serial_type];
9621096406
assert( len>=1 && len<=8 && len!=5 && len!=7 );
9621196407
switch( len ){
9621296408
default: zPayload[7] = (u8)(v&0xff); v >>= 8;
9621396409
zPayload[6] = (u8)(v&0xff); v >>= 8;
96410
+ /* no break */ deliberate_fall_through
9621496411
case 6: zPayload[5] = (u8)(v&0xff); v >>= 8;
9621596412
zPayload[4] = (u8)(v&0xff); v >>= 8;
96413
+ /* no break */ deliberate_fall_through
9621696414
case 4: zPayload[3] = (u8)(v&0xff); v >>= 8;
96415
+ /* no break */ deliberate_fall_through
9621796416
case 3: zPayload[2] = (u8)(v&0xff); v >>= 8;
96417
+ /* no break */ deliberate_fall_through
9621896418
case 2: zPayload[1] = (u8)(v&0xff); v >>= 8;
96419
+ /* no break */ deliberate_fall_through
9621996420
case 1: zPayload[0] = (u8)(v&0xff);
9622096421
}
9622196422
zPayload += len;
9622296423
}
9622396424
}else if( serial_type<0x80 ){
@@ -98738,32 +98939,41 @@
9873898939
if( res ) goto jump_to_p2;
9873998940
}
9874098941
break;
9874198942
}
9874298943
98743
-/* Opcode: IfSmaller P1 P2 P3 * *
98944
+/* Opcode: IfSizeBetween P1 P2 P3 P4 *
9874498945
**
98745
-** Estimate the number of rows in the table P1. Jump to P2 if that
98746
-** estimate is less than approximately 2**(0.1*P3).
98946
+** Let N be the approximate number of rows in the table or index
98947
+** with cursor P1 and let X be 10*log2(N) if N is positive or -1
98948
+** if N is zero. Thus X will be within the range of -1 to 640, inclusive
98949
+** Jump to P2 if X is in between P3 and P4, inclusive.
9874798950
*/
98748
-case OP_IfSmaller: { /* jump */
98951
+case OP_IfSizeBetween: { /* jump */
9874998952
VdbeCursor *pC;
9875098953
BtCursor *pCrsr;
9875198954
int res;
9875298955
i64 sz;
9875398956
9875498957
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98958
+ assert( pOp->p4type==P4_INT32 );
98959
+ assert( pOp->p3>=-1 && pOp->p3<=640 );
98960
+ assert( pOp->p4.i>=-1 && pOp->p4.i<=640 );
9875598961
pC = p->apCsr[pOp->p1];
9875698962
assert( pC!=0 );
9875798963
pCrsr = pC->uc.pCursor;
9875898964
assert( pCrsr );
9875998965
rc = sqlite3BtreeFirst(pCrsr, &res);
9876098966
if( rc ) goto abort_due_to_error;
98761
- if( res==0 ){
98967
+ if( res!=0 ){
98968
+ sz = -1; /* -Infinity encoding */
98969
+ }else{
9876298970
sz = sqlite3BtreeRowCountEst(pCrsr);
98763
- if( ALWAYS(sz>=0) && sqlite3LogEst((u64)sz)<pOp->p3 ) res = 1;
98971
+ assert( sz>0 );
98972
+ sz = sqlite3LogEst((u64)sz);
9876498973
}
98974
+ res = sz>=pOp->p3 && sz<=pOp->p4.i;
9876598975
VdbeBranchTaken(res!=0,2);
9876698976
if( res ) goto jump_to_p2;
9876798977
break;
9876898978
}
9876998979
@@ -99459,42 +99669,55 @@
9945999669
if( rc ) goto abort_due_to_error;
9946099670
pOut->u.i = pgno;
9946199671
break;
9946299672
}
9946399673
99464
-/* Opcode: SqlExec * * * P4 *
99674
+/* Opcode: SqlExec P1 P2 * P4 *
9946599675
**
9946699676
** Run the SQL statement or statements specified in the P4 string.
99467
-** Disable Auth and Trace callbacks while those statements are running if
99468
-** P1 is true.
99677
+**
99678
+** The P1 parameter is a bitmask of options:
99679
+**
99680
+** 0x0001 Disable Auth and Trace callbacks while the statements
99681
+** in P4 are running.
99682
+**
99683
+** 0x0002 Set db->nAnalysisLimit to P2 while the statements in
99684
+** P4 are running.
99685
+**
9946999686
*/
9947099687
case OP_SqlExec: {
9947199688
char *zErr;
9947299689
#ifndef SQLITE_OMIT_AUTHORIZATION
9947399690
sqlite3_xauth xAuth;
9947499691
#endif
9947599692
u8 mTrace;
99693
+ int savedAnalysisLimit;
9947699694
9947799695
sqlite3VdbeIncrWriteCounter(p, 0);
9947899696
db->nSqlExec++;
9947999697
zErr = 0;
9948099698
#ifndef SQLITE_OMIT_AUTHORIZATION
9948199699
xAuth = db->xAuth;
9948299700
#endif
9948399701
mTrace = db->mTrace;
99484
- if( pOp->p1 ){
99702
+ savedAnalysisLimit = db->nAnalysisLimit;
99703
+ if( pOp->p1 & 0x0001 ){
9948599704
#ifndef SQLITE_OMIT_AUTHORIZATION
9948699705
db->xAuth = 0;
9948799706
#endif
9948899707
db->mTrace = 0;
9948999708
}
99709
+ if( pOp->p1 & 0x0002 ){
99710
+ db->nAnalysisLimit = pOp->p2;
99711
+ }
9949099712
rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
9949199713
db->nSqlExec--;
9949299714
#ifndef SQLITE_OMIT_AUTHORIZATION
9949399715
db->xAuth = xAuth;
9949499716
#endif
9949599717
db->mTrace = mTrace;
99718
+ db->nAnalysisLimit = savedAnalysisLimit;
9949699719
if( zErr || rc ){
9949799720
sqlite3VdbeError(p, "%s", zErr);
9949899721
sqlite3_free(zErr);
9949999722
if( rc==SQLITE_NOMEM ) goto no_mem;
9950099723
goto abort_due_to_error;
@@ -99647,12 +99870,12 @@
9964799870
** register P1 the text of an error message describing any problems.
9964899871
** If no problems are found, store a NULL in register P1.
9964999872
**
9965099873
** The register P3 contains one less than the maximum number of allowed errors.
9965199874
** At most reg(P3) errors will be reported.
99652
-** In other words, the analysis stops as soon as reg(P1) errors are
99653
-** seen. Reg(P1) is updated with the number of errors remaining.
99875
+** In other words, the analysis stops as soon as reg(P3) errors are
99876
+** seen. Reg(P3) is updated with the number of errors remaining.
9965499877
**
9965599878
** The root page numbers of all tables in the database are integers
9965699879
** stored in P4_INTARRAY argument.
9965799880
**
9965899881
** If P5 is not zero, the check is done on the auxiliary database
@@ -106210,10 +106433,12 @@
106210106433
sqlite3 *db; /* The database connection */
106211106434
106212106435
assert( iCol>=0 && iCol<pEList->nExpr );
106213106436
pOrig = pEList->a[iCol].pExpr;
106214106437
assert( pOrig!=0 );
106438
+ assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) );
106439
+ if( pExpr->pAggInfo ) return;
106215106440
db = pParse->db;
106216106441
pDup = sqlite3ExprDup(db, pOrig, 0);
106217106442
if( db->mallocFailed ){
106218106443
sqlite3ExprDelete(db, pDup);
106219106444
pDup = 0;
@@ -106408,11 +106633,11 @@
106408106633
*/
106409106634
static int lookupName(
106410106635
Parse *pParse, /* The parsing context */
106411106636
const char *zDb, /* Name of the database containing table, or NULL */
106412106637
const char *zTab, /* Name of table containing column, or NULL */
106413
- const char *zCol, /* Name of the column. */
106638
+ const Expr *pRight, /* Name of the column. */
106414106639
NameContext *pNC, /* The name context used to resolve the name */
106415106640
Expr *pExpr /* Make this EXPR node point to the selected column */
106416106641
){
106417106642
int i, j; /* Loop counters */
106418106643
int cnt = 0; /* Number of matching column names */
@@ -106425,10 +106650,11 @@
106425106650
Schema *pSchema = 0; /* Schema of the expression */
106426106651
int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
106427106652
Table *pTab = 0; /* Table holding the row */
106428106653
Column *pCol; /* A column of pTab */
106429106654
ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
106655
+ const char *zCol = pRight->u.zToken;
106430106656
106431106657
assert( pNC ); /* the name context cannot be NULL. */
106432106658
assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
106433106659
assert( zDb==0 || zTab!=0 );
106434106660
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
@@ -106884,10 +107110,14 @@
106884107110
zErr = cnt==0 ? "no such column" : "ambiguous column name";
106885107111
if( zDb ){
106886107112
sqlite3ErrorMsg(pParse, "%s: %s.%s.%s", zErr, zDb, zTab, zCol);
106887107113
}else if( zTab ){
106888107114
sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
107115
+ }else if( cnt==0 && ExprHasProperty(pRight,EP_DblQuoted) ){
107116
+ sqlite3ErrorMsg(pParse, "%s: \"%s\" - should this be a"
107117
+ " string literal in single-quotes?",
107118
+ zErr, zCol);
106889107119
}else{
106890107120
sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
106891107121
}
106892107122
sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
106893107123
pParse->checkSchema = 1;
@@ -107131,20 +107361,19 @@
107131107361
** be one call to lookupName(). Then the compiler will in-line
107132107362
** lookupName() for a size reduction and performance increase.
107133107363
*/
107134107364
case TK_ID:
107135107365
case TK_DOT: {
107136
- const char *zColumn;
107137107366
const char *zTable;
107138107367
const char *zDb;
107139107368
Expr *pRight;
107140107369
107141107370
if( pExpr->op==TK_ID ){
107142107371
zDb = 0;
107143107372
zTable = 0;
107144107373
assert( !ExprHasProperty(pExpr, EP_IntValue) );
107145
- zColumn = pExpr->u.zToken;
107374
+ pRight = pExpr;
107146107375
}else{
107147107376
Expr *pLeft = pExpr->pLeft;
107148107377
testcase( pNC->ncFlags & NC_IdxExpr );
107149107378
testcase( pNC->ncFlags & NC_GenCol );
107150107379
sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
@@ -107159,18 +107388,17 @@
107159107388
pLeft = pRight->pLeft;
107160107389
pRight = pRight->pRight;
107161107390
}
107162107391
assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) );
107163107392
zTable = pLeft->u.zToken;
107164
- zColumn = pRight->u.zToken;
107165107393
assert( ExprUseYTab(pExpr) );
107166107394
if( IN_RENAME_OBJECT ){
107167107395
sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
107168107396
sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
107169107397
}
107170107398
}
107171
- return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
107399
+ return lookupName(pParse, zDb, zTable, pRight, pNC, pExpr);
107172107400
}
107173107401
107174107402
/* Resolve function names
107175107403
*/
107176107404
case TK_FUNCTION: {
@@ -118538,11 +118766,11 @@
118538118766
u64 nDistinct = p->current.anDLt[i] + 1;
118539118767
u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
118540118768
if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
118541118769
sqlite3_str_appendf(&sStat, " %llu", iVal);
118542118770
#ifdef SQLITE_ENABLE_STAT4
118543
- assert( p->current.anEq[i] );
118771
+ assert( p->current.anEq[i] || p->nRow==0 );
118544118772
#endif
118545118773
}
118546118774
sqlite3ResultStrAccum(context, &sStat);
118547118775
}
118548118776
#ifdef SQLITE_ENABLE_STAT4
@@ -118723,11 +118951,11 @@
118723118951
sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
118724118952
sqlite3VdbeLoadString(v, regTabname, pTab->zName);
118725118953
118726118954
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
118727118955
int nCol; /* Number of columns in pIdx. "N" */
118728
- int addrRewind; /* Address of "OP_Rewind iIdxCur" */
118956
+ int addrGotoEnd; /* Address of "OP_Rewind iIdxCur" */
118729118957
int addrNextRow; /* Address of "next_row:" */
118730118958
const char *zIdxName; /* Name of the index */
118731118959
int nColTest; /* Number of columns to test for changes */
118732118960
118733118961
if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
@@ -118747,13 +118975,18 @@
118747118975
VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
118748118976
118749118977
/*
118750118978
** Pseudo-code for loop that calls stat_push():
118751118979
**
118980
+ ** regChng = 0
118752118981
** Rewind csr
118753
- ** if eof(csr) goto end_of_scan;
118754
- ** regChng = 0
118982
+ ** if eof(csr){
118983
+ ** stat_init() with count = 0;
118984
+ ** goto end_of_scan;
118985
+ ** }
118986
+ ** count()
118987
+ ** stat_init()
118755118988
** goto chng_addr_0;
118756118989
**
118757118990
** next_row:
118758118991
** regChng = 0
118759118992
** if( idx(0) != regPrev(0) ) goto chng_addr_0
@@ -118788,45 +119021,40 @@
118788119021
assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
118789119022
sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
118790119023
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
118791119024
VdbeComment((v, "%s", pIdx->zName));
118792119025
118793
- /* Invoke the stat_init() function. The arguments are:
119026
+ /* Implementation of the following:
118794119027
**
119028
+ ** regChng = 0
119029
+ ** Rewind csr
119030
+ ** if eof(csr){
119031
+ ** stat_init() with count = 0;
119032
+ ** goto end_of_scan;
119033
+ ** }
119034
+ ** count()
119035
+ ** stat_init()
119036
+ ** goto chng_addr_0;
119037
+ */
119038
+ assert( regTemp2==regStat+4 );
119039
+ sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2);
119040
+
119041
+ /* Arguments to stat_init():
118795119042
** (1) the number of columns in the index including the rowid
118796119043
** (or for a WITHOUT ROWID table, the number of PK columns),
118797119044
** (2) the number of columns in the key without the rowid/pk
118798
- ** (3) estimated number of rows in the index,
118799
- */
119045
+ ** (3) estimated number of rows in the index. */
118800119046
sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat+1);
118801119047
assert( regRowid==regStat+2 );
118802119048
sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regRowid);
118803
-#ifdef SQLITE_ENABLE_STAT4
118804
- if( OptimizationEnabled(db, SQLITE_Stat4) ){
118805
- sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regTemp);
118806
- addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
118807
- VdbeCoverage(v);
118808
- }else
118809
-#endif
118810
- {
118811
- addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
118812
- VdbeCoverage(v);
118813
- sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp, 1);
118814
- }
118815
- assert( regTemp2==regStat+4 );
118816
- sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2);
119049
+ sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp,
119050
+ OptimizationDisabled(db, SQLITE_Stat4));
118817119051
sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4,
118818119052
&statInitFuncdef, 0);
118819
-
118820
- /* Implementation of the following:
118821
- **
118822
- ** Rewind csr
118823
- ** if eof(csr) goto end_of_scan;
118824
- ** regChng = 0
118825
- ** goto next_push_0;
118826
- **
118827
- */
119053
+ addrGotoEnd = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
119054
+ VdbeCoverage(v);
119055
+
118828119056
sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
118829119057
addrNextRow = sqlite3VdbeCurrentAddr(v);
118830119058
118831119059
if( nColTest>0 ){
118832119060
int endDistinctTest = sqlite3VdbeMakeLabel(pParse);
@@ -118929,10 +119157,16 @@
118929119157
sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
118930119158
}
118931119159
}
118932119160
118933119161
/* Add the entry to the stat1 table. */
119162
+ if( pIdx->pPartIdxWhere ){
119163
+ /* Partial indexes might get a zero-entry in sqlite_stat1. But
119164
+ ** an empty table is omitted from sqlite_stat1. */
119165
+ sqlite3VdbeJumpHere(v, addrGotoEnd);
119166
+ addrGotoEnd = 0;
119167
+ }
118934119168
callStatGet(pParse, regStat, STAT_GET_STAT1, regStat1);
118935119169
assert( "BBB"[0]==SQLITE_AFF_TEXT );
118936119170
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
118937119171
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
118938119172
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
@@ -118951,10 +119185,16 @@
118951119185
int regCol = regStat1+4;
118952119186
int regSampleRowid = regCol + nCol;
118953119187
int addrNext;
118954119188
int addrIsNull;
118955119189
u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
119190
+
119191
+ /* No STAT4 data is generated if the number of rows is zero */
119192
+ if( addrGotoEnd==0 ){
119193
+ sqlite3VdbeAddOp2(v, OP_Cast, regStat1, SQLITE_AFF_INTEGER);
119194
+ addrGotoEnd = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
119195
+ }
118956119196
118957119197
if( doOnce ){
118958119198
int mxCol = nCol;
118959119199
Index *pX;
118960119200
@@ -119004,11 +119244,11 @@
119004119244
sqlite3VdbeJumpHere(v, addrIsNull);
119005119245
}
119006119246
#endif /* SQLITE_ENABLE_STAT4 */
119007119247
119008119248
/* End of analysis */
119009
- sqlite3VdbeJumpHere(v, addrRewind);
119249
+ if( addrGotoEnd ) sqlite3VdbeJumpHere(v, addrGotoEnd);
119010119250
}
119011119251
119012119252
119013119253
/* Create a single sqlite_stat1 entry containing NULL as the index
119014119254
** name and the row count as the content.
@@ -120753,11 +120993,11 @@
120753120993
sqlite3VdbeJumpHere(v, addrRewind);
120754120994
}
120755120995
}
120756120996
sqlite3VdbeAddOp0(v, OP_Halt);
120757120997
120758
-#if SQLITE_USER_AUTHENTICATION
120998
+#if SQLITE_USER_AUTHENTICATION && !defined(SQLITE_OMIT_SHARED_CACHE)
120759120999
if( pParse->nTableLock>0 && db->init.busy==0 ){
120760121000
sqlite3UserAuthInit(db);
120761121001
if( db->auth.authLevel<UAUTH_User ){
120762121002
sqlite3ErrorMsg(pParse, "user not authenticated");
120763121003
pParse->rc = SQLITE_AUTH_USER;
@@ -123487,15 +123727,15 @@
123487123727
sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName),0);
123488123728
123489123729
/* Test for cycles in generated columns and illegal expressions
123490123730
** in CHECK constraints and in DEFAULT clauses. */
123491123731
if( p->tabFlags & TF_HasGenerated ){
123492
- sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0,
123732
+ sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
123493123733
sqlite3MPrintf(db, "SELECT*FROM\"%w\".\"%w\"",
123494123734
db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
123495123735
}
123496
- sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0,
123736
+ sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
123497123737
sqlite3MPrintf(db, "PRAGMA \"%w\".integrity_check(%Q)",
123498123738
db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
123499123739
}
123500123740
123501123741
/* Add the table to the in-memory representation of the database.
@@ -129253,11 +129493,11 @@
129253129493
|| sqlite3_context_db_handle(context)->mallocFailed );
129254129494
return;
129255129495
}
129256129496
if( zPattern[0]==0 ){
129257129497
assert( sqlite3_value_type(argv[1])!=SQLITE_NULL );
129258
- sqlite3_result_value(context, argv[0]);
129498
+ sqlite3_result_text(context, (const char*)zStr, nStr, SQLITE_TRANSIENT);
129259129499
return;
129260129500
}
129261129501
nPattern = sqlite3_value_bytes(argv[1]);
129262129502
assert( zPattern==sqlite3_value_text(argv[1]) ); /* No encoding change */
129263129503
zRep = sqlite3_value_text(argv[2]);
@@ -137740,10 +137980,38 @@
137740137980
/* Number of pragmas: 68 on by default, 78 total. */
137741137981
137742137982
/************** End of pragma.h **********************************************/
137743137983
/************** Continuing where we left off in pragma.c *********************/
137744137984
137985
+/*
137986
+** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
137987
+** will be run with an analysis_limit set to the lessor of the value of
137988
+** the following macro or to the actual analysis_limit if it is non-zero,
137989
+** in order to prevent PRAGMA optimize from running for too long.
137990
+**
137991
+** The value of 2000 is chosen emperically so that the worst-case run-time
137992
+** for PRAGMA optimize does not exceed 100 milliseconds against a variety
137993
+** of test databases on a RaspberryPI-4 compiled using -Os and without
137994
+** -DSQLITE_DEBUG. Of course, your mileage may vary. For the purpose of
137995
+** his paragraph, "worst-case" means that ANALYZE ends up being
137996
+** run on every table in the database. The worst case typically only
137997
+** happens if PRAGMA optimize is run on a database file for which ANALYZE
137998
+** has not been previously run and the 0x10000 flag is included so that
137999
+** all tables are analyzed. The usual case for PRAGMA optimize is that
138000
+** no ANALYZE commands will be run at all, or if any ANALYZE happens it
138001
+** will be against a single table, so that expected timing for PRAGMA
138002
+** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
138003
+** flag or less than 100 microseconds without the 0x10000 flag.
138004
+**
138005
+** An analysis limit of 2000 is almost always sufficient for the query
138006
+** planner to fully characterize an index. The additional accuracy from
138007
+** a larger analysis is not usually helpful.
138008
+*/
138009
+#ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT
138010
+# define SQLITE_DEFAULT_OPTIMIZE_LIMIT 2000
138011
+#endif
138012
+
137745138013
/*
137746138014
** Interpret the given string as a safety level. Return 0 for OFF,
137747138015
** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA. Return 1 for an empty or
137748138016
** unrecognized string argument. The FULL and EXTRA option is disallowed
137749138017
** if the omitFull parameter it 1.
@@ -139472,35 +139740,11 @@
139472139740
int bStrict; /* True for a STRICT table */
139473139741
int r2; /* Previous key for WITHOUT ROWID tables */
139474139742
int mxCol; /* Maximum non-virtual column number */
139475139743
139476139744
if( pObjTab && pObjTab!=pTab ) continue;
139477
- if( !IsOrdinaryTable(pTab) ){
139478
-#ifndef SQLITE_OMIT_VIRTUALTABLE
139479
- sqlite3_vtab *pVTab;
139480
- int a1;
139481
- if( !IsVirtual(pTab) ) continue;
139482
- if( pTab->nCol<=0 ){
139483
- const char *zMod = pTab->u.vtab.azArg[0];
139484
- if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
139485
- }
139486
- sqlite3ViewGetColumnNames(pParse, pTab);
139487
- if( pTab->u.vtab.p==0 ) continue;
139488
- pVTab = pTab->u.vtab.p->pVtab;
139489
- if( NEVER(pVTab==0) ) continue;
139490
- if( NEVER(pVTab->pModule==0) ) continue;
139491
- if( pVTab->pModule->iVersion<4 ) continue;
139492
- if( pVTab->pModule->xIntegrity==0 ) continue;
139493
- sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick);
139494
- pTab->nTabRef++;
139495
- sqlite3VdbeAppendP4(v, pTab, P4_TABLEREF);
139496
- a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
139497
- integrityCheckResultRow(v);
139498
- sqlite3VdbeJumpHere(v, a1);
139499
-#endif
139500
- continue;
139501
- }
139745
+ if( !IsOrdinaryTable(pTab) ) continue;
139502139746
if( isQuick || HasRowid(pTab) ){
139503139747
pPk = 0;
139504139748
r2 = 0;
139505139749
}else{
139506139750
pPk = sqlite3PrimaryKeyIndex(pTab);
@@ -139631,10 +139875,11 @@
139631139875
/* OP_IsType does not detect NaN values in the database file
139632139876
** which should be treated as a NULL. So if the header type
139633139877
** is REAL, we have to load the actual data using OP_Column
139634139878
** to reliably determine if the value is a NULL. */
139635139879
sqlite3VdbeAddOp3(v, OP_Column, p1, p3, 3);
139880
+ sqlite3ColumnDefault(v, pTab, j, 3);
139636139881
jmp3 = sqlite3VdbeAddOp2(v, OP_NotNull, 3, labelOk);
139637139882
VdbeCoverage(v);
139638139883
}
139639139884
zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
139640139885
pCol->zCnName);
@@ -139821,10 +140066,42 @@
139821140066
if( pPk ){
139822140067
sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol);
139823140068
}
139824140069
}
139825140070
}
140071
+
140072
+#ifndef SQLITE_OMIT_VIRTUALTABLE
140073
+ /* Second pass to invoke the xIntegrity method on all virtual
140074
+ ** tables.
140075
+ */
140076
+ for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
140077
+ Table *pTab = sqliteHashData(x);
140078
+ sqlite3_vtab *pVTab;
140079
+ int a1;
140080
+ if( pObjTab && pObjTab!=pTab ) continue;
140081
+ if( IsOrdinaryTable(pTab) ) continue;
140082
+ if( !IsVirtual(pTab) ) continue;
140083
+ if( pTab->nCol<=0 ){
140084
+ const char *zMod = pTab->u.vtab.azArg[0];
140085
+ if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
140086
+ }
140087
+ sqlite3ViewGetColumnNames(pParse, pTab);
140088
+ if( pTab->u.vtab.p==0 ) continue;
140089
+ pVTab = pTab->u.vtab.p->pVtab;
140090
+ if( NEVER(pVTab==0) ) continue;
140091
+ if( NEVER(pVTab->pModule==0) ) continue;
140092
+ if( pVTab->pModule->iVersion<4 ) continue;
140093
+ if( pVTab->pModule->xIntegrity==0 ) continue;
140094
+ sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick);
140095
+ pTab->nTabRef++;
140096
+ sqlite3VdbeAppendP4(v, pTab, P4_TABLEREF);
140097
+ a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
140098
+ integrityCheckResultRow(v);
140099
+ sqlite3VdbeJumpHere(v, a1);
140100
+ continue;
140101
+ }
140102
+#endif
139826140103
}
139827140104
{
139828140105
static const int iLn = VDBE_OFFSET_LINENO(2);
139829140106
static const VdbeOpList endCode[] = {
139830140107
{ OP_AddImm, 1, 0, 0}, /* 0 */
@@ -140084,48 +140361,67 @@
140084140361
** to change and improve over time. Applications should anticipate that
140085140362
** this pragma will perform new optimizations in future releases.
140086140363
**
140087140364
** The optional argument is a bitmask of optimizations to perform:
140088140365
**
140089
- ** 0x0001 Debugging mode. Do not actually perform any optimizations
140090
- ** but instead return one line of text for each optimization
140091
- ** that would have been done. Off by default.
140092
- **
140093
- ** 0x0002 Run ANALYZE on tables that might benefit. On by default.
140094
- ** See below for additional information.
140095
- **
140096
- ** 0x0004 (Not yet implemented) Record usage and performance
140097
- ** information from the current session in the
140098
- ** database file so that it will be available to "optimize"
140099
- ** pragmas run by future database connections.
140100
- **
140101
- ** 0x0008 (Not yet implemented) Create indexes that might have
140102
- ** been helpful to recent queries
140103
- **
140104
- ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all
140105
- ** of the optimizations listed above except Debug Mode, including new
140106
- ** optimizations that have not yet been invented. If new optimizations are
140107
- ** ever added that should be off by default, those off-by-default
140108
- ** optimizations will have bitmasks of 0x10000 or larger.
140366
+ ** 0x00001 Debugging mode. Do not actually perform any optimizations
140367
+ ** but instead return one line of text for each optimization
140368
+ ** that would have been done. Off by default.
140369
+ **
140370
+ ** 0x00002 Run ANALYZE on tables that might benefit. On by default.
140371
+ ** See below for additional information.
140372
+ **
140373
+ ** 0x00010 Run all ANALYZE operations using an analysis_limit that
140374
+ ** is the lessor of the current analysis_limit and the
140375
+ ** SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option.
140376
+ ** The default value of SQLITE_DEFAULT_OPTIMIZE_LIMIT is
140377
+ ** currently (2024-02-19) set to 2000, which is such that
140378
+ ** the worst case run-time for PRAGMA optimize on a 100MB
140379
+ ** database will usually be less than 100 milliseconds on
140380
+ ** a RaspberryPI-4 class machine. On by default.
140381
+ **
140382
+ ** 0x10000 Look at tables to see if they need to be reanalyzed
140383
+ ** due to growth or shrinkage even if they have not been
140384
+ ** queried during the current connection. Off by default.
140385
+ **
140386
+ ** The default MASK is and always shall be 0x0fffe. In the current
140387
+ ** implementation, the default mask only covers the 0x00002 optimization,
140388
+ ** though additional optimizations that are covered by 0x0fffe might be
140389
+ ** added in the future. Optimizations that are off by default and must
140390
+ ** be explicitly requested have masks of 0x10000 or greater.
140109140391
**
140110140392
** DETERMINATION OF WHEN TO RUN ANALYZE
140111140393
**
140112140394
** In the current implementation, a table is analyzed if only if all of
140113140395
** the following are true:
140114140396
**
140115
- ** (1) MASK bit 0x02 is set.
140116
- **
140117
- ** (2) The query planner used sqlite_stat1-style statistics for one or
140118
- ** more indexes of the table at some point during the lifetime of
140119
- ** the current connection.
140120
- **
140121
- ** (3) One or more indexes of the table are currently unanalyzed OR
140122
- ** the number of rows in the table has increased by 25 times or more
140123
- ** since the last time ANALYZE was run.
140397
+ ** (1) MASK bit 0x00002 is set.
140398
+ **
140399
+ ** (2) The table is an ordinary table, not a virtual table or view.
140400
+ **
140401
+ ** (3) The table name does not begin with "sqlite_".
140402
+ **
140403
+ ** (4) One or more of the following is true:
140404
+ ** (4a) The 0x10000 MASK bit is set.
140405
+ ** (4b) One or more indexes on the table lacks an entry
140406
+ ** in the sqlite_stat1 table.
140407
+ ** (4c) The query planner used sqlite_stat1-style statistics for one
140408
+ ** or more indexes of the table at some point during the lifetime
140409
+ ** of the current connection.
140410
+ **
140411
+ ** (5) One or more of the following is true:
140412
+ ** (5a) One or more indexes on the table lacks an entry
140413
+ ** in the sqlite_stat1 table. (Same as 4a)
140414
+ ** (5b) The number of rows in the table has increased or decreased by
140415
+ ** 10-fold. In other words, the current size of the table is
140416
+ ** 10 times larger than the size in sqlite_stat1 or else the
140417
+ ** current size is less than 1/10th the size in sqlite_stat1.
140124140418
**
140125140419
** The rules for when tables are analyzed are likely to change in
140126
- ** future releases.
140420
+ ** future releases. Future versions of SQLite might accept a string
140421
+ ** literal argument to this pragma that contains a mnemonic description
140422
+ ** of the options rather than a bitmap.
140127140423
*/
140128140424
case PragTyp_OPTIMIZE: {
140129140425
int iDbLast; /* Loop termination point for the schema loop */
140130140426
int iTabCur; /* Cursor for a table whose size needs checking */
140131140427
HashElem *k; /* Loop over tables of a schema */
@@ -140133,56 +140429,122 @@
140133140429
Table *pTab; /* A table in the schema */
140134140430
Index *pIdx; /* An index of the table */
140135140431
LogEst szThreshold; /* Size threshold above which reanalysis needed */
140136140432
char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
140137140433
u32 opMask; /* Mask of operations to perform */
140434
+ int nLimit; /* Analysis limit to use */
140435
+ int nCheck = 0; /* Number of tables to be optimized */
140436
+ int nBtree = 0; /* Number of btrees to scan */
140437
+ int nIndex; /* Number of indexes on the current table */
140138140438
140139140439
if( zRight ){
140140140440
opMask = (u32)sqlite3Atoi(zRight);
140141140441
if( (opMask & 0x02)==0 ) break;
140142140442
}else{
140143140443
opMask = 0xfffe;
140144140444
}
140445
+ if( (opMask & 0x10)==0 ){
140446
+ nLimit = 0;
140447
+ }else if( db->nAnalysisLimit>0
140448
+ && db->nAnalysisLimit<SQLITE_DEFAULT_OPTIMIZE_LIMIT ){
140449
+ nLimit = 0;
140450
+ }else{
140451
+ nLimit = SQLITE_DEFAULT_OPTIMIZE_LIMIT;
140452
+ }
140145140453
iTabCur = pParse->nTab++;
140146140454
for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){
140147140455
if( iDb==1 ) continue;
140148140456
sqlite3CodeVerifySchema(pParse, iDb);
140149140457
pSchema = db->aDb[iDb].pSchema;
140150140458
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
140151140459
pTab = (Table*)sqliteHashData(k);
140152140460
140153
- /* If table pTab has not been used in a way that would benefit from
140154
- ** having analysis statistics during the current session, then skip it.
140155
- ** This also has the effect of skipping virtual tables and views */
140156
- if( (pTab->tabFlags & TF_StatsUsed)==0 ) continue;
140461
+ /* This only works for ordinary tables */
140462
+ if( !IsOrdinaryTable(pTab) ) continue;
140157140463
140158
- /* Reanalyze if the table is 25 times larger than the last analysis */
140159
- szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 );
140464
+ /* Do not scan system tables */
140465
+ if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue;
140466
+
140467
+ /* Find the size of the table as last recorded in sqlite_stat1.
140468
+ ** If any index is unanalyzed, then the threshold is -1 to
140469
+ ** indicate a new, unanalyzed index
140470
+ */
140471
+ szThreshold = pTab->nRowLogEst;
140472
+ nIndex = 0;
140160140473
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
140474
+ nIndex++;
140161140475
if( !pIdx->hasStat1 ){
140162
- szThreshold = 0; /* Always analyze if any index lacks statistics */
140163
- break;
140476
+ szThreshold = -1; /* Always analyze if any index lacks statistics */
140164140477
}
140165140478
}
140166
- if( szThreshold ){
140167
- sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
140168
- sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur,
140169
- sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold);
140479
+
140480
+ /* If table pTab has not been used in a way that would benefit from
140481
+ ** having analysis statistics during the current session, then skip it,
140482
+ ** unless the 0x10000 MASK bit is set. */
140483
+ if( (pTab->tabFlags & TF_MaybeReanalyze)!=0 ){
140484
+ /* Check for size change if stat1 has been used for a query */
140485
+ }else if( opMask & 0x10000 ){
140486
+ /* Check for size change if 0x10000 is set */
140487
+ }else if( pTab->pIndex!=0 && szThreshold<0 ){
140488
+ /* Do analysis if unanalyzed indexes exists */
140489
+ }else{
140490
+ /* Otherwise, we can skip this table */
140491
+ continue;
140492
+ }
140493
+
140494
+ nCheck++;
140495
+ if( nCheck==2 ){
140496
+ /* If ANALYZE might be invoked two or more times, hold a write
140497
+ ** transaction for efficiency */
140498
+ sqlite3BeginWriteOperation(pParse, 0, iDb);
140499
+ }
140500
+ nBtree += nIndex+1;
140501
+
140502
+ /* Reanalyze if the table is 10 times larger or smaller than
140503
+ ** the last analysis. Unconditional reanalysis if there are
140504
+ ** unanalyzed indexes. */
140505
+ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
140506
+ if( szThreshold>=0 ){
140507
+ const LogEst iRange = 33; /* 10x size change */
140508
+ sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur,
140509
+ sqlite3VdbeCurrentAddr(v)+2+(opMask&1),
140510
+ szThreshold>=iRange ? szThreshold-iRange : -1,
140511
+ szThreshold+iRange);
140512
+ VdbeCoverage(v);
140513
+ }else{
140514
+ sqlite3VdbeAddOp2(v, OP_Rewind, iTabCur,
140515
+ sqlite3VdbeCurrentAddr(v)+2+(opMask&1));
140170140516
VdbeCoverage(v);
140171140517
}
140172140518
zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"",
140173140519
db->aDb[iDb].zDbSName, pTab->zName);
140174140520
if( opMask & 0x01 ){
140175140521
int r1 = sqlite3GetTempReg(pParse);
140176140522
sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
140177140523
sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1);
140178140524
}else{
140179
- sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC);
140525
+ sqlite3VdbeAddOp4(v, OP_SqlExec, nLimit ? 0x02 : 00, nLimit, 0,
140526
+ zSubSql, P4_DYNAMIC);
140180140527
}
140181140528
}
140182140529
}
140183140530
sqlite3VdbeAddOp0(v, OP_Expire);
140531
+
140532
+ /* In a schema with a large number of tables and indexes, scale back
140533
+ ** the analysis_limit to avoid excess run-time in the worst case.
140534
+ */
140535
+ if( !db->mallocFailed && nLimit>0 && nBtree>100 ){
140536
+ int iAddr, iEnd;
140537
+ VdbeOp *aOp;
140538
+ nLimit = 100*nLimit/nBtree;
140539
+ if( nLimit<100 ) nLimit = 100;
140540
+ aOp = sqlite3VdbeGetOp(v, 0);
140541
+ iEnd = sqlite3VdbeCurrentAddr(v);
140542
+ for(iAddr=0; iAddr<iEnd; iAddr++){
140543
+ if( aOp[iAddr].opcode==OP_SqlExec ) aOp[iAddr].p2 = nLimit;
140544
+ }
140545
+ }
140184140546
break;
140185140547
}
140186140548
140187140549
/*
140188140550
** PRAGMA busy_timeout
@@ -148175,10 +148537,12 @@
148175148537
/*
148176148538
** Display all information about an AggInfo object
148177148539
*/
148178148540
static void printAggInfo(AggInfo *pAggInfo){
148179148541
int ii;
148542
+ sqlite3DebugPrintf("AggInfo %d/%p:\n",
148543
+ pAggInfo->selId, pAggInfo);
148180148544
for(ii=0; ii<pAggInfo->nColumn; ii++){
148181148545
struct AggInfo_col *pCol = &pAggInfo->aCol[ii];
148182148546
sqlite3DebugPrintf(
148183148547
"agg-column[%d] pTab=%s iTable=%d iColumn=%d iMem=%d"
148184148548
" iSorterColumn=%d %s\n",
@@ -150277,10 +150641,16 @@
150277150641
assert( db->mallocFailed==0 || db->mallocFailed==1 );
150278150642
assert( db->mallocFailed==0 || pParse->nErr!=0 );
150279150643
sqlite3ExprListDelete(db, pMinMaxOrderBy);
150280150644
#ifdef SQLITE_DEBUG
150281150645
if( pAggInfo && !db->mallocFailed ){
150646
+#if TREETRACE_ENABLED
150647
+ if( sqlite3TreeTrace & 0x20 ){
150648
+ TREETRACE(0x20,pParse,p,("Finished with AggInfo\n"));
150649
+ printAggInfo(pAggInfo);
150650
+ }
150651
+#endif
150282150652
for(i=0; i<pAggInfo->nColumn; i++){
150283150653
Expr *pExpr = pAggInfo->aCol[i].pCExpr;
150284150654
if( pExpr==0 ) continue;
150285150655
assert( pExpr->pAggInfo==pAggInfo );
150286150656
assert( pExpr->iAgg==i );
@@ -154714,10 +155084,12 @@
154714155084
sCtx.pPrior = db->pVtabCtx;
154715155085
sCtx.bDeclared = 0;
154716155086
db->pVtabCtx = &sCtx;
154717155087
pTab->nTabRef++;
154718155088
rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
155089
+ assert( pTab!=0 );
155090
+ assert( pTab->nTabRef>1 || rc!=SQLITE_OK );
154719155091
sqlite3DeleteTable(db, pTab);
154720155092
db->pVtabCtx = sCtx.pPrior;
154721155093
if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
154722155094
assert( sCtx.pTab==pTab );
154723155095
@@ -154736,11 +155108,11 @@
154736155108
pVTable->pVtab->pModule = pMod->pModule;
154737155109
pMod->nRefModule++;
154738155110
pVTable->nRef = 1;
154739155111
if( sCtx.bDeclared==0 ){
154740155112
const char *zFormat = "vtable constructor did not declare schema: %s";
154741
- *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
155113
+ *pzErr = sqlite3MPrintf(db, zFormat, zModuleName);
154742155114
sqlite3VtabUnlock(pVTable);
154743155115
rc = SQLITE_ERROR;
154744155116
}else{
154745155117
int iCol;
154746155118
u16 oooHidden = 0;
@@ -164129,11 +164501,13 @@
164129164501
if( pIndex->bUnordered ) return 0;
164130164502
if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
164131164503
for(ii=0; ii<pOB->nExpr; ii++){
164132164504
Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
164133164505
if( NEVER(pExpr==0) ) continue;
164134
- if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){
164506
+ if( (pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN)
164507
+ && pExpr->iTable==iCursor
164508
+ ){
164135164509
if( pExpr->iColumn<0 ) return 1;
164136164510
for(jj=0; jj<pIndex->nKeyCol; jj++){
164137164511
if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
164138164512
}
164139164513
}else if( (aColExpr = pIndex->aColExpr)!=0 ){
@@ -164735,11 +165109,11 @@
164735165109
if( pBuilder->bldFlags1==SQLITE_BLDF1_INDEXED ){
164736165110
/* If a non-unique index is used, or if a prefix of the key for
164737165111
** unique index is used (making the index functionally non-unique)
164738165112
** then the sqlite_stat1 data becomes important for scoring the
164739165113
** plan */
164740
- pTab->tabFlags |= TF_StatsUsed;
165114
+ pTab->tabFlags |= TF_MaybeReanalyze;
164741165115
}
164742165116
#ifdef SQLITE_ENABLE_STAT4
164743165117
sqlite3Stat4ProbeFree(pBuilder->pRec);
164744165118
pBuilder->nRecValid = 0;
164745165119
pBuilder->pRec = 0;
@@ -166229,14 +166603,13 @@
166229166603
pWInfo->nOBSat = pFrom->isOrdered;
166230166604
if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
166231166605
if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
166232166606
pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
166233166607
}
166234
- if( pWInfo->pSelect->pOrderBy
166235
- && pWInfo->nOBSat > pWInfo->pSelect->pOrderBy->nExpr ){
166236
- pWInfo->nOBSat = pWInfo->pSelect->pOrderBy->nExpr;
166237
- }
166608
+ /* vvv--- See check-in [12ad822d9b827777] on 2023-03-16 ---vvv */
166609
+ assert( pWInfo->pSelect->pOrderBy==0
166610
+ || pWInfo->nOBSat <= pWInfo->pSelect->pOrderBy->nExpr );
166238166611
}else{
166239166612
pWInfo->revMask = pFrom->revLoop;
166240166613
if( pWInfo->nOBSat<=0 ){
166241166614
pWInfo->nOBSat = 0;
166242166615
if( nLoop>0 ){
@@ -166571,11 +166944,11 @@
166571166944
WhereLoop *pLoop = pWInfo->a[i].pWLoop;
166572166945
const unsigned int reqFlags = (WHERE_SELFCULL|WHERE_COLUMN_EQ);
166573166946
SrcItem *pItem = &pWInfo->pTabList->a[pLoop->iTab];
166574166947
Table *pTab = pItem->pTab;
166575166948
if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
166576
- pTab->tabFlags |= TF_StatsUsed;
166949
+ pTab->tabFlags |= TF_MaybeReanalyze;
166577166950
if( i>=1
166578166951
&& (pLoop->wsFlags & reqFlags)==reqFlags
166579166952
/* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */
166580166953
&& ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0)
166581166954
){
@@ -171056,10 +171429,18 @@
171056171429
sqlite3WithDelete(pParse->db, pWith);
171057171430
}
171058171431
return pSelect;
171059171432
}
171060171433
171434
+ /* Memory allocator for parser stack resizing. This is a thin wrapper around
171435
+ ** sqlite3_realloc() that includes a call to sqlite3FaultSim() to facilitate
171436
+ ** testing.
171437
+ */
171438
+ static void *parserStackRealloc(void *pOld, sqlite3_uint64 newSize){
171439
+ return sqlite3FaultSim(700) ? 0 : sqlite3_realloc(pOld, newSize);
171440
+ }
171441
+
171061171442
171062171443
/* Construct a new Expr object from a single token */
171063171444
static Expr *tokenExpr(Parse *pParse, int op, Token t){
171064171445
Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
171065171446
if( p ){
@@ -171357,10 +171738,13 @@
171357171738
** sqlite3ParserARG_PDECL A parameter declaration for the %extra_argument
171358171739
** sqlite3ParserARG_PARAM Code to pass %extra_argument as a subroutine parameter
171359171740
** sqlite3ParserARG_STORE Code to store %extra_argument into yypParser
171360171741
** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
171361171742
** sqlite3ParserCTX_* As sqlite3ParserARG_ except for %extra_context
171743
+** YYREALLOC Name of the realloc() function to use
171744
+** YYFREE Name of the free() function to use
171745
+** YYDYNSTACK True if stack space should be extended on heap
171362171746
** YYERRORSYMBOL is the code number of the error symbol. If not
171363171747
** defined, then do no error processing.
171364171748
** YYNSTATE the combined number of states.
171365171749
** YYNRULE the number of rules in the grammar
171366171750
** YYNTOKEN Number of terminal symbols
@@ -171370,10 +171754,12 @@
171370171754
** YY_ERROR_ACTION The yy_action[] code for syntax error
171371171755
** YY_ACCEPT_ACTION The yy_action[] code for accept
171372171756
** YY_NO_ACTION The yy_action[] code for no-op
171373171757
** YY_MIN_REDUCE Minimum value for reduce actions
171374171758
** YY_MAX_REDUCE Maximum value for reduce actions
171759
+** YY_MIN_DSTRCTR Minimum symbol value that has a destructor
171760
+** YY_MAX_DSTRCTR Maximum symbol value that has a destructor
171375171761
*/
171376171762
#ifndef INTERFACE
171377171763
# define INTERFACE 1
171378171764
#endif
171379171765
/************* Begin control #defines *****************************************/
@@ -171410,10 +171796,13 @@
171410171796
#define sqlite3ParserARG_SDECL
171411171797
#define sqlite3ParserARG_PDECL
171412171798
#define sqlite3ParserARG_PARAM
171413171799
#define sqlite3ParserARG_FETCH
171414171800
#define sqlite3ParserARG_STORE
171801
+#define YYREALLOC parserStackRealloc
171802
+#define YYFREE sqlite3_free
171803
+#define YYDYNSTACK 1
171415171804
#define sqlite3ParserCTX_SDECL Parse *pParse;
171416171805
#define sqlite3ParserCTX_PDECL ,Parse *pParse
171417171806
#define sqlite3ParserCTX_PARAM ,pParse
171418171807
#define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
171419171808
#define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
@@ -171428,10 +171817,12 @@
171428171817
#define YY_ERROR_ACTION 1243
171429171818
#define YY_ACCEPT_ACTION 1244
171430171819
#define YY_NO_ACTION 1245
171431171820
#define YY_MIN_REDUCE 1246
171432171821
#define YY_MAX_REDUCE 1650
171822
+#define YY_MIN_DSTRCTR 204
171823
+#define YY_MAX_DSTRCTR 316
171433171824
/************* End control #defines *******************************************/
171434171825
#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
171435171826
171436171827
/* Define the yytestcase() macro to be a no-op if is not already defined
171437171828
** otherwise.
@@ -171442,10 +171833,26 @@
171442171833
** for testing.
171443171834
*/
171444171835
#ifndef yytestcase
171445171836
# define yytestcase(X)
171446171837
#endif
171838
+
171839
+/* Macro to determine if stack space has the ability to grow using
171840
+** heap memory.
171841
+*/
171842
+#if YYSTACKDEPTH<=0 || YYDYNSTACK
171843
+# define YYGROWABLESTACK 1
171844
+#else
171845
+# define YYGROWABLESTACK 0
171846
+#endif
171847
+
171848
+/* Guarantee a minimum number of initial stack slots.
171849
+*/
171850
+#if YYSTACKDEPTH<=0
171851
+# undef YYSTACKDEPTH
171852
+# define YYSTACKDEPTH 2 /* Need a minimum stack size */
171853
+#endif
171447171854
171448171855
171449171856
/* Next are the tables used to determine what action to take based on the
171450171857
** current state and lookahead token. These tables are used to implement
171451171858
** functions that take a state number and lookahead value and return an
@@ -172351,18 +172758,13 @@
172351172758
#ifndef YYNOERRORRECOVERY
172352172759
int yyerrcnt; /* Shifts left before out of the error */
172353172760
#endif
172354172761
sqlite3ParserARG_SDECL /* A place to hold %extra_argument */
172355172762
sqlite3ParserCTX_SDECL /* A place to hold %extra_context */
172356
-#if YYSTACKDEPTH<=0
172357
- int yystksz; /* Current side of the stack */
172358
- yyStackEntry *yystack; /* The parser's stack */
172359
- yyStackEntry yystk0; /* First stack entry */
172360
-#else
172361
- yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
172362
- yyStackEntry *yystackEnd; /* Last entry in the stack */
172363
-#endif
172763
+ yyStackEntry *yystackEnd; /* Last entry in the stack */
172764
+ yyStackEntry *yystack; /* The parser stack */
172765
+ yyStackEntry yystk0[YYSTACKDEPTH]; /* Initial stack space */
172364172766
};
172365172767
typedef struct yyParser yyParser;
172366172768
172367172769
/* #include <assert.h> */
172368172770
#ifndef NDEBUG
@@ -173134,41 +173536,49 @@
173134173536
/* 404 */ "window ::= frame_opt",
173135173537
};
173136173538
#endif /* NDEBUG */
173137173539
173138173540
173139
-#if YYSTACKDEPTH<=0
173541
+#if YYGROWABLESTACK
173140173542
/*
173141173543
** Try to increase the size of the parser stack. Return the number
173142173544
** of errors. Return 0 on success.
173143173545
*/
173144173546
static int yyGrowStack(yyParser *p){
173547
+ int oldSize = 1 + (int)(p->yystackEnd - p->yystack);
173145173548
int newSize;
173146173549
int idx;
173147173550
yyStackEntry *pNew;
173148173551
173149
- newSize = p->yystksz*2 + 100;
173150
- idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
173151
- if( p->yystack==&p->yystk0 ){
173152
- pNew = malloc(newSize*sizeof(pNew[0]));
173153
- if( pNew ) pNew[0] = p->yystk0;
173552
+ newSize = oldSize*2 + 100;
173553
+ idx = (int)(p->yytos - p->yystack);
173554
+ if( p->yystack==p->yystk0 ){
173555
+ pNew = YYREALLOC(0, newSize*sizeof(pNew[0]));
173556
+ if( pNew==0 ) return 1;
173557
+ memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0]));
173154173558
}else{
173155
- pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
173559
+ pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0]));
173560
+ if( pNew==0 ) return 1;
173156173561
}
173157
- if( pNew ){
173158
- p->yystack = pNew;
173159
- p->yytos = &p->yystack[idx];
173562
+ p->yystack = pNew;
173563
+ p->yytos = &p->yystack[idx];
173160173564
#ifndef NDEBUG
173161
- if( yyTraceFILE ){
173162
- fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
173163
- yyTracePrompt, p->yystksz, newSize);
173164
- }
173565
+ if( yyTraceFILE ){
173566
+ fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
173567
+ yyTracePrompt, oldSize, newSize);
173568
+ }
173165173569
#endif
173166
- p->yystksz = newSize;
173167
- }
173168
- return pNew==0;
173570
+ p->yystackEnd = &p->yystack[newSize-1];
173571
+ return 0;
173169173572
}
173573
+#endif /* YYGROWABLESTACK */
173574
+
173575
+#if !YYGROWABLESTACK
173576
+/* For builds that do no have a growable stack, yyGrowStack always
173577
+** returns an error.
173578
+*/
173579
+# define yyGrowStack(X) 1
173170173580
#endif
173171173581
173172173582
/* Datatype of the argument to the memory allocated passed as the
173173173583
** second argument to sqlite3ParserAlloc() below. This can be changed by
173174173584
** putting an appropriate #define in the %include section of the input
@@ -173184,28 +173594,18 @@
173184173594
yyParser *yypParser = (yyParser*)yypRawParser;
173185173595
sqlite3ParserCTX_STORE
173186173596
#ifdef YYTRACKMAXSTACKDEPTH
173187173597
yypParser->yyhwm = 0;
173188173598
#endif
173189
-#if YYSTACKDEPTH<=0
173190
- yypParser->yytos = NULL;
173191
- yypParser->yystack = NULL;
173192
- yypParser->yystksz = 0;
173193
- if( yyGrowStack(yypParser) ){
173194
- yypParser->yystack = &yypParser->yystk0;
173195
- yypParser->yystksz = 1;
173196
- }
173197
-#endif
173599
+ yypParser->yystack = yypParser->yystk0;
173600
+ yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
173198173601
#ifndef YYNOERRORRECOVERY
173199173602
yypParser->yyerrcnt = -1;
173200173603
#endif
173201173604
yypParser->yytos = yypParser->yystack;
173202173605
yypParser->yystack[0].stateno = 0;
173203173606
yypParser->yystack[0].major = 0;
173204
-#if YYSTACKDEPTH>0
173205
- yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
173206
-#endif
173207173607
}
173208173608
173209173609
#ifndef sqlite3Parser_ENGINEALWAYSONSTACK
173210173610
/*
173211173611
** This function allocates a new parser.
@@ -173379,13 +173779,30 @@
173379173779
/*
173380173780
** Clear all secondary memory allocations from the parser
173381173781
*/
173382173782
SQLITE_PRIVATE void sqlite3ParserFinalize(void *p){
173383173783
yyParser *pParser = (yyParser*)p;
173384
- while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
173385
-#if YYSTACKDEPTH<=0
173386
- if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
173784
+
173785
+ /* In-lined version of calling yy_pop_parser_stack() for each
173786
+ ** element left in the stack */
173787
+ yyStackEntry *yytos = pParser->yytos;
173788
+ while( yytos>pParser->yystack ){
173789
+#ifndef NDEBUG
173790
+ if( yyTraceFILE ){
173791
+ fprintf(yyTraceFILE,"%sPopping %s\n",
173792
+ yyTracePrompt,
173793
+ yyTokenName[yytos->major]);
173794
+ }
173795
+#endif
173796
+ if( yytos->major>=YY_MIN_DSTRCTR ){
173797
+ yy_destructor(pParser, yytos->major, &yytos->minor);
173798
+ }
173799
+ yytos--;
173800
+ }
173801
+
173802
+#if YYGROWABLESTACK
173803
+ if( pParser->yystack!=pParser->yystk0 ) YYFREE(pParser->yystack);
173387173804
#endif
173388173805
}
173389173806
173390173807
#ifndef sqlite3Parser_ENGINEALWAYSONSTACK
173391173808
/*
@@ -173564,11 +173981,11 @@
173564173981
while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
173565173982
/* Here code is inserted which will execute if the parser
173566173983
** stack every overflows */
173567173984
/******** Begin %stack_overflow code ******************************************/
173568173985
173569
- sqlite3ErrorMsg(pParse, "parser stack overflow");
173986
+ sqlite3OomFault(pParse->db);
173570173987
/******** End %stack_overflow code ********************************************/
173571173988
sqlite3ParserARG_STORE /* Suppress warning about unused %extra_argument var */
173572173989
sqlite3ParserCTX_STORE
173573173990
}
173574173991
@@ -173608,29 +174025,23 @@
173608174025
if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
173609174026
yypParser->yyhwm++;
173610174027
assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
173611174028
}
173612174029
#endif
173613
-#if YYSTACKDEPTH>0
173614
- if( yypParser->yytos>yypParser->yystackEnd ){
173615
- yypParser->yytos--;
173616
- yyStackOverflow(yypParser);
173617
- return;
173618
- }
173619
-#else
173620
- if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
174030
+ yytos = yypParser->yytos;
174031
+ if( yytos>yypParser->yystackEnd ){
173621174032
if( yyGrowStack(yypParser) ){
173622174033
yypParser->yytos--;
173623174034
yyStackOverflow(yypParser);
173624174035
return;
173625174036
}
174037
+ yytos = yypParser->yytos;
174038
+ assert( yytos <= yypParser->yystackEnd );
173626174039
}
173627
-#endif
173628174040
if( yyNewState > YY_MAX_SHIFT ){
173629174041
yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
173630174042
}
173631
- yytos = yypParser->yytos;
173632174043
yytos->stateno = yyNewState;
173633174044
yytos->major = yyMajor;
173634174045
yytos->minor.yy0 = yyMinor;
173635174046
yyTraceShift(yypParser, yyNewState, "Shift");
173636174047
}
@@ -176208,23 +176619,16 @@
176208176619
yypParser->yyhwm++;
176209176620
assert( yypParser->yyhwm ==
176210176621
(int)(yypParser->yytos - yypParser->yystack));
176211176622
}
176212176623
#endif
176213
-#if YYSTACKDEPTH>0
176214176624
if( yypParser->yytos>=yypParser->yystackEnd ){
176215
- yyStackOverflow(yypParser);
176216
- break;
176217
- }
176218
-#else
176219
- if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
176220176625
if( yyGrowStack(yypParser) ){
176221176626
yyStackOverflow(yypParser);
176222176627
break;
176223176628
}
176224176629
}
176225
-#endif
176226176630
}
176227176631
yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor sqlite3ParserCTX_PARAM);
176228176632
}else if( yyact <= YY_MAX_SHIFTREDUCE ){
176229176633
yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
176230176634
#ifndef YYNOERRORRECOVERY
@@ -188495,26 +188899,28 @@
188495188899
const char *zTabname, /* Name of the pVTab table */
188496188900
int isQuick, /* True if this is a quick_check */
188497188901
char **pzErr /* Write error message here */
188498188902
){
188499188903
Fts3Table *p = (Fts3Table*)pVtab;
188500
- int rc;
188904
+ int rc = SQLITE_OK;
188501188905
int bOk = 0;
188502188906
188503188907
UNUSED_PARAMETER(isQuick);
188504188908
rc = sqlite3Fts3IntegrityCheck(p, &bOk);
188505
- assert( rc!=SQLITE_CORRUPT_VTAB || bOk==0 );
188506
- if( rc!=SQLITE_OK && rc!=SQLITE_CORRUPT_VTAB ){
188909
+ assert( rc!=SQLITE_CORRUPT_VTAB );
188910
+ if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){
188507188911
*pzErr = sqlite3_mprintf("unable to validate the inverted index for"
188508188912
" FTS%d table %s.%s: %s",
188509188913
p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc));
188510
- }else if( bOk==0 ){
188914
+ if( *pzErr ) rc = SQLITE_OK;
188915
+ }else if( rc==SQLITE_OK && bOk==0 ){
188511188916
*pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
188512188917
p->bFts4 ? 4 : 3, zSchema, zTabname);
188918
+ if( *pzErr==0 ) rc = SQLITE_NOMEM;
188513188919
}
188514188920
sqlite3Fts3SegmentsClose(p);
188515
- return SQLITE_OK;
188921
+ return rc;
188516188922
}
188517188923
188518188924
188519188925
188520188926
static const sqlite3_module fts3Module = {
@@ -200172,11 +200578,16 @@
200172200578
}
200173200579
200174200580
sqlite3_finalize(pStmt);
200175200581
}
200176200582
200177
- *pbOk = (rc==SQLITE_OK && cksum1==cksum2);
200583
+ if( rc==SQLITE_CORRUPT_VTAB ){
200584
+ rc = SQLITE_OK;
200585
+ *pbOk = 0;
200586
+ }else{
200587
+ *pbOk = (rc==SQLITE_OK && cksum1==cksum2);
200588
+ }
200178200589
return rc;
200179200590
}
200180200591
200181200592
/*
200182200593
** Run the integrity-check. If no error occurs and the current contents of
@@ -203796,10 +204207,44 @@
203796204207
if( p->nUsed==0 ) return;
203797204208
c = p->zBuf[p->nUsed-1];
203798204209
if( c=='[' || c=='{' ) return;
203799204210
jsonAppendChar(p, ',');
203800204211
}
204212
+
204213
+/* c is a control character. Append the canonical JSON representation
204214
+** of that control character to p.
204215
+**
204216
+** This routine assumes that the output buffer has already been enlarged
204217
+** sufficiently to hold the worst-case encoding plus a nul terminator.
204218
+*/
204219
+static void jsonAppendControlChar(JsonString *p, u8 c){
204220
+ static const char aSpecial[] = {
204221
+ 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0,
204222
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
204223
+ };
204224
+ assert( sizeof(aSpecial)==32 );
204225
+ assert( aSpecial['\b']=='b' );
204226
+ assert( aSpecial['\f']=='f' );
204227
+ assert( aSpecial['\n']=='n' );
204228
+ assert( aSpecial['\r']=='r' );
204229
+ assert( aSpecial['\t']=='t' );
204230
+ assert( c>=0 && c<sizeof(aSpecial) );
204231
+ assert( p->nUsed+7 <= p->nAlloc );
204232
+ if( aSpecial[c] ){
204233
+ p->zBuf[p->nUsed] = '\\';
204234
+ p->zBuf[p->nUsed+1] = aSpecial[c];
204235
+ p->nUsed += 2;
204236
+ }else{
204237
+ p->zBuf[p->nUsed] = '\\';
204238
+ p->zBuf[p->nUsed+1] = 'u';
204239
+ p->zBuf[p->nUsed+2] = '0';
204240
+ p->zBuf[p->nUsed+3] = '0';
204241
+ p->zBuf[p->nUsed+4] = "0123456789abcdef"[c>>4];
204242
+ p->zBuf[p->nUsed+5] = "0123456789abcdef"[c&0xf];
204243
+ p->nUsed += 6;
204244
+ }
204245
+}
203801204246
203802204247
/* Append the N-byte string in zIn to the end of the JsonString string
203803204248
** under construction. Enclose the string in double-quotes ("...") and
203804204249
** escape any double-quotes or backslash characters contained within the
203805204250
** string.
@@ -203856,39 +204301,18 @@
203856204301
z += k;
203857204302
N -= k;
203858204303
}
203859204304
c = z[0];
203860204305
if( c=='"' || c=='\\' ){
203861
- json_simple_escape:
203862204306
if( (p->nUsed+N+3 > p->nAlloc) && jsonStringGrow(p,N+3)!=0 ) return;
203863204307
p->zBuf[p->nUsed++] = '\\';
203864204308
p->zBuf[p->nUsed++] = c;
203865204309
}else if( c=='\'' ){
203866204310
p->zBuf[p->nUsed++] = c;
203867204311
}else{
203868
- static const char aSpecial[] = {
203869
- 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0,
203870
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
203871
- };
203872
- assert( sizeof(aSpecial)==32 );
203873
- assert( aSpecial['\b']=='b' );
203874
- assert( aSpecial['\f']=='f' );
203875
- assert( aSpecial['\n']=='n' );
203876
- assert( aSpecial['\r']=='r' );
203877
- assert( aSpecial['\t']=='t' );
203878
- assert( c>=0 && c<sizeof(aSpecial) );
203879
- if( aSpecial[c] ){
203880
- c = aSpecial[c];
203881
- goto json_simple_escape;
203882
- }
203883204312
if( (p->nUsed+N+7 > p->nAlloc) && jsonStringGrow(p,N+7)!=0 ) return;
203884
- p->zBuf[p->nUsed++] = '\\';
203885
- p->zBuf[p->nUsed++] = 'u';
203886
- p->zBuf[p->nUsed++] = '0';
203887
- p->zBuf[p->nUsed++] = '0';
203888
- p->zBuf[p->nUsed++] = "0123456789abcdef"[c>>4];
203889
- p->zBuf[p->nUsed++] = "0123456789abcdef"[c&0xf];
204313
+ jsonAppendControlChar(p, c);
203890204314
}
203891204315
z++;
203892204316
N--;
203893204317
}
203894204318
p->zBuf[p->nUsed++] = '"';
@@ -204585,11 +205009,14 @@
204585205009
k = j+sz;
204586205010
while( j<k ){
204587205011
if( !jsonIsOk[z[j]] && z[j]!='\'' ){
204588205012
if( z[j]=='"' ){
204589205013
if( x==JSONB_TEXTJ ) return j+1;
204590
- }else if( z[j]!='\\' || j+1>=k ){
205014
+ }else if( z[j]<=0x1f ){
205015
+ /* Control characters in JSON5 string literals are ok */
205016
+ if( x==JSONB_TEXTJ ) return j+1;
205017
+ }else if( NEVER(z[j]!='\\') || j+1>=k ){
204591205018
return j+1;
204592205019
}else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){
204593205020
j++;
204594205021
}else if( z[j+1]=='u' ){
204595205022
if( j+5>=k ) return j+1;
@@ -204783,10 +205210,11 @@
204783205210
return j+1;
204784205211
}
204785205212
case '[': {
204786205213
/* Parse array */
204787205214
iThis = pParse->nBlob;
205215
+ assert( i<=pParse->nJson );
204788205216
jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0);
204789205217
iStart = pParse->nBlob;
204790205218
if( pParse->oom ) return -1;
204791205219
if( ++pParse->iDepth > JSON_MAX_DEPTH ){
204792205220
pParse->iErr = i;
@@ -204879,13 +205307,18 @@
204879205307
}else{
204880205308
pParse->iErr = j;
204881205309
return -1;
204882205310
}
204883205311
}else if( c<=0x1f ){
204884
- /* Control characters are not allowed in strings */
204885
- pParse->iErr = j;
204886
- return -1;
205312
+ if( c==0 ){
205313
+ pParse->iErr = j;
205314
+ return -1;
205315
+ }
205316
+ /* Control characters are not allowed in canonical JSON string
205317
+ ** literals, but are allowed in JSON5 string literals. */
205318
+ opcode = JSONB_TEXT5;
205319
+ pParse->hasNonstd = 1;
204887205320
}else if( c=='"' ){
204888205321
opcode = JSONB_TEXT5;
204889205322
}
204890205323
j++;
204891205324
}
@@ -205097,10 +205530,11 @@
205097205530
if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
205098205531
jsonBlobAppendOneByte(pParse, JSONB_NULL);
205099205532
return i+4;
205100205533
}
205101205534
/* fall-through into the default case that checks for NaN */
205535
+ /* no break */ deliberate_fall_through
205102205536
}
205103205537
default: {
205104205538
u32 k;
205105205539
int nn;
205106205540
c = z[i];
@@ -205181,10 +205615,14 @@
205181205615
*/
205182205616
static void jsonReturnStringAsBlob(JsonString *pStr){
205183205617
JsonParse px;
205184205618
memset(&px, 0, sizeof(px));
205185205619
jsonStringTerminate(pStr);
205620
+ if( pStr->eErr ){
205621
+ sqlite3_result_error_nomem(pStr->pCtx);
205622
+ return;
205623
+ }
205186205624
px.zJson = pStr->zBuf;
205187205625
px.nJson = pStr->nUsed;
205188205626
px.db = sqlite3_context_db_handle(pStr->pCtx);
205189205627
(void)jsonTranslateTextToBlob(&px, 0);
205190205628
if( px.oom ){
@@ -205361,11 +205799,11 @@
205361205799
u32 k;
205362205800
u32 sz2 = sz;
205363205801
zIn = (const char*)&pParse->aBlob[i+n];
205364205802
jsonAppendChar(pOut, '"');
205365205803
while( sz2>0 ){
205366
- for(k=0; k<sz2 && zIn[k]!='\\' && zIn[k]!='"'; k++){}
205804
+ for(k=0; k<sz2 && (jsonIsOk[(u8)zIn[k]] || zIn[k]=='\''); k++){}
205367205805
if( k>0 ){
205368205806
jsonAppendRawNZ(pOut, zIn, k);
205369205807
if( k>=sz2 ){
205370205808
break;
205371205809
}
@@ -205373,10 +205811,17 @@
205373205811
sz2 -= k;
205374205812
}
205375205813
if( zIn[0]=='"' ){
205376205814
jsonAppendRawNZ(pOut, "\\\"", 2);
205377205815
zIn++;
205816
+ sz2--;
205817
+ continue;
205818
+ }
205819
+ if( zIn[0]<=0x1f ){
205820
+ if( pOut->nUsed+7>pOut->nAlloc && jsonStringGrow(pOut,7) ) break;
205821
+ jsonAppendControlChar(pOut, zIn[0]);
205822
+ zIn++;
205378205823
sz2--;
205379205824
continue;
205380205825
}
205381205826
assert( zIn[0]=='\\' );
205382205827
assert( sz2>=1 );
@@ -206506,12 +206951,13 @@
206506206951
** See for example https://sqlite.org/forum/forumpost/012136abd5292b8d
206507206952
*/
206508206953
}
206509206954
p->zJson = (char*)sqlite3_value_text(pArg);
206510206955
p->nJson = sqlite3_value_bytes(pArg);
206956
+ if( db->mallocFailed ) goto json_pfa_oom;
206511206957
if( p->nJson==0 ) goto json_pfa_malformed;
206512
- if( NEVER(p->zJson==0) ) goto json_pfa_oom;
206958
+ assert( p->zJson!=0 );
206513206959
if( jsonConvertTextToBlob(p, (flgs & JSON_KEEPERROR) ? 0 : ctx) ){
206514206960
if( flgs & JSON_KEEPERROR ){
206515206961
p->nErr = 1;
206516206962
return p;
206517206963
}else{
@@ -206673,14 +207119,14 @@
206673207119
}
206674207120
if( showContent ){
206675207121
if( sz==0 && x<=JSONB_FALSE ){
206676207122
sqlite3_str_append(pOut, "\n", 1);
206677207123
}else{
206678
- u32 i;
207124
+ u32 j;
206679207125
sqlite3_str_appendall(pOut, ": \"");
206680
- for(i=iStart+n; i<iStart+n+sz; i++){
206681
- u8 c = pParse->aBlob[i];
207126
+ for(j=iStart+n; j<iStart+n+sz; j++){
207127
+ u8 c = pParse->aBlob[j];
206682207128
if( c<0x20 || c>=0x7f ) c = '.';
206683207129
sqlite3_str_append(pOut, (char*)&c, 1);
206684207130
}
206685207131
sqlite3_str_append(pOut, "\"\n", 2);
206686207132
}
@@ -206727,15 +207173,16 @@
206727207173
sqlite3StrAccumInit(&out, 0, 0, 0, 1000000);
206728207174
p = jsonParseFuncArg(ctx, argv[0], 0);
206729207175
if( p==0 ) return;
206730207176
if( argc==1 ){
206731207177
jsonDebugPrintBlob(p, 0, p->nBlob, 0, &out);
206732
- sqlite3_result_text64(ctx, out.zText, out.nChar, SQLITE_DYNAMIC, SQLITE_UTF8);
207178
+ sqlite3_result_text64(ctx,out.zText,out.nChar,SQLITE_TRANSIENT,SQLITE_UTF8);
206733207179
}else{
206734207180
jsonShowParse(p);
206735207181
}
206736207182
jsonParseFree(p);
207183
+ sqlite3_str_reset(&out);
206737207184
}
206738207185
#endif /* SQLITE_DEBUG */
206739207186
206740207187
/****************************************************************************
206741207188
** Scalar SQL function implementations
@@ -208084,10 +208531,13 @@
208084208531
break;
208085208532
}
208086208533
case JEACH_VALUE: {
208087208534
u32 i = jsonSkipLabel(p);
208088208535
jsonReturnFromBlob(&p->sParse, i, ctx, 1);
208536
+ if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY ){
208537
+ sqlite3_result_subtype(ctx, JSON_SUBTYPE);
208538
+ }
208089208539
break;
208090208540
}
208091208541
case JEACH_TYPE: {
208092208542
u32 i = jsonSkipLabel(p);
208093208543
u8 eType = p->sParse.aBlob[i] & 0x0f;
@@ -209158,15 +209608,13 @@
209158209608
209159209609
/*
209160209610
** Clear the Rtree.pNodeBlob object
209161209611
*/
209162209612
static void nodeBlobReset(Rtree *pRtree){
209163
- if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){
209164
- sqlite3_blob *pBlob = pRtree->pNodeBlob;
209165
- pRtree->pNodeBlob = 0;
209166
- sqlite3_blob_close(pBlob);
209167
- }
209613
+ sqlite3_blob *pBlob = pRtree->pNodeBlob;
209614
+ pRtree->pNodeBlob = 0;
209615
+ sqlite3_blob_close(pBlob);
209168209616
}
209169209617
209170209618
/*
209171209619
** Obtain a reference to an r-tree node.
209172209620
*/
@@ -209206,11 +209654,10 @@
209206209654
rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, pRtree->zNodeName,
209207209655
"data", iNode, 0,
209208209656
&pRtree->pNodeBlob);
209209209657
}
209210209658
if( rc ){
209211
- nodeBlobReset(pRtree);
209212209659
*ppNode = 0;
209213209660
/* If unable to open an sqlite3_blob on the desired row, that can only
209214209661
** be because the shadow tables hold erroneous data. */
209215209662
if( rc==SQLITE_ERROR ){
209216209663
rc = SQLITE_CORRUPT_VTAB;
@@ -209266,10 +209713,11 @@
209266209713
rc = SQLITE_CORRUPT_VTAB;
209267209714
RTREE_IS_CORRUPT(pRtree);
209268209715
}
209269209716
*ppNode = pNode;
209270209717
}else{
209718
+ nodeBlobReset(pRtree);
209271209719
if( pNode ){
209272209720
pRtree->nNodeRef--;
209273209721
sqlite3_free(pNode);
209274209722
}
209275209723
*ppNode = 0;
@@ -209410,10 +209858,11 @@
209410209858
RtreeNode *pNode, /* The node from which to extract a coordinate */
209411209859
int iCell, /* The index of the cell within the node */
209412209860
int iCoord, /* Which coordinate to extract */
209413209861
RtreeCoord *pCoord /* OUT: Space to write result to */
209414209862
){
209863
+ assert( iCell<NCELL(pNode) );
209415209864
readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
209416209865
}
209417209866
209418209867
/*
209419209868
** Deserialize cell iCell of node pNode. Populate the structure pointed
@@ -209599,11 +210048,13 @@
209599210048
assert( pRtree->nCursor>0 );
209600210049
resetCursor(pCsr);
209601210050
sqlite3_finalize(pCsr->pReadAux);
209602210051
sqlite3_free(pCsr);
209603210052
pRtree->nCursor--;
209604
- nodeBlobReset(pRtree);
210053
+ if( pRtree->nCursor==0 && pRtree->inWrTrans==0 ){
210054
+ nodeBlobReset(pRtree);
210055
+ }
209605210056
return SQLITE_OK;
209606210057
}
209607210058
209608210059
/*
209609210060
** Rtree virtual table module xEof method.
@@ -210184,11 +210635,15 @@
210184210635
RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
210185210636
RtreeSearchPoint *p = rtreeSearchPointFirst(pCsr);
210186210637
int rc = SQLITE_OK;
210187210638
RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
210188210639
if( rc==SQLITE_OK && ALWAYS(p) ){
210189
- *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
210640
+ if( p->iCell>=NCELL(pNode) ){
210641
+ rc = SQLITE_ABORT;
210642
+ }else{
210643
+ *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
210644
+ }
210190210645
}
210191210646
return rc;
210192210647
}
210193210648
210194210649
/*
@@ -210202,10 +210657,11 @@
210202210657
int rc = SQLITE_OK;
210203210658
RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
210204210659
210205210660
if( rc ) return rc;
210206210661
if( NEVER(p==0) ) return SQLITE_OK;
210662
+ if( p->iCell>=NCELL(pNode) ) return SQLITE_ABORT;
210207210663
if( i==0 ){
210208210664
sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
210209210665
}else if( i<=pRtree->nDim2 ){
210210210666
nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
210211210667
#ifndef SQLITE_RTREE_INT_ONLY
@@ -211684,11 +212140,11 @@
211684212140
** Called when a transaction starts.
211685212141
*/
211686212142
static int rtreeBeginTransaction(sqlite3_vtab *pVtab){
211687212143
Rtree *pRtree = (Rtree *)pVtab;
211688212144
assert( pRtree->inWrTrans==0 );
211689
- pRtree->inWrTrans++;
212145
+ pRtree->inWrTrans = 1;
211690212146
return SQLITE_OK;
211691212147
}
211692212148
211693212149
/*
211694212150
** Called when a transaction completes (either by COMMIT or ROLLBACK).
@@ -211697,10 +212153,13 @@
211697212153
static int rtreeEndTransaction(sqlite3_vtab *pVtab){
211698212154
Rtree *pRtree = (Rtree *)pVtab;
211699212155
pRtree->inWrTrans = 0;
211700212156
nodeBlobReset(pRtree);
211701212157
return SQLITE_OK;
212158
+}
212159
+static int rtreeRollback(sqlite3_vtab *pVtab){
212160
+ return rtreeEndTransaction(pVtab);
211702212161
}
211703212162
211704212163
/*
211705212164
** The xRename method for rtree module virtual tables.
211706212165
*/
@@ -211816,11 +212275,11 @@
211816212275
rtreeRowid, /* xRowid - read data */
211817212276
rtreeUpdate, /* xUpdate - write data */
211818212277
rtreeBeginTransaction, /* xBegin - begin transaction */
211819212278
rtreeEndTransaction, /* xSync - sync transaction */
211820212279
rtreeEndTransaction, /* xCommit - commit transaction */
211821
- rtreeEndTransaction, /* xRollback - rollback transaction */
212280
+ rtreeRollback, /* xRollback - rollback transaction */
211822212281
0, /* xFindFunction - function overloading */
211823212282
rtreeRename, /* xRename - rename the table */
211824212283
rtreeSavepoint, /* xSavepoint */
211825212284
0, /* xRelease */
211826212285
0, /* xRollbackTo */
@@ -231114,10 +231573,13 @@
231114231573
** sqlite3Fts5ParserARG_PDECL A parameter declaration for the %extra_argument
231115231574
** sqlite3Fts5ParserARG_PARAM Code to pass %extra_argument as a subroutine parameter
231116231575
** sqlite3Fts5ParserARG_STORE Code to store %extra_argument into fts5yypParser
231117231576
** sqlite3Fts5ParserARG_FETCH Code to extract %extra_argument from fts5yypParser
231118231577
** sqlite3Fts5ParserCTX_* As sqlite3Fts5ParserARG_ except for %extra_context
231578
+** fts5YYREALLOC Name of the realloc() function to use
231579
+** fts5YYFREE Name of the free() function to use
231580
+** fts5YYDYNSTACK True if stack space should be extended on heap
231119231581
** fts5YYERRORSYMBOL is the code number of the error symbol. If not
231120231582
** defined, then do no error processing.
231121231583
** fts5YYNSTATE the combined number of states.
231122231584
** fts5YYNRULE the number of rules in the grammar
231123231585
** fts5YYNFTS5TOKEN Number of terminal symbols
@@ -231127,10 +231589,12 @@
231127231589
** fts5YY_ERROR_ACTION The fts5yy_action[] code for syntax error
231128231590
** fts5YY_ACCEPT_ACTION The fts5yy_action[] code for accept
231129231591
** fts5YY_NO_ACTION The fts5yy_action[] code for no-op
231130231592
** fts5YY_MIN_REDUCE Minimum value for reduce actions
231131231593
** fts5YY_MAX_REDUCE Maximum value for reduce actions
231594
+** fts5YY_MIN_DSTRCTR Minimum symbol value that has a destructor
231595
+** fts5YY_MAX_DSTRCTR Maximum symbol value that has a destructor
231132231596
*/
231133231597
#ifndef INTERFACE
231134231598
# define INTERFACE 1
231135231599
#endif
231136231600
/************* Begin control #defines *****************************************/
@@ -231153,10 +231617,13 @@
231153231617
#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
231154231618
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
231155231619
#define sqlite3Fts5ParserARG_PARAM ,pParse
231156231620
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse=fts5yypParser->pParse;
231157231621
#define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse=pParse;
231622
+#define fts5YYREALLOC realloc
231623
+#define fts5YYFREE free
231624
+#define fts5YYDYNSTACK 0
231158231625
#define sqlite3Fts5ParserCTX_SDECL
231159231626
#define sqlite3Fts5ParserCTX_PDECL
231160231627
#define sqlite3Fts5ParserCTX_PARAM
231161231628
#define sqlite3Fts5ParserCTX_FETCH
231162231629
#define sqlite3Fts5ParserCTX_STORE
@@ -231170,10 +231637,12 @@
231170231637
#define fts5YY_ERROR_ACTION 80
231171231638
#define fts5YY_ACCEPT_ACTION 81
231172231639
#define fts5YY_NO_ACTION 82
231173231640
#define fts5YY_MIN_REDUCE 83
231174231641
#define fts5YY_MAX_REDUCE 110
231642
+#define fts5YY_MIN_DSTRCTR 16
231643
+#define fts5YY_MAX_DSTRCTR 24
231175231644
/************* End control #defines *******************************************/
231176231645
#define fts5YY_NLOOKAHEAD ((int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])))
231177231646
231178231647
/* Define the fts5yytestcase() macro to be a no-op if is not already defined
231179231648
** otherwise.
@@ -231184,10 +231653,26 @@
231184231653
** for testing.
231185231654
*/
231186231655
#ifndef fts5yytestcase
231187231656
# define fts5yytestcase(X)
231188231657
#endif
231658
+
231659
+/* Macro to determine if stack space has the ability to grow using
231660
+** heap memory.
231661
+*/
231662
+#if fts5YYSTACKDEPTH<=0 || fts5YYDYNSTACK
231663
+# define fts5YYGROWABLESTACK 1
231664
+#else
231665
+# define fts5YYGROWABLESTACK 0
231666
+#endif
231667
+
231668
+/* Guarantee a minimum number of initial stack slots.
231669
+*/
231670
+#if fts5YYSTACKDEPTH<=0
231671
+# undef fts5YYSTACKDEPTH
231672
+# define fts5YYSTACKDEPTH 2 /* Need a minimum stack size */
231673
+#endif
231189231674
231190231675
231191231676
/* Next are the tables used to determine what action to take based on the
231192231677
** current state and lookahead token. These tables are used to implement
231193231678
** functions that take a state number and lookahead value and return an
@@ -231345,18 +231830,13 @@
231345231830
#ifndef fts5YYNOERRORRECOVERY
231346231831
int fts5yyerrcnt; /* Shifts left before out of the error */
231347231832
#endif
231348231833
sqlite3Fts5ParserARG_SDECL /* A place to hold %extra_argument */
231349231834
sqlite3Fts5ParserCTX_SDECL /* A place to hold %extra_context */
231350
-#if fts5YYSTACKDEPTH<=0
231351
- int fts5yystksz; /* Current side of the stack */
231352
- fts5yyStackEntry *fts5yystack; /* The parser's stack */
231353
- fts5yyStackEntry fts5yystk0; /* First stack entry */
231354
-#else
231355
- fts5yyStackEntry fts5yystack[fts5YYSTACKDEPTH]; /* The parser's stack */
231356
- fts5yyStackEntry *fts5yystackEnd; /* Last entry in the stack */
231357
-#endif
231835
+ fts5yyStackEntry *fts5yystackEnd; /* Last entry in the stack */
231836
+ fts5yyStackEntry *fts5yystack; /* The parser stack */
231837
+ fts5yyStackEntry fts5yystk0[fts5YYSTACKDEPTH]; /* Initial stack space */
231358231838
};
231359231839
typedef struct fts5yyParser fts5yyParser;
231360231840
231361231841
/* #include <assert.h> */
231362231842
#ifndef NDEBUG
@@ -231459,41 +231939,49 @@
231459231939
/* 27 */ "star_opt ::=",
231460231940
};
231461231941
#endif /* NDEBUG */
231462231942
231463231943
231464
-#if fts5YYSTACKDEPTH<=0
231944
+#if fts5YYGROWABLESTACK
231465231945
/*
231466231946
** Try to increase the size of the parser stack. Return the number
231467231947
** of errors. Return 0 on success.
231468231948
*/
231469231949
static int fts5yyGrowStack(fts5yyParser *p){
231950
+ int oldSize = 1 + (int)(p->fts5yystackEnd - p->fts5yystack);
231470231951
int newSize;
231471231952
int idx;
231472231953
fts5yyStackEntry *pNew;
231473231954
231474
- newSize = p->fts5yystksz*2 + 100;
231475
- idx = p->fts5yytos ? (int)(p->fts5yytos - p->fts5yystack) : 0;
231476
- if( p->fts5yystack==&p->fts5yystk0 ){
231477
- pNew = malloc(newSize*sizeof(pNew[0]));
231478
- if( pNew ) pNew[0] = p->fts5yystk0;
231955
+ newSize = oldSize*2 + 100;
231956
+ idx = (int)(p->fts5yytos - p->fts5yystack);
231957
+ if( p->fts5yystack==p->fts5yystk0 ){
231958
+ pNew = fts5YYREALLOC(0, newSize*sizeof(pNew[0]));
231959
+ if( pNew==0 ) return 1;
231960
+ memcpy(pNew, p->fts5yystack, oldSize*sizeof(pNew[0]));
231479231961
}else{
231480
- pNew = realloc(p->fts5yystack, newSize*sizeof(pNew[0]));
231962
+ pNew = fts5YYREALLOC(p->fts5yystack, newSize*sizeof(pNew[0]));
231963
+ if( pNew==0 ) return 1;
231481231964
}
231482
- if( pNew ){
231483
- p->fts5yystack = pNew;
231484
- p->fts5yytos = &p->fts5yystack[idx];
231965
+ p->fts5yystack = pNew;
231966
+ p->fts5yytos = &p->fts5yystack[idx];
231485231967
#ifndef NDEBUG
231486
- if( fts5yyTraceFILE ){
231487
- fprintf(fts5yyTraceFILE,"%sStack grows from %d to %d entries.\n",
231488
- fts5yyTracePrompt, p->fts5yystksz, newSize);
231489
- }
231968
+ if( fts5yyTraceFILE ){
231969
+ fprintf(fts5yyTraceFILE,"%sStack grows from %d to %d entries.\n",
231970
+ fts5yyTracePrompt, oldSize, newSize);
231971
+ }
231490231972
#endif
231491
- p->fts5yystksz = newSize;
231492
- }
231493
- return pNew==0;
231973
+ p->fts5yystackEnd = &p->fts5yystack[newSize-1];
231974
+ return 0;
231494231975
}
231976
+#endif /* fts5YYGROWABLESTACK */
231977
+
231978
+#if !fts5YYGROWABLESTACK
231979
+/* For builds that do no have a growable stack, fts5yyGrowStack always
231980
+** returns an error.
231981
+*/
231982
+# define fts5yyGrowStack(X) 1
231495231983
#endif
231496231984
231497231985
/* Datatype of the argument to the memory allocated passed as the
231498231986
** second argument to sqlite3Fts5ParserAlloc() below. This can be changed by
231499231987
** putting an appropriate #define in the %include section of the input
@@ -231509,28 +231997,18 @@
231509231997
fts5yyParser *fts5yypParser = (fts5yyParser*)fts5yypRawParser;
231510231998
sqlite3Fts5ParserCTX_STORE
231511231999
#ifdef fts5YYTRACKMAXSTACKDEPTH
231512232000
fts5yypParser->fts5yyhwm = 0;
231513232001
#endif
231514
-#if fts5YYSTACKDEPTH<=0
231515
- fts5yypParser->fts5yytos = NULL;
231516
- fts5yypParser->fts5yystack = NULL;
231517
- fts5yypParser->fts5yystksz = 0;
231518
- if( fts5yyGrowStack(fts5yypParser) ){
231519
- fts5yypParser->fts5yystack = &fts5yypParser->fts5yystk0;
231520
- fts5yypParser->fts5yystksz = 1;
231521
- }
231522
-#endif
232002
+ fts5yypParser->fts5yystack = fts5yypParser->fts5yystk0;
232003
+ fts5yypParser->fts5yystackEnd = &fts5yypParser->fts5yystack[fts5YYSTACKDEPTH-1];
231523232004
#ifndef fts5YYNOERRORRECOVERY
231524232005
fts5yypParser->fts5yyerrcnt = -1;
231525232006
#endif
231526232007
fts5yypParser->fts5yytos = fts5yypParser->fts5yystack;
231527232008
fts5yypParser->fts5yystack[0].stateno = 0;
231528232009
fts5yypParser->fts5yystack[0].major = 0;
231529
-#if fts5YYSTACKDEPTH>0
231530
- fts5yypParser->fts5yystackEnd = &fts5yypParser->fts5yystack[fts5YYSTACKDEPTH-1];
231531
-#endif
231532232010
}
231533232011
231534232012
#ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
231535232013
/*
231536232014
** This function allocates a new parser.
@@ -231640,13 +232118,30 @@
231640232118
/*
231641232119
** Clear all secondary memory allocations from the parser
231642232120
*/
231643232121
static void sqlite3Fts5ParserFinalize(void *p){
231644232122
fts5yyParser *pParser = (fts5yyParser*)p;
231645
- while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser);
231646
-#if fts5YYSTACKDEPTH<=0
231647
- if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack);
232123
+
232124
+ /* In-lined version of calling fts5yy_pop_parser_stack() for each
232125
+ ** element left in the stack */
232126
+ fts5yyStackEntry *fts5yytos = pParser->fts5yytos;
232127
+ while( fts5yytos>pParser->fts5yystack ){
232128
+#ifndef NDEBUG
232129
+ if( fts5yyTraceFILE ){
232130
+ fprintf(fts5yyTraceFILE,"%sPopping %s\n",
232131
+ fts5yyTracePrompt,
232132
+ fts5yyTokenName[fts5yytos->major]);
232133
+ }
232134
+#endif
232135
+ if( fts5yytos->major>=fts5YY_MIN_DSTRCTR ){
232136
+ fts5yy_destructor(pParser, fts5yytos->major, &fts5yytos->minor);
232137
+ }
232138
+ fts5yytos--;
232139
+ }
232140
+
232141
+#if fts5YYGROWABLESTACK
232142
+ if( pParser->fts5yystack!=pParser->fts5yystk0 ) fts5YYFREE(pParser->fts5yystack);
231648232143
#endif
231649232144
}
231650232145
231651232146
#ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
231652232147
/*
@@ -231869,29 +232364,23 @@
231869232364
if( (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack)>fts5yypParser->fts5yyhwm ){
231870232365
fts5yypParser->fts5yyhwm++;
231871232366
assert( fts5yypParser->fts5yyhwm == (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack) );
231872232367
}
231873232368
#endif
231874
-#if fts5YYSTACKDEPTH>0
231875
- if( fts5yypParser->fts5yytos>fts5yypParser->fts5yystackEnd ){
231876
- fts5yypParser->fts5yytos--;
231877
- fts5yyStackOverflow(fts5yypParser);
231878
- return;
231879
- }
231880
-#else
231881
- if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5yypParser->fts5yystksz] ){
232369
+ fts5yytos = fts5yypParser->fts5yytos;
232370
+ if( fts5yytos>fts5yypParser->fts5yystackEnd ){
231882232371
if( fts5yyGrowStack(fts5yypParser) ){
231883232372
fts5yypParser->fts5yytos--;
231884232373
fts5yyStackOverflow(fts5yypParser);
231885232374
return;
231886232375
}
232376
+ fts5yytos = fts5yypParser->fts5yytos;
232377
+ assert( fts5yytos <= fts5yypParser->fts5yystackEnd );
231887232378
}
231888
-#endif
231889232379
if( fts5yyNewState > fts5YY_MAX_SHIFT ){
231890232380
fts5yyNewState += fts5YY_MIN_REDUCE - fts5YY_MIN_SHIFTREDUCE;
231891232381
}
231892
- fts5yytos = fts5yypParser->fts5yytos;
231893232382
fts5yytos->stateno = fts5yyNewState;
231894232383
fts5yytos->major = fts5yyMajor;
231895232384
fts5yytos->minor.fts5yy0 = fts5yyMinor;
231896232385
fts5yyTraceShift(fts5yypParser, fts5yyNewState, "Shift");
231897232386
}
@@ -232324,23 +232813,16 @@
232324232813
fts5yypParser->fts5yyhwm++;
232325232814
assert( fts5yypParser->fts5yyhwm ==
232326232815
(int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack));
232327232816
}
232328232817
#endif
232329
-#if fts5YYSTACKDEPTH>0
232330232818
if( fts5yypParser->fts5yytos>=fts5yypParser->fts5yystackEnd ){
232331
- fts5yyStackOverflow(fts5yypParser);
232332
- break;
232333
- }
232334
-#else
232335
- if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5yypParser->fts5yystksz-1] ){
232336232819
if( fts5yyGrowStack(fts5yypParser) ){
232337232820
fts5yyStackOverflow(fts5yypParser);
232338232821
break;
232339232822
}
232340232823
}
232341
-#endif
232342232824
}
232343232825
fts5yyact = fts5yy_reduce(fts5yypParser,fts5yyruleno,fts5yymajor,fts5yyminor sqlite3Fts5ParserCTX_PARAM);
232344232826
}else if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
232345232827
fts5yy_shift(fts5yypParser,fts5yyact,(fts5YYCODETYPE)fts5yymajor,fts5yyminor);
232346232828
#ifndef fts5YYNOERRORRECOVERY
@@ -245375,27 +245857,30 @@
245375245857
** a rowid of iFrom or greater.
245376245858
*/
245377245859
static void fts5TokendataIterNext(Fts5Iter *pIter, int bFrom, i64 iFrom){
245378245860
int ii;
245379245861
Fts5TokenDataIter *pT = pIter->pTokenDataIter;
245862
+ Fts5Index *pIndex = pIter->pIndex;
245380245863
245381245864
for(ii=0; ii<pT->nIter; ii++){
245382245865
Fts5Iter *p = pT->apIter[ii];
245383245866
if( p->base.bEof==0
245384245867
&& (p->base.iRowid==pIter->base.iRowid || (bFrom && p->base.iRowid<iFrom))
245385245868
){
245386
- fts5MultiIterNext(p->pIndex, p, bFrom, iFrom);
245869
+ fts5MultiIterNext(pIndex, p, bFrom, iFrom);
245387245870
while( bFrom && p->base.bEof==0
245388245871
&& p->base.iRowid<iFrom
245389
- && p->pIndex->rc==SQLITE_OK
245872
+ && pIndex->rc==SQLITE_OK
245390245873
){
245391
- fts5MultiIterNext(p->pIndex, p, 0, 0);
245874
+ fts5MultiIterNext(pIndex, p, 0, 0);
245392245875
}
245393245876
}
245394245877
}
245395245878
245396
- fts5IterSetOutputsTokendata(pIter);
245879
+ if( pIndex->rc==SQLITE_OK ){
245880
+ fts5IterSetOutputsTokendata(pIter);
245881
+ }
245397245882
}
245398245883
245399245884
/*
245400245885
** If the segment-iterator passed as the first argument is at EOF, then
245401245886
** set pIter->term to a copy of buffer pTerm.
@@ -250545,11 +251030,11 @@
250545251030
int nArg, /* Number of args */
250546251031
sqlite3_value **apUnused /* Function arguments */
250547251032
){
250548251033
assert( nArg==0 );
250549251034
UNUSED_PARAM2(nArg, apUnused);
250550
- sqlite3_result_text(pCtx, "fts5: 2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a", -1, SQLITE_TRANSIENT);
251035
+ sqlite3_result_text(pCtx, "fts5: 2024-02-20 12:14:07 6c5a0c85454e3c658e51fab611c169c034447174022eebc52fd8619b528a4765", -1, SQLITE_TRANSIENT);
250551251036
}
250552251037
250553251038
/*
250554251039
** Return true if zName is the extension on one of the shadow tables used
250555251040
** by this module.
@@ -250584,18 +251069,19 @@
250584251069
UNUSED_PARAM(isQuick);
250585251070
rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0);
250586251071
if( (rc&0xff)==SQLITE_CORRUPT ){
250587251072
*pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
250588251073
zSchema, zTabname);
251074
+ rc = (*pzErr) ? SQLITE_OK : SQLITE_NOMEM;
250589251075
}else if( rc!=SQLITE_OK ){
250590251076
*pzErr = sqlite3_mprintf("unable to validate the inverted index for"
250591251077
" FTS5 table %s.%s: %s",
250592251078
zSchema, zTabname, sqlite3_errstr(rc));
250593251079
}
250594251080
sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
250595251081
250596
- return SQLITE_OK;
251082
+ return rc;
250597251083
}
250598251084
250599251085
static int fts5Init(sqlite3 *db){
250600251086
static const sqlite3_module fts5Mod = {
250601251087
/* iVersion */ 4,
250602251088
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.45.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -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 ** e876e51a0ed5c5b3126f52e532044363a014.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -457,13 +457,13 @@
457 **
458 ** See also: [sqlite3_libversion()],
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.45.1"
463 #define SQLITE_VERSION_NUMBER 3045001
464 #define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -731,10 +731,12 @@
731 ** is a valid and open [database connection].
732 ** <li> The application must not close the [database connection] specified by
733 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
734 ** <li> The application must not modify the SQL statement text passed into
735 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
 
 
736 ** </ul>
737 */
738 SQLITE_API int sqlite3_exec(
739 sqlite3*, /* An open database */
740 const char *sql, /* SQL to be evaluated */
@@ -14858,11 +14860,11 @@
14858 #ifndef SQLITE_PTRSIZE
14859 # if defined(__SIZEOF_POINTER__)
14860 # define SQLITE_PTRSIZE __SIZEOF_POINTER__
14861 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
14862 defined(_M_ARM) || defined(__arm__) || defined(__x86) || \
14863 (defined(__APPLE__) && defined(__POWERPC__)) || \
14864 (defined(__TOS_AIX__) && !defined(__64BIT__))
14865 # define SQLITE_PTRSIZE 4
14866 # else
14867 # define SQLITE_PTRSIZE 8
14868 # endif
@@ -16569,11 +16571,11 @@
16569 #define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
16570 #define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
16571 #define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
16572 #define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
16573 #define OP_Last 32 /* jump */
16574 #define OP_IfSmaller 33 /* jump */
16575 #define OP_SorterSort 34 /* jump */
16576 #define OP_Sort 35 /* jump */
16577 #define OP_Rewind 36 /* jump */
16578 #define OP_SorterNext 37 /* jump */
16579 #define OP_Prev 38 /* jump */
@@ -17492,10 +17494,14 @@
17492 struct FuncDefHash {
17493 FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */
17494 };
17495 #define SQLITE_FUNC_HASH(C,L) (((C)+(L))%SQLITE_FUNC_HASH_SZ)
17496
 
 
 
 
17497 #ifdef SQLITE_USER_AUTHENTICATION
17498 /*
17499 ** Information held in the "sqlite3" database connection object and used
17500 ** to manage user authentication.
17501 */
@@ -18368,12 +18374,11 @@
18368 #define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */
18369 #define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */
18370 #define TF_HasStored 0x00000040 /* Has one or more STORED columns */
18371 #define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */
18372 #define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */
18373 #define TF_StatsUsed 0x00000100 /* Query planner decisions affected by
18374 ** Index.aiRowLogEst[] values */
18375 #define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */
18376 #define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */
18377 #define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */
18378 #define TF_Shadow 0x00001000 /* True for a shadow table */
18379 #define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
@@ -25336,27 +25341,88 @@
25336 }else{
25337 sqlite3_result_text(context, &zBuf[1], 10, SQLITE_TRANSIENT);
25338 }
25339 }
25340 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25341
25342 /*
25343 ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
25344 **
25345 ** Return a string described by FORMAT. Conversions as follows:
25346 **
25347 ** %d day of month
 
25348 ** %f ** fractional seconds SS.SSS
 
 
 
25349 ** %H hour 00-24
25350 ** %j day of year 000-366
 
 
25351 ** %J ** julian day number
 
25352 ** %m month 01-12
25353 ** %M minute 00-59
 
 
 
25354 ** %s seconds since 1970-01-01
25355 ** %S seconds 00-59
25356 ** %w day of week 0-6 Sunday==0
25357 ** %W week of year 00-53
 
 
 
 
25358 ** %Y year 0000-9999
25359 ** %% %
25360 */
25361 static void strftimeFunc(
25362 sqlite3_context *context,
@@ -25389,19 +25455,34 @@
25389 case 'd': /* Fall thru */
25390 case 'e': {
25391 sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D);
25392 break;
25393 }
25394 case 'f': {
25395 double s = x.s;
25396 if( s>59.999 ) s = 59.999;
25397 sqlite3_str_appendf(&sRes, "%06.3f", s);
25398 break;
25399 }
25400 case 'F': {
25401 sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
25402 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25403 }
25404 case 'H':
25405 case 'k': {
25406 sqlite3_str_appendf(&sRes, cf=='H' ? "%02d" : "%2d", x.h);
25407 break;
@@ -25412,29 +25493,15 @@
25412 if( h>12 ) h -= 12;
25413 if( h==0 ) h = 12;
25414 sqlite3_str_appendf(&sRes, cf=='I' ? "%02d" : "%2d", h);
25415 break;
25416 }
25417 case 'W': /* Fall thru */
25418 case 'j': {
25419 int nDay; /* Number of days since 1st day of year */
25420 DateTime y = x;
25421 y.validJD = 0;
25422 y.M = 1;
25423 y.D = 1;
25424 computeJD(&y);
25425 nDay = (int)((x.iJD-y.iJD+43200000)/86400000);
25426 if( cf=='W' ){
25427 int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
25428 wd = (int)(((x.iJD+43200000)/86400000)%7);
25429 sqlite3_str_appendf(&sRes,"%02d",(nDay+7-wd)/7);
25430 }else{
25431 sqlite3_str_appendf(&sRes,"%03d",nDay+1);
25432 }
25433 break;
25434 }
25435 case 'J': {
25436 sqlite3_str_appendf(&sRes,"%.16g",x.iJD/86400000.0);
25437 break;
25438 }
25439 case 'm': {
25440 sqlite3_str_appendf(&sRes,"%02d",x.M);
@@ -25473,16 +25540,36 @@
25473 }
25474 case 'T': {
25475 sqlite3_str_appendf(&sRes,"%02d:%02d:%02d", x.h, x.m, (int)x.s);
25476 break;
25477 }
25478 case 'u': /* Fall thru */
25479 case 'w': {
25480 char c = (char)(((x.iJD+129600000)/86400000) % 7) + '0';
25481 if( c=='0' && cf=='u' ) c = '7';
25482 sqlite3_str_appendchar(&sRes, 1, c);
25483 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25484 }
25485 case 'Y': {
25486 sqlite3_str_appendf(&sRes,"%04d",x.Y);
25487 break;
25488 }
@@ -30127,10 +30214,28 @@
30127 sqlite3_mutex_leave(mem0.mutex);
30128 sqlite3_release_memory(nByte);
30129 sqlite3_mutex_enter(mem0.mutex);
30130 }
30131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30132 /*
30133 ** Do a memory allocation with statistics and alarms. Assume the
30134 ** lock is already held.
30135 */
30136 static void mallocWithAlarm(int n, void **pp){
@@ -30153,10 +30258,11 @@
30153 AtomicStore(&mem0.nearlyFull, 1);
30154 sqlite3MallocAlarm(nFull);
30155 if( mem0.hardLimit ){
30156 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
30157 if( nUsed >= mem0.hardLimit - nFull ){
 
30158 *pp = 0;
30159 return;
30160 }
30161 }
30162 }else{
@@ -30441,10 +30547,11 @@
30441 if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >=
30442 mem0.alarmThreshold-nDiff ){
30443 sqlite3MallocAlarm(nDiff);
30444 if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){
30445 sqlite3_mutex_leave(mem0.mutex);
 
30446 return 0;
30447 }
30448 }
30449 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
30450 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
@@ -31307,10 +31414,11 @@
31307 }
31308 #endif
31309 if( xtype==etFLOAT ){
31310 iRound = -precision;
31311 }else if( xtype==etGENERIC ){
 
31312 iRound = precision;
31313 }else{
31314 iRound = precision+1;
31315 }
31316 sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 26 : 16);
@@ -31342,17 +31450,18 @@
31342 }else{
31343 prefix = flag_prefix;
31344 }
31345
31346 exp = s.iDP-1;
31347 if( xtype==etGENERIC && precision>0 ) precision--;
31348
31349 /*
31350 ** If the field type is etGENERIC, then convert to either etEXP
31351 ** or etFLOAT, as appropriate.
31352 */
31353 if( xtype==etGENERIC ){
 
 
31354 flag_rtz = !flag_alternateform;
31355 if( exp<-4 || exp>precision ){
31356 xtype = etEXP;
31357 }else{
31358 precision = precision - exp;
@@ -35639,11 +35748,11 @@
35639 assert( i>=0 && i<sizeof(p->zBuf)-1 );
35640 p->n = sizeof(p->zBuf) - 1 - i;
35641 assert( p->n>0 );
35642 assert( p->n<sizeof(p->zBuf) );
35643 p->iDP = p->n + exp;
35644 if( iRound<0 ){
35645 iRound = p->iDP - iRound;
35646 if( iRound==0 && p->zBuf[i+1]>='5' ){
35647 iRound = 1;
35648 p->zBuf[i--] = '0';
35649 p->n++;
@@ -36817,11 +36926,11 @@
36817 /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
36818 /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
36819 /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
36820 /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
36821 /* 32 */ "Last" OpHelp(""),
36822 /* 33 */ "IfSmaller" OpHelp(""),
36823 /* 34 */ "SorterSort" OpHelp(""),
36824 /* 35 */ "Sort" OpHelp(""),
36825 /* 36 */ "Rewind" OpHelp(""),
36826 /* 37 */ "SorterNext" OpHelp(""),
36827 /* 38 */ "Prev" OpHelp(""),
@@ -39260,12 +39369,16 @@
39260 **
39261 ** If the code incorrectly assumes that it is the POSIX version that is
39262 ** available, the error message will often be an empty string. Not a
39263 ** huge problem. Incorrectly concluding that the GNU version is available
39264 ** could lead to a segfault though.
 
 
 
39265 */
39266 #if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
 
39267 zErr =
39268 # endif
39269 strerror_r(iErrno, aErr, sizeof(aErr)-1);
39270
39271 #elif SQLITE_THREADSAFE
@@ -53260,10 +53373,18 @@
53260 rc = sqlite3_step(pStmt);
53261 if( rc!=SQLITE_ROW ){
53262 pOut = 0;
53263 }else{
53264 sz = sqlite3_column_int64(pStmt, 0)*szPage;
 
 
 
 
 
 
 
 
53265 if( piSize ) *piSize = sz;
53266 if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
53267 pOut = 0;
53268 }else{
53269 pOut = sqlite3_malloc64( sz );
@@ -70281,12 +70402,51 @@
70281 # define SQLITE_CORRUPT_PAGE(pMemPage) corruptPageError(__LINE__, pMemPage)
70282 #else
70283 # define SQLITE_CORRUPT_PAGE(pMemPage) SQLITE_CORRUPT_PGNO(pMemPage->pgno)
70284 #endif
70285
 
 
 
 
 
 
70286 #ifndef SQLITE_OMIT_SHARED_CACHE
70287
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70288 #ifdef SQLITE_DEBUG
70289 /*
70290 **** This function is only used as part of an assert() statement. ***
70291 **
70292 ** Check to see if pBtree holds the required locks to read or write to the
@@ -70358,10 +70518,12 @@
70358 }
70359 }
70360 }else{
70361 iTab = iRoot;
70362 }
 
 
70363
70364 /* Search for the required lock. Either a write-lock on root-page iTab, a
70365 ** write-lock on the schema table, or (if the client is reading) a
70366 ** read-lock on iTab will suffice. Return 1 if any of these are found. */
70367 for(pLock=pBtree->pBt->pLock; pLock; pLock=pLock->pNext){
@@ -70492,10 +70654,12 @@
70492 static int setSharedCacheTableLock(Btree *p, Pgno iTable, u8 eLock){
70493 BtShared *pBt = p->pBt;
70494 BtLock *pLock = 0;
70495 BtLock *pIter;
70496
 
 
70497 assert( sqlite3BtreeHoldsMutex(p) );
70498 assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
70499 assert( p->db!=0 );
70500
70501 /* A connection with the read-uncommitted flag set will never try to
@@ -70559,10 +70723,12 @@
70559
70560 assert( sqlite3BtreeHoldsMutex(p) );
70561 assert( p->sharable || 0==*ppIter );
70562 assert( p->inTrans>0 );
70563
 
 
70564 while( *ppIter ){
70565 BtLock *pLock = *ppIter;
70566 assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
70567 assert( pLock->pBtree->inTrans>=pLock->eLock );
70568 if( pLock->pBtree==p ){
@@ -70597,10 +70763,13 @@
70597 /*
70598 ** This function changes all write-locks held by Btree p into read-locks.
70599 */
70600 static void downgradeAllSharedCacheTableLocks(Btree *p){
70601 BtShared *pBt = p->pBt;
 
 
 
70602 if( pBt->pWriter==p ){
70603 BtLock *pLock;
70604 pBt->pWriter = 0;
70605 pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
70606 for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
@@ -75210,13 +75379,16 @@
75210 if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
75211 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
75212 if( pCur->aOverflow==0
75213 || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow)
75214 ){
75215 Pgno *aNew = (Pgno*)sqlite3Realloc(
75216 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
75217 );
 
 
 
75218 if( aNew==0 ){
75219 return SQLITE_NOMEM_BKPT;
75220 }else{
75221 pCur->aOverflow = aNew;
75222 }
@@ -76261,14 +76433,14 @@
76261 u8 i;
76262
76263 assert( cursorOwnsBtShared(pCur) );
76264 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
76265
76266 /* Currently this interface is only called by the OP_IfSmaller
76267 ** opcode, and it that case the cursor will always be valid and
76268 ** will always point to a leaf node. */
76269 if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1;
76270 if( NEVER(pCur->pPage->leaf==0) ) return -1;
76271
76272 n = pCur->pPage->nCell;
76273 for(i=0; i<pCur->iPage; i++){
76274 n *= pCur->apPage[i]->nCell;
@@ -78392,11 +78564,11 @@
78392
78393 /* Verify that all sibling pages are of the same "type" (table-leaf,
78394 ** table-interior, index-leaf, or index-interior).
78395 */
78396 if( pOld->aData[0]!=apOld[0]->aData[0] ){
78397 rc = SQLITE_CORRUPT_BKPT;
78398 goto balance_cleanup;
78399 }
78400
78401 /* Load b.apCell[] with pointers to all cells in pOld. If pOld
78402 ** contains overflow cells, include them in the b.apCell[] array
@@ -78416,11 +78588,11 @@
78416 ** first.
78417 */
78418 memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow));
78419 if( pOld->nOverflow>0 ){
78420 if( NEVER(limit<pOld->aiOvfl[0]) ){
78421 rc = SQLITE_CORRUPT_BKPT;
78422 goto balance_cleanup;
78423 }
78424 limit = pOld->aiOvfl[0];
78425 for(j=0; j<limit; j++){
78426 b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
@@ -79059,11 +79231,11 @@
79059 for(pOther=pCur->pBt->pCursor; pOther; pOther=pOther->pNext){
79060 if( pOther!=pCur
79061 && pOther->eState==CURSOR_VALID
79062 && pOther->pPage==pCur->pPage
79063 ){
79064 return SQLITE_CORRUPT_BKPT;
79065 }
79066 }
79067 return SQLITE_OK;
79068 }
79069
@@ -79119,11 +79291,11 @@
79119 }
79120 }else if( sqlite3PagerPageRefcount(pPage->pDbPage)>1 ){
79121 /* The page being written is not a root page, and there is currently
79122 ** more than one reference to it. This only happens if the page is one
79123 ** of its own ancestor pages. Corruption. */
79124 rc = SQLITE_CORRUPT_BKPT;
79125 }else{
79126 MemPage * const pParent = pCur->apPage[iPage-1];
79127 int const iIdx = pCur->aiIdx[iPage-1];
79128
79129 rc = sqlite3PagerWrite(pParent->pDbPage);
@@ -79283,11 +79455,11 @@
79283 ovflPageSize = pBt->usableSize - 4;
79284 do{
79285 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
79286 if( rc ) return rc;
79287 if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){
79288 rc = SQLITE_CORRUPT_BKPT;
79289 }else{
79290 if( iOffset+ovflPageSize<(u32)nTotal ){
79291 ovflPgno = get4byte(pPage->aData);
79292 }else{
79293 ovflPageSize = nTotal - iOffset;
@@ -79311,11 +79483,11 @@
79311 MemPage *pPage = pCur->pPage; /* Page being written */
79312
79313 if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
79314 || pCur->info.pPayload < pPage->aData + pPage->cellOffset
79315 ){
79316 return SQLITE_CORRUPT_BKPT;
79317 }
79318 if( pCur->info.nLocal==nTotal ){
79319 /* The entire cell is local */
79320 return btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
79321 0, pCur->info.nLocal);
@@ -79392,11 +79564,11 @@
79392 /* This can only happen if the schema is corrupt such that there is more
79393 ** than one table or index with the same root page as used by the cursor.
79394 ** Which can only happen if the SQLITE_NoSchemaError flag was set when
79395 ** the schema was loaded. This cannot be asserted though, as a user might
79396 ** set the flag, load the schema, and then unset the flag. */
79397 return SQLITE_CORRUPT_BKPT;
79398 }
79399 }
79400
79401 /* Ensure that the cursor is not in the CURSOR_FAULT state and that it
79402 ** points to a valid cell.
@@ -79515,11 +79687,11 @@
79515 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
79516 assert( pPage->leaf || !pPage->intKey );
79517 if( pPage->nFree<0 ){
79518 if( NEVER(pCur->eState>CURSOR_INVALID) ){
79519 /* ^^^^^--- due to the moveToRoot() call above */
79520 rc = SQLITE_CORRUPT_BKPT;
79521 }else{
79522 rc = btreeComputeFreeSpace(pPage);
79523 }
79524 if( rc ) return rc;
79525 }
@@ -79554,11 +79726,11 @@
79554 pCur->info.nSize = 0;
79555 if( loc==0 ){
79556 CellInfo info;
79557 assert( idx>=0 );
79558 if( idx>=pPage->nCell ){
79559 return SQLITE_CORRUPT_BKPT;
79560 }
79561 rc = sqlite3PagerWrite(pPage->pDbPage);
79562 if( rc ){
79563 goto end_insert;
79564 }
@@ -79581,14 +79753,14 @@
79581 ** This optimization cannot be used on an autovacuum database if the
79582 ** new entry uses overflow pages, as the insertCell() call below is
79583 ** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry. */
79584 assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */
79585 if( oldCell < pPage->aData+pPage->hdrOffset+10 ){
79586 return SQLITE_CORRUPT_BKPT;
79587 }
79588 if( oldCell+szNew > pPage->aDataEnd ){
79589 return SQLITE_CORRUPT_BKPT;
79590 }
79591 memcpy(oldCell, newCell, szNew);
79592 return SQLITE_OK;
79593 }
79594 dropCell(pPage, idx, info.nSize, &rc);
@@ -79686,11 +79858,11 @@
79686 }
79687 if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
79688 nIn = pSrc->info.nLocal;
79689 aIn = pSrc->info.pPayload;
79690 if( aIn+nIn>pSrc->pPage->aDataEnd ){
79691 return SQLITE_CORRUPT_BKPT;
79692 }
79693 nRem = pSrc->info.nPayload;
79694 if( nIn==nRem && nIn<pDest->pPage->maxLocal ){
79695 memcpy(aOut, aIn, nIn);
79696 pBt->nPreformatSize = nIn + (aOut - pBt->pTmpSpace);
@@ -79711,11 +79883,11 @@
79711 pBt->nPreformatSize += 4;
79712 }
79713
79714 if( nRem>nIn ){
79715 if( aIn+nIn+4>pSrc->pPage->aDataEnd ){
79716 return SQLITE_CORRUPT_BKPT;
79717 }
79718 ovflIn = get4byte(&pSrc->info.pPayload[nIn]);
79719 }
79720
79721 do {
@@ -79807,27 +79979,27 @@
79807 if( pCur->eState>=CURSOR_REQUIRESEEK ){
79808 rc = btreeRestoreCursorPosition(pCur);
79809 assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
79810 if( rc || pCur->eState!=CURSOR_VALID ) return rc;
79811 }else{
79812 return SQLITE_CORRUPT_BKPT;
79813 }
79814 }
79815 assert( pCur->eState==CURSOR_VALID );
79816
79817 iCellDepth = pCur->iPage;
79818 iCellIdx = pCur->ix;
79819 pPage = pCur->pPage;
79820 if( pPage->nCell<=iCellIdx ){
79821 return SQLITE_CORRUPT_BKPT;
79822 }
79823 pCell = findCell(pPage, iCellIdx);
79824 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
79825 return SQLITE_CORRUPT_BKPT;
79826 }
79827 if( pCell<&pPage->aCellIdx[pPage->nCell] ){
79828 return SQLITE_CORRUPT_BKPT;
79829 }
79830
79831 /* If the BTREE_SAVEPOSITION bit is on, then the cursor position must
79832 ** be preserved following this delete operation. If the current delete
79833 ** will cause a b-tree rebalance, then this is done by saving the cursor
@@ -79914,11 +80086,11 @@
79914 n = pCur->apPage[iCellDepth+1]->pgno;
79915 }else{
79916 n = pCur->pPage->pgno;
79917 }
79918 pCell = findCell(pLeaf, pLeaf->nCell-1);
79919 if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
79920 nCell = pLeaf->xCellSize(pLeaf, pCell);
79921 assert( MX_CELL_SIZE(pBt) >= nCell );
79922 pTmp = pBt->pTmpSpace;
79923 assert( pTmp!=0 );
79924 rc = sqlite3PagerWrite(pLeaf->pDbPage);
@@ -80030,11 +80202,11 @@
80030 ** root page of the new table should go. meta[3] is the largest root-page
80031 ** created so far, so the new root-page is (meta[3]+1).
80032 */
80033 sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
80034 if( pgnoRoot>btreePagecount(pBt) ){
80035 return SQLITE_CORRUPT_BKPT;
80036 }
80037 pgnoRoot++;
80038
80039 /* The new root-page may not be allocated on a pointer-map page, or the
80040 ** PENDING_BYTE page.
@@ -80078,11 +80250,11 @@
80078 if( rc!=SQLITE_OK ){
80079 return rc;
80080 }
80081 rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
80082 if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
80083 rc = SQLITE_CORRUPT_BKPT;
80084 }
80085 if( rc!=SQLITE_OK ){
80086 releasePage(pRoot);
80087 return rc;
80088 }
@@ -80168,18 +80340,18 @@
80168 int hdr;
80169 CellInfo info;
80170
80171 assert( sqlite3_mutex_held(pBt->mutex) );
80172 if( pgno>btreePagecount(pBt) ){
80173 return SQLITE_CORRUPT_BKPT;
80174 }
80175 rc = getAndInitPage(pBt, pgno, &pPage, 0);
80176 if( rc ) return rc;
80177 if( (pBt->openFlags & BTREE_SINGLE)==0
80178 && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
80179 ){
80180 rc = SQLITE_CORRUPT_BKPT;
80181 goto cleardatabasepage_out;
80182 }
80183 hdr = pPage->hdrOffset;
80184 for(i=0; i<pPage->nCell; i++){
80185 pCell = findCell(pPage, i);
@@ -80279,11 +80451,11 @@
80279
80280 assert( sqlite3BtreeHoldsMutex(p) );
80281 assert( p->inTrans==TRANS_WRITE );
80282 assert( iTable>=2 );
80283 if( iTable>btreePagecount(pBt) ){
80284 return SQLITE_CORRUPT_BKPT;
80285 }
80286
80287 rc = sqlite3BtreeClearTable(p, iTable, 0);
80288 if( rc ) return rc;
80289 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
@@ -83920,32 +84092,52 @@
83920 }
83921 return rc;
83922 }
83923
83924 /* Handle negative integers in a single step. This is needed in the
83925 ** case when the value is -9223372036854775808.
83926 */
83927 if( op==TK_UMINUS
83928 && (pExpr->pLeft->op==TK_INTEGER || pExpr->pLeft->op==TK_FLOAT) ){
83929 pExpr = pExpr->pLeft;
83930 op = pExpr->op;
83931 negInt = -1;
83932 zNeg = "-";
 
 
 
 
 
 
83933 }
83934
83935 if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
83936 pVal = valueNew(db, pCtx);
83937 if( pVal==0 ) goto no_mem;
83938 if( ExprHasProperty(pExpr, EP_IntValue) ){
83939 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
83940 }else{
83941 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
83942 if( zVal==0 ) goto no_mem;
83943 sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
 
 
 
 
 
83944 }
83945 if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_BLOB ){
83946 sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
 
 
 
 
 
 
 
 
 
83947 }else{
83948 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
83949 }
83950 assert( (pVal->flags & MEM_IntReal)==0 );
83951 if( pVal->flags & (MEM_Int|MEM_IntReal|MEM_Real) ){
@@ -94641,11 +94833,11 @@
94641 }
94642 break;
94643 }
94644 #endif
94645
94646 #ifndef SQLITE_OMIT_CAST
94647 /* Opcode: Cast P1 P2 * * *
94648 ** Synopsis: affinity(r[P1])
94649 **
94650 ** Force the value in register P1 to be the type defined by P2.
94651 **
@@ -94856,20 +95048,24 @@
94856 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
94857 applyNumericAffinity(pIn3,0);
94858 }
94859 }
94860 }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
94861 if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
 
 
94862 testcase( pIn1->flags & MEM_Int );
94863 testcase( pIn1->flags & MEM_Real );
94864 testcase( pIn1->flags & MEM_IntReal );
94865 sqlite3VdbeMemStringify(pIn1, encoding, 1);
94866 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
94867 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
94868 if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
94869 }
94870 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
 
 
94871 testcase( pIn3->flags & MEM_Int );
94872 testcase( pIn3->flags & MEM_Real );
94873 testcase( pIn3->flags & MEM_IntReal );
94874 sqlite3VdbeMemStringify(pIn3, encoding, 1);
94875 testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) );
@@ -96209,15 +96405,20 @@
96209 len = sqlite3SmallTypeSizes[serial_type];
96210 assert( len>=1 && len<=8 && len!=5 && len!=7 );
96211 switch( len ){
96212 default: zPayload[7] = (u8)(v&0xff); v >>= 8;
96213 zPayload[6] = (u8)(v&0xff); v >>= 8;
 
96214 case 6: zPayload[5] = (u8)(v&0xff); v >>= 8;
96215 zPayload[4] = (u8)(v&0xff); v >>= 8;
 
96216 case 4: zPayload[3] = (u8)(v&0xff); v >>= 8;
 
96217 case 3: zPayload[2] = (u8)(v&0xff); v >>= 8;
 
96218 case 2: zPayload[1] = (u8)(v&0xff); v >>= 8;
 
96219 case 1: zPayload[0] = (u8)(v&0xff);
96220 }
96221 zPayload += len;
96222 }
96223 }else if( serial_type<0x80 ){
@@ -98738,32 +98939,41 @@
98738 if( res ) goto jump_to_p2;
98739 }
98740 break;
98741 }
98742
98743 /* Opcode: IfSmaller P1 P2 P3 * *
98744 **
98745 ** Estimate the number of rows in the table P1. Jump to P2 if that
98746 ** estimate is less than approximately 2**(0.1*P3).
 
 
98747 */
98748 case OP_IfSmaller: { /* jump */
98749 VdbeCursor *pC;
98750 BtCursor *pCrsr;
98751 int res;
98752 i64 sz;
98753
98754 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 
 
 
98755 pC = p->apCsr[pOp->p1];
98756 assert( pC!=0 );
98757 pCrsr = pC->uc.pCursor;
98758 assert( pCrsr );
98759 rc = sqlite3BtreeFirst(pCrsr, &res);
98760 if( rc ) goto abort_due_to_error;
98761 if( res==0 ){
 
 
98762 sz = sqlite3BtreeRowCountEst(pCrsr);
98763 if( ALWAYS(sz>=0) && sqlite3LogEst((u64)sz)<pOp->p3 ) res = 1;
 
98764 }
 
98765 VdbeBranchTaken(res!=0,2);
98766 if( res ) goto jump_to_p2;
98767 break;
98768 }
98769
@@ -99459,42 +99669,55 @@
99459 if( rc ) goto abort_due_to_error;
99460 pOut->u.i = pgno;
99461 break;
99462 }
99463
99464 /* Opcode: SqlExec * * * P4 *
99465 **
99466 ** Run the SQL statement or statements specified in the P4 string.
99467 ** Disable Auth and Trace callbacks while those statements are running if
99468 ** P1 is true.
 
 
 
 
 
 
 
99469 */
99470 case OP_SqlExec: {
99471 char *zErr;
99472 #ifndef SQLITE_OMIT_AUTHORIZATION
99473 sqlite3_xauth xAuth;
99474 #endif
99475 u8 mTrace;
 
99476
99477 sqlite3VdbeIncrWriteCounter(p, 0);
99478 db->nSqlExec++;
99479 zErr = 0;
99480 #ifndef SQLITE_OMIT_AUTHORIZATION
99481 xAuth = db->xAuth;
99482 #endif
99483 mTrace = db->mTrace;
99484 if( pOp->p1 ){
 
99485 #ifndef SQLITE_OMIT_AUTHORIZATION
99486 db->xAuth = 0;
99487 #endif
99488 db->mTrace = 0;
99489 }
 
 
 
99490 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
99491 db->nSqlExec--;
99492 #ifndef SQLITE_OMIT_AUTHORIZATION
99493 db->xAuth = xAuth;
99494 #endif
99495 db->mTrace = mTrace;
 
99496 if( zErr || rc ){
99497 sqlite3VdbeError(p, "%s", zErr);
99498 sqlite3_free(zErr);
99499 if( rc==SQLITE_NOMEM ) goto no_mem;
99500 goto abort_due_to_error;
@@ -99647,12 +99870,12 @@
99647 ** register P1 the text of an error message describing any problems.
99648 ** If no problems are found, store a NULL in register P1.
99649 **
99650 ** The register P3 contains one less than the maximum number of allowed errors.
99651 ** At most reg(P3) errors will be reported.
99652 ** In other words, the analysis stops as soon as reg(P1) errors are
99653 ** seen. Reg(P1) is updated with the number of errors remaining.
99654 **
99655 ** The root page numbers of all tables in the database are integers
99656 ** stored in P4_INTARRAY argument.
99657 **
99658 ** If P5 is not zero, the check is done on the auxiliary database
@@ -106210,10 +106433,12 @@
106210 sqlite3 *db; /* The database connection */
106211
106212 assert( iCol>=0 && iCol<pEList->nExpr );
106213 pOrig = pEList->a[iCol].pExpr;
106214 assert( pOrig!=0 );
 
 
106215 db = pParse->db;
106216 pDup = sqlite3ExprDup(db, pOrig, 0);
106217 if( db->mallocFailed ){
106218 sqlite3ExprDelete(db, pDup);
106219 pDup = 0;
@@ -106408,11 +106633,11 @@
106408 */
106409 static int lookupName(
106410 Parse *pParse, /* The parsing context */
106411 const char *zDb, /* Name of the database containing table, or NULL */
106412 const char *zTab, /* Name of table containing column, or NULL */
106413 const char *zCol, /* Name of the column. */
106414 NameContext *pNC, /* The name context used to resolve the name */
106415 Expr *pExpr /* Make this EXPR node point to the selected column */
106416 ){
106417 int i, j; /* Loop counters */
106418 int cnt = 0; /* Number of matching column names */
@@ -106425,10 +106650,11 @@
106425 Schema *pSchema = 0; /* Schema of the expression */
106426 int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
106427 Table *pTab = 0; /* Table holding the row */
106428 Column *pCol; /* A column of pTab */
106429 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
 
106430
106431 assert( pNC ); /* the name context cannot be NULL. */
106432 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
106433 assert( zDb==0 || zTab!=0 );
106434 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
@@ -106884,10 +107110,14 @@
106884 zErr = cnt==0 ? "no such column" : "ambiguous column name";
106885 if( zDb ){
106886 sqlite3ErrorMsg(pParse, "%s: %s.%s.%s", zErr, zDb, zTab, zCol);
106887 }else if( zTab ){
106888 sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
 
 
 
 
106889 }else{
106890 sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
106891 }
106892 sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
106893 pParse->checkSchema = 1;
@@ -107131,20 +107361,19 @@
107131 ** be one call to lookupName(). Then the compiler will in-line
107132 ** lookupName() for a size reduction and performance increase.
107133 */
107134 case TK_ID:
107135 case TK_DOT: {
107136 const char *zColumn;
107137 const char *zTable;
107138 const char *zDb;
107139 Expr *pRight;
107140
107141 if( pExpr->op==TK_ID ){
107142 zDb = 0;
107143 zTable = 0;
107144 assert( !ExprHasProperty(pExpr, EP_IntValue) );
107145 zColumn = pExpr->u.zToken;
107146 }else{
107147 Expr *pLeft = pExpr->pLeft;
107148 testcase( pNC->ncFlags & NC_IdxExpr );
107149 testcase( pNC->ncFlags & NC_GenCol );
107150 sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
@@ -107159,18 +107388,17 @@
107159 pLeft = pRight->pLeft;
107160 pRight = pRight->pRight;
107161 }
107162 assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) );
107163 zTable = pLeft->u.zToken;
107164 zColumn = pRight->u.zToken;
107165 assert( ExprUseYTab(pExpr) );
107166 if( IN_RENAME_OBJECT ){
107167 sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
107168 sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
107169 }
107170 }
107171 return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
107172 }
107173
107174 /* Resolve function names
107175 */
107176 case TK_FUNCTION: {
@@ -118538,11 +118766,11 @@
118538 u64 nDistinct = p->current.anDLt[i] + 1;
118539 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
118540 if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
118541 sqlite3_str_appendf(&sStat, " %llu", iVal);
118542 #ifdef SQLITE_ENABLE_STAT4
118543 assert( p->current.anEq[i] );
118544 #endif
118545 }
118546 sqlite3ResultStrAccum(context, &sStat);
118547 }
118548 #ifdef SQLITE_ENABLE_STAT4
@@ -118723,11 +118951,11 @@
118723 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
118724 sqlite3VdbeLoadString(v, regTabname, pTab->zName);
118725
118726 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
118727 int nCol; /* Number of columns in pIdx. "N" */
118728 int addrRewind; /* Address of "OP_Rewind iIdxCur" */
118729 int addrNextRow; /* Address of "next_row:" */
118730 const char *zIdxName; /* Name of the index */
118731 int nColTest; /* Number of columns to test for changes */
118732
118733 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
@@ -118747,13 +118975,18 @@
118747 VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
118748
118749 /*
118750 ** Pseudo-code for loop that calls stat_push():
118751 **
 
118752 ** Rewind csr
118753 ** if eof(csr) goto end_of_scan;
118754 ** regChng = 0
 
 
 
 
118755 ** goto chng_addr_0;
118756 **
118757 ** next_row:
118758 ** regChng = 0
118759 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
@@ -118788,45 +119021,40 @@
118788 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
118789 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
118790 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
118791 VdbeComment((v, "%s", pIdx->zName));
118792
118793 /* Invoke the stat_init() function. The arguments are:
118794 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118795 ** (1) the number of columns in the index including the rowid
118796 ** (or for a WITHOUT ROWID table, the number of PK columns),
118797 ** (2) the number of columns in the key without the rowid/pk
118798 ** (3) estimated number of rows in the index,
118799 */
118800 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat+1);
118801 assert( regRowid==regStat+2 );
118802 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regRowid);
118803 #ifdef SQLITE_ENABLE_STAT4
118804 if( OptimizationEnabled(db, SQLITE_Stat4) ){
118805 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regTemp);
118806 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
118807 VdbeCoverage(v);
118808 }else
118809 #endif
118810 {
118811 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
118812 VdbeCoverage(v);
118813 sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp, 1);
118814 }
118815 assert( regTemp2==regStat+4 );
118816 sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2);
118817 sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4,
118818 &statInitFuncdef, 0);
118819
118820 /* Implementation of the following:
118821 **
118822 ** Rewind csr
118823 ** if eof(csr) goto end_of_scan;
118824 ** regChng = 0
118825 ** goto next_push_0;
118826 **
118827 */
118828 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
118829 addrNextRow = sqlite3VdbeCurrentAddr(v);
118830
118831 if( nColTest>0 ){
118832 int endDistinctTest = sqlite3VdbeMakeLabel(pParse);
@@ -118929,10 +119157,16 @@
118929 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
118930 }
118931 }
118932
118933 /* Add the entry to the stat1 table. */
 
 
 
 
 
 
118934 callStatGet(pParse, regStat, STAT_GET_STAT1, regStat1);
118935 assert( "BBB"[0]==SQLITE_AFF_TEXT );
118936 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
118937 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
118938 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
@@ -118951,10 +119185,16 @@
118951 int regCol = regStat1+4;
118952 int regSampleRowid = regCol + nCol;
118953 int addrNext;
118954 int addrIsNull;
118955 u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
 
 
 
 
 
 
118956
118957 if( doOnce ){
118958 int mxCol = nCol;
118959 Index *pX;
118960
@@ -119004,11 +119244,11 @@
119004 sqlite3VdbeJumpHere(v, addrIsNull);
119005 }
119006 #endif /* SQLITE_ENABLE_STAT4 */
119007
119008 /* End of analysis */
119009 sqlite3VdbeJumpHere(v, addrRewind);
119010 }
119011
119012
119013 /* Create a single sqlite_stat1 entry containing NULL as the index
119014 ** name and the row count as the content.
@@ -120753,11 +120993,11 @@
120753 sqlite3VdbeJumpHere(v, addrRewind);
120754 }
120755 }
120756 sqlite3VdbeAddOp0(v, OP_Halt);
120757
120758 #if SQLITE_USER_AUTHENTICATION
120759 if( pParse->nTableLock>0 && db->init.busy==0 ){
120760 sqlite3UserAuthInit(db);
120761 if( db->auth.authLevel<UAUTH_User ){
120762 sqlite3ErrorMsg(pParse, "user not authenticated");
120763 pParse->rc = SQLITE_AUTH_USER;
@@ -123487,15 +123727,15 @@
123487 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName),0);
123488
123489 /* Test for cycles in generated columns and illegal expressions
123490 ** in CHECK constraints and in DEFAULT clauses. */
123491 if( p->tabFlags & TF_HasGenerated ){
123492 sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0,
123493 sqlite3MPrintf(db, "SELECT*FROM\"%w\".\"%w\"",
123494 db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
123495 }
123496 sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0,
123497 sqlite3MPrintf(db, "PRAGMA \"%w\".integrity_check(%Q)",
123498 db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
123499 }
123500
123501 /* Add the table to the in-memory representation of the database.
@@ -129253,11 +129493,11 @@
129253 || sqlite3_context_db_handle(context)->mallocFailed );
129254 return;
129255 }
129256 if( zPattern[0]==0 ){
129257 assert( sqlite3_value_type(argv[1])!=SQLITE_NULL );
129258 sqlite3_result_value(context, argv[0]);
129259 return;
129260 }
129261 nPattern = sqlite3_value_bytes(argv[1]);
129262 assert( zPattern==sqlite3_value_text(argv[1]) ); /* No encoding change */
129263 zRep = sqlite3_value_text(argv[2]);
@@ -137740,10 +137980,38 @@
137740 /* Number of pragmas: 68 on by default, 78 total. */
137741
137742 /************** End of pragma.h **********************************************/
137743 /************** Continuing where we left off in pragma.c *********************/
137744
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137745 /*
137746 ** Interpret the given string as a safety level. Return 0 for OFF,
137747 ** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA. Return 1 for an empty or
137748 ** unrecognized string argument. The FULL and EXTRA option is disallowed
137749 ** if the omitFull parameter it 1.
@@ -139472,35 +139740,11 @@
139472 int bStrict; /* True for a STRICT table */
139473 int r2; /* Previous key for WITHOUT ROWID tables */
139474 int mxCol; /* Maximum non-virtual column number */
139475
139476 if( pObjTab && pObjTab!=pTab ) continue;
139477 if( !IsOrdinaryTable(pTab) ){
139478 #ifndef SQLITE_OMIT_VIRTUALTABLE
139479 sqlite3_vtab *pVTab;
139480 int a1;
139481 if( !IsVirtual(pTab) ) continue;
139482 if( pTab->nCol<=0 ){
139483 const char *zMod = pTab->u.vtab.azArg[0];
139484 if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
139485 }
139486 sqlite3ViewGetColumnNames(pParse, pTab);
139487 if( pTab->u.vtab.p==0 ) continue;
139488 pVTab = pTab->u.vtab.p->pVtab;
139489 if( NEVER(pVTab==0) ) continue;
139490 if( NEVER(pVTab->pModule==0) ) continue;
139491 if( pVTab->pModule->iVersion<4 ) continue;
139492 if( pVTab->pModule->xIntegrity==0 ) continue;
139493 sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick);
139494 pTab->nTabRef++;
139495 sqlite3VdbeAppendP4(v, pTab, P4_TABLEREF);
139496 a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
139497 integrityCheckResultRow(v);
139498 sqlite3VdbeJumpHere(v, a1);
139499 #endif
139500 continue;
139501 }
139502 if( isQuick || HasRowid(pTab) ){
139503 pPk = 0;
139504 r2 = 0;
139505 }else{
139506 pPk = sqlite3PrimaryKeyIndex(pTab);
@@ -139631,10 +139875,11 @@
139631 /* OP_IsType does not detect NaN values in the database file
139632 ** which should be treated as a NULL. So if the header type
139633 ** is REAL, we have to load the actual data using OP_Column
139634 ** to reliably determine if the value is a NULL. */
139635 sqlite3VdbeAddOp3(v, OP_Column, p1, p3, 3);
 
139636 jmp3 = sqlite3VdbeAddOp2(v, OP_NotNull, 3, labelOk);
139637 VdbeCoverage(v);
139638 }
139639 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
139640 pCol->zCnName);
@@ -139821,10 +140066,42 @@
139821 if( pPk ){
139822 sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol);
139823 }
139824 }
139825 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139826 }
139827 {
139828 static const int iLn = VDBE_OFFSET_LINENO(2);
139829 static const VdbeOpList endCode[] = {
139830 { OP_AddImm, 1, 0, 0}, /* 0 */
@@ -140084,48 +140361,67 @@
140084 ** to change and improve over time. Applications should anticipate that
140085 ** this pragma will perform new optimizations in future releases.
140086 **
140087 ** The optional argument is a bitmask of optimizations to perform:
140088 **
140089 ** 0x0001 Debugging mode. Do not actually perform any optimizations
140090 ** but instead return one line of text for each optimization
140091 ** that would have been done. Off by default.
140092 **
140093 ** 0x0002 Run ANALYZE on tables that might benefit. On by default.
140094 ** See below for additional information.
140095 **
140096 ** 0x0004 (Not yet implemented) Record usage and performance
140097 ** information from the current session in the
140098 ** database file so that it will be available to "optimize"
140099 ** pragmas run by future database connections.
140100 **
140101 ** 0x0008 (Not yet implemented) Create indexes that might have
140102 ** been helpful to recent queries
140103 **
140104 ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all
140105 ** of the optimizations listed above except Debug Mode, including new
140106 ** optimizations that have not yet been invented. If new optimizations are
140107 ** ever added that should be off by default, those off-by-default
140108 ** optimizations will have bitmasks of 0x10000 or larger.
 
 
 
 
 
140109 **
140110 ** DETERMINATION OF WHEN TO RUN ANALYZE
140111 **
140112 ** In the current implementation, a table is analyzed if only if all of
140113 ** the following are true:
140114 **
140115 ** (1) MASK bit 0x02 is set.
140116 **
140117 ** (2) The query planner used sqlite_stat1-style statistics for one or
140118 ** more indexes of the table at some point during the lifetime of
140119 ** the current connection.
140120 **
140121 ** (3) One or more indexes of the table are currently unanalyzed OR
140122 ** the number of rows in the table has increased by 25 times or more
140123 ** since the last time ANALYZE was run.
 
 
 
 
 
 
 
 
 
 
 
 
140124 **
140125 ** The rules for when tables are analyzed are likely to change in
140126 ** future releases.
 
 
140127 */
140128 case PragTyp_OPTIMIZE: {
140129 int iDbLast; /* Loop termination point for the schema loop */
140130 int iTabCur; /* Cursor for a table whose size needs checking */
140131 HashElem *k; /* Loop over tables of a schema */
@@ -140133,56 +140429,122 @@
140133 Table *pTab; /* A table in the schema */
140134 Index *pIdx; /* An index of the table */
140135 LogEst szThreshold; /* Size threshold above which reanalysis needed */
140136 char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
140137 u32 opMask; /* Mask of operations to perform */
 
 
 
 
140138
140139 if( zRight ){
140140 opMask = (u32)sqlite3Atoi(zRight);
140141 if( (opMask & 0x02)==0 ) break;
140142 }else{
140143 opMask = 0xfffe;
140144 }
 
 
 
 
 
 
 
 
140145 iTabCur = pParse->nTab++;
140146 for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){
140147 if( iDb==1 ) continue;
140148 sqlite3CodeVerifySchema(pParse, iDb);
140149 pSchema = db->aDb[iDb].pSchema;
140150 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
140151 pTab = (Table*)sqliteHashData(k);
140152
140153 /* If table pTab has not been used in a way that would benefit from
140154 ** having analysis statistics during the current session, then skip it.
140155 ** This also has the effect of skipping virtual tables and views */
140156 if( (pTab->tabFlags & TF_StatsUsed)==0 ) continue;
140157
140158 /* Reanalyze if the table is 25 times larger than the last analysis */
140159 szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 );
 
 
 
 
 
 
 
140160 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
 
140161 if( !pIdx->hasStat1 ){
140162 szThreshold = 0; /* Always analyze if any index lacks statistics */
140163 break;
140164 }
140165 }
140166 if( szThreshold ){
140167 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
140168 sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur,
140169 sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140170 VdbeCoverage(v);
140171 }
140172 zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"",
140173 db->aDb[iDb].zDbSName, pTab->zName);
140174 if( opMask & 0x01 ){
140175 int r1 = sqlite3GetTempReg(pParse);
140176 sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
140177 sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1);
140178 }else{
140179 sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC);
 
140180 }
140181 }
140182 }
140183 sqlite3VdbeAddOp0(v, OP_Expire);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140184 break;
140185 }
140186
140187 /*
140188 ** PRAGMA busy_timeout
@@ -148175,10 +148537,12 @@
148175 /*
148176 ** Display all information about an AggInfo object
148177 */
148178 static void printAggInfo(AggInfo *pAggInfo){
148179 int ii;
 
 
148180 for(ii=0; ii<pAggInfo->nColumn; ii++){
148181 struct AggInfo_col *pCol = &pAggInfo->aCol[ii];
148182 sqlite3DebugPrintf(
148183 "agg-column[%d] pTab=%s iTable=%d iColumn=%d iMem=%d"
148184 " iSorterColumn=%d %s\n",
@@ -150277,10 +150641,16 @@
150277 assert( db->mallocFailed==0 || db->mallocFailed==1 );
150278 assert( db->mallocFailed==0 || pParse->nErr!=0 );
150279 sqlite3ExprListDelete(db, pMinMaxOrderBy);
150280 #ifdef SQLITE_DEBUG
150281 if( pAggInfo && !db->mallocFailed ){
 
 
 
 
 
 
150282 for(i=0; i<pAggInfo->nColumn; i++){
150283 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
150284 if( pExpr==0 ) continue;
150285 assert( pExpr->pAggInfo==pAggInfo );
150286 assert( pExpr->iAgg==i );
@@ -154714,10 +155084,12 @@
154714 sCtx.pPrior = db->pVtabCtx;
154715 sCtx.bDeclared = 0;
154716 db->pVtabCtx = &sCtx;
154717 pTab->nTabRef++;
154718 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
 
 
154719 sqlite3DeleteTable(db, pTab);
154720 db->pVtabCtx = sCtx.pPrior;
154721 if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
154722 assert( sCtx.pTab==pTab );
154723
@@ -154736,11 +155108,11 @@
154736 pVTable->pVtab->pModule = pMod->pModule;
154737 pMod->nRefModule++;
154738 pVTable->nRef = 1;
154739 if( sCtx.bDeclared==0 ){
154740 const char *zFormat = "vtable constructor did not declare schema: %s";
154741 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
154742 sqlite3VtabUnlock(pVTable);
154743 rc = SQLITE_ERROR;
154744 }else{
154745 int iCol;
154746 u16 oooHidden = 0;
@@ -164129,11 +164501,13 @@
164129 if( pIndex->bUnordered ) return 0;
164130 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
164131 for(ii=0; ii<pOB->nExpr; ii++){
164132 Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
164133 if( NEVER(pExpr==0) ) continue;
164134 if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){
 
 
164135 if( pExpr->iColumn<0 ) return 1;
164136 for(jj=0; jj<pIndex->nKeyCol; jj++){
164137 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
164138 }
164139 }else if( (aColExpr = pIndex->aColExpr)!=0 ){
@@ -164735,11 +165109,11 @@
164735 if( pBuilder->bldFlags1==SQLITE_BLDF1_INDEXED ){
164736 /* If a non-unique index is used, or if a prefix of the key for
164737 ** unique index is used (making the index functionally non-unique)
164738 ** then the sqlite_stat1 data becomes important for scoring the
164739 ** plan */
164740 pTab->tabFlags |= TF_StatsUsed;
164741 }
164742 #ifdef SQLITE_ENABLE_STAT4
164743 sqlite3Stat4ProbeFree(pBuilder->pRec);
164744 pBuilder->nRecValid = 0;
164745 pBuilder->pRec = 0;
@@ -166229,14 +166603,13 @@
166229 pWInfo->nOBSat = pFrom->isOrdered;
166230 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
166231 if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
166232 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
166233 }
166234 if( pWInfo->pSelect->pOrderBy
166235 && pWInfo->nOBSat > pWInfo->pSelect->pOrderBy->nExpr ){
166236 pWInfo->nOBSat = pWInfo->pSelect->pOrderBy->nExpr;
166237 }
166238 }else{
166239 pWInfo->revMask = pFrom->revLoop;
166240 if( pWInfo->nOBSat<=0 ){
166241 pWInfo->nOBSat = 0;
166242 if( nLoop>0 ){
@@ -166571,11 +166944,11 @@
166571 WhereLoop *pLoop = pWInfo->a[i].pWLoop;
166572 const unsigned int reqFlags = (WHERE_SELFCULL|WHERE_COLUMN_EQ);
166573 SrcItem *pItem = &pWInfo->pTabList->a[pLoop->iTab];
166574 Table *pTab = pItem->pTab;
166575 if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
166576 pTab->tabFlags |= TF_StatsUsed;
166577 if( i>=1
166578 && (pLoop->wsFlags & reqFlags)==reqFlags
166579 /* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */
166580 && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0)
166581 ){
@@ -171056,10 +171429,18 @@
171056 sqlite3WithDelete(pParse->db, pWith);
171057 }
171058 return pSelect;
171059 }
171060
 
 
 
 
 
 
 
 
171061
171062 /* Construct a new Expr object from a single token */
171063 static Expr *tokenExpr(Parse *pParse, int op, Token t){
171064 Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
171065 if( p ){
@@ -171357,10 +171738,13 @@
171357 ** sqlite3ParserARG_PDECL A parameter declaration for the %extra_argument
171358 ** sqlite3ParserARG_PARAM Code to pass %extra_argument as a subroutine parameter
171359 ** sqlite3ParserARG_STORE Code to store %extra_argument into yypParser
171360 ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
171361 ** sqlite3ParserCTX_* As sqlite3ParserARG_ except for %extra_context
 
 
 
171362 ** YYERRORSYMBOL is the code number of the error symbol. If not
171363 ** defined, then do no error processing.
171364 ** YYNSTATE the combined number of states.
171365 ** YYNRULE the number of rules in the grammar
171366 ** YYNTOKEN Number of terminal symbols
@@ -171370,10 +171754,12 @@
171370 ** YY_ERROR_ACTION The yy_action[] code for syntax error
171371 ** YY_ACCEPT_ACTION The yy_action[] code for accept
171372 ** YY_NO_ACTION The yy_action[] code for no-op
171373 ** YY_MIN_REDUCE Minimum value for reduce actions
171374 ** YY_MAX_REDUCE Maximum value for reduce actions
 
 
171375 */
171376 #ifndef INTERFACE
171377 # define INTERFACE 1
171378 #endif
171379 /************* Begin control #defines *****************************************/
@@ -171410,10 +171796,13 @@
171410 #define sqlite3ParserARG_SDECL
171411 #define sqlite3ParserARG_PDECL
171412 #define sqlite3ParserARG_PARAM
171413 #define sqlite3ParserARG_FETCH
171414 #define sqlite3ParserARG_STORE
 
 
 
171415 #define sqlite3ParserCTX_SDECL Parse *pParse;
171416 #define sqlite3ParserCTX_PDECL ,Parse *pParse
171417 #define sqlite3ParserCTX_PARAM ,pParse
171418 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
171419 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
@@ -171428,10 +171817,12 @@
171428 #define YY_ERROR_ACTION 1243
171429 #define YY_ACCEPT_ACTION 1244
171430 #define YY_NO_ACTION 1245
171431 #define YY_MIN_REDUCE 1246
171432 #define YY_MAX_REDUCE 1650
 
 
171433 /************* End control #defines *******************************************/
171434 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
171435
171436 /* Define the yytestcase() macro to be a no-op if is not already defined
171437 ** otherwise.
@@ -171442,10 +171833,26 @@
171442 ** for testing.
171443 */
171444 #ifndef yytestcase
171445 # define yytestcase(X)
171446 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171447
171448
171449 /* Next are the tables used to determine what action to take based on the
171450 ** current state and lookahead token. These tables are used to implement
171451 ** functions that take a state number and lookahead value and return an
@@ -172351,18 +172758,13 @@
172351 #ifndef YYNOERRORRECOVERY
172352 int yyerrcnt; /* Shifts left before out of the error */
172353 #endif
172354 sqlite3ParserARG_SDECL /* A place to hold %extra_argument */
172355 sqlite3ParserCTX_SDECL /* A place to hold %extra_context */
172356 #if YYSTACKDEPTH<=0
172357 int yystksz; /* Current side of the stack */
172358 yyStackEntry *yystack; /* The parser's stack */
172359 yyStackEntry yystk0; /* First stack entry */
172360 #else
172361 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
172362 yyStackEntry *yystackEnd; /* Last entry in the stack */
172363 #endif
172364 };
172365 typedef struct yyParser yyParser;
172366
172367 /* #include <assert.h> */
172368 #ifndef NDEBUG
@@ -173134,41 +173536,49 @@
173134 /* 404 */ "window ::= frame_opt",
173135 };
173136 #endif /* NDEBUG */
173137
173138
173139 #if YYSTACKDEPTH<=0
173140 /*
173141 ** Try to increase the size of the parser stack. Return the number
173142 ** of errors. Return 0 on success.
173143 */
173144 static int yyGrowStack(yyParser *p){
 
173145 int newSize;
173146 int idx;
173147 yyStackEntry *pNew;
173148
173149 newSize = p->yystksz*2 + 100;
173150 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
173151 if( p->yystack==&p->yystk0 ){
173152 pNew = malloc(newSize*sizeof(pNew[0]));
173153 if( pNew ) pNew[0] = p->yystk0;
 
173154 }else{
173155 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
 
173156 }
173157 if( pNew ){
173158 p->yystack = pNew;
173159 p->yytos = &p->yystack[idx];
173160 #ifndef NDEBUG
173161 if( yyTraceFILE ){
173162 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
173163 yyTracePrompt, p->yystksz, newSize);
173164 }
173165 #endif
173166 p->yystksz = newSize;
173167 }
173168 return pNew==0;
173169 }
 
 
 
 
 
 
 
173170 #endif
173171
173172 /* Datatype of the argument to the memory allocated passed as the
173173 ** second argument to sqlite3ParserAlloc() below. This can be changed by
173174 ** putting an appropriate #define in the %include section of the input
@@ -173184,28 +173594,18 @@
173184 yyParser *yypParser = (yyParser*)yypRawParser;
173185 sqlite3ParserCTX_STORE
173186 #ifdef YYTRACKMAXSTACKDEPTH
173187 yypParser->yyhwm = 0;
173188 #endif
173189 #if YYSTACKDEPTH<=0
173190 yypParser->yytos = NULL;
173191 yypParser->yystack = NULL;
173192 yypParser->yystksz = 0;
173193 if( yyGrowStack(yypParser) ){
173194 yypParser->yystack = &yypParser->yystk0;
173195 yypParser->yystksz = 1;
173196 }
173197 #endif
173198 #ifndef YYNOERRORRECOVERY
173199 yypParser->yyerrcnt = -1;
173200 #endif
173201 yypParser->yytos = yypParser->yystack;
173202 yypParser->yystack[0].stateno = 0;
173203 yypParser->yystack[0].major = 0;
173204 #if YYSTACKDEPTH>0
173205 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
173206 #endif
173207 }
173208
173209 #ifndef sqlite3Parser_ENGINEALWAYSONSTACK
173210 /*
173211 ** This function allocates a new parser.
@@ -173379,13 +173779,30 @@
173379 /*
173380 ** Clear all secondary memory allocations from the parser
173381 */
173382 SQLITE_PRIVATE void sqlite3ParserFinalize(void *p){
173383 yyParser *pParser = (yyParser*)p;
173384 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
173385 #if YYSTACKDEPTH<=0
173386 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173387 #endif
173388 }
173389
173390 #ifndef sqlite3Parser_ENGINEALWAYSONSTACK
173391 /*
@@ -173564,11 +173981,11 @@
173564 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
173565 /* Here code is inserted which will execute if the parser
173566 ** stack every overflows */
173567 /******** Begin %stack_overflow code ******************************************/
173568
173569 sqlite3ErrorMsg(pParse, "parser stack overflow");
173570 /******** End %stack_overflow code ********************************************/
173571 sqlite3ParserARG_STORE /* Suppress warning about unused %extra_argument var */
173572 sqlite3ParserCTX_STORE
173573 }
173574
@@ -173608,29 +174025,23 @@
173608 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
173609 yypParser->yyhwm++;
173610 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
173611 }
173612 #endif
173613 #if YYSTACKDEPTH>0
173614 if( yypParser->yytos>yypParser->yystackEnd ){
173615 yypParser->yytos--;
173616 yyStackOverflow(yypParser);
173617 return;
173618 }
173619 #else
173620 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
173621 if( yyGrowStack(yypParser) ){
173622 yypParser->yytos--;
173623 yyStackOverflow(yypParser);
173624 return;
173625 }
 
 
173626 }
173627 #endif
173628 if( yyNewState > YY_MAX_SHIFT ){
173629 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
173630 }
173631 yytos = yypParser->yytos;
173632 yytos->stateno = yyNewState;
173633 yytos->major = yyMajor;
173634 yytos->minor.yy0 = yyMinor;
173635 yyTraceShift(yypParser, yyNewState, "Shift");
173636 }
@@ -176208,23 +176619,16 @@
176208 yypParser->yyhwm++;
176209 assert( yypParser->yyhwm ==
176210 (int)(yypParser->yytos - yypParser->yystack));
176211 }
176212 #endif
176213 #if YYSTACKDEPTH>0
176214 if( yypParser->yytos>=yypParser->yystackEnd ){
176215 yyStackOverflow(yypParser);
176216 break;
176217 }
176218 #else
176219 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
176220 if( yyGrowStack(yypParser) ){
176221 yyStackOverflow(yypParser);
176222 break;
176223 }
176224 }
176225 #endif
176226 }
176227 yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor sqlite3ParserCTX_PARAM);
176228 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
176229 yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
176230 #ifndef YYNOERRORRECOVERY
@@ -188495,26 +188899,28 @@
188495 const char *zTabname, /* Name of the pVTab table */
188496 int isQuick, /* True if this is a quick_check */
188497 char **pzErr /* Write error message here */
188498 ){
188499 Fts3Table *p = (Fts3Table*)pVtab;
188500 int rc;
188501 int bOk = 0;
188502
188503 UNUSED_PARAMETER(isQuick);
188504 rc = sqlite3Fts3IntegrityCheck(p, &bOk);
188505 assert( rc!=SQLITE_CORRUPT_VTAB || bOk==0 );
188506 if( rc!=SQLITE_OK && rc!=SQLITE_CORRUPT_VTAB ){
188507 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
188508 " FTS%d table %s.%s: %s",
188509 p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc));
188510 }else if( bOk==0 ){
 
188511 *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
188512 p->bFts4 ? 4 : 3, zSchema, zTabname);
 
188513 }
188514 sqlite3Fts3SegmentsClose(p);
188515 return SQLITE_OK;
188516 }
188517
188518
188519
188520 static const sqlite3_module fts3Module = {
@@ -200172,11 +200578,16 @@
200172 }
200173
200174 sqlite3_finalize(pStmt);
200175 }
200176
200177 *pbOk = (rc==SQLITE_OK && cksum1==cksum2);
 
 
 
 
 
200178 return rc;
200179 }
200180
200181 /*
200182 ** Run the integrity-check. If no error occurs and the current contents of
@@ -203796,10 +204207,44 @@
203796 if( p->nUsed==0 ) return;
203797 c = p->zBuf[p->nUsed-1];
203798 if( c=='[' || c=='{' ) return;
203799 jsonAppendChar(p, ',');
203800 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203801
203802 /* Append the N-byte string in zIn to the end of the JsonString string
203803 ** under construction. Enclose the string in double-quotes ("...") and
203804 ** escape any double-quotes or backslash characters contained within the
203805 ** string.
@@ -203856,39 +204301,18 @@
203856 z += k;
203857 N -= k;
203858 }
203859 c = z[0];
203860 if( c=='"' || c=='\\' ){
203861 json_simple_escape:
203862 if( (p->nUsed+N+3 > p->nAlloc) && jsonStringGrow(p,N+3)!=0 ) return;
203863 p->zBuf[p->nUsed++] = '\\';
203864 p->zBuf[p->nUsed++] = c;
203865 }else if( c=='\'' ){
203866 p->zBuf[p->nUsed++] = c;
203867 }else{
203868 static const char aSpecial[] = {
203869 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0,
203870 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
203871 };
203872 assert( sizeof(aSpecial)==32 );
203873 assert( aSpecial['\b']=='b' );
203874 assert( aSpecial['\f']=='f' );
203875 assert( aSpecial['\n']=='n' );
203876 assert( aSpecial['\r']=='r' );
203877 assert( aSpecial['\t']=='t' );
203878 assert( c>=0 && c<sizeof(aSpecial) );
203879 if( aSpecial[c] ){
203880 c = aSpecial[c];
203881 goto json_simple_escape;
203882 }
203883 if( (p->nUsed+N+7 > p->nAlloc) && jsonStringGrow(p,N+7)!=0 ) return;
203884 p->zBuf[p->nUsed++] = '\\';
203885 p->zBuf[p->nUsed++] = 'u';
203886 p->zBuf[p->nUsed++] = '0';
203887 p->zBuf[p->nUsed++] = '0';
203888 p->zBuf[p->nUsed++] = "0123456789abcdef"[c>>4];
203889 p->zBuf[p->nUsed++] = "0123456789abcdef"[c&0xf];
203890 }
203891 z++;
203892 N--;
203893 }
203894 p->zBuf[p->nUsed++] = '"';
@@ -204585,11 +205009,14 @@
204585 k = j+sz;
204586 while( j<k ){
204587 if( !jsonIsOk[z[j]] && z[j]!='\'' ){
204588 if( z[j]=='"' ){
204589 if( x==JSONB_TEXTJ ) return j+1;
204590 }else if( z[j]!='\\' || j+1>=k ){
 
 
 
204591 return j+1;
204592 }else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){
204593 j++;
204594 }else if( z[j+1]=='u' ){
204595 if( j+5>=k ) return j+1;
@@ -204783,10 +205210,11 @@
204783 return j+1;
204784 }
204785 case '[': {
204786 /* Parse array */
204787 iThis = pParse->nBlob;
 
204788 jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0);
204789 iStart = pParse->nBlob;
204790 if( pParse->oom ) return -1;
204791 if( ++pParse->iDepth > JSON_MAX_DEPTH ){
204792 pParse->iErr = i;
@@ -204879,13 +205307,18 @@
204879 }else{
204880 pParse->iErr = j;
204881 return -1;
204882 }
204883 }else if( c<=0x1f ){
204884 /* Control characters are not allowed in strings */
204885 pParse->iErr = j;
204886 return -1;
 
 
 
 
 
204887 }else if( c=='"' ){
204888 opcode = JSONB_TEXT5;
204889 }
204890 j++;
204891 }
@@ -205097,10 +205530,11 @@
205097 if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
205098 jsonBlobAppendOneByte(pParse, JSONB_NULL);
205099 return i+4;
205100 }
205101 /* fall-through into the default case that checks for NaN */
 
205102 }
205103 default: {
205104 u32 k;
205105 int nn;
205106 c = z[i];
@@ -205181,10 +205615,14 @@
205181 */
205182 static void jsonReturnStringAsBlob(JsonString *pStr){
205183 JsonParse px;
205184 memset(&px, 0, sizeof(px));
205185 jsonStringTerminate(pStr);
 
 
 
 
205186 px.zJson = pStr->zBuf;
205187 px.nJson = pStr->nUsed;
205188 px.db = sqlite3_context_db_handle(pStr->pCtx);
205189 (void)jsonTranslateTextToBlob(&px, 0);
205190 if( px.oom ){
@@ -205361,11 +205799,11 @@
205361 u32 k;
205362 u32 sz2 = sz;
205363 zIn = (const char*)&pParse->aBlob[i+n];
205364 jsonAppendChar(pOut, '"');
205365 while( sz2>0 ){
205366 for(k=0; k<sz2 && zIn[k]!='\\' && zIn[k]!='"'; k++){}
205367 if( k>0 ){
205368 jsonAppendRawNZ(pOut, zIn, k);
205369 if( k>=sz2 ){
205370 break;
205371 }
@@ -205373,10 +205811,17 @@
205373 sz2 -= k;
205374 }
205375 if( zIn[0]=='"' ){
205376 jsonAppendRawNZ(pOut, "\\\"", 2);
205377 zIn++;
 
 
 
 
 
 
 
205378 sz2--;
205379 continue;
205380 }
205381 assert( zIn[0]=='\\' );
205382 assert( sz2>=1 );
@@ -206506,12 +206951,13 @@
206506 ** See for example https://sqlite.org/forum/forumpost/012136abd5292b8d
206507 */
206508 }
206509 p->zJson = (char*)sqlite3_value_text(pArg);
206510 p->nJson = sqlite3_value_bytes(pArg);
 
206511 if( p->nJson==0 ) goto json_pfa_malformed;
206512 if( NEVER(p->zJson==0) ) goto json_pfa_oom;
206513 if( jsonConvertTextToBlob(p, (flgs & JSON_KEEPERROR) ? 0 : ctx) ){
206514 if( flgs & JSON_KEEPERROR ){
206515 p->nErr = 1;
206516 return p;
206517 }else{
@@ -206673,14 +207119,14 @@
206673 }
206674 if( showContent ){
206675 if( sz==0 && x<=JSONB_FALSE ){
206676 sqlite3_str_append(pOut, "\n", 1);
206677 }else{
206678 u32 i;
206679 sqlite3_str_appendall(pOut, ": \"");
206680 for(i=iStart+n; i<iStart+n+sz; i++){
206681 u8 c = pParse->aBlob[i];
206682 if( c<0x20 || c>=0x7f ) c = '.';
206683 sqlite3_str_append(pOut, (char*)&c, 1);
206684 }
206685 sqlite3_str_append(pOut, "\"\n", 2);
206686 }
@@ -206727,15 +207173,16 @@
206727 sqlite3StrAccumInit(&out, 0, 0, 0, 1000000);
206728 p = jsonParseFuncArg(ctx, argv[0], 0);
206729 if( p==0 ) return;
206730 if( argc==1 ){
206731 jsonDebugPrintBlob(p, 0, p->nBlob, 0, &out);
206732 sqlite3_result_text64(ctx, out.zText, out.nChar, SQLITE_DYNAMIC, SQLITE_UTF8);
206733 }else{
206734 jsonShowParse(p);
206735 }
206736 jsonParseFree(p);
 
206737 }
206738 #endif /* SQLITE_DEBUG */
206739
206740 /****************************************************************************
206741 ** Scalar SQL function implementations
@@ -208084,10 +208531,13 @@
208084 break;
208085 }
208086 case JEACH_VALUE: {
208087 u32 i = jsonSkipLabel(p);
208088 jsonReturnFromBlob(&p->sParse, i, ctx, 1);
 
 
 
208089 break;
208090 }
208091 case JEACH_TYPE: {
208092 u32 i = jsonSkipLabel(p);
208093 u8 eType = p->sParse.aBlob[i] & 0x0f;
@@ -209158,15 +209608,13 @@
209158
209159 /*
209160 ** Clear the Rtree.pNodeBlob object
209161 */
209162 static void nodeBlobReset(Rtree *pRtree){
209163 if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){
209164 sqlite3_blob *pBlob = pRtree->pNodeBlob;
209165 pRtree->pNodeBlob = 0;
209166 sqlite3_blob_close(pBlob);
209167 }
209168 }
209169
209170 /*
209171 ** Obtain a reference to an r-tree node.
209172 */
@@ -209206,11 +209654,10 @@
209206 rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, pRtree->zNodeName,
209207 "data", iNode, 0,
209208 &pRtree->pNodeBlob);
209209 }
209210 if( rc ){
209211 nodeBlobReset(pRtree);
209212 *ppNode = 0;
209213 /* If unable to open an sqlite3_blob on the desired row, that can only
209214 ** be because the shadow tables hold erroneous data. */
209215 if( rc==SQLITE_ERROR ){
209216 rc = SQLITE_CORRUPT_VTAB;
@@ -209266,10 +209713,11 @@
209266 rc = SQLITE_CORRUPT_VTAB;
209267 RTREE_IS_CORRUPT(pRtree);
209268 }
209269 *ppNode = pNode;
209270 }else{
 
209271 if( pNode ){
209272 pRtree->nNodeRef--;
209273 sqlite3_free(pNode);
209274 }
209275 *ppNode = 0;
@@ -209410,10 +209858,11 @@
209410 RtreeNode *pNode, /* The node from which to extract a coordinate */
209411 int iCell, /* The index of the cell within the node */
209412 int iCoord, /* Which coordinate to extract */
209413 RtreeCoord *pCoord /* OUT: Space to write result to */
209414 ){
 
209415 readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
209416 }
209417
209418 /*
209419 ** Deserialize cell iCell of node pNode. Populate the structure pointed
@@ -209599,11 +210048,13 @@
209599 assert( pRtree->nCursor>0 );
209600 resetCursor(pCsr);
209601 sqlite3_finalize(pCsr->pReadAux);
209602 sqlite3_free(pCsr);
209603 pRtree->nCursor--;
209604 nodeBlobReset(pRtree);
 
 
209605 return SQLITE_OK;
209606 }
209607
209608 /*
209609 ** Rtree virtual table module xEof method.
@@ -210184,11 +210635,15 @@
210184 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
210185 RtreeSearchPoint *p = rtreeSearchPointFirst(pCsr);
210186 int rc = SQLITE_OK;
210187 RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
210188 if( rc==SQLITE_OK && ALWAYS(p) ){
210189 *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
 
 
 
 
210190 }
210191 return rc;
210192 }
210193
210194 /*
@@ -210202,10 +210657,11 @@
210202 int rc = SQLITE_OK;
210203 RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
210204
210205 if( rc ) return rc;
210206 if( NEVER(p==0) ) return SQLITE_OK;
 
210207 if( i==0 ){
210208 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
210209 }else if( i<=pRtree->nDim2 ){
210210 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
210211 #ifndef SQLITE_RTREE_INT_ONLY
@@ -211684,11 +212140,11 @@
211684 ** Called when a transaction starts.
211685 */
211686 static int rtreeBeginTransaction(sqlite3_vtab *pVtab){
211687 Rtree *pRtree = (Rtree *)pVtab;
211688 assert( pRtree->inWrTrans==0 );
211689 pRtree->inWrTrans++;
211690 return SQLITE_OK;
211691 }
211692
211693 /*
211694 ** Called when a transaction completes (either by COMMIT or ROLLBACK).
@@ -211697,10 +212153,13 @@
211697 static int rtreeEndTransaction(sqlite3_vtab *pVtab){
211698 Rtree *pRtree = (Rtree *)pVtab;
211699 pRtree->inWrTrans = 0;
211700 nodeBlobReset(pRtree);
211701 return SQLITE_OK;
 
 
 
211702 }
211703
211704 /*
211705 ** The xRename method for rtree module virtual tables.
211706 */
@@ -211816,11 +212275,11 @@
211816 rtreeRowid, /* xRowid - read data */
211817 rtreeUpdate, /* xUpdate - write data */
211818 rtreeBeginTransaction, /* xBegin - begin transaction */
211819 rtreeEndTransaction, /* xSync - sync transaction */
211820 rtreeEndTransaction, /* xCommit - commit transaction */
211821 rtreeEndTransaction, /* xRollback - rollback transaction */
211822 0, /* xFindFunction - function overloading */
211823 rtreeRename, /* xRename - rename the table */
211824 rtreeSavepoint, /* xSavepoint */
211825 0, /* xRelease */
211826 0, /* xRollbackTo */
@@ -231114,10 +231573,13 @@
231114 ** sqlite3Fts5ParserARG_PDECL A parameter declaration for the %extra_argument
231115 ** sqlite3Fts5ParserARG_PARAM Code to pass %extra_argument as a subroutine parameter
231116 ** sqlite3Fts5ParserARG_STORE Code to store %extra_argument into fts5yypParser
231117 ** sqlite3Fts5ParserARG_FETCH Code to extract %extra_argument from fts5yypParser
231118 ** sqlite3Fts5ParserCTX_* As sqlite3Fts5ParserARG_ except for %extra_context
 
 
 
231119 ** fts5YYERRORSYMBOL is the code number of the error symbol. If not
231120 ** defined, then do no error processing.
231121 ** fts5YYNSTATE the combined number of states.
231122 ** fts5YYNRULE the number of rules in the grammar
231123 ** fts5YYNFTS5TOKEN Number of terminal symbols
@@ -231127,10 +231589,12 @@
231127 ** fts5YY_ERROR_ACTION The fts5yy_action[] code for syntax error
231128 ** fts5YY_ACCEPT_ACTION The fts5yy_action[] code for accept
231129 ** fts5YY_NO_ACTION The fts5yy_action[] code for no-op
231130 ** fts5YY_MIN_REDUCE Minimum value for reduce actions
231131 ** fts5YY_MAX_REDUCE Maximum value for reduce actions
 
 
231132 */
231133 #ifndef INTERFACE
231134 # define INTERFACE 1
231135 #endif
231136 /************* Begin control #defines *****************************************/
@@ -231153,10 +231617,13 @@
231153 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
231154 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
231155 #define sqlite3Fts5ParserARG_PARAM ,pParse
231156 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse=fts5yypParser->pParse;
231157 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse=pParse;
 
 
 
231158 #define sqlite3Fts5ParserCTX_SDECL
231159 #define sqlite3Fts5ParserCTX_PDECL
231160 #define sqlite3Fts5ParserCTX_PARAM
231161 #define sqlite3Fts5ParserCTX_FETCH
231162 #define sqlite3Fts5ParserCTX_STORE
@@ -231170,10 +231637,12 @@
231170 #define fts5YY_ERROR_ACTION 80
231171 #define fts5YY_ACCEPT_ACTION 81
231172 #define fts5YY_NO_ACTION 82
231173 #define fts5YY_MIN_REDUCE 83
231174 #define fts5YY_MAX_REDUCE 110
 
 
231175 /************* End control #defines *******************************************/
231176 #define fts5YY_NLOOKAHEAD ((int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])))
231177
231178 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
231179 ** otherwise.
@@ -231184,10 +231653,26 @@
231184 ** for testing.
231185 */
231186 #ifndef fts5yytestcase
231187 # define fts5yytestcase(X)
231188 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231189
231190
231191 /* Next are the tables used to determine what action to take based on the
231192 ** current state and lookahead token. These tables are used to implement
231193 ** functions that take a state number and lookahead value and return an
@@ -231345,18 +231830,13 @@
231345 #ifndef fts5YYNOERRORRECOVERY
231346 int fts5yyerrcnt; /* Shifts left before out of the error */
231347 #endif
231348 sqlite3Fts5ParserARG_SDECL /* A place to hold %extra_argument */
231349 sqlite3Fts5ParserCTX_SDECL /* A place to hold %extra_context */
231350 #if fts5YYSTACKDEPTH<=0
231351 int fts5yystksz; /* Current side of the stack */
231352 fts5yyStackEntry *fts5yystack; /* The parser's stack */
231353 fts5yyStackEntry fts5yystk0; /* First stack entry */
231354 #else
231355 fts5yyStackEntry fts5yystack[fts5YYSTACKDEPTH]; /* The parser's stack */
231356 fts5yyStackEntry *fts5yystackEnd; /* Last entry in the stack */
231357 #endif
231358 };
231359 typedef struct fts5yyParser fts5yyParser;
231360
231361 /* #include <assert.h> */
231362 #ifndef NDEBUG
@@ -231459,41 +231939,49 @@
231459 /* 27 */ "star_opt ::=",
231460 };
231461 #endif /* NDEBUG */
231462
231463
231464 #if fts5YYSTACKDEPTH<=0
231465 /*
231466 ** Try to increase the size of the parser stack. Return the number
231467 ** of errors. Return 0 on success.
231468 */
231469 static int fts5yyGrowStack(fts5yyParser *p){
 
231470 int newSize;
231471 int idx;
231472 fts5yyStackEntry *pNew;
231473
231474 newSize = p->fts5yystksz*2 + 100;
231475 idx = p->fts5yytos ? (int)(p->fts5yytos - p->fts5yystack) : 0;
231476 if( p->fts5yystack==&p->fts5yystk0 ){
231477 pNew = malloc(newSize*sizeof(pNew[0]));
231478 if( pNew ) pNew[0] = p->fts5yystk0;
 
231479 }else{
231480 pNew = realloc(p->fts5yystack, newSize*sizeof(pNew[0]));
 
231481 }
231482 if( pNew ){
231483 p->fts5yystack = pNew;
231484 p->fts5yytos = &p->fts5yystack[idx];
231485 #ifndef NDEBUG
231486 if( fts5yyTraceFILE ){
231487 fprintf(fts5yyTraceFILE,"%sStack grows from %d to %d entries.\n",
231488 fts5yyTracePrompt, p->fts5yystksz, newSize);
231489 }
231490 #endif
231491 p->fts5yystksz = newSize;
231492 }
231493 return pNew==0;
231494 }
 
 
 
 
 
 
 
231495 #endif
231496
231497 /* Datatype of the argument to the memory allocated passed as the
231498 ** second argument to sqlite3Fts5ParserAlloc() below. This can be changed by
231499 ** putting an appropriate #define in the %include section of the input
@@ -231509,28 +231997,18 @@
231509 fts5yyParser *fts5yypParser = (fts5yyParser*)fts5yypRawParser;
231510 sqlite3Fts5ParserCTX_STORE
231511 #ifdef fts5YYTRACKMAXSTACKDEPTH
231512 fts5yypParser->fts5yyhwm = 0;
231513 #endif
231514 #if fts5YYSTACKDEPTH<=0
231515 fts5yypParser->fts5yytos = NULL;
231516 fts5yypParser->fts5yystack = NULL;
231517 fts5yypParser->fts5yystksz = 0;
231518 if( fts5yyGrowStack(fts5yypParser) ){
231519 fts5yypParser->fts5yystack = &fts5yypParser->fts5yystk0;
231520 fts5yypParser->fts5yystksz = 1;
231521 }
231522 #endif
231523 #ifndef fts5YYNOERRORRECOVERY
231524 fts5yypParser->fts5yyerrcnt = -1;
231525 #endif
231526 fts5yypParser->fts5yytos = fts5yypParser->fts5yystack;
231527 fts5yypParser->fts5yystack[0].stateno = 0;
231528 fts5yypParser->fts5yystack[0].major = 0;
231529 #if fts5YYSTACKDEPTH>0
231530 fts5yypParser->fts5yystackEnd = &fts5yypParser->fts5yystack[fts5YYSTACKDEPTH-1];
231531 #endif
231532 }
231533
231534 #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
231535 /*
231536 ** This function allocates a new parser.
@@ -231640,13 +232118,30 @@
231640 /*
231641 ** Clear all secondary memory allocations from the parser
231642 */
231643 static void sqlite3Fts5ParserFinalize(void *p){
231644 fts5yyParser *pParser = (fts5yyParser*)p;
231645 while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser);
231646 #if fts5YYSTACKDEPTH<=0
231647 if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231648 #endif
231649 }
231650
231651 #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
231652 /*
@@ -231869,29 +232364,23 @@
231869 if( (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack)>fts5yypParser->fts5yyhwm ){
231870 fts5yypParser->fts5yyhwm++;
231871 assert( fts5yypParser->fts5yyhwm == (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack) );
231872 }
231873 #endif
231874 #if fts5YYSTACKDEPTH>0
231875 if( fts5yypParser->fts5yytos>fts5yypParser->fts5yystackEnd ){
231876 fts5yypParser->fts5yytos--;
231877 fts5yyStackOverflow(fts5yypParser);
231878 return;
231879 }
231880 #else
231881 if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5yypParser->fts5yystksz] ){
231882 if( fts5yyGrowStack(fts5yypParser) ){
231883 fts5yypParser->fts5yytos--;
231884 fts5yyStackOverflow(fts5yypParser);
231885 return;
231886 }
 
 
231887 }
231888 #endif
231889 if( fts5yyNewState > fts5YY_MAX_SHIFT ){
231890 fts5yyNewState += fts5YY_MIN_REDUCE - fts5YY_MIN_SHIFTREDUCE;
231891 }
231892 fts5yytos = fts5yypParser->fts5yytos;
231893 fts5yytos->stateno = fts5yyNewState;
231894 fts5yytos->major = fts5yyMajor;
231895 fts5yytos->minor.fts5yy0 = fts5yyMinor;
231896 fts5yyTraceShift(fts5yypParser, fts5yyNewState, "Shift");
231897 }
@@ -232324,23 +232813,16 @@
232324 fts5yypParser->fts5yyhwm++;
232325 assert( fts5yypParser->fts5yyhwm ==
232326 (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack));
232327 }
232328 #endif
232329 #if fts5YYSTACKDEPTH>0
232330 if( fts5yypParser->fts5yytos>=fts5yypParser->fts5yystackEnd ){
232331 fts5yyStackOverflow(fts5yypParser);
232332 break;
232333 }
232334 #else
232335 if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5yypParser->fts5yystksz-1] ){
232336 if( fts5yyGrowStack(fts5yypParser) ){
232337 fts5yyStackOverflow(fts5yypParser);
232338 break;
232339 }
232340 }
232341 #endif
232342 }
232343 fts5yyact = fts5yy_reduce(fts5yypParser,fts5yyruleno,fts5yymajor,fts5yyminor sqlite3Fts5ParserCTX_PARAM);
232344 }else if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
232345 fts5yy_shift(fts5yypParser,fts5yyact,(fts5YYCODETYPE)fts5yymajor,fts5yyminor);
232346 #ifndef fts5YYNOERRORRECOVERY
@@ -245375,27 +245857,30 @@
245375 ** a rowid of iFrom or greater.
245376 */
245377 static void fts5TokendataIterNext(Fts5Iter *pIter, int bFrom, i64 iFrom){
245378 int ii;
245379 Fts5TokenDataIter *pT = pIter->pTokenDataIter;
 
245380
245381 for(ii=0; ii<pT->nIter; ii++){
245382 Fts5Iter *p = pT->apIter[ii];
245383 if( p->base.bEof==0
245384 && (p->base.iRowid==pIter->base.iRowid || (bFrom && p->base.iRowid<iFrom))
245385 ){
245386 fts5MultiIterNext(p->pIndex, p, bFrom, iFrom);
245387 while( bFrom && p->base.bEof==0
245388 && p->base.iRowid<iFrom
245389 && p->pIndex->rc==SQLITE_OK
245390 ){
245391 fts5MultiIterNext(p->pIndex, p, 0, 0);
245392 }
245393 }
245394 }
245395
245396 fts5IterSetOutputsTokendata(pIter);
 
 
245397 }
245398
245399 /*
245400 ** If the segment-iterator passed as the first argument is at EOF, then
245401 ** set pIter->term to a copy of buffer pTerm.
@@ -250545,11 +251030,11 @@
250545 int nArg, /* Number of args */
250546 sqlite3_value **apUnused /* Function arguments */
250547 ){
250548 assert( nArg==0 );
250549 UNUSED_PARAM2(nArg, apUnused);
250550 sqlite3_result_text(pCtx, "fts5: 2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a", -1, SQLITE_TRANSIENT);
250551 }
250552
250553 /*
250554 ** Return true if zName is the extension on one of the shadow tables used
250555 ** by this module.
@@ -250584,18 +251069,19 @@
250584 UNUSED_PARAM(isQuick);
250585 rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0);
250586 if( (rc&0xff)==SQLITE_CORRUPT ){
250587 *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
250588 zSchema, zTabname);
 
250589 }else if( rc!=SQLITE_OK ){
250590 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
250591 " FTS5 table %s.%s: %s",
250592 zSchema, zTabname, sqlite3_errstr(rc));
250593 }
250594 sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
250595
250596 return SQLITE_OK;
250597 }
250598
250599 static int fts5Init(sqlite3 *db){
250600 static const sqlite3_module fts5Mod = {
250601 /* iVersion */ 4,
250602
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.46.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -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 ** 27a2113d78b35e324e9aedda7403c96c56ad.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -457,13 +457,13 @@
457 **
458 ** See also: [sqlite3_libversion()],
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.46.0"
463 #define SQLITE_VERSION_NUMBER 3046000
464 #define SQLITE_SOURCE_ID "2024-02-20 15:38:36 27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -731,10 +731,12 @@
731 ** is a valid and open [database connection].
732 ** <li> The application must not close the [database connection] specified by
733 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
734 ** <li> The application must not modify the SQL statement text passed into
735 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
736 ** <li> The application must not dereference the arrays or string pointers
737 ** passed as the 3rd and 4th callback parameters after it returns.
738 ** </ul>
739 */
740 SQLITE_API int sqlite3_exec(
741 sqlite3*, /* An open database */
742 const char *sql, /* SQL to be evaluated */
@@ -14858,11 +14860,11 @@
14860 #ifndef SQLITE_PTRSIZE
14861 # if defined(__SIZEOF_POINTER__)
14862 # define SQLITE_PTRSIZE __SIZEOF_POINTER__
14863 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
14864 defined(_M_ARM) || defined(__arm__) || defined(__x86) || \
14865 (defined(__APPLE__) && defined(__ppc__)) || \
14866 (defined(__TOS_AIX__) && !defined(__64BIT__))
14867 # define SQLITE_PTRSIZE 4
14868 # else
14869 # define SQLITE_PTRSIZE 8
14870 # endif
@@ -16569,11 +16571,11 @@
16571 #define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
16572 #define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
16573 #define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
16574 #define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
16575 #define OP_Last 32 /* jump */
16576 #define OP_IfSizeBetween 33 /* jump */
16577 #define OP_SorterSort 34 /* jump */
16578 #define OP_Sort 35 /* jump */
16579 #define OP_Rewind 36 /* jump */
16580 #define OP_SorterNext 37 /* jump */
16581 #define OP_Prev 38 /* jump */
@@ -17492,10 +17494,14 @@
17494 struct FuncDefHash {
17495 FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */
17496 };
17497 #define SQLITE_FUNC_HASH(C,L) (((C)+(L))%SQLITE_FUNC_HASH_SZ)
17498
17499 #if defined(SQLITE_USER_AUTHENTICATION)
17500 # warning "The SQLITE_USER_AUTHENTICATION extension is deprecated. \
17501 See ext/userauth/user-auth.txt for details."
17502 #endif
17503 #ifdef SQLITE_USER_AUTHENTICATION
17504 /*
17505 ** Information held in the "sqlite3" database connection object and used
17506 ** to manage user authentication.
17507 */
@@ -18368,12 +18374,11 @@
18374 #define TF_HasStat1 0x00000010 /* nRowLogEst set from sqlite_stat1 */
18375 #define TF_HasVirtual 0x00000020 /* Has one or more VIRTUAL columns */
18376 #define TF_HasStored 0x00000040 /* Has one or more STORED columns */
18377 #define TF_HasGenerated 0x00000060 /* Combo: HasVirtual + HasStored */
18378 #define TF_WithoutRowid 0x00000080 /* No rowid. PRIMARY KEY is the key */
18379 #define TF_MaybeReanalyze 0x00000100 /* Maybe run ANALYZE on this table */
 
18380 #define TF_NoVisibleRowid 0x00000200 /* No user-visible "rowid" column */
18381 #define TF_OOOHidden 0x00000400 /* Out-of-Order hidden columns */
18382 #define TF_HasNotNull 0x00000800 /* Contains NOT NULL constraints */
18383 #define TF_Shadow 0x00001000 /* True for a shadow table */
18384 #define TF_HasStat4 0x00002000 /* STAT4 info available for this table */
@@ -25336,27 +25341,88 @@
25341 }else{
25342 sqlite3_result_text(context, &zBuf[1], 10, SQLITE_TRANSIENT);
25343 }
25344 }
25345 }
25346
25347 /*
25348 ** Compute the number of days after the most recent January 1.
25349 **
25350 ** In other words, compute the zero-based day number for the
25351 ** current year:
25352 **
25353 ** Jan01 = 0, Jan02 = 1, ..., Jan31 = 30, Feb01 = 31, ...
25354 ** Dec31 = 364 or 365.
25355 */
25356 static int daysAfterJan01(DateTime *pDate){
25357 DateTime jan01 = *pDate;
25358 assert( jan01.validYMD );
25359 assert( jan01.validHMS );
25360 assert( pDate->validJD );
25361 jan01.validJD = 0;
25362 jan01.M = 1;
25363 jan01.D = 1;
25364 computeJD(&jan01);
25365 return (int)((pDate->iJD-jan01.iJD+43200000)/86400000);
25366 }
25367
25368 /*
25369 ** Return the number of days after the most recent Monday.
25370 **
25371 ** In other words, return the day of the week according
25372 ** to this code:
25373 **
25374 ** 0=Monday, 1=Tuesday, 2=Wednesday, ..., 6=Sunday.
25375 */
25376 static int daysAfterMonday(DateTime *pDate){
25377 assert( pDate->validJD );
25378 return (int)((pDate->iJD+43200000)/86400000) % 7;
25379 }
25380
25381 /*
25382 ** Return the number of days after the most recent Sunday.
25383 **
25384 ** In other words, return the day of the week according
25385 ** to this code:
25386 **
25387 ** 0=Sunday, 1=Monday, 2=Tues, ..., 6=Saturday
25388 */
25389 static int daysAfterSunday(DateTime *pDate){
25390 assert( pDate->validJD );
25391 return (int)((pDate->iJD+129600000)/86400000) % 7;
25392 }
25393
25394 /*
25395 ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
25396 **
25397 ** Return a string described by FORMAT. Conversions as follows:
25398 **
25399 ** %d day of month 01-31
25400 ** %e day of month 1-31
25401 ** %f ** fractional seconds SS.SSS
25402 ** %F ISO date. YYYY-MM-DD
25403 ** %G ISO year corresponding to %V 0000-9999.
25404 ** %g 2-digit ISO year corresponding to %V 00-99
25405 ** %H hour 00-24
25406 ** %k hour 0-24 (leading zero converted to space)
25407 ** %I hour 01-12
25408 ** %j day of year 001-366
25409 ** %J ** julian day number
25410 ** %l hour 1-12 (leading zero converted to space)
25411 ** %m month 01-12
25412 ** %M minute 00-59
25413 ** %p "am" or "pm"
25414 ** %P "AM" or "PM"
25415 ** %R time as HH:MM
25416 ** %s seconds since 1970-01-01
25417 ** %S seconds 00-59
25418 ** %T time as HH:MM:SS
25419 ** %u day of week 1-7 Monday==1, Sunday==7
25420 ** %w day of week 0-6 Sunday==0, Monday==1
25421 ** %U week of year 00-53 (First Sunday is start of week 01)
25422 ** %V week of year 01-53 (First week containing Thursday is week 01)
25423 ** %W week of year 00-53 (First Monday is start of week 01)
25424 ** %Y year 0000-9999
25425 ** %% %
25426 */
25427 static void strftimeFunc(
25428 sqlite3_context *context,
@@ -25389,19 +25455,34 @@
25455 case 'd': /* Fall thru */
25456 case 'e': {
25457 sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D);
25458 break;
25459 }
25460 case 'f': { /* Fractional seconds. (Non-standard) */
25461 double s = x.s;
25462 if( s>59.999 ) s = 59.999;
25463 sqlite3_str_appendf(&sRes, "%06.3f", s);
25464 break;
25465 }
25466 case 'F': {
25467 sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
25468 break;
25469 }
25470 case 'G': /* Fall thru */
25471 case 'g': {
25472 DateTime y = x;
25473 assert( y.validJD );
25474 /* Move y so that it is the Thursday in the same week as x */
25475 y.iJD += (3 - daysAfterMonday(&x))*86400000;
25476 y.validYMD = 0;
25477 computeYMD(&y);
25478 if( cf=='g' ){
25479 sqlite3_str_appendf(&sRes, "%02d", y.Y%100);
25480 }else{
25481 sqlite3_str_appendf(&sRes, "%04d", y.Y);
25482 }
25483 break;
25484 }
25485 case 'H':
25486 case 'k': {
25487 sqlite3_str_appendf(&sRes, cf=='H' ? "%02d" : "%2d", x.h);
25488 break;
@@ -25412,29 +25493,15 @@
25493 if( h>12 ) h -= 12;
25494 if( h==0 ) h = 12;
25495 sqlite3_str_appendf(&sRes, cf=='I' ? "%02d" : "%2d", h);
25496 break;
25497 }
25498 case 'j': { /* Day of year. Jan01==1, Jan02==2, and so forth */
25499 sqlite3_str_appendf(&sRes,"%03d",daysAfterJan01(&x)+1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25500 break;
25501 }
25502 case 'J': { /* Julian day number. (Non-standard) */
25503 sqlite3_str_appendf(&sRes,"%.16g",x.iJD/86400000.0);
25504 break;
25505 }
25506 case 'm': {
25507 sqlite3_str_appendf(&sRes,"%02d",x.M);
@@ -25473,16 +25540,36 @@
25540 }
25541 case 'T': {
25542 sqlite3_str_appendf(&sRes,"%02d:%02d:%02d", x.h, x.m, (int)x.s);
25543 break;
25544 }
25545 case 'u': /* Day of week. 1 to 7. Monday==1, Sunday==7 */
25546 case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */
25547 char c = (char)daysAfterSunday(&x) + '0';
25548 if( c=='0' && cf=='u' ) c = '7';
25549 sqlite3_str_appendchar(&sRes, 1, c);
25550 break;
25551 }
25552 case 'U': { /* Week num. 00-53. First Sun of the year is week 01 */
25553 sqlite3_str_appendf(&sRes,"%02d",
25554 (daysAfterJan01(&x)-daysAfterSunday(&x)+7)/7);
25555 break;
25556 }
25557 case 'V': { /* Week num. 01-53. First week with a Thur is week 01 */
25558 DateTime y = x;
25559 /* Adjust y so that is the Thursday in the same week as x */
25560 assert( y.validJD );
25561 y.iJD += (3 - daysAfterMonday(&x))*86400000;
25562 y.validYMD = 0;
25563 computeYMD(&y);
25564 sqlite3_str_appendf(&sRes,"%02d", daysAfterJan01(&y)/7+1);
25565 break;
25566 }
25567 case 'W': { /* Week num. 00-53. First Mon of the year is week 01 */
25568 sqlite3_str_appendf(&sRes,"%02d",
25569 (daysAfterJan01(&x)-daysAfterMonday(&x)+7)/7);
25570 break;
25571 }
25572 case 'Y': {
25573 sqlite3_str_appendf(&sRes,"%04d",x.Y);
25574 break;
25575 }
@@ -30127,10 +30214,28 @@
30214 sqlite3_mutex_leave(mem0.mutex);
30215 sqlite3_release_memory(nByte);
30216 sqlite3_mutex_enter(mem0.mutex);
30217 }
30218
30219 #ifdef SQLITE_DEBUG
30220 /*
30221 ** This routine is called whenever an out-of-memory condition is seen,
30222 ** It's only purpose to to serve as a breakpoint for gdb or similar
30223 ** code debuggers when working on out-of-memory conditions, for example
30224 ** caused by PRAGMA hard_heap_limit=N.
30225 */
30226 static SQLITE_NOINLINE void test_oom_breakpoint(void){
30227 static u64 nOomFault = 0;
30228 nOomFault++;
30229 /* The assert() is never reached in a human lifetime. It is here mostly
30230 ** to prevent code optimizers from optimizing out this function. */
30231 assert( (nOomFault>>32) < 0xffffffff );
30232 }
30233 #else
30234 # define test_oom_breakpoint(X) /* No-op for production builds */
30235 #endif
30236
30237 /*
30238 ** Do a memory allocation with statistics and alarms. Assume the
30239 ** lock is already held.
30240 */
30241 static void mallocWithAlarm(int n, void **pp){
@@ -30153,10 +30258,11 @@
30258 AtomicStore(&mem0.nearlyFull, 1);
30259 sqlite3MallocAlarm(nFull);
30260 if( mem0.hardLimit ){
30261 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
30262 if( nUsed >= mem0.hardLimit - nFull ){
30263 test_oom_breakpoint();
30264 *pp = 0;
30265 return;
30266 }
30267 }
30268 }else{
@@ -30441,10 +30547,11 @@
30547 if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >=
30548 mem0.alarmThreshold-nDiff ){
30549 sqlite3MallocAlarm(nDiff);
30550 if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){
30551 sqlite3_mutex_leave(mem0.mutex);
30552 test_oom_breakpoint();
30553 return 0;
30554 }
30555 }
30556 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
30557 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
@@ -31307,10 +31414,11 @@
31414 }
31415 #endif
31416 if( xtype==etFLOAT ){
31417 iRound = -precision;
31418 }else if( xtype==etGENERIC ){
31419 if( precision==0 ) precision = 1;
31420 iRound = precision;
31421 }else{
31422 iRound = precision+1;
31423 }
31424 sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 26 : 16);
@@ -31342,17 +31450,18 @@
31450 }else{
31451 prefix = flag_prefix;
31452 }
31453
31454 exp = s.iDP-1;
 
31455
31456 /*
31457 ** If the field type is etGENERIC, then convert to either etEXP
31458 ** or etFLOAT, as appropriate.
31459 */
31460 if( xtype==etGENERIC ){
31461 assert( precision>0 );
31462 precision--;
31463 flag_rtz = !flag_alternateform;
31464 if( exp<-4 || exp>precision ){
31465 xtype = etEXP;
31466 }else{
31467 precision = precision - exp;
@@ -35639,11 +35748,11 @@
35748 assert( i>=0 && i<sizeof(p->zBuf)-1 );
35749 p->n = sizeof(p->zBuf) - 1 - i;
35750 assert( p->n>0 );
35751 assert( p->n<sizeof(p->zBuf) );
35752 p->iDP = p->n + exp;
35753 if( iRound<=0 ){
35754 iRound = p->iDP - iRound;
35755 if( iRound==0 && p->zBuf[i+1]>='5' ){
35756 iRound = 1;
35757 p->zBuf[i--] = '0';
35758 p->n++;
@@ -36817,11 +36926,11 @@
36926 /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
36927 /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
36928 /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
36929 /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
36930 /* 32 */ "Last" OpHelp(""),
36931 /* 33 */ "IfSizeBetween" OpHelp(""),
36932 /* 34 */ "SorterSort" OpHelp(""),
36933 /* 35 */ "Sort" OpHelp(""),
36934 /* 36 */ "Rewind" OpHelp(""),
36935 /* 37 */ "SorterNext" OpHelp(""),
36936 /* 38 */ "Prev" OpHelp(""),
@@ -39260,12 +39369,16 @@
39369 **
39370 ** If the code incorrectly assumes that it is the POSIX version that is
39371 ** available, the error message will often be an empty string. Not a
39372 ** huge problem. Incorrectly concluding that the GNU version is available
39373 ** could lead to a segfault though.
39374 **
39375 ** Forum post 3f13857fa4062301 reports that the Android SDK may use
39376 ** int-type return, depending on its version.
39377 */
39378 #if (defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)) \
39379 && !defined(ANDROID) && !defined(__ANDROID__)
39380 zErr =
39381 # endif
39382 strerror_r(iErrno, aErr, sizeof(aErr)-1);
39383
39384 #elif SQLITE_THREADSAFE
@@ -53260,10 +53373,18 @@
53373 rc = sqlite3_step(pStmt);
53374 if( rc!=SQLITE_ROW ){
53375 pOut = 0;
53376 }else{
53377 sz = sqlite3_column_int64(pStmt, 0)*szPage;
53378 if( sz==0 ){
53379 sqlite3_reset(pStmt);
53380 sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
53381 rc = sqlite3_step(pStmt);
53382 if( rc==SQLITE_ROW ){
53383 sz = sqlite3_column_int64(pStmt, 0)*szPage;
53384 }
53385 }
53386 if( piSize ) *piSize = sz;
53387 if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
53388 pOut = 0;
53389 }else{
53390 pOut = sqlite3_malloc64( sz );
@@ -70281,12 +70402,51 @@
70402 # define SQLITE_CORRUPT_PAGE(pMemPage) corruptPageError(__LINE__, pMemPage)
70403 #else
70404 # define SQLITE_CORRUPT_PAGE(pMemPage) SQLITE_CORRUPT_PGNO(pMemPage->pgno)
70405 #endif
70406
70407 /* Default value for SHARED_LOCK_TRACE macro if shared-cache is disabled
70408 ** or if the lock tracking is disabled. This is always the value for
70409 ** release builds.
70410 */
70411 #define SHARED_LOCK_TRACE(X,MSG,TAB,TYPE) /*no-op*/
70412
70413 #ifndef SQLITE_OMIT_SHARED_CACHE
70414
70415 #if 0
70416 /* ^---- Change to 1 and recompile to enable shared-lock tracing
70417 ** for debugging purposes.
70418 **
70419 ** Print all shared-cache locks on a BtShared. Debugging use only.
70420 */
70421 static void sharedLockTrace(
70422 BtShared *pBt,
70423 const char *zMsg,
70424 int iRoot,
70425 int eLockType
70426 ){
70427 BtLock *pLock;
70428 if( iRoot>0 ){
70429 printf("%s-%p %u%s:", zMsg, pBt, iRoot, eLockType==READ_LOCK?"R":"W");
70430 }else{
70431 printf("%s-%p:", zMsg, pBt);
70432 }
70433 for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
70434 printf(" %p/%u%s", pLock->pBtree, pLock->iTable,
70435 pLock->eLock==READ_LOCK ? "R" : "W");
70436 while( pLock->pNext && pLock->pBtree==pLock->pNext->pBtree ){
70437 pLock = pLock->pNext;
70438 printf(",%u%s", pLock->iTable, pLock->eLock==READ_LOCK ? "R" : "W");
70439 }
70440 }
70441 printf("\n");
70442 fflush(stdout);
70443 }
70444 #undef SHARED_LOCK_TRACE
70445 #define SHARED_LOCK_TRACE(X,MSG,TAB,TYPE) sharedLockTrace(X,MSG,TAB,TYPE)
70446 #endif /* Shared-lock tracing */
70447
70448 #ifdef SQLITE_DEBUG
70449 /*
70450 **** This function is only used as part of an assert() statement. ***
70451 **
70452 ** Check to see if pBtree holds the required locks to read or write to the
@@ -70358,10 +70518,12 @@
70518 }
70519 }
70520 }else{
70521 iTab = iRoot;
70522 }
70523
70524 SHARED_LOCK_TRACE(pBtree->pBt,"hasLock",iRoot,eLockType);
70525
70526 /* Search for the required lock. Either a write-lock on root-page iTab, a
70527 ** write-lock on the schema table, or (if the client is reading) a
70528 ** read-lock on iTab will suffice. Return 1 if any of these are found. */
70529 for(pLock=pBtree->pBt->pLock; pLock; pLock=pLock->pNext){
@@ -70492,10 +70654,12 @@
70654 static int setSharedCacheTableLock(Btree *p, Pgno iTable, u8 eLock){
70655 BtShared *pBt = p->pBt;
70656 BtLock *pLock = 0;
70657 BtLock *pIter;
70658
70659 SHARED_LOCK_TRACE(pBt,"setLock", iTable, eLock);
70660
70661 assert( sqlite3BtreeHoldsMutex(p) );
70662 assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
70663 assert( p->db!=0 );
70664
70665 /* A connection with the read-uncommitted flag set will never try to
@@ -70559,10 +70723,12 @@
70723
70724 assert( sqlite3BtreeHoldsMutex(p) );
70725 assert( p->sharable || 0==*ppIter );
70726 assert( p->inTrans>0 );
70727
70728 SHARED_LOCK_TRACE(pBt, "clearAllLocks", 0, 0);
70729
70730 while( *ppIter ){
70731 BtLock *pLock = *ppIter;
70732 assert( (pBt->btsFlags & BTS_EXCLUSIVE)==0 || pBt->pWriter==pLock->pBtree );
70733 assert( pLock->pBtree->inTrans>=pLock->eLock );
70734 if( pLock->pBtree==p ){
@@ -70597,10 +70763,13 @@
70763 /*
70764 ** This function changes all write-locks held by Btree p into read-locks.
70765 */
70766 static void downgradeAllSharedCacheTableLocks(Btree *p){
70767 BtShared *pBt = p->pBt;
70768
70769 SHARED_LOCK_TRACE(pBt, "downgradeLocks", 0, 0);
70770
70771 if( pBt->pWriter==p ){
70772 BtLock *pLock;
70773 pBt->pWriter = 0;
70774 pBt->btsFlags &= ~(BTS_EXCLUSIVE|BTS_PENDING);
70775 for(pLock=pBt->pLock; pLock; pLock=pLock->pNext){
@@ -75210,13 +75379,16 @@
75379 if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
75380 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
75381 if( pCur->aOverflow==0
75382 || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow)
75383 ){
75384 Pgno *aNew;
75385 if( sqlite3FaultSim(413) ){
75386 aNew = 0;
75387 }else{
75388 aNew = (Pgno*)sqlite3Realloc(pCur->aOverflow, nOvfl*2*sizeof(Pgno));
75389 }
75390 if( aNew==0 ){
75391 return SQLITE_NOMEM_BKPT;
75392 }else{
75393 pCur->aOverflow = aNew;
75394 }
@@ -76261,14 +76433,14 @@
76433 u8 i;
76434
76435 assert( cursorOwnsBtShared(pCur) );
76436 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
76437
76438 /* Currently this interface is only called by the OP_IfSizeBetween
76439 ** opcode and the OP_Count opcode with P3=1. In either case,
76440 ** the cursor will always be valid unless the btree is empty. */
76441 if( pCur->eState!=CURSOR_VALID ) return 0;
76442 if( NEVER(pCur->pPage->leaf==0) ) return -1;
76443
76444 n = pCur->pPage->nCell;
76445 for(i=0; i<pCur->iPage; i++){
76446 n *= pCur->apPage[i]->nCell;
@@ -78392,11 +78564,11 @@
78564
78565 /* Verify that all sibling pages are of the same "type" (table-leaf,
78566 ** table-interior, index-leaf, or index-interior).
78567 */
78568 if( pOld->aData[0]!=apOld[0]->aData[0] ){
78569 rc = SQLITE_CORRUPT_PAGE(pOld);
78570 goto balance_cleanup;
78571 }
78572
78573 /* Load b.apCell[] with pointers to all cells in pOld. If pOld
78574 ** contains overflow cells, include them in the b.apCell[] array
@@ -78416,11 +78588,11 @@
78588 ** first.
78589 */
78590 memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow));
78591 if( pOld->nOverflow>0 ){
78592 if( NEVER(limit<pOld->aiOvfl[0]) ){
78593 rc = SQLITE_CORRUPT_PAGE(pOld);
78594 goto balance_cleanup;
78595 }
78596 limit = pOld->aiOvfl[0];
78597 for(j=0; j<limit; j++){
78598 b.apCell[b.nCell] = aData + (maskPage & get2byteAligned(piCell));
@@ -79059,11 +79231,11 @@
79231 for(pOther=pCur->pBt->pCursor; pOther; pOther=pOther->pNext){
79232 if( pOther!=pCur
79233 && pOther->eState==CURSOR_VALID
79234 && pOther->pPage==pCur->pPage
79235 ){
79236 return SQLITE_CORRUPT_PAGE(pCur->pPage);
79237 }
79238 }
79239 return SQLITE_OK;
79240 }
79241
@@ -79119,11 +79291,11 @@
79291 }
79292 }else if( sqlite3PagerPageRefcount(pPage->pDbPage)>1 ){
79293 /* The page being written is not a root page, and there is currently
79294 ** more than one reference to it. This only happens if the page is one
79295 ** of its own ancestor pages. Corruption. */
79296 rc = SQLITE_CORRUPT_PAGE(pPage);
79297 }else{
79298 MemPage * const pParent = pCur->apPage[iPage-1];
79299 int const iIdx = pCur->aiIdx[iPage-1];
79300
79301 rc = sqlite3PagerWrite(pParent->pDbPage);
@@ -79283,11 +79455,11 @@
79455 ovflPageSize = pBt->usableSize - 4;
79456 do{
79457 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
79458 if( rc ) return rc;
79459 if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){
79460 rc = SQLITE_CORRUPT_PAGE(pPage);
79461 }else{
79462 if( iOffset+ovflPageSize<(u32)nTotal ){
79463 ovflPgno = get4byte(pPage->aData);
79464 }else{
79465 ovflPageSize = nTotal - iOffset;
@@ -79311,11 +79483,11 @@
79483 MemPage *pPage = pCur->pPage; /* Page being written */
79484
79485 if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
79486 || pCur->info.pPayload < pPage->aData + pPage->cellOffset
79487 ){
79488 return SQLITE_CORRUPT_PAGE(pPage);
79489 }
79490 if( pCur->info.nLocal==nTotal ){
79491 /* The entire cell is local */
79492 return btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
79493 0, pCur->info.nLocal);
@@ -79392,11 +79564,11 @@
79564 /* This can only happen if the schema is corrupt such that there is more
79565 ** than one table or index with the same root page as used by the cursor.
79566 ** Which can only happen if the SQLITE_NoSchemaError flag was set when
79567 ** the schema was loaded. This cannot be asserted though, as a user might
79568 ** set the flag, load the schema, and then unset the flag. */
79569 return SQLITE_CORRUPT_PGNO(pCur->pgnoRoot);
79570 }
79571 }
79572
79573 /* Ensure that the cursor is not in the CURSOR_FAULT state and that it
79574 ** points to a valid cell.
@@ -79515,11 +79687,11 @@
79687 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
79688 assert( pPage->leaf || !pPage->intKey );
79689 if( pPage->nFree<0 ){
79690 if( NEVER(pCur->eState>CURSOR_INVALID) ){
79691 /* ^^^^^--- due to the moveToRoot() call above */
79692 rc = SQLITE_CORRUPT_PAGE(pPage);
79693 }else{
79694 rc = btreeComputeFreeSpace(pPage);
79695 }
79696 if( rc ) return rc;
79697 }
@@ -79554,11 +79726,11 @@
79726 pCur->info.nSize = 0;
79727 if( loc==0 ){
79728 CellInfo info;
79729 assert( idx>=0 );
79730 if( idx>=pPage->nCell ){
79731 return SQLITE_CORRUPT_PAGE(pPage);
79732 }
79733 rc = sqlite3PagerWrite(pPage->pDbPage);
79734 if( rc ){
79735 goto end_insert;
79736 }
@@ -79581,14 +79753,14 @@
79753 ** This optimization cannot be used on an autovacuum database if the
79754 ** new entry uses overflow pages, as the insertCell() call below is
79755 ** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry. */
79756 assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */
79757 if( oldCell < pPage->aData+pPage->hdrOffset+10 ){
79758 return SQLITE_CORRUPT_PAGE(pPage);
79759 }
79760 if( oldCell+szNew > pPage->aDataEnd ){
79761 return SQLITE_CORRUPT_PAGE(pPage);
79762 }
79763 memcpy(oldCell, newCell, szNew);
79764 return SQLITE_OK;
79765 }
79766 dropCell(pPage, idx, info.nSize, &rc);
@@ -79686,11 +79858,11 @@
79858 }
79859 if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
79860 nIn = pSrc->info.nLocal;
79861 aIn = pSrc->info.pPayload;
79862 if( aIn+nIn>pSrc->pPage->aDataEnd ){
79863 return SQLITE_CORRUPT_PAGE(pSrc->pPage);
79864 }
79865 nRem = pSrc->info.nPayload;
79866 if( nIn==nRem && nIn<pDest->pPage->maxLocal ){
79867 memcpy(aOut, aIn, nIn);
79868 pBt->nPreformatSize = nIn + (aOut - pBt->pTmpSpace);
@@ -79711,11 +79883,11 @@
79883 pBt->nPreformatSize += 4;
79884 }
79885
79886 if( nRem>nIn ){
79887 if( aIn+nIn+4>pSrc->pPage->aDataEnd ){
79888 return SQLITE_CORRUPT_PAGE(pSrc->pPage);
79889 }
79890 ovflIn = get4byte(&pSrc->info.pPayload[nIn]);
79891 }
79892
79893 do {
@@ -79807,27 +79979,27 @@
79979 if( pCur->eState>=CURSOR_REQUIRESEEK ){
79980 rc = btreeRestoreCursorPosition(pCur);
79981 assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
79982 if( rc || pCur->eState!=CURSOR_VALID ) return rc;
79983 }else{
79984 return SQLITE_CORRUPT_PGNO(pCur->pgnoRoot);
79985 }
79986 }
79987 assert( pCur->eState==CURSOR_VALID );
79988
79989 iCellDepth = pCur->iPage;
79990 iCellIdx = pCur->ix;
79991 pPage = pCur->pPage;
79992 if( pPage->nCell<=iCellIdx ){
79993 return SQLITE_CORRUPT_PAGE(pPage);
79994 }
79995 pCell = findCell(pPage, iCellIdx);
79996 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
79997 return SQLITE_CORRUPT_PAGE(pPage);
79998 }
79999 if( pCell<&pPage->aCellIdx[pPage->nCell] ){
80000 return SQLITE_CORRUPT_PAGE(pPage);
80001 }
80002
80003 /* If the BTREE_SAVEPOSITION bit is on, then the cursor position must
80004 ** be preserved following this delete operation. If the current delete
80005 ** will cause a b-tree rebalance, then this is done by saving the cursor
@@ -79914,11 +80086,11 @@
80086 n = pCur->apPage[iCellDepth+1]->pgno;
80087 }else{
80088 n = pCur->pPage->pgno;
80089 }
80090 pCell = findCell(pLeaf, pLeaf->nCell-1);
80091 if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_PAGE(pLeaf);
80092 nCell = pLeaf->xCellSize(pLeaf, pCell);
80093 assert( MX_CELL_SIZE(pBt) >= nCell );
80094 pTmp = pBt->pTmpSpace;
80095 assert( pTmp!=0 );
80096 rc = sqlite3PagerWrite(pLeaf->pDbPage);
@@ -80030,11 +80202,11 @@
80202 ** root page of the new table should go. meta[3] is the largest root-page
80203 ** created so far, so the new root-page is (meta[3]+1).
80204 */
80205 sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
80206 if( pgnoRoot>btreePagecount(pBt) ){
80207 return SQLITE_CORRUPT_PGNO(pgnoRoot);
80208 }
80209 pgnoRoot++;
80210
80211 /* The new root-page may not be allocated on a pointer-map page, or the
80212 ** PENDING_BYTE page.
@@ -80078,11 +80250,11 @@
80250 if( rc!=SQLITE_OK ){
80251 return rc;
80252 }
80253 rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
80254 if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
80255 rc = SQLITE_CORRUPT_PGNO(pgnoRoot);
80256 }
80257 if( rc!=SQLITE_OK ){
80258 releasePage(pRoot);
80259 return rc;
80260 }
@@ -80168,18 +80340,18 @@
80340 int hdr;
80341 CellInfo info;
80342
80343 assert( sqlite3_mutex_held(pBt->mutex) );
80344 if( pgno>btreePagecount(pBt) ){
80345 return SQLITE_CORRUPT_PGNO(pgno);
80346 }
80347 rc = getAndInitPage(pBt, pgno, &pPage, 0);
80348 if( rc ) return rc;
80349 if( (pBt->openFlags & BTREE_SINGLE)==0
80350 && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
80351 ){
80352 rc = SQLITE_CORRUPT_PAGE(pPage);
80353 goto cleardatabasepage_out;
80354 }
80355 hdr = pPage->hdrOffset;
80356 for(i=0; i<pPage->nCell; i++){
80357 pCell = findCell(pPage, i);
@@ -80279,11 +80451,11 @@
80451
80452 assert( sqlite3BtreeHoldsMutex(p) );
80453 assert( p->inTrans==TRANS_WRITE );
80454 assert( iTable>=2 );
80455 if( iTable>btreePagecount(pBt) ){
80456 return SQLITE_CORRUPT_PGNO(iTable);
80457 }
80458
80459 rc = sqlite3BtreeClearTable(p, iTable, 0);
80460 if( rc ) return rc;
80461 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
@@ -83920,32 +84092,52 @@
84092 }
84093 return rc;
84094 }
84095
84096 /* Handle negative integers in a single step. This is needed in the
84097 ** case when the value is -9223372036854775808. Except - do not do this
84098 ** for hexadecimal literals. */
84099 if( op==TK_UMINUS ){
84100 Expr *pLeft = pExpr->pLeft;
84101 if( (pLeft->op==TK_INTEGER || pLeft->op==TK_FLOAT) ){
84102 if( ExprHasProperty(pLeft, EP_IntValue)
84103 || pLeft->u.zToken[0]!='0' || (pLeft->u.zToken[1] & ~0x20)!='X'
84104 ){
84105 pExpr = pLeft;
84106 op = pExpr->op;
84107 negInt = -1;
84108 zNeg = "-";
84109 }
84110 }
84111 }
84112
84113 if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
84114 pVal = valueNew(db, pCtx);
84115 if( pVal==0 ) goto no_mem;
84116 if( ExprHasProperty(pExpr, EP_IntValue) ){
84117 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
84118 }else{
84119 i64 iVal;
84120 if( op==TK_INTEGER && 0==sqlite3DecOrHexToI64(pExpr->u.zToken, &iVal) ){
84121 sqlite3VdbeMemSetInt64(pVal, iVal*negInt);
84122 }else{
84123 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
84124 if( zVal==0 ) goto no_mem;
84125 sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
84126 }
84127 }
84128 if( affinity==SQLITE_AFF_BLOB ){
84129 if( op==TK_FLOAT ){
84130 assert( pVal && pVal->z && pVal->flags==(MEM_Str|MEM_Term) );
84131 sqlite3AtoF(pVal->z, &pVal->u.r, pVal->n, SQLITE_UTF8);
84132 pVal->flags = MEM_Real;
84133 }else if( op==TK_INTEGER ){
84134 /* This case is required by -9223372036854775808 and other strings
84135 ** that look like integers but cannot be handled by the
84136 ** sqlite3DecOrHexToI64() call above. */
84137 sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
84138 }
84139 }else{
84140 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
84141 }
84142 assert( (pVal->flags & MEM_IntReal)==0 );
84143 if( pVal->flags & (MEM_Int|MEM_IntReal|MEM_Real) ){
@@ -94641,11 +94833,11 @@
94833 }
94834 break;
94835 }
94836 #endif
94837
94838 #if !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_ANALYZE)
94839 /* Opcode: Cast P1 P2 * * *
94840 ** Synopsis: affinity(r[P1])
94841 **
94842 ** Force the value in register P1 to be the type defined by P2.
94843 **
@@ -94856,20 +95048,24 @@
95048 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
95049 applyNumericAffinity(pIn3,0);
95050 }
95051 }
95052 }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
95053 if( (flags1 & MEM_Str)!=0 ){
95054 pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
95055 }else if( (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95056 testcase( pIn1->flags & MEM_Int );
95057 testcase( pIn1->flags & MEM_Real );
95058 testcase( pIn1->flags & MEM_IntReal );
95059 sqlite3VdbeMemStringify(pIn1, encoding, 1);
95060 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
95061 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
95062 if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
95063 }
95064 if( (flags3 & MEM_Str)!=0 ){
95065 pIn3->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
95066 }else if( (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
95067 testcase( pIn3->flags & MEM_Int );
95068 testcase( pIn3->flags & MEM_Real );
95069 testcase( pIn3->flags & MEM_IntReal );
95070 sqlite3VdbeMemStringify(pIn3, encoding, 1);
95071 testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) );
@@ -96209,15 +96405,20 @@
96405 len = sqlite3SmallTypeSizes[serial_type];
96406 assert( len>=1 && len<=8 && len!=5 && len!=7 );
96407 switch( len ){
96408 default: zPayload[7] = (u8)(v&0xff); v >>= 8;
96409 zPayload[6] = (u8)(v&0xff); v >>= 8;
96410 /* no break */ deliberate_fall_through
96411 case 6: zPayload[5] = (u8)(v&0xff); v >>= 8;
96412 zPayload[4] = (u8)(v&0xff); v >>= 8;
96413 /* no break */ deliberate_fall_through
96414 case 4: zPayload[3] = (u8)(v&0xff); v >>= 8;
96415 /* no break */ deliberate_fall_through
96416 case 3: zPayload[2] = (u8)(v&0xff); v >>= 8;
96417 /* no break */ deliberate_fall_through
96418 case 2: zPayload[1] = (u8)(v&0xff); v >>= 8;
96419 /* no break */ deliberate_fall_through
96420 case 1: zPayload[0] = (u8)(v&0xff);
96421 }
96422 zPayload += len;
96423 }
96424 }else if( serial_type<0x80 ){
@@ -98738,32 +98939,41 @@
98939 if( res ) goto jump_to_p2;
98940 }
98941 break;
98942 }
98943
98944 /* Opcode: IfSizeBetween P1 P2 P3 P4 *
98945 **
98946 ** Let N be the approximate number of rows in the table or index
98947 ** with cursor P1 and let X be 10*log2(N) if N is positive or -1
98948 ** if N is zero. Thus X will be within the range of -1 to 640, inclusive
98949 ** Jump to P2 if X is in between P3 and P4, inclusive.
98950 */
98951 case OP_IfSizeBetween: { /* jump */
98952 VdbeCursor *pC;
98953 BtCursor *pCrsr;
98954 int res;
98955 i64 sz;
98956
98957 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
98958 assert( pOp->p4type==P4_INT32 );
98959 assert( pOp->p3>=-1 && pOp->p3<=640 );
98960 assert( pOp->p4.i>=-1 && pOp->p4.i<=640 );
98961 pC = p->apCsr[pOp->p1];
98962 assert( pC!=0 );
98963 pCrsr = pC->uc.pCursor;
98964 assert( pCrsr );
98965 rc = sqlite3BtreeFirst(pCrsr, &res);
98966 if( rc ) goto abort_due_to_error;
98967 if( res!=0 ){
98968 sz = -1; /* -Infinity encoding */
98969 }else{
98970 sz = sqlite3BtreeRowCountEst(pCrsr);
98971 assert( sz>0 );
98972 sz = sqlite3LogEst((u64)sz);
98973 }
98974 res = sz>=pOp->p3 && sz<=pOp->p4.i;
98975 VdbeBranchTaken(res!=0,2);
98976 if( res ) goto jump_to_p2;
98977 break;
98978 }
98979
@@ -99459,42 +99669,55 @@
99669 if( rc ) goto abort_due_to_error;
99670 pOut->u.i = pgno;
99671 break;
99672 }
99673
99674 /* Opcode: SqlExec P1 P2 * P4 *
99675 **
99676 ** Run the SQL statement or statements specified in the P4 string.
99677 **
99678 ** The P1 parameter is a bitmask of options:
99679 **
99680 ** 0x0001 Disable Auth and Trace callbacks while the statements
99681 ** in P4 are running.
99682 **
99683 ** 0x0002 Set db->nAnalysisLimit to P2 while the statements in
99684 ** P4 are running.
99685 **
99686 */
99687 case OP_SqlExec: {
99688 char *zErr;
99689 #ifndef SQLITE_OMIT_AUTHORIZATION
99690 sqlite3_xauth xAuth;
99691 #endif
99692 u8 mTrace;
99693 int savedAnalysisLimit;
99694
99695 sqlite3VdbeIncrWriteCounter(p, 0);
99696 db->nSqlExec++;
99697 zErr = 0;
99698 #ifndef SQLITE_OMIT_AUTHORIZATION
99699 xAuth = db->xAuth;
99700 #endif
99701 mTrace = db->mTrace;
99702 savedAnalysisLimit = db->nAnalysisLimit;
99703 if( pOp->p1 & 0x0001 ){
99704 #ifndef SQLITE_OMIT_AUTHORIZATION
99705 db->xAuth = 0;
99706 #endif
99707 db->mTrace = 0;
99708 }
99709 if( pOp->p1 & 0x0002 ){
99710 db->nAnalysisLimit = pOp->p2;
99711 }
99712 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
99713 db->nSqlExec--;
99714 #ifndef SQLITE_OMIT_AUTHORIZATION
99715 db->xAuth = xAuth;
99716 #endif
99717 db->mTrace = mTrace;
99718 db->nAnalysisLimit = savedAnalysisLimit;
99719 if( zErr || rc ){
99720 sqlite3VdbeError(p, "%s", zErr);
99721 sqlite3_free(zErr);
99722 if( rc==SQLITE_NOMEM ) goto no_mem;
99723 goto abort_due_to_error;
@@ -99647,12 +99870,12 @@
99870 ** register P1 the text of an error message describing any problems.
99871 ** If no problems are found, store a NULL in register P1.
99872 **
99873 ** The register P3 contains one less than the maximum number of allowed errors.
99874 ** At most reg(P3) errors will be reported.
99875 ** In other words, the analysis stops as soon as reg(P3) errors are
99876 ** seen. Reg(P3) is updated with the number of errors remaining.
99877 **
99878 ** The root page numbers of all tables in the database are integers
99879 ** stored in P4_INTARRAY argument.
99880 **
99881 ** If P5 is not zero, the check is done on the auxiliary database
@@ -106210,10 +106433,12 @@
106433 sqlite3 *db; /* The database connection */
106434
106435 assert( iCol>=0 && iCol<pEList->nExpr );
106436 pOrig = pEList->a[iCol].pExpr;
106437 assert( pOrig!=0 );
106438 assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) );
106439 if( pExpr->pAggInfo ) return;
106440 db = pParse->db;
106441 pDup = sqlite3ExprDup(db, pOrig, 0);
106442 if( db->mallocFailed ){
106443 sqlite3ExprDelete(db, pDup);
106444 pDup = 0;
@@ -106408,11 +106633,11 @@
106633 */
106634 static int lookupName(
106635 Parse *pParse, /* The parsing context */
106636 const char *zDb, /* Name of the database containing table, or NULL */
106637 const char *zTab, /* Name of table containing column, or NULL */
106638 const Expr *pRight, /* Name of the column. */
106639 NameContext *pNC, /* The name context used to resolve the name */
106640 Expr *pExpr /* Make this EXPR node point to the selected column */
106641 ){
106642 int i, j; /* Loop counters */
106643 int cnt = 0; /* Number of matching column names */
@@ -106425,10 +106650,11 @@
106650 Schema *pSchema = 0; /* Schema of the expression */
106651 int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
106652 Table *pTab = 0; /* Table holding the row */
106653 Column *pCol; /* A column of pTab */
106654 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
106655 const char *zCol = pRight->u.zToken;
106656
106657 assert( pNC ); /* the name context cannot be NULL. */
106658 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
106659 assert( zDb==0 || zTab!=0 );
106660 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
@@ -106884,10 +107110,14 @@
107110 zErr = cnt==0 ? "no such column" : "ambiguous column name";
107111 if( zDb ){
107112 sqlite3ErrorMsg(pParse, "%s: %s.%s.%s", zErr, zDb, zTab, zCol);
107113 }else if( zTab ){
107114 sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
107115 }else if( cnt==0 && ExprHasProperty(pRight,EP_DblQuoted) ){
107116 sqlite3ErrorMsg(pParse, "%s: \"%s\" - should this be a"
107117 " string literal in single-quotes?",
107118 zErr, zCol);
107119 }else{
107120 sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
107121 }
107122 sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr);
107123 pParse->checkSchema = 1;
@@ -107131,20 +107361,19 @@
107361 ** be one call to lookupName(). Then the compiler will in-line
107362 ** lookupName() for a size reduction and performance increase.
107363 */
107364 case TK_ID:
107365 case TK_DOT: {
 
107366 const char *zTable;
107367 const char *zDb;
107368 Expr *pRight;
107369
107370 if( pExpr->op==TK_ID ){
107371 zDb = 0;
107372 zTable = 0;
107373 assert( !ExprHasProperty(pExpr, EP_IntValue) );
107374 pRight = pExpr;
107375 }else{
107376 Expr *pLeft = pExpr->pLeft;
107377 testcase( pNC->ncFlags & NC_IdxExpr );
107378 testcase( pNC->ncFlags & NC_GenCol );
107379 sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
@@ -107159,18 +107388,17 @@
107388 pLeft = pRight->pLeft;
107389 pRight = pRight->pRight;
107390 }
107391 assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) );
107392 zTable = pLeft->u.zToken;
 
107393 assert( ExprUseYTab(pExpr) );
107394 if( IN_RENAME_OBJECT ){
107395 sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
107396 sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
107397 }
107398 }
107399 return lookupName(pParse, zDb, zTable, pRight, pNC, pExpr);
107400 }
107401
107402 /* Resolve function names
107403 */
107404 case TK_FUNCTION: {
@@ -118538,11 +118766,11 @@
118766 u64 nDistinct = p->current.anDLt[i] + 1;
118767 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
118768 if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
118769 sqlite3_str_appendf(&sStat, " %llu", iVal);
118770 #ifdef SQLITE_ENABLE_STAT4
118771 assert( p->current.anEq[i] || p->nRow==0 );
118772 #endif
118773 }
118774 sqlite3ResultStrAccum(context, &sStat);
118775 }
118776 #ifdef SQLITE_ENABLE_STAT4
@@ -118723,11 +118951,11 @@
118951 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
118952 sqlite3VdbeLoadString(v, regTabname, pTab->zName);
118953
118954 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
118955 int nCol; /* Number of columns in pIdx. "N" */
118956 int addrGotoEnd; /* Address of "OP_Rewind iIdxCur" */
118957 int addrNextRow; /* Address of "next_row:" */
118958 const char *zIdxName; /* Name of the index */
118959 int nColTest; /* Number of columns to test for changes */
118960
118961 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
@@ -118747,13 +118975,18 @@
118975 VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
118976
118977 /*
118978 ** Pseudo-code for loop that calls stat_push():
118979 **
118980 ** regChng = 0
118981 ** Rewind csr
118982 ** if eof(csr){
118983 ** stat_init() with count = 0;
118984 ** goto end_of_scan;
118985 ** }
118986 ** count()
118987 ** stat_init()
118988 ** goto chng_addr_0;
118989 **
118990 ** next_row:
118991 ** regChng = 0
118992 ** if( idx(0) != regPrev(0) ) goto chng_addr_0
@@ -118788,45 +119021,40 @@
119021 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
119022 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
119023 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
119024 VdbeComment((v, "%s", pIdx->zName));
119025
119026 /* Implementation of the following:
119027 **
119028 ** regChng = 0
119029 ** Rewind csr
119030 ** if eof(csr){
119031 ** stat_init() with count = 0;
119032 ** goto end_of_scan;
119033 ** }
119034 ** count()
119035 ** stat_init()
119036 ** goto chng_addr_0;
119037 */
119038 assert( regTemp2==regStat+4 );
119039 sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2);
119040
119041 /* Arguments to stat_init():
119042 ** (1) the number of columns in the index including the rowid
119043 ** (or for a WITHOUT ROWID table, the number of PK columns),
119044 ** (2) the number of columns in the key without the rowid/pk
119045 ** (3) estimated number of rows in the index. */
 
119046 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat+1);
119047 assert( regRowid==regStat+2 );
119048 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regRowid);
119049 sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp,
119050 OptimizationDisabled(db, SQLITE_Stat4));
 
 
 
 
 
 
 
 
 
 
 
 
119051 sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4,
119052 &statInitFuncdef, 0);
119053 addrGotoEnd = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
119054 VdbeCoverage(v);
119055
 
 
 
 
 
 
119056 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
119057 addrNextRow = sqlite3VdbeCurrentAddr(v);
119058
119059 if( nColTest>0 ){
119060 int endDistinctTest = sqlite3VdbeMakeLabel(pParse);
@@ -118929,10 +119157,16 @@
119157 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
119158 }
119159 }
119160
119161 /* Add the entry to the stat1 table. */
119162 if( pIdx->pPartIdxWhere ){
119163 /* Partial indexes might get a zero-entry in sqlite_stat1. But
119164 ** an empty table is omitted from sqlite_stat1. */
119165 sqlite3VdbeJumpHere(v, addrGotoEnd);
119166 addrGotoEnd = 0;
119167 }
119168 callStatGet(pParse, regStat, STAT_GET_STAT1, regStat1);
119169 assert( "BBB"[0]==SQLITE_AFF_TEXT );
119170 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
119171 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
119172 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
@@ -118951,10 +119185,16 @@
119185 int regCol = regStat1+4;
119186 int regSampleRowid = regCol + nCol;
119187 int addrNext;
119188 int addrIsNull;
119189 u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
119190
119191 /* No STAT4 data is generated if the number of rows is zero */
119192 if( addrGotoEnd==0 ){
119193 sqlite3VdbeAddOp2(v, OP_Cast, regStat1, SQLITE_AFF_INTEGER);
119194 addrGotoEnd = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
119195 }
119196
119197 if( doOnce ){
119198 int mxCol = nCol;
119199 Index *pX;
119200
@@ -119004,11 +119244,11 @@
119244 sqlite3VdbeJumpHere(v, addrIsNull);
119245 }
119246 #endif /* SQLITE_ENABLE_STAT4 */
119247
119248 /* End of analysis */
119249 if( addrGotoEnd ) sqlite3VdbeJumpHere(v, addrGotoEnd);
119250 }
119251
119252
119253 /* Create a single sqlite_stat1 entry containing NULL as the index
119254 ** name and the row count as the content.
@@ -120753,11 +120993,11 @@
120993 sqlite3VdbeJumpHere(v, addrRewind);
120994 }
120995 }
120996 sqlite3VdbeAddOp0(v, OP_Halt);
120997
120998 #if SQLITE_USER_AUTHENTICATION && !defined(SQLITE_OMIT_SHARED_CACHE)
120999 if( pParse->nTableLock>0 && db->init.busy==0 ){
121000 sqlite3UserAuthInit(db);
121001 if( db->auth.authLevel<UAUTH_User ){
121002 sqlite3ErrorMsg(pParse, "user not authenticated");
121003 pParse->rc = SQLITE_AUTH_USER;
@@ -123487,15 +123727,15 @@
123727 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName),0);
123728
123729 /* Test for cycles in generated columns and illegal expressions
123730 ** in CHECK constraints and in DEFAULT clauses. */
123731 if( p->tabFlags & TF_HasGenerated ){
123732 sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
123733 sqlite3MPrintf(db, "SELECT*FROM\"%w\".\"%w\"",
123734 db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
123735 }
123736 sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
123737 sqlite3MPrintf(db, "PRAGMA \"%w\".integrity_check(%Q)",
123738 db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
123739 }
123740
123741 /* Add the table to the in-memory representation of the database.
@@ -129253,11 +129493,11 @@
129493 || sqlite3_context_db_handle(context)->mallocFailed );
129494 return;
129495 }
129496 if( zPattern[0]==0 ){
129497 assert( sqlite3_value_type(argv[1])!=SQLITE_NULL );
129498 sqlite3_result_text(context, (const char*)zStr, nStr, SQLITE_TRANSIENT);
129499 return;
129500 }
129501 nPattern = sqlite3_value_bytes(argv[1]);
129502 assert( zPattern==sqlite3_value_text(argv[1]) ); /* No encoding change */
129503 zRep = sqlite3_value_text(argv[2]);
@@ -137740,10 +137980,38 @@
137980 /* Number of pragmas: 68 on by default, 78 total. */
137981
137982 /************** End of pragma.h **********************************************/
137983 /************** Continuing where we left off in pragma.c *********************/
137984
137985 /*
137986 ** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
137987 ** will be run with an analysis_limit set to the lessor of the value of
137988 ** the following macro or to the actual analysis_limit if it is non-zero,
137989 ** in order to prevent PRAGMA optimize from running for too long.
137990 **
137991 ** The value of 2000 is chosen emperically so that the worst-case run-time
137992 ** for PRAGMA optimize does not exceed 100 milliseconds against a variety
137993 ** of test databases on a RaspberryPI-4 compiled using -Os and without
137994 ** -DSQLITE_DEBUG. Of course, your mileage may vary. For the purpose of
137995 ** his paragraph, "worst-case" means that ANALYZE ends up being
137996 ** run on every table in the database. The worst case typically only
137997 ** happens if PRAGMA optimize is run on a database file for which ANALYZE
137998 ** has not been previously run and the 0x10000 flag is included so that
137999 ** all tables are analyzed. The usual case for PRAGMA optimize is that
138000 ** no ANALYZE commands will be run at all, or if any ANALYZE happens it
138001 ** will be against a single table, so that expected timing for PRAGMA
138002 ** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
138003 ** flag or less than 100 microseconds without the 0x10000 flag.
138004 **
138005 ** An analysis limit of 2000 is almost always sufficient for the query
138006 ** planner to fully characterize an index. The additional accuracy from
138007 ** a larger analysis is not usually helpful.
138008 */
138009 #ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT
138010 # define SQLITE_DEFAULT_OPTIMIZE_LIMIT 2000
138011 #endif
138012
138013 /*
138014 ** Interpret the given string as a safety level. Return 0 for OFF,
138015 ** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA. Return 1 for an empty or
138016 ** unrecognized string argument. The FULL and EXTRA option is disallowed
138017 ** if the omitFull parameter it 1.
@@ -139472,35 +139740,11 @@
139740 int bStrict; /* True for a STRICT table */
139741 int r2; /* Previous key for WITHOUT ROWID tables */
139742 int mxCol; /* Maximum non-virtual column number */
139743
139744 if( pObjTab && pObjTab!=pTab ) continue;
139745 if( !IsOrdinaryTable(pTab) ) continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139746 if( isQuick || HasRowid(pTab) ){
139747 pPk = 0;
139748 r2 = 0;
139749 }else{
139750 pPk = sqlite3PrimaryKeyIndex(pTab);
@@ -139631,10 +139875,11 @@
139875 /* OP_IsType does not detect NaN values in the database file
139876 ** which should be treated as a NULL. So if the header type
139877 ** is REAL, we have to load the actual data using OP_Column
139878 ** to reliably determine if the value is a NULL. */
139879 sqlite3VdbeAddOp3(v, OP_Column, p1, p3, 3);
139880 sqlite3ColumnDefault(v, pTab, j, 3);
139881 jmp3 = sqlite3VdbeAddOp2(v, OP_NotNull, 3, labelOk);
139882 VdbeCoverage(v);
139883 }
139884 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
139885 pCol->zCnName);
@@ -139821,10 +140066,42 @@
140066 if( pPk ){
140067 sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol);
140068 }
140069 }
140070 }
140071
140072 #ifndef SQLITE_OMIT_VIRTUALTABLE
140073 /* Second pass to invoke the xIntegrity method on all virtual
140074 ** tables.
140075 */
140076 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
140077 Table *pTab = sqliteHashData(x);
140078 sqlite3_vtab *pVTab;
140079 int a1;
140080 if( pObjTab && pObjTab!=pTab ) continue;
140081 if( IsOrdinaryTable(pTab) ) continue;
140082 if( !IsVirtual(pTab) ) continue;
140083 if( pTab->nCol<=0 ){
140084 const char *zMod = pTab->u.vtab.azArg[0];
140085 if( sqlite3HashFind(&db->aModule, zMod)==0 ) continue;
140086 }
140087 sqlite3ViewGetColumnNames(pParse, pTab);
140088 if( pTab->u.vtab.p==0 ) continue;
140089 pVTab = pTab->u.vtab.p->pVtab;
140090 if( NEVER(pVTab==0) ) continue;
140091 if( NEVER(pVTab->pModule==0) ) continue;
140092 if( pVTab->pModule->iVersion<4 ) continue;
140093 if( pVTab->pModule->xIntegrity==0 ) continue;
140094 sqlite3VdbeAddOp3(v, OP_VCheck, i, 3, isQuick);
140095 pTab->nTabRef++;
140096 sqlite3VdbeAppendP4(v, pTab, P4_TABLEREF);
140097 a1 = sqlite3VdbeAddOp1(v, OP_IsNull, 3); VdbeCoverage(v);
140098 integrityCheckResultRow(v);
140099 sqlite3VdbeJumpHere(v, a1);
140100 continue;
140101 }
140102 #endif
140103 }
140104 {
140105 static const int iLn = VDBE_OFFSET_LINENO(2);
140106 static const VdbeOpList endCode[] = {
140107 { OP_AddImm, 1, 0, 0}, /* 0 */
@@ -140084,48 +140361,67 @@
140361 ** to change and improve over time. Applications should anticipate that
140362 ** this pragma will perform new optimizations in future releases.
140363 **
140364 ** The optional argument is a bitmask of optimizations to perform:
140365 **
140366 ** 0x00001 Debugging mode. Do not actually perform any optimizations
140367 ** but instead return one line of text for each optimization
140368 ** that would have been done. Off by default.
140369 **
140370 ** 0x00002 Run ANALYZE on tables that might benefit. On by default.
140371 ** See below for additional information.
140372 **
140373 ** 0x00010 Run all ANALYZE operations using an analysis_limit that
140374 ** is the lessor of the current analysis_limit and the
140375 ** SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option.
140376 ** The default value of SQLITE_DEFAULT_OPTIMIZE_LIMIT is
140377 ** currently (2024-02-19) set to 2000, which is such that
140378 ** the worst case run-time for PRAGMA optimize on a 100MB
140379 ** database will usually be less than 100 milliseconds on
140380 ** a RaspberryPI-4 class machine. On by default.
140381 **
140382 ** 0x10000 Look at tables to see if they need to be reanalyzed
140383 ** due to growth or shrinkage even if they have not been
140384 ** queried during the current connection. Off by default.
140385 **
140386 ** The default MASK is and always shall be 0x0fffe. In the current
140387 ** implementation, the default mask only covers the 0x00002 optimization,
140388 ** though additional optimizations that are covered by 0x0fffe might be
140389 ** added in the future. Optimizations that are off by default and must
140390 ** be explicitly requested have masks of 0x10000 or greater.
140391 **
140392 ** DETERMINATION OF WHEN TO RUN ANALYZE
140393 **
140394 ** In the current implementation, a table is analyzed if only if all of
140395 ** the following are true:
140396 **
140397 ** (1) MASK bit 0x00002 is set.
140398 **
140399 ** (2) The table is an ordinary table, not a virtual table or view.
140400 **
140401 ** (3) The table name does not begin with "sqlite_".
140402 **
140403 ** (4) One or more of the following is true:
140404 ** (4a) The 0x10000 MASK bit is set.
140405 ** (4b) One or more indexes on the table lacks an entry
140406 ** in the sqlite_stat1 table.
140407 ** (4c) The query planner used sqlite_stat1-style statistics for one
140408 ** or more indexes of the table at some point during the lifetime
140409 ** of the current connection.
140410 **
140411 ** (5) One or more of the following is true:
140412 ** (5a) One or more indexes on the table lacks an entry
140413 ** in the sqlite_stat1 table. (Same as 4a)
140414 ** (5b) The number of rows in the table has increased or decreased by
140415 ** 10-fold. In other words, the current size of the table is
140416 ** 10 times larger than the size in sqlite_stat1 or else the
140417 ** current size is less than 1/10th the size in sqlite_stat1.
140418 **
140419 ** The rules for when tables are analyzed are likely to change in
140420 ** future releases. Future versions of SQLite might accept a string
140421 ** literal argument to this pragma that contains a mnemonic description
140422 ** of the options rather than a bitmap.
140423 */
140424 case PragTyp_OPTIMIZE: {
140425 int iDbLast; /* Loop termination point for the schema loop */
140426 int iTabCur; /* Cursor for a table whose size needs checking */
140427 HashElem *k; /* Loop over tables of a schema */
@@ -140133,56 +140429,122 @@
140429 Table *pTab; /* A table in the schema */
140430 Index *pIdx; /* An index of the table */
140431 LogEst szThreshold; /* Size threshold above which reanalysis needed */
140432 char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
140433 u32 opMask; /* Mask of operations to perform */
140434 int nLimit; /* Analysis limit to use */
140435 int nCheck = 0; /* Number of tables to be optimized */
140436 int nBtree = 0; /* Number of btrees to scan */
140437 int nIndex; /* Number of indexes on the current table */
140438
140439 if( zRight ){
140440 opMask = (u32)sqlite3Atoi(zRight);
140441 if( (opMask & 0x02)==0 ) break;
140442 }else{
140443 opMask = 0xfffe;
140444 }
140445 if( (opMask & 0x10)==0 ){
140446 nLimit = 0;
140447 }else if( db->nAnalysisLimit>0
140448 && db->nAnalysisLimit<SQLITE_DEFAULT_OPTIMIZE_LIMIT ){
140449 nLimit = 0;
140450 }else{
140451 nLimit = SQLITE_DEFAULT_OPTIMIZE_LIMIT;
140452 }
140453 iTabCur = pParse->nTab++;
140454 for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){
140455 if( iDb==1 ) continue;
140456 sqlite3CodeVerifySchema(pParse, iDb);
140457 pSchema = db->aDb[iDb].pSchema;
140458 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
140459 pTab = (Table*)sqliteHashData(k);
140460
140461 /* This only works for ordinary tables */
140462 if( !IsOrdinaryTable(pTab) ) continue;
 
 
140463
140464 /* Do not scan system tables */
140465 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue;
140466
140467 /* Find the size of the table as last recorded in sqlite_stat1.
140468 ** If any index is unanalyzed, then the threshold is -1 to
140469 ** indicate a new, unanalyzed index
140470 */
140471 szThreshold = pTab->nRowLogEst;
140472 nIndex = 0;
140473 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
140474 nIndex++;
140475 if( !pIdx->hasStat1 ){
140476 szThreshold = -1; /* Always analyze if any index lacks statistics */
 
140477 }
140478 }
140479
140480 /* If table pTab has not been used in a way that would benefit from
140481 ** having analysis statistics during the current session, then skip it,
140482 ** unless the 0x10000 MASK bit is set. */
140483 if( (pTab->tabFlags & TF_MaybeReanalyze)!=0 ){
140484 /* Check for size change if stat1 has been used for a query */
140485 }else if( opMask & 0x10000 ){
140486 /* Check for size change if 0x10000 is set */
140487 }else if( pTab->pIndex!=0 && szThreshold<0 ){
140488 /* Do analysis if unanalyzed indexes exists */
140489 }else{
140490 /* Otherwise, we can skip this table */
140491 continue;
140492 }
140493
140494 nCheck++;
140495 if( nCheck==2 ){
140496 /* If ANALYZE might be invoked two or more times, hold a write
140497 ** transaction for efficiency */
140498 sqlite3BeginWriteOperation(pParse, 0, iDb);
140499 }
140500 nBtree += nIndex+1;
140501
140502 /* Reanalyze if the table is 10 times larger or smaller than
140503 ** the last analysis. Unconditional reanalysis if there are
140504 ** unanalyzed indexes. */
140505 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
140506 if( szThreshold>=0 ){
140507 const LogEst iRange = 33; /* 10x size change */
140508 sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur,
140509 sqlite3VdbeCurrentAddr(v)+2+(opMask&1),
140510 szThreshold>=iRange ? szThreshold-iRange : -1,
140511 szThreshold+iRange);
140512 VdbeCoverage(v);
140513 }else{
140514 sqlite3VdbeAddOp2(v, OP_Rewind, iTabCur,
140515 sqlite3VdbeCurrentAddr(v)+2+(opMask&1));
140516 VdbeCoverage(v);
140517 }
140518 zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"",
140519 db->aDb[iDb].zDbSName, pTab->zName);
140520 if( opMask & 0x01 ){
140521 int r1 = sqlite3GetTempReg(pParse);
140522 sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
140523 sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1);
140524 }else{
140525 sqlite3VdbeAddOp4(v, OP_SqlExec, nLimit ? 0x02 : 00, nLimit, 0,
140526 zSubSql, P4_DYNAMIC);
140527 }
140528 }
140529 }
140530 sqlite3VdbeAddOp0(v, OP_Expire);
140531
140532 /* In a schema with a large number of tables and indexes, scale back
140533 ** the analysis_limit to avoid excess run-time in the worst case.
140534 */
140535 if( !db->mallocFailed && nLimit>0 && nBtree>100 ){
140536 int iAddr, iEnd;
140537 VdbeOp *aOp;
140538 nLimit = 100*nLimit/nBtree;
140539 if( nLimit<100 ) nLimit = 100;
140540 aOp = sqlite3VdbeGetOp(v, 0);
140541 iEnd = sqlite3VdbeCurrentAddr(v);
140542 for(iAddr=0; iAddr<iEnd; iAddr++){
140543 if( aOp[iAddr].opcode==OP_SqlExec ) aOp[iAddr].p2 = nLimit;
140544 }
140545 }
140546 break;
140547 }
140548
140549 /*
140550 ** PRAGMA busy_timeout
@@ -148175,10 +148537,12 @@
148537 /*
148538 ** Display all information about an AggInfo object
148539 */
148540 static void printAggInfo(AggInfo *pAggInfo){
148541 int ii;
148542 sqlite3DebugPrintf("AggInfo %d/%p:\n",
148543 pAggInfo->selId, pAggInfo);
148544 for(ii=0; ii<pAggInfo->nColumn; ii++){
148545 struct AggInfo_col *pCol = &pAggInfo->aCol[ii];
148546 sqlite3DebugPrintf(
148547 "agg-column[%d] pTab=%s iTable=%d iColumn=%d iMem=%d"
148548 " iSorterColumn=%d %s\n",
@@ -150277,10 +150641,16 @@
150641 assert( db->mallocFailed==0 || db->mallocFailed==1 );
150642 assert( db->mallocFailed==0 || pParse->nErr!=0 );
150643 sqlite3ExprListDelete(db, pMinMaxOrderBy);
150644 #ifdef SQLITE_DEBUG
150645 if( pAggInfo && !db->mallocFailed ){
150646 #if TREETRACE_ENABLED
150647 if( sqlite3TreeTrace & 0x20 ){
150648 TREETRACE(0x20,pParse,p,("Finished with AggInfo\n"));
150649 printAggInfo(pAggInfo);
150650 }
150651 #endif
150652 for(i=0; i<pAggInfo->nColumn; i++){
150653 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
150654 if( pExpr==0 ) continue;
150655 assert( pExpr->pAggInfo==pAggInfo );
150656 assert( pExpr->iAgg==i );
@@ -154714,10 +155084,12 @@
155084 sCtx.pPrior = db->pVtabCtx;
155085 sCtx.bDeclared = 0;
155086 db->pVtabCtx = &sCtx;
155087 pTab->nTabRef++;
155088 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
155089 assert( pTab!=0 );
155090 assert( pTab->nTabRef>1 || rc!=SQLITE_OK );
155091 sqlite3DeleteTable(db, pTab);
155092 db->pVtabCtx = sCtx.pPrior;
155093 if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
155094 assert( sCtx.pTab==pTab );
155095
@@ -154736,11 +155108,11 @@
155108 pVTable->pVtab->pModule = pMod->pModule;
155109 pMod->nRefModule++;
155110 pVTable->nRef = 1;
155111 if( sCtx.bDeclared==0 ){
155112 const char *zFormat = "vtable constructor did not declare schema: %s";
155113 *pzErr = sqlite3MPrintf(db, zFormat, zModuleName);
155114 sqlite3VtabUnlock(pVTable);
155115 rc = SQLITE_ERROR;
155116 }else{
155117 int iCol;
155118 u16 oooHidden = 0;
@@ -164129,11 +164501,13 @@
164501 if( pIndex->bUnordered ) return 0;
164502 if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
164503 for(ii=0; ii<pOB->nExpr; ii++){
164504 Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
164505 if( NEVER(pExpr==0) ) continue;
164506 if( (pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN)
164507 && pExpr->iTable==iCursor
164508 ){
164509 if( pExpr->iColumn<0 ) return 1;
164510 for(jj=0; jj<pIndex->nKeyCol; jj++){
164511 if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
164512 }
164513 }else if( (aColExpr = pIndex->aColExpr)!=0 ){
@@ -164735,11 +165109,11 @@
165109 if( pBuilder->bldFlags1==SQLITE_BLDF1_INDEXED ){
165110 /* If a non-unique index is used, or if a prefix of the key for
165111 ** unique index is used (making the index functionally non-unique)
165112 ** then the sqlite_stat1 data becomes important for scoring the
165113 ** plan */
165114 pTab->tabFlags |= TF_MaybeReanalyze;
165115 }
165116 #ifdef SQLITE_ENABLE_STAT4
165117 sqlite3Stat4ProbeFree(pBuilder->pRec);
165118 pBuilder->nRecValid = 0;
165119 pBuilder->pRec = 0;
@@ -166229,14 +166603,13 @@
166603 pWInfo->nOBSat = pFrom->isOrdered;
166604 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
166605 if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
166606 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
166607 }
166608 /* vvv--- See check-in [12ad822d9b827777] on 2023-03-16 ---vvv */
166609 assert( pWInfo->pSelect->pOrderBy==0
166610 || pWInfo->nOBSat <= pWInfo->pSelect->pOrderBy->nExpr );
 
166611 }else{
166612 pWInfo->revMask = pFrom->revLoop;
166613 if( pWInfo->nOBSat<=0 ){
166614 pWInfo->nOBSat = 0;
166615 if( nLoop>0 ){
@@ -166571,11 +166944,11 @@
166944 WhereLoop *pLoop = pWInfo->a[i].pWLoop;
166945 const unsigned int reqFlags = (WHERE_SELFCULL|WHERE_COLUMN_EQ);
166946 SrcItem *pItem = &pWInfo->pTabList->a[pLoop->iTab];
166947 Table *pTab = pItem->pTab;
166948 if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
166949 pTab->tabFlags |= TF_MaybeReanalyze;
166950 if( i>=1
166951 && (pLoop->wsFlags & reqFlags)==reqFlags
166952 /* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */
166953 && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0)
166954 ){
@@ -171056,10 +171429,18 @@
171429 sqlite3WithDelete(pParse->db, pWith);
171430 }
171431 return pSelect;
171432 }
171433
171434 /* Memory allocator for parser stack resizing. This is a thin wrapper around
171435 ** sqlite3_realloc() that includes a call to sqlite3FaultSim() to facilitate
171436 ** testing.
171437 */
171438 static void *parserStackRealloc(void *pOld, sqlite3_uint64 newSize){
171439 return sqlite3FaultSim(700) ? 0 : sqlite3_realloc(pOld, newSize);
171440 }
171441
171442
171443 /* Construct a new Expr object from a single token */
171444 static Expr *tokenExpr(Parse *pParse, int op, Token t){
171445 Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
171446 if( p ){
@@ -171357,10 +171738,13 @@
171738 ** sqlite3ParserARG_PDECL A parameter declaration for the %extra_argument
171739 ** sqlite3ParserARG_PARAM Code to pass %extra_argument as a subroutine parameter
171740 ** sqlite3ParserARG_STORE Code to store %extra_argument into yypParser
171741 ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
171742 ** sqlite3ParserCTX_* As sqlite3ParserARG_ except for %extra_context
171743 ** YYREALLOC Name of the realloc() function to use
171744 ** YYFREE Name of the free() function to use
171745 ** YYDYNSTACK True if stack space should be extended on heap
171746 ** YYERRORSYMBOL is the code number of the error symbol. If not
171747 ** defined, then do no error processing.
171748 ** YYNSTATE the combined number of states.
171749 ** YYNRULE the number of rules in the grammar
171750 ** YYNTOKEN Number of terminal symbols
@@ -171370,10 +171754,12 @@
171754 ** YY_ERROR_ACTION The yy_action[] code for syntax error
171755 ** YY_ACCEPT_ACTION The yy_action[] code for accept
171756 ** YY_NO_ACTION The yy_action[] code for no-op
171757 ** YY_MIN_REDUCE Minimum value for reduce actions
171758 ** YY_MAX_REDUCE Maximum value for reduce actions
171759 ** YY_MIN_DSTRCTR Minimum symbol value that has a destructor
171760 ** YY_MAX_DSTRCTR Maximum symbol value that has a destructor
171761 */
171762 #ifndef INTERFACE
171763 # define INTERFACE 1
171764 #endif
171765 /************* Begin control #defines *****************************************/
@@ -171410,10 +171796,13 @@
171796 #define sqlite3ParserARG_SDECL
171797 #define sqlite3ParserARG_PDECL
171798 #define sqlite3ParserARG_PARAM
171799 #define sqlite3ParserARG_FETCH
171800 #define sqlite3ParserARG_STORE
171801 #define YYREALLOC parserStackRealloc
171802 #define YYFREE sqlite3_free
171803 #define YYDYNSTACK 1
171804 #define sqlite3ParserCTX_SDECL Parse *pParse;
171805 #define sqlite3ParserCTX_PDECL ,Parse *pParse
171806 #define sqlite3ParserCTX_PARAM ,pParse
171807 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
171808 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
@@ -171428,10 +171817,12 @@
171817 #define YY_ERROR_ACTION 1243
171818 #define YY_ACCEPT_ACTION 1244
171819 #define YY_NO_ACTION 1245
171820 #define YY_MIN_REDUCE 1246
171821 #define YY_MAX_REDUCE 1650
171822 #define YY_MIN_DSTRCTR 204
171823 #define YY_MAX_DSTRCTR 316
171824 /************* End control #defines *******************************************/
171825 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
171826
171827 /* Define the yytestcase() macro to be a no-op if is not already defined
171828 ** otherwise.
@@ -171442,10 +171833,26 @@
171833 ** for testing.
171834 */
171835 #ifndef yytestcase
171836 # define yytestcase(X)
171837 #endif
171838
171839 /* Macro to determine if stack space has the ability to grow using
171840 ** heap memory.
171841 */
171842 #if YYSTACKDEPTH<=0 || YYDYNSTACK
171843 # define YYGROWABLESTACK 1
171844 #else
171845 # define YYGROWABLESTACK 0
171846 #endif
171847
171848 /* Guarantee a minimum number of initial stack slots.
171849 */
171850 #if YYSTACKDEPTH<=0
171851 # undef YYSTACKDEPTH
171852 # define YYSTACKDEPTH 2 /* Need a minimum stack size */
171853 #endif
171854
171855
171856 /* Next are the tables used to determine what action to take based on the
171857 ** current state and lookahead token. These tables are used to implement
171858 ** functions that take a state number and lookahead value and return an
@@ -172351,18 +172758,13 @@
172758 #ifndef YYNOERRORRECOVERY
172759 int yyerrcnt; /* Shifts left before out of the error */
172760 #endif
172761 sqlite3ParserARG_SDECL /* A place to hold %extra_argument */
172762 sqlite3ParserCTX_SDECL /* A place to hold %extra_context */
172763 yyStackEntry *yystackEnd; /* Last entry in the stack */
172764 yyStackEntry *yystack; /* The parser stack */
172765 yyStackEntry yystk0[YYSTACKDEPTH]; /* Initial stack space */
 
 
 
 
 
172766 };
172767 typedef struct yyParser yyParser;
172768
172769 /* #include <assert.h> */
172770 #ifndef NDEBUG
@@ -173134,41 +173536,49 @@
173536 /* 404 */ "window ::= frame_opt",
173537 };
173538 #endif /* NDEBUG */
173539
173540
173541 #if YYGROWABLESTACK
173542 /*
173543 ** Try to increase the size of the parser stack. Return the number
173544 ** of errors. Return 0 on success.
173545 */
173546 static int yyGrowStack(yyParser *p){
173547 int oldSize = 1 + (int)(p->yystackEnd - p->yystack);
173548 int newSize;
173549 int idx;
173550 yyStackEntry *pNew;
173551
173552 newSize = oldSize*2 + 100;
173553 idx = (int)(p->yytos - p->yystack);
173554 if( p->yystack==p->yystk0 ){
173555 pNew = YYREALLOC(0, newSize*sizeof(pNew[0]));
173556 if( pNew==0 ) return 1;
173557 memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0]));
173558 }else{
173559 pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0]));
173560 if( pNew==0 ) return 1;
173561 }
173562 p->yystack = pNew;
173563 p->yytos = &p->yystack[idx];
 
173564 #ifndef NDEBUG
173565 if( yyTraceFILE ){
173566 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
173567 yyTracePrompt, oldSize, newSize);
173568 }
173569 #endif
173570 p->yystackEnd = &p->yystack[newSize-1];
173571 return 0;
 
173572 }
173573 #endif /* YYGROWABLESTACK */
173574
173575 #if !YYGROWABLESTACK
173576 /* For builds that do no have a growable stack, yyGrowStack always
173577 ** returns an error.
173578 */
173579 # define yyGrowStack(X) 1
173580 #endif
173581
173582 /* Datatype of the argument to the memory allocated passed as the
173583 ** second argument to sqlite3ParserAlloc() below. This can be changed by
173584 ** putting an appropriate #define in the %include section of the input
@@ -173184,28 +173594,18 @@
173594 yyParser *yypParser = (yyParser*)yypRawParser;
173595 sqlite3ParserCTX_STORE
173596 #ifdef YYTRACKMAXSTACKDEPTH
173597 yypParser->yyhwm = 0;
173598 #endif
173599 yypParser->yystack = yypParser->yystk0;
173600 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
 
 
 
 
 
 
 
173601 #ifndef YYNOERRORRECOVERY
173602 yypParser->yyerrcnt = -1;
173603 #endif
173604 yypParser->yytos = yypParser->yystack;
173605 yypParser->yystack[0].stateno = 0;
173606 yypParser->yystack[0].major = 0;
 
 
 
173607 }
173608
173609 #ifndef sqlite3Parser_ENGINEALWAYSONSTACK
173610 /*
173611 ** This function allocates a new parser.
@@ -173379,13 +173779,30 @@
173779 /*
173780 ** Clear all secondary memory allocations from the parser
173781 */
173782 SQLITE_PRIVATE void sqlite3ParserFinalize(void *p){
173783 yyParser *pParser = (yyParser*)p;
173784
173785 /* In-lined version of calling yy_pop_parser_stack() for each
173786 ** element left in the stack */
173787 yyStackEntry *yytos = pParser->yytos;
173788 while( yytos>pParser->yystack ){
173789 #ifndef NDEBUG
173790 if( yyTraceFILE ){
173791 fprintf(yyTraceFILE,"%sPopping %s\n",
173792 yyTracePrompt,
173793 yyTokenName[yytos->major]);
173794 }
173795 #endif
173796 if( yytos->major>=YY_MIN_DSTRCTR ){
173797 yy_destructor(pParser, yytos->major, &yytos->minor);
173798 }
173799 yytos--;
173800 }
173801
173802 #if YYGROWABLESTACK
173803 if( pParser->yystack!=pParser->yystk0 ) YYFREE(pParser->yystack);
173804 #endif
173805 }
173806
173807 #ifndef sqlite3Parser_ENGINEALWAYSONSTACK
173808 /*
@@ -173564,11 +173981,11 @@
173981 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
173982 /* Here code is inserted which will execute if the parser
173983 ** stack every overflows */
173984 /******** Begin %stack_overflow code ******************************************/
173985
173986 sqlite3OomFault(pParse->db);
173987 /******** End %stack_overflow code ********************************************/
173988 sqlite3ParserARG_STORE /* Suppress warning about unused %extra_argument var */
173989 sqlite3ParserCTX_STORE
173990 }
173991
@@ -173608,29 +174025,23 @@
174025 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
174026 yypParser->yyhwm++;
174027 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
174028 }
174029 #endif
174030 yytos = yypParser->yytos;
174031 if( yytos>yypParser->yystackEnd ){
 
 
 
 
 
 
174032 if( yyGrowStack(yypParser) ){
174033 yypParser->yytos--;
174034 yyStackOverflow(yypParser);
174035 return;
174036 }
174037 yytos = yypParser->yytos;
174038 assert( yytos <= yypParser->yystackEnd );
174039 }
 
174040 if( yyNewState > YY_MAX_SHIFT ){
174041 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
174042 }
 
174043 yytos->stateno = yyNewState;
174044 yytos->major = yyMajor;
174045 yytos->minor.yy0 = yyMinor;
174046 yyTraceShift(yypParser, yyNewState, "Shift");
174047 }
@@ -176208,23 +176619,16 @@
176619 yypParser->yyhwm++;
176620 assert( yypParser->yyhwm ==
176621 (int)(yypParser->yytos - yypParser->yystack));
176622 }
176623 #endif
 
176624 if( yypParser->yytos>=yypParser->yystackEnd ){
 
 
 
 
 
176625 if( yyGrowStack(yypParser) ){
176626 yyStackOverflow(yypParser);
176627 break;
176628 }
176629 }
 
176630 }
176631 yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor sqlite3ParserCTX_PARAM);
176632 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
176633 yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
176634 #ifndef YYNOERRORRECOVERY
@@ -188495,26 +188899,28 @@
188899 const char *zTabname, /* Name of the pVTab table */
188900 int isQuick, /* True if this is a quick_check */
188901 char **pzErr /* Write error message here */
188902 ){
188903 Fts3Table *p = (Fts3Table*)pVtab;
188904 int rc = SQLITE_OK;
188905 int bOk = 0;
188906
188907 UNUSED_PARAMETER(isQuick);
188908 rc = sqlite3Fts3IntegrityCheck(p, &bOk);
188909 assert( rc!=SQLITE_CORRUPT_VTAB );
188910 if( rc==SQLITE_ERROR || (rc&0xFF)==SQLITE_CORRUPT ){
188911 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
188912 " FTS%d table %s.%s: %s",
188913 p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc));
188914 if( *pzErr ) rc = SQLITE_OK;
188915 }else if( rc==SQLITE_OK && bOk==0 ){
188916 *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
188917 p->bFts4 ? 4 : 3, zSchema, zTabname);
188918 if( *pzErr==0 ) rc = SQLITE_NOMEM;
188919 }
188920 sqlite3Fts3SegmentsClose(p);
188921 return rc;
188922 }
188923
188924
188925
188926 static const sqlite3_module fts3Module = {
@@ -200172,11 +200578,16 @@
200578 }
200579
200580 sqlite3_finalize(pStmt);
200581 }
200582
200583 if( rc==SQLITE_CORRUPT_VTAB ){
200584 rc = SQLITE_OK;
200585 *pbOk = 0;
200586 }else{
200587 *pbOk = (rc==SQLITE_OK && cksum1==cksum2);
200588 }
200589 return rc;
200590 }
200591
200592 /*
200593 ** Run the integrity-check. If no error occurs and the current contents of
@@ -203796,10 +204207,44 @@
204207 if( p->nUsed==0 ) return;
204208 c = p->zBuf[p->nUsed-1];
204209 if( c=='[' || c=='{' ) return;
204210 jsonAppendChar(p, ',');
204211 }
204212
204213 /* c is a control character. Append the canonical JSON representation
204214 ** of that control character to p.
204215 **
204216 ** This routine assumes that the output buffer has already been enlarged
204217 ** sufficiently to hold the worst-case encoding plus a nul terminator.
204218 */
204219 static void jsonAppendControlChar(JsonString *p, u8 c){
204220 static const char aSpecial[] = {
204221 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0,
204222 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
204223 };
204224 assert( sizeof(aSpecial)==32 );
204225 assert( aSpecial['\b']=='b' );
204226 assert( aSpecial['\f']=='f' );
204227 assert( aSpecial['\n']=='n' );
204228 assert( aSpecial['\r']=='r' );
204229 assert( aSpecial['\t']=='t' );
204230 assert( c>=0 && c<sizeof(aSpecial) );
204231 assert( p->nUsed+7 <= p->nAlloc );
204232 if( aSpecial[c] ){
204233 p->zBuf[p->nUsed] = '\\';
204234 p->zBuf[p->nUsed+1] = aSpecial[c];
204235 p->nUsed += 2;
204236 }else{
204237 p->zBuf[p->nUsed] = '\\';
204238 p->zBuf[p->nUsed+1] = 'u';
204239 p->zBuf[p->nUsed+2] = '0';
204240 p->zBuf[p->nUsed+3] = '0';
204241 p->zBuf[p->nUsed+4] = "0123456789abcdef"[c>>4];
204242 p->zBuf[p->nUsed+5] = "0123456789abcdef"[c&0xf];
204243 p->nUsed += 6;
204244 }
204245 }
204246
204247 /* Append the N-byte string in zIn to the end of the JsonString string
204248 ** under construction. Enclose the string in double-quotes ("...") and
204249 ** escape any double-quotes or backslash characters contained within the
204250 ** string.
@@ -203856,39 +204301,18 @@
204301 z += k;
204302 N -= k;
204303 }
204304 c = z[0];
204305 if( c=='"' || c=='\\' ){
 
204306 if( (p->nUsed+N+3 > p->nAlloc) && jsonStringGrow(p,N+3)!=0 ) return;
204307 p->zBuf[p->nUsed++] = '\\';
204308 p->zBuf[p->nUsed++] = c;
204309 }else if( c=='\'' ){
204310 p->zBuf[p->nUsed++] = c;
204311 }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204312 if( (p->nUsed+N+7 > p->nAlloc) && jsonStringGrow(p,N+7)!=0 ) return;
204313 jsonAppendControlChar(p, c);
 
 
 
 
 
204314 }
204315 z++;
204316 N--;
204317 }
204318 p->zBuf[p->nUsed++] = '"';
@@ -204585,11 +205009,14 @@
205009 k = j+sz;
205010 while( j<k ){
205011 if( !jsonIsOk[z[j]] && z[j]!='\'' ){
205012 if( z[j]=='"' ){
205013 if( x==JSONB_TEXTJ ) return j+1;
205014 }else if( z[j]<=0x1f ){
205015 /* Control characters in JSON5 string literals are ok */
205016 if( x==JSONB_TEXTJ ) return j+1;
205017 }else if( NEVER(z[j]!='\\') || j+1>=k ){
205018 return j+1;
205019 }else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){
205020 j++;
205021 }else if( z[j+1]=='u' ){
205022 if( j+5>=k ) return j+1;
@@ -204783,10 +205210,11 @@
205210 return j+1;
205211 }
205212 case '[': {
205213 /* Parse array */
205214 iThis = pParse->nBlob;
205215 assert( i<=pParse->nJson );
205216 jsonBlobAppendNode(pParse, JSONB_ARRAY, pParse->nJson - i, 0);
205217 iStart = pParse->nBlob;
205218 if( pParse->oom ) return -1;
205219 if( ++pParse->iDepth > JSON_MAX_DEPTH ){
205220 pParse->iErr = i;
@@ -204879,13 +205307,18 @@
205307 }else{
205308 pParse->iErr = j;
205309 return -1;
205310 }
205311 }else if( c<=0x1f ){
205312 if( c==0 ){
205313 pParse->iErr = j;
205314 return -1;
205315 }
205316 /* Control characters are not allowed in canonical JSON string
205317 ** literals, but are allowed in JSON5 string literals. */
205318 opcode = JSONB_TEXT5;
205319 pParse->hasNonstd = 1;
205320 }else if( c=='"' ){
205321 opcode = JSONB_TEXT5;
205322 }
205323 j++;
205324 }
@@ -205097,10 +205530,11 @@
205530 if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
205531 jsonBlobAppendOneByte(pParse, JSONB_NULL);
205532 return i+4;
205533 }
205534 /* fall-through into the default case that checks for NaN */
205535 /* no break */ deliberate_fall_through
205536 }
205537 default: {
205538 u32 k;
205539 int nn;
205540 c = z[i];
@@ -205181,10 +205615,14 @@
205615 */
205616 static void jsonReturnStringAsBlob(JsonString *pStr){
205617 JsonParse px;
205618 memset(&px, 0, sizeof(px));
205619 jsonStringTerminate(pStr);
205620 if( pStr->eErr ){
205621 sqlite3_result_error_nomem(pStr->pCtx);
205622 return;
205623 }
205624 px.zJson = pStr->zBuf;
205625 px.nJson = pStr->nUsed;
205626 px.db = sqlite3_context_db_handle(pStr->pCtx);
205627 (void)jsonTranslateTextToBlob(&px, 0);
205628 if( px.oom ){
@@ -205361,11 +205799,11 @@
205799 u32 k;
205800 u32 sz2 = sz;
205801 zIn = (const char*)&pParse->aBlob[i+n];
205802 jsonAppendChar(pOut, '"');
205803 while( sz2>0 ){
205804 for(k=0; k<sz2 && (jsonIsOk[(u8)zIn[k]] || zIn[k]=='\''); k++){}
205805 if( k>0 ){
205806 jsonAppendRawNZ(pOut, zIn, k);
205807 if( k>=sz2 ){
205808 break;
205809 }
@@ -205373,10 +205811,17 @@
205811 sz2 -= k;
205812 }
205813 if( zIn[0]=='"' ){
205814 jsonAppendRawNZ(pOut, "\\\"", 2);
205815 zIn++;
205816 sz2--;
205817 continue;
205818 }
205819 if( zIn[0]<=0x1f ){
205820 if( pOut->nUsed+7>pOut->nAlloc && jsonStringGrow(pOut,7) ) break;
205821 jsonAppendControlChar(pOut, zIn[0]);
205822 zIn++;
205823 sz2--;
205824 continue;
205825 }
205826 assert( zIn[0]=='\\' );
205827 assert( sz2>=1 );
@@ -206506,12 +206951,13 @@
206951 ** See for example https://sqlite.org/forum/forumpost/012136abd5292b8d
206952 */
206953 }
206954 p->zJson = (char*)sqlite3_value_text(pArg);
206955 p->nJson = sqlite3_value_bytes(pArg);
206956 if( db->mallocFailed ) goto json_pfa_oom;
206957 if( p->nJson==0 ) goto json_pfa_malformed;
206958 assert( p->zJson!=0 );
206959 if( jsonConvertTextToBlob(p, (flgs & JSON_KEEPERROR) ? 0 : ctx) ){
206960 if( flgs & JSON_KEEPERROR ){
206961 p->nErr = 1;
206962 return p;
206963 }else{
@@ -206673,14 +207119,14 @@
207119 }
207120 if( showContent ){
207121 if( sz==0 && x<=JSONB_FALSE ){
207122 sqlite3_str_append(pOut, "\n", 1);
207123 }else{
207124 u32 j;
207125 sqlite3_str_appendall(pOut, ": \"");
207126 for(j=iStart+n; j<iStart+n+sz; j++){
207127 u8 c = pParse->aBlob[j];
207128 if( c<0x20 || c>=0x7f ) c = '.';
207129 sqlite3_str_append(pOut, (char*)&c, 1);
207130 }
207131 sqlite3_str_append(pOut, "\"\n", 2);
207132 }
@@ -206727,15 +207173,16 @@
207173 sqlite3StrAccumInit(&out, 0, 0, 0, 1000000);
207174 p = jsonParseFuncArg(ctx, argv[0], 0);
207175 if( p==0 ) return;
207176 if( argc==1 ){
207177 jsonDebugPrintBlob(p, 0, p->nBlob, 0, &out);
207178 sqlite3_result_text64(ctx,out.zText,out.nChar,SQLITE_TRANSIENT,SQLITE_UTF8);
207179 }else{
207180 jsonShowParse(p);
207181 }
207182 jsonParseFree(p);
207183 sqlite3_str_reset(&out);
207184 }
207185 #endif /* SQLITE_DEBUG */
207186
207187 /****************************************************************************
207188 ** Scalar SQL function implementations
@@ -208084,10 +208531,13 @@
208531 break;
208532 }
208533 case JEACH_VALUE: {
208534 u32 i = jsonSkipLabel(p);
208535 jsonReturnFromBlob(&p->sParse, i, ctx, 1);
208536 if( (p->sParse.aBlob[i] & 0x0f)>=JSONB_ARRAY ){
208537 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
208538 }
208539 break;
208540 }
208541 case JEACH_TYPE: {
208542 u32 i = jsonSkipLabel(p);
208543 u8 eType = p->sParse.aBlob[i] & 0x0f;
@@ -209158,15 +209608,13 @@
209608
209609 /*
209610 ** Clear the Rtree.pNodeBlob object
209611 */
209612 static void nodeBlobReset(Rtree *pRtree){
209613 sqlite3_blob *pBlob = pRtree->pNodeBlob;
209614 pRtree->pNodeBlob = 0;
209615 sqlite3_blob_close(pBlob);
 
 
209616 }
209617
209618 /*
209619 ** Obtain a reference to an r-tree node.
209620 */
@@ -209206,11 +209654,10 @@
209654 rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, pRtree->zNodeName,
209655 "data", iNode, 0,
209656 &pRtree->pNodeBlob);
209657 }
209658 if( rc ){
 
209659 *ppNode = 0;
209660 /* If unable to open an sqlite3_blob on the desired row, that can only
209661 ** be because the shadow tables hold erroneous data. */
209662 if( rc==SQLITE_ERROR ){
209663 rc = SQLITE_CORRUPT_VTAB;
@@ -209266,10 +209713,11 @@
209713 rc = SQLITE_CORRUPT_VTAB;
209714 RTREE_IS_CORRUPT(pRtree);
209715 }
209716 *ppNode = pNode;
209717 }else{
209718 nodeBlobReset(pRtree);
209719 if( pNode ){
209720 pRtree->nNodeRef--;
209721 sqlite3_free(pNode);
209722 }
209723 *ppNode = 0;
@@ -209410,10 +209858,11 @@
209858 RtreeNode *pNode, /* The node from which to extract a coordinate */
209859 int iCell, /* The index of the cell within the node */
209860 int iCoord, /* Which coordinate to extract */
209861 RtreeCoord *pCoord /* OUT: Space to write result to */
209862 ){
209863 assert( iCell<NCELL(pNode) );
209864 readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
209865 }
209866
209867 /*
209868 ** Deserialize cell iCell of node pNode. Populate the structure pointed
@@ -209599,11 +210048,13 @@
210048 assert( pRtree->nCursor>0 );
210049 resetCursor(pCsr);
210050 sqlite3_finalize(pCsr->pReadAux);
210051 sqlite3_free(pCsr);
210052 pRtree->nCursor--;
210053 if( pRtree->nCursor==0 && pRtree->inWrTrans==0 ){
210054 nodeBlobReset(pRtree);
210055 }
210056 return SQLITE_OK;
210057 }
210058
210059 /*
210060 ** Rtree virtual table module xEof method.
@@ -210184,11 +210635,15 @@
210635 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
210636 RtreeSearchPoint *p = rtreeSearchPointFirst(pCsr);
210637 int rc = SQLITE_OK;
210638 RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
210639 if( rc==SQLITE_OK && ALWAYS(p) ){
210640 if( p->iCell>=NCELL(pNode) ){
210641 rc = SQLITE_ABORT;
210642 }else{
210643 *pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
210644 }
210645 }
210646 return rc;
210647 }
210648
210649 /*
@@ -210202,10 +210657,11 @@
210657 int rc = SQLITE_OK;
210658 RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
210659
210660 if( rc ) return rc;
210661 if( NEVER(p==0) ) return SQLITE_OK;
210662 if( p->iCell>=NCELL(pNode) ) return SQLITE_ABORT;
210663 if( i==0 ){
210664 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
210665 }else if( i<=pRtree->nDim2 ){
210666 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
210667 #ifndef SQLITE_RTREE_INT_ONLY
@@ -211684,11 +212140,11 @@
212140 ** Called when a transaction starts.
212141 */
212142 static int rtreeBeginTransaction(sqlite3_vtab *pVtab){
212143 Rtree *pRtree = (Rtree *)pVtab;
212144 assert( pRtree->inWrTrans==0 );
212145 pRtree->inWrTrans = 1;
212146 return SQLITE_OK;
212147 }
212148
212149 /*
212150 ** Called when a transaction completes (either by COMMIT or ROLLBACK).
@@ -211697,10 +212153,13 @@
212153 static int rtreeEndTransaction(sqlite3_vtab *pVtab){
212154 Rtree *pRtree = (Rtree *)pVtab;
212155 pRtree->inWrTrans = 0;
212156 nodeBlobReset(pRtree);
212157 return SQLITE_OK;
212158 }
212159 static int rtreeRollback(sqlite3_vtab *pVtab){
212160 return rtreeEndTransaction(pVtab);
212161 }
212162
212163 /*
212164 ** The xRename method for rtree module virtual tables.
212165 */
@@ -211816,11 +212275,11 @@
212275 rtreeRowid, /* xRowid - read data */
212276 rtreeUpdate, /* xUpdate - write data */
212277 rtreeBeginTransaction, /* xBegin - begin transaction */
212278 rtreeEndTransaction, /* xSync - sync transaction */
212279 rtreeEndTransaction, /* xCommit - commit transaction */
212280 rtreeRollback, /* xRollback - rollback transaction */
212281 0, /* xFindFunction - function overloading */
212282 rtreeRename, /* xRename - rename the table */
212283 rtreeSavepoint, /* xSavepoint */
212284 0, /* xRelease */
212285 0, /* xRollbackTo */
@@ -231114,10 +231573,13 @@
231573 ** sqlite3Fts5ParserARG_PDECL A parameter declaration for the %extra_argument
231574 ** sqlite3Fts5ParserARG_PARAM Code to pass %extra_argument as a subroutine parameter
231575 ** sqlite3Fts5ParserARG_STORE Code to store %extra_argument into fts5yypParser
231576 ** sqlite3Fts5ParserARG_FETCH Code to extract %extra_argument from fts5yypParser
231577 ** sqlite3Fts5ParserCTX_* As sqlite3Fts5ParserARG_ except for %extra_context
231578 ** fts5YYREALLOC Name of the realloc() function to use
231579 ** fts5YYFREE Name of the free() function to use
231580 ** fts5YYDYNSTACK True if stack space should be extended on heap
231581 ** fts5YYERRORSYMBOL is the code number of the error symbol. If not
231582 ** defined, then do no error processing.
231583 ** fts5YYNSTATE the combined number of states.
231584 ** fts5YYNRULE the number of rules in the grammar
231585 ** fts5YYNFTS5TOKEN Number of terminal symbols
@@ -231127,10 +231589,12 @@
231589 ** fts5YY_ERROR_ACTION The fts5yy_action[] code for syntax error
231590 ** fts5YY_ACCEPT_ACTION The fts5yy_action[] code for accept
231591 ** fts5YY_NO_ACTION The fts5yy_action[] code for no-op
231592 ** fts5YY_MIN_REDUCE Minimum value for reduce actions
231593 ** fts5YY_MAX_REDUCE Maximum value for reduce actions
231594 ** fts5YY_MIN_DSTRCTR Minimum symbol value that has a destructor
231595 ** fts5YY_MAX_DSTRCTR Maximum symbol value that has a destructor
231596 */
231597 #ifndef INTERFACE
231598 # define INTERFACE 1
231599 #endif
231600 /************* Begin control #defines *****************************************/
@@ -231153,10 +231617,13 @@
231617 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
231618 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
231619 #define sqlite3Fts5ParserARG_PARAM ,pParse
231620 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse=fts5yypParser->pParse;
231621 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse=pParse;
231622 #define fts5YYREALLOC realloc
231623 #define fts5YYFREE free
231624 #define fts5YYDYNSTACK 0
231625 #define sqlite3Fts5ParserCTX_SDECL
231626 #define sqlite3Fts5ParserCTX_PDECL
231627 #define sqlite3Fts5ParserCTX_PARAM
231628 #define sqlite3Fts5ParserCTX_FETCH
231629 #define sqlite3Fts5ParserCTX_STORE
@@ -231170,10 +231637,12 @@
231637 #define fts5YY_ERROR_ACTION 80
231638 #define fts5YY_ACCEPT_ACTION 81
231639 #define fts5YY_NO_ACTION 82
231640 #define fts5YY_MIN_REDUCE 83
231641 #define fts5YY_MAX_REDUCE 110
231642 #define fts5YY_MIN_DSTRCTR 16
231643 #define fts5YY_MAX_DSTRCTR 24
231644 /************* End control #defines *******************************************/
231645 #define fts5YY_NLOOKAHEAD ((int)(sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0])))
231646
231647 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
231648 ** otherwise.
@@ -231184,10 +231653,26 @@
231653 ** for testing.
231654 */
231655 #ifndef fts5yytestcase
231656 # define fts5yytestcase(X)
231657 #endif
231658
231659 /* Macro to determine if stack space has the ability to grow using
231660 ** heap memory.
231661 */
231662 #if fts5YYSTACKDEPTH<=0 || fts5YYDYNSTACK
231663 # define fts5YYGROWABLESTACK 1
231664 #else
231665 # define fts5YYGROWABLESTACK 0
231666 #endif
231667
231668 /* Guarantee a minimum number of initial stack slots.
231669 */
231670 #if fts5YYSTACKDEPTH<=0
231671 # undef fts5YYSTACKDEPTH
231672 # define fts5YYSTACKDEPTH 2 /* Need a minimum stack size */
231673 #endif
231674
231675
231676 /* Next are the tables used to determine what action to take based on the
231677 ** current state and lookahead token. These tables are used to implement
231678 ** functions that take a state number and lookahead value and return an
@@ -231345,18 +231830,13 @@
231830 #ifndef fts5YYNOERRORRECOVERY
231831 int fts5yyerrcnt; /* Shifts left before out of the error */
231832 #endif
231833 sqlite3Fts5ParserARG_SDECL /* A place to hold %extra_argument */
231834 sqlite3Fts5ParserCTX_SDECL /* A place to hold %extra_context */
231835 fts5yyStackEntry *fts5yystackEnd; /* Last entry in the stack */
231836 fts5yyStackEntry *fts5yystack; /* The parser stack */
231837 fts5yyStackEntry fts5yystk0[fts5YYSTACKDEPTH]; /* Initial stack space */
 
 
 
 
 
231838 };
231839 typedef struct fts5yyParser fts5yyParser;
231840
231841 /* #include <assert.h> */
231842 #ifndef NDEBUG
@@ -231459,41 +231939,49 @@
231939 /* 27 */ "star_opt ::=",
231940 };
231941 #endif /* NDEBUG */
231942
231943
231944 #if fts5YYGROWABLESTACK
231945 /*
231946 ** Try to increase the size of the parser stack. Return the number
231947 ** of errors. Return 0 on success.
231948 */
231949 static int fts5yyGrowStack(fts5yyParser *p){
231950 int oldSize = 1 + (int)(p->fts5yystackEnd - p->fts5yystack);
231951 int newSize;
231952 int idx;
231953 fts5yyStackEntry *pNew;
231954
231955 newSize = oldSize*2 + 100;
231956 idx = (int)(p->fts5yytos - p->fts5yystack);
231957 if( p->fts5yystack==p->fts5yystk0 ){
231958 pNew = fts5YYREALLOC(0, newSize*sizeof(pNew[0]));
231959 if( pNew==0 ) return 1;
231960 memcpy(pNew, p->fts5yystack, oldSize*sizeof(pNew[0]));
231961 }else{
231962 pNew = fts5YYREALLOC(p->fts5yystack, newSize*sizeof(pNew[0]));
231963 if( pNew==0 ) return 1;
231964 }
231965 p->fts5yystack = pNew;
231966 p->fts5yytos = &p->fts5yystack[idx];
 
231967 #ifndef NDEBUG
231968 if( fts5yyTraceFILE ){
231969 fprintf(fts5yyTraceFILE,"%sStack grows from %d to %d entries.\n",
231970 fts5yyTracePrompt, oldSize, newSize);
231971 }
231972 #endif
231973 p->fts5yystackEnd = &p->fts5yystack[newSize-1];
231974 return 0;
 
231975 }
231976 #endif /* fts5YYGROWABLESTACK */
231977
231978 #if !fts5YYGROWABLESTACK
231979 /* For builds that do no have a growable stack, fts5yyGrowStack always
231980 ** returns an error.
231981 */
231982 # define fts5yyGrowStack(X) 1
231983 #endif
231984
231985 /* Datatype of the argument to the memory allocated passed as the
231986 ** second argument to sqlite3Fts5ParserAlloc() below. This can be changed by
231987 ** putting an appropriate #define in the %include section of the input
@@ -231509,28 +231997,18 @@
231997 fts5yyParser *fts5yypParser = (fts5yyParser*)fts5yypRawParser;
231998 sqlite3Fts5ParserCTX_STORE
231999 #ifdef fts5YYTRACKMAXSTACKDEPTH
232000 fts5yypParser->fts5yyhwm = 0;
232001 #endif
232002 fts5yypParser->fts5yystack = fts5yypParser->fts5yystk0;
232003 fts5yypParser->fts5yystackEnd = &fts5yypParser->fts5yystack[fts5YYSTACKDEPTH-1];
 
 
 
 
 
 
 
232004 #ifndef fts5YYNOERRORRECOVERY
232005 fts5yypParser->fts5yyerrcnt = -1;
232006 #endif
232007 fts5yypParser->fts5yytos = fts5yypParser->fts5yystack;
232008 fts5yypParser->fts5yystack[0].stateno = 0;
232009 fts5yypParser->fts5yystack[0].major = 0;
 
 
 
232010 }
232011
232012 #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
232013 /*
232014 ** This function allocates a new parser.
@@ -231640,13 +232118,30 @@
232118 /*
232119 ** Clear all secondary memory allocations from the parser
232120 */
232121 static void sqlite3Fts5ParserFinalize(void *p){
232122 fts5yyParser *pParser = (fts5yyParser*)p;
232123
232124 /* In-lined version of calling fts5yy_pop_parser_stack() for each
232125 ** element left in the stack */
232126 fts5yyStackEntry *fts5yytos = pParser->fts5yytos;
232127 while( fts5yytos>pParser->fts5yystack ){
232128 #ifndef NDEBUG
232129 if( fts5yyTraceFILE ){
232130 fprintf(fts5yyTraceFILE,"%sPopping %s\n",
232131 fts5yyTracePrompt,
232132 fts5yyTokenName[fts5yytos->major]);
232133 }
232134 #endif
232135 if( fts5yytos->major>=fts5YY_MIN_DSTRCTR ){
232136 fts5yy_destructor(pParser, fts5yytos->major, &fts5yytos->minor);
232137 }
232138 fts5yytos--;
232139 }
232140
232141 #if fts5YYGROWABLESTACK
232142 if( pParser->fts5yystack!=pParser->fts5yystk0 ) fts5YYFREE(pParser->fts5yystack);
232143 #endif
232144 }
232145
232146 #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
232147 /*
@@ -231869,29 +232364,23 @@
232364 if( (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack)>fts5yypParser->fts5yyhwm ){
232365 fts5yypParser->fts5yyhwm++;
232366 assert( fts5yypParser->fts5yyhwm == (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack) );
232367 }
232368 #endif
232369 fts5yytos = fts5yypParser->fts5yytos;
232370 if( fts5yytos>fts5yypParser->fts5yystackEnd ){
 
 
 
 
 
 
232371 if( fts5yyGrowStack(fts5yypParser) ){
232372 fts5yypParser->fts5yytos--;
232373 fts5yyStackOverflow(fts5yypParser);
232374 return;
232375 }
232376 fts5yytos = fts5yypParser->fts5yytos;
232377 assert( fts5yytos <= fts5yypParser->fts5yystackEnd );
232378 }
 
232379 if( fts5yyNewState > fts5YY_MAX_SHIFT ){
232380 fts5yyNewState += fts5YY_MIN_REDUCE - fts5YY_MIN_SHIFTREDUCE;
232381 }
 
232382 fts5yytos->stateno = fts5yyNewState;
232383 fts5yytos->major = fts5yyMajor;
232384 fts5yytos->minor.fts5yy0 = fts5yyMinor;
232385 fts5yyTraceShift(fts5yypParser, fts5yyNewState, "Shift");
232386 }
@@ -232324,23 +232813,16 @@
232813 fts5yypParser->fts5yyhwm++;
232814 assert( fts5yypParser->fts5yyhwm ==
232815 (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack));
232816 }
232817 #endif
 
232818 if( fts5yypParser->fts5yytos>=fts5yypParser->fts5yystackEnd ){
 
 
 
 
 
232819 if( fts5yyGrowStack(fts5yypParser) ){
232820 fts5yyStackOverflow(fts5yypParser);
232821 break;
232822 }
232823 }
 
232824 }
232825 fts5yyact = fts5yy_reduce(fts5yypParser,fts5yyruleno,fts5yymajor,fts5yyminor sqlite3Fts5ParserCTX_PARAM);
232826 }else if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
232827 fts5yy_shift(fts5yypParser,fts5yyact,(fts5YYCODETYPE)fts5yymajor,fts5yyminor);
232828 #ifndef fts5YYNOERRORRECOVERY
@@ -245375,27 +245857,30 @@
245857 ** a rowid of iFrom or greater.
245858 */
245859 static void fts5TokendataIterNext(Fts5Iter *pIter, int bFrom, i64 iFrom){
245860 int ii;
245861 Fts5TokenDataIter *pT = pIter->pTokenDataIter;
245862 Fts5Index *pIndex = pIter->pIndex;
245863
245864 for(ii=0; ii<pT->nIter; ii++){
245865 Fts5Iter *p = pT->apIter[ii];
245866 if( p->base.bEof==0
245867 && (p->base.iRowid==pIter->base.iRowid || (bFrom && p->base.iRowid<iFrom))
245868 ){
245869 fts5MultiIterNext(pIndex, p, bFrom, iFrom);
245870 while( bFrom && p->base.bEof==0
245871 && p->base.iRowid<iFrom
245872 && pIndex->rc==SQLITE_OK
245873 ){
245874 fts5MultiIterNext(pIndex, p, 0, 0);
245875 }
245876 }
245877 }
245878
245879 if( pIndex->rc==SQLITE_OK ){
245880 fts5IterSetOutputsTokendata(pIter);
245881 }
245882 }
245883
245884 /*
245885 ** If the segment-iterator passed as the first argument is at EOF, then
245886 ** set pIter->term to a copy of buffer pTerm.
@@ -250545,11 +251030,11 @@
251030 int nArg, /* Number of args */
251031 sqlite3_value **apUnused /* Function arguments */
251032 ){
251033 assert( nArg==0 );
251034 UNUSED_PARAM2(nArg, apUnused);
251035 sqlite3_result_text(pCtx, "fts5: 2024-02-20 12:14:07 6c5a0c85454e3c658e51fab611c169c034447174022eebc52fd8619b528a4765", -1, SQLITE_TRANSIENT);
251036 }
251037
251038 /*
251039 ** Return true if zName is the extension on one of the shadow tables used
251040 ** by this module.
@@ -250584,18 +251069,19 @@
251069 UNUSED_PARAM(isQuick);
251070 rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0);
251071 if( (rc&0xff)==SQLITE_CORRUPT ){
251072 *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
251073 zSchema, zTabname);
251074 rc = (*pzErr) ? SQLITE_OK : SQLITE_NOMEM;
251075 }else if( rc!=SQLITE_OK ){
251076 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
251077 " FTS5 table %s.%s: %s",
251078 zSchema, zTabname, sqlite3_errstr(rc));
251079 }
251080 sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
251081
251082 return rc;
251083 }
251084
251085 static int fts5Init(sqlite3 *db){
251086 static const sqlite3_module fts5Mod = {
251087 /* iVersion */ 4,
251088
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.45.1"
150
-#define SQLITE_VERSION_NUMBER 3045001
151
-#define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
149
+#define SQLITE_VERSION "3.46.0"
150
+#define SQLITE_VERSION_NUMBER 3046000
151
+#define SQLITE_SOURCE_ID "2024-02-20 15:38:36 27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -418,10 +418,12 @@
418418
** is a valid and open [database connection].
419419
** <li> The application must not close the [database connection] specified by
420420
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
421421
** <li> The application must not modify the SQL statement text passed into
422422
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
423
+** <li> The application must not dereference the arrays or string pointers
424
+** passed as the 3rd and 4th callback parameters after it returns.
423425
** </ul>
424426
*/
425427
SQLITE_API int sqlite3_exec(
426428
sqlite3*, /* An open database */
427429
const char *sql, /* SQL to be evaluated */
428430
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.45.1"
150 #define SQLITE_VERSION_NUMBER 3045001
151 #define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -418,10 +418,12 @@
418 ** is a valid and open [database connection].
419 ** <li> The application must not close the [database connection] specified by
420 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
421 ** <li> The application must not modify the SQL statement text passed into
422 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
 
 
423 ** </ul>
424 */
425 SQLITE_API int sqlite3_exec(
426 sqlite3*, /* An open database */
427 const char *sql, /* SQL to be evaluated */
428
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.46.0"
150 #define SQLITE_VERSION_NUMBER 3046000
151 #define SQLITE_SOURCE_ID "2024-02-20 15:38:36 27a2113d78b35e324e9aedda7403c96c56ad0bed8c6b139fc5a179e8800b9109"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -418,10 +418,12 @@
418 ** is a valid and open [database connection].
419 ** <li> The application must not close the [database connection] specified by
420 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
421 ** <li> The application must not modify the SQL statement text passed into
422 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
423 ** <li> The application must not dereference the arrays or string pointers
424 ** passed as the 3rd and 4th callback parameters after it returns.
425 ** </ul>
426 */
427 SQLITE_API int sqlite3_exec(
428 sqlite3*, /* An open database */
429 const char *sql, /* SQL to be evaluated */
430

Keyboard Shortcuts

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