Fossil SCM

Update the built-in SQLite to version 3.39.2 RC 1.

drh 2022-07-21 14:48 trunk
Commit 8c36dad3ba1110546daf56dfd6ec505d7c0600a35b9d252406af5a06b7423dcc
3 files changed +84 -189 +212 -249 +3 -3
+84 -189
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,19 +53,10 @@
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
-
6758
/*
6859
** Warning pragmas copied from msvc.h in the core.
6960
*/
7061
#if defined(_MSC_VER)
7162
#pragma warning(disable : 4054)
@@ -254,10 +245,21 @@
254245
#else
255246
# define setBinaryMode(X,Y)
256247
# define setTextMode(X,Y)
257248
#endif
258249
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
+
259261
/* True if the timer is enabled */
260262
static int enableTimer = 0;
261263
262264
/* Return the current wall-clock time */
263265
static sqlite3_int64 timeOfDay(void){
@@ -715,11 +717,11 @@
715717
**
716718
** The result is stored in space obtained from malloc() and must either
717719
** be freed by the caller or else passed back into this routine via the
718720
** zPrior argument for reuse.
719721
*/
720
-#ifndef SQLITE_SHELL_FIDDLE
722
+#ifndef SQLITE_SHELL_WASM_MODE
721723
static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
722724
char *zPrompt;
723725
char *zResult;
724726
if( in!=0 ){
725727
zResult = local_getline(zPrior, in);
@@ -735,11 +737,11 @@
735737
if( zResult && *zResult ) shell_add_history(zResult);
736738
#endif
737739
}
738740
return zResult;
739741
}
740
-#endif /* !SQLITE_SHELL_FIDDLE */
742
+#endif /* !SQLITE_SHELL_WASM_MODE */
741743
742744
/*
743745
** Return the value of a hexadecimal digit. Return -1 if the input
744746
** is not a hex digit.
745747
*/
@@ -3792,11 +3794,10 @@
37923794
#define re_compile sqlite3re_compile
37933795
#define re_free sqlite3re_free
37943796
37953797
/* The end-of-input character */
37963798
#define RE_EOF 0 /* End of input */
3797
-#define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */
37983799
37993800
/* The NFA is implemented as sequence of opcodes taken from the following
38003801
** set. Each opcode has a single integer argument.
38013802
*/
38023803
#define RE_OP_MATCH 1 /* Match the one character in the argument */
@@ -3814,37 +3815,10 @@
38143815
#define RE_OP_DIGIT 13 /* digit: [0-9] */
38153816
#define RE_OP_NOTDIGIT 14 /* Not a digit */
38163817
#define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
38173818
#define RE_OP_NOTSPACE 16 /* Not a digit */
38183819
#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
-
38463820
38473821
/* Each opcode is a "state" in the NFA */
38483822
typedef unsigned short ReStateNumber;
38493823
38503824
/* Because this is an NFA and not a DFA, multiple states can be active at
@@ -3875,11 +3849,11 @@
38753849
const char *zErr; /* Error message to return */
38763850
char *aOp; /* Operators for the virtual machine */
38773851
int *aArg; /* Arguments to each operator */
38783852
unsigned (*xNextChar)(ReInput*); /* Next character function */
38793853
unsigned char zInit[12]; /* Initial text to match */
3880
- int nInit; /* Number of bytes in zInit */
3854
+ int nInit; /* Number of characters in zInit */
38813855
unsigned nState; /* Number of entries in aOp[] and aArg[] */
38823856
unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
38833857
};
38843858
38853859
/* Add a state to the given state set if it is not already there */
@@ -3948,11 +3922,11 @@
39483922
ReStateSet aStateSet[2], *pThis, *pNext;
39493923
ReStateNumber aSpace[100];
39503924
ReStateNumber *pToFree;
39513925
unsigned int i = 0;
39523926
unsigned int iSwap = 0;
3953
- int c = RE_START;
3927
+ int c = RE_EOF+1;
39543928
int cPrev = 0;
39553929
int rc = 0;
39563930
ReInput in;
39573931
39583932
in.z = zIn;
@@ -3967,11 +3941,10 @@
39673941
strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
39683942
){
39693943
in.i++;
39703944
}
39713945
if( in.i+pRe->nInit>in.mx ) return 0;
3972
- c = RE_START-1;
39733946
}
39743947
39753948
if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
39763949
pToFree = 0;
39773950
aStateSet[0].aState = aSpace;
@@ -3996,14 +3969,10 @@
39963969
switch( pRe->aOp[x] ){
39973970
case RE_OP_MATCH: {
39983971
if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
39993972
break;
40003973
}
4001
- case RE_OP_ATSTART: {
4002
- if( cPrev==RE_START ) re_add_state(pThis, x+1);
4003
- break;
4004
- }
40053974
case RE_OP_ANY: {
40063975
if( c!=0 ) re_add_state(pNext, x+1);
40073976
break;
40083977
}
40093978
case RE_OP_WORD: {
@@ -4081,13 +4050,11 @@
40814050
}
40824051
}
40834052
}
40844053
}
40854054
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; }
4055
+ if( pRe->aOp[pNext->aState[i]]==RE_OP_ACCEPT ){ rc = 1; break; }
40894056
}
40904057
re_match_end:
40914058
sqlite3_free(pToFree);
40924059
return rc;
40934060
}
@@ -4238,10 +4205,11 @@
42384205
const char *zErr;
42394206
while( (c = p->xNextChar(&p->sIn))!=0 ){
42404207
iStart = p->nState;
42414208
switch( c ){
42424209
case '|':
4210
+ case '$':
42434211
case ')': {
42444212
p->sIn.i--;
42454213
return 0;
42464214
}
42474215
case '(': {
@@ -4274,18 +4242,10 @@
42744242
case '?': {
42754243
if( iPrev<0 ) return "'?' without operand";
42764244
re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
42774245
break;
42784246
}
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
- }
42874247
case '{': {
42884248
int m = 0, n = 0;
42894249
int sz, j;
42904250
if( iPrev<0 ) return "'{m,n}' without operand";
42914251
while( (c=rePeek(p))>='0' && c<='9' ){ m = m*10 + c - '0'; p->sIn.i++; }
@@ -4300,11 +4260,10 @@
43004260
p->sIn.i++;
43014261
sz = p->nState - iPrev;
43024262
if( m==0 ){
43034263
if( n==0 ) return "both m and n are zero in '{m,n}'";
43044264
re_insert(p, iPrev, RE_OP_FORK, sz+1);
4305
- iPrev++;
43064265
n--;
43074266
}else{
43084267
for(j=1; j<m; j++) re_copy(p, iPrev, sz);
43094268
}
43104269
for(j=m; j<n; j++){
@@ -4419,11 +4378,15 @@
44194378
zErr = re_subcompile_re(pRe);
44204379
if( zErr ){
44214380
re_free(pRe);
44224381
return zErr;
44234382
}
4424
- if( pRe->sIn.i>=pRe->sIn.mx ){
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 ){
44254388
re_append(pRe, RE_OP_ACCEPT, 0);
44264389
*ppRe = pRe;
44274390
}else{
44284391
re_free(pRe);
44294392
return "unrecognized character";
@@ -4502,71 +4465,10 @@
45024465
}
45034466
if( setAux ){
45044467
sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
45054468
}
45064469
}
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
-
45684470
45694471
/*
45704472
** Invoke this routine to register the regexp() function with the
45714473
** SQLite database connection.
45724474
*/
@@ -4588,23 +4490,16 @@
45884490
/* The regexpi(PATTERN,STRING) function is a case-insensitive version
45894491
** of regexp(PATTERN,STRING). */
45904492
rc = sqlite3_create_function(db, "regexpi", 2,
45914493
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
45924494
(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 */
46004495
}
46014496
return rc;
46024497
}
46034498
46044499
/************************* End ../ext/misc/regexp.c ********************/
4605
-#ifndef SQLITE_SHELL_FIDDLE
4500
+#ifndef SQLITE_SHELL_WASM_MODE
46064501
/************************* Begin ../ext/misc/fileio.c ******************/
46074502
/*
46084503
** 2014-06-13
46094504
**
46104505
** The author disclaims copyright to this source code. In place of
@@ -12353,19 +12248,19 @@
1235312248
int nIndent; /* Size of array aiIndent[] */
1235412249
int iIndent; /* Index of current op in aiIndent[] */
1235512250
char *zNonce; /* Nonce for temporary safe-mode excapes */
1235612251
EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
1235712252
ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12358
-#ifdef SQLITE_SHELL_FIDDLE
12253
+#ifdef SQLITE_SHELL_WASM_MODE
1235912254
struct {
1236012255
const char * zInput; /* Input string from wasm/JS proxy */
1236112256
const char * zPos; /* Cursor pos into zInput */
1236212257
} wasm;
1236312258
#endif
1236412259
};
1236512260
12366
-#ifdef SQLITE_SHELL_FIDDLE
12261
+#ifdef SQLITE_SHELL_WASM_MODE
1236712262
static ShellState shellState;
1236812263
#endif
1236912264
1237012265
1237112266
/* Allowed values for ShellState.autoEQP
@@ -13029,11 +12924,11 @@
1302912924
UNUSED_PARAMETER(zA2);
1303012925
UNUSED_PARAMETER(zA3);
1303112926
UNUSED_PARAMETER(zA4);
1303212927
switch( op ){
1303312928
case SQLITE_ATTACH: {
13034
-#ifndef SQLITE_SHELL_FIDDLE
12929
+#ifndef SQLITE_SHELL_WASM_MODE
1303512930
/* In WASM builds the filesystem is a virtual sandbox, so
1303612931
** there's no harm in using ATTACH. */
1303712932
failIfSafeMode(p, "cannot run ATTACH in safe mode");
1303812933
#endif
1303912934
break;
@@ -15443,11 +15338,11 @@
1544315338
** There must be two or more spaces between the end of the command and the
1544415339
** start of the description of what that command does.
1544515340
*/
1544615341
static const char *(azHelp[]) = {
1544715342
#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15448
- && !defined(SQLITE_SHELL_FIDDLE)
15343
+ && !defined(SQLITE_SHELL_WASM_MODE)
1544915344
".archive ... Manage SQL archives",
1545015345
" Each command must have exactly one of the following options:",
1545115346
" -c, --create Create a new archive",
1545215347
" -u, --update Add or update files with changed mtime",
1545315348
" -i, --insert Like -u but always add even if unchanged",
@@ -15469,23 +15364,23 @@
1546915364
" http://sqlite.org/cli.html#sqlite_archive_support",
1547015365
#endif
1547115366
#ifndef SQLITE_OMIT_AUTHORIZATION
1547215367
".auth ON|OFF Show authorizer callbacks",
1547315368
#endif
15474
-#ifndef SQLITE_SHELL_FIDDLE
15369
+#ifndef SQLITE_SHELL_WASM_MODE
1547515370
".backup ?DB? FILE Backup DB (default \"main\") to FILE",
1547615371
" Options:",
1547715372
" --append Use the appendvfs",
1547815373
" --async Write to FILE without journal and fsync()",
1547915374
#endif
1548015375
".bail on|off Stop after hitting an error. Default OFF",
1548115376
".binary on|off Turn binary output on or off. Default OFF",
15482
-#ifndef SQLITE_SHELL_FIDDLE
15377
+#ifndef SQLITE_SHELL_WASM_MODE
1548315378
".cd DIRECTORY Change the working directory to DIRECTORY",
1548415379
#endif
1548515380
".changes on|off Show number of rows changed by SQL",
15486
-#ifndef SQLITE_SHELL_FIDDLE
15381
+#ifndef SQLITE_SHELL_WASM_MODE
1548715382
".check GLOB Fail if output since .testcase does not match",
1548815383
".clone NEWDB Clone data into NEWDB from the existing database",
1548915384
#endif
1549015385
".connection [close] [#] Open or close an auxiliary database connection",
1549115386
".databases List names and files of attached databases",
@@ -15507,15 +15402,15 @@
1550715402
#ifdef SQLITE_DEBUG
1550815403
" test Show raw EXPLAIN QUERY PLAN output",
1550915404
" trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
1551015405
#endif
1551115406
" trigger Like \"full\" but also show trigger bytecode",
15512
-#ifndef SQLITE_SHELL_FIDDLE
15407
+#ifndef SQLITE_SHELL_WASM_MODE
1551315408
".excel Display the output of next command in spreadsheet",
1551415409
" --bom Put a UTF8 byte-order mark on intermediate file",
1551515410
#endif
15516
-#ifndef SQLITE_SHELL_FIDDLE
15411
+#ifndef SQLITE_SHELL_WASM_MODE
1551715412
".exit ?CODE? Exit this program with return-code CODE",
1551815413
#endif
1551915414
".expert EXPERIMENTAL. Suggest indexes for queries",
1552015415
".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
1552115416
".filectrl CMD ... Run various sqlite3_file_control() operations",
@@ -15522,11 +15417,11 @@
1552215417
" --schema SCHEMA Use SCHEMA instead of \"main\"",
1552315418
" --help Show CMD details",
1552415419
".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
1552515420
".headers on|off Turn display of headers on or off",
1552615421
".help ?-all? ?PATTERN? Show help text for PATTERN",
15527
-#ifndef SQLITE_SHELL_FIDDLE
15422
+#ifndef SQLITE_SHELL_WASM_MODE
1552815423
".import FILE TABLE Import data from FILE into TABLE",
1552915424
" Options:",
1553015425
" --ascii Use \\037 and \\036 as column and row separators",
1553115426
" --csv Use , and \\n as column and row separators",
1553215427
" --skip N Skip the first N rows of input",
@@ -15551,14 +15446,14 @@
1555115446
#endif
1555215447
".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
1555315448
".lint OPTIONS Report potential schema issues.",
1555415449
" Options:",
1555515450
" fkey-indexes Find missing foreign key indexes",
15556
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
15451
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
1555715452
".load FILE ?ENTRY? Load an extension library",
1555815453
#endif
15559
-#ifndef SQLITE_SHELL_FIDDLE
15454
+#ifndef SQLITE_SHELL_WASM_MODE
1556015455
".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
1556115456
#endif
1556215457
".mode MODE ?OPTIONS? Set output mode",
1556315458
" MODE is one of:",
1556415459
" ascii Columns/rows delimited by 0x1F and 0x1E",
@@ -15581,15 +15476,15 @@
1558115476
" --wordwrap B Wrap or not at word boundaries per B (on/off)",
1558215477
" --ww Shorthand for \"--wordwrap 1\"",
1558315478
" --quote Quote output text as SQL literals",
1558415479
" --noquote Do not quote output text",
1558515480
" TABLE The name of SQL table used for \"insert\" mode",
15586
-#ifndef SQLITE_SHELL_FIDDLE
15481
+#ifndef SQLITE_SHELL_WASM_MODE
1558715482
".nonce STRING Suspend safe mode for one command if nonce matches",
1558815483
#endif
1558915484
".nullvalue STRING Use STRING in place of NULL values",
15590
-#ifndef SQLITE_SHELL_FIDDLE
15485
+#ifndef SQLITE_SHELL_WASM_MODE
1559115486
".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
1559215487
" If FILE begins with '|' then open as a pipe",
1559315488
" --bom Put a UTF8 byte-order mark at the beginning",
1559415489
" -e Send output to the system text editor",
1559515490
" -x Send output as CSV to a spreadsheet (same as \".excel\")",
@@ -15607,11 +15502,11 @@
1560715502
#endif
1560815503
" --new Initialize FILE to an empty database",
1560915504
" --nofollow Do not follow symbolic links",
1561015505
" --readonly Open FILE readonly",
1561115506
" --zip FILE is a ZIP archive",
15612
-#ifndef SQLITE_SHELL_FIDDLE
15507
+#ifndef SQLITE_SHELL_WASM_MODE
1561315508
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1561415509
" If FILE begins with '|' then open it as a pipe.",
1561515510
" Options:",
1561615511
" --bom Prefix output with a UTF8 byte-order mark",
1561715512
" -e Send output to the system text editor",
@@ -15631,11 +15526,11 @@
1563115526
" --once Do no more than one progress interrupt",
1563215527
" --quiet|-q No output except at interrupts",
1563315528
" --reset Reset the count for each input and interrupt",
1563415529
#endif
1563515530
".prompt MAIN CONTINUE Replace the standard prompts",
15636
-#ifndef SQLITE_SHELL_FIDDLE
15531
+#ifndef SQLITE_SHELL_WASM_MODE
1563715532
".quit Exit this program",
1563815533
".read FILE Read input from FILE or command output",
1563915534
" If FILE begins with \"|\", it is a command that generates the input.",
1564015535
#endif
1564115536
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
@@ -15644,11 +15539,11 @@
1564415539
" --recovery-db NAME Store recovery metadata in database file NAME",
1564515540
" --lost-and-found TABLE Alternative name for the lost-and-found table",
1564615541
" --no-rowids Do not attempt to recover rowid values",
1564715542
" that are not also INTEGER PRIMARY KEYs",
1564815543
#endif
15649
-#ifndef SQLITE_SHELL_FIDDLE
15544
+#ifndef SQLITE_SHELL_WASM_MODE
1565015545
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
1565115546
".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
1565215547
#endif
1565315548
".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
1565415549
".schema ?PATTERN? Show the CREATE statements matching PATTERN",
@@ -15681,24 +15576,24 @@
1568115576
" --sha3-224 Use the sha3-224 algorithm",
1568215577
" --sha3-256 Use the sha3-256 algorithm (default)",
1568315578
" --sha3-384 Use the sha3-384 algorithm",
1568415579
" --sha3-512 Use the sha3-512 algorithm",
1568515580
" Any other argument is a LIKE pattern for tables to hash",
15686
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
15581
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
1568715582
".shell CMD ARGS... Run CMD ARGS... in a system shell",
1568815583
#endif
1568915584
".show Show the current values for various settings",
1569015585
".stats ?ARG? Show stats or turn stats on or off",
1569115586
" off Turn off automatic stat display",
1569215587
" on Turn on automatic stat display",
1569315588
" stmt Show statement stats",
1569415589
" vmstep Show the virtual machine step count only",
15695
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
15590
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
1569615591
".system CMD ARGS... Run CMD ARGS... in a system shell",
1569715592
#endif
1569815593
".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15699
-#ifndef SQLITE_SHELL_FIDDLE
15594
+#ifndef SQLITE_SHELL_WASM_MODE
1570015595
".testcase NAME Begin redirecting output to 'testcase-out.txt'",
1570115596
#endif
1570215597
".testctrl CMD ... Run various sqlite3_test_control() operations",
1570315598
" Run \".testctrl\" with no arguments for details",
1570415599
".timeout MS Try opening locked tables for MS milliseconds",
@@ -16247,11 +16142,11 @@
1624716142
sqlite3_uint_init(p->db, 0, 0);
1624816143
sqlite3_decimal_init(p->db, 0, 0);
1624916144
sqlite3_regexp_init(p->db, 0, 0);
1625016145
sqlite3_ieee_init(p->db, 0, 0);
1625116146
sqlite3_series_init(p->db, 0, 0);
16252
-#ifndef SQLITE_SHELL_FIDDLE
16147
+#ifndef SQLITE_SHELL_WASM_MODE
1625316148
sqlite3_fileio_init(p->db, 0, 0);
1625416149
sqlite3_completion_init(p->db, 0, 0);
1625516150
#endif
1625616151
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1625716152
sqlite3_dbdata_init(p->db, 0, 0);
@@ -19377,19 +19272,19 @@
1937719272
}
1937819273
}else
1937919274
#endif
1938019275
1938119276
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19382
- && !defined(SQLITE_SHELL_FIDDLE)
19277
+ && !defined(SQLITE_SHELL_WASM_MODE)
1938319278
if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
1938419279
open_db(p, 0);
1938519280
failIfSafeMode(p, "cannot run .archive in safe mode");
1938619281
rc = arDotCommand(p, 0, azArg, nArg);
1938719282
}else
1938819283
#endif
1938919284
19390
-#ifndef SQLITE_SHELL_FIDDLE
19285
+#ifndef SQLITE_SHELL_WASM_MODE
1939119286
if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
1939219287
|| (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
1939319288
){
1939419289
const char *zDestFile = 0;
1939519290
const char *zDb = 0;
@@ -19454,11 +19349,11 @@
1945419349
utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
1945519350
rc = 1;
1945619351
}
1945719352
close_db(pDest);
1945819353
}else
19459
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
19354
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
1946019355
1946119356
if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
1946219357
if( nArg==2 ){
1946319358
bail_on_error = booleanValue(azArg[1]);
1946419359
}else{
@@ -19485,11 +19380,11 @@
1948519380
*/
1948619381
if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
1948719382
test_breakpoint();
1948819383
}else
1948919384
19490
-#ifndef SQLITE_SHELL_FIDDLE
19385
+#ifndef SQLITE_SHELL_WASM_MODE
1949119386
if( c=='c' && strcmp(azArg[0],"cd")==0 ){
1949219387
failIfSafeMode(p, "cannot run .cd in safe mode");
1949319388
if( nArg==2 ){
1949419389
#if defined(_WIN32) || defined(WIN32)
1949519390
wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19505,11 +19400,11 @@
1950519400
}else{
1950619401
raw_printf(stderr, "Usage: .cd DIRECTORY\n");
1950719402
rc = 1;
1950819403
}
1950919404
}else
19510
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
19405
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
1951119406
1951219407
if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
1951319408
if( nArg==2 ){
1951419409
setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
1951519410
}else{
@@ -19516,11 +19411,11 @@
1951619411
raw_printf(stderr, "Usage: .changes on|off\n");
1951719412
rc = 1;
1951819413
}
1951919414
}else
1952019415
19521
-#ifndef SQLITE_SHELL_FIDDLE
19416
+#ifndef SQLITE_SHELL_WASM_MODE
1952219417
/* Cancel output redirection, if it is currently set (by .testcase)
1952319418
** Then read the content of the testcase-out.txt file and compare against
1952419419
** azArg[1]. If there are differences, report an error and exit.
1952519420
*/
1952619421
if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19541,23 +19436,23 @@
1954119436
utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
1954219437
p->nCheck++;
1954319438
}
1954419439
sqlite3_free(zRes);
1954519440
}else
19546
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
19441
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
1954719442
19548
-#ifndef SQLITE_SHELL_FIDDLE
19443
+#ifndef SQLITE_SHELL_WASM_MODE
1954919444
if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
1955019445
failIfSafeMode(p, "cannot run .clone in safe mode");
1955119446
if( nArg==2 ){
1955219447
tryToClone(p, azArg[1]);
1955319448
}else{
1955419449
raw_printf(stderr, "Usage: .clone FILENAME\n");
1955519450
rc = 1;
1955619451
}
1955719452
}else
19558
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
19453
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
1955919454
1956019455
if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
1956119456
if( nArg==1 ){
1956219457
/* List available connections */
1956319458
int i;
@@ -19842,11 +19737,11 @@
1984219737
raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
1984319738
rc = 1;
1984419739
}
1984519740
}else
1984619741
19847
-#ifndef SQLITE_SHELL_FIDDLE
19742
+#ifndef SQLITE_SHELL_WASM_MODE
1984819743
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
1984919744
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
1985019745
rc = 2;
1985119746
}else
1985219747
#endif
@@ -20102,11 +19997,11 @@
2010219997
}else{
2010319998
showHelp(p->out, 0);
2010419999
}
2010520000
}else
2010620001
20107
-#ifndef SQLITE_SHELL_FIDDLE
20002
+#ifndef SQLITE_SHELL_WASM_MODE
2010820003
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
2010920004
char *zTable = 0; /* Insert data into this table */
2011020005
char *zSchema = 0; /* within this schema (may default to "main") */
2011120006
char *zFile = 0; /* Name of file to extra content from */
2011220007
sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -20393,11 +20288,11 @@
2039320288
utf8_printf(p->out,
2039420289
"Added %d rows with %d errors using %d lines of input\n",
2039520290
sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
2039620291
}
2039720292
}else
20398
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
20293
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2039920294
2040020295
#ifndef SQLITE_UNTESTABLE
2040120296
if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
2040220297
char *zSql;
2040320298
char *zCollist = 0;
@@ -20583,11 +20478,11 @@
2058320478
if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
2058420479
open_db(p, 0);
2058520480
lintDotCommand(p, azArg, nArg);
2058620481
}else
2058720482
20588
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
20483
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
2058920484
if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
2059020485
const char *zFile, *zProc;
2059120486
char *zErrMsg = 0;
2059220487
failIfSafeMode(p, "cannot run .load in safe mode");
2059320488
if( nArg<2 ){
@@ -20605,11 +20500,11 @@
2060520500
rc = 1;
2060620501
}
2060720502
}else
2060820503
#endif
2060920504
20610
-#ifndef SQLITE_SHELL_FIDDLE
20505
+#ifndef SQLITE_SHELL_WASM_MODE
2061120506
if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
2061220507
failIfSafeMode(p, "cannot run .log in safe mode");
2061320508
if( nArg!=2 ){
2061420509
raw_printf(stderr, "Usage: .log FILENAME\n");
2061520510
rc = 1;
@@ -20742,11 +20637,11 @@
2074220637
rc = 1;
2074320638
}
2074420639
p->cMode = p->mode;
2074520640
}else
2074620641
20747
-#ifndef SQLITE_SHELL_FIDDLE
20642
+#ifndef SQLITE_SHELL_WASM_MODE
2074820643
if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
2074920644
if( nArg!=2 ){
2075020645
raw_printf(stderr, "Usage: .nonce NONCE\n");
2075120646
rc = 1;
2075220647
}else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20757,11 +20652,11 @@
2075720652
p->bSafeMode = 0;
2075820653
return 0; /* Return immediately to bypass the safe mode reset
2075920654
** at the end of this procedure */
2076020655
}
2076120656
}else
20762
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
20657
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2076320658
2076420659
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
2076520660
if( nArg==2 ){
2076620661
sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
2076720662
"%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20779,11 +20674,11 @@
2077920674
int openMode = SHELL_OPEN_UNSPEC;
2078020675
2078120676
/* Check for command-line arguments */
2078220677
for(iName=1; iName<nArg; iName++){
2078320678
const char *z = azArg[iName];
20784
-#ifndef SQLITE_SHELL_FIDDLE
20679
+#ifndef SQLITE_SHELL_WASM_MODE
2078520680
if( optionMatch(z,"new") ){
2078620681
newFlag = 1;
2078720682
#ifdef SQLITE_HAVE_ZLIB
2078820683
}else if( optionMatch(z, "zip") ){
2078920684
openMode = SHELL_OPEN_ZIPFILE;
@@ -20801,11 +20696,11 @@
2080120696
openMode = SHELL_OPEN_HEXDB;
2080220697
}else if( optionMatch(z, "maxsize") && iName+1<nArg ){
2080320698
p->szMax = integerValue(azArg[++iName]);
2080420699
#endif /* SQLITE_OMIT_DESERIALIZE */
2080520700
}else
20806
-#endif /* !SQLITE_SHELL_FIDDLE */
20701
+#endif /* !SQLITE_SHELL_WASM_MODE */
2080720702
if( z[0]=='-' ){
2080820703
utf8_printf(stderr, "unknown option: %s\n", z);
2080920704
rc = 1;
2081020705
goto meta_command_exit;
2081120706
}else if( zFN ){
@@ -20829,11 +20724,11 @@
2082920724
p->szMax = 0;
2083020725
2083120726
/* If a filename is specified, try to open it first */
2083220727
if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
2083320728
if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20834
-#ifndef SQLITE_SHELL_FIDDLE
20729
+#ifndef SQLITE_SHELL_WASM_MODE
2083520730
if( p->bSafeMode
2083620731
&& p->openMode!=SHELL_OPEN_HEXDB
2083720732
&& zFN
2083820733
&& strcmp(zFN,":memory:")!=0
2083920734
){
@@ -20862,11 +20757,11 @@
2086220757
p->pAuxDb->zDbFilename = 0;
2086320758
open_db(p, 0);
2086420759
}
2086520760
}else
2086620761
20867
-#ifndef SQLITE_SHELL_FIDDLE
20762
+#ifndef SQLITE_SHELL_WASM_MODE
2086820763
if( (c=='o'
2086920764
&& (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
2087020765
|| (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
2087120766
){
2087220767
char *zFile = 0;
@@ -20978,11 +20873,11 @@
2097820873
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2097920874
}
2098020875
}
2098120876
sqlite3_free(zFile);
2098220877
}else
20983
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
20878
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2098420879
2098520880
if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
2098620881
open_db(p,0);
2098720882
if( nArg<=1 ) goto parameter_syntax_error;
2098820883
@@ -21148,17 +21043,17 @@
2114821043
if( nArg >= 3) {
2114921044
strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
2115021045
}
2115121046
}else
2115221047
21153
-#ifndef SQLITE_SHELL_FIDDLE
21048
+#ifndef SQLITE_SHELL_WASM_MODE
2115421049
if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
2115521050
rc = 2;
2115621051
}else
2115721052
#endif
2115821053
21159
-#ifndef SQLITE_SHELL_FIDDLE
21054
+#ifndef SQLITE_SHELL_WASM_MODE
2116021055
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
2116121056
FILE *inSaved = p->in;
2116221057
int savedLineno = p->lineno;
2116321058
failIfSafeMode(p, "cannot run .read in safe mode");
2116421059
if( nArg!=2 ){
@@ -21189,13 +21084,13 @@
2118921084
fclose(p->in);
2119021085
}
2119121086
p->in = inSaved;
2119221087
p->lineno = savedLineno;
2119321088
}else
21194
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
21089
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2119521090
21196
-#ifndef SQLITE_SHELL_FIDDLE
21091
+#ifndef SQLITE_SHELL_WASM_MODE
2119721092
if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
2119821093
const char *zSrcFile;
2119921094
const char *zDb;
2120021095
sqlite3 *pSrc;
2120121096
sqlite3_backup *pBackup;
@@ -21243,11 +21138,11 @@
2124321138
utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
2124421139
rc = 1;
2124521140
}
2124621141
close_db(pSrc);
2124721142
}else
21248
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
21143
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2124921144
2125021145
if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
2125121146
if( nArg==2 ){
2125221147
p->scanstatsOn = (u8)booleanValue(azArg[1]);
2125321148
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21869,11 +21764,11 @@
2186921764
shell_exec(p, zSql, 0);
2187021765
}
2187121766
sqlite3_free(zSql);
2187221767
}else
2187321768
21874
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
21769
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
2187521770
if( c=='s'
2187621771
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
2187721772
){
2187821773
char *zCmd;
2187921774
int i, x;
@@ -21890,11 +21785,11 @@
2189021785
}
2189121786
x = zCmd!=0 ? system(zCmd) : 1;
2189221787
sqlite3_free(zCmd);
2189321788
if( x ) raw_printf(stderr, "System command returns %d\n", x);
2189421789
}else
21895
-#endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE) */
21790
+#endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE) */
2189621791
2189721792
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
2189821793
static const char *azBool[] = { "off", "on", "trigger", "full"};
2189921794
const char *zOut;
2190021795
int i;
@@ -22070,11 +21965,11 @@
2207021965
2207121966
for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
2207221967
sqlite3_free(azResult);
2207321968
}else
2207421969
22075
-#ifndef SQLITE_SHELL_FIDDLE
21970
+#ifndef SQLITE_SHELL_WASM_MODE
2207621971
/* Begin redirecting output to the file "testcase-out.txt" */
2207721972
if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
2207821973
output_reset(p);
2207921974
p->out = output_file_open("testcase-out.txt", 0);
2208021975
if( p->out==0 ){
@@ -22084,11 +21979,11 @@
2208421979
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
2208521980
}else{
2208621981
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
2208721982
}
2208821983
}else
22089
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
21984
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2209021985
2209121986
#ifndef SQLITE_UNTESTABLE
2209221987
if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
2209321988
static const struct {
2209421989
const char *zCtrlName; /* Name of a test-control option */
@@ -22756,11 +22651,11 @@
2275622651
2275722652
static void echo_group_input(ShellState *p, const char *zDo){
2275822653
if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
2275922654
}
2276022655
22761
-#ifdef SQLITE_SHELL_FIDDLE
22656
+#ifdef SQLITE_SHELL_WASM_MODE
2276222657
/*
2276322658
** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
2276422659
** because we need the global shellState and cannot access it from that function
2276522660
** without moving lots of code around (creating a larger/messier diff).
2276622661
*/
@@ -22787,11 +22682,11 @@
2278722682
shell_check_oom(zLine);
2278822683
memcpy(zLine, zBegin, (size_t)nZ);
2278922684
zLine[nZ] = 0;
2279022685
return zLine;
2279122686
}
22792
-#endif /* SQLITE_SHELL_FIDDLE */
22687
+#endif /* SQLITE_SHELL_WASM_MODE */
2279322688
2279422689
/*
2279522690
** Read input from *in and process it. If *in==0 then input
2279622691
** is interactive - the user is typing it it. Otherwise, input
2279722692
** is coming from a file or device. A prompt is issued and history
@@ -23170,11 +23065,11 @@
2317023065
# else
2317123066
# define SQLITE_SHELL_IS_UTF8 (1)
2317223067
# endif
2317323068
#endif
2317423069
23175
-#ifdef SQLITE_SHELL_FIDDLE
23070
+#ifdef SQLITE_SHELL_WASM_MODE
2317623071
# define main fiddle_main
2317723072
#endif
2317823073
2317923074
#if SQLITE_SHELL_IS_UTF8
2318023075
int SQLITE_CDECL main(int argc, char **argv){
@@ -23184,11 +23079,11 @@
2318423079
#endif
2318523080
#ifdef SQLITE_DEBUG
2318623081
sqlite3_int64 mem_main_enter = sqlite3_memory_used();
2318723082
#endif
2318823083
char *zErrMsg = 0;
23189
-#ifdef SQLITE_SHELL_FIDDLE
23084
+#ifdef SQLITE_SHELL_WASM_MODE
2319023085
# define data shellState
2319123086
#else
2319223087
ShellState data;
2319323088
#endif
2319423089
const char *zInitFile = 0;
@@ -23204,11 +23099,11 @@
2320423099
int argcToFree = 0;
2320523100
#endif
2320623101
2320723102
setBinaryMode(stdin, 0);
2320823103
setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23209
-#ifdef SQLITE_SHELL_FIDDLE
23104
+#ifdef SQLITE_SHELL_WASM_MODE
2321023105
stdin_is_interactive = 0;
2321123106
stdout_is_console = 1;
2321223107
#else
2321323108
stdin_is_interactive = isatty(0);
2321423109
stdout_is_console = isatty(1);
@@ -23466,11 +23361,11 @@
2346623361
utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
2346723362
return 1;
2346823363
#endif
2346923364
}
2347023365
data.out = stdout;
23471
-#ifndef SQLITE_SHELL_FIDDLE
23366
+#ifndef SQLITE_SHELL_WASM_MODE
2347223367
sqlite3_appendvfs_init(0,0,0);
2347323368
#endif
2347423369
2347523370
/* Go ahead and open the database file if it already exists. If the
2347623371
** file does not exist, delay opening it. This prevents empty database
@@ -23734,11 +23629,11 @@
2373423629
}else{
2373523630
data.in = stdin;
2373623631
rc = process_input(&data);
2373723632
}
2373823633
}
23739
-#ifndef SQLITE_SHELL_FIDDLE
23634
+#ifndef SQLITE_SHELL_WASM_MODE
2374023635
/* In WASM mode we have to leave the db state in place so that
2374123636
** client code can "push" SQL into it after this call returns. */
2374223637
free(azCmd);
2374323638
set_table_name(&data, 0);
2374423639
if( data.db ){
@@ -23769,16 +23664,16 @@
2376923664
if( sqlite3_memory_used()>mem_main_enter ){
2377023665
utf8_printf(stderr, "Memory leaked: %u bytes\n",
2377123666
(unsigned int)(sqlite3_memory_used()-mem_main_enter));
2377223667
}
2377323668
#endif
23774
-#endif /* !SQLITE_SHELL_FIDDLE */
23669
+#endif /* !SQLITE_SHELL_WASM_MODE */
2377523670
return rc;
2377623671
}
2377723672
2377823673
23779
-#ifdef SQLITE_SHELL_FIDDLE
23674
+#ifdef SQLITE_SHELL_WASM_MODE
2378023675
/* Only for emcc experimentation purposes. */
2378123676
int fiddle_experiment(int a,int b){
2378223677
return a + b;
2378323678
}
2378423679
@@ -23895,6 +23790,6 @@
2389523790
shellState.wasm.zPos = zSql;
2389623791
process_input(&shellState);
2389723792
memset(&shellState.wasm, 0, sizeof(shellState.wasm));
2389823793
}
2389923794
}
23900
-#endif /* SQLITE_SHELL_FIDDLE */
23795
+#endif /* SQLITE_SHELL_WASM_MODE */
2390123796
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,19 +53,10 @@
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)
@@ -254,10 +245,21 @@
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){
@@ -715,11 +717,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);
@@ -735,11 +737,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 */
@@ -3792,11 +3794,10 @@
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 */
@@ -3814,37 +3815,10 @@
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
@@ -3875,11 +3849,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 */
@@ -3948,11 +3922,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;
@@ -3967,11 +3941,10 @@
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;
@@ -3996,14 +3969,10 @@
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 }
4009 case RE_OP_WORD: {
@@ -4081,13 +4050,11 @@
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 }
@@ -4238,10 +4205,11 @@
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 '(': {
@@ -4274,18 +4242,10 @@
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";
4291 while( (c=rePeek(p))>='0' && c<='9' ){ m = m*10 + c - '0'; p->sIn.i++; }
@@ -4300,11 +4260,10 @@
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++){
@@ -4419,11 +4378,15 @@
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";
@@ -4502,71 +4465,10 @@
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 */
@@ -4588,23 +4490,16 @@
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
@@ -12353,19 +12248,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
@@ -13029,11 +12924,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;
@@ -15443,11 +15338,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",
@@ -15469,23 +15364,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",
@@ -15507,15 +15402,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",
@@ -15522,11 +15417,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",
@@ -15551,14 +15446,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",
@@ -15581,15 +15476,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\")",
@@ -15607,11 +15502,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",
@@ -15631,11 +15526,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)
@@ -15644,11 +15539,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",
@@ -15681,24 +15576,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",
@@ -16247,11 +16142,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);
@@ -19377,19 +19272,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;
@@ -19454,11 +19349,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{
@@ -19485,11 +19380,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]);
@@ -19505,11 +19400,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{
@@ -19516,11 +19411,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 ){
@@ -19541,23 +19436,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;
@@ -19842,11 +19737,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
@@ -20102,11 +19997,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 */
@@ -20393,11 +20288,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;
@@ -20583,11 +20478,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 ){
@@ -20605,11 +20500,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;
@@ -20742,11 +20637,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 ){
@@ -20757,11 +20652,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]);
@@ -20779,11 +20674,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;
@@ -20801,11 +20696,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 ){
@@ -20829,11 +20724,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 ){
@@ -20862,11 +20757,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;
@@ -20978,11 +20873,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
@@ -21148,17 +21043,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 ){
@@ -21189,13 +21084,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;
@@ -21243,11 +21138,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
@@ -21869,11 +21764,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;
@@ -21890,11 +21785,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;
@@ -22070,11 +21965,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 ){
@@ -22084,11 +21979,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 */
@@ -22756,11 +22651,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 */
@@ -22787,11 +22682,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
@@ -23170,11 +23065,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){
@@ -23184,11 +23079,11 @@
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;
@@ -23204,11 +23099,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);
@@ -23466,11 +23361,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
@@ -23734,11 +23629,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 ){
@@ -23769,16 +23664,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
@@ -23895,6 +23790,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
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,19 +53,10 @@
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)
@@ -254,10 +245,21 @@
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){
@@ -715,11 +717,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);
@@ -735,11 +737,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 */
@@ -3792,11 +3794,10 @@
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 */
@@ -3814,37 +3815,10 @@
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
@@ -3875,11 +3849,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 */
@@ -3948,11 +3922,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;
@@ -3967,11 +3941,10 @@
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;
@@ -3996,14 +3969,10 @@
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 }
3978 case RE_OP_WORD: {
@@ -4081,13 +4050,11 @@
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 }
@@ -4238,10 +4205,11 @@
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 '(': {
@@ -4274,18 +4242,10 @@
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";
4251 while( (c=rePeek(p))>='0' && c<='9' ){ m = m*10 + c - '0'; p->sIn.i++; }
@@ -4300,11 +4260,10 @@
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++){
@@ -4419,11 +4378,15 @@
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";
@@ -4502,71 +4465,10 @@
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 */
@@ -4588,23 +4490,16 @@
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
@@ -12353,19 +12248,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
@@ -13029,11 +12924,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;
@@ -15443,11 +15338,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",
@@ -15469,23 +15364,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",
@@ -15507,15 +15402,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",
@@ -15522,11 +15417,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",
@@ -15551,14 +15446,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",
@@ -15581,15 +15476,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\")",
@@ -15607,11 +15502,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",
@@ -15631,11 +15526,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)
@@ -15644,11 +15539,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",
@@ -15681,24 +15576,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",
@@ -16247,11 +16142,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);
@@ -19377,19 +19272,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;
@@ -19454,11 +19349,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{
@@ -19485,11 +19380,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]);
@@ -19505,11 +19400,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{
@@ -19516,11 +19411,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 ){
@@ -19541,23 +19436,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;
@@ -19842,11 +19737,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
@@ -20102,11 +19997,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 */
@@ -20393,11 +20288,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;
@@ -20583,11 +20478,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 ){
@@ -20605,11 +20500,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;
@@ -20742,11 +20637,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 ){
@@ -20757,11 +20652,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]);
@@ -20779,11 +20674,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;
@@ -20801,11 +20696,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 ){
@@ -20829,11 +20724,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 ){
@@ -20862,11 +20757,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;
@@ -20978,11 +20873,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
@@ -21148,17 +21043,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 ){
@@ -21189,13 +21084,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;
@@ -21243,11 +21138,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
@@ -21869,11 +21764,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;
@@ -21890,11 +21785,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;
@@ -22070,11 +21965,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 ){
@@ -22084,11 +21979,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 */
@@ -22756,11 +22651,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 */
@@ -22787,11 +22682,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
@@ -23170,11 +23065,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){
@@ -23184,11 +23079,11 @@
23079 #endif
23080 #ifdef SQLITE_DEBUG
23081 sqlite3_int64 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;
@@ -23204,11 +23099,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);
@@ -23466,11 +23361,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
@@ -23734,11 +23629,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 ){
@@ -23769,16 +23664,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
@@ -23895,6 +23790,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
+212 -249
--- 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.40.0. By combining all the individual C code files into this
3
+** version 3.39.2. 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.40.0"
456
-#define SQLITE_VERSION_NUMBER 3040000
457
-#define SQLITE_SOURCE_ID "2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a"
455
+#define SQLITE_VERSION "3.39.2"
456
+#define SQLITE_VERSION_NUMBER 3039002
457
+#define SQLITE_SOURCE_ID "2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -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_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 */
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 */
1556915569
#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] */
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] */
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_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 */
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 */
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_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 */
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 */
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, 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,\
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,\
1575315753
/* 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,\
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,\
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,\
@@ -29561,17 +29561,12 @@
2956129561
if( db->nVdbeExec>0 ){
2956229562
AtomicStore(&db->u1.isInterrupted, 1);
2956329563
}
2956429564
DisableLookaside;
2956529565
if( db->pParse ){
29566
- Parse *pParse;
2956729566
sqlite3ErrorMsg(db->pParse, "out of memory");
2956829567
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
- }
2957329568
}
2957429569
}
2957529570
return 0;
2957629571
}
2957729572
@@ -35280,67 +35275,67 @@
3528035275
/* 3 */ "Checkpoint" OpHelp(""),
3528135276
/* 4 */ "JournalMode" OpHelp(""),
3528235277
/* 5 */ "Vacuum" OpHelp(""),
3528335278
/* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
3528435279
/* 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"),
35280
+ /* 8 */ "Goto" OpHelp(""),
35281
+ /* 9 */ "Gosub" OpHelp(""),
35282
+ /* 10 */ "InitCoroutine" OpHelp(""),
35283
+ /* 11 */ "Yield" OpHelp(""),
35284
+ /* 12 */ "MustBeInt" OpHelp(""),
35285
+ /* 13 */ "Jump" OpHelp(""),
35286
+ /* 14 */ "Once" OpHelp(""),
35287
+ /* 15 */ "If" OpHelp(""),
35288
+ /* 16 */ "IfNot" OpHelp(""),
35289
+ /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
35290
+ /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
3529635291
/* 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]"),
35292
+ /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35293
+ /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35294
+ /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35295
+ /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35296
+ /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35297
+ /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35298
+ /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35299
+ /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"),
35300
+ /* 28 */ "Found" OpHelp("key=r[P3@P4]"),
35301
+ /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35302
+ /* 30 */ "NotExists" OpHelp("intkey=r[P3]"),
35303
+ /* 31 */ "Last" OpHelp(""),
35304
+ /* 32 */ "IfSmaller" OpHelp(""),
35305
+ /* 33 */ "SorterSort" OpHelp(""),
35306
+ /* 34 */ "Sort" OpHelp(""),
35307
+ /* 35 */ "Rewind" OpHelp(""),
35308
+ /* 36 */ "SorterNext" OpHelp(""),
35309
+ /* 37 */ "Prev" OpHelp(""),
35310
+ /* 38 */ "Next" OpHelp(""),
35311
+ /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35312
+ /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35313
+ /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35314
+ /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"),
3532035315
/* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
3532135316
/* 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"),
35317
+ /* 45 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35318
+ /* 46 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35319
+ /* 47 */ "Program" OpHelp(""),
35320
+ /* 48 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35321
+ /* 49 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
3532735322
/* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
3532835323
/* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
3532935324
/* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
3533035325
/* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
3533135326
/* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
3533235327
/* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
3533335328
/* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
3533435329
/* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
3533535330
/* 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"),
35331
+ /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35332
+ /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35333
+ /* 61 */ "IncrVacuum" OpHelp(""),
35334
+ /* 62 */ "VNext" OpHelp(""),
35335
+ /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35336
+ /* 64 */ "Init" OpHelp("Start at P2"),
3534235337
/* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
3534335338
/* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
3534435339
/* 67 */ "Return" OpHelp(""),
3534535340
/* 68 */ "EndCoroutine" OpHelp(""),
3534635341
/* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
@@ -68314,10 +68309,11 @@
6831468309
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6831568310
assert( pPage->pBt!=0 );
6831668311
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
6831768312
assert( pPage->nOverflow==0 );
6831868313
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68314
+ temp = 0;
6831968315
src = data = pPage->aData;
6832068316
hdr = pPage->hdrOffset;
6832168317
cellOffset = pPage->cellOffset;
6832268318
nCell = pPage->nCell;
6832368319
assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
@@ -68368,42 +68364,43 @@
6836868364
}
6836968365
6837068366
cbrk = usableSize;
6837168367
iCellLast = usableSize - 4;
6837268368
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
- }
68369
+ for(i=0; i<nCell; i++){
68370
+ u8 *pAddr; /* The i-th cell pointer */
68371
+ pAddr = &data[cellOffset + i*2];
68372
+ pc = get2byte(pAddr);
68373
+ testcase( pc==iCellFirst );
68374
+ testcase( pc==iCellLast );
68375
+ /* These conditions have already been verified in btreeInitPage()
68376
+ ** if PRAGMA cell_size_check=ON.
68377
+ */
68378
+ if( pc<iCellStart || pc>iCellLast ){
68379
+ return SQLITE_CORRUPT_PAGE(pPage);
68380
+ }
68381
+ assert( pc>=iCellStart && pc<=iCellLast );
68382
+ size = pPage->xCellSize(pPage, &src[pc]);
68383
+ cbrk -= size;
68384
+ if( cbrk<iCellStart || pc+size>usableSize ){
68385
+ return SQLITE_CORRUPT_PAGE(pPage);
68386
+ }
68387
+ assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68388
+ testcase( cbrk+size==usableSize );
68389
+ testcase( pc+size==usableSize );
68390
+ put2byte(pAddr, cbrk);
68391
+ if( temp==0 ){
68392
+ if( cbrk==pc ) continue;
68393
+ temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68394
+ memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68395
+ src = temp;
68396
+ }
68397
+ memcpy(&data[cbrk], &src[pc], size);
6840168398
}
6840268399
data[hdr+7] = 0;
6840368400
68404
-defragment_out:
68401
+ defragment_out:
6840568402
assert( pPage->nFree>=0 );
6840668403
if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
6840768404
return SQLITE_CORRUPT_PAGE(pPage);
6840868405
}
6840968406
assert( cbrk>=iCellFirst );
@@ -68472,13 +68469,13 @@
6847268469
return &aData[pc + x];
6847368470
}
6847468471
iAddr = pc;
6847568472
pTmp = &aData[pc];
6847668473
pc = get2byte(pTmp);
68477
- if( pc<=iAddr ){
68474
+ if( pc<=iAddr+size ){
6847868475
if( pc ){
68479
- /* The next slot in the chain comes before the current slot */
68476
+ /* The next slot in the chain is not past the end of the current slot */
6848068477
*pRc = SQLITE_CORRUPT_PAGE(pPg);
6848168478
}
6848268479
return 0;
6848368480
}
6848468481
}
@@ -68626,11 +68623,11 @@
6862668623
iPtr = hdr + 1;
6862768624
if( data[iPtr+1]==0 && data[iPtr]==0 ){
6862868625
iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
6862968626
}else{
6863068627
while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
68631
- if( iFreeBlk<=iPtr ){
68628
+ if( iFreeBlk<iPtr+4 ){
6863268629
if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
6863368630
return SQLITE_CORRUPT_PAGE(pPage);
6863468631
}
6863568632
iPtr = iFreeBlk;
6863668633
}
@@ -69108,11 +69105,13 @@
6910869105
if( pCur ){
6910969106
pCur->iPage--;
6911069107
pCur->pPage = pCur->apPage[pCur->iPage];
6911169108
}
6911269109
testcase( pgno==0 );
69113
- assert( pgno!=0 || rc!=SQLITE_OK );
69110
+ assert( pgno!=0 || rc==SQLITE_CORRUPT
69111
+ || rc==SQLITE_IOERR_NOMEM
69112
+ || rc==SQLITE_NOMEM );
6911469113
return rc;
6911569114
}
6911669115
6911769116
/*
6911869117
** Release a MemPage. This should be called once for each prior
@@ -72050,10 +72049,12 @@
7205072049
** the new child page does not match the flags field of the parent (i.e.
7205172050
** if an intkey page appears to be the parent of a non-intkey page, or
7205272051
** vice-versa).
7205372052
*/
7205472053
static int moveToChild(BtCursor *pCur, u32 newPgno){
72054
+ BtShared *pBt = pCur->pBt;
72055
+
7205572056
assert( cursorOwnsBtShared(pCur) );
7205672057
assert( pCur->eState==CURSOR_VALID );
7205772058
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
7205872059
assert( pCur->iPage>=0 );
7205972060
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
@@ -72063,12 +72064,11 @@
7206372064
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
7206472065
pCur->aiIdx[pCur->iPage] = pCur->ix;
7206572066
pCur->apPage[pCur->iPage] = pCur->pPage;
7206672067
pCur->ix = 0;
7206772068
pCur->iPage++;
72068
- return getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur,
72069
- pCur->curPagerFlags);
72069
+ return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
7207072070
}
7207172071
7207272072
#ifdef SQLITE_DEBUG
7207372073
/*
7207472074
** Page pParent is an internal (non-leaf) tree page. This function
@@ -72170,11 +72170,11 @@
7217072170
assert( pCur->skipNext!=SQLITE_OK );
7217172171
return pCur->skipNext;
7217272172
}
7217372173
sqlite3BtreeClearCursor(pCur);
7217472174
}
72175
- rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
72175
+ rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
7217672176
0, pCur->curPagerFlags);
7217772177
if( rc!=SQLITE_OK ){
7217872178
pCur->eState = CURSOR_INVALID;
7217972179
return rc;
7218072180
}
@@ -73811,10 +73811,16 @@
7381173811
data = pPage->aData;
7381273812
ptr = &pPage->aCellIdx[2*idx];
7381373813
assert( pPage->pBt->usableSize > (u32)(ptr-data) );
7381473814
pc = get2byte(ptr);
7381573815
hdr = pPage->hdrOffset;
73816
+#if 0 /* Not required. Omit for efficiency */
73817
+ if( pc<hdr+pPage->nCell*2 ){
73818
+ *pRC = SQLITE_CORRUPT_BKPT;
73819
+ return;
73820
+ }
73821
+#endif
7381673822
testcase( pc==(u32)get2byte(&data[hdr+5]) );
7381773823
testcase( pc+sz==pPage->pBt->usableSize );
7381873824
if( pc+sz > pPage->pBt->usableSize ){
7381973825
*pRC = SQLITE_CORRUPT_BKPT;
7382073826
return;
@@ -80761,18 +80767,11 @@
8076180767
return 0;
8076280768
}
8076380769
#endif
8076480770
8076580771
/*
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.
80772
+** Swap all content between two VDBE structures.
8077480773
*/
8077580774
SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
8077680775
Vdbe tmp, *pTmp;
8077780776
char *zTmp;
8077880777
assert( pA->db==pB->db );
@@ -81459,12 +81458,12 @@
8145981458
Parse *pParse = p->pParse;
8146081459
int *aLabel = pParse->aLabel;
8146181460
p->readOnly = 1;
8146281461
p->bIsReader = 0;
8146381462
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 */ ){
81463
+ while(1){
81464
+
8146681465
/* Only JUMP opcodes and the short list of special opcodes in the switch
8146781466
** below need to be considered. The mkopcodeh.tcl generator script groups
8146881467
** all these opcodes together near the front of the opcode list. Skip
8146981468
** any opcode that does not need processing by virtual of the fact that
8147081469
** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -81489,14 +81488,10 @@
8148981488
case OP_JournalMode: {
8149081489
p->readOnly = 0;
8149181490
p->bIsReader = 1;
8149281491
break;
8149381492
}
81494
- case OP_Init: {
81495
- assert( pOp->p2>=0 );
81496
- goto resolve_p2_values_loop_exit;
81497
- }
8149881493
#ifndef SQLITE_OMIT_VIRTUALTABLE
8149981494
case OP_VUpdate: {
8150081495
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
8150181496
break;
8150281497
}
@@ -81525,14 +81520,13 @@
8152581520
/* The mkopcodeh.tcl script has so arranged things that the only
8152681521
** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
8152781522
** have non-negative values for P2. */
8152881523
assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
8152981524
}
81530
- assert( pOp>p->aOp );
81525
+ if( pOp==p->aOp ) break;
8153181526
pOp--;
8153281527
}
81533
-resolve_p2_values_loop_exit:
8153481528
if( aLabel ){
8153581529
sqlite3DbFreeNN(p->db, pParse->aLabel);
8153681530
pParse->aLabel = 0;
8153781531
}
8153881532
pParse->nLabel = 0;
@@ -86054,13 +86048,11 @@
8605486048
Vdbe *v = (Vdbe*)pStmt;
8605586049
sqlite3 *db = v->db;
8605686050
if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
8605786051
sqlite3_mutex_enter(db->mutex);
8605886052
checkProfileCallback(db, v);
86059
- assert( v->eVdbeState>=VDBE_READY_STATE );
86060
- rc = sqlite3VdbeReset(v);
86061
- sqlite3VdbeDelete(v);
86053
+ rc = sqlite3VdbeFinalize(v);
8606286054
rc = sqlite3ApiExit(db, rc);
8606386055
sqlite3LeaveMutexAndCloseZombie(db);
8606486056
}
8606586057
return rc;
8606686058
}
@@ -90949,18 +90941,15 @@
9094990941
**
9095090942
** Check the cursor P1 to see if it is currently pointing at a NULL row.
9095190943
** If it is, then set register P3 to NULL and jump immediately to P2.
9095290944
** If P1 is not on a NULL row, then fall through without making any
9095390945
** changes.
90954
-**
90955
-** If P1 is not an open cursor, then this opcode is a no-op.
9095690946
*/
9095790947
case OP_IfNullRow: { /* jump */
90958
- VdbeCursor *pC;
9095990948
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90960
- pC = p->apCsr[pOp->p1];
90961
- if( ALWAYS(pC) && pC->nullRow ){
90949
+ assert( p->apCsr[pOp->p1]!=0 );
90950
+ if( p->apCsr[pOp->p1]->nullRow ){
9096290951
sqlite3VdbeMemSetNull(aMem + pOp->p3);
9096390952
goto jump_to_p2;
9096490953
}
9096590954
break;
9096690955
}
@@ -101549,37 +101538,27 @@
101549101538
pDup = sqlite3ExprDup(db, pOrig, 0);
101550101539
if( db->mallocFailed ){
101551101540
sqlite3ExprDelete(db, pDup);
101552101541
pDup = 0;
101553101542
}else{
101543
+ Expr temp;
101554101544
incrAggFunctionDepth(pDup, nSubquery);
101555101545
if( pExpr->op==TK_COLLATE ){
101556101546
assert( !ExprHasProperty(pExpr, EP_IntValue) );
101557101547
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
101558101548
}
101559
-
101560
- /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
101561
- ** prevents ExprDelete() from deleting the Expr structure itself,
101562
- ** allowing it to be repopulated by the memcpy() on the following line.
101563
- ** The pExpr->u.zToken might point into memory that will be freed by the
101564
- ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
101565
- ** make a copy of the token before doing the sqlite3DbFree().
101566
- */
101567
- ExprSetProperty(pExpr, EP_Static);
101568
- sqlite3ExprDelete(db, pExpr);
101569
- memcpy(pExpr, pDup, sizeof(*pExpr));
101570
- if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
101571
- assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
101572
- pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
101573
- pExpr->flags |= EP_MemToken;
101574
- }
101549
+ memcpy(&temp, pDup, sizeof(Expr));
101550
+ memcpy(pDup, pExpr, sizeof(Expr));
101551
+ memcpy(pExpr, &temp, sizeof(Expr));
101575101552
if( ExprHasProperty(pExpr, EP_WinFunc) ){
101576101553
if( ALWAYS(pExpr->y.pWin!=0) ){
101577101554
pExpr->y.pWin->pOwner = pExpr;
101578101555
}
101579101556
}
101580
- sqlite3DbFree(db, pDup);
101557
+ sqlite3ParserAddCleanup(pParse,
101558
+ (void(*)(sqlite3*,void*))sqlite3ExprDelete,
101559
+ pDup);
101581101560
}
101582101561
}
101583101562
101584101563
/*
101585101564
** Subqueries stores the original database, table and column names for their
@@ -137363,10 +137342,13 @@
137363137342
}
137364137343
137365137344
/*
137366137345
** Return a pointer to a string containing the 'declaration type' of the
137367137346
** expression pExpr. The string may be treated as static by the caller.
137347
+**
137348
+** Also try to estimate the size of the returned value and return that
137349
+** result in *pEstWidth.
137368137350
**
137369137351
** The declaration type is the exact datatype definition extracted from the
137370137352
** original CREATE TABLE statement if the expression is a column. The
137371137353
** declaration type for a ROWID field is INTEGER. Exactly when an expression
137372137354
** is considered a column can be complex in the presence of subqueries. The
@@ -139609,12 +139591,11 @@
139609139591
**
139610139592
** (3) If the subquery is the right operand of a LEFT JOIN then
139611139593
** (3a) the subquery may not be a join and
139612139594
** (3b) the FROM clause of the subquery may not contain a virtual
139613139595
** 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!)
139596
+** (3c) the outer query may not be an aggregate.
139616139597
** (3d) the outer query may not be DISTINCT.
139617139598
** See also (26) for restrictions on RIGHT JOIN.
139618139599
**
139619139600
** (4) The subquery can not be DISTINCT.
139620139601
**
@@ -139822,17 +139803,22 @@
139822139803
**
139823139804
** (t1 LEFT OUTER JOIN t2) JOIN t3
139824139805
**
139825139806
** which is not at all the same thing.
139826139807
**
139808
+ ** If the subquery is the right operand of a LEFT JOIN, then the outer
139809
+ ** query cannot be an aggregate. (3c) This is an artifact of the way
139810
+ ** aggregates are processed - there is no mechanism to determine if
139811
+ ** the LEFT JOIN table should be all-NULL.
139812
+ **
139827139813
** See also tickets #306, #350, and #3300.
139828139814
*/
139829139815
if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
139830139816
if( pSubSrc->nSrc>1 /* (3a) */
139817
+ || isAgg /* (3c) */
139831139818
|| IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
139832139819
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
139833
- || (p->pGroupBy!=0) /* (3c) */
139834139820
|| (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
139835139821
){
139836139822
return 0;
139837139823
}
139838139824
isOuterJoin = 1;
@@ -140747,11 +140733,10 @@
140747140733
if( p->pWhere
140748140734
|| p->pEList->nExpr!=1
140749140735
|| p->pSrc->nSrc!=1
140750140736
|| p->pSrc->a[0].pSelect
140751140737
|| pAggInfo->nFunc!=1
140752
- || p->pHaving
140753140738
){
140754140739
return 0;
140755140740
}
140756140741
pTab = p->pSrc->a[0].pTab;
140757140742
assert( pTab!=0 );
@@ -156143,22 +156128,16 @@
156143156128
}
156144156129
}
156145156130
}
156146156131
156147156132
/*
156148
-** Deallocate internal memory used by a WhereLoop object. Leave the
156149
-** object in an initialized state, as if it had been newly allocated.
156133
+** Deallocate internal memory used by a WhereLoop object
156150156134
*/
156151156135
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
- }
156136
+ if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
156157156137
whereLoopClearUnion(db, p);
156158
- p->nLTerm = 0;
156159
- p->wsFlags = 0;
156138
+ whereLoopInit(p);
156160156139
}
156161156140
156162156141
/*
156163156142
** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
156164156143
*/
@@ -156178,13 +156157,11 @@
156178156157
/*
156179156158
** Transfer content from the second pLoop into the first.
156180156159
*/
156181156160
static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
156182156161
whereLoopClearUnion(db, pTo);
156183
- if( pFrom->nLTerm > pTo->nLSlot
156184
- && whereLoopResize(db, pTo, pFrom->nLTerm)
156185
- ){
156162
+ if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
156186156163
memset(pTo, 0, WHERE_LOOP_XFER_SZ);
156187156164
return SQLITE_NOMEM_BKPT;
156188156165
}
156189156166
memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
156190156167
memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
@@ -156833,15 +156810,11 @@
156833156810
pNew->wsFlags = saved_wsFlags;
156834156811
pNew->u.btree.nEq = saved_nEq;
156835156812
pNew->u.btree.nBtm = saved_nBtm;
156836156813
pNew->u.btree.nTop = saved_nTop;
156837156814
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
- }
156815
+ if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156843156816
pNew->aLTerm[pNew->nLTerm++] = pTerm;
156844156817
pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
156845156818
156846156819
assert( nInMul==0
156847156820
|| (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
@@ -156930,43 +156903,42 @@
156930156903
}
156931156904
}
156932156905
if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
156933156906
}else if( eOp & WO_ISNULL ){
156934156907
pNew->wsFlags |= WHERE_COLUMN_NULL;
156908
+ }else if( eOp & (WO_GT|WO_GE) ){
156909
+ testcase( eOp & WO_GT );
156910
+ testcase( eOp & WO_GE );
156911
+ pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
156912
+ pNew->u.btree.nBtm = whereRangeVectorLen(
156913
+ pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156914
+ );
156915
+ pBtm = pTerm;
156916
+ pTop = 0;
156917
+ if( pTerm->wtFlags & TERM_LIKEOPT ){
156918
+ /* Range constraints that come from the LIKE optimization are
156919
+ ** always used in pairs. */
156920
+ pTop = &pTerm[1];
156921
+ assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
156922
+ assert( pTop->wtFlags & TERM_LIKEOPT );
156923
+ assert( pTop->eOperator==WO_LT );
156924
+ if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156925
+ pNew->aLTerm[pNew->nLTerm++] = pTop;
156926
+ pNew->wsFlags |= WHERE_TOP_LIMIT;
156927
+ pNew->u.btree.nTop = 1;
156928
+ }
156935156929
}else{
156936
- int nVecLen = whereRangeVectorLen(
156930
+ assert( eOp & (WO_LT|WO_LE) );
156931
+ testcase( eOp & WO_LT );
156932
+ testcase( eOp & WO_LE );
156933
+ pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
156934
+ pNew->u.btree.nTop = whereRangeVectorLen(
156937156935
pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156938156936
);
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
- }
156937
+ pTop = pTerm;
156938
+ pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
156939
+ pNew->aLTerm[pNew->nLTerm-2] : 0;
156968156940
}
156969156941
156970156942
/* At this point pNew->nOut is set to the number of rows expected to
156971156943
** be visited by the index scan before considering term pTerm, or the
156972156944
** values of nIn and nInMul. In other words, assuming that all
@@ -158134,17 +158106,11 @@
158134158106
WhereLoop *pNew;
158135158107
158136158108
158137158109
/* Loop over the tables in the join, from left to right */
158138158110
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
-
158111
+ whereLoopInit(pNew);
158146158112
pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
158147158113
for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
158148158114
Bitmask mUnusable = 0;
158149158115
pNew->iTab = iTab;
158150158116
pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
@@ -158737,13 +158703,13 @@
158737158703
for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
158738158704
for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
158739158705
LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
158740158706
LogEst rCost; /* Cost of path (pFrom+pWLoop) */
158741158707
LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
158742
- i8 isOrdered; /* isOrdered for (pFrom+pWLoop) */
158708
+ i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */
158743158709
Bitmask maskNew; /* Mask of src visited by (..) */
158744
- Bitmask revMask; /* Mask of rev-order loops for (..) */
158710
+ Bitmask revMask = 0; /* Mask of rev-order loops for (..) */
158745158711
158746158712
if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
158747158713
if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
158748158714
if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
158749158715
/* Do not use an automatic index if the this loop is expected
@@ -158758,13 +158724,11 @@
158758158724
** Compute its cost */
158759158725
rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
158760158726
rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
158761158727
nOut = pFrom->nRow + pWLoop->nOut;
158762158728
maskNew = pFrom->maskLoop | pWLoop->maskSelf;
158763
- isOrdered = pFrom->isOrdered;
158764158729
if( isOrdered<0 ){
158765
- revMask = 0;
158766158730
isOrdered = wherePathSatisfiesOrderBy(pWInfo,
158767158731
pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
158768158732
iLoop, pWLoop, &revMask);
158769158733
}else{
158770158734
revMask = pFrom->revLoop;
@@ -212539,16 +212503,15 @@
212539212503
*/
212540212504
static int dbpageBegin(sqlite3_vtab *pVtab){
212541212505
DbpageTable *pTab = (DbpageTable *)pVtab;
212542212506
sqlite3 *db = pTab->db;
212543212507
int i;
212544
- int rc = SQLITE_OK;
212545
- for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
212508
+ for(i=0; i<db->nDb; i++){
212546212509
Btree *pBt = db->aDb[i].pBt;
212547
- if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
212510
+ if( pBt ) sqlite3BtreeBeginTrans(pBt, 1, 0);
212548212511
}
212549
- return rc;
212512
+ return SQLITE_OK;
212550212513
}
212551212514
212552212515
212553212516
/*
212554212517
** Invoke this routine to register the "dbpage" virtual table module
@@ -236671,11 +236634,11 @@
236671236634
int nArg, /* Number of args */
236672236635
sqlite3_value **apUnused /* Function arguments */
236673236636
){
236674236637
assert( nArg==0 );
236675236638
UNUSED_PARAM2(nArg, apUnused);
236676
- sqlite3_result_text(pCtx, "fts5: 2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a", -1, SQLITE_TRANSIENT);
236639
+ sqlite3_result_text(pCtx, "fts5: 2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21", -1, SQLITE_TRANSIENT);
236677236640
}
236678236641
236679236642
/*
236680236643
** Return true if zName is the extension on one of the shadow tables used
236681236644
** by this module.
236682236645
--- 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 **
@@ -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,\
@@ -29561,17 +29561,12 @@
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
@@ -35280,67 +35275,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"),
@@ -68314,10 +68309,11 @@
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 );
@@ -68368,42 +68364,43 @@
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 );
@@ -68472,13 +68469,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 }
@@ -68626,11 +68623,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 }
@@ -69108,11 +69105,13 @@
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
@@ -72050,10 +72049,12 @@
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) ){
@@ -72063,12 +72064,11 @@
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
@@ -72170,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 }
@@ -73811,10 +73811,16 @@
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;
@@ -80761,18 +80767,11 @@
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 );
@@ -81459,12 +81458,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.
@@ -81489,14 +81488,10 @@
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 }
@@ -81525,14 +81520,13 @@
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;
@@ -86054,13 +86048,11 @@
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 }
@@ -90949,18 +90941,15 @@
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 }
@@ -101549,37 +101538,27 @@
101549 pDup = sqlite3ExprDup(db, pOrig, 0);
101550 if( db->mallocFailed ){
101551 sqlite3ExprDelete(db, pDup);
101552 pDup = 0;
101553 }else{
 
101554 incrAggFunctionDepth(pDup, nSubquery);
101555 if( pExpr->op==TK_COLLATE ){
101556 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101557 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
101558 }
101559
101560 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
101561 ** prevents ExprDelete() from deleting the Expr structure itself,
101562 ** allowing it to be repopulated by the memcpy() on the following line.
101563 ** The pExpr->u.zToken might point into memory that will be freed by the
101564 ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
101565 ** make a copy of the token before doing the sqlite3DbFree().
101566 */
101567 ExprSetProperty(pExpr, EP_Static);
101568 sqlite3ExprDelete(db, pExpr);
101569 memcpy(pExpr, pDup, sizeof(*pExpr));
101570 if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
101571 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
101572 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
101573 pExpr->flags |= EP_MemToken;
101574 }
101575 if( ExprHasProperty(pExpr, EP_WinFunc) ){
101576 if( ALWAYS(pExpr->y.pWin!=0) ){
101577 pExpr->y.pWin->pOwner = pExpr;
101578 }
101579 }
101580 sqlite3DbFree(db, pDup);
 
 
101581 }
101582 }
101583
101584 /*
101585 ** Subqueries stores the original database, table and column names for their
@@ -137363,10 +137342,13 @@
137363 }
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
@@ -139609,12 +139591,11 @@
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 **
@@ -139822,17 +139803,22 @@
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;
@@ -140747,11 +140733,10 @@
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 );
@@ -156143,22 +156128,16 @@
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 */
@@ -156178,13 +156157,11 @@
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]));
@@ -156833,15 +156810,11 @@
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
@@ -156930,43 +156903,42 @@
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
@@ -158134,17 +158106,11 @@
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;
@@ -158737,13 +158703,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
@@ -158758,13 +158724,11 @@
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;
@@ -212539,16 +212503,15 @@
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
@@ -236671,11 +236634,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.
236682
--- 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.2. 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.2"
456 #define SQLITE_VERSION_NUMBER 3039002
457 #define SQLITE_SOURCE_ID "2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -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,\
@@ -29561,17 +29561,12 @@
29561 if( db->nVdbeExec>0 ){
29562 AtomicStore(&db->u1.isInterrupted, 1);
29563 }
29564 DisableLookaside;
29565 if( db->pParse ){
 
29566 sqlite3ErrorMsg(db->pParse, "out of memory");
29567 db->pParse->rc = SQLITE_NOMEM_BKPT;
 
 
 
 
29568 }
29569 }
29570 return 0;
29571 }
29572
@@ -35280,67 +35275,67 @@
35275 /* 3 */ "Checkpoint" OpHelp(""),
35276 /* 4 */ "JournalMode" OpHelp(""),
35277 /* 5 */ "Vacuum" OpHelp(""),
35278 /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
35279 /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
35280 /* 8 */ "Goto" OpHelp(""),
35281 /* 9 */ "Gosub" OpHelp(""),
35282 /* 10 */ "InitCoroutine" OpHelp(""),
35283 /* 11 */ "Yield" OpHelp(""),
35284 /* 12 */ "MustBeInt" OpHelp(""),
35285 /* 13 */ "Jump" OpHelp(""),
35286 /* 14 */ "Once" OpHelp(""),
35287 /* 15 */ "If" OpHelp(""),
35288 /* 16 */ "IfNot" OpHelp(""),
35289 /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
35290 /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35291 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
35292 /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35293 /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35294 /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35295 /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35296 /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35297 /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35298 /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35299 /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"),
35300 /* 28 */ "Found" OpHelp("key=r[P3@P4]"),
35301 /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35302 /* 30 */ "NotExists" OpHelp("intkey=r[P3]"),
35303 /* 31 */ "Last" OpHelp(""),
35304 /* 32 */ "IfSmaller" OpHelp(""),
35305 /* 33 */ "SorterSort" OpHelp(""),
35306 /* 34 */ "Sort" OpHelp(""),
35307 /* 35 */ "Rewind" OpHelp(""),
35308 /* 36 */ "SorterNext" OpHelp(""),
35309 /* 37 */ "Prev" OpHelp(""),
35310 /* 38 */ "Next" OpHelp(""),
35311 /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35312 /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35313 /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35314 /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35315 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
35316 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
35317 /* 45 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35318 /* 46 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35319 /* 47 */ "Program" OpHelp(""),
35320 /* 48 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35321 /* 49 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35322 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
35323 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
35324 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
35325 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
35326 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
35327 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
35328 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
35329 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
35330 /* 58 */ "ElseEq" OpHelp(""),
35331 /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35332 /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35333 /* 61 */ "IncrVacuum" OpHelp(""),
35334 /* 62 */ "VNext" OpHelp(""),
35335 /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35336 /* 64 */ "Init" OpHelp("Start at P2"),
35337 /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
35338 /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
35339 /* 67 */ "Return" OpHelp(""),
35340 /* 68 */ "EndCoroutine" OpHelp(""),
35341 /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
@@ -68314,10 +68309,11 @@
68309 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
68310 assert( pPage->pBt!=0 );
68311 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
68312 assert( pPage->nOverflow==0 );
68313 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68314 temp = 0;
68315 src = data = pPage->aData;
68316 hdr = pPage->hdrOffset;
68317 cellOffset = pPage->cellOffset;
68318 nCell = pPage->nCell;
68319 assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
@@ -68368,42 +68364,43 @@
68364 }
68365
68366 cbrk = usableSize;
68367 iCellLast = usableSize - 4;
68368 iCellStart = get2byte(&data[hdr+5]);
68369 for(i=0; i<nCell; i++){
68370 u8 *pAddr; /* The i-th cell pointer */
68371 pAddr = &data[cellOffset + i*2];
68372 pc = get2byte(pAddr);
68373 testcase( pc==iCellFirst );
68374 testcase( pc==iCellLast );
68375 /* These conditions have already been verified in btreeInitPage()
68376 ** if PRAGMA cell_size_check=ON.
68377 */
68378 if( pc<iCellStart || pc>iCellLast ){
68379 return SQLITE_CORRUPT_PAGE(pPage);
68380 }
68381 assert( pc>=iCellStart && pc<=iCellLast );
68382 size = pPage->xCellSize(pPage, &src[pc]);
68383 cbrk -= size;
68384 if( cbrk<iCellStart || pc+size>usableSize ){
68385 return SQLITE_CORRUPT_PAGE(pPage);
68386 }
68387 assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68388 testcase( cbrk+size==usableSize );
68389 testcase( pc+size==usableSize );
68390 put2byte(pAddr, cbrk);
68391 if( temp==0 ){
68392 if( cbrk==pc ) continue;
68393 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68394 memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68395 src = temp;
68396 }
68397 memcpy(&data[cbrk], &src[pc], size);
68398 }
68399 data[hdr+7] = 0;
68400
68401 defragment_out:
68402 assert( pPage->nFree>=0 );
68403 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
68404 return SQLITE_CORRUPT_PAGE(pPage);
68405 }
68406 assert( cbrk>=iCellFirst );
@@ -68472,13 +68469,13 @@
68469 return &aData[pc + x];
68470 }
68471 iAddr = pc;
68472 pTmp = &aData[pc];
68473 pc = get2byte(pTmp);
68474 if( pc<=iAddr+size ){
68475 if( pc ){
68476 /* The next slot in the chain is not past the end of the current slot */
68477 *pRc = SQLITE_CORRUPT_PAGE(pPg);
68478 }
68479 return 0;
68480 }
68481 }
@@ -68626,11 +68623,11 @@
68623 iPtr = hdr + 1;
68624 if( data[iPtr+1]==0 && data[iPtr]==0 ){
68625 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
68626 }else{
68627 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
68628 if( iFreeBlk<iPtr+4 ){
68629 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
68630 return SQLITE_CORRUPT_PAGE(pPage);
68631 }
68632 iPtr = iFreeBlk;
68633 }
@@ -69108,11 +69105,13 @@
69105 if( pCur ){
69106 pCur->iPage--;
69107 pCur->pPage = pCur->apPage[pCur->iPage];
69108 }
69109 testcase( pgno==0 );
69110 assert( pgno!=0 || rc==SQLITE_CORRUPT
69111 || rc==SQLITE_IOERR_NOMEM
69112 || rc==SQLITE_NOMEM );
69113 return rc;
69114 }
69115
69116 /*
69117 ** Release a MemPage. This should be called once for each prior
@@ -72050,10 +72049,12 @@
72049 ** the new child page does not match the flags field of the parent (i.e.
72050 ** if an intkey page appears to be the parent of a non-intkey page, or
72051 ** vice-versa).
72052 */
72053 static int moveToChild(BtCursor *pCur, u32 newPgno){
72054 BtShared *pBt = pCur->pBt;
72055
72056 assert( cursorOwnsBtShared(pCur) );
72057 assert( pCur->eState==CURSOR_VALID );
72058 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
72059 assert( pCur->iPage>=0 );
72060 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
@@ -72063,12 +72064,11 @@
72064 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
72065 pCur->aiIdx[pCur->iPage] = pCur->ix;
72066 pCur->apPage[pCur->iPage] = pCur->pPage;
72067 pCur->ix = 0;
72068 pCur->iPage++;
72069 return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
 
72070 }
72071
72072 #ifdef SQLITE_DEBUG
72073 /*
72074 ** Page pParent is an internal (non-leaf) tree page. This function
@@ -72170,11 +72170,11 @@
72170 assert( pCur->skipNext!=SQLITE_OK );
72171 return pCur->skipNext;
72172 }
72173 sqlite3BtreeClearCursor(pCur);
72174 }
72175 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
72176 0, pCur->curPagerFlags);
72177 if( rc!=SQLITE_OK ){
72178 pCur->eState = CURSOR_INVALID;
72179 return rc;
72180 }
@@ -73811,10 +73811,16 @@
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 #if 0 /* Not required. Omit for efficiency */
73817 if( pc<hdr+pPage->nCell*2 ){
73818 *pRC = SQLITE_CORRUPT_BKPT;
73819 return;
73820 }
73821 #endif
73822 testcase( pc==(u32)get2byte(&data[hdr+5]) );
73823 testcase( pc+sz==pPage->pBt->usableSize );
73824 if( pc+sz > pPage->pBt->usableSize ){
73825 *pRC = SQLITE_CORRUPT_BKPT;
73826 return;
@@ -80761,18 +80767,11 @@
80767 return 0;
80768 }
80769 #endif
80770
80771 /*
80772 ** Swap all content between two VDBE structures.
 
 
 
 
 
 
 
80773 */
80774 SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
80775 Vdbe tmp, *pTmp;
80776 char *zTmp;
80777 assert( pA->db==pB->db );
@@ -81459,12 +81458,12 @@
81458 Parse *pParse = p->pParse;
81459 int *aLabel = pParse->aLabel;
81460 p->readOnly = 1;
81461 p->bIsReader = 0;
81462 pOp = &p->aOp[p->nOp-1];
81463 while(1){
81464
81465 /* Only JUMP opcodes and the short list of special opcodes in the switch
81466 ** below need to be considered. The mkopcodeh.tcl generator script groups
81467 ** all these opcodes together near the front of the opcode list. Skip
81468 ** any opcode that does not need processing by virtual of the fact that
81469 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -81489,14 +81488,10 @@
81488 case OP_JournalMode: {
81489 p->readOnly = 0;
81490 p->bIsReader = 1;
81491 break;
81492 }
 
 
 
 
81493 #ifndef SQLITE_OMIT_VIRTUALTABLE
81494 case OP_VUpdate: {
81495 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
81496 break;
81497 }
@@ -81525,14 +81520,13 @@
81520 /* The mkopcodeh.tcl script has so arranged things that the only
81521 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
81522 ** have non-negative values for P2. */
81523 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
81524 }
81525 if( pOp==p->aOp ) break;
81526 pOp--;
81527 }
 
