Fossil SCM

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

drh 2022-07-19 13:17 trunk
Commit e5be71d6acc1aaaaf0843c2cad3042f15f2bf7e28ee4a762eec369be0da7e1a5
3 files changed +191 -86 +374 -281 +4 -4
+191 -86
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,10 +53,19 @@
5353
*/
5454
#if !defined(SQLITE_OS_WINRT)
5555
# define SQLITE_OS_WINRT 0
5656
#endif
5757
58
+/*
59
+** If SQLITE_SHELL_FIDDLE is defined then the shell is modified
60
+** somewhat for use as a WASM module in a web browser. This flag
61
+** should only be used when building the "fiddle" web application, as
62
+** the browser-mode build has much different user input requirements
63
+** and this build mode rewires the user input subsystem to account for
64
+** that.
65
+*/
66
+
5867
/*
5968
** Warning pragmas copied from msvc.h in the core.
6069
*/
6170
#if defined(_MSC_VER)
6271
#pragma warning(disable : 4054)
@@ -245,21 +254,10 @@
245254
#else
246255
# define setBinaryMode(X,Y)
247256
# define setTextMode(X,Y)
248257
#endif
249258
250
-/*
251
-** When compiling with emcc (a.k.a. emscripten), we're building a
252
-** WebAssembly (WASM) bundle and need to disable and rewire a few
253
-** things.
254
-*/
255
-#ifdef __EMSCRIPTEN__
256
-#define SQLITE_SHELL_WASM_MODE
257
-#else
258
-#undef SQLITE_SHELL_WASM_MODE
259
-#endif
260
-
261259
/* True if the timer is enabled */
262260
static int enableTimer = 0;
263261
264262
/* Return the current wall-clock time */
265263
static sqlite3_int64 timeOfDay(void){
@@ -717,11 +715,11 @@
717715
**
718716
** The result is stored in space obtained from malloc() and must either
719717
** be freed by the caller or else passed back into this routine via the
720718
** zPrior argument for reuse.
721719
*/
722
-#ifndef SQLITE_SHELL_WASM_MODE
720
+#ifndef SQLITE_SHELL_FIDDLE
723721
static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
724722
char *zPrompt;
725723
char *zResult;
726724
if( in!=0 ){
727725
zResult = local_getline(zPrior, in);
@@ -737,11 +735,11 @@
737735
if( zResult && *zResult ) shell_add_history(zResult);
738736
#endif
739737
}
740738
return zResult;
741739
}
742
-#endif /* !SQLITE_SHELL_WASM_MODE */
740
+#endif /* !SQLITE_SHELL_FIDDLE */
743741
744742
/*
745743
** Return the value of a hexadecimal digit. Return -1 if the input
746744
** is not a hex digit.
747745
*/
@@ -3794,10 +3792,11 @@
37943792
#define re_compile sqlite3re_compile
37953793
#define re_free sqlite3re_free
37963794
37973795
/* The end-of-input character */
37983796
#define RE_EOF 0 /* End of input */
3797
+#define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */
37993798
38003799
/* The NFA is implemented as sequence of opcodes taken from the following
38013800
** set. Each opcode has a single integer argument.
38023801
*/
38033802
#define RE_OP_MATCH 1 /* Match the one character in the argument */
@@ -3815,10 +3814,37 @@
38153814
#define RE_OP_DIGIT 13 /* digit: [0-9] */
38163815
#define RE_OP_NOTDIGIT 14 /* Not a digit */
38173816
#define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
38183817
#define RE_OP_NOTSPACE 16 /* Not a digit */
38193818
#define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
3819
+#define RE_OP_ATSTART 18 /* Currently at the start of the string */
3820
+
3821
+#if defined(SQLITE_DEBUG)
3822
+/* Opcode names used for symbolic debugging */
3823
+static const char *ReOpName[] = {
3824
+ "EOF",
3825
+ "MATCH",
3826
+ "ANY",
3827
+ "ANYSTAR",
3828
+ "FORK",
3829
+ "GOTO",
3830
+ "ACCEPT",
3831
+ "CC_INC",
3832
+ "CC_EXC",
3833
+ "CC_VALUE",
3834
+ "CC_RANGE",
3835
+ "WORD",
3836
+ "NOTWORD",
3837
+ "DIGIT",
3838
+ "NOTDIGIT",
3839
+ "SPACE",
3840
+ "NOTSPACE",
3841
+ "BOUNDARY",
3842
+ "ATSTART",
3843
+};
3844
+#endif /* SQLITE_DEBUG */
3845
+
38203846
38213847
/* Each opcode is a "state" in the NFA */
38223848
typedef unsigned short ReStateNumber;
38233849
38243850
/* Because this is an NFA and not a DFA, multiple states can be active at
@@ -3849,11 +3875,11 @@
38493875
const char *zErr; /* Error message to return */
38503876
char *aOp; /* Operators for the virtual machine */
38513877
int *aArg; /* Arguments to each operator */
38523878
unsigned (*xNextChar)(ReInput*); /* Next character function */
38533879
unsigned char zInit[12]; /* Initial text to match */
3854
- int nInit; /* Number of characters in zInit */
3880
+ int nInit; /* Number of bytes in zInit */
38553881
unsigned nState; /* Number of entries in aOp[] and aArg[] */
38563882
unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
38573883
};
38583884
38593885
/* Add a state to the given state set if it is not already there */
@@ -3922,11 +3948,11 @@
39223948
ReStateSet aStateSet[2], *pThis, *pNext;
39233949
ReStateNumber aSpace[100];
39243950
ReStateNumber *pToFree;
39253951
unsigned int i = 0;
39263952
unsigned int iSwap = 0;
3927
- int c = RE_EOF+1;
3953
+ int c = RE_START;
39283954
int cPrev = 0;
39293955
int rc = 0;
39303956
ReInput in;
39313957
39323958
in.z = zIn;
@@ -3941,10 +3967,11 @@
39413967
strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
39423968
){
39433969
in.i++;
39443970
}
39453971
if( in.i+pRe->nInit>in.mx ) return 0;
3972
+ c = RE_START-1;
39463973
}
39473974
39483975
if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
39493976
pToFree = 0;
39503977
aStateSet[0].aState = aSpace;
@@ -3968,10 +3995,14 @@
39683995
int x = pThis->aState[i];
39693996
switch( pRe->aOp[x] ){
39703997
case RE_OP_MATCH: {
39713998
if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
39723999
break;
4000
+ }
4001
+ case RE_OP_ATSTART: {
4002
+ if( cPrev==RE_START ) re_add_state(pThis, x+1);
4003
+ break;
39734004
}
39744005
case RE_OP_ANY: {
39754006
if( c!=0 ) re_add_state(pNext, x+1);
39764007
break;
39774008
}
@@ -4050,11 +4081,13 @@
40504081
}
40514082
}
40524083
}
40534084
}
40544085
for(i=0; i<pNext->nState; i++){
4055
- if( pRe->aOp[pNext->aState[i]]==RE_OP_ACCEPT ){ rc = 1; break; }
4086
+ int x = pNext->aState[i];
4087
+ while( pRe->aOp[x]==RE_OP_GOTO ) x += pRe->aArg[x];
4088
+ if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; }
40564089
}
40574090
re_match_end:
40584091
sqlite3_free(pToFree);
40594092
return rc;
40604093
}
@@ -4205,11 +4238,10 @@
42054238
const char *zErr;
42064239
while( (c = p->xNextChar(&p->sIn))!=0 ){
42074240
iStart = p->nState;
42084241
switch( c ){
42094242
case '|':
4210
- case '$':
42114243
case ')': {
42124244
p->sIn.i--;
42134245
return 0;
42144246
}
42154247
case '(': {
@@ -4241,10 +4273,18 @@
42414273
}
42424274
case '?': {
42434275
if( iPrev<0 ) return "'?' without operand";
42444276
re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
42454277
break;
4278
+ }
4279
+ case '$': {
4280
+ re_append(p, RE_OP_MATCH, RE_EOF);
4281
+ break;
4282
+ }
4283
+ case '^': {
4284
+ re_append(p, RE_OP_ATSTART, 0);
4285
+ break;
42464286
}
42474287
case '{': {
42484288
int m = 0, n = 0;
42494289
int sz, j;
42504290
if( iPrev<0 ) return "'{m,n}' without operand";
@@ -4260,10 +4300,11 @@
42604300
p->sIn.i++;
42614301
sz = p->nState - iPrev;
42624302
if( m==0 ){
42634303
if( n==0 ) return "both m and n are zero in '{m,n}'";
42644304
re_insert(p, iPrev, RE_OP_FORK, sz+1);
4305
+ iPrev++;
42654306
n--;
42664307
}else{
42674308
for(j=1; j<m; j++) re_copy(p, iPrev, sz);
42684309
}
42694310
for(j=m; j<n; j++){
@@ -4378,15 +4419,11 @@
43784419
zErr = re_subcompile_re(pRe);
43794420
if( zErr ){
43804421
re_free(pRe);
43814422
return zErr;
43824423
}
4383
- if( rePeek(pRe)=='$' && pRe->sIn.i+1>=pRe->sIn.mx ){
4384
- re_append(pRe, RE_OP_MATCH, RE_EOF);
4385
- re_append(pRe, RE_OP_ACCEPT, 0);
4386
- *ppRe = pRe;
4387
- }else if( pRe->sIn.i>=pRe->sIn.mx ){
4424
+ if( pRe->sIn.i>=pRe->sIn.mx ){
43884425
re_append(pRe, RE_OP_ACCEPT, 0);
43894426
*ppRe = pRe;
43904427
}else{
43914428
re_free(pRe);
43924429
return "unrecognized character";
@@ -4407,11 +4444,11 @@
44074444
pRe->zInit[j++] = (unsigned char)x;
44084445
}else if( x<=0xfff ){
44094446
pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6));
44104447
pRe->zInit[j++] = 0x80 | (x&0x3f);
44114448
}else if( x<=0xffff ){
4412
- pRe->zInit[j++] = (unsigned char)(0xd0 | (x>>12));
4449
+ pRe->zInit[j++] = (unsigned char)(0xe0 | (x>>12));
44134450
pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f);
44144451
pRe->zInit[j++] = 0x80 | (x&0x3f);
44154452
}else{
44164453
break;
44174454
}
@@ -4465,10 +4502,71 @@
44654502
}
44664503
if( setAux ){
44674504
sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
44684505
}
44694506
}
4507
+
4508
+#if defined(SQLITE_DEBUG)
4509
+/*
4510
+** This function is used for testing and debugging only. It is only available
4511
+** if the SQLITE_DEBUG compile-time option is used.
4512
+**
4513
+** Compile a regular expression and then convert the compiled expression into
4514
+** text and return that text.
4515
+*/
4516
+static void re_bytecode_func(
4517
+ sqlite3_context *context,
4518
+ int argc,
4519
+ sqlite3_value **argv
4520
+){
4521
+ const char *zPattern;
4522
+ const char *zErr;
4523
+ ReCompiled *pRe;
4524
+ sqlite3_str *pStr;
4525
+ int i;
4526
+ int n;
4527
+ char *z;
4528
+
4529
+ zPattern = (const char*)sqlite3_value_text(argv[0]);
4530
+ if( zPattern==0 ) return;
4531
+ zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
4532
+ if( zErr ){
4533
+ re_free(pRe);
4534
+ sqlite3_result_error(context, zErr, -1);
4535
+ return;
4536
+ }
4537
+ if( pRe==0 ){
4538
+ sqlite3_result_error_nomem(context);
4539
+ return;
4540
+ }
4541
+ pStr = sqlite3_str_new(0);
4542
+ if( pStr==0 ) goto re_bytecode_func_err;
4543
+ if( pRe->nInit>0 ){
4544
+ sqlite3_str_appendf(pStr, "INIT ");
4545
+ for(i=0; i<pRe->nInit; i++){
4546
+ sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
4547
+ }
4548
+ sqlite3_str_appendf(pStr, "\n");
4549
+ }
4550
+ for(i=0; i<pRe->nState; i++){
4551
+ sqlite3_str_appendf(pStr, "%-8s %4d\n",
4552
+ ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
4553
+ }
4554
+ n = sqlite3_str_length(pStr);
4555
+ z = sqlite3_str_finish(pStr);
4556
+ if( n==0 ){
4557
+ sqlite3_free(z);
4558
+ }else{
4559
+ sqlite3_result_text(context, z, n-1, sqlite3_free);
4560
+ }
4561
+
4562
+re_bytecode_func_err:
4563
+ re_free(pRe);
4564
+}
4565
+
4566
+#endif /* SQLITE_DEBUG */
4567
+
44704568
44714569
/*
44724570
** Invoke this routine to register the regexp() function with the
44734571
** SQLite database connection.
44744572
*/
@@ -4490,16 +4588,23 @@
44904588
/* The regexpi(PATTERN,STRING) function is a case-insensitive version
44914589
** of regexp(PATTERN,STRING). */
44924590
rc = sqlite3_create_function(db, "regexpi", 2,
44934591
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
44944592
(void*)db, re_sql_func, 0, 0);
4593
+#if defined(SQLITE_DEBUG)
4594
+ if( rc==SQLITE_OK ){
4595
+ rc = sqlite3_create_function(db, "regexp_bytecode", 1,
4596
+ SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
4597
+ 0, re_bytecode_func, 0, 0);
4598
+ }
4599
+#endif /* SQLITE_DEBUG */
44954600
}
44964601
return rc;
44974602
}
44984603
44994604
/************************* End ../ext/misc/regexp.c ********************/
4500
-#ifndef SQLITE_SHELL_WASM_MODE
4605
+#ifndef SQLITE_SHELL_FIDDLE
45014606
/************************* Begin ../ext/misc/fileio.c ******************/
45024607
/*
45034608
** 2014-06-13
45044609
**
45054610
** The author disclaims copyright to this source code. In place of
@@ -12248,19 +12353,19 @@
1224812353
int nIndent; /* Size of array aiIndent[] */
1224912354
int iIndent; /* Index of current op in aiIndent[] */
1225012355
char *zNonce; /* Nonce for temporary safe-mode excapes */
1225112356
EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
1225212357
ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12253
-#ifdef SQLITE_SHELL_WASM_MODE
12358
+#ifdef SQLITE_SHELL_FIDDLE
1225412359
struct {
1225512360
const char * zInput; /* Input string from wasm/JS proxy */
1225612361
const char * zPos; /* Cursor pos into zInput */
1225712362
} wasm;
1225812363
#endif
1225912364
};
1226012365
12261
-#ifdef SQLITE_SHELL_WASM_MODE
12366
+#ifdef SQLITE_SHELL_FIDDLE
1226212367
static ShellState shellState;
1226312368
#endif
1226412369
1226512370
1226612371
/* Allowed values for ShellState.autoEQP
@@ -12924,11 +13029,11 @@
1292413029
UNUSED_PARAMETER(zA2);
1292513030
UNUSED_PARAMETER(zA3);
1292613031
UNUSED_PARAMETER(zA4);
1292713032
switch( op ){
1292813033
case SQLITE_ATTACH: {
12929
-#ifndef SQLITE_SHELL_WASM_MODE
13034
+#ifndef SQLITE_SHELL_FIDDLE
1293013035
/* In WASM builds the filesystem is a virtual sandbox, so
1293113036
** there's no harm in using ATTACH. */
1293213037
failIfSafeMode(p, "cannot run ATTACH in safe mode");
1293313038
#endif
1293413039
break;
@@ -15338,11 +15443,11 @@
1533815443
** There must be two or more spaces between the end of the command and the
1533915444
** start of the description of what that command does.
1534015445
*/
1534115446
static const char *(azHelp[]) = {
1534215447
#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15343
- && !defined(SQLITE_SHELL_WASM_MODE)
15448
+ && !defined(SQLITE_SHELL_FIDDLE)
1534415449
".archive ... Manage SQL archives",
1534515450
" Each command must have exactly one of the following options:",
1534615451
" -c, --create Create a new archive",
1534715452
" -u, --update Add or update files with changed mtime",
1534815453
" -i, --insert Like -u but always add even if unchanged",
@@ -15364,23 +15469,23 @@
1536415469
" http://sqlite.org/cli.html#sqlite_archive_support",
1536515470
#endif
1536615471
#ifndef SQLITE_OMIT_AUTHORIZATION
1536715472
".auth ON|OFF Show authorizer callbacks",
1536815473
#endif
15369
-#ifndef SQLITE_SHELL_WASM_MODE
15474
+#ifndef SQLITE_SHELL_FIDDLE
1537015475
".backup ?DB? FILE Backup DB (default \"main\") to FILE",
1537115476
" Options:",
1537215477
" --append Use the appendvfs",
1537315478
" --async Write to FILE without journal and fsync()",
1537415479
#endif
1537515480
".bail on|off Stop after hitting an error. Default OFF",
1537615481
".binary on|off Turn binary output on or off. Default OFF",
15377
-#ifndef SQLITE_SHELL_WASM_MODE
15482
+#ifndef SQLITE_SHELL_FIDDLE
1537815483
".cd DIRECTORY Change the working directory to DIRECTORY",
1537915484
#endif
1538015485
".changes on|off Show number of rows changed by SQL",
15381
-#ifndef SQLITE_SHELL_WASM_MODE
15486
+#ifndef SQLITE_SHELL_FIDDLE
1538215487
".check GLOB Fail if output since .testcase does not match",
1538315488
".clone NEWDB Clone data into NEWDB from the existing database",
1538415489
#endif
1538515490
".connection [close] [#] Open or close an auxiliary database connection",
1538615491
".databases List names and files of attached databases",
@@ -15402,15 +15507,15 @@
1540215507
#ifdef SQLITE_DEBUG
1540315508
" test Show raw EXPLAIN QUERY PLAN output",
1540415509
" trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
1540515510
#endif
1540615511
" trigger Like \"full\" but also show trigger bytecode",
15407
-#ifndef SQLITE_SHELL_WASM_MODE
15512
+#ifndef SQLITE_SHELL_FIDDLE
1540815513
".excel Display the output of next command in spreadsheet",
1540915514
" --bom Put a UTF8 byte-order mark on intermediate file",
1541015515
#endif
15411
-#ifndef SQLITE_SHELL_WASM_MODE
15516
+#ifndef SQLITE_SHELL_FIDDLE
1541215517
".exit ?CODE? Exit this program with return-code CODE",
1541315518
#endif
1541415519
".expert EXPERIMENTAL. Suggest indexes for queries",
1541515520
".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
1541615521
".filectrl CMD ... Run various sqlite3_file_control() operations",
@@ -15417,11 +15522,11 @@
1541715522
" --schema SCHEMA Use SCHEMA instead of \"main\"",
1541815523
" --help Show CMD details",
1541915524
".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
1542015525
".headers on|off Turn display of headers on or off",
1542115526
".help ?-all? ?PATTERN? Show help text for PATTERN",
15422
-#ifndef SQLITE_SHELL_WASM_MODE
15527
+#ifndef SQLITE_SHELL_FIDDLE
1542315528
".import FILE TABLE Import data from FILE into TABLE",
1542415529
" Options:",
1542515530
" --ascii Use \\037 and \\036 as column and row separators",
1542615531
" --csv Use , and \\n as column and row separators",
1542715532
" --skip N Skip the first N rows of input",
@@ -15446,14 +15551,14 @@
1544615551
#endif
1544715552
".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
1544815553
".lint OPTIONS Report potential schema issues.",
1544915554
" Options:",
1545015555
" fkey-indexes Find missing foreign key indexes",
15451
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
15556
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
1545215557
".load FILE ?ENTRY? Load an extension library",
1545315558
#endif
15454
-#ifndef SQLITE_SHELL_WASM_MODE
15559
+#ifndef SQLITE_SHELL_FIDDLE
1545515560
".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
1545615561
#endif
1545715562
".mode MODE ?OPTIONS? Set output mode",
1545815563
" MODE is one of:",
1545915564
" ascii Columns/rows delimited by 0x1F and 0x1E",
@@ -15476,15 +15581,15 @@
1547615581
" --wordwrap B Wrap or not at word boundaries per B (on/off)",
1547715582
" --ww Shorthand for \"--wordwrap 1\"",
1547815583
" --quote Quote output text as SQL literals",
1547915584
" --noquote Do not quote output text",
1548015585
" TABLE The name of SQL table used for \"insert\" mode",
15481
-#ifndef SQLITE_SHELL_WASM_MODE
15586
+#ifndef SQLITE_SHELL_FIDDLE
1548215587
".nonce STRING Suspend safe mode for one command if nonce matches",
1548315588
#endif
1548415589
".nullvalue STRING Use STRING in place of NULL values",
15485
-#ifndef SQLITE_SHELL_WASM_MODE
15590
+#ifndef SQLITE_SHELL_FIDDLE
1548615591
".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
1548715592
" If FILE begins with '|' then open as a pipe",
1548815593
" --bom Put a UTF8 byte-order mark at the beginning",
1548915594
" -e Send output to the system text editor",
1549015595
" -x Send output as CSV to a spreadsheet (same as \".excel\")",
@@ -15502,11 +15607,11 @@
1550215607
#endif
1550315608
" --new Initialize FILE to an empty database",
1550415609
" --nofollow Do not follow symbolic links",
1550515610
" --readonly Open FILE readonly",
1550615611
" --zip FILE is a ZIP archive",
15507
-#ifndef SQLITE_SHELL_WASM_MODE
15612
+#ifndef SQLITE_SHELL_FIDDLE
1550815613
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1550915614
" If FILE begins with '|' then open it as a pipe.",
1551015615
" Options:",
1551115616
" --bom Prefix output with a UTF8 byte-order mark",
1551215617
" -e Send output to the system text editor",
@@ -15526,11 +15631,11 @@
1552615631
" --once Do no more than one progress interrupt",
1552715632
" --quiet|-q No output except at interrupts",
1552815633
" --reset Reset the count for each input and interrupt",
1552915634
#endif
1553015635
".prompt MAIN CONTINUE Replace the standard prompts",
15531
-#ifndef SQLITE_SHELL_WASM_MODE
15636
+#ifndef SQLITE_SHELL_FIDDLE
1553215637
".quit Exit this program",
1553315638
".read FILE Read input from FILE or command output",
1553415639
" If FILE begins with \"|\", it is a command that generates the input.",
1553515640
#endif
1553615641
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
@@ -15539,11 +15644,11 @@
1553915644
" --recovery-db NAME Store recovery metadata in database file NAME",
1554015645
" --lost-and-found TABLE Alternative name for the lost-and-found table",
1554115646
" --no-rowids Do not attempt to recover rowid values",
1554215647
" that are not also INTEGER PRIMARY KEYs",
1554315648
#endif
15544
-#ifndef SQLITE_SHELL_WASM_MODE
15649
+#ifndef SQLITE_SHELL_FIDDLE
1554515650
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
1554615651
".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
1554715652
#endif
1554815653
".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
1554915654
".schema ?PATTERN? Show the CREATE statements matching PATTERN",
@@ -15576,24 +15681,24 @@
1557615681
" --sha3-224 Use the sha3-224 algorithm",
1557715682
" --sha3-256 Use the sha3-256 algorithm (default)",
1557815683
" --sha3-384 Use the sha3-384 algorithm",
1557915684
" --sha3-512 Use the sha3-512 algorithm",
1558015685
" Any other argument is a LIKE pattern for tables to hash",
15581
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15686
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
1558215687
".shell CMD ARGS... Run CMD ARGS... in a system shell",
1558315688
#endif
1558415689
".show Show the current values for various settings",
1558515690
".stats ?ARG? Show stats or turn stats on or off",
1558615691
" off Turn off automatic stat display",
1558715692
" on Turn on automatic stat display",
1558815693
" stmt Show statement stats",
1558915694
" vmstep Show the virtual machine step count only",
15590
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15695
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
1559115696
".system CMD ARGS... Run CMD ARGS... in a system shell",
1559215697
#endif
1559315698
".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15594
-#ifndef SQLITE_SHELL_WASM_MODE
15699
+#ifndef SQLITE_SHELL_FIDDLE
1559515700
".testcase NAME Begin redirecting output to 'testcase-out.txt'",
1559615701
#endif
1559715702
".testctrl CMD ... Run various sqlite3_test_control() operations",
1559815703
" Run \".testctrl\" with no arguments for details",
1559915704
".timeout MS Try opening locked tables for MS milliseconds",
@@ -16142,11 +16247,11 @@
1614216247
sqlite3_uint_init(p->db, 0, 0);
1614316248
sqlite3_decimal_init(p->db, 0, 0);
1614416249
sqlite3_regexp_init(p->db, 0, 0);
1614516250
sqlite3_ieee_init(p->db, 0, 0);
1614616251
sqlite3_series_init(p->db, 0, 0);
16147
-#ifndef SQLITE_SHELL_WASM_MODE
16252
+#ifndef SQLITE_SHELL_FIDDLE
1614816253
sqlite3_fileio_init(p->db, 0, 0);
1614916254
sqlite3_completion_init(p->db, 0, 0);
1615016255
#endif
1615116256
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1615216257
sqlite3_dbdata_init(p->db, 0, 0);
@@ -19272,19 +19377,19 @@
1927219377
}
1927319378
}else
1927419379
#endif
1927519380
1927619381
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19277
- && !defined(SQLITE_SHELL_WASM_MODE)
19382
+ && !defined(SQLITE_SHELL_FIDDLE)
1927819383
if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
1927919384
open_db(p, 0);
1928019385
failIfSafeMode(p, "cannot run .archive in safe mode");
1928119386
rc = arDotCommand(p, 0, azArg, nArg);
1928219387
}else
1928319388
#endif
1928419389
19285
-#ifndef SQLITE_SHELL_WASM_MODE
19390
+#ifndef SQLITE_SHELL_FIDDLE
1928619391
if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
1928719392
|| (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
1928819393
){
1928919394
const char *zDestFile = 0;
1929019395
const char *zDb = 0;
@@ -19349,11 +19454,11 @@
1934919454
utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
1935019455
rc = 1;
1935119456
}
1935219457
close_db(pDest);
1935319458
}else
19354
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19459
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
1935519460
1935619461
if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
1935719462
if( nArg==2 ){
1935819463
bail_on_error = booleanValue(azArg[1]);
1935919464
}else{
@@ -19380,11 +19485,11 @@
1938019485
*/
1938119486
if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
1938219487
test_breakpoint();
1938319488
}else
1938419489
19385
-#ifndef SQLITE_SHELL_WASM_MODE
19490
+#ifndef SQLITE_SHELL_FIDDLE
1938619491
if( c=='c' && strcmp(azArg[0],"cd")==0 ){
1938719492
failIfSafeMode(p, "cannot run .cd in safe mode");
1938819493
if( nArg==2 ){
1938919494
#if defined(_WIN32) || defined(WIN32)
1939019495
wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19400,11 +19505,11 @@
1940019505
}else{
1940119506
raw_printf(stderr, "Usage: .cd DIRECTORY\n");
1940219507
rc = 1;
1940319508
}
1940419509
}else
19405
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19510
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
1940619511
1940719512
if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
1940819513
if( nArg==2 ){
1940919514
setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
1941019515
}else{
@@ -19411,11 +19516,11 @@
1941119516
raw_printf(stderr, "Usage: .changes on|off\n");
1941219517
rc = 1;
1941319518
}
1941419519
}else
1941519520
19416
-#ifndef SQLITE_SHELL_WASM_MODE
19521
+#ifndef SQLITE_SHELL_FIDDLE
1941719522
/* Cancel output redirection, if it is currently set (by .testcase)
1941819523
** Then read the content of the testcase-out.txt file and compare against
1941919524
** azArg[1]. If there are differences, report an error and exit.
1942019525
*/
1942119526
if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19436,23 +19541,23 @@
1943619541
utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
1943719542
p->nCheck++;
1943819543
}
1943919544
sqlite3_free(zRes);
1944019545
}else
19441
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19546
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
1944219547
19443
-#ifndef SQLITE_SHELL_WASM_MODE
19548
+#ifndef SQLITE_SHELL_FIDDLE
1944419549
if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
1944519550
failIfSafeMode(p, "cannot run .clone in safe mode");
1944619551
if( nArg==2 ){
1944719552
tryToClone(p, azArg[1]);
1944819553
}else{
1944919554
raw_printf(stderr, "Usage: .clone FILENAME\n");
1945019555
rc = 1;
1945119556
}
1945219557
}else
19453
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19558
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
1945419559
1945519560
if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
1945619561
if( nArg==1 ){
1945719562
/* List available connections */
1945819563
int i;
@@ -19737,11 +19842,11 @@
1973719842
raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
1973819843
rc = 1;
1973919844
}
1974019845
}else
1974119846
19742
-#ifndef SQLITE_SHELL_WASM_MODE
19847
+#ifndef SQLITE_SHELL_FIDDLE
1974319848
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
1974419849
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
1974519850
rc = 2;
1974619851
}else
1974719852
#endif
@@ -19997,11 +20102,11 @@
1999720102
}else{
1999820103
showHelp(p->out, 0);
1999920104
}
2000020105
}else
2000120106
20002
-#ifndef SQLITE_SHELL_WASM_MODE
20107
+#ifndef SQLITE_SHELL_FIDDLE
2000320108
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
2000420109
char *zTable = 0; /* Insert data into this table */
2000520110
char *zSchema = 0; /* within this schema (may default to "main") */
2000620111
char *zFile = 0; /* Name of file to extra content from */
2000720112
sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -20288,11 +20393,11 @@
2028820393
utf8_printf(p->out,
2028920394
"Added %d rows with %d errors using %d lines of input\n",
2029020395
sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
2029120396
}
2029220397
}else
20293
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20398
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2029420399
2029520400
#ifndef SQLITE_UNTESTABLE
2029620401
if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
2029720402
char *zSql;
2029820403
char *zCollist = 0;
@@ -20478,11 +20583,11 @@
2047820583
if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
2047920584
open_db(p, 0);
2048020585
lintDotCommand(p, azArg, nArg);
2048120586
}else
2048220587
20483
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
20588
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
2048420589
if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
2048520590
const char *zFile, *zProc;
2048620591
char *zErrMsg = 0;
2048720592
failIfSafeMode(p, "cannot run .load in safe mode");
2048820593
if( nArg<2 ){
@@ -20500,11 +20605,11 @@
2050020605
rc = 1;
2050120606
}
2050220607
}else
2050320608
#endif
2050420609
20505
-#ifndef SQLITE_SHELL_WASM_MODE
20610
+#ifndef SQLITE_SHELL_FIDDLE
2050620611
if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
2050720612
failIfSafeMode(p, "cannot run .log in safe mode");
2050820613
if( nArg!=2 ){
2050920614
raw_printf(stderr, "Usage: .log FILENAME\n");
2051020615
rc = 1;
@@ -20637,11 +20742,11 @@
2063720742
rc = 1;
2063820743
}
2063920744
p->cMode = p->mode;
2064020745
}else
2064120746
20642
-#ifndef SQLITE_SHELL_WASM_MODE
20747
+#ifndef SQLITE_SHELL_FIDDLE
2064320748
if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
2064420749
if( nArg!=2 ){
2064520750
raw_printf(stderr, "Usage: .nonce NONCE\n");
2064620751
rc = 1;
2064720752
}else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20652,11 +20757,11 @@
2065220757
p->bSafeMode = 0;
2065320758
return 0; /* Return immediately to bypass the safe mode reset
2065420759
** at the end of this procedure */
2065520760
}
2065620761
}else
20657
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20762
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2065820763
2065920764
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
2066020765
if( nArg==2 ){
2066120766
sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
2066220767
"%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20674,11 +20779,11 @@
2067420779
int openMode = SHELL_OPEN_UNSPEC;
2067520780
2067620781
/* Check for command-line arguments */
2067720782
for(iName=1; iName<nArg; iName++){
2067820783
const char *z = azArg[iName];
20679
-#ifndef SQLITE_SHELL_WASM_MODE
20784
+#ifndef SQLITE_SHELL_FIDDLE
2068020785
if( optionMatch(z,"new") ){
2068120786
newFlag = 1;
2068220787
#ifdef SQLITE_HAVE_ZLIB
2068320788
}else if( optionMatch(z, "zip") ){
2068420789
openMode = SHELL_OPEN_ZIPFILE;
@@ -20696,11 +20801,11 @@
2069620801
openMode = SHELL_OPEN_HEXDB;
2069720802
}else if( optionMatch(z, "maxsize") && iName+1<nArg ){
2069820803
p->szMax = integerValue(azArg[++iName]);
2069920804
#endif /* SQLITE_OMIT_DESERIALIZE */
2070020805
}else
20701
-#endif /* !SQLITE_SHELL_WASM_MODE */
20806
+#endif /* !SQLITE_SHELL_FIDDLE */
2070220807
if( z[0]=='-' ){
2070320808
utf8_printf(stderr, "unknown option: %s\n", z);
2070420809
rc = 1;
2070520810
goto meta_command_exit;
2070620811
}else if( zFN ){
@@ -20724,11 +20829,11 @@
2072420829
p->szMax = 0;
2072520830
2072620831
/* If a filename is specified, try to open it first */
2072720832
if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
2072820833
if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20729
-#ifndef SQLITE_SHELL_WASM_MODE
20834
+#ifndef SQLITE_SHELL_FIDDLE
2073020835
if( p->bSafeMode
2073120836
&& p->openMode!=SHELL_OPEN_HEXDB
2073220837
&& zFN
2073320838
&& strcmp(zFN,":memory:")!=0
2073420839
){
@@ -20757,11 +20862,11 @@
2075720862
p->pAuxDb->zDbFilename = 0;
2075820863
open_db(p, 0);
2075920864
}
2076020865
}else
2076120866
20762
-#ifndef SQLITE_SHELL_WASM_MODE
20867
+#ifndef SQLITE_SHELL_FIDDLE
2076320868
if( (c=='o'
2076420869
&& (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
2076520870
|| (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
2076620871
){
2076720872
char *zFile = 0;
@@ -20873,11 +20978,11 @@
2087320978
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2087420979
}
2087520980
}
2087620981
sqlite3_free(zFile);
2087720982
}else
20878
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20983
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2087920984
2088020985
if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
2088120986
open_db(p,0);
2088220987
if( nArg<=1 ) goto parameter_syntax_error;
2088320988
@@ -21043,17 +21148,17 @@
2104321148
if( nArg >= 3) {
2104421149
strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
2104521150
}
2104621151
}else
2104721152
21048
-#ifndef SQLITE_SHELL_WASM_MODE
21153
+#ifndef SQLITE_SHELL_FIDDLE
2104921154
if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
2105021155
rc = 2;
2105121156
}else
2105221157
#endif
2105321158
21054
-#ifndef SQLITE_SHELL_WASM_MODE
21159
+#ifndef SQLITE_SHELL_FIDDLE
2105521160
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
2105621161
FILE *inSaved = p->in;
2105721162
int savedLineno = p->lineno;
2105821163
failIfSafeMode(p, "cannot run .read in safe mode");
2105921164
if( nArg!=2 ){
@@ -21084,13 +21189,13 @@
2108421189
fclose(p->in);
2108521190
}
2108621191
p->in = inSaved;
2108721192
p->lineno = savedLineno;
2108821193
}else
21089
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21194
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2109021195
21091
-#ifndef SQLITE_SHELL_WASM_MODE
21196
+#ifndef SQLITE_SHELL_FIDDLE
2109221197
if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
2109321198
const char *zSrcFile;
2109421199
const char *zDb;
2109521200
sqlite3 *pSrc;
2109621201
sqlite3_backup *pBackup;
@@ -21138,11 +21243,11 @@
2113821243
utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
2113921244
rc = 1;
2114021245
}
2114121246
close_db(pSrc);
2114221247
}else
21143
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21248
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2114421249
2114521250
if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
2114621251
if( nArg==2 ){
2114721252
p->scanstatsOn = (u8)booleanValue(azArg[1]);
2114821253
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21764,11 +21869,11 @@
2176421869
shell_exec(p, zSql, 0);
2176521870
}
2176621871
sqlite3_free(zSql);
2176721872
}else
2176821873
21769
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
21874
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
2177021875
if( c=='s'
2177121876
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
2177221877
){
2177321878
char *zCmd;
2177421879
int i, x;
@@ -21785,11 +21890,11 @@
2178521890
}
2178621891
x = zCmd!=0 ? system(zCmd) : 1;
2178721892
sqlite3_free(zCmd);
2178821893
if( x ) raw_printf(stderr, "System command returns %d\n", x);
2178921894
}else
21790
-#endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE) */
21895
+#endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE) */
2179121896
2179221897
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
2179321898
static const char *azBool[] = { "off", "on", "trigger", "full"};
2179421899
const char *zOut;
2179521900
int i;
@@ -21965,11 +22070,11 @@
2196522070
2196622071
for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
2196722072
sqlite3_free(azResult);
2196822073
}else
2196922074
21970
-#ifndef SQLITE_SHELL_WASM_MODE
22075
+#ifndef SQLITE_SHELL_FIDDLE
2197122076
/* Begin redirecting output to the file "testcase-out.txt" */
2197222077
if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
2197322078
output_reset(p);
2197422079
p->out = output_file_open("testcase-out.txt", 0);
2197522080
if( p->out==0 ){
@@ -21979,11 +22084,11 @@
2197922084
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
2198022085
}else{
2198122086
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
2198222087
}
2198322088
}else
21984
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
22089
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2198522090
2198622091
#ifndef SQLITE_UNTESTABLE
2198722092
if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
2198822093
static const struct {
2198922094
const char *zCtrlName; /* Name of a test-control option */
@@ -22651,11 +22756,11 @@
2265122756
2265222757
static void echo_group_input(ShellState *p, const char *zDo){
2265322758
if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
2265422759
}
2265522760
22656
-#ifdef SQLITE_SHELL_WASM_MODE
22761
+#ifdef SQLITE_SHELL_FIDDLE
2265722762
/*
2265822763
** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
2265922764
** because we need the global shellState and cannot access it from that function
2266022765
** without moving lots of code around (creating a larger/messier diff).
2266122766
*/
@@ -22682,11 +22787,11 @@
2268222787
shell_check_oom(zLine);
2268322788
memcpy(zLine, zBegin, (size_t)nZ);
2268422789
zLine[nZ] = 0;
2268522790
return zLine;
2268622791
}
22687
-#endif /* SQLITE_SHELL_WASM_MODE */
22792
+#endif /* SQLITE_SHELL_FIDDLE */
2268822793
2268922794
/*
2269022795
** Read input from *in and process it. If *in==0 then input
2269122796
** is interactive - the user is typing it it. Otherwise, input
2269222797
** is coming from a file or device. A prompt is issued and history
@@ -23065,11 +23170,11 @@
2306523170
# else
2306623171
# define SQLITE_SHELL_IS_UTF8 (1)
2306723172
# endif
2306823173
#endif
2306923174
23070
-#ifdef SQLITE_SHELL_WASM_MODE
23175
+#ifdef SQLITE_SHELL_FIDDLE
2307123176
# define main fiddle_main
2307223177
#endif
2307323178
2307423179
#if SQLITE_SHELL_IS_UTF8
2307523180
int SQLITE_CDECL main(int argc, char **argv){
@@ -23076,14 +23181,14 @@
2307623181
#else
2307723182
int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
2307823183
char **argv;
2307923184
#endif
2308023185
#ifdef SQLITE_DEBUG
23081
- sqlite3_uint64 mem_main_enter = sqlite3_memory_used();
23186
+ sqlite3_int64 mem_main_enter = sqlite3_memory_used();
2308223187
#endif
2308323188
char *zErrMsg = 0;
23084
-#ifdef SQLITE_SHELL_WASM_MODE
23189
+#ifdef SQLITE_SHELL_FIDDLE
2308523190
# define data shellState
2308623191
#else
2308723192
ShellState data;
2308823193
#endif
2308923194
const char *zInitFile = 0;
@@ -23099,11 +23204,11 @@
2309923204
int argcToFree = 0;
2310023205
#endif
2310123206
2310223207
setBinaryMode(stdin, 0);
2310323208
setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23104
-#ifdef SQLITE_SHELL_WASM_MODE
23209
+#ifdef SQLITE_SHELL_FIDDLE
2310523210
stdin_is_interactive = 0;
2310623211
stdout_is_console = 1;
2310723212
#else
2310823213
stdin_is_interactive = isatty(0);
2310923214
stdout_is_console = isatty(1);
@@ -23361,11 +23466,11 @@
2336123466
utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
2336223467
return 1;
2336323468
#endif
2336423469
}
2336523470
data.out = stdout;
23366
-#ifndef SQLITE_SHELL_WASM_MODE
23471
+#ifndef SQLITE_SHELL_FIDDLE
2336723472
sqlite3_appendvfs_init(0,0,0);
2336823473
#endif
2336923474
2337023475
/* Go ahead and open the database file if it already exists. If the
2337123476
** file does not exist, delay opening it. This prevents empty database
@@ -23629,11 +23734,11 @@
2362923734
}else{
2363023735
data.in = stdin;
2363123736
rc = process_input(&data);
2363223737
}
2363323738
}
23634
-#ifndef SQLITE_SHELL_WASM_MODE
23739
+#ifndef SQLITE_SHELL_FIDDLE
2363523740
/* In WASM mode we have to leave the db state in place so that
2363623741
** client code can "push" SQL into it after this call returns. */
2363723742
free(azCmd);
2363823743
set_table_name(&data, 0);
2363923744
if( data.db ){
@@ -23664,16 +23769,16 @@
2366423769
if( sqlite3_memory_used()>mem_main_enter ){
2366523770
utf8_printf(stderr, "Memory leaked: %u bytes\n",
2366623771
(unsigned int)(sqlite3_memory_used()-mem_main_enter));
2366723772
}
2366823773
#endif
23669
-#endif /* !SQLITE_SHELL_WASM_MODE */
23774
+#endif /* !SQLITE_SHELL_FIDDLE */
2367023775
return rc;
2367123776
}
2367223777
2367323778
23674
-#ifdef SQLITE_SHELL_WASM_MODE
23779
+#ifdef SQLITE_SHELL_FIDDLE
2367523780
/* Only for emcc experimentation purposes. */
2367623781
int fiddle_experiment(int a,int b){
2367723782
return a + b;
2367823783
}
2367923784
@@ -23790,6 +23895,6 @@
2379023895
shellState.wasm.zPos = zSql;
2379123896
process_input(&shellState);
2379223897
memset(&shellState.wasm, 0, sizeof(shellState.wasm));
2379323898
}
2379423899
}
23795
-#endif /* SQLITE_SHELL_WASM_MODE */
23900
+#endif /* SQLITE_SHELL_FIDDLE */
2379623901
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,10 +53,19 @@
53 */
54 #if !defined(SQLITE_OS_WINRT)
55 # define SQLITE_OS_WINRT 0
56 #endif
57
 
 
 
 
 
 
 
 
 
