Fossil SCM

Update the built-in SQLite to the latest 3.41.0 alpha version in order to silence harmless compiler warnings and for general testing of SQLite.

drh 2023-01-16 18:14 trunk
Commit cdd89e2dbe65908ca6a1d399b956ebb46f0acb5b5e4de841e7c54e5cfbdb813a
3 files changed +47 -17 +379 -144 +45 -14
+47 -17
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -182,10 +182,18 @@
182182
# define shell_stifle_history(X)
183183
184184
# define SHELL_USE_LOCAL_GETLINE 1
185185
#endif
186186
187
+#ifndef deliberate_fall_through
188
+/* Quiet some compilers about some of our intentional code. */
189
+# if GCC_VERSION>=7000000
190
+# define deliberate_fall_through __attribute__((fallthrough));
191
+# else
192
+# define deliberate_fall_through
193
+# endif
194
+#endif
187195
188196
#if defined(_WIN32) || defined(WIN32)
189197
# if SQLITE_OS_WINRT
190198
# define SQLITE_OMIT_POPEN 1
191199
# else
@@ -488,10 +496,22 @@
488496
#define PROMPT_LEN_MAX 20
489497
/* First line prompt. default: "sqlite> " */
490498
static char mainPrompt[PROMPT_LEN_MAX];
491499
/* Continuation prompt. default: " ...> " */
492500
static char continuePrompt[PROMPT_LEN_MAX];
501
+
502
+/* This is variant of the standard-library strncpy() routine with the
503
+** one change that the destination string is always zero-terminated, even
504
+** if there is no zero-terminator in the first n-1 characters of the source
505
+** string.
506
+*/
507
+static char *shell_strncpy(char *dest, const char *src, size_t n){
508
+ size_t i;
509
+ for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i];
510
+ dest[i] = 0;
511
+ return dest;
512
+}
493513
494514
/*
495515
** Optionally disable dynamic continuation prompt.
496516
** Unless disabled, the continuation prompt shows open SQL lexemes if any,
497517
** or open parentheses level if non-zero, or continuation prompt as set.
@@ -556,22 +576,22 @@
556576
size_t ncp = strlen(continuePrompt);
557577
size_t ndp = strlen(dynPrompt.zScannerAwaits);
558578
if( ndp > ncp-3 ) return continuePrompt;
559579
strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
560580
while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
561
- strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
581
+ shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
562582
PROMPT_LEN_MAX-4);
563583
}else{
564584
if( dynPrompt.inParenLevel>9 ){
565
- strncpy(dynPrompt.dynamicPrompt, "(..", 4);
585
+ shell_strncpy(dynPrompt.dynamicPrompt, "(..", 4);
566586
}else if( dynPrompt.inParenLevel<0 ){
567
- strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
587
+ shell_strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
568588
}else{
569
- strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
589
+ shell_strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
570590
dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
571591
}
572
- strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
592
+ shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
573593
}
574594
}
575595
return dynPrompt.dynamicPrompt;
576596
}
577597
#endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
@@ -3129,10 +3149,19 @@
31293149
*/
31303150
31313151
#include <assert.h>
31323152
31333153
/* #include "sqlite3ext.h" */
3154
+
3155
+#ifndef deliberate_fall_through
3156
+/* Quiet some compilers about some of our intentional code. */
3157
+# if GCC_VERSION>=7000000
3158
+# define deliberate_fall_through __attribute__((fallthrough));
3159
+# else
3160
+# define deliberate_fall_through
3161
+# endif
3162
+#endif
31343163
31353164
SQLITE_EXTENSION_INIT1;
31363165
31373166
#define PC 0x80 /* pad character */
31383167
#define WS 0x81 /* whitespace */
@@ -3240,19 +3269,19 @@
32403269
u8 bdp = BX_DV_PROTO(c);
32413270
switch( bdp ){
32423271
case ND:
32433272
/* Treat dark non-digits as pad, but they terminate decode too. */
32443273
ncIn = 0;
3245
- /* fall thru */
3274
+ deliberate_fall_through;
32463275
case WS:
32473276
/* Treat whitespace as pad and terminate this group.*/
32483277
nti = nac;
3249
- /* fall thru */
3278
+ deliberate_fall_through;
32503279
case PC:
32513280
bdp = 0;
32523281
--nbo;
3253
- /* fall thru */
3282
+ deliberate_fall_through;
32543283
default: /* bdp is the digit value. */
32553284
qv = qv<<6 | bdp;
32563285
break;
32573286
}
32583287
}
@@ -8929,11 +8958,11 @@
89298958
}else{
89308959
zFile = (const char*)sqlite3_value_text(argv[0]);
89318960
}
89328961
89338962
if( 0==pTab->pWriteFd && 0==bInMemory ){
8934
- pCsr->pFile = fopen(zFile, "rb");
8963
+ pCsr->pFile = zFile ? fopen(zFile, "rb") : 0;
89358964
if( pCsr->pFile==0 ){
89368965
zipfileCursorErr(pCsr, "cannot open file: %s", zFile);
89378966
rc = SQLITE_ERROR;
89388967
}else{
89398968
rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd);
@@ -9959,19 +9988,20 @@
99599988
if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){
99609989
sqlite3_result_value(context, argv[0]);
99619990
}else{
99629991
const Bytef *pData= sqlite3_value_blob(argv[0]);
99639992
Bytef *pOut = sqlite3_malloc(sz);
9964
- if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){
9993
+ if( pOut==0 ){
9994
+ sqlite3_result_error_nomem(context);
9995
+ }else if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){
99659996
sqlite3_result_error(context, "error in uncompress()", -1);
99669997
}else{
99679998
sqlite3_result_blob(context, pOut, sz, SQLITE_TRANSIENT);
99689999
}
996910000
sqlite3_free(pOut);
997010001
}
997110002
}
9972
-
997310003
997410004
#ifdef _WIN32
997510005
997610006
#endif
997710007
int sqlite3_sqlar_init(
@@ -19815,11 +19845,11 @@
1981519845
" --quiet|-q No output except at interrupts",
1981619846
" --reset Reset the count for each input and interrupt",
1981719847
#endif
1981819848
".prompt MAIN CONTINUE Replace the standard prompts",
1981919849
#ifndef SQLITE_SHELL_FIDDLE
19820
- ".quit Exit this program",
19850
+ ".quit Stop interpreting input stream, exit if primary.",
1982119851
".read FILE Read input from FILE or command output",
1982219852
" If FILE begins with \"|\", it is a command that generates the input.",
1982319853
#endif
1982419854
#if SQLITE_SHELL_HAVE_RECOVER
1982519855
".recover Recover as much data as possible from corrupt db.",
@@ -21973,11 +22003,11 @@
2197322003
case AR_SWITCH_VERBOSE:
2197422004
pAr->bVerbose = 1;
2197522005
break;
2197622006
case AR_SWITCH_APPEND:
2197722007
pAr->bAppend = 1;
21978
- /* Fall thru into --file */
22008
+ deliberate_fall_through;
2197922009
case AR_SWITCH_FILE:
2198022010
pAr->zFile = zArg;
2198122011
break;
2198222012
case AR_SWITCH_DIRECTORY:
2198322013
pAr->zDir = zArg;
@@ -24757,14 +24787,14 @@
2475724787
}else
2475824788
#endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
2475924789
2476024790
if( c=='p' && cli_strncmp(azArg[0], "prompt", n)==0 ){
2476124791
if( nArg >= 2) {
24762
- strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
24792
+ shell_strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
2476324793
}
2476424794
if( nArg >= 3) {
24765
- strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
24795
+ shell_strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
2476624796
}
2476724797
}else
2476824798
2476924799
#ifndef SQLITE_SHELL_FIDDLE
2477024800
if( c=='q' && cli_strncmp(azArg[0], "quit", n)==0 ){
@@ -26301,11 +26331,11 @@
2630126331
goto TermScan;
2630226332
}
2630326333
break;
2630426334
case '[':
2630526335
cin = ']';
26306
- /* fall thru */
26336
+ deliberate_fall_through;
2630726337
case '`': case '\'': case '"':
2630826338
cWait = cin;
2630926339
qss = QSS_HasDark | cWait;
2631026340
CONTINUE_PROMPT_AWAITC(pst, cin);
2631126341
goto TermScan;
@@ -26337,11 +26367,11 @@
2633726367
if(*zLine==cWait){
2633826368
/* Swallow doubled end-delimiter.*/
2633926369
++zLine;
2634026370
continue;
2634126371
}
26342
- /* fall thru */
26372
+ deliberate_fall_through;
2634326373
case ']':
2634426374
cWait = 0;
2634526375
CONTINUE_PROMPT_AWAITC(pst, 0);
2634626376
qss = QSS_SETV(qss, 0);
2634726377
goto PlainScan;
2634826378
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -182,10 +182,18 @@
182 # define shell_stifle_history(X)
183
184 # define SHELL_USE_LOCAL_GETLINE 1
185 #endif
186
 
 
 
 
 
 
 
 
187
188 #if defined(_WIN32) || defined(WIN32)
189 # if SQLITE_OS_WINRT
190 # define SQLITE_OMIT_POPEN 1
191 # else
@@ -488,10 +496,22 @@
488 #define PROMPT_LEN_MAX 20
489 /* First line prompt. default: "sqlite> " */
490 static char mainPrompt[PROMPT_LEN_MAX];
491 /* Continuation prompt. default: " ...> " */
492 static char continuePrompt[PROMPT_LEN_MAX];
 
 
 
 
 
 
 
 
 
 
 
 
493
494 /*
495 ** Optionally disable dynamic continuation prompt.
496 ** Unless disabled, the continuation prompt shows open SQL lexemes if any,
497 ** or open parentheses level if non-zero, or continuation prompt as set.
@@ -556,22 +576,22 @@
556 size_t ncp = strlen(continuePrompt);
557 size_t ndp = strlen(dynPrompt.zScannerAwaits);
558 if( ndp > ncp-3 ) return continuePrompt;
559 strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
560 while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
561 strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
562 PROMPT_LEN_MAX-4);
563 }else{
564 if( dynPrompt.inParenLevel>9 ){
565 strncpy(dynPrompt.dynamicPrompt, "(..", 4);
566 }else if( dynPrompt.inParenLevel<0 ){
567 strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
568 }else{
569 strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
570 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
571 }
572 strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
573 }
574 }
575 return dynPrompt.dynamicPrompt;
576 }
577 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
@@ -3129,10 +3149,19 @@
3129 */
3130
3131 #include <assert.h>
3132
3133 /* #include "sqlite3ext.h" */
 
 
 
 
 
 
 
 
 
3134
3135 SQLITE_EXTENSION_INIT1;
3136
3137 #define PC 0x80 /* pad character */
3138 #define WS 0x81 /* whitespace */
@@ -3240,19 +3269,19 @@
3240 u8 bdp = BX_DV_PROTO(c);
3241 switch( bdp ){
3242 case ND:
3243 /* Treat dark non-digits as pad, but they terminate decode too. */
3244 ncIn = 0;
3245 /* fall thru */
3246 case WS:
3247 /* Treat whitespace as pad and terminate this group.*/
3248 nti = nac;
3249 /* fall thru */
3250 case PC:
3251 bdp = 0;
3252 --nbo;
3253 /* fall thru */
3254 default: /* bdp is the digit value. */
3255 qv = qv<<6 | bdp;
3256 break;
3257 }
3258 }
@@ -8929,11 +8958,11 @@
8929 }else{
8930 zFile = (const char*)sqlite3_value_text(argv[0]);
8931 }
8932
8933 if( 0==pTab->pWriteFd && 0==bInMemory ){
8934 pCsr->pFile = fopen(zFile, "rb");
8935 if( pCsr->pFile==0 ){
8936 zipfileCursorErr(pCsr, "cannot open file: %s", zFile);
8937 rc = SQLITE_ERROR;
8938 }else{
8939 rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd);
@@ -9959,19 +9988,20 @@
9959 if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){
9960 sqlite3_result_value(context, argv[0]);
9961 }else{
9962 const Bytef *pData= sqlite3_value_blob(argv[0]);
9963 Bytef *pOut = sqlite3_malloc(sz);
9964 if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){
 
 
9965 sqlite3_result_error(context, "error in uncompress()", -1);
9966 }else{
9967 sqlite3_result_blob(context, pOut, sz, SQLITE_TRANSIENT);
9968 }
9969 sqlite3_free(pOut);
9970 }
9971 }
9972
9973
9974 #ifdef _WIN32
9975
9976 #endif
9977 int sqlite3_sqlar_init(
@@ -19815,11 +19845,11 @@
19815 " --quiet|-q No output except at interrupts",
19816 " --reset Reset the count for each input and interrupt",
19817 #endif
19818 ".prompt MAIN CONTINUE Replace the standard prompts",
19819 #ifndef SQLITE_SHELL_FIDDLE
19820 ".quit Exit this program",
19821 ".read FILE Read input from FILE or command output",
19822 " If FILE begins with \"|\", it is a command that generates the input.",
19823 #endif
19824 #if SQLITE_SHELL_HAVE_RECOVER
19825 ".recover Recover as much data as possible from corrupt db.",
@@ -21973,11 +22003,11 @@
21973 case AR_SWITCH_VERBOSE:
21974 pAr->bVerbose = 1;
21975 break;
21976 case AR_SWITCH_APPEND:
21977 pAr->bAppend = 1;
21978 /* Fall thru into --file */
21979 case AR_SWITCH_FILE:
21980 pAr->zFile = zArg;
21981 break;
21982 case AR_SWITCH_DIRECTORY:
21983 pAr->zDir = zArg;
@@ -24757,14 +24787,14 @@
24757 }else
24758 #endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
24759
24760 if( c=='p' && cli_strncmp(azArg[0], "prompt", n)==0 ){
24761 if( nArg >= 2) {
24762 strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
24763 }
24764 if( nArg >= 3) {
24765 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
24766 }
24767 }else
24768
24769 #ifndef SQLITE_SHELL_FIDDLE
24770 if( c=='q' && cli_strncmp(azArg[0], "quit", n)==0 ){
@@ -26301,11 +26331,11 @@
26301 goto TermScan;
26302 }
26303 break;
26304 case '[':
26305 cin = ']';
26306 /* fall thru */
26307 case '`': case '\'': case '"':
26308 cWait = cin;
26309 qss = QSS_HasDark | cWait;
26310 CONTINUE_PROMPT_AWAITC(pst, cin);
26311 goto TermScan;
@@ -26337,11 +26367,11 @@
26337 if(*zLine==cWait){
26338 /* Swallow doubled end-delimiter.*/
26339 ++zLine;
26340 continue;
26341 }
26342 /* fall thru */
26343 case ']':
26344 cWait = 0;
26345 CONTINUE_PROMPT_AWAITC(pst, 0);
26346 qss = QSS_SETV(qss, 0);
26347 goto PlainScan;
26348
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -182,10 +182,18 @@
182 # define shell_stifle_history(X)
183
184 # define SHELL_USE_LOCAL_GETLINE 1
185 #endif
186
187 #ifndef deliberate_fall_through
188 /* Quiet some compilers about some of our intentional code. */
189 # if GCC_VERSION>=7000000
190 # define deliberate_fall_through __attribute__((fallthrough));
191 # else
192 # define deliberate_fall_through
193 # endif
194 #endif
195
196 #if defined(_WIN32) || defined(WIN32)
197 # if SQLITE_OS_WINRT
198 # define SQLITE_OMIT_POPEN 1
199 # else
@@ -488,10 +496,22 @@
496 #define PROMPT_LEN_MAX 20
497 /* First line prompt. default: "sqlite> " */
498 static char mainPrompt[PROMPT_LEN_MAX];
499 /* Continuation prompt. default: " ...> " */
500 static char continuePrompt[PROMPT_LEN_MAX];
501
502 /* This is variant of the standard-library strncpy() routine with the
503 ** one change that the destination string is always zero-terminated, even
504 ** if there is no zero-terminator in the first n-1 characters of the source
505 ** string.
506 */
507 static char *shell_strncpy(char *dest, const char *src, size_t n){
508 size_t i;
509 for(i=0; i<n-1 && src[i]!=0; i++) dest[i] = src[i];
510 dest[i] = 0;
511 return dest;
512 }
513
514 /*
515 ** Optionally disable dynamic continuation prompt.
516 ** Unless disabled, the continuation prompt shows open SQL lexemes if any,
517 ** or open parentheses level if non-zero, or continuation prompt as set.
@@ -556,22 +576,22 @@
576 size_t ncp = strlen(continuePrompt);
577 size_t ndp = strlen(dynPrompt.zScannerAwaits);
578 if( ndp > ncp-3 ) return continuePrompt;
579 strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
580 while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
581 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
582 PROMPT_LEN_MAX-4);
583 }else{
584 if( dynPrompt.inParenLevel>9 ){
585 shell_strncpy(dynPrompt.dynamicPrompt, "(..", 4);
586 }else if( dynPrompt.inParenLevel<0 ){
587 shell_strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
588 }else{
589 shell_strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
590 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
591 }
592 shell_strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
593 }
594 }
595 return dynPrompt.dynamicPrompt;
596 }
597 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
@@ -3129,10 +3149,19 @@
3149 */
3150
3151 #include <assert.h>
3152
3153 /* #include "sqlite3ext.h" */
3154
3155 #ifndef deliberate_fall_through
3156 /* Quiet some compilers about some of our intentional code. */
3157 # if GCC_VERSION>=7000000
3158 # define deliberate_fall_through __attribute__((fallthrough));
3159 # else
3160 # define deliberate_fall_through
3161 # endif
3162 #endif
3163
3164 SQLITE_EXTENSION_INIT1;
3165
3166 #define PC 0x80 /* pad character */
3167 #define WS 0x81 /* whitespace */
@@ -3240,19 +3269,19 @@
3269 u8 bdp = BX_DV_PROTO(c);
3270 switch( bdp ){
3271 case ND:
3272 /* Treat dark non-digits as pad, but they terminate decode too. */
3273 ncIn = 0;
3274 deliberate_fall_through;
3275 case WS:
3276 /* Treat whitespace as pad and terminate this group.*/
3277 nti = nac;
3278 deliberate_fall_through;
3279 case PC:
3280 bdp = 0;
3281 --nbo;
3282 deliberate_fall_through;
3283 default: /* bdp is the digit value. */
3284 qv = qv<<6 | bdp;
3285 break;
3286 }
3287 }
@@ -8929,11 +8958,11 @@
8958 }else{
8959 zFile = (const char*)sqlite3_value_text(argv[0]);
8960 }
8961
8962 if( 0==pTab->pWriteFd && 0==bInMemory ){
8963 pCsr->pFile = zFile ? fopen(zFile, "rb") : 0;
8964 if( pCsr->pFile==0 ){
8965 zipfileCursorErr(pCsr, "cannot open file: %s", zFile);
8966 rc = SQLITE_ERROR;
8967 }else{
8968 rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd);
@@ -9959,19 +9988,20 @@
9988 if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){
9989 sqlite3_result_value(context, argv[0]);
9990 }else{
9991 const Bytef *pData= sqlite3_value_blob(argv[0]);
9992 Bytef *pOut = sqlite3_malloc(sz);
9993 if( pOut==0 ){
9994 sqlite3_result_error_nomem(context);
9995 }else if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){
9996 sqlite3_result_error(context, "error in uncompress()", -1);
9997 }else{
9998 sqlite3_result_blob(context, pOut, sz, SQLITE_TRANSIENT);
9999 }
10000 sqlite3_free(pOut);
10001 }
10002 }
 
