Fossil SCM

Update the change log. Also update the built-in SQLite to the latest trunk version for beta-testing of SQLite.

drh 2026-05-21 19:13 UTC trunk
Commit 055e4d047217fe48deb14cb37e93b8be754edac73cfb0fdfa111f69d7c0effd3
+1 -2
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -68,12 +68,11 @@
6868
const sqlite3_qrf_spec *pSpec, /* Result format specification */
6969
char **pzErr /* OUT: Write error message here */
7070
);
7171
7272
/*
73
-** Range of values for sqlite3_qrf_spec.aWidth[] entries and for
74
-** sqlite3_qrf_spec.mxColWidth and .nScreenWidth
73
+** Range of values for sqlite3_qrf_spec.aWidth[] entries.
7574
*/
7675
#define QRF_MAX_WIDTH 10000
7776
#define QRF_MIN_WIDTH 0
7877
7978
/*
8079
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -68,12 +68,11 @@
68 const sqlite3_qrf_spec *pSpec, /* Result format specification */
69 char **pzErr /* OUT: Write error message here */
70 );
71
72 /*
73 ** Range of values for sqlite3_qrf_spec.aWidth[] entries and for
74 ** sqlite3_qrf_spec.mxColWidth and .nScreenWidth
75 */
76 #define QRF_MAX_WIDTH 10000
77 #define QRF_MIN_WIDTH 0
78
79 /*
80
--- extsrc/qrf.h
+++ extsrc/qrf.h
@@ -68,12 +68,11 @@
68 const sqlite3_qrf_spec *pSpec, /* Result format specification */
69 char **pzErr /* OUT: Write error message here */
70 );
71
72 /*
73 ** Range of values for sqlite3_qrf_spec.aWidth[] entries.
 
74 */
75 #define QRF_MAX_WIDTH 10000
76 #define QRF_MIN_WIDTH 0
77
78 /*
79
+79 -28
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -154,10 +154,11 @@
154154
#include <string.h>
155155
#include <stdio.h>
156156
#include <assert.h>
157157
#include <math.h>
158158
#include <stdint.h>
159
+#include <time.h>
159160
#include "sqlite3.h"
160161
typedef sqlite3_int64 i64;
161162
typedef sqlite3_uint64 u64;
162163
typedef unsigned char u8;
163164
#include <ctype.h>
@@ -190,13 +191,14 @@
190191
#include <sys/stat.h>
191192
192193
#if HAVE_READLINE
193194
# include <readline/readline.h>
194195
# include <readline/history.h>
195
-#endif
196
-
197
-#if HAVE_EDITLINE
196
+#elif HAVE_EDITLINE
197
+/* If both HAVE_READLINE and HAVE_EDITLINE are true, assume that this
198
+** libedit installation does not have its own headers, instead using
199
+** those from libreadline. */
198200
# include <editline/readline.h>
199201
#endif
200202
201203
#if HAVE_EDITLINE || HAVE_READLINE
202204
@@ -744,12 +746,11 @@
744746
const sqlite3_qrf_spec *pSpec, /* Result format specification */
745747
char **pzErr /* OUT: Write error message here */
746748
);
747749
748750
/*
749
-** Range of values for sqlite3_qrf_spec.aWidth[] entries and for
750
-** sqlite3_qrf_spec.mxColWidth and .nScreenWidth
751
+** Range of values for sqlite3_qrf_spec.aWidth[] entries.
751752
*/
752753
#define QRF_MAX_WIDTH 10000
753754
#define QRF_MIN_WIDTH 0
754755
755756
/*
@@ -1129,10 +1130,14 @@
11291130
sqlite3_str_append(pOut, "-", 1);
11301131
}
11311132
if( N<10000 ){
11321133
sqlite3_str_appendf(pOut, "%4lld ", N);
11331134
return;
1135
+ }
1136
+ if( N>=9223372036854775800LL ){
1137
+ sqlite3_str_appendf(pOut, "%.2fE", 1e-18*(double)N);
1138
+ return;
11341139
}
11351140
for(i=1; i<=18; i++){
11361141
N = (N+5)/10;
11371142
if( N<10000 ){
11381143
int n = (int)N;
@@ -1289,12 +1294,12 @@
12891294
if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
12901295
int nSp = 0;
12911296
sqlite3_str_reset(pStats);
12921297
if( nCycle>=0 && nTotal>0 ){
12931298
qrfApproxInt64(pStats, nCycle);
1294
- sqlite3_str_appendf(pStats, " %3d%%",
1295
- ((nCycle*100)+nTotal/2) / nTotal
1299
+ sqlite3_str_appendf(pStats, " %3.0f%%",
1300
+ ((100.0*(double)nCycle)+nTotal/2.0) / (double)nTotal
12961301
);
12971302
nSp = 2;
12981303
}
12991304
if( nLoop>=0 ){
13001305
if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
@@ -2532,16 +2537,16 @@
25322537
const char *azDash[2] = {
25332538
BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24,
25342539
DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24
25352540
};/* 0 1 2 3 4 5 6 7 8 9 */
25362541
const int nDash = 30;
2537
- N *= 3;
2538
- while( N>nDash ){
2542
+ i64 nn = 3*(i64)N;
2543
+ while( nn>nDash ){
25392544
sqlite3_str_append(pOut, azDash[bDbl], nDash);
2540
- N -= nDash;
2545
+ nn -= nDash;
25412546
}
2542
- sqlite3_str_append(pOut, azDash[bDbl], N);
2547
+ sqlite3_str_append(pOut, azDash[bDbl], (int)nn);
25432548
}
25442549
25452550
/*
25462551
** Draw a horizontal separator for a QRF_STYLE_Box table.
25472552
*/
@@ -2610,11 +2615,11 @@
26102615
int nSW /* Screen width */
26112616
){
26122617
int i; /* Loop counter */
26132618
int nr; /* Number of rows */
26142619
int w = 0; /* Width of the current column */
2615
- int t; /* Total width of all columns */
2620
+ i64 t; /* Total width of all columns */
26162621
int *aw; /* Array of individual column widths */
26172622
26182623
aw = sqlite3_malloc64( sizeof(int)*nCol );
26192624
if( aw==0 ){
26202625
qrfOom(p);
@@ -2748,12 +2753,15 @@
27482753
}else{
27492754
sepW = pData->nCol*3 + 1;
27502755
if( p->spec.bBorder==QRF_No ) sepW -= 2;
27512756
}
27522757
nCol = pData->nCol;
2753
- for(i=sumW=0; i<nCol; i++) sumW += pData->a[i].w;
2754
- if( p->spec.nScreenWidth >= sumW+sepW ) return;
2758
+ for(i=0, sumW=0; i<nCol; i++){
2759
+ if( sumW > 2147483647 - pData->a[i].w ) return;
2760
+ sumW += pData->a[i].w;
2761
+ }
2762
+ if( p->spec.nScreenWidth >= (i64)sumW + sepW ) return;
27552763
27562764
/* First thing to do is reduce the separation between columns */
27572765
pData->nMargin = 0;
27582766
if( p->spec.eStyle==QRF_STYLE_Column ){
27592767
sepW = pData->nCol - 1;
@@ -3624,11 +3632,11 @@
36243632
p->nRow = 0;
36253633
sz = sizeof(sqlite3_qrf_spec);
36263634
memcpy(&p->spec, pSpec, sz);
36273635
if( p->spec.zNull==0 ) p->spec.zNull = "";
36283636
p->mxWidth = p->spec.nScreenWidth;
3629
- if( p->mxWidth<=0 ) p->mxWidth = QRF_MAX_WIDTH;
3637
+ if( p->mxWidth<=0 ) p->mxWidth = 2147483647;
36303638
p->mxHeight = p->spec.nLineLimit;
36313639
if( p->mxHeight<=0 ) p->mxHeight = 2147483647;
36323640
if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto;
36333641
if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
36343642
if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
@@ -5272,10 +5280,14 @@
52725280
#include <stdarg.h>
52735281
52745282
/******************************************************************************
52755283
** The Hash Engine
52765284
*/
5285
+#if defined(__GNUC__) && __GNUC__>=11
5286
+# pragma GCC diagnostic push
5287
+# pragma GCC diagnostic ignored "-Wstringop-overread"
5288
+#endif
52775289
/* Context for the SHA1 hash */
52785290
typedef struct SHA1Context SHA1Context;
52795291
struct SHA1Context {
52805292
unsigned int state[5];
52815293
unsigned int count[2];
@@ -5467,10 +5479,13 @@
54675479
zOut[i*2+1] = zEncode[digest[i] & 0xf];
54685480
}
54695481
zOut[i*2]= 0;
54705482
}
54715483
}
5484
+#if defined(__GNUC__) && __GNUC__>=11
5485
+# pragma GCC diagnostic pop
5486
+#endif
54725487
/* End of the hashing logic
54735488
*****************************************************************************/
54745489
54755490
/*
54765491
** Two SQL functions: sha1(X) and sha1b(X).
@@ -8369,11 +8384,11 @@
83698384
if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
83708385
double r = sqlite3_value_double(argv[iArg++]);
83718386
if( r<(double)SMALLEST_INT64 ){
83728387
iMin = SMALLEST_INT64;
83738388
}else if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8374
- iMin = (sqlite3_int64)seriesCeil(r+1.0);
8389
+ iMin = (sqlite3_int64)seriesCeil(r)+1;
83758390
}else{
83768391
iMin = (sqlite3_int64)seriesCeil(r);
83778392
}
83788393
}else{
83798394
iMin = sqlite3_value_int64(argv[iArg++]);
@@ -8390,11 +8405,11 @@
83908405
if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
83918406
double r = sqlite3_value_double(argv[iArg++]);
83928407
if( r>(double)LARGEST_INT64 ){
83938408
iMax = LARGEST_INT64;
83948409
}else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8395
- iMax = (sqlite3_int64)(r-1.0);
8410
+ iMax = ((sqlite3_int64)r)-1;
83968411
}else{
83978412
iMax = (sqlite3_int64)seriesFloor(r);
83988413
}
83998414
}else{
84008415
iMax = sqlite3_value_int64(argv[iArg++]);
@@ -9638,11 +9653,10 @@
96389653
if( pRe==0 ){
96399654
sqlite3_result_error_nomem(context);
96409655
return;
96419656
}
96429657
pStr = sqlite3_str_new(0);
9643
- if( pStr==0 ) goto re_bytecode_func_err;
96449658
if( pRe->nInit>0 ){
96459659
sqlite3_str_appendf(pStr, "INIT ");
96469660
for(i=0; i<pRe->nInit; i++){
96479661
sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
96489662
}
@@ -9649,20 +9663,20 @@
96499663
sqlite3_str_appendf(pStr, "\n");
96509664
}
96519665
for(i=0; (unsigned)i<pRe->nState; i++){
96529666
sqlite3_str_appendf(pStr, "%-8s %4d\n",
96539667
ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
9668
+ }
9669
+ if( sqlite3_str_errcode(pStr)==SQLITE_NOMEM ){
9670
+ sqlite3_str_finish(pStr);
9671
+ re_free(pRe);
9672
+ sqlite3_result_error_nomem(context);
9673
+ return;
96549674
}
96559675
n = sqlite3_str_length(pStr);
96569676
z = sqlite3_str_finish(pStr);
9657
- if( n==0 ){
9658
- sqlite3_free(z);
9659
- }else{
9660
- sqlite3_result_text(context, z, n-1, sqlite3_free);
9661
- }
9662
-
9663
-re_bytecode_func_err:
9677
+ sqlite3_result_text(context, z, n-1, sqlite3_free);
96649678
re_free(pRe);
96659679
}
96669680
96679681
#endif /* SQLITE_DEBUG */
96689682
@@ -25172,11 +25186,11 @@
2517225186
case 1:
2517325187
#if defined(SQLITE_PS1)
2517425188
return SQLITE_PS1;
2517525189
#else
2517625190
if( shellNoColor() ){
25177
- return "/A-/v /~> ";
25191
+ return "/A-/v /f-> ";
2517825192
}else{
2517925193
return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> ";
2518025194
}
2518125195
#endif
2518225196
@@ -25184,11 +25198,11 @@
2518425198
case 2:
2518525199
#if defined(SQLITE_PS2)
2518625200
return SQLITE_PS2;
2518725201
#else
2518825202
if( shellNoColor() ){
25189
- return "/B/C> ";
25203
+ return "/B/C-> ";
2519025204
}else{
2519125205
return "/B/e[1;/x33/:36/;m/C/e[0m-> ";
2519225206
}
2519325207
#endif
2519425208
@@ -26976,11 +26990,11 @@
2697626990
return SQLITE_OK;
2697726991
}
2697826992
#endif
2697926993
2698026994
/*
26981
-** Print a schema statement. This is helper routine to dump_callbac().
26995
+** Print a schema statement. This is a helper routine to dump_callback().
2698226996
**
2698326997
** This routine converts some CREATE TABLE statements for shadow tables
2698426998
** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements.
2698526999
**
2698627000
** If the schema statement in z[] contains a start-of-comment and if
@@ -28540,10 +28554,13 @@
2854028554
" --reset Reset the count for each input and interrupt",
2854128555
" --timeout S Halt after running for S seconds",
2854228556
#endif
2854328557
".prompt MAIN CONTINUE Replace the standard prompts",
2854428558
" --hard-reset Unset SQLITE_PS1/2 and then --reset",
28559
+#ifndef SQLITE_NO_COLOR
28560
+ " --no-color Disable color prompts. Use --color to re-enable",
28561
+#endif
2854528562
" --reset Revert to default prompts",
2854628563
" --show Show the current prompt strings",
2854728564
" -- No more options. Subsequent args are prompts",
2854828565
#ifndef SQLITE_SHELL_FIDDLE
2854928566
".quit Stop interpreting input stream, exit if primary.",
@@ -35491,10 +35508,26 @@
3549135508
}else
3549235509
if( strcmp(z,"-show")==0 ){
3549335510
cli_printf(stdout,"Main prompt: '%s'\n", prompt_string(p, 0));
3549435511
cli_printf(stdout,"Continuation: '%s'\n", prompt_string(p, 1));
3549535512
}else
35513
+#ifndef SQLITE_NO_COLOR
35514
+ if( strcmp(z,"-color")==0 ){
35515
+#ifdef _WIN32
35516
+ _putenv("NO_COLOR=");
35517
+#else
35518
+ unsetenv("NO_COLOR");
35519
+#endif
35520
+ }else
35521
+ if( strcmp(z,"-no-color")==0 ){
35522
+#ifdef _WIN32
35523
+ _putenv("NO_COLOR=1");
35524
+#else
35525
+ setenv("NO_COLOR","1",1);
35526
+#endif
35527
+ }else
35528
+#endif
3549635529
if( strcmp(z,"-")==0 ){
3549735530
noOpt = 1;
3549835531
}else
3549935532
{
3550035533
dotCmdError(p, i, "unknown option", 0);
@@ -35505,10 +35538,11 @@
3550535538
dotCmdError(p, i, "extra argument", 0);
3550635539
rc = 1;
3550735540
goto meta_command_exit;
3550835541
}else if( !p->dot.abQuot[i] && sqlite3_strglob("*[^a-z]*",z)!=0 ){
3550935542
dotCmdError(p, i, "use quotes around the prompt string", 0);
35543
+ rc = 1;
3551035544
}else{
3551135545
free(p->azPrompt[cnt]);
3551235546
p->azPrompt[cnt] = strdup(z);
3551335547
cnt++;
3551435548
}
@@ -37801,10 +37835,23 @@
3780137835
sputz(stdout, "WARNING: attempt to configure SQLite after"
3780237836
" initialization.\n");
3780337837
}
3780437838
}
3780537839
37840
+#if HAVE_EDITLINE
37841
+/*
37842
+** https://sqlite.org/forum/forumpost/aad7a634916ff050:
37843
+**
37844
+** Calling setlocale(LC_ALL,"") is required to get libedit to accept
37845
+** non-ASCII input.
37846
+*/
37847
+#define DO_SET_LOCALE 1
37848
+#include <locale.h>
37849
+#else
37850
+#define DO_SET_LOCALE 0
37851
+#endif
37852
+
3780637853
/*
3780737854
** Initialize the state information in data
3780837855
*/
3780937856
static void main_init(ShellState *p) {
3781037857
memset(p, 0, sizeof(*p));
@@ -37825,10 +37872,14 @@
3782537872
#else
3782637873
/* No \001...\002 escapes required for linenoise or when not using a
3782737874
** command-line editing library */
3782837875
p->bDelimitNonprint = 0;
3782937876
#endif
37877
+#if DO_SET_LOCALE
37878
+ setlocale(LC_CTYPE,"");
37879
+#endif
37880
+#undef DO_SET_LOCALE
3783037881
}
3783137882
3783237883
/*
3783337884
** Output text to the console in a font that attracts extra attention.
3783437885
*/
3783537886
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -154,10 +154,11 @@
154 #include <string.h>
155 #include <stdio.h>
156 #include <assert.h>
157 #include <math.h>
158 #include <stdint.h>
 
159 #include "sqlite3.h"
160 typedef sqlite3_int64 i64;
161 typedef sqlite3_uint64 u64;
162 typedef unsigned char u8;
163 #include <ctype.h>
@@ -190,13 +191,14 @@
190 #include <sys/stat.h>
191
192 #if HAVE_READLINE
193 # include <readline/readline.h>
194 # include <readline/history.h>
195 #endif
196
197 #if HAVE_EDITLINE
 
198 # include <editline/readline.h>
199 #endif
200
201 #if HAVE_EDITLINE || HAVE_READLINE
202
@@ -744,12 +746,11 @@
744 const sqlite3_qrf_spec *pSpec, /* Result format specification */
745 char **pzErr /* OUT: Write error message here */
746 );
747
748 /*
749 ** Range of values for sqlite3_qrf_spec.aWidth[] entries and for
750 ** sqlite3_qrf_spec.mxColWidth and .nScreenWidth
751 */
752 #define QRF_MAX_WIDTH 10000
753 #define QRF_MIN_WIDTH 0
754
755 /*
@@ -1129,10 +1130,14 @@
1129 sqlite3_str_append(pOut, "-", 1);
1130 }
1131 if( N<10000 ){
1132 sqlite3_str_appendf(pOut, "%4lld ", N);
1133 return;
 
 
 
 
1134 }
1135 for(i=1; i<=18; i++){
1136 N = (N+5)/10;
1137 if( N<10000 ){
1138 int n = (int)N;
@@ -1289,12 +1294,12 @@
1289 if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
1290 int nSp = 0;
1291 sqlite3_str_reset(pStats);
1292 if( nCycle>=0 && nTotal>0 ){
1293 qrfApproxInt64(pStats, nCycle);
1294 sqlite3_str_appendf(pStats, " %3d%%",
1295 ((nCycle*100)+nTotal/2) / nTotal
1296 );
1297 nSp = 2;
1298 }
1299 if( nLoop>=0 ){
1300 if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
@@ -2532,16 +2537,16 @@
2532 const char *azDash[2] = {
2533 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24,
2534 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24
2535 };/* 0 1 2 3 4 5 6 7 8 9 */
2536 const int nDash = 30;
2537 N *= 3;
2538 while( N>nDash ){
2539 sqlite3_str_append(pOut, azDash[bDbl], nDash);
2540 N -= nDash;
2541 }
2542 sqlite3_str_append(pOut, azDash[bDbl], N);
2543 }
2544
2545 /*
2546 ** Draw a horizontal separator for a QRF_STYLE_Box table.
2547 */
@@ -2610,11 +2615,11 @@
2610 int nSW /* Screen width */
2611 ){
2612 int i; /* Loop counter */
2613 int nr; /* Number of rows */
2614 int w = 0; /* Width of the current column */
2615 int t; /* Total width of all columns */
2616 int *aw; /* Array of individual column widths */
2617
2618 aw = sqlite3_malloc64( sizeof(int)*nCol );
2619 if( aw==0 ){
2620 qrfOom(p);
@@ -2748,12 +2753,15 @@
2748 }else{
2749 sepW = pData->nCol*3 + 1;
2750 if( p->spec.bBorder==QRF_No ) sepW -= 2;
2751 }
2752 nCol = pData->nCol;
2753 for(i=sumW=0; i<nCol; i++) sumW += pData->a[i].w;
2754 if( p->spec.nScreenWidth >= sumW+sepW ) return;
 
 
 
2755
2756 /* First thing to do is reduce the separation between columns */
2757 pData->nMargin = 0;
2758 if( p->spec.eStyle==QRF_STYLE_Column ){
2759 sepW = pData->nCol - 1;
@@ -3624,11 +3632,11 @@
3624 p->nRow = 0;
3625 sz = sizeof(sqlite3_qrf_spec);
3626 memcpy(&p->spec, pSpec, sz);
3627 if( p->spec.zNull==0 ) p->spec.zNull = "";
3628 p->mxWidth = p->spec.nScreenWidth;
3629 if( p->mxWidth<=0 ) p->mxWidth = QRF_MAX_WIDTH;
3630 p->mxHeight = p->spec.nLineLimit;
3631 if( p->mxHeight<=0 ) p->mxHeight = 2147483647;
3632 if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto;
3633 if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
3634 if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
@@ -5272,10 +5280,14 @@
5272 #include <stdarg.h>
5273
5274 /******************************************************************************
5275 ** The Hash Engine
5276 */
 
 
 
 
5277 /* Context for the SHA1 hash */
5278 typedef struct SHA1Context SHA1Context;
5279 struct SHA1Context {
5280 unsigned int state[5];
5281 unsigned int count[2];
@@ -5467,10 +5479,13 @@
5467 zOut[i*2+1] = zEncode[digest[i] & 0xf];
5468 }
5469 zOut[i*2]= 0;
5470 }
5471 }
 
 
 