58 /*
59 ** Warning pragmas copied from msvc.h in the core.
60 */
61 #if defined(_MSC_VER)
62 #pragma warning(disable : 4054)
@@ -245,21 +254,10 @@
245 #else
246 # define setBinaryMode(X,Y)
247 # define setTextMode(X,Y)
248 #endif
249
250 /*
251 ** When compiling with emcc (a.k.a. emscripten), we're building a
252 ** WebAssembly (WASM) bundle and need to disable and rewire a few
253 ** things.
254 */
255 #ifdef __EMSCRIPTEN__
256 #define SQLITE_SHELL_WASM_MODE
257 #else
258 #undef SQLITE_SHELL_WASM_MODE
259 #endif
260
261 /* True if the timer is enabled */
262 static int enableTimer = 0;
263
264 /* Return the current wall-clock time */
265 static sqlite3_int64 timeOfDay(void){
@@ -717,11 +715,11 @@
717 **
718 ** The result is stored in space obtained from malloc() and must either
719 ** be freed by the caller or else passed back into this routine via the
720 ** zPrior argument for reuse.
721 */
722 #ifndef SQLITE_SHELL_WASM_MODE
723 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
724 char *zPrompt;
725 char *zResult;
726 if( in!=0 ){
727 zResult = local_getline(zPrior, in);
@@ -737,11 +735,11 @@
737 if( zResult && *zResult ) shell_add_history(zResult);
738 #endif
739 }
740 return zResult;
741 }
742 #endif /* !SQLITE_SHELL_WASM_MODE */
743
744 /*
745 ** Return the value of a hexadecimal digit. Return -1 if the input
746 ** is not a hex digit.
747 */
@@ -3794,10 +3792,11 @@
3794 #define re_compile sqlite3re_compile
3795 #define re_free sqlite3re_free
3796
3797 /* The end-of-input character */
3798 #define RE_EOF 0 /* End of input */
 
3799
3800 /* The NFA is implemented as sequence of opcodes taken from the following
3801 ** set. Each opcode has a single integer argument.
3802 */
3803 #define RE_OP_MATCH 1 /* Match the one character in the argument */
@@ -3815,10 +3814,37 @@
3815 #define RE_OP_DIGIT 13 /* digit: [0-9] */
3816 #define RE_OP_NOTDIGIT 14 /* Not a digit */
3817 #define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
3818 #define RE_OP_NOTSPACE 16 /* Not a digit */
3819 #define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3820
3821 /* Each opcode is a "state" in the NFA */
3822 typedef unsigned short ReStateNumber;
3823
3824 /* Because this is an NFA and not a DFA, multiple states can be active at
@@ -3849,11 +3875,11 @@
3849 const char *zErr; /* Error message to return */
3850 char *aOp; /* Operators for the virtual machine */
3851 int *aArg; /* Arguments to each operator */
3852 unsigned (*xNextChar)(ReInput*); /* Next character function */
3853 unsigned char zInit[12]; /* Initial text to match */
3854 int nInit; /* Number of characters in zInit */
3855 unsigned nState; /* Number of entries in aOp[] and aArg[] */
3856 unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
3857 };
3858
3859 /* Add a state to the given state set if it is not already there */
@@ -3922,11 +3948,11 @@
3922 ReStateSet aStateSet[2], *pThis, *pNext;
3923 ReStateNumber aSpace[100];
3924 ReStateNumber *pToFree;
3925 unsigned int i = 0;
3926 unsigned int iSwap = 0;
3927 int c = RE_EOF+1;
3928 int cPrev = 0;
3929 int rc = 0;
3930 ReInput in;
3931
3932 in.z = zIn;
@@ -3941,10 +3967,11 @@
3941 strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
3942 ){
3943 in.i++;
3944 }
3945 if( in.i+pRe->nInit>in.mx ) return 0;
 
3946 }
3947
3948 if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
3949 pToFree = 0;
3950 aStateSet[0].aState = aSpace;
@@ -3968,10 +3995,14 @@
3968 int x = pThis->aState[i];
3969 switch( pRe->aOp[x] ){
3970 case RE_OP_MATCH: {
3971 if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
3972 break;
 
 
 
 
3973 }
3974 case RE_OP_ANY: {
3975 if( c!=0 ) re_add_state(pNext, x+1);
3976 break;
3977 }
@@ -4050,11 +4081,13 @@
4050 }
4051 }
4052 }
4053 }
4054 for(i=0; i<pNext->nState; i++){
4055 if( pRe->aOp[pNext->aState[i]]==RE_OP_ACCEPT ){ rc = 1; break; }
 
 
4056 }
4057 re_match_end:
4058 sqlite3_free(pToFree);
4059 return rc;
4060 }
@@ -4205,11 +4238,10 @@
4205 const char *zErr;
4206 while( (c = p->xNextChar(&p->sIn))!=0 ){
4207 iStart = p->nState;
4208 switch( c ){
4209 case '|':
4210 case '$':
4211 case ')': {
4212 p->sIn.i--;
4213 return 0;
4214 }
4215 case '(': {
@@ -4241,10 +4273,18 @@
4241 }
4242 case '?': {
4243 if( iPrev<0 ) return "'?' without operand";
4244 re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
4245 break;
 
 
 
 
 
 
 
 
4246 }
4247 case '{': {
4248 int m = 0, n = 0;
4249 int sz, j;
4250 if( iPrev<0 ) return "'{m,n}' without operand";
@@ -4260,10 +4300,11 @@
4260 p->sIn.i++;
4261 sz = p->nState - iPrev;
4262 if( m==0 ){
4263 if( n==0 ) return "both m and n are zero in '{m,n}'";
4264 re_insert(p, iPrev, RE_OP_FORK, sz+1);
 
4265 n--;
4266 }else{
4267 for(j=1; j<m; j++) re_copy(p, iPrev, sz);
4268 }
4269 for(j=m; j<n; j++){
@@ -4378,15 +4419,11 @@
4378 zErr = re_subcompile_re(pRe);
4379 if( zErr ){
4380 re_free(pRe);
4381 return zErr;
4382 }
4383 if( rePeek(pRe)=='$' && pRe->sIn.i+1>=pRe->sIn.mx ){
4384 re_append(pRe, RE_OP_MATCH, RE_EOF);
4385 re_append(pRe, RE_OP_ACCEPT, 0);
4386 *ppRe = pRe;
4387 }else if( pRe->sIn.i>=pRe->sIn.mx ){
4388 re_append(pRe, RE_OP_ACCEPT, 0);
4389 *ppRe = pRe;
4390 }else{
4391 re_free(pRe);
4392 return "unrecognized character";
@@ -4407,11 +4444,11 @@
4407 pRe->zInit[j++] = (unsigned char)x;
4408 }else if( x<=0xfff ){
4409 pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6));
4410 pRe->zInit[j++] = 0x80 | (x&0x3f);
4411 }else if( x<=0xffff ){
4412 pRe->zInit[j++] = (unsigned char)(0xd0 | (x>>12));
4413 pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f);
4414 pRe->zInit[j++] = 0x80 | (x&0x3f);
4415 }else{
4416 break;
4417 }
@@ -4465,10 +4502,71 @@
4465 }
4466 if( setAux ){
4467 sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
4468 }
4469 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4470
4471 /*
4472 ** Invoke this routine to register the regexp() function with the
4473 ** SQLite database connection.
4474 */
@@ -4490,16 +4588,23 @@
4490 /* The regexpi(PATTERN,STRING) function is a case-insensitive version
4491 ** of regexp(PATTERN,STRING). */
4492 rc = sqlite3_create_function(db, "regexpi", 2,
4493 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
4494 (void*)db, re_sql_func, 0, 0);
 
 
 
 
 
 
 
4495 }
4496 return rc;
4497 }
4498
4499 /************************* End ../ext/misc/regexp.c ********************/
4500 #ifndef SQLITE_SHELL_WASM_MODE
4501 /************************* Begin ../ext/misc/fileio.c ******************/
4502 /*
4503 ** 2014-06-13
4504 **
4505 ** The author disclaims copyright to this source code. In place of
@@ -12248,19 +12353,19 @@
12248 int nIndent; /* Size of array aiIndent[] */
12249 int iIndent; /* Index of current op in aiIndent[] */
12250 char *zNonce; /* Nonce for temporary safe-mode excapes */
12251 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
12252 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12253 #ifdef SQLITE_SHELL_WASM_MODE
12254 struct {
12255 const char * zInput; /* Input string from wasm/JS proxy */
12256 const char * zPos; /* Cursor pos into zInput */
12257 } wasm;
12258 #endif
12259 };
12260
12261 #ifdef SQLITE_SHELL_WASM_MODE
12262 static ShellState shellState;
12263 #endif
12264
12265
12266 /* Allowed values for ShellState.autoEQP
@@ -12924,11 +13029,11 @@
12924 UNUSED_PARAMETER(zA2);
12925 UNUSED_PARAMETER(zA3);
12926 UNUSED_PARAMETER(zA4);
12927 switch( op ){
12928 case SQLITE_ATTACH: {
12929 #ifndef SQLITE_SHELL_WASM_MODE
12930 /* In WASM builds the filesystem is a virtual sandbox, so
12931 ** there's no harm in using ATTACH. */
12932 failIfSafeMode(p, "cannot run ATTACH in safe mode");
12933 #endif
12934 break;
@@ -15338,11 +15443,11 @@
15338 ** There must be two or more spaces between the end of the command and the
15339 ** start of the description of what that command does.
15340 */
15341 static const char *(azHelp[]) = {
15342 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15343 && !defined(SQLITE_SHELL_WASM_MODE)
15344 ".archive ... Manage SQL archives",
15345 " Each command must have exactly one of the following options:",
15346 " -c, --create Create a new archive",
15347 " -u, --update Add or update files with changed mtime",
15348 " -i, --insert Like -u but always add even if unchanged",
@@ -15364,23 +15469,23 @@
15364 " http://sqlite.org/cli.html#sqlite_archive_support",
15365 #endif
15366 #ifndef SQLITE_OMIT_AUTHORIZATION
15367 ".auth ON|OFF Show authorizer callbacks",
15368 #endif
15369 #ifndef SQLITE_SHELL_WASM_MODE
15370 ".backup ?DB? FILE Backup DB (default \"main\") to FILE",
15371 " Options:",
15372 " --append Use the appendvfs",
15373 " --async Write to FILE without journal and fsync()",
15374 #endif
15375 ".bail on|off Stop after hitting an error. Default OFF",
15376 ".binary on|off Turn binary output on or off. Default OFF",
15377 #ifndef SQLITE_SHELL_WASM_MODE
15378 ".cd DIRECTORY Change the working directory to DIRECTORY",
15379 #endif
15380 ".changes on|off Show number of rows changed by SQL",
15381 #ifndef SQLITE_SHELL_WASM_MODE
15382 ".check GLOB Fail if output since .testcase does not match",
15383 ".clone NEWDB Clone data into NEWDB from the existing database",
15384 #endif
15385 ".connection [close] [#] Open or close an auxiliary database connection",
15386 ".databases List names and files of attached databases",
@@ -15402,15 +15507,15 @@
15402 #ifdef SQLITE_DEBUG
15403 " test Show raw EXPLAIN QUERY PLAN output",
15404 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
15405 #endif
15406 " trigger Like \"full\" but also show trigger bytecode",
15407 #ifndef SQLITE_SHELL_WASM_MODE
15408 ".excel Display the output of next command in spreadsheet",
15409 " --bom Put a UTF8 byte-order mark on intermediate file",
15410 #endif
15411 #ifndef SQLITE_SHELL_WASM_MODE
15412 ".exit ?CODE? Exit this program with return-code CODE",
15413 #endif
15414 ".expert EXPERIMENTAL. Suggest indexes for queries",
15415 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
15416 ".filectrl CMD ... Run various sqlite3_file_control() operations",
@@ -15417,11 +15522,11 @@
15417 " --schema SCHEMA Use SCHEMA instead of \"main\"",
15418 " --help Show CMD details",
15419 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
15420 ".headers on|off Turn display of headers on or off",
15421 ".help ?-all? ?PATTERN? Show help text for PATTERN",
15422 #ifndef SQLITE_SHELL_WASM_MODE
15423 ".import FILE TABLE Import data from FILE into TABLE",
15424 " Options:",
15425 " --ascii Use \\037 and \\036 as column and row separators",
15426 " --csv Use , and \\n as column and row separators",
15427 " --skip N Skip the first N rows of input",
@@ -15446,14 +15551,14 @@
15446 #endif
15447 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
15448 ".lint OPTIONS Report potential schema issues.",
15449 " Options:",
15450 " fkey-indexes Find missing foreign key indexes",
15451 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
15452 ".load FILE ?ENTRY? Load an extension library",
15453 #endif
15454 #ifndef SQLITE_SHELL_WASM_MODE
15455 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15456 #endif
15457 ".mode MODE ?OPTIONS? Set output mode",
15458 " MODE is one of:",
15459 " ascii Columns/rows delimited by 0x1F and 0x1E",
@@ -15476,15 +15581,15 @@
15476 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
15477 " --ww Shorthand for \"--wordwrap 1\"",
15478 " --quote Quote output text as SQL literals",
15479 " --noquote Do not quote output text",
15480 " TABLE The name of SQL table used for \"insert\" mode",
15481 #ifndef SQLITE_SHELL_WASM_MODE
15482 ".nonce STRING Suspend safe mode for one command if nonce matches",
15483 #endif
15484 ".nullvalue STRING Use STRING in place of NULL values",
15485 #ifndef SQLITE_SHELL_WASM_MODE
15486 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
15487 " If FILE begins with '|' then open as a pipe",
15488 " --bom Put a UTF8 byte-order mark at the beginning",
15489 " -e Send output to the system text editor",
15490 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
@@ -15502,11 +15607,11 @@
15502 #endif
15503 " --new Initialize FILE to an empty database",
15504 " --nofollow Do not follow symbolic links",
15505 " --readonly Open FILE readonly",
15506 " --zip FILE is a ZIP archive",
15507 #ifndef SQLITE_SHELL_WASM_MODE
15508 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
15509 " If FILE begins with '|' then open it as a pipe.",
15510 " Options:",
15511 " --bom Prefix output with a UTF8 byte-order mark",
15512 " -e Send output to the system text editor",
@@ -15526,11 +15631,11 @@
15526 " --once Do no more than one progress interrupt",
15527 " --quiet|-q No output except at interrupts",
15528 " --reset Reset the count for each input and interrupt",
15529 #endif
15530 ".prompt MAIN CONTINUE Replace the standard prompts",
15531 #ifndef SQLITE_SHELL_WASM_MODE
15532 ".quit Exit this program",
15533 ".read FILE Read input from FILE or command output",
15534 " If FILE begins with \"|\", it is a command that generates the input.",
15535 #endif
15536 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
@@ -15539,11 +15644,11 @@
15539 " --recovery-db NAME Store recovery metadata in database file NAME",
15540 " --lost-and-found TABLE Alternative name for the lost-and-found table",
15541 " --no-rowids Do not attempt to recover rowid values",
15542 " that are not also INTEGER PRIMARY KEYs",
15543 #endif
15544 #ifndef SQLITE_SHELL_WASM_MODE
15545 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
15546 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
15547 #endif
15548 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
15549 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
@@ -15576,24 +15681,24 @@
15576 " --sha3-224 Use the sha3-224 algorithm",
15577 " --sha3-256 Use the sha3-256 algorithm (default)",
15578 " --sha3-384 Use the sha3-384 algorithm",
15579 " --sha3-512 Use the sha3-512 algorithm",
15580 " Any other argument is a LIKE pattern for tables to hash",
15581 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15582 ".shell CMD ARGS... Run CMD ARGS... in a system shell",
15583 #endif
15584 ".show Show the current values for various settings",
15585 ".stats ?ARG? Show stats or turn stats on or off",
15586 " off Turn off automatic stat display",
15587 " on Turn on automatic stat display",
15588 " stmt Show statement stats",
15589 " vmstep Show the virtual machine step count only",
15590 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15591 ".system CMD ARGS... Run CMD ARGS... in a system shell",
15592 #endif
15593 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15594 #ifndef SQLITE_SHELL_WASM_MODE
15595 ".testcase NAME Begin redirecting output to 'testcase-out.txt'",
15596 #endif
15597 ".testctrl CMD ... Run various sqlite3_test_control() operations",
15598 " Run \".testctrl\" with no arguments for details",
15599 ".timeout MS Try opening locked tables for MS milliseconds",
@@ -16142,11 +16247,11 @@
16142 sqlite3_uint_init(p->db, 0, 0);
16143 sqlite3_decimal_init(p->db, 0, 0);
16144 sqlite3_regexp_init(p->db, 0, 0);
16145 sqlite3_ieee_init(p->db, 0, 0);
16146 sqlite3_series_init(p->db, 0, 0);
16147 #ifndef SQLITE_SHELL_WASM_MODE
16148 sqlite3_fileio_init(p->db, 0, 0);
16149 sqlite3_completion_init(p->db, 0, 0);
16150 #endif
16151 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16152 sqlite3_dbdata_init(p->db, 0, 0);
@@ -19272,19 +19377,19 @@
19272 }
19273 }else
19274 #endif
19275
19276 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19277 && !defined(SQLITE_SHELL_WASM_MODE)
19278 if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
19279 open_db(p, 0);
19280 failIfSafeMode(p, "cannot run .archive in safe mode");
19281 rc = arDotCommand(p, 0, azArg, nArg);
19282 }else
19283 #endif
19284
19285 #ifndef SQLITE_SHELL_WASM_MODE
19286 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
19287 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
19288 ){
19289 const char *zDestFile = 0;
19290 const char *zDb = 0;
@@ -19349,11 +19454,11 @@
19349 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
19350 rc = 1;
19351 }
19352 close_db(pDest);
19353 }else
19354 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19355
19356 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
19357 if( nArg==2 ){
19358 bail_on_error = booleanValue(azArg[1]);
19359 }else{
@@ -19380,11 +19485,11 @@
19380 */
19381 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
19382 test_breakpoint();
19383 }else
19384
19385 #ifndef SQLITE_SHELL_WASM_MODE
19386 if( c=='c' && strcmp(azArg[0],"cd")==0 ){
19387 failIfSafeMode(p, "cannot run .cd in safe mode");
19388 if( nArg==2 ){
19389 #if defined(_WIN32) || defined(WIN32)
19390 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19400,11 +19505,11 @@
19400 }else{
19401 raw_printf(stderr, "Usage: .cd DIRECTORY\n");
19402 rc = 1;
19403 }
19404 }else
19405 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19406
19407 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
19408 if( nArg==2 ){
19409 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
19410 }else{
@@ -19411,11 +19516,11 @@
19411 raw_printf(stderr, "Usage: .changes on|off\n");
19412 rc = 1;
19413 }
19414 }else
19415
19416 #ifndef SQLITE_SHELL_WASM_MODE
19417 /* Cancel output redirection, if it is currently set (by .testcase)
19418 ** Then read the content of the testcase-out.txt file and compare against
19419 ** azArg[1]. If there are differences, report an error and exit.
19420 */
19421 if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19436,23 +19541,23 @@
19436 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
19437 p->nCheck++;
19438 }
19439 sqlite3_free(zRes);
19440 }else
19441 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19442
19443 #ifndef SQLITE_SHELL_WASM_MODE
19444 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
19445 failIfSafeMode(p, "cannot run .clone in safe mode");
19446 if( nArg==2 ){
19447 tryToClone(p, azArg[1]);
19448 }else{
19449 raw_printf(stderr, "Usage: .clone FILENAME\n");
19450 rc = 1;
19451 }
19452 }else
19453 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19454
19455 if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
19456 if( nArg==1 ){
19457 /* List available connections */
19458 int i;
@@ -19737,11 +19842,11 @@
19737 raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
19738 rc = 1;
19739 }
19740 }else
19741
19742 #ifndef SQLITE_SHELL_WASM_MODE
19743 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
19744 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
19745 rc = 2;
19746 }else
19747 #endif
@@ -19997,11 +20102,11 @@
19997 }else{
19998 showHelp(p->out, 0);
19999 }
20000 }else
20001
20002 #ifndef SQLITE_SHELL_WASM_MODE
20003 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
20004 char *zTable = 0; /* Insert data into this table */
20005 char *zSchema = 0; /* within this schema (may default to "main") */
20006 char *zFile = 0; /* Name of file to extra content from */
20007 sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -20288,11 +20393,11 @@
20288 utf8_printf(p->out,
20289 "Added %d rows with %d errors using %d lines of input\n",
20290 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
20291 }
20292 }else
20293 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20294
20295 #ifndef SQLITE_UNTESTABLE
20296 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
20297 char *zSql;
20298 char *zCollist = 0;
@@ -20478,11 +20583,11 @@
20478 if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
20479 open_db(p, 0);
20480 lintDotCommand(p, azArg, nArg);
20481 }else
20482
20483 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
20484 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
20485 const char *zFile, *zProc;
20486 char *zErrMsg = 0;
20487 failIfSafeMode(p, "cannot run .load in safe mode");
20488 if( nArg<2 ){
@@ -20500,11 +20605,11 @@
20500 rc = 1;
20501 }
20502 }else
20503 #endif
20504
20505 #ifndef SQLITE_SHELL_WASM_MODE
20506 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
20507 failIfSafeMode(p, "cannot run .log in safe mode");
20508 if( nArg!=2 ){
20509 raw_printf(stderr, "Usage: .log FILENAME\n");
20510 rc = 1;
@@ -20637,11 +20742,11 @@
20637 rc = 1;
20638 }
20639 p->cMode = p->mode;
20640 }else
20641
20642 #ifndef SQLITE_SHELL_WASM_MODE
20643 if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
20644 if( nArg!=2 ){
20645 raw_printf(stderr, "Usage: .nonce NONCE\n");
20646 rc = 1;
20647 }else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20652,11 +20757,11 @@
20652 p->bSafeMode = 0;
20653 return 0; /* Return immediately to bypass the safe mode reset
20654 ** at the end of this procedure */
20655 }
20656 }else
20657 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20658
20659 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
20660 if( nArg==2 ){
20661 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
20662 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20674,11 +20779,11 @@
20674 int openMode = SHELL_OPEN_UNSPEC;
20675
20676 /* Check for command-line arguments */
20677 for(iName=1; iName<nArg; iName++){
20678 const char *z = azArg[iName];
20679 #ifndef SQLITE_SHELL_WASM_MODE
20680 if( optionMatch(z,"new") ){
20681 newFlag = 1;
20682 #ifdef SQLITE_HAVE_ZLIB
20683 }else if( optionMatch(z, "zip") ){
20684 openMode = SHELL_OPEN_ZIPFILE;
@@ -20696,11 +20801,11 @@
20696 openMode = SHELL_OPEN_HEXDB;
20697 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
20698 p->szMax = integerValue(azArg[++iName]);
20699 #endif /* SQLITE_OMIT_DESERIALIZE */
20700 }else
20701 #endif /* !SQLITE_SHELL_WASM_MODE */
20702 if( z[0]=='-' ){
20703 utf8_printf(stderr, "unknown option: %s\n", z);
20704 rc = 1;
20705 goto meta_command_exit;
20706 }else if( zFN ){
@@ -20724,11 +20829,11 @@
20724 p->szMax = 0;
20725
20726 /* If a filename is specified, try to open it first */
20727 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
20728 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20729 #ifndef SQLITE_SHELL_WASM_MODE
20730 if( p->bSafeMode
20731 && p->openMode!=SHELL_OPEN_HEXDB
20732 && zFN
20733 && strcmp(zFN,":memory:")!=0
20734 ){
@@ -20757,11 +20862,11 @@
20757 p->pAuxDb->zDbFilename = 0;
20758 open_db(p, 0);
20759 }
20760 }else
20761
20762 #ifndef SQLITE_SHELL_WASM_MODE
20763 if( (c=='o'
20764 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
20765 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
20766 ){
20767 char *zFile = 0;
@@ -20873,11 +20978,11 @@
20873 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20874 }
20875 }
20876 sqlite3_free(zFile);
20877 }else
20878 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20879
20880 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
20881 open_db(p,0);
20882 if( nArg<=1 ) goto parameter_syntax_error;
20883
@@ -21043,17 +21148,17 @@
21043 if( nArg >= 3) {
21044 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
21045 }
21046 }else
21047
21048 #ifndef SQLITE_SHELL_WASM_MODE
21049 if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
21050 rc = 2;
21051 }else
21052 #endif
21053
21054 #ifndef SQLITE_SHELL_WASM_MODE
21055 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
21056 FILE *inSaved = p->in;
21057 int savedLineno = p->lineno;
21058 failIfSafeMode(p, "cannot run .read in safe mode");
21059 if( nArg!=2 ){
@@ -21084,13 +21189,13 @@
21084 fclose(p->in);
21085 }
21086 p->in = inSaved;
21087 p->lineno = savedLineno;
21088 }else
21089 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21090
21091 #ifndef SQLITE_SHELL_WASM_MODE
21092 if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
21093 const char *zSrcFile;
21094 const char *zDb;
21095 sqlite3 *pSrc;
21096 sqlite3_backup *pBackup;
@@ -21138,11 +21243,11 @@
21138 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
21139 rc = 1;
21140 }
21141 close_db(pSrc);
21142 }else
21143 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21144
21145 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
21146 if( nArg==2 ){
21147 p->scanstatsOn = (u8)booleanValue(azArg[1]);
21148 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21764,11 +21869,11 @@
21764 shell_exec(p, zSql, 0);
21765 }
21766 sqlite3_free(zSql);
21767 }else
21768
21769 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
21770 if( c=='s'
21771 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
21772 ){
21773 char *zCmd;
21774 int i, x;
@@ -21785,11 +21890,11 @@
21785 }
21786 x = zCmd!=0 ? system(zCmd) : 1;
21787 sqlite3_free(zCmd);
21788 if( x ) raw_printf(stderr, "System command returns %d\n", x);
21789 }else
21790 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE) */
21791
21792 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
21793 static const char *azBool[] = { "off", "on", "trigger", "full"};
21794 const char *zOut;
21795 int i;
@@ -21965,11 +22070,11 @@
21965
21966 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
21967 sqlite3_free(azResult);
21968 }else
21969
21970 #ifndef SQLITE_SHELL_WASM_MODE
21971 /* Begin redirecting output to the file "testcase-out.txt" */
21972 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
21973 output_reset(p);
21974 p->out = output_file_open("testcase-out.txt", 0);
21975 if( p->out==0 ){
@@ -21979,11 +22084,11 @@
21979 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
21980 }else{
21981 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
21982 }
21983 }else
21984 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21985
21986 #ifndef SQLITE_UNTESTABLE
21987 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
21988 static const struct {
21989 const char *zCtrlName; /* Name of a test-control option */
@@ -22651,11 +22756,11 @@
22651
22652 static void echo_group_input(ShellState *p, const char *zDo){
22653 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
22654 }
22655
22656 #ifdef SQLITE_SHELL_WASM_MODE
22657 /*
22658 ** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
22659 ** because we need the global shellState and cannot access it from that function
22660 ** without moving lots of code around (creating a larger/messier diff).
22661 */
@@ -22682,11 +22787,11 @@
22682 shell_check_oom(zLine);
22683 memcpy(zLine, zBegin, (size_t)nZ);
22684 zLine[nZ] = 0;
22685 return zLine;
22686 }
22687 #endif /* SQLITE_SHELL_WASM_MODE */
22688
22689 /*
22690 ** Read input from *in and process it. If *in==0 then input
22691 ** is interactive - the user is typing it it. Otherwise, input
22692 ** is coming from a file or device. A prompt is issued and history
@@ -23065,11 +23170,11 @@
23065 # else
23066 # define SQLITE_SHELL_IS_UTF8 (1)
23067 # endif
23068 #endif
23069
23070 #ifdef SQLITE_SHELL_WASM_MODE
23071 # define main fiddle_main
23072 #endif
23073
23074 #if SQLITE_SHELL_IS_UTF8
23075 int SQLITE_CDECL main(int argc, char **argv){
@@ -23076,14 +23181,14 @@
23076 #else
23077 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
23078 char **argv;
23079 #endif
23080 #ifdef SQLITE_DEBUG
23081 sqlite3_uint64 mem_main_enter = sqlite3_memory_used();
23082 #endif
23083 char *zErrMsg = 0;
23084 #ifdef SQLITE_SHELL_WASM_MODE
23085 # define data shellState
23086 #else
23087 ShellState data;
23088 #endif
23089 const char *zInitFile = 0;
@@ -23099,11 +23204,11 @@
23099 int argcToFree = 0;
23100 #endif
23101
23102 setBinaryMode(stdin, 0);
23103 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23104 #ifdef SQLITE_SHELL_WASM_MODE
23105 stdin_is_interactive = 0;
23106 stdout_is_console = 1;
23107 #else
23108 stdin_is_interactive = isatty(0);
23109 stdout_is_console = isatty(1);
@@ -23361,11 +23466,11 @@
23361 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
23362 return 1;
23363 #endif
23364 }
23365 data.out = stdout;
23366 #ifndef SQLITE_SHELL_WASM_MODE
23367 sqlite3_appendvfs_init(0,0,0);
23368 #endif
23369
23370 /* Go ahead and open the database file if it already exists. If the
23371 ** file does not exist, delay opening it. This prevents empty database
@@ -23629,11 +23734,11 @@
23629 }else{
23630 data.in = stdin;
23631 rc = process_input(&data);
23632 }
23633 }
23634 #ifndef SQLITE_SHELL_WASM_MODE
23635 /* In WASM mode we have to leave the db state in place so that
23636 ** client code can "push" SQL into it after this call returns. */
23637 free(azCmd);
23638 set_table_name(&data, 0);
23639 if( data.db ){
@@ -23664,16 +23769,16 @@
23664 if( sqlite3_memory_used()>mem_main_enter ){
23665 utf8_printf(stderr, "Memory leaked: %u bytes\n",
23666 (unsigned int)(sqlite3_memory_used()-mem_main_enter));
23667 }
23668 #endif
23669 #endif /* !SQLITE_SHELL_WASM_MODE */
23670 return rc;
23671 }
23672
23673
23674 #ifdef SQLITE_SHELL_WASM_MODE
23675 /* Only for emcc experimentation purposes. */
23676 int fiddle_experiment(int a,int b){
23677 return a + b;
23678 }
23679
@@ -23790,6 +23895,6 @@
23790 shellState.wasm.zPos = zSql;
23791 process_input(&shellState);
23792 memset(&shellState.wasm, 0, sizeof(shellState.wasm));
23793 }
23794 }
23795 #endif /* SQLITE_SHELL_WASM_MODE */
23796
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,10 +53,19 @@
53 */
54 #if !defined(SQLITE_OS_WINRT)
55 # define SQLITE_OS_WINRT 0
56 #endif
57
58 /*
59 ** If SQLITE_SHELL_FIDDLE is defined then the shell is modified
60 ** somewhat for use as a WASM module in a web browser. This flag
61 ** should only be used when building the "fiddle" web application, as
62 ** the browser-mode build has much different user input requirements
63 ** and this build mode rewires the user input subsystem to account for
64 ** that.
65 */
66
67 /*
68 ** Warning pragmas copied from msvc.h in the core.
69 */
70 #if defined(_MSC_VER)
71 #pragma warning(disable : 4054)
@@ -245,21 +254,10 @@
254 #else
255 # define setBinaryMode(X,Y)
256 # define setTextMode(X,Y)
257 #endif
258
 
 
 
 
 
 
 
 
 
 
 