10003
10004 #ifdef _WIN32
10005
10006 #endif
10007 int sqlite3_sqlar_init(
@@ -19815,11 +19845,11 @@
19845 " --quiet|-q No output except at interrupts",
19846 " --reset Reset the count for each input and interrupt",
19847 #endif
19848 ".prompt MAIN CONTINUE Replace the standard prompts",
19849 #ifndef SQLITE_SHELL_FIDDLE
19850 ".quit Stop interpreting input stream, exit if primary.",
19851 ".read FILE Read input from FILE or command output",
19852 " If FILE begins with \"|\", it is a command that generates the input.",
19853 #endif
19854 #if SQLITE_SHELL_HAVE_RECOVER
19855 ".recover Recover as much data as possible from corrupt db.",
@@ -21973,11 +22003,11 @@
22003 case AR_SWITCH_VERBOSE:
22004 pAr->bVerbose = 1;
22005 break;
22006 case AR_SWITCH_APPEND:
22007 pAr->bAppend = 1;
22008 deliberate_fall_through;
22009 case AR_SWITCH_FILE:
22010 pAr->zFile = zArg;
22011 break;
22012 case AR_SWITCH_DIRECTORY:
22013 pAr->zDir = zArg;
@@ -24757,14 +24787,14 @@
24787 }else
24788 #endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
24789
24790 if( c=='p' && cli_strncmp(azArg[0], "prompt", n)==0 ){
24791 if( nArg >= 2) {
24792 shell_strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
24793 }
24794 if( nArg >= 3) {
24795 shell_strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
24796 }
24797 }else
24798
24799 #ifndef SQLITE_SHELL_FIDDLE
24800 if( c=='q' && cli_strncmp(azArg[0], "quit", n)==0 ){
@@ -26301,11 +26331,11 @@
26331 goto TermScan;
26332 }
26333 break;
26334 case '[':
26335 cin = ']';
26336 deliberate_fall_through;
26337 case '`': case '\'': case '"':
26338 cWait = cin;
26339 qss = QSS_HasDark | cWait;
26340 CONTINUE_PROMPT_AWAITC(pst, cin);
26341 goto TermScan;
@@ -26337,11 +26367,11 @@
26367 if(*zLine==cWait){
26368 /* Swallow doubled end-delimiter.*/
26369 ++zLine;
26370 continue;
26371 }
26372 deliberate_fall_through;
26373 case ']':
26374 cWait = 0;
26375 CONTINUE_PROMPT_AWAITC(pst, 0);
26376 qss = QSS_SETV(qss, 0);
26377 goto PlainScan;
26378
+379 -144
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.41.0"
456456
#define SQLITE_VERSION_NUMBER 3041000
457
-#define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7"
457
+#define SQLITE_SOURCE_ID "2023-01-16 18:13:00 83f21285fe86430a66ce6841606e3ad7c27da52ac75a034c6a00c7a9fdb9791d"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -2983,12 +2983,16 @@
29832983
** that are started after the running statement count reaches zero are
29842984
** not effected by the sqlite3_interrupt().
29852985
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
29862986
** SQL statements is a no-op and has no effect on SQL statements
29872987
** that are started after the sqlite3_interrupt() call returns.
2988
+**
2989
+** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2990
+** or not an interrupt is currently in effect for [database connection] D.
29882991
*/
29892992
SQLITE_API void sqlite3_interrupt(sqlite3*);
2993
+SQLITE_API int sqlite3_is_interrupted(sqlite3*);
29902994
29912995
/*
29922996
** CAPI3REF: Determine If An SQL Statement Is Complete
29932997
**
29942998
** These routines are useful during command-line input to determine if the
@@ -3666,11 +3670,11 @@
36663670
** CAPI3REF: Query Progress Callbacks
36673671
** METHOD: sqlite3
36683672
**
36693673
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
36703674
** function X to be invoked periodically during long running calls to
3671
-** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3675
+** [sqlite3_step()] and [sqlite3_prepare()] and similar for
36723676
** database connection D. An example use for this
36733677
** interface is to keep a GUI updated during a large query.
36743678
**
36753679
** ^The parameter P is passed through as the only parameter to the
36763680
** callback function X. ^The parameter N is the approximate number of
@@ -3691,10 +3695,17 @@
36913695
** The progress handler callback must not do anything that will modify
36923696
** the database connection that invoked the progress handler.
36933697
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
36943698
** database connections for the meaning of "modify" in this paragraph.
36953699
**
3700
+** The progress handler callback would originally only be invoked from the
3701
+** bytecode engine. It still might be invoked during [sqlite3_prepare()]
3702
+** and similar because those routines might force a reparse of the schema
3703
+** which involves running the bytecode engine. However, beginning with
3704
+** SQLite version 3.41.0, the progress handler callback might also be
3705
+** invoked directly from [sqlite3_prepare()] while analyzing and generating
3706
+** code for complex queries.
36963707
*/
36973708
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
36983709
36993710
/*
37003711
** CAPI3REF: Opening A New Database Connection
@@ -3727,17 +3738,22 @@
37273738
** sqlite3_open_v2() must include, at a minimum, one of the following
37283739
** three flag combinations:)^
37293740
**
37303741
** <dl>
37313742
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3732
-** <dd>The database is opened in read-only mode. If the database does not
3733
-** already exist, an error is returned.</dd>)^
3743
+** <dd>The database is opened in read-only mode. If the database does
3744
+** not already exist, an error is returned.</dd>)^
37343745
**
37353746
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3736
-** <dd>The database is opened for reading and writing if possible, or reading
3737
-** only if the file is write protected by the operating system. In either
3738
-** case the database must already exist, otherwise an error is returned.</dd>)^
3747
+** <dd>The database is opened for reading and writing if possible, or
3748
+** reading only if the file is write protected by the operating
3749
+** system. In either case the database must already exist, otherwise
3750
+** an error is returned. For historical reasons, if opening in
3751
+** read-write mode fails due to OS-level permissions, an attempt is
3752
+** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3753
+** used to determine whether the database is actually
3754
+** read-write.</dd>)^
37393755
**
37403756
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
37413757
** <dd>The database is opened for reading and writing, and is created if
37423758
** it does not already exist. This is the behavior that is always used for
37433759
** sqlite3_open() and sqlite3_open16().</dd>)^
@@ -5714,14 +5730,25 @@
57145730
** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
57155731
** The SQLITE_DIRECTONLY flag means that the function may only be invoked
57165732
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
57175733
** schema structures such as [CHECK constraints], [DEFAULT clauses],
57185734
** [expression indexes], [partial indexes], or [generated columns].
5719
-** The SQLITE_DIRECTONLY flags is a security feature which is recommended
5720
-** for all [application-defined SQL functions], and especially for functions
5721
-** that have side-effects or that could potentially leak sensitive
5722
-** information.
5735
+** <p>
5736
+** The SQLITE_DIRECTONLY flag is recommended for any
5737
+** [application-defined SQL function]
5738
+** that has side-effects or that could potentially leak sensitive information.
5739
+** This will prevent attacks in which an application is tricked
5740
+** into using a database file that has had its schema surreptiously
5741
+** modified to invoke the application-defined function in ways that are
5742
+** harmful.
5743
+** <p>
5744
+** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5745
+** [application-defined SQL functions], regardless of whether or not they
5746
+** are security sensitive, as doing so prevents those functions from being used
5747
+** inside of the database schema, and thus ensures that the database
5748
+** can be inspected and modified using generic tools (such as the [CLI])
5749
+** that do not have access to the application-defined functions.
57235750
** </dd>
57245751
**
57255752
** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
57265753
** The SQLITE_INNOCUOUS flag means that the function is unlikely
57275754
** to cause problems even if misused. An innocuous function should have
@@ -7441,14 +7468,14 @@
74417468
** checked separately in byte code. If the omit flag is change to true, then
74427469
** the constraint may or may not be checked in byte code. In other words,
74437470
** when the omit flag is true there is no guarantee that the constraint will
74447471
** not be checked again using byte code.)^
74457472
**
7446
-** ^The idxNum and idxPtr values are recorded and passed into the
7473
+** ^The idxNum and idxStr values are recorded and passed into the
74477474
** [xFilter] method.
7448
-** ^[sqlite3_free()] is used to free idxPtr if and only if
7449
-** needToFreeIdxPtr is true.
7475
+** ^[sqlite3_free()] is used to free idxStr if and only if
7476
+** needToFreeIdxStr is true.
74507477
**
74517478
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
74527479
** the correct order to satisfy the ORDER BY clause so that no separate
74537480
** sorting step is required.
74547481
**
@@ -10400,10 +10427,14 @@
1040010427
** parameter is undefined. For an INSERT or UPDATE on a rowid table the
1040110428
** seventh parameter is the final rowid value of the row being inserted
1040210429
** or updated. The value of the seventh parameter passed to the callback
1040310430
** function is not defined for operations on WITHOUT ROWID tables, or for
1040410431
** DELETE operations on rowid tables.
10432
+**
10433
+** ^The sqlite3_update_hook(D,C,P) function returns the P argument from
10434
+** the previous call on the same [database connection] D, or NULL for
10435
+** the first call on D.
1040510436
**
1040610437
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
1040710438
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
1040810439
** provide additional information about a preupdate event. These routines
1040910440
** may only be called from within a preupdate callback. Invoking any of
@@ -15767,11 +15798,19 @@
1576715798
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
1576815799
SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
1576915800
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
1577015801
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
1577115802
15772
-SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,Pgno*aRoot,int nRoot,int,int*);
15803
+SQLITE_PRIVATE int sqlite3BtreeIntegrityCheck(
15804
+ sqlite3 *db, /* Database connection that is running the check */
15805
+ Btree *p, /* The btree to be checked */
15806
+ Pgno *aRoot, /* An array of root pages numbers for individual trees */
15807
+ int nRoot, /* Number of entries in aRoot[] */
15808
+ int mxErr, /* Stop reporting errors after this many */
15809
+ int *pnErr, /* OUT: Write number of errors seen to this variable */
15810
+ char **pzOut /* OUT: Write the error message string here */
15811
+);
1577315812
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
1577415813
SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
1577515814
1577615815
#ifndef SQLITE_OMIT_INCRBLOB
1577715816
SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
@@ -17373,12 +17412,18 @@
1737317412
** SQLITE_FUNC_ANYORDER == NC_OrderAgg == SF_OrderByReqd
1737417413
** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
1737517414
** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
1737617415
** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
1737717416
** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API
17378
-** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS
17417
+** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!!
1737917418
** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
17419
+**
17420
+** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the
17421
+** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is
17422
+** used internally and if set means tha the function has side effects.
17423
+** SQLITE_INNOCUOUS is used by application code and means "not unsafe".
17424
+** See multiple instances of tag-20230109-1.
1738017425
*/
1738117426
#define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
1738217427
#define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
1738317428
#define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
1738417429
#define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -17491,11 +17536,11 @@
1749117536
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1749217537
#define MFUNCTION(zName, nArg, xPtr, xFunc) \
1749317538
{nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
1749417539
xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
1749517540
#define JFUNCTION(zName, nArg, iArg, xFunc) \
17496
- {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|\
17541
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|\
1749717542
SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
1749817543
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1749917544
#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
1750017545
{nArg, SQLITE_FUNC_BUILTIN|\
1750117546
SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
@@ -19192,10 +19237,13 @@
1919219237
Returning *pReturning; /* The RETURNING clause */
1919319238
} u1;
1919419239
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
1919519240
u32 oldmask; /* Mask of old.* columns referenced */
1919619241
u32 newmask; /* Mask of new.* columns referenced */
19242
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
19243
+ u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
19244
+#endif
1919719245
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
1919819246
u8 bReturning; /* Coding a RETURNING trigger */
1919919247
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
1920019248
u8 disableTriggers; /* True to disable triggers */
1920119249
@@ -19940,17 +19988,15 @@
1994019988
** that deal with sqlite3StackAlloc() failures to be unreachable.
1994119989
*/
1994219990
#ifdef SQLITE_USE_ALLOCA
1994319991
# define sqlite3StackAllocRaw(D,N) alloca(N)
1994419992
# define sqlite3StackAllocRawNN(D,N) alloca(N)
19945
-# define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
1994619993
# define sqlite3StackFree(D,P)
1994719994
# define sqlite3StackFreeNN(D,P)
1994819995
#else
1994919996
# define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
1995019997
# define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N)
19951
-# define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N)
1995219998
# define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
1995319999
# define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P)
1995420000
#endif
1995520001
1995620002
/* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they
@@ -20071,10 +20117,11 @@
2007120117
SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
2007220118
#endif
2007320119
#endif
2007420120
2007520121
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
20122
+SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
2007620123
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
2007720124
SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
2007820125
SQLITE_PRIVATE void sqlite3Dequote(char*);
2007920126
SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
2008020127
SQLITE_PRIVATE void sqlite3DequoteToken(Token*);
@@ -20448,11 +20495,11 @@
2044820495
SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
2044920496
SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
2045020497
SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
2045120498
SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
2045220499
SQLITE_PRIVATE i64 sqlite3RealToI64(double);
20453
-SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
20500
+SQLITE_PRIVATE int sqlite3Int64ToText(i64,char*);
2045420501
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
2045520502
SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
2045620503
SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
2045720504
SQLITE_PRIVATE int sqlite3Atoi(const char*);
2045820505
#ifndef SQLITE_OMIT_UTF16
@@ -33722,10 +33769,30 @@
3372233769
z = sqlite3VMPrintf(db, zFormat, ap);
3372333770
va_end(ap);
3372433771
sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
3372533772
}
3372633773
}
33774
+
33775
+/*
33776
+** Check for interrupts and invoke progress callback.
33777
+*/
33778
+SQLITE_PRIVATE void sqlite3ProgressCheck(Parse *p){
33779
+ sqlite3 *db = p->db;
33780
+ if( AtomicLoad(&db->u1.isInterrupted) ){
33781
+ p->nErr++;
33782
+ p->rc = SQLITE_INTERRUPT;
33783
+ }
33784
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
33785
+ if( db->xProgress && (++p->nProgressSteps)>=db->nProgressOps ){
33786
+ if( db->xProgress(db->pProgressArg) ){
33787
+ p->nErr++;
33788
+ p->rc = SQLITE_INTERRUPT;
33789
+ }
33790
+ p->nProgressSteps = 0;
33791
+ }
33792
+#endif
33793
+}
3372733794
3372833795
/*
3372933796
** Add an error message to pParse->zErrMsg and increment pParse->nErr.
3373033797
**
3373133798
** This function should be used to report any error that occurs while
@@ -34180,15 +34247,18 @@
3418034247
#if defined(_MSC_VER)
3418134248
#pragma warning(default : 4756)
3418234249
#endif
3418334250
3418434251
/*
34185
-** Render an signed 64-bit integer as text. Store the result in zOut[].
34252
+** Render an signed 64-bit integer as text. Store the result in zOut[] and
34253
+** return the length of the string that was stored, in bytes. The value
34254
+** returned does not include the zero terminator at the end of the output
34255
+** string.
3418634256
**
3418734257
** The caller must ensure that zOut[] is at least 21 bytes in size.
3418834258
*/
34189
-SQLITE_PRIVATE void sqlite3Int64ToText(i64 v, char *zOut){
34259
+SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){
3419034260
int i;
3419134261
u64 x;
3419234262
char zTemp[22];
3419334263
if( v<0 ){
3419434264
x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
@@ -34201,10 +34271,11 @@
3420134271
zTemp[i--] = (x%10) + '0';
3420234272
x = x/10;
3420334273
}while( x );
3420434274
if( v<0 ) zTemp[i--] = '-';
3420534275
memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i);
34276
+ return sizeof(zTemp)-2-i;
3420634277
}
3420734278
3420834279
/*
3420934280
** Compare the 19-character string zNum against the text representation
3421034281
** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -35530,16 +35601,17 @@
3553035601
h = 0;
3553135602
elem = pH->first;
3553235603
count = pH->count;
3553335604
}
3553435605
if( pHash ) *pHash = h;
35535
- while( count-- ){
35606
+ while( count ){
3553635607
assert( elem!=0 );
3553735608
if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
3553835609
return elem;
3553935610
}
3554035611
elem = elem->next;
35612
+ count--;
3554135613
}
3554235614
return &nullElement;
3554335615
}
3554435616
3554535617
/* Remove a single entry from the hash table given a pointer to that
@@ -36259,12 +36331,11 @@
3625936331
c = aIn[++i];
3626036332
}
3626136333
if( j+n>nOut ) return -1;
3626236334
memset(&aOut[j], 0, n);
3626336335
j += n;
36264
- c = aIn[i];
36265
- if( c==0 ) break;
36336
+ if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
3626636337
}else{
3626736338
aOut[j] = c<<4;
3626836339
c = kvvfsHexValue[aIn[++i]];
3626936340
if( c<0 ) break;
3627036341
aOut[j++] += c;
@@ -43287,16 +43358,14 @@
4328743358
assert( nName>0 );
4328843359
assert( zName!=0 );
4328943360
if( zName[0]=='.' ){
4329043361
if( nName==1 ) return;
4329143362
if( zName[1]=='.' && nName==2 ){
43292
- if( pPath->nUsed<=1 ){
43293
- pPath->rc = SQLITE_ERROR;
43294
- return;
43363
+ if( pPath->nUsed>1 ){
43364
+ assert( pPath->zOut[0]=='/' );
43365
+ while( pPath->zOut[--pPath->nUsed]!='/' ){}
4329543366
}
43296
- assert( pPath->zOut[0]=='/' );
43297
- while( pPath->zOut[--pPath->nUsed]!='/' ){}
4329843367
return;
4329943368
}
4330043369
}
4330143370
if( pPath->nUsed + nName + 2 >= pPath->nOut ){
4330243371
pPath->rc = SQLITE_ERROR;
@@ -67958,12 +68027,12 @@
6795868027
#define ISAUTOVACUUM(pBt) 0
6795968028
#endif
6796068029
6796168030
6796268031
/*
67963
-** This structure is passed around through all the sanity checking routines
67964
-** in order to keep track of some global state information.
68032
+** This structure is passed around through all the PRAGMA integrity_check
68033
+** checking routines in order to keep track of some global state information.
6796568034
**
6796668035
** The aRef[] array is allocated so that there is 1 bit for each page in
6796768036
** the database. As the integrity-check proceeds, for each page used in
6796868037
** the database the corresponding bit is set. This allows integrity-check to
6796968038
** detect pages that are used twice and orphaned pages (both of which
@@ -67975,11 +68044,12 @@
6797568044
Pager *pPager; /* The associated pager. Also accessible by pBt->pPager */
6797668045
u8 *aPgRef; /* 1 bit per page in the db (see above) */
6797768046
Pgno nPage; /* Number of pages in the database */
6797868047
int mxErr; /* Stop accumulating errors when this reaches zero */
6797968048
int nErr; /* Number of messages written to zErrMsg so far */
67980
- int bOomFault; /* A memory allocation error has occurred */
68049
+ int rc; /* SQLITE_OK, SQLITE_NOMEM, or SQLITE_INTERRUPT */
68050
+ u32 nStep; /* Number of steps into the integrity_check process */
6798168051
const char *zPfx; /* Error message prefix */
6798268052
Pgno v1; /* Value for first %u substitution in zPfx */
6798368053
int v2; /* Value for second %d substitution in zPfx */
6798468054
StrAccum errMsg; /* Accumulate the error message text here */
6798568055
u32 *heap; /* Min-heap used for analyzing cell coverage */
@@ -77219,31 +77289,31 @@
7721977289
return SQLITE_OK;
7722077290
}
7722177291
7722277292
/*
7722377293
** Overwrite the cell that cursor pCur is pointing to with fresh content
77224
-** contained in pX.
77294
+** contained in pX. In this variant, pCur is pointing to an overflow
77295
+** cell.
7722577296
*/
77226
-static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
77297
+static SQLITE_NOINLINE int btreeOverwriteOverflowCell(
77298
+ BtCursor *pCur, /* Cursor pointing to cell to ovewrite */
77299
+ const BtreePayload *pX /* Content to write into the cell */
77300
+){
7722777301
int iOffset; /* Next byte of pX->pData to write */
7722877302
int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
7722977303
int rc; /* Return code */
7723077304
MemPage *pPage = pCur->pPage; /* Page being written */
7723177305
BtShared *pBt; /* Btree */
7723277306
Pgno ovflPgno; /* Next overflow page to write */
7723377307
u32 ovflPageSize; /* Size to write on overflow page */
7723477308
77235
- if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
77236
- || pCur->info.pPayload < pPage->aData + pPage->cellOffset
77237
- ){
77238
- return SQLITE_CORRUPT_BKPT;
77239
- }
77309
+ assert( pCur->info.nLocal<nTotal ); /* pCur is an overflow cell */
77310
+
7724077311
/* Overwrite the local portion first */
7724177312
rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
7724277313
0, pCur->info.nLocal);
7724377314
if( rc ) return rc;
77244
- if( pCur->info.nLocal==nTotal ) return SQLITE_OK;
7724577315
7724677316
/* Now overwrite the overflow pages */
7724777317
iOffset = pCur->info.nLocal;
7724877318
assert( nTotal>=0 );
7724977319
assert( iOffset>=0 );
@@ -77268,10 +77338,33 @@
7726877338
if( rc ) return rc;
7726977339
iOffset += ovflPageSize;
7727077340
}while( iOffset<nTotal );
7727177341
return SQLITE_OK;
7727277342
}
77343
+
77344
+/*
77345
+** Overwrite the cell that cursor pCur is pointing to with fresh content
77346
+** contained in pX.
77347
+*/
77348
+static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
77349
+ int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
77350
+ MemPage *pPage = pCur->pPage; /* Page being written */
77351
+
77352
+ if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
77353
+ || pCur->info.pPayload < pPage->aData + pPage->cellOffset
77354
+ ){
77355
+ return SQLITE_CORRUPT_BKPT;
77356
+ }
77357
+ if( pCur->info.nLocal==nTotal ){
77358
+ /* The entire cell is local */
77359
+ return btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
77360
+ 0, pCur->info.nLocal);
77361
+ }else{
77362
+ /* The cell contains overflow content */
77363
+ return btreeOverwriteOverflowCell(pCur, pX);
77364
+ }
77365
+}
7727377366
7727477367
7727577368
/*
7727677369
** Insert a new record into the BTree. The content of the new record
7727777370
** is described by the pX object. The pCur cursor is used only to
@@ -78463,19 +78556,55 @@
7846378556
SQLITE_PRIVATE Pager *sqlite3BtreePager(Btree *p){
7846478557
return p->pBt->pPager;
7846578558
}
7846678559
7846778560
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
78561
+/*
78562
+** Record an OOM error during integrity_check
78563
+*/
78564
+static void checkOom(IntegrityCk *pCheck){
78565
+ pCheck->rc = SQLITE_NOMEM;
78566
+ pCheck->mxErr = 0; /* Causes integrity_check processing to stop */
78567
+ if( pCheck->nErr==0 ) pCheck->nErr++;
78568
+}
78569
+
78570
+/*
78571
+** Invoke the progress handler, if appropriate. Also check for an
78572
+** interrupt.
78573
+*/
78574
+static void checkProgress(IntegrityCk *pCheck){
78575
+ sqlite3 *db = pCheck->db;
78576
+ if( AtomicLoad(&db->u1.isInterrupted) ){
78577
+ pCheck->rc = SQLITE_INTERRUPT;
78578
+ pCheck->nErr++;
78579
+ pCheck->mxErr = 0;
78580
+ }
78581
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
78582
+ if( db->xProgress ){
78583
+ assert( db->nProgressOps>0 );
78584
+ pCheck->nStep++;
78585
+ if( (pCheck->nStep % db->nProgressOps)==0
78586
+ && db->xProgress(db->pProgressArg)
78587
+ ){
78588
+ pCheck->rc = SQLITE_INTERRUPT;
78589
+ pCheck->nErr++;
78590
+ pCheck->mxErr = 0;
78591
+ }
78592
+ }
78593
+#endif
78594
+}
78595
+
7846878596
/*
7846978597
** Append a message to the error message string.
7847078598
*/
7847178599
static void checkAppendMsg(
7847278600
IntegrityCk *pCheck,
7847378601
const char *zFormat,
7847478602
...
7847578603
){
7847678604
va_list ap;
78605
+ checkProgress(pCheck);
7847778606
if( !pCheck->mxErr ) return;
7847878607
pCheck->mxErr--;
7847978608
pCheck->nErr++;
7848078609
va_start(ap, zFormat);
7848178610
if( pCheck->errMsg.nChar ){
@@ -78485,11 +78614,11 @@
7848578614
sqlite3_str_appendf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2);
7848678615
}
7848778616
sqlite3_str_vappendf(&pCheck->errMsg, zFormat, ap);
7848878617
va_end(ap);
7848978618
if( pCheck->errMsg.accError==SQLITE_NOMEM ){
78490
- pCheck->bOomFault = 1;
78619
+ checkOom(pCheck);
7849178620
}
7849278621
}
7849378622
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
7849478623
7849578624
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -78527,11 +78656,10 @@
7852778656
}
7852878657
if( getPageReferenced(pCheck, iPage) ){
7852978658
checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
7853078659
return 1;
7853178660
}
78532
- if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1;
7853378661
setPageReferenced(pCheck, iPage);
7853478662
return 0;
7853578663
}
7853678664
7853778665
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -78550,11 +78678,11 @@
7855078678
u8 ePtrmapType;
7855178679
Pgno iPtrmapParent;
7855278680
7855378681
rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
7855478682
if( rc!=SQLITE_OK ){
78555
- if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->bOomFault = 1;
78683
+ if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) checkOom(pCheck);
7855678684
checkAppendMsg(pCheck, "Failed to read ptrmap key=%d", iChild);
7855778685
return;
7855878686
}
7855978687
7856078688
if( ePtrmapType!=eType || iPtrmapParent!=iParent ){
@@ -78734,10 +78862,12 @@
7873478862
int saved_v2 = pCheck->v2;
7873578863
u8 savedIsInit = 0;
7873678864
7873778865
/* Check that the page exists
7873878866
*/
78867
+ checkProgress(pCheck);
78868
+ if( pCheck->mxErr==0 ) goto end_of_check;
7873978869
pBt = pCheck->pBt;
7874078870
usableSize = pBt->usableSize;
7874178871
if( iPage==0 ) return 0;
7874278872
if( checkRef(pCheck, iPage) ) return 0;
7874378873
pCheck->zPfx = "Page %u: ";
@@ -78979,17 +79109,18 @@
7897979109
** and the checks to make sure every page is referenced are also skipped,
7898079110
** since obviously it is not possible to know which pages are covered by
7898179111
** the unverified btrees. Except, if aRoot[1] is 1, then the freelist
7898279112
** checks are still performed.
7898379113
*/
78984
-SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
79114
+SQLITE_PRIVATE int sqlite3BtreeIntegrityCheck(
7898579115
sqlite3 *db, /* Database connection that is running the check */
7898679116
Btree *p, /* The btree to be checked */
7898779117
Pgno *aRoot, /* An array of root pages numbers for individual trees */
7898879118
int nRoot, /* Number of entries in aRoot[] */
7898979119
int mxErr, /* Stop reporting errors after this many */
78990
- int *pnErr /* Write number of errors seen to this variable */
79120
+ int *pnErr, /* OUT: Write number of errors seen to this variable */
79121
+ char **pzOut /* OUT: Write the error message string here */
7899179122
){
7899279123
Pgno i;
7899379124
IntegrityCk sCheck;
7899479125
BtShared *pBt = p->pBt;
7899579126
u64 savedDbFlags = pBt->db->flags;
@@ -79008,36 +79139,30 @@
7900879139
7900979140
sqlite3BtreeEnter(p);
7901079141
assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
7901179142
VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
7901279143
assert( nRef>=0 );
79144
+ memset(&sCheck, 0, sizeof(sCheck));
7901379145
sCheck.db = db;
7901479146
sCheck.pBt = pBt;
7901579147
sCheck.pPager = pBt->pPager;
7901679148
sCheck.nPage = btreePagecount(sCheck.pBt);
7901779149
sCheck.mxErr = mxErr;
79018
- sCheck.nErr = 0;
79019
- sCheck.bOomFault = 0;
79020
- sCheck.zPfx = 0;
79021
- sCheck.v1 = 0;
79022
- sCheck.v2 = 0;
79023
- sCheck.aPgRef = 0;
79024
- sCheck.heap = 0;
7902579150
sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
7902679151
sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL;
7902779152
if( sCheck.nPage==0 ){
7902879153
goto integrity_ck_cleanup;
7902979154
}
7903079155
7903179156
sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1);
7903279157
if( !sCheck.aPgRef ){
79033
- sCheck.bOomFault = 1;
79158
+ checkOom(&sCheck);
7903479159
goto integrity_ck_cleanup;
7903579160
}
7903679161
sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
7903779162
if( sCheck.heap==0 ){
79038
- sCheck.bOomFault = 1;
79163
+ checkOom(&sCheck);
7903979164
goto integrity_ck_cleanup;
7904079165
}
7904179166
7904279167
i = PENDING_BYTE_PAGE(pBt);
7904379168
if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
@@ -79114,20 +79239,21 @@
7911479239
/* Clean up and report errors.
7911579240
*/
7911679241
integrity_ck_cleanup:
7911779242
sqlite3PageFree(sCheck.heap);
7911879243
sqlite3_free(sCheck.aPgRef);
79119
- if( sCheck.bOomFault ){
79244
+ *pnErr = sCheck.nErr;
79245
+ if( sCheck.nErr==0 ){
7912079246
sqlite3_str_reset(&sCheck.errMsg);
79121
- sCheck.nErr++;
79247
+ *pzOut = 0;
79248
+ }else{
79249
+ *pzOut = sqlite3StrAccumFinish(&sCheck.errMsg);
7912279250
}
79123
- *pnErr = sCheck.nErr;
79124
- if( sCheck.nErr==0 ) sqlite3_str_reset(&sCheck.errMsg);
7912579251
/* Make sure this analysis did not leave any unref() pages. */
7912679252
assert( nRef==sqlite3PagerRefcount(pBt->pPager) );
7912779253
sqlite3BtreeLeave(p);
79128
- return sqlite3StrAccumFinish(&sCheck.errMsg);
79254
+ return sCheck.rc;
7912979255
}
7913079256
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
7913179257
7913279258
/*
7913379259
** Return the full pathname of the underlying database file. Return
@@ -80309,20 +80435,21 @@
8030980435
/* Work-around for GCC bug
8031080436
** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 */
8031180437
i64 x;
8031280438
assert( (p->flags&MEM_Int)*2==sizeof(x) );
8031380439
memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2);
80314
- sqlite3Int64ToText(x, zBuf);
80440
+ p->n = sqlite3Int64ToText(x, zBuf);
8031580441
#else
80316
- sqlite3Int64ToText(p->u.i, zBuf);
80442
+ p->n = sqlite3Int64ToText(p->u.i, zBuf);
8031780443
#endif
8031880444
}else{
8031980445
sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
8032080446
sqlite3_str_appendf(&acc, "%!.15g",
8032180447
(p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
8032280448
assert( acc.zText==zBuf && acc.mxAlloc<=0 );
8032380449
zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
80450
+ p->n = acc.nChar;
8032480451
}
8032580452
}
8032680453
8032780454
#ifdef SQLITE_DEBUG
8032880455
/*
@@ -80346,10 +80473,11 @@
8034680473
** true if everything is ok and false if there is a problem.
8034780474
**
8034880475
** This routine is for use inside of assert() statements only.
8034980476
*/
8035080477
SQLITE_PRIVATE int sqlite3VdbeMemValidStrRep(Mem *p){
80478
+ Mem tmp;
8035180479
char zBuf[100];
8035280480
char *z;
8035380481
int i, j, incr;
8035480482
if( (p->flags & MEM_Str)==0 ) return 1;
8035580483
if( p->flags & MEM_Term ){
@@ -80362,11 +80490,12 @@
8036280490
assert( p->z[p->n]==0 );
8036380491
assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 );
8036480492
assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
8036580493
}
8036680494
if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
80367
- vdbeMemRenderNum(sizeof(zBuf), zBuf, p);
80495
+ memcpy(&tmp, p, sizeof(tmp));
80496
+ vdbeMemRenderNum(sizeof(zBuf), zBuf, &tmp);
8036880497
z = p->z;
8036980498
i = j = 0;
8037080499
incr = 1;
8037180500
if( p->enc!=SQLITE_UTF8 ){
8037280501
incr = 2;
@@ -80631,11 +80760,11 @@
8063180760
return SQLITE_NOMEM_BKPT;
8063280761
}
8063380762
8063480763
vdbeMemRenderNum(nByte, pMem->z, pMem);
8063580764
assert( pMem->z!=0 );
80636
- pMem->n = sqlite3Strlen30NN(pMem->z);
80765
+ assert( pMem->n==sqlite3Strlen30NN(pMem->z) );
8063780766
pMem->enc = SQLITE_UTF8;
8063880767
pMem->flags |= MEM_Str|MEM_Term;
8063980768
if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
8064080769
sqlite3VdbeChangeEncoding(pMem, enc);
8064180770
return SQLITE_OK;
@@ -80871,36 +81000,39 @@
8087181000
if( pMem->flags & MEM_Null ) return ifNull;
8087281001
return sqlite3VdbeRealValue(pMem)!=0.0;
8087381002
}
8087481003
8087581004
/*
80876
-** The MEM structure is already a MEM_Real. Try to also make it a
80877
-** MEM_Int if we can.
81005
+** The MEM structure is already a MEM_Real or MEM_IntReal. Try to
81006
+** make it a MEM_Int if we can.
8087881007
*/
8087981008
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
80880
- i64 ix;
8088181009
assert( pMem!=0 );
80882
- assert( pMem->flags & MEM_Real );
81010
+ assert( pMem->flags & (MEM_Real|MEM_IntReal) );
8088381011
assert( !sqlite3VdbeMemIsRowSet(pMem) );
8088481012
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
8088581013
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
8088681014
80887
- ix = doubleToInt64(pMem->u.r);
80888
-
80889
- /* Only mark the value as an integer if
80890
- **
80891
- ** (1) the round-trip conversion real->int->real is a no-op, and
80892
- ** (2) The integer is neither the largest nor the smallest
80893
- ** possible integer (ticket #3922)
80894
- **
80895
- ** The second and third terms in the following conditional enforces
80896
- ** the second condition under the assumption that addition overflow causes
80897
- ** values to wrap around.
80898
- */
80899
- if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
80900
- pMem->u.i = ix;
81015
+ if( pMem->flags & MEM_IntReal ){
8090181016
MemSetTypeFlag(pMem, MEM_Int);
81017
+ }else{
81018
+ i64 ix = doubleToInt64(pMem->u.r);
81019
+
81020
+ /* Only mark the value as an integer if
81021
+ **
81022
+ ** (1) the round-trip conversion real->int->real is a no-op, and
81023
+ ** (2) The integer is neither the largest nor the smallest
81024
+ ** possible integer (ticket #3922)
81025
+ **
81026
+ ** The second and third terms in the following conditional enforces
81027
+ ** the second condition under the assumption that addition overflow causes
81028
+ ** values to wrap around.
81029
+ */
81030
+ if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
81031
+ pMem->u.i = ix;
81032
+ MemSetTypeFlag(pMem, MEM_Int);
81033
+ }
8090281034
}
8090381035
}
8090481036
8090581037
/*
8090681038
** Convert pMem to type integer. Invalidate any prior representations.
@@ -82755,10 +82887,13 @@
8275582887
}else{
8275682888
#ifdef SQLITE_DEBUG
8275782889
int i;
8275882890
for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1;
8275982891
#endif
82892
+ if( nNewSize>=100 && (nNewSize/100)>(p->nLabelAlloc/100) ){
82893
+ sqlite3ProgressCheck(p);
82894
+ }
8276082895
p->nLabelAlloc = nNewSize;
8276182896
p->aLabel[j] = v->nOp;
8276282897
}
8276382898
}
8276482899
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
@@ -90423,11 +90558,11 @@
9042390558
){
9042490559
if( affinity>=SQLITE_AFF_NUMERIC ){
9042590560
assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
9042690561
|| affinity==SQLITE_AFF_NUMERIC || affinity==SQLITE_AFF_FLEXNUM );
9042790562
if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
90428
- if( (pRec->flags & MEM_Real)==0 ){
90563
+ if( (pRec->flags & (MEM_Real|MEM_IntReal))==0 ){
9042990564
if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
9043090565
}else if( affinity<=SQLITE_AFF_REAL ){
9043190566
sqlite3VdbeIntegerAffinity(pRec);
9043290567
}
9043390568
}
@@ -91179,10 +91314,16 @@
9117991314
int pcx;
9118091315
9118191316
#ifdef SQLITE_DEBUG
9118291317
if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
9118391318
#endif
91319
+
91320
+ /* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates
91321
+ ** something is wrong with the code generator. Raise and assertion in order
91322
+ ** to bring this to the attention of fuzzers and other testing tools. */
91323
+ assert( pOp->p1!=SQLITE_INTERNAL );
91324
+
9118491325
if( p->pFrame && pOp->p1==SQLITE_OK ){
9118591326
/* Halt the sub-program. Return control to the parent frame. */
9118691327
pFrame = p->pFrame;
9118791328
p->pFrame = pFrame->pParent;
9118891329
p->nFrame--;
@@ -93171,11 +93312,11 @@
9317193312
if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
9317293313
break;
9317393314
}
9317493315
case COLTYPE_REAL: {
9317593316
testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
93176
- testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal );
93317
+ assert( (pIn1->flags & MEM_IntReal)==0 );
9317793318
if( pIn1->flags & MEM_Int ){
9317893319
/* When applying REAL affinity, if the result is still an MEM_Int
9317993320
** that will fit in 6 bytes, then change the type to MEM_IntReal
9318093321
** so that we keep the high-resolution integer value but know that
9318193322
** the type really wants to be REAL. */
@@ -96148,10 +96289,13 @@
9614896289
** The next use of the Rowid or Column or Next instruction for P1
9614996290
** will refer to the first entry in the database table or index.
9615096291
** If the table or index is empty, jump immediately to P2.
9615196292
** If the table or index is not empty, fall through to the following
9615296293
** instruction.
96294
+**
96295
+** If P2 is zero, that is an assertion that the P1 table is never
96296
+** empty and hence the jump will never be taken.
9615396297
**
9615496298
** This opcode leaves the cursor configured to move in forward order,
9615596299
** from the beginning toward the end. In other words, the cursor is
9615696300
** configured to use Next, not Prev.
9615796301
*/
@@ -96160,10 +96304,12 @@
9616096304
BtCursor *pCrsr;
9616196305
int res;
9616296306
9616396307
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9616496308
assert( pOp->p5==0 );
96309
+ assert( pOp->p2>=0 && pOp->p2<p->nOp );
96310
+
9616596311
pC = p->apCsr[pOp->p1];
9616696312
assert( pC!=0 );
9616796313
assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
9616896314
res = 1;
9616996315
#ifdef SQLITE_DEBUG
@@ -96179,13 +96325,14 @@
9617996325
pC->deferredMoveto = 0;
9618096326
pC->cacheStatus = CACHE_STALE;
9618196327
}
9618296328
if( rc ) goto abort_due_to_error;
9618396329
pC->nullRow = (u8)res;
96184
- assert( pOp->p2>0 && pOp->p2<p->nOp );
96185
- VdbeBranchTaken(res!=0,2);
96186
- if( res ) goto jump_to_p2;
96330
+ if( pOp->p2>0 ){
96331
+ VdbeBranchTaken(res!=0,2);
96332
+ if( res ) goto jump_to_p2;
96333
+ }
9618796334
break;
9618896335
}
9618996336
9619096337
/* Opcode: Next P1 P2 P3 * P5
9619196338
**
@@ -96987,17 +97134,18 @@
9698797134
assert( (pnErr->flags & MEM_Int)!=0 );
9698897135
assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
9698997136
pIn1 = &aMem[pOp->p1];
9699097137
assert( pOp->p5<db->nDb );
9699197138
assert( DbMaskTest(p->btreeMask, pOp->p5) );
96992
- z = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot,
96993
- (int)pnErr->u.i+1, &nErr);
97139
+ rc = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot,
97140
+ (int)pnErr->u.i+1, &nErr, &z);
9699497141
sqlite3VdbeMemSetNull(pIn1);
9699597142
if( nErr==0 ){
9699697143
assert( z==0 );
96997
- }else if( z==0 ){
96998
- goto no_mem;
97144
+ }else if( rc ){
97145
+ sqlite3_free(z);
97146
+ goto abort_due_to_error;
9699997147
}else{
9700097148
pnErr->u.i -= nErr-1;
9700197149
sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
9700297150
}
9700397151
UPDATE_MAX_BLOBSIZE(pIn1);
@@ -103838,10 +103986,11 @@
103838103986
assert( ExprUseYTab(pExpr) );
103839103987
pExpr->y.pTab = pTab;
103840103988
if( pParse->bReturning ){
103841103989
eNewExprOp = TK_REGISTER;
103842103990
pExpr->op2 = TK_COLUMN;
103991
+ pExpr->iColumn = iCol;
103843103992
pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
103844103993
sqlite3TableColumnToStorage(pTab, iCol) + 1;
103845103994
}else{
103846103995
pExpr->iColumn = (i16)iCol;
103847103996
eNewExprOp = TK_TRIGGER;
@@ -132018,10 +132167,12 @@
132018132167
unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
132019132168
unsigned int);
132020132169
const char *(*db_name)(sqlite3*,int);
132021132170
/* Version 3.40.0 and later */
132022132171
int (*value_encoding)(sqlite3_value*);
132172
+ /* Version 3.41.0 and later */
132173
+ int (*is_interrupted)(sqlite3*);
132023132174
};
132024132175
132025132176
/*
132026132177
** This is the function signature used for all extension entry points. It
132027132178
** is also defined in the file "loadext.c".
@@ -132344,10 +132495,12 @@
132344132495
#define sqlite3_serialize sqlite3_api->serialize
132345132496
#endif
132346132497
#define sqlite3_db_name sqlite3_api->db_name
132347132498
/* Version 3.40.0 and later */
132348132499
#define sqlite3_value_encoding sqlite3_api->value_encoding
132500
+/* Version 3.41.0 and later */
132501
+#define sqlite3_is_interrupted sqlite3_api->is_interrupted
132349132502
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
132350132503
132351132504
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
132352132505
/* This case when the file really is being compiled as a loadable
132353132506
** extension */
@@ -132858,11 +133011,13 @@
132858133011
0,
132859133012
0,
132860133013
#endif
132861133014
sqlite3_db_name,
132862133015
/* Version 3.40.0 and later */
132863
- sqlite3_value_encoding
133016
+ sqlite3_value_encoding,
133017
+ /* Version 3.41.0 and later */
133018
+ sqlite3_is_interrupted
132864133019
};
132865133020
132866133021
/* True if x is the directory separator character
132867133022
*/
132868133023
#if SQLITE_OS_WIN
@@ -135868,11 +136023,12 @@
135868136023
sqlite3ExprListDelete(db, pCheck);
135869136024
}
135870136025
if( !isQuick ){ /* Omit the remaining tests for quick_check */
135871136026
/* Validate index entries for the current row */
135872136027
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
135873
- int jmp2, jmp3, jmp4, jmp5;
136028
+ int jmp2, jmp3, jmp4, jmp5, label6;
136029
+ int kk;
135874136030
int ckUniq = sqlite3VdbeMakeLabel(pParse);
135875136031
if( pPk==pIdx ) continue;
135876136032
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
135877136033
pPrior, r1);
135878136034
pPrior = pIdx;
@@ -135886,17 +136042,36 @@
135886136042
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
135887136043
jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
135888136044
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
135889136045
jmp4 = integrityCheckResultRow(v);
135890136046
sqlite3VdbeJumpHere(v, jmp2);
136047
+
136048
+ /* Any indexed columns with non-BINARY collations must still hold
136049
+ ** the exact same text value as the table. */
136050
+ label6 = 0;
136051
+ for(kk=0; kk<pIdx->nKeyCol; kk++){
136052
+ if( pIdx->azColl[kk]==sqlite3StrBINARY ) continue;
136053
+ if( label6==0 ) label6 = sqlite3VdbeMakeLabel(pParse);
136054
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur+j, kk, 3);
136055
+ sqlite3VdbeAddOp3(v, OP_Ne, 3, label6, r1+kk); VdbeCoverage(v);
136056
+ }
136057
+ if( label6 ){
136058
+ int jmp6 = sqlite3VdbeAddOp0(v, OP_Goto);
136059
+ sqlite3VdbeResolveLabel(v, label6);
136060
+ sqlite3VdbeLoadString(v, 3, "row ");
136061
+ sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
136062
+ sqlite3VdbeLoadString(v, 4, " values differ from index ");
136063
+ sqlite3VdbeGoto(v, jmp5-1);
136064
+ sqlite3VdbeJumpHere(v, jmp6);
136065
+ }
136066
+
135891136067
/* For UNIQUE indexes, verify that only one entry exists with the
135892136068
** current key. The entry is unique if (1) any column is NULL
135893136069
** or (2) the next entry has a different key */
135894136070
if( IsUniqueIndex(pIdx) ){
135895136071
int uniqOk = sqlite3VdbeMakeLabel(pParse);
135896136072
int jmp6;
135897
- int kk;
135898136073
for(kk=0; kk<pIdx->nKeyCol; kk++){
135899136074
int iCol = pIdx->aiColumn[kk];
135900136075
assert( iCol!=XN_ROWID && iCol<pTab->nCol );
135901136076
if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
135902136077
sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
@@ -139696,11 +139871,10 @@
139696139871
#ifdef SQLITE_ENABLE_COLUMN_METADATA
139697139872
# define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)
139698139873
#else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
139699139874
# define columnType(A,B,C,D,E) columnTypeImpl(A,B)
139700139875
#endif
139701
-#ifndef SQLITE_OMIT_DECLTYPE
139702139876
static const char *columnTypeImpl(
139703139877
NameContext *pNC,
139704139878
#ifndef SQLITE_ENABLE_COLUMN_METADATA
139705139879
Expr *pExpr
139706139880
#else
@@ -139727,11 +139901,11 @@
139727139901
** database table or a subquery.
139728139902
*/
139729139903
Table *pTab = 0; /* Table structure column is extracted from */
139730139904
Select *pS = 0; /* Select the column is extracted from */
139731139905
int iCol = pExpr->iColumn; /* Index of column in pTab */
139732
- while( ALWAYS(pNC) && !pTab ){
139906
+ while( pNC && !pTab ){
139733139907
SrcList *pTabList = pNC->pSrcList;
139734139908
for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
139735139909
if( j<pTabList->nSrc ){
139736139910
pTab = pTabList->a[j].pTab;
139737139911
pS = pTabList->a[j].pSelect;
@@ -139738,11 +139912,11 @@
139738139912
}else{
139739139913
pNC = pNC->pNext;
139740139914
}
139741139915
}
139742139916
139743
- if( NEVER(pTab==0) ){
139917
+ if( pTab==0 ){
139744139918
/* At one time, code such as "SELECT new.x" within a trigger would
139745139919
** cause this condition to run. Since then, we have restructured how
139746139920
** trigger code is generated and so this condition is no longer
139747139921
** possible. However, it can still be true for statements like
139748139922
** the following:
@@ -139843,11 +140017,10 @@
139843140017
*pzOrigCol = zOrigCol;
139844140018
}
139845140019
#endif
139846140020
return zType;
139847140021
}
139848
-#endif /* !defined(SQLITE_OMIT_DECLTYPE) */
139849140022
139850140023
/*
139851140024
** Generate code that will tell the VDBE the declaration types of columns
139852140025
** in the result set.
139853140026
*/
@@ -140039,11 +140212,11 @@
140039140212
}
140040140213
assert( nCol==(i16)nCol );
140041140214
*pnCol = nCol;
140042140215
*paCol = aCol;
140043140216
140044
- for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
140217
+ for(i=0, pCol=aCol; i<nCol && !pParse->nErr; i++, pCol++){
140045140218
struct ExprList_item *pX = &pEList->a[i];
140046140219
struct ExprList_item *pCollide;
140047140220
/* Get an appropriate name for the column
140048140221
*/
140049140222
if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
@@ -140089,11 +140262,14 @@
140089140262
if( nName>0 ){
140090140263
for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
140091140264
if( zName[j]==':' ) nName = j;
140092140265
}
140093140266
zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
140094
- if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
140267
+ sqlite3ProgressCheck(pParse);
140268
+ if( cnt>3 ){
140269
+ sqlite3_randomness(sizeof(cnt), &cnt);
140270
+ }
140095140271
}
140096140272
pCol->zCnName = zName;
140097140273
pCol->hName = sqlite3StrIHash(zName);
140098140274
if( pX->fg.bNoExpand ){
140099140275
pCol->colFlags |= COLFLAG_NOEXPAND;
@@ -140102,18 +140278,18 @@
140102140278
if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
140103140279
sqlite3OomFault(db);
140104140280
}
140105140281
}
140106140282
sqlite3HashClear(&ht);
140107
- if( db->mallocFailed ){
140283
+ if( pParse->nErr ){
140108140284
for(j=0; j<i; j++){
140109140285
sqlite3DbFree(db, aCol[j].zCnName);
140110140286
}
140111140287
sqlite3DbFree(db, aCol);
140112140288
*paCol = 0;
140113140289
*pnCol = 0;
140114
- return SQLITE_NOMEM_BKPT;
140290
+ return pParse->rc;
140115140291
}
140116140292
return SQLITE_OK;
140117140293
}
140118140294
140119140295
/*
@@ -140137,18 +140313,21 @@
140137140313
Column *pCol;
140138140314
CollSeq *pColl;
140139140315
int i,j;
140140140316
Expr *p;
140141140317
struct ExprList_item *a;
140318
+ NameContext sNC;
140142140319
140143140320
assert( pSelect!=0 );
140144140321
assert( (pSelect->selFlags & SF_Resolved)!=0 );
140145
- assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
140322
+ assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
140146140323
assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
140147140324
if( db->mallocFailed ) return;
140148140325
while( pSelect->pPrior ) pSelect = pSelect->pPrior;
140149140326
a = pSelect->pEList->a;
140327
+ memset(&sNC, 0, sizeof(sNC));
140328
+ sNC.pSrcList = pSelect->pSrc;
140150140329
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
140151140330
const char *zType;
140152140331
i64 n;
140153140332
pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
140154140333
p = a[i].pExpr;
@@ -140170,32 +140349,35 @@
140170140349
}else
140171140350
if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140172140351
pCol->affinity = SQLITE_AFF_BLOB;
140173140352
}
140174140353
}
140175
- if( pCol->affinity==SQLITE_AFF_NUMERIC
140176
- || pCol->affinity==SQLITE_AFF_FLEXNUM
140177
- ){
140178
- zType = "NUM";
140179
- }else{
140180
- zType = 0;
140181
- for(j=1; j<SQLITE_N_STDTYPE; j++){
140182
- if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
140183
- zType = sqlite3StdType[j];
140184
- break;
140185
- }
140186
- }
140187
- }
140188
- if( zType ){
140189
- i64 m = sqlite3Strlen30(zType);
140190
- n = sqlite3Strlen30(pCol->zCnName);
140191
- pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
140192
- if( pCol->zCnName ){
140193
- memcpy(&pCol->zCnName[n+1], zType, m+1);
140194
- pCol->colFlags |= COLFLAG_HASTYPE;
140195
- }else{
140196
- testcase( pCol->colFlags & COLFLAG_HASTYPE );
140354
+ zType = columnType(&sNC, p, 0, 0, 0);
140355
+ if( zType==0 || pCol->affinity!=sqlite3AffinityType(zType, 0) ){
140356
+ if( pCol->affinity==SQLITE_AFF_NUMERIC
140357
+ || pCol->affinity==SQLITE_AFF_FLEXNUM
140358
+ ){
140359
+ zType = "NUM";
140360
+ }else{
140361
+ zType = 0;
140362
+ for(j=1; j<SQLITE_N_STDTYPE; j++){
140363
+ if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
140364
+ zType = sqlite3StdType[j];
140365
+ break;
140366
+ }
140367
+ }
140368
+ }
140369
+ }
140370
+ if( zType ){
140371
+ i64 m = sqlite3Strlen30(zType);
140372
+ n = sqlite3Strlen30(pCol->zCnName);
140373
+ pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
140374
+ if( pCol->zCnName ){
140375
+ memcpy(&pCol->zCnName[n+1], zType, m+1);
140376
+ pCol->colFlags |= COLFLAG_HASTYPE;
140377
+ }else{
140378
+ testcase( pCol->colFlags & COLFLAG_HASTYPE );
140197140379
pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
140198140380
}
140199140381
}
140200140382
pColl = sqlite3ExprCollSeq(pParse, p);
140201140383
if( pColl ){
@@ -156196,10 +156378,17 @@
156196156378
/* This term is a vector operation that has been decomposed into
156197156379
** other, subsequent terms. It can be ignored. See tag-20220128a */
156198156380
assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
156199156381
assert( pWC->a[ii].eOperator==WO_ROWVAL );
156200156382
continue;
156383
+ }
156384
+ if( pWC->a[ii].nChild ){
156385
+ /* If this term has child terms, then they are also part of the
156386
+ ** pWC->a[] array. So this term can be ignored, as a LIMIT clause
156387
+ ** will only be added if each of the child terms passes the
156388
+ ** (leftCursor==iCsr) test below. */
156389
+ continue;
156201156390
}
156202156391
if( pWC->a[ii].leftCursor!=iCsr ) return;
156203156392
}
156204156393
156205156394
/* Check condition (5). Return early if it is not met. */
@@ -159128,10 +159317,11 @@
159128159317
if( pX==0 ) continue;
159129159318
if( pX==pTerm ) break;
159130159319
if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
159131159320
}
159132159321
if( j<0 ){
159322
+ sqlite3ProgressCheck(pWC->pWInfo->pParse);
159133159323
if( pLoop->maskSelf==pTerm->prereqAll ){
159134159324
/* If there are extra terms in the WHERE clause not used by an index
159135159325
** that depend only on the table being scanned, and that will tend to
159136159326
** cause many rows to be omitted, then mark that table as
159137159327
** "self-culling".
@@ -159295,11 +159485,14 @@
159295159485
LogEst rSize; /* Number of rows in the table */
159296159486
LogEst rLogSize; /* Logarithm of table size */
159297159487
WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
159298159488
159299159489
pNew = pBuilder->pNew;
159300
- if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
159490
+ assert( db->mallocFailed==0 || pParse->nErr>0 );
159491
+ if( pParse->nErr ){
159492
+ return pParse->rc;
159493
+ }
159301159494
WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n",
159302159495
pProbe->pTable->zName,pProbe->zName,
159303159496
pNew->u.btree.nEq, pNew->nSkip, pNew->rRun));
159304159497
159305159498
assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
@@ -159611,10 +159804,13 @@
159611159804
if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
159612159805
&& pNew->u.btree.nEq<pProbe->nColumn
159613159806
&& (pNew->u.btree.nEq<pProbe->nKeyCol ||
159614159807
pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
159615159808
){
159809
+ if( pNew->u.btree.nEq>3 ){
159810
+ sqlite3ProgressCheck(pParse);
159811
+ }
159616159812
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
159617159813
}
159618159814
pNew->nOut = saved_nOut;
159619159815
#ifdef SQLITE_ENABLE_STAT4
159620159816
pBuilder->nRecValid = nRecValid;
@@ -160770,12 +160966,10 @@
160770160966
rc = whereLoopAddBtree(&sSubBuild, mPrereq);
160771160967
}
160772160968
if( rc==SQLITE_OK ){
160773160969
rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
160774160970
}
160775
- assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0
160776
- || rc==SQLITE_NOMEM );
160777160971
testcase( rc==SQLITE_NOMEM && sCur.n>0 );
160778160972
testcase( rc==SQLITE_DONE );
160779160973
if( sCur.n==0 ){
160780160974
sSum.n = 0;
160781160975
break;
@@ -166126,12 +166320,11 @@
166126166320
int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
166127166321
int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
166128166322
VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because bound <expr> */
166129166323
VdbeCoverageNeverNullIf(v, op==OP_Le); /* values previously checked */
166130166324
windowAggFinal(&s, 0);
166131
- sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
166132
- VdbeCoverageNeverTaken(v);
166325
+ sqlite3VdbeAddOp1(v, OP_Rewind, s.current.csr);
166133166326
windowReturnOneRow(&s);
166134166327
sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
166135166328
sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
166136166329
sqlite3VdbeJumpHere(v, addrGe);
166137166330
}
@@ -166139,17 +166332,14 @@
166139166332
assert( pMWin->eEnd==TK_FOLLOWING );
166140166333
sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regStart);
166141166334
}
166142166335
166143166336
if( pMWin->eStart!=TK_UNBOUNDED ){
166144
- sqlite3VdbeAddOp2(v, OP_Rewind, s.start.csr, 1);
166145
- VdbeCoverageNeverTaken(v);
166337
+ sqlite3VdbeAddOp1(v, OP_Rewind, s.start.csr);
166146166338
}
166147
- sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
166148
- VdbeCoverageNeverTaken(v);
166149
- sqlite3VdbeAddOp2(v, OP_Rewind, s.end.csr, 1);
166150
- VdbeCoverageNeverTaken(v);
166339
+ sqlite3VdbeAddOp1(v, OP_Rewind, s.current.csr);
166340
+ sqlite3VdbeAddOp1(v, OP_Rewind, s.end.csr);
166151166341
if( regPeer && pOrderBy ){
166152166342
sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, pOrderBy->nExpr-1);
166153166343
sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.start.reg, pOrderBy->nExpr-1);
166154166344
sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.current.reg, pOrderBy->nExpr-1);
166155166345
sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.end.reg, pOrderBy->nExpr-1);
@@ -175259,18 +175449,35 @@
175259175449
/*
175260175450
** Cause any pending operation to stop at its earliest opportunity.
175261175451
*/
175262175452
SQLITE_API void sqlite3_interrupt(sqlite3 *db){
175263175453
#ifdef SQLITE_ENABLE_API_ARMOR
175264
- if( !sqlite3SafetyCheckOk(db) && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE) ){
175454
+ if( !sqlite3SafetyCheckOk(db)
175455
+ && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
175456
+ ){
175265175457
(void)SQLITE_MISUSE_BKPT;
175266175458
return;
175267175459
}
175268175460
#endif
175269175461
AtomicStore(&db->u1.isInterrupted, 1);
175270175462
}
175271175463
175464
+/*
175465
+** Return true or false depending on whether or not an interrupt is
175466
+** pending on connection db.
175467
+*/
175468
+SQLITE_API int sqlite3_is_interrupted(sqlite3 *db){
175469
+#ifdef SQLITE_ENABLE_API_ARMOR
175470
+ if( !sqlite3SafetyCheckOk(db)
175471
+ && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
175472
+ ){
175473
+ (void)SQLITE_MISUSE_BKPT;
175474
+ return 0;
175475
+ }
175476
+#endif
175477
+ return AtomicLoad(&db->u1.isInterrupted)!=0;
175478
+}
175272175479
175273175480
/*
175274175481
** This function is exactly the same as sqlite3_create_function(), except
175275175482
** that it is designed to be called by internal code. The difference is
175276175483
** that if a malloc() fails in sqlite3_create_function(), an error code
@@ -175311,11 +175518,11 @@
175311175518
enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
175312175519
175313175520
/* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But
175314175521
** the meaning is inverted. So flip the bit. */
175315175522
assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS );
175316
- extraFlags ^= SQLITE_FUNC_UNSAFE;
175523
+ extraFlags ^= SQLITE_FUNC_UNSAFE; /* tag-20230109-1 */
175317175524
175318175525
175319175526
#ifndef SQLITE_OMIT_UTF16
175320175527
/* If SQLITE_UTF16 is specified as the encoding type, transform this
175321175528
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
@@ -175329,15 +175536,15 @@
175329175536
enc = SQLITE_UTF16NATIVE;
175330175537
break;
175331175538
case SQLITE_ANY: {
175332175539
int rc;
175333175540
rc = sqlite3CreateFunc(db, zFunctionName, nArg,
175334
- (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
175541
+ (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE, /* tag-20230109-1 */
175335175542
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
175336175543
if( rc==SQLITE_OK ){
175337175544
rc = sqlite3CreateFunc(db, zFunctionName, nArg,
175338
- (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
175545
+ (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE, /* tag-20230109-1*/
175339175546
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
175340175547
}
175341175548
if( rc!=SQLITE_OK ){
175342175549
return rc;
175343175550
}
@@ -212650,11 +212857,12 @@
212650212857
** leave an error code and error message in the rbu handle.
212651212858
*/
212652212859
static void rbuDeleteOalFile(sqlite3rbu *p){
212653212860
char *zOal = rbuMPrintf(p, "%s-oal", p->zTarget);
212654212861
if( zOal ){
212655
- sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
212862
+ sqlite3_vfs *pVfs = 0;
212863
+ sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_VFS_POINTER, &pVfs);
212656212864
assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
212657212865
pVfs->xDelete(pVfs, zOal, 0);
212658212866
sqlite3_free(zOal);
212659212867
}
212660212868
}
@@ -213407,13 +213615,16 @@
213407213615
sqlite3_free(p->apShm);
213408213616
p->apShm = 0;
213409213617
sqlite3_free(p->zDel);
213410213618
213411213619
if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
213620
+ const sqlite3_io_methods *pMeth = p->pReal->pMethods;
213412213621
rbuMainlistRemove(p);
213413213622
rbuUnlockShm(p);
213414
- p->pReal->pMethods->xShmUnmap(p->pReal, 0);
213623
+ if( pMeth->iVersion>1 && pMeth->xShmUnmap ){
213624
+ pMeth->xShmUnmap(p->pReal, 0);
213625
+ }
213415213626
}
213416213627
else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){
213417213628
rbuUpdateTempSize(p, 0);
213418213629
}
213419213630
assert( p->pMainNext==0 && p->pRbuVfs->pMain!=p );
@@ -213868,10 +214079,29 @@
213868214079
rbuVfsShmLock, /* xShmLock */
213869214080
rbuVfsShmBarrier, /* xShmBarrier */
213870214081
rbuVfsShmUnmap, /* xShmUnmap */
213871214082
0, 0 /* xFetch, xUnfetch */
213872214083
};
214084
+ static sqlite3_io_methods rbuvfs_io_methods1 = {
214085
+ 1, /* iVersion */
214086
+ rbuVfsClose, /* xClose */
214087
+ rbuVfsRead, /* xRead */
214088
+ rbuVfsWrite, /* xWrite */
214089
+ rbuVfsTruncate, /* xTruncate */
214090
+ rbuVfsSync, /* xSync */
214091
+ rbuVfsFileSize, /* xFileSize */
214092
+ rbuVfsLock, /* xLock */
214093
+ rbuVfsUnlock, /* xUnlock */
214094
+ rbuVfsCheckReservedLock, /* xCheckReservedLock */
214095
+ rbuVfsFileControl, /* xFileControl */
214096
+ rbuVfsSectorSize, /* xSectorSize */
214097
+ rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */
214098
+ 0, 0, 0, 0, 0, 0
214099
+ };
214100
+
214101
+
214102
+
213873214103
rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
213874214104
sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
213875214105
rbu_file *pFd = (rbu_file *)pFile;
213876214106
int rc = SQLITE_OK;
213877214107
const char *zOpen = zName;
@@ -213922,14 +214152,19 @@
213922214152
213923214153
if( rc==SQLITE_OK ){
213924214154
rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags);
213925214155
}
213926214156
if( pFd->pReal->pMethods ){
214157
+ const sqlite3_io_methods *pMeth = pFd->pReal->pMethods;
213927214158
/* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
213928214159
** pointer and, if the file is a main database file, link it into the
213929214160
** mutex protected linked list of all such files. */
213930
- pFile->pMethods = &rbuvfs_io_methods;
214161
+ if( pMeth->iVersion<2 || pMeth->xShmLock==0 ){
214162
+ pFile->pMethods = &rbuvfs_io_methods1;
214163
+ }else{
214164
+ pFile->pMethods = &rbuvfs_io_methods;
214165
+ }
213931214166
if( flags & SQLITE_OPEN_MAIN_DB ){
213932214167
rbuMainlistAdd(pFd);
213933214168
}
213934214169
}else{
213935214170
sqlite3_free(pFd->zDel);
@@ -239641,11 +239876,11 @@
239641239876
int nArg, /* Number of args */
239642239877
sqlite3_value **apUnused /* Function arguments */
239643239878
){
239644239879
assert( nArg==0 );
239645239880
UNUSED_PARAM2(nArg, apUnused);
239646
- sqlite3_result_text(pCtx, "fts5: 2022-12-27 22:46:49 e8afad630b085a9208491e0516a6a30c9cda77a20b1aa2cba49b2f44eb9fa2f8", -1, SQLITE_TRANSIENT);
239881
+ sqlite3_result_text(pCtx, "fts5: 2023-01-16 18:13:00 83f21285fe86430a66ce6841606e3ad7c27da52ac75a034c6a00c7a9fdb9791d", -1, SQLITE_TRANSIENT);
239647239882
}
239648239883
239649239884
/*
239650239885
** Return true if zName is the extension on one of the shadow tables used
239651239886
** by this module.
239652239887
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.41.0"
456 #define SQLITE_VERSION_NUMBER 3041000
457 #define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -2983,12 +2983,16 @@
2983 ** that are started after the running statement count reaches zero are
2984 ** not effected by the sqlite3_interrupt().
2985 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2986 ** SQL statements is a no-op and has no effect on SQL statements
2987 ** that are started after the sqlite3_interrupt() call returns.
 
 
 
2988 */
2989 SQLITE_API void sqlite3_interrupt(sqlite3*);
 