5472 /* End of the hashing logic
5473 *****************************************************************************/
5474
5475 /*
5476 ** Two SQL functions: sha1(X) and sha1b(X).
@@ -8369,11 +8384,11 @@
8369 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
8370 double r = sqlite3_value_double(argv[iArg++]);
8371 if( r<(double)SMALLEST_INT64 ){
8372 iMin = SMALLEST_INT64;
8373 }else if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8374 iMin = (sqlite3_int64)seriesCeil(r+1.0);
8375 }else{
8376 iMin = (sqlite3_int64)seriesCeil(r);
8377 }
8378 }else{
8379 iMin = sqlite3_value_int64(argv[iArg++]);
@@ -8390,11 +8405,11 @@
8390 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
8391 double r = sqlite3_value_double(argv[iArg++]);
8392 if( r>(double)LARGEST_INT64 ){
8393 iMax = LARGEST_INT64;
8394 }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8395 iMax = (sqlite3_int64)(r-1.0);
8396 }else{
8397 iMax = (sqlite3_int64)seriesFloor(r);
8398 }
8399 }else{
8400 iMax = sqlite3_value_int64(argv[iArg++]);
@@ -9638,11 +9653,10 @@
9638 if( pRe==0 ){
9639 sqlite3_result_error_nomem(context);
9640 return;
9641 }
9642 pStr = sqlite3_str_new(0);
9643 if( pStr==0 ) goto re_bytecode_func_err;
9644 if( pRe->nInit>0 ){
9645 sqlite3_str_appendf(pStr, "INIT ");
9646 for(i=0; i<pRe->nInit; i++){
9647 sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
9648 }
@@ -9649,20 +9663,20 @@
9649 sqlite3_str_appendf(pStr, "\n");
9650 }
9651 for(i=0; (unsigned)i<pRe->nState; i++){
9652 sqlite3_str_appendf(pStr, "%-8s %4d\n",
9653 ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
 
 
 
 
 
 
9654 }
9655 n = sqlite3_str_length(pStr);
9656 z = sqlite3_str_finish(pStr);
9657 if( n==0 ){
9658 sqlite3_free(z);
9659 }else{
9660 sqlite3_result_text(context, z, n-1, sqlite3_free);
9661 }
9662
9663 re_bytecode_func_err:
9664 re_free(pRe);
9665 }
9666
9667 #endif /* SQLITE_DEBUG */
9668
@@ -25172,11 +25186,11 @@
25172 case 1:
25173 #if defined(SQLITE_PS1)
25174 return SQLITE_PS1;
25175 #else
25176 if( shellNoColor() ){
25177 return "/A-/v /~> ";
25178 }else{
25179 return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> ";
25180 }
25181 #endif
25182
@@ -25184,11 +25198,11 @@
25184 case 2:
25185 #if defined(SQLITE_PS2)
25186 return SQLITE_PS2;
25187 #else
25188 if( shellNoColor() ){
25189 return "/B/C> ";
25190 }else{
25191 return "/B/e[1;/x33/:36/;m/C/e[0m-> ";
25192 }
25193 #endif
25194
@@ -26976,11 +26990,11 @@
26976 return SQLITE_OK;
26977 }
26978 #endif
26979
26980 /*
26981 ** Print a schema statement. This is helper routine to dump_callbac().
26982 **
26983 ** This routine converts some CREATE TABLE statements for shadow tables
26984 ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements.
26985 **
26986 ** If the schema statement in z[] contains a start-of-comment and if
@@ -28540,10 +28554,13 @@
28540 " --reset Reset the count for each input and interrupt",
28541 " --timeout S Halt after running for S seconds",
28542 #endif
28543 ".prompt MAIN CONTINUE Replace the standard prompts",
28544 " --hard-reset Unset SQLITE_PS1/2 and then --reset",
 
 
 
28545 " --reset Revert to default prompts",
28546 " --show Show the current prompt strings",
28547 " -- No more options. Subsequent args are prompts",
28548 #ifndef SQLITE_SHELL_FIDDLE
28549 ".quit Stop interpreting input stream, exit if primary.",
@@ -35491,10 +35508,26 @@
35491 }else
35492 if( strcmp(z,"-show")==0 ){
35493 cli_printf(stdout,"Main prompt: '%s'\n", prompt_string(p, 0));
35494 cli_printf(stdout,"Continuation: '%s'\n", prompt_string(p, 1));
35495 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35496 if( strcmp(z,"-")==0 ){
35497 noOpt = 1;
35498 }else
35499 {
35500 dotCmdError(p, i, "unknown option", 0);
@@ -35505,10 +35538,11 @@
35505 dotCmdError(p, i, "extra argument", 0);
35506 rc = 1;
35507 goto meta_command_exit;
35508 }else if( !p->dot.abQuot[i] && sqlite3_strglob("*[^a-z]*",z)!=0 ){
35509 dotCmdError(p, i, "use quotes around the prompt string", 0);
 
35510 }else{
35511 free(p->azPrompt[cnt]);
35512 p->azPrompt[cnt] = strdup(z);
35513 cnt++;
35514 }
@@ -37801,10 +37835,23 @@
37801 sputz(stdout, "WARNING: attempt to configure SQLite after"
37802 " initialization.\n");
37803 }
37804 }
37805
 
 
 
 
 
 
 
 
 
 
 
 
 
37806 /*
37807 ** Initialize the state information in data
37808 */
37809 static void main_init(ShellState *p) {
37810 memset(p, 0, sizeof(*p));
@@ -37825,10 +37872,14 @@
37825 #else
37826 /* No \001...\002 escapes required for linenoise or when not using a
37827 ** command-line editing library */
37828 p->bDelimitNonprint = 0;
37829 #endif
 
 
 
 
37830 }
37831
37832 /*
37833 ** Output text to the console in a font that attracts extra attention.
37834 */
37835
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -154,10 +154,11 @@
154 #include <string.h>
155 #include <stdio.h>
156 #include <assert.h>
157 #include <math.h>
158 #include <stdint.h>
159 #include <time.h>
160 #include "sqlite3.h"
161 typedef sqlite3_int64 i64;
162 typedef sqlite3_uint64 u64;
163 typedef unsigned char u8;
164 #include <ctype.h>
@@ -190,13 +191,14 @@
191 #include <sys/stat.h>
192
193 #if HAVE_READLINE
194 # include <readline/readline.h>
195 # include <readline/history.h>
196 #elif HAVE_EDITLINE
197 /* If both HAVE_READLINE and HAVE_EDITLINE are true, assume that this
198 ** libedit installation does not have its own headers, instead using
199 ** those from libreadline. */
200 # include <editline/readline.h>
201 #endif
202
203 #if HAVE_EDITLINE || HAVE_READLINE
204
@@ -744,12 +746,11 @@
746 const sqlite3_qrf_spec *pSpec, /* Result format specification */
747 char **pzErr /* OUT: Write error message here */
748 );
749
750 /*
751 ** Range of values for sqlite3_qrf_spec.aWidth[] entries.
 
752 */
753 #define QRF_MAX_WIDTH 10000
754 #define QRF_MIN_WIDTH 0
755
756 /*
@@ -1129,10 +1130,14 @@
1130 sqlite3_str_append(pOut, "-", 1);
1131 }
1132 if( N<10000 ){
1133 sqlite3_str_appendf(pOut, "%4lld ", N);
1134 return;
1135 }
1136 if( N>=9223372036854775800LL ){
1137 sqlite3_str_appendf(pOut, "%.2fE", 1e-18*(double)N);
1138 return;
1139 }
1140 for(i=1; i<=18; i++){
1141 N = (N+5)/10;
1142 if( N<10000 ){
1143 int n = (int)N;
@@ -1289,12 +1294,12 @@
1294 if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
1295 int nSp = 0;
1296 sqlite3_str_reset(pStats);
1297 if( nCycle>=0 && nTotal>0 ){
1298 qrfApproxInt64(pStats, nCycle);
1299 sqlite3_str_appendf(pStats, " %3.0f%%",
1300 ((100.0*(double)nCycle)+nTotal/2.0) / (double)nTotal
1301 );
1302 nSp = 2;
1303 }
1304 if( nLoop>=0 ){
1305 if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' ');
@@ -2532,16 +2537,16 @@
2537 const char *azDash[2] = {
2538 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24,
2539 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24
2540 };/* 0 1 2 3 4 5 6 7 8 9 */
2541 const int nDash = 30;
2542 i64 nn = 3*(i64)N;
2543 while( nn>nDash ){
2544 sqlite3_str_append(pOut, azDash[bDbl], nDash);
2545 nn -= nDash;
2546 }
2547 sqlite3_str_append(pOut, azDash[bDbl], (int)nn);
2548 }
2549
2550 /*
2551 ** Draw a horizontal separator for a QRF_STYLE_Box table.
2552 */
@@ -2610,11 +2615,11 @@
2615 int nSW /* Screen width */
2616 ){
2617 int i; /* Loop counter */
2618 int nr; /* Number of rows */
2619 int w = 0; /* Width of the current column */
2620 i64 t; /* Total width of all columns */
2621 int *aw; /* Array of individual column widths */
2622
2623 aw = sqlite3_malloc64( sizeof(int)*nCol );
2624 if( aw==0 ){
2625 qrfOom(p);
@@ -2748,12 +2753,15 @@
2753 }else{
2754 sepW = pData->nCol*3 + 1;
2755 if( p->spec.bBorder==QRF_No ) sepW -= 2;
2756 }
2757 nCol = pData->nCol;
2758 for(i=0, sumW=0; i<nCol; i++){
2759 if( sumW > 2147483647 - pData->a[i].w ) return;
2760 sumW += pData->a[i].w;
2761 }
2762 if( p->spec.nScreenWidth >= (i64)sumW + sepW ) return;
2763
2764 /* First thing to do is reduce the separation between columns */
2765 pData->nMargin = 0;
2766 if( p->spec.eStyle==QRF_STYLE_Column ){
2767 sepW = pData->nCol - 1;
@@ -3624,11 +3632,11 @@
3632 p->nRow = 0;
3633 sz = sizeof(sqlite3_qrf_spec);
3634 memcpy(&p->spec, pSpec, sz);
3635 if( p->spec.zNull==0 ) p->spec.zNull = "";
3636 p->mxWidth = p->spec.nScreenWidth;
3637 if( p->mxWidth<=0 ) p->mxWidth = 2147483647;
3638 p->mxHeight = p->spec.nLineLimit;
3639 if( p->mxHeight<=0 ) p->mxHeight = 2147483647;
3640 if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto;
3641 if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto;
3642 if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto;
@@ -5272,10 +5280,14 @@
5280 #include <stdarg.h>
5281
5282 /******************************************************************************
5283 ** The Hash Engine
5284 */
5285 #if defined(__GNUC__) && __GNUC__>=11
5286 # pragma GCC diagnostic push
5287 # pragma GCC diagnostic ignored "-Wstringop-overread"
5288 #endif
5289 /* Context for the SHA1 hash */
5290 typedef struct SHA1Context SHA1Context;
5291 struct SHA1Context {
5292 unsigned int state[5];
5293 unsigned int count[2];
@@ -5467,10 +5479,13 @@
5479 zOut[i*2+1] = zEncode[digest[i] & 0xf];
5480 }
5481 zOut[i*2]= 0;
5482 }
5483 }
5484 #if defined(__GNUC__) && __GNUC__>=11
5485 # pragma GCC diagnostic pop
5486 #endif
5487 /* End of the hashing logic
5488 *****************************************************************************/
5489
5490 /*
5491 ** Two SQL functions: sha1(X) and sha1b(X).
@@ -8369,11 +8384,11 @@
8384 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
8385 double r = sqlite3_value_double(argv[iArg++]);
8386 if( r<(double)SMALLEST_INT64 ){
8387 iMin = SMALLEST_INT64;
8388 }else if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8389 iMin = (sqlite3_int64)seriesCeil(r)+1;
8390 }else{
8391 iMin = (sqlite3_int64)seriesCeil(r);
8392 }
8393 }else{
8394 iMin = sqlite3_value_int64(argv[iArg++]);
@@ -8390,11 +8405,11 @@
8405 if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){
8406 double r = sqlite3_value_double(argv[iArg++]);
8407 if( r>(double)LARGEST_INT64 ){
8408 iMax = LARGEST_INT64;
8409 }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8410 iMax = ((sqlite3_int64)r)-1;
8411 }else{
8412 iMax = (sqlite3_int64)seriesFloor(r);
8413 }
8414 }else{
8415 iMax = sqlite3_value_int64(argv[iArg++]);
@@ -9638,11 +9653,10 @@
9653 if( pRe==0 ){
9654 sqlite3_result_error_nomem(context);
9655 return;
9656 }
9657 pStr = sqlite3_str_new(0);
 
9658 if( pRe->nInit>0 ){
9659 sqlite3_str_appendf(pStr, "INIT ");
9660 for(i=0; i<pRe->nInit; i++){
9661 sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
9662 }
@@ -9649,20 +9663,20 @@
9663 sqlite3_str_appendf(pStr, "\n");
9664 }
9665 for(i=0; (unsigned)i<pRe->nState; i++){
9666 sqlite3_str_appendf(pStr, "%-8s %4d\n",
9667 ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
9668 }
9669 if( sqlite3_str_errcode(pStr)==SQLITE_NOMEM ){
9670 sqlite3_str_finish(pStr);
9671 re_free(pRe);
9672 sqlite3_result_error_nomem(context);
9673 return;
9674 }
9675 n = sqlite3_str_length(pStr);
9676 z = sqlite3_str_finish(pStr);
9677 sqlite3_result_text(context, z, n-1, sqlite3_free);
 
 
 
 
 
 
9678 re_free(pRe);
9679 }
9680
9681 #endif /* SQLITE_DEBUG */
9682
@@ -25172,11 +25186,11 @@
25186 case 1:
25187 #if defined(SQLITE_PS1)
25188 return SQLITE_PS1;
25189 #else
25190 if( shellNoColor() ){
25191 return "/A-/v /f-> ";
25192 }else{
25193 return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> ";
25194 }
25195 #endif
25196
@@ -25184,11 +25198,11 @@
25198 case 2:
25199 #if defined(SQLITE_PS2)
25200 return SQLITE_PS2;
25201 #else
25202 if( shellNoColor() ){
25203 return "/B/C-> ";
25204 }else{
25205 return "/B/e[1;/x33/:36/;m/C/e[0m-> ";
25206 }
25207 #endif
25208
@@ -26976,11 +26990,11 @@
26990 return SQLITE_OK;
26991 }
26992 #endif
26993
26994 /*
26995 ** Print a schema statement. This is a helper routine to dump_callback().
26996 **
26997 ** This routine converts some CREATE TABLE statements for shadow tables
26998 ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements.
26999 **
27000 ** If the schema statement in z[] contains a start-of-comment and if
@@ -28540,10 +28554,13 @@
28554 " --reset Reset the count for each input and interrupt",
28555 " --timeout S Halt after running for S seconds",
28556 #endif
28557 ".prompt MAIN CONTINUE Replace the standard prompts",
28558 " --hard-reset Unset SQLITE_PS1/2 and then --reset",
28559 #ifndef SQLITE_NO_COLOR
28560 " --no-color Disable color prompts. Use --color to re-enable",
28561 #endif
28562 " --reset Revert to default prompts",
28563 " --show Show the current prompt strings",
28564 " -- No more options. Subsequent args are prompts",
28565 #ifndef SQLITE_SHELL_FIDDLE
28566 ".quit Stop interpreting input stream, exit if primary.",
@@ -35491,10 +35508,26 @@
35508 }else
35509 if( strcmp(z,"-show")==0 ){
35510 cli_printf(stdout,"Main prompt: '%s'\n", prompt_string(p, 0));
35511 cli_printf(stdout,"Continuation: '%s'\n", prompt_string(p, 1));
35512 }else
35513 #ifndef SQLITE_NO_COLOR
35514 if( strcmp(z,"-color")==0 ){
35515 #ifdef _WIN32
35516 _putenv("NO_COLOR=");
35517 #else
35518 unsetenv("NO_COLOR");
35519 #endif
35520 }else
35521 if( strcmp(z,"-no-color")==0 ){
35522 #ifdef _WIN32
35523 _putenv("NO_COLOR=1");
35524 #else
35525 setenv("NO_COLOR","1",1);
35526 #endif
35527 }else
35528 #endif
35529 if( strcmp(z,"-")==0 ){
35530 noOpt = 1;
35531 }else
35532 {
35533 dotCmdError(p, i, "unknown option", 0);
@@ -35505,10 +35538,11 @@
35538 dotCmdError(p, i, "extra argument", 0);
35539 rc = 1;
35540 goto meta_command_exit;
35541 }else if( !p->dot.abQuot[i] && sqlite3_strglob("*[^a-z]*",z)!=0 ){
35542 dotCmdError(p, i, "use quotes around the prompt string", 0);
35543 rc = 1;
35544 }else{
35545 free(p->azPrompt[cnt]);
35546 p->azPrompt[cnt] = strdup(z);
35547 cnt++;
35548 }
@@ -37801,10 +37835,23 @@
37835 sputz(stdout, "WARNING: attempt to configure SQLite after"
37836 " initialization.\n");
37837 }
37838 }
37839
37840 #if HAVE_EDITLINE
37841 /*
37842 ** https://sqlite.org/forum/forumpost/aad7a634916ff050:
37843 **
37844 ** Calling setlocale(LC_ALL,"") is required to get libedit to accept
37845 ** non-ASCII input.
37846 */
37847 #define DO_SET_LOCALE 1
37848 #include <locale.h>
37849 #else
37850 #define DO_SET_LOCALE 0
37851 #endif
37852
37853 /*
37854 ** Initialize the state information in data
37855 */
37856 static void main_init(ShellState *p) {
37857 memset(p, 0, sizeof(*p));
@@ -37825,10 +37872,14 @@
37872 #else
37873 /* No \001...\002 escapes required for linenoise or when not using a
37874 ** command-line editing library */
37875 p->bDelimitNonprint = 0;
37876 #endif
37877 #if DO_SET_LOCALE
37878 setlocale(LC_CTYPE,"");
37879 #endif
37880 #undef DO_SET_LOCALE
37881 }
37882
37883 /*
37884 ** Output text to the console in a font that attracts extra attention.
37885 */
37886
+699 -270
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 7e4134e3ff1ca8712f5fc78fadae66554945 with changes in files:
21
+** 9ac4a33a2932d353c4871fd8e09c10addf82 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.54.0"
471471
#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb"
472
+#define SQLITE_SOURCE_ID "2026-05-21 15:14:35 9ac4a33a2932d353c4871fd8e09c10addf827f1fc3fc9380037d738cf2cd0353"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-05-04T10:14:13.819Z"
475
+#define SQLITE_SCM_DATETIME "2026-05-21T15:14:35.420Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -4373,12 +4373,11 @@
43734373
** parameter on F or if the value of P does not match any of the
43744374
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
43754375
**
43764376
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
43774377
** 64-bit signed integer and returns that integer, or D if P does not
4378
-** exist. If the value of P is something other than an integer, then
4379
-** zero is returned.
4378
+** exist or ff the value of P is something other than an integer.
43804379
**
43814380
** The sqlite3_uri_key(F,N) returns a pointer to the name (not
43824381
** the value) of the N-th query parameter for filename F, or a NULL
43834382
** pointer if N is less than zero or greater than the number of query
43844383
** parameters minus 1. The N value is zero-based so N should be 0 to obtain
@@ -18705,11 +18704,11 @@
1870518704
int aLimit[SQLITE_N_LIMIT]; /* Limits */
1870618705
int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
1870718706
struct sqlite3InitInfo { /* Information used during initialization */
1870818707
Pgno newTnum; /* Rootpage of table being initialized */
1870918708
u8 iDb; /* Which db file is being initialized */
18710
- u8 busy; /* TRUE if currently initializing */
18709
+ u8 busy; /* TRUE if initing. 2 if due to ADD COLUMN */
1871118710
unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
1871218711
unsigned imposterTable : 2; /* Building an imposter table */
1871318712
unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
1871418713
const char **azInit; /* "type", "name", and "tbl_name" columns */
1871518714
} init;
@@ -21256,11 +21255,11 @@
2125621255
*/
2125721256
#define INITFLAG_AlterMask 0x0007 /* Types of ALTER */
2125821257
#define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
2125921258
#define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
2126021259
#define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
21261
-#define INITFLAG_AlterDropCons 0x0004 /* Reparse after an ADD COLUMN */
21260
+#define INITFLAG_AlterDropCons 0x0004 /* Reparse after a DROP CONSTRAINT */
2126221261
2126321262
/* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
2126421263
** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
2126521264
** parameters are for temporary use during development, to help find
2126621265
** optimal values for parameters in the query planner. The should not
@@ -22509,11 +22508,19 @@
2250922508
SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
2251022509
SQLITE_PRIVATE void sqlite3AlterFunctions(void);
2251122510
SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
2251222511
SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
2251322512
SQLITE_PRIVATE void sqlite3AlterDropConstraint(Parse*,SrcList*,Token*,Token*);
22514
-SQLITE_PRIVATE void sqlite3AlterAddConstraint(Parse*,SrcList*,Token*,Token*,const char*,int);
22513
+SQLITE_PRIVATE void sqlite3AlterAddConstraint(
22514
+ Parse *pParse, /* Parse context */
22515
+ SrcList *pSrc, /* Table to add constraint to */
22516
+ Token *pFirst, /* First token of new constraint */
22517
+ Token *pName, /* Name of new constraint. NULL if name omitted. */
22518
+ const char *zExpr, /* Text of CHECK expression */
22519
+ int nExpr, /* Size of pExpr in bytes */
22520
+ Expr *pExpr /* The parsed CHECK expression */
22521
+);
2251522522
SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*);
2251622523
SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *);
2251722524
SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
2251822525
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
2251922526
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
@@ -32413,12 +32420,14 @@
3241332420
#define etSRCITEM 12 /* a pointer to a SrcItem */
3241432421
#define etPOINTER 13 /* The %p conversion */
3241532422
#define etESCAPE_w 14 /* %w -> Strings with '\"' doubled */
3241632423
#define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
3241732424
#define etDECIMAL 16 /* %d or %u, but not %x, %o */
32425
+#define etESCAPE_j 17 /* %j -> JSON string literal w/o "..." */
32426
+#define etESCAPE_J 18 /* %J -> JSON string literal with "..." */
3241832427
32419
-#define etINVALID 17 /* Any unrecognized conversion type */
32428
+#define etINVALID 19 /* Any unrecognized conversion type */
3242032429
3242132430
3242232431
/*
3242332432
** An "etByte" is an 8-bit unsigned value.
3242432433
*/
@@ -32444,24 +32453,24 @@
3244432453
#define FLAG_SIGNED 1 /* True if the value to convert is signed */
3244532454
#define FLAG_STRING 4 /* Allow infinite precision */
3244632455
3244732456
/*
3244832457
** The table is searched by hash. In the case of %C where C is the character
32449
-** and that character has ASCII value j, then the hash is j%23.
32458
+** and that character has ASCII value j, then the hash is j%25.
3245032459
**
3245132460
** The order of the entries in fmtinfo[] and the hash chain was entered
3245232461
** manually, but based on the output of the following TCL script:
3245332462
*/
3245432463
#if 0 /***** Beginning of script ******/
32455
-foreach c {d s g z q Q w c o u x X f e E G i n % p T S r} {
32464
+foreach c {d s g z q Q w c o u x X f e E G i n % p T S r J j} {
3245632465
scan $c %c x
3245732466
set n($c) $x
3245832467
}
3245932468
set mx [llength [array names n]]
3246032469
puts "count: $mx"
3246132470
32462
-set mx 27
32471
+set mx 25
3246332472
puts "*********** mx=$mx ************"
3246432473
for {set r 0} {$r<$mx} {incr r} {
3246532474
puts -nonewline [format %2d: $r]
3246632475
foreach c [array names n] {
3246732476
if {($n($c))%$mx==$r} {puts -nonewline " $c"}
@@ -32469,35 +32478,38 @@
3246932478
puts ""
3247032479
}
3247132480
#endif /***** End of script ********/
3247232481
3247332482
static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
32483
+static const char aHex[] = "0123456789abcdef";
3247432484
static const char aPrefix[] = "-x0\000X0";
32475
-static const et_info fmtinfo[23] = {
32476
- /* 0 */ { 's', 0, 4, etSTRING, 0, 0, 1 },
32477
- /* 1 */ { 'E', 0, 1, etEXP, 14, 0, 0 }, /* Hash: 0 */
32478
- /* 2 */ { 'u', 10, 0, etDECIMAL, 0, 0, 3 },
32479
- /* 3 */ { 'G', 0, 1, etGENERIC, 14, 0, 0 }, /* Hash: 2 */
32480
- /* 4 */ { 'w', 0, 4, etESCAPE_w, 0, 0, 0 },
32481
- /* 5 */ { 'x', 16, 0, etRADIX, 16, 1, 0 },
32482
- /* 6 */ { 'c', 0, 0, etCHARX, 0, 0, 0 }, /* Hash: 7 */
32483
- /* 7 */ { 'z', 0, 4, etDYNSTRING, 0, 0, 6 },
32484
- /* 8 */ { 'd', 10, 1, etDECIMAL, 0, 0, 0 },
32485
- /* 9 */ { 'e', 0, 1, etEXP, 30, 0, 0 },
32486
- /* 10 */ { 'f', 0, 1, etFLOAT, 0, 0, 0 },
32487
- /* 11 */ { 'g', 0, 1, etGENERIC, 30, 0, 0 },
32488
- /* 12 */ { 'Q', 0, 4, etESCAPE_Q, 0, 0, 0 },
32489
- /* 13 */ { 'i', 10, 1, etDECIMAL, 0, 0, 0 },
32490
- /* 14 */ { '%', 0, 0, etPERCENT, 0, 0, 16 },
32491
- /* 15 */ { 'T', 0, 0, etTOKEN, 0, 0, 0 },
32492
- /* 16 */ { 'S', 0, 0, etSRCITEM, 0, 0, 0 }, /* Hash: 14 */
32493
- /* 17 */ { 'X', 16, 0, etRADIX, 0, 4, 0 }, /* Hash: 19 */
32494
- /* 18 */ { 'n', 0, 0, etSIZE, 0, 0, 0 },
32495
- /* 19 */ { 'o', 8, 0, etRADIX, 0, 2, 17 },
32496
- /* 20 */ { 'p', 16, 0, etPOINTER, 0, 1, 0 },
32497
- /* 21 */ { 'q', 0, 4, etESCAPE_q, 0, 0, 0 },
32498
- /* 22 */ { 'r', 10, 1, etORDINAL, 0, 0, 0 }
32485
+static const et_info fmtinfo[25] = {
32486
+ /* 0 */ { 'd', 10, 1, etDECIMAL, 0, 0, 0 },
32487
+ /* 1 */ { 'e', 0, 1, etEXP, 30, 0, 0 },
32488
+ /* 2 */ { 'f', 0, 1, etFLOAT, 0, 0, 0 },
32489
+ /* 3 */ { 'g', 0, 1, etGENERIC, 30, 0, 0 },
32490
+ /* 4 */ { 'j', 0, 0, etESCAPE_j, 0, 0, 0 }, /* Hash: 6 */
32491
+ /* 5 */ { 'i', 10, 1, etDECIMAL, 0, 0, 0 },
32492
+ /* 6 */ { 'Q', 0, 4, etESCAPE_Q, 0, 0, 4 },
32493
+ /* 7 */ { 'p', 16, 0, etPOINTER, 0, 1, 0 }, /* Hash: 12 */
32494
+ /* 8 */ { 'S', 0, 0, etSRCITEM, 0, 0, 0 },
32495
+ /* 9 */ { 'T', 0, 0, etTOKEN, 0, 0, 0 },
32496
+ /* 10 */ { 'n', 0, 0, etSIZE, 0, 0, 0 },
32497
+ /* 11 */ { 'o', 8, 0, etRADIX, 0, 2, 0 },
32498
+ /* 12 */ { '%', 0, 0, etPERCENT, 0, 0, 7 },
32499
+ /* 13 */ { 'q', 0, 4, etESCAPE_q, 0, 0, 16 },
32500
+ /* 14 */ { 'r', 10, 1, etORDINAL, 0, 0, 0 },
32501
+ /* 15 */ { 's', 0, 4, etSTRING, 0, 0, 0 },
32502
+ /* 16 */ { 'X', 16, 0, etRADIX, 0, 4, 0 }, /* Hash: 13 */
32503
+ /* 17 */ { 'u', 10, 0, etDECIMAL, 0, 0, 0 },
32504
+ /* 18 */ { 'w', 0, 4, etESCAPE_w, 0, 0, 0 }, /* Hash: 19 */
32505
+ /* 19 */ { 'E', 0, 1, etEXP, 14, 0, 18 },
32506
+ /* 20 */ { 'x', 16, 0, etRADIX, 16, 1, 0 },
32507
+ /* 21 */ { 'G', 0, 1, etGENERIC, 14, 0, 0 },
32508
+ /* 22 */ { 'z', 0, 4, etDYNSTRING, 0, 0, 0 },
32509
+ /* 23 */ { 'J', 0, 0, etESCAPE_J, 0, 0, 0 }, /* Hash: 24 */
32510
+ /* 24 */ { 'c', 0, 0, etCHARX, 0, 0, 23 }
3249932511
};
3250032512
3250132513
/* Additional Notes:
3250232514
**
3250332515
** %S Takes a pointer to SrcItem. Shows name or database.name
@@ -32754,12 +32766,12 @@
3275432766
break;
3275532767
}
3275632768
}
3275732769
#else
3275832770
/* Fast hash-table lookup */
32759
- assert( ArraySize(fmtinfo)==23 );
32760
- idx = ((unsigned)c) % 23;
32771
+ assert( ArraySize(fmtinfo)==25 );
32772
+ idx = ((unsigned)c) % 25;
3276132773
if( fmtinfo[idx].fmttype==c
3276232774
|| fmtinfo[idx = fmtinfo[idx].iNxt].fmttype==c
3276332775
){
3276432776
infop = &fmtinfo[idx];
3276532777
xtype = infop->type;
@@ -33126,11 +33138,11 @@
3312633138
length = width;
3312733139
}
3312833140
3312933141
if( zExtra==0 ){
3313033142
/* The result is being rendered directory into pAccum. This
33131
- ** is the command and fast case */
33143
+ ** is the common and fast case */
3313233144
pAccum->nChar += length;
3313333145
zOut[length] = 0;
3313433146
continue;
3313533147
}else{
3313633148
/* We were unable to render directly into pAccum because we
@@ -33246,10 +33258,87 @@
3324633258
/* Adjust width to account for extra bytes in UTF-8 characters */
3324733259
int ii = length - 1;
3324833260
while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++;
3324933261
}
3325033262
break;
33263
+ case etESCAPE_j: /* %j: JSON string literal w/o "..." */
33264
+ case etESCAPE_J: { /* %J: Generate a JSON string literal */
33265
+ char *escarg;
33266
+ i64 i, j, px, iStart;
33267
+ unsigned char ch;
33268
+
33269
+ if( bArgList ){
33270
+ escarg = getTextArg(pArgList);
33271
+ }else{
33272
+ escarg = va_arg(ap,char*);
33273
+ }
33274
+ iStart = sqlite3_str_length(pAccum);
33275
+ if( escarg==0 ){
33276
+ if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "null", 4);
33277
+ }else{
33278
+ if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1);
33279
+ px = precision;
33280
+ testcase( px==0 );
33281
+ if( px<0 ){
33282
+ px = 0x7fffffff;
33283
+ }else if( flag_altform2 ){
33284
+ /* Convert precision from code-points to bytes */
33285
+ for(i=0; i<px && escarg[i]; i++){
33286
+ if( (escarg[i]&0xc0)==0x80 ) px++;
33287
+ }
33288
+ if( i==px ){
33289
+ while( (escarg[px]&0xc0)==0x80 ) px++;
33290
+ }
33291
+ }
33292
+ for(i=j=0; i<px; i++){
33293
+ if( (ch = ((u8*)escarg)[i])<=0x1f || ch=='"' || ch=='\\' ){
33294
+ if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j);
33295
+ j = i+1;
33296
+ if( ch==0 ) break;
33297
+ sqlite3_str_appendchar(pAccum, 1, '\\');
33298
+ if( ch>0x1f ){
33299
+ sqlite3_str_appendchar(pAccum, 1, ch);
33300
+ }else if( ((1u<<ch)&0x3700)!=0 ){
33301
+ ch = "btn?fr"[ch-8];
33302
+ sqlite3_str_appendchar(pAccum, 1, ch);
33303
+ }else{
33304
+ sqlite3_str_append(pAccum, "u00", 3);
33305
+ sqlite3_str_appendchar(pAccum, 1, aHex[ch>>4]);
33306
+ sqlite3_str_appendchar(pAccum, 1, aHex[ch&0xf]);
33307
+ }
33308
+ }
33309
+ }
33310
+ if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j);
33311
+ if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1);
33312
+ }
33313
+ if( width>0 && sqlite3_str_errcode(pAccum)==SQLITE_OK ){
33314
+ sqlite3_int64 n = sqlite3_str_length(pAccum) - iStart;
33315
+ sqlite3_int64 len = n;
33316
+ char *zz;
33317
+ if( flag_altform2 && n>0 ){
33318
+ zz = sqlite3_str_value(pAccum);
33319
+ for(i=iStart; zz[i]; i++){
33320
+ if( (zz[i]&0xc0)==0x80 ) len--;
33321
+ }
33322
+ }
33323
+ if( width>len ){
33324
+ sqlite3_int64 sp = width-len;
33325
+ assert( sp>0 && sp<0x7fffffff );
33326
+ sqlite3_str_appendchar(pAccum, (int)sp, ' ');
33327
+ if( !flag_leftjustify
33328
+ && n>0
33329
+ && sqlite3_str_errcode(pAccum)==0
33330
+ ){
33331
+ zz = sqlite3_str_value(pAccum);
33332
+ zz += iStart;
33333
+ memmove(zz+sp, zz, n);
33334
+ memset(zz, ' ', sp);
33335
+ }
33336
+ }
33337
+ }
33338
+ continue;
33339
+ }
3325133340
case etESCAPE_q: /* %q: Escape ' characters */
3325233341
case etESCAPE_Q: /* %Q: Escape ' and enclose in '...' */
3325333342
case etESCAPE_w: { /* %w: Escape " characters */
3325433343
i64 i, j, k, n;
3325533344
int needQuote = 0;
@@ -33337,11 +33426,11 @@
3333733426
bufpt[j-1] = '\\';
3333833427
bufpt[j++] = 'u';
3333933428
bufpt[j++] = '0';
3334033429
bufpt[j++] = '0';
3334133430
bufpt[j++] = ch>=0x10 ? '1' : '0';
33342
- bufpt[j++] = "0123456789abcdef"[ch&0xf];
33431
+ bufpt[j++] = aHex[ch&0xf];
3334333432
}
3334433433
}
3334533434
}else{
3334633435
for(i=0; i<k; i++){
3334733436
bufpt[j++] = ch = escarg[i];
@@ -45345,13 +45434,13 @@
4534545434
4534645435
/* Minimum number of regions required to be mapped. */
4534745436
nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap;
4534845437
4534945438
if( pShmNode->nRegion<nReqRegion ){
45350
- char **apNew; /* New apRegion[] array */
45351
- int nByte = nReqRegion*szRegion; /* Minimum required file size */
45352
- struct stat sStat; /* Used by fstat() */
45439
+ char **apNew; /* New apRegion[] array */
45440
+ i64 nByte = nReqRegion*(i64)szRegion; /* Minimum required file size */
45441
+ struct stat sStat; /* Used by fstat() */
4535345442
4535445443
pShmNode->szRegion = szRegion;
4535545444
4535645445
if( pShmNode->hShm>=0 ){
4535745446
/* The requested region is not mapped into this processes address space.
@@ -45378,11 +45467,11 @@
4537845467
** pages forces the OS to allocate them immediately, which reduces
4537945468
** the chances of SIGBUS while accessing the mapped region later on.
4538045469
*/
4538145470
else{
4538245471
static const int pgsz = 4096;
45383
- int iPg;
45472
+ i64 iPg;
4538445473
4538545474
/* Write to the last byte of each newly allocated or extended page */
4538645475
assert( (nByte % pgsz)==0 );
4538745476
for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){
4538845477
int x = 0;
@@ -45404,12 +45493,12 @@
4540445493
rc = SQLITE_IOERR_NOMEM_BKPT;
4540545494
goto shmpage_out;
4540645495
}
4540745496
pShmNode->apRegion = apNew;
4540845497
while( pShmNode->nRegion<nReqRegion ){
45409
- int nMap = szRegion*nShmPerMap;
45410
- int i;
45498
+ i64 nMap = (i64)szRegion*(i64)nShmPerMap;
45499
+ i64 i;
4541145500
void *pMem;
4541245501
if( pShmNode->hShm>=0 ){
4541345502
pMem = osMmap(0, nMap,
4541445503
pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE,
4541545504
MAP_SHARED, pShmNode->hShm, szRegion*(i64)pShmNode->nRegion
@@ -49195,107 +49284,154 @@
4919549284
4919649285
{ "CreateFileW", (SYSCALL)CreateFileW, 0 },
4919749286
#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
4919849287
LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent)
4919949288
49289
+#if defined(SQLITE_UWP)
49290
+ { "CreateFileMappingFromApp",(SYSCALL)CreateFileMappingFromApp,0 },
49291
+#else
49292
+ { "CreateFileMappingFromApp",(SYSCALL)0, 0 },
49293
+#endif
49294
+#define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE,\
49295
+ PSECURITY_ATTRIBUTES, \
49296
+ ULONG,ULONG64,PCWSTR))aSyscall[3].pCurrent)
49297
+
49298
+#if !defined(SQLITE_UWP)
4920049299
{ "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
49300
+#else
49301
+ { "CreateFileMappingW", (SYSCALL)0, 0 },
49302
+#endif
4920149303
#define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
49202
- DWORD,DWORD,DWORD,LPCWSTR))aSyscall[3].pCurrent)
49304
+ DWORD,DWORD,DWORD,LPCWSTR))aSyscall[4].pCurrent)
4920349305
4920449306
{ "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
49205
-#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[4].pCurrent)
49307
+#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[5].pCurrent)
4920649308
4920749309
{ "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
49208
-#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[5].pCurrent)
49310
+#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[6].pCurrent)
4920949311
4921049312
{ "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
4921149313
#define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
49212
- DWORD,va_list*))aSyscall[6].pCurrent)
49314
+ DWORD,va_list*))aSyscall[7].pCurrent)
4921349315
49214
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49316
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP)
4921549317
{ "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
4921649318
#else
4921749319
{ "FreeLibrary", (SYSCALL)0, 0 },
4921849320
#endif
4921949321
49220
-#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[7].pCurrent)
49322
+#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[8].pCurrent)
4922149323
4922249324
{ "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
49223
-#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[8].pCurrent)
49325
+#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[9].pCurrent)
4922449326
4922549327
{ "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
49226
-#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent)
49328
+#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
4922749329
4922849330
{ "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
4922949331
#define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
49230
- LPVOID))aSyscall[10].pCurrent)
49332
+ LPVOID))aSyscall[11].pCurrent)
4923149333
49232
- { "GetFileSize", (SYSCALL)GetFileSize, 0 },
49233
-#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[11].pCurrent)
49334
+ { "GetFileSizeEx", (SYSCALL)GetFileSizeEx, 0 },
49335
+#define osGetFileSizeEx ((BOOL(WINAPI*)(HANDLE, \
49336
+ PLARGE_INTEGER))aSyscall[12].pCurrent)
4923449337
4923549338
{ "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
4923649339
#define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
49237
- LPWSTR*))aSyscall[12].pCurrent)
49340
+ LPWSTR*))aSyscall[13].pCurrent)
4923849341
4923949342
{ "GetLastError", (SYSCALL)GetLastError, 0 },
49240
-#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[13].pCurrent)
49343
+#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[14].pCurrent)
4924149344
49242
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49345
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP)
4924349346
{ "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
4924449347
#else
4924549348
{ "GetProcAddressA", (SYSCALL)0, 0 },
4924649349
#endif
4924749350
#define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
49248
- LPCSTR))aSyscall[14].pCurrent)
49351
+ LPCSTR))aSyscall[15].pCurrent)
4924949352
4925049353
{ "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
49251
-#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[15].pCurrent)
49252
-
49253
- { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
49254
-#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[16].pCurrent)
49354
+#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[16].pCurrent)
4925549355
4925649356
{ "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
4925749357
#define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
4925849358
LPFILETIME))aSyscall[17].pCurrent)
4925949359
49360
+#ifdef SQLITE_UWP
49361
+ { "GetTempPathW", (SYSCALL)0, 0 },
49362
+#else
4926049363
{ "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
49364
+#endif
4926149365
#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent)
4926249366
49263
- { "GetTickCount", (SYSCALL)GetTickCount, 0 },
49264
-#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[19].pCurrent)
49367
+ { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
49368
+#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[19].pCurrent)
4926549369
49370
+#ifdef SQLITE_UWP
49371
+ { "HeapAlloc", (SYSCALL)0, 0 },
49372
+#else
4926649373
{ "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
49374
+#endif
4926749375
#define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
4926849376
SIZE_T))aSyscall[20].pCurrent)
4926949377
49378
+#ifdef SQLITE_UWP
49379
+ { "HeapCreate", (SYSCALL)0, 0 },
49380
+#else
4927049381
{ "HeapCreate", (SYSCALL)HeapCreate, 0 },
49382
+#endif
4927149383
#define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
4927249384
SIZE_T))aSyscall[21].pCurrent)
4927349385
49386
+#ifdef SQLITE_UWP
49387
+ { "HeapDestroy", (SYSCALL)0, 0 },
49388
+#else
4927449389
{ "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
49390
+#endif
4927549391
#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent)
4927649392
49393
+#ifdef SQLITE_UWP
49394
+ { "HeapFree", (SYSCALL)0, 0 },
49395
+#else
4927749396
{ "HeapFree", (SYSCALL)HeapFree, 0 },
49397
+#endif
4927849398
#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent)
4927949399
49400
+#ifdef SQLITE_UWP
49401
+ { "HeapReAlloc", (SYSCALL)0, 0 },
49402
+#else
4928049403
{ "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
49404
+#endif
4928149405
#define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
4928249406
SIZE_T))aSyscall[24].pCurrent)
4928349407
49408
+#ifdef SQLITE_UWP
49409
+ { "HeapSize", (SYSCALL)0, 0 },
49410
+#else
4928449411
{ "HeapSize", (SYSCALL)HeapSize, 0 },
49412
+#endif
4928549413
#define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
4928649414
LPCVOID))aSyscall[25].pCurrent)
4928749415
49416
+#ifdef SQLITE_UWP
49417
+ { "HeapValidate", (SYSCALL)0, 0 },
49418
+#else
4928849419
{ "HeapValidate", (SYSCALL)HeapValidate, 0 },
49420
+#endif
4928949421
#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
4929049422
LPCVOID))aSyscall[26].pCurrent)
4929149423
49424
+#ifdef SQLITE_UWP
49425
+ { "HeapCompact", (SYSCALL)0, 0 },
49426
+#else
4929249427
{ "HeapCompact", (SYSCALL)HeapCompact, 0 },
49428
+#endif
4929349429
#define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent)
4929449430
4929549431
49296
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49432
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP)
4929749433
{ "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
4929849434
#else
4929949435
{ "LoadLibraryW", (SYSCALL)0, 0 },
4930049436
#endif
4930149437
#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent)
@@ -49305,72 +49441,82 @@
4930549441
4930649442
{ "LockFileEx", (SYSCALL)LockFileEx, 0 },
4930749443
#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
4930849444
LPOVERLAPPED))aSyscall[30].pCurrent)
4930949445
49310
-#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49446
+#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
49447
+ && !defined(SQLITE_UWP)
4931149448
{ "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
4931249449
#else
4931349450
{ "MapViewOfFile", (SYSCALL)0, 0 },
4931449451
#endif
4931549452
#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
4931649453
SIZE_T))aSyscall[31].pCurrent)
49454
+
49455
+#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
49456
+ && defined(SQLITE_UWP)
49457
+ { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
49458
+#else
49459
+ { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
49460
+#endif
49461
+#define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
49462
+ SIZE_T))aSyscall[32].pCurrent)
4931749463
4931849464
{ "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
4931949465
#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
49320
- int))aSyscall[32].pCurrent)
49466
+ int))aSyscall[33].pCurrent)
4932149467
4932249468
{ "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
4932349469
#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
49324
- LARGE_INTEGER*))aSyscall[33].pCurrent)
49470
+ LARGE_INTEGER*))aSyscall[34].pCurrent)
4932549471
4932649472
{ "ReadFile", (SYSCALL)ReadFile, 0 },
4932749473
#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
49328
- LPOVERLAPPED))aSyscall[34].pCurrent)
49474
+ LPOVERLAPPED))aSyscall[35].pCurrent)
4932949475
4933049476
{ "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
49331
-#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[35].pCurrent)
49477
+#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent)
4933249478
49333
- { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
49334
-#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
49335
- DWORD))aSyscall[36].pCurrent)
49479
+ { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
49480
+#define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER,\
49481
+ PLARGE_INTEGER,DWORD))aSyscall[37].pCurrent)
4933649482
4933749483
{ "Sleep", (SYSCALL)Sleep, 0 },
49338
-#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[37].pCurrent)
49484
+#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[38].pCurrent)
4933949485
4934049486
{ "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
4934149487
#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49342
- LPOVERLAPPED))aSyscall[38].pCurrent)
49488
+ LPOVERLAPPED))aSyscall[39].pCurrent)
4934349489
4934449490
#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
4934549491
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
4934649492
#else
4934749493
{ "UnmapViewOfFile", (SYSCALL)0, 0 },
4934849494
#endif
49349
-#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[39].pCurrent)
49495
+#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[40].pCurrent)
4935049496
4935149497
{ "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
4935249498
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
49353
- LPCSTR,LPBOOL))aSyscall[40].pCurrent)
49499
+ LPCSTR,LPBOOL))aSyscall[41].pCurrent)
4935449500
4935549501
{ "WriteFile", (SYSCALL)WriteFile, 0 },
4935649502
#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
49357
- LPOVERLAPPED))aSyscall[41].pCurrent)
49503
+ LPOVERLAPPED))aSyscall[42].pCurrent)
4935849504
4935949505
{ "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
4936049506
#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
49361
- DWORD))aSyscall[42].pCurrent)
49507
+ DWORD))aSyscall[43].pCurrent)
4936249508
4936349509
{ "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
4936449510
#define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
49365
- BOOL))aSyscall[43].pCurrent)
49511
+ BOOL))aSyscall[44].pCurrent)
4936649512
4936749513
{ "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
49368
-#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[44].pCurrent)
49514
+#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[45].pCurrent)
4936949515
4937049516
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
49371
-#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[45].pCurrent)
49517
+#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[46].pCurrent)
4937249518
4937349519
/*
4937449520
** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
4937549521
** is really just a macro that uses a compiler intrinsic (e.g. x64).
4937649522
** So do not try to make this is into a redefinable interface.
@@ -49379,95 +49525,93 @@
4937949525
{ "InterlockedCompareExchange", (SYSCALL)0, 0 },
4938049526
#define osInterlockedCompareExchange InterlockedCompareExchange
4938149527
#else
4938249528
{ "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
4938349529
#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\
49384
- LONG,LONG))aSyscall[46].pCurrent)
49530
+ LONG,LONG))aSyscall[47].pCurrent)
4938549531
#endif /* defined(InterlockedCompareExchange) */
4938649532
4938749533
#if SQLITE_WIN32_USE_UUID
4938849534
{ "UuidCreate", (SYSCALL)UuidCreate, 0 },
4938949535
#else
4939049536
{ "UuidCreate", (SYSCALL)0, 0 },
4939149537
#endif
49392
-#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[47].pCurrent)
49538
+#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent)
4939349539
4939449540
#if SQLITE_WIN32_USE_UUID
4939549541
{ "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
4939649542
#else
4939749543
{ "UuidCreateSequential", (SYSCALL)0, 0 },
4939849544
#endif
4939949545
#define osUuidCreateSequential \
49400
- ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent)
49546
+ ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[49].pCurrent)
4940149547
4940249548
#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
4940349549
{ "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
4940449550
#else
4940549551
{ "FlushViewOfFile", (SYSCALL)0, 0 },
4940649552
#endif
4940749553
#define osFlushViewOfFile \
49408
- ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[49].pCurrent)
49554
+ ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[50].pCurrent)
4940949555
4941049556
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
4941149557
{ "CreateEvent", (SYSCALL)CreateEvent, 0 },
4941249558
#else
4941349559
{ "CreateEvent", (SYSCALL)0, 0 },
4941449560
#endif
49415
-#define osCreateEvent ( \
49416
- (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
49417
- aSyscall[50].pCurrent \
49418
-)
49561
+#define osCreateEvent ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
49562
+ BOOL,LPCSTR))aSyscall[51].pCurrent)
4941949563
4942049564
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
4942149565
{ "CancelIo", (SYSCALL)CancelIo, 0 },
4942249566
#else
4942349567
{ "CancelIo", (SYSCALL)0, 0 },
4942449568
#endif
49425
-#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
49569
+#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent)
4942649570
4942749571
#ifndef _WIN32
4942849572
{ "getenv", (SYSCALL)getenv, 0 },
4942949573
#else
4943049574
{ "getenv", (SYSCALL)0, 0 },
4943149575
#endif
49432
-#define osGetenv ((const char *(*)(const char *))aSyscall[52].pCurrent)
49576
+#define osGetenv ((const char *(*)(const char *))aSyscall[53].pCurrent)
4943349577
4943449578
#ifndef _WIN32
4943549579
{ "getcwd", (SYSCALL)getcwd, 0 },
4943649580
#else
4943749581
{ "getcwd", (SYSCALL)0, 0 },
4943849582
#endif
49439
-#define osGetcwd ((char*(*)(char*,size_t))aSyscall[53].pCurrent)
49583
+#define osGetcwd ((char*(*)(char*,size_t))aSyscall[54].pCurrent)
4944049584
4944149585
#ifndef _WIN32
4944249586
{ "readlink", (SYSCALL)readlink, 0 },
4944349587
#else
4944449588
{ "readlink", (SYSCALL)0, 0 },
4944549589
#endif
49446
-#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[54].pCurrent)
49590
+#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[55].pCurrent)
4944749591
4944849592
#ifndef _WIN32
4944949593
{ "lstat", (SYSCALL)lstat, 0 },
4945049594
#else
4945149595
{ "lstat", (SYSCALL)0, 0 },
4945249596
#endif
49453
-#define osLstat ((int(*)(const char*,struct stat*))aSyscall[55].pCurrent)
49597
+#define osLstat ((int(*)(const char*,struct stat*))aSyscall[56].pCurrent)
4945449598
4945549599
#ifndef _WIN32
4945649600
{ "__errno", (SYSCALL)__errno, 0 },
4945749601
#else
4945849602
{ "__errno", (SYSCALL)0, 0 },
4945949603
#endif
49460
-#define osErrno (*((int*(*)(void))aSyscall[56].pCurrent)())
49604
+#define osErrno (*((int*(*)(void))aSyscall[57].pCurrent)())
4946149605
4946249606
#ifndef _WIN32
4946349607
{ "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
4946449608
#else
4946549609
{ "cygwin_conv_path", (SYSCALL)0, 0 },
4946649610
#endif
4946749611
#define osCygwin_conv_path ((size_t(*)(unsigned int, \
49468
- const void *, void *, size_t))aSyscall[57].pCurrent)
49612
+ const void *, void *, size_t))aSyscall[58].pCurrent)
4946949613
4947049614
}; /* End of the overrideable system calls */
4947149615
4947249616
/*
4947349617
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -49551,10 +49695,13 @@
4955149695
}
4955249696
return 0;
4955349697
}
4955449698
4955549699
#ifdef SQLITE_WIN32_MALLOC
49700
+#ifdef SQLITE_UWP
49701
+# error SQLITE_WIN32_MALLOC is incompatible with SQLITE_UWP
49702
+#endif
4955649703
/*
4955749704
** If a Win32 native heap has been configured, this function will attempt to
4955849705
** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one
4955949706
** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The
4956049707
** "pnLargest" argument, if non-zero, will be used to return the size of the
@@ -50509,31 +50656,15 @@
5050950656
** If successful, return SQLITE_OK. Or, if an error occurs, return an SQLite
5051050657
** error code.
5051150658
*/
5051250659
static int winHandleSeek(HANDLE h, sqlite3_int64 iOffset){
5051350660
int rc = SQLITE_OK; /* Return value */
50514
-
50515
- LONG upperBits; /* Most sig. 32 bits of new offset */
50516
- LONG lowerBits; /* Least sig. 32 bits of new offset */
50517
- DWORD dwRet; /* Value returned by SetFilePointer() */
50518
-
50519
- upperBits = (LONG)((iOffset>>32) & 0x7fffffff);
50520
- lowerBits = (LONG)(iOffset & 0xffffffff);
50521
-
50522
- dwRet = osSetFilePointer(h, lowerBits, &upperBits, FILE_BEGIN);
50523
-
50524
- /* API oddity: If successful, SetFilePointer() returns a dword
50525
- ** containing the lower 32-bits of the new file-offset. Or, if it fails,
50526
- ** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
50527
- ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
50528
- ** whether an error has actually occurred, it is also necessary to call
50529
- ** GetLastError(). */
50530
- if( dwRet==INVALID_SET_FILE_POINTER ){
50531
- DWORD lastErrno = osGetLastError();
50532
- if( lastErrno!=NO_ERROR ){
50533
- rc = SQLITE_IOERR_SEEK;
50534
- }
50661
+ LARGE_INTEGER x; /* The offset */
50662
+
50663
+ x.QuadPart = iOffset;
50664
+ if( osSetFilePointerEx(h, x, 0, FILE_BEGIN)==0 ){
50665
+ rc = SQLITE_IOERR_SEEK;
5053550666
}
5053650667
OSTRACE(("SEEK file=%p, offset=%lld rc=%s\n", h, iOffset,sqlite3ErrName(rc)));
5053750668
return rc;
5053850669
}
5053950670
@@ -50812,18 +50943,17 @@
5081250943
** Determine the size in bytes of the file opened by the handle passed as
5081350944
** the first argument.
5081450945
*/
5081550946
static int winHandleSize(HANDLE h, sqlite3_int64 *pnByte){
5081650947
int rc = SQLITE_OK;
50817
- DWORD upperBits = 0;
50818
- DWORD lowerBits = 0;
50819
-
50948
+ LARGE_INTEGER x;
5082050949
assert( pnByte );
50821
- lowerBits = osGetFileSize(h, &upperBits);
50822
- *pnByte = (((sqlite3_int64)upperBits)<<32) + lowerBits;
50823
- if( lowerBits==INVALID_FILE_SIZE && osGetLastError()!=NO_ERROR ){
50950
+ if( osGetFileSizeEx(h, &x)==0 ){
5082450951
rc = SQLITE_IOERR_FSTAT;
50952
+ *pnByte = 0;
50953
+ }else{
50954
+ *pnByte = x.QuadPart;
5082550955
}
5082650956
return rc;
5082750957
}
5082850958
5082950959
/*
@@ -51020,21 +51150,18 @@
5102051150
assert( id!=0 );
5102151151
assert( pSize!=0 );
5102251152
SimulateIOError(return SQLITE_IOERR_FSTAT);
5102351153
OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize));
5102451154
{
51025
- DWORD upperBits;
51026
- DWORD lowerBits;
51027
- DWORD lastErrno;
51028
-
51029
- lowerBits = osGetFileSize(pFile->h, &upperBits);
51030
- *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
51031
- if( (lowerBits == INVALID_FILE_SIZE)
51032
- && ((lastErrno = osGetLastError())!=NO_ERROR) ){
51033
- pFile->lastErrno = lastErrno;
51155
+ LARGE_INTEGER x;
51156
+ if( osGetFileSizeEx(pFile->h, &x)==0 ){
51157
+ *pSize = 0;
51158
+ pFile->lastErrno = osGetLastError();
5103451159
rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
5103551160
"winFileSize", pFile->zPath);
51161
+ }else{
51162
+ *pSize = x.QuadPart;
5103651163
}
5103751164
}
5103851165
OSTRACE(("SIZE file=%p, pSize=%p, *pSize=%lld, rc=%s\n",
5103951166
pFile->h, pSize, *pSize, sqlite3ErrName(rc)));
5104051167
return rc;
@@ -52373,11 +52500,11 @@
5237352500
5237452501
assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
5237552502
if( pShmNode->nRegion<=iRegion ){
5237652503
HANDLE hShared = pShmNode->hSharedShm;
5237752504
struct ShmRegion *apNew; /* New aRegion[] array */
52378
- int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
52505
+ i64 nByte = ((i64)iRegion+1)*(i64)szRegion; /* Minimum file size */
5237952506
sqlite3_int64 sz; /* Current size of wal-index file */
5238052507
5238152508
pShmNode->szRegion = szRegion;
5238252509
5238352510
/* The requested region is not mapped into this processes address space.
@@ -52404,11 +52531,11 @@
5240452531
}
5240552532
}
5240652533
5240752534
/* Map the requested memory region into this processes address space. */
5240852535
apNew = (struct ShmRegion*)sqlite3_realloc64(
52409
- pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
52536
+ pShmNode->aRegion, ((i64)iRegion+1)*sizeof(apNew[0])
5241052537
);
5241152538
if( !apNew ){
5241252539
rc = SQLITE_IOERR_NOMEM_BKPT;
5241352540
goto shmpage_out;
5241452541
}
@@ -52421,20 +52548,30 @@
5242152548
5242252549
while( pShmNode->nRegion<=iRegion ){
5242352550
HANDLE hMap = NULL; /* file-mapping handle */
5242452551
void *pMap = 0; /* Mapped memory region */
5242552552
52553
+#ifdef SQLITE_UWP
52554
+ hMap = osCreateFileMappingFromApp(hShared, NULL, protect, nByte, NULL);
52555
+#else
5242652556
hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
52427
- OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
52557
+#endif
52558
+ OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%lld, rc=%s\n",
5242852559
osGetCurrentProcessId(), pShmNode->nRegion, nByte,
5242952560
hMap ? "ok" : "failed"));
5243052561
if( hMap ){
52431
- int iOffset = pShmNode->nRegion*szRegion;
52562
+ i64 iOffset = pShmNode->nRegion*szRegion;
5243252563
int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
52564
+#ifdef SQLITE_UWP
52565
+ pMap = osMapViewOfFileFromApp(hMap, flags,
52566
+ iOffset - iOffsetShift, (i64)szRegion + iOffsetShift
52567
+ );
52568
+#else
5243352569
pMap = osMapViewOfFile(hMap, flags,
52434
- 0, iOffset - iOffsetShift, szRegion + iOffsetShift
52570
+ 0, iOffset - iOffsetShift, (i64)szRegion + iOffsetShift
5243552571
);
52572
+#endif
5243652573
OSTRACE(("SHM-MAP-MAP pid=%lu, region=%d, offset=%d, size=%d, rc=%s\n",
5243752574
osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
5243852575
szRegion, pMap ? "ok" : "failed"));
5243952576
}
5244052577
if( !pMap ){
@@ -52451,11 +52588,11 @@
5245152588
}
5245252589
}
5245352590
5245452591
shmpage_out:
5245552592
if( pShmNode->nRegion>iRegion ){
52456
- int iOffset = iRegion*szRegion;
52593
+ i64 iOffset = (i64)iRegion*(i64)szRegion;
5245752594
int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
5245852595
char *p = (char *)pShmNode->aRegion[iRegion].pMap;
5245952596
*pp = (void *)&p[iOffsetShift];
5246052597
}else{
5246152598
*pp = 0;
@@ -52563,13 +52700,17 @@
5256352700
if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
5256452701
protect = PAGE_READWRITE;
5256552702
flags |= FILE_MAP_WRITE;
5256652703
}
5256752704
#endif
52705
+#ifdef SQLITE_UWP
52706
+ pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL);
52707
+#else
5256852708
pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect,
5256952709
(DWORD)((nMap>>32) & 0xffffffff),
5257052710
(DWORD)(nMap & 0xffffffff), NULL);
52711
+#endif
5257152712
if( pFd->hMap==NULL ){
5257252713
pFd->lastErrno = osGetLastError();
5257352714
rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
5257452715
"winMapfile1", pFd->zPath);
5257552716
/* Log the error, but continue normal operation using xRead/xWrite */
@@ -52577,11 +52718,15 @@
5257752718
osGetCurrentProcessId(), pFd, sqlite3ErrName(rc)));
5257852719
return SQLITE_OK;
5257952720
}
5258052721
assert( (nMap % winSysInfo.dwPageSize)==0 );
5258152722
assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
52723
+#ifdef SQLITE_UWP
52724
+ pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, (SIZE_T)nMap);
52725
+#else
5258252726
pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap);
52727
+#endif
5258352728
if( pNew==NULL ){
5258452729
osCloseHandle(pFd->hMap);
5258552730
pFd->hMap = NULL;
5258652731
pFd->lastErrno = osGetLastError();
5258752732
rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
@@ -52920,11 +53065,11 @@
5292053065
if( !zWidePath ){
5292153066
sqlite3_free(zBuf);
5292253067
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
5292353068
return SQLITE_IOERR_NOMEM_BKPT;
5292453069
}
52925
- if( osGetTempPathW(nMax, zWidePath)==0 ){
53070
+ if( osGetTempPathW==0 || osGetTempPathW(nMax, zWidePath)==0 ){
5292653071
sqlite3_free(zWidePath);
5292753072
sqlite3_free(zBuf);
5292853073
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
5292953074
return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
5293053075
"winGetTempname2", 0);
@@ -53723,37 +53868,37 @@
5372353868
/*
5372453869
** Interfaces for opening a shared library, finding entry points
5372553870
** within the shared library, and closing the shared library.
5372653871
*/
5372753872
static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
53728
- HANDLE h;
53873
+ HANDLE h = 0;
5372953874
void *zConverted = winConvertFromUtf8Filename(zFilename);
5373053875
UNUSED_PARAMETER(pVfs);
5373153876
if( zConverted==0 ){
5373253877
OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
5373353878
return 0;
5373453879
}
53735
- h = osLoadLibraryW((LPCWSTR)zConverted);
53880
+ h = osLoadLibraryW ? osLoadLibraryW((LPCWSTR)zConverted) : 0;
5373653881
OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
5373753882
sqlite3_free(zConverted);
5373853883
return (void*)h;
5373953884
}
5374053885
static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
5374153886
UNUSED_PARAMETER(pVfs);
5374253887
winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
5374353888
}
5374453889
static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
53745
- FARPROC proc;
53890
+ FARPROC proc = 0;
5374653891
UNUSED_PARAMETER(pVfs);
53747
- proc = osGetProcAddressA((HANDLE)pH, zSym);
53892
+ proc = osGetProcAddressA ? osGetProcAddressA((HANDLE)pH, zSym) : 0;
5374853893
OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n",
5374953894
(void*)pH, zSym, (void*)proc));
5375053895
return (void(*)(void))proc;
5375153896
}
5375253897
static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
5375353898
UNUSED_PARAMETER(pVfs);
53754
- osFreeLibrary((HANDLE)pHandle);
53899
+ if( osFreeLibrary!=0 ) osFreeLibrary((HANDLE)pHandle);
5375553900
OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle));
5375653901
}
5375753902
#else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
5375853903
#define winDlOpen 0
5375953904
#define winDlError 0
@@ -53798,36 +53943,39 @@
5379853943
e.a = (unsigned char*)zBuf;
5379953944
e.na = nBuf;
5380053945
e.nXor = 0;
5380153946
e.i = 0;
5380253947
{
53803
- SYSTEMTIME x;
53804
- osGetSystemTime(&x);
53805
- xorMemory(&e, (unsigned char*)&x, sizeof(SYSTEMTIME));
53948
+ FILETIME x;
53949
+ osGetSystemTimeAsFileTime(&x);
53950
+ xorMemory(&e, (unsigned char*)&x, sizeof(x));
5380653951
}
5380753952
{
5380853953
DWORD pid = osGetCurrentProcessId();
53809
- xorMemory(&e, (unsigned char*)&pid, sizeof(DWORD));
53954
+ xorMemory(&e, (unsigned char*)&pid, sizeof(pid));
5381053955
}
5381153956
{
53812
- DWORD cnt = osGetTickCount();
53813
- xorMemory(&e, (unsigned char*)&cnt, sizeof(DWORD));
53957
+ ULONGLONG cnt = osGetTickCount64();
53958
+ xorMemory(&e, (unsigned char*)&cnt, sizeof(cnt));
5381453959
}
5381553960
{
5381653961
LARGE_INTEGER i;
5381753962
osQueryPerformanceCounter(&i);
53818
- xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER));
53963
+ xorMemory(&e, (unsigned char*)&i, sizeof(i));
5381953964
}
5382053965
#if SQLITE_WIN32_USE_UUID
53966
+#ifdef SQLITE_UWP
53967
+# error SQLITE_WIN32_USE_UUID is incompatible with SQLITE_UWP
53968
+#endif
5382153969
{
5382253970
UUID id;
53823
- memset(&id, 0, sizeof(UUID));
53971
+ memset(&id, 0, sizeof(id));
5382453972
osUuidCreate(&id);
53825
- xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
53973
+ xorMemory(&e, (unsigned char*)&id, sizeof(id));
5382653974
memset(&id, 0, sizeof(UUID));
5382753975
osUuidCreateSequential(&id);
53828
- xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
53976
+ xorMemory(&e, (unsigned char*)&id, sizeof(id));
5382953977
}
5383053978
#endif /* SQLITE_WIN32_USE_UUID */
5383153979
return e.nXor>nBuf ? nBuf : e.nXor;
5383253980
#endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */
5383353981
}
@@ -54042,15 +54190,19 @@
5404254190
winNextSystemCall, /* xNextSystemCall */
5404354191
};
5404454192
5404554193
/* Double-check that the aSyscall[] array has been constructed
5404654194
** correctly. See ticket [bb3a86e890c8e96ab] */
54047
- assert( ArraySize(aSyscall)==58 );
54195
+ assert( ArraySize(aSyscall)==59 );
5404854196
assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
54049
- assert( strcmp(aSyscall[20].zName,"HeapAlloc")==0 );
54050
- assert( strcmp(aSyscall[40].zName,"WideCharToMultiByte")==0 );
54051
- assert( strcmp(aSyscall[57].zName,"cygwin_conv_path")==0 );
54197
+ assert( strcmp(aSyscall[8].zName,"FreeLibrary")==0 );
54198
+ assert( strcmp(aSyscall[16].zName,"GetSystemInfo")==0 );
54199
+ assert( strcmp(aSyscall[24].zName,"HeapReAlloc")==0 );
54200
+ assert( strcmp(aSyscall[32].zName,"MapViewOfFileFromApp")==0 );
54201
+ assert( strcmp(aSyscall[40].zName,"UnmapViewOfFile")==0 );
54202
+ assert( strcmp(aSyscall[48].zName,"UuidCreate")==0 );
54203
+ assert( strcmp(aSyscall[56].zName,"lstat")==0 );
5405254204
5405354205
/* get memory map allocation granularity */
5405454206
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
5405554207
osGetSystemInfo(&winSysInfo);
5405654208
assert( winSysInfo.dwAllocationGranularity>0 );
@@ -71953,10 +72105,20 @@
7195372105
** See the header comment on "btreeInt.h" for additional information.
7195472106
** Including a description of file format and an overview of operation.
7195572107
*/
7195672108
/* #include "btreeInt.h" */
7195772109
72110
+/*
72111
+** Suppress false-positive compiler warnings from GCC. Warnings are
72112
+** re-enabled at the bottom of this source file.
72113
+*/
72114
+#if defined(__GNUC__) && __GNUC__>=11
72115
+# pragma GCC diagnostic push
72116
+# pragma GCC diagnostic ignored "-Wstringop-overread"
72117
+# pragma GCC diagnostic ignored "-Wstringop-overflow"
72118
+#endif
72119
+
7195872120
/*
7195972121
** The header string that appears at the beginning of every
7196072122
** SQLite database.
7196172123
*/
7196272124
static const char zMagicHeader[] = SQLITE_FILE_HEADER;
@@ -77228,10 +77390,18 @@
7722877390
DbPage *pDbPage;
7722977391
rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage,
7723077392
(eOp==0 ? PAGER_GET_READONLY : 0)
7723177393
);
7723277394
if( rc==SQLITE_OK ){
77395
+ if( eOp!=0
77396
+ && (sqlite3PagerPageRefcount(pDbPage)!=1
77397
+ || NEVER(((MemPage*)sqlite3PagerGetExtra(pDbPage))->isInit))
77398
+ && sqlite3FaultSim(411)==SQLITE_OK
77399
+ ){
77400
+ sqlite3PagerUnref(pDbPage);
77401
+ return SQLITE_CORRUPT_PAGE(pPage);
77402
+ }
7723377403
aPayload = sqlite3PagerGetData(pDbPage);
7723477404
nextPage = get4byte(aPayload);
7723577405
rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
7723677406
sqlite3PagerUnref(pDbPage);
7723777407
offset = 0;
@@ -83504,10 +83674,17 @@
8350483674
SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree *p){
8350583675
testcase( p->sharable );
8350683676
return p->pBt->nRef;
8350783677
}
8350883678
#endif
83679
+
83680
+/* Re-enable GCC compiler warnings that were suppressed at the top
83681
+** of this source file to prevent annoying false-positives.
83682
+*/
83683
+#if defined(__GNUC__) && __GNUC__>=11
83684
+# pragma GCC diagnostic pop
83685
+#endif
8350983686
8351083687
/************** End of btree.c ***********************************************/
8351183688
/************** Begin file backup.c ******************************************/
8351283689
/*
8351383690
** 2009 January 28
@@ -87107,15 +87284,25 @@
8710787284
/*
8710887285
** Add an OP_ParseSchema opcode. This routine is broken out from
8710987286
** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees
8711087287
** as having been used.
8711187288
**
87112
-** The zWhere string must have been obtained from sqlite3_malloc().
87289
+** zWhere is a WHERE clause that defines which entries of the schema
87290
+** to reparse. If zWhere==0, that means all entries. p5 is a mask
87291
+** of INITFLAG_* values for the parse.
87292
+**
87293
+** In the current usage, the following are always true:
87294
+**
87295
+** ALTER TABLE: zWhere==0, p5!=0
87296
+** Otherwise: zWhere!=0, p5==0
87297
+**
87298
+** The zWhere string must have been obtained from sqlite3DbMalloc().
8711387299
** This routine will take ownership of the allocated memory.
8711487300
*/
8711587301
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere, u16 p5){
8711687302
int j;
87303
+ assert( p5==0 || zWhere==0 );
8711787304
sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
8711887305
sqlite3VdbeChangeP5(p, p5);
8711987306
for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
8712087307
sqlite3MayAbort(p->pParse);
8712187308
}
@@ -95713,14 +95900,16 @@
9571395900
*/
9571495901
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
9571595902
int eType = sqlite3_value_type(pVal);
9571695903
if( eType==SQLITE_TEXT ){
9571795904
Mem *pMem = (Mem*)pVal;
95718
- assert( pMem->db!=0 );
95719
- sqlite3_mutex_enter(pMem->db->mutex);
95905
+#if SQLITE_THREADSAFE>0
95906
+ sqlite3_mutex *pMutex = pMem->db ? pMem->db->mutex : 0;
95907
+#endif
95908
+ sqlite3_mutex_enter(pMutex);
9572095909
applyNumericAffinity(pMem, 0);
95721
- sqlite3_mutex_leave(pMem->db->mutex);
95910
+ sqlite3_mutex_leave(pMutex);
9572295911
eType = sqlite3_value_type(pVal);
9572395912
}
9572495913
return eType;
9572595914
}
9572695915
@@ -102423,15 +102612,22 @@
102423102612
goto abort_due_to_error;
102424102613
}
102425102614
break;
102426102615
}
102427102616
102428
-/* Opcode: ParseSchema P1 * * P4 *
102617
+/* Opcode: ParseSchema P1 * * P4 P5
102429102618
**
102430102619
** Read and parse all entries from the schema table of database P1
102431102620
** that match the WHERE clause P4. If P4 is a NULL pointer, then the
102432102621
** entire schema for P1 is reparsed.
102622
+**
102623
+** When P4 is NULL, the P5 value is used as the mFlags argument
102624
+** to sqlite3InitOne(). In other words, P5 should be a mask composed
102625
+** of INITFLAG_* values.
102626
+**
102627
+** The P4==0 case is only used by ALTER TABLE and P5!=0 for all such
102628
+** cases. For uses other than ALTER TABLE, P4<>0 and P5==0.
102433102629
**
102434102630
** This opcode invokes the parser to create a new virtual machine,
102435102631
** then runs the new virtual machine. It is thus a re-entrant opcode.
102436102632
*/
102437102633
case OP_ParseSchema: {
@@ -102456,18 +102652,20 @@
102456102652
|| db->mallocFailed
102457102653
|| (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) );
102458102654
102459102655
#ifndef SQLITE_OMIT_ALTERTABLE
102460102656
if( pOp->p4.z==0 ){
102657
+ assert( pOp->p5!=0 );
102461102658
sqlite3SchemaClear(db->aDb[iDb].pSchema);
102462102659
db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
102463102660
rc = sqlite3InitOne(db, iDb, &p->zErrMsg, pOp->p5);
102464102661
db->mDbFlags |= DBFLAG_SchemaChange;
102465102662
p->expired = 0;
102466102663
}else
102467102664
#endif
102468102665
{
102666
+ assert( pOp->p5==0 );
102469102667
zSchema = LEGACY_SCHEMA_TABLE;
102470102668
initData.db = db;
102471102669
initData.iDb = iDb;
102472102670
initData.pzErrMsg = &p->zErrMsg;
102473102671
initData.mInitFlags = 0;
@@ -109972,10 +110170,11 @@
109972110170
}
109973110171
extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
109974110172
pExpr->op = TK_FUNCTION;
109975110173
pExpr->u.zToken = "coalesce";
109976110174
pExpr->x.pList = pFJMatch;
110175
+ pExpr->affExpr = SQLITE_AFF_DEFER;
109977110176
cnt = 1;
109978110177
goto lookupname_end;
109979110178
}else{
109980110179
sqlite3ExprListDelete(db, pFJMatch);
109981110180
pFJMatch = 0;
@@ -110137,10 +110336,30 @@
110137110336
sqlite3AtoF(p->u.zToken, &r);
110138110337
assert( r>=0.0 );
110139110338
if( r>1.0 ) return -1;
110140110339
return (int)(r*134217728.0);
110141110340
}
110341
+
110342
+/*
110343
+** Set the EP_SubtArg property on every expression inside of
110344
+** pList. If any subexpression is actually a subquery, then
110345
+** also set the EP_SubtArg property on the first result-set
110346
+** column of that subquery.
110347
+*/
110348
+static SQLITE_NOINLINE void resolveSetExprSubtypeArg(ExprList *pList){
110349
+ int nn, ii;
110350
+ nn = pList ? pList->nExpr : 0;
110351
+ for(ii=0; ii<nn; ii++){
110352
+ Expr *pExpr = pList->a[ii].pExpr;
110353
+ ExprSetProperty(pExpr, EP_SubtArg);
110354
+ if( pExpr->op==TK_SELECT ){
110355
+ assert( ExprUseXSelect(pExpr) );
110356
+ assert( pExpr->x.pSelect!=0 );
110357
+ resolveSetExprSubtypeArg(pExpr->x.pSelect->pEList);
110358
+ }
110359
+ }
110360
+}
110142110361
110143110362
/*
110144110363
** This routine is callback for sqlite3WalkExpr().
110145110364
**
110146110365
** Resolve symbolic names into TK_COLUMN operators for the current
@@ -110382,14 +110601,11 @@
110382110601
** the function may return a value with a subtype back to its
110383110602
** caller using sqlite3_result_value(). */
110384110603
if( (pDef->funcFlags & SQLITE_SUBTYPE)
110385110604
|| ExprHasProperty(pExpr, EP_SubtArg)
110386110605
){
110387
- int ii;
110388
- for(ii=0; ii<n; ii++){
110389
- ExprSetProperty(pList->a[ii].pExpr, EP_SubtArg);
110390
- }
110606
+ resolveSetExprSubtypeArg(pList);
110391110607
}
110392110608
110393110609
if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
110394110610
/* For the purposes of the EP_ConstFunc flag, date and time
110395110611
** functions and other functions that change slowly are considered
@@ -110415,12 +110631,17 @@
110415110631
&& (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
110416110632
){
110417110633
/* Internal-use-only functions are disallowed unless the
110418110634
** SQL is being compiled using sqlite3NestedParse() or
110419110635
** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
110420
- ** used to activate internal functions for testing purposes */
110421
- no_such_func = 1;
110636
+ ** used to activate internal functions for testing purposes.
110637
+ **
110638
+ ** The 2 value for no_such_func means that the function is
110639
+ ** an internal-use-only function which should be treated as a
110640
+ ** non-existant function for name resolution purposes.
110641
+ */
110642
+ no_such_func = 2;
110422110643
pDef = 0;
110423110644
}else
110424110645
if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
110425110646
&& !IN_RENAME_OBJECT
110426110647
){
@@ -110460,13 +110681,20 @@
110460110681
sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr);
110461110682
pNC->nNcErr++;
110462110683
is_agg = 0;
110463110684
}
110464110685
#endif
110465
- else if( no_such_func && pParse->db->init.busy==0
110686
+ else if( no_such_func
110687
+ && (pParse->db->init.busy==0 ||
110688
+ (no_such_func==2 && pParse->db->init.busy==2))
110689
+ /* Suppress "no such function" errors when reading
110690
+ ** the sqlite_schema table. Except, do raise the error
110691
+ ** if init.busy is 2, meaning the schema parse is due
110692
+ ** to an ALTER TABLE ADD COLUMN statement, and the function
110693
+ ** is an internal-use-only function (no_such_func==2). */
110466110694
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
110467
- && pParse->explain==0
110695
+ && pParse->explain==0
110468110696
#endif
110469110697
){
110470110698
sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr);
110471110699
pNC->nNcErr++;
110472110700
}else if( wrong_num_args ){
@@ -111849,11 +112077,13 @@
111849112077
** Return TRUE if the two expressions have equivalent collating sequences.
111850112078
*/
111851112079
SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse *pParse, const Expr *pE1, const Expr *pE2){
111852112080
CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pE1);
111853112081
CollSeq *pColl2 = sqlite3ExprNNCollSeq(pParse, pE2);
111854
- return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0;
112082
+ assert( (pColl1==pColl2) ==
112083
+ (sqlite3_stricmp(pColl1->zName,pColl2->zName)==0) );
112084
+ return pColl1==pColl2;
111855112085
}
111856112086
111857112087
/*
111858112088
** pExpr is an operand of a comparison operator. aff2 is the
111859112089
** type affinity of the other operand. This routine returns the
@@ -116203,40 +116433,51 @@
116203116433
}
116204116434
return target;
116205116435
}
116206116436
116207116437
/*
116208
-** Expression Node callback for sqlite3ExprCanReturnSubtype().
116209
-**
116210
-** Only a function call is able to return a subtype. So if the node
116211
-** is not a function call, return WRC_Prune immediately.
116212
-**
116213
-** A function call is able to return a subtype if it has the
116214
-** SQLITE_RESULT_SUBTYPE property.
116215
-**
116216
-** Assume that every function is able to pass-through a subtype from
116217
-** one of its argument (using sqlite3_result_value()). Most functions
116218
-** are not this way, but we don't have a mechanism to distinguish those
116219
-** that are from those that are not, so assume they all work this way.
116220
-** That means that if one of its arguments is another function and that
116221
-** other function is able to return a subtype, then this function is
116222
-** able to return a subtype.
116438
+** Expression Node callback for sqlite3ExprCanReturnSubtype(). If
116439
+** pExpr is able to return a subtype, set pWalker->eCode and abort
116440
+** the search. If pExpr can never return a subtype, prune search.
116441
+**
116442
+** The only expressions that can return a subtype are:
116443
+**
116444
+** 1. A function
116445
+** 2. The no-op "+" operator
116446
+** 3. A CASE...END expression
116447
+** 4. A CAST() expression
116448
+** 5. A "expr COLLATE colseq" expression.
116449
+**
116450
+** For any other kind of expression, prune the search.
116451
+**
116452
+** For case 1, the expression can yield a subtype if the function has
116453
+** the SQLITE_RESULT_SUBTYPE property. Functions can also return
116454
+** a subtype (via sqlite3_result_value()) if any of the arguments can
116455
+** return a subtype.
116456
+**
116457
+** In all cases 1 through 5, the expression might also return a subtype
116458
+** if any operand can return a subtype.
116223116459
*/
116224116460
static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
116225116461
int n;
116226116462
FuncDef *pDef;
116227116463
sqlite3 *db;
116464
+ if( pExpr->op==TK_CASE || pExpr->op==TK_UPLUS
116465
+ || pExpr->op==TK_COLLATE || pExpr->op==TK_CAST
116466
+ ){
116467
+ return WRC_Continue;
116468
+ }
116228116469
if( pExpr->op!=TK_FUNCTION ){
116229116470
return WRC_Prune;
116230116471
}
116231116472
assert( ExprUseXList(pExpr) );
116232116473
db = pWalker->pParse->db;
116233116474
n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
116234116475
pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
116235116476
if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
116236116477
pWalker->eCode = 1;
116237
- return WRC_Prune;
116478
+ return WRC_Abort;
116238116479
}
116239116480
return WRC_Continue;
116240116481
}
116241116482
116242116483
/*
@@ -122210,23 +122451,35 @@
122210122451
SQLITE_PRIVATE void sqlite3AlterAddConstraint(
122211122452
Parse *pParse, /* Parse context */
122212122453
SrcList *pSrc, /* Table to add constraint to */
122213122454
Token *pFirst, /* First token of new constraint */
122214122455
Token *pName, /* Name of new constraint. NULL if name omitted. */
122215
- const char *pExpr, /* Text of CHECK expression */
122216
- int nExpr /* Size of pExpr in bytes */
122456
+ const char *zExpr, /* Text of CHECK expression */
122457
+ int nExpr, /* Size of pExpr in bytes */
122458
+ Expr *pExpr /* The parsed CHECK expression */
122217122459
){
122218122460
Table *pTab = 0; /* Table identified by pSrc */
122219122461
int iDb = 0; /* Which schema does pTab live in */
122220122462
const char *zDb = 0; /* Name of the schema in which pTab lives */
122221122463
const char *pCons = 0; /* Text of the constraint */
122222122464
int nCons; /* Bytes of text to use from pCons[] */
122465
+ int rc; /* Result from error checking pExpr */
122223122466
122224122467
/* Look up the table being altered. */
122225122468
assert( pSrc->nSrc==1 );
122226122469
pTab = alterFindTable(pParse, pSrc, &iDb, &zDb, 1);
122227
- if( !pTab ) return;
122470
+ if( !pTab ){
122471
+ sqlite3ExprDelete(pParse->db, pExpr);
122472
+ return;
122473
+ }
122474
+
122475
+ /* Verify that the new CHECK constraint does not contain any
122476
+ ** internal-use-only function. Forum post 2026-05-10T01:11:28Z
122477
+ */
122478
+ rc = sqlite3ResolveSelfReference(pParse, pTab, NC_IsCheck, pExpr, 0);
122479
+ sqlite3ExprDelete(pParse->db, pExpr);
122480
+ if( rc ) return;
122228122481
122229122482
/* If this new constraint has a name, check that it is not a duplicate of
122230122483
** an existing constraint. It is an error if it is. */
122231122484
if( pName ){
122232122485
char *zName = sqlite3NameFromToken(pParse->db, pName);
@@ -122243,11 +122496,11 @@
122243122496
122244122497
/* Search for a constraint violation. Throw an exception if one is found. */
122245122498
sqlite3NestedParse(pParse,
122246122499
"SELECT sqlite_fail('constraint failed', %d) "
122247122500
"FROM %Q.%Q WHERE (%.*s) IS NOT TRUE",
122248
- SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, pExpr
122501
+ SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, zExpr
122249122502
);
122250122503
122251122504
/* Edit the SQL for the named table. */
122252122505
pCons = pFirst->z;
122253122506
nCons = alterRtrimConstraint(pParse->db, pCons, pParse->sLastToken.z - pCons);
@@ -125929,10 +126182,23 @@
125929126182
if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
125930126183
if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
125931126184
return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
125932126185
}
125933126186
126187
+/*
126188
+** Suppress false-positive warning message generated with -O3 in GCC
126189
+** on the second call to sqlite3Strlen30() in the sqlite3ColumnSetColl()
126190
+** function below. See the forum thread beginning on 2026-05-10T01:11:22Z.
126191
+**
126192
+** See also the "pop" pragma to undo this warning suppression immediately
126193
+** after the function.
126194
+*/
126195
+#if defined(__GNUC__) && __GNUC__>=11
126196
+# pragma GCC diagnostic push
126197
+# pragma GCC diagnostic ignored "-Wstringop-overread"
126198
+#endif
126199
+
125934126200
/*
125935126201
** Set the collating sequence name for a column.
125936126202
*/
125937126203
SQLITE_PRIVATE void sqlite3ColumnSetColl(
125938126204
sqlite3 *db,
@@ -125953,10 +126219,15 @@
125953126219
pCol->zCnName = zNew;
125954126220
memcpy(pCol->zCnName + n, zColl, nColl);
125955126221
pCol->colFlags |= COLFLAG_HASCOLL;
125956126222
}
125957126223
}
126224
+
126225
+/* Undo the false-positive warning suppression above. */
126226
+#if defined(__GNUC__) && __GNUC__>=11
126227
+# pragma GCC diagnostic pop
126228
+#endif
125958126229
125959126230
/*
125960126231
** Return the collating sequence name for a column
125961126232
*/
125962126233
SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){
@@ -134599,15 +134870,20 @@
134599134870
** to initialize it */
134600134871
if( ALWAYS(p) && type!=SQLITE_NULL ){
134601134872
assert( p->cnt>0 );
134602134873
p->cnt--;
134603134874
if( !p->approx ){
134604
- if( sqlite3SubInt64(&p->iSum, sqlite3_value_int64(argv[0])) ){
134605
- p->ovrfl = 1;
134606
- p->approx = 1;
134875
+ i64 x = p->iSum;
134876
+ if( sqlite3SubInt64(&x, sqlite3_value_int64(argv[0]))==0 ){
134877
+ p->iSum = x;
134878
+ return;
134607134879
}
134608
- }else if( type==SQLITE_INTEGER ){
134880
+ p->ovrfl = 1;
134881
+ p->approx = 1;
134882
+ kahanBabuskaNeumaierInit(p, p->iSum);
134883
+ }
134884
+ if( type==SQLITE_INTEGER ){
134609134885
i64 iVal = sqlite3_value_int64(argv[0]);
134610134886
if( iVal!=SMALLEST_INT64 ){
134611134887
kahanBabuskaNeumaierStepInt64(p, -iVal);
134612134888
}else{
134613134889
kahanBabuskaNeumaierStepInt64(p, LARGEST_INT64);
@@ -140569,10 +140845,48 @@
140569140845
}
140570140846
140571140847
/* If no test above fails then the indices must be compatible */
140572140848
return 1;
140573140849
}
140850
+
140851
+/*
140852
+** Examine an expression node and abort if it references the ROWID.
140853
+** This is a Walker callback used by xferCompatibleCheck()
140854
+*/
140855
+static int xferCheckRowid(Walker *pWalk, Expr *pExpr){
140856
+ if( pExpr->op==TK_COLUMN && pExpr->iColumn<0 ){
140857
+ pWalk->eCode = 1;
140858
+ return WRC_Abort;
140859
+ }else{
140860
+ return WRC_Continue;
140861
+ }
140862
+}
140863
+
140864
+/*
140865
+** Analyze CHECK constraints on the source and destination tables and
140866
+** return true if those CHECK constraints are compatible with the
140867
+** xfer-optimization.
140868
+**
140869
+** * The pDest and pSrc tables must have identical CHECK constraints.
140870
+**
140871
+** * If the destination table, pDest, does not have an
140872
+** INTEGER PRIMARY KEY column, then no CHECK constraint may
140873
+** referenced the ROWID. (See forum post 2026-05-11T13:15:57Z)
140874
+*/
140875
+static int xferCompatibleCheck(Table *pDest, Table *pSrc){
140876
+ if( sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
140877
+ return 0;
140878
+ }
140879
+ if( pDest->iPKey<0 ){
140880
+ Walker w;
140881
+ memset(&w, 0, sizeof(w));
140882
+ w.xExprCallback = xferCheckRowid;
140883
+ sqlite3WalkExprList(&w,pDest->pCheck);
140884
+ if( w.eCode ) return 0;
140885
+ }
140886
+ return 1;
140887
+}
140574140888
140575140889
/*
140576140890
** Attempt the transfer optimization on INSERTs of the form
140577140891
**
140578140892
** INSERT INTO tab1 SELECT * FROM tab2;
@@ -140696,12 +141010,23 @@
140696141010
return 0; /* Number of columns must be the same in tab1 and tab2 */
140697141011
}
140698141012
if( pDest->iPKey!=pSrc->iPKey ){
140699141013
return 0; /* Both tables must have the same INTEGER PRIMARY KEY */
140700141014
}
140701
- if( (pDest->tabFlags & TF_Strict)!=0 && (pSrc->tabFlags & TF_Strict)==0 ){
140702
- return 0; /* Cannot feed from a non-strict into a strict table */
141015
+ if( (pDest->tabFlags & TF_Strict)!=0 ){
141016
+ if( (pSrc->tabFlags & TF_Strict)==0 ){
141017
+ return 0; /* Cannot feed from a non-strict into a strict table */
141018
+ }
141019
+ for(i=0; i<pDest->nCol; i++){
141020
+ unsigned eDestType = pDest->aCol[i].eCType;
141021
+ unsigned eSrcType = pSrc->aCol[i].eCType;
141022
+ if( eDestType==COLTYPE_ANY ) continue;
141023
+ if( eDestType==eSrcType ) continue;
141024
+ if( eDestType==COLTYPE_INT && eSrcType==COLTYPE_INTEGER ) continue;
141025
+ if( eDestType==COLTYPE_INTEGER && eSrcType==COLTYPE_INT ) continue;
141026
+ return 0; /* Incompatible types in source and destination */
141027
+ }
140703141028
}
140704141029
for(i=0; i<pDest->nCol; i++){
140705141030
Column *pDestCol = &pDest->aCol[i];
140706141031
Column *pSrcCol = &pSrc->aCol[i];
140707141032
#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
@@ -140791,11 +141116,11 @@
140791141116
}
140792141117
}
140793141118
#ifndef SQLITE_OMIT_CHECK
140794141119
if( pDest->pCheck
140795141120
&& (db->mDbFlags & DBFLAG_Vacuum)==0
140796
- && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1)
141121
+ && !xferCompatibleCheck(pDest,pSrc)
140797141122
){
140798141123
return 0; /* Tables have different CHECK constraints. Ticket #2252 */
140799141124
}
140800141125
#endif
140801141126
#ifndef SQLITE_OMIT_FOREIGN_KEY
@@ -140812,10 +141137,22 @@
140812141137
}
140813141138
#endif
140814141139
if( (db->flags & SQLITE_CountRows)!=0 ){
140815141140
return 0; /* xfer opt does not play well with PRAGMA count_changes */
140816141141
}
141142
+#ifndef SQLITE_OMIT_AUTHORIZATION
141143
+ if( db->xAuth ){
141144
+ int iDb = sqlite3SchemaToIndex(db, pSrc->pSchema);
141145
+ if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 0;
141146
+ for(i=0; i<pSrc->nCol; i++){
141147
+ Column *pSrcCol = &pSrc->aCol[i];
141148
+ if( sqlite3AuthReadCol(pParse, pSrc->zName, pSrcCol->zCnName, iDb) ){
141149
+ return 0;
141150
+ }
141151
+ }
141152
+ }
141153
+#endif
140817141154
140818141155
/* If we get this far, it means that the xfer optimization is at
140819141156
** least a possibility, though it might only work if the destination
140820141157
** table (tab1) is initially empty.
140821141158
*/
@@ -146810,11 +147147,17 @@
146810147147
assert( iDb>=0 && iDb<db->nDb );
146811147148
assert( db->aDb[iDb].pSchema );
146812147149
assert( sqlite3_mutex_held(db->mutex) );
146813147150
assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
146814147151
146815
- db->init.busy = 1;
147152
+ db->init.busy = 1 + ((mFlags & INITFLAG_AlterAdd)!=0);
147153
+ /* ^--- Any non-zero value for init.busy means that we are scanning
147154
+ ** the sqlite_schema table to build the internal schema representation,
147155
+ ** rather than running actual CREATE statements. init.busy==2 has the
147156
+ ** additional meaning that the scan is happening as part of
147157
+ ** ALTER TABLE ADD COLUMN, which is stricter in its enforcement of
147158
+ ** function name resolution. */
146816147159
146817147160
/* Construct the in-memory representation schema tables (sqlite_schema or
146818147161
** sqlite_temp_schema) by invoking the parser directly. The appropriate
146819147162
** table name will be inserted automatically by the parser so we can just
146820147163
** use the abbreviation "x" here. The parser will also automatically tag
@@ -164903,11 +165246,11 @@
164903165246
164904165247
/* Set up a new SrcList in pOrTab containing the table being scanned
164905165248
** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
164906165249
** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
164907165250
*/
164908
- if( pWInfo->nLevel>1 ){
165251
+ if( pWInfo->nLevel>1 || pTabItem->fg.fromExists ){
164909165252
int nNotReady; /* The number of notReady tables */
164910165253
SrcItem *origSrc; /* Original list of tables */
164911165254
nNotReady = pWInfo->nLevel - iLevel - 1;
164912165255
pOrTab = sqlite3DbMallocRawNN(db, SZ_SRCLIST(nNotReady+1));
164913165256
if( pOrTab==0 ) return notReady;
@@ -164916,10 +165259,17 @@
164916165259
memcpy(pOrTab->a, pTabItem, sizeof(*pTabItem));
164917165260
origSrc = pWInfo->pTabList->a;
164918165261
for(k=1; k<=nNotReady; k++){
164919165262
memcpy(&pOrTab->a[k], &origSrc[pLevel[k].iFrom], sizeof(pOrTab->a[k]));
164920165263
}
165264
+
165265
+ /* Clear the fromExists flag on the OR-optimized table entry so that
165266
+ ** the calls to sqlite3WhereEnd() do not code early-exits after the
165267
+ ** first row is visited. The early exit applies to this table's
165268
+ ** overall loop - including the multiple OR branches and any WHERE
165269
+ ** conditions not passed to the sub-loops - not to the sub-loops. */
165270
+ pOrTab->a[0].fg.fromExists = 0;
164921165271
}else{
164922165272
pOrTab = pWInfo->pTabList;
164923165273
}
164924165274
164925165275
/* Initialize the rowset register to contain NULL. An SQL NULL is
@@ -165159,11 +165509,11 @@
165159165509
** indent everything in between the this point and the final OP_Return.
165160165510
** See tag-20220407a in vdbe.c and shell.c */
165161165511
assert( pLevel->op==OP_Return );
165162165512
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
165163165513
165164
- if( pWInfo->nLevel>1 ){ sqlite3DbFreeNN(db, pOrTab); }
165514
+ if( pWInfo->pTabList!=pOrTab ){ sqlite3DbFreeNN(db, pOrTab); }
165165165515
if( !untestedTerms ) disableTerm(pLevel, pTerm);
165166165516
}else
165167165517
#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
165168165518
165169165519
{
@@ -166508,20 +166858,18 @@
166508166858
** 1. The SQLITE_Transitive optimization must be enabled
166509166859
** 2. Must be either an == or an IS operator
166510166860
** 3. Not originating in the ON clause of an OUTER JOIN
166511166861
** 4. The operator is not IS or else the query does not contain RIGHT JOIN
166512166862
** 5. The affinities of A and B must be compatible
166513
-** 6a. Both operands use the same collating sequence OR
166514
-** 6b. The overall collating sequence is BINARY
166863
+** 6. Both operands use the same collating sequence
166515166864
** If this routine returns TRUE, that means that the RHS can be substituted
166516166865
** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
166517166866
** This is an optimization. No harm comes from returning 0. But if 1 is
166518166867
** returned when it should not be, then incorrect answers might result.
166519166868
*/
166520166869
static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){
166521166870
char aff1, aff2;
166522
- CollSeq *pColl;
166523166871
if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
166524166872
if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
166525166873
if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
166526166874
assert( pSrc!=0 );
166527166875
if( pExpr->op==TK_IS
@@ -166535,14 +166883,11 @@
166535166883
if( aff1!=aff2
166536166884
&& (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
166537166885
){
166538166886
return 0; /* (5) */
166539166887
}
166540
- pColl = sqlite3ExprCompareCollSeq(pParse, pExpr);
166541
- if( !sqlite3IsBinary(pColl)
166542
- && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight)
166543
- ){
166888
+ if( !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight) ){
166544166889
return 0; /* (6) */
166545166890
}
166546166891
return 1;
166547166892
}
166548166893
@@ -166870,11 +167215,11 @@
166870167215
166871167216
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
166872167217
/* Analyze a term that is composed of two or more subterms connected by
166873167218
** an OR operator.
166874167219
*/
166875
- else if( pExpr->op==TK_OR ){
167220
+ else if( pExpr->op==TK_OR && !ExprHasProperty(pExpr, EP_Collate) ){
166876167221
assert( pWC->op==TK_AND );
166877167222
exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
166878167223
pTerm = &pWC->a[idxTerm];
166879167224
}
166880167225
#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
@@ -170589,13 +170934,14 @@
170589170934
pLoop->nOut--;
170590170935
if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
170591170936
&& (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
170592170937
){
170593170938
Expr *pRight = pOpExpr->pRight;
170939
+ Parse *pParse = pWC->pWInfo->pParse;
170594170940
int k = 0;
170595170941
testcase( pOpExpr->op==TK_IS );
170596
- if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){
170942
+ if( sqlite3ExprIsInteger(pRight, &k, pParse) && k>=(-1) && k<=1 ){
170597170943
k = 10;
170598170944
}else{
170599170945
k = 20;
170600170946
}
170601170947
if( iReduce<k ){
@@ -170688,11 +171034,12 @@
170688171034
testcase( pLhs->iColumn==XN_ROWID );
170689171035
aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs));
170690171036
idxaff = sqlite3TableColumnAffinity(pIdx->pTable, pLhs->iColumn);
170691171037
if( aff!=idxaff ) break;
170692171038
170693
- pColl = sqlite3ExprCompareCollSeq(pParse, pTerm->pExpr);
171039
+ if( ExprHasProperty(pTerm->pExpr, EP_Commuted) ) SWAP(Expr*, pRhs, pLhs);
171040
+ pColl = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
170694171041
if( pColl==0 ) break;
170695171042
if( sqlite3StrICmp(pColl->zName, pIdx->azColl[i+nEq]) ) break;
170696171043
}
170697171044
return i;
170698171045
}
@@ -183162,13 +183509,15 @@
183162183509
case 196: /* expr ::= LP nexprlist COMMA expr RP */
183163183510
{
183164183511
ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy14, yymsp[-1].minor.yy454);
183165183512
yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
183166183513
if( yymsp[-4].minor.yy454 ){
183514
+ int i;
183167183515
yymsp[-4].minor.yy454->x.pList = pList;
183168
- if( ALWAYS(pList->nExpr) ){
183169
- yymsp[-4].minor.yy454->flags |= pList->a[0].pExpr->flags & EP_Propagate;
183516
+ for(i=0; i<pList->nExpr; i++){
183517
+ assert( pList->a[i].pExpr!=0 );
183518
+ yymsp[-4].minor.yy454->flags |= pList->a[i].pExpr->flags & EP_Propagate;
183170183519
}
183171183520
}else{
183172183521
sqlite3ExprListDelete(pParse->db, pList);
183173183522
}
183174183523
}
@@ -183632,19 +183981,17 @@
183632183981
sqlite3AlterSetNotNull(pParse, yymsp[-7].minor.yy203, &yymsp[-4].minor.yy0, &yymsp[-2].minor.yy0);
183633183982
}
183634183983
break;
183635183984
case 300: /* cmd ::= ALTER TABLE fullname ADD CONSTRAINT nm CHECK LP expr RP onconf */
183636183985
{
183637
- sqlite3AlterAddConstraint(pParse, yymsp[-8].minor.yy203, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1));
183986
+ sqlite3AlterAddConstraint(pParse, yymsp[-8].minor.yy203, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1), yymsp[-2].minor.yy454);
183638183987
}
183639
- yy_destructor(yypParser,219,&yymsp[-2].minor);
183640183988
break;
183641183989
case 301: /* cmd ::= ALTER TABLE fullname ADD CHECK LP expr RP onconf */
183642183990
{
183643
- sqlite3AlterAddConstraint(pParse, yymsp[-6].minor.yy203, &yymsp[-4].minor.yy0, 0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1));
183991
+ sqlite3AlterAddConstraint(pParse, yymsp[-6].minor.yy203, &yymsp[-4].minor.yy0, 0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1), yymsp[-2].minor.yy454);
183644183992
}
183645
- yy_destructor(yypParser,219,&yymsp[-2].minor);
183646183993
break;
183647183994
case 302: /* cmd ::= create_vtab */
183648183995
{sqlite3VtabFinishParse(pParse,0);}
183649183996
break;
183650183997
case 303: /* cmd ::= create_vtab LP vtabarglist RP */
@@ -199171,11 +199518,11 @@
199171199518
break;
199172199519
199173199520
/* State 3. The integer just read is a column number. */
199174199521
default: assert( eState==3 );
199175199522
iCol = (int)v;
199176
- if( iCol<1 ){
199523
+ if( iCol<1 || iCol>0x3fffffff ){
199177199524
rc = SQLITE_CORRUPT_VTAB;
199178199525
break;
199179199526
}
199180199527
if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM;
199181199528
pCsr->aStat[iCol+1].nDoc++;
@@ -199861,10 +200208,11 @@
199861200208
/* If this is a "NEAR" keyword, check for an explicit nearness. */
199862200209
if( pKey->eType==FTSQUERY_NEAR ){
199863200210
assert( nKey==4 );
199864200211
if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
199865200212
nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear);
200213
+ if( nNear>=1000000000 ) nNear = 1000000000;
199866200214
}
199867200215
}
199868200216
199869200217
/* At this point this is probably a keyword. But for that to be true,
199870200218
** the next byte must contain either whitespace, an open or close
@@ -209724,11 +210072,11 @@
209724210072
int nHit = fts3ColumnlistCount(&pIter);
209725210073
if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
209726210074
if( p->flag==FTS3_MATCHINFO_LHITS ){
209727210075
p->aMatchinfo[iStart + iCol] = (u32)nHit;
209728210076
}else if( nHit ){
209729
- p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
210077
+ p->aMatchinfo[iStart + iCol/32] |= (1U << (iCol&0x1F));
209730210078
}
209731210079
}
209732210080
assert( *pIter==0x00 || *pIter==0x01 );
209733210081
if( *pIter!=0x01 ) break;
209734210082
pIter++;
@@ -213744,11 +214092,11 @@
213744214092
break;
213745214093
case '\n':
213746214094
break;
213747214095
case 0xe2:
213748214096
/* '\' followed by either U+2028 or U+2029 is ignored as
213749
- ** whitespace. Not that in UTF8, U+2028 is 0xe2 0x80 0x29.
214097
+ ** whitespace. Note that in UTF8, U+2028 is 0xe2 0x80 0x29.
213750214098
** U+2029 is the same except for the last byte */
213751214099
if( sz2<4
213752214100
|| 0x80!=(u8)zIn[2]
213753214101
|| (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3])
213754214102
){
@@ -216313,15 +216661,13 @@
216313216661
char c;
216314216662
JsonString *pStr;
216315216663
UNUSED_PARAMETER(argc);
216316216664
UNUSED_PARAMETER(argv);
216317216665
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216318
-#ifdef NEVER
216319216666
/* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
216320216667
** always have been called to initialize it */
216321216668
if( NEVER(!pStr) ) return;
216322
-#endif
216323216669
z = pStr->zBuf;
216324216670
for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
216325216671
if( c=='"' ){
216326216672
inStr = !inStr;
216327216673
}else if( c=='\\' ){
@@ -216346,10 +216692,17 @@
216346216692
216347216693
/*
216348216694
** json_group_obj(NAME,VALUE)
216349216695
**
216350216696
** Return a JSON object composed of all names and values in the aggregate.
216697
+**
216698
+** Rows for which NAME is NULL do not result in a new entry. However, we
216699
+** do initially insert a "@" entry into the growing string for each null entry
216700
+** and change the first character of the string to "@" to signal that the
216701
+** string contains null entries. The "@" markers are needed in order to
216702
+** correctly process xInverse() requests. The initial "@" is converted
216703
+** back into "{" and the "@" null values are removed by jsonObjectCompute().
216351216704
*/
216352216705
static void jsonObjectStep(
216353216706
sqlite3_context *ctx,
216354216707
int argc,
216355216708
sqlite3_value **argv
@@ -216363,49 +216716,97 @@
216363216716
z = (const char*)sqlite3_value_text(argv[0]);
216364216717
n = sqlite3Strlen30(z);
216365216718
if( pStr->zBuf==0 ){
216366216719
jsonStringInit(pStr, ctx);
216367216720
jsonAppendChar(pStr, '{');
216368
- }else if( pStr->nUsed>1 && z!=0 ){
216721
+ }else if( pStr->nUsed>1 ){
216369216722
jsonAppendChar(pStr, ',');
216370216723
}
216371216724
pStr->pCtx = ctx;
216372216725
if( z!=0 ){
216373216726
jsonAppendString(pStr, z, n);
216374216727
jsonAppendChar(pStr, ':');
216375216728
jsonAppendSqlValue(pStr, argv[1]);
216729
+ }else{
216730
+ pStr->zBuf[0] = '@';
216731
+ jsonAppendRawNZ(pStr, "@", 1);
216376216732
}
216377216733
}
216378216734
}
216379216735
static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
216380216736
JsonString *pStr;
216381216737
int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216382216738
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216383216739
if( pStr ){
216384
- jsonAppendRawNZ(pStr, "}", 2);
216385
- jsonStringTrimOneChar(pStr);
216740
+ JsonString *pOgStr = pStr;
216741
+ JsonString tmpStr;
216742
+ jsonAppendRawNZ(pOgStr, "}", 2); /* Ensure it is zero-terminated */
216743
+ jsonStringTrimOneChar(pOgStr); /* Remove the zero terminator */
216386216744
pStr->pCtx = ctx;
216387216745
if( pStr->eErr ){
216388216746
jsonReturnString(pStr, 0, 0);
216389216747
return;
216390
- }else if( flags & JSON_BLOB ){
216748
+ }
216749
+ if( pStr->zBuf[0]!='{' ){
216750
+ /* The string contains null entries that need to be removed */
216751
+ u64 i, j;
216752
+ int inStr = 0;
216753
+ if( !isFinal ){
216754
+ /* Work with a temporary copy of the string if this is not the
216755
+ ** final result */
216756
+ jsonStringInit(&tmpStr, ctx);
216757
+ jsonAppendRawNZ(&tmpStr, pStr->zBuf, pStr->nUsed+1);
216758
+ pStr = &tmpStr;
216759
+ if( pStr->eErr ){
216760
+ jsonReturnString(pStr, 0, 0);
216761
+ return;
216762
+ }
216763
+ jsonStringTrimOneChar(pStr); /* Remove zero terminator */
216764
+ }
216765
+ /* Fix up the string by changing the initial "@" flag back to
216766
+ ** to "{" and removing all subsequence "@" entries, with their
216767
+ ** associated comma delimeters. */
216768
+ pStr->zBuf[0] = '{';
216769
+ for(i=j=1; i<pStr->nUsed; i++){
216770
+ char c = pStr->zBuf[i];
216771
+ if( c=='"' ){
216772
+ inStr = !inStr;
216773
+ pStr->zBuf[j++] = '"';
216774
+ }else if( c=='\\' ){
216775
+ pStr->zBuf[j++] = '\\';
216776
+ pStr->zBuf[j++] = pStr->zBuf[++i];
216777
+ }else if( c=='@' && !inStr ){
216778
+ assert( i+1<pStr->nUsed );
216779
+ if( pStr->zBuf[i+1]==',' ){
216780
+ i++;
216781
+ }else if( pStr->zBuf[j-1]==',' ){
216782
+ j--;
216783
+ }
216784
+ }else{
216785
+ pStr->zBuf[j++] = c;
216786
+ }
216787
+ }
216788
+ pStr->zBuf[j] = 0; /* Restore zero terminator */
216789
+ pStr->nUsed = j; /* Truncate the string */
216790
+ }
216791
+ if( flags & JSON_BLOB ){
216391216792
jsonReturnStringAsBlob(pStr);
216392216793
if( isFinal ){
216393216794
if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
216394216795
}else{
216395
- jsonStringTrimOneChar(pStr);
216796
+ jsonStringTrimOneChar(pOgStr);
216396216797
}
216397
- return;
216398216798
}else if( isFinal ){
216399216799
sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
216400216800
pStr->bStatic ? SQLITE_TRANSIENT :
216401216801
sqlite3RCStrUnref);
216402216802
pStr->bStatic = 1;
216403216803
}else{
216404216804
sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
216405
- jsonStringTrimOneChar(pStr);
216805
+ jsonStringTrimOneChar(pOgStr);
216406216806
}
216807
+ if( pStr!=pOgStr ) jsonStringReset(pStr);
216407216808
}else if( flags & JSON_BLOB ){
216408216809
static const unsigned char emptyObject = 0x0c;
216409216810
sqlite3_result_blob(ctx, &emptyObject, 1, SQLITE_STATIC);
216410216811
}else{
216411216812
sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC);
@@ -218751,11 +219152,14 @@
218751219152
while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
218752219153
u8 *pCellData;
218753219154
pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc);
218754219155
if( rc ) return rc;
218755219156
nCell = NCELL(pNode);
218756
- assert( nCell<200 );
219157
+ if( nCell>RTREE_MAXCELLS ){
219158
+ RTREE_IS_CORRUPT(pRtree);
219159
+ return SQLITE_CORRUPT_VTAB;
219160
+ }
218757219161
pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell);
218758219162
while( p->iCell<nCell ){
218759219163
sqlite3_rtree_dbl rScore = (sqlite3_rtree_dbl)-1;
218760219164
eWithin = FULLY_WITHIN;
218761219165
for(ii=0; ii<nConstraint; ii++){
@@ -223781,11 +224185,11 @@
223781224185
*/
223782224186
static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
223783224187
const UChar *zInput; /* Pointer to input string */
223784224188
UChar *zOutput = 0; /* Pointer to output buffer */
223785224189
int nInput; /* Size of utf-16 input string in bytes */
223786
- int nOut; /* Size of output buffer in bytes */
224190
+ sqlite3_int64 nOut; /* Size of output buffer in bytes */
223787224191
int cnt;
223788224192
int bToUpper; /* True for toupper(), false for tolower() */
223789224193
UErrorCode status;
223790224194
const char *zLocale = 0;
223791224195
@@ -223804,22 +224208,22 @@
223804224208
sqlite3_result_text16(p, "", 0, SQLITE_STATIC);
223805224209
return;
223806224210
}
223807224211
223808224212
for(cnt=0; cnt<2; cnt++){
223809
- UChar *zNew = sqlite3_realloc(zOutput, nOut);
224213
+ UChar *zNew = sqlite3_realloc64(zOutput, nOut);
223810224214
if( zNew==0 ){
223811224215
sqlite3_free(zOutput);
223812224216
sqlite3_result_error_nomem(p);
223813224217
return;
223814224218
}
223815224219
zOutput = zNew;
223816224220
status = U_ZERO_ERROR;
223817224221
if( bToUpper ){
223818
- nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
224222
+ nOut = 2LL*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
223819224223
}else{
223820
- nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
224224
+ nOut = 2LL*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
223821224225
}
223822224226
223823224227
if( U_SUCCESS(status) ){
223824224228
sqlite3_result_text16(p, zOutput, nOut, xFree);
223825224229
}else if( status==U_BUFFER_OVERFLOW_ERROR ){
@@ -231535,16 +231939,17 @@
231535231939
if( NEVER(pBt==0) ) return SQLITE_OK;
231536231940
pCsr->pPager = sqlite3BtreePager(pBt);
231537231941
pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
231538231942
pCsr->mxPgno = sqlite3BtreeLastPage(pBt);
231539231943
if( idxNum & 1 ){
231944
+ i64 iPg = sqlite3_value_int64(argv[idxNum>>1]);
231540231945
assert( argc>(idxNum>>1) );
231541
- pCsr->pgno = sqlite3_value_int(argv[idxNum>>1]);
231542
- if( pCsr->pgno<1 || pCsr->pgno>pCsr->mxPgno ){
231946
+ if( iPg<1 || iPg>pCsr->mxPgno ){
231543231947
pCsr->pgno = 1;
231544231948
pCsr->mxPgno = 0;
231545231949
}else{
231950
+ pCsr->pgno = (Pgno)iPg;
231546231951
pCsr->mxPgno = pCsr->pgno;
231547231952
}
231548231953
}else{
231549231954
assert( pCsr->pgno==1 );
231550231955
}
@@ -231620,10 +232025,11 @@
231620232025
sqlite3_value **argv,
231621232026
sqlite_int64 *pRowid
231622232027
){
231623232028
DbpageTable *pTab = (DbpageTable *)pVtab;
231624232029
Pgno pgno;
232030
+ sqlite3_int64 pgno64;
231625232031
DbPage *pDbPage = 0;
231626232032
int rc = SQLITE_OK;
231627232033
char *zErr = 0;
231628232034
int iDb;
231629232035
Btree *pBt;
@@ -231639,15 +232045,15 @@
231639232045
if( argc==1 ){
231640232046
zErr = "cannot delete";
231641232047
goto update_fail;
231642232048
}
231643232049
if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
231644
- pgno = (Pgno)sqlite3_value_int64(argv[2]);
232050
+ pgno64 = sqlite3_value_int64(argv[2]);
231645232051
isInsert = 1;
231646232052
}else{
231647
- pgno = (Pgno)sqlite3_value_int64(argv[0]);
231648
- if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){
232053
+ pgno64 = (Pgno)sqlite3_value_int64(argv[0]);
232054
+ if( sqlite3_value_int64(argv[1])!=pgno64 ){
231649232055
zErr = "cannot insert";
231650232056
goto update_fail;
231651232057
}
231652232058
isInsert = 0;
231653232059
}
@@ -231660,14 +232066,15 @@
231660232066
zErr = "no such schema";
231661232067
goto update_fail;
231662232068
}
231663232069
}
231664232070
pBt = pTab->db->aDb[iDb].pBt;
231665
- if( pgno<1 || NEVER(pBt==0) ){
232071
+ if( pgno64<1 || pgno64>4294967294 || NEVER(pBt==0) ){
231666232072
zErr = "bad page number";
231667232073
goto update_fail;
231668232074
}
232075
+ pgno = (Pgno)pgno64;
231669232076
szPage = sqlite3BtreeGetPageSize(pBt);
231670232077
if( sqlite3_value_type(argv[3])!=SQLITE_BLOB
231671232078
|| sqlite3_value_bytes(argv[3])!=szPage
231672232079
){
231673232080
if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){
@@ -232688,11 +233095,13 @@
232688233095
/*
232689233096
** Read a varint value from aBuf[] into *piVal. Return the number of
232690233097
** bytes read.
232691233098
*/
232692233099
static int sessionVarintGet(const u8 *aBuf, int *piVal){
232693
- return getVarint32(aBuf, *piVal);
233100
+ int ret = getVarint32(aBuf, *piVal);
233101
+ *piVal = (*piVal & 0x7FFFFFFF);
233102
+ return ret;
232694233103
}
232695233104
232696233105
/*
232697233106
** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal.
232698233107
** Return the number of bytes read.
@@ -232703,11 +233112,11 @@
232703233112
memset(aCopy, 0, sizeof(aCopy));
232704233113
if( nBuf<sizeof(aCopy) ){
232705233114
memcpy(aCopy, aBuf, nBuf);
232706233115
aRead = aCopy;
232707233116
}
232708
- return getVarint32(aRead, *piVal);
233117
+ return sessionVarintGet(aRead, piVal);
232709233118
}
232710233119
232711233120
/* Load an unaligned and unsigned 32-bit integer */
232712233121
#define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
232713233122
@@ -234479,11 +234888,11 @@
234479234888
234480234889
if( zStmt==0 ){
234481234890
rc = SQLITE_NOMEM;
234482234891
}else{
234483234892
sqlite3_stmt *pStmt;
234484
- rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
234893
+ rc = sqlite3_prepare_v2(pSession->db, zStmt, -1, &pStmt, 0);
234485234894
if( rc==SQLITE_OK ){
234486234895
SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
234487234896
pDiffCtx->pStmt = pStmt;
234488234897
pDiffCtx->nOldOff = 0;
234489234898
pDiffCtx->bRowid = pTab->bRowid;
@@ -234542,11 +234951,11 @@
234542234951
);
234543234952
if( zStmt==0 || z1==0 || z2==0 ){
234544234953
rc = SQLITE_NOMEM;
234545234954
}else{
234546234955
sqlite3_stmt *pStmt;
234547
- rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
234956
+ rc = sqlite3_prepare_v2(pSession->db, zStmt, -1, &pStmt, 0);
234548234957
234549234958
if( rc==SQLITE_OK ){
234550234959
SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
234551234960
pDiffCtx->pStmt = pStmt;
234552234961
pDiffCtx->nOldOff = pTab->nCol;
@@ -236036,21 +236445,25 @@
236036236445
int i;
236037236446
for(i=0; rc==SQLITE_OK && i<nCol; i++){
236038236447
int eType;
236039236448
rc = sessionInputBuffer(pIn, nByte + 10);
236040236449
if( rc==SQLITE_OK ){
236041
- eType = pIn->aData[pIn->iNext + nByte++];
236042
- if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
236043
- int n;
236044
- int nRem = pIn->nData - (pIn->iNext + nByte);
236045
- nByte += sessionVarintGetSafe(&pIn->aData[pIn->iNext+nByte], nRem, &n);
236046
- nByte += n;
236047
- rc = sessionInputBuffer(pIn, nByte);
236048
- }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
236049
- nByte += 8;
236050
- }else if( eType!=0 && eType!=SQLITE_NULL ){
236450
+ if( pIn->iNext+nByte>=pIn->nData ){
236051236451
rc = SQLITE_CORRUPT_BKPT;
236452
+ }else{
236453
+ eType = pIn->aData[pIn->iNext + nByte++];
236454
+ if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
236455
+ int n;
236456
+ int nRem = pIn->nData - (pIn->iNext + nByte);
236457
+ nByte += sessionVarintGetSafe(&pIn->aData[pIn->iNext+nByte], nRem,&n);
236458
+ nByte += n;
236459
+ rc = sessionInputBuffer(pIn, nByte);
236460
+ }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
236461
+ nByte += 8;
236462
+ }else if( eType!=0 && eType!=SQLITE_NULL ){
236463
+ rc = SQLITE_CORRUPT_BKPT;
236464
+ }
236052236465
}
236053236466
}
236054236467
if( rc==SQLITE_OK && (pIn->iNext+nByte)>pIn->nData ){
236055236468
rc = SQLITE_CORRUPT_BKPT;
236056236469
}
@@ -237386,11 +237799,11 @@
237386237799
237387237800
/* Bind values to the UPDATE statement. */
237388237801
for(i=0; rc==SQLITE_OK && i<nCol; i++){
237389237802
sqlite3_value *pOld = sessionChangesetOld(pIter, i);
237390237803
sqlite3_value *pNew = sessionChangesetNew(pIter, i);
237391
- if( p->abPK[i] || (bPatchset==0 && pOld) ){
237804
+ if( pOld && (p->abPK[i] || bPatchset==0) ){
237392237805
rc = sessionBindValue(pUp, i*2+2, pOld);
237393237806
}
237394237807
if( rc==SQLITE_OK && pNew ){
237395237808
rc = sessionBindValue(pUp, i*2+1, pNew);
237396237809
}
@@ -239447,10 +239860,11 @@
239447239860
sqlite3_changegroup *pGrp,
239448239861
int bDiscard,
239449239862
char **pzErr
239450239863
){
239451239864
int rc = SQLITE_OK;
239865
+ char *zErr = 0;
239452239866
if( pGrp->cd.pTab ){
239453239867
SessionBuffer *aBuf = pGrp->cd.aBuf;
239454239868
int ii;
239455239869
239456239870
if( bDiscard==0 ){
@@ -239458,26 +239872,26 @@
239458239872
u8 eUndef = SQLITE_NULL;
239459239873
if( pGrp->cd.eOp==SQLITE_UPDATE ){
239460239874
for(ii=0; ii<nBuf; ii++){
239461239875
if( pGrp->cd.pTab->abPK[ii] ){
239462239876
if( aBuf[ii].nBuf<=1 ){
239463
- *pzErr = sqlite3_mprintf(
239877
+ zErr = sqlite3_mprintf(
239464239878
"invalid change: %s value in PK of old.* record",
239465239879
aBuf[ii].nBuf==1 ? "null" : "undefined"
239466239880
);
239467239881
rc = SQLITE_ERROR;
239468239882
break;
239469239883
}else if( aBuf[ii + nBuf].nBuf>0 ){
239470
- *pzErr = sqlite3_mprintf(
239884
+ zErr = sqlite3_mprintf(
239471239885
"invalid change: defined value in PK of new.* record"
239472239886
);
239473239887
rc = SQLITE_ERROR;
239474239888
break;
239475239889
}
239476239890
}else
239477239891
if( pGrp->bPatch==0 && (aBuf[ii].nBuf>0)!=(aBuf[ii+nBuf].nBuf>0) ){
239478
- *pzErr = sqlite3_mprintf(
239892
+ zErr = sqlite3_mprintf(
239479239893
"invalid change: column %d "
239480239894
"- old.* value is %sdefined but new.* is %sdefined",
239481239895
ii, aBuf[ii].nBuf ? "" : "un", aBuf[ii+nBuf].nBuf ? "" : "un"
239482239896
);
239483239897
rc = SQLITE_ERROR;
@@ -239490,18 +239904,18 @@
239490239904
for(ii=0; ii<nBuf; ii++){
239491239905
int isPK = pGrp->cd.pTab->abPK[ii];
239492239906
if( (pGrp->cd.eOp==SQLITE_INSERT || pGrp->bPatch==0 || isPK)
239493239907
&& aBuf[ii].nBuf==0
239494239908
){
239495
- *pzErr = sqlite3_mprintf(
239909
+ zErr = sqlite3_mprintf(
239496239910
"invalid change: column %d is undefined", ii
239497239911
);
239498239912
rc = SQLITE_ERROR;
239499239913
break;
239500239914
}
239501239915
if( aBuf[ii].nBuf==1 && isPK ){
239502
- *pzErr = sqlite3_mprintf(
239916
+ zErr = sqlite3_mprintf(
239503239917
"invalid change: null value in PK"
239504239918
);
239505239919
rc = SQLITE_ERROR;
239506239920
break;
239507239921
}
@@ -239547,10 +239961,15 @@
239547239961
}
239548239962
}
239549239963
pGrp->cd.pTab = 0;
239550239964
}
239551239965
239966
+ if( pzErr ){
239967
+ *pzErr = zErr;
239968
+ }else{
239969
+ sqlite3_free(zErr);
239970
+ }
239552239971
return rc;
239553239972
}
239554239973
239555239974
#endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */
239556239975
@@ -250006,11 +250425,11 @@
250006250425
}
250007250426
250008250427
static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
250009250428
Fts5Data *pRet = fts5DataRead(p, iRowid);
250010250429
if( pRet ){
250011
- if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
250430
+ if( pRet->szLeaf<4 || pRet->szLeaf>pRet->nn ){
250012250431
FTS5_CORRUPT_ROWID(p, iRowid);
250013250432
fts5DataRelease(pRet);
250014250433
pRet = 0;
250015250434
}
250016250435
}
@@ -251660,10 +252079,14 @@
251660252079
/* Figure out how many new bytes are in this term */
251661252080
fts5FastGetVarint32(a, iOff, nNew);
251662252081
if( nKeep<nMatch ){
251663252082
goto search_failed;
251664252083
}
252084
+ if( (iOff+nNew)>n ){
252085
+ FTS5_CORRUPT_ITER(p, pIter);
252086
+ return;
252087
+ }
251665252088
251666252089
assert( nKeep>=nMatch );
251667252090
if( nKeep==nMatch ){
251668252091
u32 nCmp;
251669252092
u32 i;
@@ -252786,11 +253209,11 @@
252786253209
}
252787253210
252788253211
/* Advance pointer p until it points to pEnd or an 0x01 byte that is
252789253212
** not part of a varint */
252790253213
while( p<pEnd && *p!=0x01 ){
252791
- while( *p++ & 0x80 );
253214
+ while( p<pEnd && (*p++ & 0x80) );
252792253215
}
252793253216
252794253217
if( pColset->aiCol[i]==iCurrent ){
252795253218
if( pColset->nCol==1 ){
252796253219
pIter->base.pData = aCopy;
@@ -262254,11 +262677,11 @@
262254262677
int nArg, /* Number of args */
262255262678
sqlite3_value **apUnused /* Function arguments */
262256262679
){
262257262680
assert( nArg==0 );
262258262681
UNUSED_PARAM2(nArg, apUnused);
262259
- sqlite3_result_text(pCtx, "fts5: 2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb", -1, SQLITE_TRANSIENT);
262682
+ sqlite3_result_text(pCtx, "fts5: 2026-05-21 15:14:35 9ac4a33a2932d353c4871fd8e09c10addf827f1fc3fc9380037d738cf2cd0353", -1, SQLITE_TRANSIENT);
262260262683
}
262261262684
262262262685
/*
262263262686
** Implementation of fts5_locale(LOCALE, TEXT) function.
262264262687
**
@@ -264648,12 +265071,18 @@
264648265071
PorterTokenizer *pRet;
264649265072
void *pUserdata = 0;
264650265073
const char *zBase = "unicode61";
264651265074
fts5_tokenizer_v2 *pV2 = 0;
264652265075
264653
- if( nArg>0 ){
264654
- zBase = azArg[0];
265076
+ while( nArg>0 ){
265077
+ if( sqlite3_stricmp(azArg[0],"porter")==0 ){
265078
+ nArg--;
265079
+ azArg++;
265080
+ }else{
265081
+ zBase = azArg[0];
265082
+ break;
265083
+ }
264655265084
}
264656265085
264657265086
pRet = (PorterTokenizer*)sqlite3_malloc64(sizeof(PorterTokenizer));
264658265087
if( pRet ){
264659265088
memset(pRet, 0, sizeof(PorterTokenizer));
264660265089
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 7e4134e3ff1ca8712f5fc78fadae66554945 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-05-04T10:14:13.819Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4373,12 +4373,11 @@
4373 ** parameter on F or if the value of P does not match any of the
4374 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4375 **
4376 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4377 ** 64-bit signed integer and returns that integer, or D if P does not
4378 ** exist. If the value of P is something other than an integer, then
4379 ** zero is returned.
4380 **
4381 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4382 ** the value) of the N-th query parameter for filename F, or a NULL
4383 ** pointer if N is less than zero or greater than the number of query
4384 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
@@ -18705,11 +18704,11 @@
18705 int aLimit[SQLITE_N_LIMIT]; /* Limits */
18706 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
18707 struct sqlite3InitInfo { /* Information used during initialization */
18708 Pgno newTnum; /* Rootpage of table being initialized */
18709 u8 iDb; /* Which db file is being initialized */
18710 u8 busy; /* TRUE if currently initializing */
18711 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
18712 unsigned imposterTable : 2; /* Building an imposter table */
18713 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
18714 const char **azInit; /* "type", "name", and "tbl_name" columns */
18715 } init;
@@ -21256,11 +21255,11 @@
21256 */
21257 #define INITFLAG_AlterMask 0x0007 /* Types of ALTER */
21258 #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
21259 #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
21260 #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
21261 #define INITFLAG_AlterDropCons 0x0004 /* Reparse after an ADD COLUMN */
21262
21263 /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
21264 ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
21265 ** parameters are for temporary use during development, to help find
21266 ** optimal values for parameters in the query planner. The should not
@@ -22509,11 +22508,19 @@
22509 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
22510 SQLITE_PRIVATE void sqlite3AlterFunctions(void);
22511 SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
22512 SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
22513 SQLITE_PRIVATE void sqlite3AlterDropConstraint(Parse*,SrcList*,Token*,Token*);
22514 SQLITE_PRIVATE void sqlite3AlterAddConstraint(Parse*,SrcList*,Token*,Token*,const char*,int);
 
 
 
 
 
 
 
 
22515 SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*);
22516 SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *);
22517 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
22518 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
22519 SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
@@ -32413,12 +32420,14 @@
32413 #define etSRCITEM 12 /* a pointer to a SrcItem */
32414 #define etPOINTER 13 /* The %p conversion */
32415 #define etESCAPE_w 14 /* %w -> Strings with '\"' doubled */
32416 #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
32417 #define etDECIMAL 16 /* %d or %u, but not %x, %o */
 
 
32418
32419 #define etINVALID 17 /* Any unrecognized conversion type */
32420
32421
32422 /*
32423 ** An "etByte" is an 8-bit unsigned value.
32424 */
@@ -32444,24 +32453,24 @@
32444 #define FLAG_SIGNED 1 /* True if the value to convert is signed */
32445 #define FLAG_STRING 4 /* Allow infinite precision */
32446
32447 /*
32448 ** The table is searched by hash. In the case of %C where C is the character
32449 ** and that character has ASCII value j, then the hash is j%23.
32450 **
32451 ** The order of the entries in fmtinfo[] and the hash chain was entered
32452 ** manually, but based on the output of the following TCL script:
32453 */
32454 #if 0 /***** Beginning of script ******/
32455 foreach c {d s g z q Q w c o u x X f e E G i n % p T S r} {
32456 scan $c %c x
32457 set n($c) $x
32458 }
32459 set mx [llength [array names n]]
32460 puts "count: $mx"
32461
32462 set mx 27
32463 puts "*********** mx=$mx ************"
32464 for {set r 0} {$r<$mx} {incr r} {
32465 puts -nonewline [format %2d: $r]
32466 foreach c [array names n] {
32467 if {($n($c))%$mx==$r} {puts -nonewline " $c"}
@@ -32469,35 +32478,38 @@
32469 puts ""
32470 }
32471 #endif /***** End of script ********/
32472
32473 static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
 
32474 static const char aPrefix[] = "-x0\000X0";
32475 static const et_info fmtinfo[23] = {
32476 /* 0 */ { 's', 0, 4, etSTRING, 0, 0, 1 },
32477 /* 1 */ { 'E', 0, 1, etEXP, 14, 0, 0 }, /* Hash: 0 */
32478 /* 2 */ { 'u', 10, 0, etDECIMAL, 0, 0, 3 },
32479 /* 3 */ { 'G', 0, 1, etGENERIC, 14, 0, 0 }, /* Hash: 2 */
32480 /* 4 */ { 'w', 0, 4, etESCAPE_w, 0, 0, 0 },
32481 /* 5 */ { 'x', 16, 0, etRADIX, 16, 1, 0 },
32482 /* 6 */ { 'c', 0, 0, etCHARX, 0, 0, 0 }, /* Hash: 7 */
32483 /* 7 */ { 'z', 0, 4, etDYNSTRING, 0, 0, 6 },
32484 /* 8 */ { 'd', 10, 1, etDECIMAL, 0, 0, 0 },
32485 /* 9 */ { 'e', 0, 1, etEXP, 30, 0, 0 },
32486 /* 10 */ { 'f', 0, 1, etFLOAT, 0, 0, 0 },
32487 /* 11 */ { 'g', 0, 1, etGENERIC, 30, 0, 0 },
32488 /* 12 */ { 'Q', 0, 4, etESCAPE_Q, 0, 0, 0 },
32489 /* 13 */ { 'i', 10, 1, etDECIMAL, 0, 0, 0 },
32490 /* 14 */ { '%', 0, 0, etPERCENT, 0, 0, 16 },
32491 /* 15 */ { 'T', 0, 0, etTOKEN, 0, 0, 0 },
32492 /* 16 */ { 'S', 0, 0, etSRCITEM, 0, 0, 0 }, /* Hash: 14 */
32493 /* 17 */ { 'X', 16, 0, etRADIX, 0, 4, 0 }, /* Hash: 19 */
32494 /* 18 */ { 'n', 0, 0, etSIZE, 0, 0, 0 },
32495 /* 19 */ { 'o', 8, 0, etRADIX, 0, 2, 17 },
32496 /* 20 */ { 'p', 16, 0, etPOINTER, 0, 1, 0 },
32497 /* 21 */ { 'q', 0, 4, etESCAPE_q, 0, 0, 0 },
32498 /* 22 */ { 'r', 10, 1, etORDINAL, 0, 0, 0 }
 
 
32499 };
32500
32501 /* Additional Notes:
32502 **
32503 ** %S Takes a pointer to SrcItem. Shows name or database.name
@@ -32754,12 +32766,12 @@
32754 break;
32755 }
32756 }
32757 #else
32758 /* Fast hash-table lookup */
32759 assert( ArraySize(fmtinfo)==23 );
32760 idx = ((unsigned)c) % 23;
32761 if( fmtinfo[idx].fmttype==c
32762 || fmtinfo[idx = fmtinfo[idx].iNxt].fmttype==c
32763 ){
32764 infop = &fmtinfo[idx];
32765 xtype = infop->type;
@@ -33126,11 +33138,11 @@
33126 length = width;
33127 }
33128
33129 if( zExtra==0 ){
33130 /* The result is being rendered directory into pAccum. This
33131 ** is the command and fast case */
33132 pAccum->nChar += length;
33133 zOut[length] = 0;
33134 continue;
33135 }else{
33136 /* We were unable to render directly into pAccum because we
@@ -33246,10 +33258,87 @@
33246 /* Adjust width to account for extra bytes in UTF-8 characters */
33247 int ii = length - 1;
33248 while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++;
33249 }
33250 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33251 case etESCAPE_q: /* %q: Escape ' characters */
33252 case etESCAPE_Q: /* %Q: Escape ' and enclose in '...' */
33253 case etESCAPE_w: { /* %w: Escape " characters */
33254 i64 i, j, k, n;
33255 int needQuote = 0;
@@ -33337,11 +33426,11 @@
33337 bufpt[j-1] = '\\';
33338 bufpt[j++] = 'u';
33339 bufpt[j++] = '0';
33340 bufpt[j++] = '0';
33341 bufpt[j++] = ch>=0x10 ? '1' : '0';
33342 bufpt[j++] = "0123456789abcdef"[ch&0xf];
33343 }
33344 }
33345 }else{
33346 for(i=0; i<k; i++){
33347 bufpt[j++] = ch = escarg[i];
@@ -45345,13 +45434,13 @@
45345
45346 /* Minimum number of regions required to be mapped. */
45347 nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap;
45348
45349 if( pShmNode->nRegion<nReqRegion ){
45350 char **apNew; /* New apRegion[] array */
45351 int nByte = nReqRegion*szRegion; /* Minimum required file size */
45352 struct stat sStat; /* Used by fstat() */
45353
45354 pShmNode->szRegion = szRegion;
45355
45356 if( pShmNode->hShm>=0 ){
45357 /* The requested region is not mapped into this processes address space.
@@ -45378,11 +45467,11 @@
45378 ** pages forces the OS to allocate them immediately, which reduces
45379 ** the chances of SIGBUS while accessing the mapped region later on.
45380 */
45381 else{
45382 static const int pgsz = 4096;
45383 int iPg;
45384
45385 /* Write to the last byte of each newly allocated or extended page */
45386 assert( (nByte % pgsz)==0 );
45387 for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){
45388 int x = 0;
@@ -45404,12 +45493,12 @@
45404 rc = SQLITE_IOERR_NOMEM_BKPT;
45405 goto shmpage_out;
45406 }
45407 pShmNode->apRegion = apNew;
45408 while( pShmNode->nRegion<nReqRegion ){
45409 int nMap = szRegion*nShmPerMap;
45410 int i;
45411 void *pMem;
45412 if( pShmNode->hShm>=0 ){
45413 pMem = osMmap(0, nMap,
45414 pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE,
45415 MAP_SHARED, pShmNode->hShm, szRegion*(i64)pShmNode->nRegion
@@ -49195,107 +49284,154 @@
49195
49196 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
49197 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
49198 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent)
49199
 
 
 
 
 
 
 
 
 
 
49200 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
 
 
 
49201 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
49202 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[3].pCurrent)
49203
49204 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
49205 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[4].pCurrent)
49206
49207 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
49208 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[5].pCurrent)
49209
49210 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
49211 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
49212 DWORD,va_list*))aSyscall[6].pCurrent)
49213
49214 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49215 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
49216 #else
49217 { "FreeLibrary", (SYSCALL)0, 0 },
49218 #endif
49219
49220 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[7].pCurrent)
49221
49222 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
49223 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[8].pCurrent)
49224
49225 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
49226 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent)
49227
49228 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
49229 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
49230 LPVOID))aSyscall[10].pCurrent)
49231
49232 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
49233 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[11].pCurrent)
 
49234
49235 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
49236 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
49237 LPWSTR*))aSyscall[12].pCurrent)
49238
49239 { "GetLastError", (SYSCALL)GetLastError, 0 },
49240 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[13].pCurrent)
49241
49242 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49243 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
49244 #else
49245 { "GetProcAddressA", (SYSCALL)0, 0 },
49246 #endif
49247 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
49248 LPCSTR))aSyscall[14].pCurrent)
49249
49250 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
49251 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[15].pCurrent)
49252
49253 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
49254 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[16].pCurrent)
49255
49256 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
49257 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
49258 LPFILETIME))aSyscall[17].pCurrent)
49259
 
 
 