259 /* True if the timer is enabled */
260 static int enableTimer = 0;
261
262 /* Return the current wall-clock time */
263 static sqlite3_int64 timeOfDay(void){
@@ -717,11 +715,11 @@
715 **
716 ** The result is stored in space obtained from malloc() and must either
717 ** be freed by the caller or else passed back into this routine via the
718 ** zPrior argument for reuse.
719 */
720 #ifndef SQLITE_SHELL_FIDDLE
721 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
722 char *zPrompt;
723 char *zResult;
724 if( in!=0 ){
725 zResult = local_getline(zPrior, in);
@@ -737,11 +735,11 @@
735 if( zResult && *zResult ) shell_add_history(zResult);
736 #endif
737 }
738 return zResult;
739 }
740 #endif /* !SQLITE_SHELL_FIDDLE */
741
742 /*
743 ** Return the value of a hexadecimal digit. Return -1 if the input
744 ** is not a hex digit.
745 */
@@ -3794,10 +3792,11 @@
3792 #define re_compile sqlite3re_compile
3793 #define re_free sqlite3re_free
3794
3795 /* The end-of-input character */
3796 #define RE_EOF 0 /* End of input */
3797 #define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */
3798
3799 /* The NFA is implemented as sequence of opcodes taken from the following
3800 ** set. Each opcode has a single integer argument.
3801 */
3802 #define RE_OP_MATCH 1 /* Match the one character in the argument */
@@ -3815,10 +3814,37 @@
3814 #define RE_OP_DIGIT 13 /* digit: [0-9] */
3815 #define RE_OP_NOTDIGIT 14 /* Not a digit */
3816 #define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
3817 #define RE_OP_NOTSPACE 16 /* Not a digit */
3818 #define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
3819 #define RE_OP_ATSTART 18 /* Currently at the start of the string */
3820
3821 #if defined(SQLITE_DEBUG)
3822 /* Opcode names used for symbolic debugging */
3823 static const char *ReOpName[] = {
3824 "EOF",
3825 "MATCH",
3826 "ANY",
3827 "ANYSTAR",
3828 "FORK",
3829 "GOTO",
3830 "ACCEPT",
3831 "CC_INC",
3832 "CC_EXC",
3833 "CC_VALUE",
3834 "CC_RANGE",
3835 "WORD",
3836 "NOTWORD",
3837 "DIGIT",
3838 "NOTDIGIT",
3839 "SPACE",
3840 "NOTSPACE",
3841 "BOUNDARY",
3842 "ATSTART",
3843 };
3844 #endif /* SQLITE_DEBUG */
3845
3846
3847 /* Each opcode is a "state" in the NFA */
3848 typedef unsigned short ReStateNumber;
3849
3850 /* Because this is an NFA and not a DFA, multiple states can be active at
@@ -3849,11 +3875,11 @@
3875 const char *zErr; /* Error message to return */
3876 char *aOp; /* Operators for the virtual machine */
3877 int *aArg; /* Arguments to each operator */
3878 unsigned (*xNextChar)(ReInput*); /* Next character function */
3879 unsigned char zInit[12]; /* Initial text to match */
3880 int nInit; /* Number of bytes in zInit */
3881 unsigned nState; /* Number of entries in aOp[] and aArg[] */
3882 unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
3883 };
3884
3885 /* Add a state to the given state set if it is not already there */
@@ -3922,11 +3948,11 @@
3948 ReStateSet aStateSet[2], *pThis, *pNext;
3949 ReStateNumber aSpace[100];
3950 ReStateNumber *pToFree;
3951 unsigned int i = 0;
3952 unsigned int iSwap = 0;
3953 int c = RE_START;
3954 int cPrev = 0;
3955 int rc = 0;
3956 ReInput in;
3957
3958 in.z = zIn;
@@ -3941,10 +3967,11 @@
3967 strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
3968 ){
3969 in.i++;
3970 }
3971 if( in.i+pRe->nInit>in.mx ) return 0;
3972 c = RE_START-1;
3973 }
3974
3975 if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
3976 pToFree = 0;
3977 aStateSet[0].aState = aSpace;
@@ -3968,10 +3995,14 @@
3995 int x = pThis->aState[i];
3996 switch( pRe->aOp[x] ){
3997 case RE_OP_MATCH: {
3998 if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
3999 break;
4000 }
4001 case RE_OP_ATSTART: {
4002 if( cPrev==RE_START ) re_add_state(pThis, x+1);
4003 break;
4004 }
4005 case RE_OP_ANY: {
4006 if( c!=0 ) re_add_state(pNext, x+1);
4007 break;
4008 }
@@ -4050,11 +4081,13 @@
4081 }
4082 }
4083 }
4084 }
4085 for(i=0; i<pNext->nState; i++){
4086 int x = pNext->aState[i];
4087 while( pRe->aOp[x]==RE_OP_GOTO ) x += pRe->aArg[x];
4088 if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; }
4089 }
4090 re_match_end:
4091 sqlite3_free(pToFree);
4092 return rc;
4093 }
@@ -4205,11 +4238,10 @@
4238 const char *zErr;
4239 while( (c = p->xNextChar(&p->sIn))!=0 ){
4240 iStart = p->nState;
4241 switch( c ){
4242 case '|':
 
4243 case ')': {
4244 p->sIn.i--;
4245 return 0;
4246 }
4247 case '(': {
@@ -4241,10 +4273,18 @@
4273 }
4274 case '?': {
4275 if( iPrev<0 ) return "'?' without operand";
4276 re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
4277 break;
4278 }
4279 case '$': {
4280 re_append(p, RE_OP_MATCH, RE_EOF);
4281 break;
4282 }
4283 case '^': {
4284 re_append(p, RE_OP_ATSTART, 0);
4285 break;
4286 }
4287 case '{': {
4288 int m = 0, n = 0;
4289 int sz, j;
4290 if( iPrev<0 ) return "'{m,n}' without operand";
@@ -4260,10 +4300,11 @@
4300 p->sIn.i++;
4301 sz = p->nState - iPrev;
4302 if( m==0 ){
4303 if( n==0 ) return "both m and n are zero in '{m,n}'";
4304 re_insert(p, iPrev, RE_OP_FORK, sz+1);
4305 iPrev++;
4306 n--;
4307 }else{
4308 for(j=1; j<m; j++) re_copy(p, iPrev, sz);
4309 }
4310 for(j=m; j<n; j++){
@@ -4378,15 +4419,11 @@
4419 zErr = re_subcompile_re(pRe);
4420 if( zErr ){
4421 re_free(pRe);
4422 return zErr;
4423 }
4424 if( pRe->sIn.i>=pRe->sIn.mx ){
 
 
 
 
4425 re_append(pRe, RE_OP_ACCEPT, 0);
4426 *ppRe = pRe;
4427 }else{
4428 re_free(pRe);
4429 return "unrecognized character";
@@ -4407,11 +4444,11 @@
4444 pRe->zInit[j++] = (unsigned char)x;
4445 }else if( x<=0xfff ){
4446 pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6));
4447 pRe->zInit[j++] = 0x80 | (x&0x3f);
4448 }else if( x<=0xffff ){
4449 pRe->zInit[j++] = (unsigned char)(0xe0 | (x>>12));
4450 pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f);
4451 pRe->zInit[j++] = 0x80 | (x&0x3f);
4452 }else{
4453 break;
4454 }
@@ -4465,10 +4502,71 @@
4502 }
4503 if( setAux ){
4504 sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
4505 }
4506 }
4507
4508 #if defined(SQLITE_DEBUG)
4509 /*
4510 ** This function is used for testing and debugging only. It is only available
4511 ** if the SQLITE_DEBUG compile-time option is used.
4512 **
4513 ** Compile a regular expression and then convert the compiled expression into
4514 ** text and return that text.
4515 */
4516 static void re_bytecode_func(
4517 sqlite3_context *context,
4518 int argc,
4519 sqlite3_value **argv
4520 ){
4521 const char *zPattern;
4522 const char *zErr;
4523 ReCompiled *pRe;
4524 sqlite3_str *pStr;
4525 int i;
4526 int n;
4527 char *z;
4528
4529 zPattern = (const char*)sqlite3_value_text(argv[0]);
4530 if( zPattern==0 ) return;
4531 zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
4532 if( zErr ){
4533 re_free(pRe);
4534 sqlite3_result_error(context, zErr, -1);
4535 return;
4536 }
4537 if( pRe==0 ){
4538 sqlite3_result_error_nomem(context);
4539 return;
4540 }
4541 pStr = sqlite3_str_new(0);
4542 if( pStr==0 ) goto re_bytecode_func_err;
4543 if( pRe->nInit>0 ){
4544 sqlite3_str_appendf(pStr, "INIT ");
4545 for(i=0; i<pRe->nInit; i++){
4546 sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
4547 }
4548 sqlite3_str_appendf(pStr, "\n");
4549 }
4550 for(i=0; i<pRe->nState; i++){
4551 sqlite3_str_appendf(pStr, "%-8s %4d\n",
4552 ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
4553 }
4554 n = sqlite3_str_length(pStr);
4555 z = sqlite3_str_finish(pStr);
4556 if( n==0 ){
4557 sqlite3_free(z);
4558 }else{
4559 sqlite3_result_text(context, z, n-1, sqlite3_free);
4560 }
4561
4562 re_bytecode_func_err:
4563 re_free(pRe);
4564 }
4565
4566 #endif /* SQLITE_DEBUG */
4567
4568
4569 /*
4570 ** Invoke this routine to register the regexp() function with the
4571 ** SQLite database connection.
4572 */
@@ -4490,16 +4588,23 @@
4588 /* The regexpi(PATTERN,STRING) function is a case-insensitive version
4589 ** of regexp(PATTERN,STRING). */
4590 rc = sqlite3_create_function(db, "regexpi", 2,
4591 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
4592 (void*)db, re_sql_func, 0, 0);
4593 #if defined(SQLITE_DEBUG)
4594 if( rc==SQLITE_OK ){
4595 rc = sqlite3_create_function(db, "regexp_bytecode", 1,
4596 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
4597 0, re_bytecode_func, 0, 0);
4598 }
4599 #endif /* SQLITE_DEBUG */
4600 }
4601 return rc;
4602 }
4603
4604 /************************* End ../ext/misc/regexp.c ********************/
4605 #ifndef SQLITE_SHELL_FIDDLE
4606 /************************* Begin ../ext/misc/fileio.c ******************/
4607 /*
4608 ** 2014-06-13
4609 **
4610 ** The author disclaims copyright to this source code. In place of
@@ -12248,19 +12353,19 @@
12353 int nIndent; /* Size of array aiIndent[] */
12354 int iIndent; /* Index of current op in aiIndent[] */
12355 char *zNonce; /* Nonce for temporary safe-mode excapes */
12356 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
12357 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12358 #ifdef SQLITE_SHELL_FIDDLE
12359 struct {
12360 const char * zInput; /* Input string from wasm/JS proxy */
12361 const char * zPos; /* Cursor pos into zInput */
12362 } wasm;
12363 #endif
12364 };
12365
12366 #ifdef SQLITE_SHELL_FIDDLE
12367 static ShellState shellState;
12368 #endif
12369
12370
12371 /* Allowed values for ShellState.autoEQP
@@ -12924,11 +13029,11 @@
13029 UNUSED_PARAMETER(zA2);
13030 UNUSED_PARAMETER(zA3);
13031 UNUSED_PARAMETER(zA4);
13032 switch( op ){
13033 case SQLITE_ATTACH: {
13034 #ifndef SQLITE_SHELL_FIDDLE
13035 /* In WASM builds the filesystem is a virtual sandbox, so
13036 ** there's no harm in using ATTACH. */
13037 failIfSafeMode(p, "cannot run ATTACH in safe mode");
13038 #endif
13039 break;
@@ -15338,11 +15443,11 @@
15443 ** There must be two or more spaces between the end of the command and the
15444 ** start of the description of what that command does.
15445 */
15446 static const char *(azHelp[]) = {
15447 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15448 && !defined(SQLITE_SHELL_FIDDLE)
15449 ".archive ... Manage SQL archives",
15450 " Each command must have exactly one of the following options:",
15451 " -c, --create Create a new archive",
15452 " -u, --update Add or update files with changed mtime",
15453 " -i, --insert Like -u but always add even if unchanged",
@@ -15364,23 +15469,23 @@
15469 " http://sqlite.org/cli.html#sqlite_archive_support",
15470 #endif
15471 #ifndef SQLITE_OMIT_AUTHORIZATION
15472 ".auth ON|OFF Show authorizer callbacks",
15473 #endif
15474 #ifndef SQLITE_SHELL_FIDDLE
15475 ".backup ?DB? FILE Backup DB (default \"main\") to FILE",
15476 " Options:",
15477 " --append Use the appendvfs",
15478 " --async Write to FILE without journal and fsync()",
15479 #endif
15480 ".bail on|off Stop after hitting an error. Default OFF",
15481 ".binary on|off Turn binary output on or off. Default OFF",
15482 #ifndef SQLITE_SHELL_FIDDLE
15483 ".cd DIRECTORY Change the working directory to DIRECTORY",
15484 #endif
15485 ".changes on|off Show number of rows changed by SQL",
15486 #ifndef SQLITE_SHELL_FIDDLE
15487 ".check GLOB Fail if output since .testcase does not match",
15488 ".clone NEWDB Clone data into NEWDB from the existing database",
15489 #endif
15490 ".connection [close] [#] Open or close an auxiliary database connection",
15491 ".databases List names and files of attached databases",
@@ -15402,15 +15507,15 @@
15507 #ifdef SQLITE_DEBUG
15508 " test Show raw EXPLAIN QUERY PLAN output",
15509 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
15510 #endif
15511 " trigger Like \"full\" but also show trigger bytecode",
15512 #ifndef SQLITE_SHELL_FIDDLE
15513 ".excel Display the output of next command in spreadsheet",
15514 " --bom Put a UTF8 byte-order mark on intermediate file",
15515 #endif
15516 #ifndef SQLITE_SHELL_FIDDLE
15517 ".exit ?CODE? Exit this program with return-code CODE",
15518 #endif
15519 ".expert EXPERIMENTAL. Suggest indexes for queries",
15520 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
15521 ".filectrl CMD ... Run various sqlite3_file_control() operations",
@@ -15417,11 +15522,11 @@
15522 " --schema SCHEMA Use SCHEMA instead of \"main\"",
15523 " --help Show CMD details",
15524 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
15525 ".headers on|off Turn display of headers on or off",
15526 ".help ?-all? ?PATTERN? Show help text for PATTERN",
15527 #ifndef SQLITE_SHELL_FIDDLE
15528 ".import FILE TABLE Import data from FILE into TABLE",
15529 " Options:",
15530 " --ascii Use \\037 and \\036 as column and row separators",
15531 " --csv Use , and \\n as column and row separators",
15532 " --skip N Skip the first N rows of input",
@@ -15446,14 +15551,14 @@
15551 #endif
15552 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
15553 ".lint OPTIONS Report potential schema issues.",
15554 " Options:",
15555 " fkey-indexes Find missing foreign key indexes",
15556 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
15557 ".load FILE ?ENTRY? Load an extension library",
15558 #endif
15559 #ifndef SQLITE_SHELL_FIDDLE
15560 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15561 #endif
15562 ".mode MODE ?OPTIONS? Set output mode",
15563 " MODE is one of:",
15564 " ascii Columns/rows delimited by 0x1F and 0x1E",
@@ -15476,15 +15581,15 @@
15581 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
15582 " --ww Shorthand for \"--wordwrap 1\"",
15583 " --quote Quote output text as SQL literals",
15584 " --noquote Do not quote output text",
15585 " TABLE The name of SQL table used for \"insert\" mode",
15586 #ifndef SQLITE_SHELL_FIDDLE
15587 ".nonce STRING Suspend safe mode for one command if nonce matches",
15588 #endif
15589 ".nullvalue STRING Use STRING in place of NULL values",
15590 #ifndef SQLITE_SHELL_FIDDLE
15591 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
15592 " If FILE begins with '|' then open as a pipe",
15593 " --bom Put a UTF8 byte-order mark at the beginning",
15594 " -e Send output to the system text editor",
15595 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
@@ -15502,11 +15607,11 @@
15607 #endif
15608 " --new Initialize FILE to an empty database",
15609 " --nofollow Do not follow symbolic links",
15610 " --readonly Open FILE readonly",
15611 " --zip FILE is a ZIP archive",
15612 #ifndef SQLITE_SHELL_FIDDLE
15613 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
15614 " If FILE begins with '|' then open it as a pipe.",
15615 " Options:",
15616 " --bom Prefix output with a UTF8 byte-order mark",
15617 " -e Send output to the system text editor",
@@ -15526,11 +15631,11 @@
15631 " --once Do no more than one progress interrupt",
15632 " --quiet|-q No output except at interrupts",
15633 " --reset Reset the count for each input and interrupt",
15634 #endif
15635 ".prompt MAIN CONTINUE Replace the standard prompts",
15636 #ifndef SQLITE_SHELL_FIDDLE
15637 ".quit Exit this program",
15638 ".read FILE Read input from FILE or command output",
15639 " If FILE begins with \"|\", it is a command that generates the input.",
15640 #endif
15641 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
@@ -15539,11 +15644,11 @@
15644 " --recovery-db NAME Store recovery metadata in database file NAME",
15645 " --lost-and-found TABLE Alternative name for the lost-and-found table",
15646 " --no-rowids Do not attempt to recover rowid values",
15647 " that are not also INTEGER PRIMARY KEYs",
15648 #endif
15649 #ifndef SQLITE_SHELL_FIDDLE
15650 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
15651 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
15652 #endif
15653 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
15654 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
@@ -15576,24 +15681,24 @@
15681 " --sha3-224 Use the sha3-224 algorithm",
15682 " --sha3-256 Use the sha3-256 algorithm (default)",
15683 " --sha3-384 Use the sha3-384 algorithm",
15684 " --sha3-512 Use the sha3-512 algorithm",
15685 " Any other argument is a LIKE pattern for tables to hash",
15686 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
15687 ".shell CMD ARGS... Run CMD ARGS... in a system shell",
15688 #endif
15689 ".show Show the current values for various settings",
15690 ".stats ?ARG? Show stats or turn stats on or off",
15691 " off Turn off automatic stat display",
15692 " on Turn on automatic stat display",
15693 " stmt Show statement stats",
15694 " vmstep Show the virtual machine step count only",
15695 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
15696 ".system CMD ARGS... Run CMD ARGS... in a system shell",
15697 #endif
15698 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15699 #ifndef SQLITE_SHELL_FIDDLE
15700 ".testcase NAME Begin redirecting output to 'testcase-out.txt'",
15701 #endif
15702 ".testctrl CMD ... Run various sqlite3_test_control() operations",
15703 " Run \".testctrl\" with no arguments for details",
15704 ".timeout MS Try opening locked tables for MS milliseconds",
@@ -16142,11 +16247,11 @@
16247 sqlite3_uint_init(p->db, 0, 0);
16248 sqlite3_decimal_init(p->db, 0, 0);
16249 sqlite3_regexp_init(p->db, 0, 0);
16250 sqlite3_ieee_init(p->db, 0, 0);
16251 sqlite3_series_init(p->db, 0, 0);
16252 #ifndef SQLITE_SHELL_FIDDLE
16253 sqlite3_fileio_init(p->db, 0, 0);
16254 sqlite3_completion_init(p->db, 0, 0);
16255 #endif
16256 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16257 sqlite3_dbdata_init(p->db, 0, 0);
@@ -19272,19 +19377,19 @@
19377 }
19378 }else
19379 #endif
19380
19381 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19382 && !defined(SQLITE_SHELL_FIDDLE)
19383 if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
19384 open_db(p, 0);
19385 failIfSafeMode(p, "cannot run .archive in safe mode");
19386 rc = arDotCommand(p, 0, azArg, nArg);
19387 }else
19388 #endif
19389
19390 #ifndef SQLITE_SHELL_FIDDLE
19391 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
19392 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
19393 ){
19394 const char *zDestFile = 0;
19395 const char *zDb = 0;
@@ -19349,11 +19454,11 @@
19454 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
19455 rc = 1;
19456 }
19457 close_db(pDest);
19458 }else
19459 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
19460
19461 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
19462 if( nArg==2 ){
19463 bail_on_error = booleanValue(azArg[1]);
19464 }else{
@@ -19380,11 +19485,11 @@
19485 */
19486 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
19487 test_breakpoint();
19488 }else
19489
19490 #ifndef SQLITE_SHELL_FIDDLE
19491 if( c=='c' && strcmp(azArg[0],"cd")==0 ){
19492 failIfSafeMode(p, "cannot run .cd in safe mode");
19493 if( nArg==2 ){
19494 #if defined(_WIN32) || defined(WIN32)
19495 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19400,11 +19505,11 @@
19505 }else{
19506 raw_printf(stderr, "Usage: .cd DIRECTORY\n");
19507 rc = 1;
19508 }
19509 }else
19510 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
19511
19512 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
19513 if( nArg==2 ){
19514 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
19515 }else{
@@ -19411,11 +19516,11 @@
19516 raw_printf(stderr, "Usage: .changes on|off\n");
19517 rc = 1;
19518 }
19519 }else
19520
19521 #ifndef SQLITE_SHELL_FIDDLE
19522 /* Cancel output redirection, if it is currently set (by .testcase)
19523 ** Then read the content of the testcase-out.txt file and compare against
19524 ** azArg[1]. If there are differences, report an error and exit.
19525 */
19526 if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19436,23 +19541,23 @@
19541 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
19542 p->nCheck++;
19543 }
19544 sqlite3_free(zRes);
19545 }else
19546 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
19547
19548 #ifndef SQLITE_SHELL_FIDDLE
19549 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
19550 failIfSafeMode(p, "cannot run .clone in safe mode");
19551 if( nArg==2 ){
19552 tryToClone(p, azArg[1]);
19553 }else{
19554 raw_printf(stderr, "Usage: .clone FILENAME\n");
19555 rc = 1;
19556 }
19557 }else
19558 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
19559
19560 if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
19561 if( nArg==1 ){
19562 /* List available connections */
19563 int i;
@@ -19737,11 +19842,11 @@
19842 raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
19843 rc = 1;
19844 }
19845 }else
19846
19847 #ifndef SQLITE_SHELL_FIDDLE
19848 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
19849 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
19850 rc = 2;
19851 }else
19852 #endif
@@ -19997,11 +20102,11 @@
20102 }else{
20103 showHelp(p->out, 0);
20104 }
20105 }else
20106
20107 #ifndef SQLITE_SHELL_FIDDLE
20108 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
20109 char *zTable = 0; /* Insert data into this table */
20110 char *zSchema = 0; /* within this schema (may default to "main") */
20111 char *zFile = 0; /* Name of file to extra content from */
20112 sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -20288,11 +20393,11 @@
20393 utf8_printf(p->out,
20394 "Added %d rows with %d errors using %d lines of input\n",
20395 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
20396 }
20397 }else
20398 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
20399
20400 #ifndef SQLITE_UNTESTABLE
20401 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
20402 char *zSql;
20403 char *zCollist = 0;
@@ -20478,11 +20583,11 @@
20583 if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
20584 open_db(p, 0);
20585 lintDotCommand(p, azArg, nArg);
20586 }else
20587
20588 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
20589 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
20590 const char *zFile, *zProc;
20591 char *zErrMsg = 0;
20592 failIfSafeMode(p, "cannot run .load in safe mode");
20593 if( nArg<2 ){
@@ -20500,11 +20605,11 @@
20605 rc = 1;
20606 }
20607 }else
20608 #endif
20609
20610 #ifndef SQLITE_SHELL_FIDDLE
20611 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
20612 failIfSafeMode(p, "cannot run .log in safe mode");
20613 if( nArg!=2 ){
20614 raw_printf(stderr, "Usage: .log FILENAME\n");
20615 rc = 1;
@@ -20637,11 +20742,11 @@
20742 rc = 1;
20743 }
20744 p->cMode = p->mode;
20745 }else
20746
20747 #ifndef SQLITE_SHELL_FIDDLE
20748 if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
20749 if( nArg!=2 ){
20750 raw_printf(stderr, "Usage: .nonce NONCE\n");
20751 rc = 1;
20752 }else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20652,11 +20757,11 @@
20757 p->bSafeMode = 0;
20758 return 0; /* Return immediately to bypass the safe mode reset
20759 ** at the end of this procedure */
20760 }
20761 }else
20762 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
20763
20764 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
20765 if( nArg==2 ){
20766 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
20767 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20674,11 +20779,11 @@
20779 int openMode = SHELL_OPEN_UNSPEC;
20780
20781 /* Check for command-line arguments */
20782 for(iName=1; iName<nArg; iName++){
20783 const char *z = azArg[iName];
20784 #ifndef SQLITE_SHELL_FIDDLE
20785 if( optionMatch(z,"new") ){
20786 newFlag = 1;
20787 #ifdef SQLITE_HAVE_ZLIB
20788 }else if( optionMatch(z, "zip") ){
20789 openMode = SHELL_OPEN_ZIPFILE;
@@ -20696,11 +20801,11 @@
20801 openMode = SHELL_OPEN_HEXDB;
20802 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
20803 p->szMax = integerValue(azArg[++iName]);
20804 #endif /* SQLITE_OMIT_DESERIALIZE */
20805 }else
20806 #endif /* !SQLITE_SHELL_FIDDLE */
20807 if( z[0]=='-' ){
20808 utf8_printf(stderr, "unknown option: %s\n", z);
20809 rc = 1;
20810 goto meta_command_exit;
20811 }else if( zFN ){
@@ -20724,11 +20829,11 @@
20829 p->szMax = 0;
20830
20831 /* If a filename is specified, try to open it first */
20832 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
20833 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20834 #ifndef SQLITE_SHELL_FIDDLE
20835 if( p->bSafeMode
20836 && p->openMode!=SHELL_OPEN_HEXDB
20837 && zFN
20838 && strcmp(zFN,":memory:")!=0
20839 ){
@@ -20757,11 +20862,11 @@
20862 p->pAuxDb->zDbFilename = 0;
20863 open_db(p, 0);
20864 }
20865 }else
20866
20867 #ifndef SQLITE_SHELL_FIDDLE
20868 if( (c=='o'
20869 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
20870 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
20871 ){
20872 char *zFile = 0;
@@ -20873,11 +20978,11 @@
20978 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20979 }
20980 }
20981 sqlite3_free(zFile);
20982 }else
20983 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
20984
20985 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
20986 open_db(p,0);
20987 if( nArg<=1 ) goto parameter_syntax_error;
20988
@@ -21043,17 +21148,17 @@
21148 if( nArg >= 3) {
21149 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
21150 }
21151 }else
21152
21153 #ifndef SQLITE_SHELL_FIDDLE
21154 if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
21155 rc = 2;
21156 }else
21157 #endif
21158
21159 #ifndef SQLITE_SHELL_FIDDLE
21160 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
21161 FILE *inSaved = p->in;
21162 int savedLineno = p->lineno;
21163 failIfSafeMode(p, "cannot run .read in safe mode");
21164 if( nArg!=2 ){
@@ -21084,13 +21189,13 @@
21189 fclose(p->in);
21190 }
21191 p->in = inSaved;
21192 p->lineno = savedLineno;
21193 }else
21194 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
21195
21196 #ifndef SQLITE_SHELL_FIDDLE
21197 if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
21198 const char *zSrcFile;
21199 const char *zDb;
21200 sqlite3 *pSrc;
21201 sqlite3_backup *pBackup;
@@ -21138,11 +21243,11 @@
21243 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
21244 rc = 1;
21245 }
21246 close_db(pSrc);
21247 }else
21248 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
21249
21250 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
21251 if( nArg==2 ){
21252 p->scanstatsOn = (u8)booleanValue(azArg[1]);
21253 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21764,11 +21869,11 @@
21869 shell_exec(p, zSql, 0);
21870 }
21871 sqlite3_free(zSql);
21872 }else
21873
21874 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
21875 if( c=='s'
21876 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
21877 ){
21878 char *zCmd;
21879 int i, x;
@@ -21785,11 +21890,11 @@
21890 }
21891 x = zCmd!=0 ? system(zCmd) : 1;
21892 sqlite3_free(zCmd);
21893 if( x ) raw_printf(stderr, "System command returns %d\n", x);
21894 }else
21895 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE) */
21896
21897 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
21898 static const char *azBool[] = { "off", "on", "trigger", "full"};
21899 const char *zOut;
21900 int i;
@@ -21965,11 +22070,11 @@
22070
22071 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
22072 sqlite3_free(azResult);
22073 }else
22074
22075 #ifndef SQLITE_SHELL_FIDDLE
22076 /* Begin redirecting output to the file "testcase-out.txt" */
22077 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
22078 output_reset(p);
22079 p->out = output_file_open("testcase-out.txt", 0);
22080 if( p->out==0 ){
@@ -21979,11 +22084,11 @@
22084 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
22085 }else{
22086 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
22087 }
22088 }else
22089 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
22090
22091 #ifndef SQLITE_UNTESTABLE
22092 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
22093 static const struct {
22094 const char *zCtrlName; /* Name of a test-control option */
@@ -22651,11 +22756,11 @@
22756
22757 static void echo_group_input(ShellState *p, const char *zDo){
22758 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
22759 }
22760
22761 #ifdef SQLITE_SHELL_FIDDLE
22762 /*
22763 ** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
22764 ** because we need the global shellState and cannot access it from that function
22765 ** without moving lots of code around (creating a larger/messier diff).
22766 */
@@ -22682,11 +22787,11 @@
22787 shell_check_oom(zLine);
22788 memcpy(zLine, zBegin, (size_t)nZ);
22789 zLine[nZ] = 0;
22790 return zLine;
22791 }
22792 #endif /* SQLITE_SHELL_FIDDLE */
22793
22794 /*
22795 ** Read input from *in and process it. If *in==0 then input
22796 ** is interactive - the user is typing it it. Otherwise, input
22797 ** is coming from a file or device. A prompt is issued and history
@@ -23065,11 +23170,11 @@
23170 # else
23171 # define SQLITE_SHELL_IS_UTF8 (1)
23172 # endif
23173 #endif
23174
23175 #ifdef SQLITE_SHELL_FIDDLE
23176 # define main fiddle_main
23177 #endif
23178
23179 #if SQLITE_SHELL_IS_UTF8
23180 int SQLITE_CDECL main(int argc, char **argv){
@@ -23076,14 +23181,14 @@
23181 #else
23182 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
23183 char **argv;
23184 #endif
23185 #ifdef SQLITE_DEBUG
23186 sqlite3_int64 mem_main_enter = sqlite3_memory_used();
23187 #endif
23188 char *zErrMsg = 0;
23189 #ifdef SQLITE_SHELL_FIDDLE
23190 # define data shellState
23191 #else
23192 ShellState data;
23193 #endif
23194 const char *zInitFile = 0;
@@ -23099,11 +23204,11 @@
23204 int argcToFree = 0;
23205 #endif
23206
23207 setBinaryMode(stdin, 0);
23208 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23209 #ifdef SQLITE_SHELL_FIDDLE
23210 stdin_is_interactive = 0;
23211 stdout_is_console = 1;
23212 #else
23213 stdin_is_interactive = isatty(0);
23214 stdout_is_console = isatty(1);
@@ -23361,11 +23466,11 @@
23466 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
23467 return 1;
23468 #endif
23469 }
23470 data.out = stdout;
23471 #ifndef SQLITE_SHELL_FIDDLE
23472 sqlite3_appendvfs_init(0,0,0);
23473 #endif
23474
23475 /* Go ahead and open the database file if it already exists. If the
23476 ** file does not exist, delay opening it. This prevents empty database
@@ -23629,11 +23734,11 @@
23734 }else{
23735 data.in = stdin;
23736 rc = process_input(&data);
23737 }
23738 }
23739 #ifndef SQLITE_SHELL_FIDDLE
23740 /* In WASM mode we have to leave the db state in place so that
23741 ** client code can "push" SQL into it after this call returns. */
23742 free(azCmd);
23743 set_table_name(&data, 0);
23744 if( data.db ){
@@ -23664,16 +23769,16 @@
23769 if( sqlite3_memory_used()>mem_main_enter ){
23770 utf8_printf(stderr, "Memory leaked: %u bytes\n",
23771 (unsigned int)(sqlite3_memory_used()-mem_main_enter));
23772 }
23773 #endif
23774 #endif /* !SQLITE_SHELL_FIDDLE */
23775 return rc;
23776 }
23777
23778
23779 #ifdef SQLITE_SHELL_FIDDLE
23780 /* Only for emcc experimentation purposes. */
23781 int fiddle_experiment(int a,int b){
23782 return a + b;
23783 }
23784
@@ -23790,6 +23895,6 @@
23895 shellState.wasm.zPos = zSql;
23896 process_input(&shellState);
23897 memset(&shellState.wasm, 0, sizeof(shellState.wasm));
23898 }
23899 }
23900 #endif /* SQLITE_SHELL_FIDDLE */
23901
+374 -281
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.39.0. By combining all the individual C code files into this
3
+** version 3.40.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -450,13 +450,13 @@
450450
**
451451
** See also: [sqlite3_libversion()],
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455
-#define SQLITE_VERSION "3.39.0"
456
-#define SQLITE_VERSION_NUMBER 3039000
457
-#define SQLITE_SOURCE_ID "2022-06-25 14:57:57 14e166f40dbfa6e055543f8301525f2ca2e96a02a57269818b9e69e162e98918"
455
+#define SQLITE_VERSION "3.40.0"
456
+#define SQLITE_VERSION_NUMBER 3040000
457
+#define SQLITE_SOURCE_ID "2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -6586,11 +6586,11 @@
65866586
** CAPI3REF: Return The Schema Name For A Database Connection
65876587
** METHOD: sqlite3
65886588
**
65896589
** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
65906590
** for the N-th database on database connection D, or a NULL pointer of N is
6591
-** out of range. An N alue of 0 means the main database file. An N of 1 is
6591
+** out of range. An N value of 0 means the main database file. An N of 1 is
65926592
** the "temp" schema. Larger values of N correspond to various ATTACH-ed
65936593
** databases.
65946594
**
65956595
** Space to hold the string that is returned by sqlite3_db_name() is managed
65966596
** by SQLite itself. The string might be deallocated by any operation that
@@ -15553,67 +15553,67 @@
1555315553
#define OP_Checkpoint 3
1555415554
#define OP_JournalMode 4
1555515555
#define OP_Vacuum 5
1555615556
#define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */
1555715557
#define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */
15558
-#define OP_Goto 8 /* jump */
15559
-#define OP_Gosub 9 /* jump */
15560
-#define OP_InitCoroutine 10 /* jump */
15561
-#define OP_Yield 11 /* jump */
15562
-#define OP_MustBeInt 12 /* jump */
15563
-#define OP_Jump 13 /* jump */
15564
-#define OP_Once 14 /* jump */
15565
-#define OP_If 15 /* jump */
15566
-#define OP_IfNot 16 /* jump */
15567
-#define OP_IsNullOrType 17 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
15568
-#define OP_IfNullRow 18 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15558
+#define OP_Init 8 /* jump, synopsis: Start at P2 */
15559
+#define OP_Goto 9 /* jump */
15560
+#define OP_Gosub 10 /* jump */
15561
+#define OP_InitCoroutine 11 /* jump */
15562
+#define OP_Yield 12 /* jump */
15563
+#define OP_MustBeInt 13 /* jump */
15564
+#define OP_Jump 14 /* jump */
15565
+#define OP_Once 15 /* jump */
15566
+#define OP_If 16 /* jump */
15567
+#define OP_IfNot 17 /* jump */
15568
+#define OP_IsNullOrType 18 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
1556915569
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
15570
-#define OP_SeekLT 20 /* jump, synopsis: key=r[P3@P4] */
15571
-#define OP_SeekLE 21 /* jump, synopsis: key=r[P3@P4] */
15572
-#define OP_SeekGE 22 /* jump, synopsis: key=r[P3@P4] */
15573
-#define OP_SeekGT 23 /* jump, synopsis: key=r[P3@P4] */
15574
-#define OP_IfNotOpen 24 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15575
-#define OP_IfNoHope 25 /* jump, synopsis: key=r[P3@P4] */
15576
-#define OP_NoConflict 26 /* jump, synopsis: key=r[P3@P4] */
15577
-#define OP_NotFound 27 /* jump, synopsis: key=r[P3@P4] */
15578
-#define OP_Found 28 /* jump, synopsis: key=r[P3@P4] */
15579
-#define OP_SeekRowid 29 /* jump, synopsis: intkey=r[P3] */
15580
-#define OP_NotExists 30 /* jump, synopsis: intkey=r[P3] */
15581
-#define OP_Last 31 /* jump */
15582
-#define OP_IfSmaller 32 /* jump */
15583
-#define OP_SorterSort 33 /* jump */
15584
-#define OP_Sort 34 /* jump */
15585
-#define OP_Rewind 35 /* jump */
15586
-#define OP_SorterNext 36 /* jump */
15587
-#define OP_Prev 37 /* jump */
15588
-#define OP_Next 38 /* jump */
15589
-#define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */
15590
-#define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */
15591
-#define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */
15592
-#define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */
15570
+#define OP_IfNullRow 20 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15571
+#define OP_SeekLT 21 /* jump, synopsis: key=r[P3@P4] */
15572
+#define OP_SeekLE 22 /* jump, synopsis: key=r[P3@P4] */
15573
+#define OP_SeekGE 23 /* jump, synopsis: key=r[P3@P4] */
15574
+#define OP_SeekGT 24 /* jump, synopsis: key=r[P3@P4] */
15575
+#define OP_IfNotOpen 25 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15576
+#define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */
15577
+#define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */
15578
+#define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
15579
+#define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
15580
+#define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
15581
+#define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
15582
+#define OP_Last 32 /* jump */
15583
+#define OP_IfSmaller 33 /* jump */
15584
+#define OP_SorterSort 34 /* jump */
15585
+#define OP_Sort 35 /* jump */
15586
+#define OP_Rewind 36 /* jump */
15587
+#define OP_SorterNext 37 /* jump */
15588
+#define OP_Prev 38 /* jump */
15589
+#define OP_Next 39 /* jump */
15590
+#define OP_IdxLE 40 /* jump, synopsis: key=r[P3@P4] */
15591
+#define OP_IdxGT 41 /* jump, synopsis: key=r[P3@P4] */
15592
+#define OP_IdxLT 42 /* jump, synopsis: key=r[P3@P4] */
1559315593
#define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
1559415594
#define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15595
-#define OP_RowSetRead 45 /* jump, synopsis: r[P3]=rowset(P1) */
15596
-#define OP_RowSetTest 46 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15597
-#define OP_Program 47 /* jump */
15598
-#define OP_FkIfZero 48 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15599
-#define OP_IfPos 49 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15595
+#define OP_IdxGE 45 /* jump, synopsis: key=r[P3@P4] */
15596
+#define OP_RowSetRead 46 /* jump, synopsis: r[P3]=rowset(P1) */
15597
+#define OP_RowSetTest 47 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15598
+#define OP_Program 48 /* jump */
15599
+#define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
1560015600
#define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
1560115601
#define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
1560215602
#define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
1560315603
#define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
1560415604
#define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
1560515605
#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
1560615606
#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
1560715607
#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
1560815608
#define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15609
-#define OP_IfNotZero 59 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15610
-#define OP_DecrJumpZero 60 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15611
-#define OP_IncrVacuum 61 /* jump */
15612
-#define OP_VNext 62 /* jump */
15613
-#define OP_Filter 63 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
15614
-#define OP_Init 64 /* jump, synopsis: Start at P2 */
15609
+#define OP_IfPos 59 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15610
+#define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15611
+#define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15612
+#define OP_IncrVacuum 62 /* jump */
15613
+#define OP_VNext 63 /* jump */
15614
+#define OP_Filter 64 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
1561515615
#define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */
1561615616
#define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */
1561715617
#define OP_Return 67
1561815618
#define OP_EndCoroutine 68
1561915619
#define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */
@@ -15745,17 +15745,17 @@
1574515745
#define OPFLG_IN3 0x08 /* in3: P3 is an input */
1574615746
#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
1574715747
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
1574815748
#define OPFLG_INITIALIZER {\
1574915749
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
15750
-/* 8 */ 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x03,\
15751
-/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x09, 0x09, 0x09, 0x09,\
15752
-/* 24 */ 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x01,\
15750
+/* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
15751
+/* 16 */ 0x03, 0x03, 0x03, 0x12, 0x01, 0x09, 0x09, 0x09,\
15752
+/* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
1575315753
/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15754
-/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\
15755
-/* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15756
-/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\
15754
+/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\
15755
+/* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15756
+/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
1575715757
/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
1575815758
/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
1575915759
/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
1576015760
/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
1576115761
/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
@@ -19777,18 +19777,20 @@
1977719777
SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
1977819778
SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
1977919779
SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
1978019780
SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
1978119781
SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19782
+#if TREETRACE_ENABLED
1978219783
SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
1978319784
const ExprList*,const Expr*, const Trigger*);
1978419785
SQLITE_PRIVATE void sqlite3TreeViewInsert(const With*, const SrcList*,
1978519786
const IdList*, const Select*, const ExprList*,
1978619787
int, const Upsert*, const Trigger*);
1978719788
SQLITE_PRIVATE void sqlite3TreeViewUpdate(const With*, const SrcList*, const ExprList*,
1978819789
const Expr*, int, const ExprList*, const Expr*,
1978919790
const Upsert*, const Trigger*);
19791
+#endif
1979019792
#ifndef SQLITE_OMIT_TRIGGER
1979119793
SQLITE_PRIVATE void sqlite3TreeViewTriggerStep(TreeView*, const TriggerStep*, u8, u8);
1979219794
SQLITE_PRIVATE void sqlite3TreeViewTrigger(TreeView*, const Trigger*, u8, u8);
1979319795
#endif
1979419796
#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -29559,12 +29561,17 @@
2955929561
if( db->nVdbeExec>0 ){
2956029562
AtomicStore(&db->u1.isInterrupted, 1);
2956129563
}
2956229564
DisableLookaside;
2956329565
if( db->pParse ){
29566
+ Parse *pParse;
2956429567
sqlite3ErrorMsg(db->pParse, "out of memory");
2956529568
db->pParse->rc = SQLITE_NOMEM_BKPT;
29569
+ for(pParse=db->pParse->pOuterParse; pParse; pParse = pParse->pOuterParse){
29570
+ pParse->nErr++;
29571
+ pParse->rc = SQLITE_NOMEM;
29572
+ }
2956629573
}
2956729574
}
2956829575
return 0;
2956929576
}
2957029577
@@ -30426,12 +30433,12 @@
3042630433
}
3042730434
break;
3042830435
case etSQLESCAPE: /* %q: Escape ' characters */
3042930436
case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */
3043030437
case etSQLESCAPE3: { /* %w: Escape " characters */
30431
- int i, j, k, n, isnull;
30432
- int needQuote;
30438
+ i64 i, j, k, n;
30439
+ int needQuote, isnull;
3043330440
char ch;
3043430441
char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
3043530442
char *escarg;
3043630443
3043730444
if( bArgList ){
@@ -31115,12 +31122,12 @@
3111531122
int i;
3111631123
sqlite3TreeViewPush(&pView, moreToFollow);
3111731124
sqlite3TreeViewLine(pView, "COLUMNS");
3111831125
for(i=0; i<nCol; i++){
3111931126
u16 flg = aCol[i].colFlags;
31120
- int moreToFollow = i<(nCol - 1);
31121
- sqlite3TreeViewPush(&pView, moreToFollow);
31127
+ int colMoreToFollow = i<(nCol - 1);
31128
+ sqlite3TreeViewPush(&pView, colMoreToFollow);
3112231129
sqlite3TreeViewLine(pView, 0);
3112331130
printf(" %s", aCol[i].zCnName);
3112431131
switch( aCol[i].eCType ){
3112531132
case COLTYPE_ANY: printf(" ANY"); break;
3112631133
case COLTYPE_BLOB: printf(" BLOB"); break;
@@ -31247,11 +31254,11 @@
3124731254
if( pItem->pSelect ){
3124831255
if( pItem->pTab ){
3124931256
Table *pTab = pItem->pTab;
3125031257
sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
3125131258
}
31252
- assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31259
+ assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
3125331260
sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
3125431261
}
3125531262
if( pItem->fg.isTabFunc ){
3125631263
sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
3125731264
}
@@ -32014,10 +32021,11 @@
3201432021
pUpsert = pUpsert->pNextUpsert;
3201532022
}
3201632023
sqlite3TreeViewPop(&pView);
3201732024
}
3201832025
32026
+#if TREETRACE_ENABLED
3201932027
/*
3202032028
** Generate a human-readable diagram of the data structure that go
3202132029
** into generating an DELETE statement.
3202232030
*/
3202332031
SQLITE_PRIVATE void sqlite3TreeViewDelete(
@@ -32067,11 +32075,13 @@
3206732075
if( pTrigger ){
3206832076
sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
3206932077
}
3207032078
sqlite3TreeViewPop(&pView);
3207132079
}
32080
+#endif /* TREETRACE_ENABLED */
3207232081
32082
+#if TREETRACE_ENABLED
3207332083
/*
3207432084
** Generate a human-readable diagram of the data structure that go
3207532085
** into generating an INSERT statement.
3207632086
*/
3207732087
SQLITE_PRIVATE void sqlite3TreeViewInsert(
@@ -32135,11 +32145,13 @@
3213532145
if( pTrigger ){
3213632146
sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
3213732147
}
3213832148
sqlite3TreeViewPop(&pView);
3213932149
}
32150
+#endif /* TREETRACE_ENABLED */
3214032151
32152
+#if TREETRACE_ENABLED
3214132153
/*
3214232154
** Generate a human-readable diagram of the data structure that go
3214332155
** into generating an UPDATE statement.
3214432156
*/
3214532157
SQLITE_PRIVATE void sqlite3TreeViewUpdate(
@@ -32211,10 +32223,11 @@
3221132223
if( pTrigger ){
3221232224
sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
3221332225
}
3221432226
sqlite3TreeViewPop(&pView);
3221532227
}
32228
+#endif /* TREETRACE_ENABLED */
3221632229
3221732230
#ifndef SQLITE_OMIT_TRIGGER
3221832231
/*
3221932232
** Show a human-readable graph of a TriggerStep
3222032233
*/
@@ -35267,67 +35280,67 @@
3526735280
/* 3 */ "Checkpoint" OpHelp(""),
3526835281
/* 4 */ "JournalMode" OpHelp(""),
3526935282
/* 5 */ "Vacuum" OpHelp(""),
3527035283
/* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
3527135284
/* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
35272
- /* 8 */ "Goto" OpHelp(""),
35273
- /* 9 */ "Gosub" OpHelp(""),
35274
- /* 10 */ "InitCoroutine" OpHelp(""),
35275
- /* 11 */ "Yield" OpHelp(""),
35276
- /* 12 */ "MustBeInt" OpHelp(""),
35277
- /* 13 */ "Jump" OpHelp(""),
35278
- /* 14 */ "Once" OpHelp(""),
35279
- /* 15 */ "If" OpHelp(""),
35280
- /* 16 */ "IfNot" OpHelp(""),
35281
- /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
35282
- /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35285
+ /* 8 */ "Init" OpHelp("Start at P2"),
35286
+ /* 9 */ "Goto" OpHelp(""),
35287
+ /* 10 */ "Gosub" OpHelp(""),
35288
+ /* 11 */ "InitCoroutine" OpHelp(""),
35289
+ /* 12 */ "Yield" OpHelp(""),
35290
+ /* 13 */ "MustBeInt" OpHelp(""),
35291
+ /* 14 */ "Jump" OpHelp(""),
35292
+ /* 15 */ "Once" OpHelp(""),
35293
+ /* 16 */ "If" OpHelp(""),
35294
+ /* 17 */ "IfNot" OpHelp(""),
35295
+ /* 18 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
3528335296
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
35284
- /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35285
- /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35286
- /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35287
- /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35288
- /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35289
- /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35290
- /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35291
- /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"),
35292
- /* 28 */ "Found" OpHelp("key=r[P3@P4]"),
35293
- /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35294
- /* 30 */ "NotExists" OpHelp("intkey=r[P3]"),
35295
- /* 31 */ "Last" OpHelp(""),
35296
- /* 32 */ "IfSmaller" OpHelp(""),
35297
- /* 33 */ "SorterSort" OpHelp(""),
35298
- /* 34 */ "Sort" OpHelp(""),
35299
- /* 35 */ "Rewind" OpHelp(""),
35300
- /* 36 */ "SorterNext" OpHelp(""),
35301
- /* 37 */ "Prev" OpHelp(""),
35302
- /* 38 */ "Next" OpHelp(""),
35303
- /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35304
- /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35305
- /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35306
- /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35297
+ /* 20 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35298
+ /* 21 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35299
+ /* 22 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35300
+ /* 23 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35301
+ /* 24 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35302
+ /* 25 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35303
+ /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35304
+ /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35305
+ /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
35306
+ /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
35307
+ /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35308
+ /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
35309
+ /* 32 */ "Last" OpHelp(""),
35310
+ /* 33 */ "IfSmaller" OpHelp(""),
35311
+ /* 34 */ "SorterSort" OpHelp(""),
35312
+ /* 35 */ "Sort" OpHelp(""),
35313
+ /* 36 */ "Rewind" OpHelp(""),
35314
+ /* 37 */ "SorterNext" OpHelp(""),
35315
+ /* 38 */ "Prev" OpHelp(""),
35316
+ /* 39 */ "Next" OpHelp(""),
35317
+ /* 40 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35318
+ /* 41 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35319
+ /* 42 */ "IdxLT" OpHelp("key=r[P3@P4]"),
3530735320
/* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
3530835321
/* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
35309
- /* 45 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35310
- /* 46 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35311
- /* 47 */ "Program" OpHelp(""),
35312
- /* 48 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35313
- /* 49 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35322
+ /* 45 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35323
+ /* 46 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35324
+ /* 47 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35325
+ /* 48 */ "Program" OpHelp(""),
35326
+ /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
3531435327
/* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
3531535328
/* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
3531635329
/* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
3531735330
/* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
3531835331
/* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
3531935332
/* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
3532035333
/* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
3532135334
/* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
3532235335
/* 58 */ "ElseEq" OpHelp(""),
35323
- /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35324
- /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35325
- /* 61 */ "IncrVacuum" OpHelp(""),
35326
- /* 62 */ "VNext" OpHelp(""),
35327
- /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35328
- /* 64 */ "Init" OpHelp("Start at P2"),
35336
+ /* 59 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35337
+ /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35338
+ /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35339
+ /* 62 */ "IncrVacuum" OpHelp(""),
35340
+ /* 63 */ "VNext" OpHelp(""),
35341
+ /* 64 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
3532935342
/* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
3533035343
/* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
3533135344
/* 67 */ "Return" OpHelp(""),
3533235345
/* 68 */ "EndCoroutine" OpHelp(""),
3533335346
/* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
@@ -68301,11 +68314,10 @@
6830168314
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6830268315
assert( pPage->pBt!=0 );
6830368316
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
6830468317
assert( pPage->nOverflow==0 );
6830568318
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68306
- temp = 0;
6830768319
src = data = pPage->aData;
6830868320
hdr = pPage->hdrOffset;
6830968321
cellOffset = pPage->cellOffset;
6831068322
nCell = pPage->nCell;
6831168323
assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
@@ -68356,43 +68368,42 @@
6835668368
}
6835768369
6835868370
cbrk = usableSize;
6835968371
iCellLast = usableSize - 4;
6836068372
iCellStart = get2byte(&data[hdr+5]);
68361
- for(i=0; i<nCell; i++){
68362
- u8 *pAddr; /* The i-th cell pointer */
68363
- pAddr = &data[cellOffset + i*2];
68364
- pc = get2byte(pAddr);
68365
- testcase( pc==iCellFirst );
68366
- testcase( pc==iCellLast );
68367
- /* These conditions have already been verified in btreeInitPage()
68368
- ** if PRAGMA cell_size_check=ON.
68369
- */
68370
- if( pc<iCellStart || pc>iCellLast ){
68371
- return SQLITE_CORRUPT_PAGE(pPage);
68372
- }
68373
- assert( pc>=iCellStart && pc<=iCellLast );
68374
- size = pPage->xCellSize(pPage, &src[pc]);
68375
- cbrk -= size;
68376
- if( cbrk<iCellStart || pc+size>usableSize ){
68377
- return SQLITE_CORRUPT_PAGE(pPage);
68378
- }
68379
- assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68380
- testcase( cbrk+size==usableSize );
68381
- testcase( pc+size==usableSize );
68382
- put2byte(pAddr, cbrk);
68383
- if( temp==0 ){
68384
- if( cbrk==pc ) continue;
68385
- temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68386
- memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68387
- src = temp;
68388
- }
68389
- memcpy(&data[cbrk], &src[pc], size);
68373
+ if( nCell>0 ){
68374
+ temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68375
+ memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68376
+ src = temp;
68377
+ for(i=0; i<nCell; i++){
68378
+ u8 *pAddr; /* The i-th cell pointer */
68379
+ pAddr = &data[cellOffset + i*2];
68380
+ pc = get2byte(pAddr);
68381
+ testcase( pc==iCellFirst );
68382
+ testcase( pc==iCellLast );
68383
+ /* These conditions have already been verified in btreeInitPage()
68384
+ ** if PRAGMA cell_size_check=ON.
68385
+ */
68386
+ if( pc<iCellStart || pc>iCellLast ){
68387
+ return SQLITE_CORRUPT_PAGE(pPage);
68388
+ }
68389
+ assert( pc>=iCellStart && pc<=iCellLast );
68390
+ size = pPage->xCellSize(pPage, &src[pc]);
68391
+ cbrk -= size;
68392
+ if( cbrk<iCellStart || pc+size>usableSize ){
68393
+ return SQLITE_CORRUPT_PAGE(pPage);
68394
+ }
68395
+ assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68396
+ testcase( cbrk+size==usableSize );
68397
+ testcase( pc+size==usableSize );
68398
+ put2byte(pAddr, cbrk);
68399
+ memcpy(&data[cbrk], &src[pc], size);
68400
+ }
6839068401
}
6839168402
data[hdr+7] = 0;
6839268403
68393
- defragment_out:
68404
+defragment_out:
6839468405
assert( pPage->nFree>=0 );
6839568406
if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
6839668407
return SQLITE_CORRUPT_PAGE(pPage);
6839768408
}
6839868409
assert( cbrk>=iCellFirst );
@@ -68461,13 +68472,13 @@
6846168472
return &aData[pc + x];
6846268473
}
6846368474
iAddr = pc;
6846468475
pTmp = &aData[pc];
6846568476
pc = get2byte(pTmp);
68466
- if( pc<=iAddr+size ){
68477
+ if( pc<=iAddr ){
6846768478
if( pc ){
68468
- /* The next slot in the chain is not past the end of the current slot */
68479
+ /* The next slot in the chain comes before the current slot */
6846968480
*pRc = SQLITE_CORRUPT_PAGE(pPg);
6847068481
}
6847168482
return 0;
6847268483
}
6847368484
}
@@ -68615,11 +68626,11 @@
6861568626
iPtr = hdr + 1;
6861668627
if( data[iPtr+1]==0 && data[iPtr]==0 ){
6861768628
iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
6861868629
}else{
6861968630
while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
68620
- if( iFreeBlk<iPtr+4 ){
68631
+ if( iFreeBlk<=iPtr ){
6862168632
if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
6862268633
return SQLITE_CORRUPT_PAGE(pPage);
6862368634
}
6862468635
iPtr = iFreeBlk;
6862568636
}
@@ -69097,13 +69108,11 @@
6909769108
if( pCur ){
6909869109
pCur->iPage--;
6909969110
pCur->pPage = pCur->apPage[pCur->iPage];
6910069111
}
6910169112
testcase( pgno==0 );
69102
- assert( pgno!=0 || rc==SQLITE_CORRUPT
69103
- || rc==SQLITE_IOERR_NOMEM
69104
- || rc==SQLITE_NOMEM );
69113
+ assert( pgno!=0 || rc!=SQLITE_OK );
6910569114
return rc;
6910669115
}
6910769116
6910869117
/*
6910969118
** Release a MemPage. This should be called once for each prior
@@ -72041,12 +72050,10 @@
7204172050
** the new child page does not match the flags field of the parent (i.e.
7204272051
** if an intkey page appears to be the parent of a non-intkey page, or
7204372052
** vice-versa).
7204472053
*/
7204572054
static int moveToChild(BtCursor *pCur, u32 newPgno){
72046
- BtShared *pBt = pCur->pBt;
72047
-
7204872055
assert( cursorOwnsBtShared(pCur) );
7204972056
assert( pCur->eState==CURSOR_VALID );
7205072057
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
7205172058
assert( pCur->iPage>=0 );
7205272059
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
@@ -72056,11 +72063,12 @@
7205672063
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
7205772064
pCur->aiIdx[pCur->iPage] = pCur->ix;
7205872065
pCur->apPage[pCur->iPage] = pCur->pPage;
7205972066
pCur->ix = 0;
7206072067
pCur->iPage++;
72061
- return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
72068
+ return getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur,
72069
+ pCur->curPagerFlags);
7206272070
}
7206372071
7206472072
#ifdef SQLITE_DEBUG
7206572073
/*
7206672074
** Page pParent is an internal (non-leaf) tree page. This function
@@ -72162,11 +72170,11 @@
7216272170
assert( pCur->skipNext!=SQLITE_OK );
7216372171
return pCur->skipNext;
7216472172
}
7216572173
sqlite3BtreeClearCursor(pCur);
7216672174
}
72167
- rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
72175
+ rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
7216872176
0, pCur->curPagerFlags);
7216972177
if( rc!=SQLITE_OK ){
7217072178
pCur->eState = CURSOR_INVALID;
7217172179
return rc;
7217272180
}
@@ -73803,16 +73811,10 @@
7380373811
data = pPage->aData;
7380473812
ptr = &pPage->aCellIdx[2*idx];
7380573813
assert( pPage->pBt->usableSize > (u32)(ptr-data) );
7380673814
pc = get2byte(ptr);
7380773815
hdr = pPage->hdrOffset;
73808
-#if 0 /* Not required. Omit for efficiency */
73809
- if( pc<hdr+pPage->nCell*2 ){
73810
- *pRC = SQLITE_CORRUPT_BKPT;
73811
- return;
73812
- }
73813
-#endif
7381473816
testcase( pc==(u32)get2byte(&data[hdr+5]) );
7381573817
testcase( pc+sz==pPage->pBt->usableSize );
7381673818
if( pc+sz > pPage->pBt->usableSize ){
7381773819
*pRC = SQLITE_CORRUPT_BKPT;
7381873820
return;
@@ -80759,11 +80761,18 @@
8075980761
return 0;
8076080762
}
8076180763
#endif
8076280764
8076380765
/*
80764
-** Swap all content between two VDBE structures.
80766
+** Swap byte-code between two VDBE structures.
80767
+**
80768
+** This happens after pB was previously run and returned
80769
+** SQLITE_SCHEMA. The statement was then reprepared in pA.
80770
+** This routine transfers the new bytecode in pA over to pB
80771
+** so that pB can be run again. The old pB byte code is
80772
+** moved back to pA so that it will be cleaned up when pA is
80773
+** finalized.
8076580774
*/
8076680775
SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
8076780776
Vdbe tmp, *pTmp;
8076880777
char *zTmp;
8076980778
assert( pA->db==pB->db );
@@ -81450,12 +81459,12 @@
8145081459
Parse *pParse = p->pParse;
8145181460
int *aLabel = pParse->aLabel;
8145281461
p->readOnly = 1;
8145381462
p->bIsReader = 0;
8145481463
pOp = &p->aOp[p->nOp-1];
81455
- while(1){
81456
-
81464
+ assert( p->aOp[0].opcode==OP_Init );
81465
+ while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
8145781466
/* Only JUMP opcodes and the short list of special opcodes in the switch
8145881467
** below need to be considered. The mkopcodeh.tcl generator script groups
8145981468
** all these opcodes together near the front of the opcode list. Skip
8146081469
** any opcode that does not need processing by virtual of the fact that
8146181470
** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -81480,10 +81489,14 @@
8148081489
case OP_JournalMode: {
8148181490
p->readOnly = 0;
8148281491
p->bIsReader = 1;
8148381492
break;
8148481493
}
81494
+ case OP_Init: {
81495
+ assert( pOp->p2>=0 );
81496
+ goto resolve_p2_values_loop_exit;
81497
+ }
8148581498
#ifndef SQLITE_OMIT_VIRTUALTABLE
8148681499
case OP_VUpdate: {
8148781500
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
8148881501
break;
8148981502
}
@@ -81512,13 +81525,14 @@
8151281525
/* The mkopcodeh.tcl script has so arranged things that the only
8151381526
** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
8151481527
** have non-negative values for P2. */
8151581528
assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
8151681529
}
81517
- if( pOp==p->aOp ) break;
81530
+ assert( pOp>p->aOp );
8151881531
pOp--;
8151981532
}
81533
+resolve_p2_values_loop_exit:
8152081534
if( aLabel ){
8152181535
sqlite3DbFreeNN(p->db, pParse->aLabel);
8152281536
pParse->aLabel = 0;
8152381537
}
8152481538
pParse->nLabel = 0;
@@ -86040,11 +86054,13 @@
8604086054
Vdbe *v = (Vdbe*)pStmt;
8604186055
sqlite3 *db = v->db;
8604286056
if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
8604386057
sqlite3_mutex_enter(db->mutex);
8604486058
checkProfileCallback(db, v);
86045
- rc = sqlite3VdbeFinalize(v);
86059
+ assert( v->eVdbeState>=VDBE_READY_STATE );
86060
+ rc = sqlite3VdbeReset(v);
86061
+ sqlite3VdbeDelete(v);
8604686062
rc = sqlite3ApiExit(db, rc);
8604786063
sqlite3LeaveMutexAndCloseZombie(db);
8604886064
}
8604986065
return rc;
8605086066
}
@@ -90933,15 +90949,18 @@
9093390949
**
9093490950
** Check the cursor P1 to see if it is currently pointing at a NULL row.
9093590951
** If it is, then set register P3 to NULL and jump immediately to P2.
9093690952
** If P1 is not on a NULL row, then fall through without making any
9093790953
** changes.
90954
+**
90955
+** If P1 is not an open cursor, then this opcode is a no-op.
9093890956
*/
9093990957
case OP_IfNullRow: { /* jump */
90958
+ VdbeCursor *pC;
9094090959
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90941
- assert( p->apCsr[pOp->p1]!=0 );
90942
- if( p->apCsr[pOp->p1]->nullRow ){
90960
+ pC = p->apCsr[pOp->p1];
90961
+ if( ALWAYS(pC) && pC->nullRow ){
9094390962
sqlite3VdbeMemSetNull(aMem + pOp->p3);
9094490963
goto jump_to_p2;
9094590964
}
9094690965
break;
9094790966
}
@@ -101759,11 +101778,11 @@
101759101778
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
101760101779
u8 hCol;
101761101780
pTab = pItem->pTab;
101762101781
assert( pTab!=0 && pTab->zName!=0 );
101763101782
assert( pTab->nCol>0 || pParse->nErr );
101764
- assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
101783
+ assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
101765101784
if( pItem->fg.isNestedFrom ){
101766101785
/* In this case, pItem is a subquery that has been formed from a
101767101786
** parenthesized subset of the FROM clause terms. Example:
101768101787
** .... FROM t1 LEFT JOIN (t2 RIGHT JOIN t3 USING(x)) USING(y) ...
101769101788
** \_________________________/
@@ -115449,12 +115468,10 @@
115449115468
pParse->nested++;
115450115469
memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
115451115470
memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
115452115471
db->mDbFlags |= DBFLAG_PreferBuiltin;
115453115472
sqlite3RunParser(pParse, zSql);
115454
- sqlite3DbFree(db, pParse->zErrMsg);
115455
- pParse->zErrMsg = 0;
115456115473
db->mDbFlags = savedDbFlags;
115457115474
sqlite3DbFree(db, zSql);
115458115475
memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
115459115476
pParse->nested--;
115460115477
}
@@ -135851,11 +135868,11 @@
135851135868
/*
135852135869
** Mark a subquery result column as having been used.
135853135870
*/
135854135871
SQLITE_PRIVATE void sqlite3SrcItemColumnUsed(SrcItem *pItem, int iCol){
135855135872
assert( pItem!=0 );
135856
- assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
135873
+ assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
135857135874
if( pItem->fg.isNestedFrom ){
135858135875
ExprList *pResults;
135859135876
assert( pItem->pSelect!=0 );
135860135877
pResults = pItem->pSelect->pEList;
135861135878
assert( pResults!=0 );
@@ -137347,13 +137364,10 @@
137347137364
137348137365
/*
137349137366
** Return a pointer to a string containing the 'declaration type' of the
137350137367
** expression pExpr. The string may be treated as static by the caller.
137351137368
**
137352
-** Also try to estimate the size of the returned value and return that
137353
-** result in *pEstWidth.
137354
-**
137355137369
** The declaration type is the exact datatype definition extracted from the
137356137370
** original CREATE TABLE statement if the expression is a column. The
137357137371
** declaration type for a ROWID field is INTEGER. Exactly when an expression
137358137372
** is considered a column can be complex in the presence of subqueries. The
137359137373
** result-set expression in all of the following SELECT statements is
@@ -139595,11 +139609,12 @@
139595139609
**
139596139610
** (3) If the subquery is the right operand of a LEFT JOIN then
139597139611
** (3a) the subquery may not be a join and
139598139612
** (3b) the FROM clause of the subquery may not contain a virtual
139599139613
** table and
139600
-** (3c) the outer query may not be an aggregate.
139614
+** (3c) The outer query may not have a GROUP BY. (This limitation is
139615
+** due to how TK_IF_NULL_ROW works. FIX ME!)
139601139616
** (3d) the outer query may not be DISTINCT.
139602139617
** See also (26) for restrictions on RIGHT JOIN.
139603139618
**
139604139619
** (4) The subquery can not be DISTINCT.
139605139620
**
@@ -139649,10 +139664,13 @@
139649139664
** (17d) the outer query may not be
139650139665
** (17d1) aggregate, or
139651139666
** (17d2) DISTINCT
139652139667
** (17e) the subquery may not contain window functions, and
139653139668
** (17f) the subquery must not be the RHS of a LEFT JOIN.
139669
+** (17g) either the subquery is the first element of the outer
139670
+** query or there are no RIGHT or FULL JOINs in any arm
139671
+** of the subquery. (This is a duplicate of condition (27b).)
139654139672
**
139655139673
** The parent and sub-query may contain WHERE clauses. Subject to
139656139674
** rules (11), (13) and (14), they may also contain ORDER BY,
139657139675
** LIMIT and OFFSET clauses. The subquery cannot use any compound
139658139676
** operator other than UNION ALL because all the other compound
@@ -139700,11 +139718,15 @@
139700139718
**
139701139719
** (26) The subquery may not be the right operand of a RIGHT JOIN.
139702139720
** See also (3) for restrictions on LEFT JOIN.
139703139721
**
139704139722
** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139705
-** is the first element of the parent query.
139723
+** is the first element of the parent query. This must be the
139724
+** the case if:
139725
+** (27a) the subquery is not compound query, and
139726
+** (27b) the subquery is a compound query and the RIGHT JOIN occurs
139727
+** in any arm of the compound query. (See also (17g).)
139706139728
**
139707139729
** (28) The subquery is not a MATERIALIZED CTE.
139708139730
**
139709139731
** (29) Either the subquery is not the right-hand operand of a join with an
139710139732
** ON or USING clause nor the right-hand operand of a NATURAL JOIN, or
@@ -139800,22 +139822,17 @@
139800139822
**
139801139823
** (t1 LEFT OUTER JOIN t2) JOIN t3
139802139824
**
139803139825
** which is not at all the same thing.
139804139826
**
139805
- ** If the subquery is the right operand of a LEFT JOIN, then the outer
139806
- ** query cannot be an aggregate. (3c) This is an artifact of the way
139807
- ** aggregates are processed - there is no mechanism to determine if
139808
- ** the LEFT JOIN table should be all-NULL.
139809
- **
139810139827
** See also tickets #306, #350, and #3300.
139811139828
*/
139812139829
if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
139813139830
if( pSubSrc->nSrc>1 /* (3a) */
139814
- || isAgg /* (3c) */
139815139831
|| IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
139816139832
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
139833
+ || (p->pGroupBy!=0) /* (3c) */
139817139834
|| (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
139818139835
){
139819139836
return 0;
139820139837
}
139821139838
isOuterJoin = 1;
@@ -139830,11 +139847,11 @@
139830139847
}
139831139848
#endif
139832139849
139833139850
assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139834139851
if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139835
- return 0; /* Restriction (27) */
139852
+ return 0; /* Restriction (27a) */
139836139853
}
139837139854
if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139838139855
return 0; /* (28) */
139839139856
}
139840139857
@@ -139850,11 +139867,11 @@
139850139867
**
139851139868
** (29b) The subquery itself must not be the right operand of a
139852139869
** NATURAL join or a join that as an ON or USING clause.
139853139870
**
139854139871
** These conditions are sufficient to keep an EP_OuterON from being
139855
- ** flattened into an EP_InnerON. Restrictions (3a) and (27) prevent
139872
+ ** flattened into an EP_InnerON. Restrictions (3a) and (27a) prevent
139856139873
** an EP_InnerON from being flattened into an EP_OuterON.
139857139874
*/
139858139875
if( pSubSrc->nSrc>=2
139859139876
&& (pSubSrc->a[pSubSrc->nSrc-1].fg.jointype & JT_OUTER)!=0
139860139877
){
@@ -139891,10 +139908,16 @@
139891139908
#ifndef SQLITE_OMIT_WINDOWFUNC
139892139909
|| pSub1->pWin /* (17e) */
139893139910
#endif
139894139911
){
139895139912
return 0;
139913
+ }
139914
+ if( iFrom>0 && (pSub1->pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139915
+ /* Without this restriction, the JT_LTORJ flag would end up being
139916
+ ** omitted on left-hand tables of the right join that is being
139917
+ ** flattened. */
139918
+ return 0; /* Restrictions (17g), (27b) */
139896139919
}
139897139920
testcase( pSub1->pSrc->nSrc>1 );
139898139921
}
139899139922
139900139923
/* Restriction (18). */
@@ -140724,10 +140747,11 @@
140724140747
if( p->pWhere
140725140748
|| p->pEList->nExpr!=1
140726140749
|| p->pSrc->nSrc!=1
140727140750
|| p->pSrc->a[0].pSelect
140728140751
|| pAggInfo->nFunc!=1
140752
+ || p->pHaving
140729140753
){
140730140754
return 0;
140731140755
}
140732140756
pTab = p->pSrc->a[0].pTab;
140733140757
assert( pTab!=0 );
@@ -141425,11 +141449,11 @@
141425141449
141426141450
if( (zTabName = pFrom->zAlias)==0 ){
141427141451
zTabName = pTab->zName;
141428141452
}
141429141453
if( db->mallocFailed ) break;
141430
- assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141454
+ assert( (int)pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141431141455
if( pFrom->fg.isNestedFrom ){
141432141456
assert( pFrom->pSelect!=0 );
141433141457
pNestedFrom = pFrom->pSelect->pEList;
141434141458
assert( pNestedFrom!=0 );
141435141459
assert( pNestedFrom->nExpr==pTab->nCol );
@@ -142354,11 +142378,13 @@
142354142378
&& (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
142355142379
&& OptimizationEnabled(db, SQLITE_OmitOrderBy)
142356142380
){
142357142381
SELECTTRACE(0x100,pParse,p,
142358142382
("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1));
142359
- sqlite3ExprListDelete(db, pSub->pOrderBy);
142383
+ sqlite3ParserAddCleanup(pParse,
142384
+ (void(*)(sqlite3*,void*))sqlite3ExprListDelete,
142385
+ pSub->pOrderBy);
142360142386
pSub->pOrderBy = 0;
142361142387
}
142362142388
142363142389
/* If the outer query contains a "complex" result set (that is,
142364142390
** if the result set of the outer query uses functions or subqueries)
@@ -155354,11 +155380,11 @@
155354155380
#ifndef SQLITE_DEBUG
155355155381
UNUSED_PARAMETER( pParse );
155356155382
#endif
155357155383
assert( pRec!=0 );
155358155384
assert( pIdx->nSample>0 );
155359
- assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol );
155385
+ assert( pRec->nField>0 );
155360155386
155361155387
/* Do a binary search to find the first sample greater than or equal
155362155388
** to pRec. If pRec contains a single field, the set of samples to search
155363155389
** is simply the aSample[] array. If the samples in aSample[] contain more
155364155390
** than one fields, all fields following the first are ignored.
@@ -155400,11 +155426,11 @@
155400155426
** appears that it should be 1 field in size. However, that would make it
155401155427
** smaller than sample 1, so the binary search would not work. As a result,
155402155428
** it is extended to two fields. The duplicates that this creates do not
155403155429
** cause any problems.
155404155430
*/
155405
- nField = pRec->nField;
155431
+ nField = MIN(pRec->nField, pIdx->nSample);
155406155432
iCol = 0;
155407155433
iSample = pIdx->nSample * nField;
155408155434
do{
155409155435
int iSamp; /* Index in aSample[] of test sample */
155410155436
int n; /* Number of fields in test sample */
@@ -156117,16 +156143,22 @@
156117156143
}
156118156144
}
156119156145
}
156120156146
156121156147
/*
156122
-** Deallocate internal memory used by a WhereLoop object
156148
+** Deallocate internal memory used by a WhereLoop object. Leave the
156149
+** object in an initialized state, as if it had been newly allocated.
156123156150
*/
156124156151
static void whereLoopClear(sqlite3 *db, WhereLoop *p){
156125
- if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
156152
+ if( p->aLTerm!=p->aLTermSpace ){
156153
+ sqlite3DbFreeNN(db, p->aLTerm);
156154
+ p->aLTerm = p->aLTermSpace;
156155
+ p->nLSlot = ArraySize(p->aLTermSpace);
156156
+ }
156126156157
whereLoopClearUnion(db, p);
156127
- whereLoopInit(p);
156158
+ p->nLTerm = 0;
156159
+ p->wsFlags = 0;
156128156160
}
156129156161
156130156162
/*
156131156163
** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
156132156164
*/
@@ -156146,11 +156178,13 @@
156146156178
/*
156147156179
** Transfer content from the second pLoop into the first.
156148156180
*/
156149156181
static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
156150156182
whereLoopClearUnion(db, pTo);
156151
- if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
156183
+ if( pFrom->nLTerm > pTo->nLSlot
156184
+ && whereLoopResize(db, pTo, pFrom->nLTerm)
156185
+ ){
156152156186
memset(pTo, 0, WHERE_LOOP_XFER_SZ);
156153156187
return SQLITE_NOMEM_BKPT;
156154156188
}
156155156189
memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
156156156190
memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
@@ -156799,11 +156833,15 @@
156799156833
pNew->wsFlags = saved_wsFlags;
156800156834
pNew->u.btree.nEq = saved_nEq;
156801156835
pNew->u.btree.nBtm = saved_nBtm;
156802156836
pNew->u.btree.nTop = saved_nTop;
156803156837
pNew->nLTerm = saved_nLTerm;
156804
- if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156838
+ if( pNew->nLTerm>=pNew->nLSlot
156839
+ && whereLoopResize(db, pNew, pNew->nLTerm+1)
156840
+ ){
156841
+ break; /* OOM while trying to enlarge the pNew->aLTerm array */
156842
+ }
156805156843
pNew->aLTerm[pNew->nLTerm++] = pTerm;
156806156844
pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
156807156845
156808156846
assert( nInMul==0
156809156847
|| (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
@@ -156892,42 +156930,43 @@
156892156930
}
156893156931
}
156894156932
if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
156895156933
}else if( eOp & WO_ISNULL ){
156896156934
pNew->wsFlags |= WHERE_COLUMN_NULL;
156897
- }else if( eOp & (WO_GT|WO_GE) ){
156898
- testcase( eOp & WO_GT );
156899
- testcase( eOp & WO_GE );
156900
- pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
156901
- pNew->u.btree.nBtm = whereRangeVectorLen(
156902
- pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156903
- );
156904
- pBtm = pTerm;
156905
- pTop = 0;
156906
- if( pTerm->wtFlags & TERM_LIKEOPT ){
156907
- /* Range constraints that come from the LIKE optimization are
156908
- ** always used in pairs. */
156909
- pTop = &pTerm[1];
156910
- assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
156911
- assert( pTop->wtFlags & TERM_LIKEOPT );
156912
- assert( pTop->eOperator==WO_LT );
156913
- if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156914
- pNew->aLTerm[pNew->nLTerm++] = pTop;
156915
- pNew->wsFlags |= WHERE_TOP_LIMIT;
156916
- pNew->u.btree.nTop = 1;
156917
- }
156918
- }else{
156919
- assert( eOp & (WO_LT|WO_LE) );
156920
- testcase( eOp & WO_LT );
156921
- testcase( eOp & WO_LE );
156922
- pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
156923
- pNew->u.btree.nTop = whereRangeVectorLen(
156924
- pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156925
- );
156926
- pTop = pTerm;
156927
- pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
156928
- pNew->aLTerm[pNew->nLTerm-2] : 0;
156935
+ }else{
156936
+ int nVecLen = whereRangeVectorLen(
156937
+ pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156938
+ );
156939
+ if( eOp & (WO_GT|WO_GE) ){
156940
+ testcase( eOp & WO_GT );
156941
+ testcase( eOp & WO_GE );
156942
+ pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
156943
+ pNew->u.btree.nBtm = nVecLen;
156944
+ pBtm = pTerm;
156945
+ pTop = 0;
156946
+ if( pTerm->wtFlags & TERM_LIKEOPT ){
156947
+ /* Range constraints that come from the LIKE optimization are
156948
+ ** always used in pairs. */
156949
+ pTop = &pTerm[1];
156950
+ assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
156951
+ assert( pTop->wtFlags & TERM_LIKEOPT );
156952
+ assert( pTop->eOperator==WO_LT );
156953
+ if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156954
+ pNew->aLTerm[pNew->nLTerm++] = pTop;
156955
+ pNew->wsFlags |= WHERE_TOP_LIMIT;
156956
+ pNew->u.btree.nTop = 1;
156957
+ }
156958
+ }else{
156959
+ assert( eOp & (WO_LT|WO_LE) );
156960
+ testcase( eOp & WO_LT );
156961
+ testcase( eOp & WO_LE );
156962
+ pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
156963
+ pNew->u.btree.nTop = nVecLen;
156964
+ pTop = pTerm;
156965
+ pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
156966
+ pNew->aLTerm[pNew->nLTerm-2] : 0;
156967
+ }
156929156968
}
156930156969
156931156970
/* At this point pNew->nOut is set to the number of rows expected to
156932156971
** be visited by the index scan before considering term pTerm, or the
156933156972
** values of nIn and nInMul. In other words, assuming that all
@@ -158089,16 +158128,23 @@
158089158128
SrcItem *pItem;
158090158129
SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
158091158130
sqlite3 *db = pWInfo->pParse->db;
158092158131
int rc = SQLITE_OK;
158093158132
int bFirstPastRJ = 0;
158133
+ int hasRightJoin = 0;
158094158134
WhereLoop *pNew;
158095158135
158096158136
158097158137
/* Loop over the tables in the join, from left to right */
158098158138
pNew = pBuilder->pNew;
158099
- whereLoopInit(pNew);
158139
+
158140
+ /* Verify that pNew has already been initialized */
158141
+ assert( pNew->nLTerm==0 );
158142
+ assert( pNew->wsFlags==0 );
158143
+ assert( pNew->nLSlot>=ArraySize(pNew->aLTermSpace) );
158144
+ assert( pNew->aLTerm!=0 );
158145
+
158100158146
pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
158101158147
for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
158102158148
Bitmask mUnusable = 0;
158103158149
pNew->iTab = iTab;
158104158150
pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
@@ -158109,19 +158155,20 @@
158109158155
/* Add prerequisites to prevent reordering of FROM clause terms
158110158156
** across CROSS joins and outer joins. The bFirstPastRJ boolean
158111158157
** prevents the right operand of a RIGHT JOIN from being swapped with
158112158158
** other elements even further to the right.
158113158159
**
158114
- ** The JT_LTORJ term prevents any FROM-clause term reordering for terms
158115
- ** to the left of a RIGHT JOIN. This is conservative. Relaxing this
158116
- ** constraint somewhat to prevent terms from crossing from the right
158117
- ** side of a LEFT JOIN over to the left side when they are on the
158118
- ** left side of a RIGHT JOIN would be sufficient for all known failure
158119
- ** cases. FIX ME: Implement this optimization.
158160
+ ** The JT_LTORJ case and the hasRightJoin flag work together to
158161
+ ** prevent FROM-clause terms from moving from the right side of
158162
+ ** a LEFT JOIN over to the left side of that join if the LEFT JOIN
158163
+ ** is itself on the left side of a RIGHT JOIN.
158120158164
*/
158165
+ if( pItem->fg.jointype & JT_LTORJ ) hasRightJoin = 1;
158121158166
mPrereq |= mPrior;
158122158167
bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
158168
+ }else if( !hasRightJoin ){
158169
+ mPrereq = 0;
158123158170
}
158124158171
#ifndef SQLITE_OMIT_VIRTUALTABLE
158125158172
if( IsVirtual(pItem->pTab) ){
158126158173
SrcItem *p;
158127158174
for(p=&pItem[1]; p<pEnd; p++){
@@ -158690,13 +158737,13 @@
158690158737
for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
158691158738
for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
158692158739
LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
158693158740
LogEst rCost; /* Cost of path (pFrom+pWLoop) */
158694158741
LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
158695
- i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */
158742
+ i8 isOrdered; /* isOrdered for (pFrom+pWLoop) */
158696158743
Bitmask maskNew; /* Mask of src visited by (..) */
158697
- Bitmask revMask = 0; /* Mask of rev-order loops for (..) */
158744
+ Bitmask revMask; /* Mask of rev-order loops for (..) */
158698158745
158699158746
if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
158700158747
if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
158701158748
if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
158702158749
/* Do not use an automatic index if the this loop is expected
@@ -158711,11 +158758,13 @@
158711158758
** Compute its cost */
158712158759
rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
158713158760
rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
158714158761
nOut = pFrom->nRow + pWLoop->nOut;
158715158762
maskNew = pFrom->maskLoop | pWLoop->maskSelf;
158763
+ isOrdered = pFrom->isOrdered;
158716158764
if( isOrdered<0 ){
158765
+ revMask = 0;
158717158766
isOrdered = wherePathSatisfiesOrderBy(pWInfo,
158718158767
pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
158719158768
iLoop, pWLoop, &revMask);
158720158769
}else{
158721158770
revMask = pFrom->revLoop;
@@ -169958,10 +170007,11 @@
169958170007
while( 1 ){
169959170008
n = sqlite3GetToken((u8*)zSql, &tokenType);
169960170009
mxSqlLen -= n;
169961170010
if( mxSqlLen<0 ){
169962170011
pParse->rc = SQLITE_TOOBIG;
170012
+ pParse->nErr++;
169963170013
break;
169964170014
}
169965170015
#ifndef SQLITE_OMIT_WINDOWFUNC
169966170016
if( tokenType>=TK_WINDOW ){
169967170017
assert( tokenType==TK_SPACE || tokenType==TK_OVER || tokenType==TK_FILTER
@@ -174698,12 +174748,15 @@
174698174748
sqlite3ShowUpsert(0);
174699174749
sqlite3ShowTriggerStep(0);
174700174750
sqlite3ShowTriggerStepList(0);
174701174751
sqlite3ShowTrigger(0);
174702174752
sqlite3ShowTriggerList(0);
174753
+#ifndef SQLITE_OMIT_WINDOWFUNC
174703174754
sqlite3ShowWindow(0);
174704174755
sqlite3ShowWinFunc(0);
174756
+#endif
174757
+ sqlite3ShowSelect(0);
174705174758
}
174706174759
#endif
174707174760
break;
174708174761
}
174709174762
@@ -181033,12 +181086,11 @@
181033181086
static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181034181087
int iToken; /* Used to iterate through phrase tokens */
181035181088
char *aPoslist = 0; /* Position list for deferred tokens */
181036181089
int nPoslist = 0; /* Number of bytes in aPoslist */
181037181090
int iPrev = -1; /* Token number of previous deferred token */
181038
-
181039
- assert( pPhrase->doclist.bFreeList==0 );
181091
+ char *aFree = (pPhrase->doclist.bFreeList ? pPhrase->doclist.pList : 0);
181040181092
181041181093
for(iToken=0; iToken<pPhrase->nToken; iToken++){
181042181094
Fts3PhraseToken *pToken = &pPhrase->aToken[iToken];
181043181095
Fts3DeferredToken *pDeferred = pToken->pDeferred;
181044181096
@@ -181048,10 +181100,11 @@
181048181100
int rc = sqlite3Fts3DeferredTokenList(pDeferred, &pList, &nList);
181049181101
if( rc!=SQLITE_OK ) return rc;
181050181102
181051181103
if( pList==0 ){
181052181104
sqlite3_free(aPoslist);
181105
+ sqlite3_free(aFree);
181053181106
pPhrase->doclist.pList = 0;
181054181107
pPhrase->doclist.nList = 0;
181055181108
return SQLITE_OK;
181056181109
181057181110
}else if( aPoslist==0 ){
@@ -181068,10 +181121,11 @@
181068181121
sqlite3_free(aPoslist);
181069181122
aPoslist = pList;
181070181123
nPoslist = (int)(aOut - aPoslist);
181071181124
if( nPoslist==0 ){
181072181125
sqlite3_free(aPoslist);
181126
+ sqlite3_free(aFree);
181073181127
pPhrase->doclist.pList = 0;
181074181128
pPhrase->doclist.nList = 0;
181075181129
return SQLITE_OK;
181076181130
}
181077181131
}
@@ -181107,10 +181161,11 @@
181107181161
sqlite3_free(aPoslist);
181108181162
return SQLITE_NOMEM;
181109181163
}
181110181164
181111181165
pPhrase->doclist.pList = aOut;
181166
+ assert( p1 && p2 );
181112181167
if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
181113181168
pPhrase->doclist.bFreeList = 1;
181114181169
pPhrase->doclist.nList = (int)(aOut - pPhrase->doclist.pList);
181115181170
}else{
181116181171
sqlite3_free(aOut);
@@ -181119,10 +181174,11 @@
181119181174
}
181120181175
sqlite3_free(aPoslist);
181121181176
}
181122181177
}
181123181178
181179
+ if( pPhrase->doclist.pList!=aFree ) sqlite3_free(aFree);
181124181180
return SQLITE_OK;
181125181181
}
181126181182
#endif /* SQLITE_DISABLE_FTS4_DEFERRED */
181127181183
181128181184
/*
@@ -182293,15 +182349,14 @@
182293182349
);
182294182350
break;
182295182351
182296182352
default: {
182297182353
#ifndef SQLITE_DISABLE_FTS4_DEFERRED
182298
- if( pCsr->pDeferred
182299
- && (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred)
182300
- ){
182354
+ if( pCsr->pDeferred && (pExpr->bDeferred || (
182355
+ pExpr->iDocid==pCsr->iPrevId && pExpr->pPhrase->doclist.pList
182356
+ ))){
182301182357
Fts3Phrase *pPhrase = pExpr->pPhrase;
182302
- assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
182303182358
if( pExpr->bDeferred ){
182304182359
fts3EvalInvalidatePoslist(pPhrase);
182305182360
}
182306182361
*pRc = fts3EvalDeferredPhrase(pCsr, pPhrase);
182307182362
bHit = (pPhrase->doclist.pList!=0);
@@ -212484,15 +212539,16 @@
212484212539
*/
212485212540
static int dbpageBegin(sqlite3_vtab *pVtab){
212486212541
DbpageTable *pTab = (DbpageTable *)pVtab;
212487212542
sqlite3 *db = pTab->db;
212488212543
int i;
212489
- for(i=0; i<db->nDb; i++){
212544
+ int rc = SQLITE_OK;
212545
+ for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
212490212546
Btree *pBt = db->aDb[i].pBt;
212491
- if( pBt ) sqlite3BtreeBeginTrans(pBt, 1, 0);
212547
+ if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
212492212548
}
212493
- return SQLITE_OK;
212549
+ return rc;
212494212550
}
212495212551
212496212552
212497212553
/*
212498212554
** Invoke this routine to register the "dbpage" virtual table module
@@ -236615,11 +236671,11 @@
236615236671
int nArg, /* Number of args */
236616236672
sqlite3_value **apUnused /* Function arguments */
236617236673
){
236618236674
assert( nArg==0 );
236619236675
UNUSED_PARAM2(nArg, apUnused);
236620
- sqlite3_result_text(pCtx, "fts5: 2022-06-25 14:57:57 14e166f40dbfa6e055543f8301525f2ca2e96a02a57269818b9e69e162e98918", -1, SQLITE_TRANSIENT);
236676
+ sqlite3_result_text(pCtx, "fts5: 2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a", -1, SQLITE_TRANSIENT);
236621236677
}
236622236678
236623236679
/*
236624236680
** Return true if zName is the extension on one of the shadow tables used
236625236681
** by this module.
@@ -241286,10 +241342,20 @@
241286241342
/* #include <assert.h> */
241287241343
/* #include <string.h> */
241288241344
241289241345
#ifndef SQLITE_OMIT_VIRTUALTABLE
241290241346
241347
+
241348
+#define STMT_NUM_INTEGER_COLUMN 10
241349
+typedef struct StmtRow StmtRow;
241350
+struct StmtRow {
241351
+ sqlite3_int64 iRowid; /* Rowid value */
241352
+ char *zSql; /* column "sql" */
241353
+ int aCol[STMT_NUM_INTEGER_COLUMN+1]; /* all other column values */
241354
+ StmtRow *pNext; /* Next row to return */
241355
+};
241356
+
241291241357
/* stmt_vtab is a subclass of sqlite3_vtab which will
241292241358
** serve as the underlying representation of a stmt virtual table
241293241359
*/
241294241360
typedef struct stmt_vtab stmt_vtab;
241295241361
struct stmt_vtab {
@@ -241303,12 +241369,11 @@
241303241369
*/
241304241370
typedef struct stmt_cursor stmt_cursor;
241305241371
struct stmt_cursor {
241306241372
sqlite3_vtab_cursor base; /* Base class - must be first */
241307241373
sqlite3 *db; /* Database connection for this cursor */
241308
- sqlite3_stmt *pStmt; /* Statement cursor is currently pointing at */
241309
- sqlite3_int64 iRowid; /* The rowid */
241374
+ StmtRow *pRow; /* Current row */
241310241375
};
241311241376
241312241377
/*
241313241378
** The stmtConnect() method is invoked to create a new
241314241379
** stmt_vtab that describes the stmt virtual table.
@@ -241348,11 +241413,11 @@
241348241413
241349241414
rc = sqlite3_declare_vtab(db,
241350241415
"CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,"
241351241416
"reprep,run,mem)");
241352241417
if( rc==SQLITE_OK ){
241353
- pNew = sqlite3_malloc( sizeof(*pNew) );
241418
+ pNew = sqlite3_malloc64( sizeof(*pNew) );
241354241419
*ppVtab = (sqlite3_vtab*)pNew;
241355241420
if( pNew==0 ) return SQLITE_NOMEM;
241356241421
memset(pNew, 0, sizeof(*pNew));
241357241422
pNew->db = db;
241358241423
}
@@ -241370,22 +241435,33 @@
241370241435
/*
241371241436
** Constructor for a new stmt_cursor object.
241372241437
*/
241373241438
static int stmtOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
241374241439
stmt_cursor *pCur;
241375
- pCur = sqlite3_malloc( sizeof(*pCur) );
241440
+ pCur = sqlite3_malloc64( sizeof(*pCur) );
241376241441
if( pCur==0 ) return SQLITE_NOMEM;
241377241442
memset(pCur, 0, sizeof(*pCur));
241378241443
pCur->db = ((stmt_vtab*)p)->db;
241379241444
*ppCursor = &pCur->base;
241380241445
return SQLITE_OK;
241381241446
}
241447
+
241448
+static void stmtCsrReset(stmt_cursor *pCur){
241449
+ StmtRow *pRow = 0;
241450
+ StmtRow *pNext = 0;
241451
+ for(pRow=pCur->pRow; pRow; pRow=pNext){
241452
+ pNext = pRow->pNext;
241453
+ sqlite3_free(pRow);
241454
+ }
241455
+ pCur->pRow = 0;
241456
+}
241382241457
241383241458
/*
241384241459
** Destructor for a stmt_cursor.
241385241460
*/
241386241461
static int stmtClose(sqlite3_vtab_cursor *cur){
241462
+ stmtCsrReset((stmt_cursor*)cur);
241387241463
sqlite3_free(cur);
241388241464
return SQLITE_OK;
241389241465
}
241390241466
241391241467
@@ -241392,12 +241468,13 @@
241392241468
/*
241393241469
** Advance a stmt_cursor to its next row of output.
241394241470
*/
241395241471
static int stmtNext(sqlite3_vtab_cursor *cur){
241396241472
stmt_cursor *pCur = (stmt_cursor*)cur;
241397
- pCur->iRowid++;
241398
- pCur->pStmt = sqlite3_next_stmt(pCur->db, pCur->pStmt);
241473
+ StmtRow *pNext = pCur->pRow->pNext;
241474
+ sqlite3_free(pCur->pRow);
241475
+ pCur->pRow = pNext;
241399241476
return SQLITE_OK;
241400241477
}
241401241478
241402241479
/*
241403241480
** Return values of columns for the row at which the stmt_cursor
@@ -241407,43 +241484,15 @@
241407241484
sqlite3_vtab_cursor *cur, /* The cursor */
241408241485
sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
241409241486
int i /* Which column to return */
241410241487
){
241411241488
stmt_cursor *pCur = (stmt_cursor*)cur;
241412
- switch( i ){
241413
- case STMT_COLUMN_SQL: {
241414
- sqlite3_result_text(ctx, sqlite3_sql(pCur->pStmt), -1, SQLITE_TRANSIENT);
241415
- break;
241416
- }
241417
- case STMT_COLUMN_NCOL: {
241418
- sqlite3_result_int(ctx, sqlite3_column_count(pCur->pStmt));
241419
- break;
241420
- }
241421
- case STMT_COLUMN_RO: {
241422
- sqlite3_result_int(ctx, sqlite3_stmt_readonly(pCur->pStmt));
241423
- break;
241424
- }
241425
- case STMT_COLUMN_BUSY: {
241426
- sqlite3_result_int(ctx, sqlite3_stmt_busy(pCur->pStmt));
241427
- break;
241428
- }
241429
- default: {
241430
- assert( i==STMT_COLUMN_MEM );
241431
- i = SQLITE_STMTSTATUS_MEMUSED +
241432
- STMT_COLUMN_NSCAN - SQLITE_STMTSTATUS_FULLSCAN_STEP;
241433
- /* Fall thru */
241434
- }
241435
- case STMT_COLUMN_NSCAN:
241436
- case STMT_COLUMN_NSORT:
241437
- case STMT_COLUMN_NAIDX:
241438
- case STMT_COLUMN_NSTEP:
241439
- case STMT_COLUMN_REPREP:
241440
- case STMT_COLUMN_RUN: {
241441
- sqlite3_result_int(ctx, sqlite3_stmt_status(pCur->pStmt,
241442
- i-STMT_COLUMN_NSCAN+SQLITE_STMTSTATUS_FULLSCAN_STEP, 0));
241443
- break;
241444
- }
241489
+ StmtRow *pRow = pCur->pRow;
241490
+ if( i==STMT_COLUMN_SQL ){
241491
+ sqlite3_result_text(ctx, pRow->zSql, -1, SQLITE_TRANSIENT);
241492
+ }else{
241493
+ sqlite3_result_int(ctx, pRow->aCol[i]);
241445241494
}
241446241495
return SQLITE_OK;
241447241496
}
241448241497
241449241498
/*
@@ -241450,21 +241499,21 @@
241450241499
** Return the rowid for the current row. In this implementation, the
241451241500
** rowid is the same as the output value.
241452241501
*/
241453241502
static int stmtRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
241454241503
stmt_cursor *pCur = (stmt_cursor*)cur;
241455
- *pRowid = pCur->iRowid;
241504
+ *pRowid = pCur->pRow->iRowid;
241456241505
return SQLITE_OK;
241457241506
}
241458241507
241459241508
/*
241460241509
** Return TRUE if the cursor has been moved off of the last
241461241510
** row of output.
241462241511
*/
241463241512
static int stmtEof(sqlite3_vtab_cursor *cur){
241464241513
stmt_cursor *pCur = (stmt_cursor*)cur;
241465
- return pCur->pStmt==0;
241514
+ return pCur->pRow==0;
241466241515
}
241467241516
241468241517
/*
241469241518
** This method is called to "rewind" the stmt_cursor object back
241470241519
** to the first row of output. This method is always called at least
@@ -241475,13 +241524,57 @@
241475241524
sqlite3_vtab_cursor *pVtabCursor,
241476241525
int idxNum, const char *idxStr,
241477241526
int argc, sqlite3_value **argv
241478241527
){
241479241528
stmt_cursor *pCur = (stmt_cursor *)pVtabCursor;
241480
- pCur->pStmt = 0;
241481
- pCur->iRowid = 0;
241482
- return stmtNext(pVtabCursor);
241529
+ sqlite3_stmt *p = 0;
241530
+ sqlite3_int64 iRowid = 1;
241531
+ StmtRow **ppRow = 0;
241532
+
241533
+ stmtCsrReset(pCur);
241534
+ ppRow = &pCur->pRow;
241535
+ for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
241536
+ const char *zSql = sqlite3_sql(p);
241537
+ sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
241538
+ StmtRow *pNew = (StmtRow*)sqlite3_malloc64(sizeof(StmtRow) + nSql);
241539
+
241540
+ if( pNew==0 ) return SQLITE_NOMEM;
241541
+ memset(pNew, 0, sizeof(StmtRow));
241542
+ if( zSql ){
241543
+ pNew->zSql = (char*)&pNew[1];
241544
+ memcpy(pNew->zSql, zSql, nSql);
241545
+ }
241546
+ pNew->aCol[STMT_COLUMN_NCOL] = sqlite3_column_count(p);
241547
+ pNew->aCol[STMT_COLUMN_RO] = sqlite3_stmt_readonly(p);
241548
+ pNew->aCol[STMT_COLUMN_BUSY] = sqlite3_stmt_busy(p);
241549
+ pNew->aCol[STMT_COLUMN_NSCAN] = sqlite3_stmt_status(
241550
+ p, SQLITE_STMTSTATUS_FULLSCAN_STEP, 0
241551
+ );
241552
+ pNew->aCol[STMT_COLUMN_NSORT] = sqlite3_stmt_status(
241553
+ p, SQLITE_STMTSTATUS_SORT, 0
241554
+ );
241555
+ pNew->aCol[STMT_COLUMN_NAIDX] = sqlite3_stmt_status(
241556
+ p, SQLITE_STMTSTATUS_AUTOINDEX, 0
241557
+ );
241558
+ pNew->aCol[STMT_COLUMN_NSTEP] = sqlite3_stmt_status(
241559
+ p, SQLITE_STMTSTATUS_VM_STEP, 0
241560
+ );
241561
+ pNew->aCol[STMT_COLUMN_REPREP] = sqlite3_stmt_status(
241562
+ p, SQLITE_STMTSTATUS_REPREPARE, 0
241563
+ );
241564
+ pNew->aCol[STMT_COLUMN_RUN] = sqlite3_stmt_status(
241565
+ p, SQLITE_STMTSTATUS_RUN, 0
241566
+ );
241567
+ pNew->aCol[STMT_COLUMN_MEM] = sqlite3_stmt_status(
241568
+ p, SQLITE_STMTSTATUS_MEMUSED, 0
241569
+ );
241570
+ pNew->iRowid = iRowid++;
241571
+ *ppRow = pNew;
241572
+ ppRow = &pNew->pNext;
241573
+ }
241574
+
241575
+ return SQLITE_OK;
241483241576
}
241484241577
241485241578
/*
241486241579
** SQLite will invoke this method one or more times while planning a query
241487241580
** that uses the stmt virtual table. This routine needs to create
241488241581
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.39.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -450,13 +450,13 @@
450 **
451 ** See also: [sqlite3_libversion()],
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-06-25 14:57:57 14e166f40dbfa6e055543f8301525f2ca2e96a02a57269818b9e69e162e98918"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -6586,11 +6586,11 @@
6586 ** CAPI3REF: Return The Schema Name For A Database Connection
6587 ** METHOD: sqlite3
6588 **
6589 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6590 ** for the N-th database on database connection D, or a NULL pointer of N is
6591 ** out of range. An N alue of 0 means the main database file. An N of 1 is
6592 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6593 ** databases.
6594 **
6595 ** Space to hold the string that is returned by sqlite3_db_name() is managed
6596 ** by SQLite itself. The string might be deallocated by any operation that
@@ -15553,67 +15553,67 @@
15553 #define OP_Checkpoint 3
15554 #define OP_JournalMode 4
15555 #define OP_Vacuum 5
15556 #define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */
15557 #define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */
15558 #define OP_Goto 8 /* jump */
15559 #define OP_Gosub 9 /* jump */
15560 #define OP_InitCoroutine 10 /* jump */
15561 #define OP_Yield 11 /* jump */
15562 #define OP_MustBeInt 12 /* jump */
15563 #define OP_Jump 13 /* jump */
15564 #define OP_Once 14 /* jump */
15565 #define OP_If 15 /* jump */
15566 #define OP_IfNot 16 /* jump */
15567 #define OP_IsNullOrType 17 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
15568 #define OP_IfNullRow 18 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15569 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
15570 #define OP_SeekLT 20 /* jump, synopsis: key=r[P3@P4] */
15571 #define OP_SeekLE 21 /* jump, synopsis: key=r[P3@P4] */
15572 #define OP_SeekGE 22 /* jump, synopsis: key=r[P3@P4] */
15573 #define OP_SeekGT 23 /* jump, synopsis: key=r[P3@P4] */
15574 #define OP_IfNotOpen 24 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15575 #define OP_IfNoHope 25 /* jump, synopsis: key=r[P3@P4] */
15576 #define OP_NoConflict 26 /* jump, synopsis: key=r[P3@P4] */
15577 #define OP_NotFound 27 /* jump, synopsis: key=r[P3@P4] */
15578 #define OP_Found 28 /* jump, synopsis: key=r[P3@P4] */
15579 #define OP_SeekRowid 29 /* jump, synopsis: intkey=r[P3] */
15580 #define OP_NotExists 30 /* jump, synopsis: intkey=r[P3] */
15581 #define OP_Last 31 /* jump */
15582 #define OP_IfSmaller 32 /* jump */
15583 #define OP_SorterSort 33 /* jump */
15584 #define OP_Sort 34 /* jump */
15585 #define OP_Rewind 35 /* jump */
15586 #define OP_SorterNext 36 /* jump */
15587 #define OP_Prev 37 /* jump */
15588 #define OP_Next 38 /* jump */
15589 #define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */
15590 #define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */
15591 #define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */
15592 #define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */
15593 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
15594 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15595 #define OP_RowSetRead 45 /* jump, synopsis: r[P3]=rowset(P1) */
15596 #define OP_RowSetTest 46 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15597 #define OP_Program 47 /* jump */
15598 #define OP_FkIfZero 48 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15599 #define OP_IfPos 49 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15600 #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
15601 #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
15602 #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
15603 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
15604 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
15605 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15606 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15607 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15608 #define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15609 #define OP_IfNotZero 59 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15610 #define OP_DecrJumpZero 60 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15611 #define OP_IncrVacuum 61 /* jump */
15612 #define OP_VNext 62 /* jump */
15613 #define OP_Filter 63 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
15614 #define OP_Init 64 /* jump, synopsis: Start at P2 */
15615 #define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */
15616 #define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */
15617 #define OP_Return 67
15618 #define OP_EndCoroutine 68
15619 #define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */
@@ -15745,17 +15745,17 @@
15745 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
15746 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
15747 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
15748 #define OPFLG_INITIALIZER {\
15749 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
15750 /* 8 */ 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x03,\
15751 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x09, 0x09, 0x09, 0x09,\
15752 /* 24 */ 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x01,\
15753 /* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15754 /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\
15755 /* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15756 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\
15757 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
15758 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
15759 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
15760 /* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
15761 /* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
@@ -19777,18 +19777,20 @@
19777 SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
19778 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19779 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19780 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19781 SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
 
19782 SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
19783 const ExprList*,const Expr*, const Trigger*);
19784 SQLITE_PRIVATE void sqlite3TreeViewInsert(const With*, const SrcList*,
19785 const IdList*, const Select*, const ExprList*,
19786 int, const Upsert*, const Trigger*);
19787 SQLITE_PRIVATE void sqlite3TreeViewUpdate(const With*, const SrcList*, const ExprList*,
19788 const Expr*, int, const ExprList*, const Expr*,
19789 const Upsert*, const Trigger*);
 
19790 #ifndef SQLITE_OMIT_TRIGGER
19791 SQLITE_PRIVATE void sqlite3TreeViewTriggerStep(TreeView*, const TriggerStep*, u8, u8);
19792 SQLITE_PRIVATE void sqlite3TreeViewTrigger(TreeView*, const Trigger*, u8, u8);
19793 #endif
19794 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -29559,12 +29561,17 @@
29559 if( db->nVdbeExec>0 ){
29560 AtomicStore(&db->u1.isInterrupted, 1);
29561 }
29562 DisableLookaside;
29563 if( db->pParse ){
 
29564 sqlite3ErrorMsg(db->pParse, "out of memory");
29565 db->pParse->rc = SQLITE_NOMEM_BKPT;
 
 
 
 
29566 }
29567 }
29568 return 0;
29569 }
29570
@@ -30426,12 +30433,12 @@
30426 }
30427 break;
30428 case etSQLESCAPE: /* %q: Escape ' characters */
30429 case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */
30430 case etSQLESCAPE3: { /* %w: Escape " characters */
30431 int i, j, k, n, isnull;
30432 int needQuote;
30433 char ch;
30434 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
30435 char *escarg;
30436
30437 if( bArgList ){
@@ -31115,12 +31122,12 @@
31115 int i;
31116 sqlite3TreeViewPush(&pView, moreToFollow);
31117 sqlite3TreeViewLine(pView, "COLUMNS");
31118 for(i=0; i<nCol; i++){
31119 u16 flg = aCol[i].colFlags;
31120 int moreToFollow = i<(nCol - 1);
31121 sqlite3TreeViewPush(&pView, moreToFollow);
31122 sqlite3TreeViewLine(pView, 0);
31123 printf(" %s", aCol[i].zCnName);
31124 switch( aCol[i].eCType ){
31125 case COLTYPE_ANY: printf(" ANY"); break;
31126 case COLTYPE_BLOB: printf(" BLOB"); break;
@@ -31247,11 +31254,11 @@
31247 if( pItem->pSelect ){
31248 if( pItem->pTab ){
31249 Table *pTab = pItem->pTab;
31250 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31251 }
31252 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31253 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
31254 }
31255 if( pItem->fg.isTabFunc ){
31256 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31257 }
@@ -32014,10 +32021,11 @@
32014 pUpsert = pUpsert->pNextUpsert;
32015 }
32016 sqlite3TreeViewPop(&pView);
32017 }
32018
 
32019 /*
32020 ** Generate a human-readable diagram of the data structure that go
32021 ** into generating an DELETE statement.
32022 */
32023 SQLITE_PRIVATE void sqlite3TreeViewDelete(
@@ -32067,11 +32075,13 @@
32067 if( pTrigger ){
32068 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32069 }
32070 sqlite3TreeViewPop(&pView);
32071 }
 
32072
 
32073 /*
32074 ** Generate a human-readable diagram of the data structure that go
32075 ** into generating an INSERT statement.
32076 */
32077 SQLITE_PRIVATE void sqlite3TreeViewInsert(
@@ -32135,11 +32145,13 @@
32135 if( pTrigger ){
32136 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32137 }
32138 sqlite3TreeViewPop(&pView);
32139 }
 
32140
 
32141 /*
32142 ** Generate a human-readable diagram of the data structure that go
32143 ** into generating an UPDATE statement.
32144 */
32145 SQLITE_PRIVATE void sqlite3TreeViewUpdate(
@@ -32211,10 +32223,11 @@
32211 if( pTrigger ){
32212 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32213 }
32214 sqlite3TreeViewPop(&pView);
32215 }
 
32216
32217 #ifndef SQLITE_OMIT_TRIGGER
32218 /*
32219 ** Show a human-readable graph of a TriggerStep
32220 */
@@ -35267,67 +35280,67 @@
35267 /* 3 */ "Checkpoint" OpHelp(""),
35268 /* 4 */ "JournalMode" OpHelp(""),
35269 /* 5 */ "Vacuum" OpHelp(""),
35270 /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
35271 /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
35272 /* 8 */ "Goto" OpHelp(""),
35273 /* 9 */ "Gosub" OpHelp(""),
35274 /* 10 */ "InitCoroutine" OpHelp(""),
35275 /* 11 */ "Yield" OpHelp(""),
35276 /* 12 */ "MustBeInt" OpHelp(""),
35277 /* 13 */ "Jump" OpHelp(""),
35278 /* 14 */ "Once" OpHelp(""),
35279 /* 15 */ "If" OpHelp(""),
35280 /* 16 */ "IfNot" OpHelp(""),
35281 /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
35282 /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35283 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
35284 /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35285 /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35286 /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35287 /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35288 /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35289 /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35290 /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35291 /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"),
35292 /* 28 */ "Found" OpHelp("key=r[P3@P4]"),
35293 /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35294 /* 30 */ "NotExists" OpHelp("intkey=r[P3]"),
35295 /* 31 */ "Last" OpHelp(""),
35296 /* 32 */ "IfSmaller" OpHelp(""),
35297 /* 33 */ "SorterSort" OpHelp(""),
35298 /* 34 */ "Sort" OpHelp(""),
35299 /* 35 */ "Rewind" OpHelp(""),
35300 /* 36 */ "SorterNext" OpHelp(""),
35301 /* 37 */ "Prev" OpHelp(""),
35302 /* 38 */ "Next" OpHelp(""),
35303 /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35304 /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35305 /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35306 /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35307 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
35308 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
35309 /* 45 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35310 /* 46 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35311 /* 47 */ "Program" OpHelp(""),
35312 /* 48 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35313 /* 49 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35314 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
35315 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
35316 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
35317 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
35318 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
35319 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
35320 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
35321 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
35322 /* 58 */ "ElseEq" OpHelp(""),
35323 /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35324 /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35325 /* 61 */ "IncrVacuum" OpHelp(""),
35326 /* 62 */ "VNext" OpHelp(""),
35327 /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35328 /* 64 */ "Init" OpHelp("Start at P2"),
35329 /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
35330 /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
35331 /* 67 */ "Return" OpHelp(""),
35332 /* 68 */ "EndCoroutine" OpHelp(""),
35333 /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
@@ -68301,11 +68314,10 @@
68301 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
68302 assert( pPage->pBt!=0 );
68303 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
68304 assert( pPage->nOverflow==0 );
68305 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68306 temp = 0;
68307 src = data = pPage->aData;
68308 hdr = pPage->hdrOffset;
68309 cellOffset = pPage->cellOffset;
68310 nCell = pPage->nCell;
68311 assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
@@ -68356,43 +68368,42 @@
68356 }
68357
68358 cbrk = usableSize;
68359 iCellLast = usableSize - 4;
68360 iCellStart = get2byte(&data[hdr+5]);
68361 for(i=0; i<nCell; i++){
68362 u8 *pAddr; /* The i-th cell pointer */
68363 pAddr = &data[cellOffset + i*2];
68364 pc = get2byte(pAddr);
68365 testcase( pc==iCellFirst );
68366 testcase( pc==iCellLast );
68367 /* These conditions have already been verified in btreeInitPage()
68368 ** if PRAGMA cell_size_check=ON.
68369 */
68370 if( pc<iCellStart || pc>iCellLast ){
68371 return SQLITE_CORRUPT_PAGE(pPage);
68372 }
68373 assert( pc>=iCellStart && pc<=iCellLast );
68374 size = pPage->xCellSize(pPage, &src[pc]);
68375 cbrk -= size;
68376 if( cbrk<iCellStart || pc+size>usableSize ){
68377 return SQLITE_CORRUPT_PAGE(pPage);
68378 }
68379 assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68380 testcase( cbrk+size==usableSize );
68381 testcase( pc+size==usableSize );
68382 put2byte(pAddr, cbrk);
68383 if( temp==0 ){
68384 if( cbrk==pc ) continue;
68385 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68386 memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68387 src = temp;
68388 }
68389 memcpy(&data[cbrk], &src[pc], size);
68390 }
68391 data[hdr+7] = 0;
68392
68393 defragment_out:
68394 assert( pPage->nFree>=0 );
68395 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
68396 return SQLITE_CORRUPT_PAGE(pPage);
68397 }
68398 assert( cbrk>=iCellFirst );
@@ -68461,13 +68472,13 @@
68461 return &aData[pc + x];
68462 }
68463 iAddr = pc;
68464 pTmp = &aData[pc];
68465 pc = get2byte(pTmp);
68466 if( pc<=iAddr+size ){
68467 if( pc ){
68468 /* The next slot in the chain is not past the end of the current slot */
68469 *pRc = SQLITE_CORRUPT_PAGE(pPg);
68470 }
68471 return 0;
68472 }
68473 }
@@ -68615,11 +68626,11 @@
68615 iPtr = hdr + 1;
68616 if( data[iPtr+1]==0 && data[iPtr]==0 ){
68617 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
68618 }else{
68619 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
68620 if( iFreeBlk<iPtr+4 ){
68621 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
68622 return SQLITE_CORRUPT_PAGE(pPage);
68623 }
68624 iPtr = iFreeBlk;
68625 }
@@ -69097,13 +69108,11 @@
69097 if( pCur ){
69098 pCur->iPage--;
69099 pCur->pPage = pCur->apPage[pCur->iPage];
69100 }
69101 testcase( pgno==0 );
69102 assert( pgno!=0 || rc==SQLITE_CORRUPT
69103 || rc==SQLITE_IOERR_NOMEM
69104 || rc==SQLITE_NOMEM );
69105 return rc;
69106 }
69107
69108 /*
69109 ** Release a MemPage. This should be called once for each prior
@@ -72041,12 +72050,10 @@
72041 ** the new child page does not match the flags field of the parent (i.e.
72042 ** if an intkey page appears to be the parent of a non-intkey page, or
72043 ** vice-versa).
72044 */
72045 static int moveToChild(BtCursor *pCur, u32 newPgno){
72046 BtShared *pBt = pCur->pBt;
72047
72048 assert( cursorOwnsBtShared(pCur) );
72049 assert( pCur->eState==CURSOR_VALID );
72050 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
72051 assert( pCur->iPage>=0 );
72052 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
@@ -72056,11 +72063,12 @@
72056 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
72057 pCur->aiIdx[pCur->iPage] = pCur->ix;
72058 pCur->apPage[pCur->iPage] = pCur->pPage;
72059 pCur->ix = 0;
72060 pCur->iPage++;
72061 return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
 
72062 }
72063
72064 #ifdef SQLITE_DEBUG
72065 /*
72066 ** Page pParent is an internal (non-leaf) tree page. This function
@@ -72162,11 +72170,11 @@
72162 assert( pCur->skipNext!=SQLITE_OK );
72163 return pCur->skipNext;
72164 }
72165 sqlite3BtreeClearCursor(pCur);
72166 }
72167 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
72168 0, pCur->curPagerFlags);
72169 if( rc!=SQLITE_OK ){
72170 pCur->eState = CURSOR_INVALID;
72171 return rc;
72172 }
@@ -73803,16 +73811,10 @@
73803 data = pPage->aData;
73804 ptr = &pPage->aCellIdx[2*idx];
73805 assert( pPage->pBt->usableSize > (u32)(ptr-data) );
73806 pc = get2byte(ptr);
73807 hdr = pPage->hdrOffset;
73808 #if 0 /* Not required. Omit for efficiency */
73809 if( pc<hdr+pPage->nCell*2 ){
73810 *pRC = SQLITE_CORRUPT_BKPT;
73811 return;
73812 }
73813 #endif
73814 testcase( pc==(u32)get2byte(&data[hdr+5]) );
73815 testcase( pc+sz==pPage->pBt->usableSize );
73816 if( pc+sz > pPage->pBt->usableSize ){
73817 *pRC = SQLITE_CORRUPT_BKPT;
73818 return;
@@ -80759,11 +80761,18 @@
80759 return 0;
80760 }
80761 #endif
80762
80763 /*
80764 ** Swap all content between two VDBE structures.
 
 
 
 
 
 
 
80765 */
80766 SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
80767 Vdbe tmp, *pTmp;
80768 char *zTmp;
80769 assert( pA->db==pB->db );
@@ -81450,12 +81459,12 @@
81450 Parse *pParse = p->pParse;
81451 int *aLabel = pParse->aLabel;
81452 p->readOnly = 1;
81453 p->bIsReader = 0;
81454 pOp = &p->aOp[p->nOp-1];
81455 while(1){
81456
81457 /* Only JUMP opcodes and the short list of special opcodes in the switch
81458 ** below need to be considered. The mkopcodeh.tcl generator script groups
81459 ** all these opcodes together near the front of the opcode list. Skip
81460 ** any opcode that does not need processing by virtual of the fact that
81461 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -81480,10 +81489,14 @@
81480 case OP_JournalMode: {
81481 p->readOnly = 0;
81482 p->bIsReader = 1;
81483 break;
81484 }
 
 
 
 
81485 #ifndef SQLITE_OMIT_VIRTUALTABLE
81486 case OP_VUpdate: {
81487 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
81488 break;
81489 }
@@ -81512,13 +81525,14 @@
81512 /* The mkopcodeh.tcl script has so arranged things that the only
81513 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
81514 ** have non-negative values for P2. */
81515 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
81516 }
81517 if( pOp==p->aOp ) break;
81518 pOp--;
81519 }
 