2990
2991 /*
2992 ** CAPI3REF: Determine If An SQL Statement Is Complete
2993 **
2994 ** These routines are useful during command-line input to determine if the
@@ -3666,11 +3670,11 @@
3666 ** CAPI3REF: Query Progress Callbacks
3667 ** METHOD: sqlite3
3668 **
3669 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3670 ** function X to be invoked periodically during long running calls to
3671 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3672 ** database connection D. An example use for this
3673 ** interface is to keep a GUI updated during a large query.
3674 **
3675 ** ^The parameter P is passed through as the only parameter to the
3676 ** callback function X. ^The parameter N is the approximate number of
@@ -3691,10 +3695,17 @@
3691 ** The progress handler callback must not do anything that will modify
3692 ** the database connection that invoked the progress handler.
3693 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3694 ** database connections for the meaning of "modify" in this paragraph.
3695 **
 
 
 
 
 
 
 
3696 */
3697 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3698
3699 /*
3700 ** CAPI3REF: Opening A New Database Connection
@@ -3727,17 +3738,22 @@
3727 ** sqlite3_open_v2() must include, at a minimum, one of the following
3728 ** three flag combinations:)^
3729 **
3730 ** <dl>
3731 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3732 ** <dd>The database is opened in read-only mode. If the database does not
3733 ** already exist, an error is returned.</dd>)^
3734 **
3735 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3736 ** <dd>The database is opened for reading and writing if possible, or reading
3737 ** only if the file is write protected by the operating system. In either
3738 ** case the database must already exist, otherwise an error is returned.</dd>)^
 
 
 
 
 
3739 **
3740 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3741 ** <dd>The database is opened for reading and writing, and is created if
3742 ** it does not already exist. This is the behavior that is always used for
3743 ** sqlite3_open() and sqlite3_open16().</dd>)^
@@ -5714,14 +5730,25 @@
5714 ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
5715 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5716 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5717 ** schema structures such as [CHECK constraints], [DEFAULT clauses],
5718 ** [expression indexes], [partial indexes], or [generated columns].
5719 ** The SQLITE_DIRECTONLY flags is a security feature which is recommended
5720 ** for all [application-defined SQL functions], and especially for functions
5721 ** that have side-effects or that could potentially leak sensitive
5722 ** information.
 
 
 
 
 
 
 
 
 
 
 
5723 ** </dd>
5724 **
5725 ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
5726 ** The SQLITE_INNOCUOUS flag means that the function is unlikely
5727 ** to cause problems even if misused. An innocuous function should have
@@ -7441,14 +7468,14 @@
7441 ** checked separately in byte code. If the omit flag is change to true, then
7442 ** the constraint may or may not be checked in byte code. In other words,
7443 ** when the omit flag is true there is no guarantee that the constraint will
7444 ** not be checked again using byte code.)^
7445 **
7446 ** ^The idxNum and idxPtr values are recorded and passed into the
7447 ** [xFilter] method.
7448 ** ^[sqlite3_free()] is used to free idxPtr if and only if
7449 ** needToFreeIdxPtr is true.
7450 **
7451 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
7452 ** the correct order to satisfy the ORDER BY clause so that no separate
7453 ** sorting step is required.
7454 **
@@ -10400,10 +10427,14 @@
10400 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
10401 ** seventh parameter is the final rowid value of the row being inserted
10402 ** or updated. The value of the seventh parameter passed to the callback
10403 ** function is not defined for operations on WITHOUT ROWID tables, or for
10404 ** DELETE operations on rowid tables.
 
 
 
 
10405 **
10406 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
10407 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
10408 ** provide additional information about a preupdate event. These routines
10409 ** may only be called from within a preupdate callback. Invoking any of
@@ -15767,11 +15798,19 @@
15767 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
15768 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
15769 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
15770 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
15771
15772 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,Pgno*aRoot,int nRoot,int,int*);
 
 
 
 
 
 
 
 
15773 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
15774 SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
15775
15776 #ifndef SQLITE_OMIT_INCRBLOB
15777 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
@@ -17373,12 +17412,18 @@
17373 ** SQLITE_FUNC_ANYORDER == NC_OrderAgg == SF_OrderByReqd
17374 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
17375 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
17376 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
17377 ** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API
17378 ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS
17379 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
 
 
 
 
 
 
17380 */
17381 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
17382 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
17383 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
17384 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -17491,11 +17536,11 @@
17491 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
17492 #define MFUNCTION(zName, nArg, xPtr, xFunc) \
17493 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
17494 xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
17495 #define JFUNCTION(zName, nArg, iArg, xFunc) \
17496 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|\
17497 SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
17498 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
17499 #define INLINE_FUNC(zName, nArg, iArg, mFlags) \
17500 {nArg, SQLITE_FUNC_BUILTIN|\
17501 SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
@@ -19192,10 +19237,13 @@
19192 Returning *pReturning; /* The RETURNING clause */
19193 } u1;
19194 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
19195 u32 oldmask; /* Mask of old.* columns referenced */
19196 u32 newmask; /* Mask of new.* columns referenced */
 
 
 