49260 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
 
49261 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent)
49262
49263 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
49264 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[19].pCurrent)
49265
 
 
 
49266 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
 
49267 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
49268 SIZE_T))aSyscall[20].pCurrent)
49269
 
 
 
49270 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
 
49271 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
49272 SIZE_T))aSyscall[21].pCurrent)
49273
 
 
 
49274 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
 
49275 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent)
49276
 
 
 
49277 { "HeapFree", (SYSCALL)HeapFree, 0 },
 
49278 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent)
49279
 
 
 
49280 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
 
49281 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
49282 SIZE_T))aSyscall[24].pCurrent)
49283
 
 
 
49284 { "HeapSize", (SYSCALL)HeapSize, 0 },
 
49285 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
49286 LPCVOID))aSyscall[25].pCurrent)
49287
 
 
 
49288 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
 
49289 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
49290 LPCVOID))aSyscall[26].pCurrent)
49291
 
 
 
49292 { "HeapCompact", (SYSCALL)HeapCompact, 0 },
 
49293 #define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent)
49294
49295
49296 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49297 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
49298 #else
49299 { "LoadLibraryW", (SYSCALL)0, 0 },
49300 #endif
49301 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent)
@@ -49305,72 +49441,82 @@
49305
49306 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
49307 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
49308 LPOVERLAPPED))aSyscall[30].pCurrent)
49309
49310 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
 