81520 if( aLabel ){
81521 sqlite3DbFreeNN(p->db, pParse->aLabel);
81522 pParse->aLabel = 0;
81523 }
81524 pParse->nLabel = 0;
@@ -86040,11 +86054,13 @@
86040 Vdbe *v = (Vdbe*)pStmt;
86041 sqlite3 *db = v->db;
86042 if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
86043 sqlite3_mutex_enter(db->mutex);
86044 checkProfileCallback(db, v);
86045 rc = sqlite3VdbeFinalize(v);
 
 
86046 rc = sqlite3ApiExit(db, rc);
86047 sqlite3LeaveMutexAndCloseZombie(db);
86048 }
86049 return rc;
86050 }
@@ -90933,15 +90949,18 @@
90933 **
90934 ** Check the cursor P1 to see if it is currently pointing at a NULL row.
90935 ** If it is, then set register P3 to NULL and jump immediately to P2.
90936 ** If P1 is not on a NULL row, then fall through without making any
90937 ** changes.
 
 
90938 */
90939 case OP_IfNullRow: { /* jump */
 
90940 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90941 assert( p->apCsr[pOp->p1]!=0 );
90942 if( p->apCsr[pOp->p1]->nullRow ){
90943 sqlite3VdbeMemSetNull(aMem + pOp->p3);
90944 goto jump_to_p2;
90945 }
90946 break;
90947 }
@@ -101759,11 +101778,11 @@
101759 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
101760 u8 hCol;
101761 pTab = pItem->pTab;
101762 assert( pTab!=0 && pTab->zName!=0 );
101763 assert( pTab->nCol>0 || pParse->nErr );
101764 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
101765 if( pItem->fg.isNestedFrom ){
101766 /* In this case, pItem is a subquery that has been formed from a
101767 ** parenthesized subset of the FROM clause terms. Example:
101768 ** .... FROM t1 LEFT JOIN (t2 RIGHT JOIN t3 USING(x)) USING(y) ...
101769 ** \_________________________/
@@ -115449,12 +115468,10 @@
115449 pParse->nested++;
115450 memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
115451 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
115452 db->mDbFlags |= DBFLAG_PreferBuiltin;
115453 sqlite3RunParser(pParse, zSql);
115454 sqlite3DbFree(db, pParse->zErrMsg);
115455 pParse->zErrMsg = 0;
115456 db->mDbFlags = savedDbFlags;
115457 sqlite3DbFree(db, zSql);
115458 memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
115459 pParse->nested--;
115460 }
@@ -135851,11 +135868,11 @@
135851 /*
135852 ** Mark a subquery result column as having been used.
135853 */
135854 SQLITE_PRIVATE void sqlite3SrcItemColumnUsed(SrcItem *pItem, int iCol){
135855 assert( pItem!=0 );
135856 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
135857 if( pItem->fg.isNestedFrom ){
135858 ExprList *pResults;
135859 assert( pItem->pSelect!=0 );
135860 pResults = pItem->pSelect->pEList;
135861 assert( pResults!=0 );
@@ -137347,13 +137364,10 @@
137347
137348 /*
137349 ** Return a pointer to a string containing the 'declaration type' of the
137350 ** expression pExpr. The string may be treated as static by the caller.
137351 **
137352 ** Also try to estimate the size of the returned value and return that
137353 ** result in *pEstWidth.
137354 **
137355 ** The declaration type is the exact datatype definition extracted from the
137356 ** original CREATE TABLE statement if the expression is a column. The
137357 ** declaration type for a ROWID field is INTEGER. Exactly when an expression
137358 ** is considered a column can be complex in the presence of subqueries. The
137359 ** result-set expression in all of the following SELECT statements is
@@ -139595,11 +139609,12 @@
139595 **
139596 ** (3) If the subquery is the right operand of a LEFT JOIN then
139597 ** (3a) the subquery may not be a join and
139598 ** (3b) the FROM clause of the subquery may not contain a virtual
139599 ** table and
139600 ** (3c) the outer query may not be an aggregate.
 
139601 ** (3d) the outer query may not be DISTINCT.
139602 ** See also (26) for restrictions on RIGHT JOIN.
139603 **
139604 ** (4) The subquery can not be DISTINCT.
139605 **
@@ -139649,10 +139664,13 @@
139649 ** (17d) the outer query may not be
139650 ** (17d1) aggregate, or
139651 ** (17d2) DISTINCT
139652 ** (17e) the subquery may not contain window functions, and
139653 ** (17f) the subquery must not be the RHS of a LEFT JOIN.
 
 
 
139654 **
139655 ** The parent and sub-query may contain WHERE clauses. Subject to
139656 ** rules (11), (13) and (14), they may also contain ORDER BY,
139657 ** LIMIT and OFFSET clauses. The subquery cannot use any compound
139658 ** operator other than UNION ALL because all the other compound
@@ -139700,11 +139718,15 @@
139700 **
139701 ** (26) The subquery may not be the right operand of a RIGHT JOIN.
139702 ** See also (3) for restrictions on LEFT JOIN.
139703 **
139704 ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139705 ** is the first element of the parent query.
 
 
 
 
139706 **
139707 ** (28) The subquery is not a MATERIALIZED CTE.
139708 **
139709 ** (29) Either the subquery is not the right-hand operand of a join with an
139710 ** ON or USING clause nor the right-hand operand of a NATURAL JOIN, or
@@ -139800,22 +139822,17 @@
139800 **
139801 ** (t1 LEFT OUTER JOIN t2) JOIN t3
139802 **
139803 ** which is not at all the same thing.
139804 **
139805 ** If the subquery is the right operand of a LEFT JOIN, then the outer
139806 ** query cannot be an aggregate. (3c) This is an artifact of the way
139807 ** aggregates are processed - there is no mechanism to determine if
139808 ** the LEFT JOIN table should be all-NULL.
139809 **
139810 ** See also tickets #306, #350, and #3300.
139811 */
139812 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
139813 if( pSubSrc->nSrc>1 /* (3a) */
139814 || isAgg /* (3c) */
139815 || IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
139816 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
 
139817 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
139818 ){
139819 return 0;
139820 }
139821 isOuterJoin = 1;
@@ -139830,11 +139847,11 @@
139830 }
139831 #endif
139832
139833 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139834 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139835 return 0; /* Restriction (27) */
139836 }
139837 if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139838 return 0; /* (28) */
139839 }
139840
@@ -139850,11 +139867,11 @@
139850 **
139851 ** (29b) The subquery itself must not be the right operand of a
139852 ** NATURAL join or a join that as an ON or USING clause.
139853 **
139854 ** These conditions are sufficient to keep an EP_OuterON from being
139855 ** flattened into an EP_InnerON. Restrictions (3a) and (27) prevent
139856 ** an EP_InnerON from being flattened into an EP_OuterON.
139857 */
139858 if( pSubSrc->nSrc>=2
139859 && (pSubSrc->a[pSubSrc->nSrc-1].fg.jointype & JT_OUTER)!=0
139860 ){
@@ -139891,10 +139908,16 @@
139891 #ifndef SQLITE_OMIT_WINDOWFUNC
139892 || pSub1->pWin /* (17e) */
139893 #endif
139894 ){
139895 return 0;
 
 
 
 
 
 
139896 }
139897 testcase( pSub1->pSrc->nSrc>1 );
139898 }
139899
139900 /* Restriction (18). */
@@ -140724,10 +140747,11 @@
140724 if( p->pWhere
140725 || p->pEList->nExpr!=1
140726 || p->pSrc->nSrc!=1
140727 || p->pSrc->a[0].pSelect
140728 || pAggInfo->nFunc!=1
 
140729 ){
140730 return 0;
140731 }
140732 pTab = p->pSrc->a[0].pTab;
140733 assert( pTab!=0 );
@@ -141425,11 +141449,11 @@
141425
141426 if( (zTabName = pFrom->zAlias)==0 ){
141427 zTabName = pTab->zName;
141428 }
141429 if( db->mallocFailed ) break;
141430 assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141431 if( pFrom->fg.isNestedFrom ){
141432 assert( pFrom->pSelect!=0 );
141433 pNestedFrom = pFrom->pSelect->pEList;
141434 assert( pNestedFrom!=0 );
141435 assert( pNestedFrom->nExpr==pTab->nCol );
@@ -142354,11 +142378,13 @@
142354 && (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
142355 && OptimizationEnabled(db, SQLITE_OmitOrderBy)
142356 ){
142357 SELECTTRACE(0x100,pParse,p,
142358 ("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1));
142359 sqlite3ExprListDelete(db, pSub->pOrderBy);
 
 
142360 pSub->pOrderBy = 0;
142361 }
142362
142363 /* If the outer query contains a "complex" result set (that is,
142364 ** if the result set of the outer query uses functions or subqueries)
@@ -155354,11 +155380,11 @@
155354 #ifndef SQLITE_DEBUG
155355 UNUSED_PARAMETER( pParse );
155356 #endif
155357 assert( pRec!=0 );
155358 assert( pIdx->nSample>0 );
155359 assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol );
155360
155361 /* Do a binary search to find the first sample greater than or equal
155362 ** to pRec. If pRec contains a single field, the set of samples to search
155363 ** is simply the aSample[] array. If the samples in aSample[] contain more
155364 ** than one fields, all fields following the first are ignored.
@@ -155400,11 +155426,11 @@
155400 ** appears that it should be 1 field in size. However, that would make it
155401 ** smaller than sample 1, so the binary search would not work. As a result,
155402 ** it is extended to two fields. The duplicates that this creates do not
155403 ** cause any problems.
155404 */
155405 nField = pRec->nField;
155406 iCol = 0;
155407 iSample = pIdx->nSample * nField;
155408 do{
155409 int iSamp; /* Index in aSample[] of test sample */
155410 int n; /* Number of fields in test sample */
@@ -156117,16 +156143,22 @@
156117 }
156118 }
156119 }
156120
156121 /*
156122 ** Deallocate internal memory used by a WhereLoop object
 
156123 */
156124 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
156125 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
 
 
 
 
156126 whereLoopClearUnion(db, p);
156127 whereLoopInit(p);
 
156128 }
156129
156130 /*
156131 ** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
156132 */
@@ -156146,11 +156178,13 @@
156146 /*
156147 ** Transfer content from the second pLoop into the first.
156148 */
156149 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
156150 whereLoopClearUnion(db, pTo);
156151 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
 
 
156152 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
156153 return SQLITE_NOMEM_BKPT;
156154 }
156155 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
156156 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
@@ -156799,11 +156833,15 @@
156799 pNew->wsFlags = saved_wsFlags;
156800 pNew->u.btree.nEq = saved_nEq;
156801 pNew->u.btree.nBtm = saved_nBtm;
156802 pNew->u.btree.nTop = saved_nTop;
156803 pNew->nLTerm = saved_nLTerm;
156804 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
 
 
 
 
156805 pNew->aLTerm[pNew->nLTerm++] = pTerm;
156806 pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
156807
156808 assert( nInMul==0
156809 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
@@ -156892,42 +156930,43 @@
156892 }
156893 }
156894 if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
156895 }else if( eOp & WO_ISNULL ){
156896 pNew->wsFlags |= WHERE_COLUMN_NULL;
156897 }else if( eOp & (WO_GT|WO_GE) ){
156898 testcase( eOp & WO_GT );
156899 testcase( eOp & WO_GE );
156900 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
156901 pNew->u.btree.nBtm = whereRangeVectorLen(
156902 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156903 );
156904 pBtm = pTerm;
156905 pTop = 0;
156906 if( pTerm->wtFlags & TERM_LIKEOPT ){
156907 /* Range constraints that come from the LIKE optimization are
156908 ** always used in pairs. */
156909 pTop = &pTerm[1];
156910 assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
156911 assert( pTop->wtFlags & TERM_LIKEOPT );
156912 assert( pTop->eOperator==WO_LT );
156913 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156914 pNew->aLTerm[pNew->nLTerm++] = pTop;
156915 pNew->wsFlags |= WHERE_TOP_LIMIT;
156916 pNew->u.btree.nTop = 1;
156917 }
156918 }else{
156919 assert( eOp & (WO_LT|WO_LE) );
156920 testcase( eOp & WO_LT );
156921 testcase( eOp & WO_LE );
156922 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
156923 pNew->u.btree.nTop = whereRangeVectorLen(
156924 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156925 );
156926 pTop = pTerm;
156927 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
156928 pNew->aLTerm[pNew->nLTerm-2] : 0;
 
156929 }
156930
156931 /* At this point pNew->nOut is set to the number of rows expected to
156932 ** be visited by the index scan before considering term pTerm, or the
156933 ** values of nIn and nInMul. In other words, assuming that all
@@ -158089,16 +158128,23 @@
158089 SrcItem *pItem;
158090 SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
158091 sqlite3 *db = pWInfo->pParse->db;
158092 int rc = SQLITE_OK;
158093 int bFirstPastRJ = 0;
 
158094 WhereLoop *pNew;
158095
158096
158097 /* Loop over the tables in the join, from left to right */
158098 pNew = pBuilder->pNew;
158099 whereLoopInit(pNew);
 
 
 
 
 
 
158100 pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
158101 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
158102 Bitmask mUnusable = 0;
158103 pNew->iTab = iTab;
158104 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
@@ -158109,19 +158155,20 @@
158109 /* Add prerequisites to prevent reordering of FROM clause terms
158110 ** across CROSS joins and outer joins. The bFirstPastRJ boolean
158111 ** prevents the right operand of a RIGHT JOIN from being swapped with
158112 ** other elements even further to the right.
158113 **
158114 ** The JT_LTORJ term prevents any FROM-clause term reordering for terms
158115 ** to the left of a RIGHT JOIN. This is conservative. Relaxing this
158116 ** constraint somewhat to prevent terms from crossing from the right
158117 ** side of a LEFT JOIN over to the left side when they are on the
158118 ** left side of a RIGHT JOIN would be sufficient for all known failure
158119 ** cases. FIX ME: Implement this optimization.
158120 */
 