19197 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
19198 u8 bReturning; /* Coding a RETURNING trigger */
19199 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
19200 u8 disableTriggers; /* True to disable triggers */
19201
@@ -19940,17 +19988,15 @@
19940 ** that deal with sqlite3StackAlloc() failures to be unreachable.
19941 */
19942 #ifdef SQLITE_USE_ALLOCA
19943 # define sqlite3StackAllocRaw(D,N) alloca(N)
19944 # define sqlite3StackAllocRawNN(D,N) alloca(N)
19945 # define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
19946 # define sqlite3StackFree(D,P)
19947 # define sqlite3StackFreeNN(D,P)
19948 #else
19949 # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
19950 # define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N)
19951 # define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N)
19952 # define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
19953 # define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P)
19954 #endif
19955
19956 /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they
@@ -20071,10 +20117,11 @@
20071 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
20072 #endif
20073 #endif
20074
20075 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
 
20076 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
20077 SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
20078 SQLITE_PRIVATE void sqlite3Dequote(char*);
20079 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
20080 SQLITE_PRIVATE void sqlite3DequoteToken(Token*);
@@ -20448,11 +20495,11 @@
20448 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
20449 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
20450 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
20451 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
20452 SQLITE_PRIVATE i64 sqlite3RealToI64(double);
20453 SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
20454 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
20455 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
20456 SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
20457 SQLITE_PRIVATE int sqlite3Atoi(const char*);
20458 #ifndef SQLITE_OMIT_UTF16
@@ -33722,10 +33769,30 @@
33722 z = sqlite3VMPrintf(db, zFormat, ap);
33723 va_end(ap);
33724 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
33725 }
33726 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33727
33728 /*
33729 ** Add an error message to pParse->zErrMsg and increment pParse->nErr.
33730 **
33731 ** This function should be used to report any error that occurs while
@@ -34180,15 +34247,18 @@
34180 #if defined(_MSC_VER)
34181 #pragma warning(default : 4756)
34182 #endif
34183
34184 /*
34185 ** Render an signed 64-bit integer as text. Store the result in zOut[].
 
 
 
34186 **
34187 ** The caller must ensure that zOut[] is at least 21 bytes in size.
34188 */
34189 SQLITE_PRIVATE void sqlite3Int64ToText(i64 v, char *zOut){
34190 int i;
34191 u64 x;
34192 char zTemp[22];
34193 if( v<0 ){
34194 x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
@@ -34201,10 +34271,11 @@
34201 zTemp[i--] = (x%10) + '0';
34202 x = x/10;
34203 }while( x );
34204 if( v<0 ) zTemp[i--] = '-';
34205 memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i);
 
34206 }
34207
34208 /*
34209 ** Compare the 19-character string zNum against the text representation
34210 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -35530,16 +35601,17 @@
35530 h = 0;
35531 elem = pH->first;
35532 count = pH->count;
35533 }
35534 if( pHash ) *pHash = h;
35535 while( count-- ){
35536 assert( elem!=0 );
35537 if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
35538 return elem;
35539 }
35540 elem = elem->next;
 
35541 }
35542 return &nullElement;
35543 }
35544
35545 /* Remove a single entry from the hash table given a pointer to that
@@ -36259,12 +36331,11 @@
36259 c = aIn[++i];
36260 }
36261 if( j+n>nOut ) return -1;
36262 memset(&aOut[j], 0, n);
36263 j += n;
36264 c = aIn[i];
36265 if( c==0 ) break;
36266 }else{
36267 aOut[j] = c<<4;
36268 c = kvvfsHexValue[aIn[++i]];
36269 if( c<0 ) break;
36270 aOut[j++] += c;
@@ -43287,16 +43358,14 @@
43287 assert( nName>0 );
43288 assert( zName!=0 );
43289 if( zName[0]=='.' ){
43290 if( nName==1 ) return;
43291 if( zName[1]=='.' && nName==2 ){
43292 if( pPath->nUsed<=1 ){
43293 pPath->rc = SQLITE_ERROR;
43294 return;
43295 }
43296 assert( pPath->zOut[0]=='/' );
43297 while( pPath->zOut[--pPath->nUsed]!='/' ){}
43298 return;
43299 }
43300 }
43301 if( pPath->nUsed + nName + 2 >= pPath->nOut ){
43302 pPath->rc = SQLITE_ERROR;
@@ -67958,12 +68027,12 @@
67958 #define ISAUTOVACUUM(pBt) 0
67959 #endif
67960
67961
67962 /*
67963 ** This structure is passed around through all the sanity checking routines
67964 ** in order to keep track of some global state information.
67965 **
67966 ** The aRef[] array is allocated so that there is 1 bit for each page in
67967 ** the database. As the integrity-check proceeds, for each page used in
67968 ** the database the corresponding bit is set. This allows integrity-check to
67969 ** detect pages that are used twice and orphaned pages (both of which
@@ -67975,11 +68044,12 @@
67975 Pager *pPager; /* The associated pager. Also accessible by pBt->pPager */
67976 u8 *aPgRef; /* 1 bit per page in the db (see above) */
67977 Pgno nPage; /* Number of pages in the database */
67978 int mxErr; /* Stop accumulating errors when this reaches zero */
67979 int nErr; /* Number of messages written to zErrMsg so far */
67980 int bOomFault; /* A memory allocation error has occurred */
 
67981 const char *zPfx; /* Error message prefix */
67982 Pgno v1; /* Value for first %u substitution in zPfx */
67983 int v2; /* Value for second %d substitution in zPfx */
67984 StrAccum errMsg; /* Accumulate the error message text here */
67985 u32 *heap; /* Min-heap used for analyzing cell coverage */
@@ -77219,31 +77289,31 @@
77219 return SQLITE_OK;
77220 }
77221
77222 /*
77223 ** Overwrite the cell that cursor pCur is pointing to with fresh content
77224 ** contained in pX.
 
77225 */
77226 static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
 
 
 
