Fossil SCM

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

drh 2026-07-24 22:13 UTC trunk
Commit 896a4636ae374e285571abb0a4e7821421c741751c5d3a206c9b0fa4e614c541
+1 -1
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -85,11 +85,11 @@
8585
#define QRF_STYLE_Column 2 /* One record per line in neat columns */
8686
#define QRF_STYLE_Count 3 /* Output only a count of the rows of output */
8787
#define QRF_STYLE_Csv 4 /* Comma-separated-value */
8888
#define QRF_STYLE_Eqp 5 /* Format EXPLAIN QUERY PLAN output */
8989
#define QRF_STYLE_Explain 6 /* EXPLAIN output */
90
-#define QRF_STYLE_Html 7 /* Generate an XHTML table */
90
+#define QRF_STYLE_Html 7 /* Generate HTML-style <tr><td> output */
9191
#define QRF_STYLE_Insert 8 /* Generate SQL "insert" statements */
9292
#define QRF_STYLE_Json 9 /* Output is a list of JSON objects */
9393
#define QRF_STYLE_JObject 10 /* Independent JSON objects for each row */
9494
#define QRF_STYLE_Line 11 /* One column per line. */
9595
#define QRF_STYLE_List 12 /* One record per line with a separator */
9696
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -85,11 +85,11 @@
85 #define QRF_STYLE_Column 2 /* One record per line in neat columns */
86 #define QRF_STYLE_Count 3 /* Output only a count of the rows of output */
87 #define QRF_STYLE_Csv 4 /* Comma-separated-value */
88 #define QRF_STYLE_Eqp 5 /* Format EXPLAIN QUERY PLAN output */
89 #define QRF_STYLE_Explain 6 /* EXPLAIN output */
90 #define QRF_STYLE_Html 7 /* Generate an XHTML table */
91 #define QRF_STYLE_Insert 8 /* Generate SQL "insert" statements */
92 #define QRF_STYLE_Json 9 /* Output is a list of JSON objects */
93 #define QRF_STYLE_JObject 10 /* Independent JSON objects for each row */
94 #define QRF_STYLE_Line 11 /* One column per line. */
95 #define QRF_STYLE_List 12 /* One record per line with a separator */
96
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -85,11 +85,11 @@
85 #define QRF_STYLE_Column 2 /* One record per line in neat columns */
86 #define QRF_STYLE_Count 3 /* Output only a count of the rows of output */
87 #define QRF_STYLE_Csv 4 /* Comma-separated-value */
88 #define QRF_STYLE_Eqp 5 /* Format EXPLAIN QUERY PLAN output */
89 #define QRF_STYLE_Explain 6 /* EXPLAIN output */
90 #define QRF_STYLE_Html 7 /* Generate HTML-style <tr><td> output */
91 #define QRF_STYLE_Insert 8 /* Generate SQL "insert" statements */
92 #define QRF_STYLE_Json 9 /* Output is a list of JSON objects */
93 #define QRF_STYLE_JObject 10 /* Independent JSON objects for each row */
94 #define QRF_STYLE_Line 11 /* One column per line. */
95 #define QRF_STYLE_List 12 /* One record per line with a separator */
96
+73 -33
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -206,28 +206,38 @@
206206
# define shell_add_history(X) add_history(X)
207207
# define shell_read_history(X) read_history(X)
208208
# define shell_write_history(X) write_history(X)
209209
# define shell_stifle_history(X) stifle_history(X)
210210
# define shell_readline(X) readline(X)
211
+# define SHELL_CMDLINE_EDIT_AVAILABLE 1 /* command-line editing available */
211212
212213
#elif HAVE_LINENOISE
213214
214215
# include "linenoise.h"
215216
# define shell_add_history(X) linenoiseHistoryAdd(X)
216217
# define shell_read_history(X) linenoiseHistoryLoad(X)
217218
# define shell_write_history(X) linenoiseHistorySave(X)
218219
# define shell_stifle_history(X) linenoiseHistorySetMaxLen(X)
219220
# define shell_readline(X) linenoise(X)
221
+# define SHELL_CMDLINE_EDIT_AVAILABLE 1 /* command-line editing available */
220222
221223
#else
222224
223225
# define shell_read_history(X)
224226
# define shell_write_history(X)
225227
# define shell_stifle_history(X)
228
+# define SHELL_CMDLINE_EDIT_AVAILABLE 0 /* command-line editing not available */
229
+#endif
226230
227
-# define SHELL_USE_LOCAL_GETLINE 1
228
-#endif
231
+/*
232
+** Global variable shellCmdLineEdit determines whether or not command-line
233
+** editing is enabled. It defaults to 1 if the CLI is linked against a
234
+** command-line editing library (linenoise, readline, or editline) and
235
+** to 0 if no command-line editing library is available. The
236
+** "--cmdline-edit off" command-line option will change this value to 0.
237
+*/
238
+static int shellCmdLineEdit = SHELL_CMDLINE_EDIT_AVAILABLE;
229239
230240
#ifndef deliberate_fall_through
231241
/* Quiet some compilers about some of our intentional code. */
232242
# if defined(GCC_VERSION) && GCC_VERSION>=7000000
233243
# define deliberate_fall_through __attribute__((fallthrough));
@@ -764,11 +774,11 @@
764774
#define QRF_STYLE_Column 2 /* One record per line in neat columns */
765775
#define QRF_STYLE_Count 3 /* Output only a count of the rows of output */
766776
#define QRF_STYLE_Csv 4 /* Comma-separated-value */
767777
#define QRF_STYLE_Eqp 5 /* Format EXPLAIN QUERY PLAN output */
768778
#define QRF_STYLE_Explain 6 /* EXPLAIN output */
769
-#define QRF_STYLE_Html 7 /* Generate an XHTML table */
779
+#define QRF_STYLE_Html 7 /* Generate HTML-style <tr><td> output */
770780
#define QRF_STYLE_Insert 8 /* Generate SQL "insert" statements */
771781
#define QRF_STYLE_Json 9 /* Output is a list of JSON objects */
772782
#define QRF_STYLE_JObject 10 /* Independent JSON objects for each row */
773783
#define QRF_STYLE_Line 11 /* One column per line. */
774784
#define QRF_STYLE_List 12 /* One record per line with a separator */
@@ -3491,17 +3501,17 @@
34913501
assert( p->nRow==0 );
34923502
assert( p->spec.bTitles>=QRF_Yes );
34933503
switch( p->spec.eStyle ){
34943504
case QRF_STYLE_Html: {
34953505
int i;
3496
- sqlite3_str_append(p->pOut, "<TR>", 4);
3506
+ sqlite3_str_append(p->pOut, "<tr>", 4);
34973507
for(i=0; i<p->nCol; i++){
34983508
const char *zCName = sqlite3_column_name(p->pStmt, i);
3499
- sqlite3_str_append(p->pOut, "\n<TH>", 5);
3509
+ sqlite3_str_append(p->pOut, "\n<th>", 5);
35003510
qrfEncodeText(p, p->pOut, zCName);
35013511
}
3502
- sqlite3_str_append(p->pOut, "\n</TR>\n", 7);
3512
+ sqlite3_str_append(p->pOut, "\n</tr>\n", 7);
35033513
break;
35043514
}
35053515
case QRF_STYLE_Quote:
35063516
case QRF_STYLE_List: {
35073517
int i;
@@ -3553,16 +3563,16 @@
35533563
}
35543564
case QRF_STYLE_Html: {
35553565
if( p->nRow==0 && p->spec.bTitles>=QRF_Yes ){
35563566
qrfSimpleTitle(p);
35573567
}
3558
- sqlite3_str_append(p->pOut, "<TR>", 4);
3568
+ sqlite3_str_append(p->pOut, "<tr>", 4);
35593569
for(i=0; i<p->nCol; i++){
3560
- sqlite3_str_append(p->pOut, "\n<TD>", 5);
3570
+ sqlite3_str_append(p->pOut, "\n<td>", 5);
35613571
qrfRenderValue(p, p->pOut, i);
35623572
}
3563
- sqlite3_str_append(p->pOut, "\n</TR>\n", 7);
3573
+ sqlite3_str_append(p->pOut, "\n</tr>\n", 7);
35643574
qrfWrite(p);
35653575
break;
35663576
}
35673577
case QRF_STYLE_Insert: {
35683578
unsigned int mxIns = p->spec.nMultiInsert;
@@ -24839,10 +24849,20 @@
2483924849
#endif
2484024850
#ifdef SQLITE_SHELL_EXTSRC
2484124851
# include SHELL_STRINGIFY(SQLITE_SHELL_EXTSRC)
2484224852
#endif
2484324853
24854
+/*
24855
+** Set the SQLITE_SHELL_EDITION to a YYYYMMDD date string and the
24856
+** code will attempt to use defaults for the prompt and for the
24857
+** initial output mode (and maybe other feature) that were for
24858
+** the most recent version not newer than the specified date.
24859
+*/
24860
+#ifndef SQLITE_SHELL_EDITION
24861
+# define SQLITE_SHELL_EDITION 99991231 /* Use the latest if unspecified */
24862
+#endif
24863
+
2484424864
#if defined(SQLITE_ENABLE_SESSION)
2484524865
/*
2484624866
** State information for a single open session
2484724867
*/
2484824868
typedef struct OpenSession OpenSession;
@@ -25420,11 +25440,11 @@
2542025440
*/
2542125441
static char *local_getline(char *zLine, FILE *in){
2542225442
int nLine = zLine==0 ? 0 : 100;
2542325443
int n = 0;
2542425444
25425
- while( 1 ){
25445
+ while( seenInterrupt<2 ){
2542625446
if( n+100>nLine ){
2542725447
if( nLine>=1073741773 ){
2542825448
free(zLine);
2542925449
return 0;
2543025450
}
@@ -25484,11 +25504,13 @@
2548425504
# define SQLITE_PS_APPDEF shellPromptAppDef
2548525505
static const char *shellPromptAppDef(int c){
2548625506
switch( c ){
2548725507
/* The default main prompt string */
2548825508
case 1:
25489
-#if defined(SQLITE_PS1)
25509
+#if SQLITE_SHELL_EDITION<20260423
25510
+ return "sqlite> "; /* Legacy prompt for backwards compatibility */
25511
+#elif defined(SQLITE_PS1)
2549025512
return SQLITE_PS1;
2549125513
#else
2549225514
if( shellNoColor() ){
2549325515
return "/A-/v /f-> ";
2549425516
}else{
@@ -25496,11 +25518,13 @@
2549625518
}
2549725519
#endif
2549825520
2549925521
/* The default continuation prompt string */
2550025522
case 2:
25501
-#if defined(SQLITE_PS2)
25523
+#if SQLITE_SHELL_EDITION<20260423
25524
+ return " ...> "; /* Legacy continuation prompt */
25525
+#elif defined(SQLITE_PS2)
2550225526
return SQLITE_PS2;
2550325527
#else
2550425528
if( shellNoColor() ){
2550525529
return "/B/C-> ";
2550625530
}else{
@@ -25969,30 +25993,33 @@
2596925993
zResult = local_getline(zPrior, in);
2597025994
}else{
2597125995
const char *zBase = prompt_string(p, bContinue!=0);
2597225996
char *zPrompt = expand_prompt(p, zAll, zBase);
2597325997
shell_check_oom(zPrompt);
25974
-#if SHELL_USE_LOCAL_GETLINE
25975
- sputz(stdout, zPrompt);
25976
- fflush(stdout);
25977
- do{
25978
- zResult = local_getline(zPrior, stdin);
25979
- zPrior = 0;
25980
- /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
25981
- if( zResult==0 ) sqlite3_sleep(50);
25982
- }while( zResult==0 && seenInterrupt>0 );
25983
-#else
25984
- free(zPrior);
25985
- zResult = shell_readline(zPrompt);
25986
- while( zResult==0 ){
25987
- /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
25988
- sqlite3_sleep(50);
25989
- if( seenInterrupt==0 ) break;
25990
- zResult = shell_readline("");
25991
- }
25992
- if( zResult && *zResult ) shell_add_history(zResult);
25993
-#endif
25998
+#if SHELL_CMDLINE_EDIT_AVAILABLE
25999
+ if( shellCmdLineEdit ){
26000
+ free(zPrior);
26001
+ zResult = shell_readline(zPrompt);
26002
+ while( zResult==0 ){
26003
+ /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
26004
+ sqlite3_sleep(50);
26005
+ if( seenInterrupt==0 ) break;
26006
+ zResult = shell_readline("");
26007
+ }
26008
+ if( zResult && *zResult ) shell_add_history(zResult);
26009
+ }else
26010
+#endif
26011
+ {
26012
+ sputz(stdout, zPrompt);
26013
+ fflush(stdout);
26014
+ do{
26015
+ zResult = local_getline(zPrior, stdin);
26016
+ zPrior = 0;
26017
+ /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
26018
+ if( zResult==0 ) sqlite3_sleep(50);
26019
+ }while( zResult==0 && seenInterrupt>0 );
26020
+ }
2599426021
sqlite3_free(zPrompt);
2599526022
}
2599626023
return zResult;
2599726024
}
2599826025
#endif /* !SQLITE_SHELL_FIDDLE */
@@ -26726,11 +26753,13 @@
2672626753
** already been freed and zeroed prior to calling this routine.
2672726754
*/
2672826755
static void modeDefault(ShellState *p){
2672926756
p->mode.spec.iVersion = 2;
2673026757
p->mode.autoExplain = 1;
26731
- if( stdin_is_interactive || stdout_is_console ){
26758
+ if( (stdin_is_interactive || stdout_is_console)
26759
+ && SQLITE_SHELL_EDITION>=20260409
26760
+ ){
2673226761
modeChange(p, MODE_TTY);
2673326762
}else{
2673426763
modeChange(p, MODE_BATCH);
2673526764
}
2673626765
}
@@ -35519,10 +35548,11 @@
3551935548
{ "attached", SQLITE_LIMIT_ATTACHED },
3552035549
{ "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
3552135550
{ "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
3552235551
{ "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
3552335552
{ "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
35553
+ { "schema", SQLITE_LIMIT_SCHEMA },
3552435554
};
3552535555
int i, n2;
3552635556
open_db(p, 0);
3552735557
if( nArg==1 ){
3552835558
for(i=0; i<ArraySize(aLimit); i++){
@@ -38213,10 +38243,11 @@
3821338243
" -ascii set '.mode ascii'\n"
3821438244
" -bail stop after hitting an error\n"
3821538245
" -batch force batch I/O\n"
3821638246
" -box set '.mode box'\n"
3821738247
" -cmd COMMAND run \"COMMAND\" before reading stdin\n"
38248
+ " -cmdline-edit BOOL enable or disable command-line editing\n"
3821838249
" -column set '.mode column'\n"
3821938250
" -csv set '.mode csv -limits off'\n"
3822038251
#if !defined(SQLITE_OMIT_DESERIALIZE)
3822138252
" -deserialize open the database using sqlite3_deserialize()\n"
3822238253
#endif
@@ -38483,10 +38514,13 @@
3848338514
stdout_is_console = 1;
3848438515
data.wasm.zDefaultDbName = "/fiddle.sqlite3";
3848538516
#else
3848638517
stdin_is_interactive = isatty(0);
3848738518
stdout_is_console = isatty(1);
38519
+ if( !stdin_is_interactive || !stdout_is_console ){
38520
+ shellCmdLineEdit = 0;
38521
+ }
3848838522
#endif
3848938523
atexit(abnormalExit);
3849038524
#ifdef SQLITE_DEBUG
3849138525
mem_main_enter = sqlite3_memory_used();
3849238526
#endif
@@ -38730,10 +38764,12 @@
3873038764
}else if( cli_strcmp(z,"-safe")==0 ){
3873138765
/* no-op - catch this on the second pass */
3873238766
}else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
3873338767
/* skip over the argument */
3873438768
i++;
38769
+ }else if( cli_strcmp(z,"-cmdline-edit")==0 ){
38770
+ shellCmdLineEdit = booleanValue(cmdline_option_value(argc,argv,++i));
3873538771
}else if( cli_strcmp(z,"-test-argv")==0 ){
3873638772
/* Undocumented test option. Print the values in argv[] and exit.
3873738773
** Use this to verify that any translation of the argv[], for example
3873838774
** on Windows that receives wargv[] from the OS and must convert
3873938775
** to UTF8 prior to calling this routine. */
@@ -38992,10 +39028,12 @@
3899239028
i++;
3899339029
#ifdef SQLITE_ENABLE_MULTIPLEX
3899439030
}else if( cli_strcmp(z,"-multiplex")==0 ){
3899539031
i++;
3899639032
#endif
39033
+ }else if( cli_strcmp(z,"-cmdline-edit")==0 ){
39034
+ i+=2;
3899739035
}else if( cli_strcmp(z,"-help")==0 ){
3899839036
usage(1);
3899939037
}else if( cli_strcmp(z,"-cmd")==0 ){
3900039038
/* Run commands that follow -cmd first and separately from commands
3900139039
** that simply appear on the command-line. This seems goofy. It would
@@ -39021,12 +39059,14 @@
3902139059
rc = 1;
3902239060
goto shell_main_exit;
3902339061
}
3902439062
open_db(&data, OPEN_DB_ZIPFILE);
3902539063
if( z[2] ){
39064
+ char *zSaved = argv[i];
3902639065
argv[i] = &z[2];
3902739066
arDotCommand(&data, 1, argv+(i-1), argc-(i-1));
39067
+ argv[i] = zSaved;
3902839068
}else{
3902939069
arDotCommand(&data, 1, argv+i, argc-i);
3903039070
}
3903139071
readStdin = 0;
3903239072
stdin_is_interactive = 0;
3903339073
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -206,28 +206,38 @@
206 # define shell_add_history(X) add_history(X)
207 # define shell_read_history(X) read_history(X)
208 # define shell_write_history(X) write_history(X)
209 # define shell_stifle_history(X) stifle_history(X)
210 # define shell_readline(X) readline(X)
 
211
212 #elif HAVE_LINENOISE
213
214 # include "linenoise.h"
215 # define shell_add_history(X) linenoiseHistoryAdd(X)
216 # define shell_read_history(X) linenoiseHistoryLoad(X)
217 # define shell_write_history(X) linenoiseHistorySave(X)
218 # define shell_stifle_history(X) linenoiseHistorySetMaxLen(X)
219 # define shell_readline(X) linenoise(X)
 
220
221 #else
222
223 # define shell_read_history(X)
224 # define shell_write_history(X)
225 # define shell_stifle_history(X)
 
 
226
227 # define SHELL_USE_LOCAL_GETLINE 1
228 #endif
 
 
 
 
 
 
229
230 #ifndef deliberate_fall_through
231 /* Quiet some compilers about some of our intentional code. */
232 # if defined(GCC_VERSION) && GCC_VERSION>=7000000
233 # define deliberate_fall_through __attribute__((fallthrough));
@@ -764,11 +774,11 @@
764 #define QRF_STYLE_Column 2 /* One record per line in neat columns */
765 #define QRF_STYLE_Count 3 /* Output only a count of the rows of output */
766 #define QRF_STYLE_Csv 4 /* Comma-separated-value */
767 #define QRF_STYLE_Eqp 5 /* Format EXPLAIN QUERY PLAN output */
768 #define QRF_STYLE_Explain 6 /* EXPLAIN output */
769 #define QRF_STYLE_Html 7 /* Generate an XHTML table */
770 #define QRF_STYLE_Insert 8 /* Generate SQL "insert" statements */
771 #define QRF_STYLE_Json 9 /* Output is a list of JSON objects */
772 #define QRF_STYLE_JObject 10 /* Independent JSON objects for each row */
773 #define QRF_STYLE_Line 11 /* One column per line. */
774 #define QRF_STYLE_List 12 /* One record per line with a separator */
@@ -3491,17 +3501,17 @@
3491 assert( p->nRow==0 );
3492 assert( p->spec.bTitles>=QRF_Yes );
3493 switch( p->spec.eStyle ){
3494 case QRF_STYLE_Html: {
3495 int i;
3496 sqlite3_str_append(p->pOut, "<TR>", 4);
3497 for(i=0; i<p->nCol; i++){
3498 const char *zCName = sqlite3_column_name(p->pStmt, i);
3499 sqlite3_str_append(p->pOut, "\n<TH>", 5);
3500 qrfEncodeText(p, p->pOut, zCName);
3501 }
3502 sqlite3_str_append(p->pOut, "\n</TR>\n", 7);
3503 break;
3504 }
3505 case QRF_STYLE_Quote:
3506 case QRF_STYLE_List: {
3507 int i;
@@ -3553,16 +3563,16 @@
3553 }
3554 case QRF_STYLE_Html: {
3555 if( p->nRow==0 && p->spec.bTitles>=QRF_Yes ){
3556 qrfSimpleTitle(p);
3557 }
3558 sqlite3_str_append(p->pOut, "<TR>", 4);
3559 for(i=0; i<p->nCol; i++){
3560 sqlite3_str_append(p->pOut, "\n<TD>", 5);
3561 qrfRenderValue(p, p->pOut, i);
3562 }
3563 sqlite3_str_append(p->pOut, "\n</TR>\n", 7);
3564 qrfWrite(p);
3565 break;
3566 }
3567 case QRF_STYLE_Insert: {
3568 unsigned int mxIns = p->spec.nMultiInsert;
@@ -24839,10 +24849,20 @@
24839 #endif
24840 #ifdef SQLITE_SHELL_EXTSRC
24841 # include SHELL_STRINGIFY(SQLITE_SHELL_EXTSRC)
24842 #endif
24843
 
 
 
 
 
 
 
 
 
 
24844 #if defined(SQLITE_ENABLE_SESSION)
24845 /*
24846 ** State information for a single open session
24847 */
24848 typedef struct OpenSession OpenSession;
@@ -25420,11 +25440,11 @@
25420 */
25421 static char *local_getline(char *zLine, FILE *in){
25422 int nLine = zLine==0 ? 0 : 100;
25423 int n = 0;
25424
25425 while( 1 ){
25426 if( n+100>nLine ){
25427 if( nLine>=1073741773 ){
25428 free(zLine);
25429 return 0;
25430 }
@@ -25484,11 +25504,13 @@
25484 # define SQLITE_PS_APPDEF shellPromptAppDef
25485 static const char *shellPromptAppDef(int c){
25486 switch( c ){
25487 /* The default main prompt string */
25488 case 1:
25489 #if defined(SQLITE_PS1)
 
 
25490 return SQLITE_PS1;
25491 #else
25492 if( shellNoColor() ){
25493 return "/A-/v /f-> ";
25494 }else{
@@ -25496,11 +25518,13 @@
25496 }
25497 #endif
25498
25499 /* The default continuation prompt string */
25500 case 2:
25501 #if defined(SQLITE_PS2)
 
 
25502 return SQLITE_PS2;
25503 #else
25504 if( shellNoColor() ){
25505 return "/B/C-> ";
25506 }else{
@@ -25969,30 +25993,33 @@
25969 zResult = local_getline(zPrior, in);
25970 }else{
25971 const char *zBase = prompt_string(p, bContinue!=0);
25972 char *zPrompt = expand_prompt(p, zAll, zBase);
25973 shell_check_oom(zPrompt);
25974 #if SHELL_USE_LOCAL_GETLINE
25975 sputz(stdout, zPrompt);
25976 fflush(stdout);
25977 do{
25978 zResult = local_getline(zPrior, stdin);
25979 zPrior = 0;
25980 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
25981 if( zResult==0 ) sqlite3_sleep(50);
25982 }while( zResult==0 && seenInterrupt>0 );
25983 #else
25984 free(zPrior);
25985 zResult = shell_readline(zPrompt);
25986 while( zResult==0 ){
25987 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
25988 sqlite3_sleep(50);
25989 if( seenInterrupt==0 ) break;
25990 zResult = shell_readline("");
25991 }
25992 if( zResult && *zResult ) shell_add_history(zResult);
25993 #endif
 
 
 
25994 sqlite3_free(zPrompt);
25995 }
25996 return zResult;
25997 }
25998 #endif /* !SQLITE_SHELL_FIDDLE */
@@ -26726,11 +26753,13 @@
26726 ** already been freed and zeroed prior to calling this routine.
26727 */
26728 static void modeDefault(ShellState *p){
26729 p->mode.spec.iVersion = 2;
26730 p->mode.autoExplain = 1;
26731 if( stdin_is_interactive || stdout_is_console ){
 
 
26732 modeChange(p, MODE_TTY);
26733 }else{
26734 modeChange(p, MODE_BATCH);
26735 }
26736 }
@@ -35519,10 +35548,11 @@
35519 { "attached", SQLITE_LIMIT_ATTACHED },
35520 { "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
35521 { "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
35522 { "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
35523 { "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
 
35524 };
35525 int i, n2;
35526 open_db(p, 0);
35527 if( nArg==1 ){
35528 for(i=0; i<ArraySize(aLimit); i++){
@@ -38213,10 +38243,11 @@
38213 " -ascii set '.mode ascii'\n"
38214 " -bail stop after hitting an error\n"
38215 " -batch force batch I/O\n"
38216 " -box set '.mode box'\n"
38217 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
 
38218 " -column set '.mode column'\n"
38219 " -csv set '.mode csv -limits off'\n"
38220 #if !defined(SQLITE_OMIT_DESERIALIZE)
38221 " -deserialize open the database using sqlite3_deserialize()\n"
38222 #endif
@@ -38483,10 +38514,13 @@
38483 stdout_is_console = 1;
38484 data.wasm.zDefaultDbName = "/fiddle.sqlite3";
38485 #else
38486 stdin_is_interactive = isatty(0);
38487 stdout_is_console = isatty(1);
 
 
 
38488 #endif
38489 atexit(abnormalExit);
38490 #ifdef SQLITE_DEBUG
38491 mem_main_enter = sqlite3_memory_used();
38492 #endif
@@ -38730,10 +38764,12 @@
38730 }else if( cli_strcmp(z,"-safe")==0 ){
38731 /* no-op - catch this on the second pass */
38732 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
38733 /* skip over the argument */
38734 i++;
 
 
38735 }else if( cli_strcmp(z,"-test-argv")==0 ){
38736 /* Undocumented test option. Print the values in argv[] and exit.
38737 ** Use this to verify that any translation of the argv[], for example
38738 ** on Windows that receives wargv[] from the OS and must convert
38739 ** to UTF8 prior to calling this routine. */
@@ -38992,10 +39028,12 @@
38992 i++;
38993 #ifdef SQLITE_ENABLE_MULTIPLEX
38994 }else if( cli_strcmp(z,"-multiplex")==0 ){
38995 i++;
38996 #endif
 
 
38997 }else if( cli_strcmp(z,"-help")==0 ){
38998 usage(1);
38999 }else if( cli_strcmp(z,"-cmd")==0 ){
39000 /* Run commands that follow -cmd first and separately from commands
39001 ** that simply appear on the command-line. This seems goofy. It would
@@ -39021,12 +39059,14 @@
39021 rc = 1;
39022 goto shell_main_exit;
39023 }
39024 open_db(&data, OPEN_DB_ZIPFILE);
39025 if( z[2] ){
 
39026 argv[i] = &z[2];
39027 arDotCommand(&data, 1, argv+(i-1), argc-(i-1));
 
39028 }else{
39029 arDotCommand(&data, 1, argv+i, argc-i);
39030 }
39031 readStdin = 0;
39032 stdin_is_interactive = 0;
39033
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -206,28 +206,38 @@
206 # define shell_add_history(X) add_history(X)
207 # define shell_read_history(X) read_history(X)
208 # define shell_write_history(X) write_history(X)
209 # define shell_stifle_history(X) stifle_history(X)
210 # define shell_readline(X) readline(X)
211 # define SHELL_CMDLINE_EDIT_AVAILABLE 1 /* command-line editing available */
212
213 #elif HAVE_LINENOISE
214
215 # include "linenoise.h"
216 # define shell_add_history(X) linenoiseHistoryAdd(X)
217 # define shell_read_history(X) linenoiseHistoryLoad(X)
218 # define shell_write_history(X) linenoiseHistorySave(X)
219 # define shell_stifle_history(X) linenoiseHistorySetMaxLen(X)
220 # define shell_readline(X) linenoise(X)
221 # define SHELL_CMDLINE_EDIT_AVAILABLE 1 /* command-line editing available */
222
223 #else
224
225 # define shell_read_history(X)
226 # define shell_write_history(X)
227 # define shell_stifle_history(X)
228 # define SHELL_CMDLINE_EDIT_AVAILABLE 0 /* command-line editing not available */
229 #endif
230
231 /*
232 ** Global variable shellCmdLineEdit determines whether or not command-line
233 ** editing is enabled. It defaults to 1 if the CLI is linked against a
234 ** command-line editing library (linenoise, readline, or editline) and
235 ** to 0 if no command-line editing library is available. The
236 ** "--cmdline-edit off" command-line option will change this value to 0.
237 */
238 static int shellCmdLineEdit = SHELL_CMDLINE_EDIT_AVAILABLE;
239
240 #ifndef deliberate_fall_through
241 /* Quiet some compilers about some of our intentional code. */
242 # if defined(GCC_VERSION) && GCC_VERSION>=7000000
243 # define deliberate_fall_through __attribute__((fallthrough));
@@ -764,11 +774,11 @@
774 #define QRF_STYLE_Column 2 /* One record per line in neat columns */
775 #define QRF_STYLE_Count 3 /* Output only a count of the rows of output */
776 #define QRF_STYLE_Csv 4 /* Comma-separated-value */
777 #define QRF_STYLE_Eqp 5 /* Format EXPLAIN QUERY PLAN output */
778 #define QRF_STYLE_Explain 6 /* EXPLAIN output */
779 #define QRF_STYLE_Html 7 /* Generate HTML-style <tr><td> output */
780 #define QRF_STYLE_Insert 8 /* Generate SQL "insert" statements */
781 #define QRF_STYLE_Json 9 /* Output is a list of JSON objects */
782 #define QRF_STYLE_JObject 10 /* Independent JSON objects for each row */
783 #define QRF_STYLE_Line 11 /* One column per line. */
784 #define QRF_STYLE_List 12 /* One record per line with a separator */
@@ -3491,17 +3501,17 @@
3501 assert( p->nRow==0 );
3502 assert( p->spec.bTitles>=QRF_Yes );
3503 switch( p->spec.eStyle ){
3504 case QRF_STYLE_Html: {
3505 int i;
3506 sqlite3_str_append(p->pOut, "<tr>", 4);
3507 for(i=0; i<p->nCol; i++){
3508 const char *zCName = sqlite3_column_name(p->pStmt, i);
3509 sqlite3_str_append(p->pOut, "\n<th>", 5);
3510 qrfEncodeText(p, p->pOut, zCName);
3511 }
3512 sqlite3_str_append(p->pOut, "\n</tr>\n", 7);
3513 break;
3514 }
3515 case QRF_STYLE_Quote:
3516 case QRF_STYLE_List: {
3517 int i;
@@ -3553,16 +3563,16 @@
3563 }
3564 case QRF_STYLE_Html: {
3565 if( p->nRow==0 && p->spec.bTitles>=QRF_Yes ){
3566 qrfSimpleTitle(p);
3567 }
3568 sqlite3_str_append(p->pOut, "<tr>", 4);
3569 for(i=0; i<p->nCol; i++){
3570 sqlite3_str_append(p->pOut, "\n<td>", 5);
3571 qrfRenderValue(p, p->pOut, i);
3572 }
3573 sqlite3_str_append(p->pOut, "\n</tr>\n", 7);
3574 qrfWrite(p);
3575 break;
3576 }
3577 case QRF_STYLE_Insert: {
3578 unsigned int mxIns = p->spec.nMultiInsert;
@@ -24839,10 +24849,20 @@
24849 #endif
24850 #ifdef SQLITE_SHELL_EXTSRC
24851 # include SHELL_STRINGIFY(SQLITE_SHELL_EXTSRC)
24852 #endif
24853
24854 /*
24855 ** Set the SQLITE_SHELL_EDITION to a YYYYMMDD date string and the
24856 ** code will attempt to use defaults for the prompt and for the
24857 ** initial output mode (and maybe other feature) that were for
24858 ** the most recent version not newer than the specified date.
24859 */
24860 #ifndef SQLITE_SHELL_EDITION
24861 # define SQLITE_SHELL_EDITION 99991231 /* Use the latest if unspecified */
24862 #endif
24863
24864 #if defined(SQLITE_ENABLE_SESSION)
24865 /*
24866 ** State information for a single open session
24867 */
24868 typedef struct OpenSession OpenSession;
@@ -25420,11 +25440,11 @@
25440 */
25441 static char *local_getline(char *zLine, FILE *in){
25442 int nLine = zLine==0 ? 0 : 100;
25443 int n = 0;
25444
25445 while( seenInterrupt<2 ){
25446 if( n+100>nLine ){
25447 if( nLine>=1073741773 ){
25448 free(zLine);
25449 return 0;
25450 }
@@ -25484,11 +25504,13 @@
25504 # define SQLITE_PS_APPDEF shellPromptAppDef
25505 static const char *shellPromptAppDef(int c){
25506 switch( c ){
25507 /* The default main prompt string */
25508 case 1:
25509 #if SQLITE_SHELL_EDITION<20260423
25510 return "sqlite> "; /* Legacy prompt for backwards compatibility */
25511 #elif defined(SQLITE_PS1)
25512 return SQLITE_PS1;
25513 #else
25514 if( shellNoColor() ){
25515 return "/A-/v /f-> ";
25516 }else{
@@ -25496,11 +25518,13 @@
25518 }
25519 #endif
25520
25521 /* The default continuation prompt string */
25522 case 2:
25523 #if SQLITE_SHELL_EDITION<20260423
25524 return " ...> "; /* Legacy continuation prompt */
25525 #elif defined(SQLITE_PS2)
25526 return SQLITE_PS2;
25527 #else
25528 if( shellNoColor() ){
25529 return "/B/C-> ";
25530 }else{
@@ -25969,30 +25993,33 @@
25993 zResult = local_getline(zPrior, in);
25994 }else{
25995 const char *zBase = prompt_string(p, bContinue!=0);
25996 char *zPrompt = expand_prompt(p, zAll, zBase);
25997 shell_check_oom(zPrompt);
25998 #if SHELL_CMDLINE_EDIT_AVAILABLE
25999 if( shellCmdLineEdit ){
26000 free(zPrior);
26001 zResult = shell_readline(zPrompt);
26002 while( zResult==0 ){
26003 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
26004 sqlite3_sleep(50);
26005 if( seenInterrupt==0 ) break;
26006 zResult = shell_readline("");
26007 }
26008 if( zResult && *zResult ) shell_add_history(zResult);
26009 }else
26010 #endif
26011 {
26012 sputz(stdout, zPrompt);
26013 fflush(stdout);
26014 do{
26015 zResult = local_getline(zPrior, stdin);
26016 zPrior = 0;
26017 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
26018 if( zResult==0 ) sqlite3_sleep(50);
26019 }while( zResult==0 && seenInterrupt>0 );
26020 }
26021 sqlite3_free(zPrompt);
26022 }
26023 return zResult;
26024 }
26025 #endif /* !SQLITE_SHELL_FIDDLE */
@@ -26726,11 +26753,13 @@
26753 ** already been freed and zeroed prior to calling this routine.
26754 */
26755 static void modeDefault(ShellState *p){
26756 p->mode.spec.iVersion = 2;
26757 p->mode.autoExplain = 1;
26758 if( (stdin_is_interactive || stdout_is_console)
26759 && SQLITE_SHELL_EDITION>=20260409
26760 ){
26761 modeChange(p, MODE_TTY);
26762 }else{
26763 modeChange(p, MODE_BATCH);
26764 }
26765 }
@@ -35519,10 +35548,11 @@
35548 { "attached", SQLITE_LIMIT_ATTACHED },
35549 { "like_pattern_length", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
35550 { "variable_number", SQLITE_LIMIT_VARIABLE_NUMBER },
35551 { "trigger_depth", SQLITE_LIMIT_TRIGGER_DEPTH },
35552 { "worker_threads", SQLITE_LIMIT_WORKER_THREADS },
35553 { "schema", SQLITE_LIMIT_SCHEMA },
35554 };
35555 int i, n2;
35556 open_db(p, 0);
35557 if( nArg==1 ){
35558 for(i=0; i<ArraySize(aLimit); i++){
@@ -38213,10 +38243,11 @@
38243 " -ascii set '.mode ascii'\n"
38244 " -bail stop after hitting an error\n"
38245 " -batch force batch I/O\n"
38246 " -box set '.mode box'\n"
38247 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
38248 " -cmdline-edit BOOL enable or disable command-line editing\n"
38249 " -column set '.mode column'\n"
38250 " -csv set '.mode csv -limits off'\n"
38251 #if !defined(SQLITE_OMIT_DESERIALIZE)
38252 " -deserialize open the database using sqlite3_deserialize()\n"
38253 #endif
@@ -38483,10 +38514,13 @@
38514 stdout_is_console = 1;
38515 data.wasm.zDefaultDbName = "/fiddle.sqlite3";
38516 #else
38517 stdin_is_interactive = isatty(0);
38518 stdout_is_console = isatty(1);
38519 if( !stdin_is_interactive || !stdout_is_console ){
38520 shellCmdLineEdit = 0;
38521 }
38522 #endif
38523 atexit(abnormalExit);
38524 #ifdef SQLITE_DEBUG
38525 mem_main_enter = sqlite3_memory_used();
38526 #endif
@@ -38730,10 +38764,12 @@
38764 }else if( cli_strcmp(z,"-safe")==0 ){
38765 /* no-op - catch this on the second pass */
38766 }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
38767 /* skip over the argument */
38768 i++;
38769 }else if( cli_strcmp(z,"-cmdline-edit")==0 ){
38770 shellCmdLineEdit = booleanValue(cmdline_option_value(argc,argv,++i));
38771 }else if( cli_strcmp(z,"-test-argv")==0 ){
38772 /* Undocumented test option. Print the values in argv[] and exit.
38773 ** Use this to verify that any translation of the argv[], for example
38774 ** on Windows that receives wargv[] from the OS and must convert
38775 ** to UTF8 prior to calling this routine. */
@@ -38992,10 +39028,12 @@
39028 i++;
39029 #ifdef SQLITE_ENABLE_MULTIPLEX
39030 }else if( cli_strcmp(z,"-multiplex")==0 ){
39031 i++;
39032 #endif
39033 }else if( cli_strcmp(z,"-cmdline-edit")==0 ){
39034 i+=2;
39035 }else if( cli_strcmp(z,"-help")==0 ){
39036 usage(1);
39037 }else if( cli_strcmp(z,"-cmd")==0 ){
39038 /* Run commands that follow -cmd first and separately from commands
39039 ** that simply appear on the command-line. This seems goofy. It would
@@ -39021,12 +39059,14 @@
39059 rc = 1;
39060 goto shell_main_exit;
39061 }
39062 open_db(&data, OPEN_DB_ZIPFILE);
39063 if( z[2] ){
39064 char *zSaved = argv[i];
39065 argv[i] = &z[2];
39066 arDotCommand(&data, 1, argv+(i-1), argc-(i-1));
39067 argv[i] = zSaved;
39068 }else{
39069 arDotCommand(&data, 1, argv+i, argc-i);
39070 }
39071 readStdin = 0;
39072 stdin_is_interactive = 0;
39073
+480 -246
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** c8aa208bf5b00f3ab93c5edd510dfd0d7edd with changes in files:
21
+** 2f1f4f73535386549c12694dc57cfe555eec with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.54.0"
471471
#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-07-08 15:43:42 c8aa208bf5b00f3ab93c5edd510dfd0d7edd271c064f159616ee409b308f7eb9"
472
+#define SQLITE_SOURCE_ID "2026-07-24 16:28:47 2f1f4f73535386549c12694dc57cfe555eec689ae6824c6241aaf8d5befcd74d"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-07-08T15:43:42.959Z"
475
+#define SQLITE_SCM_DATETIME "2026-07-24T16:28:47.830Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -4751,10 +4751,14 @@
47514751
** nesting depth for separate triggers.</dd>)^
47524752
**
47534753
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
47544754
** <dd>The maximum number of auxiliary worker threads that a single
47554755
** [prepared statement] may start.</dd>)^
4756
+**
4757
+** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4758
+** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4759
+** defined by the database schema.</dd>)^
47564760
** </dl>
47574761
*/
47584762
#define SQLITE_LIMIT_LENGTH 0
47594763
#define SQLITE_LIMIT_SQL_LENGTH 1
47604764
#define SQLITE_LIMIT_COLUMN 2
@@ -4766,10 +4770,11 @@
47664770
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
47674771
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
47684772
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
47694773
#define SQLITE_LIMIT_WORKER_THREADS 11
47704774
#define SQLITE_LIMIT_PARSER_DEPTH 12
4775
+#define SQLITE_LIMIT_SCHEMA 13
47714776
47724777
/*
47734778
** CAPI3REF: Prepare Flags
47744779
**
47754780
** These constants define various flags that can be passed into the
@@ -6798,11 +6803,15 @@
67986803
** to by the second parameter and which is N bytes long where N is the
67996804
** third parameter.
68006805
**
68016806
** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
68026807
** interfaces set the result of the application-defined function to be
6803
-** a BLOB containing all zero bytes and N bytes in size.
6808
+** a BLOB containing all zero bytes and N bytes in size. The
6809
+** zeroblob64(C,N) interface returns a [result code], which is normally
6810
+** [SQLITE_OK] but might be some other value if the requested operation
6811
+** could not be complete, for example if insufficient memory is available
6812
+** or if the value of N is out of range.
68046813
**
68056814
** ^The sqlite3_result_double() interface sets the result from
68066815
** an application-defined function to be a floating point value specified
68076816
** by its 2nd argument.
68086817
**
@@ -15031,10 +15040,37 @@
1503115040
*/
1503215041
#ifndef SQLITE_MAX_TRIGGER_DEPTH
1503315042
# define SQLITE_MAX_TRIGGER_DEPTH 1000
1503415043
#endif
1503515044
15045
+/*
15046
+** Maximum number of objects defined by a single database schema.
15047
+** Objects include:
15048
+**
15049
+** * tables (including the sqlite_schema table)
15050
+** * virtual tables
15051
+** * named indexes
15052
+** * indexes created automatically by UNIQUE and PRIMARY KEY constraints
15053
+** * triggers
15054
+** * views
15055
+**
15056
+** The total of all of the above is the number of objects in the schema,
15057
+** and that number may not exceed this value.
15058
+**
15059
+** The maximum number of objects is restricted to forestall theoretical
15060
+** signed integer overflow attacks using databases with billions of
15061
+** schema objects. Such attacks are "theoretical" because memory and
15062
+** disk space constraints would be reached long before billions of schema
15063
+** objects could be created. Even so, it seems good to have a well defined
15064
+** upper limit on the complexity of the schema, for defense in depth.
15065
+** No real-world application should ever get anywhere close to hitting
15066
+** this limit.
15067
+*/
15068
+#ifndef SQLITE_MAX_SCHEMA
15069
+# define SQLITE_MAX_SCHEMA 10000000
15070
+#endif
15071
+
1503615072
/************** End of sqliteLimit.h *****************************************/
1503715073
/************** Continuing where we left off in sqliteInt.h ******************/
1503815074
1503915075
/* Disable nuisance warnings on Borland compilers */
1504015076
#if defined(__BORLANDC__)
@@ -15289,11 +15325,13 @@
1528915325
** bitmask tests, testcase() can be used to make sure each bit
1529015326
** is significant and used at least once. On switch statements
1529115327
** where multiple cases go to the same block of code, testcase()
1529215328
** can insure that all cases are evaluated.
1529315329
*/
15294
-#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
15330
+#if defined(SQLITE_MUTATION_TEST)
15331
+# define testcase(X)
15332
+#elif defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
1529515333
# ifndef SQLITE_AMALGAMATION
1529615334
extern unsigned int sqlite3CoverageCounter;
1529715335
# endif
1529815336
# define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; }
1529915337
#else
@@ -18636,11 +18674,11 @@
1863618674
1863718675
/*
1863818676
** The number of different kinds of things that can be limited
1863918677
** using the sqlite3_limit() interface.
1864018678
*/
18641
-#define SQLITE_N_LIMIT (SQLITE_LIMIT_PARSER_DEPTH+1)
18679
+#define SQLITE_N_LIMIT (SQLITE_LIMIT_SCHEMA+1)
1864218680
1864318681
/*
1864418682
** Lookaside malloc is a set of fixed-size buffers that can be used
1864518683
** to satisfy small transient memory allocation requests for objects
1864618684
** associated with a particular database connection. The use of
@@ -22010,10 +22048,11 @@
2201022048
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
2201122049
SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
2201222050
#endif
2201322051
#if defined(SQLITE_TEST)
2201422052
SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
22053
+SQLITE_PRIVATE const char *sqlite3TestPtrToText(void*);
2201522054
#endif
2201622055
2201722056
#if defined(SQLITE_DEBUG)
2201822057
SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView*, const char *zFormat, ...);
2201922058
SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
@@ -22234,10 +22273,11 @@
2223422273
SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
2223522274
SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
2223622275
SQLITE_PRIVATE void sqlite3ClearOnOrUsing(sqlite3*, OnOrUsing*);
2223722276
SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
2223822277
SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,int,int,char**);
22278
+SQLITE_PRIVATE int sqlite3IndexBloomable(const Index*,int);
2223922279
SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
2224022280
Expr*, int, int, u8);
2224122281
SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
2224222282
SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
2224322283
SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
@@ -23646,10 +23686,13 @@
2364623686
"MAX_PAGE_COUNT=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_COUNT),
2364723687
#endif
2364823688
#ifdef SQLITE_MAX_PAGE_SIZE
2364923689
"MAX_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_SIZE),
2365023690
#endif
23691
+#ifdef SQLITE_MAX_SCHEMA
23692
+ "MAX_SCHEMA=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA),
23693
+#endif
2365123694
#ifdef SQLITE_MAX_SCHEMA_RETRY
2365223695
"MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
2365323696
#endif
2365423697
#ifdef SQLITE_MAX_SQL_LENGTH
2365523698
"MAX_SQL_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_SQL_LENGTH),
@@ -26531,11 +26574,11 @@
2653126574
** on the appropriate weekday, this is a no-op.
2653226575
*/
2653326576
if( sqlite3_strnicmp(z, "weekday ", 8)==0
2653426577
&& sqlite3AtoF(&z[8], &r)>0
2653526578
&& r>=-6.0 && r<=6.0
26536
- && (n=(int)r)==r
26579
+ && sqlite3RealSameAsInt(r,(i64)(n=(int)r))
2653726580
){
2653826581
sqlite3_int64 Z;
2653926582
computeYMD_HMS(p);
2654026583
p->tz = 0;
2654126584
p->validJD = 0;
@@ -46092,11 +46135,10 @@
4609246135
i64 nNew /* Required mapping size */
4609346136
){
4609446137
const char *zErr = "mmap";
4609546138
int h = pFd->h; /* File descriptor open on db file */
4609646139
u8 *pOrig = (u8 *)pFd->pMapRegion; /* Pointer to current file mapping */
46097
- i64 nOrig = pFd->mmapSizeActual; /* Size of pOrig region in bytes */
4609846140
u8 *pNew = 0; /* Location of new mapping */
4609946141
int flags = PROT_READ; /* Flags to pass to mmap() */
4610046142
4610146143
assert( pFd->nFetchOut==0 );
4610246144
assert( nNew>pFd->mmapSize );
@@ -46110,25 +46152,16 @@
4611046152
#endif
4611146153
4611246154
if( pOrig ){
4611346155
#if HAVE_MREMAP
4611446156
i64 nReuse = pFd->mmapSize;
46157
+ pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
46158
+ zErr = "mremap";
4611546159
#else
4611646160
const int szSyspage = osGetpagesize();
4611746161
i64 nReuse = (pFd->mmapSize & ~(szSyspage-1));
46118
-#endif
4611946162
u8 *pReq = &pOrig[nReuse];
46120
-
46121
- /* Unmap any pages of the existing mapping that cannot be reused. */
46122
- if( nReuse!=nOrig ){
46123
- osMunmap(pReq, nOrig-nReuse);
46124
- }
46125
-
46126
-#if HAVE_MREMAP
46127
- pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
46128
- zErr = "mremap";
46129
-#else
4613046163
pNew = osMmap(pReq, nNew-nReuse, flags, MAP_SHARED, h, nReuse);
4613146164
if( pNew!=MAP_FAILED ){
4613246165
if( pNew!=pReq ){
4613346166
osMunmap(pNew, nNew - nReuse);
4613446167
pNew = 0;
@@ -46759,40 +46792,33 @@
4675946792
verifyDbFile(pNew);
4676046793
}
4676146794
return rc;
4676246795
}
4676346796
46764
-/*
46765
-** Directories to consider for temp files.
46766
-*/
46767
-static const char *azTempDirs[] = {
46768
- 0,
46769
- 0,
46770
- "/var/tmp",
46771
- "/usr/tmp",
46772
- "/tmp",
46773
- "."
46774
-};
46775
-
46776
-/*
46777
-** Initialize first two members of azTempDirs[] array.
46778
-*/
46779
-static void unixTempFileInit(void){
46780
- azTempDirs[0] = getenv("SQLITE_TMPDIR");
46781
- azTempDirs[1] = getenv("TMPDIR");
46782
-}
46783
-
4678446797
/*
4678546798
** Return the name of a directory in which to put temporary files.
4678646799
** If no suitable temporary file directory can be found, return NULL.
46800
+**
46801
+** The return value might be a string obtained from getenv() and so
46802
+** the return value should not be used after any call to setenv() or
46803
+** putenv() as that value might have been freed.
4678746804
*/
4678846805
static const char *unixTempFileDir(void){
46789
- unsigned int i = 0;
46806
+ unsigned int i;
4679046807
struct stat buf;
46791
- const char *zDir = sqlite3_temp_directory;
46808
+ const char *zDir;
4679246809
46793
- while(1){
46810
+ for(i=0; i<7; i++){
46811
+ switch( i ){
46812
+ case 0: zDir = sqlite3_temp_directory; break;
46813
+ case 1: zDir = getenv("SQLITE_TMPDIR"); break;
46814
+ case 2: zDir = getenv("TMPDIR"); break;
46815
+ case 3: zDir = "/var/tmp"; break;
46816
+ case 4: zDir = "/usr/tmp"; break;
46817
+ case 5: zDir = "/tmp"; break;
46818
+ default: zDir = "."; break;
46819
+ }
4679446820
if( zDir!=0
4679546821
#if OS_VXWORKS
4679646822
&& zDir[0]=='/'
4679746823
#endif
4679846824
&& osStat(zDir, &buf)==0
@@ -46799,12 +46825,10 @@
4679946825
&& S_ISDIR(buf.st_mode)
4680046826
&& osAccess(zDir, 03)==0
4680146827
){
4680246828
return zDir;
4680346829
}
46804
- if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break;
46805
- zDir = azTempDirs[i++];
4680646830
}
4680746831
return 0;
4680846832
}
4680946833
4681046834
/*
@@ -49083,13 +49107,10 @@
4908349107
** DMS UNIX_SHM_BASE+8 128
4908449108
*/
4908549109
assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */
4908649110
#endif
4908749111
49088
- /* Initialize temp file dir array. */
49089
- unixTempFileInit();
49090
-
4909149112
return SQLITE_OK;
4909249113
}
4909349114
4909449115
/*
4909549116
** Shutdown the operating system interface.
@@ -93648,14 +93669,15 @@
9364893669
SQLITE_API void sqlite3_result_str(sqlite3_context *pCtx, sqlite3_str *pStr, int eOwn){
9364993670
#ifdef SQLITE_ENABLE_API_ARMOR
9365093671
if( pCtx==0 ) return;
9365193672
if( pStr==0 ) return;
9365293673
#endif
93674
+ testcase( pStr==(sqlite3_str*)&sqlite3OomStr );
9365393675
if( pStr->accError==0 ){
9365493676
if( pStr->nChar==0 ){
9365593677
setResultStrOrError(pCtx, "", 0, SQLITE_UTF8_ZT, SQLITE_STATIC);
93656
- if( eOwn ) sqlite3_str_reset(pStr);
93678
+ sqlite3_str_reset(pStr);
9365793679
}else{
9365893680
const char *zText = sqlite3_str_value(pStr);
9365993681
/* Only internal code has the ability to capture a pointer to
9366093682
** an sqlite3_str object that uses static buffer. And none of
9366193683
** those internal use cases every invoke the sqlite3_result_str()
@@ -93666,26 +93688,21 @@
9366693688
setResultStrOrError(pCtx, zText, pStr->nChar,
9366793689
SQLITE_UTF8, SQLITE_TRANSIENT);
9366893690
}else{
9366993691
setResultStrOrError(pCtx, zText, pStr->nChar,
9367093692
SQLITE_UTF8_ZT, SQLITE_DYNAMIC);
93693
+ sqlite3StrAccumInit(pStr, pStr->db, 0, 0, pStr->mxAlloc);
9367193694
}
9367293695
}
9367393696
}else if( pStr->accError==SQLITE_NOMEM ){
9367493697
sqlite3_result_error_nomem(pCtx);
9367593698
}else{
9367693699
assert( pStr->accError==SQLITE_TOOBIG );
9367793700
sqlite3_result_error_toobig(pCtx);
9367893701
}
93679
- if( eOwn ){
93680
- testcase( pStr==(sqlite3_str*)&sqlite3OomStr );
93681
- if( pStr->accError==0 ){
93682
- sqlite3StrAccumInit(pStr, pStr->db, 0, 0, pStr->mxAlloc);
93683
- }
93684
- if( eOwn==SQLITE_FINISH ){
93685
- sqlite3_str_free(pStr);
93686
- }
93702
+ if( eOwn==SQLITE_FINISH ){
93703
+ sqlite3_str_free(pStr);
9368793704
}
9368893705
}
9368993706
9369093707
#ifndef SQLITE_UNTESTABLE
9369193708
/* Force the INT64 value currently stored as the result to be
@@ -96574,10 +96591,14 @@
9657496591
}
9657596592
9657696593
/*
9657796594
** Compute a bloom filter hash using pOp->p4.i registers from aMem[] beginning
9657896595
** with pOp->p3. Return the hash.
96596
+**
96597
+** IMPORTANT RESTRICTION (tag-202607231411): This hash is only valid if the
96598
+** collating sequence for TEXT is BINARY. Hence, Bloom filters that use this
96599
+** hash will not work for look-ups that use any other collating sequence.
9657996600
*/
9658096601
static u64 filterHash(const Mem *aMem, const Op *pOp){
9658196602
int i, mx;
9658296603
u64 h = 0;
9658396604
@@ -96586,15 +96607,32 @@
9658696607
const Mem *p = &aMem[i];
9658796608
if( p->flags & (MEM_Int|MEM_IntReal) ){
9658896609
h += p->u.i;
9658996610
}else if( p->flags & MEM_Real ){
9659096611
h += sqlite3VdbeIntValue(p);
96591
- }else if( p->flags & (MEM_Str|MEM_Blob) ){
96592
- /* All strings have the same hash and all blobs have the same hash,
96593
- ** though, at least, those hashes are different from each other and
96594
- ** from NULL. */
96595
- h += 4093 + (p->flags & (MEM_Str|MEM_Blob));
96612
+ }else if( p->flags & MEM_Str ){
96613
+ u64 x;
96614
+ h += p->n;
96615
+ if( p->n >= sizeof(x) ){
96616
+ memcpy(&x, p->z, sizeof(x));
96617
+ h += x;
96618
+ memcpy(&x, p->z + p->n - sizeof(x), sizeof(x));
96619
+ h += x;
96620
+ }else{
96621
+ x = 0;
96622
+ memcpy(&x, p->z, p->n);
96623
+ h += x;
96624
+ }
96625
+ }else if( p->flags & MEM_Blob ){
96626
+ int n = p->n;
96627
+ u64 x = 0;
96628
+ if( n ){
96629
+ memcpy(&x, p->z, MIN(n, sizeof(x)));
96630
+ h += x;
96631
+ }
96632
+ h += n;
96633
+ if( p->flags & MEM_Zero ) h += p->u.nZero;
9659696634
}
9659796635
}
9659896636
return h;
9659996637
}
9660096638
@@ -101417,11 +101455,11 @@
101417101455
*/
101418101456
case OP_SeekRowid: { /* jump0, in3, ncycle */
101419101457
VdbeCursor *pC;
101420101458
BtCursor *pCrsr;
101421101459
int res;
101422
- u64 iKey;
101460
+ i64 iKey;
101423101461
101424101462
pIn3 = &aMem[pOp->p3];
101425101463
testcase( pIn3->flags & MEM_Int );
101426101464
testcase( pIn3->flags & MEM_IntReal );
101427101465
testcase( pIn3->flags & MEM_Real );
@@ -101431,13 +101469,23 @@
101431101469
** integer value of pIn3. Jump to P2 if pIn3 cannot be converted
101432101470
** into an integer without loss of information. Take care to avoid
101433101471
** changing the datatype of pIn3, however, as it is used by other
101434101472
** parts of the prepared statement. */
101435101473
Mem x = pIn3[0];
101436
- applyAffinity(&x, SQLITE_AFF_NUMERIC, encoding);
101437
- if( (x.flags & MEM_Int)==0 ) goto jump_to_p2;
101438
- iKey = x.u.i;
101474
+ if( x.flags & MEM_Str ){
101475
+ applyNumericAffinity(&x, 1);
101476
+ }
101477
+ if( x.flags & MEM_Int ){
101478
+ iKey = x.u.i;
101479
+ }else
101480
+ if( (x.flags & MEM_Real)==0
101481
+ || x.u.r < -9223372036854775808.0
101482
+ || x.u.r > 9223372036854775807.0
101483
+ || (double)(iKey = sqlite3RealToI64(x.u.r))!=x.u.r
101484
+ ){
101485
+ goto jump_to_p2;
101486
+ }
101439101487
goto notExistsWithKey;
101440101488
}
101441101489
/* Fall through into OP_NotExists */
101442101490
/* no break */ deliberate_fall_through
101443101491
case OP_NotExists: /* jump, in3, ncycle */
@@ -110677,18 +110725,17 @@
110677110725
if( cnt==1 ){
110678110726
assert( pNC!=0 );
110679110727
#ifndef SQLITE_OMIT_AUTHORIZATION
110680110728
if( db->xAuth ){
110681110729
if( pFJMatch ){
110682
- int ii;
110683110730
assert( pExpr->op==TK_FUNCTION );
110684110731
assert( sqlite3_stricmp(pExpr->u.zToken,"coalesce")==0 );
110685110732
assert( pExpr->x.pList==pFJMatch );
110686110733
assert( pFJMatch->nExpr>0 );
110687
- for(ii=0; ii<pFJMatch->nExpr; ii++){
110688
- assert( pFJMatch->a[0].pExpr->op==TK_COLUMN );
110689
- sqlite3AuthRead(pParse, pFJMatch->a[0].pExpr, pSchema, pNC->pSrcList);
110734
+ for(i=0; i<pFJMatch->nExpr; i++){
110735
+ assert( pFJMatch->a[i].pExpr->op==TK_COLUMN );
110736
+ sqlite3AuthRead(pParse,pFJMatch->a[i].pExpr,pSchema,pNC->pSrcList);
110690110737
}
110691110738
}else if( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ){
110692110739
sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
110693110740
}
110694110741
}
@@ -110802,15 +110849,24 @@
110802110849
static SQLITE_NOINLINE void resolveSetExprSubtypeArg(ExprList *pList){
110803110850
int nn, ii;
110804110851
nn = pList ? pList->nExpr : 0;
110805110852
for(ii=0; ii<nn; ii++){
110806110853
Expr *pExpr = pList->a[ii].pExpr;
110807
- ExprSetProperty(pExpr, EP_SubtArg);
110808
- if( pExpr->op==TK_SELECT ){
110809
- assert( ExprUseXSelect(pExpr) );
110810
- assert( pExpr->x.pSelect!=0 );
110811
- resolveSetExprSubtypeArg(pExpr->x.pSelect->pEList);
110854
+ while( 1 /*exit-by-break*/ ){
110855
+ ExprSetProperty(pExpr, EP_SubtArg);
110856
+ if( pExpr->op==TK_SELECT ){
110857
+ assert( ExprUseXSelect(pExpr) );
110858
+ assert( pExpr->x.pSelect!=0 );
110859
+ resolveSetExprSubtypeArg(pExpr->x.pSelect->pEList);
110860
+ break;
110861
+ }
110862
+ if( pExpr->op==TK_UPLUS ){
110863
+ pExpr = pExpr->pLeft;
110864
+ assert( pExpr!=0 );
110865
+ }else{
110866
+ break;
110867
+ }
110812110868
}
110813110869
}
110814110870
}
110815110871
110816110872
/*
@@ -115893,10 +115949,12 @@
115893115949
}else{
115894115950
VdbeComment((v, "RHS of IN operator"));
115895115951
}
115896115952
#endif
115897115953
pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
115954
+ assert( pKeyInfo!=0 || pParse->nErr );
115955
+ if( pKeyInfo==0 ) return;
115898115956
115899115957
if( ExprUseXSelect(pExpr) ){
115900115958
/* Case 1: expr IN (SELECT ...)
115901115959
**
115902115960
** Generate code to write the results of the select into the temporary
@@ -115917,21 +115975,35 @@
115917115975
int rc;
115918115976
int addrBloom = 0;
115919115977
sqlite3SelectDestInit(&dest, SRT_Set, iTab);
115920115978
dest.zAffSdst = exprINAffinity(pParse, pExpr);
115921115979
pSelect->iLimit = 0;
115980
+ assert( pEList!=0 );
115981
+ assert( pEList->nExpr>0 );
115982
+ assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
115983
+ for(i=0; i<nVal; i++){
115984
+ Expr *p = sqlite3VectorFieldSubexpr(pLeft, i);
115985
+ CollSeq *pColl;
115986
+ pKeyInfo->aColl[i] = pColl = sqlite3BinaryCompareCollSeq(
115987
+ pParse, p, pEList->a[i].pExpr
115988
+ );
115989
+ if( !sqlite3IsBinary(pColl) ){
115990
+ allowBloom = 0; /* tag-202607231411 */
115991
+ }
115992
+ }
115922115993
if( addrOnce
115923115994
&& allowBloom
115924115995
&& OptimizationEnabled(pParse->db, SQLITE_BloomFilter)
115925115996
){
115926115997
int regBloom = ++pParse->nMem;
115927115998
addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
115928115999
VdbeComment((v, "Bloom filter"));
115929116000
dest.iSDParm2 = regBloom;
116001
+ sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
116002
+ pKeyInfo = 0;
115930116003
}
115931116004
testcase( pSelect->selFlags & SF_Distinct );
115932
- testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
115933116005
pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
115934116006
rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
115935116007
sqlite3SelectDelete(pParse->db, pCopy);
115936116008
sqlite3DbFree(pParse->db, dest.zAffSdst);
115937116009
if( addrBloom ){
@@ -115945,20 +116017,10 @@
115945116017
}
115946116018
if( rc ){
115947116019
sqlite3KeyInfoUnref(pKeyInfo);
115948116020
return;
115949116021
}
115950
- assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
115951
- assert( pEList!=0 );
115952
- assert( pEList->nExpr>0 );
115953
- assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
115954
- for(i=0; i<nVal; i++){
115955
- Expr *p = sqlite3VectorFieldSubexpr(pLeft, i);
115956
- pKeyInfo->aColl[i] = sqlite3BinaryCompareCollSeq(
115957
- pParse, p, pEList->a[i].pExpr
115958
- );
115959
- }
115960116022
}
115961116023
}else if( ALWAYS(pExpr->x.pList!=0) ){
115962116024
/* Case 2: expr IN (exprlist)
115963116025
**
115964116026
** For each expression, build an index key from the evaluation and
@@ -115975,14 +116037,13 @@
115975116037
if( affinity<=SQLITE_AFF_NONE ){
115976116038
affinity = SQLITE_AFF_BLOB;
115977116039
}else if( affinity==SQLITE_AFF_REAL ){
115978116040
affinity = SQLITE_AFF_NUMERIC;
115979116041
}
115980
- if( pKeyInfo ){
115981
- assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
115982
- pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
115983
- }
116042
+ assert( pKeyInfo!=0 );
116043
+ assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
116044
+ pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
115984116045
115985116046
/* Loop through each expression in <exprlist>. */
115986116047
r1 = sqlite3GetTempReg(pParse);
115987116048
r2 = sqlite3GetTempReg(pParse);
115988116049
for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
@@ -116935,11 +116996,11 @@
116935116996
if( pExpr->op!=TK_FUNCTION ){
116936116997
return WRC_Prune;
116937116998
}
116938116999
assert( ExprUseXList(pExpr) );
116939117000
db = pWalker->pParse->db;
116940
- n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
117001
+ n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
116941117002
pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
116942117003
if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
116943117004
pWalker->eCode = 1;
116944117005
return WRC_Abort;
116945117006
}
@@ -122344,19 +122405,41 @@
122344122405
122345122406
122346122407
/*
122347122408
** Argument z points into the body of a constraint - specifically the
122348122409
** second token of the constraint definition. For a named constraint,
122349
-** z points to the first token past the CONSTRAINT keyword. For an
122410
+** z points to the second token of the constraint definition. For an
122350122411
** unnamed NOT NULL constraint, z points to the first byte past the NOT
122351122412
** keyword.
122413
+**
122414
+** Argument eTok may be the token value of the first token of the constraint
122415
+** (e.g. TK_CHECK or TK_REFERENCES) or zero. If it is either TK_REFERENCES
122416
+** or TK_FOREIGN, special parsing is enabled to find the end of the foreign-key
122417
+** constraint definition.
122352122418
**
122353122419
** Return the number of bytes until the end of the constraint.
122354122420
*/
122355
-static int getConstraint(const u8 *z){
122421
+static int getConstraint(const u8 *z, int eTok){
122356122422
int iOff = 0;
122357122423
int t = 0;
122424
+
122425
+#ifndef SQLITE_OMIT_FOREIGN_KEY
122426
+ if( eTok==TK_FOREIGN ){
122427
+ /* For a FOREIGN KEY constraint, use getConstraint() to parse everything
122428
+ ** up to the REFERENCES keyword. Then getConstraintToken() to consume
122429
+ ** the TK_REFERENCES token itself. Then fall through to the special
122430
+ ** handling for TK_REFERENCES below. */
122431
+ iOff = getConstraint(z, 0);
122432
+ iOff += getConstraintToken(&z[iOff], &eTok);
122433
+ }
122434
+
122435
+ if( eTok==TK_REFERENCES ){
122436
+ /* REFERENCES is followed by a table name. Gobble this up here in
122437
+ ** case the table name is a fallback token like TK_GENERATED. */
122438
+ iOff += getConstraintToken(&z[iOff], &t);
122439
+ }
122440
+#endif
122358122441
122359122442
/* Now, the current constraint proceeds until the next occurence of one
122360122443
** of the following tokens:
122361122444
**
122362122445
** CONSTRAINT, PRIMARY, NOT, UNIQUE, CHECK, DEFAULT,
@@ -122525,24 +122608,24 @@
122525122608
|| t==TK_COMMA || t==TK_RP || t==TK_GENERATED || t==TK_AS
122526122609
){
122527122610
t = TK_CHECK;
122528122611
}else{
122529122612
iOff += nTok;
122530
- iOff += getConstraint(&zSql[iOff]);
122613
+ iOff += getConstraint(&zSql[iOff], t);
122531122614
}
122532122615
122533122616
if( cmp==0 || (iNotNull>=0 && t==TK_NOT) ){
122534
- if( t!=TK_NOT && t!=TK_CHECK ){
122617
+ if( t!=TK_NOT && t!=TK_CHECK && t!=TK_REFERENCES && t!=TK_FOREIGN ){
122535122618
errorMPrintf(ctx, "constraint may not be dropped: %s", zCons);
122536122619
return;
122537122620
}
122538122621
iEnd = iOff;
122539122622
break;
122540122623
}
122541122624
122542122625
}else if( t==TK_NOT && iNotNull==ii ){
122543
- iEnd = iOff + getConstraint(&zSql[iOff]);
122626
+ iEnd = iOff + getConstraint(&zSql[iOff], 0);
122544122627
break;
122545122628
}else if( t==TK_RP || t==TK_ILLEGAL ){
122546122629
iEnd = -1;
122547122630
break;
122548122631
}else if( t==TK_COMMA ){
@@ -128170,10 +128253,27 @@
128170128253
pIdx->aSortOrder = (u8*)zExtra;
128171128254
pIdx->nColumn = (u16)N; /* See tag-20250221-1 above for proof of safety */
128172128255
pIdx->isResized = 1;
128173128256
return SQLITE_OK;
128174128257
}
128258
+
128259
+/*
128260
+** Return true if the index pIdx can support a Bloom filter on its
128261
+** first N columns. Specifically, return true if all of the first N
128262
+** columns have the BINARY collating sequence or no collating sequence
128263
+** at all, and return false if there are any non-BINARY collating
128264
+** seqeuences on any of the first N columns. tag-202607231411
128265
+*/
128266
+SQLITE_PRIVATE int sqlite3IndexBloomable(const Index *pIdx, int N){
128267
+ int i;
128268
+ assert( pIdx!=0 );
128269
+ assert( N <= pIdx->nColumn );
128270
+ for(i=0; i<N; i++){
128271
+ if( sqlite3StrICmp(pIdx->azColl[i],"BINARY")!=0 ) return 0;
128272
+ }
128273
+ return 1;
128274
+}
128175128275
128176128276
/*
128177128277
** Estimate the total row width for a table.
128178128278
*/
128179128279
static void estimateTableWidth(Table *pTab){
@@ -130038,12 +130138,13 @@
130038130138
}
130039130139
}
130040130140
if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
130041130141
if( !ifNotExist ){
130042130142
sqlite3ErrorMsg(pParse, "index %s already exists", zName);
130143
+ }else if( db->init.busy ){
130144
+ sqlite3ErrorMsg(pParse,""); /* corruptSchema() will do the error */
130043130145
}else{
130044
- assert( !db->init.busy );
130045130146
sqlite3CodeVerifySchema(pParse, iDb);
130046130147
sqlite3ForceNotReadOnly(pParse);
130047130148
}
130048130149
goto exit_create_index;
130049130150
}
@@ -136304,17 +136405,21 @@
136304136405
static void percentSort(
136305136406
double *a, /* Array to sort */
136306136407
unsigned int n, /* Number of elements in array a[] */
136307136408
int iReq /* Element caller cares about (or -ve) */
136308136409
){
136309
- int iLt; /* Entries before a[iLt] are less than rPivot */
136310
- int iGt; /* Entries at or after a[iGt] are greater than rPivot */
136410
+ int iLt; /* Entries before a[iLt] are less than or equal to rPivot */
136411
+ int iGt; /* Entries a[iGt] and after are greater or equal to rPivot */
136311136412
int i; /* Loop counter */
136312136413
double rPivot; /* The pivot value */
136313136414
136314136415
assert( n>=2 );
136315136416
do{
136417
+ /* Put the first, middle, and last elements in sorted order.
136418
+ ** After doing so, return immediately if the array contains
136419
+ ** three or fewer elements as there is nothing more to do.
136420
+ */
136316136421
if( a[0]>a[n-1] ){
136317136422
SWAP_DOUBLE(a[0],a[n-1])
136318136423
}
136319136424
if( n==2 ) return;
136320136425
iGt = n-1;
@@ -136323,10 +136428,15 @@
136323136428
SWAP_DOUBLE(a[0],a[i])
136324136429
}else if( a[i]>a[iGt] ){
136325136430
SWAP_DOUBLE(a[i],a[iGt])
136326136431
}
136327136432
if( n==3 ) return;
136433
+
136434
+ /* Take the value of the middle element as the pivot. Shuffle
136435
+ ** values around so that all elements less than the pivot come
136436
+ ** before all elements greater than the pivot.
136437
+ */
136328136438
rPivot = a[i];
136329136439
iLt = i = 1;
136330136440
do{
136331136441
if( a[i]<rPivot ){
136332136442
if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt])
@@ -136340,12 +136450,16 @@
136340136450
}else{
136341136451
i++;
136342136452
}
136343136453
}while( i<iGt );
136344136454
136455
+ assert( iLt>0 && iLt<iGt && iGt<n );
136456
+ testcase( iGt>iLt+1 );
136345136457
assert( a[iLt]==rPivot );
136346
- assert( iGt>iLt );
136458
+ assert( a[iLt-1]<=rPivot );
136459
+ assert( a[iGt]>=rPivot );
136460
+ assert( a[iLt+1]>=rPivot );
136347136461
136348136462
if( iReq>=0 ){
136349136463
/* In this case, the only elements that the caller requires sorted into
136350136464
** the correct positions are elements a[iReq] and a[iReq+1]. At this
136351136465
** point we know that element a[iLt] is in the correct position and
@@ -140577,10 +140691,26 @@
140577140691
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
140578140692
regTrigCnt = pTrigger!=0 || sqlite3FkRequired(pParse, pTab, 0, 0);
140579140693
}else{
140580140694
pTrigger = 0;
140581140695
regTrigCnt = sqlite3FkRequired(pParse, pTab, 0, 0);
140696
+ }
140697
+ if( regTrigCnt ){
140698
+ /* At this point regTrigCnt is non-zero if there are DELETE triggers
140699
+ ** or FK triggers. But we only care about these things if there is
140700
+ ** a chance that a row will be deleted by an ON CONFLICT REPLACE
140701
+ ** constraint. So zero regTrigCnt if no such constraint can be found. */
140702
+ if( overrideError!=OE_Replace ){
140703
+ if( overrideError!=OE_Default ){
140704
+ regTrigCnt = 0;
140705
+ }else if( pkChng==0 || pPk || pTab->keyConf!=OE_Replace ){
140706
+ for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
140707
+ if( pIdx->onError==OE_Replace ) break;
140708
+ }
140709
+ if( pIdx==0 ) regTrigCnt = 0;
140710
+ }
140711
+ }
140582140712
}
140583140713
if( regTrigCnt ){
140584140714
/* Replace triggers might exist. Allocate the counter and
140585140715
** initialize it to zero. */
140586140716
regTrigCnt = ++pParse->nMem;
@@ -140629,13 +140759,17 @@
140629140759
** the UNIQUE constraints have run.
140630140760
*/
140631140761
if( onError==OE_Replace /* IPK rule is REPLACE */
140632140762
&& onError!=overrideError /* Rules for other constraints are different */
140633140763
&& pTab->pIndex /* There exist other constraints */
140634
- && !upsertIpkDelay /* IPK check already deferred by UPSERT */
140635140764
){
140636
- ipkTop = sqlite3VdbeAddOp0(v, OP_Goto)+1;
140765
+ if( upsertIpkDelay ){
140766
+ ipkTop = upsertIpkDelay + 1;
140767
+ upsertIpkDelay = 0;
140768
+ }else{
140769
+ ipkTop = sqlite3VdbeAddOp0(v, OP_Goto)+1;
140770
+ }
140637140771
VdbeComment((v, "defer IPK REPLACE until last"));
140638140772
}
140639140773
140640140774
if( isUpdate ){
140641140775
/* pkChng!=0 does not mean that the rowid has changed, only that
@@ -140725,15 +140859,15 @@
140725140859
sqlite3VdbeGoto(v, ignoreDest);
140726140860
break;
140727140861
}
140728140862
}
140729140863
sqlite3VdbeResolveLabel(v, addrRowidOk);
140730
- if( pUpsert && pUpsertClause!=pUpsert ){
140731
- upsertIpkReturn = sqlite3VdbeAddOp0(v, OP_Goto);
140732
- }else if( ipkTop ){
140864
+ if( ipkTop ){
140733140865
ipkBottom = sqlite3VdbeAddOp0(v, OP_Goto);
140734140866
sqlite3VdbeJumpHere(v, ipkTop-1);
140867
+ }else if( pUpsert && pUpsertClause!=pUpsert ){
140868
+ upsertIpkReturn = sqlite3VdbeAddOp0(v, OP_Goto);
140735140869
}
140736140870
}
140737140871
140738140872
/* Test all UNIQUE constraints by creating entries for each UNIQUE
140739140873
** index and making sure that duplicate entries do not already exist.
@@ -140749,10 +140883,11 @@
140749140883
int regIdx; /* Range of registers holding content for pIdx */
140750140884
int regR; /* Range of registers holding conflicting PK */
140751140885
int iThisCur; /* Cursor for this UNIQUE index */
140752140886
int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
140753140887
int addrConflictCk; /* First opcode in the conflict check logic */
140888
+ int nConflictCk; /* Number of opcodes in conflict check logic */
140754140889
140755140890
if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
140756140891
if( pUpsert ){
140757140892
pUpsertClause = sqlite3UpsertOfIndex(pUpsert, pIdx);
140758140893
if( upsertIpkDelay && pUpsertClause==pUpsert ){
@@ -140924,10 +141059,15 @@
140924141059
VdbeCoverageIf(v, op==OP_Ne);
140925141060
}
140926141061
}
140927141062
}
140928141063
}
141064
+
141065
+ nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
141066
+ assert( nConflictCk>0 || db->mallocFailed );
141067
+ testcase( nConflictCk<=0 );
141068
+ testcase( nConflictCk>1 );
140929141069
140930141070
/* Generate code that executes if the new index entry is not unique */
140931141071
assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
140932141072
|| onError==OE_Ignore || onError==OE_Replace || onError==OE_Update );
140933141073
switch( onError ){
@@ -140950,17 +141090,11 @@
140950141090
testcase( onError==OE_Ignore );
140951141091
sqlite3VdbeGoto(v, ignoreDest);
140952141092
break;
140953141093
}
140954141094
default: {
140955
- int nConflictCk; /* Number of opcodes in conflict check logic */
140956
-
140957141095
assert( onError==OE_Replace );
140958
- nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
140959
- assert( nConflictCk>0 || db->mallocFailed );
140960
- testcase( nConflictCk<=0 );
140961
- testcase( nConflictCk>1 );
140962141096
if( regTrigCnt ){
140963141097
sqlite3MultiWrite(pParse);
140964141098
nReplaceTrig++;
140965141099
}
140966141100
if( pTrigger && isUpdate ){
@@ -140970,62 +141104,62 @@
140970141104
regR, nPkField, 0, OE_Replace,
140971141105
(pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
140972141106
if( pTrigger && isUpdate ){
140973141107
sqlite3VdbeAddOp1(v, OP_CursorUnlock, iDataCur);
140974141108
}
140975
- if( regTrigCnt ){
140976
- int addrBypass; /* Jump destination to bypass recheck logic */
140977
-
140978
- sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
140979
- addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */
140980
- VdbeComment((v, "bypass recheck"));
140981
-
140982
- /* Here we insert code that will be invoked after all constraint
140983
- ** checks have run, if and only if one or more replace triggers
140984
- ** fired. */
140985
- sqlite3VdbeResolveLabel(v, lblRecheckOk);
140986
- lblRecheckOk = sqlite3VdbeMakeLabel(pParse);
140987
- if( pIdx->pPartIdxWhere ){
140988
- /* Bypass the recheck if this partial index is not defined
140989
- ** for the current row */
140990
- sqlite3VdbeAddOp2(v, OP_IsNull, regIdx-1, lblRecheckOk);
140991
- VdbeCoverage(v);
140992
- }
140993
- /* Copy the constraint check code from above, except change
140994
- ** the constraint-ok jump destination to be the address of
140995
- ** the next retest block */
140996
- while( nConflictCk>0 ){
140997
- VdbeOp x; /* Conflict check opcode to copy */
140998
- /* The sqlite3VdbeAddOp4() call might reallocate the opcode array.
140999
- ** Hence, make a complete copy of the opcode, rather than using
141000
- ** a pointer to the opcode. */
141001
- x = *sqlite3VdbeGetOp(v, addrConflictCk);
141002
- if( x.opcode!=OP_IdxRowid ){
141003
- int p2; /* New P2 value for copied conflict check opcode */
141004
- const char *zP4;
141005
- if( sqlite3OpcodeProperty[x.opcode]&OPFLG_JUMP ){
141006
- p2 = lblRecheckOk;
141007
- }else{
141008
- p2 = x.p2;
141009
- }
141010
- zP4 = x.p4type==P4_INT32 ? SQLITE_INT_TO_PTR(x.p4.i) : x.p4.z;
141011
- sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, zP4, x.p4type);
141012
- sqlite3VdbeChangeP5(v, x.p5);
141013
- VdbeCoverageIf(v, p2!=x.p2);
141014
- }
141015
- nConflictCk--;
141016
- addrConflictCk++;
141017
- }
141018
- /* If the retest fails, issue an abort */
141019
- sqlite3UniqueConstraint(pParse, OE_Abort, pIdx);
141020
-
141021
- sqlite3VdbeJumpHere(v, addrBypass); /* Terminate the recheck bypass */
141022
- }
141023141109
seenReplace = 1;
141024141110
break;
141025141111
}
141026141112
}
141113
+ if( regTrigCnt ){
141114
+ int addrBypass; /* Jump destination to bypass recheck logic */
141115
+
141116
+ sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
141117
+ addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */
141118
+ VdbeComment((v, "bypass recheck"));
141119
+
141120
+ /* Here we insert code that will be invoked after all constraint
141121
+ ** checks have run, if and only if one or more replace triggers
141122
+ ** fired. */
141123
+ sqlite3VdbeResolveLabel(v, lblRecheckOk);
141124
+ lblRecheckOk = sqlite3VdbeMakeLabel(pParse);
141125
+ if( pIdx->pPartIdxWhere ){
141126
+ /* Bypass the recheck if this partial index is not defined
141127
+ ** for the current row */
141128
+ sqlite3VdbeAddOp2(v, OP_IsNull, regIdx-1, lblRecheckOk);
141129
+ VdbeCoverage(v);
141130
+ }
141131
+ /* Copy the constraint check code from above, except change
141132
+ ** the constraint-ok jump destination to be the address of
141133
+ ** the next retest block */
141134
+ while( nConflictCk>0 ){
141135
+ VdbeOp x; /* Conflict check opcode to copy */
141136
+ /* The sqlite3VdbeAddOp4() call might reallocate the opcode array.
141137
+ ** Hence, make a complete copy of the opcode, rather than using
141138
+ ** a pointer to the opcode. */
141139
+ x = *sqlite3VdbeGetOp(v, addrConflictCk);
141140
+ if( x.opcode!=OP_IdxRowid ){
141141
+ int p2; /* New P2 value for copied conflict check opcode */
141142
+ const char *zP4;
141143
+ if( sqlite3OpcodeProperty[x.opcode]&OPFLG_JUMP ){
141144
+ p2 = lblRecheckOk;
141145
+ }else{
141146
+ p2 = x.p2;
141147
+ }
141148
+ zP4 = x.p4type==P4_INT32 ? SQLITE_INT_TO_PTR(x.p4.i) : x.p4.z;
141149
+ sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, zP4, x.p4type);
141150
+ sqlite3VdbeChangeP5(v, x.p5);
141151
+ VdbeCoverageIf(v, p2!=x.p2);
141152
+ }
141153
+ nConflictCk--;
141154
+ addrConflictCk++;
141155
+ }
141156
+ /* If the retest fails, issue an abort */
141157
+ sqlite3UniqueConstraint(pParse, OE_Abort, pIdx);
141158
+
141159
+ sqlite3VdbeJumpHere(v, addrBypass); /* Terminate the recheck bypass */
141160
+ }
141027141161
sqlite3VdbeResolveLabel(v, addrUniqueOk);
141028141162
if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
141029141163
if( pUpsertClause
141030141164
&& upsertIpkReturn
141031141165
&& sqlite3UpsertNextIsIPK(pUpsertClause)
@@ -141059,12 +141193,12 @@
141059141193
VdbeCoverage(v);
141060141194
sqlite3RowidConstraint(pParse, OE_Abort, pTab);
141061141195
}else{
141062141196
sqlite3VdbeGoto(v, addrRecheck);
141063141197
}
141064
- sqlite3VdbeResolveLabel(v, lblRecheckOk);
141065141198
}
141199
+ if( regTrigCnt ) sqlite3VdbeResolveLabel(v, lblRecheckOk);
141066141200
141067141201
/* Generate the table record */
141068141202
if( HasRowid(pTab) ){
141069141203
int regRec = aRegIdx[ix];
141070141204
sqlite3VdbeAddOp3(v, OP_MakeRecord, regNewData+1, pTab->nNVCol, regRec);
@@ -147540,10 +147674,11 @@
147540147674
corruptSchema(pData, argv, 0);
147541147675
return 1;
147542147676
}
147543147677
147544147678
assert( iDb>=0 && iDb<db->nDb );
147679
+ assert( db->aDb[iDb].pSchema!=0 );
147545147680
if( argv[3]==0 ){
147546147681
corruptSchema(pData, argv, 0);
147547147682
}else if( argv[4]
147548147683
&& 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
147549147684
&& 'r'==sqlite3UpperToLower[(unsigned char)argv[4][1]] ){
@@ -147614,10 +147749,20 @@
147614147749
){
147615147750
if( sqlite3Config.bExtraSchemaChecks ){
147616147751
corruptSchema(pData, argv, "invalid rootpage");
147617147752
}
147618147753
}
147754
+ }
147755
+ if( pData->pzErrMsg[0]==0 ){
147756
+ Schema *pX = db->aDb[iDb].pSchema;
147757
+ if( pX->tblHash.count + pX->idxHash.count + pX->trigHash.count
147758
+ > (u32)db->aLimit[SQLITE_LIMIT_SCHEMA]
147759
+ ){
147760
+ *pData->pzErrMsg = sqlite3MPrintf(db, "too many schema objects");
147761
+ pData->rc = SQLITE_ERROR;
147762
+ return 1;
147763
+ }
147619147764
}
147620147765
return 0;
147621147766
}
147622147767
147623147768
/*
@@ -149659,10 +149804,52 @@
149659149804
}
149660149805
pSort->nDefer = (u8)nDefer;
149661149806
*ppExtra = pExtra;
149662149807
}
149663149808
#endif
149809
+
149810
+#ifdef SQLITE_DEBUG
149811
+/*
149812
+** This is a byte-code validation check that only runs when SQLITE_DEBUG
149813
+** is defined. This routine looks backwards through the bytecode
149814
+** for the definition of cursor with index iCur. It extracts the KeyInfo from
149815
+** that cursor (it must be an index cursor) and verifies that the cursor
149816
+** does not use any collating seqeuences other than BINARY for its first
149817
+** nCol columns.
149818
+**
149819
+** This routine is used inside of an assert(). So it should return true
149820
+** on success and false if the invariant is not satisfied.
149821
+**
149822
+** tag-202607231411
149823
+*/
149824
+static int sqlite3CursorBloomable(Parse *pParse, int iCur, int nCol){
149825
+ int i,k;
149826
+ Vdbe *v = pParse->pVdbe;
149827
+ if( pParse->nErr ) return 1;
149828
+ assert( v );
149829
+ for(k=sqlite3VdbeCurrentAddr(v)-1; k>0; k--){
149830
+ const VdbeOp *pOp = sqlite3VdbeGetOp(v, k);
149831
+ const KeyInfo *pKeyInfo;
149832
+ if( pOp->p1!=iCur ) continue;
149833
+ if( pOp->opcode!=OP_OpenRead
149834
+ && pOp->opcode!=OP_OpenWrite
149835
+ && pOp->opcode!=OP_OpenEphemeral
149836
+ ){
149837
+ continue;
149838
+ }
149839
+ assert( pOp->p4type==P4_KEYINFO );
149840
+ pKeyInfo = (const KeyInfo*)pOp->p4.pKeyInfo;
149841
+ assert( pKeyInfo!=0 );
149842
+ for(i=0; i<nCol; i++){
149843
+ assert( sqlite3IsBinary(pKeyInfo->aColl[i]) );
149844
+ }
149845
+ return 1;
149846
+ }
149847
+ return 0;
149848
+}
149849
+#endif /* SQLITE_DEBUG */
149850
+
149664149851
149665149852
/*
149666149853
** This routine generates the code for the inside of the inner loop
149667149854
** of a SELECT.
149668149855
**
@@ -149930,10 +150117,11 @@
149930150117
assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
149931150118
sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
149932150119
r1, pDest->zAffSdst, nResultCol);
149933150120
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
149934150121
if( pDest->iSDParm2 ){
150122
+ assert( sqlite3CursorBloomable(pParse,iParm,nResultCol) );
149935150123
sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
149936150124
regResult, nResultCol);
149937150125
ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
149938150126
}
149939150127
sqlite3ReleaseTempReg(pParse, r1);
@@ -151739,10 +151927,11 @@
151739151927
sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
151740151928
r1, pDest->zAffSdst, pIn->nSdst);
151741151929
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
151742151930
pIn->iSdst, pIn->nSdst);
151743151931
if( pDest->iSDParm2>0 ){
151932
+ assert( sqlite3CursorBloomable(pParse, pDest->iSDParm, pIn->nSdst) );
151744151933
sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
151745151934
pIn->iSdst, pIn->nSdst);
151746151935
ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
151747151936
}
151748151937
sqlite3ReleaseTempReg(pParse, r1);
@@ -155688,11 +155877,12 @@
155688155877
assert( ExprUseXList(pExpr) );
155689155878
if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
155690155879
if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
155691155880
if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
155692155881
pFrom = p->pSrc->a;
155693
- if( pFrom->fg.isSubquery==0 ) return 0; /* FROM is a subquery */
155882
+ if( pFrom->fg.isSubquery==0 ) return 0; /* FROM is a subquery */
155883
+ if( (p->selFlags & SF_Correlated)!=0 ) return 0; /* Not a correlated subq */
155694155884
pSub = pFrom->u4.pSubq->pSelect;
155695155885
if( pSub->pPrior==0 ) return 0; /* Must be a compound */
155696155886
if( pSub->selFlags & SF_CopyCte ) return 0; /* Not a CTE */
155697155887
do{
155698155888
if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */
@@ -157919,12 +158109,13 @@
157919158109
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
157920158110
if( !IN_RENAME_OBJECT ){
157921158111
if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),zName) ){
157922158112
if( !noErr ){
157923158113
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
158114
+ }else if( db->init.busy ){
158115
+ sqlite3ErrorMsg(pParse,""); /* Err msg generated by corruptSchema() */
157924158116
}else{
157925
- assert( !db->init.busy );
157926158117
sqlite3CodeVerifySchema(pParse, iDb);
157927158118
VVA_ONLY( pParse->ifNotExists = 1; )
157928158119
}
157929158120
goto trigger_cleanup;
157930158121
}
@@ -163424,14 +163615,11 @@
163424163615
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
163425163616
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*);
163426163617
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
163427163618
SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
163428163619
SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*);
163429
-
163430
-
163431
-
163432
-
163620
+SQLITE_PRIVATE int sqlite3WhereLoopBloomable(const WhereLoop*);
163433163621
163434163622
/*
163435163623
** Bitmasks for the operators on WhereTerm objects. These are all
163436163624
** operators that are of interest to the query planner. An
163437163625
** OR-ed combination of these values can be used when searching for
@@ -164896,10 +165084,11 @@
164896165084
testcase( pTerm->wtFlags & TERM_VIRTUAL );
164897165085
regRowid = sqlite3GetTempReg(pParse);
164898165086
regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid);
164899165087
sqlite3VdbeAddOp2(pParse->pVdbe, OP_MustBeInt, regRowid, addrNxt);
164900165088
VdbeCoverage(pParse->pVdbe);
165089
+ assert( sqlite3WhereLoopBloomable(pLoop) );
164901165090
sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
164902165091
addrNxt, regRowid, 1);
164903165092
VdbeCoverage(pParse->pVdbe);
164904165093
}else{
164905165094
u16 nEq = pLoop->u.btree.nEq;
@@ -164909,10 +165098,11 @@
164909165098
assert( pLoop->wsFlags & WHERE_INDEXED );
164910165099
assert( (pLoop->wsFlags & WHERE_COLUMN_IN)==0 );
164911165100
r1 = codeAllEqualityTerms(pParse,pLevel,0,0,&zStartAff);
164912165101
codeApplyAffinity(pParse, r1, nEq, zStartAff);
164913165102
sqlite3DbFree(pParse->db, zStartAff);
165103
+ assert( sqlite3WhereLoopBloomable(pLoop) );
164914165104
sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
164915165105
addrNxt, r1, nEq);
164916165106
VdbeCoverage(pParse->pVdbe);
164917165107
}
164918165108
pLevel->regFilter = 0;
@@ -165512,10 +165702,11 @@
165512165702
if( regBignull ){
165513165703
sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
165514165704
VdbeComment((v, "NULL-scan pass ctr"));
165515165705
}
165516165706
if( pLevel->regFilter ){
165707
+ assert( sqlite3WhereLoopBloomable(pLoop) );
165517165708
sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt,
165518165709
regBase, nEq);
165519165710
VdbeCoverage(v);
165520165711
filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
165521165712
}
@@ -166249,12 +166440,14 @@
166249166440
jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, 0, r+1, nPk);
166250166441
VdbeCoverage(v);
166251166442
VdbeComment((v, "match against %s", pTab->zName));
166252166443
sqlite3VdbeAddOp3(v, OP_MakeRecord, r+1, nPk, r);
166253166444
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pRJ->iMatch, r, r+1, nPk);
166254
- sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r+1, nPk);
166255
- sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
166445
+ if( pRJ->regBloom ){
166446
+ sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r+1, nPk);
166447
+ sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
166448
+ }
166256166449
sqlite3VdbeJumpHere(v, jmp1);
166257166450
sqlite3ReleaseTempRange(pParse, r, nPk+1);
166258166451
}
166259166452
166260166453
/* For a LEFT OUTER JOIN, generate code that will record the fact that
@@ -166402,11 +166595,11 @@
166402166595
WHERE_RIGHT_JOIN, 0);
166403166596
if( pSubWInfo ){
166404166597
int iCur = pLevel->iTabCur;
166405166598
int r = ++pParse->nMem;
166406166599
int nPk;
166407
- int jmp;
166600
+ int jmp = 0;
166408166601
int addrCont = sqlite3WhereContinueLabel(pSubWInfo);
166409166602
Table *pTab = pTabItem->pSTab;
166410166603
if( HasRowid(pTab) ){
166411166604
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, -1, r);
166412166605
nPk = 1;
@@ -166418,15 +166611,17 @@
166418166611
for(iPk=0; iPk<nPk; iPk++){
166419166612
int iCol = pPk->aiColumn[iPk];
166420166613
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+iPk);
166421166614
}
166422166615
}
166423
- jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
166424
- VdbeCoverage(v);
166616
+ if( pRJ->regBloom ){
166617
+ jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
166618
+ VdbeCoverage(v);
166619
+ }
166425166620
sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, addrCont, r, nPk);
166426166621
VdbeCoverage(v);
166427
- sqlite3VdbeJumpHere(v, jmp);
166622
+ if( jmp ) sqlite3VdbeJumpHere(v, jmp);
166428166623
sqlite3VdbeAddOp2(v, OP_Gosub, pRJ->regReturn, pRJ->addrSubrtn);
166429166624
sqlite3WhereEnd(pSubWInfo);
166430166625
}
166431166626
sqlite3ExprDelete(pParse->db, pSubWhere);
166432166627
ExplainQueryPlanPop(pParse);
@@ -168414,10 +168609,20 @@
168414168609
}
168415168610
sqlite3SetJoinExpr(pTerm, pItem->iCursor, joinType);
168416168611
whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
168417168612
}
168418168613
}
168614
+
168615
+/*
168616
+** Return true if the WhereLoop pLoop can be use a Bloom filter.
168617
+** tag-202607231411
168618
+*/
168619
+SQLITE_PRIVATE int sqlite3WhereLoopBloomable(const WhereLoop *pLoop){
168620
+ if( pLoop->wsFlags & WHERE_IPK ) return 1;
168621
+ if( NEVER((pLoop->wsFlags & WHERE_INDEXED)==0) ) return 0;
168622
+ return sqlite3IndexBloomable(pLoop->u.btree.pIndex, pLoop->u.btree.nEq);
168623
+}
168419168624
168420168625
/************** End of whereexpr.c *******************************************/
168421168626
/************** Begin file where.c *******************************************/
168422168627
/*
168423168628
** 2001 September 15
@@ -169426,11 +169631,11 @@
169426169631
WhereLoop *pLoop; /* The Loop object */
169427169632
char *zNotUsed; /* Extra space on the end of pIdx */
169428169633
Bitmask idxCols; /* Bitmap of columns used for indexing */
169429169634
Bitmask extraCols; /* Bitmap of additional columns */
169430169635
u8 sentWarning = 0; /* True if a warning has been issued */
169431
- u8 useBloomFilter = 0; /* True to also add a Bloom filter */
169636
+ u8 useBloomFilter = 1; /* True to also add a Bloom filter */
169432169637
Expr *pPartial = 0; /* Partial Index Expression */
169433169638
int iContinue = 0; /* Jump here to skip excluded rows */
169434169639
SrcList *pTabList; /* The complete FROM clause */
169435169640
SrcItem *pSrc; /* The FROM clause term to get the next index */
169436169641
int addrCounter = 0; /* Address where integer counter is initialized */
@@ -169553,22 +169758,17 @@
169553169758
Expr *pX = pTerm->pExpr;
169554169759
idxCols |= cMask;
169555169760
pIdx->aiColumn[n] = pTerm->u.x.leftColumn;
169556169761
pColl = sqlite3ExprCompareCollSeq(pParse, pX);
169557169762
assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
169763
+ if( !sqlite3IsBinary(pColl) ){
169764
+ /* Disallow the use of a Bloom filter if any non-BINARY collating
169765
+ ** sequence is involved. tag-202607231411 */
169766
+ useBloomFilter = 0;
169767
+ }
169558169768
pIdx->azColl[n] = pColl ? pColl->zName : sqlite3StrBINARY;
169559169769
n++;
169560
- if( ALWAYS(pX->pLeft!=0)
169561
- && sqlite3ExprAffinity(pX->pLeft)!=SQLITE_AFF_TEXT
169562
- ){
169563
- /* TUNING: only use a Bloom filter on an automatic index
169564
- ** if one or more key columns has the ability to hold numeric
169565
- ** values, since strings all have the same hash in the Bloom
169566
- ** filter implementation and hence a Bloom filter on a text column
169567
- ** is not usually helpful. */
169568
- useBloomFilter = 1;
169569
- }
169570169770
}
169571169771
}
169572169772
}
169573169773
assert( (u32)n==pLoop->u.btree.nEq );
169574169774
@@ -169634,10 +169834,11 @@
169634169834
regRecord = sqlite3GetTempReg(pParse);
169635169835
regBase = sqlite3GenerateIndexKey(
169636169836
pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
169637169837
);
169638169838
if( pLevel->regFilter ){
169839
+ assert( sqlite3WhereLoopBloomable(pLoop) );
169639169840
sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
169640169841
regBase, pLoop->u.btree.nEq);
169641169842
}
169642169843
sqlite3VdbeScanStatusCounters(v, addrExp, addrExp, sqlite3VdbeCurrentAddr(v));
169643169844
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
@@ -169749,10 +169950,11 @@
169749169950
if( sz<10000 ){
169750169951
sz = 10000;
169751169952
}else if( sz>10000000 ){
169752169953
sz = 10000000;
169753169954
}
169955
+ assert( sqlite3WhereLoopBloomable(pLoop) );
169754169956
sqlite3VdbeAddOp2(v, OP_Blob, (int)sz, pLevel->regFilter);
169755169957
169756169958
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
169757169959
pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
169758169960
for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
@@ -169771,10 +169973,11 @@
169771169973
}else{
169772169974
Index *pIdx = pLoop->u.btree.pIndex;
169773169975
int n = pLoop->u.btree.nEq;
169774169976
int r1 = sqlite3GetTempRange(pParse, n);
169775169977
int jj;
169978
+ assert( pIdx!=0 );
169776169979
for(jj=0; jj<n; jj++){
169777169980
assert( pIdx->pTable==pItem->pSTab );
169778169981
sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iCur, jj, r1+jj);
169779169982
}
169780169983
sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n);
@@ -173427,11 +173630,11 @@
173427173630
}
173428173631
#ifndef SQLITE_OMIT_VIRTUALTABLE
173429173632
if( IsVirtual(pItem->pSTab) ){
173430173633
SrcItem *p;
173431173634
for(p=&pItem[1]; p<pEnd; p++){
173432
- if( mUnusable || (p->fg.jointype & (JT_OUTER|JT_CROSS)) ){
173635
+ if( (p->fg.jointype & (JT_OUTER|JT_CROSS)) ){
173433173636
mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
173434173637
}
173435173638
}
173436173639
rc = whereLoopAddVirtual(pBuilder, mPrereq, mUnusable);
173437173640
}else
@@ -175057,23 +175260,21 @@
175057175260
Table *pTab = pItem->pSTab;
175058175261
if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
175059175262
pTab->tabFlags |= TF_MaybeReanalyze;
175060175263
if( i>=1
175061175264
&& (pLoop->wsFlags & reqFlags)==reqFlags
175062
- /* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */
175063
- && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0)
175265
+ && sqlite3WhereLoopBloomable(pLoop)
175266
+ && nSearch > pTab->nRowLogEst
175064175267
){
175065
- if( nSearch > pTab->nRowLogEst ){
175066
- testcase( pItem->fg.jointype & JT_LEFT );
175067
- pLoop->wsFlags |= WHERE_BLOOMFILTER;
175068
- pLoop->wsFlags &= ~WHERE_IDX_ONLY;
175069
- WHERETRACE(0xffffffff, (
175070
- "-> use Bloom-filter on loop %c because there are ~%.1e "
175071
- "lookups into %s which has only ~%.1e rows\n",
175072
- pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName,
175073
- (double)sqlite3LogEstToInt(pTab->nRowLogEst)));
175074
- }
175268
+ testcase( pItem->fg.jointype & JT_LEFT );
175269
+ pLoop->wsFlags |= WHERE_BLOOMFILTER;
175270
+ pLoop->wsFlags &= ~WHERE_IDX_ONLY;
175271
+ WHERETRACE(0xffffffff, (
175272
+ "-> use Bloom-filter on loop %c because there are ~%.1e "
175273
+ "lookups into %s which has only ~%.1e rows\n",
175274
+ pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName,
175275
+ (double)sqlite3LogEstToInt(pTab->nRowLogEst)));
175075175276
}
175076175277
nSearch += pLoop->nOut;
175077175278
}
175078175279
}
175079175280
@@ -175819,19 +176020,19 @@
175819176020
if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
175820176021
if( (pTabItem->fg.jointype & JT_RIGHT)!=0
175821176022
&& (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
175822176023
){
175823176024
WhereRightJoin *pRJ = pLevel->pRJ;
176025
+ int bBloomable = 0;
175824176026
pRJ->iMatch = pParse->nTab++;
175825
- pRJ->regBloom = ++pParse->nMem;
175826
- sqlite3VdbeAddOp2(v, OP_Blob, 65536, pRJ->regBloom);
175827176027
pRJ->regReturn = ++pParse->nMem;
175828176028
sqlite3VdbeAddOp2(v, OP_Null, 0, pRJ->regReturn);
175829176029
assert( pTab==pTabItem->pSTab );
175830176030
if( HasRowid(pTab) ){
175831176031
KeyInfo *pInfo;
175832176032
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRJ->iMatch, 1);
176033
+ bBloomable = 1;
175833176034
pInfo = sqlite3KeyInfoAlloc(pParse->db, 1, 0);
175834176035
if( pInfo ){
175835176036
pInfo->aColl[0] = 0;
175836176037
pInfo->aSortFlags[0] = 0;
175837176038
sqlite3VdbeAppendP4(v, pInfo, P4_KEYINFO);
@@ -175838,10 +176039,17 @@
175838176039
}
175839176040
}else{
175840176041
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
175841176042
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRJ->iMatch, pPk->nKeyCol);
175842176043
sqlite3VdbeSetP4KeyInfo(pParse, pPk);
176044
+ bBloomable = sqlite3IndexBloomable(pPk,pPk->nKeyCol);
176045
+ }
176046
+ if( bBloomable ){
176047
+ pRJ->regBloom = ++pParse->nMem;
176048
+ sqlite3VdbeAddOp2(v, OP_Blob, 65536, pRJ->regBloom);
176049
+ }else{
176050
+ pRJ->regBloom = 0;
175843176051
}
175844176052
pLoop->wsFlags &= ~WHERE_IDX_ONLY;
175845176053
/* The nature of RIGHT JOIN processing is such that it messes up
175846176054
** the output order. So omit any ORDER BY/GROUP BY elimination
175847176055
** optimizations. We need to do an actual sort for RIGHT JOIN. */
@@ -187183,67 +187391,64 @@
187183187391
SQLITE_API char *sqlite3_data_directory = 0;
187184187392
187185187393
/*
187186187394
** Initialize SQLite.
187187187395
**
187188
-** This routine must be called to initialize the memory allocation,
187189
-** VFS, and mutex subsystems prior to doing any serious work with
187190
-** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT
187396
+** The sqlite3_initialize() routine must be called to initialize the
187397
+** memory allocation, VFS, and mutex subsystems prior to doing any
187398
+** serious work. As long as you do not compile with SQLITE_OMIT_AUTOINIT
187191187399
** this routine will be called automatically by key routines such as
187192187400
** sqlite3_open().
187193187401
**
187194187402
** This routine is a no-op except on its very first call for the process,
187195
-** or for the first call after a call to sqlite3_shutdown.
187403
+** or for the first call after a call to sqlite3_shutdown. Most calls
187404
+** to sqlite3_initialize() are, in fact, no-ops. For that reason, the
187405
+** routine is broken into two pieces:
187196187406
**
187197
-** The first thread to call this routine runs the initialization to
187198
-** completion. If subsequent threads call this routine before the first
187407
+** sqlite3Initialize() Does the actual work of initialization
187408
+**
187409
+** sqlite3_initialize() Checks to see if initialization is needed
187410
+** and invokes sqlite3Initialize() if it is.
187411
+**
187412
+** The sqlite3_initialize() interface is called frequently, but
187413
+** sqlite3Initialize() runs rarely. The function is broken up this way
187414
+** to avoid wasting CPU cycles with unnecessary stack setup for local
187415
+** variables in cases where it is not needed.
187416
+**
187417
+** The first thread to call sqlite3_initialize() runs the initialization to
187418
+** completion. If subsequent threads call sqlite3_initialize() before the first
187199187419
** thread has finished the initialization process, then the subsequent
187200187420
** threads must block until the first thread finishes with the initialization.
187201187421
**
187202187422
** The first thread might call this routine recursively. Recursive
187203187423
** calls to this routine should not block, of course. Otherwise the
187204187424
** initialization process would never complete.
187205187425
**
187206
-** Let X be the first thread to enter this routine. Let Y be some other
187207
-** thread. Then while the initial invocation of this routine by X is
187208
-** incomplete, it is required that:
187426
+** Let X be the first thread to enter sqlite3_initialize(). Let Y be some
187427
+** other thread. While the initial invocation of sqlite3_initialize() by X
187428
+** is incomplete, it is required that:
187209187429
**
187210
-** * Calls to this routine from Y must block until the outer-most
187430
+** * Calls to sqlite3_initialize() from Y must block until the outer-most
187211187431
** call by X completes.
187212187432
**
187213
-** * Recursive calls to this routine from thread X return immediately
187214
-** without blocking.
187433
+** * Recursive calls to sqlite3_initialize() from thread X return
187434
+** immediately without blocking.
187215187435
*/
187216
-SQLITE_API int sqlite3_initialize(void){
187217
- MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
187218
- int rc; /* Result code */
187436
+static SQLITE_NOINLINE int sqlite3Initialize(void){
187437
+ MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
187438
+ int rc; /* Result code */
187219187439
#ifdef SQLITE_EXTRA_INIT
187220
- int bRunExtraInit = 0; /* Extra initialization needed */
187221
-#endif
187222
-
187223
-#ifdef SQLITE_OMIT_WSD
187224
- rc = sqlite3_wsd_init(4096, 24);
187225
- if( rc!=SQLITE_OK ){
187226
- return rc;
187227
- }
187440
+ int bRunExtraInit = 0; /* Extra initialization needed */
187228187441
#endif
187229187442
187230187443
/* If the following assert() fails on some obscure processor/compiler
187231
- ** combination, the work-around is to set the correct pointer
187232
- ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
187444
+ ** combination to warn that SQLite has been mis-compiled. If you hit
187445
+ ** this assert(), that means you need to recompile with the
187446
+ ** -DSQLITE_PTRSIZE=n compile-time option to set the correct pointer size.
187447
+ */
187233187448
assert( SQLITE_PTRSIZE==sizeof(char*) );
187234187449
187235
- /* If SQLite is already completely initialized, then this call
187236
- ** to sqlite3_initialize() should be a no-op. But the initialization
187237
- ** must be complete. So isInit must not be set until the very end
187238
- ** of this routine.
187239
- */
187240
- if( sqlite3GlobalConfig.isInit ){
187241
- sqlite3MemoryBarrier();
187242
- return SQLITE_OK;
187243
- }
187244
-
187245187450
/* Make sure the mutex subsystem is initialized. If unable to
187246187451
** initialize the mutex subsystem, return early with the error.
187247187452
** If the system is so sick that we are unable to allocate a mutex,
187248187453
** there is not much SQLite is going to be able to do.
187249187454
**
@@ -187383,10 +187588,30 @@
187383187588
int SQLITE_EXTRA_INIT(const char*);
187384187589
rc = SQLITE_EXTRA_INIT(0);
187385187590
}
187386187591
#endif
187387187592
return rc;
187593
+}
187594
+SQLITE_API int sqlite3_initialize(void){
187595
+ /* If this build does not support writable static data (WSD) natively
187596
+ ** then we have to invoke the (application-supplied) WSD initialization
187597
+ ** routine before doing anything else. */
187598
+#ifdef SQLITE_OMIT_WSD
187599
+ rc = sqlite3_wsd_init(4096, 24);
187600
+ if( rc!=SQLITE_OK ){
187601
+ return rc;
187602
+ }
187603
+#endif
187604
+
187605
+ if( sqlite3GlobalConfig.isInit ){
187606
+ /* SQLite has already been initialized. Fast early-out. */
187607
+ sqlite3MemoryBarrier();
187608
+ return SQLITE_OK;
187609
+ }else{
187610
+ /* Invoke sqlite3Initialize() to do the actual work. */
187611
+ return sqlite3Initialize();
187612
+ }
187388187613
}
187389187614
187390187615
/*
187391187616
** Undo the effects of sqlite3_initialize(). Must not be called while
187392187617
** there are outstanding database connections or memory allocations or
@@ -189999,10 +190224,11 @@
189999190224
SQLITE_MAX_LIKE_PATTERN_LENGTH,
190000190225
SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
190001190226
SQLITE_MAX_TRIGGER_DEPTH,
190002190227
SQLITE_MAX_WORKER_THREADS,
190003190228
SQLITE_MAX_PARSER_DEPTH,
190229
+ SQLITE_MAX_SCHEMA,
190004190230
};
190005190231
190006190232
/*
190007190233
** Make sure the hard limits are set to reasonable values
190008190234
*/
@@ -190081,11 +190307,12 @@
190081190307
assert( aHardLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]==
190082190308
SQLITE_MAX_LIKE_PATTERN_LENGTH );
190083190309
assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
190084190310
assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
190085190311
assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
190086
- assert( SQLITE_LIMIT_PARSER_DEPTH==(SQLITE_N_LIMIT-1) );
190312
+ assert( aHardLimit[SQLITE_LIMIT_SCHEMA]==SQLITE_MAX_SCHEMA );
190313
+ assert( SQLITE_LIMIT_SCHEMA==(SQLITE_N_LIMIT-1) );
190087190314
190088190315
190089190316
if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
190090190317
return -1;
190091190318
}
@@ -213541,11 +213768,11 @@
213541213768
/*
213542213769
** Expand pParse->aBlob so that it holds at least N bytes.
213543213770
**
213544213771
** Return the number of errors.
213545213772
*/
213546
-static int jsonBlobExpand(JsonParse *pParse, u32 N){
213773
+static int jsonBlobExpand(JsonParse *pParse, u64 N){
213547213774
u8 *aNew;
213548213775
u64 t;
213549213776
assert( N>pParse->nBlobAlloc );
213550213777
if( pParse->nBlobAlloc==0 ){
213551213778
t = 100;
@@ -213569,11 +213796,11 @@
213569213796
**
213570213797
** Return true on success. Return false on OOM.
213571213798
*/
213572213799
static int jsonBlobMakeEditable(JsonParse *pParse, u32 nExtra){
213573213800
u8 *aOld;
213574
- u32 nSize;
213801
+ u64 nSize;
213575213802
assert( !pParse->bReadOnly );
213576213803
if( pParse->oom ) return 0;
213577213804
if( pParse->nBlobAlloc>0 ) return 1;
213578213805
aOld = pParse->aBlob;
213579213806
nSize = pParse->nBlob + nExtra;
@@ -213590,11 +213817,11 @@
213590213817
*/
213591213818
static SQLITE_NOINLINE void jsonBlobExpandAndAppendOneByte(
213592213819
JsonParse *pParse,
213593213820
u8 c
213594213821
){
213595
- jsonBlobExpand(pParse, pParse->nBlob+1);
213822
+ jsonBlobExpand(pParse, (u64)pParse->nBlob+1);
213596213823
if( pParse->oom==0 ){
213597213824
assert( pParse->nBlob+1<=pParse->nBlobAlloc );
213598213825
pParse->aBlob[pParse->nBlob++] = c;
213599213826
}
213600213827
}
@@ -213617,11 +213844,11 @@
213617213844
JsonParse *pParse,
213618213845
u8 eType,
213619213846
u64 szPayload,
213620213847
const void *aPayload
213621213848
){
213622
- if( jsonBlobExpand(pParse, pParse->nBlob+szPayload+9) ) return;
213849
+ if( jsonBlobExpand(pParse, (u64)pParse->nBlob+(u64)szPayload+9) ) return;
213623213850
jsonBlobAppendNode(pParse, eType, szPayload, aPayload);
213624213851
}
213625213852
213626213853
213627213854
/* Append a node type byte together with the payload size and
@@ -213707,11 +213934,11 @@
213707213934
}else{
213708213935
nNeeded = 4;
213709213936
}
213710213937
delta = nNeeded - nExtra;
213711213938
if( delta ){
213712
- u32 newSize = pParse->nBlob + delta;
213939
+ u64 newSize = (u64)pParse->nBlob + delta;
213713213940
if( delta>0 ){
213714213941
if( newSize>pParse->nBlobAlloc && jsonBlobExpand(pParse, newSize) ){
213715213942
return 0; /* OOM error. Error state recorded in pParse->oom. */
213716213943
}
213717213944
a = &pParse->aBlob[i];
@@ -215055,11 +215282,11 @@
215055215282
){
215056215283
return;
215057215284
}
215058215285
if( d!=0 ){
215059215286
if( pParse->nBlob + d > pParse->nBlobAlloc ){
215060
- jsonBlobExpand(pParse, pParse->nBlob+d);
215287
+ jsonBlobExpand(pParse, (u64)pParse->nBlob+d);
215061215288
if( pParse->oom ) return;
215062215289
}
215063215290
memmove(&pParse->aBlob[iDel+nIns],
215064215291
&pParse->aBlob[iDel+nDel],
215065215292
pParse->nBlob - (iDel+nDel));
@@ -251402,10 +251629,11 @@
251402251629
i64 szData = (sizeof(Fts5Data) + 7) & ~7;
251403251630
i64 nAlloc = szData + nByte + FTS5_DATA_PADDING;
251404251631
pRet = (Fts5Data*)sqlite3_malloc64(nAlloc);
251405251632
if( pRet ){
251406251633
pRet->nn = nByte;
251634
+ pRet->szLeaf = 0;
251407251635
aOut = pRet->p = (u8*)pRet + szData;
251408251636
}else{
251409251637
rc = SQLITE_NOMEM;
251410251638
}
251411251639
@@ -251414,14 +251642,12 @@
251414251642
}
251415251643
if( rc!=SQLITE_OK ){
251416251644
sqlite3_free(pRet);
251417251645
pRet = 0;
251418251646
}else{
251419
- /* TODO1: Fix this */
251420251647
pRet->p[nByte] = 0x00;
251421251648
pRet->p[nByte+1] = 0x00;
251422
- pRet->szLeaf = fts5GetU16(&pRet->p[2]);
251423251649
}
251424251650
}
251425251651
p->rc = rc;
251426251652
p->nRead++;
251427251653
}
@@ -251438,13 +251664,21 @@
251438251664
*/
251439251665
static void fts5DataRelease(Fts5Data *pData){
251440251666
sqlite3_free(pData);
251441251667
}
251442251668
251669
+/*
251670
+** Read a leaf-page record. This is similar to fts5DataRead(), except that
251671
+** it fills in the Fts5Data.szLeaf value before returning.
251672
+*/
251443251673
static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
251444251674
Fts5Data *pRet = fts5DataRead(p, iRowid);
251445251675
if( pRet ){
251676
+ assert( pRet->szLeaf==0 );
251677
+ if( pRet->nn>=4 ){
251678
+ pRet->szLeaf = fts5GetU16(&pRet->p[2]);
251679
+ }
251446251680
if( pRet->szLeaf<4 || pRet->szLeaf>pRet->nn ){
251447251681
FTS5_CORRUPT_ROWID(p, iRowid);
251448251682
fts5DataRelease(pRet);
251449251683
pRet = 0;
251450251684
}
@@ -255681,11 +255915,11 @@
255681255915
for(pgno=iPgno; p->rc==SQLITE_OK && pgno<=pSeg->pgnoLast; pgno++){
255682255916
i64 iRowid = FTS5_SEGMENT_ROWID(pSeg->iSegid, pgno);
255683255917
int iNext = 0;
255684255918
u8 *aPg = 0;
255685255919
255686
- pLeaf = fts5DataRead(p, iRowid);
255920
+ pLeaf = fts5LeafRead(p, iRowid);
255687255921
if( pLeaf==0 ) break;
255688255922
aPg = pLeaf->p;
255689255923
255690255924
iNext = fts5GetU16(&aPg[0]);
255691255925
if( iNext!=0 ){
@@ -255976,19 +256210,19 @@
255976256210
255977256211
assert_nc( pSeg->iLeafPgno>pSeg->iTermLeafPgno );
255978256212
/* The entry being removed may be the only position list in
255979256213
** its doclist. */
255980256214
for(iPgno=pSeg->iLeafPgno-1; iPgno>pSeg->iTermLeafPgno; iPgno-- ){
255981
- Fts5Data *pPg = fts5DataRead(p, FTS5_SEGMENT_ROWID(iSegid, iPgno));
256215
+ Fts5Data *pPg = fts5LeafRead(p, FTS5_SEGMENT_ROWID(iSegid, iPgno));
255982256216
int bEmpty = (pPg && pPg->nn==4);
255983256217
fts5DataRelease(pPg);
255984256218
if( bEmpty==0 ) break;
255985256219
}
255986256220
255987256221
if( iPgno==pSeg->iTermLeafPgno ){
255988256222
i64 iId = FTS5_SEGMENT_ROWID(iSegid, pSeg->iTermLeafPgno);
255989
- Fts5Data *pTerm = fts5DataRead(p, iId);
256223
+ Fts5Data *pTerm = fts5LeafRead(p, iId);
255990256224
if( pTerm && pTerm->szLeaf==pSeg->iTermLeafOffset ){
255991256225
u8 *aTermIdx = &pTerm->p[pTerm->szLeaf];
255992256226
int nTermIdx = pTerm->nn - pTerm->szLeaf;
255993256227
int iTermIdx = 0;
255994256228
i64 iTermOff = 0;
@@ -258936,11 +259170,11 @@
258936259170
int i;
258937259171
258938259172
/* Now check that the iter.nEmpty leaves following the current leaf
258939259173
** (a) exist and (b) contain no terms. */
258940259174
for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
258941
- Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
259175
+ Fts5Data *pLeaf = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
258942259176
if( pLeaf ){
258943259177
if( !fts5LeafIsTermless(pLeaf)
258944259178
|| (i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf))
258945259179
){
258946259180
FTS5_CORRUPT_ROWID(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
@@ -263716,11 +263950,11 @@
263716263950
int nArg, /* Number of args */
263717263951
sqlite3_value **apUnused /* Function arguments */
263718263952
){
263719263953
assert( nArg==0 );
263720263954
UNUSED_PARAM2(nArg, apUnused);
263721
- sqlite3_result_text(pCtx, "fts5: 2026-07-07 14:53:53 c3b0fff1b76b8c354b34fef17ff639968698e97234d6ab7af15e0e1a835486e9", -1, SQLITE_TRANSIENT);
263955
+ sqlite3_result_text(pCtx, "fts5: 2026-07-24 16:28:47 2f1f4f73535386549c12694dc57cfe555eec689ae6824c6241aaf8d5befcd74d", -1, SQLITE_TRANSIENT);
263722263956
}
263723263957
263724263958
/*
263725263959
** Implementation of fts5_locale(LOCALE, TEXT) function.
263726263960
**
263727263961
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** c8aa208bf5b00f3ab93c5edd510dfd0d7edd with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-07-08 15:43:42 c8aa208bf5b00f3ab93c5edd510dfd0d7edd271c064f159616ee409b308f7eb9"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-07-08T15:43:42.959Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4751,10 +4751,14 @@
4751 ** nesting depth for separate triggers.</dd>)^
4752 **
4753 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4754 ** <dd>The maximum number of auxiliary worker threads that a single
4755 ** [prepared statement] may start.</dd>)^
 
 
 
 
4756 ** </dl>
4757 */
4758 #define SQLITE_LIMIT_LENGTH 0
4759 #define SQLITE_LIMIT_SQL_LENGTH 1
4760 #define SQLITE_LIMIT_COLUMN 2
@@ -4766,10 +4770,11 @@
4766 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
4767 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
4768 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
4769 #define SQLITE_LIMIT_WORKER_THREADS 11
4770 #define SQLITE_LIMIT_PARSER_DEPTH 12
 
4771
4772 /*
4773 ** CAPI3REF: Prepare Flags
4774 **
4775 ** These constants define various flags that can be passed into the
@@ -6798,11 +6803,15 @@
6798 ** to by the second parameter and which is N bytes long where N is the
6799 ** third parameter.
6800 **
6801 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
6802 ** interfaces set the result of the application-defined function to be
6803 ** a BLOB containing all zero bytes and N bytes in size.
 
 
 
 
6804 **
6805 ** ^The sqlite3_result_double() interface sets the result from
6806 ** an application-defined function to be a floating point value specified
6807 ** by its 2nd argument.
6808 **
@@ -15031,10 +15040,37 @@
15031 */
15032 #ifndef SQLITE_MAX_TRIGGER_DEPTH
15033 # define SQLITE_MAX_TRIGGER_DEPTH 1000
15034 #endif
15035
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15036 /************** End of sqliteLimit.h *****************************************/
15037 /************** Continuing where we left off in sqliteInt.h ******************/
15038
15039 /* Disable nuisance warnings on Borland compilers */
15040 #if defined(__BORLANDC__)
@@ -15289,11 +15325,13 @@
15289 ** bitmask tests, testcase() can be used to make sure each bit
15290 ** is significant and used at least once. On switch statements
15291 ** where multiple cases go to the same block of code, testcase()
15292 ** can insure that all cases are evaluated.
15293 */
15294 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
 
 
15295 # ifndef SQLITE_AMALGAMATION
15296 extern unsigned int sqlite3CoverageCounter;
15297 # endif
15298 # define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; }
15299 #else
@@ -18636,11 +18674,11 @@
18636
18637 /*
18638 ** The number of different kinds of things that can be limited
18639 ** using the sqlite3_limit() interface.
18640 */
18641 #define SQLITE_N_LIMIT (SQLITE_LIMIT_PARSER_DEPTH+1)
18642
18643 /*
18644 ** Lookaside malloc is a set of fixed-size buffers that can be used
18645 ** to satisfy small transient memory allocation requests for objects
18646 ** associated with a particular database connection. The use of
@@ -22010,10 +22048,11 @@
22010 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
22011 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
22012 #endif
22013 #if defined(SQLITE_TEST)
22014 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
 
22015 #endif
22016
22017 #if defined(SQLITE_DEBUG)
22018 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView*, const char *zFormat, ...);
22019 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
@@ -22234,10 +22273,11 @@
22234 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
22235 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
22236 SQLITE_PRIVATE void sqlite3ClearOnOrUsing(sqlite3*, OnOrUsing*);
22237 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
22238 SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,int,int,char**);
 
22239 SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
22240 Expr*, int, int, u8);
22241 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
22242 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
22243 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
@@ -23646,10 +23686,13 @@
23646 "MAX_PAGE_COUNT=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_COUNT),
23647 #endif
23648 #ifdef SQLITE_MAX_PAGE_SIZE
23649 "MAX_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_SIZE),
23650 #endif
 
 
 
23651 #ifdef SQLITE_MAX_SCHEMA_RETRY
23652 "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
23653 #endif
23654 #ifdef SQLITE_MAX_SQL_LENGTH
23655 "MAX_SQL_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_SQL_LENGTH),
@@ -26531,11 +26574,11 @@
26531 ** on the appropriate weekday, this is a no-op.
26532 */
26533 if( sqlite3_strnicmp(z, "weekday ", 8)==0
26534 && sqlite3AtoF(&z[8], &r)>0
26535 && r>=-6.0 && r<=6.0
26536 && (n=(int)r)==r
26537 ){
26538 sqlite3_int64 Z;
26539 computeYMD_HMS(p);
26540 p->tz = 0;
26541 p->validJD = 0;
@@ -46092,11 +46135,10 @@
46092 i64 nNew /* Required mapping size */
46093 ){
46094 const char *zErr = "mmap";
46095 int h = pFd->h; /* File descriptor open on db file */
46096 u8 *pOrig = (u8 *)pFd->pMapRegion; /* Pointer to current file mapping */
46097 i64 nOrig = pFd->mmapSizeActual; /* Size of pOrig region in bytes */
46098 u8 *pNew = 0; /* Location of new mapping */
46099 int flags = PROT_READ; /* Flags to pass to mmap() */
46100
46101 assert( pFd->nFetchOut==0 );
46102 assert( nNew>pFd->mmapSize );
@@ -46110,25 +46152,16 @@
46110 #endif
46111
46112 if( pOrig ){
46113 #if HAVE_MREMAP
46114 i64 nReuse = pFd->mmapSize;
 
 
46115 #else
46116 const int szSyspage = osGetpagesize();
46117 i64 nReuse = (pFd->mmapSize & ~(szSyspage-1));
46118 #endif
46119 u8 *pReq = &pOrig[nReuse];
46120
46121 /* Unmap any pages of the existing mapping that cannot be reused. */
46122 if( nReuse!=nOrig ){
46123 osMunmap(pReq, nOrig-nReuse);
46124 }
46125
46126 #if HAVE_MREMAP
46127 pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
46128 zErr = "mremap";
46129 #else
46130 pNew = osMmap(pReq, nNew-nReuse, flags, MAP_SHARED, h, nReuse);
46131 if( pNew!=MAP_FAILED ){
46132 if( pNew!=pReq ){
46133 osMunmap(pNew, nNew - nReuse);
46134 pNew = 0;
@@ -46759,40 +46792,33 @@
46759 verifyDbFile(pNew);
46760 }
46761 return rc;
46762 }
46763
46764 /*
46765 ** Directories to consider for temp files.
46766 */
46767 static const char *azTempDirs[] = {
46768 0,
46769 0,
46770 "/var/tmp",
46771 "/usr/tmp",
46772 "/tmp",
46773 "."
46774 };
46775
46776 /*
46777 ** Initialize first two members of azTempDirs[] array.
46778 */
46779 static void unixTempFileInit(void){
46780 azTempDirs[0] = getenv("SQLITE_TMPDIR");
46781 azTempDirs[1] = getenv("TMPDIR");
46782 }
46783
46784 /*
46785 ** Return the name of a directory in which to put temporary files.
46786 ** If no suitable temporary file directory can be found, return NULL.
 
 
 
 
46787 */
46788 static const char *unixTempFileDir(void){
46789 unsigned int i = 0;
46790 struct stat buf;
46791 const char *zDir = sqlite3_temp_directory;
46792
46793 while(1){
 
 
 
 
 
 
 
 
 
46794 if( zDir!=0
46795 #if OS_VXWORKS
46796 && zDir[0]=='/'
46797 #endif
46798 && osStat(zDir, &buf)==0
@@ -46799,12 +46825,10 @@
46799 && S_ISDIR(buf.st_mode)
46800 && osAccess(zDir, 03)==0
46801 ){
46802 return zDir;
46803 }
46804 if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break;
46805 zDir = azTempDirs[i++];
46806 }
46807 return 0;
46808 }
46809
46810 /*
@@ -49083,13 +49107,10 @@
49083 ** DMS UNIX_SHM_BASE+8 128
49084 */
49085 assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */
49086 #endif
49087
49088 /* Initialize temp file dir array. */
49089 unixTempFileInit();
49090
49091 return SQLITE_OK;
49092 }
49093
49094 /*
49095 ** Shutdown the operating system interface.
@@ -93648,14 +93669,15 @@
93648 SQLITE_API void sqlite3_result_str(sqlite3_context *pCtx, sqlite3_str *pStr, int eOwn){
93649 #ifdef SQLITE_ENABLE_API_ARMOR
93650 if( pCtx==0 ) return;
93651 if( pStr==0 ) return;
93652 #endif
 
93653 if( pStr->accError==0 ){
93654 if( pStr->nChar==0 ){
93655 setResultStrOrError(pCtx, "", 0, SQLITE_UTF8_ZT, SQLITE_STATIC);
93656 if( eOwn ) sqlite3_str_reset(pStr);
93657 }else{
93658 const char *zText = sqlite3_str_value(pStr);
93659 /* Only internal code has the ability to capture a pointer to
93660 ** an sqlite3_str object that uses static buffer. And none of
93661 ** those internal use cases every invoke the sqlite3_result_str()
@@ -93666,26 +93688,21 @@
93666 setResultStrOrError(pCtx, zText, pStr->nChar,
93667 SQLITE_UTF8, SQLITE_TRANSIENT);
93668 }else{
93669 setResultStrOrError(pCtx, zText, pStr->nChar,
93670 SQLITE_UTF8_ZT, SQLITE_DYNAMIC);
 
93671 }
93672 }
93673 }else if( pStr->accError==SQLITE_NOMEM ){
93674 sqlite3_result_error_nomem(pCtx);
93675 }else{
93676 assert( pStr->accError==SQLITE_TOOBIG );
93677 sqlite3_result_error_toobig(pCtx);
93678 }
93679 if( eOwn ){
93680 testcase( pStr==(sqlite3_str*)&sqlite3OomStr );
93681 if( pStr->accError==0 ){
93682 sqlite3StrAccumInit(pStr, pStr->db, 0, 0, pStr->mxAlloc);
93683 }
93684 if( eOwn==SQLITE_FINISH ){
93685 sqlite3_str_free(pStr);
93686 }
93687 }
93688 }
93689
93690 #ifndef SQLITE_UNTESTABLE
93691 /* Force the INT64 value currently stored as the result to be
@@ -96574,10 +96591,14 @@
96574 }
96575
96576 /*
96577 ** Compute a bloom filter hash using pOp->p4.i registers from aMem[] beginning
96578 ** with pOp->p3. Return the hash.
 
 
 
 
96579 */
96580 static u64 filterHash(const Mem *aMem, const Op *pOp){
96581 int i, mx;
96582 u64 h = 0;
96583
@@ -96586,15 +96607,32 @@
96586 const Mem *p = &aMem[i];
96587 if( p->flags & (MEM_Int|MEM_IntReal) ){
96588 h += p->u.i;
96589 }else if( p->flags & MEM_Real ){
96590 h += sqlite3VdbeIntValue(p);
96591 }else if( p->flags & (MEM_Str|MEM_Blob) ){
96592 /* All strings have the same hash and all blobs have the same hash,
96593 ** though, at least, those hashes are different from each other and
96594 ** from NULL. */
96595 h += 4093 + (p->flags & (MEM_Str|MEM_Blob));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96596 }
96597 }
96598 return h;
96599 }
96600
@@ -101417,11 +101455,11 @@
101417 */
101418 case OP_SeekRowid: { /* jump0, in3, ncycle */
101419 VdbeCursor *pC;
101420 BtCursor *pCrsr;
101421 int res;
101422 u64 iKey;
101423
101424 pIn3 = &aMem[pOp->p3];
101425 testcase( pIn3->flags & MEM_Int );
101426 testcase( pIn3->flags & MEM_IntReal );
101427 testcase( pIn3->flags & MEM_Real );
@@ -101431,13 +101469,23 @@
101431 ** integer value of pIn3. Jump to P2 if pIn3 cannot be converted
101432 ** into an integer without loss of information. Take care to avoid
101433 ** changing the datatype of pIn3, however, as it is used by other
101434 ** parts of the prepared statement. */
101435 Mem x = pIn3[0];
101436 applyAffinity(&x, SQLITE_AFF_NUMERIC, encoding);
101437 if( (x.flags & MEM_Int)==0 ) goto jump_to_p2;
101438 iKey = x.u.i;
 
 
 
 
 
 
 
 
 
 
101439 goto notExistsWithKey;
101440 }
101441 /* Fall through into OP_NotExists */
101442 /* no break */ deliberate_fall_through
101443 case OP_NotExists: /* jump, in3, ncycle */
@@ -110677,18 +110725,17 @@
110677 if( cnt==1 ){
110678 assert( pNC!=0 );
110679 #ifndef SQLITE_OMIT_AUTHORIZATION
110680 if( db->xAuth ){
110681 if( pFJMatch ){
110682 int ii;
110683 assert( pExpr->op==TK_FUNCTION );
110684 assert( sqlite3_stricmp(pExpr->u.zToken,"coalesce")==0 );
110685 assert( pExpr->x.pList==pFJMatch );
110686 assert( pFJMatch->nExpr>0 );
110687 for(ii=0; ii<pFJMatch->nExpr; ii++){
110688 assert( pFJMatch->a[0].pExpr->op==TK_COLUMN );
110689 sqlite3AuthRead(pParse, pFJMatch->a[0].pExpr, pSchema, pNC->pSrcList);
110690 }
110691 }else if( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ){
110692 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
110693 }
110694 }
@@ -110802,15 +110849,24 @@
110802 static SQLITE_NOINLINE void resolveSetExprSubtypeArg(ExprList *pList){
110803 int nn, ii;
110804 nn = pList ? pList->nExpr : 0;
110805 for(ii=0; ii<nn; ii++){
110806 Expr *pExpr = pList->a[ii].pExpr;
110807 ExprSetProperty(pExpr, EP_SubtArg);
110808 if( pExpr->op==TK_SELECT ){
110809 assert( ExprUseXSelect(pExpr) );
110810 assert( pExpr->x.pSelect!=0 );
110811 resolveSetExprSubtypeArg(pExpr->x.pSelect->pEList);
 
 
 
 
 
 
 
 
 
110812 }
110813 }
110814 }
110815
110816 /*
@@ -115893,10 +115949,12 @@
115893 }else{
115894 VdbeComment((v, "RHS of IN operator"));
115895 }
115896 #endif
115897 pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
 
 
115898
115899 if( ExprUseXSelect(pExpr) ){
115900 /* Case 1: expr IN (SELECT ...)
115901 **
115902 ** Generate code to write the results of the select into the temporary
@@ -115917,21 +115975,35 @@
115917 int rc;
115918 int addrBloom = 0;
115919 sqlite3SelectDestInit(&dest, SRT_Set, iTab);
115920 dest.zAffSdst = exprINAffinity(pParse, pExpr);
115921 pSelect->iLimit = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
115922 if( addrOnce
115923 && allowBloom
115924 && OptimizationEnabled(pParse->db, SQLITE_BloomFilter)
115925 ){
115926 int regBloom = ++pParse->nMem;
115927 addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
115928 VdbeComment((v, "Bloom filter"));
115929 dest.iSDParm2 = regBloom;
 
 
115930 }
115931 testcase( pSelect->selFlags & SF_Distinct );
115932 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
115933 pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
115934 rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
115935 sqlite3SelectDelete(pParse->db, pCopy);
115936 sqlite3DbFree(pParse->db, dest.zAffSdst);
115937 if( addrBloom ){
@@ -115945,20 +116017,10 @@
115945 }
115946 if( rc ){
115947 sqlite3KeyInfoUnref(pKeyInfo);
115948 return;
115949 }
115950 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
115951 assert( pEList!=0 );
115952 assert( pEList->nExpr>0 );
115953 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
115954 for(i=0; i<nVal; i++){
115955 Expr *p = sqlite3VectorFieldSubexpr(pLeft, i);
115956 pKeyInfo->aColl[i] = sqlite3BinaryCompareCollSeq(
115957 pParse, p, pEList->a[i].pExpr
115958 );
115959 }
115960 }
115961 }else if( ALWAYS(pExpr->x.pList!=0) ){
115962 /* Case 2: expr IN (exprlist)
115963 **
115964 ** For each expression, build an index key from the evaluation and
@@ -115975,14 +116037,13 @@
115975 if( affinity<=SQLITE_AFF_NONE ){
115976 affinity = SQLITE_AFF_BLOB;
115977 }else if( affinity==SQLITE_AFF_REAL ){
115978 affinity = SQLITE_AFF_NUMERIC;
115979 }
115980 if( pKeyInfo ){
115981 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
115982 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
115983 }
115984
115985 /* Loop through each expression in <exprlist>. */
115986 r1 = sqlite3GetTempReg(pParse);
115987 r2 = sqlite3GetTempReg(pParse);
115988 for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
@@ -116935,11 +116996,11 @@
116935 if( pExpr->op!=TK_FUNCTION ){
116936 return WRC_Prune;
116937 }
116938 assert( ExprUseXList(pExpr) );
116939 db = pWalker->pParse->db;
116940 n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
116941 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
116942 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
116943 pWalker->eCode = 1;
116944 return WRC_Abort;
116945 }
@@ -122344,19 +122405,41 @@
122344
122345
122346 /*
122347 ** Argument z points into the body of a constraint - specifically the
122348 ** second token of the constraint definition. For a named constraint,
122349 ** z points to the first token past the CONSTRAINT keyword. For an
122350 ** unnamed NOT NULL constraint, z points to the first byte past the NOT
122351 ** keyword.
 
 
 
 
 
122352 **
122353 ** Return the number of bytes until the end of the constraint.
122354 */
122355 static int getConstraint(const u8 *z){
122356 int iOff = 0;
122357 int t = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122358
122359 /* Now, the current constraint proceeds until the next occurence of one
122360 ** of the following tokens:
122361 **
122362 ** CONSTRAINT, PRIMARY, NOT, UNIQUE, CHECK, DEFAULT,
@@ -122525,24 +122608,24 @@
122525 || t==TK_COMMA || t==TK_RP || t==TK_GENERATED || t==TK_AS
122526 ){
122527 t = TK_CHECK;
122528 }else{
122529 iOff += nTok;
122530 iOff += getConstraint(&zSql[iOff]);
122531 }
122532
122533 if( cmp==0 || (iNotNull>=0 && t==TK_NOT) ){
122534 if( t!=TK_NOT && t!=TK_CHECK ){
122535 errorMPrintf(ctx, "constraint may not be dropped: %s", zCons);
122536 return;
122537 }
122538 iEnd = iOff;
122539 break;
122540 }
122541
122542 }else if( t==TK_NOT && iNotNull==ii ){
122543 iEnd = iOff + getConstraint(&zSql[iOff]);
122544 break;
122545 }else if( t==TK_RP || t==TK_ILLEGAL ){
122546 iEnd = -1;
122547 break;
122548 }else if( t==TK_COMMA ){
@@ -128170,10 +128253,27 @@
128170 pIdx->aSortOrder = (u8*)zExtra;
128171 pIdx->nColumn = (u16)N; /* See tag-20250221-1 above for proof of safety */
128172 pIdx->isResized = 1;
128173 return SQLITE_OK;
128174 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128175
128176 /*
128177 ** Estimate the total row width for a table.
128178 */
128179 static void estimateTableWidth(Table *pTab){
@@ -130038,12 +130138,13 @@
130038 }
130039 }
130040 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
130041 if( !ifNotExist ){
130042 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
 
 
130043 }else{
130044 assert( !db->init.busy );
130045 sqlite3CodeVerifySchema(pParse, iDb);
130046 sqlite3ForceNotReadOnly(pParse);
130047 }
130048 goto exit_create_index;
130049 }
@@ -136304,17 +136405,21 @@
136304 static void percentSort(
136305 double *a, /* Array to sort */
136306 unsigned int n, /* Number of elements in array a[] */
136307 int iReq /* Element caller cares about (or -ve) */
136308 ){
136309 int iLt; /* Entries before a[iLt] are less than rPivot */
136310 int iGt; /* Entries at or after a[iGt] are greater than rPivot */
136311 int i; /* Loop counter */
136312 double rPivot; /* The pivot value */
136313
136314 assert( n>=2 );
136315 do{
 
 
 
 
136316 if( a[0]>a[n-1] ){
136317 SWAP_DOUBLE(a[0],a[n-1])
136318 }
136319 if( n==2 ) return;
136320 iGt = n-1;
@@ -136323,10 +136428,15 @@
136323 SWAP_DOUBLE(a[0],a[i])
136324 }else if( a[i]>a[iGt] ){
136325 SWAP_DOUBLE(a[i],a[iGt])
136326 }
136327 if( n==3 ) return;
 
 
 
 
 
136328 rPivot = a[i];
136329 iLt = i = 1;
136330 do{
136331 if( a[i]<rPivot ){
136332 if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt])
@@ -136340,12 +136450,16 @@
136340 }else{
136341 i++;
136342 }
136343 }while( i<iGt );
136344
 
 
136345 assert( a[iLt]==rPivot );
136346 assert( iGt>iLt );
 
 
136347
136348 if( iReq>=0 ){
136349 /* In this case, the only elements that the caller requires sorted into
136350 ** the correct positions are elements a[iReq] and a[iReq+1]. At this
136351 ** point we know that element a[iLt] is in the correct position and
@@ -140577,10 +140691,26 @@
140577 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
140578 regTrigCnt = pTrigger!=0 || sqlite3FkRequired(pParse, pTab, 0, 0);
140579 }else{
140580 pTrigger = 0;
140581 regTrigCnt = sqlite3FkRequired(pParse, pTab, 0, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140582 }
140583 if( regTrigCnt ){
140584 /* Replace triggers might exist. Allocate the counter and
140585 ** initialize it to zero. */
140586 regTrigCnt = ++pParse->nMem;
@@ -140629,13 +140759,17 @@
140629 ** the UNIQUE constraints have run.
140630 */
140631 if( onError==OE_Replace /* IPK rule is REPLACE */
140632 && onError!=overrideError /* Rules for other constraints are different */
140633 && pTab->pIndex /* There exist other constraints */
140634 && !upsertIpkDelay /* IPK check already deferred by UPSERT */
140635 ){
140636 ipkTop = sqlite3VdbeAddOp0(v, OP_Goto)+1;
 
 
 
 
 
140637 VdbeComment((v, "defer IPK REPLACE until last"));
140638 }
140639
140640 if( isUpdate ){
140641 /* pkChng!=0 does not mean that the rowid has changed, only that
@@ -140725,15 +140859,15 @@
140725 sqlite3VdbeGoto(v, ignoreDest);
140726 break;
140727 }
140728 }
140729 sqlite3VdbeResolveLabel(v, addrRowidOk);
140730 if( pUpsert && pUpsertClause!=pUpsert ){
140731 upsertIpkReturn = sqlite3VdbeAddOp0(v, OP_Goto);
140732 }else if( ipkTop ){
140733 ipkBottom = sqlite3VdbeAddOp0(v, OP_Goto);
140734 sqlite3VdbeJumpHere(v, ipkTop-1);
 
 
140735 }
140736 }
140737
140738 /* Test all UNIQUE constraints by creating entries for each UNIQUE
140739 ** index and making sure that duplicate entries do not already exist.
@@ -140749,10 +140883,11 @@
140749 int regIdx; /* Range of registers holding content for pIdx */
140750 int regR; /* Range of registers holding conflicting PK */
140751 int iThisCur; /* Cursor for this UNIQUE index */
140752 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
140753 int addrConflictCk; /* First opcode in the conflict check logic */
 
140754
140755 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
140756 if( pUpsert ){
140757 pUpsertClause = sqlite3UpsertOfIndex(pUpsert, pIdx);
140758 if( upsertIpkDelay && pUpsertClause==pUpsert ){
@@ -140924,10 +141059,15 @@
140924 VdbeCoverageIf(v, op==OP_Ne);
140925 }
140926 }
140927 }
140928 }
 
 
 
 
 
140929
140930 /* Generate code that executes if the new index entry is not unique */
140931 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
140932 || onError==OE_Ignore || onError==OE_Replace || onError==OE_Update );
140933 switch( onError ){
@@ -140950,17 +141090,11 @@
140950 testcase( onError==OE_Ignore );
140951 sqlite3VdbeGoto(v, ignoreDest);
140952 break;
140953 }
140954 default: {
140955 int nConflictCk; /* Number of opcodes in conflict check logic */
140956
140957 assert( onError==OE_Replace );
140958 nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
140959 assert( nConflictCk>0 || db->mallocFailed );
140960 testcase( nConflictCk<=0 );
140961 testcase( nConflictCk>1 );
140962 if( regTrigCnt ){
140963 sqlite3MultiWrite(pParse);
140964 nReplaceTrig++;
140965 }
140966 if( pTrigger && isUpdate ){
@@ -140970,62 +141104,62 @@
140970 regR, nPkField, 0, OE_Replace,
140971 (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
140972 if( pTrigger && isUpdate ){
140973 sqlite3VdbeAddOp1(v, OP_CursorUnlock, iDataCur);
140974 }
140975 if( regTrigCnt ){
140976 int addrBypass; /* Jump destination to bypass recheck logic */
140977
140978 sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
140979 addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */
140980 VdbeComment((v, "bypass recheck"));
140981
140982 /* Here we insert code that will be invoked after all constraint
140983 ** checks have run, if and only if one or more replace triggers
140984 ** fired. */
140985 sqlite3VdbeResolveLabel(v, lblRecheckOk);
140986 lblRecheckOk = sqlite3VdbeMakeLabel(pParse);
140987 if( pIdx->pPartIdxWhere ){
140988 /* Bypass the recheck if this partial index is not defined
140989 ** for the current row */
140990 sqlite3VdbeAddOp2(v, OP_IsNull, regIdx-1, lblRecheckOk);
140991 VdbeCoverage(v);
140992 }
140993 /* Copy the constraint check code from above, except change
140994 ** the constraint-ok jump destination to be the address of
140995 ** the next retest block */
140996 while( nConflictCk>0 ){
140997 VdbeOp x; /* Conflict check opcode to copy */
140998 /* The sqlite3VdbeAddOp4() call might reallocate the opcode array.
140999 ** Hence, make a complete copy of the opcode, rather than using
141000 ** a pointer to the opcode. */
141001 x = *sqlite3VdbeGetOp(v, addrConflictCk);
141002 if( x.opcode!=OP_IdxRowid ){
141003 int p2; /* New P2 value for copied conflict check opcode */
141004 const char *zP4;
141005 if( sqlite3OpcodeProperty[x.opcode]&OPFLG_JUMP ){
141006 p2 = lblRecheckOk;
141007 }else{
141008 p2 = x.p2;
141009 }
141010 zP4 = x.p4type==P4_INT32 ? SQLITE_INT_TO_PTR(x.p4.i) : x.p4.z;
141011 sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, zP4, x.p4type);
141012 sqlite3VdbeChangeP5(v, x.p5);
141013 VdbeCoverageIf(v, p2!=x.p2);
141014 }
141015 nConflictCk--;
141016 addrConflictCk++;
141017 }
141018 /* If the retest fails, issue an abort */
141019 sqlite3UniqueConstraint(pParse, OE_Abort, pIdx);
141020
141021 sqlite3VdbeJumpHere(v, addrBypass); /* Terminate the recheck bypass */
141022 }
141023 seenReplace = 1;
141024 break;
141025 }
141026 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141027 sqlite3VdbeResolveLabel(v, addrUniqueOk);
141028 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
141029 if( pUpsertClause
141030 && upsertIpkReturn
141031 && sqlite3UpsertNextIsIPK(pUpsertClause)
@@ -141059,12 +141193,12 @@
141059 VdbeCoverage(v);
141060 sqlite3RowidConstraint(pParse, OE_Abort, pTab);
141061 }else{
141062 sqlite3VdbeGoto(v, addrRecheck);
141063 }
141064 sqlite3VdbeResolveLabel(v, lblRecheckOk);
141065 }
 
141066
141067 /* Generate the table record */
141068 if( HasRowid(pTab) ){
141069 int regRec = aRegIdx[ix];
141070 sqlite3VdbeAddOp3(v, OP_MakeRecord, regNewData+1, pTab->nNVCol, regRec);
@@ -147540,10 +147674,11 @@
147540 corruptSchema(pData, argv, 0);
147541 return 1;
147542 }
147543
147544 assert( iDb>=0 && iDb<db->nDb );
 
147545 if( argv[3]==0 ){
147546 corruptSchema(pData, argv, 0);
147547 }else if( argv[4]
147548 && 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
147549 && 'r'==sqlite3UpperToLower[(unsigned char)argv[4][1]] ){
@@ -147614,10 +147749,20 @@
147614 ){
147615 if( sqlite3Config.bExtraSchemaChecks ){
147616 corruptSchema(pData, argv, "invalid rootpage");
147617 }
147618 }
 
 
 
 
 
 
 
 
 
 
147619 }
147620 return 0;
147621 }
147622
147623 /*
@@ -149659,10 +149804,52 @@
149659 }
149660 pSort->nDefer = (u8)nDefer;
149661 *ppExtra = pExtra;
149662 }
149663 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149664
149665 /*
149666 ** This routine generates the code for the inside of the inner loop
149667 ** of a SELECT.
149668 **
@@ -149930,10 +150117,11 @@
149930 assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
149931 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
149932 r1, pDest->zAffSdst, nResultCol);
149933 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
149934 if( pDest->iSDParm2 ){
 
149935 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
149936 regResult, nResultCol);
149937 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
149938 }
149939 sqlite3ReleaseTempReg(pParse, r1);
@@ -151739,10 +151927,11 @@
151739 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
151740 r1, pDest->zAffSdst, pIn->nSdst);
151741 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
151742 pIn->iSdst, pIn->nSdst);
151743 if( pDest->iSDParm2>0 ){
 
151744 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
151745 pIn->iSdst, pIn->nSdst);
151746 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
151747 }
151748 sqlite3ReleaseTempReg(pParse, r1);
@@ -155688,11 +155877,12 @@
155688 assert( ExprUseXList(pExpr) );
155689 if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
155690 if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
155691 if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
155692 pFrom = p->pSrc->a;
155693 if( pFrom->fg.isSubquery==0 ) return 0; /* FROM is a subquery */
 
155694 pSub = pFrom->u4.pSubq->pSelect;
155695 if( pSub->pPrior==0 ) return 0; /* Must be a compound */
155696 if( pSub->selFlags & SF_CopyCte ) return 0; /* Not a CTE */
155697 do{
155698 if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */
@@ -157919,12 +158109,13 @@
157919 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
157920 if( !IN_RENAME_OBJECT ){
157921 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),zName) ){
157922 if( !noErr ){
157923 sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
 
 
157924 }else{
157925 assert( !db->init.busy );
157926 sqlite3CodeVerifySchema(pParse, iDb);
157927 VVA_ONLY( pParse->ifNotExists = 1; )
157928 }
157929 goto trigger_cleanup;
157930 }
@@ -163424,14 +163615,11 @@
163424 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
163425 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*);
163426 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
163427 SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
163428 SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*);
163429
163430
163431
163432
163433
163434 /*
163435 ** Bitmasks for the operators on WhereTerm objects. These are all
163436 ** operators that are of interest to the query planner. An
163437 ** OR-ed combination of these values can be used when searching for
@@ -164896,10 +165084,11 @@
164896 testcase( pTerm->wtFlags & TERM_VIRTUAL );
164897 regRowid = sqlite3GetTempReg(pParse);
164898 regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid);
164899 sqlite3VdbeAddOp2(pParse->pVdbe, OP_MustBeInt, regRowid, addrNxt);
164900 VdbeCoverage(pParse->pVdbe);
 
164901 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
164902 addrNxt, regRowid, 1);
164903 VdbeCoverage(pParse->pVdbe);
164904 }else{
164905 u16 nEq = pLoop->u.btree.nEq;
@@ -164909,10 +165098,11 @@
164909 assert( pLoop->wsFlags & WHERE_INDEXED );
164910 assert( (pLoop->wsFlags & WHERE_COLUMN_IN)==0 );
164911 r1 = codeAllEqualityTerms(pParse,pLevel,0,0,&zStartAff);
164912 codeApplyAffinity(pParse, r1, nEq, zStartAff);
164913 sqlite3DbFree(pParse->db, zStartAff);
 
164914 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
164915 addrNxt, r1, nEq);
164916 VdbeCoverage(pParse->pVdbe);
164917 }
164918 pLevel->regFilter = 0;
@@ -165512,10 +165702,11 @@
165512 if( regBignull ){
165513 sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
165514 VdbeComment((v, "NULL-scan pass ctr"));
165515 }
165516 if( pLevel->regFilter ){
 
165517 sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt,
165518 regBase, nEq);
165519 VdbeCoverage(v);
165520 filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
165521 }
@@ -166249,12 +166440,14 @@
166249 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, 0, r+1, nPk);
166250 VdbeCoverage(v);
166251 VdbeComment((v, "match against %s", pTab->zName));
166252 sqlite3VdbeAddOp3(v, OP_MakeRecord, r+1, nPk, r);
166253 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pRJ->iMatch, r, r+1, nPk);
166254 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r+1, nPk);
166255 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
 
 
166256 sqlite3VdbeJumpHere(v, jmp1);
166257 sqlite3ReleaseTempRange(pParse, r, nPk+1);
166258 }
166259
166260 /* For a LEFT OUTER JOIN, generate code that will record the fact that
@@ -166402,11 +166595,11 @@
166402 WHERE_RIGHT_JOIN, 0);
166403 if( pSubWInfo ){
166404 int iCur = pLevel->iTabCur;
166405 int r = ++pParse->nMem;
166406 int nPk;
166407 int jmp;
166408 int addrCont = sqlite3WhereContinueLabel(pSubWInfo);
166409 Table *pTab = pTabItem->pSTab;
166410 if( HasRowid(pTab) ){
166411 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, -1, r);
166412 nPk = 1;
@@ -166418,15 +166611,17 @@
166418 for(iPk=0; iPk<nPk; iPk++){
166419 int iCol = pPk->aiColumn[iPk];
166420 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+iPk);
166421 }
166422 }
166423 jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
166424 VdbeCoverage(v);
 
 
166425 sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, addrCont, r, nPk);
166426 VdbeCoverage(v);
166427 sqlite3VdbeJumpHere(v, jmp);
166428 sqlite3VdbeAddOp2(v, OP_Gosub, pRJ->regReturn, pRJ->addrSubrtn);
166429 sqlite3WhereEnd(pSubWInfo);
166430 }
166431 sqlite3ExprDelete(pParse->db, pSubWhere);
166432 ExplainQueryPlanPop(pParse);
@@ -168414,10 +168609,20 @@
168414 }
168415 sqlite3SetJoinExpr(pTerm, pItem->iCursor, joinType);
168416 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
168417 }
168418 }
 
 
 
 
 
 
 
 
 
 
168419
168420 /************** End of whereexpr.c *******************************************/
168421 /************** Begin file where.c *******************************************/
168422 /*
168423 ** 2001 September 15
@@ -169426,11 +169631,11 @@
169426 WhereLoop *pLoop; /* The Loop object */
169427 char *zNotUsed; /* Extra space on the end of pIdx */
169428 Bitmask idxCols; /* Bitmap of columns used for indexing */
169429 Bitmask extraCols; /* Bitmap of additional columns */
169430 u8 sentWarning = 0; /* True if a warning has been issued */
169431 u8 useBloomFilter = 0; /* True to also add a Bloom filter */
169432 Expr *pPartial = 0; /* Partial Index Expression */
169433 int iContinue = 0; /* Jump here to skip excluded rows */
169434 SrcList *pTabList; /* The complete FROM clause */
169435 SrcItem *pSrc; /* The FROM clause term to get the next index */
169436 int addrCounter = 0; /* Address where integer counter is initialized */
@@ -169553,22 +169758,17 @@
169553 Expr *pX = pTerm->pExpr;
169554 idxCols |= cMask;
169555 pIdx->aiColumn[n] = pTerm->u.x.leftColumn;
169556 pColl = sqlite3ExprCompareCollSeq(pParse, pX);
169557 assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
 
 
 
 
 
169558 pIdx->azColl[n] = pColl ? pColl->zName : sqlite3StrBINARY;
169559 n++;
169560 if( ALWAYS(pX->pLeft!=0)
169561 && sqlite3ExprAffinity(pX->pLeft)!=SQLITE_AFF_TEXT
169562 ){
169563 /* TUNING: only use a Bloom filter on an automatic index
169564 ** if one or more key columns has the ability to hold numeric
169565 ** values, since strings all have the same hash in the Bloom
169566 ** filter implementation and hence a Bloom filter on a text column
169567 ** is not usually helpful. */
169568 useBloomFilter = 1;
169569 }
169570 }
169571 }
169572 }
169573 assert( (u32)n==pLoop->u.btree.nEq );
169574
@@ -169634,10 +169834,11 @@
169634 regRecord = sqlite3GetTempReg(pParse);
169635 regBase = sqlite3GenerateIndexKey(
169636 pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
169637 );
169638 if( pLevel->regFilter ){
 
169639 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
169640 regBase, pLoop->u.btree.nEq);
169641 }
169642 sqlite3VdbeScanStatusCounters(v, addrExp, addrExp, sqlite3VdbeCurrentAddr(v));
169643 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
@@ -169749,10 +169950,11 @@
169749 if( sz<10000 ){
169750 sz = 10000;
169751 }else if( sz>10000000 ){
169752 sz = 10000000;
169753 }
 
169754 sqlite3VdbeAddOp2(v, OP_Blob, (int)sz, pLevel->regFilter);
169755
169756 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
169757 pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
169758 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
@@ -169771,10 +169973,11 @@
169771 }else{
169772 Index *pIdx = pLoop->u.btree.pIndex;
169773 int n = pLoop->u.btree.nEq;
169774 int r1 = sqlite3GetTempRange(pParse, n);
169775 int jj;
 
169776 for(jj=0; jj<n; jj++){
169777 assert( pIdx->pTable==pItem->pSTab );
169778 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iCur, jj, r1+jj);
169779 }
169780 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n);
@@ -173427,11 +173630,11 @@
173427 }
173428 #ifndef SQLITE_OMIT_VIRTUALTABLE
173429 if( IsVirtual(pItem->pSTab) ){
173430 SrcItem *p;
173431 for(p=&pItem[1]; p<pEnd; p++){
173432 if( mUnusable || (p->fg.jointype & (JT_OUTER|JT_CROSS)) ){
173433 mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
173434 }
173435 }
173436 rc = whereLoopAddVirtual(pBuilder, mPrereq, mUnusable);
173437 }else
@@ -175057,23 +175260,21 @@
175057 Table *pTab = pItem->pSTab;
175058 if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
175059 pTab->tabFlags |= TF_MaybeReanalyze;
175060 if( i>=1
175061 && (pLoop->wsFlags & reqFlags)==reqFlags
175062 /* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */
175063 && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0)
175064 ){
175065 if( nSearch > pTab->nRowLogEst ){
175066 testcase( pItem->fg.jointype & JT_LEFT );
175067 pLoop->wsFlags |= WHERE_BLOOMFILTER;
175068 pLoop->wsFlags &= ~WHERE_IDX_ONLY;
175069 WHERETRACE(0xffffffff, (
175070 "-> use Bloom-filter on loop %c because there are ~%.1e "
175071 "lookups into %s which has only ~%.1e rows\n",
175072 pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName,
175073 (double)sqlite3LogEstToInt(pTab->nRowLogEst)));
175074 }
175075 }
175076 nSearch += pLoop->nOut;
175077 }
175078 }
175079
@@ -175819,19 +176020,19 @@
175819 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
175820 if( (pTabItem->fg.jointype & JT_RIGHT)!=0
175821 && (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
175822 ){
175823 WhereRightJoin *pRJ = pLevel->pRJ;
 
175824 pRJ->iMatch = pParse->nTab++;
175825 pRJ->regBloom = ++pParse->nMem;
175826 sqlite3VdbeAddOp2(v, OP_Blob, 65536, pRJ->regBloom);
175827 pRJ->regReturn = ++pParse->nMem;
175828 sqlite3VdbeAddOp2(v, OP_Null, 0, pRJ->regReturn);
175829 assert( pTab==pTabItem->pSTab );
175830 if( HasRowid(pTab) ){
175831 KeyInfo *pInfo;
175832 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRJ->iMatch, 1);
 
175833 pInfo = sqlite3KeyInfoAlloc(pParse->db, 1, 0);
175834 if( pInfo ){
175835 pInfo->aColl[0] = 0;
175836 pInfo->aSortFlags[0] = 0;
175837 sqlite3VdbeAppendP4(v, pInfo, P4_KEYINFO);
@@ -175838,10 +176039,17 @@
175838 }
175839 }else{
175840 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
175841 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRJ->iMatch, pPk->nKeyCol);
175842 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
 
 
 
 
 
 
 
175843 }
175844 pLoop->wsFlags &= ~WHERE_IDX_ONLY;
175845 /* The nature of RIGHT JOIN processing is such that it messes up
175846 ** the output order. So omit any ORDER BY/GROUP BY elimination
175847 ** optimizations. We need to do an actual sort for RIGHT JOIN. */
@@ -187183,67 +187391,64 @@
187183 SQLITE_API char *sqlite3_data_directory = 0;
187184
187185 /*
187186 ** Initialize SQLite.
187187 **
187188 ** This routine must be called to initialize the memory allocation,
187189 ** VFS, and mutex subsystems prior to doing any serious work with
187190 ** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT
187191 ** this routine will be called automatically by key routines such as
187192 ** sqlite3_open().
187193 **
187194 ** This routine is a no-op except on its very first call for the process,
187195 ** or for the first call after a call to sqlite3_shutdown.
 
 
187196 **
187197 ** The first thread to call this routine runs the initialization to
187198 ** completion. If subsequent threads call this routine before the first
 
 
 
 
 
 
 
 
 
 
187199 ** thread has finished the initialization process, then the subsequent
187200 ** threads must block until the first thread finishes with the initialization.
187201 **
187202 ** The first thread might call this routine recursively. Recursive
187203 ** calls to this routine should not block, of course. Otherwise the
187204 ** initialization process would never complete.
187205 **
187206 ** Let X be the first thread to enter this routine. Let Y be some other
187207 ** thread. Then while the initial invocation of this routine by X is
187208 ** incomplete, it is required that:
187209 **
187210 ** * Calls to this routine from Y must block until the outer-most
187211 ** call by X completes.
187212 **
187213 ** * Recursive calls to this routine from thread X return immediately
187214 ** without blocking.
187215 */
187216 SQLITE_API int sqlite3_initialize(void){
187217 MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
187218 int rc; /* Result code */
187219 #ifdef SQLITE_EXTRA_INIT
187220 int bRunExtraInit = 0; /* Extra initialization needed */
187221 #endif
187222
187223 #ifdef SQLITE_OMIT_WSD
187224 rc = sqlite3_wsd_init(4096, 24);
187225 if( rc!=SQLITE_OK ){
187226 return rc;
187227 }
187228 #endif
187229
187230 /* If the following assert() fails on some obscure processor/compiler
187231 ** combination, the work-around is to set the correct pointer
187232 ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
 
 
187233 assert( SQLITE_PTRSIZE==sizeof(char*) );
187234
187235 /* If SQLite is already completely initialized, then this call
187236 ** to sqlite3_initialize() should be a no-op. But the initialization
187237 ** must be complete. So isInit must not be set until the very end
187238 ** of this routine.
187239 */
187240 if( sqlite3GlobalConfig.isInit ){
187241 sqlite3MemoryBarrier();
187242 return SQLITE_OK;
187243 }
187244
187245 /* Make sure the mutex subsystem is initialized. If unable to
187246 ** initialize the mutex subsystem, return early with the error.
187247 ** If the system is so sick that we are unable to allocate a mutex,
187248 ** there is not much SQLite is going to be able to do.
187249 **
@@ -187383,10 +187588,30 @@
187383 int SQLITE_EXTRA_INIT(const char*);
187384 rc = SQLITE_EXTRA_INIT(0);
187385 }
187386 #endif
187387 return rc;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187388 }
187389
187390 /*
187391 ** Undo the effects of sqlite3_initialize(). Must not be called while
187392 ** there are outstanding database connections or memory allocations or
@@ -189999,10 +190224,11 @@
189999 SQLITE_MAX_LIKE_PATTERN_LENGTH,
190000 SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
190001 SQLITE_MAX_TRIGGER_DEPTH,
190002 SQLITE_MAX_WORKER_THREADS,
190003 SQLITE_MAX_PARSER_DEPTH,
 
190004 };
190005
190006 /*
190007 ** Make sure the hard limits are set to reasonable values
190008 */
@@ -190081,11 +190307,12 @@
190081 assert( aHardLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]==
190082 SQLITE_MAX_LIKE_PATTERN_LENGTH );
190083 assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
190084 assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
190085 assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
190086 assert( SQLITE_LIMIT_PARSER_DEPTH==(SQLITE_N_LIMIT-1) );
 