81528 if( aLabel ){
81529 sqlite3DbFreeNN(p->db, pParse->aLabel);
81530 pParse->aLabel = 0;
81531 }
81532 pParse->nLabel = 0;
@@ -86054,13 +86048,11 @@
86048 Vdbe *v = (Vdbe*)pStmt;
86049 sqlite3 *db = v->db;
86050 if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
86051 sqlite3_mutex_enter(db->mutex);
86052 checkProfileCallback(db, v);
86053 rc = sqlite3VdbeFinalize(v);
 
 
86054 rc = sqlite3ApiExit(db, rc);
86055 sqlite3LeaveMutexAndCloseZombie(db);
86056 }
86057 return rc;
86058 }
@@ -90949,18 +90941,15 @@
90941 **
90942 ** Check the cursor P1 to see if it is currently pointing at a NULL row.
90943 ** If it is, then set register P3 to NULL and jump immediately to P2.
90944 ** If P1 is not on a NULL row, then fall through without making any
90945 ** changes.
 
 
90946 */
90947 case OP_IfNullRow: { /* jump */
 
90948 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90949 assert( p->apCsr[pOp->p1]!=0 );
90950 if( p->apCsr[pOp->p1]->nullRow ){
90951 sqlite3VdbeMemSetNull(aMem + pOp->p3);
90952 goto jump_to_p2;
90953 }
90954 break;
90955 }
@@ -101549,37 +101538,27 @@
101538 pDup = sqlite3ExprDup(db, pOrig, 0);
101539 if( db->mallocFailed ){
101540 sqlite3ExprDelete(db, pDup);
101541 pDup = 0;
101542 }else{
101543 Expr temp;
101544 incrAggFunctionDepth(pDup, nSubquery);
101545 if( pExpr->op==TK_COLLATE ){
101546 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101547 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
101548 }
101549 memcpy(&temp, pDup, sizeof(Expr));
101550 memcpy(pDup, pExpr, sizeof(Expr));
101551 memcpy(pExpr, &temp, sizeof(Expr));
 
 
 
 
 
 
 
 
 
 
 
 
 
101552 if( ExprHasProperty(pExpr, EP_WinFunc) ){
101553 if( ALWAYS(pExpr->y.pWin!=0) ){
101554 pExpr->y.pWin->pOwner = pExpr;
101555 }
101556 }
101557 sqlite3ParserAddCleanup(pParse,
101558 (void(*)(sqlite3*,void*))sqlite3ExprDelete,
101559 pDup);
101560 }
101561 }
101562
101563 /*
101564 ** Subqueries stores the original database, table and column names for their
@@ -137363,10 +137342,13 @@
137342 }
137343
137344 /*
137345 ** Return a pointer to a string containing the 'declaration type' of the
137346 ** expression pExpr. The string may be treated as static by the caller.
137347 **
137348 ** Also try to estimate the size of the returned value and return that
137349 ** result in *pEstWidth.
137350 **
137351 ** The declaration type is the exact datatype definition extracted from the
137352 ** original CREATE TABLE statement if the expression is a column. The
137353 ** declaration type for a ROWID field is INTEGER. Exactly when an expression
137354 ** is considered a column can be complex in the presence of subqueries. The
@@ -139609,12 +139591,11 @@
139591 **
139592 ** (3) If the subquery is the right operand of a LEFT JOIN then
139593 ** (3a) the subquery may not be a join and
139594 ** (3b) the FROM clause of the subquery may not contain a virtual
139595 ** table and
139596 ** (3c) the outer query may not be an aggregate.
 
139597 ** (3d) the outer query may not be DISTINCT.
139598 ** See also (26) for restrictions on RIGHT JOIN.
139599 **
139600 ** (4) The subquery can not be DISTINCT.
139601 **
@@ -139822,17 +139803,22 @@
139803 **
139804 ** (t1 LEFT OUTER JOIN t2) JOIN t3
139805 **
139806 ** which is not at all the same thing.
139807 **
139808 ** If the subquery is the right operand of a LEFT JOIN, then the outer
139809 ** query cannot be an aggregate. (3c) This is an artifact of the way
139810 ** aggregates are processed - there is no mechanism to determine if
139811 ** the LEFT JOIN table should be all-NULL.
139812 **
139813 ** See also tickets #306, #350, and #3300.
139814 */
139815 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
139816 if( pSubSrc->nSrc>1 /* (3a) */
139817 || isAgg /* (3c) */
139818 || IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
139819 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
 
139820 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
139821 ){
139822 return 0;
139823 }
139824 isOuterJoin = 1;
@@ -140747,11 +140733,10 @@
140733 if( p->pWhere
140734 || p->pEList->nExpr!=1
140735 || p->pSrc->nSrc!=1
140736 || p->pSrc->a[0].pSelect
140737 || pAggInfo->nFunc!=1
 
140738 ){
140739 return 0;
140740 }
140741 pTab = p->pSrc->a[0].pTab;
140742 assert( pTab!=0 );
@@ -156143,22 +156128,16 @@
156128 }
156129 }
156130 }
156131
156132 /*
156133 ** Deallocate internal memory used by a WhereLoop object
 
156134 */
156135 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
156136 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
 
 
 
 
156137 whereLoopClearUnion(db, p);
156138 whereLoopInit(p);
 