77227 int iOffset; /* Next byte of pX->pData to write */
77228 int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
77229 int rc; /* Return code */
77230 MemPage *pPage = pCur->pPage; /* Page being written */
77231 BtShared *pBt; /* Btree */
77232 Pgno ovflPgno; /* Next overflow page to write */
77233 u32 ovflPageSize; /* Size to write on overflow page */
77234
77235 if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
77236 || pCur->info.pPayload < pPage->aData + pPage->cellOffset
77237 ){
77238 return SQLITE_CORRUPT_BKPT;
77239 }
77240 /* Overwrite the local portion first */
77241 rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
77242 0, pCur->info.nLocal);
77243 if( rc ) return rc;
77244 if( pCur->info.nLocal==nTotal ) return SQLITE_OK;
77245
77246 /* Now overwrite the overflow pages */
77247 iOffset = pCur->info.nLocal;
77248 assert( nTotal>=0 );
77249 assert( iOffset>=0 );
@@ -77268,10 +77338,33 @@
77268 if( rc ) return rc;
77269 iOffset += ovflPageSize;
77270 }while( iOffset<nTotal );
77271 return SQLITE_OK;
77272 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77273
77274
77275 /*
77276 ** Insert a new record into the BTree. The content of the new record
77277 ** is described by the pX object. The pCur cursor is used only to
@@ -78463,19 +78556,55 @@
78463 SQLITE_PRIVATE Pager *sqlite3BtreePager(Btree *p){
78464 return p->pBt->pPager;
78465 }
78466
78467 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78468 /*
78469 ** Append a message to the error message string.
78470 */
78471 static void checkAppendMsg(
78472 IntegrityCk *pCheck,
78473 const char *zFormat,
78474 ...
78475 ){
78476 va_list ap;
 
78477 if( !pCheck->mxErr ) return;
78478 pCheck->mxErr--;
78479 pCheck->nErr++;
78480 va_start(ap, zFormat);
78481 if( pCheck->errMsg.nChar ){
@@ -78485,11 +78614,11 @@
78485 sqlite3_str_appendf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2);
78486 }
78487 sqlite3_str_vappendf(&pCheck->errMsg, zFormat, ap);
78488 va_end(ap);
78489 if( pCheck->errMsg.accError==SQLITE_NOMEM ){
78490 pCheck->bOomFault = 1;
78491 }
78492 }
78493 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
78494
78495 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -78527,11 +78656,10 @@
78527 }
78528 if( getPageReferenced(pCheck, iPage) ){
78529 checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
78530 return 1;
78531 }
78532 if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1;
78533 setPageReferenced(pCheck, iPage);
78534 return 0;
78535 }
78536
78537 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -78550,11 +78678,11 @@
78550 u8 ePtrmapType;
78551 Pgno iPtrmapParent;
78552
78553 rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
78554 if( rc!=SQLITE_OK ){
78555 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->bOomFault = 1;
78556 checkAppendMsg(pCheck, "Failed to read ptrmap key=%d", iChild);
78557 return;
78558 }
78559
78560 if( ePtrmapType!=eType || iPtrmapParent!=iParent ){
@@ -78734,10 +78862,12 @@
78734 int saved_v2 = pCheck->v2;
78735 u8 savedIsInit = 0;
78736
78737 /* Check that the page exists
78738 */
 
 
78739 pBt = pCheck->pBt;
78740 usableSize = pBt->usableSize;
78741 if( iPage==0 ) return 0;
78742 if( checkRef(pCheck, iPage) ) return 0;
78743 pCheck->zPfx = "Page %u: ";
@@ -78979,17 +79109,18 @@
78979 ** and the checks to make sure every page is referenced are also skipped,
78980 ** since obviously it is not possible to know which pages are covered by
78981 ** the unverified btrees. Except, if aRoot[1] is 1, then the freelist
78982 ** checks are still performed.
78983 */
78984 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
78985 sqlite3 *db, /* Database connection that is running the check */
78986 Btree *p, /* The btree to be checked */
78987 Pgno *aRoot, /* An array of root pages numbers for individual trees */
78988 int nRoot, /* Number of entries in aRoot[] */
78989 int mxErr, /* Stop reporting errors after this many */
78990 int *pnErr /* Write number of errors seen to this variable */
 
78991 ){
78992 Pgno i;
78993 IntegrityCk sCheck;
78994 BtShared *pBt = p->pBt;
78995 u64 savedDbFlags = pBt->db->flags;
@@ -79008,36 +79139,30 @@
79008
79009 sqlite3BtreeEnter(p);
79010 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
79011 VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
79012 assert( nRef>=0 );
 
79013 sCheck.db = db;
79014 sCheck.pBt = pBt;
79015 sCheck.pPager = pBt->pPager;
79016 sCheck.nPage = btreePagecount(sCheck.pBt);
79017 sCheck.mxErr = mxErr;
79018 sCheck.nErr = 0;
79019 sCheck.bOomFault = 0;
79020 sCheck.zPfx = 0;
79021 sCheck.v1 = 0;
79022 sCheck.v2 = 0;
79023 sCheck.aPgRef = 0;
79024 sCheck.heap = 0;
79025 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
79026 sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL;
79027 if( sCheck.nPage==0 ){
79028 goto integrity_ck_cleanup;
79029 }
79030
79031 sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1);
79032 if( !sCheck.aPgRef ){
79033 sCheck.bOomFault = 1;
79034 goto integrity_ck_cleanup;
79035 }
79036 sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
79037 if( sCheck.heap==0 ){
79038 sCheck.bOomFault = 1;
79039 goto integrity_ck_cleanup;
79040 }
79041
79042 i = PENDING_BYTE_PAGE(pBt);
79043 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
@@ -79114,20 +79239,21 @@
79114 /* Clean up and report errors.
79115 */
79116 integrity_ck_cleanup:
79117 sqlite3PageFree(sCheck.heap);
79118 sqlite3_free(sCheck.aPgRef);
79119 if( sCheck.bOomFault ){
 
79120 sqlite3_str_reset(&sCheck.errMsg);
79121 sCheck.nErr++;
 
 
79122 }
79123 *pnErr = sCheck.nErr;
79124 if( sCheck.nErr==0 ) sqlite3_str_reset(&sCheck.errMsg);
79125 /* Make sure this analysis did not leave any unref() pages. */
79126 assert( nRef==sqlite3PagerRefcount(pBt->pPager) );
79127 sqlite3BtreeLeave(p);
79128 return sqlite3StrAccumFinish(&sCheck.errMsg);
79129 }
79130 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
79131
79132 /*
79133 ** Return the full pathname of the underlying database file. Return
@@ -80309,20 +80435,21 @@
80309 /* Work-around for GCC bug
80310 ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 */
80311 i64 x;
80312 assert( (p->flags&MEM_Int)*2==sizeof(x) );
80313 memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2);
80314 sqlite3Int64ToText(x, zBuf);
80315 #else
80316 sqlite3Int64ToText(p->u.i, zBuf);
80317 #endif
80318 }else{
80319 sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
80320 sqlite3_str_appendf(&acc, "%!.15g",
80321 (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
80322 assert( acc.zText==zBuf && acc.mxAlloc<=0 );
80323 zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
 
80324 }
80325 }
80326
80327 #ifdef SQLITE_DEBUG
80328 /*
@@ -80346,10 +80473,11 @@
80346 ** true if everything is ok and false if there is a problem.
80347 **
80348 ** This routine is for use inside of assert() statements only.
80349 */
80350 SQLITE_PRIVATE int sqlite3VdbeMemValidStrRep(Mem *p){
 
80351 char zBuf[100];
80352 char *z;
80353 int i, j, incr;
80354 if( (p->flags & MEM_Str)==0 ) return 1;
80355 if( p->flags & MEM_Term ){
@@ -80362,11 +80490,12 @@
80362 assert( p->z[p->n]==0 );
80363 assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 );
80364 assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
80365 }
80366 if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
80367 vdbeMemRenderNum(sizeof(zBuf), zBuf, p);
 
80368 z = p->z;
80369 i = j = 0;
80370 incr = 1;
80371 if( p->enc!=SQLITE_UTF8 ){
80372 incr = 2;
@@ -80631,11 +80760,11 @@
80631 return SQLITE_NOMEM_BKPT;
80632 }
80633
80634 vdbeMemRenderNum(nByte, pMem->z, pMem);
80635 assert( pMem->z!=0 );
80636 pMem->n = sqlite3Strlen30NN(pMem->z);
80637 pMem->enc = SQLITE_UTF8;
80638 pMem->flags |= MEM_Str|MEM_Term;
80639 if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
80640 sqlite3VdbeChangeEncoding(pMem, enc);
80641 return SQLITE_OK;
@@ -80871,36 +81000,39 @@
80871 if( pMem->flags & MEM_Null ) return ifNull;
80872 return sqlite3VdbeRealValue(pMem)!=0.0;
80873 }
80874
80875 /*
80876 ** The MEM structure is already a MEM_Real. Try to also make it a
80877 ** MEM_Int if we can.
80878 */
80879 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
80880 i64 ix;
80881 assert( pMem!=0 );
80882 assert( pMem->flags & MEM_Real );
80883 assert( !sqlite3VdbeMemIsRowSet(pMem) );
80884 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
80885 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
80886
80887 ix = doubleToInt64(pMem->u.r);
80888
80889 /* Only mark the value as an integer if
80890 **
80891 ** (1) the round-trip conversion real->int->real is a no-op, and
80892 ** (2) The integer is neither the largest nor the smallest
80893 ** possible integer (ticket #3922)
80894 **
80895 ** The second and third terms in the following conditional enforces
80896 ** the second condition under the assumption that addition overflow causes
80897 ** values to wrap around.
80898 */
80899 if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
80900 pMem->u.i = ix;
80901 MemSetTypeFlag(pMem, MEM_Int);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80902 }
80903 }
80904
80905 /*
80906 ** Convert pMem to type integer. Invalidate any prior representations.
@@ -82755,10 +82887,13 @@
82755 }else{
82756 #ifdef SQLITE_DEBUG
82757 int i;
82758 for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1;
82759 #endif
 
 
 
82760 p->nLabelAlloc = nNewSize;
82761 p->aLabel[j] = v->nOp;
82762 }
82763 }
82764 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
@@ -90423,11 +90558,11 @@
90423 ){
90424 if( affinity>=SQLITE_AFF_NUMERIC ){
90425 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
90426 || affinity==SQLITE_AFF_NUMERIC || affinity==SQLITE_AFF_FLEXNUM );
90427 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
90428 if( (pRec->flags & MEM_Real)==0 ){
90429 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
90430 }else if( affinity<=SQLITE_AFF_REAL ){
90431 sqlite3VdbeIntegerAffinity(pRec);
90432 }
90433 }
@@ -91179,10 +91314,16 @@
91179 int pcx;
91180
91181 #ifdef SQLITE_DEBUG
91182 if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
91183 #endif
 
 
 
 
 
 
91184 if( p->pFrame && pOp->p1==SQLITE_OK ){
91185 /* Halt the sub-program. Return control to the parent frame. */
91186 pFrame = p->pFrame;
91187 p->pFrame = pFrame->pParent;
91188 p->nFrame--;
@@ -93171,11 +93312,11 @@
93171 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
93172 break;
93173 }
93174 case COLTYPE_REAL: {
93175 testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
93176 testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal );
93177 if( pIn1->flags & MEM_Int ){
93178 /* When applying REAL affinity, if the result is still an MEM_Int
93179 ** that will fit in 6 bytes, then change the type to MEM_IntReal
93180 ** so that we keep the high-resolution integer value but know that
93181 ** the type really wants to be REAL. */
@@ -96148,10 +96289,13 @@
96148 ** The next use of the Rowid or Column or Next instruction for P1
96149 ** will refer to the first entry in the database table or index.
96150 ** If the table or index is empty, jump immediately to P2.
96151 ** If the table or index is not empty, fall through to the following
96152 ** instruction.
 
 
 
96153 **
96154 ** This opcode leaves the cursor configured to move in forward order,
96155 ** from the beginning toward the end. In other words, the cursor is
96156 ** configured to use Next, not Prev.
96157 */
@@ -96160,10 +96304,12 @@
96160 BtCursor *pCrsr;
96161 int res;
96162
96163 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96164 assert( pOp->p5==0 );
 
 
96165 pC = p->apCsr[pOp->p1];
96166 assert( pC!=0 );
96167 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
96168 res = 1;
96169 #ifdef SQLITE_DEBUG
@@ -96179,13 +96325,14 @@
96179 pC->deferredMoveto = 0;
96180 pC->cacheStatus = CACHE_STALE;
96181 }
96182 if( rc ) goto abort_due_to_error;
96183 pC->nullRow = (u8)res;
96184 assert( pOp->p2>0 && pOp->p2<p->nOp );
96185 VdbeBranchTaken(res!=0,2);
96186 if( res ) goto jump_to_p2;
 
96187 break;
96188 }
96189
96190 /* Opcode: Next P1 P2 P3 * P5
96191 **
@@ -96987,17 +97134,18 @@
96987 assert( (pnErr->flags & MEM_Int)!=0 );
96988 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
96989 pIn1 = &aMem[pOp->p1];
96990 assert( pOp->p5<db->nDb );
96991 assert( DbMaskTest(p->btreeMask, pOp->p5) );
96992 z = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot,
96993 (int)pnErr->u.i+1, &nErr);
96994 sqlite3VdbeMemSetNull(pIn1);
96995 if( nErr==0 ){
96996 assert( z==0 );
96997 }else if( z==0 ){
96998 goto no_mem;
 
96999 }else{
97000 pnErr->u.i -= nErr-1;
97001 sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
97002 }
97003 UPDATE_MAX_BLOBSIZE(pIn1);
@@ -103838,10 +103986,11 @@
103838 assert( ExprUseYTab(pExpr) );
103839 pExpr->y.pTab = pTab;
103840 if( pParse->bReturning ){
103841 eNewExprOp = TK_REGISTER;
103842 pExpr->op2 = TK_COLUMN;
 
103843 pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
103844 sqlite3TableColumnToStorage(pTab, iCol) + 1;
103845 }else{
103846 pExpr->iColumn = (i16)iCol;
103847 eNewExprOp = TK_TRIGGER;
@@ -132018,10 +132167,12 @@
132018 unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
132019 unsigned int);
132020 const char *(*db_name)(sqlite3*,int);
132021 /* Version 3.40.0 and later */
132022 int (*value_encoding)(sqlite3_value*);
 
 
132023 };
132024
132025 /*
132026 ** This is the function signature used for all extension entry points. It
132027 ** is also defined in the file "loadext.c".
@@ -132344,10 +132495,12 @@
132344 #define sqlite3_serialize sqlite3_api->serialize
132345 #endif
132346 #define sqlite3_db_name sqlite3_api->db_name
132347 /* Version 3.40.0 and later */
132348 #define sqlite3_value_encoding sqlite3_api->value_encoding
 
 
132349 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
132350
132351 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
132352 /* This case when the file really is being compiled as a loadable
132353 ** extension */
@@ -132858,11 +133011,13 @@
132858 0,
132859 0,
132860 #endif
132861 sqlite3_db_name,
132862 /* Version 3.40.0 and later */
132863 sqlite3_value_encoding
 
 
132864 };
132865
132866 /* True if x is the directory separator character
132867 */
132868 #if SQLITE_OS_WIN
@@ -135868,11 +136023,12 @@
135868 sqlite3ExprListDelete(db, pCheck);
135869 }
135870 if( !isQuick ){ /* Omit the remaining tests for quick_check */
135871 /* Validate index entries for the current row */
135872 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
135873 int jmp2, jmp3, jmp4, jmp5;
 
135874 int ckUniq = sqlite3VdbeMakeLabel(pParse);
135875 if( pPk==pIdx ) continue;
135876 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
135877 pPrior, r1);
135878 pPrior = pIdx;
@@ -135886,17 +136042,36 @@
135886 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
135887 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
135888 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
135889 jmp4 = integrityCheckResultRow(v);
135890 sqlite3VdbeJumpHere(v, jmp2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135891 /* For UNIQUE indexes, verify that only one entry exists with the
135892 ** current key. The entry is unique if (1) any column is NULL
135893 ** or (2) the next entry has a different key */
135894 if( IsUniqueIndex(pIdx) ){
135895 int uniqOk = sqlite3VdbeMakeLabel(pParse);
135896 int jmp6;
135897 int kk;
135898 for(kk=0; kk<pIdx->nKeyCol; kk++){
135899 int iCol = pIdx->aiColumn[kk];
135900 assert( iCol!=XN_ROWID && iCol<pTab->nCol );
135901 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
135902 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
@@ -139696,11 +139871,10 @@
139696 #ifdef SQLITE_ENABLE_COLUMN_METADATA
139697 # define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)
139698 #else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
139699 # define columnType(A,B,C,D,E) columnTypeImpl(A,B)
139700 #endif
139701 #ifndef SQLITE_OMIT_DECLTYPE
139702 static const char *columnTypeImpl(
139703 NameContext *pNC,
139704 #ifndef SQLITE_ENABLE_COLUMN_METADATA
139705 Expr *pExpr
139706 #else
@@ -139727,11 +139901,11 @@
139727 ** database table or a subquery.
139728 */
139729 Table *pTab = 0; /* Table structure column is extracted from */
139730 Select *pS = 0; /* Select the column is extracted from */
139731 int iCol = pExpr->iColumn; /* Index of column in pTab */
139732 while( ALWAYS(pNC) && !pTab ){
139733 SrcList *pTabList = pNC->pSrcList;
139734 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
139735 if( j<pTabList->nSrc ){
139736 pTab = pTabList->a[j].pTab;
139737 pS = pTabList->a[j].pSelect;
@@ -139738,11 +139912,11 @@
139738 }else{
139739 pNC = pNC->pNext;
139740 }
139741 }
139742
139743 if( NEVER(pTab==0) ){
139744 /* At one time, code such as "SELECT new.x" within a trigger would
139745 ** cause this condition to run. Since then, we have restructured how
139746 ** trigger code is generated and so this condition is no longer
139747 ** possible. However, it can still be true for statements like
139748 ** the following:
@@ -139843,11 +140017,10 @@
139843 *pzOrigCol = zOrigCol;
139844 }
139845 #endif
139846 return zType;
139847 }
139848 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
139849
139850 /*
139851 ** Generate code that will tell the VDBE the declaration types of columns
139852 ** in the result set.
139853 */
@@ -140039,11 +140212,11 @@
140039 }
140040 assert( nCol==(i16)nCol );
140041 *pnCol = nCol;
140042 *paCol = aCol;
140043
140044 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
140045 struct ExprList_item *pX = &pEList->a[i];
140046 struct ExprList_item *pCollide;
140047 /* Get an appropriate name for the column
140048 */
140049 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
@@ -140089,11 +140262,14 @@
140089 if( nName>0 ){
140090 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
140091 if( zName[j]==':' ) nName = j;
140092 }
140093 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
140094 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
 
 
 
140095 }
140096 pCol->zCnName = zName;
140097 pCol->hName = sqlite3StrIHash(zName);
140098 if( pX->fg.bNoExpand ){
140099 pCol->colFlags |= COLFLAG_NOEXPAND;
@@ -140102,18 +140278,18 @@
140102 if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
140103 sqlite3OomFault(db);
140104 }
140105 }
140106 sqlite3HashClear(&ht);
140107 if( db->mallocFailed ){
140108 for(j=0; j<i; j++){
140109 sqlite3DbFree(db, aCol[j].zCnName);
140110 }
140111 sqlite3DbFree(db, aCol);
140112 *paCol = 0;
140113 *pnCol = 0;
140114 return SQLITE_NOMEM_BKPT;
140115 }
140116 return SQLITE_OK;
140117 }
140118
140119 /*
@@ -140137,18 +140313,21 @@
140137 Column *pCol;
140138 CollSeq *pColl;
140139 int i,j;
140140 Expr *p;
140141 struct ExprList_item *a;
 
140142
140143 assert( pSelect!=0 );
140144 assert( (pSelect->selFlags & SF_Resolved)!=0 );
140145 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
140146 assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
140147 if( db->mallocFailed ) return;
140148 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
140149 a = pSelect->pEList->a;
 
 
140150 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
140151 const char *zType;
140152 i64 n;
140153 pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
140154 p = a[i].pExpr;
@@ -140170,32 +140349,35 @@
140170 }else
140171 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140172 pCol->affinity = SQLITE_AFF_BLOB;
140173 }
140174 }
140175 if( pCol->affinity==SQLITE_AFF_NUMERIC
140176 || pCol->affinity==SQLITE_AFF_FLEXNUM
140177 ){
140178 zType = "NUM";
140179 }else{
140180 zType = 0;
140181 for(j=1; j<SQLITE_N_STDTYPE; j++){
140182 if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
140183 zType = sqlite3StdType[j];
140184 break;
140185 }
140186 }
140187 }
140188 if( zType ){
140189 i64 m = sqlite3Strlen30(zType);
140190 n = sqlite3Strlen30(pCol->zCnName);
140191 pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
140192 if( pCol->zCnName ){
140193 memcpy(&pCol->zCnName[n+1], zType, m+1);
140194 pCol->colFlags |= COLFLAG_HASTYPE;
140195 }else{
140196 testcase( pCol->colFlags & COLFLAG_HASTYPE );
 
 
 
140197 pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
140198 }
140199 }
140200 pColl = sqlite3ExprCollSeq(pParse, p);
140201 if( pColl ){
@@ -156196,10 +156378,17 @@
156196 /* This term is a vector operation that has been decomposed into
156197 ** other, subsequent terms. It can be ignored. See tag-20220128a */
156198 assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
156199 assert( pWC->a[ii].eOperator==WO_ROWVAL );
156200 continue;
 
 
 
 
 
 
 
156201 }
156202 if( pWC->a[ii].leftCursor!=iCsr ) return;
156203 }
156204
156205 /* Check condition (5). Return early if it is not met. */
@@ -159128,10 +159317,11 @@
159128 if( pX==0 ) continue;
159129 if( pX==pTerm ) break;
159130 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
159131 }
159132 if( j<0 ){
 
159133 if( pLoop->maskSelf==pTerm->prereqAll ){
159134 /* If there are extra terms in the WHERE clause not used by an index
159135 ** that depend only on the table being scanned, and that will tend to
159136 ** cause many rows to be omitted, then mark that table as
159137 ** "self-culling".
@@ -159295,11 +159485,14 @@
159295 LogEst rSize; /* Number of rows in the table */
159296 LogEst rLogSize; /* Logarithm of table size */
159297 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
159298
159299 pNew = pBuilder->pNew;
159300 if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
 
 
 
159301 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n",
159302 pProbe->pTable->zName,pProbe->zName,
159303 pNew->u.btree.nEq, pNew->nSkip, pNew->rRun));
159304
159305 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
@@ -159611,10 +159804,13 @@
159611 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
159612 && pNew->u.btree.nEq<pProbe->nColumn
159613 && (pNew->u.btree.nEq<pProbe->nKeyCol ||
159614 pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
159615 ){
 
 
 
159616 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
159617 }
159618 pNew->nOut = saved_nOut;
159619 #ifdef SQLITE_ENABLE_STAT4
159620 pBuilder->nRecValid = nRecValid;
@@ -160770,12 +160966,10 @@
160770 rc = whereLoopAddBtree(&sSubBuild, mPrereq);
160771 }
160772 if( rc==SQLITE_OK ){
160773 rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
160774 }
160775 assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0
160776 || rc==SQLITE_NOMEM );
160777 testcase( rc==SQLITE_NOMEM && sCur.n>0 );
160778 testcase( rc==SQLITE_DONE );
160779 if( sCur.n==0 ){
160780 sSum.n = 0;
160781 break;
@@ -166126,12 +166320,11 @@
166126 int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
166127 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
166128 VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because bound <expr> */
166129 VdbeCoverageNeverNullIf(v, op==OP_Le); /* values previously checked */
166130 windowAggFinal(&s, 0);
166131 sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
166132 VdbeCoverageNeverTaken(v);
166133 windowReturnOneRow(&s);
166134 sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
166135 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
166136 sqlite3VdbeJumpHere(v, addrGe);
166137 }
@@ -166139,17 +166332,14 @@
166139 assert( pMWin->eEnd==TK_FOLLOWING );
166140 sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regStart);
166141 }
166142
166143 if( pMWin->eStart!=TK_UNBOUNDED ){
166144 sqlite3VdbeAddOp2(v, OP_Rewind, s.start.csr, 1);
166145 VdbeCoverageNeverTaken(v);
166146 }
166147 sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
166148 VdbeCoverageNeverTaken(v);
166149 sqlite3VdbeAddOp2(v, OP_Rewind, s.end.csr, 1);
166150 VdbeCoverageNeverTaken(v);
166151 if( regPeer && pOrderBy ){
166152 sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, pOrderBy->nExpr-1);
166153 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.start.reg, pOrderBy->nExpr-1);
166154 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.current.reg, pOrderBy->nExpr-1);
166155 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.end.reg, pOrderBy->nExpr-1);
@@ -175259,18 +175449,35 @@
175259 /*
175260 ** Cause any pending operation to stop at its earliest opportunity.
175261 */
175262 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
175263 #ifdef SQLITE_ENABLE_API_ARMOR
175264 if( !sqlite3SafetyCheckOk(db) && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE) ){
 
 
175265 (void)SQLITE_MISUSE_BKPT;
175266 return;
175267 }
175268 #endif
175269 AtomicStore(&db->u1.isInterrupted, 1);
175270 }
175271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175272
175273 /*
175274 ** This function is exactly the same as sqlite3_create_function(), except
175275 ** that it is designed to be called by internal code. The difference is
175276 ** that if a malloc() fails in sqlite3_create_function(), an error code
@@ -175311,11 +175518,11 @@
175311 enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
175312
175313 /* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But
175314 ** the meaning is inverted. So flip the bit. */
175315 assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS );
175316 extraFlags ^= SQLITE_FUNC_UNSAFE;
175317
175318
175319 #ifndef SQLITE_OMIT_UTF16
175320 /* If SQLITE_UTF16 is specified as the encoding type, transform this
175321 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
@@ -175329,15 +175536,15 @@
175329 enc = SQLITE_UTF16NATIVE;
175330 break;
175331 case SQLITE_ANY: {
175332 int rc;
175333 rc = sqlite3CreateFunc(db, zFunctionName, nArg,
175334 (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
175335 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
175336 if( rc==SQLITE_OK ){
175337 rc = sqlite3CreateFunc(db, zFunctionName, nArg,
175338 (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
175339 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
175340 }
175341 if( rc!=SQLITE_OK ){
175342 return rc;
175343 }
@@ -212650,11 +212857,12 @@
212650 ** leave an error code and error message in the rbu handle.
212651 */
212652 static void rbuDeleteOalFile(sqlite3rbu *p){
212653 char *zOal = rbuMPrintf(p, "%s-oal", p->zTarget);
212654 if( zOal ){
212655 sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
 
212656 assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
212657 pVfs->xDelete(pVfs, zOal, 0);
212658 sqlite3_free(zOal);
212659 }
212660 }
@@ -213407,13 +213615,16 @@
213407 sqlite3_free(p->apShm);
213408 p->apShm = 0;
213409 sqlite3_free(p->zDel);
213410
213411 if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
 