49311 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
49312 #else
49313 { "MapViewOfFile", (SYSCALL)0, 0 },
49314 #endif
49315 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49316 SIZE_T))aSyscall[31].pCurrent)
 
 
 
 
 
 
 
 
 
49317
49318 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
49319 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
49320 int))aSyscall[32].pCurrent)
49321
49322 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
49323 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
49324 LARGE_INTEGER*))aSyscall[33].pCurrent)
49325
49326 { "ReadFile", (SYSCALL)ReadFile, 0 },
49327 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
49328 LPOVERLAPPED))aSyscall[34].pCurrent)
49329
49330 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
49331 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[35].pCurrent)
49332
49333 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
49334 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
49335 DWORD))aSyscall[36].pCurrent)
49336
49337 { "Sleep", (SYSCALL)Sleep, 0 },
49338 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[37].pCurrent)
49339
49340 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
49341 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49342 LPOVERLAPPED))aSyscall[38].pCurrent)
49343
49344 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49345 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
49346 #else
49347 { "UnmapViewOfFile", (SYSCALL)0, 0 },
49348 #endif
49349 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[39].pCurrent)
49350
49351 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
49352 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
49353 LPCSTR,LPBOOL))aSyscall[40].pCurrent)
49354
49355 { "WriteFile", (SYSCALL)WriteFile, 0 },
49356 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
49357 LPOVERLAPPED))aSyscall[41].pCurrent)
49358
49359 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
49360 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
49361 DWORD))aSyscall[42].pCurrent)
49362
49363 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
49364 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
49365 BOOL))aSyscall[43].pCurrent)
49366
49367 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
49368 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[44].pCurrent)
49369
49370 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
49371 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[45].pCurrent)
49372
49373 /*
49374 ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
49375 ** is really just a macro that uses a compiler intrinsic (e.g. x64).
49376 ** So do not try to make this is into a redefinable interface.
@@ -49379,95 +49525,93 @@
49379 { "InterlockedCompareExchange", (SYSCALL)0, 0 },
49380 #define osInterlockedCompareExchange InterlockedCompareExchange
49381 #else
49382 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
49383 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\
49384 LONG,LONG))aSyscall[46].pCurrent)
49385 #endif /* defined(InterlockedCompareExchange) */
49386
49387 #if SQLITE_WIN32_USE_UUID
49388 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
49389 #else
49390 { "UuidCreate", (SYSCALL)0, 0 },
49391 #endif
49392 #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[47].pCurrent)
49393
49394 #if SQLITE_WIN32_USE_UUID
49395 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
49396 #else
49397 { "UuidCreateSequential", (SYSCALL)0, 0 },
49398 #endif
49399 #define osUuidCreateSequential \
49400 ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent)
49401
49402 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
49403 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
49404 #else
49405 { "FlushViewOfFile", (SYSCALL)0, 0 },
49406 #endif
49407 #define osFlushViewOfFile \
49408 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[49].pCurrent)
49409
49410 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49411 { "CreateEvent", (SYSCALL)CreateEvent, 0 },
49412 #else
49413 { "CreateEvent", (SYSCALL)0, 0 },
49414 #endif
49415 #define osCreateEvent ( \
49416 (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
49417 aSyscall[50].pCurrent \
49418 )
49419
49420 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49421 { "CancelIo", (SYSCALL)CancelIo, 0 },
49422 #else
49423 { "CancelIo", (SYSCALL)0, 0 },
49424 #endif
49425 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
49426
49427 #ifndef _WIN32
49428 { "getenv", (SYSCALL)getenv, 0 },
49429 #else
49430 { "getenv", (SYSCALL)0, 0 },
49431 #endif
49432 #define osGetenv ((const char *(*)(const char *))aSyscall[52].pCurrent)
49433
49434 #ifndef _WIN32
49435 { "getcwd", (SYSCALL)getcwd, 0 },
49436 #else
49437 { "getcwd", (SYSCALL)0, 0 },
49438 #endif
49439 #define osGetcwd ((char*(*)(char*,size_t))aSyscall[53].pCurrent)
49440
49441 #ifndef _WIN32
49442 { "readlink", (SYSCALL)readlink, 0 },
49443 #else
49444 { "readlink", (SYSCALL)0, 0 },
49445 #endif
49446 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[54].pCurrent)
49447
49448 #ifndef _WIN32
49449 { "lstat", (SYSCALL)lstat, 0 },
49450 #else
49451 { "lstat", (SYSCALL)0, 0 },
49452 #endif
49453 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[55].pCurrent)
49454
49455 #ifndef _WIN32
49456 { "__errno", (SYSCALL)__errno, 0 },
49457 #else
49458 { "__errno", (SYSCALL)0, 0 },
49459 #endif
49460 #define osErrno (*((int*(*)(void))aSyscall[56].pCurrent)())
49461
49462 #ifndef _WIN32
49463 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
49464 #else
49465 { "cygwin_conv_path", (SYSCALL)0, 0 },
49466 #endif
49467 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
49468 const void *, void *, size_t))aSyscall[57].pCurrent)
49469
49470 }; /* End of the overrideable system calls */
49471
49472 /*
49473 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -49551,10 +49695,13 @@
49551 }
49552 return 0;
49553 }
49554
49555 #ifdef SQLITE_WIN32_MALLOC
 
 
 
49556 /*
49557 ** If a Win32 native heap has been configured, this function will attempt to
49558 ** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one
49559 ** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The
49560 ** "pnLargest" argument, if non-zero, will be used to return the size of the
@@ -50509,31 +50656,15 @@
50509 ** If successful, return SQLITE_OK. Or, if an error occurs, return an SQLite
50510 ** error code.
50511 */
50512 static int winHandleSeek(HANDLE h, sqlite3_int64 iOffset){
50513 int rc = SQLITE_OK; /* Return value */
50514
50515 LONG upperBits; /* Most sig. 32 bits of new offset */
50516 LONG lowerBits; /* Least sig. 32 bits of new offset */
50517 DWORD dwRet; /* Value returned by SetFilePointer() */
50518
50519 upperBits = (LONG)((iOffset>>32) & 0x7fffffff);
50520 lowerBits = (LONG)(iOffset & 0xffffffff);
50521
50522 dwRet = osSetFilePointer(h, lowerBits, &upperBits, FILE_BEGIN);
50523
50524 /* API oddity: If successful, SetFilePointer() returns a dword
50525 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
50526 ** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
50527 ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
50528 ** whether an error has actually occurred, it is also necessary to call
50529 ** GetLastError(). */
50530 if( dwRet==INVALID_SET_FILE_POINTER ){
50531 DWORD lastErrno = osGetLastError();
50532 if( lastErrno!=NO_ERROR ){
50533 rc = SQLITE_IOERR_SEEK;
50534 }
50535 }
50536 OSTRACE(("SEEK file=%p, offset=%lld rc=%s\n", h, iOffset,sqlite3ErrName(rc)));
50537 return rc;
50538 }
50539
@@ -50812,18 +50943,17 @@
50812 ** Determine the size in bytes of the file opened by the handle passed as
50813 ** the first argument.
50814 */
50815 static int winHandleSize(HANDLE h, sqlite3_int64 *pnByte){
50816 int rc = SQLITE_OK;
50817 DWORD upperBits = 0;
50818 DWORD lowerBits = 0;
50819
50820 assert( pnByte );
50821 lowerBits = osGetFileSize(h, &upperBits);
50822 *pnByte = (((sqlite3_int64)upperBits)<<32) + lowerBits;
50823 if( lowerBits==INVALID_FILE_SIZE && osGetLastError()!=NO_ERROR ){
50824 rc = SQLITE_IOERR_FSTAT;
 
 
 
50825 }
50826 return rc;
50827 }
50828
50829 /*
@@ -51020,21 +51150,18 @@
51020 assert( id!=0 );
51021 assert( pSize!=0 );
51022 SimulateIOError(return SQLITE_IOERR_FSTAT);
51023 OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize));
51024 {
51025 DWORD upperBits;
51026 DWORD lowerBits;
51027 DWORD lastErrno;
51028
51029 lowerBits = osGetFileSize(pFile->h, &upperBits);
51030 *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
51031 if( (lowerBits == INVALID_FILE_SIZE)
51032 && ((lastErrno = osGetLastError())!=NO_ERROR) ){
51033 pFile->lastErrno = lastErrno;
51034 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
51035 "winFileSize", pFile->zPath);
 
 
51036 }
51037 }
51038 OSTRACE(("SIZE file=%p, pSize=%p, *pSize=%lld, rc=%s\n",
51039 pFile->h, pSize, *pSize, sqlite3ErrName(rc)));
51040 return rc;
@@ -52373,11 +52500,11 @@
52373
52374 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
52375 if( pShmNode->nRegion<=iRegion ){
52376 HANDLE hShared = pShmNode->hSharedShm;
52377 struct ShmRegion *apNew; /* New aRegion[] array */
52378 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
52379 sqlite3_int64 sz; /* Current size of wal-index file */
52380
52381 pShmNode->szRegion = szRegion;
52382
52383 /* The requested region is not mapped into this processes address space.
@@ -52404,11 +52531,11 @@
52404 }
52405 }
52406
52407 /* Map the requested memory region into this processes address space. */
52408 apNew = (struct ShmRegion*)sqlite3_realloc64(
52409 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
52410 );
52411 if( !apNew ){
52412 rc = SQLITE_IOERR_NOMEM_BKPT;
52413 goto shmpage_out;
52414 }
@@ -52421,20 +52548,30 @@
52421
52422 while( pShmNode->nRegion<=iRegion ){
52423 HANDLE hMap = NULL; /* file-mapping handle */
52424 void *pMap = 0; /* Mapped memory region */
52425
 
 
 
52426 hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
52427 OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
 
52428 osGetCurrentProcessId(), pShmNode->nRegion, nByte,
52429 hMap ? "ok" : "failed"));
52430 if( hMap ){
52431 int iOffset = pShmNode->nRegion*szRegion;
52432 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
 
 
 
 
 
52433 pMap = osMapViewOfFile(hMap, flags,
52434 0, iOffset - iOffsetShift, szRegion + iOffsetShift
52435 );
 
52436 OSTRACE(("SHM-MAP-MAP pid=%lu, region=%d, offset=%d, size=%d, rc=%s\n",
52437 osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
52438 szRegion, pMap ? "ok" : "failed"));
52439 }
52440 if( !pMap ){
@@ -52451,11 +52588,11 @@
52451 }
52452 }
52453
52454 shmpage_out:
52455 if( pShmNode->nRegion>iRegion ){
52456 int iOffset = iRegion*szRegion;
52457 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
52458 char *p = (char *)pShmNode->aRegion[iRegion].pMap;
52459 *pp = (void *)&p[iOffsetShift];
52460 }else{
52461 *pp = 0;
@@ -52563,13 +52700,17 @@
52563 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
52564 protect = PAGE_READWRITE;
52565 flags |= FILE_MAP_WRITE;
52566 }
52567 #endif
 
 
 