158121 mPrereq |= mPrior;
158122 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
 
 
158123 }
158124 #ifndef SQLITE_OMIT_VIRTUALTABLE
158125 if( IsVirtual(pItem->pTab) ){
158126 SrcItem *p;
158127 for(p=&pItem[1]; p<pEnd; p++){
@@ -158690,13 +158737,13 @@
158690 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
158691 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
158692 LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
158693 LogEst rCost; /* Cost of path (pFrom+pWLoop) */
158694 LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
158695 i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */
158696 Bitmask maskNew; /* Mask of src visited by (..) */
158697 Bitmask revMask = 0; /* Mask of rev-order loops for (..) */
158698
158699 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
158700 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
158701 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
158702 /* Do not use an automatic index if the this loop is expected
@@ -158711,11 +158758,13 @@
158711 ** Compute its cost */
158712 rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
158713 rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
158714 nOut = pFrom->nRow + pWLoop->nOut;
158715 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
 
158716 if( isOrdered<0 ){
 
158717 isOrdered = wherePathSatisfiesOrderBy(pWInfo,
158718 pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
158719 iLoop, pWLoop, &revMask);
158720 }else{
158721 revMask = pFrom->revLoop;
@@ -169958,10 +170007,11 @@
169958 while( 1 ){
169959 n = sqlite3GetToken((u8*)zSql, &tokenType);
169960 mxSqlLen -= n;
169961 if( mxSqlLen<0 ){
169962 pParse->rc = SQLITE_TOOBIG;
 
169963 break;
169964 }
169965 #ifndef SQLITE_OMIT_WINDOWFUNC
169966 if( tokenType>=TK_WINDOW ){
169967 assert( tokenType==TK_SPACE || tokenType==TK_OVER || tokenType==TK_FILTER
@@ -174698,12 +174748,15 @@
174698 sqlite3ShowUpsert(0);
174699 sqlite3ShowTriggerStep(0);
174700 sqlite3ShowTriggerStepList(0);
174701 sqlite3ShowTrigger(0);
174702 sqlite3ShowTriggerList(0);
 
174703 sqlite3ShowWindow(0);
174704 sqlite3ShowWinFunc(0);
 
 
174705 }
174706 #endif
174707 break;
174708 }
174709
@@ -181033,12 +181086,11 @@
181033 static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181034 int iToken; /* Used to iterate through phrase tokens */
181035 char *aPoslist = 0; /* Position list for deferred tokens */
181036 int nPoslist = 0; /* Number of bytes in aPoslist */
181037 int iPrev = -1; /* Token number of previous deferred token */
181038
181039 assert( pPhrase->doclist.bFreeList==0 );
181040
181041 for(iToken=0; iToken<pPhrase->nToken; iToken++){
181042 Fts3PhraseToken *pToken = &pPhrase->aToken[iToken];
181043 Fts3DeferredToken *pDeferred = pToken->pDeferred;
181044
@@ -181048,10 +181100,11 @@
181048 int rc = sqlite3Fts3DeferredTokenList(pDeferred, &pList, &nList);
181049 if( rc!=SQLITE_OK ) return rc;
181050
181051 if( pList==0 ){
181052 sqlite3_free(aPoslist);
 
181053 pPhrase->doclist.pList = 0;
181054 pPhrase->doclist.nList = 0;
181055 return SQLITE_OK;
181056
181057 }else if( aPoslist==0 ){
@@ -181068,10 +181121,11 @@
181068 sqlite3_free(aPoslist);
181069 aPoslist = pList;
181070 nPoslist = (int)(aOut - aPoslist);
181071 if( nPoslist==0 ){
181072 sqlite3_free(aPoslist);
 
181073 pPhrase->doclist.pList = 0;
181074 pPhrase->doclist.nList = 0;
181075 return SQLITE_OK;
181076 }
181077 }
@@ -181107,10 +181161,11 @@
181107 sqlite3_free(aPoslist);
181108 return SQLITE_NOMEM;
181109 }
181110
181111 pPhrase->doclist.pList = aOut;
 
181112 if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
181113 pPhrase->doclist.bFreeList = 1;
181114 pPhrase->doclist.nList = (int)(aOut - pPhrase->doclist.pList);
181115 }else{
181116 sqlite3_free(aOut);
@@ -181119,10 +181174,11 @@
181119 }
181120 sqlite3_free(aPoslist);
181121 }
181122 }
181123
 
181124 return SQLITE_OK;
181125 }
181126 #endif /* SQLITE_DISABLE_FTS4_DEFERRED */
181127
181128 /*
@@ -182293,15 +182349,14 @@
182293 );
182294 break;
182295
182296 default: {
182297 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
182298 if( pCsr->pDeferred
182299 && (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred)
182300 ){
182301 Fts3Phrase *pPhrase = pExpr->pPhrase;
182302 assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
182303 if( pExpr->bDeferred ){
182304 fts3EvalInvalidatePoslist(pPhrase);
182305 }
182306 *pRc = fts3EvalDeferredPhrase(pCsr, pPhrase);
182307 bHit = (pPhrase->doclist.pList!=0);
@@ -212484,15 +212539,16 @@
212484 */
212485 static int dbpageBegin(sqlite3_vtab *pVtab){
212486 DbpageTable *pTab = (DbpageTable *)pVtab;
212487 sqlite3 *db = pTab->db;
212488 int i;
212489 for(i=0; i<db->nDb; i++){
 
212490 Btree *pBt = db->aDb[i].pBt;
212491 if( pBt ) sqlite3BtreeBeginTrans(pBt, 1, 0);
212492 }
212493 return SQLITE_OK;
212494 }
212495
212496
212497 /*
212498 ** Invoke this routine to register the "dbpage" virtual table module
@@ -236615,11 +236671,11 @@
236615 int nArg, /* Number of args */
236616 sqlite3_value **apUnused /* Function arguments */
236617 ){
236618 assert( nArg==0 );
236619 UNUSED_PARAM2(nArg, apUnused);
236620 sqlite3_result_text(pCtx, "fts5: 2022-06-25 14:57:57 14e166f40dbfa6e055543f8301525f2ca2e96a02a57269818b9e69e162e98918", -1, SQLITE_TRANSIENT);
236621 }
236622
236623 /*
236624 ** Return true if zName is the extension on one of the shadow tables used
236625 ** by this module.
@@ -241286,10 +241342,20 @@
241286 /* #include <assert.h> */
241287 /* #include <string.h> */
241288
241289 #ifndef SQLITE_OMIT_VIRTUALTABLE
241290
 
 
 
 
 
 
 
 
 
 
241291 /* stmt_vtab is a subclass of sqlite3_vtab which will
241292 ** serve as the underlying representation of a stmt virtual table
241293 */
241294 typedef struct stmt_vtab stmt_vtab;
241295 struct stmt_vtab {
@@ -241303,12 +241369,11 @@
241303 */
241304 typedef struct stmt_cursor stmt_cursor;
241305 struct stmt_cursor {
241306 sqlite3_vtab_cursor base; /* Base class - must be first */
241307 sqlite3 *db; /* Database connection for this cursor */
241308 sqlite3_stmt *pStmt; /* Statement cursor is currently pointing at */
241309 sqlite3_int64 iRowid; /* The rowid */
241310 };
241311
241312 /*
241313 ** The stmtConnect() method is invoked to create a new
241314 ** stmt_vtab that describes the stmt virtual table.
@@ -241348,11 +241413,11 @@
241348
241349 rc = sqlite3_declare_vtab(db,
241350 "CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,"
241351 "reprep,run,mem)");
241352 if( rc==SQLITE_OK ){
241353 pNew = sqlite3_malloc( sizeof(*pNew) );
241354 *ppVtab = (sqlite3_vtab*)pNew;
241355 if( pNew==0 ) return SQLITE_NOMEM;
241356 memset(pNew, 0, sizeof(*pNew));
241357 pNew->db = db;
241358 }
@@ -241370,22 +241435,33 @@
241370 /*
241371 ** Constructor for a new stmt_cursor object.
241372 */
241373 static int stmtOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
241374 stmt_cursor *pCur;
241375 pCur = sqlite3_malloc( sizeof(*pCur) );
241376 if( pCur==0 ) return SQLITE_NOMEM;
241377 memset(pCur, 0, sizeof(*pCur));
241378 pCur->db = ((stmt_vtab*)p)->db;
241379 *ppCursor = &pCur->base;
241380 return SQLITE_OK;
241381 }
 
 
 
 
 
 
 
 
 
 
241382
241383 /*
241384 ** Destructor for a stmt_cursor.
241385 */
241386 static int stmtClose(sqlite3_vtab_cursor *cur){
 
241387 sqlite3_free(cur);
241388 return SQLITE_OK;
241389 }
241390
241391
@@ -241392,12 +241468,13 @@
241392 /*
241393 ** Advance a stmt_cursor to its next row of output.
241394 */
241395 static int stmtNext(sqlite3_vtab_cursor *cur){
241396 stmt_cursor *pCur = (stmt_cursor*)cur;
241397 pCur->iRowid++;
241398 pCur->pStmt = sqlite3_next_stmt(pCur->db, pCur->pStmt);
 
241399 return SQLITE_OK;
241400 }
241401
241402 /*
241403 ** Return values of columns for the row at which the stmt_cursor
@@ -241407,43 +241484,15 @@
241407 sqlite3_vtab_cursor *cur, /* The cursor */
241408 sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
241409 int i /* Which column to return */
241410 ){
241411 stmt_cursor *pCur = (stmt_cursor*)cur;
241412 switch( i ){
241413 case STMT_COLUMN_SQL: {
241414 sqlite3_result_text(ctx, sqlite3_sql(pCur->pStmt), -1, SQLITE_TRANSIENT);
241415 break;
241416 }
241417 case STMT_COLUMN_NCOL: {
241418 sqlite3_result_int(ctx, sqlite3_column_count(pCur->pStmt));
241419 break;
241420 }
241421 case STMT_COLUMN_RO: {
241422 sqlite3_result_int(ctx, sqlite3_stmt_readonly(pCur->pStmt));
241423 break;
241424 }
241425 case STMT_COLUMN_BUSY: {
241426 sqlite3_result_int(ctx, sqlite3_stmt_busy(pCur->pStmt));
241427 break;
241428 }
241429 default: {
241430 assert( i==STMT_COLUMN_MEM );
241431 i = SQLITE_STMTSTATUS_MEMUSED +
241432 STMT_COLUMN_NSCAN - SQLITE_STMTSTATUS_FULLSCAN_STEP;
241433 /* Fall thru */
241434 }
241435 case STMT_COLUMN_NSCAN:
241436 case STMT_COLUMN_NSORT:
241437 case STMT_COLUMN_NAIDX:
241438 case STMT_COLUMN_NSTEP:
241439 case STMT_COLUMN_REPREP:
241440 case STMT_COLUMN_RUN: {
241441 sqlite3_result_int(ctx, sqlite3_stmt_status(pCur->pStmt,
241442 i-STMT_COLUMN_NSCAN+SQLITE_STMTSTATUS_FULLSCAN_STEP, 0));
241443 break;
241444 }
241445 }
241446 return SQLITE_OK;
241447 }
241448
241449 /*
@@ -241450,21 +241499,21 @@
241450 ** Return the rowid for the current row. In this implementation, the
241451 ** rowid is the same as the output value.
241452 */
241453 static int stmtRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
241454 stmt_cursor *pCur = (stmt_cursor*)cur;
241455 *pRowid = pCur->iRowid;
241456 return SQLITE_OK;
241457 }
241458
241459 /*
241460 ** Return TRUE if the cursor has been moved off of the last
241461 ** row of output.
241462 */
241463 static int stmtEof(sqlite3_vtab_cursor *cur){
241464 stmt_cursor *pCur = (stmt_cursor*)cur;
241465 return pCur->pStmt==0;
241466 }
241467
241468 /*
241469 ** This method is called to "rewind" the stmt_cursor object back
241470 ** to the first row of output. This method is always called at least
@@ -241475,13 +241524,57 @@
241475 sqlite3_vtab_cursor *pVtabCursor,
241476 int idxNum, const char *idxStr,
241477 int argc, sqlite3_value **argv
241478 ){
241479 stmt_cursor *pCur = (stmt_cursor *)pVtabCursor;
241480 pCur->pStmt = 0;
241481 pCur->iRowid = 0;
241482 return stmtNext(pVtabCursor);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241483 }
241484
241485 /*
241486 ** SQLite will invoke this method one or more times while planning a query
241487 ** that uses the stmt virtual table. This routine needs to create
241488
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.40.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -450,13 +450,13 @@
450 **
451 ** See also: [sqlite3_libversion()],
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.40.0"
456 #define SQLITE_VERSION_NUMBER 3040000
457 #define SQLITE_SOURCE_ID "2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -6586,11 +6586,11 @@
6586 ** CAPI3REF: Return The Schema Name For A Database Connection
6587 ** METHOD: sqlite3
6588 **
6589 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6590 ** for the N-th database on database connection D, or a NULL pointer of N is
6591 ** out of range. An N value of 0 means the main database file. An N of 1 is
6592 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6593 ** databases.
6594 **
6595 ** Space to hold the string that is returned by sqlite3_db_name() is managed
6596 ** by SQLite itself. The string might be deallocated by any operation that
@@ -15553,67 +15553,67 @@
15553 #define OP_Checkpoint 3
15554 #define OP_JournalMode 4
15555 #define OP_Vacuum 5
15556 #define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */
15557 #define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */
15558 #define OP_Init 8 /* jump, synopsis: Start at P2 */
15559 #define OP_Goto 9 /* jump */
15560 #define OP_Gosub 10 /* jump */
15561 #define OP_InitCoroutine 11 /* jump */
15562 #define OP_Yield 12 /* jump */
15563 #define OP_MustBeInt 13 /* jump */
15564 #define OP_Jump 14 /* jump */
15565 #define OP_Once 15 /* jump */
15566 #define OP_If 16 /* jump */
15567 #define OP_IfNot 17 /* jump */
15568 #define OP_IsNullOrType 18 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
15569 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
15570 #define OP_IfNullRow 20 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15571 #define OP_SeekLT 21 /* jump, synopsis: key=r[P3@P4] */
15572 #define OP_SeekLE 22 /* jump, synopsis: key=r[P3@P4] */
15573 #define OP_SeekGE 23 /* jump, synopsis: key=r[P3@P4] */
15574 #define OP_SeekGT 24 /* jump, synopsis: key=r[P3@P4] */
15575 #define OP_IfNotOpen 25 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15576 #define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */
15577 #define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */
15578 #define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
15579 #define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
15580 #define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
15581 #define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
15582 #define OP_Last 32 /* jump */
15583 #define OP_IfSmaller 33 /* jump */
15584 #define OP_SorterSort 34 /* jump */
15585 #define OP_Sort 35 /* jump */
15586 #define OP_Rewind 36 /* jump */
15587 #define OP_SorterNext 37 /* jump */
15588 #define OP_Prev 38 /* jump */
15589 #define OP_Next 39 /* jump */
15590 #define OP_IdxLE 40 /* jump, synopsis: key=r[P3@P4] */
15591 #define OP_IdxGT 41 /* jump, synopsis: key=r[P3@P4] */
15592 #define OP_IdxLT 42 /* jump, synopsis: key=r[P3@P4] */
15593 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
15594 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15595 #define OP_IdxGE 45 /* jump, synopsis: key=r[P3@P4] */
15596 #define OP_RowSetRead 46 /* jump, synopsis: r[P3]=rowset(P1) */
15597 #define OP_RowSetTest 47 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15598 #define OP_Program 48 /* jump */
15599 #define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15600 #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
15601 #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
15602 #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
15603 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
15604 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
15605 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15606 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15607 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15608 #define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15609 #define OP_IfPos 59 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15610 #define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15611 #define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15612 #define OP_IncrVacuum 62 /* jump */
15613 #define OP_VNext 63 /* jump */
15614 #define OP_Filter 64 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
15615 #define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */
15616 #define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */
15617 #define OP_Return 67
15618 #define OP_EndCoroutine 68
15619 #define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */
@@ -15745,17 +15745,17 @@
15745 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
15746 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
15747 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
15748 #define OPFLG_INITIALIZER {\
15749 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
15750 /* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
15751 /* 16 */ 0x03, 0x03, 0x03, 0x12, 0x01, 0x09, 0x09, 0x09,\
15752 /* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
15753 /* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15754 /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\
15755 /* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15756 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
15757 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
15758 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
15759 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
15760 /* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
15761 /* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
@@ -19777,18 +19777,20 @@
19777 SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
19778 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19779 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19780 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19781 SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19782 #if TREETRACE_ENABLED
19783 SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
19784 const ExprList*,const Expr*, const Trigger*);
19785 SQLITE_PRIVATE void sqlite3TreeViewInsert(const With*, const SrcList*,
19786 const IdList*, const Select*, const ExprList*,
19787 int, const Upsert*, const Trigger*);
19788 SQLITE_PRIVATE void sqlite3TreeViewUpdate(const With*, const SrcList*, const ExprList*,
19789 const Expr*, int, const ExprList*, const Expr*,
19790 const Upsert*, const Trigger*);
19791 #endif
19792 #ifndef SQLITE_OMIT_TRIGGER
19793 SQLITE_PRIVATE void sqlite3TreeViewTriggerStep(TreeView*, const TriggerStep*, u8, u8);
19794 SQLITE_PRIVATE void sqlite3TreeViewTrigger(TreeView*, const Trigger*, u8, u8);
19795 #endif
19796 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -29559,12 +29561,17 @@
29561 if( db->nVdbeExec>0 ){
29562 AtomicStore(&db->u1.isInterrupted, 1);
29563 }
29564 DisableLookaside;
29565 if( db->pParse ){
29566 Parse *pParse;
29567 sqlite3ErrorMsg(db->pParse, "out of memory");
29568 db->pParse->rc = SQLITE_NOMEM_BKPT;
29569 for(pParse=db->pParse->pOuterParse; pParse; pParse = pParse->pOuterParse){
29570 pParse->nErr++;
29571 pParse->rc = SQLITE_NOMEM;
29572 }
29573 }
29574 }
29575 return 0;
29576 }
29577
@@ -30426,12 +30433,12 @@
30433 }
30434 break;
30435 case etSQLESCAPE: /* %q: Escape ' characters */
30436 case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */
30437 case etSQLESCAPE3: { /* %w: Escape " characters */
30438 i64 i, j, k, n;
30439 int needQuote, isnull;
30440 char ch;
30441 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
30442 char *escarg;
30443
30444 if( bArgList ){
@@ -31115,12 +31122,12 @@
31122 int i;
31123 sqlite3TreeViewPush(&pView, moreToFollow);
31124 sqlite3TreeViewLine(pView, "COLUMNS");
31125 for(i=0; i<nCol; i++){
31126 u16 flg = aCol[i].colFlags;
31127 int colMoreToFollow = i<(nCol - 1);
31128 sqlite3TreeViewPush(&pView, colMoreToFollow);
31129 sqlite3TreeViewLine(pView, 0);
31130 printf(" %s", aCol[i].zCnName);
31131 switch( aCol[i].eCType ){
31132 case COLTYPE_ANY: printf(" ANY"); break;
31133 case COLTYPE_BLOB: printf(" BLOB"); break;
@@ -31247,11 +31254,11 @@
31254 if( pItem->pSelect ){
31255 if( pItem->pTab ){
31256 Table *pTab = pItem->pTab;
31257 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31258 }
31259 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31260 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
31261 }
31262 if( pItem->fg.isTabFunc ){
31263 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31264 }
@@ -32014,10 +32021,11 @@
32021 pUpsert = pUpsert->pNextUpsert;
32022 }
32023 sqlite3TreeViewPop(&pView);
32024 }
32025
32026 #if TREETRACE_ENABLED
32027 /*
32028 ** Generate a human-readable diagram of the data structure that go
32029 ** into generating an DELETE statement.
32030 */
32031 SQLITE_PRIVATE void sqlite3TreeViewDelete(
@@ -32067,11 +32075,13 @@
32075 if( pTrigger ){
32076 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32077 }
32078 sqlite3TreeViewPop(&pView);
32079 }
32080 #endif /* TREETRACE_ENABLED */
32081
32082 #if TREETRACE_ENABLED
32083 /*
32084 ** Generate a human-readable diagram of the data structure that go
32085 ** into generating an INSERT statement.
32086 */
32087 SQLITE_PRIVATE void sqlite3TreeViewInsert(
@@ -32135,11 +32145,13 @@
32145 if( pTrigger ){
32146 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32147 }
32148 sqlite3TreeViewPop(&pView);
32149 }
32150 #endif /* TREETRACE_ENABLED */
32151
32152 #if TREETRACE_ENABLED
32153 /*
32154 ** Generate a human-readable diagram of the data structure that go
32155 ** into generating an UPDATE statement.
32156 */
32157 SQLITE_PRIVATE void sqlite3TreeViewUpdate(
@@ -32211,10 +32223,11 @@
32223 if( pTrigger ){
32224 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32225 }
32226 sqlite3TreeViewPop(&pView);
32227 }
32228 #endif /* TREETRACE_ENABLED */
32229
32230 #ifndef SQLITE_OMIT_TRIGGER
32231 /*
32232 ** Show a human-readable graph of a TriggerStep
32233 */
@@ -35267,67 +35280,67 @@
35280 /* 3 */ "Checkpoint" OpHelp(""),
35281 /* 4 */ "JournalMode" OpHelp(""),
35282 /* 5 */ "Vacuum" OpHelp(""),
35283 /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
35284 /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
35285 /* 8 */ "Init" OpHelp("Start at P2"),
35286 /* 9 */ "Goto" OpHelp(""),
35287 /* 10 */ "Gosub" OpHelp(""),
35288 /* 11 */ "InitCoroutine" OpHelp(""),
35289 /* 12 */ "Yield" OpHelp(""),
35290 /* 13 */ "MustBeInt" OpHelp(""),
35291 /* 14 */ "Jump" OpHelp(""),
35292 /* 15 */ "Once" OpHelp(""),
35293 /* 16 */ "If" OpHelp(""),
35294 /* 17 */ "IfNot" OpHelp(""),
35295 /* 18 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
35296 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
35297 /* 20 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35298 /* 21 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35299 /* 22 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35300 /* 23 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35301 /* 24 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35302 /* 25 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35303 /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35304 /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35305 /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
35306 /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
35307 /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35308 /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
35309 /* 32 */ "Last" OpHelp(""),
35310 /* 33 */ "IfSmaller" OpHelp(""),
35311 /* 34 */ "SorterSort" OpHelp(""),
35312 /* 35 */ "Sort" OpHelp(""),
35313 /* 36 */ "Rewind" OpHelp(""),
35314 /* 37 */ "SorterNext" OpHelp(""),
35315 /* 38 */ "Prev" OpHelp(""),
35316 /* 39 */ "Next" OpHelp(""),
35317 /* 40 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35318 /* 41 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35319 /* 42 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35320 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
35321 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
35322 /* 45 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35323 /* 46 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35324 /* 47 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35325 /* 48 */ "Program" OpHelp(""),
35326 /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35327 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
35328 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
35329 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
35330 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
35331 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
35332 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
35333 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
35334 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
35335 /* 58 */ "ElseEq" OpHelp(""),
35336 /* 59 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35337 /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35338 /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35339 /* 62 */ "IncrVacuum" OpHelp(""),
35340 /* 63 */ "VNext" OpHelp(""),
35341 /* 64 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35342 /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
35343 /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
35344 /* 67 */ "Return" OpHelp(""),
35345 /* 68 */ "EndCoroutine" OpHelp(""),
35346 /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
@@ -68301,11 +68314,10 @@
68314 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
68315 assert( pPage->pBt!=0 );
68316 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
68317 assert( pPage->nOverflow==0 );
68318 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 
68319 src = data = pPage->aData;
68320 hdr = pPage->hdrOffset;
68321 cellOffset = pPage->cellOffset;
68322 nCell = pPage->nCell;
68323 assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
@@ -68356,43 +68368,42 @@
68368 }
68369
68370 cbrk = usableSize;
68371 iCellLast = usableSize - 4;
68372 iCellStart = get2byte(&data[hdr+5]);
68373 if( nCell>0 ){
68374 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68375 memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68376 src = temp;
68377 for(i=0; i<nCell; i++){
68378 u8 *pAddr; /* The i-th cell pointer */
68379 pAddr = &data[cellOffset + i*2];
68380 pc = get2byte(pAddr);
68381 testcase( pc==iCellFirst );
68382 testcase( pc==iCellLast );
68383 /* These conditions have already been verified in btreeInitPage()
68384 ** if PRAGMA cell_size_check=ON.
68385 */
68386 if( pc<iCellStart || pc>iCellLast ){
68387 return SQLITE_CORRUPT_PAGE(pPage);
68388 }
68389 assert( pc>=iCellStart && pc<=iCellLast );
68390 size = pPage->xCellSize(pPage, &src[pc]);
68391 cbrk -= size;
68392 if( cbrk<iCellStart || pc+size>usableSize ){
68393 return SQLITE_CORRUPT_PAGE(pPage);
68394 }
68395 assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68396 testcase( cbrk+size==usableSize );
68397 testcase( pc+size==usableSize );
68398 put2byte(pAddr, cbrk);
68399 memcpy(&data[cbrk], &src[pc], size);
68400 }
 
68401 }
68402 data[hdr+7] = 0;
68403
68404 defragment_out:
68405 assert( pPage->nFree>=0 );
68406 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
68407 return SQLITE_CORRUPT_PAGE(pPage);
68408 }
68409 assert( cbrk>=iCellFirst );
@@ -68461,13 +68472,13 @@
68472 return &aData[pc + x];
68473 }
68474 iAddr = pc;
68475 pTmp = &aData[pc];
68476 pc = get2byte(pTmp);
68477 if( pc<=iAddr ){
68478 if( pc ){
68479 /* The next slot in the chain comes before the current slot */
68480 *pRc = SQLITE_CORRUPT_PAGE(pPg);
68481 }
68482 return 0;
68483 }
68484 }
@@ -68615,11 +68626,11 @@
68626 iPtr = hdr + 1;
68627 if( data[iPtr+1]==0 && data[iPtr]==0 ){
68628 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
68629 }else{
68630 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
68631 if( iFreeBlk<=iPtr ){
68632 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
68633 return SQLITE_CORRUPT_PAGE(pPage);
68634 }
68635 iPtr = iFreeBlk;
68636 }
@@ -69097,13 +69108,11 @@
69108 if( pCur ){
69109 pCur->iPage--;
69110 pCur->pPage = pCur->apPage[pCur->iPage];
69111 }
69112 testcase( pgno==0 );
69113 assert( pgno!=0 || rc!=SQLITE_OK );
 
 
69114 return rc;
69115 }
69116
69117 /*
69118 ** Release a MemPage. This should be called once for each prior
@@ -72041,12 +72050,10 @@
72050 ** the new child page does not match the flags field of the parent (i.e.
72051 ** if an intkey page appears to be the parent of a non-intkey page, or
72052 ** vice-versa).
72053 */
72054 static int moveToChild(BtCursor *pCur, u32 newPgno){
 
 
72055 assert( cursorOwnsBtShared(pCur) );
72056 assert( pCur->eState==CURSOR_VALID );
72057 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
72058 assert( pCur->iPage>=0 );
72059 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
@@ -72056,11 +72063,12 @@
72063 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
72064 pCur->aiIdx[pCur->iPage] = pCur->ix;
72065 pCur->apPage[pCur->iPage] = pCur->pPage;
72066 pCur->ix = 0;
72067 pCur->iPage++;
72068 return getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur,
72069 pCur->curPagerFlags);
72070 }
72071
72072 #ifdef SQLITE_DEBUG
72073 /*
72074 ** Page pParent is an internal (non-leaf) tree page. This function
@@ -72162,11 +72170,11 @@
72170 assert( pCur->skipNext!=SQLITE_OK );
72171 return pCur->skipNext;
72172 }
72173 sqlite3BtreeClearCursor(pCur);
72174 }
72175 rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
72176 0, pCur->curPagerFlags);
72177 if( rc!=SQLITE_OK ){
72178 pCur->eState = CURSOR_INVALID;
72179 return rc;
72180 }
@@ -73803,16 +73811,10 @@
73811 data = pPage->aData;
73812 ptr = &pPage->aCellIdx[2*idx];
73813 assert( pPage->pBt->usableSize > (u32)(ptr-data) );
73814 pc = get2byte(ptr);
73815 hdr = pPage->hdrOffset;
 
 
 
 
 
 
73816 testcase( pc==(u32)get2byte(&data[hdr+5]) );
73817 testcase( pc+sz==pPage->pBt->usableSize );
73818 if( pc+sz > pPage->pBt->usableSize ){
73819 *pRC = SQLITE_CORRUPT_BKPT;
73820 return;
@@ -80759,11 +80761,18 @@
80761 return 0;
80762 }
80763 #endif
80764
80765 /*
80766 ** Swap byte-code between two VDBE structures.
80767 **
80768 ** This happens after pB was previously run and returned
80769 ** SQLITE_SCHEMA. The statement was then reprepared in pA.
80770 ** This routine transfers the new bytecode in pA over to pB
80771 ** so that pB can be run again. The old pB byte code is
80772 ** moved back to pA so that it will be cleaned up when pA is
80773 ** finalized.
80774 */
80775 SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
80776 Vdbe tmp, *pTmp;
80777 char *zTmp;
80778 assert( pA->db==pB->db );
@@ -81450,12 +81459,12 @@
81459 Parse *pParse = p->pParse;
81460 int *aLabel = pParse->aLabel;
81461 p->readOnly = 1;
81462 p->bIsReader = 0;
81463 pOp = &p->aOp[p->nOp-1];
81464 assert( p->aOp[0].opcode==OP_Init );
81465 while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
81466 /* Only JUMP opcodes and the short list of special opcodes in the switch
81467 ** below need to be considered. The mkopcodeh.tcl generator script groups
81468 ** all these opcodes together near the front of the opcode list. Skip
81469 ** any opcode that does not need processing by virtual of the fact that
81470 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -81480,10 +81489,14 @@
81489 case OP_JournalMode: {
81490 p->readOnly = 0;
81491 p->bIsReader = 1;
81492 break;
81493 }
81494 case OP_Init: {
81495 assert( pOp->p2>=0 );
81496 goto resolve_p2_values_loop_exit;
81497 }
81498 #ifndef SQLITE_OMIT_VIRTUALTABLE
81499 case OP_VUpdate: {
81500 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
81501 break;
81502 }
@@ -81512,13 +81525,14 @@
81525 /* The mkopcodeh.tcl script has so arranged things that the only
81526 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
81527 ** have non-negative values for P2. */
81528 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
81529 }
81530 assert( pOp>p->aOp );
81531 pOp--;
81532 }
81533 resolve_p2_values_loop_exit:
81534 if( aLabel ){
81535 sqlite3DbFreeNN(p->db, pParse->aLabel);
81536 pParse->aLabel = 0;
81537 }
81538 pParse->nLabel = 0;
@@ -86040,11 +86054,13 @@
86054 Vdbe *v = (Vdbe*)pStmt;
86055 sqlite3 *db = v->db;
86056 if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
86057 sqlite3_mutex_enter(db->mutex);
86058 checkProfileCallback(db, v);
86059 assert( v->eVdbeState>=VDBE_READY_STATE );
86060 rc = sqlite3VdbeReset(v);
86061 sqlite3VdbeDelete(v);
86062 rc = sqlite3ApiExit(db, rc);
86063 sqlite3LeaveMutexAndCloseZombie(db);
86064 }
86065 return rc;
86066 }
@@ -90933,15 +90949,18 @@
90949 **
90950 ** Check the cursor P1 to see if it is currently pointing at a NULL row.
90951 ** If it is, then set register P3 to NULL and jump immediately to P2.
90952 ** If P1 is not on a NULL row, then fall through without making any
90953 ** changes.
90954 **
90955 ** If P1 is not an open cursor, then this opcode is a no-op.
90956 */
90957 case OP_IfNullRow: { /* jump */
90958 VdbeCursor *pC;
90959 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90960 pC = p->apCsr[pOp->p1];
90961 if( ALWAYS(pC) && pC->nullRow ){
90962 sqlite3VdbeMemSetNull(aMem + pOp->p3);
90963 goto jump_to_p2;
90964 }
90965 break;
90966 }
@@ -101759,11 +101778,11 @@
101778 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
101779 u8 hCol;
101780 pTab = pItem->pTab;
101781 assert( pTab!=0 && pTab->zName!=0 );
101782 assert( pTab->nCol>0 || pParse->nErr );
101783 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
101784 if( pItem->fg.isNestedFrom ){
101785 /* In this case, pItem is a subquery that has been formed from a
101786 ** parenthesized subset of the FROM clause terms. Example:
101787 ** .... FROM t1 LEFT JOIN (t2 RIGHT JOIN t3 USING(x)) USING(y) ...
101788 ** \_________________________/
@@ -115449,12 +115468,10 @@
115468 pParse->nested++;
115469 memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
115470 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
115471 db->mDbFlags |= DBFLAG_PreferBuiltin;
115472 sqlite3RunParser(pParse, zSql);
 
 
115473 db->mDbFlags = savedDbFlags;
115474 sqlite3DbFree(db, zSql);
115475 memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
115476 pParse->nested--;
115477 }
@@ -135851,11 +135868,11 @@
135868 /*
135869 ** Mark a subquery result column as having been used.
135870 */
135871 SQLITE_PRIVATE void sqlite3SrcItemColumnUsed(SrcItem *pItem, int iCol){
135872 assert( pItem!=0 );
135873 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
135874 if( pItem->fg.isNestedFrom ){
135875 ExprList *pResults;
135876 assert( pItem->pSelect!=0 );
135877 pResults = pItem->pSelect->pEList;
135878 assert( pResults!=0 );
@@ -137347,13 +137364,10 @@
137364
137365 /*
137366 ** Return a pointer to a string containing the 'declaration type' of the
137367 ** expression pExpr. The string may be treated as static by the caller.
137368 **
 
 
 
137369 ** The declaration type is the exact datatype definition extracted from the
137370 ** original CREATE TABLE statement if the expression is a column. The
137371 ** declaration type for a ROWID field is INTEGER. Exactly when an expression
137372 ** is considered a column can be complex in the presence of subqueries. The
137373 ** result-set expression in all of the following SELECT statements is
@@ -139595,11 +139609,12 @@
139609 **
139610 ** (3) If the subquery is the right operand of a LEFT JOIN then
139611 ** (3a) the subquery may not be a join and
139612 ** (3b) the FROM clause of the subquery may not contain a virtual
139613 ** table and
139614 ** (3c) The outer query may not have a GROUP BY. (This limitation is
139615 ** due to how TK_IF_NULL_ROW works. FIX ME!)
139616 ** (3d) the outer query may not be DISTINCT.
139617 ** See also (26) for restrictions on RIGHT JOIN.
139618 **
139619 ** (4) The subquery can not be DISTINCT.
139620 **
@@ -139649,10 +139664,13 @@
139664 ** (17d) the outer query may not be
139665 ** (17d1) aggregate, or
139666 ** (17d2) DISTINCT
139667 ** (17e) the subquery may not contain window functions, and
139668 ** (17f) the subquery must not be the RHS of a LEFT JOIN.
139669 ** (17g) either the subquery is the first element of the outer
139670 ** query or there are no RIGHT or FULL JOINs in any arm
139671 ** of the subquery. (This is a duplicate of condition (27b).)
139672 **
139673 ** The parent and sub-query may contain WHERE clauses. Subject to
139674 ** rules (11), (13) and (14), they may also contain ORDER BY,
139675 ** LIMIT and OFFSET clauses. The subquery cannot use any compound
139676 ** operator other than UNION ALL because all the other compound
@@ -139700,11 +139718,15 @@
139718 **
139719 ** (26) The subquery may not be the right operand of a RIGHT JOIN.
139720 ** See also (3) for restrictions on LEFT JOIN.
139721 **
139722 ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139723 ** is the first element of the parent query. This must be the
139724 ** the case if:
139725 ** (27a) the subquery is not compound query, and
139726 ** (27b) the subquery is a compound query and the RIGHT JOIN occurs
139727 ** in any arm of the compound query. (See also (17g).)
139728 **
139729 ** (28) The subquery is not a MATERIALIZED CTE.
139730 **
139731 ** (29) Either the subquery is not the right-hand operand of a join with an
139732 ** ON or USING clause nor the right-hand operand of a NATURAL JOIN, or
@@ -139800,22 +139822,17 @@
139822 **
139823 ** (t1 LEFT OUTER JOIN t2) JOIN t3
139824 **
139825 ** which is not at all the same thing.
139826 **
 
 
 
 
 
139827 ** See also tickets #306, #350, and #3300.
139828 */
139829 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
139830 if( pSubSrc->nSrc>1 /* (3a) */
 
139831 || IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
139832 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
139833 || (p->pGroupBy!=0) /* (3c) */
139834 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
139835 ){
139836 return 0;
139837 }
139838 isOuterJoin = 1;
@@ -139830,11 +139847,11 @@
139847 }
139848 #endif
139849
139850 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139851 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139852 return 0; /* Restriction (27a) */
139853 }
139854 if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139855 return 0; /* (28) */
139856 }
139857
@@ -139850,11 +139867,11 @@
139867 **
139868 ** (29b) The subquery itself must not be the right operand of a
139869 ** NATURAL join or a join that as an ON or USING clause.
139870 **
139871 ** These conditions are sufficient to keep an EP_OuterON from being
139872 ** flattened into an EP_InnerON. Restrictions (3a) and (27a) prevent
139873 ** an EP_InnerON from being flattened into an EP_OuterON.
139874 */
139875 if( pSubSrc->nSrc>=2
139876 && (pSubSrc->a[pSubSrc->nSrc-1].fg.jointype & JT_OUTER)!=0
139877 ){
@@ -139891,10 +139908,16 @@
139908 #ifndef SQLITE_OMIT_WINDOWFUNC
139909 || pSub1->pWin /* (17e) */
139910 #endif
139911 ){
139912 return 0;
139913 }
139914 if( iFrom>0 && (pSub1->pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139915 /* Without this restriction, the JT_LTORJ flag would end up being
139916 ** omitted on left-hand tables of the right join that is being
139917 ** flattened. */
139918 return 0; /* Restrictions (17g), (27b) */
139919 }
139920 testcase( pSub1->pSrc->nSrc>1 );
139921 }
139922
139923 /* Restriction (18). */
@@ -140724,10 +140747,11 @@
140747 if( p->pWhere
140748 || p->pEList->nExpr!=1
140749 || p->pSrc->nSrc!=1
140750 || p->pSrc->a[0].pSelect
140751 || pAggInfo->nFunc!=1
140752 || p->pHaving
140753 ){
140754 return 0;
140755 }
140756 pTab = p->pSrc->a[0].pTab;
140757 assert( pTab!=0 );
@@ -141425,11 +141449,11 @@
141449
141450 if( (zTabName = pFrom->zAlias)==0 ){
141451 zTabName = pTab->zName;
141452 }
141453 if( db->mallocFailed ) break;
141454 assert( (int)pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141455 if( pFrom->fg.isNestedFrom ){
141456 assert( pFrom->pSelect!=0 );
141457 pNestedFrom = pFrom->pSelect->pEList;
141458 assert( pNestedFrom!=0 );
141459 assert( pNestedFrom->nExpr==pTab->nCol );
@@ -142354,11 +142378,13 @@
142378 && (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
142379 && OptimizationEnabled(db, SQLITE_OmitOrderBy)
142380 ){
142381 SELECTTRACE(0x100,pParse,p,
142382 ("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1));
142383 sqlite3ParserAddCleanup(pParse,
142384 (void(*)(sqlite3*,void*))sqlite3ExprListDelete,
142385 pSub->pOrderBy);
142386 pSub->pOrderBy = 0;
142387 }
142388
142389 /* If the outer query contains a "complex" result set (that is,
142390 ** if the result set of the outer query uses functions or subqueries)
@@ -155354,11 +155380,11 @@
155380 #ifndef SQLITE_DEBUG
155381 UNUSED_PARAMETER( pParse );
155382 #endif
155383 assert( pRec!=0 );
155384 assert( pIdx->nSample>0 );
155385 assert( pRec->nField>0 );
155386
155387 /* Do a binary search to find the first sample greater than or equal
155388 ** to pRec. If pRec contains a single field, the set of samples to search
155389 ** is simply the aSample[] array. If the samples in aSample[] contain more
155390 ** than one fields, all fields following the first are ignored.
@@ -155400,11 +155426,11 @@
155426 ** appears that it should be 1 field in size. However, that would make it
155427 ** smaller than sample 1, so the binary search would not work. As a result,
155428 ** it is extended to two fields. The duplicates that this creates do not
155429 ** cause any problems.
155430 */
155431 nField = MIN(pRec->nField, pIdx->nSample);
155432 iCol = 0;
155433 iSample = pIdx->nSample * nField;
155434 do{
155435 int iSamp; /* Index in aSample[] of test sample */
155436 int n; /* Number of fields in test sample */
@@ -156117,16 +156143,22 @@
156143 }
156144 }
156145 }
156146
156147 /*
156148 ** Deallocate internal memory used by a WhereLoop object. Leave the
156149 ** object in an initialized state, as if it had been newly allocated.
156150 */
156151 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
156152 if( p->aLTerm!=p->aLTermSpace ){
156153 sqlite3DbFreeNN(db, p->aLTerm);
156154 p->aLTerm = p->aLTermSpace;
156155 p->nLSlot = ArraySize(p->aLTermSpace);
156156 }
156157 whereLoopClearUnion(db, p);
156158 p->nLTerm = 0;
156159 p->wsFlags = 0;
156160 }
156161
156162 /*
156163 ** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
156164 */
@@ -156146,11 +156178,13 @@
156178 /*
156179 ** Transfer content from the second pLoop into the first.
156180 */
156181 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
156182 whereLoopClearUnion(db, pTo);
156183 if( pFrom->nLTerm > pTo->nLSlot
156184 && whereLoopResize(db, pTo, pFrom->nLTerm)
156185 ){
156186 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
156187 return SQLITE_NOMEM_BKPT;
156188 }
156189 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
156190 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
@@ -156799,11 +156833,15 @@
156833 pNew->wsFlags = saved_wsFlags;
156834 pNew->u.btree.nEq = saved_nEq;
156835 pNew->u.btree.nBtm = saved_nBtm;
156836 pNew->u.btree.nTop = saved_nTop;
156837 pNew->nLTerm = saved_nLTerm;
156838 if( pNew->nLTerm>=pNew->nLSlot
156839 && whereLoopResize(db, pNew, pNew->nLTerm+1)
156840 ){
156841 break; /* OOM while trying to enlarge the pNew->aLTerm array */
156842 }
156843 pNew->aLTerm[pNew->nLTerm++] = pTerm;
156844 pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
156845
156846 assert( nInMul==0
156847 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
@@ -156892,42 +156930,43 @@
156930 }
156931 }
156932 if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
156933 }else if( eOp & WO_ISNULL ){
156934 pNew->wsFlags |= WHERE_COLUMN_NULL;
156935 }else{
156936 int nVecLen = whereRangeVectorLen(
156937 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156938 );
156939 if( eOp & (WO_GT|WO_GE) ){
156940 testcase( eOp & WO_GT );
156941 testcase( eOp & WO_GE );
156942 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
156943 pNew->u.btree.nBtm = nVecLen;
156944 pBtm = pTerm;
156945 pTop = 0;
156946 if( pTerm->wtFlags & TERM_LIKEOPT ){
156947 /* Range constraints that come from the LIKE optimization are
156948 ** always used in pairs. */
156949 pTop = &pTerm[1];
156950 assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
156951 assert( pTop->wtFlags & TERM_LIKEOPT );
156952 assert( pTop->eOperator==WO_LT );
156953 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156954 pNew->aLTerm[pNew->nLTerm++] = pTop;
156955 pNew->wsFlags |= WHERE_TOP_LIMIT;
156956 pNew->u.btree.nTop = 1;
156957 }
156958 }else{
156959 assert( eOp & (WO_LT|WO_LE) );
156960 testcase( eOp & WO_LT );
156961 testcase( eOp & WO_LE );
156962 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
156963 pNew->u.btree.nTop = nVecLen;
156964 pTop = pTerm;
156965 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
156966 pNew->aLTerm[pNew->nLTerm-2] : 0;
156967 }
156968 }
156969
156970 /* At this point pNew->nOut is set to the number of rows expected to
156971 ** be visited by the index scan before considering term pTerm, or the
156972 ** values of nIn and nInMul. In other words, assuming that all
@@ -158089,16 +158128,23 @@
158128 SrcItem *pItem;
158129 SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
158130 sqlite3 *db = pWInfo->pParse->db;
158131 int rc = SQLITE_OK;
158132 int bFirstPastRJ = 0;
158133 int hasRightJoin = 0;
158134 WhereLoop *pNew;
158135
158136
158137 /* Loop over the tables in the join, from left to right */
158138 pNew = pBuilder->pNew;
158139
158140 /* Verify that pNew has already been initialized */
158141 assert( pNew->nLTerm==0 );
158142 assert( pNew->wsFlags==0 );
158143 assert( pNew->nLSlot>=ArraySize(pNew->aLTermSpace) );
158144 assert( pNew->aLTerm!=0 );
158145
158146 pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
158147 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
158148 Bitmask mUnusable = 0;
158149 pNew->iTab = iTab;
158150 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
@@ -158109,19 +158155,20 @@
158155 /* Add prerequisites to prevent reordering of FROM clause terms
158156 ** across CROSS joins and outer joins. The bFirstPastRJ boolean
158157 ** prevents the right operand of a RIGHT JOIN from being swapped with
158158 ** other elements even further to the right.
158159 **
158160 ** The JT_LTORJ case and the hasRightJoin flag work together to
158161 ** prevent FROM-clause terms from moving from the right side of
158162 ** a LEFT JOIN over to the left side of that join if the LEFT JOIN
158163 ** is itself on the left side of a RIGHT JOIN.
 
 
158164 */
158165 if( pItem->fg.jointype & JT_LTORJ ) hasRightJoin = 1;
158166 mPrereq |= mPrior;
158167 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
158168 }else if( !hasRightJoin ){
158169 mPrereq = 0;
158170 }
158171 #ifndef SQLITE_OMIT_VIRTUALTABLE
158172 if( IsVirtual(pItem->pTab) ){
158173 SrcItem *p;
158174 for(p=&pItem[1]; p<pEnd; p++){
@@ -158690,13 +158737,13 @@
158737 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
158738 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
158739 LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
158740 LogEst rCost; /* Cost of path (pFrom+pWLoop) */
158741 LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
158742 i8 isOrdered; /* isOrdered for (pFrom+pWLoop) */
158743 Bitmask maskNew; /* Mask of src visited by (..) */
158744 Bitmask revMask; /* Mask of rev-order loops for (..) */
158745
158746 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
158747 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
158748 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
158749 /* Do not use an automatic index if the this loop is expected
@@ -158711,11 +158758,13 @@
158758 ** Compute its cost */
158759 rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
158760 rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
158761 nOut = pFrom->nRow + pWLoop->nOut;
158762 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
158763 isOrdered = pFrom->isOrdered;
158764 if( isOrdered<0 ){
158765 revMask = 0;
158766 isOrdered = wherePathSatisfiesOrderBy(pWInfo,
158767 pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
158768 iLoop, pWLoop, &revMask);
158769 }else{
158770 revMask = pFrom->revLoop;
@@ -169958,10 +170007,11 @@
170007 while( 1 ){
170008 n = sqlite3GetToken((u8*)zSql, &tokenType);
170009 mxSqlLen -= n;
170010 if( mxSqlLen<0 ){
170011 pParse->rc = SQLITE_TOOBIG;
170012 pParse->nErr++;
170013 break;
170014 }
170015 #ifndef SQLITE_OMIT_WINDOWFUNC
170016 if( tokenType>=TK_WINDOW ){
170017 assert( tokenType==TK_SPACE || tokenType==TK_OVER || tokenType==TK_FILTER
@@ -174698,12 +174748,15 @@
174748 sqlite3ShowUpsert(0);
174749 sqlite3ShowTriggerStep(0);
174750 sqlite3ShowTriggerStepList(0);
174751 sqlite3ShowTrigger(0);
174752 sqlite3ShowTriggerList(0);
174753 #ifndef SQLITE_OMIT_WINDOWFUNC
174754 sqlite3ShowWindow(0);
174755 sqlite3ShowWinFunc(0);
174756 #endif
174757 sqlite3ShowSelect(0);
174758 }
174759 #endif
174760 break;
174761 }
174762
@@ -181033,12 +181086,11 @@
181086 static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181087 int iToken; /* Used to iterate through phrase tokens */
181088 char *aPoslist = 0; /* Position list for deferred tokens */
181089 int nPoslist = 0; /* Number of bytes in aPoslist */
181090 int iPrev = -1; /* Token number of previous deferred token */
181091 char *aFree = (pPhrase->doclist.bFreeList ? pPhrase->doclist.pList : 0);
 
181092
181093 for(iToken=0; iToken<pPhrase->nToken; iToken++){
181094 Fts3PhraseToken *pToken = &pPhrase->aToken[iToken];
181095 Fts3DeferredToken *pDeferred = pToken->pDeferred;
181096
@@ -181048,10 +181100,11 @@
181100 int rc = sqlite3Fts3DeferredTokenList(pDeferred, &pList, &nList);
181101 if( rc!=SQLITE_OK ) return rc;
181102
181103 if( pList==0 ){
181104 sqlite3_free(aPoslist);
181105 sqlite3_free(aFree);
181106 pPhrase->doclist.pList = 0;
181107 pPhrase->doclist.nList = 0;
181108 return SQLITE_OK;
181109
181110 }else if( aPoslist==0 ){
@@ -181068,10 +181121,11 @@
181121 sqlite3_free(aPoslist);
181122 aPoslist = pList;
181123 nPoslist = (int)(aOut - aPoslist);
181124 if( nPoslist==0 ){
181125 sqlite3_free(aPoslist);
181126 sqlite3_free(aFree);
181127 pPhrase->doclist.pList = 0;
181128 pPhrase->doclist.nList = 0;
181129 return SQLITE_OK;
181130 }
181131 }
@@ -181107,10 +181161,11 @@
181161 sqlite3_free(aPoslist);
181162 return SQLITE_NOMEM;
181163 }
181164
181165 pPhrase->doclist.pList = aOut;
181166 assert( p1 && p2 );
181167 if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
181168 pPhrase->doclist.bFreeList = 1;
181169 pPhrase->doclist.nList = (int)(aOut - pPhrase->doclist.pList);
181170 }else{
181171 sqlite3_free(aOut);
@@ -181119,10 +181174,11 @@
181174 }
181175 sqlite3_free(aPoslist);
181176 }
181177 }
181178
181179 if( pPhrase->doclist.pList!=aFree ) sqlite3_free(aFree);
181180 return SQLITE_OK;
181181 }
181182 #endif /* SQLITE_DISABLE_FTS4_DEFERRED */
181183
181184 /*
@@ -182293,15 +182349,14 @@
182349 );
182350 break;
182351
182352 default: {
182353 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
182354 if( pCsr->pDeferred && (pExpr->bDeferred || (
182355 pExpr->iDocid==pCsr->iPrevId && pExpr->pPhrase->doclist.pList
182356 ))){
182357 Fts3Phrase *pPhrase = pExpr->pPhrase;
 
182358 if( pExpr->bDeferred ){
182359 fts3EvalInvalidatePoslist(pPhrase);
182360 }
182361 *pRc = fts3EvalDeferredPhrase(pCsr, pPhrase);
182362 bHit = (pPhrase->doclist.pList!=0);
@@ -212484,15 +212539,16 @@
212539 */
212540 static int dbpageBegin(sqlite3_vtab *pVtab){
212541 DbpageTable *pTab = (DbpageTable *)pVtab;
212542 sqlite3 *db = pTab->db;
212543 int i;
212544 int rc = SQLITE_OK;
212545 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
212546 Btree *pBt = db->aDb[i].pBt;
212547 if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
212548 }
212549 return rc;
212550 }
212551
212552
212553 /*
212554 ** Invoke this routine to register the "dbpage" virtual table module
@@ -236615,11 +236671,11 @@
236671 int nArg, /* Number of args */
236672 sqlite3_value **apUnused /* Function arguments */
236673 ){
236674 assert( nArg==0 );
236675 UNUSED_PARAM2(nArg, apUnused);
236676 sqlite3_result_text(pCtx, "fts5: 2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a", -1, SQLITE_TRANSIENT);
236677 }
236678
236679 /*
236680 ** Return true if zName is the extension on one of the shadow tables used
236681 ** by this module.
@@ -241286,10 +241342,20 @@
241342 /* #include <assert.h> */
241343 /* #include <string.h> */
241344
241345 #ifndef SQLITE_OMIT_VIRTUALTABLE
241346
241347
241348 #define STMT_NUM_INTEGER_COLUMN 10
241349 typedef struct StmtRow StmtRow;
241350 struct StmtRow {
241351 sqlite3_int64 iRowid; /* Rowid value */
241352 char *zSql; /* column "sql" */
241353 int aCol[STMT_NUM_INTEGER_COLUMN+1]; /* all other column values */
241354 StmtRow *pNext; /* Next row to return */
241355 };
241356
241357 /* stmt_vtab is a subclass of sqlite3_vtab which will
241358 ** serve as the underlying representation of a stmt virtual table
241359 */
241360 typedef struct stmt_vtab stmt_vtab;
241361 struct stmt_vtab {
@@ -241303,12 +241369,11 @@
241369 */
241370 typedef struct stmt_cursor stmt_cursor;
241371 struct stmt_cursor {
241372 sqlite3_vtab_cursor base; /* Base class - must be first */
241373 sqlite3 *db; /* Database connection for this cursor */
241374 StmtRow *pRow; /* Current row */
 
241375 };
241376
241377 /*
241378 ** The stmtConnect() method is invoked to create a new
241379 ** stmt_vtab that describes the stmt virtual table.
@@ -241348,11 +241413,11 @@
241413
241414 rc = sqlite3_declare_vtab(db,
241415 "CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,"
241416 "reprep,run,mem)");
241417 if( rc==SQLITE_OK ){
241418 pNew = sqlite3_malloc64( sizeof(*pNew) );
241419 *ppVtab = (sqlite3_vtab*)pNew;
241420 if( pNew==0 ) return SQLITE_NOMEM;
241421 memset(pNew, 0, sizeof(*pNew));
241422 pNew->db = db;
241423 }
@@ -241370,22 +241435,33 @@
241435 /*
241436 ** Constructor for a new stmt_cursor object.
241437 */
241438 static int stmtOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
241439 stmt_cursor *pCur;
241440 pCur = sqlite3_malloc64( sizeof(*pCur) );
241441 if( pCur==0 ) return SQLITE_NOMEM;
241442 memset(pCur, 0, sizeof(*pCur));
241443 pCur->db = ((stmt_vtab*)p)->db;
241444 *ppCursor = &pCur->base;
241445 return SQLITE_OK;
241446 }
241447
241448 static void stmtCsrReset(stmt_cursor *pCur){
241449 StmtRow *pRow = 0;
241450 StmtRow *pNext = 0;
241451 for(pRow=pCur->pRow; pRow; pRow=pNext){
241452 pNext = pRow->pNext;
241453 sqlite3_free(pRow);
241454 }
241455 pCur->pRow = 0;
241456 }
241457
241458 /*
241459 ** Destructor for a stmt_cursor.
241460 */
241461 static int stmtClose(sqlite3_vtab_cursor *cur){
241462 stmtCsrReset((stmt_cursor*)cur);
241463 sqlite3_free(cur);
241464 return SQLITE_OK;
241465 }
241466
241467
@@ -241392,12 +241468,13 @@
241468 /*
241469 ** Advance a stmt_cursor to its next row of output.
241470 */
241471 static int stmtNext(sqlite3_vtab_cursor *cur){
241472 stmt_cursor *pCur = (stmt_cursor*)cur;
241473 StmtRow *pNext = pCur->pRow->pNext;
241474 sqlite3_free(pCur->pRow);
241475 pCur->pRow = pNext;
241476 return SQLITE_OK;
241477 }
241478
241479 /*
241480 ** Return values of columns for the row at which the stmt_cursor
@@ -241407,43 +241484,15 @@
241484 sqlite3_vtab_cursor *cur, /* The cursor */
241485 sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
241486 int i /* Which column to return */
241487 ){
241488 stmt_cursor *pCur = (stmt_cursor*)cur;
241489 StmtRow *pRow = pCur->pRow;
241490 if( i==STMT_COLUMN_SQL ){
241491 sqlite3_result_text(ctx, pRow->zSql, -1, SQLITE_TRANSIENT);
241492 }else{
241493 sqlite3_result_int(ctx, pRow->aCol[i]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241494 }
241495 return SQLITE_OK;
241496 }
241497
241498 /*
@@ -241450,21 +241499,21 @@
241499 ** Return the rowid for the current row. In this implementation, the
241500 ** rowid is the same as the output value.
241501 */
241502 static int stmtRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
241503 stmt_cursor *pCur = (stmt_cursor*)cur;
241504 *pRowid = pCur->pRow->iRowid;
241505 return SQLITE_OK;
241506 }
241507
241508 /*
241509 ** Return TRUE if the cursor has been moved off of the last
241510 ** row of output.
241511 */
241512 static int stmtEof(sqlite3_vtab_cursor *cur){
241513 stmt_cursor *pCur = (stmt_cursor*)cur;
241514 return pCur->pRow==0;
241515 }
241516
241517 /*
241518 ** This method is called to "rewind" the stmt_cursor object back
241519 ** to the first row of output. This method is always called at least
@@ -241475,13 +241524,57 @@
241524 sqlite3_vtab_cursor *pVtabCursor,
241525 int idxNum, const char *idxStr,
241526 int argc, sqlite3_value **argv
241527 ){
241528 stmt_cursor *pCur = (stmt_cursor *)pVtabCursor;
241529 sqlite3_stmt *p = 0;
241530 sqlite3_int64 iRowid = 1;
241531 StmtRow **ppRow = 0;
241532
241533 stmtCsrReset(pCur);
241534 ppRow = &pCur->pRow;
241535 for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
241536 const char *zSql = sqlite3_sql(p);
241537 sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
241538 StmtRow *pNew = (StmtRow*)sqlite3_malloc64(sizeof(StmtRow) + nSql);
241539
241540 if( pNew==0 ) return SQLITE_NOMEM;
241541 memset(pNew, 0, sizeof(StmtRow));
241542 if( zSql ){
241543 pNew->zSql = (char*)&pNew[1];
241544 memcpy(pNew->zSql, zSql, nSql);
241545 }
241546 pNew->aCol[STMT_COLUMN_NCOL] = sqlite3_column_count(p);
241547 pNew->aCol[STMT_COLUMN_RO] = sqlite3_stmt_readonly(p);
241548 pNew->aCol[STMT_COLUMN_BUSY] = sqlite3_stmt_busy(p);
241549 pNew->aCol[STMT_COLUMN_NSCAN] = sqlite3_stmt_status(
241550 p, SQLITE_STMTSTATUS_FULLSCAN_STEP, 0
241551 );
241552 pNew->aCol[STMT_COLUMN_NSORT] = sqlite3_stmt_status(
241553 p, SQLITE_STMTSTATUS_SORT, 0
241554 );
241555 pNew->aCol[STMT_COLUMN_NAIDX] = sqlite3_stmt_status(
241556 p, SQLITE_STMTSTATUS_AUTOINDEX, 0
241557 );
241558 pNew->aCol[STMT_COLUMN_NSTEP] = sqlite3_stmt_status(
241559 p, SQLITE_STMTSTATUS_VM_STEP, 0
241560 );
241561 pNew->aCol[STMT_COLUMN_REPREP] = sqlite3_stmt_status(
241562 p, SQLITE_STMTSTATUS_REPREPARE, 0
241563 );
241564 pNew->aCol[STMT_COLUMN_RUN] = sqlite3_stmt_status(
241565 p, SQLITE_STMTSTATUS_RUN, 0
241566 );
241567 pNew->aCol[STMT_COLUMN_MEM] = sqlite3_stmt_status(
241568 p, SQLITE_STMTSTATUS_MEMUSED, 0
241569 );
241570 pNew->iRowid = iRowid++;
241571 *ppRow = pNew;
241572 ppRow = &pNew->pNext;
241573 }
241574
241575 return SQLITE_OK;
241576 }
241577
241578 /*
241579 ** SQLite will invoke this method one or more times while planning a query
241580 ** that uses the stmt virtual table. This routine needs to create
241581
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.39.0"
150
-#define SQLITE_VERSION_NUMBER 3039000
151
-#define SQLITE_SOURCE_ID "2022-06-25 14:57:57 14e166f40dbfa6e055543f8301525f2ca2e96a02a57269818b9e69e162e98918"
149
+#define SQLITE_VERSION "3.40.0"
150
+#define SQLITE_VERSION_NUMBER 3040000
151
+#define SQLITE_SOURCE_ID "2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -6280,11 +6280,11 @@
62806280
** CAPI3REF: Return The Schema Name For A Database Connection
62816281
** METHOD: sqlite3
62826282
**
62836283
** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
62846284
** for the N-th database on database connection D, or a NULL pointer of N is
6285
-** out of range. An N alue of 0 means the main database file. An N of 1 is
6285
+** out of range. An N value of 0 means the main database file. An N of 1 is
62866286
** the "temp" schema. Larger values of N correspond to various ATTACH-ed
62876287
** databases.
62886288
**
62896289
** Space to hold the string that is returned by sqlite3_db_name() is managed
62906290
** by SQLite itself. The string might be deallocated by any operation that
62916291
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-06-25 14:57:57 14e166f40dbfa6e055543f8301525f2ca2e96a02a57269818b9e69e162e98918"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -6280,11 +6280,11 @@
6280 ** CAPI3REF: Return The Schema Name For A Database Connection
6281 ** METHOD: sqlite3
6282 **
6283 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6284 ** for the N-th database on database connection D, or a NULL pointer of N is
6285 ** out of range. An N alue of 0 means the main database file. An N of 1 is
6286 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6287 ** databases.
6288 **
6289 ** Space to hold the string that is returned by sqlite3_db_name() is managed
6290 ** by SQLite itself. The string might be deallocated by any operation that
6291
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.40.0"
150 #define SQLITE_VERSION_NUMBER 3040000
151 #define SQLITE_SOURCE_ID "2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -6280,11 +6280,11 @@
6280 ** CAPI3REF: Return The Schema Name For A Database Connection
6281 ** METHOD: sqlite3
6282 **
6283 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6284 ** for the N-th database on database connection D, or a NULL pointer of N is
6285 ** out of range. An N value of 0 means the main database file. An N of 1 is
6286 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6287 ** databases.
6288 **
6289 ** Space to hold the string that is returned by sqlite3_db_name() is managed
6290 ** by SQLite itself. The string might be deallocated by any operation that
6291

Keyboard Shortcuts

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