213412 rbuMainlistRemove(p);
213413 rbuUnlockShm(p);
213414 p->pReal->pMethods->xShmUnmap(p->pReal, 0);
 
 
213415 }
213416 else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){
213417 rbuUpdateTempSize(p, 0);
213418 }
213419 assert( p->pMainNext==0 && p->pRbuVfs->pMain!=p );
@@ -213868,10 +214079,29 @@
213868 rbuVfsShmLock, /* xShmLock */
213869 rbuVfsShmBarrier, /* xShmBarrier */
213870 rbuVfsShmUnmap, /* xShmUnmap */
213871 0, 0 /* xFetch, xUnfetch */
213872 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213873 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
213874 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
213875 rbu_file *pFd = (rbu_file *)pFile;
213876 int rc = SQLITE_OK;
213877 const char *zOpen = zName;
@@ -213922,14 +214152,19 @@
213922
213923 if( rc==SQLITE_OK ){
213924 rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags);
213925 }
213926 if( pFd->pReal->pMethods ){
 
213927 /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
213928 ** pointer and, if the file is a main database file, link it into the
213929 ** mutex protected linked list of all such files. */
213930 pFile->pMethods = &rbuvfs_io_methods;
 
 
 
 
213931 if( flags & SQLITE_OPEN_MAIN_DB ){
213932 rbuMainlistAdd(pFd);
213933 }
213934 }else{
213935 sqlite3_free(pFd->zDel);
@@ -239641,11 +239876,11 @@
239641 int nArg, /* Number of args */
239642 sqlite3_value **apUnused /* Function arguments */
239643 ){
239644 assert( nArg==0 );
239645 UNUSED_PARAM2(nArg, apUnused);
239646 sqlite3_result_text(pCtx, "fts5: 2022-12-27 22:46:49 e8afad630b085a9208491e0516a6a30c9cda77a20b1aa2cba49b2f44eb9fa2f8", -1, SQLITE_TRANSIENT);
239647 }
239648
239649 /*
239650 ** Return true if zName is the extension on one of the shadow tables used
239651 ** by this module.
239652
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.41.0"
456 #define SQLITE_VERSION_NUMBER 3041000
457 #define SQLITE_SOURCE_ID "2023-01-16 18:13:00 83f21285fe86430a66ce6841606e3ad7c27da52ac75a034c6a00c7a9fdb9791d"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -2983,12 +2983,16 @@
2983 ** that are started after the running statement count reaches zero are
2984 ** not effected by the sqlite3_interrupt().
2985 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2986 ** SQL statements is a no-op and has no effect on SQL statements
2987 ** that are started after the sqlite3_interrupt() call returns.
2988 **
2989 ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2990 ** or not an interrupt is currently in effect for [database connection] D.
2991 */
2992 SQLITE_API void sqlite3_interrupt(sqlite3*);
2993 SQLITE_API int sqlite3_is_interrupted(sqlite3*);
2994
2995 /*
2996 ** CAPI3REF: Determine If An SQL Statement Is Complete
2997 **
2998 ** These routines are useful during command-line input to determine if the
@@ -3666,11 +3670,11 @@
3670 ** CAPI3REF: Query Progress Callbacks
3671 ** METHOD: sqlite3
3672 **
3673 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3674 ** function X to be invoked periodically during long running calls to
3675 ** [sqlite3_step()] and [sqlite3_prepare()] and similar for
3676 ** database connection D. An example use for this
3677 ** interface is to keep a GUI updated during a large query.
3678 **
3679 ** ^The parameter P is passed through as the only parameter to the
3680 ** callback function X. ^The parameter N is the approximate number of
@@ -3691,10 +3695,17 @@
3695 ** The progress handler callback must not do anything that will modify
3696 ** the database connection that invoked the progress handler.
3697 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3698 ** database connections for the meaning of "modify" in this paragraph.
3699 **
3700 ** The progress handler callback would originally only be invoked from the
3701 ** bytecode engine. It still might be invoked during [sqlite3_prepare()]
3702 ** and similar because those routines might force a reparse of the schema
3703 ** which involves running the bytecode engine. However, beginning with
3704 ** SQLite version 3.41.0, the progress handler callback might also be
3705 ** invoked directly from [sqlite3_prepare()] while analyzing and generating
3706 ** code for complex queries.
3707 */
3708 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3709
3710 /*
3711 ** CAPI3REF: Opening A New Database Connection
@@ -3727,17 +3738,22 @@
3738 ** sqlite3_open_v2() must include, at a minimum, one of the following
3739 ** three flag combinations:)^
3740 **
3741 ** <dl>
3742 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3743 ** <dd>The database is opened in read-only mode. If the database does
3744 ** not already exist, an error is returned.</dd>)^
3745 **
3746 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3747 ** <dd>The database is opened for reading and writing if possible, or
3748 ** reading only if the file is write protected by the operating
3749 ** system. In either case the database must already exist, otherwise
3750 ** an error is returned. For historical reasons, if opening in
3751 ** read-write mode fails due to OS-level permissions, an attempt is
3752 ** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3753 ** used to determine whether the database is actually
3754 ** read-write.</dd>)^
3755 **
3756 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3757 ** <dd>The database is opened for reading and writing, and is created if
3758 ** it does not already exist. This is the behavior that is always used for
3759 ** sqlite3_open() and sqlite3_open16().</dd>)^
@@ -5714,14 +5730,25 @@
5730 ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
5731 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5732 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5733 ** schema structures such as [CHECK constraints], [DEFAULT clauses],
5734 ** [expression indexes], [partial indexes], or [generated columns].
5735 ** <p>
5736 ** The SQLITE_DIRECTONLY flag is recommended for any
5737 ** [application-defined SQL function]
5738 ** that has side-effects or that could potentially leak sensitive information.
5739 ** This will prevent attacks in which an application is tricked
5740 ** into using a database file that has had its schema surreptiously
5741 ** modified to invoke the application-defined function in ways that are
5742 ** harmful.
5743 ** <p>
5744 ** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5745 ** [application-defined SQL functions], regardless of whether or not they
5746 ** are security sensitive, as doing so prevents those functions from being used
5747 ** inside of the database schema, and thus ensures that the database
5748 ** can be inspected and modified using generic tools (such as the [CLI])
5749 ** that do not have access to the application-defined functions.
5750 ** </dd>
5751 **
5752 ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
5753 ** The SQLITE_INNOCUOUS flag means that the function is unlikely
5754 ** to cause problems even if misused. An innocuous function should have
@@ -7441,14 +7468,14 @@
7468 ** checked separately in byte code. If the omit flag is change to true, then
7469 ** the constraint may or may not be checked in byte code. In other words,
7470 ** when the omit flag is true there is no guarantee that the constraint will
7471 ** not be checked again using byte code.)^
7472 **
7473 ** ^The idxNum and idxStr values are recorded and passed into the
7474 ** [xFilter] method.
7475 ** ^[sqlite3_free()] is used to free idxStr if and only if
7476 ** needToFreeIdxStr is true.
7477 **
7478 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
7479 ** the correct order to satisfy the ORDER BY clause so that no separate
7480 ** sorting step is required.
7481 **
@@ -10400,10 +10427,14 @@
10427 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
10428 ** seventh parameter is the final rowid value of the row being inserted
10429 ** or updated. The value of the seventh parameter passed to the callback
10430 ** function is not defined for operations on WITHOUT ROWID tables, or for
10431 ** DELETE operations on rowid tables.
10432 **
10433 ** ^The sqlite3_update_hook(D,C,P) function returns the P argument from
10434 ** the previous call on the same [database connection] D, or NULL for
10435 ** the first call on D.
10436 **
10437 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
10438 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
10439 ** provide additional information about a preupdate event. These routines
10440 ** may only be called from within a preupdate callback. Invoking any of
@@ -15767,11 +15798,19 @@
15798 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
15799 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
15800 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
15801 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
15802
15803 SQLITE_PRIVATE int sqlite3BtreeIntegrityCheck(
15804 sqlite3 *db, /* Database connection that is running the check */
15805 Btree *p, /* The btree to be checked */
15806 Pgno *aRoot, /* An array of root pages numbers for individual trees */
15807 int nRoot, /* Number of entries in aRoot[] */
15808 int mxErr, /* Stop reporting errors after this many */
15809 int *pnErr, /* OUT: Write number of errors seen to this variable */
15810 char **pzOut /* OUT: Write the error message string here */
15811 );
15812 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
15813 SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
15814
15815 #ifndef SQLITE_OMIT_INCRBLOB
15816 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
@@ -17373,12 +17412,18 @@
17412 ** SQLITE_FUNC_ANYORDER == NC_OrderAgg == SF_OrderByReqd
17413 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
17414 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
17415 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
17416 ** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API
17417 ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!!
17418 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
17419 **
17420 ** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the
17421 ** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is
17422 ** used internally and if set means tha the function has side effects.
17423 ** SQLITE_INNOCUOUS is used by application code and means "not unsafe".
17424 ** See multiple instances of tag-20230109-1.
17425 */
17426 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
17427 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
17428 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
17429 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -17491,11 +17536,11 @@
17536 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
17537 #define MFUNCTION(zName, nArg, xPtr, xFunc) \
17538 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
17539 xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
17540 #define JFUNCTION(zName, nArg, iArg, xFunc) \
17541 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|\
17542 SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
17543 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
17544 #define INLINE_FUNC(zName, nArg, iArg, mFlags) \
17545 {nArg, SQLITE_FUNC_BUILTIN|\
17546 SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
@@ -19192,10 +19237,13 @@
19237 Returning *pReturning; /* The RETURNING clause */
19238 } u1;
19239 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
19240 u32 oldmask; /* Mask of old.* columns referenced */
19241 u32 newmask; /* Mask of new.* columns referenced */
19242 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
19243 u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
19244 #endif
19245 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
19246 u8 bReturning; /* Coding a RETURNING trigger */
19247 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
19248 u8 disableTriggers; /* True to disable triggers */
19249
@@ -19940,17 +19988,15 @@
19988 ** that deal with sqlite3StackAlloc() failures to be unreachable.
19989 */
19990 #ifdef SQLITE_USE_ALLOCA
19991 # define sqlite3StackAllocRaw(D,N) alloca(N)
19992 # define sqlite3StackAllocRawNN(D,N) alloca(N)
 
19993 # define sqlite3StackFree(D,P)
19994 # define sqlite3StackFreeNN(D,P)
19995 #else
19996 # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
19997 # define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N)
 
19998 # define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
19999 # define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P)
20000 #endif
20001
20002 /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they
@@ -20071,10 +20117,11 @@
20117 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
20118 #endif
20119 #endif
20120
20121 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
20122 SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
20123 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
20124 SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
20125 SQLITE_PRIVATE void sqlite3Dequote(char*);
20126 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
20127 SQLITE_PRIVATE void sqlite3DequoteToken(Token*);
@@ -20448,11 +20495,11 @@
20495 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
20496 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
20497 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
20498 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
20499 SQLITE_PRIVATE i64 sqlite3RealToI64(double);
20500 SQLITE_PRIVATE int sqlite3Int64ToText(i64,char*);
20501 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
20502 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
20503 SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
20504 SQLITE_PRIVATE int sqlite3Atoi(const char*);
20505 #ifndef SQLITE_OMIT_UTF16
@@ -33722,10 +33769,30 @@
33769 z = sqlite3VMPrintf(db, zFormat, ap);
33770 va_end(ap);
33771 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
33772 }
33773 }
33774
33775 /*
33776 ** Check for interrupts and invoke progress callback.
33777 */
33778 SQLITE_PRIVATE void sqlite3ProgressCheck(Parse *p){
33779 sqlite3 *db = p->db;
33780 if( AtomicLoad(&db->u1.isInterrupted) ){
33781 p->nErr++;
33782 p->rc = SQLITE_INTERRUPT;
33783 }
33784 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
33785 if( db->xProgress && (++p->nProgressSteps)>=db->nProgressOps ){
33786 if( db->xProgress(db->pProgressArg) ){
33787 p->nErr++;
33788 p->rc = SQLITE_INTERRUPT;
33789 }
33790 p->nProgressSteps = 0;
33791 }
33792 #endif
33793 }
33794
33795 /*
33796 ** Add an error message to pParse->zErrMsg and increment pParse->nErr.
33797 **
33798 ** This function should be used to report any error that occurs while
@@ -34180,15 +34247,18 @@
34247 #if defined(_MSC_VER)
34248 #pragma warning(default : 4756)
34249 #endif
34250
34251 /*
34252 ** Render an signed 64-bit integer as text. Store the result in zOut[] and
34253 ** return the length of the string that was stored, in bytes. The value
34254 ** returned does not include the zero terminator at the end of the output
34255 ** string.
34256 **
34257 ** The caller must ensure that zOut[] is at least 21 bytes in size.
34258 */
34259 SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){
34260 int i;
34261 u64 x;
34262 char zTemp[22];
34263 if( v<0 ){
34264 x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v;
@@ -34201,10 +34271,11 @@
34271 zTemp[i--] = (x%10) + '0';
34272 x = x/10;
34273 }while( x );
34274 if( v<0 ) zTemp[i--] = '-';
34275 memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i);
34276 return sizeof(zTemp)-2-i;
34277 }
34278
34279 /*
34280 ** Compare the 19-character string zNum against the text representation
34281 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -35530,16 +35601,17 @@
35601 h = 0;
35602 elem = pH->first;
35603 count = pH->count;
35604 }
35605 if( pHash ) *pHash = h;
35606 while( count ){
35607 assert( elem!=0 );
35608 if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
35609 return elem;
35610 }
35611 elem = elem->next;
35612 count--;
35613 }
35614 return &nullElement;
35615 }
35616
35617 /* Remove a single entry from the hash table given a pointer to that
@@ -36259,12 +36331,11 @@
36331 c = aIn[++i];
36332 }
36333 if( j+n>nOut ) return -1;
36334 memset(&aOut[j], 0, n);
36335 j += n;
36336 if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
 
36337 }else{
36338 aOut[j] = c<<4;
36339 c = kvvfsHexValue[aIn[++i]];
36340 if( c<0 ) break;
36341 aOut[j++] += c;
@@ -43287,16 +43358,14 @@
43358 assert( nName>0 );
43359 assert( zName!=0 );
43360 if( zName[0]=='.' ){
43361 if( nName==1 ) return;
43362 if( zName[1]=='.' && nName==2 ){
43363 if( pPath->nUsed>1 ){
43364 assert( pPath->zOut[0]=='/' );
43365 while( pPath->zOut[--pPath->nUsed]!='/' ){}
43366 }
 
 
43367 return;
43368 }
43369 }
43370 if( pPath->nUsed + nName + 2 >= pPath->nOut ){
43371 pPath->rc = SQLITE_ERROR;
@@ -67958,12 +68027,12 @@
68027 #define ISAUTOVACUUM(pBt) 0
68028 #endif
68029
68030
68031 /*
68032 ** This structure is passed around through all the PRAGMA integrity_check
68033 ** checking routines in order to keep track of some global state information.
68034 **
68035 ** The aRef[] array is allocated so that there is 1 bit for each page in
68036 ** the database. As the integrity-check proceeds, for each page used in
68037 ** the database the corresponding bit is set. This allows integrity-check to
68038 ** detect pages that are used twice and orphaned pages (both of which
@@ -67975,11 +68044,12 @@
68044 Pager *pPager; /* The associated pager. Also accessible by pBt->pPager */
68045 u8 *aPgRef; /* 1 bit per page in the db (see above) */
68046 Pgno nPage; /* Number of pages in the database */
68047 int mxErr; /* Stop accumulating errors when this reaches zero */
68048 int nErr; /* Number of messages written to zErrMsg so far */
68049 int rc; /* SQLITE_OK, SQLITE_NOMEM, or SQLITE_INTERRUPT */
68050 u32 nStep; /* Number of steps into the integrity_check process */
68051 const char *zPfx; /* Error message prefix */
68052 Pgno v1; /* Value for first %u substitution in zPfx */
68053 int v2; /* Value for second %d substitution in zPfx */
68054 StrAccum errMsg; /* Accumulate the error message text here */
68055 u32 *heap; /* Min-heap used for analyzing cell coverage */
@@ -77219,31 +77289,31 @@
77289 return SQLITE_OK;
77290 }
77291
77292 /*
77293 ** Overwrite the cell that cursor pCur is pointing to with fresh content
77294 ** contained in pX. In this variant, pCur is pointing to an overflow
77295 ** cell.
77296 */
77297 static SQLITE_NOINLINE int btreeOverwriteOverflowCell(
77298 BtCursor *pCur, /* Cursor pointing to cell to ovewrite */
77299 const BtreePayload *pX /* Content to write into the cell */
77300 ){
77301 int iOffset; /* Next byte of pX->pData to write */
77302 int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
77303 int rc; /* Return code */
77304 MemPage *pPage = pCur->pPage; /* Page being written */
77305 BtShared *pBt; /* Btree */
77306 Pgno ovflPgno; /* Next overflow page to write */
77307 u32 ovflPageSize; /* Size to write on overflow page */
77308
77309 assert( pCur->info.nLocal<nTotal ); /* pCur is an overflow cell */
77310
 
 
 
77311 /* Overwrite the local portion first */
77312 rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
77313 0, pCur->info.nLocal);
77314 if( rc ) return rc;
 
77315
77316 /* Now overwrite the overflow pages */
77317 iOffset = pCur->info.nLocal;
77318 assert( nTotal>=0 );
77319 assert( iOffset>=0 );
@@ -77268,10 +77338,33 @@
77338 if( rc ) return rc;
77339 iOffset += ovflPageSize;
77340 }while( iOffset<nTotal );
77341 return SQLITE_OK;
77342 }
77343
77344 /*
77345 ** Overwrite the cell that cursor pCur is pointing to with fresh content
77346 ** contained in pX.
77347 */
77348 static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
77349 int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
77350 MemPage *pPage = pCur->pPage; /* Page being written */
77351
77352 if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
77353 || pCur->info.pPayload < pPage->aData + pPage->cellOffset
77354 ){
77355 return SQLITE_CORRUPT_BKPT;
77356 }
77357 if( pCur->info.nLocal==nTotal ){
77358 /* The entire cell is local */
77359 return btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
77360 0, pCur->info.nLocal);
77361 }else{
77362 /* The cell contains overflow content */
77363 return btreeOverwriteOverflowCell(pCur, pX);
77364 }
77365 }
77366
77367
77368 /*
77369 ** Insert a new record into the BTree. The content of the new record
77370 ** is described by the pX object. The pCur cursor is used only to
@@ -78463,19 +78556,55 @@
78556 SQLITE_PRIVATE Pager *sqlite3BtreePager(Btree *p){
78557 return p->pBt->pPager;
78558 }
78559
78560 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
78561 /*
78562 ** Record an OOM error during integrity_check
78563 */
78564 static void checkOom(IntegrityCk *pCheck){
78565 pCheck->rc = SQLITE_NOMEM;
78566 pCheck->mxErr = 0; /* Causes integrity_check processing to stop */
78567 if( pCheck->nErr==0 ) pCheck->nErr++;
78568 }
78569
78570 /*
78571 ** Invoke the progress handler, if appropriate. Also check for an
78572 ** interrupt.
78573 */
78574 static void checkProgress(IntegrityCk *pCheck){
78575 sqlite3 *db = pCheck->db;
78576 if( AtomicLoad(&db->u1.isInterrupted) ){
78577 pCheck->rc = SQLITE_INTERRUPT;
78578 pCheck->nErr++;
78579 pCheck->mxErr = 0;
78580 }
78581 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
78582 if( db->xProgress ){
78583 assert( db->nProgressOps>0 );
78584 pCheck->nStep++;
78585 if( (pCheck->nStep % db->nProgressOps)==0
78586 && db->xProgress(db->pProgressArg)
78587 ){
78588 pCheck->rc = SQLITE_INTERRUPT;
78589 pCheck->nErr++;
78590 pCheck->mxErr = 0;
78591 }
78592 }
78593 #endif
78594 }
78595
78596 /*
78597 ** Append a message to the error message string.
78598 */
78599 static void checkAppendMsg(
78600 IntegrityCk *pCheck,
78601 const char *zFormat,
78602 ...
78603 ){
78604 va_list ap;
78605 checkProgress(pCheck);
78606 if( !pCheck->mxErr ) return;
78607 pCheck->mxErr--;
78608 pCheck->nErr++;
78609 va_start(ap, zFormat);
78610 if( pCheck->errMsg.nChar ){
@@ -78485,11 +78614,11 @@
78614 sqlite3_str_appendf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2);
78615 }
78616 sqlite3_str_vappendf(&pCheck->errMsg, zFormat, ap);
78617 va_end(ap);
78618 if( pCheck->errMsg.accError==SQLITE_NOMEM ){
78619 checkOom(pCheck);
78620 }
78621 }
78622 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
78623
78624 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -78527,11 +78656,10 @@
78656 }
78657 if( getPageReferenced(pCheck, iPage) ){
78658 checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
78659 return 1;
78660 }
 