52568 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect,
52569 (DWORD)((nMap>>32) & 0xffffffff),
52570 (DWORD)(nMap & 0xffffffff), NULL);
 
52571 if( pFd->hMap==NULL ){
52572 pFd->lastErrno = osGetLastError();
52573 rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
52574 "winMapfile1", pFd->zPath);
52575 /* Log the error, but continue normal operation using xRead/xWrite */
@@ -52577,11 +52718,15 @@
52577 osGetCurrentProcessId(), pFd, sqlite3ErrName(rc)));
52578 return SQLITE_OK;
52579 }
52580 assert( (nMap % winSysInfo.dwPageSize)==0 );
52581 assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
 
 
 
52582 pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap);
 
52583 if( pNew==NULL ){
52584 osCloseHandle(pFd->hMap);
52585 pFd->hMap = NULL;
52586 pFd->lastErrno = osGetLastError();
52587 rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
@@ -52920,11 +53065,11 @@
52920 if( !zWidePath ){
52921 sqlite3_free(zBuf);
52922 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
52923 return SQLITE_IOERR_NOMEM_BKPT;
52924 }
52925 if( osGetTempPathW(nMax, zWidePath)==0 ){
52926 sqlite3_free(zWidePath);
52927 sqlite3_free(zBuf);
52928 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
52929 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
52930 "winGetTempname2", 0);
@@ -53723,37 +53868,37 @@
53723 /*
53724 ** Interfaces for opening a shared library, finding entry points
53725 ** within the shared library, and closing the shared library.
53726 */
53727 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
53728 HANDLE h;
53729 void *zConverted = winConvertFromUtf8Filename(zFilename);
53730 UNUSED_PARAMETER(pVfs);
53731 if( zConverted==0 ){
53732 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53733 return 0;
53734 }
53735 h = osLoadLibraryW((LPCWSTR)zConverted);
53736 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
53737 sqlite3_free(zConverted);
53738 return (void*)h;
53739 }
53740 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
53741 UNUSED_PARAMETER(pVfs);
53742 winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
53743 }
53744 static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
53745 FARPROC proc;
53746 UNUSED_PARAMETER(pVfs);
53747 proc = osGetProcAddressA((HANDLE)pH, zSym);
53748 OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n",
53749 (void*)pH, zSym, (void*)proc));
53750 return (void(*)(void))proc;
53751 }
53752 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
53753 UNUSED_PARAMETER(pVfs);
53754 osFreeLibrary((HANDLE)pHandle);
53755 OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle));
53756 }
53757 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
53758 #define winDlOpen 0
53759 #define winDlError 0
@@ -53798,36 +53943,39 @@
53798 e.a = (unsigned char*)zBuf;
53799 e.na = nBuf;
53800 e.nXor = 0;
53801 e.i = 0;
53802 {
53803 SYSTEMTIME x;
53804 osGetSystemTime(&x);
53805 xorMemory(&e, (unsigned char*)&x, sizeof(SYSTEMTIME));
53806 }
53807 {
53808 DWORD pid = osGetCurrentProcessId();
53809 xorMemory(&e, (unsigned char*)&pid, sizeof(DWORD));
53810 }
53811 {
53812 DWORD cnt = osGetTickCount();
53813 xorMemory(&e, (unsigned char*)&cnt, sizeof(DWORD));
53814 }
53815 {
53816 LARGE_INTEGER i;
53817 osQueryPerformanceCounter(&i);
53818 xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER));
53819 }
53820 #if SQLITE_WIN32_USE_UUID
 
 
 
53821 {
53822 UUID id;
53823 memset(&id, 0, sizeof(UUID));
53824 osUuidCreate(&id);
53825 xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
53826 memset(&id, 0, sizeof(UUID));
53827 osUuidCreateSequential(&id);
53828 xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
53829 }
53830 #endif /* SQLITE_WIN32_USE_UUID */
53831 return e.nXor>nBuf ? nBuf : e.nXor;
53832 #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */
53833 }
@@ -54042,15 +54190,19 @@
54042 winNextSystemCall, /* xNextSystemCall */
54043 };
54044
54045 /* Double-check that the aSyscall[] array has been constructed
54046 ** correctly. See ticket [bb3a86e890c8e96ab] */
54047 assert( ArraySize(aSyscall)==58 );
54048 assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
54049 assert( strcmp(aSyscall[20].zName,"HeapAlloc")==0 );
54050 assert( strcmp(aSyscall[40].zName,"WideCharToMultiByte")==0 );
54051 assert( strcmp(aSyscall[57].zName,"cygwin_conv_path")==0 );
 
 
 
 
54052
54053 /* get memory map allocation granularity */
54054 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
54055 osGetSystemInfo(&winSysInfo);
54056 assert( winSysInfo.dwAllocationGranularity>0 );
@@ -71953,10 +72105,20 @@
71953 ** See the header comment on "btreeInt.h" for additional information.
71954 ** Including a description of file format and an overview of operation.
71955 */
71956 /* #include "btreeInt.h" */
71957
 
 
 
 
 
 
 
 
 
 
71958 /*
71959 ** The header string that appears at the beginning of every
71960 ** SQLite database.
71961 */
71962 static const char zMagicHeader[] = SQLITE_FILE_HEADER;
@@ -77228,10 +77390,18 @@
77228 DbPage *pDbPage;
77229 rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage,
77230 (eOp==0 ? PAGER_GET_READONLY : 0)
77231 );
77232 if( rc==SQLITE_OK ){
 
 
 
 
 
 
 
 
77233 aPayload = sqlite3PagerGetData(pDbPage);
77234 nextPage = get4byte(aPayload);
77235 rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
77236 sqlite3PagerUnref(pDbPage);
77237 offset = 0;
@@ -83504,10 +83674,17 @@
83504 SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree *p){
83505 testcase( p->sharable );
83506 return p->pBt->nRef;
83507 }
83508 #endif
 
 
 
 
 
 
 
83509
83510 /************** End of btree.c ***********************************************/
83511 /************** Begin file backup.c ******************************************/
83512 /*
83513 ** 2009 January 28
@@ -87107,15 +87284,25 @@
87107 /*
87108 ** Add an OP_ParseSchema opcode. This routine is broken out from
87109 ** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees
87110 ** as having been used.
87111 **
87112 ** The zWhere string must have been obtained from sqlite3_malloc().
 
 
 
 
 
 
 
 
 
87113 ** This routine will take ownership of the allocated memory.
87114 */
87115 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere, u16 p5){
87116 int j;
 
87117 sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
87118 sqlite3VdbeChangeP5(p, p5);
87119 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
87120 sqlite3MayAbort(p->pParse);
87121 }
@@ -95713,14 +95900,16 @@
95713 */
95714 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
95715 int eType = sqlite3_value_type(pVal);
95716 if( eType==SQLITE_TEXT ){
95717 Mem *pMem = (Mem*)pVal;
95718 assert( pMem->db!=0 );
95719 sqlite3_mutex_enter(pMem->db->mutex);
 
 
95720 applyNumericAffinity(pMem, 0);
95721 sqlite3_mutex_leave(pMem->db->mutex);
95722 eType = sqlite3_value_type(pVal);
95723 }
95724 return eType;
95725 }
95726
@@ -102423,15 +102612,22 @@
102423 goto abort_due_to_error;
102424 }
102425 break;
102426 }
102427
102428 /* Opcode: ParseSchema P1 * * P4 *
102429 **
102430 ** Read and parse all entries from the schema table of database P1
102431 ** that match the WHERE clause P4. If P4 is a NULL pointer, then the
102432 ** entire schema for P1 is reparsed.
 
 
 
 
 
 
 
102433 **
102434 ** This opcode invokes the parser to create a new virtual machine,
102435 ** then runs the new virtual machine. It is thus a re-entrant opcode.
102436 */
102437 case OP_ParseSchema: {
@@ -102456,18 +102652,20 @@
102456 || db->mallocFailed
102457 || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) );
102458
102459 #ifndef SQLITE_OMIT_ALTERTABLE
102460 if( pOp->p4.z==0 ){
 
102461 sqlite3SchemaClear(db->aDb[iDb].pSchema);
102462 db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
102463 rc = sqlite3InitOne(db, iDb, &p->zErrMsg, pOp->p5);
102464 db->mDbFlags |= DBFLAG_SchemaChange;
102465 p->expired = 0;
102466 }else
102467 #endif
102468 {
 
102469 zSchema = LEGACY_SCHEMA_TABLE;
102470 initData.db = db;
102471 initData.iDb = iDb;
102472 initData.pzErrMsg = &p->zErrMsg;
102473 initData.mInitFlags = 0;
@@ -109972,10 +110170,11 @@
109972 }
109973 extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
109974 pExpr->op = TK_FUNCTION;
109975 pExpr->u.zToken = "coalesce";
109976 pExpr->x.pList = pFJMatch;
 
109977 cnt = 1;
109978 goto lookupname_end;
109979 }else{
109980 sqlite3ExprListDelete(db, pFJMatch);
109981 pFJMatch = 0;
@@ -110137,10 +110336,30 @@
110137 sqlite3AtoF(p->u.zToken, &r);
110138 assert( r>=0.0 );
110139 if( r>1.0 ) return -1;
110140 return (int)(r*134217728.0);
110141 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110142
110143 /*
110144 ** This routine is callback for sqlite3WalkExpr().
110145 **
110146 ** Resolve symbolic names into TK_COLUMN operators for the current
@@ -110382,14 +110601,11 @@
110382 ** the function may return a value with a subtype back to its
110383 ** caller using sqlite3_result_value(). */
110384 if( (pDef->funcFlags & SQLITE_SUBTYPE)
110385 || ExprHasProperty(pExpr, EP_SubtArg)
110386 ){
110387 int ii;
110388 for(ii=0; ii<n; ii++){
110389 ExprSetProperty(pList->a[ii].pExpr, EP_SubtArg);
110390 }
110391 }
110392
110393 if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
110394 /* For the purposes of the EP_ConstFunc flag, date and time
110395 ** functions and other functions that change slowly are considered
@@ -110415,12 +110631,17 @@
110415 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
110416 ){
110417 /* Internal-use-only functions are disallowed unless the
110418 ** SQL is being compiled using sqlite3NestedParse() or
110419 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
110420 ** used to activate internal functions for testing purposes */
110421 no_such_func = 1;
 
 
 
 
 
110422 pDef = 0;
110423 }else
110424 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
110425 && !IN_RENAME_OBJECT
110426 ){
@@ -110460,13 +110681,20 @@
110460 sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr);
110461 pNC->nNcErr++;
110462 is_agg = 0;
110463 }
110464 #endif
110465 else if( no_such_func && pParse->db->init.busy==0
 
 
 
 
 
 
 
110466 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
110467 && pParse->explain==0
110468 #endif
110469 ){
110470 sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr);
110471 pNC->nNcErr++;
110472 }else if( wrong_num_args ){
@@ -111849,11 +112077,13 @@
111849 ** Return TRUE if the two expressions have equivalent collating sequences.
111850 */
111851 SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse *pParse, const Expr *pE1, const Expr *pE2){
111852 CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pE1);
111853 CollSeq *pColl2 = sqlite3ExprNNCollSeq(pParse, pE2);
111854 return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0;
 
 
111855 }
111856
111857 /*
111858 ** pExpr is an operand of a comparison operator. aff2 is the
111859 ** type affinity of the other operand. This routine returns the
@@ -116203,40 +116433,51 @@
116203 }
116204 return target;
116205 }
116206
116207 /*
116208 ** Expression Node callback for sqlite3ExprCanReturnSubtype().
116209 **
116210 ** Only a function call is able to return a subtype. So if the node
116211 ** is not a function call, return WRC_Prune immediately.
116212 **
116213 ** A function call is able to return a subtype if it has the
116214 ** SQLITE_RESULT_SUBTYPE property.
116215 **
116216 ** Assume that every function is able to pass-through a subtype from
116217 ** one of its argument (using sqlite3_result_value()). Most functions
116218 ** are not this way, but we don't have a mechanism to distinguish those
116219 ** that are from those that are not, so assume they all work this way.
116220 ** That means that if one of its arguments is another function and that
116221 ** other function is able to return a subtype, then this function is
116222 ** able to return a subtype.
 
 
 
 
 
 
116223 */
116224 static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
116225 int n;
116226 FuncDef *pDef;
116227 sqlite3 *db;
 
 
 
 
 
116228 if( pExpr->op!=TK_FUNCTION ){
116229 return WRC_Prune;
116230 }
116231 assert( ExprUseXList(pExpr) );
116232 db = pWalker->pParse->db;
116233 n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
116234 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
116235 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
116236 pWalker->eCode = 1;
116237 return WRC_Prune;
116238 }
116239 return WRC_Continue;
116240 }
116241
116242 /*
@@ -122210,23 +122451,35 @@
122210 SQLITE_PRIVATE void sqlite3AlterAddConstraint(
122211 Parse *pParse, /* Parse context */
122212 SrcList *pSrc, /* Table to add constraint to */
122213 Token *pFirst, /* First token of new constraint */
122214 Token *pName, /* Name of new constraint. NULL if name omitted. */
122215 const char *pExpr, /* Text of CHECK expression */
122216 int nExpr /* Size of pExpr in bytes */
 
122217 ){
122218 Table *pTab = 0; /* Table identified by pSrc */
122219 int iDb = 0; /* Which schema does pTab live in */
122220 const char *zDb = 0; /* Name of the schema in which pTab lives */
122221 const char *pCons = 0; /* Text of the constraint */
122222 int nCons; /* Bytes of text to use from pCons[] */
 
122223
122224 /* Look up the table being altered. */
122225 assert( pSrc->nSrc==1 );
122226 pTab = alterFindTable(pParse, pSrc, &iDb, &zDb, 1);
122227 if( !pTab ) return;
 
 
 
 
 
 
 
 
 
 
122228
122229 /* If this new constraint has a name, check that it is not a duplicate of
122230 ** an existing constraint. It is an error if it is. */
122231 if( pName ){
122232 char *zName = sqlite3NameFromToken(pParse->db, pName);
@@ -122243,11 +122496,11 @@
122243
122244 /* Search for a constraint violation. Throw an exception if one is found. */
122245 sqlite3NestedParse(pParse,
122246 "SELECT sqlite_fail('constraint failed', %d) "
122247 "FROM %Q.%Q WHERE (%.*s) IS NOT TRUE",
122248 SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, pExpr
122249 );
122250
122251 /* Edit the SQL for the named table. */
122252 pCons = pFirst->z;
122253 nCons = alterRtrimConstraint(pParse->db, pCons, pParse->sLastToken.z - pCons);
@@ -125929,10 +126182,23 @@
125929 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
125930 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
125931 return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
125932 }
125933
 
 
 
 
 
 
 
 
 
 
 
 
 
125934 /*
125935 ** Set the collating sequence name for a column.
125936 */
125937 SQLITE_PRIVATE void sqlite3ColumnSetColl(
125938 sqlite3 *db,
@@ -125953,10 +126219,15 @@
125953 pCol->zCnName = zNew;
125954 memcpy(pCol->zCnName + n, zColl, nColl);
125955 pCol->colFlags |= COLFLAG_HASCOLL;
125956 }
125957 }
 
 
 
 
 