190087
190088
190089 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
190090 return -1;
190091 }
@@ -213541,11 +213768,11 @@
213541 /*
213542 ** Expand pParse->aBlob so that it holds at least N bytes.
213543 **
213544 ** Return the number of errors.
213545 */
213546 static int jsonBlobExpand(JsonParse *pParse, u32 N){
213547 u8 *aNew;
213548 u64 t;
213549 assert( N>pParse->nBlobAlloc );
213550 if( pParse->nBlobAlloc==0 ){
213551 t = 100;
@@ -213569,11 +213796,11 @@
213569 **
213570 ** Return true on success. Return false on OOM.
213571 */
213572 static int jsonBlobMakeEditable(JsonParse *pParse, u32 nExtra){
213573 u8 *aOld;
213574 u32 nSize;
213575 assert( !pParse->bReadOnly );
213576 if( pParse->oom ) return 0;
213577 if( pParse->nBlobAlloc>0 ) return 1;
213578 aOld = pParse->aBlob;
213579 nSize = pParse->nBlob + nExtra;
@@ -213590,11 +213817,11 @@
213590 */
213591 static SQLITE_NOINLINE void jsonBlobExpandAndAppendOneByte(
213592 JsonParse *pParse,
213593 u8 c
213594 ){
213595 jsonBlobExpand(pParse, pParse->nBlob+1);
213596 if( pParse->oom==0 ){
213597 assert( pParse->nBlob+1<=pParse->nBlobAlloc );
213598 pParse->aBlob[pParse->nBlob++] = c;
213599 }
213600 }
@@ -213617,11 +213844,11 @@
213617 JsonParse *pParse,
213618 u8 eType,
213619 u64 szPayload,
213620 const void *aPayload
213621 ){
213622 if( jsonBlobExpand(pParse, pParse->nBlob+szPayload+9) ) return;
213623 jsonBlobAppendNode(pParse, eType, szPayload, aPayload);
213624 }
213625
213626
213627 /* Append a node type byte together with the payload size and
@@ -213707,11 +213934,11 @@
213707 }else{
213708 nNeeded = 4;
213709 }
213710 delta = nNeeded - nExtra;
213711 if( delta ){
213712 u32 newSize = pParse->nBlob + delta;
213713 if( delta>0 ){
213714 if( newSize>pParse->nBlobAlloc && jsonBlobExpand(pParse, newSize) ){
213715 return 0; /* OOM error. Error state recorded in pParse->oom. */
213716 }
213717 a = &pParse->aBlob[i];
@@ -215055,11 +215282,11 @@
215055 ){
215056 return;
215057 }
215058 if( d!=0 ){
215059 if( pParse->nBlob + d > pParse->nBlobAlloc ){
215060 jsonBlobExpand(pParse, pParse->nBlob+d);
215061 if( pParse->oom ) return;
215062 }
215063 memmove(&pParse->aBlob[iDel+nIns],
215064 &pParse->aBlob[iDel+nDel],
215065 pParse->nBlob - (iDel+nDel));
@@ -251402,10 +251629,11 @@
251402 i64 szData = (sizeof(Fts5Data) + 7) & ~7;
251403 i64 nAlloc = szData + nByte + FTS5_DATA_PADDING;
251404 pRet = (Fts5Data*)sqlite3_malloc64(nAlloc);
251405 if( pRet ){
251406 pRet->nn = nByte;
 
251407 aOut = pRet->p = (u8*)pRet + szData;
251408 }else{
251409 rc = SQLITE_NOMEM;
251410 }
251411
@@ -251414,14 +251642,12 @@
251414 }
251415 if( rc!=SQLITE_OK ){
251416 sqlite3_free(pRet);
251417 pRet = 0;
251418 }else{
251419 /* TODO1: Fix this */
251420 pRet->p[nByte] = 0x00;
251421 pRet->p[nByte+1] = 0x00;
251422 pRet->szLeaf = fts5GetU16(&pRet->p[2]);
251423 }
251424 }
251425 p->rc = rc;
251426 p->nRead++;
251427 }
@@ -251438,13 +251664,21 @@
251438 */
251439 static void fts5DataRelease(Fts5Data *pData){
251440 sqlite3_free(pData);
251441 }
251442
 
 
 
 
251443 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
251444 Fts5Data *pRet = fts5DataRead(p, iRowid);
251445 if( pRet ){
 
 
 
 
251446 if( pRet->szLeaf<4 || pRet->szLeaf>pRet->nn ){
251447 FTS5_CORRUPT_ROWID(p, iRowid);
251448 fts5DataRelease(pRet);
251449 pRet = 0;
251450 }
@@ -255681,11 +255915,11 @@
255681 for(pgno=iPgno; p->rc==SQLITE_OK && pgno<=pSeg->pgnoLast; pgno++){
255682 i64 iRowid = FTS5_SEGMENT_ROWID(pSeg->iSegid, pgno);
255683 int iNext = 0;
255684 u8 *aPg = 0;
255685
255686 pLeaf = fts5DataRead(p, iRowid);
255687 if( pLeaf==0 ) break;
255688 aPg = pLeaf->p;
255689
255690 iNext = fts5GetU16(&aPg[0]);
255691 if( iNext!=0 ){
@@ -255976,19 +256210,19 @@
255976
255977 assert_nc( pSeg->iLeafPgno>pSeg->iTermLeafPgno );
255978 /* The entry being removed may be the only position list in
255979 ** its doclist. */
255980 for(iPgno=pSeg->iLeafPgno-1; iPgno>pSeg->iTermLeafPgno; iPgno-- ){
255981 Fts5Data *pPg = fts5DataRead(p, FTS5_SEGMENT_ROWID(iSegid, iPgno));
255982 int bEmpty = (pPg && pPg->nn==4);
255983 fts5DataRelease(pPg);
255984 if( bEmpty==0 ) break;
255985 }
255986
255987 if( iPgno==pSeg->iTermLeafPgno ){
255988 i64 iId = FTS5_SEGMENT_ROWID(iSegid, pSeg->iTermLeafPgno);
255989 Fts5Data *pTerm = fts5DataRead(p, iId);
255990 if( pTerm && pTerm->szLeaf==pSeg->iTermLeafOffset ){
255991 u8 *aTermIdx = &pTerm->p[pTerm->szLeaf];
255992 int nTermIdx = pTerm->nn - pTerm->szLeaf;
255993 int iTermIdx = 0;
255994 i64 iTermOff = 0;
@@ -258936,11 +259170,11 @@
258936 int i;
258937
258938 /* Now check that the iter.nEmpty leaves following the current leaf
258939 ** (a) exist and (b) contain no terms. */
258940 for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
258941 Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
258942 if( pLeaf ){
258943 if( !fts5LeafIsTermless(pLeaf)
258944 || (i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf))
258945 ){
258946 FTS5_CORRUPT_ROWID(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
@@ -263716,11 +263950,11 @@
263716 int nArg, /* Number of args */
263717 sqlite3_value **apUnused /* Function arguments */
263718 ){
263719 assert( nArg==0 );
263720 UNUSED_PARAM2(nArg, apUnused);
263721 sqlite3_result_text(pCtx, "fts5: 2026-07-07 14:53:53 c3b0fff1b76b8c354b34fef17ff639968698e97234d6ab7af15e0e1a835486e9", -1, SQLITE_TRANSIENT);
263722 }
263723
263724 /*
263725 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263726 **
263727
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 2f1f4f73535386549c12694dc57cfe555eec with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-07-24 16:28:47 2f1f4f73535386549c12694dc57cfe555eec689ae6824c6241aaf8d5befcd74d"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-07-24T16:28:47.830Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4751,10 +4751,14 @@
4751 ** nesting depth for separate triggers.</dd>)^
4752 **
4753 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4754 ** <dd>The maximum number of auxiliary worker threads that a single
4755 ** [prepared statement] may start.</dd>)^
4756 **
4757 ** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4758 ** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4759 ** defined by the database schema.</dd>)^
4760 ** </dl>
4761 */
4762 #define SQLITE_LIMIT_LENGTH 0
4763 #define SQLITE_LIMIT_SQL_LENGTH 1
4764 #define SQLITE_LIMIT_COLUMN 2
@@ -4766,10 +4770,11 @@
4770 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
4771 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
4772 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
4773 #define SQLITE_LIMIT_WORKER_THREADS 11
4774 #define SQLITE_LIMIT_PARSER_DEPTH 12
4775 #define SQLITE_LIMIT_SCHEMA 13
4776
4777 /*
4778 ** CAPI3REF: Prepare Flags
4779 **
4780 ** These constants define various flags that can be passed into the
@@ -6798,11 +6803,15 @@
6803 ** to by the second parameter and which is N bytes long where N is the
6804 ** third parameter.
6805 **
6806 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
6807 ** interfaces set the result of the application-defined function to be
6808 ** a BLOB containing all zero bytes and N bytes in size. The
6809 ** zeroblob64(C,N) interface returns a [result code], which is normally
6810 ** [SQLITE_OK] but might be some other value if the requested operation
6811 ** could not be complete, for example if insufficient memory is available
6812 ** or if the value of N is out of range.
6813 **
6814 ** ^The sqlite3_result_double() interface sets the result from
6815 ** an application-defined function to be a floating point value specified
6816 ** by its 2nd argument.
6817 **
@@ -15031,10 +15040,37 @@
15040 */
15041 #ifndef SQLITE_MAX_TRIGGER_DEPTH
15042 # define SQLITE_MAX_TRIGGER_DEPTH 1000
15043 #endif
15044
15045 /*
15046 ** Maximum number of objects defined by a single database schema.
15047 ** Objects include:
15048 **
15049 ** * tables (including the sqlite_schema table)
15050 ** * virtual tables
15051 ** * named indexes
15052 ** * indexes created automatically by UNIQUE and PRIMARY KEY constraints
15053 ** * triggers
15054 ** * views
15055 **
15056 ** The total of all of the above is the number of objects in the schema,
15057 ** and that number may not exceed this value.
15058 **
15059 ** The maximum number of objects is restricted to forestall theoretical
15060 ** signed integer overflow attacks using databases with billions of
15061 ** schema objects. Such attacks are "theoretical" because memory and
15062 ** disk space constraints would be reached long before billions of schema
15063 ** objects could be created. Even so, it seems good to have a well defined
15064 ** upper limit on the complexity of the schema, for defense in depth.
15065 ** No real-world application should ever get anywhere close to hitting
15066 ** this limit.
15067 */
15068 #ifndef SQLITE_MAX_SCHEMA
15069 # define SQLITE_MAX_SCHEMA 10000000
15070 #endif
15071
15072 /************** End of sqliteLimit.h *****************************************/
15073 /************** Continuing where we left off in sqliteInt.h ******************/
15074
15075 /* Disable nuisance warnings on Borland compilers */
15076 #if defined(__BORLANDC__)
@@ -15289,11 +15325,13 @@
15325 ** bitmask tests, testcase() can be used to make sure each bit
15326 ** is significant and used at least once. On switch statements
15327 ** where multiple cases go to the same block of code, testcase()
15328 ** can insure that all cases are evaluated.
15329 */
15330 #if defined(SQLITE_MUTATION_TEST)
15331 # define testcase(X)
15332 #elif defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
15333 # ifndef SQLITE_AMALGAMATION
15334 extern unsigned int sqlite3CoverageCounter;
15335 # endif
15336 # define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; }
15337 #else
@@ -18636,11 +18674,11 @@
18674
18675 /*
18676 ** The number of different kinds of things that can be limited
18677 ** using the sqlite3_limit() interface.
18678 */
18679 #define SQLITE_N_LIMIT (SQLITE_LIMIT_SCHEMA+1)
18680
18681 /*
18682 ** Lookaside malloc is a set of fixed-size buffers that can be used
18683 ** to satisfy small transient memory allocation requests for objects
18684 ** associated with a particular database connection. The use of
@@ -22010,10 +22048,11 @@
22048 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
22049 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
22050 #endif
22051 #if defined(SQLITE_TEST)
22052 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
22053 SQLITE_PRIVATE const char *sqlite3TestPtrToText(void*);
22054 #endif
22055
22056 #if defined(SQLITE_DEBUG)
22057 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView*, const char *zFormat, ...);
22058 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
@@ -22234,10 +22273,11 @@
22273 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
22274 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
22275 SQLITE_PRIVATE void sqlite3ClearOnOrUsing(sqlite3*, OnOrUsing*);
22276 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
22277 SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,int,int,char**);
22278 SQLITE_PRIVATE int sqlite3IndexBloomable(const Index*,int);
22279 SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
22280 Expr*, int, int, u8);
22281 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
22282 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
22283 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
@@ -23646,10 +23686,13 @@
23686 "MAX_PAGE_COUNT=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_COUNT),
23687 #endif
23688 #ifdef SQLITE_MAX_PAGE_SIZE
23689 "MAX_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_SIZE),
23690 #endif
23691 #ifdef SQLITE_MAX_SCHEMA
23692 "MAX_SCHEMA=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA),
23693 #endif
23694 #ifdef SQLITE_MAX_SCHEMA_RETRY
23695 "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
23696 #endif
23697 #ifdef SQLITE_MAX_SQL_LENGTH
23698 "MAX_SQL_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_SQL_LENGTH),
@@ -26531,11 +26574,11 @@
26574 ** on the appropriate weekday, this is a no-op.
26575 */
26576 if( sqlite3_strnicmp(z, "weekday ", 8)==0
26577 && sqlite3AtoF(&z[8], &r)>0
26578 && r>=-6.0 && r<=6.0
26579 && sqlite3RealSameAsInt(r,(i64)(n=(int)r))
26580 ){
26581 sqlite3_int64 Z;
26582 computeYMD_HMS(p);
26583 p->tz = 0;
26584 p->validJD = 0;
@@ -46092,11 +46135,10 @@
46135 i64 nNew /* Required mapping size */
46136 ){
46137 const char *zErr = "mmap";
46138 int h = pFd->h; /* File descriptor open on db file */
46139 u8 *pOrig = (u8 *)pFd->pMapRegion; /* Pointer to current file mapping */
 
46140 u8 *pNew = 0; /* Location of new mapping */
46141 int flags = PROT_READ; /* Flags to pass to mmap() */
46142
46143 assert( pFd->nFetchOut==0 );
46144 assert( nNew>pFd->mmapSize );
@@ -46110,25 +46152,16 @@
46152 #endif
46153
46154 if( pOrig ){
46155 #if HAVE_MREMAP
46156 i64 nReuse = pFd->mmapSize;
46157 pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
46158 zErr = "mremap";
46159 #else
46160 const int szSyspage = osGetpagesize();
46161 i64 nReuse = (pFd->mmapSize & ~(szSyspage-1));
 
46162 u8 *pReq = &pOrig[nReuse];
 
 
 
 
 
 
 
 
 
 
46163 pNew = osMmap(pReq, nNew-nReuse, flags, MAP_SHARED, h, nReuse);
46164 if( pNew!=MAP_FAILED ){
46165 if( pNew!=pReq ){
46166 osMunmap(pNew, nNew - nReuse);
46167 pNew = 0;
@@ -46759,40 +46792,33 @@
46792 verifyDbFile(pNew);
46793 }
46794 return rc;
46795 }
46796
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46797 /*
46798 ** Return the name of a directory in which to put temporary files.
46799 ** If no suitable temporary file directory can be found, return NULL.
46800 **
46801 ** The return value might be a string obtained from getenv() and so
46802 ** the return value should not be used after any call to setenv() or
46803 ** putenv() as that value might have been freed.
46804 */
46805 static const char *unixTempFileDir(void){
46806 unsigned int i;
46807 struct stat buf;
46808 const char *zDir;
46809
46810 for(i=0; i<7; i++){
46811 switch( i ){
46812 case 0: zDir = sqlite3_temp_directory; break;
46813 case 1: zDir = getenv("SQLITE_TMPDIR"); break;
46814 case 2: zDir = getenv("TMPDIR"); break;
46815 case 3: zDir = "/var/tmp"; break;
46816 case 4: zDir = "/usr/tmp"; break;
46817 case 5: zDir = "/tmp"; break;
46818 default: zDir = "."; break;
46819 }
46820 if( zDir!=0
46821 #if OS_VXWORKS
46822 && zDir[0]=='/'
46823 #endif
46824 && osStat(zDir, &buf)==0
@@ -46799,12 +46825,10 @@
46825 && S_ISDIR(buf.st_mode)
46826 && osAccess(zDir, 03)==0
46827 ){
46828 return zDir;
46829 }
 
 
46830 }
46831 return 0;
46832 }
46833
46834 /*
@@ -49083,13 +49107,10 @@
49107 ** DMS UNIX_SHM_BASE+8 128
49108 */
49109 assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */
49110 #endif
49111
 
 
 
49112 return SQLITE_OK;
49113 }
49114
49115 /*
49116 ** Shutdown the operating system interface.
@@ -93648,14 +93669,15 @@
93669 SQLITE_API void sqlite3_result_str(sqlite3_context *pCtx, sqlite3_str *pStr, int eOwn){
93670 #ifdef SQLITE_ENABLE_API_ARMOR
93671 if( pCtx==0 ) return;
93672 if( pStr==0 ) return;
93673 #endif
93674 testcase( pStr==(sqlite3_str*)&sqlite3OomStr );
93675 if( pStr->accError==0 ){
93676 if( pStr->nChar==0 ){
93677 setResultStrOrError(pCtx, "", 0, SQLITE_UTF8_ZT, SQLITE_STATIC);
93678 sqlite3_str_reset(pStr);
93679 }else{
93680 const char *zText = sqlite3_str_value(pStr);
93681 /* Only internal code has the ability to capture a pointer to
93682 ** an sqlite3_str object that uses static buffer. And none of
93683 ** those internal use cases every invoke the sqlite3_result_str()
@@ -93666,26 +93688,21 @@
93688 setResultStrOrError(pCtx, zText, pStr->nChar,
93689 SQLITE_UTF8, SQLITE_TRANSIENT);
93690 }else{
93691 setResultStrOrError(pCtx, zText, pStr->nChar,
93692 SQLITE_UTF8_ZT, SQLITE_DYNAMIC);
93693 sqlite3StrAccumInit(pStr, pStr->db, 0, 0, pStr->mxAlloc);
93694 }
93695 }
93696 }else if( pStr->accError==SQLITE_NOMEM ){
93697 sqlite3_result_error_nomem(pCtx);
93698 }else{
93699 assert( pStr->accError==SQLITE_TOOBIG );
93700 sqlite3_result_error_toobig(pCtx);
93701 }
93702 if( eOwn==SQLITE_FINISH ){
93703 sqlite3_str_free(pStr);
 
 
 
 
 
 
93704 }
93705 }
93706
93707 #ifndef SQLITE_UNTESTABLE
93708 /* Force the INT64 value currently stored as the result to be
@@ -96574,10 +96591,14 @@
96591 }
96592
96593 /*
96594 ** Compute a bloom filter hash using pOp->p4.i registers from aMem[] beginning
96595 ** with pOp->p3. Return the hash.
96596 **
96597 ** IMPORTANT RESTRICTION (tag-202607231411): This hash is only valid if the
96598 ** collating sequence for TEXT is BINARY. Hence, Bloom filters that use this
96599 ** hash will not work for look-ups that use any other collating sequence.
96600 */
96601 static u64 filterHash(const Mem *aMem, const Op *pOp){
96602 int i, mx;
96603 u64 h = 0;
96604
@@ -96586,15 +96607,32 @@
96607 const Mem *p = &aMem[i];
96608 if( p->flags & (MEM_Int|MEM_IntReal) ){
96609 h += p->u.i;
96610 }else if( p->flags & MEM_Real ){
96611 h += sqlite3VdbeIntValue(p);
96612 }else if( p->flags & MEM_Str ){
96613 u64 x;
96614 h += p->n;
96615 if( p->n >= sizeof(x) ){
96616 memcpy(&x, p->z, sizeof(x));
96617 h += x;
96618 memcpy(&x, p->z + p->n - sizeof(x), sizeof(x));
96619 h += x;
96620 }else{
96621 x = 0;
96622 memcpy(&x, p->z, p->n);
96623 h += x;
96624 }
96625 }else if( p->flags & MEM_Blob ){
96626 int n = p->n;
96627 u64 x = 0;
96628 if( n ){
96629 memcpy(&x, p->z, MIN(n, sizeof(x)));
96630 h += x;
96631 }
96632 h += n;
96633 if( p->flags & MEM_Zero ) h += p->u.nZero;
96634 }
96635 }
96636 return h;
96637 }
96638
@@ -101417,11 +101455,11 @@
101455 */
101456 case OP_SeekRowid: { /* jump0, in3, ncycle */
101457 VdbeCursor *pC;
101458 BtCursor *pCrsr;
101459 int res;
101460 i64 iKey;
101461
101462 pIn3 = &aMem[pOp->p3];
101463 testcase( pIn3->flags & MEM_Int );
101464 testcase( pIn3->flags & MEM_IntReal );
101465 testcase( pIn3->flags & MEM_Real );
@@ -101431,13 +101469,23 @@
101469 ** integer value of pIn3. Jump to P2 if pIn3 cannot be converted
101470 ** into an integer without loss of information. Take care to avoid
101471 ** changing the datatype of pIn3, however, as it is used by other
101472 ** parts of the prepared statement. */
101473 Mem x = pIn3[0];
101474 if( x.flags & MEM_Str ){
101475 applyNumericAffinity(&x, 1);
101476 }
101477 if( x.flags & MEM_Int ){
101478 iKey = x.u.i;
101479 }else
101480 if( (x.flags & MEM_Real)==0
101481 || x.u.r < -9223372036854775808.0
101482 || x.u.r > 9223372036854775807.0
101483 || (double)(iKey = sqlite3RealToI64(x.u.r))!=x.u.r
101484 ){
101485 goto jump_to_p2;
101486 }
101487 goto notExistsWithKey;
101488 }
101489 /* Fall through into OP_NotExists */
101490 /* no break */ deliberate_fall_through
101491 case OP_NotExists: /* jump, in3, ncycle */
@@ -110677,18 +110725,17 @@
110725 if( cnt==1 ){
110726 assert( pNC!=0 );
110727 #ifndef SQLITE_OMIT_AUTHORIZATION
110728 if( db->xAuth ){
110729 if( pFJMatch ){
 
110730 assert( pExpr->op==TK_FUNCTION );
110731 assert( sqlite3_stricmp(pExpr->u.zToken,"coalesce")==0 );
110732 assert( pExpr->x.pList==pFJMatch );
110733 assert( pFJMatch->nExpr>0 );
110734 for(i=0; i<pFJMatch->nExpr; i++){
110735 assert( pFJMatch->a[i].pExpr->op==TK_COLUMN );
110736 sqlite3AuthRead(pParse,pFJMatch->a[i].pExpr,pSchema,pNC->pSrcList);
110737 }
110738 }else if( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ){
110739 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
110740 }
110741 }
@@ -110802,15 +110849,24 @@
110849 static SQLITE_NOINLINE void resolveSetExprSubtypeArg(ExprList *pList){
110850 int nn, ii;
110851 nn = pList ? pList->nExpr : 0;
110852 for(ii=0; ii<nn; ii++){
110853 Expr *pExpr = pList->a[ii].pExpr;
110854 while( 1 /*exit-by-break*/ ){
110855 ExprSetProperty(pExpr, EP_SubtArg);
110856 if( pExpr->op==TK_SELECT ){
110857 assert( ExprUseXSelect(pExpr) );
110858 assert( pExpr->x.pSelect!=0 );
110859 resolveSetExprSubtypeArg(pExpr->x.pSelect->pEList);
110860 break;
110861 }
110862 if( pExpr->op==TK_UPLUS ){
110863 pExpr = pExpr->pLeft;
110864 assert( pExpr!=0 );
110865 }else{
110866 break;
110867 }
110868 }
110869 }
110870 }
110871
110872 /*
@@ -115893,10 +115949,12 @@
115949 }else{
115950 VdbeComment((v, "RHS of IN operator"));
115951 }
115952 #endif
115953 pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
115954 assert( pKeyInfo!=0 || pParse->nErr );
115955 if( pKeyInfo==0 ) return;
115956
115957 if( ExprUseXSelect(pExpr) ){
115958 /* Case 1: expr IN (SELECT ...)
115959 **
115960 ** Generate code to write the results of the select into the temporary
@@ -115917,21 +115975,35 @@
115975 int rc;
115976 int addrBloom = 0;
115977 sqlite3SelectDestInit(&dest, SRT_Set, iTab);
115978 dest.zAffSdst = exprINAffinity(pParse, pExpr);
115979 pSelect->iLimit = 0;
115980 assert( pEList!=0 );
115981 assert( pEList->nExpr>0 );
115982 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
115983 for(i=0; i<nVal; i++){
115984 Expr *p = sqlite3VectorFieldSubexpr(pLeft, i);
115985 CollSeq *pColl;
115986 pKeyInfo->aColl[i] = pColl = sqlite3BinaryCompareCollSeq(
115987 pParse, p, pEList->a[i].pExpr
115988 );
115989 if( !sqlite3IsBinary(pColl) ){
115990 allowBloom = 0; /* tag-202607231411 */
115991 }
115992 }
115993 if( addrOnce
115994 && allowBloom
115995 && OptimizationEnabled(pParse->db, SQLITE_BloomFilter)
115996 ){
115997 int regBloom = ++pParse->nMem;
115998 addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
115999 VdbeComment((v, "Bloom filter"));
116000 dest.iSDParm2 = regBloom;
116001 sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
116002 pKeyInfo = 0;
116003 }
116004 testcase( pSelect->selFlags & SF_Distinct );
 
116005 pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
116006 rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
116007 sqlite3SelectDelete(pParse->db, pCopy);
116008 sqlite3DbFree(pParse->db, dest.zAffSdst);
116009 if( addrBloom ){
@@ -115945,20 +116017,10 @@
116017 }
116018 if( rc ){
116019 sqlite3KeyInfoUnref(pKeyInfo);
116020 return;
116021 }
 
 
 
 
 
 
 
 
 
 
116022 }
116023 }else if( ALWAYS(pExpr->x.pList!=0) ){
116024 /* Case 2: expr IN (exprlist)
116025 **
116026 ** For each expression, build an index key from the evaluation and
@@ -115975,14 +116037,13 @@
116037 if( affinity<=SQLITE_AFF_NONE ){
116038 affinity = SQLITE_AFF_BLOB;
116039 }else if( affinity==SQLITE_AFF_REAL ){
116040 affinity = SQLITE_AFF_NUMERIC;
116041 }
116042 assert( pKeyInfo!=0 );
116043 assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
116044 pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
 
116045
116046 /* Loop through each expression in <exprlist>. */
116047 r1 = sqlite3GetTempReg(pParse);
116048 r2 = sqlite3GetTempReg(pParse);
116049 for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
@@ -116935,11 +116996,11 @@
116996 if( pExpr->op!=TK_FUNCTION ){
116997 return WRC_Prune;
116998 }
116999 assert( ExprUseXList(pExpr) );
117000 db = pWalker->pParse->db;
117001 n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
117002 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
117003 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
117004 pWalker->eCode = 1;
117005 return WRC_Abort;
117006 }
@@ -122344,19 +122405,41 @@
122405
122406
122407 /*
122408 ** Argument z points into the body of a constraint - specifically the
122409 ** second token of the constraint definition. For a named constraint,
122410 ** z points to the second token of the constraint definition. For an
122411 ** unnamed NOT NULL constraint, z points to the first byte past the NOT
122412 ** keyword.
122413 **
122414 ** Argument eTok may be the token value of the first token of the constraint
122415 ** (e.g. TK_CHECK or TK_REFERENCES) or zero. If it is either TK_REFERENCES
122416 ** or TK_FOREIGN, special parsing is enabled to find the end of the foreign-key
122417 ** constraint definition.
122418 **
122419 ** Return the number of bytes until the end of the constraint.
122420 */
122421 static int getConstraint(const u8 *z, int eTok){
122422 int iOff = 0;
122423 int t = 0;
122424
122425 #ifndef SQLITE_OMIT_FOREIGN_KEY
122426 if( eTok==TK_FOREIGN ){
122427 /* For a FOREIGN KEY constraint, use getConstraint() to parse everything
122428 ** up to the REFERENCES keyword. Then getConstraintToken() to consume
122429 ** the TK_REFERENCES token itself. Then fall through to the special
122430 ** handling for TK_REFERENCES below. */
122431 iOff = getConstraint(z, 0);
122432 iOff += getConstraintToken(&z[iOff], &eTok);
122433 }
122434
122435 if( eTok==TK_REFERENCES ){
122436 /* REFERENCES is followed by a table name. Gobble this up here in
122437 ** case the table name is a fallback token like TK_GENERATED. */
122438 iOff += getConstraintToken(&z[iOff], &t);
122439 }
122440 #endif
122441
122442 /* Now, the current constraint proceeds until the next occurence of one
122443 ** of the following tokens:
122444 **
122445 ** CONSTRAINT, PRIMARY, NOT, UNIQUE, CHECK, DEFAULT,
@@ -122525,24 +122608,24 @@
122608 || t==TK_COMMA || t==TK_RP || t==TK_GENERATED || t==TK_AS
122609 ){
122610 t = TK_CHECK;
122611 }else{
122612 iOff += nTok;
122613 iOff += getConstraint(&zSql[iOff], t);
122614 }
122615
122616 if( cmp==0 || (iNotNull>=0 && t==TK_NOT) ){
122617 if( t!=TK_NOT && t!=TK_CHECK && t!=TK_REFERENCES && t!=TK_FOREIGN ){
122618 errorMPrintf(ctx, "constraint may not be dropped: %s", zCons);
122619 return;
122620 }
122621 iEnd = iOff;
122622 break;
122623 }
122624
122625 }else if( t==TK_NOT && iNotNull==ii ){
122626 iEnd = iOff + getConstraint(&zSql[iOff], 0);
122627 break;
122628 }else if( t==TK_RP || t==TK_ILLEGAL ){
122629 iEnd = -1;
122630 break;
122631 }else if( t==TK_COMMA ){
@@ -128170,10 +128253,27 @@
128253 pIdx->aSortOrder = (u8*)zExtra;
128254 pIdx->nColumn = (u16)N; /* See tag-20250221-1 above for proof of safety */
128255 pIdx->isResized = 1;
128256 return SQLITE_OK;
128257 }
128258
128259 /*
128260 ** Return true if the index pIdx can support a Bloom filter on its
128261 ** first N columns. Specifically, return true if all of the first N
128262 ** columns have the BINARY collating sequence or no collating sequence
128263 ** at all, and return false if there are any non-BINARY collating
128264 ** seqeuences on any of the first N columns. tag-202607231411
128265 */
128266 SQLITE_PRIVATE int sqlite3IndexBloomable(const Index *pIdx, int N){
128267 int i;
128268 assert( pIdx!=0 );
128269 assert( N <= pIdx->nColumn );
128270 for(i=0; i<N; i++){
128271 if( sqlite3StrICmp(pIdx->azColl[i],"BINARY")!=0 ) return 0;
128272 }
128273 return 1;
128274 }
128275
128276 /*
128277 ** Estimate the total row width for a table.
128278 */
128279 static void estimateTableWidth(Table *pTab){
@@ -130038,12 +130138,13 @@
130138 }
130139 }
130140 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
130141 if( !ifNotExist ){
130142 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
130143 }else if( db->init.busy ){
130144 sqlite3ErrorMsg(pParse,""); /* corruptSchema() will do the error */
130145 }else{
 
130146 sqlite3CodeVerifySchema(pParse, iDb);
130147 sqlite3ForceNotReadOnly(pParse);
130148 }
130149 goto exit_create_index;
130150 }
@@ -136304,17 +136405,21 @@
136405 static void percentSort(
136406 double *a, /* Array to sort */
136407 unsigned int n, /* Number of elements in array a[] */
136408 int iReq /* Element caller cares about (or -ve) */
136409 ){
136410 int iLt; /* Entries before a[iLt] are less than or equal to rPivot */
136411 int iGt; /* Entries a[iGt] and after are greater or equal to rPivot */
136412 int i; /* Loop counter */
136413 double rPivot; /* The pivot value */
136414
136415 assert( n>=2 );
136416 do{
136417 /* Put the first, middle, and last elements in sorted order.
136418 ** After doing so, return immediately if the array contains
136419 ** three or fewer elements as there is nothing more to do.
136420 */
136421 if( a[0]>a[n-1] ){
136422 SWAP_DOUBLE(a[0],a[n-1])
136423 }
136424 if( n==2 ) return;
136425 iGt = n-1;
@@ -136323,10 +136428,15 @@
136428 SWAP_DOUBLE(a[0],a[i])
136429 }else if( a[i]>a[iGt] ){
136430 SWAP_DOUBLE(a[i],a[iGt])
136431 }
136432 if( n==3 ) return;
136433
136434 /* Take the value of the middle element as the pivot. Shuffle
136435 ** values around so that all elements less than the pivot come
136436 ** before all elements greater than the pivot.
136437 */
136438 rPivot = a[i];
136439 iLt = i = 1;
136440 do{
136441 if( a[i]<rPivot ){
136442 if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt])
@@ -136340,12 +136450,16 @@
136450 }else{
136451 i++;
136452 }
136453 }while( i<iGt );
136454
136455 assert( iLt>0 && iLt<iGt && iGt<n );
136456 testcase( iGt>iLt+1 );
136457 assert( a[iLt]==rPivot );
136458 assert( a[iLt-1]<=rPivot );
136459 assert( a[iGt]>=rPivot );
136460 assert( a[iLt+1]>=rPivot );
136461
136462 if( iReq>=0 ){
136463 /* In this case, the only elements that the caller requires sorted into
136464 ** the correct positions are elements a[iReq] and a[iReq+1]. At this
136465 ** point we know that element a[iLt] is in the correct position and
@@ -140577,10 +140691,26 @@
140691 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
140692 regTrigCnt = pTrigger!=0 || sqlite3FkRequired(pParse, pTab, 0, 0);
140693 }else{
140694 pTrigger = 0;
140695 regTrigCnt = sqlite3FkRequired(pParse, pTab, 0, 0);
140696 }
140697 if( regTrigCnt ){
140698 /* At this point regTrigCnt is non-zero if there are DELETE triggers
140699 ** or FK triggers. But we only care about these things if there is
140700 ** a chance that a row will be deleted by an ON CONFLICT REPLACE
140701 ** constraint. So zero regTrigCnt if no such constraint can be found. */
140702 if( overrideError!=OE_Replace ){
140703 if( overrideError!=OE_Default ){
140704 regTrigCnt = 0;
140705 }else if( pkChng==0 || pPk || pTab->keyConf!=OE_Replace ){
140706 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
140707 if( pIdx->onError==OE_Replace ) break;
140708 }
140709 if( pIdx==0 ) regTrigCnt = 0;
140710 }
140711 }
140712 }
140713 if( regTrigCnt ){
140714 /* Replace triggers might exist. Allocate the counter and
140715 ** initialize it to zero. */
140716 regTrigCnt = ++pParse->nMem;
@@ -140629,13 +140759,17 @@
140759 ** the UNIQUE constraints have run.
140760 */
140761 if( onError==OE_Replace /* IPK rule is REPLACE */
140762 && onError!=overrideError /* Rules for other constraints are different */
140763 && pTab->pIndex /* There exist other constraints */
 
140764 ){
140765 if( upsertIpkDelay ){
140766 ipkTop = upsertIpkDelay + 1;
140767 upsertIpkDelay = 0;
140768 }else{
140769 ipkTop = sqlite3VdbeAddOp0(v, OP_Goto)+1;
140770 }
140771 VdbeComment((v, "defer IPK REPLACE until last"));
140772 }
140773
140774 if( isUpdate ){
140775 /* pkChng!=0 does not mean that the rowid has changed, only that
@@ -140725,15 +140859,15 @@
140859 sqlite3VdbeGoto(v, ignoreDest);
140860 break;
140861 }
140862 }
140863 sqlite3VdbeResolveLabel(v, addrRowidOk);
140864 if( ipkTop ){
 
 
140865 ipkBottom = sqlite3VdbeAddOp0(v, OP_Goto);
140866 sqlite3VdbeJumpHere(v, ipkTop-1);
140867 }else if( pUpsert && pUpsertClause!=pUpsert ){
140868 upsertIpkReturn = sqlite3VdbeAddOp0(v, OP_Goto);
140869 }
140870 }
140871
140872 /* Test all UNIQUE constraints by creating entries for each UNIQUE
140873 ** index and making sure that duplicate entries do not already exist.
@@ -140749,10 +140883,11 @@
140883 int regIdx; /* Range of registers holding content for pIdx */
140884 int regR; /* Range of registers holding conflicting PK */
140885 int iThisCur; /* Cursor for this UNIQUE index */
140886 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
140887 int addrConflictCk; /* First opcode in the conflict check logic */
140888 int nConflictCk; /* Number of opcodes in conflict check logic */
140889
140890 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
140891 if( pUpsert ){
140892 pUpsertClause = sqlite3UpsertOfIndex(pUpsert, pIdx);
140893 if( upsertIpkDelay && pUpsertClause==pUpsert ){
@@ -140924,10 +141059,15 @@
141059 VdbeCoverageIf(v, op==OP_Ne);
141060 }
141061 }
141062 }
141063 }
141064
141065 nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk;
141066 assert( nConflictCk>0 || db->mallocFailed );
141067 testcase( nConflictCk<=0 );
141068 testcase( nConflictCk>1 );
141069
141070 /* Generate code that executes if the new index entry is not unique */
141071 assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
141072 || onError==OE_Ignore || onError==OE_Replace || onError==OE_Update );
141073 switch( onError ){
@@ -140950,17 +141090,11 @@
141090 testcase( onError==OE_Ignore );
141091 sqlite3VdbeGoto(v, ignoreDest);
141092 break;
141093 }
141094 default: {
 
 
141095 assert( onError==OE_Replace );
 
 
 
 
141096 if( regTrigCnt ){
141097 sqlite3MultiWrite(pParse);
141098 nReplaceTrig++;
141099 }
141100 if( pTrigger && isUpdate ){
@@ -140970,62 +141104,62 @@
141104 regR, nPkField, 0, OE_Replace,
141105 (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
141106 if( pTrigger && isUpdate ){
141107 sqlite3VdbeAddOp1(v, OP_CursorUnlock, iDataCur);
141108 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141109 seenReplace = 1;
141110 break;
141111 }
141112 }
141113 if( regTrigCnt ){
141114 int addrBypass; /* Jump destination to bypass recheck logic */
141115
141116 sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */
141117 addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */
141118 VdbeComment((v, "bypass recheck"));
141119
141120 /* Here we insert code that will be invoked after all constraint
141121 ** checks have run, if and only if one or more replace triggers
141122 ** fired. */
141123 sqlite3VdbeResolveLabel(v, lblRecheckOk);
141124 lblRecheckOk = sqlite3VdbeMakeLabel(pParse);
141125 if( pIdx->pPartIdxWhere ){
141126 /* Bypass the recheck if this partial index is not defined
141127 ** for the current row */
141128 sqlite3VdbeAddOp2(v, OP_IsNull, regIdx-1, lblRecheckOk);
141129 VdbeCoverage(v);
141130 }
141131 /* Copy the constraint check code from above, except change
141132 ** the constraint-ok jump destination to be the address of
141133 ** the next retest block */
141134 while( nConflictCk>0 ){
141135 VdbeOp x; /* Conflict check opcode to copy */
141136 /* The sqlite3VdbeAddOp4() call might reallocate the opcode array.
141137 ** Hence, make a complete copy of the opcode, rather than using
141138 ** a pointer to the opcode. */
141139 x = *sqlite3VdbeGetOp(v, addrConflictCk);
141140 if( x.opcode!=OP_IdxRowid ){
141141 int p2; /* New P2 value for copied conflict check opcode */
141142 const char *zP4;
141143 if( sqlite3OpcodeProperty[x.opcode]&OPFLG_JUMP ){
141144 p2 = lblRecheckOk;
141145 }else{
141146 p2 = x.p2;
141147 }
141148 zP4 = x.p4type==P4_INT32 ? SQLITE_INT_TO_PTR(x.p4.i) : x.p4.z;
141149 sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, zP4, x.p4type);
141150 sqlite3VdbeChangeP5(v, x.p5);
141151 VdbeCoverageIf(v, p2!=x.p2);
141152 }
141153 nConflictCk--;
141154 addrConflictCk++;
141155 }
141156 /* If the retest fails, issue an abort */
141157 sqlite3UniqueConstraint(pParse, OE_Abort, pIdx);
141158
141159 sqlite3VdbeJumpHere(v, addrBypass); /* Terminate the recheck bypass */
141160 }
141161 sqlite3VdbeResolveLabel(v, addrUniqueOk);
141162 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
141163 if( pUpsertClause
141164 && upsertIpkReturn
141165 && sqlite3UpsertNextIsIPK(pUpsertClause)
@@ -141059,12 +141193,12 @@
141193 VdbeCoverage(v);
141194 sqlite3RowidConstraint(pParse, OE_Abort, pTab);
141195 }else{
141196 sqlite3VdbeGoto(v, addrRecheck);
141197 }
 
141198 }
141199 if( regTrigCnt ) sqlite3VdbeResolveLabel(v, lblRecheckOk);
141200
141201 /* Generate the table record */
141202 if( HasRowid(pTab) ){
141203 int regRec = aRegIdx[ix];
141204 sqlite3VdbeAddOp3(v, OP_MakeRecord, regNewData+1, pTab->nNVCol, regRec);
@@ -147540,10 +147674,11 @@
147674 corruptSchema(pData, argv, 0);
147675 return 1;
147676 }
147677
147678 assert( iDb>=0 && iDb<db->nDb );
147679 assert( db->aDb[iDb].pSchema!=0 );
147680 if( argv[3]==0 ){
147681 corruptSchema(pData, argv, 0);
147682 }else if( argv[4]
147683 && 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
147684 && 'r'==sqlite3UpperToLower[(unsigned char)argv[4][1]] ){
@@ -147614,10 +147749,20 @@
147749 ){
147750 if( sqlite3Config.bExtraSchemaChecks ){
147751 corruptSchema(pData, argv, "invalid rootpage");
147752 }
147753 }
147754 }
147755 if( pData->pzErrMsg[0]==0 ){
147756 Schema *pX = db->aDb[iDb].pSchema;
147757 if( pX->tblHash.count + pX->idxHash.count + pX->trigHash.count
147758 > (u32)db->aLimit[SQLITE_LIMIT_SCHEMA]
147759 ){
147760 *pData->pzErrMsg = sqlite3MPrintf(db, "too many schema objects");
147761 pData->rc = SQLITE_ERROR;
147762 return 1;
147763 }
147764 }
147765 return 0;
147766 }
147767
147768 /*
@@ -149659,10 +149804,52 @@
149804 }
149805 pSort->nDefer = (u8)nDefer;
149806 *ppExtra = pExtra;
149807 }
149808 #endif
149809
149810 #ifdef SQLITE_DEBUG
149811 /*
149812 ** This is a byte-code validation check that only runs when SQLITE_DEBUG
149813 ** is defined. This routine looks backwards through the bytecode
149814 ** for the definition of cursor with index iCur. It extracts the KeyInfo from
149815 ** that cursor (it must be an index cursor) and verifies that the cursor
149816 ** does not use any collating seqeuences other than BINARY for its first
149817 ** nCol columns.
149818 **
149819 ** This routine is used inside of an assert(). So it should return true
149820 ** on success and false if the invariant is not satisfied.
149821 **
149822 ** tag-202607231411
149823 */
149824 static int sqlite3CursorBloomable(Parse *pParse, int iCur, int nCol){
149825 int i,k;
149826 Vdbe *v = pParse->pVdbe;
149827 if( pParse->nErr ) return 1;
149828 assert( v );
149829 for(k=sqlite3VdbeCurrentAddr(v)-1; k>0; k--){
149830 const VdbeOp *pOp = sqlite3VdbeGetOp(v, k);
149831 const KeyInfo *pKeyInfo;
149832 if( pOp->p1!=iCur ) continue;
149833 if( pOp->opcode!=OP_OpenRead
149834 && pOp->opcode!=OP_OpenWrite
149835 && pOp->opcode!=OP_OpenEphemeral
149836 ){
149837 continue;
149838 }
149839 assert( pOp->p4type==P4_KEYINFO );
149840 pKeyInfo = (const KeyInfo*)pOp->p4.pKeyInfo;
149841 assert( pKeyInfo!=0 );
149842 for(i=0; i<nCol; i++){
149843 assert( sqlite3IsBinary(pKeyInfo->aColl[i]) );
149844 }
149845 return 1;
149846 }
149847 return 0;
149848 }
149849 #endif /* SQLITE_DEBUG */
149850
149851
149852 /*
149853 ** This routine generates the code for the inside of the inner loop
149854 ** of a SELECT.
149855 **
@@ -149930,10 +150117,11 @@
150117 assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
150118 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
150119 r1, pDest->zAffSdst, nResultCol);
150120 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
150121 if( pDest->iSDParm2 ){
150122 assert( sqlite3CursorBloomable(pParse,iParm,nResultCol) );
150123 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
150124 regResult, nResultCol);
150125 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
150126 }
150127 sqlite3ReleaseTempReg(pParse, r1);
@@ -151739,10 +151927,11 @@
151927 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
151928 r1, pDest->zAffSdst, pIn->nSdst);
151929 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
151930 pIn->iSdst, pIn->nSdst);
151931 if( pDest->iSDParm2>0 ){
151932 assert( sqlite3CursorBloomable(pParse, pDest->iSDParm, pIn->nSdst) );
151933 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
151934 pIn->iSdst, pIn->nSdst);
151935 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
151936 }
151937 sqlite3ReleaseTempReg(pParse, r1);
@@ -155688,11 +155877,12 @@
155877 assert( ExprUseXList(pExpr) );
155878 if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
155879 if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
155880 if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
155881 pFrom = p->pSrc->a;
155882 if( pFrom->fg.isSubquery==0 ) return 0; /* FROM is a subquery */
155883 if( (p->selFlags & SF_Correlated)!=0 ) return 0; /* Not a correlated subq */
155884 pSub = pFrom->u4.pSubq->pSelect;
155885 if( pSub->pPrior==0 ) return 0; /* Must be a compound */
155886 if( pSub->selFlags & SF_CopyCte ) return 0; /* Not a CTE */
155887 do{
155888 if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */
@@ -157919,12 +158109,13 @@
158109 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
158110 if( !IN_RENAME_OBJECT ){
158111 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),zName) ){
158112 if( !noErr ){
158113 sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
158114 }else if( db->init.busy ){
158115 sqlite3ErrorMsg(pParse,""); /* Err msg generated by corruptSchema() */
158116 }else{
 
158117 sqlite3CodeVerifySchema(pParse, iDb);
158118 VVA_ONLY( pParse->ifNotExists = 1; )
158119 }
158120 goto trigger_cleanup;
158121 }
@@ -163424,14 +163615,11 @@
163615 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
163616 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*);
163617 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
163618 SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
163619 SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*);
163620 SQLITE_PRIVATE int sqlite3WhereLoopBloomable(const WhereLoop*);
 
 
 