156139 }
156140
156141 /*
156142 ** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
156143 */
@@ -156178,13 +156157,11 @@
156157 /*
156158 ** Transfer content from the second pLoop into the first.
156159 */
156160 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
156161 whereLoopClearUnion(db, pTo);
156162 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
 
 
156163 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
156164 return SQLITE_NOMEM_BKPT;
156165 }
156166 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
156167 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
@@ -156833,15 +156810,11 @@
156810 pNew->wsFlags = saved_wsFlags;
156811 pNew->u.btree.nEq = saved_nEq;
156812 pNew->u.btree.nBtm = saved_nBtm;
156813 pNew->u.btree.nTop = saved_nTop;
156814 pNew->nLTerm = saved_nLTerm;
156815 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
 
 
 
 
156816 pNew->aLTerm[pNew->nLTerm++] = pTerm;
156817 pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
156818
156819 assert( nInMul==0
156820 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
@@ -156930,43 +156903,42 @@
156903 }
156904 }
156905 if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
156906 }else if( eOp & WO_ISNULL ){
156907 pNew->wsFlags |= WHERE_COLUMN_NULL;
156908 }else if( eOp & (WO_GT|WO_GE) ){
156909 testcase( eOp & WO_GT );
156910 testcase( eOp & WO_GE );
156911 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
156912 pNew->u.btree.nBtm = whereRangeVectorLen(
156913 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156914 );
156915 pBtm = pTerm;
156916 pTop = 0;
156917 if( pTerm->wtFlags & TERM_LIKEOPT ){
156918 /* Range constraints that come from the LIKE optimization are
156919 ** always used in pairs. */
156920 pTop = &pTerm[1];
156921 assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
156922 assert( pTop->wtFlags & TERM_LIKEOPT );
156923 assert( pTop->eOperator==WO_LT );
156924 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156925 pNew->aLTerm[pNew->nLTerm++] = pTop;
156926 pNew->wsFlags |= WHERE_TOP_LIMIT;
156927 pNew->u.btree.nTop = 1;
156928 }
156929 }else{
156930 assert( eOp & (WO_LT|WO_LE) );
156931 testcase( eOp & WO_LT );
156932 testcase( eOp & WO_LE );
156933 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
156934 pNew->u.btree.nTop = whereRangeVectorLen(
156935 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156936 );
156937 pTop = pTerm;
156938 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
156939 pNew->aLTerm[pNew->nLTerm-2] : 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156940 }
156941
156942 /* At this point pNew->nOut is set to the number of rows expected to
156943 ** be visited by the index scan before considering term pTerm, or the
156944 ** values of nIn and nInMul. In other words, assuming that all
@@ -158134,17 +158106,11 @@
158106 WhereLoop *pNew;
158107
158108
158109 /* Loop over the tables in the join, from left to right */
158110 pNew = pBuilder->pNew;
158111 whereLoopInit(pNew);
 
 
 
 
 
 
158112 pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
158113 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
158114 Bitmask mUnusable = 0;
158115 pNew->iTab = iTab;
158116 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
@@ -158737,13 +158703,13 @@
158703 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
158704 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
158705 LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
158706 LogEst rCost; /* Cost of path (pFrom+pWLoop) */
158707 LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
158708 i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */
158709 Bitmask maskNew; /* Mask of src visited by (..) */
158710 Bitmask revMask = 0; /* Mask of rev-order loops for (..) */
158711
158712 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
158713 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
158714 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
158715 /* Do not use an automatic index if the this loop is expected
@@ -158758,13 +158724,11 @@
158724 ** Compute its cost */
158725 rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
158726 rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
158727 nOut = pFrom->nRow + pWLoop->nOut;
158728 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
 