125958
125959 /*
125960 ** Return the collating sequence name for a column
125961 */
125962 SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){
@@ -134599,15 +134870,20 @@
134599 ** to initialize it */
134600 if( ALWAYS(p) && type!=SQLITE_NULL ){
134601 assert( p->cnt>0 );
134602 p->cnt--;
134603 if( !p->approx ){
134604 if( sqlite3SubInt64(&p->iSum, sqlite3_value_int64(argv[0])) ){
134605 p->ovrfl = 1;
134606 p->approx = 1;
 
134607 }
134608 }else if( type==SQLITE_INTEGER ){
 
 
 
 
134609 i64 iVal = sqlite3_value_int64(argv[0]);
134610 if( iVal!=SMALLEST_INT64 ){
134611 kahanBabuskaNeumaierStepInt64(p, -iVal);
134612 }else{
134613 kahanBabuskaNeumaierStepInt64(p, LARGEST_INT64);
@@ -140569,10 +140845,48 @@
140569 }
140570
140571 /* If no test above fails then the indices must be compatible */
140572 return 1;
140573 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140574
140575 /*
140576 ** Attempt the transfer optimization on INSERTs of the form
140577 **
140578 ** INSERT INTO tab1 SELECT * FROM tab2;
@@ -140696,12 +141010,23 @@
140696 return 0; /* Number of columns must be the same in tab1 and tab2 */
140697 }
140698 if( pDest->iPKey!=pSrc->iPKey ){
140699 return 0; /* Both tables must have the same INTEGER PRIMARY KEY */
140700 }
140701 if( (pDest->tabFlags & TF_Strict)!=0 && (pSrc->tabFlags & TF_Strict)==0 ){
140702 return 0; /* Cannot feed from a non-strict into a strict table */
 
 
 
 
 
 
 
 
 
 
 
140703 }
140704 for(i=0; i<pDest->nCol; i++){
140705 Column *pDestCol = &pDest->aCol[i];
140706 Column *pSrcCol = &pSrc->aCol[i];
140707 #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
@@ -140791,11 +141116,11 @@
140791 }
140792 }
140793 #ifndef SQLITE_OMIT_CHECK
140794 if( pDest->pCheck
140795 && (db->mDbFlags & DBFLAG_Vacuum)==0
140796 && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1)
140797 ){
140798 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
140799 }
140800 #endif
140801 #ifndef SQLITE_OMIT_FOREIGN_KEY
@@ -140812,10 +141137,22 @@
140812 }
140813 #endif
140814 if( (db->flags & SQLITE_CountRows)!=0 ){
140815 return 0; /* xfer opt does not play well with PRAGMA count_changes */
140816 }
 
 
 
 
 
 
 
 
 
 
 
 
140817
140818 /* If we get this far, it means that the xfer optimization is at
140819 ** least a possibility, though it might only work if the destination
140820 ** table (tab1) is initially empty.
140821 */
@@ -146810,11 +147147,17 @@
146810 assert( iDb>=0 && iDb<db->nDb );
146811 assert( db->aDb[iDb].pSchema );
146812 assert( sqlite3_mutex_held(db->mutex) );
146813 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
146814
146815 db->init.busy = 1;
 
 
 
 
 
 
146816
146817 /* Construct the in-memory representation schema tables (sqlite_schema or
146818 ** sqlite_temp_schema) by invoking the parser directly. The appropriate
146819 ** table name will be inserted automatically by the parser so we can just
146820 ** use the abbreviation "x" here. The parser will also automatically tag
@@ -164903,11 +165246,11 @@
164903
164904 /* Set up a new SrcList in pOrTab containing the table being scanned
164905 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
164906 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
164907 */
164908 if( pWInfo->nLevel>1 ){
164909 int nNotReady; /* The number of notReady tables */
164910 SrcItem *origSrc; /* Original list of tables */
164911 nNotReady = pWInfo->nLevel - iLevel - 1;
164912 pOrTab = sqlite3DbMallocRawNN(db, SZ_SRCLIST(nNotReady+1));
164913 if( pOrTab==0 ) return notReady;
@@ -164916,10 +165259,17 @@
164916 memcpy(pOrTab->a, pTabItem, sizeof(*pTabItem));
164917 origSrc = pWInfo->pTabList->a;
164918 for(k=1; k<=nNotReady; k++){
164919 memcpy(&pOrTab->a[k], &origSrc[pLevel[k].iFrom], sizeof(pOrTab->a[k]));
164920 }
 
 
 
 
 
 
 
164921 }else{
164922 pOrTab = pWInfo->pTabList;
164923 }
164924
164925 /* Initialize the rowset register to contain NULL. An SQL NULL is
@@ -165159,11 +165509,11 @@
165159 ** indent everything in between the this point and the final OP_Return.
165160 ** See tag-20220407a in vdbe.c and shell.c */
165161 assert( pLevel->op==OP_Return );
165162 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
165163
165164 if( pWInfo->nLevel>1 ){ sqlite3DbFreeNN(db, pOrTab); }
165165 if( !untestedTerms ) disableTerm(pLevel, pTerm);
165166 }else
165167 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
165168
165169 {
@@ -166508,20 +166858,18 @@
166508 ** 1. The SQLITE_Transitive optimization must be enabled
166509 ** 2. Must be either an == or an IS operator
166510 ** 3. Not originating in the ON clause of an OUTER JOIN
166511 ** 4. The operator is not IS or else the query does not contain RIGHT JOIN
166512 ** 5. The affinities of A and B must be compatible
166513 ** 6a. Both operands use the same collating sequence OR
166514 ** 6b. The overall collating sequence is BINARY
166515 ** If this routine returns TRUE, that means that the RHS can be substituted
166516 ** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
166517 ** This is an optimization. No harm comes from returning 0. But if 1 is
166518 ** returned when it should not be, then incorrect answers might result.
166519 */
166520 static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){
166521 char aff1, aff2;
166522 CollSeq *pColl;
166523 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
166524 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
166525 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
166526 assert( pSrc!=0 );
166527 if( pExpr->op==TK_IS
@@ -166535,14 +166883,11 @@
166535 if( aff1!=aff2
166536 && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
166537 ){
166538 return 0; /* (5) */
166539 }
166540 pColl = sqlite3ExprCompareCollSeq(pParse, pExpr);
166541 if( !sqlite3IsBinary(pColl)
166542 && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight)
166543 ){
166544 return 0; /* (6) */
166545 }
166546 return 1;
166547 }
166548
@@ -166870,11 +167215,11 @@
166870
166871 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
166872 /* Analyze a term that is composed of two or more subterms connected by
166873 ** an OR operator.
166874 */
166875 else if( pExpr->op==TK_OR ){
166876 assert( pWC->op==TK_AND );
166877 exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
166878 pTerm = &pWC->a[idxTerm];
166879 }
166880 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
@@ -170589,13 +170934,14 @@
170589 pLoop->nOut--;
170590 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
170591 && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
170592 ){
170593 Expr *pRight = pOpExpr->pRight;
 
170594 int k = 0;
170595 testcase( pOpExpr->op==TK_IS );
170596 if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){
170597 k = 10;
170598 }else{
170599 k = 20;
170600 }
170601 if( iReduce<k ){
@@ -170688,11 +171034,12 @@
170688 testcase( pLhs->iColumn==XN_ROWID );
170689 aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs));
170690 idxaff = sqlite3TableColumnAffinity(pIdx->pTable, pLhs->iColumn);
170691 if( aff!=idxaff ) break;
170692
170693 pColl = sqlite3ExprCompareCollSeq(pParse, pTerm->pExpr);
 
170694 if( pColl==0 ) break;
170695 if( sqlite3StrICmp(pColl->zName, pIdx->azColl[i+nEq]) ) break;
170696 }
170697 return i;
170698 }
@@ -183162,13 +183509,15 @@
183162 case 196: /* expr ::= LP nexprlist COMMA expr RP */
183163 {
183164 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy14, yymsp[-1].minor.yy454);
183165 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
183166 if( yymsp[-4].minor.yy454 ){
 
183167 yymsp[-4].minor.yy454->x.pList = pList;
183168 if( ALWAYS(pList->nExpr) ){
183169 yymsp[-4].minor.yy454->flags |= pList->a[0].pExpr->flags & EP_Propagate;
 
183170 }
183171 }else{
183172 sqlite3ExprListDelete(pParse->db, pList);
183173 }
183174 }
@@ -183632,19 +183981,17 @@
183632 sqlite3AlterSetNotNull(pParse, yymsp[-7].minor.yy203, &yymsp[-4].minor.yy0, &yymsp[-2].minor.yy0);
183633 }
183634 break;
183635 case 300: /* cmd ::= ALTER TABLE fullname ADD CONSTRAINT nm CHECK LP expr RP onconf */
183636 {
183637 sqlite3AlterAddConstraint(pParse, yymsp[-8].minor.yy203, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1));
183638 }
183639 yy_destructor(yypParser,219,&yymsp[-2].minor);
183640 break;
183641 case 301: /* cmd ::= ALTER TABLE fullname ADD CHECK LP expr RP onconf */
183642 {
183643 sqlite3AlterAddConstraint(pParse, yymsp[-6].minor.yy203, &yymsp[-4].minor.yy0, 0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1));
183644 }
183645 yy_destructor(yypParser,219,&yymsp[-2].minor);
183646 break;
183647 case 302: /* cmd ::= create_vtab */
183648 {sqlite3VtabFinishParse(pParse,0);}
183649 break;
183650 case 303: /* cmd ::= create_vtab LP vtabarglist RP */
@@ -199171,11 +199518,11 @@
199171 break;
199172
199173 /* State 3. The integer just read is a column number. */
199174 default: assert( eState==3 );
199175 iCol = (int)v;
199176 if( iCol<1 ){
199177 rc = SQLITE_CORRUPT_VTAB;
199178 break;
199179 }
199180 if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM;
199181 pCsr->aStat[iCol+1].nDoc++;
@@ -199861,10 +200208,11 @@
199861 /* If this is a "NEAR" keyword, check for an explicit nearness. */
199862 if( pKey->eType==FTSQUERY_NEAR ){
199863 assert( nKey==4 );
199864 if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
199865 nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear);
 
199866 }
199867 }
199868
199869 /* At this point this is probably a keyword. But for that to be true,
199870 ** the next byte must contain either whitespace, an open or close
@@ -209724,11 +210072,11 @@
209724 int nHit = fts3ColumnlistCount(&pIter);
209725 if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
209726 if( p->flag==FTS3_MATCHINFO_LHITS ){
209727 p->aMatchinfo[iStart + iCol] = (u32)nHit;
209728 }else if( nHit ){
209729 p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
209730 }
209731 }
209732 assert( *pIter==0x00 || *pIter==0x01 );
209733 if( *pIter!=0x01 ) break;
209734 pIter++;
@@ -213744,11 +214092,11 @@
213744 break;
213745 case '\n':
213746 break;
213747 case 0xe2:
213748 /* '\' followed by either U+2028 or U+2029 is ignored as
213749 ** whitespace. Not that in UTF8, U+2028 is 0xe2 0x80 0x29.
213750 ** U+2029 is the same except for the last byte */
213751 if( sz2<4
213752 || 0x80!=(u8)zIn[2]
213753 || (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3])
213754 ){
@@ -216313,15 +216661,13 @@
216313 char c;
216314 JsonString *pStr;
216315 UNUSED_PARAMETER(argc);
216316 UNUSED_PARAMETER(argv);
216317 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216318 #ifdef NEVER
216319 /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
216320 ** always have been called to initialize it */
216321 if( NEVER(!pStr) ) return;
216322 #endif
216323 z = pStr->zBuf;
216324 for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
216325 if( c=='"' ){
216326 inStr = !inStr;
216327 }else if( c=='\\' ){
@@ -216346,10 +216692,17 @@
216346
216347 /*
216348 ** json_group_obj(NAME,VALUE)
216349 **
216350 ** Return a JSON object composed of all names and values in the aggregate.
 
 
 
 
 
 
 
216351 */
216352 static void jsonObjectStep(
216353 sqlite3_context *ctx,
216354 int argc,
216355 sqlite3_value **argv
@@ -216363,49 +216716,97 @@
216363 z = (const char*)sqlite3_value_text(argv[0]);
216364 n = sqlite3Strlen30(z);
216365 if( pStr->zBuf==0 ){
216366 jsonStringInit(pStr, ctx);
216367 jsonAppendChar(pStr, '{');
216368 }else if( pStr->nUsed>1 && z!=0 ){
216369 jsonAppendChar(pStr, ',');
216370 }
216371 pStr->pCtx = ctx;
216372 if( z!=0 ){
216373 jsonAppendString(pStr, z, n);
216374 jsonAppendChar(pStr, ':');
216375 jsonAppendSqlValue(pStr, argv[1]);
 
 
 
216376 }
216377 }
216378 }
216379 static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
216380 JsonString *pStr;
216381 int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216382 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216383 if( pStr ){
216384 jsonAppendRawNZ(pStr, "}", 2);
216385 jsonStringTrimOneChar(pStr);
 
 
216386 pStr->pCtx = ctx;
216387 if( pStr->eErr ){
216388 jsonReturnString(pStr, 0, 0);
216389 return;
216390 }else if( flags & JSON_BLOB ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216391 jsonReturnStringAsBlob(pStr);
216392 if( isFinal ){
216393 if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
216394 }else{
216395 jsonStringTrimOneChar(pStr);
216396 }
216397 return;
216398 }else if( isFinal ){
216399 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
216400 pStr->bStatic ? SQLITE_TRANSIENT :
216401 sqlite3RCStrUnref);
216402 pStr->bStatic = 1;
216403 }else{
216404 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
216405 jsonStringTrimOneChar(pStr);
216406 }
 
216407 }else if( flags & JSON_BLOB ){
216408 static const unsigned char emptyObject = 0x0c;
216409 sqlite3_result_blob(ctx, &emptyObject, 1, SQLITE_STATIC);
216410 }else{
216411 sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC);
@@ -218751,11 +219152,14 @@
218751 while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
218752 u8 *pCellData;
218753 pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc);
218754 if( rc ) return rc;
218755 nCell = NCELL(pNode);
218756 assert( nCell<200 );
 
 
 
218757 pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell);
218758 while( p->iCell<nCell ){
218759 sqlite3_rtree_dbl rScore = (sqlite3_rtree_dbl)-1;
218760 eWithin = FULLY_WITHIN;
218761 for(ii=0; ii<nConstraint; ii++){
@@ -223781,11 +224185,11 @@
223781 */
223782 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
223783 const UChar *zInput; /* Pointer to input string */
223784 UChar *zOutput = 0; /* Pointer to output buffer */
223785 int nInput; /* Size of utf-16 input string in bytes */
223786 int nOut; /* Size of output buffer in bytes */
223787 int cnt;
223788 int bToUpper; /* True for toupper(), false for tolower() */
223789 UErrorCode status;
223790 const char *zLocale = 0;
223791
@@ -223804,22 +224208,22 @@
223804 sqlite3_result_text16(p, "", 0, SQLITE_STATIC);
223805 return;
223806 }
223807
223808 for(cnt=0; cnt<2; cnt++){
223809 UChar *zNew = sqlite3_realloc(zOutput, nOut);
223810 if( zNew==0 ){
223811 sqlite3_free(zOutput);
223812 sqlite3_result_error_nomem(p);
223813 return;
223814 }
223815 zOutput = zNew;
223816 status = U_ZERO_ERROR;
223817 if( bToUpper ){
223818 nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
223819 }else{
223820 nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
223821 }
223822
223823 if( U_SUCCESS(status) ){
223824 sqlite3_result_text16(p, zOutput, nOut, xFree);
223825 }else if( status==U_BUFFER_OVERFLOW_ERROR ){
@@ -231535,16 +231939,17 @@
231535 if( NEVER(pBt==0) ) return SQLITE_OK;
231536 pCsr->pPager = sqlite3BtreePager(pBt);
231537 pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
231538 pCsr->mxPgno = sqlite3BtreeLastPage(pBt);
231539 if( idxNum & 1 ){
 
231540 assert( argc>(idxNum>>1) );
231541 pCsr->pgno = sqlite3_value_int(argv[idxNum>>1]);
231542 if( pCsr->pgno<1 || pCsr->pgno>pCsr->mxPgno ){
231543 pCsr->pgno = 1;
231544 pCsr->mxPgno = 0;
231545 }else{
 
231546 pCsr->mxPgno = pCsr->pgno;
231547 }
231548 }else{
231549 assert( pCsr->pgno==1 );
231550 }
@@ -231620,10 +232025,11 @@
231620 sqlite3_value **argv,
231621 sqlite_int64 *pRowid
231622 ){
231623 DbpageTable *pTab = (DbpageTable *)pVtab;
231624 Pgno pgno;
 
231625 DbPage *pDbPage = 0;
231626 int rc = SQLITE_OK;
231627 char *zErr = 0;
231628 int iDb;
231629 Btree *pBt;
@@ -231639,15 +232045,15 @@
231639 if( argc==1 ){
231640 zErr = "cannot delete";
231641 goto update_fail;
231642 }
231643 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
231644 pgno = (Pgno)sqlite3_value_int64(argv[2]);
231645 isInsert = 1;
231646 }else{
231647 pgno = (Pgno)sqlite3_value_int64(argv[0]);
231648 if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){
231649 zErr = "cannot insert";
231650 goto update_fail;
231651 }
231652 isInsert = 0;
231653 }
@@ -231660,14 +232066,15 @@
231660 zErr = "no such schema";
231661 goto update_fail;
231662 }
231663 }
231664 pBt = pTab->db->aDb[iDb].pBt;
231665 if( pgno<1 || NEVER(pBt==0) ){
231666 zErr = "bad page number";
231667 goto update_fail;
231668 }
 
231669 szPage = sqlite3BtreeGetPageSize(pBt);
231670 if( sqlite3_value_type(argv[3])!=SQLITE_BLOB
231671 || sqlite3_value_bytes(argv[3])!=szPage
231672 ){
231673 if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){
@@ -232688,11 +233095,13 @@
232688 /*
232689 ** Read a varint value from aBuf[] into *piVal. Return the number of
232690 ** bytes read.
232691 */
232692 static int sessionVarintGet(const u8 *aBuf, int *piVal){
232693 return getVarint32(aBuf, *piVal);
 
 
232694 }
232695
232696 /*
232697 ** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal.
232698 ** Return the number of bytes read.
@@ -232703,11 +233112,11 @@
232703 memset(aCopy, 0, sizeof(aCopy));
232704 if( nBuf<sizeof(aCopy) ){
232705 memcpy(aCopy, aBuf, nBuf);
232706 aRead = aCopy;
232707 }
232708 return getVarint32(aRead, *piVal);
232709 }
232710
232711 /* Load an unaligned and unsigned 32-bit integer */
232712 #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
232713
@@ -234479,11 +234888,11 @@
234479
234480 if( zStmt==0 ){
234481 rc = SQLITE_NOMEM;
234482 }else{
234483 sqlite3_stmt *pStmt;
234484 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
234485 if( rc==SQLITE_OK ){
234486 SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
234487 pDiffCtx->pStmt = pStmt;
234488 pDiffCtx->nOldOff = 0;
234489 pDiffCtx->bRowid = pTab->bRowid;
@@ -234542,11 +234951,11 @@
234542 );
234543 if( zStmt==0 || z1==0 || z2==0 ){
234544 rc = SQLITE_NOMEM;
234545 }else{
234546 sqlite3_stmt *pStmt;
234547 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
234548
234549 if( rc==SQLITE_OK ){
234550 SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
234551 pDiffCtx->pStmt = pStmt;
234552 pDiffCtx->nOldOff = pTab->nCol;
@@ -236036,21 +236445,25 @@
236036 int i;
236037 for(i=0; rc==SQLITE_OK && i<nCol; i++){
236038 int eType;
236039 rc = sessionInputBuffer(pIn, nByte + 10);
236040 if( rc==SQLITE_OK ){
236041 eType = pIn->aData[pIn->iNext + nByte++];
236042 if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
236043 int n;
236044 int nRem = pIn->nData - (pIn->iNext + nByte);
236045 nByte += sessionVarintGetSafe(&pIn->aData[pIn->iNext+nByte], nRem, &n);
236046 nByte += n;
236047 rc = sessionInputBuffer(pIn, nByte);
236048 }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
236049 nByte += 8;
236050 }else if( eType!=0 && eType!=SQLITE_NULL ){
236051 rc = SQLITE_CORRUPT_BKPT;
 
 
 
 
 
 
 
 
 
 
 
 
 
236052 }
236053 }
236054 if( rc==SQLITE_OK && (pIn->iNext+nByte)>pIn->nData ){
236055 rc = SQLITE_CORRUPT_BKPT;
236056 }
@@ -237386,11 +237799,11 @@
237386
237387 /* Bind values to the UPDATE statement. */
237388 for(i=0; rc==SQLITE_OK && i<nCol; i++){
237389 sqlite3_value *pOld = sessionChangesetOld(pIter, i);
237390 sqlite3_value *pNew = sessionChangesetNew(pIter, i);
237391 if( p->abPK[i] || (bPatchset==0 && pOld) ){
237392 rc = sessionBindValue(pUp, i*2+2, pOld);
237393 }
237394 if( rc==SQLITE_OK && pNew ){
237395 rc = sessionBindValue(pUp, i*2+1, pNew);
237396 }
@@ -239447,10 +239860,11 @@
239447 sqlite3_changegroup *pGrp,
239448 int bDiscard,
239449 char **pzErr
239450 ){
239451 int rc = SQLITE_OK;
 
239452 if( pGrp->cd.pTab ){
239453 SessionBuffer *aBuf = pGrp->cd.aBuf;
239454 int ii;
239455
239456 if( bDiscard==0 ){
@@ -239458,26 +239872,26 @@
239458 u8 eUndef = SQLITE_NULL;
239459 if( pGrp->cd.eOp==SQLITE_UPDATE ){
239460 for(ii=0; ii<nBuf; ii++){
239461 if( pGrp->cd.pTab->abPK[ii] ){
239462 if( aBuf[ii].nBuf<=1 ){
239463 *pzErr = sqlite3_mprintf(
239464 "invalid change: %s value in PK of old.* record",
239465 aBuf[ii].nBuf==1 ? "null" : "undefined"
239466 );
239467 rc = SQLITE_ERROR;
239468 break;
239469 }else if( aBuf[ii + nBuf].nBuf>0 ){
239470 *pzErr = sqlite3_mprintf(
239471 "invalid change: defined value in PK of new.* record"
239472 );
239473 rc = SQLITE_ERROR;
239474 break;
239475 }
239476 }else
239477 if( pGrp->bPatch==0 && (aBuf[ii].nBuf>0)!=(aBuf[ii+nBuf].nBuf>0) ){
239478 *pzErr = sqlite3_mprintf(
239479 "invalid change: column %d "
239480 "- old.* value is %sdefined but new.* is %sdefined",
239481 ii, aBuf[ii].nBuf ? "" : "un", aBuf[ii+nBuf].nBuf ? "" : "un"
239482 );
239483 rc = SQLITE_ERROR;
@@ -239490,18 +239904,18 @@
239490 for(ii=0; ii<nBuf; ii++){
239491 int isPK = pGrp->cd.pTab->abPK[ii];
239492 if( (pGrp->cd.eOp==SQLITE_INSERT || pGrp->bPatch==0 || isPK)
239493 && aBuf[ii].nBuf==0
239494 ){
239495 *pzErr = sqlite3_mprintf(
239496 "invalid change: column %d is undefined", ii
239497 );
239498 rc = SQLITE_ERROR;
239499 break;
239500 }
239501 if( aBuf[ii].nBuf==1 && isPK ){
239502 *pzErr = sqlite3_mprintf(
239503 "invalid change: null value in PK"
239504 );
239505 rc = SQLITE_ERROR;
239506 break;
239507 }
@@ -239547,10 +239961,15 @@
239547 }
239548 }
239549 pGrp->cd.pTab = 0;
239550 }
239551
 
 
 
 
 
239552 return rc;
239553 }
239554
239555 #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */
239556
@@ -250006,11 +250425,11 @@
250006 }
250007
250008 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
250009 Fts5Data *pRet = fts5DataRead(p, iRowid);
250010 if( pRet ){
250011 if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
250012 FTS5_CORRUPT_ROWID(p, iRowid);
250013 fts5DataRelease(pRet);
250014 pRet = 0;
250015 }
250016 }
@@ -251660,10 +252079,14 @@
251660 /* Figure out how many new bytes are in this term */
251661 fts5FastGetVarint32(a, iOff, nNew);
251662 if( nKeep<nMatch ){
251663 goto search_failed;
251664 }
 
 
 
 
251665
251666 assert( nKeep>=nMatch );
251667 if( nKeep==nMatch ){
251668 u32 nCmp;
251669 u32 i;
@@ -252786,11 +253209,11 @@
252786 }
252787
252788 /* Advance pointer p until it points to pEnd or an 0x01 byte that is
252789 ** not part of a varint */
252790 while( p<pEnd && *p!=0x01 ){
252791 while( *p++ & 0x80 );
252792 }
252793
252794 if( pColset->aiCol[i]==iCurrent ){
252795 if( pColset->nCol==1 ){
252796 pIter->base.pData = aCopy;
@@ -262254,11 +262677,11 @@
262254 int nArg, /* Number of args */
262255 sqlite3_value **apUnused /* Function arguments */
262256 ){
262257 assert( nArg==0 );
262258 UNUSED_PARAM2(nArg, apUnused);
262259 sqlite3_result_text(pCtx, "fts5: 2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb", -1, SQLITE_TRANSIENT);
262260 }
262261
262262 /*
262263 ** Implementation of fts5_locale(LOCALE, TEXT) function.
262264 **
@@ -264648,12 +265071,18 @@
264648 PorterTokenizer *pRet;
264649 void *pUserdata = 0;
264650 const char *zBase = "unicode61";
264651 fts5_tokenizer_v2 *pV2 = 0;
264652
264653 if( nArg>0 ){
264654 zBase = azArg[0];
 
 
 
 
 
 
264655 }
264656
264657 pRet = (PorterTokenizer*)sqlite3_malloc64(sizeof(PorterTokenizer));
264658 if( pRet ){
264659 memset(pRet, 0, sizeof(PorterTokenizer));
264660
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 9ac4a33a2932d353c4871fd8e09c10addf82 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-05-21 15:14:35 9ac4a33a2932d353c4871fd8e09c10addf827f1fc3fc9380037d738cf2cd0353"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-05-21T15:14:35.420Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -4373,12 +4373,11 @@
4373 ** parameter on F or if the value of P does not match any of the
4374 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4375 **
4376 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4377 ** 64-bit signed integer and returns that integer, or D if P does not
4378 ** exist or ff the value of P is something other than an integer.
 
4379 **
4380 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4381 ** the value) of the N-th query parameter for filename F, or a NULL
4382 ** pointer if N is less than zero or greater than the number of query
4383 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
@@ -18705,11 +18704,11 @@
18704 int aLimit[SQLITE_N_LIMIT]; /* Limits */
18705 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
18706 struct sqlite3InitInfo { /* Information used during initialization */
18707 Pgno newTnum; /* Rootpage of table being initialized */
18708 u8 iDb; /* Which db file is being initialized */
18709 u8 busy; /* TRUE if initing. 2 if due to ADD COLUMN */
18710 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
18711 unsigned imposterTable : 2; /* Building an imposter table */
18712 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
18713 const char **azInit; /* "type", "name", and "tbl_name" columns */
18714 } init;
@@ -21256,11 +21255,11 @@
21255 */
21256 #define INITFLAG_AlterMask 0x0007 /* Types of ALTER */
21257 #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
21258 #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
21259 #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
21260 #define INITFLAG_AlterDropCons 0x0004 /* Reparse after a DROP CONSTRAINT */
21261
21262 /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
21263 ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
21264 ** parameters are for temporary use during development, to help find
21265 ** optimal values for parameters in the query planner. The should not
@@ -22509,11 +22508,19 @@
22508 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
22509 SQLITE_PRIVATE void sqlite3AlterFunctions(void);
22510 SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
22511 SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
22512 SQLITE_PRIVATE void sqlite3AlterDropConstraint(Parse*,SrcList*,Token*,Token*);
22513 SQLITE_PRIVATE void sqlite3AlterAddConstraint(
22514 Parse *pParse, /* Parse context */
22515 SrcList *pSrc, /* Table to add constraint to */
22516 Token *pFirst, /* First token of new constraint */
22517 Token *pName, /* Name of new constraint. NULL if name omitted. */
22518 const char *zExpr, /* Text of CHECK expression */
22519 int nExpr, /* Size of pExpr in bytes */
22520 Expr *pExpr /* The parsed CHECK expression */
22521 );
22522 SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*);
22523 SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *);
22524 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
22525 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
22526 SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
@@ -32413,12 +32420,14 @@
32420 #define etSRCITEM 12 /* a pointer to a SrcItem */
32421 #define etPOINTER 13 /* The %p conversion */
32422 #define etESCAPE_w 14 /* %w -> Strings with '\"' doubled */
32423 #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
32424 #define etDECIMAL 16 /* %d or %u, but not %x, %o */
32425 #define etESCAPE_j 17 /* %j -> JSON string literal w/o "..." */
32426 #define etESCAPE_J 18 /* %J -> JSON string literal with "..." */
32427
32428 #define etINVALID 19 /* Any unrecognized conversion type */
32429
32430
32431 /*
32432 ** An "etByte" is an 8-bit unsigned value.
32433 */
@@ -32444,24 +32453,24 @@
32453 #define FLAG_SIGNED 1 /* True if the value to convert is signed */
32454 #define FLAG_STRING 4 /* Allow infinite precision */
32455
32456 /*
32457 ** The table is searched by hash. In the case of %C where C is the character
32458 ** and that character has ASCII value j, then the hash is j%25.
32459 **
32460 ** The order of the entries in fmtinfo[] and the hash chain was entered
32461 ** manually, but based on the output of the following TCL script:
32462 */
32463 #if 0 /***** Beginning of script ******/
32464 foreach c {d s g z q Q w c o u x X f e E G i n % p T S r J j} {
32465 scan $c %c x
32466 set n($c) $x
32467 }
32468 set mx [llength [array names n]]
32469 puts "count: $mx"
32470
32471 set mx 25
32472 puts "*********** mx=$mx ************"
32473 for {set r 0} {$r<$mx} {incr r} {
32474 puts -nonewline [format %2d: $r]
32475 foreach c [array names n] {
32476 if {($n($c))%$mx==$r} {puts -nonewline " $c"}
@@ -32469,35 +32478,38 @@
32478 puts ""
32479 }
32480 #endif /***** End of script ********/
32481
32482 static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
32483 static const char aHex[] = "0123456789abcdef";
32484 static const char aPrefix[] = "-x0\000X0";
32485 static const et_info fmtinfo[25] = {
32486 /* 0 */ { 'd', 10, 1, etDECIMAL, 0, 0, 0 },
32487 /* 1 */ { 'e', 0, 1, etEXP, 30, 0, 0 },
32488 /* 2 */ { 'f', 0, 1, etFLOAT, 0, 0, 0 },
32489 /* 3 */ { 'g', 0, 1, etGENERIC, 30, 0, 0 },
32490 /* 4 */ { 'j', 0, 0, etESCAPE_j, 0, 0, 0 }, /* Hash: 6 */
32491 /* 5 */ { 'i', 10, 1, etDECIMAL, 0, 0, 0 },
32492 /* 6 */ { 'Q', 0, 4, etESCAPE_Q, 0, 0, 4 },
32493 /* 7 */ { 'p', 16, 0, etPOINTER, 0, 1, 0 }, /* Hash: 12 */
32494 /* 8 */ { 'S', 0, 0, etSRCITEM, 0, 0, 0 },
32495 /* 9 */ { 'T', 0, 0, etTOKEN, 0, 0, 0 },
32496 /* 10 */ { 'n', 0, 0, etSIZE, 0, 0, 0 },
32497 /* 11 */ { 'o', 8, 0, etRADIX, 0, 2, 0 },
32498 /* 12 */ { '%', 0, 0, etPERCENT, 0, 0, 7 },
32499 /* 13 */ { 'q', 0, 4, etESCAPE_q, 0, 0, 16 },
32500 /* 14 */ { 'r', 10, 1, etORDINAL, 0, 0, 0 },
32501 /* 15 */ { 's', 0, 4, etSTRING, 0, 0, 0 },
32502 /* 16 */ { 'X', 16, 0, etRADIX, 0, 4, 0 }, /* Hash: 13 */
32503 /* 17 */ { 'u', 10, 0, etDECIMAL, 0, 0, 0 },
32504 /* 18 */ { 'w', 0, 4, etESCAPE_w, 0, 0, 0 }, /* Hash: 19 */
32505 /* 19 */ { 'E', 0, 1, etEXP, 14, 0, 18 },
32506 /* 20 */ { 'x', 16, 0, etRADIX, 16, 1, 0 },
32507 /* 21 */ { 'G', 0, 1, etGENERIC, 14, 0, 0 },
32508 /* 22 */ { 'z', 0, 4, etDYNSTRING, 0, 0, 0 },
32509 /* 23 */ { 'J', 0, 0, etESCAPE_J, 0, 0, 0 }, /* Hash: 24 */
32510 /* 24 */ { 'c', 0, 0, etCHARX, 0, 0, 23 }
32511 };
32512
32513 /* Additional Notes:
32514 **
32515 ** %S Takes a pointer to SrcItem. Shows name or database.name
@@ -32754,12 +32766,12 @@
32766 break;
32767 }
32768 }
32769 #else
32770 /* Fast hash-table lookup */
32771 assert( ArraySize(fmtinfo)==25 );
32772 idx = ((unsigned)c) % 25;
32773 if( fmtinfo[idx].fmttype==c
32774 || fmtinfo[idx = fmtinfo[idx].iNxt].fmttype==c
32775 ){
32776 infop = &fmtinfo[idx];
32777 xtype = infop->type;
@@ -33126,11 +33138,11 @@
33138 length = width;
33139 }
33140
33141 if( zExtra==0 ){
33142 /* The result is being rendered directory into pAccum. This
33143 ** is the common and fast case */
33144 pAccum->nChar += length;
33145 zOut[length] = 0;
33146 continue;
33147 }else{
33148 /* We were unable to render directly into pAccum because we
@@ -33246,10 +33258,87 @@
33258 /* Adjust width to account for extra bytes in UTF-8 characters */
33259 int ii = length - 1;
33260 while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++;
33261 }
33262 break;
33263 case etESCAPE_j: /* %j: JSON string literal w/o "..." */
33264 case etESCAPE_J: { /* %J: Generate a JSON string literal */
33265 char *escarg;
33266 i64 i, j, px, iStart;
33267 unsigned char ch;
33268
33269 if( bArgList ){
33270 escarg = getTextArg(pArgList);
33271 }else{
33272 escarg = va_arg(ap,char*);
33273 }
33274 iStart = sqlite3_str_length(pAccum);
33275 if( escarg==0 ){
33276 if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "null", 4);
33277 }else{
33278 if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1);
33279 px = precision;
33280 testcase( px==0 );
33281 if( px<0 ){
33282 px = 0x7fffffff;
33283 }else if( flag_altform2 ){
33284 /* Convert precision from code-points to bytes */
33285 for(i=0; i<px && escarg[i]; i++){
33286 if( (escarg[i]&0xc0)==0x80 ) px++;
33287 }
33288 if( i==px ){
33289 while( (escarg[px]&0xc0)==0x80 ) px++;
33290 }
33291 }
33292 for(i=j=0; i<px; i++){
33293 if( (ch = ((u8*)escarg)[i])<=0x1f || ch=='"' || ch=='\\' ){
33294 if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j);
33295 j = i+1;
33296 if( ch==0 ) break;
33297 sqlite3_str_appendchar(pAccum, 1, '\\');
33298 if( ch>0x1f ){
33299 sqlite3_str_appendchar(pAccum, 1, ch);
33300 }else if( ((1u<<ch)&0x3700)!=0 ){
33301 ch = "btn?fr"[ch-8];
33302 sqlite3_str_appendchar(pAccum, 1, ch);
33303 }else{
33304 sqlite3_str_append(pAccum, "u00", 3);
33305 sqlite3_str_appendchar(pAccum, 1, aHex[ch>>4]);
33306 sqlite3_str_appendchar(pAccum, 1, aHex[ch&0xf]);
33307 }
33308 }
33309 }
33310 if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j);
33311 if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1);
33312 }
33313 if( width>0 && sqlite3_str_errcode(pAccum)==SQLITE_OK ){
33314 sqlite3_int64 n = sqlite3_str_length(pAccum) - iStart;
33315 sqlite3_int64 len = n;
33316 char *zz;
33317 if( flag_altform2 && n>0 ){
33318 zz = sqlite3_str_value(pAccum);
33319 for(i=iStart; zz[i]; i++){
33320 if( (zz[i]&0xc0)==0x80 ) len--;
33321 }
33322 }
33323 if( width>len ){
33324 sqlite3_int64 sp = width-len;
33325 assert( sp>0 && sp<0x7fffffff );
33326 sqlite3_str_appendchar(pAccum, (int)sp, ' ');
33327 if( !flag_leftjustify
33328 && n>0
33329 && sqlite3_str_errcode(pAccum)==0
33330 ){
33331 zz = sqlite3_str_value(pAccum);
33332 zz += iStart;
33333 memmove(zz+sp, zz, n);
33334 memset(zz, ' ', sp);
33335 }
33336 }
33337 }
33338 continue;
33339 }
33340 case etESCAPE_q: /* %q: Escape ' characters */
33341 case etESCAPE_Q: /* %Q: Escape ' and enclose in '...' */
33342 case etESCAPE_w: { /* %w: Escape " characters */
33343 i64 i, j, k, n;
33344 int needQuote = 0;
@@ -33337,11 +33426,11 @@
33426 bufpt[j-1] = '\\';
33427 bufpt[j++] = 'u';
33428 bufpt[j++] = '0';
33429 bufpt[j++] = '0';
33430 bufpt[j++] = ch>=0x10 ? '1' : '0';
33431 bufpt[j++] = aHex[ch&0xf];
33432 }
33433 }
33434 }else{
33435 for(i=0; i<k; i++){
33436 bufpt[j++] = ch = escarg[i];
@@ -45345,13 +45434,13 @@
45434
45435 /* Minimum number of regions required to be mapped. */
45436 nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap;
45437
45438 if( pShmNode->nRegion<nReqRegion ){
45439 char **apNew; /* New apRegion[] array */
45440 i64 nByte = nReqRegion*(i64)szRegion; /* Minimum required file size */
45441 struct stat sStat; /* Used by fstat() */
45442
45443 pShmNode->szRegion = szRegion;
45444
45445 if( pShmNode->hShm>=0 ){
45446 /* The requested region is not mapped into this processes address space.
@@ -45378,11 +45467,11 @@
45467 ** pages forces the OS to allocate them immediately, which reduces
45468 ** the chances of SIGBUS while accessing the mapped region later on.
45469 */
45470 else{
45471 static const int pgsz = 4096;
45472 i64 iPg;
45473
45474 /* Write to the last byte of each newly allocated or extended page */
45475 assert( (nByte % pgsz)==0 );
45476 for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){
45477 int x = 0;
@@ -45404,12 +45493,12 @@
45493 rc = SQLITE_IOERR_NOMEM_BKPT;
45494 goto shmpage_out;
45495 }
45496 pShmNode->apRegion = apNew;
45497 while( pShmNode->nRegion<nReqRegion ){
45498 i64 nMap = (i64)szRegion*(i64)nShmPerMap;
45499 i64 i;
45500 void *pMem;
45501 if( pShmNode->hShm>=0 ){
45502 pMem = osMmap(0, nMap,
45503 pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE,
45504 MAP_SHARED, pShmNode->hShm, szRegion*(i64)pShmNode->nRegion
@@ -49195,107 +49284,154 @@
49284
49285 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
49286 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
49287 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent)
49288
49289 #if defined(SQLITE_UWP)
49290 { "CreateFileMappingFromApp",(SYSCALL)CreateFileMappingFromApp,0 },
49291 #else
49292 { "CreateFileMappingFromApp",(SYSCALL)0, 0 },
49293 #endif
49294 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE,\
49295 PSECURITY_ATTRIBUTES, \
49296 ULONG,ULONG64,PCWSTR))aSyscall[3].pCurrent)
49297
49298 #if !defined(SQLITE_UWP)
49299 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
49300 #else
49301 { "CreateFileMappingW", (SYSCALL)0, 0 },
49302 #endif
49303 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
49304 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[4].pCurrent)
49305
49306 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
49307 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[5].pCurrent)
49308
49309 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
49310 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[6].pCurrent)
49311
49312 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
49313 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
49314 DWORD,va_list*))aSyscall[7].pCurrent)
49315
49316 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP)
49317 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
49318 #else
49319 { "FreeLibrary", (SYSCALL)0, 0 },
49320 #endif
49321
49322 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[8].pCurrent)
49323
49324 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
49325 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[9].pCurrent)
49326
49327 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
49328 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
49329
49330 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
49331 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
49332 LPVOID))aSyscall[11].pCurrent)
49333
49334 { "GetFileSizeEx", (SYSCALL)GetFileSizeEx, 0 },
49335 #define osGetFileSizeEx ((BOOL(WINAPI*)(HANDLE, \
49336 PLARGE_INTEGER))aSyscall[12].pCurrent)
49337
49338 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
49339 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
49340 LPWSTR*))aSyscall[13].pCurrent)
49341
49342 { "GetLastError", (SYSCALL)GetLastError, 0 },
49343 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[14].pCurrent)
49344
49345 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP)
49346 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
49347 #else
49348 { "GetProcAddressA", (SYSCALL)0, 0 },
49349 #endif
49350 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
49351 LPCSTR))aSyscall[15].pCurrent)
49352
49353 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
49354 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[16].pCurrent)
 
 
 
