Fossil SCM

Update the built-in SQLite to the first 3.42.0 alpha version for testing.

drh 2023-05-01 20:43 trunk
Commit a6cc3da40c115de677ce7d74589c4d0fc24e94d80ecfb1c5df8216d4249ef756
3 files changed +505 -128 +2634 -1269 +49 -24
+505 -128
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -244,10 +244,11 @@
244244
245245
#if defined(_WIN32) || defined(WIN32)
246246
#if SQLITE_OS_WINRT
247247
#include <intrin.h>
248248
#endif
249
+#define WIN32_LEAN_AND_MEAN
249250
#include <windows.h>
250251
251252
/* string conversion routines only needed on Win32 */
252253
extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
253254
extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int);
@@ -458,14 +459,28 @@
458459
** at an error if we are not interactive.
459460
*/
460461
static int bail_on_error = 0;
461462
462463
/*
463
-** Threat stdin as an interactive input if the following variable
464
+** Treat stdin as an interactive input if the following variable
464465
** is true. Otherwise, assume stdin is connected to a file or pipe.
465466
*/
466467
static int stdin_is_interactive = 1;
468
+
469
+#if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE \
470
+ && !defined(SHELL_OMIT_WIN_UTF8)
471
+# define SHELL_WIN_UTF8_OPT 1
472
+#else
473
+# define SHELL_WIN_UTF8_OPT 0
474
+#endif
475
+
476
+#if SHELL_WIN_UTF8_OPT
477
+/*
478
+** Setup console for UTF-8 input/output when following variable true.
479
+*/
480
+static int console_utf8 = 0;
481
+#endif
467482
468483
/*
469484
** On Windows systems we have to know if standard output is a console
470485
** in order to translate UTF-8 into MBCS. The following variable is
471486
** true if translation is required.
@@ -595,20 +610,150 @@
595610
}
596611
return dynPrompt.dynamicPrompt;
597612
}
598613
#endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
599614
615
+#if SHELL_WIN_UTF8_OPT
616
+/* Following struct is used for -utf8 operation. */
617
+static struct ConsoleState {
618
+ int stdinEof; /* EOF has been seen on console input */
619
+ int infsMode; /* Input file stream mode upon shell start */
620
+ UINT inCodePage; /* Input code page upon shell start */
621
+ UINT outCodePage; /* Output code page upon shell start */
622
+ HANDLE hConsoleIn; /* Console input handle */
623
+ DWORD consoleMode; /* Console mode upon shell start */
624
+} conState = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
625
+
626
+/*
627
+** Prepare console, (if known to be a WIN32 console), for UTF-8
628
+** input (from either typing or suitable paste operations) and for
629
+** UTF-8 rendering. This may "fail" with a message to stderr, where
630
+** the preparation is not done and common "code page" issues occur.
631
+*/
632
+static void console_prepare(void){
633
+ HANDLE hCI = GetStdHandle(STD_INPUT_HANDLE);
634
+ DWORD consoleMode = 0;
635
+ if( isatty(0) && GetFileType(hCI)==FILE_TYPE_CHAR
636
+ && GetConsoleMode( hCI, &consoleMode) ){
637
+ if( !IsValidCodePage(CP_UTF8) ){
638
+ fprintf(stderr, "Cannot use UTF-8 code page.\n");
639
+ console_utf8 = 0;
640
+ return;
641
+ }
642
+ conState.hConsoleIn = hCI;
643
+ conState.consoleMode = consoleMode;
644
+ conState.inCodePage = GetConsoleCP();
645
+ conState.outCodePage = GetConsoleOutputCP();
646
+ SetConsoleCP(CP_UTF8);
647
+ SetConsoleOutputCP(CP_UTF8);
648
+ consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
649
+ SetConsoleMode(conState.hConsoleIn, consoleMode);
650
+ conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
651
+ console_utf8 = 1;
652
+ }else{
653
+ console_utf8 = 0;
654
+ }
655
+}
656
+
657
+/*
658
+** Undo the effects of console_prepare(), if any.
659
+*/
660
+static void SQLITE_CDECL console_restore(void){
661
+ if( console_utf8 && conState.inCodePage!=0
662
+ && conState.hConsoleIn!=INVALID_HANDLE_VALUE ){
663
+ _setmode(_fileno(stdin), conState.infsMode);
664
+ SetConsoleCP(conState.inCodePage);
665
+ SetConsoleOutputCP(conState.outCodePage);
666
+ SetConsoleMode(conState.hConsoleIn, conState.consoleMode);
667
+ /* Avoid multiple calls. */
668
+ conState.hConsoleIn = INVALID_HANDLE_VALUE;
669
+ conState.consoleMode = 0;
670
+ console_utf8 = 0;
671
+ }
672
+}
673
+
674
+/*
675
+** Collect input like fgets(...) with special provisions for input
676
+** from the Windows console to get around its strange coding issues.
677
+** Defers to plain fgets() when input is not interactive or when the
678
+** startup option, -utf8, has not been provided or taken effect.
679
+*/
680
+static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
681
+ if( fin==0 ) fin = stdin;
682
+ if( fin==stdin && stdin_is_interactive && console_utf8 ){
683
+# define SQLITE_IALIM 150
684
+ wchar_t wbuf[SQLITE_IALIM];
685
+ int lend = 0;
686
+ int noc = 0;
687
+ if( ncmax==0 || conState.stdinEof ) return 0;
688
+ buf[0] = 0;
689
+ while( noc<ncmax-7-1 && !lend ){
690
+ /* There is room for at least 2 more characters and a 0-terminator. */
691
+ int na = (ncmax > SQLITE_IALIM*4+1 + noc)
692
+ ? SQLITE_IALIM : (ncmax-1 - noc)/4;
693
+# undef SQLITE_IALIM
694
+ DWORD nbr = 0;
695
+ BOOL bRC = ReadConsoleW(conState.hConsoleIn, wbuf, na, &nbr, 0);
696
+ if( !bRC || (noc==0 && nbr==0) ) return 0;
697
+ if( nbr > 0 ){
698
+ int nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
699
+ wbuf,nbr,0,0,0,0);
700
+ if( nmb !=0 && noc+nmb <= ncmax ){
701
+ int iseg = noc;
702
+ nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
703
+ wbuf,nbr,buf+noc,nmb,0,0);
704
+ noc += nmb;
705
+ /* Fixup line-ends as coded by Windows for CR (or "Enter".)*/
706
+ if( noc > 0 ){
707
+ if( buf[noc-1]=='\n' ){
708
+ lend = 1;
709
+ if( noc > 1 && buf[noc-2]=='\r' ){
710
+ buf[noc-2] = '\n';
711
+ --noc;
712
+ }
713
+ }
714
+ }
715
+ /* Check for ^Z (anywhere in line) too. */
716
+ while( iseg < noc ){
717
+ if( buf[iseg]==0x1a ){
718
+ conState.stdinEof = 1;
719
+ noc = iseg; /* Chop ^Z and anything following. */
720
+ break;
721
+ }
722
+ ++iseg;
723
+ }
724
+ }else break; /* Drop apparent garbage in. (Could assert.) */
725
+ }else break;
726
+ }
727
+ /* If got nothing, (after ^Z chop), must be at end-of-file. */
728
+ if( noc == 0 ) return 0;
729
+ buf[noc] = 0;
730
+ return buf;
731
+ }else{
732
+ return fgets(buf, ncmax, fin);
733
+ }
734
+}
735
+
736
+# define fgets(b,n,f) utf8_fgets(b,n,f)
737
+#endif /* SHELL_WIN_UTF8_OPT */
738
+
600739
/*
601740
** Render output like fprintf(). Except, if the output is going to the
602
-** console and if this is running on a Windows machine, translate the
603
-** output from UTF-8 into MBCS.
741
+** console and if this is running on a Windows machine, and if the -utf8
742
+** option is unavailable or (available and inactive), translate the
743
+** output from UTF-8 into MBCS for output through 8-bit stdout stream.
744
+** (With -utf8 active, no translation is needed and must not be done.)
604745
*/
605746
#if defined(_WIN32) || defined(WIN32)
606747
void utf8_printf(FILE *out, const char *zFormat, ...){
607748
va_list ap;
608749
va_start(ap, zFormat);
609
- if( stdout_is_console && (out==stdout || out==stderr) ){
750
+ if( stdout_is_console && (out==stdout || out==stderr)
751
+# if SHELL_WIN_UTF8_OPT
752
+ && !console_utf8
753
+# endif
754
+ ){
610755
char *z1 = sqlite3_vmprintf(zFormat, ap);
611756
char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0);
612757
sqlite3_free(z1);
613758
fputs(z2, out);
614759
sqlite3_free(z2);
@@ -636,11 +781,11 @@
636781
}
637782
638783
/* Check a pointer to see if it is NULL. If it is NULL, exit with an
639784
** out-of-memory error.
640785
*/
641
-static void shell_check_oom(void *p){
786
+static void shell_check_oom(const void *p){
642787
if( p==0 ) shell_out_of_memory();
643788
}
644789
645790
/*
646791
** Write I/O traces to the following stream.
@@ -815,13 +960,18 @@
815960
zLine[n] = 0;
816961
break;
817962
}
818963
}
819964
#if defined(_WIN32) || defined(WIN32)
820
- /* For interactive input on Windows systems, translate the
821
- ** multi-byte characterset characters into UTF-8. */
822
- if( stdin_is_interactive && in==stdin ){
965
+ /* For interactive input on Windows systems, without -utf8,
966
+ ** translate the multi-byte characterset characters into UTF-8.
967
+ ** This is the translation that predates the -utf8 option. */
968
+ if( stdin_is_interactive && in==stdin
969
+# if SHELL_WIN_UTF8_OPT
970
+ && !console_utf8
971
+# endif /* SHELL_WIN_UTF8_OPT */
972
+ ){
823973
char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
824974
if( zTrans ){
825975
i64 nTrans = strlen(zTrans)+1;
826976
if( nTrans>nLine ){
827977
zLine = realloc(zLine, nTrans);
@@ -858,14 +1008,24 @@
8581008
}else{
8591009
zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
8601010
#if SHELL_USE_LOCAL_GETLINE
8611011
printf("%s", zPrompt);
8621012
fflush(stdout);
863
- zResult = local_getline(zPrior, stdin);
1013
+ do{
1014
+ zResult = local_getline(zPrior, stdin);
1015
+ /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
1016
+ if( zResult==0 ) sqlite3_sleep(50);
1017
+ }while( zResult==0 && seenInterrupt>0 );
8641018
#else
8651019
free(zPrior);
8661020
zResult = shell_readline(zPrompt);
1021
+ while( zResult==0 ){
1022
+ /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
1023
+ sqlite3_sleep(50);
1024
+ if( seenInterrupt==0 ) break;
1025
+ zResult = shell_readline("");
1026
+ }
8671027
if( zResult && *zResult ) shell_add_history(zResult);
8681028
#endif
8691029
}
8701030
return zResult;
8711031
}
@@ -1644,11 +1804,12 @@
16441804
** May you find forgiveness for yourself and forgive others.
16451805
** May you share freely, never taking more than you give.
16461806
**
16471807
******************************************************************************
16481808
**
1649
-** This SQLite extension implements functions that compute SHA3 hashes.
1809
+** This SQLite extension implements functions that compute SHA3 hashes
1810
+** in the way described by the (U.S.) NIST FIPS 202 SHA-3 Standard.
16501811
** Two SQL functions are implemented:
16511812
**
16521813
** sha3(X,SIZE)
16531814
** sha3_query(Y,SIZE)
16541815
**
@@ -3244,22 +3405,22 @@
32443405
*pOut = 0;
32453406
return pOut;
32463407
}
32473408
32483409
/* Skip over text which is not base64 numeral(s). */
3249
-static char * skipNonB64( char *s ){
3410
+static char * skipNonB64( char *s, int nc ){
32503411
char c;
3251
- while( (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
3412
+ while( nc-- > 0 && (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
32523413
return s;
32533414
}
32543415
32553416
/* Decode base64 text into a byte buffer. */
32563417
static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
32573418
if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
32583419
while( ncIn>0 && *pIn!=PAD_CHAR ){
32593420
static signed char nboi[] = { 0, 0, 1, 2, 3 };
3260
- char *pUse = skipNonB64(pIn);
3421
+ char *pUse = skipNonB64(pIn, ncIn);
32613422
unsigned long qv = 0L;
32623423
int nti, nbo, nac;
32633424
ncIn -= (pUse - pIn);
32643425
pIn = pUse;
32653426
nti = (ncIn>4)? 4 : ncIn;
@@ -3314,14 +3475,21 @@
33143475
nc = 4*(nv+2/3); /* quads needed */
33153476
nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
33163477
if( nvMax < nc ){
33173478
sqlite3_result_error(context, "blob expanded to base64 too big", -1);
33183479
return;
3480
+ }
3481
+ bBuf = (u8*)sqlite3_value_blob(av[0]);
3482
+ if( !bBuf ){
3483
+ if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
3484
+ goto memFail;
3485
+ }
3486
+ sqlite3_result_text(context,"",-1,SQLITE_STATIC);
3487
+ break;
33193488
}
33203489
cBuf = sqlite3_malloc(nc);
33213490
if( !cBuf ) goto memFail;
3322
- bBuf = (u8*)sqlite3_value_blob(av[0]);
33233491
nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
33243492
sqlite3_result_text(context, cBuf, nc, sqlite3_free);
33253493
break;
33263494
case SQLITE_TEXT:
33273495
nc = nv;
@@ -3329,14 +3497,21 @@
33293497
if( nvMax < nb ){
33303498
sqlite3_result_error(context, "blob from base64 may be too big", -1);
33313499
return;
33323500
}else if( nb<1 ){
33333501
nb = 1;
3502
+ }
3503
+ cBuf = (char *)sqlite3_value_text(av[0]);
3504
+ if( !cBuf ){
3505
+ if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
3506
+ goto memFail;
3507
+ }
3508
+ sqlite3_result_zeroblob(context, 0);
3509
+ break;
33343510
}
33353511
bBuf = sqlite3_malloc(nb);
33363512
if( !bBuf ) goto memFail;
3337
- cBuf = (char *)sqlite3_value_text(av[0]);
33383513
nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
33393514
sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
33403515
break;
33413516
default:
33423517
sqlite3_result_error(context, "base64 accepts only blob or text", -1);
@@ -3520,13 +3695,13 @@
35203695
35213696
/* Width of base64 lines. Should be an integer multiple of 5. */
35223697
#define B85_DARK_MAX 80
35233698
35243699
3525
-static char * skipNonB85( char *s ){
3700
+static char * skipNonB85( char *s, int nc ){
35263701
char c;
3527
- while( (c = *s) && !IS_B85(c) ) ++s;
3702
+ while( nc-- > 0 && (c = *s) && !IS_B85(c) ) ++s;
35283703
return s;
35293704
}
35303705
35313706
/* Convert small integer, known to be in 0..84 inclusive, to base85 numeral.
35323707
* Do not use the macro form with argument expression having a side-effect.*/
@@ -3592,11 +3767,11 @@
35923767
/* Decode base85 text into a byte buffer. */
35933768
static u8* fromBase85( char *pIn, int ncIn, u8 *pOut ){
35943769
if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
35953770
while( ncIn>0 ){
35963771
static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
3597
- char *pUse = skipNonB85(pIn);
3772
+ char *pUse = skipNonB85(pIn, ncIn);
35983773
unsigned long qv = 0L;
35993774
int nti, nbo;
36003775
ncIn -= (pUse - pIn);
36013776
pIn = pUse;
36023777
nti = (ncIn>5)? 5 : ncIn;
@@ -3676,14 +3851,21 @@
36763851
/* ulongs tail newlines tailenc+nul*/
36773852
nc = 5*(nv/4) + nv%4 + nv/64+1 + 2;
36783853
if( nvMax < nc ){
36793854
sqlite3_result_error(context, "blob expanded to base85 too big", -1);
36803855
return;
3856
+ }
3857
+ bBuf = (u8*)sqlite3_value_blob(av[0]);
3858
+ if( !bBuf ){
3859
+ if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
3860
+ goto memFail;
3861
+ }
3862
+ sqlite3_result_text(context,"",-1,SQLITE_STATIC);
3863
+ break;
36813864
}
36823865
cBuf = sqlite3_malloc(nc);
36833866
if( !cBuf ) goto memFail;
3684
- bBuf = (u8*)sqlite3_value_blob(av[0]);
36853867
nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
36863868
sqlite3_result_text(context, cBuf, nc, sqlite3_free);
36873869
break;
36883870
case SQLITE_TEXT:
36893871
nc = nv;
@@ -3691,14 +3873,21 @@
36913873
if( nvMax < nb ){
36923874
sqlite3_result_error(context, "blob from base85 may be too big", -1);
36933875
return;
36943876
}else if( nb<1 ){
36953877
nb = 1;
3878
+ }
3879
+ cBuf = (char *)sqlite3_value_text(av[0]);
3880
+ if( !cBuf ){
3881
+ if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
3882
+ goto memFail;
3883
+ }
3884
+ sqlite3_result_zeroblob(context, 0);
3885
+ break;
36963886
}
36973887
bBuf = sqlite3_malloc(nb);
36983888
if( !bBuf ) goto memFail;
3699
- cBuf = (char *)sqlite3_value_text(av[0]);
37003889
nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
37013890
sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
37023891
break;
37033892
default:
37043893
sqlite3_result_error(context, "base85 accepts only blob or text.", -1);
@@ -4114,11 +4303,11 @@
41144303
}
41154304
41164305
/************************* End ../ext/misc/ieee754.c ********************/
41174306
/************************* Begin ../ext/misc/series.c ******************/
41184307
/*
4119
-** 2015-08-18
4308
+** 2015-08-18, 2023-04-28
41204309
**
41214310
** The author disclaims copyright to this source code. In place of
41224311
** a legal notice, here is a blessing:
41234312
**
41244313
** May you do good and not evil.
@@ -4127,11 +4316,23 @@
41274316
**
41284317
*************************************************************************
41294318
**
41304319
** This file demonstrates how to create a table-valued-function using
41314320
** a virtual table. This demo implements the generate_series() function
4132
-** which gives similar results to the eponymous function in PostgreSQL.
4321
+** which gives the same results as the eponymous function in PostgreSQL,
4322
+** within the limitation that its arguments are signed 64-bit integers.
4323
+**
4324
+** Considering its equivalents to generate_series(start,stop,step): A
4325
+** value V[n] sequence is produced for integer n ascending from 0 where
4326
+** ( V[n] == start + n * step && sgn(V[n] - stop) * sgn(step) >= 0 )
4327
+** for each produced value (independent of production time ordering.)
4328
+**
4329
+** All parameters must be either integer or convertable to integer.
4330
+** The start parameter is required.
4331
+** The stop parameter defaults to (1<<32)-1 (aka 4294967295 or 0xffffffff)
4332
+** The step parameter defaults to 1 and 0 is treated as 1.
4333
+**
41334334
** Examples:
41344335
**
41354336
** SELECT * FROM generate_series(0,100,5);
41364337
**
41374338
** The query above returns integers from 0 through 100 counting by steps
@@ -4143,10 +4344,18 @@
41434344
**
41444345
** SELECT * FROM generate_series(20) LIMIT 10;
41454346
**
41464347
** Integers 20 through 29.
41474348
**
4349
+** SELECT * FROM generate_series(0,-100,-5);
4350
+**
4351
+** Integers 0 -5 -10 ... -100.
4352
+**
4353
+** SELECT * FROM generate_series(0,-1);
4354
+**
4355
+** Empty sequence.
4356
+**
41484357
** HOW IT WORKS
41494358
**
41504359
** The generate_series "function" is really a virtual table with the
41514360
** following schema:
41524361
**
@@ -4154,10 +4363,13 @@
41544363
** value,
41554364
** start HIDDEN,
41564365
** stop HIDDEN,
41574366
** step HIDDEN
41584367
** );
4368
+**
4369
+** The virtual table also has a rowid, logically equivalent to n+1 where
4370
+** "n" is the ascending integer in the aforesaid production definition.
41594371
**
41604372
** Function arguments in queries against this virtual table are translated
41614373
** into equality constraints against successive hidden columns. In other
41624374
** words, the following pairs of queries are equivalent to each other:
41634375
**
@@ -4187,27 +4399,109 @@
41874399
*/
41884400
/* #include "sqlite3ext.h" */
41894401
SQLITE_EXTENSION_INIT1
41904402
#include <assert.h>
41914403
#include <string.h>
4404
+#include <limits.h>
41924405
41934406
#ifndef SQLITE_OMIT_VIRTUALTABLE
4407
+/*
4408
+** Return that member of a generate_series(...) sequence whose 0-based
4409
+** index is ix. The 0th member is given by smBase. The sequence members
4410
+** progress per ix increment by smStep.
4411
+*/
4412
+static sqlite3_int64 genSeqMember(sqlite3_int64 smBase,
4413
+ sqlite3_int64 smStep,
4414
+ sqlite3_uint64 ix){
4415
+ if( ix>=(sqlite3_uint64)LLONG_MAX ){
4416
+ /* Get ix into signed i64 range. */
4417
+ ix -= (sqlite3_uint64)LLONG_MAX;
4418
+ smBase += LLONG_MAX * smStep;
4419
+ }
4420
+ return smBase + ((sqlite3_int64)ix)*smStep;
4421
+}
41944422
4423
+/* typedef unsigned char u8; */
4424
+
4425
+typedef struct SequenceSpec {
4426
+ sqlite3_int64 iBase; /* Starting value ("start") */
4427
+ sqlite3_int64 iTerm; /* Given terminal value ("stop") */
4428
+ sqlite3_int64 iStep; /* Increment ("step") */
4429
+ sqlite3_uint64 uSeqIndexMax; /* maximum sequence index (aka "n") */
4430
+ sqlite3_uint64 uSeqIndexNow; /* Current index during generation */
4431
+ sqlite3_int64 iValueNow; /* Current value during generation */
4432
+ u8 isNotEOF; /* Sequence generation not exhausted */
4433
+ u8 isReversing; /* Sequence is being reverse generated */
4434
+} SequenceSpec;
4435
+
4436
+/*
4437
+** Prepare a SequenceSpec for use in generating an integer series
4438
+** given initialized iBase, iTerm and iStep values. Sequence is
4439
+** initialized per given isReversing. Other members are computed.
4440
+*/
4441
+void setupSequence( SequenceSpec *pss ){
4442
+ pss->uSeqIndexMax = 0;
4443
+ pss->isNotEOF = 0;
4444
+ if( pss->iTerm < pss->iBase ){
4445
+ sqlite3_uint64 nuspan = (sqlite3_uint64)(pss->iBase-pss->iTerm);
4446
+ if( pss->iStep<0 ){
4447
+ pss->isNotEOF = 1;
4448
+ if( nuspan==ULONG_MAX ){
4449
+ pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1;
4450
+ }else if( pss->iStep>LLONG_MIN ){
4451
+ pss->uSeqIndexMax = nuspan/-pss->iStep;
4452
+ }
4453
+ }
4454
+ }else if( pss->iTerm > pss->iBase ){
4455
+ sqlite3_uint64 puspan = (sqlite3_uint64)(pss->iTerm-pss->iBase);
4456
+ if( pss->iStep>0 ){
4457
+ pss->isNotEOF = 1;
4458
+ pss->uSeqIndexMax = puspan/pss->iStep;
4459
+ }
4460
+ }else if( pss->iTerm == pss->iBase ){
4461
+ pss->isNotEOF = 1;
4462
+ pss->uSeqIndexMax = 0;
4463
+ }
4464
+ pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0;
4465
+ pss->iValueNow = (pss->isReversing)
4466
+ ? genSeqMember(pss->iBase, pss->iStep, pss->uSeqIndexMax)
4467
+ : pss->iBase;
4468
+}
4469
+
4470
+/*
4471
+** Progress sequence generator to yield next value, if any.
4472
+** Leave its state to either yield next value or be at EOF.
4473
+** Return whether there is a next value, or 0 at EOF.
4474
+*/
4475
+int progressSequence( SequenceSpec *pss ){
4476
+ if( !pss->isNotEOF ) return 0;
4477
+ if( pss->isReversing ){
4478
+ if( pss->uSeqIndexNow > 0 ){
4479
+ pss->uSeqIndexNow--;
4480
+ pss->iValueNow -= pss->iStep;
4481
+ }else{
4482
+ pss->isNotEOF = 0;
4483
+ }
4484
+ }else{
4485
+ if( pss->uSeqIndexNow < pss->uSeqIndexMax ){
4486
+ pss->uSeqIndexNow++;
4487
+ pss->iValueNow += pss->iStep;
4488
+ }else{
4489
+ pss->isNotEOF = 0;
4490
+ }
4491
+ }
4492
+ return pss->isNotEOF;
4493
+}
41954494
41964495
/* series_cursor is a subclass of sqlite3_vtab_cursor which will
41974496
** serve as the underlying representation of a cursor that scans
41984497
** over rows of the result
41994498
*/
42004499
typedef struct series_cursor series_cursor;
42014500
struct series_cursor {
42024501
sqlite3_vtab_cursor base; /* Base class - must be first */
4203
- int isDesc; /* True to count down rather than up */
4204
- sqlite3_int64 iRowid; /* The rowid */
4205
- sqlite3_int64 iValue; /* Current value ("value") */
4206
- sqlite3_int64 mnValue; /* Mimimum value ("start") */
4207
- sqlite3_int64 mxValue; /* Maximum value ("stop") */
4208
- sqlite3_int64 iStep; /* Increment ("step") */
4502
+ SequenceSpec ss; /* (this) Derived class data */
42094503
};
42104504
42114505
/*
42124506
** The seriesConnect() method is invoked to create a new
42134507
** series_vtab that describes the generate_series virtual table.
@@ -4285,16 +4579,11 @@
42854579
/*
42864580
** Advance a series_cursor to its next row of output.
42874581
*/
42884582
static int seriesNext(sqlite3_vtab_cursor *cur){
42894583
series_cursor *pCur = (series_cursor*)cur;
4290
- if( pCur->isDesc ){
4291
- pCur->iValue -= pCur->iStep;
4292
- }else{
4293
- pCur->iValue += pCur->iStep;
4294
- }
4295
- pCur->iRowid++;
4584
+ progressSequence( & pCur->ss );
42964585
return SQLITE_OK;
42974586
}
42984587
42994588
/*
43004589
** Return values of columns for the row at which the series_cursor
@@ -4306,14 +4595,14 @@
43064595
int i /* Which column to return */
43074596
){
43084597
series_cursor *pCur = (series_cursor*)cur;
43094598
sqlite3_int64 x = 0;
43104599
switch( i ){
4311
- case SERIES_COLUMN_START: x = pCur->mnValue; break;
4312
- case SERIES_COLUMN_STOP: x = pCur->mxValue; break;
4313
- case SERIES_COLUMN_STEP: x = pCur->iStep; break;
4314
- default: x = pCur->iValue; break;
4600
+ case SERIES_COLUMN_START: x = pCur->ss.iBase; break;
4601
+ case SERIES_COLUMN_STOP: x = pCur->ss.iTerm; break;
4602
+ case SERIES_COLUMN_STEP: x = pCur->ss.iStep; break;
4603
+ default: x = pCur->ss.iValueNow; break;
43154604
}
43164605
sqlite3_result_int64(ctx, x);
43174606
return SQLITE_OK;
43184607
}
43194608
@@ -4322,28 +4611,24 @@
43224611
** first row returned is assigned rowid value 1, and each subsequent
43234612
** row a value 1 more than that of the previous.
43244613
*/
43254614
static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
43264615
series_cursor *pCur = (series_cursor*)cur;
4327
- *pRowid = pCur->iRowid;
4616
+ *pRowid = ((sqlite3_int64)pCur->ss.uSeqIndexNow + 1);
43284617
return SQLITE_OK;
43294618
}
43304619
43314620
/*
43324621
** Return TRUE if the cursor has been moved off of the last
43334622
** row of output.
43344623
*/
43354624
static int seriesEof(sqlite3_vtab_cursor *cur){
43364625
series_cursor *pCur = (series_cursor*)cur;
4337
- if( pCur->isDesc ){
4338
- return pCur->iValue < pCur->mnValue;
4339
- }else{
4340
- return pCur->iValue > pCur->mxValue;
4341
- }
4626
+ return !pCur->ss.isNotEOF;
43424627
}
43434628
4344
-/* True to cause run-time checking of the start=, stop=, and/or step=
4629
+/* True to cause run-time checking of the start=, stop=, and/or step=
43454630
** parameters. The only reason to do this is for testing the
43464631
** constraint checking logic for virtual tables in the SQLite core.
43474632
*/
43484633
#ifndef SQLITE_SERIES_CONSTRAINT_VERIFY
43494634
# define SQLITE_SERIES_CONSTRAINT_VERIFY 0
@@ -4350,11 +4635,11 @@
43504635
#endif
43514636
43524637
/*
43534638
** This method is called to "rewind" the series_cursor object back
43544639
** to the first row of output. This method is always called at least
4355
-** once prior to any call to seriesColumn() or seriesRowid() or
4640
+** once prior to any call to seriesColumn() or seriesRowid() or
43564641
** seriesEof().
43574642
**
43584643
** The query plan selected by seriesBestIndex is passed in the idxNum
43594644
** parameter. (idxStr is not used in this implementation.) idxNum
43604645
** is a bitmask showing which constraints are available:
@@ -4370,58 +4655,53 @@
43704655
** This routine should initialize the cursor and position it so that it
43714656
** is pointing at the first row, or pointing off the end of the table
43724657
** (so that seriesEof() will return true) if the table is empty.
43734658
*/
43744659
static int seriesFilter(
4375
- sqlite3_vtab_cursor *pVtabCursor,
4660
+ sqlite3_vtab_cursor *pVtabCursor,
43764661
int idxNum, const char *idxStrUnused,
43774662
int argc, sqlite3_value **argv
43784663
){
43794664
series_cursor *pCur = (series_cursor *)pVtabCursor;
43804665
int i = 0;
43814666
(void)idxStrUnused;
43824667
if( idxNum & 1 ){
4383
- pCur->mnValue = sqlite3_value_int64(argv[i++]);
4668
+ pCur->ss.iBase = sqlite3_value_int64(argv[i++]);
43844669
}else{
4385
- pCur->mnValue = 0;
4670
+ pCur->ss.iBase = 0;
43864671
}
43874672
if( idxNum & 2 ){
4388
- pCur->mxValue = sqlite3_value_int64(argv[i++]);
4673
+ pCur->ss.iTerm = sqlite3_value_int64(argv[i++]);
43894674
}else{
4390
- pCur->mxValue = 0xffffffff;
4675
+ pCur->ss.iTerm = 0xffffffff;
43914676
}
43924677
if( idxNum & 4 ){
4393
- pCur->iStep = sqlite3_value_int64(argv[i++]);
4394
- if( pCur->iStep==0 ){
4395
- pCur->iStep = 1;
4396
- }else if( pCur->iStep<0 ){
4397
- pCur->iStep = -pCur->iStep;
4678
+ pCur->ss.iStep = sqlite3_value_int64(argv[i++]);
4679
+ if( pCur->ss.iStep==0 ){
4680
+ pCur->ss.iStep = 1;
4681
+ }else if( pCur->ss.iStep<0 ){
43984682
if( (idxNum & 16)==0 ) idxNum |= 8;
43994683
}
44004684
}else{
4401
- pCur->iStep = 1;
4685
+ pCur->ss.iStep = 1;
44024686
}
44034687
for(i=0; i<argc; i++){
44044688
if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
44054689
/* If any of the constraints have a NULL value, then return no rows.
44064690
** See ticket https://www.sqlite.org/src/info/fac496b61722daf2 */
4407
- pCur->mnValue = 1;
4408
- pCur->mxValue = 0;
4691
+ pCur->ss.iBase = 1;
4692
+ pCur->ss.iTerm = 0;
4693
+ pCur->ss.iStep = 1;
44094694
break;
44104695
}
44114696
}
44124697
if( idxNum & 8 ){
4413
- pCur->isDesc = 1;
4414
- pCur->iValue = pCur->mxValue;
4415
- if( pCur->iStep>0 ){
4416
- pCur->iValue -= (pCur->mxValue - pCur->mnValue)%pCur->iStep;
4417
- }
4698
+ pCur->ss.isReversing = pCur->ss.iStep > 0;
44184699
}else{
4419
- pCur->isDesc = 0;
4420
- pCur->iValue = pCur->mnValue;
4700
+ pCur->ss.isReversing = pCur->ss.iStep < 0;
44214701
}
4422
- pCur->iRowid = 1;
4702
+ setupSequence( &pCur->ss );
44234703
return SQLITE_OK;
44244704
}
44254705
44264706
/*
44274707
** SQLite will invoke this method one or more times while planning a query
@@ -14576,11 +14856,11 @@
1457614856
pStmt = recoverPreparePrintf(p, p->dbOut, "PRAGMA index_xinfo(%Q)", zName);
1457714857
while( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
1457814858
int iField = sqlite3_column_int(pStmt, 0);
1457914859
int iCol = sqlite3_column_int(pStmt, 1);
1458014860
14581
- assert( iField<pNew->nCol && iCol<pNew->nCol );
14861
+ assert( iCol<pNew->nCol );
1458214862
pNew->aCol[iCol].iField = iField;
1458314863
1458414864
pNew->bIntkey = 0;
1458514865
iPk = -2;
1458614866
}
@@ -16521,10 +16801,11 @@
1652116801
#define SHFLG_CountChanges 0x00000020 /* .changes setting */
1652216802
#define SHFLG_Echo 0x00000040 /* .echo on/off, or --echo setting */
1652316803
#define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
1652416804
#define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
1652516805
#define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
16806
+#define SHFLG_TestingMode 0x00000400 /* allow unsafe testing features */
1652616807
1652716808
/*
1652816809
** Macros for testing and setting shellFlgs
1652916810
*/
1653016811
#define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -16854,10 +17135,11 @@
1685417135
*/
1685517136
static void output_quoted_string(FILE *out, const char *z){
1685617137
int i;
1685717138
char c;
1685817139
setBinaryMode(out, 1);
17140
+ if( z==0 ) return;
1685917141
for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1686017142
if( c==0 ){
1686117143
utf8_printf(out,"'%s'",z);
1686217144
}else{
1686317145
raw_printf(out, "'");
@@ -16983,10 +17265,11 @@
1698317265
/*
1698417266
** Output the given string as a quoted according to JSON quoting rules.
1698517267
*/
1698617268
static void output_json_string(FILE *out, const char *z, i64 n){
1698717269
unsigned int c;
17270
+ if( z==0 ) z = "";
1698817271
if( n<0 ) n = strlen(z);
1698917272
fputc('"', out);
1699017273
while( n-- ){
1699117274
c = *(z++);
1699217275
if( c=='\\' || c=='"' ){
@@ -17107,12 +17390,11 @@
1710717390
/*
1710817391
** This routine runs when the user presses Ctrl-C
1710917392
*/
1711017393
static void interrupt_handler(int NotUsed){
1711117394
UNUSED_PARAMETER(NotUsed);
17112
- seenInterrupt++;
17113
- if( seenInterrupt>2 ) exit(1);
17395
+ if( ++seenInterrupt>1 ) exit(1);
1711417396
if( globalDb ) sqlite3_interrupt(globalDb);
1711517397
}
1711617398
1711717399
#if (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
1711817400
/*
@@ -18559,14 +18841,18 @@
1855918841
zVar = zNum;
1856018842
}
1856118843
sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
1856218844
if( rc==SQLITE_OK && pQ && sqlite3_step(pQ)==SQLITE_ROW ){
1856318845
sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
18846
+#ifdef NAN
1856418847
}else if( sqlite3_strlike("_NAN", zVar, 0)==0 ){
1856518848
sqlite3_bind_double(pStmt, i, NAN);
18849
+#endif
18850
+#ifdef INFINITY
1856618851
}else if( sqlite3_strlike("_INF", zVar, 0)==0 ){
1856718852
sqlite3_bind_double(pStmt, i, INFINITY);
18853
+#endif
1856818854
}else{
1856918855
sqlite3_bind_null(pStmt, i);
1857018856
}
1857118857
sqlite3_reset(pQ);
1857218858
}
@@ -18806,11 +19092,11 @@
1880619092
nAlloc = nColumn*4;
1880719093
if( nAlloc<=0 ) nAlloc = 1;
1880819094
azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
1880919095
shell_check_oom(azData);
1881019096
azNextLine = sqlite3_malloc64( nColumn*sizeof(char*) );
18811
- shell_check_oom((void*)azNextLine);
19097
+ shell_check_oom(azNextLine);
1881219098
memset((void*)azNextLine, 0, nColumn*sizeof(char*) );
1881319099
if( p->cmOpts.bQuote ){
1881419100
azQuoted = sqlite3_malloc64( nColumn*sizeof(char*) );
1881519101
shell_check_oom(azQuoted);
1881619102
memset(azQuoted, 0, nColumn*sizeof(char*) );
@@ -18836,10 +19122,11 @@
1883619122
if( wx==0 ){
1883719123
wx = p->cmOpts.iWrap;
1883819124
}
1883919125
if( wx<0 ) wx = -wx;
1884019126
uz = (const unsigned char*)sqlite3_column_name(pStmt,i);
19127
+ if( uz==0 ) uz = (u8*)"";
1884119128
azData[i] = translateForDisplayAndDup(uz, &zNotUsed, wx, bw);
1884219129
}
1884319130
do{
1884419131
int useNextLine = bNextLine;
1884519132
bNextLine = 0;
@@ -19769,17 +20056,17 @@
1976920056
" from the \".mode\" output mode",
1977020057
" * If FILE begins with \"|\" then it is a command that generates the",
1977120058
" input text.",
1977220059
#endif
1977320060
#ifndef SQLITE_OMIT_TEST_CONTROL
19774
- ".imposter INDEX TABLE Create imposter table TABLE on index INDEX",
20061
+ ",imposter INDEX TABLE Create imposter table TABLE on index INDEX",
1977520062
#endif
1977620063
".indexes ?TABLE? Show names of indexes",
1977720064
" If TABLE is specified, only show indexes for",
1977820065
" tables matching TABLE using the LIKE operator.",
1977920066
#ifdef SQLITE_ENABLE_IOTRACE
19780
- ".iotrace FILE Enable I/O diagnostic logging to FILE",
20067
+ ",iotrace FILE Enable I/O diagnostic logging to FILE",
1978120068
#endif
1978220069
".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
1978320070
".lint OPTIONS Report potential schema issues.",
1978420071
" Options:",
1978520072
" fkey-indexes Find missing foreign key indexes",
@@ -19884,11 +20171,11 @@
1988420171
".scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off",
1988520172
".schema ?PATTERN? Show the CREATE statements matching PATTERN",
1988620173
" Options:",
1988720174
" --indent Try to pretty-print the schema",
1988820175
" --nosys Omit objects whose names start with \"sqlite_\"",
19889
- ".selftest ?OPTIONS? Run tests defined in the SELFTEST table",
20176
+ ",selftest ?OPTIONS? Run tests defined in the SELFTEST table",
1989020177
" Options:",
1989120178
" --init Create a new SELFTEST table",
1989220179
" -v Verbose output",
1989320180
".separator COL ?ROW? Change the column and row separators",
1989420181
#if defined(SQLITE_ENABLE_SESSION)
@@ -19926,13 +20213,13 @@
1992620213
#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
1992720214
".system CMD ARGS... Run CMD ARGS... in a system shell",
1992820215
#endif
1992920216
".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
1993020217
#ifndef SQLITE_SHELL_FIDDLE
19931
- ".testcase NAME Begin redirecting output to 'testcase-out.txt'",
20218
+ ",testcase NAME Begin redirecting output to 'testcase-out.txt'",
1993220219
#endif
19933
- ".testctrl CMD ... Run various sqlite3_test_control() operations",
20220
+ ",testctrl CMD ... Run various sqlite3_test_control() operations",
1993420221
" Run \".testctrl\" with no arguments for details",
1993520222
".timeout MS Try opening locked tables for MS milliseconds",
1993620223
".timer on|off Turn SQL timer on or off",
1993720224
#ifndef SQLITE_OMIT_TRACE
1993820225
".trace ?OPTIONS? Output each SQL statement as it is run",
@@ -19980,20 +20267,45 @@
1998020267
|| zPattern[0]=='0'
1998120268
|| cli_strcmp(zPattern,"-a")==0
1998220269
|| cli_strcmp(zPattern,"-all")==0
1998320270
|| cli_strcmp(zPattern,"--all")==0
1998420271
){
19985
- /* Show all commands, but only one line per command */
19986
- if( zPattern==0 ) zPattern = "";
20272
+ enum HelpWanted { HW_NoCull = 0, HW_SummaryOnly = 1, HW_Undoc = 2 };
20273
+ enum HelpHave { HH_Undoc = 2, HH_Summary = 1, HH_More = 0 };
20274
+ /* Show all or most commands
20275
+ ** *zPattern==0 => summary of documented commands only
20276
+ ** *zPattern=='0' => whole help for undocumented commands
20277
+ ** Otherwise => whole help for documented commands
20278
+ */
20279
+ enum HelpWanted hw = HW_SummaryOnly;
20280
+ enum HelpHave hh = HH_More;
20281
+ if( zPattern!=0 ){
20282
+ hw = (*zPattern=='0')? HW_NoCull|HW_Undoc : HW_NoCull;
20283
+ }
1998720284
for(i=0; i<ArraySize(azHelp); i++){
19988
- if( azHelp[i][0]=='.' || zPattern[0] ){
19989
- utf8_printf(out, "%s\n", azHelp[i]);
19990
- n++;
20285
+ switch( azHelp[i][0] ){
20286
+ case ',':
20287
+ hh = HH_Summary|HH_Undoc;
20288
+ break;
20289
+ case '.':
20290
+ hh = HH_Summary;
20291
+ break;
20292
+ default:
20293
+ hh &= ~HH_Summary;
20294
+ break;
20295
+ }
20296
+ if( ((hw^hh)&HH_Undoc)==0 ){
20297
+ if( (hh&HH_Summary)!=0 ){
20298
+ utf8_printf(out, ".%s\n", azHelp[i]+1);
20299
+ ++n;
20300
+ }else if( (hw&HW_SummaryOnly)==0 ){
20301
+ utf8_printf(out, "%s\n", azHelp[i]);
20302
+ }
1999120303
}
1999220304
}
1999320305
}else{
19994
- /* Look for commands that for which zPattern is an exact prefix */
20306
+ /* Seek documented commands for which zPattern is an exact prefix */
1999520307
zPat = sqlite3_mprintf(".%s*", zPattern);
1999620308
shell_check_oom(zPat);
1999720309
for(i=0; i<ArraySize(azHelp); i++){
1999820310
if( sqlite3_strglob(zPat, azHelp[i])==0 ){
1999920311
utf8_printf(out, "%s\n", azHelp[i]);
@@ -20002,28 +20314,32 @@
2000220314
}
2000320315
}
2000420316
sqlite3_free(zPat);
2000520317
if( n ){
2000620318
if( n==1 ){
20007
- /* when zPattern is a prefix of exactly one command, then include the
20008
- ** details of that command, which should begin at offset j */
20009
- while( j<ArraySize(azHelp)-1 && azHelp[j][0]!='.' ){
20319
+ /* when zPattern is a prefix of exactly one command, then include
20320
+ ** the details of that command, which should begin at offset j */
20321
+ while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){
2001020322
utf8_printf(out, "%s\n", azHelp[j]);
2001120323
j++;
2001220324
}
2001320325
}
2001420326
return n;
2001520327
}
20016
- /* Look for commands that contain zPattern anywhere. Show the complete
20017
- ** text of all commands that match. */
20328
+ /* Look for documented commands that contain zPattern anywhere.
20329
+ ** Show complete text of all documented commands that match. */
2001820330
zPat = sqlite3_mprintf("%%%s%%", zPattern);
2001920331
shell_check_oom(zPat);
2002020332
for(i=0; i<ArraySize(azHelp); i++){
20333
+ if( azHelp[i][0]==',' ){
20334
+ while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i;
20335
+ continue;
20336
+ }
2002120337
if( azHelp[i][0]=='.' ) j = i;
2002220338
if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
2002320339
utf8_printf(out, "%s\n", azHelp[j]);
20024
- while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]!='.' ){
20340
+ while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){
2002520341
j++;
2002620342
utf8_printf(out, "%s\n", azHelp[j]);
2002720343
}
2002820344
i = j;
2002920345
n++;
@@ -20344,10 +20660,17 @@
2034420660
return;
2034520661
}
2034620662
exit(1);
2034720663
}
2034820664
sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0);
20665
+
20666
+ /* Reflect the use or absence of --unsafe-testing invocation. */
20667
+ {
20668
+ int testmode_on = ShellHasFlag(p,SHFLG_TestingMode);
20669
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, testmode_on,0);
20670
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, !testmode_on,0);
20671
+ }
2034920672
2035020673
#ifndef SQLITE_OMIT_LOAD_EXTENSION
2035120674
sqlite3_enable_load_extension(p->db, 1);
2035220675
#endif
2035320676
sqlite3_shathree_init(p->db, 0, 0);
@@ -20677,11 +21000,11 @@
2067721000
if( p->traceOut==0 ) return 0;
2067821001
if( mType==SQLITE_TRACE_CLOSE ){
2067921002
utf8_printf(p->traceOut, "-- closing database connection\n");
2068021003
return 0;
2068121004
}
20682
- if( mType!=SQLITE_TRACE_ROW && ((const char*)pX)[0]=='-' ){
21005
+ if( mType!=SQLITE_TRACE_ROW && pX!=0 && ((const char*)pX)[0]=='-' ){
2068321006
zSql = (const char*)pX;
2068421007
}else{
2068521008
pStmt = (sqlite3_stmt*)pP;
2068621009
switch( p->eTraceType ){
2068721010
case SHELL_TRACE_EXPANDED: {
@@ -20709,11 +21032,11 @@
2070921032
case SQLITE_TRACE_STMT: {
2071021033
utf8_printf(p->traceOut, "%.*s;\n", (int)nSql, zSql);
2071121034
break;
2071221035
}
2071321036
case SQLITE_TRACE_PROFILE: {
20714
- sqlite3_int64 nNanosec = *(sqlite3_int64*)pX;
21037
+ sqlite3_int64 nNanosec = pX ? *(sqlite3_int64*)pX : 0;
2071521038
utf8_printf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec);
2071621039
break;
2071721040
}
2071821041
}
2071921042
return 0;
@@ -21237,11 +21560,13 @@
2123721560
}
2123821561
sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
2123921562
if( sqlite3_step(pStmt)==SQLITE_ROW
2124021563
&& sqlite3_column_bytes(pStmt,0)>100
2124121564
){
21242
- memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
21565
+ const u8 *pb = sqlite3_column_blob(pStmt,0);
21566
+ shell_check_oom(pb);
21567
+ memcpy(aHdr, pb, 100);
2124321568
sqlite3_finalize(pStmt);
2124421569
}else{
2124521570
raw_printf(stderr, "unable to read database header\n");
2124621571
sqlite3_finalize(pStmt);
2124721572
return 1;
@@ -22054,11 +22379,14 @@
2205422379
if( arProcessSwitch(pAr, pMatch->eSwitch, zArg) ) return SQLITE_ERROR;
2205522380
}
2205622381
}
2205722382
}
2205822383
}
22059
-
22384
+ if( pAr->eCmd==0 ){
22385
+ utf8_printf(stderr, "Required argument missing. Usage:\n");
22386
+ return arUsage(stderr);
22387
+ }
2206022388
return SQLITE_OK;
2206122389
}
2206222390
2206322391
/*
2206422392
** This function assumes that all arguments within the ArCommand.azArg[]
@@ -23949,10 +24277,16 @@
2394924277
sqlite3_stmt *pStmt;
2395024278
int tnum = 0;
2395124279
int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
2395224280
int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
2395324281
int i;
24282
+ if( !ShellHasFlag(p,SHFLG_TestingMode) ){
24283
+ utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n",
24284
+ "imposter");
24285
+ rc = 1;
24286
+ goto meta_command_exit;
24287
+ }
2395424288
if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
2395524289
utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
2395624290
" .imposter off\n");
2395724291
/* Also allowed, but not documented:
2395824292
**
@@ -24133,11 +24467,12 @@
2413324467
#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
2413424468
if( c=='l' && cli_strncmp(azArg[0], "load", n)==0 ){
2413524469
const char *zFile, *zProc;
2413624470
char *zErrMsg = 0;
2413724471
failIfSafeMode(p, "cannot run .load in safe mode");
24138
- if( nArg<2 ){
24472
+ if( nArg<2 || azArg[1][0]==0 ){
24473
+ /* Must have a non-empty FILE. (Will not load self.) */
2413924474
raw_printf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
2414024475
rc = 1;
2414124476
goto meta_command_exit;
2414224477
}
2414324478
zFile = azArg[1];
@@ -25457,32 +25792,40 @@
2545725792
"' OR ') as query, tname from tabcols group by tname)"
2545825793
, zRevText);
2545925794
shell_check_oom(zRevText);
2546025795
if( bDebug ) utf8_printf(p->out, "%s\n", zRevText);
2546125796
lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
25462
- assert(lrc==SQLITE_OK);
25463
- if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
25464
- lrc = SQLITE_ROW==sqlite3_step(pStmt);
25465
- if( lrc ){
25466
- const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
25467
- sqlite3_stmt *pCheckStmt;
25468
- lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
25469
- if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
25470
- if( SQLITE_OK==lrc ){
25471
- if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
25472
- double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
25473
- if( countIrreversible>0 ){
25474
- int sz = (int)(countIrreversible + 0.5);
25475
- utf8_printf(stderr,
25476
- "Digest includes %d invalidly encoded text field%s.\n",
25477
- sz, (sz>1)? "s": "");
25478
- }
25479
- }
25480
- sqlite3_finalize(pCheckStmt);
25481
- }
25482
- sqlite3_finalize(pStmt);
25483
- }
25797
+ if( lrc!=SQLITE_OK ){
25798
+ /* assert(lrc==SQLITE_NOMEM); // might also be SQLITE_ERROR if the
25799
+ ** user does cruel and unnatural things like ".limit expr_depth 0". */
25800
+ rc = 1;
25801
+ }else{
25802
+ if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
25803
+ lrc = SQLITE_ROW==sqlite3_step(pStmt);
25804
+ if( lrc ){
25805
+ const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
25806
+ sqlite3_stmt *pCheckStmt;
25807
+ lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
25808
+ if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
25809
+ if( lrc!=SQLITE_OK ){
25810
+ rc = 1;
25811
+ }else{
25812
+ if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
25813
+ double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
25814
+ if( countIrreversible>0 ){
25815
+ int sz = (int)(countIrreversible + 0.5);
25816
+ utf8_printf(stderr,
25817
+ "Digest includes %d invalidly encoded text field%s.\n",
25818
+ sz, (sz>1)? "s": "");
25819
+ }
25820
+ }
25821
+ sqlite3_finalize(pCheckStmt);
25822
+ }
25823
+ sqlite3_finalize(pStmt);
25824
+ }
25825
+ }
25826
+ if( rc ) utf8_printf(stderr, ".sha3sum failed.\n");
2548425827
sqlite3_free(zRevText);
2548525828
}
2548625829
#endif /* !defined(*_OMIT_SCHEMA_PRAGMAS) && !defined(*_OMIT_VIRTUALTABLE) */
2548725830
sqlite3_free(zSql);
2548825831
}else
@@ -25741,10 +26084,16 @@
2574126084
int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
2574226085
int isOk = 0;
2574326086
int i, n2;
2574426087
const char *zCmd = 0;
2574526088
26089
+ if( !ShellHasFlag(p,SHFLG_TestingMode) ){
26090
+ utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n",
26091
+ "testctrl");
26092
+ rc = 1;
26093
+ goto meta_command_exit;
26094
+ }
2574626095
open_db(p, 0);
2574726096
zCmd = nArg>=2 ? azArg[1] : "help";
2574826097
2574926098
/* The argument can optionally begin with "-" or "--" */
2575026099
if( zCmd[0]=='-' && zCmd[1] ){
@@ -26740,10 +27089,14 @@
2674027089
" -sorterref SIZE sorter references threshold size\n"
2674127090
#endif
2674227091
" -stats print memory stats before each finalize\n"
2674327092
" -table set output mode to 'table'\n"
2674427093
" -tabs set output mode to 'tabs'\n"
27094
+ " -unsafe-testing allow unsafe commands and modes for testing\n"
27095
+#if SHELL_WIN_UTF8_OPT
27096
+ " -utf8 setup interactive console code page for UTF-8\n"
27097
+#endif
2674527098
" -version show SQLite version\n"
2674627099
" -vfs NAME use NAME as the default VFS\n"
2674727100
#ifdef SQLITE_ENABLE_VFSTRACE
2674827101
" -vfstrace enable tracing of all VFS calls\n"
2674927102
#endif
@@ -26831,10 +27184,14 @@
2683127184
argv[0], argv[argc-1]);
2683227185
exit(1);
2683327186
}
2683427187
return argv[i];
2683527188
}
27189
+
27190
+static void sayAbnormalExit(void){
27191
+ if( seenInterrupt ) fprintf(stderr, "Program interrupted.\n");
27192
+}
2683627193
2683727194
#ifndef SQLITE_SHELL_IS_UTF8
2683827195
# if (defined(_WIN32) || defined(WIN32)) \
2683927196
&& (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__)))
2684027197
# define SQLITE_SHELL_IS_UTF8 (0)
@@ -26852,11 +27209,11 @@
2685227209
#else
2685327210
int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
2685427211
char **argv;
2685527212
#endif
2685627213
#ifdef SQLITE_DEBUG
26857
- sqlite3_int64 mem_main_enter = sqlite3_memory_used();
27214
+ sqlite3_int64 mem_main_enter = 0;
2685827215
#endif
2685927216
char *zErrMsg = 0;
2686027217
#ifdef SQLITE_SHELL_FIDDLE
2686127218
# define data shellState
2686227219
#else
@@ -26873,22 +27230,27 @@
2687327230
const char *zVfs = 0; /* Value of -vfs command-line option */
2687427231
#if !SQLITE_SHELL_IS_UTF8
2687527232
char **argvToFree = 0;
2687627233
int argcToFree = 0;
2687727234
#endif
26878
-
26879
- setBinaryMode(stdin, 0);
2688027235
setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
27236
+
2688127237
#ifdef SQLITE_SHELL_FIDDLE
2688227238
stdin_is_interactive = 0;
2688327239
stdout_is_console = 1;
2688427240
data.wasm.zDefaultDbName = "/fiddle.sqlite3";
2688527241
#else
2688627242
stdin_is_interactive = isatty(0);
2688727243
stdout_is_console = isatty(1);
2688827244
#endif
26889
-
27245
+#if SHELL_WIN_UTF8_OPT
27246
+ atexit(console_restore); /* Needs revision for CLI as library call */
27247
+#endif
27248
+ atexit(sayAbnormalExit);
27249
+#ifdef SQLITE_DEBUG
27250
+ mem_main_enter = sqlite3_memory_used();
27251
+#endif
2689027252
#if !defined(_WIN32_WCE)
2689127253
if( getenv("SQLITE_DEBUG_BREAK") ){
2689227254
if( isatty(0) && isatty(2) ){
2689327255
fprintf(stderr,
2689427256
"attach debugger to process %d and press any key to continue.\n",
@@ -26904,10 +27266,18 @@
2690427266
#elif defined(SIGTRAP)
2690527267
raise(SIGTRAP);
2690627268
#endif
2690727269
}
2690827270
}
27271
+#endif
27272
+ /* Register a valid signal handler early, before much else is done. */
27273
+#ifdef SIGINT
27274
+ signal(SIGINT, interrupt_handler);
27275
+#elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
27276
+ if( !SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE) ){
27277
+ fprintf(stderr, "No ^C handler.\n");
27278
+ }
2690927279
#endif
2691027280
2691127281
#if USE_SYSTEM_SQLITE+0!=1
2691227282
if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
2691327283
utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
@@ -26944,19 +27314,10 @@
2694427314
#endif
2694527315
2694627316
assert( argc>=1 && argv && argv[0] );
2694727317
Argv0 = argv[0];
2694827318
26949
- /* Make sure we have a valid signal handler early, before anything
26950
- ** else is done.
26951
- */
26952
-#ifdef SIGINT
26953
- signal(SIGINT, interrupt_handler);
26954
-#elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
26955
- SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
26956
-#endif
26957
-
2695827319
#ifdef SQLITE_SHELL_DBNAME_PROC
2695927320
{
2696027321
/* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
2696127322
** of a C-function that will provide the name of the database file. Use
2696227323
** this compile-time option to embed this shell program in larger
@@ -27109,10 +27470,12 @@
2710927470
}else if( cli_strcmp(z,"-bail")==0 ){
2711027471
bail_on_error = 1;
2711127472
}else if( cli_strcmp(z,"-nonce")==0 ){
2711227473
free(data.zNonce);
2711327474
data.zNonce = strdup(argv[++i]);
27475
+ }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
27476
+ ShellSetFlag(&data,SHFLG_TestingMode);
2711427477
}else if( cli_strcmp(z,"-safe")==0 ){
2711527478
/* no-op - catch this on the second pass */
2711627479
}
2711727480
}
2711827481
#ifndef SQLITE_SHELL_FIDDLE
@@ -27271,10 +27634,14 @@
2727127634
return 0;
2727227635
}else if( cli_strcmp(z,"-interactive")==0 ){
2727327636
stdin_is_interactive = 1;
2727427637
}else if( cli_strcmp(z,"-batch")==0 ){
2727527638
stdin_is_interactive = 0;
27639
+ }else if( cli_strcmp(z,"-utf8")==0 ){
27640
+#if SHELL_WIN_UTF8_OPT
27641
+ console_utf8 = 1;
27642
+#endif /* SHELL_WIN_UTF8_OPT */
2727627643
}else if( cli_strcmp(z,"-heap")==0 ){
2727727644
i++;
2727827645
}else if( cli_strcmp(z,"-pagecache")==0 ){
2727927646
i+=2;
2728027647
}else if( cli_strcmp(z,"-lookaside")==0 ){
@@ -27341,17 +27708,27 @@
2734127708
readStdin = 0;
2734227709
break;
2734327710
#endif
2734427711
}else if( cli_strcmp(z,"-safe")==0 ){
2734527712
data.bSafeMode = data.bSafeModePersist = 1;
27713
+ }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
27714
+ /* Acted upon in first pass. */
2734627715
}else{
2734727716
utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
2734827717
raw_printf(stderr,"Use -help for a list of options.\n");
2734927718
return 1;
2735027719
}
2735127720
data.cMode = data.mode;
2735227721
}
27722
+#if SHELL_WIN_UTF8_OPT
27723
+ if( console_utf8 && stdin_is_interactive ){
27724
+ console_prepare();
27725
+ }else{
27726
+ setBinaryMode(stdin, 0);
27727
+ console_utf8 = 0;
27728
+ }
27729
+#endif
2735327730
2735427731
if( !readStdin ){
2735527732
/* Run all arguments that do not begin with '-' as if they were separate
2735627733
** command-line inputs, except for the argToSkip argument which contains
2735727734
** the database filename.
2735827735
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -244,10 +244,11 @@
244
245 #if defined(_WIN32) || defined(WIN32)
246 #if SQLITE_OS_WINRT
247 #include <intrin.h>
248 #endif
 
249 #include <windows.h>
250
251 /* string conversion routines only needed on Win32 */
252 extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
253 extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int);
@@ -458,14 +459,28 @@
458 ** at an error if we are not interactive.
459 */
460 static int bail_on_error = 0;
461
462 /*
463 ** Threat stdin as an interactive input if the following variable
464 ** is true. Otherwise, assume stdin is connected to a file or pipe.
465 */
466 static int stdin_is_interactive = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
468 /*
469 ** On Windows systems we have to know if standard output is a console
470 ** in order to translate UTF-8 into MBCS. The following variable is
471 ** true if translation is required.
@@ -595,20 +610,150 @@
595 }
596 return dynPrompt.dynamicPrompt;
597 }
598 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
599
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
600 /*
601 ** Render output like fprintf(). Except, if the output is going to the
602 ** console and if this is running on a Windows machine, translate the
603 ** output from UTF-8 into MBCS.
 
 
604 */
605 #if defined(_WIN32) || defined(WIN32)
606 void utf8_printf(FILE *out, const char *zFormat, ...){
607 va_list ap;
608 va_start(ap, zFormat);
609 if( stdout_is_console && (out==stdout || out==stderr) ){
 
 
 
 
610 char *z1 = sqlite3_vmprintf(zFormat, ap);
611 char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0);
612 sqlite3_free(z1);
613 fputs(z2, out);
614 sqlite3_free(z2);
@@ -636,11 +781,11 @@
636 }
637
638 /* Check a pointer to see if it is NULL. If it is NULL, exit with an
639 ** out-of-memory error.
640 */
641 static void shell_check_oom(void *p){
642 if( p==0 ) shell_out_of_memory();
643 }
644
645 /*
646 ** Write I/O traces to the following stream.
@@ -815,13 +960,18 @@
815 zLine[n] = 0;
816 break;
817 }
818 }
819 #if defined(_WIN32) || defined(WIN32)
820 /* For interactive input on Windows systems, translate the
821 ** multi-byte characterset characters into UTF-8. */
822 if( stdin_is_interactive && in==stdin ){
 
 
 
 
 
823 char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
824 if( zTrans ){
825 i64 nTrans = strlen(zTrans)+1;
826 if( nTrans>nLine ){
827 zLine = realloc(zLine, nTrans);
@@ -858,14 +1008,24 @@
858 }else{
859 zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
860 #if SHELL_USE_LOCAL_GETLINE
861 printf("%s", zPrompt);
862 fflush(stdout);
863 zResult = local_getline(zPrior, stdin);
 
 
 
 
864 #else
865 free(zPrior);
866 zResult = shell_readline(zPrompt);
 
 
 
 
 
 
867 if( zResult && *zResult ) shell_add_history(zResult);
868 #endif
869 }
870 return zResult;
871 }
@@ -1644,11 +1804,12 @@
1644 ** May you find forgiveness for yourself and forgive others.
1645 ** May you share freely, never taking more than you give.
1646 **
1647 ******************************************************************************
1648 **
1649 ** This SQLite extension implements functions that compute SHA3 hashes.
 
1650 ** Two SQL functions are implemented:
1651 **
1652 ** sha3(X,SIZE)
1653 ** sha3_query(Y,SIZE)
1654 **
@@ -3244,22 +3405,22 @@
3244 *pOut = 0;
3245 return pOut;
3246 }
3247
3248 /* Skip over text which is not base64 numeral(s). */
3249 static char * skipNonB64( char *s ){
3250 char c;
3251 while( (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
3252 return s;
3253 }
3254
3255 /* Decode base64 text into a byte buffer. */
3256 static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
3257 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
3258 while( ncIn>0 && *pIn!=PAD_CHAR ){
3259 static signed char nboi[] = { 0, 0, 1, 2, 3 };
3260 char *pUse = skipNonB64(pIn);
3261 unsigned long qv = 0L;
3262 int nti, nbo, nac;
3263 ncIn -= (pUse - pIn);
3264 pIn = pUse;
3265 nti = (ncIn>4)? 4 : ncIn;
@@ -3314,14 +3475,21 @@
3314 nc = 4*(nv+2/3); /* quads needed */
3315 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
3316 if( nvMax < nc ){
3317 sqlite3_result_error(context, "blob expanded to base64 too big", -1);
3318 return;
 
 
 
 
 
 
 
 
3319 }
3320 cBuf = sqlite3_malloc(nc);
3321 if( !cBuf ) goto memFail;
3322 bBuf = (u8*)sqlite3_value_blob(av[0]);
3323 nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
3324 sqlite3_result_text(context, cBuf, nc, sqlite3_free);
3325 break;
3326 case SQLITE_TEXT:
3327 nc = nv;
@@ -3329,14 +3497,21 @@
3329 if( nvMax < nb ){
3330 sqlite3_result_error(context, "blob from base64 may be too big", -1);
3331 return;
3332 }else if( nb<1 ){
3333 nb = 1;
 
 
 
 
 
 
 
 
3334 }
3335 bBuf = sqlite3_malloc(nb);
3336 if( !bBuf ) goto memFail;
3337 cBuf = (char *)sqlite3_value_text(av[0]);
3338 nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
3339 sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
3340 break;
3341 default:
3342 sqlite3_result_error(context, "base64 accepts only blob or text", -1);
@@ -3520,13 +3695,13 @@
3520
3521 /* Width of base64 lines. Should be an integer multiple of 5. */
3522 #define B85_DARK_MAX 80
3523
3524
3525 static char * skipNonB85( char *s ){
3526 char c;
3527 while( (c = *s) && !IS_B85(c) ) ++s;
3528 return s;
3529 }
3530
3531 /* Convert small integer, known to be in 0..84 inclusive, to base85 numeral.
3532 * Do not use the macro form with argument expression having a side-effect.*/
@@ -3592,11 +3767,11 @@
3592 /* Decode base85 text into a byte buffer. */
3593 static u8* fromBase85( char *pIn, int ncIn, u8 *pOut ){
3594 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
3595 while( ncIn>0 ){
3596 static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
3597 char *pUse = skipNonB85(pIn);
3598 unsigned long qv = 0L;
3599 int nti, nbo;
3600 ncIn -= (pUse - pIn);
3601 pIn = pUse;
3602 nti = (ncIn>5)? 5 : ncIn;
@@ -3676,14 +3851,21 @@
3676 /* ulongs tail newlines tailenc+nul*/
3677 nc = 5*(nv/4) + nv%4 + nv/64+1 + 2;
3678 if( nvMax < nc ){
3679 sqlite3_result_error(context, "blob expanded to base85 too big", -1);
3680 return;
 
 
 
 
 
 
 
 
3681 }
3682 cBuf = sqlite3_malloc(nc);
3683 if( !cBuf ) goto memFail;
3684 bBuf = (u8*)sqlite3_value_blob(av[0]);
3685 nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
3686 sqlite3_result_text(context, cBuf, nc, sqlite3_free);
3687 break;
3688 case SQLITE_TEXT:
3689 nc = nv;
@@ -3691,14 +3873,21 @@
3691 if( nvMax < nb ){
3692 sqlite3_result_error(context, "blob from base85 may be too big", -1);
3693 return;
3694 }else if( nb<1 ){
3695 nb = 1;
 
 
 
 
 
 
 
 
3696 }
3697 bBuf = sqlite3_malloc(nb);
3698 if( !bBuf ) goto memFail;
3699 cBuf = (char *)sqlite3_value_text(av[0]);
3700 nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
3701 sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
3702 break;
3703 default:
3704 sqlite3_result_error(context, "base85 accepts only blob or text.", -1);
@@ -4114,11 +4303,11 @@
4114 }
4115
4116 /************************* End ../ext/misc/ieee754.c ********************/
4117 /************************* Begin ../ext/misc/series.c ******************/
4118 /*
4119 ** 2015-08-18
4120 **
4121 ** The author disclaims copyright to this source code. In place of
4122 ** a legal notice, here is a blessing:
4123 **
4124 ** May you do good and not evil.
@@ -4127,11 +4316,23 @@
4127 **
4128 *************************************************************************
4129 **
4130 ** This file demonstrates how to create a table-valued-function using
4131 ** a virtual table. This demo implements the generate_series() function
4132 ** which gives similar results to the eponymous function in PostgreSQL.
 
 
 
 
 
 
 
 
 
 
 
 
4133 ** Examples:
4134 **
4135 ** SELECT * FROM generate_series(0,100,5);
4136 **
4137 ** The query above returns integers from 0 through 100 counting by steps
@@ -4143,10 +4344,18 @@
4143 **
4144 ** SELECT * FROM generate_series(20) LIMIT 10;
4145 **
4146 ** Integers 20 through 29.
4147 **
 
 
 
 
 
 
 
 
4148 ** HOW IT WORKS
4149 **
4150 ** The generate_series "function" is really a virtual table with the
4151 ** following schema:
4152 **
@@ -4154,10 +4363,13 @@
4154 ** value,
4155 ** start HIDDEN,
4156 ** stop HIDDEN,
4157 ** step HIDDEN
4158 ** );
 
 
 
4159 **
4160 ** Function arguments in queries against this virtual table are translated
4161 ** into equality constraints against successive hidden columns. In other
4162 ** words, the following pairs of queries are equivalent to each other:
4163 **
@@ -4187,27 +4399,109 @@
4187 */
4188 /* #include "sqlite3ext.h" */
4189 SQLITE_EXTENSION_INIT1
4190 #include <assert.h>
4191 #include <string.h>
 
4192
4193 #ifndef SQLITE_OMIT_VIRTUALTABLE
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4195
4196 /* series_cursor is a subclass of sqlite3_vtab_cursor which will
4197 ** serve as the underlying representation of a cursor that scans
4198 ** over rows of the result
4199 */
4200 typedef struct series_cursor series_cursor;
4201 struct series_cursor {
4202 sqlite3_vtab_cursor base; /* Base class - must be first */
4203 int isDesc; /* True to count down rather than up */
4204 sqlite3_int64 iRowid; /* The rowid */
4205 sqlite3_int64 iValue; /* Current value ("value") */
4206 sqlite3_int64 mnValue; /* Mimimum value ("start") */
4207 sqlite3_int64 mxValue; /* Maximum value ("stop") */
4208 sqlite3_int64 iStep; /* Increment ("step") */
4209 };
4210
4211 /*
4212 ** The seriesConnect() method is invoked to create a new
4213 ** series_vtab that describes the generate_series virtual table.
@@ -4285,16 +4579,11 @@
4285 /*
4286 ** Advance a series_cursor to its next row of output.
4287 */
4288 static int seriesNext(sqlite3_vtab_cursor *cur){
4289 series_cursor *pCur = (series_cursor*)cur;
4290 if( pCur->isDesc ){
4291 pCur->iValue -= pCur->iStep;
4292 }else{
4293 pCur->iValue += pCur->iStep;
4294 }
4295 pCur->iRowid++;
4296 return SQLITE_OK;
4297 }
4298
4299 /*
4300 ** Return values of columns for the row at which the series_cursor
@@ -4306,14 +4595,14 @@
4306 int i /* Which column to return */
4307 ){
4308 series_cursor *pCur = (series_cursor*)cur;
4309 sqlite3_int64 x = 0;
4310 switch( i ){
4311 case SERIES_COLUMN_START: x = pCur->mnValue; break;
4312 case SERIES_COLUMN_STOP: x = pCur->mxValue; break;
4313 case SERIES_COLUMN_STEP: x = pCur->iStep; break;
4314 default: x = pCur->iValue; break;
4315 }
4316 sqlite3_result_int64(ctx, x);
4317 return SQLITE_OK;
4318 }
4319
@@ -4322,28 +4611,24 @@
4322 ** first row returned is assigned rowid value 1, and each subsequent
4323 ** row a value 1 more than that of the previous.
4324 */
4325 static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
4326 series_cursor *pCur = (series_cursor*)cur;
4327 *pRowid = pCur->iRowid;
4328 return SQLITE_OK;
4329 }
4330
4331 /*
4332 ** Return TRUE if the cursor has been moved off of the last
4333 ** row of output.
4334 */
4335 static int seriesEof(sqlite3_vtab_cursor *cur){
4336 series_cursor *pCur = (series_cursor*)cur;
4337 if( pCur->isDesc ){
4338 return pCur->iValue < pCur->mnValue;
4339 }else{
4340 return pCur->iValue > pCur->mxValue;
4341 }
4342 }
4343
4344 /* True to cause run-time checking of the start=, stop=, and/or step=
4345 ** parameters. The only reason to do this is for testing the
4346 ** constraint checking logic for virtual tables in the SQLite core.
4347 */
4348 #ifndef SQLITE_SERIES_CONSTRAINT_VERIFY
4349 # define SQLITE_SERIES_CONSTRAINT_VERIFY 0
@@ -4350,11 +4635,11 @@
4350 #endif
4351
4352 /*
4353 ** This method is called to "rewind" the series_cursor object back
4354 ** to the first row of output. This method is always called at least
4355 ** once prior to any call to seriesColumn() or seriesRowid() or
4356 ** seriesEof().
4357 **
4358 ** The query plan selected by seriesBestIndex is passed in the idxNum
4359 ** parameter. (idxStr is not used in this implementation.) idxNum
4360 ** is a bitmask showing which constraints are available:
@@ -4370,58 +4655,53 @@
4370 ** This routine should initialize the cursor and position it so that it
4371 ** is pointing at the first row, or pointing off the end of the table
4372 ** (so that seriesEof() will return true) if the table is empty.
4373 */
4374 static int seriesFilter(
4375 sqlite3_vtab_cursor *pVtabCursor,
4376 int idxNum, const char *idxStrUnused,
4377 int argc, sqlite3_value **argv
4378 ){
4379 series_cursor *pCur = (series_cursor *)pVtabCursor;
4380 int i = 0;
4381 (void)idxStrUnused;
4382 if( idxNum & 1 ){
4383 pCur->mnValue = sqlite3_value_int64(argv[i++]);
4384 }else{
4385 pCur->mnValue = 0;
4386 }
4387 if( idxNum & 2 ){
4388 pCur->mxValue = sqlite3_value_int64(argv[i++]);
4389 }else{
4390 pCur->mxValue = 0xffffffff;
4391 }
4392 if( idxNum & 4 ){
4393 pCur->iStep = sqlite3_value_int64(argv[i++]);
4394 if( pCur->iStep==0 ){
4395 pCur->iStep = 1;
4396 }else if( pCur->iStep<0 ){
4397 pCur->iStep = -pCur->iStep;
4398 if( (idxNum & 16)==0 ) idxNum |= 8;
4399 }
4400 }else{
4401 pCur->iStep = 1;
4402 }
4403 for(i=0; i<argc; i++){
4404 if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
4405 /* If any of the constraints have a NULL value, then return no rows.
4406 ** See ticket https://www.sqlite.org/src/info/fac496b61722daf2 */
4407 pCur->mnValue = 1;
4408 pCur->mxValue = 0;
 
4409 break;
4410 }
4411 }
4412 if( idxNum & 8 ){
4413 pCur->isDesc = 1;
4414 pCur->iValue = pCur->mxValue;
4415 if( pCur->iStep>0 ){
4416 pCur->iValue -= (pCur->mxValue - pCur->mnValue)%pCur->iStep;
4417 }
4418 }else{
4419 pCur->isDesc = 0;
4420 pCur->iValue = pCur->mnValue;
4421 }
4422 pCur->iRowid = 1;
4423 return SQLITE_OK;
4424 }
4425
4426 /*
4427 ** SQLite will invoke this method one or more times while planning a query
@@ -14576,11 +14856,11 @@
14576 pStmt = recoverPreparePrintf(p, p->dbOut, "PRAGMA index_xinfo(%Q)", zName);
14577 while( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
14578 int iField = sqlite3_column_int(pStmt, 0);
14579 int iCol = sqlite3_column_int(pStmt, 1);
14580
14581 assert( iField<pNew->nCol && iCol<pNew->nCol );
14582 pNew->aCol[iCol].iField = iField;
14583
14584 pNew->bIntkey = 0;
14585 iPk = -2;
14586 }
@@ -16521,10 +16801,11 @@
16521 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
16522 #define SHFLG_Echo 0x00000040 /* .echo on/off, or --echo setting */
16523 #define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
16524 #define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
16525 #define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
 
16526
16527 /*
16528 ** Macros for testing and setting shellFlgs
16529 */
16530 #define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -16854,10 +17135,11 @@
16854 */
16855 static void output_quoted_string(FILE *out, const char *z){
16856 int i;
16857 char c;
16858 setBinaryMode(out, 1);
 
16859 for(i=0; (c = z[i])!=0 && c!='\''; i++){}
16860 if( c==0 ){
16861 utf8_printf(out,"'%s'",z);
16862 }else{
16863 raw_printf(out, "'");
@@ -16983,10 +17265,11 @@
16983 /*
16984 ** Output the given string as a quoted according to JSON quoting rules.
16985 */
16986 static void output_json_string(FILE *out, const char *z, i64 n){
16987 unsigned int c;
 
16988 if( n<0 ) n = strlen(z);
16989 fputc('"', out);
16990 while( n-- ){
16991 c = *(z++);
16992 if( c=='\\' || c=='"' ){
@@ -17107,12 +17390,11 @@
17107 /*
17108 ** This routine runs when the user presses Ctrl-C
17109 */
17110 static void interrupt_handler(int NotUsed){
17111 UNUSED_PARAMETER(NotUsed);
17112 seenInterrupt++;
17113 if( seenInterrupt>2 ) exit(1);
17114 if( globalDb ) sqlite3_interrupt(globalDb);
17115 }
17116
17117 #if (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
17118 /*
@@ -18559,14 +18841,18 @@
18559 zVar = zNum;
18560 }
18561 sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
18562 if( rc==SQLITE_OK && pQ && sqlite3_step(pQ)==SQLITE_ROW ){
18563 sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
 
18564 }else if( sqlite3_strlike("_NAN", zVar, 0)==0 ){
18565 sqlite3_bind_double(pStmt, i, NAN);
 
 
18566 }else if( sqlite3_strlike("_INF", zVar, 0)==0 ){
18567 sqlite3_bind_double(pStmt, i, INFINITY);
 
18568 }else{
18569 sqlite3_bind_null(pStmt, i);
18570 }
18571 sqlite3_reset(pQ);
18572 }
@@ -18806,11 +19092,11 @@
18806 nAlloc = nColumn*4;
18807 if( nAlloc<=0 ) nAlloc = 1;
18808 azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
18809 shell_check_oom(azData);
18810 azNextLine = sqlite3_malloc64( nColumn*sizeof(char*) );
18811 shell_check_oom((void*)azNextLine);
18812 memset((void*)azNextLine, 0, nColumn*sizeof(char*) );
18813 if( p->cmOpts.bQuote ){
18814 azQuoted = sqlite3_malloc64( nColumn*sizeof(char*) );
18815 shell_check_oom(azQuoted);
18816 memset(azQuoted, 0, nColumn*sizeof(char*) );
@@ -18836,10 +19122,11 @@
18836 if( wx==0 ){
18837 wx = p->cmOpts.iWrap;
18838 }
18839 if( wx<0 ) wx = -wx;
18840 uz = (const unsigned char*)sqlite3_column_name(pStmt,i);
 
18841 azData[i] = translateForDisplayAndDup(uz, &zNotUsed, wx, bw);
18842 }
18843 do{
18844 int useNextLine = bNextLine;
18845 bNextLine = 0;
@@ -19769,17 +20056,17 @@
19769 " from the \".mode\" output mode",
19770 " * If FILE begins with \"|\" then it is a command that generates the",
19771 " input text.",
19772 #endif
19773 #ifndef SQLITE_OMIT_TEST_CONTROL
19774 ".imposter INDEX TABLE Create imposter table TABLE on index INDEX",
19775 #endif
19776 ".indexes ?TABLE? Show names of indexes",
19777 " If TABLE is specified, only show indexes for",
19778 " tables matching TABLE using the LIKE operator.",
19779 #ifdef SQLITE_ENABLE_IOTRACE
19780 ".iotrace FILE Enable I/O diagnostic logging to FILE",
19781 #endif
19782 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
19783 ".lint OPTIONS Report potential schema issues.",
19784 " Options:",
19785 " fkey-indexes Find missing foreign key indexes",
@@ -19884,11 +20171,11 @@
19884 ".scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off",
19885 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
19886 " Options:",
19887 " --indent Try to pretty-print the schema",
19888 " --nosys Omit objects whose names start with \"sqlite_\"",
19889 ".selftest ?OPTIONS? Run tests defined in the SELFTEST table",
19890 " Options:",
19891 " --init Create a new SELFTEST table",
19892 " -v Verbose output",
19893 ".separator COL ?ROW? Change the column and row separators",
19894 #if defined(SQLITE_ENABLE_SESSION)
@@ -19926,13 +20213,13 @@
19926 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
19927 ".system CMD ARGS... Run CMD ARGS... in a system shell",
19928 #endif
19929 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
19930 #ifndef SQLITE_SHELL_FIDDLE
19931 ".testcase NAME Begin redirecting output to 'testcase-out.txt'",
19932 #endif
19933 ".testctrl CMD ... Run various sqlite3_test_control() operations",
19934 " Run \".testctrl\" with no arguments for details",
19935 ".timeout MS Try opening locked tables for MS milliseconds",
19936 ".timer on|off Turn SQL timer on or off",
19937 #ifndef SQLITE_OMIT_TRACE
19938 ".trace ?OPTIONS? Output each SQL statement as it is run",
@@ -19980,20 +20267,45 @@
19980 || zPattern[0]=='0'
19981 || cli_strcmp(zPattern,"-a")==0
19982 || cli_strcmp(zPattern,"-all")==0
19983 || cli_strcmp(zPattern,"--all")==0
19984 ){
19985 /* Show all commands, but only one line per command */
19986 if( zPattern==0 ) zPattern = "";
 
 
 
 
 
 
 
 
 
 
19987 for(i=0; i<ArraySize(azHelp); i++){
19988 if( azHelp[i][0]=='.' || zPattern[0] ){
19989 utf8_printf(out, "%s\n", azHelp[i]);
19990 n++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19991 }
19992 }
19993 }else{
19994 /* Look for commands that for which zPattern is an exact prefix */
19995 zPat = sqlite3_mprintf(".%s*", zPattern);
19996 shell_check_oom(zPat);
19997 for(i=0; i<ArraySize(azHelp); i++){
19998 if( sqlite3_strglob(zPat, azHelp[i])==0 ){
19999 utf8_printf(out, "%s\n", azHelp[i]);
@@ -20002,28 +20314,32 @@
20002 }
20003 }
20004 sqlite3_free(zPat);
20005 if( n ){
20006 if( n==1 ){
20007 /* when zPattern is a prefix of exactly one command, then include the
20008 ** details of that command, which should begin at offset j */
20009 while( j<ArraySize(azHelp)-1 && azHelp[j][0]!='.' ){
20010 utf8_printf(out, "%s\n", azHelp[j]);
20011 j++;
20012 }
20013 }
20014 return n;
20015 }
20016 /* Look for commands that contain zPattern anywhere. Show the complete
20017 ** text of all commands that match. */
20018 zPat = sqlite3_mprintf("%%%s%%", zPattern);
20019 shell_check_oom(zPat);
20020 for(i=0; i<ArraySize(azHelp); i++){
 
 
 
 
20021 if( azHelp[i][0]=='.' ) j = i;
20022 if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
20023 utf8_printf(out, "%s\n", azHelp[j]);
20024 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]!='.' ){
20025 j++;
20026 utf8_printf(out, "%s\n", azHelp[j]);
20027 }
20028 i = j;
20029 n++;
@@ -20344,10 +20660,17 @@
20344 return;
20345 }
20346 exit(1);
20347 }
20348 sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0);
 
 
 
 
 
 
 
20349
20350 #ifndef SQLITE_OMIT_LOAD_EXTENSION
20351 sqlite3_enable_load_extension(p->db, 1);
20352 #endif
20353 sqlite3_shathree_init(p->db, 0, 0);
@@ -20677,11 +21000,11 @@
20677 if( p->traceOut==0 ) return 0;
20678 if( mType==SQLITE_TRACE_CLOSE ){
20679 utf8_printf(p->traceOut, "-- closing database connection\n");
20680 return 0;
20681 }
20682 if( mType!=SQLITE_TRACE_ROW && ((const char*)pX)[0]=='-' ){
20683 zSql = (const char*)pX;
20684 }else{
20685 pStmt = (sqlite3_stmt*)pP;
20686 switch( p->eTraceType ){
20687 case SHELL_TRACE_EXPANDED: {
@@ -20709,11 +21032,11 @@
20709 case SQLITE_TRACE_STMT: {
20710 utf8_printf(p->traceOut, "%.*s;\n", (int)nSql, zSql);
20711 break;
20712 }
20713 case SQLITE_TRACE_PROFILE: {
20714 sqlite3_int64 nNanosec = *(sqlite3_int64*)pX;
20715 utf8_printf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec);
20716 break;
20717 }
20718 }
20719 return 0;
@@ -21237,11 +21560,13 @@
21237 }
21238 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
21239 if( sqlite3_step(pStmt)==SQLITE_ROW
21240 && sqlite3_column_bytes(pStmt,0)>100
21241 ){
21242 memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
 
 
21243 sqlite3_finalize(pStmt);
21244 }else{
21245 raw_printf(stderr, "unable to read database header\n");
21246 sqlite3_finalize(pStmt);
21247 return 1;
@@ -22054,11 +22379,14 @@
22054 if( arProcessSwitch(pAr, pMatch->eSwitch, zArg) ) return SQLITE_ERROR;
22055 }
22056 }
22057 }
22058 }
22059
 
 
 
22060 return SQLITE_OK;
22061 }
22062
22063 /*
22064 ** This function assumes that all arguments within the ArCommand.azArg[]
@@ -23949,10 +24277,16 @@
23949 sqlite3_stmt *pStmt;
23950 int tnum = 0;
23951 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
23952 int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
23953 int i;
 
 
 
 
 
 
23954 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
23955 utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
23956 " .imposter off\n");
23957 /* Also allowed, but not documented:
23958 **
@@ -24133,11 +24467,12 @@
24133 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
24134 if( c=='l' && cli_strncmp(azArg[0], "load", n)==0 ){
24135 const char *zFile, *zProc;
24136 char *zErrMsg = 0;
24137 failIfSafeMode(p, "cannot run .load in safe mode");
24138 if( nArg<2 ){
 
24139 raw_printf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
24140 rc = 1;
24141 goto meta_command_exit;
24142 }
24143 zFile = azArg[1];
@@ -25457,32 +25792,40 @@
25457 "' OR ') as query, tname from tabcols group by tname)"
25458 , zRevText);
25459 shell_check_oom(zRevText);
25460 if( bDebug ) utf8_printf(p->out, "%s\n", zRevText);
25461 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
25462 assert(lrc==SQLITE_OK);
25463 if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
25464 lrc = SQLITE_ROW==sqlite3_step(pStmt);
25465 if( lrc ){
25466 const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
25467 sqlite3_stmt *pCheckStmt;
25468 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
25469 if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
25470 if( SQLITE_OK==lrc ){
25471 if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
25472 double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
25473 if( countIrreversible>0 ){
25474 int sz = (int)(countIrreversible + 0.5);
25475 utf8_printf(stderr,
25476 "Digest includes %d invalidly encoded text field%s.\n",
25477 sz, (sz>1)? "s": "");
25478 }
25479 }
25480 sqlite3_finalize(pCheckStmt);
25481 }
25482 sqlite3_finalize(pStmt);
25483 }
 
 
 
 
 
 
 
 
25484 sqlite3_free(zRevText);
25485 }
25486 #endif /* !defined(*_OMIT_SCHEMA_PRAGMAS) && !defined(*_OMIT_VIRTUALTABLE) */
25487 sqlite3_free(zSql);
25488 }else
@@ -25741,10 +26084,16 @@
25741 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
25742 int isOk = 0;
25743 int i, n2;
25744 const char *zCmd = 0;
25745
 
 
 
 
 
 
25746 open_db(p, 0);
25747 zCmd = nArg>=2 ? azArg[1] : "help";
25748
25749 /* The argument can optionally begin with "-" or "--" */
25750 if( zCmd[0]=='-' && zCmd[1] ){
@@ -26740,10 +27089,14 @@
26740 " -sorterref SIZE sorter references threshold size\n"
26741 #endif
26742 " -stats print memory stats before each finalize\n"
26743 " -table set output mode to 'table'\n"
26744 " -tabs set output mode to 'tabs'\n"
 
 
 
 
26745 " -version show SQLite version\n"
26746 " -vfs NAME use NAME as the default VFS\n"
26747 #ifdef SQLITE_ENABLE_VFSTRACE
26748 " -vfstrace enable tracing of all VFS calls\n"
26749 #endif
@@ -26831,10 +27184,14 @@
26831 argv[0], argv[argc-1]);
26832 exit(1);
26833 }
26834 return argv[i];
26835 }
 
 
 
 
26836
26837 #ifndef SQLITE_SHELL_IS_UTF8
26838 # if (defined(_WIN32) || defined(WIN32)) \
26839 && (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__)))
26840 # define SQLITE_SHELL_IS_UTF8 (0)
@@ -26852,11 +27209,11 @@
26852 #else
26853 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
26854 char **argv;
26855 #endif
26856 #ifdef SQLITE_DEBUG
26857 sqlite3_int64 mem_main_enter = sqlite3_memory_used();
26858 #endif
26859 char *zErrMsg = 0;
26860 #ifdef SQLITE_SHELL_FIDDLE
26861 # define data shellState
26862 #else
@@ -26873,22 +27230,27 @@
26873 const char *zVfs = 0; /* Value of -vfs command-line option */
26874 #if !SQLITE_SHELL_IS_UTF8
26875 char **argvToFree = 0;
26876 int argcToFree = 0;
26877 #endif
26878
26879 setBinaryMode(stdin, 0);
26880 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
 
26881 #ifdef SQLITE_SHELL_FIDDLE
26882 stdin_is_interactive = 0;
26883 stdout_is_console = 1;
26884 data.wasm.zDefaultDbName = "/fiddle.sqlite3";
26885 #else
26886 stdin_is_interactive = isatty(0);
26887 stdout_is_console = isatty(1);
26888 #endif
26889
 
 
 
 
 
 
26890 #if !defined(_WIN32_WCE)
26891 if( getenv("SQLITE_DEBUG_BREAK") ){
26892 if( isatty(0) && isatty(2) ){
26893 fprintf(stderr,
26894 "attach debugger to process %d and press any key to continue.\n",
@@ -26904,10 +27266,18 @@
26904 #elif defined(SIGTRAP)
26905 raise(SIGTRAP);
26906 #endif
26907 }
26908 }
 
 
 
 
 
 
 
 
26909 #endif
26910
26911 #if USE_SYSTEM_SQLITE+0!=1
26912 if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
26913 utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
@@ -26944,19 +27314,10 @@
26944 #endif
26945
26946 assert( argc>=1 && argv && argv[0] );
26947 Argv0 = argv[0];
26948
26949 /* Make sure we have a valid signal handler early, before anything
26950 ** else is done.
26951 */
26952 #ifdef SIGINT
26953 signal(SIGINT, interrupt_handler);
26954 #elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
26955 SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
26956 #endif
26957
26958 #ifdef SQLITE_SHELL_DBNAME_PROC
26959 {
26960 /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
26961 ** of a C-function that will provide the name of the database file. Use
26962 ** this compile-time option to embed this shell program in larger
@@ -27109,10 +27470,12 @@
27109 }else if( cli_strcmp(z,"-bail")==0 ){
27110 bail_on_error = 1;
27111 }else if( cli_strcmp(z,"-nonce")==0 ){
27112 free(data.zNonce);
27113 data.zNonce = strdup(argv[++i]);
 
 
27114 }else if( cli_strcmp(z,"-safe")==0 ){
27115 /* no-op - catch this on the second pass */
27116 }
27117 }
27118 #ifndef SQLITE_SHELL_FIDDLE
@@ -27271,10 +27634,14 @@
27271 return 0;
27272 }else if( cli_strcmp(z,"-interactive")==0 ){
27273 stdin_is_interactive = 1;
27274 }else if( cli_strcmp(z,"-batch")==0 ){
27275 stdin_is_interactive = 0;
 
 
 
 
27276 }else if( cli_strcmp(z,"-heap")==0 ){
27277 i++;
27278 }else if( cli_strcmp(z,"-pagecache")==0 ){
27279 i+=2;
27280 }else if( cli_strcmp(z,"-lookaside")==0 ){
@@ -27341,17 +27708,27 @@
27341 readStdin = 0;
27342 break;
27343 #endif
27344 }else if( cli_strcmp(z,"-safe")==0 ){
27345 data.bSafeMode = data.bSafeModePersist = 1;
 
 
27346 }else{
27347 utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
27348 raw_printf(stderr,"Use -help for a list of options.\n");
27349 return 1;
27350 }
27351 data.cMode = data.mode;
27352 }
 
 
 
 
 
 
 
 
27353
27354 if( !readStdin ){
27355 /* Run all arguments that do not begin with '-' as if they were separate
27356 ** command-line inputs, except for the argToSkip argument which contains
27357 ** the database filename.
27358
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -244,10 +244,11 @@
244
245 #if defined(_WIN32) || defined(WIN32)
246 #if SQLITE_OS_WINRT
247 #include <intrin.h>
248 #endif
249 #define WIN32_LEAN_AND_MEAN
250 #include <windows.h>
251
252 /* string conversion routines only needed on Win32 */
253 extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
254 extern char *sqlite3_win32_mbcs_to_utf8_v2(const char *, int);
@@ -458,14 +459,28 @@
459 ** at an error if we are not interactive.
460 */
461 static int bail_on_error = 0;
462
463 /*
464 ** Treat stdin as an interactive input if the following variable
465 ** is true. Otherwise, assume stdin is connected to a file or pipe.
466 */
467 static int stdin_is_interactive = 1;
468
469 #if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE \
470 && !defined(SHELL_OMIT_WIN_UTF8)
471 # define SHELL_WIN_UTF8_OPT 1
472 #else
473 # define SHELL_WIN_UTF8_OPT 0
474 #endif
475
476 #if SHELL_WIN_UTF8_OPT
477 /*
478 ** Setup console for UTF-8 input/output when following variable true.
479 */
480 static int console_utf8 = 0;
481 #endif
482
483 /*
484 ** On Windows systems we have to know if standard output is a console
485 ** in order to translate UTF-8 into MBCS. The following variable is
486 ** true if translation is required.
@@ -595,20 +610,150 @@
610 }
611 return dynPrompt.dynamicPrompt;
612 }
613 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
614
615 #if SHELL_WIN_UTF8_OPT
616 /* Following struct is used for -utf8 operation. */
617 static struct ConsoleState {
618 int stdinEof; /* EOF has been seen on console input */
619 int infsMode; /* Input file stream mode upon shell start */
620 UINT inCodePage; /* Input code page upon shell start */
621 UINT outCodePage; /* Output code page upon shell start */
622 HANDLE hConsoleIn; /* Console input handle */
623 DWORD consoleMode; /* Console mode upon shell start */
624 } conState = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
625
626 /*
627 ** Prepare console, (if known to be a WIN32 console), for UTF-8
628 ** input (from either typing or suitable paste operations) and for
629 ** UTF-8 rendering. This may "fail" with a message to stderr, where
630 ** the preparation is not done and common "code page" issues occur.
631 */
632 static void console_prepare(void){
633 HANDLE hCI = GetStdHandle(STD_INPUT_HANDLE);
634 DWORD consoleMode = 0;
635 if( isatty(0) && GetFileType(hCI)==FILE_TYPE_CHAR
636 && GetConsoleMode( hCI, &consoleMode) ){
637 if( !IsValidCodePage(CP_UTF8) ){
638 fprintf(stderr, "Cannot use UTF-8 code page.\n");
639 console_utf8 = 0;
640 return;
641 }
642 conState.hConsoleIn = hCI;
643 conState.consoleMode = consoleMode;
644 conState.inCodePage = GetConsoleCP();
645 conState.outCodePage = GetConsoleOutputCP();
646 SetConsoleCP(CP_UTF8);
647 SetConsoleOutputCP(CP_UTF8);
648 consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
649 SetConsoleMode(conState.hConsoleIn, consoleMode);
650 conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
651 console_utf8 = 1;
652 }else{
653 console_utf8 = 0;
654 }
655 }
656
657 /*
658 ** Undo the effects of console_prepare(), if any.
659 */
660 static void SQLITE_CDECL console_restore(void){
661 if( console_utf8 && conState.inCodePage!=0
662 && conState.hConsoleIn!=INVALID_HANDLE_VALUE ){
663 _setmode(_fileno(stdin), conState.infsMode);
664 SetConsoleCP(conState.inCodePage);
665 SetConsoleOutputCP(conState.outCodePage);
666 SetConsoleMode(conState.hConsoleIn, conState.consoleMode);
667 /* Avoid multiple calls. */
668 conState.hConsoleIn = INVALID_HANDLE_VALUE;
669 conState.consoleMode = 0;
670 console_utf8 = 0;
671 }
672 }
673
674 /*
675 ** Collect input like fgets(...) with special provisions for input
676 ** from the Windows console to get around its strange coding issues.
677 ** Defers to plain fgets() when input is not interactive or when the
678 ** startup option, -utf8, has not been provided or taken effect.
679 */
680 static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
681 if( fin==0 ) fin = stdin;
682 if( fin==stdin && stdin_is_interactive && console_utf8 ){
683 # define SQLITE_IALIM 150
684 wchar_t wbuf[SQLITE_IALIM];
685 int lend = 0;
686 int noc = 0;
687 if( ncmax==0 || conState.stdinEof ) return 0;
688 buf[0] = 0;
689 while( noc<ncmax-7-1 && !lend ){
690 /* There is room for at least 2 more characters and a 0-terminator. */
691 int na = (ncmax > SQLITE_IALIM*4+1 + noc)
692 ? SQLITE_IALIM : (ncmax-1 - noc)/4;
693 # undef SQLITE_IALIM
694 DWORD nbr = 0;
695 BOOL bRC = ReadConsoleW(conState.hConsoleIn, wbuf, na, &nbr, 0);
696 if( !bRC || (noc==0 && nbr==0) ) return 0;
697 if( nbr > 0 ){
698 int nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
699 wbuf,nbr,0,0,0,0);
700 if( nmb !=0 && noc+nmb <= ncmax ){
701 int iseg = noc;
702 nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
703 wbuf,nbr,buf+noc,nmb,0,0);
704 noc += nmb;
705 /* Fixup line-ends as coded by Windows for CR (or "Enter".)*/
706 if( noc > 0 ){
707 if( buf[noc-1]=='\n' ){
708 lend = 1;
709 if( noc > 1 && buf[noc-2]=='\r' ){
710 buf[noc-2] = '\n';
711 --noc;
712 }
713 }
714 }
715 /* Check for ^Z (anywhere in line) too. */
716 while( iseg < noc ){
717 if( buf[iseg]==0x1a ){
718 conState.stdinEof = 1;
719 noc = iseg; /* Chop ^Z and anything following. */
720 break;
721 }
722 ++iseg;
723 }
724 }else break; /* Drop apparent garbage in. (Could assert.) */
725 }else break;
726 }
727 /* If got nothing, (after ^Z chop), must be at end-of-file. */
728 if( noc == 0 ) return 0;
729 buf[noc] = 0;
730 return buf;
731 }else{
732 return fgets(buf, ncmax, fin);
733 }
734 }
735
736 # define fgets(b,n,f) utf8_fgets(b,n,f)
737 #endif /* SHELL_WIN_UTF8_OPT */
738
739 /*
740 ** Render output like fprintf(). Except, if the output is going to the
741 ** console and if this is running on a Windows machine, and if the -utf8
742 ** option is unavailable or (available and inactive), translate the
743 ** output from UTF-8 into MBCS for output through 8-bit stdout stream.
744 ** (With -utf8 active, no translation is needed and must not be done.)
745 */
746 #if defined(_WIN32) || defined(WIN32)
747 void utf8_printf(FILE *out, const char *zFormat, ...){
748 va_list ap;
749 va_start(ap, zFormat);
750 if( stdout_is_console && (out==stdout || out==stderr)
751 # if SHELL_WIN_UTF8_OPT
752 && !console_utf8
753 # endif
754 ){
755 char *z1 = sqlite3_vmprintf(zFormat, ap);
756 char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0);
757 sqlite3_free(z1);
758 fputs(z2, out);
759 sqlite3_free(z2);
@@ -636,11 +781,11 @@
781 }
782
783 /* Check a pointer to see if it is NULL. If it is NULL, exit with an
784 ** out-of-memory error.
785 */
786 static void shell_check_oom(const void *p){
787 if( p==0 ) shell_out_of_memory();
788 }
789
790 /*
791 ** Write I/O traces to the following stream.
@@ -815,13 +960,18 @@
960 zLine[n] = 0;
961 break;
962 }
963 }
964 #if defined(_WIN32) || defined(WIN32)
965 /* For interactive input on Windows systems, without -utf8,
966 ** translate the multi-byte characterset characters into UTF-8.
967 ** This is the translation that predates the -utf8 option. */
968 if( stdin_is_interactive && in==stdin
969 # if SHELL_WIN_UTF8_OPT
970 && !console_utf8
971 # endif /* SHELL_WIN_UTF8_OPT */
972 ){
973 char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
974 if( zTrans ){
975 i64 nTrans = strlen(zTrans)+1;
976 if( nTrans>nLine ){
977 zLine = realloc(zLine, nTrans);
@@ -858,14 +1008,24 @@
1008 }else{
1009 zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
1010 #if SHELL_USE_LOCAL_GETLINE
1011 printf("%s", zPrompt);
1012 fflush(stdout);
1013 do{
1014 zResult = local_getline(zPrior, stdin);
1015 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
1016 if( zResult==0 ) sqlite3_sleep(50);
1017 }while( zResult==0 && seenInterrupt>0 );
1018 #else
1019 free(zPrior);
1020 zResult = shell_readline(zPrompt);
1021 while( zResult==0 ){
1022 /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
1023 sqlite3_sleep(50);
1024 if( seenInterrupt==0 ) break;
1025 zResult = shell_readline("");
1026 }
1027 if( zResult && *zResult ) shell_add_history(zResult);
1028 #endif
1029 }
1030 return zResult;
1031 }
@@ -1644,11 +1804,12 @@
1804 ** May you find forgiveness for yourself and forgive others.
1805 ** May you share freely, never taking more than you give.
1806 **
1807 ******************************************************************************
1808 **
1809 ** This SQLite extension implements functions that compute SHA3 hashes
1810 ** in the way described by the (U.S.) NIST FIPS 202 SHA-3 Standard.
1811 ** Two SQL functions are implemented:
1812 **
1813 ** sha3(X,SIZE)
1814 ** sha3_query(Y,SIZE)
1815 **
@@ -3244,22 +3405,22 @@
3405 *pOut = 0;
3406 return pOut;
3407 }
3408
3409 /* Skip over text which is not base64 numeral(s). */
3410 static char * skipNonB64( char *s, int nc ){
3411 char c;
3412 while( nc-- > 0 && (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
3413 return s;
3414 }
3415
3416 /* Decode base64 text into a byte buffer. */
3417 static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
3418 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
3419 while( ncIn>0 && *pIn!=PAD_CHAR ){
3420 static signed char nboi[] = { 0, 0, 1, 2, 3 };
3421 char *pUse = skipNonB64(pIn, ncIn);
3422 unsigned long qv = 0L;
3423 int nti, nbo, nac;
3424 ncIn -= (pUse - pIn);
3425 pIn = pUse;
3426 nti = (ncIn>4)? 4 : ncIn;
@@ -3314,14 +3475,21 @@
3475 nc = 4*(nv+2/3); /* quads needed */
3476 nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
3477 if( nvMax < nc ){
3478 sqlite3_result_error(context, "blob expanded to base64 too big", -1);
3479 return;
3480 }
3481 bBuf = (u8*)sqlite3_value_blob(av[0]);
3482 if( !bBuf ){
3483 if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
3484 goto memFail;
3485 }
3486 sqlite3_result_text(context,"",-1,SQLITE_STATIC);
3487 break;
3488 }
3489 cBuf = sqlite3_malloc(nc);
3490 if( !cBuf ) goto memFail;
 
3491 nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
3492 sqlite3_result_text(context, cBuf, nc, sqlite3_free);
3493 break;
3494 case SQLITE_TEXT:
3495 nc = nv;
@@ -3329,14 +3497,21 @@
3497 if( nvMax < nb ){
3498 sqlite3_result_error(context, "blob from base64 may be too big", -1);
3499 return;
3500 }else if( nb<1 ){
3501 nb = 1;
3502 }
3503 cBuf = (char *)sqlite3_value_text(av[0]);
3504 if( !cBuf ){
3505 if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
3506 goto memFail;
3507 }
3508 sqlite3_result_zeroblob(context, 0);
3509 break;
3510 }
3511 bBuf = sqlite3_malloc(nb);
3512 if( !bBuf ) goto memFail;
 
3513 nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
3514 sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
3515 break;
3516 default:
3517 sqlite3_result_error(context, "base64 accepts only blob or text", -1);
@@ -3520,13 +3695,13 @@
3695
3696 /* Width of base64 lines. Should be an integer multiple of 5. */
3697 #define B85_DARK_MAX 80
3698
3699
3700 static char * skipNonB85( char *s, int nc ){
3701 char c;
3702 while( nc-- > 0 && (c = *s) && !IS_B85(c) ) ++s;
3703 return s;
3704 }
3705
3706 /* Convert small integer, known to be in 0..84 inclusive, to base85 numeral.
3707 * Do not use the macro form with argument expression having a side-effect.*/
@@ -3592,11 +3767,11 @@
3767 /* Decode base85 text into a byte buffer. */
3768 static u8* fromBase85( char *pIn, int ncIn, u8 *pOut ){
3769 if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
3770 while( ncIn>0 ){
3771 static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
3772 char *pUse = skipNonB85(pIn, ncIn);
3773 unsigned long qv = 0L;
3774 int nti, nbo;
3775 ncIn -= (pUse - pIn);
3776 pIn = pUse;
3777 nti = (ncIn>5)? 5 : ncIn;
@@ -3676,14 +3851,21 @@
3851 /* ulongs tail newlines tailenc+nul*/
3852 nc = 5*(nv/4) + nv%4 + nv/64+1 + 2;
3853 if( nvMax < nc ){
3854 sqlite3_result_error(context, "blob expanded to base85 too big", -1);
3855 return;
3856 }
3857 bBuf = (u8*)sqlite3_value_blob(av[0]);
3858 if( !bBuf ){
3859 if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
3860 goto memFail;
3861 }
3862 sqlite3_result_text(context,"",-1,SQLITE_STATIC);
3863 break;
3864 }
3865 cBuf = sqlite3_malloc(nc);
3866 if( !cBuf ) goto memFail;
 
3867 nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
3868 sqlite3_result_text(context, cBuf, nc, sqlite3_free);
3869 break;
3870 case SQLITE_TEXT:
3871 nc = nv;
@@ -3691,14 +3873,21 @@
3873 if( nvMax < nb ){
3874 sqlite3_result_error(context, "blob from base85 may be too big", -1);
3875 return;
3876 }else if( nb<1 ){
3877 nb = 1;
3878 }
3879 cBuf = (char *)sqlite3_value_text(av[0]);
3880 if( !cBuf ){
3881 if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
3882 goto memFail;
3883 }
3884 sqlite3_result_zeroblob(context, 0);
3885 break;
3886 }
3887 bBuf = sqlite3_malloc(nb);
3888 if( !bBuf ) goto memFail;
 
3889 nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
3890 sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
3891 break;
3892 default:
3893 sqlite3_result_error(context, "base85 accepts only blob or text.", -1);
@@ -4114,11 +4303,11 @@
4303 }
4304
4305 /************************* End ../ext/misc/ieee754.c ********************/
4306 /************************* Begin ../ext/misc/series.c ******************/
4307 /*
4308 ** 2015-08-18, 2023-04-28
4309 **
4310 ** The author disclaims copyright to this source code. In place of
4311 ** a legal notice, here is a blessing:
4312 **
4313 ** May you do good and not evil.
@@ -4127,11 +4316,23 @@
4316 **
4317 *************************************************************************
4318 **
4319 ** This file demonstrates how to create a table-valued-function using
4320 ** a virtual table. This demo implements the generate_series() function
4321 ** which gives the same results as the eponymous function in PostgreSQL,
4322 ** within the limitation that its arguments are signed 64-bit integers.
4323 **
4324 ** Considering its equivalents to generate_series(start,stop,step): A
4325 ** value V[n] sequence is produced for integer n ascending from 0 where
4326 ** ( V[n] == start + n * step && sgn(V[n] - stop) * sgn(step) >= 0 )
4327 ** for each produced value (independent of production time ordering.)
4328 **
4329 ** All parameters must be either integer or convertable to integer.
4330 ** The start parameter is required.
4331 ** The stop parameter defaults to (1<<32)-1 (aka 4294967295 or 0xffffffff)
4332 ** The step parameter defaults to 1 and 0 is treated as 1.
4333 **
4334 ** Examples:
4335 **
4336 ** SELECT * FROM generate_series(0,100,5);
4337 **
4338 ** The query above returns integers from 0 through 100 counting by steps
@@ -4143,10 +4344,18 @@
4344 **
4345 ** SELECT * FROM generate_series(20) LIMIT 10;
4346 **
4347 ** Integers 20 through 29.
4348 **
4349 ** SELECT * FROM generate_series(0,-100,-5);
4350 **
4351 ** Integers 0 -5 -10 ... -100.
4352 **
4353 ** SELECT * FROM generate_series(0,-1);
4354 **
4355 ** Empty sequence.
4356 **
4357 ** HOW IT WORKS
4358 **
4359 ** The generate_series "function" is really a virtual table with the
4360 ** following schema:
4361 **
@@ -4154,10 +4363,13 @@
4363 ** value,
4364 ** start HIDDEN,
4365 ** stop HIDDEN,
4366 ** step HIDDEN
4367 ** );
4368 **
4369 ** The virtual table also has a rowid, logically equivalent to n+1 where
4370 ** "n" is the ascending integer in the aforesaid production definition.
4371 **
4372 ** Function arguments in queries against this virtual table are translated
4373 ** into equality constraints against successive hidden columns. In other
4374 ** words, the following pairs of queries are equivalent to each other:
4375 **
@@ -4187,27 +4399,109 @@
4399 */
4400 /* #include "sqlite3ext.h" */
4401 SQLITE_EXTENSION_INIT1
4402 #include <assert.h>
4403 #include <string.h>
4404 #include <limits.h>
4405
4406 #ifndef SQLITE_OMIT_VIRTUALTABLE
4407 /*
4408 ** Return that member of a generate_series(...) sequence whose 0-based
4409 ** index is ix. The 0th member is given by smBase. The sequence members
4410 ** progress per ix increment by smStep.
4411 */
4412 static sqlite3_int64 genSeqMember(sqlite3_int64 smBase,
4413 sqlite3_int64 smStep,
4414 sqlite3_uint64 ix){
4415 if( ix>=(sqlite3_uint64)LLONG_MAX ){
4416 /* Get ix into signed i64 range. */
4417 ix -= (sqlite3_uint64)LLONG_MAX;
4418 smBase += LLONG_MAX * smStep;
4419 }
4420 return smBase + ((sqlite3_int64)ix)*smStep;
4421 }
4422
4423 /* typedef unsigned char u8; */
4424
4425 typedef struct SequenceSpec {
4426 sqlite3_int64 iBase; /* Starting value ("start") */
4427 sqlite3_int64 iTerm; /* Given terminal value ("stop") */
4428 sqlite3_int64 iStep; /* Increment ("step") */
4429 sqlite3_uint64 uSeqIndexMax; /* maximum sequence index (aka "n") */
4430 sqlite3_uint64 uSeqIndexNow; /* Current index during generation */
4431 sqlite3_int64 iValueNow; /* Current value during generation */
4432 u8 isNotEOF; /* Sequence generation not exhausted */
4433 u8 isReversing; /* Sequence is being reverse generated */
4434 } SequenceSpec;
4435
4436 /*
4437 ** Prepare a SequenceSpec for use in generating an integer series
4438 ** given initialized iBase, iTerm and iStep values. Sequence is
4439 ** initialized per given isReversing. Other members are computed.
4440 */
4441 void setupSequence( SequenceSpec *pss ){
4442 pss->uSeqIndexMax = 0;
4443 pss->isNotEOF = 0;
4444 if( pss->iTerm < pss->iBase ){
4445 sqlite3_uint64 nuspan = (sqlite3_uint64)(pss->iBase-pss->iTerm);
4446 if( pss->iStep<0 ){
4447 pss->isNotEOF = 1;
4448 if( nuspan==ULONG_MAX ){
4449 pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1;
4450 }else if( pss->iStep>LLONG_MIN ){
4451 pss->uSeqIndexMax = nuspan/-pss->iStep;
4452 }
4453 }
4454 }else if( pss->iTerm > pss->iBase ){
4455 sqlite3_uint64 puspan = (sqlite3_uint64)(pss->iTerm-pss->iBase);
4456 if( pss->iStep>0 ){
4457 pss->isNotEOF = 1;
4458 pss->uSeqIndexMax = puspan/pss->iStep;
4459 }
4460 }else if( pss->iTerm == pss->iBase ){
4461 pss->isNotEOF = 1;
4462 pss->uSeqIndexMax = 0;
4463 }
4464 pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0;
4465 pss->iValueNow = (pss->isReversing)
4466 ? genSeqMember(pss->iBase, pss->iStep, pss->uSeqIndexMax)
4467 : pss->iBase;
4468 }
4469
4470 /*
4471 ** Progress sequence generator to yield next value, if any.
4472 ** Leave its state to either yield next value or be at EOF.
4473 ** Return whether there is a next value, or 0 at EOF.
4474 */
4475 int progressSequence( SequenceSpec *pss ){
4476 if( !pss->isNotEOF ) return 0;
4477 if( pss->isReversing ){
4478 if( pss->uSeqIndexNow > 0 ){
4479 pss->uSeqIndexNow--;
4480 pss->iValueNow -= pss->iStep;
4481 }else{
4482 pss->isNotEOF = 0;
4483 }
4484 }else{
4485 if( pss->uSeqIndexNow < pss->uSeqIndexMax ){
4486 pss->uSeqIndexNow++;
4487 pss->iValueNow += pss->iStep;
4488 }else{
4489 pss->isNotEOF = 0;
4490 }
4491 }
4492 return pss->isNotEOF;
4493 }
4494
4495 /* series_cursor is a subclass of sqlite3_vtab_cursor which will
4496 ** serve as the underlying representation of a cursor that scans
4497 ** over rows of the result
4498 */
4499 typedef struct series_cursor series_cursor;
4500 struct series_cursor {
4501 sqlite3_vtab_cursor base; /* Base class - must be first */
4502 SequenceSpec ss; /* (this) Derived class data */
 
 
 
 
 
4503 };
4504
4505 /*
4506 ** The seriesConnect() method is invoked to create a new
4507 ** series_vtab that describes the generate_series virtual table.
@@ -4285,16 +4579,11 @@
4579 /*
4580 ** Advance a series_cursor to its next row of output.
4581 */
4582 static int seriesNext(sqlite3_vtab_cursor *cur){
4583 series_cursor *pCur = (series_cursor*)cur;
4584 progressSequence( & pCur->ss );
 
 
 
 
 
4585 return SQLITE_OK;
4586 }
4587
4588 /*
4589 ** Return values of columns for the row at which the series_cursor
@@ -4306,14 +4595,14 @@
4595 int i /* Which column to return */
4596 ){
4597 series_cursor *pCur = (series_cursor*)cur;
4598 sqlite3_int64 x = 0;
4599 switch( i ){
4600 case SERIES_COLUMN_START: x = pCur->ss.iBase; break;
4601 case SERIES_COLUMN_STOP: x = pCur->ss.iTerm; break;
4602 case SERIES_COLUMN_STEP: x = pCur->ss.iStep; break;
4603 default: x = pCur->ss.iValueNow; break;
4604 }
4605 sqlite3_result_int64(ctx, x);
4606 return SQLITE_OK;
4607 }
4608
@@ -4322,28 +4611,24 @@
4611 ** first row returned is assigned rowid value 1, and each subsequent
4612 ** row a value 1 more than that of the previous.
4613 */
4614 static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
4615 series_cursor *pCur = (series_cursor*)cur;
4616 *pRowid = ((sqlite3_int64)pCur->ss.uSeqIndexNow + 1);
4617 return SQLITE_OK;
4618 }
4619
4620 /*
4621 ** Return TRUE if the cursor has been moved off of the last
4622 ** row of output.
4623 */
4624 static int seriesEof(sqlite3_vtab_cursor *cur){
4625 series_cursor *pCur = (series_cursor*)cur;
4626 return !pCur->ss.isNotEOF;
 
 
 
 
4627 }
4628
4629 /* True to cause run-time checking of the start=, stop=, and/or step=
4630 ** parameters. The only reason to do this is for testing the
4631 ** constraint checking logic for virtual tables in the SQLite core.
4632 */
4633 #ifndef SQLITE_SERIES_CONSTRAINT_VERIFY
4634 # define SQLITE_SERIES_CONSTRAINT_VERIFY 0
@@ -4350,11 +4635,11 @@
4635 #endif
4636
4637 /*
4638 ** This method is called to "rewind" the series_cursor object back
4639 ** to the first row of output. This method is always called at least
4640 ** once prior to any call to seriesColumn() or seriesRowid() or
4641 ** seriesEof().
4642 **
4643 ** The query plan selected by seriesBestIndex is passed in the idxNum
4644 ** parameter. (idxStr is not used in this implementation.) idxNum
4645 ** is a bitmask showing which constraints are available:
@@ -4370,58 +4655,53 @@
4655 ** This routine should initialize the cursor and position it so that it
4656 ** is pointing at the first row, or pointing off the end of the table
4657 ** (so that seriesEof() will return true) if the table is empty.
4658 */
4659 static int seriesFilter(
4660 sqlite3_vtab_cursor *pVtabCursor,
4661 int idxNum, const char *idxStrUnused,
4662 int argc, sqlite3_value **argv
4663 ){
4664 series_cursor *pCur = (series_cursor *)pVtabCursor;
4665 int i = 0;
4666 (void)idxStrUnused;
4667 if( idxNum & 1 ){
4668 pCur->ss.iBase = sqlite3_value_int64(argv[i++]);
4669 }else{
4670 pCur->ss.iBase = 0;
4671 }
4672 if( idxNum & 2 ){
4673 pCur->ss.iTerm = sqlite3_value_int64(argv[i++]);
4674 }else{
4675 pCur->ss.iTerm = 0xffffffff;
4676 }
4677 if( idxNum & 4 ){
4678 pCur->ss.iStep = sqlite3_value_int64(argv[i++]);
4679 if( pCur->ss.iStep==0 ){
4680 pCur->ss.iStep = 1;
4681 }else if( pCur->ss.iStep<0 ){
 
4682 if( (idxNum & 16)==0 ) idxNum |= 8;
4683 }
4684 }else{
4685 pCur->ss.iStep = 1;
4686 }
4687 for(i=0; i<argc; i++){
4688 if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
4689 /* If any of the constraints have a NULL value, then return no rows.
4690 ** See ticket https://www.sqlite.org/src/info/fac496b61722daf2 */
4691 pCur->ss.iBase = 1;
4692 pCur->ss.iTerm = 0;
4693 pCur->ss.iStep = 1;
4694 break;
4695 }
4696 }
4697 if( idxNum & 8 ){
4698 pCur->ss.isReversing = pCur->ss.iStep > 0;
 
 
 
 
4699 }else{
4700 pCur->ss.isReversing = pCur->ss.iStep < 0;
 
4701 }
4702 setupSequence( &pCur->ss );
4703 return SQLITE_OK;
4704 }
4705
4706 /*
4707 ** SQLite will invoke this method one or more times while planning a query
@@ -14576,11 +14856,11 @@
14856 pStmt = recoverPreparePrintf(p, p->dbOut, "PRAGMA index_xinfo(%Q)", zName);
14857 while( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
14858 int iField = sqlite3_column_int(pStmt, 0);
14859 int iCol = sqlite3_column_int(pStmt, 1);
14860
14861 assert( iCol<pNew->nCol );
14862 pNew->aCol[iCol].iField = iField;
14863
14864 pNew->bIntkey = 0;
14865 iPk = -2;
14866 }
@@ -16521,10 +16801,11 @@
16801 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
16802 #define SHFLG_Echo 0x00000040 /* .echo on/off, or --echo setting */
16803 #define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
16804 #define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
16805 #define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
16806 #define SHFLG_TestingMode 0x00000400 /* allow unsafe testing features */
16807
16808 /*
16809 ** Macros for testing and setting shellFlgs
16810 */
16811 #define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -16854,10 +17135,11 @@
17135 */
17136 static void output_quoted_string(FILE *out, const char *z){
17137 int i;
17138 char c;
17139 setBinaryMode(out, 1);
17140 if( z==0 ) return;
17141 for(i=0; (c = z[i])!=0 && c!='\''; i++){}
17142 if( c==0 ){
17143 utf8_printf(out,"'%s'",z);
17144 }else{
17145 raw_printf(out, "'");
@@ -16983,10 +17265,11 @@
17265 /*
17266 ** Output the given string as a quoted according to JSON quoting rules.
17267 */
17268 static void output_json_string(FILE *out, const char *z, i64 n){
17269 unsigned int c;
17270 if( z==0 ) z = "";
17271 if( n<0 ) n = strlen(z);
17272 fputc('"', out);
17273 while( n-- ){
17274 c = *(z++);
17275 if( c=='\\' || c=='"' ){
@@ -17107,12 +17390,11 @@
17390 /*
17391 ** This routine runs when the user presses Ctrl-C
17392 */
17393 static void interrupt_handler(int NotUsed){
17394 UNUSED_PARAMETER(NotUsed);
17395 if( ++seenInterrupt>1 ) exit(1);
 
17396 if( globalDb ) sqlite3_interrupt(globalDb);
17397 }
17398
17399 #if (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
17400 /*
@@ -18559,14 +18841,18 @@
18841 zVar = zNum;
18842 }
18843 sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
18844 if( rc==SQLITE_OK && pQ && sqlite3_step(pQ)==SQLITE_ROW ){
18845 sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
18846 #ifdef NAN
18847 }else if( sqlite3_strlike("_NAN", zVar, 0)==0 ){
18848 sqlite3_bind_double(pStmt, i, NAN);
18849 #endif
18850 #ifdef INFINITY
18851 }else if( sqlite3_strlike("_INF", zVar, 0)==0 ){
18852 sqlite3_bind_double(pStmt, i, INFINITY);
18853 #endif
18854 }else{
18855 sqlite3_bind_null(pStmt, i);
18856 }
18857 sqlite3_reset(pQ);
18858 }
@@ -18806,11 +19092,11 @@
19092 nAlloc = nColumn*4;
19093 if( nAlloc<=0 ) nAlloc = 1;
19094 azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
19095 shell_check_oom(azData);
19096 azNextLine = sqlite3_malloc64( nColumn*sizeof(char*) );
19097 shell_check_oom(azNextLine);
19098 memset((void*)azNextLine, 0, nColumn*sizeof(char*) );
19099 if( p->cmOpts.bQuote ){
19100 azQuoted = sqlite3_malloc64( nColumn*sizeof(char*) );
19101 shell_check_oom(azQuoted);
19102 memset(azQuoted, 0, nColumn*sizeof(char*) );
@@ -18836,10 +19122,11 @@
19122 if( wx==0 ){
19123 wx = p->cmOpts.iWrap;
19124 }
19125 if( wx<0 ) wx = -wx;
19126 uz = (const unsigned char*)sqlite3_column_name(pStmt,i);
19127 if( uz==0 ) uz = (u8*)"";
19128 azData[i] = translateForDisplayAndDup(uz, &zNotUsed, wx, bw);
19129 }
19130 do{
19131 int useNextLine = bNextLine;
19132 bNextLine = 0;
@@ -19769,17 +20056,17 @@
20056 " from the \".mode\" output mode",
20057 " * If FILE begins with \"|\" then it is a command that generates the",
20058 " input text.",
20059 #endif
20060 #ifndef SQLITE_OMIT_TEST_CONTROL
20061 ",imposter INDEX TABLE Create imposter table TABLE on index INDEX",
20062 #endif
20063 ".indexes ?TABLE? Show names of indexes",
20064 " If TABLE is specified, only show indexes for",
20065 " tables matching TABLE using the LIKE operator.",
20066 #ifdef SQLITE_ENABLE_IOTRACE
20067 ",iotrace FILE Enable I/O diagnostic logging to FILE",
20068 #endif
20069 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
20070 ".lint OPTIONS Report potential schema issues.",
20071 " Options:",
20072 " fkey-indexes Find missing foreign key indexes",
@@ -19884,11 +20171,11 @@
20171 ".scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off",
20172 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
20173 " Options:",
20174 " --indent Try to pretty-print the schema",
20175 " --nosys Omit objects whose names start with \"sqlite_\"",
20176 ",selftest ?OPTIONS? Run tests defined in the SELFTEST table",
20177 " Options:",
20178 " --init Create a new SELFTEST table",
20179 " -v Verbose output",
20180 ".separator COL ?ROW? Change the column and row separators",
20181 #if defined(SQLITE_ENABLE_SESSION)
@@ -19926,13 +20213,13 @@
20213 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
20214 ".system CMD ARGS... Run CMD ARGS... in a system shell",
20215 #endif
20216 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
20217 #ifndef SQLITE_SHELL_FIDDLE
20218 ",testcase NAME Begin redirecting output to 'testcase-out.txt'",
20219 #endif
20220 ",testctrl CMD ... Run various sqlite3_test_control() operations",
20221 " Run \".testctrl\" with no arguments for details",
20222 ".timeout MS Try opening locked tables for MS milliseconds",
20223 ".timer on|off Turn SQL timer on or off",
20224 #ifndef SQLITE_OMIT_TRACE
20225 ".trace ?OPTIONS? Output each SQL statement as it is run",
@@ -19980,20 +20267,45 @@
20267 || zPattern[0]=='0'
20268 || cli_strcmp(zPattern,"-a")==0
20269 || cli_strcmp(zPattern,"-all")==0
20270 || cli_strcmp(zPattern,"--all")==0
20271 ){
20272 enum HelpWanted { HW_NoCull = 0, HW_SummaryOnly = 1, HW_Undoc = 2 };
20273 enum HelpHave { HH_Undoc = 2, HH_Summary = 1, HH_More = 0 };
20274 /* Show all or most commands
20275 ** *zPattern==0 => summary of documented commands only
20276 ** *zPattern=='0' => whole help for undocumented commands
20277 ** Otherwise => whole help for documented commands
20278 */
20279 enum HelpWanted hw = HW_SummaryOnly;
20280 enum HelpHave hh = HH_More;
20281 if( zPattern!=0 ){
20282 hw = (*zPattern=='0')? HW_NoCull|HW_Undoc : HW_NoCull;
20283 }
20284 for(i=0; i<ArraySize(azHelp); i++){
20285 switch( azHelp[i][0] ){
20286 case ',':
20287 hh = HH_Summary|HH_Undoc;
20288 break;
20289 case '.':
20290 hh = HH_Summary;
20291 break;
20292 default:
20293 hh &= ~HH_Summary;
20294 break;
20295 }
20296 if( ((hw^hh)&HH_Undoc)==0 ){
20297 if( (hh&HH_Summary)!=0 ){
20298 utf8_printf(out, ".%s\n", azHelp[i]+1);
20299 ++n;
20300 }else if( (hw&HW_SummaryOnly)==0 ){
20301 utf8_printf(out, "%s\n", azHelp[i]);
20302 }
20303 }
20304 }
20305 }else{
20306 /* Seek documented commands for which zPattern is an exact prefix */
20307 zPat = sqlite3_mprintf(".%s*", zPattern);
20308 shell_check_oom(zPat);
20309 for(i=0; i<ArraySize(azHelp); i++){
20310 if( sqlite3_strglob(zPat, azHelp[i])==0 ){
20311 utf8_printf(out, "%s\n", azHelp[i]);
@@ -20002,28 +20314,32 @@
20314 }
20315 }
20316 sqlite3_free(zPat);
20317 if( n ){
20318 if( n==1 ){
20319 /* when zPattern is a prefix of exactly one command, then include
20320 ** the details of that command, which should begin at offset j */
20321 while( j<ArraySize(azHelp)-1 && azHelp[j][0]==' ' ){
20322 utf8_printf(out, "%s\n", azHelp[j]);
20323 j++;
20324 }
20325 }
20326 return n;
20327 }
20328 /* Look for documented commands that contain zPattern anywhere.
20329 ** Show complete text of all documented commands that match. */
20330 zPat = sqlite3_mprintf("%%%s%%", zPattern);
20331 shell_check_oom(zPat);
20332 for(i=0; i<ArraySize(azHelp); i++){
20333 if( azHelp[i][0]==',' ){
20334 while( i<ArraySize(azHelp)-1 && azHelp[i+1][0]==' ' ) ++i;
20335 continue;
20336 }
20337 if( azHelp[i][0]=='.' ) j = i;
20338 if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
20339 utf8_printf(out, "%s\n", azHelp[j]);
20340 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]==' ' ){
20341 j++;
20342 utf8_printf(out, "%s\n", azHelp[j]);
20343 }
20344 i = j;
20345 n++;
@@ -20344,10 +20660,17 @@
20660 return;
20661 }
20662 exit(1);
20663 }
20664 sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0);
20665
20666 /* Reflect the use or absence of --unsafe-testing invocation. */
20667 {
20668 int testmode_on = ShellHasFlag(p,SHFLG_TestingMode);
20669 sqlite3_db_config(p->db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, testmode_on,0);
20670 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, !testmode_on,0);
20671 }
20672
20673 #ifndef SQLITE_OMIT_LOAD_EXTENSION
20674 sqlite3_enable_load_extension(p->db, 1);
20675 #endif
20676 sqlite3_shathree_init(p->db, 0, 0);
@@ -20677,11 +21000,11 @@
21000 if( p->traceOut==0 ) return 0;
21001 if( mType==SQLITE_TRACE_CLOSE ){
21002 utf8_printf(p->traceOut, "-- closing database connection\n");
21003 return 0;
21004 }
21005 if( mType!=SQLITE_TRACE_ROW && pX!=0 && ((const char*)pX)[0]=='-' ){
21006 zSql = (const char*)pX;
21007 }else{
21008 pStmt = (sqlite3_stmt*)pP;
21009 switch( p->eTraceType ){
21010 case SHELL_TRACE_EXPANDED: {
@@ -20709,11 +21032,11 @@
21032 case SQLITE_TRACE_STMT: {
21033 utf8_printf(p->traceOut, "%.*s;\n", (int)nSql, zSql);
21034 break;
21035 }
21036 case SQLITE_TRACE_PROFILE: {
21037 sqlite3_int64 nNanosec = pX ? *(sqlite3_int64*)pX : 0;
21038 utf8_printf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec);
21039 break;
21040 }
21041 }
21042 return 0;
@@ -21237,11 +21560,13 @@
21560 }
21561 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
21562 if( sqlite3_step(pStmt)==SQLITE_ROW
21563 && sqlite3_column_bytes(pStmt,0)>100
21564 ){
21565 const u8 *pb = sqlite3_column_blob(pStmt,0);
21566 shell_check_oom(pb);
21567 memcpy(aHdr, pb, 100);
21568 sqlite3_finalize(pStmt);
21569 }else{
21570 raw_printf(stderr, "unable to read database header\n");
21571 sqlite3_finalize(pStmt);
21572 return 1;
@@ -22054,11 +22379,14 @@
22379 if( arProcessSwitch(pAr, pMatch->eSwitch, zArg) ) return SQLITE_ERROR;
22380 }
22381 }
22382 }
22383 }
22384 if( pAr->eCmd==0 ){
22385 utf8_printf(stderr, "Required argument missing. Usage:\n");
22386 return arUsage(stderr);
22387 }
22388 return SQLITE_OK;
22389 }
22390
22391 /*
22392 ** This function assumes that all arguments within the ArCommand.azArg[]
@@ -23949,10 +24277,16 @@
24277 sqlite3_stmt *pStmt;
24278 int tnum = 0;
24279 int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */
24280 int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */
24281 int i;
24282 if( !ShellHasFlag(p,SHFLG_TestingMode) ){
24283 utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n",
24284 "imposter");
24285 rc = 1;
24286 goto meta_command_exit;
24287 }
24288 if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){
24289 utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n"
24290 " .imposter off\n");
24291 /* Also allowed, but not documented:
24292 **
@@ -24133,11 +24467,12 @@
24467 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
24468 if( c=='l' && cli_strncmp(azArg[0], "load", n)==0 ){
24469 const char *zFile, *zProc;
24470 char *zErrMsg = 0;
24471 failIfSafeMode(p, "cannot run .load in safe mode");
24472 if( nArg<2 || azArg[1][0]==0 ){
24473 /* Must have a non-empty FILE. (Will not load self.) */
24474 raw_printf(stderr, "Usage: .load FILE ?ENTRYPOINT?\n");
24475 rc = 1;
24476 goto meta_command_exit;
24477 }
24478 zFile = azArg[1];
@@ -25457,32 +25792,40 @@
25792 "' OR ') as query, tname from tabcols group by tname)"
25793 , zRevText);
25794 shell_check_oom(zRevText);
25795 if( bDebug ) utf8_printf(p->out, "%s\n", zRevText);
25796 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
25797 if( lrc!=SQLITE_OK ){
25798 /* assert(lrc==SQLITE_NOMEM); // might also be SQLITE_ERROR if the
25799 ** user does cruel and unnatural things like ".limit expr_depth 0". */
25800 rc = 1;
25801 }else{
25802 if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
25803 lrc = SQLITE_ROW==sqlite3_step(pStmt);
25804 if( lrc ){
25805 const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
25806 sqlite3_stmt *pCheckStmt;
25807 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
25808 if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
25809 if( lrc!=SQLITE_OK ){
25810 rc = 1;
25811 }else{
25812 if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
25813 double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
25814 if( countIrreversible>0 ){
25815 int sz = (int)(countIrreversible + 0.5);
25816 utf8_printf(stderr,
25817 "Digest includes %d invalidly encoded text field%s.\n",
25818 sz, (sz>1)? "s": "");
25819 }
25820 }
25821 sqlite3_finalize(pCheckStmt);
25822 }
25823 sqlite3_finalize(pStmt);
25824 }
25825 }
25826 if( rc ) utf8_printf(stderr, ".sha3sum failed.\n");
25827 sqlite3_free(zRevText);
25828 }
25829 #endif /* !defined(*_OMIT_SCHEMA_PRAGMAS) && !defined(*_OMIT_VIRTUALTABLE) */
25830 sqlite3_free(zSql);
25831 }else
@@ -25741,10 +26084,16 @@
26084 int rc2 = 0; /* 0: usage. 1: %d 2: %x 3: no-output */
26085 int isOk = 0;
26086 int i, n2;
26087 const char *zCmd = 0;
26088
26089 if( !ShellHasFlag(p,SHFLG_TestingMode) ){
26090 utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n",
26091 "testctrl");
26092 rc = 1;
26093 goto meta_command_exit;
26094 }
26095 open_db(p, 0);
26096 zCmd = nArg>=2 ? azArg[1] : "help";
26097
26098 /* The argument can optionally begin with "-" or "--" */
26099 if( zCmd[0]=='-' && zCmd[1] ){
@@ -26740,10 +27089,14 @@
27089 " -sorterref SIZE sorter references threshold size\n"
27090 #endif
27091 " -stats print memory stats before each finalize\n"
27092 " -table set output mode to 'table'\n"
27093 " -tabs set output mode to 'tabs'\n"
27094 " -unsafe-testing allow unsafe commands and modes for testing\n"
27095 #if SHELL_WIN_UTF8_OPT
27096 " -utf8 setup interactive console code page for UTF-8\n"
27097 #endif
27098 " -version show SQLite version\n"
27099 " -vfs NAME use NAME as the default VFS\n"
27100 #ifdef SQLITE_ENABLE_VFSTRACE
27101 " -vfstrace enable tracing of all VFS calls\n"
27102 #endif
@@ -26831,10 +27184,14 @@
27184 argv[0], argv[argc-1]);
27185 exit(1);
27186 }
27187 return argv[i];
27188 }
27189
27190 static void sayAbnormalExit(void){
27191 if( seenInterrupt ) fprintf(stderr, "Program interrupted.\n");
27192 }
27193
27194 #ifndef SQLITE_SHELL_IS_UTF8
27195 # if (defined(_WIN32) || defined(WIN32)) \
27196 && (defined(_MSC_VER) || (defined(UNICODE) && defined(__GNUC__)))
27197 # define SQLITE_SHELL_IS_UTF8 (0)
@@ -26852,11 +27209,11 @@
27209 #else
27210 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
27211 char **argv;
27212 #endif
27213 #ifdef SQLITE_DEBUG
27214 sqlite3_int64 mem_main_enter = 0;
27215 #endif
27216 char *zErrMsg = 0;
27217 #ifdef SQLITE_SHELL_FIDDLE
27218 # define data shellState
27219 #else
@@ -26873,22 +27230,27 @@
27230 const char *zVfs = 0; /* Value of -vfs command-line option */
27231 #if !SQLITE_SHELL_IS_UTF8
27232 char **argvToFree = 0;
27233 int argcToFree = 0;
27234 #endif
 
 
27235 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
27236
27237 #ifdef SQLITE_SHELL_FIDDLE
27238 stdin_is_interactive = 0;
27239 stdout_is_console = 1;
27240 data.wasm.zDefaultDbName = "/fiddle.sqlite3";
27241 #else
27242 stdin_is_interactive = isatty(0);
27243 stdout_is_console = isatty(1);
27244 #endif
27245 #if SHELL_WIN_UTF8_OPT
27246 atexit(console_restore); /* Needs revision for CLI as library call */
27247 #endif
27248 atexit(sayAbnormalExit);
27249 #ifdef SQLITE_DEBUG
27250 mem_main_enter = sqlite3_memory_used();
27251 #endif
27252 #if !defined(_WIN32_WCE)
27253 if( getenv("SQLITE_DEBUG_BREAK") ){
27254 if( isatty(0) && isatty(2) ){
27255 fprintf(stderr,
27256 "attach debugger to process %d and press any key to continue.\n",
@@ -26904,10 +27266,18 @@
27266 #elif defined(SIGTRAP)
27267 raise(SIGTRAP);
27268 #endif
27269 }
27270 }
27271 #endif
27272 /* Register a valid signal handler early, before much else is done. */
27273 #ifdef SIGINT
27274 signal(SIGINT, interrupt_handler);
27275 #elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
27276 if( !SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE) ){
27277 fprintf(stderr, "No ^C handler.\n");
27278 }
27279 #endif
27280
27281 #if USE_SYSTEM_SQLITE+0!=1
27282 if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
27283 utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
@@ -26944,19 +27314,10 @@
27314 #endif
27315
27316 assert( argc>=1 && argv && argv[0] );
27317 Argv0 = argv[0];
27318
 
 
 
 
 
 
 
 
 
27319 #ifdef SQLITE_SHELL_DBNAME_PROC
27320 {
27321 /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
27322 ** of a C-function that will provide the name of the database file. Use
27323 ** this compile-time option to embed this shell program in larger
@@ -27109,10 +27470,12 @@
27470 }else if( cli_strcmp(z,"-bail")==0 ){
27471 bail_on_error = 1;
27472 }else if( cli_strcmp(z,"-nonce")==0 ){
27473 free(data.zNonce);
27474 data.zNonce = strdup(argv[++i]);
27475 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
27476 ShellSetFlag(&data,SHFLG_TestingMode);
27477 }else if( cli_strcmp(z,"-safe")==0 ){
27478 /* no-op - catch this on the second pass */
27479 }
27480 }
27481 #ifndef SQLITE_SHELL_FIDDLE
@@ -27271,10 +27634,14 @@
27634 return 0;
27635 }else if( cli_strcmp(z,"-interactive")==0 ){
27636 stdin_is_interactive = 1;
27637 }else if( cli_strcmp(z,"-batch")==0 ){
27638 stdin_is_interactive = 0;
27639 }else if( cli_strcmp(z,"-utf8")==0 ){
27640 #if SHELL_WIN_UTF8_OPT
27641 console_utf8 = 1;
27642 #endif /* SHELL_WIN_UTF8_OPT */
27643 }else if( cli_strcmp(z,"-heap")==0 ){
27644 i++;
27645 }else if( cli_strcmp(z,"-pagecache")==0 ){
27646 i+=2;
27647 }else if( cli_strcmp(z,"-lookaside")==0 ){
@@ -27341,17 +27708,27 @@
27708 readStdin = 0;
27709 break;
27710 #endif
27711 }else if( cli_strcmp(z,"-safe")==0 ){
27712 data.bSafeMode = data.bSafeModePersist = 1;
27713 }else if( cli_strcmp(z,"-unsafe-testing")==0 ){
27714 /* Acted upon in first pass. */
27715 }else{
27716 utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
27717 raw_printf(stderr,"Use -help for a list of options.\n");
27718 return 1;
27719 }
27720 data.cMode = data.mode;
27721 }
27722 #if SHELL_WIN_UTF8_OPT
27723 if( console_utf8 && stdin_is_interactive ){
27724 console_prepare();
27725 }else{
27726 setBinaryMode(stdin, 0);
27727 console_utf8 = 0;
27728 }
27729 #endif
27730
27731 if( !readStdin ){
27732 /* Run all arguments that do not begin with '-' as if they were separate
27733 ** command-line inputs, except for the argToSkip argument which contains
27734 ** the database filename.
27735
+2634 -1269
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -121,10 +121,14 @@
121121
#if defined(_MSC_VER) && !defined(_WIN64)
122122
#undef SQLITE_4_BYTE_ALIGNED_MALLOC
123123
#define SQLITE_4_BYTE_ALIGNED_MALLOC
124124
#endif /* defined(_MSC_VER) && !defined(_WIN64) */
125125
126
+#if !defined(HAVE_LOG2) && defined(_MSC_VER) && _MSC_VER<1800
127
+#define HAVE_LOG2 0
128
+#endif /* !defined(HAVE_LOG2) && defined(_MSC_VER) && _MSC_VER<1800 */
129
+
126130
#endif /* SQLITE_MSVC_H */
127131
128132
/************** End of msvc.h ************************************************/
129133
/************** Continuing where we left off in sqliteInt.h ******************/
130134
@@ -452,11 +456,11 @@
452456
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453457
** [sqlite_version()] and [sqlite_source_id()].
454458
*/
455459
#define SQLITE_VERSION "3.42.0"
456460
#define SQLITE_VERSION_NUMBER 3042000
457
-#define SQLITE_SOURCE_ID "2023-04-10 18:44:00 4c5a3c5fb351cc1c2ce16c33314ce19c53531f09263f87456283d9d756002f9d"
461
+#define SQLITE_SOURCE_ID "2023-05-01 20:42:15 342af5b4fa0bd7c699e5497161db13d0cf795c7a5875ae30d666122e518f213b"
458462
459463
/*
460464
** CAPI3REF: Run-Time Library Version Numbers
461465
** KEYWORDS: sqlite3_version sqlite3_sourceid
462466
**
@@ -2702,29 +2706,29 @@
27022706
** additional information. This feature can also be turned on and off
27032707
** using the [PRAGMA legacy_alter_table] statement.
27042708
** </dd>
27052709
**
27062710
** [[SQLITE_DBCONFIG_DQS_DML]]
2707
-** <dt>SQLITE_DBCONFIG_DQS_DML</td>
2711
+** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
27082712
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
27092713
** the legacy [double-quoted string literal] misfeature for DML statements
27102714
** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
27112715
** default value of this setting is determined by the [-DSQLITE_DQS]
27122716
** compile-time option.
27132717
** </dd>
27142718
**
27152719
** [[SQLITE_DBCONFIG_DQS_DDL]]
2716
-** <dt>SQLITE_DBCONFIG_DQS_DDL</td>
2720
+** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
27172721
** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
27182722
** the legacy [double-quoted string literal] misfeature for DDL statements,
27192723
** such as CREATE TABLE and CREATE INDEX. The
27202724
** default value of this setting is determined by the [-DSQLITE_DQS]
27212725
** compile-time option.
27222726
** </dd>
27232727
**
27242728
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2725
-** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2729
+** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
27262730
** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
27272731
** assume that database schemas are untainted by malicious content.
27282732
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
27292733
** takes additional defensive steps to protect the application from harm
27302734
** including:
@@ -2740,20 +2744,20 @@
27402744
** all applications are advised to turn it off if possible. This setting
27412745
** can also be controlled using the [PRAGMA trusted_schema] statement.
27422746
** </dd>
27432747
**
27442748
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2745
-** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
2749
+** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
27462750
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
27472751
** the legacy file format flag. When activated, this flag causes all newly
27482752
** created database file to have a schema format version number (the 4-byte
27492753
** integer found at offset 44 into the database header) of 1. This in turn
27502754
** means that the resulting database file will be readable and writable by
27512755
** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
27522756
** newly created databases are generally not understandable by SQLite versions
27532757
** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2754
-** is now scarcely any need to generated database files that are compatible
2758
+** is now scarcely any need to generate database files that are compatible
27552759
** all the way back to version 3.0.0, and so this setting is of little
27562760
** practical use, but is provided so that SQLite can continue to claim the
27572761
** ability to generate new database files that are compatible with version
27582762
** 3.0.0.
27592763
** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
@@ -2762,27 +2766,39 @@
27622766
** not considered a bug since SQLite versions 3.3.0 and earlier do not support
27632767
** either generated columns or decending indexes.
27642768
** </dd>
27652769
**
27662770
** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2767
-** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</td>
2771
+** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
27682772
** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
27692773
** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
27702774
** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
27712775
** statistics. For statistics to be collected, the flag must be set on
27722776
** the database handle both when the SQL statement is prepared and when it
27732777
** is stepped. The flag is set (collection of statistics is enabled)
2774
-** by default.</dd>
2778
+** by default. This option takes two arguments: an integer and a pointer to
2779
+** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2780
+** leave unchanged the statement scanstatus option. If the second argument
2781
+** is not NULL, then the value of the statement scanstatus setting after
2782
+** processing the first argument is written into the integer that the second
2783
+** argument points to.
2784
+** </dd>
27752785
**
27762786
** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2777
-** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</td>
2778
-** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option change the default order
2787
+** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
2788
+** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
27792789
** in which tables and indexes are scanned so that the scans start at the end
27802790
** and work toward the beginning rather than starting at the beginning and
2781
-** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2782
-** same as setting [PRAGMA reverse_unordered_selects]. This configuration option
2783
-** is useful for application testing.</dd>
2791
+** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2792
+** same as setting [PRAGMA reverse_unordered_selects]. This option takes
2793
+** two arguments which are an integer and a pointer to an integer. The first
2794
+** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2795
+** reverse scan order flag, respectively. If the second argument is not NULL,
2796
+** then 0 or 1 is written into the integer that the second argument points to
2797
+** depending on if the reverse scan order flag is set after processing the
2798
+** first argument.
2799
+** </dd>
27842800
**
27852801
** </dl>
27862802
*/
27872803
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
27882804
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
@@ -2800,11 +2816,11 @@
28002816
#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
28012817
#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
28022818
#define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
28032819
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
28042820
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2805
-#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2821
+#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
28062822
#define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
28072823
#define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
28082824
28092825
/*
28102826
** CAPI3REF: Enable Or Disable Extended Result Codes
@@ -11106,20 +11122,24 @@
1110611122
** [sqlite3session_create()] for details.
1110711123
*/
1110811124
SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
1110911125
1111011126
/*
11111
-** CAPIREF: Conigure a Session Object
11127
+** CAPI3REF: Configure a Session Object
1111211128
** METHOD: sqlite3_session
1111311129
**
1111411130
** This method is used to configure a session object after it has been
11115
-** created. At present the only valid value for the second parameter is
11116
-** [SQLITE_SESSION_OBJCONFIG_SIZE].
11131
+** created. At present the only valid values for the second parameter are
11132
+** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].
1111711133
**
11118
-** Arguments for sqlite3session_object_config()
11134
+*/
11135
+SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11136
+
11137
+/*
11138
+** CAPI3REF: Options for sqlite3session_object_config
1111911139
**
11120
-** The following values may passed as the the 4th parameter to
11140
+** The following values may passed as the the 2nd parameter to
1112111141
** sqlite3session_object_config().
1112211142
**
1112311143
** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
1112411144
** This option is used to set, clear or query the flag that enables
1112511145
** the [sqlite3session_changeset_size()] API. Because it imposes some
@@ -11131,16 +11151,25 @@
1113111151
** variable is set to 1 if the sqlite3session_changeset_size() API is
1113211152
** enabled following the current call, or 0 otherwise.
1113311153
**
1113411154
** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
1113511155
** the first table has been attached to the session object.
11156
+**
11157
+** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>
11158
+** This option is used to set, clear or query the flag that enables
11159
+** collection of data for tables with no explicit PRIMARY KEY.
11160
+**
11161
+** Normally, tables with no explicit PRIMARY KEY are simply ignored
11162
+** by the sessions module. However, if this flag is set, it behaves
11163
+** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted
11164
+** as their leftmost columns.
11165
+**
11166
+** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11167
+** the first table has been attached to the session object.
1113611168
*/
11137
-SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11138
-
11139
-/*
11140
-*/
11141
-#define SQLITE_SESSION_OBJCONFIG_SIZE 1
11169
+#define SQLITE_SESSION_OBJCONFIG_SIZE 1
11170
+#define SQLITE_SESSION_OBJCONFIG_ROWID 2
1114211171
1114311172
/*
1114411173
** CAPI3REF: Enable Or Disable A Session Object
1114511174
** METHOD: sqlite3_session
1114611175
**
@@ -13652,11 +13681,11 @@
1365213681
# define SQLITE_INLINE __forceinline
1365313682
#else
1365413683
# define SQLITE_NOINLINE
1365513684
# define SQLITE_INLINE
1365613685
#endif
13657
-#if defined(SQLITE_COVERAGE_TEST)
13686
+#if defined(SQLITE_COVERAGE_TEST) || defined(__STRICT_ANSI__)
1365813687
# undef SQLITE_INLINE
1365913688
# define SQLITE_INLINE
1366013689
#endif
1366113690
1366213691
/*
@@ -20020,19 +20049,23 @@
2002020049
# define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
2002120050
# define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
2002220051
# define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
2002320052
# define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
2002420053
# define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
20054
+# define sqlite3JsonId1(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x42)
20055
+# define sqlite3JsonId2(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x46)
2002520056
#else
2002620057
# define sqlite3Toupper(x) toupper((unsigned char)(x))
2002720058
# define sqlite3Isspace(x) isspace((unsigned char)(x))
2002820059
# define sqlite3Isalnum(x) isalnum((unsigned char)(x))
2002920060
# define sqlite3Isalpha(x) isalpha((unsigned char)(x))
2003020061
# define sqlite3Isdigit(x) isdigit((unsigned char)(x))
2003120062
# define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
2003220063
# define sqlite3Tolower(x) tolower((unsigned char)(x))
2003320064
# define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
20065
+# define sqlite3JsonId1(x) (sqlite3IsIdChar(x)&&(x)<'0')
20066
+# define sqlite3JsonId2(x) sqlite3IsIdChar(x)
2003420067
#endif
2003520068
SQLITE_PRIVATE int sqlite3IsIdChar(u8);
2003620069
2003720070
/*
2003820071
** Internal function prototypes
@@ -22161,11 +22194,11 @@
2216122194
** isalpha() 0x02
2216222195
** isdigit() 0x04
2216322196
** isalnum() 0x06
2216422197
** isxdigit() 0x08
2216522198
** toupper() 0x20
22166
-** SQLite identifier character 0x40
22199
+** SQLite identifier character 0x40 $, _, or non-ascii
2216722200
** Quote character 0x80
2216822201
**
2216922202
** Bit 0x20 is set if the mapped character requires translation to upper
2217022203
** case. i.e. if the character is a lower-case ASCII character.
2217122204
** If x is a lower-case ASCII character, then its upper-case equivalent
@@ -34434,17 +34467,19 @@
3443434467
}else{
3443534468
x = v;
3443634469
}
3443734470
i = sizeof(zTemp)-2;
3443834471
zTemp[sizeof(zTemp)-1] = 0;
34439
- do{
34440
- zTemp[i--] = (x%10) + '0';
34472
+ while( 1 /*exit-by-break*/ ){
34473
+ zTemp[i] = (x%10) + '0';
3444134474
x = x/10;
34442
- }while( x );
34443
- if( v<0 ) zTemp[i--] = '-';
34444
- memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i);
34445
- return sizeof(zTemp)-2-i;
34475
+ if( x==0 ) break;
34476
+ i--;
34477
+ };
34478
+ if( v<0 ) zTemp[--i] = '-';
34479
+ memcpy(zOut, &zTemp[i], sizeof(zTemp)-i);
34480
+ return sizeof(zTemp)-1-i;
3444634481
}
3444734482
3444834483
/*
3444934484
** Compare the 19-character string zNum against the text representation
3445034485
** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -34605,11 +34640,13 @@
3460534640
for(i=2; z[i]=='0'; i++){}
3460634641
for(k=i; sqlite3Isxdigit(z[k]); k++){
3460734642
u = u*16 + sqlite3HexToInt(z[k]);
3460834643
}
3460934644
memcpy(pOut, &u, 8);
34610
- return (z[k]==0 && k-i<=16) ? 0 : 2;
34645
+ if( k-i>16 ) return 2;
34646
+ if( z[k]!=0 ) return 1;
34647
+ return 0;
3461134648
}else
3461234649
#endif /* SQLITE_OMIT_HEX_INTEGER */
3461334650
{
3461434651
return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8);
3461534652
}
@@ -34641,11 +34678,11 @@
3464134678
&& sqlite3Isxdigit(zNum[2])
3464234679
){
3464334680
u32 u = 0;
3464434681
zNum += 2;
3464534682
while( zNum[0]=='0' ) zNum++;
34646
- for(i=0; sqlite3Isxdigit(zNum[i]) && i<8; i++){
34683
+ for(i=0; i<8 && sqlite3Isxdigit(zNum[i]); i++){
3464734684
u = u*16 + sqlite3HexToInt(zNum[i]);
3464834685
}
3464934686
if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){
3465034687
memcpy(pValue, &u, 4);
3465134688
return 1;
@@ -37137,11 +37174,11 @@
3713737174
# define SQLITE_ENABLE_LOCKING_STYLE 0
3713837175
# endif
3713937176
#endif
3714037177
3714137178
/* Use pread() and pwrite() if they are available */
37142
-#if defined(__APPLE__)
37179
+#if defined(__APPLE__) || defined(__linux__)
3714337180
# define HAVE_PREAD 1
3714437181
# define HAVE_PWRITE 1
3714537182
#endif
3714637183
#if defined(HAVE_PREAD64) && defined(HAVE_PWRITE64)
3714737184
# undef USE_PREAD
@@ -40387,16 +40424,10 @@
4038740424
4038840425
/*
4038940426
** Seek to the offset passed as the second argument, then read cnt
4039040427
** bytes into pBuf. Return the number of bytes actually read.
4039140428
**
40392
-** NB: If you define USE_PREAD or USE_PREAD64, then it might also
40393
-** be necessary to define _XOPEN_SOURCE to be 500. This varies from
40394
-** one system to another. Since SQLite does not define USE_PREAD
40395
-** in any form by default, we will not attempt to define _XOPEN_SOURCE.
40396
-** See tickets #2741 and #2681.
40397
-**
4039840429
** To avoid stomping the errno value on a failed read the lastErrno value
4039940430
** is set before returning.
4040040431
*/
4040140432
static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
4040240433
int got;
@@ -50419,11 +50450,11 @@
5041950450
&extendedParameters);
5042050451
if( h!=INVALID_HANDLE_VALUE ) break;
5042150452
if( isReadWrite ){
5042250453
int rc2, isRO = 0;
5042350454
sqlite3BeginBenignMalloc();
50424
- rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
50455
+ rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
5042550456
sqlite3EndBenignMalloc();
5042650457
if( rc2==SQLITE_OK && isRO ) break;
5042750458
}
5042850459
}while( winRetryIoerr(&cnt, &lastErrno) );
5042950460
#else
@@ -50436,11 +50467,11 @@
5043650467
NULL);
5043750468
if( h!=INVALID_HANDLE_VALUE ) break;
5043850469
if( isReadWrite ){
5043950470
int rc2, isRO = 0;
5044050471
sqlite3BeginBenignMalloc();
50441
- rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
50472
+ rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
5044250473
sqlite3EndBenignMalloc();
5044350474
if( rc2==SQLITE_OK && isRO ) break;
5044450475
}
5044550476
}while( winRetryIoerr(&cnt, &lastErrno) );
5044650477
#endif
@@ -50456,11 +50487,11 @@
5045650487
NULL);
5045750488
if( h!=INVALID_HANDLE_VALUE ) break;
5045850489
if( isReadWrite ){
5045950490
int rc2, isRO = 0;
5046050491
sqlite3BeginBenignMalloc();
50461
- rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
50492
+ rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
5046250493
sqlite3EndBenignMalloc();
5046350494
if( rc2==SQLITE_OK && isRO ) break;
5046450495
}
5046550496
}while( winRetryIoerr(&cnt, &lastErrno) );
5046650497
}
@@ -50678,10 +50709,17 @@
5067850709
UNUSED_PARAMETER(pVfs);
5067950710
5068050711
SimulateIOError( return SQLITE_IOERR_ACCESS; );
5068150712
OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
5068250713
zFilename, flags, pResOut));
50714
+
50715
+ if( zFilename==0 ){
50716
+ *pResOut = 0;
50717
+ OSTRACE(("ACCESS name=%s, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
50718
+ zFilename, pResOut, *pResOut));
50719
+ return SQLITE_OK;
50720
+ }
5068350721
5068450722
zConverted = winConvertFromUtf8Filename(zFilename);
5068550723
if( zConverted==0 ){
5068650724
OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
5068750725
return SQLITE_IOERR_NOMEM_BKPT;
@@ -52835,15 +52873,19 @@
5283552873
# define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
5283652874
static void pcachePageTrace(int i, sqlite3_pcache_page *pLower){
5283752875
PgHdr *pPg;
5283852876
unsigned char *a;
5283952877
int j;
52840
- pPg = (PgHdr*)pLower->pExtra;
52841
- printf("%3lld: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
52842
- a = (unsigned char *)pLower->pBuf;
52843
- for(j=0; j<12; j++) printf("%02x", a[j]);
52844
- printf(" ptr %p\n", pPg);
52878
+ if( pLower==0 ){
52879
+ printf("%3d: NULL\n", i);
52880
+ }else{
52881
+ pPg = (PgHdr*)pLower->pExtra;
52882
+ printf("%3d: nRef %2lld flgs %02x data ", i, pPg->nRef, pPg->flags);
52883
+ a = (unsigned char *)pLower->pBuf;
52884
+ for(j=0; j<12; j++) printf("%02x", a[j]);
52885
+ printf(" ptr %p\n", pPg);
52886
+ }
5284552887
}
5284652888
static void pcacheDump(PCache *pCache){
5284752889
int N;
5284852890
int i;
5284952891
sqlite3_pcache_page *pLower;
@@ -52852,13 +52894,12 @@
5285252894
if( pCache->pCache==0 ) return;
5285352895
N = sqlite3PcachePagecount(pCache);
5285452896
if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
5285552897
for(i=1; i<=N; i++){
5285652898
pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
52857
- if( pLower==0 ) continue;
5285852899
pcachePageTrace(i, pLower);
52859
- if( ((PgHdr*)pLower)->pPage==0 ){
52900
+ if( pLower && ((PgHdr*)pLower)->pPage==0 ){
5286052901
sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
5286152902
}
5286252903
}
5286352904
}
5286452905
#else
@@ -58242,10 +58283,12 @@
5824258283
*/
5824358284
static int pager_truncate(Pager *pPager, Pgno nPage){
5824458285
int rc = SQLITE_OK;
5824558286
assert( pPager->eState!=PAGER_ERROR );
5824658287
assert( pPager->eState!=PAGER_READER );
58288
+ PAGERTRACE(("Truncate %d npage %u\n", PAGERID(pPager), nPage));
58289
+
5824758290
5824858291
if( isOpen(pPager->fd)
5824958292
&& (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
5825058293
){
5825158294
i64 currentSize, newSize;
@@ -61159,10 +61202,14 @@
6115961202
6116061203
assert( !isOpen(pPager->fd) || !MEMDB );
6116161204
if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
6116261205
if( pgno>pPager->mxPgno ){
6116361206
rc = SQLITE_FULL;
61207
+ if( pgno<=pPager->dbSize ){
61208
+ sqlite3PcacheRelease(pPg);
61209
+ pPg = 0;
61210
+ }
6116461211
goto pager_acquire_err;
6116561212
}
6116661213
if( noContent ){
6116761214
/* Failure to set the bits in the InJournal bit-vectors is benign.
6116861215
** It merely means that we might do some extra work to journal a
@@ -61323,14 +61370,16 @@
6132361370
}
6132461371
6132561372
/*
6132661373
** Release a page reference.
6132761374
**
61328
-** The sqlite3PagerUnref() and sqlite3PagerUnrefNotNull() may only be
61329
-** used if we know that the page being released is not the last page.
61375
+** The sqlite3PagerUnref() and sqlite3PagerUnrefNotNull() may only be used
61376
+** if we know that the page being released is not the last reference to page1.
6133061377
** The btree layer always holds page1 open until the end, so these first
61331
-** to routines can be used to release any page other than BtShared.pPage1.
61378
+** two routines can be used to release any page other than BtShared.pPage1.
61379
+** The assert() at tag-20230419-2 proves that this constraint is always
61380
+** honored.
6133261381
**
6133361382
** Use sqlite3PagerUnrefPageOne() to release page1. This latter routine
6133461383
** checks the total number of outstanding pages and if the number of
6133561384
** pages reaches zero it drops the database lock.
6133661385
*/
@@ -61342,11 +61391,11 @@
6134261391
pagerReleaseMapPage(pPg);
6134361392
}else{
6134461393
sqlite3PcacheRelease(pPg);
6134561394
}
6134661395
/* Do not use this routine to release the last reference to page1 */
61347
- assert( sqlite3PcacheRefCount(pPager->pPCache)>0 );
61396
+ assert( sqlite3PcacheRefCount(pPager->pPCache)>0 ); /* tag-20230419-2 */
6134861397
}
6134961398
SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
6135061399
if( pPg ) sqlite3PagerUnrefNotNull(pPg);
6135161400
}
6135261401
SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *pPg){
@@ -64113,23 +64162,44 @@
6411364162
}
6411464163
6411564164
assert( nByte>=8 );
6411664165
assert( (nByte&0x00000007)==0 );
6411764166
assert( nByte<=65536 );
64167
+ assert( nByte%4==0 );
6411864168
64119
- if( nativeCksum ){
64120
- do {
64121
- s1 += *aData++ + s2;
64122
- s2 += *aData++ + s1;
64123
- }while( aData<aEnd );
64124
- }else{
64169
+ if( !nativeCksum ){
6412564170
do {
6412664171
s1 += BYTESWAP32(aData[0]) + s2;
6412764172
s2 += BYTESWAP32(aData[1]) + s1;
6412864173
aData += 2;
6412964174
}while( aData<aEnd );
64175
+ }else if( nByte%64==0 ){
64176
+ do {
64177
+ s1 += *aData++ + s2;
64178
+ s2 += *aData++ + s1;
64179
+ s1 += *aData++ + s2;
64180
+ s2 += *aData++ + s1;
64181
+ s1 += *aData++ + s2;
64182
+ s2 += *aData++ + s1;
64183
+ s1 += *aData++ + s2;
64184
+ s2 += *aData++ + s1;
64185
+ s1 += *aData++ + s2;
64186
+ s2 += *aData++ + s1;
64187
+ s1 += *aData++ + s2;
64188
+ s2 += *aData++ + s1;
64189
+ s1 += *aData++ + s2;
64190
+ s2 += *aData++ + s1;
64191
+ s1 += *aData++ + s2;
64192
+ s2 += *aData++ + s1;
64193
+ }while( aData<aEnd );
64194
+ }else{
64195
+ do {
64196
+ s1 += *aData++ + s2;
64197
+ s2 += *aData++ + s1;
64198
+ }while( aData<aEnd );
6413064199
}
64200
+ assert( aData==aEnd );
6413164201
6413264202
aOut[0] = s1;
6413364203
aOut[1] = s2;
6413464204
}
6413564205
@@ -76202,11 +76272,11 @@
7620276272
aAfter[j] = iAfter;
7620376273
break;
7620476274
}
7620576275
}
7620676276
if( j>=nFree ){
76207
- if( nFree>=sizeof(aOfst)/sizeof(aOfst[0]) ){
76277
+ if( nFree>=(int)(sizeof(aOfst)/sizeof(aOfst[0])) ){
7620876278
for(j=0; j<nFree; j++){
7620976279
freeSpace(pPg, aOfst[j], aAfter[j]-aOfst[j]);
7621076280
}
7621176281
nFree = 0;
7621276282
}
@@ -77907,11 +77977,11 @@
7790777977
return btreeOverwriteCell(pCur, &x2);
7790877978
}
7790977979
}
7791077980
}
7791177981
assert( pCur->eState==CURSOR_VALID
77912
- || (pCur->eState==CURSOR_INVALID && loc) );
77982
+ || (pCur->eState==CURSOR_INVALID && loc) || CORRUPT_DB );
7791377983
7791477984
pPage = pCur->pPage;
7791577985
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
7791677986
assert( pPage->leaf || !pPage->intKey );
7791777987
if( pPage->nFree<0 ){
@@ -80157,17 +80227,11 @@
8015780227
assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
8015880228
assert( p->bDestLocked );
8015980229
assert( !isFatalError(p->rc) );
8016080230
assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
8016180231
assert( zSrcData );
80162
-
80163
- /* Catch the case where the destination is an in-memory database and the
80164
- ** page sizes of the source and destination differ.
80165
- */
80166
- if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){
80167
- rc = SQLITE_READONLY;
80168
- }
80232
+ assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
8016980233
8017080234
/* This loop runs once for each destination page spanned by the source
8017180235
** page. For each iteration, variable iOff is set to the byte offset
8017280236
** of the destination page.
8017380237
*/
@@ -80296,11 +80360,14 @@
8029680360
/* Do not allow backup if the destination database is in WAL mode
8029780361
** and the page sizes are different between source and destination */
8029880362
pgszSrc = sqlite3BtreeGetPageSize(p->pSrc);
8029980363
pgszDest = sqlite3BtreeGetPageSize(p->pDest);
8030080364
destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p->pDest));
80301
- if( SQLITE_OK==rc && destMode==PAGER_JOURNALMODE_WAL && pgszSrc!=pgszDest ){
80365
+ if( SQLITE_OK==rc
80366
+ && (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
80367
+ && pgszSrc!=pgszDest
80368
+ ){
8030280369
rc = SQLITE_READONLY;
8030380370
}
8030480371
8030580372
/* Now that there is a read-lock on the source database, query the
8030680373
** source pager for the number of pages in the database.
@@ -80845,10 +80912,11 @@
8084580912
Mem tmp;
8084680913
char zBuf[100];
8084780914
char *z;
8084880915
int i, j, incr;
8084980916
if( (p->flags & MEM_Str)==0 ) return 1;
80917
+ if( p->db && p->db->mallocFailed ) return 1;
8085080918
if( p->flags & MEM_Term ){
8085180919
/* Insure that the string is properly zero-terminated. Pay particular
8085280920
** attention to the case where p->n is odd */
8085380921
if( p->szMalloc>0 && p->z==p->zMalloc ){
8085480922
assert( p->enc==SQLITE_UTF8 || p->szMalloc >= ((p->n+1)&~1)+2 );
@@ -83508,10 +83576,12 @@
8350883576
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
8350983577
int nMaxArgs = *pMaxFuncArgs;
8351083578
Op *pOp;
8351183579
Parse *pParse = p->pParse;
8351283580
int *aLabel = pParse->aLabel;
83581
+
83582
+ assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
8351383583
p->readOnly = 1;
8351483584
p->bIsReader = 0;
8351583585
pOp = &p->aOp[p->nOp-1];
8351683586
assert( p->aOp[0].opcode==OP_Init );
8351783587
while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
@@ -83567,10 +83637,11 @@
8356783637
/* The mkopcodeh.tcl script has so arranged things that the only
8356883638
** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
8356983639
** have non-negative values for P2. */
8357083640
assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
8357183641
assert( ADDR(pOp->p2)<-pParse->nLabel );
83642
+ assert( aLabel!=0 ); /* True because of tag-20230419-1 */
8357283643
pOp->p2 = aLabel[ADDR(pOp->p2)];
8357383644
}
8357483645
break;
8357583646
}
8357683647
}
@@ -84310,11 +84381,11 @@
8431084381
}
8431184382
}
8431284383
8431384384
/* Return the most recently added opcode
8431484385
*/
84315
-VdbeOp * sqlite3VdbeGetLastOp(Vdbe *p){
84386
+SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetLastOp(Vdbe *p){
8431684387
return sqlite3VdbeGetOp(p, p->nOp - 1);
8431784388
}
8431884389
8431984390
#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
8432084391
/*
@@ -88039,10 +88110,20 @@
8803988110
sqlite3 *db = v->db;
8804088111
i64 iKey2;
8804188112
PreUpdate preupdate;
8804288113
const char *zTbl = pTab->zName;
8804388114
static const u8 fakeSortOrder = 0;
88115
+#ifdef SQLITE_DEBUG
88116
+ int nRealCol;
88117
+ if( pTab->tabFlags & TF_WithoutRowid ){
88118
+ nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn;
88119
+ }else if( pTab->tabFlags & TF_HasVirtual ){
88120
+ nRealCol = pTab->nNVCol;
88121
+ }else{
88122
+ nRealCol = pTab->nCol;
88123
+ }
88124
+#endif
8804488125
8804588126
assert( db->pPreUpdate==0 );
8804688127
memset(&preupdate, 0, sizeof(PreUpdate));
8804788128
if( HasRowid(pTab)==0 ){
8804888129
iKey1 = iKey2 = 0;
@@ -88055,12 +88136,12 @@
8805588136
}
8805688137
}
8805788138
8805888139
assert( pCsr!=0 );
8805988140
assert( pCsr->eCurType==CURTYPE_BTREE );
88060
- assert( pCsr->nField==pTab->nCol
88061
- || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1)
88141
+ assert( pCsr->nField==nRealCol
88142
+ || (pCsr->nField==nRealCol+1 && op==SQLITE_DELETE && iReg==-1)
8806288143
);
8806388144
8806488145
preupdate.v = v;
8806588146
preupdate.pCsr = pCsr;
8806688147
preupdate.op = op;
@@ -89429,13 +89510,13 @@
8942989510
p = (Vdbe *)pStmt;
8943089511
db = p->db;
8943189512
assert( db!=0 );
8943289513
n = sqlite3_column_count(pStmt);
8943389514
if( N<n && N>=0 ){
89515
+ u8 prior_mallocFailed = db->mallocFailed;
8943489516
N += useType*n;
8943589517
sqlite3_mutex_enter(db->mutex);
89436
- assert( db->mallocFailed==0 );
8943789518
#ifndef SQLITE_OMIT_UTF16
8943889519
if( useUtf16 ){
8943989520
ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
8944089521
}else
8944189522
#endif
@@ -89443,11 +89524,12 @@
8944389524
ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
8944489525
}
8944589526
/* A malloc may have failed inside of the _text() call. If this
8944689527
** is the case, clear the mallocFailed flag and return NULL.
8944789528
*/
89448
- if( db->mallocFailed ){
89529
+ assert( db->mallocFailed==0 || db->mallocFailed==1 );
89530
+ if( db->mallocFailed > prior_mallocFailed ){
8944989531
sqlite3OomClear(db);
8945089532
ret = 0;
8945189533
}
8945289534
sqlite3_mutex_leave(db->mutex);
8945389535
}
@@ -93333,11 +93415,11 @@
9333393415
*/
9333493416
case OP_IfNullRow: { /* jump */
9333593417
VdbeCursor *pC;
9333693418
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9333793419
pC = p->apCsr[pOp->p1];
93338
- if( ALWAYS(pC) && pC->nullRow ){
93420
+ if( pC && pC->nullRow ){
9333993421
sqlite3VdbeMemSetNull(aMem + pOp->p3);
9334093422
goto jump_to_p2;
9334193423
}
9334293424
break;
9334393425
}
@@ -93828,11 +93910,11 @@
9382893910
pIn1->flags |= MEM_IntReal;
9382993911
pIn1->flags &= ~MEM_Int;
9383093912
}else{
9383193913
pIn1->u.r = (double)pIn1->u.i;
9383293914
pIn1->flags |= MEM_Real;
93833
- pIn1->flags &= ~MEM_Int;
93915
+ pIn1->flags &= ~(MEM_Int|MEM_Str);
9383493916
}
9383593917
}
9383693918
REGISTER_TRACE((int)(pIn1-aMem), pIn1);
9383793919
zAffinity++;
9383893920
if( zAffinity[0]==0 ) break;
@@ -107198,28 +107280,31 @@
107198107280
107199107281
/*
107200107282
** Join two expressions using an AND operator. If either expression is
107201107283
** NULL, then just return the other expression.
107202107284
**
107203
-** If one side or the other of the AND is known to be false, then instead
107204
-** of returning an AND expression, just return a constant expression with
107205
-** a value of false.
107285
+** If one side or the other of the AND is known to be false, and neither side
107286
+** is part of an ON clause, then instead of returning an AND expression,
107287
+** just return a constant expression with a value of false.
107206107288
*/
107207107289
SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
107208107290
sqlite3 *db = pParse->db;
107209107291
if( pLeft==0 ){
107210107292
return pRight;
107211107293
}else if( pRight==0 ){
107212107294
return pLeft;
107213
- }else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight))
107214
- && !IN_RENAME_OBJECT
107215
- ){
107216
- sqlite3ExprDeferredDelete(pParse, pLeft);
107217
- sqlite3ExprDeferredDelete(pParse, pRight);
107218
- return sqlite3Expr(db, TK_INTEGER, "0");
107219107295
}else{
107220
- return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
107296
+ u32 f = pLeft->flags | pRight->flags;
107297
+ if( (f&(EP_OuterON|EP_InnerON|EP_IsFalse))==EP_IsFalse
107298
+ && !IN_RENAME_OBJECT
107299
+ ){
107300
+ sqlite3ExprDeferredDelete(pParse, pLeft);
107301
+ sqlite3ExprDeferredDelete(pParse, pRight);
107302
+ return sqlite3Expr(db, TK_INTEGER, "0");
107303
+ }else{
107304
+ return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
107305
+ }
107221107306
}
107222107307
}
107223107308
107224107309
/*
107225107310
** Construct a new expression node for a function with multiple
@@ -112373,11 +112458,11 @@
112373112458
int iAgg = pExpr->iAgg;
112374112459
Parse *pParse = pWalker->pParse;
112375112460
sqlite3 *db = pParse->db;
112376112461
assert( iAgg>=0 );
112377112462
if( pExpr->op!=TK_AGG_FUNCTION ){
112378
- if( ALWAYS(iAgg<pAggInfo->nColumn)
112463
+ if( iAgg<pAggInfo->nColumn
112379112464
&& pAggInfo->aCol[iAgg].pCExpr==pExpr
112380112465
){
112381112466
pExpr = sqlite3ExprDup(db, pExpr, 0);
112382112467
if( pExpr ){
112383112468
pAggInfo->aCol[iAgg].pCExpr = pExpr;
@@ -112578,11 +112663,11 @@
112578112663
findOrCreateAggInfoColumn(pParse, pAggInfo, pExpr);
112579112664
break;
112580112665
} /* endif pExpr->iTable==pItem->iCursor */
112581112666
} /* end loop over pSrcList */
112582112667
}
112583
- return WRC_Prune;
112668
+ return WRC_Continue;
112584112669
}
112585112670
case TK_AGG_FUNCTION: {
112586112671
if( (pNC->ncFlags & NC_InAggFunc)==0
112587112672
&& pWalker->walkerDepth==pExpr->op2
112588112673
){
@@ -114075,10 +114160,23 @@
114075114160
}
114076114161
114077114162
sqlite3_free(zQuot);
114078114163
return rc;
114079114164
}
114165
+
114166
+/*
114167
+** Set all pEList->a[].fg.eEName fields in the expression-list to val.
114168
+*/
114169
+static void renameSetENames(ExprList *pEList, int val){
114170
+ if( pEList ){
114171
+ int i;
114172
+ for(i=0; i<pEList->nExpr; i++){
114173
+ assert( val==ENAME_NAME || pEList->a[i].fg.eEName==ENAME_NAME );
114174
+ pEList->a[i].fg.eEName = val;
114175
+ }
114176
+ }
114177
+}
114080114178
114081114179
/*
114082114180
** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
114083114181
** it was read from the schema of database zDb. Return SQLITE_OK if
114084114182
** successful. Otherwise, return an SQLite error code and leave an error
@@ -114123,11 +114221,21 @@
114123114221
if( pSel==0 ){
114124114222
pStep->pExprList = 0;
114125114223
pSrc = 0;
114126114224
rc = SQLITE_NOMEM;
114127114225
}else{
114226
+ /* pStep->pExprList contains an expression-list used for an UPDATE
114227
+ ** statement. So the a[].zEName values are the RHS of the
114228
+ ** "<col> = <expr>" clauses of the UPDATE statement. So, before
114229
+ ** running SelectPrep(), change all the eEName values in
114230
+ ** pStep->pExprList to ENAME_SPAN (from their current value of
114231
+ ** ENAME_NAME). This is to prevent any ids in ON() clauses that are
114232
+ ** part of pSrc from being incorrectly resolved against the
114233
+ ** a[].zEName values as if they were column aliases. */
114234
+ renameSetENames(pStep->pExprList, ENAME_SPAN);
114128114235
sqlite3SelectPrep(pParse, pSel, 0);
114236
+ renameSetENames(pStep->pExprList, ENAME_NAME);
114129114237
rc = pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
114130114238
assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
114131114239
assert( pSrc==pSel->pSrc );
114132114240
if( pStep->pExprList ) pSel->pEList = 0;
114133114241
pSel->pSrc = 0;
@@ -116952,11 +117060,11 @@
116952117060
assert( db->lookaside.bDisable );
116953117061
if( (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0
116954117062
&& IsOrdinaryTable(pStat4)
116955117063
){
116956117064
rc = loadStatTbl(db,
116957
- "SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx",
117065
+ "SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx COLLATE nocase",
116958117066
"SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4",
116959117067
zDb
116960117068
);
116961117069
}
116962117070
return rc;
@@ -129027,26 +129135,26 @@
129027129135
zFrom = pFKey->pFrom->zName;
129028129136
nFrom = sqlite3Strlen30(zFrom);
129029129137
129030129138
if( action==OE_Restrict ){
129031129139
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
129032
- Token tFrom;
129033
- Token tDb;
129140
+ SrcList *pSrc;
129034129141
Expr *pRaise;
129035129142
129036
- tFrom.z = zFrom;
129037
- tFrom.n = nFrom;
129038
- tDb.z = db->aDb[iDb].zDbSName;
129039
- tDb.n = sqlite3Strlen30(tDb.z);
129040
-
129041129143
pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
129042129144
if( pRaise ){
129043129145
pRaise->affExpr = OE_Abort;
129044129146
}
129147
+ pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
129148
+ if( pSrc ){
129149
+ assert( pSrc->nSrc==1 );
129150
+ pSrc->a[0].zName = sqlite3DbStrDup(db, zFrom);
129151
+ pSrc->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
129152
+ }
129045129153
pSelect = sqlite3SelectNew(pParse,
129046129154
sqlite3ExprListAppend(pParse, 0, pRaise),
129047
- sqlite3SrcListAppend(pParse, 0, &tDb, &tFrom),
129155
+ pSrc,
129048129156
pWhere,
129049129157
0, 0, 0, 0, 0
129050129158
);
129051129159
pWhere = 0;
129052129160
}
@@ -137995,11 +138103,13 @@
137995138103
encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
137996138104
if( encoding==0 ) encoding = SQLITE_UTF8;
137997138105
#else
137998138106
encoding = SQLITE_UTF8;
137999138107
#endif
138000
- if( db->nVdbeActive>0 && encoding!=ENC(db) ){
138108
+ if( db->nVdbeActive>0 && encoding!=ENC(db)
138109
+ && (db->mDbFlags & DBFLAG_Vacuum)==0
138110
+ ){
138001138111
rc = SQLITE_LOCKED;
138002138112
goto initone_error_out;
138003138113
}else{
138004138114
sqlite3SetTextEncoding(db, encoding);
138005138115
}
@@ -138389,11 +138499,15 @@
138389138499
sParse.pOuterParse = db->pParse;
138390138500
db->pParse = &sParse;
138391138501
sParse.db = db;
138392138502
sParse.pReprepare = pReprepare;
138393138503
assert( ppStmt && *ppStmt==0 );
138394
- if( db->mallocFailed ) sqlite3ErrorMsg(&sParse, "out of memory");
138504
+ if( db->mallocFailed ){
138505
+ sqlite3ErrorMsg(&sParse, "out of memory");
138506
+ db->errCode = rc = SQLITE_NOMEM;
138507
+ goto end_prepare;
138508
+ }
138395138509
assert( sqlite3_mutex_held(db->mutex) );
138396138510
138397138511
/* For a long-term use prepared statement avoid the use of
138398138512
** lookaside memory.
138399138513
*/
@@ -141079,11 +141193,11 @@
141079141193
141080141194
assert( pSelect!=0 );
141081141195
assert( (pSelect->selFlags & SF_Resolved)!=0 );
141082141196
assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
141083141197
assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
141084
- if( db->mallocFailed ) return;
141198
+ if( db->mallocFailed || IN_RENAME_OBJECT ) return;
141085141199
while( pSelect->pPrior ) pSelect = pSelect->pPrior;
141086141200
a = pSelect->pEList->a;
141087141201
memset(&sNC, 0, sizeof(sNC));
141088141202
sNC.pSrcList = pSelect->pSrc;
141089141203
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
@@ -141124,22 +141238,20 @@
141124141238
if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
141125141239
zType = sqlite3StdType[j];
141126141240
break;
141127141241
}
141128141242
}
141129
- }
141130
- }
141131
- if( zType ){
141132
- i64 m = sqlite3Strlen30(zType);
141133
- n = sqlite3Strlen30(pCol->zCnName);
141134
- pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
141135
- if( pCol->zCnName ){
141136
- memcpy(&pCol->zCnName[n+1], zType, m+1);
141137
- pCol->colFlags |= COLFLAG_HASTYPE;
141138
- }else{
141139
- testcase( pCol->colFlags & COLFLAG_HASTYPE );
141140
- pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
141243
+ }
141244
+ }
141245
+ if( zType ){
141246
+ i64 m = sqlite3Strlen30(zType);
141247
+ n = sqlite3Strlen30(pCol->zCnName);
141248
+ pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
141249
+ pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
141250
+ if( pCol->zCnName ){
141251
+ memcpy(&pCol->zCnName[n+1], zType, m+1);
141252
+ pCol->colFlags |= COLFLAG_HASTYPE;
141141141253
}
141142141254
}
141143141255
pColl = sqlite3ExprCollSeq(pParse, p);
141144141256
if( pColl ){
141145141257
assert( pTab->pIndex==0 );
@@ -144027,15 +144139,17 @@
144027144139
if( pX->pPrior && pX->op!=TK_ALL ){
144028144140
/* This optimization does not work for compound subqueries that
144029144141
** use UNION, INTERSECT, or EXCEPT. Only UNION ALL is allowed. */
144030144142
return 0;
144031144143
}
144144
+#ifndef SQLITE_OMIT_WINDOWFUNC
144032144145
if( pX->pWin ){
144033144146
/* This optimization does not work for subqueries that use window
144034144147
** functions. */
144035144148
return 0;
144036144149
}
144150
+#endif
144037144151
}
144038144152
colUsed = pItem->colUsed;
144039144153
if( pSub->pOrderBy ){
144040144154
ExprList *pList = pSub->pOrderBy;
144041144155
for(j=0; j<pList->nExpr; j++){
@@ -145207,16 +145321,17 @@
145207145321
assert( pAggInfo->iFirstReg==0 );
145208145322
assert( pSelect!=0 );
145209145323
assert( pSelect->pGroupBy!=0 );
145210145324
pAggInfo->nColumn = pAggInfo->nAccumulator;
145211145325
if( ALWAYS(pAggInfo->nSortingColumn>0) ){
145212
- if( pAggInfo->nColumn==0 ){
145213
- pAggInfo->nSortingColumn = pSelect->pGroupBy->nExpr;
145214
- }else{
145215
- pAggInfo->nSortingColumn =
145216
- pAggInfo->aCol[pAggInfo->nColumn-1].iSorterColumn+1;
145326
+ int mx = pSelect->pGroupBy->nExpr - 1;
145327
+ int j, k;
145328
+ for(j=0; j<pAggInfo->nColumn; j++){
145329
+ k = pAggInfo->aCol[j].iSorterColumn;
145330
+ if( k>mx ) mx = k;
145217145331
}
145332
+ pAggInfo->nSortingColumn = mx+1;
145218145333
}
145219145334
analyzeAggFuncArgs(pAggInfo, pNC);
145220145335
#if TREETRACE_ENABLED
145221145336
if( sqlite3TreeTrace & 0x20 ){
145222145337
IndexedExpr *pIEpr;
@@ -153970,11 +154085,11 @@
153970154085
/* If we survive all prior tests, that means this term is worth hinting */
153971154086
pExpr = sqlite3ExprAnd(pParse, pExpr, sqlite3ExprDup(db, pTerm->pExpr, 0));
153972154087
}
153973154088
if( pExpr!=0 ){
153974154089
sWalker.xExprCallback = codeCursorHintFixExpr;
153975
- sqlite3WalkExpr(&sWalker, pExpr);
154090
+ if( pParse->nErr==0 ) sqlite3WalkExpr(&sWalker, pExpr);
153976154091
sqlite3VdbeAddOp4(v, OP_CursorHint,
153977154092
(sHint.pIdx ? sHint.iIdxCur : sHint.iTabCur), 0, 0,
153978154093
(const char*)pExpr, P4_EXPR);
153979154094
}
153980154095
}
@@ -163480,26 +163595,49 @@
163480163595
if( pSelect && pSelect->pLimit ){
163481163596
sqlite3WhereAddLimit(&pWInfo->sWC, pSelect);
163482163597
}
163483163598
if( pParse->nErr ) goto whereBeginError;
163484163599
163485
- /* Special case: WHERE terms that do not refer to any tables in the join
163486
- ** (constant expressions). Evaluate each such term, and jump over all the
163487
- ** generated code if the result is not true.
163488
- **
163489
- ** Do not do this if the expression contains non-deterministic functions
163490
- ** that are not within a sub-select. This is not strictly required, but
163491
- ** preserves SQLite's legacy behaviour in the following two cases:
163492
- **
163493
- ** FROM ... WHERE random()>0; -- eval random() once per row
163494
- ** FROM ... WHERE (SELECT random())>0; -- eval random() once overall
163600
+ /* The False-WHERE-Term-Bypass optimization:
163601
+ **
163602
+ ** If there are WHERE terms that are false, then no rows will be output,
163603
+ ** so skip over all of the code generated here.
163604
+ **
163605
+ ** Conditions:
163606
+ **
163607
+ ** (1) The WHERE term must not refer to any tables in the join.
163608
+ ** (2) The term must not come from an ON clause on the
163609
+ ** right-hand side of a LEFT or FULL JOIN.
163610
+ ** (3) The term must not come from an ON clause, or there must be
163611
+ ** no RIGHT or FULL OUTER joins in pTabList.
163612
+ ** (4) If the expression contains non-deterministic functions
163613
+ ** that are not within a sub-select. This is not required
163614
+ ** for correctness but rather to preserves SQLite's legacy
163615
+ ** behaviour in the following two cases:
163616
+ **
163617
+ ** WHERE random()>0; -- eval random() once per row
163618
+ ** WHERE (SELECT random())>0; -- eval random() just once overall
163619
+ **
163620
+ ** Note that the Where term need not be a constant in order for this
163621
+ ** optimization to apply, though it does need to be constant relative to
163622
+ ** the current subquery (condition 1). The term might include variables
163623
+ ** from outer queries so that the value of the term changes from one
163624
+ ** invocation of the current subquery to the next.
163495163625
*/
163496163626
for(ii=0; ii<sWLB.pWC->nBase; ii++){
163497
- WhereTerm *pT = &sWLB.pWC->a[ii];
163627
+ WhereTerm *pT = &sWLB.pWC->a[ii]; /* A term of the WHERE clause */
163628
+ Expr *pX; /* The expression of pT */
163498163629
if( pT->wtFlags & TERM_VIRTUAL ) continue;
163499
- if( pT->prereqAll==0 && (nTabList==0 || exprIsDeterministic(pT->pExpr)) ){
163500
- sqlite3ExprIfFalse(pParse, pT->pExpr, pWInfo->iBreak, SQLITE_JUMPIFNULL);
163630
+ pX = pT->pExpr;
163631
+ assert( pX!=0 );
163632
+ assert( pT->prereqAll!=0 || !ExprHasProperty(pX, EP_OuterON) );
163633
+ if( pT->prereqAll==0 /* Conditions (1) and (2) */
163634
+ && (nTabList==0 || exprIsDeterministic(pX)) /* Condition (4) */
163635
+ && !(ExprHasProperty(pX, EP_InnerON) /* Condition (3) */
163636
+ && (pTabList->a[0].fg.jointype & JT_LTORJ)!=0 )
163637
+ ){
163638
+ sqlite3ExprIfFalse(pParse, pX, pWInfo->iBreak, SQLITE_JUMPIFNULL);
163501163639
pT->wtFlags |= TERM_CODED;
163502163640
}
163503163641
}
163504163642
163505163643
if( wctrlFlags & WHERE_WANT_DISTINCT ){
@@ -165072,10 +165210,11 @@
165072165210
}
165073165211
}
165074165212
}
165075165213
/* no break */ deliberate_fall_through
165076165214
165215
+ case TK_IF_NULL_ROW:
165077165216
case TK_AGG_FUNCTION:
165078165217
case TK_COLUMN: {
165079165218
int iCol = -1;
165080165219
if( pParse->db->mallocFailed ) return WRC_Abort;
165081165220
if( p->pSub ){
@@ -167902,11 +168041,11 @@
167902168041
#define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
167903168042
#define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
167904168043
#define YYFALLBACK 1
167905168044
#define YYNSTATE 575
167906168045
#define YYNRULE 403
167907
-#define YYNRULE_WITH_ACTION 341
168046
+#define YYNRULE_WITH_ACTION 340
167908168047
#define YYNTOKEN 185
167909168048
#define YY_MAX_SHIFT 574
167910168049
#define YY_MIN_SHIFTREDUCE 833
167911168050
#define YY_MAX_SHIFTREDUCE 1235
167912168051
#define YY_ERROR_ACTION 1236
@@ -167982,145 +168121,145 @@
167982168121
*********** Begin parsing tables **********************************************/
167983168122
#define YY_ACTTAB_COUNT (2096)
167984168123
static const YYACTIONTYPE yy_action[] = {
167985168124
/* 0 */ 568, 208, 568, 118, 115, 229, 568, 118, 115, 229,
167986168125
/* 10 */ 568, 1310, 377, 1289, 408, 562, 562, 562, 568, 409,
167987
- /* 20 */ 378, 1310, 1272, 41, 41, 41, 41, 208, 1521, 71,
168126
+ /* 20 */ 378, 1310, 1272, 41, 41, 41, 41, 208, 1520, 71,
167988168127
/* 30 */ 71, 969, 419, 41, 41, 491, 303, 279, 303, 970,
167989
- /* 40 */ 397, 71, 71, 125, 126, 80, 1213, 1213, 1047, 1050,
168128
+ /* 40 */ 397, 71, 71, 125, 126, 80, 1212, 1212, 1047, 1050,
167990168129
/* 50 */ 1037, 1037, 123, 123, 124, 124, 124, 124, 476, 409,
167991168130
/* 60 */ 1237, 1, 1, 574, 2, 1241, 550, 118, 115, 229,
167992168131
/* 70 */ 317, 480, 146, 480, 524, 118, 115, 229, 529, 1323,
167993
- /* 80 */ 417, 523, 142, 125, 126, 80, 1213, 1213, 1047, 1050,
168132
+ /* 80 */ 417, 523, 142, 125, 126, 80, 1212, 1212, 1047, 1050,
167994168133
/* 90 */ 1037, 1037, 123, 123, 124, 124, 124, 124, 118, 115,
167995168134
/* 100 */ 229, 327, 122, 122, 122, 122, 121, 121, 120, 120,
167996168135
/* 110 */ 120, 119, 116, 444, 284, 284, 284, 284, 442, 442,
167997
- /* 120 */ 442, 1562, 376, 1564, 1189, 375, 1160, 565, 1160, 565,
167998
- /* 130 */ 409, 1562, 537, 259, 226, 444, 101, 145, 449, 316,
168136
+ /* 120 */ 442, 1561, 376, 1563, 1188, 375, 1159, 565, 1159, 565,
168137
+ /* 130 */ 409, 1561, 537, 259, 226, 444, 101, 145, 449, 316,
167999168138
/* 140 */ 559, 240, 122, 122, 122, 122, 121, 121, 120, 120,
168000
- /* 150 */ 120, 119, 116, 444, 125, 126, 80, 1213, 1213, 1047,
168139
+ /* 150 */ 120, 119, 116, 444, 125, 126, 80, 1212, 1212, 1047,
168001168140
/* 160 */ 1050, 1037, 1037, 123, 123, 124, 124, 124, 124, 142,
168002
- /* 170 */ 294, 1189, 339, 448, 120, 120, 120, 119, 116, 444,
168003
- /* 180 */ 127, 1189, 1190, 1189, 148, 441, 440, 568, 119, 116,
168141
+ /* 170 */ 294, 1188, 339, 448, 120, 120, 120, 119, 116, 444,
168142
+ /* 180 */ 127, 1188, 1189, 1188, 148, 441, 440, 568, 119, 116,
168004168143
/* 190 */ 444, 124, 124, 124, 124, 117, 122, 122, 122, 122,
168005168144
/* 200 */ 121, 121, 120, 120, 120, 119, 116, 444, 454, 113,
168006168145
/* 210 */ 13, 13, 546, 122, 122, 122, 122, 121, 121, 120,
168007
- /* 220 */ 120, 120, 119, 116, 444, 422, 316, 559, 1189, 1190,
168008
- /* 230 */ 1189, 149, 1220, 409, 1220, 124, 124, 124, 124, 122,
168146
+ /* 220 */ 120, 120, 119, 116, 444, 422, 316, 559, 1188, 1189,
168147
+ /* 230 */ 1188, 149, 1220, 409, 1220, 124, 124, 124, 124, 122,
168009168148
/* 240 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
168010168149
/* 250 */ 444, 465, 342, 1034, 1034, 1048, 1051, 125, 126, 80,
168011
- /* 260 */ 1213, 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124,
168012
- /* 270 */ 124, 124, 1275, 522, 222, 1189, 568, 409, 224, 514,
168150
+ /* 260 */ 1212, 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124,
168151
+ /* 270 */ 124, 124, 1275, 522, 222, 1188, 568, 409, 224, 514,
168013168152
/* 280 */ 175, 82, 83, 122, 122, 122, 122, 121, 121, 120,
168014
- /* 290 */ 120, 120, 119, 116, 444, 1005, 16, 16, 1189, 133,
168015
- /* 300 */ 133, 125, 126, 80, 1213, 1213, 1047, 1050, 1037, 1037,
168153
+ /* 290 */ 120, 120, 119, 116, 444, 1005, 16, 16, 1188, 133,
168154
+ /* 300 */ 133, 125, 126, 80, 1212, 1212, 1047, 1050, 1037, 1037,
168016168155
/* 310 */ 123, 123, 124, 124, 124, 124, 122, 122, 122, 122,
168017168156
/* 320 */ 121, 121, 120, 120, 120, 119, 116, 444, 1038, 546,
168018
- /* 330 */ 1189, 373, 1189, 1190, 1189, 252, 1429, 399, 504, 501,
168157
+ /* 330 */ 1188, 373, 1188, 1189, 1188, 252, 1429, 399, 504, 501,
168019168158
/* 340 */ 500, 111, 560, 566, 4, 924, 924, 433, 499, 340,
168020
- /* 350 */ 460, 328, 360, 394, 1233, 1189, 1190, 1189, 563, 568,
168159
+ /* 350 */ 460, 328, 360, 394, 1233, 1188, 1189, 1188, 563, 568,
168021168160
/* 360 */ 122, 122, 122, 122, 121, 121, 120, 120, 120, 119,
168022
- /* 370 */ 116, 444, 284, 284, 369, 1575, 1601, 441, 440, 154,
168023
- /* 380 */ 409, 445, 71, 71, 1282, 565, 1217, 1189, 1190, 1189,
168024
- /* 390 */ 85, 1219, 271, 557, 543, 515, 1556, 568, 98, 1218,
168025
- /* 400 */ 6, 1274, 472, 142, 125, 126, 80, 1213, 1213, 1047,
168161
+ /* 370 */ 116, 444, 284, 284, 369, 1574, 1600, 441, 440, 154,
168162
+ /* 380 */ 409, 445, 71, 71, 1282, 565, 1217, 1188, 1189, 1188,
168163
+ /* 390 */ 85, 1219, 271, 557, 543, 515, 1555, 568, 98, 1218,
168164
+ /* 400 */ 6, 1274, 472, 142, 125, 126, 80, 1212, 1212, 1047,
168026168165
/* 410 */ 1050, 1037, 1037, 123, 123, 124, 124, 124, 124, 550,
168027
- /* 420 */ 13, 13, 1024, 507, 1220, 1189, 1220, 549, 109, 109,
168166
+ /* 420 */ 13, 13, 1024, 507, 1220, 1188, 1220, 549, 109, 109,
168028168167
/* 430 */ 222, 568, 1234, 175, 568, 427, 110, 197, 445, 569,
168029
- /* 440 */ 445, 430, 1547, 1014, 325, 551, 1189, 270, 287, 368,
168168
+ /* 440 */ 445, 430, 1546, 1014, 325, 551, 1188, 270, 287, 368,
168030168169
/* 450 */ 510, 363, 509, 257, 71, 71, 543, 71, 71, 359,
168031
- /* 460 */ 316, 559, 1607, 122, 122, 122, 122, 121, 121, 120,
168170
+ /* 460 */ 316, 559, 1606, 122, 122, 122, 122, 121, 121, 120,
168032168171
/* 470 */ 120, 120, 119, 116, 444, 1014, 1014, 1016, 1017, 27,
168033
- /* 480 */ 284, 284, 1189, 1190, 1189, 1155, 568, 1606, 409, 899,
168034
- /* 490 */ 190, 550, 356, 565, 550, 935, 533, 517, 1155, 516,
168035
- /* 500 */ 413, 1155, 552, 1189, 1190, 1189, 568, 544, 1549, 51,
168036
- /* 510 */ 51, 214, 125, 126, 80, 1213, 1213, 1047, 1050, 1037,
168037
- /* 520 */ 1037, 123, 123, 124, 124, 124, 124, 1189, 474, 135,
168038
- /* 530 */ 135, 409, 284, 284, 1485, 505, 121, 121, 120, 120,
168039
- /* 540 */ 120, 119, 116, 444, 1005, 565, 518, 217, 541, 1556,
168040
- /* 550 */ 316, 559, 142, 6, 532, 125, 126, 80, 1213, 1213,
168172
+ /* 480 */ 284, 284, 1188, 1189, 1188, 1154, 568, 1605, 409, 899,
168173
+ /* 490 */ 190, 550, 356, 565, 550, 935, 533, 517, 1154, 516,
168174
+ /* 500 */ 413, 1154, 552, 1188, 1189, 1188, 568, 544, 1548, 51,
168175
+ /* 510 */ 51, 214, 125, 126, 80, 1212, 1212, 1047, 1050, 1037,
168176
+ /* 520 */ 1037, 123, 123, 124, 124, 124, 124, 1188, 474, 135,
168177
+ /* 530 */ 135, 409, 284, 284, 1484, 505, 121, 121, 120, 120,
168178
+ /* 540 */ 120, 119, 116, 444, 1005, 565, 518, 217, 541, 1555,
168179
+ /* 550 */ 316, 559, 142, 6, 532, 125, 126, 80, 1212, 1212,
168041168180
/* 560 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168042
- /* 570 */ 1550, 122, 122, 122, 122, 121, 121, 120, 120, 120,
168043
- /* 580 */ 119, 116, 444, 485, 1189, 1190, 1189, 482, 281, 1263,
168044
- /* 590 */ 955, 252, 1189, 373, 504, 501, 500, 1189, 340, 570,
168045
- /* 600 */ 1189, 570, 409, 292, 499, 955, 874, 191, 480, 316,
168181
+ /* 570 */ 1549, 122, 122, 122, 122, 121, 121, 120, 120, 120,
168182
+ /* 580 */ 119, 116, 444, 485, 1188, 1189, 1188, 482, 281, 1263,
168183
+ /* 590 */ 955, 252, 1188, 373, 504, 501, 500, 1188, 340, 570,
168184
+ /* 600 */ 1188, 570, 409, 292, 499, 955, 874, 191, 480, 316,
168046168185
/* 610 */ 559, 384, 290, 380, 122, 122, 122, 122, 121, 121,
168047
- /* 620 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1213,
168048
- /* 630 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168049
- /* 640 */ 124, 409, 394, 1133, 1189, 867, 100, 284, 284, 1189,
168050
- /* 650 */ 1190, 1189, 373, 1090, 1189, 1190, 1189, 1189, 1190, 1189,
168051
- /* 660 */ 565, 455, 32, 373, 233, 125, 126, 80, 1213, 1213,
168186
+ /* 620 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1212,
168187
+ /* 630 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168188
+ /* 640 */ 124, 409, 394, 1132, 1188, 867, 100, 284, 284, 1188,
168189
+ /* 650 */ 1189, 1188, 373, 1089, 1188, 1189, 1188, 1188, 1189, 1188,
168190
+ /* 660 */ 565, 455, 32, 373, 233, 125, 126, 80, 1212, 1212,
168052168191
/* 670 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168053168192
/* 680 */ 1428, 957, 568, 228, 956, 122, 122, 122, 122, 121,
168054
- /* 690 */ 121, 120, 120, 120, 119, 116, 444, 1155, 228, 1189,
168055
- /* 700 */ 157, 1189, 1190, 1189, 1548, 13, 13, 301, 955, 1228,
168056
- /* 710 */ 1155, 153, 409, 1155, 373, 1578, 1173, 5, 369, 1575,
168193
+ /* 690 */ 121, 120, 120, 120, 119, 116, 444, 1154, 228, 1188,
168194
+ /* 700 */ 157, 1188, 1189, 1188, 1547, 13, 13, 301, 955, 1228,
168195
+ /* 710 */ 1154, 153, 409, 1154, 373, 1577, 1172, 5, 369, 1574,
168057168196
/* 720 */ 429, 1234, 3, 955, 122, 122, 122, 122, 121, 121,
168058
- /* 730 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1213,
168059
- /* 740 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168060
- /* 750 */ 124, 409, 208, 567, 1189, 1025, 1189, 1190, 1189, 1189,
168061
- /* 760 */ 388, 850, 155, 1547, 286, 402, 1095, 1095, 488, 568,
168062
- /* 770 */ 465, 342, 1315, 1315, 1547, 125, 126, 80, 1213, 1213,
168197
+ /* 730 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1212,
168198
+ /* 740 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168199
+ /* 750 */ 124, 409, 208, 567, 1188, 1025, 1188, 1189, 1188, 1188,
168200
+ /* 760 */ 388, 850, 155, 1546, 286, 402, 1094, 1094, 488, 568,
168201
+ /* 770 */ 465, 342, 1315, 1315, 1546, 125, 126, 80, 1212, 1212,
168063168202
/* 780 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168064168203
/* 790 */ 129, 568, 13, 13, 374, 122, 122, 122, 122, 121,
168065168204
/* 800 */ 121, 120, 120, 120, 119, 116, 444, 302, 568, 453,
168066
- /* 810 */ 528, 1189, 1190, 1189, 13, 13, 1189, 1190, 1189, 1293,
168067
- /* 820 */ 463, 1263, 409, 1313, 1313, 1547, 1010, 453, 452, 200,
168205
+ /* 810 */ 528, 1188, 1189, 1188, 13, 13, 1188, 1189, 1188, 1293,
168206
+ /* 820 */ 463, 1263, 409, 1313, 1313, 1546, 1010, 453, 452, 200,
168068168207
/* 830 */ 299, 71, 71, 1261, 122, 122, 122, 122, 121, 121,
168069
- /* 840 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1213,
168070
- /* 850 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168071
- /* 860 */ 124, 409, 227, 1070, 1155, 284, 284, 419, 312, 278,
168072
- /* 870 */ 278, 285, 285, 1415, 406, 405, 382, 1155, 565, 568,
168073
- /* 880 */ 1155, 1192, 565, 1595, 565, 125, 126, 80, 1213, 1213,
168208
+ /* 840 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1212,
168209
+ /* 850 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168210
+ /* 860 */ 124, 409, 227, 1069, 1154, 284, 284, 419, 312, 278,
168211
+ /* 870 */ 278, 285, 285, 1415, 406, 405, 382, 1154, 565, 568,
168212
+ /* 880 */ 1154, 1191, 565, 1594, 565, 125, 126, 80, 1212, 1212,
168074168213
/* 890 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168075
- /* 900 */ 453, 1477, 13, 13, 1531, 122, 122, 122, 122, 121,
168214
+ /* 900 */ 453, 1476, 13, 13, 1530, 122, 122, 122, 122, 121,
168076168215
/* 910 */ 121, 120, 120, 120, 119, 116, 444, 201, 568, 354,
168077
- /* 920 */ 1581, 574, 2, 1241, 838, 839, 840, 1557, 317, 1208,
168078
- /* 930 */ 146, 6, 409, 255, 254, 253, 206, 1323, 9, 1192,
168216
+ /* 920 */ 1580, 574, 2, 1241, 838, 839, 840, 1556, 317, 1207,
168217
+ /* 930 */ 146, 6, 409, 255, 254, 253, 206, 1323, 9, 1191,
168079168218
/* 940 */ 262, 71, 71, 424, 122, 122, 122, 122, 121, 121,
168080
- /* 950 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1213,
168081
- /* 960 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168082
- /* 970 */ 124, 568, 284, 284, 568, 1209, 409, 573, 313, 1241,
168219
+ /* 950 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1212,
168220
+ /* 960 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168221
+ /* 970 */ 124, 568, 284, 284, 568, 1208, 409, 573, 313, 1241,
168083168222
/* 980 */ 349, 1292, 352, 419, 317, 565, 146, 491, 525, 1637,
168084168223
/* 990 */ 395, 371, 491, 1323, 70, 70, 1291, 71, 71, 240,
168085
- /* 1000 */ 1321, 104, 80, 1213, 1213, 1047, 1050, 1037, 1037, 123,
168224
+ /* 1000 */ 1321, 104, 80, 1212, 1212, 1047, 1050, 1037, 1037, 123,
168086168225
/* 1010 */ 123, 124, 124, 124, 124, 122, 122, 122, 122, 121,
168087
- /* 1020 */ 121, 120, 120, 120, 119, 116, 444, 1111, 284, 284,
168088
- /* 1030 */ 428, 448, 1520, 1209, 439, 284, 284, 1484, 1348, 311,
168089
- /* 1040 */ 474, 565, 1112, 969, 491, 491, 217, 1259, 565, 1533,
168090
- /* 1050 */ 568, 970, 207, 568, 1024, 240, 383, 1113, 519, 122,
168226
+ /* 1020 */ 121, 120, 120, 120, 119, 116, 444, 1110, 284, 284,
168227
+ /* 1030 */ 428, 448, 1519, 1208, 439, 284, 284, 1483, 1348, 311,
168228
+ /* 1040 */ 474, 565, 1111, 969, 491, 491, 217, 1259, 565, 1532,
168229
+ /* 1050 */ 568, 970, 207, 568, 1024, 240, 383, 1112, 519, 122,
168091168230
/* 1060 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
168092168231
/* 1070 */ 444, 1015, 107, 71, 71, 1014, 13, 13, 910, 568,
168093
- /* 1080 */ 1490, 568, 284, 284, 97, 526, 491, 448, 911, 1322,
168094
- /* 1090 */ 1318, 545, 409, 284, 284, 565, 151, 209, 1490, 1492,
168232
+ /* 1080 */ 1489, 568, 284, 284, 97, 526, 491, 448, 911, 1322,
168233
+ /* 1090 */ 1318, 545, 409, 284, 284, 565, 151, 209, 1489, 1491,
168095168234
/* 1100 */ 262, 450, 55, 55, 56, 56, 565, 1014, 1014, 1016,
168096
- /* 1110 */ 443, 332, 409, 527, 12, 295, 125, 126, 80, 1213,
168097
- /* 1120 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168098
- /* 1130 */ 124, 347, 409, 862, 1529, 1209, 125, 126, 80, 1213,
168099
- /* 1140 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168100
- /* 1150 */ 124, 1134, 1635, 474, 1635, 371, 125, 114, 80, 1213,
168101
- /* 1160 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168102
- /* 1170 */ 124, 1490, 329, 474, 331, 122, 122, 122, 122, 121,
168235
+ /* 1110 */ 443, 332, 409, 527, 12, 295, 125, 126, 80, 1212,
168236
+ /* 1120 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168237
+ /* 1130 */ 124, 347, 409, 862, 1528, 1208, 125, 126, 80, 1212,
168238
+ /* 1140 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168239
+ /* 1150 */ 124, 1133, 1635, 474, 1635, 371, 125, 114, 80, 1212,
168240
+ /* 1160 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168241
+ /* 1170 */ 124, 1489, 329, 474, 331, 122, 122, 122, 122, 121,
168103168242
/* 1180 */ 121, 120, 120, 120, 119, 116, 444, 203, 1415, 568,
168104
- /* 1190 */ 1290, 862, 464, 1209, 436, 122, 122, 122, 122, 121,
168105
- /* 1200 */ 121, 120, 120, 120, 119, 116, 444, 553, 1134, 1636,
168243
+ /* 1190 */ 1290, 862, 464, 1208, 436, 122, 122, 122, 122, 121,
168244
+ /* 1200 */ 121, 120, 120, 120, 119, 116, 444, 553, 1133, 1636,
168106168245
/* 1210 */ 539, 1636, 15, 15, 890, 122, 122, 122, 122, 121,
168107168246
/* 1220 */ 121, 120, 120, 120, 119, 116, 444, 568, 298, 538,
168108
- /* 1230 */ 1132, 1415, 1554, 1555, 1327, 409, 6, 6, 1166, 1264,
168247
+ /* 1230 */ 1131, 1415, 1553, 1554, 1327, 409, 6, 6, 1165, 1264,
168109168248
/* 1240 */ 415, 320, 284, 284, 1415, 508, 565, 525, 300, 457,
168110168249
/* 1250 */ 43, 43, 568, 891, 12, 565, 330, 478, 425, 407,
168111
- /* 1260 */ 126, 80, 1213, 1213, 1047, 1050, 1037, 1037, 123, 123,
168112
- /* 1270 */ 124, 124, 124, 124, 568, 57, 57, 288, 1189, 1415,
168113
- /* 1280 */ 496, 458, 392, 392, 391, 273, 389, 1132, 1553, 847,
168114
- /* 1290 */ 1166, 407, 6, 568, 321, 1155, 470, 44, 44, 1552,
168115
- /* 1300 */ 1111, 426, 234, 6, 323, 256, 540, 256, 1155, 431,
168116
- /* 1310 */ 568, 1155, 322, 17, 487, 1112, 58, 58, 122, 122,
168250
+ /* 1260 */ 126, 80, 1212, 1212, 1047, 1050, 1037, 1037, 123, 123,
168251
+ /* 1270 */ 124, 124, 124, 124, 568, 57, 57, 288, 1188, 1415,
168252
+ /* 1280 */ 496, 458, 392, 392, 391, 273, 389, 1131, 1552, 847,
168253
+ /* 1290 */ 1165, 407, 6, 568, 321, 1154, 470, 44, 44, 1551,
168254
+ /* 1300 */ 1110, 426, 234, 6, 323, 256, 540, 256, 1154, 431,
168255
+ /* 1310 */ 568, 1154, 322, 17, 487, 1111, 58, 58, 122, 122,
168117168256
/* 1320 */ 122, 122, 121, 121, 120, 120, 120, 119, 116, 444,
168118
- /* 1330 */ 1113, 216, 481, 59, 59, 1189, 1190, 1189, 111, 560,
168257
+ /* 1330 */ 1112, 216, 481, 59, 59, 1188, 1189, 1188, 111, 560,
168119168258
/* 1340 */ 324, 4, 236, 456, 526, 568, 237, 456, 568, 437,
168120
- /* 1350 */ 168, 556, 420, 141, 479, 563, 568, 293, 568, 1092,
168121
- /* 1360 */ 568, 293, 568, 1092, 531, 568, 870, 8, 60, 60,
168259
+ /* 1350 */ 168, 556, 420, 141, 479, 563, 568, 293, 568, 1091,
168260
+ /* 1360 */ 568, 293, 568, 1091, 531, 568, 870, 8, 60, 60,
168122168261
/* 1370 */ 235, 61, 61, 568, 414, 568, 414, 568, 445, 62,
168123168262
/* 1380 */ 62, 45, 45, 46, 46, 47, 47, 199, 49, 49,
168124168263
/* 1390 */ 557, 568, 359, 568, 100, 486, 50, 50, 63, 63,
168125168264
/* 1400 */ 64, 64, 561, 415, 535, 410, 568, 1024, 568, 534,
168126168265
/* 1410 */ 316, 559, 316, 559, 65, 65, 14, 14, 568, 1024,
@@ -168127,73 +168266,73 @@
168127168266
/* 1420 */ 568, 512, 930, 870, 1015, 109, 109, 929, 1014, 66,
168128168267
/* 1430 */ 66, 131, 131, 110, 451, 445, 569, 445, 416, 177,
168129168268
/* 1440 */ 1014, 132, 132, 67, 67, 568, 467, 568, 930, 471,
168130168269
/* 1450 */ 1360, 283, 226, 929, 315, 1359, 407, 568, 459, 407,
168131168270
/* 1460 */ 1014, 1014, 1016, 239, 407, 86, 213, 1346, 52, 52,
168132
- /* 1470 */ 68, 68, 1014, 1014, 1016, 1017, 27, 1580, 1177, 447,
168133
- /* 1480 */ 69, 69, 288, 97, 108, 1536, 106, 392, 392, 391,
168271
+ /* 1470 */ 68, 68, 1014, 1014, 1016, 1017, 27, 1579, 1176, 447,
168272
+ /* 1480 */ 69, 69, 288, 97, 108, 1535, 106, 392, 392, 391,
168134168273
/* 1490 */ 273, 389, 568, 877, 847, 881, 568, 111, 560, 466,
168135
- /* 1500 */ 4, 568, 152, 30, 38, 568, 1129, 234, 396, 323,
168274
+ /* 1500 */ 4, 568, 152, 30, 38, 568, 1128, 234, 396, 323,
168136168275
/* 1510 */ 111, 560, 527, 4, 563, 53, 53, 322, 568, 163,
168137168276
/* 1520 */ 163, 568, 337, 468, 164, 164, 333, 563, 76, 76,
168138
- /* 1530 */ 568, 289, 1509, 568, 31, 1508, 568, 445, 338, 483,
168139
- /* 1540 */ 100, 54, 54, 344, 72, 72, 296, 236, 1077, 557,
168277
+ /* 1530 */ 568, 289, 1508, 568, 31, 1507, 568, 445, 338, 483,
168278
+ /* 1540 */ 100, 54, 54, 344, 72, 72, 296, 236, 1076, 557,
168140168279
/* 1550 */ 445, 877, 1356, 134, 134, 168, 73, 73, 141, 161,
168141
- /* 1560 */ 161, 1569, 557, 535, 568, 319, 568, 348, 536, 1007,
168280
+ /* 1560 */ 161, 1568, 557, 535, 568, 319, 568, 348, 536, 1007,
168142168281
/* 1570 */ 473, 261, 261, 889, 888, 235, 535, 568, 1024, 568,
168143168282
/* 1580 */ 475, 534, 261, 367, 109, 109, 521, 136, 136, 130,
168144168283
/* 1590 */ 130, 1024, 110, 366, 445, 569, 445, 109, 109, 1014,
168145
- /* 1600 */ 162, 162, 156, 156, 568, 110, 1077, 445, 569, 445,
168284
+ /* 1600 */ 162, 162, 156, 156, 568, 110, 1076, 445, 569, 445,
168146168285
/* 1610 */ 410, 351, 1014, 568, 353, 316, 559, 568, 343, 568,
168147168286
/* 1620 */ 100, 497, 357, 258, 100, 896, 897, 140, 140, 355,
168148168287
/* 1630 */ 1306, 1014, 1014, 1016, 1017, 27, 139, 139, 362, 451,
168149
- /* 1640 */ 137, 137, 138, 138, 1014, 1014, 1016, 1017, 27, 1177,
168288
+ /* 1640 */ 137, 137, 138, 138, 1014, 1014, 1016, 1017, 27, 1176,
168150168289
/* 1650 */ 447, 568, 372, 288, 111, 560, 1018, 4, 392, 392,
168151
- /* 1660 */ 391, 273, 389, 568, 1138, 847, 568, 1073, 568, 258,
168290
+ /* 1660 */ 391, 273, 389, 568, 1137, 847, 568, 1072, 568, 258,
168152168291
/* 1670 */ 492, 563, 568, 211, 75, 75, 555, 960, 234, 261,
168153168292
/* 1680 */ 323, 111, 560, 927, 4, 113, 77, 77, 322, 74,
168154168293
/* 1690 */ 74, 42, 42, 1369, 445, 48, 48, 1414, 563, 972,
168155
- /* 1700 */ 973, 1089, 1088, 1089, 1088, 860, 557, 150, 928, 1342,
168294
+ /* 1700 */ 973, 1088, 1087, 1088, 1087, 860, 557, 150, 928, 1342,
168156168295
/* 1710 */ 113, 1354, 554, 1419, 1018, 1271, 1262, 1250, 236, 1249,
168157
- /* 1720 */ 1251, 445, 1588, 1339, 308, 276, 168, 309, 11, 141,
168296
+ /* 1720 */ 1251, 445, 1587, 1339, 308, 276, 168, 309, 11, 141,
168158168297
/* 1730 */ 393, 310, 232, 557, 1401, 1024, 335, 291, 1396, 219,
168159168298
/* 1740 */ 336, 109, 109, 934, 297, 1406, 235, 341, 477, 110,
168160168299
/* 1750 */ 502, 445, 569, 445, 1389, 1405, 1014, 400, 1289, 365,
168161
- /* 1760 */ 223, 1481, 1024, 1480, 1351, 1352, 1350, 1349, 109, 109,
168162
- /* 1770 */ 204, 1591, 1228, 558, 265, 218, 110, 205, 445, 569,
168163
- /* 1780 */ 445, 410, 387, 1014, 1528, 179, 316, 559, 1014, 1014,
168164
- /* 1790 */ 1016, 1017, 27, 230, 1526, 1225, 79, 560, 85, 4,
168300
+ /* 1760 */ 223, 1480, 1024, 1479, 1351, 1352, 1350, 1349, 109, 109,
168301
+ /* 1770 */ 204, 1590, 1228, 558, 265, 218, 110, 205, 445, 569,
168302
+ /* 1780 */ 445, 410, 387, 1014, 1527, 179, 316, 559, 1014, 1014,
168303
+ /* 1790 */ 1016, 1017, 27, 230, 1525, 1225, 79, 560, 85, 4,
168165168304
/* 1800 */ 418, 215, 548, 81, 84, 188, 1402, 173, 181, 461,
168166168305
/* 1810 */ 451, 35, 462, 563, 183, 1014, 1014, 1016, 1017, 27,
168167
- /* 1820 */ 184, 1486, 185, 186, 495, 242, 98, 398, 1408, 36,
168168
- /* 1830 */ 1407, 484, 91, 469, 401, 1410, 445, 192, 1475, 246,
168169
- /* 1840 */ 1497, 490, 346, 277, 248, 196, 493, 511, 557, 350,
168306
+ /* 1820 */ 184, 1485, 185, 186, 495, 242, 98, 398, 1408, 36,
168307
+ /* 1830 */ 1407, 484, 91, 469, 401, 1410, 445, 192, 1474, 246,
168308
+ /* 1840 */ 1496, 490, 346, 277, 248, 196, 493, 511, 557, 350,
168170168309
/* 1850 */ 1252, 249, 250, 403, 1309, 1308, 111, 560, 432, 4,
168171
- /* 1860 */ 1307, 1300, 93, 1605, 881, 1604, 224, 404, 434, 520,
168172
- /* 1870 */ 263, 435, 1574, 563, 1279, 1278, 364, 1024, 306, 1277,
168173
- /* 1880 */ 264, 1603, 1560, 109, 109, 370, 1299, 307, 1559, 438,
168310
+ /* 1860 */ 1307, 1300, 93, 1604, 881, 1603, 224, 404, 434, 520,
168311
+ /* 1870 */ 263, 435, 1573, 563, 1279, 1278, 364, 1024, 306, 1277,
168312
+ /* 1880 */ 264, 1602, 1559, 109, 109, 370, 1299, 307, 1558, 438,
168174168313
/* 1890 */ 128, 110, 1374, 445, 569, 445, 445, 546, 1014, 10,
168175168314
/* 1900 */ 1461, 105, 381, 1373, 34, 571, 99, 1332, 557, 314,
168176
- /* 1910 */ 1183, 530, 272, 274, 379, 210, 1331, 547, 385, 386,
168177
- /* 1920 */ 275, 572, 1247, 1242, 411, 412, 1513, 165, 178, 1514,
168178
- /* 1930 */ 1014, 1014, 1016, 1017, 27, 1512, 1511, 1024, 78, 147,
168315
+ /* 1910 */ 1182, 530, 272, 274, 379, 210, 1331, 547, 385, 386,
168316
+ /* 1920 */ 275, 572, 1247, 1242, 411, 412, 1512, 165, 178, 1513,
168317
+ /* 1930 */ 1014, 1014, 1016, 1017, 27, 1511, 1510, 1024, 78, 147,
168179168318
/* 1940 */ 166, 220, 221, 109, 109, 834, 304, 167, 446, 212,
168180
- /* 1950 */ 318, 110, 231, 445, 569, 445, 144, 1087, 1014, 1085,
168181
- /* 1960 */ 326, 180, 169, 1208, 182, 334, 238, 913, 241, 1101,
168319
+ /* 1950 */ 318, 110, 231, 445, 569, 445, 144, 1086, 1014, 1084,
168320
+ /* 1960 */ 326, 180, 169, 1207, 182, 334, 238, 913, 241, 1100,
168182168321
/* 1970 */ 187, 170, 171, 421, 87, 88, 423, 189, 89, 90,
168183
- /* 1980 */ 172, 1104, 243, 1100, 244, 158, 18, 245, 345, 247,
168184
- /* 1990 */ 1014, 1014, 1016, 1017, 27, 261, 1093, 193, 1222, 489,
168322
+ /* 1980 */ 172, 1103, 243, 1099, 244, 158, 18, 245, 345, 247,
168323
+ /* 1990 */ 1014, 1014, 1016, 1017, 27, 261, 1092, 193, 1222, 489,
168185168324
/* 2000 */ 194, 37, 366, 849, 494, 251, 195, 506, 92, 19,
168186168325
/* 2010 */ 498, 358, 20, 503, 879, 361, 94, 892, 305, 159,
168187
- /* 2020 */ 513, 39, 95, 1171, 160, 1053, 964, 1140, 96, 174,
168188
- /* 2030 */ 1139, 225, 280, 282, 198, 958, 113, 1161, 1157, 260,
168189
- /* 2040 */ 21, 22, 23, 1159, 1165, 1164, 1145, 24, 33, 25,
168190
- /* 2050 */ 202, 542, 26, 100, 1068, 102, 1054, 103, 7, 1052,
168191
- /* 2060 */ 1056, 1110, 1057, 1109, 266, 267, 28, 40, 390, 1019,
168192
- /* 2070 */ 861, 112, 29, 564, 1179, 1178, 268, 176, 143, 923,
168326
+ /* 2020 */ 513, 39, 95, 1170, 160, 1053, 964, 1139, 96, 174,
168327
+ /* 2030 */ 1138, 225, 280, 282, 198, 958, 113, 1160, 1156, 260,
168328
+ /* 2040 */ 21, 22, 23, 1158, 1164, 1163, 1144, 24, 33, 25,
168329
+ /* 2050 */ 202, 542, 26, 100, 1067, 102, 1054, 103, 7, 1052,
168330
+ /* 2060 */ 1056, 1109, 1057, 1108, 266, 267, 28, 40, 390, 1019,
168331
+ /* 2070 */ 861, 112, 29, 564, 1178, 1177, 268, 176, 143, 923,
168193168332
/* 2080 */ 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238,
168194
- /* 2090 */ 1238, 1238, 1238, 1238, 269, 1596,
168333
+ /* 2090 */ 1238, 1238, 1238, 1238, 269, 1595,
168195168334
};
168196168335
static const YYCODETYPE yy_lookahead[] = {
168197168336
/* 0 */ 193, 193, 193, 274, 275, 276, 193, 274, 275, 276,
168198168337
/* 10 */ 193, 223, 219, 225, 206, 210, 211, 212, 193, 19,
168199168338
/* 20 */ 219, 233, 216, 216, 217, 216, 217, 193, 295, 216,
@@ -168532,67 +168671,67 @@
168532168671
/* 380 */ 1665, 1623, 1702, 1630, 1666, 1667, 1671, 1673, 1703, 1718,
168533168672
/* 390 */ 1719, 1729, 1730, 1731, 1621, 1622, 1628, 1720, 1713, 1716,
168534168673
/* 400 */ 1722, 1723, 1733, 1717, 1724, 1727, 1728, 1725, 1740,
168535168674
};
168536168675
static const YYACTIONTYPE yy_default[] = {
168537
- /* 0 */ 1641, 1641, 1641, 1470, 1236, 1347, 1236, 1236, 1236, 1470,
168538
- /* 10 */ 1470, 1470, 1236, 1377, 1377, 1523, 1269, 1236, 1236, 1236,
168539
- /* 20 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1469, 1236, 1236,
168540
- /* 30 */ 1236, 1236, 1558, 1558, 1236, 1236, 1236, 1236, 1236, 1236,
168676
+ /* 0 */ 1641, 1641, 1641, 1469, 1236, 1347, 1236, 1236, 1236, 1469,
168677
+ /* 10 */ 1469, 1469, 1236, 1377, 1377, 1522, 1269, 1236, 1236, 1236,
168678
+ /* 20 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1468, 1236, 1236,
168679
+ /* 30 */ 1236, 1236, 1557, 1557, 1236, 1236, 1236, 1236, 1236, 1236,
168541168680
/* 40 */ 1236, 1236, 1386, 1236, 1393, 1236, 1236, 1236, 1236, 1236,
168542
- /* 50 */ 1471, 1472, 1236, 1236, 1236, 1522, 1524, 1487, 1400, 1399,
168543
- /* 60 */ 1398, 1397, 1505, 1365, 1391, 1384, 1388, 1465, 1466, 1464,
168544
- /* 70 */ 1468, 1472, 1471, 1236, 1387, 1433, 1449, 1432, 1236, 1236,
168681
+ /* 50 */ 1470, 1471, 1236, 1236, 1236, 1521, 1523, 1486, 1400, 1399,
168682
+ /* 60 */ 1398, 1397, 1504, 1365, 1391, 1384, 1388, 1465, 1466, 1464,
168683
+ /* 70 */ 1619, 1471, 1470, 1236, 1387, 1433, 1449, 1432, 1236, 1236,
168545168684
/* 80 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168546168685
/* 90 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168547168686
/* 100 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168548168687
/* 110 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168549168688
/* 120 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168550168689
/* 130 */ 1441, 1448, 1447, 1446, 1455, 1445, 1442, 1435, 1434, 1436,
168551168690
/* 140 */ 1437, 1236, 1236, 1260, 1236, 1236, 1257, 1311, 1236, 1236,
168552
- /* 150 */ 1236, 1236, 1236, 1542, 1541, 1236, 1438, 1236, 1269, 1427,
168553
- /* 160 */ 1426, 1452, 1439, 1451, 1450, 1530, 1594, 1593, 1488, 1236,
168554
- /* 170 */ 1236, 1236, 1236, 1236, 1236, 1558, 1236, 1236, 1236, 1236,
168691
+ /* 150 */ 1236, 1236, 1236, 1541, 1540, 1236, 1438, 1236, 1269, 1427,
168692
+ /* 160 */ 1426, 1452, 1439, 1451, 1450, 1529, 1593, 1592, 1487, 1236,
168693
+ /* 170 */ 1236, 1236, 1236, 1236, 1236, 1557, 1236, 1236, 1236, 1236,
168555168694
/* 180 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168556168695
/* 190 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1367,
168557
- /* 200 */ 1558, 1558, 1236, 1269, 1558, 1558, 1368, 1368, 1265, 1265,
168558
- /* 210 */ 1371, 1236, 1537, 1338, 1338, 1338, 1338, 1347, 1338, 1236,
168696
+ /* 200 */ 1557, 1557, 1236, 1269, 1557, 1557, 1368, 1368, 1265, 1265,
168697
+ /* 210 */ 1371, 1236, 1536, 1338, 1338, 1338, 1338, 1347, 1338, 1236,
168559168698
/* 220 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168560
- /* 230 */ 1236, 1236, 1236, 1236, 1527, 1525, 1236, 1236, 1236, 1236,
168699
+ /* 230 */ 1236, 1236, 1236, 1236, 1526, 1524, 1236, 1236, 1236, 1236,
168561168700
/* 240 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168562168701
/* 250 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168563168702
/* 260 */ 1236, 1236, 1236, 1343, 1236, 1236, 1236, 1236, 1236, 1236,
168564
- /* 270 */ 1236, 1236, 1236, 1236, 1236, 1587, 1236, 1500, 1325, 1343,
168703
+ /* 270 */ 1236, 1236, 1236, 1236, 1236, 1586, 1236, 1499, 1325, 1343,
168565168704
/* 280 */ 1343, 1343, 1343, 1345, 1326, 1324, 1337, 1270, 1243, 1633,
168566168705
/* 290 */ 1403, 1392, 1344, 1392, 1630, 1390, 1403, 1403, 1390, 1403,
168567
- /* 300 */ 1344, 1630, 1286, 1609, 1281, 1377, 1377, 1377, 1367, 1367,
168706
+ /* 300 */ 1344, 1630, 1286, 1608, 1281, 1377, 1377, 1377, 1367, 1367,
168568168707
/* 310 */ 1367, 1367, 1371, 1371, 1467, 1344, 1337, 1236, 1633, 1633,
168569
- /* 320 */ 1353, 1353, 1632, 1632, 1353, 1488, 1617, 1412, 1314, 1320,
168570
- /* 330 */ 1320, 1320, 1320, 1353, 1254, 1390, 1617, 1617, 1390, 1412,
168571
- /* 340 */ 1314, 1390, 1314, 1390, 1353, 1254, 1504, 1627, 1353, 1254,
168572
- /* 350 */ 1478, 1353, 1254, 1353, 1254, 1478, 1312, 1312, 1312, 1301,
168573
- /* 360 */ 1236, 1236, 1478, 1312, 1286, 1312, 1301, 1312, 1312, 1576,
168574
- /* 370 */ 1236, 1482, 1482, 1478, 1353, 1568, 1568, 1380, 1380, 1385,
168575
- /* 380 */ 1371, 1473, 1353, 1236, 1385, 1383, 1381, 1390, 1304, 1590,
168576
- /* 390 */ 1590, 1586, 1586, 1586, 1638, 1638, 1537, 1602, 1269, 1269,
168577
- /* 400 */ 1269, 1269, 1602, 1288, 1288, 1270, 1270, 1269, 1602, 1236,
168578
- /* 410 */ 1236, 1236, 1236, 1236, 1236, 1597, 1236, 1532, 1489, 1357,
168708
+ /* 320 */ 1353, 1353, 1632, 1632, 1353, 1487, 1616, 1412, 1314, 1320,
168709
+ /* 330 */ 1320, 1320, 1320, 1353, 1254, 1390, 1616, 1616, 1390, 1412,
168710
+ /* 340 */ 1314, 1390, 1314, 1390, 1353, 1254, 1503, 1627, 1353, 1254,
168711
+ /* 350 */ 1477, 1353, 1254, 1353, 1254, 1477, 1312, 1312, 1312, 1301,
168712
+ /* 360 */ 1236, 1236, 1477, 1312, 1286, 1312, 1301, 1312, 1312, 1575,
168713
+ /* 370 */ 1236, 1481, 1481, 1477, 1353, 1567, 1567, 1380, 1380, 1385,
168714
+ /* 380 */ 1371, 1472, 1353, 1236, 1385, 1383, 1381, 1390, 1304, 1589,
168715
+ /* 390 */ 1589, 1585, 1585, 1585, 1638, 1638, 1536, 1601, 1269, 1269,
168716
+ /* 400 */ 1269, 1269, 1601, 1288, 1288, 1270, 1270, 1269, 1601, 1236,
168717
+ /* 410 */ 1236, 1236, 1236, 1236, 1236, 1596, 1236, 1531, 1488, 1357,
168579168718
/* 420 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168580
- /* 430 */ 1236, 1236, 1236, 1236, 1543, 1236, 1236, 1236, 1236, 1236,
168581
- /* 440 */ 1236, 1236, 1236, 1236, 1236, 1417, 1236, 1239, 1534, 1236,
168719
+ /* 430 */ 1236, 1236, 1236, 1236, 1542, 1236, 1236, 1236, 1236, 1236,
168720
+ /* 440 */ 1236, 1236, 1236, 1236, 1236, 1417, 1236, 1239, 1533, 1236,
168582168721
/* 450 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1394, 1395, 1358,
168583168722
/* 460 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1409, 1236, 1236,
168584168723
/* 470 */ 1236, 1404, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168585
- /* 480 */ 1629, 1236, 1236, 1236, 1236, 1236, 1236, 1503, 1502, 1236,
168724
+ /* 480 */ 1629, 1236, 1236, 1236, 1236, 1236, 1236, 1502, 1501, 1236,
168586168725
/* 490 */ 1236, 1355, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168587168726
/* 500 */ 1236, 1236, 1236, 1236, 1236, 1284, 1236, 1236, 1236, 1236,
168588168727
/* 510 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168589168728
/* 520 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1382,
168590168729
/* 530 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168591
- /* 540 */ 1236, 1236, 1236, 1236, 1573, 1372, 1236, 1236, 1236, 1236,
168730
+ /* 540 */ 1236, 1236, 1236, 1236, 1572, 1372, 1236, 1236, 1236, 1236,
168592168731
/* 550 */ 1620, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168593
- /* 560 */ 1236, 1236, 1236, 1236, 1236, 1613, 1328, 1418, 1236, 1421,
168732
+ /* 560 */ 1236, 1236, 1236, 1236, 1236, 1612, 1328, 1418, 1236, 1421,
168594168733
/* 570 */ 1258, 1236, 1248, 1236, 1236,
168595168734
};
168596168735
/********** End of lemon-generated parsing tables *****************************/
168597168736
168598168737
/* The next table maps tokens (terminal symbols) into fallback tokens.
@@ -169437,162 +169576,162 @@
169437169576
/* 224 */ "expr ::= CASE case_operand case_exprlist case_else END",
169438169577
/* 225 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
169439169578
/* 226 */ "case_exprlist ::= WHEN expr THEN expr",
169440169579
/* 227 */ "case_else ::= ELSE expr",
169441169580
/* 228 */ "case_else ::=",
169442
- /* 229 */ "case_operand ::= expr",
169443
- /* 230 */ "case_operand ::=",
169444
- /* 231 */ "exprlist ::=",
169445
- /* 232 */ "nexprlist ::= nexprlist COMMA expr",
169446
- /* 233 */ "nexprlist ::= expr",
169447
- /* 234 */ "paren_exprlist ::=",
169448
- /* 235 */ "paren_exprlist ::= LP exprlist RP",
169449
- /* 236 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
169450
- /* 237 */ "uniqueflag ::= UNIQUE",
169451
- /* 238 */ "uniqueflag ::=",
169452
- /* 239 */ "eidlist_opt ::=",
169453
- /* 240 */ "eidlist_opt ::= LP eidlist RP",
169454
- /* 241 */ "eidlist ::= eidlist COMMA nm collate sortorder",
169455
- /* 242 */ "eidlist ::= nm collate sortorder",
169456
- /* 243 */ "collate ::=",
169457
- /* 244 */ "collate ::= COLLATE ID|STRING",
169458
- /* 245 */ "cmd ::= DROP INDEX ifexists fullname",
169459
- /* 246 */ "cmd ::= VACUUM vinto",
169460
- /* 247 */ "cmd ::= VACUUM nm vinto",
169461
- /* 248 */ "vinto ::= INTO expr",
169462
- /* 249 */ "vinto ::=",
169463
- /* 250 */ "cmd ::= PRAGMA nm dbnm",
169464
- /* 251 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
169465
- /* 252 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
169466
- /* 253 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
169467
- /* 254 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
169468
- /* 255 */ "plus_num ::= PLUS INTEGER|FLOAT",
169469
- /* 256 */ "minus_num ::= MINUS INTEGER|FLOAT",
169470
- /* 257 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
169471
- /* 258 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
169472
- /* 259 */ "trigger_time ::= BEFORE|AFTER",
169473
- /* 260 */ "trigger_time ::= INSTEAD OF",
169474
- /* 261 */ "trigger_time ::=",
169475
- /* 262 */ "trigger_event ::= DELETE|INSERT",
169476
- /* 263 */ "trigger_event ::= UPDATE",
169477
- /* 264 */ "trigger_event ::= UPDATE OF idlist",
169478
- /* 265 */ "when_clause ::=",
169479
- /* 266 */ "when_clause ::= WHEN expr",
169480
- /* 267 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
169481
- /* 268 */ "trigger_cmd_list ::= trigger_cmd SEMI",
169482
- /* 269 */ "trnm ::= nm DOT nm",
169483
- /* 270 */ "tridxby ::= INDEXED BY nm",
169484
- /* 271 */ "tridxby ::= NOT INDEXED",
169485
- /* 272 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
169486
- /* 273 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
169487
- /* 274 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
169488
- /* 275 */ "trigger_cmd ::= scanpt select scanpt",
169489
- /* 276 */ "expr ::= RAISE LP IGNORE RP",
169490
- /* 277 */ "expr ::= RAISE LP raisetype COMMA nm RP",
169491
- /* 278 */ "raisetype ::= ROLLBACK",
169492
- /* 279 */ "raisetype ::= ABORT",
169493
- /* 280 */ "raisetype ::= FAIL",
169494
- /* 281 */ "cmd ::= DROP TRIGGER ifexists fullname",
169495
- /* 282 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
169496
- /* 283 */ "cmd ::= DETACH database_kw_opt expr",
169497
- /* 284 */ "key_opt ::=",
169498
- /* 285 */ "key_opt ::= KEY expr",
169499
- /* 286 */ "cmd ::= REINDEX",
169500
- /* 287 */ "cmd ::= REINDEX nm dbnm",
169501
- /* 288 */ "cmd ::= ANALYZE",
169502
- /* 289 */ "cmd ::= ANALYZE nm dbnm",
169503
- /* 290 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
169504
- /* 291 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
169505
- /* 292 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
169506
- /* 293 */ "add_column_fullname ::= fullname",
169507
- /* 294 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
169508
- /* 295 */ "cmd ::= create_vtab",
169509
- /* 296 */ "cmd ::= create_vtab LP vtabarglist RP",
169510
- /* 297 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
169511
- /* 298 */ "vtabarg ::=",
169512
- /* 299 */ "vtabargtoken ::= ANY",
169513
- /* 300 */ "vtabargtoken ::= lp anylist RP",
169514
- /* 301 */ "lp ::= LP",
169515
- /* 302 */ "with ::= WITH wqlist",
169516
- /* 303 */ "with ::= WITH RECURSIVE wqlist",
169517
- /* 304 */ "wqas ::= AS",
169518
- /* 305 */ "wqas ::= AS MATERIALIZED",
169519
- /* 306 */ "wqas ::= AS NOT MATERIALIZED",
169520
- /* 307 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
169521
- /* 308 */ "wqlist ::= wqitem",
169522
- /* 309 */ "wqlist ::= wqlist COMMA wqitem",
169523
- /* 310 */ "windowdefn_list ::= windowdefn",
169524
- /* 311 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
169525
- /* 312 */ "windowdefn ::= nm AS LP window RP",
169526
- /* 313 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
169527
- /* 314 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
169528
- /* 315 */ "window ::= ORDER BY sortlist frame_opt",
169529
- /* 316 */ "window ::= nm ORDER BY sortlist frame_opt",
169530
- /* 317 */ "window ::= frame_opt",
169531
- /* 318 */ "window ::= nm frame_opt",
169532
- /* 319 */ "frame_opt ::=",
169533
- /* 320 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
169534
- /* 321 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
169535
- /* 322 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
169536
- /* 323 */ "frame_bound_s ::= frame_bound",
169537
- /* 324 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
169538
- /* 325 */ "frame_bound_e ::= frame_bound",
169539
- /* 326 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
169540
- /* 327 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
169541
- /* 328 */ "frame_bound ::= CURRENT ROW",
169542
- /* 329 */ "frame_exclude_opt ::=",
169543
- /* 330 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
169544
- /* 331 */ "frame_exclude ::= NO OTHERS",
169545
- /* 332 */ "frame_exclude ::= CURRENT ROW",
169546
- /* 333 */ "frame_exclude ::= GROUP|TIES",
169547
- /* 334 */ "window_clause ::= WINDOW windowdefn_list",
169548
- /* 335 */ "filter_over ::= filter_clause over_clause",
169549
- /* 336 */ "filter_over ::= over_clause",
169550
- /* 337 */ "filter_over ::= filter_clause",
169551
- /* 338 */ "over_clause ::= OVER LP window RP",
169552
- /* 339 */ "over_clause ::= OVER nm",
169553
- /* 340 */ "filter_clause ::= FILTER LP WHERE expr RP",
169554
- /* 341 */ "input ::= cmdlist",
169555
- /* 342 */ "cmdlist ::= cmdlist ecmd",
169556
- /* 343 */ "cmdlist ::= ecmd",
169557
- /* 344 */ "ecmd ::= SEMI",
169558
- /* 345 */ "ecmd ::= cmdx SEMI",
169559
- /* 346 */ "ecmd ::= explain cmdx SEMI",
169560
- /* 347 */ "trans_opt ::=",
169561
- /* 348 */ "trans_opt ::= TRANSACTION",
169562
- /* 349 */ "trans_opt ::= TRANSACTION nm",
169563
- /* 350 */ "savepoint_opt ::= SAVEPOINT",
169564
- /* 351 */ "savepoint_opt ::=",
169565
- /* 352 */ "cmd ::= create_table create_table_args",
169566
- /* 353 */ "table_option_set ::= table_option",
169567
- /* 354 */ "columnlist ::= columnlist COMMA columnname carglist",
169568
- /* 355 */ "columnlist ::= columnname carglist",
169569
- /* 356 */ "nm ::= ID|INDEXED|JOIN_KW",
169570
- /* 357 */ "nm ::= STRING",
169571
- /* 358 */ "typetoken ::= typename",
169572
- /* 359 */ "typename ::= ID|STRING",
169573
- /* 360 */ "signed ::= plus_num",
169574
- /* 361 */ "signed ::= minus_num",
169575
- /* 362 */ "carglist ::= carglist ccons",
169576
- /* 363 */ "carglist ::=",
169577
- /* 364 */ "ccons ::= NULL onconf",
169578
- /* 365 */ "ccons ::= GENERATED ALWAYS AS generated",
169579
- /* 366 */ "ccons ::= AS generated",
169580
- /* 367 */ "conslist_opt ::= COMMA conslist",
169581
- /* 368 */ "conslist ::= conslist tconscomma tcons",
169582
- /* 369 */ "conslist ::= tcons",
169583
- /* 370 */ "tconscomma ::=",
169584
- /* 371 */ "defer_subclause_opt ::= defer_subclause",
169585
- /* 372 */ "resolvetype ::= raisetype",
169586
- /* 373 */ "selectnowith ::= oneselect",
169587
- /* 374 */ "oneselect ::= values",
169588
- /* 375 */ "sclp ::= selcollist COMMA",
169589
- /* 376 */ "as ::= ID|STRING",
169590
- /* 377 */ "indexed_opt ::= indexed_by",
169591
- /* 378 */ "returning ::=",
169592
- /* 379 */ "expr ::= term",
169593
- /* 380 */ "likeop ::= LIKE_KW|MATCH",
169581
+ /* 229 */ "case_operand ::=",
169582
+ /* 230 */ "exprlist ::=",
169583
+ /* 231 */ "nexprlist ::= nexprlist COMMA expr",
169584
+ /* 232 */ "nexprlist ::= expr",
169585
+ /* 233 */ "paren_exprlist ::=",
169586
+ /* 234 */ "paren_exprlist ::= LP exprlist RP",
169587
+ /* 235 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
169588
+ /* 236 */ "uniqueflag ::= UNIQUE",
169589
+ /* 237 */ "uniqueflag ::=",
169590
+ /* 238 */ "eidlist_opt ::=",
169591
+ /* 239 */ "eidlist_opt ::= LP eidlist RP",
169592
+ /* 240 */ "eidlist ::= eidlist COMMA nm collate sortorder",
169593
+ /* 241 */ "eidlist ::= nm collate sortorder",
169594
+ /* 242 */ "collate ::=",
169595
+ /* 243 */ "collate ::= COLLATE ID|STRING",
169596
+ /* 244 */ "cmd ::= DROP INDEX ifexists fullname",
169597
+ /* 245 */ "cmd ::= VACUUM vinto",
169598
+ /* 246 */ "cmd ::= VACUUM nm vinto",
169599
+ /* 247 */ "vinto ::= INTO expr",
169600
+ /* 248 */ "vinto ::=",
169601
+ /* 249 */ "cmd ::= PRAGMA nm dbnm",
169602
+ /* 250 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
169603
+ /* 251 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
169604
+ /* 252 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
169605
+ /* 253 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
169606
+ /* 254 */ "plus_num ::= PLUS INTEGER|FLOAT",
169607
+ /* 255 */ "minus_num ::= MINUS INTEGER|FLOAT",
169608
+ /* 256 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
169609
+ /* 257 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
169610
+ /* 258 */ "trigger_time ::= BEFORE|AFTER",
169611
+ /* 259 */ "trigger_time ::= INSTEAD OF",
169612
+ /* 260 */ "trigger_time ::=",
169613
+ /* 261 */ "trigger_event ::= DELETE|INSERT",
169614
+ /* 262 */ "trigger_event ::= UPDATE",
169615
+ /* 263 */ "trigger_event ::= UPDATE OF idlist",
169616
+ /* 264 */ "when_clause ::=",
169617
+ /* 265 */ "when_clause ::= WHEN expr",
169618
+ /* 266 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
169619
+ /* 267 */ "trigger_cmd_list ::= trigger_cmd SEMI",
169620
+ /* 268 */ "trnm ::= nm DOT nm",
169621
+ /* 269 */ "tridxby ::= INDEXED BY nm",
169622
+ /* 270 */ "tridxby ::= NOT INDEXED",
169623
+ /* 271 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
169624
+ /* 272 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
169625
+ /* 273 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
169626
+ /* 274 */ "trigger_cmd ::= scanpt select scanpt",
169627
+ /* 275 */ "expr ::= RAISE LP IGNORE RP",
169628
+ /* 276 */ "expr ::= RAISE LP raisetype COMMA nm RP",
169629
+ /* 277 */ "raisetype ::= ROLLBACK",
169630
+ /* 278 */ "raisetype ::= ABORT",
169631
+ /* 279 */ "raisetype ::= FAIL",
169632
+ /* 280 */ "cmd ::= DROP TRIGGER ifexists fullname",
169633
+ /* 281 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
169634
+ /* 282 */ "cmd ::= DETACH database_kw_opt expr",
169635
+ /* 283 */ "key_opt ::=",
169636
+ /* 284 */ "key_opt ::= KEY expr",
169637
+ /* 285 */ "cmd ::= REINDEX",
169638
+ /* 286 */ "cmd ::= REINDEX nm dbnm",
169639
+ /* 287 */ "cmd ::= ANALYZE",
169640
+ /* 288 */ "cmd ::= ANALYZE nm dbnm",
169641
+ /* 289 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
169642
+ /* 290 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
169643
+ /* 291 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
169644
+ /* 292 */ "add_column_fullname ::= fullname",
169645
+ /* 293 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
169646
+ /* 294 */ "cmd ::= create_vtab",
169647
+ /* 295 */ "cmd ::= create_vtab LP vtabarglist RP",
169648
+ /* 296 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
169649
+ /* 297 */ "vtabarg ::=",
169650
+ /* 298 */ "vtabargtoken ::= ANY",
169651
+ /* 299 */ "vtabargtoken ::= lp anylist RP",
169652
+ /* 300 */ "lp ::= LP",
169653
+ /* 301 */ "with ::= WITH wqlist",
169654
+ /* 302 */ "with ::= WITH RECURSIVE wqlist",
169655
+ /* 303 */ "wqas ::= AS",
169656
+ /* 304 */ "wqas ::= AS MATERIALIZED",
169657
+ /* 305 */ "wqas ::= AS NOT MATERIALIZED",
169658
+ /* 306 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
169659
+ /* 307 */ "wqlist ::= wqitem",
169660
+ /* 308 */ "wqlist ::= wqlist COMMA wqitem",
169661
+ /* 309 */ "windowdefn_list ::= windowdefn",
169662
+ /* 310 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
169663
+ /* 311 */ "windowdefn ::= nm AS LP window RP",
169664
+ /* 312 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
169665
+ /* 313 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
169666
+ /* 314 */ "window ::= ORDER BY sortlist frame_opt",
169667
+ /* 315 */ "window ::= nm ORDER BY sortlist frame_opt",
169668
+ /* 316 */ "window ::= frame_opt",
169669
+ /* 317 */ "window ::= nm frame_opt",
169670
+ /* 318 */ "frame_opt ::=",
169671
+ /* 319 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
169672
+ /* 320 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
169673
+ /* 321 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
169674
+ /* 322 */ "frame_bound_s ::= frame_bound",
169675
+ /* 323 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
169676
+ /* 324 */ "frame_bound_e ::= frame_bound",
169677
+ /* 325 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
169678
+ /* 326 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
169679
+ /* 327 */ "frame_bound ::= CURRENT ROW",
169680
+ /* 328 */ "frame_exclude_opt ::=",
169681
+ /* 329 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
169682
+ /* 330 */ "frame_exclude ::= NO OTHERS",
169683
+ /* 331 */ "frame_exclude ::= CURRENT ROW",
169684
+ /* 332 */ "frame_exclude ::= GROUP|TIES",
169685
+ /* 333 */ "window_clause ::= WINDOW windowdefn_list",
169686
+ /* 334 */ "filter_over ::= filter_clause over_clause",
169687
+ /* 335 */ "filter_over ::= over_clause",
169688
+ /* 336 */ "filter_over ::= filter_clause",
169689
+ /* 337 */ "over_clause ::= OVER LP window RP",
169690
+ /* 338 */ "over_clause ::= OVER nm",
169691
+ /* 339 */ "filter_clause ::= FILTER LP WHERE expr RP",
169692
+ /* 340 */ "input ::= cmdlist",
169693
+ /* 341 */ "cmdlist ::= cmdlist ecmd",
169694
+ /* 342 */ "cmdlist ::= ecmd",
169695
+ /* 343 */ "ecmd ::= SEMI",
169696
+ /* 344 */ "ecmd ::= cmdx SEMI",
169697
+ /* 345 */ "ecmd ::= explain cmdx SEMI",
169698
+ /* 346 */ "trans_opt ::=",
169699
+ /* 347 */ "trans_opt ::= TRANSACTION",
169700
+ /* 348 */ "trans_opt ::= TRANSACTION nm",
169701
+ /* 349 */ "savepoint_opt ::= SAVEPOINT",
169702
+ /* 350 */ "savepoint_opt ::=",
169703
+ /* 351 */ "cmd ::= create_table create_table_args",
169704
+ /* 352 */ "table_option_set ::= table_option",
169705
+ /* 353 */ "columnlist ::= columnlist COMMA columnname carglist",
169706
+ /* 354 */ "columnlist ::= columnname carglist",
169707
+ /* 355 */ "nm ::= ID|INDEXED|JOIN_KW",
169708
+ /* 356 */ "nm ::= STRING",
169709
+ /* 357 */ "typetoken ::= typename",
169710
+ /* 358 */ "typename ::= ID|STRING",
169711
+ /* 359 */ "signed ::= plus_num",
169712
+ /* 360 */ "signed ::= minus_num",
169713
+ /* 361 */ "carglist ::= carglist ccons",
169714
+ /* 362 */ "carglist ::=",
169715
+ /* 363 */ "ccons ::= NULL onconf",
169716
+ /* 364 */ "ccons ::= GENERATED ALWAYS AS generated",
169717
+ /* 365 */ "ccons ::= AS generated",
169718
+ /* 366 */ "conslist_opt ::= COMMA conslist",
169719
+ /* 367 */ "conslist ::= conslist tconscomma tcons",
169720
+ /* 368 */ "conslist ::= tcons",
169721
+ /* 369 */ "tconscomma ::=",
169722
+ /* 370 */ "defer_subclause_opt ::= defer_subclause",
169723
+ /* 371 */ "resolvetype ::= raisetype",
169724
+ /* 372 */ "selectnowith ::= oneselect",
169725
+ /* 373 */ "oneselect ::= values",
169726
+ /* 374 */ "sclp ::= selcollist COMMA",
169727
+ /* 375 */ "as ::= ID|STRING",
169728
+ /* 376 */ "indexed_opt ::= indexed_by",
169729
+ /* 377 */ "returning ::=",
169730
+ /* 378 */ "expr ::= term",
169731
+ /* 379 */ "likeop ::= LIKE_KW|MATCH",
169732
+ /* 380 */ "case_operand ::= expr",
169594169733
/* 381 */ "exprlist ::= nexprlist",
169595169734
/* 382 */ "nmnum ::= plus_num",
169596169735
/* 383 */ "nmnum ::= nm",
169597169736
/* 384 */ "nmnum ::= ON",
169598169737
/* 385 */ "nmnum ::= DELETE",
@@ -170346,162 +170485,162 @@
170346170485
217, /* (224) expr ::= CASE case_operand case_exprlist case_else END */
170347170486
279, /* (225) case_exprlist ::= case_exprlist WHEN expr THEN expr */
170348170487
279, /* (226) case_exprlist ::= WHEN expr THEN expr */
170349170488
280, /* (227) case_else ::= ELSE expr */
170350170489
280, /* (228) case_else ::= */
170351
- 278, /* (229) case_operand ::= expr */
170352
- 278, /* (230) case_operand ::= */
170353
- 261, /* (231) exprlist ::= */
170354
- 253, /* (232) nexprlist ::= nexprlist COMMA expr */
170355
- 253, /* (233) nexprlist ::= expr */
170356
- 277, /* (234) paren_exprlist ::= */
170357
- 277, /* (235) paren_exprlist ::= LP exprlist RP */
170358
- 190, /* (236) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
170359
- 281, /* (237) uniqueflag ::= UNIQUE */
170360
- 281, /* (238) uniqueflag ::= */
170361
- 221, /* (239) eidlist_opt ::= */
170362
- 221, /* (240) eidlist_opt ::= LP eidlist RP */
170363
- 232, /* (241) eidlist ::= eidlist COMMA nm collate sortorder */
170364
- 232, /* (242) eidlist ::= nm collate sortorder */
170365
- 282, /* (243) collate ::= */
170366
- 282, /* (244) collate ::= COLLATE ID|STRING */
170367
- 190, /* (245) cmd ::= DROP INDEX ifexists fullname */
170368
- 190, /* (246) cmd ::= VACUUM vinto */
170369
- 190, /* (247) cmd ::= VACUUM nm vinto */
170370
- 283, /* (248) vinto ::= INTO expr */
170371
- 283, /* (249) vinto ::= */
170372
- 190, /* (250) cmd ::= PRAGMA nm dbnm */
170373
- 190, /* (251) cmd ::= PRAGMA nm dbnm EQ nmnum */
170374
- 190, /* (252) cmd ::= PRAGMA nm dbnm LP nmnum RP */
170375
- 190, /* (253) cmd ::= PRAGMA nm dbnm EQ minus_num */
170376
- 190, /* (254) cmd ::= PRAGMA nm dbnm LP minus_num RP */
170377
- 211, /* (255) plus_num ::= PLUS INTEGER|FLOAT */
170378
- 212, /* (256) minus_num ::= MINUS INTEGER|FLOAT */
170379
- 190, /* (257) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
170380
- 285, /* (258) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
170381
- 287, /* (259) trigger_time ::= BEFORE|AFTER */
170382
- 287, /* (260) trigger_time ::= INSTEAD OF */
170383
- 287, /* (261) trigger_time ::= */
170384
- 288, /* (262) trigger_event ::= DELETE|INSERT */
170385
- 288, /* (263) trigger_event ::= UPDATE */
170386
- 288, /* (264) trigger_event ::= UPDATE OF idlist */
170387
- 290, /* (265) when_clause ::= */
170388
- 290, /* (266) when_clause ::= WHEN expr */
170389
- 286, /* (267) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
170390
- 286, /* (268) trigger_cmd_list ::= trigger_cmd SEMI */
170391
- 292, /* (269) trnm ::= nm DOT nm */
170392
- 293, /* (270) tridxby ::= INDEXED BY nm */
170393
- 293, /* (271) tridxby ::= NOT INDEXED */
170394
- 291, /* (272) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
170395
- 291, /* (273) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
170396
- 291, /* (274) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
170397
- 291, /* (275) trigger_cmd ::= scanpt select scanpt */
170398
- 217, /* (276) expr ::= RAISE LP IGNORE RP */
170399
- 217, /* (277) expr ::= RAISE LP raisetype COMMA nm RP */
170400
- 236, /* (278) raisetype ::= ROLLBACK */
170401
- 236, /* (279) raisetype ::= ABORT */
170402
- 236, /* (280) raisetype ::= FAIL */
170403
- 190, /* (281) cmd ::= DROP TRIGGER ifexists fullname */
170404
- 190, /* (282) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
170405
- 190, /* (283) cmd ::= DETACH database_kw_opt expr */
170406
- 295, /* (284) key_opt ::= */
170407
- 295, /* (285) key_opt ::= KEY expr */
170408
- 190, /* (286) cmd ::= REINDEX */
170409
- 190, /* (287) cmd ::= REINDEX nm dbnm */
170410
- 190, /* (288) cmd ::= ANALYZE */
170411
- 190, /* (289) cmd ::= ANALYZE nm dbnm */
170412
- 190, /* (290) cmd ::= ALTER TABLE fullname RENAME TO nm */
170413
- 190, /* (291) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
170414
- 190, /* (292) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
170415
- 296, /* (293) add_column_fullname ::= fullname */
170416
- 190, /* (294) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
170417
- 190, /* (295) cmd ::= create_vtab */
170418
- 190, /* (296) cmd ::= create_vtab LP vtabarglist RP */
170419
- 298, /* (297) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
170420
- 300, /* (298) vtabarg ::= */
170421
- 301, /* (299) vtabargtoken ::= ANY */
170422
- 301, /* (300) vtabargtoken ::= lp anylist RP */
170423
- 302, /* (301) lp ::= LP */
170424
- 266, /* (302) with ::= WITH wqlist */
170425
- 266, /* (303) with ::= WITH RECURSIVE wqlist */
170426
- 305, /* (304) wqas ::= AS */
170427
- 305, /* (305) wqas ::= AS MATERIALIZED */
170428
- 305, /* (306) wqas ::= AS NOT MATERIALIZED */
170429
- 304, /* (307) wqitem ::= nm eidlist_opt wqas LP select RP */
170430
- 241, /* (308) wqlist ::= wqitem */
170431
- 241, /* (309) wqlist ::= wqlist COMMA wqitem */
170432
- 306, /* (310) windowdefn_list ::= windowdefn */
170433
- 306, /* (311) windowdefn_list ::= windowdefn_list COMMA windowdefn */
170434
- 307, /* (312) windowdefn ::= nm AS LP window RP */
170435
- 308, /* (313) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
170436
- 308, /* (314) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
170437
- 308, /* (315) window ::= ORDER BY sortlist frame_opt */
170438
- 308, /* (316) window ::= nm ORDER BY sortlist frame_opt */
170439
- 308, /* (317) window ::= frame_opt */
170440
- 308, /* (318) window ::= nm frame_opt */
170441
- 309, /* (319) frame_opt ::= */
170442
- 309, /* (320) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
170443
- 309, /* (321) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
170444
- 313, /* (322) range_or_rows ::= RANGE|ROWS|GROUPS */
170445
- 315, /* (323) frame_bound_s ::= frame_bound */
170446
- 315, /* (324) frame_bound_s ::= UNBOUNDED PRECEDING */
170447
- 316, /* (325) frame_bound_e ::= frame_bound */
170448
- 316, /* (326) frame_bound_e ::= UNBOUNDED FOLLOWING */
170449
- 314, /* (327) frame_bound ::= expr PRECEDING|FOLLOWING */
170450
- 314, /* (328) frame_bound ::= CURRENT ROW */
170451
- 317, /* (329) frame_exclude_opt ::= */
170452
- 317, /* (330) frame_exclude_opt ::= EXCLUDE frame_exclude */
170453
- 318, /* (331) frame_exclude ::= NO OTHERS */
170454
- 318, /* (332) frame_exclude ::= CURRENT ROW */
170455
- 318, /* (333) frame_exclude ::= GROUP|TIES */
170456
- 251, /* (334) window_clause ::= WINDOW windowdefn_list */
170457
- 273, /* (335) filter_over ::= filter_clause over_clause */
170458
- 273, /* (336) filter_over ::= over_clause */
170459
- 273, /* (337) filter_over ::= filter_clause */
170460
- 312, /* (338) over_clause ::= OVER LP window RP */
170461
- 312, /* (339) over_clause ::= OVER nm */
170462
- 311, /* (340) filter_clause ::= FILTER LP WHERE expr RP */
170463
- 185, /* (341) input ::= cmdlist */
170464
- 186, /* (342) cmdlist ::= cmdlist ecmd */
170465
- 186, /* (343) cmdlist ::= ecmd */
170466
- 187, /* (344) ecmd ::= SEMI */
170467
- 187, /* (345) ecmd ::= cmdx SEMI */
170468
- 187, /* (346) ecmd ::= explain cmdx SEMI */
170469
- 192, /* (347) trans_opt ::= */
170470
- 192, /* (348) trans_opt ::= TRANSACTION */
170471
- 192, /* (349) trans_opt ::= TRANSACTION nm */
170472
- 194, /* (350) savepoint_opt ::= SAVEPOINT */
170473
- 194, /* (351) savepoint_opt ::= */
170474
- 190, /* (352) cmd ::= create_table create_table_args */
170475
- 203, /* (353) table_option_set ::= table_option */
170476
- 201, /* (354) columnlist ::= columnlist COMMA columnname carglist */
170477
- 201, /* (355) columnlist ::= columnname carglist */
170478
- 193, /* (356) nm ::= ID|INDEXED|JOIN_KW */
170479
- 193, /* (357) nm ::= STRING */
170480
- 208, /* (358) typetoken ::= typename */
170481
- 209, /* (359) typename ::= ID|STRING */
170482
- 210, /* (360) signed ::= plus_num */
170483
- 210, /* (361) signed ::= minus_num */
170484
- 207, /* (362) carglist ::= carglist ccons */
170485
- 207, /* (363) carglist ::= */
170486
- 215, /* (364) ccons ::= NULL onconf */
170487
- 215, /* (365) ccons ::= GENERATED ALWAYS AS generated */
170488
- 215, /* (366) ccons ::= AS generated */
170489
- 202, /* (367) conslist_opt ::= COMMA conslist */
170490
- 228, /* (368) conslist ::= conslist tconscomma tcons */
170491
- 228, /* (369) conslist ::= tcons */
170492
- 229, /* (370) tconscomma ::= */
170493
- 233, /* (371) defer_subclause_opt ::= defer_subclause */
170494
- 235, /* (372) resolvetype ::= raisetype */
170495
- 239, /* (373) selectnowith ::= oneselect */
170496
- 240, /* (374) oneselect ::= values */
170497
- 254, /* (375) sclp ::= selcollist COMMA */
170498
- 255, /* (376) as ::= ID|STRING */
170499
- 264, /* (377) indexed_opt ::= indexed_by */
170500
- 272, /* (378) returning ::= */
170501
- 217, /* (379) expr ::= term */
170502
- 274, /* (380) likeop ::= LIKE_KW|MATCH */
170490
+ 278, /* (229) case_operand ::= */
170491
+ 261, /* (230) exprlist ::= */
170492
+ 253, /* (231) nexprlist ::= nexprlist COMMA expr */
170493
+ 253, /* (232) nexprlist ::= expr */
170494
+ 277, /* (233) paren_exprlist ::= */
170495
+ 277, /* (234) paren_exprlist ::= LP exprlist RP */
170496
+ 190, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
170497
+ 281, /* (236) uniqueflag ::= UNIQUE */
170498
+ 281, /* (237) uniqueflag ::= */
170499
+ 221, /* (238) eidlist_opt ::= */
170500
+ 221, /* (239) eidlist_opt ::= LP eidlist RP */
170501
+ 232, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */
170502
+ 232, /* (241) eidlist ::= nm collate sortorder */
170503
+ 282, /* (242) collate ::= */
170504
+ 282, /* (243) collate ::= COLLATE ID|STRING */
170505
+ 190, /* (244) cmd ::= DROP INDEX ifexists fullname */
170506
+ 190, /* (245) cmd ::= VACUUM vinto */
170507
+ 190, /* (246) cmd ::= VACUUM nm vinto */
170508
+ 283, /* (247) vinto ::= INTO expr */
170509
+ 283, /* (248) vinto ::= */
170510
+ 190, /* (249) cmd ::= PRAGMA nm dbnm */
170511
+ 190, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */
170512
+ 190, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */
170513
+ 190, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */
170514
+ 190, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */
170515
+ 211, /* (254) plus_num ::= PLUS INTEGER|FLOAT */
170516
+ 212, /* (255) minus_num ::= MINUS INTEGER|FLOAT */
170517
+ 190, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
170518
+ 285, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
170519
+ 287, /* (258) trigger_time ::= BEFORE|AFTER */
170520
+ 287, /* (259) trigger_time ::= INSTEAD OF */
170521
+ 287, /* (260) trigger_time ::= */
170522
+ 288, /* (261) trigger_event ::= DELETE|INSERT */
170523
+ 288, /* (262) trigger_event ::= UPDATE */
170524
+ 288, /* (263) trigger_event ::= UPDATE OF idlist */
170525
+ 290, /* (264) when_clause ::= */
170526
+ 290, /* (265) when_clause ::= WHEN expr */
170527
+ 286, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
170528
+ 286, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */
170529
+ 292, /* (268) trnm ::= nm DOT nm */
170530
+ 293, /* (269) tridxby ::= INDEXED BY nm */
170531
+ 293, /* (270) tridxby ::= NOT INDEXED */
170532
+ 291, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
170533
+ 291, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
170534
+ 291, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
170535
+ 291, /* (274) trigger_cmd ::= scanpt select scanpt */
170536
+ 217, /* (275) expr ::= RAISE LP IGNORE RP */
170537
+ 217, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */
170538
+ 236, /* (277) raisetype ::= ROLLBACK */
170539
+ 236, /* (278) raisetype ::= ABORT */
170540
+ 236, /* (279) raisetype ::= FAIL */
170541
+ 190, /* (280) cmd ::= DROP TRIGGER ifexists fullname */
170542
+ 190, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
170543
+ 190, /* (282) cmd ::= DETACH database_kw_opt expr */
170544
+ 295, /* (283) key_opt ::= */
170545
+ 295, /* (284) key_opt ::= KEY expr */
170546
+ 190, /* (285) cmd ::= REINDEX */
170547
+ 190, /* (286) cmd ::= REINDEX nm dbnm */
170548
+ 190, /* (287) cmd ::= ANALYZE */
170549
+ 190, /* (288) cmd ::= ANALYZE nm dbnm */
170550
+ 190, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */
170551
+ 190, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
170552
+ 190, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
170553
+ 296, /* (292) add_column_fullname ::= fullname */
170554
+ 190, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
170555
+ 190, /* (294) cmd ::= create_vtab */
170556
+ 190, /* (295) cmd ::= create_vtab LP vtabarglist RP */
170557
+ 298, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
170558
+ 300, /* (297) vtabarg ::= */
170559
+ 301, /* (298) vtabargtoken ::= ANY */
170560
+ 301, /* (299) vtabargtoken ::= lp anylist RP */
170561
+ 302, /* (300) lp ::= LP */
170562
+ 266, /* (301) with ::= WITH wqlist */
170563
+ 266, /* (302) with ::= WITH RECURSIVE wqlist */
170564
+ 305, /* (303) wqas ::= AS */
170565
+ 305, /* (304) wqas ::= AS MATERIALIZED */
170566
+ 305, /* (305) wqas ::= AS NOT MATERIALIZED */
170567
+ 304, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */
170568
+ 241, /* (307) wqlist ::= wqitem */
170569
+ 241, /* (308) wqlist ::= wqlist COMMA wqitem */
170570
+ 306, /* (309) windowdefn_list ::= windowdefn */
170571
+ 306, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */
170572
+ 307, /* (311) windowdefn ::= nm AS LP window RP */
170573
+ 308, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
170574
+ 308, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
170575
+ 308, /* (314) window ::= ORDER BY sortlist frame_opt */
170576
+ 308, /* (315) window ::= nm ORDER BY sortlist frame_opt */
170577
+ 308, /* (316) window ::= frame_opt */
170578
+ 308, /* (317) window ::= nm frame_opt */
170579
+ 309, /* (318) frame_opt ::= */
170580
+ 309, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
170581
+ 309, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
170582
+ 313, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */
170583
+ 315, /* (322) frame_bound_s ::= frame_bound */
170584
+ 315, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */
170585
+ 316, /* (324) frame_bound_e ::= frame_bound */
170586
+ 316, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */
170587
+ 314, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */
170588
+ 314, /* (327) frame_bound ::= CURRENT ROW */
170589
+ 317, /* (328) frame_exclude_opt ::= */
170590
+ 317, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */
170591
+ 318, /* (330) frame_exclude ::= NO OTHERS */
170592
+ 318, /* (331) frame_exclude ::= CURRENT ROW */
170593
+ 318, /* (332) frame_exclude ::= GROUP|TIES */
170594
+ 251, /* (333) window_clause ::= WINDOW windowdefn_list */
170595
+ 273, /* (334) filter_over ::= filter_clause over_clause */
170596
+ 273, /* (335) filter_over ::= over_clause */
170597
+ 273, /* (336) filter_over ::= filter_clause */
170598
+ 312, /* (337) over_clause ::= OVER LP window RP */
170599
+ 312, /* (338) over_clause ::= OVER nm */
170600
+ 311, /* (339) filter_clause ::= FILTER LP WHERE expr RP */
170601
+ 185, /* (340) input ::= cmdlist */
170602
+ 186, /* (341) cmdlist ::= cmdlist ecmd */
170603
+ 186, /* (342) cmdlist ::= ecmd */
170604
+ 187, /* (343) ecmd ::= SEMI */
170605
+ 187, /* (344) ecmd ::= cmdx SEMI */
170606
+ 187, /* (345) ecmd ::= explain cmdx SEMI */
170607
+ 192, /* (346) trans_opt ::= */
170608
+ 192, /* (347) trans_opt ::= TRANSACTION */
170609
+ 192, /* (348) trans_opt ::= TRANSACTION nm */
170610
+ 194, /* (349) savepoint_opt ::= SAVEPOINT */
170611
+ 194, /* (350) savepoint_opt ::= */
170612
+ 190, /* (351) cmd ::= create_table create_table_args */
170613
+ 203, /* (352) table_option_set ::= table_option */
170614
+ 201, /* (353) columnlist ::= columnlist COMMA columnname carglist */
170615
+ 201, /* (354) columnlist ::= columnname carglist */
170616
+ 193, /* (355) nm ::= ID|INDEXED|JOIN_KW */
170617
+ 193, /* (356) nm ::= STRING */
170618
+ 208, /* (357) typetoken ::= typename */
170619
+ 209, /* (358) typename ::= ID|STRING */
170620
+ 210, /* (359) signed ::= plus_num */
170621
+ 210, /* (360) signed ::= minus_num */
170622
+ 207, /* (361) carglist ::= carglist ccons */
170623
+ 207, /* (362) carglist ::= */
170624
+ 215, /* (363) ccons ::= NULL onconf */
170625
+ 215, /* (364) ccons ::= GENERATED ALWAYS AS generated */
170626
+ 215, /* (365) ccons ::= AS generated */
170627
+ 202, /* (366) conslist_opt ::= COMMA conslist */
170628
+ 228, /* (367) conslist ::= conslist tconscomma tcons */
170629
+ 228, /* (368) conslist ::= tcons */
170630
+ 229, /* (369) tconscomma ::= */
170631
+ 233, /* (370) defer_subclause_opt ::= defer_subclause */
170632
+ 235, /* (371) resolvetype ::= raisetype */
170633
+ 239, /* (372) selectnowith ::= oneselect */
170634
+ 240, /* (373) oneselect ::= values */
170635
+ 254, /* (374) sclp ::= selcollist COMMA */
170636
+ 255, /* (375) as ::= ID|STRING */
170637
+ 264, /* (376) indexed_opt ::= indexed_by */
170638
+ 272, /* (377) returning ::= */
170639
+ 217, /* (378) expr ::= term */
170640
+ 274, /* (379) likeop ::= LIKE_KW|MATCH */
170641
+ 278, /* (380) case_operand ::= expr */
170503170642
261, /* (381) exprlist ::= nexprlist */
170504170643
284, /* (382) nmnum ::= plus_num */
170505170644
284, /* (383) nmnum ::= nm */
170506170645
284, /* (384) nmnum ::= ON */
170507170646
284, /* (385) nmnum ::= DELETE */
@@ -170754,162 +170893,162 @@
170754170893
-5, /* (224) expr ::= CASE case_operand case_exprlist case_else END */
170755170894
-5, /* (225) case_exprlist ::= case_exprlist WHEN expr THEN expr */
170756170895
-4, /* (226) case_exprlist ::= WHEN expr THEN expr */
170757170896
-2, /* (227) case_else ::= ELSE expr */
170758170897
0, /* (228) case_else ::= */
170759
- -1, /* (229) case_operand ::= expr */
170760
- 0, /* (230) case_operand ::= */
170761
- 0, /* (231) exprlist ::= */
170762
- -3, /* (232) nexprlist ::= nexprlist COMMA expr */
170763
- -1, /* (233) nexprlist ::= expr */
170764
- 0, /* (234) paren_exprlist ::= */
170765
- -3, /* (235) paren_exprlist ::= LP exprlist RP */
170766
- -12, /* (236) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
170767
- -1, /* (237) uniqueflag ::= UNIQUE */
170768
- 0, /* (238) uniqueflag ::= */
170769
- 0, /* (239) eidlist_opt ::= */
170770
- -3, /* (240) eidlist_opt ::= LP eidlist RP */
170771
- -5, /* (241) eidlist ::= eidlist COMMA nm collate sortorder */
170772
- -3, /* (242) eidlist ::= nm collate sortorder */
170773
- 0, /* (243) collate ::= */
170774
- -2, /* (244) collate ::= COLLATE ID|STRING */
170775
- -4, /* (245) cmd ::= DROP INDEX ifexists fullname */
170776
- -2, /* (246) cmd ::= VACUUM vinto */
170777
- -3, /* (247) cmd ::= VACUUM nm vinto */
170778
- -2, /* (248) vinto ::= INTO expr */
170779
- 0, /* (249) vinto ::= */
170780
- -3, /* (250) cmd ::= PRAGMA nm dbnm */
170781
- -5, /* (251) cmd ::= PRAGMA nm dbnm EQ nmnum */
170782
- -6, /* (252) cmd ::= PRAGMA nm dbnm LP nmnum RP */
170783
- -5, /* (253) cmd ::= PRAGMA nm dbnm EQ minus_num */
170784
- -6, /* (254) cmd ::= PRAGMA nm dbnm LP minus_num RP */
170785
- -2, /* (255) plus_num ::= PLUS INTEGER|FLOAT */
170786
- -2, /* (256) minus_num ::= MINUS INTEGER|FLOAT */
170787
- -5, /* (257) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
170788
- -11, /* (258) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
170789
- -1, /* (259) trigger_time ::= BEFORE|AFTER */
170790
- -2, /* (260) trigger_time ::= INSTEAD OF */
170791
- 0, /* (261) trigger_time ::= */
170792
- -1, /* (262) trigger_event ::= DELETE|INSERT */
170793
- -1, /* (263) trigger_event ::= UPDATE */
170794
- -3, /* (264) trigger_event ::= UPDATE OF idlist */
170795
- 0, /* (265) when_clause ::= */
170796
- -2, /* (266) when_clause ::= WHEN expr */
170797
- -3, /* (267) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
170798
- -2, /* (268) trigger_cmd_list ::= trigger_cmd SEMI */
170799
- -3, /* (269) trnm ::= nm DOT nm */
170800
- -3, /* (270) tridxby ::= INDEXED BY nm */
170801
- -2, /* (271) tridxby ::= NOT INDEXED */
170802
- -9, /* (272) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
170803
- -8, /* (273) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
170804
- -6, /* (274) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
170805
- -3, /* (275) trigger_cmd ::= scanpt select scanpt */
170806
- -4, /* (276) expr ::= RAISE LP IGNORE RP */
170807
- -6, /* (277) expr ::= RAISE LP raisetype COMMA nm RP */
170808
- -1, /* (278) raisetype ::= ROLLBACK */
170809
- -1, /* (279) raisetype ::= ABORT */
170810
- -1, /* (280) raisetype ::= FAIL */
170811
- -4, /* (281) cmd ::= DROP TRIGGER ifexists fullname */
170812
- -6, /* (282) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
170813
- -3, /* (283) cmd ::= DETACH database_kw_opt expr */
170814
- 0, /* (284) key_opt ::= */
170815
- -2, /* (285) key_opt ::= KEY expr */
170816
- -1, /* (286) cmd ::= REINDEX */
170817
- -3, /* (287) cmd ::= REINDEX nm dbnm */
170818
- -1, /* (288) cmd ::= ANALYZE */
170819
- -3, /* (289) cmd ::= ANALYZE nm dbnm */
170820
- -6, /* (290) cmd ::= ALTER TABLE fullname RENAME TO nm */
170821
- -7, /* (291) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
170822
- -6, /* (292) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
170823
- -1, /* (293) add_column_fullname ::= fullname */
170824
- -8, /* (294) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
170825
- -1, /* (295) cmd ::= create_vtab */
170826
- -4, /* (296) cmd ::= create_vtab LP vtabarglist RP */
170827
- -8, /* (297) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
170828
- 0, /* (298) vtabarg ::= */
170829
- -1, /* (299) vtabargtoken ::= ANY */
170830
- -3, /* (300) vtabargtoken ::= lp anylist RP */
170831
- -1, /* (301) lp ::= LP */
170832
- -2, /* (302) with ::= WITH wqlist */
170833
- -3, /* (303) with ::= WITH RECURSIVE wqlist */
170834
- -1, /* (304) wqas ::= AS */
170835
- -2, /* (305) wqas ::= AS MATERIALIZED */
170836
- -3, /* (306) wqas ::= AS NOT MATERIALIZED */
170837
- -6, /* (307) wqitem ::= nm eidlist_opt wqas LP select RP */
170838
- -1, /* (308) wqlist ::= wqitem */
170839
- -3, /* (309) wqlist ::= wqlist COMMA wqitem */
170840
- -1, /* (310) windowdefn_list ::= windowdefn */
170841
- -3, /* (311) windowdefn_list ::= windowdefn_list COMMA windowdefn */
170842
- -5, /* (312) windowdefn ::= nm AS LP window RP */
170843
- -5, /* (313) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
170844
- -6, /* (314) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
170845
- -4, /* (315) window ::= ORDER BY sortlist frame_opt */
170846
- -5, /* (316) window ::= nm ORDER BY sortlist frame_opt */
170847
- -1, /* (317) window ::= frame_opt */
170848
- -2, /* (318) window ::= nm frame_opt */
170849
- 0, /* (319) frame_opt ::= */
170850
- -3, /* (320) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
170851
- -6, /* (321) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
170852
- -1, /* (322) range_or_rows ::= RANGE|ROWS|GROUPS */
170853
- -1, /* (323) frame_bound_s ::= frame_bound */
170854
- -2, /* (324) frame_bound_s ::= UNBOUNDED PRECEDING */
170855
- -1, /* (325) frame_bound_e ::= frame_bound */
170856
- -2, /* (326) frame_bound_e ::= UNBOUNDED FOLLOWING */
170857
- -2, /* (327) frame_bound ::= expr PRECEDING|FOLLOWING */
170858
- -2, /* (328) frame_bound ::= CURRENT ROW */
170859
- 0, /* (329) frame_exclude_opt ::= */
170860
- -2, /* (330) frame_exclude_opt ::= EXCLUDE frame_exclude */
170861
- -2, /* (331) frame_exclude ::= NO OTHERS */
170862
- -2, /* (332) frame_exclude ::= CURRENT ROW */
170863
- -1, /* (333) frame_exclude ::= GROUP|TIES */
170864
- -2, /* (334) window_clause ::= WINDOW windowdefn_list */
170865
- -2, /* (335) filter_over ::= filter_clause over_clause */
170866
- -1, /* (336) filter_over ::= over_clause */
170867
- -1, /* (337) filter_over ::= filter_clause */
170868
- -4, /* (338) over_clause ::= OVER LP window RP */
170869
- -2, /* (339) over_clause ::= OVER nm */
170870
- -5, /* (340) filter_clause ::= FILTER LP WHERE expr RP */
170871
- -1, /* (341) input ::= cmdlist */
170872
- -2, /* (342) cmdlist ::= cmdlist ecmd */
170873
- -1, /* (343) cmdlist ::= ecmd */
170874
- -1, /* (344) ecmd ::= SEMI */
170875
- -2, /* (345) ecmd ::= cmdx SEMI */
170876
- -3, /* (346) ecmd ::= explain cmdx SEMI */
170877
- 0, /* (347) trans_opt ::= */
170878
- -1, /* (348) trans_opt ::= TRANSACTION */
170879
- -2, /* (349) trans_opt ::= TRANSACTION nm */
170880
- -1, /* (350) savepoint_opt ::= SAVEPOINT */
170881
- 0, /* (351) savepoint_opt ::= */
170882
- -2, /* (352) cmd ::= create_table create_table_args */
170883
- -1, /* (353) table_option_set ::= table_option */
170884
- -4, /* (354) columnlist ::= columnlist COMMA columnname carglist */
170885
- -2, /* (355) columnlist ::= columnname carglist */
170886
- -1, /* (356) nm ::= ID|INDEXED|JOIN_KW */
170887
- -1, /* (357) nm ::= STRING */
170888
- -1, /* (358) typetoken ::= typename */
170889
- -1, /* (359) typename ::= ID|STRING */
170890
- -1, /* (360) signed ::= plus_num */
170891
- -1, /* (361) signed ::= minus_num */
170892
- -2, /* (362) carglist ::= carglist ccons */
170893
- 0, /* (363) carglist ::= */
170894
- -2, /* (364) ccons ::= NULL onconf */
170895
- -4, /* (365) ccons ::= GENERATED ALWAYS AS generated */
170896
- -2, /* (366) ccons ::= AS generated */
170897
- -2, /* (367) conslist_opt ::= COMMA conslist */
170898
- -3, /* (368) conslist ::= conslist tconscomma tcons */
170899
- -1, /* (369) conslist ::= tcons */
170900
- 0, /* (370) tconscomma ::= */
170901
- -1, /* (371) defer_subclause_opt ::= defer_subclause */
170902
- -1, /* (372) resolvetype ::= raisetype */
170903
- -1, /* (373) selectnowith ::= oneselect */
170904
- -1, /* (374) oneselect ::= values */
170905
- -2, /* (375) sclp ::= selcollist COMMA */
170906
- -1, /* (376) as ::= ID|STRING */
170907
- -1, /* (377) indexed_opt ::= indexed_by */
170908
- 0, /* (378) returning ::= */
170909
- -1, /* (379) expr ::= term */
170910
- -1, /* (380) likeop ::= LIKE_KW|MATCH */
170898
+ 0, /* (229) case_operand ::= */
170899
+ 0, /* (230) exprlist ::= */
170900
+ -3, /* (231) nexprlist ::= nexprlist COMMA expr */
170901
+ -1, /* (232) nexprlist ::= expr */
170902
+ 0, /* (233) paren_exprlist ::= */
170903
+ -3, /* (234) paren_exprlist ::= LP exprlist RP */
170904
+ -12, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
170905
+ -1, /* (236) uniqueflag ::= UNIQUE */
170906
+ 0, /* (237) uniqueflag ::= */
170907
+ 0, /* (238) eidlist_opt ::= */
170908
+ -3, /* (239) eidlist_opt ::= LP eidlist RP */
170909
+ -5, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */
170910
+ -3, /* (241) eidlist ::= nm collate sortorder */
170911
+ 0, /* (242) collate ::= */
170912
+ -2, /* (243) collate ::= COLLATE ID|STRING */
170913
+ -4, /* (244) cmd ::= DROP INDEX ifexists fullname */
170914
+ -2, /* (245) cmd ::= VACUUM vinto */
170915
+ -3, /* (246) cmd ::= VACUUM nm vinto */
170916
+ -2, /* (247) vinto ::= INTO expr */
170917
+ 0, /* (248) vinto ::= */
170918
+ -3, /* (249) cmd ::= PRAGMA nm dbnm */
170919
+ -5, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */
170920
+ -6, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */
170921
+ -5, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */
170922
+ -6, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */
170923
+ -2, /* (254) plus_num ::= PLUS INTEGER|FLOAT */
170924
+ -2, /* (255) minus_num ::= MINUS INTEGER|FLOAT */
170925
+ -5, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
170926
+ -11, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
170927
+ -1, /* (258) trigger_time ::= BEFORE|AFTER */
170928
+ -2, /* (259) trigger_time ::= INSTEAD OF */
170929
+ 0, /* (260) trigger_time ::= */
170930
+ -1, /* (261) trigger_event ::= DELETE|INSERT */
170931
+ -1, /* (262) trigger_event ::= UPDATE */
170932
+ -3, /* (263) trigger_event ::= UPDATE OF idlist */
170933
+ 0, /* (264) when_clause ::= */
170934
+ -2, /* (265) when_clause ::= WHEN expr */
170935
+ -3, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
170936
+ -2, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */
170937
+ -3, /* (268) trnm ::= nm DOT nm */
170938
+ -3, /* (269) tridxby ::= INDEXED BY nm */
170939
+ -2, /* (270) tridxby ::= NOT INDEXED */
170940
+ -9, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
170941
+ -8, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
170942
+ -6, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
170943
+ -3, /* (274) trigger_cmd ::= scanpt select scanpt */
170944
+ -4, /* (275) expr ::= RAISE LP IGNORE RP */
170945
+ -6, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */
170946
+ -1, /* (277) raisetype ::= ROLLBACK */
170947
+ -1, /* (278) raisetype ::= ABORT */
170948
+ -1, /* (279) raisetype ::= FAIL */
170949
+ -4, /* (280) cmd ::= DROP TRIGGER ifexists fullname */
170950
+ -6, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
170951
+ -3, /* (282) cmd ::= DETACH database_kw_opt expr */
170952
+ 0, /* (283) key_opt ::= */
170953
+ -2, /* (284) key_opt ::= KEY expr */
170954
+ -1, /* (285) cmd ::= REINDEX */
170955
+ -3, /* (286) cmd ::= REINDEX nm dbnm */
170956
+ -1, /* (287) cmd ::= ANALYZE */
170957
+ -3, /* (288) cmd ::= ANALYZE nm dbnm */
170958
+ -6, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */
170959
+ -7, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
170960
+ -6, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
170961
+ -1, /* (292) add_column_fullname ::= fullname */
170962
+ -8, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
170963
+ -1, /* (294) cmd ::= create_vtab */
170964
+ -4, /* (295) cmd ::= create_vtab LP vtabarglist RP */
170965
+ -8, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
170966
+ 0, /* (297) vtabarg ::= */
170967
+ -1, /* (298) vtabargtoken ::= ANY */
170968
+ -3, /* (299) vtabargtoken ::= lp anylist RP */
170969
+ -1, /* (300) lp ::= LP */
170970
+ -2, /* (301) with ::= WITH wqlist */
170971
+ -3, /* (302) with ::= WITH RECURSIVE wqlist */
170972
+ -1, /* (303) wqas ::= AS */
170973
+ -2, /* (304) wqas ::= AS MATERIALIZED */
170974
+ -3, /* (305) wqas ::= AS NOT MATERIALIZED */
170975
+ -6, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */
170976
+ -1, /* (307) wqlist ::= wqitem */
170977
+ -3, /* (308) wqlist ::= wqlist COMMA wqitem */
170978
+ -1, /* (309) windowdefn_list ::= windowdefn */
170979
+ -3, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */
170980
+ -5, /* (311) windowdefn ::= nm AS LP window RP */
170981
+ -5, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
170982
+ -6, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
170983
+ -4, /* (314) window ::= ORDER BY sortlist frame_opt */
170984
+ -5, /* (315) window ::= nm ORDER BY sortlist frame_opt */
170985
+ -1, /* (316) window ::= frame_opt */
170986
+ -2, /* (317) window ::= nm frame_opt */
170987
+ 0, /* (318) frame_opt ::= */
170988
+ -3, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
170989
+ -6, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
170990
+ -1, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */
170991
+ -1, /* (322) frame_bound_s ::= frame_bound */
170992
+ -2, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */
170993
+ -1, /* (324) frame_bound_e ::= frame_bound */
170994
+ -2, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */
170995
+ -2, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */
170996
+ -2, /* (327) frame_bound ::= CURRENT ROW */
170997
+ 0, /* (328) frame_exclude_opt ::= */
170998
+ -2, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */
170999
+ -2, /* (330) frame_exclude ::= NO OTHERS */
171000
+ -2, /* (331) frame_exclude ::= CURRENT ROW */
171001
+ -1, /* (332) frame_exclude ::= GROUP|TIES */
171002
+ -2, /* (333) window_clause ::= WINDOW windowdefn_list */
171003
+ -2, /* (334) filter_over ::= filter_clause over_clause */
171004
+ -1, /* (335) filter_over ::= over_clause */
171005
+ -1, /* (336) filter_over ::= filter_clause */
171006
+ -4, /* (337) over_clause ::= OVER LP window RP */
171007
+ -2, /* (338) over_clause ::= OVER nm */
171008
+ -5, /* (339) filter_clause ::= FILTER LP WHERE expr RP */
171009
+ -1, /* (340) input ::= cmdlist */
171010
+ -2, /* (341) cmdlist ::= cmdlist ecmd */
171011
+ -1, /* (342) cmdlist ::= ecmd */
171012
+ -1, /* (343) ecmd ::= SEMI */
171013
+ -2, /* (344) ecmd ::= cmdx SEMI */
171014
+ -3, /* (345) ecmd ::= explain cmdx SEMI */
171015
+ 0, /* (346) trans_opt ::= */
171016
+ -1, /* (347) trans_opt ::= TRANSACTION */
171017
+ -2, /* (348) trans_opt ::= TRANSACTION nm */
171018
+ -1, /* (349) savepoint_opt ::= SAVEPOINT */
171019
+ 0, /* (350) savepoint_opt ::= */
171020
+ -2, /* (351) cmd ::= create_table create_table_args */
171021
+ -1, /* (352) table_option_set ::= table_option */
171022
+ -4, /* (353) columnlist ::= columnlist COMMA columnname carglist */
171023
+ -2, /* (354) columnlist ::= columnname carglist */
171024
+ -1, /* (355) nm ::= ID|INDEXED|JOIN_KW */
171025
+ -1, /* (356) nm ::= STRING */
171026
+ -1, /* (357) typetoken ::= typename */
171027
+ -1, /* (358) typename ::= ID|STRING */
171028
+ -1, /* (359) signed ::= plus_num */
171029
+ -1, /* (360) signed ::= minus_num */
171030
+ -2, /* (361) carglist ::= carglist ccons */
171031
+ 0, /* (362) carglist ::= */
171032
+ -2, /* (363) ccons ::= NULL onconf */
171033
+ -4, /* (364) ccons ::= GENERATED ALWAYS AS generated */
171034
+ -2, /* (365) ccons ::= AS generated */
171035
+ -2, /* (366) conslist_opt ::= COMMA conslist */
171036
+ -3, /* (367) conslist ::= conslist tconscomma tcons */
171037
+ -1, /* (368) conslist ::= tcons */
171038
+ 0, /* (369) tconscomma ::= */
171039
+ -1, /* (370) defer_subclause_opt ::= defer_subclause */
171040
+ -1, /* (371) resolvetype ::= raisetype */
171041
+ -1, /* (372) selectnowith ::= oneselect */
171042
+ -1, /* (373) oneselect ::= values */
171043
+ -2, /* (374) sclp ::= selcollist COMMA */
171044
+ -1, /* (375) as ::= ID|STRING */
171045
+ -1, /* (376) indexed_opt ::= indexed_by */
171046
+ 0, /* (377) returning ::= */
171047
+ -1, /* (378) expr ::= term */
171048
+ -1, /* (379) likeop ::= LIKE_KW|MATCH */
171049
+ -1, /* (380) case_operand ::= expr */
170911171050
-1, /* (381) exprlist ::= nexprlist */
170912171051
-1, /* (382) nmnum ::= plus_num */
170913171052
-1, /* (383) nmnum ::= nm */
170914171053
-1, /* (384) nmnum ::= ON */
170915171054
-1, /* (385) nmnum ::= DELETE */
@@ -170987,11 +171126,11 @@
170987171126
{yymsp[1].minor.yy394 = TK_DEFERRED;}
170988171127
break;
170989171128
case 5: /* transtype ::= DEFERRED */
170990171129
case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
170991171130
case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
170992
- case 322: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==322);
171131
+ case 321: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==321);
170993171132
{yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/}
170994171133
break;
170995171134
case 8: /* cmd ::= COMMIT|END trans_opt */
170996171135
case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
170997171136
{sqlite3EndTransaction(pParse,yymsp[-1].major);}
@@ -171024,11 +171163,11 @@
171024171163
case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
171025171164
case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
171026171165
case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72);
171027171166
case 81: /* ifexists ::= */ yytestcase(yyruleno==81);
171028171167
case 98: /* distinct ::= */ yytestcase(yyruleno==98);
171029
- case 243: /* collate ::= */ yytestcase(yyruleno==243);
171168
+ case 242: /* collate ::= */ yytestcase(yyruleno==242);
171030171169
{yymsp[1].minor.yy394 = 0;}
171031171170
break;
171032171171
case 16: /* ifnotexists ::= IF NOT EXISTS */
171033171172
{yymsp[-2].minor.yy394 = 1;}
171034171173
break;
@@ -171210,11 +171349,11 @@
171210171349
break;
171211171350
case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
171212171351
case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80);
171213171352
case 215: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==215);
171214171353
case 218: /* in_op ::= NOT IN */ yytestcase(yyruleno==218);
171215
- case 244: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==244);
171354
+ case 243: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==243);
171216171355
{yymsp[-1].minor.yy394 = 1;}
171217171356
break;
171218171357
case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
171219171358
{yymsp[-1].minor.yy394 = 0;}
171220171359
break;
@@ -171360,13 +171499,13 @@
171360171499
{yymsp[0].minor.yy394 = SF_All;}
171361171500
break;
171362171501
case 99: /* sclp ::= */
171363171502
case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132);
171364171503
case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142);
171365
- case 231: /* exprlist ::= */ yytestcase(yyruleno==231);
171366
- case 234: /* paren_exprlist ::= */ yytestcase(yyruleno==234);
171367
- case 239: /* eidlist_opt ::= */ yytestcase(yyruleno==239);
171504
+ case 230: /* exprlist ::= */ yytestcase(yyruleno==230);
171505
+ case 233: /* paren_exprlist ::= */ yytestcase(yyruleno==233);
171506
+ case 238: /* eidlist_opt ::= */ yytestcase(yyruleno==238);
171368171507
{yymsp[1].minor.yy322 = 0;}
171369171508
break;
171370171509
case 100: /* selcollist ::= sclp scanpt expr scanpt as */
171371171510
{
171372171511
yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
@@ -171388,12 +171527,12 @@
171388171527
yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
171389171528
}
171390171529
break;
171391171530
case 103: /* as ::= AS nm */
171392171531
case 115: /* dbnm ::= DOT nm */ yytestcase(yyruleno==115);
171393
- case 255: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==255);
171394
- case 256: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==256);
171532
+ case 254: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==254);
171533
+ case 255: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==255);
171395171534
{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
171396171535
break;
171397171536
case 105: /* from ::= */
171398171537
case 108: /* stl_prefix ::= */ yytestcase(yyruleno==108);
171399171538
{yymsp[1].minor.yy131 = 0;}
@@ -171433,11 +171572,11 @@
171433171572
break;
171434171573
case 113: /* seltablist ::= stl_prefix LP seltablist RP as on_using */
171435171574
{
171436171575
if( yymsp[-5].minor.yy131==0 && yymsp[-1].minor.yy0.n==0 && yymsp[0].minor.yy561.pOn==0 && yymsp[0].minor.yy561.pUsing==0 ){
171437171576
yymsp[-5].minor.yy131 = yymsp[-3].minor.yy131;
171438
- }else if( yymsp[-3].minor.yy131->nSrc==1 ){
171577
+ }else if( ALWAYS(yymsp[-3].minor.yy131!=0) && yymsp[-3].minor.yy131->nSrc==1 ){
171439171578
yymsp[-5].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy131,0,0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy561);
171440171579
if( yymsp[-5].minor.yy131 ){
171441171580
SrcItem *pNew = &yymsp[-5].minor.yy131->a[yymsp[-5].minor.yy131->nSrc-1];
171442171581
SrcItem *pOld = yymsp[-3].minor.yy131->a;
171443171582
pNew->zName = pOld->zName;
@@ -171562,19 +171701,19 @@
171562171701
case 144: /* having_opt ::= */
171563171702
case 146: /* limit_opt ::= */ yytestcase(yyruleno==146);
171564171703
case 151: /* where_opt ::= */ yytestcase(yyruleno==151);
171565171704
case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153);
171566171705
case 228: /* case_else ::= */ yytestcase(yyruleno==228);
171567
- case 230: /* case_operand ::= */ yytestcase(yyruleno==230);
171568
- case 249: /* vinto ::= */ yytestcase(yyruleno==249);
171706
+ case 229: /* case_operand ::= */ yytestcase(yyruleno==229);
171707
+ case 248: /* vinto ::= */ yytestcase(yyruleno==248);
171569171708
{yymsp[1].minor.yy528 = 0;}
171570171709
break;
171571171710
case 145: /* having_opt ::= HAVING expr */
171572171711
case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152);
171573171712
case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154);
171574171713
case 227: /* case_else ::= ELSE expr */ yytestcase(yyruleno==227);
171575
- case 248: /* vinto ::= INTO expr */ yytestcase(yyruleno==248);
171714
+ case 247: /* vinto ::= INTO expr */ yytestcase(yyruleno==247);
171576171715
{yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;}
171577171716
break;
171578171717
case 147: /* limit_opt ::= LIMIT expr */
171579171718
{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);}
171580171719
break;
@@ -172001,394 +172140,391 @@
172001172140
{
172002172141
yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
172003172142
yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528);
172004172143
}
172005172144
break;
172006
- case 229: /* case_operand ::= expr */
172007
-{yymsp[0].minor.yy528 = yymsp[0].minor.yy528; /*A-overwrites-X*/}
172008
- break;
172009
- case 232: /* nexprlist ::= nexprlist COMMA expr */
172145
+ case 231: /* nexprlist ::= nexprlist COMMA expr */
172010172146
{yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);}
172011172147
break;
172012
- case 233: /* nexprlist ::= expr */
172148
+ case 232: /* nexprlist ::= expr */
172013172149
{yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/}
172014172150
break;
172015
- case 235: /* paren_exprlist ::= LP exprlist RP */
172016
- case 240: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==240);
172151
+ case 234: /* paren_exprlist ::= LP exprlist RP */
172152
+ case 239: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==239);
172017172153
{yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
172018172154
break;
172019
- case 236: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
172155
+ case 235: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
172020172156
{
172021172157
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
172022172158
sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394,
172023172159
&yymsp[-11].minor.yy0, yymsp[0].minor.yy528, SQLITE_SO_ASC, yymsp[-8].minor.yy394, SQLITE_IDXTYPE_APPDEF);
172024172160
if( IN_RENAME_OBJECT && pParse->pNewIndex ){
172025172161
sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
172026172162
}
172027172163
}
172028172164
break;
172029
- case 237: /* uniqueflag ::= UNIQUE */
172030
- case 279: /* raisetype ::= ABORT */ yytestcase(yyruleno==279);
172165
+ case 236: /* uniqueflag ::= UNIQUE */
172166
+ case 278: /* raisetype ::= ABORT */ yytestcase(yyruleno==278);
172031172167
{yymsp[0].minor.yy394 = OE_Abort;}
172032172168
break;
172033
- case 238: /* uniqueflag ::= */
172169
+ case 237: /* uniqueflag ::= */
172034172170
{yymsp[1].minor.yy394 = OE_None;}
172035172171
break;
172036
- case 241: /* eidlist ::= eidlist COMMA nm collate sortorder */
172172
+ case 240: /* eidlist ::= eidlist COMMA nm collate sortorder */
172037172173
{
172038172174
yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394);
172039172175
}
172040172176
break;
172041
- case 242: /* eidlist ::= nm collate sortorder */
172177
+ case 241: /* eidlist ::= nm collate sortorder */
172042172178
{
172043172179
yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/
172044172180
}
172045172181
break;
172046
- case 245: /* cmd ::= DROP INDEX ifexists fullname */
172182
+ case 244: /* cmd ::= DROP INDEX ifexists fullname */
172047172183
{sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);}
172048172184
break;
172049
- case 246: /* cmd ::= VACUUM vinto */
172185
+ case 245: /* cmd ::= VACUUM vinto */
172050172186
{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);}
172051172187
break;
172052
- case 247: /* cmd ::= VACUUM nm vinto */
172188
+ case 246: /* cmd ::= VACUUM nm vinto */
172053172189
{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);}
172054172190
break;
172055
- case 250: /* cmd ::= PRAGMA nm dbnm */
172191
+ case 249: /* cmd ::= PRAGMA nm dbnm */
172056172192
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
172057172193
break;
172058
- case 251: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
172194
+ case 250: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
172059172195
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
172060172196
break;
172061
- case 252: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
172197
+ case 251: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
172062172198
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
172063172199
break;
172064
- case 253: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
172200
+ case 252: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
172065172201
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
172066172202
break;
172067
- case 254: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
172203
+ case 253: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
172068172204
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
172069172205
break;
172070
- case 257: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
172206
+ case 256: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
172071172207
{
172072172208
Token all;
172073172209
all.z = yymsp[-3].minor.yy0.z;
172074172210
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
172075172211
sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all);
172076172212
}
172077172213
break;
172078
- case 258: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
172214
+ case 257: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
172079172215
{
172080172216
sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394);
172081172217
yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
172082172218
}
172083172219
break;
172084
- case 259: /* trigger_time ::= BEFORE|AFTER */
172220
+ case 258: /* trigger_time ::= BEFORE|AFTER */
172085172221
{ yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ }
172086172222
break;
172087
- case 260: /* trigger_time ::= INSTEAD OF */
172223
+ case 259: /* trigger_time ::= INSTEAD OF */
172088172224
{ yymsp[-1].minor.yy394 = TK_INSTEAD;}
172089172225
break;
172090
- case 261: /* trigger_time ::= */
172226
+ case 260: /* trigger_time ::= */
172091172227
{ yymsp[1].minor.yy394 = TK_BEFORE; }
172092172228
break;
172093
- case 262: /* trigger_event ::= DELETE|INSERT */
172094
- case 263: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==263);
172229
+ case 261: /* trigger_event ::= DELETE|INSERT */
172230
+ case 262: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==262);
172095172231
{yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;}
172096172232
break;
172097
- case 264: /* trigger_event ::= UPDATE OF idlist */
172233
+ case 263: /* trigger_event ::= UPDATE OF idlist */
172098172234
{yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;}
172099172235
break;
172100
- case 265: /* when_clause ::= */
172101
- case 284: /* key_opt ::= */ yytestcase(yyruleno==284);
172236
+ case 264: /* when_clause ::= */
172237
+ case 283: /* key_opt ::= */ yytestcase(yyruleno==283);
172102172238
{ yymsp[1].minor.yy528 = 0; }
172103172239
break;
172104
- case 266: /* when_clause ::= WHEN expr */
172105
- case 285: /* key_opt ::= KEY expr */ yytestcase(yyruleno==285);
172240
+ case 265: /* when_clause ::= WHEN expr */
172241
+ case 284: /* key_opt ::= KEY expr */ yytestcase(yyruleno==284);
172106172242
{ yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; }
172107172243
break;
172108
- case 267: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
172244
+ case 266: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
172109172245
{
172110172246
assert( yymsp[-2].minor.yy33!=0 );
172111172247
yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33;
172112172248
yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33;
172113172249
}
172114172250
break;
172115
- case 268: /* trigger_cmd_list ::= trigger_cmd SEMI */
172251
+ case 267: /* trigger_cmd_list ::= trigger_cmd SEMI */
172116172252
{
172117172253
assert( yymsp[-1].minor.yy33!=0 );
172118172254
yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33;
172119172255
}
172120172256
break;
172121
- case 269: /* trnm ::= nm DOT nm */
172257
+ case 268: /* trnm ::= nm DOT nm */
172122172258
{
172123172259
yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
172124172260
sqlite3ErrorMsg(pParse,
172125172261
"qualified table names are not allowed on INSERT, UPDATE, and DELETE "
172126172262
"statements within triggers");
172127172263
}
172128172264
break;
172129
- case 270: /* tridxby ::= INDEXED BY nm */
172265
+ case 269: /* tridxby ::= INDEXED BY nm */
172130172266
{
172131172267
sqlite3ErrorMsg(pParse,
172132172268
"the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
172133172269
"within triggers");
172134172270
}
172135172271
break;
172136
- case 271: /* tridxby ::= NOT INDEXED */
172272
+ case 270: /* tridxby ::= NOT INDEXED */
172137172273
{
172138172274
sqlite3ErrorMsg(pParse,
172139172275
"the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
172140172276
"within triggers");
172141172277
}
172142172278
break;
172143
- case 272: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
172279
+ case 271: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
172144172280
{yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);}
172145172281
yymsp[-8].minor.yy33 = yylhsminor.yy33;
172146172282
break;
172147
- case 273: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
172283
+ case 272: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
172148172284
{
172149172285
yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/
172150172286
}
172151172287
yymsp[-7].minor.yy33 = yylhsminor.yy33;
172152172288
break;
172153
- case 274: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
172289
+ case 273: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
172154172290
{yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);}
172155172291
yymsp[-5].minor.yy33 = yylhsminor.yy33;
172156172292
break;
172157
- case 275: /* trigger_cmd ::= scanpt select scanpt */
172293
+ case 274: /* trigger_cmd ::= scanpt select scanpt */
172158172294
{yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/}
172159172295
yymsp[-2].minor.yy33 = yylhsminor.yy33;
172160172296
break;
172161
- case 276: /* expr ::= RAISE LP IGNORE RP */
172297
+ case 275: /* expr ::= RAISE LP IGNORE RP */
172162172298
{
172163172299
yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
172164172300
if( yymsp[-3].minor.yy528 ){
172165172301
yymsp[-3].minor.yy528->affExpr = OE_Ignore;
172166172302
}
172167172303
}
172168172304
break;
172169
- case 277: /* expr ::= RAISE LP raisetype COMMA nm RP */
172305
+ case 276: /* expr ::= RAISE LP raisetype COMMA nm RP */
172170172306
{
172171172307
yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
172172172308
if( yymsp[-5].minor.yy528 ) {
172173172309
yymsp[-5].minor.yy528->affExpr = (char)yymsp[-3].minor.yy394;
172174172310
}
172175172311
}
172176172312
break;
172177
- case 278: /* raisetype ::= ROLLBACK */
172313
+ case 277: /* raisetype ::= ROLLBACK */
172178172314
{yymsp[0].minor.yy394 = OE_Rollback;}
172179172315
break;
172180
- case 280: /* raisetype ::= FAIL */
172316
+ case 279: /* raisetype ::= FAIL */
172181172317
{yymsp[0].minor.yy394 = OE_Fail;}
172182172318
break;
172183
- case 281: /* cmd ::= DROP TRIGGER ifexists fullname */
172319
+ case 280: /* cmd ::= DROP TRIGGER ifexists fullname */
172184172320
{
172185172321
sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394);
172186172322
}
172187172323
break;
172188
- case 282: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
172324
+ case 281: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
172189172325
{
172190172326
sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528);
172191172327
}
172192172328
break;
172193
- case 283: /* cmd ::= DETACH database_kw_opt expr */
172329
+ case 282: /* cmd ::= DETACH database_kw_opt expr */
172194172330
{
172195172331
sqlite3Detach(pParse, yymsp[0].minor.yy528);
172196172332
}
172197172333
break;
172198
- case 286: /* cmd ::= REINDEX */
172334
+ case 285: /* cmd ::= REINDEX */
172199172335
{sqlite3Reindex(pParse, 0, 0);}
172200172336
break;
172201
- case 287: /* cmd ::= REINDEX nm dbnm */
172337
+ case 286: /* cmd ::= REINDEX nm dbnm */
172202172338
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
172203172339
break;
172204
- case 288: /* cmd ::= ANALYZE */
172340
+ case 287: /* cmd ::= ANALYZE */
172205172341
{sqlite3Analyze(pParse, 0, 0);}
172206172342
break;
172207
- case 289: /* cmd ::= ANALYZE nm dbnm */
172343
+ case 288: /* cmd ::= ANALYZE nm dbnm */
172208172344
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
172209172345
break;
172210
- case 290: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
172346
+ case 289: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
172211172347
{
172212172348
sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0);
172213172349
}
172214172350
break;
172215
- case 291: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
172351
+ case 290: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
172216172352
{
172217172353
yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
172218172354
sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
172219172355
}
172220172356
break;
172221
- case 292: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
172357
+ case 291: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
172222172358
{
172223172359
sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0);
172224172360
}
172225172361
break;
172226
- case 293: /* add_column_fullname ::= fullname */
172362
+ case 292: /* add_column_fullname ::= fullname */
172227172363
{
172228172364
disableLookaside(pParse);
172229172365
sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131);
172230172366
}
172231172367
break;
172232
- case 294: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
172368
+ case 293: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
172233172369
{
172234172370
sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
172235172371
}
172236172372
break;
172237
- case 295: /* cmd ::= create_vtab */
172373
+ case 294: /* cmd ::= create_vtab */
172238172374
{sqlite3VtabFinishParse(pParse,0);}
172239172375
break;
172240
- case 296: /* cmd ::= create_vtab LP vtabarglist RP */
172376
+ case 295: /* cmd ::= create_vtab LP vtabarglist RP */
172241172377
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
172242172378
break;
172243
- case 297: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
172379
+ case 296: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
172244172380
{
172245172381
sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394);
172246172382
}
172247172383
break;
172248
- case 298: /* vtabarg ::= */
172384
+ case 297: /* vtabarg ::= */
172249172385
{sqlite3VtabArgInit(pParse);}
172250172386
break;
172251
- case 299: /* vtabargtoken ::= ANY */
172252
- case 300: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==300);
172253
- case 301: /* lp ::= LP */ yytestcase(yyruleno==301);
172387
+ case 298: /* vtabargtoken ::= ANY */
172388
+ case 299: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==299);
172389
+ case 300: /* lp ::= LP */ yytestcase(yyruleno==300);
172254172390
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
172255172391
break;
172256
- case 302: /* with ::= WITH wqlist */
172257
- case 303: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==303);
172392
+ case 301: /* with ::= WITH wqlist */
172393
+ case 302: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==302);
172258172394
{ sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); }
172259172395
break;
172260
- case 304: /* wqas ::= AS */
172396
+ case 303: /* wqas ::= AS */
172261172397
{yymsp[0].minor.yy516 = M10d_Any;}
172262172398
break;
172263
- case 305: /* wqas ::= AS MATERIALIZED */
172399
+ case 304: /* wqas ::= AS MATERIALIZED */
172264172400
{yymsp[-1].minor.yy516 = M10d_Yes;}
172265172401
break;
172266
- case 306: /* wqas ::= AS NOT MATERIALIZED */
172402
+ case 305: /* wqas ::= AS NOT MATERIALIZED */
172267172403
{yymsp[-2].minor.yy516 = M10d_No;}
172268172404
break;
172269
- case 307: /* wqitem ::= nm eidlist_opt wqas LP select RP */
172405
+ case 306: /* wqitem ::= nm eidlist_opt wqas LP select RP */
172270172406
{
172271172407
yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/
172272172408
}
172273172409
break;
172274
- case 308: /* wqlist ::= wqitem */
172410
+ case 307: /* wqlist ::= wqitem */
172275172411
{
172276172412
yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/
172277172413
}
172278172414
break;
172279
- case 309: /* wqlist ::= wqlist COMMA wqitem */
172415
+ case 308: /* wqlist ::= wqlist COMMA wqitem */
172280172416
{
172281172417
yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385);
172282172418
}
172283172419
break;
172284
- case 310: /* windowdefn_list ::= windowdefn */
172420
+ case 309: /* windowdefn_list ::= windowdefn */
172285172421
{ yylhsminor.yy41 = yymsp[0].minor.yy41; }
172286172422
yymsp[0].minor.yy41 = yylhsminor.yy41;
172287172423
break;
172288
- case 311: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
172424
+ case 310: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
172289172425
{
172290172426
assert( yymsp[0].minor.yy41!=0 );
172291172427
sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41);
172292172428
yymsp[0].minor.yy41->pNextWin = yymsp[-2].minor.yy41;
172293172429
yylhsminor.yy41 = yymsp[0].minor.yy41;
172294172430
}
172295172431
yymsp[-2].minor.yy41 = yylhsminor.yy41;
172296172432
break;
172297
- case 312: /* windowdefn ::= nm AS LP window RP */
172433
+ case 311: /* windowdefn ::= nm AS LP window RP */
172298172434
{
172299172435
if( ALWAYS(yymsp[-1].minor.yy41) ){
172300172436
yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
172301172437
}
172302172438
yylhsminor.yy41 = yymsp[-1].minor.yy41;
172303172439
}
172304172440
yymsp[-4].minor.yy41 = yylhsminor.yy41;
172305172441
break;
172306
- case 313: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
172442
+ case 312: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
172307172443
{
172308172444
yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0);
172309172445
}
172310172446
break;
172311
- case 314: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
172447
+ case 313: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
172312172448
{
172313172449
yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0);
172314172450
}
172315172451
yymsp[-5].minor.yy41 = yylhsminor.yy41;
172316172452
break;
172317
- case 315: /* window ::= ORDER BY sortlist frame_opt */
172453
+ case 314: /* window ::= ORDER BY sortlist frame_opt */
172318172454
{
172319172455
yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0);
172320172456
}
172321172457
break;
172322
- case 316: /* window ::= nm ORDER BY sortlist frame_opt */
172458
+ case 315: /* window ::= nm ORDER BY sortlist frame_opt */
172323172459
{
172324172460
yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
172325172461
}
172326172462
yymsp[-4].minor.yy41 = yylhsminor.yy41;
172327172463
break;
172328
- case 317: /* window ::= frame_opt */
172329
- case 336: /* filter_over ::= over_clause */ yytestcase(yyruleno==336);
172464
+ case 316: /* window ::= frame_opt */
172465
+ case 335: /* filter_over ::= over_clause */ yytestcase(yyruleno==335);
172330172466
{
172331172467
yylhsminor.yy41 = yymsp[0].minor.yy41;
172332172468
}
172333172469
yymsp[0].minor.yy41 = yylhsminor.yy41;
172334172470
break;
172335
- case 318: /* window ::= nm frame_opt */
172471
+ case 317: /* window ::= nm frame_opt */
172336172472
{
172337172473
yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0);
172338172474
}
172339172475
yymsp[-1].minor.yy41 = yylhsminor.yy41;
172340172476
break;
172341
- case 319: /* frame_opt ::= */
172477
+ case 318: /* frame_opt ::= */
172342172478
{
172343172479
yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
172344172480
}
172345172481
break;
172346
- case 320: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
172482
+ case 319: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
172347172483
{
172348172484
yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516);
172349172485
}
172350172486
yymsp[-2].minor.yy41 = yylhsminor.yy41;
172351172487
break;
172352
- case 321: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
172488
+ case 320: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
172353172489
{
172354172490
yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516);
172355172491
}
172356172492
yymsp[-5].minor.yy41 = yylhsminor.yy41;
172357172493
break;
172358
- case 323: /* frame_bound_s ::= frame_bound */
172359
- case 325: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==325);
172494
+ case 322: /* frame_bound_s ::= frame_bound */
172495
+ case 324: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==324);
172360172496
{yylhsminor.yy595 = yymsp[0].minor.yy595;}
172361172497
yymsp[0].minor.yy595 = yylhsminor.yy595;
172362172498
break;
172363
- case 324: /* frame_bound_s ::= UNBOUNDED PRECEDING */
172364
- case 326: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==326);
172365
- case 328: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==328);
172499
+ case 323: /* frame_bound_s ::= UNBOUNDED PRECEDING */
172500
+ case 325: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==325);
172501
+ case 327: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==327);
172366172502
{yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;}
172367172503
yymsp[-1].minor.yy595 = yylhsminor.yy595;
172368172504
break;
172369
- case 327: /* frame_bound ::= expr PRECEDING|FOLLOWING */
172505
+ case 326: /* frame_bound ::= expr PRECEDING|FOLLOWING */
172370172506
{yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;}
172371172507
yymsp[-1].minor.yy595 = yylhsminor.yy595;
172372172508
break;
172373
- case 329: /* frame_exclude_opt ::= */
172509
+ case 328: /* frame_exclude_opt ::= */
172374172510
{yymsp[1].minor.yy516 = 0;}
172375172511
break;
172376
- case 330: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
172512
+ case 329: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
172377172513
{yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;}
172378172514
break;
172379
- case 331: /* frame_exclude ::= NO OTHERS */
172380
- case 332: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==332);
172515
+ case 330: /* frame_exclude ::= NO OTHERS */
172516
+ case 331: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==331);
172381172517
{yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/}
172382172518
break;
172383
- case 333: /* frame_exclude ::= GROUP|TIES */
172519
+ case 332: /* frame_exclude ::= GROUP|TIES */
172384172520
{yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/}
172385172521
break;
172386
- case 334: /* window_clause ::= WINDOW windowdefn_list */
172522
+ case 333: /* window_clause ::= WINDOW windowdefn_list */
172387172523
{ yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; }
172388172524
break;
172389
- case 335: /* filter_over ::= filter_clause over_clause */
172525
+ case 334: /* filter_over ::= filter_clause over_clause */
172390172526
{
172391172527
if( yymsp[0].minor.yy41 ){
172392172528
yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528;
172393172529
}else{
172394172530
sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
@@ -172395,11 +172531,11 @@
172395172531
}
172396172532
yylhsminor.yy41 = yymsp[0].minor.yy41;
172397172533
}
172398172534
yymsp[-1].minor.yy41 = yylhsminor.yy41;
172399172535
break;
172400
- case 337: /* filter_over ::= filter_clause */
172536
+ case 336: /* filter_over ::= filter_clause */
172401172537
{
172402172538
yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
172403172539
if( yylhsminor.yy41 ){
172404172540
yylhsminor.yy41->eFrmType = TK_FILTER;
172405172541
yylhsminor.yy41->pFilter = yymsp[0].minor.yy528;
@@ -172407,68 +172543,69 @@
172407172543
sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy528);
172408172544
}
172409172545
}
172410172546
yymsp[0].minor.yy41 = yylhsminor.yy41;
172411172547
break;
172412
- case 338: /* over_clause ::= OVER LP window RP */
172548
+ case 337: /* over_clause ::= OVER LP window RP */
172413172549
{
172414172550
yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41;
172415172551
assert( yymsp[-3].minor.yy41!=0 );
172416172552
}
172417172553
break;
172418
- case 339: /* over_clause ::= OVER nm */
172554
+ case 338: /* over_clause ::= OVER nm */
172419172555
{
172420172556
yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
172421172557
if( yymsp[-1].minor.yy41 ){
172422172558
yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
172423172559
}
172424172560
}
172425172561
break;
172426
- case 340: /* filter_clause ::= FILTER LP WHERE expr RP */
172562
+ case 339: /* filter_clause ::= FILTER LP WHERE expr RP */
172427172563
{ yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; }
172428172564
break;
172429172565
default:
172430
- /* (341) input ::= cmdlist */ yytestcase(yyruleno==341);
172431
- /* (342) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==342);
172432
- /* (343) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=343);
172433
- /* (344) ecmd ::= SEMI */ yytestcase(yyruleno==344);
172434
- /* (345) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==345);
172435
- /* (346) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=346);
172436
- /* (347) trans_opt ::= */ yytestcase(yyruleno==347);
172437
- /* (348) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==348);
172438
- /* (349) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==349);
172439
- /* (350) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==350);
172440
- /* (351) savepoint_opt ::= */ yytestcase(yyruleno==351);
172441
- /* (352) cmd ::= create_table create_table_args */ yytestcase(yyruleno==352);
172442
- /* (353) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=353);
172443
- /* (354) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==354);
172444
- /* (355) columnlist ::= columnname carglist */ yytestcase(yyruleno==355);
172445
- /* (356) nm ::= ID|INDEXED|JOIN_KW */ yytestcase(yyruleno==356);
172446
- /* (357) nm ::= STRING */ yytestcase(yyruleno==357);
172447
- /* (358) typetoken ::= typename */ yytestcase(yyruleno==358);
172448
- /* (359) typename ::= ID|STRING */ yytestcase(yyruleno==359);
172449
- /* (360) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=360);
172450
- /* (361) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=361);
172451
- /* (362) carglist ::= carglist ccons */ yytestcase(yyruleno==362);
172452
- /* (363) carglist ::= */ yytestcase(yyruleno==363);
172453
- /* (364) ccons ::= NULL onconf */ yytestcase(yyruleno==364);
172454
- /* (365) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==365);
172455
- /* (366) ccons ::= AS generated */ yytestcase(yyruleno==366);
172456
- /* (367) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==367);
172457
- /* (368) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==368);
172458
- /* (369) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=369);
172459
- /* (370) tconscomma ::= */ yytestcase(yyruleno==370);
172460
- /* (371) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=371);
172461
- /* (372) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=372);
172462
- /* (373) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=373);
172463
- /* (374) oneselect ::= values */ yytestcase(yyruleno==374);
172464
- /* (375) sclp ::= selcollist COMMA */ yytestcase(yyruleno==375);
172465
- /* (376) as ::= ID|STRING */ yytestcase(yyruleno==376);
172466
- /* (377) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=377);
172467
- /* (378) returning ::= */ yytestcase(yyruleno==378);
172468
- /* (379) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=379);
172469
- /* (380) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==380);
172566
+ /* (340) input ::= cmdlist */ yytestcase(yyruleno==340);
172567
+ /* (341) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==341);
172568
+ /* (342) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=342);
172569
+ /* (343) ecmd ::= SEMI */ yytestcase(yyruleno==343);
172570
+ /* (344) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==344);
172571
+ /* (345) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=345);
172572
+ /* (346) trans_opt ::= */ yytestcase(yyruleno==346);
172573
+ /* (347) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==347);
172574
+ /* (348) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==348);
172575
+ /* (349) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==349);
172576
+ /* (350) savepoint_opt ::= */ yytestcase(yyruleno==350);
172577
+ /* (351) cmd ::= create_table create_table_args */ yytestcase(yyruleno==351);
172578
+ /* (352) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=352);
172579
+ /* (353) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==353);
172580
+ /* (354) columnlist ::= columnname carglist */ yytestcase(yyruleno==354);
172581
+ /* (355) nm ::= ID|INDEXED|JOIN_KW */ yytestcase(yyruleno==355);
172582
+ /* (356) nm ::= STRING */ yytestcase(yyruleno==356);
172583
+ /* (357) typetoken ::= typename */ yytestcase(yyruleno==357);
172584
+ /* (358) typename ::= ID|STRING */ yytestcase(yyruleno==358);
172585
+ /* (359) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=359);
172586
+ /* (360) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=360);
172587
+ /* (361) carglist ::= carglist ccons */ yytestcase(yyruleno==361);
172588
+ /* (362) carglist ::= */ yytestcase(yyruleno==362);
172589
+ /* (363) ccons ::= NULL onconf */ yytestcase(yyruleno==363);
172590
+ /* (364) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==364);
172591
+ /* (365) ccons ::= AS generated */ yytestcase(yyruleno==365);
172592
+ /* (366) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==366);
172593
+ /* (367) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==367);
172594
+ /* (368) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=368);
172595
+ /* (369) tconscomma ::= */ yytestcase(yyruleno==369);
172596
+ /* (370) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=370);
172597
+ /* (371) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=371);
172598
+ /* (372) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=372);
172599
+ /* (373) oneselect ::= values */ yytestcase(yyruleno==373);
172600
+ /* (374) sclp ::= selcollist COMMA */ yytestcase(yyruleno==374);
172601
+ /* (375) as ::= ID|STRING */ yytestcase(yyruleno==375);
172602
+ /* (376) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=376);
172603
+ /* (377) returning ::= */ yytestcase(yyruleno==377);
172604
+ /* (378) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=378);
172605
+ /* (379) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==379);
172606
+ /* (380) case_operand ::= expr */ yytestcase(yyruleno==380);
172470172607
/* (381) exprlist ::= nexprlist */ yytestcase(yyruleno==381);
172471172608
/* (382) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=382);
172472172609
/* (383) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=383);
172473172610
/* (384) nmnum ::= ON */ yytestcase(yyruleno==384);
172474172611
/* (385) nmnum ::= DELETE */ yytestcase(yyruleno==385);
@@ -199500,10 +199637,11 @@
199500199637
#define JNODE_REMOVE 0x04 /* Do not output */
199501199638
#define JNODE_REPLACE 0x08 /* Replace with JsonNode.u.iReplace */
199502199639
#define JNODE_PATCH 0x10 /* Patch with JsonNode.u.pPatch */
199503199640
#define JNODE_APPEND 0x20 /* More ARRAY/OBJECT entries at u.iAppend */
199504199641
#define JNODE_LABEL 0x40 /* Is a label of an object */
199642
+#define JNODE_JSON5 0x80 /* Node contains JSON5 enhancements */
199505199643
199506199644
199507199645
/* A single node of parsed JSON
199508199646
*/
199509199647
struct JsonNode {
@@ -199526,14 +199664,16 @@
199526199664
u32 nNode; /* Number of slots of aNode[] used */
199527199665
u32 nAlloc; /* Number of slots of aNode[] allocated */
199528199666
JsonNode *aNode; /* Array of nodes containing the parse */
199529199667
const char *zJson; /* Original JSON string */
199530199668
u32 *aUp; /* Index of parent of each node */
199531
- u8 oom; /* Set to true if out of memory */
199669
+ u16 iDepth; /* Nesting depth */
199532199670
u8 nErr; /* Number of errors seen */
199533
- u16 iDepth; /* Nesting depth */
199671
+ u8 oom; /* Set to true if out of memory */
199672
+ u8 hasNonstd; /* True if input uses non-standard features like JSON5 */
199534199673
int nJson; /* Length of the zJson string in bytes */
199674
+ u32 iErr; /* Error location in zJson[] */
199535199675
u32 iHold; /* Replace cache line with the lowest iHold value */
199536199676
};
199537199677
199538199678
/*
199539199679
** Maximum nesting depth of JSON for this implementation.
@@ -199689,10 +199829,133 @@
199689199829
p->zBuf[p->nUsed++] = c;
199690199830
}
199691199831
p->zBuf[p->nUsed++] = '"';
199692199832
assert( p->nUsed<p->nAlloc );
199693199833
}
199834
+
199835
+/*
199836
+** The zIn[0..N] string is a JSON5 string literal. Append to p a translation
199837
+** of the string literal that standard JSON and that omits all JSON5
199838
+** features.
199839
+*/
199840
+static void jsonAppendNormalizedString(JsonString *p, const char *zIn, u32 N){
199841
+ u32 i;
199842
+ jsonAppendChar(p, '"');
199843
+ zIn++;
199844
+ N -= 2;
199845
+ while( N>0 ){
199846
+ for(i=0; i<N && zIn[i]!='\\'; i++){}
199847
+ if( i>0 ){
199848
+ jsonAppendRaw(p, zIn, i);
199849
+ zIn += i;
199850
+ N -= i;
199851
+ if( N==0 ) break;
199852
+ }
199853
+ assert( zIn[0]=='\\' );
199854
+ switch( (u8)zIn[1] ){
199855
+ case '\'':
199856
+ jsonAppendChar(p, '\'');
199857
+ break;
199858
+ case 'v':
199859
+ jsonAppendRaw(p, "\\u0009", 6);
199860
+ break;
199861
+ case 'x':
199862
+ jsonAppendRaw(p, "\\u00", 4);
199863
+ jsonAppendRaw(p, &zIn[2], 2);
199864
+ zIn += 2;
199865
+ N -= 2;
199866
+ break;
199867
+ case '0':
199868
+ jsonAppendRaw(p, "\\u0000", 6);
199869
+ break;
199870
+ case '\r':
199871
+ if( zIn[2]=='\n' ){
199872
+ zIn++;
199873
+ N--;
199874
+ }
199875
+ break;
199876
+ case '\n':
199877
+ break;
199878
+ case 0xe2:
199879
+ assert( N>=4 );
199880
+ assert( 0x80==(u8)zIn[2] );
199881
+ assert( 0xa8==(u8)zIn[3] || 0xa9==(u8)zIn[3] );
199882
+ zIn += 2;
199883
+ N -= 2;
199884
+ break;
199885
+ default:
199886
+ jsonAppendRaw(p, zIn, 2);
199887
+ break;
199888
+ }
199889
+ zIn += 2;
199890
+ N -= 2;
199891
+ }
199892
+ jsonAppendChar(p, '"');
199893
+}
199894
+
199895
+/*
199896
+** The zIn[0..N] string is a JSON5 integer literal. Append to p a translation
199897
+** of the string literal that standard JSON and that omits all JSON5
199898
+** features.
199899
+*/
199900
+static void jsonAppendNormalizedInt(JsonString *p, const char *zIn, u32 N){
199901
+ if( zIn[0]=='+' ){
199902
+ zIn++;
199903
+ N--;
199904
+ }else if( zIn[0]=='-' ){
199905
+ jsonAppendChar(p, '-');
199906
+ zIn++;
199907
+ N--;
199908
+ }
199909
+ if( zIn[0]=='0' && (zIn[1]=='x' || zIn[1]=='X') ){
199910
+ sqlite3_int64 i = 0;
199911
+ int rc = sqlite3DecOrHexToI64(zIn, &i);
199912
+ if( rc<=1 ){
199913
+ jsonPrintf(100,p,"%lld",i);
199914
+ }else{
199915
+ assert( rc==2 );
199916
+ jsonAppendRaw(p, "9.0e999", 7);
199917
+ }
199918
+ return;
199919
+ }
199920
+ jsonAppendRaw(p, zIn, N);
199921
+}
199922
+
199923
+/*
199924
+** The zIn[0..N] string is a JSON5 real literal. Append to p a translation
199925
+** of the string literal that standard JSON and that omits all JSON5
199926
+** features.
199927
+*/
199928
+static void jsonAppendNormalizedReal(JsonString *p, const char *zIn, u32 N){
199929
+ u32 i;
199930
+ if( zIn[0]=='+' ){
199931
+ zIn++;
199932
+ N--;
199933
+ }else if( zIn[0]=='-' ){
199934
+ jsonAppendChar(p, '-');
199935
+ zIn++;
199936
+ N--;
199937
+ }
199938
+ if( zIn[0]=='.' ){
199939
+ jsonAppendChar(p, '0');
199940
+ }
199941
+ for(i=0; i<N; i++){
199942
+ if( zIn[i]=='.' && (i+1==N || !sqlite3Isdigit(zIn[i+1])) ){
199943
+ i++;
199944
+ jsonAppendRaw(p, zIn, i);
199945
+ zIn += i;
199946
+ N -= i;
199947
+ jsonAppendChar(p, '0');
199948
+ break;
199949
+ }
199950
+ }
199951
+ if( N>0 ){
199952
+ jsonAppendRaw(p, zIn, N);
199953
+ }
199954
+}
199955
+
199956
+
199694199957
199695199958
/*
199696199959
** Append a function parameter value to the JSON string under
199697199960
** construction.
199698199961
*/
@@ -199820,21 +200083,42 @@
199820200083
case JSON_FALSE: {
199821200084
jsonAppendRaw(pOut, "false", 5);
199822200085
break;
199823200086
}
199824200087
case JSON_STRING: {
200088
+ assert( pNode->eU==1 );
199825200089
if( pNode->jnFlags & JNODE_RAW ){
199826
- assert( pNode->eU==1 );
199827
- jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
199828
- break;
200090
+ if( pNode->jnFlags & JNODE_LABEL ){
200091
+ jsonAppendChar(pOut, '"');
200092
+ jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
200093
+ jsonAppendChar(pOut, '"');
200094
+ }else{
200095
+ jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
200096
+ }
200097
+ }else if( pNode->jnFlags & JNODE_JSON5 ){
200098
+ jsonAppendNormalizedString(pOut, pNode->u.zJContent, pNode->n);
200099
+ }else{
200100
+ jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
199829200101
}
199830
- /* no break */ deliberate_fall_through
200102
+ break;
199831200103
}
199832
- case JSON_REAL:
200104
+ case JSON_REAL: {
200105
+ assert( pNode->eU==1 );
200106
+ if( pNode->jnFlags & JNODE_JSON5 ){
200107
+ jsonAppendNormalizedReal(pOut, pNode->u.zJContent, pNode->n);
200108
+ }else{
200109
+ jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
200110
+ }
200111
+ break;
200112
+ }
199833200113
case JSON_INT: {
199834200114
assert( pNode->eU==1 );
199835
- jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
200115
+ if( pNode->jnFlags & JNODE_JSON5 ){
200116
+ jsonAppendNormalizedInt(pOut, pNode->u.zJContent, pNode->n);
200117
+ }else{
200118
+ jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
200119
+ }
199836200120
break;
199837200121
}
199838200122
case JSON_ARRAY: {
199839200123
u32 j = 1;
199840200124
jsonAppendChar(pOut, '[');
@@ -199946,63 +200230,45 @@
199946200230
sqlite3_result_int(pCtx, 0);
199947200231
break;
199948200232
}
199949200233
case JSON_INT: {
199950200234
sqlite3_int64 i = 0;
200235
+ int rc;
200236
+ int bNeg = 0;
199951200237
const char *z;
200238
+
200239
+
199952200240
assert( pNode->eU==1 );
199953200241
z = pNode->u.zJContent;
199954
- if( z[0]=='-' ){ z++; }
199955
- while( z[0]>='0' && z[0]<='9' ){
199956
- unsigned v = *(z++) - '0';
199957
- if( i>=LARGEST_INT64/10 ){
199958
- if( i>LARGEST_INT64/10 ) goto int_as_real;
199959
- if( z[0]>='0' && z[0]<='9' ) goto int_as_real;
199960
- if( v==9 ) goto int_as_real;
199961
- if( v==8 ){
199962
- if( pNode->u.zJContent[0]=='-' ){
199963
- sqlite3_result_int64(pCtx, SMALLEST_INT64);
199964
- goto int_done;
199965
- }else{
199966
- goto int_as_real;
199967
- }
199968
- }
199969
- }
199970
- i = i*10 + v;
199971
- }
199972
- if( pNode->u.zJContent[0]=='-' ){ i = -i; }
199973
- sqlite3_result_int64(pCtx, i);
199974
- int_done:
199975
- break;
199976
- int_as_real: ; /* no break */ deliberate_fall_through
200242
+ if( z[0]=='-' ){ z++; bNeg = 1; }
200243
+ else if( z[0]=='+' ){ z++; }
200244
+ rc = sqlite3DecOrHexToI64(z, &i);
200245
+ if( rc<=1 ){
200246
+ sqlite3_result_int64(pCtx, bNeg ? -i : i);
200247
+ }else if( rc==3 && bNeg ){
200248
+ sqlite3_result_int64(pCtx, SMALLEST_INT64);
200249
+ }else{
200250
+ goto to_double;
200251
+ }
200252
+ break;
199977200253
}
199978200254
case JSON_REAL: {
199979200255
double r;
199980
-#ifdef SQLITE_AMALGAMATION
199981200256
const char *z;
199982200257
assert( pNode->eU==1 );
200258
+ to_double:
199983200259
z = pNode->u.zJContent;
199984200260
sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
199985
-#else
199986
- assert( pNode->eU==1 );
199987
- r = strtod(pNode->u.zJContent, 0);
199988
-#endif
199989200261
sqlite3_result_double(pCtx, r);
199990200262
break;
199991200263
}
199992200264
case JSON_STRING: {
199993
-#if 0 /* Never happens because JNODE_RAW is only set by json_set(),
199994
- ** json_insert() and json_replace() and those routines do not
199995
- ** call jsonReturn() */
199996200265
if( pNode->jnFlags & JNODE_RAW ){
199997200266
assert( pNode->eU==1 );
199998200267
sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
199999200268
SQLITE_TRANSIENT);
200000
- }else
200001
-#endif
200002
- assert( (pNode->jnFlags & JNODE_RAW)==0 );
200003
- if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
200269
+ }else if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
200004200270
/* JSON formatted without any backslash-escapes */
200005200271
assert( pNode->eU==1 );
200006200272
sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
200007200273
SQLITE_TRANSIENT);
200008200274
}else{
@@ -200010,22 +200276,21 @@
200010200276
u32 i;
200011200277
u32 n = pNode->n;
200012200278
const char *z;
200013200279
char *zOut;
200014200280
u32 j;
200281
+ u32 nOut = n;
200015200282
assert( pNode->eU==1 );
200016200283
z = pNode->u.zJContent;
200017
- zOut = sqlite3_malloc( n+1 );
200284
+ zOut = sqlite3_malloc( nOut+1 );
200018200285
if( zOut==0 ){
200019200286
sqlite3_result_error_nomem(pCtx);
200020200287
break;
200021200288
}
200022200289
for(i=1, j=0; i<n-1; i++){
200023200290
char c = z[i];
200024
- if( c!='\\' ){
200025
- zOut[j++] = c;
200026
- }else{
200291
+ if( c=='\\' ){
200027200292
c = z[++i];
200028200293
if( c=='u' ){
200029200294
u32 v = jsonHexToInt4(z+i+1);
200030200295
i += 4;
200031200296
if( v==0 ) break;
@@ -200053,26 +200318,44 @@
200053200318
zOut[j++] = 0xe0 | (v>>12);
200054200319
zOut[j++] = 0x80 | ((v>>6)&0x3f);
200055200320
zOut[j++] = 0x80 | (v&0x3f);
200056200321
}
200057200322
}
200323
+ continue;
200324
+ }else if( c=='b' ){
200325
+ c = '\b';
200326
+ }else if( c=='f' ){
200327
+ c = '\f';
200328
+ }else if( c=='n' ){
200329
+ c = '\n';
200330
+ }else if( c=='r' ){
200331
+ c = '\r';
200332
+ }else if( c=='t' ){
200333
+ c = '\t';
200334
+ }else if( c=='v' ){
200335
+ c = '\v';
200336
+ }else if( c=='\'' || c=='"' || c=='/' || c=='\\' ){
200337
+ /* pass through unchanged */
200338
+ }else if( c=='0' ){
200339
+ c = 0;
200340
+ }else if( c=='x' ){
200341
+ c = (jsonHexToInt(z[i+1])<<4) | jsonHexToInt(z[i+2]);
200342
+ i += 2;
200343
+ }else if( c=='\r' && z[i+1]=='\n' ){
200344
+ i++;
200345
+ continue;
200346
+ }else if( 0xe2==(u8)c ){
200347
+ assert( 0x80==(u8)z[i+1] );
200348
+ assert( 0xa8==(u8)z[i+2] || 0xa9==(u8)z[i+2] );
200349
+ i += 2;
200350
+ continue;
200058200351
}else{
200059
- if( c=='b' ){
200060
- c = '\b';
200061
- }else if( c=='f' ){
200062
- c = '\f';
200063
- }else if( c=='n' ){
200064
- c = '\n';
200065
- }else if( c=='r' ){
200066
- c = '\r';
200067
- }else if( c=='t' ){
200068
- c = '\t';
200069
- }
200070
- zOut[j++] = c;
200071
- }
200072
- }
200073
- }
200352
+ continue;
200353
+ }
200354
+ } /* end if( c=='\\' ) */
200355
+ zOut[j++] = c;
200356
+ } /* end for() */
200074200357
zOut[j] = 0;
200075200358
sqlite3_result_text(pCtx, zOut, j, sqlite3_free);
200076200359
}
200077200360
break;
200078200361
}
@@ -200136,28 +200419,159 @@
200136200419
JsonNode *p;
200137200420
if( pParse->aNode==0 || pParse->nNode>=pParse->nAlloc ){
200138200421
return jsonParseAddNodeExpand(pParse, eType, n, zContent);
200139200422
}
200140200423
p = &pParse->aNode[pParse->nNode];
200141
- p->eType = (u8)eType;
200142
- p->jnFlags = 0;
200424
+ p->eType = (u8)(eType & 0xff);
200425
+ p->jnFlags = (u8)(eType >> 8);
200143200426
VVA( p->eU = zContent ? 1 : 0 );
200144200427
p->n = n;
200145200428
p->u.zJContent = zContent;
200146200429
return pParse->nNode++;
200147200430
}
200431
+
200432
+/*
200433
+** Return true if z[] begins with 2 (or more) hexadecimal digits
200434
+*/
200435
+static int jsonIs2Hex(const char *z){
200436
+ return sqlite3Isxdigit(z[0]) && sqlite3Isxdigit(z[1]);
200437
+}
200148200438
200149200439
/*
200150200440
** Return true if z[] begins with 4 (or more) hexadecimal digits
200151200441
*/
200152200442
static int jsonIs4Hex(const char *z){
200153
- int i;
200154
- for(i=0; i<4; i++) if( !sqlite3Isxdigit(z[i]) ) return 0;
200155
- return 1;
200443
+ return jsonIs2Hex(z) && jsonIs2Hex(&z[2]);
200156200444
}
200157200445
200158
-#ifdef SQLITE_ENABLE_JSON_NAN_INF
200446
+/*
200447
+** Return the number of bytes of JSON5 whitespace at the beginning of
200448
+** the input string z[].
200449
+**
200450
+** JSON5 whitespace consists of any of the following characters:
200451
+**
200452
+** Unicode UTF-8 Name
200453
+** U+0009 09 horizontal tab
200454
+** U+000a 0a line feed
200455
+** U+000b 0b vertical tab
200456
+** U+000c 0c form feed
200457
+** U+000d 0d carriage return
200458
+** U+0020 20 space
200459
+** U+00a0 c2 a0 non-breaking space
200460
+** U+1680 e1 9a 80 ogham space mark
200461
+** U+2000 e2 80 80 en quad
200462
+** U+2001 e2 80 81 em quad
200463
+** U+2002 e2 80 82 en space
200464
+** U+2003 e2 80 83 em space
200465
+** U+2004 e2 80 84 three-per-em space
200466
+** U+2005 e2 80 85 four-per-em space
200467
+** U+2006 e2 80 86 six-per-em space
200468
+** U+2007 e2 80 87 figure space
200469
+** U+2008 e2 80 88 punctuation space
200470
+** U+2009 e2 80 89 thin space
200471
+** U+200a e2 80 8a hair space
200472
+** U+2028 e2 80 a8 line separator
200473
+** U+2029 e2 80 a9 paragraph separator
200474
+** U+202f e2 80 af narrow no-break space (NNBSP)
200475
+** U+205f e2 81 9f medium mathematical space (MMSP)
200476
+** U+3000 e3 80 80 ideographical space
200477
+** U+FEFF ef bb bf byte order mark
200478
+**
200479
+** In addition, comments between '/', '*' and '*', '/' and
200480
+** from '/', '/' to end-of-line are also considered to be whitespace.
200481
+*/
200482
+static int json5Whitespace(const char *zIn){
200483
+ int n = 0;
200484
+ const u8 *z = (u8*)zIn;
200485
+ while( 1 /*exit by "goto whitespace_done"*/ ){
200486
+ switch( z[n] ){
200487
+ case 0x09:
200488
+ case 0x0a:
200489
+ case 0x0b:
200490
+ case 0x0c:
200491
+ case 0x0d:
200492
+ case 0x20: {
200493
+ n++;
200494
+ break;
200495
+ }
200496
+ case '/': {
200497
+ if( z[n+1]=='*' && z[n+2]!=0 ){
200498
+ int j;
200499
+ for(j=n+3; z[j]!='/' || z[j-1]!='*'; j++){
200500
+ if( z[j]==0 ) goto whitespace_done;
200501
+ }
200502
+ n = j+1;
200503
+ break;
200504
+ }else if( z[n+1]=='/' ){
200505
+ int j;
200506
+ char c;
200507
+ for(j=n+2; (c = z[j])!=0; j++){
200508
+ if( c=='\n' || c=='\r' ) break;
200509
+ if( 0xe2==(u8)c && 0x80==(u8)z[j+1]
200510
+ && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2])
200511
+ ){
200512
+ j += 2;
200513
+ break;
200514
+ }
200515
+ }
200516
+ n = j;
200517
+ if( z[n] ) n++;
200518
+ break;
200519
+ }
200520
+ goto whitespace_done;
200521
+ }
200522
+ case 0xc2: {
200523
+ if( z[n+1]==0xa0 ){
200524
+ n += 2;
200525
+ break;
200526
+ }
200527
+ goto whitespace_done;
200528
+ }
200529
+ case 0xe1: {
200530
+ if( z[n+1]==0x9a && z[n+2]==0x80 ){
200531
+ n += 3;
200532
+ break;
200533
+ }
200534
+ goto whitespace_done;
200535
+ }
200536
+ case 0xe2: {
200537
+ if( z[n+1]==0x80 ){
200538
+ u8 c = z[n+2];
200539
+ if( c<0x80 ) goto whitespace_done;
200540
+ if( c<=0x8a || c==0xa8 || c==0xa9 || c==0xaf ){
200541
+ n += 3;
200542
+ break;
200543
+ }
200544
+ }else if( z[n+1]==0x81 && z[n+2]==0x9f ){
200545
+ n += 3;
200546
+ break;
200547
+ }
200548
+ goto whitespace_done;
200549
+ }
200550
+ case 0xe3: {
200551
+ if( z[n+1]==0x80 && z[n+2]==0x80 ){
200552
+ n += 3;
200553
+ break;
200554
+ }
200555
+ goto whitespace_done;
200556
+ }
200557
+ case 0xef: {
200558
+ if( z[n+1]==0xbb && z[n+2]==0xbf ){
200559
+ n += 3;
200560
+ break;
200561
+ }
200562
+ goto whitespace_done;
200563
+ }
200564
+ default: {
200565
+ goto whitespace_done;
200566
+ }
200567
+ }
200568
+ }
200569
+ whitespace_done:
200570
+ return n;
200571
+}
200572
+
200159200573
/*
200160200574
** Extra floating-point literals to allow in JSON.
200161200575
*/
200162200576
static const struct NanInfName {
200163200577
char c1;
@@ -200172,204 +200586,456 @@
200172200586
{ 'i', 'I', 8, JSON_REAL, 7, "infinity", "9.0e999" },
200173200587
{ 'n', 'N', 3, JSON_NULL, 4, "NaN", "null" },
200174200588
{ 'q', 'Q', 4, JSON_NULL, 4, "QNaN", "null" },
200175200589
{ 's', 'S', 4, JSON_NULL, 4, "SNaN", "null" },
200176200590
};
200177
-#endif /* SQLITE_ENABLE_JSON_NAN_INF */
200178200591
200179200592
/*
200180200593
** Parse a single JSON value which begins at pParse->zJson[i]. Return the
200181200594
** index of the first character past the end of the value parsed.
200182200595
**
200183
-** Return negative for a syntax error. Special cases: return -2 if the
200184
-** first non-whitespace character is '}' and return -3 if the first
200185
-** non-whitespace character is ']'.
200596
+** Special return values:
200597
+**
200598
+** 0 End if input
200599
+** -1 Syntax error
200600
+** -2 '}' seen
200601
+** -3 ']' seen
200602
+** -4 ',' seen
200603
+** -5 ':' seen
200186200604
*/
200187200605
static int jsonParseValue(JsonParse *pParse, u32 i){
200188200606
char c;
200189200607
u32 j;
200190200608
int iThis;
200191200609
int x;
200192200610
JsonNode *pNode;
200193200611
const char *z = pParse->zJson;
200194
- while( fast_isspace(z[i]) ){ i++; }
200195
- if( (c = z[i])=='{' ){
200612
+json_parse_restart:
200613
+ switch( (u8)z[i] ){
200614
+ case '{': {
200196200615
/* Parse object */
200197200616
iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
200198200617
if( iThis<0 ) return -1;
200199200618
for(j=i+1;;j++){
200200
- while( fast_isspace(z[j]) ){ j++; }
200201
- if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
200619
+ if( ++pParse->iDepth > JSON_MAX_DEPTH ){
200620
+ pParse->iErr = j;
200621
+ return -1;
200622
+ }
200202200623
x = jsonParseValue(pParse, j);
200203
- if( x<0 ){
200204
- pParse->iDepth--;
200205
- if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
200206
- return -1;
200624
+ if( x<=0 ){
200625
+ if( x==(-2) ){
200626
+ j = pParse->iErr;
200627
+ if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
200628
+ pParse->iDepth--;
200629
+ break;
200630
+ }
200631
+ j += json5Whitespace(&z[j]);
200632
+ if( sqlite3JsonId1(z[j])
200633
+ || (z[j]=='\\' && z[j+1]=='u' && jsonIs4Hex(&z[j+2]))
200634
+ ){
200635
+ int k = j+1;
200636
+ while( (sqlite3JsonId2(z[k]) && json5Whitespace(&z[k])==0)
200637
+ || (z[k]=='\\' && z[k+1]=='u' && jsonIs4Hex(&z[k+2]))
200638
+ ){
200639
+ k++;
200640
+ }
200641
+ jsonParseAddNode(pParse, JSON_STRING | (JNODE_RAW<<8), k-j, &z[j]);
200642
+ pParse->hasNonstd = 1;
200643
+ x = k;
200644
+ }else{
200645
+ if( x!=-1 ) pParse->iErr = j;
200646
+ return -1;
200647
+ }
200207200648
}
200208200649
if( pParse->oom ) return -1;
200209200650
pNode = &pParse->aNode[pParse->nNode-1];
200210
- if( pNode->eType!=JSON_STRING ) return -1;
200651
+ if( pNode->eType!=JSON_STRING ){
200652
+ pParse->iErr = j;
200653
+ return -1;
200654
+ }
200211200655
pNode->jnFlags |= JNODE_LABEL;
200212200656
j = x;
200213
- while( fast_isspace(z[j]) ){ j++; }
200214
- if( z[j]!=':' ) return -1;
200215
- j++;
200657
+ if( z[j]==':' ){
200658
+ j++;
200659
+ }else{
200660
+ if( fast_isspace(z[j]) ){
200661
+ do{ j++; }while( fast_isspace(z[j]) );
200662
+ if( z[j]==':' ){
200663
+ j++;
200664
+ goto parse_object_value;
200665
+ }
200666
+ }
200667
+ x = jsonParseValue(pParse, j);
200668
+ if( x!=(-5) ){
200669
+ if( x!=(-1) ) pParse->iErr = j;
200670
+ return -1;
200671
+ }
200672
+ j = pParse->iErr+1;
200673
+ }
200674
+ parse_object_value:
200216200675
x = jsonParseValue(pParse, j);
200217200676
pParse->iDepth--;
200218
- if( x<0 ) return -1;
200677
+ if( x<=0 ){
200678
+ if( x!=(-1) ) pParse->iErr = j;
200679
+ return -1;
200680
+ }
200219200681
j = x;
200220
- while( fast_isspace(z[j]) ){ j++; }
200221
- c = z[j];
200222
- if( c==',' ) continue;
200223
- if( c!='}' ) return -1;
200224
- break;
200682
+ if( z[j]==',' ){
200683
+ continue;
200684
+ }else if( z[j]=='}' ){
200685
+ break;
200686
+ }else{
200687
+ if( fast_isspace(z[j]) ){
200688
+ do{ j++; }while( fast_isspace(z[j]) );
200689
+ if( z[j]==',' ){
200690
+ continue;
200691
+ }else if( z[j]=='}' ){
200692
+ break;
200693
+ }
200694
+ }
200695
+ x = jsonParseValue(pParse, j);
200696
+ if( x==(-4) ){
200697
+ j = pParse->iErr;
200698
+ continue;
200699
+ }
200700
+ if( x==(-2) ){
200701
+ j = pParse->iErr;
200702
+ break;
200703
+ }
200704
+ }
200705
+ pParse->iErr = j;
200706
+ return -1;
200225200707
}
200226200708
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
200227200709
return j+1;
200228
- }else if( c=='[' ){
200710
+ }
200711
+ case '[': {
200229200712
/* Parse array */
200230200713
iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
200231200714
if( iThis<0 ) return -1;
200232200715
memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
200233200716
for(j=i+1;;j++){
200234
- while( fast_isspace(z[j]) ){ j++; }
200235
- if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
200717
+ if( ++pParse->iDepth > JSON_MAX_DEPTH ){
200718
+ pParse->iErr = j;
200719
+ return -1;
200720
+ }
200236200721
x = jsonParseValue(pParse, j);
200237200722
pParse->iDepth--;
200238
- if( x<0 ){
200239
- if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
200723
+ if( x<=0 ){
200724
+ if( x==(-3) ){
200725
+ j = pParse->iErr;
200726
+ if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
200727
+ break;
200728
+ }
200729
+ if( x!=(-1) ) pParse->iErr = j;
200240200730
return -1;
200241200731
}
200242200732
j = x;
200243
- while( fast_isspace(z[j]) ){ j++; }
200244
- c = z[j];
200245
- if( c==',' ) continue;
200246
- if( c!=']' ) return -1;
200247
- break;
200733
+ if( z[j]==',' ){
200734
+ continue;
200735
+ }else if( z[j]==']' ){
200736
+ break;
200737
+ }else{
200738
+ if( fast_isspace(z[j]) ){
200739
+ do{ j++; }while( fast_isspace(z[j]) );
200740
+ if( z[j]==',' ){
200741
+ continue;
200742
+ }else if( z[j]==']' ){
200743
+ break;
200744
+ }
200745
+ }
200746
+ x = jsonParseValue(pParse, j);
200747
+ if( x==(-4) ){
200748
+ j = pParse->iErr;
200749
+ continue;
200750
+ }
200751
+ if( x==(-3) ){
200752
+ j = pParse->iErr;
200753
+ break;
200754
+ }
200755
+ }
200756
+ pParse->iErr = j;
200757
+ return -1;
200248200758
}
200249200759
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
200250200760
return j+1;
200251
- }else if( c=='"' ){
200761
+ }
200762
+ case '\'': {
200763
+ u8 jnFlags;
200764
+ char cDelim;
200765
+ pParse->hasNonstd = 1;
200766
+ jnFlags = JNODE_JSON5;
200767
+ goto parse_string;
200768
+ case '"':
200252200769
/* Parse string */
200253
- u8 jnFlags = 0;
200770
+ jnFlags = 0;
200771
+ parse_string:
200772
+ cDelim = z[i];
200254200773
j = i+1;
200255200774
for(;;){
200256200775
c = z[j];
200257200776
if( (c & ~0x1f)==0 ){
200258200777
/* Control characters are not allowed in strings */
200778
+ pParse->iErr = j;
200259200779
return -1;
200260200780
}
200261200781
if( c=='\\' ){
200262200782
c = z[++j];
200263200783
if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
200264200784
|| c=='n' || c=='r' || c=='t'
200265
- || (c=='u' && jsonIs4Hex(z+j+1)) ){
200266
- jnFlags = JNODE_ESCAPE;
200785
+ || (c=='u' && jsonIs4Hex(&z[j+1])) ){
200786
+ jnFlags |= JNODE_ESCAPE;
200787
+ }else if( c=='\'' || c=='0' || c=='v' || c=='\n'
200788
+ || (0xe2==(u8)c && 0x80==(u8)z[j+1]
200789
+ && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
200790
+ || (c=='x' && jsonIs2Hex(&z[j+1])) ){
200791
+ jnFlags |= (JNODE_ESCAPE|JNODE_JSON5);
200792
+ pParse->hasNonstd = 1;
200793
+ }else if( c=='\r' ){
200794
+ if( z[j+1]=='\n' ) j++;
200795
+ jnFlags |= (JNODE_ESCAPE|JNODE_JSON5);
200796
+ pParse->hasNonstd = 1;
200267200797
}else{
200798
+ pParse->iErr = j;
200268200799
return -1;
200269200800
}
200270
- }else if( c=='"' ){
200801
+ }else if( c==cDelim ){
200271200802
break;
200272200803
}
200273200804
j++;
200274200805
}
200275
- jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
200276
- if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
200806
+ jsonParseAddNode(pParse, JSON_STRING | (jnFlags<<8), j+1-i, &z[i]);
200277200807
return j+1;
200278
- }else if( c=='n'
200279
- && strncmp(z+i,"null",4)==0
200280
- && !sqlite3Isalnum(z[i+4]) ){
200281
- jsonParseAddNode(pParse, JSON_NULL, 0, 0);
200282
- return i+4;
200283
- }else if( c=='t'
200284
- && strncmp(z+i,"true",4)==0
200285
- && !sqlite3Isalnum(z[i+4]) ){
200286
- jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
200287
- return i+4;
200288
- }else if( c=='f'
200289
- && strncmp(z+i,"false",5)==0
200290
- && !sqlite3Isalnum(z[i+5]) ){
200291
- jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
200292
- return i+5;
200293
- }else if( c=='-' || (c>='0' && c<='9') ){
200808
+ }
200809
+ case 'n': {
200810
+ if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
200811
+ jsonParseAddNode(pParse, JSON_NULL, 0, 0);
200812
+ return i+4;
200813
+ }
200814
+ pParse->iErr = i;
200815
+ return -1;
200816
+ }
200817
+ case 't': {
200818
+ if( strncmp(z+i,"true",4)==0 && !sqlite3Isalnum(z[i+4]) ){
200819
+ jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
200820
+ return i+4;
200821
+ }
200822
+ pParse->iErr = i;
200823
+ return -1;
200824
+ }
200825
+ case 'f': {
200826
+ if( strncmp(z+i,"false",5)==0 && !sqlite3Isalnum(z[i+5]) ){
200827
+ jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
200828
+ return i+5;
200829
+ }
200830
+ pParse->iErr = i;
200831
+ return -1;
200832
+ }
200833
+ case '+': {
200834
+ u8 seenDP, seenE, jnFlags;
200835
+ pParse->hasNonstd = 1;
200836
+ jnFlags = JNODE_JSON5;
200837
+ goto parse_number;
200838
+ case '.':
200839
+ if( sqlite3Isdigit(z[i+1]) ){
200840
+ pParse->hasNonstd = 1;
200841
+ jnFlags = JNODE_JSON5;
200842
+ seenE = 0;
200843
+ seenDP = JSON_REAL;
200844
+ goto parse_number_2;
200845
+ }
200846
+ pParse->iErr = i;
200847
+ return -1;
200848
+ case '-':
200849
+ case '0':
200850
+ case '1':
200851
+ case '2':
200852
+ case '3':
200853
+ case '4':
200854
+ case '5':
200855
+ case '6':
200856
+ case '7':
200857
+ case '8':
200858
+ case '9':
200294200859
/* Parse number */
200295
- u8 seenDP = 0;
200296
- u8 seenE = 0;
200860
+ jnFlags = 0;
200861
+ parse_number:
200862
+ seenDP = JSON_INT;
200863
+ seenE = 0;
200297200864
assert( '-' < '0' );
200865
+ assert( '+' < '0' );
200866
+ assert( '.' < '0' );
200867
+ c = z[i];
200868
+
200298200869
if( c<='0' ){
200299
- j = c=='-' ? i+1 : i;
200300
- if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
200870
+ if( c=='0' ){
200871
+ if( (z[i+1]=='x' || z[i+1]=='X') && sqlite3Isxdigit(z[i+2]) ){
200872
+ assert( seenDP==JSON_INT );
200873
+ pParse->hasNonstd = 1;
200874
+ jnFlags |= JNODE_JSON5;
200875
+ for(j=i+3; sqlite3Isxdigit(z[j]); j++){}
200876
+ goto parse_number_finish;
200877
+ }else if( sqlite3Isdigit(z[i+1]) ){
200878
+ pParse->iErr = i+1;
200879
+ return -1;
200880
+ }
200881
+ }else{
200882
+ if( !sqlite3Isdigit(z[i+1]) ){
200883
+ /* JSON5 allows for "+Infinity" and "-Infinity" using exactly
200884
+ ** that case. SQLite also allows these in any case and it allows
200885
+ ** "+inf" and "-inf". */
200886
+ if( (z[i+1]=='I' || z[i+1]=='i')
200887
+ && sqlite3StrNICmp(&z[i+1], "inf",3)==0
200888
+ ){
200889
+ pParse->hasNonstd = 1;
200890
+ if( z[i]=='-' ){
200891
+ jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999");
200892
+ }else{
200893
+ jsonParseAddNode(pParse, JSON_REAL, 7, "9.0e999");
200894
+ }
200895
+ return i + (sqlite3StrNICmp(&z[i+4],"inity",5)==0 ? 9 : 4);
200896
+ }
200897
+ if( z[i+1]=='.' ){
200898
+ pParse->hasNonstd = 1;
200899
+ jnFlags |= JNODE_JSON5;
200900
+ goto parse_number_2;
200901
+ }
200902
+ pParse->iErr = i;
200903
+ return -1;
200904
+ }
200905
+ if( z[i+1]=='0' ){
200906
+ if( sqlite3Isdigit(z[i+2]) ){
200907
+ pParse->iErr = i+1;
200908
+ return -1;
200909
+ }else if( (z[i+2]=='x' || z[i+2]=='X') && sqlite3Isxdigit(z[i+3]) ){
200910
+ pParse->hasNonstd = 1;
200911
+ jnFlags |= JNODE_JSON5;
200912
+ for(j=i+4; sqlite3Isxdigit(z[j]); j++){}
200913
+ goto parse_number_finish;
200914
+ }
200915
+ }
200916
+ }
200301200917
}
200302
- j = i+1;
200303
- for(;; j++){
200918
+ parse_number_2:
200919
+ for(j=i+1;; j++){
200304200920
c = z[j];
200305
- if( c>='0' && c<='9' ) continue;
200921
+ if( sqlite3Isdigit(c) ) continue;
200306200922
if( c=='.' ){
200307
- if( z[j-1]=='-' ) return -1;
200308
- if( seenDP ) return -1;
200309
- seenDP = 1;
200923
+ if( seenDP==JSON_REAL ){
200924
+ pParse->iErr = j;
200925
+ return -1;
200926
+ }
200927
+ seenDP = JSON_REAL;
200310200928
continue;
200311200929
}
200312200930
if( c=='e' || c=='E' ){
200313
- if( z[j-1]<'0' ) return -1;
200314
- if( seenE ) return -1;
200315
- seenDP = seenE = 1;
200931
+ if( z[j-1]<'0' ){
200932
+ if( ALWAYS(z[j-1]=='.') && ALWAYS(j-2>=i) && sqlite3Isdigit(z[j-2]) ){
200933
+ pParse->hasNonstd = 1;
200934
+ jnFlags |= JNODE_JSON5;
200935
+ }else{
200936
+ pParse->iErr = j;
200937
+ return -1;
200938
+ }
200939
+ }
200940
+ if( seenE ){
200941
+ pParse->iErr = j;
200942
+ return -1;
200943
+ }
200944
+ seenDP = JSON_REAL;
200945
+ seenE = 1;
200316200946
c = z[j+1];
200317200947
if( c=='+' || c=='-' ){
200318200948
j++;
200319200949
c = z[j+1];
200320200950
}
200321
- if( c<'0' || c>'9' ) return -1;
200951
+ if( c<'0' || c>'9' ){
200952
+ pParse->iErr = j;
200953
+ return -1;
200954
+ }
200322200955
continue;
200323200956
}
200324
-#ifdef SQLITE_ENABLE_JSON_NAN_INF
200325
- /* Non-standard JSON: Allow "-Inf" (in any case)
200326
- ** to be understood as floating point literals. */
200327
- if( (c=='i' || c=='I')
200328
- && j==i+1
200329
- && z[i]=='-'
200330
- && sqlite3StrNICmp(&z[j], "inf",3)==0
200331
- ){
200332
- if( !sqlite3Isalnum(z[j+3]) ){
200333
- jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999");
200334
- return i+4;
200335
- }else if( (sqlite3StrNICmp(&z[j],"infinity",8)==0 &&
200336
- !sqlite3Isalnum(z[j+8])) ){
200337
- jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999");
200338
- return i+9;
200339
- }
200340
- }
200341
-#endif
200342200957
break;
200343200958
}
200344
- if( z[j-1]<'0' ) return -1;
200345
- jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
200346
- j - i, &z[i]);
200959
+ if( z[j-1]<'0' ){
200960
+ if( ALWAYS(z[j-1]=='.') && ALWAYS(j-2>=i) && sqlite3Isdigit(z[j-2]) ){
200961
+ pParse->hasNonstd = 1;
200962
+ jnFlags |= JNODE_JSON5;
200963
+ }else{
200964
+ pParse->iErr = j;
200965
+ return -1;
200966
+ }
200967
+ }
200968
+ parse_number_finish:
200969
+ jsonParseAddNode(pParse, seenDP | (jnFlags<<8), j - i, &z[i]);
200347200970
return j;
200348
- }else if( c=='}' ){
200971
+ }
200972
+ case '}': {
200973
+ pParse->iErr = i;
200349200974
return -2; /* End of {...} */
200350
- }else if( c==']' ){
200975
+ }
200976
+ case ']': {
200977
+ pParse->iErr = i;
200351200978
return -3; /* End of [...] */
200352
- }else if( c==0 ){
200979
+ }
200980
+ case ',': {
200981
+ pParse->iErr = i;
200982
+ return -4; /* List separator */
200983
+ }
200984
+ case ':': {
200985
+ pParse->iErr = i;
200986
+ return -5; /* Object label/value separator */
200987
+ }
200988
+ case 0: {
200353200989
return 0; /* End of file */
200354
- }else{
200355
-#ifdef SQLITE_ENABLE_JSON_NAN_INF
200356
- int k, nn;
200990
+ }
200991
+ case 0x09:
200992
+ case 0x0a:
200993
+ case 0x0d:
200994
+ case 0x20: {
200995
+ do{
200996
+ i++;
200997
+ }while( fast_isspace(z[i]) );
200998
+ goto json_parse_restart;
200999
+ }
201000
+ case 0x0b:
201001
+ case 0x0c:
201002
+ case '/':
201003
+ case 0xc2:
201004
+ case 0xe1:
201005
+ case 0xe2:
201006
+ case 0xe3:
201007
+ case 0xef: {
201008
+ j = json5Whitespace(&z[i]);
201009
+ if( j>0 ){
201010
+ i += j;
201011
+ pParse->hasNonstd = 1;
201012
+ goto json_parse_restart;
201013
+ }
201014
+ pParse->iErr = i;
201015
+ return -1;
201016
+ }
201017
+ default: {
201018
+ u32 k;
201019
+ int nn;
201020
+ c = z[i];
200357201021
for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
200358201022
if( c!=aNanInfName[k].c1 && c!=aNanInfName[k].c2 ) continue;
200359201023
nn = aNanInfName[k].n;
200360201024
if( sqlite3StrNICmp(&z[i], aNanInfName[k].zMatch, nn)!=0 ){
200361201025
continue;
200362201026
}
200363201027
if( sqlite3Isalnum(z[i+nn]) ) continue;
200364201028
jsonParseAddNode(pParse, aNanInfName[k].eType,
200365201029
aNanInfName[k].nRepl, aNanInfName[k].zRepl);
201030
+ pParse->hasNonstd = 1;
200366201031
return i + nn;
200367201032
}
200368
-#endif
201033
+ pParse->iErr = i;
200369201034
return -1; /* Syntax error */
200370201035
}
201036
+ } /* End switch(z[i]) */
200371201037
}
200372201038
200373201039
/*
200374201040
** Parse a complete JSON string. Return 0 on success or non-zero if there
200375201041
** are any errors. If an error occurs, free all memory associated with
@@ -200389,11 +201055,18 @@
200389201055
i = jsonParseValue(pParse, 0);
200390201056
if( pParse->oom ) i = -1;
200391201057
if( i>0 ){
200392201058
assert( pParse->iDepth==0 );
200393201059
while( fast_isspace(zJson[i]) ) i++;
200394
- if( zJson[i] ) i = -1;
201060
+ if( zJson[i] ){
201061
+ i += json5Whitespace(&zJson[i]);
201062
+ if( zJson[i] ){
201063
+ jsonParseReset(pParse);
201064
+ return 1;
201065
+ }
201066
+ pParse->hasNonstd = 1;
201067
+ }
200395201068
}
200396201069
if( i<=0 ){
200397201070
if( pCtx!=0 ){
200398201071
if( pParse->oom ){
200399201072
sqlite3_result_error_nomem(pCtx);
@@ -200460,10 +201133,19 @@
200460201133
** of the argv array. Use the sqlite3_get_auxdata() cache for this
200461201134
** parse if it is available. If the cache is not available or if it
200462201135
** is no longer valid, parse the JSON again and return the new parse,
200463201136
** and also register the new parse so that it will be available for
200464201137
** future sqlite3_get_auxdata() calls.
201138
+**
201139
+** If an error occurs and pErrCtx!=0 then report the error on pErrCtx
201140
+** and return NULL.
201141
+**
201142
+** If an error occurs and pErrCtx==0 then return the Parse object with
201143
+** JsonParse.nErr non-zero. If the caller invokes this routine with
201144
+** pErrCtx==0 and it gets back a JsonParse with nErr!=0, then the caller
201145
+** is responsible for invoking jsonParseFree() on the returned value.
201146
+** But the caller may invoke jsonParseFree() *only* if pParse->nErr!=0.
200465201147
*/
200466201148
static JsonParse *jsonParseCached(
200467201149
sqlite3_context *pCtx,
200468201150
sqlite3_value **argv,
200469201151
sqlite3_context *pErrCtx
@@ -200509,10 +201191,14 @@
200509201191
}
200510201192
memset(p, 0, sizeof(*p));
200511201193
p->zJson = (char*)&p[1];
200512201194
memcpy((char*)p->zJson, zJson, nJson+1);
200513201195
if( jsonParse(p, pErrCtx, p->zJson) ){
201196
+ if( pErrCtx==0 ){
201197
+ p->nErr = 1;
201198
+ return p;
201199
+ }
200514201200
sqlite3_free(p);
200515201201
return 0;
200516201202
}
200517201203
p->nJson = nJson;
200518201204
p->iHold = iMaxHold+1;
@@ -200523,19 +201209,28 @@
200523201209
200524201210
/*
200525201211
** Compare the OBJECT label at pNode against zKey,nKey. Return true on
200526201212
** a match.
200527201213
*/
200528
-static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
201214
+static int jsonLabelCompare(const JsonNode *pNode, const char *zKey, u32 nKey){
200529201215
assert( pNode->eU==1 );
200530201216
if( pNode->jnFlags & JNODE_RAW ){
200531201217
if( pNode->n!=nKey ) return 0;
200532201218
return strncmp(pNode->u.zJContent, zKey, nKey)==0;
200533201219
}else{
200534201220
if( pNode->n!=nKey+2 ) return 0;
200535201221
return strncmp(pNode->u.zJContent+1, zKey, nKey)==0;
200536201222
}
201223
+}
201224
+static int jsonSameLabel(const JsonNode *p1, const JsonNode *p2){
201225
+ if( p1->jnFlags & JNODE_RAW ){
201226
+ return jsonLabelCompare(p2, p1->u.zJContent, p1->n);
201227
+ }else if( p2->jnFlags & JNODE_RAW ){
201228
+ return jsonLabelCompare(p1, p2->u.zJContent, p2->n);
201229
+ }else{
201230
+ return p1->n==p2->n && strncmp(p1->u.zJContent,p2->u.zJContent,p1->n)==0;
201231
+ }
200537201232
}
200538201233
200539201234
/* forward declaration */
200540201235
static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**);
200541201236
@@ -201003,11 +201698,11 @@
201003201698
if( argc==2 ){
201004201699
/* With a single PATH argument */
201005201700
zPath = (const char*)sqlite3_value_text(argv[1]);
201006201701
if( zPath==0 ) return;
201007201702
if( flags & JSON_ABPATH ){
201008
- if( zPath[0]!='$' ){
201703
+ if( zPath[0]!='$' || (zPath[1]!='.' && zPath[1]!='[' && zPath[1]!=0) ){
201009201704
/* The -> and ->> operators accept abbreviated PATH arguments. This
201010201705
** is mostly for compatibility with PostgreSQL, but also for
201011201706
** convenience.
201012201707
**
201013201708
** NUMBER ==> $[NUMBER] // PG compatible
@@ -201094,16 +201789,14 @@
201094201789
assert( pPatch[i].eType==JSON_STRING );
201095201790
assert( pPatch[i].jnFlags & JNODE_LABEL );
201096201791
assert( pPatch[i].eU==1 );
201097201792
nKey = pPatch[i].n;
201098201793
zKey = pPatch[i].u.zJContent;
201099
- assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
201100201794
for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
201101201795
assert( pTarget[j].eType==JSON_STRING );
201102201796
assert( pTarget[j].jnFlags & JNODE_LABEL );
201103
- assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
201104
- if( pTarget[j].n==nKey && strncmp(pTarget[j].u.zJContent,zKey,nKey)==0 ){
201797
+ if( jsonSameLabel(&pPatch[i], &pTarget[j]) ){
201105201798
if( pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH) ) break;
201106201799
if( pPatch[i+1].eType==JSON_NULL ){
201107201800
pTarget[j+1].jnFlags |= JNODE_REMOVE;
201108201801
}else{
201109201802
JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
@@ -201386,22 +202079,81 @@
201386202079
}
201387202080
201388202081
/*
201389202082
** json_valid(JSON)
201390202083
**
201391
-** Return 1 if JSON is a well-formed JSON string according to RFC-7159.
201392
-** Return 0 otherwise.
202084
+** Return 1 if JSON is a well-formed canonical JSON string according
202085
+** to RFC-7159. Return 0 otherwise.
201393202086
*/
201394202087
static void jsonValidFunc(
201395202088
sqlite3_context *ctx,
201396202089
int argc,
201397202090
sqlite3_value **argv
201398202091
){
201399202092
JsonParse *p; /* The parse */
201400202093
UNUSED_PARAMETER(argc);
201401202094
p = jsonParseCached(ctx, argv, 0);
201402
- sqlite3_result_int(ctx, p!=0);
202095
+ if( p==0 || p->oom ){
202096
+ sqlite3_result_error_nomem(ctx);
202097
+ sqlite3_free(p);
202098
+ }else{
202099
+ sqlite3_result_int(ctx, p->nErr==0 && p->hasNonstd==0);
202100
+ if( p->nErr ) jsonParseFree(p);
202101
+ }
202102
+}
202103
+
202104
+/*
202105
+** json_error_position(JSON)
202106
+**
202107
+** If the argument is not an interpretable JSON string, then return the 1-based
202108
+** character position at which the parser first recognized that the input
202109
+** was in error. The left-most character is 1. If the string is valid
202110
+** JSON, then return 0.
202111
+**
202112
+** Note that json_valid() is only true for strictly conforming canonical JSON.
202113
+** But this routine returns zero if the input contains extension. Thus:
202114
+**
202115
+** (1) If the input X is strictly conforming canonical JSON:
202116
+**
202117
+** json_valid(X) returns true
202118
+** json_error_position(X) returns 0
202119
+**
202120
+** (2) If the input X is JSON but it includes extension (such as JSON5) that
202121
+** are not part of RFC-8259:
202122
+**
202123
+** json_valid(X) returns false
202124
+** json_error_position(X) return 0
202125
+**
202126
+** (3) If the input X cannot be interpreted as JSON even taking extensions
202127
+** into account:
202128
+**
202129
+** json_valid(X) return false
202130
+** json_error_position(X) returns 1 or more
202131
+*/
202132
+static void jsonErrorFunc(
202133
+ sqlite3_context *ctx,
202134
+ int argc,
202135
+ sqlite3_value **argv
202136
+){
202137
+ JsonParse *p; /* The parse */
202138
+ UNUSED_PARAMETER(argc);
202139
+ p = jsonParseCached(ctx, argv, 0);
202140
+ if( p==0 || p->oom ){
202141
+ sqlite3_result_error_nomem(ctx);
202142
+ sqlite3_free(p);
202143
+ }else if( p->nErr==0 ){
202144
+ sqlite3_result_int(ctx, 0);
202145
+ }else{
202146
+ int n = 1;
202147
+ u32 i;
202148
+ const char *z = p->zJson;
202149
+ for(i=0; i<p->iErr && ALWAYS(z[i]); i++){
202150
+ if( (z[i]&0xc0)!=0x80 ) n++;
202151
+ }
202152
+ sqlite3_result_int(ctx, n);
202153
+ jsonParseFree(p);
202154
+ }
201403202155
}
201404202156
201405202157
201406202158
/****************************************************************************
201407202159
** Aggregate SQL function implementations
@@ -201741,18 +202493,20 @@
201741202493
assert( pNode->eType==JSON_STRING );
201742202494
assert( pNode->jnFlags & JNODE_LABEL );
201743202495
assert( pNode->eU==1 );
201744202496
z = pNode->u.zJContent;
201745202497
nn = pNode->n;
201746
- assert( nn>=2 );
201747
- assert( z[0]=='"' );
201748
- assert( z[nn-1]=='"' );
201749
- if( nn>2 && sqlite3Isalpha(z[1]) ){
201750
- for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
201751
- if( jj==nn-1 ){
201752
- z++;
201753
- nn -= 2;
202498
+ if( (pNode->jnFlags & JNODE_RAW)==0 ){
202499
+ assert( nn>=2 );
202500
+ assert( z[0]=='"' || z[0]=='\'' );
202501
+ assert( z[nn-1]=='"' || z[0]=='\'' );
202502
+ if( nn>2 && sqlite3Isalpha(z[1]) ){
202503
+ for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
202504
+ if( jj==nn-1 ){
202505
+ z++;
202506
+ nn -= 2;
202507
+ }
201754202508
}
201755202509
}
201756202510
jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
201757202511
}
201758202512
@@ -202108,10 +202862,11 @@
202108202862
static FuncDef aJsonFunc[] = {
202109202863
JFUNCTION(json, 1, 0, jsonRemoveFunc),
202110202864
JFUNCTION(json_array, -1, 0, jsonArrayFunc),
202111202865
JFUNCTION(json_array_length, 1, 0, jsonArrayLengthFunc),
202112202866
JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc),
202867
+ JFUNCTION(json_error_position,1, 0, jsonErrorFunc),
202113202868
JFUNCTION(json_extract, -1, 0, jsonExtractFunc),
202114202869
JFUNCTION(->, 2, JSON_JSON, jsonExtractFunc),
202115202870
JFUNCTION(->>, 2, JSON_SQL, jsonExtractFunc),
202116202871
JFUNCTION(json_insert, -1, 0, jsonSetFunc),
202117202872
JFUNCTION(json_object, -1, 0, jsonObjectFunc),
@@ -202632,20 +203387,21 @@
202632203387
** using C-preprocessor macros. If that is unsuccessful, or if
202633203388
** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
202634203389
** at run-time.
202635203390
*/
202636203391
#ifndef SQLITE_BYTEORDER
202637
-#if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
202638
- defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
202639
- defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
202640
- defined(__arm__)
202641
-# define SQLITE_BYTEORDER 1234
202642
-#elif defined(sparc) || defined(__ppc__)
202643
-# define SQLITE_BYTEORDER 4321
202644
-#else
202645
-# define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
202646
-#endif
203392
+# if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
203393
+ defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
203394
+ defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
203395
+ defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64)
203396
+# define SQLITE_BYTEORDER 1234
203397
+# elif defined(sparc) || defined(__ppc__) || \
203398
+ defined(__ARMEB__) || defined(__AARCH64EB__)
203399
+# define SQLITE_BYTEORDER 4321
203400
+# else
203401
+# define SQLITE_BYTEORDER 0
203402
+# endif
202647203403
#endif
202648203404
202649203405
202650203406
/* What version of MSVC is being used. 0 means MSVC is not being used */
202651203407
#ifndef MSVC_VERSION
@@ -216825,10 +217581,12 @@
216825217581
# define SESSIONS_STRM_CHUNK_SIZE 64
216826217582
# else
216827217583
# define SESSIONS_STRM_CHUNK_SIZE 1024
216828217584
# endif
216829217585
#endif
217586
+
217587
+#define SESSIONS_ROWID "_rowid_"
216830217588
216831217589
static int sessions_strm_chunk_size = SESSIONS_STRM_CHUNK_SIZE;
216832217590
216833217591
typedef struct SessionHook SessionHook;
216834217592
struct SessionHook {
@@ -216847,10 +217605,11 @@
216847217605
char *zDb; /* Name of database session is attached to */
216848217606
int bEnableSize; /* True if changeset_size() enabled */
216849217607
int bEnable; /* True if currently recording */
216850217608
int bIndirect; /* True if all changes are indirect */
216851217609
int bAutoAttach; /* True to auto-attach tables */
217610
+ int bImplicitPK; /* True to handle tables with implicit PK */
216852217611
int rc; /* Non-zero if an error has occurred */
216853217612
void *pFilterCtx; /* First argument to pass to xTableFilter */
216854217613
int (*xTableFilter)(void *pCtx, const char *zTab);
216855217614
i64 nMalloc; /* Number of bytes of data allocated */
216856217615
i64 nMaxChangesetSize;
@@ -216923,10 +217682,11 @@
216923217682
struct SessionTable {
216924217683
SessionTable *pNext;
216925217684
char *zName; /* Local name of table */
216926217685
int nCol; /* Number of columns in table zName */
216927217686
int bStat1; /* True if this is sqlite_stat1 */
217687
+ int bRowid; /* True if this table uses rowid for PK */
216928217688
const char **azCol; /* Column names */
216929217689
u8 *abPK; /* Array of primary key flags */
216930217690
int nEntry; /* Total number of entries in hash table */
216931217691
int nChange; /* Size of apChange[] array */
216932217692
SessionChange **apChange; /* Hash table buckets */
@@ -217315,60 +218075,66 @@
217315218075
** of *piHash asn *pbNullPK are undefined. Otherwise, SQLITE_OK is returned
217316218076
** and the output variables are set as described above.
217317218077
*/
217318218078
static int sessionPreupdateHash(
217319218079
sqlite3_session *pSession, /* Session object that owns pTab */
218080
+ i64 iRowid,
217320218081
SessionTable *pTab, /* Session table handle */
217321218082
int bNew, /* True to hash the new.* PK */
217322218083
int *piHash, /* OUT: Hash value */
217323218084
int *pbNullPK /* OUT: True if there are NULL values in PK */
217324218085
){
217325218086
unsigned int h = 0; /* Hash value to return */
217326218087
int i; /* Used to iterate through columns */
217327218088
217328
- assert( *pbNullPK==0 );
217329
- assert( pTab->nCol==pSession->hook.xCount(pSession->hook.pCtx) );
217330
- for(i=0; i<pTab->nCol; i++){
217331
- if( pTab->abPK[i] ){
217332
- int rc;
217333
- int eType;
217334
- sqlite3_value *pVal;
217335
-
217336
- if( bNew ){
217337
- rc = pSession->hook.xNew(pSession->hook.pCtx, i, &pVal);
217338
- }else{
217339
- rc = pSession->hook.xOld(pSession->hook.pCtx, i, &pVal);
217340
- }
217341
- if( rc!=SQLITE_OK ) return rc;
217342
-
217343
- eType = sqlite3_value_type(pVal);
217344
- h = sessionHashAppendType(h, eType);
217345
- if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
217346
- i64 iVal;
217347
- if( eType==SQLITE_INTEGER ){
217348
- iVal = sqlite3_value_int64(pVal);
217349
- }else{
217350
- double rVal = sqlite3_value_double(pVal);
217351
- assert( sizeof(iVal)==8 && sizeof(rVal)==8 );
217352
- memcpy(&iVal, &rVal, 8);
217353
- }
217354
- h = sessionHashAppendI64(h, iVal);
217355
- }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
217356
- const u8 *z;
217357
- int n;
217358
- if( eType==SQLITE_TEXT ){
217359
- z = (const u8 *)sqlite3_value_text(pVal);
217360
- }else{
217361
- z = (const u8 *)sqlite3_value_blob(pVal);
217362
- }
217363
- n = sqlite3_value_bytes(pVal);
217364
- if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
217365
- h = sessionHashAppendBlob(h, n, z);
217366
- }else{
217367
- assert( eType==SQLITE_NULL );
217368
- assert( pTab->bStat1==0 || i!=1 );
217369
- *pbNullPK = 1;
218089
+ if( pTab->bRowid ){
218090
+ assert( pTab->nCol-1==pSession->hook.xCount(pSession->hook.pCtx) );
218091
+ h = sessionHashAppendI64(h, iRowid);
218092
+ }else{
218093
+ assert( *pbNullPK==0 );
218094
+ assert( pTab->nCol==pSession->hook.xCount(pSession->hook.pCtx) );
218095
+ for(i=0; i<pTab->nCol; i++){
218096
+ if( pTab->abPK[i] ){
218097
+ int rc;
218098
+ int eType;
218099
+ sqlite3_value *pVal;
218100
+
218101
+ if( bNew ){
218102
+ rc = pSession->hook.xNew(pSession->hook.pCtx, i, &pVal);
218103
+ }else{
218104
+ rc = pSession->hook.xOld(pSession->hook.pCtx, i, &pVal);
218105
+ }
218106
+ if( rc!=SQLITE_OK ) return rc;
218107
+
218108
+ eType = sqlite3_value_type(pVal);
218109
+ h = sessionHashAppendType(h, eType);
218110
+ if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
218111
+ i64 iVal;
218112
+ if( eType==SQLITE_INTEGER ){
218113
+ iVal = sqlite3_value_int64(pVal);
218114
+ }else{
218115
+ double rVal = sqlite3_value_double(pVal);
218116
+ assert( sizeof(iVal)==8 && sizeof(rVal)==8 );
218117
+ memcpy(&iVal, &rVal, 8);
218118
+ }
218119
+ h = sessionHashAppendI64(h, iVal);
218120
+ }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
218121
+ const u8 *z;
218122
+ int n;
218123
+ if( eType==SQLITE_TEXT ){
218124
+ z = (const u8 *)sqlite3_value_text(pVal);
218125
+ }else{
218126
+ z = (const u8 *)sqlite3_value_blob(pVal);
218127
+ }
218128
+ n = sqlite3_value_bytes(pVal);
218129
+ if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
218130
+ h = sessionHashAppendBlob(h, n, z);
218131
+ }else{
218132
+ assert( eType==SQLITE_NULL );
218133
+ assert( pTab->bStat1==0 || i!=1 );
218134
+ *pbNullPK = 1;
218135
+ }
217370218136
}
217371218137
}
217372218138
}
217373218139
217374218140
*piHash = (h % pTab->nChange);
@@ -217647,16 +218413,22 @@
217647218413
** if the pre-update-hook does not affect the same row as pChange, it returns
217648218414
** false.
217649218415
*/
217650218416
static int sessionPreupdateEqual(
217651218417
sqlite3_session *pSession, /* Session object that owns SessionTable */
218418
+ i64 iRowid, /* Rowid value if pTab->bRowid */
217652218419
SessionTable *pTab, /* Table associated with change */
217653218420
SessionChange *pChange, /* Change to compare to */
217654218421
int op /* Current pre-update operation */
217655218422
){
217656218423
int iCol; /* Used to iterate through columns */
217657218424
u8 *a = pChange->aRecord; /* Cursor used to scan change record */
218425
+
218426
+ if( pTab->bRowid ){
218427
+ if( a[0]!=SQLITE_INTEGER ) return 0;
218428
+ return sessionGetI64(&a[1])==iRowid;
218429
+ }
217658218430
217659218431
assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE );
217660218432
for(iCol=0; iCol<pTab->nCol; iCol++){
217661218433
if( !pTab->abPK[iCol] ){
217662218434
a += sessionSerialLen(a);
@@ -217798,11 +218570,12 @@
217798218570
const char *zDb, /* Name of attached database (e.g. "main") */
217799218571
const char *zThis, /* Table name */
217800218572
int *pnCol, /* OUT: number of columns */
217801218573
const char **pzTab, /* OUT: Copy of zThis */
217802218574
const char ***pazCol, /* OUT: Array of column names for table */
217803
- u8 **pabPK /* OUT: Array of booleans - true for PK col */
218575
+ u8 **pabPK, /* OUT: Array of booleans - true for PK col */
218576
+ int *pbRowid /* OUT: True if only PK is a rowid */
217804218577
){
217805218578
char *zPragma;
217806218579
sqlite3_stmt *pStmt;
217807218580
int rc;
217808218581
sqlite3_int64 nByte;
@@ -217810,10 +218583,11 @@
217810218583
int nThis;
217811218584
int i;
217812218585
u8 *pAlloc = 0;
217813218586
char **azCol = 0;
217814218587
u8 *abPK = 0;
218588
+ int bRowid = 0; /* Set to true to use rowid as PK */
217815218589
217816218590
assert( pazCol && pabPK );
217817218591
217818218592
nThis = sqlite3Strlen30(zThis);
217819218593
if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
@@ -217854,14 +218628,19 @@
217854218628
if( pzTab ) *pzTab = 0;
217855218629
return rc;
217856218630
}
217857218631
217858218632
nByte = nThis + 1;
218633
+ bRowid = (pbRowid!=0);
217859218634
while( SQLITE_ROW==sqlite3_step(pStmt) ){
217860218635
nByte += sqlite3_column_bytes(pStmt, 1);
217861218636
nDbCol++;
218637
+ if( sqlite3_column_int(pStmt, 5) ) bRowid = 0;
217862218638
}
218639
+ if( nDbCol==0 ) bRowid = 0;
218640
+ nDbCol += bRowid;
218641
+ nByte += strlen(SESSIONS_ROWID);
217863218642
rc = sqlite3_reset(pStmt);
217864218643
217865218644
if( rc==SQLITE_OK ){
217866218645
nByte += nDbCol * (sizeof(const char *) + sizeof(u8) + 1);
217867218646
pAlloc = sessionMalloc64(pSession, nByte);
@@ -217879,10 +218658,18 @@
217879218658
*pzTab = (char *)pAlloc;
217880218659
pAlloc += nThis+1;
217881218660
}
217882218661
217883218662
i = 0;
218663
+ if( bRowid ){
218664
+ size_t nName = strlen(SESSIONS_ROWID);
218665
+ memcpy(pAlloc, SESSIONS_ROWID, nName+1);
218666
+ azCol[i] = (char*)pAlloc;
218667
+ pAlloc += nName+1;
218668
+ abPK[i] = 1;
218669
+ i++;
218670
+ }
217884218671
while( SQLITE_ROW==sqlite3_step(pStmt) ){
217885218672
int nName = sqlite3_column_bytes(pStmt, 1);
217886218673
const unsigned char *zName = sqlite3_column_text(pStmt, 1);
217887218674
if( zName==0 ) break;
217888218675
memcpy(pAlloc, zName, nName+1);
@@ -217890,11 +218677,10 @@
217890218677
pAlloc += nName+1;
217891218678
abPK[i] = sqlite3_column_int(pStmt, 5);
217892218679
i++;
217893218680
}
217894218681
rc = sqlite3_reset(pStmt);
217895
-
217896218682
}
217897218683
217898218684
/* If successful, populate the output variables. Otherwise, zero them and
217899218685
** free any allocation made. An error code will be returned in this case.
217900218686
*/
@@ -217907,10 +218693,11 @@
217907218693
*pabPK = 0;
217908218694
*pnCol = 0;
217909218695
if( pzTab ) *pzTab = 0;
217910218696
sessionFree(pSession, azCol);
217911218697
}
218698
+ if( pbRowid ) *pbRowid = bRowid;
217912218699
sqlite3_finalize(pStmt);
217913218700
return rc;
217914218701
}
217915218702
217916218703
/*
@@ -217928,11 +218715,12 @@
217928218715
static int sessionInitTable(sqlite3_session *pSession, SessionTable *pTab){
217929218716
if( pTab->nCol==0 ){
217930218717
u8 *abPK;
217931218718
assert( pTab->azCol==0 || pTab->abPK==0 );
217932218719
pSession->rc = sessionTableInfo(pSession, pSession->db, pSession->zDb,
217933
- pTab->zName, &pTab->nCol, 0, &pTab->azCol, &abPK
218720
+ pTab->zName, &pTab->nCol, 0, &pTab->azCol, &abPK,
218721
+ (pSession->bImplicitPK ? &pTab->bRowid : 0)
217934218722
);
217935218723
if( pSession->rc==SQLITE_OK ){
217936218724
int i;
217937218725
for(i=0; i<pTab->nCol; i++){
217938218726
if( abPK[i] ){
@@ -218000,10 +218788,11 @@
218000218788
SessionTable *pTab, /* Table that change applies to */
218001218789
SessionChange *pC /* Update pC->nMaxSize */
218002218790
){
218003218791
i64 nNew = 2;
218004218792
if( pC->op==SQLITE_INSERT ){
218793
+ if( pTab->bRowid ) nNew += 9;
218005218794
if( op!=SQLITE_DELETE ){
218006218795
int ii;
218007218796
for(ii=0; ii<pTab->nCol; ii++){
218008218797
sqlite3_value *p = 0;
218009218798
pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
@@ -218016,11 +218805,15 @@
218016218805
nNew += pC->nRecord;
218017218806
}
218018218807
}else{
218019218808
int ii;
218020218809
u8 *pCsr = pC->aRecord;
218021
- for(ii=0; ii<pTab->nCol; ii++){
218810
+ if( pTab->bRowid ){
218811
+ nNew += 9;
218812
+ pCsr += 9;
218813
+ }
218814
+ for(ii=0; ii<(pTab->nCol-pTab->bRowid); ii++){
218022218815
int bChanged = 1;
218023218816
int nOld = 0;
218024218817
int eType;
218025218818
sqlite3_value *p = 0;
218026218819
pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
@@ -218100,10 +218893,11 @@
218100218893
** Unless one is already present or an error occurs, an entry is added
218101218894
** to the changed-rows hash table associated with table pTab.
218102218895
*/
218103218896
static void sessionPreupdateOneChange(
218104218897
int op, /* One of SQLITE_UPDATE, INSERT, DELETE */
218898
+ i64 iRowid,
218105218899
sqlite3_session *pSession, /* Session object pTab is attached to */
218106218900
SessionTable *pTab /* Table that change applies to */
218107218901
){
218108218902
int iHash;
218109218903
int bNull = 0;
@@ -218115,11 +218909,11 @@
218115218909
/* Load table details if required */
218116218910
if( sessionInitTable(pSession, pTab) ) return;
218117218911
218118218912
/* Check the number of columns in this xPreUpdate call matches the
218119218913
** number of columns in the table. */
218120
- if( pTab->nCol!=pSession->hook.xCount(pSession->hook.pCtx) ){
218914
+ if( (pTab->nCol-pTab->bRowid)!=pSession->hook.xCount(pSession->hook.pCtx) ){
218121218915
pSession->rc = SQLITE_SCHEMA;
218122218916
return;
218123218917
}
218124218918
218125218919
/* Grow the hash table if required */
@@ -218148,18 +218942,20 @@
218148218942
}
218149218943
218150218944
/* Calculate the hash-key for this change. If the primary key of the row
218151218945
** includes a NULL value, exit early. Such changes are ignored by the
218152218946
** session module. */
218153
- rc = sessionPreupdateHash(pSession, pTab, op==SQLITE_INSERT, &iHash, &bNull);
218947
+ rc = sessionPreupdateHash(
218948
+ pSession, iRowid, pTab, op==SQLITE_INSERT, &iHash, &bNull
218949
+ );
218154218950
if( rc!=SQLITE_OK ) goto error_out;
218155218951
218156218952
if( bNull==0 ){
218157218953
/* Search the hash table for an existing record for this row. */
218158218954
SessionChange *pC;
218159218955
for(pC=pTab->apChange[iHash]; pC; pC=pC->pNext){
218160
- if( sessionPreupdateEqual(pSession, pTab, pC, op) ) break;
218956
+ if( sessionPreupdateEqual(pSession, iRowid, pTab, pC, op) ) break;
218161218957
}
218162218958
218163218959
if( pC==0 ){
218164218960
/* Create a new change object containing all the old values (if
218165218961
** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
@@ -218170,11 +218966,11 @@
218170218966
assert( rc==SQLITE_OK );
218171218967
pTab->nEntry++;
218172218968
218173218969
/* Figure out how large an allocation is required */
218174218970
nByte = sizeof(SessionChange);
218175
- for(i=0; i<pTab->nCol; i++){
218971
+ for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
218176218972
sqlite3_value *p = 0;
218177218973
if( op!=SQLITE_INSERT ){
218178218974
TESTONLY(int trc = ) pSession->hook.xOld(pSession->hook.pCtx, i, &p);
218179218975
assert( trc==SQLITE_OK );
218180218976
}else if( pTab->abPK[i] ){
@@ -218185,10 +218981,13 @@
218185218981
/* This may fail if SQLite value p contains a utf-16 string that must
218186218982
** be converted to utf-8 and an OOM error occurs while doing so. */
218187218983
rc = sessionSerializeValue(0, p, &nByte);
218188218984
if( rc!=SQLITE_OK ) goto error_out;
218189218985
}
218986
+ if( pTab->bRowid ){
218987
+ nByte += 9; /* Size of rowid field - an integer */
218988
+ }
218190218989
218191218990
/* Allocate the change object */
218192218991
pC = (SessionChange *)sessionMalloc64(pSession, nByte);
218193218992
if( !pC ){
218194218993
rc = SQLITE_NOMEM;
@@ -218201,11 +219000,16 @@
218201219000
/* Populate the change object. None of the preupdate_old(),
218202219001
** preupdate_new() or SerializeValue() calls below may fail as all
218203219002
** required values and encodings have already been cached in memory.
218204219003
** It is not possible for an OOM to occur in this block. */
218205219004
nByte = 0;
218206
- for(i=0; i<pTab->nCol; i++){
219005
+ if( pTab->bRowid ){
219006
+ pC->aRecord[0] = SQLITE_INTEGER;
219007
+ sessionPutI64(&pC->aRecord[1], iRowid);
219008
+ nByte = 9;
219009
+ }
219010
+ for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
218207219011
sqlite3_value *p = 0;
218208219012
if( op!=SQLITE_INSERT ){
218209219013
pSession->hook.xOld(pSession->hook.pCtx, i, &p);
218210219014
}else if( pTab->abPK[i] ){
218211219015
pSession->hook.xNew(pSession->hook.pCtx, i, &p);
@@ -218316,13 +219120,14 @@
218316219120
if( sqlite3_strnicmp(zDb, pSession->zDb, nDb+1) ) continue;
218317219121
218318219122
pSession->rc = sessionFindTable(pSession, zName, &pTab);
218319219123
if( pTab ){
218320219124
assert( pSession->rc==SQLITE_OK );
218321
- sessionPreupdateOneChange(op, pSession, pTab);
219125
+ assert( op==SQLITE_UPDATE || iKey1==iKey2 );
219126
+ sessionPreupdateOneChange(op, iKey1, pSession, pTab);
218322219127
if( op==SQLITE_UPDATE ){
218323
- sessionPreupdateOneChange(SQLITE_INSERT, pSession, pTab);
219128
+ sessionPreupdateOneChange(SQLITE_INSERT, iKey2, pSession, pTab);
218324219129
}
218325219130
}
218326219131
}
218327219132
}
218328219133
@@ -218357,29 +219162,30 @@
218357219162
}
218358219163
218359219164
typedef struct SessionDiffCtx SessionDiffCtx;
218360219165
struct SessionDiffCtx {
218361219166
sqlite3_stmt *pStmt;
219167
+ int bRowid;
218362219168
int nOldOff;
218363219169
};
218364219170
218365219171
/*
218366219172
** The diff hook implementations.
218367219173
*/
218368219174
static int sessionDiffOld(void *pCtx, int iVal, sqlite3_value **ppVal){
218369219175
SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
218370
- *ppVal = sqlite3_column_value(p->pStmt, iVal+p->nOldOff);
219176
+ *ppVal = sqlite3_column_value(p->pStmt, iVal+p->nOldOff+p->bRowid);
218371219177
return SQLITE_OK;
218372219178
}
218373219179
static int sessionDiffNew(void *pCtx, int iVal, sqlite3_value **ppVal){
218374219180
SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
218375
- *ppVal = sqlite3_column_value(p->pStmt, iVal);
219181
+ *ppVal = sqlite3_column_value(p->pStmt, iVal+p->bRowid);
218376219182
return SQLITE_OK;
218377219183
}
218378219184
static int sessionDiffCount(void *pCtx){
218379219185
SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
218380
- return p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt);
219186
+ return (p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt)) - p->bRowid;
218381219187
}
218382219188
static int sessionDiffDepth(void *pCtx){
218383219189
(void)pCtx;
218384219190
return 0;
218385219191
}
@@ -218454,18 +219260,20 @@
218454219260
}
218455219261
218456219262
static char *sessionSelectFindNew(
218457219263
const char *zDb1, /* Pick rows in this db only */
218458219264
const char *zDb2, /* But not in this one */
219265
+ int bRowid,
218459219266
const char *zTbl, /* Table name */
218460219267
const char *zExpr
218461219268
){
219269
+ const char *zSel = (bRowid ? SESSIONS_ROWID ", *" : "*");
218462219270
char *zRet = sqlite3_mprintf(
218463
- "SELECT * FROM \"%w\".\"%w\" WHERE NOT EXISTS ("
219271
+ "SELECT %s FROM \"%w\".\"%w\" WHERE NOT EXISTS ("
218464219272
" SELECT 1 FROM \"%w\".\"%w\" WHERE %s"
218465219273
")",
218466
- zDb1, zTbl, zDb2, zTbl, zExpr
219274
+ zSel, zDb1, zTbl, zDb2, zTbl, zExpr
218467219275
);
218468219276
return zRet;
218469219277
}
218470219278
218471219279
static int sessionDiffFindNew(
@@ -218475,11 +219283,13 @@
218475219283
const char *zDb1,
218476219284
const char *zDb2,
218477219285
char *zExpr
218478219286
){
218479219287
int rc = SQLITE_OK;
218480
- char *zStmt = sessionSelectFindNew(zDb1, zDb2, pTab->zName,zExpr);
219288
+ char *zStmt = sessionSelectFindNew(
219289
+ zDb1, zDb2, pTab->bRowid, pTab->zName, zExpr
219290
+ );
218481219291
218482219292
if( zStmt==0 ){
218483219293
rc = SQLITE_NOMEM;
218484219294
}else{
218485219295
sqlite3_stmt *pStmt;
@@ -218486,20 +219296,43 @@
218486219296
rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
218487219297
if( rc==SQLITE_OK ){
218488219298
SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
218489219299
pDiffCtx->pStmt = pStmt;
218490219300
pDiffCtx->nOldOff = 0;
219301
+ pDiffCtx->bRowid = pTab->bRowid;
218491219302
while( SQLITE_ROW==sqlite3_step(pStmt) ){
218492
- sessionPreupdateOneChange(op, pSession, pTab);
219303
+ i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
219304
+ sessionPreupdateOneChange(op, iRowid, pSession, pTab);
218493219305
}
218494219306
rc = sqlite3_finalize(pStmt);
218495219307
}
218496219308
sqlite3_free(zStmt);
218497219309
}
218498219310
218499219311
return rc;
218500219312
}
219313
+
219314
+/*
219315
+** Return a comma-separated list of the fully-qualified (with both database
219316
+** and table name) column names from table pTab. e.g.
219317
+**
219318
+** "main"."t1"."a", "main"."t1"."b", "main"."t1"."c"
219319
+*/
219320
+static char *sessionAllCols(
219321
+ const char *zDb,
219322
+ SessionTable *pTab
219323
+){
219324
+ int ii;
219325
+ char *zRet = 0;
219326
+ for(ii=0; ii<pTab->nCol; ii++){
219327
+ zRet = sqlite3_mprintf("%z%s\"%w\".\"%w\".\"%w\"",
219328
+ zRet, (zRet ? ", " : ""), zDb, pTab->zName, pTab->azCol[ii]
219329
+ );
219330
+ if( !zRet ) break;
219331
+ }
219332
+ return zRet;
219333
+}
218501219334
218502219335
static int sessionDiffFindModified(
218503219336
sqlite3_session *pSession,
218504219337
SessionTable *pTab,
218505219338
const char *zFrom,
@@ -218511,15 +219344,17 @@
218511219344
pSession->zDb, zFrom, pTab->zName, pTab->azCol, pTab->abPK
218512219345
);
218513219346
if( zExpr2==0 ){
218514219347
rc = SQLITE_NOMEM;
218515219348
}else{
219349
+ char *z1 = sessionAllCols(pSession->zDb, pTab);
219350
+ char *z2 = sessionAllCols(zFrom, pTab);
218516219351
char *zStmt = sqlite3_mprintf(
218517
- "SELECT * FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)",
218518
- pSession->zDb, pTab->zName, zFrom, pTab->zName, zExpr, zExpr2
219352
+ "SELECT %s,%s FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)",
219353
+ z1, z2, pSession->zDb, pTab->zName, zFrom, pTab->zName, zExpr, zExpr2
218519219354
);
218520
- if( zStmt==0 ){
219355
+ if( zStmt==0 || z1==0 || z2==0 ){
218521219356
rc = SQLITE_NOMEM;
218522219357
}else{
218523219358
sqlite3_stmt *pStmt;
218524219359
rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
218525219360
@@ -218526,16 +219361,19 @@
218526219361
if( rc==SQLITE_OK ){
218527219362
SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
218528219363
pDiffCtx->pStmt = pStmt;
218529219364
pDiffCtx->nOldOff = pTab->nCol;
218530219365
while( SQLITE_ROW==sqlite3_step(pStmt) ){
218531
- sessionPreupdateOneChange(SQLITE_UPDATE, pSession, pTab);
219366
+ i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
219367
+ sessionPreupdateOneChange(SQLITE_UPDATE, iRowid, pSession, pTab);
218532219368
}
218533219369
rc = sqlite3_finalize(pStmt);
218534219370
}
218535
- sqlite3_free(zStmt);
218536219371
}
219372
+ sqlite3_free(zStmt);
219373
+ sqlite3_free(z1);
219374
+ sqlite3_free(z2);
218537219375
}
218538219376
218539219377
return rc;
218540219378
}
218541219379
@@ -218570,13 +219408,16 @@
218570219408
/* Check the table schemas match */
218571219409
if( rc==SQLITE_OK ){
218572219410
int bHasPk = 0;
218573219411
int bMismatch = 0;
218574219412
int nCol; /* Columns in zFrom.zTbl */
219413
+ int bRowid = 0;
218575219414
u8 *abPK;
218576219415
const char **azCol = 0;
218577
- rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, &abPK);
219416
+ rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, &abPK,
219417
+ pSession->bImplicitPK ? &bRowid : 0
219418
+ );
218578219419
if( rc==SQLITE_OK ){
218579219420
if( pTo->nCol!=nCol ){
218580219421
bMismatch = 1;
218581219422
}else{
218582219423
int i;
@@ -219223,19 +220064,20 @@
219223220064
static int sessionSelectStmt(
219224220065
sqlite3 *db, /* Database handle */
219225220066
int bIgnoreNoop,
219226220067
const char *zDb, /* Database name */
219227220068
const char *zTab, /* Table name */
220069
+ int bRowid,
219228220070
int nCol, /* Number of columns in table */
219229220071
const char **azCol, /* Names of table columns */
219230220072
u8 *abPK, /* PRIMARY KEY array */
219231220073
sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
219232220074
){
219233220075
int rc = SQLITE_OK;
219234220076
char *zSql = 0;
219235220077
const char *zSep = "";
219236
- const char *zCols = "*";
220078
+ const char *zCols = bRowid ? SESSIONS_ROWID ", *" : "*";
219237220079
int nSql = -1;
219238220080
int i;
219239220081
219240220082
SessionBuffer nooptest = {0, 0, 0};
219241220083
SessionBuffer pkfield = {0, 0, 0};
@@ -219250,11 +220092,10 @@
219250220092
"?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc
219251220093
);
219252220094
zCols = "tbl, ?2, stat";
219253220095
}else{
219254220096
for(i=0; i<nCol; i++){
219255
-
219256220097
if( abPK[i] ){
219257220098
sessionAppendStr(&pkfield, zSep, &rc);
219258220099
sessionAppendStr(&pkvar, zSep, &rc);
219259220100
zSep = ", ";
219260220101
sessionAppendIdent(&pkfield, azCol[i], &rc);
@@ -219457,24 +220298,32 @@
219457220298
const char **azCol = 0; /* Table columns */
219458220299
int i; /* Used to iterate through hash buckets */
219459220300
sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */
219460220301
int nRewind = buf.nBuf; /* Initial size of write buffer */
219461220302
int nNoop; /* Size of buffer after writing tbl header */
220303
+ int bRowid = 0;
219462220304
219463220305
/* Check the table schema is still Ok. */
219464
- rc = sessionTableInfo(0, db, pSession->zDb, zName, &nCol, 0,&azCol,&abPK);
219465
- if( !rc && (pTab->nCol!=nCol || memcmp(abPK, pTab->abPK, nCol)) ){
220306
+ rc = sessionTableInfo(
220307
+ 0, db, pSession->zDb, zName, &nCol, 0, &azCol, &abPK,
220308
+ (pSession->bImplicitPK ? &bRowid : 0)
220309
+ );
220310
+ if( rc==SQLITE_OK && (
220311
+ pTab->nCol!=nCol
220312
+ || pTab->bRowid!=bRowid
220313
+ || memcmp(abPK, pTab->abPK, nCol)
220314
+ )){
219466220315
rc = SQLITE_SCHEMA;
219467220316
}
219468220317
219469220318
/* Write a table header */
219470220319
sessionAppendTableHdr(&buf, bPatchset, pTab, &rc);
219471220320
219472220321
/* Build and compile a statement to execute: */
219473220322
if( rc==SQLITE_OK ){
219474220323
rc = sessionSelectStmt(
219475
- db, 0, pSession->zDb, zName, nCol, azCol, abPK, &pSel
220324
+ db, 0, pSession->zDb, zName, bRowid, nCol, azCol, abPK, &pSel
219476220325
);
219477220326
}
219478220327
219479220328
nNoop = buf.nBuf;
219480220329
for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
@@ -219554,12 +220403,12 @@
219554220403
void **ppChangeset /* OUT: Buffer containing changeset */
219555220404
){
219556220405
int rc;
219557220406
219558220407
if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE;
219559
- rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset);
219560
- assert( rc || pnChangeset==0
220408
+ rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
220409
+ assert( 1 || rc || pnChangeset==0
219561220410
|| pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
219562220411
);
219563220412
return rc;
219564220413
}
219565220414
@@ -219671,10 +220520,23 @@
219671220520
}
219672220521
}
219673220522
*(int*)pArg = pSession->bEnableSize;
219674220523
break;
219675220524
}
220525
+
220526
+ case SQLITE_SESSION_OBJCONFIG_ROWID: {
220527
+ int iArg = *(int*)pArg;
220528
+ if( iArg>=0 ){
220529
+ if( pSession->pTable ){
220530
+ rc = SQLITE_MISUSE;
220531
+ }else{
220532
+ pSession->bImplicitPK = (iArg!=0);
220533
+ }
220534
+ }
220535
+ *(int*)pArg = pSession->bImplicitPK;
220536
+ break;
220537
+ }
219676220538
219677220539
default:
219678220540
rc = SQLITE_MISUSE;
219679220541
}
219680220542
@@ -220661,10 +221523,11 @@
220661221523
SessionBuffer constraints; /* Deferred constraints are stored here */
220662221524
SessionBuffer rebase; /* Rebase information (if any) here */
220663221525
u8 bRebaseStarted; /* If table header is already in rebase */
220664221526
u8 bRebase; /* True to collect rebase information */
220665221527
u8 bIgnoreNoop; /* True to ignore no-op conflicts */
221528
+ int bRowid;
220666221529
};
220667221530
220668221531
/* Number of prepared UPDATE statements to cache. */
220669221532
#define SESSION_UPDATE_CACHE_SZ 12
220670221533
@@ -220911,12 +221774,13 @@
220911221774
static int sessionSelectRow(
220912221775
sqlite3 *db, /* Database handle */
220913221776
const char *zTab, /* Table name */
220914221777
SessionApplyCtx *p /* Session changeset-apply context */
220915221778
){
221779
+ /* TODO */
220916221780
return sessionSelectStmt(db, p->bIgnoreNoop,
220917
- "main", zTab, p->nCol, p->azCol, p->abPK, &p->pSelect
221781
+ "main", zTab, p->bRowid, p->nCol, p->azCol, p->abPK, &p->pSelect
220918221782
);
220919221783
}
220920221784
220921221785
/*
220922221786
** Formulate and prepare an INSERT statement to add a record to table zTab.
@@ -221608,10 +222472,11 @@
221608222472
sApply.azCol = 0;
221609222473
sApply.abPK = 0;
221610222474
sApply.bStat1 = 0;
221611222475
sApply.bDeferConstraints = 1;
221612222476
sApply.bRebaseStarted = 0;
222477
+ sApply.bRowid = 0;
221613222478
memset(&sApply.constraints, 0, sizeof(SessionBuffer));
221614222479
221615222480
/* If an xFilter() callback was specified, invoke it now. If the
221616222481
** xFilter callback returns zero, skip this table. If it returns
221617222482
** non-zero, proceed. */
@@ -221627,12 +222492,12 @@
221627222492
}else{
221628222493
int nMinCol = 0;
221629222494
int i;
221630222495
221631222496
sqlite3changeset_pk(pIter, &abPK, 0);
221632
- rc = sessionTableInfo(0,
221633
- db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK
222497
+ rc = sessionTableInfo(0, db, "main", zNew,
222498
+ &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK, &sApply.bRowid
221634222499
);
221635222500
if( rc!=SQLITE_OK ) break;
221636222501
for(i=0; i<sApply.nCol; i++){
221637222502
if( sApply.abPK[i] ) nMinCol = i+1;
221638222503
}
@@ -223510,29 +224375,34 @@
223510224375
fts5_tokenizer *pTokApi;
223511224376
int bLock; /* True when table is preparing statement */
223512224377
int ePattern; /* FTS_PATTERN_XXX constant */
223513224378
223514224379
/* Values loaded from the %_config table */
224380
+ int iVersion; /* fts5 file format 'version' */
223515224381
int iCookie; /* Incremented when %_config is modified */
223516224382
int pgsz; /* Approximate page size used in %_data */
223517224383
int nAutomerge; /* 'automerge' setting */
223518224384
int nCrisisMerge; /* Maximum allowed segments per level */
223519224385
int nUsermerge; /* 'usermerge' setting */
223520224386
int nHashSize; /* Bytes of memory for in-memory hash */
223521224387
char *zRank; /* Name of rank function */
223522224388
char *zRankArgs; /* Arguments to rank function */
224389
+ int bSecureDelete; /* 'secure-delete' */
223523224390
223524224391
/* If non-NULL, points to sqlite3_vtab.base.zErrmsg. Often NULL. */
223525224392
char **pzErrmsg;
223526224393
223527224394
#ifdef SQLITE_DEBUG
223528224395
int bPrefixIndex; /* True to use prefix-indexes */
223529224396
#endif
223530224397
};
223531224398
223532
-/* Current expected value of %_config table 'version' field */
223533
-#define FTS5_CURRENT_VERSION 4
224399
+/* Current expected value of %_config table 'version' field. And
224400
+** the expected version if the 'secure-delete' option has ever been
224401
+** set on the table. */
224402
+#define FTS5_CURRENT_VERSION 4
224403
+#define FTS5_CURRENT_VERSION_SECUREDELETE 5
223534224404
223535224405
#define FTS5_CONTENT_NORMAL 0
223536224406
#define FTS5_CONTENT_NONE 1
223537224407
#define FTS5_CONTENT_EXTERNAL 2
223538224408
@@ -223694,10 +224564,11 @@
223694224564
/* The following are used internally by the fts5_index.c module. They are
223695224565
** defined here only to make it easier to avoid clashes with the flags
223696224566
** above. */
223697224567
#define FTS5INDEX_QUERY_SKIPEMPTY 0x0010
223698224568
#define FTS5INDEX_QUERY_NOOUTPUT 0x0020
224569
+#define FTS5INDEX_QUERY_SKIPHASH 0x0040
223699224570
223700224571
/*
223701224572
** Create/destroy an Fts5Index object.
223702224573
*/
223703224574
static int sqlite3Fts5IndexOpen(Fts5Config *pConfig, int bCreate, Fts5Index**, char**);
@@ -227693,10 +228564,22 @@
227693228564
pConfig->zRankArgs = zRankArgs;
227694228565
}else if( rc==SQLITE_ERROR ){
227695228566
rc = SQLITE_OK;
227696228567
*pbBadkey = 1;
227697228568
}
228569
+ }
228570
+
228571
+ else if( 0==sqlite3_stricmp(zKey, "secure-delete") ){
228572
+ int bVal = -1;
228573
+ if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){
228574
+ bVal = sqlite3_value_int(pVal);
228575
+ }
228576
+ if( bVal<0 ){
228577
+ *pbBadkey = 1;
228578
+ }else{
228579
+ pConfig->bSecureDelete = (bVal ? 1 : 0);
228580
+ }
227698228581
}else{
227699228582
*pbBadkey = 1;
227700228583
}
227701228584
return rc;
227702228585
}
@@ -227737,19 +228620,24 @@
227737228620
}
227738228621
}
227739228622
rc = sqlite3_finalize(p);
227740228623
}
227741228624
227742
- if( rc==SQLITE_OK && iVersion!=FTS5_CURRENT_VERSION ){
228625
+ if( rc==SQLITE_OK
228626
+ && iVersion!=FTS5_CURRENT_VERSION
228627
+ && iVersion!=FTS5_CURRENT_VERSION_SECUREDELETE
228628
+ ){
227743228629
rc = SQLITE_ERROR;
227744228630
if( pConfig->pzErrmsg ){
227745228631
assert( 0==*pConfig->pzErrmsg );
227746
- *pConfig->pzErrmsg = sqlite3_mprintf(
227747
- "invalid fts5 file format (found %d, expected %d) - run 'rebuild'",
227748
- iVersion, FTS5_CURRENT_VERSION
228632
+ *pConfig->pzErrmsg = sqlite3_mprintf("invalid fts5 file format "
228633
+ "(found %d, expected %d or %d) - run 'rebuild'",
228634
+ iVersion, FTS5_CURRENT_VERSION, FTS5_CURRENT_VERSION_SECUREDELETE
227749228635
);
227750228636
}
228637
+ }else{
228638
+ pConfig->iVersion = iVersion;
227751228639
}
227752228640
227753228641
if( rc==SQLITE_OK ){
227754228642
pConfig->iCookie = iCookie;
227755228643
}
@@ -228163,11 +229051,11 @@
228163229051
228164229052
static int sqlite3Fts5ExprAnd(Fts5Expr **pp1, Fts5Expr *p2){
228165229053
Fts5Parse sParse;
228166229054
memset(&sParse, 0, sizeof(sParse));
228167229055
228168
- if( *pp1 ){
229056
+ if( *pp1 && p2 ){
228169229057
Fts5Expr *p1 = *pp1;
228170229058
int nPhrase = p1->nPhrase + p2->nPhrase;
228171229059
228172229060
p1->pRoot = sqlite3Fts5ParseNode(&sParse, FTS5_AND, p1->pRoot, p2->pRoot,0);
228173229061
p2->pRoot = 0;
@@ -228188,11 +229076,11 @@
228188229076
p1->apExprPhrase = ap;
228189229077
}
228190229078
}
228191229079
sqlite3_free(p2->apExprPhrase);
228192229080
sqlite3_free(p2);
228193
- }else{
229081
+ }else if( p2 ){
228194229082
*pp1 = p2;
228195229083
}
228196229084
228197229085
return sParse.rc;
228198229086
}
@@ -231705,10 +232593,12 @@
231705232593
sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
231706232594
sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
231707232595
sqlite3_stmt *pIdxSelect;
231708232596
int nRead; /* Total number of blocks read */
231709232597
232598
+ sqlite3_stmt *pDeleteFromIdx;
232599
+
231710232600
sqlite3_stmt *pDataVersion;
231711232601
i64 iStructVersion; /* data_version when pStruct read */
231712232602
Fts5Structure *pStruct; /* Current db structure (or NULL) */
231713232603
};
231714232604
@@ -231797,13 +232687,10 @@
231797232687
** Current leaf page number within segment.
231798232688
**
231799232689
** iLeafOffset:
231800232690
** Byte offset within the current leaf that is the first byte of the
231801232691
** position list data (one byte passed the position-list size field).
231802
-** rowid field of the current entry. Usually this is the size field of the
231803
-** position list data. The exception is if the rowid for the current entry
231804
-** is the last thing on the leaf page.
231805232692
**
231806232693
** pLeaf:
231807232694
** Buffer containing current leaf page data. Set to NULL at EOF.
231808232695
**
231809232696
** iTermLeafPgno, iTermLeafOffset:
@@ -232388,10 +233275,11 @@
232388233275
** Add a level to the Fts5Structure.aLevel[] array of structure object
232389233276
** (*ppStruct).
232390233277
*/
232391233278
static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
232392233279
fts5StructureMakeWritable(pRc, ppStruct);
233280
+ assert( (ppStruct!=0 && (*ppStruct)!=0) || (*pRc)!=SQLITE_OK );
232393233281
if( *pRc==SQLITE_OK ){
232394233282
Fts5Structure *pStruct = *ppStruct;
232395233283
int nLevel = pStruct->nLevel;
232396233284
sqlite3_int64 nByte = (
232397233285
sizeof(Fts5Structure) + /* Main structure */
@@ -232846,46 +233734,29 @@
232846233734
assert( pLvl->bEof==0 );
232847233735
if( iOff<=pLvl->iFirstOff ){
232848233736
pLvl->bEof = 1;
232849233737
}else{
232850233738
u8 *a = pLvl->pData->p;
232851
- i64 iVal;
232852
- int iLimit;
232853
- int ii;
232854
- int nZero = 0;
232855
-
232856
- /* Currently iOff points to the first byte of a varint. This block
232857
- ** decrements iOff until it points to the first byte of the previous
232858
- ** varint. Taking care not to read any memory locations that occur
232859
- ** before the buffer in memory. */
232860
- iLimit = (iOff>9 ? iOff-9 : 0);
232861
- for(iOff--; iOff>iLimit; iOff--){
232862
- if( (a[iOff-1] & 0x80)==0 ) break;
232863
- }
232864
-
232865
- fts5GetVarint(&a[iOff], (u64*)&iVal);
232866
- pLvl->iRowid -= iVal;
232867
- pLvl->iLeafPgno--;
232868
-
232869
- /* Skip backwards past any 0x00 varints. */
232870
- for(ii=iOff-1; ii>=pLvl->iFirstOff && a[ii]==0x00; ii--){
232871
- nZero++;
232872
- }
232873
- if( ii>=pLvl->iFirstOff && (a[ii] & 0x80) ){
232874
- /* The byte immediately before the last 0x00 byte has the 0x80 bit
232875
- ** set. So the last 0x00 is only a varint 0 if there are 8 more 0x80
232876
- ** bytes before a[ii]. */
232877
- int bZero = 0; /* True if last 0x00 counts */
232878
- if( (ii-8)>=pLvl->iFirstOff ){
232879
- int j;
232880
- for(j=1; j<=8 && (a[ii-j] & 0x80); j++);
232881
- bZero = (j>8);
232882
- }
232883
- if( bZero==0 ) nZero--;
232884
- }
232885
- pLvl->iLeafPgno -= nZero;
232886
- pLvl->iOff = iOff - nZero;
233739
+
233740
+ pLvl->iOff = 0;
233741
+ fts5DlidxLvlNext(pLvl);
233742
+ while( 1 ){
233743
+ int nZero = 0;
233744
+ int ii = pLvl->iOff;
233745
+ u64 delta = 0;
233746
+
233747
+ while( a[ii]==0 ){
233748
+ nZero++;
233749
+ ii++;
233750
+ }
233751
+ ii += sqlite3Fts5GetVarint(&a[ii], &delta);
233752
+
233753
+ if( ii>=iOff ) break;
233754
+ pLvl->iLeafPgno += nZero+1;
233755
+ pLvl->iRowid += delta;
233756
+ pLvl->iOff = ii;
233757
+ }
232887233758
}
232888233759
232889233760
return pLvl->bEof;
232890233761
}
232891233762
@@ -233077,11 +233948,11 @@
233077233948
static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
233078233949
u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
233079233950
i64 iOff = pIter->iLeafOffset;
233080233951
233081233952
ASSERT_SZLEAF_OK(pIter->pLeaf);
233082
- if( iOff>=pIter->pLeaf->szLeaf ){
233953
+ while( iOff>=pIter->pLeaf->szLeaf ){
233083233954
fts5SegIterNextPage(p, pIter);
233084233955
if( pIter->pLeaf==0 ){
233085233956
if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
233086233957
return;
233087233958
}
@@ -233176,14 +234047,16 @@
233176234047
if( p->rc==SQLITE_OK ){
233177234048
memset(pIter, 0, sizeof(*pIter));
233178234049
fts5SegIterSetNext(p, pIter);
233179234050
pIter->pSeg = pSeg;
233180234051
pIter->iLeafPgno = pSeg->pgnoFirst-1;
233181
- fts5SegIterNextPage(p, pIter);
234052
+ do {
234053
+ fts5SegIterNextPage(p, pIter);
234054
+ }while( p->rc==SQLITE_OK && pIter->pLeaf && pIter->pLeaf->nn==4 );
233182234055
}
233183234056
233184
- if( p->rc==SQLITE_OK ){
234057
+ if( p->rc==SQLITE_OK && pIter->pLeaf ){
233185234058
pIter->iLeafOffset = 4;
233186234059
assert( pIter->pLeaf!=0 );
233187234060
assert_nc( pIter->pLeaf->nn>4 );
233188234061
assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
233189234062
pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
@@ -233373,11 +234246,11 @@
233373234246
233374234247
ASSERT_SZLEAF_OK(pIter->pLeaf);
233375234248
iOff = pIter->iLeafOffset;
233376234249
233377234250
/* Next entry is on the next page */
233378
- if( pIter->pSeg && iOff>=pIter->pLeaf->szLeaf ){
234251
+ while( pIter->pSeg && iOff>=pIter->pLeaf->szLeaf ){
233379234252
fts5SegIterNextPage(p, pIter);
233380234253
if( p->rc || pIter->pLeaf==0 ) return;
233381234254
pIter->iRowid = 0;
233382234255
iOff = 4;
233383234256
}
@@ -233566,11 +234439,11 @@
233566234439
static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
233567234440
Fts5DlidxIter *pDlidx = pIter->pDlidx;
233568234441
Fts5Data *pLast = 0;
233569234442
int pgnoLast = 0;
233570234443
233571
- if( pDlidx ){
234444
+ if( pDlidx && p->pConfig->iVersion==FTS5_CURRENT_VERSION ){
233572234445
int iSegid = pIter->pSeg->iSegid;
233573234446
pgnoLast = fts5DlidxIterPgno(pDlidx);
233574234447
pLast = fts5LeafRead(p, FTS5_SEGMENT_ROWID(iSegid, pgnoLast));
233575234448
}else{
233576234449
Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
@@ -234127,11 +235000,12 @@
234127235000
return 0;
234128235001
}
234129235002
234130235003
/*
234131235004
** Move the seg-iter so that it points to the first rowid on page iLeafPgno.
234132
-** It is an error if leaf iLeafPgno does not exist or contains no rowids.
235005
+** It is an error if leaf iLeafPgno does not exist. Unless the db is
235006
+** a 'secure-delete' db, if it contains no rowids then this is also an error.
234133235007
*/
234134235008
static void fts5SegIterGotoPage(
234135235009
Fts5Index *p, /* FTS5 backend object */
234136235010
Fts5SegIter *pIter, /* Iterator to advance */
234137235011
int iLeafPgno
@@ -234142,25 +235016,27 @@
234142235016
p->rc = FTS5_CORRUPT;
234143235017
}else{
234144235018
fts5DataRelease(pIter->pNextLeaf);
234145235019
pIter->pNextLeaf = 0;
234146235020
pIter->iLeafPgno = iLeafPgno-1;
234147
- fts5SegIterNextPage(p, pIter);
234148
- assert( p->rc!=SQLITE_OK || pIter->iLeafPgno==iLeafPgno );
234149235021
234150
- if( p->rc==SQLITE_OK && ALWAYS(pIter->pLeaf!=0) ){
235022
+ while( p->rc==SQLITE_OK ){
234151235023
int iOff;
234152
- u8 *a = pIter->pLeaf->p;
234153
- int n = pIter->pLeaf->szLeaf;
234154
-
235024
+ fts5SegIterNextPage(p, pIter);
235025
+ if( pIter->pLeaf==0 ) break;
234155235026
iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
234156
- if( iOff<4 || iOff>=n ){
234157
- p->rc = FTS5_CORRUPT;
234158
- }else{
234159
- iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
234160
- pIter->iLeafOffset = iOff;
234161
- fts5SegIterLoadNPos(p, pIter);
235027
+ if( iOff>0 ){
235028
+ u8 *a = pIter->pLeaf->p;
235029
+ int n = pIter->pLeaf->szLeaf;
235030
+ if( iOff<4 || iOff>=n ){
235031
+ p->rc = FTS5_CORRUPT;
235032
+ }else{
235033
+ iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
235034
+ pIter->iLeafOffset = iOff;
235035
+ fts5SegIterLoadNPos(p, pIter);
235036
+ }
235037
+ break;
234162235038
}
234163235039
}
234164235040
}
234165235041
}
234166235042
@@ -234871,11 +235747,11 @@
234871235747
/* Allocate space for the new multi-seg-iterator. */
234872235748
if( p->rc==SQLITE_OK ){
234873235749
if( iLevel<0 ){
234874235750
assert( pStruct->nSegment==fts5StructureCountSegments(pStruct) );
234875235751
nSeg = pStruct->nSegment;
234876
- nSeg += (p->pHash ? 1 : 0);
235752
+ nSeg += (p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH));
234877235753
}else{
234878235754
nSeg = MIN(pStruct->aLevel[iLevel].nSeg, nSegment);
234879235755
}
234880235756
}
234881235757
*ppOut = pNew = fts5MultiIterAlloc(p, nSeg);
@@ -234892,11 +235768,11 @@
234892235768
234893235769
/* Initialize each of the component segment iterators. */
234894235770
if( p->rc==SQLITE_OK ){
234895235771
if( iLevel<0 ){
234896235772
Fts5StructureLevel *pEnd = &pStruct->aLevel[pStruct->nLevel];
234897
- if( p->pHash ){
235773
+ if( p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH) ){
234898235774
/* Add a segment iterator for the current contents of the hash table. */
234899235775
Fts5SegIter *pIter = &pNew->aSeg[iIter++];
234900235776
fts5SegIterHashInit(p, pTerm, nTerm, flags, pIter);
234901235777
}
234902235778
for(pLvl=&pStruct->aLevel[0]; pLvl<pEnd; pLvl++){
@@ -235647,11 +236523,11 @@
235647236523
fts5BufferZero(&buf);
235648236524
fts5BufferGrow(&p->rc, &buf, pData->nn);
235649236525
fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
235650236526
fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
235651236527
fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
235652
- fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff,&pData->p[iOff]);
236528
+ fts5BufferAppendBlob(&p->rc, &buf,pData->szLeaf-iOff,&pData->p[iOff]);
235653236529
if( p->rc==SQLITE_OK ){
235654236530
/* Set the szLeaf field */
235655236531
fts5PutU16(&buf.p[2], (u16)buf.n);
235656236532
}
235657236533
@@ -235925,20 +236801,20 @@
235925236801
Fts5Index *p, /* FTS5 backend object */
235926236802
Fts5Structure **ppStruct /* IN/OUT: Current structure of index */
235927236803
){
235928236804
const int nCrisis = p->pConfig->nCrisisMerge;
235929236805
Fts5Structure *pStruct = *ppStruct;
235930
- int iLvl = 0;
235931
-
235932
- assert( p->rc!=SQLITE_OK || pStruct->nLevel>0 );
235933
- while( p->rc==SQLITE_OK && pStruct->aLevel[iLvl].nSeg>=nCrisis ){
235934
- fts5IndexMergeLevel(p, &pStruct, iLvl, 0);
235935
- assert( p->rc!=SQLITE_OK || pStruct->nLevel>(iLvl+1) );
235936
- fts5StructurePromote(p, iLvl+1, pStruct);
235937
- iLvl++;
235938
- }
235939
- *ppStruct = pStruct;
236806
+ if( pStruct && pStruct->nLevel>0 ){
236807
+ int iLvl = 0;
236808
+ while( p->rc==SQLITE_OK && pStruct->aLevel[iLvl].nSeg>=nCrisis ){
236809
+ fts5IndexMergeLevel(p, &pStruct, iLvl, 0);
236810
+ assert( p->rc!=SQLITE_OK || pStruct->nLevel>(iLvl+1) );
236811
+ fts5StructurePromote(p, iLvl+1, pStruct);
236812
+ iLvl++;
236813
+ }
236814
+ *ppStruct = pStruct;
236815
+ }
235940236816
}
235941236817
235942236818
static int fts5IndexReturn(Fts5Index *p){
235943236819
int rc = p->rc;
235944236820
p->rc = SQLITE_OK;
@@ -235967,10 +236843,417 @@
235967236843
ret += i;
235968236844
}
235969236845
}
235970236846
return ret;
235971236847
}
236848
+
236849
+/*
236850
+** Execute the SQL statement:
236851
+**
236852
+** DELETE FROM %_idx WHERE (segid, (pgno/2)) = ($iSegid, $iPgno);
236853
+**
236854
+** This is used when a secure-delete operation removes the last term
236855
+** from a segment leaf page. In that case the %_idx entry is removed
236856
+** too. This is done to ensure that if all instances of a token are
236857
+** removed from an fts5 database in secure-delete mode, no trace of
236858
+** the token itself remains in the database.
236859
+*/
236860
+static void fts5SecureDeleteIdxEntry(
236861
+ Fts5Index *p, /* FTS5 backend object */
236862
+ int iSegid, /* Id of segment to delete entry for */
236863
+ int iPgno /* Page number within segment */
236864
+){
236865
+ if( iPgno!=1 ){
236866
+ assert( p->pConfig->iVersion==FTS5_CURRENT_VERSION_SECUREDELETE );
236867
+ if( p->pDeleteFromIdx==0 ){
236868
+ fts5IndexPrepareStmt(p, &p->pDeleteFromIdx, sqlite3_mprintf(
236869
+ "DELETE FROM '%q'.'%q_idx' WHERE (segid, (pgno/2)) = (?1, ?2)",
236870
+ p->pConfig->zDb, p->pConfig->zName
236871
+ ));
236872
+ }
236873
+ if( p->rc==SQLITE_OK ){
236874
+ sqlite3_bind_int(p->pDeleteFromIdx, 1, iSegid);
236875
+ sqlite3_bind_int(p->pDeleteFromIdx, 2, iPgno);
236876
+ sqlite3_step(p->pDeleteFromIdx);
236877
+ p->rc = sqlite3_reset(p->pDeleteFromIdx);
236878
+ }
236879
+ }
236880
+}
236881
+
236882
+/*
236883
+** This is called when a secure-delete operation removes a position-list
236884
+** that overflows onto segment page iPgno of segment pSeg. This function
236885
+** rewrites node iPgno, and possibly one or more of its right-hand peers,
236886
+** to remove this portion of the position list.
236887
+**
236888
+** Output variable (*pbLastInDoclist) is set to true if the position-list
236889
+** removed is followed by a new term or the end-of-segment, or false if
236890
+** it is followed by another rowid/position list.
236891
+*/
236892
+static void fts5SecureDeleteOverflow(
236893
+ Fts5Index *p,
236894
+ Fts5StructureSegment *pSeg,
236895
+ int iPgno,
236896
+ int *pbLastInDoclist
236897
+){
236898
+ const int bDetailNone = (p->pConfig->eDetail==FTS5_DETAIL_NONE);
236899
+ int pgno;
236900
+ Fts5Data *pLeaf = 0;
236901
+ assert( iPgno!=1 );
236902
+
236903
+ *pbLastInDoclist = 1;
236904
+ for(pgno=iPgno; p->rc==SQLITE_OK && pgno<=pSeg->pgnoLast; pgno++){
236905
+ i64 iRowid = FTS5_SEGMENT_ROWID(pSeg->iSegid, pgno);
236906
+ int iNext = 0;
236907
+ u8 *aPg = 0;
236908
+
236909
+ pLeaf = fts5DataRead(p, iRowid);
236910
+ if( pLeaf==0 ) break;
236911
+ aPg = pLeaf->p;
236912
+
236913
+ iNext = fts5GetU16(&aPg[0]);
236914
+ if( iNext!=0 ){
236915
+ *pbLastInDoclist = 0;
236916
+ }
236917
+ if( iNext==0 && pLeaf->szLeaf!=pLeaf->nn ){
236918
+ fts5GetVarint32(&aPg[pLeaf->szLeaf], iNext);
236919
+ }
236920
+
236921
+ if( iNext==0 ){
236922
+ /* The page contains no terms or rowids. Replace it with an empty
236923
+ ** page and move on to the right-hand peer. */
236924
+ const u8 aEmpty[] = {0x00, 0x00, 0x00, 0x04};
236925
+ assert_nc( bDetailNone==0 || pLeaf->nn==4 );
236926
+ if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty));
236927
+ fts5DataRelease(pLeaf);
236928
+ pLeaf = 0;
236929
+ }else if( bDetailNone ){
236930
+ break;
236931
+ }else if( iNext>=pLeaf->szLeaf || iNext<4 ){
236932
+ p->rc = FTS5_CORRUPT;
236933
+ break;
236934
+ }else{
236935
+ int nShift = iNext - 4;
236936
+ int nPg;
236937
+
236938
+ int nIdx = 0;
236939
+ u8 *aIdx = 0;
236940
+
236941
+ /* Unless the current page footer is 0 bytes in size (in which case
236942
+ ** the new page footer will be as well), allocate and populate a
236943
+ ** buffer containing the new page footer. Set stack variables aIdx
236944
+ ** and nIdx accordingly. */
236945
+ if( pLeaf->nn>pLeaf->szLeaf ){
236946
+ int iFirst = 0;
236947
+ int i1 = pLeaf->szLeaf;
236948
+ int i2 = 0;
236949
+
236950
+ aIdx = sqlite3Fts5MallocZero(&p->rc, (pLeaf->nn-pLeaf->szLeaf)+2);
236951
+ if( aIdx==0 ) break;
236952
+ i1 += fts5GetVarint32(&aPg[i1], iFirst);
236953
+ i2 = sqlite3Fts5PutVarint(aIdx, iFirst-nShift);
236954
+ if( i1<pLeaf->nn ){
236955
+ memcpy(&aIdx[i2], &aPg[i1], pLeaf->nn-i1);
236956
+ i2 += (pLeaf->nn-i1);
236957
+ }
236958
+ nIdx = i2;
236959
+ }
236960
+
236961
+ /* Modify the contents of buffer aPg[]. Set nPg to the new size
236962
+ ** in bytes. The new page is always smaller than the old. */
236963
+ nPg = pLeaf->szLeaf - nShift;
236964
+ memmove(&aPg[4], &aPg[4+nShift], nPg-4);
236965
+ fts5PutU16(&aPg[2], nPg);
236966
+ if( fts5GetU16(&aPg[0]) ) fts5PutU16(&aPg[0], 4);
236967
+ if( nIdx>0 ){
236968
+ memcpy(&aPg[nPg], aIdx, nIdx);
236969
+ nPg += nIdx;
236970
+ }
236971
+ sqlite3_free(aIdx);
236972
+
236973
+ /* Write the new page to disk and exit the loop */
236974
+ assert( nPg>4 || fts5GetU16(aPg)==0 );
236975
+ fts5DataWrite(p, iRowid, aPg, nPg);
236976
+ break;
236977
+ }
236978
+ }
236979
+ fts5DataRelease(pLeaf);
236980
+}
236981
+
236982
+/*
236983
+** Completely remove the entry that pSeg currently points to from
236984
+** the database.
236985
+*/
236986
+static void fts5DoSecureDelete(
236987
+ Fts5Index *p,
236988
+ Fts5SegIter *pSeg
236989
+){
236990
+ const int bDetailNone = (p->pConfig->eDetail==FTS5_DETAIL_NONE);
236991
+ int iSegid = pSeg->pSeg->iSegid;
236992
+ u8 *aPg = pSeg->pLeaf->p;
236993
+ int nPg = pSeg->pLeaf->nn;
236994
+ int iPgIdx = pSeg->pLeaf->szLeaf;
236995
+
236996
+ u64 iDelta = 0;
236997
+ u64 iNextDelta = 0;
236998
+ int iNextOff = 0;
236999
+ int iOff = 0;
237000
+ int nIdx = 0;
237001
+ u8 *aIdx = 0;
237002
+ int bLastInDoclist = 0;
237003
+ int iIdx = 0;
237004
+ int iStart = 0;
237005
+ int iKeyOff = 0;
237006
+ int iPrevKeyOff = 0;
237007
+ int iDelKeyOff = 0; /* Offset of deleted key, if any */
237008
+
237009
+ nIdx = nPg-iPgIdx;
237010
+ aIdx = sqlite3Fts5MallocZero(&p->rc, nIdx+16);
237011
+ if( p->rc ) return;
237012
+ memcpy(aIdx, &aPg[iPgIdx], nIdx);
237013
+
237014
+ /* At this point segment iterator pSeg points to the entry
237015
+ ** this function should remove from the b-tree segment.
237016
+ **
237017
+ ** In detail=full or detail=column mode, pSeg->iLeafOffset is the
237018
+ ** offset of the first byte in the position-list for the entry to
237019
+ ** remove. Immediately before this comes two varints that will also
237020
+ ** need to be removed:
237021
+ **
237022
+ ** + the rowid or delta rowid value for the entry, and
237023
+ ** + the size of the position list in bytes.
237024
+ **
237025
+ ** Or, in detail=none mode, there is a single varint prior to
237026
+ ** pSeg->iLeafOffset - the rowid or delta rowid value.
237027
+ **
237028
+ ** This block sets the following variables:
237029
+ **
237030
+ ** iStart:
237031
+ ** iDelta:
237032
+ */
237033
+ {
237034
+ int iSOP;
237035
+ if( pSeg->iLeafPgno==pSeg->iTermLeafPgno ){
237036
+ iStart = pSeg->iTermLeafOffset;
237037
+ }else{
237038
+ iStart = fts5GetU16(&aPg[0]);
237039
+ }
237040
+
237041
+ iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta);
237042
+ assert_nc( iSOP<=pSeg->iLeafOffset );
237043
+
237044
+ if( bDetailNone ){
237045
+ while( iSOP<pSeg->iLeafOffset ){
237046
+ if( aPg[iSOP]==0x00 ) iSOP++;
237047
+ if( aPg[iSOP]==0x00 ) iSOP++;
237048
+ iStart = iSOP;
237049
+ iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta);
237050
+ }
237051
+
237052
+ iNextOff = iSOP;
237053
+ if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
237054
+ if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
237055
+
237056
+ }else{
237057
+ int nPos = 0;
237058
+ iSOP += fts5GetVarint32(&aPg[iSOP], nPos);
237059
+ while( iSOP<pSeg->iLeafOffset ){
237060
+ iStart = iSOP + (nPos/2);
237061
+ iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta);
237062
+ iSOP += fts5GetVarint32(&aPg[iSOP], nPos);
237063
+ }
237064
+ assert_nc( iSOP==pSeg->iLeafOffset );
237065
+ iNextOff = pSeg->iLeafOffset + pSeg->nPos;
237066
+ }
237067
+ }
237068
+
237069
+ iOff = iStart;
237070
+ if( iNextOff>=iPgIdx ){
237071
+ int pgno = pSeg->iLeafPgno+1;
237072
+ fts5SecureDeleteOverflow(p, pSeg->pSeg, pgno, &bLastInDoclist);
237073
+ iNextOff = iPgIdx;
237074
+ }else{
237075
+ /* Set bLastInDoclist to true if the entry being removed is the last
237076
+ ** in its doclist. */
237077
+ for(iIdx=0, iKeyOff=0; iIdx<nIdx; /* no-op */){
237078
+ u32 iVal = 0;
237079
+ iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
237080
+ iKeyOff += iVal;
237081
+ if( iKeyOff==iNextOff ){
237082
+ bLastInDoclist = 1;
237083
+ }
237084
+ }
237085
+ }
237086
+
237087
+ if( fts5GetU16(&aPg[0])==iStart && (bLastInDoclist||iNextOff==iPgIdx) ){
237088
+ fts5PutU16(&aPg[0], 0);
237089
+ }
237090
+
237091
+ if( bLastInDoclist==0 ){
237092
+ if( iNextOff!=iPgIdx ){
237093
+ iNextOff += fts5GetVarint(&aPg[iNextOff], &iNextDelta);
237094
+ iOff += sqlite3Fts5PutVarint(&aPg[iOff], iDelta + iNextDelta);
237095
+ }
237096
+ }else if(
237097
+ iStart==pSeg->iTermLeafOffset && pSeg->iLeafPgno==pSeg->iTermLeafPgno
237098
+ ){
237099
+ /* The entry being removed was the only position list in its
237100
+ ** doclist. Therefore the term needs to be removed as well. */
237101
+ int iKey = 0;
237102
+ for(iIdx=0, iKeyOff=0; iIdx<nIdx; iKey++){
237103
+ u32 iVal = 0;
237104
+ iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
237105
+ if( (iKeyOff+iVal)>(u32)iStart ) break;
237106
+ iKeyOff += iVal;
237107
+ }
237108
+
237109
+ iDelKeyOff = iOff = iKeyOff;
237110
+ if( iNextOff!=iPgIdx ){
237111
+ int nPrefix = 0;
237112
+ int nSuffix = 0;
237113
+ int nPrefix2 = 0;
237114
+ int nSuffix2 = 0;
237115
+
237116
+ iDelKeyOff = iNextOff;
237117
+ iNextOff += fts5GetVarint32(&aPg[iNextOff], nPrefix2);
237118
+ iNextOff += fts5GetVarint32(&aPg[iNextOff], nSuffix2);
237119
+
237120
+ if( iKey!=1 ){
237121
+ iKeyOff += fts5GetVarint32(&aPg[iKeyOff], nPrefix);
237122
+ }
237123
+ iKeyOff += fts5GetVarint32(&aPg[iKeyOff], nSuffix);
237124
+
237125
+ nPrefix = MIN(nPrefix, nPrefix2);
237126
+ nSuffix = (nPrefix2 + nSuffix2) - nPrefix;
237127
+
237128
+ if( (iKeyOff+nSuffix)>iPgIdx || (iNextOff+nSuffix2)>iPgIdx ){
237129
+ p->rc = FTS5_CORRUPT;
237130
+ }else{
237131
+ if( iKey!=1 ){
237132
+ iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
237133
+ }
237134
+ iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
237135
+ if( nPrefix2>nPrefix ){
237136
+ memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
237137
+ iOff += (nPrefix2-nPrefix);
237138
+ }
237139
+ memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
237140
+ iOff += nSuffix2;
237141
+ iNextOff += nSuffix2;
237142
+ }
237143
+ }
237144
+ }else if( iStart==4 ){
237145
+ int iPgno;
237146
+
237147
+ assert_nc( pSeg->iLeafPgno>pSeg->iTermLeafPgno );
237148
+ /* The entry being removed may be the only position list in
237149
+ ** its doclist. */
237150
+ for(iPgno=pSeg->iLeafPgno-1; iPgno>pSeg->iTermLeafPgno; iPgno-- ){
237151
+ Fts5Data *pPg = fts5DataRead(p, FTS5_SEGMENT_ROWID(iSegid, iPgno));
237152
+ int bEmpty = (pPg && pPg->nn==4);
237153
+ fts5DataRelease(pPg);
237154
+ if( bEmpty==0 ) break;
237155
+ }
237156
+
237157
+ if( iPgno==pSeg->iTermLeafPgno ){
237158
+ i64 iId = FTS5_SEGMENT_ROWID(iSegid, pSeg->iTermLeafPgno);
237159
+ Fts5Data *pTerm = fts5DataRead(p, iId);
237160
+ if( pTerm && pTerm->szLeaf==pSeg->iTermLeafOffset ){
237161
+ u8 *aTermIdx = &pTerm->p[pTerm->szLeaf];
237162
+ int nTermIdx = pTerm->nn - pTerm->szLeaf;
237163
+ int iTermIdx = 0;
237164
+ int iTermOff = 0;
237165
+
237166
+ while( 1 ){
237167
+ u32 iVal = 0;
237168
+ int nByte = fts5GetVarint32(&aTermIdx[iTermIdx], iVal);
237169
+ iTermOff += iVal;
237170
+ if( (iTermIdx+nByte)>=nTermIdx ) break;
237171
+ iTermIdx += nByte;
237172
+ }
237173
+ nTermIdx = iTermIdx;
237174
+
237175
+ memmove(&pTerm->p[iTermOff], &pTerm->p[pTerm->szLeaf], nTermIdx);
237176
+ fts5PutU16(&pTerm->p[2], iTermOff);
237177
+
237178
+ fts5DataWrite(p, iId, pTerm->p, iTermOff+nTermIdx);
237179
+ if( nTermIdx==0 ){
237180
+ fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iTermLeafPgno);
237181
+ }
237182
+ }
237183
+ fts5DataRelease(pTerm);
237184
+ }
237185
+ }
237186
+
237187
+ if( p->rc==SQLITE_OK ){
237188
+ const int nMove = nPg - iNextOff;
237189
+ int nShift = 0;
237190
+
237191
+ memmove(&aPg[iOff], &aPg[iNextOff], nMove);
237192
+ iPgIdx -= (iNextOff - iOff);
237193
+ nPg = iPgIdx;
237194
+ fts5PutU16(&aPg[2], iPgIdx);
237195
+
237196
+ nShift = iNextOff - iOff;
237197
+ for(iIdx=0, iKeyOff=0, iPrevKeyOff=0; iIdx<nIdx; /* no-op */){
237198
+ u32 iVal = 0;
237199
+ iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
237200
+ iKeyOff += iVal;
237201
+ if( iKeyOff!=iDelKeyOff ){
237202
+ if( iKeyOff>iOff ){
237203
+ iKeyOff -= nShift;
237204
+ nShift = 0;
237205
+ }
237206
+ nPg += sqlite3Fts5PutVarint(&aPg[nPg], iKeyOff - iPrevKeyOff);
237207
+ iPrevKeyOff = iKeyOff;
237208
+ }
237209
+ }
237210
+
237211
+ if( iPgIdx==nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
237212
+ fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iLeafPgno);
237213
+ }
237214
+
237215
+ assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
237216
+ fts5DataWrite(p, FTS5_SEGMENT_ROWID(iSegid,pSeg->iLeafPgno), aPg,nPg);
237217
+ }
237218
+ sqlite3_free(aIdx);
237219
+}
237220
+
237221
+/*
237222
+** This is called as part of flushing a delete to disk in 'secure-delete'
237223
+** mode. It edits the segments within the database described by argument
237224
+** pStruct to remove the entries for term zTerm, rowid iRowid.
237225
+*/
237226
+static void fts5FlushSecureDelete(
237227
+ Fts5Index *p,
237228
+ Fts5Structure *pStruct,
237229
+ const char *zTerm,
237230
+ i64 iRowid
237231
+){
237232
+ const int f = FTS5INDEX_QUERY_SKIPHASH;
237233
+ int nTerm = (int)strlen(zTerm);
237234
+ Fts5Iter *pIter = 0; /* Used to find term instance */
237235
+
237236
+ fts5MultiIterNew(p, pStruct, f, 0, (const u8*)zTerm, nTerm, -1, 0, &pIter);
237237
+ if( fts5MultiIterEof(p, pIter)==0 ){
237238
+ i64 iThis = fts5MultiIterRowid(pIter);
237239
+ if( iThis<iRowid ){
237240
+ fts5MultiIterNextFrom(p, pIter, iRowid);
237241
+ }
237242
+
237243
+ if( p->rc==SQLITE_OK
237244
+ && fts5MultiIterEof(p, pIter)==0
237245
+ && iRowid==fts5MultiIterRowid(pIter)
237246
+ ){
237247
+ Fts5SegIter *pSeg = &pIter->aSeg[pIter->aFirst[1].iFirst];
237248
+ fts5DoSecureDelete(p, pSeg);
237249
+ }
237250
+ }
237251
+
237252
+ fts5MultiIterFree(pIter);
237253
+}
237254
+
235972237255
235973237256
/*
235974237257
** Flush the contents of in-memory hash table iHash to a new level-0
235975237258
** segment on disk. Also update the corresponding structure record.
235976237259
**
@@ -235990,10 +237273,11 @@
235990237273
fts5StructureInvalidate(p);
235991237274
235992237275
if( iSegid ){
235993237276
const int pgsz = p->pConfig->pgsz;
235994237277
int eDetail = p->pConfig->eDetail;
237278
+ int bSecureDelete = p->pConfig->bSecureDelete;
235995237279
Fts5StructureSegment *pSeg; /* New segment within pStruct */
235996237280
Fts5Buffer *pBuf; /* Buffer in which to assemble leaf page */
235997237281
Fts5Buffer *pPgidx; /* Buffer in which to assemble pgidx */
235998237282
235999237283
Fts5SegWriter writer;
@@ -236012,44 +237296,81 @@
236012237296
if( p->rc==SQLITE_OK ){
236013237297
p->rc = sqlite3Fts5HashScanInit(pHash, 0, 0);
236014237298
}
236015237299
while( p->rc==SQLITE_OK && 0==sqlite3Fts5HashScanEof(pHash) ){
236016237300
const char *zTerm; /* Buffer containing term */
237301
+ int nTerm; /* Size of zTerm in bytes */
236017237302
const u8 *pDoclist; /* Pointer to doclist for this term */
236018237303
int nDoclist; /* Size of doclist in bytes */
236019237304
236020
- /* Write the term for this entry to disk. */
237305
+ /* Get the term and doclist for this entry. */
236021237306
sqlite3Fts5HashScanEntry(pHash, &zTerm, &pDoclist, &nDoclist);
236022
- fts5WriteAppendTerm(p, &writer, (int)strlen(zTerm), (const u8*)zTerm);
236023
- if( p->rc!=SQLITE_OK ) break;
237307
+ nTerm = (int)strlen(zTerm);
237308
+ if( bSecureDelete==0 ){
237309
+ fts5WriteAppendTerm(p, &writer, nTerm, (const u8*)zTerm);
237310
+ if( p->rc!=SQLITE_OK ) break;
237311
+ assert( writer.bFirstRowidInPage==0 );
237312
+ }
236024237313
236025
- assert( writer.bFirstRowidInPage==0 );
236026
- if( pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){
237314
+ if( !bSecureDelete && pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){
236027237315
/* The entire doclist will fit on the current leaf. */
236028237316
fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist);
236029237317
}else{
237318
+ int bTermWritten = !bSecureDelete;
236030237319
i64 iRowid = 0;
236031
- u64 iDelta = 0;
237320
+ i64 iPrev = 0;
236032237321
int iOff = 0;
236033237322
236034237323
/* The entire doclist will not fit on this leaf. The following
236035237324
** loop iterates through the poslists that make up the current
236036237325
** doclist. */
236037237326
while( p->rc==SQLITE_OK && iOff<nDoclist ){
237327
+ u64 iDelta = 0;
236038237328
iOff += fts5GetVarint(&pDoclist[iOff], &iDelta);
236039237329
iRowid += iDelta;
237330
+
237331
+ /* If in secure delete mode, and if this entry in the poslist is
237332
+ ** in fact a delete, then edit the existing segments directly
237333
+ ** using fts5FlushSecureDelete(). */
237334
+ if( bSecureDelete ){
237335
+ if( eDetail==FTS5_DETAIL_NONE ){
237336
+ if( iOff<nDoclist && pDoclist[iOff]==0x00 ){
237337
+ fts5FlushSecureDelete(p, pStruct, zTerm, iRowid);
237338
+ iOff++;
237339
+ if( iOff<nDoclist && pDoclist[iOff]==0x00 ){
237340
+ iOff++;
237341
+ nDoclist = 0;
237342
+ }else{
237343
+ continue;
237344
+ }
237345
+ }
237346
+ }else if( (pDoclist[iOff] & 0x01) ){
237347
+ fts5FlushSecureDelete(p, pStruct, zTerm, iRowid);
237348
+ if( p->rc!=SQLITE_OK || pDoclist[iOff]==0x01 ){
237349
+ iOff++;
237350
+ continue;
237351
+ }
237352
+ }
237353
+ }
237354
+
237355
+ if( p->rc==SQLITE_OK && bTermWritten==0 ){
237356
+ fts5WriteAppendTerm(p, &writer, nTerm, (const u8*)zTerm);
237357
+ bTermWritten = 1;
237358
+ assert( p->rc!=SQLITE_OK || writer.bFirstRowidInPage==0 );
237359
+ }
236040237360
236041237361
if( writer.bFirstRowidInPage ){
236042237362
fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
236043237363
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
236044237364
writer.bFirstRowidInPage = 0;
236045237365
fts5WriteDlidxAppend(p, &writer, iRowid);
236046
- if( p->rc!=SQLITE_OK ) break;
236047237366
}else{
236048
- pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iDelta);
237367
+ pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid-iPrev);
236049237368
}
237369
+ if( p->rc!=SQLITE_OK ) break;
236050237370
assert( pBuf->n<=pBuf->nSpace );
237371
+ iPrev = iRowid;
236051237372
236052237373
if( eDetail==FTS5_DETAIL_NONE ){
236053237374
if( iOff<nDoclist && pDoclist[iOff]==0 ){
236054237375
pBuf->p[pBuf->n++] = 0;
236055237376
iOff++;
@@ -236104,24 +237425,27 @@
236104237425
if( p->rc==SQLITE_OK ) sqlite3Fts5HashScanNext(pHash);
236105237426
}
236106237427
sqlite3Fts5HashClear(pHash);
236107237428
fts5WriteFinish(p, &writer, &pgnoLast);
236108237429
236109
- /* Update the Fts5Structure. It is written back to the database by the
236110
- ** fts5StructureRelease() call below. */
236111
- if( pStruct->nLevel==0 ){
236112
- fts5StructureAddLevel(&p->rc, &pStruct);
236113
- }
236114
- fts5StructureExtendLevel(&p->rc, pStruct, 0, 1, 0);
236115
- if( p->rc==SQLITE_OK ){
236116
- pSeg = &pStruct->aLevel[0].aSeg[ pStruct->aLevel[0].nSeg++ ];
236117
- pSeg->iSegid = iSegid;
236118
- pSeg->pgnoFirst = 1;
236119
- pSeg->pgnoLast = pgnoLast;
236120
- pStruct->nSegment++;
236121
- }
236122
- fts5StructurePromote(p, 0, pStruct);
237430
+ assert( p->rc!=SQLITE_OK || bSecureDelete || pgnoLast>0 );
237431
+ if( pgnoLast>0 ){
237432
+ /* Update the Fts5Structure. It is written back to the database by the
237433
+ ** fts5StructureRelease() call below. */
237434
+ if( pStruct->nLevel==0 ){
237435
+ fts5StructureAddLevel(&p->rc, &pStruct);
237436
+ }
237437
+ fts5StructureExtendLevel(&p->rc, pStruct, 0, 1, 0);
237438
+ if( p->rc==SQLITE_OK ){
237439
+ pSeg = &pStruct->aLevel[0].aSeg[ pStruct->aLevel[0].nSeg++ ];
237440
+ pSeg->iSegid = iSegid;
237441
+ pSeg->pgnoFirst = 1;
237442
+ pSeg->pgnoLast = pgnoLast;
237443
+ pStruct->nSegment++;
237444
+ }
237445
+ fts5StructurePromote(p, 0, pStruct);
237446
+ }
236123237447
}
236124237448
236125237449
fts5IndexAutomerge(p, &pStruct, pgnoLast);
236126237450
fts5IndexCrisismerge(p, &pStruct);
236127237451
fts5StructureWrite(p, pStruct);
@@ -236858,10 +238182,11 @@
236858238182
sqlite3_finalize(p->pDeleter);
236859238183
sqlite3_finalize(p->pIdxWriter);
236860238184
sqlite3_finalize(p->pIdxDeleter);
236861238185
sqlite3_finalize(p->pIdxSelect);
236862238186
sqlite3_finalize(p->pDataVersion);
238187
+ sqlite3_finalize(p->pDeleteFromIdx);
236863238188
sqlite3Fts5HashFree(p->pHash);
236864238189
sqlite3_free(p->zDataTbl);
236865238190
sqlite3_free(p);
236866238191
}
236867238192
return rc;
@@ -237488,10 +238813,11 @@
237488238813
static void fts5IndexIntegrityCheckSegment(
237489238814
Fts5Index *p, /* FTS5 backend object */
237490238815
Fts5StructureSegment *pSeg /* Segment to check internal consistency */
237491238816
){
237492238817
Fts5Config *pConfig = p->pConfig;
238818
+ int bSecureDelete = (pConfig->iVersion==FTS5_CURRENT_VERSION_SECUREDELETE);
237493238819
sqlite3_stmt *pStmt = 0;
237494238820
int rc2;
237495238821
int iIdxPrevLeaf = pSeg->pgnoFirst-1;
237496238822
int iDlidxPrevLeaf = pSeg->pgnoLast;
237497238823
@@ -237523,11 +238849,23 @@
237523238849
/* Check that the leaf contains at least one term, and that it is equal
237524238850
** to or larger than the split-key in zIdxTerm. Also check that if there
237525238851
** is also a rowid pointer within the leaf page header, it points to a
237526238852
** location before the term. */
237527238853
if( pLeaf->nn<=pLeaf->szLeaf ){
237528
- p->rc = FTS5_CORRUPT;
238854
+
238855
+ if( nIdxTerm==0
238856
+ && pConfig->iVersion==FTS5_CURRENT_VERSION_SECUREDELETE
238857
+ && pLeaf->nn==pLeaf->szLeaf
238858
+ && pLeaf->nn==4
238859
+ ){
238860
+ /* special case - the very first page in a segment keeps its %_idx
238861
+ ** entry even if all the terms are removed from it by secure-delete
238862
+ ** operations. */
238863
+ }else{
238864
+ p->rc = FTS5_CORRUPT;
238865
+ }
238866
+
237529238867
}else{
237530238868
int iOff; /* Offset of first term on leaf */
237531238869
int iRowidOff; /* Offset of first rowid on leaf */
237532238870
int nTerm; /* Size of term on leaf in bytes */
237533238871
int res; /* Comparison of term and split-key */
@@ -237587,13 +238925,16 @@
237587238925
i64 iRowid;
237588238926
int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
237589238927
ASSERT_SZLEAF_OK(pLeaf);
237590238928
if( iRowidOff>=pLeaf->szLeaf ){
237591238929
p->rc = FTS5_CORRUPT;
237592
- }else{
238930
+ }else if( bSecureDelete==0 || iRowidOff>0 ){
238931
+ i64 iDlRowid = fts5DlidxIterRowid(pDlidx);
237593238932
fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
237594
- if( iRowid!=fts5DlidxIterRowid(pDlidx) ) p->rc = FTS5_CORRUPT;
238933
+ if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
238934
+ p->rc = FTS5_CORRUPT;
238935
+ }
237595238936
}
237596238937
fts5DataRelease(pLeaf);
237597238938
}
237598238939
}
237599238940
@@ -239851,10 +241192,12 @@
239851241192
){
239852241193
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
239853241194
Fts5Config *pConfig = pTab->p.pConfig;
239854241195
int eType0; /* value_type() of apVal[0] */
239855241196
int rc = SQLITE_OK; /* Return code */
241197
+ int bUpdateOrDelete = 0;
241198
+
239856241199
239857241200
/* A transaction must be open when this is called. */
239858241201
assert( pTab->ts.eState==1 || pTab->ts.eState==2 );
239859241202
239860241203
assert( pVtab->zErrMsg==0 );
@@ -239861,10 +241204,15 @@
239861241204
assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
239862241205
assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
239863241206
|| sqlite3_value_type(apVal[0])==SQLITE_NULL
239864241207
);
239865241208
assert( pTab->p.pConfig->pzErrmsg==0 );
241209
+ if( pConfig->pgsz==0 ){
241210
+ rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
241211
+ if( rc!=SQLITE_OK ) return rc;
241212
+ }
241213
+
239866241214
pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
239867241215
239868241216
/* Put any active cursors into REQUIRE_SEEK state. */
239869241217
fts5TripCursors(pTab);
239870241218
@@ -239913,10 +241261,11 @@
239913241261
239914241262
/* DELETE */
239915241263
else if( nArg==1 ){
239916241264
i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */
239917241265
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0);
241266
+ bUpdateOrDelete = 1;
239918241267
}
239919241268
239920241269
/* INSERT or UPDATE */
239921241270
else{
239922241271
int eType1 = sqlite3_value_numeric_type(apVal[1]);
@@ -239928,10 +241277,11 @@
239928241277
else if( eType0!=SQLITE_INTEGER ){
239929241278
/* If this is a REPLACE, first remove the current entry (if any) */
239930241279
if( eConflict==SQLITE_REPLACE && eType1==SQLITE_INTEGER ){
239931241280
i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */
239932241281
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
241282
+ bUpdateOrDelete = 1;
239933241283
}
239934241284
fts5StorageInsert(&rc, pTab, apVal, pRowid);
239935241285
}
239936241286
239937241287
/* UPDATE */
@@ -239956,13 +241306,27 @@
239956241306
}
239957241307
}else{
239958241308
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
239959241309
fts5StorageInsert(&rc, pTab, apVal, pRowid);
239960241310
}
241311
+ bUpdateOrDelete = 1;
239961241312
}
239962241313
}
239963241314
}
241315
+
241316
+ if( rc==SQLITE_OK
241317
+ && bUpdateOrDelete
241318
+ && pConfig->bSecureDelete
241319
+ && pConfig->iVersion==FTS5_CURRENT_VERSION
241320
+ ){
241321
+ rc = sqlite3Fts5StorageConfigValue(
241322
+ pTab->pStorage, "version", 0, FTS5_CURRENT_VERSION_SECUREDELETE
241323
+ );
241324
+ if( rc==SQLITE_OK ){
241325
+ pConfig->iVersion = FTS5_CURRENT_VERSION_SECUREDELETE;
241326
+ }
241327
+ }
239964241328
239965241329
pTab->p.pConfig->pzErrmsg = 0;
239966241330
return rc;
239967241331
}
239968241332
@@ -240819,10 +242183,11 @@
240819242183
static int fts5RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
240820242184
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
240821242185
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
240822242186
fts5CheckTransactionState(pTab, FTS5_ROLLBACKTO, iSavepoint);
240823242187
fts5TripCursors(pTab);
242188
+ pTab->p.pConfig->pgsz = 0;
240824242189
return sqlite3Fts5StorageRollback(pTab->pStorage);
240825242190
}
240826242191
240827242192
/*
240828242193
** Register a new auxiliary function with global context pGlobal.
@@ -241021,11 +242386,11 @@
241021242386
int nArg, /* Number of args */
241022242387
sqlite3_value **apUnused /* Function arguments */
241023242388
){
241024242389
assert( nArg==0 );
241025242390
UNUSED_PARAM2(nArg, apUnused);
241026
- sqlite3_result_text(pCtx, "fts5: 2023-04-10 13:20:51 49ba030080dd00b4fdf788fd3da057b333e705fa0fe37d653e2461bf96ca3785", -1, SQLITE_TRANSIENT);
242391
+ sqlite3_result_text(pCtx, "fts5: 2023-05-01 20:09:52 62d703d83cf8cf3358715792347c49315a82c659e475158e385746f4329a4f39", -1, SQLITE_TRANSIENT);
241027242392
}
241028242393
241029242394
/*
241030242395
** Return true if zName is the extension on one of the shadow tables used
241031242396
** by this module.
241032242397
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -121,10 +121,14 @@
121 #if defined(_MSC_VER) && !defined(_WIN64)
122 #undef SQLITE_4_BYTE_ALIGNED_MALLOC
123 #define SQLITE_4_BYTE_ALIGNED_MALLOC
124 #endif /* defined(_MSC_VER) && !defined(_WIN64) */
125
 
 
 
 
126 #endif /* SQLITE_MSVC_H */
127
128 /************** End of msvc.h ************************************************/
129 /************** Continuing where we left off in sqliteInt.h ******************/
130
@@ -452,11 +456,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.42.0"
456 #define SQLITE_VERSION_NUMBER 3042000
457 #define SQLITE_SOURCE_ID "2023-04-10 18:44:00 4c5a3c5fb351cc1c2ce16c33314ce19c53531f09263f87456283d9d756002f9d"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -2702,29 +2706,29 @@
2702 ** additional information. This feature can also be turned on and off
2703 ** using the [PRAGMA legacy_alter_table] statement.
2704 ** </dd>
2705 **
2706 ** [[SQLITE_DBCONFIG_DQS_DML]]
2707 ** <dt>SQLITE_DBCONFIG_DQS_DML</td>
2708 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2709 ** the legacy [double-quoted string literal] misfeature for DML statements
2710 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2711 ** default value of this setting is determined by the [-DSQLITE_DQS]
2712 ** compile-time option.
2713 ** </dd>
2714 **
2715 ** [[SQLITE_DBCONFIG_DQS_DDL]]
2716 ** <dt>SQLITE_DBCONFIG_DQS_DDL</td>
2717 ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
2718 ** the legacy [double-quoted string literal] misfeature for DDL statements,
2719 ** such as CREATE TABLE and CREATE INDEX. The
2720 ** default value of this setting is determined by the [-DSQLITE_DQS]
2721 ** compile-time option.
2722 ** </dd>
2723 **
2724 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2725 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2726 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2727 ** assume that database schemas are untainted by malicious content.
2728 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2729 ** takes additional defensive steps to protect the application from harm
2730 ** including:
@@ -2740,20 +2744,20 @@
2740 ** all applications are advised to turn it off if possible. This setting
2741 ** can also be controlled using the [PRAGMA trusted_schema] statement.
2742 ** </dd>
2743 **
2744 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2745 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
2746 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2747 ** the legacy file format flag. When activated, this flag causes all newly
2748 ** created database file to have a schema format version number (the 4-byte
2749 ** integer found at offset 44 into the database header) of 1. This in turn
2750 ** means that the resulting database file will be readable and writable by
2751 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2752 ** newly created databases are generally not understandable by SQLite versions
2753 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2754 ** is now scarcely any need to generated database files that are compatible
2755 ** all the way back to version 3.0.0, and so this setting is of little
2756 ** practical use, but is provided so that SQLite can continue to claim the
2757 ** ability to generate new database files that are compatible with version
2758 ** 3.0.0.
2759 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
@@ -2762,27 +2766,39 @@
2762 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2763 ** either generated columns or decending indexes.
2764 ** </dd>
2765 **
2766 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2767 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</td>
2768 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
2769 ** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
2770 ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2771 ** statistics. For statistics to be collected, the flag must be set on
2772 ** the database handle both when the SQL statement is prepared and when it
2773 ** is stepped. The flag is set (collection of statistics is enabled)
2774 ** by default.</dd>
 
 
 
 
 
 
2775 **
2776 ** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2777 ** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</td>
2778 ** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option change the default order
2779 ** in which tables and indexes are scanned so that the scans start at the end
2780 ** and work toward the beginning rather than starting at the beginning and
2781 ** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2782 ** same as setting [PRAGMA reverse_unordered_selects]. This configuration option
2783 ** is useful for application testing.</dd>
 
 
 
 
 
 
2784 **
2785 ** </dl>
2786 */
2787 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2788 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
@@ -2800,11 +2816,11 @@
2800 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
2801 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
2802 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
2803 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
2804 #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2805 #define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2806 #define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
2807 #define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
2808
2809 /*
2810 ** CAPI3REF: Enable Or Disable Extended Result Codes
@@ -11106,20 +11122,24 @@
11106 ** [sqlite3session_create()] for details.
11107 */
11108 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
11109
11110 /*
11111 ** CAPIREF: Conigure a Session Object
11112 ** METHOD: sqlite3_session
11113 **
11114 ** This method is used to configure a session object after it has been
11115 ** created. At present the only valid value for the second parameter is
11116 ** [SQLITE_SESSION_OBJCONFIG_SIZE].
11117 **
11118 ** Arguments for sqlite3session_object_config()
 
 
 
 
11119 **
11120 ** The following values may passed as the the 4th parameter to
11121 ** sqlite3session_object_config().
11122 **
11123 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
11124 ** This option is used to set, clear or query the flag that enables
11125 ** the [sqlite3session_changeset_size()] API. Because it imposes some
@@ -11131,16 +11151,25 @@
11131 ** variable is set to 1 if the sqlite3session_changeset_size() API is
11132 ** enabled following the current call, or 0 otherwise.
11133 **
11134 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11135 ** the first table has been attached to the session object.
 
 
 
 
 
 
 
 
 
 
 
 
11136 */
11137 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11138
11139 /*
11140 */
11141 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
11142
11143 /*
11144 ** CAPI3REF: Enable Or Disable A Session Object
11145 ** METHOD: sqlite3_session
11146 **
@@ -13652,11 +13681,11 @@
13652 # define SQLITE_INLINE __forceinline
13653 #else
13654 # define SQLITE_NOINLINE
13655 # define SQLITE_INLINE
13656 #endif
13657 #if defined(SQLITE_COVERAGE_TEST)
13658 # undef SQLITE_INLINE
13659 # define SQLITE_INLINE
13660 #endif
13661
13662 /*
@@ -20020,19 +20049,23 @@
20020 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
20021 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
20022 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
20023 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
20024 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
 
 
20025 #else
20026 # define sqlite3Toupper(x) toupper((unsigned char)(x))
20027 # define sqlite3Isspace(x) isspace((unsigned char)(x))
20028 # define sqlite3Isalnum(x) isalnum((unsigned char)(x))
20029 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
20030 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
20031 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
20032 # define sqlite3Tolower(x) tolower((unsigned char)(x))
20033 # define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
 
 
20034 #endif
20035 SQLITE_PRIVATE int sqlite3IsIdChar(u8);
20036
20037 /*
20038 ** Internal function prototypes
@@ -22161,11 +22194,11 @@
22161 ** isalpha() 0x02
22162 ** isdigit() 0x04
22163 ** isalnum() 0x06
22164 ** isxdigit() 0x08
22165 ** toupper() 0x20
22166 ** SQLite identifier character 0x40
22167 ** Quote character 0x80
22168 **
22169 ** Bit 0x20 is set if the mapped character requires translation to upper
22170 ** case. i.e. if the character is a lower-case ASCII character.
22171 ** If x is a lower-case ASCII character, then its upper-case equivalent
@@ -34434,17 +34467,19 @@
34434 }else{
34435 x = v;
34436 }
34437 i = sizeof(zTemp)-2;
34438 zTemp[sizeof(zTemp)-1] = 0;
34439 do{
34440 zTemp[i--] = (x%10) + '0';
34441 x = x/10;
34442 }while( x );
34443 if( v<0 ) zTemp[i--] = '-';
34444 memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i);
34445 return sizeof(zTemp)-2-i;
 
 
34446 }
34447
34448 /*
34449 ** Compare the 19-character string zNum against the text representation
34450 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -34605,11 +34640,13 @@
34605 for(i=2; z[i]=='0'; i++){}
34606 for(k=i; sqlite3Isxdigit(z[k]); k++){
34607 u = u*16 + sqlite3HexToInt(z[k]);
34608 }
34609 memcpy(pOut, &u, 8);
34610 return (z[k]==0 && k-i<=16) ? 0 : 2;
 
 
34611 }else
34612 #endif /* SQLITE_OMIT_HEX_INTEGER */
34613 {
34614 return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8);
34615 }
@@ -34641,11 +34678,11 @@
34641 && sqlite3Isxdigit(zNum[2])
34642 ){
34643 u32 u = 0;
34644 zNum += 2;
34645 while( zNum[0]=='0' ) zNum++;
34646 for(i=0; sqlite3Isxdigit(zNum[i]) && i<8; i++){
34647 u = u*16 + sqlite3HexToInt(zNum[i]);
34648 }
34649 if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){
34650 memcpy(pValue, &u, 4);
34651 return 1;
@@ -37137,11 +37174,11 @@
37137 # define SQLITE_ENABLE_LOCKING_STYLE 0
37138 # endif
37139 #endif
37140
37141 /* Use pread() and pwrite() if they are available */
37142 #if defined(__APPLE__)
37143 # define HAVE_PREAD 1
37144 # define HAVE_PWRITE 1
37145 #endif
37146 #if defined(HAVE_PREAD64) && defined(HAVE_PWRITE64)
37147 # undef USE_PREAD
@@ -40387,16 +40424,10 @@
40387
40388 /*
40389 ** Seek to the offset passed as the second argument, then read cnt
40390 ** bytes into pBuf. Return the number of bytes actually read.
40391 **
40392 ** NB: If you define USE_PREAD or USE_PREAD64, then it might also
40393 ** be necessary to define _XOPEN_SOURCE to be 500. This varies from
40394 ** one system to another. Since SQLite does not define USE_PREAD
40395 ** in any form by default, we will not attempt to define _XOPEN_SOURCE.
40396 ** See tickets #2741 and #2681.
40397 **
40398 ** To avoid stomping the errno value on a failed read the lastErrno value
40399 ** is set before returning.
40400 */
40401 static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
40402 int got;
@@ -50419,11 +50450,11 @@
50419 &extendedParameters);
50420 if( h!=INVALID_HANDLE_VALUE ) break;
50421 if( isReadWrite ){
50422 int rc2, isRO = 0;
50423 sqlite3BeginBenignMalloc();
50424 rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
50425 sqlite3EndBenignMalloc();
50426 if( rc2==SQLITE_OK && isRO ) break;
50427 }
50428 }while( winRetryIoerr(&cnt, &lastErrno) );
50429 #else
@@ -50436,11 +50467,11 @@
50436 NULL);
50437 if( h!=INVALID_HANDLE_VALUE ) break;
50438 if( isReadWrite ){
50439 int rc2, isRO = 0;
50440 sqlite3BeginBenignMalloc();
50441 rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
50442 sqlite3EndBenignMalloc();
50443 if( rc2==SQLITE_OK && isRO ) break;
50444 }
50445 }while( winRetryIoerr(&cnt, &lastErrno) );
50446 #endif
@@ -50456,11 +50487,11 @@
50456 NULL);
50457 if( h!=INVALID_HANDLE_VALUE ) break;
50458 if( isReadWrite ){
50459 int rc2, isRO = 0;
50460 sqlite3BeginBenignMalloc();
50461 rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
50462 sqlite3EndBenignMalloc();
50463 if( rc2==SQLITE_OK && isRO ) break;
50464 }
50465 }while( winRetryIoerr(&cnt, &lastErrno) );
50466 }
@@ -50678,10 +50709,17 @@
50678 UNUSED_PARAMETER(pVfs);
50679
50680 SimulateIOError( return SQLITE_IOERR_ACCESS; );
50681 OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
50682 zFilename, flags, pResOut));
 
 
 
 
 
 
 
50683
50684 zConverted = winConvertFromUtf8Filename(zFilename);
50685 if( zConverted==0 ){
50686 OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
50687 return SQLITE_IOERR_NOMEM_BKPT;
@@ -52835,15 +52873,19 @@
52835 # define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
52836 static void pcachePageTrace(int i, sqlite3_pcache_page *pLower){
52837 PgHdr *pPg;
52838 unsigned char *a;
52839 int j;
52840 pPg = (PgHdr*)pLower->pExtra;
52841 printf("%3lld: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
52842 a = (unsigned char *)pLower->pBuf;
52843 for(j=0; j<12; j++) printf("%02x", a[j]);
52844 printf(" ptr %p\n", pPg);
 
 
 
 
52845 }
52846 static void pcacheDump(PCache *pCache){
52847 int N;
52848 int i;
52849 sqlite3_pcache_page *pLower;
@@ -52852,13 +52894,12 @@
52852 if( pCache->pCache==0 ) return;
52853 N = sqlite3PcachePagecount(pCache);
52854 if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
52855 for(i=1; i<=N; i++){
52856 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
52857 if( pLower==0 ) continue;
52858 pcachePageTrace(i, pLower);
52859 if( ((PgHdr*)pLower)->pPage==0 ){
52860 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
52861 }
52862 }
52863 }
52864 #else
@@ -58242,10 +58283,12 @@
58242 */
58243 static int pager_truncate(Pager *pPager, Pgno nPage){
58244 int rc = SQLITE_OK;
58245 assert( pPager->eState!=PAGER_ERROR );
58246 assert( pPager->eState!=PAGER_READER );
 
 
58247
58248 if( isOpen(pPager->fd)
58249 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
58250 ){
58251 i64 currentSize, newSize;
@@ -61159,10 +61202,14 @@
61159
61160 assert( !isOpen(pPager->fd) || !MEMDB );
61161 if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
61162 if( pgno>pPager->mxPgno ){
61163 rc = SQLITE_FULL;
 
 
 
 
61164 goto pager_acquire_err;
61165 }
61166 if( noContent ){
61167 /* Failure to set the bits in the InJournal bit-vectors is benign.
61168 ** It merely means that we might do some extra work to journal a
@@ -61323,14 +61370,16 @@
61323 }
61324
61325 /*
61326 ** Release a page reference.
61327 **
61328 ** The sqlite3PagerUnref() and sqlite3PagerUnrefNotNull() may only be
61329 ** used if we know that the page being released is not the last page.
61330 ** The btree layer always holds page1 open until the end, so these first
61331 ** to routines can be used to release any page other than BtShared.pPage1.
 
 
61332 **
61333 ** Use sqlite3PagerUnrefPageOne() to release page1. This latter routine
61334 ** checks the total number of outstanding pages and if the number of
61335 ** pages reaches zero it drops the database lock.
61336 */
@@ -61342,11 +61391,11 @@
61342 pagerReleaseMapPage(pPg);
61343 }else{
61344 sqlite3PcacheRelease(pPg);
61345 }
61346 /* Do not use this routine to release the last reference to page1 */
61347 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 );
61348 }
61349 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
61350 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
61351 }
61352 SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *pPg){
@@ -64113,23 +64162,44 @@
64113 }
64114
64115 assert( nByte>=8 );
64116 assert( (nByte&0x00000007)==0 );
64117 assert( nByte<=65536 );
 
64118
64119 if( nativeCksum ){
64120 do {
64121 s1 += *aData++ + s2;
64122 s2 += *aData++ + s1;
64123 }while( aData<aEnd );
64124 }else{
64125 do {
64126 s1 += BYTESWAP32(aData[0]) + s2;
64127 s2 += BYTESWAP32(aData[1]) + s1;
64128 aData += 2;
64129 }while( aData<aEnd );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64130 }
 
64131
64132 aOut[0] = s1;
64133 aOut[1] = s2;
64134 }
64135
@@ -76202,11 +76272,11 @@
76202 aAfter[j] = iAfter;
76203 break;
76204 }
76205 }
76206 if( j>=nFree ){
76207 if( nFree>=sizeof(aOfst)/sizeof(aOfst[0]) ){
76208 for(j=0; j<nFree; j++){
76209 freeSpace(pPg, aOfst[j], aAfter[j]-aOfst[j]);
76210 }
76211 nFree = 0;
76212 }
@@ -77907,11 +77977,11 @@
77907 return btreeOverwriteCell(pCur, &x2);
77908 }
77909 }
77910 }
77911 assert( pCur->eState==CURSOR_VALID
77912 || (pCur->eState==CURSOR_INVALID && loc) );
77913
77914 pPage = pCur->pPage;
77915 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
77916 assert( pPage->leaf || !pPage->intKey );
77917 if( pPage->nFree<0 ){
@@ -80157,17 +80227,11 @@
80157 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
80158 assert( p->bDestLocked );
80159 assert( !isFatalError(p->rc) );
80160 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
80161 assert( zSrcData );
80162
80163 /* Catch the case where the destination is an in-memory database and the
80164 ** page sizes of the source and destination differ.
80165 */
80166 if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){
80167 rc = SQLITE_READONLY;
80168 }
80169
80170 /* This loop runs once for each destination page spanned by the source
80171 ** page. For each iteration, variable iOff is set to the byte offset
80172 ** of the destination page.
80173 */
@@ -80296,11 +80360,14 @@
80296 /* Do not allow backup if the destination database is in WAL mode
80297 ** and the page sizes are different between source and destination */
80298 pgszSrc = sqlite3BtreeGetPageSize(p->pSrc);
80299 pgszDest = sqlite3BtreeGetPageSize(p->pDest);
80300 destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p->pDest));
80301 if( SQLITE_OK==rc && destMode==PAGER_JOURNALMODE_WAL && pgszSrc!=pgszDest ){
 
 
 
80302 rc = SQLITE_READONLY;
80303 }
80304
80305 /* Now that there is a read-lock on the source database, query the
80306 ** source pager for the number of pages in the database.
@@ -80845,10 +80912,11 @@
80845 Mem tmp;
80846 char zBuf[100];
80847 char *z;
80848 int i, j, incr;
80849 if( (p->flags & MEM_Str)==0 ) return 1;
 
80850 if( p->flags & MEM_Term ){
80851 /* Insure that the string is properly zero-terminated. Pay particular
80852 ** attention to the case where p->n is odd */
80853 if( p->szMalloc>0 && p->z==p->zMalloc ){
80854 assert( p->enc==SQLITE_UTF8 || p->szMalloc >= ((p->n+1)&~1)+2 );
@@ -83508,10 +83576,12 @@
83508 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
83509 int nMaxArgs = *pMaxFuncArgs;
83510 Op *pOp;
83511 Parse *pParse = p->pParse;
83512 int *aLabel = pParse->aLabel;
 
 
83513 p->readOnly = 1;
83514 p->bIsReader = 0;
83515 pOp = &p->aOp[p->nOp-1];
83516 assert( p->aOp[0].opcode==OP_Init );
83517 while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
@@ -83567,10 +83637,11 @@
83567 /* The mkopcodeh.tcl script has so arranged things that the only
83568 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
83569 ** have non-negative values for P2. */
83570 assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
83571 assert( ADDR(pOp->p2)<-pParse->nLabel );
 
83572 pOp->p2 = aLabel[ADDR(pOp->p2)];
83573 }
83574 break;
83575 }
83576 }
@@ -84310,11 +84381,11 @@
84310 }
84311 }
84312
84313 /* Return the most recently added opcode
84314 */
84315 VdbeOp * sqlite3VdbeGetLastOp(Vdbe *p){
84316 return sqlite3VdbeGetOp(p, p->nOp - 1);
84317 }
84318
84319 #if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
84320 /*
@@ -88039,10 +88110,20 @@
88039 sqlite3 *db = v->db;
88040 i64 iKey2;
88041 PreUpdate preupdate;
88042 const char *zTbl = pTab->zName;
88043 static const u8 fakeSortOrder = 0;
 
 
 
 
 
 
 
 
 
 
88044
88045 assert( db->pPreUpdate==0 );
88046 memset(&preupdate, 0, sizeof(PreUpdate));
88047 if( HasRowid(pTab)==0 ){
88048 iKey1 = iKey2 = 0;
@@ -88055,12 +88136,12 @@
88055 }
88056 }
88057
88058 assert( pCsr!=0 );
88059 assert( pCsr->eCurType==CURTYPE_BTREE );
88060 assert( pCsr->nField==pTab->nCol
88061 || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1)
88062 );
88063
88064 preupdate.v = v;
88065 preupdate.pCsr = pCsr;
88066 preupdate.op = op;
@@ -89429,13 +89510,13 @@
89429 p = (Vdbe *)pStmt;
89430 db = p->db;
89431 assert( db!=0 );
89432 n = sqlite3_column_count(pStmt);
89433 if( N<n && N>=0 ){
 
89434 N += useType*n;
89435 sqlite3_mutex_enter(db->mutex);
89436 assert( db->mallocFailed==0 );
89437 #ifndef SQLITE_OMIT_UTF16
89438 if( useUtf16 ){
89439 ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
89440 }else
89441 #endif
@@ -89443,11 +89524,12 @@
89443 ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
89444 }
89445 /* A malloc may have failed inside of the _text() call. If this
89446 ** is the case, clear the mallocFailed flag and return NULL.
89447 */
89448 if( db->mallocFailed ){
 
89449 sqlite3OomClear(db);
89450 ret = 0;
89451 }
89452 sqlite3_mutex_leave(db->mutex);
89453 }
@@ -93333,11 +93415,11 @@
93333 */
93334 case OP_IfNullRow: { /* jump */
93335 VdbeCursor *pC;
93336 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
93337 pC = p->apCsr[pOp->p1];
93338 if( ALWAYS(pC) && pC->nullRow ){
93339 sqlite3VdbeMemSetNull(aMem + pOp->p3);
93340 goto jump_to_p2;
93341 }
93342 break;
93343 }
@@ -93828,11 +93910,11 @@
93828 pIn1->flags |= MEM_IntReal;
93829 pIn1->flags &= ~MEM_Int;
93830 }else{
93831 pIn1->u.r = (double)pIn1->u.i;
93832 pIn1->flags |= MEM_Real;
93833 pIn1->flags &= ~MEM_Int;
93834 }
93835 }
93836 REGISTER_TRACE((int)(pIn1-aMem), pIn1);
93837 zAffinity++;
93838 if( zAffinity[0]==0 ) break;
@@ -107198,28 +107280,31 @@
107198
107199 /*
107200 ** Join two expressions using an AND operator. If either expression is
107201 ** NULL, then just return the other expression.
107202 **
107203 ** If one side or the other of the AND is known to be false, then instead
107204 ** of returning an AND expression, just return a constant expression with
107205 ** a value of false.
107206 */
107207 SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
107208 sqlite3 *db = pParse->db;
107209 if( pLeft==0 ){
107210 return pRight;
107211 }else if( pRight==0 ){
107212 return pLeft;
107213 }else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight))
107214 && !IN_RENAME_OBJECT
107215 ){
107216 sqlite3ExprDeferredDelete(pParse, pLeft);
107217 sqlite3ExprDeferredDelete(pParse, pRight);
107218 return sqlite3Expr(db, TK_INTEGER, "0");
107219 }else{
107220 return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
 
 
 
 
 
 
 
 
 
107221 }
107222 }
107223
107224 /*
107225 ** Construct a new expression node for a function with multiple
@@ -112373,11 +112458,11 @@
112373 int iAgg = pExpr->iAgg;
112374 Parse *pParse = pWalker->pParse;
112375 sqlite3 *db = pParse->db;
112376 assert( iAgg>=0 );
112377 if( pExpr->op!=TK_AGG_FUNCTION ){
112378 if( ALWAYS(iAgg<pAggInfo->nColumn)
112379 && pAggInfo->aCol[iAgg].pCExpr==pExpr
112380 ){
112381 pExpr = sqlite3ExprDup(db, pExpr, 0);
112382 if( pExpr ){
112383 pAggInfo->aCol[iAgg].pCExpr = pExpr;
@@ -112578,11 +112663,11 @@
112578 findOrCreateAggInfoColumn(pParse, pAggInfo, pExpr);
112579 break;
112580 } /* endif pExpr->iTable==pItem->iCursor */
112581 } /* end loop over pSrcList */
112582 }
112583 return WRC_Prune;
112584 }
112585 case TK_AGG_FUNCTION: {
112586 if( (pNC->ncFlags & NC_InAggFunc)==0
112587 && pWalker->walkerDepth==pExpr->op2
112588 ){
@@ -114075,10 +114160,23 @@
114075 }
114076
114077 sqlite3_free(zQuot);
114078 return rc;
114079 }
 
 
 
 
 
 
 
 
 
 
 
 
 
114080
114081 /*
114082 ** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
114083 ** it was read from the schema of database zDb. Return SQLITE_OK if
114084 ** successful. Otherwise, return an SQLite error code and leave an error
@@ -114123,11 +114221,21 @@
114123 if( pSel==0 ){
114124 pStep->pExprList = 0;
114125 pSrc = 0;
114126 rc = SQLITE_NOMEM;
114127 }else{
 
 
 
 
 
 
 
 
 
114128 sqlite3SelectPrep(pParse, pSel, 0);
 
114129 rc = pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
114130 assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
114131 assert( pSrc==pSel->pSrc );
114132 if( pStep->pExprList ) pSel->pEList = 0;
114133 pSel->pSrc = 0;
@@ -116952,11 +117060,11 @@
116952 assert( db->lookaside.bDisable );
116953 if( (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0
116954 && IsOrdinaryTable(pStat4)
116955 ){
116956 rc = loadStatTbl(db,
116957 "SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx",
116958 "SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4",
116959 zDb
116960 );
116961 }
116962 return rc;
@@ -129027,26 +129135,26 @@
129027 zFrom = pFKey->pFrom->zName;
129028 nFrom = sqlite3Strlen30(zFrom);
129029
129030 if( action==OE_Restrict ){
129031 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
129032 Token tFrom;
129033 Token tDb;
129034 Expr *pRaise;
129035
129036 tFrom.z = zFrom;
129037 tFrom.n = nFrom;
129038 tDb.z = db->aDb[iDb].zDbSName;
129039 tDb.n = sqlite3Strlen30(tDb.z);
129040
129041 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
129042 if( pRaise ){
129043 pRaise->affExpr = OE_Abort;
129044 }
 
 
 
 
 
 
129045 pSelect = sqlite3SelectNew(pParse,
129046 sqlite3ExprListAppend(pParse, 0, pRaise),
129047 sqlite3SrcListAppend(pParse, 0, &tDb, &tFrom),
129048 pWhere,
129049 0, 0, 0, 0, 0
129050 );
129051 pWhere = 0;
129052 }
@@ -137995,11 +138103,13 @@
137995 encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
137996 if( encoding==0 ) encoding = SQLITE_UTF8;
137997 #else
137998 encoding = SQLITE_UTF8;
137999 #endif
138000 if( db->nVdbeActive>0 && encoding!=ENC(db) ){
 
 
138001 rc = SQLITE_LOCKED;
138002 goto initone_error_out;
138003 }else{
138004 sqlite3SetTextEncoding(db, encoding);
138005 }
@@ -138389,11 +138499,15 @@
138389 sParse.pOuterParse = db->pParse;
138390 db->pParse = &sParse;
138391 sParse.db = db;
138392 sParse.pReprepare = pReprepare;
138393 assert( ppStmt && *ppStmt==0 );
138394 if( db->mallocFailed ) sqlite3ErrorMsg(&sParse, "out of memory");
 
 
 
 
138395 assert( sqlite3_mutex_held(db->mutex) );
138396
138397 /* For a long-term use prepared statement avoid the use of
138398 ** lookaside memory.
138399 */
@@ -141079,11 +141193,11 @@
141079
141080 assert( pSelect!=0 );
141081 assert( (pSelect->selFlags & SF_Resolved)!=0 );
141082 assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
141083 assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
141084 if( db->mallocFailed ) return;
141085 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
141086 a = pSelect->pEList->a;
141087 memset(&sNC, 0, sizeof(sNC));
141088 sNC.pSrcList = pSelect->pSrc;
141089 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
@@ -141124,22 +141238,20 @@
141124 if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
141125 zType = sqlite3StdType[j];
141126 break;
141127 }
141128 }
141129 }
141130 }
141131 if( zType ){
141132 i64 m = sqlite3Strlen30(zType);
141133 n = sqlite3Strlen30(pCol->zCnName);
141134 pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
141135 if( pCol->zCnName ){
141136 memcpy(&pCol->zCnName[n+1], zType, m+1);
141137 pCol->colFlags |= COLFLAG_HASTYPE;
141138 }else{
141139 testcase( pCol->colFlags & COLFLAG_HASTYPE );
141140 pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
141141 }
141142 }
141143 pColl = sqlite3ExprCollSeq(pParse, p);
141144 if( pColl ){
141145 assert( pTab->pIndex==0 );
@@ -144027,15 +144139,17 @@
144027 if( pX->pPrior && pX->op!=TK_ALL ){
144028 /* This optimization does not work for compound subqueries that
144029 ** use UNION, INTERSECT, or EXCEPT. Only UNION ALL is allowed. */
144030 return 0;
144031 }
 
144032 if( pX->pWin ){
144033 /* This optimization does not work for subqueries that use window
144034 ** functions. */
144035 return 0;
144036 }
 
144037 }
144038 colUsed = pItem->colUsed;
144039 if( pSub->pOrderBy ){
144040 ExprList *pList = pSub->pOrderBy;
144041 for(j=0; j<pList->nExpr; j++){
@@ -145207,16 +145321,17 @@
145207 assert( pAggInfo->iFirstReg==0 );
145208 assert( pSelect!=0 );
145209 assert( pSelect->pGroupBy!=0 );
145210 pAggInfo->nColumn = pAggInfo->nAccumulator;
145211 if( ALWAYS(pAggInfo->nSortingColumn>0) ){
145212 if( pAggInfo->nColumn==0 ){
145213 pAggInfo->nSortingColumn = pSelect->pGroupBy->nExpr;
145214 }else{
145215 pAggInfo->nSortingColumn =
145216 pAggInfo->aCol[pAggInfo->nColumn-1].iSorterColumn+1;
145217 }
 
145218 }
145219 analyzeAggFuncArgs(pAggInfo, pNC);
145220 #if TREETRACE_ENABLED
145221 if( sqlite3TreeTrace & 0x20 ){
145222 IndexedExpr *pIEpr;
@@ -153970,11 +154085,11 @@
153970 /* If we survive all prior tests, that means this term is worth hinting */
153971 pExpr = sqlite3ExprAnd(pParse, pExpr, sqlite3ExprDup(db, pTerm->pExpr, 0));
153972 }
153973 if( pExpr!=0 ){
153974 sWalker.xExprCallback = codeCursorHintFixExpr;
153975 sqlite3WalkExpr(&sWalker, pExpr);
153976 sqlite3VdbeAddOp4(v, OP_CursorHint,
153977 (sHint.pIdx ? sHint.iIdxCur : sHint.iTabCur), 0, 0,
153978 (const char*)pExpr, P4_EXPR);
153979 }
153980 }
@@ -163480,26 +163595,49 @@
163480 if( pSelect && pSelect->pLimit ){
163481 sqlite3WhereAddLimit(&pWInfo->sWC, pSelect);
163482 }
163483 if( pParse->nErr ) goto whereBeginError;
163484
163485 /* Special case: WHERE terms that do not refer to any tables in the join
163486 ** (constant expressions). Evaluate each such term, and jump over all the
163487 ** generated code if the result is not true.
163488 **
163489 ** Do not do this if the expression contains non-deterministic functions
163490 ** that are not within a sub-select. This is not strictly required, but
163491 ** preserves SQLite's legacy behaviour in the following two cases:
163492 **
163493 ** FROM ... WHERE random()>0; -- eval random() once per row
163494 ** FROM ... WHERE (SELECT random())>0; -- eval random() once overall
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163495 */
163496 for(ii=0; ii<sWLB.pWC->nBase; ii++){
163497 WhereTerm *pT = &sWLB.pWC->a[ii];
 
163498 if( pT->wtFlags & TERM_VIRTUAL ) continue;
163499 if( pT->prereqAll==0 && (nTabList==0 || exprIsDeterministic(pT->pExpr)) ){
163500 sqlite3ExprIfFalse(pParse, pT->pExpr, pWInfo->iBreak, SQLITE_JUMPIFNULL);
 
 
 
 
 
 
 
163501 pT->wtFlags |= TERM_CODED;
163502 }
163503 }
163504
163505 if( wctrlFlags & WHERE_WANT_DISTINCT ){
@@ -165072,10 +165210,11 @@
165072 }
165073 }
165074 }
165075 /* no break */ deliberate_fall_through
165076
 
165077 case TK_AGG_FUNCTION:
165078 case TK_COLUMN: {
165079 int iCol = -1;
165080 if( pParse->db->mallocFailed ) return WRC_Abort;
165081 if( p->pSub ){
@@ -167902,11 +168041,11 @@
167902 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
167903 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
167904 #define YYFALLBACK 1
167905 #define YYNSTATE 575
167906 #define YYNRULE 403
167907 #define YYNRULE_WITH_ACTION 341
167908 #define YYNTOKEN 185
167909 #define YY_MAX_SHIFT 574
167910 #define YY_MIN_SHIFTREDUCE 833
167911 #define YY_MAX_SHIFTREDUCE 1235
167912 #define YY_ERROR_ACTION 1236
@@ -167982,145 +168121,145 @@
167982 *********** Begin parsing tables **********************************************/
167983 #define YY_ACTTAB_COUNT (2096)
167984 static const YYACTIONTYPE yy_action[] = {
167985 /* 0 */ 568, 208, 568, 118, 115, 229, 568, 118, 115, 229,
167986 /* 10 */ 568, 1310, 377, 1289, 408, 562, 562, 562, 568, 409,
167987 /* 20 */ 378, 1310, 1272, 41, 41, 41, 41, 208, 1521, 71,
167988 /* 30 */ 71, 969, 419, 41, 41, 491, 303, 279, 303, 970,
167989 /* 40 */ 397, 71, 71, 125, 126, 80, 1213, 1213, 1047, 1050,
167990 /* 50 */ 1037, 1037, 123, 123, 124, 124, 124, 124, 476, 409,
167991 /* 60 */ 1237, 1, 1, 574, 2, 1241, 550, 118, 115, 229,
167992 /* 70 */ 317, 480, 146, 480, 524, 118, 115, 229, 529, 1323,
167993 /* 80 */ 417, 523, 142, 125, 126, 80, 1213, 1213, 1047, 1050,
167994 /* 90 */ 1037, 1037, 123, 123, 124, 124, 124, 124, 118, 115,
167995 /* 100 */ 229, 327, 122, 122, 122, 122, 121, 121, 120, 120,
167996 /* 110 */ 120, 119, 116, 444, 284, 284, 284, 284, 442, 442,
167997 /* 120 */ 442, 1562, 376, 1564, 1189, 375, 1160, 565, 1160, 565,
167998 /* 130 */ 409, 1562, 537, 259, 226, 444, 101, 145, 449, 316,
167999 /* 140 */ 559, 240, 122, 122, 122, 122, 121, 121, 120, 120,
168000 /* 150 */ 120, 119, 116, 444, 125, 126, 80, 1213, 1213, 1047,
168001 /* 160 */ 1050, 1037, 1037, 123, 123, 124, 124, 124, 124, 142,
168002 /* 170 */ 294, 1189, 339, 448, 120, 120, 120, 119, 116, 444,
168003 /* 180 */ 127, 1189, 1190, 1189, 148, 441, 440, 568, 119, 116,
168004 /* 190 */ 444, 124, 124, 124, 124, 117, 122, 122, 122, 122,
168005 /* 200 */ 121, 121, 120, 120, 120, 119, 116, 444, 454, 113,
168006 /* 210 */ 13, 13, 546, 122, 122, 122, 122, 121, 121, 120,
168007 /* 220 */ 120, 120, 119, 116, 444, 422, 316, 559, 1189, 1190,
168008 /* 230 */ 1189, 149, 1220, 409, 1220, 124, 124, 124, 124, 122,
168009 /* 240 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
168010 /* 250 */ 444, 465, 342, 1034, 1034, 1048, 1051, 125, 126, 80,
168011 /* 260 */ 1213, 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124,
168012 /* 270 */ 124, 124, 1275, 522, 222, 1189, 568, 409, 224, 514,
168013 /* 280 */ 175, 82, 83, 122, 122, 122, 122, 121, 121, 120,
168014 /* 290 */ 120, 120, 119, 116, 444, 1005, 16, 16, 1189, 133,
168015 /* 300 */ 133, 125, 126, 80, 1213, 1213, 1047, 1050, 1037, 1037,
168016 /* 310 */ 123, 123, 124, 124, 124, 124, 122, 122, 122, 122,
168017 /* 320 */ 121, 121, 120, 120, 120, 119, 116, 444, 1038, 546,
168018 /* 330 */ 1189, 373, 1189, 1190, 1189, 252, 1429, 399, 504, 501,
168019 /* 340 */ 500, 111, 560, 566, 4, 924, 924, 433, 499, 340,
168020 /* 350 */ 460, 328, 360, 394, 1233, 1189, 1190, 1189, 563, 568,
168021 /* 360 */ 122, 122, 122, 122, 121, 121, 120, 120, 120, 119,
168022 /* 370 */ 116, 444, 284, 284, 369, 1575, 1601, 441, 440, 154,
168023 /* 380 */ 409, 445, 71, 71, 1282, 565, 1217, 1189, 1190, 1189,
168024 /* 390 */ 85, 1219, 271, 557, 543, 515, 1556, 568, 98, 1218,
168025 /* 400 */ 6, 1274, 472, 142, 125, 126, 80, 1213, 1213, 1047,
168026 /* 410 */ 1050, 1037, 1037, 123, 123, 124, 124, 124, 124, 550,
168027 /* 420 */ 13, 13, 1024, 507, 1220, 1189, 1220, 549, 109, 109,
168028 /* 430 */ 222, 568, 1234, 175, 568, 427, 110, 197, 445, 569,
168029 /* 440 */ 445, 430, 1547, 1014, 325, 551, 1189, 270, 287, 368,
168030 /* 450 */ 510, 363, 509, 257, 71, 71, 543, 71, 71, 359,
168031 /* 460 */ 316, 559, 1607, 122, 122, 122, 122, 121, 121, 120,
168032 /* 470 */ 120, 120, 119, 116, 444, 1014, 1014, 1016, 1017, 27,
168033 /* 480 */ 284, 284, 1189, 1190, 1189, 1155, 568, 1606, 409, 899,
168034 /* 490 */ 190, 550, 356, 565, 550, 935, 533, 517, 1155, 516,
168035 /* 500 */ 413, 1155, 552, 1189, 1190, 1189, 568, 544, 1549, 51,
168036 /* 510 */ 51, 214, 125, 126, 80, 1213, 1213, 1047, 1050, 1037,
168037 /* 520 */ 1037, 123, 123, 124, 124, 124, 124, 1189, 474, 135,
168038 /* 530 */ 135, 409, 284, 284, 1485, 505, 121, 121, 120, 120,
168039 /* 540 */ 120, 119, 116, 444, 1005, 565, 518, 217, 541, 1556,
168040 /* 550 */ 316, 559, 142, 6, 532, 125, 126, 80, 1213, 1213,
168041 /* 560 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168042 /* 570 */ 1550, 122, 122, 122, 122, 121, 121, 120, 120, 120,
168043 /* 580 */ 119, 116, 444, 485, 1189, 1190, 1189, 482, 281, 1263,
168044 /* 590 */ 955, 252, 1189, 373, 504, 501, 500, 1189, 340, 570,
168045 /* 600 */ 1189, 570, 409, 292, 499, 955, 874, 191, 480, 316,
168046 /* 610 */ 559, 384, 290, 380, 122, 122, 122, 122, 121, 121,
168047 /* 620 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1213,
168048 /* 630 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168049 /* 640 */ 124, 409, 394, 1133, 1189, 867, 100, 284, 284, 1189,
168050 /* 650 */ 1190, 1189, 373, 1090, 1189, 1190, 1189, 1189, 1190, 1189,
168051 /* 660 */ 565, 455, 32, 373, 233, 125, 126, 80, 1213, 1213,
168052 /* 670 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168053 /* 680 */ 1428, 957, 568, 228, 956, 122, 122, 122, 122, 121,
168054 /* 690 */ 121, 120, 120, 120, 119, 116, 444, 1155, 228, 1189,
168055 /* 700 */ 157, 1189, 1190, 1189, 1548, 13, 13, 301, 955, 1228,
168056 /* 710 */ 1155, 153, 409, 1155, 373, 1578, 1173, 5, 369, 1575,
168057 /* 720 */ 429, 1234, 3, 955, 122, 122, 122, 122, 121, 121,
168058 /* 730 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1213,
168059 /* 740 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168060 /* 750 */ 124, 409, 208, 567, 1189, 1025, 1189, 1190, 1189, 1189,
168061 /* 760 */ 388, 850, 155, 1547, 286, 402, 1095, 1095, 488, 568,
168062 /* 770 */ 465, 342, 1315, 1315, 1547, 125, 126, 80, 1213, 1213,
168063 /* 780 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168064 /* 790 */ 129, 568, 13, 13, 374, 122, 122, 122, 122, 121,
168065 /* 800 */ 121, 120, 120, 120, 119, 116, 444, 302, 568, 453,
168066 /* 810 */ 528, 1189, 1190, 1189, 13, 13, 1189, 1190, 1189, 1293,
168067 /* 820 */ 463, 1263, 409, 1313, 1313, 1547, 1010, 453, 452, 200,
168068 /* 830 */ 299, 71, 71, 1261, 122, 122, 122, 122, 121, 121,
168069 /* 840 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1213,
168070 /* 850 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168071 /* 860 */ 124, 409, 227, 1070, 1155, 284, 284, 419, 312, 278,
168072 /* 870 */ 278, 285, 285, 1415, 406, 405, 382, 1155, 565, 568,
168073 /* 880 */ 1155, 1192, 565, 1595, 565, 125, 126, 80, 1213, 1213,
168074 /* 890 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168075 /* 900 */ 453, 1477, 13, 13, 1531, 122, 122, 122, 122, 121,
168076 /* 910 */ 121, 120, 120, 120, 119, 116, 444, 201, 568, 354,
168077 /* 920 */ 1581, 574, 2, 1241, 838, 839, 840, 1557, 317, 1208,
168078 /* 930 */ 146, 6, 409, 255, 254, 253, 206, 1323, 9, 1192,
168079 /* 940 */ 262, 71, 71, 424, 122, 122, 122, 122, 121, 121,
168080 /* 950 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1213,
168081 /* 960 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168082 /* 970 */ 124, 568, 284, 284, 568, 1209, 409, 573, 313, 1241,
168083 /* 980 */ 349, 1292, 352, 419, 317, 565, 146, 491, 525, 1637,
168084 /* 990 */ 395, 371, 491, 1323, 70, 70, 1291, 71, 71, 240,
168085 /* 1000 */ 1321, 104, 80, 1213, 1213, 1047, 1050, 1037, 1037, 123,
168086 /* 1010 */ 123, 124, 124, 124, 124, 122, 122, 122, 122, 121,
168087 /* 1020 */ 121, 120, 120, 120, 119, 116, 444, 1111, 284, 284,
168088 /* 1030 */ 428, 448, 1520, 1209, 439, 284, 284, 1484, 1348, 311,
168089 /* 1040 */ 474, 565, 1112, 969, 491, 491, 217, 1259, 565, 1533,
168090 /* 1050 */ 568, 970, 207, 568, 1024, 240, 383, 1113, 519, 122,
168091 /* 1060 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
168092 /* 1070 */ 444, 1015, 107, 71, 71, 1014, 13, 13, 910, 568,
168093 /* 1080 */ 1490, 568, 284, 284, 97, 526, 491, 448, 911, 1322,
168094 /* 1090 */ 1318, 545, 409, 284, 284, 565, 151, 209, 1490, 1492,
168095 /* 1100 */ 262, 450, 55, 55, 56, 56, 565, 1014, 1014, 1016,
168096 /* 1110 */ 443, 332, 409, 527, 12, 295, 125, 126, 80, 1213,
168097 /* 1120 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168098 /* 1130 */ 124, 347, 409, 862, 1529, 1209, 125, 126, 80, 1213,
168099 /* 1140 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168100 /* 1150 */ 124, 1134, 1635, 474, 1635, 371, 125, 114, 80, 1213,
168101 /* 1160 */ 1213, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168102 /* 1170 */ 124, 1490, 329, 474, 331, 122, 122, 122, 122, 121,
168103 /* 1180 */ 121, 120, 120, 120, 119, 116, 444, 203, 1415, 568,
168104 /* 1190 */ 1290, 862, 464, 1209, 436, 122, 122, 122, 122, 121,
168105 /* 1200 */ 121, 120, 120, 120, 119, 116, 444, 553, 1134, 1636,
168106 /* 1210 */ 539, 1636, 15, 15, 890, 122, 122, 122, 122, 121,
168107 /* 1220 */ 121, 120, 120, 120, 119, 116, 444, 568, 298, 538,
168108 /* 1230 */ 1132, 1415, 1554, 1555, 1327, 409, 6, 6, 1166, 1264,
168109 /* 1240 */ 415, 320, 284, 284, 1415, 508, 565, 525, 300, 457,
168110 /* 1250 */ 43, 43, 568, 891, 12, 565, 330, 478, 425, 407,
168111 /* 1260 */ 126, 80, 1213, 1213, 1047, 1050, 1037, 1037, 123, 123,
168112 /* 1270 */ 124, 124, 124, 124, 568, 57, 57, 288, 1189, 1415,
168113 /* 1280 */ 496, 458, 392, 392, 391, 273, 389, 1132, 1553, 847,
168114 /* 1290 */ 1166, 407, 6, 568, 321, 1155, 470, 44, 44, 1552,
168115 /* 1300 */ 1111, 426, 234, 6, 323, 256, 540, 256, 1155, 431,
168116 /* 1310 */ 568, 1155, 322, 17, 487, 1112, 58, 58, 122, 122,
168117 /* 1320 */ 122, 122, 121, 121, 120, 120, 120, 119, 116, 444,
168118 /* 1330 */ 1113, 216, 481, 59, 59, 1189, 1190, 1189, 111, 560,
168119 /* 1340 */ 324, 4, 236, 456, 526, 568, 237, 456, 568, 437,
168120 /* 1350 */ 168, 556, 420, 141, 479, 563, 568, 293, 568, 1092,
168121 /* 1360 */ 568, 293, 568, 1092, 531, 568, 870, 8, 60, 60,
168122 /* 1370 */ 235, 61, 61, 568, 414, 568, 414, 568, 445, 62,
168123 /* 1380 */ 62, 45, 45, 46, 46, 47, 47, 199, 49, 49,
168124 /* 1390 */ 557, 568, 359, 568, 100, 486, 50, 50, 63, 63,
168125 /* 1400 */ 64, 64, 561, 415, 535, 410, 568, 1024, 568, 534,
168126 /* 1410 */ 316, 559, 316, 559, 65, 65, 14, 14, 568, 1024,
@@ -168127,73 +168266,73 @@
168127 /* 1420 */ 568, 512, 930, 870, 1015, 109, 109, 929, 1014, 66,
168128 /* 1430 */ 66, 131, 131, 110, 451, 445, 569, 445, 416, 177,
168129 /* 1440 */ 1014, 132, 132, 67, 67, 568, 467, 568, 930, 471,
168130 /* 1450 */ 1360, 283, 226, 929, 315, 1359, 407, 568, 459, 407,
168131 /* 1460 */ 1014, 1014, 1016, 239, 407, 86, 213, 1346, 52, 52,
168132 /* 1470 */ 68, 68, 1014, 1014, 1016, 1017, 27, 1580, 1177, 447,
168133 /* 1480 */ 69, 69, 288, 97, 108, 1536, 106, 392, 392, 391,
168134 /* 1490 */ 273, 389, 568, 877, 847, 881, 568, 111, 560, 466,
168135 /* 1500 */ 4, 568, 152, 30, 38, 568, 1129, 234, 396, 323,
168136 /* 1510 */ 111, 560, 527, 4, 563, 53, 53, 322, 568, 163,
168137 /* 1520 */ 163, 568, 337, 468, 164, 164, 333, 563, 76, 76,
168138 /* 1530 */ 568, 289, 1509, 568, 31, 1508, 568, 445, 338, 483,
168139 /* 1540 */ 100, 54, 54, 344, 72, 72, 296, 236, 1077, 557,
168140 /* 1550 */ 445, 877, 1356, 134, 134, 168, 73, 73, 141, 161,
168141 /* 1560 */ 161, 1569, 557, 535, 568, 319, 568, 348, 536, 1007,
168142 /* 1570 */ 473, 261, 261, 889, 888, 235, 535, 568, 1024, 568,
168143 /* 1580 */ 475, 534, 261, 367, 109, 109, 521, 136, 136, 130,
168144 /* 1590 */ 130, 1024, 110, 366, 445, 569, 445, 109, 109, 1014,
168145 /* 1600 */ 162, 162, 156, 156, 568, 110, 1077, 445, 569, 445,
168146 /* 1610 */ 410, 351, 1014, 568, 353, 316, 559, 568, 343, 568,
168147 /* 1620 */ 100, 497, 357, 258, 100, 896, 897, 140, 140, 355,
168148 /* 1630 */ 1306, 1014, 1014, 1016, 1017, 27, 139, 139, 362, 451,
168149 /* 1640 */ 137, 137, 138, 138, 1014, 1014, 1016, 1017, 27, 1177,
168150 /* 1650 */ 447, 568, 372, 288, 111, 560, 1018, 4, 392, 392,
168151 /* 1660 */ 391, 273, 389, 568, 1138, 847, 568, 1073, 568, 258,
168152 /* 1670 */ 492, 563, 568, 211, 75, 75, 555, 960, 234, 261,
168153 /* 1680 */ 323, 111, 560, 927, 4, 113, 77, 77, 322, 74,
168154 /* 1690 */ 74, 42, 42, 1369, 445, 48, 48, 1414, 563, 972,
168155 /* 1700 */ 973, 1089, 1088, 1089, 1088, 860, 557, 150, 928, 1342,
168156 /* 1710 */ 113, 1354, 554, 1419, 1018, 1271, 1262, 1250, 236, 1249,
168157 /* 1720 */ 1251, 445, 1588, 1339, 308, 276, 168, 309, 11, 141,
168158 /* 1730 */ 393, 310, 232, 557, 1401, 1024, 335, 291, 1396, 219,
168159 /* 1740 */ 336, 109, 109, 934, 297, 1406, 235, 341, 477, 110,
168160 /* 1750 */ 502, 445, 569, 445, 1389, 1405, 1014, 400, 1289, 365,
168161 /* 1760 */ 223, 1481, 1024, 1480, 1351, 1352, 1350, 1349, 109, 109,
168162 /* 1770 */ 204, 1591, 1228, 558, 265, 218, 110, 205, 445, 569,
168163 /* 1780 */ 445, 410, 387, 1014, 1528, 179, 316, 559, 1014, 1014,
168164 /* 1790 */ 1016, 1017, 27, 230, 1526, 1225, 79, 560, 85, 4,
168165 /* 1800 */ 418, 215, 548, 81, 84, 188, 1402, 173, 181, 461,
168166 /* 1810 */ 451, 35, 462, 563, 183, 1014, 1014, 1016, 1017, 27,
168167 /* 1820 */ 184, 1486, 185, 186, 495, 242, 98, 398, 1408, 36,
168168 /* 1830 */ 1407, 484, 91, 469, 401, 1410, 445, 192, 1475, 246,
168169 /* 1840 */ 1497, 490, 346, 277, 248, 196, 493, 511, 557, 350,
168170 /* 1850 */ 1252, 249, 250, 403, 1309, 1308, 111, 560, 432, 4,
168171 /* 1860 */ 1307, 1300, 93, 1605, 881, 1604, 224, 404, 434, 520,
168172 /* 1870 */ 263, 435, 1574, 563, 1279, 1278, 364, 1024, 306, 1277,
168173 /* 1880 */ 264, 1603, 1560, 109, 109, 370, 1299, 307, 1559, 438,
168174 /* 1890 */ 128, 110, 1374, 445, 569, 445, 445, 546, 1014, 10,
168175 /* 1900 */ 1461, 105, 381, 1373, 34, 571, 99, 1332, 557, 314,
168176 /* 1910 */ 1183, 530, 272, 274, 379, 210, 1331, 547, 385, 386,
168177 /* 1920 */ 275, 572, 1247, 1242, 411, 412, 1513, 165, 178, 1514,
168178 /* 1930 */ 1014, 1014, 1016, 1017, 27, 1512, 1511, 1024, 78, 147,
168179 /* 1940 */ 166, 220, 221, 109, 109, 834, 304, 167, 446, 212,
168180 /* 1950 */ 318, 110, 231, 445, 569, 445, 144, 1087, 1014, 1085,
168181 /* 1960 */ 326, 180, 169, 1208, 182, 334, 238, 913, 241, 1101,
168182 /* 1970 */ 187, 170, 171, 421, 87, 88, 423, 189, 89, 90,
168183 /* 1980 */ 172, 1104, 243, 1100, 244, 158, 18, 245, 345, 247,
168184 /* 1990 */ 1014, 1014, 1016, 1017, 27, 261, 1093, 193, 1222, 489,
168185 /* 2000 */ 194, 37, 366, 849, 494, 251, 195, 506, 92, 19,
168186 /* 2010 */ 498, 358, 20, 503, 879, 361, 94, 892, 305, 159,
168187 /* 2020 */ 513, 39, 95, 1171, 160, 1053, 964, 1140, 96, 174,
168188 /* 2030 */ 1139, 225, 280, 282, 198, 958, 113, 1161, 1157, 260,
168189 /* 2040 */ 21, 22, 23, 1159, 1165, 1164, 1145, 24, 33, 25,
168190 /* 2050 */ 202, 542, 26, 100, 1068, 102, 1054, 103, 7, 1052,
168191 /* 2060 */ 1056, 1110, 1057, 1109, 266, 267, 28, 40, 390, 1019,
168192 /* 2070 */ 861, 112, 29, 564, 1179, 1178, 268, 176, 143, 923,
168193 /* 2080 */ 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238,
168194 /* 2090 */ 1238, 1238, 1238, 1238, 269, 1596,
168195 };
168196 static const YYCODETYPE yy_lookahead[] = {
168197 /* 0 */ 193, 193, 193, 274, 275, 276, 193, 274, 275, 276,
168198 /* 10 */ 193, 223, 219, 225, 206, 210, 211, 212, 193, 19,
168199 /* 20 */ 219, 233, 216, 216, 217, 216, 217, 193, 295, 216,
@@ -168532,67 +168671,67 @@
168532 /* 380 */ 1665, 1623, 1702, 1630, 1666, 1667, 1671, 1673, 1703, 1718,
168533 /* 390 */ 1719, 1729, 1730, 1731, 1621, 1622, 1628, 1720, 1713, 1716,
168534 /* 400 */ 1722, 1723, 1733, 1717, 1724, 1727, 1728, 1725, 1740,
168535 };
168536 static const YYACTIONTYPE yy_default[] = {
168537 /* 0 */ 1641, 1641, 1641, 1470, 1236, 1347, 1236, 1236, 1236, 1470,
168538 /* 10 */ 1470, 1470, 1236, 1377, 1377, 1523, 1269, 1236, 1236, 1236,
168539 /* 20 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1469, 1236, 1236,
168540 /* 30 */ 1236, 1236, 1558, 1558, 1236, 1236, 1236, 1236, 1236, 1236,
168541 /* 40 */ 1236, 1236, 1386, 1236, 1393, 1236, 1236, 1236, 1236, 1236,
168542 /* 50 */ 1471, 1472, 1236, 1236, 1236, 1522, 1524, 1487, 1400, 1399,
168543 /* 60 */ 1398, 1397, 1505, 1365, 1391, 1384, 1388, 1465, 1466, 1464,
168544 /* 70 */ 1468, 1472, 1471, 1236, 1387, 1433, 1449, 1432, 1236, 1236,
168545 /* 80 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168546 /* 90 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168547 /* 100 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168548 /* 110 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168549 /* 120 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168550 /* 130 */ 1441, 1448, 1447, 1446, 1455, 1445, 1442, 1435, 1434, 1436,
168551 /* 140 */ 1437, 1236, 1236, 1260, 1236, 1236, 1257, 1311, 1236, 1236,
168552 /* 150 */ 1236, 1236, 1236, 1542, 1541, 1236, 1438, 1236, 1269, 1427,
168553 /* 160 */ 1426, 1452, 1439, 1451, 1450, 1530, 1594, 1593, 1488, 1236,
168554 /* 170 */ 1236, 1236, 1236, 1236, 1236, 1558, 1236, 1236, 1236, 1236,
168555 /* 180 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168556 /* 190 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1367,
168557 /* 200 */ 1558, 1558, 1236, 1269, 1558, 1558, 1368, 1368, 1265, 1265,
168558 /* 210 */ 1371, 1236, 1537, 1338, 1338, 1338, 1338, 1347, 1338, 1236,
168559 /* 220 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168560 /* 230 */ 1236, 1236, 1236, 1236, 1527, 1525, 1236, 1236, 1236, 1236,
168561 /* 240 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168562 /* 250 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168563 /* 260 */ 1236, 1236, 1236, 1343, 1236, 1236, 1236, 1236, 1236, 1236,
168564 /* 270 */ 1236, 1236, 1236, 1236, 1236, 1587, 1236, 1500, 1325, 1343,
168565 /* 280 */ 1343, 1343, 1343, 1345, 1326, 1324, 1337, 1270, 1243, 1633,
168566 /* 290 */ 1403, 1392, 1344, 1392, 1630, 1390, 1403, 1403, 1390, 1403,
168567 /* 300 */ 1344, 1630, 1286, 1609, 1281, 1377, 1377, 1377, 1367, 1367,
168568 /* 310 */ 1367, 1367, 1371, 1371, 1467, 1344, 1337, 1236, 1633, 1633,
168569 /* 320 */ 1353, 1353, 1632, 1632, 1353, 1488, 1617, 1412, 1314, 1320,
168570 /* 330 */ 1320, 1320, 1320, 1353, 1254, 1390, 1617, 1617, 1390, 1412,
168571 /* 340 */ 1314, 1390, 1314, 1390, 1353, 1254, 1504, 1627, 1353, 1254,
168572 /* 350 */ 1478, 1353, 1254, 1353, 1254, 1478, 1312, 1312, 1312, 1301,
168573 /* 360 */ 1236, 1236, 1478, 1312, 1286, 1312, 1301, 1312, 1312, 1576,
168574 /* 370 */ 1236, 1482, 1482, 1478, 1353, 1568, 1568, 1380, 1380, 1385,
168575 /* 380 */ 1371, 1473, 1353, 1236, 1385, 1383, 1381, 1390, 1304, 1590,
168576 /* 390 */ 1590, 1586, 1586, 1586, 1638, 1638, 1537, 1602, 1269, 1269,
168577 /* 400 */ 1269, 1269, 1602, 1288, 1288, 1270, 1270, 1269, 1602, 1236,
168578 /* 410 */ 1236, 1236, 1236, 1236, 1236, 1597, 1236, 1532, 1489, 1357,
168579 /* 420 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168580 /* 430 */ 1236, 1236, 1236, 1236, 1543, 1236, 1236, 1236, 1236, 1236,
168581 /* 440 */ 1236, 1236, 1236, 1236, 1236, 1417, 1236, 1239, 1534, 1236,
168582 /* 450 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1394, 1395, 1358,
168583 /* 460 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1409, 1236, 1236,
168584 /* 470 */ 1236, 1404, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168585 /* 480 */ 1629, 1236, 1236, 1236, 1236, 1236, 1236, 1503, 1502, 1236,
168586 /* 490 */ 1236, 1355, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168587 /* 500 */ 1236, 1236, 1236, 1236, 1236, 1284, 1236, 1236, 1236, 1236,
168588 /* 510 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168589 /* 520 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1382,
168590 /* 530 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168591 /* 540 */ 1236, 1236, 1236, 1236, 1573, 1372, 1236, 1236, 1236, 1236,
168592 /* 550 */ 1620, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168593 /* 560 */ 1236, 1236, 1236, 1236, 1236, 1613, 1328, 1418, 1236, 1421,
168594 /* 570 */ 1258, 1236, 1248, 1236, 1236,
168595 };
168596 /********** End of lemon-generated parsing tables *****************************/
168597
168598 /* The next table maps tokens (terminal symbols) into fallback tokens.
@@ -169437,162 +169576,162 @@
169437 /* 224 */ "expr ::= CASE case_operand case_exprlist case_else END",
169438 /* 225 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
169439 /* 226 */ "case_exprlist ::= WHEN expr THEN expr",
169440 /* 227 */ "case_else ::= ELSE expr",
169441 /* 228 */ "case_else ::=",
169442 /* 229 */ "case_operand ::= expr",
169443 /* 230 */ "case_operand ::=",
169444 /* 231 */ "exprlist ::=",
169445 /* 232 */ "nexprlist ::= nexprlist COMMA expr",
169446 /* 233 */ "nexprlist ::= expr",
169447 /* 234 */ "paren_exprlist ::=",
169448 /* 235 */ "paren_exprlist ::= LP exprlist RP",
169449 /* 236 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
169450 /* 237 */ "uniqueflag ::= UNIQUE",
169451 /* 238 */ "uniqueflag ::=",
169452 /* 239 */ "eidlist_opt ::=",
169453 /* 240 */ "eidlist_opt ::= LP eidlist RP",
169454 /* 241 */ "eidlist ::= eidlist COMMA nm collate sortorder",
169455 /* 242 */ "eidlist ::= nm collate sortorder",
169456 /* 243 */ "collate ::=",
169457 /* 244 */ "collate ::= COLLATE ID|STRING",
169458 /* 245 */ "cmd ::= DROP INDEX ifexists fullname",
169459 /* 246 */ "cmd ::= VACUUM vinto",
169460 /* 247 */ "cmd ::= VACUUM nm vinto",
169461 /* 248 */ "vinto ::= INTO expr",
169462 /* 249 */ "vinto ::=",
169463 /* 250 */ "cmd ::= PRAGMA nm dbnm",
169464 /* 251 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
169465 /* 252 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
169466 /* 253 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
169467 /* 254 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
169468 /* 255 */ "plus_num ::= PLUS INTEGER|FLOAT",
169469 /* 256 */ "minus_num ::= MINUS INTEGER|FLOAT",
169470 /* 257 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
169471 /* 258 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
169472 /* 259 */ "trigger_time ::= BEFORE|AFTER",
169473 /* 260 */ "trigger_time ::= INSTEAD OF",
169474 /* 261 */ "trigger_time ::=",
169475 /* 262 */ "trigger_event ::= DELETE|INSERT",
169476 /* 263 */ "trigger_event ::= UPDATE",
169477 /* 264 */ "trigger_event ::= UPDATE OF idlist",
169478 /* 265 */ "when_clause ::=",
169479 /* 266 */ "when_clause ::= WHEN expr",
169480 /* 267 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
169481 /* 268 */ "trigger_cmd_list ::= trigger_cmd SEMI",
169482 /* 269 */ "trnm ::= nm DOT nm",
169483 /* 270 */ "tridxby ::= INDEXED BY nm",
169484 /* 271 */ "tridxby ::= NOT INDEXED",
169485 /* 272 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
169486 /* 273 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
169487 /* 274 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
169488 /* 275 */ "trigger_cmd ::= scanpt select scanpt",
169489 /* 276 */ "expr ::= RAISE LP IGNORE RP",
169490 /* 277 */ "expr ::= RAISE LP raisetype COMMA nm RP",
169491 /* 278 */ "raisetype ::= ROLLBACK",
169492 /* 279 */ "raisetype ::= ABORT",
169493 /* 280 */ "raisetype ::= FAIL",
169494 /* 281 */ "cmd ::= DROP TRIGGER ifexists fullname",
169495 /* 282 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
169496 /* 283 */ "cmd ::= DETACH database_kw_opt expr",
169497 /* 284 */ "key_opt ::=",
169498 /* 285 */ "key_opt ::= KEY expr",
169499 /* 286 */ "cmd ::= REINDEX",
169500 /* 287 */ "cmd ::= REINDEX nm dbnm",
169501 /* 288 */ "cmd ::= ANALYZE",
169502 /* 289 */ "cmd ::= ANALYZE nm dbnm",
169503 /* 290 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
169504 /* 291 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
169505 /* 292 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
169506 /* 293 */ "add_column_fullname ::= fullname",
169507 /* 294 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
169508 /* 295 */ "cmd ::= create_vtab",
169509 /* 296 */ "cmd ::= create_vtab LP vtabarglist RP",
169510 /* 297 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
169511 /* 298 */ "vtabarg ::=",
169512 /* 299 */ "vtabargtoken ::= ANY",
169513 /* 300 */ "vtabargtoken ::= lp anylist RP",
169514 /* 301 */ "lp ::= LP",
169515 /* 302 */ "with ::= WITH wqlist",
169516 /* 303 */ "with ::= WITH RECURSIVE wqlist",
169517 /* 304 */ "wqas ::= AS",
169518 /* 305 */ "wqas ::= AS MATERIALIZED",
169519 /* 306 */ "wqas ::= AS NOT MATERIALIZED",
169520 /* 307 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
169521 /* 308 */ "wqlist ::= wqitem",
169522 /* 309 */ "wqlist ::= wqlist COMMA wqitem",
169523 /* 310 */ "windowdefn_list ::= windowdefn",
169524 /* 311 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
169525 /* 312 */ "windowdefn ::= nm AS LP window RP",
169526 /* 313 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
169527 /* 314 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
169528 /* 315 */ "window ::= ORDER BY sortlist frame_opt",
169529 /* 316 */ "window ::= nm ORDER BY sortlist frame_opt",
169530 /* 317 */ "window ::= frame_opt",
169531 /* 318 */ "window ::= nm frame_opt",
169532 /* 319 */ "frame_opt ::=",
169533 /* 320 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
169534 /* 321 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
169535 /* 322 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
169536 /* 323 */ "frame_bound_s ::= frame_bound",
169537 /* 324 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
169538 /* 325 */ "frame_bound_e ::= frame_bound",
169539 /* 326 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
169540 /* 327 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
169541 /* 328 */ "frame_bound ::= CURRENT ROW",
169542 /* 329 */ "frame_exclude_opt ::=",
169543 /* 330 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
169544 /* 331 */ "frame_exclude ::= NO OTHERS",
169545 /* 332 */ "frame_exclude ::= CURRENT ROW",
169546 /* 333 */ "frame_exclude ::= GROUP|TIES",
169547 /* 334 */ "window_clause ::= WINDOW windowdefn_list",
169548 /* 335 */ "filter_over ::= filter_clause over_clause",
169549 /* 336 */ "filter_over ::= over_clause",
169550 /* 337 */ "filter_over ::= filter_clause",
169551 /* 338 */ "over_clause ::= OVER LP window RP",
169552 /* 339 */ "over_clause ::= OVER nm",
169553 /* 340 */ "filter_clause ::= FILTER LP WHERE expr RP",
169554 /* 341 */ "input ::= cmdlist",
169555 /* 342 */ "cmdlist ::= cmdlist ecmd",
169556 /* 343 */ "cmdlist ::= ecmd",
169557 /* 344 */ "ecmd ::= SEMI",
169558 /* 345 */ "ecmd ::= cmdx SEMI",
169559 /* 346 */ "ecmd ::= explain cmdx SEMI",
169560 /* 347 */ "trans_opt ::=",
169561 /* 348 */ "trans_opt ::= TRANSACTION",
169562 /* 349 */ "trans_opt ::= TRANSACTION nm",
169563 /* 350 */ "savepoint_opt ::= SAVEPOINT",
169564 /* 351 */ "savepoint_opt ::=",
169565 /* 352 */ "cmd ::= create_table create_table_args",
169566 /* 353 */ "table_option_set ::= table_option",
169567 /* 354 */ "columnlist ::= columnlist COMMA columnname carglist",
169568 /* 355 */ "columnlist ::= columnname carglist",
169569 /* 356 */ "nm ::= ID|INDEXED|JOIN_KW",
169570 /* 357 */ "nm ::= STRING",
169571 /* 358 */ "typetoken ::= typename",
169572 /* 359 */ "typename ::= ID|STRING",
169573 /* 360 */ "signed ::= plus_num",
169574 /* 361 */ "signed ::= minus_num",
169575 /* 362 */ "carglist ::= carglist ccons",
169576 /* 363 */ "carglist ::=",
169577 /* 364 */ "ccons ::= NULL onconf",
169578 /* 365 */ "ccons ::= GENERATED ALWAYS AS generated",
169579 /* 366 */ "ccons ::= AS generated",
169580 /* 367 */ "conslist_opt ::= COMMA conslist",
169581 /* 368 */ "conslist ::= conslist tconscomma tcons",
169582 /* 369 */ "conslist ::= tcons",
169583 /* 370 */ "tconscomma ::=",
169584 /* 371 */ "defer_subclause_opt ::= defer_subclause",
169585 /* 372 */ "resolvetype ::= raisetype",
169586 /* 373 */ "selectnowith ::= oneselect",
169587 /* 374 */ "oneselect ::= values",
169588 /* 375 */ "sclp ::= selcollist COMMA",
169589 /* 376 */ "as ::= ID|STRING",
169590 /* 377 */ "indexed_opt ::= indexed_by",
169591 /* 378 */ "returning ::=",
169592 /* 379 */ "expr ::= term",
169593 /* 380 */ "likeop ::= LIKE_KW|MATCH",
169594 /* 381 */ "exprlist ::= nexprlist",
169595 /* 382 */ "nmnum ::= plus_num",
169596 /* 383 */ "nmnum ::= nm",
169597 /* 384 */ "nmnum ::= ON",
169598 /* 385 */ "nmnum ::= DELETE",
@@ -170346,162 +170485,162 @@
170346 217, /* (224) expr ::= CASE case_operand case_exprlist case_else END */
170347 279, /* (225) case_exprlist ::= case_exprlist WHEN expr THEN expr */
170348 279, /* (226) case_exprlist ::= WHEN expr THEN expr */
170349 280, /* (227) case_else ::= ELSE expr */
170350 280, /* (228) case_else ::= */
170351 278, /* (229) case_operand ::= expr */
170352 278, /* (230) case_operand ::= */
170353 261, /* (231) exprlist ::= */
170354 253, /* (232) nexprlist ::= nexprlist COMMA expr */
170355 253, /* (233) nexprlist ::= expr */
170356 277, /* (234) paren_exprlist ::= */
170357 277, /* (235) paren_exprlist ::= LP exprlist RP */
170358 190, /* (236) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
170359 281, /* (237) uniqueflag ::= UNIQUE */
170360 281, /* (238) uniqueflag ::= */
170361 221, /* (239) eidlist_opt ::= */
170362 221, /* (240) eidlist_opt ::= LP eidlist RP */
170363 232, /* (241) eidlist ::= eidlist COMMA nm collate sortorder */
170364 232, /* (242) eidlist ::= nm collate sortorder */
170365 282, /* (243) collate ::= */
170366 282, /* (244) collate ::= COLLATE ID|STRING */
170367 190, /* (245) cmd ::= DROP INDEX ifexists fullname */
170368 190, /* (246) cmd ::= VACUUM vinto */
170369 190, /* (247) cmd ::= VACUUM nm vinto */
170370 283, /* (248) vinto ::= INTO expr */
170371 283, /* (249) vinto ::= */
170372 190, /* (250) cmd ::= PRAGMA nm dbnm */
170373 190, /* (251) cmd ::= PRAGMA nm dbnm EQ nmnum */
170374 190, /* (252) cmd ::= PRAGMA nm dbnm LP nmnum RP */
170375 190, /* (253) cmd ::= PRAGMA nm dbnm EQ minus_num */
170376 190, /* (254) cmd ::= PRAGMA nm dbnm LP minus_num RP */
170377 211, /* (255) plus_num ::= PLUS INTEGER|FLOAT */
170378 212, /* (256) minus_num ::= MINUS INTEGER|FLOAT */
170379 190, /* (257) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
170380 285, /* (258) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
170381 287, /* (259) trigger_time ::= BEFORE|AFTER */
170382 287, /* (260) trigger_time ::= INSTEAD OF */
170383 287, /* (261) trigger_time ::= */
170384 288, /* (262) trigger_event ::= DELETE|INSERT */
170385 288, /* (263) trigger_event ::= UPDATE */
170386 288, /* (264) trigger_event ::= UPDATE OF idlist */
170387 290, /* (265) when_clause ::= */
170388 290, /* (266) when_clause ::= WHEN expr */
170389 286, /* (267) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
170390 286, /* (268) trigger_cmd_list ::= trigger_cmd SEMI */
170391 292, /* (269) trnm ::= nm DOT nm */
170392 293, /* (270) tridxby ::= INDEXED BY nm */
170393 293, /* (271) tridxby ::= NOT INDEXED */
170394 291, /* (272) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
170395 291, /* (273) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
170396 291, /* (274) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
170397 291, /* (275) trigger_cmd ::= scanpt select scanpt */
170398 217, /* (276) expr ::= RAISE LP IGNORE RP */
170399 217, /* (277) expr ::= RAISE LP raisetype COMMA nm RP */
170400 236, /* (278) raisetype ::= ROLLBACK */
170401 236, /* (279) raisetype ::= ABORT */
170402 236, /* (280) raisetype ::= FAIL */
170403 190, /* (281) cmd ::= DROP TRIGGER ifexists fullname */
170404 190, /* (282) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
170405 190, /* (283) cmd ::= DETACH database_kw_opt expr */
170406 295, /* (284) key_opt ::= */
170407 295, /* (285) key_opt ::= KEY expr */
170408 190, /* (286) cmd ::= REINDEX */
170409 190, /* (287) cmd ::= REINDEX nm dbnm */
170410 190, /* (288) cmd ::= ANALYZE */
170411 190, /* (289) cmd ::= ANALYZE nm dbnm */
170412 190, /* (290) cmd ::= ALTER TABLE fullname RENAME TO nm */
170413 190, /* (291) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
170414 190, /* (292) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
170415 296, /* (293) add_column_fullname ::= fullname */
170416 190, /* (294) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
170417 190, /* (295) cmd ::= create_vtab */
170418 190, /* (296) cmd ::= create_vtab LP vtabarglist RP */
170419 298, /* (297) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
170420 300, /* (298) vtabarg ::= */
170421 301, /* (299) vtabargtoken ::= ANY */
170422 301, /* (300) vtabargtoken ::= lp anylist RP */
170423 302, /* (301) lp ::= LP */
170424 266, /* (302) with ::= WITH wqlist */
170425 266, /* (303) with ::= WITH RECURSIVE wqlist */
170426 305, /* (304) wqas ::= AS */
170427 305, /* (305) wqas ::= AS MATERIALIZED */
170428 305, /* (306) wqas ::= AS NOT MATERIALIZED */
170429 304, /* (307) wqitem ::= nm eidlist_opt wqas LP select RP */
170430 241, /* (308) wqlist ::= wqitem */
170431 241, /* (309) wqlist ::= wqlist COMMA wqitem */
170432 306, /* (310) windowdefn_list ::= windowdefn */
170433 306, /* (311) windowdefn_list ::= windowdefn_list COMMA windowdefn */
170434 307, /* (312) windowdefn ::= nm AS LP window RP */
170435 308, /* (313) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
170436 308, /* (314) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
170437 308, /* (315) window ::= ORDER BY sortlist frame_opt */
170438 308, /* (316) window ::= nm ORDER BY sortlist frame_opt */
170439 308, /* (317) window ::= frame_opt */
170440 308, /* (318) window ::= nm frame_opt */
170441 309, /* (319) frame_opt ::= */
170442 309, /* (320) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
170443 309, /* (321) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
170444 313, /* (322) range_or_rows ::= RANGE|ROWS|GROUPS */
170445 315, /* (323) frame_bound_s ::= frame_bound */
170446 315, /* (324) frame_bound_s ::= UNBOUNDED PRECEDING */
170447 316, /* (325) frame_bound_e ::= frame_bound */
170448 316, /* (326) frame_bound_e ::= UNBOUNDED FOLLOWING */
170449 314, /* (327) frame_bound ::= expr PRECEDING|FOLLOWING */
170450 314, /* (328) frame_bound ::= CURRENT ROW */
170451 317, /* (329) frame_exclude_opt ::= */
170452 317, /* (330) frame_exclude_opt ::= EXCLUDE frame_exclude */
170453 318, /* (331) frame_exclude ::= NO OTHERS */
170454 318, /* (332) frame_exclude ::= CURRENT ROW */
170455 318, /* (333) frame_exclude ::= GROUP|TIES */
170456 251, /* (334) window_clause ::= WINDOW windowdefn_list */
170457 273, /* (335) filter_over ::= filter_clause over_clause */
170458 273, /* (336) filter_over ::= over_clause */
170459 273, /* (337) filter_over ::= filter_clause */
170460 312, /* (338) over_clause ::= OVER LP window RP */
170461 312, /* (339) over_clause ::= OVER nm */
170462 311, /* (340) filter_clause ::= FILTER LP WHERE expr RP */
170463 185, /* (341) input ::= cmdlist */
170464 186, /* (342) cmdlist ::= cmdlist ecmd */
170465 186, /* (343) cmdlist ::= ecmd */
170466 187, /* (344) ecmd ::= SEMI */
170467 187, /* (345) ecmd ::= cmdx SEMI */
170468 187, /* (346) ecmd ::= explain cmdx SEMI */
170469 192, /* (347) trans_opt ::= */
170470 192, /* (348) trans_opt ::= TRANSACTION */
170471 192, /* (349) trans_opt ::= TRANSACTION nm */
170472 194, /* (350) savepoint_opt ::= SAVEPOINT */
170473 194, /* (351) savepoint_opt ::= */
170474 190, /* (352) cmd ::= create_table create_table_args */
170475 203, /* (353) table_option_set ::= table_option */
170476 201, /* (354) columnlist ::= columnlist COMMA columnname carglist */
170477 201, /* (355) columnlist ::= columnname carglist */
170478 193, /* (356) nm ::= ID|INDEXED|JOIN_KW */
170479 193, /* (357) nm ::= STRING */
170480 208, /* (358) typetoken ::= typename */
170481 209, /* (359) typename ::= ID|STRING */
170482 210, /* (360) signed ::= plus_num */
170483 210, /* (361) signed ::= minus_num */
170484 207, /* (362) carglist ::= carglist ccons */
170485 207, /* (363) carglist ::= */
170486 215, /* (364) ccons ::= NULL onconf */
170487 215, /* (365) ccons ::= GENERATED ALWAYS AS generated */
170488 215, /* (366) ccons ::= AS generated */
170489 202, /* (367) conslist_opt ::= COMMA conslist */
170490 228, /* (368) conslist ::= conslist tconscomma tcons */
170491 228, /* (369) conslist ::= tcons */
170492 229, /* (370) tconscomma ::= */
170493 233, /* (371) defer_subclause_opt ::= defer_subclause */
170494 235, /* (372) resolvetype ::= raisetype */
170495 239, /* (373) selectnowith ::= oneselect */
170496 240, /* (374) oneselect ::= values */
170497 254, /* (375) sclp ::= selcollist COMMA */
170498 255, /* (376) as ::= ID|STRING */
170499 264, /* (377) indexed_opt ::= indexed_by */
170500 272, /* (378) returning ::= */
170501 217, /* (379) expr ::= term */
170502 274, /* (380) likeop ::= LIKE_KW|MATCH */
170503 261, /* (381) exprlist ::= nexprlist */
170504 284, /* (382) nmnum ::= plus_num */
170505 284, /* (383) nmnum ::= nm */
170506 284, /* (384) nmnum ::= ON */
170507 284, /* (385) nmnum ::= DELETE */
@@ -170754,162 +170893,162 @@
170754 -5, /* (224) expr ::= CASE case_operand case_exprlist case_else END */
170755 -5, /* (225) case_exprlist ::= case_exprlist WHEN expr THEN expr */
170756 -4, /* (226) case_exprlist ::= WHEN expr THEN expr */
170757 -2, /* (227) case_else ::= ELSE expr */
170758 0, /* (228) case_else ::= */
170759 -1, /* (229) case_operand ::= expr */
170760 0, /* (230) case_operand ::= */
170761 0, /* (231) exprlist ::= */
170762 -3, /* (232) nexprlist ::= nexprlist COMMA expr */
170763 -1, /* (233) nexprlist ::= expr */
170764 0, /* (234) paren_exprlist ::= */
170765 -3, /* (235) paren_exprlist ::= LP exprlist RP */
170766 -12, /* (236) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
170767 -1, /* (237) uniqueflag ::= UNIQUE */
170768 0, /* (238) uniqueflag ::= */
170769 0, /* (239) eidlist_opt ::= */
170770 -3, /* (240) eidlist_opt ::= LP eidlist RP */
170771 -5, /* (241) eidlist ::= eidlist COMMA nm collate sortorder */
170772 -3, /* (242) eidlist ::= nm collate sortorder */
170773 0, /* (243) collate ::= */
170774 -2, /* (244) collate ::= COLLATE ID|STRING */
170775 -4, /* (245) cmd ::= DROP INDEX ifexists fullname */
170776 -2, /* (246) cmd ::= VACUUM vinto */
170777 -3, /* (247) cmd ::= VACUUM nm vinto */
170778 -2, /* (248) vinto ::= INTO expr */
170779 0, /* (249) vinto ::= */
170780 -3, /* (250) cmd ::= PRAGMA nm dbnm */
170781 -5, /* (251) cmd ::= PRAGMA nm dbnm EQ nmnum */
170782 -6, /* (252) cmd ::= PRAGMA nm dbnm LP nmnum RP */
170783 -5, /* (253) cmd ::= PRAGMA nm dbnm EQ minus_num */
170784 -6, /* (254) cmd ::= PRAGMA nm dbnm LP minus_num RP */
170785 -2, /* (255) plus_num ::= PLUS INTEGER|FLOAT */
170786 -2, /* (256) minus_num ::= MINUS INTEGER|FLOAT */
170787 -5, /* (257) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
170788 -11, /* (258) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
170789 -1, /* (259) trigger_time ::= BEFORE|AFTER */
170790 -2, /* (260) trigger_time ::= INSTEAD OF */
170791 0, /* (261) trigger_time ::= */
170792 -1, /* (262) trigger_event ::= DELETE|INSERT */
170793 -1, /* (263) trigger_event ::= UPDATE */
170794 -3, /* (264) trigger_event ::= UPDATE OF idlist */
170795 0, /* (265) when_clause ::= */
170796 -2, /* (266) when_clause ::= WHEN expr */
170797 -3, /* (267) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
170798 -2, /* (268) trigger_cmd_list ::= trigger_cmd SEMI */
170799 -3, /* (269) trnm ::= nm DOT nm */
170800 -3, /* (270) tridxby ::= INDEXED BY nm */
170801 -2, /* (271) tridxby ::= NOT INDEXED */
170802 -9, /* (272) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
170803 -8, /* (273) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
170804 -6, /* (274) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
170805 -3, /* (275) trigger_cmd ::= scanpt select scanpt */
170806 -4, /* (276) expr ::= RAISE LP IGNORE RP */
170807 -6, /* (277) expr ::= RAISE LP raisetype COMMA nm RP */
170808 -1, /* (278) raisetype ::= ROLLBACK */
170809 -1, /* (279) raisetype ::= ABORT */
170810 -1, /* (280) raisetype ::= FAIL */
170811 -4, /* (281) cmd ::= DROP TRIGGER ifexists fullname */
170812 -6, /* (282) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
170813 -3, /* (283) cmd ::= DETACH database_kw_opt expr */
170814 0, /* (284) key_opt ::= */
170815 -2, /* (285) key_opt ::= KEY expr */
170816 -1, /* (286) cmd ::= REINDEX */
170817 -3, /* (287) cmd ::= REINDEX nm dbnm */
170818 -1, /* (288) cmd ::= ANALYZE */
170819 -3, /* (289) cmd ::= ANALYZE nm dbnm */
170820 -6, /* (290) cmd ::= ALTER TABLE fullname RENAME TO nm */
170821 -7, /* (291) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
170822 -6, /* (292) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
170823 -1, /* (293) add_column_fullname ::= fullname */
170824 -8, /* (294) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
170825 -1, /* (295) cmd ::= create_vtab */
170826 -4, /* (296) cmd ::= create_vtab LP vtabarglist RP */
170827 -8, /* (297) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
170828 0, /* (298) vtabarg ::= */
170829 -1, /* (299) vtabargtoken ::= ANY */
170830 -3, /* (300) vtabargtoken ::= lp anylist RP */
170831 -1, /* (301) lp ::= LP */
170832 -2, /* (302) with ::= WITH wqlist */
170833 -3, /* (303) with ::= WITH RECURSIVE wqlist */
170834 -1, /* (304) wqas ::= AS */
170835 -2, /* (305) wqas ::= AS MATERIALIZED */
170836 -3, /* (306) wqas ::= AS NOT MATERIALIZED */
170837 -6, /* (307) wqitem ::= nm eidlist_opt wqas LP select RP */
170838 -1, /* (308) wqlist ::= wqitem */
170839 -3, /* (309) wqlist ::= wqlist COMMA wqitem */
170840 -1, /* (310) windowdefn_list ::= windowdefn */
170841 -3, /* (311) windowdefn_list ::= windowdefn_list COMMA windowdefn */
170842 -5, /* (312) windowdefn ::= nm AS LP window RP */
170843 -5, /* (313) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
170844 -6, /* (314) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
170845 -4, /* (315) window ::= ORDER BY sortlist frame_opt */
170846 -5, /* (316) window ::= nm ORDER BY sortlist frame_opt */
170847 -1, /* (317) window ::= frame_opt */
170848 -2, /* (318) window ::= nm frame_opt */
170849 0, /* (319) frame_opt ::= */
170850 -3, /* (320) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
170851 -6, /* (321) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
170852 -1, /* (322) range_or_rows ::= RANGE|ROWS|GROUPS */
170853 -1, /* (323) frame_bound_s ::= frame_bound */
170854 -2, /* (324) frame_bound_s ::= UNBOUNDED PRECEDING */
170855 -1, /* (325) frame_bound_e ::= frame_bound */
170856 -2, /* (326) frame_bound_e ::= UNBOUNDED FOLLOWING */
170857 -2, /* (327) frame_bound ::= expr PRECEDING|FOLLOWING */
170858 -2, /* (328) frame_bound ::= CURRENT ROW */
170859 0, /* (329) frame_exclude_opt ::= */
170860 -2, /* (330) frame_exclude_opt ::= EXCLUDE frame_exclude */
170861 -2, /* (331) frame_exclude ::= NO OTHERS */
170862 -2, /* (332) frame_exclude ::= CURRENT ROW */
170863 -1, /* (333) frame_exclude ::= GROUP|TIES */
170864 -2, /* (334) window_clause ::= WINDOW windowdefn_list */
170865 -2, /* (335) filter_over ::= filter_clause over_clause */
170866 -1, /* (336) filter_over ::= over_clause */
170867 -1, /* (337) filter_over ::= filter_clause */
170868 -4, /* (338) over_clause ::= OVER LP window RP */
170869 -2, /* (339) over_clause ::= OVER nm */
170870 -5, /* (340) filter_clause ::= FILTER LP WHERE expr RP */
170871 -1, /* (341) input ::= cmdlist */
170872 -2, /* (342) cmdlist ::= cmdlist ecmd */
170873 -1, /* (343) cmdlist ::= ecmd */
170874 -1, /* (344) ecmd ::= SEMI */
170875 -2, /* (345) ecmd ::= cmdx SEMI */
170876 -3, /* (346) ecmd ::= explain cmdx SEMI */
170877 0, /* (347) trans_opt ::= */
170878 -1, /* (348) trans_opt ::= TRANSACTION */
170879 -2, /* (349) trans_opt ::= TRANSACTION nm */
170880 -1, /* (350) savepoint_opt ::= SAVEPOINT */
170881 0, /* (351) savepoint_opt ::= */
170882 -2, /* (352) cmd ::= create_table create_table_args */
170883 -1, /* (353) table_option_set ::= table_option */
170884 -4, /* (354) columnlist ::= columnlist COMMA columnname carglist */
170885 -2, /* (355) columnlist ::= columnname carglist */
170886 -1, /* (356) nm ::= ID|INDEXED|JOIN_KW */
170887 -1, /* (357) nm ::= STRING */
170888 -1, /* (358) typetoken ::= typename */
170889 -1, /* (359) typename ::= ID|STRING */
170890 -1, /* (360) signed ::= plus_num */
170891 -1, /* (361) signed ::= minus_num */
170892 -2, /* (362) carglist ::= carglist ccons */
170893 0, /* (363) carglist ::= */
170894 -2, /* (364) ccons ::= NULL onconf */
170895 -4, /* (365) ccons ::= GENERATED ALWAYS AS generated */
170896 -2, /* (366) ccons ::= AS generated */
170897 -2, /* (367) conslist_opt ::= COMMA conslist */
170898 -3, /* (368) conslist ::= conslist tconscomma tcons */
170899 -1, /* (369) conslist ::= tcons */
170900 0, /* (370) tconscomma ::= */
170901 -1, /* (371) defer_subclause_opt ::= defer_subclause */
170902 -1, /* (372) resolvetype ::= raisetype */
170903 -1, /* (373) selectnowith ::= oneselect */
170904 -1, /* (374) oneselect ::= values */
170905 -2, /* (375) sclp ::= selcollist COMMA */
170906 -1, /* (376) as ::= ID|STRING */
170907 -1, /* (377) indexed_opt ::= indexed_by */
170908 0, /* (378) returning ::= */
170909 -1, /* (379) expr ::= term */
170910 -1, /* (380) likeop ::= LIKE_KW|MATCH */
170911 -1, /* (381) exprlist ::= nexprlist */
170912 -1, /* (382) nmnum ::= plus_num */
170913 -1, /* (383) nmnum ::= nm */
170914 -1, /* (384) nmnum ::= ON */
170915 -1, /* (385) nmnum ::= DELETE */
@@ -170987,11 +171126,11 @@
170987 {yymsp[1].minor.yy394 = TK_DEFERRED;}
170988 break;
170989 case 5: /* transtype ::= DEFERRED */
170990 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
170991 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
170992 case 322: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==322);
170993 {yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/}
170994 break;
170995 case 8: /* cmd ::= COMMIT|END trans_opt */
170996 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
170997 {sqlite3EndTransaction(pParse,yymsp[-1].major);}
@@ -171024,11 +171163,11 @@
171024 case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
171025 case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
171026 case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72);
171027 case 81: /* ifexists ::= */ yytestcase(yyruleno==81);
171028 case 98: /* distinct ::= */ yytestcase(yyruleno==98);
171029 case 243: /* collate ::= */ yytestcase(yyruleno==243);
171030 {yymsp[1].minor.yy394 = 0;}
171031 break;
171032 case 16: /* ifnotexists ::= IF NOT EXISTS */
171033 {yymsp[-2].minor.yy394 = 1;}
171034 break;
@@ -171210,11 +171349,11 @@
171210 break;
171211 case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
171212 case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80);
171213 case 215: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==215);
171214 case 218: /* in_op ::= NOT IN */ yytestcase(yyruleno==218);
171215 case 244: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==244);
171216 {yymsp[-1].minor.yy394 = 1;}
171217 break;
171218 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
171219 {yymsp[-1].minor.yy394 = 0;}
171220 break;
@@ -171360,13 +171499,13 @@
171360 {yymsp[0].minor.yy394 = SF_All;}
171361 break;
171362 case 99: /* sclp ::= */
171363 case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132);
171364 case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142);
171365 case 231: /* exprlist ::= */ yytestcase(yyruleno==231);
171366 case 234: /* paren_exprlist ::= */ yytestcase(yyruleno==234);
171367 case 239: /* eidlist_opt ::= */ yytestcase(yyruleno==239);
171368 {yymsp[1].minor.yy322 = 0;}
171369 break;
171370 case 100: /* selcollist ::= sclp scanpt expr scanpt as */
171371 {
171372 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
@@ -171388,12 +171527,12 @@
171388 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
171389 }
171390 break;
171391 case 103: /* as ::= AS nm */
171392 case 115: /* dbnm ::= DOT nm */ yytestcase(yyruleno==115);
171393 case 255: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==255);
171394 case 256: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==256);
171395 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
171396 break;
171397 case 105: /* from ::= */
171398 case 108: /* stl_prefix ::= */ yytestcase(yyruleno==108);
171399 {yymsp[1].minor.yy131 = 0;}
@@ -171433,11 +171572,11 @@
171433 break;
171434 case 113: /* seltablist ::= stl_prefix LP seltablist RP as on_using */
171435 {
171436 if( yymsp[-5].minor.yy131==0 && yymsp[-1].minor.yy0.n==0 && yymsp[0].minor.yy561.pOn==0 && yymsp[0].minor.yy561.pUsing==0 ){
171437 yymsp[-5].minor.yy131 = yymsp[-3].minor.yy131;
171438 }else if( yymsp[-3].minor.yy131->nSrc==1 ){
171439 yymsp[-5].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy131,0,0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy561);
171440 if( yymsp[-5].minor.yy131 ){
171441 SrcItem *pNew = &yymsp[-5].minor.yy131->a[yymsp[-5].minor.yy131->nSrc-1];
171442 SrcItem *pOld = yymsp[-3].minor.yy131->a;
171443 pNew->zName = pOld->zName;
@@ -171562,19 +171701,19 @@
171562 case 144: /* having_opt ::= */
171563 case 146: /* limit_opt ::= */ yytestcase(yyruleno==146);
171564 case 151: /* where_opt ::= */ yytestcase(yyruleno==151);
171565 case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153);
171566 case 228: /* case_else ::= */ yytestcase(yyruleno==228);
171567 case 230: /* case_operand ::= */ yytestcase(yyruleno==230);
171568 case 249: /* vinto ::= */ yytestcase(yyruleno==249);
171569 {yymsp[1].minor.yy528 = 0;}
171570 break;
171571 case 145: /* having_opt ::= HAVING expr */
171572 case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152);
171573 case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154);
171574 case 227: /* case_else ::= ELSE expr */ yytestcase(yyruleno==227);
171575 case 248: /* vinto ::= INTO expr */ yytestcase(yyruleno==248);
171576 {yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;}
171577 break;
171578 case 147: /* limit_opt ::= LIMIT expr */
171579 {yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);}
171580 break;
@@ -172001,394 +172140,391 @@
172001 {
172002 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
172003 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528);
172004 }
172005 break;
172006 case 229: /* case_operand ::= expr */
172007 {yymsp[0].minor.yy528 = yymsp[0].minor.yy528; /*A-overwrites-X*/}
172008 break;
172009 case 232: /* nexprlist ::= nexprlist COMMA expr */
172010 {yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);}
172011 break;
172012 case 233: /* nexprlist ::= expr */
172013 {yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/}
172014 break;
172015 case 235: /* paren_exprlist ::= LP exprlist RP */
172016 case 240: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==240);
172017 {yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
172018 break;
172019 case 236: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
172020 {
172021 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
172022 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394,
172023 &yymsp[-11].minor.yy0, yymsp[0].minor.yy528, SQLITE_SO_ASC, yymsp[-8].minor.yy394, SQLITE_IDXTYPE_APPDEF);
172024 if( IN_RENAME_OBJECT && pParse->pNewIndex ){
172025 sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
172026 }
172027 }
172028 break;
172029 case 237: /* uniqueflag ::= UNIQUE */
172030 case 279: /* raisetype ::= ABORT */ yytestcase(yyruleno==279);
172031 {yymsp[0].minor.yy394 = OE_Abort;}
172032 break;
172033 case 238: /* uniqueflag ::= */
172034 {yymsp[1].minor.yy394 = OE_None;}
172035 break;
172036 case 241: /* eidlist ::= eidlist COMMA nm collate sortorder */
172037 {
172038 yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394);
172039 }
172040 break;
172041 case 242: /* eidlist ::= nm collate sortorder */
172042 {
172043 yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/
172044 }
172045 break;
172046 case 245: /* cmd ::= DROP INDEX ifexists fullname */
172047 {sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);}
172048 break;
172049 case 246: /* cmd ::= VACUUM vinto */
172050 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);}
172051 break;
172052 case 247: /* cmd ::= VACUUM nm vinto */
172053 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);}
172054 break;
172055 case 250: /* cmd ::= PRAGMA nm dbnm */
172056 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
172057 break;
172058 case 251: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
172059 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
172060 break;
172061 case 252: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
172062 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
172063 break;
172064 case 253: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
172065 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
172066 break;
172067 case 254: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
172068 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
172069 break;
172070 case 257: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
172071 {
172072 Token all;
172073 all.z = yymsp[-3].minor.yy0.z;
172074 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
172075 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all);
172076 }
172077 break;
172078 case 258: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
172079 {
172080 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394);
172081 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
172082 }
172083 break;
172084 case 259: /* trigger_time ::= BEFORE|AFTER */
172085 { yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ }
172086 break;
172087 case 260: /* trigger_time ::= INSTEAD OF */
172088 { yymsp[-1].minor.yy394 = TK_INSTEAD;}
172089 break;
172090 case 261: /* trigger_time ::= */
172091 { yymsp[1].minor.yy394 = TK_BEFORE; }
172092 break;
172093 case 262: /* trigger_event ::= DELETE|INSERT */
172094 case 263: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==263);
172095 {yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;}
172096 break;
172097 case 264: /* trigger_event ::= UPDATE OF idlist */
172098 {yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;}
172099 break;
172100 case 265: /* when_clause ::= */
172101 case 284: /* key_opt ::= */ yytestcase(yyruleno==284);
172102 { yymsp[1].minor.yy528 = 0; }
172103 break;
172104 case 266: /* when_clause ::= WHEN expr */
172105 case 285: /* key_opt ::= KEY expr */ yytestcase(yyruleno==285);
172106 { yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; }
172107 break;
172108 case 267: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
172109 {
172110 assert( yymsp[-2].minor.yy33!=0 );
172111 yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33;
172112 yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33;
172113 }
172114 break;
172115 case 268: /* trigger_cmd_list ::= trigger_cmd SEMI */
172116 {
172117 assert( yymsp[-1].minor.yy33!=0 );
172118 yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33;
172119 }
172120 break;
172121 case 269: /* trnm ::= nm DOT nm */
172122 {
172123 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
172124 sqlite3ErrorMsg(pParse,
172125 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
172126 "statements within triggers");
172127 }
172128 break;
172129 case 270: /* tridxby ::= INDEXED BY nm */
172130 {
172131 sqlite3ErrorMsg(pParse,
172132 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
172133 "within triggers");
172134 }
172135 break;
172136 case 271: /* tridxby ::= NOT INDEXED */
172137 {
172138 sqlite3ErrorMsg(pParse,
172139 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
172140 "within triggers");
172141 }
172142 break;
172143 case 272: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
172144 {yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);}
172145 yymsp[-8].minor.yy33 = yylhsminor.yy33;
172146 break;
172147 case 273: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
172148 {
172149 yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/
172150 }
172151 yymsp[-7].minor.yy33 = yylhsminor.yy33;
172152 break;
172153 case 274: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
172154 {yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);}
172155 yymsp[-5].minor.yy33 = yylhsminor.yy33;
172156 break;
172157 case 275: /* trigger_cmd ::= scanpt select scanpt */
172158 {yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/}
172159 yymsp[-2].minor.yy33 = yylhsminor.yy33;
172160 break;
172161 case 276: /* expr ::= RAISE LP IGNORE RP */
172162 {
172163 yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
172164 if( yymsp[-3].minor.yy528 ){
172165 yymsp[-3].minor.yy528->affExpr = OE_Ignore;
172166 }
172167 }
172168 break;
172169 case 277: /* expr ::= RAISE LP raisetype COMMA nm RP */
172170 {
172171 yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
172172 if( yymsp[-5].minor.yy528 ) {
172173 yymsp[-5].minor.yy528->affExpr = (char)yymsp[-3].minor.yy394;
172174 }
172175 }
172176 break;
172177 case 278: /* raisetype ::= ROLLBACK */
172178 {yymsp[0].minor.yy394 = OE_Rollback;}
172179 break;
172180 case 280: /* raisetype ::= FAIL */
172181 {yymsp[0].minor.yy394 = OE_Fail;}
172182 break;
172183 case 281: /* cmd ::= DROP TRIGGER ifexists fullname */
172184 {
172185 sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394);
172186 }
172187 break;
172188 case 282: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
172189 {
172190 sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528);
172191 }
172192 break;
172193 case 283: /* cmd ::= DETACH database_kw_opt expr */
172194 {
172195 sqlite3Detach(pParse, yymsp[0].minor.yy528);
172196 }
172197 break;
172198 case 286: /* cmd ::= REINDEX */
172199 {sqlite3Reindex(pParse, 0, 0);}
172200 break;
172201 case 287: /* cmd ::= REINDEX nm dbnm */
172202 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
172203 break;
172204 case 288: /* cmd ::= ANALYZE */
172205 {sqlite3Analyze(pParse, 0, 0);}
172206 break;
172207 case 289: /* cmd ::= ANALYZE nm dbnm */
172208 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
172209 break;
172210 case 290: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
172211 {
172212 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0);
172213 }
172214 break;
172215 case 291: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
172216 {
172217 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
172218 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
172219 }
172220 break;
172221 case 292: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
172222 {
172223 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0);
172224 }
172225 break;
172226 case 293: /* add_column_fullname ::= fullname */
172227 {
172228 disableLookaside(pParse);
172229 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131);
172230 }
172231 break;
172232 case 294: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
172233 {
172234 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
172235 }
172236 break;
172237 case 295: /* cmd ::= create_vtab */
172238 {sqlite3VtabFinishParse(pParse,0);}
172239 break;
172240 case 296: /* cmd ::= create_vtab LP vtabarglist RP */
172241 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
172242 break;
172243 case 297: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
172244 {
172245 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394);
172246 }
172247 break;
172248 case 298: /* vtabarg ::= */
172249 {sqlite3VtabArgInit(pParse);}
172250 break;
172251 case 299: /* vtabargtoken ::= ANY */
172252 case 300: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==300);
172253 case 301: /* lp ::= LP */ yytestcase(yyruleno==301);
172254 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
172255 break;
172256 case 302: /* with ::= WITH wqlist */
172257 case 303: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==303);
172258 { sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); }
172259 break;
172260 case 304: /* wqas ::= AS */
172261 {yymsp[0].minor.yy516 = M10d_Any;}
172262 break;
172263 case 305: /* wqas ::= AS MATERIALIZED */
172264 {yymsp[-1].minor.yy516 = M10d_Yes;}
172265 break;
172266 case 306: /* wqas ::= AS NOT MATERIALIZED */
172267 {yymsp[-2].minor.yy516 = M10d_No;}
172268 break;
172269 case 307: /* wqitem ::= nm eidlist_opt wqas LP select RP */
172270 {
172271 yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/
172272 }
172273 break;
172274 case 308: /* wqlist ::= wqitem */
172275 {
172276 yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/
172277 }
172278 break;
172279 case 309: /* wqlist ::= wqlist COMMA wqitem */
172280 {
172281 yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385);
172282 }
172283 break;
172284 case 310: /* windowdefn_list ::= windowdefn */
172285 { yylhsminor.yy41 = yymsp[0].minor.yy41; }
172286 yymsp[0].minor.yy41 = yylhsminor.yy41;
172287 break;
172288 case 311: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
172289 {
172290 assert( yymsp[0].minor.yy41!=0 );
172291 sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41);
172292 yymsp[0].minor.yy41->pNextWin = yymsp[-2].minor.yy41;
172293 yylhsminor.yy41 = yymsp[0].minor.yy41;
172294 }
172295 yymsp[-2].minor.yy41 = yylhsminor.yy41;
172296 break;
172297 case 312: /* windowdefn ::= nm AS LP window RP */
172298 {
172299 if( ALWAYS(yymsp[-1].minor.yy41) ){
172300 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
172301 }
172302 yylhsminor.yy41 = yymsp[-1].minor.yy41;
172303 }
172304 yymsp[-4].minor.yy41 = yylhsminor.yy41;
172305 break;
172306 case 313: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
172307 {
172308 yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0);
172309 }
172310 break;
172311 case 314: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
172312 {
172313 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0);
172314 }
172315 yymsp[-5].minor.yy41 = yylhsminor.yy41;
172316 break;
172317 case 315: /* window ::= ORDER BY sortlist frame_opt */
172318 {
172319 yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0);
172320 }
172321 break;
172322 case 316: /* window ::= nm ORDER BY sortlist frame_opt */
172323 {
172324 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
172325 }
172326 yymsp[-4].minor.yy41 = yylhsminor.yy41;
172327 break;
172328 case 317: /* window ::= frame_opt */
172329 case 336: /* filter_over ::= over_clause */ yytestcase(yyruleno==336);
172330 {
172331 yylhsminor.yy41 = yymsp[0].minor.yy41;
172332 }
172333 yymsp[0].minor.yy41 = yylhsminor.yy41;
172334 break;
172335 case 318: /* window ::= nm frame_opt */
172336 {
172337 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0);
172338 }
172339 yymsp[-1].minor.yy41 = yylhsminor.yy41;
172340 break;
172341 case 319: /* frame_opt ::= */
172342 {
172343 yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
172344 }
172345 break;
172346 case 320: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
172347 {
172348 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516);
172349 }
172350 yymsp[-2].minor.yy41 = yylhsminor.yy41;
172351 break;
172352 case 321: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
172353 {
172354 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516);
172355 }
172356 yymsp[-5].minor.yy41 = yylhsminor.yy41;
172357 break;
172358 case 323: /* frame_bound_s ::= frame_bound */
172359 case 325: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==325);
172360 {yylhsminor.yy595 = yymsp[0].minor.yy595;}
172361 yymsp[0].minor.yy595 = yylhsminor.yy595;
172362 break;
172363 case 324: /* frame_bound_s ::= UNBOUNDED PRECEDING */
172364 case 326: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==326);
172365 case 328: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==328);
172366 {yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;}
172367 yymsp[-1].minor.yy595 = yylhsminor.yy595;
172368 break;
172369 case 327: /* frame_bound ::= expr PRECEDING|FOLLOWING */
172370 {yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;}
172371 yymsp[-1].minor.yy595 = yylhsminor.yy595;
172372 break;
172373 case 329: /* frame_exclude_opt ::= */
172374 {yymsp[1].minor.yy516 = 0;}
172375 break;
172376 case 330: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
172377 {yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;}
172378 break;
172379 case 331: /* frame_exclude ::= NO OTHERS */
172380 case 332: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==332);
172381 {yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/}
172382 break;
172383 case 333: /* frame_exclude ::= GROUP|TIES */
172384 {yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/}
172385 break;
172386 case 334: /* window_clause ::= WINDOW windowdefn_list */
172387 { yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; }
172388 break;
172389 case 335: /* filter_over ::= filter_clause over_clause */
172390 {
172391 if( yymsp[0].minor.yy41 ){
172392 yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528;
172393 }else{
172394 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
@@ -172395,11 +172531,11 @@
172395 }
172396 yylhsminor.yy41 = yymsp[0].minor.yy41;
172397 }
172398 yymsp[-1].minor.yy41 = yylhsminor.yy41;
172399 break;
172400 case 337: /* filter_over ::= filter_clause */
172401 {
172402 yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
172403 if( yylhsminor.yy41 ){
172404 yylhsminor.yy41->eFrmType = TK_FILTER;
172405 yylhsminor.yy41->pFilter = yymsp[0].minor.yy528;
@@ -172407,68 +172543,69 @@
172407 sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy528);
172408 }
172409 }
172410 yymsp[0].minor.yy41 = yylhsminor.yy41;
172411 break;
172412 case 338: /* over_clause ::= OVER LP window RP */
172413 {
172414 yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41;
172415 assert( yymsp[-3].minor.yy41!=0 );
172416 }
172417 break;
172418 case 339: /* over_clause ::= OVER nm */
172419 {
172420 yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
172421 if( yymsp[-1].minor.yy41 ){
172422 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
172423 }
172424 }
172425 break;
172426 case 340: /* filter_clause ::= FILTER LP WHERE expr RP */
172427 { yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; }
172428 break;
172429 default:
172430 /* (341) input ::= cmdlist */ yytestcase(yyruleno==341);
172431 /* (342) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==342);
172432 /* (343) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=343);
172433 /* (344) ecmd ::= SEMI */ yytestcase(yyruleno==344);
172434 /* (345) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==345);
172435 /* (346) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=346);
172436 /* (347) trans_opt ::= */ yytestcase(yyruleno==347);
172437 /* (348) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==348);
172438 /* (349) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==349);
172439 /* (350) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==350);
172440 /* (351) savepoint_opt ::= */ yytestcase(yyruleno==351);
172441 /* (352) cmd ::= create_table create_table_args */ yytestcase(yyruleno==352);
172442 /* (353) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=353);
172443 /* (354) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==354);
172444 /* (355) columnlist ::= columnname carglist */ yytestcase(yyruleno==355);
172445 /* (356) nm ::= ID|INDEXED|JOIN_KW */ yytestcase(yyruleno==356);
172446 /* (357) nm ::= STRING */ yytestcase(yyruleno==357);
172447 /* (358) typetoken ::= typename */ yytestcase(yyruleno==358);
172448 /* (359) typename ::= ID|STRING */ yytestcase(yyruleno==359);
172449 /* (360) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=360);
172450 /* (361) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=361);
172451 /* (362) carglist ::= carglist ccons */ yytestcase(yyruleno==362);
172452 /* (363) carglist ::= */ yytestcase(yyruleno==363);
172453 /* (364) ccons ::= NULL onconf */ yytestcase(yyruleno==364);
172454 /* (365) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==365);
172455 /* (366) ccons ::= AS generated */ yytestcase(yyruleno==366);
172456 /* (367) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==367);
172457 /* (368) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==368);
172458 /* (369) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=369);
172459 /* (370) tconscomma ::= */ yytestcase(yyruleno==370);
172460 /* (371) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=371);
172461 /* (372) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=372);
172462 /* (373) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=373);
172463 /* (374) oneselect ::= values */ yytestcase(yyruleno==374);
172464 /* (375) sclp ::= selcollist COMMA */ yytestcase(yyruleno==375);
172465 /* (376) as ::= ID|STRING */ yytestcase(yyruleno==376);
172466 /* (377) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=377);
172467 /* (378) returning ::= */ yytestcase(yyruleno==378);
172468 /* (379) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=379);
172469 /* (380) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==380);
 
172470 /* (381) exprlist ::= nexprlist */ yytestcase(yyruleno==381);
172471 /* (382) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=382);
172472 /* (383) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=383);
172473 /* (384) nmnum ::= ON */ yytestcase(yyruleno==384);
172474 /* (385) nmnum ::= DELETE */ yytestcase(yyruleno==385);
@@ -199500,10 +199637,11 @@
199500 #define JNODE_REMOVE 0x04 /* Do not output */
199501 #define JNODE_REPLACE 0x08 /* Replace with JsonNode.u.iReplace */
199502 #define JNODE_PATCH 0x10 /* Patch with JsonNode.u.pPatch */
199503 #define JNODE_APPEND 0x20 /* More ARRAY/OBJECT entries at u.iAppend */
199504 #define JNODE_LABEL 0x40 /* Is a label of an object */
 
199505
199506
199507 /* A single node of parsed JSON
199508 */
199509 struct JsonNode {
@@ -199526,14 +199664,16 @@
199526 u32 nNode; /* Number of slots of aNode[] used */
199527 u32 nAlloc; /* Number of slots of aNode[] allocated */
199528 JsonNode *aNode; /* Array of nodes containing the parse */
199529 const char *zJson; /* Original JSON string */
199530 u32 *aUp; /* Index of parent of each node */
199531 u8 oom; /* Set to true if out of memory */
199532 u8 nErr; /* Number of errors seen */
199533 u16 iDepth; /* Nesting depth */
 
199534 int nJson; /* Length of the zJson string in bytes */
 
199535 u32 iHold; /* Replace cache line with the lowest iHold value */
199536 };
199537
199538 /*
199539 ** Maximum nesting depth of JSON for this implementation.
@@ -199689,10 +199829,133 @@
199689 p->zBuf[p->nUsed++] = c;
199690 }
199691 p->zBuf[p->nUsed++] = '"';
199692 assert( p->nUsed<p->nAlloc );
199693 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199694
199695 /*
199696 ** Append a function parameter value to the JSON string under
199697 ** construction.
199698 */
@@ -199820,21 +200083,42 @@
199820 case JSON_FALSE: {
199821 jsonAppendRaw(pOut, "false", 5);
199822 break;
199823 }
199824 case JSON_STRING: {
 
199825 if( pNode->jnFlags & JNODE_RAW ){
199826 assert( pNode->eU==1 );
199827 jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
199828 break;
 
 
 
 
 
 
 
 
199829 }
199830 /* no break */ deliberate_fall_through
199831 }
199832 case JSON_REAL:
 
 
 
 
 
 
 
 
199833 case JSON_INT: {
199834 assert( pNode->eU==1 );
199835 jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
 
 
 
 
199836 break;
199837 }
199838 case JSON_ARRAY: {
199839 u32 j = 1;
199840 jsonAppendChar(pOut, '[');
@@ -199946,63 +200230,45 @@
199946 sqlite3_result_int(pCtx, 0);
199947 break;
199948 }
199949 case JSON_INT: {
199950 sqlite3_int64 i = 0;
 
 
199951 const char *z;
 
 
199952 assert( pNode->eU==1 );
199953 z = pNode->u.zJContent;
199954 if( z[0]=='-' ){ z++; }
199955 while( z[0]>='0' && z[0]<='9' ){
199956 unsigned v = *(z++) - '0';
199957 if( i>=LARGEST_INT64/10 ){
199958 if( i>LARGEST_INT64/10 ) goto int_as_real;
199959 if( z[0]>='0' && z[0]<='9' ) goto int_as_real;
199960 if( v==9 ) goto int_as_real;
199961 if( v==8 ){
199962 if( pNode->u.zJContent[0]=='-' ){
199963 sqlite3_result_int64(pCtx, SMALLEST_INT64);
199964 goto int_done;
199965 }else{
199966 goto int_as_real;
199967 }
199968 }
199969 }
199970 i = i*10 + v;
199971 }
199972 if( pNode->u.zJContent[0]=='-' ){ i = -i; }
199973 sqlite3_result_int64(pCtx, i);
199974 int_done:
199975 break;
199976 int_as_real: ; /* no break */ deliberate_fall_through
199977 }
199978 case JSON_REAL: {
199979 double r;
199980 #ifdef SQLITE_AMALGAMATION
199981 const char *z;
199982 assert( pNode->eU==1 );
 
199983 z = pNode->u.zJContent;
199984 sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
199985 #else
199986 assert( pNode->eU==1 );
199987 r = strtod(pNode->u.zJContent, 0);
199988 #endif
199989 sqlite3_result_double(pCtx, r);
199990 break;
199991 }
199992 case JSON_STRING: {
199993 #if 0 /* Never happens because JNODE_RAW is only set by json_set(),
199994 ** json_insert() and json_replace() and those routines do not
199995 ** call jsonReturn() */
199996 if( pNode->jnFlags & JNODE_RAW ){
199997 assert( pNode->eU==1 );
199998 sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
199999 SQLITE_TRANSIENT);
200000 }else
200001 #endif
200002 assert( (pNode->jnFlags & JNODE_RAW)==0 );
200003 if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
200004 /* JSON formatted without any backslash-escapes */
200005 assert( pNode->eU==1 );
200006 sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
200007 SQLITE_TRANSIENT);
200008 }else{
@@ -200010,22 +200276,21 @@
200010 u32 i;
200011 u32 n = pNode->n;
200012 const char *z;
200013 char *zOut;
200014 u32 j;
 
200015 assert( pNode->eU==1 );
200016 z = pNode->u.zJContent;
200017 zOut = sqlite3_malloc( n+1 );
200018 if( zOut==0 ){
200019 sqlite3_result_error_nomem(pCtx);
200020 break;
200021 }
200022 for(i=1, j=0; i<n-1; i++){
200023 char c = z[i];
200024 if( c!='\\' ){
200025 zOut[j++] = c;
200026 }else{
200027 c = z[++i];
200028 if( c=='u' ){
200029 u32 v = jsonHexToInt4(z+i+1);
200030 i += 4;
200031 if( v==0 ) break;
@@ -200053,26 +200318,44 @@
200053 zOut[j++] = 0xe0 | (v>>12);
200054 zOut[j++] = 0x80 | ((v>>6)&0x3f);
200055 zOut[j++] = 0x80 | (v&0x3f);
200056 }
200057 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200058 }else{
200059 if( c=='b' ){
200060 c = '\b';
200061 }else if( c=='f' ){
200062 c = '\f';
200063 }else if( c=='n' ){
200064 c = '\n';
200065 }else if( c=='r' ){
200066 c = '\r';
200067 }else if( c=='t' ){
200068 c = '\t';
200069 }
200070 zOut[j++] = c;
200071 }
200072 }
200073 }
200074 zOut[j] = 0;
200075 sqlite3_result_text(pCtx, zOut, j, sqlite3_free);
200076 }
200077 break;
200078 }
@@ -200136,28 +200419,159 @@
200136 JsonNode *p;
200137 if( pParse->aNode==0 || pParse->nNode>=pParse->nAlloc ){
200138 return jsonParseAddNodeExpand(pParse, eType, n, zContent);
200139 }
200140 p = &pParse->aNode[pParse->nNode];
200141 p->eType = (u8)eType;
200142 p->jnFlags = 0;
200143 VVA( p->eU = zContent ? 1 : 0 );
200144 p->n = n;
200145 p->u.zJContent = zContent;
200146 return pParse->nNode++;
200147 }
 
 
 
 
 
 
 
200148
200149 /*
200150 ** Return true if z[] begins with 4 (or more) hexadecimal digits
200151 */
200152 static int jsonIs4Hex(const char *z){
200153 int i;
200154 for(i=0; i<4; i++) if( !sqlite3Isxdigit(z[i]) ) return 0;
200155 return 1;
200156 }
200157
200158 #ifdef SQLITE_ENABLE_JSON_NAN_INF
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200159 /*
200160 ** Extra floating-point literals to allow in JSON.
200161 */
200162 static const struct NanInfName {
200163 char c1;
@@ -200172,204 +200586,456 @@
200172 { 'i', 'I', 8, JSON_REAL, 7, "infinity", "9.0e999" },
200173 { 'n', 'N', 3, JSON_NULL, 4, "NaN", "null" },
200174 { 'q', 'Q', 4, JSON_NULL, 4, "QNaN", "null" },
200175 { 's', 'S', 4, JSON_NULL, 4, "SNaN", "null" },
200176 };
200177 #endif /* SQLITE_ENABLE_JSON_NAN_INF */
200178
200179 /*
200180 ** Parse a single JSON value which begins at pParse->zJson[i]. Return the
200181 ** index of the first character past the end of the value parsed.
200182 **
200183 ** Return negative for a syntax error. Special cases: return -2 if the
200184 ** first non-whitespace character is '}' and return -3 if the first
200185 ** non-whitespace character is ']'.
 
 
 
 
 
200186 */
200187 static int jsonParseValue(JsonParse *pParse, u32 i){
200188 char c;
200189 u32 j;
200190 int iThis;
200191 int x;
200192 JsonNode *pNode;
200193 const char *z = pParse->zJson;
200194 while( fast_isspace(z[i]) ){ i++; }
200195 if( (c = z[i])=='{' ){
 
200196 /* Parse object */
200197 iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
200198 if( iThis<0 ) return -1;
200199 for(j=i+1;;j++){
200200 while( fast_isspace(z[j]) ){ j++; }
200201 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
 
 
200202 x = jsonParseValue(pParse, j);
200203 if( x<0 ){
200204 pParse->iDepth--;
200205 if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
200206 return -1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200207 }
200208 if( pParse->oom ) return -1;
200209 pNode = &pParse->aNode[pParse->nNode-1];
200210 if( pNode->eType!=JSON_STRING ) return -1;
 
 
 
200211 pNode->jnFlags |= JNODE_LABEL;
200212 j = x;
200213 while( fast_isspace(z[j]) ){ j++; }
200214 if( z[j]!=':' ) return -1;
200215 j++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200216 x = jsonParseValue(pParse, j);
200217 pParse->iDepth--;
200218 if( x<0 ) return -1;
 
 
 
200219 j = x;
200220 while( fast_isspace(z[j]) ){ j++; }
200221 c = z[j];
200222 if( c==',' ) continue;
200223 if( c!='}' ) return -1;
200224 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200225 }
200226 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
200227 return j+1;
200228 }else if( c=='[' ){
 
200229 /* Parse array */
200230 iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
200231 if( iThis<0 ) return -1;
200232 memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
200233 for(j=i+1;;j++){
200234 while( fast_isspace(z[j]) ){ j++; }
200235 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
 
 
200236 x = jsonParseValue(pParse, j);
200237 pParse->iDepth--;
200238 if( x<0 ){
200239 if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
 
 
 
 
 
200240 return -1;
200241 }
200242 j = x;
200243 while( fast_isspace(z[j]) ){ j++; }
200244 c = z[j];
200245 if( c==',' ) continue;
200246 if( c!=']' ) return -1;
200247 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200248 }
200249 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
200250 return j+1;
200251 }else if( c=='"' ){
 
 
 
 
 
 
 
200252 /* Parse string */
200253 u8 jnFlags = 0;
 
 
200254 j = i+1;
200255 for(;;){
200256 c = z[j];
200257 if( (c & ~0x1f)==0 ){
200258 /* Control characters are not allowed in strings */
 
200259 return -1;
200260 }
200261 if( c=='\\' ){
200262 c = z[++j];
200263 if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
200264 || c=='n' || c=='r' || c=='t'
200265 || (c=='u' && jsonIs4Hex(z+j+1)) ){
200266 jnFlags = JNODE_ESCAPE;
 
 
 
 
 
 
 
 
 
 
200267 }else{
 
200268 return -1;
200269 }
200270 }else if( c=='"' ){
200271 break;
200272 }
200273 j++;
200274 }
200275 jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
200276 if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
200277 return j+1;
200278 }else if( c=='n'
200279 && strncmp(z+i,"null",4)==0
200280 && !sqlite3Isalnum(z[i+4]) ){
200281 jsonParseAddNode(pParse, JSON_NULL, 0, 0);
200282 return i+4;
200283 }else if( c=='t'
200284 && strncmp(z+i,"true",4)==0
200285 && !sqlite3Isalnum(z[i+4]) ){
200286 jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
200287 return i+4;
200288 }else if( c=='f'
200289 && strncmp(z+i,"false",5)==0
200290 && !sqlite3Isalnum(z[i+5]) ){
200291 jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
200292 return i+5;
200293 }else if( c=='-' || (c>='0' && c<='9') ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200294 /* Parse number */
200295 u8 seenDP = 0;
200296 u8 seenE = 0;
 
 
200297 assert( '-' < '0' );
 
 
 
 
200298 if( c<='0' ){
200299 j = c=='-' ? i+1 : i;
200300 if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200301 }
200302 j = i+1;
200303 for(;; j++){
200304 c = z[j];
200305 if( c>='0' && c<='9' ) continue;
200306 if( c=='.' ){
200307 if( z[j-1]=='-' ) return -1;
200308 if( seenDP ) return -1;
200309 seenDP = 1;
 
 
200310 continue;
200311 }
200312 if( c=='e' || c=='E' ){
200313 if( z[j-1]<'0' ) return -1;
200314 if( seenE ) return -1;
200315 seenDP = seenE = 1;
 
 
 
 
 
 
 
 
 
 
 
 
200316 c = z[j+1];
200317 if( c=='+' || c=='-' ){
200318 j++;
200319 c = z[j+1];
200320 }
200321 if( c<'0' || c>'9' ) return -1;
 
 
 
200322 continue;
200323 }
200324 #ifdef SQLITE_ENABLE_JSON_NAN_INF
200325 /* Non-standard JSON: Allow "-Inf" (in any case)
200326 ** to be understood as floating point literals. */
200327 if( (c=='i' || c=='I')
200328 && j==i+1
200329 && z[i]=='-'
200330 && sqlite3StrNICmp(&z[j], "inf",3)==0
200331 ){
200332 if( !sqlite3Isalnum(z[j+3]) ){
200333 jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999");
200334 return i+4;
200335 }else if( (sqlite3StrNICmp(&z[j],"infinity",8)==0 &&
200336 !sqlite3Isalnum(z[j+8])) ){
200337 jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999");
200338 return i+9;
200339 }
200340 }
200341 #endif
200342 break;
200343 }
200344 if( z[j-1]<'0' ) return -1;
200345 jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
200346 j - i, &z[i]);
 
 
 
 
 
 
 
 
200347 return j;
200348 }else if( c=='}' ){
 
 
200349 return -2; /* End of {...} */
200350 }else if( c==']' ){
 
 
200351 return -3; /* End of [...] */
200352 }else if( c==0 ){
 
 
 
 
 
 
 
 
 
200353 return 0; /* End of file */
200354 }else{
200355 #ifdef SQLITE_ENABLE_JSON_NAN_INF
200356 int k, nn;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200357 for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
200358 if( c!=aNanInfName[k].c1 && c!=aNanInfName[k].c2 ) continue;
200359 nn = aNanInfName[k].n;
200360 if( sqlite3StrNICmp(&z[i], aNanInfName[k].zMatch, nn)!=0 ){
200361 continue;
200362 }
200363 if( sqlite3Isalnum(z[i+nn]) ) continue;
200364 jsonParseAddNode(pParse, aNanInfName[k].eType,
200365 aNanInfName[k].nRepl, aNanInfName[k].zRepl);
 
200366 return i + nn;
200367 }
200368 #endif
200369 return -1; /* Syntax error */
200370 }
 
200371 }
200372
200373 /*
200374 ** Parse a complete JSON string. Return 0 on success or non-zero if there
200375 ** are any errors. If an error occurs, free all memory associated with
@@ -200389,11 +201055,18 @@
200389 i = jsonParseValue(pParse, 0);
200390 if( pParse->oom ) i = -1;
200391 if( i>0 ){
200392 assert( pParse->iDepth==0 );
200393 while( fast_isspace(zJson[i]) ) i++;
200394 if( zJson[i] ) i = -1;
 
 
 
 
 
 
 
200395 }
200396 if( i<=0 ){
200397 if( pCtx!=0 ){
200398 if( pParse->oom ){
200399 sqlite3_result_error_nomem(pCtx);
@@ -200460,10 +201133,19 @@
200460 ** of the argv array. Use the sqlite3_get_auxdata() cache for this
200461 ** parse if it is available. If the cache is not available or if it
200462 ** is no longer valid, parse the JSON again and return the new parse,
200463 ** and also register the new parse so that it will be available for
200464 ** future sqlite3_get_auxdata() calls.
 
 
 
 
 
 
 
 
 
200465 */
200466 static JsonParse *jsonParseCached(
200467 sqlite3_context *pCtx,
200468 sqlite3_value **argv,
200469 sqlite3_context *pErrCtx
@@ -200509,10 +201191,14 @@
200509 }
200510 memset(p, 0, sizeof(*p));
200511 p->zJson = (char*)&p[1];
200512 memcpy((char*)p->zJson, zJson, nJson+1);
200513 if( jsonParse(p, pErrCtx, p->zJson) ){
 
 
 
 
200514 sqlite3_free(p);
200515 return 0;
200516 }
200517 p->nJson = nJson;
200518 p->iHold = iMaxHold+1;
@@ -200523,19 +201209,28 @@
200523
200524 /*
200525 ** Compare the OBJECT label at pNode against zKey,nKey. Return true on
200526 ** a match.
200527 */
200528 static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
200529 assert( pNode->eU==1 );
200530 if( pNode->jnFlags & JNODE_RAW ){
200531 if( pNode->n!=nKey ) return 0;
200532 return strncmp(pNode->u.zJContent, zKey, nKey)==0;
200533 }else{
200534 if( pNode->n!=nKey+2 ) return 0;
200535 return strncmp(pNode->u.zJContent+1, zKey, nKey)==0;
200536 }
 
 
 
 
 
 
 
 
 
200537 }
200538
200539 /* forward declaration */
200540 static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**);
200541
@@ -201003,11 +201698,11 @@
201003 if( argc==2 ){
201004 /* With a single PATH argument */
201005 zPath = (const char*)sqlite3_value_text(argv[1]);
201006 if( zPath==0 ) return;
201007 if( flags & JSON_ABPATH ){
201008 if( zPath[0]!='$' ){
201009 /* The -> and ->> operators accept abbreviated PATH arguments. This
201010 ** is mostly for compatibility with PostgreSQL, but also for
201011 ** convenience.
201012 **
201013 ** NUMBER ==> $[NUMBER] // PG compatible
@@ -201094,16 +201789,14 @@
201094 assert( pPatch[i].eType==JSON_STRING );
201095 assert( pPatch[i].jnFlags & JNODE_LABEL );
201096 assert( pPatch[i].eU==1 );
201097 nKey = pPatch[i].n;
201098 zKey = pPatch[i].u.zJContent;
201099 assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
201100 for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
201101 assert( pTarget[j].eType==JSON_STRING );
201102 assert( pTarget[j].jnFlags & JNODE_LABEL );
201103 assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
201104 if( pTarget[j].n==nKey && strncmp(pTarget[j].u.zJContent,zKey,nKey)==0 ){
201105 if( pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH) ) break;
201106 if( pPatch[i+1].eType==JSON_NULL ){
201107 pTarget[j+1].jnFlags |= JNODE_REMOVE;
201108 }else{
201109 JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
@@ -201386,22 +202079,81 @@
201386 }
201387
201388 /*
201389 ** json_valid(JSON)
201390 **
201391 ** Return 1 if JSON is a well-formed JSON string according to RFC-7159.
201392 ** Return 0 otherwise.
201393 */
201394 static void jsonValidFunc(
201395 sqlite3_context *ctx,
201396 int argc,
201397 sqlite3_value **argv
201398 ){
201399 JsonParse *p; /* The parse */
201400 UNUSED_PARAMETER(argc);
201401 p = jsonParseCached(ctx, argv, 0);
201402 sqlite3_result_int(ctx, p!=0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201403 }
201404
201405
201406 /****************************************************************************
201407 ** Aggregate SQL function implementations
@@ -201741,18 +202493,20 @@
201741 assert( pNode->eType==JSON_STRING );
201742 assert( pNode->jnFlags & JNODE_LABEL );
201743 assert( pNode->eU==1 );
201744 z = pNode->u.zJContent;
201745 nn = pNode->n;
201746 assert( nn>=2 );
201747 assert( z[0]=='"' );
201748 assert( z[nn-1]=='"' );
201749 if( nn>2 && sqlite3Isalpha(z[1]) ){
201750 for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
201751 if( jj==nn-1 ){
201752 z++;
201753 nn -= 2;
 
 
201754 }
201755 }
201756 jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
201757 }
201758
@@ -202108,10 +202862,11 @@
202108 static FuncDef aJsonFunc[] = {
202109 JFUNCTION(json, 1, 0, jsonRemoveFunc),
202110 JFUNCTION(json_array, -1, 0, jsonArrayFunc),
202111 JFUNCTION(json_array_length, 1, 0, jsonArrayLengthFunc),
202112 JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc),
 
202113 JFUNCTION(json_extract, -1, 0, jsonExtractFunc),
202114 JFUNCTION(->, 2, JSON_JSON, jsonExtractFunc),
202115 JFUNCTION(->>, 2, JSON_SQL, jsonExtractFunc),
202116 JFUNCTION(json_insert, -1, 0, jsonSetFunc),
202117 JFUNCTION(json_object, -1, 0, jsonObjectFunc),
@@ -202632,20 +203387,21 @@
202632 ** using C-preprocessor macros. If that is unsuccessful, or if
202633 ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
202634 ** at run-time.
202635 */
202636 #ifndef SQLITE_BYTEORDER
202637 #if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
202638 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
202639 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
202640 defined(__arm__)
202641 # define SQLITE_BYTEORDER 1234
202642 #elif defined(sparc) || defined(__ppc__)
202643 # define SQLITE_BYTEORDER 4321
202644 #else
202645 # define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
202646 #endif
 
202647 #endif
202648
202649
202650 /* What version of MSVC is being used. 0 means MSVC is not being used */
202651 #ifndef MSVC_VERSION
@@ -216825,10 +217581,12 @@
216825 # define SESSIONS_STRM_CHUNK_SIZE 64
216826 # else
216827 # define SESSIONS_STRM_CHUNK_SIZE 1024
216828 # endif
216829 #endif
 
 
216830
216831 static int sessions_strm_chunk_size = SESSIONS_STRM_CHUNK_SIZE;
216832
216833 typedef struct SessionHook SessionHook;
216834 struct SessionHook {
@@ -216847,10 +217605,11 @@
216847 char *zDb; /* Name of database session is attached to */
216848 int bEnableSize; /* True if changeset_size() enabled */
216849 int bEnable; /* True if currently recording */
216850 int bIndirect; /* True if all changes are indirect */
216851 int bAutoAttach; /* True to auto-attach tables */
 
216852 int rc; /* Non-zero if an error has occurred */
216853 void *pFilterCtx; /* First argument to pass to xTableFilter */
216854 int (*xTableFilter)(void *pCtx, const char *zTab);
216855 i64 nMalloc; /* Number of bytes of data allocated */
216856 i64 nMaxChangesetSize;
@@ -216923,10 +217682,11 @@
216923 struct SessionTable {
216924 SessionTable *pNext;
216925 char *zName; /* Local name of table */
216926 int nCol; /* Number of columns in table zName */
216927 int bStat1; /* True if this is sqlite_stat1 */
 
216928 const char **azCol; /* Column names */
216929 u8 *abPK; /* Array of primary key flags */
216930 int nEntry; /* Total number of entries in hash table */
216931 int nChange; /* Size of apChange[] array */
216932 SessionChange **apChange; /* Hash table buckets */
@@ -217315,60 +218075,66 @@
217315 ** of *piHash asn *pbNullPK are undefined. Otherwise, SQLITE_OK is returned
217316 ** and the output variables are set as described above.
217317 */
217318 static int sessionPreupdateHash(
217319 sqlite3_session *pSession, /* Session object that owns pTab */
 
217320 SessionTable *pTab, /* Session table handle */
217321 int bNew, /* True to hash the new.* PK */
217322 int *piHash, /* OUT: Hash value */
217323 int *pbNullPK /* OUT: True if there are NULL values in PK */
217324 ){
217325 unsigned int h = 0; /* Hash value to return */
217326 int i; /* Used to iterate through columns */
217327
217328 assert( *pbNullPK==0 );
217329 assert( pTab->nCol==pSession->hook.xCount(pSession->hook.pCtx) );
217330 for(i=0; i<pTab->nCol; i++){
217331 if( pTab->abPK[i] ){
217332 int rc;
217333 int eType;
217334 sqlite3_value *pVal;
217335
217336 if( bNew ){
217337 rc = pSession->hook.xNew(pSession->hook.pCtx, i, &pVal);
217338 }else{
217339 rc = pSession->hook.xOld(pSession->hook.pCtx, i, &pVal);
217340 }
217341 if( rc!=SQLITE_OK ) return rc;
217342
217343 eType = sqlite3_value_type(pVal);
217344 h = sessionHashAppendType(h, eType);
217345 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
217346 i64 iVal;
217347 if( eType==SQLITE_INTEGER ){
217348 iVal = sqlite3_value_int64(pVal);
217349 }else{
217350 double rVal = sqlite3_value_double(pVal);
217351 assert( sizeof(iVal)==8 && sizeof(rVal)==8 );
217352 memcpy(&iVal, &rVal, 8);
217353 }
217354 h = sessionHashAppendI64(h, iVal);
217355 }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
217356 const u8 *z;
217357 int n;
217358 if( eType==SQLITE_TEXT ){
217359 z = (const u8 *)sqlite3_value_text(pVal);
217360 }else{
217361 z = (const u8 *)sqlite3_value_blob(pVal);
217362 }
217363 n = sqlite3_value_bytes(pVal);
217364 if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
217365 h = sessionHashAppendBlob(h, n, z);
217366 }else{
217367 assert( eType==SQLITE_NULL );
217368 assert( pTab->bStat1==0 || i!=1 );
217369 *pbNullPK = 1;
 
 
 
 
 
217370 }
217371 }
217372 }
217373
217374 *piHash = (h % pTab->nChange);
@@ -217647,16 +218413,22 @@
217647 ** if the pre-update-hook does not affect the same row as pChange, it returns
217648 ** false.
217649 */
217650 static int sessionPreupdateEqual(
217651 sqlite3_session *pSession, /* Session object that owns SessionTable */
 
217652 SessionTable *pTab, /* Table associated with change */
217653 SessionChange *pChange, /* Change to compare to */
217654 int op /* Current pre-update operation */
217655 ){
217656 int iCol; /* Used to iterate through columns */
217657 u8 *a = pChange->aRecord; /* Cursor used to scan change record */
 
 
 
 
 
217658
217659 assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE );
217660 for(iCol=0; iCol<pTab->nCol; iCol++){
217661 if( !pTab->abPK[iCol] ){
217662 a += sessionSerialLen(a);
@@ -217798,11 +218570,12 @@
217798 const char *zDb, /* Name of attached database (e.g. "main") */
217799 const char *zThis, /* Table name */
217800 int *pnCol, /* OUT: number of columns */
217801 const char **pzTab, /* OUT: Copy of zThis */
217802 const char ***pazCol, /* OUT: Array of column names for table */
217803 u8 **pabPK /* OUT: Array of booleans - true for PK col */
 
217804 ){
217805 char *zPragma;
217806 sqlite3_stmt *pStmt;
217807 int rc;
217808 sqlite3_int64 nByte;
@@ -217810,10 +218583,11 @@
217810 int nThis;
217811 int i;
217812 u8 *pAlloc = 0;
217813 char **azCol = 0;
217814 u8 *abPK = 0;
 
217815
217816 assert( pazCol && pabPK );
217817
217818 nThis = sqlite3Strlen30(zThis);
217819 if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
@@ -217854,14 +218628,19 @@
217854 if( pzTab ) *pzTab = 0;
217855 return rc;
217856 }
217857
217858 nByte = nThis + 1;
 
217859 while( SQLITE_ROW==sqlite3_step(pStmt) ){
217860 nByte += sqlite3_column_bytes(pStmt, 1);
217861 nDbCol++;
 
217862 }
 
 
 
217863 rc = sqlite3_reset(pStmt);
217864
217865 if( rc==SQLITE_OK ){
217866 nByte += nDbCol * (sizeof(const char *) + sizeof(u8) + 1);
217867 pAlloc = sessionMalloc64(pSession, nByte);
@@ -217879,10 +218658,18 @@
217879 *pzTab = (char *)pAlloc;
217880 pAlloc += nThis+1;
217881 }
217882
217883 i = 0;
 
 
 
 
 
 
 
 
217884 while( SQLITE_ROW==sqlite3_step(pStmt) ){
217885 int nName = sqlite3_column_bytes(pStmt, 1);
217886 const unsigned char *zName = sqlite3_column_text(pStmt, 1);
217887 if( zName==0 ) break;
217888 memcpy(pAlloc, zName, nName+1);
@@ -217890,11 +218677,10 @@
217890 pAlloc += nName+1;
217891 abPK[i] = sqlite3_column_int(pStmt, 5);
217892 i++;
217893 }
217894 rc = sqlite3_reset(pStmt);
217895
217896 }
217897
217898 /* If successful, populate the output variables. Otherwise, zero them and
217899 ** free any allocation made. An error code will be returned in this case.
217900 */
@@ -217907,10 +218693,11 @@
217907 *pabPK = 0;
217908 *pnCol = 0;
217909 if( pzTab ) *pzTab = 0;
217910 sessionFree(pSession, azCol);
217911 }
 
217912 sqlite3_finalize(pStmt);
217913 return rc;
217914 }
217915
217916 /*
@@ -217928,11 +218715,12 @@
217928 static int sessionInitTable(sqlite3_session *pSession, SessionTable *pTab){
217929 if( pTab->nCol==0 ){
217930 u8 *abPK;
217931 assert( pTab->azCol==0 || pTab->abPK==0 );
217932 pSession->rc = sessionTableInfo(pSession, pSession->db, pSession->zDb,
217933 pTab->zName, &pTab->nCol, 0, &pTab->azCol, &abPK
 
217934 );
217935 if( pSession->rc==SQLITE_OK ){
217936 int i;
217937 for(i=0; i<pTab->nCol; i++){
217938 if( abPK[i] ){
@@ -218000,10 +218788,11 @@
218000 SessionTable *pTab, /* Table that change applies to */
218001 SessionChange *pC /* Update pC->nMaxSize */
218002 ){
218003 i64 nNew = 2;
218004 if( pC->op==SQLITE_INSERT ){
 
218005 if( op!=SQLITE_DELETE ){
218006 int ii;
218007 for(ii=0; ii<pTab->nCol; ii++){
218008 sqlite3_value *p = 0;
218009 pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
@@ -218016,11 +218805,15 @@
218016 nNew += pC->nRecord;
218017 }
218018 }else{
218019 int ii;
218020 u8 *pCsr = pC->aRecord;
218021 for(ii=0; ii<pTab->nCol; ii++){
 
 
 
 
218022 int bChanged = 1;
218023 int nOld = 0;
218024 int eType;
218025 sqlite3_value *p = 0;
218026 pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
@@ -218100,10 +218893,11 @@
218100 ** Unless one is already present or an error occurs, an entry is added
218101 ** to the changed-rows hash table associated with table pTab.
218102 */
218103 static void sessionPreupdateOneChange(
218104 int op, /* One of SQLITE_UPDATE, INSERT, DELETE */
 
218105 sqlite3_session *pSession, /* Session object pTab is attached to */
218106 SessionTable *pTab /* Table that change applies to */
218107 ){
218108 int iHash;
218109 int bNull = 0;
@@ -218115,11 +218909,11 @@
218115 /* Load table details if required */
218116 if( sessionInitTable(pSession, pTab) ) return;
218117
218118 /* Check the number of columns in this xPreUpdate call matches the
218119 ** number of columns in the table. */
218120 if( pTab->nCol!=pSession->hook.xCount(pSession->hook.pCtx) ){
218121 pSession->rc = SQLITE_SCHEMA;
218122 return;
218123 }
218124
218125 /* Grow the hash table if required */
@@ -218148,18 +218942,20 @@
218148 }
218149
218150 /* Calculate the hash-key for this change. If the primary key of the row
218151 ** includes a NULL value, exit early. Such changes are ignored by the
218152 ** session module. */
218153 rc = sessionPreupdateHash(pSession, pTab, op==SQLITE_INSERT, &iHash, &bNull);
 
 
218154 if( rc!=SQLITE_OK ) goto error_out;
218155
218156 if( bNull==0 ){
218157 /* Search the hash table for an existing record for this row. */
218158 SessionChange *pC;
218159 for(pC=pTab->apChange[iHash]; pC; pC=pC->pNext){
218160 if( sessionPreupdateEqual(pSession, pTab, pC, op) ) break;
218161 }
218162
218163 if( pC==0 ){
218164 /* Create a new change object containing all the old values (if
218165 ** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
@@ -218170,11 +218966,11 @@
218170 assert( rc==SQLITE_OK );
218171 pTab->nEntry++;
218172
218173 /* Figure out how large an allocation is required */
218174 nByte = sizeof(SessionChange);
218175 for(i=0; i<pTab->nCol; i++){
218176 sqlite3_value *p = 0;
218177 if( op!=SQLITE_INSERT ){
218178 TESTONLY(int trc = ) pSession->hook.xOld(pSession->hook.pCtx, i, &p);
218179 assert( trc==SQLITE_OK );
218180 }else if( pTab->abPK[i] ){
@@ -218185,10 +218981,13 @@
218185 /* This may fail if SQLite value p contains a utf-16 string that must
218186 ** be converted to utf-8 and an OOM error occurs while doing so. */
218187 rc = sessionSerializeValue(0, p, &nByte);
218188 if( rc!=SQLITE_OK ) goto error_out;
218189 }
 
 
 
218190
218191 /* Allocate the change object */
218192 pC = (SessionChange *)sessionMalloc64(pSession, nByte);
218193 if( !pC ){
218194 rc = SQLITE_NOMEM;
@@ -218201,11 +219000,16 @@
218201 /* Populate the change object. None of the preupdate_old(),
218202 ** preupdate_new() or SerializeValue() calls below may fail as all
218203 ** required values and encodings have already been cached in memory.
218204 ** It is not possible for an OOM to occur in this block. */
218205 nByte = 0;
218206 for(i=0; i<pTab->nCol; i++){
 
 
 
 
 
218207 sqlite3_value *p = 0;
218208 if( op!=SQLITE_INSERT ){
218209 pSession->hook.xOld(pSession->hook.pCtx, i, &p);
218210 }else if( pTab->abPK[i] ){
218211 pSession->hook.xNew(pSession->hook.pCtx, i, &p);
@@ -218316,13 +219120,14 @@
218316 if( sqlite3_strnicmp(zDb, pSession->zDb, nDb+1) ) continue;
218317
218318 pSession->rc = sessionFindTable(pSession, zName, &pTab);
218319 if( pTab ){
218320 assert( pSession->rc==SQLITE_OK );
218321 sessionPreupdateOneChange(op, pSession, pTab);
 
218322 if( op==SQLITE_UPDATE ){
218323 sessionPreupdateOneChange(SQLITE_INSERT, pSession, pTab);
218324 }
218325 }
218326 }
218327 }
218328
@@ -218357,29 +219162,30 @@
218357 }
218358
218359 typedef struct SessionDiffCtx SessionDiffCtx;
218360 struct SessionDiffCtx {
218361 sqlite3_stmt *pStmt;
 
218362 int nOldOff;
218363 };
218364
218365 /*
218366 ** The diff hook implementations.
218367 */
218368 static int sessionDiffOld(void *pCtx, int iVal, sqlite3_value **ppVal){
218369 SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
218370 *ppVal = sqlite3_column_value(p->pStmt, iVal+p->nOldOff);
218371 return SQLITE_OK;
218372 }
218373 static int sessionDiffNew(void *pCtx, int iVal, sqlite3_value **ppVal){
218374 SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
218375 *ppVal = sqlite3_column_value(p->pStmt, iVal);
218376 return SQLITE_OK;
218377 }
218378 static int sessionDiffCount(void *pCtx){
218379 SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
218380 return p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt);
218381 }
218382 static int sessionDiffDepth(void *pCtx){
218383 (void)pCtx;
218384 return 0;
218385 }
@@ -218454,18 +219260,20 @@
218454 }
218455
218456 static char *sessionSelectFindNew(
218457 const char *zDb1, /* Pick rows in this db only */
218458 const char *zDb2, /* But not in this one */
 
218459 const char *zTbl, /* Table name */
218460 const char *zExpr
218461 ){
 
218462 char *zRet = sqlite3_mprintf(
218463 "SELECT * FROM \"%w\".\"%w\" WHERE NOT EXISTS ("
218464 " SELECT 1 FROM \"%w\".\"%w\" WHERE %s"
218465 ")",
218466 zDb1, zTbl, zDb2, zTbl, zExpr
218467 );
218468 return zRet;
218469 }
218470
218471 static int sessionDiffFindNew(
@@ -218475,11 +219283,13 @@
218475 const char *zDb1,
218476 const char *zDb2,
218477 char *zExpr
218478 ){
218479 int rc = SQLITE_OK;
218480 char *zStmt = sessionSelectFindNew(zDb1, zDb2, pTab->zName,zExpr);
 
 
218481
218482 if( zStmt==0 ){
218483 rc = SQLITE_NOMEM;
218484 }else{
218485 sqlite3_stmt *pStmt;
@@ -218486,20 +219296,43 @@
218486 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
218487 if( rc==SQLITE_OK ){
218488 SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
218489 pDiffCtx->pStmt = pStmt;
218490 pDiffCtx->nOldOff = 0;
 
218491 while( SQLITE_ROW==sqlite3_step(pStmt) ){
218492 sessionPreupdateOneChange(op, pSession, pTab);
 
218493 }
218494 rc = sqlite3_finalize(pStmt);
218495 }
218496 sqlite3_free(zStmt);
218497 }
218498
218499 return rc;
218500 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218501
218502 static int sessionDiffFindModified(
218503 sqlite3_session *pSession,
218504 SessionTable *pTab,
218505 const char *zFrom,
@@ -218511,15 +219344,17 @@
218511 pSession->zDb, zFrom, pTab->zName, pTab->azCol, pTab->abPK
218512 );
218513 if( zExpr2==0 ){
218514 rc = SQLITE_NOMEM;
218515 }else{
 
 
218516 char *zStmt = sqlite3_mprintf(
218517 "SELECT * FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)",
218518 pSession->zDb, pTab->zName, zFrom, pTab->zName, zExpr, zExpr2
218519 );
218520 if( zStmt==0 ){
218521 rc = SQLITE_NOMEM;
218522 }else{
218523 sqlite3_stmt *pStmt;
218524 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
218525
@@ -218526,16 +219361,19 @@
218526 if( rc==SQLITE_OK ){
218527 SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
218528 pDiffCtx->pStmt = pStmt;
218529 pDiffCtx->nOldOff = pTab->nCol;
218530 while( SQLITE_ROW==sqlite3_step(pStmt) ){
218531 sessionPreupdateOneChange(SQLITE_UPDATE, pSession, pTab);
 
218532 }
218533 rc = sqlite3_finalize(pStmt);
218534 }
218535 sqlite3_free(zStmt);
218536 }
 
 
 
218537 }
218538
218539 return rc;
218540 }
218541
@@ -218570,13 +219408,16 @@
218570 /* Check the table schemas match */
218571 if( rc==SQLITE_OK ){
218572 int bHasPk = 0;
218573 int bMismatch = 0;
218574 int nCol; /* Columns in zFrom.zTbl */
 
218575 u8 *abPK;
218576 const char **azCol = 0;
218577 rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, &abPK);
 
 
218578 if( rc==SQLITE_OK ){
218579 if( pTo->nCol!=nCol ){
218580 bMismatch = 1;
218581 }else{
218582 int i;
@@ -219223,19 +220064,20 @@
219223 static int sessionSelectStmt(
219224 sqlite3 *db, /* Database handle */
219225 int bIgnoreNoop,
219226 const char *zDb, /* Database name */
219227 const char *zTab, /* Table name */
 
219228 int nCol, /* Number of columns in table */
219229 const char **azCol, /* Names of table columns */
219230 u8 *abPK, /* PRIMARY KEY array */
219231 sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
219232 ){
219233 int rc = SQLITE_OK;
219234 char *zSql = 0;
219235 const char *zSep = "";
219236 const char *zCols = "*";
219237 int nSql = -1;
219238 int i;
219239
219240 SessionBuffer nooptest = {0, 0, 0};
219241 SessionBuffer pkfield = {0, 0, 0};
@@ -219250,11 +220092,10 @@
219250 "?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc
219251 );
219252 zCols = "tbl, ?2, stat";
219253 }else{
219254 for(i=0; i<nCol; i++){
219255
219256 if( abPK[i] ){
219257 sessionAppendStr(&pkfield, zSep, &rc);
219258 sessionAppendStr(&pkvar, zSep, &rc);
219259 zSep = ", ";
219260 sessionAppendIdent(&pkfield, azCol[i], &rc);
@@ -219457,24 +220298,32 @@
219457 const char **azCol = 0; /* Table columns */
219458 int i; /* Used to iterate through hash buckets */
219459 sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */
219460 int nRewind = buf.nBuf; /* Initial size of write buffer */
219461 int nNoop; /* Size of buffer after writing tbl header */
 
219462
219463 /* Check the table schema is still Ok. */
219464 rc = sessionTableInfo(0, db, pSession->zDb, zName, &nCol, 0,&azCol,&abPK);
219465 if( !rc && (pTab->nCol!=nCol || memcmp(abPK, pTab->abPK, nCol)) ){
 
 
 
 
 
 
 
219466 rc = SQLITE_SCHEMA;
219467 }
219468
219469 /* Write a table header */
219470 sessionAppendTableHdr(&buf, bPatchset, pTab, &rc);
219471
219472 /* Build and compile a statement to execute: */
219473 if( rc==SQLITE_OK ){
219474 rc = sessionSelectStmt(
219475 db, 0, pSession->zDb, zName, nCol, azCol, abPK, &pSel
219476 );
219477 }
219478
219479 nNoop = buf.nBuf;
219480 for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
@@ -219554,12 +220403,12 @@
219554 void **ppChangeset /* OUT: Buffer containing changeset */
219555 ){
219556 int rc;
219557
219558 if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE;
219559 rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset);
219560 assert( rc || pnChangeset==0
219561 || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
219562 );
219563 return rc;
219564 }
219565
@@ -219671,10 +220520,23 @@
219671 }
219672 }
219673 *(int*)pArg = pSession->bEnableSize;
219674 break;
219675 }
 
 
 
 
 
 
 
 
 
 
 
 
 
219676
219677 default:
219678 rc = SQLITE_MISUSE;
219679 }
219680
@@ -220661,10 +221523,11 @@
220661 SessionBuffer constraints; /* Deferred constraints are stored here */
220662 SessionBuffer rebase; /* Rebase information (if any) here */
220663 u8 bRebaseStarted; /* If table header is already in rebase */
220664 u8 bRebase; /* True to collect rebase information */
220665 u8 bIgnoreNoop; /* True to ignore no-op conflicts */
 
220666 };
220667
220668 /* Number of prepared UPDATE statements to cache. */
220669 #define SESSION_UPDATE_CACHE_SZ 12
220670
@@ -220911,12 +221774,13 @@
220911 static int sessionSelectRow(
220912 sqlite3 *db, /* Database handle */
220913 const char *zTab, /* Table name */
220914 SessionApplyCtx *p /* Session changeset-apply context */
220915 ){
 
220916 return sessionSelectStmt(db, p->bIgnoreNoop,
220917 "main", zTab, p->nCol, p->azCol, p->abPK, &p->pSelect
220918 );
220919 }
220920
220921 /*
220922 ** Formulate and prepare an INSERT statement to add a record to table zTab.
@@ -221608,10 +222472,11 @@
221608 sApply.azCol = 0;
221609 sApply.abPK = 0;
221610 sApply.bStat1 = 0;
221611 sApply.bDeferConstraints = 1;
221612 sApply.bRebaseStarted = 0;
 
221613 memset(&sApply.constraints, 0, sizeof(SessionBuffer));
221614
221615 /* If an xFilter() callback was specified, invoke it now. If the
221616 ** xFilter callback returns zero, skip this table. If it returns
221617 ** non-zero, proceed. */
@@ -221627,12 +222492,12 @@
221627 }else{
221628 int nMinCol = 0;
221629 int i;
221630
221631 sqlite3changeset_pk(pIter, &abPK, 0);
221632 rc = sessionTableInfo(0,
221633 db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK
221634 );
221635 if( rc!=SQLITE_OK ) break;
221636 for(i=0; i<sApply.nCol; i++){
221637 if( sApply.abPK[i] ) nMinCol = i+1;
221638 }
@@ -223510,29 +224375,34 @@
223510 fts5_tokenizer *pTokApi;
223511 int bLock; /* True when table is preparing statement */
223512 int ePattern; /* FTS_PATTERN_XXX constant */
223513
223514 /* Values loaded from the %_config table */
 
223515 int iCookie; /* Incremented when %_config is modified */
223516 int pgsz; /* Approximate page size used in %_data */
223517 int nAutomerge; /* 'automerge' setting */
223518 int nCrisisMerge; /* Maximum allowed segments per level */
223519 int nUsermerge; /* 'usermerge' setting */
223520 int nHashSize; /* Bytes of memory for in-memory hash */
223521 char *zRank; /* Name of rank function */
223522 char *zRankArgs; /* Arguments to rank function */
 
223523
223524 /* If non-NULL, points to sqlite3_vtab.base.zErrmsg. Often NULL. */
223525 char **pzErrmsg;
223526
223527 #ifdef SQLITE_DEBUG
223528 int bPrefixIndex; /* True to use prefix-indexes */
223529 #endif
223530 };
223531
223532 /* Current expected value of %_config table 'version' field */
223533 #define FTS5_CURRENT_VERSION 4
 
 
 
223534
223535 #define FTS5_CONTENT_NORMAL 0
223536 #define FTS5_CONTENT_NONE 1
223537 #define FTS5_CONTENT_EXTERNAL 2
223538
@@ -223694,10 +224564,11 @@
223694 /* The following are used internally by the fts5_index.c module. They are
223695 ** defined here only to make it easier to avoid clashes with the flags
223696 ** above. */
223697 #define FTS5INDEX_QUERY_SKIPEMPTY 0x0010
223698 #define FTS5INDEX_QUERY_NOOUTPUT 0x0020
 
223699
223700 /*
223701 ** Create/destroy an Fts5Index object.
223702 */
223703 static int sqlite3Fts5IndexOpen(Fts5Config *pConfig, int bCreate, Fts5Index**, char**);
@@ -227693,10 +228564,22 @@
227693 pConfig->zRankArgs = zRankArgs;
227694 }else if( rc==SQLITE_ERROR ){
227695 rc = SQLITE_OK;
227696 *pbBadkey = 1;
227697 }
 
 
 
 
 
 
 
 
 
 
 
 
227698 }else{
227699 *pbBadkey = 1;
227700 }
227701 return rc;
227702 }
@@ -227737,19 +228620,24 @@
227737 }
227738 }
227739 rc = sqlite3_finalize(p);
227740 }
227741
227742 if( rc==SQLITE_OK && iVersion!=FTS5_CURRENT_VERSION ){
 
 
 
227743 rc = SQLITE_ERROR;
227744 if( pConfig->pzErrmsg ){
227745 assert( 0==*pConfig->pzErrmsg );
227746 *pConfig->pzErrmsg = sqlite3_mprintf(
227747 "invalid fts5 file format (found %d, expected %d) - run 'rebuild'",
227748 iVersion, FTS5_CURRENT_VERSION
227749 );
227750 }
 
 
227751 }
227752
227753 if( rc==SQLITE_OK ){
227754 pConfig->iCookie = iCookie;
227755 }
@@ -228163,11 +229051,11 @@
228163
228164 static int sqlite3Fts5ExprAnd(Fts5Expr **pp1, Fts5Expr *p2){
228165 Fts5Parse sParse;
228166 memset(&sParse, 0, sizeof(sParse));
228167
228168 if( *pp1 ){
228169 Fts5Expr *p1 = *pp1;
228170 int nPhrase = p1->nPhrase + p2->nPhrase;
228171
228172 p1->pRoot = sqlite3Fts5ParseNode(&sParse, FTS5_AND, p1->pRoot, p2->pRoot,0);
228173 p2->pRoot = 0;
@@ -228188,11 +229076,11 @@
228188 p1->apExprPhrase = ap;
228189 }
228190 }
228191 sqlite3_free(p2->apExprPhrase);
228192 sqlite3_free(p2);
228193 }else{
228194 *pp1 = p2;
228195 }
228196
228197 return sParse.rc;
228198 }
@@ -231705,10 +232593,12 @@
231705 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
231706 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
231707 sqlite3_stmt *pIdxSelect;
231708 int nRead; /* Total number of blocks read */
231709
 
 
231710 sqlite3_stmt *pDataVersion;
231711 i64 iStructVersion; /* data_version when pStruct read */
231712 Fts5Structure *pStruct; /* Current db structure (or NULL) */
231713 };
231714
@@ -231797,13 +232687,10 @@
231797 ** Current leaf page number within segment.
231798 **
231799 ** iLeafOffset:
231800 ** Byte offset within the current leaf that is the first byte of the
231801 ** position list data (one byte passed the position-list size field).
231802 ** rowid field of the current entry. Usually this is the size field of the
231803 ** position list data. The exception is if the rowid for the current entry
231804 ** is the last thing on the leaf page.
231805 **
231806 ** pLeaf:
231807 ** Buffer containing current leaf page data. Set to NULL at EOF.
231808 **
231809 ** iTermLeafPgno, iTermLeafOffset:
@@ -232388,10 +233275,11 @@
232388 ** Add a level to the Fts5Structure.aLevel[] array of structure object
232389 ** (*ppStruct).
232390 */
232391 static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
232392 fts5StructureMakeWritable(pRc, ppStruct);
 
232393 if( *pRc==SQLITE_OK ){
232394 Fts5Structure *pStruct = *ppStruct;
232395 int nLevel = pStruct->nLevel;
232396 sqlite3_int64 nByte = (
232397 sizeof(Fts5Structure) + /* Main structure */
@@ -232846,46 +233734,29 @@
232846 assert( pLvl->bEof==0 );
232847 if( iOff<=pLvl->iFirstOff ){
232848 pLvl->bEof = 1;
232849 }else{
232850 u8 *a = pLvl->pData->p;
232851 i64 iVal;
232852 int iLimit;
232853 int ii;
232854 int nZero = 0;
232855
232856 /* Currently iOff points to the first byte of a varint. This block
232857 ** decrements iOff until it points to the first byte of the previous
232858 ** varint. Taking care not to read any memory locations that occur
232859 ** before the buffer in memory. */
232860 iLimit = (iOff>9 ? iOff-9 : 0);
232861 for(iOff--; iOff>iLimit; iOff--){
232862 if( (a[iOff-1] & 0x80)==0 ) break;
232863 }
232864
232865 fts5GetVarint(&a[iOff], (u64*)&iVal);
232866 pLvl->iRowid -= iVal;
232867 pLvl->iLeafPgno--;
232868
232869 /* Skip backwards past any 0x00 varints. */
232870 for(ii=iOff-1; ii>=pLvl->iFirstOff && a[ii]==0x00; ii--){
232871 nZero++;
232872 }
232873 if( ii>=pLvl->iFirstOff && (a[ii] & 0x80) ){
232874 /* The byte immediately before the last 0x00 byte has the 0x80 bit
232875 ** set. So the last 0x00 is only a varint 0 if there are 8 more 0x80
232876 ** bytes before a[ii]. */
232877 int bZero = 0; /* True if last 0x00 counts */
232878 if( (ii-8)>=pLvl->iFirstOff ){
232879 int j;
232880 for(j=1; j<=8 && (a[ii-j] & 0x80); j++);
232881 bZero = (j>8);
232882 }
232883 if( bZero==0 ) nZero--;
232884 }
232885 pLvl->iLeafPgno -= nZero;
232886 pLvl->iOff = iOff - nZero;
232887 }
232888
232889 return pLvl->bEof;
232890 }
232891
@@ -233077,11 +233948,11 @@
233077 static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
233078 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
233079 i64 iOff = pIter->iLeafOffset;
233080
233081 ASSERT_SZLEAF_OK(pIter->pLeaf);
233082 if( iOff>=pIter->pLeaf->szLeaf ){
233083 fts5SegIterNextPage(p, pIter);
233084 if( pIter->pLeaf==0 ){
233085 if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
233086 return;
233087 }
@@ -233176,14 +234047,16 @@
233176 if( p->rc==SQLITE_OK ){
233177 memset(pIter, 0, sizeof(*pIter));
233178 fts5SegIterSetNext(p, pIter);
233179 pIter->pSeg = pSeg;
233180 pIter->iLeafPgno = pSeg->pgnoFirst-1;
233181 fts5SegIterNextPage(p, pIter);
 
 
233182 }
233183
233184 if( p->rc==SQLITE_OK ){
233185 pIter->iLeafOffset = 4;
233186 assert( pIter->pLeaf!=0 );
233187 assert_nc( pIter->pLeaf->nn>4 );
233188 assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
233189 pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
@@ -233373,11 +234246,11 @@
233373
233374 ASSERT_SZLEAF_OK(pIter->pLeaf);
233375 iOff = pIter->iLeafOffset;
233376
233377 /* Next entry is on the next page */
233378 if( pIter->pSeg && iOff>=pIter->pLeaf->szLeaf ){
233379 fts5SegIterNextPage(p, pIter);
233380 if( p->rc || pIter->pLeaf==0 ) return;
233381 pIter->iRowid = 0;
233382 iOff = 4;
233383 }
@@ -233566,11 +234439,11 @@
233566 static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
233567 Fts5DlidxIter *pDlidx = pIter->pDlidx;
233568 Fts5Data *pLast = 0;
233569 int pgnoLast = 0;
233570
233571 if( pDlidx ){
233572 int iSegid = pIter->pSeg->iSegid;
233573 pgnoLast = fts5DlidxIterPgno(pDlidx);
233574 pLast = fts5LeafRead(p, FTS5_SEGMENT_ROWID(iSegid, pgnoLast));
233575 }else{
233576 Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
@@ -234127,11 +235000,12 @@
234127 return 0;
234128 }
234129
234130 /*
234131 ** Move the seg-iter so that it points to the first rowid on page iLeafPgno.
234132 ** It is an error if leaf iLeafPgno does not exist or contains no rowids.
 
234133 */
234134 static void fts5SegIterGotoPage(
234135 Fts5Index *p, /* FTS5 backend object */
234136 Fts5SegIter *pIter, /* Iterator to advance */
234137 int iLeafPgno
@@ -234142,25 +235016,27 @@
234142 p->rc = FTS5_CORRUPT;
234143 }else{
234144 fts5DataRelease(pIter->pNextLeaf);
234145 pIter->pNextLeaf = 0;
234146 pIter->iLeafPgno = iLeafPgno-1;
234147 fts5SegIterNextPage(p, pIter);
234148 assert( p->rc!=SQLITE_OK || pIter->iLeafPgno==iLeafPgno );
234149
234150 if( p->rc==SQLITE_OK && ALWAYS(pIter->pLeaf!=0) ){
234151 int iOff;
234152 u8 *a = pIter->pLeaf->p;
234153 int n = pIter->pLeaf->szLeaf;
234154
234155 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
234156 if( iOff<4 || iOff>=n ){
234157 p->rc = FTS5_CORRUPT;
234158 }else{
234159 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
234160 pIter->iLeafOffset = iOff;
234161 fts5SegIterLoadNPos(p, pIter);
 
 
 
 
 
234162 }
234163 }
234164 }
234165 }
234166
@@ -234871,11 +235747,11 @@
234871 /* Allocate space for the new multi-seg-iterator. */
234872 if( p->rc==SQLITE_OK ){
234873 if( iLevel<0 ){
234874 assert( pStruct->nSegment==fts5StructureCountSegments(pStruct) );
234875 nSeg = pStruct->nSegment;
234876 nSeg += (p->pHash ? 1 : 0);
234877 }else{
234878 nSeg = MIN(pStruct->aLevel[iLevel].nSeg, nSegment);
234879 }
234880 }
234881 *ppOut = pNew = fts5MultiIterAlloc(p, nSeg);
@@ -234892,11 +235768,11 @@
234892
234893 /* Initialize each of the component segment iterators. */
234894 if( p->rc==SQLITE_OK ){
234895 if( iLevel<0 ){
234896 Fts5StructureLevel *pEnd = &pStruct->aLevel[pStruct->nLevel];
234897 if( p->pHash ){
234898 /* Add a segment iterator for the current contents of the hash table. */
234899 Fts5SegIter *pIter = &pNew->aSeg[iIter++];
234900 fts5SegIterHashInit(p, pTerm, nTerm, flags, pIter);
234901 }
234902 for(pLvl=&pStruct->aLevel[0]; pLvl<pEnd; pLvl++){
@@ -235647,11 +236523,11 @@
235647 fts5BufferZero(&buf);
235648 fts5BufferGrow(&p->rc, &buf, pData->nn);
235649 fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
235650 fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
235651 fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
235652 fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff,&pData->p[iOff]);
235653 if( p->rc==SQLITE_OK ){
235654 /* Set the szLeaf field */
235655 fts5PutU16(&buf.p[2], (u16)buf.n);
235656 }
235657
@@ -235925,20 +236801,20 @@
235925 Fts5Index *p, /* FTS5 backend object */
235926 Fts5Structure **ppStruct /* IN/OUT: Current structure of index */
235927 ){
235928 const int nCrisis = p->pConfig->nCrisisMerge;
235929 Fts5Structure *pStruct = *ppStruct;
235930 int iLvl = 0;
235931
235932 assert( p->rc!=SQLITE_OK || pStruct->nLevel>0 );
235933 while( p->rc==SQLITE_OK && pStruct->aLevel[iLvl].nSeg>=nCrisis ){
235934 fts5IndexMergeLevel(p, &pStruct, iLvl, 0);
235935 assert( p->rc!=SQLITE_OK || pStruct->nLevel>(iLvl+1) );
235936 fts5StructurePromote(p, iLvl+1, pStruct);
235937 iLvl++;
235938 }
235939 *ppStruct = pStruct;
235940 }
235941
235942 static int fts5IndexReturn(Fts5Index *p){
235943 int rc = p->rc;
235944 p->rc = SQLITE_OK;
@@ -235967,10 +236843,417 @@
235967 ret += i;
235968 }
235969 }
235970 return ret;
235971 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235972
235973 /*
235974 ** Flush the contents of in-memory hash table iHash to a new level-0
235975 ** segment on disk. Also update the corresponding structure record.
235976 **
@@ -235990,10 +237273,11 @@
235990 fts5StructureInvalidate(p);
235991
235992 if( iSegid ){
235993 const int pgsz = p->pConfig->pgsz;
235994 int eDetail = p->pConfig->eDetail;
 
235995 Fts5StructureSegment *pSeg; /* New segment within pStruct */
235996 Fts5Buffer *pBuf; /* Buffer in which to assemble leaf page */
235997 Fts5Buffer *pPgidx; /* Buffer in which to assemble pgidx */
235998
235999 Fts5SegWriter writer;
@@ -236012,44 +237296,81 @@
236012 if( p->rc==SQLITE_OK ){
236013 p->rc = sqlite3Fts5HashScanInit(pHash, 0, 0);
236014 }
236015 while( p->rc==SQLITE_OK && 0==sqlite3Fts5HashScanEof(pHash) ){
236016 const char *zTerm; /* Buffer containing term */
 
236017 const u8 *pDoclist; /* Pointer to doclist for this term */
236018 int nDoclist; /* Size of doclist in bytes */
236019
236020 /* Write the term for this entry to disk. */
236021 sqlite3Fts5HashScanEntry(pHash, &zTerm, &pDoclist, &nDoclist);
236022 fts5WriteAppendTerm(p, &writer, (int)strlen(zTerm), (const u8*)zTerm);
236023 if( p->rc!=SQLITE_OK ) break;
 
 
 
 
236024
236025 assert( writer.bFirstRowidInPage==0 );
236026 if( pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){
236027 /* The entire doclist will fit on the current leaf. */
236028 fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist);
236029 }else{
 
236030 i64 iRowid = 0;
236031 u64 iDelta = 0;
236032 int iOff = 0;
236033
236034 /* The entire doclist will not fit on this leaf. The following
236035 ** loop iterates through the poslists that make up the current
236036 ** doclist. */
236037 while( p->rc==SQLITE_OK && iOff<nDoclist ){
 
236038 iOff += fts5GetVarint(&pDoclist[iOff], &iDelta);
236039 iRowid += iDelta;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236040
236041 if( writer.bFirstRowidInPage ){
236042 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
236043 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
236044 writer.bFirstRowidInPage = 0;
236045 fts5WriteDlidxAppend(p, &writer, iRowid);
236046 if( p->rc!=SQLITE_OK ) break;
236047 }else{
236048 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iDelta);
236049 }
 
236050 assert( pBuf->n<=pBuf->nSpace );
 
236051
236052 if( eDetail==FTS5_DETAIL_NONE ){
236053 if( iOff<nDoclist && pDoclist[iOff]==0 ){
236054 pBuf->p[pBuf->n++] = 0;
236055 iOff++;
@@ -236104,24 +237425,27 @@
236104 if( p->rc==SQLITE_OK ) sqlite3Fts5HashScanNext(pHash);
236105 }
236106 sqlite3Fts5HashClear(pHash);
236107 fts5WriteFinish(p, &writer, &pgnoLast);
236108
236109 /* Update the Fts5Structure. It is written back to the database by the
236110 ** fts5StructureRelease() call below. */
236111 if( pStruct->nLevel==0 ){
236112 fts5StructureAddLevel(&p->rc, &pStruct);
236113 }
236114 fts5StructureExtendLevel(&p->rc, pStruct, 0, 1, 0);
236115 if( p->rc==SQLITE_OK ){
236116 pSeg = &pStruct->aLevel[0].aSeg[ pStruct->aLevel[0].nSeg++ ];
236117 pSeg->iSegid = iSegid;
236118 pSeg->pgnoFirst = 1;
236119 pSeg->pgnoLast = pgnoLast;
236120 pStruct->nSegment++;
236121 }
236122 fts5StructurePromote(p, 0, pStruct);
 
 
 
236123 }
236124
236125 fts5IndexAutomerge(p, &pStruct, pgnoLast);
236126 fts5IndexCrisismerge(p, &pStruct);
236127 fts5StructureWrite(p, pStruct);
@@ -236858,10 +238182,11 @@
236858 sqlite3_finalize(p->pDeleter);
236859 sqlite3_finalize(p->pIdxWriter);
236860 sqlite3_finalize(p->pIdxDeleter);
236861 sqlite3_finalize(p->pIdxSelect);
236862 sqlite3_finalize(p->pDataVersion);
 
236863 sqlite3Fts5HashFree(p->pHash);
236864 sqlite3_free(p->zDataTbl);
236865 sqlite3_free(p);
236866 }
236867 return rc;
@@ -237488,10 +238813,11 @@
237488 static void fts5IndexIntegrityCheckSegment(
237489 Fts5Index *p, /* FTS5 backend object */
237490 Fts5StructureSegment *pSeg /* Segment to check internal consistency */
237491 ){
237492 Fts5Config *pConfig = p->pConfig;
 
237493 sqlite3_stmt *pStmt = 0;
237494 int rc2;
237495 int iIdxPrevLeaf = pSeg->pgnoFirst-1;
237496 int iDlidxPrevLeaf = pSeg->pgnoLast;
237497
@@ -237523,11 +238849,23 @@
237523 /* Check that the leaf contains at least one term, and that it is equal
237524 ** to or larger than the split-key in zIdxTerm. Also check that if there
237525 ** is also a rowid pointer within the leaf page header, it points to a
237526 ** location before the term. */
237527 if( pLeaf->nn<=pLeaf->szLeaf ){
237528 p->rc = FTS5_CORRUPT;
 
 
 
 
 
 
 
 
 
 
 
 
237529 }else{
237530 int iOff; /* Offset of first term on leaf */
237531 int iRowidOff; /* Offset of first rowid on leaf */
237532 int nTerm; /* Size of term on leaf in bytes */
237533 int res; /* Comparison of term and split-key */
@@ -237587,13 +238925,16 @@
237587 i64 iRowid;
237588 int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
237589 ASSERT_SZLEAF_OK(pLeaf);
237590 if( iRowidOff>=pLeaf->szLeaf ){
237591 p->rc = FTS5_CORRUPT;
237592 }else{
 
237593 fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
237594 if( iRowid!=fts5DlidxIterRowid(pDlidx) ) p->rc = FTS5_CORRUPT;
 
 
237595 }
237596 fts5DataRelease(pLeaf);
237597 }
237598 }
237599
@@ -239851,10 +241192,12 @@
239851 ){
239852 Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
239853 Fts5Config *pConfig = pTab->p.pConfig;
239854 int eType0; /* value_type() of apVal[0] */
239855 int rc = SQLITE_OK; /* Return code */
 
 
239856
239857 /* A transaction must be open when this is called. */
239858 assert( pTab->ts.eState==1 || pTab->ts.eState==2 );
239859
239860 assert( pVtab->zErrMsg==0 );
@@ -239861,10 +241204,15 @@
239861 assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
239862 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
239863 || sqlite3_value_type(apVal[0])==SQLITE_NULL
239864 );
239865 assert( pTab->p.pConfig->pzErrmsg==0 );
 
 
 
 
 
239866 pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
239867
239868 /* Put any active cursors into REQUIRE_SEEK state. */
239869 fts5TripCursors(pTab);
239870
@@ -239913,10 +241261,11 @@
239913
239914 /* DELETE */
239915 else if( nArg==1 ){
239916 i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */
239917 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0);
 
239918 }
239919
239920 /* INSERT or UPDATE */
239921 else{
239922 int eType1 = sqlite3_value_numeric_type(apVal[1]);
@@ -239928,10 +241277,11 @@
239928 else if( eType0!=SQLITE_INTEGER ){
239929 /* If this is a REPLACE, first remove the current entry (if any) */
239930 if( eConflict==SQLITE_REPLACE && eType1==SQLITE_INTEGER ){
239931 i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */
239932 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
 
239933 }
239934 fts5StorageInsert(&rc, pTab, apVal, pRowid);
239935 }
239936
239937 /* UPDATE */
@@ -239956,13 +241306,27 @@
239956 }
239957 }else{
239958 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
239959 fts5StorageInsert(&rc, pTab, apVal, pRowid);
239960 }
 
239961 }
239962 }
239963 }
 
 
 
 
 
 
 
 
 
 
 
 
 
239964
239965 pTab->p.pConfig->pzErrmsg = 0;
239966 return rc;
239967 }
239968
@@ -240819,10 +242183,11 @@
240819 static int fts5RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
240820 Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
240821 UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
240822 fts5CheckTransactionState(pTab, FTS5_ROLLBACKTO, iSavepoint);
240823 fts5TripCursors(pTab);
 
240824 return sqlite3Fts5StorageRollback(pTab->pStorage);
240825 }
240826
240827 /*
240828 ** Register a new auxiliary function with global context pGlobal.
@@ -241021,11 +242386,11 @@
241021 int nArg, /* Number of args */
241022 sqlite3_value **apUnused /* Function arguments */
241023 ){
241024 assert( nArg==0 );
241025 UNUSED_PARAM2(nArg, apUnused);
241026 sqlite3_result_text(pCtx, "fts5: 2023-04-10 13:20:51 49ba030080dd00b4fdf788fd3da057b333e705fa0fe37d653e2461bf96ca3785", -1, SQLITE_TRANSIENT);
241027 }
241028
241029 /*
241030 ** Return true if zName is the extension on one of the shadow tables used
241031 ** by this module.
241032
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -121,10 +121,14 @@
121 #if defined(_MSC_VER) && !defined(_WIN64)
122 #undef SQLITE_4_BYTE_ALIGNED_MALLOC
123 #define SQLITE_4_BYTE_ALIGNED_MALLOC
124 #endif /* defined(_MSC_VER) && !defined(_WIN64) */
125
126 #if !defined(HAVE_LOG2) && defined(_MSC_VER) && _MSC_VER<1800
127 #define HAVE_LOG2 0
128 #endif /* !defined(HAVE_LOG2) && defined(_MSC_VER) && _MSC_VER<1800 */
129
130 #endif /* SQLITE_MSVC_H */
131
132 /************** End of msvc.h ************************************************/
133 /************** Continuing where we left off in sqliteInt.h ******************/
134
@@ -452,11 +456,11 @@
456 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
457 ** [sqlite_version()] and [sqlite_source_id()].
458 */
459 #define SQLITE_VERSION "3.42.0"
460 #define SQLITE_VERSION_NUMBER 3042000
461 #define SQLITE_SOURCE_ID "2023-05-01 20:42:15 342af5b4fa0bd7c699e5497161db13d0cf795c7a5875ae30d666122e518f213b"
462
463 /*
464 ** CAPI3REF: Run-Time Library Version Numbers
465 ** KEYWORDS: sqlite3_version sqlite3_sourceid
466 **
@@ -2702,29 +2706,29 @@
2706 ** additional information. This feature can also be turned on and off
2707 ** using the [PRAGMA legacy_alter_table] statement.
2708 ** </dd>
2709 **
2710 ** [[SQLITE_DBCONFIG_DQS_DML]]
2711 ** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
2712 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2713 ** the legacy [double-quoted string literal] misfeature for DML statements
2714 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2715 ** default value of this setting is determined by the [-DSQLITE_DQS]
2716 ** compile-time option.
2717 ** </dd>
2718 **
2719 ** [[SQLITE_DBCONFIG_DQS_DDL]]
2720 ** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
2721 ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
2722 ** the legacy [double-quoted string literal] misfeature for DDL statements,
2723 ** such as CREATE TABLE and CREATE INDEX. The
2724 ** default value of this setting is determined by the [-DSQLITE_DQS]
2725 ** compile-time option.
2726 ** </dd>
2727 **
2728 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2729 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
2730 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2731 ** assume that database schemas are untainted by malicious content.
2732 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2733 ** takes additional defensive steps to protect the application from harm
2734 ** including:
@@ -2740,20 +2744,20 @@
2744 ** all applications are advised to turn it off if possible. This setting
2745 ** can also be controlled using the [PRAGMA trusted_schema] statement.
2746 ** </dd>
2747 **
2748 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2749 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2750 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2751 ** the legacy file format flag. When activated, this flag causes all newly
2752 ** created database file to have a schema format version number (the 4-byte
2753 ** integer found at offset 44 into the database header) of 1. This in turn
2754 ** means that the resulting database file will be readable and writable by
2755 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2756 ** newly created databases are generally not understandable by SQLite versions
2757 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2758 ** is now scarcely any need to generate database files that are compatible
2759 ** all the way back to version 3.0.0, and so this setting is of little
2760 ** practical use, but is provided so that SQLite can continue to claim the
2761 ** ability to generate new database files that are compatible with version
2762 ** 3.0.0.
2763 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
@@ -2762,27 +2766,39 @@
2766 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2767 ** either generated columns or decending indexes.
2768 ** </dd>
2769 **
2770 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2771 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2772 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
2773 ** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
2774 ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2775 ** statistics. For statistics to be collected, the flag must be set on
2776 ** the database handle both when the SQL statement is prepared and when it
2777 ** is stepped. The flag is set (collection of statistics is enabled)
2778 ** by default. This option takes two arguments: an integer and a pointer to
2779 ** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2780 ** leave unchanged the statement scanstatus option. If the second argument
2781 ** is not NULL, then the value of the statement scanstatus setting after
2782 ** processing the first argument is written into the integer that the second
2783 ** argument points to.
2784 ** </dd>
2785 **
2786 ** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2787 ** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
2788 ** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
2789 ** in which tables and indexes are scanned so that the scans start at the end
2790 ** and work toward the beginning rather than starting at the beginning and
2791 ** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2792 ** same as setting [PRAGMA reverse_unordered_selects]. This option takes
2793 ** two arguments which are an integer and a pointer to an integer. The first
2794 ** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2795 ** reverse scan order flag, respectively. If the second argument is not NULL,
2796 ** then 0 or 1 is written into the integer that the second argument points to
2797 ** depending on if the reverse scan order flag is set after processing the
2798 ** first argument.
2799 ** </dd>
2800 **
2801 ** </dl>
2802 */
2803 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2804 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
@@ -2800,11 +2816,11 @@
2816 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
2817 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
2818 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
2819 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
2820 #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2821 #define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2822 #define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
2823 #define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
2824
2825 /*
2826 ** CAPI3REF: Enable Or Disable Extended Result Codes
@@ -11106,20 +11122,24 @@
11122 ** [sqlite3session_create()] for details.
11123 */
11124 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
11125
11126 /*
11127 ** CAPI3REF: Configure a Session Object
11128 ** METHOD: sqlite3_session
11129 **
11130 ** This method is used to configure a session object after it has been
11131 ** created. At present the only valid values for the second parameter are
11132 ** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].
11133 **
11134 */
11135 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11136
11137 /*
11138 ** CAPI3REF: Options for sqlite3session_object_config
11139 **
11140 ** The following values may passed as the the 2nd parameter to
11141 ** sqlite3session_object_config().
11142 **
11143 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
11144 ** This option is used to set, clear or query the flag that enables
11145 ** the [sqlite3session_changeset_size()] API. Because it imposes some
@@ -11131,16 +11151,25 @@
11151 ** variable is set to 1 if the sqlite3session_changeset_size() API is
11152 ** enabled following the current call, or 0 otherwise.
11153 **
11154 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11155 ** the first table has been attached to the session object.
11156 **
11157 ** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>
11158 ** This option is used to set, clear or query the flag that enables
11159 ** collection of data for tables with no explicit PRIMARY KEY.
11160 **
11161 ** Normally, tables with no explicit PRIMARY KEY are simply ignored
11162 ** by the sessions module. However, if this flag is set, it behaves
11163 ** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted
11164 ** as their leftmost columns.
11165 **
11166 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11167 ** the first table has been attached to the session object.
11168 */
11169 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
11170 #define SQLITE_SESSION_OBJCONFIG_ROWID 2
 
 
 
11171
11172 /*
11173 ** CAPI3REF: Enable Or Disable A Session Object
11174 ** METHOD: sqlite3_session
11175 **
@@ -13652,11 +13681,11 @@
13681 # define SQLITE_INLINE __forceinline
13682 #else
13683 # define SQLITE_NOINLINE
13684 # define SQLITE_INLINE
13685 #endif
13686 #if defined(SQLITE_COVERAGE_TEST) || defined(__STRICT_ANSI__)
13687 # undef SQLITE_INLINE
13688 # define SQLITE_INLINE
13689 #endif
13690
13691 /*
@@ -20020,19 +20049,23 @@
20049 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
20050 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
20051 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
20052 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
20053 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
20054 # define sqlite3JsonId1(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x42)
20055 # define sqlite3JsonId2(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x46)
20056 #else
20057 # define sqlite3Toupper(x) toupper((unsigned char)(x))
20058 # define sqlite3Isspace(x) isspace((unsigned char)(x))
20059 # define sqlite3Isalnum(x) isalnum((unsigned char)(x))
20060 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
20061 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
20062 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
20063 # define sqlite3Tolower(x) tolower((unsigned char)(x))
20064 # define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
20065 # define sqlite3JsonId1(x) (sqlite3IsIdChar(x)&&(x)<'0')
20066 # define sqlite3JsonId2(x) sqlite3IsIdChar(x)
20067 #endif
20068 SQLITE_PRIVATE int sqlite3IsIdChar(u8);
20069
20070 /*
20071 ** Internal function prototypes
@@ -22161,11 +22194,11 @@
22194 ** isalpha() 0x02
22195 ** isdigit() 0x04
22196 ** isalnum() 0x06
22197 ** isxdigit() 0x08
22198 ** toupper() 0x20
22199 ** SQLite identifier character 0x40 $, _, or non-ascii
22200 ** Quote character 0x80
22201 **
22202 ** Bit 0x20 is set if the mapped character requires translation to upper
22203 ** case. i.e. if the character is a lower-case ASCII character.
22204 ** If x is a lower-case ASCII character, then its upper-case equivalent
@@ -34434,17 +34467,19 @@
34467 }else{
34468 x = v;
34469 }
34470 i = sizeof(zTemp)-2;
34471 zTemp[sizeof(zTemp)-1] = 0;
34472 while( 1 /*exit-by-break*/ ){
34473 zTemp[i] = (x%10) + '0';
34474 x = x/10;
34475 if( x==0 ) break;
34476 i--;
34477 };
34478 if( v<0 ) zTemp[--i] = '-';
34479 memcpy(zOut, &zTemp[i], sizeof(zTemp)-i);
34480 return sizeof(zTemp)-1-i;
34481 }
34482
34483 /*
34484 ** Compare the 19-character string zNum against the text representation
34485 ** value 2^63: 9223372036854775808. Return negative, zero, or positive
@@ -34605,11 +34640,13 @@
34640 for(i=2; z[i]=='0'; i++){}
34641 for(k=i; sqlite3Isxdigit(z[k]); k++){
34642 u = u*16 + sqlite3HexToInt(z[k]);
34643 }
34644 memcpy(pOut, &u, 8);
34645 if( k-i>16 ) return 2;
34646 if( z[k]!=0 ) return 1;
34647 return 0;
34648 }else
34649 #endif /* SQLITE_OMIT_HEX_INTEGER */
34650 {
34651 return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8);
34652 }
@@ -34641,11 +34678,11 @@
34678 && sqlite3Isxdigit(zNum[2])
34679 ){
34680 u32 u = 0;
34681 zNum += 2;
34682 while( zNum[0]=='0' ) zNum++;
34683 for(i=0; i<8 && sqlite3Isxdigit(zNum[i]); i++){
34684 u = u*16 + sqlite3HexToInt(zNum[i]);
34685 }
34686 if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){
34687 memcpy(pValue, &u, 4);
34688 return 1;
@@ -37137,11 +37174,11 @@
37174 # define SQLITE_ENABLE_LOCKING_STYLE 0
37175 # endif
37176 #endif
37177
37178 /* Use pread() and pwrite() if they are available */
37179 #if defined(__APPLE__) || defined(__linux__)
37180 # define HAVE_PREAD 1
37181 # define HAVE_PWRITE 1
37182 #endif
37183 #if defined(HAVE_PREAD64) && defined(HAVE_PWRITE64)
37184 # undef USE_PREAD
@@ -40387,16 +40424,10 @@
40424
40425 /*
40426 ** Seek to the offset passed as the second argument, then read cnt
40427 ** bytes into pBuf. Return the number of bytes actually read.
40428 **
 
 
 
 
 
 
40429 ** To avoid stomping the errno value on a failed read the lastErrno value
40430 ** is set before returning.
40431 */
40432 static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
40433 int got;
@@ -50419,11 +50450,11 @@
50450 &extendedParameters);
50451 if( h!=INVALID_HANDLE_VALUE ) break;
50452 if( isReadWrite ){
50453 int rc2, isRO = 0;
50454 sqlite3BeginBenignMalloc();
50455 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
50456 sqlite3EndBenignMalloc();
50457 if( rc2==SQLITE_OK && isRO ) break;
50458 }
50459 }while( winRetryIoerr(&cnt, &lastErrno) );
50460 #else
@@ -50436,11 +50467,11 @@
50467 NULL);
50468 if( h!=INVALID_HANDLE_VALUE ) break;
50469 if( isReadWrite ){
50470 int rc2, isRO = 0;
50471 sqlite3BeginBenignMalloc();
50472 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
50473 sqlite3EndBenignMalloc();
50474 if( rc2==SQLITE_OK && isRO ) break;
50475 }
50476 }while( winRetryIoerr(&cnt, &lastErrno) );
50477 #endif
@@ -50456,11 +50487,11 @@
50487 NULL);
50488 if( h!=INVALID_HANDLE_VALUE ) break;
50489 if( isReadWrite ){
50490 int rc2, isRO = 0;
50491 sqlite3BeginBenignMalloc();
50492 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
50493 sqlite3EndBenignMalloc();
50494 if( rc2==SQLITE_OK && isRO ) break;
50495 }
50496 }while( winRetryIoerr(&cnt, &lastErrno) );
50497 }
@@ -50678,10 +50709,17 @@
50709 UNUSED_PARAMETER(pVfs);
50710
50711 SimulateIOError( return SQLITE_IOERR_ACCESS; );
50712 OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
50713 zFilename, flags, pResOut));
50714
50715 if( zFilename==0 ){
50716 *pResOut = 0;
50717 OSTRACE(("ACCESS name=%s, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
50718 zFilename, pResOut, *pResOut));
50719 return SQLITE_OK;
50720 }
50721
50722 zConverted = winConvertFromUtf8Filename(zFilename);
50723 if( zConverted==0 ){
50724 OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
50725 return SQLITE_IOERR_NOMEM_BKPT;
@@ -52835,15 +52873,19 @@
52873 # define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
52874 static void pcachePageTrace(int i, sqlite3_pcache_page *pLower){
52875 PgHdr *pPg;
52876 unsigned char *a;
52877 int j;
52878 if( pLower==0 ){
52879 printf("%3d: NULL\n", i);
52880 }else{
52881 pPg = (PgHdr*)pLower->pExtra;
52882 printf("%3d: nRef %2lld flgs %02x data ", i, pPg->nRef, pPg->flags);
52883 a = (unsigned char *)pLower->pBuf;
52884 for(j=0; j<12; j++) printf("%02x", a[j]);
52885 printf(" ptr %p\n", pPg);
52886 }
52887 }
52888 static void pcacheDump(PCache *pCache){
52889 int N;
52890 int i;
52891 sqlite3_pcache_page *pLower;
@@ -52852,13 +52894,12 @@
52894 if( pCache->pCache==0 ) return;
52895 N = sqlite3PcachePagecount(pCache);
52896 if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
52897 for(i=1; i<=N; i++){
52898 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
 
52899 pcachePageTrace(i, pLower);
52900 if( pLower && ((PgHdr*)pLower)->pPage==0 ){
52901 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
52902 }
52903 }
52904 }
52905 #else
@@ -58242,10 +58283,12 @@
58283 */
58284 static int pager_truncate(Pager *pPager, Pgno nPage){
58285 int rc = SQLITE_OK;
58286 assert( pPager->eState!=PAGER_ERROR );
58287 assert( pPager->eState!=PAGER_READER );
58288 PAGERTRACE(("Truncate %d npage %u\n", PAGERID(pPager), nPage));
58289
58290
58291 if( isOpen(pPager->fd)
58292 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
58293 ){
58294 i64 currentSize, newSize;
@@ -61159,10 +61202,14 @@
61202
61203 assert( !isOpen(pPager->fd) || !MEMDB );
61204 if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
61205 if( pgno>pPager->mxPgno ){
61206 rc = SQLITE_FULL;
61207 if( pgno<=pPager->dbSize ){
61208 sqlite3PcacheRelease(pPg);
61209 pPg = 0;
61210 }
61211 goto pager_acquire_err;
61212 }
61213 if( noContent ){
61214 /* Failure to set the bits in the InJournal bit-vectors is benign.
61215 ** It merely means that we might do some extra work to journal a
@@ -61323,14 +61370,16 @@
61370 }
61371
61372 /*
61373 ** Release a page reference.
61374 **
61375 ** The sqlite3PagerUnref() and sqlite3PagerUnrefNotNull() may only be used
61376 ** if we know that the page being released is not the last reference to page1.
61377 ** The btree layer always holds page1 open until the end, so these first
61378 ** two routines can be used to release any page other than BtShared.pPage1.
61379 ** The assert() at tag-20230419-2 proves that this constraint is always
61380 ** honored.
61381 **
61382 ** Use sqlite3PagerUnrefPageOne() to release page1. This latter routine
61383 ** checks the total number of outstanding pages and if the number of
61384 ** pages reaches zero it drops the database lock.
61385 */
@@ -61342,11 +61391,11 @@
61391 pagerReleaseMapPage(pPg);
61392 }else{
61393 sqlite3PcacheRelease(pPg);
61394 }
61395 /* Do not use this routine to release the last reference to page1 */
61396 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 ); /* tag-20230419-2 */
61397 }
61398 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
61399 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
61400 }
61401 SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *pPg){
@@ -64113,23 +64162,44 @@
64162 }
64163
64164 assert( nByte>=8 );
64165 assert( (nByte&0x00000007)==0 );
64166 assert( nByte<=65536 );
64167 assert( nByte%4==0 );
64168
64169 if( !nativeCksum ){
 
 
 
 
 
64170 do {
64171 s1 += BYTESWAP32(aData[0]) + s2;
64172 s2 += BYTESWAP32(aData[1]) + s1;
64173 aData += 2;
64174 }while( aData<aEnd );
64175 }else if( nByte%64==0 ){
64176 do {
64177 s1 += *aData++ + s2;
64178 s2 += *aData++ + s1;
64179 s1 += *aData++ + s2;
64180 s2 += *aData++ + s1;
64181 s1 += *aData++ + s2;
64182 s2 += *aData++ + s1;
64183 s1 += *aData++ + s2;
64184 s2 += *aData++ + s1;
64185 s1 += *aData++ + s2;
64186 s2 += *aData++ + s1;
64187 s1 += *aData++ + s2;
64188 s2 += *aData++ + s1;
64189 s1 += *aData++ + s2;
64190 s2 += *aData++ + s1;
64191 s1 += *aData++ + s2;
64192 s2 += *aData++ + s1;
64193 }while( aData<aEnd );
64194 }else{
64195 do {
64196 s1 += *aData++ + s2;
64197 s2 += *aData++ + s1;
64198 }while( aData<aEnd );
64199 }
64200 assert( aData==aEnd );
64201
64202 aOut[0] = s1;
64203 aOut[1] = s2;
64204 }
64205
@@ -76202,11 +76272,11 @@
76272 aAfter[j] = iAfter;
76273 break;
76274 }
76275 }
76276 if( j>=nFree ){
76277 if( nFree>=(int)(sizeof(aOfst)/sizeof(aOfst[0])) ){
76278 for(j=0; j<nFree; j++){
76279 freeSpace(pPg, aOfst[j], aAfter[j]-aOfst[j]);
76280 }
76281 nFree = 0;
76282 }
@@ -77907,11 +77977,11 @@
77977 return btreeOverwriteCell(pCur, &x2);
77978 }
77979 }
77980 }
77981 assert( pCur->eState==CURSOR_VALID
77982 || (pCur->eState==CURSOR_INVALID && loc) || CORRUPT_DB );
77983
77984 pPage = pCur->pPage;
77985 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
77986 assert( pPage->leaf || !pPage->intKey );
77987 if( pPage->nFree<0 ){
@@ -80157,17 +80227,11 @@
80227 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
80228 assert( p->bDestLocked );
80229 assert( !isFatalError(p->rc) );
80230 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
80231 assert( zSrcData );
80232 assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
 
 
 
 
 
 
80233
80234 /* This loop runs once for each destination page spanned by the source
80235 ** page. For each iteration, variable iOff is set to the byte offset
80236 ** of the destination page.
80237 */
@@ -80296,11 +80360,14 @@
80360 /* Do not allow backup if the destination database is in WAL mode
80361 ** and the page sizes are different between source and destination */
80362 pgszSrc = sqlite3BtreeGetPageSize(p->pSrc);
80363 pgszDest = sqlite3BtreeGetPageSize(p->pDest);
80364 destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p->pDest));
80365 if( SQLITE_OK==rc
80366 && (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
80367 && pgszSrc!=pgszDest
80368 ){
80369 rc = SQLITE_READONLY;
80370 }
80371
80372 /* Now that there is a read-lock on the source database, query the
80373 ** source pager for the number of pages in the database.
@@ -80845,10 +80912,11 @@
80912 Mem tmp;
80913 char zBuf[100];
80914 char *z;
80915 int i, j, incr;
80916 if( (p->flags & MEM_Str)==0 ) return 1;
80917 if( p->db && p->db->mallocFailed ) return 1;
80918 if( p->flags & MEM_Term ){
80919 /* Insure that the string is properly zero-terminated. Pay particular
80920 ** attention to the case where p->n is odd */
80921 if( p->szMalloc>0 && p->z==p->zMalloc ){
80922 assert( p->enc==SQLITE_UTF8 || p->szMalloc >= ((p->n+1)&~1)+2 );
@@ -83508,10 +83576,12 @@
83576 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
83577 int nMaxArgs = *pMaxFuncArgs;
83578 Op *pOp;
83579 Parse *pParse = p->pParse;
83580 int *aLabel = pParse->aLabel;
83581
83582 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
83583 p->readOnly = 1;
83584 p->bIsReader = 0;
83585 pOp = &p->aOp[p->nOp-1];
83586 assert( p->aOp[0].opcode==OP_Init );
83587 while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
@@ -83567,10 +83637,11 @@
83637 /* The mkopcodeh.tcl script has so arranged things that the only
83638 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
83639 ** have non-negative values for P2. */
83640 assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
83641 assert( ADDR(pOp->p2)<-pParse->nLabel );
83642 assert( aLabel!=0 ); /* True because of tag-20230419-1 */
83643 pOp->p2 = aLabel[ADDR(pOp->p2)];
83644 }
83645 break;
83646 }
83647 }
@@ -84310,11 +84381,11 @@
84381 }
84382 }
84383
84384 /* Return the most recently added opcode
84385 */
84386 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetLastOp(Vdbe *p){
84387 return sqlite3VdbeGetOp(p, p->nOp - 1);
84388 }
84389
84390 #if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
84391 /*
@@ -88039,10 +88110,20 @@
88110 sqlite3 *db = v->db;
88111 i64 iKey2;
88112 PreUpdate preupdate;
88113 const char *zTbl = pTab->zName;
88114 static const u8 fakeSortOrder = 0;
88115 #ifdef SQLITE_DEBUG
88116 int nRealCol;
88117 if( pTab->tabFlags & TF_WithoutRowid ){
88118 nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn;
88119 }else if( pTab->tabFlags & TF_HasVirtual ){
88120 nRealCol = pTab->nNVCol;
88121 }else{
88122 nRealCol = pTab->nCol;
88123 }
88124 #endif
88125
88126 assert( db->pPreUpdate==0 );
88127 memset(&preupdate, 0, sizeof(PreUpdate));
88128 if( HasRowid(pTab)==0 ){
88129 iKey1 = iKey2 = 0;
@@ -88055,12 +88136,12 @@
88136 }
88137 }
88138
88139 assert( pCsr!=0 );
88140 assert( pCsr->eCurType==CURTYPE_BTREE );
88141 assert( pCsr->nField==nRealCol
88142 || (pCsr->nField==nRealCol+1 && op==SQLITE_DELETE && iReg==-1)
88143 );
88144
88145 preupdate.v = v;
88146 preupdate.pCsr = pCsr;
88147 preupdate.op = op;
@@ -89429,13 +89510,13 @@
89510 p = (Vdbe *)pStmt;
89511 db = p->db;
89512 assert( db!=0 );
89513 n = sqlite3_column_count(pStmt);
89514 if( N<n && N>=0 ){
89515 u8 prior_mallocFailed = db->mallocFailed;
89516 N += useType*n;
89517 sqlite3_mutex_enter(db->mutex);
 
89518 #ifndef SQLITE_OMIT_UTF16
89519 if( useUtf16 ){
89520 ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
89521 }else
89522 #endif
@@ -89443,11 +89524,12 @@
89524 ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
89525 }
89526 /* A malloc may have failed inside of the _text() call. If this
89527 ** is the case, clear the mallocFailed flag and return NULL.
89528 */
89529 assert( db->mallocFailed==0 || db->mallocFailed==1 );
89530 if( db->mallocFailed > prior_mallocFailed ){
89531 sqlite3OomClear(db);
89532 ret = 0;
89533 }
89534 sqlite3_mutex_leave(db->mutex);
89535 }
@@ -93333,11 +93415,11 @@
93415 */
93416 case OP_IfNullRow: { /* jump */
93417 VdbeCursor *pC;
93418 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
93419 pC = p->apCsr[pOp->p1];
93420 if( pC && pC->nullRow ){
93421 sqlite3VdbeMemSetNull(aMem + pOp->p3);
93422 goto jump_to_p2;
93423 }
93424 break;
93425 }
@@ -93828,11 +93910,11 @@
93910 pIn1->flags |= MEM_IntReal;
93911 pIn1->flags &= ~MEM_Int;
93912 }else{
93913 pIn1->u.r = (double)pIn1->u.i;
93914 pIn1->flags |= MEM_Real;
93915 pIn1->flags &= ~(MEM_Int|MEM_Str);
93916 }
93917 }
93918 REGISTER_TRACE((int)(pIn1-aMem), pIn1);
93919 zAffinity++;
93920 if( zAffinity[0]==0 ) break;
@@ -107198,28 +107280,31 @@
107280
107281 /*
107282 ** Join two expressions using an AND operator. If either expression is
107283 ** NULL, then just return the other expression.
107284 **
107285 ** If one side or the other of the AND is known to be false, and neither side
107286 ** is part of an ON clause, then instead of returning an AND expression,
107287 ** just return a constant expression with a value of false.
107288 */
107289 SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
107290 sqlite3 *db = pParse->db;
107291 if( pLeft==0 ){
107292 return pRight;
107293 }else if( pRight==0 ){
107294 return pLeft;
 
 
 
 
 
 
107295 }else{
107296 u32 f = pLeft->flags | pRight->flags;
107297 if( (f&(EP_OuterON|EP_InnerON|EP_IsFalse))==EP_IsFalse
107298 && !IN_RENAME_OBJECT
107299 ){
107300 sqlite3ExprDeferredDelete(pParse, pLeft);
107301 sqlite3ExprDeferredDelete(pParse, pRight);
107302 return sqlite3Expr(db, TK_INTEGER, "0");
107303 }else{
107304 return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
107305 }
107306 }
107307 }
107308
107309 /*
107310 ** Construct a new expression node for a function with multiple
@@ -112373,11 +112458,11 @@
112458 int iAgg = pExpr->iAgg;
112459 Parse *pParse = pWalker->pParse;
112460 sqlite3 *db = pParse->db;
112461 assert( iAgg>=0 );
112462 if( pExpr->op!=TK_AGG_FUNCTION ){
112463 if( iAgg<pAggInfo->nColumn
112464 && pAggInfo->aCol[iAgg].pCExpr==pExpr
112465 ){
112466 pExpr = sqlite3ExprDup(db, pExpr, 0);
112467 if( pExpr ){
112468 pAggInfo->aCol[iAgg].pCExpr = pExpr;
@@ -112578,11 +112663,11 @@
112663 findOrCreateAggInfoColumn(pParse, pAggInfo, pExpr);
112664 break;
112665 } /* endif pExpr->iTable==pItem->iCursor */
112666 } /* end loop over pSrcList */
112667 }
112668 return WRC_Continue;
112669 }
112670 case TK_AGG_FUNCTION: {
112671 if( (pNC->ncFlags & NC_InAggFunc)==0
112672 && pWalker->walkerDepth==pExpr->op2
112673 ){
@@ -114075,10 +114160,23 @@
114160 }
114161
114162 sqlite3_free(zQuot);
114163 return rc;
114164 }
114165
114166 /*
114167 ** Set all pEList->a[].fg.eEName fields in the expression-list to val.
114168 */
114169 static void renameSetENames(ExprList *pEList, int val){
114170 if( pEList ){
114171 int i;
114172 for(i=0; i<pEList->nExpr; i++){
114173 assert( val==ENAME_NAME || pEList->a[i].fg.eEName==ENAME_NAME );
114174 pEList->a[i].fg.eEName = val;
114175 }
114176 }
114177 }
114178
114179 /*
114180 ** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
114181 ** it was read from the schema of database zDb. Return SQLITE_OK if
114182 ** successful. Otherwise, return an SQLite error code and leave an error
@@ -114123,11 +114221,21 @@
114221 if( pSel==0 ){
114222 pStep->pExprList = 0;
114223 pSrc = 0;
114224 rc = SQLITE_NOMEM;
114225 }else{
114226 /* pStep->pExprList contains an expression-list used for an UPDATE
114227 ** statement. So the a[].zEName values are the RHS of the
114228 ** "<col> = <expr>" clauses of the UPDATE statement. So, before
114229 ** running SelectPrep(), change all the eEName values in
114230 ** pStep->pExprList to ENAME_SPAN (from their current value of
114231 ** ENAME_NAME). This is to prevent any ids in ON() clauses that are
114232 ** part of pSrc from being incorrectly resolved against the
114233 ** a[].zEName values as if they were column aliases. */
114234 renameSetENames(pStep->pExprList, ENAME_SPAN);
114235 sqlite3SelectPrep(pParse, pSel, 0);
114236 renameSetENames(pStep->pExprList, ENAME_NAME);
114237 rc = pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
114238 assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
114239 assert( pSrc==pSel->pSrc );
114240 if( pStep->pExprList ) pSel->pEList = 0;
114241 pSel->pSrc = 0;
@@ -116952,11 +117060,11 @@
117060 assert( db->lookaside.bDisable );
117061 if( (pStat4 = sqlite3FindTable(db, "sqlite_stat4", zDb))!=0
117062 && IsOrdinaryTable(pStat4)
117063 ){
117064 rc = loadStatTbl(db,
117065 "SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx COLLATE nocase",
117066 "SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4",
117067 zDb
117068 );
117069 }
117070 return rc;
@@ -129027,26 +129135,26 @@
129135 zFrom = pFKey->pFrom->zName;
129136 nFrom = sqlite3Strlen30(zFrom);
129137
129138 if( action==OE_Restrict ){
129139 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
129140 SrcList *pSrc;
 
129141 Expr *pRaise;
129142
 
 
 
 
 
129143 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
129144 if( pRaise ){
129145 pRaise->affExpr = OE_Abort;
129146 }
129147 pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
129148 if( pSrc ){
129149 assert( pSrc->nSrc==1 );
129150 pSrc->a[0].zName = sqlite3DbStrDup(db, zFrom);
129151 pSrc->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
129152 }
129153 pSelect = sqlite3SelectNew(pParse,
129154 sqlite3ExprListAppend(pParse, 0, pRaise),
129155 pSrc,
129156 pWhere,
129157 0, 0, 0, 0, 0
129158 );
129159 pWhere = 0;
129160 }
@@ -137995,11 +138103,13 @@
138103 encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
138104 if( encoding==0 ) encoding = SQLITE_UTF8;
138105 #else
138106 encoding = SQLITE_UTF8;
138107 #endif
138108 if( db->nVdbeActive>0 && encoding!=ENC(db)
138109 && (db->mDbFlags & DBFLAG_Vacuum)==0
138110 ){
138111 rc = SQLITE_LOCKED;
138112 goto initone_error_out;
138113 }else{
138114 sqlite3SetTextEncoding(db, encoding);
138115 }
@@ -138389,11 +138499,15 @@
138499 sParse.pOuterParse = db->pParse;
138500 db->pParse = &sParse;
138501 sParse.db = db;
138502 sParse.pReprepare = pReprepare;
138503 assert( ppStmt && *ppStmt==0 );
138504 if( db->mallocFailed ){
138505 sqlite3ErrorMsg(&sParse, "out of memory");
138506 db->errCode = rc = SQLITE_NOMEM;
138507 goto end_prepare;
138508 }
138509 assert( sqlite3_mutex_held(db->mutex) );
138510
138511 /* For a long-term use prepared statement avoid the use of
138512 ** lookaside memory.
138513 */
@@ -141079,11 +141193,11 @@
141193
141194 assert( pSelect!=0 );
141195 assert( (pSelect->selFlags & SF_Resolved)!=0 );
141196 assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
141197 assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
141198 if( db->mallocFailed || IN_RENAME_OBJECT ) return;
141199 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
141200 a = pSelect->pEList->a;
141201 memset(&sNC, 0, sizeof(sNC));
141202 sNC.pSrcList = pSelect->pSrc;
141203 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
@@ -141124,22 +141238,20 @@
141238 if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
141239 zType = sqlite3StdType[j];
141240 break;
141241 }
141242 }
141243 }
141244 }
141245 if( zType ){
141246 i64 m = sqlite3Strlen30(zType);
141247 n = sqlite3Strlen30(pCol->zCnName);
141248 pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
141249 pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
141250 if( pCol->zCnName ){
141251 memcpy(&pCol->zCnName[n+1], zType, m+1);
141252 pCol->colFlags |= COLFLAG_HASTYPE;
 
 
141253 }
141254 }
141255 pColl = sqlite3ExprCollSeq(pParse, p);
141256 if( pColl ){
141257 assert( pTab->pIndex==0 );
@@ -144027,15 +144139,17 @@
144139 if( pX->pPrior && pX->op!=TK_ALL ){
144140 /* This optimization does not work for compound subqueries that
144141 ** use UNION, INTERSECT, or EXCEPT. Only UNION ALL is allowed. */
144142 return 0;
144143 }
144144 #ifndef SQLITE_OMIT_WINDOWFUNC
144145 if( pX->pWin ){
144146 /* This optimization does not work for subqueries that use window
144147 ** functions. */
144148 return 0;
144149 }
144150 #endif
144151 }
144152 colUsed = pItem->colUsed;
144153 if( pSub->pOrderBy ){
144154 ExprList *pList = pSub->pOrderBy;
144155 for(j=0; j<pList->nExpr; j++){
@@ -145207,16 +145321,17 @@
145321 assert( pAggInfo->iFirstReg==0 );
145322 assert( pSelect!=0 );
145323 assert( pSelect->pGroupBy!=0 );
145324 pAggInfo->nColumn = pAggInfo->nAccumulator;
145325 if( ALWAYS(pAggInfo->nSortingColumn>0) ){
145326 int mx = pSelect->pGroupBy->nExpr - 1;
145327 int j, k;
145328 for(j=0; j<pAggInfo->nColumn; j++){
145329 k = pAggInfo->aCol[j].iSorterColumn;
145330 if( k>mx ) mx = k;
145331 }
145332 pAggInfo->nSortingColumn = mx+1;
145333 }
145334 analyzeAggFuncArgs(pAggInfo, pNC);
145335 #if TREETRACE_ENABLED
145336 if( sqlite3TreeTrace & 0x20 ){
145337 IndexedExpr *pIEpr;
@@ -153970,11 +154085,11 @@
154085 /* If we survive all prior tests, that means this term is worth hinting */
154086 pExpr = sqlite3ExprAnd(pParse, pExpr, sqlite3ExprDup(db, pTerm->pExpr, 0));
154087 }
154088 if( pExpr!=0 ){
154089 sWalker.xExprCallback = codeCursorHintFixExpr;
154090 if( pParse->nErr==0 ) sqlite3WalkExpr(&sWalker, pExpr);
154091 sqlite3VdbeAddOp4(v, OP_CursorHint,
154092 (sHint.pIdx ? sHint.iIdxCur : sHint.iTabCur), 0, 0,
154093 (const char*)pExpr, P4_EXPR);
154094 }
154095 }
@@ -163480,26 +163595,49 @@
163595 if( pSelect && pSelect->pLimit ){
163596 sqlite3WhereAddLimit(&pWInfo->sWC, pSelect);
163597 }
163598 if( pParse->nErr ) goto whereBeginError;
163599
163600 /* The False-WHERE-Term-Bypass optimization:
163601 **
163602 ** If there are WHERE terms that are false, then no rows will be output,
163603 ** so skip over all of the code generated here.
163604 **
163605 ** Conditions:
163606 **
163607 ** (1) The WHERE term must not refer to any tables in the join.
163608 ** (2) The term must not come from an ON clause on the
163609 ** right-hand side of a LEFT or FULL JOIN.
163610 ** (3) The term must not come from an ON clause, or there must be
163611 ** no RIGHT or FULL OUTER joins in pTabList.
163612 ** (4) If the expression contains non-deterministic functions
163613 ** that are not within a sub-select. This is not required
163614 ** for correctness but rather to preserves SQLite's legacy
163615 ** behaviour in the following two cases:
163616 **
163617 ** WHERE random()>0; -- eval random() once per row
163618 ** WHERE (SELECT random())>0; -- eval random() just once overall
163619 **
163620 ** Note that the Where term need not be a constant in order for this
163621 ** optimization to apply, though it does need to be constant relative to
163622 ** the current subquery (condition 1). The term might include variables
163623 ** from outer queries so that the value of the term changes from one
163624 ** invocation of the current subquery to the next.
163625 */
163626 for(ii=0; ii<sWLB.pWC->nBase; ii++){
163627 WhereTerm *pT = &sWLB.pWC->a[ii]; /* A term of the WHERE clause */
163628 Expr *pX; /* The expression of pT */
163629 if( pT->wtFlags & TERM_VIRTUAL ) continue;
163630 pX = pT->pExpr;
163631 assert( pX!=0 );
163632 assert( pT->prereqAll!=0 || !ExprHasProperty(pX, EP_OuterON) );
163633 if( pT->prereqAll==0 /* Conditions (1) and (2) */
163634 && (nTabList==0 || exprIsDeterministic(pX)) /* Condition (4) */
163635 && !(ExprHasProperty(pX, EP_InnerON) /* Condition (3) */
163636 && (pTabList->a[0].fg.jointype & JT_LTORJ)!=0 )
163637 ){
163638 sqlite3ExprIfFalse(pParse, pX, pWInfo->iBreak, SQLITE_JUMPIFNULL);
163639 pT->wtFlags |= TERM_CODED;
163640 }
163641 }
163642
163643 if( wctrlFlags & WHERE_WANT_DISTINCT ){
@@ -165072,10 +165210,11 @@
165210 }
165211 }
165212 }
165213 /* no break */ deliberate_fall_through
165214
165215 case TK_IF_NULL_ROW:
165216 case TK_AGG_FUNCTION:
165217 case TK_COLUMN: {
165218 int iCol = -1;
165219 if( pParse->db->mallocFailed ) return WRC_Abort;
165220 if( p->pSub ){
@@ -167902,11 +168041,11 @@
168041 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
168042 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
168043 #define YYFALLBACK 1
168044 #define YYNSTATE 575
168045 #define YYNRULE 403
168046 #define YYNRULE_WITH_ACTION 340
168047 #define YYNTOKEN 185
168048 #define YY_MAX_SHIFT 574
168049 #define YY_MIN_SHIFTREDUCE 833
168050 #define YY_MAX_SHIFTREDUCE 1235
168051 #define YY_ERROR_ACTION 1236
@@ -167982,145 +168121,145 @@
168121 *********** Begin parsing tables **********************************************/
168122 #define YY_ACTTAB_COUNT (2096)
168123 static const YYACTIONTYPE yy_action[] = {
168124 /* 0 */ 568, 208, 568, 118, 115, 229, 568, 118, 115, 229,
168125 /* 10 */ 568, 1310, 377, 1289, 408, 562, 562, 562, 568, 409,
168126 /* 20 */ 378, 1310, 1272, 41, 41, 41, 41, 208, 1520, 71,
168127 /* 30 */ 71, 969, 419, 41, 41, 491, 303, 279, 303, 970,
168128 /* 40 */ 397, 71, 71, 125, 126, 80, 1212, 1212, 1047, 1050,
168129 /* 50 */ 1037, 1037, 123, 123, 124, 124, 124, 124, 476, 409,
168130 /* 60 */ 1237, 1, 1, 574, 2, 1241, 550, 118, 115, 229,
168131 /* 70 */ 317, 480, 146, 480, 524, 118, 115, 229, 529, 1323,
168132 /* 80 */ 417, 523, 142, 125, 126, 80, 1212, 1212, 1047, 1050,
168133 /* 90 */ 1037, 1037, 123, 123, 124, 124, 124, 124, 118, 115,
168134 /* 100 */ 229, 327, 122, 122, 122, 122, 121, 121, 120, 120,
168135 /* 110 */ 120, 119, 116, 444, 284, 284, 284, 284, 442, 442,
168136 /* 120 */ 442, 1561, 376, 1563, 1188, 375, 1159, 565, 1159, 565,
168137 /* 130 */ 409, 1561, 537, 259, 226, 444, 101, 145, 449, 316,
168138 /* 140 */ 559, 240, 122, 122, 122, 122, 121, 121, 120, 120,
168139 /* 150 */ 120, 119, 116, 444, 125, 126, 80, 1212, 1212, 1047,
168140 /* 160 */ 1050, 1037, 1037, 123, 123, 124, 124, 124, 124, 142,
168141 /* 170 */ 294, 1188, 339, 448, 120, 120, 120, 119, 116, 444,
168142 /* 180 */ 127, 1188, 1189, 1188, 148, 441, 440, 568, 119, 116,
168143 /* 190 */ 444, 124, 124, 124, 124, 117, 122, 122, 122, 122,
168144 /* 200 */ 121, 121, 120, 120, 120, 119, 116, 444, 454, 113,
168145 /* 210 */ 13, 13, 546, 122, 122, 122, 122, 121, 121, 120,
168146 /* 220 */ 120, 120, 119, 116, 444, 422, 316, 559, 1188, 1189,
168147 /* 230 */ 1188, 149, 1220, 409, 1220, 124, 124, 124, 124, 122,
168148 /* 240 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
168149 /* 250 */ 444, 465, 342, 1034, 1034, 1048, 1051, 125, 126, 80,
168150 /* 260 */ 1212, 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124,
168151 /* 270 */ 124, 124, 1275, 522, 222, 1188, 568, 409, 224, 514,
168152 /* 280 */ 175, 82, 83, 122, 122, 122, 122, 121, 121, 120,
168153 /* 290 */ 120, 120, 119, 116, 444, 1005, 16, 16, 1188, 133,
168154 /* 300 */ 133, 125, 126, 80, 1212, 1212, 1047, 1050, 1037, 1037,
168155 /* 310 */ 123, 123, 124, 124, 124, 124, 122, 122, 122, 122,
168156 /* 320 */ 121, 121, 120, 120, 120, 119, 116, 444, 1038, 546,
168157 /* 330 */ 1188, 373, 1188, 1189, 1188, 252, 1429, 399, 504, 501,
168158 /* 340 */ 500, 111, 560, 566, 4, 924, 924, 433, 499, 340,
168159 /* 350 */ 460, 328, 360, 394, 1233, 1188, 1189, 1188, 563, 568,
168160 /* 360 */ 122, 122, 122, 122, 121, 121, 120, 120, 120, 119,
168161 /* 370 */ 116, 444, 284, 284, 369, 1574, 1600, 441, 440, 154,
168162 /* 380 */ 409, 445, 71, 71, 1282, 565, 1217, 1188, 1189, 1188,
168163 /* 390 */ 85, 1219, 271, 557, 543, 515, 1555, 568, 98, 1218,
168164 /* 400 */ 6, 1274, 472, 142, 125, 126, 80, 1212, 1212, 1047,
168165 /* 410 */ 1050, 1037, 1037, 123, 123, 124, 124, 124, 124, 550,
168166 /* 420 */ 13, 13, 1024, 507, 1220, 1188, 1220, 549, 109, 109,
168167 /* 430 */ 222, 568, 1234, 175, 568, 427, 110, 197, 445, 569,
168168 /* 440 */ 445, 430, 1546, 1014, 325, 551, 1188, 270, 287, 368,
168169 /* 450 */ 510, 363, 509, 257, 71, 71, 543, 71, 71, 359,
168170 /* 460 */ 316, 559, 1606, 122, 122, 122, 122, 121, 121, 120,
168171 /* 470 */ 120, 120, 119, 116, 444, 1014, 1014, 1016, 1017, 27,
168172 /* 480 */ 284, 284, 1188, 1189, 1188, 1154, 568, 1605, 409, 899,
168173 /* 490 */ 190, 550, 356, 565, 550, 935, 533, 517, 1154, 516,
168174 /* 500 */ 413, 1154, 552, 1188, 1189, 1188, 568, 544, 1548, 51,
168175 /* 510 */ 51, 214, 125, 126, 80, 1212, 1212, 1047, 1050, 1037,
168176 /* 520 */ 1037, 123, 123, 124, 124, 124, 124, 1188, 474, 135,
168177 /* 530 */ 135, 409, 284, 284, 1484, 505, 121, 121, 120, 120,
168178 /* 540 */ 120, 119, 116, 444, 1005, 565, 518, 217, 541, 1555,
168179 /* 550 */ 316, 559, 142, 6, 532, 125, 126, 80, 1212, 1212,
168180 /* 560 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168181 /* 570 */ 1549, 122, 122, 122, 122, 121, 121, 120, 120, 120,
168182 /* 580 */ 119, 116, 444, 485, 1188, 1189, 1188, 482, 281, 1263,
168183 /* 590 */ 955, 252, 1188, 373, 504, 501, 500, 1188, 340, 570,
168184 /* 600 */ 1188, 570, 409, 292, 499, 955, 874, 191, 480, 316,
168185 /* 610 */ 559, 384, 290, 380, 122, 122, 122, 122, 121, 121,
168186 /* 620 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1212,
168187 /* 630 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168188 /* 640 */ 124, 409, 394, 1132, 1188, 867, 100, 284, 284, 1188,
168189 /* 650 */ 1189, 1188, 373, 1089, 1188, 1189, 1188, 1188, 1189, 1188,
168190 /* 660 */ 565, 455, 32, 373, 233, 125, 126, 80, 1212, 1212,
168191 /* 670 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168192 /* 680 */ 1428, 957, 568, 228, 956, 122, 122, 122, 122, 121,
168193 /* 690 */ 121, 120, 120, 120, 119, 116, 444, 1154, 228, 1188,
168194 /* 700 */ 157, 1188, 1189, 1188, 1547, 13, 13, 301, 955, 1228,
168195 /* 710 */ 1154, 153, 409, 1154, 373, 1577, 1172, 5, 369, 1574,
168196 /* 720 */ 429, 1234, 3, 955, 122, 122, 122, 122, 121, 121,
168197 /* 730 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1212,
168198 /* 740 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168199 /* 750 */ 124, 409, 208, 567, 1188, 1025, 1188, 1189, 1188, 1188,
168200 /* 760 */ 388, 850, 155, 1546, 286, 402, 1094, 1094, 488, 568,
168201 /* 770 */ 465, 342, 1315, 1315, 1546, 125, 126, 80, 1212, 1212,
168202 /* 780 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168203 /* 790 */ 129, 568, 13, 13, 374, 122, 122, 122, 122, 121,
168204 /* 800 */ 121, 120, 120, 120, 119, 116, 444, 302, 568, 453,
168205 /* 810 */ 528, 1188, 1189, 1188, 13, 13, 1188, 1189, 1188, 1293,
168206 /* 820 */ 463, 1263, 409, 1313, 1313, 1546, 1010, 453, 452, 200,
168207 /* 830 */ 299, 71, 71, 1261, 122, 122, 122, 122, 121, 121,
168208 /* 840 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1212,
168209 /* 850 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168210 /* 860 */ 124, 409, 227, 1069, 1154, 284, 284, 419, 312, 278,
168211 /* 870 */ 278, 285, 285, 1415, 406, 405, 382, 1154, 565, 568,
168212 /* 880 */ 1154, 1191, 565, 1594, 565, 125, 126, 80, 1212, 1212,
168213 /* 890 */ 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124, 124,
168214 /* 900 */ 453, 1476, 13, 13, 1530, 122, 122, 122, 122, 121,
168215 /* 910 */ 121, 120, 120, 120, 119, 116, 444, 201, 568, 354,
168216 /* 920 */ 1580, 574, 2, 1241, 838, 839, 840, 1556, 317, 1207,
168217 /* 930 */ 146, 6, 409, 255, 254, 253, 206, 1323, 9, 1191,
168218 /* 940 */ 262, 71, 71, 424, 122, 122, 122, 122, 121, 121,
168219 /* 950 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1212,
168220 /* 960 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168221 /* 970 */ 124, 568, 284, 284, 568, 1208, 409, 573, 313, 1241,
168222 /* 980 */ 349, 1292, 352, 419, 317, 565, 146, 491, 525, 1637,
168223 /* 990 */ 395, 371, 491, 1323, 70, 70, 1291, 71, 71, 240,
168224 /* 1000 */ 1321, 104, 80, 1212, 1212, 1047, 1050, 1037, 1037, 123,
168225 /* 1010 */ 123, 124, 124, 124, 124, 122, 122, 122, 122, 121,
168226 /* 1020 */ 121, 120, 120, 120, 119, 116, 444, 1110, 284, 284,
168227 /* 1030 */ 428, 448, 1519, 1208, 439, 284, 284, 1483, 1348, 311,
168228 /* 1040 */ 474, 565, 1111, 969, 491, 491, 217, 1259, 565, 1532,
168229 /* 1050 */ 568, 970, 207, 568, 1024, 240, 383, 1112, 519, 122,
168230 /* 1060 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
168231 /* 1070 */ 444, 1015, 107, 71, 71, 1014, 13, 13, 910, 568,
168232 /* 1080 */ 1489, 568, 284, 284, 97, 526, 491, 448, 911, 1322,
168233 /* 1090 */ 1318, 545, 409, 284, 284, 565, 151, 209, 1489, 1491,
168234 /* 1100 */ 262, 450, 55, 55, 56, 56, 565, 1014, 1014, 1016,
168235 /* 1110 */ 443, 332, 409, 527, 12, 295, 125, 126, 80, 1212,
168236 /* 1120 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168237 /* 1130 */ 124, 347, 409, 862, 1528, 1208, 125, 126, 80, 1212,
168238 /* 1140 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168239 /* 1150 */ 124, 1133, 1635, 474, 1635, 371, 125, 114, 80, 1212,
168240 /* 1160 */ 1212, 1047, 1050, 1037, 1037, 123, 123, 124, 124, 124,
168241 /* 1170 */ 124, 1489, 329, 474, 331, 122, 122, 122, 122, 121,
168242 /* 1180 */ 121, 120, 120, 120, 119, 116, 444, 203, 1415, 568,
168243 /* 1190 */ 1290, 862, 464, 1208, 436, 122, 122, 122, 122, 121,
168244 /* 1200 */ 121, 120, 120, 120, 119, 116, 444, 553, 1133, 1636,
168245 /* 1210 */ 539, 1636, 15, 15, 890, 122, 122, 122, 122, 121,
168246 /* 1220 */ 121, 120, 120, 120, 119, 116, 444, 568, 298, 538,
168247 /* 1230 */ 1131, 1415, 1553, 1554, 1327, 409, 6, 6, 1165, 1264,
168248 /* 1240 */ 415, 320, 284, 284, 1415, 508, 565, 525, 300, 457,
168249 /* 1250 */ 43, 43, 568, 891, 12, 565, 330, 478, 425, 407,
168250 /* 1260 */ 126, 80, 1212, 1212, 1047, 1050, 1037, 1037, 123, 123,
168251 /* 1270 */ 124, 124, 124, 124, 568, 57, 57, 288, 1188, 1415,
168252 /* 1280 */ 496, 458, 392, 392, 391, 273, 389, 1131, 1552, 847,
168253 /* 1290 */ 1165, 407, 6, 568, 321, 1154, 470, 44, 44, 1551,
168254 /* 1300 */ 1110, 426, 234, 6, 323, 256, 540, 256, 1154, 431,
168255 /* 1310 */ 568, 1154, 322, 17, 487, 1111, 58, 58, 122, 122,
168256 /* 1320 */ 122, 122, 121, 121, 120, 120, 120, 119, 116, 444,
168257 /* 1330 */ 1112, 216, 481, 59, 59, 1188, 1189, 1188, 111, 560,
168258 /* 1340 */ 324, 4, 236, 456, 526, 568, 237, 456, 568, 437,
168259 /* 1350 */ 168, 556, 420, 141, 479, 563, 568, 293, 568, 1091,
168260 /* 1360 */ 568, 293, 568, 1091, 531, 568, 870, 8, 60, 60,
168261 /* 1370 */ 235, 61, 61, 568, 414, 568, 414, 568, 445, 62,
168262 /* 1380 */ 62, 45, 45, 46, 46, 47, 47, 199, 49, 49,
168263 /* 1390 */ 557, 568, 359, 568, 100, 486, 50, 50, 63, 63,
168264 /* 1400 */ 64, 64, 561, 415, 535, 410, 568, 1024, 568, 534,
168265 /* 1410 */ 316, 559, 316, 559, 65, 65, 14, 14, 568, 1024,
@@ -168127,73 +168266,73 @@
168266 /* 1420 */ 568, 512, 930, 870, 1015, 109, 109, 929, 1014, 66,
168267 /* 1430 */ 66, 131, 131, 110, 451, 445, 569, 445, 416, 177,
168268 /* 1440 */ 1014, 132, 132, 67, 67, 568, 467, 568, 930, 471,
168269 /* 1450 */ 1360, 283, 226, 929, 315, 1359, 407, 568, 459, 407,
168270 /* 1460 */ 1014, 1014, 1016, 239, 407, 86, 213, 1346, 52, 52,
168271 /* 1470 */ 68, 68, 1014, 1014, 1016, 1017, 27, 1579, 1176, 447,
168272 /* 1480 */ 69, 69, 288, 97, 108, 1535, 106, 392, 392, 391,
168273 /* 1490 */ 273, 389, 568, 877, 847, 881, 568, 111, 560, 466,
168274 /* 1500 */ 4, 568, 152, 30, 38, 568, 1128, 234, 396, 323,
168275 /* 1510 */ 111, 560, 527, 4, 563, 53, 53, 322, 568, 163,
168276 /* 1520 */ 163, 568, 337, 468, 164, 164, 333, 563, 76, 76,
168277 /* 1530 */ 568, 289, 1508, 568, 31, 1507, 568, 445, 338, 483,
168278 /* 1540 */ 100, 54, 54, 344, 72, 72, 296, 236, 1076, 557,
168279 /* 1550 */ 445, 877, 1356, 134, 134, 168, 73, 73, 141, 161,
168280 /* 1560 */ 161, 1568, 557, 535, 568, 319, 568, 348, 536, 1007,
168281 /* 1570 */ 473, 261, 261, 889, 888, 235, 535, 568, 1024, 568,
168282 /* 1580 */ 475, 534, 261, 367, 109, 109, 521, 136, 136, 130,
168283 /* 1590 */ 130, 1024, 110, 366, 445, 569, 445, 109, 109, 1014,
168284 /* 1600 */ 162, 162, 156, 156, 568, 110, 1076, 445, 569, 445,
168285 /* 1610 */ 410, 351, 1014, 568, 353, 316, 559, 568, 343, 568,
168286 /* 1620 */ 100, 497, 357, 258, 100, 896, 897, 140, 140, 355,
168287 /* 1630 */ 1306, 1014, 1014, 1016, 1017, 27, 139, 139, 362, 451,
168288 /* 1640 */ 137, 137, 138, 138, 1014, 1014, 1016, 1017, 27, 1176,
168289 /* 1650 */ 447, 568, 372, 288, 111, 560, 1018, 4, 392, 392,
168290 /* 1660 */ 391, 273, 389, 568, 1137, 847, 568, 1072, 568, 258,
168291 /* 1670 */ 492, 563, 568, 211, 75, 75, 555, 960, 234, 261,
168292 /* 1680 */ 323, 111, 560, 927, 4, 113, 77, 77, 322, 74,
168293 /* 1690 */ 74, 42, 42, 1369, 445, 48, 48, 1414, 563, 972,
168294 /* 1700 */ 973, 1088, 1087, 1088, 1087, 860, 557, 150, 928, 1342,
168295 /* 1710 */ 113, 1354, 554, 1419, 1018, 1271, 1262, 1250, 236, 1249,
168296 /* 1720 */ 1251, 445, 1587, 1339, 308, 276, 168, 309, 11, 141,
168297 /* 1730 */ 393, 310, 232, 557, 1401, 1024, 335, 291, 1396, 219,
168298 /* 1740 */ 336, 109, 109, 934, 297, 1406, 235, 341, 477, 110,
168299 /* 1750 */ 502, 445, 569, 445, 1389, 1405, 1014, 400, 1289, 365,
168300 /* 1760 */ 223, 1480, 1024, 1479, 1351, 1352, 1350, 1349, 109, 109,
168301 /* 1770 */ 204, 1590, 1228, 558, 265, 218, 110, 205, 445, 569,
168302 /* 1780 */ 445, 410, 387, 1014, 1527, 179, 316, 559, 1014, 1014,
168303 /* 1790 */ 1016, 1017, 27, 230, 1525, 1225, 79, 560, 85, 4,
168304 /* 1800 */ 418, 215, 548, 81, 84, 188, 1402, 173, 181, 461,
168305 /* 1810 */ 451, 35, 462, 563, 183, 1014, 1014, 1016, 1017, 27,
168306 /* 1820 */ 184, 1485, 185, 186, 495, 242, 98, 398, 1408, 36,
168307 /* 1830 */ 1407, 484, 91, 469, 401, 1410, 445, 192, 1474, 246,
168308 /* 1840 */ 1496, 490, 346, 277, 248, 196, 493, 511, 557, 350,
168309 /* 1850 */ 1252, 249, 250, 403, 1309, 1308, 111, 560, 432, 4,
168310 /* 1860 */ 1307, 1300, 93, 1604, 881, 1603, 224, 404, 434, 520,
168311 /* 1870 */ 263, 435, 1573, 563, 1279, 1278, 364, 1024, 306, 1277,
168312 /* 1880 */ 264, 1602, 1559, 109, 109, 370, 1299, 307, 1558, 438,
168313 /* 1890 */ 128, 110, 1374, 445, 569, 445, 445, 546, 1014, 10,
168314 /* 1900 */ 1461, 105, 381, 1373, 34, 571, 99, 1332, 557, 314,
168315 /* 1910 */ 1182, 530, 272, 274, 379, 210, 1331, 547, 385, 386,
168316 /* 1920 */ 275, 572, 1247, 1242, 411, 412, 1512, 165, 178, 1513,
168317 /* 1930 */ 1014, 1014, 1016, 1017, 27, 1511, 1510, 1024, 78, 147,
168318 /* 1940 */ 166, 220, 221, 109, 109, 834, 304, 167, 446, 212,
168319 /* 1950 */ 318, 110, 231, 445, 569, 445, 144, 1086, 1014, 1084,
168320 /* 1960 */ 326, 180, 169, 1207, 182, 334, 238, 913, 241, 1100,
168321 /* 1970 */ 187, 170, 171, 421, 87, 88, 423, 189, 89, 90,
168322 /* 1980 */ 172, 1103, 243, 1099, 244, 158, 18, 245, 345, 247,
168323 /* 1990 */ 1014, 1014, 1016, 1017, 27, 261, 1092, 193, 1222, 489,
168324 /* 2000 */ 194, 37, 366, 849, 494, 251, 195, 506, 92, 19,
168325 /* 2010 */ 498, 358, 20, 503, 879, 361, 94, 892, 305, 159,
168326 /* 2020 */ 513, 39, 95, 1170, 160, 1053, 964, 1139, 96, 174,
168327 /* 2030 */ 1138, 225, 280, 282, 198, 958, 113, 1160, 1156, 260,
168328 /* 2040 */ 21, 22, 23, 1158, 1164, 1163, 1144, 24, 33, 25,
168329 /* 2050 */ 202, 542, 26, 100, 1067, 102, 1054, 103, 7, 1052,
168330 /* 2060 */ 1056, 1109, 1057, 1108, 266, 267, 28, 40, 390, 1019,
168331 /* 2070 */ 861, 112, 29, 564, 1178, 1177, 268, 176, 143, 923,
168332 /* 2080 */ 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238,
168333 /* 2090 */ 1238, 1238, 1238, 1238, 269, 1595,
168334 };
168335 static const YYCODETYPE yy_lookahead[] = {
168336 /* 0 */ 193, 193, 193, 274, 275, 276, 193, 274, 275, 276,
168337 /* 10 */ 193, 223, 219, 225, 206, 210, 211, 212, 193, 19,
168338 /* 20 */ 219, 233, 216, 216, 217, 216, 217, 193, 295, 216,
@@ -168532,67 +168671,67 @@
168671 /* 380 */ 1665, 1623, 1702, 1630, 1666, 1667, 1671, 1673, 1703, 1718,
168672 /* 390 */ 1719, 1729, 1730, 1731, 1621, 1622, 1628, 1720, 1713, 1716,
168673 /* 400 */ 1722, 1723, 1733, 1717, 1724, 1727, 1728, 1725, 1740,
168674 };
168675 static const YYACTIONTYPE yy_default[] = {
168676 /* 0 */ 1641, 1641, 1641, 1469, 1236, 1347, 1236, 1236, 1236, 1469,
168677 /* 10 */ 1469, 1469, 1236, 1377, 1377, 1522, 1269, 1236, 1236, 1236,
168678 /* 20 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1468, 1236, 1236,
168679 /* 30 */ 1236, 1236, 1557, 1557, 1236, 1236, 1236, 1236, 1236, 1236,
168680 /* 40 */ 1236, 1236, 1386, 1236, 1393, 1236, 1236, 1236, 1236, 1236,
168681 /* 50 */ 1470, 1471, 1236, 1236, 1236, 1521, 1523, 1486, 1400, 1399,
168682 /* 60 */ 1398, 1397, 1504, 1365, 1391, 1384, 1388, 1465, 1466, 1464,
168683 /* 70 */ 1619, 1471, 1470, 1236, 1387, 1433, 1449, 1432, 1236, 1236,
168684 /* 80 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168685 /* 90 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168686 /* 100 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168687 /* 110 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168688 /* 120 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168689 /* 130 */ 1441, 1448, 1447, 1446, 1455, 1445, 1442, 1435, 1434, 1436,
168690 /* 140 */ 1437, 1236, 1236, 1260, 1236, 1236, 1257, 1311, 1236, 1236,
168691 /* 150 */ 1236, 1236, 1236, 1541, 1540, 1236, 1438, 1236, 1269, 1427,
168692 /* 160 */ 1426, 1452, 1439, 1451, 1450, 1529, 1593, 1592, 1487, 1236,
168693 /* 170 */ 1236, 1236, 1236, 1236, 1236, 1557, 1236, 1236, 1236, 1236,
168694 /* 180 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168695 /* 190 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1367,
168696 /* 200 */ 1557, 1557, 1236, 1269, 1557, 1557, 1368, 1368, 1265, 1265,
168697 /* 210 */ 1371, 1236, 1536, 1338, 1338, 1338, 1338, 1347, 1338, 1236,
168698 /* 220 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168699 /* 230 */ 1236, 1236, 1236, 1236, 1526, 1524, 1236, 1236, 1236, 1236,
168700 /* 240 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168701 /* 250 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168702 /* 260 */ 1236, 1236, 1236, 1343, 1236, 1236, 1236, 1236, 1236, 1236,
168703 /* 270 */ 1236, 1236, 1236, 1236, 1236, 1586, 1236, 1499, 1325, 1343,
168704 /* 280 */ 1343, 1343, 1343, 1345, 1326, 1324, 1337, 1270, 1243, 1633,
168705 /* 290 */ 1403, 1392, 1344, 1392, 1630, 1390, 1403, 1403, 1390, 1403,
168706 /* 300 */ 1344, 1630, 1286, 1608, 1281, 1377, 1377, 1377, 1367, 1367,
168707 /* 310 */ 1367, 1367, 1371, 1371, 1467, 1344, 1337, 1236, 1633, 1633,
168708 /* 320 */ 1353, 1353, 1632, 1632, 1353, 1487, 1616, 1412, 1314, 1320,
168709 /* 330 */ 1320, 1320, 1320, 1353, 1254, 1390, 1616, 1616, 1390, 1412,
168710 /* 340 */ 1314, 1390, 1314, 1390, 1353, 1254, 1503, 1627, 1353, 1254,
168711 /* 350 */ 1477, 1353, 1254, 1353, 1254, 1477, 1312, 1312, 1312, 1301,
168712 /* 360 */ 1236, 1236, 1477, 1312, 1286, 1312, 1301, 1312, 1312, 1575,
168713 /* 370 */ 1236, 1481, 1481, 1477, 1353, 1567, 1567, 1380, 1380, 1385,
168714 /* 380 */ 1371, 1472, 1353, 1236, 1385, 1383, 1381, 1390, 1304, 1589,
168715 /* 390 */ 1589, 1585, 1585, 1585, 1638, 1638, 1536, 1601, 1269, 1269,
168716 /* 400 */ 1269, 1269, 1601, 1288, 1288, 1270, 1270, 1269, 1601, 1236,
168717 /* 410 */ 1236, 1236, 1236, 1236, 1236, 1596, 1236, 1531, 1488, 1357,
168718 /* 420 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168719 /* 430 */ 1236, 1236, 1236, 1236, 1542, 1236, 1236, 1236, 1236, 1236,
168720 /* 440 */ 1236, 1236, 1236, 1236, 1236, 1417, 1236, 1239, 1533, 1236,
168721 /* 450 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1394, 1395, 1358,
168722 /* 460 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1409, 1236, 1236,
168723 /* 470 */ 1236, 1404, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168724 /* 480 */ 1629, 1236, 1236, 1236, 1236, 1236, 1236, 1502, 1501, 1236,
168725 /* 490 */ 1236, 1355, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168726 /* 500 */ 1236, 1236, 1236, 1236, 1236, 1284, 1236, 1236, 1236, 1236,
168727 /* 510 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168728 /* 520 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1382,
168729 /* 530 */ 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168730 /* 540 */ 1236, 1236, 1236, 1236, 1572, 1372, 1236, 1236, 1236, 1236,
168731 /* 550 */ 1620, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236, 1236,
168732 /* 560 */ 1236, 1236, 1236, 1236, 1236, 1612, 1328, 1418, 1236, 1421,
168733 /* 570 */ 1258, 1236, 1248, 1236, 1236,
168734 };
168735 /********** End of lemon-generated parsing tables *****************************/
168736
168737 /* The next table maps tokens (terminal symbols) into fallback tokens.
@@ -169437,162 +169576,162 @@
169576 /* 224 */ "expr ::= CASE case_operand case_exprlist case_else END",
169577 /* 225 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
169578 /* 226 */ "case_exprlist ::= WHEN expr THEN expr",
169579 /* 227 */ "case_else ::= ELSE expr",
169580 /* 228 */ "case_else ::=",
169581 /* 229 */ "case_operand ::=",
169582 /* 230 */ "exprlist ::=",
169583 /* 231 */ "nexprlist ::= nexprlist COMMA expr",
169584 /* 232 */ "nexprlist ::= expr",
169585 /* 233 */ "paren_exprlist ::=",
169586 /* 234 */ "paren_exprlist ::= LP exprlist RP",
169587 /* 235 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
169588 /* 236 */ "uniqueflag ::= UNIQUE",
169589 /* 237 */ "uniqueflag ::=",
169590 /* 238 */ "eidlist_opt ::=",
169591 /* 239 */ "eidlist_opt ::= LP eidlist RP",
169592 /* 240 */ "eidlist ::= eidlist COMMA nm collate sortorder",
169593 /* 241 */ "eidlist ::= nm collate sortorder",
169594 /* 242 */ "collate ::=",
169595 /* 243 */ "collate ::= COLLATE ID|STRING",
169596 /* 244 */ "cmd ::= DROP INDEX ifexists fullname",
169597 /* 245 */ "cmd ::= VACUUM vinto",
169598 /* 246 */ "cmd ::= VACUUM nm vinto",
169599 /* 247 */ "vinto ::= INTO expr",
169600 /* 248 */ "vinto ::=",
169601 /* 249 */ "cmd ::= PRAGMA nm dbnm",
169602 /* 250 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
169603 /* 251 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
169604 /* 252 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
169605 /* 253 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
169606 /* 254 */ "plus_num ::= PLUS INTEGER|FLOAT",
169607 /* 255 */ "minus_num ::= MINUS INTEGER|FLOAT",
169608 /* 256 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
169609 /* 257 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
169610 /* 258 */ "trigger_time ::= BEFORE|AFTER",
169611 /* 259 */ "trigger_time ::= INSTEAD OF",
169612 /* 260 */ "trigger_time ::=",
169613 /* 261 */ "trigger_event ::= DELETE|INSERT",
169614 /* 262 */ "trigger_event ::= UPDATE",
169615 /* 263 */ "trigger_event ::= UPDATE OF idlist",
169616 /* 264 */ "when_clause ::=",
169617 /* 265 */ "when_clause ::= WHEN expr",
169618 /* 266 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
169619 /* 267 */ "trigger_cmd_list ::= trigger_cmd SEMI",
169620 /* 268 */ "trnm ::= nm DOT nm",
169621 /* 269 */ "tridxby ::= INDEXED BY nm",
169622 /* 270 */ "tridxby ::= NOT INDEXED",
169623 /* 271 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
169624 /* 272 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
169625 /* 273 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
169626 /* 274 */ "trigger_cmd ::= scanpt select scanpt",
169627 /* 275 */ "expr ::= RAISE LP IGNORE RP",
169628 /* 276 */ "expr ::= RAISE LP raisetype COMMA nm RP",
169629 /* 277 */ "raisetype ::= ROLLBACK",
169630 /* 278 */ "raisetype ::= ABORT",
169631 /* 279 */ "raisetype ::= FAIL",
169632 /* 280 */ "cmd ::= DROP TRIGGER ifexists fullname",
169633 /* 281 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
169634 /* 282 */ "cmd ::= DETACH database_kw_opt expr",
169635 /* 283 */ "key_opt ::=",
169636 /* 284 */ "key_opt ::= KEY expr",
169637 /* 285 */ "cmd ::= REINDEX",
169638 /* 286 */ "cmd ::= REINDEX nm dbnm",
169639 /* 287 */ "cmd ::= ANALYZE",
169640 /* 288 */ "cmd ::= ANALYZE nm dbnm",
169641 /* 289 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
169642 /* 290 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
169643 /* 291 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
169644 /* 292 */ "add_column_fullname ::= fullname",
169645 /* 293 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
169646 /* 294 */ "cmd ::= create_vtab",
169647 /* 295 */ "cmd ::= create_vtab LP vtabarglist RP",
169648 /* 296 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
169649 /* 297 */ "vtabarg ::=",
169650 /* 298 */ "vtabargtoken ::= ANY",
169651 /* 299 */ "vtabargtoken ::= lp anylist RP",
169652 /* 300 */ "lp ::= LP",
169653 /* 301 */ "with ::= WITH wqlist",
169654 /* 302 */ "with ::= WITH RECURSIVE wqlist",
169655 /* 303 */ "wqas ::= AS",
169656 /* 304 */ "wqas ::= AS MATERIALIZED",
169657 /* 305 */ "wqas ::= AS NOT MATERIALIZED",
169658 /* 306 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
169659 /* 307 */ "wqlist ::= wqitem",
169660 /* 308 */ "wqlist ::= wqlist COMMA wqitem",
169661 /* 309 */ "windowdefn_list ::= windowdefn",
169662 /* 310 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
169663 /* 311 */ "windowdefn ::= nm AS LP window RP",
169664 /* 312 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
169665 /* 313 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
169666 /* 314 */ "window ::= ORDER BY sortlist frame_opt",
169667 /* 315 */ "window ::= nm ORDER BY sortlist frame_opt",
169668 /* 316 */ "window ::= frame_opt",
169669 /* 317 */ "window ::= nm frame_opt",
169670 /* 318 */ "frame_opt ::=",
169671 /* 319 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
169672 /* 320 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
169673 /* 321 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
169674 /* 322 */ "frame_bound_s ::= frame_bound",
169675 /* 323 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
169676 /* 324 */ "frame_bound_e ::= frame_bound",
169677 /* 325 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
169678 /* 326 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
169679 /* 327 */ "frame_bound ::= CURRENT ROW",
169680 /* 328 */ "frame_exclude_opt ::=",
169681 /* 329 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
169682 /* 330 */ "frame_exclude ::= NO OTHERS",
169683 /* 331 */ "frame_exclude ::= CURRENT ROW",
169684 /* 332 */ "frame_exclude ::= GROUP|TIES",
169685 /* 333 */ "window_clause ::= WINDOW windowdefn_list",
169686 /* 334 */ "filter_over ::= filter_clause over_clause",
169687 /* 335 */ "filter_over ::= over_clause",
169688 /* 336 */ "filter_over ::= filter_clause",
169689 /* 337 */ "over_clause ::= OVER LP window RP",
169690 /* 338 */ "over_clause ::= OVER nm",
169691 /* 339 */ "filter_clause ::= FILTER LP WHERE expr RP",
169692 /* 340 */ "input ::= cmdlist",
169693 /* 341 */ "cmdlist ::= cmdlist ecmd",
169694 /* 342 */ "cmdlist ::= ecmd",
169695 /* 343 */ "ecmd ::= SEMI",
169696 /* 344 */ "ecmd ::= cmdx SEMI",
169697 /* 345 */ "ecmd ::= explain cmdx SEMI",
169698 /* 346 */ "trans_opt ::=",
169699 /* 347 */ "trans_opt ::= TRANSACTION",
169700 /* 348 */ "trans_opt ::= TRANSACTION nm",
169701 /* 349 */ "savepoint_opt ::= SAVEPOINT",
169702 /* 350 */ "savepoint_opt ::=",
169703 /* 351 */ "cmd ::= create_table create_table_args",
169704 /* 352 */ "table_option_set ::= table_option",
169705 /* 353 */ "columnlist ::= columnlist COMMA columnname carglist",
169706 /* 354 */ "columnlist ::= columnname carglist",
169707 /* 355 */ "nm ::= ID|INDEXED|JOIN_KW",
169708 /* 356 */ "nm ::= STRING",
169709 /* 357 */ "typetoken ::= typename",
169710 /* 358 */ "typename ::= ID|STRING",
169711 /* 359 */ "signed ::= plus_num",
169712 /* 360 */ "signed ::= minus_num",
169713 /* 361 */ "carglist ::= carglist ccons",
169714 /* 362 */ "carglist ::=",
169715 /* 363 */ "ccons ::= NULL onconf",
169716 /* 364 */ "ccons ::= GENERATED ALWAYS AS generated",
169717 /* 365 */ "ccons ::= AS generated",
169718 /* 366 */ "conslist_opt ::= COMMA conslist",
169719 /* 367 */ "conslist ::= conslist tconscomma tcons",
169720 /* 368 */ "conslist ::= tcons",
169721 /* 369 */ "tconscomma ::=",
169722 /* 370 */ "defer_subclause_opt ::= defer_subclause",
169723 /* 371 */ "resolvetype ::= raisetype",
169724 /* 372 */ "selectnowith ::= oneselect",
169725 /* 373 */ "oneselect ::= values",
169726 /* 374 */ "sclp ::= selcollist COMMA",
169727 /* 375 */ "as ::= ID|STRING",
169728 /* 376 */ "indexed_opt ::= indexed_by",
169729 /* 377 */ "returning ::=",
169730 /* 378 */ "expr ::= term",
169731 /* 379 */ "likeop ::= LIKE_KW|MATCH",
169732 /* 380 */ "case_operand ::= expr",
169733 /* 381 */ "exprlist ::= nexprlist",
169734 /* 382 */ "nmnum ::= plus_num",
169735 /* 383 */ "nmnum ::= nm",
169736 /* 384 */ "nmnum ::= ON",
169737 /* 385 */ "nmnum ::= DELETE",
@@ -170346,162 +170485,162 @@
170485 217, /* (224) expr ::= CASE case_operand case_exprlist case_else END */
170486 279, /* (225) case_exprlist ::= case_exprlist WHEN expr THEN expr */
170487 279, /* (226) case_exprlist ::= WHEN expr THEN expr */
170488 280, /* (227) case_else ::= ELSE expr */
170489 280, /* (228) case_else ::= */
170490 278, /* (229) case_operand ::= */
170491 261, /* (230) exprlist ::= */
170492 253, /* (231) nexprlist ::= nexprlist COMMA expr */
170493 253, /* (232) nexprlist ::= expr */
170494 277, /* (233) paren_exprlist ::= */
170495 277, /* (234) paren_exprlist ::= LP exprlist RP */
170496 190, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
170497 281, /* (236) uniqueflag ::= UNIQUE */
170498 281, /* (237) uniqueflag ::= */
170499 221, /* (238) eidlist_opt ::= */
170500 221, /* (239) eidlist_opt ::= LP eidlist RP */
170501 232, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */
170502 232, /* (241) eidlist ::= nm collate sortorder */
170503 282, /* (242) collate ::= */
170504 282, /* (243) collate ::= COLLATE ID|STRING */
170505 190, /* (244) cmd ::= DROP INDEX ifexists fullname */
170506 190, /* (245) cmd ::= VACUUM vinto */
170507 190, /* (246) cmd ::= VACUUM nm vinto */
170508 283, /* (247) vinto ::= INTO expr */
170509 283, /* (248) vinto ::= */
170510 190, /* (249) cmd ::= PRAGMA nm dbnm */
170511 190, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */
170512 190, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */
170513 190, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */
170514 190, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */
170515 211, /* (254) plus_num ::= PLUS INTEGER|FLOAT */
170516 212, /* (255) minus_num ::= MINUS INTEGER|FLOAT */
170517 190, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
170518 285, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
170519 287, /* (258) trigger_time ::= BEFORE|AFTER */
170520 287, /* (259) trigger_time ::= INSTEAD OF */
170521 287, /* (260) trigger_time ::= */
170522 288, /* (261) trigger_event ::= DELETE|INSERT */
170523 288, /* (262) trigger_event ::= UPDATE */
170524 288, /* (263) trigger_event ::= UPDATE OF idlist */
170525 290, /* (264) when_clause ::= */
170526 290, /* (265) when_clause ::= WHEN expr */
170527 286, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
170528 286, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */
170529 292, /* (268) trnm ::= nm DOT nm */
170530 293, /* (269) tridxby ::= INDEXED BY nm */
170531 293, /* (270) tridxby ::= NOT INDEXED */
170532 291, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
170533 291, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
170534 291, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
170535 291, /* (274) trigger_cmd ::= scanpt select scanpt */
170536 217, /* (275) expr ::= RAISE LP IGNORE RP */
170537 217, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */
170538 236, /* (277) raisetype ::= ROLLBACK */
170539 236, /* (278) raisetype ::= ABORT */
170540 236, /* (279) raisetype ::= FAIL */
170541 190, /* (280) cmd ::= DROP TRIGGER ifexists fullname */
170542 190, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
170543 190, /* (282) cmd ::= DETACH database_kw_opt expr */
170544 295, /* (283) key_opt ::= */
170545 295, /* (284) key_opt ::= KEY expr */
170546 190, /* (285) cmd ::= REINDEX */
170547 190, /* (286) cmd ::= REINDEX nm dbnm */
170548 190, /* (287) cmd ::= ANALYZE */
170549 190, /* (288) cmd ::= ANALYZE nm dbnm */
170550 190, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */
170551 190, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
170552 190, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
170553 296, /* (292) add_column_fullname ::= fullname */
170554 190, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
170555 190, /* (294) cmd ::= create_vtab */
170556 190, /* (295) cmd ::= create_vtab LP vtabarglist RP */
170557 298, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
170558 300, /* (297) vtabarg ::= */
170559 301, /* (298) vtabargtoken ::= ANY */
170560 301, /* (299) vtabargtoken ::= lp anylist RP */
170561 302, /* (300) lp ::= LP */
170562 266, /* (301) with ::= WITH wqlist */
170563 266, /* (302) with ::= WITH RECURSIVE wqlist */
170564 305, /* (303) wqas ::= AS */
170565 305, /* (304) wqas ::= AS MATERIALIZED */
170566 305, /* (305) wqas ::= AS NOT MATERIALIZED */
170567 304, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */
170568 241, /* (307) wqlist ::= wqitem */
170569 241, /* (308) wqlist ::= wqlist COMMA wqitem */
170570 306, /* (309) windowdefn_list ::= windowdefn */
170571 306, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */
170572 307, /* (311) windowdefn ::= nm AS LP window RP */
170573 308, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
170574 308, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
170575 308, /* (314) window ::= ORDER BY sortlist frame_opt */
170576 308, /* (315) window ::= nm ORDER BY sortlist frame_opt */
170577 308, /* (316) window ::= frame_opt */
170578 308, /* (317) window ::= nm frame_opt */
170579 309, /* (318) frame_opt ::= */
170580 309, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
170581 309, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
170582 313, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */
170583 315, /* (322) frame_bound_s ::= frame_bound */
170584 315, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */
170585 316, /* (324) frame_bound_e ::= frame_bound */
170586 316, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */
170587 314, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */
170588 314, /* (327) frame_bound ::= CURRENT ROW */
170589 317, /* (328) frame_exclude_opt ::= */
170590 317, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */
170591 318, /* (330) frame_exclude ::= NO OTHERS */
170592 318, /* (331) frame_exclude ::= CURRENT ROW */
170593 318, /* (332) frame_exclude ::= GROUP|TIES */
170594 251, /* (333) window_clause ::= WINDOW windowdefn_list */
170595 273, /* (334) filter_over ::= filter_clause over_clause */
170596 273, /* (335) filter_over ::= over_clause */
170597 273, /* (336) filter_over ::= filter_clause */
170598 312, /* (337) over_clause ::= OVER LP window RP */
170599 312, /* (338) over_clause ::= OVER nm */
170600 311, /* (339) filter_clause ::= FILTER LP WHERE expr RP */
170601 185, /* (340) input ::= cmdlist */
170602 186, /* (341) cmdlist ::= cmdlist ecmd */
170603 186, /* (342) cmdlist ::= ecmd */
170604 187, /* (343) ecmd ::= SEMI */
170605 187, /* (344) ecmd ::= cmdx SEMI */
170606 187, /* (345) ecmd ::= explain cmdx SEMI */
170607 192, /* (346) trans_opt ::= */
170608 192, /* (347) trans_opt ::= TRANSACTION */
170609 192, /* (348) trans_opt ::= TRANSACTION nm */
170610 194, /* (349) savepoint_opt ::= SAVEPOINT */
170611 194, /* (350) savepoint_opt ::= */
170612 190, /* (351) cmd ::= create_table create_table_args */
170613 203, /* (352) table_option_set ::= table_option */
170614 201, /* (353) columnlist ::= columnlist COMMA columnname carglist */
170615 201, /* (354) columnlist ::= columnname carglist */
170616 193, /* (355) nm ::= ID|INDEXED|JOIN_KW */
170617 193, /* (356) nm ::= STRING */
170618 208, /* (357) typetoken ::= typename */
170619 209, /* (358) typename ::= ID|STRING */
170620 210, /* (359) signed ::= plus_num */
170621 210, /* (360) signed ::= minus_num */
170622 207, /* (361) carglist ::= carglist ccons */
170623 207, /* (362) carglist ::= */
170624 215, /* (363) ccons ::= NULL onconf */
170625 215, /* (364) ccons ::= GENERATED ALWAYS AS generated */
170626 215, /* (365) ccons ::= AS generated */
170627 202, /* (366) conslist_opt ::= COMMA conslist */
170628 228, /* (367) conslist ::= conslist tconscomma tcons */
170629 228, /* (368) conslist ::= tcons */
170630 229, /* (369) tconscomma ::= */
170631 233, /* (370) defer_subclause_opt ::= defer_subclause */
170632 235, /* (371) resolvetype ::= raisetype */
170633 239, /* (372) selectnowith ::= oneselect */
170634 240, /* (373) oneselect ::= values */
170635 254, /* (374) sclp ::= selcollist COMMA */
170636 255, /* (375) as ::= ID|STRING */
170637 264, /* (376) indexed_opt ::= indexed_by */
170638 272, /* (377) returning ::= */
170639 217, /* (378) expr ::= term */
170640 274, /* (379) likeop ::= LIKE_KW|MATCH */
170641 278, /* (380) case_operand ::= expr */
170642 261, /* (381) exprlist ::= nexprlist */
170643 284, /* (382) nmnum ::= plus_num */
170644 284, /* (383) nmnum ::= nm */
170645 284, /* (384) nmnum ::= ON */
170646 284, /* (385) nmnum ::= DELETE */
@@ -170754,162 +170893,162 @@
170893 -5, /* (224) expr ::= CASE case_operand case_exprlist case_else END */
170894 -5, /* (225) case_exprlist ::= case_exprlist WHEN expr THEN expr */
170895 -4, /* (226) case_exprlist ::= WHEN expr THEN expr */
170896 -2, /* (227) case_else ::= ELSE expr */
170897 0, /* (228) case_else ::= */
170898 0, /* (229) case_operand ::= */
170899 0, /* (230) exprlist ::= */
170900 -3, /* (231) nexprlist ::= nexprlist COMMA expr */
170901 -1, /* (232) nexprlist ::= expr */
170902 0, /* (233) paren_exprlist ::= */
170903 -3, /* (234) paren_exprlist ::= LP exprlist RP */
170904 -12, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
170905 -1, /* (236) uniqueflag ::= UNIQUE */
170906 0, /* (237) uniqueflag ::= */
170907 0, /* (238) eidlist_opt ::= */
170908 -3, /* (239) eidlist_opt ::= LP eidlist RP */
170909 -5, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */
170910 -3, /* (241) eidlist ::= nm collate sortorder */
170911 0, /* (242) collate ::= */
170912 -2, /* (243) collate ::= COLLATE ID|STRING */
170913 -4, /* (244) cmd ::= DROP INDEX ifexists fullname */
170914 -2, /* (245) cmd ::= VACUUM vinto */
170915 -3, /* (246) cmd ::= VACUUM nm vinto */
170916 -2, /* (247) vinto ::= INTO expr */
170917 0, /* (248) vinto ::= */
170918 -3, /* (249) cmd ::= PRAGMA nm dbnm */
170919 -5, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */
170920 -6, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */
170921 -5, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */
170922 -6, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */
170923 -2, /* (254) plus_num ::= PLUS INTEGER|FLOAT */
170924 -2, /* (255) minus_num ::= MINUS INTEGER|FLOAT */
170925 -5, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
170926 -11, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
170927 -1, /* (258) trigger_time ::= BEFORE|AFTER */
170928 -2, /* (259) trigger_time ::= INSTEAD OF */
170929 0, /* (260) trigger_time ::= */
170930 -1, /* (261) trigger_event ::= DELETE|INSERT */
170931 -1, /* (262) trigger_event ::= UPDATE */
170932 -3, /* (263) trigger_event ::= UPDATE OF idlist */
170933 0, /* (264) when_clause ::= */
170934 -2, /* (265) when_clause ::= WHEN expr */
170935 -3, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
170936 -2, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */
170937 -3, /* (268) trnm ::= nm DOT nm */
170938 -3, /* (269) tridxby ::= INDEXED BY nm */
170939 -2, /* (270) tridxby ::= NOT INDEXED */
170940 -9, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
170941 -8, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
170942 -6, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
170943 -3, /* (274) trigger_cmd ::= scanpt select scanpt */
170944 -4, /* (275) expr ::= RAISE LP IGNORE RP */
170945 -6, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */
170946 -1, /* (277) raisetype ::= ROLLBACK */
170947 -1, /* (278) raisetype ::= ABORT */
170948 -1, /* (279) raisetype ::= FAIL */
170949 -4, /* (280) cmd ::= DROP TRIGGER ifexists fullname */
170950 -6, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
170951 -3, /* (282) cmd ::= DETACH database_kw_opt expr */
170952 0, /* (283) key_opt ::= */
170953 -2, /* (284) key_opt ::= KEY expr */
170954 -1, /* (285) cmd ::= REINDEX */
170955 -3, /* (286) cmd ::= REINDEX nm dbnm */
170956 -1, /* (287) cmd ::= ANALYZE */
170957 -3, /* (288) cmd ::= ANALYZE nm dbnm */
170958 -6, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */
170959 -7, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
170960 -6, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
170961 -1, /* (292) add_column_fullname ::= fullname */
170962 -8, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
170963 -1, /* (294) cmd ::= create_vtab */
170964 -4, /* (295) cmd ::= create_vtab LP vtabarglist RP */
170965 -8, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
170966 0, /* (297) vtabarg ::= */
170967 -1, /* (298) vtabargtoken ::= ANY */
170968 -3, /* (299) vtabargtoken ::= lp anylist RP */
170969 -1, /* (300) lp ::= LP */
170970 -2, /* (301) with ::= WITH wqlist */
170971 -3, /* (302) with ::= WITH RECURSIVE wqlist */
170972 -1, /* (303) wqas ::= AS */
170973 -2, /* (304) wqas ::= AS MATERIALIZED */
170974 -3, /* (305) wqas ::= AS NOT MATERIALIZED */
170975 -6, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */
170976 -1, /* (307) wqlist ::= wqitem */
170977 -3, /* (308) wqlist ::= wqlist COMMA wqitem */
170978 -1, /* (309) windowdefn_list ::= windowdefn */
170979 -3, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */
170980 -5, /* (311) windowdefn ::= nm AS LP window RP */
170981 -5, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
170982 -6, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
170983 -4, /* (314) window ::= ORDER BY sortlist frame_opt */
170984 -5, /* (315) window ::= nm ORDER BY sortlist frame_opt */
170985 -1, /* (316) window ::= frame_opt */
170986 -2, /* (317) window ::= nm frame_opt */
170987 0, /* (318) frame_opt ::= */
170988 -3, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
170989 -6, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
170990 -1, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */
170991 -1, /* (322) frame_bound_s ::= frame_bound */
170992 -2, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */
170993 -1, /* (324) frame_bound_e ::= frame_bound */
170994 -2, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */
170995 -2, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */
170996 -2, /* (327) frame_bound ::= CURRENT ROW */
170997 0, /* (328) frame_exclude_opt ::= */
170998 -2, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */
170999 -2, /* (330) frame_exclude ::= NO OTHERS */
171000 -2, /* (331) frame_exclude ::= CURRENT ROW */
171001 -1, /* (332) frame_exclude ::= GROUP|TIES */
171002 -2, /* (333) window_clause ::= WINDOW windowdefn_list */
171003 -2, /* (334) filter_over ::= filter_clause over_clause */
171004 -1, /* (335) filter_over ::= over_clause */
171005 -1, /* (336) filter_over ::= filter_clause */
171006 -4, /* (337) over_clause ::= OVER LP window RP */
171007 -2, /* (338) over_clause ::= OVER nm */
171008 -5, /* (339) filter_clause ::= FILTER LP WHERE expr RP */
171009 -1, /* (340) input ::= cmdlist */
171010 -2, /* (341) cmdlist ::= cmdlist ecmd */
171011 -1, /* (342) cmdlist ::= ecmd */
171012 -1, /* (343) ecmd ::= SEMI */
171013 -2, /* (344) ecmd ::= cmdx SEMI */
171014 -3, /* (345) ecmd ::= explain cmdx SEMI */
171015 0, /* (346) trans_opt ::= */
171016 -1, /* (347) trans_opt ::= TRANSACTION */
171017 -2, /* (348) trans_opt ::= TRANSACTION nm */
171018 -1, /* (349) savepoint_opt ::= SAVEPOINT */
171019 0, /* (350) savepoint_opt ::= */
171020 -2, /* (351) cmd ::= create_table create_table_args */
171021 -1, /* (352) table_option_set ::= table_option */
171022 -4, /* (353) columnlist ::= columnlist COMMA columnname carglist */
171023 -2, /* (354) columnlist ::= columnname carglist */
171024 -1, /* (355) nm ::= ID|INDEXED|JOIN_KW */
171025 -1, /* (356) nm ::= STRING */
171026 -1, /* (357) typetoken ::= typename */
171027 -1, /* (358) typename ::= ID|STRING */
171028 -1, /* (359) signed ::= plus_num */
171029 -1, /* (360) signed ::= minus_num */
171030 -2, /* (361) carglist ::= carglist ccons */
171031 0, /* (362) carglist ::= */
171032 -2, /* (363) ccons ::= NULL onconf */
171033 -4, /* (364) ccons ::= GENERATED ALWAYS AS generated */
171034 -2, /* (365) ccons ::= AS generated */
171035 -2, /* (366) conslist_opt ::= COMMA conslist */
171036 -3, /* (367) conslist ::= conslist tconscomma tcons */
171037 -1, /* (368) conslist ::= tcons */
171038 0, /* (369) tconscomma ::= */
171039 -1, /* (370) defer_subclause_opt ::= defer_subclause */
171040 -1, /* (371) resolvetype ::= raisetype */
171041 -1, /* (372) selectnowith ::= oneselect */
171042 -1, /* (373) oneselect ::= values */
171043 -2, /* (374) sclp ::= selcollist COMMA */
171044 -1, /* (375) as ::= ID|STRING */
171045 -1, /* (376) indexed_opt ::= indexed_by */
171046 0, /* (377) returning ::= */
171047 -1, /* (378) expr ::= term */
171048 -1, /* (379) likeop ::= LIKE_KW|MATCH */
171049 -1, /* (380) case_operand ::= expr */
171050 -1, /* (381) exprlist ::= nexprlist */
171051 -1, /* (382) nmnum ::= plus_num */
171052 -1, /* (383) nmnum ::= nm */
171053 -1, /* (384) nmnum ::= ON */
171054 -1, /* (385) nmnum ::= DELETE */
@@ -170987,11 +171126,11 @@
171126 {yymsp[1].minor.yy394 = TK_DEFERRED;}
171127 break;
171128 case 5: /* transtype ::= DEFERRED */
171129 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
171130 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
171131 case 321: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==321);
171132 {yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/}
171133 break;
171134 case 8: /* cmd ::= COMMIT|END trans_opt */
171135 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
171136 {sqlite3EndTransaction(pParse,yymsp[-1].major);}
@@ -171024,11 +171163,11 @@
171163 case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
171164 case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
171165 case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72);
171166 case 81: /* ifexists ::= */ yytestcase(yyruleno==81);
171167 case 98: /* distinct ::= */ yytestcase(yyruleno==98);
171168 case 242: /* collate ::= */ yytestcase(yyruleno==242);
171169 {yymsp[1].minor.yy394 = 0;}
171170 break;
171171 case 16: /* ifnotexists ::= IF NOT EXISTS */
171172 {yymsp[-2].minor.yy394 = 1;}
171173 break;
@@ -171210,11 +171349,11 @@
171349 break;
171350 case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
171351 case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80);
171352 case 215: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==215);
171353 case 218: /* in_op ::= NOT IN */ yytestcase(yyruleno==218);
171354 case 243: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==243);
171355 {yymsp[-1].minor.yy394 = 1;}
171356 break;
171357 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
171358 {yymsp[-1].minor.yy394 = 0;}
171359 break;
@@ -171360,13 +171499,13 @@
171499 {yymsp[0].minor.yy394 = SF_All;}
171500 break;
171501 case 99: /* sclp ::= */
171502 case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132);
171503 case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142);
171504 case 230: /* exprlist ::= */ yytestcase(yyruleno==230);
171505 case 233: /* paren_exprlist ::= */ yytestcase(yyruleno==233);
171506 case 238: /* eidlist_opt ::= */ yytestcase(yyruleno==238);
171507 {yymsp[1].minor.yy322 = 0;}
171508 break;
171509 case 100: /* selcollist ::= sclp scanpt expr scanpt as */
171510 {
171511 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
@@ -171388,12 +171527,12 @@
171527 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
171528 }
171529 break;
171530 case 103: /* as ::= AS nm */
171531 case 115: /* dbnm ::= DOT nm */ yytestcase(yyruleno==115);
171532 case 254: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==254);
171533 case 255: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==255);
171534 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
171535 break;
171536 case 105: /* from ::= */
171537 case 108: /* stl_prefix ::= */ yytestcase(yyruleno==108);
171538 {yymsp[1].minor.yy131 = 0;}
@@ -171433,11 +171572,11 @@
171572 break;
171573 case 113: /* seltablist ::= stl_prefix LP seltablist RP as on_using */
171574 {
171575 if( yymsp[-5].minor.yy131==0 && yymsp[-1].minor.yy0.n==0 && yymsp[0].minor.yy561.pOn==0 && yymsp[0].minor.yy561.pUsing==0 ){
171576 yymsp[-5].minor.yy131 = yymsp[-3].minor.yy131;
171577 }else if( ALWAYS(yymsp[-3].minor.yy131!=0) && yymsp[-3].minor.yy131->nSrc==1 ){
171578 yymsp[-5].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy131,0,0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy561);
171579 if( yymsp[-5].minor.yy131 ){
171580 SrcItem *pNew = &yymsp[-5].minor.yy131->a[yymsp[-5].minor.yy131->nSrc-1];
171581 SrcItem *pOld = yymsp[-3].minor.yy131->a;
171582 pNew->zName = pOld->zName;
@@ -171562,19 +171701,19 @@
171701 case 144: /* having_opt ::= */
171702 case 146: /* limit_opt ::= */ yytestcase(yyruleno==146);
171703 case 151: /* where_opt ::= */ yytestcase(yyruleno==151);
171704 case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153);
171705 case 228: /* case_else ::= */ yytestcase(yyruleno==228);
171706 case 229: /* case_operand ::= */ yytestcase(yyruleno==229);
171707 case 248: /* vinto ::= */ yytestcase(yyruleno==248);
171708 {yymsp[1].minor.yy528 = 0;}
171709 break;
171710 case 145: /* having_opt ::= HAVING expr */
171711 case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152);
171712 case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154);
171713 case 227: /* case_else ::= ELSE expr */ yytestcase(yyruleno==227);
171714 case 247: /* vinto ::= INTO expr */ yytestcase(yyruleno==247);
171715 {yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;}
171716 break;
171717 case 147: /* limit_opt ::= LIMIT expr */
171718 {yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);}
171719 break;
@@ -172001,394 +172140,391 @@
172140 {
172141 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
172142 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528);
172143 }
172144 break;
172145 case 231: /* nexprlist ::= nexprlist COMMA expr */
 
 
 
172146 {yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);}
172147 break;
172148 case 232: /* nexprlist ::= expr */
172149 {yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/}
172150 break;
172151 case 234: /* paren_exprlist ::= LP exprlist RP */
172152 case 239: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==239);
172153 {yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
172154 break;
172155 case 235: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
172156 {
172157 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
172158 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394,
172159 &yymsp[-11].minor.yy0, yymsp[0].minor.yy528, SQLITE_SO_ASC, yymsp[-8].minor.yy394, SQLITE_IDXTYPE_APPDEF);
172160 if( IN_RENAME_OBJECT && pParse->pNewIndex ){
172161 sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
172162 }
172163 }
172164 break;
172165 case 236: /* uniqueflag ::= UNIQUE */
172166 case 278: /* raisetype ::= ABORT */ yytestcase(yyruleno==278);
172167 {yymsp[0].minor.yy394 = OE_Abort;}
172168 break;
172169 case 237: /* uniqueflag ::= */
172170 {yymsp[1].minor.yy394 = OE_None;}
172171 break;
172172 case 240: /* eidlist ::= eidlist COMMA nm collate sortorder */
172173 {
172174 yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394);
172175 }
172176 break;
172177 case 241: /* eidlist ::= nm collate sortorder */
172178 {
172179 yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/
172180 }
172181 break;
172182 case 244: /* cmd ::= DROP INDEX ifexists fullname */
172183 {sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);}
172184 break;
172185 case 245: /* cmd ::= VACUUM vinto */
172186 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);}
172187 break;
172188 case 246: /* cmd ::= VACUUM nm vinto */
172189 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);}
172190 break;
172191 case 249: /* cmd ::= PRAGMA nm dbnm */
172192 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
172193 break;
172194 case 250: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
172195 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
172196 break;
172197 case 251: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
172198 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
172199 break;
172200 case 252: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
172201 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
172202 break;
172203 case 253: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
172204 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
172205 break;
172206 case 256: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
172207 {
172208 Token all;
172209 all.z = yymsp[-3].minor.yy0.z;
172210 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
172211 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all);
172212 }
172213 break;
172214 case 257: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
172215 {
172216 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394);
172217 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
172218 }
172219 break;
172220 case 258: /* trigger_time ::= BEFORE|AFTER */
172221 { yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ }
172222 break;
172223 case 259: /* trigger_time ::= INSTEAD OF */
172224 { yymsp[-1].minor.yy394 = TK_INSTEAD;}
172225 break;
172226 case 260: /* trigger_time ::= */
172227 { yymsp[1].minor.yy394 = TK_BEFORE; }
172228 break;
172229 case 261: /* trigger_event ::= DELETE|INSERT */
172230 case 262: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==262);
172231 {yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;}
172232 break;
172233 case 263: /* trigger_event ::= UPDATE OF idlist */
172234 {yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;}
172235 break;
172236 case 264: /* when_clause ::= */
172237 case 283: /* key_opt ::= */ yytestcase(yyruleno==283);
172238 { yymsp[1].minor.yy528 = 0; }
172239 break;
172240 case 265: /* when_clause ::= WHEN expr */
172241 case 284: /* key_opt ::= KEY expr */ yytestcase(yyruleno==284);
172242 { yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; }
172243 break;
172244 case 266: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
172245 {
172246 assert( yymsp[-2].minor.yy33!=0 );
172247 yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33;
172248 yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33;
172249 }
172250 break;
172251 case 267: /* trigger_cmd_list ::= trigger_cmd SEMI */
172252 {
172253 assert( yymsp[-1].minor.yy33!=0 );
172254 yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33;
172255 }
172256 break;
172257 case 268: /* trnm ::= nm DOT nm */
172258 {
172259 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
172260 sqlite3ErrorMsg(pParse,
172261 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
172262 "statements within triggers");
172263 }
172264 break;
172265 case 269: /* tridxby ::= INDEXED BY nm */
172266 {
172267 sqlite3ErrorMsg(pParse,
172268 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
172269 "within triggers");
172270 }
172271 break;
172272 case 270: /* tridxby ::= NOT INDEXED */
172273 {
172274 sqlite3ErrorMsg(pParse,
172275 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
172276 "within triggers");
172277 }
172278 break;
172279 case 271: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
172280 {yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);}
172281 yymsp[-8].minor.yy33 = yylhsminor.yy33;
172282 break;
172283 case 272: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
172284 {
172285 yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/
172286 }
172287 yymsp[-7].minor.yy33 = yylhsminor.yy33;
172288 break;
172289 case 273: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
172290 {yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);}
172291 yymsp[-5].minor.yy33 = yylhsminor.yy33;
172292 break;
172293 case 274: /* trigger_cmd ::= scanpt select scanpt */
172294 {yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/}
172295 yymsp[-2].minor.yy33 = yylhsminor.yy33;
172296 break;
172297 case 275: /* expr ::= RAISE LP IGNORE RP */
172298 {
172299 yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
172300 if( yymsp[-3].minor.yy528 ){
172301 yymsp[-3].minor.yy528->affExpr = OE_Ignore;
172302 }
172303 }
172304 break;
172305 case 276: /* expr ::= RAISE LP raisetype COMMA nm RP */
172306 {
172307 yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
172308 if( yymsp[-5].minor.yy528 ) {
172309 yymsp[-5].minor.yy528->affExpr = (char)yymsp[-3].minor.yy394;
172310 }
172311 }
172312 break;
172313 case 277: /* raisetype ::= ROLLBACK */
172314 {yymsp[0].minor.yy394 = OE_Rollback;}
172315 break;
172316 case 279: /* raisetype ::= FAIL */
172317 {yymsp[0].minor.yy394 = OE_Fail;}
172318 break;
172319 case 280: /* cmd ::= DROP TRIGGER ifexists fullname */
172320 {
172321 sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394);
172322 }
172323 break;
172324 case 281: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
172325 {
172326 sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528);
172327 }
172328 break;
172329 case 282: /* cmd ::= DETACH database_kw_opt expr */
172330 {
172331 sqlite3Detach(pParse, yymsp[0].minor.yy528);
172332 }
172333 break;
172334 case 285: /* cmd ::= REINDEX */
172335 {sqlite3Reindex(pParse, 0, 0);}
172336 break;
172337 case 286: /* cmd ::= REINDEX nm dbnm */
172338 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
172339 break;
172340 case 287: /* cmd ::= ANALYZE */
172341 {sqlite3Analyze(pParse, 0, 0);}
172342 break;
172343 case 288: /* cmd ::= ANALYZE nm dbnm */
172344 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
172345 break;
172346 case 289: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
172347 {
172348 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0);
172349 }
172350 break;
172351 case 290: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
172352 {
172353 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
172354 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
172355 }
172356 break;
172357 case 291: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
172358 {
172359 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0);
172360 }
172361 break;
172362 case 292: /* add_column_fullname ::= fullname */
172363 {
172364 disableLookaside(pParse);
172365 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131);
172366 }
172367 break;
172368 case 293: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
172369 {
172370 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
172371 }
172372 break;
172373 case 294: /* cmd ::= create_vtab */
172374 {sqlite3VtabFinishParse(pParse,0);}
172375 break;
172376 case 295: /* cmd ::= create_vtab LP vtabarglist RP */
172377 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
172378 break;
172379 case 296: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
172380 {
172381 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394);
172382 }
172383 break;
172384 case 297: /* vtabarg ::= */
172385 {sqlite3VtabArgInit(pParse);}
172386 break;
172387 case 298: /* vtabargtoken ::= ANY */
172388 case 299: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==299);
172389 case 300: /* lp ::= LP */ yytestcase(yyruleno==300);
172390 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
172391 break;
172392 case 301: /* with ::= WITH wqlist */
172393 case 302: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==302);
172394 { sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); }
172395 break;
172396 case 303: /* wqas ::= AS */
172397 {yymsp[0].minor.yy516 = M10d_Any;}
172398 break;
172399 case 304: /* wqas ::= AS MATERIALIZED */
172400 {yymsp[-1].minor.yy516 = M10d_Yes;}
172401 break;
172402 case 305: /* wqas ::= AS NOT MATERIALIZED */
172403 {yymsp[-2].minor.yy516 = M10d_No;}
172404 break;
172405 case 306: /* wqitem ::= nm eidlist_opt wqas LP select RP */
172406 {
172407 yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/
172408 }
172409 break;
172410 case 307: /* wqlist ::= wqitem */
172411 {
172412 yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/
172413 }
172414 break;
172415 case 308: /* wqlist ::= wqlist COMMA wqitem */
172416 {
172417 yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385);
172418 }
172419 break;
172420 case 309: /* windowdefn_list ::= windowdefn */
172421 { yylhsminor.yy41 = yymsp[0].minor.yy41; }
172422 yymsp[0].minor.yy41 = yylhsminor.yy41;
172423 break;
172424 case 310: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
172425 {
172426 assert( yymsp[0].minor.yy41!=0 );
172427 sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41);
172428 yymsp[0].minor.yy41->pNextWin = yymsp[-2].minor.yy41;
172429 yylhsminor.yy41 = yymsp[0].minor.yy41;
172430 }
172431 yymsp[-2].minor.yy41 = yylhsminor.yy41;
172432 break;
172433 case 311: /* windowdefn ::= nm AS LP window RP */
172434 {
172435 if( ALWAYS(yymsp[-1].minor.yy41) ){
172436 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
172437 }
172438 yylhsminor.yy41 = yymsp[-1].minor.yy41;
172439 }
172440 yymsp[-4].minor.yy41 = yylhsminor.yy41;
172441 break;
172442 case 312: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
172443 {
172444 yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0);
172445 }
172446 break;
172447 case 313: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
172448 {
172449 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0);
172450 }
172451 yymsp[-5].minor.yy41 = yylhsminor.yy41;
172452 break;
172453 case 314: /* window ::= ORDER BY sortlist frame_opt */
172454 {
172455 yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0);
172456 }
172457 break;
172458 case 315: /* window ::= nm ORDER BY sortlist frame_opt */
172459 {
172460 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
172461 }
172462 yymsp[-4].minor.yy41 = yylhsminor.yy41;
172463 break;
172464 case 316: /* window ::= frame_opt */
172465 case 335: /* filter_over ::= over_clause */ yytestcase(yyruleno==335);
172466 {
172467 yylhsminor.yy41 = yymsp[0].minor.yy41;
172468 }
172469 yymsp[0].minor.yy41 = yylhsminor.yy41;
172470 break;
172471 case 317: /* window ::= nm frame_opt */
172472 {
172473 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0);
172474 }
172475 yymsp[-1].minor.yy41 = yylhsminor.yy41;
172476 break;
172477 case 318: /* frame_opt ::= */
172478 {
172479 yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
172480 }
172481 break;
172482 case 319: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
172483 {
172484 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516);
172485 }
172486 yymsp[-2].minor.yy41 = yylhsminor.yy41;
172487 break;
172488 case 320: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
172489 {
172490 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516);
172491 }
172492 yymsp[-5].minor.yy41 = yylhsminor.yy41;
172493 break;
172494 case 322: /* frame_bound_s ::= frame_bound */
172495 case 324: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==324);
172496 {yylhsminor.yy595 = yymsp[0].minor.yy595;}
172497 yymsp[0].minor.yy595 = yylhsminor.yy595;
172498 break;
172499 case 323: /* frame_bound_s ::= UNBOUNDED PRECEDING */
172500 case 325: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==325);
172501 case 327: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==327);
172502 {yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;}
172503 yymsp[-1].minor.yy595 = yylhsminor.yy595;
172504 break;
172505 case 326: /* frame_bound ::= expr PRECEDING|FOLLOWING */
172506 {yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;}
172507 yymsp[-1].minor.yy595 = yylhsminor.yy595;
172508 break;
172509 case 328: /* frame_exclude_opt ::= */
172510 {yymsp[1].minor.yy516 = 0;}
172511 break;
172512 case 329: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
172513 {yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;}
172514 break;
172515 case 330: /* frame_exclude ::= NO OTHERS */
172516 case 331: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==331);
172517 {yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/}
172518 break;
172519 case 332: /* frame_exclude ::= GROUP|TIES */
172520 {yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/}
172521 break;
172522 case 333: /* window_clause ::= WINDOW windowdefn_list */
172523 { yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; }
172524 break;
172525 case 334: /* filter_over ::= filter_clause over_clause */
172526 {
172527 if( yymsp[0].minor.yy41 ){
172528 yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528;
172529 }else{
172530 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
@@ -172395,11 +172531,11 @@
172531 }
172532 yylhsminor.yy41 = yymsp[0].minor.yy41;
172533 }
172534 yymsp[-1].minor.yy41 = yylhsminor.yy41;
172535 break;
172536 case 336: /* filter_over ::= filter_clause */
172537 {
172538 yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
172539 if( yylhsminor.yy41 ){
172540 yylhsminor.yy41->eFrmType = TK_FILTER;
172541 yylhsminor.yy41->pFilter = yymsp[0].minor.yy528;
@@ -172407,68 +172543,69 @@
172543 sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy528);
172544 }
172545 }
172546 yymsp[0].minor.yy41 = yylhsminor.yy41;
172547 break;
172548 case 337: /* over_clause ::= OVER LP window RP */
172549 {
172550 yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41;
172551 assert( yymsp[-3].minor.yy41!=0 );
172552 }
172553 break;
172554 case 338: /* over_clause ::= OVER nm */
172555 {
172556 yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
172557 if( yymsp[-1].minor.yy41 ){
172558 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
172559 }
172560 }
172561 break;
172562 case 339: /* filter_clause ::= FILTER LP WHERE expr RP */
172563 { yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; }
172564 break;
172565 default:
172566 /* (340) input ::= cmdlist */ yytestcase(yyruleno==340);
172567 /* (341) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==341);
172568 /* (342) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=342);
172569 /* (343) ecmd ::= SEMI */ yytestcase(yyruleno==343);
172570 /* (344) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==344);
172571 /* (345) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=345);
172572 /* (346) trans_opt ::= */ yytestcase(yyruleno==346);
172573 /* (347) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==347);
172574 /* (348) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==348);
172575 /* (349) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==349);
172576 /* (350) savepoint_opt ::= */ yytestcase(yyruleno==350);
172577 /* (351) cmd ::= create_table create_table_args */ yytestcase(yyruleno==351);
172578 /* (352) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=352);
172579 /* (353) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==353);
172580 /* (354) columnlist ::= columnname carglist */ yytestcase(yyruleno==354);
172581 /* (355) nm ::= ID|INDEXED|JOIN_KW */ yytestcase(yyruleno==355);
172582 /* (356) nm ::= STRING */ yytestcase(yyruleno==356);
172583 /* (357) typetoken ::= typename */ yytestcase(yyruleno==357);
172584 /* (358) typename ::= ID|STRING */ yytestcase(yyruleno==358);
172585 /* (359) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=359);
172586 /* (360) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=360);
172587 /* (361) carglist ::= carglist ccons */ yytestcase(yyruleno==361);
172588 /* (362) carglist ::= */ yytestcase(yyruleno==362);
172589 /* (363) ccons ::= NULL onconf */ yytestcase(yyruleno==363);
172590 /* (364) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==364);
172591 /* (365) ccons ::= AS generated */ yytestcase(yyruleno==365);
172592 /* (366) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==366);
172593 /* (367) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==367);
172594 /* (368) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=368);
172595 /* (369) tconscomma ::= */ yytestcase(yyruleno==369);
172596 /* (370) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=370);
172597 /* (371) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=371);
172598 /* (372) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=372);
172599 /* (373) oneselect ::= values */ yytestcase(yyruleno==373);
172600 /* (374) sclp ::= selcollist COMMA */ yytestcase(yyruleno==374);
172601 /* (375) as ::= ID|STRING */ yytestcase(yyruleno==375);
172602 /* (376) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=376);
172603 /* (377) returning ::= */ yytestcase(yyruleno==377);
172604 /* (378) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=378);
172605 /* (379) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==379);
172606 /* (380) case_operand ::= expr */ yytestcase(yyruleno==380);
172607 /* (381) exprlist ::= nexprlist */ yytestcase(yyruleno==381);
172608 /* (382) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=382);
172609 /* (383) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=383);
172610 /* (384) nmnum ::= ON */ yytestcase(yyruleno==384);
172611 /* (385) nmnum ::= DELETE */ yytestcase(yyruleno==385);
@@ -199500,10 +199637,11 @@
199637 #define JNODE_REMOVE 0x04 /* Do not output */
199638 #define JNODE_REPLACE 0x08 /* Replace with JsonNode.u.iReplace */
199639 #define JNODE_PATCH 0x10 /* Patch with JsonNode.u.pPatch */
199640 #define JNODE_APPEND 0x20 /* More ARRAY/OBJECT entries at u.iAppend */
199641 #define JNODE_LABEL 0x40 /* Is a label of an object */
199642 #define JNODE_JSON5 0x80 /* Node contains JSON5 enhancements */
199643
199644
199645 /* A single node of parsed JSON
199646 */
199647 struct JsonNode {
@@ -199526,14 +199664,16 @@
199664 u32 nNode; /* Number of slots of aNode[] used */
199665 u32 nAlloc; /* Number of slots of aNode[] allocated */
199666 JsonNode *aNode; /* Array of nodes containing the parse */
199667 const char *zJson; /* Original JSON string */
199668 u32 *aUp; /* Index of parent of each node */
199669 u16 iDepth; /* Nesting depth */
199670 u8 nErr; /* Number of errors seen */
199671 u8 oom; /* Set to true if out of memory */
199672 u8 hasNonstd; /* True if input uses non-standard features like JSON5 */
199673 int nJson; /* Length of the zJson string in bytes */
199674 u32 iErr; /* Error location in zJson[] */
199675 u32 iHold; /* Replace cache line with the lowest iHold value */
199676 };
199677
199678 /*
199679 ** Maximum nesting depth of JSON for this implementation.
@@ -199689,10 +199829,133 @@
199829 p->zBuf[p->nUsed++] = c;
199830 }
199831 p->zBuf[p->nUsed++] = '"';
199832 assert( p->nUsed<p->nAlloc );
199833 }
199834
199835 /*
199836 ** The zIn[0..N] string is a JSON5 string literal. Append to p a translation
199837 ** of the string literal that standard JSON and that omits all JSON5
199838 ** features.
199839 */
199840 static void jsonAppendNormalizedString(JsonString *p, const char *zIn, u32 N){
199841 u32 i;
199842 jsonAppendChar(p, '"');
199843 zIn++;
199844 N -= 2;
199845 while( N>0 ){
199846 for(i=0; i<N && zIn[i]!='\\'; i++){}
199847 if( i>0 ){
199848 jsonAppendRaw(p, zIn, i);
199849 zIn += i;
199850 N -= i;
199851 if( N==0 ) break;
199852 }
199853 assert( zIn[0]=='\\' );
199854 switch( (u8)zIn[1] ){
199855 case '\'':
199856 jsonAppendChar(p, '\'');
199857 break;
199858 case 'v':
199859 jsonAppendRaw(p, "\\u0009", 6);
199860 break;
199861 case 'x':
199862 jsonAppendRaw(p, "\\u00", 4);
199863 jsonAppendRaw(p, &zIn[2], 2);
199864 zIn += 2;
199865 N -= 2;
199866 break;
199867 case '0':
199868 jsonAppendRaw(p, "\\u0000", 6);
199869 break;
199870 case '\r':
199871 if( zIn[2]=='\n' ){
199872 zIn++;
199873 N--;
199874 }
199875 break;
199876 case '\n':
199877 break;
199878 case 0xe2:
199879 assert( N>=4 );
199880 assert( 0x80==(u8)zIn[2] );
199881 assert( 0xa8==(u8)zIn[3] || 0xa9==(u8)zIn[3] );
199882 zIn += 2;
199883 N -= 2;
199884 break;
199885 default:
199886 jsonAppendRaw(p, zIn, 2);
199887 break;
199888 }
199889 zIn += 2;
199890 N -= 2;
199891 }
199892 jsonAppendChar(p, '"');
199893 }
199894
199895 /*
199896 ** The zIn[0..N] string is a JSON5 integer literal. Append to p a translation
199897 ** of the string literal that standard JSON and that omits all JSON5
199898 ** features.
199899 */
199900 static void jsonAppendNormalizedInt(JsonString *p, const char *zIn, u32 N){
199901 if( zIn[0]=='+' ){
199902 zIn++;
199903 N--;
199904 }else if( zIn[0]=='-' ){
199905 jsonAppendChar(p, '-');
199906 zIn++;
199907 N--;
199908 }
199909 if( zIn[0]=='0' && (zIn[1]=='x' || zIn[1]=='X') ){
199910 sqlite3_int64 i = 0;
199911 int rc = sqlite3DecOrHexToI64(zIn, &i);
199912 if( rc<=1 ){
199913 jsonPrintf(100,p,"%lld",i);
199914 }else{
199915 assert( rc==2 );
199916 jsonAppendRaw(p, "9.0e999", 7);
199917 }
199918 return;
199919 }
199920 jsonAppendRaw(p, zIn, N);
199921 }
199922
199923 /*
199924 ** The zIn[0..N] string is a JSON5 real literal. Append to p a translation
199925 ** of the string literal that standard JSON and that omits all JSON5
199926 ** features.
199927 */
199928 static void jsonAppendNormalizedReal(JsonString *p, const char *zIn, u32 N){
199929 u32 i;
199930 if( zIn[0]=='+' ){
199931 zIn++;
199932 N--;
199933 }else if( zIn[0]=='-' ){
199934 jsonAppendChar(p, '-');
199935 zIn++;
199936 N--;
199937 }
199938 if( zIn[0]=='.' ){
199939 jsonAppendChar(p, '0');
199940 }
199941 for(i=0; i<N; i++){
199942 if( zIn[i]=='.' && (i+1==N || !sqlite3Isdigit(zIn[i+1])) ){
199943 i++;
199944 jsonAppendRaw(p, zIn, i);
199945 zIn += i;
199946 N -= i;
199947 jsonAppendChar(p, '0');
199948 break;
199949 }
199950 }
199951 if( N>0 ){
199952 jsonAppendRaw(p, zIn, N);
199953 }
199954 }
199955
199956
199957
199958 /*
199959 ** Append a function parameter value to the JSON string under
199960 ** construction.
199961 */
@@ -199820,21 +200083,42 @@
200083 case JSON_FALSE: {
200084 jsonAppendRaw(pOut, "false", 5);
200085 break;
200086 }
200087 case JSON_STRING: {
200088 assert( pNode->eU==1 );
200089 if( pNode->jnFlags & JNODE_RAW ){
200090 if( pNode->jnFlags & JNODE_LABEL ){
200091 jsonAppendChar(pOut, '"');
200092 jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
200093 jsonAppendChar(pOut, '"');
200094 }else{
200095 jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
200096 }
200097 }else if( pNode->jnFlags & JNODE_JSON5 ){
200098 jsonAppendNormalizedString(pOut, pNode->u.zJContent, pNode->n);
200099 }else{
200100 jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
200101 }
200102 break;
200103 }
200104 case JSON_REAL: {
200105 assert( pNode->eU==1 );
200106 if( pNode->jnFlags & JNODE_JSON5 ){
200107 jsonAppendNormalizedReal(pOut, pNode->u.zJContent, pNode->n);
200108 }else{
200109 jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
200110 }
200111 break;
200112 }
200113 case JSON_INT: {
200114 assert( pNode->eU==1 );
200115 if( pNode->jnFlags & JNODE_JSON5 ){
200116 jsonAppendNormalizedInt(pOut, pNode->u.zJContent, pNode->n);
200117 }else{
200118 jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
200119 }
200120 break;
200121 }
200122 case JSON_ARRAY: {
200123 u32 j = 1;
200124 jsonAppendChar(pOut, '[');
@@ -199946,63 +200230,45 @@
200230 sqlite3_result_int(pCtx, 0);
200231 break;
200232 }
200233 case JSON_INT: {
200234 sqlite3_int64 i = 0;
200235 int rc;
200236 int bNeg = 0;
200237 const char *z;
200238
200239
200240 assert( pNode->eU==1 );
200241 z = pNode->u.zJContent;
200242 if( z[0]=='-' ){ z++; bNeg = 1; }
200243 else if( z[0]=='+' ){ z++; }
200244 rc = sqlite3DecOrHexToI64(z, &i);
200245 if( rc<=1 ){
200246 sqlite3_result_int64(pCtx, bNeg ? -i : i);
200247 }else if( rc==3 && bNeg ){
200248 sqlite3_result_int64(pCtx, SMALLEST_INT64);
200249 }else{
200250 goto to_double;
200251 }
200252 break;
 
 
 
 
 
 
 
 
 
 
 
 
200253 }
200254 case JSON_REAL: {
200255 double r;
 
200256 const char *z;
200257 assert( pNode->eU==1 );
200258 to_double:
200259 z = pNode->u.zJContent;
200260 sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
 
 
 
 
200261 sqlite3_result_double(pCtx, r);
200262 break;
200263 }
200264 case JSON_STRING: {
 
 
 
200265 if( pNode->jnFlags & JNODE_RAW ){
200266 assert( pNode->eU==1 );
200267 sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
200268 SQLITE_TRANSIENT);
200269 }else if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
 
 
 
200270 /* JSON formatted without any backslash-escapes */
200271 assert( pNode->eU==1 );
200272 sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
200273 SQLITE_TRANSIENT);
200274 }else{
@@ -200010,22 +200276,21 @@
200276 u32 i;
200277 u32 n = pNode->n;
200278 const char *z;
200279 char *zOut;
200280 u32 j;
200281 u32 nOut = n;
200282 assert( pNode->eU==1 );
200283 z = pNode->u.zJContent;
200284 zOut = sqlite3_malloc( nOut+1 );
200285 if( zOut==0 ){
200286 sqlite3_result_error_nomem(pCtx);
200287 break;
200288 }
200289 for(i=1, j=0; i<n-1; i++){
200290 char c = z[i];
200291 if( c=='\\' ){
 
 
200292 c = z[++i];
200293 if( c=='u' ){
200294 u32 v = jsonHexToInt4(z+i+1);
200295 i += 4;
200296 if( v==0 ) break;
@@ -200053,26 +200318,44 @@
200318 zOut[j++] = 0xe0 | (v>>12);
200319 zOut[j++] = 0x80 | ((v>>6)&0x3f);
200320 zOut[j++] = 0x80 | (v&0x3f);
200321 }
200322 }
200323 continue;
200324 }else if( c=='b' ){
200325 c = '\b';
200326 }else if( c=='f' ){
200327 c = '\f';
200328 }else if( c=='n' ){
200329 c = '\n';
200330 }else if( c=='r' ){
200331 c = '\r';
200332 }else if( c=='t' ){
200333 c = '\t';
200334 }else if( c=='v' ){
200335 c = '\v';
200336 }else if( c=='\'' || c=='"' || c=='/' || c=='\\' ){
200337 /* pass through unchanged */
200338 }else if( c=='0' ){
200339 c = 0;
200340 }else if( c=='x' ){
200341 c = (jsonHexToInt(z[i+1])<<4) | jsonHexToInt(z[i+2]);
200342 i += 2;
200343 }else if( c=='\r' && z[i+1]=='\n' ){
200344 i++;
200345 continue;
200346 }else if( 0xe2==(u8)c ){
200347 assert( 0x80==(u8)z[i+1] );
200348 assert( 0xa8==(u8)z[i+2] || 0xa9==(u8)z[i+2] );
200349 i += 2;
200350 continue;
200351 }else{
200352 continue;
200353 }
200354 } /* end if( c=='\\' ) */
200355 zOut[j++] = c;
200356 } /* end for() */
 
 
 
 
 
 
 
 
 
 
200357 zOut[j] = 0;
200358 sqlite3_result_text(pCtx, zOut, j, sqlite3_free);
200359 }
200360 break;
200361 }
@@ -200136,28 +200419,159 @@
200419 JsonNode *p;
200420 if( pParse->aNode==0 || pParse->nNode>=pParse->nAlloc ){
200421 return jsonParseAddNodeExpand(pParse, eType, n, zContent);
200422 }
200423 p = &pParse->aNode[pParse->nNode];
200424 p->eType = (u8)(eType & 0xff);
200425 p->jnFlags = (u8)(eType >> 8);
200426 VVA( p->eU = zContent ? 1 : 0 );
200427 p->n = n;
200428 p->u.zJContent = zContent;
200429 return pParse->nNode++;
200430 }
200431
200432 /*
200433 ** Return true if z[] begins with 2 (or more) hexadecimal digits
200434 */
200435 static int jsonIs2Hex(const char *z){
200436 return sqlite3Isxdigit(z[0]) && sqlite3Isxdigit(z[1]);
200437 }
200438
200439 /*
200440 ** Return true if z[] begins with 4 (or more) hexadecimal digits
200441 */
200442 static int jsonIs4Hex(const char *z){
200443 return jsonIs2Hex(z) && jsonIs2Hex(&z[2]);
 
 
200444 }
200445
200446 /*
200447 ** Return the number of bytes of JSON5 whitespace at the beginning of
200448 ** the input string z[].
200449 **
200450 ** JSON5 whitespace consists of any of the following characters:
200451 **
200452 ** Unicode UTF-8 Name
200453 ** U+0009 09 horizontal tab
200454 ** U+000a 0a line feed
200455 ** U+000b 0b vertical tab
200456 ** U+000c 0c form feed
200457 ** U+000d 0d carriage return
200458 ** U+0020 20 space
200459 ** U+00a0 c2 a0 non-breaking space
200460 ** U+1680 e1 9a 80 ogham space mark
200461 ** U+2000 e2 80 80 en quad
200462 ** U+2001 e2 80 81 em quad
200463 ** U+2002 e2 80 82 en space
200464 ** U+2003 e2 80 83 em space
200465 ** U+2004 e2 80 84 three-per-em space
200466 ** U+2005 e2 80 85 four-per-em space
200467 ** U+2006 e2 80 86 six-per-em space
200468 ** U+2007 e2 80 87 figure space
200469 ** U+2008 e2 80 88 punctuation space
200470 ** U+2009 e2 80 89 thin space
200471 ** U+200a e2 80 8a hair space
200472 ** U+2028 e2 80 a8 line separator
200473 ** U+2029 e2 80 a9 paragraph separator
200474 ** U+202f e2 80 af narrow no-break space (NNBSP)
200475 ** U+205f e2 81 9f medium mathematical space (MMSP)
200476 ** U+3000 e3 80 80 ideographical space
200477 ** U+FEFF ef bb bf byte order mark
200478 **
200479 ** In addition, comments between '/', '*' and '*', '/' and
200480 ** from '/', '/' to end-of-line are also considered to be whitespace.
200481 */
200482 static int json5Whitespace(const char *zIn){
200483 int n = 0;
200484 const u8 *z = (u8*)zIn;
200485 while( 1 /*exit by "goto whitespace_done"*/ ){
200486 switch( z[n] ){
200487 case 0x09:
200488 case 0x0a:
200489 case 0x0b:
200490 case 0x0c:
200491 case 0x0d:
200492 case 0x20: {
200493 n++;
200494 break;
200495 }
200496 case '/': {
200497 if( z[n+1]=='*' && z[n+2]!=0 ){
200498 int j;
200499 for(j=n+3; z[j]!='/' || z[j-1]!='*'; j++){
200500 if( z[j]==0 ) goto whitespace_done;
200501 }
200502 n = j+1;
200503 break;
200504 }else if( z[n+1]=='/' ){
200505 int j;
200506 char c;
200507 for(j=n+2; (c = z[j])!=0; j++){
200508 if( c=='\n' || c=='\r' ) break;
200509 if( 0xe2==(u8)c && 0x80==(u8)z[j+1]
200510 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2])
200511 ){
200512 j += 2;
200513 break;
200514 }
200515 }
200516 n = j;
200517 if( z[n] ) n++;
200518 break;
200519 }
200520 goto whitespace_done;
200521 }
200522 case 0xc2: {
200523 if( z[n+1]==0xa0 ){
200524 n += 2;
200525 break;
200526 }
200527 goto whitespace_done;
200528 }
200529 case 0xe1: {
200530 if( z[n+1]==0x9a && z[n+2]==0x80 ){
200531 n += 3;
200532 break;
200533 }
200534 goto whitespace_done;
200535 }
200536 case 0xe2: {
200537 if( z[n+1]==0x80 ){
200538 u8 c = z[n+2];
200539 if( c<0x80 ) goto whitespace_done;
200540 if( c<=0x8a || c==0xa8 || c==0xa9 || c==0xaf ){
200541 n += 3;
200542 break;
200543 }
200544 }else if( z[n+1]==0x81 && z[n+2]==0x9f ){
200545 n += 3;
200546 break;
200547 }
200548 goto whitespace_done;
200549 }
200550 case 0xe3: {
200551 if( z[n+1]==0x80 && z[n+2]==0x80 ){
200552 n += 3;
200553 break;
200554 }
200555 goto whitespace_done;
200556 }
200557 case 0xef: {
200558 if( z[n+1]==0xbb && z[n+2]==0xbf ){
200559 n += 3;
200560 break;
200561 }
200562 goto whitespace_done;
200563 }
200564 default: {
200565 goto whitespace_done;
200566 }
200567 }
200568 }
200569 whitespace_done:
200570 return n;
200571 }
200572
200573 /*
200574 ** Extra floating-point literals to allow in JSON.
200575 */
200576 static const struct NanInfName {
200577 char c1;
@@ -200172,204 +200586,456 @@
200586 { 'i', 'I', 8, JSON_REAL, 7, "infinity", "9.0e999" },
200587 { 'n', 'N', 3, JSON_NULL, 4, "NaN", "null" },
200588 { 'q', 'Q', 4, JSON_NULL, 4, "QNaN", "null" },
200589 { 's', 'S', 4, JSON_NULL, 4, "SNaN", "null" },
200590 };
 
200591
200592 /*
200593 ** Parse a single JSON value which begins at pParse->zJson[i]. Return the
200594 ** index of the first character past the end of the value parsed.
200595 **
200596 ** Special return values:
200597 **
200598 ** 0 End if input
200599 ** -1 Syntax error
200600 ** -2 '}' seen
200601 ** -3 ']' seen
200602 ** -4 ',' seen
200603 ** -5 ':' seen
200604 */
200605 static int jsonParseValue(JsonParse *pParse, u32 i){
200606 char c;
200607 u32 j;
200608 int iThis;
200609 int x;
200610 JsonNode *pNode;
200611 const char *z = pParse->zJson;
200612 json_parse_restart:
200613 switch( (u8)z[i] ){
200614 case '{': {
200615 /* Parse object */
200616 iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
200617 if( iThis<0 ) return -1;
200618 for(j=i+1;;j++){
200619 if( ++pParse->iDepth > JSON_MAX_DEPTH ){
200620 pParse->iErr = j;
200621 return -1;
200622 }
200623 x = jsonParseValue(pParse, j);
200624 if( x<=0 ){
200625 if( x==(-2) ){
200626 j = pParse->iErr;
200627 if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
200628 pParse->iDepth--;
200629 break;
200630 }
200631 j += json5Whitespace(&z[j]);
200632 if( sqlite3JsonId1(z[j])
200633 || (z[j]=='\\' && z[j+1]=='u' && jsonIs4Hex(&z[j+2]))
200634 ){
200635 int k = j+1;
200636 while( (sqlite3JsonId2(z[k]) && json5Whitespace(&z[k])==0)
200637 || (z[k]=='\\' && z[k+1]=='u' && jsonIs4Hex(&z[k+2]))
200638 ){
200639 k++;
200640 }
200641 jsonParseAddNode(pParse, JSON_STRING | (JNODE_RAW<<8), k-j, &z[j]);
200642 pParse->hasNonstd = 1;
200643 x = k;
200644 }else{
200645 if( x!=-1 ) pParse->iErr = j;
200646 return -1;
200647 }
200648 }
200649 if( pParse->oom ) return -1;
200650 pNode = &pParse->aNode[pParse->nNode-1];
200651 if( pNode->eType!=JSON_STRING ){
200652 pParse->iErr = j;
200653 return -1;
200654 }
200655 pNode->jnFlags |= JNODE_LABEL;
200656 j = x;
200657 if( z[j]==':' ){
200658 j++;
200659 }else{
200660 if( fast_isspace(z[j]) ){
200661 do{ j++; }while( fast_isspace(z[j]) );
200662 if( z[j]==':' ){
200663 j++;
200664 goto parse_object_value;
200665 }
200666 }
200667 x = jsonParseValue(pParse, j);
200668 if( x!=(-5) ){
200669 if( x!=(-1) ) pParse->iErr = j;
200670 return -1;
200671 }
200672 j = pParse->iErr+1;
200673 }
200674 parse_object_value:
200675 x = jsonParseValue(pParse, j);
200676 pParse->iDepth--;
200677 if( x<=0 ){
200678 if( x!=(-1) ) pParse->iErr = j;
200679 return -1;
200680 }
200681 j = x;
200682 if( z[j]==',' ){
200683 continue;
200684 }else if( z[j]=='}' ){
200685 break;
200686 }else{
200687 if( fast_isspace(z[j]) ){
200688 do{ j++; }while( fast_isspace(z[j]) );
200689 if( z[j]==',' ){
200690 continue;
200691 }else if( z[j]=='}' ){
200692 break;
200693 }
200694 }
200695 x = jsonParseValue(pParse, j);
200696 if( x==(-4) ){
200697 j = pParse->iErr;
200698 continue;
200699 }
200700 if( x==(-2) ){
200701 j = pParse->iErr;
200702 break;
200703 }
200704 }
200705 pParse->iErr = j;
200706 return -1;
200707 }
200708 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
200709 return j+1;
200710 }
200711 case '[': {
200712 /* Parse array */
200713 iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
200714 if( iThis<0 ) return -1;
200715 memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
200716 for(j=i+1;;j++){
200717 if( ++pParse->iDepth > JSON_MAX_DEPTH ){
200718 pParse->iErr = j;
200719 return -1;
200720 }
200721 x = jsonParseValue(pParse, j);
200722 pParse->iDepth--;
200723 if( x<=0 ){
200724 if( x==(-3) ){
200725 j = pParse->iErr;
200726 if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
200727 break;
200728 }
200729 if( x!=(-1) ) pParse->iErr = j;
200730 return -1;
200731 }
200732 j = x;
200733 if( z[j]==',' ){
200734 continue;
200735 }else if( z[j]==']' ){
200736 break;
200737 }else{
200738 if( fast_isspace(z[j]) ){
200739 do{ j++; }while( fast_isspace(z[j]) );
200740 if( z[j]==',' ){
200741 continue;
200742 }else if( z[j]==']' ){
200743 break;
200744 }
200745 }
200746 x = jsonParseValue(pParse, j);
200747 if( x==(-4) ){
200748 j = pParse->iErr;
200749 continue;
200750 }
200751 if( x==(-3) ){
200752 j = pParse->iErr;
200753 break;
200754 }
200755 }
200756 pParse->iErr = j;
200757 return -1;
200758 }
200759 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
200760 return j+1;
200761 }
200762 case '\'': {
200763 u8 jnFlags;
200764 char cDelim;
200765 pParse->hasNonstd = 1;
200766 jnFlags = JNODE_JSON5;
200767 goto parse_string;
200768 case '"':
200769 /* Parse string */
200770 jnFlags = 0;
200771 parse_string:
200772 cDelim = z[i];
200773 j = i+1;
200774 for(;;){
200775 c = z[j];
200776 if( (c & ~0x1f)==0 ){
200777 /* Control characters are not allowed in strings */
200778 pParse->iErr = j;
200779 return -1;
200780 }
200781 if( c=='\\' ){
200782 c = z[++j];
200783 if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
200784 || c=='n' || c=='r' || c=='t'
200785 || (c=='u' && jsonIs4Hex(&z[j+1])) ){
200786 jnFlags |= JNODE_ESCAPE;
200787 }else if( c=='\'' || c=='0' || c=='v' || c=='\n'
200788 || (0xe2==(u8)c && 0x80==(u8)z[j+1]
200789 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
200790 || (c=='x' && jsonIs2Hex(&z[j+1])) ){
200791 jnFlags |= (JNODE_ESCAPE|JNODE_JSON5);
200792 pParse->hasNonstd = 1;
200793 }else if( c=='\r' ){
200794 if( z[j+1]=='\n' ) j++;
200795 jnFlags |= (JNODE_ESCAPE|JNODE_JSON5);
200796 pParse->hasNonstd = 1;
200797 }else{
200798 pParse->iErr = j;
200799 return -1;
200800 }
200801 }else if( c==cDelim ){
200802 break;
200803 }
200804 j++;
200805 }
200806 jsonParseAddNode(pParse, JSON_STRING | (jnFlags<<8), j+1-i, &z[i]);
 
200807 return j+1;
200808 }
200809 case 'n': {
200810 if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
200811 jsonParseAddNode(pParse, JSON_NULL, 0, 0);
200812 return i+4;
200813 }
200814 pParse->iErr = i;
200815 return -1;
200816 }
200817 case 't': {
200818 if( strncmp(z+i,"true",4)==0 && !sqlite3Isalnum(z[i+4]) ){
200819 jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
200820 return i+4;
200821 }
200822 pParse->iErr = i;
200823 return -1;
200824 }
200825 case 'f': {
200826 if( strncmp(z+i,"false",5)==0 && !sqlite3Isalnum(z[i+5]) ){
200827 jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
200828 return i+5;
200829 }
200830 pParse->iErr = i;
200831 return -1;
200832 }
200833 case '+': {
200834 u8 seenDP, seenE, jnFlags;
200835 pParse->hasNonstd = 1;
200836 jnFlags = JNODE_JSON5;
200837 goto parse_number;
200838 case '.':
200839 if( sqlite3Isdigit(z[i+1]) ){
200840 pParse->hasNonstd = 1;
200841 jnFlags = JNODE_JSON5;
200842 seenE = 0;
200843 seenDP = JSON_REAL;
200844 goto parse_number_2;
200845 }
200846 pParse->iErr = i;
200847 return -1;
200848 case '-':
200849 case '0':
200850 case '1':
200851 case '2':
200852 case '3':
200853 case '4':
200854 case '5':
200855 case '6':
200856 case '7':
200857 case '8':
200858 case '9':
200859 /* Parse number */
200860 jnFlags = 0;
200861 parse_number:
200862 seenDP = JSON_INT;
200863 seenE = 0;
200864 assert( '-' < '0' );
200865 assert( '+' < '0' );
200866 assert( '.' < '0' );
200867 c = z[i];
200868
200869 if( c<='0' ){
200870 if( c=='0' ){
200871 if( (z[i+1]=='x' || z[i+1]=='X') && sqlite3Isxdigit(z[i+2]) ){
200872 assert( seenDP==JSON_INT );
200873 pParse->hasNonstd = 1;
200874 jnFlags |= JNODE_JSON5;
200875 for(j=i+3; sqlite3Isxdigit(z[j]); j++){}
200876 goto parse_number_finish;
200877 }else if( sqlite3Isdigit(z[i+1]) ){
200878 pParse->iErr = i+1;
200879 return -1;
200880 }
200881 }else{
200882 if( !sqlite3Isdigit(z[i+1]) ){
200883 /* JSON5 allows for "+Infinity" and "-Infinity" using exactly
200884 ** that case. SQLite also allows these in any case and it allows
200885 ** "+inf" and "-inf". */
200886 if( (z[i+1]=='I' || z[i+1]=='i')
200887 && sqlite3StrNICmp(&z[i+1], "inf",3)==0
200888 ){
200889 pParse->hasNonstd = 1;
200890 if( z[i]=='-' ){
200891 jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999");
200892 }else{
200893 jsonParseAddNode(pParse, JSON_REAL, 7, "9.0e999");
200894 }
200895 return i + (sqlite3StrNICmp(&z[i+4],"inity",5)==0 ? 9 : 4);
200896 }
200897 if( z[i+1]=='.' ){
200898 pParse->hasNonstd = 1;
200899 jnFlags |= JNODE_JSON5;
200900 goto parse_number_2;
200901 }
200902 pParse->iErr = i;
200903 return -1;
200904 }
200905 if( z[i+1]=='0' ){
200906 if( sqlite3Isdigit(z[i+2]) ){
200907 pParse->iErr = i+1;
200908 return -1;
200909 }else if( (z[i+2]=='x' || z[i+2]=='X') && sqlite3Isxdigit(z[i+3]) ){
200910 pParse->hasNonstd = 1;
200911 jnFlags |= JNODE_JSON5;
200912 for(j=i+4; sqlite3Isxdigit(z[j]); j++){}
200913 goto parse_number_finish;
200914 }
200915 }
200916 }
200917 }
200918 parse_number_2:
200919 for(j=i+1;; j++){
200920 c = z[j];
200921 if( sqlite3Isdigit(c) ) continue;
200922 if( c=='.' ){
200923 if( seenDP==JSON_REAL ){
200924 pParse->iErr = j;
200925 return -1;
200926 }
200927 seenDP = JSON_REAL;
200928 continue;
200929 }
200930 if( c=='e' || c=='E' ){
200931 if( z[j-1]<'0' ){
200932 if( ALWAYS(z[j-1]=='.') && ALWAYS(j-2>=i) && sqlite3Isdigit(z[j-2]) ){
200933 pParse->hasNonstd = 1;
200934 jnFlags |= JNODE_JSON5;
200935 }else{
200936 pParse->iErr = j;
200937 return -1;
200938 }
200939 }
200940 if( seenE ){
200941 pParse->iErr = j;
200942 return -1;
200943 }
200944 seenDP = JSON_REAL;
200945 seenE = 1;
200946 c = z[j+1];
200947 if( c=='+' || c=='-' ){
200948 j++;
200949 c = z[j+1];
200950 }
200951 if( c<'0' || c>'9' ){
200952 pParse->iErr = j;
200953 return -1;
200954 }
200955 continue;
200956 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200957 break;
200958 }
200959 if( z[j-1]<'0' ){
200960 if( ALWAYS(z[j-1]=='.') && ALWAYS(j-2>=i) && sqlite3Isdigit(z[j-2]) ){
200961 pParse->hasNonstd = 1;
200962 jnFlags |= JNODE_JSON5;
200963 }else{
200964 pParse->iErr = j;
200965 return -1;
200966 }
200967 }
200968 parse_number_finish:
200969 jsonParseAddNode(pParse, seenDP | (jnFlags<<8), j - i, &z[i]);
200970 return j;
200971 }
200972 case '}': {
200973 pParse->iErr = i;
200974 return -2; /* End of {...} */
200975 }
200976 case ']': {
200977 pParse->iErr = i;
200978 return -3; /* End of [...] */
200979 }
200980 case ',': {
200981 pParse->iErr = i;
200982 return -4; /* List separator */
200983 }
200984 case ':': {
200985 pParse->iErr = i;
200986 return -5; /* Object label/value separator */
200987 }
200988 case 0: {
200989 return 0; /* End of file */
200990 }
200991 case 0x09:
200992 case 0x0a:
200993 case 0x0d:
200994 case 0x20: {
200995 do{
200996 i++;
200997 }while( fast_isspace(z[i]) );
200998 goto json_parse_restart;
200999 }
201000 case 0x0b:
201001 case 0x0c:
201002 case '/':
201003 case 0xc2:
201004 case 0xe1:
201005 case 0xe2:
201006 case 0xe3:
201007 case 0xef: {
201008 j = json5Whitespace(&z[i]);
201009 if( j>0 ){
201010 i += j;
201011 pParse->hasNonstd = 1;
201012 goto json_parse_restart;
201013 }
201014 pParse->iErr = i;
201015 return -1;
201016 }
201017 default: {
201018 u32 k;
201019 int nn;
201020 c = z[i];
201021 for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
201022 if( c!=aNanInfName[k].c1 && c!=aNanInfName[k].c2 ) continue;
201023 nn = aNanInfName[k].n;
201024 if( sqlite3StrNICmp(&z[i], aNanInfName[k].zMatch, nn)!=0 ){
201025 continue;
201026 }
201027 if( sqlite3Isalnum(z[i+nn]) ) continue;
201028 jsonParseAddNode(pParse, aNanInfName[k].eType,
201029 aNanInfName[k].nRepl, aNanInfName[k].zRepl);
201030 pParse->hasNonstd = 1;
201031 return i + nn;
201032 }
201033 pParse->iErr = i;
201034 return -1; /* Syntax error */
201035 }
201036 } /* End switch(z[i]) */
201037 }
201038
201039 /*
201040 ** Parse a complete JSON string. Return 0 on success or non-zero if there
201041 ** are any errors. If an error occurs, free all memory associated with
@@ -200389,11 +201055,18 @@
201055 i = jsonParseValue(pParse, 0);
201056 if( pParse->oom ) i = -1;
201057 if( i>0 ){
201058 assert( pParse->iDepth==0 );
201059 while( fast_isspace(zJson[i]) ) i++;
201060 if( zJson[i] ){
201061 i += json5Whitespace(&zJson[i]);
201062 if( zJson[i] ){
201063 jsonParseReset(pParse);
201064 return 1;
201065 }
201066 pParse->hasNonstd = 1;
201067 }
201068 }
201069 if( i<=0 ){
201070 if( pCtx!=0 ){
201071 if( pParse->oom ){
201072 sqlite3_result_error_nomem(pCtx);
@@ -200460,10 +201133,19 @@
201133 ** of the argv array. Use the sqlite3_get_auxdata() cache for this
201134 ** parse if it is available. If the cache is not available or if it
201135 ** is no longer valid, parse the JSON again and return the new parse,
201136 ** and also register the new parse so that it will be available for
201137 ** future sqlite3_get_auxdata() calls.
201138 **
201139 ** If an error occurs and pErrCtx!=0 then report the error on pErrCtx
201140 ** and return NULL.
201141 **
201142 ** If an error occurs and pErrCtx==0 then return the Parse object with
201143 ** JsonParse.nErr non-zero. If the caller invokes this routine with
201144 ** pErrCtx==0 and it gets back a JsonParse with nErr!=0, then the caller
201145 ** is responsible for invoking jsonParseFree() on the returned value.
201146 ** But the caller may invoke jsonParseFree() *only* if pParse->nErr!=0.
201147 */
201148 static JsonParse *jsonParseCached(
201149 sqlite3_context *pCtx,
201150 sqlite3_value **argv,
201151 sqlite3_context *pErrCtx
@@ -200509,10 +201191,14 @@
201191 }
201192 memset(p, 0, sizeof(*p));
201193 p->zJson = (char*)&p[1];
201194 memcpy((char*)p->zJson, zJson, nJson+1);
201195 if( jsonParse(p, pErrCtx, p->zJson) ){
201196 if( pErrCtx==0 ){
201197 p->nErr = 1;
201198 return p;
201199 }
201200 sqlite3_free(p);
201201 return 0;
201202 }
201203 p->nJson = nJson;
201204 p->iHold = iMaxHold+1;
@@ -200523,19 +201209,28 @@
201209
201210 /*
201211 ** Compare the OBJECT label at pNode against zKey,nKey. Return true on
201212 ** a match.
201213 */
201214 static int jsonLabelCompare(const JsonNode *pNode, const char *zKey, u32 nKey){
201215 assert( pNode->eU==1 );
201216 if( pNode->jnFlags & JNODE_RAW ){
201217 if( pNode->n!=nKey ) return 0;
201218 return strncmp(pNode->u.zJContent, zKey, nKey)==0;
201219 }else{
201220 if( pNode->n!=nKey+2 ) return 0;
201221 return strncmp(pNode->u.zJContent+1, zKey, nKey)==0;
201222 }
201223 }
201224 static int jsonSameLabel(const JsonNode *p1, const JsonNode *p2){
201225 if( p1->jnFlags & JNODE_RAW ){
201226 return jsonLabelCompare(p2, p1->u.zJContent, p1->n);
201227 }else if( p2->jnFlags & JNODE_RAW ){
201228 return jsonLabelCompare(p1, p2->u.zJContent, p2->n);
201229 }else{
201230 return p1->n==p2->n && strncmp(p1->u.zJContent,p2->u.zJContent,p1->n)==0;
201231 }
201232 }
201233
201234 /* forward declaration */
201235 static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**);
201236
@@ -201003,11 +201698,11 @@
201698 if( argc==2 ){
201699 /* With a single PATH argument */
201700 zPath = (const char*)sqlite3_value_text(argv[1]);
201701 if( zPath==0 ) return;
201702 if( flags & JSON_ABPATH ){
201703 if( zPath[0]!='$' || (zPath[1]!='.' && zPath[1]!='[' && zPath[1]!=0) ){
201704 /* The -> and ->> operators accept abbreviated PATH arguments. This
201705 ** is mostly for compatibility with PostgreSQL, but also for
201706 ** convenience.
201707 **
201708 ** NUMBER ==> $[NUMBER] // PG compatible
@@ -201094,16 +201789,14 @@
201789 assert( pPatch[i].eType==JSON_STRING );
201790 assert( pPatch[i].jnFlags & JNODE_LABEL );
201791 assert( pPatch[i].eU==1 );
201792 nKey = pPatch[i].n;
201793 zKey = pPatch[i].u.zJContent;
 
201794 for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
201795 assert( pTarget[j].eType==JSON_STRING );
201796 assert( pTarget[j].jnFlags & JNODE_LABEL );
201797 if( jsonSameLabel(&pPatch[i], &pTarget[j]) ){
 
201798 if( pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH) ) break;
201799 if( pPatch[i+1].eType==JSON_NULL ){
201800 pTarget[j+1].jnFlags |= JNODE_REMOVE;
201801 }else{
201802 JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
@@ -201386,22 +202079,81 @@
202079 }
202080
202081 /*
202082 ** json_valid(JSON)
202083 **
202084 ** Return 1 if JSON is a well-formed canonical JSON string according
202085 ** to RFC-7159. Return 0 otherwise.
202086 */
202087 static void jsonValidFunc(
202088 sqlite3_context *ctx,
202089 int argc,
202090 sqlite3_value **argv
202091 ){
202092 JsonParse *p; /* The parse */
202093 UNUSED_PARAMETER(argc);
202094 p = jsonParseCached(ctx, argv, 0);
202095 if( p==0 || p->oom ){
202096 sqlite3_result_error_nomem(ctx);
202097 sqlite3_free(p);
202098 }else{
202099 sqlite3_result_int(ctx, p->nErr==0 && p->hasNonstd==0);
202100 if( p->nErr ) jsonParseFree(p);
202101 }
202102 }
202103
202104 /*
202105 ** json_error_position(JSON)
202106 **
202107 ** If the argument is not an interpretable JSON string, then return the 1-based
202108 ** character position at which the parser first recognized that the input
202109 ** was in error. The left-most character is 1. If the string is valid
202110 ** JSON, then return 0.
202111 **
202112 ** Note that json_valid() is only true for strictly conforming canonical JSON.
202113 ** But this routine returns zero if the input contains extension. Thus:
202114 **
202115 ** (1) If the input X is strictly conforming canonical JSON:
202116 **
202117 ** json_valid(X) returns true
202118 ** json_error_position(X) returns 0
202119 **
202120 ** (2) If the input X is JSON but it includes extension (such as JSON5) that
202121 ** are not part of RFC-8259:
202122 **
202123 ** json_valid(X) returns false
202124 ** json_error_position(X) return 0
202125 **
202126 ** (3) If the input X cannot be interpreted as JSON even taking extensions
202127 ** into account:
202128 **
202129 ** json_valid(X) return false
202130 ** json_error_position(X) returns 1 or more
202131 */
202132 static void jsonErrorFunc(
202133 sqlite3_context *ctx,
202134 int argc,
202135 sqlite3_value **argv
202136 ){
202137 JsonParse *p; /* The parse */
202138 UNUSED_PARAMETER(argc);
202139 p = jsonParseCached(ctx, argv, 0);
202140 if( p==0 || p->oom ){
202141 sqlite3_result_error_nomem(ctx);
202142 sqlite3_free(p);
202143 }else if( p->nErr==0 ){
202144 sqlite3_result_int(ctx, 0);
202145 }else{
202146 int n = 1;
202147 u32 i;
202148 const char *z = p->zJson;
202149 for(i=0; i<p->iErr && ALWAYS(z[i]); i++){
202150 if( (z[i]&0xc0)!=0x80 ) n++;
202151 }
202152 sqlite3_result_int(ctx, n);
202153 jsonParseFree(p);
202154 }
202155 }
202156
202157
202158 /****************************************************************************
202159 ** Aggregate SQL function implementations
@@ -201741,18 +202493,20 @@
202493 assert( pNode->eType==JSON_STRING );
202494 assert( pNode->jnFlags & JNODE_LABEL );
202495 assert( pNode->eU==1 );
202496 z = pNode->u.zJContent;
202497 nn = pNode->n;
202498 if( (pNode->jnFlags & JNODE_RAW)==0 ){
202499 assert( nn>=2 );
202500 assert( z[0]=='"' || z[0]=='\'' );
202501 assert( z[nn-1]=='"' || z[0]=='\'' );
202502 if( nn>2 && sqlite3Isalpha(z[1]) ){
202503 for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
202504 if( jj==nn-1 ){
202505 z++;
202506 nn -= 2;
202507 }
202508 }
202509 }
202510 jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
202511 }
202512
@@ -202108,10 +202862,11 @@
202862 static FuncDef aJsonFunc[] = {
202863 JFUNCTION(json, 1, 0, jsonRemoveFunc),
202864 JFUNCTION(json_array, -1, 0, jsonArrayFunc),
202865 JFUNCTION(json_array_length, 1, 0, jsonArrayLengthFunc),
202866 JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc),
202867 JFUNCTION(json_error_position,1, 0, jsonErrorFunc),
202868 JFUNCTION(json_extract, -1, 0, jsonExtractFunc),
202869 JFUNCTION(->, 2, JSON_JSON, jsonExtractFunc),
202870 JFUNCTION(->>, 2, JSON_SQL, jsonExtractFunc),
202871 JFUNCTION(json_insert, -1, 0, jsonSetFunc),
202872 JFUNCTION(json_object, -1, 0, jsonObjectFunc),
@@ -202632,20 +203387,21 @@
203387 ** using C-preprocessor macros. If that is unsuccessful, or if
203388 ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
203389 ** at run-time.
203390 */
203391 #ifndef SQLITE_BYTEORDER
203392 # if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
203393 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
203394 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
203395 defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64)
203396 # define SQLITE_BYTEORDER 1234
203397 # elif defined(sparc) || defined(__ppc__) || \
203398 defined(__ARMEB__) || defined(__AARCH64EB__)
203399 # define SQLITE_BYTEORDER 4321
203400 # else
203401 # define SQLITE_BYTEORDER 0
203402 # endif
203403 #endif
203404
203405
203406 /* What version of MSVC is being used. 0 means MSVC is not being used */
203407 #ifndef MSVC_VERSION
@@ -216825,10 +217581,12 @@
217581 # define SESSIONS_STRM_CHUNK_SIZE 64
217582 # else
217583 # define SESSIONS_STRM_CHUNK_SIZE 1024
217584 # endif
217585 #endif
217586
217587 #define SESSIONS_ROWID "_rowid_"
217588
217589 static int sessions_strm_chunk_size = SESSIONS_STRM_CHUNK_SIZE;
217590
217591 typedef struct SessionHook SessionHook;
217592 struct SessionHook {
@@ -216847,10 +217605,11 @@
217605 char *zDb; /* Name of database session is attached to */
217606 int bEnableSize; /* True if changeset_size() enabled */
217607 int bEnable; /* True if currently recording */
217608 int bIndirect; /* True if all changes are indirect */
217609 int bAutoAttach; /* True to auto-attach tables */
217610 int bImplicitPK; /* True to handle tables with implicit PK */
217611 int rc; /* Non-zero if an error has occurred */
217612 void *pFilterCtx; /* First argument to pass to xTableFilter */
217613 int (*xTableFilter)(void *pCtx, const char *zTab);
217614 i64 nMalloc; /* Number of bytes of data allocated */
217615 i64 nMaxChangesetSize;
@@ -216923,10 +217682,11 @@
217682 struct SessionTable {
217683 SessionTable *pNext;
217684 char *zName; /* Local name of table */
217685 int nCol; /* Number of columns in table zName */
217686 int bStat1; /* True if this is sqlite_stat1 */
217687 int bRowid; /* True if this table uses rowid for PK */
217688 const char **azCol; /* Column names */
217689 u8 *abPK; /* Array of primary key flags */
217690 int nEntry; /* Total number of entries in hash table */
217691 int nChange; /* Size of apChange[] array */
217692 SessionChange **apChange; /* Hash table buckets */
@@ -217315,60 +218075,66 @@
218075 ** of *piHash asn *pbNullPK are undefined. Otherwise, SQLITE_OK is returned
218076 ** and the output variables are set as described above.
218077 */
218078 static int sessionPreupdateHash(
218079 sqlite3_session *pSession, /* Session object that owns pTab */
218080 i64 iRowid,
218081 SessionTable *pTab, /* Session table handle */
218082 int bNew, /* True to hash the new.* PK */
218083 int *piHash, /* OUT: Hash value */
218084 int *pbNullPK /* OUT: True if there are NULL values in PK */
218085 ){
218086 unsigned int h = 0; /* Hash value to return */
218087 int i; /* Used to iterate through columns */
218088
218089 if( pTab->bRowid ){
218090 assert( pTab->nCol-1==pSession->hook.xCount(pSession->hook.pCtx) );
218091 h = sessionHashAppendI64(h, iRowid);
218092 }else{
218093 assert( *pbNullPK==0 );
218094 assert( pTab->nCol==pSession->hook.xCount(pSession->hook.pCtx) );
218095 for(i=0; i<pTab->nCol; i++){
218096 if( pTab->abPK[i] ){
218097 int rc;
218098 int eType;
218099 sqlite3_value *pVal;
218100
218101 if( bNew ){
218102 rc = pSession->hook.xNew(pSession->hook.pCtx, i, &pVal);
218103 }else{
218104 rc = pSession->hook.xOld(pSession->hook.pCtx, i, &pVal);
218105 }
218106 if( rc!=SQLITE_OK ) return rc;
218107
218108 eType = sqlite3_value_type(pVal);
218109 h = sessionHashAppendType(h, eType);
218110 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
218111 i64 iVal;
218112 if( eType==SQLITE_INTEGER ){
218113 iVal = sqlite3_value_int64(pVal);
218114 }else{
218115 double rVal = sqlite3_value_double(pVal);
218116 assert( sizeof(iVal)==8 && sizeof(rVal)==8 );
218117 memcpy(&iVal, &rVal, 8);
218118 }
218119 h = sessionHashAppendI64(h, iVal);
218120 }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
218121 const u8 *z;
218122 int n;
218123 if( eType==SQLITE_TEXT ){
218124 z = (const u8 *)sqlite3_value_text(pVal);
218125 }else{
218126 z = (const u8 *)sqlite3_value_blob(pVal);
218127 }
218128 n = sqlite3_value_bytes(pVal);
218129 if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
218130 h = sessionHashAppendBlob(h, n, z);
218131 }else{
218132 assert( eType==SQLITE_NULL );
218133 assert( pTab->bStat1==0 || i!=1 );
218134 *pbNullPK = 1;
218135 }
218136 }
218137 }
218138 }
218139
218140 *piHash = (h % pTab->nChange);
@@ -217647,16 +218413,22 @@
218413 ** if the pre-update-hook does not affect the same row as pChange, it returns
218414 ** false.
218415 */
218416 static int sessionPreupdateEqual(
218417 sqlite3_session *pSession, /* Session object that owns SessionTable */
218418 i64 iRowid, /* Rowid value if pTab->bRowid */
218419 SessionTable *pTab, /* Table associated with change */
218420 SessionChange *pChange, /* Change to compare to */
218421 int op /* Current pre-update operation */
218422 ){
218423 int iCol; /* Used to iterate through columns */
218424 u8 *a = pChange->aRecord; /* Cursor used to scan change record */
218425
218426 if( pTab->bRowid ){
218427 if( a[0]!=SQLITE_INTEGER ) return 0;
218428 return sessionGetI64(&a[1])==iRowid;
218429 }
218430
218431 assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE );
218432 for(iCol=0; iCol<pTab->nCol; iCol++){
218433 if( !pTab->abPK[iCol] ){
218434 a += sessionSerialLen(a);
@@ -217798,11 +218570,12 @@
218570 const char *zDb, /* Name of attached database (e.g. "main") */
218571 const char *zThis, /* Table name */
218572 int *pnCol, /* OUT: number of columns */
218573 const char **pzTab, /* OUT: Copy of zThis */
218574 const char ***pazCol, /* OUT: Array of column names for table */
218575 u8 **pabPK, /* OUT: Array of booleans - true for PK col */
218576 int *pbRowid /* OUT: True if only PK is a rowid */
218577 ){
218578 char *zPragma;
218579 sqlite3_stmt *pStmt;
218580 int rc;
218581 sqlite3_int64 nByte;
@@ -217810,10 +218583,11 @@
218583 int nThis;
218584 int i;
218585 u8 *pAlloc = 0;
218586 char **azCol = 0;
218587 u8 *abPK = 0;
218588 int bRowid = 0; /* Set to true to use rowid as PK */
218589
218590 assert( pazCol && pabPK );
218591
218592 nThis = sqlite3Strlen30(zThis);
218593 if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
@@ -217854,14 +218628,19 @@
218628 if( pzTab ) *pzTab = 0;
218629 return rc;
218630 }
218631
218632 nByte = nThis + 1;
218633 bRowid = (pbRowid!=0);
218634 while( SQLITE_ROW==sqlite3_step(pStmt) ){
218635 nByte += sqlite3_column_bytes(pStmt, 1);
218636 nDbCol++;
218637 if( sqlite3_column_int(pStmt, 5) ) bRowid = 0;
218638 }
218639 if( nDbCol==0 ) bRowid = 0;
218640 nDbCol += bRowid;
218641 nByte += strlen(SESSIONS_ROWID);
218642 rc = sqlite3_reset(pStmt);
218643
218644 if( rc==SQLITE_OK ){
218645 nByte += nDbCol * (sizeof(const char *) + sizeof(u8) + 1);
218646 pAlloc = sessionMalloc64(pSession, nByte);
@@ -217879,10 +218658,18 @@
218658 *pzTab = (char *)pAlloc;
218659 pAlloc += nThis+1;
218660 }
218661
218662 i = 0;
218663 if( bRowid ){
218664 size_t nName = strlen(SESSIONS_ROWID);
218665 memcpy(pAlloc, SESSIONS_ROWID, nName+1);
218666 azCol[i] = (char*)pAlloc;
218667 pAlloc += nName+1;
218668 abPK[i] = 1;
218669 i++;
218670 }
218671 while( SQLITE_ROW==sqlite3_step(pStmt) ){
218672 int nName = sqlite3_column_bytes(pStmt, 1);
218673 const unsigned char *zName = sqlite3_column_text(pStmt, 1);
218674 if( zName==0 ) break;
218675 memcpy(pAlloc, zName, nName+1);
@@ -217890,11 +218677,10 @@
218677 pAlloc += nName+1;
218678 abPK[i] = sqlite3_column_int(pStmt, 5);
218679 i++;
218680 }
218681 rc = sqlite3_reset(pStmt);
 
218682 }
218683
218684 /* If successful, populate the output variables. Otherwise, zero them and
218685 ** free any allocation made. An error code will be returned in this case.
218686 */
@@ -217907,10 +218693,11 @@
218693 *pabPK = 0;
218694 *pnCol = 0;
218695 if( pzTab ) *pzTab = 0;
218696 sessionFree(pSession, azCol);
218697 }
218698 if( pbRowid ) *pbRowid = bRowid;
218699 sqlite3_finalize(pStmt);
218700 return rc;
218701 }
218702
218703 /*
@@ -217928,11 +218715,12 @@
218715 static int sessionInitTable(sqlite3_session *pSession, SessionTable *pTab){
218716 if( pTab->nCol==0 ){
218717 u8 *abPK;
218718 assert( pTab->azCol==0 || pTab->abPK==0 );
218719 pSession->rc = sessionTableInfo(pSession, pSession->db, pSession->zDb,
218720 pTab->zName, &pTab->nCol, 0, &pTab->azCol, &abPK,
218721 (pSession->bImplicitPK ? &pTab->bRowid : 0)
218722 );
218723 if( pSession->rc==SQLITE_OK ){
218724 int i;
218725 for(i=0; i<pTab->nCol; i++){
218726 if( abPK[i] ){
@@ -218000,10 +218788,11 @@
218788 SessionTable *pTab, /* Table that change applies to */
218789 SessionChange *pC /* Update pC->nMaxSize */
218790 ){
218791 i64 nNew = 2;
218792 if( pC->op==SQLITE_INSERT ){
218793 if( pTab->bRowid ) nNew += 9;
218794 if( op!=SQLITE_DELETE ){
218795 int ii;
218796 for(ii=0; ii<pTab->nCol; ii++){
218797 sqlite3_value *p = 0;
218798 pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
@@ -218016,11 +218805,15 @@
218805 nNew += pC->nRecord;
218806 }
218807 }else{
218808 int ii;
218809 u8 *pCsr = pC->aRecord;
218810 if( pTab->bRowid ){
218811 nNew += 9;
218812 pCsr += 9;
218813 }
218814 for(ii=0; ii<(pTab->nCol-pTab->bRowid); ii++){
218815 int bChanged = 1;
218816 int nOld = 0;
218817 int eType;
218818 sqlite3_value *p = 0;
218819 pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
@@ -218100,10 +218893,11 @@
218893 ** Unless one is already present or an error occurs, an entry is added
218894 ** to the changed-rows hash table associated with table pTab.
218895 */
218896 static void sessionPreupdateOneChange(
218897 int op, /* One of SQLITE_UPDATE, INSERT, DELETE */
218898 i64 iRowid,
218899 sqlite3_session *pSession, /* Session object pTab is attached to */
218900 SessionTable *pTab /* Table that change applies to */
218901 ){
218902 int iHash;
218903 int bNull = 0;
@@ -218115,11 +218909,11 @@
218909 /* Load table details if required */
218910 if( sessionInitTable(pSession, pTab) ) return;
218911
218912 /* Check the number of columns in this xPreUpdate call matches the
218913 ** number of columns in the table. */
218914 if( (pTab->nCol-pTab->bRowid)!=pSession->hook.xCount(pSession->hook.pCtx) ){
218915 pSession->rc = SQLITE_SCHEMA;
218916 return;
218917 }
218918
218919 /* Grow the hash table if required */
@@ -218148,18 +218942,20 @@
218942 }
218943
218944 /* Calculate the hash-key for this change. If the primary key of the row
218945 ** includes a NULL value, exit early. Such changes are ignored by the
218946 ** session module. */
218947 rc = sessionPreupdateHash(
218948 pSession, iRowid, pTab, op==SQLITE_INSERT, &iHash, &bNull
218949 );
218950 if( rc!=SQLITE_OK ) goto error_out;
218951
218952 if( bNull==0 ){
218953 /* Search the hash table for an existing record for this row. */
218954 SessionChange *pC;
218955 for(pC=pTab->apChange[iHash]; pC; pC=pC->pNext){
218956 if( sessionPreupdateEqual(pSession, iRowid, pTab, pC, op) ) break;
218957 }
218958
218959 if( pC==0 ){
218960 /* Create a new change object containing all the old values (if
218961 ** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
@@ -218170,11 +218966,11 @@
218966 assert( rc==SQLITE_OK );
218967 pTab->nEntry++;
218968
218969 /* Figure out how large an allocation is required */
218970 nByte = sizeof(SessionChange);
218971 for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
218972 sqlite3_value *p = 0;
218973 if( op!=SQLITE_INSERT ){
218974 TESTONLY(int trc = ) pSession->hook.xOld(pSession->hook.pCtx, i, &p);
218975 assert( trc==SQLITE_OK );
218976 }else if( pTab->abPK[i] ){
@@ -218185,10 +218981,13 @@
218981 /* This may fail if SQLite value p contains a utf-16 string that must
218982 ** be converted to utf-8 and an OOM error occurs while doing so. */
218983 rc = sessionSerializeValue(0, p, &nByte);
218984 if( rc!=SQLITE_OK ) goto error_out;
218985 }
218986 if( pTab->bRowid ){
218987 nByte += 9; /* Size of rowid field - an integer */
218988 }
218989
218990 /* Allocate the change object */
218991 pC = (SessionChange *)sessionMalloc64(pSession, nByte);
218992 if( !pC ){
218993 rc = SQLITE_NOMEM;
@@ -218201,11 +219000,16 @@
219000 /* Populate the change object. None of the preupdate_old(),
219001 ** preupdate_new() or SerializeValue() calls below may fail as all
219002 ** required values and encodings have already been cached in memory.
219003 ** It is not possible for an OOM to occur in this block. */
219004 nByte = 0;
219005 if( pTab->bRowid ){
219006 pC->aRecord[0] = SQLITE_INTEGER;
219007 sessionPutI64(&pC->aRecord[1], iRowid);
219008 nByte = 9;
219009 }
219010 for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
219011 sqlite3_value *p = 0;
219012 if( op!=SQLITE_INSERT ){
219013 pSession->hook.xOld(pSession->hook.pCtx, i, &p);
219014 }else if( pTab->abPK[i] ){
219015 pSession->hook.xNew(pSession->hook.pCtx, i, &p);
@@ -218316,13 +219120,14 @@
219120 if( sqlite3_strnicmp(zDb, pSession->zDb, nDb+1) ) continue;
219121
219122 pSession->rc = sessionFindTable(pSession, zName, &pTab);
219123 if( pTab ){
219124 assert( pSession->rc==SQLITE_OK );
219125 assert( op==SQLITE_UPDATE || iKey1==iKey2 );
219126 sessionPreupdateOneChange(op, iKey1, pSession, pTab);
219127 if( op==SQLITE_UPDATE ){
219128 sessionPreupdateOneChange(SQLITE_INSERT, iKey2, pSession, pTab);
219129 }
219130 }
219131 }
219132 }
219133
@@ -218357,29 +219162,30 @@
219162 }
219163
219164 typedef struct SessionDiffCtx SessionDiffCtx;
219165 struct SessionDiffCtx {
219166 sqlite3_stmt *pStmt;
219167 int bRowid;
219168 int nOldOff;
219169 };
219170
219171 /*
219172 ** The diff hook implementations.
219173 */
219174 static int sessionDiffOld(void *pCtx, int iVal, sqlite3_value **ppVal){
219175 SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
219176 *ppVal = sqlite3_column_value(p->pStmt, iVal+p->nOldOff+p->bRowid);
219177 return SQLITE_OK;
219178 }
219179 static int sessionDiffNew(void *pCtx, int iVal, sqlite3_value **ppVal){
219180 SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
219181 *ppVal = sqlite3_column_value(p->pStmt, iVal+p->bRowid);
219182 return SQLITE_OK;
219183 }
219184 static int sessionDiffCount(void *pCtx){
219185 SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
219186 return (p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt)) - p->bRowid;
219187 }
219188 static int sessionDiffDepth(void *pCtx){
219189 (void)pCtx;
219190 return 0;
219191 }
@@ -218454,18 +219260,20 @@
219260 }
219261
219262 static char *sessionSelectFindNew(
219263 const char *zDb1, /* Pick rows in this db only */
219264 const char *zDb2, /* But not in this one */
219265 int bRowid,
219266 const char *zTbl, /* Table name */
219267 const char *zExpr
219268 ){
219269 const char *zSel = (bRowid ? SESSIONS_ROWID ", *" : "*");
219270 char *zRet = sqlite3_mprintf(
219271 "SELECT %s FROM \"%w\".\"%w\" WHERE NOT EXISTS ("
219272 " SELECT 1 FROM \"%w\".\"%w\" WHERE %s"
219273 ")",
219274 zSel, zDb1, zTbl, zDb2, zTbl, zExpr
219275 );
219276 return zRet;
219277 }
219278
219279 static int sessionDiffFindNew(
@@ -218475,11 +219283,13 @@
219283 const char *zDb1,
219284 const char *zDb2,
219285 char *zExpr
219286 ){
219287 int rc = SQLITE_OK;
219288 char *zStmt = sessionSelectFindNew(
219289 zDb1, zDb2, pTab->bRowid, pTab->zName, zExpr
219290 );
219291
219292 if( zStmt==0 ){
219293 rc = SQLITE_NOMEM;
219294 }else{
219295 sqlite3_stmt *pStmt;
@@ -218486,20 +219296,43 @@
219296 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
219297 if( rc==SQLITE_OK ){
219298 SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
219299 pDiffCtx->pStmt = pStmt;
219300 pDiffCtx->nOldOff = 0;
219301 pDiffCtx->bRowid = pTab->bRowid;
219302 while( SQLITE_ROW==sqlite3_step(pStmt) ){
219303 i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
219304 sessionPreupdateOneChange(op, iRowid, pSession, pTab);
219305 }
219306 rc = sqlite3_finalize(pStmt);
219307 }
219308 sqlite3_free(zStmt);
219309 }
219310
219311 return rc;
219312 }
219313
219314 /*
219315 ** Return a comma-separated list of the fully-qualified (with both database
219316 ** and table name) column names from table pTab. e.g.
219317 **
219318 ** "main"."t1"."a", "main"."t1"."b", "main"."t1"."c"
219319 */
219320 static char *sessionAllCols(
219321 const char *zDb,
219322 SessionTable *pTab
219323 ){
219324 int ii;
219325 char *zRet = 0;
219326 for(ii=0; ii<pTab->nCol; ii++){
219327 zRet = sqlite3_mprintf("%z%s\"%w\".\"%w\".\"%w\"",
219328 zRet, (zRet ? ", " : ""), zDb, pTab->zName, pTab->azCol[ii]
219329 );
219330 if( !zRet ) break;
219331 }
219332 return zRet;
219333 }
219334
219335 static int sessionDiffFindModified(
219336 sqlite3_session *pSession,
219337 SessionTable *pTab,
219338 const char *zFrom,
@@ -218511,15 +219344,17 @@
219344 pSession->zDb, zFrom, pTab->zName, pTab->azCol, pTab->abPK
219345 );
219346 if( zExpr2==0 ){
219347 rc = SQLITE_NOMEM;
219348 }else{
219349 char *z1 = sessionAllCols(pSession->zDb, pTab);
219350 char *z2 = sessionAllCols(zFrom, pTab);
219351 char *zStmt = sqlite3_mprintf(
219352 "SELECT %s,%s FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)",
219353 z1, z2, pSession->zDb, pTab->zName, zFrom, pTab->zName, zExpr, zExpr2
219354 );
219355 if( zStmt==0 || z1==0 || z2==0 ){
219356 rc = SQLITE_NOMEM;
219357 }else{
219358 sqlite3_stmt *pStmt;
219359 rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0);
219360
@@ -218526,16 +219361,19 @@
219361 if( rc==SQLITE_OK ){
219362 SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
219363 pDiffCtx->pStmt = pStmt;
219364 pDiffCtx->nOldOff = pTab->nCol;
219365 while( SQLITE_ROW==sqlite3_step(pStmt) ){
219366 i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
219367 sessionPreupdateOneChange(SQLITE_UPDATE, iRowid, pSession, pTab);
219368 }
219369 rc = sqlite3_finalize(pStmt);
219370 }
 
219371 }
219372 sqlite3_free(zStmt);
219373 sqlite3_free(z1);
219374 sqlite3_free(z2);
219375 }
219376
219377 return rc;
219378 }
219379
@@ -218570,13 +219408,16 @@
219408 /* Check the table schemas match */
219409 if( rc==SQLITE_OK ){
219410 int bHasPk = 0;
219411 int bMismatch = 0;
219412 int nCol; /* Columns in zFrom.zTbl */
219413 int bRowid = 0;
219414 u8 *abPK;
219415 const char **azCol = 0;
219416 rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, &abPK,
219417 pSession->bImplicitPK ? &bRowid : 0
219418 );
219419 if( rc==SQLITE_OK ){
219420 if( pTo->nCol!=nCol ){
219421 bMismatch = 1;
219422 }else{
219423 int i;
@@ -219223,19 +220064,20 @@
220064 static int sessionSelectStmt(
220065 sqlite3 *db, /* Database handle */
220066 int bIgnoreNoop,
220067 const char *zDb, /* Database name */
220068 const char *zTab, /* Table name */
220069 int bRowid,
220070 int nCol, /* Number of columns in table */
220071 const char **azCol, /* Names of table columns */
220072 u8 *abPK, /* PRIMARY KEY array */
220073 sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
220074 ){
220075 int rc = SQLITE_OK;
220076 char *zSql = 0;
220077 const char *zSep = "";
220078 const char *zCols = bRowid ? SESSIONS_ROWID ", *" : "*";
220079 int nSql = -1;
220080 int i;
220081
220082 SessionBuffer nooptest = {0, 0, 0};
220083 SessionBuffer pkfield = {0, 0, 0};
@@ -219250,11 +220092,10 @@
220092 "?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc
220093 );
220094 zCols = "tbl, ?2, stat";
220095 }else{
220096 for(i=0; i<nCol; i++){
 
220097 if( abPK[i] ){
220098 sessionAppendStr(&pkfield, zSep, &rc);
220099 sessionAppendStr(&pkvar, zSep, &rc);
220100 zSep = ", ";
220101 sessionAppendIdent(&pkfield, azCol[i], &rc);
@@ -219457,24 +220298,32 @@
220298 const char **azCol = 0; /* Table columns */
220299 int i; /* Used to iterate through hash buckets */
220300 sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */
220301 int nRewind = buf.nBuf; /* Initial size of write buffer */
220302 int nNoop; /* Size of buffer after writing tbl header */
220303 int bRowid = 0;
220304
220305 /* Check the table schema is still Ok. */
220306 rc = sessionTableInfo(
220307 0, db, pSession->zDb, zName, &nCol, 0, &azCol, &abPK,
220308 (pSession->bImplicitPK ? &bRowid : 0)
220309 );
220310 if( rc==SQLITE_OK && (
220311 pTab->nCol!=nCol
220312 || pTab->bRowid!=bRowid
220313 || memcmp(abPK, pTab->abPK, nCol)
220314 )){
220315 rc = SQLITE_SCHEMA;
220316 }
220317
220318 /* Write a table header */
220319 sessionAppendTableHdr(&buf, bPatchset, pTab, &rc);
220320
220321 /* Build and compile a statement to execute: */
220322 if( rc==SQLITE_OK ){
220323 rc = sessionSelectStmt(
220324 db, 0, pSession->zDb, zName, bRowid, nCol, azCol, abPK, &pSel
220325 );
220326 }
220327
220328 nNoop = buf.nBuf;
220329 for(i=0; i<pTab->nChange && rc==SQLITE_OK; i++){
@@ -219554,12 +220403,12 @@
220403 void **ppChangeset /* OUT: Buffer containing changeset */
220404 ){
220405 int rc;
220406
220407 if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE;
220408 rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
220409 assert( 1 || rc || pnChangeset==0
220410 || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
220411 );
220412 return rc;
220413 }
220414
@@ -219671,10 +220520,23 @@
220520 }
220521 }
220522 *(int*)pArg = pSession->bEnableSize;
220523 break;
220524 }
220525
220526 case SQLITE_SESSION_OBJCONFIG_ROWID: {
220527 int iArg = *(int*)pArg;
220528 if( iArg>=0 ){
220529 if( pSession->pTable ){
220530 rc = SQLITE_MISUSE;
220531 }else{
220532 pSession->bImplicitPK = (iArg!=0);
220533 }
220534 }
220535 *(int*)pArg = pSession->bImplicitPK;
220536 break;
220537 }
220538
220539 default:
220540 rc = SQLITE_MISUSE;
220541 }
220542
@@ -220661,10 +221523,11 @@
221523 SessionBuffer constraints; /* Deferred constraints are stored here */
221524 SessionBuffer rebase; /* Rebase information (if any) here */
221525 u8 bRebaseStarted; /* If table header is already in rebase */
221526 u8 bRebase; /* True to collect rebase information */
221527 u8 bIgnoreNoop; /* True to ignore no-op conflicts */
221528 int bRowid;
221529 };
221530
221531 /* Number of prepared UPDATE statements to cache. */
221532 #define SESSION_UPDATE_CACHE_SZ 12
221533
@@ -220911,12 +221774,13 @@
221774 static int sessionSelectRow(
221775 sqlite3 *db, /* Database handle */
221776 const char *zTab, /* Table name */
221777 SessionApplyCtx *p /* Session changeset-apply context */
221778 ){
221779 /* TODO */
221780 return sessionSelectStmt(db, p->bIgnoreNoop,
221781 "main", zTab, p->bRowid, p->nCol, p->azCol, p->abPK, &p->pSelect
221782 );
221783 }
221784
221785 /*
221786 ** Formulate and prepare an INSERT statement to add a record to table zTab.
@@ -221608,10 +222472,11 @@
222472 sApply.azCol = 0;
222473 sApply.abPK = 0;
222474 sApply.bStat1 = 0;
222475 sApply.bDeferConstraints = 1;
222476 sApply.bRebaseStarted = 0;
222477 sApply.bRowid = 0;
222478 memset(&sApply.constraints, 0, sizeof(SessionBuffer));
222479
222480 /* If an xFilter() callback was specified, invoke it now. If the
222481 ** xFilter callback returns zero, skip this table. If it returns
222482 ** non-zero, proceed. */
@@ -221627,12 +222492,12 @@
222492 }else{
222493 int nMinCol = 0;
222494 int i;
222495
222496 sqlite3changeset_pk(pIter, &abPK, 0);
222497 rc = sessionTableInfo(0, db, "main", zNew,
222498 &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK, &sApply.bRowid
222499 );
222500 if( rc!=SQLITE_OK ) break;
222501 for(i=0; i<sApply.nCol; i++){
222502 if( sApply.abPK[i] ) nMinCol = i+1;
222503 }
@@ -223510,29 +224375,34 @@
224375 fts5_tokenizer *pTokApi;
224376 int bLock; /* True when table is preparing statement */
224377 int ePattern; /* FTS_PATTERN_XXX constant */
224378
224379 /* Values loaded from the %_config table */
224380 int iVersion; /* fts5 file format 'version' */
224381 int iCookie; /* Incremented when %_config is modified */
224382 int pgsz; /* Approximate page size used in %_data */
224383 int nAutomerge; /* 'automerge' setting */
224384 int nCrisisMerge; /* Maximum allowed segments per level */
224385 int nUsermerge; /* 'usermerge' setting */
224386 int nHashSize; /* Bytes of memory for in-memory hash */
224387 char *zRank; /* Name of rank function */
224388 char *zRankArgs; /* Arguments to rank function */
224389 int bSecureDelete; /* 'secure-delete' */
224390
224391 /* If non-NULL, points to sqlite3_vtab.base.zErrmsg. Often NULL. */
224392 char **pzErrmsg;
224393
224394 #ifdef SQLITE_DEBUG
224395 int bPrefixIndex; /* True to use prefix-indexes */
224396 #endif
224397 };
224398
224399 /* Current expected value of %_config table 'version' field. And
224400 ** the expected version if the 'secure-delete' option has ever been
224401 ** set on the table. */
224402 #define FTS5_CURRENT_VERSION 4
224403 #define FTS5_CURRENT_VERSION_SECUREDELETE 5
224404
224405 #define FTS5_CONTENT_NORMAL 0
224406 #define FTS5_CONTENT_NONE 1
224407 #define FTS5_CONTENT_EXTERNAL 2
224408
@@ -223694,10 +224564,11 @@
224564 /* The following are used internally by the fts5_index.c module. They are
224565 ** defined here only to make it easier to avoid clashes with the flags
224566 ** above. */
224567 #define FTS5INDEX_QUERY_SKIPEMPTY 0x0010
224568 #define FTS5INDEX_QUERY_NOOUTPUT 0x0020
224569 #define FTS5INDEX_QUERY_SKIPHASH 0x0040
224570
224571 /*
224572 ** Create/destroy an Fts5Index object.
224573 */
224574 static int sqlite3Fts5IndexOpen(Fts5Config *pConfig, int bCreate, Fts5Index**, char**);
@@ -227693,10 +228564,22 @@
228564 pConfig->zRankArgs = zRankArgs;
228565 }else if( rc==SQLITE_ERROR ){
228566 rc = SQLITE_OK;
228567 *pbBadkey = 1;
228568 }
228569 }
228570
228571 else if( 0==sqlite3_stricmp(zKey, "secure-delete") ){
228572 int bVal = -1;
228573 if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){
228574 bVal = sqlite3_value_int(pVal);
228575 }
228576 if( bVal<0 ){
228577 *pbBadkey = 1;
228578 }else{
228579 pConfig->bSecureDelete = (bVal ? 1 : 0);
228580 }
228581 }else{
228582 *pbBadkey = 1;
228583 }
228584 return rc;
228585 }
@@ -227737,19 +228620,24 @@
228620 }
228621 }
228622 rc = sqlite3_finalize(p);
228623 }
228624
228625 if( rc==SQLITE_OK
228626 && iVersion!=FTS5_CURRENT_VERSION
228627 && iVersion!=FTS5_CURRENT_VERSION_SECUREDELETE
228628 ){
228629 rc = SQLITE_ERROR;
228630 if( pConfig->pzErrmsg ){
228631 assert( 0==*pConfig->pzErrmsg );
228632 *pConfig->pzErrmsg = sqlite3_mprintf("invalid fts5 file format "
228633 "(found %d, expected %d or %d) - run 'rebuild'",
228634 iVersion, FTS5_CURRENT_VERSION, FTS5_CURRENT_VERSION_SECUREDELETE
228635 );
228636 }
228637 }else{
228638 pConfig->iVersion = iVersion;
228639 }
228640
228641 if( rc==SQLITE_OK ){
228642 pConfig->iCookie = iCookie;
228643 }
@@ -228163,11 +229051,11 @@
229051
229052 static int sqlite3Fts5ExprAnd(Fts5Expr **pp1, Fts5Expr *p2){
229053 Fts5Parse sParse;
229054 memset(&sParse, 0, sizeof(sParse));
229055
229056 if( *pp1 && p2 ){
229057 Fts5Expr *p1 = *pp1;
229058 int nPhrase = p1->nPhrase + p2->nPhrase;
229059
229060 p1->pRoot = sqlite3Fts5ParseNode(&sParse, FTS5_AND, p1->pRoot, p2->pRoot,0);
229061 p2->pRoot = 0;
@@ -228188,11 +229076,11 @@
229076 p1->apExprPhrase = ap;
229077 }
229078 }
229079 sqlite3_free(p2->apExprPhrase);
229080 sqlite3_free(p2);
229081 }else if( p2 ){
229082 *pp1 = p2;
229083 }
229084
229085 return sParse.rc;
229086 }
@@ -231705,10 +232593,12 @@
232593 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
232594 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
232595 sqlite3_stmt *pIdxSelect;
232596 int nRead; /* Total number of blocks read */
232597
232598 sqlite3_stmt *pDeleteFromIdx;
232599
232600 sqlite3_stmt *pDataVersion;
232601 i64 iStructVersion; /* data_version when pStruct read */
232602 Fts5Structure *pStruct; /* Current db structure (or NULL) */
232603 };
232604
@@ -231797,13 +232687,10 @@
232687 ** Current leaf page number within segment.
232688 **
232689 ** iLeafOffset:
232690 ** Byte offset within the current leaf that is the first byte of the
232691 ** position list data (one byte passed the position-list size field).
 
 
 
232692 **
232693 ** pLeaf:
232694 ** Buffer containing current leaf page data. Set to NULL at EOF.
232695 **
232696 ** iTermLeafPgno, iTermLeafOffset:
@@ -232388,10 +233275,11 @@
233275 ** Add a level to the Fts5Structure.aLevel[] array of structure object
233276 ** (*ppStruct).
233277 */
233278 static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
233279 fts5StructureMakeWritable(pRc, ppStruct);
233280 assert( (ppStruct!=0 && (*ppStruct)!=0) || (*pRc)!=SQLITE_OK );
233281 if( *pRc==SQLITE_OK ){
233282 Fts5Structure *pStruct = *ppStruct;
233283 int nLevel = pStruct->nLevel;
233284 sqlite3_int64 nByte = (
233285 sizeof(Fts5Structure) + /* Main structure */
@@ -232846,46 +233734,29 @@
233734 assert( pLvl->bEof==0 );
233735 if( iOff<=pLvl->iFirstOff ){
233736 pLvl->bEof = 1;
233737 }else{
233738 u8 *a = pLvl->pData->p;
233739
233740 pLvl->iOff = 0;
233741 fts5DlidxLvlNext(pLvl);
233742 while( 1 ){
233743 int nZero = 0;
233744 int ii = pLvl->iOff;
233745 u64 delta = 0;
233746
233747 while( a[ii]==0 ){
233748 nZero++;
233749 ii++;
233750 }
233751 ii += sqlite3Fts5GetVarint(&a[ii], &delta);
233752
233753 if( ii>=iOff ) break;
233754 pLvl->iLeafPgno += nZero+1;
233755 pLvl->iRowid += delta;
233756 pLvl->iOff = ii;
233757 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233758 }
233759
233760 return pLvl->bEof;
233761 }
233762
@@ -233077,11 +233948,11 @@
233948 static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
233949 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
233950 i64 iOff = pIter->iLeafOffset;
233951
233952 ASSERT_SZLEAF_OK(pIter->pLeaf);
233953 while( iOff>=pIter->pLeaf->szLeaf ){
233954 fts5SegIterNextPage(p, pIter);
233955 if( pIter->pLeaf==0 ){
233956 if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
233957 return;
233958 }
@@ -233176,14 +234047,16 @@
234047 if( p->rc==SQLITE_OK ){
234048 memset(pIter, 0, sizeof(*pIter));
234049 fts5SegIterSetNext(p, pIter);
234050 pIter->pSeg = pSeg;
234051 pIter->iLeafPgno = pSeg->pgnoFirst-1;
234052 do {
234053 fts5SegIterNextPage(p, pIter);
234054 }while( p->rc==SQLITE_OK && pIter->pLeaf && pIter->pLeaf->nn==4 );
234055 }
234056
234057 if( p->rc==SQLITE_OK && pIter->pLeaf ){
234058 pIter->iLeafOffset = 4;
234059 assert( pIter->pLeaf!=0 );
234060 assert_nc( pIter->pLeaf->nn>4 );
234061 assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
234062 pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
@@ -233373,11 +234246,11 @@
234246
234247 ASSERT_SZLEAF_OK(pIter->pLeaf);
234248 iOff = pIter->iLeafOffset;
234249
234250 /* Next entry is on the next page */
234251 while( pIter->pSeg && iOff>=pIter->pLeaf->szLeaf ){
234252 fts5SegIterNextPage(p, pIter);
234253 if( p->rc || pIter->pLeaf==0 ) return;
234254 pIter->iRowid = 0;
234255 iOff = 4;
234256 }
@@ -233566,11 +234439,11 @@
234439 static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
234440 Fts5DlidxIter *pDlidx = pIter->pDlidx;
234441 Fts5Data *pLast = 0;
234442 int pgnoLast = 0;
234443
234444 if( pDlidx && p->pConfig->iVersion==FTS5_CURRENT_VERSION ){
234445 int iSegid = pIter->pSeg->iSegid;
234446 pgnoLast = fts5DlidxIterPgno(pDlidx);
234447 pLast = fts5LeafRead(p, FTS5_SEGMENT_ROWID(iSegid, pgnoLast));
234448 }else{
234449 Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
@@ -234127,11 +235000,12 @@
235000 return 0;
235001 }
235002
235003 /*
235004 ** Move the seg-iter so that it points to the first rowid on page iLeafPgno.
235005 ** It is an error if leaf iLeafPgno does not exist. Unless the db is
235006 ** a 'secure-delete' db, if it contains no rowids then this is also an error.
235007 */
235008 static void fts5SegIterGotoPage(
235009 Fts5Index *p, /* FTS5 backend object */
235010 Fts5SegIter *pIter, /* Iterator to advance */
235011 int iLeafPgno
@@ -234142,25 +235016,27 @@
235016 p->rc = FTS5_CORRUPT;
235017 }else{
235018 fts5DataRelease(pIter->pNextLeaf);
235019 pIter->pNextLeaf = 0;
235020 pIter->iLeafPgno = iLeafPgno-1;
 
 
235021
235022 while( p->rc==SQLITE_OK ){
235023 int iOff;
235024 fts5SegIterNextPage(p, pIter);
235025 if( pIter->pLeaf==0 ) break;
 
235026 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
235027 if( iOff>0 ){
235028 u8 *a = pIter->pLeaf->p;
235029 int n = pIter->pLeaf->szLeaf;
235030 if( iOff<4 || iOff>=n ){
235031 p->rc = FTS5_CORRUPT;
235032 }else{
235033 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
235034 pIter->iLeafOffset = iOff;
235035 fts5SegIterLoadNPos(p, pIter);
235036 }
235037 break;
235038 }
235039 }
235040 }
235041 }
235042
@@ -234871,11 +235747,11 @@
235747 /* Allocate space for the new multi-seg-iterator. */
235748 if( p->rc==SQLITE_OK ){
235749 if( iLevel<0 ){
235750 assert( pStruct->nSegment==fts5StructureCountSegments(pStruct) );
235751 nSeg = pStruct->nSegment;
235752 nSeg += (p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH));
235753 }else{
235754 nSeg = MIN(pStruct->aLevel[iLevel].nSeg, nSegment);
235755 }
235756 }
235757 *ppOut = pNew = fts5MultiIterAlloc(p, nSeg);
@@ -234892,11 +235768,11 @@
235768
235769 /* Initialize each of the component segment iterators. */
235770 if( p->rc==SQLITE_OK ){
235771 if( iLevel<0 ){
235772 Fts5StructureLevel *pEnd = &pStruct->aLevel[pStruct->nLevel];
235773 if( p->pHash && 0==(flags & FTS5INDEX_QUERY_SKIPHASH) ){
235774 /* Add a segment iterator for the current contents of the hash table. */
235775 Fts5SegIter *pIter = &pNew->aSeg[iIter++];
235776 fts5SegIterHashInit(p, pTerm, nTerm, flags, pIter);
235777 }
235778 for(pLvl=&pStruct->aLevel[0]; pLvl<pEnd; pLvl++){
@@ -235647,11 +236523,11 @@
236523 fts5BufferZero(&buf);
236524 fts5BufferGrow(&p->rc, &buf, pData->nn);
236525 fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
236526 fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
236527 fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
236528 fts5BufferAppendBlob(&p->rc, &buf,pData->szLeaf-iOff,&pData->p[iOff]);
236529 if( p->rc==SQLITE_OK ){
236530 /* Set the szLeaf field */
236531 fts5PutU16(&buf.p[2], (u16)buf.n);
236532 }
236533
@@ -235925,20 +236801,20 @@
236801 Fts5Index *p, /* FTS5 backend object */
236802 Fts5Structure **ppStruct /* IN/OUT: Current structure of index */
236803 ){
236804 const int nCrisis = p->pConfig->nCrisisMerge;
236805 Fts5Structure *pStruct = *ppStruct;
236806 if( pStruct && pStruct->nLevel>0 ){
236807 int iLvl = 0;
236808 while( p->rc==SQLITE_OK && pStruct->aLevel[iLvl].nSeg>=nCrisis ){
236809 fts5IndexMergeLevel(p, &pStruct, iLvl, 0);
236810 assert( p->rc!=SQLITE_OK || pStruct->nLevel>(iLvl+1) );
236811 fts5StructurePromote(p, iLvl+1, pStruct);
236812 iLvl++;
236813 }
236814 *ppStruct = pStruct;
236815 }
236816 }
236817
236818 static int fts5IndexReturn(Fts5Index *p){
236819 int rc = p->rc;
236820 p->rc = SQLITE_OK;
@@ -235967,10 +236843,417 @@
236843 ret += i;
236844 }
236845 }
236846 return ret;
236847 }
236848
236849 /*
236850 ** Execute the SQL statement:
236851 **
236852 ** DELETE FROM %_idx WHERE (segid, (pgno/2)) = ($iSegid, $iPgno);
236853 **
236854 ** This is used when a secure-delete operation removes the last term
236855 ** from a segment leaf page. In that case the %_idx entry is removed
236856 ** too. This is done to ensure that if all instances of a token are
236857 ** removed from an fts5 database in secure-delete mode, no trace of
236858 ** the token itself remains in the database.
236859 */
236860 static void fts5SecureDeleteIdxEntry(
236861 Fts5Index *p, /* FTS5 backend object */
236862 int iSegid, /* Id of segment to delete entry for */
236863 int iPgno /* Page number within segment */
236864 ){
236865 if( iPgno!=1 ){
236866 assert( p->pConfig->iVersion==FTS5_CURRENT_VERSION_SECUREDELETE );
236867 if( p->pDeleteFromIdx==0 ){
236868 fts5IndexPrepareStmt(p, &p->pDeleteFromIdx, sqlite3_mprintf(
236869 "DELETE FROM '%q'.'%q_idx' WHERE (segid, (pgno/2)) = (?1, ?2)",
236870 p->pConfig->zDb, p->pConfig->zName
236871 ));
236872 }
236873 if( p->rc==SQLITE_OK ){
236874 sqlite3_bind_int(p->pDeleteFromIdx, 1, iSegid);
236875 sqlite3_bind_int(p->pDeleteFromIdx, 2, iPgno);
236876 sqlite3_step(p->pDeleteFromIdx);
236877 p->rc = sqlite3_reset(p->pDeleteFromIdx);
236878 }
236879 }
236880 }
236881
236882 /*
236883 ** This is called when a secure-delete operation removes a position-list
236884 ** that overflows onto segment page iPgno of segment pSeg. This function
236885 ** rewrites node iPgno, and possibly one or more of its right-hand peers,
236886 ** to remove this portion of the position list.
236887 **
236888 ** Output variable (*pbLastInDoclist) is set to true if the position-list
236889 ** removed is followed by a new term or the end-of-segment, or false if
236890 ** it is followed by another rowid/position list.
236891 */
236892 static void fts5SecureDeleteOverflow(
236893 Fts5Index *p,
236894 Fts5StructureSegment *pSeg,
236895 int iPgno,
236896 int *pbLastInDoclist
236897 ){
236898 const int bDetailNone = (p->pConfig->eDetail==FTS5_DETAIL_NONE);
236899 int pgno;
236900 Fts5Data *pLeaf = 0;
236901 assert( iPgno!=1 );
236902
236903 *pbLastInDoclist = 1;
236904 for(pgno=iPgno; p->rc==SQLITE_OK && pgno<=pSeg->pgnoLast; pgno++){
236905 i64 iRowid = FTS5_SEGMENT_ROWID(pSeg->iSegid, pgno);
236906 int iNext = 0;
236907 u8 *aPg = 0;
236908
236909 pLeaf = fts5DataRead(p, iRowid);
236910 if( pLeaf==0 ) break;
236911 aPg = pLeaf->p;
236912
236913 iNext = fts5GetU16(&aPg[0]);
236914 if( iNext!=0 ){
236915 *pbLastInDoclist = 0;
236916 }
236917 if( iNext==0 && pLeaf->szLeaf!=pLeaf->nn ){
236918 fts5GetVarint32(&aPg[pLeaf->szLeaf], iNext);
236919 }
236920
236921 if( iNext==0 ){
236922 /* The page contains no terms or rowids. Replace it with an empty
236923 ** page and move on to the right-hand peer. */
236924 const u8 aEmpty[] = {0x00, 0x00, 0x00, 0x04};
236925 assert_nc( bDetailNone==0 || pLeaf->nn==4 );
236926 if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty));
236927 fts5DataRelease(pLeaf);
236928 pLeaf = 0;
236929 }else if( bDetailNone ){
236930 break;
236931 }else if( iNext>=pLeaf->szLeaf || iNext<4 ){
236932 p->rc = FTS5_CORRUPT;
236933 break;
236934 }else{
236935 int nShift = iNext - 4;
236936 int nPg;
236937
236938 int nIdx = 0;
236939 u8 *aIdx = 0;
236940
236941 /* Unless the current page footer is 0 bytes in size (in which case
236942 ** the new page footer will be as well), allocate and populate a
236943 ** buffer containing the new page footer. Set stack variables aIdx
236944 ** and nIdx accordingly. */
236945 if( pLeaf->nn>pLeaf->szLeaf ){
236946 int iFirst = 0;
236947 int i1 = pLeaf->szLeaf;
236948 int i2 = 0;
236949
236950 aIdx = sqlite3Fts5MallocZero(&p->rc, (pLeaf->nn-pLeaf->szLeaf)+2);
236951 if( aIdx==0 ) break;
236952 i1 += fts5GetVarint32(&aPg[i1], iFirst);
236953 i2 = sqlite3Fts5PutVarint(aIdx, iFirst-nShift);
236954 if( i1<pLeaf->nn ){
236955 memcpy(&aIdx[i2], &aPg[i1], pLeaf->nn-i1);
236956 i2 += (pLeaf->nn-i1);
236957 }
236958 nIdx = i2;
236959 }
236960
236961 /* Modify the contents of buffer aPg[]. Set nPg to the new size
236962 ** in bytes. The new page is always smaller than the old. */
236963 nPg = pLeaf->szLeaf - nShift;
236964 memmove(&aPg[4], &aPg[4+nShift], nPg-4);
236965 fts5PutU16(&aPg[2], nPg);
236966 if( fts5GetU16(&aPg[0]) ) fts5PutU16(&aPg[0], 4);
236967 if( nIdx>0 ){
236968 memcpy(&aPg[nPg], aIdx, nIdx);
236969 nPg += nIdx;
236970 }
236971 sqlite3_free(aIdx);
236972
236973 /* Write the new page to disk and exit the loop */
236974 assert( nPg>4 || fts5GetU16(aPg)==0 );
236975 fts5DataWrite(p, iRowid, aPg, nPg);
236976 break;
236977 }
236978 }
236979 fts5DataRelease(pLeaf);
236980 }
236981
236982 /*
236983 ** Completely remove the entry that pSeg currently points to from
236984 ** the database.
236985 */
236986 static void fts5DoSecureDelete(
236987 Fts5Index *p,
236988 Fts5SegIter *pSeg
236989 ){
236990 const int bDetailNone = (p->pConfig->eDetail==FTS5_DETAIL_NONE);
236991 int iSegid = pSeg->pSeg->iSegid;
236992 u8 *aPg = pSeg->pLeaf->p;
236993 int nPg = pSeg->pLeaf->nn;
236994 int iPgIdx = pSeg->pLeaf->szLeaf;
236995
236996 u64 iDelta = 0;
236997 u64 iNextDelta = 0;
236998 int iNextOff = 0;
236999 int iOff = 0;
237000 int nIdx = 0;
237001 u8 *aIdx = 0;
237002 int bLastInDoclist = 0;
237003 int iIdx = 0;
237004 int iStart = 0;
237005 int iKeyOff = 0;
237006 int iPrevKeyOff = 0;
237007 int iDelKeyOff = 0; /* Offset of deleted key, if any */
237008
237009 nIdx = nPg-iPgIdx;
237010 aIdx = sqlite3Fts5MallocZero(&p->rc, nIdx+16);
237011 if( p->rc ) return;
237012 memcpy(aIdx, &aPg[iPgIdx], nIdx);
237013
237014 /* At this point segment iterator pSeg points to the entry
237015 ** this function should remove from the b-tree segment.
237016 **
237017 ** In detail=full or detail=column mode, pSeg->iLeafOffset is the
237018 ** offset of the first byte in the position-list for the entry to
237019 ** remove. Immediately before this comes two varints that will also
237020 ** need to be removed:
237021 **
237022 ** + the rowid or delta rowid value for the entry, and
237023 ** + the size of the position list in bytes.
237024 **
237025 ** Or, in detail=none mode, there is a single varint prior to
237026 ** pSeg->iLeafOffset - the rowid or delta rowid value.
237027 **
237028 ** This block sets the following variables:
237029 **
237030 ** iStart:
237031 ** iDelta:
237032 */
237033 {
237034 int iSOP;
237035 if( pSeg->iLeafPgno==pSeg->iTermLeafPgno ){
237036 iStart = pSeg->iTermLeafOffset;
237037 }else{
237038 iStart = fts5GetU16(&aPg[0]);
237039 }
237040
237041 iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta);
237042 assert_nc( iSOP<=pSeg->iLeafOffset );
237043
237044 if( bDetailNone ){
237045 while( iSOP<pSeg->iLeafOffset ){
237046 if( aPg[iSOP]==0x00 ) iSOP++;
237047 if( aPg[iSOP]==0x00 ) iSOP++;
237048 iStart = iSOP;
237049 iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta);
237050 }
237051
237052 iNextOff = iSOP;
237053 if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
237054 if( iNextOff<pSeg->iEndofDoclist && aPg[iNextOff]==0x00 ) iNextOff++;
237055
237056 }else{
237057 int nPos = 0;
237058 iSOP += fts5GetVarint32(&aPg[iSOP], nPos);
237059 while( iSOP<pSeg->iLeafOffset ){
237060 iStart = iSOP + (nPos/2);
237061 iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta);
237062 iSOP += fts5GetVarint32(&aPg[iSOP], nPos);
237063 }
237064 assert_nc( iSOP==pSeg->iLeafOffset );
237065 iNextOff = pSeg->iLeafOffset + pSeg->nPos;
237066 }
237067 }
237068
237069 iOff = iStart;
237070 if( iNextOff>=iPgIdx ){
237071 int pgno = pSeg->iLeafPgno+1;
237072 fts5SecureDeleteOverflow(p, pSeg->pSeg, pgno, &bLastInDoclist);
237073 iNextOff = iPgIdx;
237074 }else{
237075 /* Set bLastInDoclist to true if the entry being removed is the last
237076 ** in its doclist. */
237077 for(iIdx=0, iKeyOff=0; iIdx<nIdx; /* no-op */){
237078 u32 iVal = 0;
237079 iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
237080 iKeyOff += iVal;
237081 if( iKeyOff==iNextOff ){
237082 bLastInDoclist = 1;
237083 }
237084 }
237085 }
237086
237087 if( fts5GetU16(&aPg[0])==iStart && (bLastInDoclist||iNextOff==iPgIdx) ){
237088 fts5PutU16(&aPg[0], 0);
237089 }
237090
237091 if( bLastInDoclist==0 ){
237092 if( iNextOff!=iPgIdx ){
237093 iNextOff += fts5GetVarint(&aPg[iNextOff], &iNextDelta);
237094 iOff += sqlite3Fts5PutVarint(&aPg[iOff], iDelta + iNextDelta);
237095 }
237096 }else if(
237097 iStart==pSeg->iTermLeafOffset && pSeg->iLeafPgno==pSeg->iTermLeafPgno
237098 ){
237099 /* The entry being removed was the only position list in its
237100 ** doclist. Therefore the term needs to be removed as well. */
237101 int iKey = 0;
237102 for(iIdx=0, iKeyOff=0; iIdx<nIdx; iKey++){
237103 u32 iVal = 0;
237104 iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
237105 if( (iKeyOff+iVal)>(u32)iStart ) break;
237106 iKeyOff += iVal;
237107 }
237108
237109 iDelKeyOff = iOff = iKeyOff;
237110 if( iNextOff!=iPgIdx ){
237111 int nPrefix = 0;
237112 int nSuffix = 0;
237113 int nPrefix2 = 0;
237114 int nSuffix2 = 0;
237115
237116 iDelKeyOff = iNextOff;
237117 iNextOff += fts5GetVarint32(&aPg[iNextOff], nPrefix2);
237118 iNextOff += fts5GetVarint32(&aPg[iNextOff], nSuffix2);
237119
237120 if( iKey!=1 ){
237121 iKeyOff += fts5GetVarint32(&aPg[iKeyOff], nPrefix);
237122 }
237123 iKeyOff += fts5GetVarint32(&aPg[iKeyOff], nSuffix);
237124
237125 nPrefix = MIN(nPrefix, nPrefix2);
237126 nSuffix = (nPrefix2 + nSuffix2) - nPrefix;
237127
237128 if( (iKeyOff+nSuffix)>iPgIdx || (iNextOff+nSuffix2)>iPgIdx ){
237129 p->rc = FTS5_CORRUPT;
237130 }else{
237131 if( iKey!=1 ){
237132 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
237133 }
237134 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
237135 if( nPrefix2>nPrefix ){
237136 memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
237137 iOff += (nPrefix2-nPrefix);
237138 }
237139 memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
237140 iOff += nSuffix2;
237141 iNextOff += nSuffix2;
237142 }
237143 }
237144 }else if( iStart==4 ){
237145 int iPgno;
237146
237147 assert_nc( pSeg->iLeafPgno>pSeg->iTermLeafPgno );
237148 /* The entry being removed may be the only position list in
237149 ** its doclist. */
237150 for(iPgno=pSeg->iLeafPgno-1; iPgno>pSeg->iTermLeafPgno; iPgno-- ){
237151 Fts5Data *pPg = fts5DataRead(p, FTS5_SEGMENT_ROWID(iSegid, iPgno));
237152 int bEmpty = (pPg && pPg->nn==4);
237153 fts5DataRelease(pPg);
237154 if( bEmpty==0 ) break;
237155 }
237156
237157 if( iPgno==pSeg->iTermLeafPgno ){
237158 i64 iId = FTS5_SEGMENT_ROWID(iSegid, pSeg->iTermLeafPgno);
237159 Fts5Data *pTerm = fts5DataRead(p, iId);
237160 if( pTerm && pTerm->szLeaf==pSeg->iTermLeafOffset ){
237161 u8 *aTermIdx = &pTerm->p[pTerm->szLeaf];
237162 int nTermIdx = pTerm->nn - pTerm->szLeaf;
237163 int iTermIdx = 0;
237164 int iTermOff = 0;
237165
237166 while( 1 ){
237167 u32 iVal = 0;
237168 int nByte = fts5GetVarint32(&aTermIdx[iTermIdx], iVal);
237169 iTermOff += iVal;
237170 if( (iTermIdx+nByte)>=nTermIdx ) break;
237171 iTermIdx += nByte;
237172 }
237173 nTermIdx = iTermIdx;
237174
237175 memmove(&pTerm->p[iTermOff], &pTerm->p[pTerm->szLeaf], nTermIdx);
237176 fts5PutU16(&pTerm->p[2], iTermOff);
237177
237178 fts5DataWrite(p, iId, pTerm->p, iTermOff+nTermIdx);
237179 if( nTermIdx==0 ){
237180 fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iTermLeafPgno);
237181 }
237182 }
237183 fts5DataRelease(pTerm);
237184 }
237185 }
237186
237187 if( p->rc==SQLITE_OK ){
237188 const int nMove = nPg - iNextOff;
237189 int nShift = 0;
237190
237191 memmove(&aPg[iOff], &aPg[iNextOff], nMove);
237192 iPgIdx -= (iNextOff - iOff);
237193 nPg = iPgIdx;
237194 fts5PutU16(&aPg[2], iPgIdx);
237195
237196 nShift = iNextOff - iOff;
237197 for(iIdx=0, iKeyOff=0, iPrevKeyOff=0; iIdx<nIdx; /* no-op */){
237198 u32 iVal = 0;
237199 iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
237200 iKeyOff += iVal;
237201 if( iKeyOff!=iDelKeyOff ){
237202 if( iKeyOff>iOff ){
237203 iKeyOff -= nShift;
237204 nShift = 0;
237205 }
237206 nPg += sqlite3Fts5PutVarint(&aPg[nPg], iKeyOff - iPrevKeyOff);
237207 iPrevKeyOff = iKeyOff;
237208 }
237209 }
237210
237211 if( iPgIdx==nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
237212 fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iLeafPgno);
237213 }
237214
237215 assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
237216 fts5DataWrite(p, FTS5_SEGMENT_ROWID(iSegid,pSeg->iLeafPgno), aPg,nPg);
237217 }
237218 sqlite3_free(aIdx);
237219 }
237220
237221 /*
237222 ** This is called as part of flushing a delete to disk in 'secure-delete'
237223 ** mode. It edits the segments within the database described by argument
237224 ** pStruct to remove the entries for term zTerm, rowid iRowid.
237225 */
237226 static void fts5FlushSecureDelete(
237227 Fts5Index *p,
237228 Fts5Structure *pStruct,
237229 const char *zTerm,
237230 i64 iRowid
237231 ){
237232 const int f = FTS5INDEX_QUERY_SKIPHASH;
237233 int nTerm = (int)strlen(zTerm);
237234 Fts5Iter *pIter = 0; /* Used to find term instance */
237235
237236 fts5MultiIterNew(p, pStruct, f, 0, (const u8*)zTerm, nTerm, -1, 0, &pIter);
237237 if( fts5MultiIterEof(p, pIter)==0 ){
237238 i64 iThis = fts5MultiIterRowid(pIter);
237239 if( iThis<iRowid ){
237240 fts5MultiIterNextFrom(p, pIter, iRowid);
237241 }
237242
237243 if( p->rc==SQLITE_OK
237244 && fts5MultiIterEof(p, pIter)==0
237245 && iRowid==fts5MultiIterRowid(pIter)
237246 ){
237247 Fts5SegIter *pSeg = &pIter->aSeg[pIter->aFirst[1].iFirst];
237248 fts5DoSecureDelete(p, pSeg);
237249 }
237250 }
237251
237252 fts5MultiIterFree(pIter);
237253 }
237254
237255
237256 /*
237257 ** Flush the contents of in-memory hash table iHash to a new level-0
237258 ** segment on disk. Also update the corresponding structure record.
237259 **
@@ -235990,10 +237273,11 @@
237273 fts5StructureInvalidate(p);
237274
237275 if( iSegid ){
237276 const int pgsz = p->pConfig->pgsz;
237277 int eDetail = p->pConfig->eDetail;
237278 int bSecureDelete = p->pConfig->bSecureDelete;
237279 Fts5StructureSegment *pSeg; /* New segment within pStruct */
237280 Fts5Buffer *pBuf; /* Buffer in which to assemble leaf page */
237281 Fts5Buffer *pPgidx; /* Buffer in which to assemble pgidx */
237282
237283 Fts5SegWriter writer;
@@ -236012,44 +237296,81 @@
237296 if( p->rc==SQLITE_OK ){
237297 p->rc = sqlite3Fts5HashScanInit(pHash, 0, 0);
237298 }
237299 while( p->rc==SQLITE_OK && 0==sqlite3Fts5HashScanEof(pHash) ){
237300 const char *zTerm; /* Buffer containing term */
237301 int nTerm; /* Size of zTerm in bytes */
237302 const u8 *pDoclist; /* Pointer to doclist for this term */
237303 int nDoclist; /* Size of doclist in bytes */
237304
237305 /* Get the term and doclist for this entry. */
237306 sqlite3Fts5HashScanEntry(pHash, &zTerm, &pDoclist, &nDoclist);
237307 nTerm = (int)strlen(zTerm);
237308 if( bSecureDelete==0 ){
237309 fts5WriteAppendTerm(p, &writer, nTerm, (const u8*)zTerm);
237310 if( p->rc!=SQLITE_OK ) break;
237311 assert( writer.bFirstRowidInPage==0 );
237312 }
237313
237314 if( !bSecureDelete && pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){
 
237315 /* The entire doclist will fit on the current leaf. */
237316 fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist);
237317 }else{
237318 int bTermWritten = !bSecureDelete;
237319 i64 iRowid = 0;
237320 i64 iPrev = 0;
237321 int iOff = 0;
237322
237323 /* The entire doclist will not fit on this leaf. The following
237324 ** loop iterates through the poslists that make up the current
237325 ** doclist. */
237326 while( p->rc==SQLITE_OK && iOff<nDoclist ){
237327 u64 iDelta = 0;
237328 iOff += fts5GetVarint(&pDoclist[iOff], &iDelta);
237329 iRowid += iDelta;
237330
237331 /* If in secure delete mode, and if this entry in the poslist is
237332 ** in fact a delete, then edit the existing segments directly
237333 ** using fts5FlushSecureDelete(). */
237334 if( bSecureDelete ){
237335 if( eDetail==FTS5_DETAIL_NONE ){
237336 if( iOff<nDoclist && pDoclist[iOff]==0x00 ){
237337 fts5FlushSecureDelete(p, pStruct, zTerm, iRowid);
237338 iOff++;
237339 if( iOff<nDoclist && pDoclist[iOff]==0x00 ){
237340 iOff++;
237341 nDoclist = 0;
237342 }else{
237343 continue;
237344 }
237345 }
237346 }else if( (pDoclist[iOff] & 0x01) ){
237347 fts5FlushSecureDelete(p, pStruct, zTerm, iRowid);
237348 if( p->rc!=SQLITE_OK || pDoclist[iOff]==0x01 ){
237349 iOff++;
237350 continue;
237351 }
237352 }
237353 }
237354
237355 if( p->rc==SQLITE_OK && bTermWritten==0 ){
237356 fts5WriteAppendTerm(p, &writer, nTerm, (const u8*)zTerm);
237357 bTermWritten = 1;
237358 assert( p->rc!=SQLITE_OK || writer.bFirstRowidInPage==0 );
237359 }
237360
237361 if( writer.bFirstRowidInPage ){
237362 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
237363 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
237364 writer.bFirstRowidInPage = 0;
237365 fts5WriteDlidxAppend(p, &writer, iRowid);
 
237366 }else{
237367 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid-iPrev);
237368 }
237369 if( p->rc!=SQLITE_OK ) break;
237370 assert( pBuf->n<=pBuf->nSpace );
237371 iPrev = iRowid;
237372
237373 if( eDetail==FTS5_DETAIL_NONE ){
237374 if( iOff<nDoclist && pDoclist[iOff]==0 ){
237375 pBuf->p[pBuf->n++] = 0;
237376 iOff++;
@@ -236104,24 +237425,27 @@
237425 if( p->rc==SQLITE_OK ) sqlite3Fts5HashScanNext(pHash);
237426 }
237427 sqlite3Fts5HashClear(pHash);
237428 fts5WriteFinish(p, &writer, &pgnoLast);
237429
237430 assert( p->rc!=SQLITE_OK || bSecureDelete || pgnoLast>0 );
237431 if( pgnoLast>0 ){
237432 /* Update the Fts5Structure. It is written back to the database by the
237433 ** fts5StructureRelease() call below. */
237434 if( pStruct->nLevel==0 ){
237435 fts5StructureAddLevel(&p->rc, &pStruct);
237436 }
237437 fts5StructureExtendLevel(&p->rc, pStruct, 0, 1, 0);
237438 if( p->rc==SQLITE_OK ){
237439 pSeg = &pStruct->aLevel[0].aSeg[ pStruct->aLevel[0].nSeg++ ];
237440 pSeg->iSegid = iSegid;
237441 pSeg->pgnoFirst = 1;
237442 pSeg->pgnoLast = pgnoLast;
237443 pStruct->nSegment++;
237444 }
237445 fts5StructurePromote(p, 0, pStruct);
237446 }
237447 }
237448
237449 fts5IndexAutomerge(p, &pStruct, pgnoLast);
237450 fts5IndexCrisismerge(p, &pStruct);
237451 fts5StructureWrite(p, pStruct);
@@ -236858,10 +238182,11 @@
238182 sqlite3_finalize(p->pDeleter);
238183 sqlite3_finalize(p->pIdxWriter);
238184 sqlite3_finalize(p->pIdxDeleter);
238185 sqlite3_finalize(p->pIdxSelect);
238186 sqlite3_finalize(p->pDataVersion);
238187 sqlite3_finalize(p->pDeleteFromIdx);
238188 sqlite3Fts5HashFree(p->pHash);
238189 sqlite3_free(p->zDataTbl);
238190 sqlite3_free(p);
238191 }
238192 return rc;
@@ -237488,10 +238813,11 @@
238813 static void fts5IndexIntegrityCheckSegment(
238814 Fts5Index *p, /* FTS5 backend object */
238815 Fts5StructureSegment *pSeg /* Segment to check internal consistency */
238816 ){
238817 Fts5Config *pConfig = p->pConfig;
238818 int bSecureDelete = (pConfig->iVersion==FTS5_CURRENT_VERSION_SECUREDELETE);
238819 sqlite3_stmt *pStmt = 0;
238820 int rc2;
238821 int iIdxPrevLeaf = pSeg->pgnoFirst-1;
238822 int iDlidxPrevLeaf = pSeg->pgnoLast;
238823
@@ -237523,11 +238849,23 @@
238849 /* Check that the leaf contains at least one term, and that it is equal
238850 ** to or larger than the split-key in zIdxTerm. Also check that if there
238851 ** is also a rowid pointer within the leaf page header, it points to a
238852 ** location before the term. */
238853 if( pLeaf->nn<=pLeaf->szLeaf ){
238854
238855 if( nIdxTerm==0
238856 && pConfig->iVersion==FTS5_CURRENT_VERSION_SECUREDELETE
238857 && pLeaf->nn==pLeaf->szLeaf
238858 && pLeaf->nn==4
238859 ){
238860 /* special case - the very first page in a segment keeps its %_idx
238861 ** entry even if all the terms are removed from it by secure-delete
238862 ** operations. */
238863 }else{
238864 p->rc = FTS5_CORRUPT;
238865 }
238866
238867 }else{
238868 int iOff; /* Offset of first term on leaf */
238869 int iRowidOff; /* Offset of first rowid on leaf */
238870 int nTerm; /* Size of term on leaf in bytes */
238871 int res; /* Comparison of term and split-key */
@@ -237587,13 +238925,16 @@
238925 i64 iRowid;
238926 int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
238927 ASSERT_SZLEAF_OK(pLeaf);
238928 if( iRowidOff>=pLeaf->szLeaf ){
238929 p->rc = FTS5_CORRUPT;
238930 }else if( bSecureDelete==0 || iRowidOff>0 ){
238931 i64 iDlRowid = fts5DlidxIterRowid(pDlidx);
238932 fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
238933 if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
238934 p->rc = FTS5_CORRUPT;
238935 }
238936 }
238937 fts5DataRelease(pLeaf);
238938 }
238939 }
238940
@@ -239851,10 +241192,12 @@
241192 ){
241193 Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
241194 Fts5Config *pConfig = pTab->p.pConfig;
241195 int eType0; /* value_type() of apVal[0] */
241196 int rc = SQLITE_OK; /* Return code */
241197 int bUpdateOrDelete = 0;
241198
241199
241200 /* A transaction must be open when this is called. */
241201 assert( pTab->ts.eState==1 || pTab->ts.eState==2 );
241202
241203 assert( pVtab->zErrMsg==0 );
@@ -239861,10 +241204,15 @@
241204 assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
241205 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER
241206 || sqlite3_value_type(apVal[0])==SQLITE_NULL
241207 );
241208 assert( pTab->p.pConfig->pzErrmsg==0 );
241209 if( pConfig->pgsz==0 ){
241210 rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
241211 if( rc!=SQLITE_OK ) return rc;
241212 }
241213
241214 pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
241215
241216 /* Put any active cursors into REQUIRE_SEEK state. */
241217 fts5TripCursors(pTab);
241218
@@ -239913,10 +241261,11 @@
241261
241262 /* DELETE */
241263 else if( nArg==1 ){
241264 i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */
241265 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0);
241266 bUpdateOrDelete = 1;
241267 }
241268
241269 /* INSERT or UPDATE */
241270 else{
241271 int eType1 = sqlite3_value_numeric_type(apVal[1]);
@@ -239928,10 +241277,11 @@
241277 else if( eType0!=SQLITE_INTEGER ){
241278 /* If this is a REPLACE, first remove the current entry (if any) */
241279 if( eConflict==SQLITE_REPLACE && eType1==SQLITE_INTEGER ){
241280 i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */
241281 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
241282 bUpdateOrDelete = 1;
241283 }
241284 fts5StorageInsert(&rc, pTab, apVal, pRowid);
241285 }
241286
241287 /* UPDATE */
@@ -239956,13 +241306,27 @@
241306 }
241307 }else{
241308 rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
241309 fts5StorageInsert(&rc, pTab, apVal, pRowid);
241310 }
241311 bUpdateOrDelete = 1;
241312 }
241313 }
241314 }
241315
241316 if( rc==SQLITE_OK
241317 && bUpdateOrDelete
241318 && pConfig->bSecureDelete
241319 && pConfig->iVersion==FTS5_CURRENT_VERSION
241320 ){
241321 rc = sqlite3Fts5StorageConfigValue(
241322 pTab->pStorage, "version", 0, FTS5_CURRENT_VERSION_SECUREDELETE
241323 );
241324 if( rc==SQLITE_OK ){
241325 pConfig->iVersion = FTS5_CURRENT_VERSION_SECUREDELETE;
241326 }
241327 }
241328
241329 pTab->p.pConfig->pzErrmsg = 0;
241330 return rc;
241331 }
241332
@@ -240819,10 +242183,11 @@
242183 static int fts5RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
242184 Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
242185 UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
242186 fts5CheckTransactionState(pTab, FTS5_ROLLBACKTO, iSavepoint);
242187 fts5TripCursors(pTab);
242188 pTab->p.pConfig->pgsz = 0;
242189 return sqlite3Fts5StorageRollback(pTab->pStorage);
242190 }
242191
242192 /*
242193 ** Register a new auxiliary function with global context pGlobal.
@@ -241021,11 +242386,11 @@
242386 int nArg, /* Number of args */
242387 sqlite3_value **apUnused /* Function arguments */
242388 ){
242389 assert( nArg==0 );
242390 UNUSED_PARAM2(nArg, apUnused);
242391 sqlite3_result_text(pCtx, "fts5: 2023-05-01 20:09:52 62d703d83cf8cf3358715792347c49315a82c659e475158e385746f4329a4f39", -1, SQLITE_TRANSIENT);
242392 }
242393
242394 /*
242395 ** Return true if zName is the extension on one of the shadow tables used
242396 ** by this module.
242397
+49 -24
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.42.0"
150150
#define SQLITE_VERSION_NUMBER 3042000
151
-#define SQLITE_SOURCE_ID "2023-04-10 18:44:00 4c5a3c5fb351cc1c2ce16c33314ce19c53531f09263f87456283d9d756002f9d"
151
+#define SQLITE_SOURCE_ID "2023-05-01 20:42:15 342af5b4fa0bd7c699e5497161db13d0cf795c7a5875ae30d666122e518f213b"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -2396,29 +2396,29 @@
23962396
** additional information. This feature can also be turned on and off
23972397
** using the [PRAGMA legacy_alter_table] statement.
23982398
** </dd>
23992399
**
24002400
** [[SQLITE_DBCONFIG_DQS_DML]]
2401
-** <dt>SQLITE_DBCONFIG_DQS_DML</td>
2401
+** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
24022402
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
24032403
** the legacy [double-quoted string literal] misfeature for DML statements
24042404
** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
24052405
** default value of this setting is determined by the [-DSQLITE_DQS]
24062406
** compile-time option.
24072407
** </dd>
24082408
**
24092409
** [[SQLITE_DBCONFIG_DQS_DDL]]
2410
-** <dt>SQLITE_DBCONFIG_DQS_DDL</td>
2410
+** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
24112411
** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
24122412
** the legacy [double-quoted string literal] misfeature for DDL statements,
24132413
** such as CREATE TABLE and CREATE INDEX. The
24142414
** default value of this setting is determined by the [-DSQLITE_DQS]
24152415
** compile-time option.
24162416
** </dd>
24172417
**
24182418
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2419
-** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2419
+** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
24202420
** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
24212421
** assume that database schemas are untainted by malicious content.
24222422
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
24232423
** takes additional defensive steps to protect the application from harm
24242424
** including:
@@ -2434,20 +2434,20 @@
24342434
** all applications are advised to turn it off if possible. This setting
24352435
** can also be controlled using the [PRAGMA trusted_schema] statement.
24362436
** </dd>
24372437
**
24382438
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2439
-** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
2439
+** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
24402440
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
24412441
** the legacy file format flag. When activated, this flag causes all newly
24422442
** created database file to have a schema format version number (the 4-byte
24432443
** integer found at offset 44 into the database header) of 1. This in turn
24442444
** means that the resulting database file will be readable and writable by
24452445
** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
24462446
** newly created databases are generally not understandable by SQLite versions
24472447
** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2448
-** is now scarcely any need to generated database files that are compatible
2448
+** is now scarcely any need to generate database files that are compatible
24492449
** all the way back to version 3.0.0, and so this setting is of little
24502450
** practical use, but is provided so that SQLite can continue to claim the
24512451
** ability to generate new database files that are compatible with version
24522452
** 3.0.0.
24532453
** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
@@ -2456,27 +2456,39 @@
24562456
** not considered a bug since SQLite versions 3.3.0 and earlier do not support
24572457
** either generated columns or decending indexes.
24582458
** </dd>
24592459
**
24602460
** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2461
-** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</td>
2461
+** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
24622462
** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
24632463
** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
24642464
** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
24652465
** statistics. For statistics to be collected, the flag must be set on
24662466
** the database handle both when the SQL statement is prepared and when it
24672467
** is stepped. The flag is set (collection of statistics is enabled)
2468
-** by default.</dd>
2468
+** by default. This option takes two arguments: an integer and a pointer to
2469
+** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2470
+** leave unchanged the statement scanstatus option. If the second argument
2471
+** is not NULL, then the value of the statement scanstatus setting after
2472
+** processing the first argument is written into the integer that the second
2473
+** argument points to.
2474
+** </dd>
24692475
**
24702476
** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2471
-** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</td>
2472
-** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option change the default order
2477
+** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
2478
+** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
24732479
** in which tables and indexes are scanned so that the scans start at the end
24742480
** and work toward the beginning rather than starting at the beginning and
2475
-** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2476
-** same as setting [PRAGMA reverse_unordered_selects]. This configuration option
2477
-** is useful for application testing.</dd>
2481
+** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2482
+** same as setting [PRAGMA reverse_unordered_selects]. This option takes
2483
+** two arguments which are an integer and a pointer to an integer. The first
2484
+** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2485
+** reverse scan order flag, respectively. If the second argument is not NULL,
2486
+** then 0 or 1 is written into the integer that the second argument points to
2487
+** depending on if the reverse scan order flag is set after processing the
2488
+** first argument.
2489
+** </dd>
24782490
**
24792491
** </dl>
24802492
*/
24812493
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
24822494
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
@@ -2494,11 +2506,11 @@
24942506
#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
24952507
#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
24962508
#define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
24972509
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
24982510
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2499
-#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2511
+#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
25002512
#define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
25012513
#define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
25022514
25032515
/*
25042516
** CAPI3REF: Enable Or Disable Extended Result Codes
@@ -10800,20 +10812,24 @@
1080010812
** [sqlite3session_create()] for details.
1080110813
*/
1080210814
SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
1080310815
1080410816
/*
10805
-** CAPIREF: Conigure a Session Object
10817
+** CAPI3REF: Configure a Session Object
1080610818
** METHOD: sqlite3_session
1080710819
**
1080810820
** This method is used to configure a session object after it has been
10809
-** created. At present the only valid value for the second parameter is
10810
-** [SQLITE_SESSION_OBJCONFIG_SIZE].
10821
+** created. At present the only valid values for the second parameter are
10822
+** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].
1081110823
**
10812
-** Arguments for sqlite3session_object_config()
10824
+*/
10825
+SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10826
+
10827
+/*
10828
+** CAPI3REF: Options for sqlite3session_object_config
1081310829
**
10814
-** The following values may passed as the the 4th parameter to
10830
+** The following values may passed as the the 2nd parameter to
1081510831
** sqlite3session_object_config().
1081610832
**
1081710833
** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
1081810834
** This option is used to set, clear or query the flag that enables
1081910835
** the [sqlite3session_changeset_size()] API. Because it imposes some
@@ -10825,16 +10841,25 @@
1082510841
** variable is set to 1 if the sqlite3session_changeset_size() API is
1082610842
** enabled following the current call, or 0 otherwise.
1082710843
**
1082810844
** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
1082910845
** the first table has been attached to the session object.
10830
-*/
10831
-SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10832
-
10833
-/*
10846
+**
10847
+** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>
10848
+** This option is used to set, clear or query the flag that enables
10849
+** collection of data for tables with no explicit PRIMARY KEY.
10850
+**
10851
+** Normally, tables with no explicit PRIMARY KEY are simply ignored
10852
+** by the sessions module. However, if this flag is set, it behaves
10853
+** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted
10854
+** as their leftmost columns.
10855
+**
10856
+** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10857
+** the first table has been attached to the session object.
1083410858
*/
10835
-#define SQLITE_SESSION_OBJCONFIG_SIZE 1
10859
+#define SQLITE_SESSION_OBJCONFIG_SIZE 1
10860
+#define SQLITE_SESSION_OBJCONFIG_ROWID 2
1083610861
1083710862
/*
1083810863
** CAPI3REF: Enable Or Disable A Session Object
1083910864
** METHOD: sqlite3_session
1084010865
**
1084110866
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.42.0"
150 #define SQLITE_VERSION_NUMBER 3042000
151 #define SQLITE_SOURCE_ID "2023-04-10 18:44:00 4c5a3c5fb351cc1c2ce16c33314ce19c53531f09263f87456283d9d756002f9d"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2396,29 +2396,29 @@
2396 ** additional information. This feature can also be turned on and off
2397 ** using the [PRAGMA legacy_alter_table] statement.
2398 ** </dd>
2399 **
2400 ** [[SQLITE_DBCONFIG_DQS_DML]]
2401 ** <dt>SQLITE_DBCONFIG_DQS_DML</td>
2402 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2403 ** the legacy [double-quoted string literal] misfeature for DML statements
2404 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2405 ** default value of this setting is determined by the [-DSQLITE_DQS]
2406 ** compile-time option.
2407 ** </dd>
2408 **
2409 ** [[SQLITE_DBCONFIG_DQS_DDL]]
2410 ** <dt>SQLITE_DBCONFIG_DQS_DDL</td>
2411 ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
2412 ** the legacy [double-quoted string literal] misfeature for DDL statements,
2413 ** such as CREATE TABLE and CREATE INDEX. The
2414 ** default value of this setting is determined by the [-DSQLITE_DQS]
2415 ** compile-time option.
2416 ** </dd>
2417 **
2418 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2419 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2420 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2421 ** assume that database schemas are untainted by malicious content.
2422 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2423 ** takes additional defensive steps to protect the application from harm
2424 ** including:
@@ -2434,20 +2434,20 @@
2434 ** all applications are advised to turn it off if possible. This setting
2435 ** can also be controlled using the [PRAGMA trusted_schema] statement.
2436 ** </dd>
2437 **
2438 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2439 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
2440 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2441 ** the legacy file format flag. When activated, this flag causes all newly
2442 ** created database file to have a schema format version number (the 4-byte
2443 ** integer found at offset 44 into the database header) of 1. This in turn
2444 ** means that the resulting database file will be readable and writable by
2445 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2446 ** newly created databases are generally not understandable by SQLite versions
2447 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2448 ** is now scarcely any need to generated database files that are compatible
2449 ** all the way back to version 3.0.0, and so this setting is of little
2450 ** practical use, but is provided so that SQLite can continue to claim the
2451 ** ability to generate new database files that are compatible with version
2452 ** 3.0.0.
2453 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
@@ -2456,27 +2456,39 @@
2456 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2457 ** either generated columns or decending indexes.
2458 ** </dd>
2459 **
2460 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2461 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</td>
2462 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
2463 ** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
2464 ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2465 ** statistics. For statistics to be collected, the flag must be set on
2466 ** the database handle both when the SQL statement is prepared and when it
2467 ** is stepped. The flag is set (collection of statistics is enabled)
2468 ** by default.</dd>
 
 
 
 
 
 
2469 **
2470 ** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2471 ** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</td>
2472 ** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option change the default order
2473 ** in which tables and indexes are scanned so that the scans start at the end
2474 ** and work toward the beginning rather than starting at the beginning and
2475 ** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2476 ** same as setting [PRAGMA reverse_unordered_selects]. This configuration option
2477 ** is useful for application testing.</dd>
 
 
 
 
 
 
2478 **
2479 ** </dl>
2480 */
2481 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2482 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
@@ -2494,11 +2506,11 @@
2494 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
2495 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
2496 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
2497 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
2498 #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2499 #define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2500 #define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
2501 #define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
2502
2503 /*
2504 ** CAPI3REF: Enable Or Disable Extended Result Codes
@@ -10800,20 +10812,24 @@
10800 ** [sqlite3session_create()] for details.
10801 */
10802 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
10803
10804 /*
10805 ** CAPIREF: Conigure a Session Object
10806 ** METHOD: sqlite3_session
10807 **
10808 ** This method is used to configure a session object after it has been
10809 ** created. At present the only valid value for the second parameter is
10810 ** [SQLITE_SESSION_OBJCONFIG_SIZE].
10811 **
10812 ** Arguments for sqlite3session_object_config()
 
 
 
 
10813 **
10814 ** The following values may passed as the the 4th parameter to
10815 ** sqlite3session_object_config().
10816 **
10817 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
10818 ** This option is used to set, clear or query the flag that enables
10819 ** the [sqlite3session_changeset_size()] API. Because it imposes some
@@ -10825,16 +10841,25 @@
10825 ** variable is set to 1 if the sqlite3session_changeset_size() API is
10826 ** enabled following the current call, or 0 otherwise.
10827 **
10828 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10829 ** the first table has been attached to the session object.
10830 */
10831 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10832
10833 /*
 
 
 
 
 
 
 
 
10834 */
10835 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
 
10836
10837 /*
10838 ** CAPI3REF: Enable Or Disable A Session Object
10839 ** METHOD: sqlite3_session
10840 **
10841
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.42.0"
150 #define SQLITE_VERSION_NUMBER 3042000
151 #define SQLITE_SOURCE_ID "2023-05-01 20:42:15 342af5b4fa0bd7c699e5497161db13d0cf795c7a5875ae30d666122e518f213b"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2396,29 +2396,29 @@
2396 ** additional information. This feature can also be turned on and off
2397 ** using the [PRAGMA legacy_alter_table] statement.
2398 ** </dd>
2399 **
2400 ** [[SQLITE_DBCONFIG_DQS_DML]]
2401 ** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
2402 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2403 ** the legacy [double-quoted string literal] misfeature for DML statements
2404 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2405 ** default value of this setting is determined by the [-DSQLITE_DQS]
2406 ** compile-time option.
2407 ** </dd>
2408 **
2409 ** [[SQLITE_DBCONFIG_DQS_DDL]]
2410 ** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
2411 ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
2412 ** the legacy [double-quoted string literal] misfeature for DDL statements,
2413 ** such as CREATE TABLE and CREATE INDEX. The
2414 ** default value of this setting is determined by the [-DSQLITE_DQS]
2415 ** compile-time option.
2416 ** </dd>
2417 **
2418 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2419 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
2420 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2421 ** assume that database schemas are untainted by malicious content.
2422 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2423 ** takes additional defensive steps to protect the application from harm
2424 ** including:
@@ -2434,20 +2434,20 @@
2434 ** all applications are advised to turn it off if possible. This setting
2435 ** can also be controlled using the [PRAGMA trusted_schema] statement.
2436 ** </dd>
2437 **
2438 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2439 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2440 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2441 ** the legacy file format flag. When activated, this flag causes all newly
2442 ** created database file to have a schema format version number (the 4-byte
2443 ** integer found at offset 44 into the database header) of 1. This in turn
2444 ** means that the resulting database file will be readable and writable by
2445 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2446 ** newly created databases are generally not understandable by SQLite versions
2447 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2448 ** is now scarcely any need to generate database files that are compatible
2449 ** all the way back to version 3.0.0, and so this setting is of little
2450 ** practical use, but is provided so that SQLite can continue to claim the
2451 ** ability to generate new database files that are compatible with version
2452 ** 3.0.0.
2453 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
@@ -2456,27 +2456,39 @@
2456 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2457 ** either generated columns or decending indexes.
2458 ** </dd>
2459 **
2460 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2461 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2462 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
2463 ** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
2464 ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2465 ** statistics. For statistics to be collected, the flag must be set on
2466 ** the database handle both when the SQL statement is prepared and when it
2467 ** is stepped. The flag is set (collection of statistics is enabled)
2468 ** by default. This option takes two arguments: an integer and a pointer to
2469 ** an integer.. The first argument is 1, 0, or -1 to enable, disable, or
2470 ** leave unchanged the statement scanstatus option. If the second argument
2471 ** is not NULL, then the value of the statement scanstatus setting after
2472 ** processing the first argument is written into the integer that the second
2473 ** argument points to.
2474 ** </dd>
2475 **
2476 ** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2477 ** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
2478 ** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
2479 ** in which tables and indexes are scanned so that the scans start at the end
2480 ** and work toward the beginning rather than starting at the beginning and
2481 ** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2482 ** same as setting [PRAGMA reverse_unordered_selects]. This option takes
2483 ** two arguments which are an integer and a pointer to an integer. The first
2484 ** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2485 ** reverse scan order flag, respectively. If the second argument is not NULL,
2486 ** then 0 or 1 is written into the integer that the second argument points to
2487 ** depending on if the reverse scan order flag is set after processing the
2488 ** first argument.
2489 ** </dd>
2490 **
2491 ** </dl>
2492 */
2493 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2494 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
@@ -2494,11 +2506,11 @@
2506 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
2507 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
2508 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
2509 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
2510 #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2511 #define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2512 #define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
2513 #define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
2514
2515 /*
2516 ** CAPI3REF: Enable Or Disable Extended Result Codes
@@ -10800,20 +10812,24 @@
10812 ** [sqlite3session_create()] for details.
10813 */
10814 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
10815
10816 /*
10817 ** CAPI3REF: Configure a Session Object
10818 ** METHOD: sqlite3_session
10819 **
10820 ** This method is used to configure a session object after it has been
10821 ** created. At present the only valid values for the second parameter are
10822 ** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].
10823 **
10824 */
10825 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10826
10827 /*
10828 ** CAPI3REF: Options for sqlite3session_object_config
10829 **
10830 ** The following values may passed as the the 2nd parameter to
10831 ** sqlite3session_object_config().
10832 **
10833 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
10834 ** This option is used to set, clear or query the flag that enables
10835 ** the [sqlite3session_changeset_size()] API. Because it imposes some
@@ -10825,16 +10841,25 @@
10841 ** variable is set to 1 if the sqlite3session_changeset_size() API is
10842 ** enabled following the current call, or 0 otherwise.
10843 **
10844 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10845 ** the first table has been attached to the session object.
10846 **
10847 ** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>
10848 ** This option is used to set, clear or query the flag that enables
10849 ** collection of data for tables with no explicit PRIMARY KEY.
10850 **
10851 ** Normally, tables with no explicit PRIMARY KEY are simply ignored
10852 ** by the sessions module. However, if this flag is set, it behaves
10853 ** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted
10854 ** as their leftmost columns.
10855 **
10856 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10857 ** the first table has been attached to the session object.
10858 */
10859 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
10860 #define SQLITE_SESSION_OBJCONFIG_ROWID 2
10861
10862 /*
10863 ** CAPI3REF: Enable Or Disable A Session Object
10864 ** METHOD: sqlite3_session
10865 **
10866

Keyboard Shortcuts

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