158729 if( isOrdered<0 ){
 
158730 isOrdered = wherePathSatisfiesOrderBy(pWInfo,
158731 pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
158732 iLoop, pWLoop, &revMask);
158733 }else{
158734 revMask = pFrom->revLoop;
@@ -212539,16 +212503,15 @@
212503 */
212504 static int dbpageBegin(sqlite3_vtab *pVtab){
212505 DbpageTable *pTab = (DbpageTable *)pVtab;
212506 sqlite3 *db = pTab->db;
212507 int i;
212508 for(i=0; i<db->nDb; i++){
 
212509 Btree *pBt = db->aDb[i].pBt;
212510 if( pBt ) sqlite3BtreeBeginTrans(pBt, 1, 0);
212511 }
212512 return SQLITE_OK;
212513 }
212514
212515
212516 /*
212517 ** Invoke this routine to register the "dbpage" virtual table module
@@ -236671,11 +236634,11 @@
236634 int nArg, /* Number of args */
236635 sqlite3_value **apUnused /* Function arguments */
236636 ){
236637 assert( nArg==0 );
236638 UNUSED_PARAM2(nArg, apUnused);
236639 sqlite3_result_text(pCtx, "fts5: 2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21", -1, SQLITE_TRANSIENT);
236640 }
236641
236642 /*
236643 ** Return true if zName is the extension on one of the shadow tables used
236644 ** by this module.
236645
--- 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.40.0"
150
-#define SQLITE_VERSION_NUMBER 3040000
151
-#define SQLITE_SOURCE_ID "2022-07-18 19:32:30 22d280a5cd395abbedcfffbac3d3b3a614c327be25763ca380c1338a2a7bd33a"
149
+#define SQLITE_VERSION "3.39.2"
150
+#define SQLITE_VERSION_NUMBER 3039002
151
+#define SQLITE_SOURCE_ID "2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- 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 **
157
--- 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.2"
150 #define SQLITE_VERSION_NUMBER 3039002
151 #define SQLITE_SOURCE_ID "2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

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