49355
49356 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
49357 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
49358 LPFILETIME))aSyscall[17].pCurrent)
49359
49360 #ifdef SQLITE_UWP
49361 { "GetTempPathW", (SYSCALL)0, 0 },
49362 #else
49363 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
49364 #endif
49365 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent)
49366
49367 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
49368 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[19].pCurrent)
49369
49370 #ifdef SQLITE_UWP
49371 { "HeapAlloc", (SYSCALL)0, 0 },
49372 #else
49373 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
49374 #endif
49375 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
49376 SIZE_T))aSyscall[20].pCurrent)
49377
49378 #ifdef SQLITE_UWP
49379 { "HeapCreate", (SYSCALL)0, 0 },
49380 #else
49381 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
49382 #endif
49383 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
49384 SIZE_T))aSyscall[21].pCurrent)
49385
49386 #ifdef SQLITE_UWP
49387 { "HeapDestroy", (SYSCALL)0, 0 },
49388 #else
49389 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
49390 #endif
49391 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent)
49392
49393 #ifdef SQLITE_UWP
49394 { "HeapFree", (SYSCALL)0, 0 },
49395 #else
49396 { "HeapFree", (SYSCALL)HeapFree, 0 },
49397 #endif
49398 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent)
49399
49400 #ifdef SQLITE_UWP
49401 { "HeapReAlloc", (SYSCALL)0, 0 },
49402 #else
49403 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
49404 #endif
49405 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
49406 SIZE_T))aSyscall[24].pCurrent)
49407
49408 #ifdef SQLITE_UWP
49409 { "HeapSize", (SYSCALL)0, 0 },
49410 #else
49411 { "HeapSize", (SYSCALL)HeapSize, 0 },
49412 #endif
49413 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
49414 LPCVOID))aSyscall[25].pCurrent)
49415
49416 #ifdef SQLITE_UWP
49417 { "HeapValidate", (SYSCALL)0, 0 },
49418 #else
49419 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
49420 #endif
49421 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
49422 LPCVOID))aSyscall[26].pCurrent)
49423
49424 #ifdef SQLITE_UWP
49425 { "HeapCompact", (SYSCALL)0, 0 },
49426 #else
49427 { "HeapCompact", (SYSCALL)HeapCompact, 0 },
49428 #endif
49429 #define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent)
49430
49431
49432 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP)
49433 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
49434 #else
49435 { "LoadLibraryW", (SYSCALL)0, 0 },
49436 #endif
49437 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent)
@@ -49305,72 +49441,82 @@
49441
49442 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
49443 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
49444 LPOVERLAPPED))aSyscall[30].pCurrent)
49445
49446 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
49447 && !defined(SQLITE_UWP)
49448 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
49449 #else
49450 { "MapViewOfFile", (SYSCALL)0, 0 },
49451 #endif
49452 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49453 SIZE_T))aSyscall[31].pCurrent)
49454
49455 #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
49456 && defined(SQLITE_UWP)
49457 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
49458 #else
49459 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
49460 #endif
49461 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
49462 SIZE_T))aSyscall[32].pCurrent)
49463
49464 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
49465 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
49466 int))aSyscall[33].pCurrent)
49467
49468 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
49469 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
49470 LARGE_INTEGER*))aSyscall[34].pCurrent)
49471
49472 { "ReadFile", (SYSCALL)ReadFile, 0 },
49473 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
49474 LPOVERLAPPED))aSyscall[35].pCurrent)
49475
49476 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
49477 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent)
49478
49479 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
49480 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER,\
49481 PLARGE_INTEGER,DWORD))aSyscall[37].pCurrent)
49482
49483 { "Sleep", (SYSCALL)Sleep, 0 },
49484 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[38].pCurrent)
49485
49486 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
49487 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49488 LPOVERLAPPED))aSyscall[39].pCurrent)
49489
49490 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49491 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
49492 #else
49493 { "UnmapViewOfFile", (SYSCALL)0, 0 },
49494 #endif
49495 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[40].pCurrent)
49496
49497 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
49498 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
49499 LPCSTR,LPBOOL))aSyscall[41].pCurrent)
49500
49501 { "WriteFile", (SYSCALL)WriteFile, 0 },
49502 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
49503 LPOVERLAPPED))aSyscall[42].pCurrent)
49504
49505 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
49506 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
49507 DWORD))aSyscall[43].pCurrent)
49508
49509 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
49510 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
49511 BOOL))aSyscall[44].pCurrent)
49512
49513 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
49514 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[45].pCurrent)
49515
49516 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
49517 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[46].pCurrent)
49518
49519 /*
49520 ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
49521 ** is really just a macro that uses a compiler intrinsic (e.g. x64).
49522 ** So do not try to make this is into a redefinable interface.
@@ -49379,95 +49525,93 @@
49525 { "InterlockedCompareExchange", (SYSCALL)0, 0 },
49526 #define osInterlockedCompareExchange InterlockedCompareExchange
49527 #else
49528 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
49529 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\
49530 LONG,LONG))aSyscall[47].pCurrent)
49531 #endif /* defined(InterlockedCompareExchange) */
49532
49533 #if SQLITE_WIN32_USE_UUID
49534 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
49535 #else
49536 { "UuidCreate", (SYSCALL)0, 0 },
49537 #endif
49538 #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent)
49539
49540 #if SQLITE_WIN32_USE_UUID
49541 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
49542 #else
49543 { "UuidCreateSequential", (SYSCALL)0, 0 },
49544 #endif
49545 #define osUuidCreateSequential \
49546 ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[49].pCurrent)
49547
49548 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
49549 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
49550 #else
49551 { "FlushViewOfFile", (SYSCALL)0, 0 },
49552 #endif
49553 #define osFlushViewOfFile \
49554 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[50].pCurrent)
49555
49556 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49557 { "CreateEvent", (SYSCALL)CreateEvent, 0 },
49558 #else
49559 { "CreateEvent", (SYSCALL)0, 0 },
49560 #endif
49561 #define osCreateEvent ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
49562 BOOL,LPCSTR))aSyscall[51].pCurrent)
 
 
49563
49564 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49565 { "CancelIo", (SYSCALL)CancelIo, 0 },
49566 #else
49567 { "CancelIo", (SYSCALL)0, 0 },
49568 #endif
49569 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent)
49570
49571 #ifndef _WIN32
49572 { "getenv", (SYSCALL)getenv, 0 },
49573 #else
49574 { "getenv", (SYSCALL)0, 0 },
49575 #endif
49576 #define osGetenv ((const char *(*)(const char *))aSyscall[53].pCurrent)
49577
49578 #ifndef _WIN32
49579 { "getcwd", (SYSCALL)getcwd, 0 },
49580 #else
49581 { "getcwd", (SYSCALL)0, 0 },
49582 #endif
49583 #define osGetcwd ((char*(*)(char*,size_t))aSyscall[54].pCurrent)
49584
49585 #ifndef _WIN32
49586 { "readlink", (SYSCALL)readlink, 0 },
49587 #else
49588 { "readlink", (SYSCALL)0, 0 },
49589 #endif
49590 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[55].pCurrent)
49591
49592 #ifndef _WIN32
49593 { "lstat", (SYSCALL)lstat, 0 },
49594 #else
49595 { "lstat", (SYSCALL)0, 0 },
49596 #endif
49597 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[56].pCurrent)
49598
49599 #ifndef _WIN32
49600 { "__errno", (SYSCALL)__errno, 0 },
49601 #else
49602 { "__errno", (SYSCALL)0, 0 },
49603 #endif
49604 #define osErrno (*((int*(*)(void))aSyscall[57].pCurrent)())
49605
49606 #ifndef _WIN32
49607 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
49608 #else
49609 { "cygwin_conv_path", (SYSCALL)0, 0 },
49610 #endif
49611 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
49612 const void *, void *, size_t))aSyscall[58].pCurrent)
49613
49614 }; /* End of the overrideable system calls */
49615
49616 /*
49617 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -49551,10 +49695,13 @@
49695 }
49696 return 0;
49697 }
49698
49699 #ifdef SQLITE_WIN32_MALLOC
49700 #ifdef SQLITE_UWP
49701 # error SQLITE_WIN32_MALLOC is incompatible with SQLITE_UWP
49702 #endif
49703 /*
49704 ** If a Win32 native heap has been configured, this function will attempt to
49705 ** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one
49706 ** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The
49707 ** "pnLargest" argument, if non-zero, will be used to return the size of the
@@ -50509,31 +50656,15 @@
50656 ** If successful, return SQLITE_OK. Or, if an error occurs, return an SQLite
50657 ** error code.
50658 */
50659 static int winHandleSeek(HANDLE h, sqlite3_int64 iOffset){
50660 int rc = SQLITE_OK; /* Return value */
50661 LARGE_INTEGER x; /* The offset */
50662
50663 x.QuadPart = iOffset;
50664 if( osSetFilePointerEx(h, x, 0, FILE_BEGIN)==0 ){
50665 rc = SQLITE_IOERR_SEEK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50666 }
50667 OSTRACE(("SEEK file=%p, offset=%lld rc=%s\n", h, iOffset,sqlite3ErrName(rc)));
50668 return rc;
50669 }
50670
@@ -50812,18 +50943,17 @@
50943 ** Determine the size in bytes of the file opened by the handle passed as
50944 ** the first argument.
50945 */
50946 static int winHandleSize(HANDLE h, sqlite3_int64 *pnByte){
50947 int rc = SQLITE_OK;
50948 LARGE_INTEGER x;
 
 
50949 assert( pnByte );
50950 if( osGetFileSizeEx(h, &x)==0 ){
 
 
50951 rc = SQLITE_IOERR_FSTAT;
50952 *pnByte = 0;
50953 }else{
50954 *pnByte = x.QuadPart;
50955 }
50956 return rc;
50957 }
50958
50959 /*
@@ -51020,21 +51150,18 @@
51150 assert( id!=0 );
51151 assert( pSize!=0 );
51152 SimulateIOError(return SQLITE_IOERR_FSTAT);
51153 OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize));
51154 {
51155 LARGE_INTEGER x;
51156 if( osGetFileSizeEx(pFile->h, &x)==0 ){
51157 *pSize = 0;
51158 pFile->lastErrno = osGetLastError();
 
 
 
 
 
51159 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
51160 "winFileSize", pFile->zPath);
51161 }else{
51162 *pSize = x.QuadPart;
51163 }
51164 }
51165 OSTRACE(("SIZE file=%p, pSize=%p, *pSize=%lld, rc=%s\n",
51166 pFile->h, pSize, *pSize, sqlite3ErrName(rc)));
51167 return rc;
@@ -52373,11 +52500,11 @@
52500
52501 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
52502 if( pShmNode->nRegion<=iRegion ){
52503 HANDLE hShared = pShmNode->hSharedShm;
52504 struct ShmRegion *apNew; /* New aRegion[] array */
52505 i64 nByte = ((i64)iRegion+1)*(i64)szRegion; /* Minimum file size */
52506 sqlite3_int64 sz; /* Current size of wal-index file */
52507
52508 pShmNode->szRegion = szRegion;
52509
52510 /* The requested region is not mapped into this processes address space.
@@ -52404,11 +52531,11 @@
52531 }
52532 }
52533
52534 /* Map the requested memory region into this processes address space. */
52535 apNew = (struct ShmRegion*)sqlite3_realloc64(
52536 pShmNode->aRegion, ((i64)iRegion+1)*sizeof(apNew[0])
52537 );
52538 if( !apNew ){
52539 rc = SQLITE_IOERR_NOMEM_BKPT;
52540 goto shmpage_out;
52541 }
@@ -52421,20 +52548,30 @@
52548
52549 while( pShmNode->nRegion<=iRegion ){
52550 HANDLE hMap = NULL; /* file-mapping handle */
52551 void *pMap = 0; /* Mapped memory region */
52552
52553 #ifdef SQLITE_UWP
52554 hMap = osCreateFileMappingFromApp(hShared, NULL, protect, nByte, NULL);
52555 #else
52556 hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
52557 #endif
52558 OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%lld, rc=%s\n",
52559 osGetCurrentProcessId(), pShmNode->nRegion, nByte,
52560 hMap ? "ok" : "failed"));
52561 if( hMap ){
52562 i64 iOffset = pShmNode->nRegion*szRegion;
52563 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
52564 #ifdef SQLITE_UWP
52565 pMap = osMapViewOfFileFromApp(hMap, flags,
52566 iOffset - iOffsetShift, (i64)szRegion + iOffsetShift
52567 );
52568 #else
52569 pMap = osMapViewOfFile(hMap, flags,
52570 0, iOffset - iOffsetShift, (i64)szRegion + iOffsetShift
52571 );
52572 #endif
52573 OSTRACE(("SHM-MAP-MAP pid=%lu, region=%d, offset=%d, size=%d, rc=%s\n",
52574 osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
52575 szRegion, pMap ? "ok" : "failed"));
52576 }
52577 if( !pMap ){
@@ -52451,11 +52588,11 @@
52588 }
52589 }
52590
52591 shmpage_out:
52592 if( pShmNode->nRegion>iRegion ){
52593 i64 iOffset = (i64)iRegion*(i64)szRegion;
52594 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
52595 char *p = (char *)pShmNode->aRegion[iRegion].pMap;
52596 *pp = (void *)&p[iOffsetShift];
52597 }else{
52598 *pp = 0;
@@ -52563,13 +52700,17 @@
52700 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
52701 protect = PAGE_READWRITE;
52702 flags |= FILE_MAP_WRITE;
52703 }
52704 #endif
52705 #ifdef SQLITE_UWP
52706 pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL);
52707 #else
52708 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect,
52709 (DWORD)((nMap>>32) & 0xffffffff),
52710 (DWORD)(nMap & 0xffffffff), NULL);
52711 #endif
52712 if( pFd->hMap==NULL ){
52713 pFd->lastErrno = osGetLastError();
52714 rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
52715 "winMapfile1", pFd->zPath);
52716 /* Log the error, but continue normal operation using xRead/xWrite */
@@ -52577,11 +52718,15 @@
52718 osGetCurrentProcessId(), pFd, sqlite3ErrName(rc)));
52719 return SQLITE_OK;
52720 }
52721 assert( (nMap % winSysInfo.dwPageSize)==0 );
52722 assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff );
52723 #ifdef SQLITE_UWP
52724 pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, (SIZE_T)nMap);
52725 #else
52726 pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap);
52727 #endif
52728 if( pNew==NULL ){
52729 osCloseHandle(pFd->hMap);
52730 pFd->hMap = NULL;
52731 pFd->lastErrno = osGetLastError();
52732 rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
@@ -52920,11 +53065,11 @@
53065 if( !zWidePath ){
53066 sqlite3_free(zBuf);
53067 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
53068 return SQLITE_IOERR_NOMEM_BKPT;
53069 }
53070 if( osGetTempPathW==0 || osGetTempPathW(nMax, zWidePath)==0 ){
53071 sqlite3_free(zWidePath);
53072 sqlite3_free(zBuf);
53073 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
53074 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
53075 "winGetTempname2", 0);
@@ -53723,37 +53868,37 @@
53868 /*
53869 ** Interfaces for opening a shared library, finding entry points
53870 ** within the shared library, and closing the shared library.
53871 */
53872 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
53873 HANDLE h = 0;
53874 void *zConverted = winConvertFromUtf8Filename(zFilename);
53875 UNUSED_PARAMETER(pVfs);
53876 if( zConverted==0 ){
53877 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53878 return 0;
53879 }
53880 h = osLoadLibraryW ? osLoadLibraryW((LPCWSTR)zConverted) : 0;
53881 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
53882 sqlite3_free(zConverted);
53883 return (void*)h;
53884 }
53885 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
53886 UNUSED_PARAMETER(pVfs);
53887 winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
53888 }
53889 static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
53890 FARPROC proc = 0;
53891 UNUSED_PARAMETER(pVfs);
53892 proc = osGetProcAddressA ? osGetProcAddressA((HANDLE)pH, zSym) : 0;
53893 OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n",
53894 (void*)pH, zSym, (void*)proc));
53895 return (void(*)(void))proc;
53896 }
53897 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
53898 UNUSED_PARAMETER(pVfs);
53899 if( osFreeLibrary!=0 ) osFreeLibrary((HANDLE)pHandle);
53900 OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle));
53901 }
53902 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
53903 #define winDlOpen 0
53904 #define winDlError 0
@@ -53798,36 +53943,39 @@
53943 e.a = (unsigned char*)zBuf;
53944 e.na = nBuf;
53945 e.nXor = 0;
53946 e.i = 0;
53947 {
53948 FILETIME x;
53949 osGetSystemTimeAsFileTime(&x);
53950 xorMemory(&e, (unsigned char*)&x, sizeof(x));
53951 }
53952 {
53953 DWORD pid = osGetCurrentProcessId();
53954 xorMemory(&e, (unsigned char*)&pid, sizeof(pid));
53955 }
53956 {
53957 ULONGLONG cnt = osGetTickCount64();
53958 xorMemory(&e, (unsigned char*)&cnt, sizeof(cnt));
53959 }
53960 {
53961 LARGE_INTEGER i;
53962 osQueryPerformanceCounter(&i);
53963 xorMemory(&e, (unsigned char*)&i, sizeof(i));
53964 }
53965 #if SQLITE_WIN32_USE_UUID
53966 #ifdef SQLITE_UWP
53967 # error SQLITE_WIN32_USE_UUID is incompatible with SQLITE_UWP
53968 #endif
53969 {
53970 UUID id;
53971 memset(&id, 0, sizeof(id));
53972 osUuidCreate(&id);
53973 xorMemory(&e, (unsigned char*)&id, sizeof(id));
53974 memset(&id, 0, sizeof(UUID));
53975 osUuidCreateSequential(&id);
53976 xorMemory(&e, (unsigned char*)&id, sizeof(id));
53977 }
53978 #endif /* SQLITE_WIN32_USE_UUID */
53979 return e.nXor>nBuf ? nBuf : e.nXor;
53980 #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */
53981 }
@@ -54042,15 +54190,19 @@
54190 winNextSystemCall, /* xNextSystemCall */
54191 };
54192
54193 /* Double-check that the aSyscall[] array has been constructed
54194 ** correctly. See ticket [bb3a86e890c8e96ab] */
54195 assert( ArraySize(aSyscall)==59 );
54196 assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
54197 assert( strcmp(aSyscall[8].zName,"FreeLibrary")==0 );
54198 assert( strcmp(aSyscall[16].zName,"GetSystemInfo")==0 );
54199 assert( strcmp(aSyscall[24].zName,"HeapReAlloc")==0 );
54200 assert( strcmp(aSyscall[32].zName,"MapViewOfFileFromApp")==0 );
54201 assert( strcmp(aSyscall[40].zName,"UnmapViewOfFile")==0 );
54202 assert( strcmp(aSyscall[48].zName,"UuidCreate")==0 );
54203 assert( strcmp(aSyscall[56].zName,"lstat")==0 );
54204
54205 /* get memory map allocation granularity */
54206 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
54207 osGetSystemInfo(&winSysInfo);
54208 assert( winSysInfo.dwAllocationGranularity>0 );
@@ -71953,10 +72105,20 @@
72105 ** See the header comment on "btreeInt.h" for additional information.
72106 ** Including a description of file format and an overview of operation.
72107 */
72108 /* #include "btreeInt.h" */
72109
72110 /*
72111 ** Suppress false-positive compiler warnings from GCC. Warnings are
72112 ** re-enabled at the bottom of this source file.
72113 */
72114 #if defined(__GNUC__) && __GNUC__>=11
72115 # pragma GCC diagnostic push
72116 # pragma GCC diagnostic ignored "-Wstringop-overread"
72117 # pragma GCC diagnostic ignored "-Wstringop-overflow"
72118 #endif
72119
72120 /*
72121 ** The header string that appears at the beginning of every
72122 ** SQLite database.
72123 */
72124 static const char zMagicHeader[] = SQLITE_FILE_HEADER;
@@ -77228,10 +77390,18 @@
77390 DbPage *pDbPage;
77391 rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage,
77392 (eOp==0 ? PAGER_GET_READONLY : 0)
77393 );
77394 if( rc==SQLITE_OK ){
77395 if( eOp!=0
77396 && (sqlite3PagerPageRefcount(pDbPage)!=1
77397 || NEVER(((MemPage*)sqlite3PagerGetExtra(pDbPage))->isInit))
77398 && sqlite3FaultSim(411)==SQLITE_OK
77399 ){
77400 sqlite3PagerUnref(pDbPage);
77401 return SQLITE_CORRUPT_PAGE(pPage);
77402 }
77403 aPayload = sqlite3PagerGetData(pDbPage);
77404 nextPage = get4byte(aPayload);
77405 rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
77406 sqlite3PagerUnref(pDbPage);
77407 offset = 0;
@@ -83504,10 +83674,17 @@
83674 SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree *p){
83675 testcase( p->sharable );
83676 return p->pBt->nRef;
83677 }
83678 #endif
83679
83680 /* Re-enable GCC compiler warnings that were suppressed at the top
83681 ** of this source file to prevent annoying false-positives.
83682 */
83683 #if defined(__GNUC__) && __GNUC__>=11
83684 # pragma GCC diagnostic pop
83685 #endif
83686
83687 /************** End of btree.c ***********************************************/
83688 /************** Begin file backup.c ******************************************/
83689 /*
83690 ** 2009 January 28
@@ -87107,15 +87284,25 @@
87284 /*
87285 ** Add an OP_ParseSchema opcode. This routine is broken out from
87286 ** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees
87287 ** as having been used.
87288 **
87289 ** zWhere is a WHERE clause that defines which entries of the schema
87290 ** to reparse. If zWhere==0, that means all entries. p5 is a mask
87291 ** of INITFLAG_* values for the parse.
87292 **
87293 ** In the current usage, the following are always true:
87294 **
87295 ** ALTER TABLE: zWhere==0, p5!=0
87296 ** Otherwise: zWhere!=0, p5==0
87297 **
87298 ** The zWhere string must have been obtained from sqlite3DbMalloc().
87299 ** This routine will take ownership of the allocated memory.
87300 */
87301 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere, u16 p5){
87302 int j;
87303 assert( p5==0 || zWhere==0 );
87304 sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
87305 sqlite3VdbeChangeP5(p, p5);
87306 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
87307 sqlite3MayAbort(p->pParse);
87308 }
@@ -95713,14 +95900,16 @@
95900 */
95901 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
95902 int eType = sqlite3_value_type(pVal);
95903 if( eType==SQLITE_TEXT ){
95904 Mem *pMem = (Mem*)pVal;
95905 #if SQLITE_THREADSAFE>0
95906 sqlite3_mutex *pMutex = pMem->db ? pMem->db->mutex : 0;
95907 #endif
95908 sqlite3_mutex_enter(pMutex);
95909 applyNumericAffinity(pMem, 0);
95910 sqlite3_mutex_leave(pMutex);
95911 eType = sqlite3_value_type(pVal);
95912 }
95913 return eType;
95914 }
95915
@@ -102423,15 +102612,22 @@
102612 goto abort_due_to_error;
102613 }
102614 break;
102615 }
102616
102617 /* Opcode: ParseSchema P1 * * P4 P5
102618 **
102619 ** Read and parse all entries from the schema table of database P1
102620 ** that match the WHERE clause P4. If P4 is a NULL pointer, then the
102621 ** entire schema for P1 is reparsed.
102622 **
102623 ** When P4 is NULL, the P5 value is used as the mFlags argument
102624 ** to sqlite3InitOne(). In other words, P5 should be a mask composed
102625 ** of INITFLAG_* values.
102626 **
102627 ** The P4==0 case is only used by ALTER TABLE and P5!=0 for all such
102628 ** cases. For uses other than ALTER TABLE, P4<>0 and P5==0.
102629 **
102630 ** This opcode invokes the parser to create a new virtual machine,
102631 ** then runs the new virtual machine. It is thus a re-entrant opcode.
102632 */
102633 case OP_ParseSchema: {
@@ -102456,18 +102652,20 @@
102652 || db->mallocFailed
102653 || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) );
102654
102655 #ifndef SQLITE_OMIT_ALTERTABLE
102656 if( pOp->p4.z==0 ){
102657 assert( pOp->p5!=0 );
102658 sqlite3SchemaClear(db->aDb[iDb].pSchema);
102659 db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
102660 rc = sqlite3InitOne(db, iDb, &p->zErrMsg, pOp->p5);
102661 db->mDbFlags |= DBFLAG_SchemaChange;
102662 p->expired = 0;
102663 }else
102664 #endif
102665 {
102666 assert( pOp->p5==0 );
102667 zSchema = LEGACY_SCHEMA_TABLE;
102668 initData.db = db;
102669 initData.iDb = iDb;
102670 initData.pzErrMsg = &p->zErrMsg;
102671 initData.mInitFlags = 0;
@@ -109972,10 +110170,11 @@
110170 }
110171 extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
110172 pExpr->op = TK_FUNCTION;
110173 pExpr->u.zToken = "coalesce";
110174 pExpr->x.pList = pFJMatch;
110175 pExpr->affExpr = SQLITE_AFF_DEFER;
110176 cnt = 1;
110177 goto lookupname_end;
110178 }else{
110179 sqlite3ExprListDelete(db, pFJMatch);
110180 pFJMatch = 0;
@@ -110137,10 +110336,30 @@
110336 sqlite3AtoF(p->u.zToken, &r);
110337 assert( r>=0.0 );
110338 if( r>1.0 ) return -1;
110339 return (int)(r*134217728.0);
110340 }
110341
110342 /*
110343 ** Set the EP_SubtArg property on every expression inside of
110344 ** pList. If any subexpression is actually a subquery, then
110345 ** also set the EP_SubtArg property on the first result-set
110346 ** column of that subquery.
110347 */
110348 static SQLITE_NOINLINE void resolveSetExprSubtypeArg(ExprList *pList){
110349 int nn, ii;
110350 nn = pList ? pList->nExpr : 0;
110351 for(ii=0; ii<nn; ii++){
110352 Expr *pExpr = pList->a[ii].pExpr;
110353 ExprSetProperty(pExpr, EP_SubtArg);
110354 if( pExpr->op==TK_SELECT ){
110355 assert( ExprUseXSelect(pExpr) );
110356 assert( pExpr->x.pSelect!=0 );
110357 resolveSetExprSubtypeArg(pExpr->x.pSelect->pEList);
110358 }
110359 }
110360 }
110361
110362 /*
110363 ** This routine is callback for sqlite3WalkExpr().
110364 **
110365 ** Resolve symbolic names into TK_COLUMN operators for the current
@@ -110382,14 +110601,11 @@
110601 ** the function may return a value with a subtype back to its
110602 ** caller using sqlite3_result_value(). */
110603 if( (pDef->funcFlags & SQLITE_SUBTYPE)
110604 || ExprHasProperty(pExpr, EP_SubtArg)
110605 ){
110606 resolveSetExprSubtypeArg(pList);
 
 
 
110607 }
110608
110609 if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
110610 /* For the purposes of the EP_ConstFunc flag, date and time
110611 ** functions and other functions that change slowly are considered
@@ -110415,12 +110631,17 @@
110631 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
110632 ){
110633 /* Internal-use-only functions are disallowed unless the
110634 ** SQL is being compiled using sqlite3NestedParse() or
110635 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
110636 ** used to activate internal functions for testing purposes.
110637 **
110638 ** The 2 value for no_such_func means that the function is
110639 ** an internal-use-only function which should be treated as a
110640 ** non-existant function for name resolution purposes.
110641 */
110642 no_such_func = 2;
110643 pDef = 0;
110644 }else
110645 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
110646 && !IN_RENAME_OBJECT
110647 ){
@@ -110460,13 +110681,20 @@
110681 sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr);
110682 pNC->nNcErr++;
110683 is_agg = 0;
110684 }
110685 #endif
110686 else if( no_such_func
110687 && (pParse->db->init.busy==0 ||
110688 (no_such_func==2 && pParse->db->init.busy==2))
110689 /* Suppress "no such function" errors when reading
110690 ** the sqlite_schema table. Except, do raise the error
110691 ** if init.busy is 2, meaning the schema parse is due
110692 ** to an ALTER TABLE ADD COLUMN statement, and the function
110693 ** is an internal-use-only function (no_such_func==2). */
110694 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
110695 && pParse->explain==0
110696 #endif
110697 ){
110698 sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr);
110699 pNC->nNcErr++;
110700 }else if( wrong_num_args ){
@@ -111849,11 +112077,13 @@
112077 ** Return TRUE if the two expressions have equivalent collating sequences.
112078 */
112079 SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse *pParse, const Expr *pE1, const Expr *pE2){
112080 CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pE1);
112081 CollSeq *pColl2 = sqlite3ExprNNCollSeq(pParse, pE2);
112082 assert( (pColl1==pColl2) ==
112083 (sqlite3_stricmp(pColl1->zName,pColl2->zName)==0) );
112084 return pColl1==pColl2;
112085 }
112086
112087 /*
112088 ** pExpr is an operand of a comparison operator. aff2 is the
112089 ** type affinity of the other operand. This routine returns the
@@ -116203,40 +116433,51 @@
116433 }
116434 return target;
116435 }
116436
116437 /*
116438 ** Expression Node callback for sqlite3ExprCanReturnSubtype(). If
116439 ** pExpr is able to return a subtype, set pWalker->eCode and abort
116440 ** the search. If pExpr can never return a subtype, prune search.
116441 **
116442 ** The only expressions that can return a subtype are:
116443 **
116444 ** 1. A function
116445 ** 2. The no-op "+" operator
116446 ** 3. A CASE...END expression
116447 ** 4. A CAST() expression
116448 ** 5. A "expr COLLATE colseq" expression.
116449 **
116450 ** For any other kind of expression, prune the search.
116451 **
116452 ** For case 1, the expression can yield a subtype if the function has
116453 ** the SQLITE_RESULT_SUBTYPE property. Functions can also return
116454 ** a subtype (via sqlite3_result_value()) if any of the arguments can
116455 ** return a subtype.
116456 **
116457 ** In all cases 1 through 5, the expression might also return a subtype
116458 ** if any operand can return a subtype.
116459 */
116460 static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
116461 int n;
116462 FuncDef *pDef;
116463 sqlite3 *db;
116464 if( pExpr->op==TK_CASE || pExpr->op==TK_UPLUS
116465 || pExpr->op==TK_COLLATE || pExpr->op==TK_CAST
116466 ){
116467 return WRC_Continue;
116468 }
116469 if( pExpr->op!=TK_FUNCTION ){
116470 return WRC_Prune;
116471 }
116472 assert( ExprUseXList(pExpr) );
116473 db = pWalker->pParse->db;
116474 n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0;
116475 pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
116476 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
116477 pWalker->eCode = 1;
116478 return WRC_Abort;
116479 }
116480 return WRC_Continue;
116481 }
116482
116483 /*
@@ -122210,23 +122451,35 @@
122451 SQLITE_PRIVATE void sqlite3AlterAddConstraint(
122452 Parse *pParse, /* Parse context */
122453 SrcList *pSrc, /* Table to add constraint to */
122454 Token *pFirst, /* First token of new constraint */
122455 Token *pName, /* Name of new constraint. NULL if name omitted. */
122456 const char *zExpr, /* Text of CHECK expression */
122457 int nExpr, /* Size of pExpr in bytes */
122458 Expr *pExpr /* The parsed CHECK expression */
122459 ){
122460 Table *pTab = 0; /* Table identified by pSrc */
122461 int iDb = 0; /* Which schema does pTab live in */
122462 const char *zDb = 0; /* Name of the schema in which pTab lives */
122463 const char *pCons = 0; /* Text of the constraint */
122464 int nCons; /* Bytes of text to use from pCons[] */
122465 int rc; /* Result from error checking pExpr */
122466
122467 /* Look up the table being altered. */
122468 assert( pSrc->nSrc==1 );
122469 pTab = alterFindTable(pParse, pSrc, &iDb, &zDb, 1);
122470 if( !pTab ){
122471 sqlite3ExprDelete(pParse->db, pExpr);
122472 return;
122473 }
122474
122475 /* Verify that the new CHECK constraint does not contain any
122476 ** internal-use-only function. Forum post 2026-05-10T01:11:28Z
122477 */
122478 rc = sqlite3ResolveSelfReference(pParse, pTab, NC_IsCheck, pExpr, 0);
122479 sqlite3ExprDelete(pParse->db, pExpr);
122480 if( rc ) return;
122481
122482 /* If this new constraint has a name, check that it is not a duplicate of
122483 ** an existing constraint. It is an error if it is. */
122484 if( pName ){
122485 char *zName = sqlite3NameFromToken(pParse->db, pName);
@@ -122243,11 +122496,11 @@
122496
122497 /* Search for a constraint violation. Throw an exception if one is found. */
122498 sqlite3NestedParse(pParse,
122499 "SELECT sqlite_fail('constraint failed', %d) "
122500 "FROM %Q.%Q WHERE (%.*s) IS NOT TRUE",
122501 SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, zExpr
122502 );
122503
122504 /* Edit the SQL for the named table. */
122505 pCons = pFirst->z;
122506 nCons = alterRtrimConstraint(pParse->db, pCons, pParse->sLastToken.z - pCons);
@@ -125929,10 +126182,23 @@
126182 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
126183 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
126184 return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
126185 }
126186
126187 /*
126188 ** Suppress false-positive warning message generated with -O3 in GCC
126189 ** on the second call to sqlite3Strlen30() in the sqlite3ColumnSetColl()
126190 ** function below. See the forum thread beginning on 2026-05-10T01:11:22Z.
126191 **
126192 ** See also the "pop" pragma to undo this warning suppression immediately
126193 ** after the function.
126194 */
126195 #if defined(__GNUC__) && __GNUC__>=11
126196 # pragma GCC diagnostic push
126197 # pragma GCC diagnostic ignored "-Wstringop-overread"
126198 #endif
126199
126200 /*
126201 ** Set the collating sequence name for a column.
126202 */
126203 SQLITE_PRIVATE void sqlite3ColumnSetColl(
126204 sqlite3 *db,
@@ -125953,10 +126219,15 @@
126219 pCol->zCnName = zNew;
126220 memcpy(pCol->zCnName + n, zColl, nColl);
126221 pCol->colFlags |= COLFLAG_HASCOLL;
126222 }
126223 }
126224
126225 /* Undo the false-positive warning suppression above. */
126226 #if defined(__GNUC__) && __GNUC__>=11
126227 # pragma GCC diagnostic pop
126228 #endif
126229
126230 /*
126231 ** Return the collating sequence name for a column
126232 */
126233 SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){
@@ -134599,15 +134870,20 @@
134870 ** to initialize it */
134871 if( ALWAYS(p) && type!=SQLITE_NULL ){
134872 assert( p->cnt>0 );
134873 p->cnt--;
134874 if( !p->approx ){
134875 i64 x = p->iSum;
134876 if( sqlite3SubInt64(&x, sqlite3_value_int64(argv[0]))==0 ){
134877 p->iSum = x;
134878 return;
134879 }
134880 p->ovrfl = 1;
134881 p->approx = 1;
134882 kahanBabuskaNeumaierInit(p, p->iSum);
134883 }
134884 if( type==SQLITE_INTEGER ){
134885 i64 iVal = sqlite3_value_int64(argv[0]);
134886 if( iVal!=SMALLEST_INT64 ){
134887 kahanBabuskaNeumaierStepInt64(p, -iVal);
134888 }else{
134889 kahanBabuskaNeumaierStepInt64(p, LARGEST_INT64);
@@ -140569,10 +140845,48 @@
140845 }
140846
140847 /* If no test above fails then the indices must be compatible */
140848 return 1;
140849 }
140850
140851 /*
140852 ** Examine an expression node and abort if it references the ROWID.
140853 ** This is a Walker callback used by xferCompatibleCheck()
140854 */
140855 static int xferCheckRowid(Walker *pWalk, Expr *pExpr){
140856 if( pExpr->op==TK_COLUMN && pExpr->iColumn<0 ){
140857 pWalk->eCode = 1;
140858 return WRC_Abort;
140859 }else{
140860 return WRC_Continue;
140861 }
140862 }
140863
140864 /*
140865 ** Analyze CHECK constraints on the source and destination tables and
140866 ** return true if those CHECK constraints are compatible with the
140867 ** xfer-optimization.
140868 **
140869 ** * The pDest and pSrc tables must have identical CHECK constraints.
140870 **
140871 ** * If the destination table, pDest, does not have an
140872 ** INTEGER PRIMARY KEY column, then no CHECK constraint may
140873 ** referenced the ROWID. (See forum post 2026-05-11T13:15:57Z)
140874 */
140875 static int xferCompatibleCheck(Table *pDest, Table *pSrc){
140876 if( sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
140877 return 0;
140878 }
140879 if( pDest->iPKey<0 ){
140880 Walker w;
140881 memset(&w, 0, sizeof(w));
140882 w.xExprCallback = xferCheckRowid;
140883 sqlite3WalkExprList(&w,pDest->pCheck);
140884 if( w.eCode ) return 0;
140885 }
140886 return 1;
140887 }
140888
140889 /*
140890 ** Attempt the transfer optimization on INSERTs of the form
140891 **
140892 ** INSERT INTO tab1 SELECT * FROM tab2;
@@ -140696,12 +141010,23 @@
141010 return 0; /* Number of columns must be the same in tab1 and tab2 */
141011 }
141012 if( pDest->iPKey!=pSrc->iPKey ){
141013 return 0; /* Both tables must have the same INTEGER PRIMARY KEY */
141014 }
141015 if( (pDest->tabFlags & TF_Strict)!=0 ){
141016 if( (pSrc->tabFlags & TF_Strict)==0 ){
141017 return 0; /* Cannot feed from a non-strict into a strict table */
141018 }
141019 for(i=0; i<pDest->nCol; i++){
141020 unsigned eDestType = pDest->aCol[i].eCType;
141021 unsigned eSrcType = pSrc->aCol[i].eCType;
141022 if( eDestType==COLTYPE_ANY ) continue;
141023 if( eDestType==eSrcType ) continue;
141024 if( eDestType==COLTYPE_INT && eSrcType==COLTYPE_INTEGER ) continue;
141025 if( eDestType==COLTYPE_INTEGER && eSrcType==COLTYPE_INT ) continue;
141026 return 0; /* Incompatible types in source and destination */
141027 }
141028 }
141029 for(i=0; i<pDest->nCol; i++){
141030 Column *pDestCol = &pDest->aCol[i];
141031 Column *pSrcCol = &pSrc->aCol[i];
141032 #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
@@ -140791,11 +141116,11 @@
141116 }
141117 }
141118 #ifndef SQLITE_OMIT_CHECK
141119 if( pDest->pCheck
141120 && (db->mDbFlags & DBFLAG_Vacuum)==0
141121 && !xferCompatibleCheck(pDest,pSrc)
141122 ){
141123 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
141124 }
141125 #endif
141126 #ifndef SQLITE_OMIT_FOREIGN_KEY
@@ -140812,10 +141137,22 @@
141137 }
141138 #endif
141139 if( (db->flags & SQLITE_CountRows)!=0 ){
141140 return 0; /* xfer opt does not play well with PRAGMA count_changes */
141141 }
141142 #ifndef SQLITE_OMIT_AUTHORIZATION
141143 if( db->xAuth ){
141144 int iDb = sqlite3SchemaToIndex(db, pSrc->pSchema);
141145 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 0;
141146 for(i=0; i<pSrc->nCol; i++){
141147 Column *pSrcCol = &pSrc->aCol[i];
141148 if( sqlite3AuthReadCol(pParse, pSrc->zName, pSrcCol->zCnName, iDb) ){
141149 return 0;
141150 }
141151 }
141152 }
141153 #endif
141154
141155 /* If we get this far, it means that the xfer optimization is at
141156 ** least a possibility, though it might only work if the destination
141157 ** table (tab1) is initially empty.
141158 */
@@ -146810,11 +147147,17 @@
147147 assert( iDb>=0 && iDb<db->nDb );
147148 assert( db->aDb[iDb].pSchema );
147149 assert( sqlite3_mutex_held(db->mutex) );
147150 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
147151
147152 db->init.busy = 1 + ((mFlags & INITFLAG_AlterAdd)!=0);
147153 /* ^--- Any non-zero value for init.busy means that we are scanning
147154 ** the sqlite_schema table to build the internal schema representation,
147155 ** rather than running actual CREATE statements. init.busy==2 has the
147156 ** additional meaning that the scan is happening as part of
147157 ** ALTER TABLE ADD COLUMN, which is stricter in its enforcement of
147158 ** function name resolution. */
147159
147160 /* Construct the in-memory representation schema tables (sqlite_schema or
147161 ** sqlite_temp_schema) by invoking the parser directly. The appropriate
147162 ** table name will be inserted automatically by the parser so we can just
147163 ** use the abbreviation "x" here. The parser will also automatically tag
@@ -164903,11 +165246,11 @@
165246
165247 /* Set up a new SrcList in pOrTab containing the table being scanned
165248 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
165249 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
165250 */
165251 if( pWInfo->nLevel>1 || pTabItem->fg.fromExists ){
165252 int nNotReady; /* The number of notReady tables */
165253 SrcItem *origSrc; /* Original list of tables */
165254 nNotReady = pWInfo->nLevel - iLevel - 1;
165255 pOrTab = sqlite3DbMallocRawNN(db, SZ_SRCLIST(nNotReady+1));
165256 if( pOrTab==0 ) return notReady;
@@ -164916,10 +165259,17 @@
165259 memcpy(pOrTab->a, pTabItem, sizeof(*pTabItem));
165260 origSrc = pWInfo->pTabList->a;
165261 for(k=1; k<=nNotReady; k++){
165262 memcpy(&pOrTab->a[k], &origSrc[pLevel[k].iFrom], sizeof(pOrTab->a[k]));
165263 }
165264
165265 /* Clear the fromExists flag on the OR-optimized table entry so that
165266 ** the calls to sqlite3WhereEnd() do not code early-exits after the
165267 ** first row is visited. The early exit applies to this table's
165268 ** overall loop - including the multiple OR branches and any WHERE
165269 ** conditions not passed to the sub-loops - not to the sub-loops. */
165270 pOrTab->a[0].fg.fromExists = 0;
165271 }else{
165272 pOrTab = pWInfo->pTabList;
165273 }
165274
165275 /* Initialize the rowset register to contain NULL. An SQL NULL is
@@ -165159,11 +165509,11 @@
165509 ** indent everything in between the this point and the final OP_Return.
165510 ** See tag-20220407a in vdbe.c and shell.c */
165511 assert( pLevel->op==OP_Return );
165512 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
165513
165514 if( pWInfo->pTabList!=pOrTab ){ sqlite3DbFreeNN(db, pOrTab); }
165515 if( !untestedTerms ) disableTerm(pLevel, pTerm);
165516 }else
165517 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
165518
165519 {
@@ -166508,20 +166858,18 @@
166858 ** 1. The SQLITE_Transitive optimization must be enabled
166859 ** 2. Must be either an == or an IS operator
166860 ** 3. Not originating in the ON clause of an OUTER JOIN
166861 ** 4. The operator is not IS or else the query does not contain RIGHT JOIN
166862 ** 5. The affinities of A and B must be compatible
166863 ** 6. Both operands use the same collating sequence
 
166864 ** If this routine returns TRUE, that means that the RHS can be substituted
166865 ** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
166866 ** This is an optimization. No harm comes from returning 0. But if 1 is
166867 ** returned when it should not be, then incorrect answers might result.
166868 */
166869 static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){
166870 char aff1, aff2;
 
166871 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */
166872 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */
166873 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */
166874 assert( pSrc!=0 );
166875 if( pExpr->op==TK_IS
@@ -166535,14 +166883,11 @@
166883 if( aff1!=aff2
166884 && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
166885 ){
166886 return 0; /* (5) */
166887 }
166888 if( !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight) ){
 
 
 
166889 return 0; /* (6) */
166890 }
166891 return 1;
166892 }
166893
@@ -166870,11 +167215,11 @@
167215
167216 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
167217 /* Analyze a term that is composed of two or more subterms connected by
167218 ** an OR operator.
167219 */
167220 else if( pExpr->op==TK_OR && !ExprHasProperty(pExpr, EP_Collate) ){
167221 assert( pWC->op==TK_AND );
167222 exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
167223 pTerm = &pWC->a[idxTerm];
167224 }
167225 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
@@ -170589,13 +170934,14 @@
170934 pLoop->nOut--;
170935 if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
170936 && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */
170937 ){
170938 Expr *pRight = pOpExpr->pRight;
170939 Parse *pParse = pWC->pWInfo->pParse;
170940 int k = 0;
170941 testcase( pOpExpr->op==TK_IS );
170942 if( sqlite3ExprIsInteger(pRight, &k, pParse) && k>=(-1) && k<=1 ){
170943 k = 10;
170944 }else{
170945 k = 20;
170946 }
170947 if( iReduce<k ){
@@ -170688,11 +171034,12 @@
171034 testcase( pLhs->iColumn==XN_ROWID );
171035 aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs));
171036 idxaff = sqlite3TableColumnAffinity(pIdx->pTable, pLhs->iColumn);
171037 if( aff!=idxaff ) break;
171038
171039 if( ExprHasProperty(pTerm->pExpr, EP_Commuted) ) SWAP(Expr*, pRhs, pLhs);
171040 pColl = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
171041 if( pColl==0 ) break;
171042 if( sqlite3StrICmp(pColl->zName, pIdx->azColl[i+nEq]) ) break;
171043 }
171044 return i;
171045 }
@@ -183162,13 +183509,15 @@
183509 case 196: /* expr ::= LP nexprlist COMMA expr RP */
183510 {
183511 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy14, yymsp[-1].minor.yy454);
183512 yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
183513 if( yymsp[-4].minor.yy454 ){
183514 int i;
183515 yymsp[-4].minor.yy454->x.pList = pList;
183516 for(i=0; i<pList->nExpr; i++){
183517 assert( pList->a[i].pExpr!=0 );
183518 yymsp[-4].minor.yy454->flags |= pList->a[i].pExpr->flags & EP_Propagate;
183519 }
183520 }else{
183521 sqlite3ExprListDelete(pParse->db, pList);
183522 }
183523 }
@@ -183632,19 +183981,17 @@
183981 sqlite3AlterSetNotNull(pParse, yymsp[-7].minor.yy203, &yymsp[-4].minor.yy0, &yymsp[-2].minor.yy0);
183982 }
183983 break;
183984 case 300: /* cmd ::= ALTER TABLE fullname ADD CONSTRAINT nm CHECK LP expr RP onconf */
183985 {
183986 sqlite3AlterAddConstraint(pParse, yymsp[-8].minor.yy203, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1), yymsp[-2].minor.yy454);
183987 }
 