163621
163622 /*
163623 ** Bitmasks for the operators on WhereTerm objects. These are all
163624 ** operators that are of interest to the query planner. An
163625 ** OR-ed combination of these values can be used when searching for
@@ -164896,10 +165084,11 @@
165084 testcase( pTerm->wtFlags & TERM_VIRTUAL );
165085 regRowid = sqlite3GetTempReg(pParse);
165086 regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid);
165087 sqlite3VdbeAddOp2(pParse->pVdbe, OP_MustBeInt, regRowid, addrNxt);
165088 VdbeCoverage(pParse->pVdbe);
165089 assert( sqlite3WhereLoopBloomable(pLoop) );
165090 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
165091 addrNxt, regRowid, 1);
165092 VdbeCoverage(pParse->pVdbe);
165093 }else{
165094 u16 nEq = pLoop->u.btree.nEq;
@@ -164909,10 +165098,11 @@
165098 assert( pLoop->wsFlags & WHERE_INDEXED );
165099 assert( (pLoop->wsFlags & WHERE_COLUMN_IN)==0 );
165100 r1 = codeAllEqualityTerms(pParse,pLevel,0,0,&zStartAff);
165101 codeApplyAffinity(pParse, r1, nEq, zStartAff);
165102 sqlite3DbFree(pParse->db, zStartAff);
165103 assert( sqlite3WhereLoopBloomable(pLoop) );
165104 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
165105 addrNxt, r1, nEq);
165106 VdbeCoverage(pParse->pVdbe);
165107 }
165108 pLevel->regFilter = 0;
@@ -165512,10 +165702,11 @@
165702 if( regBignull ){
165703 sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
165704 VdbeComment((v, "NULL-scan pass ctr"));
165705 }
165706 if( pLevel->regFilter ){
165707 assert( sqlite3WhereLoopBloomable(pLoop) );
165708 sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt,
165709 regBase, nEq);
165710 VdbeCoverage(v);
165711 filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady);
165712 }
@@ -166249,12 +166440,14 @@
166440 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, 0, r+1, nPk);
166441 VdbeCoverage(v);
166442 VdbeComment((v, "match against %s", pTab->zName));
166443 sqlite3VdbeAddOp3(v, OP_MakeRecord, r+1, nPk, r);
166444 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pRJ->iMatch, r, r+1, nPk);
166445 if( pRJ->regBloom ){
166446 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r+1, nPk);
166447 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
166448 }
166449 sqlite3VdbeJumpHere(v, jmp1);
166450 sqlite3ReleaseTempRange(pParse, r, nPk+1);
166451 }
166452
166453 /* For a LEFT OUTER JOIN, generate code that will record the fact that
@@ -166402,11 +166595,11 @@
166595 WHERE_RIGHT_JOIN, 0);
166596 if( pSubWInfo ){
166597 int iCur = pLevel->iTabCur;
166598 int r = ++pParse->nMem;
166599 int nPk;
166600 int jmp = 0;
166601 int addrCont = sqlite3WhereContinueLabel(pSubWInfo);
166602 Table *pTab = pTabItem->pSTab;
166603 if( HasRowid(pTab) ){
166604 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, -1, r);
166605 nPk = 1;
@@ -166418,15 +166611,17 @@
166611 for(iPk=0; iPk<nPk; iPk++){
166612 int iCol = pPk->aiColumn[iPk];
166613 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+iPk);
166614 }
166615 }
166616 if( pRJ->regBloom ){
166617 jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
166618 VdbeCoverage(v);
166619 }
166620 sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, addrCont, r, nPk);
166621 VdbeCoverage(v);
166622 if( jmp ) sqlite3VdbeJumpHere(v, jmp);
166623 sqlite3VdbeAddOp2(v, OP_Gosub, pRJ->regReturn, pRJ->addrSubrtn);
166624 sqlite3WhereEnd(pSubWInfo);
166625 }
166626 sqlite3ExprDelete(pParse->db, pSubWhere);
166627 ExplainQueryPlanPop(pParse);
@@ -168414,10 +168609,20 @@
168609 }
168610 sqlite3SetJoinExpr(pTerm, pItem->iCursor, joinType);
168611 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
168612 }
168613 }
168614
168615 /*
168616 ** Return true if the WhereLoop pLoop can be use a Bloom filter.
168617 ** tag-202607231411
168618 */
168619 SQLITE_PRIVATE int sqlite3WhereLoopBloomable(const WhereLoop *pLoop){
168620 if( pLoop->wsFlags & WHERE_IPK ) return 1;
168621 if( NEVER((pLoop->wsFlags & WHERE_INDEXED)==0) ) return 0;
168622 return sqlite3IndexBloomable(pLoop->u.btree.pIndex, pLoop->u.btree.nEq);
168623 }
168624
168625 /************** End of whereexpr.c *******************************************/
168626 /************** Begin file where.c *******************************************/
168627 /*
168628 ** 2001 September 15
@@ -169426,11 +169631,11 @@
169631 WhereLoop *pLoop; /* The Loop object */
169632 char *zNotUsed; /* Extra space on the end of pIdx */
169633 Bitmask idxCols; /* Bitmap of columns used for indexing */
169634 Bitmask extraCols; /* Bitmap of additional columns */
169635 u8 sentWarning = 0; /* True if a warning has been issued */
169636 u8 useBloomFilter = 1; /* True to also add a Bloom filter */
169637 Expr *pPartial = 0; /* Partial Index Expression */
169638 int iContinue = 0; /* Jump here to skip excluded rows */
169639 SrcList *pTabList; /* The complete FROM clause */
169640 SrcItem *pSrc; /* The FROM clause term to get the next index */
169641 int addrCounter = 0; /* Address where integer counter is initialized */
@@ -169553,22 +169758,17 @@
169758 Expr *pX = pTerm->pExpr;
169759 idxCols |= cMask;
169760 pIdx->aiColumn[n] = pTerm->u.x.leftColumn;
169761 pColl = sqlite3ExprCompareCollSeq(pParse, pX);
169762 assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
169763 if( !sqlite3IsBinary(pColl) ){
169764 /* Disallow the use of a Bloom filter if any non-BINARY collating
169765 ** sequence is involved. tag-202607231411 */
169766 useBloomFilter = 0;
169767 }
169768 pIdx->azColl[n] = pColl ? pColl->zName : sqlite3StrBINARY;
169769 n++;
 
 
 
 
 
 
 
 
 
 
169770 }
169771 }
169772 }
169773 assert( (u32)n==pLoop->u.btree.nEq );
169774
@@ -169634,10 +169834,11 @@
169834 regRecord = sqlite3GetTempReg(pParse);
169835 regBase = sqlite3GenerateIndexKey(
169836 pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
169837 );
169838 if( pLevel->regFilter ){
169839 assert( sqlite3WhereLoopBloomable(pLoop) );
169840 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
169841 regBase, pLoop->u.btree.nEq);
169842 }
169843 sqlite3VdbeScanStatusCounters(v, addrExp, addrExp, sqlite3VdbeCurrentAddr(v));
169844 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
@@ -169749,10 +169950,11 @@
169950 if( sz<10000 ){
169951 sz = 10000;
169952 }else if( sz>10000000 ){
169953 sz = 10000000;
169954 }
169955 assert( sqlite3WhereLoopBloomable(pLoop) );
169956 sqlite3VdbeAddOp2(v, OP_Blob, (int)sz, pLevel->regFilter);
169957
169958 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
169959 pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
169960 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
@@ -169771,10 +169973,11 @@
169973 }else{
169974 Index *pIdx = pLoop->u.btree.pIndex;
169975 int n = pLoop->u.btree.nEq;
169976 int r1 = sqlite3GetTempRange(pParse, n);
169977 int jj;
169978 assert( pIdx!=0 );
169979 for(jj=0; jj<n; jj++){
169980 assert( pIdx->pTable==pItem->pSTab );
169981 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iCur, jj, r1+jj);
169982 }
169983 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n);
@@ -173427,11 +173630,11 @@
173630 }
173631 #ifndef SQLITE_OMIT_VIRTUALTABLE
173632 if( IsVirtual(pItem->pSTab) ){
173633 SrcItem *p;
173634 for(p=&pItem[1]; p<pEnd; p++){
173635 if( (p->fg.jointype & (JT_OUTER|JT_CROSS)) ){
173636 mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
173637 }
173638 }
173639 rc = whereLoopAddVirtual(pBuilder, mPrereq, mUnusable);
173640 }else
@@ -175057,23 +175260,21 @@
175260 Table *pTab = pItem->pSTab;
175261 if( (pTab->tabFlags & TF_HasStat1)==0 ) break;
175262 pTab->tabFlags |= TF_MaybeReanalyze;
175263 if( i>=1
175264 && (pLoop->wsFlags & reqFlags)==reqFlags
175265 && sqlite3WhereLoopBloomable(pLoop)
175266 && nSearch > pTab->nRowLogEst
175267 ){
175268 testcase( pItem->fg.jointype & JT_LEFT );
175269 pLoop->wsFlags |= WHERE_BLOOMFILTER;
175270 pLoop->wsFlags &= ~WHERE_IDX_ONLY;
175271 WHERETRACE(0xffffffff, (
175272 "-> use Bloom-filter on loop %c because there are ~%.1e "
175273 "lookups into %s which has only ~%.1e rows\n",
175274 pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName,
175275 (double)sqlite3LogEstToInt(pTab->nRowLogEst)));
 
 
175276 }
175277 nSearch += pLoop->nOut;
175278 }
175279 }
175280
@@ -175819,19 +176020,19 @@
176020 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
176021 if( (pTabItem->fg.jointype & JT_RIGHT)!=0
176022 && (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
176023 ){
176024 WhereRightJoin *pRJ = pLevel->pRJ;
176025 int bBloomable = 0;
176026 pRJ->iMatch = pParse->nTab++;
 
 
176027 pRJ->regReturn = ++pParse->nMem;
176028 sqlite3VdbeAddOp2(v, OP_Null, 0, pRJ->regReturn);
176029 assert( pTab==pTabItem->pSTab );
176030 if( HasRowid(pTab) ){
176031 KeyInfo *pInfo;
176032 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRJ->iMatch, 1);
176033 bBloomable = 1;
176034 pInfo = sqlite3KeyInfoAlloc(pParse->db, 1, 0);
176035 if( pInfo ){
176036 pInfo->aColl[0] = 0;
176037 pInfo->aSortFlags[0] = 0;
176038 sqlite3VdbeAppendP4(v, pInfo, P4_KEYINFO);
@@ -175838,10 +176039,17 @@
176039 }
176040 }else{
176041 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
176042 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRJ->iMatch, pPk->nKeyCol);
176043 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
176044 bBloomable = sqlite3IndexBloomable(pPk,pPk->nKeyCol);
176045 }
176046 if( bBloomable ){
176047 pRJ->regBloom = ++pParse->nMem;
176048 sqlite3VdbeAddOp2(v, OP_Blob, 65536, pRJ->regBloom);
176049 }else{
176050 pRJ->regBloom = 0;
176051 }
176052 pLoop->wsFlags &= ~WHERE_IDX_ONLY;
176053 /* The nature of RIGHT JOIN processing is such that it messes up
176054 ** the output order. So omit any ORDER BY/GROUP BY elimination
176055 ** optimizations. We need to do an actual sort for RIGHT JOIN. */
@@ -187183,67 +187391,64 @@
187391 SQLITE_API char *sqlite3_data_directory = 0;
187392
187393 /*
187394 ** Initialize SQLite.
187395 **
187396 ** The sqlite3_initialize() routine must be called to initialize the
187397 ** memory allocation, VFS, and mutex subsystems prior to doing any
187398 ** serious work. As long as you do not compile with SQLITE_OMIT_AUTOINIT
187399 ** this routine will be called automatically by key routines such as
187400 ** sqlite3_open().
187401 **
187402 ** This routine is a no-op except on its very first call for the process,
187403 ** or for the first call after a call to sqlite3_shutdown. Most calls
187404 ** to sqlite3_initialize() are, in fact, no-ops. For that reason, the
187405 ** routine is broken into two pieces:
187406 **
187407 ** sqlite3Initialize() Does the actual work of initialization
187408 **
187409 ** sqlite3_initialize() Checks to see if initialization is needed
187410 ** and invokes sqlite3Initialize() if it is.
187411 **
187412 ** The sqlite3_initialize() interface is called frequently, but
187413 ** sqlite3Initialize() runs rarely. The function is broken up this way
187414 ** to avoid wasting CPU cycles with unnecessary stack setup for local
187415 ** variables in cases where it is not needed.
187416 **
187417 ** The first thread to call sqlite3_initialize() runs the initialization to
187418 ** completion. If subsequent threads call sqlite3_initialize() before the first
187419 ** thread has finished the initialization process, then the subsequent
187420 ** threads must block until the first thread finishes with the initialization.
187421 **
187422 ** The first thread might call this routine recursively. Recursive
187423 ** calls to this routine should not block, of course. Otherwise the
187424 ** initialization process would never complete.
187425 **
187426 ** Let X be the first thread to enter sqlite3_initialize(). Let Y be some
187427 ** other thread. While the initial invocation of sqlite3_initialize() by X
187428 ** is incomplete, it is required that:
187429 **
187430 ** * Calls to sqlite3_initialize() from Y must block until the outer-most
187431 ** call by X completes.
187432 **
187433 ** * Recursive calls to sqlite3_initialize() from thread X return
187434 ** immediately without blocking.
187435 */
187436 static SQLITE_NOINLINE int sqlite3Initialize(void){
187437 MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
187438 int rc; /* Result code */
187439 #ifdef SQLITE_EXTRA_INIT
187440 int bRunExtraInit = 0; /* Extra initialization needed */
 
 
 
 
 
 
 
187441 #endif
187442
187443 /* If the following assert() fails on some obscure processor/compiler
187444 ** combination to warn that SQLite has been mis-compiled. If you hit
187445 ** this assert(), that means you need to recompile with the
187446 ** -DSQLITE_PTRSIZE=n compile-time option to set the correct pointer size.
187447 */
187448 assert( SQLITE_PTRSIZE==sizeof(char*) );
187449
 
 
 
 
 
 
 
 
 
 
187450 /* Make sure the mutex subsystem is initialized. If unable to
187451 ** initialize the mutex subsystem, return early with the error.
187452 ** If the system is so sick that we are unable to allocate a mutex,
187453 ** there is not much SQLite is going to be able to do.
187454 **
@@ -187383,10 +187588,30 @@
187588 int SQLITE_EXTRA_INIT(const char*);
187589 rc = SQLITE_EXTRA_INIT(0);
187590 }
187591 #endif
187592 return rc;
187593 }
187594 SQLITE_API int sqlite3_initialize(void){
187595 /* If this build does not support writable static data (WSD) natively
187596 ** then we have to invoke the (application-supplied) WSD initialization
187597 ** routine before doing anything else. */
187598 #ifdef SQLITE_OMIT_WSD
187599 rc = sqlite3_wsd_init(4096, 24);
187600 if( rc!=SQLITE_OK ){
187601 return rc;
187602 }
187603 #endif
187604
187605 if( sqlite3GlobalConfig.isInit ){
187606 /* SQLite has already been initialized. Fast early-out. */
187607 sqlite3MemoryBarrier();
187608 return SQLITE_OK;
187609 }else{
187610 /* Invoke sqlite3Initialize() to do the actual work. */
187611 return sqlite3Initialize();
187612 }
187613 }
187614
187615 /*
187616 ** Undo the effects of sqlite3_initialize(). Must not be called while
187617 ** there are outstanding database connections or memory allocations or
@@ -189999,10 +190224,11 @@
190224 SQLITE_MAX_LIKE_PATTERN_LENGTH,
190225 SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
190226 SQLITE_MAX_TRIGGER_DEPTH,
190227 SQLITE_MAX_WORKER_THREADS,
190228 SQLITE_MAX_PARSER_DEPTH,
190229 SQLITE_MAX_SCHEMA,
190230 };
190231
190232 /*
190233 ** Make sure the hard limits are set to reasonable values
190234 */
@@ -190081,11 +190307,12 @@
190307 assert( aHardLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]==
190308 SQLITE_MAX_LIKE_PATTERN_LENGTH );
190309 assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
190310 assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
190311 assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
190312 assert( aHardLimit[SQLITE_LIMIT_SCHEMA]==SQLITE_MAX_SCHEMA );
190313 assert( SQLITE_LIMIT_SCHEMA==(SQLITE_N_LIMIT-1) );
190314
190315
190316 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
190317 return -1;
190318 }
@@ -213541,11 +213768,11 @@
213768 /*
213769 ** Expand pParse->aBlob so that it holds at least N bytes.
213770 **
213771 ** Return the number of errors.
213772 */
213773 static int jsonBlobExpand(JsonParse *pParse, u64 N){
213774 u8 *aNew;
213775 u64 t;
213776 assert( N>pParse->nBlobAlloc );
213777 if( pParse->nBlobAlloc==0 ){
213778 t = 100;
@@ -213569,11 +213796,11 @@
213796 **
213797 ** Return true on success. Return false on OOM.
213798 */
213799 static int jsonBlobMakeEditable(JsonParse *pParse, u32 nExtra){
213800 u8 *aOld;
213801 u64 nSize;
213802 assert( !pParse->bReadOnly );
213803 if( pParse->oom ) return 0;
213804 if( pParse->nBlobAlloc>0 ) return 1;
213805 aOld = pParse->aBlob;
213806 nSize = pParse->nBlob + nExtra;
@@ -213590,11 +213817,11 @@
213817 */
213818 static SQLITE_NOINLINE void jsonBlobExpandAndAppendOneByte(
213819 JsonParse *pParse,
213820 u8 c
213821 ){
213822 jsonBlobExpand(pParse, (u64)pParse->nBlob+1);
213823 if( pParse->oom==0 ){
213824 assert( pParse->nBlob+1<=pParse->nBlobAlloc );
213825 pParse->aBlob[pParse->nBlob++] = c;
213826 }
213827 }
@@ -213617,11 +213844,11 @@
213844 JsonParse *pParse,
213845 u8 eType,
213846 u64 szPayload,
213847 const void *aPayload
213848 ){
213849 if( jsonBlobExpand(pParse, (u64)pParse->nBlob+(u64)szPayload+9) ) return;
213850 jsonBlobAppendNode(pParse, eType, szPayload, aPayload);
213851 }
213852
213853
213854 /* Append a node type byte together with the payload size and
@@ -213707,11 +213934,11 @@
213934 }else{
213935 nNeeded = 4;
213936 }
213937 delta = nNeeded - nExtra;
213938 if( delta ){
213939 u64 newSize = (u64)pParse->nBlob + delta;
213940 if( delta>0 ){
213941 if( newSize>pParse->nBlobAlloc && jsonBlobExpand(pParse, newSize) ){
213942 return 0; /* OOM error. Error state recorded in pParse->oom. */
213943 }
213944 a = &pParse->aBlob[i];
@@ -215055,11 +215282,11 @@
215282 ){
215283 return;
215284 }
215285 if( d!=0 ){
215286 if( pParse->nBlob + d > pParse->nBlobAlloc ){
215287 jsonBlobExpand(pParse, (u64)pParse->nBlob+d);
215288 if( pParse->oom ) return;
215289 }
215290 memmove(&pParse->aBlob[iDel+nIns],
215291 &pParse->aBlob[iDel+nDel],
215292 pParse->nBlob - (iDel+nDel));
@@ -251402,10 +251629,11 @@
251629 i64 szData = (sizeof(Fts5Data) + 7) & ~7;
251630 i64 nAlloc = szData + nByte + FTS5_DATA_PADDING;
251631 pRet = (Fts5Data*)sqlite3_malloc64(nAlloc);
251632 if( pRet ){
251633 pRet->nn = nByte;
251634 pRet->szLeaf = 0;
251635 aOut = pRet->p = (u8*)pRet + szData;
251636 }else{
251637 rc = SQLITE_NOMEM;
251638 }
251639
@@ -251414,14 +251642,12 @@
251642 }
251643 if( rc!=SQLITE_OK ){
251644 sqlite3_free(pRet);
251645 pRet = 0;
251646 }else{
 
251647 pRet->p[nByte] = 0x00;
251648 pRet->p[nByte+1] = 0x00;
 
251649 }
251650 }
251651 p->rc = rc;
251652 p->nRead++;
251653 }
@@ -251438,13 +251664,21 @@
251664 */
251665 static void fts5DataRelease(Fts5Data *pData){
251666 sqlite3_free(pData);
251667 }
251668
251669 /*
251670 ** Read a leaf-page record. This is similar to fts5DataRead(), except that
251671 ** it fills in the Fts5Data.szLeaf value before returning.
251672 */
251673 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
251674 Fts5Data *pRet = fts5DataRead(p, iRowid);
251675 if( pRet ){
251676 assert( pRet->szLeaf==0 );
251677 if( pRet->nn>=4 ){
251678 pRet->szLeaf = fts5GetU16(&pRet->p[2]);
251679 }
251680 if( pRet->szLeaf<4 || pRet->szLeaf>pRet->nn ){
251681 FTS5_CORRUPT_ROWID(p, iRowid);
251682 fts5DataRelease(pRet);
251683 pRet = 0;
251684 }
@@ -255681,11 +255915,11 @@
255915 for(pgno=iPgno; p->rc==SQLITE_OK && pgno<=pSeg->pgnoLast; pgno++){
255916 i64 iRowid = FTS5_SEGMENT_ROWID(pSeg->iSegid, pgno);
255917 int iNext = 0;
255918 u8 *aPg = 0;
255919
255920 pLeaf = fts5LeafRead(p, iRowid);
255921 if( pLeaf==0 ) break;
255922 aPg = pLeaf->p;
255923
255924 iNext = fts5GetU16(&aPg[0]);
255925 if( iNext!=0 ){
@@ -255976,19 +256210,19 @@
256210
256211 assert_nc( pSeg->iLeafPgno>pSeg->iTermLeafPgno );
256212 /* The entry being removed may be the only position list in
256213 ** its doclist. */
256214 for(iPgno=pSeg->iLeafPgno-1; iPgno>pSeg->iTermLeafPgno; iPgno-- ){
256215 Fts5Data *pPg = fts5LeafRead(p, FTS5_SEGMENT_ROWID(iSegid, iPgno));
256216 int bEmpty = (pPg && pPg->nn==4);
256217 fts5DataRelease(pPg);
256218 if( bEmpty==0 ) break;
256219 }
256220
256221 if( iPgno==pSeg->iTermLeafPgno ){
256222 i64 iId = FTS5_SEGMENT_ROWID(iSegid, pSeg->iTermLeafPgno);
256223 Fts5Data *pTerm = fts5LeafRead(p, iId);
256224 if( pTerm && pTerm->szLeaf==pSeg->iTermLeafOffset ){
256225 u8 *aTermIdx = &pTerm->p[pTerm->szLeaf];
256226 int nTermIdx = pTerm->nn - pTerm->szLeaf;
256227 int iTermIdx = 0;
256228 i64 iTermOff = 0;
@@ -258936,11 +259170,11 @@
259170 int i;
259171
259172 /* Now check that the iter.nEmpty leaves following the current leaf
259173 ** (a) exist and (b) contain no terms. */
259174 for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
259175 Fts5Data *pLeaf = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
259176 if( pLeaf ){
259177 if( !fts5LeafIsTermless(pLeaf)
259178 || (i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf))
259179 ){
259180 FTS5_CORRUPT_ROWID(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
@@ -263716,11 +263950,11 @@
263950 int nArg, /* Number of args */
263951 sqlite3_value **apUnused /* Function arguments */
263952 ){
263953 assert( nArg==0 );
263954 UNUSED_PARAM2(nArg, apUnused);
263955 sqlite3_result_text(pCtx, "fts5: 2026-07-24 16:28:47 2f1f4f73535386549c12694dc57cfe555eec689ae6824c6241aaf8d5befcd74d", -1, SQLITE_TRANSIENT);
263956 }
263957
263958 /*
263959 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263960 **
263961
+12 -3
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.54.0"
150150
#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-07-08 15:43:42 c8aa208bf5b00f3ab93c5edd510dfd0d7edd271c064f159616ee409b308f7eb9"
151
+#define SQLITE_SOURCE_ID "2026-07-24 16:28:47 2f1f4f73535386549c12694dc57cfe555eec689ae6824c6241aaf8d5befcd74d"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-07-08T15:43:42.959Z"
154
+#define SQLITE_SCM_DATETIME "2026-07-24T16:28:47.830Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -4430,10 +4430,14 @@
44304430
** nesting depth for separate triggers.</dd>)^
44314431
**
44324432
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
44334433
** <dd>The maximum number of auxiliary worker threads that a single
44344434
** [prepared statement] may start.</dd>)^
4435
+**
4436
+** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4437
+** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4438
+** defined by the database schema.</dd>)^
44354439
** </dl>
44364440
*/
44374441
#define SQLITE_LIMIT_LENGTH 0
44384442
#define SQLITE_LIMIT_SQL_LENGTH 1
44394443
#define SQLITE_LIMIT_COLUMN 2
@@ -4445,10 +4449,11 @@
44454449
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
44464450
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
44474451
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
44484452
#define SQLITE_LIMIT_WORKER_THREADS 11
44494453
#define SQLITE_LIMIT_PARSER_DEPTH 12
4454
+#define SQLITE_LIMIT_SCHEMA 13
44504455
44514456
/*
44524457
** CAPI3REF: Prepare Flags
44534458
**
44544459
** These constants define various flags that can be passed into the
@@ -6477,11 +6482,15 @@
64776482
** to by the second parameter and which is N bytes long where N is the
64786483
** third parameter.
64796484
**
64806485
** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
64816486
** interfaces set the result of the application-defined function to be
6482
-** a BLOB containing all zero bytes and N bytes in size.
6487
+** a BLOB containing all zero bytes and N bytes in size. The
6488
+** zeroblob64(C,N) interface returns a [result code], which is normally
6489
+** [SQLITE_OK] but might be some other value if the requested operation
6490
+** could not be complete, for example if insufficient memory is available
6491
+** or if the value of N is out of range.
64836492
**
64846493
** ^The sqlite3_result_double() interface sets the result from
64856494
** an application-defined function to be a floating point value specified
64866495
** by its 2nd argument.
64876496
**
64886497
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-07-08 15:43:42 c8aa208bf5b00f3ab93c5edd510dfd0d7edd271c064f159616ee409b308f7eb9"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-07-08T15:43:42.959Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4430,10 +4430,14 @@
4430 ** nesting depth for separate triggers.</dd>)^
4431 **
4432 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4433 ** <dd>The maximum number of auxiliary worker threads that a single
4434 ** [prepared statement] may start.</dd>)^
 
 
 
 
4435 ** </dl>
4436 */
4437 #define SQLITE_LIMIT_LENGTH 0
4438 #define SQLITE_LIMIT_SQL_LENGTH 1
4439 #define SQLITE_LIMIT_COLUMN 2
@@ -4445,10 +4449,11 @@
4445 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
4446 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
4447 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
4448 #define SQLITE_LIMIT_WORKER_THREADS 11
4449 #define SQLITE_LIMIT_PARSER_DEPTH 12
 
4450
4451 /*
4452 ** CAPI3REF: Prepare Flags
4453 **
4454 ** These constants define various flags that can be passed into the
@@ -6477,11 +6482,15 @@
6477 ** to by the second parameter and which is N bytes long where N is the
6478 ** third parameter.
6479 **
6480 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
6481 ** interfaces set the result of the application-defined function to be
6482 ** a BLOB containing all zero bytes and N bytes in size.
 
 
 
 
6483 **
6484 ** ^The sqlite3_result_double() interface sets the result from
6485 ** an application-defined function to be a floating point value specified
6486 ** by its 2nd argument.
6487 **
6488
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-07-24 16:28:47 2f1f4f73535386549c12694dc57cfe555eec689ae6824c6241aaf8d5befcd74d"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-07-24T16:28:47.830Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4430,10 +4430,14 @@
4430 ** nesting depth for separate triggers.</dd>)^
4431 **
4432 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4433 ** <dd>The maximum number of auxiliary worker threads that a single
4434 ** [prepared statement] may start.</dd>)^
4435 **
4436 ** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4437 ** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4438 ** defined by the database schema.</dd>)^
4439 ** </dl>
4440 */
4441 #define SQLITE_LIMIT_LENGTH 0
4442 #define SQLITE_LIMIT_SQL_LENGTH 1
4443 #define SQLITE_LIMIT_COLUMN 2
@@ -4445,10 +4449,11 @@
4449 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
4450 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
4451 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
4452 #define SQLITE_LIMIT_WORKER_THREADS 11
4453 #define SQLITE_LIMIT_PARSER_DEPTH 12
4454 #define SQLITE_LIMIT_SCHEMA 13
4455
4456 /*
4457 ** CAPI3REF: Prepare Flags
4458 **
4459 ** These constants define various flags that can be passed into the
@@ -6477,11 +6482,15 @@
6482 ** to by the second parameter and which is N bytes long where N is the
6483 ** third parameter.
6484 **
6485 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
6486 ** interfaces set the result of the application-defined function to be
6487 ** a BLOB containing all zero bytes and N bytes in size. The
6488 ** zeroblob64(C,N) interface returns a [result code], which is normally
6489 ** [SQLITE_OK] but might be some other value if the requested operation
6490 ** could not be complete, for example if insufficient memory is available
6491 ** or if the value of N is out of range.
6492 **
6493 ** ^The sqlite3_result_double() interface sets the result from
6494 ** an application-defined function to be a floating point value specified
6495 ** by its 2nd argument.
6496 **
6497

Keyboard Shortcuts

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