78661 setPageReferenced(pCheck, iPage);
78662 return 0;
78663 }
78664
78665 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -78550,11 +78678,11 @@
78678 u8 ePtrmapType;
78679 Pgno iPtrmapParent;
78680
78681 rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
78682 if( rc!=SQLITE_OK ){
78683 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) checkOom(pCheck);
78684 checkAppendMsg(pCheck, "Failed to read ptrmap key=%d", iChild);
78685 return;
78686 }
78687
78688 if( ePtrmapType!=eType || iPtrmapParent!=iParent ){
@@ -78734,10 +78862,12 @@
78862 int saved_v2 = pCheck->v2;
78863 u8 savedIsInit = 0;
78864
78865 /* Check that the page exists
78866 */
78867 checkProgress(pCheck);
78868 if( pCheck->mxErr==0 ) goto end_of_check;
78869 pBt = pCheck->pBt;
78870 usableSize = pBt->usableSize;
78871 if( iPage==0 ) return 0;
78872 if( checkRef(pCheck, iPage) ) return 0;
78873 pCheck->zPfx = "Page %u: ";
@@ -78979,17 +79109,18 @@
79109 ** and the checks to make sure every page is referenced are also skipped,
79110 ** since obviously it is not possible to know which pages are covered by
79111 ** the unverified btrees. Except, if aRoot[1] is 1, then the freelist
79112 ** checks are still performed.
79113 */
79114 SQLITE_PRIVATE int sqlite3BtreeIntegrityCheck(
79115 sqlite3 *db, /* Database connection that is running the check */
79116 Btree *p, /* The btree to be checked */
79117 Pgno *aRoot, /* An array of root pages numbers for individual trees */
79118 int nRoot, /* Number of entries in aRoot[] */
79119 int mxErr, /* Stop reporting errors after this many */
79120 int *pnErr, /* OUT: Write number of errors seen to this variable */
79121 char **pzOut /* OUT: Write the error message string here */
79122 ){
79123 Pgno i;
79124 IntegrityCk sCheck;
79125 BtShared *pBt = p->pBt;
79126 u64 savedDbFlags = pBt->db->flags;
@@ -79008,36 +79139,30 @@
79139
79140 sqlite3BtreeEnter(p);
79141 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
79142 VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
79143 assert( nRef>=0 );
79144 memset(&sCheck, 0, sizeof(sCheck));
79145 sCheck.db = db;
79146 sCheck.pBt = pBt;
79147 sCheck.pPager = pBt->pPager;
79148 sCheck.nPage = btreePagecount(sCheck.pBt);
79149 sCheck.mxErr = mxErr;
 
 
 
 
 
 
 
79150 sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
79151 sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL;
79152 if( sCheck.nPage==0 ){
79153 goto integrity_ck_cleanup;
79154 }
79155
79156 sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1);
79157 if( !sCheck.aPgRef ){
79158 checkOom(&sCheck);
79159 goto integrity_ck_cleanup;
79160 }
79161 sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
79162 if( sCheck.heap==0 ){
79163 checkOom(&sCheck);
79164 goto integrity_ck_cleanup;
79165 }
79166
79167 i = PENDING_BYTE_PAGE(pBt);
79168 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
@@ -79114,20 +79239,21 @@
79239 /* Clean up and report errors.
79240 */
79241 integrity_ck_cleanup:
79242 sqlite3PageFree(sCheck.heap);
79243 sqlite3_free(sCheck.aPgRef);
79244 *pnErr = sCheck.nErr;
79245 if( sCheck.nErr==0 ){
79246 sqlite3_str_reset(&sCheck.errMsg);
79247 *pzOut = 0;
79248 }else{
79249 *pzOut = sqlite3StrAccumFinish(&sCheck.errMsg);
79250 }
 
 
79251 /* Make sure this analysis did not leave any unref() pages. */
79252 assert( nRef==sqlite3PagerRefcount(pBt->pPager) );
79253 sqlite3BtreeLeave(p);
79254 return sCheck.rc;
79255 }
79256 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
79257
79258 /*
79259 ** Return the full pathname of the underlying database file. Return
@@ -80309,20 +80435,21 @@
80435 /* Work-around for GCC bug
80436 ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 */
80437 i64 x;
80438 assert( (p->flags&MEM_Int)*2==sizeof(x) );
80439 memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2);
80440 p->n = sqlite3Int64ToText(x, zBuf);
80441 #else
80442 p->n = sqlite3Int64ToText(p->u.i, zBuf);
80443 #endif
80444 }else{
80445 sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
80446 sqlite3_str_appendf(&acc, "%!.15g",
80447 (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
80448 assert( acc.zText==zBuf && acc.mxAlloc<=0 );
80449 zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
80450 p->n = acc.nChar;
80451 }
80452 }
80453
80454 #ifdef SQLITE_DEBUG
80455 /*
@@ -80346,10 +80473,11 @@
80473 ** true if everything is ok and false if there is a problem.
80474 **
80475 ** This routine is for use inside of assert() statements only.
80476 */
80477 SQLITE_PRIVATE int sqlite3VdbeMemValidStrRep(Mem *p){
80478 Mem tmp;
80479 char zBuf[100];
80480 char *z;
80481 int i, j, incr;
80482 if( (p->flags & MEM_Str)==0 ) return 1;
80483 if( p->flags & MEM_Term ){
@@ -80362,11 +80490,12 @@
80490 assert( p->z[p->n]==0 );
80491 assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 );
80492 assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
80493 }
80494 if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
80495 memcpy(&tmp, p, sizeof(tmp));
80496 vdbeMemRenderNum(sizeof(zBuf), zBuf, &tmp);
80497 z = p->z;
80498 i = j = 0;
80499 incr = 1;
80500 if( p->enc!=SQLITE_UTF8 ){
80501 incr = 2;
@@ -80631,11 +80760,11 @@
80760 return SQLITE_NOMEM_BKPT;
80761 }
80762
80763 vdbeMemRenderNum(nByte, pMem->z, pMem);
80764 assert( pMem->z!=0 );
80765 assert( pMem->n==sqlite3Strlen30NN(pMem->z) );
80766 pMem->enc = SQLITE_UTF8;
80767 pMem->flags |= MEM_Str|MEM_Term;
80768 if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
80769 sqlite3VdbeChangeEncoding(pMem, enc);
80770 return SQLITE_OK;
@@ -80871,36 +81000,39 @@
81000 if( pMem->flags & MEM_Null ) return ifNull;
81001 return sqlite3VdbeRealValue(pMem)!=0.0;
81002 }
81003
81004 /*
81005 ** The MEM structure is already a MEM_Real or MEM_IntReal. Try to
81006 ** make it a MEM_Int if we can.
81007 */
81008 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
 
81009 assert( pMem!=0 );
81010 assert( pMem->flags & (MEM_Real|MEM_IntReal) );
81011 assert( !sqlite3VdbeMemIsRowSet(pMem) );
81012 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81013 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
81014
81015 if( pMem->flags & MEM_IntReal ){
 
 
 
 
 
 
 
 
 
 
 
 
 
81016 MemSetTypeFlag(pMem, MEM_Int);
81017 }else{
81018 i64 ix = doubleToInt64(pMem->u.r);
81019
81020 /* Only mark the value as an integer if
81021 **
81022 ** (1) the round-trip conversion real->int->real is a no-op, and
81023 ** (2) The integer is neither the largest nor the smallest
81024 ** possible integer (ticket #3922)
81025 **
81026 ** The second and third terms in the following conditional enforces
81027 ** the second condition under the assumption that addition overflow causes
81028 ** values to wrap around.
81029 */
81030 if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
81031 pMem->u.i = ix;
81032 MemSetTypeFlag(pMem, MEM_Int);
81033 }
81034 }
81035 }
81036
81037 /*
81038 ** Convert pMem to type integer. Invalidate any prior representations.
@@ -82755,10 +82887,13 @@
82887 }else{
82888 #ifdef SQLITE_DEBUG
82889 int i;
82890 for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1;
82891 #endif
82892 if( nNewSize>=100 && (nNewSize/100)>(p->nLabelAlloc/100) ){
82893 sqlite3ProgressCheck(p);
82894 }
82895 p->nLabelAlloc = nNewSize;
82896 p->aLabel[j] = v->nOp;
82897 }
82898 }
82899 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
@@ -90423,11 +90558,11 @@
90558 ){
90559 if( affinity>=SQLITE_AFF_NUMERIC ){
90560 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
90561 || affinity==SQLITE_AFF_NUMERIC || affinity==SQLITE_AFF_FLEXNUM );
90562 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
90563 if( (pRec->flags & (MEM_Real|MEM_IntReal))==0 ){
90564 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
90565 }else if( affinity<=SQLITE_AFF_REAL ){
90566 sqlite3VdbeIntegerAffinity(pRec);
90567 }
90568 }
@@ -91179,10 +91314,16 @@
91314 int pcx;
91315
91316 #ifdef SQLITE_DEBUG
91317 if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
91318 #endif
91319
91320 /* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates
91321 ** something is wrong with the code generator. Raise and assertion in order
91322 ** to bring this to the attention of fuzzers and other testing tools. */
91323 assert( pOp->p1!=SQLITE_INTERNAL );
91324
91325 if( p->pFrame && pOp->p1==SQLITE_OK ){
91326 /* Halt the sub-program. Return control to the parent frame. */
91327 pFrame = p->pFrame;
91328 p->pFrame = pFrame->pParent;
91329 p->nFrame--;
@@ -93171,11 +93312,11 @@
93312 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
93313 break;
93314 }
93315 case COLTYPE_REAL: {
93316 testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
93317 assert( (pIn1->flags & MEM_IntReal)==0 );
93318 if( pIn1->flags & MEM_Int ){
93319 /* When applying REAL affinity, if the result is still an MEM_Int
93320 ** that will fit in 6 bytes, then change the type to MEM_IntReal
93321 ** so that we keep the high-resolution integer value but know that
93322 ** the type really wants to be REAL. */
@@ -96148,10 +96289,13 @@
96289 ** The next use of the Rowid or Column or Next instruction for P1
96290 ** will refer to the first entry in the database table or index.
96291 ** If the table or index is empty, jump immediately to P2.
96292 ** If the table or index is not empty, fall through to the following
96293 ** instruction.
96294 **
96295 ** If P2 is zero, that is an assertion that the P1 table is never
96296 ** empty and hence the jump will never be taken.
96297 **
96298 ** This opcode leaves the cursor configured to move in forward order,
96299 ** from the beginning toward the end. In other words, the cursor is
96300 ** configured to use Next, not Prev.
96301 */
@@ -96160,10 +96304,12 @@
96304 BtCursor *pCrsr;
96305 int res;
96306
96307 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96308 assert( pOp->p5==0 );
96309 assert( pOp->p2>=0 && pOp->p2<p->nOp );
96310
96311 pC = p->apCsr[pOp->p1];
96312 assert( pC!=0 );
96313 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
96314 res = 1;
96315 #ifdef SQLITE_DEBUG
@@ -96179,13 +96325,14 @@
96325 pC->deferredMoveto = 0;
96326 pC->cacheStatus = CACHE_STALE;
96327 }
96328 if( rc ) goto abort_due_to_error;
96329 pC->nullRow = (u8)res;
96330 if( pOp->p2>0 ){
96331 VdbeBranchTaken(res!=0,2);
96332 if( res ) goto jump_to_p2;
96333 }
96334 break;
96335 }
96336
96337 /* Opcode: Next P1 P2 P3 * P5
96338 **
@@ -96987,17 +97134,18 @@
97134 assert( (pnErr->flags & MEM_Int)!=0 );
97135 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
97136 pIn1 = &aMem[pOp->p1];
97137 assert( pOp->p5<db->nDb );
97138 assert( DbMaskTest(p->btreeMask, pOp->p5) );
97139 rc = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot,
97140 (int)pnErr->u.i+1, &nErr, &z);
97141 sqlite3VdbeMemSetNull(pIn1);
97142 if( nErr==0 ){
97143 assert( z==0 );
97144 }else if( rc ){
97145 sqlite3_free(z);
97146 goto abort_due_to_error;
97147 }else{
97148 pnErr->u.i -= nErr-1;
97149 sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
97150 }
97151 UPDATE_MAX_BLOBSIZE(pIn1);
@@ -103838,10 +103986,11 @@
103986 assert( ExprUseYTab(pExpr) );
103987 pExpr->y.pTab = pTab;
103988 if( pParse->bReturning ){
103989 eNewExprOp = TK_REGISTER;
103990 pExpr->op2 = TK_COLUMN;
103991 pExpr->iColumn = iCol;
103992 pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
103993 sqlite3TableColumnToStorage(pTab, iCol) + 1;
103994 }else{
103995 pExpr->iColumn = (i16)iCol;
103996 eNewExprOp = TK_TRIGGER;
@@ -132018,10 +132167,12 @@
132167 unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
132168 unsigned int);
132169 const char *(*db_name)(sqlite3*,int);
132170 /* Version 3.40.0 and later */
132171 int (*value_encoding)(sqlite3_value*);
132172 /* Version 3.41.0 and later */
132173 int (*is_interrupted)(sqlite3*);
132174 };
132175
132176 /*
132177 ** This is the function signature used for all extension entry points. It
132178 ** is also defined in the file "loadext.c".
@@ -132344,10 +132495,12 @@
132495 #define sqlite3_serialize sqlite3_api->serialize
132496 #endif
132497 #define sqlite3_db_name sqlite3_api->db_name
132498 /* Version 3.40.0 and later */
132499 #define sqlite3_value_encoding sqlite3_api->value_encoding
132500 /* Version 3.41.0 and later */
132501 #define sqlite3_is_interrupted sqlite3_api->is_interrupted
132502 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
132503
132504 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
132505 /* This case when the file really is being compiled as a loadable
132506 ** extension */
@@ -132858,11 +133011,13 @@
133011 0,
133012 0,
133013 #endif
133014 sqlite3_db_name,
133015 /* Version 3.40.0 and later */
133016 sqlite3_value_encoding,
133017 /* Version 3.41.0 and later */
133018 sqlite3_is_interrupted
133019 };
133020
133021 /* True if x is the directory separator character
133022 */
133023 #if SQLITE_OS_WIN
@@ -135868,11 +136023,12 @@
136023 sqlite3ExprListDelete(db, pCheck);
136024 }
136025 if( !isQuick ){ /* Omit the remaining tests for quick_check */
136026 /* Validate index entries for the current row */
136027 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
136028 int jmp2, jmp3, jmp4, jmp5, label6;
136029 int kk;
136030 int ckUniq = sqlite3VdbeMakeLabel(pParse);
136031 if( pPk==pIdx ) continue;
136032 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
136033 pPrior, r1);
136034 pPrior = pIdx;
@@ -135886,17 +136042,36 @@
136042 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
136043 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
136044 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
136045 jmp4 = integrityCheckResultRow(v);
136046 sqlite3VdbeJumpHere(v, jmp2);
136047
136048 /* Any indexed columns with non-BINARY collations must still hold
136049 ** the exact same text value as the table. */
136050 label6 = 0;
136051 for(kk=0; kk<pIdx->nKeyCol; kk++){
136052 if( pIdx->azColl[kk]==sqlite3StrBINARY ) continue;
136053 if( label6==0 ) label6 = sqlite3VdbeMakeLabel(pParse);
136054 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur+j, kk, 3);
136055 sqlite3VdbeAddOp3(v, OP_Ne, 3, label6, r1+kk); VdbeCoverage(v);
136056 }
136057 if( label6 ){
136058 int jmp6 = sqlite3VdbeAddOp0(v, OP_Goto);
136059 sqlite3VdbeResolveLabel(v, label6);
136060 sqlite3VdbeLoadString(v, 3, "row ");
136061 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
136062 sqlite3VdbeLoadString(v, 4, " values differ from index ");
136063 sqlite3VdbeGoto(v, jmp5-1);
136064 sqlite3VdbeJumpHere(v, jmp6);
136065 }
136066
136067 /* For UNIQUE indexes, verify that only one entry exists with the
136068 ** current key. The entry is unique if (1) any column is NULL
136069 ** or (2) the next entry has a different key */
136070 if( IsUniqueIndex(pIdx) ){
136071 int uniqOk = sqlite3VdbeMakeLabel(pParse);
136072 int jmp6;
 
136073 for(kk=0; kk<pIdx->nKeyCol; kk++){
136074 int iCol = pIdx->aiColumn[kk];
136075 assert( iCol!=XN_ROWID && iCol<pTab->nCol );
136076 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
136077 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
@@ -139696,11 +139871,10 @@
139871 #ifdef SQLITE_ENABLE_COLUMN_METADATA
139872 # define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)
139873 #else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
139874 # define columnType(A,B,C,D,E) columnTypeImpl(A,B)
139875 #endif
 
139876 static const char *columnTypeImpl(
139877 NameContext *pNC,
139878 #ifndef SQLITE_ENABLE_COLUMN_METADATA
139879 Expr *pExpr
139880 #else
@@ -139727,11 +139901,11 @@
139901 ** database table or a subquery.
139902 */
139903 Table *pTab = 0; /* Table structure column is extracted from */
139904 Select *pS = 0; /* Select the column is extracted from */
139905 int iCol = pExpr->iColumn; /* Index of column in pTab */
139906 while( pNC && !pTab ){
139907 SrcList *pTabList = pNC->pSrcList;
139908 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
139909 if( j<pTabList->nSrc ){
139910 pTab = pTabList->a[j].pTab;
139911 pS = pTabList->a[j].pSelect;
@@ -139738,11 +139912,11 @@
139912 }else{
139913 pNC = pNC->pNext;
139914 }
139915 }
139916
139917 if( pTab==0 ){
139918 /* At one time, code such as "SELECT new.x" within a trigger would
139919 ** cause this condition to run. Since then, we have restructured how
139920 ** trigger code is generated and so this condition is no longer
139921 ** possible. However, it can still be true for statements like
139922 ** the following:
@@ -139843,11 +140017,10 @@
140017 *pzOrigCol = zOrigCol;
140018 }
140019 #endif
140020 return zType;
140021 }
 
140022
140023 /*
140024 ** Generate code that will tell the VDBE the declaration types of columns
140025 ** in the result set.
140026 */
@@ -140039,11 +140212,11 @@
140212 }
140213 assert( nCol==(i16)nCol );
140214 *pnCol = nCol;
140215 *paCol = aCol;
140216
140217 for(i=0, pCol=aCol; i<nCol && !pParse->nErr; i++, pCol++){
140218 struct ExprList_item *pX = &pEList->a[i];
140219 struct ExprList_item *pCollide;
140220 /* Get an appropriate name for the column
140221 */
140222 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
@@ -140089,11 +140262,14 @@
140262 if( nName>0 ){
140263 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
140264 if( zName[j]==':' ) nName = j;
140265 }
140266 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
140267 sqlite3ProgressCheck(pParse);
140268 if( cnt>3 ){
140269 sqlite3_randomness(sizeof(cnt), &cnt);
140270 }
140271 }
140272 pCol->zCnName = zName;
140273 pCol->hName = sqlite3StrIHash(zName);
140274 if( pX->fg.bNoExpand ){
140275 pCol->colFlags |= COLFLAG_NOEXPAND;
@@ -140102,18 +140278,18 @@
140278 if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
140279 sqlite3OomFault(db);
140280 }
140281 }
140282 sqlite3HashClear(&ht);
140283 if( pParse->nErr ){
140284 for(j=0; j<i; j++){
140285 sqlite3DbFree(db, aCol[j].zCnName);
140286 }
140287 sqlite3DbFree(db, aCol);
140288 *paCol = 0;
140289 *pnCol = 0;
140290 return pParse->rc;
140291 }
140292 return SQLITE_OK;
140293 }
140294
140295 /*
@@ -140137,18 +140313,21 @@
140313 Column *pCol;
140314 CollSeq *pColl;
140315 int i,j;
140316 Expr *p;
140317 struct ExprList_item *a;
140318 NameContext sNC;
140319
140320 assert( pSelect!=0 );
140321 assert( (pSelect->selFlags & SF_Resolved)!=0 );
140322 assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
140323 assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
140324 if( db->mallocFailed ) return;
140325 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
140326 a = pSelect->pEList->a;
140327 memset(&sNC, 0, sizeof(sNC));
140328 sNC.pSrcList = pSelect->pSrc;
140329 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
140330 const char *zType;
140331 i64 n;
140332 pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
140333 p = a[i].pExpr;
@@ -140170,32 +140349,35 @@
140349 }else
140350 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140351 pCol->affinity = SQLITE_AFF_BLOB;
140352 }
140353 }
140354 zType = columnType(&sNC, p, 0, 0, 0);
140355 if( zType==0 || pCol->affinity!=sqlite3AffinityType(zType, 0) ){
140356 if( pCol->affinity==SQLITE_AFF_NUMERIC
140357 || pCol->affinity==SQLITE_AFF_FLEXNUM
140358 ){
140359 zType = "NUM";
140360 }else{
140361 zType = 0;
140362 for(j=1; j<SQLITE_N_STDTYPE; j++){
140363 if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
140364 zType = sqlite3StdType[j];
140365 break;
140366 }
140367 }
140368 }
140369 }
140370 if( zType ){
140371 i64 m = sqlite3Strlen30(zType);
140372 n = sqlite3Strlen30(pCol->zCnName);
140373 pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
140374 if( pCol->zCnName ){
140375 memcpy(&pCol->zCnName[n+1], zType, m+1);
140376 pCol->colFlags |= COLFLAG_HASTYPE;
140377 }else{
140378 testcase( pCol->colFlags & COLFLAG_HASTYPE );
140379 pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
140380 }
140381 }
140382 pColl = sqlite3ExprCollSeq(pParse, p);
140383 if( pColl ){
@@ -156196,10 +156378,17 @@
156378 /* This term is a vector operation that has been decomposed into
156379 ** other, subsequent terms. It can be ignored. See tag-20220128a */
156380 assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
156381 assert( pWC->a[ii].eOperator==WO_ROWVAL );
156382 continue;
156383 }
156384 if( pWC->a[ii].nChild ){
156385 /* If this term has child terms, then they are also part of the
156386 ** pWC->a[] array. So this term can be ignored, as a LIMIT clause
156387 ** will only be added if each of the child terms passes the
156388 ** (leftCursor==iCsr) test below. */
156389 continue;
156390 }
156391 if( pWC->a[ii].leftCursor!=iCsr ) return;
156392 }
156393
156394 /* Check condition (5). Return early if it is not met. */
@@ -159128,10 +159317,11 @@
159317 if( pX==0 ) continue;
159318 if( pX==pTerm ) break;
159319 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
159320 }
159321 if( j<0 ){
159322 sqlite3ProgressCheck(pWC->pWInfo->pParse);
159323 if( pLoop->maskSelf==pTerm->prereqAll ){
159324 /* If there are extra terms in the WHERE clause not used by an index
159325 ** that depend only on the table being scanned, and that will tend to
159326 ** cause many rows to be omitted, then mark that table as
159327 ** "self-culling".
@@ -159295,11 +159485,14 @@
159485 LogEst rSize; /* Number of rows in the table */
159486 LogEst rLogSize; /* Logarithm of table size */
159487 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
159488
159489 pNew = pBuilder->pNew;
159490 assert( db->mallocFailed==0 || pParse->nErr>0 );
159491 if( pParse->nErr ){
159492 return pParse->rc;
159493 }
159494 WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n",
159495 pProbe->pTable->zName,pProbe->zName,
159496 pNew->u.btree.nEq, pNew->nSkip, pNew->rRun));
159497
159498 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
@@ -159611,10 +159804,13 @@
159804 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
159805 && pNew->u.btree.nEq<pProbe->nColumn
159806 && (pNew->u.btree.nEq<pProbe->nKeyCol ||
159807 pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
159808 ){
159809 if( pNew->u.btree.nEq>3 ){
159810 sqlite3ProgressCheck(pParse);
159811 }
159812 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
159813 }
159814 pNew->nOut = saved_nOut;
159815 #ifdef SQLITE_ENABLE_STAT4
159816 pBuilder->nRecValid = nRecValid;
@@ -160770,12 +160966,10 @@
160966 rc = whereLoopAddBtree(&sSubBuild, mPrereq);
160967 }
160968 if( rc==SQLITE_OK ){
160969 rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
160970 }
 
 
160971 testcase( rc==SQLITE_NOMEM && sCur.n>0 );
160972 testcase( rc==SQLITE_DONE );
160973 if( sCur.n==0 ){
160974 sSum.n = 0;
160975 break;
@@ -166126,12 +166320,11 @@
166320 int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
166321 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
166322 VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because bound <expr> */
166323 VdbeCoverageNeverNullIf(v, op==OP_Le); /* values previously checked */
166324 windowAggFinal(&s, 0);
166325 sqlite3VdbeAddOp1(v, OP_Rewind, s.current.csr);
 
166326 windowReturnOneRow(&s);
166327 sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
166328 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
166329 sqlite3VdbeJumpHere(v, addrGe);
166330 }
@@ -166139,17 +166332,14 @@
166332 assert( pMWin->eEnd==TK_FOLLOWING );
166333 sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regStart);
166334 }
166335
166336 if( pMWin->eStart!=TK_UNBOUNDED ){
166337 sqlite3VdbeAddOp1(v, OP_Rewind, s.start.csr);
 
166338 }
166339 sqlite3VdbeAddOp1(v, OP_Rewind, s.current.csr);
166340 sqlite3VdbeAddOp1(v, OP_Rewind, s.end.csr);
 
 
166341 if( regPeer && pOrderBy ){
166342 sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, pOrderBy->nExpr-1);
166343 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.start.reg, pOrderBy->nExpr-1);
166344 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.current.reg, pOrderBy->nExpr-1);
166345 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.end.reg, pOrderBy->nExpr-1);
@@ -175259,18 +175449,35 @@
175449 /*
175450 ** Cause any pending operation to stop at its earliest opportunity.
175451 */
175452 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
175453 #ifdef SQLITE_ENABLE_API_ARMOR
175454 if( !sqlite3SafetyCheckOk(db)
175455 && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
175456 ){
175457 (void)SQLITE_MISUSE_BKPT;
175458 return;
175459 }
175460 #endif
175461 AtomicStore(&db->u1.isInterrupted, 1);
175462 }
175463
175464 /*
175465 ** Return true or false depending on whether or not an interrupt is
175466 ** pending on connection db.
175467 */
175468 SQLITE_API int sqlite3_is_interrupted(sqlite3 *db){
175469 #ifdef SQLITE_ENABLE_API_ARMOR
175470 if( !sqlite3SafetyCheckOk(db)
175471 && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE)
175472 ){
175473 (void)SQLITE_MISUSE_BKPT;
175474 return 0;
175475 }
175476 #endif
175477 return AtomicLoad(&db->u1.isInterrupted)!=0;
175478 }
175479
175480 /*
175481 ** This function is exactly the same as sqlite3_create_function(), except
175482 ** that it is designed to be called by internal code. The difference is
175483 ** that if a malloc() fails in sqlite3_create_function(), an error code
@@ -175311,11 +175518,11 @@
175518 enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
175519
175520 /* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But
175521 ** the meaning is inverted. So flip the bit. */
175522 assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS );
175523 extraFlags ^= SQLITE_FUNC_UNSAFE; /* tag-20230109-1 */
175524
175525
175526 #ifndef SQLITE_OMIT_UTF16
175527 /* If SQLITE_UTF16 is specified as the encoding type, transform this
175528 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
@@ -175329,15 +175536,15 @@
175536 enc = SQLITE_UTF16NATIVE;
175537 break;
175538 case SQLITE_ANY: {
175539 int rc;
175540 rc = sqlite3CreateFunc(db, zFunctionName, nArg,
175541 (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE, /* tag-20230109-1 */
175542 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
175543 if( rc==SQLITE_OK ){
175544 rc = sqlite3CreateFunc(db, zFunctionName, nArg,
175545 (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE, /* tag-20230109-1*/
175546 pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
175547 }
175548 if( rc!=SQLITE_OK ){
175549 return rc;
175550 }
@@ -212650,11 +212857,12 @@
212857 ** leave an error code and error message in the rbu handle.
212858 */
212859 static void rbuDeleteOalFile(sqlite3rbu *p){
212860 char *zOal = rbuMPrintf(p, "%s-oal", p->zTarget);
212861 if( zOal ){
212862 sqlite3_vfs *pVfs = 0;
212863 sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_VFS_POINTER, &pVfs);
212864 assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
212865 pVfs->xDelete(pVfs, zOal, 0);
212866 sqlite3_free(zOal);
212867 }
212868 }
@@ -213407,13 +213615,16 @@
213615 sqlite3_free(p->apShm);
213616 p->apShm = 0;
213617 sqlite3_free(p->zDel);
213618
213619 if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
213620 const sqlite3_io_methods *pMeth = p->pReal->pMethods;
213621 rbuMainlistRemove(p);
213622 rbuUnlockShm(p);
213623 if( pMeth->iVersion>1 && pMeth->xShmUnmap ){
213624 pMeth->xShmUnmap(p->pReal, 0);
213625 }
213626 }
213627 else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){
213628 rbuUpdateTempSize(p, 0);
213629 }
213630 assert( p->pMainNext==0 && p->pRbuVfs->pMain!=p );
@@ -213868,10 +214079,29 @@
214079 rbuVfsShmLock, /* xShmLock */
214080 rbuVfsShmBarrier, /* xShmBarrier */
214081 rbuVfsShmUnmap, /* xShmUnmap */
214082 0, 0 /* xFetch, xUnfetch */
214083 };
214084 static sqlite3_io_methods rbuvfs_io_methods1 = {
214085 1, /* iVersion */
214086 rbuVfsClose, /* xClose */
214087 rbuVfsRead, /* xRead */
214088 rbuVfsWrite, /* xWrite */
214089 rbuVfsTruncate, /* xTruncate */
214090 rbuVfsSync, /* xSync */
214091 rbuVfsFileSize, /* xFileSize */
214092 rbuVfsLock, /* xLock */
214093 rbuVfsUnlock, /* xUnlock */
214094 rbuVfsCheckReservedLock, /* xCheckReservedLock */
214095 rbuVfsFileControl, /* xFileControl */
214096 rbuVfsSectorSize, /* xSectorSize */
214097 rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */
214098 0, 0, 0, 0, 0, 0
214099 };
214100
214101
214102
214103 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
214104 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
214105 rbu_file *pFd = (rbu_file *)pFile;
214106 int rc = SQLITE_OK;
214107 const char *zOpen = zName;
@@ -213922,14 +214152,19 @@
214152
214153 if( rc==SQLITE_OK ){
214154 rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags);
214155 }
214156 if( pFd->pReal->pMethods ){
214157 const sqlite3_io_methods *pMeth = pFd->pReal->pMethods;
214158 /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
214159 ** pointer and, if the file is a main database file, link it into the
214160 ** mutex protected linked list of all such files. */
214161 if( pMeth->iVersion<2 || pMeth->xShmLock==0 ){
214162 pFile->pMethods = &rbuvfs_io_methods1;
214163 }else{
214164 pFile->pMethods = &rbuvfs_io_methods;
214165 }
214166 if( flags & SQLITE_OPEN_MAIN_DB ){
214167 rbuMainlistAdd(pFd);
214168 }
214169 }else{
214170 sqlite3_free(pFd->zDel);
@@ -239641,11 +239876,11 @@
239876 int nArg, /* Number of args */
239877 sqlite3_value **apUnused /* Function arguments */
239878 ){
239879 assert( nArg==0 );
239880 UNUSED_PARAM2(nArg, apUnused);
239881 sqlite3_result_text(pCtx, "fts5: 2023-01-16 18:13:00 83f21285fe86430a66ce6841606e3ad7c27da52ac75a034c6a00c7a9fdb9791d", -1, SQLITE_TRANSIENT);
239882 }
239883
239884 /*
239885 ** Return true if zName is the extension on one of the shadow tables used
239886 ** by this module.
239887
+45 -14
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.41.0"
150150
#define SQLITE_VERSION_NUMBER 3041000
151
-#define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7"
151
+#define SQLITE_SOURCE_ID "2023-01-16 18:13:00 83f21285fe86430a66ce6841606e3ad7c27da52ac75a034c6a00c7a9fdb9791d"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -2677,12 +2677,16 @@
26772677
** that are started after the running statement count reaches zero are
26782678
** not effected by the sqlite3_interrupt().
26792679
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
26802680
** SQL statements is a no-op and has no effect on SQL statements
26812681
** that are started after the sqlite3_interrupt() call returns.
2682
+**
2683
+** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2684
+** or not an interrupt is currently in effect for [database connection] D.
26822685
*/
26832686
SQLITE_API void sqlite3_interrupt(sqlite3*);
2687
+SQLITE_API int sqlite3_is_interrupted(sqlite3*);
26842688
26852689
/*
26862690
** CAPI3REF: Determine If An SQL Statement Is Complete
26872691
**
26882692
** These routines are useful during command-line input to determine if the
@@ -3360,11 +3364,11 @@
33603364
** CAPI3REF: Query Progress Callbacks
33613365
** METHOD: sqlite3
33623366
**
33633367
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
33643368
** function X to be invoked periodically during long running calls to
3365
-** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3369
+** [sqlite3_step()] and [sqlite3_prepare()] and similar for
33663370
** database connection D. An example use for this
33673371
** interface is to keep a GUI updated during a large query.
33683372
**
33693373
** ^The parameter P is passed through as the only parameter to the
33703374
** callback function X. ^The parameter N is the approximate number of
@@ -3385,10 +3389,17 @@
33853389
** The progress handler callback must not do anything that will modify
33863390
** the database connection that invoked the progress handler.
33873391
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
33883392
** database connections for the meaning of "modify" in this paragraph.
33893393
**
3394
+** The progress handler callback would originally only be invoked from the
3395
+** bytecode engine. It still might be invoked during [sqlite3_prepare()]
3396
+** and similar because those routines might force a reparse of the schema
3397
+** which involves running the bytecode engine. However, beginning with
3398
+** SQLite version 3.41.0, the progress handler callback might also be
3399
+** invoked directly from [sqlite3_prepare()] while analyzing and generating
3400
+** code for complex queries.
33903401
*/
33913402
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
33923403
33933404
/*
33943405
** CAPI3REF: Opening A New Database Connection
@@ -3421,17 +3432,22 @@
34213432
** sqlite3_open_v2() must include, at a minimum, one of the following
34223433
** three flag combinations:)^
34233434
**
34243435
** <dl>
34253436
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3426
-** <dd>The database is opened in read-only mode. If the database does not
3427
-** already exist, an error is returned.</dd>)^
3437
+** <dd>The database is opened in read-only mode. If the database does
3438
+** not already exist, an error is returned.</dd>)^
34283439
**
34293440
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3430
-** <dd>The database is opened for reading and writing if possible, or reading
3431
-** only if the file is write protected by the operating system. In either
3432
-** case the database must already exist, otherwise an error is returned.</dd>)^
3441
+** <dd>The database is opened for reading and writing if possible, or
3442
+** reading only if the file is write protected by the operating
3443
+** system. In either case the database must already exist, otherwise
3444
+** an error is returned. For historical reasons, if opening in
3445
+** read-write mode fails due to OS-level permissions, an attempt is
3446
+** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3447
+** used to determine whether the database is actually
3448
+** read-write.</dd>)^
34333449
**
34343450
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
34353451
** <dd>The database is opened for reading and writing, and is created if
34363452
** it does not already exist. This is the behavior that is always used for
34373453
** sqlite3_open() and sqlite3_open16().</dd>)^
@@ -5408,14 +5424,25 @@
54085424
** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
54095425
** The SQLITE_DIRECTONLY flag means that the function may only be invoked
54105426
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
54115427
** schema structures such as [CHECK constraints], [DEFAULT clauses],
54125428
** [expression indexes], [partial indexes], or [generated columns].
5413
-** The SQLITE_DIRECTONLY flags is a security feature which is recommended
5414
-** for all [application-defined SQL functions], and especially for functions
5415
-** that have side-effects or that could potentially leak sensitive
5416
-** information.
5429
+** <p>
5430
+** The SQLITE_DIRECTONLY flag is recommended for any
5431
+** [application-defined SQL function]
5432
+** that has side-effects or that could potentially leak sensitive information.
5433
+** This will prevent attacks in which an application is tricked
5434
+** into using a database file that has had its schema surreptiously
5435
+** modified to invoke the application-defined function in ways that are
5436
+** harmful.
5437
+** <p>
5438
+** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5439
+** [application-defined SQL functions], regardless of whether or not they
5440
+** are security sensitive, as doing so prevents those functions from being used
5441
+** inside of the database schema, and thus ensures that the database
5442
+** can be inspected and modified using generic tools (such as the [CLI])
5443
+** that do not have access to the application-defined functions.
54175444
** </dd>
54185445
**
54195446
** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
54205447
** The SQLITE_INNOCUOUS flag means that the function is unlikely
54215448
** to cause problems even if misused. An innocuous function should have
@@ -7135,14 +7162,14 @@
71357162
** checked separately in byte code. If the omit flag is change to true, then
71367163
** the constraint may or may not be checked in byte code. In other words,
71377164
** when the omit flag is true there is no guarantee that the constraint will
71387165
** not be checked again using byte code.)^
71397166
**
7140
-** ^The idxNum and idxPtr values are recorded and passed into the
7167
+** ^The idxNum and idxStr values are recorded and passed into the
71417168
** [xFilter] method.
7142
-** ^[sqlite3_free()] is used to free idxPtr if and only if
7143
-** needToFreeIdxPtr is true.
7169
+** ^[sqlite3_free()] is used to free idxStr if and only if
7170
+** needToFreeIdxStr is true.
71447171
**
71457172
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
71467173
** the correct order to satisfy the ORDER BY clause so that no separate
71477174
** sorting step is required.
71487175
**
@@ -10094,10 +10121,14 @@
1009410121
** parameter is undefined. For an INSERT or UPDATE on a rowid table the
1009510122
** seventh parameter is the final rowid value of the row being inserted
1009610123
** or updated. The value of the seventh parameter passed to the callback
1009710124
** function is not defined for operations on WITHOUT ROWID tables, or for
1009810125
** DELETE operations on rowid tables.
10126
+**
10127
+** ^The sqlite3_update_hook(D,C,P) function returns the P argument from
10128
+** the previous call on the same [database connection] D, or NULL for
10129
+** the first call on D.
1009910130
**
1010010131
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
1010110132
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
1010210133
** provide additional information about a preupdate event. These routines
1010310134
** may only be called from within a preupdate callback. Invoking any of
1010410135
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.41.0"
150 #define SQLITE_VERSION_NUMBER 3041000
151 #define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2677,12 +2677,16 @@
2677 ** that are started after the running statement count reaches zero are
2678 ** not effected by the sqlite3_interrupt().
2679 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2680 ** SQL statements is a no-op and has no effect on SQL statements
2681 ** that are started after the sqlite3_interrupt() call returns.
 
 
 
2682 */
2683 SQLITE_API void sqlite3_interrupt(sqlite3*);
 