183988 break;
183989 case 301: /* cmd ::= ALTER TABLE fullname ADD CHECK LP expr RP onconf */
183990 {
183991 sqlite3AlterAddConstraint(pParse, yymsp[-6].minor.yy203, &yymsp[-4].minor.yy0, 0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1), yymsp[-2].minor.yy454);
183992 }
 
183993 break;
183994 case 302: /* cmd ::= create_vtab */
183995 {sqlite3VtabFinishParse(pParse,0);}
183996 break;
183997 case 303: /* cmd ::= create_vtab LP vtabarglist RP */
@@ -199171,11 +199518,11 @@
199518 break;
199519
199520 /* State 3. The integer just read is a column number. */
199521 default: assert( eState==3 );
199522 iCol = (int)v;
199523 if( iCol<1 || iCol>0x3fffffff ){
199524 rc = SQLITE_CORRUPT_VTAB;
199525 break;
199526 }
199527 if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM;
199528 pCsr->aStat[iCol+1].nDoc++;
@@ -199861,10 +200208,11 @@
200208 /* If this is a "NEAR" keyword, check for an explicit nearness. */
200209 if( pKey->eType==FTSQUERY_NEAR ){
200210 assert( nKey==4 );
200211 if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
200212 nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear);
200213 if( nNear>=1000000000 ) nNear = 1000000000;
200214 }
200215 }
200216
200217 /* At this point this is probably a keyword. But for that to be true,
200218 ** the next byte must contain either whitespace, an open or close
@@ -209724,11 +210072,11 @@
210072 int nHit = fts3ColumnlistCount(&pIter);
210073 if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
210074 if( p->flag==FTS3_MATCHINFO_LHITS ){
210075 p->aMatchinfo[iStart + iCol] = (u32)nHit;
210076 }else if( nHit ){
210077 p->aMatchinfo[iStart + iCol/32] |= (1U << (iCol&0x1F));
210078 }
210079 }
210080 assert( *pIter==0x00 || *pIter==0x01 );
210081 if( *pIter!=0x01 ) break;
210082 pIter++;
@@ -213744,11 +214092,11 @@
214092 break;
214093 case '\n':
214094 break;
214095 case 0xe2:
214096 /* '\' followed by either U+2028 or U+2029 is ignored as
214097 ** whitespace. Note that in UTF8, U+2028 is 0xe2 0x80 0x29.
214098 ** U+2029 is the same except for the last byte */
214099 if( sz2<4
214100 || 0x80!=(u8)zIn[2]
214101 || (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3])
214102 ){
@@ -216313,15 +216661,13 @@
216661 char c;
216662 JsonString *pStr;
216663 UNUSED_PARAMETER(argc);
216664 UNUSED_PARAMETER(argv);
216665 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
 
216666 /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
216667 ** always have been called to initialize it */
216668 if( NEVER(!pStr) ) return;
 
216669 z = pStr->zBuf;
216670 for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
216671 if( c=='"' ){
216672 inStr = !inStr;
216673 }else if( c=='\\' ){
@@ -216346,10 +216692,17 @@
216692
216693 /*
216694 ** json_group_obj(NAME,VALUE)
216695 **
216696 ** Return a JSON object composed of all names and values in the aggregate.
216697 **
216698 ** Rows for which NAME is NULL do not result in a new entry. However, we
216699 ** do initially insert a "@" entry into the growing string for each null entry
216700 ** and change the first character of the string to "@" to signal that the
216701 ** string contains null entries. The "@" markers are needed in order to
216702 ** correctly process xInverse() requests. The initial "@" is converted
216703 ** back into "{" and the "@" null values are removed by jsonObjectCompute().
216704 */
216705 static void jsonObjectStep(
216706 sqlite3_context *ctx,
216707 int argc,
216708 sqlite3_value **argv
@@ -216363,49 +216716,97 @@
216716 z = (const char*)sqlite3_value_text(argv[0]);
216717 n = sqlite3Strlen30(z);
216718 if( pStr->zBuf==0 ){
216719 jsonStringInit(pStr, ctx);
216720 jsonAppendChar(pStr, '{');
216721 }else if( pStr->nUsed>1 ){
216722 jsonAppendChar(pStr, ',');
216723 }
216724 pStr->pCtx = ctx;
216725 if( z!=0 ){
216726 jsonAppendString(pStr, z, n);
216727 jsonAppendChar(pStr, ':');
216728 jsonAppendSqlValue(pStr, argv[1]);
216729 }else{
216730 pStr->zBuf[0] = '@';
216731 jsonAppendRawNZ(pStr, "@", 1);
216732 }
216733 }
216734 }
216735 static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
216736 JsonString *pStr;
216737 int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
216738 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
216739 if( pStr ){
216740 JsonString *pOgStr = pStr;
216741 JsonString tmpStr;
216742 jsonAppendRawNZ(pOgStr, "}", 2); /* Ensure it is zero-terminated */
216743 jsonStringTrimOneChar(pOgStr); /* Remove the zero terminator */
216744 pStr->pCtx = ctx;
216745 if( pStr->eErr ){
216746 jsonReturnString(pStr, 0, 0);
216747 return;
216748 }
216749 if( pStr->zBuf[0]!='{' ){
216750 /* The string contains null entries that need to be removed */
216751 u64 i, j;
216752 int inStr = 0;
216753 if( !isFinal ){
216754 /* Work with a temporary copy of the string if this is not the
216755 ** final result */
216756 jsonStringInit(&tmpStr, ctx);
216757 jsonAppendRawNZ(&tmpStr, pStr->zBuf, pStr->nUsed+1);
216758 pStr = &tmpStr;
216759 if( pStr->eErr ){
216760 jsonReturnString(pStr, 0, 0);
216761 return;
216762 }
216763 jsonStringTrimOneChar(pStr); /* Remove zero terminator */
216764 }
216765 /* Fix up the string by changing the initial "@" flag back to
216766 ** to "{" and removing all subsequence "@" entries, with their
216767 ** associated comma delimeters. */
216768 pStr->zBuf[0] = '{';
216769 for(i=j=1; i<pStr->nUsed; i++){
216770 char c = pStr->zBuf[i];
216771 if( c=='"' ){
216772 inStr = !inStr;
216773 pStr->zBuf[j++] = '"';
216774 }else if( c=='\\' ){
216775 pStr->zBuf[j++] = '\\';
216776 pStr->zBuf[j++] = pStr->zBuf[++i];
216777 }else if( c=='@' && !inStr ){
216778 assert( i+1<pStr->nUsed );
216779 if( pStr->zBuf[i+1]==',' ){
216780 i++;
216781 }else if( pStr->zBuf[j-1]==',' ){
216782 j--;
216783 }
216784 }else{
216785 pStr->zBuf[j++] = c;
216786 }
216787 }
216788 pStr->zBuf[j] = 0; /* Restore zero terminator */
216789 pStr->nUsed = j; /* Truncate the string */
216790 }
216791 if( flags & JSON_BLOB ){
216792 jsonReturnStringAsBlob(pStr);
216793 if( isFinal ){
216794 if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
216795 }else{
216796 jsonStringTrimOneChar(pOgStr);
216797 }
 
216798 }else if( isFinal ){
216799 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
216800 pStr->bStatic ? SQLITE_TRANSIENT :
216801 sqlite3RCStrUnref);
216802 pStr->bStatic = 1;
216803 }else{
216804 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
216805 jsonStringTrimOneChar(pOgStr);
216806 }
216807 if( pStr!=pOgStr ) jsonStringReset(pStr);
216808 }else if( flags & JSON_BLOB ){
216809 static const unsigned char emptyObject = 0x0c;
216810 sqlite3_result_blob(ctx, &emptyObject, 1, SQLITE_STATIC);
216811 }else{
216812 sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC);
@@ -218751,11 +219152,14 @@
219152 while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
219153 u8 *pCellData;
219154 pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc);
219155 if( rc ) return rc;
219156 nCell = NCELL(pNode);
219157 if( nCell>RTREE_MAXCELLS ){
219158 RTREE_IS_CORRUPT(pRtree);
219159 return SQLITE_CORRUPT_VTAB;
219160 }
219161 pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell);
219162 while( p->iCell<nCell ){
219163 sqlite3_rtree_dbl rScore = (sqlite3_rtree_dbl)-1;
219164 eWithin = FULLY_WITHIN;
219165 for(ii=0; ii<nConstraint; ii++){
@@ -223781,11 +224185,11 @@
224185 */
224186 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
224187 const UChar *zInput; /* Pointer to input string */
224188 UChar *zOutput = 0; /* Pointer to output buffer */
224189 int nInput; /* Size of utf-16 input string in bytes */
224190 sqlite3_int64 nOut; /* Size of output buffer in bytes */
224191 int cnt;
224192 int bToUpper; /* True for toupper(), false for tolower() */
224193 UErrorCode status;
224194 const char *zLocale = 0;
224195
@@ -223804,22 +224208,22 @@
224208 sqlite3_result_text16(p, "", 0, SQLITE_STATIC);
224209 return;
224210 }
224211
224212 for(cnt=0; cnt<2; cnt++){
224213 UChar *zNew = sqlite3_realloc64(zOutput, nOut);
224214 if( zNew==0 ){
224215 sqlite3_free(zOutput);
224216 sqlite3_result_error_nomem(p);
224217 return;
224218 }
224219 zOutput = zNew;
224220 status = U_ZERO_ERROR;
224221 if( bToUpper ){
224222 nOut = 2LL*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
224223 }else{
224224 nOut = 2LL*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
224225 }
224226
224227 if( U_SUCCESS(status) ){
224228 sqlite3_result_text16(p, zOutput, nOut, xFree);
224229 }else if( status==U_BUFFER_OVERFLOW_ERROR ){
@@ -231535,16 +231939,17 @@
231939 if( NEVER(pBt==0) ) return SQLITE_OK;
231940 pCsr->pPager = sqlite3BtreePager(pBt);
231941 pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
231942 pCsr->mxPgno = sqlite3BtreeLastPage(pBt);
231943 if( idxNum & 1 ){
231944 i64 iPg = sqlite3_value_int64(argv[idxNum>>1]);
231945 assert( argc>(idxNum>>1) );
231946 if( iPg<1 || iPg>pCsr->mxPgno ){
 
231947 pCsr->pgno = 1;
231948 pCsr->mxPgno = 0;
231949 }else{
231950 pCsr->pgno = (Pgno)iPg;
231951 pCsr->mxPgno = pCsr->pgno;
231952 }
231953 }else{
231954 assert( pCsr->pgno==1 );
231955 }
@@ -231620,10 +232025,11 @@
232025 sqlite3_value **argv,
232026 sqlite_int64 *pRowid
232027 ){
232028 DbpageTable *pTab = (DbpageTable *)pVtab;
232029 Pgno pgno;
232030 sqlite3_int64 pgno64;
232031 DbPage *pDbPage = 0;
232032 int rc = SQLITE_OK;
232033 char *zErr = 0;
232034 int iDb;
232035 Btree *pBt;
@@ -231639,15 +232045,15 @@
232045 if( argc==1 ){
232046 zErr = "cannot delete";
232047 goto update_fail;
232048 }
232049 if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
232050 pgno64 = sqlite3_value_int64(argv[2]);
232051 isInsert = 1;
232052 }else{
232053 pgno64 = (Pgno)sqlite3_value_int64(argv[0]);
232054 if( sqlite3_value_int64(argv[1])!=pgno64 ){
232055 zErr = "cannot insert";
232056 goto update_fail;
232057 }
232058 isInsert = 0;
232059 }
@@ -231660,14 +232066,15 @@
232066 zErr = "no such schema";
232067 goto update_fail;
232068 }
232069 }
232070 pBt = pTab->db->aDb[iDb].pBt;
232071 if( pgno64<1 || pgno64>4294967294 || NEVER(pBt==0) ){
232072 zErr = "bad page number";
232073 goto update_fail;
232074 }
232075 pgno = (Pgno)pgno64;
232076 szPage = sqlite3BtreeGetPageSize(pBt);
232077 if( sqlite3_value_type(argv[3])!=SQLITE_BLOB
232078 || sqlite3_value_bytes(argv[3])!=szPage
232079 ){
232080 if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){
@@ -232688,11 +233095,13 @@
233095 /*
233096 ** Read a varint value from aBuf[] into *piVal. Return the number of
233097 ** bytes read.
233098 */
233099 static int sessionVarintGet(const u8 *aBuf, int *piVal){
233100 int ret = getVarint32(aBuf, *piVal);
233101 *piVal = (*piVal & 0x7FFFFFFF);
233102 return ret;
233103 }
233104
233105 /*
233106 ** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal.
233107 ** Return the number of bytes read.
@@ -232703,11 +233112,11 @@
233112 memset(aCopy, 0, sizeof(aCopy));
233113 if( nBuf<sizeof(aCopy) ){
233114 memcpy(aCopy, aBuf, nBuf);
233115 aRead = aCopy;
233116 }
233117 return sessionVarintGet(aRead, piVal);
233118 }
233119
233120 /* Load an unaligned and unsigned 32-bit integer */
233121 #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
233122
@@ -234479,11 +234888,11 @@
234888
234889 if( zStmt==0 ){
234890 rc = SQLITE_NOMEM;
234891 }else{
234892 sqlite3_stmt *pStmt;
234893 rc = sqlite3_prepare_v2(pSession->db, zStmt, -1, &pStmt, 0);
234894 if( rc==SQLITE_OK ){
234895 SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
234896 pDiffCtx->pStmt = pStmt;
234897 pDiffCtx->nOldOff = 0;
234898 pDiffCtx->bRowid = pTab->bRowid;
@@ -234542,11 +234951,11 @@
234951 );
234952 if( zStmt==0 || z1==0 || z2==0 ){
234953 rc = SQLITE_NOMEM;
234954 }else{
234955 sqlite3_stmt *pStmt;
234956 rc = sqlite3_prepare_v2(pSession->db, zStmt, -1, &pStmt, 0);
234957
234958 if( rc==SQLITE_OK ){
234959 SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
234960 pDiffCtx->pStmt = pStmt;
234961 pDiffCtx->nOldOff = pTab->nCol;
@@ -236036,21 +236445,25 @@
236445 int i;
236446 for(i=0; rc==SQLITE_OK && i<nCol; i++){
236447 int eType;
236448 rc = sessionInputBuffer(pIn, nByte + 10);
236449 if( rc==SQLITE_OK ){
236450 if( pIn->iNext+nByte>=pIn->nData ){
 
 
 
 
 
 
 
 
 
236451 rc = SQLITE_CORRUPT_BKPT;
236452 }else{
236453 eType = pIn->aData[pIn->iNext + nByte++];
236454 if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
236455 int n;
236456 int nRem = pIn->nData - (pIn->iNext + nByte);
236457 nByte += sessionVarintGetSafe(&pIn->aData[pIn->iNext+nByte], nRem,&n);
236458 nByte += n;
236459 rc = sessionInputBuffer(pIn, nByte);
236460 }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
236461 nByte += 8;
236462 }else if( eType!=0 && eType!=SQLITE_NULL ){
236463 rc = SQLITE_CORRUPT_BKPT;
236464 }
236465 }
236466 }
236467 if( rc==SQLITE_OK && (pIn->iNext+nByte)>pIn->nData ){
236468 rc = SQLITE_CORRUPT_BKPT;
236469 }
@@ -237386,11 +237799,11 @@
237799
237800 /* Bind values to the UPDATE statement. */
237801 for(i=0; rc==SQLITE_OK && i<nCol; i++){
237802 sqlite3_value *pOld = sessionChangesetOld(pIter, i);
237803 sqlite3_value *pNew = sessionChangesetNew(pIter, i);
237804 if( pOld && (p->abPK[i] || bPatchset==0) ){
237805 rc = sessionBindValue(pUp, i*2+2, pOld);
237806 }
237807 if( rc==SQLITE_OK && pNew ){
237808 rc = sessionBindValue(pUp, i*2+1, pNew);
237809 }
@@ -239447,10 +239860,11 @@
239860 sqlite3_changegroup *pGrp,
239861 int bDiscard,
239862 char **pzErr
239863 ){
239864 int rc = SQLITE_OK;
239865 char *zErr = 0;
239866 if( pGrp->cd.pTab ){
239867 SessionBuffer *aBuf = pGrp->cd.aBuf;
239868 int ii;
239869
239870 if( bDiscard==0 ){
@@ -239458,26 +239872,26 @@
239872 u8 eUndef = SQLITE_NULL;
239873 if( pGrp->cd.eOp==SQLITE_UPDATE ){
239874 for(ii=0; ii<nBuf; ii++){
239875 if( pGrp->cd.pTab->abPK[ii] ){
239876 if( aBuf[ii].nBuf<=1 ){
239877 zErr = sqlite3_mprintf(
239878 "invalid change: %s value in PK of old.* record",
239879 aBuf[ii].nBuf==1 ? "null" : "undefined"
239880 );
239881 rc = SQLITE_ERROR;
239882 break;
239883 }else if( aBuf[ii + nBuf].nBuf>0 ){
239884 zErr = sqlite3_mprintf(
239885 "invalid change: defined value in PK of new.* record"
239886 );
239887 rc = SQLITE_ERROR;
239888 break;
239889 }
239890 }else
239891 if( pGrp->bPatch==0 && (aBuf[ii].nBuf>0)!=(aBuf[ii+nBuf].nBuf>0) ){
239892 zErr = sqlite3_mprintf(
239893 "invalid change: column %d "
239894 "- old.* value is %sdefined but new.* is %sdefined",
239895 ii, aBuf[ii].nBuf ? "" : "un", aBuf[ii+nBuf].nBuf ? "" : "un"
239896 );
239897 rc = SQLITE_ERROR;
@@ -239490,18 +239904,18 @@
239904 for(ii=0; ii<nBuf; ii++){
239905 int isPK = pGrp->cd.pTab->abPK[ii];
239906 if( (pGrp->cd.eOp==SQLITE_INSERT || pGrp->bPatch==0 || isPK)
239907 && aBuf[ii].nBuf==0
239908 ){
239909 zErr = sqlite3_mprintf(
239910 "invalid change: column %d is undefined", ii
239911 );
239912 rc = SQLITE_ERROR;
239913 break;
239914 }
239915 if( aBuf[ii].nBuf==1 && isPK ){
239916 zErr = sqlite3_mprintf(
239917 "invalid change: null value in PK"
239918 );
239919 rc = SQLITE_ERROR;
239920 break;
239921 }
@@ -239547,10 +239961,15 @@
239961 }
239962 }
239963 pGrp->cd.pTab = 0;
239964 }
239965
239966 if( pzErr ){
239967 *pzErr = zErr;
239968 }else{
239969 sqlite3_free(zErr);
239970 }
239971 return rc;
239972 }
239973
239974 #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */
239975
@@ -250006,11 +250425,11 @@
250425 }
250426
250427 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
250428 Fts5Data *pRet = fts5DataRead(p, iRowid);
250429 if( pRet ){
250430 if( pRet->szLeaf<4 || pRet->szLeaf>pRet->nn ){
250431 FTS5_CORRUPT_ROWID(p, iRowid);
250432 fts5DataRelease(pRet);
250433 pRet = 0;
250434 }
250435 }
@@ -251660,10 +252079,14 @@
252079 /* Figure out how many new bytes are in this term */
252080 fts5FastGetVarint32(a, iOff, nNew);
252081 if( nKeep<nMatch ){
252082 goto search_failed;
252083 }
252084 if( (iOff+nNew)>n ){
252085 FTS5_CORRUPT_ITER(p, pIter);
252086 return;
252087 }
252088
252089 assert( nKeep>=nMatch );
252090 if( nKeep==nMatch ){
252091 u32 nCmp;
252092 u32 i;
@@ -252786,11 +253209,11 @@
253209 }
253210
253211 /* Advance pointer p until it points to pEnd or an 0x01 byte that is
253212 ** not part of a varint */
253213 while( p<pEnd && *p!=0x01 ){
253214 while( p<pEnd && (*p++ & 0x80) );
253215 }
253216
253217 if( pColset->aiCol[i]==iCurrent ){
253218 if( pColset->nCol==1 ){
253219 pIter->base.pData = aCopy;
@@ -262254,11 +262677,11 @@
262677 int nArg, /* Number of args */
262678 sqlite3_value **apUnused /* Function arguments */
262679 ){
262680 assert( nArg==0 );
262681 UNUSED_PARAM2(nArg, apUnused);
262682 sqlite3_result_text(pCtx, "fts5: 2026-05-21 15:14:35 9ac4a33a2932d353c4871fd8e09c10addf827f1fc3fc9380037d738cf2cd0353", -1, SQLITE_TRANSIENT);
262683 }
262684
262685 /*
262686 ** Implementation of fts5_locale(LOCALE, TEXT) function.
262687 **
@@ -264648,12 +265071,18 @@
265071 PorterTokenizer *pRet;
265072 void *pUserdata = 0;
265073 const char *zBase = "unicode61";
265074 fts5_tokenizer_v2 *pV2 = 0;
265075
265076 while( nArg>0 ){
265077 if( sqlite3_stricmp(azArg[0],"porter")==0 ){
265078 nArg--;
265079 azArg++;
265080 }else{
265081 zBase = azArg[0];
265082 break;
265083 }
265084 }
265085
265086 pRet = (PorterTokenizer*)sqlite3_malloc64(sizeof(PorterTokenizer));
265087 if( pRet ){
265088 memset(pRet, 0, sizeof(PorterTokenizer));
265089
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.54.0"
150150
#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb"
151
+#define SQLITE_SOURCE_ID "2026-05-21 15:14:35 9ac4a33a2932d353c4871fd8e09c10addf827f1fc3fc9380037d738cf2cd0353"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-05-04T10:14:13.819Z"
154
+#define SQLITE_SCM_DATETIME "2026-05-21T15:14:35.420Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -4052,12 +4052,11 @@
40524052
** parameter on F or if the value of P does not match any of the
40534053
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
40544054
**
40554055
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
40564056
** 64-bit signed integer and returns that integer, or D if P does not
4057
-** exist. If the value of P is something other than an integer, then
4058
-** zero is returned.
4057
+** exist or ff the value of P is something other than an integer.
40594058
**
40604059
** The sqlite3_uri_key(F,N) returns a pointer to the name (not
40614060
** the value) of the N-th query parameter for filename F, or a NULL
40624061
** pointer if N is less than zero or greater than the number of query
40634062
** parameters minus 1. The N value is zero-based so N should be 0 to obtain
40644063
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-05-04T10:14:13.819Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4052,12 +4052,11 @@
4052 ** parameter on F or if the value of P does not match any of the
4053 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4054 **
4055 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4056 ** 64-bit signed integer and returns that integer, or D if P does not
4057 ** exist. If the value of P is something other than an integer, then
4058 ** zero is returned.
4059 **
4060 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4061 ** the value) of the N-th query parameter for filename F, or a NULL
4062 ** pointer if N is less than zero or greater than the number of query
4063 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
4064
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-05-21 15:14:35 9ac4a33a2932d353c4871fd8e09c10addf827f1fc3fc9380037d738cf2cd0353"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-05-21T15:14:35.420Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -4052,12 +4052,11 @@
4052 ** parameter on F or if the value of P does not match any of the
4053 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4054 **
4055 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4056 ** 64-bit signed integer and returns that integer, or D if P does not
4057 ** exist or ff the value of P is something other than an integer.
 
4058 **
4059 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4060 ** the value) of the N-th query parameter for filename F, or a NULL
4061 ** pointer if N is less than zero or greater than the number of query
4062 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
4063
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,6 +1,24 @@
11
<title>Change Log</title>
2
+
3
+<h2 id='v2_29'>Changes for version 2.29 (pending)</h2><ol>
4
+ <li> Enhance the [/help/www/ci_edit|/ci_edit] web page to show more
5
+ context of the check-in being edited.
6
+ <li> Honor the NO_COLOR environment variable in the
7
+ "[/help/system|fossil sys ls]" command.
8
+ <li> On the [/help/www/info|/info webpage] (and similar) put a
9
+ "copy" button before the date.
10
+ <li> Add the ".m4a" and ".oft" mimetypes.
11
+ <li> When doing a "fossil update", if a file under management needs to
12
+ overwrite an unmanaged file, display the name of the backup that
13
+ is made of the unmanaged file, and use file_delete() to delete
14
+ the unmanaged file, even if that unmanaged file is read-only.
15
+ <li> Improve the default prompts used by the
16
+ "[/help/sqlite3|fossil sql]" command.
17
+ <li> The captcha now uses light-gray boxes as the background, instead of
18
+ spaces, to work around width inconsistencies in some fonts.
19
+</ol>
220
321
<h2 id='v2_28'>Changes for version 2.28 (2026-03-11)</h2><ol>
422
<li> Improvements to [./antibot.wiki|anti-robot defenses]:<ol type="a">
523
<li> The default configuration now allows robots to download any tarball
624
or similar, to better support of automated build systems.
725
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,6 +1,24 @@
1 <title>Change Log</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3 <h2 id='v2_28'>Changes for version 2.28 (2026-03-11)</h2><ol>
4 <li> Improvements to [./antibot.wiki|anti-robot defenses]:<ol type="a">
5 <li> The default configuration now allows robots to download any tarball
6 or similar, to better support of automated build systems.
7
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,6 +1,24 @@
1 <title>Change Log</title>
2
3 <h2 id='v2_29'>Changes for version 2.29 (pending)</h2><ol>
4 <li> Enhance the [/help/www/ci_edit|/ci_edit] web page to show more
5 context of the check-in being edited.
6 <li> Honor the NO_COLOR environment variable in the
7 "[/help/system|fossil sys ls]" command.
8 <li> On the [/help/www/info|/info webpage] (and similar) put a
9 "copy" button before the date.
10 <li> Add the ".m4a" and ".oft" mimetypes.
11 <li> When doing a "fossil update", if a file under management needs to
12 overwrite an unmanaged file, display the name of the backup that
13 is made of the unmanaged file, and use file_delete() to delete
14 the unmanaged file, even if that unmanaged file is read-only.
15 <li> Improve the default prompts used by the
16 "[/help/sqlite3|fossil sql]" command.
17 <li> The captcha now uses light-gray boxes as the background, instead of
18 spaces, to work around width inconsistencies in some fonts.
19 </ol>
20
21 <h2 id='v2_28'>Changes for version 2.28 (2026-03-11)</h2><ol>
22 <li> Improvements to [./antibot.wiki|anti-robot defenses]:<ol type="a">
23 <li> The default configuration now allows robots to download any tarball
24 or similar, to better support of automated build systems.
25

Keyboard Shortcuts

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