2684
2685 /*
2686 ** CAPI3REF: Determine If An SQL Statement Is Complete
2687 **
2688 ** These routines are useful during command-line input to determine if the
@@ -3360,11 +3364,11 @@
3360 ** CAPI3REF: Query Progress Callbacks
3361 ** METHOD: sqlite3
3362 **
3363 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3364 ** function X to be invoked periodically during long running calls to
3365 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3366 ** database connection D. An example use for this
3367 ** interface is to keep a GUI updated during a large query.
3368 **
3369 ** ^The parameter P is passed through as the only parameter to the
3370 ** callback function X. ^The parameter N is the approximate number of
@@ -3385,10 +3389,17 @@
3385 ** The progress handler callback must not do anything that will modify
3386 ** the database connection that invoked the progress handler.
3387 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3388 ** database connections for the meaning of "modify" in this paragraph.
3389 **
 
 
 
 
 
 
 
3390 */
3391 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3392
3393 /*
3394 ** CAPI3REF: Opening A New Database Connection
@@ -3421,17 +3432,22 @@
3421 ** sqlite3_open_v2() must include, at a minimum, one of the following
3422 ** three flag combinations:)^
3423 **
3424 ** <dl>
3425 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3426 ** <dd>The database is opened in read-only mode. If the database does not
3427 ** already exist, an error is returned.</dd>)^
3428 **
3429 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3430 ** <dd>The database is opened for reading and writing if possible, or reading
3431 ** only if the file is write protected by the operating system. In either
3432 ** case the database must already exist, otherwise an error is returned.</dd>)^
 
 
 
 
 
3433 **
3434 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3435 ** <dd>The database is opened for reading and writing, and is created if
3436 ** it does not already exist. This is the behavior that is always used for
3437 ** sqlite3_open() and sqlite3_open16().</dd>)^
@@ -5408,14 +5424,25 @@
5408 ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
5409 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5410 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5411 ** schema structures such as [CHECK constraints], [DEFAULT clauses],
5412 ** [expression indexes], [partial indexes], or [generated columns].
5413 ** The SQLITE_DIRECTONLY flags is a security feature which is recommended
5414 ** for all [application-defined SQL functions], and especially for functions
5415 ** that have side-effects or that could potentially leak sensitive
5416 ** information.
 
 
 
 
 
 
 
 
 
 
 
5417 ** </dd>
5418 **
5419 ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
5420 ** The SQLITE_INNOCUOUS flag means that the function is unlikely
5421 ** to cause problems even if misused. An innocuous function should have
@@ -7135,14 +7162,14 @@
7135 ** checked separately in byte code. If the omit flag is change to true, then
7136 ** the constraint may or may not be checked in byte code. In other words,
7137 ** when the omit flag is true there is no guarantee that the constraint will
7138 ** not be checked again using byte code.)^
7139 **
7140 ** ^The idxNum and idxPtr values are recorded and passed into the
7141 ** [xFilter] method.
7142 ** ^[sqlite3_free()] is used to free idxPtr if and only if
7143 ** needToFreeIdxPtr is true.
7144 **
7145 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
7146 ** the correct order to satisfy the ORDER BY clause so that no separate
7147 ** sorting step is required.
7148 **
@@ -10094,10 +10121,14 @@
10094 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
10095 ** seventh parameter is the final rowid value of the row being inserted
10096 ** or updated. The value of the seventh parameter passed to the callback
10097 ** function is not defined for operations on WITHOUT ROWID tables, or for
10098 ** DELETE operations on rowid tables.
 
 
 
 
10099 **
10100 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
10101 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
10102 ** provide additional information about a preupdate event. These routines
10103 ** may only be called from within a preupdate callback. Invoking any of
10104
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.41.0"
150 #define SQLITE_VERSION_NUMBER 3041000
151 #define SQLITE_SOURCE_ID "2023-01-16 18:13:00 83f21285fe86430a66ce6841606e3ad7c27da52ac75a034c6a00c7a9fdb9791d"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2677,12 +2677,16 @@
2677 ** that are started after the running statement count reaches zero are
2678 ** not effected by the sqlite3_interrupt().
2679 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2680 ** SQL statements is a no-op and has no effect on SQL statements
2681 ** that are started after the sqlite3_interrupt() call returns.
2682 **
2683 ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2684 ** or not an interrupt is currently in effect for [database connection] D.
2685 */
2686 SQLITE_API void sqlite3_interrupt(sqlite3*);
2687 SQLITE_API int sqlite3_is_interrupted(sqlite3*);
2688
2689 /*
2690 ** CAPI3REF: Determine If An SQL Statement Is Complete
2691 **
2692 ** These routines are useful during command-line input to determine if the
@@ -3360,11 +3364,11 @@
3364 ** CAPI3REF: Query Progress Callbacks
3365 ** METHOD: sqlite3
3366 **
3367 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3368 ** function X to be invoked periodically during long running calls to
3369 ** [sqlite3_step()] and [sqlite3_prepare()] and similar for
3370 ** database connection D. An example use for this
3371 ** interface is to keep a GUI updated during a large query.
3372 **
3373 ** ^The parameter P is passed through as the only parameter to the
3374 ** callback function X. ^The parameter N is the approximate number of
@@ -3385,10 +3389,17 @@
3389 ** The progress handler callback must not do anything that will modify
3390 ** the database connection that invoked the progress handler.
3391 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3392 ** database connections for the meaning of "modify" in this paragraph.
3393 **
3394 ** The progress handler callback would originally only be invoked from the
3395 ** bytecode engine. It still might be invoked during [sqlite3_prepare()]
3396 ** and similar because those routines might force a reparse of the schema
3397 ** which involves running the bytecode engine. However, beginning with
3398 ** SQLite version 3.41.0, the progress handler callback might also be
3399 ** invoked directly from [sqlite3_prepare()] while analyzing and generating
3400 ** code for complex queries.
3401 */
3402 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3403
3404 /*
3405 ** CAPI3REF: Opening A New Database Connection
@@ -3421,17 +3432,22 @@
3432 ** sqlite3_open_v2() must include, at a minimum, one of the following
3433 ** three flag combinations:)^
3434 **
3435 ** <dl>
3436 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3437 ** <dd>The database is opened in read-only mode. If the database does
3438 ** not already exist, an error is returned.</dd>)^
3439 **
3440 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3441 ** <dd>The database is opened for reading and writing if possible, or
3442 ** reading only if the file is write protected by the operating
3443 ** system. In either case the database must already exist, otherwise
3444 ** an error is returned. For historical reasons, if opening in
3445 ** read-write mode fails due to OS-level permissions, an attempt is
3446 ** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3447 ** used to determine whether the database is actually
3448 ** read-write.</dd>)^
3449 **
3450 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3451 ** <dd>The database is opened for reading and writing, and is created if
3452 ** it does not already exist. This is the behavior that is always used for
3453 ** sqlite3_open() and sqlite3_open16().</dd>)^
@@ -5408,14 +5424,25 @@
5424 ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
5425 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5426 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5427 ** schema structures such as [CHECK constraints], [DEFAULT clauses],
5428 ** [expression indexes], [partial indexes], or [generated columns].
5429 ** <p>
5430 ** The SQLITE_DIRECTONLY flag is recommended for any
5431 ** [application-defined SQL function]
5432 ** that has side-effects or that could potentially leak sensitive information.
5433 ** This will prevent attacks in which an application is tricked
5434 ** into using a database file that has had its schema surreptiously
5435 ** modified to invoke the application-defined function in ways that are
5436 ** harmful.
5437 ** <p>
5438 ** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5439 ** [application-defined SQL functions], regardless of whether or not they
5440 ** are security sensitive, as doing so prevents those functions from being used
5441 ** inside of the database schema, and thus ensures that the database
5442 ** can be inspected and modified using generic tools (such as the [CLI])
5443 ** that do not have access to the application-defined functions.
5444 ** </dd>
5445 **
5446 ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
5447 ** The SQLITE_INNOCUOUS flag means that the function is unlikely
5448 ** to cause problems even if misused. An innocuous function should have
@@ -7135,14 +7162,14 @@
7162 ** checked separately in byte code. If the omit flag is change to true, then
7163 ** the constraint may or may not be checked in byte code. In other words,
7164 ** when the omit flag is true there is no guarantee that the constraint will
7165 ** not be checked again using byte code.)^
7166 **
7167 ** ^The idxNum and idxStr values are recorded and passed into the
7168 ** [xFilter] method.
7169 ** ^[sqlite3_free()] is used to free idxStr if and only if
7170 ** needToFreeIdxStr is true.
7171 **
7172 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
7173 ** the correct order to satisfy the ORDER BY clause so that no separate
7174 ** sorting step is required.
7175 **
@@ -10094,10 +10121,14 @@
10121 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
10122 ** seventh parameter is the final rowid value of the row being inserted
10123 ** or updated. The value of the seventh parameter passed to the callback
10124 ** function is not defined for operations on WITHOUT ROWID tables, or for
10125 ** DELETE operations on rowid tables.
10126 **
10127 ** ^The sqlite3_update_hook(D,C,P) function returns the P argument from
10128 ** the previous call on the same [database connection] D, or NULL for
10129 ** the first call on D.
10130 **
10131 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
10132 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
10133 ** provide additional information about a preupdate event. These routines
10134 ** may only be called from within a preupdate callback. Invoking any of
10135

Keyboard Shortcuts

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