Fossil SCM

Update the built-in SQLite to the latest 3.22.0 alpha code.

drh 2018-01-07 21:38 UTC trunk
Commit 5b558bc76bb9fb5fbd641dc18c96b01ec1469cec2c229a00f7c8ec7098bae6b6
3 files changed +6635 -433 +3177 -2646 +33 -8
+6635 -433
--- src/shell.c
+++ src/shell.c
@@ -77,10 +77,13 @@
7777
#include <stdlib.h>
7878
#include <string.h>
7979
#include <stdio.h>
8080
#include <assert.h>
8181
#include "sqlite3.h"
82
+typedef sqlite3_int64 i64;
83
+typedef sqlite3_uint64 u64;
84
+typedef unsigned char u8;
8285
#if SQLITE_USER_AUTHENTICATION
8386
# include "sqlite3userauth.h"
8487
#endif
8588
#include <ctype.h>
8689
#include <stdarg.h>
@@ -88,13 +91,23 @@
8891
#if !defined(_WIN32) && !defined(WIN32)
8992
# include <signal.h>
9093
# if !defined(__RTP__) && !defined(_WRS_KERNEL)
9194
# include <pwd.h>
9295
# endif
96
+#endif
97
+#if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW_H)
9398
# include <unistd.h>
94
-# include <sys/types.h>
99
+# include <dirent.h>
100
+# if defined(__MINGW_H)
101
+# define DIRENT dirent
102
+# ifndef S_ISLNK
103
+# define S_ISLNK(mode) (0)
104
+# endif
105
+# endif
95106
#endif
107
+#include <sys/types.h>
108
+#include <sys/stat.h>
96109
97110
#if HAVE_READLINE
98111
# include <readline/readline.h>
99112
# include <readline/history.h>
100113
#endif
@@ -744,10 +757,75 @@
744757
upr = mid-1;
745758
}
746759
}
747760
return 0;
748761
}
762
+
763
+/*
764
+** Construct a fake object name and column list to describe the structure
765
+** of the view, virtual table, or table valued function zSchema.zName.
766
+*/
767
+static char *shellFakeSchema(
768
+ sqlite3 *db, /* The database connection containing the vtab */
769
+ const char *zSchema, /* Schema of the database holding the vtab */
770
+ const char *zName /* The name of the virtual table */
771
+){
772
+ sqlite3_stmt *pStmt = 0;
773
+ char *zSql;
774
+ ShellText s;
775
+ char cQuote;
776
+ char *zDiv = "(";
777
+ int nRow = 0;
778
+
779
+ zSql = sqlite3_mprintf("PRAGMA \"%w\".table_info=%Q;",
780
+ zSchema ? zSchema : "main", zName);
781
+ sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
782
+ sqlite3_free(zSql);
783
+ initText(&s);
784
+ if( zSchema ){
785
+ cQuote = quoteChar(zSchema);
786
+ if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0;
787
+ appendText(&s, zSchema, cQuote);
788
+ appendText(&s, ".", 0);
789
+ }
790
+ cQuote = quoteChar(zName);
791
+ appendText(&s, zName, cQuote);
792
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
793
+ const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
794
+ nRow++;
795
+ appendText(&s, zDiv, 0);
796
+ zDiv = ",";
797
+ cQuote = quoteChar(zCol);
798
+ appendText(&s, zCol, cQuote);
799
+ }
800
+ appendText(&s, ")", 0);
801
+ sqlite3_finalize(pStmt);
802
+ if( nRow==0 ){
803
+ freeText(&s);
804
+ s.z = 0;
805
+ }
806
+ return s.z;
807
+}
808
+
809
+/*
810
+** SQL function: shell_module_schema(X)
811
+**
812
+** Return a fake schema for the table-valued function or eponymous virtual
813
+** table X.
814
+*/
815
+static void shellModuleSchema(
816
+ sqlite3_context *pCtx,
817
+ int nVal,
818
+ sqlite3_value **apVal
819
+){
820
+ const char *zName = (const char*)sqlite3_value_text(apVal[0]);
821
+ char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
822
+ if( zFake ){
823
+ sqlite3_result_text(pCtx, sqlite3_mprintf("/* %z */", zFake),
824
+ -1, sqlite3_free);
825
+ }
826
+}
749827
750828
/*
751829
** SQL function: shell_add_schema(S,X)
752830
**
753831
** Add the schema name X to the CREATE statement in S and return the result.
@@ -780,24 +858,40 @@
780858
"VIRTUAL TABLE"
781859
};
782860
int i = 0;
783861
const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
784862
const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
785
- assert( nVal==2 );
863
+ const char *zName = (const char*)sqlite3_value_text(apVal[2]);
864
+ sqlite3 *db = sqlite3_context_db_handle(pCtx);
786865
if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
787866
for(i=0; i<(int)(sizeof(aPrefix)/sizeof(aPrefix[0])); i++){
788867
int n = strlen30(aPrefix[i]);
789868
if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
790
- char cQuote = quoteChar(zSchema);
791
- char *z;
792
- if( cQuote ){
793
- z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
794
- }else{
795
- z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
796
- }
797
- sqlite3_result_text(pCtx, z, -1, sqlite3_free);
798
- return;
869
+ char *z = 0;
870
+ char *zFake = 0;
871
+ if( zSchema ){
872
+ char cQuote = quoteChar(zSchema);
873
+ if( cQuote && sqlite3_stricmp(zSchema,"temp")!=0 ){
874
+ z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
875
+ }else{
876
+ z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
877
+ }
878
+ }
879
+ if( zName
880
+ && aPrefix[i][0]=='V'
881
+ && (zFake = shellFakeSchema(db, zSchema, zName))!=0
882
+ ){
883
+ if( z==0 ){
884
+ z = sqlite3_mprintf("%s\n/* %z */", zIn, zFake);
885
+ }else{
886
+ z = sqlite3_mprintf("%z\n/* %z */", z, zFake);
887
+ }
888
+ }
889
+ if( z ){
890
+ sqlite3_result_text(pCtx, z, -1, sqlite3_free);
891
+ return;
892
+ }
799893
}
800894
}
801895
}
802896
sqlite3_result_value(pCtx, apVal[0]);
803897
}
@@ -809,10 +903,208 @@
809903
** work here in the middle of this regular program.
810904
*/
811905
#define SQLITE_EXTENSION_INIT1
812906
#define SQLITE_EXTENSION_INIT2(X) (void)(X)
813907
908
+#if defined(_WIN32) && defined(_MSC_VER)
909
+/************************* Begin test_windirent.c ******************/
910
+/*
911
+** 2015 November 30
912
+**
913
+** The author disclaims copyright to this source code. In place of
914
+** a legal notice, here is a blessing:
915
+**
916
+** May you do good and not evil.
917
+** May you find forgiveness for yourself and forgive others.
918
+** May you share freely, never taking more than you give.
919
+**
920
+*************************************************************************
921
+** This file contains code to implement most of the opendir() family of
922
+** POSIX functions on Win32 using the MSVCRT.
923
+*/
924
+
925
+#if defined(_WIN32) && defined(_MSC_VER)
926
+
927
+#include "test_windirent.h"
928
+
929
+/*
930
+** Implementation of the POSIX getenv() function using the Win32 API.
931
+** This function is not thread-safe.
932
+*/
933
+const char *windirent_getenv(
934
+ const char *name
935
+){
936
+ static char value[32768]; /* Maximum length, per MSDN */
937
+ DWORD dwSize = sizeof(value) / sizeof(char); /* Size in chars */
938
+ DWORD dwRet; /* Value returned by GetEnvironmentVariableA() */
939
+
940
+ memset(value, 0, sizeof(value));
941
+ dwRet = GetEnvironmentVariableA(name, value, dwSize);
942
+ if( dwRet==0 || dwRet>dwSize ){
943
+ /*
944
+ ** The function call to GetEnvironmentVariableA() failed -OR-
945
+ ** the buffer is not large enough. Either way, return NULL.
946
+ */
947
+ return 0;
948
+ }else{
949
+ /*
950
+ ** The function call to GetEnvironmentVariableA() succeeded
951
+ ** -AND- the buffer contains the entire value.
952
+ */
953
+ return value;
954
+ }
955
+}
956
+
957
+/*
958
+** Implementation of the POSIX opendir() function using the MSVCRT.
959
+*/
960
+LPDIR opendir(
961
+ const char *dirname
962
+){
963
+ struct _finddata_t data;
964
+ LPDIR dirp = (LPDIR)sqlite3_malloc(sizeof(DIR));
965
+ SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]);
966
+
967
+ if( dirp==NULL ) return NULL;
968
+ memset(dirp, 0, sizeof(DIR));
969
+
970
+ /* TODO: Remove this if Unix-style root paths are not used. */
971
+ if( sqlite3_stricmp(dirname, "/")==0 ){
972
+ dirname = windirent_getenv("SystemDrive");
973
+ }
974
+
975
+ memset(&data, 0, sizeof(struct _finddata_t));
976
+ _snprintf(data.name, namesize, "%s\\*", dirname);
977
+ dirp->d_handle = _findfirst(data.name, &data);
978
+
979
+ if( dirp->d_handle==BAD_INTPTR_T ){
980
+ closedir(dirp);
981
+ return NULL;
982
+ }
983
+
984
+ /* TODO: Remove this block to allow hidden and/or system files. */
985
+ if( is_filtered(data) ){
986
+next:
987
+
988
+ memset(&data, 0, sizeof(struct _finddata_t));
989
+ if( _findnext(dirp->d_handle, &data)==-1 ){
990
+ closedir(dirp);
991
+ return NULL;
992
+ }
993
+
994
+ /* TODO: Remove this block to allow hidden and/or system files. */
995
+ if( is_filtered(data) ) goto next;
996
+ }
997
+
998
+ dirp->d_first.d_attributes = data.attrib;
999
+ strncpy(dirp->d_first.d_name, data.name, NAME_MAX);
1000
+ dirp->d_first.d_name[NAME_MAX] = '\0';
1001
+
1002
+ return dirp;
1003
+}
1004
+
1005
+/*
1006
+** Implementation of the POSIX readdir() function using the MSVCRT.
1007
+*/
1008
+LPDIRENT readdir(
1009
+ LPDIR dirp
1010
+){
1011
+ struct _finddata_t data;
1012
+
1013
+ if( dirp==NULL ) return NULL;
1014
+
1015
+ if( dirp->d_first.d_ino==0 ){
1016
+ dirp->d_first.d_ino++;
1017
+ dirp->d_next.d_ino++;
1018
+
1019
+ return &dirp->d_first;
1020
+ }
1021
+
1022
+next:
1023
+
1024
+ memset(&data, 0, sizeof(struct _finddata_t));
1025
+ if( _findnext(dirp->d_handle, &data)==-1 ) return NULL;
1026
+
1027
+ /* TODO: Remove this block to allow hidden and/or system files. */
1028
+ if( is_filtered(data) ) goto next;
1029
+
1030
+ dirp->d_next.d_ino++;
1031
+ dirp->d_next.d_attributes = data.attrib;
1032
+ strncpy(dirp->d_next.d_name, data.name, NAME_MAX);
1033
+ dirp->d_next.d_name[NAME_MAX] = '\0';
1034
+
1035
+ return &dirp->d_next;
1036
+}
1037
+
1038
+/*
1039
+** Implementation of the POSIX readdir_r() function using the MSVCRT.
1040
+*/
1041
+INT readdir_r(
1042
+ LPDIR dirp,
1043
+ LPDIRENT entry,
1044
+ LPDIRENT *result
1045
+){
1046
+ struct _finddata_t data;
1047
+
1048
+ if( dirp==NULL ) return EBADF;
1049
+
1050
+ if( dirp->d_first.d_ino==0 ){
1051
+ dirp->d_first.d_ino++;
1052
+ dirp->d_next.d_ino++;
1053
+
1054
+ entry->d_ino = dirp->d_first.d_ino;
1055
+ entry->d_attributes = dirp->d_first.d_attributes;
1056
+ strncpy(entry->d_name, dirp->d_first.d_name, NAME_MAX);
1057
+ entry->d_name[NAME_MAX] = '\0';
1058
+
1059
+ *result = entry;
1060
+ return 0;
1061
+ }
1062
+
1063
+next:
1064
+
1065
+ memset(&data, 0, sizeof(struct _finddata_t));
1066
+ if( _findnext(dirp->d_handle, &data)==-1 ){
1067
+ *result = NULL;
1068
+ return ENOENT;
1069
+ }
1070
+
1071
+ /* TODO: Remove this block to allow hidden and/or system files. */
1072
+ if( is_filtered(data) ) goto next;
1073
+
1074
+ entry->d_ino = (ino_t)-1; /* not available */
1075
+ entry->d_attributes = data.attrib;
1076
+ strncpy(entry->d_name, data.name, NAME_MAX);
1077
+ entry->d_name[NAME_MAX] = '\0';
1078
+
1079
+ *result = entry;
1080
+ return 0;
1081
+}
1082
+
1083
+/*
1084
+** Implementation of the POSIX closedir() function using the MSVCRT.
1085
+*/
1086
+INT closedir(
1087
+ LPDIR dirp
1088
+){
1089
+ INT result = 0;
1090
+
1091
+ if( dirp==NULL ) return EINVAL;
1092
+
1093
+ if( dirp->d_handle!=NULL_INTPTR_T && dirp->d_handle!=BAD_INTPTR_T ){
1094
+ result = _findclose(dirp->d_handle);
1095
+ }
1096
+
1097
+ sqlite3_free(dirp);
1098
+ return result;
1099
+}
1100
+
1101
+#endif /* defined(WIN32) && defined(_MSC_VER) */
1102
+
1103
+/************************* End test_windirent.c ********************/
1104
+#define dirent DIRENT
1105
+#endif
8141106
/************************* Begin ../ext/misc/shathree.c ******************/
8151107
/*
8161108
** 2017-03-08
8171109
**
8181110
** The author disclaims copyright to this source code. In place of
@@ -842,11 +1134,11 @@
8421134
*/
8431135
SQLITE_EXTENSION_INIT1
8441136
#include <assert.h>
8451137
#include <string.h>
8461138
#include <stdarg.h>
847
-typedef sqlite3_uint64 u64;
1139
+/* typedef sqlite3_uint64 u64; */
8481140
8491141
/******************************************************************************
8501142
** The Hash Engine
8511143
*/
8521144
/*
@@ -889,13 +1181,13 @@
8891181
/*
8901182
** A single step of the Keccak mixing function for a 1600-bit state
8911183
*/
8921184
static void KeccakF1600Step(SHA3Context *p){
8931185
int i;
894
- u64 B0, B1, B2, B3, B4;
895
- u64 C0, C1, C2, C3, C4;
896
- u64 D0, D1, D2, D3, D4;
1186
+ u64 b0, b1, b2, b3, b4;
1187
+ u64 c0, c1, c2, c3, c4;
1188
+ u64 d0, d1, d2, d3, d4;
8971189
static const u64 RC[] = {
8981190
0x0000000000000001ULL, 0x0000000000008082ULL,
8991191
0x800000000000808aULL, 0x8000000080008000ULL,
9001192
0x000000000000808bULL, 0x0000000080000001ULL,
9011193
0x8000000080008081ULL, 0x8000000000008009ULL,
@@ -906,305 +1198,305 @@
9061198
0x8000000000008002ULL, 0x8000000000000080ULL,
9071199
0x000000000000800aULL, 0x800000008000000aULL,
9081200
0x8000000080008081ULL, 0x8000000000008080ULL,
9091201
0x0000000080000001ULL, 0x8000000080008008ULL
9101202
};
911
-# define A00 (p->u.s[0])
912
-# define A01 (p->u.s[1])
913
-# define A02 (p->u.s[2])
914
-# define A03 (p->u.s[3])
915
-# define A04 (p->u.s[4])
916
-# define A10 (p->u.s[5])
917
-# define A11 (p->u.s[6])
918
-# define A12 (p->u.s[7])
919
-# define A13 (p->u.s[8])
920
-# define A14 (p->u.s[9])
921
-# define A20 (p->u.s[10])
922
-# define A21 (p->u.s[11])
923
-# define A22 (p->u.s[12])
924
-# define A23 (p->u.s[13])
925
-# define A24 (p->u.s[14])
926
-# define A30 (p->u.s[15])
927
-# define A31 (p->u.s[16])
928
-# define A32 (p->u.s[17])
929
-# define A33 (p->u.s[18])
930
-# define A34 (p->u.s[19])
931
-# define A40 (p->u.s[20])
932
-# define A41 (p->u.s[21])
933
-# define A42 (p->u.s[22])
934
-# define A43 (p->u.s[23])
935
-# define A44 (p->u.s[24])
1203
+# define a00 (p->u.s[0])
1204
+# define a01 (p->u.s[1])
1205
+# define a02 (p->u.s[2])
1206
+# define a03 (p->u.s[3])
1207
+# define a04 (p->u.s[4])
1208
+# define a10 (p->u.s[5])
1209
+# define a11 (p->u.s[6])
1210
+# define a12 (p->u.s[7])
1211
+# define a13 (p->u.s[8])
1212
+# define a14 (p->u.s[9])
1213
+# define a20 (p->u.s[10])
1214
+# define a21 (p->u.s[11])
1215
+# define a22 (p->u.s[12])
1216
+# define a23 (p->u.s[13])
1217
+# define a24 (p->u.s[14])
1218
+# define a30 (p->u.s[15])
1219
+# define a31 (p->u.s[16])
1220
+# define a32 (p->u.s[17])
1221
+# define a33 (p->u.s[18])
1222
+# define a34 (p->u.s[19])
1223
+# define a40 (p->u.s[20])
1224
+# define a41 (p->u.s[21])
1225
+# define a42 (p->u.s[22])
1226
+# define a43 (p->u.s[23])
1227
+# define a44 (p->u.s[24])
9361228
# define ROL64(a,x) ((a<<x)|(a>>(64-x)))
9371229
9381230
for(i=0; i<24; i+=4){
939
- C0 = A00^A10^A20^A30^A40;
940
- C1 = A01^A11^A21^A31^A41;
941
- C2 = A02^A12^A22^A32^A42;
942
- C3 = A03^A13^A23^A33^A43;
943
- C4 = A04^A14^A24^A34^A44;
944
- D0 = C4^ROL64(C1, 1);
945
- D1 = C0^ROL64(C2, 1);
946
- D2 = C1^ROL64(C3, 1);
947
- D3 = C2^ROL64(C4, 1);
948
- D4 = C3^ROL64(C0, 1);
949
-
950
- B0 = (A00^D0);
951
- B1 = ROL64((A11^D1), 44);
952
- B2 = ROL64((A22^D2), 43);
953
- B3 = ROL64((A33^D3), 21);
954
- B4 = ROL64((A44^D4), 14);
955
- A00 = B0 ^((~B1)& B2 );
956
- A00 ^= RC[i];
957
- A11 = B1 ^((~B2)& B3 );
958
- A22 = B2 ^((~B3)& B4 );
959
- A33 = B3 ^((~B4)& B0 );
960
- A44 = B4 ^((~B0)& B1 );
961
-
962
- B2 = ROL64((A20^D0), 3);
963
- B3 = ROL64((A31^D1), 45);
964
- B4 = ROL64((A42^D2), 61);
965
- B0 = ROL64((A03^D3), 28);
966
- B1 = ROL64((A14^D4), 20);
967
- A20 = B0 ^((~B1)& B2 );
968
- A31 = B1 ^((~B2)& B3 );
969
- A42 = B2 ^((~B3)& B4 );
970
- A03 = B3 ^((~B4)& B0 );
971
- A14 = B4 ^((~B0)& B1 );
972
-
973
- B4 = ROL64((A40^D0), 18);
974
- B0 = ROL64((A01^D1), 1);
975
- B1 = ROL64((A12^D2), 6);
976
- B2 = ROL64((A23^D3), 25);
977
- B3 = ROL64((A34^D4), 8);
978
- A40 = B0 ^((~B1)& B2 );
979
- A01 = B1 ^((~B2)& B3 );
980
- A12 = B2 ^((~B3)& B4 );
981
- A23 = B3 ^((~B4)& B0 );
982
- A34 = B4 ^((~B0)& B1 );
983
-
984
- B1 = ROL64((A10^D0), 36);
985
- B2 = ROL64((A21^D1), 10);
986
- B3 = ROL64((A32^D2), 15);
987
- B4 = ROL64((A43^D3), 56);
988
- B0 = ROL64((A04^D4), 27);
989
- A10 = B0 ^((~B1)& B2 );
990
- A21 = B1 ^((~B2)& B3 );
991
- A32 = B2 ^((~B3)& B4 );
992
- A43 = B3 ^((~B4)& B0 );
993
- A04 = B4 ^((~B0)& B1 );
994
-
995
- B3 = ROL64((A30^D0), 41);
996
- B4 = ROL64((A41^D1), 2);
997
- B0 = ROL64((A02^D2), 62);
998
- B1 = ROL64((A13^D3), 55);
999
- B2 = ROL64((A24^D4), 39);
1000
- A30 = B0 ^((~B1)& B2 );
1001
- A41 = B1 ^((~B2)& B3 );
1002
- A02 = B2 ^((~B3)& B4 );
1003
- A13 = B3 ^((~B4)& B0 );
1004
- A24 = B4 ^((~B0)& B1 );
1005
-
1006
- C0 = A00^A20^A40^A10^A30;
1007
- C1 = A11^A31^A01^A21^A41;
1008
- C2 = A22^A42^A12^A32^A02;
1009
- C3 = A33^A03^A23^A43^A13;
1010
- C4 = A44^A14^A34^A04^A24;
1011
- D0 = C4^ROL64(C1, 1);
1012
- D1 = C0^ROL64(C2, 1);
1013
- D2 = C1^ROL64(C3, 1);
1014
- D3 = C2^ROL64(C4, 1);
1015
- D4 = C3^ROL64(C0, 1);
1016
-
1017
- B0 = (A00^D0);
1018
- B1 = ROL64((A31^D1), 44);
1019
- B2 = ROL64((A12^D2), 43);
1020
- B3 = ROL64((A43^D3), 21);
1021
- B4 = ROL64((A24^D4), 14);
1022
- A00 = B0 ^((~B1)& B2 );
1023
- A00 ^= RC[i+1];
1024
- A31 = B1 ^((~B2)& B3 );
1025
- A12 = B2 ^((~B3)& B4 );
1026
- A43 = B3 ^((~B4)& B0 );
1027
- A24 = B4 ^((~B0)& B1 );
1028
-
1029
- B2 = ROL64((A40^D0), 3);
1030
- B3 = ROL64((A21^D1), 45);
1031
- B4 = ROL64((A02^D2), 61);
1032
- B0 = ROL64((A33^D3), 28);
1033
- B1 = ROL64((A14^D4), 20);
1034
- A40 = B0 ^((~B1)& B2 );
1035
- A21 = B1 ^((~B2)& B3 );
1036
- A02 = B2 ^((~B3)& B4 );
1037
- A33 = B3 ^((~B4)& B0 );
1038
- A14 = B4 ^((~B0)& B1 );
1039
-
1040
- B4 = ROL64((A30^D0), 18);
1041
- B0 = ROL64((A11^D1), 1);
1042
- B1 = ROL64((A42^D2), 6);
1043
- B2 = ROL64((A23^D3), 25);
1044
- B3 = ROL64((A04^D4), 8);
1045
- A30 = B0 ^((~B1)& B2 );
1046
- A11 = B1 ^((~B2)& B3 );
1047
- A42 = B2 ^((~B3)& B4 );
1048
- A23 = B3 ^((~B4)& B0 );
1049
- A04 = B4 ^((~B0)& B1 );
1050
-
1051
- B1 = ROL64((A20^D0), 36);
1052
- B2 = ROL64((A01^D1), 10);
1053
- B3 = ROL64((A32^D2), 15);
1054
- B4 = ROL64((A13^D3), 56);
1055
- B0 = ROL64((A44^D4), 27);
1056
- A20 = B0 ^((~B1)& B2 );
1057
- A01 = B1 ^((~B2)& B3 );
1058
- A32 = B2 ^((~B3)& B4 );
1059
- A13 = B3 ^((~B4)& B0 );
1060
- A44 = B4 ^((~B0)& B1 );
1061
-
1062
- B3 = ROL64((A10^D0), 41);
1063
- B4 = ROL64((A41^D1), 2);
1064
- B0 = ROL64((A22^D2), 62);
1065
- B1 = ROL64((A03^D3), 55);
1066
- B2 = ROL64((A34^D4), 39);
1067
- A10 = B0 ^((~B1)& B2 );
1068
- A41 = B1 ^((~B2)& B3 );
1069
- A22 = B2 ^((~B3)& B4 );
1070
- A03 = B3 ^((~B4)& B0 );
1071
- A34 = B4 ^((~B0)& B1 );
1072
-
1073
- C0 = A00^A40^A30^A20^A10;
1074
- C1 = A31^A21^A11^A01^A41;
1075
- C2 = A12^A02^A42^A32^A22;
1076
- C3 = A43^A33^A23^A13^A03;
1077
- C4 = A24^A14^A04^A44^A34;
1078
- D0 = C4^ROL64(C1, 1);
1079
- D1 = C0^ROL64(C2, 1);
1080
- D2 = C1^ROL64(C3, 1);
1081
- D3 = C2^ROL64(C4, 1);
1082
- D4 = C3^ROL64(C0, 1);
1083
-
1084
- B0 = (A00^D0);
1085
- B1 = ROL64((A21^D1), 44);
1086
- B2 = ROL64((A42^D2), 43);
1087
- B3 = ROL64((A13^D3), 21);
1088
- B4 = ROL64((A34^D4), 14);
1089
- A00 = B0 ^((~B1)& B2 );
1090
- A00 ^= RC[i+2];
1091
- A21 = B1 ^((~B2)& B3 );
1092
- A42 = B2 ^((~B3)& B4 );
1093
- A13 = B3 ^((~B4)& B0 );
1094
- A34 = B4 ^((~B0)& B1 );
1095
-
1096
- B2 = ROL64((A30^D0), 3);
1097
- B3 = ROL64((A01^D1), 45);
1098
- B4 = ROL64((A22^D2), 61);
1099
- B0 = ROL64((A43^D3), 28);
1100
- B1 = ROL64((A14^D4), 20);
1101
- A30 = B0 ^((~B1)& B2 );
1102
- A01 = B1 ^((~B2)& B3 );
1103
- A22 = B2 ^((~B3)& B4 );
1104
- A43 = B3 ^((~B4)& B0 );
1105
- A14 = B4 ^((~B0)& B1 );
1106
-
1107
- B4 = ROL64((A10^D0), 18);
1108
- B0 = ROL64((A31^D1), 1);
1109
- B1 = ROL64((A02^D2), 6);
1110
- B2 = ROL64((A23^D3), 25);
1111
- B3 = ROL64((A44^D4), 8);
1112
- A10 = B0 ^((~B1)& B2 );
1113
- A31 = B1 ^((~B2)& B3 );
1114
- A02 = B2 ^((~B3)& B4 );
1115
- A23 = B3 ^((~B4)& B0 );
1116
- A44 = B4 ^((~B0)& B1 );
1117
-
1118
- B1 = ROL64((A40^D0), 36);
1119
- B2 = ROL64((A11^D1), 10);
1120
- B3 = ROL64((A32^D2), 15);
1121
- B4 = ROL64((A03^D3), 56);
1122
- B0 = ROL64((A24^D4), 27);
1123
- A40 = B0 ^((~B1)& B2 );
1124
- A11 = B1 ^((~B2)& B3 );
1125
- A32 = B2 ^((~B3)& B4 );
1126
- A03 = B3 ^((~B4)& B0 );
1127
- A24 = B4 ^((~B0)& B1 );
1128
-
1129
- B3 = ROL64((A20^D0), 41);
1130
- B4 = ROL64((A41^D1), 2);
1131
- B0 = ROL64((A12^D2), 62);
1132
- B1 = ROL64((A33^D3), 55);
1133
- B2 = ROL64((A04^D4), 39);
1134
- A20 = B0 ^((~B1)& B2 );
1135
- A41 = B1 ^((~B2)& B3 );
1136
- A12 = B2 ^((~B3)& B4 );
1137
- A33 = B3 ^((~B4)& B0 );
1138
- A04 = B4 ^((~B0)& B1 );
1139
-
1140
- C0 = A00^A30^A10^A40^A20;
1141
- C1 = A21^A01^A31^A11^A41;
1142
- C2 = A42^A22^A02^A32^A12;
1143
- C3 = A13^A43^A23^A03^A33;
1144
- C4 = A34^A14^A44^A24^A04;
1145
- D0 = C4^ROL64(C1, 1);
1146
- D1 = C0^ROL64(C2, 1);
1147
- D2 = C1^ROL64(C3, 1);
1148
- D3 = C2^ROL64(C4, 1);
1149
- D4 = C3^ROL64(C0, 1);
1150
-
1151
- B0 = (A00^D0);
1152
- B1 = ROL64((A01^D1), 44);
1153
- B2 = ROL64((A02^D2), 43);
1154
- B3 = ROL64((A03^D3), 21);
1155
- B4 = ROL64((A04^D4), 14);
1156
- A00 = B0 ^((~B1)& B2 );
1157
- A00 ^= RC[i+3];
1158
- A01 = B1 ^((~B2)& B3 );
1159
- A02 = B2 ^((~B3)& B4 );
1160
- A03 = B3 ^((~B4)& B0 );
1161
- A04 = B4 ^((~B0)& B1 );
1162
-
1163
- B2 = ROL64((A10^D0), 3);
1164
- B3 = ROL64((A11^D1), 45);
1165
- B4 = ROL64((A12^D2), 61);
1166
- B0 = ROL64((A13^D3), 28);
1167
- B1 = ROL64((A14^D4), 20);
1168
- A10 = B0 ^((~B1)& B2 );
1169
- A11 = B1 ^((~B2)& B3 );
1170
- A12 = B2 ^((~B3)& B4 );
1171
- A13 = B3 ^((~B4)& B0 );
1172
- A14 = B4 ^((~B0)& B1 );
1173
-
1174
- B4 = ROL64((A20^D0), 18);
1175
- B0 = ROL64((A21^D1), 1);
1176
- B1 = ROL64((A22^D2), 6);
1177
- B2 = ROL64((A23^D3), 25);
1178
- B3 = ROL64((A24^D4), 8);
1179
- A20 = B0 ^((~B1)& B2 );
1180
- A21 = B1 ^((~B2)& B3 );
1181
- A22 = B2 ^((~B3)& B4 );
1182
- A23 = B3 ^((~B4)& B0 );
1183
- A24 = B4 ^((~B0)& B1 );
1184
-
1185
- B1 = ROL64((A30^D0), 36);
1186
- B2 = ROL64((A31^D1), 10);
1187
- B3 = ROL64((A32^D2), 15);
1188
- B4 = ROL64((A33^D3), 56);
1189
- B0 = ROL64((A34^D4), 27);
1190
- A30 = B0 ^((~B1)& B2 );
1191
- A31 = B1 ^((~B2)& B3 );
1192
- A32 = B2 ^((~B3)& B4 );
1193
- A33 = B3 ^((~B4)& B0 );
1194
- A34 = B4 ^((~B0)& B1 );
1195
-
1196
- B3 = ROL64((A40^D0), 41);
1197
- B4 = ROL64((A41^D1), 2);
1198
- B0 = ROL64((A42^D2), 62);
1199
- B1 = ROL64((A43^D3), 55);
1200
- B2 = ROL64((A44^D4), 39);
1201
- A40 = B0 ^((~B1)& B2 );
1202
- A41 = B1 ^((~B2)& B3 );
1203
- A42 = B2 ^((~B3)& B4 );
1204
- A43 = B3 ^((~B4)& B0 );
1205
- A44 = B4 ^((~B0)& B1 );
1231
+ c0 = a00^a10^a20^a30^a40;
1232
+ c1 = a01^a11^a21^a31^a41;
1233
+ c2 = a02^a12^a22^a32^a42;
1234
+ c3 = a03^a13^a23^a33^a43;
1235
+ c4 = a04^a14^a24^a34^a44;
1236
+ d0 = c4^ROL64(c1, 1);
1237
+ d1 = c0^ROL64(c2, 1);
1238
+ d2 = c1^ROL64(c3, 1);
1239
+ d3 = c2^ROL64(c4, 1);
1240
+ d4 = c3^ROL64(c0, 1);
1241
+
1242
+ b0 = (a00^d0);
1243
+ b1 = ROL64((a11^d1), 44);
1244
+ b2 = ROL64((a22^d2), 43);
1245
+ b3 = ROL64((a33^d3), 21);
1246
+ b4 = ROL64((a44^d4), 14);
1247
+ a00 = b0 ^((~b1)& b2 );
1248
+ a00 ^= RC[i];
1249
+ a11 = b1 ^((~b2)& b3 );
1250
+ a22 = b2 ^((~b3)& b4 );
1251
+ a33 = b3 ^((~b4)& b0 );
1252
+ a44 = b4 ^((~b0)& b1 );
1253
+
1254
+ b2 = ROL64((a20^d0), 3);
1255
+ b3 = ROL64((a31^d1), 45);
1256
+ b4 = ROL64((a42^d2), 61);
1257
+ b0 = ROL64((a03^d3), 28);
1258
+ b1 = ROL64((a14^d4), 20);
1259
+ a20 = b0 ^((~b1)& b2 );
1260
+ a31 = b1 ^((~b2)& b3 );
1261
+ a42 = b2 ^((~b3)& b4 );
1262
+ a03 = b3 ^((~b4)& b0 );
1263
+ a14 = b4 ^((~b0)& b1 );
1264
+
1265
+ b4 = ROL64((a40^d0), 18);
1266
+ b0 = ROL64((a01^d1), 1);
1267
+ b1 = ROL64((a12^d2), 6);
1268
+ b2 = ROL64((a23^d3), 25);
1269
+ b3 = ROL64((a34^d4), 8);
1270
+ a40 = b0 ^((~b1)& b2 );
1271
+ a01 = b1 ^((~b2)& b3 );
1272
+ a12 = b2 ^((~b3)& b4 );
1273
+ a23 = b3 ^((~b4)& b0 );
1274
+ a34 = b4 ^((~b0)& b1 );
1275
+
1276
+ b1 = ROL64((a10^d0), 36);
1277
+ b2 = ROL64((a21^d1), 10);
1278
+ b3 = ROL64((a32^d2), 15);
1279
+ b4 = ROL64((a43^d3), 56);
1280
+ b0 = ROL64((a04^d4), 27);
1281
+ a10 = b0 ^((~b1)& b2 );
1282
+ a21 = b1 ^((~b2)& b3 );
1283
+ a32 = b2 ^((~b3)& b4 );
1284
+ a43 = b3 ^((~b4)& b0 );
1285
+ a04 = b4 ^((~b0)& b1 );
1286
+
1287
+ b3 = ROL64((a30^d0), 41);
1288
+ b4 = ROL64((a41^d1), 2);
1289
+ b0 = ROL64((a02^d2), 62);
1290
+ b1 = ROL64((a13^d3), 55);
1291
+ b2 = ROL64((a24^d4), 39);
1292
+ a30 = b0 ^((~b1)& b2 );
1293
+ a41 = b1 ^((~b2)& b3 );
1294
+ a02 = b2 ^((~b3)& b4 );
1295
+ a13 = b3 ^((~b4)& b0 );
1296
+ a24 = b4 ^((~b0)& b1 );
1297
+
1298
+ c0 = a00^a20^a40^a10^a30;
1299
+ c1 = a11^a31^a01^a21^a41;
1300
+ c2 = a22^a42^a12^a32^a02;
1301
+ c3 = a33^a03^a23^a43^a13;
1302
+ c4 = a44^a14^a34^a04^a24;
1303
+ d0 = c4^ROL64(c1, 1);
1304
+ d1 = c0^ROL64(c2, 1);
1305
+ d2 = c1^ROL64(c3, 1);
1306
+ d3 = c2^ROL64(c4, 1);
1307
+ d4 = c3^ROL64(c0, 1);
1308
+
1309
+ b0 = (a00^d0);
1310
+ b1 = ROL64((a31^d1), 44);
1311
+ b2 = ROL64((a12^d2), 43);
1312
+ b3 = ROL64((a43^d3), 21);
1313
+ b4 = ROL64((a24^d4), 14);
1314
+ a00 = b0 ^((~b1)& b2 );
1315
+ a00 ^= RC[i+1];
1316
+ a31 = b1 ^((~b2)& b3 );
1317
+ a12 = b2 ^((~b3)& b4 );
1318
+ a43 = b3 ^((~b4)& b0 );
1319
+ a24 = b4 ^((~b0)& b1 );
1320
+
1321
+ b2 = ROL64((a40^d0), 3);
1322
+ b3 = ROL64((a21^d1), 45);
1323
+ b4 = ROL64((a02^d2), 61);
1324
+ b0 = ROL64((a33^d3), 28);
1325
+ b1 = ROL64((a14^d4), 20);
1326
+ a40 = b0 ^((~b1)& b2 );
1327
+ a21 = b1 ^((~b2)& b3 );
1328
+ a02 = b2 ^((~b3)& b4 );
1329
+ a33 = b3 ^((~b4)& b0 );
1330
+ a14 = b4 ^((~b0)& b1 );
1331
+
1332
+ b4 = ROL64((a30^d0), 18);
1333
+ b0 = ROL64((a11^d1), 1);
1334
+ b1 = ROL64((a42^d2), 6);
1335
+ b2 = ROL64((a23^d3), 25);
1336
+ b3 = ROL64((a04^d4), 8);
1337
+ a30 = b0 ^((~b1)& b2 );
1338
+ a11 = b1 ^((~b2)& b3 );
1339
+ a42 = b2 ^((~b3)& b4 );
1340
+ a23 = b3 ^((~b4)& b0 );
1341
+ a04 = b4 ^((~b0)& b1 );
1342
+
1343
+ b1 = ROL64((a20^d0), 36);
1344
+ b2 = ROL64((a01^d1), 10);
1345
+ b3 = ROL64((a32^d2), 15);
1346
+ b4 = ROL64((a13^d3), 56);
1347
+ b0 = ROL64((a44^d4), 27);
1348
+ a20 = b0 ^((~b1)& b2 );
1349
+ a01 = b1 ^((~b2)& b3 );
1350
+ a32 = b2 ^((~b3)& b4 );
1351
+ a13 = b3 ^((~b4)& b0 );
1352
+ a44 = b4 ^((~b0)& b1 );
1353
+
1354
+ b3 = ROL64((a10^d0), 41);
1355
+ b4 = ROL64((a41^d1), 2);
1356
+ b0 = ROL64((a22^d2), 62);
1357
+ b1 = ROL64((a03^d3), 55);
1358
+ b2 = ROL64((a34^d4), 39);
1359
+ a10 = b0 ^((~b1)& b2 );
1360
+ a41 = b1 ^((~b2)& b3 );
1361
+ a22 = b2 ^((~b3)& b4 );
1362
+ a03 = b3 ^((~b4)& b0 );
1363
+ a34 = b4 ^((~b0)& b1 );
1364
+
1365
+ c0 = a00^a40^a30^a20^a10;
1366
+ c1 = a31^a21^a11^a01^a41;
1367
+ c2 = a12^a02^a42^a32^a22;
1368
+ c3 = a43^a33^a23^a13^a03;
1369
+ c4 = a24^a14^a04^a44^a34;
1370
+ d0 = c4^ROL64(c1, 1);
1371
+ d1 = c0^ROL64(c2, 1);
1372
+ d2 = c1^ROL64(c3, 1);
1373
+ d3 = c2^ROL64(c4, 1);
1374
+ d4 = c3^ROL64(c0, 1);
1375
+
1376
+ b0 = (a00^d0);
1377
+ b1 = ROL64((a21^d1), 44);
1378
+ b2 = ROL64((a42^d2), 43);
1379
+ b3 = ROL64((a13^d3), 21);
1380
+ b4 = ROL64((a34^d4), 14);
1381
+ a00 = b0 ^((~b1)& b2 );
1382
+ a00 ^= RC[i+2];
1383
+ a21 = b1 ^((~b2)& b3 );
1384
+ a42 = b2 ^((~b3)& b4 );
1385
+ a13 = b3 ^((~b4)& b0 );
1386
+ a34 = b4 ^((~b0)& b1 );
1387
+
1388
+ b2 = ROL64((a30^d0), 3);
1389
+ b3 = ROL64((a01^d1), 45);
1390
+ b4 = ROL64((a22^d2), 61);
1391
+ b0 = ROL64((a43^d3), 28);
1392
+ b1 = ROL64((a14^d4), 20);
1393
+ a30 = b0 ^((~b1)& b2 );
1394
+ a01 = b1 ^((~b2)& b3 );
1395
+ a22 = b2 ^((~b3)& b4 );
1396
+ a43 = b3 ^((~b4)& b0 );
1397
+ a14 = b4 ^((~b0)& b1 );
1398
+
1399
+ b4 = ROL64((a10^d0), 18);
1400
+ b0 = ROL64((a31^d1), 1);
1401
+ b1 = ROL64((a02^d2), 6);
1402
+ b2 = ROL64((a23^d3), 25);
1403
+ b3 = ROL64((a44^d4), 8);
1404
+ a10 = b0 ^((~b1)& b2 );
1405
+ a31 = b1 ^((~b2)& b3 );
1406
+ a02 = b2 ^((~b3)& b4 );
1407
+ a23 = b3 ^((~b4)& b0 );
1408
+ a44 = b4 ^((~b0)& b1 );
1409
+
1410
+ b1 = ROL64((a40^d0), 36);
1411
+ b2 = ROL64((a11^d1), 10);
1412
+ b3 = ROL64((a32^d2), 15);
1413
+ b4 = ROL64((a03^d3), 56);
1414
+ b0 = ROL64((a24^d4), 27);
1415
+ a40 = b0 ^((~b1)& b2 );
1416
+ a11 = b1 ^((~b2)& b3 );
1417
+ a32 = b2 ^((~b3)& b4 );
1418
+ a03 = b3 ^((~b4)& b0 );
1419
+ a24 = b4 ^((~b0)& b1 );
1420
+
1421
+ b3 = ROL64((a20^d0), 41);
1422
+ b4 = ROL64((a41^d1), 2);
1423
+ b0 = ROL64((a12^d2), 62);
1424
+ b1 = ROL64((a33^d3), 55);
1425
+ b2 = ROL64((a04^d4), 39);
1426
+ a20 = b0 ^((~b1)& b2 );
1427
+ a41 = b1 ^((~b2)& b3 );
1428
+ a12 = b2 ^((~b3)& b4 );
1429
+ a33 = b3 ^((~b4)& b0 );
1430
+ a04 = b4 ^((~b0)& b1 );
1431
+
1432
+ c0 = a00^a30^a10^a40^a20;
1433
+ c1 = a21^a01^a31^a11^a41;
1434
+ c2 = a42^a22^a02^a32^a12;
1435
+ c3 = a13^a43^a23^a03^a33;
1436
+ c4 = a34^a14^a44^a24^a04;
1437
+ d0 = c4^ROL64(c1, 1);
1438
+ d1 = c0^ROL64(c2, 1);
1439
+ d2 = c1^ROL64(c3, 1);
1440
+ d3 = c2^ROL64(c4, 1);
1441
+ d4 = c3^ROL64(c0, 1);
1442
+
1443
+ b0 = (a00^d0);
1444
+ b1 = ROL64((a01^d1), 44);
1445
+ b2 = ROL64((a02^d2), 43);
1446
+ b3 = ROL64((a03^d3), 21);
1447
+ b4 = ROL64((a04^d4), 14);
1448
+ a00 = b0 ^((~b1)& b2 );
1449
+ a00 ^= RC[i+3];
1450
+ a01 = b1 ^((~b2)& b3 );
1451
+ a02 = b2 ^((~b3)& b4 );
1452
+ a03 = b3 ^((~b4)& b0 );
1453
+ a04 = b4 ^((~b0)& b1 );
1454
+
1455
+ b2 = ROL64((a10^d0), 3);
1456
+ b3 = ROL64((a11^d1), 45);
1457
+ b4 = ROL64((a12^d2), 61);
1458
+ b0 = ROL64((a13^d3), 28);
1459
+ b1 = ROL64((a14^d4), 20);
1460
+ a10 = b0 ^((~b1)& b2 );
1461
+ a11 = b1 ^((~b2)& b3 );
1462
+ a12 = b2 ^((~b3)& b4 );
1463
+ a13 = b3 ^((~b4)& b0 );
1464
+ a14 = b4 ^((~b0)& b1 );
1465
+
1466
+ b4 = ROL64((a20^d0), 18);
1467
+ b0 = ROL64((a21^d1), 1);
1468
+ b1 = ROL64((a22^d2), 6);
1469
+ b2 = ROL64((a23^d3), 25);
1470
+ b3 = ROL64((a24^d4), 8);
1471
+ a20 = b0 ^((~b1)& b2 );
1472
+ a21 = b1 ^((~b2)& b3 );
1473
+ a22 = b2 ^((~b3)& b4 );
1474
+ a23 = b3 ^((~b4)& b0 );
1475
+ a24 = b4 ^((~b0)& b1 );
1476
+
1477
+ b1 = ROL64((a30^d0), 36);
1478
+ b2 = ROL64((a31^d1), 10);
1479
+ b3 = ROL64((a32^d2), 15);
1480
+ b4 = ROL64((a33^d3), 56);
1481
+ b0 = ROL64((a34^d4), 27);
1482
+ a30 = b0 ^((~b1)& b2 );
1483
+ a31 = b1 ^((~b2)& b3 );
1484
+ a32 = b2 ^((~b3)& b4 );
1485
+ a33 = b3 ^((~b4)& b0 );
1486
+ a34 = b4 ^((~b0)& b1 );
1487
+
1488
+ b3 = ROL64((a40^d0), 41);
1489
+ b4 = ROL64((a41^d1), 2);
1490
+ b0 = ROL64((a42^d2), 62);
1491
+ b1 = ROL64((a43^d3), 55);
1492
+ b2 = ROL64((a44^d4), 39);
1493
+ a40 = b0 ^((~b1)& b2 );
1494
+ a41 = b1 ^((~b2)& b3 );
1495
+ a42 = b2 ^((~b3)& b4 );
1496
+ a43 = b3 ^((~b4)& b0 );
1497
+ a44 = b4 ^((~b0)& b1 );
12061498
}
12071499
}
12081500
12091501
/*
12101502
** Initialize a new hash. iSize determines the size of the hash
@@ -1539,14 +1831,123 @@
15391831
** May you share freely, never taking more than you give.
15401832
**
15411833
******************************************************************************
15421834
**
15431835
** This SQLite extension implements SQL functions readfile() and
1544
-** writefile().
1836
+** writefile(), and eponymous virtual type "fsdir".
1837
+**
1838
+** WRITEFILE(FILE, DATA [, MODE [, MTIME]]):
1839
+**
1840
+** If neither of the optional arguments is present, then this UDF
1841
+** function writes blob DATA to file FILE. If successful, the number
1842
+** of bytes written is returned. If an error occurs, NULL is returned.
1843
+**
1844
+** If the first option argument - MODE - is present, then it must
1845
+** be passed an integer value that corresponds to a POSIX mode
1846
+** value (file type + permissions, as returned in the stat.st_mode
1847
+** field by the stat() system call). Three types of files may
1848
+** be written/created:
1849
+**
1850
+** regular files: (mode & 0170000)==0100000
1851
+** symbolic links: (mode & 0170000)==0120000
1852
+** directories: (mode & 0170000)==0040000
1853
+**
1854
+** For a directory, the DATA is ignored. For a symbolic link, it is
1855
+** interpreted as text and used as the target of the link. For a
1856
+** regular file, it is interpreted as a blob and written into the
1857
+** named file. Regardless of the type of file, its permissions are
1858
+** set to (mode & 0777) before returning.
1859
+**
1860
+** If the optional MTIME argument is present, then it is interpreted
1861
+** as an integer - the number of seconds since the unix epoch. The
1862
+** modification-time of the target file is set to this value before
1863
+** returning.
1864
+**
1865
+** If three or more arguments are passed to this function and an
1866
+** error is encountered, an exception is raised.
1867
+**
1868
+** READFILE(FILE):
1869
+**
1870
+** Read and return the contents of file FILE (type blob) from disk.
1871
+**
1872
+** FSDIR:
1873
+**
1874
+** Used as follows:
1875
+**
1876
+** SELECT * FROM fsdir($path [, $dir]);
1877
+**
1878
+** Parameter $path is an absolute or relative pathname. If the file that it
1879
+** refers to does not exist, it is an error. If the path refers to a regular
1880
+** file or symbolic link, it returns a single row. Or, if the path refers
1881
+** to a directory, it returns one row for the directory, and one row for each
1882
+** file within the hierarchy rooted at $path.
1883
+**
1884
+** Each row has the following columns:
1885
+**
1886
+** name: Path to file or directory (text value).
1887
+** mode: Value of stat.st_mode for directory entry (an integer).
1888
+** mtime: Value of stat.st_mtime for directory entry (an integer).
1889
+** data: For a regular file, a blob containing the file data. For a
1890
+** symlink, a text value containing the text of the link. For a
1891
+** directory, NULL.
1892
+**
1893
+** If a non-NULL value is specified for the optional $dir parameter and
1894
+** $path is a relative path, then $path is interpreted relative to $dir.
1895
+** And the paths returned in the "name" column of the table are also
1896
+** relative to directory $dir.
15451897
*/
15461898
SQLITE_EXTENSION_INIT1
15471899
#include <stdio.h>
1900
+#include <string.h>
1901
+#include <assert.h>
1902
+
1903
+#include <sys/types.h>
1904
+#include <sys/stat.h>
1905
+#include <fcntl.h>
1906
+#if !defined(_WIN32) && !defined(WIN32)
1907
+# include <unistd.h>
1908
+# include <dirent.h>
1909
+# include <utime.h>
1910
+#else
1911
+# include "windows.h"
1912
+# include <io.h>
1913
+# include <direct.h>
1914
+# include "test_windirent.h"
1915
+# define dirent DIRENT
1916
+# define timespec TIMESPEC
1917
+# define stat _stat
1918
+# define mkdir(path,mode) _mkdir(path)
1919
+# define lstat(path,buf) _stat(path,buf)
1920
+#endif
1921
+#include <time.h>
1922
+#include <errno.h>
1923
+
1924
+
1925
+#define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
1926
+
1927
+/*
1928
+** Set the result stored by context ctx to a blob containing the
1929
+** contents of file zName.
1930
+*/
1931
+static void readFileContents(sqlite3_context *ctx, const char *zName){
1932
+ FILE *in;
1933
+ long nIn;
1934
+ void *pBuf;
1935
+
1936
+ in = fopen(zName, "rb");
1937
+ if( in==0 ) return;
1938
+ fseek(in, 0, SEEK_END);
1939
+ nIn = ftell(in);
1940
+ rewind(in);
1941
+ pBuf = sqlite3_malloc( nIn );
1942
+ if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1943
+ sqlite3_result_blob(ctx, pBuf, nIn, sqlite3_free);
1944
+ }else{
1945
+ sqlite3_free(pBuf);
1946
+ }
1947
+ fclose(in);
1948
+}
15481949
15491950
/*
15501951
** Implementation of the "readfile(X)" SQL function. The entire content
15511952
** of the file named X is read and returned as a BLOB. NULL is returned
15521953
** if the file does not exist or is unreadable.
@@ -1555,62 +1956,611 @@
15551956
sqlite3_context *context,
15561957
int argc,
15571958
sqlite3_value **argv
15581959
){
15591960
const char *zName;
1560
- FILE *in;
1561
- long nIn;
1562
- void *pBuf;
1563
-
15641961
(void)(argc); /* Unused parameter */
15651962
zName = (const char*)sqlite3_value_text(argv[0]);
15661963
if( zName==0 ) return;
1567
- in = fopen(zName, "rb");
1568
- if( in==0 ) return;
1569
- fseek(in, 0, SEEK_END);
1570
- nIn = ftell(in);
1571
- rewind(in);
1572
- pBuf = sqlite3_malloc( nIn );
1573
- if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1574
- sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
1964
+ readFileContents(context, zName);
1965
+}
1966
+
1967
+/*
1968
+** Set the error message contained in context ctx to the results of
1969
+** vprintf(zFmt, ...).
1970
+*/
1971
+static void ctxErrorMsg(sqlite3_context *ctx, const char *zFmt, ...){
1972
+ char *zMsg = 0;
1973
+ va_list ap;
1974
+ va_start(ap, zFmt);
1975
+ zMsg = sqlite3_vmprintf(zFmt, ap);
1976
+ sqlite3_result_error(ctx, zMsg, -1);
1977
+ sqlite3_free(zMsg);
1978
+ va_end(ap);
1979
+}
1980
+
1981
+/*
1982
+** Argument zFile is the name of a file that will be created and/or written
1983
+** by SQL function writefile(). This function ensures that the directory
1984
+** zFile will be written to exists, creating it if required. The permissions
1985
+** for any path components created by this function are set to (mode&0777).
1986
+**
1987
+** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
1988
+** SQLITE_OK is returned if the directory is successfully created, or
1989
+** SQLITE_ERROR otherwise.
1990
+*/
1991
+static int makeDirectory(
1992
+ const char *zFile,
1993
+ mode_t mode
1994
+){
1995
+ char *zCopy = sqlite3_mprintf("%s", zFile);
1996
+ int rc = SQLITE_OK;
1997
+
1998
+ if( zCopy==0 ){
1999
+ rc = SQLITE_NOMEM;
15752000
}else{
1576
- sqlite3_free(pBuf);
2001
+ int nCopy = (int)strlen(zCopy);
2002
+ int i = 1;
2003
+
2004
+ while( rc==SQLITE_OK ){
2005
+ struct stat sStat;
2006
+ int rc2;
2007
+
2008
+ for(; zCopy[i]!='/' && i<nCopy; i++);
2009
+ if( i==nCopy ) break;
2010
+ zCopy[i] = '\0';
2011
+
2012
+ rc2 = stat(zCopy, &sStat);
2013
+ if( rc2!=0 ){
2014
+ if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
2015
+ }else{
2016
+ if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2017
+ }
2018
+ zCopy[i] = '/';
2019
+ i++;
2020
+ }
2021
+
2022
+ sqlite3_free(zCopy);
15772023
}
1578
- fclose(in);
2024
+
2025
+ return rc;
15792026
}
15802027
15812028
/*
1582
-** Implementation of the "writefile(X,Y)" SQL function. The argument Y
1583
-** is written into file X. The number of bytes written is returned. Or
1584
-** NULL is returned if something goes wrong, such as being unable to open
1585
-** file X for writing.
2029
+** This function does the work for the writefile() UDF. Refer to
2030
+** header comments at the top of this file for details.
2031
+*/
2032
+static int writeFile(
2033
+ sqlite3_context *pCtx, /* Context to return bytes written in */
2034
+ const char *zFile, /* File to write */
2035
+ sqlite3_value *pData, /* Data to write */
2036
+ mode_t mode, /* MODE parameter passed to writefile() */
2037
+ sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */
2038
+){
2039
+#if !defined(_WIN32) && !defined(WIN32)
2040
+ if( S_ISLNK(mode) ){
2041
+ const char *zTo = (const char*)sqlite3_value_text(pData);
2042
+ if( symlink(zTo, zFile)<0 ) return 1;
2043
+ }else
2044
+#endif
2045
+ {
2046
+ if( S_ISDIR(mode) ){
2047
+ if( mkdir(zFile, mode) ){
2048
+ /* The mkdir() call to create the directory failed. This might not
2049
+ ** be an error though - if there is already a directory at the same
2050
+ ** path and either the permissions already match or can be changed
2051
+ ** to do so using chmod(), it is not an error. */
2052
+ struct stat sStat;
2053
+ if( errno!=EEXIST
2054
+ || 0!=stat(zFile, &sStat)
2055
+ || !S_ISDIR(sStat.st_mode)
2056
+ || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
2057
+ ){
2058
+ return 1;
2059
+ }
2060
+ }
2061
+ }else{
2062
+ sqlite3_int64 nWrite = 0;
2063
+ const char *z;
2064
+ int rc = 0;
2065
+ FILE *out = fopen(zFile, "wb");
2066
+ if( out==0 ) return 1;
2067
+ z = (const char*)sqlite3_value_blob(pData);
2068
+ if( z ){
2069
+ sqlite3_int64 n = fwrite(z, 1, sqlite3_value_bytes(pData), out);
2070
+ nWrite = sqlite3_value_bytes(pData);
2071
+ if( nWrite!=n ){
2072
+ rc = 1;
2073
+ }
2074
+ }
2075
+ fclose(out);
2076
+ if( rc==0 && mode && chmod(zFile, mode & 0777) ){
2077
+ rc = 1;
2078
+ }
2079
+ if( rc ) return 2;
2080
+ sqlite3_result_int64(pCtx, nWrite);
2081
+ }
2082
+ }
2083
+
2084
+ if( mtime>=0 ){
2085
+#if !defined(_WIN32) && !defined(WIN32)
2086
+ struct timespec times[2];
2087
+ times[0].tv_nsec = times[1].tv_nsec = 0;
2088
+ times[0].tv_sec = time(0);
2089
+ times[1].tv_sec = mtime;
2090
+ if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
2091
+ return 1;
2092
+ }
2093
+#else
2094
+ FILETIME lastAccess;
2095
+ FILETIME lastWrite;
2096
+ SYSTEMTIME currentTime;
2097
+ LONGLONG intervals;
2098
+ HANDLE hFile;
2099
+ GetSystemTime(&currentTime);
2100
+ SystemTimeToFileTime(&currentTime, &lastAccess);
2101
+ intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
2102
+ lastWrite.dwLowDateTime = (DWORD)intervals;
2103
+ lastWrite.dwHighDateTime = intervals >> 32;
2104
+ hFile = CreateFile(
2105
+ zFile, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
2106
+ FILE_FLAG_BACKUP_SEMANTICS, NULL
2107
+ );
2108
+ if( hFile!=INVALID_HANDLE_VALUE ){
2109
+ BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
2110
+ CloseHandle(hFile);
2111
+ return !bResult;
2112
+ }else{
2113
+ return 1;
2114
+ }
2115
+#endif
2116
+ }
2117
+
2118
+ return 0;
2119
+}
2120
+
2121
+/*
2122
+** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
2123
+** Refer to header comments at the top of this file for details.
15862124
*/
15872125
static void writefileFunc(
15882126
sqlite3_context *context,
15892127
int argc,
15902128
sqlite3_value **argv
15912129
){
1592
- FILE *out;
1593
- const char *z;
1594
- sqlite3_int64 rc;
15952130
const char *zFile;
2131
+ mode_t mode = 0;
2132
+ int res;
2133
+ sqlite3_int64 mtime = -1;
15962134
1597
- (void)(argc); /* Unused parameter */
2135
+ if( argc<2 || argc>4 ){
2136
+ sqlite3_result_error(context,
2137
+ "wrong number of arguments to function writefile()", -1
2138
+ );
2139
+ return;
2140
+ }
2141
+
15982142
zFile = (const char*)sqlite3_value_text(argv[0]);
15992143
if( zFile==0 ) return;
1600
- out = fopen(zFile, "wb");
1601
- if( out==0 ) return;
1602
- z = (const char*)sqlite3_value_blob(argv[1]);
1603
- if( z==0 ){
1604
- rc = 0;
2144
+ if( argc>=3 ){
2145
+ mode = (mode_t)sqlite3_value_int(argv[2]);
2146
+ }
2147
+ if( argc==4 ){
2148
+ mtime = sqlite3_value_int64(argv[3]);
2149
+ }
2150
+
2151
+ res = writeFile(context, zFile, argv[1], mode, mtime);
2152
+ if( res==1 && errno==ENOENT ){
2153
+ if( makeDirectory(zFile, mode)==SQLITE_OK ){
2154
+ res = writeFile(context, zFile, argv[1], mode, mtime);
2155
+ }
2156
+ }
2157
+
2158
+ if( argc>2 && res!=0 ){
2159
+ if( S_ISLNK(mode) ){
2160
+ ctxErrorMsg(context, "failed to create symlink: %s", zFile);
2161
+ }else if( S_ISDIR(mode) ){
2162
+ ctxErrorMsg(context, "failed to create directory: %s", zFile);
2163
+ }else{
2164
+ ctxErrorMsg(context, "failed to write file: %s", zFile);
2165
+ }
2166
+ }
2167
+}
2168
+
2169
+#ifndef SQLITE_OMIT_VIRTUALTABLE
2170
+
2171
+/*
2172
+** Cursor type for recursively iterating through a directory structure.
2173
+*/
2174
+typedef struct fsdir_cursor fsdir_cursor;
2175
+typedef struct FsdirLevel FsdirLevel;
2176
+
2177
+struct FsdirLevel {
2178
+ DIR *pDir; /* From opendir() */
2179
+ char *zDir; /* Name of directory (nul-terminated) */
2180
+};
2181
+
2182
+struct fsdir_cursor {
2183
+ sqlite3_vtab_cursor base; /* Base class - must be first */
2184
+
2185
+ int nLvl; /* Number of entries in aLvl[] array */
2186
+ int iLvl; /* Index of current entry */
2187
+ FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
2188
+
2189
+ const char *zBase;
2190
+ int nBase;
2191
+
2192
+ struct stat sStat; /* Current lstat() results */
2193
+ char *zPath; /* Path to current entry */
2194
+ sqlite3_int64 iRowid; /* Current rowid */
2195
+};
2196
+
2197
+typedef struct fsdir_tab fsdir_tab;
2198
+struct fsdir_tab {
2199
+ sqlite3_vtab base; /* Base class - must be first */
2200
+};
2201
+
2202
+/*
2203
+** Construct a new fsdir virtual table object.
2204
+*/
2205
+static int fsdirConnect(
2206
+ sqlite3 *db,
2207
+ void *pAux,
2208
+ int argc, const char *const*argv,
2209
+ sqlite3_vtab **ppVtab,
2210
+ char **pzErr
2211
+){
2212
+ fsdir_tab *pNew = 0;
2213
+ int rc;
2214
+
2215
+ rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2216
+ if( rc==SQLITE_OK ){
2217
+ pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2218
+ if( pNew==0 ) return SQLITE_NOMEM;
2219
+ memset(pNew, 0, sizeof(*pNew));
2220
+ }
2221
+ *ppVtab = (sqlite3_vtab*)pNew;
2222
+ return rc;
2223
+}
2224
+
2225
+/*
2226
+** This method is the destructor for fsdir vtab objects.
2227
+*/
2228
+static int fsdirDisconnect(sqlite3_vtab *pVtab){
2229
+ sqlite3_free(pVtab);
2230
+ return SQLITE_OK;
2231
+}
2232
+
2233
+/*
2234
+** Constructor for a new fsdir_cursor object.
2235
+*/
2236
+static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
2237
+ fsdir_cursor *pCur;
2238
+ pCur = sqlite3_malloc( sizeof(*pCur) );
2239
+ if( pCur==0 ) return SQLITE_NOMEM;
2240
+ memset(pCur, 0, sizeof(*pCur));
2241
+ pCur->iLvl = -1;
2242
+ *ppCursor = &pCur->base;
2243
+ return SQLITE_OK;
2244
+}
2245
+
2246
+/*
2247
+** Reset a cursor back to the state it was in when first returned
2248
+** by fsdirOpen().
2249
+*/
2250
+static void fsdirResetCursor(fsdir_cursor *pCur){
2251
+ int i;
2252
+ for(i=0; i<=pCur->iLvl; i++){
2253
+ FsdirLevel *pLvl = &pCur->aLvl[i];
2254
+ if( pLvl->pDir ) closedir(pLvl->pDir);
2255
+ sqlite3_free(pLvl->zDir);
2256
+ }
2257
+ sqlite3_free(pCur->zPath);
2258
+ pCur->aLvl = 0;
2259
+ pCur->zPath = 0;
2260
+ pCur->zBase = 0;
2261
+ pCur->nBase = 0;
2262
+ pCur->iLvl = -1;
2263
+ pCur->iRowid = 1;
2264
+}
2265
+
2266
+/*
2267
+** Destructor for an fsdir_cursor.
2268
+*/
2269
+static int fsdirClose(sqlite3_vtab_cursor *cur){
2270
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
2271
+
2272
+ fsdirResetCursor(pCur);
2273
+ sqlite3_free(pCur->aLvl);
2274
+ sqlite3_free(pCur);
2275
+ return SQLITE_OK;
2276
+}
2277
+
2278
+/*
2279
+** Set the error message for the virtual table associated with cursor
2280
+** pCur to the results of vprintf(zFmt, ...).
2281
+*/
2282
+static void fsdirSetErrmsg(fsdir_cursor *pCur, const char *zFmt, ...){
2283
+ va_list ap;
2284
+ va_start(ap, zFmt);
2285
+ pCur->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
2286
+ va_end(ap);
2287
+}
2288
+
2289
+
2290
+/*
2291
+** Advance an fsdir_cursor to its next row of output.
2292
+*/
2293
+static int fsdirNext(sqlite3_vtab_cursor *cur){
2294
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
2295
+ mode_t m = pCur->sStat.st_mode;
2296
+
2297
+ pCur->iRowid++;
2298
+ if( S_ISDIR(m) ){
2299
+ /* Descend into this directory */
2300
+ int iNew = pCur->iLvl + 1;
2301
+ FsdirLevel *pLvl;
2302
+ if( iNew>=pCur->nLvl ){
2303
+ int nNew = iNew+1;
2304
+ int nByte = nNew*sizeof(FsdirLevel);
2305
+ FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc(pCur->aLvl, nByte);
2306
+ if( aNew==0 ) return SQLITE_NOMEM;
2307
+ memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
2308
+ pCur->aLvl = aNew;
2309
+ pCur->nLvl = nNew;
2310
+ }
2311
+ pCur->iLvl = iNew;
2312
+ pLvl = &pCur->aLvl[iNew];
2313
+
2314
+ pLvl->zDir = pCur->zPath;
2315
+ pCur->zPath = 0;
2316
+ pLvl->pDir = opendir(pLvl->zDir);
2317
+ if( pLvl->pDir==0 ){
2318
+ fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath);
2319
+ return SQLITE_ERROR;
2320
+ }
2321
+ }
2322
+
2323
+ while( pCur->iLvl>=0 ){
2324
+ FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl];
2325
+ struct dirent *pEntry = readdir(pLvl->pDir);
2326
+ if( pEntry ){
2327
+ if( pEntry->d_name[0]=='.' ){
2328
+ if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
2329
+ if( pEntry->d_name[1]=='\0' ) continue;
2330
+ }
2331
+ sqlite3_free(pCur->zPath);
2332
+ pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
2333
+ if( pCur->zPath==0 ) return SQLITE_NOMEM;
2334
+ if( lstat(pCur->zPath, &pCur->sStat) ){
2335
+ fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2336
+ return SQLITE_ERROR;
2337
+ }
2338
+ return SQLITE_OK;
2339
+ }
2340
+ closedir(pLvl->pDir);
2341
+ sqlite3_free(pLvl->zDir);
2342
+ pLvl->pDir = 0;
2343
+ pLvl->zDir = 0;
2344
+ pCur->iLvl--;
2345
+ }
2346
+
2347
+ /* EOF */
2348
+ sqlite3_free(pCur->zPath);
2349
+ pCur->zPath = 0;
2350
+ return SQLITE_OK;
2351
+}
2352
+
2353
+/*
2354
+** Return values of columns for the row at which the series_cursor
2355
+** is currently pointing.
2356
+*/
2357
+static int fsdirColumn(
2358
+ sqlite3_vtab_cursor *cur, /* The cursor */
2359
+ sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
2360
+ int i /* Which column to return */
2361
+){
2362
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
2363
+ switch( i ){
2364
+ case 0: { /* name */
2365
+ sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
2366
+ break;
2367
+ }
2368
+
2369
+ case 1: /* mode */
2370
+ sqlite3_result_int64(ctx, pCur->sStat.st_mode);
2371
+ break;
2372
+
2373
+ case 2: /* mtime */
2374
+ sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
2375
+ break;
2376
+
2377
+ case 3: { /* data */
2378
+ mode_t m = pCur->sStat.st_mode;
2379
+ if( S_ISDIR(m) ){
2380
+ sqlite3_result_null(ctx);
2381
+#if !defined(_WIN32) && !defined(WIN32)
2382
+ }else if( S_ISLNK(m) ){
2383
+ char aStatic[64];
2384
+ char *aBuf = aStatic;
2385
+ int nBuf = 64;
2386
+ int n;
2387
+
2388
+ while( 1 ){
2389
+ n = readlink(pCur->zPath, aBuf, nBuf);
2390
+ if( n<nBuf ) break;
2391
+ if( aBuf!=aStatic ) sqlite3_free(aBuf);
2392
+ nBuf = nBuf*2;
2393
+ aBuf = sqlite3_malloc(nBuf);
2394
+ if( aBuf==0 ){
2395
+ sqlite3_result_error_nomem(ctx);
2396
+ return SQLITE_NOMEM;
2397
+ }
2398
+ }
2399
+
2400
+ sqlite3_result_text(ctx, aBuf, n, SQLITE_TRANSIENT);
2401
+ if( aBuf!=aStatic ) sqlite3_free(aBuf);
2402
+#endif
2403
+ }else{
2404
+ readFileContents(ctx, pCur->zPath);
2405
+ }
2406
+ }
2407
+ }
2408
+ return SQLITE_OK;
2409
+}
2410
+
2411
+/*
2412
+** Return the rowid for the current row. In this implementation, the
2413
+** first row returned is assigned rowid value 1, and each subsequent
2414
+** row a value 1 more than that of the previous.
2415
+*/
2416
+static int fsdirRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
2417
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
2418
+ *pRowid = pCur->iRowid;
2419
+ return SQLITE_OK;
2420
+}
2421
+
2422
+/*
2423
+** Return TRUE if the cursor has been moved off of the last
2424
+** row of output.
2425
+*/
2426
+static int fsdirEof(sqlite3_vtab_cursor *cur){
2427
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
2428
+ return (pCur->zPath==0);
2429
+}
2430
+
2431
+/*
2432
+** xFilter callback.
2433
+*/
2434
+static int fsdirFilter(
2435
+ sqlite3_vtab_cursor *cur,
2436
+ int idxNum, const char *idxStr,
2437
+ int argc, sqlite3_value **argv
2438
+){
2439
+ const char *zDir = 0;
2440
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
2441
+
2442
+ fsdirResetCursor(pCur);
2443
+
2444
+ if( idxNum==0 ){
2445
+ fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
2446
+ return SQLITE_ERROR;
2447
+ }
2448
+
2449
+ assert( argc==idxNum && (argc==1 || argc==2) );
2450
+ zDir = (const char*)sqlite3_value_text(argv[0]);
2451
+ if( zDir==0 ){
2452
+ fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
2453
+ return SQLITE_ERROR;
2454
+ }
2455
+ if( argc==2 ){
2456
+ pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
2457
+ }
2458
+ if( pCur->zBase ){
2459
+ pCur->nBase = (int)strlen(pCur->zBase)+1;
2460
+ pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
2461
+ }else{
2462
+ pCur->zPath = sqlite3_mprintf("%s", zDir);
2463
+ }
2464
+
2465
+ if( pCur->zPath==0 ){
2466
+ return SQLITE_NOMEM;
2467
+ }
2468
+ if( lstat(pCur->zPath, &pCur->sStat) ){
2469
+ fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2470
+ return SQLITE_ERROR;
2471
+ }
2472
+
2473
+ return SQLITE_OK;
2474
+}
2475
+
2476
+/*
2477
+** SQLite will invoke this method one or more times while planning a query
2478
+** that uses the generate_series virtual table. This routine needs to create
2479
+** a query plan for each invocation and compute an estimated cost for that
2480
+** plan.
2481
+**
2482
+** In this implementation idxNum is used to represent the
2483
+** query plan. idxStr is unused.
2484
+**
2485
+** The query plan is represented by bits in idxNum:
2486
+**
2487
+** (1) start = $value -- constraint exists
2488
+** (2) stop = $value -- constraint exists
2489
+** (4) step = $value -- constraint exists
2490
+** (8) output in descending order
2491
+*/
2492
+static int fsdirBestIndex(
2493
+ sqlite3_vtab *tab,
2494
+ sqlite3_index_info *pIdxInfo
2495
+){
2496
+ int i; /* Loop over constraints */
2497
+ int idx4 = -1;
2498
+ int idx5 = -1;
2499
+
2500
+ const struct sqlite3_index_constraint *pConstraint;
2501
+ pConstraint = pIdxInfo->aConstraint;
2502
+ for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
2503
+ if( pConstraint->usable==0 ) continue;
2504
+ if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
2505
+ if( pConstraint->iColumn==4 ) idx4 = i;
2506
+ if( pConstraint->iColumn==5 ) idx5 = i;
2507
+ }
2508
+
2509
+ if( idx4<0 ){
2510
+ pIdxInfo->idxNum = 0;
2511
+ pIdxInfo->estimatedCost = (double)(((sqlite3_int64)1) << 50);
16052512
}else{
1606
- rc = fwrite(z, 1, sqlite3_value_bytes(argv[1]), out);
2513
+ pIdxInfo->aConstraintUsage[idx4].omit = 1;
2514
+ pIdxInfo->aConstraintUsage[idx4].argvIndex = 1;
2515
+ if( idx5>=0 ){
2516
+ pIdxInfo->aConstraintUsage[idx5].omit = 1;
2517
+ pIdxInfo->aConstraintUsage[idx5].argvIndex = 2;
2518
+ pIdxInfo->idxNum = 2;
2519
+ pIdxInfo->estimatedCost = 10.0;
2520
+ }else{
2521
+ pIdxInfo->idxNum = 1;
2522
+ pIdxInfo->estimatedCost = 100.0;
2523
+ }
16072524
}
1608
- fclose(out);
1609
- sqlite3_result_int64(context, rc);
2525
+
2526
+ return SQLITE_OK;
16102527
}
16112528
2529
+/*
2530
+** Register the "fsdir" virtual table.
2531
+*/
2532
+static int fsdirRegister(sqlite3 *db){
2533
+ static sqlite3_module fsdirModule = {
2534
+ 0, /* iVersion */
2535
+ 0, /* xCreate */
2536
+ fsdirConnect, /* xConnect */
2537
+ fsdirBestIndex, /* xBestIndex */
2538
+ fsdirDisconnect, /* xDisconnect */
2539
+ 0, /* xDestroy */
2540
+ fsdirOpen, /* xOpen - open a cursor */
2541
+ fsdirClose, /* xClose - close a cursor */
2542
+ fsdirFilter, /* xFilter - configure scan constraints */
2543
+ fsdirNext, /* xNext - advance a cursor */
2544
+ fsdirEof, /* xEof - check for end of scan */
2545
+ fsdirColumn, /* xColumn - read data */
2546
+ fsdirRowid, /* xRowid - read data */
2547
+ 0, /* xUpdate */
2548
+ 0, /* xBegin */
2549
+ 0, /* xSync */
2550
+ 0, /* xCommit */
2551
+ 0, /* xRollback */
2552
+ 0, /* xFindMethod */
2553
+ 0, /* xRename */
2554
+ };
2555
+
2556
+ int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
2557
+ return rc;
2558
+}
2559
+#else /* SQLITE_OMIT_VIRTUALTABLE */
2560
+# define fsdirRegister(x) SQLITE_OK
2561
+#endif
16122562
16132563
#ifdef _WIN32
16142564
16152565
#endif
16162566
int sqlite3_fileio_init(
@@ -1622,13 +2572,16 @@
16222572
SQLITE_EXTENSION_INIT2(pApi);
16232573
(void)pzErrMsg; /* Unused parameter */
16242574
rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
16252575
readfileFunc, 0, 0);
16262576
if( rc==SQLITE_OK ){
1627
- rc = sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
2577
+ rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
16282578
writefileFunc, 0, 0);
16292579
}
2580
+ if( rc==SQLITE_OK ){
2581
+ rc = fsdirRegister(db);
2582
+ }
16302583
return rc;
16312584
}
16322585
16332586
/************************* End ../ext/misc/fileio.c ********************/
16342587
/************************* Begin ../ext/misc/completion.c ******************/
@@ -2154,10 +3107,4226 @@
21543107
#endif
21553108
return rc;
21563109
}
21573110
21583111
/************************* End ../ext/misc/completion.c ********************/
3112
+/************************* Begin ../ext/misc/appendvfs.c ******************/
3113
+/*
3114
+** 2017-10-20
3115
+**
3116
+** The author disclaims copyright to this source code. In place of
3117
+** a legal notice, here is a blessing:
3118
+**
3119
+** May you do good and not evil.
3120
+** May you find forgiveness for yourself and forgive others.
3121
+** May you share freely, never taking more than you give.
3122
+**
3123
+******************************************************************************
3124
+**
3125
+** This file implements a VFS shim that allows an SQLite database to be
3126
+** appended onto the end of some other file, such as an executable.
3127
+**
3128
+** A special record must appear at the end of the file that identifies the
3129
+** file as an appended database and provides an offset to page 1. For
3130
+** best performance page 1 should be located at a disk page boundary, though
3131
+** that is not required.
3132
+**
3133
+** When opening a database using this VFS, the connection might treat
3134
+** the file as an ordinary SQLite database, or it might treat is as a
3135
+** database appended onto some other file. Here are the rules:
3136
+**
3137
+** (1) When opening a new empty file, that file is treated as an ordinary
3138
+** database.
3139
+**
3140
+** (2) When opening a file that begins with the standard SQLite prefix
3141
+** string "SQLite format 3", that file is treated as an ordinary
3142
+** database.
3143
+**
3144
+** (3) When opening a file that ends with the appendvfs trailer string
3145
+** "Start-Of-SQLite3-NNNNNNNN" that file is treated as an appended
3146
+** database.
3147
+**
3148
+** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
3149
+** set, then a new database is appended to the already existing file.
3150
+**
3151
+** (5) Otherwise, SQLITE_CANTOPEN is returned.
3152
+**
3153
+** To avoid unnecessary complications with the PENDING_BYTE, the size of
3154
+** the file containing the database is limited to 1GB. This VFS will refuse
3155
+** to read or write past the 1GB mark. This restriction might be lifted in
3156
+** future versions. For now, if you need a large database, then keep the
3157
+** database in a separate file.
3158
+**
3159
+** If the file being opened is not an appended database, then this shim is
3160
+** a pass-through into the default underlying VFS.
3161
+**/
3162
+SQLITE_EXTENSION_INIT1
3163
+#include <string.h>
3164
+#include <assert.h>
3165
+
3166
+/* The append mark at the end of the database is:
3167
+**
3168
+** Start-Of-SQLite3-NNNNNNNN
3169
+** 123456789 123456789 12345
3170
+**
3171
+** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
3172
+** the offset to page 1.
3173
+*/
3174
+#define APND_MARK_PREFIX "Start-Of-SQLite3-"
3175
+#define APND_MARK_PREFIX_SZ 17
3176
+#define APND_MARK_SIZE 25
3177
+
3178
+/*
3179
+** Maximum size of the combined prefix + database + append-mark. This
3180
+** must be less than 0x40000000 to avoid locking issues on Windows.
3181
+*/
3182
+#define APND_MAX_SIZE (65536*15259)
3183
+
3184
+/*
3185
+** Forward declaration of objects used by this utility
3186
+*/
3187
+typedef struct sqlite3_vfs ApndVfs;
3188
+typedef struct ApndFile ApndFile;
3189
+
3190
+/* Access to a lower-level VFS that (might) implement dynamic loading,
3191
+** access to randomness, etc.
3192
+*/
3193
+#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
3194
+#define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
3195
+
3196
+/* An open file */
3197
+struct ApndFile {
3198
+ sqlite3_file base; /* IO methods */
3199
+ sqlite3_int64 iPgOne; /* File offset to page 1 */
3200
+ sqlite3_int64 iMark; /* Start of the append-mark */
3201
+};
3202
+
3203
+/*
3204
+** Methods for ApndFile
3205
+*/
3206
+static int apndClose(sqlite3_file*);
3207
+static int apndRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
3208
+static int apndWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
3209
+static int apndTruncate(sqlite3_file*, sqlite3_int64 size);
3210
+static int apndSync(sqlite3_file*, int flags);
3211
+static int apndFileSize(sqlite3_file*, sqlite3_int64 *pSize);
3212
+static int apndLock(sqlite3_file*, int);
3213
+static int apndUnlock(sqlite3_file*, int);
3214
+static int apndCheckReservedLock(sqlite3_file*, int *pResOut);
3215
+static int apndFileControl(sqlite3_file*, int op, void *pArg);
3216
+static int apndSectorSize(sqlite3_file*);
3217
+static int apndDeviceCharacteristics(sqlite3_file*);
3218
+static int apndShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
3219
+static int apndShmLock(sqlite3_file*, int offset, int n, int flags);
3220
+static void apndShmBarrier(sqlite3_file*);
3221
+static int apndShmUnmap(sqlite3_file*, int deleteFlag);
3222
+static int apndFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
3223
+static int apndUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p);
3224
+
3225
+/*
3226
+** Methods for ApndVfs
3227
+*/
3228
+static int apndOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
3229
+static int apndDelete(sqlite3_vfs*, const char *zName, int syncDir);
3230
+static int apndAccess(sqlite3_vfs*, const char *zName, int flags, int *);
3231
+static int apndFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
3232
+static void *apndDlOpen(sqlite3_vfs*, const char *zFilename);
3233
+static void apndDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
3234
+static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void);
3235
+static void apndDlClose(sqlite3_vfs*, void*);
3236
+static int apndRandomness(sqlite3_vfs*, int nByte, char *zOut);
3237
+static int apndSleep(sqlite3_vfs*, int microseconds);
3238
+static int apndCurrentTime(sqlite3_vfs*, double*);
3239
+static int apndGetLastError(sqlite3_vfs*, int, char *);
3240
+static int apndCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*);
3241
+static int apndSetSystemCall(sqlite3_vfs*, const char*,sqlite3_syscall_ptr);
3242
+static sqlite3_syscall_ptr apndGetSystemCall(sqlite3_vfs*, const char *z);
3243
+static const char *apndNextSystemCall(sqlite3_vfs*, const char *zName);
3244
+
3245
+static sqlite3_vfs apnd_vfs = {
3246
+ 3, /* iVersion (set when registered) */
3247
+ 0, /* szOsFile (set when registered) */
3248
+ 1024, /* mxPathname */
3249
+ 0, /* pNext */
3250
+ "apndvfs", /* zName */
3251
+ 0, /* pAppData (set when registered) */
3252
+ apndOpen, /* xOpen */
3253
+ apndDelete, /* xDelete */
3254
+ apndAccess, /* xAccess */
3255
+ apndFullPathname, /* xFullPathname */
3256
+ apndDlOpen, /* xDlOpen */
3257
+ apndDlError, /* xDlError */
3258
+ apndDlSym, /* xDlSym */
3259
+ apndDlClose, /* xDlClose */
3260
+ apndRandomness, /* xRandomness */
3261
+ apndSleep, /* xSleep */
3262
+ apndCurrentTime, /* xCurrentTime */
3263
+ apndGetLastError, /* xGetLastError */
3264
+ apndCurrentTimeInt64, /* xCurrentTimeInt64 */
3265
+ apndSetSystemCall, /* xSetSystemCall */
3266
+ apndGetSystemCall, /* xGetSystemCall */
3267
+ apndNextSystemCall /* xNextSystemCall */
3268
+};
3269
+
3270
+static const sqlite3_io_methods apnd_io_methods = {
3271
+ 3, /* iVersion */
3272
+ apndClose, /* xClose */
3273
+ apndRead, /* xRead */
3274
+ apndWrite, /* xWrite */
3275
+ apndTruncate, /* xTruncate */
3276
+ apndSync, /* xSync */
3277
+ apndFileSize, /* xFileSize */
3278
+ apndLock, /* xLock */
3279
+ apndUnlock, /* xUnlock */
3280
+ apndCheckReservedLock, /* xCheckReservedLock */
3281
+ apndFileControl, /* xFileControl */
3282
+ apndSectorSize, /* xSectorSize */
3283
+ apndDeviceCharacteristics, /* xDeviceCharacteristics */
3284
+ apndShmMap, /* xShmMap */
3285
+ apndShmLock, /* xShmLock */
3286
+ apndShmBarrier, /* xShmBarrier */
3287
+ apndShmUnmap, /* xShmUnmap */
3288
+ apndFetch, /* xFetch */
3289
+ apndUnfetch /* xUnfetch */
3290
+};
3291
+
3292
+
3293
+
3294
+/*
3295
+** Close an apnd-file.
3296
+*/
3297
+static int apndClose(sqlite3_file *pFile){
3298
+ pFile = ORIGFILE(pFile);
3299
+ return pFile->pMethods->xClose(pFile);
3300
+}
3301
+
3302
+/*
3303
+** Read data from an apnd-file.
3304
+*/
3305
+static int apndRead(
3306
+ sqlite3_file *pFile,
3307
+ void *zBuf,
3308
+ int iAmt,
3309
+ sqlite_int64 iOfst
3310
+){
3311
+ ApndFile *p = (ApndFile *)pFile;
3312
+ pFile = ORIGFILE(pFile);
3313
+ return pFile->pMethods->xRead(pFile, zBuf, iAmt, iOfst+p->iPgOne);
3314
+}
3315
+
3316
+/*
3317
+** Add the append-mark onto the end of the file.
3318
+*/
3319
+static int apndWriteMark(ApndFile *p, sqlite3_file *pFile){
3320
+ int i;
3321
+ unsigned char a[APND_MARK_SIZE];
3322
+ memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3323
+ for(i=0; i<8; i++){
3324
+ a[APND_MARK_PREFIX_SZ+i] = (p->iPgOne >> (56 - i*8)) & 0xff;
3325
+ }
3326
+ return pFile->pMethods->xWrite(pFile, a, APND_MARK_SIZE, p->iMark);
3327
+}
3328
+
3329
+/*
3330
+** Write data to an apnd-file.
3331
+*/
3332
+static int apndWrite(
3333
+ sqlite3_file *pFile,
3334
+ const void *zBuf,
3335
+ int iAmt,
3336
+ sqlite_int64 iOfst
3337
+){
3338
+ int rc;
3339
+ ApndFile *p = (ApndFile *)pFile;
3340
+ pFile = ORIGFILE(pFile);
3341
+ if( iOfst+iAmt>=APND_MAX_SIZE ) return SQLITE_FULL;
3342
+ rc = pFile->pMethods->xWrite(pFile, zBuf, iAmt, iOfst+p->iPgOne);
3343
+ if( rc==SQLITE_OK && iOfst + iAmt + p->iPgOne > p->iMark ){
3344
+ sqlite3_int64 sz = 0;
3345
+ rc = pFile->pMethods->xFileSize(pFile, &sz);
3346
+ if( rc==SQLITE_OK ){
3347
+ p->iMark = sz - APND_MARK_SIZE;
3348
+ if( iOfst + iAmt + p->iPgOne > p->iMark ){
3349
+ p->iMark = p->iPgOne + iOfst + iAmt;
3350
+ rc = apndWriteMark(p, pFile);
3351
+ }
3352
+ }
3353
+ }
3354
+ return rc;
3355
+}
3356
+
3357
+/*
3358
+** Truncate an apnd-file.
3359
+*/
3360
+static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
3361
+ int rc;
3362
+ ApndFile *p = (ApndFile *)pFile;
3363
+ pFile = ORIGFILE(pFile);
3364
+ rc = pFile->pMethods->xTruncate(pFile, size+p->iPgOne+APND_MARK_SIZE);
3365
+ if( rc==SQLITE_OK ){
3366
+ p->iMark = p->iPgOne+size;
3367
+ rc = apndWriteMark(p, pFile);
3368
+ }
3369
+ return rc;
3370
+}
3371
+
3372
+/*
3373
+** Sync an apnd-file.
3374
+*/
3375
+static int apndSync(sqlite3_file *pFile, int flags){
3376
+ pFile = ORIGFILE(pFile);
3377
+ return pFile->pMethods->xSync(pFile, flags);
3378
+}
3379
+
3380
+/*
3381
+** Return the current file-size of an apnd-file.
3382
+*/
3383
+static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
3384
+ ApndFile *p = (ApndFile *)pFile;
3385
+ int rc;
3386
+ pFile = ORIGFILE(p);
3387
+ rc = pFile->pMethods->xFileSize(pFile, pSize);
3388
+ if( rc==SQLITE_OK && p->iPgOne ){
3389
+ *pSize -= p->iPgOne + APND_MARK_SIZE;
3390
+ }
3391
+ return rc;
3392
+}
3393
+
3394
+/*
3395
+** Lock an apnd-file.
3396
+*/
3397
+static int apndLock(sqlite3_file *pFile, int eLock){
3398
+ pFile = ORIGFILE(pFile);
3399
+ return pFile->pMethods->xLock(pFile, eLock);
3400
+}
3401
+
3402
+/*
3403
+** Unlock an apnd-file.
3404
+*/
3405
+static int apndUnlock(sqlite3_file *pFile, int eLock){
3406
+ pFile = ORIGFILE(pFile);
3407
+ return pFile->pMethods->xUnlock(pFile, eLock);
3408
+}
3409
+
3410
+/*
3411
+** Check if another file-handle holds a RESERVED lock on an apnd-file.
3412
+*/
3413
+static int apndCheckReservedLock(sqlite3_file *pFile, int *pResOut){
3414
+ pFile = ORIGFILE(pFile);
3415
+ return pFile->pMethods->xCheckReservedLock(pFile, pResOut);
3416
+}
3417
+
3418
+/*
3419
+** File control method. For custom operations on an apnd-file.
3420
+*/
3421
+static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
3422
+ ApndFile *p = (ApndFile *)pFile;
3423
+ int rc;
3424
+ pFile = ORIGFILE(pFile);
3425
+ rc = pFile->pMethods->xFileControl(pFile, op, pArg);
3426
+ if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
3427
+ *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", p->iPgOne, *(char**)pArg);
3428
+ }
3429
+ return rc;
3430
+}
3431
+
3432
+/*
3433
+** Return the sector-size in bytes for an apnd-file.
3434
+*/
3435
+static int apndSectorSize(sqlite3_file *pFile){
3436
+ pFile = ORIGFILE(pFile);
3437
+ return pFile->pMethods->xSectorSize(pFile);
3438
+}
3439
+
3440
+/*
3441
+** Return the device characteristic flags supported by an apnd-file.
3442
+*/
3443
+static int apndDeviceCharacteristics(sqlite3_file *pFile){
3444
+ pFile = ORIGFILE(pFile);
3445
+ return pFile->pMethods->xDeviceCharacteristics(pFile);
3446
+}
3447
+
3448
+/* Create a shared memory file mapping */
3449
+static int apndShmMap(
3450
+ sqlite3_file *pFile,
3451
+ int iPg,
3452
+ int pgsz,
3453
+ int bExtend,
3454
+ void volatile **pp
3455
+){
3456
+ pFile = ORIGFILE(pFile);
3457
+ return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp);
3458
+}
3459
+
3460
+/* Perform locking on a shared-memory segment */
3461
+static int apndShmLock(sqlite3_file *pFile, int offset, int n, int flags){
3462
+ pFile = ORIGFILE(pFile);
3463
+ return pFile->pMethods->xShmLock(pFile,offset,n,flags);
3464
+}
3465
+
3466
+/* Memory barrier operation on shared memory */
3467
+static void apndShmBarrier(sqlite3_file *pFile){
3468
+ pFile = ORIGFILE(pFile);
3469
+ pFile->pMethods->xShmBarrier(pFile);
3470
+}
3471
+
3472
+/* Unmap a shared memory segment */
3473
+static int apndShmUnmap(sqlite3_file *pFile, int deleteFlag){
3474
+ pFile = ORIGFILE(pFile);
3475
+ return pFile->pMethods->xShmUnmap(pFile,deleteFlag);
3476
+}
3477
+
3478
+/* Fetch a page of a memory-mapped file */
3479
+static int apndFetch(
3480
+ sqlite3_file *pFile,
3481
+ sqlite3_int64 iOfst,
3482
+ int iAmt,
3483
+ void **pp
3484
+){
3485
+ ApndFile *p = (ApndFile *)pFile;
3486
+ pFile = ORIGFILE(pFile);
3487
+ return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
3488
+}
3489
+
3490
+/* Release a memory-mapped page */
3491
+static int apndUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
3492
+ ApndFile *p = (ApndFile *)pFile;
3493
+ pFile = ORIGFILE(pFile);
3494
+ return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
3495
+}
3496
+
3497
+/*
3498
+** Check to see if the file is an ordinary SQLite database file.
3499
+*/
3500
+static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
3501
+ int rc;
3502
+ char zHdr[16];
3503
+ static const char aSqliteHdr[] = "SQLite format 3";
3504
+ if( sz<512 ) return 0;
3505
+ rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0);
3506
+ if( rc ) return 0;
3507
+ return memcmp(zHdr, aSqliteHdr, sizeof(zHdr))==0;
3508
+}
3509
+
3510
+/*
3511
+** Try to read the append-mark off the end of a file. Return the
3512
+** start of the appended database if the append-mark is present. If
3513
+** there is no append-mark, return -1;
3514
+*/
3515
+static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
3516
+ int rc, i;
3517
+ sqlite3_int64 iMark;
3518
+ unsigned char a[APND_MARK_SIZE];
3519
+
3520
+ if( sz<=APND_MARK_SIZE ) return -1;
3521
+ rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
3522
+ if( rc ) return -1;
3523
+ if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
3524
+ iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ]&0x7f))<<56;
3525
+ for(i=1; i<8; i++){
3526
+ iMark += (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<(56-8*i);
3527
+ }
3528
+ return iMark;
3529
+}
3530
+
3531
+/*
3532
+** Open an apnd file handle.
3533
+*/
3534
+static int apndOpen(
3535
+ sqlite3_vfs *pVfs,
3536
+ const char *zName,
3537
+ sqlite3_file *pFile,
3538
+ int flags,
3539
+ int *pOutFlags
3540
+){
3541
+ ApndFile *p;
3542
+ sqlite3_file *pSubFile;
3543
+ sqlite3_vfs *pSubVfs;
3544
+ int rc;
3545
+ sqlite3_int64 sz;
3546
+ pSubVfs = ORIGVFS(pVfs);
3547
+ if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
3548
+ return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
3549
+ }
3550
+ p = (ApndFile*)pFile;
3551
+ memset(p, 0, sizeof(*p));
3552
+ pSubFile = ORIGFILE(pFile);
3553
+ p->base.pMethods = &apnd_io_methods;
3554
+ rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
3555
+ if( rc ) goto apnd_open_done;
3556
+ rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
3557
+ if( rc ){
3558
+ pSubFile->pMethods->xClose(pSubFile);
3559
+ goto apnd_open_done;
3560
+ }
3561
+ if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
3562
+ memmove(pFile, pSubFile, pSubVfs->szOsFile);
3563
+ return SQLITE_OK;
3564
+ }
3565
+ p->iMark = 0;
3566
+ p->iPgOne = apndReadMark(sz, pFile);
3567
+ if( p->iPgOne>0 ){
3568
+ return SQLITE_OK;
3569
+ }
3570
+ if( (flags & SQLITE_OPEN_CREATE)==0 ){
3571
+ pSubFile->pMethods->xClose(pSubFile);
3572
+ rc = SQLITE_CANTOPEN;
3573
+ }
3574
+ p->iPgOne = (sz+0xfff) & ~(sqlite3_int64)0xfff;
3575
+apnd_open_done:
3576
+ if( rc ) pFile->pMethods = 0;
3577
+ return rc;
3578
+}
3579
+
3580
+/*
3581
+** All other VFS methods are pass-thrus.
3582
+*/
3583
+static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
3584
+ return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
3585
+}
3586
+static int apndAccess(
3587
+ sqlite3_vfs *pVfs,
3588
+ const char *zPath,
3589
+ int flags,
3590
+ int *pResOut
3591
+){
3592
+ return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
3593
+}
3594
+static int apndFullPathname(
3595
+ sqlite3_vfs *pVfs,
3596
+ const char *zPath,
3597
+ int nOut,
3598
+ char *zOut
3599
+){
3600
+ return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
3601
+}
3602
+static void *apndDlOpen(sqlite3_vfs *pVfs, const char *zPath){
3603
+ return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath);
3604
+}
3605
+static void apndDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
3606
+ ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg);
3607
+}
3608
+static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
3609
+ return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym);
3610
+}
3611
+static void apndDlClose(sqlite3_vfs *pVfs, void *pHandle){
3612
+ ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle);
3613
+}
3614
+static int apndRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
3615
+ return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut);
3616
+}
3617
+static int apndSleep(sqlite3_vfs *pVfs, int nMicro){
3618
+ return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro);
3619
+}
3620
+static int apndCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
3621
+ return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut);
3622
+}
3623
+static int apndGetLastError(sqlite3_vfs *pVfs, int a, char *b){
3624
+ return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
3625
+}
3626
+static int apndCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
3627
+ return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p);
3628
+}
3629
+static int apndSetSystemCall(
3630
+ sqlite3_vfs *pVfs,
3631
+ const char *zName,
3632
+ sqlite3_syscall_ptr pCall
3633
+){
3634
+ return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall);
3635
+}
3636
+static sqlite3_syscall_ptr apndGetSystemCall(
3637
+ sqlite3_vfs *pVfs,
3638
+ const char *zName
3639
+){
3640
+ return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName);
3641
+}
3642
+static const char *apndNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
3643
+ return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
3644
+}
3645
+
3646
+
3647
+#ifdef _WIN32
3648
+
3649
+#endif
3650
+/*
3651
+** This routine is called when the extension is loaded.
3652
+** Register the new VFS.
3653
+*/
3654
+int sqlite3_appendvfs_init(
3655
+ sqlite3 *db,
3656
+ char **pzErrMsg,
3657
+ const sqlite3_api_routines *pApi
3658
+){
3659
+ int rc = SQLITE_OK;
3660
+ sqlite3_vfs *pOrig;
3661
+ SQLITE_EXTENSION_INIT2(pApi);
3662
+ pOrig = sqlite3_vfs_find(0);
3663
+ apnd_vfs.iVersion = pOrig->iVersion;
3664
+ apnd_vfs.pAppData = pOrig;
3665
+ apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
3666
+ rc = sqlite3_vfs_register(&apnd_vfs, 0);
3667
+#ifdef APPENDVFS_TEST
3668
+ if( rc==SQLITE_OK ){
3669
+ rc = sqlite3_auto_extension((void(*)(void))apndvfsRegister);
3670
+ }
3671
+#endif
3672
+ if( rc==SQLITE_OK ) rc = SQLITE_OK_LOAD_PERMANENTLY;
3673
+ return rc;
3674
+}
3675
+
3676
+/************************* End ../ext/misc/appendvfs.c ********************/
3677
+#ifdef SQLITE_HAVE_ZLIB
3678
+/************************* Begin ../ext/misc/zipfile.c ******************/
3679
+/*
3680
+** 2017-12-26
3681
+**
3682
+** The author disclaims copyright to this source code. In place of
3683
+** a legal notice, here is a blessing:
3684
+**
3685
+** May you do good and not evil.
3686
+** May you find forgiveness for yourself and forgive others.
3687
+** May you share freely, never taking more than you give.
3688
+**
3689
+******************************************************************************
3690
+**
3691
+*/
3692
+SQLITE_EXTENSION_INIT1
3693
+#include <stdio.h>
3694
+#include <string.h>
3695
+#include <assert.h>
3696
+
3697
+#include <sys/types.h>
3698
+#include <sys/stat.h>
3699
+#include <fcntl.h>
3700
+#if !defined(_WIN32) && !defined(WIN32)
3701
+# include <unistd.h>
3702
+# include <dirent.h>
3703
+# include <utime.h>
3704
+#else
3705
+# include <io.h>
3706
+#endif
3707
+#include <time.h>
3708
+#include <errno.h>
3709
+
3710
+#include <zlib.h>
3711
+
3712
+#ifndef SQLITE_OMIT_VIRTUALTABLE
3713
+
3714
+#ifndef SQLITE_AMALGAMATION
3715
+/* typedef sqlite3_int64 i64; */
3716
+/* typedef unsigned char u8; */
3717
+typedef unsigned short u16;
3718
+typedef unsigned long u32;
3719
+#define MIN(a,b) ((a)<(b) ? (a) : (b))
3720
+#endif
3721
+
3722
+#define ZIPFILE_SCHEMA "CREATE TABLE y(" \
3723
+ "name, /* Name of file in zip archive */" \
3724
+ "mode, /* POSIX mode for file */" \
3725
+ "mtime, /* Last modification time in seconds since epoch */" \
3726
+ "sz, /* Size of object */" \
3727
+ "data, /* Data stored in zip file (possibly compressed) */" \
3728
+ "method, /* Compression method (integer) */" \
3729
+ "f HIDDEN /* Name of zip file */" \
3730
+");"
3731
+
3732
+#define ZIPFILE_F_COLUMN_IDX 6 /* Index of column "f" in the above */
3733
+#define ZIPFILE_BUFFER_SIZE (64*1024)
3734
+
3735
+
3736
+/*
3737
+** Magic numbers used to read and write zip files.
3738
+**
3739
+** ZIPFILE_NEWENTRY_MADEBY:
3740
+** Use this value for the "version-made-by" field in new zip file
3741
+** entries. The upper byte indicates "unix", and the lower byte
3742
+** indicates that the zip file matches pkzip specification 3.0.
3743
+** This is what info-zip seems to do.
3744
+**
3745
+** ZIPFILE_NEWENTRY_REQUIRED:
3746
+** Value for "version-required-to-extract" field of new entries.
3747
+** Version 2.0 is required to support folders and deflate compression.
3748
+**
3749
+** ZIPFILE_NEWENTRY_FLAGS:
3750
+** Value for "general-purpose-bit-flags" field of new entries. Bit
3751
+** 11 means "utf-8 filename and comment".
3752
+**
3753
+** ZIPFILE_SIGNATURE_CDS:
3754
+** First 4 bytes of a valid CDS record.
3755
+**
3756
+** ZIPFILE_SIGNATURE_LFH:
3757
+** First 4 bytes of a valid LFH record.
3758
+*/
3759
+#define ZIPFILE_EXTRA_TIMESTAMP 0x5455
3760
+#define ZIPFILE_NEWENTRY_MADEBY ((3<<8) + 30)
3761
+#define ZIPFILE_NEWENTRY_REQUIRED 20
3762
+#define ZIPFILE_NEWENTRY_FLAGS 0x800
3763
+#define ZIPFILE_SIGNATURE_CDS 0x02014b50
3764
+#define ZIPFILE_SIGNATURE_LFH 0x04034b50
3765
+#define ZIPFILE_SIGNATURE_EOCD 0x06054b50
3766
+#define ZIPFILE_LFH_FIXED_SZ 30
3767
+
3768
+/*
3769
+** Set the error message contained in context ctx to the results of
3770
+** vprintf(zFmt, ...).
3771
+*/
3772
+static void zipfileCtxErrorMsg(sqlite3_context *ctx, const char *zFmt, ...){
3773
+ char *zMsg = 0;
3774
+ va_list ap;
3775
+ va_start(ap, zFmt);
3776
+ zMsg = sqlite3_vmprintf(zFmt, ap);
3777
+ sqlite3_result_error(ctx, zMsg, -1);
3778
+ sqlite3_free(zMsg);
3779
+ va_end(ap);
3780
+}
3781
+
3782
+
3783
+/*
3784
+*** 4.3.16 End of central directory record:
3785
+***
3786
+*** end of central dir signature 4 bytes (0x06054b50)
3787
+*** number of this disk 2 bytes
3788
+*** number of the disk with the
3789
+*** start of the central directory 2 bytes
3790
+*** total number of entries in the
3791
+*** central directory on this disk 2 bytes
3792
+*** total number of entries in
3793
+*** the central directory 2 bytes
3794
+*** size of the central directory 4 bytes
3795
+*** offset of start of central
3796
+*** directory with respect to
3797
+*** the starting disk number 4 bytes
3798
+*** .ZIP file comment length 2 bytes
3799
+*** .ZIP file comment (variable size)
3800
+*/
3801
+typedef struct ZipfileEOCD ZipfileEOCD;
3802
+struct ZipfileEOCD {
3803
+ u16 iDisk;
3804
+ u16 iFirstDisk;
3805
+ u16 nEntry;
3806
+ u16 nEntryTotal;
3807
+ u32 nSize;
3808
+ u32 iOffset;
3809
+};
3810
+
3811
+/*
3812
+*** 4.3.12 Central directory structure:
3813
+***
3814
+*** ...
3815
+***
3816
+*** central file header signature 4 bytes (0x02014b50)
3817
+*** version made by 2 bytes
3818
+*** version needed to extract 2 bytes
3819
+*** general purpose bit flag 2 bytes
3820
+*** compression method 2 bytes
3821
+*** last mod file time 2 bytes
3822
+*** last mod file date 2 bytes
3823
+*** crc-32 4 bytes
3824
+*** compressed size 4 bytes
3825
+*** uncompressed size 4 bytes
3826
+*** file name length 2 bytes
3827
+*** extra field length 2 bytes
3828
+*** file comment length 2 bytes
3829
+*** disk number start 2 bytes
3830
+*** internal file attributes 2 bytes
3831
+*** external file attributes 4 bytes
3832
+*** relative offset of local header 4 bytes
3833
+*/
3834
+typedef struct ZipfileCDS ZipfileCDS;
3835
+struct ZipfileCDS {
3836
+ u16 iVersionMadeBy;
3837
+ u16 iVersionExtract;
3838
+ u16 flags;
3839
+ u16 iCompression;
3840
+ u16 mTime;
3841
+ u16 mDate;
3842
+ u32 crc32;
3843
+ u32 szCompressed;
3844
+ u32 szUncompressed;
3845
+ u16 nFile;
3846
+ u16 nExtra;
3847
+ u16 nComment;
3848
+ u16 iDiskStart;
3849
+ u16 iInternalAttr;
3850
+ u32 iExternalAttr;
3851
+ u32 iOffset;
3852
+ char *zFile; /* Filename (sqlite3_malloc()) */
3853
+};
3854
+
3855
+/*
3856
+*** 4.3.7 Local file header:
3857
+***
3858
+*** local file header signature 4 bytes (0x04034b50)
3859
+*** version needed to extract 2 bytes
3860
+*** general purpose bit flag 2 bytes
3861
+*** compression method 2 bytes
3862
+*** last mod file time 2 bytes
3863
+*** last mod file date 2 bytes
3864
+*** crc-32 4 bytes
3865
+*** compressed size 4 bytes
3866
+*** uncompressed size 4 bytes
3867
+*** file name length 2 bytes
3868
+*** extra field length 2 bytes
3869
+***
3870
+*/
3871
+typedef struct ZipfileLFH ZipfileLFH;
3872
+struct ZipfileLFH {
3873
+ u16 iVersionExtract;
3874
+ u16 flags;
3875
+ u16 iCompression;
3876
+ u16 mTime;
3877
+ u16 mDate;
3878
+ u32 crc32;
3879
+ u32 szCompressed;
3880
+ u32 szUncompressed;
3881
+ u16 nFile;
3882
+ u16 nExtra;
3883
+};
3884
+
3885
+typedef struct ZipfileEntry ZipfileEntry;
3886
+struct ZipfileEntry {
3887
+ char *zPath; /* Path of zipfile entry */
3888
+ i64 iRowid; /* Rowid for this value if queried */
3889
+ u8 *aCdsEntry; /* Buffer containing entire CDS entry */
3890
+ int nCdsEntry; /* Size of buffer aCdsEntry[] in bytes */
3891
+ int bDeleted; /* True if entry has been deleted */
3892
+ ZipfileEntry *pNext; /* Next element in in-memory CDS */
3893
+};
3894
+
3895
+/*
3896
+** Cursor type for recursively iterating through a directory structure.
3897
+*/
3898
+typedef struct ZipfileCsr ZipfileCsr;
3899
+struct ZipfileCsr {
3900
+ sqlite3_vtab_cursor base; /* Base class - must be first */
3901
+ int bEof; /* True when at EOF */
3902
+
3903
+ /* Used outside of write transactions */
3904
+ FILE *pFile; /* Zip file */
3905
+ i64 iNextOff; /* Offset of next record in central directory */
3906
+ ZipfileEOCD eocd; /* Parse of central directory record */
3907
+
3908
+ /* Used inside write transactions */
3909
+ ZipfileEntry *pCurrent;
3910
+
3911
+ ZipfileCDS cds; /* Central Directory Structure */
3912
+ ZipfileLFH lfh; /* Local File Header for current entry */
3913
+ i64 iDataOff; /* Offset in zipfile to data */
3914
+ u32 mTime; /* Extended mtime value */
3915
+ int flags; /* Flags byte (see below for bits) */
3916
+ ZipfileCsr *pCsrNext; /* Next cursor on same virtual table */
3917
+};
3918
+
3919
+/*
3920
+** Values for ZipfileCsr.flags.
3921
+*/
3922
+#define ZIPFILE_MTIME_VALID 0x0001
3923
+
3924
+typedef struct ZipfileTab ZipfileTab;
3925
+struct ZipfileTab {
3926
+ sqlite3_vtab base; /* Base class - must be first */
3927
+ char *zFile; /* Zip file this table accesses (may be NULL) */
3928
+ u8 *aBuffer; /* Temporary buffer used for various tasks */
3929
+
3930
+ /* The following are used by write transactions only */
3931
+ ZipfileCsr *pCsrList; /* List of cursors */
3932
+ ZipfileEntry *pFirstEntry; /* Linked list of all files (if pWriteFd!=0) */
3933
+ ZipfileEntry *pLastEntry; /* Last element in pFirstEntry list */
3934
+ FILE *pWriteFd; /* File handle open on zip archive */
3935
+ i64 szCurrent; /* Current size of zip archive */
3936
+ i64 szOrig; /* Size of archive at start of transaction */
3937
+};
3938
+
3939
+static void zipfileDequote(char *zIn){
3940
+ char q = zIn[0];
3941
+ if( q=='"' || q=='\'' || q=='`' || q=='[' ){
3942
+ char c;
3943
+ int iIn = 1;
3944
+ int iOut = 0;
3945
+ if( q=='[' ) q = ']';
3946
+ while( (c = zIn[iIn++]) ){
3947
+ if( c==q ){
3948
+ if( zIn[iIn++]!=q ) break;
3949
+ }
3950
+ zIn[iOut++] = c;
3951
+ }
3952
+ zIn[iOut] = '\0';
3953
+ }
3954
+}
3955
+
3956
+/*
3957
+** Construct a new ZipfileTab virtual table object.
3958
+**
3959
+** argv[0] -> module name ("zipfile")
3960
+** argv[1] -> database name
3961
+** argv[2] -> table name
3962
+** argv[...] -> "column name" and other module argument fields.
3963
+*/
3964
+static int zipfileConnect(
3965
+ sqlite3 *db,
3966
+ void *pAux,
3967
+ int argc, const char *const*argv,
3968
+ sqlite3_vtab **ppVtab,
3969
+ char **pzErr
3970
+){
3971
+ int nByte = sizeof(ZipfileTab) + ZIPFILE_BUFFER_SIZE;
3972
+ int nFile = 0;
3973
+ const char *zFile = 0;
3974
+ ZipfileTab *pNew = 0;
3975
+ int rc;
3976
+
3977
+ if( argc>3 ){
3978
+ zFile = argv[3];
3979
+ nFile = (int)strlen(zFile)+1;
3980
+ }
3981
+
3982
+ rc = sqlite3_declare_vtab(db, ZIPFILE_SCHEMA);
3983
+ if( rc==SQLITE_OK ){
3984
+ pNew = (ZipfileTab*)sqlite3_malloc(nByte+nFile);
3985
+ if( pNew==0 ) return SQLITE_NOMEM;
3986
+ memset(pNew, 0, nByte+nFile);
3987
+ pNew->aBuffer = (u8*)&pNew[1];
3988
+ if( zFile ){
3989
+ pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
3990
+ memcpy(pNew->zFile, zFile, nFile);
3991
+ zipfileDequote(pNew->zFile);
3992
+ }
3993
+ }
3994
+ *ppVtab = (sqlite3_vtab*)pNew;
3995
+ return rc;
3996
+}
3997
+
3998
+/*
3999
+** This method is the destructor for zipfile vtab objects.
4000
+*/
4001
+static int zipfileDisconnect(sqlite3_vtab *pVtab){
4002
+ sqlite3_free(pVtab);
4003
+ return SQLITE_OK;
4004
+}
4005
+
4006
+/*
4007
+** Constructor for a new ZipfileCsr object.
4008
+*/
4009
+static int zipfileOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCsr){
4010
+ ZipfileCsr *pCsr;
4011
+ pCsr = sqlite3_malloc(sizeof(*pCsr));
4012
+ *ppCsr = (sqlite3_vtab_cursor*)pCsr;
4013
+ if( pCsr==0 ){
4014
+ return SQLITE_NOMEM;
4015
+ }
4016
+ memset(pCsr, 0, sizeof(*pCsr));
4017
+ return SQLITE_OK;
4018
+}
4019
+
4020
+/*
4021
+** Reset a cursor back to the state it was in when first returned
4022
+** by zipfileOpen().
4023
+*/
4024
+static void zipfileResetCursor(ZipfileCsr *pCsr){
4025
+ ZipfileTab *pTab = (ZipfileTab*)(pCsr->base.pVtab);
4026
+ ZipfileCsr **pp;
4027
+
4028
+ /* Remove this cursor from the ZipfileTab.pCsrList list. */
4029
+ for(pp=&pTab->pCsrList; *pp; pp=&((*pp)->pCsrNext)){
4030
+ if( *pp==pCsr ) *pp = pCsr->pCsrNext;
4031
+ }
4032
+
4033
+ sqlite3_free(pCsr->cds.zFile);
4034
+ pCsr->cds.zFile = 0;
4035
+ pCsr->bEof = 0;
4036
+ if( pCsr->pFile ){
4037
+ fclose(pCsr->pFile);
4038
+ pCsr->pFile = 0;
4039
+ }
4040
+}
4041
+
4042
+/*
4043
+** Destructor for an ZipfileCsr.
4044
+*/
4045
+static int zipfileClose(sqlite3_vtab_cursor *cur){
4046
+ ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4047
+ zipfileResetCursor(pCsr);
4048
+ sqlite3_free(pCsr);
4049
+ return SQLITE_OK;
4050
+}
4051
+
4052
+/*
4053
+** Set the error message for the virtual table associated with cursor
4054
+** pCsr to the results of vprintf(zFmt, ...).
4055
+*/
4056
+static void zipfileSetErrmsg(ZipfileCsr *pCsr, const char *zFmt, ...){
4057
+ va_list ap;
4058
+ va_start(ap, zFmt);
4059
+ pCsr->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
4060
+ va_end(ap);
4061
+}
4062
+
4063
+static int zipfileReadData(
4064
+ FILE *pFile, /* Read from this file */
4065
+ u8 *aRead, /* Read into this buffer */
4066
+ int nRead, /* Number of bytes to read */
4067
+ i64 iOff, /* Offset to read from */
4068
+ char **pzErrmsg /* OUT: Error message (from sqlite3_malloc) */
4069
+){
4070
+ size_t n;
4071
+ fseek(pFile, (long)iOff, SEEK_SET);
4072
+ n = fread(aRead, 1, nRead, pFile);
4073
+ if( (int)n!=nRead ){
4074
+ *pzErrmsg = sqlite3_mprintf("error in fread()");
4075
+ return SQLITE_ERROR;
4076
+ }
4077
+ return SQLITE_OK;
4078
+}
4079
+
4080
+static int zipfileAppendData(
4081
+ ZipfileTab *pTab,
4082
+ const u8 *aWrite,
4083
+ int nWrite
4084
+){
4085
+ size_t n;
4086
+ fseek(pTab->pWriteFd, (long)pTab->szCurrent, SEEK_SET);
4087
+ n = fwrite(aWrite, 1, nWrite, pTab->pWriteFd);
4088
+ if( (int)n!=nWrite ){
4089
+ pTab->base.zErrMsg = sqlite3_mprintf("error in fwrite()");
4090
+ return SQLITE_ERROR;
4091
+ }
4092
+ pTab->szCurrent += nWrite;
4093
+ return SQLITE_OK;
4094
+}
4095
+
4096
+static u16 zipfileGetU16(const u8 *aBuf){
4097
+ return (aBuf[1] << 8) + aBuf[0];
4098
+}
4099
+static u32 zipfileGetU32(const u8 *aBuf){
4100
+ return ((u32)(aBuf[3]) << 24)
4101
+ + ((u32)(aBuf[2]) << 16)
4102
+ + ((u32)(aBuf[1]) << 8)
4103
+ + ((u32)(aBuf[0]) << 0);
4104
+}
4105
+
4106
+static void zipfilePutU16(u8 *aBuf, u16 val){
4107
+ aBuf[0] = val & 0xFF;
4108
+ aBuf[1] = (val>>8) & 0xFF;
4109
+}
4110
+static void zipfilePutU32(u8 *aBuf, u32 val){
4111
+ aBuf[0] = val & 0xFF;
4112
+ aBuf[1] = (val>>8) & 0xFF;
4113
+ aBuf[2] = (val>>16) & 0xFF;
4114
+ aBuf[3] = (val>>24) & 0xFF;
4115
+}
4116
+
4117
+#define zipfileRead32(aBuf) ( aBuf+=4, zipfileGetU32(aBuf-4) )
4118
+#define zipfileRead16(aBuf) ( aBuf+=2, zipfileGetU16(aBuf-2) )
4119
+
4120
+#define zipfileWrite32(aBuf,val) { zipfilePutU32(aBuf,val); aBuf+=4; }
4121
+#define zipfileWrite16(aBuf,val) { zipfilePutU16(aBuf,val); aBuf+=2; }
4122
+
4123
+static u8* zipfileCsrBuffer(ZipfileCsr *pCsr){
4124
+ return ((ZipfileTab*)(pCsr->base.pVtab))->aBuffer;
4125
+}
4126
+
4127
+/*
4128
+** Magic numbers used to read CDS records.
4129
+*/
4130
+#define ZIPFILE_CDS_FIXED_SZ 46
4131
+#define ZIPFILE_CDS_NFILE_OFF 28
4132
+
4133
+static int zipfileReadCDS(ZipfileCsr *pCsr){
4134
+ char **pzErr = &pCsr->base.pVtab->zErrMsg;
4135
+ u8 *aRead;
4136
+ int rc = SQLITE_OK;
4137
+
4138
+ sqlite3_free(pCsr->cds.zFile);
4139
+ pCsr->cds.zFile = 0;
4140
+
4141
+ if( pCsr->pCurrent==0 ){
4142
+ aRead = zipfileCsrBuffer(pCsr);
4143
+ rc = zipfileReadData(
4144
+ pCsr->pFile, aRead, ZIPFILE_CDS_FIXED_SZ, pCsr->iNextOff, pzErr
4145
+ );
4146
+ }else{
4147
+ aRead = pCsr->pCurrent->aCdsEntry;
4148
+ }
4149
+
4150
+ if( rc==SQLITE_OK ){
4151
+ u32 sig = zipfileRead32(aRead);
4152
+ if( sig!=ZIPFILE_SIGNATURE_CDS ){
4153
+ assert( pCsr->pCurrent==0 );
4154
+ zipfileSetErrmsg(pCsr,"failed to read CDS at offset %lld",pCsr->iNextOff);
4155
+ rc = SQLITE_ERROR;
4156
+ }else{
4157
+ int nRead;
4158
+ pCsr->cds.iVersionMadeBy = zipfileRead16(aRead);
4159
+ pCsr->cds.iVersionExtract = zipfileRead16(aRead);
4160
+ pCsr->cds.flags = zipfileRead16(aRead);
4161
+ pCsr->cds.iCompression = zipfileRead16(aRead);
4162
+ pCsr->cds.mTime = zipfileRead16(aRead);
4163
+ pCsr->cds.mDate = zipfileRead16(aRead);
4164
+ pCsr->cds.crc32 = zipfileRead32(aRead);
4165
+ pCsr->cds.szCompressed = zipfileRead32(aRead);
4166
+ pCsr->cds.szUncompressed = zipfileRead32(aRead);
4167
+ assert( pCsr->pCurrent
4168
+ || aRead==zipfileCsrBuffer(pCsr)+ZIPFILE_CDS_NFILE_OFF
4169
+ );
4170
+ pCsr->cds.nFile = zipfileRead16(aRead);
4171
+ pCsr->cds.nExtra = zipfileRead16(aRead);
4172
+ pCsr->cds.nComment = zipfileRead16(aRead);
4173
+ pCsr->cds.iDiskStart = zipfileRead16(aRead);
4174
+ pCsr->cds.iInternalAttr = zipfileRead16(aRead);
4175
+ pCsr->cds.iExternalAttr = zipfileRead32(aRead);
4176
+ pCsr->cds.iOffset = zipfileRead32(aRead);
4177
+ assert( pCsr->pCurrent
4178
+ || aRead==zipfileCsrBuffer(pCsr)+ZIPFILE_CDS_FIXED_SZ
4179
+ );
4180
+
4181
+ if( pCsr->pCurrent==0 ){
4182
+ nRead = pCsr->cds.nFile + pCsr->cds.nExtra;
4183
+ aRead = zipfileCsrBuffer(pCsr);
4184
+ pCsr->iNextOff += ZIPFILE_CDS_FIXED_SZ;
4185
+ rc = zipfileReadData(pCsr->pFile, aRead, nRead, pCsr->iNextOff, pzErr);
4186
+ }
4187
+
4188
+ if( rc==SQLITE_OK ){
4189
+ pCsr->cds.zFile = sqlite3_mprintf("%.*s", (int)pCsr->cds.nFile, aRead);
4190
+ pCsr->iNextOff += pCsr->cds.nFile;
4191
+ pCsr->iNextOff += pCsr->cds.nExtra;
4192
+ pCsr->iNextOff += pCsr->cds.nComment;
4193
+ }
4194
+
4195
+ /* Scan the cds.nExtra bytes of "extra" fields for any that can
4196
+ ** be interpreted. The general format of an extra field is:
4197
+ **
4198
+ ** Header ID 2 bytes
4199
+ ** Data Size 2 bytes
4200
+ ** Data N bytes
4201
+ **
4202
+ */
4203
+ if( rc==SQLITE_OK ){
4204
+ u8 *p = &aRead[pCsr->cds.nFile];
4205
+ u8 *pEnd = &p[pCsr->cds.nExtra];
4206
+
4207
+ while( p<pEnd ){
4208
+ u16 id = zipfileRead16(p);
4209
+ u16 nByte = zipfileRead16(p);
4210
+
4211
+ switch( id ){
4212
+ case ZIPFILE_EXTRA_TIMESTAMP: {
4213
+ u8 b = p[0];
4214
+ if( b & 0x01 ){ /* 0x01 -> modtime is present */
4215
+ pCsr->mTime = zipfileGetU32(&p[1]);
4216
+ pCsr->flags |= ZIPFILE_MTIME_VALID;
4217
+ }
4218
+ break;
4219
+ }
4220
+ }
4221
+
4222
+ p += nByte;
4223
+ }
4224
+ }
4225
+ }
4226
+ }
4227
+
4228
+ return rc;
4229
+}
4230
+
4231
+static FILE *zipfileGetFd(ZipfileCsr *pCsr){
4232
+ if( pCsr->pFile ) return pCsr->pFile;
4233
+ return ((ZipfileTab*)(pCsr->base.pVtab))->pWriteFd;
4234
+}
4235
+
4236
+static int zipfileReadLFH(ZipfileCsr *pCsr){
4237
+ FILE *pFile = zipfileGetFd(pCsr);
4238
+ char **pzErr = &pCsr->base.pVtab->zErrMsg;
4239
+ static const int szFix = ZIPFILE_LFH_FIXED_SZ;
4240
+ u8 *aRead = zipfileCsrBuffer(pCsr);
4241
+ int rc;
4242
+
4243
+ rc = zipfileReadData(pFile, aRead, szFix, pCsr->cds.iOffset, pzErr);
4244
+ if( rc==SQLITE_OK ){
4245
+ u32 sig = zipfileRead32(aRead);
4246
+ if( sig!=ZIPFILE_SIGNATURE_LFH ){
4247
+ zipfileSetErrmsg(pCsr, "failed to read LFH at offset %d",
4248
+ (int)pCsr->cds.iOffset
4249
+ );
4250
+ rc = SQLITE_ERROR;
4251
+ }else{
4252
+ pCsr->lfh.iVersionExtract = zipfileRead16(aRead);
4253
+ pCsr->lfh.flags = zipfileRead16(aRead);
4254
+ pCsr->lfh.iCompression = zipfileRead16(aRead);
4255
+ pCsr->lfh.mTime = zipfileRead16(aRead);
4256
+ pCsr->lfh.mDate = zipfileRead16(aRead);
4257
+ pCsr->lfh.crc32 = zipfileRead32(aRead);
4258
+ pCsr->lfh.szCompressed = zipfileRead32(aRead);
4259
+ pCsr->lfh.szUncompressed = zipfileRead32(aRead);
4260
+ pCsr->lfh.nFile = zipfileRead16(aRead);
4261
+ pCsr->lfh.nExtra = zipfileRead16(aRead);
4262
+ assert( aRead==zipfileCsrBuffer(pCsr)+szFix );
4263
+ pCsr->iDataOff = pCsr->cds.iOffset+szFix+pCsr->lfh.nFile+pCsr->lfh.nExtra;
4264
+ }
4265
+ }
4266
+
4267
+ return rc;
4268
+}
4269
+
4270
+
4271
+/*
4272
+** Advance an ZipfileCsr to its next row of output.
4273
+*/
4274
+static int zipfileNext(sqlite3_vtab_cursor *cur){
4275
+ ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4276
+ int rc = SQLITE_OK;
4277
+ pCsr->flags = 0;
4278
+
4279
+ if( pCsr->pCurrent==0 ){
4280
+ i64 iEof = pCsr->eocd.iOffset + pCsr->eocd.nSize;
4281
+ if( pCsr->iNextOff>=iEof ){
4282
+ pCsr->bEof = 1;
4283
+ }
4284
+ }else{
4285
+ assert( pCsr->pFile==0 );
4286
+ do {
4287
+ pCsr->pCurrent = pCsr->pCurrent->pNext;
4288
+ }while( pCsr->pCurrent && pCsr->pCurrent->bDeleted );
4289
+ if( pCsr->pCurrent==0 ){
4290
+ pCsr->bEof = 1;
4291
+ }
4292
+ }
4293
+
4294
+ if( pCsr->bEof==0 ){
4295
+ rc = zipfileReadCDS(pCsr);
4296
+ if( rc==SQLITE_OK ){
4297
+ rc = zipfileReadLFH(pCsr);
4298
+ }
4299
+ }
4300
+
4301
+ return rc;
4302
+}
4303
+
4304
+/*
4305
+** "Standard" MS-DOS time format:
4306
+**
4307
+** File modification time:
4308
+** Bits 00-04: seconds divided by 2
4309
+** Bits 05-10: minute
4310
+** Bits 11-15: hour
4311
+** File modification date:
4312
+** Bits 00-04: day
4313
+** Bits 05-08: month (1-12)
4314
+** Bits 09-15: years from 1980
4315
+*/
4316
+static time_t zipfileMtime(ZipfileCsr *pCsr){
4317
+ struct tm t;
4318
+ memset(&t, 0, sizeof(t));
4319
+ t.tm_sec = (pCsr->cds.mTime & 0x1F)*2;
4320
+ t.tm_min = (pCsr->cds.mTime >> 5) & 0x2F;
4321
+ t.tm_hour = (pCsr->cds.mTime >> 11) & 0x1F;
4322
+
4323
+ t.tm_mday = (pCsr->cds.mDate & 0x1F);
4324
+ t.tm_mon = ((pCsr->cds.mDate >> 5) & 0x0F) - 1;
4325
+ t.tm_year = 80 + ((pCsr->cds.mDate >> 9) & 0x7F);
4326
+
4327
+ return mktime(&t);
4328
+}
4329
+
4330
+static void zipfileMtimeToDos(ZipfileCDS *pCds, u32 mTime){
4331
+ time_t t = (time_t)mTime;
4332
+ struct tm res;
4333
+
4334
+#if !defined(_WIN32) && !defined(WIN32)
4335
+ localtime_r(&t, &res);
4336
+#else
4337
+ memcpy(&res, localtime(&t), sizeof(struct tm));
4338
+#endif
4339
+
4340
+ pCds->mTime = (u16)(
4341
+ (res.tm_sec / 2) +
4342
+ (res.tm_min << 5) +
4343
+ (res.tm_hour << 11));
4344
+
4345
+ pCds->mDate = (u16)(
4346
+ (res.tm_mday-1) +
4347
+ ((res.tm_mon+1) << 5) +
4348
+ ((res.tm_year-80) << 9));
4349
+}
4350
+
4351
+/*
4352
+** Return values of columns for the row at which the series_cursor
4353
+** is currently pointing.
4354
+*/
4355
+static int zipfileColumn(
4356
+ sqlite3_vtab_cursor *cur, /* The cursor */
4357
+ sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
4358
+ int i /* Which column to return */
4359
+){
4360
+ ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4361
+ int rc = SQLITE_OK;
4362
+ switch( i ){
4363
+ case 0: /* name */
4364
+ sqlite3_result_text(ctx, pCsr->cds.zFile, -1, SQLITE_TRANSIENT);
4365
+ break;
4366
+ case 1: /* mode */
4367
+ /* TODO: Whether or not the following is correct surely depends on
4368
+ ** the platform on which the archive was created. */
4369
+ sqlite3_result_int(ctx, pCsr->cds.iExternalAttr >> 16);
4370
+ break;
4371
+ case 2: { /* mtime */
4372
+ if( pCsr->flags & ZIPFILE_MTIME_VALID ){
4373
+ sqlite3_result_int64(ctx, pCsr->mTime);
4374
+ }else{
4375
+ sqlite3_result_int64(ctx, zipfileMtime(pCsr));
4376
+ }
4377
+ break;
4378
+ }
4379
+ case 3: { /* sz */
4380
+ sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
4381
+ break;
4382
+ }
4383
+ case 4: { /* data */
4384
+ int sz = pCsr->cds.szCompressed;
4385
+ if( sz>0 ){
4386
+ u8 *aBuf = sqlite3_malloc(sz);
4387
+ if( aBuf==0 ){
4388
+ rc = SQLITE_NOMEM;
4389
+ }else{
4390
+ FILE *pFile = zipfileGetFd(pCsr);
4391
+ rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff,
4392
+ &pCsr->base.pVtab->zErrMsg
4393
+ );
4394
+ }
4395
+ if( rc==SQLITE_OK ){
4396
+ sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
4397
+ sqlite3_free(aBuf);
4398
+ }
4399
+ }
4400
+ break;
4401
+ }
4402
+ case 5: /* method */
4403
+ sqlite3_result_int(ctx, pCsr->cds.iCompression);
4404
+ break;
4405
+ }
4406
+
4407
+ return SQLITE_OK;
4408
+}
4409
+
4410
+/*
4411
+** Return the rowid for the current row.
4412
+*/
4413
+static int zipfileRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
4414
+ ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4415
+ if( pCsr->pCurrent ){
4416
+ *pRowid = pCsr->pCurrent->iRowid;
4417
+ }else{
4418
+ *pRowid = pCsr->cds.iOffset;
4419
+ }
4420
+ return SQLITE_OK;
4421
+}
4422
+
4423
+/*
4424
+** Return TRUE if the cursor has been moved off of the last
4425
+** row of output.
4426
+*/
4427
+static int zipfileEof(sqlite3_vtab_cursor *cur){
4428
+ ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4429
+ return pCsr->bEof;
4430
+}
4431
+
4432
+/*
4433
+*/
4434
+static int zipfileReadEOCD(
4435
+ ZipfileTab *pTab, /* Return errors here */
4436
+ FILE *pFile, /* Read from this file */
4437
+ ZipfileEOCD *pEOCD /* Object to populate */
4438
+){
4439
+ u8 *aRead = pTab->aBuffer; /* Temporary buffer */
4440
+ i64 szFile; /* Total size of file in bytes */
4441
+ int nRead; /* Bytes to read from file */
4442
+ i64 iOff; /* Offset to read from */
4443
+ int rc;
4444
+
4445
+ fseek(pFile, 0, SEEK_END);
4446
+ szFile = (i64)ftell(pFile);
4447
+ if( szFile==0 ){
4448
+ return SQLITE_EMPTY;
4449
+ }
4450
+ nRead = (int)(MIN(szFile, ZIPFILE_BUFFER_SIZE));
4451
+ iOff = szFile - nRead;
4452
+
4453
+ rc = zipfileReadData(pFile, aRead, nRead, iOff, &pTab->base.zErrMsg);
4454
+ if( rc==SQLITE_OK ){
4455
+ int i;
4456
+
4457
+ /* Scan backwards looking for the signature bytes */
4458
+ for(i=nRead-20; i>=0; i--){
4459
+ if( aRead[i]==0x50 && aRead[i+1]==0x4b
4460
+ && aRead[i+2]==0x05 && aRead[i+3]==0x06
4461
+ ){
4462
+ break;
4463
+ }
4464
+ }
4465
+ if( i<0 ){
4466
+ pTab->base.zErrMsg = sqlite3_mprintf(
4467
+ "cannot find end of central directory record"
4468
+ );
4469
+ return SQLITE_ERROR;
4470
+ }
4471
+
4472
+ aRead += i+4;
4473
+ pEOCD->iDisk = zipfileRead16(aRead);
4474
+ pEOCD->iFirstDisk = zipfileRead16(aRead);
4475
+ pEOCD->nEntry = zipfileRead16(aRead);
4476
+ pEOCD->nEntryTotal = zipfileRead16(aRead);
4477
+ pEOCD->nSize = zipfileRead32(aRead);
4478
+ pEOCD->iOffset = zipfileRead32(aRead);
4479
+
4480
+#if 0
4481
+ printf("iDisk=%d iFirstDisk=%d nEntry=%d "
4482
+ "nEntryTotal=%d nSize=%d iOffset=%d",
4483
+ (int)pEOCD->iDisk, (int)pEOCD->iFirstDisk, (int)pEOCD->nEntry,
4484
+ (int)pEOCD->nEntryTotal, (int)pEOCD->nSize, (int)pEOCD->iOffset
4485
+ );
4486
+#endif
4487
+ }
4488
+
4489
+ return SQLITE_OK;
4490
+}
4491
+
4492
+/*
4493
+** xFilter callback.
4494
+*/
4495
+static int zipfileFilter(
4496
+ sqlite3_vtab_cursor *cur,
4497
+ int idxNum, const char *idxStr,
4498
+ int argc, sqlite3_value **argv
4499
+){
4500
+ ZipfileTab *pTab = (ZipfileTab*)cur->pVtab;
4501
+ ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4502
+ const char *zFile; /* Zip file to scan */
4503
+ int rc = SQLITE_OK; /* Return Code */
4504
+
4505
+ zipfileResetCursor(pCsr);
4506
+
4507
+ if( pTab->zFile ){
4508
+ zFile = pTab->zFile;
4509
+ }else if( idxNum==0 ){
4510
+ /* Error. This is an eponymous virtual table and the user has not
4511
+ ** supplied a file name. */
4512
+ zipfileSetErrmsg(pCsr, "table function zipfile() requires an argument");
4513
+ return SQLITE_ERROR;
4514
+ }else{
4515
+ zFile = (const char*)sqlite3_value_text(argv[0]);
4516
+ }
4517
+
4518
+ if( pTab->pWriteFd==0 ){
4519
+ pCsr->pFile = fopen(zFile, "rb");
4520
+ if( pCsr->pFile==0 ){
4521
+ zipfileSetErrmsg(pCsr, "cannot open file: %s", zFile);
4522
+ rc = SQLITE_ERROR;
4523
+ }else{
4524
+ rc = zipfileReadEOCD(pTab, pCsr->pFile, &pCsr->eocd);
4525
+ if( rc==SQLITE_OK ){
4526
+ pCsr->iNextOff = pCsr->eocd.iOffset;
4527
+ rc = zipfileNext(cur);
4528
+ }else if( rc==SQLITE_EMPTY ){
4529
+ rc = SQLITE_OK;
4530
+ pCsr->bEof = 1;
4531
+ }
4532
+ }
4533
+ }else{
4534
+ ZipfileEntry e;
4535
+ memset(&e, 0, sizeof(e));
4536
+ e.pNext = pTab->pFirstEntry;
4537
+ pCsr->pCurrent = &e;
4538
+ rc = zipfileNext(cur);
4539
+ assert( pCsr->pCurrent!=&e );
4540
+ }
4541
+
4542
+ return rc;
4543
+}
4544
+
4545
+/*
4546
+** xBestIndex callback.
4547
+*/
4548
+static int zipfileBestIndex(
4549
+ sqlite3_vtab *tab,
4550
+ sqlite3_index_info *pIdxInfo
4551
+){
4552
+ int i;
4553
+
4554
+ for(i=0; i<pIdxInfo->nConstraint; i++){
4555
+ const struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
4556
+ if( pCons->usable==0 ) continue;
4557
+ if( pCons->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
4558
+ if( pCons->iColumn!=ZIPFILE_F_COLUMN_IDX ) continue;
4559
+ break;
4560
+ }
4561
+
4562
+ if( i<pIdxInfo->nConstraint ){
4563
+ pIdxInfo->aConstraintUsage[i].argvIndex = 1;
4564
+ pIdxInfo->aConstraintUsage[i].omit = 1;
4565
+ pIdxInfo->estimatedCost = 1000.0;
4566
+ pIdxInfo->idxNum = 1;
4567
+ }else{
4568
+ pIdxInfo->estimatedCost = (double)(((sqlite3_int64)1) << 50);
4569
+ pIdxInfo->idxNum = 0;
4570
+ }
4571
+
4572
+ return SQLITE_OK;
4573
+}
4574
+
4575
+/*
4576
+** Add object pNew to the end of the linked list that begins at
4577
+** ZipfileTab.pFirstEntry and ends with pLastEntry.
4578
+*/
4579
+static void zipfileAddEntry(ZipfileTab *pTab, ZipfileEntry *pNew){
4580
+ assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
4581
+ assert( pNew->pNext==0 );
4582
+ if( pTab->pFirstEntry==0 ){
4583
+ pNew->iRowid = 1;
4584
+ pTab->pFirstEntry = pTab->pLastEntry = pNew;
4585
+ }else{
4586
+ assert( pTab->pLastEntry->pNext==0 );
4587
+ pNew->iRowid = pTab->pLastEntry->iRowid+1;
4588
+ pTab->pLastEntry->pNext = pNew;
4589
+ pTab->pLastEntry = pNew;
4590
+ }
4591
+}
4592
+
4593
+static int zipfileLoadDirectory(ZipfileTab *pTab){
4594
+ ZipfileEOCD eocd;
4595
+ int rc;
4596
+
4597
+ rc = zipfileReadEOCD(pTab, pTab->pWriteFd, &eocd);
4598
+ if( rc==SQLITE_OK ){
4599
+ int i;
4600
+ int iOff = 0;
4601
+ u8 *aBuf = sqlite3_malloc(eocd.nSize);
4602
+ if( aBuf==0 ){
4603
+ rc = SQLITE_NOMEM;
4604
+ }else{
4605
+ rc = zipfileReadData(
4606
+ pTab->pWriteFd, aBuf, eocd.nSize, eocd.iOffset, &pTab->base.zErrMsg
4607
+ );
4608
+ }
4609
+
4610
+ for(i=0; rc==SQLITE_OK && i<eocd.nEntry; i++){
4611
+ u16 nFile;
4612
+ u16 nExtra;
4613
+ u16 nComment;
4614
+ ZipfileEntry *pNew;
4615
+ u8 *aRec = &aBuf[iOff];
4616
+
4617
+ nFile = zipfileGetU16(&aRec[ZIPFILE_CDS_NFILE_OFF]);
4618
+ nExtra = zipfileGetU16(&aRec[ZIPFILE_CDS_NFILE_OFF+2]);
4619
+ nComment = zipfileGetU16(&aRec[ZIPFILE_CDS_NFILE_OFF+4]);
4620
+
4621
+ pNew = sqlite3_malloc(
4622
+ sizeof(ZipfileEntry)
4623
+ + nFile+1
4624
+ + ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment
4625
+ );
4626
+ if( pNew==0 ){
4627
+ rc = SQLITE_NOMEM;
4628
+ }else{
4629
+ memset(pNew, 0, sizeof(ZipfileEntry));
4630
+ pNew->zPath = (char*)&pNew[1];
4631
+ memcpy(pNew->zPath, &aBuf[ZIPFILE_CDS_FIXED_SZ], nFile);
4632
+ pNew->zPath[nFile] = '\0';
4633
+ pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
4634
+ pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
4635
+ memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
4636
+ zipfileAddEntry(pTab, pNew);
4637
+ }
4638
+
4639
+ iOff += ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
4640
+ }
4641
+
4642
+ sqlite3_free(aBuf);
4643
+ }else if( rc==SQLITE_EMPTY ){
4644
+ rc = SQLITE_OK;
4645
+ }
4646
+
4647
+ return rc;
4648
+}
4649
+
4650
+static ZipfileEntry *zipfileNewEntry(
4651
+ ZipfileCDS *pCds, /* Values for fixed size part of CDS */
4652
+ const char *zPath, /* Path for new entry */
4653
+ int nPath, /* strlen(zPath) */
4654
+ u32 mTime /* Modification time (or 0) */
4655
+){
4656
+ u8 *aWrite;
4657
+ ZipfileEntry *pNew;
4658
+ pCds->nFile = (u16)nPath;
4659
+ pCds->nExtra = mTime ? 9 : 0;
4660
+ pNew = (ZipfileEntry*)sqlite3_malloc(
4661
+ sizeof(ZipfileEntry) +
4662
+ nPath+1 +
4663
+ ZIPFILE_CDS_FIXED_SZ + nPath + pCds->nExtra
4664
+ );
4665
+
4666
+ if( pNew ){
4667
+ memset(pNew, 0, sizeof(ZipfileEntry));
4668
+ pNew->zPath = (char*)&pNew[1];
4669
+ pNew->aCdsEntry = (u8*)&pNew->zPath[nPath+1];
4670
+ pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ + nPath + pCds->nExtra;
4671
+ memcpy(pNew->zPath, zPath, nPath+1);
4672
+
4673
+ aWrite = pNew->aCdsEntry;
4674
+ zipfileWrite32(aWrite, ZIPFILE_SIGNATURE_CDS);
4675
+ zipfileWrite16(aWrite, pCds->iVersionMadeBy);
4676
+ zipfileWrite16(aWrite, pCds->iVersionExtract);
4677
+ zipfileWrite16(aWrite, pCds->flags);
4678
+ zipfileWrite16(aWrite, pCds->iCompression);
4679
+ zipfileWrite16(aWrite, pCds->mTime);
4680
+ zipfileWrite16(aWrite, pCds->mDate);
4681
+ zipfileWrite32(aWrite, pCds->crc32);
4682
+ zipfileWrite32(aWrite, pCds->szCompressed);
4683
+ zipfileWrite32(aWrite, pCds->szUncompressed);
4684
+ zipfileWrite16(aWrite, pCds->nFile);
4685
+ zipfileWrite16(aWrite, pCds->nExtra);
4686
+ zipfileWrite16(aWrite, pCds->nComment); assert( pCds->nComment==0 );
4687
+ zipfileWrite16(aWrite, pCds->iDiskStart);
4688
+ zipfileWrite16(aWrite, pCds->iInternalAttr);
4689
+ zipfileWrite32(aWrite, pCds->iExternalAttr);
4690
+ zipfileWrite32(aWrite, pCds->iOffset);
4691
+ assert( aWrite==&pNew->aCdsEntry[ZIPFILE_CDS_FIXED_SZ] );
4692
+ memcpy(aWrite, zPath, nPath);
4693
+ if( pCds->nExtra ){
4694
+ aWrite += nPath;
4695
+ zipfileWrite16(aWrite, ZIPFILE_EXTRA_TIMESTAMP);
4696
+ zipfileWrite16(aWrite, 5);
4697
+ *aWrite++ = 0x01;
4698
+ zipfileWrite32(aWrite, mTime);
4699
+ }
4700
+ }
4701
+
4702
+ return pNew;
4703
+}
4704
+
4705
+static int zipfileAppendEntry(
4706
+ ZipfileTab *pTab,
4707
+ ZipfileCDS *pCds,
4708
+ const char *zPath, /* Path for new entry */
4709
+ int nPath, /* strlen(zPath) */
4710
+ const u8 *pData,
4711
+ int nData,
4712
+ u32 mTime
4713
+){
4714
+ u8 *aBuf = pTab->aBuffer;
4715
+ int rc;
4716
+
4717
+ zipfileWrite32(aBuf, ZIPFILE_SIGNATURE_LFH);
4718
+ zipfileWrite16(aBuf, pCds->iVersionExtract);
4719
+ zipfileWrite16(aBuf, pCds->flags);
4720
+ zipfileWrite16(aBuf, pCds->iCompression);
4721
+ zipfileWrite16(aBuf, pCds->mTime);
4722
+ zipfileWrite16(aBuf, pCds->mDate);
4723
+ zipfileWrite32(aBuf, pCds->crc32);
4724
+ zipfileWrite32(aBuf, pCds->szCompressed);
4725
+ zipfileWrite32(aBuf, pCds->szUncompressed);
4726
+ zipfileWrite16(aBuf, (u16)nPath);
4727
+ zipfileWrite16(aBuf, pCds->nExtra);
4728
+ assert( aBuf==&pTab->aBuffer[ZIPFILE_LFH_FIXED_SZ] );
4729
+ rc = zipfileAppendData(pTab, pTab->aBuffer, (int)(aBuf - pTab->aBuffer));
4730
+ if( rc==SQLITE_OK ){
4731
+ rc = zipfileAppendData(pTab, (const u8*)zPath, nPath);
4732
+ }
4733
+
4734
+ if( rc==SQLITE_OK && pCds->nExtra ){
4735
+ aBuf = pTab->aBuffer;
4736
+ zipfileWrite16(aBuf, ZIPFILE_EXTRA_TIMESTAMP);
4737
+ zipfileWrite16(aBuf, 5);
4738
+ *aBuf++ = 0x01;
4739
+ zipfileWrite32(aBuf, mTime);
4740
+ rc = zipfileAppendData(pTab, pTab->aBuffer, 9);
4741
+ }
4742
+
4743
+ if( rc==SQLITE_OK ){
4744
+ rc = zipfileAppendData(pTab, pData, nData);
4745
+ }
4746
+
4747
+ return rc;
4748
+}
4749
+
4750
+static int zipfileGetMode(ZipfileTab *pTab, sqlite3_value *pVal, int *pMode){
4751
+ const char *z = (const char*)sqlite3_value_text(pVal);
4752
+ int mode = 0;
4753
+ if( z==0 || (z[0]>=0 && z[0]<=9) ){
4754
+ mode = sqlite3_value_int(pVal);
4755
+ }else{
4756
+ const char zTemplate[11] = "-rwxrwxrwx";
4757
+ int i;
4758
+ if( strlen(z)!=10 ) goto parse_error;
4759
+ switch( z[0] ){
4760
+ case '-': mode |= S_IFREG; break;
4761
+ case 'd': mode |= S_IFDIR; break;
4762
+#if !defined(_WIN32) && !defined(WIN32)
4763
+ case 'l': mode |= S_IFLNK; break;
4764
+#endif
4765
+ default: goto parse_error;
4766
+ }
4767
+ for(i=1; i<10; i++){
4768
+ if( z[i]==zTemplate[i] ) mode |= 1 << (9-i);
4769
+ else if( z[i]!='-' ) goto parse_error;
4770
+ }
4771
+ }
4772
+ *pMode = mode;
4773
+ return SQLITE_OK;
4774
+
4775
+ parse_error:
4776
+ pTab->base.zErrMsg = sqlite3_mprintf("zipfile: parse error in mode: %s", z);
4777
+ return SQLITE_ERROR;
4778
+}
4779
+
4780
+/*
4781
+** xUpdate method.
4782
+*/
4783
+static int zipfileUpdate(
4784
+ sqlite3_vtab *pVtab,
4785
+ int nVal,
4786
+ sqlite3_value **apVal,
4787
+ sqlite_int64 *pRowid
4788
+){
4789
+ ZipfileTab *pTab = (ZipfileTab*)pVtab;
4790
+ int rc = SQLITE_OK; /* Return Code */
4791
+ ZipfileEntry *pNew = 0; /* New in-memory CDS entry */
4792
+
4793
+ int mode; /* Mode for new entry */
4794
+ i64 mTime; /* Modification time for new entry */
4795
+ i64 sz; /* Uncompressed size */
4796
+ const char *zPath; /* Path for new entry */
4797
+ int nPath; /* strlen(zPath) */
4798
+ const u8 *pData; /* Pointer to buffer containing content */
4799
+ int nData; /* Size of pData buffer in bytes */
4800
+ int iMethod = 0; /* Compression method for new entry */
4801
+ u8 *pFree = 0; /* Free this */
4802
+ ZipfileCDS cds; /* New Central Directory Structure entry */
4803
+
4804
+ assert( pTab->zFile );
4805
+ assert( pTab->pWriteFd );
4806
+
4807
+ if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
4808
+ i64 iDelete = sqlite3_value_int64(apVal[0]);
4809
+ ZipfileEntry *p;
4810
+ for(p=pTab->pFirstEntry; p; p=p->pNext){
4811
+ if( p->iRowid==iDelete ){
4812
+ p->bDeleted = 1;
4813
+ break;
4814
+ }
4815
+ }
4816
+ if( nVal==1 ) return SQLITE_OK;
4817
+ }
4818
+
4819
+ zPath = (const char*)sqlite3_value_text(apVal[2]);
4820
+ nPath = (int)strlen(zPath);
4821
+ rc = zipfileGetMode(pTab, apVal[3], &mode);
4822
+ if( rc!=SQLITE_OK ) return rc;
4823
+ mTime = sqlite3_value_int64(apVal[4]);
4824
+ sz = sqlite3_value_int(apVal[5]);
4825
+ pData = sqlite3_value_blob(apVal[6]);
4826
+ nData = sqlite3_value_bytes(apVal[6]);
4827
+
4828
+ /* If a NULL value is inserted into the 'method' column, do automatic
4829
+ ** compression. */
4830
+ if( nData>0 && sqlite3_value_type(apVal[7])==SQLITE_NULL ){
4831
+ pFree = (u8*)sqlite3_malloc(nData);
4832
+ if( pFree==0 ){
4833
+ rc = SQLITE_NOMEM;
4834
+ }else{
4835
+ int res;
4836
+ z_stream str;
4837
+ memset(&str, 0, sizeof(str));
4838
+ str.next_in = (z_const Bytef*)pData;
4839
+ str.avail_in = nData;
4840
+ str.next_out = pFree;
4841
+ str.avail_out = nData;
4842
+ deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
4843
+ res = deflate(&str, Z_FINISH);
4844
+ if( res==Z_STREAM_END ){
4845
+ pData = pFree;
4846
+ nData = str.total_out;
4847
+ iMethod = 8;
4848
+ }else if( res!=Z_OK ){
4849
+ pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error");
4850
+ rc = SQLITE_ERROR;
4851
+ }
4852
+ deflateEnd(&str);
4853
+ }
4854
+ }else{
4855
+ iMethod = sqlite3_value_int(apVal[7]);
4856
+ if( iMethod<0 || iMethod>65535 ){
4857
+ pTab->base.zErrMsg = sqlite3_mprintf(
4858
+ "zipfile: invalid compression method: %d", iMethod
4859
+ );
4860
+ rc = SQLITE_ERROR;
4861
+ }
4862
+ }
4863
+
4864
+ if( rc==SQLITE_OK ){
4865
+ /* Create the new CDS record. */
4866
+ memset(&cds, 0, sizeof(cds));
4867
+ cds.iVersionMadeBy = ZIPFILE_NEWENTRY_MADEBY;
4868
+ cds.iVersionExtract = ZIPFILE_NEWENTRY_REQUIRED;
4869
+ cds.flags = ZIPFILE_NEWENTRY_FLAGS;
4870
+ cds.iCompression = (u16)iMethod;
4871
+ zipfileMtimeToDos(&cds, (u32)mTime);
4872
+ cds.crc32 = crc32(0, pData, nData);
4873
+ cds.szCompressed = nData;
4874
+ cds.szUncompressed = (u32)sz;
4875
+ cds.iExternalAttr = (mode<<16);
4876
+ cds.iOffset = (u32)pTab->szCurrent;
4877
+ pNew = zipfileNewEntry(&cds, zPath, nPath, (u32)mTime);
4878
+ if( pNew==0 ){
4879
+ rc = SQLITE_NOMEM;
4880
+ }else{
4881
+ zipfileAddEntry(pTab, pNew);
4882
+ }
4883
+ }
4884
+
4885
+ /* Append the new header+file to the archive */
4886
+ if( rc==SQLITE_OK ){
4887
+ rc = zipfileAppendEntry(pTab, &cds, zPath, nPath, pData, nData, (u32)mTime);
4888
+ }
4889
+
4890
+ sqlite3_free(pFree);
4891
+ return rc;
4892
+}
4893
+
4894
+static int zipfileAppendEOCD(ZipfileTab *pTab, ZipfileEOCD *p){
4895
+ u8 *aBuf = pTab->aBuffer;
4896
+
4897
+ zipfileWrite32(aBuf, ZIPFILE_SIGNATURE_EOCD);
4898
+ zipfileWrite16(aBuf, p->iDisk);
4899
+ zipfileWrite16(aBuf, p->iFirstDisk);
4900
+ zipfileWrite16(aBuf, p->nEntry);
4901
+ zipfileWrite16(aBuf, p->nEntryTotal);
4902
+ zipfileWrite32(aBuf, p->nSize);
4903
+ zipfileWrite32(aBuf, p->iOffset);
4904
+ zipfileWrite16(aBuf, 0); /* Size of trailing comment in bytes*/
4905
+
4906
+ assert( (aBuf-pTab->aBuffer)==22 );
4907
+ return zipfileAppendData(pTab, pTab->aBuffer, (int)(aBuf - pTab->aBuffer));
4908
+}
4909
+
4910
+static void zipfileCleanupTransaction(ZipfileTab *pTab){
4911
+ ZipfileEntry *pEntry;
4912
+ ZipfileEntry *pNext;
4913
+
4914
+ for(pEntry=pTab->pFirstEntry; pEntry; pEntry=pNext){
4915
+ pNext = pEntry->pNext;
4916
+ sqlite3_free(pEntry);
4917
+ }
4918
+ pTab->pFirstEntry = 0;
4919
+ pTab->pLastEntry = 0;
4920
+ fclose(pTab->pWriteFd);
4921
+ pTab->pWriteFd = 0;
4922
+ pTab->szCurrent = 0;
4923
+ pTab->szOrig = 0;
4924
+}
4925
+
4926
+static int zipfileBegin(sqlite3_vtab *pVtab){
4927
+ ZipfileTab *pTab = (ZipfileTab*)pVtab;
4928
+ int rc = SQLITE_OK;
4929
+
4930
+ assert( pTab->pWriteFd==0 );
4931
+
4932
+ /* This table is only writable if a default archive path was specified
4933
+ ** as part of the CREATE VIRTUAL TABLE statement. */
4934
+ if( pTab->zFile==0 ){
4935
+ pTab->base.zErrMsg = sqlite3_mprintf(
4936
+ "zipfile: writing requires a default archive"
4937
+ );
4938
+ return SQLITE_ERROR;
4939
+ }
4940
+
4941
+ /* Open a write fd on the file. Also load the entire central directory
4942
+ ** structure into memory. During the transaction any new file data is
4943
+ ** appended to the archive file, but the central directory is accumulated
4944
+ ** in main-memory until the transaction is committed. */
4945
+ pTab->pWriteFd = fopen(pTab->zFile, "ab+");
4946
+ if( pTab->pWriteFd==0 ){
4947
+ pTab->base.zErrMsg = sqlite3_mprintf(
4948
+ "zipfile: failed to open file %s for writing", pTab->zFile
4949
+ );
4950
+ rc = SQLITE_ERROR;
4951
+ }else{
4952
+ fseek(pTab->pWriteFd, 0, SEEK_END);
4953
+ pTab->szCurrent = pTab->szOrig = (i64)ftell(pTab->pWriteFd);
4954
+ rc = zipfileLoadDirectory(pTab);
4955
+ }
4956
+
4957
+ if( rc!=SQLITE_OK ){
4958
+ zipfileCleanupTransaction(pTab);
4959
+ }
4960
+
4961
+ return rc;
4962
+}
4963
+
4964
+static int zipfileCommit(sqlite3_vtab *pVtab){
4965
+ ZipfileTab *pTab = (ZipfileTab*)pVtab;
4966
+ int rc = SQLITE_OK;
4967
+ if( pTab->pWriteFd ){
4968
+ i64 iOffset = pTab->szCurrent;
4969
+ ZipfileEntry *p;
4970
+ ZipfileEOCD eocd;
4971
+ int nEntry = 0;
4972
+
4973
+ /* Write out all undeleted entries */
4974
+ for(p=pTab->pFirstEntry; rc==SQLITE_OK && p; p=p->pNext){
4975
+ if( p->bDeleted ) continue;
4976
+ rc = zipfileAppendData(pTab, p->aCdsEntry, p->nCdsEntry);
4977
+ nEntry++;
4978
+ }
4979
+
4980
+ /* Write out the EOCD record */
4981
+ eocd.iDisk = 0;
4982
+ eocd.iFirstDisk = 0;
4983
+ eocd.nEntry = (u16)nEntry;
4984
+ eocd.nEntryTotal = (u16)nEntry;
4985
+ eocd.nSize = (u32)(pTab->szCurrent - iOffset);
4986
+ eocd.iOffset = (u32)iOffset;
4987
+ rc = zipfileAppendEOCD(pTab, &eocd);
4988
+
4989
+ zipfileCleanupTransaction(pTab);
4990
+ }
4991
+ return rc;
4992
+}
4993
+
4994
+static int zipfileRollback(sqlite3_vtab *pVtab){
4995
+ return zipfileCommit(pVtab);
4996
+}
4997
+
4998
+/*
4999
+** Register the "zipfile" virtual table.
5000
+*/
5001
+static int zipfileRegister(sqlite3 *db){
5002
+ static sqlite3_module zipfileModule = {
5003
+ 1, /* iVersion */
5004
+ zipfileConnect, /* xCreate */
5005
+ zipfileConnect, /* xConnect */
5006
+ zipfileBestIndex, /* xBestIndex */
5007
+ zipfileDisconnect, /* xDisconnect */
5008
+ zipfileDisconnect, /* xDestroy */
5009
+ zipfileOpen, /* xOpen - open a cursor */
5010
+ zipfileClose, /* xClose - close a cursor */
5011
+ zipfileFilter, /* xFilter - configure scan constraints */
5012
+ zipfileNext, /* xNext - advance a cursor */
5013
+ zipfileEof, /* xEof - check for end of scan */
5014
+ zipfileColumn, /* xColumn - read data */
5015
+ zipfileRowid, /* xRowid - read data */
5016
+ zipfileUpdate, /* xUpdate */
5017
+ zipfileBegin, /* xBegin */
5018
+ 0, /* xSync */
5019
+ zipfileCommit, /* xCommit */
5020
+ zipfileRollback, /* xRollback */
5021
+ 0, /* xFindMethod */
5022
+ 0, /* xRename */
5023
+ };
5024
+
5025
+ int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0);
5026
+ return rc;
5027
+}
5028
+#else /* SQLITE_OMIT_VIRTUALTABLE */
5029
+# define zipfileRegister(x) SQLITE_OK
5030
+#endif
5031
+
5032
+/*
5033
+** zipfile_uncompress(DATA, SZ, METHOD)
5034
+*/
5035
+static void zipfileUncompressFunc(
5036
+ sqlite3_context *context,
5037
+ int argc,
5038
+ sqlite3_value **argv
5039
+){
5040
+ int iMethod;
5041
+
5042
+ iMethod = sqlite3_value_int(argv[2]);
5043
+ if( iMethod==0 ){
5044
+ sqlite3_result_value(context, argv[0]);
5045
+ }else if( iMethod==8 ){
5046
+ Byte *res;
5047
+ int sz = sqlite3_value_int(argv[1]);
5048
+ z_stream str;
5049
+ memset(&str, 0, sizeof(str));
5050
+ str.next_in = (Byte*)sqlite3_value_blob(argv[0]);
5051
+ str.avail_in = sqlite3_value_bytes(argv[0]);
5052
+ res = str.next_out = (Byte*)sqlite3_malloc(sz);
5053
+ if( res==0 ){
5054
+ sqlite3_result_error_nomem(context);
5055
+ }else{
5056
+ int err;
5057
+ str.avail_out = sz;
5058
+
5059
+ err = inflateInit2(&str, -15);
5060
+ if( err!=Z_OK ){
5061
+ zipfileCtxErrorMsg(context, "inflateInit2() failed (%d)", err);
5062
+ }else{
5063
+ err = inflate(&str, Z_NO_FLUSH);
5064
+ if( err!=Z_STREAM_END ){
5065
+ zipfileCtxErrorMsg(context, "inflate() failed (%d)", err);
5066
+ }else{
5067
+ sqlite3_result_blob(context, res, sz, SQLITE_TRANSIENT);
5068
+ }
5069
+ }
5070
+ sqlite3_free(res);
5071
+ inflateEnd(&str);
5072
+ }
5073
+ }else{
5074
+ zipfileCtxErrorMsg(context, "unrecognized compression method: %d", iMethod);
5075
+ }
5076
+}
5077
+
5078
+#ifdef _WIN32
5079
+
5080
+#endif
5081
+int sqlite3_zipfile_init(
5082
+ sqlite3 *db,
5083
+ char **pzErrMsg,
5084
+ const sqlite3_api_routines *pApi
5085
+){
5086
+ int rc = SQLITE_OK;
5087
+ SQLITE_EXTENSION_INIT2(pApi);
5088
+ (void)pzErrMsg; /* Unused parameter */
5089
+ rc = sqlite3_create_function(db, "zipfile_uncompress", 3,
5090
+ SQLITE_UTF8, 0, zipfileUncompressFunc, 0, 0
5091
+ );
5092
+ if( rc!=SQLITE_OK ) return rc;
5093
+ return zipfileRegister(db);
5094
+}
5095
+
5096
+
5097
+/************************* End ../ext/misc/zipfile.c ********************/
5098
+/************************* Begin ../ext/misc/sqlar.c ******************/
5099
+/*
5100
+** 2017-12-17
5101
+**
5102
+** The author disclaims copyright to this source code. In place of
5103
+** a legal notice, here is a blessing:
5104
+**
5105
+** May you do good and not evil.
5106
+** May you find forgiveness for yourself and forgive others.
5107
+** May you share freely, never taking more than you give.
5108
+**
5109
+******************************************************************************
5110
+**
5111
+** Utility functions sqlar_compress() and sqlar_uncompress(). Useful
5112
+** for working with sqlar archives and used by the shell tool's built-in
5113
+** sqlar support.
5114
+*/
5115
+SQLITE_EXTENSION_INIT1
5116
+#include <zlib.h>
5117
+
5118
+/*
5119
+** Implementation of the "sqlar_compress(X)" SQL function.
5120
+**
5121
+** If the type of X is SQLITE_BLOB, and compressing that blob using
5122
+** zlib utility function compress() yields a smaller blob, return the
5123
+** compressed blob. Otherwise, return a copy of X.
5124
+**
5125
+** SQLar uses the "zlib format" for compressed content. The zlib format
5126
+** contains a two-byte identification header and a four-byte checksum at
5127
+** the end. This is different from ZIP which uses the raw deflate format.
5128
+**
5129
+** Future enhancements to SQLar might add support for new compression formats.
5130
+** If so, those new formats will be identified by alternative headers in the
5131
+** compressed data.
5132
+*/
5133
+static void sqlarCompressFunc(
5134
+ sqlite3_context *context,
5135
+ int argc,
5136
+ sqlite3_value **argv
5137
+){
5138
+ assert( argc==1 );
5139
+ if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
5140
+ const Bytef *pData = sqlite3_value_blob(argv[0]);
5141
+ uLong nData = sqlite3_value_bytes(argv[0]);
5142
+ uLongf nOut = compressBound(nData);
5143
+ Bytef *pOut;
5144
+
5145
+ pOut = (Bytef*)sqlite3_malloc(nOut);
5146
+ if( pOut==0 ){
5147
+ sqlite3_result_error_nomem(context);
5148
+ return;
5149
+ }else{
5150
+ if( Z_OK!=compress(pOut, &nOut, pData, nData) ){
5151
+ sqlite3_result_error(context, "error in compress()", -1);
5152
+ }else if( nOut<nData ){
5153
+ sqlite3_result_blob(context, pOut, nOut, SQLITE_TRANSIENT);
5154
+ }else{
5155
+ sqlite3_result_value(context, argv[0]);
5156
+ }
5157
+ sqlite3_free(pOut);
5158
+ }
5159
+ }else{
5160
+ sqlite3_result_value(context, argv[0]);
5161
+ }
5162
+}
5163
+
5164
+/*
5165
+** Implementation of the "sqlar_uncompress(X,SZ)" SQL function
5166
+**
5167
+** Parameter SZ is interpreted as an integer. If it is less than or
5168
+** equal to zero, then this function returns a copy of X. Or, if
5169
+** SZ is equal to the size of X when interpreted as a blob, also
5170
+** return a copy of X. Otherwise, decompress blob X using zlib
5171
+** utility function uncompress() and return the results (another
5172
+** blob).
5173
+*/
5174
+static void sqlarUncompressFunc(
5175
+ sqlite3_context *context,
5176
+ int argc,
5177
+ sqlite3_value **argv
5178
+){
5179
+ uLong nData;
5180
+ uLongf sz;
5181
+
5182
+ assert( argc==2 );
5183
+ sz = sqlite3_value_int(argv[1]);
5184
+
5185
+ if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){
5186
+ sqlite3_result_value(context, argv[0]);
5187
+ }else{
5188
+ const Bytef *pData= sqlite3_value_blob(argv[0]);
5189
+ Bytef *pOut = sqlite3_malloc(sz);
5190
+ if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){
5191
+ sqlite3_result_error(context, "error in uncompress()", -1);
5192
+ }else{
5193
+ sqlite3_result_blob(context, pOut, sz, SQLITE_TRANSIENT);
5194
+ }
5195
+ sqlite3_free(pOut);
5196
+ }
5197
+}
5198
+
5199
+
5200
+#ifdef _WIN32
5201
+
5202
+#endif
5203
+int sqlite3_sqlar_init(
5204
+ sqlite3 *db,
5205
+ char **pzErrMsg,
5206
+ const sqlite3_api_routines *pApi
5207
+){
5208
+ int rc = SQLITE_OK;
5209
+ SQLITE_EXTENSION_INIT2(pApi);
5210
+ (void)pzErrMsg; /* Unused parameter */
5211
+ rc = sqlite3_create_function(db, "sqlar_compress", 1, SQLITE_UTF8, 0,
5212
+ sqlarCompressFunc, 0, 0);
5213
+ if( rc==SQLITE_OK ){
5214
+ rc = sqlite3_create_function(db, "sqlar_uncompress", 2, SQLITE_UTF8, 0,
5215
+ sqlarUncompressFunc, 0, 0);
5216
+ }
5217
+ return rc;
5218
+}
5219
+
5220
+/************************* End ../ext/misc/sqlar.c ********************/
5221
+#endif
5222
+/************************* Begin ../ext/expert/sqlite3expert.h ******************/
5223
+/*
5224
+** 2017 April 07
5225
+**
5226
+** The author disclaims copyright to this source code. In place of
5227
+** a legal notice, here is a blessing:
5228
+**
5229
+** May you do good and not evil.
5230
+** May you find forgiveness for yourself and forgive others.
5231
+** May you share freely, never taking more than you give.
5232
+**
5233
+*************************************************************************
5234
+*/
5235
+
5236
+
5237
+
5238
+typedef struct sqlite3expert sqlite3expert;
5239
+
5240
+/*
5241
+** Create a new sqlite3expert object.
5242
+**
5243
+** If successful, a pointer to the new object is returned and (*pzErr) set
5244
+** to NULL. Or, if an error occurs, NULL is returned and (*pzErr) set to
5245
+** an English-language error message. In this case it is the responsibility
5246
+** of the caller to eventually free the error message buffer using
5247
+** sqlite3_free().
5248
+*/
5249
+sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErr);
5250
+
5251
+/*
5252
+** Configure an sqlite3expert object.
5253
+**
5254
+** EXPERT_CONFIG_SAMPLE:
5255
+** By default, sqlite3_expert_analyze() generates sqlite_stat1 data for
5256
+** each candidate index. This involves scanning and sorting the entire
5257
+** contents of each user database table once for each candidate index
5258
+** associated with the table. For large databases, this can be
5259
+** prohibitively slow. This option allows the sqlite3expert object to
5260
+** be configured so that sqlite_stat1 data is instead generated based on a
5261
+** subset of each table, or so that no sqlite_stat1 data is used at all.
5262
+**
5263
+** A single integer argument is passed to this option. If the value is less
5264
+** than or equal to zero, then no sqlite_stat1 data is generated or used by
5265
+** the analysis - indexes are recommended based on the database schema only.
5266
+** Or, if the value is 100 or greater, complete sqlite_stat1 data is
5267
+** generated for each candidate index (this is the default). Finally, if the
5268
+** value falls between 0 and 100, then it represents the percentage of user
5269
+** table rows that should be considered when generating sqlite_stat1 data.
5270
+**
5271
+** Examples:
5272
+**
5273
+** // Do not generate any sqlite_stat1 data
5274
+** sqlite3_expert_config(pExpert, EXPERT_CONFIG_SAMPLE, 0);
5275
+**
5276
+** // Generate sqlite_stat1 data based on 10% of the rows in each table.
5277
+** sqlite3_expert_config(pExpert, EXPERT_CONFIG_SAMPLE, 10);
5278
+*/
5279
+int sqlite3_expert_config(sqlite3expert *p, int op, ...);
5280
+
5281
+#define EXPERT_CONFIG_SAMPLE 1 /* int */
5282
+
5283
+/*
5284
+** Specify zero or more SQL statements to be included in the analysis.
5285
+**
5286
+** Buffer zSql must contain zero or more complete SQL statements. This
5287
+** function parses all statements contained in the buffer and adds them
5288
+** to the internal list of statements to analyze. If successful, SQLITE_OK
5289
+** is returned and (*pzErr) set to NULL. Or, if an error occurs - for example
5290
+** due to a error in the SQL - an SQLite error code is returned and (*pzErr)
5291
+** may be set to point to an English language error message. In this case
5292
+** the caller is responsible for eventually freeing the error message buffer
5293
+** using sqlite3_free().
5294
+**
5295
+** If an error does occur while processing one of the statements in the
5296
+** buffer passed as the second argument, none of the statements in the
5297
+** buffer are added to the analysis.
5298
+**
5299
+** This function must be called before sqlite3_expert_analyze(). If a call
5300
+** to this function is made on an sqlite3expert object that has already
5301
+** been passed to sqlite3_expert_analyze() SQLITE_MISUSE is returned
5302
+** immediately and no statements are added to the analysis.
5303
+*/
5304
+int sqlite3_expert_sql(
5305
+ sqlite3expert *p, /* From a successful sqlite3_expert_new() */
5306
+ const char *zSql, /* SQL statement(s) to add */
5307
+ char **pzErr /* OUT: Error message (if any) */
5308
+);
5309
+
5310
+
5311
+/*
5312
+** This function is called after the sqlite3expert object has been configured
5313
+** with all SQL statements using sqlite3_expert_sql() to actually perform
5314
+** the analysis. Once this function has been called, it is not possible to
5315
+** add further SQL statements to the analysis.
5316
+**
5317
+** If successful, SQLITE_OK is returned and (*pzErr) is set to NULL. Or, if
5318
+** an error occurs, an SQLite error code is returned and (*pzErr) set to
5319
+** point to a buffer containing an English language error message. In this
5320
+** case it is the responsibility of the caller to eventually free the buffer
5321
+** using sqlite3_free().
5322
+**
5323
+** If an error does occur within this function, the sqlite3expert object
5324
+** is no longer useful for any purpose. At that point it is no longer
5325
+** possible to add further SQL statements to the object or to re-attempt
5326
+** the analysis. The sqlite3expert object must still be freed using a call
5327
+** sqlite3_expert_destroy().
5328
+*/
5329
+int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr);
5330
+
5331
+/*
5332
+** Return the total number of statements loaded using sqlite3_expert_sql().
5333
+** The total number of SQL statements may be different from the total number
5334
+** to calls to sqlite3_expert_sql().
5335
+*/
5336
+int sqlite3_expert_count(sqlite3expert*);
5337
+
5338
+/*
5339
+** Return a component of the report.
5340
+**
5341
+** This function is called after sqlite3_expert_analyze() to extract the
5342
+** results of the analysis. Each call to this function returns either a
5343
+** NULL pointer or a pointer to a buffer containing a nul-terminated string.
5344
+** The value passed as the third argument must be one of the EXPERT_REPORT_*
5345
+** #define constants defined below.
5346
+**
5347
+** For some EXPERT_REPORT_* parameters, the buffer returned contains
5348
+** information relating to a specific SQL statement. In these cases that
5349
+** SQL statement is identified by the value passed as the second argument.
5350
+** SQL statements are numbered from 0 in the order in which they are parsed.
5351
+** If an out-of-range value (less than zero or equal to or greater than the
5352
+** value returned by sqlite3_expert_count()) is passed as the second argument
5353
+** along with such an EXPERT_REPORT_* parameter, NULL is always returned.
5354
+**
5355
+** EXPERT_REPORT_SQL:
5356
+** Return the text of SQL statement iStmt.
5357
+**
5358
+** EXPERT_REPORT_INDEXES:
5359
+** Return a buffer containing the CREATE INDEX statements for all recommended
5360
+** indexes for statement iStmt. If there are no new recommeded indexes, NULL
5361
+** is returned.
5362
+**
5363
+** EXPERT_REPORT_PLAN:
5364
+** Return a buffer containing the EXPLAIN QUERY PLAN output for SQL query
5365
+** iStmt after the proposed indexes have been added to the database schema.
5366
+**
5367
+** EXPERT_REPORT_CANDIDATES:
5368
+** Return a pointer to a buffer containing the CREATE INDEX statements
5369
+** for all indexes that were tested (for all SQL statements). The iStmt
5370
+** parameter is ignored for EXPERT_REPORT_CANDIDATES calls.
5371
+*/
5372
+const char *sqlite3_expert_report(sqlite3expert*, int iStmt, int eReport);
5373
+
5374
+/*
5375
+** Values for the third argument passed to sqlite3_expert_report().
5376
+*/
5377
+#define EXPERT_REPORT_SQL 1
5378
+#define EXPERT_REPORT_INDEXES 2
5379
+#define EXPERT_REPORT_PLAN 3
5380
+#define EXPERT_REPORT_CANDIDATES 4
5381
+
5382
+/*
5383
+** Free an (sqlite3expert*) handle and all associated resources. There
5384
+** should be one call to this function for each successful call to
5385
+** sqlite3-expert_new().
5386
+*/
5387
+void sqlite3_expert_destroy(sqlite3expert*);
5388
+
5389
+
5390
+
5391
+/************************* End ../ext/expert/sqlite3expert.h ********************/
5392
+/************************* Begin ../ext/expert/sqlite3expert.c ******************/
5393
+/*
5394
+** 2017 April 09
5395
+**
5396
+** The author disclaims copyright to this source code. In place of
5397
+** a legal notice, here is a blessing:
5398
+**
5399
+** May you do good and not evil.
5400
+** May you find forgiveness for yourself and forgive others.
5401
+** May you share freely, never taking more than you give.
5402
+**
5403
+*************************************************************************
5404
+*/
5405
+#include <assert.h>
5406
+#include <string.h>
5407
+#include <stdio.h>
5408
+
5409
+/* typedef sqlite3_int64 i64; */
5410
+/* typedef sqlite3_uint64 u64; */
5411
+
5412
+typedef struct IdxColumn IdxColumn;
5413
+typedef struct IdxConstraint IdxConstraint;
5414
+typedef struct IdxScan IdxScan;
5415
+typedef struct IdxStatement IdxStatement;
5416
+typedef struct IdxTable IdxTable;
5417
+typedef struct IdxWrite IdxWrite;
5418
+
5419
+#define STRLEN (int)strlen
5420
+
5421
+/*
5422
+** A temp table name that we assume no user database will actually use.
5423
+** If this assumption proves incorrect triggers on the table with the
5424
+** conflicting name will be ignored.
5425
+*/
5426
+#define UNIQUE_TABLE_NAME "t592690916721053953805701627921227776"
5427
+
5428
+/*
5429
+** A single constraint. Equivalent to either "col = ?" or "col < ?" (or
5430
+** any other type of single-ended range constraint on a column).
5431
+**
5432
+** pLink:
5433
+** Used to temporarily link IdxConstraint objects into lists while
5434
+** creating candidate indexes.
5435
+*/
5436
+struct IdxConstraint {
5437
+ char *zColl; /* Collation sequence */
5438
+ int bRange; /* True for range, false for eq */
5439
+ int iCol; /* Constrained table column */
5440
+ int bFlag; /* Used by idxFindCompatible() */
5441
+ int bDesc; /* True if ORDER BY <expr> DESC */
5442
+ IdxConstraint *pNext; /* Next constraint in pEq or pRange list */
5443
+ IdxConstraint *pLink; /* See above */
5444
+};
5445
+
5446
+/*
5447
+** A single scan of a single table.
5448
+*/
5449
+struct IdxScan {
5450
+ IdxTable *pTab; /* Associated table object */
5451
+ int iDb; /* Database containing table zTable */
5452
+ i64 covering; /* Mask of columns required for cov. index */
5453
+ IdxConstraint *pOrder; /* ORDER BY columns */
5454
+ IdxConstraint *pEq; /* List of == constraints */
5455
+ IdxConstraint *pRange; /* List of < constraints */
5456
+ IdxScan *pNextScan; /* Next IdxScan object for same analysis */
5457
+};
5458
+
5459
+/*
5460
+** Information regarding a single database table. Extracted from
5461
+** "PRAGMA table_info" by function idxGetTableInfo().
5462
+*/
5463
+struct IdxColumn {
5464
+ char *zName;
5465
+ char *zColl;
5466
+ int iPk;
5467
+};
5468
+struct IdxTable {
5469
+ int nCol;
5470
+ char *zName; /* Table name */
5471
+ IdxColumn *aCol;
5472
+ IdxTable *pNext; /* Next table in linked list of all tables */
5473
+};
5474
+
5475
+/*
5476
+** An object of the following type is created for each unique table/write-op
5477
+** seen. The objects are stored in a singly-linked list beginning at
5478
+** sqlite3expert.pWrite.
5479
+*/
5480
+struct IdxWrite {
5481
+ IdxTable *pTab;
5482
+ int eOp; /* SQLITE_UPDATE, DELETE or INSERT */
5483
+ IdxWrite *pNext;
5484
+};
5485
+
5486
+/*
5487
+** Each statement being analyzed is represented by an instance of this
5488
+** structure.
5489
+*/
5490
+struct IdxStatement {
5491
+ int iId; /* Statement number */
5492
+ char *zSql; /* SQL statement */
5493
+ char *zIdx; /* Indexes */
5494
+ char *zEQP; /* Plan */
5495
+ IdxStatement *pNext;
5496
+};
5497
+
5498
+
5499
+/*
5500
+** A hash table for storing strings. With space for a payload string
5501
+** with each entry. Methods are:
5502
+**
5503
+** idxHashInit()
5504
+** idxHashClear()
5505
+** idxHashAdd()
5506
+** idxHashSearch()
5507
+*/
5508
+#define IDX_HASH_SIZE 1023
5509
+typedef struct IdxHashEntry IdxHashEntry;
5510
+typedef struct IdxHash IdxHash;
5511
+struct IdxHashEntry {
5512
+ char *zKey; /* nul-terminated key */
5513
+ char *zVal; /* nul-terminated value string */
5514
+ char *zVal2; /* nul-terminated value string 2 */
5515
+ IdxHashEntry *pHashNext; /* Next entry in same hash bucket */
5516
+ IdxHashEntry *pNext; /* Next entry in hash */
5517
+};
5518
+struct IdxHash {
5519
+ IdxHashEntry *pFirst;
5520
+ IdxHashEntry *aHash[IDX_HASH_SIZE];
5521
+};
5522
+
5523
+/*
5524
+** sqlite3expert object.
5525
+*/
5526
+struct sqlite3expert {
5527
+ int iSample; /* Percentage of tables to sample for stat1 */
5528
+ sqlite3 *db; /* User database */
5529
+ sqlite3 *dbm; /* In-memory db for this analysis */
5530
+ sqlite3 *dbv; /* Vtab schema for this analysis */
5531
+ IdxTable *pTable; /* List of all IdxTable objects */
5532
+ IdxScan *pScan; /* List of scan objects */
5533
+ IdxWrite *pWrite; /* List of write objects */
5534
+ IdxStatement *pStatement; /* List of IdxStatement objects */
5535
+ int bRun; /* True once analysis has run */
5536
+ char **pzErrmsg;
5537
+ int rc; /* Error code from whereinfo hook */
5538
+ IdxHash hIdx; /* Hash containing all candidate indexes */
5539
+ char *zCandidates; /* For EXPERT_REPORT_CANDIDATES */
5540
+};
5541
+
5542
+
5543
+/*
5544
+** Allocate and return nByte bytes of zeroed memory using sqlite3_malloc().
5545
+** If the allocation fails, set *pRc to SQLITE_NOMEM and return NULL.
5546
+*/
5547
+static void *idxMalloc(int *pRc, int nByte){
5548
+ void *pRet;
5549
+ assert( *pRc==SQLITE_OK );
5550
+ assert( nByte>0 );
5551
+ pRet = sqlite3_malloc(nByte);
5552
+ if( pRet ){
5553
+ memset(pRet, 0, nByte);
5554
+ }else{
5555
+ *pRc = SQLITE_NOMEM;
5556
+ }
5557
+ return pRet;
5558
+}
5559
+
5560
+/*
5561
+** Initialize an IdxHash hash table.
5562
+*/
5563
+static void idxHashInit(IdxHash *pHash){
5564
+ memset(pHash, 0, sizeof(IdxHash));
5565
+}
5566
+
5567
+/*
5568
+** Reset an IdxHash hash table.
5569
+*/
5570
+static void idxHashClear(IdxHash *pHash){
5571
+ int i;
5572
+ for(i=0; i<IDX_HASH_SIZE; i++){
5573
+ IdxHashEntry *pEntry;
5574
+ IdxHashEntry *pNext;
5575
+ for(pEntry=pHash->aHash[i]; pEntry; pEntry=pNext){
5576
+ pNext = pEntry->pHashNext;
5577
+ sqlite3_free(pEntry->zVal2);
5578
+ sqlite3_free(pEntry);
5579
+ }
5580
+ }
5581
+ memset(pHash, 0, sizeof(IdxHash));
5582
+}
5583
+
5584
+/*
5585
+** Return the index of the hash bucket that the string specified by the
5586
+** arguments to this function belongs.
5587
+*/
5588
+static int idxHashString(const char *z, int n){
5589
+ unsigned int ret = 0;
5590
+ int i;
5591
+ for(i=0; i<n; i++){
5592
+ ret += (ret<<3) + (unsigned char)(z[i]);
5593
+ }
5594
+ return (int)(ret % IDX_HASH_SIZE);
5595
+}
5596
+
5597
+/*
5598
+** If zKey is already present in the hash table, return non-zero and do
5599
+** nothing. Otherwise, add an entry with key zKey and payload string zVal to
5600
+** the hash table passed as the second argument.
5601
+*/
5602
+static int idxHashAdd(
5603
+ int *pRc,
5604
+ IdxHash *pHash,
5605
+ const char *zKey,
5606
+ const char *zVal
5607
+){
5608
+ int nKey = STRLEN(zKey);
5609
+ int iHash = idxHashString(zKey, nKey);
5610
+ int nVal = (zVal ? STRLEN(zVal) : 0);
5611
+ IdxHashEntry *pEntry;
5612
+ assert( iHash>=0 );
5613
+ for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){
5614
+ if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){
5615
+ return 1;
5616
+ }
5617
+ }
5618
+ pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + nKey+1 + nVal+1);
5619
+ if( pEntry ){
5620
+ pEntry->zKey = (char*)&pEntry[1];
5621
+ memcpy(pEntry->zKey, zKey, nKey);
5622
+ if( zVal ){
5623
+ pEntry->zVal = &pEntry->zKey[nKey+1];
5624
+ memcpy(pEntry->zVal, zVal, nVal);
5625
+ }
5626
+ pEntry->pHashNext = pHash->aHash[iHash];
5627
+ pHash->aHash[iHash] = pEntry;
5628
+
5629
+ pEntry->pNext = pHash->pFirst;
5630
+ pHash->pFirst = pEntry;
5631
+ }
5632
+ return 0;
5633
+}
5634
+
5635
+/*
5636
+** If zKey/nKey is present in the hash table, return a pointer to the
5637
+** hash-entry object.
5638
+*/
5639
+static IdxHashEntry *idxHashFind(IdxHash *pHash, const char *zKey, int nKey){
5640
+ int iHash;
5641
+ IdxHashEntry *pEntry;
5642
+ if( nKey<0 ) nKey = STRLEN(zKey);
5643
+ iHash = idxHashString(zKey, nKey);
5644
+ assert( iHash>=0 );
5645
+ for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){
5646
+ if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){
5647
+ return pEntry;
5648
+ }
5649
+ }
5650
+ return 0;
5651
+}
5652
+
5653
+/*
5654
+** If the hash table contains an entry with a key equal to the string
5655
+** passed as the final two arguments to this function, return a pointer
5656
+** to the payload string. Otherwise, if zKey/nKey is not present in the
5657
+** hash table, return NULL.
5658
+*/
5659
+static const char *idxHashSearch(IdxHash *pHash, const char *zKey, int nKey){
5660
+ IdxHashEntry *pEntry = idxHashFind(pHash, zKey, nKey);
5661
+ if( pEntry ) return pEntry->zVal;
5662
+ return 0;
5663
+}
5664
+
5665
+/*
5666
+** Allocate and return a new IdxConstraint object. Set the IdxConstraint.zColl
5667
+** variable to point to a copy of nul-terminated string zColl.
5668
+*/
5669
+static IdxConstraint *idxNewConstraint(int *pRc, const char *zColl){
5670
+ IdxConstraint *pNew;
5671
+ int nColl = STRLEN(zColl);
5672
+
5673
+ assert( *pRc==SQLITE_OK );
5674
+ pNew = (IdxConstraint*)idxMalloc(pRc, sizeof(IdxConstraint) * nColl + 1);
5675
+ if( pNew ){
5676
+ pNew->zColl = (char*)&pNew[1];
5677
+ memcpy(pNew->zColl, zColl, nColl+1);
5678
+ }
5679
+ return pNew;
5680
+}
5681
+
5682
+/*
5683
+** An error associated with database handle db has just occurred. Pass
5684
+** the error message to callback function xOut.
5685
+*/
5686
+static void idxDatabaseError(
5687
+ sqlite3 *db, /* Database handle */
5688
+ char **pzErrmsg /* Write error here */
5689
+){
5690
+ *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
5691
+}
5692
+
5693
+/*
5694
+** Prepare an SQL statement.
5695
+*/
5696
+static int idxPrepareStmt(
5697
+ sqlite3 *db, /* Database handle to compile against */
5698
+ sqlite3_stmt **ppStmt, /* OUT: Compiled SQL statement */
5699
+ char **pzErrmsg, /* OUT: sqlite3_malloc()ed error message */
5700
+ const char *zSql /* SQL statement to compile */
5701
+){
5702
+ int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
5703
+ if( rc!=SQLITE_OK ){
5704
+ *ppStmt = 0;
5705
+ idxDatabaseError(db, pzErrmsg);
5706
+ }
5707
+ return rc;
5708
+}
5709
+
5710
+/*
5711
+** Prepare an SQL statement using the results of a printf() formatting.
5712
+*/
5713
+static int idxPrintfPrepareStmt(
5714
+ sqlite3 *db, /* Database handle to compile against */
5715
+ sqlite3_stmt **ppStmt, /* OUT: Compiled SQL statement */
5716
+ char **pzErrmsg, /* OUT: sqlite3_malloc()ed error message */
5717
+ const char *zFmt, /* printf() format of SQL statement */
5718
+ ... /* Trailing printf() arguments */
5719
+){
5720
+ va_list ap;
5721
+ int rc;
5722
+ char *zSql;
5723
+ va_start(ap, zFmt);
5724
+ zSql = sqlite3_vmprintf(zFmt, ap);
5725
+ if( zSql==0 ){
5726
+ rc = SQLITE_NOMEM;
5727
+ }else{
5728
+ rc = idxPrepareStmt(db, ppStmt, pzErrmsg, zSql);
5729
+ sqlite3_free(zSql);
5730
+ }
5731
+ va_end(ap);
5732
+ return rc;
5733
+}
5734
+
5735
+
5736
+/*************************************************************************
5737
+** Beginning of virtual table implementation.
5738
+*/
5739
+typedef struct ExpertVtab ExpertVtab;
5740
+struct ExpertVtab {
5741
+ sqlite3_vtab base;
5742
+ IdxTable *pTab;
5743
+ sqlite3expert *pExpert;
5744
+};
5745
+
5746
+typedef struct ExpertCsr ExpertCsr;
5747
+struct ExpertCsr {
5748
+ sqlite3_vtab_cursor base;
5749
+ sqlite3_stmt *pData;
5750
+};
5751
+
5752
+static char *expertDequote(const char *zIn){
5753
+ int n = STRLEN(zIn);
5754
+ char *zRet = sqlite3_malloc(n);
5755
+
5756
+ assert( zIn[0]=='\'' );
5757
+ assert( zIn[n-1]=='\'' );
5758
+
5759
+ if( zRet ){
5760
+ int iOut = 0;
5761
+ int iIn = 0;
5762
+ for(iIn=1; iIn<(n-1); iIn++){
5763
+ if( zIn[iIn]=='\'' ){
5764
+ assert( zIn[iIn+1]=='\'' );
5765
+ iIn++;
5766
+ }
5767
+ zRet[iOut++] = zIn[iIn];
5768
+ }
5769
+ zRet[iOut] = '\0';
5770
+ }
5771
+
5772
+ return zRet;
5773
+}
5774
+
5775
+/*
5776
+** This function is the implementation of both the xConnect and xCreate
5777
+** methods of the r-tree virtual table.
5778
+**
5779
+** argv[0] -> module name
5780
+** argv[1] -> database name
5781
+** argv[2] -> table name
5782
+** argv[...] -> column names...
5783
+*/
5784
+static int expertConnect(
5785
+ sqlite3 *db,
5786
+ void *pAux,
5787
+ int argc, const char *const*argv,
5788
+ sqlite3_vtab **ppVtab,
5789
+ char **pzErr
5790
+){
5791
+ sqlite3expert *pExpert = (sqlite3expert*)pAux;
5792
+ ExpertVtab *p = 0;
5793
+ int rc;
5794
+
5795
+ if( argc!=4 ){
5796
+ *pzErr = sqlite3_mprintf("internal error!");
5797
+ rc = SQLITE_ERROR;
5798
+ }else{
5799
+ char *zCreateTable = expertDequote(argv[3]);
5800
+ if( zCreateTable ){
5801
+ rc = sqlite3_declare_vtab(db, zCreateTable);
5802
+ if( rc==SQLITE_OK ){
5803
+ p = idxMalloc(&rc, sizeof(ExpertVtab));
5804
+ }
5805
+ if( rc==SQLITE_OK ){
5806
+ p->pExpert = pExpert;
5807
+ p->pTab = pExpert->pTable;
5808
+ assert( sqlite3_stricmp(p->pTab->zName, argv[2])==0 );
5809
+ }
5810
+ sqlite3_free(zCreateTable);
5811
+ }else{
5812
+ rc = SQLITE_NOMEM;
5813
+ }
5814
+ }
5815
+
5816
+ *ppVtab = (sqlite3_vtab*)p;
5817
+ return rc;
5818
+}
5819
+
5820
+static int expertDisconnect(sqlite3_vtab *pVtab){
5821
+ ExpertVtab *p = (ExpertVtab*)pVtab;
5822
+ sqlite3_free(p);
5823
+ return SQLITE_OK;
5824
+}
5825
+
5826
+static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
5827
+ ExpertVtab *p = (ExpertVtab*)pVtab;
5828
+ int rc = SQLITE_OK;
5829
+ int n = 0;
5830
+ IdxScan *pScan;
5831
+ const int opmask =
5832
+ SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_GT |
5833
+ SQLITE_INDEX_CONSTRAINT_LT | SQLITE_INDEX_CONSTRAINT_GE |
5834
+ SQLITE_INDEX_CONSTRAINT_LE;
5835
+
5836
+ pScan = idxMalloc(&rc, sizeof(IdxScan));
5837
+ if( pScan ){
5838
+ int i;
5839
+
5840
+ /* Link the new scan object into the list */
5841
+ pScan->pTab = p->pTab;
5842
+ pScan->pNextScan = p->pExpert->pScan;
5843
+ p->pExpert->pScan = pScan;
5844
+
5845
+ /* Add the constraints to the IdxScan object */
5846
+ for(i=0; i<pIdxInfo->nConstraint; i++){
5847
+ struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
5848
+ if( pCons->usable
5849
+ && pCons->iColumn>=0
5850
+ && p->pTab->aCol[pCons->iColumn].iPk==0
5851
+ && (pCons->op & opmask)
5852
+ ){
5853
+ IdxConstraint *pNew;
5854
+ const char *zColl = sqlite3_vtab_collation(pIdxInfo, i);
5855
+ pNew = idxNewConstraint(&rc, zColl);
5856
+ if( pNew ){
5857
+ pNew->iCol = pCons->iColumn;
5858
+ if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
5859
+ pNew->pNext = pScan->pEq;
5860
+ pScan->pEq = pNew;
5861
+ }else{
5862
+ pNew->bRange = 1;
5863
+ pNew->pNext = pScan->pRange;
5864
+ pScan->pRange = pNew;
5865
+ }
5866
+ }
5867
+ n++;
5868
+ pIdxInfo->aConstraintUsage[i].argvIndex = n;
5869
+ }
5870
+ }
5871
+
5872
+ /* Add the ORDER BY to the IdxScan object */
5873
+ for(i=pIdxInfo->nOrderBy-1; i>=0; i--){
5874
+ int iCol = pIdxInfo->aOrderBy[i].iColumn;
5875
+ if( iCol>=0 ){
5876
+ IdxConstraint *pNew = idxNewConstraint(&rc, p->pTab->aCol[iCol].zColl);
5877
+ if( pNew ){
5878
+ pNew->iCol = iCol;
5879
+ pNew->bDesc = pIdxInfo->aOrderBy[i].desc;
5880
+ pNew->pNext = pScan->pOrder;
5881
+ pNew->pLink = pScan->pOrder;
5882
+ pScan->pOrder = pNew;
5883
+ n++;
5884
+ }
5885
+ }
5886
+ }
5887
+ }
5888
+
5889
+ pIdxInfo->estimatedCost = 1000000.0 / n;
5890
+ return rc;
5891
+}
5892
+
5893
+static int expertUpdate(
5894
+ sqlite3_vtab *pVtab,
5895
+ int nData,
5896
+ sqlite3_value **azData,
5897
+ sqlite_int64 *pRowid
5898
+){
5899
+ return SQLITE_OK;
5900
+}
5901
+
5902
+/*
5903
+** Virtual table module xOpen method.
5904
+*/
5905
+static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
5906
+ int rc = SQLITE_OK;
5907
+ ExpertCsr *pCsr;
5908
+ pCsr = idxMalloc(&rc, sizeof(ExpertCsr));
5909
+ *ppCursor = (sqlite3_vtab_cursor*)pCsr;
5910
+ return rc;
5911
+}
5912
+
5913
+/*
5914
+** Virtual table module xClose method.
5915
+*/
5916
+static int expertClose(sqlite3_vtab_cursor *cur){
5917
+ ExpertCsr *pCsr = (ExpertCsr*)cur;
5918
+ sqlite3_finalize(pCsr->pData);
5919
+ sqlite3_free(pCsr);
5920
+ return SQLITE_OK;
5921
+}
5922
+
5923
+/*
5924
+** Virtual table module xEof method.
5925
+**
5926
+** Return non-zero if the cursor does not currently point to a valid
5927
+** record (i.e if the scan has finished), or zero otherwise.
5928
+*/
5929
+static int expertEof(sqlite3_vtab_cursor *cur){
5930
+ ExpertCsr *pCsr = (ExpertCsr*)cur;
5931
+ return pCsr->pData==0;
5932
+}
5933
+
5934
+/*
5935
+** Virtual table module xNext method.
5936
+*/
5937
+static int expertNext(sqlite3_vtab_cursor *cur){
5938
+ ExpertCsr *pCsr = (ExpertCsr*)cur;
5939
+ int rc = SQLITE_OK;
5940
+
5941
+ assert( pCsr->pData );
5942
+ rc = sqlite3_step(pCsr->pData);
5943
+ if( rc!=SQLITE_ROW ){
5944
+ rc = sqlite3_finalize(pCsr->pData);
5945
+ pCsr->pData = 0;
5946
+ }else{
5947
+ rc = SQLITE_OK;
5948
+ }
5949
+
5950
+ return rc;
5951
+}
5952
+
5953
+/*
5954
+** Virtual table module xRowid method.
5955
+*/
5956
+static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
5957
+ *pRowid = 0;
5958
+ return SQLITE_OK;
5959
+}
5960
+
5961
+/*
5962
+** Virtual table module xColumn method.
5963
+*/
5964
+static int expertColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
5965
+ ExpertCsr *pCsr = (ExpertCsr*)cur;
5966
+ sqlite3_value *pVal;
5967
+ pVal = sqlite3_column_value(pCsr->pData, i);
5968
+ if( pVal ){
5969
+ sqlite3_result_value(ctx, pVal);
5970
+ }
5971
+ return SQLITE_OK;
5972
+}
5973
+
5974
+/*
5975
+** Virtual table module xFilter method.
5976
+*/
5977
+static int expertFilter(
5978
+ sqlite3_vtab_cursor *cur,
5979
+ int idxNum, const char *idxStr,
5980
+ int argc, sqlite3_value **argv
5981
+){
5982
+ ExpertCsr *pCsr = (ExpertCsr*)cur;
5983
+ ExpertVtab *pVtab = (ExpertVtab*)(cur->pVtab);
5984
+ sqlite3expert *pExpert = pVtab->pExpert;
5985
+ int rc;
5986
+
5987
+ rc = sqlite3_finalize(pCsr->pData);
5988
+ pCsr->pData = 0;
5989
+ if( rc==SQLITE_OK ){
5990
+ rc = idxPrintfPrepareStmt(pExpert->db, &pCsr->pData, &pVtab->base.zErrMsg,
5991
+ "SELECT * FROM main.%Q WHERE sample()", pVtab->pTab->zName
5992
+ );
5993
+ }
5994
+
5995
+ if( rc==SQLITE_OK ){
5996
+ rc = expertNext(cur);
5997
+ }
5998
+ return rc;
5999
+}
6000
+
6001
+static int idxRegisterVtab(sqlite3expert *p){
6002
+ static sqlite3_module expertModule = {
6003
+ 2, /* iVersion */
6004
+ expertConnect, /* xCreate - create a table */
6005
+ expertConnect, /* xConnect - connect to an existing table */
6006
+ expertBestIndex, /* xBestIndex - Determine search strategy */
6007
+ expertDisconnect, /* xDisconnect - Disconnect from a table */
6008
+ expertDisconnect, /* xDestroy - Drop a table */
6009
+ expertOpen, /* xOpen - open a cursor */
6010
+ expertClose, /* xClose - close a cursor */
6011
+ expertFilter, /* xFilter - configure scan constraints */
6012
+ expertNext, /* xNext - advance a cursor */
6013
+ expertEof, /* xEof */
6014
+ expertColumn, /* xColumn - read data */
6015
+ expertRowid, /* xRowid - read data */
6016
+ expertUpdate, /* xUpdate - write data */
6017
+ 0, /* xBegin - begin transaction */
6018
+ 0, /* xSync - sync transaction */
6019
+ 0, /* xCommit - commit transaction */
6020
+ 0, /* xRollback - rollback transaction */
6021
+ 0, /* xFindFunction - function overloading */
6022
+ 0, /* xRename - rename the table */
6023
+ 0, /* xSavepoint */
6024
+ 0, /* xRelease */
6025
+ 0, /* xRollbackTo */
6026
+ };
6027
+
6028
+ return sqlite3_create_module(p->dbv, "expert", &expertModule, (void*)p);
6029
+}
6030
+/*
6031
+** End of virtual table implementation.
6032
+*************************************************************************/
6033
+/*
6034
+** Finalize SQL statement pStmt. If (*pRc) is SQLITE_OK when this function
6035
+** is called, set it to the return value of sqlite3_finalize() before
6036
+** returning. Otherwise, discard the sqlite3_finalize() return value.
6037
+*/
6038
+static void idxFinalize(int *pRc, sqlite3_stmt *pStmt){
6039
+ int rc = sqlite3_finalize(pStmt);
6040
+ if( *pRc==SQLITE_OK ) *pRc = rc;
6041
+}
6042
+
6043
+/*
6044
+** Attempt to allocate an IdxTable structure corresponding to table zTab
6045
+** in the main database of connection db. If successful, set (*ppOut) to
6046
+** point to the new object and return SQLITE_OK. Otherwise, return an
6047
+** SQLite error code and set (*ppOut) to NULL. In this case *pzErrmsg may be
6048
+** set to point to an error string.
6049
+**
6050
+** It is the responsibility of the caller to eventually free either the
6051
+** IdxTable object or error message using sqlite3_free().
6052
+*/
6053
+static int idxGetTableInfo(
6054
+ sqlite3 *db, /* Database connection to read details from */
6055
+ const char *zTab, /* Table name */
6056
+ IdxTable **ppOut, /* OUT: New object (if successful) */
6057
+ char **pzErrmsg /* OUT: Error message (if not) */
6058
+){
6059
+ sqlite3_stmt *p1 = 0;
6060
+ int nCol = 0;
6061
+ int nTab = STRLEN(zTab);
6062
+ int nByte = sizeof(IdxTable) + nTab + 1;
6063
+ IdxTable *pNew = 0;
6064
+ int rc, rc2;
6065
+ char *pCsr = 0;
6066
+
6067
+ rc = idxPrintfPrepareStmt(db, &p1, pzErrmsg, "PRAGMA table_info=%Q", zTab);
6068
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
6069
+ const char *zCol = (const char*)sqlite3_column_text(p1, 1);
6070
+ nByte += 1 + STRLEN(zCol);
6071
+ rc = sqlite3_table_column_metadata(
6072
+ db, "main", zTab, zCol, 0, &zCol, 0, 0, 0
6073
+ );
6074
+ nByte += 1 + STRLEN(zCol);
6075
+ nCol++;
6076
+ }
6077
+ rc2 = sqlite3_reset(p1);
6078
+ if( rc==SQLITE_OK ) rc = rc2;
6079
+
6080
+ nByte += sizeof(IdxColumn) * nCol;
6081
+ if( rc==SQLITE_OK ){
6082
+ pNew = idxMalloc(&rc, nByte);
6083
+ }
6084
+ if( rc==SQLITE_OK ){
6085
+ pNew->aCol = (IdxColumn*)&pNew[1];
6086
+ pNew->nCol = nCol;
6087
+ pCsr = (char*)&pNew->aCol[nCol];
6088
+ }
6089
+
6090
+ nCol = 0;
6091
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
6092
+ const char *zCol = (const char*)sqlite3_column_text(p1, 1);
6093
+ int nCopy = STRLEN(zCol) + 1;
6094
+ pNew->aCol[nCol].zName = pCsr;
6095
+ pNew->aCol[nCol].iPk = sqlite3_column_int(p1, 5);
6096
+ memcpy(pCsr, zCol, nCopy);
6097
+ pCsr += nCopy;
6098
+
6099
+ rc = sqlite3_table_column_metadata(
6100
+ db, "main", zTab, zCol, 0, &zCol, 0, 0, 0
6101
+ );
6102
+ if( rc==SQLITE_OK ){
6103
+ nCopy = STRLEN(zCol) + 1;
6104
+ pNew->aCol[nCol].zColl = pCsr;
6105
+ memcpy(pCsr, zCol, nCopy);
6106
+ pCsr += nCopy;
6107
+ }
6108
+
6109
+ nCol++;
6110
+ }
6111
+ idxFinalize(&rc, p1);
6112
+
6113
+ if( rc!=SQLITE_OK ){
6114
+ sqlite3_free(pNew);
6115
+ pNew = 0;
6116
+ }else{
6117
+ pNew->zName = pCsr;
6118
+ memcpy(pNew->zName, zTab, nTab+1);
6119
+ }
6120
+
6121
+ *ppOut = pNew;
6122
+ return rc;
6123
+}
6124
+
6125
+/*
6126
+** This function is a no-op if *pRc is set to anything other than
6127
+** SQLITE_OK when it is called.
6128
+**
6129
+** If *pRc is initially set to SQLITE_OK, then the text specified by
6130
+** the printf() style arguments is appended to zIn and the result returned
6131
+** in a buffer allocated by sqlite3_malloc(). sqlite3_free() is called on
6132
+** zIn before returning.
6133
+*/
6134
+static char *idxAppendText(int *pRc, char *zIn, const char *zFmt, ...){
6135
+ va_list ap;
6136
+ char *zAppend = 0;
6137
+ char *zRet = 0;
6138
+ int nIn = zIn ? STRLEN(zIn) : 0;
6139
+ int nAppend = 0;
6140
+ va_start(ap, zFmt);
6141
+ if( *pRc==SQLITE_OK ){
6142
+ zAppend = sqlite3_vmprintf(zFmt, ap);
6143
+ if( zAppend ){
6144
+ nAppend = STRLEN(zAppend);
6145
+ zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
6146
+ }
6147
+ if( zAppend && zRet ){
6148
+ memcpy(zRet, zIn, nIn);
6149
+ memcpy(&zRet[nIn], zAppend, nAppend+1);
6150
+ }else{
6151
+ sqlite3_free(zRet);
6152
+ zRet = 0;
6153
+ *pRc = SQLITE_NOMEM;
6154
+ }
6155
+ sqlite3_free(zAppend);
6156
+ sqlite3_free(zIn);
6157
+ }
6158
+ va_end(ap);
6159
+ return zRet;
6160
+}
6161
+
6162
+/*
6163
+** Return true if zId must be quoted in order to use it as an SQL
6164
+** identifier, or false otherwise.
6165
+*/
6166
+static int idxIdentifierRequiresQuotes(const char *zId){
6167
+ int i;
6168
+ for(i=0; zId[i]; i++){
6169
+ if( !(zId[i]=='_')
6170
+ && !(zId[i]>='0' && zId[i]<='9')
6171
+ && !(zId[i]>='a' && zId[i]<='z')
6172
+ && !(zId[i]>='A' && zId[i]<='Z')
6173
+ ){
6174
+ return 1;
6175
+ }
6176
+ }
6177
+ return 0;
6178
+}
6179
+
6180
+/*
6181
+** This function appends an index column definition suitable for constraint
6182
+** pCons to the string passed as zIn and returns the result.
6183
+*/
6184
+static char *idxAppendColDefn(
6185
+ int *pRc, /* IN/OUT: Error code */
6186
+ char *zIn, /* Column defn accumulated so far */
6187
+ IdxTable *pTab, /* Table index will be created on */
6188
+ IdxConstraint *pCons
6189
+){
6190
+ char *zRet = zIn;
6191
+ IdxColumn *p = &pTab->aCol[pCons->iCol];
6192
+ if( zRet ) zRet = idxAppendText(pRc, zRet, ", ");
6193
+
6194
+ if( idxIdentifierRequiresQuotes(p->zName) ){
6195
+ zRet = idxAppendText(pRc, zRet, "%Q", p->zName);
6196
+ }else{
6197
+ zRet = idxAppendText(pRc, zRet, "%s", p->zName);
6198
+ }
6199
+
6200
+ if( sqlite3_stricmp(p->zColl, pCons->zColl) ){
6201
+ if( idxIdentifierRequiresQuotes(pCons->zColl) ){
6202
+ zRet = idxAppendText(pRc, zRet, " COLLATE %Q", pCons->zColl);
6203
+ }else{
6204
+ zRet = idxAppendText(pRc, zRet, " COLLATE %s", pCons->zColl);
6205
+ }
6206
+ }
6207
+
6208
+ if( pCons->bDesc ){
6209
+ zRet = idxAppendText(pRc, zRet, " DESC");
6210
+ }
6211
+ return zRet;
6212
+}
6213
+
6214
+/*
6215
+** Search database dbm for an index compatible with the one idxCreateFromCons()
6216
+** would create from arguments pScan, pEq and pTail. If no error occurs and
6217
+** such an index is found, return non-zero. Or, if no such index is found,
6218
+** return zero.
6219
+**
6220
+** If an error occurs, set *pRc to an SQLite error code and return zero.
6221
+*/
6222
+static int idxFindCompatible(
6223
+ int *pRc, /* OUT: Error code */
6224
+ sqlite3* dbm, /* Database to search */
6225
+ IdxScan *pScan, /* Scan for table to search for index on */
6226
+ IdxConstraint *pEq, /* List of == constraints */
6227
+ IdxConstraint *pTail /* List of range constraints */
6228
+){
6229
+ const char *zTbl = pScan->pTab->zName;
6230
+ sqlite3_stmt *pIdxList = 0;
6231
+ IdxConstraint *pIter;
6232
+ int nEq = 0; /* Number of elements in pEq */
6233
+ int rc;
6234
+
6235
+ /* Count the elements in list pEq */
6236
+ for(pIter=pEq; pIter; pIter=pIter->pLink) nEq++;
6237
+
6238
+ rc = idxPrintfPrepareStmt(dbm, &pIdxList, 0, "PRAGMA index_list=%Q", zTbl);
6239
+ while( rc==SQLITE_OK && sqlite3_step(pIdxList)==SQLITE_ROW ){
6240
+ int bMatch = 1;
6241
+ IdxConstraint *pT = pTail;
6242
+ sqlite3_stmt *pInfo = 0;
6243
+ const char *zIdx = (const char*)sqlite3_column_text(pIdxList, 1);
6244
+
6245
+ /* Zero the IdxConstraint.bFlag values in the pEq list */
6246
+ for(pIter=pEq; pIter; pIter=pIter->pLink) pIter->bFlag = 0;
6247
+
6248
+ rc = idxPrintfPrepareStmt(dbm, &pInfo, 0, "PRAGMA index_xInfo=%Q", zIdx);
6249
+ while( rc==SQLITE_OK && sqlite3_step(pInfo)==SQLITE_ROW ){
6250
+ int iIdx = sqlite3_column_int(pInfo, 0);
6251
+ int iCol = sqlite3_column_int(pInfo, 1);
6252
+ const char *zColl = (const char*)sqlite3_column_text(pInfo, 4);
6253
+
6254
+ if( iIdx<nEq ){
6255
+ for(pIter=pEq; pIter; pIter=pIter->pLink){
6256
+ if( pIter->bFlag ) continue;
6257
+ if( pIter->iCol!=iCol ) continue;
6258
+ if( sqlite3_stricmp(pIter->zColl, zColl) ) continue;
6259
+ pIter->bFlag = 1;
6260
+ break;
6261
+ }
6262
+ if( pIter==0 ){
6263
+ bMatch = 0;
6264
+ break;
6265
+ }
6266
+ }else{
6267
+ if( pT ){
6268
+ if( pT->iCol!=iCol || sqlite3_stricmp(pT->zColl, zColl) ){
6269
+ bMatch = 0;
6270
+ break;
6271
+ }
6272
+ pT = pT->pLink;
6273
+ }
6274
+ }
6275
+ }
6276
+ idxFinalize(&rc, pInfo);
6277
+
6278
+ if( rc==SQLITE_OK && bMatch ){
6279
+ sqlite3_finalize(pIdxList);
6280
+ return 1;
6281
+ }
6282
+ }
6283
+ idxFinalize(&rc, pIdxList);
6284
+
6285
+ *pRc = rc;
6286
+ return 0;
6287
+}
6288
+
6289
+static int idxCreateFromCons(
6290
+ sqlite3expert *p,
6291
+ IdxScan *pScan,
6292
+ IdxConstraint *pEq,
6293
+ IdxConstraint *pTail
6294
+){
6295
+ sqlite3 *dbm = p->dbm;
6296
+ int rc = SQLITE_OK;
6297
+ if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){
6298
+ IdxTable *pTab = pScan->pTab;
6299
+ char *zCols = 0;
6300
+ char *zIdx = 0;
6301
+ IdxConstraint *pCons;
6302
+ int h = 0;
6303
+ const char *zFmt;
6304
+
6305
+ for(pCons=pEq; pCons; pCons=pCons->pLink){
6306
+ zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
6307
+ }
6308
+ for(pCons=pTail; pCons; pCons=pCons->pLink){
6309
+ zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
6310
+ }
6311
+
6312
+ if( rc==SQLITE_OK ){
6313
+ /* Hash the list of columns to come up with a name for the index */
6314
+ const char *zTable = pScan->pTab->zName;
6315
+ char *zName; /* Index name */
6316
+ int i;
6317
+ for(i=0; zCols[i]; i++){
6318
+ h += ((h<<3) + zCols[i]);
6319
+ }
6320
+ zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
6321
+ if( zName==0 ){
6322
+ rc = SQLITE_NOMEM;
6323
+ }else{
6324
+ if( idxIdentifierRequiresQuotes(zTable) ){
6325
+ zFmt = "CREATE INDEX '%q' ON %Q(%s)";
6326
+ }else{
6327
+ zFmt = "CREATE INDEX %s ON %s(%s)";
6328
+ }
6329
+ zIdx = sqlite3_mprintf(zFmt, zName, zTable, zCols);
6330
+ if( !zIdx ){
6331
+ rc = SQLITE_NOMEM;
6332
+ }else{
6333
+ rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg);
6334
+ idxHashAdd(&rc, &p->hIdx, zName, zIdx);
6335
+ }
6336
+ sqlite3_free(zName);
6337
+ sqlite3_free(zIdx);
6338
+ }
6339
+ }
6340
+
6341
+ sqlite3_free(zCols);
6342
+ }
6343
+ return rc;
6344
+}
6345
+
6346
+/*
6347
+** Return true if list pList (linked by IdxConstraint.pLink) contains
6348
+** a constraint compatible with *p. Otherwise return false.
6349
+*/
6350
+static int idxFindConstraint(IdxConstraint *pList, IdxConstraint *p){
6351
+ IdxConstraint *pCmp;
6352
+ for(pCmp=pList; pCmp; pCmp=pCmp->pLink){
6353
+ if( p->iCol==pCmp->iCol ) return 1;
6354
+ }
6355
+ return 0;
6356
+}
6357
+
6358
+static int idxCreateFromWhere(
6359
+ sqlite3expert *p,
6360
+ IdxScan *pScan, /* Create indexes for this scan */
6361
+ IdxConstraint *pTail /* range/ORDER BY constraints for inclusion */
6362
+){
6363
+ IdxConstraint *p1 = 0;
6364
+ IdxConstraint *pCon;
6365
+ int rc;
6366
+
6367
+ /* Gather up all the == constraints. */
6368
+ for(pCon=pScan->pEq; pCon; pCon=pCon->pNext){
6369
+ if( !idxFindConstraint(p1, pCon) && !idxFindConstraint(pTail, pCon) ){
6370
+ pCon->pLink = p1;
6371
+ p1 = pCon;
6372
+ }
6373
+ }
6374
+
6375
+ /* Create an index using the == constraints collected above. And the
6376
+ ** range constraint/ORDER BY terms passed in by the caller, if any. */
6377
+ rc = idxCreateFromCons(p, pScan, p1, pTail);
6378
+
6379
+ /* If no range/ORDER BY passed by the caller, create a version of the
6380
+ ** index for each range constraint. */
6381
+ if( pTail==0 ){
6382
+ for(pCon=pScan->pRange; rc==SQLITE_OK && pCon; pCon=pCon->pNext){
6383
+ assert( pCon->pLink==0 );
6384
+ if( !idxFindConstraint(p1, pCon) && !idxFindConstraint(pTail, pCon) ){
6385
+ rc = idxCreateFromCons(p, pScan, p1, pCon);
6386
+ }
6387
+ }
6388
+ }
6389
+
6390
+ return rc;
6391
+}
6392
+
6393
+/*
6394
+** Create candidate indexes in database [dbm] based on the data in
6395
+** linked-list pScan.
6396
+*/
6397
+static int idxCreateCandidates(sqlite3expert *p, char **pzErr){
6398
+ int rc = SQLITE_OK;
6399
+ IdxScan *pIter;
6400
+
6401
+ for(pIter=p->pScan; pIter && rc==SQLITE_OK; pIter=pIter->pNextScan){
6402
+ rc = idxCreateFromWhere(p, pIter, 0);
6403
+ if( rc==SQLITE_OK && pIter->pOrder ){
6404
+ rc = idxCreateFromWhere(p, pIter, pIter->pOrder);
6405
+ }
6406
+ }
6407
+
6408
+ return rc;
6409
+}
6410
+
6411
+/*
6412
+** Free all elements of the linked list starting at pConstraint.
6413
+*/
6414
+static void idxConstraintFree(IdxConstraint *pConstraint){
6415
+ IdxConstraint *pNext;
6416
+ IdxConstraint *p;
6417
+
6418
+ for(p=pConstraint; p; p=pNext){
6419
+ pNext = p->pNext;
6420
+ sqlite3_free(p);
6421
+ }
6422
+}
6423
+
6424
+/*
6425
+** Free all elements of the linked list starting from pScan up until pLast
6426
+** (pLast is not freed).
6427
+*/
6428
+static void idxScanFree(IdxScan *pScan, IdxScan *pLast){
6429
+ IdxScan *p;
6430
+ IdxScan *pNext;
6431
+ for(p=pScan; p!=pLast; p=pNext){
6432
+ pNext = p->pNextScan;
6433
+ idxConstraintFree(p->pOrder);
6434
+ idxConstraintFree(p->pEq);
6435
+ idxConstraintFree(p->pRange);
6436
+ sqlite3_free(p);
6437
+ }
6438
+}
6439
+
6440
+/*
6441
+** Free all elements of the linked list starting from pStatement up
6442
+** until pLast (pLast is not freed).
6443
+*/
6444
+static void idxStatementFree(IdxStatement *pStatement, IdxStatement *pLast){
6445
+ IdxStatement *p;
6446
+ IdxStatement *pNext;
6447
+ for(p=pStatement; p!=pLast; p=pNext){
6448
+ pNext = p->pNext;
6449
+ sqlite3_free(p->zEQP);
6450
+ sqlite3_free(p->zIdx);
6451
+ sqlite3_free(p);
6452
+ }
6453
+}
6454
+
6455
+/*
6456
+** Free the linked list of IdxTable objects starting at pTab.
6457
+*/
6458
+static void idxTableFree(IdxTable *pTab){
6459
+ IdxTable *pIter;
6460
+ IdxTable *pNext;
6461
+ for(pIter=pTab; pIter; pIter=pNext){
6462
+ pNext = pIter->pNext;
6463
+ sqlite3_free(pIter);
6464
+ }
6465
+}
6466
+
6467
+/*
6468
+** Free the linked list of IdxWrite objects starting at pTab.
6469
+*/
6470
+static void idxWriteFree(IdxWrite *pTab){
6471
+ IdxWrite *pIter;
6472
+ IdxWrite *pNext;
6473
+ for(pIter=pTab; pIter; pIter=pNext){
6474
+ pNext = pIter->pNext;
6475
+ sqlite3_free(pIter);
6476
+ }
6477
+}
6478
+
6479
+
6480
+
6481
+/*
6482
+** This function is called after candidate indexes have been created. It
6483
+** runs all the queries to see which indexes they prefer, and populates
6484
+** IdxStatement.zIdx and IdxStatement.zEQP with the results.
6485
+*/
6486
+int idxFindIndexes(
6487
+ sqlite3expert *p,
6488
+ char **pzErr /* OUT: Error message (sqlite3_malloc) */
6489
+){
6490
+ IdxStatement *pStmt;
6491
+ sqlite3 *dbm = p->dbm;
6492
+ int rc = SQLITE_OK;
6493
+
6494
+ IdxHash hIdx;
6495
+ idxHashInit(&hIdx);
6496
+
6497
+ for(pStmt=p->pStatement; rc==SQLITE_OK && pStmt; pStmt=pStmt->pNext){
6498
+ IdxHashEntry *pEntry;
6499
+ sqlite3_stmt *pExplain = 0;
6500
+ idxHashClear(&hIdx);
6501
+ rc = idxPrintfPrepareStmt(dbm, &pExplain, pzErr,
6502
+ "EXPLAIN QUERY PLAN %s", pStmt->zSql
6503
+ );
6504
+ while( rc==SQLITE_OK && sqlite3_step(pExplain)==SQLITE_ROW ){
6505
+ int iSelectid = sqlite3_column_int(pExplain, 0);
6506
+ int iOrder = sqlite3_column_int(pExplain, 1);
6507
+ int iFrom = sqlite3_column_int(pExplain, 2);
6508
+ const char *zDetail = (const char*)sqlite3_column_text(pExplain, 3);
6509
+ int nDetail = STRLEN(zDetail);
6510
+ int i;
6511
+
6512
+ for(i=0; i<nDetail; i++){
6513
+ const char *zIdx = 0;
6514
+ if( memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
6515
+ zIdx = &zDetail[i+13];
6516
+ }else if( memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0 ){
6517
+ zIdx = &zDetail[i+22];
6518
+ }
6519
+ if( zIdx ){
6520
+ const char *zSql;
6521
+ int nIdx = 0;
6522
+ while( zIdx[nIdx]!='\0' && (zIdx[nIdx]!=' ' || zIdx[nIdx+1]!='(') ){
6523
+ nIdx++;
6524
+ }
6525
+ zSql = idxHashSearch(&p->hIdx, zIdx, nIdx);
6526
+ if( zSql ){
6527
+ idxHashAdd(&rc, &hIdx, zSql, 0);
6528
+ if( rc ) goto find_indexes_out;
6529
+ }
6530
+ break;
6531
+ }
6532
+ }
6533
+
6534
+ pStmt->zEQP = idxAppendText(&rc, pStmt->zEQP, "%d|%d|%d|%s\n",
6535
+ iSelectid, iOrder, iFrom, zDetail
6536
+ );
6537
+ }
6538
+
6539
+ for(pEntry=hIdx.pFirst; pEntry; pEntry=pEntry->pNext){
6540
+ pStmt->zIdx = idxAppendText(&rc, pStmt->zIdx, "%s;\n", pEntry->zKey);
6541
+ }
6542
+
6543
+ idxFinalize(&rc, pExplain);
6544
+ }
6545
+
6546
+ find_indexes_out:
6547
+ idxHashClear(&hIdx);
6548
+ return rc;
6549
+}
6550
+
6551
+static int idxAuthCallback(
6552
+ void *pCtx,
6553
+ int eOp,
6554
+ const char *z3,
6555
+ const char *z4,
6556
+ const char *zDb,
6557
+ const char *zTrigger
6558
+){
6559
+ int rc = SQLITE_OK;
6560
+ if( eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE || eOp==SQLITE_DELETE ){
6561
+ if( sqlite3_stricmp(zDb, "main")==0 ){
6562
+ sqlite3expert *p = (sqlite3expert*)pCtx;
6563
+ IdxTable *pTab;
6564
+ for(pTab=p->pTable; pTab; pTab=pTab->pNext){
6565
+ if( 0==sqlite3_stricmp(z3, pTab->zName) ) break;
6566
+ }
6567
+ if( pTab ){
6568
+ IdxWrite *pWrite;
6569
+ for(pWrite=p->pWrite; pWrite; pWrite=pWrite->pNext){
6570
+ if( pWrite->pTab==pTab && pWrite->eOp==eOp ) break;
6571
+ }
6572
+ if( pWrite==0 ){
6573
+ pWrite = idxMalloc(&rc, sizeof(IdxWrite));
6574
+ if( rc==SQLITE_OK ){
6575
+ pWrite->pTab = pTab;
6576
+ pWrite->eOp = eOp;
6577
+ pWrite->pNext = p->pWrite;
6578
+ p->pWrite = pWrite;
6579
+ }
6580
+ }
6581
+ }
6582
+ }
6583
+ }
6584
+ return rc;
6585
+}
6586
+
6587
+static int idxProcessOneTrigger(
6588
+ sqlite3expert *p,
6589
+ IdxWrite *pWrite,
6590
+ char **pzErr
6591
+){
6592
+ static const char *zInt = UNIQUE_TABLE_NAME;
6593
+ static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
6594
+ IdxTable *pTab = pWrite->pTab;
6595
+ const char *zTab = pTab->zName;
6596
+ const char *zSql =
6597
+ "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_master "
6598
+ "WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
6599
+ "ORDER BY type;";
6600
+ sqlite3_stmt *pSelect = 0;
6601
+ int rc = SQLITE_OK;
6602
+ char *zWrite = 0;
6603
+
6604
+ /* Create the table and its triggers in the temp schema */
6605
+ rc = idxPrintfPrepareStmt(p->db, &pSelect, pzErr, zSql, zTab, zTab);
6606
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSelect) ){
6607
+ const char *zCreate = (const char*)sqlite3_column_text(pSelect, 0);
6608
+ rc = sqlite3_exec(p->dbv, zCreate, 0, 0, pzErr);
6609
+ }
6610
+ idxFinalize(&rc, pSelect);
6611
+
6612
+ /* Rename the table in the temp schema to zInt */
6613
+ if( rc==SQLITE_OK ){
6614
+ char *z = sqlite3_mprintf("ALTER TABLE temp.%Q RENAME TO %Q", zTab, zInt);
6615
+ if( z==0 ){
6616
+ rc = SQLITE_NOMEM;
6617
+ }else{
6618
+ rc = sqlite3_exec(p->dbv, z, 0, 0, pzErr);
6619
+ sqlite3_free(z);
6620
+ }
6621
+ }
6622
+
6623
+ switch( pWrite->eOp ){
6624
+ case SQLITE_INSERT: {
6625
+ int i;
6626
+ zWrite = idxAppendText(&rc, zWrite, "INSERT INTO %Q VALUES(", zInt);
6627
+ for(i=0; i<pTab->nCol; i++){
6628
+ zWrite = idxAppendText(&rc, zWrite, "%s?", i==0 ? "" : ", ");
6629
+ }
6630
+ zWrite = idxAppendText(&rc, zWrite, ")");
6631
+ break;
6632
+ }
6633
+ case SQLITE_UPDATE: {
6634
+ int i;
6635
+ zWrite = idxAppendText(&rc, zWrite, "UPDATE %Q SET ", zInt);
6636
+ for(i=0; i<pTab->nCol; i++){
6637
+ zWrite = idxAppendText(&rc, zWrite, "%s%Q=?", i==0 ? "" : ", ",
6638
+ pTab->aCol[i].zName
6639
+ );
6640
+ }
6641
+ break;
6642
+ }
6643
+ default: {
6644
+ assert( pWrite->eOp==SQLITE_DELETE );
6645
+ if( rc==SQLITE_OK ){
6646
+ zWrite = sqlite3_mprintf("DELETE FROM %Q", zInt);
6647
+ if( zWrite==0 ) rc = SQLITE_NOMEM;
6648
+ }
6649
+ }
6650
+ }
6651
+
6652
+ if( rc==SQLITE_OK ){
6653
+ sqlite3_stmt *pX = 0;
6654
+ rc = sqlite3_prepare_v2(p->dbv, zWrite, -1, &pX, 0);
6655
+ idxFinalize(&rc, pX);
6656
+ if( rc!=SQLITE_OK ){
6657
+ idxDatabaseError(p->dbv, pzErr);
6658
+ }
6659
+ }
6660
+ sqlite3_free(zWrite);
6661
+
6662
+ if( rc==SQLITE_OK ){
6663
+ rc = sqlite3_exec(p->dbv, zDrop, 0, 0, pzErr);
6664
+ }
6665
+
6666
+ return rc;
6667
+}
6668
+
6669
+static int idxProcessTriggers(sqlite3expert *p, char **pzErr){
6670
+ int rc = SQLITE_OK;
6671
+ IdxWrite *pEnd = 0;
6672
+ IdxWrite *pFirst = p->pWrite;
6673
+
6674
+ while( rc==SQLITE_OK && pFirst!=pEnd ){
6675
+ IdxWrite *pIter;
6676
+ for(pIter=pFirst; rc==SQLITE_OK && pIter!=pEnd; pIter=pIter->pNext){
6677
+ rc = idxProcessOneTrigger(p, pIter, pzErr);
6678
+ }
6679
+ pEnd = pFirst;
6680
+ pFirst = p->pWrite;
6681
+ }
6682
+
6683
+ return rc;
6684
+}
6685
+
6686
+
6687
+static int idxCreateVtabSchema(sqlite3expert *p, char **pzErrmsg){
6688
+ int rc = idxRegisterVtab(p);
6689
+ sqlite3_stmt *pSchema = 0;
6690
+
6691
+ /* For each table in the main db schema:
6692
+ **
6693
+ ** 1) Add an entry to the p->pTable list, and
6694
+ ** 2) Create the equivalent virtual table in dbv.
6695
+ */
6696
+ rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
6697
+ "SELECT type, name, sql, 1 FROM sqlite_master "
6698
+ "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' "
6699
+ " UNION ALL "
6700
+ "SELECT type, name, sql, 2 FROM sqlite_master "
6701
+ "WHERE type = 'trigger'"
6702
+ " AND tbl_name IN(SELECT name FROM sqlite_master WHERE type = 'view') "
6703
+ "ORDER BY 4, 1"
6704
+ );
6705
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSchema) ){
6706
+ const char *zType = (const char*)sqlite3_column_text(pSchema, 0);
6707
+ const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
6708
+ const char *zSql = (const char*)sqlite3_column_text(pSchema, 2);
6709
+
6710
+ if( zType[0]=='v' || zType[1]=='r' ){
6711
+ rc = sqlite3_exec(p->dbv, zSql, 0, 0, pzErrmsg);
6712
+ }else{
6713
+ IdxTable *pTab;
6714
+ rc = idxGetTableInfo(p->db, zName, &pTab, pzErrmsg);
6715
+ if( rc==SQLITE_OK ){
6716
+ int i;
6717
+ char *zInner = 0;
6718
+ char *zOuter = 0;
6719
+ pTab->pNext = p->pTable;
6720
+ p->pTable = pTab;
6721
+
6722
+ /* The statement the vtab will pass to sqlite3_declare_vtab() */
6723
+ zInner = idxAppendText(&rc, 0, "CREATE TABLE x(");
6724
+ for(i=0; i<pTab->nCol; i++){
6725
+ zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s",
6726
+ (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl
6727
+ );
6728
+ }
6729
+ zInner = idxAppendText(&rc, zInner, ")");
6730
+
6731
+ /* The CVT statement to create the vtab */
6732
+ zOuter = idxAppendText(&rc, 0,
6733
+ "CREATE VIRTUAL TABLE %Q USING expert(%Q)", zName, zInner
6734
+ );
6735
+ if( rc==SQLITE_OK ){
6736
+ rc = sqlite3_exec(p->dbv, zOuter, 0, 0, pzErrmsg);
6737
+ }
6738
+ sqlite3_free(zInner);
6739
+ sqlite3_free(zOuter);
6740
+ }
6741
+ }
6742
+ }
6743
+ idxFinalize(&rc, pSchema);
6744
+ return rc;
6745
+}
6746
+
6747
+struct IdxSampleCtx {
6748
+ int iTarget;
6749
+ double target; /* Target nRet/nRow value */
6750
+ double nRow; /* Number of rows seen */
6751
+ double nRet; /* Number of rows returned */
6752
+};
6753
+
6754
+static void idxSampleFunc(
6755
+ sqlite3_context *pCtx,
6756
+ int argc,
6757
+ sqlite3_value **argv
6758
+){
6759
+ struct IdxSampleCtx *p = (struct IdxSampleCtx*)sqlite3_user_data(pCtx);
6760
+ int bRet;
6761
+
6762
+ assert( argc==0 );
6763
+ if( p->nRow==0.0 ){
6764
+ bRet = 1;
6765
+ }else{
6766
+ bRet = (p->nRet / p->nRow) <= p->target;
6767
+ if( bRet==0 ){
6768
+ unsigned short rnd;
6769
+ sqlite3_randomness(2, (void*)&rnd);
6770
+ bRet = ((int)rnd % 100) <= p->iTarget;
6771
+ }
6772
+ }
6773
+
6774
+ sqlite3_result_int(pCtx, bRet);
6775
+ p->nRow += 1.0;
6776
+ p->nRet += (double)bRet;
6777
+}
6778
+
6779
+struct IdxRemCtx {
6780
+ int nSlot;
6781
+ struct IdxRemSlot {
6782
+ int eType; /* SQLITE_NULL, INTEGER, REAL, TEXT, BLOB */
6783
+ i64 iVal; /* SQLITE_INTEGER value */
6784
+ double rVal; /* SQLITE_FLOAT value */
6785
+ int nByte; /* Bytes of space allocated at z */
6786
+ int n; /* Size of buffer z */
6787
+ char *z; /* SQLITE_TEXT/BLOB value */
6788
+ } aSlot[1];
6789
+};
6790
+
6791
+/*
6792
+** Implementation of scalar function rem().
6793
+*/
6794
+static void idxRemFunc(
6795
+ sqlite3_context *pCtx,
6796
+ int argc,
6797
+ sqlite3_value **argv
6798
+){
6799
+ struct IdxRemCtx *p = (struct IdxRemCtx*)sqlite3_user_data(pCtx);
6800
+ struct IdxRemSlot *pSlot;
6801
+ int iSlot;
6802
+ assert( argc==2 );
6803
+
6804
+ iSlot = sqlite3_value_int(argv[0]);
6805
+ assert( iSlot<=p->nSlot );
6806
+ pSlot = &p->aSlot[iSlot];
6807
+
6808
+ switch( pSlot->eType ){
6809
+ case SQLITE_NULL:
6810
+ /* no-op */
6811
+ break;
6812
+
6813
+ case SQLITE_INTEGER:
6814
+ sqlite3_result_int64(pCtx, pSlot->iVal);
6815
+ break;
6816
+
6817
+ case SQLITE_FLOAT:
6818
+ sqlite3_result_double(pCtx, pSlot->rVal);
6819
+ break;
6820
+
6821
+ case SQLITE_BLOB:
6822
+ sqlite3_result_blob(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
6823
+ break;
6824
+
6825
+ case SQLITE_TEXT:
6826
+ sqlite3_result_text(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
6827
+ break;
6828
+ }
6829
+
6830
+ pSlot->eType = sqlite3_value_type(argv[1]);
6831
+ switch( pSlot->eType ){
6832
+ case SQLITE_NULL:
6833
+ /* no-op */
6834
+ break;
6835
+
6836
+ case SQLITE_INTEGER:
6837
+ pSlot->iVal = sqlite3_value_int64(argv[1]);
6838
+ break;
6839
+
6840
+ case SQLITE_FLOAT:
6841
+ pSlot->rVal = sqlite3_value_double(argv[1]);
6842
+ break;
6843
+
6844
+ case SQLITE_BLOB:
6845
+ case SQLITE_TEXT: {
6846
+ int nByte = sqlite3_value_bytes(argv[1]);
6847
+ if( nByte>pSlot->nByte ){
6848
+ char *zNew = (char*)sqlite3_realloc(pSlot->z, nByte*2);
6849
+ if( zNew==0 ){
6850
+ sqlite3_result_error_nomem(pCtx);
6851
+ return;
6852
+ }
6853
+ pSlot->nByte = nByte*2;
6854
+ pSlot->z = zNew;
6855
+ }
6856
+ pSlot->n = nByte;
6857
+ if( pSlot->eType==SQLITE_BLOB ){
6858
+ memcpy(pSlot->z, sqlite3_value_blob(argv[1]), nByte);
6859
+ }else{
6860
+ memcpy(pSlot->z, sqlite3_value_text(argv[1]), nByte);
6861
+ }
6862
+ break;
6863
+ }
6864
+ }
6865
+}
6866
+
6867
+static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr){
6868
+ int rc = SQLITE_OK;
6869
+ const char *zMax =
6870
+ "SELECT max(i.seqno) FROM "
6871
+ " sqlite_master AS s, "
6872
+ " pragma_index_list(s.name) AS l, "
6873
+ " pragma_index_info(l.name) AS i "
6874
+ "WHERE s.type = 'table'";
6875
+ sqlite3_stmt *pMax = 0;
6876
+
6877
+ *pnMax = 0;
6878
+ rc = idxPrepareStmt(db, &pMax, pzErr, zMax);
6879
+ if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pMax) ){
6880
+ *pnMax = sqlite3_column_int(pMax, 0) + 1;
6881
+ }
6882
+ idxFinalize(&rc, pMax);
6883
+
6884
+ return rc;
6885
+}
6886
+
6887
+static int idxPopulateOneStat1(
6888
+ sqlite3expert *p,
6889
+ sqlite3_stmt *pIndexXInfo,
6890
+ sqlite3_stmt *pWriteStat,
6891
+ const char *zTab,
6892
+ const char *zIdx,
6893
+ char **pzErr
6894
+){
6895
+ char *zCols = 0;
6896
+ char *zOrder = 0;
6897
+ char *zQuery = 0;
6898
+ int nCol = 0;
6899
+ int i;
6900
+ sqlite3_stmt *pQuery = 0;
6901
+ int *aStat = 0;
6902
+ int rc = SQLITE_OK;
6903
+
6904
+ assert( p->iSample>0 );
6905
+
6906
+ /* Formulate the query text */
6907
+ sqlite3_bind_text(pIndexXInfo, 1, zIdx, -1, SQLITE_STATIC);
6908
+ while( SQLITE_OK==rc && SQLITE_ROW==sqlite3_step(pIndexXInfo) ){
6909
+ const char *zComma = zCols==0 ? "" : ", ";
6910
+ const char *zName = (const char*)sqlite3_column_text(pIndexXInfo, 0);
6911
+ const char *zColl = (const char*)sqlite3_column_text(pIndexXInfo, 1);
6912
+ zCols = idxAppendText(&rc, zCols,
6913
+ "%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl
6914
+ );
6915
+ zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
6916
+ }
6917
+ if( rc==SQLITE_OK ){
6918
+ if( p->iSample==100 ){
6919
+ zQuery = sqlite3_mprintf(
6920
+ "SELECT %s FROM %Q x ORDER BY %s", zCols, zTab, zOrder
6921
+ );
6922
+ }else{
6923
+ zQuery = sqlite3_mprintf(
6924
+ "SELECT %s FROM temp."UNIQUE_TABLE_NAME" x ORDER BY %s", zCols, zOrder
6925
+ );
6926
+ }
6927
+ }
6928
+ sqlite3_free(zCols);
6929
+ sqlite3_free(zOrder);
6930
+
6931
+ /* Formulate the query text */
6932
+ if( rc==SQLITE_OK ){
6933
+ sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv);
6934
+ rc = idxPrepareStmt(dbrem, &pQuery, pzErr, zQuery);
6935
+ }
6936
+ sqlite3_free(zQuery);
6937
+
6938
+ if( rc==SQLITE_OK ){
6939
+ aStat = (int*)idxMalloc(&rc, sizeof(int)*(nCol+1));
6940
+ }
6941
+ if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){
6942
+ IdxHashEntry *pEntry;
6943
+ char *zStat = 0;
6944
+ for(i=0; i<=nCol; i++) aStat[i] = 1;
6945
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){
6946
+ aStat[0]++;
6947
+ for(i=0; i<nCol; i++){
6948
+ if( sqlite3_column_int(pQuery, i)==0 ) break;
6949
+ }
6950
+ for(/*no-op*/; i<nCol; i++){
6951
+ aStat[i+1]++;
6952
+ }
6953
+ }
6954
+
6955
+ if( rc==SQLITE_OK ){
6956
+ int s0 = aStat[0];
6957
+ zStat = sqlite3_mprintf("%d", s0);
6958
+ if( zStat==0 ) rc = SQLITE_NOMEM;
6959
+ for(i=1; rc==SQLITE_OK && i<=nCol; i++){
6960
+ zStat = idxAppendText(&rc, zStat, " %d", (s0+aStat[i]/2) / aStat[i]);
6961
+ }
6962
+ }
6963
+
6964
+ if( rc==SQLITE_OK ){
6965
+ sqlite3_bind_text(pWriteStat, 1, zTab, -1, SQLITE_STATIC);
6966
+ sqlite3_bind_text(pWriteStat, 2, zIdx, -1, SQLITE_STATIC);
6967
+ sqlite3_bind_text(pWriteStat, 3, zStat, -1, SQLITE_STATIC);
6968
+ sqlite3_step(pWriteStat);
6969
+ rc = sqlite3_reset(pWriteStat);
6970
+ }
6971
+
6972
+ pEntry = idxHashFind(&p->hIdx, zIdx, STRLEN(zIdx));
6973
+ if( pEntry ){
6974
+ assert( pEntry->zVal2==0 );
6975
+ pEntry->zVal2 = zStat;
6976
+ }else{
6977
+ sqlite3_free(zStat);
6978
+ }
6979
+ }
6980
+ sqlite3_free(aStat);
6981
+ idxFinalize(&rc, pQuery);
6982
+
6983
+ return rc;
6984
+}
6985
+
6986
+static int idxBuildSampleTable(sqlite3expert *p, const char *zTab){
6987
+ int rc;
6988
+ char *zSql;
6989
+
6990
+ rc = sqlite3_exec(p->dbv,"DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
6991
+ if( rc!=SQLITE_OK ) return rc;
6992
+
6993
+ zSql = sqlite3_mprintf(
6994
+ "CREATE TABLE temp." UNIQUE_TABLE_NAME " AS SELECT * FROM %Q", zTab
6995
+ );
6996
+ if( zSql==0 ) return SQLITE_NOMEM;
6997
+ rc = sqlite3_exec(p->dbv, zSql, 0, 0, 0);
6998
+ sqlite3_free(zSql);
6999
+
7000
+ return rc;
7001
+}
7002
+
7003
+/*
7004
+** This function is called as part of sqlite3_expert_analyze(). Candidate
7005
+** indexes have already been created in database sqlite3expert.dbm, this
7006
+** function populates sqlite_stat1 table in the same database.
7007
+**
7008
+** The stat1 data is generated by querying the
7009
+*/
7010
+static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
7011
+ int rc = SQLITE_OK;
7012
+ int nMax =0;
7013
+ struct IdxRemCtx *pCtx = 0;
7014
+ struct IdxSampleCtx samplectx;
7015
+ int i;
7016
+ i64 iPrev = -100000;
7017
+ sqlite3_stmt *pAllIndex = 0;
7018
+ sqlite3_stmt *pIndexXInfo = 0;
7019
+ sqlite3_stmt *pWrite = 0;
7020
+
7021
+ const char *zAllIndex =
7022
+ "SELECT s.rowid, s.name, l.name FROM "
7023
+ " sqlite_master AS s, "
7024
+ " pragma_index_list(s.name) AS l "
7025
+ "WHERE s.type = 'table'";
7026
+ const char *zIndexXInfo =
7027
+ "SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
7028
+ const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
7029
+
7030
+ /* If iSample==0, no sqlite_stat1 data is required. */
7031
+ if( p->iSample==0 ) return SQLITE_OK;
7032
+
7033
+ rc = idxLargestIndex(p->dbm, &nMax, pzErr);
7034
+ if( nMax<=0 || rc!=SQLITE_OK ) return rc;
7035
+
7036
+ rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0);
7037
+
7038
+ if( rc==SQLITE_OK ){
7039
+ int nByte = sizeof(struct IdxRemCtx) + (sizeof(struct IdxRemSlot) * nMax);
7040
+ pCtx = (struct IdxRemCtx*)idxMalloc(&rc, nByte);
7041
+ }
7042
+
7043
+ if( rc==SQLITE_OK ){
7044
+ sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv);
7045
+ rc = sqlite3_create_function(
7046
+ dbrem, "rem", 2, SQLITE_UTF8, (void*)pCtx, idxRemFunc, 0, 0
7047
+ );
7048
+ }
7049
+ if( rc==SQLITE_OK ){
7050
+ rc = sqlite3_create_function(
7051
+ p->db, "sample", 0, SQLITE_UTF8, (void*)&samplectx, idxSampleFunc, 0, 0
7052
+ );
7053
+ }
7054
+
7055
+ if( rc==SQLITE_OK ){
7056
+ pCtx->nSlot = nMax+1;
7057
+ rc = idxPrepareStmt(p->dbm, &pAllIndex, pzErr, zAllIndex);
7058
+ }
7059
+ if( rc==SQLITE_OK ){
7060
+ rc = idxPrepareStmt(p->dbm, &pIndexXInfo, pzErr, zIndexXInfo);
7061
+ }
7062
+ if( rc==SQLITE_OK ){
7063
+ rc = idxPrepareStmt(p->dbm, &pWrite, pzErr, zWrite);
7064
+ }
7065
+
7066
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pAllIndex) ){
7067
+ i64 iRowid = sqlite3_column_int64(pAllIndex, 0);
7068
+ const char *zTab = (const char*)sqlite3_column_text(pAllIndex, 1);
7069
+ const char *zIdx = (const char*)sqlite3_column_text(pAllIndex, 2);
7070
+ if( p->iSample<100 && iPrev!=iRowid ){
7071
+ samplectx.target = (double)p->iSample / 100.0;
7072
+ samplectx.iTarget = p->iSample;
7073
+ samplectx.nRow = 0.0;
7074
+ samplectx.nRet = 0.0;
7075
+ rc = idxBuildSampleTable(p, zTab);
7076
+ if( rc!=SQLITE_OK ) break;
7077
+ }
7078
+ rc = idxPopulateOneStat1(p, pIndexXInfo, pWrite, zTab, zIdx, pzErr);
7079
+ iPrev = iRowid;
7080
+ }
7081
+ if( rc==SQLITE_OK && p->iSample<100 ){
7082
+ rc = sqlite3_exec(p->dbv,
7083
+ "DROP TABLE IF EXISTS temp." UNIQUE_TABLE_NAME, 0,0,0
7084
+ );
7085
+ }
7086
+
7087
+ idxFinalize(&rc, pAllIndex);
7088
+ idxFinalize(&rc, pIndexXInfo);
7089
+ idxFinalize(&rc, pWrite);
7090
+
7091
+ for(i=0; i<pCtx->nSlot; i++){
7092
+ sqlite3_free(pCtx->aSlot[i].z);
7093
+ }
7094
+ sqlite3_free(pCtx);
7095
+
7096
+ if( rc==SQLITE_OK ){
7097
+ rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_master", 0, 0, 0);
7098
+ }
7099
+
7100
+ sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
7101
+ return rc;
7102
+}
7103
+
7104
+/*
7105
+** Allocate a new sqlite3expert object.
7106
+*/
7107
+sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErrmsg){
7108
+ int rc = SQLITE_OK;
7109
+ sqlite3expert *pNew;
7110
+
7111
+ pNew = (sqlite3expert*)idxMalloc(&rc, sizeof(sqlite3expert));
7112
+
7113
+ /* Open two in-memory databases to work with. The "vtab database" (dbv)
7114
+ ** will contain a virtual table corresponding to each real table in
7115
+ ** the user database schema, and a copy of each view. It is used to
7116
+ ** collect information regarding the WHERE, ORDER BY and other clauses
7117
+ ** of the user's query.
7118
+ */
7119
+ if( rc==SQLITE_OK ){
7120
+ pNew->db = db;
7121
+ pNew->iSample = 100;
7122
+ rc = sqlite3_open(":memory:", &pNew->dbv);
7123
+ }
7124
+ if( rc==SQLITE_OK ){
7125
+ rc = sqlite3_open(":memory:", &pNew->dbm);
7126
+ if( rc==SQLITE_OK ){
7127
+ sqlite3_db_config(pNew->dbm, SQLITE_DBCONFIG_TRIGGER_EQP, 1, (int*)0);
7128
+ }
7129
+ }
7130
+
7131
+
7132
+ /* Copy the entire schema of database [db] into [dbm]. */
7133
+ if( rc==SQLITE_OK ){
7134
+ sqlite3_stmt *pSql;
7135
+ rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
7136
+ "SELECT sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%%'"
7137
+ " AND sql NOT LIKE 'CREATE VIRTUAL %%'"
7138
+ );
7139
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
7140
+ const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
7141
+ rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
7142
+ }
7143
+ idxFinalize(&rc, pSql);
7144
+ }
7145
+
7146
+ /* Create the vtab schema */
7147
+ if( rc==SQLITE_OK ){
7148
+ rc = idxCreateVtabSchema(pNew, pzErrmsg);
7149
+ }
7150
+
7151
+ /* Register the auth callback with dbv */
7152
+ if( rc==SQLITE_OK ){
7153
+ sqlite3_set_authorizer(pNew->dbv, idxAuthCallback, (void*)pNew);
7154
+ }
7155
+
7156
+ /* If an error has occurred, free the new object and reutrn NULL. Otherwise,
7157
+ ** return the new sqlite3expert handle. */
7158
+ if( rc!=SQLITE_OK ){
7159
+ sqlite3_expert_destroy(pNew);
7160
+ pNew = 0;
7161
+ }
7162
+ return pNew;
7163
+}
7164
+
7165
+/*
7166
+** Configure an sqlite3expert object.
7167
+*/
7168
+int sqlite3_expert_config(sqlite3expert *p, int op, ...){
7169
+ int rc = SQLITE_OK;
7170
+ va_list ap;
7171
+ va_start(ap, op);
7172
+ switch( op ){
7173
+ case EXPERT_CONFIG_SAMPLE: {
7174
+ int iVal = va_arg(ap, int);
7175
+ if( iVal<0 ) iVal = 0;
7176
+ if( iVal>100 ) iVal = 100;
7177
+ p->iSample = iVal;
7178
+ break;
7179
+ }
7180
+ default:
7181
+ rc = SQLITE_NOTFOUND;
7182
+ break;
7183
+ }
7184
+
7185
+ va_end(ap);
7186
+ return rc;
7187
+}
7188
+
7189
+/*
7190
+** Add an SQL statement to the analysis.
7191
+*/
7192
+int sqlite3_expert_sql(
7193
+ sqlite3expert *p, /* From sqlite3_expert_new() */
7194
+ const char *zSql, /* SQL statement to add */
7195
+ char **pzErr /* OUT: Error message (if any) */
7196
+){
7197
+ IdxScan *pScanOrig = p->pScan;
7198
+ IdxStatement *pStmtOrig = p->pStatement;
7199
+ int rc = SQLITE_OK;
7200
+ const char *zStmt = zSql;
7201
+
7202
+ if( p->bRun ) return SQLITE_MISUSE;
7203
+
7204
+ while( rc==SQLITE_OK && zStmt && zStmt[0] ){
7205
+ sqlite3_stmt *pStmt = 0;
7206
+ rc = sqlite3_prepare_v2(p->dbv, zStmt, -1, &pStmt, &zStmt);
7207
+ if( rc==SQLITE_OK ){
7208
+ if( pStmt ){
7209
+ IdxStatement *pNew;
7210
+ const char *z = sqlite3_sql(pStmt);
7211
+ int n = STRLEN(z);
7212
+ pNew = (IdxStatement*)idxMalloc(&rc, sizeof(IdxStatement) + n+1);
7213
+ if( rc==SQLITE_OK ){
7214
+ pNew->zSql = (char*)&pNew[1];
7215
+ memcpy(pNew->zSql, z, n+1);
7216
+ pNew->pNext = p->pStatement;
7217
+ if( p->pStatement ) pNew->iId = p->pStatement->iId+1;
7218
+ p->pStatement = pNew;
7219
+ }
7220
+ sqlite3_finalize(pStmt);
7221
+ }
7222
+ }else{
7223
+ idxDatabaseError(p->dbv, pzErr);
7224
+ }
7225
+ }
7226
+
7227
+ if( rc!=SQLITE_OK ){
7228
+ idxScanFree(p->pScan, pScanOrig);
7229
+ idxStatementFree(p->pStatement, pStmtOrig);
7230
+ p->pScan = pScanOrig;
7231
+ p->pStatement = pStmtOrig;
7232
+ }
7233
+
7234
+ return rc;
7235
+}
7236
+
7237
+int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr){
7238
+ int rc;
7239
+ IdxHashEntry *pEntry;
7240
+
7241
+ /* Do trigger processing to collect any extra IdxScan structures */
7242
+ rc = idxProcessTriggers(p, pzErr);
7243
+
7244
+ /* Create candidate indexes within the in-memory database file */
7245
+ if( rc==SQLITE_OK ){
7246
+ rc = idxCreateCandidates(p, pzErr);
7247
+ }
7248
+
7249
+ /* Generate the stat1 data */
7250
+ if( rc==SQLITE_OK ){
7251
+ rc = idxPopulateStat1(p, pzErr);
7252
+ }
7253
+
7254
+ /* Formulate the EXPERT_REPORT_CANDIDATES text */
7255
+ for(pEntry=p->hIdx.pFirst; pEntry; pEntry=pEntry->pNext){
7256
+ p->zCandidates = idxAppendText(&rc, p->zCandidates,
7257
+ "%s;%s%s\n", pEntry->zVal,
7258
+ pEntry->zVal2 ? " -- stat1: " : "", pEntry->zVal2
7259
+ );
7260
+ }
7261
+
7262
+ /* Figure out which of the candidate indexes are preferred by the query
7263
+ ** planner and report the results to the user. */
7264
+ if( rc==SQLITE_OK ){
7265
+ rc = idxFindIndexes(p, pzErr);
7266
+ }
7267
+
7268
+ if( rc==SQLITE_OK ){
7269
+ p->bRun = 1;
7270
+ }
7271
+ return rc;
7272
+}
7273
+
7274
+/*
7275
+** Return the total number of statements that have been added to this
7276
+** sqlite3expert using sqlite3_expert_sql().
7277
+*/
7278
+int sqlite3_expert_count(sqlite3expert *p){
7279
+ int nRet = 0;
7280
+ if( p->pStatement ) nRet = p->pStatement->iId+1;
7281
+ return nRet;
7282
+}
7283
+
7284
+/*
7285
+** Return a component of the report.
7286
+*/
7287
+const char *sqlite3_expert_report(sqlite3expert *p, int iStmt, int eReport){
7288
+ const char *zRet = 0;
7289
+ IdxStatement *pStmt;
7290
+
7291
+ if( p->bRun==0 ) return 0;
7292
+ for(pStmt=p->pStatement; pStmt && pStmt->iId!=iStmt; pStmt=pStmt->pNext);
7293
+ switch( eReport ){
7294
+ case EXPERT_REPORT_SQL:
7295
+ if( pStmt ) zRet = pStmt->zSql;
7296
+ break;
7297
+ case EXPERT_REPORT_INDEXES:
7298
+ if( pStmt ) zRet = pStmt->zIdx;
7299
+ break;
7300
+ case EXPERT_REPORT_PLAN:
7301
+ if( pStmt ) zRet = pStmt->zEQP;
7302
+ break;
7303
+ case EXPERT_REPORT_CANDIDATES:
7304
+ zRet = p->zCandidates;
7305
+ break;
7306
+ }
7307
+ return zRet;
7308
+}
7309
+
7310
+/*
7311
+** Free an sqlite3expert object.
7312
+*/
7313
+void sqlite3_expert_destroy(sqlite3expert *p){
7314
+ if( p ){
7315
+ sqlite3_close(p->dbm);
7316
+ sqlite3_close(p->dbv);
7317
+ idxScanFree(p->pScan, 0);
7318
+ idxStatementFree(p->pStatement, 0);
7319
+ idxTableFree(p->pTable);
7320
+ idxWriteFree(p->pWrite);
7321
+ idxHashClear(&p->hIdx);
7322
+ sqlite3_free(p->zCandidates);
7323
+ sqlite3_free(p);
7324
+ }
7325
+}
7326
+
7327
+/************************* End ../ext/expert/sqlite3expert.c ********************/
21597328
21607329
#if defined(SQLITE_ENABLE_SESSION)
21617330
/*
21627331
** State information for a single open session
21637332
*/
@@ -2180,21 +7349,28 @@
21807349
int mode; /* Mode prior to ".explain on" */
21817350
int showHeader; /* The ".header" setting prior to ".explain on" */
21827351
int colWidth[100]; /* Column widths prior to ".explain on" */
21837352
};
21847353
7354
+typedef struct ExpertInfo ExpertInfo;
7355
+struct ExpertInfo {
7356
+ sqlite3expert *pExpert;
7357
+ int bVerbose;
7358
+};
7359
+
21857360
/*
21867361
** State information about the database connection is contained in an
21877362
** instance of the following structure.
21887363
*/
21897364
typedef struct ShellState ShellState;
21907365
struct ShellState {
21917366
sqlite3 *db; /* The database */
2192
- int autoExplain; /* Automatically turn on .explain mode */
2193
- int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
2194
- int statsOn; /* True to display memory stats before each finalize */
2195
- int scanstatsOn; /* True to display scan stats before each finalize */
7367
+ u8 autoExplain; /* Automatically turn on .explain mode */
7368
+ u8 autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
7369
+ u8 statsOn; /* True to display memory stats before each finalize */
7370
+ u8 scanstatsOn; /* True to display scan stats before each finalize */
7371
+ u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
21967372
int outCount; /* Revert to stdout when reaching zero */
21977373
int cnt; /* Number of records displayed so far */
21987374
FILE *out; /* Write results here */
21997375
FILE *traceOut; /* Output for sqlite3_trace() */
22007376
int nErr; /* Number of errors seen */
@@ -2224,12 +7400,28 @@
22247400
int iIndent; /* Index of current op in aiIndent[] */
22257401
#if defined(SQLITE_ENABLE_SESSION)
22267402
int nSession; /* Number of active sessions */
22277403
OpenSession aSession[4]; /* Array of sessions. [0] is in focus. */
22287404
#endif
7405
+ ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
22297406
};
22307407
7408
+
7409
+/* Allowed values for ShellState.autoEQP
7410
+*/
7411
+#define AUTOEQP_off 0
7412
+#define AUTOEQP_on 1
7413
+#define AUTOEQP_trigger 2
7414
+#define AUTOEQP_full 3
7415
+
7416
+/* Allowed values for ShellState.openMode
7417
+*/
7418
+#define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */
7419
+#define SHELL_OPEN_NORMAL 1 /* Normal database file */
7420
+#define SHELL_OPEN_APPENDVFS 2 /* Use appendvfs */
7421
+#define SHELL_OPEN_ZIPFILE 3 /* Use the zipfile virtual table */
7422
+
22317423
/*
22327424
** These are the allowed shellFlgs values
22337425
*/
22347426
#define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
22357427
#define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
@@ -2652,10 +7844,26 @@
26527844
z[n] = 0;
26537845
printSchemaLine(out, z, zTail);
26547846
z[n] = c;
26557847
}
26567848
7849
+/*
7850
+** Return true if string z[] has nothing but whitespace and comments to the
7851
+** end of the first line.
7852
+*/
7853
+static int wsToEol(const char *z){
7854
+ int i;
7855
+ for(i=0; z[i]; i++){
7856
+ if( z[i]=='\n' ) return 1;
7857
+ if( IsSpace(z[i]) ) continue;
7858
+ if( z[i]=='-' && z[i+1]=='-' ) return 1;
7859
+ return 0;
7860
+ }
7861
+ return 1;
7862
+}
7863
+
7864
+
26577865
/*
26587866
** This is the callback routine that the shell
26597867
** invokes for each row of a query result.
26607868
*/
26617869
static int shell_callback(
@@ -2791,17 +7999,19 @@
27917999
z[j++] = c;
27928000
}
27938001
while( j>0 && IsSpace(z[j-1]) ){ j--; }
27948002
z[j] = 0;
27958003
if( strlen30(z)>=79 ){
2796
- for(i=j=0; (c = z[i])!=0; i++){
8004
+ for(i=j=0; (c = z[i])!=0; i++){ /* Copy changes from z[i] back to z[j] */
27978005
if( c==cEnd ){
27988006
cEnd = 0;
27998007
}else if( c=='"' || c=='\'' || c=='`' ){
28008008
cEnd = c;
28018009
}else if( c=='[' ){
28028010
cEnd = ']';
8011
+ }else if( c=='-' && z[i+1]=='-' ){
8012
+ cEnd = '\n';
28038013
}else if( c=='(' ){
28048014
nParen++;
28058015
}else if( c==')' ){
28068016
nParen--;
28078017
if( nLine>0 && nParen==0 && j>0 ){
@@ -2808,11 +8018,13 @@
28088018
printSchemaLineN(p->out, z, j, "\n");
28098019
j = 0;
28108020
}
28118021
}
28128022
z[j++] = c;
2813
- if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
8023
+ if( nParen==1 && cEnd==0
8024
+ && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1)))
8025
+ ){
28148026
if( c=='\n' ) j--;
28158027
printSchemaLineN(p->out, z, j, "\n ");
28168028
j = 0;
28178029
nLine++;
28188030
while( IsSpace(z[i+1]) ){ i++; }
@@ -3206,11 +8418,11 @@
32068418
{ "write_bytes: ", "Bytes written to storage:" },
32078419
{ "cancelled_write_bytes: ", "Cancelled write bytes:" },
32088420
};
32098421
int i;
32108422
for(i=0; i<ArraySize(aTrans); i++){
3211
- int n = (int)strlen(aTrans[i].zPattern);
8423
+ int n = strlen30(aTrans[i].zPattern);
32128424
if( strncmp(aTrans[i].zPattern, z, n)==0 ){
32138425
utf8_printf(out, "%-36s %s", aTrans[i].zDesc, &z[n]);
32148426
break;
32158427
}
32168428
}
@@ -3606,10 +8818,83 @@
36068818
rc = sqlite3_step(pStmt);
36078819
} while( rc == SQLITE_ROW );
36088820
}
36098821
}
36108822
}
8823
+
8824
+/*
8825
+** This function is called to process SQL if the previous shell command
8826
+** was ".expert". It passes the SQL in the second argument directly to
8827
+** the sqlite3expert object.
8828
+**
8829
+** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
8830
+** code. In this case, (*pzErr) may be set to point to a buffer containing
8831
+** an English language error message. It is the responsibility of the
8832
+** caller to eventually free this buffer using sqlite3_free().
8833
+*/
8834
+static int expertHandleSQL(
8835
+ ShellState *pState,
8836
+ const char *zSql,
8837
+ char **pzErr
8838
+){
8839
+ assert( pState->expert.pExpert );
8840
+ assert( pzErr==0 || *pzErr==0 );
8841
+ return sqlite3_expert_sql(pState->expert.pExpert, zSql, pzErr);
8842
+}
8843
+
8844
+/*
8845
+** This function is called either to silently clean up the object
8846
+** created by the ".expert" command (if bCancel==1), or to generate a
8847
+** report from it and then clean it up (if bCancel==0).
8848
+**
8849
+** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
8850
+** code. In this case, (*pzErr) may be set to point to a buffer containing
8851
+** an English language error message. It is the responsibility of the
8852
+** caller to eventually free this buffer using sqlite3_free().
8853
+*/
8854
+static int expertFinish(
8855
+ ShellState *pState,
8856
+ int bCancel,
8857
+ char **pzErr
8858
+){
8859
+ int rc = SQLITE_OK;
8860
+ sqlite3expert *p = pState->expert.pExpert;
8861
+ assert( p );
8862
+ assert( bCancel || pzErr==0 || *pzErr==0 );
8863
+ if( bCancel==0 ){
8864
+ FILE *out = pState->out;
8865
+ int bVerbose = pState->expert.bVerbose;
8866
+
8867
+ rc = sqlite3_expert_analyze(p, pzErr);
8868
+ if( rc==SQLITE_OK ){
8869
+ int nQuery = sqlite3_expert_count(p);
8870
+ int i;
8871
+
8872
+ if( bVerbose ){
8873
+ const char *zCand = sqlite3_expert_report(p,0,EXPERT_REPORT_CANDIDATES);
8874
+ raw_printf(out, "-- Candidates -----------------------------\n");
8875
+ raw_printf(out, "%s\n", zCand);
8876
+ }
8877
+ for(i=0; i<nQuery; i++){
8878
+ const char *zSql = sqlite3_expert_report(p, i, EXPERT_REPORT_SQL);
8879
+ const char *zIdx = sqlite3_expert_report(p, i, EXPERT_REPORT_INDEXES);
8880
+ const char *zEQP = sqlite3_expert_report(p, i, EXPERT_REPORT_PLAN);
8881
+ if( zIdx==0 ) zIdx = "(no new indexes)\n";
8882
+ if( bVerbose ){
8883
+ raw_printf(out, "-- Query %d --------------------------------\n",i+1);
8884
+ raw_printf(out, "%s\n\n", zSql);
8885
+ }
8886
+ raw_printf(out, "%s\n", zIdx);
8887
+ raw_printf(out, "%s\n", zEQP);
8888
+ }
8889
+ }
8890
+ }
8891
+ sqlite3_expert_destroy(p);
8892
+ pState->expert.pExpert = 0;
8893
+ return rc;
8894
+}
8895
+
36118896
36128897
/*
36138898
** Execute a statement or set of statements. Print
36148899
** any result rows/columns depending on the current mode
36158900
** set via the supplied callback.
@@ -3632,10 +8917,15 @@
36328917
const char *zLeftover; /* Tail of unprocessed SQL */
36338918
36348919
if( pzErrMsg ){
36358920
*pzErrMsg = NULL;
36368921
}
8922
+
8923
+ if( pArg->expert.pExpert ){
8924
+ rc = expertHandleSQL(pArg, zSql, pzErrMsg);
8925
+ return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
8926
+ }
36378927
36388928
while( zSql[0] && (SQLITE_OK == rc) ){
36398929
static const char *zStmtSql;
36408930
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
36418931
if( SQLITE_OK != rc ){
@@ -3666,11 +8956,16 @@
36668956
36678957
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
36688958
if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
36698959
sqlite3_stmt *pExplain;
36708960
char *zEQP;
8961
+ int triggerEQP = 0;
36718962
disable_debug_trace_modes();
8963
+ sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
8964
+ if( pArg->autoEQP>=AUTOEQP_trigger ){
8965
+ sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
8966
+ }
36728967
zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
36738968
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
36748969
if( rc==SQLITE_OK ){
36758970
while( sqlite3_step(pExplain)==SQLITE_ROW ){
36768971
raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
@@ -3679,11 +8974,11 @@
36798974
utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
36808975
}
36818976
}
36828977
sqlite3_finalize(pExplain);
36838978
sqlite3_free(zEQP);
3684
- if( pArg->autoEQP>=2 ){
8979
+ if( pArg->autoEQP>=AUTOEQP_full ){
36858980
/* Also do an EXPLAIN for ".eqp full" mode */
36868981
zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql);
36878982
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
36888983
if( rc==SQLITE_OK ){
36898984
pArg->cMode = MODE_Explain;
@@ -3692,10 +8987,11 @@
36928987
explain_data_delete(pArg);
36938988
}
36948989
sqlite3_finalize(pExplain);
36958990
sqlite3_free(zEQP);
36968991
}
8992
+ sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, triggerEQP, 0);
36978993
restore_debug_trace_modes();
36988994
}
36998995
37008996
if( pArg ){
37018997
pArg->cMode = pArg->mode;
@@ -4032,10 +9328,13 @@
40329328
40339329
/*
40349330
** Text of a help message
40359331
*/
40369332
static char zHelp[] =
9333
+#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE)
9334
+ ".archive ... Manage SQL archives: \".archive --help\" for details\n"
9335
+#endif
40379336
#ifndef SQLITE_OMIT_AUTHORIZATION
40389337
".auth ON|OFF Show authorizer callbacks\n"
40399338
#endif
40409339
".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
40419340
".bail on|off Stop after hitting an error. Default OFF\n"
@@ -4050,10 +9349,11 @@
40509349
" If TABLE specified, only dump tables matching\n"
40519350
" LIKE pattern TABLE.\n"
40529351
".echo on|off Turn command echo on or off\n"
40539352
".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
40549353
".exit Exit this program\n"
9354
+ ".expert EXPERIMENTAL. Suggest indexes for specified queries\n"
40559355
/* Because explain mode comes on automatically now, the ".explain" mode
40569356
** is removed from the help screen. It is still supported for legacy, however */
40579357
/*".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"*/
40589358
".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
40599359
".headers on|off Turn display of headers on or off\n"
@@ -4233,19 +9533,63 @@
42339533
if( sqlite3_strglob(pSession->azFilter[i], zTab)==0 ) return 0;
42349534
}
42359535
return 1;
42369536
}
42379537
#endif
9538
+
9539
+/*
9540
+** Try to deduce the type of file for zName based on its content. Return
9541
+** one of the SHELL_OPEN_* constants.
9542
+*/
9543
+static int deduceDatabaseType(const char *zName){
9544
+ FILE *f = fopen(zName, "rb");
9545
+ size_t n;
9546
+ int rc = SHELL_OPEN_UNSPEC;
9547
+ char zBuf[100];
9548
+ if( f==0 ) return SHELL_OPEN_NORMAL;
9549
+ fseek(f, -25, SEEK_END);
9550
+ n = fread(zBuf, 25, 1, f);
9551
+ if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){
9552
+ rc = SHELL_OPEN_APPENDVFS;
9553
+ }else{
9554
+ fseek(f, -22, SEEK_END);
9555
+ n = fread(zBuf, 22, 1, f);
9556
+ if( n==1 && zBuf[0]==0x50 && zBuf[1]==0x4b && zBuf[2]==0x05
9557
+ && zBuf[3]==0x06 ){
9558
+ rc = SHELL_OPEN_ZIPFILE;
9559
+ }
9560
+ }
9561
+ fclose(f);
9562
+ return rc;
9563
+}
42389564
42399565
/*
42409566
** Make sure the database is open. If it is not, then open it. If
42419567
** the database fails to open, print an error message and exit.
42429568
*/
42439569
static void open_db(ShellState *p, int keepAlive){
42449570
if( p->db==0 ){
42459571
sqlite3_initialize();
4246
- sqlite3_open(p->zDbFilename, &p->db);
9572
+ if( p->openMode==SHELL_OPEN_UNSPEC && access(p->zDbFilename,0)==0 ){
9573
+ p->openMode = deduceDatabaseType(p->zDbFilename);
9574
+ }
9575
+ switch( p->openMode ){
9576
+ case SHELL_OPEN_APPENDVFS: {
9577
+ sqlite3_open_v2(p->zDbFilename, &p->db,
9578
+ SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
9579
+ break;
9580
+ }
9581
+ case SHELL_OPEN_ZIPFILE: {
9582
+ sqlite3_open(":memory:", &p->db);
9583
+ break;
9584
+ }
9585
+ case SHELL_OPEN_UNSPEC:
9586
+ case SHELL_OPEN_NORMAL: {
9587
+ sqlite3_open(p->zDbFilename, &p->db);
9588
+ break;
9589
+ }
9590
+ }
42479591
globalDb = p->db;
42489592
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
42499593
utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
42509594
p->zDbFilename, sqlite3_errmsg(p->db));
42519595
if( keepAlive ) return;
@@ -4255,12 +9599,24 @@
42559599
sqlite3_enable_load_extension(p->db, 1);
42569600
#endif
42579601
sqlite3_fileio_init(p->db, 0, 0);
42589602
sqlite3_shathree_init(p->db, 0, 0);
42599603
sqlite3_completion_init(p->db, 0, 0);
4260
- sqlite3_create_function(p->db, "shell_add_schema", 2, SQLITE_UTF8, 0,
9604
+#ifdef SQLITE_HAVE_ZLIB
9605
+ sqlite3_zipfile_init(p->db, 0, 0);
9606
+ sqlite3_sqlar_init(p->db, 0, 0);
9607
+#endif
9608
+ sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
42619609
shellAddSchemaName, 0, 0);
9610
+ sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
9611
+ shellModuleSchema, 0, 0);
9612
+ if( p->openMode==SHELL_OPEN_ZIPFILE ){
9613
+ char *zSql = sqlite3_mprintf(
9614
+ "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
9615
+ sqlite3_exec(p->db, zSql, 0, 0, 0);
9616
+ sqlite3_free(zSql);
9617
+ }
42629618
}
42639619
}
42649620
42659621
#if HAVE_READLINE || HAVE_EDITLINE
42669622
/*
@@ -4294,11 +9650,11 @@
42949650
#elif HAVE_LINENOISE
42959651
/*
42969652
** Linenoise completion callback
42979653
*/
42989654
static void linenoise_completion(const char *zLine, linenoiseCompletions *lc){
4299
- int nLine = (int)strlen(zLine);
9655
+ int nLine = strlen30(zLine);
43009656
int i, iStart;
43019657
sqlite3_stmt *pStmt = 0;
43029658
char *zSql;
43039659
char zBuf[1000];
43049660
@@ -4520,11 +9876,11 @@
45209876
FILE *f = (FILE*)pArg;
45219877
UNUSED_PARAMETER(mType);
45229878
UNUSED_PARAMETER(pP);
45239879
if( f ){
45249880
const char *z = (const char*)pX;
4525
- int i = (int)strlen(z);
9881
+ int i = strlen30(z);
45269882
while( i>0 && z[i-1]==';' ){ i--; }
45279883
utf8_printf(f, "%.*s;\n", i, z);
45289884
}
45299885
return 0;
45309886
}
@@ -4709,11 +10065,11 @@
470910065
sqlite3_stmt *pInsert = 0;
471010066
char *zQuery = 0;
471110067
char *zInsert = 0;
471210068
int rc;
471310069
int i, j, n;
4714
- int nTable = (int)strlen(zTable);
10070
+ int nTable = strlen30(zTable);
471510071
int k = 0;
471610072
int cnt = 0;
471710073
const int spinRate = 10000;
471810074
471910075
zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
@@ -4730,11 +10086,11 @@
473010086
raw_printf(stderr, "out of memory\n");
473110087
goto end_data_xfer;
473210088
}
473310089
sqlite3_snprintf(200+nTable,zInsert,
473410090
"INSERT OR IGNORE INTO \"%s\" VALUES(?", zTable);
4735
- i = (int)strlen(zInsert);
10091
+ i = strlen30(zInsert);
473610092
for(j=1; j<n; j++){
473710093
memcpy(zInsert+i, ",?", 2);
473810094
i += 2;
473910095
}
474010096
memcpy(zInsert+i, ");", 3);
@@ -5312,11 +10668,11 @@
531210668
"ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
531310669
;
531410670
const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
531510671
531610672
for(i=2; i<nArg; i++){
5317
- int n = (int)strlen(azArg[i]);
10673
+ int n = strlen30(azArg[i]);
531810674
if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
531910675
bVerbose = 1;
532010676
}
532110677
else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){
532210678
bGroupByParent = 1;
@@ -5415,20 +10771,822 @@
541510771
ShellState *pState, /* Current shell tool state */
541610772
char **azArg, /* Array of arguments passed to dot command */
541710773
int nArg /* Number of entries in azArg[] */
541810774
){
541910775
int n;
5420
- n = (nArg>=2 ? (int)strlen(azArg[1]) : 0);
10776
+ n = (nArg>=2 ? strlen30(azArg[1]) : 0);
542110777
if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage;
542210778
return lintFkeyIndexes(pState, azArg, nArg);
542310779
542410780
usage:
542510781
raw_printf(stderr, "Usage %s sub-command ?switches...?\n", azArg[0]);
542610782
raw_printf(stderr, "Where sub-commands are:\n");
542710783
raw_printf(stderr, " fkey-indexes\n");
542810784
return SQLITE_ERROR;
542910785
}
10786
+
10787
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
10788
+/*********************************************************************************
10789
+** The ".archive" or ".ar" command.
10790
+*/
10791
+static void shellPrepare(
10792
+ sqlite3 *db,
10793
+ int *pRc,
10794
+ const char *zSql,
10795
+ sqlite3_stmt **ppStmt
10796
+){
10797
+ *ppStmt = 0;
10798
+ if( *pRc==SQLITE_OK ){
10799
+ int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
10800
+ if( rc!=SQLITE_OK ){
10801
+ raw_printf(stderr, "sql error: %s (%d)\n",
10802
+ sqlite3_errmsg(db), sqlite3_errcode(db)
10803
+ );
10804
+ *pRc = rc;
10805
+ }
10806
+ }
10807
+}
10808
+
10809
+static void shellPreparePrintf(
10810
+ sqlite3 *db,
10811
+ int *pRc,
10812
+ sqlite3_stmt **ppStmt,
10813
+ const char *zFmt,
10814
+ ...
10815
+){
10816
+ *ppStmt = 0;
10817
+ if( *pRc==SQLITE_OK ){
10818
+ va_list ap;
10819
+ char *z;
10820
+ va_start(ap, zFmt);
10821
+ z = sqlite3_vmprintf(zFmt, ap);
10822
+ if( z==0 ){
10823
+ *pRc = SQLITE_NOMEM;
10824
+ }else{
10825
+ shellPrepare(db, pRc, z, ppStmt);
10826
+ sqlite3_free(z);
10827
+ }
10828
+ }
10829
+}
10830
+
10831
+static void shellFinalize(
10832
+ int *pRc,
10833
+ sqlite3_stmt *pStmt
10834
+){
10835
+ if( pStmt ){
10836
+ sqlite3 *db = sqlite3_db_handle(pStmt);
10837
+ int rc = sqlite3_finalize(pStmt);
10838
+ if( *pRc==SQLITE_OK ){
10839
+ if( rc!=SQLITE_OK ){
10840
+ raw_printf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
10841
+ }
10842
+ *pRc = rc;
10843
+ }
10844
+ }
10845
+}
10846
+
10847
+static void shellReset(
10848
+ int *pRc,
10849
+ sqlite3_stmt *pStmt
10850
+){
10851
+ int rc = sqlite3_reset(pStmt);
10852
+ if( *pRc==SQLITE_OK ){
10853
+ if( rc!=SQLITE_OK ){
10854
+ sqlite3 *db = sqlite3_db_handle(pStmt);
10855
+ raw_printf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
10856
+ }
10857
+ *pRc = rc;
10858
+ }
10859
+}
10860
+/*
10861
+** Structure representing a single ".ar" command.
10862
+*/
10863
+typedef struct ArCommand ArCommand;
10864
+struct ArCommand {
10865
+ int eCmd; /* An AR_CMD_* value */
10866
+ const char *zFile; /* --file argument, or NULL */
10867
+ const char *zDir; /* --directory argument, or NULL */
10868
+ int bVerbose; /* True if --verbose */
10869
+ int bZip; /* True if --zip */
10870
+ int nArg; /* Number of command arguments */
10871
+ char **azArg; /* Array of command arguments */
10872
+};
10873
+
10874
+/*
10875
+** Print a usage message for the .ar command to stderr and return SQLITE_ERROR.
10876
+*/
10877
+static int arUsage(FILE *f){
10878
+ raw_printf(f,
10879
+"\n"
10880
+"Usage: .ar [OPTION...] [FILE...]\n"
10881
+"The .ar command manages sqlar archives.\n"
10882
+"\n"
10883
+"Examples:\n"
10884
+" .ar -cf archive.sar foo bar # Create archive.sar from files foo and bar\n"
10885
+" .ar -tf archive.sar # List members of archive.sar\n"
10886
+" .ar -xvf archive.sar # Verbosely extract files from archive.sar\n"
10887
+"\n"
10888
+"Each command line must feature exactly one command option:\n"
10889
+" -c, --create Create a new archive\n"
10890
+" -u, --update Update or add files to an existing archive\n"
10891
+" -t, --list List contents of archive\n"
10892
+" -x, --extract Extract files from archive\n"
10893
+"\n"
10894
+"And zero or more optional options:\n"
10895
+" -v, --verbose Print each filename as it is processed\n"
10896
+" -f FILE, --file FILE Operate on archive FILE (default is current db)\n"
10897
+" -C DIR, --directory DIR Change to directory DIR to read/extract files\n"
10898
+"\n"
10899
+"See also: http://sqlite.org/cli.html#sqlar_archive_support\n"
10900
+"\n"
10901
+);
10902
+ return SQLITE_ERROR;
10903
+}
10904
+
10905
+/*
10906
+** Print an error message for the .ar command to stderr and return
10907
+** SQLITE_ERROR.
10908
+*/
10909
+static int arErrorMsg(const char *zFmt, ...){
10910
+ va_list ap;
10911
+ char *z;
10912
+ va_start(ap, zFmt);
10913
+ z = sqlite3_vmprintf(zFmt, ap);
10914
+ va_end(ap);
10915
+ raw_printf(stderr, "Error: %s (try \".ar --help\")\n", z);
10916
+ sqlite3_free(z);
10917
+ return SQLITE_ERROR;
10918
+}
10919
+
10920
+/*
10921
+** Values for ArCommand.eCmd.
10922
+*/
10923
+#define AR_CMD_CREATE 1
10924
+#define AR_CMD_EXTRACT 2
10925
+#define AR_CMD_LIST 3
10926
+#define AR_CMD_UPDATE 4
10927
+#define AR_CMD_HELP 5
10928
+
10929
+/*
10930
+** Other (non-command) switches.
10931
+*/
10932
+#define AR_SWITCH_VERBOSE 6
10933
+#define AR_SWITCH_FILE 7
10934
+#define AR_SWITCH_DIRECTORY 8
10935
+#define AR_SWITCH_ZIP 9
10936
+
10937
+static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
10938
+ switch( eSwitch ){
10939
+ case AR_CMD_CREATE:
10940
+ case AR_CMD_EXTRACT:
10941
+ case AR_CMD_LIST:
10942
+ case AR_CMD_UPDATE:
10943
+ case AR_CMD_HELP:
10944
+ if( pAr->eCmd ){
10945
+ return arErrorMsg("multiple command options");
10946
+ }
10947
+ pAr->eCmd = eSwitch;
10948
+ break;
10949
+
10950
+ case AR_SWITCH_VERBOSE:
10951
+ pAr->bVerbose = 1;
10952
+ break;
10953
+ case AR_SWITCH_ZIP:
10954
+ pAr->bZip = 1;
10955
+ break;
10956
+
10957
+ case AR_SWITCH_FILE:
10958
+ pAr->zFile = zArg;
10959
+ break;
10960
+ case AR_SWITCH_DIRECTORY:
10961
+ pAr->zDir = zArg;
10962
+ break;
10963
+ }
10964
+
10965
+ return SQLITE_OK;
10966
+}
10967
+
10968
+/*
10969
+** Parse the command line for an ".ar" command. The results are written into
10970
+** structure (*pAr). SQLITE_OK is returned if the command line is parsed
10971
+** successfully, otherwise an error message is written to stderr and
10972
+** SQLITE_ERROR returned.
10973
+*/
10974
+static int arParseCommand(
10975
+ char **azArg, /* Array of arguments passed to dot command */
10976
+ int nArg, /* Number of entries in azArg[] */
10977
+ ArCommand *pAr /* Populate this object */
10978
+){
10979
+ struct ArSwitch {
10980
+ char cShort;
10981
+ const char *zLong;
10982
+ int eSwitch;
10983
+ int bArg;
10984
+ } aSwitch[] = {
10985
+ { 'c', "create", AR_CMD_CREATE, 0 },
10986
+ { 'x', "extract", AR_CMD_EXTRACT, 0 },
10987
+ { 't', "list", AR_CMD_LIST, 0 },
10988
+ { 'u', "update", AR_CMD_UPDATE, 0 },
10989
+ { 'h', "help", AR_CMD_HELP, 0 },
10990
+ { 'v', "verbose", AR_SWITCH_VERBOSE, 0 },
10991
+ { 'f', "file", AR_SWITCH_FILE, 1 },
10992
+ { 'C', "directory", AR_SWITCH_DIRECTORY, 1 },
10993
+ { 'z', "zip", AR_SWITCH_ZIP, 0 }
10994
+ };
10995
+ int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
10996
+ struct ArSwitch *pEnd = &aSwitch[nSwitch];
10997
+
10998
+ if( nArg<=1 ){
10999
+ return arUsage(stderr);
11000
+ }else{
11001
+ char *z = azArg[1];
11002
+ memset(pAr, 0, sizeof(ArCommand));
11003
+
11004
+ if( z[0]!='-' ){
11005
+ /* Traditional style [tar] invocation */
11006
+ int i;
11007
+ int iArg = 2;
11008
+ for(i=0; z[i]; i++){
11009
+ const char *zArg = 0;
11010
+ struct ArSwitch *pOpt;
11011
+ for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){
11012
+ if( z[i]==pOpt->cShort ) break;
11013
+ }
11014
+ if( pOpt==pEnd ){
11015
+ return arErrorMsg("unrecognized option: %c", z[i]);
11016
+ }
11017
+ if( pOpt->bArg ){
11018
+ if( iArg>=nArg ){
11019
+ return arErrorMsg("option requires an argument: %c",z[i]);
11020
+ }
11021
+ zArg = azArg[iArg++];
11022
+ }
11023
+ if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR;
11024
+ }
11025
+ pAr->nArg = nArg-iArg;
11026
+ if( pAr->nArg>0 ){
11027
+ pAr->azArg = &azArg[iArg];
11028
+ }
11029
+ }else{
11030
+ /* Non-traditional invocation */
11031
+ int iArg;
11032
+ for(iArg=1; iArg<nArg; iArg++){
11033
+ int n;
11034
+ z = azArg[iArg];
11035
+ if( z[0]!='-' ){
11036
+ /* All remaining command line words are command arguments. */
11037
+ pAr->azArg = &azArg[iArg];
11038
+ pAr->nArg = nArg-iArg;
11039
+ break;
11040
+ }
11041
+ n = strlen30(z);
11042
+
11043
+ if( z[1]!='-' ){
11044
+ int i;
11045
+ /* One or more short options */
11046
+ for(i=1; i<n; i++){
11047
+ const char *zArg = 0;
11048
+ struct ArSwitch *pOpt;
11049
+ for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){
11050
+ if( z[i]==pOpt->cShort ) break;
11051
+ }
11052
+ if( pOpt==pEnd ){
11053
+ return arErrorMsg("unrecognized option: %c\n", z[i]);
11054
+ }
11055
+ if( pOpt->bArg ){
11056
+ if( i<(n-1) ){
11057
+ zArg = &z[i+1];
11058
+ i = n;
11059
+ }else{
11060
+ if( iArg>=(nArg-1) ){
11061
+ return arErrorMsg("option requires an argument: %c\n",z[i]);
11062
+ }
11063
+ zArg = azArg[++iArg];
11064
+ }
11065
+ }
11066
+ if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR;
11067
+ }
11068
+ }else if( z[2]=='\0' ){
11069
+ /* A -- option, indicating that all remaining command line words
11070
+ ** are command arguments. */
11071
+ pAr->azArg = &azArg[iArg+1];
11072
+ pAr->nArg = nArg-iArg-1;
11073
+ break;
11074
+ }else{
11075
+ /* A long option */
11076
+ const char *zArg = 0; /* Argument for option, if any */
11077
+ struct ArSwitch *pMatch = 0; /* Matching option */
11078
+ struct ArSwitch *pOpt; /* Iterator */
11079
+ for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){
11080
+ const char *zLong = pOpt->zLong;
11081
+ if( (n-2)<=strlen30(zLong) && 0==memcmp(&z[2], zLong, n-2) ){
11082
+ if( pMatch ){
11083
+ return arErrorMsg("ambiguous option: %s",z);
11084
+ }else{
11085
+ pMatch = pOpt;
11086
+ }
11087
+ }
11088
+ }
11089
+
11090
+ if( pMatch==0 ){
11091
+ return arErrorMsg("unrecognized option: %s", z);
11092
+ }
11093
+ if( pMatch->bArg ){
11094
+ if( iArg>=(nArg-1) ){
11095
+ return arErrorMsg("option requires an argument: %s", z);
11096
+ }
11097
+ zArg = azArg[++iArg];
11098
+ }
11099
+ if( arProcessSwitch(pAr, pMatch->eSwitch, zArg) ) return SQLITE_ERROR;
11100
+ }
11101
+ }
11102
+ }
11103
+ }
11104
+
11105
+ return SQLITE_OK;
11106
+}
11107
+
11108
+/*
11109
+** This function assumes that all arguments within the ArCommand.azArg[]
11110
+** array refer to archive members, as for the --extract or --list commands.
11111
+** It checks that each of them are present. If any specified file is not
11112
+** present in the archive, an error is printed to stderr and an error
11113
+** code returned. Otherwise, if all specified arguments are present in
11114
+** the archive, SQLITE_OK is returned.
11115
+**
11116
+** This function strips any trailing '/' characters from each argument.
11117
+** This is consistent with the way the [tar] command seems to work on
11118
+** Linux.
11119
+*/
11120
+static int arCheckEntries(sqlite3 *db, ArCommand *pAr){
11121
+ int rc = SQLITE_OK;
11122
+ if( pAr->nArg ){
11123
+ int i;
11124
+ sqlite3_stmt *pTest = 0;
11125
+
11126
+ shellPreparePrintf(db, &rc, &pTest, "SELECT name FROM %s WHERE name=?1",
11127
+ pAr->bZip ? "zipfile(?2)" : "sqlar"
11128
+ );
11129
+ if( rc==SQLITE_OK && pAr->bZip ){
11130
+ sqlite3_bind_text(pTest, 2, pAr->zFile, -1, SQLITE_TRANSIENT);
11131
+ }
11132
+ for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11133
+ char *z = pAr->azArg[i];
11134
+ int n = strlen30(z);
11135
+ int bOk = 0;
11136
+ while( n>0 && z[n-1]=='/' ) n--;
11137
+ z[n] = '\0';
11138
+ sqlite3_bind_text(pTest, 1, z, -1, SQLITE_STATIC);
11139
+ if( SQLITE_ROW==sqlite3_step(pTest) ){
11140
+ bOk = 1;
11141
+ }
11142
+ shellReset(&rc, pTest);
11143
+ if( rc==SQLITE_OK && bOk==0 ){
11144
+ raw_printf(stderr, "not found in archive: %s\n", z);
11145
+ rc = SQLITE_ERROR;
11146
+ }
11147
+ }
11148
+ shellFinalize(&rc, pTest);
11149
+ }
11150
+
11151
+ return rc;
11152
+}
11153
+
11154
+/*
11155
+** Format a WHERE clause that can be used against the "sqlar" table to
11156
+** identify all archive members that match the command arguments held
11157
+** in (*pAr). Leave this WHERE clause in (*pzWhere) before returning.
11158
+** The caller is responsible for eventually calling sqlite3_free() on
11159
+** any non-NULL (*pzWhere) value.
11160
+*/
11161
+static void arWhereClause(
11162
+ int *pRc,
11163
+ ArCommand *pAr,
11164
+ char **pzWhere /* OUT: New WHERE clause */
11165
+){
11166
+ char *zWhere = 0;
11167
+ if( *pRc==SQLITE_OK ){
11168
+ if( pAr->nArg==0 ){
11169
+ zWhere = sqlite3_mprintf("1");
11170
+ }else{
11171
+ int i;
11172
+ const char *zSep = "";
11173
+ for(i=0; i<pAr->nArg; i++){
11174
+ const char *z = pAr->azArg[i];
11175
+ zWhere = sqlite3_mprintf(
11176
+ "%z%s name = '%q' OR name BETWEEN '%q/' AND '%q0'",
11177
+ zWhere, zSep, z, z, z
11178
+ );
11179
+ if( zWhere==0 ){
11180
+ *pRc = SQLITE_NOMEM;
11181
+ break;
11182
+ }
11183
+ zSep = " OR ";
11184
+ }
11185
+ }
11186
+ }
11187
+ *pzWhere = zWhere;
11188
+}
11189
+
11190
+/*
11191
+** Argument zMode must point to a buffer at least 11 bytes in size. This
11192
+** function populates this buffer with the string interpretation of
11193
+** the unix file mode passed as the second argument (e.g. "drwxr-xr-x").
11194
+*/
11195
+static void shellModeToString(char *zMode, int mode){
11196
+ int i;
11197
+
11198
+ /* Magic numbers copied from [man 2 stat] */
11199
+ if( mode & 0040000 ){
11200
+ zMode[0] = 'd';
11201
+ }else if( (mode & 0120000)==0120000 ){
11202
+ zMode[0] = 'l';
11203
+ }else{
11204
+ zMode[0] = '-';
11205
+ }
11206
+
11207
+ for(i=0; i<3; i++){
11208
+ int m = (mode >> ((2-i)*3));
11209
+ char *a = &zMode[1 + i*3];
11210
+ a[0] = (m & 0x4) ? 'r' : '-';
11211
+ a[1] = (m & 0x2) ? 'w' : '-';
11212
+ a[2] = (m & 0x1) ? 'x' : '-';
11213
+ }
11214
+ zMode[10] = '\0';
11215
+}
11216
+
11217
+/*
11218
+** Implementation of .ar "lisT" command.
11219
+*/
11220
+static int arListCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
11221
+ const char *zSql = "SELECT %s FROM %s WHERE %s";
11222
+ const char *zTbl = (pAr->bZip ? "zipfile(?)" : "sqlar");
11223
+ const char *azCols[] = {
11224
+ "name",
11225
+ "mode, sz, datetime(mtime, 'unixepoch'), name"
11226
+ };
11227
+
11228
+ char *zWhere = 0;
11229
+ sqlite3_stmt *pSql = 0;
11230
+ int rc;
11231
+
11232
+ rc = arCheckEntries(db, pAr);
11233
+ arWhereClause(&rc, pAr, &zWhere);
11234
+
11235
+ shellPreparePrintf(db, &rc, &pSql, zSql, azCols[pAr->bVerbose], zTbl, zWhere);
11236
+ if( rc==SQLITE_OK && pAr->bZip ){
11237
+ sqlite3_bind_text(pSql, 1, pAr->zFile, -1, SQLITE_TRANSIENT);
11238
+ }
11239
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11240
+ if( pAr->bVerbose ){
11241
+ char zMode[11];
11242
+ shellModeToString(zMode, sqlite3_column_int(pSql, 0));
11243
+
11244
+ raw_printf(p->out, "%s % 10d %s %s\n", zMode,
11245
+ sqlite3_column_int(pSql, 1),
11246
+ sqlite3_column_text(pSql, 2),
11247
+ sqlite3_column_text(pSql, 3)
11248
+ );
11249
+ }else{
11250
+ raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
11251
+ }
11252
+ }
11253
+
11254
+ shellFinalize(&rc, pSql);
11255
+ return rc;
11256
+}
11257
+
11258
+
11259
+/*
11260
+** Implementation of .ar "eXtract" command.
11261
+*/
11262
+static int arExtractCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
11263
+ const char *zSql1 =
11264
+ "SELECT "
11265
+ " :1 || name, "
11266
+ " writefile(?1 || name, %s, mode, mtime) "
11267
+ "FROM %s WHERE (%s) AND (data IS NULL OR ?2 = 0)";
11268
+
11269
+ const char *azExtraArg[] = {
11270
+ "sqlar_uncompress(data, sz)",
11271
+ "zipfile_uncompress(data, sz, method)"
11272
+ };
11273
+ const char *azSource[] = {
11274
+ "sqlar", "zipfile(?3)"
11275
+ };
11276
+
11277
+
11278
+
11279
+ sqlite3_stmt *pSql = 0;
11280
+ int rc = SQLITE_OK;
11281
+ char *zDir = 0;
11282
+ char *zWhere = 0;
11283
+ int i;
11284
+
11285
+ /* If arguments are specified, check that they actually exist within
11286
+ ** the archive before proceeding. And formulate a WHERE clause to
11287
+ ** match them. */
11288
+ rc = arCheckEntries(db, pAr);
11289
+ arWhereClause(&rc, pAr, &zWhere);
11290
+
11291
+ if( rc==SQLITE_OK ){
11292
+ if( pAr->zDir ){
11293
+ zDir = sqlite3_mprintf("%s/", pAr->zDir);
11294
+ }else{
11295
+ zDir = sqlite3_mprintf("");
11296
+ }
11297
+ if( zDir==0 ) rc = SQLITE_NOMEM;
11298
+ }
11299
+
11300
+ shellPreparePrintf(db, &rc, &pSql, zSql1,
11301
+ azExtraArg[pAr->bZip], azSource[pAr->bZip], zWhere
11302
+ );
11303
+
11304
+ if( rc==SQLITE_OK ){
11305
+ sqlite3_bind_text(pSql, 1, zDir, -1, SQLITE_STATIC);
11306
+ if( pAr->bZip ){
11307
+ sqlite3_bind_text(pSql, 3, pAr->zFile, -1, SQLITE_STATIC);
11308
+ }
11309
+
11310
+ /* Run the SELECT statement twice. The first time, writefile() is called
11311
+ ** for all archive members that should be extracted. The second time,
11312
+ ** only for the directories. This is because the timestamps for
11313
+ ** extracted directories must be reset after they are populated (as
11314
+ ** populating them changes the timestamp). */
11315
+ for(i=0; i<2; i++){
11316
+ sqlite3_bind_int(pSql, 2, i);
11317
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11318
+ if( i==0 && pAr->bVerbose ){
11319
+ raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
11320
+ }
11321
+ }
11322
+ shellReset(&rc, pSql);
11323
+ }
11324
+ shellFinalize(&rc, pSql);
11325
+ }
11326
+
11327
+ sqlite3_free(zDir);
11328
+ sqlite3_free(zWhere);
11329
+ return rc;
11330
+}
11331
+
11332
+
11333
+/*
11334
+** Implementation of .ar "create" and "update" commands.
11335
+**
11336
+** Create the "sqlar" table in the database if it does not already exist.
11337
+** Then add each file in the azFile[] array to the archive. Directories
11338
+** are added recursively. If argument bVerbose is non-zero, a message is
11339
+** printed on stdout for each file archived.
11340
+**
11341
+** The create command is the same as update, except that it drops
11342
+** any existing "sqlar" table before beginning.
11343
+*/
11344
+static int arCreateUpdate(
11345
+ ShellState *p, /* Shell state pointer */
11346
+ sqlite3 *db,
11347
+ ArCommand *pAr, /* Command arguments and options */
11348
+ int bUpdate
11349
+){
11350
+ const char *zSql = "SELECT name, mode, mtime, data FROM fsdir(?, ?)";
11351
+ const char *zCreate =
11352
+ "CREATE TABLE IF NOT EXISTS sqlar(\n"
11353
+ " name TEXT PRIMARY KEY, -- name of the file\n"
11354
+ " mode INT, -- access permissions\n"
11355
+ " mtime INT, -- last modification time\n"
11356
+ " sz INT, -- original file size\n"
11357
+ " data BLOB -- compressed content\n"
11358
+ ")";
11359
+ const char *zDrop = "DROP TABLE IF EXISTS sqlar";
11360
+ const char *zInsert = "REPLACE INTO sqlar VALUES(?,?,?,?,sqlar_compress(?))";
11361
+
11362
+ sqlite3_stmt *pStmt = 0; /* Directory traverser */
11363
+ sqlite3_stmt *pInsert = 0; /* Compilation of zInsert */
11364
+ int i; /* For iterating through azFile[] */
11365
+ int rc; /* Return code */
11366
+
11367
+ assert( pAr->bZip==0 );
11368
+
11369
+ rc = sqlite3_exec(db, "SAVEPOINT ar;", 0, 0, 0);
11370
+ if( rc!=SQLITE_OK ) return rc;
11371
+
11372
+ if( bUpdate==0 ){
11373
+ rc = sqlite3_exec(db, zDrop, 0, 0, 0);
11374
+ if( rc!=SQLITE_OK ) return rc;
11375
+ }
11376
+
11377
+ rc = sqlite3_exec(db, zCreate, 0, 0, 0);
11378
+ shellPrepare(db, &rc, zInsert, &pInsert);
11379
+ shellPrepare(db, &rc, zSql, &pStmt);
11380
+ sqlite3_bind_text(pStmt, 2, pAr->zDir, -1, SQLITE_STATIC);
11381
+
11382
+ for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11383
+ sqlite3_bind_text(pStmt, 1, pAr->azArg[i], -1, SQLITE_STATIC);
11384
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
11385
+ int sz;
11386
+ const char *zName = (const char*)sqlite3_column_text(pStmt, 0);
11387
+ int mode = sqlite3_column_int(pStmt, 1);
11388
+ unsigned int mtime = sqlite3_column_int(pStmt, 2);
11389
+
11390
+ if( pAr->bVerbose ){
11391
+ raw_printf(p->out, "%s\n", zName);
11392
+ }
11393
+
11394
+ sqlite3_bind_text(pInsert, 1, zName, -1, SQLITE_STATIC);
11395
+ sqlite3_bind_int(pInsert, 2, mode);
11396
+ sqlite3_bind_int64(pInsert, 3, (sqlite3_int64)mtime);
11397
+
11398
+ if( S_ISDIR(mode) ){
11399
+ sz = 0;
11400
+ sqlite3_bind_null(pInsert, 5);
11401
+ }else{
11402
+ sqlite3_bind_value(pInsert, 5, sqlite3_column_value(pStmt, 3));
11403
+ if( S_ISLNK(mode) ){
11404
+ sz = -1;
11405
+ }else{
11406
+ sz = sqlite3_column_bytes(pStmt, 3);
11407
+ }
11408
+ }
11409
+
11410
+ sqlite3_bind_int(pInsert, 4, sz);
11411
+ sqlite3_step(pInsert);
11412
+ rc = sqlite3_reset(pInsert);
11413
+ }
11414
+ shellReset(&rc, pStmt);
11415
+ }
11416
+
11417
+ if( rc!=SQLITE_OK ){
11418
+ sqlite3_exec(db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0);
11419
+ }else{
11420
+ rc = sqlite3_exec(db, "RELEASE ar;", 0, 0, 0);
11421
+ }
11422
+ shellFinalize(&rc, pStmt);
11423
+ shellFinalize(&rc, pInsert);
11424
+ return rc;
11425
+}
11426
+
11427
+/*
11428
+** Implementation of .ar "Create" command.
11429
+**
11430
+** Create the "sqlar" table in the database if it does not already exist.
11431
+** Then add each file in the azFile[] array to the archive. Directories
11432
+** are added recursively. If argument bVerbose is non-zero, a message is
11433
+** printed on stdout for each file archived.
11434
+*/
11435
+static int arCreateCommand(
11436
+ ShellState *p, /* Shell state pointer */
11437
+ sqlite3 *db,
11438
+ ArCommand *pAr /* Command arguments and options */
11439
+){
11440
+ return arCreateUpdate(p, db, pAr, 0);
11441
+}
11442
+
11443
+/*
11444
+** Implementation of .ar "Update" command.
11445
+*/
11446
+static int arUpdateCmd(ShellState *p, sqlite3 *db, ArCommand *pAr){
11447
+ return arCreateUpdate(p, db, pAr, 1);
11448
+}
11449
+
11450
+
11451
+/*
11452
+** Implementation of ".ar" dot command.
11453
+*/
11454
+static int arDotCommand(
11455
+ ShellState *pState, /* Current shell tool state */
11456
+ char **azArg, /* Array of arguments passed to dot command */
11457
+ int nArg /* Number of entries in azArg[] */
11458
+){
11459
+ ArCommand cmd;
11460
+ int rc;
11461
+ rc = arParseCommand(azArg, nArg, &cmd);
11462
+ if( rc==SQLITE_OK ){
11463
+ sqlite3 *db = 0; /* Database handle to use as archive */
11464
+
11465
+ if( cmd.bZip ){
11466
+ if( cmd.zFile==0 ){
11467
+ raw_printf(stderr, "zip format requires a --file switch\n");
11468
+ return SQLITE_ERROR;
11469
+ }else
11470
+ if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
11471
+ raw_printf(stderr, "zip archives are read-only\n");
11472
+ return SQLITE_ERROR;
11473
+ }
11474
+ db = pState->db;
11475
+ }else if( cmd.zFile ){
11476
+ int flags;
11477
+ if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
11478
+ flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
11479
+ }else{
11480
+ flags = SQLITE_OPEN_READONLY;
11481
+ }
11482
+ rc = sqlite3_open_v2(cmd.zFile, &db, flags, 0);
11483
+ if( rc!=SQLITE_OK ){
11484
+ raw_printf(stderr, "cannot open file: %s (%s)\n",
11485
+ cmd.zFile, sqlite3_errmsg(db)
11486
+ );
11487
+ sqlite3_close(db);
11488
+ return rc;
11489
+ }
11490
+ sqlite3_fileio_init(db, 0, 0);
11491
+#ifdef SQLITE_HAVE_ZLIB
11492
+ sqlite3_sqlar_init(db, 0, 0);
11493
+#endif
11494
+ }else{
11495
+ db = pState->db;
11496
+ }
11497
+
11498
+ switch( cmd.eCmd ){
11499
+ case AR_CMD_CREATE:
11500
+ rc = arCreateCommand(pState, db, &cmd);
11501
+ break;
11502
+
11503
+ case AR_CMD_EXTRACT:
11504
+ rc = arExtractCommand(pState, db, &cmd);
11505
+ break;
11506
+
11507
+ case AR_CMD_LIST:
11508
+ rc = arListCommand(pState, db, &cmd);
11509
+ break;
11510
+
11511
+ case AR_CMD_HELP:
11512
+ arUsage(pState->out);
11513
+ break;
11514
+
11515
+ default:
11516
+ assert( cmd.eCmd==AR_CMD_UPDATE );
11517
+ rc = arUpdateCmd(pState, db, &cmd);
11518
+ break;
11519
+ }
11520
+
11521
+ if( cmd.zFile ){
11522
+ sqlite3_close(db);
11523
+ }
11524
+ }
11525
+
11526
+ return rc;
11527
+}
11528
+/* End of the ".archive" or ".ar" command logic
11529
+**********************************************************************************/
11530
+#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) */
11531
+
11532
+/*
11533
+** Implementation of ".expert" dot command.
11534
+*/
11535
+static int expertDotCommand(
11536
+ ShellState *pState, /* Current shell tool state */
11537
+ char **azArg, /* Array of arguments passed to dot command */
11538
+ int nArg /* Number of entries in azArg[] */
11539
+){
11540
+ int rc = SQLITE_OK;
11541
+ char *zErr = 0;
11542
+ int i;
11543
+ int iSample = 0;
11544
+
11545
+ assert( pState->expert.pExpert==0 );
11546
+ memset(&pState->expert, 0, sizeof(ExpertInfo));
11547
+
11548
+ for(i=1; rc==SQLITE_OK && i<nArg; i++){
11549
+ char *z = azArg[i];
11550
+ int n;
11551
+ if( z[0]=='-' && z[1]=='-' ) z++;
11552
+ n = strlen30(z);
11553
+ if( n>=2 && 0==strncmp(z, "-verbose", n) ){
11554
+ pState->expert.bVerbose = 1;
11555
+ }
11556
+ else if( n>=2 && 0==strncmp(z, "-sample", n) ){
11557
+ if( i==(nArg-1) ){
11558
+ raw_printf(stderr, "option requires an argument: %s\n", z);
11559
+ rc = SQLITE_ERROR;
11560
+ }else{
11561
+ iSample = (int)integerValue(azArg[++i]);
11562
+ if( iSample<0 || iSample>100 ){
11563
+ raw_printf(stderr, "value out of range: %s\n", azArg[i]);
11564
+ rc = SQLITE_ERROR;
11565
+ }
11566
+ }
11567
+ }
11568
+ else{
11569
+ raw_printf(stderr, "unknown option: %s\n", z);
11570
+ rc = SQLITE_ERROR;
11571
+ }
11572
+ }
11573
+
11574
+ if( rc==SQLITE_OK ){
11575
+ pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
11576
+ if( pState->expert.pExpert==0 ){
11577
+ raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
11578
+ rc = SQLITE_ERROR;
11579
+ }else{
11580
+ sqlite3_expert_config(
11581
+ pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
11582
+ );
11583
+ }
11584
+ }
11585
+
11586
+ return rc;
11587
+}
543011588
543111589
543211590
/*
543311591
** If an input line begins with "." then invoke this routine to
543411592
** process that line.
@@ -5439,10 +11597,14 @@
543911597
int h = 1;
544011598
int nArg = 0;
544111599
int n, c;
544211600
int rc = 0;
544311601
char *azArg[50];
11602
+
11603
+ if( p->expert.pExpert ){
11604
+ expertFinish(p, 1, 0);
11605
+ }
544411606
544511607
/* Parse the input line into tokens.
544611608
*/
544711609
while( zLine[h] && nArg<ArraySize(azArg) ){
544811610
while( IsSpace(zLine[h]) ){ h++; }
@@ -5485,10 +11647,17 @@
548511647
}else{
548611648
sqlite3_set_authorizer(p->db, 0, 0);
548711649
}
548811650
}else
548911651
#endif
11652
+
11653
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
11654
+ if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
11655
+ open_db(p, 0);
11656
+ rc = arDotCommand(p, azArg, nArg);
11657
+ }else
11658
+#endif
549011659
549111660
if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
549211661
|| (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
549311662
){
549411663
const char *zDestFile = 0;
@@ -5755,16 +11924,18 @@
575511924
}else
575611925
575711926
if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
575811927
if( nArg==2 ){
575911928
if( strcmp(azArg[1],"full")==0 ){
5760
- p->autoEQP = 2;
11929
+ p->autoEQP = AUTOEQP_full;
11930
+ }else if( strcmp(azArg[1],"trigger")==0 ){
11931
+ p->autoEQP = AUTOEQP_trigger;
576111932
}else{
576211933
p->autoEQP = booleanValue(azArg[1]);
576311934
}
576411935
}else{
5765
- raw_printf(stderr, "Usage: .eqp on|off|full\n");
11936
+ raw_printf(stderr, "Usage: .eqp off|on|trigger|full\n");
576611937
rc = 1;
576711938
}
576811939
}else
576911940
577011941
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -5793,10 +11964,15 @@
579311964
}else if( val==99 ){
579411965
if( p->mode==MODE_Explain ) p->mode = p->normalMode;
579511966
p->autoExplain = 1;
579611967
}
579711968
}else
11969
+
11970
+ if( c=='e' && strncmp(azArg[0], "expert", n)==0 ){
11971
+ open_db(p, 0);
11972
+ expertDotCommand(p, azArg, nArg);
11973
+ }else
579811974
579911975
if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
580011976
ShellState data;
580111977
char *zErrMsg = 0;
580211978
int doStats = 0;
@@ -6254,11 +12430,11 @@
625412430
}
625512431
}else
625612432
625712433
if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
625812434
const char *zMode = nArg>=2 ? azArg[1] : "";
6259
- int n2 = (int)strlen(zMode);
12435
+ int n2 = strlen30(zMode);
626012436
int c2 = zMode[0];
626112437
if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
626212438
p->mode = MODE_Line;
626312439
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
626412440
}else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
@@ -6319,15 +12495,22 @@
631912495
sqlite3_close(p->db);
632012496
p->db = 0;
632112497
p->zDbFilename = 0;
632212498
sqlite3_free(p->zFreeOnClose);
632312499
p->zFreeOnClose = 0;
12500
+ p->openMode = SHELL_OPEN_UNSPEC;
632412501
/* Check for command-line arguments */
632512502
for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
632612503
const char *z = azArg[iName];
632712504
if( optionMatch(z,"new") ){
632812505
newFlag = 1;
12506
+#ifdef SQLITE_HAVE_ZIP
12507
+ }else if( optionMatch(z, "zip") ){
12508
+ p->openMode = SHELL_OPEN_ZIPFILE;
12509
+#endif
12510
+ }else if( optionMatch(z, "append") ){
12511
+ p->openMode = SHELL_OPEN_APPENDVFS;
632912512
}else if( z[0]=='-' ){
633012513
utf8_printf(stderr, "unknown option: %s\n", z);
633112514
rc = 1;
633212515
goto meta_command_exit;
633312516
}
@@ -6506,63 +12689,52 @@
650612689
650712690
if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
650812691
ShellText sSelect;
650912692
ShellState data;
651012693
char *zErrMsg = 0;
6511
- const char *zDiv = 0;
12694
+ const char *zDiv = "(";
12695
+ const char *zName = 0;
651212696
int iSchema = 0;
12697
+ int bDebug = 0;
12698
+ int ii;
651312699
651412700
open_db(p, 0);
651512701
memcpy(&data, p, sizeof(data));
651612702
data.showHeader = 0;
651712703
data.cMode = data.mode = MODE_Semi;
651812704
initText(&sSelect);
6519
- if( nArg>=2 && optionMatch(azArg[1], "indent") ){
6520
- data.cMode = data.mode = MODE_Pretty;
6521
- nArg--;
6522
- if( nArg==2 ) azArg[1] = azArg[2];
6523
- }
6524
- if( nArg==2 && azArg[1][0]!='-' ){
6525
- int i;
6526
- for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
6527
- if( strcmp(azArg[1],"sqlite_master")==0 ){
6528
- char *new_argv[2], *new_colv[2];
6529
- new_argv[0] = "CREATE TABLE sqlite_master (\n"
6530
- " type text,\n"
6531
- " name text,\n"
6532
- " tbl_name text,\n"
6533
- " rootpage integer,\n"
6534
- " sql text\n"
6535
- ")";
6536
- new_argv[1] = 0;
6537
- new_colv[0] = "sql";
6538
- new_colv[1] = 0;
6539
- callback(&data, 1, new_argv, new_colv);
6540
- rc = SQLITE_OK;
6541
- }else if( strcmp(azArg[1],"sqlite_temp_master")==0 ){
6542
- char *new_argv[2], *new_colv[2];
6543
- new_argv[0] = "CREATE TEMP TABLE sqlite_temp_master (\n"
6544
- " type text,\n"
6545
- " name text,\n"
6546
- " tbl_name text,\n"
6547
- " rootpage integer,\n"
6548
- " sql text\n"
6549
- ")";
6550
- new_argv[1] = 0;
6551
- new_colv[0] = "sql";
6552
- new_colv[1] = 0;
6553
- callback(&data, 1, new_argv, new_colv);
6554
- rc = SQLITE_OK;
6555
- }else{
6556
- zDiv = "(";
6557
- }
6558
- }else if( nArg==1 ){
6559
- zDiv = "(";
6560
- }else{
6561
- raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
6562
- rc = 1;
6563
- goto meta_command_exit;
12705
+ for(ii=1; ii<nArg; ii++){
12706
+ if( optionMatch(azArg[ii],"indent") ){
12707
+ data.cMode = data.mode = MODE_Pretty;
12708
+ }else if( optionMatch(azArg[ii],"debug") ){
12709
+ bDebug = 1;
12710
+ }else if( zName==0 ){
12711
+ zName = azArg[ii];
12712
+ }else{
12713
+ raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
12714
+ rc = 1;
12715
+ goto meta_command_exit;
12716
+ }
12717
+ }
12718
+ if( zName!=0 ){
12719
+ int isMaster = sqlite3_strlike(zName, "sqlite_master", 0)==0;
12720
+ if( isMaster || sqlite3_strlike(zName,"sqlite_temp_master",0)==0 ){
12721
+ char *new_argv[2], *new_colv[2];
12722
+ new_argv[0] = sqlite3_mprintf(
12723
+ "CREATE TABLE %s (\n"
12724
+ " type text,\n"
12725
+ " name text,\n"
12726
+ " tbl_name text,\n"
12727
+ " rootpage integer,\n"
12728
+ " sql text\n"
12729
+ ")", isMaster ? "sqlite_master" : "sqlite_temp_master");
12730
+ new_argv[1] = 0;
12731
+ new_colv[0] = "sql";
12732
+ new_colv[1] = 0;
12733
+ callback(&data, 1, new_argv, new_colv);
12734
+ sqlite3_free(new_argv[0]);
12735
+ }
656412736
}
656512737
if( zDiv ){
656612738
sqlite3_stmt *pStmt = 0;
656712739
rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list",
656812740
-1, &pStmt, 0);
@@ -6578,43 +12750,52 @@
657812750
const char *zDb = (const char*)sqlite3_column_text(pStmt, 0);
657912751
char zScNum[30];
658012752
sqlite3_snprintf(sizeof(zScNum), zScNum, "%d", ++iSchema);
658112753
appendText(&sSelect, zDiv, 0);
658212754
zDiv = " UNION ALL ";
6583
- if( strcmp(zDb, "main")!=0 ){
6584
- appendText(&sSelect, "SELECT shell_add_schema(sql,", 0);
6585
- appendText(&sSelect, zDb, '"');
6586
- appendText(&sSelect, ") AS sql, type, tbl_name, name, rowid,", 0);
6587
- appendText(&sSelect, zScNum, 0);
6588
- appendText(&sSelect, " AS snum, ", 0);
6589
- appendText(&sSelect, zDb, '\'');
6590
- appendText(&sSelect, " AS sname FROM ", 0);
6591
- appendText(&sSelect, zDb, '"');
6592
- appendText(&sSelect, ".sqlite_master", 0);
6593
- }else{
6594
- appendText(&sSelect, "SELECT sql, type, tbl_name, name, rowid, ", 0);
6595
- appendText(&sSelect, zScNum, 0);
6596
- appendText(&sSelect, " AS snum, 'main' AS sname FROM sqlite_master",0);
6597
- }
12755
+ appendText(&sSelect, "SELECT shell_add_schema(sql,", 0);
12756
+ if( sqlite3_stricmp(zDb, "main")!=0 ){
12757
+ appendText(&sSelect, zDb, '"');
12758
+ }else{
12759
+ appendText(&sSelect, "NULL", 0);
12760
+ }
12761
+ appendText(&sSelect, ",name) AS sql, type, tbl_name, name, rowid,", 0);
12762
+ appendText(&sSelect, zScNum, 0);
12763
+ appendText(&sSelect, " AS snum, ", 0);
12764
+ appendText(&sSelect, zDb, '\'');
12765
+ appendText(&sSelect, " AS sname FROM ", 0);
12766
+ appendText(&sSelect, zDb, '"');
12767
+ appendText(&sSelect, ".sqlite_master", 0);
659812768
}
659912769
sqlite3_finalize(pStmt);
12770
+#ifdef SQLITE_INTROSPECTION_PRAGMAS
12771
+ if( zName ){
12772
+ appendText(&sSelect,
12773
+ " UNION ALL SELECT shell_module_schema(name),"
12774
+ " 'table', name, name, name, 9e+99, 'main' FROM pragma_module_list", 0);
12775
+ }
12776
+#endif
660012777
appendText(&sSelect, ") WHERE ", 0);
6601
- if( nArg>1 ){
6602
- char *zQarg = sqlite3_mprintf("%Q", azArg[1]);
6603
- if( strchr(azArg[1], '.') ){
12778
+ if( zName ){
12779
+ char *zQarg = sqlite3_mprintf("%Q", zName);
12780
+ if( strchr(zName, '.') ){
660412781
appendText(&sSelect, "lower(printf('%s.%s',sname,tbl_name))", 0);
660512782
}else{
660612783
appendText(&sSelect, "lower(tbl_name)", 0);
660712784
}
6608
- appendText(&sSelect, strchr(azArg[1], '*') ? " GLOB " : " LIKE ", 0);
12785
+ appendText(&sSelect, strchr(zName, '*') ? " GLOB " : " LIKE ", 0);
660912786
appendText(&sSelect, zQarg, 0);
661012787
appendText(&sSelect, " AND ", 0);
661112788
sqlite3_free(zQarg);
661212789
}
661312790
appendText(&sSelect, "type!='meta' AND sql IS NOT NULL"
661412791
" ORDER BY snum, rowid", 0);
6615
- rc = sqlite3_exec(p->db, sSelect.z, callback, &data, &zErrMsg);
12792
+ if( bDebug ){
12793
+ utf8_printf(p->out, "SQL: %s;\n", sSelect.z);
12794
+ }else{
12795
+ rc = sqlite3_exec(p->db, sSelect.z, callback, &data, &zErrMsg);
12796
+ }
661612797
freeText(&sSelect);
661712798
}
661812799
if( zErrMsg ){
661912800
utf8_printf(stderr,"Error: %s\n", zErrMsg);
662012801
sqlite3_free(zErrMsg);
@@ -7108,11 +13289,11 @@
710813289
sqlite3_free(zCmd);
710913290
if( x ) raw_printf(stderr, "System command returns %d\n", x);
711013291
}else
711113292
711213293
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
7113
- static const char *azBool[] = { "off", "on", "full", "unk" };
13294
+ static const char *azBool[] = { "off", "on", "trigger", "full"};
711413295
int i;
711513296
if( nArg!=1 ){
711613297
raw_printf(stderr, "Usage: .show\n");
711713298
rc = 1;
711813299
goto meta_command_exit;
@@ -7296,10 +13477,13 @@
729613477
{ "iskeyword", SQLITE_TESTCTRL_ISKEYWORD, "IDENTIFIER" },
729713478
#endif
729813479
{ "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
729913480
{ "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
730013481
{ "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
13482
+#ifdef YYCOVERAGE
13483
+ { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
13484
+#endif
730113485
{ "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
730213486
{ "prng_reset", SQLITE_TESTCTRL_PRNG_RESET, "" },
730313487
{ "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
730413488
{ "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
730513489
{ "reserve", SQLITE_TESTCTRL_RESERVE, "BYTES-OF-RESERVE" },
@@ -7421,10 +13605,18 @@
742113605
integerValue(azArg[3]),
742213606
integerValue(azArg[4]));
742313607
isOk = 3;
742413608
}
742513609
break;
13610
+
13611
+#ifdef YYCOVERAGE
13612
+ case SQLITE_TESTCTRL_PARSER_COVERAGE:
13613
+ if( nArg==2 ){
13614
+ sqlite3_test_control(testctrl, p->out);
13615
+ isOk = 3;
13616
+ }
13617
+#endif
742613618
}
742713619
}
742813620
if( isOk==0 && iCtrl>=0 ){
742913621
utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd, aCtrl[iCtrl].zUsage);
743013622
rc = 1;
@@ -7484,12 +13676,11 @@
748413676
if( nArg!=4 ){
748513677
raw_printf(stderr, "Usage: .user login USER PASSWORD\n");
748613678
rc = 1;
748713679
goto meta_command_exit;
748813680
}
7489
- rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
7490
- (int)strlen(azArg[3]));
13681
+ rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3], strlen30(azArg[3]));
749113682
if( rc ){
749213683
utf8_printf(stderr, "Authentication failed for user %s\n", azArg[2]);
749313684
rc = 1;
749413685
}
749513686
}else if( strcmp(azArg[1],"add")==0 ){
@@ -7496,12 +13687,11 @@
749613687
if( nArg!=5 ){
749713688
raw_printf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
749813689
rc = 1;
749913690
goto meta_command_exit;
750013691
}
7501
- rc = sqlite3_user_add(p->db, azArg[2],
7502
- azArg[3], (int)strlen(azArg[3]),
13692
+ rc = sqlite3_user_add(p->db, azArg[2], azArg[3], strlen30(azArg[3]),
750313693
booleanValue(azArg[4]));
750413694
if( rc ){
750513695
raw_printf(stderr, "User-Add failed: %d\n", rc);
750613696
rc = 1;
750713697
}
@@ -7509,12 +13699,11 @@
750913699
if( nArg!=5 ){
751013700
raw_printf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
751113701
rc = 1;
751213702
goto meta_command_exit;
751313703
}
7514
- rc = sqlite3_user_change(p->db, azArg[2],
7515
- azArg[3], (int)strlen(azArg[3]),
13704
+ rc = sqlite3_user_change(p->db, azArg[2], azArg[3], strlen30(azArg[3]),
751613705
booleanValue(azArg[4]));
751713706
if( rc ){
751813707
raw_printf(stderr, "User-Edit failed: %d\n", rc);
751913708
rc = 1;
752013709
}
@@ -8186,10 +14375,16 @@
818614375
sqlite3_vfs_register(pVfs, 1);
818714376
}else{
818814377
utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
818914378
exit(1);
819014379
}
14380
+#ifdef SQLITE_HAVE_ZIP
14381
+ }else if( strcmp(z,"-zip")==0 ){
14382
+ data.openMode = SHELL_OPEN_ZIPFILE;
14383
+#endif
14384
+ }else if( strcmp(z,"-append")==0 ){
14385
+ data.openMode = SHELL_OPEN_APPENDVFS;
819114386
}
819214387
}
819314388
if( data.zDbFilename==0 ){
819414389
#ifndef SQLITE_OMIT_MEMORYDB
819514390
data.zDbFilename = ":memory:";
@@ -8198,10 +14393,11 @@
819814393
utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
819914394
return 1;
820014395
#endif
820114396
}
820214397
data.out = stdout;
14398
+ sqlite3_appendvfs_init(0,0,0);
820314399
820414400
/* Go ahead and open the database file if it already exists. If the
820514401
** file does not exist, delay opening it. This prevents empty database
820614402
** files from being created if a user mistypes the database name argument
820714403
** to the sqlite command-line tool.
@@ -8238,10 +14434,16 @@
823814434
}else if( strcmp(z,"-column")==0 ){
823914435
data.mode = MODE_Column;
824014436
}else if( strcmp(z,"-csv")==0 ){
824114437
data.mode = MODE_Csv;
824214438
memcpy(data.colSeparator,",",2);
14439
+#ifdef SQLITE_HAVE_ZIP
14440
+ }else if( strcmp(z,"-zip")==0 ){
14441
+ data.openMode = SHELL_OPEN_ZIPFILE;
14442
+#endif
14443
+ }else if( strcmp(z,"-append")==0 ){
14444
+ data.openMode = SHELL_OPEN_APPENDVFS;
824314445
}else if( strcmp(z,"-ascii")==0 ){
824414446
data.mode = MODE_Ascii;
824514447
sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
824614448
SEP_Unit);
824714449
sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
@@ -8260,13 +14462,13 @@
826014462
}else if( strcmp(z,"-noheader")==0 ){
826114463
data.showHeader = 0;
826214464
}else if( strcmp(z,"-echo")==0 ){
826314465
ShellSetFlag(&data, SHFLG_Echo);
826414466
}else if( strcmp(z,"-eqp")==0 ){
8265
- data.autoEQP = 1;
14467
+ data.autoEQP = AUTOEQP_on;
826614468
}else if( strcmp(z,"-eqpfull")==0 ){
8267
- data.autoEQP = 2;
14469
+ data.autoEQP = AUTOEQP_full;
826814470
}else if( strcmp(z,"-stats")==0 ){
826914471
data.statsOn = 1;
827014472
}else if( strcmp(z,"-scanstats")==0 ){
827114473
data.scanstatsOn = 1;
827214474
}else if( strcmp(z,"-backslash")==0 ){
827314475
--- src/shell.c
+++ src/shell.c
@@ -77,10 +77,13 @@
77 #include <stdlib.h>
78 #include <string.h>
79 #include <stdio.h>
80 #include <assert.h>
81 #include "sqlite3.h"
 
 
 
82 #if SQLITE_USER_AUTHENTICATION
83 # include "sqlite3userauth.h"
84 #endif
85 #include <ctype.h>
86 #include <stdarg.h>
@@ -88,13 +91,23 @@
88 #if !defined(_WIN32) && !defined(WIN32)
89 # include <signal.h>
90 # if !defined(__RTP__) && !defined(_WRS_KERNEL)
91 # include <pwd.h>
92 # endif
 
 
93 # include <unistd.h>
94 # include <sys/types.h>
 
 
 
 
 
 
95 #endif
 
 
96
97 #if HAVE_READLINE
98 # include <readline/readline.h>
99 # include <readline/history.h>
100 #endif
@@ -744,10 +757,75 @@
744 upr = mid-1;
745 }
746 }
747 return 0;
748 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
750 /*
751 ** SQL function: shell_add_schema(S,X)
752 **
753 ** Add the schema name X to the CREATE statement in S and return the result.
@@ -780,24 +858,40 @@
780 "VIRTUAL TABLE"
781 };
782 int i = 0;
783 const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
784 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
785 assert( nVal==2 );
 
786 if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
787 for(i=0; i<(int)(sizeof(aPrefix)/sizeof(aPrefix[0])); i++){
788 int n = strlen30(aPrefix[i]);
789 if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
790 char cQuote = quoteChar(zSchema);
791 char *z;
792 if( cQuote ){
793 z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
794 }else{
795 z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
796 }
797 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
798 return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
799 }
800 }
801 }
802 sqlite3_result_value(pCtx, apVal[0]);
803 }
@@ -809,10 +903,208 @@
809 ** work here in the middle of this regular program.
810 */
811 #define SQLITE_EXTENSION_INIT1
812 #define SQLITE_EXTENSION_INIT2(X) (void)(X)
813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
814 /************************* Begin ../ext/misc/shathree.c ******************/
815 /*
816 ** 2017-03-08
817 **
818 ** The author disclaims copyright to this source code. In place of
@@ -842,11 +1134,11 @@
842 */
843 SQLITE_EXTENSION_INIT1
844 #include <assert.h>
845 #include <string.h>
846 #include <stdarg.h>
847 typedef sqlite3_uint64 u64;
848
849 /******************************************************************************
850 ** The Hash Engine
851 */
852 /*
@@ -889,13 +1181,13 @@
889 /*
890 ** A single step of the Keccak mixing function for a 1600-bit state
891 */
892 static void KeccakF1600Step(SHA3Context *p){
893 int i;
894 u64 B0, B1, B2, B3, B4;
895 u64 C0, C1, C2, C3, C4;
896 u64 D0, D1, D2, D3, D4;
897 static const u64 RC[] = {
898 0x0000000000000001ULL, 0x0000000000008082ULL,
899 0x800000000000808aULL, 0x8000000080008000ULL,
900 0x000000000000808bULL, 0x0000000080000001ULL,
901 0x8000000080008081ULL, 0x8000000000008009ULL,
@@ -906,305 +1198,305 @@
906 0x8000000000008002ULL, 0x8000000000000080ULL,
907 0x000000000000800aULL, 0x800000008000000aULL,
908 0x8000000080008081ULL, 0x8000000000008080ULL,
909 0x0000000080000001ULL, 0x8000000080008008ULL
910 };
911 # define A00 (p->u.s[0])
912 # define A01 (p->u.s[1])
913 # define A02 (p->u.s[2])
914 # define A03 (p->u.s[3])
915 # define A04 (p->u.s[4])
916 # define A10 (p->u.s[5])
917 # define A11 (p->u.s[6])
918 # define A12 (p->u.s[7])
919 # define A13 (p->u.s[8])
920 # define A14 (p->u.s[9])
921 # define A20 (p->u.s[10])
922 # define A21 (p->u.s[11])
923 # define A22 (p->u.s[12])
924 # define A23 (p->u.s[13])
925 # define A24 (p->u.s[14])
926 # define A30 (p->u.s[15])
927 # define A31 (p->u.s[16])
928 # define A32 (p->u.s[17])
929 # define A33 (p->u.s[18])
930 # define A34 (p->u.s[19])
931 # define A40 (p->u.s[20])
932 # define A41 (p->u.s[21])
933 # define A42 (p->u.s[22])
934 # define A43 (p->u.s[23])
935 # define A44 (p->u.s[24])
936 # define ROL64(a,x) ((a<<x)|(a>>(64-x)))
937
938 for(i=0; i<24; i+=4){
939 C0 = A00^A10^A20^A30^A40;
940 C1 = A01^A11^A21^A31^A41;
941 C2 = A02^A12^A22^A32^A42;
942 C3 = A03^A13^A23^A33^A43;
943 C4 = A04^A14^A24^A34^A44;
944 D0 = C4^ROL64(C1, 1);
945 D1 = C0^ROL64(C2, 1);
946 D2 = C1^ROL64(C3, 1);
947 D3 = C2^ROL64(C4, 1);
948 D4 = C3^ROL64(C0, 1);
949
950 B0 = (A00^D0);
951 B1 = ROL64((A11^D1), 44);
952 B2 = ROL64((A22^D2), 43);
953 B3 = ROL64((A33^D3), 21);
954 B4 = ROL64((A44^D4), 14);
955 A00 = B0 ^((~B1)& B2 );
956 A00 ^= RC[i];
957 A11 = B1 ^((~B2)& B3 );
958 A22 = B2 ^((~B3)& B4 );
959 A33 = B3 ^((~B4)& B0 );
960 A44 = B4 ^((~B0)& B1 );
961
962 B2 = ROL64((A20^D0), 3);
963 B3 = ROL64((A31^D1), 45);
964 B4 = ROL64((A42^D2), 61);
965 B0 = ROL64((A03^D3), 28);
966 B1 = ROL64((A14^D4), 20);
967 A20 = B0 ^((~B1)& B2 );
968 A31 = B1 ^((~B2)& B3 );
969 A42 = B2 ^((~B3)& B4 );
970 A03 = B3 ^((~B4)& B0 );
971 A14 = B4 ^((~B0)& B1 );
972
973 B4 = ROL64((A40^D0), 18);
974 B0 = ROL64((A01^D1), 1);
975 B1 = ROL64((A12^D2), 6);
976 B2 = ROL64((A23^D3), 25);
977 B3 = ROL64((A34^D4), 8);
978 A40 = B0 ^((~B1)& B2 );
979 A01 = B1 ^((~B2)& B3 );
980 A12 = B2 ^((~B3)& B4 );
981 A23 = B3 ^((~B4)& B0 );
982 A34 = B4 ^((~B0)& B1 );
983
984 B1 = ROL64((A10^D0), 36);
985 B2 = ROL64((A21^D1), 10);
986 B3 = ROL64((A32^D2), 15);
987 B4 = ROL64((A43^D3), 56);
988 B0 = ROL64((A04^D4), 27);
989 A10 = B0 ^((~B1)& B2 );
990 A21 = B1 ^((~B2)& B3 );
991 A32 = B2 ^((~B3)& B4 );
992 A43 = B3 ^((~B4)& B0 );
993 A04 = B4 ^((~B0)& B1 );
994
995 B3 = ROL64((A30^D0), 41);
996 B4 = ROL64((A41^D1), 2);
997 B0 = ROL64((A02^D2), 62);
998 B1 = ROL64((A13^D3), 55);
999 B2 = ROL64((A24^D4), 39);
1000 A30 = B0 ^((~B1)& B2 );
1001 A41 = B1 ^((~B2)& B3 );
1002 A02 = B2 ^((~B3)& B4 );
1003 A13 = B3 ^((~B4)& B0 );
1004 A24 = B4 ^((~B0)& B1 );
1005
1006 C0 = A00^A20^A40^A10^A30;
1007 C1 = A11^A31^A01^A21^A41;
1008 C2 = A22^A42^A12^A32^A02;
1009 C3 = A33^A03^A23^A43^A13;
1010 C4 = A44^A14^A34^A04^A24;
1011 D0 = C4^ROL64(C1, 1);
1012 D1 = C0^ROL64(C2, 1);
1013 D2 = C1^ROL64(C3, 1);
1014 D3 = C2^ROL64(C4, 1);
1015 D4 = C3^ROL64(C0, 1);
1016
1017 B0 = (A00^D0);
1018 B1 = ROL64((A31^D1), 44);
1019 B2 = ROL64((A12^D2), 43);
1020 B3 = ROL64((A43^D3), 21);
1021 B4 = ROL64((A24^D4), 14);
1022 A00 = B0 ^((~B1)& B2 );
1023 A00 ^= RC[i+1];
1024 A31 = B1 ^((~B2)& B3 );
1025 A12 = B2 ^((~B3)& B4 );
1026 A43 = B3 ^((~B4)& B0 );
1027 A24 = B4 ^((~B0)& B1 );
1028
1029 B2 = ROL64((A40^D0), 3);
1030 B3 = ROL64((A21^D1), 45);
1031 B4 = ROL64((A02^D2), 61);
1032 B0 = ROL64((A33^D3), 28);
1033 B1 = ROL64((A14^D4), 20);
1034 A40 = B0 ^((~B1)& B2 );
1035 A21 = B1 ^((~B2)& B3 );
1036 A02 = B2 ^((~B3)& B4 );
1037 A33 = B3 ^((~B4)& B0 );
1038 A14 = B4 ^((~B0)& B1 );
1039
1040 B4 = ROL64((A30^D0), 18);
1041 B0 = ROL64((A11^D1), 1);
1042 B1 = ROL64((A42^D2), 6);
1043 B2 = ROL64((A23^D3), 25);
1044 B3 = ROL64((A04^D4), 8);
1045 A30 = B0 ^((~B1)& B2 );
1046 A11 = B1 ^((~B2)& B3 );
1047 A42 = B2 ^((~B3)& B4 );
1048 A23 = B3 ^((~B4)& B0 );
1049 A04 = B4 ^((~B0)& B1 );
1050
1051 B1 = ROL64((A20^D0), 36);
1052 B2 = ROL64((A01^D1), 10);
1053 B3 = ROL64((A32^D2), 15);
1054 B4 = ROL64((A13^D3), 56);
1055 B0 = ROL64((A44^D4), 27);
1056 A20 = B0 ^((~B1)& B2 );
1057 A01 = B1 ^((~B2)& B3 );
1058 A32 = B2 ^((~B3)& B4 );
1059 A13 = B3 ^((~B4)& B0 );
1060 A44 = B4 ^((~B0)& B1 );
1061
1062 B3 = ROL64((A10^D0), 41);
1063 B4 = ROL64((A41^D1), 2);
1064 B0 = ROL64((A22^D2), 62);
1065 B1 = ROL64((A03^D3), 55);
1066 B2 = ROL64((A34^D4), 39);
1067 A10 = B0 ^((~B1)& B2 );
1068 A41 = B1 ^((~B2)& B3 );
1069 A22 = B2 ^((~B3)& B4 );
1070 A03 = B3 ^((~B4)& B0 );
1071 A34 = B4 ^((~B0)& B1 );
1072
1073 C0 = A00^A40^A30^A20^A10;
1074 C1 = A31^A21^A11^A01^A41;
1075 C2 = A12^A02^A42^A32^A22;
1076 C3 = A43^A33^A23^A13^A03;
1077 C4 = A24^A14^A04^A44^A34;
1078 D0 = C4^ROL64(C1, 1);
1079 D1 = C0^ROL64(C2, 1);
1080 D2 = C1^ROL64(C3, 1);
1081 D3 = C2^ROL64(C4, 1);
1082 D4 = C3^ROL64(C0, 1);
1083
1084 B0 = (A00^D0);
1085 B1 = ROL64((A21^D1), 44);
1086 B2 = ROL64((A42^D2), 43);
1087 B3 = ROL64((A13^D3), 21);
1088 B4 = ROL64((A34^D4), 14);
1089 A00 = B0 ^((~B1)& B2 );
1090 A00 ^= RC[i+2];
1091 A21 = B1 ^((~B2)& B3 );
1092 A42 = B2 ^((~B3)& B4 );
1093 A13 = B3 ^((~B4)& B0 );
1094 A34 = B4 ^((~B0)& B1 );
1095
1096 B2 = ROL64((A30^D0), 3);
1097 B3 = ROL64((A01^D1), 45);
1098 B4 = ROL64((A22^D2), 61);
1099 B0 = ROL64((A43^D3), 28);
1100 B1 = ROL64((A14^D4), 20);
1101 A30 = B0 ^((~B1)& B2 );
1102 A01 = B1 ^((~B2)& B3 );
1103 A22 = B2 ^((~B3)& B4 );
1104 A43 = B3 ^((~B4)& B0 );
1105 A14 = B4 ^((~B0)& B1 );
1106
1107 B4 = ROL64((A10^D0), 18);
1108 B0 = ROL64((A31^D1), 1);
1109 B1 = ROL64((A02^D2), 6);
1110 B2 = ROL64((A23^D3), 25);
1111 B3 = ROL64((A44^D4), 8);
1112 A10 = B0 ^((~B1)& B2 );
1113 A31 = B1 ^((~B2)& B3 );
1114 A02 = B2 ^((~B3)& B4 );
1115 A23 = B3 ^((~B4)& B0 );
1116 A44 = B4 ^((~B0)& B1 );
1117
1118 B1 = ROL64((A40^D0), 36);
1119 B2 = ROL64((A11^D1), 10);
1120 B3 = ROL64((A32^D2), 15);
1121 B4 = ROL64((A03^D3), 56);
1122 B0 = ROL64((A24^D4), 27);
1123 A40 = B0 ^((~B1)& B2 );
1124 A11 = B1 ^((~B2)& B3 );
1125 A32 = B2 ^((~B3)& B4 );
1126 A03 = B3 ^((~B4)& B0 );
1127 A24 = B4 ^((~B0)& B1 );
1128
1129 B3 = ROL64((A20^D0), 41);
1130 B4 = ROL64((A41^D1), 2);
1131 B0 = ROL64((A12^D2), 62);
1132 B1 = ROL64((A33^D3), 55);
1133 B2 = ROL64((A04^D4), 39);
1134 A20 = B0 ^((~B1)& B2 );
1135 A41 = B1 ^((~B2)& B3 );
1136 A12 = B2 ^((~B3)& B4 );
1137 A33 = B3 ^((~B4)& B0 );
1138 A04 = B4 ^((~B0)& B1 );
1139
1140 C0 = A00^A30^A10^A40^A20;
1141 C1 = A21^A01^A31^A11^A41;
1142 C2 = A42^A22^A02^A32^A12;
1143 C3 = A13^A43^A23^A03^A33;
1144 C4 = A34^A14^A44^A24^A04;
1145 D0 = C4^ROL64(C1, 1);
1146 D1 = C0^ROL64(C2, 1);
1147 D2 = C1^ROL64(C3, 1);
1148 D3 = C2^ROL64(C4, 1);
1149 D4 = C3^ROL64(C0, 1);
1150
1151 B0 = (A00^D0);
1152 B1 = ROL64((A01^D1), 44);
1153 B2 = ROL64((A02^D2), 43);
1154 B3 = ROL64((A03^D3), 21);
1155 B4 = ROL64((A04^D4), 14);
1156 A00 = B0 ^((~B1)& B2 );
1157 A00 ^= RC[i+3];
1158 A01 = B1 ^((~B2)& B3 );
1159 A02 = B2 ^((~B3)& B4 );
1160 A03 = B3 ^((~B4)& B0 );
1161 A04 = B4 ^((~B0)& B1 );
1162
1163 B2 = ROL64((A10^D0), 3);
1164 B3 = ROL64((A11^D1), 45);
1165 B4 = ROL64((A12^D2), 61);
1166 B0 = ROL64((A13^D3), 28);
1167 B1 = ROL64((A14^D4), 20);
1168 A10 = B0 ^((~B1)& B2 );
1169 A11 = B1 ^((~B2)& B3 );
1170 A12 = B2 ^((~B3)& B4 );
1171 A13 = B3 ^((~B4)& B0 );
1172 A14 = B4 ^((~B0)& B1 );
1173
1174 B4 = ROL64((A20^D0), 18);
1175 B0 = ROL64((A21^D1), 1);
1176 B1 = ROL64((A22^D2), 6);
1177 B2 = ROL64((A23^D3), 25);
1178 B3 = ROL64((A24^D4), 8);
1179 A20 = B0 ^((~B1)& B2 );
1180 A21 = B1 ^((~B2)& B3 );
1181 A22 = B2 ^((~B3)& B4 );
1182 A23 = B3 ^((~B4)& B0 );
1183 A24 = B4 ^((~B0)& B1 );
1184
1185 B1 = ROL64((A30^D0), 36);
1186 B2 = ROL64((A31^D1), 10);
1187 B3 = ROL64((A32^D2), 15);
1188 B4 = ROL64((A33^D3), 56);
1189 B0 = ROL64((A34^D4), 27);
1190 A30 = B0 ^((~B1)& B2 );
1191 A31 = B1 ^((~B2)& B3 );
1192 A32 = B2 ^((~B3)& B4 );
1193 A33 = B3 ^((~B4)& B0 );
1194 A34 = B4 ^((~B0)& B1 );
1195
1196 B3 = ROL64((A40^D0), 41);
1197 B4 = ROL64((A41^D1), 2);
1198 B0 = ROL64((A42^D2), 62);
1199 B1 = ROL64((A43^D3), 55);
1200 B2 = ROL64((A44^D4), 39);
1201 A40 = B0 ^((~B1)& B2 );
1202 A41 = B1 ^((~B2)& B3 );
1203 A42 = B2 ^((~B3)& B4 );
1204 A43 = B3 ^((~B4)& B0 );
1205 A44 = B4 ^((~B0)& B1 );
1206 }
1207 }
1208
1209 /*
1210 ** Initialize a new hash. iSize determines the size of the hash
@@ -1539,14 +1831,123 @@
1539 ** May you share freely, never taking more than you give.
1540 **
1541 ******************************************************************************
1542 **
1543 ** This SQLite extension implements SQL functions readfile() and
1544 ** writefile().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1545 */
1546 SQLITE_EXTENSION_INIT1
1547 #include <stdio.h>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1548
1549 /*
1550 ** Implementation of the "readfile(X)" SQL function. The entire content
1551 ** of the file named X is read and returned as a BLOB. NULL is returned
1552 ** if the file does not exist or is unreadable.
@@ -1555,62 +1956,611 @@
1555 sqlite3_context *context,
1556 int argc,
1557 sqlite3_value **argv
1558 ){
1559 const char *zName;
1560 FILE *in;
1561 long nIn;
1562 void *pBuf;
1563
1564 (void)(argc); /* Unused parameter */
1565 zName = (const char*)sqlite3_value_text(argv[0]);
1566 if( zName==0 ) return;
1567 in = fopen(zName, "rb");
1568 if( in==0 ) return;
1569 fseek(in, 0, SEEK_END);
1570 nIn = ftell(in);
1571 rewind(in);
1572 pBuf = sqlite3_malloc( nIn );
1573 if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1574 sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1575 }else{
1576 sqlite3_free(pBuf);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1577 }
1578 fclose(in);
 
1579 }
1580
1581 /*
1582 ** Implementation of the "writefile(X,Y)" SQL function. The argument Y
1583 ** is written into file X. The number of bytes written is returned. Or
1584 ** NULL is returned if something goes wrong, such as being unable to open
1585 ** file X for writing.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1586 */
1587 static void writefileFunc(
1588 sqlite3_context *context,
1589 int argc,
1590 sqlite3_value **argv
1591 ){
1592 FILE *out;
1593 const char *z;
1594 sqlite3_int64 rc;
1595 const char *zFile;
 
 
 
1596
1597 (void)(argc); /* Unused parameter */
 
 
 
 
 
 
1598 zFile = (const char*)sqlite3_value_text(argv[0]);
1599 if( zFile==0 ) return;
1600 out = fopen(zFile, "wb");
1601 if( out==0 ) return;
1602 z = (const char*)sqlite3_value_blob(argv[1]);
1603 if( z==0 ){
1604 rc = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1605 }else{
1606 rc = fwrite(z, 1, sqlite3_value_bytes(argv[1]), out);
 
 
 
 
 
 
 
 
 
 
1607 }
1608 fclose(out);
1609 sqlite3_result_int64(context, rc);
1610 }
1611
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1612
1613 #ifdef _WIN32
1614
1615 #endif
1616 int sqlite3_fileio_init(
@@ -1622,13 +2572,16 @@
1622 SQLITE_EXTENSION_INIT2(pApi);
1623 (void)pzErrMsg; /* Unused parameter */
1624 rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
1625 readfileFunc, 0, 0);
1626 if( rc==SQLITE_OK ){
1627 rc = sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
1628 writefileFunc, 0, 0);
1629 }
 
 
 
1630 return rc;
1631 }
1632
1633 /************************* End ../ext/misc/fileio.c ********************/
1634 /************************* Begin ../ext/misc/completion.c ******************/
@@ -2154,10 +3107,4226 @@
2154 #endif
2155 return rc;
2156 }
2157
2158 /************************* End ../ext/misc/completion.c ********************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2159
2160 #if defined(SQLITE_ENABLE_SESSION)
2161 /*
2162 ** State information for a single open session
2163 */
@@ -2180,21 +7349,28 @@
2180 int mode; /* Mode prior to ".explain on" */
2181 int showHeader; /* The ".header" setting prior to ".explain on" */
2182 int colWidth[100]; /* Column widths prior to ".explain on" */
2183 };
2184
 
 
 
 
 
 
2185 /*
2186 ** State information about the database connection is contained in an
2187 ** instance of the following structure.
2188 */
2189 typedef struct ShellState ShellState;
2190 struct ShellState {
2191 sqlite3 *db; /* The database */
2192 int autoExplain; /* Automatically turn on .explain mode */
2193 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
2194 int statsOn; /* True to display memory stats before each finalize */
2195 int scanstatsOn; /* True to display scan stats before each finalize */
 
2196 int outCount; /* Revert to stdout when reaching zero */
2197 int cnt; /* Number of records displayed so far */
2198 FILE *out; /* Write results here */
2199 FILE *traceOut; /* Output for sqlite3_trace() */
2200 int nErr; /* Number of errors seen */
@@ -2224,12 +7400,28 @@
2224 int iIndent; /* Index of current op in aiIndent[] */
2225 #if defined(SQLITE_ENABLE_SESSION)
2226 int nSession; /* Number of active sessions */
2227 OpenSession aSession[4]; /* Array of sessions. [0] is in focus. */
2228 #endif
 
2229 };
2230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2231 /*
2232 ** These are the allowed shellFlgs values
2233 */
2234 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
2235 #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
@@ -2652,10 +7844,26 @@
2652 z[n] = 0;
2653 printSchemaLine(out, z, zTail);
2654 z[n] = c;
2655 }
2656
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2657 /*
2658 ** This is the callback routine that the shell
2659 ** invokes for each row of a query result.
2660 */
2661 static int shell_callback(
@@ -2791,17 +7999,19 @@
2791 z[j++] = c;
2792 }
2793 while( j>0 && IsSpace(z[j-1]) ){ j--; }
2794 z[j] = 0;
2795 if( strlen30(z)>=79 ){
2796 for(i=j=0; (c = z[i])!=0; i++){
2797 if( c==cEnd ){
2798 cEnd = 0;
2799 }else if( c=='"' || c=='\'' || c=='`' ){
2800 cEnd = c;
2801 }else if( c=='[' ){
2802 cEnd = ']';
 
 
2803 }else if( c=='(' ){
2804 nParen++;
2805 }else if( c==')' ){
2806 nParen--;
2807 if( nLine>0 && nParen==0 && j>0 ){
@@ -2808,11 +8018,13 @@
2808 printSchemaLineN(p->out, z, j, "\n");
2809 j = 0;
2810 }
2811 }
2812 z[j++] = c;
2813 if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
 
 
2814 if( c=='\n' ) j--;
2815 printSchemaLineN(p->out, z, j, "\n ");
2816 j = 0;
2817 nLine++;
2818 while( IsSpace(z[i+1]) ){ i++; }
@@ -3206,11 +8418,11 @@
3206 { "write_bytes: ", "Bytes written to storage:" },
3207 { "cancelled_write_bytes: ", "Cancelled write bytes:" },
3208 };
3209 int i;
3210 for(i=0; i<ArraySize(aTrans); i++){
3211 int n = (int)strlen(aTrans[i].zPattern);
3212 if( strncmp(aTrans[i].zPattern, z, n)==0 ){
3213 utf8_printf(out, "%-36s %s", aTrans[i].zDesc, &z[n]);
3214 break;
3215 }
3216 }
@@ -3606,10 +8818,83 @@
3606 rc = sqlite3_step(pStmt);
3607 } while( rc == SQLITE_ROW );
3608 }
3609 }
3610 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3611
3612 /*
3613 ** Execute a statement or set of statements. Print
3614 ** any result rows/columns depending on the current mode
3615 ** set via the supplied callback.
@@ -3632,10 +8917,15 @@
3632 const char *zLeftover; /* Tail of unprocessed SQL */
3633
3634 if( pzErrMsg ){
3635 *pzErrMsg = NULL;
3636 }
 
 
 
 
 
3637
3638 while( zSql[0] && (SQLITE_OK == rc) ){
3639 static const char *zStmtSql;
3640 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
3641 if( SQLITE_OK != rc ){
@@ -3666,11 +8956,16 @@
3666
3667 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
3668 if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
3669 sqlite3_stmt *pExplain;
3670 char *zEQP;
 
3671 disable_debug_trace_modes();
 
 
 
 
3672 zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
3673 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
3674 if( rc==SQLITE_OK ){
3675 while( sqlite3_step(pExplain)==SQLITE_ROW ){
3676 raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
@@ -3679,11 +8974,11 @@
3679 utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
3680 }
3681 }
3682 sqlite3_finalize(pExplain);
3683 sqlite3_free(zEQP);
3684 if( pArg->autoEQP>=2 ){
3685 /* Also do an EXPLAIN for ".eqp full" mode */
3686 zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql);
3687 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
3688 if( rc==SQLITE_OK ){
3689 pArg->cMode = MODE_Explain;
@@ -3692,10 +8987,11 @@
3692 explain_data_delete(pArg);
3693 }
3694 sqlite3_finalize(pExplain);
3695 sqlite3_free(zEQP);
3696 }
 
3697 restore_debug_trace_modes();
3698 }
3699
3700 if( pArg ){
3701 pArg->cMode = pArg->mode;
@@ -4032,10 +9328,13 @@
4032
4033 /*
4034 ** Text of a help message
4035 */
4036 static char zHelp[] =
 
 
 
4037 #ifndef SQLITE_OMIT_AUTHORIZATION
4038 ".auth ON|OFF Show authorizer callbacks\n"
4039 #endif
4040 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
4041 ".bail on|off Stop after hitting an error. Default OFF\n"
@@ -4050,10 +9349,11 @@
4050 " If TABLE specified, only dump tables matching\n"
4051 " LIKE pattern TABLE.\n"
4052 ".echo on|off Turn command echo on or off\n"
4053 ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
4054 ".exit Exit this program\n"
 
4055 /* Because explain mode comes on automatically now, the ".explain" mode
4056 ** is removed from the help screen. It is still supported for legacy, however */
4057 /*".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"*/
4058 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
4059 ".headers on|off Turn display of headers on or off\n"
@@ -4233,19 +9533,63 @@
4233 if( sqlite3_strglob(pSession->azFilter[i], zTab)==0 ) return 0;
4234 }
4235 return 1;
4236 }
4237 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4238
4239 /*
4240 ** Make sure the database is open. If it is not, then open it. If
4241 ** the database fails to open, print an error message and exit.
4242 */
4243 static void open_db(ShellState *p, int keepAlive){
4244 if( p->db==0 ){
4245 sqlite3_initialize();
4246 sqlite3_open(p->zDbFilename, &p->db);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4247 globalDb = p->db;
4248 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
4249 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
4250 p->zDbFilename, sqlite3_errmsg(p->db));
4251 if( keepAlive ) return;
@@ -4255,12 +9599,24 @@
4255 sqlite3_enable_load_extension(p->db, 1);
4256 #endif
4257 sqlite3_fileio_init(p->db, 0, 0);
4258 sqlite3_shathree_init(p->db, 0, 0);
4259 sqlite3_completion_init(p->db, 0, 0);
4260 sqlite3_create_function(p->db, "shell_add_schema", 2, SQLITE_UTF8, 0,
 
 
 
 
4261 shellAddSchemaName, 0, 0);
 
 
 
 
 
 
 
 
4262 }
4263 }
4264
4265 #if HAVE_READLINE || HAVE_EDITLINE
4266 /*
@@ -4294,11 +9650,11 @@
4294 #elif HAVE_LINENOISE
4295 /*
4296 ** Linenoise completion callback
4297 */
4298 static void linenoise_completion(const char *zLine, linenoiseCompletions *lc){
4299 int nLine = (int)strlen(zLine);
4300 int i, iStart;
4301 sqlite3_stmt *pStmt = 0;
4302 char *zSql;
4303 char zBuf[1000];
4304
@@ -4520,11 +9876,11 @@
4520 FILE *f = (FILE*)pArg;
4521 UNUSED_PARAMETER(mType);
4522 UNUSED_PARAMETER(pP);
4523 if( f ){
4524 const char *z = (const char*)pX;
4525 int i = (int)strlen(z);
4526 while( i>0 && z[i-1]==';' ){ i--; }
4527 utf8_printf(f, "%.*s;\n", i, z);
4528 }
4529 return 0;
4530 }
@@ -4709,11 +10065,11 @@
4709 sqlite3_stmt *pInsert = 0;
4710 char *zQuery = 0;
4711 char *zInsert = 0;
4712 int rc;
4713 int i, j, n;
4714 int nTable = (int)strlen(zTable);
4715 int k = 0;
4716 int cnt = 0;
4717 const int spinRate = 10000;
4718
4719 zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
@@ -4730,11 +10086,11 @@
4730 raw_printf(stderr, "out of memory\n");
4731 goto end_data_xfer;
4732 }
4733 sqlite3_snprintf(200+nTable,zInsert,
4734 "INSERT OR IGNORE INTO \"%s\" VALUES(?", zTable);
4735 i = (int)strlen(zInsert);
4736 for(j=1; j<n; j++){
4737 memcpy(zInsert+i, ",?", 2);
4738 i += 2;
4739 }
4740 memcpy(zInsert+i, ");", 3);
@@ -5312,11 +10668,11 @@
5312 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
5313 ;
5314 const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
5315
5316 for(i=2; i<nArg; i++){
5317 int n = (int)strlen(azArg[i]);
5318 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
5319 bVerbose = 1;
5320 }
5321 else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){
5322 bGroupByParent = 1;
@@ -5415,20 +10771,822 @@
5415 ShellState *pState, /* Current shell tool state */
5416 char **azArg, /* Array of arguments passed to dot command */
5417 int nArg /* Number of entries in azArg[] */
5418 ){
5419 int n;
5420 n = (nArg>=2 ? (int)strlen(azArg[1]) : 0);
5421 if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage;
5422 return lintFkeyIndexes(pState, azArg, nArg);
5423
5424 usage:
5425 raw_printf(stderr, "Usage %s sub-command ?switches...?\n", azArg[0]);
5426 raw_printf(stderr, "Where sub-commands are:\n");
5427 raw_printf(stderr, " fkey-indexes\n");
5428 return SQLITE_ERROR;
5429 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5430
5431
5432 /*
5433 ** If an input line begins with "." then invoke this routine to
5434 ** process that line.
@@ -5439,10 +11597,14 @@
5439 int h = 1;
5440 int nArg = 0;
5441 int n, c;
5442 int rc = 0;
5443 char *azArg[50];
 
 
 
 
5444
5445 /* Parse the input line into tokens.
5446 */
5447 while( zLine[h] && nArg<ArraySize(azArg) ){
5448 while( IsSpace(zLine[h]) ){ h++; }
@@ -5485,10 +11647,17 @@
5485 }else{
5486 sqlite3_set_authorizer(p->db, 0, 0);
5487 }
5488 }else
5489 #endif
 
 
 
 
 
 
 
5490
5491 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
5492 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
5493 ){
5494 const char *zDestFile = 0;
@@ -5755,16 +11924,18 @@
5755 }else
5756
5757 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
5758 if( nArg==2 ){
5759 if( strcmp(azArg[1],"full")==0 ){
5760 p->autoEQP = 2;
 
 
5761 }else{
5762 p->autoEQP = booleanValue(azArg[1]);
5763 }
5764 }else{
5765 raw_printf(stderr, "Usage: .eqp on|off|full\n");
5766 rc = 1;
5767 }
5768 }else
5769
5770 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -5793,10 +11964,15 @@
5793 }else if( val==99 ){
5794 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
5795 p->autoExplain = 1;
5796 }
5797 }else
 
 
 
 
 
5798
5799 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
5800 ShellState data;
5801 char *zErrMsg = 0;
5802 int doStats = 0;
@@ -6254,11 +12430,11 @@
6254 }
6255 }else
6256
6257 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
6258 const char *zMode = nArg>=2 ? azArg[1] : "";
6259 int n2 = (int)strlen(zMode);
6260 int c2 = zMode[0];
6261 if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
6262 p->mode = MODE_Line;
6263 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
6264 }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
@@ -6319,15 +12495,22 @@
6319 sqlite3_close(p->db);
6320 p->db = 0;
6321 p->zDbFilename = 0;
6322 sqlite3_free(p->zFreeOnClose);
6323 p->zFreeOnClose = 0;
 
6324 /* Check for command-line arguments */
6325 for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
6326 const char *z = azArg[iName];
6327 if( optionMatch(z,"new") ){
6328 newFlag = 1;
 
 
 
 
 
 
6329 }else if( z[0]=='-' ){
6330 utf8_printf(stderr, "unknown option: %s\n", z);
6331 rc = 1;
6332 goto meta_command_exit;
6333 }
@@ -6506,63 +12689,52 @@
6506
6507 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
6508 ShellText sSelect;
6509 ShellState data;
6510 char *zErrMsg = 0;
6511 const char *zDiv = 0;
 
6512 int iSchema = 0;
 
 
6513
6514 open_db(p, 0);
6515 memcpy(&data, p, sizeof(data));
6516 data.showHeader = 0;
6517 data.cMode = data.mode = MODE_Semi;
6518 initText(&sSelect);
6519 if( nArg>=2 && optionMatch(azArg[1], "indent") ){
6520 data.cMode = data.mode = MODE_Pretty;
6521 nArg--;
6522 if( nArg==2 ) azArg[1] = azArg[2];
6523 }
6524 if( nArg==2 && azArg[1][0]!='-' ){
6525 int i;
6526 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
6527 if( strcmp(azArg[1],"sqlite_master")==0 ){
6528 char *new_argv[2], *new_colv[2];
6529 new_argv[0] = "CREATE TABLE sqlite_master (\n"
6530 " type text,\n"
6531 " name text,\n"
6532 " tbl_name text,\n"
6533 " rootpage integer,\n"
6534 " sql text\n"
6535 ")";
6536 new_argv[1] = 0;
6537 new_colv[0] = "sql";
6538 new_colv[1] = 0;
6539 callback(&data, 1, new_argv, new_colv);
6540 rc = SQLITE_OK;
6541 }else if( strcmp(azArg[1],"sqlite_temp_master")==0 ){
6542 char *new_argv[2], *new_colv[2];
6543 new_argv[0] = "CREATE TEMP TABLE sqlite_temp_master (\n"
6544 " type text,\n"
6545 " name text,\n"
6546 " tbl_name text,\n"
6547 " rootpage integer,\n"
6548 " sql text\n"
6549 ")";
6550 new_argv[1] = 0;
6551 new_colv[0] = "sql";
6552 new_colv[1] = 0;
6553 callback(&data, 1, new_argv, new_colv);
6554 rc = SQLITE_OK;
6555 }else{
6556 zDiv = "(";
6557 }
6558 }else if( nArg==1 ){
6559 zDiv = "(";
6560 }else{
6561 raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
6562 rc = 1;
6563 goto meta_command_exit;
6564 }
6565 if( zDiv ){
6566 sqlite3_stmt *pStmt = 0;
6567 rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list",
6568 -1, &pStmt, 0);
@@ -6578,43 +12750,52 @@
6578 const char *zDb = (const char*)sqlite3_column_text(pStmt, 0);
6579 char zScNum[30];
6580 sqlite3_snprintf(sizeof(zScNum), zScNum, "%d", ++iSchema);
6581 appendText(&sSelect, zDiv, 0);
6582 zDiv = " UNION ALL ";
6583 if( strcmp(zDb, "main")!=0 ){
6584 appendText(&sSelect, "SELECT shell_add_schema(sql,", 0);
6585 appendText(&sSelect, zDb, '"');
6586 appendText(&sSelect, ") AS sql, type, tbl_name, name, rowid,", 0);
6587 appendText(&sSelect, zScNum, 0);
6588 appendText(&sSelect, " AS snum, ", 0);
6589 appendText(&sSelect, zDb, '\'');
6590 appendText(&sSelect, " AS sname FROM ", 0);
6591 appendText(&sSelect, zDb, '"');
6592 appendText(&sSelect, ".sqlite_master", 0);
6593 }else{
6594 appendText(&sSelect, "SELECT sql, type, tbl_name, name, rowid, ", 0);
6595 appendText(&sSelect, zScNum, 0);
6596 appendText(&sSelect, " AS snum, 'main' AS sname FROM sqlite_master",0);
6597 }
6598 }
6599 sqlite3_finalize(pStmt);
 
 
 
 
 
 
 
6600 appendText(&sSelect, ") WHERE ", 0);
6601 if( nArg>1 ){
6602 char *zQarg = sqlite3_mprintf("%Q", azArg[1]);
6603 if( strchr(azArg[1], '.') ){
6604 appendText(&sSelect, "lower(printf('%s.%s',sname,tbl_name))", 0);
6605 }else{
6606 appendText(&sSelect, "lower(tbl_name)", 0);
6607 }
6608 appendText(&sSelect, strchr(azArg[1], '*') ? " GLOB " : " LIKE ", 0);
6609 appendText(&sSelect, zQarg, 0);
6610 appendText(&sSelect, " AND ", 0);
6611 sqlite3_free(zQarg);
6612 }
6613 appendText(&sSelect, "type!='meta' AND sql IS NOT NULL"
6614 " ORDER BY snum, rowid", 0);
6615 rc = sqlite3_exec(p->db, sSelect.z, callback, &data, &zErrMsg);
 
 
 
 
6616 freeText(&sSelect);
6617 }
6618 if( zErrMsg ){
6619 utf8_printf(stderr,"Error: %s\n", zErrMsg);
6620 sqlite3_free(zErrMsg);
@@ -7108,11 +13289,11 @@
7108 sqlite3_free(zCmd);
7109 if( x ) raw_printf(stderr, "System command returns %d\n", x);
7110 }else
7111
7112 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
7113 static const char *azBool[] = { "off", "on", "full", "unk" };
7114 int i;
7115 if( nArg!=1 ){
7116 raw_printf(stderr, "Usage: .show\n");
7117 rc = 1;
7118 goto meta_command_exit;
@@ -7296,10 +13477,13 @@
7296 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD, "IDENTIFIER" },
7297 #endif
7298 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
7299 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
7300 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
 
 
 
7301 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
7302 { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET, "" },
7303 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
7304 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
7305 { "reserve", SQLITE_TESTCTRL_RESERVE, "BYTES-OF-RESERVE" },
@@ -7421,10 +13605,18 @@
7421 integerValue(azArg[3]),
7422 integerValue(azArg[4]));
7423 isOk = 3;
7424 }
7425 break;
 
 
 
 
 
 
 
 
7426 }
7427 }
7428 if( isOk==0 && iCtrl>=0 ){
7429 utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd, aCtrl[iCtrl].zUsage);
7430 rc = 1;
@@ -7484,12 +13676,11 @@
7484 if( nArg!=4 ){
7485 raw_printf(stderr, "Usage: .user login USER PASSWORD\n");
7486 rc = 1;
7487 goto meta_command_exit;
7488 }
7489 rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3],
7490 (int)strlen(azArg[3]));
7491 if( rc ){
7492 utf8_printf(stderr, "Authentication failed for user %s\n", azArg[2]);
7493 rc = 1;
7494 }
7495 }else if( strcmp(azArg[1],"add")==0 ){
@@ -7496,12 +13687,11 @@
7496 if( nArg!=5 ){
7497 raw_printf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
7498 rc = 1;
7499 goto meta_command_exit;
7500 }
7501 rc = sqlite3_user_add(p->db, azArg[2],
7502 azArg[3], (int)strlen(azArg[3]),
7503 booleanValue(azArg[4]));
7504 if( rc ){
7505 raw_printf(stderr, "User-Add failed: %d\n", rc);
7506 rc = 1;
7507 }
@@ -7509,12 +13699,11 @@
7509 if( nArg!=5 ){
7510 raw_printf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
7511 rc = 1;
7512 goto meta_command_exit;
7513 }
7514 rc = sqlite3_user_change(p->db, azArg[2],
7515 azArg[3], (int)strlen(azArg[3]),
7516 booleanValue(azArg[4]));
7517 if( rc ){
7518 raw_printf(stderr, "User-Edit failed: %d\n", rc);
7519 rc = 1;
7520 }
@@ -8186,10 +14375,16 @@
8186 sqlite3_vfs_register(pVfs, 1);
8187 }else{
8188 utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
8189 exit(1);
8190 }
 
 
 
 
 
 
8191 }
8192 }
8193 if( data.zDbFilename==0 ){
8194 #ifndef SQLITE_OMIT_MEMORYDB
8195 data.zDbFilename = ":memory:";
@@ -8198,10 +14393,11 @@
8198 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
8199 return 1;
8200 #endif
8201 }
8202 data.out = stdout;
 
8203
8204 /* Go ahead and open the database file if it already exists. If the
8205 ** file does not exist, delay opening it. This prevents empty database
8206 ** files from being created if a user mistypes the database name argument
8207 ** to the sqlite command-line tool.
@@ -8238,10 +14434,16 @@
8238 }else if( strcmp(z,"-column")==0 ){
8239 data.mode = MODE_Column;
8240 }else if( strcmp(z,"-csv")==0 ){
8241 data.mode = MODE_Csv;
8242 memcpy(data.colSeparator,",",2);
 
 
 
 
 
 
8243 }else if( strcmp(z,"-ascii")==0 ){
8244 data.mode = MODE_Ascii;
8245 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
8246 SEP_Unit);
8247 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
@@ -8260,13 +14462,13 @@
8260 }else if( strcmp(z,"-noheader")==0 ){
8261 data.showHeader = 0;
8262 }else if( strcmp(z,"-echo")==0 ){
8263 ShellSetFlag(&data, SHFLG_Echo);
8264 }else if( strcmp(z,"-eqp")==0 ){
8265 data.autoEQP = 1;
8266 }else if( strcmp(z,"-eqpfull")==0 ){
8267 data.autoEQP = 2;
8268 }else if( strcmp(z,"-stats")==0 ){
8269 data.statsOn = 1;
8270 }else if( strcmp(z,"-scanstats")==0 ){
8271 data.scanstatsOn = 1;
8272 }else if( strcmp(z,"-backslash")==0 ){
8273
--- src/shell.c
+++ src/shell.c
@@ -77,10 +77,13 @@
77 #include <stdlib.h>
78 #include <string.h>
79 #include <stdio.h>
80 #include <assert.h>
81 #include "sqlite3.h"
82 typedef sqlite3_int64 i64;
83 typedef sqlite3_uint64 u64;
84 typedef unsigned char u8;
85 #if SQLITE_USER_AUTHENTICATION
86 # include "sqlite3userauth.h"
87 #endif
88 #include <ctype.h>
89 #include <stdarg.h>
@@ -88,13 +91,23 @@
91 #if !defined(_WIN32) && !defined(WIN32)
92 # include <signal.h>
93 # if !defined(__RTP__) && !defined(_WRS_KERNEL)
94 # include <pwd.h>
95 # endif
96 #endif
97 #if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW_H)
98 # include <unistd.h>
99 # include <dirent.h>
100 # if defined(__MINGW_H)
101 # define DIRENT dirent
102 # ifndef S_ISLNK
103 # define S_ISLNK(mode) (0)
104 # endif
105 # endif
106 #endif
107 #include <sys/types.h>
108 #include <sys/stat.h>
109
110 #if HAVE_READLINE
111 # include <readline/readline.h>
112 # include <readline/history.h>
113 #endif
@@ -744,10 +757,75 @@
757 upr = mid-1;
758 }
759 }
760 return 0;
761 }
762
763 /*
764 ** Construct a fake object name and column list to describe the structure
765 ** of the view, virtual table, or table valued function zSchema.zName.
766 */
767 static char *shellFakeSchema(
768 sqlite3 *db, /* The database connection containing the vtab */
769 const char *zSchema, /* Schema of the database holding the vtab */
770 const char *zName /* The name of the virtual table */
771 ){
772 sqlite3_stmt *pStmt = 0;
773 char *zSql;
774 ShellText s;
775 char cQuote;
776 char *zDiv = "(";
777 int nRow = 0;
778
779 zSql = sqlite3_mprintf("PRAGMA \"%w\".table_info=%Q;",
780 zSchema ? zSchema : "main", zName);
781 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
782 sqlite3_free(zSql);
783 initText(&s);
784 if( zSchema ){
785 cQuote = quoteChar(zSchema);
786 if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0;
787 appendText(&s, zSchema, cQuote);
788 appendText(&s, ".", 0);
789 }
790 cQuote = quoteChar(zName);
791 appendText(&s, zName, cQuote);
792 while( sqlite3_step(pStmt)==SQLITE_ROW ){
793 const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
794 nRow++;
795 appendText(&s, zDiv, 0);
796 zDiv = ",";
797 cQuote = quoteChar(zCol);
798 appendText(&s, zCol, cQuote);
799 }
800 appendText(&s, ")", 0);
801 sqlite3_finalize(pStmt);
802 if( nRow==0 ){
803 freeText(&s);
804 s.z = 0;
805 }
806 return s.z;
807 }
808
809 /*
810 ** SQL function: shell_module_schema(X)
811 **
812 ** Return a fake schema for the table-valued function or eponymous virtual
813 ** table X.
814 */
815 static void shellModuleSchema(
816 sqlite3_context *pCtx,
817 int nVal,
818 sqlite3_value **apVal
819 ){
820 const char *zName = (const char*)sqlite3_value_text(apVal[0]);
821 char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
822 if( zFake ){
823 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %z */", zFake),
824 -1, sqlite3_free);
825 }
826 }
827
828 /*
829 ** SQL function: shell_add_schema(S,X)
830 **
831 ** Add the schema name X to the CREATE statement in S and return the result.
@@ -780,24 +858,40 @@
858 "VIRTUAL TABLE"
859 };
860 int i = 0;
861 const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
862 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
863 const char *zName = (const char*)sqlite3_value_text(apVal[2]);
864 sqlite3 *db = sqlite3_context_db_handle(pCtx);
865 if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
866 for(i=0; i<(int)(sizeof(aPrefix)/sizeof(aPrefix[0])); i++){
867 int n = strlen30(aPrefix[i]);
868 if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
869 char *z = 0;
870 char *zFake = 0;
871 if( zSchema ){
872 char cQuote = quoteChar(zSchema);
873 if( cQuote && sqlite3_stricmp(zSchema,"temp")!=0 ){
874 z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
875 }else{
876 z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
877 }
878 }
879 if( zName
880 && aPrefix[i][0]=='V'
881 && (zFake = shellFakeSchema(db, zSchema, zName))!=0
882 ){
883 if( z==0 ){
884 z = sqlite3_mprintf("%s\n/* %z */", zIn, zFake);
885 }else{
886 z = sqlite3_mprintf("%z\n/* %z */", z, zFake);
887 }
888 }
889 if( z ){
890 sqlite3_result_text(pCtx, z, -1, sqlite3_free);
891 return;
892 }
893 }
894 }
895 }
896 sqlite3_result_value(pCtx, apVal[0]);
897 }
@@ -809,10 +903,208 @@
903 ** work here in the middle of this regular program.
904 */
905 #define SQLITE_EXTENSION_INIT1
906 #define SQLITE_EXTENSION_INIT2(X) (void)(X)
907
908 #if defined(_WIN32) && defined(_MSC_VER)
909 /************************* Begin test_windirent.c ******************/
910 /*
911 ** 2015 November 30
912 **
913 ** The author disclaims copyright to this source code. In place of
914 ** a legal notice, here is a blessing:
915 **
916 ** May you do good and not evil.
917 ** May you find forgiveness for yourself and forgive others.
918 ** May you share freely, never taking more than you give.
919 **
920 *************************************************************************
921 ** This file contains code to implement most of the opendir() family of
922 ** POSIX functions on Win32 using the MSVCRT.
923 */
924
925 #if defined(_WIN32) && defined(_MSC_VER)
926
927 #include "test_windirent.h"
928
929 /*
930 ** Implementation of the POSIX getenv() function using the Win32 API.
931 ** This function is not thread-safe.
932 */
933 const char *windirent_getenv(
934 const char *name
935 ){
936 static char value[32768]; /* Maximum length, per MSDN */
937 DWORD dwSize = sizeof(value) / sizeof(char); /* Size in chars */
938 DWORD dwRet; /* Value returned by GetEnvironmentVariableA() */
939
940 memset(value, 0, sizeof(value));
941 dwRet = GetEnvironmentVariableA(name, value, dwSize);
942 if( dwRet==0 || dwRet>dwSize ){
943 /*
944 ** The function call to GetEnvironmentVariableA() failed -OR-
945 ** the buffer is not large enough. Either way, return NULL.
946 */
947 return 0;
948 }else{
949 /*
950 ** The function call to GetEnvironmentVariableA() succeeded
951 ** -AND- the buffer contains the entire value.
952 */
953 return value;
954 }
955 }
956
957 /*
958 ** Implementation of the POSIX opendir() function using the MSVCRT.
959 */
960 LPDIR opendir(
961 const char *dirname
962 ){
963 struct _finddata_t data;
964 LPDIR dirp = (LPDIR)sqlite3_malloc(sizeof(DIR));
965 SIZE_T namesize = sizeof(data.name) / sizeof(data.name[0]);
966
967 if( dirp==NULL ) return NULL;
968 memset(dirp, 0, sizeof(DIR));
969
970 /* TODO: Remove this if Unix-style root paths are not used. */
971 if( sqlite3_stricmp(dirname, "/")==0 ){
972 dirname = windirent_getenv("SystemDrive");
973 }
974
975 memset(&data, 0, sizeof(struct _finddata_t));
976 _snprintf(data.name, namesize, "%s\\*", dirname);
977 dirp->d_handle = _findfirst(data.name, &data);
978
979 if( dirp->d_handle==BAD_INTPTR_T ){
980 closedir(dirp);
981 return NULL;
982 }
983
984 /* TODO: Remove this block to allow hidden and/or system files. */
985 if( is_filtered(data) ){
986 next:
987
988 memset(&data, 0, sizeof(struct _finddata_t));
989 if( _findnext(dirp->d_handle, &data)==-1 ){
990 closedir(dirp);
991 return NULL;
992 }
993
994 /* TODO: Remove this block to allow hidden and/or system files. */
995 if( is_filtered(data) ) goto next;
996 }
997
998 dirp->d_first.d_attributes = data.attrib;
999 strncpy(dirp->d_first.d_name, data.name, NAME_MAX);
1000 dirp->d_first.d_name[NAME_MAX] = '\0';
1001
1002 return dirp;
1003 }
1004
1005 /*
1006 ** Implementation of the POSIX readdir() function using the MSVCRT.
1007 */
1008 LPDIRENT readdir(
1009 LPDIR dirp
1010 ){
1011 struct _finddata_t data;
1012
1013 if( dirp==NULL ) return NULL;
1014
1015 if( dirp->d_first.d_ino==0 ){
1016 dirp->d_first.d_ino++;
1017 dirp->d_next.d_ino++;
1018
1019 return &dirp->d_first;
1020 }
1021
1022 next:
1023
1024 memset(&data, 0, sizeof(struct _finddata_t));
1025 if( _findnext(dirp->d_handle, &data)==-1 ) return NULL;
1026
1027 /* TODO: Remove this block to allow hidden and/or system files. */
1028 if( is_filtered(data) ) goto next;
1029
1030 dirp->d_next.d_ino++;
1031 dirp->d_next.d_attributes = data.attrib;
1032 strncpy(dirp->d_next.d_name, data.name, NAME_MAX);
1033 dirp->d_next.d_name[NAME_MAX] = '\0';
1034
1035 return &dirp->d_next;
1036 }
1037
1038 /*
1039 ** Implementation of the POSIX readdir_r() function using the MSVCRT.
1040 */
1041 INT readdir_r(
1042 LPDIR dirp,
1043 LPDIRENT entry,
1044 LPDIRENT *result
1045 ){
1046 struct _finddata_t data;
1047
1048 if( dirp==NULL ) return EBADF;
1049
1050 if( dirp->d_first.d_ino==0 ){
1051 dirp->d_first.d_ino++;
1052 dirp->d_next.d_ino++;
1053
1054 entry->d_ino = dirp->d_first.d_ino;
1055 entry->d_attributes = dirp->d_first.d_attributes;
1056 strncpy(entry->d_name, dirp->d_first.d_name, NAME_MAX);
1057 entry->d_name[NAME_MAX] = '\0';
1058
1059 *result = entry;
1060 return 0;
1061 }
1062
1063 next:
1064
1065 memset(&data, 0, sizeof(struct _finddata_t));
1066 if( _findnext(dirp->d_handle, &data)==-1 ){
1067 *result = NULL;
1068 return ENOENT;
1069 }
1070
1071 /* TODO: Remove this block to allow hidden and/or system files. */
1072 if( is_filtered(data) ) goto next;
1073
1074 entry->d_ino = (ino_t)-1; /* not available */
1075 entry->d_attributes = data.attrib;
1076 strncpy(entry->d_name, data.name, NAME_MAX);
1077 entry->d_name[NAME_MAX] = '\0';
1078
1079 *result = entry;
1080 return 0;
1081 }
1082
1083 /*
1084 ** Implementation of the POSIX closedir() function using the MSVCRT.
1085 */
1086 INT closedir(
1087 LPDIR dirp
1088 ){
1089 INT result = 0;
1090
1091 if( dirp==NULL ) return EINVAL;
1092
1093 if( dirp->d_handle!=NULL_INTPTR_T && dirp->d_handle!=BAD_INTPTR_T ){
1094 result = _findclose(dirp->d_handle);
1095 }
1096
1097 sqlite3_free(dirp);
1098 return result;
1099 }
1100
1101 #endif /* defined(WIN32) && defined(_MSC_VER) */
1102
1103 /************************* End test_windirent.c ********************/
1104 #define dirent DIRENT
1105 #endif
1106 /************************* Begin ../ext/misc/shathree.c ******************/
1107 /*
1108 ** 2017-03-08
1109 **
1110 ** The author disclaims copyright to this source code. In place of
@@ -842,11 +1134,11 @@
1134 */
1135 SQLITE_EXTENSION_INIT1
1136 #include <assert.h>
1137 #include <string.h>
1138 #include <stdarg.h>
1139 /* typedef sqlite3_uint64 u64; */
1140
1141 /******************************************************************************
1142 ** The Hash Engine
1143 */
1144 /*
@@ -889,13 +1181,13 @@
1181 /*
1182 ** A single step of the Keccak mixing function for a 1600-bit state
1183 */
1184 static void KeccakF1600Step(SHA3Context *p){
1185 int i;
1186 u64 b0, b1, b2, b3, b4;
1187 u64 c0, c1, c2, c3, c4;
1188 u64 d0, d1, d2, d3, d4;
1189 static const u64 RC[] = {
1190 0x0000000000000001ULL, 0x0000000000008082ULL,
1191 0x800000000000808aULL, 0x8000000080008000ULL,
1192 0x000000000000808bULL, 0x0000000080000001ULL,
1193 0x8000000080008081ULL, 0x8000000000008009ULL,
@@ -906,305 +1198,305 @@
1198 0x8000000000008002ULL, 0x8000000000000080ULL,
1199 0x000000000000800aULL, 0x800000008000000aULL,
1200 0x8000000080008081ULL, 0x8000000000008080ULL,
1201 0x0000000080000001ULL, 0x8000000080008008ULL
1202 };
1203 # define a00 (p->u.s[0])
1204 # define a01 (p->u.s[1])
1205 # define a02 (p->u.s[2])
1206 # define a03 (p->u.s[3])
1207 # define a04 (p->u.s[4])
1208 # define a10 (p->u.s[5])
1209 # define a11 (p->u.s[6])
1210 # define a12 (p->u.s[7])
1211 # define a13 (p->u.s[8])
1212 # define a14 (p->u.s[9])
1213 # define a20 (p->u.s[10])
1214 # define a21 (p->u.s[11])
1215 # define a22 (p->u.s[12])
1216 # define a23 (p->u.s[13])
1217 # define a24 (p->u.s[14])
1218 # define a30 (p->u.s[15])
1219 # define a31 (p->u.s[16])
1220 # define a32 (p->u.s[17])
1221 # define a33 (p->u.s[18])
1222 # define a34 (p->u.s[19])
1223 # define a40 (p->u.s[20])
1224 # define a41 (p->u.s[21])
1225 # define a42 (p->u.s[22])
1226 # define a43 (p->u.s[23])
1227 # define a44 (p->u.s[24])
1228 # define ROL64(a,x) ((a<<x)|(a>>(64-x)))
1229
1230 for(i=0; i<24; i+=4){
1231 c0 = a00^a10^a20^a30^a40;
1232 c1 = a01^a11^a21^a31^a41;
1233 c2 = a02^a12^a22^a32^a42;
1234 c3 = a03^a13^a23^a33^a43;
1235 c4 = a04^a14^a24^a34^a44;
1236 d0 = c4^ROL64(c1, 1);
1237 d1 = c0^ROL64(c2, 1);
1238 d2 = c1^ROL64(c3, 1);
1239 d3 = c2^ROL64(c4, 1);
1240 d4 = c3^ROL64(c0, 1);
1241
1242 b0 = (a00^d0);
1243 b1 = ROL64((a11^d1), 44);
1244 b2 = ROL64((a22^d2), 43);
1245 b3 = ROL64((a33^d3), 21);
1246 b4 = ROL64((a44^d4), 14);
1247 a00 = b0 ^((~b1)& b2 );
1248 a00 ^= RC[i];
1249 a11 = b1 ^((~b2)& b3 );
1250 a22 = b2 ^((~b3)& b4 );
1251 a33 = b3 ^((~b4)& b0 );
1252 a44 = b4 ^((~b0)& b1 );
1253
1254 b2 = ROL64((a20^d0), 3);
1255 b3 = ROL64((a31^d1), 45);
1256 b4 = ROL64((a42^d2), 61);
1257 b0 = ROL64((a03^d3), 28);
1258 b1 = ROL64((a14^d4), 20);
1259 a20 = b0 ^((~b1)& b2 );
1260 a31 = b1 ^((~b2)& b3 );
1261 a42 = b2 ^((~b3)& b4 );
1262 a03 = b3 ^((~b4)& b0 );
1263 a14 = b4 ^((~b0)& b1 );
1264
1265 b4 = ROL64((a40^d0), 18);
1266 b0 = ROL64((a01^d1), 1);
1267 b1 = ROL64((a12^d2), 6);
1268 b2 = ROL64((a23^d3), 25);
1269 b3 = ROL64((a34^d4), 8);
1270 a40 = b0 ^((~b1)& b2 );
1271 a01 = b1 ^((~b2)& b3 );
1272 a12 = b2 ^((~b3)& b4 );
1273 a23 = b3 ^((~b4)& b0 );
1274 a34 = b4 ^((~b0)& b1 );
1275
1276 b1 = ROL64((a10^d0), 36);
1277 b2 = ROL64((a21^d1), 10);
1278 b3 = ROL64((a32^d2), 15);
1279 b4 = ROL64((a43^d3), 56);
1280 b0 = ROL64((a04^d4), 27);
1281 a10 = b0 ^((~b1)& b2 );
1282 a21 = b1 ^((~b2)& b3 );
1283 a32 = b2 ^((~b3)& b4 );
1284 a43 = b3 ^((~b4)& b0 );
1285 a04 = b4 ^((~b0)& b1 );
1286
1287 b3 = ROL64((a30^d0), 41);
1288 b4 = ROL64((a41^d1), 2);
1289 b0 = ROL64((a02^d2), 62);
1290 b1 = ROL64((a13^d3), 55);
1291 b2 = ROL64((a24^d4), 39);
1292 a30 = b0 ^((~b1)& b2 );
1293 a41 = b1 ^((~b2)& b3 );
1294 a02 = b2 ^((~b3)& b4 );
1295 a13 = b3 ^((~b4)& b0 );
1296 a24 = b4 ^((~b0)& b1 );
1297
1298 c0 = a00^a20^a40^a10^a30;
1299 c1 = a11^a31^a01^a21^a41;
1300 c2 = a22^a42^a12^a32^a02;
1301 c3 = a33^a03^a23^a43^a13;
1302 c4 = a44^a14^a34^a04^a24;
1303 d0 = c4^ROL64(c1, 1);
1304 d1 = c0^ROL64(c2, 1);
1305 d2 = c1^ROL64(c3, 1);
1306 d3 = c2^ROL64(c4, 1);
1307 d4 = c3^ROL64(c0, 1);
1308
1309 b0 = (a00^d0);
1310 b1 = ROL64((a31^d1), 44);
1311 b2 = ROL64((a12^d2), 43);
1312 b3 = ROL64((a43^d3), 21);
1313 b4 = ROL64((a24^d4), 14);
1314 a00 = b0 ^((~b1)& b2 );
1315 a00 ^= RC[i+1];
1316 a31 = b1 ^((~b2)& b3 );
1317 a12 = b2 ^((~b3)& b4 );
1318 a43 = b3 ^((~b4)& b0 );
1319 a24 = b4 ^((~b0)& b1 );
1320
1321 b2 = ROL64((a40^d0), 3);
1322 b3 = ROL64((a21^d1), 45);
1323 b4 = ROL64((a02^d2), 61);
1324 b0 = ROL64((a33^d3), 28);
1325 b1 = ROL64((a14^d4), 20);
1326 a40 = b0 ^((~b1)& b2 );
1327 a21 = b1 ^((~b2)& b3 );
1328 a02 = b2 ^((~b3)& b4 );
1329 a33 = b3 ^((~b4)& b0 );
1330 a14 = b4 ^((~b0)& b1 );
1331
1332 b4 = ROL64((a30^d0), 18);
1333 b0 = ROL64((a11^d1), 1);
1334 b1 = ROL64((a42^d2), 6);
1335 b2 = ROL64((a23^d3), 25);
1336 b3 = ROL64((a04^d4), 8);
1337 a30 = b0 ^((~b1)& b2 );
1338 a11 = b1 ^((~b2)& b3 );
1339 a42 = b2 ^((~b3)& b4 );
1340 a23 = b3 ^((~b4)& b0 );
1341 a04 = b4 ^((~b0)& b1 );
1342
1343 b1 = ROL64((a20^d0), 36);
1344 b2 = ROL64((a01^d1), 10);
1345 b3 = ROL64((a32^d2), 15);
1346 b4 = ROL64((a13^d3), 56);
1347 b0 = ROL64((a44^d4), 27);
1348 a20 = b0 ^((~b1)& b2 );
1349 a01 = b1 ^((~b2)& b3 );
1350 a32 = b2 ^((~b3)& b4 );
1351 a13 = b3 ^((~b4)& b0 );
1352 a44 = b4 ^((~b0)& b1 );
1353
1354 b3 = ROL64((a10^d0), 41);
1355 b4 = ROL64((a41^d1), 2);
1356 b0 = ROL64((a22^d2), 62);
1357 b1 = ROL64((a03^d3), 55);
1358 b2 = ROL64((a34^d4), 39);
1359 a10 = b0 ^((~b1)& b2 );
1360 a41 = b1 ^((~b2)& b3 );
1361 a22 = b2 ^((~b3)& b4 );
1362 a03 = b3 ^((~b4)& b0 );
1363 a34 = b4 ^((~b0)& b1 );
1364
1365 c0 = a00^a40^a30^a20^a10;
1366 c1 = a31^a21^a11^a01^a41;
1367 c2 = a12^a02^a42^a32^a22;
1368 c3 = a43^a33^a23^a13^a03;
1369 c4 = a24^a14^a04^a44^a34;
1370 d0 = c4^ROL64(c1, 1);
1371 d1 = c0^ROL64(c2, 1);
1372 d2 = c1^ROL64(c3, 1);
1373 d3 = c2^ROL64(c4, 1);
1374 d4 = c3^ROL64(c0, 1);
1375
1376 b0 = (a00^d0);
1377 b1 = ROL64((a21^d1), 44);
1378 b2 = ROL64((a42^d2), 43);
1379 b3 = ROL64((a13^d3), 21);
1380 b4 = ROL64((a34^d4), 14);
1381 a00 = b0 ^((~b1)& b2 );
1382 a00 ^= RC[i+2];
1383 a21 = b1 ^((~b2)& b3 );
1384 a42 = b2 ^((~b3)& b4 );
1385 a13 = b3 ^((~b4)& b0 );
1386 a34 = b4 ^((~b0)& b1 );
1387
1388 b2 = ROL64((a30^d0), 3);
1389 b3 = ROL64((a01^d1), 45);
1390 b4 = ROL64((a22^d2), 61);
1391 b0 = ROL64((a43^d3), 28);
1392 b1 = ROL64((a14^d4), 20);
1393 a30 = b0 ^((~b1)& b2 );
1394 a01 = b1 ^((~b2)& b3 );
1395 a22 = b2 ^((~b3)& b4 );
1396 a43 = b3 ^((~b4)& b0 );
1397 a14 = b4 ^((~b0)& b1 );
1398
1399 b4 = ROL64((a10^d0), 18);
1400 b0 = ROL64((a31^d1), 1);
1401 b1 = ROL64((a02^d2), 6);
1402 b2 = ROL64((a23^d3), 25);
1403 b3 = ROL64((a44^d4), 8);
1404 a10 = b0 ^((~b1)& b2 );
1405 a31 = b1 ^((~b2)& b3 );
1406 a02 = b2 ^((~b3)& b4 );
1407 a23 = b3 ^((~b4)& b0 );
1408 a44 = b4 ^((~b0)& b1 );
1409
1410 b1 = ROL64((a40^d0), 36);
1411 b2 = ROL64((a11^d1), 10);
1412 b3 = ROL64((a32^d2), 15);
1413 b4 = ROL64((a03^d3), 56);
1414 b0 = ROL64((a24^d4), 27);
1415 a40 = b0 ^((~b1)& b2 );
1416 a11 = b1 ^((~b2)& b3 );
1417 a32 = b2 ^((~b3)& b4 );
1418 a03 = b3 ^((~b4)& b0 );
1419 a24 = b4 ^((~b0)& b1 );
1420
1421 b3 = ROL64((a20^d0), 41);
1422 b4 = ROL64((a41^d1), 2);
1423 b0 = ROL64((a12^d2), 62);
1424 b1 = ROL64((a33^d3), 55);
1425 b2 = ROL64((a04^d4), 39);
1426 a20 = b0 ^((~b1)& b2 );
1427 a41 = b1 ^((~b2)& b3 );
1428 a12 = b2 ^((~b3)& b4 );
1429 a33 = b3 ^((~b4)& b0 );
1430 a04 = b4 ^((~b0)& b1 );
1431
1432 c0 = a00^a30^a10^a40^a20;
1433 c1 = a21^a01^a31^a11^a41;
1434 c2 = a42^a22^a02^a32^a12;
1435 c3 = a13^a43^a23^a03^a33;
1436 c4 = a34^a14^a44^a24^a04;
1437 d0 = c4^ROL64(c1, 1);
1438 d1 = c0^ROL64(c2, 1);
1439 d2 = c1^ROL64(c3, 1);
1440 d3 = c2^ROL64(c4, 1);
1441 d4 = c3^ROL64(c0, 1);
1442
1443 b0 = (a00^d0);
1444 b1 = ROL64((a01^d1), 44);
1445 b2 = ROL64((a02^d2), 43);
1446 b3 = ROL64((a03^d3), 21);
1447 b4 = ROL64((a04^d4), 14);
1448 a00 = b0 ^((~b1)& b2 );
1449 a00 ^= RC[i+3];
1450 a01 = b1 ^((~b2)& b3 );
1451 a02 = b2 ^((~b3)& b4 );
1452 a03 = b3 ^((~b4)& b0 );
1453 a04 = b4 ^((~b0)& b1 );
1454
1455 b2 = ROL64((a10^d0), 3);
1456 b3 = ROL64((a11^d1), 45);
1457 b4 = ROL64((a12^d2), 61);
1458 b0 = ROL64((a13^d3), 28);
1459 b1 = ROL64((a14^d4), 20);
1460 a10 = b0 ^((~b1)& b2 );
1461 a11 = b1 ^((~b2)& b3 );
1462 a12 = b2 ^((~b3)& b4 );
1463 a13 = b3 ^((~b4)& b0 );
1464 a14 = b4 ^((~b0)& b1 );
1465
1466 b4 = ROL64((a20^d0), 18);
1467 b0 = ROL64((a21^d1), 1);
1468 b1 = ROL64((a22^d2), 6);
1469 b2 = ROL64((a23^d3), 25);
1470 b3 = ROL64((a24^d4), 8);
1471 a20 = b0 ^((~b1)& b2 );
1472 a21 = b1 ^((~b2)& b3 );
1473 a22 = b2 ^((~b3)& b4 );
1474 a23 = b3 ^((~b4)& b0 );
1475 a24 = b4 ^((~b0)& b1 );
1476
1477 b1 = ROL64((a30^d0), 36);
1478 b2 = ROL64((a31^d1), 10);
1479 b3 = ROL64((a32^d2), 15);
1480 b4 = ROL64((a33^d3), 56);
1481 b0 = ROL64((a34^d4), 27);
1482 a30 = b0 ^((~b1)& b2 );
1483 a31 = b1 ^((~b2)& b3 );
1484 a32 = b2 ^((~b3)& b4 );
1485 a33 = b3 ^((~b4)& b0 );
1486 a34 = b4 ^((~b0)& b1 );
1487
1488 b3 = ROL64((a40^d0), 41);
1489 b4 = ROL64((a41^d1), 2);
1490 b0 = ROL64((a42^d2), 62);
1491 b1 = ROL64((a43^d3), 55);
1492 b2 = ROL64((a44^d4), 39);
1493 a40 = b0 ^((~b1)& b2 );
1494 a41 = b1 ^((~b2)& b3 );
1495 a42 = b2 ^((~b3)& b4 );
1496 a43 = b3 ^((~b4)& b0 );
1497 a44 = b4 ^((~b0)& b1 );
1498 }
1499 }
1500
1501 /*
1502 ** Initialize a new hash. iSize determines the size of the hash
@@ -1539,14 +1831,123 @@
1831 ** May you share freely, never taking more than you give.
1832 **
1833 ******************************************************************************
1834 **
1835 ** This SQLite extension implements SQL functions readfile() and
1836 ** writefile(), and eponymous virtual type "fsdir".
1837 **
1838 ** WRITEFILE(FILE, DATA [, MODE [, MTIME]]):
1839 **
1840 ** If neither of the optional arguments is present, then this UDF
1841 ** function writes blob DATA to file FILE. If successful, the number
1842 ** of bytes written is returned. If an error occurs, NULL is returned.
1843 **
1844 ** If the first option argument - MODE - is present, then it must
1845 ** be passed an integer value that corresponds to a POSIX mode
1846 ** value (file type + permissions, as returned in the stat.st_mode
1847 ** field by the stat() system call). Three types of files may
1848 ** be written/created:
1849 **
1850 ** regular files: (mode & 0170000)==0100000
1851 ** symbolic links: (mode & 0170000)==0120000
1852 ** directories: (mode & 0170000)==0040000
1853 **
1854 ** For a directory, the DATA is ignored. For a symbolic link, it is
1855 ** interpreted as text and used as the target of the link. For a
1856 ** regular file, it is interpreted as a blob and written into the
1857 ** named file. Regardless of the type of file, its permissions are
1858 ** set to (mode & 0777) before returning.
1859 **
1860 ** If the optional MTIME argument is present, then it is interpreted
1861 ** as an integer - the number of seconds since the unix epoch. The
1862 ** modification-time of the target file is set to this value before
1863 ** returning.
1864 **
1865 ** If three or more arguments are passed to this function and an
1866 ** error is encountered, an exception is raised.
1867 **
1868 ** READFILE(FILE):
1869 **
1870 ** Read and return the contents of file FILE (type blob) from disk.
1871 **
1872 ** FSDIR:
1873 **
1874 ** Used as follows:
1875 **
1876 ** SELECT * FROM fsdir($path [, $dir]);
1877 **
1878 ** Parameter $path is an absolute or relative pathname. If the file that it
1879 ** refers to does not exist, it is an error. If the path refers to a regular
1880 ** file or symbolic link, it returns a single row. Or, if the path refers
1881 ** to a directory, it returns one row for the directory, and one row for each
1882 ** file within the hierarchy rooted at $path.
1883 **
1884 ** Each row has the following columns:
1885 **
1886 ** name: Path to file or directory (text value).
1887 ** mode: Value of stat.st_mode for directory entry (an integer).
1888 ** mtime: Value of stat.st_mtime for directory entry (an integer).
1889 ** data: For a regular file, a blob containing the file data. For a
1890 ** symlink, a text value containing the text of the link. For a
1891 ** directory, NULL.
1892 **
1893 ** If a non-NULL value is specified for the optional $dir parameter and
1894 ** $path is a relative path, then $path is interpreted relative to $dir.
1895 ** And the paths returned in the "name" column of the table are also
1896 ** relative to directory $dir.
1897 */
1898 SQLITE_EXTENSION_INIT1
1899 #include <stdio.h>
1900 #include <string.h>
1901 #include <assert.h>
1902
1903 #include <sys/types.h>
1904 #include <sys/stat.h>
1905 #include <fcntl.h>
1906 #if !defined(_WIN32) && !defined(WIN32)
1907 # include <unistd.h>
1908 # include <dirent.h>
1909 # include <utime.h>
1910 #else
1911 # include "windows.h"
1912 # include <io.h>
1913 # include <direct.h>
1914 # include "test_windirent.h"
1915 # define dirent DIRENT
1916 # define timespec TIMESPEC
1917 # define stat _stat
1918 # define mkdir(path,mode) _mkdir(path)
1919 # define lstat(path,buf) _stat(path,buf)
1920 #endif
1921 #include <time.h>
1922 #include <errno.h>
1923
1924
1925 #define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
1926
1927 /*
1928 ** Set the result stored by context ctx to a blob containing the
1929 ** contents of file zName.
1930 */
1931 static void readFileContents(sqlite3_context *ctx, const char *zName){
1932 FILE *in;
1933 long nIn;
1934 void *pBuf;
1935
1936 in = fopen(zName, "rb");
1937 if( in==0 ) return;
1938 fseek(in, 0, SEEK_END);
1939 nIn = ftell(in);
1940 rewind(in);
1941 pBuf = sqlite3_malloc( nIn );
1942 if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
1943 sqlite3_result_blob(ctx, pBuf, nIn, sqlite3_free);
1944 }else{
1945 sqlite3_free(pBuf);
1946 }
1947 fclose(in);
1948 }
1949
1950 /*
1951 ** Implementation of the "readfile(X)" SQL function. The entire content
1952 ** of the file named X is read and returned as a BLOB. NULL is returned
1953 ** if the file does not exist or is unreadable.
@@ -1555,62 +1956,611 @@
1956 sqlite3_context *context,
1957 int argc,
1958 sqlite3_value **argv
1959 ){
1960 const char *zName;
 
 
 
 
1961 (void)(argc); /* Unused parameter */
1962 zName = (const char*)sqlite3_value_text(argv[0]);
1963 if( zName==0 ) return;
1964 readFileContents(context, zName);
1965 }
1966
1967 /*
1968 ** Set the error message contained in context ctx to the results of
1969 ** vprintf(zFmt, ...).
1970 */
1971 static void ctxErrorMsg(sqlite3_context *ctx, const char *zFmt, ...){
1972 char *zMsg = 0;
1973 va_list ap;
1974 va_start(ap, zFmt);
1975 zMsg = sqlite3_vmprintf(zFmt, ap);
1976 sqlite3_result_error(ctx, zMsg, -1);
1977 sqlite3_free(zMsg);
1978 va_end(ap);
1979 }
1980
1981 /*
1982 ** Argument zFile is the name of a file that will be created and/or written
1983 ** by SQL function writefile(). This function ensures that the directory
1984 ** zFile will be written to exists, creating it if required. The permissions
1985 ** for any path components created by this function are set to (mode&0777).
1986 **
1987 ** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
1988 ** SQLITE_OK is returned if the directory is successfully created, or
1989 ** SQLITE_ERROR otherwise.
1990 */
1991 static int makeDirectory(
1992 const char *zFile,
1993 mode_t mode
1994 ){
1995 char *zCopy = sqlite3_mprintf("%s", zFile);
1996 int rc = SQLITE_OK;
1997
1998 if( zCopy==0 ){
1999 rc = SQLITE_NOMEM;
2000 }else{
2001 int nCopy = (int)strlen(zCopy);
2002 int i = 1;
2003
2004 while( rc==SQLITE_OK ){
2005 struct stat sStat;
2006 int rc2;
2007
2008 for(; zCopy[i]!='/' && i<nCopy; i++);
2009 if( i==nCopy ) break;
2010 zCopy[i] = '\0';
2011
2012 rc2 = stat(zCopy, &sStat);
2013 if( rc2!=0 ){
2014 if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
2015 }else{
2016 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2017 }
2018 zCopy[i] = '/';
2019 i++;
2020 }
2021
2022 sqlite3_free(zCopy);
2023 }
2024
2025 return rc;
2026 }
2027
2028 /*
2029 ** This function does the work for the writefile() UDF. Refer to
2030 ** header comments at the top of this file for details.
2031 */
2032 static int writeFile(
2033 sqlite3_context *pCtx, /* Context to return bytes written in */
2034 const char *zFile, /* File to write */
2035 sqlite3_value *pData, /* Data to write */
2036 mode_t mode, /* MODE parameter passed to writefile() */
2037 sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */
2038 ){
2039 #if !defined(_WIN32) && !defined(WIN32)
2040 if( S_ISLNK(mode) ){
2041 const char *zTo = (const char*)sqlite3_value_text(pData);
2042 if( symlink(zTo, zFile)<0 ) return 1;
2043 }else
2044 #endif
2045 {
2046 if( S_ISDIR(mode) ){
2047 if( mkdir(zFile, mode) ){
2048 /* The mkdir() call to create the directory failed. This might not
2049 ** be an error though - if there is already a directory at the same
2050 ** path and either the permissions already match or can be changed
2051 ** to do so using chmod(), it is not an error. */
2052 struct stat sStat;
2053 if( errno!=EEXIST
2054 || 0!=stat(zFile, &sStat)
2055 || !S_ISDIR(sStat.st_mode)
2056 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
2057 ){
2058 return 1;
2059 }
2060 }
2061 }else{
2062 sqlite3_int64 nWrite = 0;
2063 const char *z;
2064 int rc = 0;
2065 FILE *out = fopen(zFile, "wb");
2066 if( out==0 ) return 1;
2067 z = (const char*)sqlite3_value_blob(pData);
2068 if( z ){
2069 sqlite3_int64 n = fwrite(z, 1, sqlite3_value_bytes(pData), out);
2070 nWrite = sqlite3_value_bytes(pData);
2071 if( nWrite!=n ){
2072 rc = 1;
2073 }
2074 }
2075 fclose(out);
2076 if( rc==0 && mode && chmod(zFile, mode & 0777) ){
2077 rc = 1;
2078 }
2079 if( rc ) return 2;
2080 sqlite3_result_int64(pCtx, nWrite);
2081 }
2082 }
2083
2084 if( mtime>=0 ){
2085 #if !defined(_WIN32) && !defined(WIN32)
2086 struct timespec times[2];
2087 times[0].tv_nsec = times[1].tv_nsec = 0;
2088 times[0].tv_sec = time(0);
2089 times[1].tv_sec = mtime;
2090 if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
2091 return 1;
2092 }
2093 #else
2094 FILETIME lastAccess;
2095 FILETIME lastWrite;
2096 SYSTEMTIME currentTime;
2097 LONGLONG intervals;
2098 HANDLE hFile;
2099 GetSystemTime(&currentTime);
2100 SystemTimeToFileTime(&currentTime, &lastAccess);
2101 intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
2102 lastWrite.dwLowDateTime = (DWORD)intervals;
2103 lastWrite.dwHighDateTime = intervals >> 32;
2104 hFile = CreateFile(
2105 zFile, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
2106 FILE_FLAG_BACKUP_SEMANTICS, NULL
2107 );
2108 if( hFile!=INVALID_HANDLE_VALUE ){
2109 BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
2110 CloseHandle(hFile);
2111 return !bResult;
2112 }else{
2113 return 1;
2114 }
2115 #endif
2116 }
2117
2118 return 0;
2119 }
2120
2121 /*
2122 ** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
2123 ** Refer to header comments at the top of this file for details.
2124 */
2125 static void writefileFunc(
2126 sqlite3_context *context,
2127 int argc,
2128 sqlite3_value **argv
2129 ){
 
 
 
2130 const char *zFile;
2131 mode_t mode = 0;
2132 int res;
2133 sqlite3_int64 mtime = -1;
2134
2135 if( argc<2 || argc>4 ){
2136 sqlite3_result_error(context,
2137 "wrong number of arguments to function writefile()", -1
2138 );
2139 return;
2140 }
2141
2142 zFile = (const char*)sqlite3_value_text(argv[0]);
2143 if( zFile==0 ) return;
2144 if( argc>=3 ){
2145 mode = (mode_t)sqlite3_value_int(argv[2]);
2146 }
2147 if( argc==4 ){
2148 mtime = sqlite3_value_int64(argv[3]);
2149 }
2150
2151 res = writeFile(context, zFile, argv[1], mode, mtime);
2152 if( res==1 && errno==ENOENT ){
2153 if( makeDirectory(zFile, mode)==SQLITE_OK ){
2154 res = writeFile(context, zFile, argv[1], mode, mtime);
2155 }
2156 }
2157
2158 if( argc>2 && res!=0 ){
2159 if( S_ISLNK(mode) ){
2160 ctxErrorMsg(context, "failed to create symlink: %s", zFile);
2161 }else if( S_ISDIR(mode) ){
2162 ctxErrorMsg(context, "failed to create directory: %s", zFile);
2163 }else{
2164 ctxErrorMsg(context, "failed to write file: %s", zFile);
2165 }
2166 }
2167 }
2168
2169 #ifndef SQLITE_OMIT_VIRTUALTABLE
2170
2171 /*
2172 ** Cursor type for recursively iterating through a directory structure.
2173 */
2174 typedef struct fsdir_cursor fsdir_cursor;
2175 typedef struct FsdirLevel FsdirLevel;
2176
2177 struct FsdirLevel {
2178 DIR *pDir; /* From opendir() */
2179 char *zDir; /* Name of directory (nul-terminated) */
2180 };
2181
2182 struct fsdir_cursor {
2183 sqlite3_vtab_cursor base; /* Base class - must be first */
2184
2185 int nLvl; /* Number of entries in aLvl[] array */
2186 int iLvl; /* Index of current entry */
2187 FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
2188
2189 const char *zBase;
2190 int nBase;
2191
2192 struct stat sStat; /* Current lstat() results */
2193 char *zPath; /* Path to current entry */
2194 sqlite3_int64 iRowid; /* Current rowid */
2195 };
2196
2197 typedef struct fsdir_tab fsdir_tab;
2198 struct fsdir_tab {
2199 sqlite3_vtab base; /* Base class - must be first */
2200 };
2201
2202 /*
2203 ** Construct a new fsdir virtual table object.
2204 */
2205 static int fsdirConnect(
2206 sqlite3 *db,
2207 void *pAux,
2208 int argc, const char *const*argv,
2209 sqlite3_vtab **ppVtab,
2210 char **pzErr
2211 ){
2212 fsdir_tab *pNew = 0;
2213 int rc;
2214
2215 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2216 if( rc==SQLITE_OK ){
2217 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2218 if( pNew==0 ) return SQLITE_NOMEM;
2219 memset(pNew, 0, sizeof(*pNew));
2220 }
2221 *ppVtab = (sqlite3_vtab*)pNew;
2222 return rc;
2223 }
2224
2225 /*
2226 ** This method is the destructor for fsdir vtab objects.
2227 */
2228 static int fsdirDisconnect(sqlite3_vtab *pVtab){
2229 sqlite3_free(pVtab);
2230 return SQLITE_OK;
2231 }
2232
2233 /*
2234 ** Constructor for a new fsdir_cursor object.
2235 */
2236 static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
2237 fsdir_cursor *pCur;
2238 pCur = sqlite3_malloc( sizeof(*pCur) );
2239 if( pCur==0 ) return SQLITE_NOMEM;
2240 memset(pCur, 0, sizeof(*pCur));
2241 pCur->iLvl = -1;
2242 *ppCursor = &pCur->base;
2243 return SQLITE_OK;
2244 }
2245
2246 /*
2247 ** Reset a cursor back to the state it was in when first returned
2248 ** by fsdirOpen().
2249 */
2250 static void fsdirResetCursor(fsdir_cursor *pCur){
2251 int i;
2252 for(i=0; i<=pCur->iLvl; i++){
2253 FsdirLevel *pLvl = &pCur->aLvl[i];
2254 if( pLvl->pDir ) closedir(pLvl->pDir);
2255 sqlite3_free(pLvl->zDir);
2256 }
2257 sqlite3_free(pCur->zPath);
2258 pCur->aLvl = 0;
2259 pCur->zPath = 0;
2260 pCur->zBase = 0;
2261 pCur->nBase = 0;
2262 pCur->iLvl = -1;
2263 pCur->iRowid = 1;
2264 }
2265
2266 /*
2267 ** Destructor for an fsdir_cursor.
2268 */
2269 static int fsdirClose(sqlite3_vtab_cursor *cur){
2270 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2271
2272 fsdirResetCursor(pCur);
2273 sqlite3_free(pCur->aLvl);
2274 sqlite3_free(pCur);
2275 return SQLITE_OK;
2276 }
2277
2278 /*
2279 ** Set the error message for the virtual table associated with cursor
2280 ** pCur to the results of vprintf(zFmt, ...).
2281 */
2282 static void fsdirSetErrmsg(fsdir_cursor *pCur, const char *zFmt, ...){
2283 va_list ap;
2284 va_start(ap, zFmt);
2285 pCur->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
2286 va_end(ap);
2287 }
2288
2289
2290 /*
2291 ** Advance an fsdir_cursor to its next row of output.
2292 */
2293 static int fsdirNext(sqlite3_vtab_cursor *cur){
2294 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2295 mode_t m = pCur->sStat.st_mode;
2296
2297 pCur->iRowid++;
2298 if( S_ISDIR(m) ){
2299 /* Descend into this directory */
2300 int iNew = pCur->iLvl + 1;
2301 FsdirLevel *pLvl;
2302 if( iNew>=pCur->nLvl ){
2303 int nNew = iNew+1;
2304 int nByte = nNew*sizeof(FsdirLevel);
2305 FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc(pCur->aLvl, nByte);
2306 if( aNew==0 ) return SQLITE_NOMEM;
2307 memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
2308 pCur->aLvl = aNew;
2309 pCur->nLvl = nNew;
2310 }
2311 pCur->iLvl = iNew;
2312 pLvl = &pCur->aLvl[iNew];
2313
2314 pLvl->zDir = pCur->zPath;
2315 pCur->zPath = 0;
2316 pLvl->pDir = opendir(pLvl->zDir);
2317 if( pLvl->pDir==0 ){
2318 fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath);
2319 return SQLITE_ERROR;
2320 }
2321 }
2322
2323 while( pCur->iLvl>=0 ){
2324 FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl];
2325 struct dirent *pEntry = readdir(pLvl->pDir);
2326 if( pEntry ){
2327 if( pEntry->d_name[0]=='.' ){
2328 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
2329 if( pEntry->d_name[1]=='\0' ) continue;
2330 }
2331 sqlite3_free(pCur->zPath);
2332 pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
2333 if( pCur->zPath==0 ) return SQLITE_NOMEM;
2334 if( lstat(pCur->zPath, &pCur->sStat) ){
2335 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2336 return SQLITE_ERROR;
2337 }
2338 return SQLITE_OK;
2339 }
2340 closedir(pLvl->pDir);
2341 sqlite3_free(pLvl->zDir);
2342 pLvl->pDir = 0;
2343 pLvl->zDir = 0;
2344 pCur->iLvl--;
2345 }
2346
2347 /* EOF */
2348 sqlite3_free(pCur->zPath);
2349 pCur->zPath = 0;
2350 return SQLITE_OK;
2351 }
2352
2353 /*
2354 ** Return values of columns for the row at which the series_cursor
2355 ** is currently pointing.
2356 */
2357 static int fsdirColumn(
2358 sqlite3_vtab_cursor *cur, /* The cursor */
2359 sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
2360 int i /* Which column to return */
2361 ){
2362 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2363 switch( i ){
2364 case 0: { /* name */
2365 sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
2366 break;
2367 }
2368
2369 case 1: /* mode */
2370 sqlite3_result_int64(ctx, pCur->sStat.st_mode);
2371 break;
2372
2373 case 2: /* mtime */
2374 sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
2375 break;
2376
2377 case 3: { /* data */
2378 mode_t m = pCur->sStat.st_mode;
2379 if( S_ISDIR(m) ){
2380 sqlite3_result_null(ctx);
2381 #if !defined(_WIN32) && !defined(WIN32)
2382 }else if( S_ISLNK(m) ){
2383 char aStatic[64];
2384 char *aBuf = aStatic;
2385 int nBuf = 64;
2386 int n;
2387
2388 while( 1 ){
2389 n = readlink(pCur->zPath, aBuf, nBuf);
2390 if( n<nBuf ) break;
2391 if( aBuf!=aStatic ) sqlite3_free(aBuf);
2392 nBuf = nBuf*2;
2393 aBuf = sqlite3_malloc(nBuf);
2394 if( aBuf==0 ){
2395 sqlite3_result_error_nomem(ctx);
2396 return SQLITE_NOMEM;
2397 }
2398 }
2399
2400 sqlite3_result_text(ctx, aBuf, n, SQLITE_TRANSIENT);
2401 if( aBuf!=aStatic ) sqlite3_free(aBuf);
2402 #endif
2403 }else{
2404 readFileContents(ctx, pCur->zPath);
2405 }
2406 }
2407 }
2408 return SQLITE_OK;
2409 }
2410
2411 /*
2412 ** Return the rowid for the current row. In this implementation, the
2413 ** first row returned is assigned rowid value 1, and each subsequent
2414 ** row a value 1 more than that of the previous.
2415 */
2416 static int fsdirRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
2417 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2418 *pRowid = pCur->iRowid;
2419 return SQLITE_OK;
2420 }
2421
2422 /*
2423 ** Return TRUE if the cursor has been moved off of the last
2424 ** row of output.
2425 */
2426 static int fsdirEof(sqlite3_vtab_cursor *cur){
2427 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2428 return (pCur->zPath==0);
2429 }
2430
2431 /*
2432 ** xFilter callback.
2433 */
2434 static int fsdirFilter(
2435 sqlite3_vtab_cursor *cur,
2436 int idxNum, const char *idxStr,
2437 int argc, sqlite3_value **argv
2438 ){
2439 const char *zDir = 0;
2440 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2441
2442 fsdirResetCursor(pCur);
2443
2444 if( idxNum==0 ){
2445 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
2446 return SQLITE_ERROR;
2447 }
2448
2449 assert( argc==idxNum && (argc==1 || argc==2) );
2450 zDir = (const char*)sqlite3_value_text(argv[0]);
2451 if( zDir==0 ){
2452 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
2453 return SQLITE_ERROR;
2454 }
2455 if( argc==2 ){
2456 pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
2457 }
2458 if( pCur->zBase ){
2459 pCur->nBase = (int)strlen(pCur->zBase)+1;
2460 pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
2461 }else{
2462 pCur->zPath = sqlite3_mprintf("%s", zDir);
2463 }
2464
2465 if( pCur->zPath==0 ){
2466 return SQLITE_NOMEM;
2467 }
2468 if( lstat(pCur->zPath, &pCur->sStat) ){
2469 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2470 return SQLITE_ERROR;
2471 }
2472
2473 return SQLITE_OK;
2474 }
2475
2476 /*
2477 ** SQLite will invoke this method one or more times while planning a query
2478 ** that uses the generate_series virtual table. This routine needs to create
2479 ** a query plan for each invocation and compute an estimated cost for that
2480 ** plan.
2481 **
2482 ** In this implementation idxNum is used to represent the
2483 ** query plan. idxStr is unused.
2484 **
2485 ** The query plan is represented by bits in idxNum:
2486 **
2487 ** (1) start = $value -- constraint exists
2488 ** (2) stop = $value -- constraint exists
2489 ** (4) step = $value -- constraint exists
2490 ** (8) output in descending order
2491 */
2492 static int fsdirBestIndex(
2493 sqlite3_vtab *tab,
2494 sqlite3_index_info *pIdxInfo
2495 ){
2496 int i; /* Loop over constraints */
2497 int idx4 = -1;
2498 int idx5 = -1;
2499
2500 const struct sqlite3_index_constraint *pConstraint;
2501 pConstraint = pIdxInfo->aConstraint;
2502 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
2503 if( pConstraint->usable==0 ) continue;
2504 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
2505 if( pConstraint->iColumn==4 ) idx4 = i;
2506 if( pConstraint->iColumn==5 ) idx5 = i;
2507 }
2508
2509 if( idx4<0 ){
2510 pIdxInfo->idxNum = 0;
2511 pIdxInfo->estimatedCost = (double)(((sqlite3_int64)1) << 50);
2512 }else{
2513 pIdxInfo->aConstraintUsage[idx4].omit = 1;
2514 pIdxInfo->aConstraintUsage[idx4].argvIndex = 1;
2515 if( idx5>=0 ){
2516 pIdxInfo->aConstraintUsage[idx5].omit = 1;
2517 pIdxInfo->aConstraintUsage[idx5].argvIndex = 2;
2518 pIdxInfo->idxNum = 2;
2519 pIdxInfo->estimatedCost = 10.0;
2520 }else{
2521 pIdxInfo->idxNum = 1;
2522 pIdxInfo->estimatedCost = 100.0;
2523 }
2524 }
2525
2526 return SQLITE_OK;
2527 }
2528
2529 /*
2530 ** Register the "fsdir" virtual table.
2531 */
2532 static int fsdirRegister(sqlite3 *db){
2533 static sqlite3_module fsdirModule = {
2534 0, /* iVersion */
2535 0, /* xCreate */
2536 fsdirConnect, /* xConnect */
2537 fsdirBestIndex, /* xBestIndex */
2538 fsdirDisconnect, /* xDisconnect */
2539 0, /* xDestroy */
2540 fsdirOpen, /* xOpen - open a cursor */
2541 fsdirClose, /* xClose - close a cursor */
2542 fsdirFilter, /* xFilter - configure scan constraints */
2543 fsdirNext, /* xNext - advance a cursor */
2544 fsdirEof, /* xEof - check for end of scan */
2545 fsdirColumn, /* xColumn - read data */
2546 fsdirRowid, /* xRowid - read data */
2547 0, /* xUpdate */
2548 0, /* xBegin */
2549 0, /* xSync */
2550 0, /* xCommit */
2551 0, /* xRollback */
2552 0, /* xFindMethod */
2553 0, /* xRename */
2554 };
2555
2556 int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
2557 return rc;
2558 }
2559 #else /* SQLITE_OMIT_VIRTUALTABLE */
2560 # define fsdirRegister(x) SQLITE_OK
2561 #endif
2562
2563 #ifdef _WIN32
2564
2565 #endif
2566 int sqlite3_fileio_init(
@@ -1622,13 +2572,16 @@
2572 SQLITE_EXTENSION_INIT2(pApi);
2573 (void)pzErrMsg; /* Unused parameter */
2574 rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
2575 readfileFunc, 0, 0);
2576 if( rc==SQLITE_OK ){
2577 rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
2578 writefileFunc, 0, 0);
2579 }
2580 if( rc==SQLITE_OK ){
2581 rc = fsdirRegister(db);
2582 }
2583 return rc;
2584 }
2585
2586 /************************* End ../ext/misc/fileio.c ********************/
2587 /************************* Begin ../ext/misc/completion.c ******************/
@@ -2154,10 +3107,4226 @@
3107 #endif
3108 return rc;
3109 }
3110
3111 /************************* End ../ext/misc/completion.c ********************/
3112 /************************* Begin ../ext/misc/appendvfs.c ******************/
3113 /*
3114 ** 2017-10-20
3115 **
3116 ** The author disclaims copyright to this source code. In place of
3117 ** a legal notice, here is a blessing:
3118 **
3119 ** May you do good and not evil.
3120 ** May you find forgiveness for yourself and forgive others.
3121 ** May you share freely, never taking more than you give.
3122 **
3123 ******************************************************************************
3124 **
3125 ** This file implements a VFS shim that allows an SQLite database to be
3126 ** appended onto the end of some other file, such as an executable.
3127 **
3128 ** A special record must appear at the end of the file that identifies the
3129 ** file as an appended database and provides an offset to page 1. For
3130 ** best performance page 1 should be located at a disk page boundary, though
3131 ** that is not required.
3132 **
3133 ** When opening a database using this VFS, the connection might treat
3134 ** the file as an ordinary SQLite database, or it might treat is as a
3135 ** database appended onto some other file. Here are the rules:
3136 **
3137 ** (1) When opening a new empty file, that file is treated as an ordinary
3138 ** database.
3139 **
3140 ** (2) When opening a file that begins with the standard SQLite prefix
3141 ** string "SQLite format 3", that file is treated as an ordinary
3142 ** database.
3143 **
3144 ** (3) When opening a file that ends with the appendvfs trailer string
3145 ** "Start-Of-SQLite3-NNNNNNNN" that file is treated as an appended
3146 ** database.
3147 **
3148 ** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
3149 ** set, then a new database is appended to the already existing file.
3150 **
3151 ** (5) Otherwise, SQLITE_CANTOPEN is returned.
3152 **
3153 ** To avoid unnecessary complications with the PENDING_BYTE, the size of
3154 ** the file containing the database is limited to 1GB. This VFS will refuse
3155 ** to read or write past the 1GB mark. This restriction might be lifted in
3156 ** future versions. For now, if you need a large database, then keep the
3157 ** database in a separate file.
3158 **
3159 ** If the file being opened is not an appended database, then this shim is
3160 ** a pass-through into the default underlying VFS.
3161 **/
3162 SQLITE_EXTENSION_INIT1
3163 #include <string.h>
3164 #include <assert.h>
3165
3166 /* The append mark at the end of the database is:
3167 **
3168 ** Start-Of-SQLite3-NNNNNNNN
3169 ** 123456789 123456789 12345
3170 **
3171 ** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
3172 ** the offset to page 1.
3173 */
3174 #define APND_MARK_PREFIX "Start-Of-SQLite3-"
3175 #define APND_MARK_PREFIX_SZ 17
3176 #define APND_MARK_SIZE 25
3177
3178 /*
3179 ** Maximum size of the combined prefix + database + append-mark. This
3180 ** must be less than 0x40000000 to avoid locking issues on Windows.
3181 */
3182 #define APND_MAX_SIZE (65536*15259)
3183
3184 /*
3185 ** Forward declaration of objects used by this utility
3186 */
3187 typedef struct sqlite3_vfs ApndVfs;
3188 typedef struct ApndFile ApndFile;
3189
3190 /* Access to a lower-level VFS that (might) implement dynamic loading,
3191 ** access to randomness, etc.
3192 */
3193 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
3194 #define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
3195
3196 /* An open file */
3197 struct ApndFile {
3198 sqlite3_file base; /* IO methods */
3199 sqlite3_int64 iPgOne; /* File offset to page 1 */
3200 sqlite3_int64 iMark; /* Start of the append-mark */
3201 };
3202
3203 /*
3204 ** Methods for ApndFile
3205 */
3206 static int apndClose(sqlite3_file*);
3207 static int apndRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
3208 static int apndWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
3209 static int apndTruncate(sqlite3_file*, sqlite3_int64 size);
3210 static int apndSync(sqlite3_file*, int flags);
3211 static int apndFileSize(sqlite3_file*, sqlite3_int64 *pSize);
3212 static int apndLock(sqlite3_file*, int);
3213 static int apndUnlock(sqlite3_file*, int);
3214 static int apndCheckReservedLock(sqlite3_file*, int *pResOut);
3215 static int apndFileControl(sqlite3_file*, int op, void *pArg);
3216 static int apndSectorSize(sqlite3_file*);
3217 static int apndDeviceCharacteristics(sqlite3_file*);
3218 static int apndShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
3219 static int apndShmLock(sqlite3_file*, int offset, int n, int flags);
3220 static void apndShmBarrier(sqlite3_file*);
3221 static int apndShmUnmap(sqlite3_file*, int deleteFlag);
3222 static int apndFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
3223 static int apndUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p);
3224
3225 /*
3226 ** Methods for ApndVfs
3227 */
3228 static int apndOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
3229 static int apndDelete(sqlite3_vfs*, const char *zName, int syncDir);
3230 static int apndAccess(sqlite3_vfs*, const char *zName, int flags, int *);
3231 static int apndFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
3232 static void *apndDlOpen(sqlite3_vfs*, const char *zFilename);
3233 static void apndDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
3234 static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void);
3235 static void apndDlClose(sqlite3_vfs*, void*);
3236 static int apndRandomness(sqlite3_vfs*, int nByte, char *zOut);
3237 static int apndSleep(sqlite3_vfs*, int microseconds);
3238 static int apndCurrentTime(sqlite3_vfs*, double*);
3239 static int apndGetLastError(sqlite3_vfs*, int, char *);
3240 static int apndCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*);
3241 static int apndSetSystemCall(sqlite3_vfs*, const char*,sqlite3_syscall_ptr);
3242 static sqlite3_syscall_ptr apndGetSystemCall(sqlite3_vfs*, const char *z);
3243 static const char *apndNextSystemCall(sqlite3_vfs*, const char *zName);
3244
3245 static sqlite3_vfs apnd_vfs = {
3246 3, /* iVersion (set when registered) */
3247 0, /* szOsFile (set when registered) */
3248 1024, /* mxPathname */
3249 0, /* pNext */
3250 "apndvfs", /* zName */
3251 0, /* pAppData (set when registered) */
3252 apndOpen, /* xOpen */
3253 apndDelete, /* xDelete */
3254 apndAccess, /* xAccess */
3255 apndFullPathname, /* xFullPathname */
3256 apndDlOpen, /* xDlOpen */
3257 apndDlError, /* xDlError */
3258 apndDlSym, /* xDlSym */
3259 apndDlClose, /* xDlClose */
3260 apndRandomness, /* xRandomness */
3261 apndSleep, /* xSleep */
3262 apndCurrentTime, /* xCurrentTime */
3263 apndGetLastError, /* xGetLastError */
3264 apndCurrentTimeInt64, /* xCurrentTimeInt64 */
3265 apndSetSystemCall, /* xSetSystemCall */
3266 apndGetSystemCall, /* xGetSystemCall */
3267 apndNextSystemCall /* xNextSystemCall */
3268 };
3269
3270 static const sqlite3_io_methods apnd_io_methods = {
3271 3, /* iVersion */
3272 apndClose, /* xClose */
3273 apndRead, /* xRead */
3274 apndWrite, /* xWrite */
3275 apndTruncate, /* xTruncate */
3276 apndSync, /* xSync */
3277 apndFileSize, /* xFileSize */
3278 apndLock, /* xLock */
3279 apndUnlock, /* xUnlock */
3280 apndCheckReservedLock, /* xCheckReservedLock */
3281 apndFileControl, /* xFileControl */
3282 apndSectorSize, /* xSectorSize */
3283 apndDeviceCharacteristics, /* xDeviceCharacteristics */
3284 apndShmMap, /* xShmMap */
3285 apndShmLock, /* xShmLock */
3286 apndShmBarrier, /* xShmBarrier */
3287 apndShmUnmap, /* xShmUnmap */
3288 apndFetch, /* xFetch */
3289 apndUnfetch /* xUnfetch */
3290 };
3291
3292
3293
3294 /*
3295 ** Close an apnd-file.
3296 */
3297 static int apndClose(sqlite3_file *pFile){
3298 pFile = ORIGFILE(pFile);
3299 return pFile->pMethods->xClose(pFile);
3300 }
3301
3302 /*
3303 ** Read data from an apnd-file.
3304 */
3305 static int apndRead(
3306 sqlite3_file *pFile,
3307 void *zBuf,
3308 int iAmt,
3309 sqlite_int64 iOfst
3310 ){
3311 ApndFile *p = (ApndFile *)pFile;
3312 pFile = ORIGFILE(pFile);
3313 return pFile->pMethods->xRead(pFile, zBuf, iAmt, iOfst+p->iPgOne);
3314 }
3315
3316 /*
3317 ** Add the append-mark onto the end of the file.
3318 */
3319 static int apndWriteMark(ApndFile *p, sqlite3_file *pFile){
3320 int i;
3321 unsigned char a[APND_MARK_SIZE];
3322 memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3323 for(i=0; i<8; i++){
3324 a[APND_MARK_PREFIX_SZ+i] = (p->iPgOne >> (56 - i*8)) & 0xff;
3325 }
3326 return pFile->pMethods->xWrite(pFile, a, APND_MARK_SIZE, p->iMark);
3327 }
3328
3329 /*
3330 ** Write data to an apnd-file.
3331 */
3332 static int apndWrite(
3333 sqlite3_file *pFile,
3334 const void *zBuf,
3335 int iAmt,
3336 sqlite_int64 iOfst
3337 ){
3338 int rc;
3339 ApndFile *p = (ApndFile *)pFile;
3340 pFile = ORIGFILE(pFile);
3341 if( iOfst+iAmt>=APND_MAX_SIZE ) return SQLITE_FULL;
3342 rc = pFile->pMethods->xWrite(pFile, zBuf, iAmt, iOfst+p->iPgOne);
3343 if( rc==SQLITE_OK && iOfst + iAmt + p->iPgOne > p->iMark ){
3344 sqlite3_int64 sz = 0;
3345 rc = pFile->pMethods->xFileSize(pFile, &sz);
3346 if( rc==SQLITE_OK ){
3347 p->iMark = sz - APND_MARK_SIZE;
3348 if( iOfst + iAmt + p->iPgOne > p->iMark ){
3349 p->iMark = p->iPgOne + iOfst + iAmt;
3350 rc = apndWriteMark(p, pFile);
3351 }
3352 }
3353 }
3354 return rc;
3355 }
3356
3357 /*
3358 ** Truncate an apnd-file.
3359 */
3360 static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
3361 int rc;
3362 ApndFile *p = (ApndFile *)pFile;
3363 pFile = ORIGFILE(pFile);
3364 rc = pFile->pMethods->xTruncate(pFile, size+p->iPgOne+APND_MARK_SIZE);
3365 if( rc==SQLITE_OK ){
3366 p->iMark = p->iPgOne+size;
3367 rc = apndWriteMark(p, pFile);
3368 }
3369 return rc;
3370 }
3371
3372 /*
3373 ** Sync an apnd-file.
3374 */
3375 static int apndSync(sqlite3_file *pFile, int flags){
3376 pFile = ORIGFILE(pFile);
3377 return pFile->pMethods->xSync(pFile, flags);
3378 }
3379
3380 /*
3381 ** Return the current file-size of an apnd-file.
3382 */
3383 static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
3384 ApndFile *p = (ApndFile *)pFile;
3385 int rc;
3386 pFile = ORIGFILE(p);
3387 rc = pFile->pMethods->xFileSize(pFile, pSize);
3388 if( rc==SQLITE_OK && p->iPgOne ){
3389 *pSize -= p->iPgOne + APND_MARK_SIZE;
3390 }
3391 return rc;
3392 }
3393
3394 /*
3395 ** Lock an apnd-file.
3396 */
3397 static int apndLock(sqlite3_file *pFile, int eLock){
3398 pFile = ORIGFILE(pFile);
3399 return pFile->pMethods->xLock(pFile, eLock);
3400 }
3401
3402 /*
3403 ** Unlock an apnd-file.
3404 */
3405 static int apndUnlock(sqlite3_file *pFile, int eLock){
3406 pFile = ORIGFILE(pFile);
3407 return pFile->pMethods->xUnlock(pFile, eLock);
3408 }
3409
3410 /*
3411 ** Check if another file-handle holds a RESERVED lock on an apnd-file.
3412 */
3413 static int apndCheckReservedLock(sqlite3_file *pFile, int *pResOut){
3414 pFile = ORIGFILE(pFile);
3415 return pFile->pMethods->xCheckReservedLock(pFile, pResOut);
3416 }
3417
3418 /*
3419 ** File control method. For custom operations on an apnd-file.
3420 */
3421 static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
3422 ApndFile *p = (ApndFile *)pFile;
3423 int rc;
3424 pFile = ORIGFILE(pFile);
3425 rc = pFile->pMethods->xFileControl(pFile, op, pArg);
3426 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
3427 *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", p->iPgOne, *(char**)pArg);
3428 }
3429 return rc;
3430 }
3431
3432 /*
3433 ** Return the sector-size in bytes for an apnd-file.
3434 */
3435 static int apndSectorSize(sqlite3_file *pFile){
3436 pFile = ORIGFILE(pFile);
3437 return pFile->pMethods->xSectorSize(pFile);
3438 }
3439
3440 /*
3441 ** Return the device characteristic flags supported by an apnd-file.
3442 */
3443 static int apndDeviceCharacteristics(sqlite3_file *pFile){
3444 pFile = ORIGFILE(pFile);
3445 return pFile->pMethods->xDeviceCharacteristics(pFile);
3446 }
3447
3448 /* Create a shared memory file mapping */
3449 static int apndShmMap(
3450 sqlite3_file *pFile,
3451 int iPg,
3452 int pgsz,
3453 int bExtend,
3454 void volatile **pp
3455 ){
3456 pFile = ORIGFILE(pFile);
3457 return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp);
3458 }
3459
3460 /* Perform locking on a shared-memory segment */
3461 static int apndShmLock(sqlite3_file *pFile, int offset, int n, int flags){
3462 pFile = ORIGFILE(pFile);
3463 return pFile->pMethods->xShmLock(pFile,offset,n,flags);
3464 }
3465
3466 /* Memory barrier operation on shared memory */
3467 static void apndShmBarrier(sqlite3_file *pFile){
3468 pFile = ORIGFILE(pFile);
3469 pFile->pMethods->xShmBarrier(pFile);
3470 }
3471
3472 /* Unmap a shared memory segment */
3473 static int apndShmUnmap(sqlite3_file *pFile, int deleteFlag){
3474 pFile = ORIGFILE(pFile);
3475 return pFile->pMethods->xShmUnmap(pFile,deleteFlag);
3476 }
3477
3478 /* Fetch a page of a memory-mapped file */
3479 static int apndFetch(
3480 sqlite3_file *pFile,
3481 sqlite3_int64 iOfst,
3482 int iAmt,
3483 void **pp
3484 ){
3485 ApndFile *p = (ApndFile *)pFile;
3486 pFile = ORIGFILE(pFile);
3487 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
3488 }
3489
3490 /* Release a memory-mapped page */
3491 static int apndUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
3492 ApndFile *p = (ApndFile *)pFile;
3493 pFile = ORIGFILE(pFile);
3494 return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
3495 }
3496
3497 /*
3498 ** Check to see if the file is an ordinary SQLite database file.
3499 */
3500 static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
3501 int rc;
3502 char zHdr[16];
3503 static const char aSqliteHdr[] = "SQLite format 3";
3504 if( sz<512 ) return 0;
3505 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0);
3506 if( rc ) return 0;
3507 return memcmp(zHdr, aSqliteHdr, sizeof(zHdr))==0;
3508 }
3509
3510 /*
3511 ** Try to read the append-mark off the end of a file. Return the
3512 ** start of the appended database if the append-mark is present. If
3513 ** there is no append-mark, return -1;
3514 */
3515 static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
3516 int rc, i;
3517 sqlite3_int64 iMark;
3518 unsigned char a[APND_MARK_SIZE];
3519
3520 if( sz<=APND_MARK_SIZE ) return -1;
3521 rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
3522 if( rc ) return -1;
3523 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
3524 iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ]&0x7f))<<56;
3525 for(i=1; i<8; i++){
3526 iMark += (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<(56-8*i);
3527 }
3528 return iMark;
3529 }
3530
3531 /*
3532 ** Open an apnd file handle.
3533 */
3534 static int apndOpen(
3535 sqlite3_vfs *pVfs,
3536 const char *zName,
3537 sqlite3_file *pFile,
3538 int flags,
3539 int *pOutFlags
3540 ){
3541 ApndFile *p;
3542 sqlite3_file *pSubFile;
3543 sqlite3_vfs *pSubVfs;
3544 int rc;
3545 sqlite3_int64 sz;
3546 pSubVfs = ORIGVFS(pVfs);
3547 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
3548 return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
3549 }
3550 p = (ApndFile*)pFile;
3551 memset(p, 0, sizeof(*p));
3552 pSubFile = ORIGFILE(pFile);
3553 p->base.pMethods = &apnd_io_methods;
3554 rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
3555 if( rc ) goto apnd_open_done;
3556 rc = pSubFile->pMethods->xFileSize(pSubFile, &sz);
3557 if( rc ){
3558 pSubFile->pMethods->xClose(pSubFile);
3559 goto apnd_open_done;
3560 }
3561 if( apndIsOrdinaryDatabaseFile(sz, pSubFile) ){
3562 memmove(pFile, pSubFile, pSubVfs->szOsFile);
3563 return SQLITE_OK;
3564 }
3565 p->iMark = 0;
3566 p->iPgOne = apndReadMark(sz, pFile);
3567 if( p->iPgOne>0 ){
3568 return SQLITE_OK;
3569 }
3570 if( (flags & SQLITE_OPEN_CREATE)==0 ){
3571 pSubFile->pMethods->xClose(pSubFile);
3572 rc = SQLITE_CANTOPEN;
3573 }
3574 p->iPgOne = (sz+0xfff) & ~(sqlite3_int64)0xfff;
3575 apnd_open_done:
3576 if( rc ) pFile->pMethods = 0;
3577 return rc;
3578 }
3579
3580 /*
3581 ** All other VFS methods are pass-thrus.
3582 */
3583 static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
3584 return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
3585 }
3586 static int apndAccess(
3587 sqlite3_vfs *pVfs,
3588 const char *zPath,
3589 int flags,
3590 int *pResOut
3591 ){
3592 return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
3593 }
3594 static int apndFullPathname(
3595 sqlite3_vfs *pVfs,
3596 const char *zPath,
3597 int nOut,
3598 char *zOut
3599 ){
3600 return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
3601 }
3602 static void *apndDlOpen(sqlite3_vfs *pVfs, const char *zPath){
3603 return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath);
3604 }
3605 static void apndDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
3606 ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg);
3607 }
3608 static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
3609 return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym);
3610 }
3611 static void apndDlClose(sqlite3_vfs *pVfs, void *pHandle){
3612 ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle);
3613 }
3614 static int apndRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
3615 return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut);
3616 }
3617 static int apndSleep(sqlite3_vfs *pVfs, int nMicro){
3618 return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro);
3619 }
3620 static int apndCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
3621 return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut);
3622 }
3623 static int apndGetLastError(sqlite3_vfs *pVfs, int a, char *b){
3624 return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
3625 }
3626 static int apndCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
3627 return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p);
3628 }
3629 static int apndSetSystemCall(
3630 sqlite3_vfs *pVfs,
3631 const char *zName,
3632 sqlite3_syscall_ptr pCall
3633 ){
3634 return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall);
3635 }
3636 static sqlite3_syscall_ptr apndGetSystemCall(
3637 sqlite3_vfs *pVfs,
3638 const char *zName
3639 ){
3640 return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName);
3641 }
3642 static const char *apndNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
3643 return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
3644 }
3645
3646
3647 #ifdef _WIN32
3648
3649 #endif
3650 /*
3651 ** This routine is called when the extension is loaded.
3652 ** Register the new VFS.
3653 */
3654 int sqlite3_appendvfs_init(
3655 sqlite3 *db,
3656 char **pzErrMsg,
3657 const sqlite3_api_routines *pApi
3658 ){
3659 int rc = SQLITE_OK;
3660 sqlite3_vfs *pOrig;
3661 SQLITE_EXTENSION_INIT2(pApi);
3662 pOrig = sqlite3_vfs_find(0);
3663 apnd_vfs.iVersion = pOrig->iVersion;
3664 apnd_vfs.pAppData = pOrig;
3665 apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
3666 rc = sqlite3_vfs_register(&apnd_vfs, 0);
3667 #ifdef APPENDVFS_TEST
3668 if( rc==SQLITE_OK ){
3669 rc = sqlite3_auto_extension((void(*)(void))apndvfsRegister);
3670 }
3671 #endif
3672 if( rc==SQLITE_OK ) rc = SQLITE_OK_LOAD_PERMANENTLY;
3673 return rc;
3674 }
3675
3676 /************************* End ../ext/misc/appendvfs.c ********************/
3677 #ifdef SQLITE_HAVE_ZLIB
3678 /************************* Begin ../ext/misc/zipfile.c ******************/
3679 /*
3680 ** 2017-12-26
3681 **
3682 ** The author disclaims copyright to this source code. In place of
3683 ** a legal notice, here is a blessing:
3684 **
3685 ** May you do good and not evil.
3686 ** May you find forgiveness for yourself and forgive others.
3687 ** May you share freely, never taking more than you give.
3688 **
3689 ******************************************************************************
3690 **
3691 */
3692 SQLITE_EXTENSION_INIT1
3693 #include <stdio.h>
3694 #include <string.h>
3695 #include <assert.h>
3696
3697 #include <sys/types.h>
3698 #include <sys/stat.h>
3699 #include <fcntl.h>
3700 #if !defined(_WIN32) && !defined(WIN32)
3701 # include <unistd.h>
3702 # include <dirent.h>
3703 # include <utime.h>
3704 #else
3705 # include <io.h>
3706 #endif
3707 #include <time.h>
3708 #include <errno.h>
3709
3710 #include <zlib.h>
3711
3712 #ifndef SQLITE_OMIT_VIRTUALTABLE
3713
3714 #ifndef SQLITE_AMALGAMATION
3715 /* typedef sqlite3_int64 i64; */
3716 /* typedef unsigned char u8; */
3717 typedef unsigned short u16;
3718 typedef unsigned long u32;
3719 #define MIN(a,b) ((a)<(b) ? (a) : (b))
3720 #endif
3721
3722 #define ZIPFILE_SCHEMA "CREATE TABLE y(" \
3723 "name, /* Name of file in zip archive */" \
3724 "mode, /* POSIX mode for file */" \
3725 "mtime, /* Last modification time in seconds since epoch */" \
3726 "sz, /* Size of object */" \
3727 "data, /* Data stored in zip file (possibly compressed) */" \
3728 "method, /* Compression method (integer) */" \
3729 "f HIDDEN /* Name of zip file */" \
3730 ");"
3731
3732 #define ZIPFILE_F_COLUMN_IDX 6 /* Index of column "f" in the above */
3733 #define ZIPFILE_BUFFER_SIZE (64*1024)
3734
3735
3736 /*
3737 ** Magic numbers used to read and write zip files.
3738 **
3739 ** ZIPFILE_NEWENTRY_MADEBY:
3740 ** Use this value for the "version-made-by" field in new zip file
3741 ** entries. The upper byte indicates "unix", and the lower byte
3742 ** indicates that the zip file matches pkzip specification 3.0.
3743 ** This is what info-zip seems to do.
3744 **
3745 ** ZIPFILE_NEWENTRY_REQUIRED:
3746 ** Value for "version-required-to-extract" field of new entries.
3747 ** Version 2.0 is required to support folders and deflate compression.
3748 **
3749 ** ZIPFILE_NEWENTRY_FLAGS:
3750 ** Value for "general-purpose-bit-flags" field of new entries. Bit
3751 ** 11 means "utf-8 filename and comment".
3752 **
3753 ** ZIPFILE_SIGNATURE_CDS:
3754 ** First 4 bytes of a valid CDS record.
3755 **
3756 ** ZIPFILE_SIGNATURE_LFH:
3757 ** First 4 bytes of a valid LFH record.
3758 */
3759 #define ZIPFILE_EXTRA_TIMESTAMP 0x5455
3760 #define ZIPFILE_NEWENTRY_MADEBY ((3<<8) + 30)
3761 #define ZIPFILE_NEWENTRY_REQUIRED 20
3762 #define ZIPFILE_NEWENTRY_FLAGS 0x800
3763 #define ZIPFILE_SIGNATURE_CDS 0x02014b50
3764 #define ZIPFILE_SIGNATURE_LFH 0x04034b50
3765 #define ZIPFILE_SIGNATURE_EOCD 0x06054b50
3766 #define ZIPFILE_LFH_FIXED_SZ 30
3767
3768 /*
3769 ** Set the error message contained in context ctx to the results of
3770 ** vprintf(zFmt, ...).
3771 */
3772 static void zipfileCtxErrorMsg(sqlite3_context *ctx, const char *zFmt, ...){
3773 char *zMsg = 0;
3774 va_list ap;
3775 va_start(ap, zFmt);
3776 zMsg = sqlite3_vmprintf(zFmt, ap);
3777 sqlite3_result_error(ctx, zMsg, -1);
3778 sqlite3_free(zMsg);
3779 va_end(ap);
3780 }
3781
3782
3783 /*
3784 *** 4.3.16 End of central directory record:
3785 ***
3786 *** end of central dir signature 4 bytes (0x06054b50)
3787 *** number of this disk 2 bytes
3788 *** number of the disk with the
3789 *** start of the central directory 2 bytes
3790 *** total number of entries in the
3791 *** central directory on this disk 2 bytes
3792 *** total number of entries in
3793 *** the central directory 2 bytes
3794 *** size of the central directory 4 bytes
3795 *** offset of start of central
3796 *** directory with respect to
3797 *** the starting disk number 4 bytes
3798 *** .ZIP file comment length 2 bytes
3799 *** .ZIP file comment (variable size)
3800 */
3801 typedef struct ZipfileEOCD ZipfileEOCD;
3802 struct ZipfileEOCD {
3803 u16 iDisk;
3804 u16 iFirstDisk;
3805 u16 nEntry;
3806 u16 nEntryTotal;
3807 u32 nSize;
3808 u32 iOffset;
3809 };
3810
3811 /*
3812 *** 4.3.12 Central directory structure:
3813 ***
3814 *** ...
3815 ***
3816 *** central file header signature 4 bytes (0x02014b50)
3817 *** version made by 2 bytes
3818 *** version needed to extract 2 bytes
3819 *** general purpose bit flag 2 bytes
3820 *** compression method 2 bytes
3821 *** last mod file time 2 bytes
3822 *** last mod file date 2 bytes
3823 *** crc-32 4 bytes
3824 *** compressed size 4 bytes
3825 *** uncompressed size 4 bytes
3826 *** file name length 2 bytes
3827 *** extra field length 2 bytes
3828 *** file comment length 2 bytes
3829 *** disk number start 2 bytes
3830 *** internal file attributes 2 bytes
3831 *** external file attributes 4 bytes
3832 *** relative offset of local header 4 bytes
3833 */
3834 typedef struct ZipfileCDS ZipfileCDS;
3835 struct ZipfileCDS {
3836 u16 iVersionMadeBy;
3837 u16 iVersionExtract;
3838 u16 flags;
3839 u16 iCompression;
3840 u16 mTime;
3841 u16 mDate;
3842 u32 crc32;
3843 u32 szCompressed;
3844 u32 szUncompressed;
3845 u16 nFile;
3846 u16 nExtra;
3847 u16 nComment;
3848 u16 iDiskStart;
3849 u16 iInternalAttr;
3850 u32 iExternalAttr;
3851 u32 iOffset;
3852 char *zFile; /* Filename (sqlite3_malloc()) */
3853 };
3854
3855 /*
3856 *** 4.3.7 Local file header:
3857 ***
3858 *** local file header signature 4 bytes (0x04034b50)
3859 *** version needed to extract 2 bytes
3860 *** general purpose bit flag 2 bytes
3861 *** compression method 2 bytes
3862 *** last mod file time 2 bytes
3863 *** last mod file date 2 bytes
3864 *** crc-32 4 bytes
3865 *** compressed size 4 bytes
3866 *** uncompressed size 4 bytes
3867 *** file name length 2 bytes
3868 *** extra field length 2 bytes
3869 ***
3870 */
3871 typedef struct ZipfileLFH ZipfileLFH;
3872 struct ZipfileLFH {
3873 u16 iVersionExtract;
3874 u16 flags;
3875 u16 iCompression;
3876 u16 mTime;
3877 u16 mDate;
3878 u32 crc32;
3879 u32 szCompressed;
3880 u32 szUncompressed;
3881 u16 nFile;
3882 u16 nExtra;
3883 };
3884
3885 typedef struct ZipfileEntry ZipfileEntry;
3886 struct ZipfileEntry {
3887 char *zPath; /* Path of zipfile entry */
3888 i64 iRowid; /* Rowid for this value if queried */
3889 u8 *aCdsEntry; /* Buffer containing entire CDS entry */
3890 int nCdsEntry; /* Size of buffer aCdsEntry[] in bytes */
3891 int bDeleted; /* True if entry has been deleted */
3892 ZipfileEntry *pNext; /* Next element in in-memory CDS */
3893 };
3894
3895 /*
3896 ** Cursor type for recursively iterating through a directory structure.
3897 */
3898 typedef struct ZipfileCsr ZipfileCsr;
3899 struct ZipfileCsr {
3900 sqlite3_vtab_cursor base; /* Base class - must be first */
3901 int bEof; /* True when at EOF */
3902
3903 /* Used outside of write transactions */
3904 FILE *pFile; /* Zip file */
3905 i64 iNextOff; /* Offset of next record in central directory */
3906 ZipfileEOCD eocd; /* Parse of central directory record */
3907
3908 /* Used inside write transactions */
3909 ZipfileEntry *pCurrent;
3910
3911 ZipfileCDS cds; /* Central Directory Structure */
3912 ZipfileLFH lfh; /* Local File Header for current entry */
3913 i64 iDataOff; /* Offset in zipfile to data */
3914 u32 mTime; /* Extended mtime value */
3915 int flags; /* Flags byte (see below for bits) */
3916 ZipfileCsr *pCsrNext; /* Next cursor on same virtual table */
3917 };
3918
3919 /*
3920 ** Values for ZipfileCsr.flags.
3921 */
3922 #define ZIPFILE_MTIME_VALID 0x0001
3923
3924 typedef struct ZipfileTab ZipfileTab;
3925 struct ZipfileTab {
3926 sqlite3_vtab base; /* Base class - must be first */
3927 char *zFile; /* Zip file this table accesses (may be NULL) */
3928 u8 *aBuffer; /* Temporary buffer used for various tasks */
3929
3930 /* The following are used by write transactions only */
3931 ZipfileCsr *pCsrList; /* List of cursors */
3932 ZipfileEntry *pFirstEntry; /* Linked list of all files (if pWriteFd!=0) */
3933 ZipfileEntry *pLastEntry; /* Last element in pFirstEntry list */
3934 FILE *pWriteFd; /* File handle open on zip archive */
3935 i64 szCurrent; /* Current size of zip archive */
3936 i64 szOrig; /* Size of archive at start of transaction */
3937 };
3938
3939 static void zipfileDequote(char *zIn){
3940 char q = zIn[0];
3941 if( q=='"' || q=='\'' || q=='`' || q=='[' ){
3942 char c;
3943 int iIn = 1;
3944 int iOut = 0;
3945 if( q=='[' ) q = ']';
3946 while( (c = zIn[iIn++]) ){
3947 if( c==q ){
3948 if( zIn[iIn++]!=q ) break;
3949 }
3950 zIn[iOut++] = c;
3951 }
3952 zIn[iOut] = '\0';
3953 }
3954 }
3955
3956 /*
3957 ** Construct a new ZipfileTab virtual table object.
3958 **
3959 ** argv[0] -> module name ("zipfile")
3960 ** argv[1] -> database name
3961 ** argv[2] -> table name
3962 ** argv[...] -> "column name" and other module argument fields.
3963 */
3964 static int zipfileConnect(
3965 sqlite3 *db,
3966 void *pAux,
3967 int argc, const char *const*argv,
3968 sqlite3_vtab **ppVtab,
3969 char **pzErr
3970 ){
3971 int nByte = sizeof(ZipfileTab) + ZIPFILE_BUFFER_SIZE;
3972 int nFile = 0;
3973 const char *zFile = 0;
3974 ZipfileTab *pNew = 0;
3975 int rc;
3976
3977 if( argc>3 ){
3978 zFile = argv[3];
3979 nFile = (int)strlen(zFile)+1;
3980 }
3981
3982 rc = sqlite3_declare_vtab(db, ZIPFILE_SCHEMA);
3983 if( rc==SQLITE_OK ){
3984 pNew = (ZipfileTab*)sqlite3_malloc(nByte+nFile);
3985 if( pNew==0 ) return SQLITE_NOMEM;
3986 memset(pNew, 0, nByte+nFile);
3987 pNew->aBuffer = (u8*)&pNew[1];
3988 if( zFile ){
3989 pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
3990 memcpy(pNew->zFile, zFile, nFile);
3991 zipfileDequote(pNew->zFile);
3992 }
3993 }
3994 *ppVtab = (sqlite3_vtab*)pNew;
3995 return rc;
3996 }
3997
3998 /*
3999 ** This method is the destructor for zipfile vtab objects.
4000 */
4001 static int zipfileDisconnect(sqlite3_vtab *pVtab){
4002 sqlite3_free(pVtab);
4003 return SQLITE_OK;
4004 }
4005
4006 /*
4007 ** Constructor for a new ZipfileCsr object.
4008 */
4009 static int zipfileOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCsr){
4010 ZipfileCsr *pCsr;
4011 pCsr = sqlite3_malloc(sizeof(*pCsr));
4012 *ppCsr = (sqlite3_vtab_cursor*)pCsr;
4013 if( pCsr==0 ){
4014 return SQLITE_NOMEM;
4015 }
4016 memset(pCsr, 0, sizeof(*pCsr));
4017 return SQLITE_OK;
4018 }
4019
4020 /*
4021 ** Reset a cursor back to the state it was in when first returned
4022 ** by zipfileOpen().
4023 */
4024 static void zipfileResetCursor(ZipfileCsr *pCsr){
4025 ZipfileTab *pTab = (ZipfileTab*)(pCsr->base.pVtab);
4026 ZipfileCsr **pp;
4027
4028 /* Remove this cursor from the ZipfileTab.pCsrList list. */
4029 for(pp=&pTab->pCsrList; *pp; pp=&((*pp)->pCsrNext)){
4030 if( *pp==pCsr ) *pp = pCsr->pCsrNext;
4031 }
4032
4033 sqlite3_free(pCsr->cds.zFile);
4034 pCsr->cds.zFile = 0;
4035 pCsr->bEof = 0;
4036 if( pCsr->pFile ){
4037 fclose(pCsr->pFile);
4038 pCsr->pFile = 0;
4039 }
4040 }
4041
4042 /*
4043 ** Destructor for an ZipfileCsr.
4044 */
4045 static int zipfileClose(sqlite3_vtab_cursor *cur){
4046 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4047 zipfileResetCursor(pCsr);
4048 sqlite3_free(pCsr);
4049 return SQLITE_OK;
4050 }
4051
4052 /*
4053 ** Set the error message for the virtual table associated with cursor
4054 ** pCsr to the results of vprintf(zFmt, ...).
4055 */
4056 static void zipfileSetErrmsg(ZipfileCsr *pCsr, const char *zFmt, ...){
4057 va_list ap;
4058 va_start(ap, zFmt);
4059 pCsr->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
4060 va_end(ap);
4061 }
4062
4063 static int zipfileReadData(
4064 FILE *pFile, /* Read from this file */
4065 u8 *aRead, /* Read into this buffer */
4066 int nRead, /* Number of bytes to read */
4067 i64 iOff, /* Offset to read from */
4068 char **pzErrmsg /* OUT: Error message (from sqlite3_malloc) */
4069 ){
4070 size_t n;
4071 fseek(pFile, (long)iOff, SEEK_SET);
4072 n = fread(aRead, 1, nRead, pFile);
4073 if( (int)n!=nRead ){
4074 *pzErrmsg = sqlite3_mprintf("error in fread()");
4075 return SQLITE_ERROR;
4076 }
4077 return SQLITE_OK;
4078 }
4079
4080 static int zipfileAppendData(
4081 ZipfileTab *pTab,
4082 const u8 *aWrite,
4083 int nWrite
4084 ){
4085 size_t n;
4086 fseek(pTab->pWriteFd, (long)pTab->szCurrent, SEEK_SET);
4087 n = fwrite(aWrite, 1, nWrite, pTab->pWriteFd);
4088 if( (int)n!=nWrite ){
4089 pTab->base.zErrMsg = sqlite3_mprintf("error in fwrite()");
4090 return SQLITE_ERROR;
4091 }
4092 pTab->szCurrent += nWrite;
4093 return SQLITE_OK;
4094 }
4095
4096 static u16 zipfileGetU16(const u8 *aBuf){
4097 return (aBuf[1] << 8) + aBuf[0];
4098 }
4099 static u32 zipfileGetU32(const u8 *aBuf){
4100 return ((u32)(aBuf[3]) << 24)
4101 + ((u32)(aBuf[2]) << 16)
4102 + ((u32)(aBuf[1]) << 8)
4103 + ((u32)(aBuf[0]) << 0);
4104 }
4105
4106 static void zipfilePutU16(u8 *aBuf, u16 val){
4107 aBuf[0] = val & 0xFF;
4108 aBuf[1] = (val>>8) & 0xFF;
4109 }
4110 static void zipfilePutU32(u8 *aBuf, u32 val){
4111 aBuf[0] = val & 0xFF;
4112 aBuf[1] = (val>>8) & 0xFF;
4113 aBuf[2] = (val>>16) & 0xFF;
4114 aBuf[3] = (val>>24) & 0xFF;
4115 }
4116
4117 #define zipfileRead32(aBuf) ( aBuf+=4, zipfileGetU32(aBuf-4) )
4118 #define zipfileRead16(aBuf) ( aBuf+=2, zipfileGetU16(aBuf-2) )
4119
4120 #define zipfileWrite32(aBuf,val) { zipfilePutU32(aBuf,val); aBuf+=4; }
4121 #define zipfileWrite16(aBuf,val) { zipfilePutU16(aBuf,val); aBuf+=2; }
4122
4123 static u8* zipfileCsrBuffer(ZipfileCsr *pCsr){
4124 return ((ZipfileTab*)(pCsr->base.pVtab))->aBuffer;
4125 }
4126
4127 /*
4128 ** Magic numbers used to read CDS records.
4129 */
4130 #define ZIPFILE_CDS_FIXED_SZ 46
4131 #define ZIPFILE_CDS_NFILE_OFF 28
4132
4133 static int zipfileReadCDS(ZipfileCsr *pCsr){
4134 char **pzErr = &pCsr->base.pVtab->zErrMsg;
4135 u8 *aRead;
4136 int rc = SQLITE_OK;
4137
4138 sqlite3_free(pCsr->cds.zFile);
4139 pCsr->cds.zFile = 0;
4140
4141 if( pCsr->pCurrent==0 ){
4142 aRead = zipfileCsrBuffer(pCsr);
4143 rc = zipfileReadData(
4144 pCsr->pFile, aRead, ZIPFILE_CDS_FIXED_SZ, pCsr->iNextOff, pzErr
4145 );
4146 }else{
4147 aRead = pCsr->pCurrent->aCdsEntry;
4148 }
4149
4150 if( rc==SQLITE_OK ){
4151 u32 sig = zipfileRead32(aRead);
4152 if( sig!=ZIPFILE_SIGNATURE_CDS ){
4153 assert( pCsr->pCurrent==0 );
4154 zipfileSetErrmsg(pCsr,"failed to read CDS at offset %lld",pCsr->iNextOff);
4155 rc = SQLITE_ERROR;
4156 }else{
4157 int nRead;
4158 pCsr->cds.iVersionMadeBy = zipfileRead16(aRead);
4159 pCsr->cds.iVersionExtract = zipfileRead16(aRead);
4160 pCsr->cds.flags = zipfileRead16(aRead);
4161 pCsr->cds.iCompression = zipfileRead16(aRead);
4162 pCsr->cds.mTime = zipfileRead16(aRead);
4163 pCsr->cds.mDate = zipfileRead16(aRead);
4164 pCsr->cds.crc32 = zipfileRead32(aRead);
4165 pCsr->cds.szCompressed = zipfileRead32(aRead);
4166 pCsr->cds.szUncompressed = zipfileRead32(aRead);
4167 assert( pCsr->pCurrent
4168 || aRead==zipfileCsrBuffer(pCsr)+ZIPFILE_CDS_NFILE_OFF
4169 );
4170 pCsr->cds.nFile = zipfileRead16(aRead);
4171 pCsr->cds.nExtra = zipfileRead16(aRead);
4172 pCsr->cds.nComment = zipfileRead16(aRead);
4173 pCsr->cds.iDiskStart = zipfileRead16(aRead);
4174 pCsr->cds.iInternalAttr = zipfileRead16(aRead);
4175 pCsr->cds.iExternalAttr = zipfileRead32(aRead);
4176 pCsr->cds.iOffset = zipfileRead32(aRead);
4177 assert( pCsr->pCurrent
4178 || aRead==zipfileCsrBuffer(pCsr)+ZIPFILE_CDS_FIXED_SZ
4179 );
4180
4181 if( pCsr->pCurrent==0 ){
4182 nRead = pCsr->cds.nFile + pCsr->cds.nExtra;
4183 aRead = zipfileCsrBuffer(pCsr);
4184 pCsr->iNextOff += ZIPFILE_CDS_FIXED_SZ;
4185 rc = zipfileReadData(pCsr->pFile, aRead, nRead, pCsr->iNextOff, pzErr);
4186 }
4187
4188 if( rc==SQLITE_OK ){
4189 pCsr->cds.zFile = sqlite3_mprintf("%.*s", (int)pCsr->cds.nFile, aRead);
4190 pCsr->iNextOff += pCsr->cds.nFile;
4191 pCsr->iNextOff += pCsr->cds.nExtra;
4192 pCsr->iNextOff += pCsr->cds.nComment;
4193 }
4194
4195 /* Scan the cds.nExtra bytes of "extra" fields for any that can
4196 ** be interpreted. The general format of an extra field is:
4197 **
4198 ** Header ID 2 bytes
4199 ** Data Size 2 bytes
4200 ** Data N bytes
4201 **
4202 */
4203 if( rc==SQLITE_OK ){
4204 u8 *p = &aRead[pCsr->cds.nFile];
4205 u8 *pEnd = &p[pCsr->cds.nExtra];
4206
4207 while( p<pEnd ){
4208 u16 id = zipfileRead16(p);
4209 u16 nByte = zipfileRead16(p);
4210
4211 switch( id ){
4212 case ZIPFILE_EXTRA_TIMESTAMP: {
4213 u8 b = p[0];
4214 if( b & 0x01 ){ /* 0x01 -> modtime is present */
4215 pCsr->mTime = zipfileGetU32(&p[1]);
4216 pCsr->flags |= ZIPFILE_MTIME_VALID;
4217 }
4218 break;
4219 }
4220 }
4221
4222 p += nByte;
4223 }
4224 }
4225 }
4226 }
4227
4228 return rc;
4229 }
4230
4231 static FILE *zipfileGetFd(ZipfileCsr *pCsr){
4232 if( pCsr->pFile ) return pCsr->pFile;
4233 return ((ZipfileTab*)(pCsr->base.pVtab))->pWriteFd;
4234 }
4235
4236 static int zipfileReadLFH(ZipfileCsr *pCsr){
4237 FILE *pFile = zipfileGetFd(pCsr);
4238 char **pzErr = &pCsr->base.pVtab->zErrMsg;
4239 static const int szFix = ZIPFILE_LFH_FIXED_SZ;
4240 u8 *aRead = zipfileCsrBuffer(pCsr);
4241 int rc;
4242
4243 rc = zipfileReadData(pFile, aRead, szFix, pCsr->cds.iOffset, pzErr);
4244 if( rc==SQLITE_OK ){
4245 u32 sig = zipfileRead32(aRead);
4246 if( sig!=ZIPFILE_SIGNATURE_LFH ){
4247 zipfileSetErrmsg(pCsr, "failed to read LFH at offset %d",
4248 (int)pCsr->cds.iOffset
4249 );
4250 rc = SQLITE_ERROR;
4251 }else{
4252 pCsr->lfh.iVersionExtract = zipfileRead16(aRead);
4253 pCsr->lfh.flags = zipfileRead16(aRead);
4254 pCsr->lfh.iCompression = zipfileRead16(aRead);
4255 pCsr->lfh.mTime = zipfileRead16(aRead);
4256 pCsr->lfh.mDate = zipfileRead16(aRead);
4257 pCsr->lfh.crc32 = zipfileRead32(aRead);
4258 pCsr->lfh.szCompressed = zipfileRead32(aRead);
4259 pCsr->lfh.szUncompressed = zipfileRead32(aRead);
4260 pCsr->lfh.nFile = zipfileRead16(aRead);
4261 pCsr->lfh.nExtra = zipfileRead16(aRead);
4262 assert( aRead==zipfileCsrBuffer(pCsr)+szFix );
4263 pCsr->iDataOff = pCsr->cds.iOffset+szFix+pCsr->lfh.nFile+pCsr->lfh.nExtra;
4264 }
4265 }
4266
4267 return rc;
4268 }
4269
4270
4271 /*
4272 ** Advance an ZipfileCsr to its next row of output.
4273 */
4274 static int zipfileNext(sqlite3_vtab_cursor *cur){
4275 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4276 int rc = SQLITE_OK;
4277 pCsr->flags = 0;
4278
4279 if( pCsr->pCurrent==0 ){
4280 i64 iEof = pCsr->eocd.iOffset + pCsr->eocd.nSize;
4281 if( pCsr->iNextOff>=iEof ){
4282 pCsr->bEof = 1;
4283 }
4284 }else{
4285 assert( pCsr->pFile==0 );
4286 do {
4287 pCsr->pCurrent = pCsr->pCurrent->pNext;
4288 }while( pCsr->pCurrent && pCsr->pCurrent->bDeleted );
4289 if( pCsr->pCurrent==0 ){
4290 pCsr->bEof = 1;
4291 }
4292 }
4293
4294 if( pCsr->bEof==0 ){
4295 rc = zipfileReadCDS(pCsr);
4296 if( rc==SQLITE_OK ){
4297 rc = zipfileReadLFH(pCsr);
4298 }
4299 }
4300
4301 return rc;
4302 }
4303
4304 /*
4305 ** "Standard" MS-DOS time format:
4306 **
4307 ** File modification time:
4308 ** Bits 00-04: seconds divided by 2
4309 ** Bits 05-10: minute
4310 ** Bits 11-15: hour
4311 ** File modification date:
4312 ** Bits 00-04: day
4313 ** Bits 05-08: month (1-12)
4314 ** Bits 09-15: years from 1980
4315 */
4316 static time_t zipfileMtime(ZipfileCsr *pCsr){
4317 struct tm t;
4318 memset(&t, 0, sizeof(t));
4319 t.tm_sec = (pCsr->cds.mTime & 0x1F)*2;
4320 t.tm_min = (pCsr->cds.mTime >> 5) & 0x2F;
4321 t.tm_hour = (pCsr->cds.mTime >> 11) & 0x1F;
4322
4323 t.tm_mday = (pCsr->cds.mDate & 0x1F);
4324 t.tm_mon = ((pCsr->cds.mDate >> 5) & 0x0F) - 1;
4325 t.tm_year = 80 + ((pCsr->cds.mDate >> 9) & 0x7F);
4326
4327 return mktime(&t);
4328 }
4329
4330 static void zipfileMtimeToDos(ZipfileCDS *pCds, u32 mTime){
4331 time_t t = (time_t)mTime;
4332 struct tm res;
4333
4334 #if !defined(_WIN32) && !defined(WIN32)
4335 localtime_r(&t, &res);
4336 #else
4337 memcpy(&res, localtime(&t), sizeof(struct tm));
4338 #endif
4339
4340 pCds->mTime = (u16)(
4341 (res.tm_sec / 2) +
4342 (res.tm_min << 5) +
4343 (res.tm_hour << 11));
4344
4345 pCds->mDate = (u16)(
4346 (res.tm_mday-1) +
4347 ((res.tm_mon+1) << 5) +
4348 ((res.tm_year-80) << 9));
4349 }
4350
4351 /*
4352 ** Return values of columns for the row at which the series_cursor
4353 ** is currently pointing.
4354 */
4355 static int zipfileColumn(
4356 sqlite3_vtab_cursor *cur, /* The cursor */
4357 sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
4358 int i /* Which column to return */
4359 ){
4360 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4361 int rc = SQLITE_OK;
4362 switch( i ){
4363 case 0: /* name */
4364 sqlite3_result_text(ctx, pCsr->cds.zFile, -1, SQLITE_TRANSIENT);
4365 break;
4366 case 1: /* mode */
4367 /* TODO: Whether or not the following is correct surely depends on
4368 ** the platform on which the archive was created. */
4369 sqlite3_result_int(ctx, pCsr->cds.iExternalAttr >> 16);
4370 break;
4371 case 2: { /* mtime */
4372 if( pCsr->flags & ZIPFILE_MTIME_VALID ){
4373 sqlite3_result_int64(ctx, pCsr->mTime);
4374 }else{
4375 sqlite3_result_int64(ctx, zipfileMtime(pCsr));
4376 }
4377 break;
4378 }
4379 case 3: { /* sz */
4380 sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
4381 break;
4382 }
4383 case 4: { /* data */
4384 int sz = pCsr->cds.szCompressed;
4385 if( sz>0 ){
4386 u8 *aBuf = sqlite3_malloc(sz);
4387 if( aBuf==0 ){
4388 rc = SQLITE_NOMEM;
4389 }else{
4390 FILE *pFile = zipfileGetFd(pCsr);
4391 rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff,
4392 &pCsr->base.pVtab->zErrMsg
4393 );
4394 }
4395 if( rc==SQLITE_OK ){
4396 sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
4397 sqlite3_free(aBuf);
4398 }
4399 }
4400 break;
4401 }
4402 case 5: /* method */
4403 sqlite3_result_int(ctx, pCsr->cds.iCompression);
4404 break;
4405 }
4406
4407 return SQLITE_OK;
4408 }
4409
4410 /*
4411 ** Return the rowid for the current row.
4412 */
4413 static int zipfileRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
4414 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4415 if( pCsr->pCurrent ){
4416 *pRowid = pCsr->pCurrent->iRowid;
4417 }else{
4418 *pRowid = pCsr->cds.iOffset;
4419 }
4420 return SQLITE_OK;
4421 }
4422
4423 /*
4424 ** Return TRUE if the cursor has been moved off of the last
4425 ** row of output.
4426 */
4427 static int zipfileEof(sqlite3_vtab_cursor *cur){
4428 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4429 return pCsr->bEof;
4430 }
4431
4432 /*
4433 */
4434 static int zipfileReadEOCD(
4435 ZipfileTab *pTab, /* Return errors here */
4436 FILE *pFile, /* Read from this file */
4437 ZipfileEOCD *pEOCD /* Object to populate */
4438 ){
4439 u8 *aRead = pTab->aBuffer; /* Temporary buffer */
4440 i64 szFile; /* Total size of file in bytes */
4441 int nRead; /* Bytes to read from file */
4442 i64 iOff; /* Offset to read from */
4443 int rc;
4444
4445 fseek(pFile, 0, SEEK_END);
4446 szFile = (i64)ftell(pFile);
4447 if( szFile==0 ){
4448 return SQLITE_EMPTY;
4449 }
4450 nRead = (int)(MIN(szFile, ZIPFILE_BUFFER_SIZE));
4451 iOff = szFile - nRead;
4452
4453 rc = zipfileReadData(pFile, aRead, nRead, iOff, &pTab->base.zErrMsg);
4454 if( rc==SQLITE_OK ){
4455 int i;
4456
4457 /* Scan backwards looking for the signature bytes */
4458 for(i=nRead-20; i>=0; i--){
4459 if( aRead[i]==0x50 && aRead[i+1]==0x4b
4460 && aRead[i+2]==0x05 && aRead[i+3]==0x06
4461 ){
4462 break;
4463 }
4464 }
4465 if( i<0 ){
4466 pTab->base.zErrMsg = sqlite3_mprintf(
4467 "cannot find end of central directory record"
4468 );
4469 return SQLITE_ERROR;
4470 }
4471
4472 aRead += i+4;
4473 pEOCD->iDisk = zipfileRead16(aRead);
4474 pEOCD->iFirstDisk = zipfileRead16(aRead);
4475 pEOCD->nEntry = zipfileRead16(aRead);
4476 pEOCD->nEntryTotal = zipfileRead16(aRead);
4477 pEOCD->nSize = zipfileRead32(aRead);
4478 pEOCD->iOffset = zipfileRead32(aRead);
4479
4480 #if 0
4481 printf("iDisk=%d iFirstDisk=%d nEntry=%d "
4482 "nEntryTotal=%d nSize=%d iOffset=%d",
4483 (int)pEOCD->iDisk, (int)pEOCD->iFirstDisk, (int)pEOCD->nEntry,
4484 (int)pEOCD->nEntryTotal, (int)pEOCD->nSize, (int)pEOCD->iOffset
4485 );
4486 #endif
4487 }
4488
4489 return SQLITE_OK;
4490 }
4491
4492 /*
4493 ** xFilter callback.
4494 */
4495 static int zipfileFilter(
4496 sqlite3_vtab_cursor *cur,
4497 int idxNum, const char *idxStr,
4498 int argc, sqlite3_value **argv
4499 ){
4500 ZipfileTab *pTab = (ZipfileTab*)cur->pVtab;
4501 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
4502 const char *zFile; /* Zip file to scan */
4503 int rc = SQLITE_OK; /* Return Code */
4504
4505 zipfileResetCursor(pCsr);
4506
4507 if( pTab->zFile ){
4508 zFile = pTab->zFile;
4509 }else if( idxNum==0 ){
4510 /* Error. This is an eponymous virtual table and the user has not
4511 ** supplied a file name. */
4512 zipfileSetErrmsg(pCsr, "table function zipfile() requires an argument");
4513 return SQLITE_ERROR;
4514 }else{
4515 zFile = (const char*)sqlite3_value_text(argv[0]);
4516 }
4517
4518 if( pTab->pWriteFd==0 ){
4519 pCsr->pFile = fopen(zFile, "rb");
4520 if( pCsr->pFile==0 ){
4521 zipfileSetErrmsg(pCsr, "cannot open file: %s", zFile);
4522 rc = SQLITE_ERROR;
4523 }else{
4524 rc = zipfileReadEOCD(pTab, pCsr->pFile, &pCsr->eocd);
4525 if( rc==SQLITE_OK ){
4526 pCsr->iNextOff = pCsr->eocd.iOffset;
4527 rc = zipfileNext(cur);
4528 }else if( rc==SQLITE_EMPTY ){
4529 rc = SQLITE_OK;
4530 pCsr->bEof = 1;
4531 }
4532 }
4533 }else{
4534 ZipfileEntry e;
4535 memset(&e, 0, sizeof(e));
4536 e.pNext = pTab->pFirstEntry;
4537 pCsr->pCurrent = &e;
4538 rc = zipfileNext(cur);
4539 assert( pCsr->pCurrent!=&e );
4540 }
4541
4542 return rc;
4543 }
4544
4545 /*
4546 ** xBestIndex callback.
4547 */
4548 static int zipfileBestIndex(
4549 sqlite3_vtab *tab,
4550 sqlite3_index_info *pIdxInfo
4551 ){
4552 int i;
4553
4554 for(i=0; i<pIdxInfo->nConstraint; i++){
4555 const struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
4556 if( pCons->usable==0 ) continue;
4557 if( pCons->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
4558 if( pCons->iColumn!=ZIPFILE_F_COLUMN_IDX ) continue;
4559 break;
4560 }
4561
4562 if( i<pIdxInfo->nConstraint ){
4563 pIdxInfo->aConstraintUsage[i].argvIndex = 1;
4564 pIdxInfo->aConstraintUsage[i].omit = 1;
4565 pIdxInfo->estimatedCost = 1000.0;
4566 pIdxInfo->idxNum = 1;
4567 }else{
4568 pIdxInfo->estimatedCost = (double)(((sqlite3_int64)1) << 50);
4569 pIdxInfo->idxNum = 0;
4570 }
4571
4572 return SQLITE_OK;
4573 }
4574
4575 /*
4576 ** Add object pNew to the end of the linked list that begins at
4577 ** ZipfileTab.pFirstEntry and ends with pLastEntry.
4578 */
4579 static void zipfileAddEntry(ZipfileTab *pTab, ZipfileEntry *pNew){
4580 assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
4581 assert( pNew->pNext==0 );
4582 if( pTab->pFirstEntry==0 ){
4583 pNew->iRowid = 1;
4584 pTab->pFirstEntry = pTab->pLastEntry = pNew;
4585 }else{
4586 assert( pTab->pLastEntry->pNext==0 );
4587 pNew->iRowid = pTab->pLastEntry->iRowid+1;
4588 pTab->pLastEntry->pNext = pNew;
4589 pTab->pLastEntry = pNew;
4590 }
4591 }
4592
4593 static int zipfileLoadDirectory(ZipfileTab *pTab){
4594 ZipfileEOCD eocd;
4595 int rc;
4596
4597 rc = zipfileReadEOCD(pTab, pTab->pWriteFd, &eocd);
4598 if( rc==SQLITE_OK ){
4599 int i;
4600 int iOff = 0;
4601 u8 *aBuf = sqlite3_malloc(eocd.nSize);
4602 if( aBuf==0 ){
4603 rc = SQLITE_NOMEM;
4604 }else{
4605 rc = zipfileReadData(
4606 pTab->pWriteFd, aBuf, eocd.nSize, eocd.iOffset, &pTab->base.zErrMsg
4607 );
4608 }
4609
4610 for(i=0; rc==SQLITE_OK && i<eocd.nEntry; i++){
4611 u16 nFile;
4612 u16 nExtra;
4613 u16 nComment;
4614 ZipfileEntry *pNew;
4615 u8 *aRec = &aBuf[iOff];
4616
4617 nFile = zipfileGetU16(&aRec[ZIPFILE_CDS_NFILE_OFF]);
4618 nExtra = zipfileGetU16(&aRec[ZIPFILE_CDS_NFILE_OFF+2]);
4619 nComment = zipfileGetU16(&aRec[ZIPFILE_CDS_NFILE_OFF+4]);
4620
4621 pNew = sqlite3_malloc(
4622 sizeof(ZipfileEntry)
4623 + nFile+1
4624 + ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment
4625 );
4626 if( pNew==0 ){
4627 rc = SQLITE_NOMEM;
4628 }else{
4629 memset(pNew, 0, sizeof(ZipfileEntry));
4630 pNew->zPath = (char*)&pNew[1];
4631 memcpy(pNew->zPath, &aBuf[ZIPFILE_CDS_FIXED_SZ], nFile);
4632 pNew->zPath[nFile] = '\0';
4633 pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
4634 pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
4635 memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
4636 zipfileAddEntry(pTab, pNew);
4637 }
4638
4639 iOff += ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
4640 }
4641
4642 sqlite3_free(aBuf);
4643 }else if( rc==SQLITE_EMPTY ){
4644 rc = SQLITE_OK;
4645 }
4646
4647 return rc;
4648 }
4649
4650 static ZipfileEntry *zipfileNewEntry(
4651 ZipfileCDS *pCds, /* Values for fixed size part of CDS */
4652 const char *zPath, /* Path for new entry */
4653 int nPath, /* strlen(zPath) */
4654 u32 mTime /* Modification time (or 0) */
4655 ){
4656 u8 *aWrite;
4657 ZipfileEntry *pNew;
4658 pCds->nFile = (u16)nPath;
4659 pCds->nExtra = mTime ? 9 : 0;
4660 pNew = (ZipfileEntry*)sqlite3_malloc(
4661 sizeof(ZipfileEntry) +
4662 nPath+1 +
4663 ZIPFILE_CDS_FIXED_SZ + nPath + pCds->nExtra
4664 );
4665
4666 if( pNew ){
4667 memset(pNew, 0, sizeof(ZipfileEntry));
4668 pNew->zPath = (char*)&pNew[1];
4669 pNew->aCdsEntry = (u8*)&pNew->zPath[nPath+1];
4670 pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ + nPath + pCds->nExtra;
4671 memcpy(pNew->zPath, zPath, nPath+1);
4672
4673 aWrite = pNew->aCdsEntry;
4674 zipfileWrite32(aWrite, ZIPFILE_SIGNATURE_CDS);
4675 zipfileWrite16(aWrite, pCds->iVersionMadeBy);
4676 zipfileWrite16(aWrite, pCds->iVersionExtract);
4677 zipfileWrite16(aWrite, pCds->flags);
4678 zipfileWrite16(aWrite, pCds->iCompression);
4679 zipfileWrite16(aWrite, pCds->mTime);
4680 zipfileWrite16(aWrite, pCds->mDate);
4681 zipfileWrite32(aWrite, pCds->crc32);
4682 zipfileWrite32(aWrite, pCds->szCompressed);
4683 zipfileWrite32(aWrite, pCds->szUncompressed);
4684 zipfileWrite16(aWrite, pCds->nFile);
4685 zipfileWrite16(aWrite, pCds->nExtra);
4686 zipfileWrite16(aWrite, pCds->nComment); assert( pCds->nComment==0 );
4687 zipfileWrite16(aWrite, pCds->iDiskStart);
4688 zipfileWrite16(aWrite, pCds->iInternalAttr);
4689 zipfileWrite32(aWrite, pCds->iExternalAttr);
4690 zipfileWrite32(aWrite, pCds->iOffset);
4691 assert( aWrite==&pNew->aCdsEntry[ZIPFILE_CDS_FIXED_SZ] );
4692 memcpy(aWrite, zPath, nPath);
4693 if( pCds->nExtra ){
4694 aWrite += nPath;
4695 zipfileWrite16(aWrite, ZIPFILE_EXTRA_TIMESTAMP);
4696 zipfileWrite16(aWrite, 5);
4697 *aWrite++ = 0x01;
4698 zipfileWrite32(aWrite, mTime);
4699 }
4700 }
4701
4702 return pNew;
4703 }
4704
4705 static int zipfileAppendEntry(
4706 ZipfileTab *pTab,
4707 ZipfileCDS *pCds,
4708 const char *zPath, /* Path for new entry */
4709 int nPath, /* strlen(zPath) */
4710 const u8 *pData,
4711 int nData,
4712 u32 mTime
4713 ){
4714 u8 *aBuf = pTab->aBuffer;
4715 int rc;
4716
4717 zipfileWrite32(aBuf, ZIPFILE_SIGNATURE_LFH);
4718 zipfileWrite16(aBuf, pCds->iVersionExtract);
4719 zipfileWrite16(aBuf, pCds->flags);
4720 zipfileWrite16(aBuf, pCds->iCompression);
4721 zipfileWrite16(aBuf, pCds->mTime);
4722 zipfileWrite16(aBuf, pCds->mDate);
4723 zipfileWrite32(aBuf, pCds->crc32);
4724 zipfileWrite32(aBuf, pCds->szCompressed);
4725 zipfileWrite32(aBuf, pCds->szUncompressed);
4726 zipfileWrite16(aBuf, (u16)nPath);
4727 zipfileWrite16(aBuf, pCds->nExtra);
4728 assert( aBuf==&pTab->aBuffer[ZIPFILE_LFH_FIXED_SZ] );
4729 rc = zipfileAppendData(pTab, pTab->aBuffer, (int)(aBuf - pTab->aBuffer));
4730 if( rc==SQLITE_OK ){
4731 rc = zipfileAppendData(pTab, (const u8*)zPath, nPath);
4732 }
4733
4734 if( rc==SQLITE_OK && pCds->nExtra ){
4735 aBuf = pTab->aBuffer;
4736 zipfileWrite16(aBuf, ZIPFILE_EXTRA_TIMESTAMP);
4737 zipfileWrite16(aBuf, 5);
4738 *aBuf++ = 0x01;
4739 zipfileWrite32(aBuf, mTime);
4740 rc = zipfileAppendData(pTab, pTab->aBuffer, 9);
4741 }
4742
4743 if( rc==SQLITE_OK ){
4744 rc = zipfileAppendData(pTab, pData, nData);
4745 }
4746
4747 return rc;
4748 }
4749
4750 static int zipfileGetMode(ZipfileTab *pTab, sqlite3_value *pVal, int *pMode){
4751 const char *z = (const char*)sqlite3_value_text(pVal);
4752 int mode = 0;
4753 if( z==0 || (z[0]>=0 && z[0]<=9) ){
4754 mode = sqlite3_value_int(pVal);
4755 }else{
4756 const char zTemplate[11] = "-rwxrwxrwx";
4757 int i;
4758 if( strlen(z)!=10 ) goto parse_error;
4759 switch( z[0] ){
4760 case '-': mode |= S_IFREG; break;
4761 case 'd': mode |= S_IFDIR; break;
4762 #if !defined(_WIN32) && !defined(WIN32)
4763 case 'l': mode |= S_IFLNK; break;
4764 #endif
4765 default: goto parse_error;
4766 }
4767 for(i=1; i<10; i++){
4768 if( z[i]==zTemplate[i] ) mode |= 1 << (9-i);
4769 else if( z[i]!='-' ) goto parse_error;
4770 }
4771 }
4772 *pMode = mode;
4773 return SQLITE_OK;
4774
4775 parse_error:
4776 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: parse error in mode: %s", z);
4777 return SQLITE_ERROR;
4778 }
4779
4780 /*
4781 ** xUpdate method.
4782 */
4783 static int zipfileUpdate(
4784 sqlite3_vtab *pVtab,
4785 int nVal,
4786 sqlite3_value **apVal,
4787 sqlite_int64 *pRowid
4788 ){
4789 ZipfileTab *pTab = (ZipfileTab*)pVtab;
4790 int rc = SQLITE_OK; /* Return Code */
4791 ZipfileEntry *pNew = 0; /* New in-memory CDS entry */
4792
4793 int mode; /* Mode for new entry */
4794 i64 mTime; /* Modification time for new entry */
4795 i64 sz; /* Uncompressed size */
4796 const char *zPath; /* Path for new entry */
4797 int nPath; /* strlen(zPath) */
4798 const u8 *pData; /* Pointer to buffer containing content */
4799 int nData; /* Size of pData buffer in bytes */
4800 int iMethod = 0; /* Compression method for new entry */
4801 u8 *pFree = 0; /* Free this */
4802 ZipfileCDS cds; /* New Central Directory Structure entry */
4803
4804 assert( pTab->zFile );
4805 assert( pTab->pWriteFd );
4806
4807 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
4808 i64 iDelete = sqlite3_value_int64(apVal[0]);
4809 ZipfileEntry *p;
4810 for(p=pTab->pFirstEntry; p; p=p->pNext){
4811 if( p->iRowid==iDelete ){
4812 p->bDeleted = 1;
4813 break;
4814 }
4815 }
4816 if( nVal==1 ) return SQLITE_OK;
4817 }
4818
4819 zPath = (const char*)sqlite3_value_text(apVal[2]);
4820 nPath = (int)strlen(zPath);
4821 rc = zipfileGetMode(pTab, apVal[3], &mode);
4822 if( rc!=SQLITE_OK ) return rc;
4823 mTime = sqlite3_value_int64(apVal[4]);
4824 sz = sqlite3_value_int(apVal[5]);
4825 pData = sqlite3_value_blob(apVal[6]);
4826 nData = sqlite3_value_bytes(apVal[6]);
4827
4828 /* If a NULL value is inserted into the 'method' column, do automatic
4829 ** compression. */
4830 if( nData>0 && sqlite3_value_type(apVal[7])==SQLITE_NULL ){
4831 pFree = (u8*)sqlite3_malloc(nData);
4832 if( pFree==0 ){
4833 rc = SQLITE_NOMEM;
4834 }else{
4835 int res;
4836 z_stream str;
4837 memset(&str, 0, sizeof(str));
4838 str.next_in = (z_const Bytef*)pData;
4839 str.avail_in = nData;
4840 str.next_out = pFree;
4841 str.avail_out = nData;
4842 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
4843 res = deflate(&str, Z_FINISH);
4844 if( res==Z_STREAM_END ){
4845 pData = pFree;
4846 nData = str.total_out;
4847 iMethod = 8;
4848 }else if( res!=Z_OK ){
4849 pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error");
4850 rc = SQLITE_ERROR;
4851 }
4852 deflateEnd(&str);
4853 }
4854 }else{
4855 iMethod = sqlite3_value_int(apVal[7]);
4856 if( iMethod<0 || iMethod>65535 ){
4857 pTab->base.zErrMsg = sqlite3_mprintf(
4858 "zipfile: invalid compression method: %d", iMethod
4859 );
4860 rc = SQLITE_ERROR;
4861 }
4862 }
4863
4864 if( rc==SQLITE_OK ){
4865 /* Create the new CDS record. */
4866 memset(&cds, 0, sizeof(cds));
4867 cds.iVersionMadeBy = ZIPFILE_NEWENTRY_MADEBY;
4868 cds.iVersionExtract = ZIPFILE_NEWENTRY_REQUIRED;
4869 cds.flags = ZIPFILE_NEWENTRY_FLAGS;
4870 cds.iCompression = (u16)iMethod;
4871 zipfileMtimeToDos(&cds, (u32)mTime);
4872 cds.crc32 = crc32(0, pData, nData);
4873 cds.szCompressed = nData;
4874 cds.szUncompressed = (u32)sz;
4875 cds.iExternalAttr = (mode<<16);
4876 cds.iOffset = (u32)pTab->szCurrent;
4877 pNew = zipfileNewEntry(&cds, zPath, nPath, (u32)mTime);
4878 if( pNew==0 ){
4879 rc = SQLITE_NOMEM;
4880 }else{
4881 zipfileAddEntry(pTab, pNew);
4882 }
4883 }
4884
4885 /* Append the new header+file to the archive */
4886 if( rc==SQLITE_OK ){
4887 rc = zipfileAppendEntry(pTab, &cds, zPath, nPath, pData, nData, (u32)mTime);
4888 }
4889
4890 sqlite3_free(pFree);
4891 return rc;
4892 }
4893
4894 static int zipfileAppendEOCD(ZipfileTab *pTab, ZipfileEOCD *p){
4895 u8 *aBuf = pTab->aBuffer;
4896
4897 zipfileWrite32(aBuf, ZIPFILE_SIGNATURE_EOCD);
4898 zipfileWrite16(aBuf, p->iDisk);
4899 zipfileWrite16(aBuf, p->iFirstDisk);
4900 zipfileWrite16(aBuf, p->nEntry);
4901 zipfileWrite16(aBuf, p->nEntryTotal);
4902 zipfileWrite32(aBuf, p->nSize);
4903 zipfileWrite32(aBuf, p->iOffset);
4904 zipfileWrite16(aBuf, 0); /* Size of trailing comment in bytes*/
4905
4906 assert( (aBuf-pTab->aBuffer)==22 );
4907 return zipfileAppendData(pTab, pTab->aBuffer, (int)(aBuf - pTab->aBuffer));
4908 }
4909
4910 static void zipfileCleanupTransaction(ZipfileTab *pTab){
4911 ZipfileEntry *pEntry;
4912 ZipfileEntry *pNext;
4913
4914 for(pEntry=pTab->pFirstEntry; pEntry; pEntry=pNext){
4915 pNext = pEntry->pNext;
4916 sqlite3_free(pEntry);
4917 }
4918 pTab->pFirstEntry = 0;
4919 pTab->pLastEntry = 0;
4920 fclose(pTab->pWriteFd);
4921 pTab->pWriteFd = 0;
4922 pTab->szCurrent = 0;
4923 pTab->szOrig = 0;
4924 }
4925
4926 static int zipfileBegin(sqlite3_vtab *pVtab){
4927 ZipfileTab *pTab = (ZipfileTab*)pVtab;
4928 int rc = SQLITE_OK;
4929
4930 assert( pTab->pWriteFd==0 );
4931
4932 /* This table is only writable if a default archive path was specified
4933 ** as part of the CREATE VIRTUAL TABLE statement. */
4934 if( pTab->zFile==0 ){
4935 pTab->base.zErrMsg = sqlite3_mprintf(
4936 "zipfile: writing requires a default archive"
4937 );
4938 return SQLITE_ERROR;
4939 }
4940
4941 /* Open a write fd on the file. Also load the entire central directory
4942 ** structure into memory. During the transaction any new file data is
4943 ** appended to the archive file, but the central directory is accumulated
4944 ** in main-memory until the transaction is committed. */
4945 pTab->pWriteFd = fopen(pTab->zFile, "ab+");
4946 if( pTab->pWriteFd==0 ){
4947 pTab->base.zErrMsg = sqlite3_mprintf(
4948 "zipfile: failed to open file %s for writing", pTab->zFile
4949 );
4950 rc = SQLITE_ERROR;
4951 }else{
4952 fseek(pTab->pWriteFd, 0, SEEK_END);
4953 pTab->szCurrent = pTab->szOrig = (i64)ftell(pTab->pWriteFd);
4954 rc = zipfileLoadDirectory(pTab);
4955 }
4956
4957 if( rc!=SQLITE_OK ){
4958 zipfileCleanupTransaction(pTab);
4959 }
4960
4961 return rc;
4962 }
4963
4964 static int zipfileCommit(sqlite3_vtab *pVtab){
4965 ZipfileTab *pTab = (ZipfileTab*)pVtab;
4966 int rc = SQLITE_OK;
4967 if( pTab->pWriteFd ){
4968 i64 iOffset = pTab->szCurrent;
4969 ZipfileEntry *p;
4970 ZipfileEOCD eocd;
4971 int nEntry = 0;
4972
4973 /* Write out all undeleted entries */
4974 for(p=pTab->pFirstEntry; rc==SQLITE_OK && p; p=p->pNext){
4975 if( p->bDeleted ) continue;
4976 rc = zipfileAppendData(pTab, p->aCdsEntry, p->nCdsEntry);
4977 nEntry++;
4978 }
4979
4980 /* Write out the EOCD record */
4981 eocd.iDisk = 0;
4982 eocd.iFirstDisk = 0;
4983 eocd.nEntry = (u16)nEntry;
4984 eocd.nEntryTotal = (u16)nEntry;
4985 eocd.nSize = (u32)(pTab->szCurrent - iOffset);
4986 eocd.iOffset = (u32)iOffset;
4987 rc = zipfileAppendEOCD(pTab, &eocd);
4988
4989 zipfileCleanupTransaction(pTab);
4990 }
4991 return rc;
4992 }
4993
4994 static int zipfileRollback(sqlite3_vtab *pVtab){
4995 return zipfileCommit(pVtab);
4996 }
4997
4998 /*
4999 ** Register the "zipfile" virtual table.
5000 */
5001 static int zipfileRegister(sqlite3 *db){
5002 static sqlite3_module zipfileModule = {
5003 1, /* iVersion */
5004 zipfileConnect, /* xCreate */
5005 zipfileConnect, /* xConnect */
5006 zipfileBestIndex, /* xBestIndex */
5007 zipfileDisconnect, /* xDisconnect */
5008 zipfileDisconnect, /* xDestroy */
5009 zipfileOpen, /* xOpen - open a cursor */
5010 zipfileClose, /* xClose - close a cursor */
5011 zipfileFilter, /* xFilter - configure scan constraints */
5012 zipfileNext, /* xNext - advance a cursor */
5013 zipfileEof, /* xEof - check for end of scan */
5014 zipfileColumn, /* xColumn - read data */
5015 zipfileRowid, /* xRowid - read data */
5016 zipfileUpdate, /* xUpdate */
5017 zipfileBegin, /* xBegin */
5018 0, /* xSync */
5019 zipfileCommit, /* xCommit */
5020 zipfileRollback, /* xRollback */
5021 0, /* xFindMethod */
5022 0, /* xRename */
5023 };
5024
5025 int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0);
5026 return rc;
5027 }
5028 #else /* SQLITE_OMIT_VIRTUALTABLE */
5029 # define zipfileRegister(x) SQLITE_OK
5030 #endif
5031
5032 /*
5033 ** zipfile_uncompress(DATA, SZ, METHOD)
5034 */
5035 static void zipfileUncompressFunc(
5036 sqlite3_context *context,
5037 int argc,
5038 sqlite3_value **argv
5039 ){
5040 int iMethod;
5041
5042 iMethod = sqlite3_value_int(argv[2]);
5043 if( iMethod==0 ){
5044 sqlite3_result_value(context, argv[0]);
5045 }else if( iMethod==8 ){
5046 Byte *res;
5047 int sz = sqlite3_value_int(argv[1]);
5048 z_stream str;
5049 memset(&str, 0, sizeof(str));
5050 str.next_in = (Byte*)sqlite3_value_blob(argv[0]);
5051 str.avail_in = sqlite3_value_bytes(argv[0]);
5052 res = str.next_out = (Byte*)sqlite3_malloc(sz);
5053 if( res==0 ){
5054 sqlite3_result_error_nomem(context);
5055 }else{
5056 int err;
5057 str.avail_out = sz;
5058
5059 err = inflateInit2(&str, -15);
5060 if( err!=Z_OK ){
5061 zipfileCtxErrorMsg(context, "inflateInit2() failed (%d)", err);
5062 }else{
5063 err = inflate(&str, Z_NO_FLUSH);
5064 if( err!=Z_STREAM_END ){
5065 zipfileCtxErrorMsg(context, "inflate() failed (%d)", err);
5066 }else{
5067 sqlite3_result_blob(context, res, sz, SQLITE_TRANSIENT);
5068 }
5069 }
5070 sqlite3_free(res);
5071 inflateEnd(&str);
5072 }
5073 }else{
5074 zipfileCtxErrorMsg(context, "unrecognized compression method: %d", iMethod);
5075 }
5076 }
5077
5078 #ifdef _WIN32
5079
5080 #endif
5081 int sqlite3_zipfile_init(
5082 sqlite3 *db,
5083 char **pzErrMsg,
5084 const sqlite3_api_routines *pApi
5085 ){
5086 int rc = SQLITE_OK;
5087 SQLITE_EXTENSION_INIT2(pApi);
5088 (void)pzErrMsg; /* Unused parameter */
5089 rc = sqlite3_create_function(db, "zipfile_uncompress", 3,
5090 SQLITE_UTF8, 0, zipfileUncompressFunc, 0, 0
5091 );
5092 if( rc!=SQLITE_OK ) return rc;
5093 return zipfileRegister(db);
5094 }
5095
5096
5097 /************************* End ../ext/misc/zipfile.c ********************/
5098 /************************* Begin ../ext/misc/sqlar.c ******************/
5099 /*
5100 ** 2017-12-17
5101 **
5102 ** The author disclaims copyright to this source code. In place of
5103 ** a legal notice, here is a blessing:
5104 **
5105 ** May you do good and not evil.
5106 ** May you find forgiveness for yourself and forgive others.
5107 ** May you share freely, never taking more than you give.
5108 **
5109 ******************************************************************************
5110 **
5111 ** Utility functions sqlar_compress() and sqlar_uncompress(). Useful
5112 ** for working with sqlar archives and used by the shell tool's built-in
5113 ** sqlar support.
5114 */
5115 SQLITE_EXTENSION_INIT1
5116 #include <zlib.h>
5117
5118 /*
5119 ** Implementation of the "sqlar_compress(X)" SQL function.
5120 **
5121 ** If the type of X is SQLITE_BLOB, and compressing that blob using
5122 ** zlib utility function compress() yields a smaller blob, return the
5123 ** compressed blob. Otherwise, return a copy of X.
5124 **
5125 ** SQLar uses the "zlib format" for compressed content. The zlib format
5126 ** contains a two-byte identification header and a four-byte checksum at
5127 ** the end. This is different from ZIP which uses the raw deflate format.
5128 **
5129 ** Future enhancements to SQLar might add support for new compression formats.
5130 ** If so, those new formats will be identified by alternative headers in the
5131 ** compressed data.
5132 */
5133 static void sqlarCompressFunc(
5134 sqlite3_context *context,
5135 int argc,
5136 sqlite3_value **argv
5137 ){
5138 assert( argc==1 );
5139 if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
5140 const Bytef *pData = sqlite3_value_blob(argv[0]);
5141 uLong nData = sqlite3_value_bytes(argv[0]);
5142 uLongf nOut = compressBound(nData);
5143 Bytef *pOut;
5144
5145 pOut = (Bytef*)sqlite3_malloc(nOut);
5146 if( pOut==0 ){
5147 sqlite3_result_error_nomem(context);
5148 return;
5149 }else{
5150 if( Z_OK!=compress(pOut, &nOut, pData, nData) ){
5151 sqlite3_result_error(context, "error in compress()", -1);
5152 }else if( nOut<nData ){
5153 sqlite3_result_blob(context, pOut, nOut, SQLITE_TRANSIENT);
5154 }else{
5155 sqlite3_result_value(context, argv[0]);
5156 }
5157 sqlite3_free(pOut);
5158 }
5159 }else{
5160 sqlite3_result_value(context, argv[0]);
5161 }
5162 }
5163
5164 /*
5165 ** Implementation of the "sqlar_uncompress(X,SZ)" SQL function
5166 **
5167 ** Parameter SZ is interpreted as an integer. If it is less than or
5168 ** equal to zero, then this function returns a copy of X. Or, if
5169 ** SZ is equal to the size of X when interpreted as a blob, also
5170 ** return a copy of X. Otherwise, decompress blob X using zlib
5171 ** utility function uncompress() and return the results (another
5172 ** blob).
5173 */
5174 static void sqlarUncompressFunc(
5175 sqlite3_context *context,
5176 int argc,
5177 sqlite3_value **argv
5178 ){
5179 uLong nData;
5180 uLongf sz;
5181
5182 assert( argc==2 );
5183 sz = sqlite3_value_int(argv[1]);
5184
5185 if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){
5186 sqlite3_result_value(context, argv[0]);
5187 }else{
5188 const Bytef *pData= sqlite3_value_blob(argv[0]);
5189 Bytef *pOut = sqlite3_malloc(sz);
5190 if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){
5191 sqlite3_result_error(context, "error in uncompress()", -1);
5192 }else{
5193 sqlite3_result_blob(context, pOut, sz, SQLITE_TRANSIENT);
5194 }
5195 sqlite3_free(pOut);
5196 }
5197 }
5198
5199
5200 #ifdef _WIN32
5201
5202 #endif
5203 int sqlite3_sqlar_init(
5204 sqlite3 *db,
5205 char **pzErrMsg,
5206 const sqlite3_api_routines *pApi
5207 ){
5208 int rc = SQLITE_OK;
5209 SQLITE_EXTENSION_INIT2(pApi);
5210 (void)pzErrMsg; /* Unused parameter */
5211 rc = sqlite3_create_function(db, "sqlar_compress", 1, SQLITE_UTF8, 0,
5212 sqlarCompressFunc, 0, 0);
5213 if( rc==SQLITE_OK ){
5214 rc = sqlite3_create_function(db, "sqlar_uncompress", 2, SQLITE_UTF8, 0,
5215 sqlarUncompressFunc, 0, 0);
5216 }
5217 return rc;
5218 }
5219
5220 /************************* End ../ext/misc/sqlar.c ********************/
5221 #endif
5222 /************************* Begin ../ext/expert/sqlite3expert.h ******************/
5223 /*
5224 ** 2017 April 07
5225 **
5226 ** The author disclaims copyright to this source code. In place of
5227 ** a legal notice, here is a blessing:
5228 **
5229 ** May you do good and not evil.
5230 ** May you find forgiveness for yourself and forgive others.
5231 ** May you share freely, never taking more than you give.
5232 **
5233 *************************************************************************
5234 */
5235
5236
5237
5238 typedef struct sqlite3expert sqlite3expert;
5239
5240 /*
5241 ** Create a new sqlite3expert object.
5242 **
5243 ** If successful, a pointer to the new object is returned and (*pzErr) set
5244 ** to NULL. Or, if an error occurs, NULL is returned and (*pzErr) set to
5245 ** an English-language error message. In this case it is the responsibility
5246 ** of the caller to eventually free the error message buffer using
5247 ** sqlite3_free().
5248 */
5249 sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErr);
5250
5251 /*
5252 ** Configure an sqlite3expert object.
5253 **
5254 ** EXPERT_CONFIG_SAMPLE:
5255 ** By default, sqlite3_expert_analyze() generates sqlite_stat1 data for
5256 ** each candidate index. This involves scanning and sorting the entire
5257 ** contents of each user database table once for each candidate index
5258 ** associated with the table. For large databases, this can be
5259 ** prohibitively slow. This option allows the sqlite3expert object to
5260 ** be configured so that sqlite_stat1 data is instead generated based on a
5261 ** subset of each table, or so that no sqlite_stat1 data is used at all.
5262 **
5263 ** A single integer argument is passed to this option. If the value is less
5264 ** than or equal to zero, then no sqlite_stat1 data is generated or used by
5265 ** the analysis - indexes are recommended based on the database schema only.
5266 ** Or, if the value is 100 or greater, complete sqlite_stat1 data is
5267 ** generated for each candidate index (this is the default). Finally, if the
5268 ** value falls between 0 and 100, then it represents the percentage of user
5269 ** table rows that should be considered when generating sqlite_stat1 data.
5270 **
5271 ** Examples:
5272 **
5273 ** // Do not generate any sqlite_stat1 data
5274 ** sqlite3_expert_config(pExpert, EXPERT_CONFIG_SAMPLE, 0);
5275 **
5276 ** // Generate sqlite_stat1 data based on 10% of the rows in each table.
5277 ** sqlite3_expert_config(pExpert, EXPERT_CONFIG_SAMPLE, 10);
5278 */
5279 int sqlite3_expert_config(sqlite3expert *p, int op, ...);
5280
5281 #define EXPERT_CONFIG_SAMPLE 1 /* int */
5282
5283 /*
5284 ** Specify zero or more SQL statements to be included in the analysis.
5285 **
5286 ** Buffer zSql must contain zero or more complete SQL statements. This
5287 ** function parses all statements contained in the buffer and adds them
5288 ** to the internal list of statements to analyze. If successful, SQLITE_OK
5289 ** is returned and (*pzErr) set to NULL. Or, if an error occurs - for example
5290 ** due to a error in the SQL - an SQLite error code is returned and (*pzErr)
5291 ** may be set to point to an English language error message. In this case
5292 ** the caller is responsible for eventually freeing the error message buffer
5293 ** using sqlite3_free().
5294 **
5295 ** If an error does occur while processing one of the statements in the
5296 ** buffer passed as the second argument, none of the statements in the
5297 ** buffer are added to the analysis.
5298 **
5299 ** This function must be called before sqlite3_expert_analyze(). If a call
5300 ** to this function is made on an sqlite3expert object that has already
5301 ** been passed to sqlite3_expert_analyze() SQLITE_MISUSE is returned
5302 ** immediately and no statements are added to the analysis.
5303 */
5304 int sqlite3_expert_sql(
5305 sqlite3expert *p, /* From a successful sqlite3_expert_new() */
5306 const char *zSql, /* SQL statement(s) to add */
5307 char **pzErr /* OUT: Error message (if any) */
5308 );
5309
5310
5311 /*
5312 ** This function is called after the sqlite3expert object has been configured
5313 ** with all SQL statements using sqlite3_expert_sql() to actually perform
5314 ** the analysis. Once this function has been called, it is not possible to
5315 ** add further SQL statements to the analysis.
5316 **
5317 ** If successful, SQLITE_OK is returned and (*pzErr) is set to NULL. Or, if
5318 ** an error occurs, an SQLite error code is returned and (*pzErr) set to
5319 ** point to a buffer containing an English language error message. In this
5320 ** case it is the responsibility of the caller to eventually free the buffer
5321 ** using sqlite3_free().
5322 **
5323 ** If an error does occur within this function, the sqlite3expert object
5324 ** is no longer useful for any purpose. At that point it is no longer
5325 ** possible to add further SQL statements to the object or to re-attempt
5326 ** the analysis. The sqlite3expert object must still be freed using a call
5327 ** sqlite3_expert_destroy().
5328 */
5329 int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr);
5330
5331 /*
5332 ** Return the total number of statements loaded using sqlite3_expert_sql().
5333 ** The total number of SQL statements may be different from the total number
5334 ** to calls to sqlite3_expert_sql().
5335 */
5336 int sqlite3_expert_count(sqlite3expert*);
5337
5338 /*
5339 ** Return a component of the report.
5340 **
5341 ** This function is called after sqlite3_expert_analyze() to extract the
5342 ** results of the analysis. Each call to this function returns either a
5343 ** NULL pointer or a pointer to a buffer containing a nul-terminated string.
5344 ** The value passed as the third argument must be one of the EXPERT_REPORT_*
5345 ** #define constants defined below.
5346 **
5347 ** For some EXPERT_REPORT_* parameters, the buffer returned contains
5348 ** information relating to a specific SQL statement. In these cases that
5349 ** SQL statement is identified by the value passed as the second argument.
5350 ** SQL statements are numbered from 0 in the order in which they are parsed.
5351 ** If an out-of-range value (less than zero or equal to or greater than the
5352 ** value returned by sqlite3_expert_count()) is passed as the second argument
5353 ** along with such an EXPERT_REPORT_* parameter, NULL is always returned.
5354 **
5355 ** EXPERT_REPORT_SQL:
5356 ** Return the text of SQL statement iStmt.
5357 **
5358 ** EXPERT_REPORT_INDEXES:
5359 ** Return a buffer containing the CREATE INDEX statements for all recommended
5360 ** indexes for statement iStmt. If there are no new recommeded indexes, NULL
5361 ** is returned.
5362 **
5363 ** EXPERT_REPORT_PLAN:
5364 ** Return a buffer containing the EXPLAIN QUERY PLAN output for SQL query
5365 ** iStmt after the proposed indexes have been added to the database schema.
5366 **
5367 ** EXPERT_REPORT_CANDIDATES:
5368 ** Return a pointer to a buffer containing the CREATE INDEX statements
5369 ** for all indexes that were tested (for all SQL statements). The iStmt
5370 ** parameter is ignored for EXPERT_REPORT_CANDIDATES calls.
5371 */
5372 const char *sqlite3_expert_report(sqlite3expert*, int iStmt, int eReport);
5373
5374 /*
5375 ** Values for the third argument passed to sqlite3_expert_report().
5376 */
5377 #define EXPERT_REPORT_SQL 1
5378 #define EXPERT_REPORT_INDEXES 2
5379 #define EXPERT_REPORT_PLAN 3
5380 #define EXPERT_REPORT_CANDIDATES 4
5381
5382 /*
5383 ** Free an (sqlite3expert*) handle and all associated resources. There
5384 ** should be one call to this function for each successful call to
5385 ** sqlite3-expert_new().
5386 */
5387 void sqlite3_expert_destroy(sqlite3expert*);
5388
5389
5390
5391 /************************* End ../ext/expert/sqlite3expert.h ********************/
5392 /************************* Begin ../ext/expert/sqlite3expert.c ******************/
5393 /*
5394 ** 2017 April 09
5395 **
5396 ** The author disclaims copyright to this source code. In place of
5397 ** a legal notice, here is a blessing:
5398 **
5399 ** May you do good and not evil.
5400 ** May you find forgiveness for yourself and forgive others.
5401 ** May you share freely, never taking more than you give.
5402 **
5403 *************************************************************************
5404 */
5405 #include <assert.h>
5406 #include <string.h>
5407 #include <stdio.h>
5408
5409 /* typedef sqlite3_int64 i64; */
5410 /* typedef sqlite3_uint64 u64; */
5411
5412 typedef struct IdxColumn IdxColumn;
5413 typedef struct IdxConstraint IdxConstraint;
5414 typedef struct IdxScan IdxScan;
5415 typedef struct IdxStatement IdxStatement;
5416 typedef struct IdxTable IdxTable;
5417 typedef struct IdxWrite IdxWrite;
5418
5419 #define STRLEN (int)strlen
5420
5421 /*
5422 ** A temp table name that we assume no user database will actually use.
5423 ** If this assumption proves incorrect triggers on the table with the
5424 ** conflicting name will be ignored.
5425 */
5426 #define UNIQUE_TABLE_NAME "t592690916721053953805701627921227776"
5427
5428 /*
5429 ** A single constraint. Equivalent to either "col = ?" or "col < ?" (or
5430 ** any other type of single-ended range constraint on a column).
5431 **
5432 ** pLink:
5433 ** Used to temporarily link IdxConstraint objects into lists while
5434 ** creating candidate indexes.
5435 */
5436 struct IdxConstraint {
5437 char *zColl; /* Collation sequence */
5438 int bRange; /* True for range, false for eq */
5439 int iCol; /* Constrained table column */
5440 int bFlag; /* Used by idxFindCompatible() */
5441 int bDesc; /* True if ORDER BY <expr> DESC */
5442 IdxConstraint *pNext; /* Next constraint in pEq or pRange list */
5443 IdxConstraint *pLink; /* See above */
5444 };
5445
5446 /*
5447 ** A single scan of a single table.
5448 */
5449 struct IdxScan {
5450 IdxTable *pTab; /* Associated table object */
5451 int iDb; /* Database containing table zTable */
5452 i64 covering; /* Mask of columns required for cov. index */
5453 IdxConstraint *pOrder; /* ORDER BY columns */
5454 IdxConstraint *pEq; /* List of == constraints */
5455 IdxConstraint *pRange; /* List of < constraints */
5456 IdxScan *pNextScan; /* Next IdxScan object for same analysis */
5457 };
5458
5459 /*
5460 ** Information regarding a single database table. Extracted from
5461 ** "PRAGMA table_info" by function idxGetTableInfo().
5462 */
5463 struct IdxColumn {
5464 char *zName;
5465 char *zColl;
5466 int iPk;
5467 };
5468 struct IdxTable {
5469 int nCol;
5470 char *zName; /* Table name */
5471 IdxColumn *aCol;
5472 IdxTable *pNext; /* Next table in linked list of all tables */
5473 };
5474
5475 /*
5476 ** An object of the following type is created for each unique table/write-op
5477 ** seen. The objects are stored in a singly-linked list beginning at
5478 ** sqlite3expert.pWrite.
5479 */
5480 struct IdxWrite {
5481 IdxTable *pTab;
5482 int eOp; /* SQLITE_UPDATE, DELETE or INSERT */
5483 IdxWrite *pNext;
5484 };
5485
5486 /*
5487 ** Each statement being analyzed is represented by an instance of this
5488 ** structure.
5489 */
5490 struct IdxStatement {
5491 int iId; /* Statement number */
5492 char *zSql; /* SQL statement */
5493 char *zIdx; /* Indexes */
5494 char *zEQP; /* Plan */
5495 IdxStatement *pNext;
5496 };
5497
5498
5499 /*
5500 ** A hash table for storing strings. With space for a payload string
5501 ** with each entry. Methods are:
5502 **
5503 ** idxHashInit()
5504 ** idxHashClear()
5505 ** idxHashAdd()
5506 ** idxHashSearch()
5507 */
5508 #define IDX_HASH_SIZE 1023
5509 typedef struct IdxHashEntry IdxHashEntry;
5510 typedef struct IdxHash IdxHash;
5511 struct IdxHashEntry {
5512 char *zKey; /* nul-terminated key */
5513 char *zVal; /* nul-terminated value string */
5514 char *zVal2; /* nul-terminated value string 2 */
5515 IdxHashEntry *pHashNext; /* Next entry in same hash bucket */
5516 IdxHashEntry *pNext; /* Next entry in hash */
5517 };
5518 struct IdxHash {
5519 IdxHashEntry *pFirst;
5520 IdxHashEntry *aHash[IDX_HASH_SIZE];
5521 };
5522
5523 /*
5524 ** sqlite3expert object.
5525 */
5526 struct sqlite3expert {
5527 int iSample; /* Percentage of tables to sample for stat1 */
5528 sqlite3 *db; /* User database */
5529 sqlite3 *dbm; /* In-memory db for this analysis */
5530 sqlite3 *dbv; /* Vtab schema for this analysis */
5531 IdxTable *pTable; /* List of all IdxTable objects */
5532 IdxScan *pScan; /* List of scan objects */
5533 IdxWrite *pWrite; /* List of write objects */
5534 IdxStatement *pStatement; /* List of IdxStatement objects */
5535 int bRun; /* True once analysis has run */
5536 char **pzErrmsg;
5537 int rc; /* Error code from whereinfo hook */
5538 IdxHash hIdx; /* Hash containing all candidate indexes */
5539 char *zCandidates; /* For EXPERT_REPORT_CANDIDATES */
5540 };
5541
5542
5543 /*
5544 ** Allocate and return nByte bytes of zeroed memory using sqlite3_malloc().
5545 ** If the allocation fails, set *pRc to SQLITE_NOMEM and return NULL.
5546 */
5547 static void *idxMalloc(int *pRc, int nByte){
5548 void *pRet;
5549 assert( *pRc==SQLITE_OK );
5550 assert( nByte>0 );
5551 pRet = sqlite3_malloc(nByte);
5552 if( pRet ){
5553 memset(pRet, 0, nByte);
5554 }else{
5555 *pRc = SQLITE_NOMEM;
5556 }
5557 return pRet;
5558 }
5559
5560 /*
5561 ** Initialize an IdxHash hash table.
5562 */
5563 static void idxHashInit(IdxHash *pHash){
5564 memset(pHash, 0, sizeof(IdxHash));
5565 }
5566
5567 /*
5568 ** Reset an IdxHash hash table.
5569 */
5570 static void idxHashClear(IdxHash *pHash){
5571 int i;
5572 for(i=0; i<IDX_HASH_SIZE; i++){
5573 IdxHashEntry *pEntry;
5574 IdxHashEntry *pNext;
5575 for(pEntry=pHash->aHash[i]; pEntry; pEntry=pNext){
5576 pNext = pEntry->pHashNext;
5577 sqlite3_free(pEntry->zVal2);
5578 sqlite3_free(pEntry);
5579 }
5580 }
5581 memset(pHash, 0, sizeof(IdxHash));
5582 }
5583
5584 /*
5585 ** Return the index of the hash bucket that the string specified by the
5586 ** arguments to this function belongs.
5587 */
5588 static int idxHashString(const char *z, int n){
5589 unsigned int ret = 0;
5590 int i;
5591 for(i=0; i<n; i++){
5592 ret += (ret<<3) + (unsigned char)(z[i]);
5593 }
5594 return (int)(ret % IDX_HASH_SIZE);
5595 }
5596
5597 /*
5598 ** If zKey is already present in the hash table, return non-zero and do
5599 ** nothing. Otherwise, add an entry with key zKey and payload string zVal to
5600 ** the hash table passed as the second argument.
5601 */
5602 static int idxHashAdd(
5603 int *pRc,
5604 IdxHash *pHash,
5605 const char *zKey,
5606 const char *zVal
5607 ){
5608 int nKey = STRLEN(zKey);
5609 int iHash = idxHashString(zKey, nKey);
5610 int nVal = (zVal ? STRLEN(zVal) : 0);
5611 IdxHashEntry *pEntry;
5612 assert( iHash>=0 );
5613 for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){
5614 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){
5615 return 1;
5616 }
5617 }
5618 pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + nKey+1 + nVal+1);
5619 if( pEntry ){
5620 pEntry->zKey = (char*)&pEntry[1];
5621 memcpy(pEntry->zKey, zKey, nKey);
5622 if( zVal ){
5623 pEntry->zVal = &pEntry->zKey[nKey+1];
5624 memcpy(pEntry->zVal, zVal, nVal);
5625 }
5626 pEntry->pHashNext = pHash->aHash[iHash];
5627 pHash->aHash[iHash] = pEntry;
5628
5629 pEntry->pNext = pHash->pFirst;
5630 pHash->pFirst = pEntry;
5631 }
5632 return 0;
5633 }
5634
5635 /*
5636 ** If zKey/nKey is present in the hash table, return a pointer to the
5637 ** hash-entry object.
5638 */
5639 static IdxHashEntry *idxHashFind(IdxHash *pHash, const char *zKey, int nKey){
5640 int iHash;
5641 IdxHashEntry *pEntry;
5642 if( nKey<0 ) nKey = STRLEN(zKey);
5643 iHash = idxHashString(zKey, nKey);
5644 assert( iHash>=0 );
5645 for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){
5646 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){
5647 return pEntry;
5648 }
5649 }
5650 return 0;
5651 }
5652
5653 /*
5654 ** If the hash table contains an entry with a key equal to the string
5655 ** passed as the final two arguments to this function, return a pointer
5656 ** to the payload string. Otherwise, if zKey/nKey is not present in the
5657 ** hash table, return NULL.
5658 */
5659 static const char *idxHashSearch(IdxHash *pHash, const char *zKey, int nKey){
5660 IdxHashEntry *pEntry = idxHashFind(pHash, zKey, nKey);
5661 if( pEntry ) return pEntry->zVal;
5662 return 0;
5663 }
5664
5665 /*
5666 ** Allocate and return a new IdxConstraint object. Set the IdxConstraint.zColl
5667 ** variable to point to a copy of nul-terminated string zColl.
5668 */
5669 static IdxConstraint *idxNewConstraint(int *pRc, const char *zColl){
5670 IdxConstraint *pNew;
5671 int nColl = STRLEN(zColl);
5672
5673 assert( *pRc==SQLITE_OK );
5674 pNew = (IdxConstraint*)idxMalloc(pRc, sizeof(IdxConstraint) * nColl + 1);
5675 if( pNew ){
5676 pNew->zColl = (char*)&pNew[1];
5677 memcpy(pNew->zColl, zColl, nColl+1);
5678 }
5679 return pNew;
5680 }
5681
5682 /*
5683 ** An error associated with database handle db has just occurred. Pass
5684 ** the error message to callback function xOut.
5685 */
5686 static void idxDatabaseError(
5687 sqlite3 *db, /* Database handle */
5688 char **pzErrmsg /* Write error here */
5689 ){
5690 *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
5691 }
5692
5693 /*
5694 ** Prepare an SQL statement.
5695 */
5696 static int idxPrepareStmt(
5697 sqlite3 *db, /* Database handle to compile against */
5698 sqlite3_stmt **ppStmt, /* OUT: Compiled SQL statement */
5699 char **pzErrmsg, /* OUT: sqlite3_malloc()ed error message */
5700 const char *zSql /* SQL statement to compile */
5701 ){
5702 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
5703 if( rc!=SQLITE_OK ){
5704 *ppStmt = 0;
5705 idxDatabaseError(db, pzErrmsg);
5706 }
5707 return rc;
5708 }
5709
5710 /*
5711 ** Prepare an SQL statement using the results of a printf() formatting.
5712 */
5713 static int idxPrintfPrepareStmt(
5714 sqlite3 *db, /* Database handle to compile against */
5715 sqlite3_stmt **ppStmt, /* OUT: Compiled SQL statement */
5716 char **pzErrmsg, /* OUT: sqlite3_malloc()ed error message */
5717 const char *zFmt, /* printf() format of SQL statement */
5718 ... /* Trailing printf() arguments */
5719 ){
5720 va_list ap;
5721 int rc;
5722 char *zSql;
5723 va_start(ap, zFmt);
5724 zSql = sqlite3_vmprintf(zFmt, ap);
5725 if( zSql==0 ){
5726 rc = SQLITE_NOMEM;
5727 }else{
5728 rc = idxPrepareStmt(db, ppStmt, pzErrmsg, zSql);
5729 sqlite3_free(zSql);
5730 }
5731 va_end(ap);
5732 return rc;
5733 }
5734
5735
5736 /*************************************************************************
5737 ** Beginning of virtual table implementation.
5738 */
5739 typedef struct ExpertVtab ExpertVtab;
5740 struct ExpertVtab {
5741 sqlite3_vtab base;
5742 IdxTable *pTab;
5743 sqlite3expert *pExpert;
5744 };
5745
5746 typedef struct ExpertCsr ExpertCsr;
5747 struct ExpertCsr {
5748 sqlite3_vtab_cursor base;
5749 sqlite3_stmt *pData;
5750 };
5751
5752 static char *expertDequote(const char *zIn){
5753 int n = STRLEN(zIn);
5754 char *zRet = sqlite3_malloc(n);
5755
5756 assert( zIn[0]=='\'' );
5757 assert( zIn[n-1]=='\'' );
5758
5759 if( zRet ){
5760 int iOut = 0;
5761 int iIn = 0;
5762 for(iIn=1; iIn<(n-1); iIn++){
5763 if( zIn[iIn]=='\'' ){
5764 assert( zIn[iIn+1]=='\'' );
5765 iIn++;
5766 }
5767 zRet[iOut++] = zIn[iIn];
5768 }
5769 zRet[iOut] = '\0';
5770 }
5771
5772 return zRet;
5773 }
5774
5775 /*
5776 ** This function is the implementation of both the xConnect and xCreate
5777 ** methods of the r-tree virtual table.
5778 **
5779 ** argv[0] -> module name
5780 ** argv[1] -> database name
5781 ** argv[2] -> table name
5782 ** argv[...] -> column names...
5783 */
5784 static int expertConnect(
5785 sqlite3 *db,
5786 void *pAux,
5787 int argc, const char *const*argv,
5788 sqlite3_vtab **ppVtab,
5789 char **pzErr
5790 ){
5791 sqlite3expert *pExpert = (sqlite3expert*)pAux;
5792 ExpertVtab *p = 0;
5793 int rc;
5794
5795 if( argc!=4 ){
5796 *pzErr = sqlite3_mprintf("internal error!");
5797 rc = SQLITE_ERROR;
5798 }else{
5799 char *zCreateTable = expertDequote(argv[3]);
5800 if( zCreateTable ){
5801 rc = sqlite3_declare_vtab(db, zCreateTable);
5802 if( rc==SQLITE_OK ){
5803 p = idxMalloc(&rc, sizeof(ExpertVtab));
5804 }
5805 if( rc==SQLITE_OK ){
5806 p->pExpert = pExpert;
5807 p->pTab = pExpert->pTable;
5808 assert( sqlite3_stricmp(p->pTab->zName, argv[2])==0 );
5809 }
5810 sqlite3_free(zCreateTable);
5811 }else{
5812 rc = SQLITE_NOMEM;
5813 }
5814 }
5815
5816 *ppVtab = (sqlite3_vtab*)p;
5817 return rc;
5818 }
5819
5820 static int expertDisconnect(sqlite3_vtab *pVtab){
5821 ExpertVtab *p = (ExpertVtab*)pVtab;
5822 sqlite3_free(p);
5823 return SQLITE_OK;
5824 }
5825
5826 static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
5827 ExpertVtab *p = (ExpertVtab*)pVtab;
5828 int rc = SQLITE_OK;
5829 int n = 0;
5830 IdxScan *pScan;
5831 const int opmask =
5832 SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_GT |
5833 SQLITE_INDEX_CONSTRAINT_LT | SQLITE_INDEX_CONSTRAINT_GE |
5834 SQLITE_INDEX_CONSTRAINT_LE;
5835
5836 pScan = idxMalloc(&rc, sizeof(IdxScan));
5837 if( pScan ){
5838 int i;
5839
5840 /* Link the new scan object into the list */
5841 pScan->pTab = p->pTab;
5842 pScan->pNextScan = p->pExpert->pScan;
5843 p->pExpert->pScan = pScan;
5844
5845 /* Add the constraints to the IdxScan object */
5846 for(i=0; i<pIdxInfo->nConstraint; i++){
5847 struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
5848 if( pCons->usable
5849 && pCons->iColumn>=0
5850 && p->pTab->aCol[pCons->iColumn].iPk==0
5851 && (pCons->op & opmask)
5852 ){
5853 IdxConstraint *pNew;
5854 const char *zColl = sqlite3_vtab_collation(pIdxInfo, i);
5855 pNew = idxNewConstraint(&rc, zColl);
5856 if( pNew ){
5857 pNew->iCol = pCons->iColumn;
5858 if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
5859 pNew->pNext = pScan->pEq;
5860 pScan->pEq = pNew;
5861 }else{
5862 pNew->bRange = 1;
5863 pNew->pNext = pScan->pRange;
5864 pScan->pRange = pNew;
5865 }
5866 }
5867 n++;
5868 pIdxInfo->aConstraintUsage[i].argvIndex = n;
5869 }
5870 }
5871
5872 /* Add the ORDER BY to the IdxScan object */
5873 for(i=pIdxInfo->nOrderBy-1; i>=0; i--){
5874 int iCol = pIdxInfo->aOrderBy[i].iColumn;
5875 if( iCol>=0 ){
5876 IdxConstraint *pNew = idxNewConstraint(&rc, p->pTab->aCol[iCol].zColl);
5877 if( pNew ){
5878 pNew->iCol = iCol;
5879 pNew->bDesc = pIdxInfo->aOrderBy[i].desc;
5880 pNew->pNext = pScan->pOrder;
5881 pNew->pLink = pScan->pOrder;
5882 pScan->pOrder = pNew;
5883 n++;
5884 }
5885 }
5886 }
5887 }
5888
5889 pIdxInfo->estimatedCost = 1000000.0 / n;
5890 return rc;
5891 }
5892
5893 static int expertUpdate(
5894 sqlite3_vtab *pVtab,
5895 int nData,
5896 sqlite3_value **azData,
5897 sqlite_int64 *pRowid
5898 ){
5899 return SQLITE_OK;
5900 }
5901
5902 /*
5903 ** Virtual table module xOpen method.
5904 */
5905 static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
5906 int rc = SQLITE_OK;
5907 ExpertCsr *pCsr;
5908 pCsr = idxMalloc(&rc, sizeof(ExpertCsr));
5909 *ppCursor = (sqlite3_vtab_cursor*)pCsr;
5910 return rc;
5911 }
5912
5913 /*
5914 ** Virtual table module xClose method.
5915 */
5916 static int expertClose(sqlite3_vtab_cursor *cur){
5917 ExpertCsr *pCsr = (ExpertCsr*)cur;
5918 sqlite3_finalize(pCsr->pData);
5919 sqlite3_free(pCsr);
5920 return SQLITE_OK;
5921 }
5922
5923 /*
5924 ** Virtual table module xEof method.
5925 **
5926 ** Return non-zero if the cursor does not currently point to a valid
5927 ** record (i.e if the scan has finished), or zero otherwise.
5928 */
5929 static int expertEof(sqlite3_vtab_cursor *cur){
5930 ExpertCsr *pCsr = (ExpertCsr*)cur;
5931 return pCsr->pData==0;
5932 }
5933
5934 /*
5935 ** Virtual table module xNext method.
5936 */
5937 static int expertNext(sqlite3_vtab_cursor *cur){
5938 ExpertCsr *pCsr = (ExpertCsr*)cur;
5939 int rc = SQLITE_OK;
5940
5941 assert( pCsr->pData );
5942 rc = sqlite3_step(pCsr->pData);
5943 if( rc!=SQLITE_ROW ){
5944 rc = sqlite3_finalize(pCsr->pData);
5945 pCsr->pData = 0;
5946 }else{
5947 rc = SQLITE_OK;
5948 }
5949
5950 return rc;
5951 }
5952
5953 /*
5954 ** Virtual table module xRowid method.
5955 */
5956 static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
5957 *pRowid = 0;
5958 return SQLITE_OK;
5959 }
5960
5961 /*
5962 ** Virtual table module xColumn method.
5963 */
5964 static int expertColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
5965 ExpertCsr *pCsr = (ExpertCsr*)cur;
5966 sqlite3_value *pVal;
5967 pVal = sqlite3_column_value(pCsr->pData, i);
5968 if( pVal ){
5969 sqlite3_result_value(ctx, pVal);
5970 }
5971 return SQLITE_OK;
5972 }
5973
5974 /*
5975 ** Virtual table module xFilter method.
5976 */
5977 static int expertFilter(
5978 sqlite3_vtab_cursor *cur,
5979 int idxNum, const char *idxStr,
5980 int argc, sqlite3_value **argv
5981 ){
5982 ExpertCsr *pCsr = (ExpertCsr*)cur;
5983 ExpertVtab *pVtab = (ExpertVtab*)(cur->pVtab);
5984 sqlite3expert *pExpert = pVtab->pExpert;
5985 int rc;
5986
5987 rc = sqlite3_finalize(pCsr->pData);
5988 pCsr->pData = 0;
5989 if( rc==SQLITE_OK ){
5990 rc = idxPrintfPrepareStmt(pExpert->db, &pCsr->pData, &pVtab->base.zErrMsg,
5991 "SELECT * FROM main.%Q WHERE sample()", pVtab->pTab->zName
5992 );
5993 }
5994
5995 if( rc==SQLITE_OK ){
5996 rc = expertNext(cur);
5997 }
5998 return rc;
5999 }
6000
6001 static int idxRegisterVtab(sqlite3expert *p){
6002 static sqlite3_module expertModule = {
6003 2, /* iVersion */
6004 expertConnect, /* xCreate - create a table */
6005 expertConnect, /* xConnect - connect to an existing table */
6006 expertBestIndex, /* xBestIndex - Determine search strategy */
6007 expertDisconnect, /* xDisconnect - Disconnect from a table */
6008 expertDisconnect, /* xDestroy - Drop a table */
6009 expertOpen, /* xOpen - open a cursor */
6010 expertClose, /* xClose - close a cursor */
6011 expertFilter, /* xFilter - configure scan constraints */
6012 expertNext, /* xNext - advance a cursor */
6013 expertEof, /* xEof */
6014 expertColumn, /* xColumn - read data */
6015 expertRowid, /* xRowid - read data */
6016 expertUpdate, /* xUpdate - write data */
6017 0, /* xBegin - begin transaction */
6018 0, /* xSync - sync transaction */
6019 0, /* xCommit - commit transaction */
6020 0, /* xRollback - rollback transaction */
6021 0, /* xFindFunction - function overloading */
6022 0, /* xRename - rename the table */
6023 0, /* xSavepoint */
6024 0, /* xRelease */
6025 0, /* xRollbackTo */
6026 };
6027
6028 return sqlite3_create_module(p->dbv, "expert", &expertModule, (void*)p);
6029 }
6030 /*
6031 ** End of virtual table implementation.
6032 *************************************************************************/
6033 /*
6034 ** Finalize SQL statement pStmt. If (*pRc) is SQLITE_OK when this function
6035 ** is called, set it to the return value of sqlite3_finalize() before
6036 ** returning. Otherwise, discard the sqlite3_finalize() return value.
6037 */
6038 static void idxFinalize(int *pRc, sqlite3_stmt *pStmt){
6039 int rc = sqlite3_finalize(pStmt);
6040 if( *pRc==SQLITE_OK ) *pRc = rc;
6041 }
6042
6043 /*
6044 ** Attempt to allocate an IdxTable structure corresponding to table zTab
6045 ** in the main database of connection db. If successful, set (*ppOut) to
6046 ** point to the new object and return SQLITE_OK. Otherwise, return an
6047 ** SQLite error code and set (*ppOut) to NULL. In this case *pzErrmsg may be
6048 ** set to point to an error string.
6049 **
6050 ** It is the responsibility of the caller to eventually free either the
6051 ** IdxTable object or error message using sqlite3_free().
6052 */
6053 static int idxGetTableInfo(
6054 sqlite3 *db, /* Database connection to read details from */
6055 const char *zTab, /* Table name */
6056 IdxTable **ppOut, /* OUT: New object (if successful) */
6057 char **pzErrmsg /* OUT: Error message (if not) */
6058 ){
6059 sqlite3_stmt *p1 = 0;
6060 int nCol = 0;
6061 int nTab = STRLEN(zTab);
6062 int nByte = sizeof(IdxTable) + nTab + 1;
6063 IdxTable *pNew = 0;
6064 int rc, rc2;
6065 char *pCsr = 0;
6066
6067 rc = idxPrintfPrepareStmt(db, &p1, pzErrmsg, "PRAGMA table_info=%Q", zTab);
6068 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
6069 const char *zCol = (const char*)sqlite3_column_text(p1, 1);
6070 nByte += 1 + STRLEN(zCol);
6071 rc = sqlite3_table_column_metadata(
6072 db, "main", zTab, zCol, 0, &zCol, 0, 0, 0
6073 );
6074 nByte += 1 + STRLEN(zCol);
6075 nCol++;
6076 }
6077 rc2 = sqlite3_reset(p1);
6078 if( rc==SQLITE_OK ) rc = rc2;
6079
6080 nByte += sizeof(IdxColumn) * nCol;
6081 if( rc==SQLITE_OK ){
6082 pNew = idxMalloc(&rc, nByte);
6083 }
6084 if( rc==SQLITE_OK ){
6085 pNew->aCol = (IdxColumn*)&pNew[1];
6086 pNew->nCol = nCol;
6087 pCsr = (char*)&pNew->aCol[nCol];
6088 }
6089
6090 nCol = 0;
6091 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(p1) ){
6092 const char *zCol = (const char*)sqlite3_column_text(p1, 1);
6093 int nCopy = STRLEN(zCol) + 1;
6094 pNew->aCol[nCol].zName = pCsr;
6095 pNew->aCol[nCol].iPk = sqlite3_column_int(p1, 5);
6096 memcpy(pCsr, zCol, nCopy);
6097 pCsr += nCopy;
6098
6099 rc = sqlite3_table_column_metadata(
6100 db, "main", zTab, zCol, 0, &zCol, 0, 0, 0
6101 );
6102 if( rc==SQLITE_OK ){
6103 nCopy = STRLEN(zCol) + 1;
6104 pNew->aCol[nCol].zColl = pCsr;
6105 memcpy(pCsr, zCol, nCopy);
6106 pCsr += nCopy;
6107 }
6108
6109 nCol++;
6110 }
6111 idxFinalize(&rc, p1);
6112
6113 if( rc!=SQLITE_OK ){
6114 sqlite3_free(pNew);
6115 pNew = 0;
6116 }else{
6117 pNew->zName = pCsr;
6118 memcpy(pNew->zName, zTab, nTab+1);
6119 }
6120
6121 *ppOut = pNew;
6122 return rc;
6123 }
6124
6125 /*
6126 ** This function is a no-op if *pRc is set to anything other than
6127 ** SQLITE_OK when it is called.
6128 **
6129 ** If *pRc is initially set to SQLITE_OK, then the text specified by
6130 ** the printf() style arguments is appended to zIn and the result returned
6131 ** in a buffer allocated by sqlite3_malloc(). sqlite3_free() is called on
6132 ** zIn before returning.
6133 */
6134 static char *idxAppendText(int *pRc, char *zIn, const char *zFmt, ...){
6135 va_list ap;
6136 char *zAppend = 0;
6137 char *zRet = 0;
6138 int nIn = zIn ? STRLEN(zIn) : 0;
6139 int nAppend = 0;
6140 va_start(ap, zFmt);
6141 if( *pRc==SQLITE_OK ){
6142 zAppend = sqlite3_vmprintf(zFmt, ap);
6143 if( zAppend ){
6144 nAppend = STRLEN(zAppend);
6145 zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
6146 }
6147 if( zAppend && zRet ){
6148 memcpy(zRet, zIn, nIn);
6149 memcpy(&zRet[nIn], zAppend, nAppend+1);
6150 }else{
6151 sqlite3_free(zRet);
6152 zRet = 0;
6153 *pRc = SQLITE_NOMEM;
6154 }
6155 sqlite3_free(zAppend);
6156 sqlite3_free(zIn);
6157 }
6158 va_end(ap);
6159 return zRet;
6160 }
6161
6162 /*
6163 ** Return true if zId must be quoted in order to use it as an SQL
6164 ** identifier, or false otherwise.
6165 */
6166 static int idxIdentifierRequiresQuotes(const char *zId){
6167 int i;
6168 for(i=0; zId[i]; i++){
6169 if( !(zId[i]=='_')
6170 && !(zId[i]>='0' && zId[i]<='9')
6171 && !(zId[i]>='a' && zId[i]<='z')
6172 && !(zId[i]>='A' && zId[i]<='Z')
6173 ){
6174 return 1;
6175 }
6176 }
6177 return 0;
6178 }
6179
6180 /*
6181 ** This function appends an index column definition suitable for constraint
6182 ** pCons to the string passed as zIn and returns the result.
6183 */
6184 static char *idxAppendColDefn(
6185 int *pRc, /* IN/OUT: Error code */
6186 char *zIn, /* Column defn accumulated so far */
6187 IdxTable *pTab, /* Table index will be created on */
6188 IdxConstraint *pCons
6189 ){
6190 char *zRet = zIn;
6191 IdxColumn *p = &pTab->aCol[pCons->iCol];
6192 if( zRet ) zRet = idxAppendText(pRc, zRet, ", ");
6193
6194 if( idxIdentifierRequiresQuotes(p->zName) ){
6195 zRet = idxAppendText(pRc, zRet, "%Q", p->zName);
6196 }else{
6197 zRet = idxAppendText(pRc, zRet, "%s", p->zName);
6198 }
6199
6200 if( sqlite3_stricmp(p->zColl, pCons->zColl) ){
6201 if( idxIdentifierRequiresQuotes(pCons->zColl) ){
6202 zRet = idxAppendText(pRc, zRet, " COLLATE %Q", pCons->zColl);
6203 }else{
6204 zRet = idxAppendText(pRc, zRet, " COLLATE %s", pCons->zColl);
6205 }
6206 }
6207
6208 if( pCons->bDesc ){
6209 zRet = idxAppendText(pRc, zRet, " DESC");
6210 }
6211 return zRet;
6212 }
6213
6214 /*
6215 ** Search database dbm for an index compatible with the one idxCreateFromCons()
6216 ** would create from arguments pScan, pEq and pTail. If no error occurs and
6217 ** such an index is found, return non-zero. Or, if no such index is found,
6218 ** return zero.
6219 **
6220 ** If an error occurs, set *pRc to an SQLite error code and return zero.
6221 */
6222 static int idxFindCompatible(
6223 int *pRc, /* OUT: Error code */
6224 sqlite3* dbm, /* Database to search */
6225 IdxScan *pScan, /* Scan for table to search for index on */
6226 IdxConstraint *pEq, /* List of == constraints */
6227 IdxConstraint *pTail /* List of range constraints */
6228 ){
6229 const char *zTbl = pScan->pTab->zName;
6230 sqlite3_stmt *pIdxList = 0;
6231 IdxConstraint *pIter;
6232 int nEq = 0; /* Number of elements in pEq */
6233 int rc;
6234
6235 /* Count the elements in list pEq */
6236 for(pIter=pEq; pIter; pIter=pIter->pLink) nEq++;
6237
6238 rc = idxPrintfPrepareStmt(dbm, &pIdxList, 0, "PRAGMA index_list=%Q", zTbl);
6239 while( rc==SQLITE_OK && sqlite3_step(pIdxList)==SQLITE_ROW ){
6240 int bMatch = 1;
6241 IdxConstraint *pT = pTail;
6242 sqlite3_stmt *pInfo = 0;
6243 const char *zIdx = (const char*)sqlite3_column_text(pIdxList, 1);
6244
6245 /* Zero the IdxConstraint.bFlag values in the pEq list */
6246 for(pIter=pEq; pIter; pIter=pIter->pLink) pIter->bFlag = 0;
6247
6248 rc = idxPrintfPrepareStmt(dbm, &pInfo, 0, "PRAGMA index_xInfo=%Q", zIdx);
6249 while( rc==SQLITE_OK && sqlite3_step(pInfo)==SQLITE_ROW ){
6250 int iIdx = sqlite3_column_int(pInfo, 0);
6251 int iCol = sqlite3_column_int(pInfo, 1);
6252 const char *zColl = (const char*)sqlite3_column_text(pInfo, 4);
6253
6254 if( iIdx<nEq ){
6255 for(pIter=pEq; pIter; pIter=pIter->pLink){
6256 if( pIter->bFlag ) continue;
6257 if( pIter->iCol!=iCol ) continue;
6258 if( sqlite3_stricmp(pIter->zColl, zColl) ) continue;
6259 pIter->bFlag = 1;
6260 break;
6261 }
6262 if( pIter==0 ){
6263 bMatch = 0;
6264 break;
6265 }
6266 }else{
6267 if( pT ){
6268 if( pT->iCol!=iCol || sqlite3_stricmp(pT->zColl, zColl) ){
6269 bMatch = 0;
6270 break;
6271 }
6272 pT = pT->pLink;
6273 }
6274 }
6275 }
6276 idxFinalize(&rc, pInfo);
6277
6278 if( rc==SQLITE_OK && bMatch ){
6279 sqlite3_finalize(pIdxList);
6280 return 1;
6281 }
6282 }
6283 idxFinalize(&rc, pIdxList);
6284
6285 *pRc = rc;
6286 return 0;
6287 }
6288
6289 static int idxCreateFromCons(
6290 sqlite3expert *p,
6291 IdxScan *pScan,
6292 IdxConstraint *pEq,
6293 IdxConstraint *pTail
6294 ){
6295 sqlite3 *dbm = p->dbm;
6296 int rc = SQLITE_OK;
6297 if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){
6298 IdxTable *pTab = pScan->pTab;
6299 char *zCols = 0;
6300 char *zIdx = 0;
6301 IdxConstraint *pCons;
6302 int h = 0;
6303 const char *zFmt;
6304
6305 for(pCons=pEq; pCons; pCons=pCons->pLink){
6306 zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
6307 }
6308 for(pCons=pTail; pCons; pCons=pCons->pLink){
6309 zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
6310 }
6311
6312 if( rc==SQLITE_OK ){
6313 /* Hash the list of columns to come up with a name for the index */
6314 const char *zTable = pScan->pTab->zName;
6315 char *zName; /* Index name */
6316 int i;
6317 for(i=0; zCols[i]; i++){
6318 h += ((h<<3) + zCols[i]);
6319 }
6320 zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
6321 if( zName==0 ){
6322 rc = SQLITE_NOMEM;
6323 }else{
6324 if( idxIdentifierRequiresQuotes(zTable) ){
6325 zFmt = "CREATE INDEX '%q' ON %Q(%s)";
6326 }else{
6327 zFmt = "CREATE INDEX %s ON %s(%s)";
6328 }
6329 zIdx = sqlite3_mprintf(zFmt, zName, zTable, zCols);
6330 if( !zIdx ){
6331 rc = SQLITE_NOMEM;
6332 }else{
6333 rc = sqlite3_exec(dbm, zIdx, 0, 0, p->pzErrmsg);
6334 idxHashAdd(&rc, &p->hIdx, zName, zIdx);
6335 }
6336 sqlite3_free(zName);
6337 sqlite3_free(zIdx);
6338 }
6339 }
6340
6341 sqlite3_free(zCols);
6342 }
6343 return rc;
6344 }
6345
6346 /*
6347 ** Return true if list pList (linked by IdxConstraint.pLink) contains
6348 ** a constraint compatible with *p. Otherwise return false.
6349 */
6350 static int idxFindConstraint(IdxConstraint *pList, IdxConstraint *p){
6351 IdxConstraint *pCmp;
6352 for(pCmp=pList; pCmp; pCmp=pCmp->pLink){
6353 if( p->iCol==pCmp->iCol ) return 1;
6354 }
6355 return 0;
6356 }
6357
6358 static int idxCreateFromWhere(
6359 sqlite3expert *p,
6360 IdxScan *pScan, /* Create indexes for this scan */
6361 IdxConstraint *pTail /* range/ORDER BY constraints for inclusion */
6362 ){
6363 IdxConstraint *p1 = 0;
6364 IdxConstraint *pCon;
6365 int rc;
6366
6367 /* Gather up all the == constraints. */
6368 for(pCon=pScan->pEq; pCon; pCon=pCon->pNext){
6369 if( !idxFindConstraint(p1, pCon) && !idxFindConstraint(pTail, pCon) ){
6370 pCon->pLink = p1;
6371 p1 = pCon;
6372 }
6373 }
6374
6375 /* Create an index using the == constraints collected above. And the
6376 ** range constraint/ORDER BY terms passed in by the caller, if any. */
6377 rc = idxCreateFromCons(p, pScan, p1, pTail);
6378
6379 /* If no range/ORDER BY passed by the caller, create a version of the
6380 ** index for each range constraint. */
6381 if( pTail==0 ){
6382 for(pCon=pScan->pRange; rc==SQLITE_OK && pCon; pCon=pCon->pNext){
6383 assert( pCon->pLink==0 );
6384 if( !idxFindConstraint(p1, pCon) && !idxFindConstraint(pTail, pCon) ){
6385 rc = idxCreateFromCons(p, pScan, p1, pCon);
6386 }
6387 }
6388 }
6389
6390 return rc;
6391 }
6392
6393 /*
6394 ** Create candidate indexes in database [dbm] based on the data in
6395 ** linked-list pScan.
6396 */
6397 static int idxCreateCandidates(sqlite3expert *p, char **pzErr){
6398 int rc = SQLITE_OK;
6399 IdxScan *pIter;
6400
6401 for(pIter=p->pScan; pIter && rc==SQLITE_OK; pIter=pIter->pNextScan){
6402 rc = idxCreateFromWhere(p, pIter, 0);
6403 if( rc==SQLITE_OK && pIter->pOrder ){
6404 rc = idxCreateFromWhere(p, pIter, pIter->pOrder);
6405 }
6406 }
6407
6408 return rc;
6409 }
6410
6411 /*
6412 ** Free all elements of the linked list starting at pConstraint.
6413 */
6414 static void idxConstraintFree(IdxConstraint *pConstraint){
6415 IdxConstraint *pNext;
6416 IdxConstraint *p;
6417
6418 for(p=pConstraint; p; p=pNext){
6419 pNext = p->pNext;
6420 sqlite3_free(p);
6421 }
6422 }
6423
6424 /*
6425 ** Free all elements of the linked list starting from pScan up until pLast
6426 ** (pLast is not freed).
6427 */
6428 static void idxScanFree(IdxScan *pScan, IdxScan *pLast){
6429 IdxScan *p;
6430 IdxScan *pNext;
6431 for(p=pScan; p!=pLast; p=pNext){
6432 pNext = p->pNextScan;
6433 idxConstraintFree(p->pOrder);
6434 idxConstraintFree(p->pEq);
6435 idxConstraintFree(p->pRange);
6436 sqlite3_free(p);
6437 }
6438 }
6439
6440 /*
6441 ** Free all elements of the linked list starting from pStatement up
6442 ** until pLast (pLast is not freed).
6443 */
6444 static void idxStatementFree(IdxStatement *pStatement, IdxStatement *pLast){
6445 IdxStatement *p;
6446 IdxStatement *pNext;
6447 for(p=pStatement; p!=pLast; p=pNext){
6448 pNext = p->pNext;
6449 sqlite3_free(p->zEQP);
6450 sqlite3_free(p->zIdx);
6451 sqlite3_free(p);
6452 }
6453 }
6454
6455 /*
6456 ** Free the linked list of IdxTable objects starting at pTab.
6457 */
6458 static void idxTableFree(IdxTable *pTab){
6459 IdxTable *pIter;
6460 IdxTable *pNext;
6461 for(pIter=pTab; pIter; pIter=pNext){
6462 pNext = pIter->pNext;
6463 sqlite3_free(pIter);
6464 }
6465 }
6466
6467 /*
6468 ** Free the linked list of IdxWrite objects starting at pTab.
6469 */
6470 static void idxWriteFree(IdxWrite *pTab){
6471 IdxWrite *pIter;
6472 IdxWrite *pNext;
6473 for(pIter=pTab; pIter; pIter=pNext){
6474 pNext = pIter->pNext;
6475 sqlite3_free(pIter);
6476 }
6477 }
6478
6479
6480
6481 /*
6482 ** This function is called after candidate indexes have been created. It
6483 ** runs all the queries to see which indexes they prefer, and populates
6484 ** IdxStatement.zIdx and IdxStatement.zEQP with the results.
6485 */
6486 int idxFindIndexes(
6487 sqlite3expert *p,
6488 char **pzErr /* OUT: Error message (sqlite3_malloc) */
6489 ){
6490 IdxStatement *pStmt;
6491 sqlite3 *dbm = p->dbm;
6492 int rc = SQLITE_OK;
6493
6494 IdxHash hIdx;
6495 idxHashInit(&hIdx);
6496
6497 for(pStmt=p->pStatement; rc==SQLITE_OK && pStmt; pStmt=pStmt->pNext){
6498 IdxHashEntry *pEntry;
6499 sqlite3_stmt *pExplain = 0;
6500 idxHashClear(&hIdx);
6501 rc = idxPrintfPrepareStmt(dbm, &pExplain, pzErr,
6502 "EXPLAIN QUERY PLAN %s", pStmt->zSql
6503 );
6504 while( rc==SQLITE_OK && sqlite3_step(pExplain)==SQLITE_ROW ){
6505 int iSelectid = sqlite3_column_int(pExplain, 0);
6506 int iOrder = sqlite3_column_int(pExplain, 1);
6507 int iFrom = sqlite3_column_int(pExplain, 2);
6508 const char *zDetail = (const char*)sqlite3_column_text(pExplain, 3);
6509 int nDetail = STRLEN(zDetail);
6510 int i;
6511
6512 for(i=0; i<nDetail; i++){
6513 const char *zIdx = 0;
6514 if( memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
6515 zIdx = &zDetail[i+13];
6516 }else if( memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0 ){
6517 zIdx = &zDetail[i+22];
6518 }
6519 if( zIdx ){
6520 const char *zSql;
6521 int nIdx = 0;
6522 while( zIdx[nIdx]!='\0' && (zIdx[nIdx]!=' ' || zIdx[nIdx+1]!='(') ){
6523 nIdx++;
6524 }
6525 zSql = idxHashSearch(&p->hIdx, zIdx, nIdx);
6526 if( zSql ){
6527 idxHashAdd(&rc, &hIdx, zSql, 0);
6528 if( rc ) goto find_indexes_out;
6529 }
6530 break;
6531 }
6532 }
6533
6534 pStmt->zEQP = idxAppendText(&rc, pStmt->zEQP, "%d|%d|%d|%s\n",
6535 iSelectid, iOrder, iFrom, zDetail
6536 );
6537 }
6538
6539 for(pEntry=hIdx.pFirst; pEntry; pEntry=pEntry->pNext){
6540 pStmt->zIdx = idxAppendText(&rc, pStmt->zIdx, "%s;\n", pEntry->zKey);
6541 }
6542
6543 idxFinalize(&rc, pExplain);
6544 }
6545
6546 find_indexes_out:
6547 idxHashClear(&hIdx);
6548 return rc;
6549 }
6550
6551 static int idxAuthCallback(
6552 void *pCtx,
6553 int eOp,
6554 const char *z3,
6555 const char *z4,
6556 const char *zDb,
6557 const char *zTrigger
6558 ){
6559 int rc = SQLITE_OK;
6560 if( eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE || eOp==SQLITE_DELETE ){
6561 if( sqlite3_stricmp(zDb, "main")==0 ){
6562 sqlite3expert *p = (sqlite3expert*)pCtx;
6563 IdxTable *pTab;
6564 for(pTab=p->pTable; pTab; pTab=pTab->pNext){
6565 if( 0==sqlite3_stricmp(z3, pTab->zName) ) break;
6566 }
6567 if( pTab ){
6568 IdxWrite *pWrite;
6569 for(pWrite=p->pWrite; pWrite; pWrite=pWrite->pNext){
6570 if( pWrite->pTab==pTab && pWrite->eOp==eOp ) break;
6571 }
6572 if( pWrite==0 ){
6573 pWrite = idxMalloc(&rc, sizeof(IdxWrite));
6574 if( rc==SQLITE_OK ){
6575 pWrite->pTab = pTab;
6576 pWrite->eOp = eOp;
6577 pWrite->pNext = p->pWrite;
6578 p->pWrite = pWrite;
6579 }
6580 }
6581 }
6582 }
6583 }
6584 return rc;
6585 }
6586
6587 static int idxProcessOneTrigger(
6588 sqlite3expert *p,
6589 IdxWrite *pWrite,
6590 char **pzErr
6591 ){
6592 static const char *zInt = UNIQUE_TABLE_NAME;
6593 static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
6594 IdxTable *pTab = pWrite->pTab;
6595 const char *zTab = pTab->zName;
6596 const char *zSql =
6597 "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_master "
6598 "WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
6599 "ORDER BY type;";
6600 sqlite3_stmt *pSelect = 0;
6601 int rc = SQLITE_OK;
6602 char *zWrite = 0;
6603
6604 /* Create the table and its triggers in the temp schema */
6605 rc = idxPrintfPrepareStmt(p->db, &pSelect, pzErr, zSql, zTab, zTab);
6606 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSelect) ){
6607 const char *zCreate = (const char*)sqlite3_column_text(pSelect, 0);
6608 rc = sqlite3_exec(p->dbv, zCreate, 0, 0, pzErr);
6609 }
6610 idxFinalize(&rc, pSelect);
6611
6612 /* Rename the table in the temp schema to zInt */
6613 if( rc==SQLITE_OK ){
6614 char *z = sqlite3_mprintf("ALTER TABLE temp.%Q RENAME TO %Q", zTab, zInt);
6615 if( z==0 ){
6616 rc = SQLITE_NOMEM;
6617 }else{
6618 rc = sqlite3_exec(p->dbv, z, 0, 0, pzErr);
6619 sqlite3_free(z);
6620 }
6621 }
6622
6623 switch( pWrite->eOp ){
6624 case SQLITE_INSERT: {
6625 int i;
6626 zWrite = idxAppendText(&rc, zWrite, "INSERT INTO %Q VALUES(", zInt);
6627 for(i=0; i<pTab->nCol; i++){
6628 zWrite = idxAppendText(&rc, zWrite, "%s?", i==0 ? "" : ", ");
6629 }
6630 zWrite = idxAppendText(&rc, zWrite, ")");
6631 break;
6632 }
6633 case SQLITE_UPDATE: {
6634 int i;
6635 zWrite = idxAppendText(&rc, zWrite, "UPDATE %Q SET ", zInt);
6636 for(i=0; i<pTab->nCol; i++){
6637 zWrite = idxAppendText(&rc, zWrite, "%s%Q=?", i==0 ? "" : ", ",
6638 pTab->aCol[i].zName
6639 );
6640 }
6641 break;
6642 }
6643 default: {
6644 assert( pWrite->eOp==SQLITE_DELETE );
6645 if( rc==SQLITE_OK ){
6646 zWrite = sqlite3_mprintf("DELETE FROM %Q", zInt);
6647 if( zWrite==0 ) rc = SQLITE_NOMEM;
6648 }
6649 }
6650 }
6651
6652 if( rc==SQLITE_OK ){
6653 sqlite3_stmt *pX = 0;
6654 rc = sqlite3_prepare_v2(p->dbv, zWrite, -1, &pX, 0);
6655 idxFinalize(&rc, pX);
6656 if( rc!=SQLITE_OK ){
6657 idxDatabaseError(p->dbv, pzErr);
6658 }
6659 }
6660 sqlite3_free(zWrite);
6661
6662 if( rc==SQLITE_OK ){
6663 rc = sqlite3_exec(p->dbv, zDrop, 0, 0, pzErr);
6664 }
6665
6666 return rc;
6667 }
6668
6669 static int idxProcessTriggers(sqlite3expert *p, char **pzErr){
6670 int rc = SQLITE_OK;
6671 IdxWrite *pEnd = 0;
6672 IdxWrite *pFirst = p->pWrite;
6673
6674 while( rc==SQLITE_OK && pFirst!=pEnd ){
6675 IdxWrite *pIter;
6676 for(pIter=pFirst; rc==SQLITE_OK && pIter!=pEnd; pIter=pIter->pNext){
6677 rc = idxProcessOneTrigger(p, pIter, pzErr);
6678 }
6679 pEnd = pFirst;
6680 pFirst = p->pWrite;
6681 }
6682
6683 return rc;
6684 }
6685
6686
6687 static int idxCreateVtabSchema(sqlite3expert *p, char **pzErrmsg){
6688 int rc = idxRegisterVtab(p);
6689 sqlite3_stmt *pSchema = 0;
6690
6691 /* For each table in the main db schema:
6692 **
6693 ** 1) Add an entry to the p->pTable list, and
6694 ** 2) Create the equivalent virtual table in dbv.
6695 */
6696 rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
6697 "SELECT type, name, sql, 1 FROM sqlite_master "
6698 "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' "
6699 " UNION ALL "
6700 "SELECT type, name, sql, 2 FROM sqlite_master "
6701 "WHERE type = 'trigger'"
6702 " AND tbl_name IN(SELECT name FROM sqlite_master WHERE type = 'view') "
6703 "ORDER BY 4, 1"
6704 );
6705 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSchema) ){
6706 const char *zType = (const char*)sqlite3_column_text(pSchema, 0);
6707 const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
6708 const char *zSql = (const char*)sqlite3_column_text(pSchema, 2);
6709
6710 if( zType[0]=='v' || zType[1]=='r' ){
6711 rc = sqlite3_exec(p->dbv, zSql, 0, 0, pzErrmsg);
6712 }else{
6713 IdxTable *pTab;
6714 rc = idxGetTableInfo(p->db, zName, &pTab, pzErrmsg);
6715 if( rc==SQLITE_OK ){
6716 int i;
6717 char *zInner = 0;
6718 char *zOuter = 0;
6719 pTab->pNext = p->pTable;
6720 p->pTable = pTab;
6721
6722 /* The statement the vtab will pass to sqlite3_declare_vtab() */
6723 zInner = idxAppendText(&rc, 0, "CREATE TABLE x(");
6724 for(i=0; i<pTab->nCol; i++){
6725 zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s",
6726 (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl
6727 );
6728 }
6729 zInner = idxAppendText(&rc, zInner, ")");
6730
6731 /* The CVT statement to create the vtab */
6732 zOuter = idxAppendText(&rc, 0,
6733 "CREATE VIRTUAL TABLE %Q USING expert(%Q)", zName, zInner
6734 );
6735 if( rc==SQLITE_OK ){
6736 rc = sqlite3_exec(p->dbv, zOuter, 0, 0, pzErrmsg);
6737 }
6738 sqlite3_free(zInner);
6739 sqlite3_free(zOuter);
6740 }
6741 }
6742 }
6743 idxFinalize(&rc, pSchema);
6744 return rc;
6745 }
6746
6747 struct IdxSampleCtx {
6748 int iTarget;
6749 double target; /* Target nRet/nRow value */
6750 double nRow; /* Number of rows seen */
6751 double nRet; /* Number of rows returned */
6752 };
6753
6754 static void idxSampleFunc(
6755 sqlite3_context *pCtx,
6756 int argc,
6757 sqlite3_value **argv
6758 ){
6759 struct IdxSampleCtx *p = (struct IdxSampleCtx*)sqlite3_user_data(pCtx);
6760 int bRet;
6761
6762 assert( argc==0 );
6763 if( p->nRow==0.0 ){
6764 bRet = 1;
6765 }else{
6766 bRet = (p->nRet / p->nRow) <= p->target;
6767 if( bRet==0 ){
6768 unsigned short rnd;
6769 sqlite3_randomness(2, (void*)&rnd);
6770 bRet = ((int)rnd % 100) <= p->iTarget;
6771 }
6772 }
6773
6774 sqlite3_result_int(pCtx, bRet);
6775 p->nRow += 1.0;
6776 p->nRet += (double)bRet;
6777 }
6778
6779 struct IdxRemCtx {
6780 int nSlot;
6781 struct IdxRemSlot {
6782 int eType; /* SQLITE_NULL, INTEGER, REAL, TEXT, BLOB */
6783 i64 iVal; /* SQLITE_INTEGER value */
6784 double rVal; /* SQLITE_FLOAT value */
6785 int nByte; /* Bytes of space allocated at z */
6786 int n; /* Size of buffer z */
6787 char *z; /* SQLITE_TEXT/BLOB value */
6788 } aSlot[1];
6789 };
6790
6791 /*
6792 ** Implementation of scalar function rem().
6793 */
6794 static void idxRemFunc(
6795 sqlite3_context *pCtx,
6796 int argc,
6797 sqlite3_value **argv
6798 ){
6799 struct IdxRemCtx *p = (struct IdxRemCtx*)sqlite3_user_data(pCtx);
6800 struct IdxRemSlot *pSlot;
6801 int iSlot;
6802 assert( argc==2 );
6803
6804 iSlot = sqlite3_value_int(argv[0]);
6805 assert( iSlot<=p->nSlot );
6806 pSlot = &p->aSlot[iSlot];
6807
6808 switch( pSlot->eType ){
6809 case SQLITE_NULL:
6810 /* no-op */
6811 break;
6812
6813 case SQLITE_INTEGER:
6814 sqlite3_result_int64(pCtx, pSlot->iVal);
6815 break;
6816
6817 case SQLITE_FLOAT:
6818 sqlite3_result_double(pCtx, pSlot->rVal);
6819 break;
6820
6821 case SQLITE_BLOB:
6822 sqlite3_result_blob(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
6823 break;
6824
6825 case SQLITE_TEXT:
6826 sqlite3_result_text(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
6827 break;
6828 }
6829
6830 pSlot->eType = sqlite3_value_type(argv[1]);
6831 switch( pSlot->eType ){
6832 case SQLITE_NULL:
6833 /* no-op */
6834 break;
6835
6836 case SQLITE_INTEGER:
6837 pSlot->iVal = sqlite3_value_int64(argv[1]);
6838 break;
6839
6840 case SQLITE_FLOAT:
6841 pSlot->rVal = sqlite3_value_double(argv[1]);
6842 break;
6843
6844 case SQLITE_BLOB:
6845 case SQLITE_TEXT: {
6846 int nByte = sqlite3_value_bytes(argv[1]);
6847 if( nByte>pSlot->nByte ){
6848 char *zNew = (char*)sqlite3_realloc(pSlot->z, nByte*2);
6849 if( zNew==0 ){
6850 sqlite3_result_error_nomem(pCtx);
6851 return;
6852 }
6853 pSlot->nByte = nByte*2;
6854 pSlot->z = zNew;
6855 }
6856 pSlot->n = nByte;
6857 if( pSlot->eType==SQLITE_BLOB ){
6858 memcpy(pSlot->z, sqlite3_value_blob(argv[1]), nByte);
6859 }else{
6860 memcpy(pSlot->z, sqlite3_value_text(argv[1]), nByte);
6861 }
6862 break;
6863 }
6864 }
6865 }
6866
6867 static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr){
6868 int rc = SQLITE_OK;
6869 const char *zMax =
6870 "SELECT max(i.seqno) FROM "
6871 " sqlite_master AS s, "
6872 " pragma_index_list(s.name) AS l, "
6873 " pragma_index_info(l.name) AS i "
6874 "WHERE s.type = 'table'";
6875 sqlite3_stmt *pMax = 0;
6876
6877 *pnMax = 0;
6878 rc = idxPrepareStmt(db, &pMax, pzErr, zMax);
6879 if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pMax) ){
6880 *pnMax = sqlite3_column_int(pMax, 0) + 1;
6881 }
6882 idxFinalize(&rc, pMax);
6883
6884 return rc;
6885 }
6886
6887 static int idxPopulateOneStat1(
6888 sqlite3expert *p,
6889 sqlite3_stmt *pIndexXInfo,
6890 sqlite3_stmt *pWriteStat,
6891 const char *zTab,
6892 const char *zIdx,
6893 char **pzErr
6894 ){
6895 char *zCols = 0;
6896 char *zOrder = 0;
6897 char *zQuery = 0;
6898 int nCol = 0;
6899 int i;
6900 sqlite3_stmt *pQuery = 0;
6901 int *aStat = 0;
6902 int rc = SQLITE_OK;
6903
6904 assert( p->iSample>0 );
6905
6906 /* Formulate the query text */
6907 sqlite3_bind_text(pIndexXInfo, 1, zIdx, -1, SQLITE_STATIC);
6908 while( SQLITE_OK==rc && SQLITE_ROW==sqlite3_step(pIndexXInfo) ){
6909 const char *zComma = zCols==0 ? "" : ", ";
6910 const char *zName = (const char*)sqlite3_column_text(pIndexXInfo, 0);
6911 const char *zColl = (const char*)sqlite3_column_text(pIndexXInfo, 1);
6912 zCols = idxAppendText(&rc, zCols,
6913 "%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl
6914 );
6915 zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
6916 }
6917 if( rc==SQLITE_OK ){
6918 if( p->iSample==100 ){
6919 zQuery = sqlite3_mprintf(
6920 "SELECT %s FROM %Q x ORDER BY %s", zCols, zTab, zOrder
6921 );
6922 }else{
6923 zQuery = sqlite3_mprintf(
6924 "SELECT %s FROM temp."UNIQUE_TABLE_NAME" x ORDER BY %s", zCols, zOrder
6925 );
6926 }
6927 }
6928 sqlite3_free(zCols);
6929 sqlite3_free(zOrder);
6930
6931 /* Formulate the query text */
6932 if( rc==SQLITE_OK ){
6933 sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv);
6934 rc = idxPrepareStmt(dbrem, &pQuery, pzErr, zQuery);
6935 }
6936 sqlite3_free(zQuery);
6937
6938 if( rc==SQLITE_OK ){
6939 aStat = (int*)idxMalloc(&rc, sizeof(int)*(nCol+1));
6940 }
6941 if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){
6942 IdxHashEntry *pEntry;
6943 char *zStat = 0;
6944 for(i=0; i<=nCol; i++) aStat[i] = 1;
6945 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){
6946 aStat[0]++;
6947 for(i=0; i<nCol; i++){
6948 if( sqlite3_column_int(pQuery, i)==0 ) break;
6949 }
6950 for(/*no-op*/; i<nCol; i++){
6951 aStat[i+1]++;
6952 }
6953 }
6954
6955 if( rc==SQLITE_OK ){
6956 int s0 = aStat[0];
6957 zStat = sqlite3_mprintf("%d", s0);
6958 if( zStat==0 ) rc = SQLITE_NOMEM;
6959 for(i=1; rc==SQLITE_OK && i<=nCol; i++){
6960 zStat = idxAppendText(&rc, zStat, " %d", (s0+aStat[i]/2) / aStat[i]);
6961 }
6962 }
6963
6964 if( rc==SQLITE_OK ){
6965 sqlite3_bind_text(pWriteStat, 1, zTab, -1, SQLITE_STATIC);
6966 sqlite3_bind_text(pWriteStat, 2, zIdx, -1, SQLITE_STATIC);
6967 sqlite3_bind_text(pWriteStat, 3, zStat, -1, SQLITE_STATIC);
6968 sqlite3_step(pWriteStat);
6969 rc = sqlite3_reset(pWriteStat);
6970 }
6971
6972 pEntry = idxHashFind(&p->hIdx, zIdx, STRLEN(zIdx));
6973 if( pEntry ){
6974 assert( pEntry->zVal2==0 );
6975 pEntry->zVal2 = zStat;
6976 }else{
6977 sqlite3_free(zStat);
6978 }
6979 }
6980 sqlite3_free(aStat);
6981 idxFinalize(&rc, pQuery);
6982
6983 return rc;
6984 }
6985
6986 static int idxBuildSampleTable(sqlite3expert *p, const char *zTab){
6987 int rc;
6988 char *zSql;
6989
6990 rc = sqlite3_exec(p->dbv,"DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
6991 if( rc!=SQLITE_OK ) return rc;
6992
6993 zSql = sqlite3_mprintf(
6994 "CREATE TABLE temp." UNIQUE_TABLE_NAME " AS SELECT * FROM %Q", zTab
6995 );
6996 if( zSql==0 ) return SQLITE_NOMEM;
6997 rc = sqlite3_exec(p->dbv, zSql, 0, 0, 0);
6998 sqlite3_free(zSql);
6999
7000 return rc;
7001 }
7002
7003 /*
7004 ** This function is called as part of sqlite3_expert_analyze(). Candidate
7005 ** indexes have already been created in database sqlite3expert.dbm, this
7006 ** function populates sqlite_stat1 table in the same database.
7007 **
7008 ** The stat1 data is generated by querying the
7009 */
7010 static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
7011 int rc = SQLITE_OK;
7012 int nMax =0;
7013 struct IdxRemCtx *pCtx = 0;
7014 struct IdxSampleCtx samplectx;
7015 int i;
7016 i64 iPrev = -100000;
7017 sqlite3_stmt *pAllIndex = 0;
7018 sqlite3_stmt *pIndexXInfo = 0;
7019 sqlite3_stmt *pWrite = 0;
7020
7021 const char *zAllIndex =
7022 "SELECT s.rowid, s.name, l.name FROM "
7023 " sqlite_master AS s, "
7024 " pragma_index_list(s.name) AS l "
7025 "WHERE s.type = 'table'";
7026 const char *zIndexXInfo =
7027 "SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
7028 const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
7029
7030 /* If iSample==0, no sqlite_stat1 data is required. */
7031 if( p->iSample==0 ) return SQLITE_OK;
7032
7033 rc = idxLargestIndex(p->dbm, &nMax, pzErr);
7034 if( nMax<=0 || rc!=SQLITE_OK ) return rc;
7035
7036 rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0);
7037
7038 if( rc==SQLITE_OK ){
7039 int nByte = sizeof(struct IdxRemCtx) + (sizeof(struct IdxRemSlot) * nMax);
7040 pCtx = (struct IdxRemCtx*)idxMalloc(&rc, nByte);
7041 }
7042
7043 if( rc==SQLITE_OK ){
7044 sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv);
7045 rc = sqlite3_create_function(
7046 dbrem, "rem", 2, SQLITE_UTF8, (void*)pCtx, idxRemFunc, 0, 0
7047 );
7048 }
7049 if( rc==SQLITE_OK ){
7050 rc = sqlite3_create_function(
7051 p->db, "sample", 0, SQLITE_UTF8, (void*)&samplectx, idxSampleFunc, 0, 0
7052 );
7053 }
7054
7055 if( rc==SQLITE_OK ){
7056 pCtx->nSlot = nMax+1;
7057 rc = idxPrepareStmt(p->dbm, &pAllIndex, pzErr, zAllIndex);
7058 }
7059 if( rc==SQLITE_OK ){
7060 rc = idxPrepareStmt(p->dbm, &pIndexXInfo, pzErr, zIndexXInfo);
7061 }
7062 if( rc==SQLITE_OK ){
7063 rc = idxPrepareStmt(p->dbm, &pWrite, pzErr, zWrite);
7064 }
7065
7066 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pAllIndex) ){
7067 i64 iRowid = sqlite3_column_int64(pAllIndex, 0);
7068 const char *zTab = (const char*)sqlite3_column_text(pAllIndex, 1);
7069 const char *zIdx = (const char*)sqlite3_column_text(pAllIndex, 2);
7070 if( p->iSample<100 && iPrev!=iRowid ){
7071 samplectx.target = (double)p->iSample / 100.0;
7072 samplectx.iTarget = p->iSample;
7073 samplectx.nRow = 0.0;
7074 samplectx.nRet = 0.0;
7075 rc = idxBuildSampleTable(p, zTab);
7076 if( rc!=SQLITE_OK ) break;
7077 }
7078 rc = idxPopulateOneStat1(p, pIndexXInfo, pWrite, zTab, zIdx, pzErr);
7079 iPrev = iRowid;
7080 }
7081 if( rc==SQLITE_OK && p->iSample<100 ){
7082 rc = sqlite3_exec(p->dbv,
7083 "DROP TABLE IF EXISTS temp." UNIQUE_TABLE_NAME, 0,0,0
7084 );
7085 }
7086
7087 idxFinalize(&rc, pAllIndex);
7088 idxFinalize(&rc, pIndexXInfo);
7089 idxFinalize(&rc, pWrite);
7090
7091 for(i=0; i<pCtx->nSlot; i++){
7092 sqlite3_free(pCtx->aSlot[i].z);
7093 }
7094 sqlite3_free(pCtx);
7095
7096 if( rc==SQLITE_OK ){
7097 rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_master", 0, 0, 0);
7098 }
7099
7100 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
7101 return rc;
7102 }
7103
7104 /*
7105 ** Allocate a new sqlite3expert object.
7106 */
7107 sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErrmsg){
7108 int rc = SQLITE_OK;
7109 sqlite3expert *pNew;
7110
7111 pNew = (sqlite3expert*)idxMalloc(&rc, sizeof(sqlite3expert));
7112
7113 /* Open two in-memory databases to work with. The "vtab database" (dbv)
7114 ** will contain a virtual table corresponding to each real table in
7115 ** the user database schema, and a copy of each view. It is used to
7116 ** collect information regarding the WHERE, ORDER BY and other clauses
7117 ** of the user's query.
7118 */
7119 if( rc==SQLITE_OK ){
7120 pNew->db = db;
7121 pNew->iSample = 100;
7122 rc = sqlite3_open(":memory:", &pNew->dbv);
7123 }
7124 if( rc==SQLITE_OK ){
7125 rc = sqlite3_open(":memory:", &pNew->dbm);
7126 if( rc==SQLITE_OK ){
7127 sqlite3_db_config(pNew->dbm, SQLITE_DBCONFIG_TRIGGER_EQP, 1, (int*)0);
7128 }
7129 }
7130
7131
7132 /* Copy the entire schema of database [db] into [dbm]. */
7133 if( rc==SQLITE_OK ){
7134 sqlite3_stmt *pSql;
7135 rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
7136 "SELECT sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%%'"
7137 " AND sql NOT LIKE 'CREATE VIRTUAL %%'"
7138 );
7139 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
7140 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
7141 rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
7142 }
7143 idxFinalize(&rc, pSql);
7144 }
7145
7146 /* Create the vtab schema */
7147 if( rc==SQLITE_OK ){
7148 rc = idxCreateVtabSchema(pNew, pzErrmsg);
7149 }
7150
7151 /* Register the auth callback with dbv */
7152 if( rc==SQLITE_OK ){
7153 sqlite3_set_authorizer(pNew->dbv, idxAuthCallback, (void*)pNew);
7154 }
7155
7156 /* If an error has occurred, free the new object and reutrn NULL. Otherwise,
7157 ** return the new sqlite3expert handle. */
7158 if( rc!=SQLITE_OK ){
7159 sqlite3_expert_destroy(pNew);
7160 pNew = 0;
7161 }
7162 return pNew;
7163 }
7164
7165 /*
7166 ** Configure an sqlite3expert object.
7167 */
7168 int sqlite3_expert_config(sqlite3expert *p, int op, ...){
7169 int rc = SQLITE_OK;
7170 va_list ap;
7171 va_start(ap, op);
7172 switch( op ){
7173 case EXPERT_CONFIG_SAMPLE: {
7174 int iVal = va_arg(ap, int);
7175 if( iVal<0 ) iVal = 0;
7176 if( iVal>100 ) iVal = 100;
7177 p->iSample = iVal;
7178 break;
7179 }
7180 default:
7181 rc = SQLITE_NOTFOUND;
7182 break;
7183 }
7184
7185 va_end(ap);
7186 return rc;
7187 }
7188
7189 /*
7190 ** Add an SQL statement to the analysis.
7191 */
7192 int sqlite3_expert_sql(
7193 sqlite3expert *p, /* From sqlite3_expert_new() */
7194 const char *zSql, /* SQL statement to add */
7195 char **pzErr /* OUT: Error message (if any) */
7196 ){
7197 IdxScan *pScanOrig = p->pScan;
7198 IdxStatement *pStmtOrig = p->pStatement;
7199 int rc = SQLITE_OK;
7200 const char *zStmt = zSql;
7201
7202 if( p->bRun ) return SQLITE_MISUSE;
7203
7204 while( rc==SQLITE_OK && zStmt && zStmt[0] ){
7205 sqlite3_stmt *pStmt = 0;
7206 rc = sqlite3_prepare_v2(p->dbv, zStmt, -1, &pStmt, &zStmt);
7207 if( rc==SQLITE_OK ){
7208 if( pStmt ){
7209 IdxStatement *pNew;
7210 const char *z = sqlite3_sql(pStmt);
7211 int n = STRLEN(z);
7212 pNew = (IdxStatement*)idxMalloc(&rc, sizeof(IdxStatement) + n+1);
7213 if( rc==SQLITE_OK ){
7214 pNew->zSql = (char*)&pNew[1];
7215 memcpy(pNew->zSql, z, n+1);
7216 pNew->pNext = p->pStatement;
7217 if( p->pStatement ) pNew->iId = p->pStatement->iId+1;
7218 p->pStatement = pNew;
7219 }
7220 sqlite3_finalize(pStmt);
7221 }
7222 }else{
7223 idxDatabaseError(p->dbv, pzErr);
7224 }
7225 }
7226
7227 if( rc!=SQLITE_OK ){
7228 idxScanFree(p->pScan, pScanOrig);
7229 idxStatementFree(p->pStatement, pStmtOrig);
7230 p->pScan = pScanOrig;
7231 p->pStatement = pStmtOrig;
7232 }
7233
7234 return rc;
7235 }
7236
7237 int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr){
7238 int rc;
7239 IdxHashEntry *pEntry;
7240
7241 /* Do trigger processing to collect any extra IdxScan structures */
7242 rc = idxProcessTriggers(p, pzErr);
7243
7244 /* Create candidate indexes within the in-memory database file */
7245 if( rc==SQLITE_OK ){
7246 rc = idxCreateCandidates(p, pzErr);
7247 }
7248
7249 /* Generate the stat1 data */
7250 if( rc==SQLITE_OK ){
7251 rc = idxPopulateStat1(p, pzErr);
7252 }
7253
7254 /* Formulate the EXPERT_REPORT_CANDIDATES text */
7255 for(pEntry=p->hIdx.pFirst; pEntry; pEntry=pEntry->pNext){
7256 p->zCandidates = idxAppendText(&rc, p->zCandidates,
7257 "%s;%s%s\n", pEntry->zVal,
7258 pEntry->zVal2 ? " -- stat1: " : "", pEntry->zVal2
7259 );
7260 }
7261
7262 /* Figure out which of the candidate indexes are preferred by the query
7263 ** planner and report the results to the user. */
7264 if( rc==SQLITE_OK ){
7265 rc = idxFindIndexes(p, pzErr);
7266 }
7267
7268 if( rc==SQLITE_OK ){
7269 p->bRun = 1;
7270 }
7271 return rc;
7272 }
7273
7274 /*
7275 ** Return the total number of statements that have been added to this
7276 ** sqlite3expert using sqlite3_expert_sql().
7277 */
7278 int sqlite3_expert_count(sqlite3expert *p){
7279 int nRet = 0;
7280 if( p->pStatement ) nRet = p->pStatement->iId+1;
7281 return nRet;
7282 }
7283
7284 /*
7285 ** Return a component of the report.
7286 */
7287 const char *sqlite3_expert_report(sqlite3expert *p, int iStmt, int eReport){
7288 const char *zRet = 0;
7289 IdxStatement *pStmt;
7290
7291 if( p->bRun==0 ) return 0;
7292 for(pStmt=p->pStatement; pStmt && pStmt->iId!=iStmt; pStmt=pStmt->pNext);
7293 switch( eReport ){
7294 case EXPERT_REPORT_SQL:
7295 if( pStmt ) zRet = pStmt->zSql;
7296 break;
7297 case EXPERT_REPORT_INDEXES:
7298 if( pStmt ) zRet = pStmt->zIdx;
7299 break;
7300 case EXPERT_REPORT_PLAN:
7301 if( pStmt ) zRet = pStmt->zEQP;
7302 break;
7303 case EXPERT_REPORT_CANDIDATES:
7304 zRet = p->zCandidates;
7305 break;
7306 }
7307 return zRet;
7308 }
7309
7310 /*
7311 ** Free an sqlite3expert object.
7312 */
7313 void sqlite3_expert_destroy(sqlite3expert *p){
7314 if( p ){
7315 sqlite3_close(p->dbm);
7316 sqlite3_close(p->dbv);
7317 idxScanFree(p->pScan, 0);
7318 idxStatementFree(p->pStatement, 0);
7319 idxTableFree(p->pTable);
7320 idxWriteFree(p->pWrite);
7321 idxHashClear(&p->hIdx);
7322 sqlite3_free(p->zCandidates);
7323 sqlite3_free(p);
7324 }
7325 }
7326
7327 /************************* End ../ext/expert/sqlite3expert.c ********************/
7328
7329 #if defined(SQLITE_ENABLE_SESSION)
7330 /*
7331 ** State information for a single open session
7332 */
@@ -2180,21 +7349,28 @@
7349 int mode; /* Mode prior to ".explain on" */
7350 int showHeader; /* The ".header" setting prior to ".explain on" */
7351 int colWidth[100]; /* Column widths prior to ".explain on" */
7352 };
7353
7354 typedef struct ExpertInfo ExpertInfo;
7355 struct ExpertInfo {
7356 sqlite3expert *pExpert;
7357 int bVerbose;
7358 };
7359
7360 /*
7361 ** State information about the database connection is contained in an
7362 ** instance of the following structure.
7363 */
7364 typedef struct ShellState ShellState;
7365 struct ShellState {
7366 sqlite3 *db; /* The database */
7367 u8 autoExplain; /* Automatically turn on .explain mode */
7368 u8 autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
7369 u8 statsOn; /* True to display memory stats before each finalize */
7370 u8 scanstatsOn; /* True to display scan stats before each finalize */
7371 u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
7372 int outCount; /* Revert to stdout when reaching zero */
7373 int cnt; /* Number of records displayed so far */
7374 FILE *out; /* Write results here */
7375 FILE *traceOut; /* Output for sqlite3_trace() */
7376 int nErr; /* Number of errors seen */
@@ -2224,12 +7400,28 @@
7400 int iIndent; /* Index of current op in aiIndent[] */
7401 #if defined(SQLITE_ENABLE_SESSION)
7402 int nSession; /* Number of active sessions */
7403 OpenSession aSession[4]; /* Array of sessions. [0] is in focus. */
7404 #endif
7405 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
7406 };
7407
7408
7409 /* Allowed values for ShellState.autoEQP
7410 */
7411 #define AUTOEQP_off 0
7412 #define AUTOEQP_on 1
7413 #define AUTOEQP_trigger 2
7414 #define AUTOEQP_full 3
7415
7416 /* Allowed values for ShellState.openMode
7417 */
7418 #define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */
7419 #define SHELL_OPEN_NORMAL 1 /* Normal database file */
7420 #define SHELL_OPEN_APPENDVFS 2 /* Use appendvfs */
7421 #define SHELL_OPEN_ZIPFILE 3 /* Use the zipfile virtual table */
7422
7423 /*
7424 ** These are the allowed shellFlgs values
7425 */
7426 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
7427 #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
@@ -2652,10 +7844,26 @@
7844 z[n] = 0;
7845 printSchemaLine(out, z, zTail);
7846 z[n] = c;
7847 }
7848
7849 /*
7850 ** Return true if string z[] has nothing but whitespace and comments to the
7851 ** end of the first line.
7852 */
7853 static int wsToEol(const char *z){
7854 int i;
7855 for(i=0; z[i]; i++){
7856 if( z[i]=='\n' ) return 1;
7857 if( IsSpace(z[i]) ) continue;
7858 if( z[i]=='-' && z[i+1]=='-' ) return 1;
7859 return 0;
7860 }
7861 return 1;
7862 }
7863
7864
7865 /*
7866 ** This is the callback routine that the shell
7867 ** invokes for each row of a query result.
7868 */
7869 static int shell_callback(
@@ -2791,17 +7999,19 @@
7999 z[j++] = c;
8000 }
8001 while( j>0 && IsSpace(z[j-1]) ){ j--; }
8002 z[j] = 0;
8003 if( strlen30(z)>=79 ){
8004 for(i=j=0; (c = z[i])!=0; i++){ /* Copy changes from z[i] back to z[j] */
8005 if( c==cEnd ){
8006 cEnd = 0;
8007 }else if( c=='"' || c=='\'' || c=='`' ){
8008 cEnd = c;
8009 }else if( c=='[' ){
8010 cEnd = ']';
8011 }else if( c=='-' && z[i+1]=='-' ){
8012 cEnd = '\n';
8013 }else if( c=='(' ){
8014 nParen++;
8015 }else if( c==')' ){
8016 nParen--;
8017 if( nLine>0 && nParen==0 && j>0 ){
@@ -2808,11 +8018,13 @@
8018 printSchemaLineN(p->out, z, j, "\n");
8019 j = 0;
8020 }
8021 }
8022 z[j++] = c;
8023 if( nParen==1 && cEnd==0
8024 && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1)))
8025 ){
8026 if( c=='\n' ) j--;
8027 printSchemaLineN(p->out, z, j, "\n ");
8028 j = 0;
8029 nLine++;
8030 while( IsSpace(z[i+1]) ){ i++; }
@@ -3206,11 +8418,11 @@
8418 { "write_bytes: ", "Bytes written to storage:" },
8419 { "cancelled_write_bytes: ", "Cancelled write bytes:" },
8420 };
8421 int i;
8422 for(i=0; i<ArraySize(aTrans); i++){
8423 int n = strlen30(aTrans[i].zPattern);
8424 if( strncmp(aTrans[i].zPattern, z, n)==0 ){
8425 utf8_printf(out, "%-36s %s", aTrans[i].zDesc, &z[n]);
8426 break;
8427 }
8428 }
@@ -3606,10 +8818,83 @@
8818 rc = sqlite3_step(pStmt);
8819 } while( rc == SQLITE_ROW );
8820 }
8821 }
8822 }
8823
8824 /*
8825 ** This function is called to process SQL if the previous shell command
8826 ** was ".expert". It passes the SQL in the second argument directly to
8827 ** the sqlite3expert object.
8828 **
8829 ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
8830 ** code. In this case, (*pzErr) may be set to point to a buffer containing
8831 ** an English language error message. It is the responsibility of the
8832 ** caller to eventually free this buffer using sqlite3_free().
8833 */
8834 static int expertHandleSQL(
8835 ShellState *pState,
8836 const char *zSql,
8837 char **pzErr
8838 ){
8839 assert( pState->expert.pExpert );
8840 assert( pzErr==0 || *pzErr==0 );
8841 return sqlite3_expert_sql(pState->expert.pExpert, zSql, pzErr);
8842 }
8843
8844 /*
8845 ** This function is called either to silently clean up the object
8846 ** created by the ".expert" command (if bCancel==1), or to generate a
8847 ** report from it and then clean it up (if bCancel==0).
8848 **
8849 ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
8850 ** code. In this case, (*pzErr) may be set to point to a buffer containing
8851 ** an English language error message. It is the responsibility of the
8852 ** caller to eventually free this buffer using sqlite3_free().
8853 */
8854 static int expertFinish(
8855 ShellState *pState,
8856 int bCancel,
8857 char **pzErr
8858 ){
8859 int rc = SQLITE_OK;
8860 sqlite3expert *p = pState->expert.pExpert;
8861 assert( p );
8862 assert( bCancel || pzErr==0 || *pzErr==0 );
8863 if( bCancel==0 ){
8864 FILE *out = pState->out;
8865 int bVerbose = pState->expert.bVerbose;
8866
8867 rc = sqlite3_expert_analyze(p, pzErr);
8868 if( rc==SQLITE_OK ){
8869 int nQuery = sqlite3_expert_count(p);
8870 int i;
8871
8872 if( bVerbose ){
8873 const char *zCand = sqlite3_expert_report(p,0,EXPERT_REPORT_CANDIDATES);
8874 raw_printf(out, "-- Candidates -----------------------------\n");
8875 raw_printf(out, "%s\n", zCand);
8876 }
8877 for(i=0; i<nQuery; i++){
8878 const char *zSql = sqlite3_expert_report(p, i, EXPERT_REPORT_SQL);
8879 const char *zIdx = sqlite3_expert_report(p, i, EXPERT_REPORT_INDEXES);
8880 const char *zEQP = sqlite3_expert_report(p, i, EXPERT_REPORT_PLAN);
8881 if( zIdx==0 ) zIdx = "(no new indexes)\n";
8882 if( bVerbose ){
8883 raw_printf(out, "-- Query %d --------------------------------\n",i+1);
8884 raw_printf(out, "%s\n\n", zSql);
8885 }
8886 raw_printf(out, "%s\n", zIdx);
8887 raw_printf(out, "%s\n", zEQP);
8888 }
8889 }
8890 }
8891 sqlite3_expert_destroy(p);
8892 pState->expert.pExpert = 0;
8893 return rc;
8894 }
8895
8896
8897 /*
8898 ** Execute a statement or set of statements. Print
8899 ** any result rows/columns depending on the current mode
8900 ** set via the supplied callback.
@@ -3632,10 +8917,15 @@
8917 const char *zLeftover; /* Tail of unprocessed SQL */
8918
8919 if( pzErrMsg ){
8920 *pzErrMsg = NULL;
8921 }
8922
8923 if( pArg->expert.pExpert ){
8924 rc = expertHandleSQL(pArg, zSql, pzErrMsg);
8925 return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
8926 }
8927
8928 while( zSql[0] && (SQLITE_OK == rc) ){
8929 static const char *zStmtSql;
8930 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
8931 if( SQLITE_OK != rc ){
@@ -3666,11 +8956,16 @@
8956
8957 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
8958 if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
8959 sqlite3_stmt *pExplain;
8960 char *zEQP;
8961 int triggerEQP = 0;
8962 disable_debug_trace_modes();
8963 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
8964 if( pArg->autoEQP>=AUTOEQP_trigger ){
8965 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
8966 }
8967 zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
8968 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
8969 if( rc==SQLITE_OK ){
8970 while( sqlite3_step(pExplain)==SQLITE_ROW ){
8971 raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
@@ -3679,11 +8974,11 @@
8974 utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
8975 }
8976 }
8977 sqlite3_finalize(pExplain);
8978 sqlite3_free(zEQP);
8979 if( pArg->autoEQP>=AUTOEQP_full ){
8980 /* Also do an EXPLAIN for ".eqp full" mode */
8981 zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql);
8982 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
8983 if( rc==SQLITE_OK ){
8984 pArg->cMode = MODE_Explain;
@@ -3692,10 +8987,11 @@
8987 explain_data_delete(pArg);
8988 }
8989 sqlite3_finalize(pExplain);
8990 sqlite3_free(zEQP);
8991 }
8992 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, triggerEQP, 0);
8993 restore_debug_trace_modes();
8994 }
8995
8996 if( pArg ){
8997 pArg->cMode = pArg->mode;
@@ -4032,10 +9328,13 @@
9328
9329 /*
9330 ** Text of a help message
9331 */
9332 static char zHelp[] =
9333 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE)
9334 ".archive ... Manage SQL archives: \".archive --help\" for details\n"
9335 #endif
9336 #ifndef SQLITE_OMIT_AUTHORIZATION
9337 ".auth ON|OFF Show authorizer callbacks\n"
9338 #endif
9339 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
9340 ".bail on|off Stop after hitting an error. Default OFF\n"
@@ -4050,10 +9349,11 @@
9349 " If TABLE specified, only dump tables matching\n"
9350 " LIKE pattern TABLE.\n"
9351 ".echo on|off Turn command echo on or off\n"
9352 ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
9353 ".exit Exit this program\n"
9354 ".expert EXPERIMENTAL. Suggest indexes for specified queries\n"
9355 /* Because explain mode comes on automatically now, the ".explain" mode
9356 ** is removed from the help screen. It is still supported for legacy, however */
9357 /*".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"*/
9358 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
9359 ".headers on|off Turn display of headers on or off\n"
@@ -4233,19 +9533,63 @@
9533 if( sqlite3_strglob(pSession->azFilter[i], zTab)==0 ) return 0;
9534 }
9535 return 1;
9536 }
9537 #endif
9538
9539 /*
9540 ** Try to deduce the type of file for zName based on its content. Return
9541 ** one of the SHELL_OPEN_* constants.
9542 */
9543 static int deduceDatabaseType(const char *zName){
9544 FILE *f = fopen(zName, "rb");
9545 size_t n;
9546 int rc = SHELL_OPEN_UNSPEC;
9547 char zBuf[100];
9548 if( f==0 ) return SHELL_OPEN_NORMAL;
9549 fseek(f, -25, SEEK_END);
9550 n = fread(zBuf, 25, 1, f);
9551 if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){
9552 rc = SHELL_OPEN_APPENDVFS;
9553 }else{
9554 fseek(f, -22, SEEK_END);
9555 n = fread(zBuf, 22, 1, f);
9556 if( n==1 && zBuf[0]==0x50 && zBuf[1]==0x4b && zBuf[2]==0x05
9557 && zBuf[3]==0x06 ){
9558 rc = SHELL_OPEN_ZIPFILE;
9559 }
9560 }
9561 fclose(f);
9562 return rc;
9563 }
9564
9565 /*
9566 ** Make sure the database is open. If it is not, then open it. If
9567 ** the database fails to open, print an error message and exit.
9568 */
9569 static void open_db(ShellState *p, int keepAlive){
9570 if( p->db==0 ){
9571 sqlite3_initialize();
9572 if( p->openMode==SHELL_OPEN_UNSPEC && access(p->zDbFilename,0)==0 ){
9573 p->openMode = deduceDatabaseType(p->zDbFilename);
9574 }
9575 switch( p->openMode ){
9576 case SHELL_OPEN_APPENDVFS: {
9577 sqlite3_open_v2(p->zDbFilename, &p->db,
9578 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
9579 break;
9580 }
9581 case SHELL_OPEN_ZIPFILE: {
9582 sqlite3_open(":memory:", &p->db);
9583 break;
9584 }
9585 case SHELL_OPEN_UNSPEC:
9586 case SHELL_OPEN_NORMAL: {
9587 sqlite3_open(p->zDbFilename, &p->db);
9588 break;
9589 }
9590 }
9591 globalDb = p->db;
9592 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
9593 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
9594 p->zDbFilename, sqlite3_errmsg(p->db));
9595 if( keepAlive ) return;
@@ -4255,12 +9599,24 @@
9599 sqlite3_enable_load_extension(p->db, 1);
9600 #endif
9601 sqlite3_fileio_init(p->db, 0, 0);
9602 sqlite3_shathree_init(p->db, 0, 0);
9603 sqlite3_completion_init(p->db, 0, 0);
9604 #ifdef SQLITE_HAVE_ZLIB
9605 sqlite3_zipfile_init(p->db, 0, 0);
9606 sqlite3_sqlar_init(p->db, 0, 0);
9607 #endif
9608 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
9609 shellAddSchemaName, 0, 0);
9610 sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
9611 shellModuleSchema, 0, 0);
9612 if( p->openMode==SHELL_OPEN_ZIPFILE ){
9613 char *zSql = sqlite3_mprintf(
9614 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
9615 sqlite3_exec(p->db, zSql, 0, 0, 0);
9616 sqlite3_free(zSql);
9617 }
9618 }
9619 }
9620
9621 #if HAVE_READLINE || HAVE_EDITLINE
9622 /*
@@ -4294,11 +9650,11 @@
9650 #elif HAVE_LINENOISE
9651 /*
9652 ** Linenoise completion callback
9653 */
9654 static void linenoise_completion(const char *zLine, linenoiseCompletions *lc){
9655 int nLine = strlen30(zLine);
9656 int i, iStart;
9657 sqlite3_stmt *pStmt = 0;
9658 char *zSql;
9659 char zBuf[1000];
9660
@@ -4520,11 +9876,11 @@
9876 FILE *f = (FILE*)pArg;
9877 UNUSED_PARAMETER(mType);
9878 UNUSED_PARAMETER(pP);
9879 if( f ){
9880 const char *z = (const char*)pX;
9881 int i = strlen30(z);
9882 while( i>0 && z[i-1]==';' ){ i--; }
9883 utf8_printf(f, "%.*s;\n", i, z);
9884 }
9885 return 0;
9886 }
@@ -4709,11 +10065,11 @@
10065 sqlite3_stmt *pInsert = 0;
10066 char *zQuery = 0;
10067 char *zInsert = 0;
10068 int rc;
10069 int i, j, n;
10070 int nTable = strlen30(zTable);
10071 int k = 0;
10072 int cnt = 0;
10073 const int spinRate = 10000;
10074
10075 zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
@@ -4730,11 +10086,11 @@
10086 raw_printf(stderr, "out of memory\n");
10087 goto end_data_xfer;
10088 }
10089 sqlite3_snprintf(200+nTable,zInsert,
10090 "INSERT OR IGNORE INTO \"%s\" VALUES(?", zTable);
10091 i = strlen30(zInsert);
10092 for(j=1; j<n; j++){
10093 memcpy(zInsert+i, ",?", 2);
10094 i += 2;
10095 }
10096 memcpy(zInsert+i, ");", 3);
@@ -5312,11 +10668,11 @@
10668 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
10669 ;
10670 const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
10671
10672 for(i=2; i<nArg; i++){
10673 int n = strlen30(azArg[i]);
10674 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
10675 bVerbose = 1;
10676 }
10677 else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){
10678 bGroupByParent = 1;
@@ -5415,20 +10771,822 @@
10771 ShellState *pState, /* Current shell tool state */
10772 char **azArg, /* Array of arguments passed to dot command */
10773 int nArg /* Number of entries in azArg[] */
10774 ){
10775 int n;
10776 n = (nArg>=2 ? strlen30(azArg[1]) : 0);
10777 if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage;
10778 return lintFkeyIndexes(pState, azArg, nArg);
10779
10780 usage:
10781 raw_printf(stderr, "Usage %s sub-command ?switches...?\n", azArg[0]);
10782 raw_printf(stderr, "Where sub-commands are:\n");
10783 raw_printf(stderr, " fkey-indexes\n");
10784 return SQLITE_ERROR;
10785 }
10786
10787 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
10788 /*********************************************************************************
10789 ** The ".archive" or ".ar" command.
10790 */
10791 static void shellPrepare(
10792 sqlite3 *db,
10793 int *pRc,
10794 const char *zSql,
10795 sqlite3_stmt **ppStmt
10796 ){
10797 *ppStmt = 0;
10798 if( *pRc==SQLITE_OK ){
10799 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
10800 if( rc!=SQLITE_OK ){
10801 raw_printf(stderr, "sql error: %s (%d)\n",
10802 sqlite3_errmsg(db), sqlite3_errcode(db)
10803 );
10804 *pRc = rc;
10805 }
10806 }
10807 }
10808
10809 static void shellPreparePrintf(
10810 sqlite3 *db,
10811 int *pRc,
10812 sqlite3_stmt **ppStmt,
10813 const char *zFmt,
10814 ...
10815 ){
10816 *ppStmt = 0;
10817 if( *pRc==SQLITE_OK ){
10818 va_list ap;
10819 char *z;
10820 va_start(ap, zFmt);
10821 z = sqlite3_vmprintf(zFmt, ap);
10822 if( z==0 ){
10823 *pRc = SQLITE_NOMEM;
10824 }else{
10825 shellPrepare(db, pRc, z, ppStmt);
10826 sqlite3_free(z);
10827 }
10828 }
10829 }
10830
10831 static void shellFinalize(
10832 int *pRc,
10833 sqlite3_stmt *pStmt
10834 ){
10835 if( pStmt ){
10836 sqlite3 *db = sqlite3_db_handle(pStmt);
10837 int rc = sqlite3_finalize(pStmt);
10838 if( *pRc==SQLITE_OK ){
10839 if( rc!=SQLITE_OK ){
10840 raw_printf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
10841 }
10842 *pRc = rc;
10843 }
10844 }
10845 }
10846
10847 static void shellReset(
10848 int *pRc,
10849 sqlite3_stmt *pStmt
10850 ){
10851 int rc = sqlite3_reset(pStmt);
10852 if( *pRc==SQLITE_OK ){
10853 if( rc!=SQLITE_OK ){
10854 sqlite3 *db = sqlite3_db_handle(pStmt);
10855 raw_printf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
10856 }
10857 *pRc = rc;
10858 }
10859 }
10860 /*
10861 ** Structure representing a single ".ar" command.
10862 */
10863 typedef struct ArCommand ArCommand;
10864 struct ArCommand {
10865 int eCmd; /* An AR_CMD_* value */
10866 const char *zFile; /* --file argument, or NULL */
10867 const char *zDir; /* --directory argument, or NULL */
10868 int bVerbose; /* True if --verbose */
10869 int bZip; /* True if --zip */
10870 int nArg; /* Number of command arguments */
10871 char **azArg; /* Array of command arguments */
10872 };
10873
10874 /*
10875 ** Print a usage message for the .ar command to stderr and return SQLITE_ERROR.
10876 */
10877 static int arUsage(FILE *f){
10878 raw_printf(f,
10879 "\n"
10880 "Usage: .ar [OPTION...] [FILE...]\n"
10881 "The .ar command manages sqlar archives.\n"
10882 "\n"
10883 "Examples:\n"
10884 " .ar -cf archive.sar foo bar # Create archive.sar from files foo and bar\n"
10885 " .ar -tf archive.sar # List members of archive.sar\n"
10886 " .ar -xvf archive.sar # Verbosely extract files from archive.sar\n"
10887 "\n"
10888 "Each command line must feature exactly one command option:\n"
10889 " -c, --create Create a new archive\n"
10890 " -u, --update Update or add files to an existing archive\n"
10891 " -t, --list List contents of archive\n"
10892 " -x, --extract Extract files from archive\n"
10893 "\n"
10894 "And zero or more optional options:\n"
10895 " -v, --verbose Print each filename as it is processed\n"
10896 " -f FILE, --file FILE Operate on archive FILE (default is current db)\n"
10897 " -C DIR, --directory DIR Change to directory DIR to read/extract files\n"
10898 "\n"
10899 "See also: http://sqlite.org/cli.html#sqlar_archive_support\n"
10900 "\n"
10901 );
10902 return SQLITE_ERROR;
10903 }
10904
10905 /*
10906 ** Print an error message for the .ar command to stderr and return
10907 ** SQLITE_ERROR.
10908 */
10909 static int arErrorMsg(const char *zFmt, ...){
10910 va_list ap;
10911 char *z;
10912 va_start(ap, zFmt);
10913 z = sqlite3_vmprintf(zFmt, ap);
10914 va_end(ap);
10915 raw_printf(stderr, "Error: %s (try \".ar --help\")\n", z);
10916 sqlite3_free(z);
10917 return SQLITE_ERROR;
10918 }
10919
10920 /*
10921 ** Values for ArCommand.eCmd.
10922 */
10923 #define AR_CMD_CREATE 1
10924 #define AR_CMD_EXTRACT 2
10925 #define AR_CMD_LIST 3
10926 #define AR_CMD_UPDATE 4
10927 #define AR_CMD_HELP 5
10928
10929 /*
10930 ** Other (non-command) switches.
10931 */
10932 #define AR_SWITCH_VERBOSE 6
10933 #define AR_SWITCH_FILE 7
10934 #define AR_SWITCH_DIRECTORY 8
10935 #define AR_SWITCH_ZIP 9
10936
10937 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
10938 switch( eSwitch ){
10939 case AR_CMD_CREATE:
10940 case AR_CMD_EXTRACT:
10941 case AR_CMD_LIST:
10942 case AR_CMD_UPDATE:
10943 case AR_CMD_HELP:
10944 if( pAr->eCmd ){
10945 return arErrorMsg("multiple command options");
10946 }
10947 pAr->eCmd = eSwitch;
10948 break;
10949
10950 case AR_SWITCH_VERBOSE:
10951 pAr->bVerbose = 1;
10952 break;
10953 case AR_SWITCH_ZIP:
10954 pAr->bZip = 1;
10955 break;
10956
10957 case AR_SWITCH_FILE:
10958 pAr->zFile = zArg;
10959 break;
10960 case AR_SWITCH_DIRECTORY:
10961 pAr->zDir = zArg;
10962 break;
10963 }
10964
10965 return SQLITE_OK;
10966 }
10967
10968 /*
10969 ** Parse the command line for an ".ar" command. The results are written into
10970 ** structure (*pAr). SQLITE_OK is returned if the command line is parsed
10971 ** successfully, otherwise an error message is written to stderr and
10972 ** SQLITE_ERROR returned.
10973 */
10974 static int arParseCommand(
10975 char **azArg, /* Array of arguments passed to dot command */
10976 int nArg, /* Number of entries in azArg[] */
10977 ArCommand *pAr /* Populate this object */
10978 ){
10979 struct ArSwitch {
10980 char cShort;
10981 const char *zLong;
10982 int eSwitch;
10983 int bArg;
10984 } aSwitch[] = {
10985 { 'c', "create", AR_CMD_CREATE, 0 },
10986 { 'x', "extract", AR_CMD_EXTRACT, 0 },
10987 { 't', "list", AR_CMD_LIST, 0 },
10988 { 'u', "update", AR_CMD_UPDATE, 0 },
10989 { 'h', "help", AR_CMD_HELP, 0 },
10990 { 'v', "verbose", AR_SWITCH_VERBOSE, 0 },
10991 { 'f', "file", AR_SWITCH_FILE, 1 },
10992 { 'C', "directory", AR_SWITCH_DIRECTORY, 1 },
10993 { 'z', "zip", AR_SWITCH_ZIP, 0 }
10994 };
10995 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
10996 struct ArSwitch *pEnd = &aSwitch[nSwitch];
10997
10998 if( nArg<=1 ){
10999 return arUsage(stderr);
11000 }else{
11001 char *z = azArg[1];
11002 memset(pAr, 0, sizeof(ArCommand));
11003
11004 if( z[0]!='-' ){
11005 /* Traditional style [tar] invocation */
11006 int i;
11007 int iArg = 2;
11008 for(i=0; z[i]; i++){
11009 const char *zArg = 0;
11010 struct ArSwitch *pOpt;
11011 for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){
11012 if( z[i]==pOpt->cShort ) break;
11013 }
11014 if( pOpt==pEnd ){
11015 return arErrorMsg("unrecognized option: %c", z[i]);
11016 }
11017 if( pOpt->bArg ){
11018 if( iArg>=nArg ){
11019 return arErrorMsg("option requires an argument: %c",z[i]);
11020 }
11021 zArg = azArg[iArg++];
11022 }
11023 if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR;
11024 }
11025 pAr->nArg = nArg-iArg;
11026 if( pAr->nArg>0 ){
11027 pAr->azArg = &azArg[iArg];
11028 }
11029 }else{
11030 /* Non-traditional invocation */
11031 int iArg;
11032 for(iArg=1; iArg<nArg; iArg++){
11033 int n;
11034 z = azArg[iArg];
11035 if( z[0]!='-' ){
11036 /* All remaining command line words are command arguments. */
11037 pAr->azArg = &azArg[iArg];
11038 pAr->nArg = nArg-iArg;
11039 break;
11040 }
11041 n = strlen30(z);
11042
11043 if( z[1]!='-' ){
11044 int i;
11045 /* One or more short options */
11046 for(i=1; i<n; i++){
11047 const char *zArg = 0;
11048 struct ArSwitch *pOpt;
11049 for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){
11050 if( z[i]==pOpt->cShort ) break;
11051 }
11052 if( pOpt==pEnd ){
11053 return arErrorMsg("unrecognized option: %c\n", z[i]);
11054 }
11055 if( pOpt->bArg ){
11056 if( i<(n-1) ){
11057 zArg = &z[i+1];
11058 i = n;
11059 }else{
11060 if( iArg>=(nArg-1) ){
11061 return arErrorMsg("option requires an argument: %c\n",z[i]);
11062 }
11063 zArg = azArg[++iArg];
11064 }
11065 }
11066 if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR;
11067 }
11068 }else if( z[2]=='\0' ){
11069 /* A -- option, indicating that all remaining command line words
11070 ** are command arguments. */
11071 pAr->azArg = &azArg[iArg+1];
11072 pAr->nArg = nArg-iArg-1;
11073 break;
11074 }else{
11075 /* A long option */
11076 const char *zArg = 0; /* Argument for option, if any */
11077 struct ArSwitch *pMatch = 0; /* Matching option */
11078 struct ArSwitch *pOpt; /* Iterator */
11079 for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){
11080 const char *zLong = pOpt->zLong;
11081 if( (n-2)<=strlen30(zLong) && 0==memcmp(&z[2], zLong, n-2) ){
11082 if( pMatch ){
11083 return arErrorMsg("ambiguous option: %s",z);
11084 }else{
11085 pMatch = pOpt;
11086 }
11087 }
11088 }
11089
11090 if( pMatch==0 ){
11091 return arErrorMsg("unrecognized option: %s", z);
11092 }
11093 if( pMatch->bArg ){
11094 if( iArg>=(nArg-1) ){
11095 return arErrorMsg("option requires an argument: %s", z);
11096 }
11097 zArg = azArg[++iArg];
11098 }
11099 if( arProcessSwitch(pAr, pMatch->eSwitch, zArg) ) return SQLITE_ERROR;
11100 }
11101 }
11102 }
11103 }
11104
11105 return SQLITE_OK;
11106 }
11107
11108 /*
11109 ** This function assumes that all arguments within the ArCommand.azArg[]
11110 ** array refer to archive members, as for the --extract or --list commands.
11111 ** It checks that each of them are present. If any specified file is not
11112 ** present in the archive, an error is printed to stderr and an error
11113 ** code returned. Otherwise, if all specified arguments are present in
11114 ** the archive, SQLITE_OK is returned.
11115 **
11116 ** This function strips any trailing '/' characters from each argument.
11117 ** This is consistent with the way the [tar] command seems to work on
11118 ** Linux.
11119 */
11120 static int arCheckEntries(sqlite3 *db, ArCommand *pAr){
11121 int rc = SQLITE_OK;
11122 if( pAr->nArg ){
11123 int i;
11124 sqlite3_stmt *pTest = 0;
11125
11126 shellPreparePrintf(db, &rc, &pTest, "SELECT name FROM %s WHERE name=?1",
11127 pAr->bZip ? "zipfile(?2)" : "sqlar"
11128 );
11129 if( rc==SQLITE_OK && pAr->bZip ){
11130 sqlite3_bind_text(pTest, 2, pAr->zFile, -1, SQLITE_TRANSIENT);
11131 }
11132 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11133 char *z = pAr->azArg[i];
11134 int n = strlen30(z);
11135 int bOk = 0;
11136 while( n>0 && z[n-1]=='/' ) n--;
11137 z[n] = '\0';
11138 sqlite3_bind_text(pTest, 1, z, -1, SQLITE_STATIC);
11139 if( SQLITE_ROW==sqlite3_step(pTest) ){
11140 bOk = 1;
11141 }
11142 shellReset(&rc, pTest);
11143 if( rc==SQLITE_OK && bOk==0 ){
11144 raw_printf(stderr, "not found in archive: %s\n", z);
11145 rc = SQLITE_ERROR;
11146 }
11147 }
11148 shellFinalize(&rc, pTest);
11149 }
11150
11151 return rc;
11152 }
11153
11154 /*
11155 ** Format a WHERE clause that can be used against the "sqlar" table to
11156 ** identify all archive members that match the command arguments held
11157 ** in (*pAr). Leave this WHERE clause in (*pzWhere) before returning.
11158 ** The caller is responsible for eventually calling sqlite3_free() on
11159 ** any non-NULL (*pzWhere) value.
11160 */
11161 static void arWhereClause(
11162 int *pRc,
11163 ArCommand *pAr,
11164 char **pzWhere /* OUT: New WHERE clause */
11165 ){
11166 char *zWhere = 0;
11167 if( *pRc==SQLITE_OK ){
11168 if( pAr->nArg==0 ){
11169 zWhere = sqlite3_mprintf("1");
11170 }else{
11171 int i;
11172 const char *zSep = "";
11173 for(i=0; i<pAr->nArg; i++){
11174 const char *z = pAr->azArg[i];
11175 zWhere = sqlite3_mprintf(
11176 "%z%s name = '%q' OR name BETWEEN '%q/' AND '%q0'",
11177 zWhere, zSep, z, z, z
11178 );
11179 if( zWhere==0 ){
11180 *pRc = SQLITE_NOMEM;
11181 break;
11182 }
11183 zSep = " OR ";
11184 }
11185 }
11186 }
11187 *pzWhere = zWhere;
11188 }
11189
11190 /*
11191 ** Argument zMode must point to a buffer at least 11 bytes in size. This
11192 ** function populates this buffer with the string interpretation of
11193 ** the unix file mode passed as the second argument (e.g. "drwxr-xr-x").
11194 */
11195 static void shellModeToString(char *zMode, int mode){
11196 int i;
11197
11198 /* Magic numbers copied from [man 2 stat] */
11199 if( mode & 0040000 ){
11200 zMode[0] = 'd';
11201 }else if( (mode & 0120000)==0120000 ){
11202 zMode[0] = 'l';
11203 }else{
11204 zMode[0] = '-';
11205 }
11206
11207 for(i=0; i<3; i++){
11208 int m = (mode >> ((2-i)*3));
11209 char *a = &zMode[1 + i*3];
11210 a[0] = (m & 0x4) ? 'r' : '-';
11211 a[1] = (m & 0x2) ? 'w' : '-';
11212 a[2] = (m & 0x1) ? 'x' : '-';
11213 }
11214 zMode[10] = '\0';
11215 }
11216
11217 /*
11218 ** Implementation of .ar "lisT" command.
11219 */
11220 static int arListCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
11221 const char *zSql = "SELECT %s FROM %s WHERE %s";
11222 const char *zTbl = (pAr->bZip ? "zipfile(?)" : "sqlar");
11223 const char *azCols[] = {
11224 "name",
11225 "mode, sz, datetime(mtime, 'unixepoch'), name"
11226 };
11227
11228 char *zWhere = 0;
11229 sqlite3_stmt *pSql = 0;
11230 int rc;
11231
11232 rc = arCheckEntries(db, pAr);
11233 arWhereClause(&rc, pAr, &zWhere);
11234
11235 shellPreparePrintf(db, &rc, &pSql, zSql, azCols[pAr->bVerbose], zTbl, zWhere);
11236 if( rc==SQLITE_OK && pAr->bZip ){
11237 sqlite3_bind_text(pSql, 1, pAr->zFile, -1, SQLITE_TRANSIENT);
11238 }
11239 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11240 if( pAr->bVerbose ){
11241 char zMode[11];
11242 shellModeToString(zMode, sqlite3_column_int(pSql, 0));
11243
11244 raw_printf(p->out, "%s % 10d %s %s\n", zMode,
11245 sqlite3_column_int(pSql, 1),
11246 sqlite3_column_text(pSql, 2),
11247 sqlite3_column_text(pSql, 3)
11248 );
11249 }else{
11250 raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
11251 }
11252 }
11253
11254 shellFinalize(&rc, pSql);
11255 return rc;
11256 }
11257
11258
11259 /*
11260 ** Implementation of .ar "eXtract" command.
11261 */
11262 static int arExtractCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
11263 const char *zSql1 =
11264 "SELECT "
11265 " :1 || name, "
11266 " writefile(?1 || name, %s, mode, mtime) "
11267 "FROM %s WHERE (%s) AND (data IS NULL OR ?2 = 0)";
11268
11269 const char *azExtraArg[] = {
11270 "sqlar_uncompress(data, sz)",
11271 "zipfile_uncompress(data, sz, method)"
11272 };
11273 const char *azSource[] = {
11274 "sqlar", "zipfile(?3)"
11275 };
11276
11277
11278
11279 sqlite3_stmt *pSql = 0;
11280 int rc = SQLITE_OK;
11281 char *zDir = 0;
11282 char *zWhere = 0;
11283 int i;
11284
11285 /* If arguments are specified, check that they actually exist within
11286 ** the archive before proceeding. And formulate a WHERE clause to
11287 ** match them. */
11288 rc = arCheckEntries(db, pAr);
11289 arWhereClause(&rc, pAr, &zWhere);
11290
11291 if( rc==SQLITE_OK ){
11292 if( pAr->zDir ){
11293 zDir = sqlite3_mprintf("%s/", pAr->zDir);
11294 }else{
11295 zDir = sqlite3_mprintf("");
11296 }
11297 if( zDir==0 ) rc = SQLITE_NOMEM;
11298 }
11299
11300 shellPreparePrintf(db, &rc, &pSql, zSql1,
11301 azExtraArg[pAr->bZip], azSource[pAr->bZip], zWhere
11302 );
11303
11304 if( rc==SQLITE_OK ){
11305 sqlite3_bind_text(pSql, 1, zDir, -1, SQLITE_STATIC);
11306 if( pAr->bZip ){
11307 sqlite3_bind_text(pSql, 3, pAr->zFile, -1, SQLITE_STATIC);
11308 }
11309
11310 /* Run the SELECT statement twice. The first time, writefile() is called
11311 ** for all archive members that should be extracted. The second time,
11312 ** only for the directories. This is because the timestamps for
11313 ** extracted directories must be reset after they are populated (as
11314 ** populating them changes the timestamp). */
11315 for(i=0; i<2; i++){
11316 sqlite3_bind_int(pSql, 2, i);
11317 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
11318 if( i==0 && pAr->bVerbose ){
11319 raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
11320 }
11321 }
11322 shellReset(&rc, pSql);
11323 }
11324 shellFinalize(&rc, pSql);
11325 }
11326
11327 sqlite3_free(zDir);
11328 sqlite3_free(zWhere);
11329 return rc;
11330 }
11331
11332
11333 /*
11334 ** Implementation of .ar "create" and "update" commands.
11335 **
11336 ** Create the "sqlar" table in the database if it does not already exist.
11337 ** Then add each file in the azFile[] array to the archive. Directories
11338 ** are added recursively. If argument bVerbose is non-zero, a message is
11339 ** printed on stdout for each file archived.
11340 **
11341 ** The create command is the same as update, except that it drops
11342 ** any existing "sqlar" table before beginning.
11343 */
11344 static int arCreateUpdate(
11345 ShellState *p, /* Shell state pointer */
11346 sqlite3 *db,
11347 ArCommand *pAr, /* Command arguments and options */
11348 int bUpdate
11349 ){
11350 const char *zSql = "SELECT name, mode, mtime, data FROM fsdir(?, ?)";
11351 const char *zCreate =
11352 "CREATE TABLE IF NOT EXISTS sqlar(\n"
11353 " name TEXT PRIMARY KEY, -- name of the file\n"
11354 " mode INT, -- access permissions\n"
11355 " mtime INT, -- last modification time\n"
11356 " sz INT, -- original file size\n"
11357 " data BLOB -- compressed content\n"
11358 ")";
11359 const char *zDrop = "DROP TABLE IF EXISTS sqlar";
11360 const char *zInsert = "REPLACE INTO sqlar VALUES(?,?,?,?,sqlar_compress(?))";
11361
11362 sqlite3_stmt *pStmt = 0; /* Directory traverser */
11363 sqlite3_stmt *pInsert = 0; /* Compilation of zInsert */
11364 int i; /* For iterating through azFile[] */
11365 int rc; /* Return code */
11366
11367 assert( pAr->bZip==0 );
11368
11369 rc = sqlite3_exec(db, "SAVEPOINT ar;", 0, 0, 0);
11370 if( rc!=SQLITE_OK ) return rc;
11371
11372 if( bUpdate==0 ){
11373 rc = sqlite3_exec(db, zDrop, 0, 0, 0);
11374 if( rc!=SQLITE_OK ) return rc;
11375 }
11376
11377 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
11378 shellPrepare(db, &rc, zInsert, &pInsert);
11379 shellPrepare(db, &rc, zSql, &pStmt);
11380 sqlite3_bind_text(pStmt, 2, pAr->zDir, -1, SQLITE_STATIC);
11381
11382 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
11383 sqlite3_bind_text(pStmt, 1, pAr->azArg[i], -1, SQLITE_STATIC);
11384 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
11385 int sz;
11386 const char *zName = (const char*)sqlite3_column_text(pStmt, 0);
11387 int mode = sqlite3_column_int(pStmt, 1);
11388 unsigned int mtime = sqlite3_column_int(pStmt, 2);
11389
11390 if( pAr->bVerbose ){
11391 raw_printf(p->out, "%s\n", zName);
11392 }
11393
11394 sqlite3_bind_text(pInsert, 1, zName, -1, SQLITE_STATIC);
11395 sqlite3_bind_int(pInsert, 2, mode);
11396 sqlite3_bind_int64(pInsert, 3, (sqlite3_int64)mtime);
11397
11398 if( S_ISDIR(mode) ){
11399 sz = 0;
11400 sqlite3_bind_null(pInsert, 5);
11401 }else{
11402 sqlite3_bind_value(pInsert, 5, sqlite3_column_value(pStmt, 3));
11403 if( S_ISLNK(mode) ){
11404 sz = -1;
11405 }else{
11406 sz = sqlite3_column_bytes(pStmt, 3);
11407 }
11408 }
11409
11410 sqlite3_bind_int(pInsert, 4, sz);
11411 sqlite3_step(pInsert);
11412 rc = sqlite3_reset(pInsert);
11413 }
11414 shellReset(&rc, pStmt);
11415 }
11416
11417 if( rc!=SQLITE_OK ){
11418 sqlite3_exec(db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0);
11419 }else{
11420 rc = sqlite3_exec(db, "RELEASE ar;", 0, 0, 0);
11421 }
11422 shellFinalize(&rc, pStmt);
11423 shellFinalize(&rc, pInsert);
11424 return rc;
11425 }
11426
11427 /*
11428 ** Implementation of .ar "Create" command.
11429 **
11430 ** Create the "sqlar" table in the database if it does not already exist.
11431 ** Then add each file in the azFile[] array to the archive. Directories
11432 ** are added recursively. If argument bVerbose is non-zero, a message is
11433 ** printed on stdout for each file archived.
11434 */
11435 static int arCreateCommand(
11436 ShellState *p, /* Shell state pointer */
11437 sqlite3 *db,
11438 ArCommand *pAr /* Command arguments and options */
11439 ){
11440 return arCreateUpdate(p, db, pAr, 0);
11441 }
11442
11443 /*
11444 ** Implementation of .ar "Update" command.
11445 */
11446 static int arUpdateCmd(ShellState *p, sqlite3 *db, ArCommand *pAr){
11447 return arCreateUpdate(p, db, pAr, 1);
11448 }
11449
11450
11451 /*
11452 ** Implementation of ".ar" dot command.
11453 */
11454 static int arDotCommand(
11455 ShellState *pState, /* Current shell tool state */
11456 char **azArg, /* Array of arguments passed to dot command */
11457 int nArg /* Number of entries in azArg[] */
11458 ){
11459 ArCommand cmd;
11460 int rc;
11461 rc = arParseCommand(azArg, nArg, &cmd);
11462 if( rc==SQLITE_OK ){
11463 sqlite3 *db = 0; /* Database handle to use as archive */
11464
11465 if( cmd.bZip ){
11466 if( cmd.zFile==0 ){
11467 raw_printf(stderr, "zip format requires a --file switch\n");
11468 return SQLITE_ERROR;
11469 }else
11470 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
11471 raw_printf(stderr, "zip archives are read-only\n");
11472 return SQLITE_ERROR;
11473 }
11474 db = pState->db;
11475 }else if( cmd.zFile ){
11476 int flags;
11477 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
11478 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
11479 }else{
11480 flags = SQLITE_OPEN_READONLY;
11481 }
11482 rc = sqlite3_open_v2(cmd.zFile, &db, flags, 0);
11483 if( rc!=SQLITE_OK ){
11484 raw_printf(stderr, "cannot open file: %s (%s)\n",
11485 cmd.zFile, sqlite3_errmsg(db)
11486 );
11487 sqlite3_close(db);
11488 return rc;
11489 }
11490 sqlite3_fileio_init(db, 0, 0);
11491 #ifdef SQLITE_HAVE_ZLIB
11492 sqlite3_sqlar_init(db, 0, 0);
11493 #endif
11494 }else{
11495 db = pState->db;
11496 }
11497
11498 switch( cmd.eCmd ){
11499 case AR_CMD_CREATE:
11500 rc = arCreateCommand(pState, db, &cmd);
11501 break;
11502
11503 case AR_CMD_EXTRACT:
11504 rc = arExtractCommand(pState, db, &cmd);
11505 break;
11506
11507 case AR_CMD_LIST:
11508 rc = arListCommand(pState, db, &cmd);
11509 break;
11510
11511 case AR_CMD_HELP:
11512 arUsage(pState->out);
11513 break;
11514
11515 default:
11516 assert( cmd.eCmd==AR_CMD_UPDATE );
11517 rc = arUpdateCmd(pState, db, &cmd);
11518 break;
11519 }
11520
11521 if( cmd.zFile ){
11522 sqlite3_close(db);
11523 }
11524 }
11525
11526 return rc;
11527 }
11528 /* End of the ".archive" or ".ar" command logic
11529 **********************************************************************************/
11530 #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) */
11531
11532 /*
11533 ** Implementation of ".expert" dot command.
11534 */
11535 static int expertDotCommand(
11536 ShellState *pState, /* Current shell tool state */
11537 char **azArg, /* Array of arguments passed to dot command */
11538 int nArg /* Number of entries in azArg[] */
11539 ){
11540 int rc = SQLITE_OK;
11541 char *zErr = 0;
11542 int i;
11543 int iSample = 0;
11544
11545 assert( pState->expert.pExpert==0 );
11546 memset(&pState->expert, 0, sizeof(ExpertInfo));
11547
11548 for(i=1; rc==SQLITE_OK && i<nArg; i++){
11549 char *z = azArg[i];
11550 int n;
11551 if( z[0]=='-' && z[1]=='-' ) z++;
11552 n = strlen30(z);
11553 if( n>=2 && 0==strncmp(z, "-verbose", n) ){
11554 pState->expert.bVerbose = 1;
11555 }
11556 else if( n>=2 && 0==strncmp(z, "-sample", n) ){
11557 if( i==(nArg-1) ){
11558 raw_printf(stderr, "option requires an argument: %s\n", z);
11559 rc = SQLITE_ERROR;
11560 }else{
11561 iSample = (int)integerValue(azArg[++i]);
11562 if( iSample<0 || iSample>100 ){
11563 raw_printf(stderr, "value out of range: %s\n", azArg[i]);
11564 rc = SQLITE_ERROR;
11565 }
11566 }
11567 }
11568 else{
11569 raw_printf(stderr, "unknown option: %s\n", z);
11570 rc = SQLITE_ERROR;
11571 }
11572 }
11573
11574 if( rc==SQLITE_OK ){
11575 pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
11576 if( pState->expert.pExpert==0 ){
11577 raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
11578 rc = SQLITE_ERROR;
11579 }else{
11580 sqlite3_expert_config(
11581 pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
11582 );
11583 }
11584 }
11585
11586 return rc;
11587 }
11588
11589
11590 /*
11591 ** If an input line begins with "." then invoke this routine to
11592 ** process that line.
@@ -5439,10 +11597,14 @@
11597 int h = 1;
11598 int nArg = 0;
11599 int n, c;
11600 int rc = 0;
11601 char *azArg[50];
11602
11603 if( p->expert.pExpert ){
11604 expertFinish(p, 1, 0);
11605 }
11606
11607 /* Parse the input line into tokens.
11608 */
11609 while( zLine[h] && nArg<ArraySize(azArg) ){
11610 while( IsSpace(zLine[h]) ){ h++; }
@@ -5485,10 +11647,17 @@
11647 }else{
11648 sqlite3_set_authorizer(p->db, 0, 0);
11649 }
11650 }else
11651 #endif
11652
11653 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
11654 if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
11655 open_db(p, 0);
11656 rc = arDotCommand(p, azArg, nArg);
11657 }else
11658 #endif
11659
11660 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
11661 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
11662 ){
11663 const char *zDestFile = 0;
@@ -5755,16 +11924,18 @@
11924 }else
11925
11926 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
11927 if( nArg==2 ){
11928 if( strcmp(azArg[1],"full")==0 ){
11929 p->autoEQP = AUTOEQP_full;
11930 }else if( strcmp(azArg[1],"trigger")==0 ){
11931 p->autoEQP = AUTOEQP_trigger;
11932 }else{
11933 p->autoEQP = booleanValue(azArg[1]);
11934 }
11935 }else{
11936 raw_printf(stderr, "Usage: .eqp off|on|trigger|full\n");
11937 rc = 1;
11938 }
11939 }else
11940
11941 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -5793,10 +11964,15 @@
11964 }else if( val==99 ){
11965 if( p->mode==MODE_Explain ) p->mode = p->normalMode;
11966 p->autoExplain = 1;
11967 }
11968 }else
11969
11970 if( c=='e' && strncmp(azArg[0], "expert", n)==0 ){
11971 open_db(p, 0);
11972 expertDotCommand(p, azArg, nArg);
11973 }else
11974
11975 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
11976 ShellState data;
11977 char *zErrMsg = 0;
11978 int doStats = 0;
@@ -6254,11 +12430,11 @@
12430 }
12431 }else
12432
12433 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
12434 const char *zMode = nArg>=2 ? azArg[1] : "";
12435 int n2 = strlen30(zMode);
12436 int c2 = zMode[0];
12437 if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
12438 p->mode = MODE_Line;
12439 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
12440 }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
@@ -6319,15 +12495,22 @@
12495 sqlite3_close(p->db);
12496 p->db = 0;
12497 p->zDbFilename = 0;
12498 sqlite3_free(p->zFreeOnClose);
12499 p->zFreeOnClose = 0;
12500 p->openMode = SHELL_OPEN_UNSPEC;
12501 /* Check for command-line arguments */
12502 for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
12503 const char *z = azArg[iName];
12504 if( optionMatch(z,"new") ){
12505 newFlag = 1;
12506 #ifdef SQLITE_HAVE_ZIP
12507 }else if( optionMatch(z, "zip") ){
12508 p->openMode = SHELL_OPEN_ZIPFILE;
12509 #endif
12510 }else if( optionMatch(z, "append") ){
12511 p->openMode = SHELL_OPEN_APPENDVFS;
12512 }else if( z[0]=='-' ){
12513 utf8_printf(stderr, "unknown option: %s\n", z);
12514 rc = 1;
12515 goto meta_command_exit;
12516 }
@@ -6506,63 +12689,52 @@
12689
12690 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
12691 ShellText sSelect;
12692 ShellState data;
12693 char *zErrMsg = 0;
12694 const char *zDiv = "(";
12695 const char *zName = 0;
12696 int iSchema = 0;
12697 int bDebug = 0;
12698 int ii;
12699
12700 open_db(p, 0);
12701 memcpy(&data, p, sizeof(data));
12702 data.showHeader = 0;
12703 data.cMode = data.mode = MODE_Semi;
12704 initText(&sSelect);
12705 for(ii=1; ii<nArg; ii++){
12706 if( optionMatch(azArg[ii],"indent") ){
12707 data.cMode = data.mode = MODE_Pretty;
12708 }else if( optionMatch(azArg[ii],"debug") ){
12709 bDebug = 1;
12710 }else if( zName==0 ){
12711 zName = azArg[ii];
12712 }else{
12713 raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
12714 rc = 1;
12715 goto meta_command_exit;
12716 }
12717 }
12718 if( zName!=0 ){
12719 int isMaster = sqlite3_strlike(zName, "sqlite_master", 0)==0;
12720 if( isMaster || sqlite3_strlike(zName,"sqlite_temp_master",0)==0 ){
12721 char *new_argv[2], *new_colv[2];
12722 new_argv[0] = sqlite3_mprintf(
12723 "CREATE TABLE %s (\n"
12724 " type text,\n"
12725 " name text,\n"
12726 " tbl_name text,\n"
12727 " rootpage integer,\n"
12728 " sql text\n"
12729 ")", isMaster ? "sqlite_master" : "sqlite_temp_master");
12730 new_argv[1] = 0;
12731 new_colv[0] = "sql";
12732 new_colv[1] = 0;
12733 callback(&data, 1, new_argv, new_colv);
12734 sqlite3_free(new_argv[0]);
12735 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12736 }
12737 if( zDiv ){
12738 sqlite3_stmt *pStmt = 0;
12739 rc = sqlite3_prepare_v2(p->db, "SELECT name FROM pragma_database_list",
12740 -1, &pStmt, 0);
@@ -6578,43 +12750,52 @@
12750 const char *zDb = (const char*)sqlite3_column_text(pStmt, 0);
12751 char zScNum[30];
12752 sqlite3_snprintf(sizeof(zScNum), zScNum, "%d", ++iSchema);
12753 appendText(&sSelect, zDiv, 0);
12754 zDiv = " UNION ALL ";
12755 appendText(&sSelect, "SELECT shell_add_schema(sql,", 0);
12756 if( sqlite3_stricmp(zDb, "main")!=0 ){
12757 appendText(&sSelect, zDb, '"');
12758 }else{
12759 appendText(&sSelect, "NULL", 0);
12760 }
12761 appendText(&sSelect, ",name) AS sql, type, tbl_name, name, rowid,", 0);
12762 appendText(&sSelect, zScNum, 0);
12763 appendText(&sSelect, " AS snum, ", 0);
12764 appendText(&sSelect, zDb, '\'');
12765 appendText(&sSelect, " AS sname FROM ", 0);
12766 appendText(&sSelect, zDb, '"');
12767 appendText(&sSelect, ".sqlite_master", 0);
 
 
12768 }
12769 sqlite3_finalize(pStmt);
12770 #ifdef SQLITE_INTROSPECTION_PRAGMAS
12771 if( zName ){
12772 appendText(&sSelect,
12773 " UNION ALL SELECT shell_module_schema(name),"
12774 " 'table', name, name, name, 9e+99, 'main' FROM pragma_module_list", 0);
12775 }
12776 #endif
12777 appendText(&sSelect, ") WHERE ", 0);
12778 if( zName ){
12779 char *zQarg = sqlite3_mprintf("%Q", zName);
12780 if( strchr(zName, '.') ){
12781 appendText(&sSelect, "lower(printf('%s.%s',sname,tbl_name))", 0);
12782 }else{
12783 appendText(&sSelect, "lower(tbl_name)", 0);
12784 }
12785 appendText(&sSelect, strchr(zName, '*') ? " GLOB " : " LIKE ", 0);
12786 appendText(&sSelect, zQarg, 0);
12787 appendText(&sSelect, " AND ", 0);
12788 sqlite3_free(zQarg);
12789 }
12790 appendText(&sSelect, "type!='meta' AND sql IS NOT NULL"
12791 " ORDER BY snum, rowid", 0);
12792 if( bDebug ){
12793 utf8_printf(p->out, "SQL: %s;\n", sSelect.z);
12794 }else{
12795 rc = sqlite3_exec(p->db, sSelect.z, callback, &data, &zErrMsg);
12796 }
12797 freeText(&sSelect);
12798 }
12799 if( zErrMsg ){
12800 utf8_printf(stderr,"Error: %s\n", zErrMsg);
12801 sqlite3_free(zErrMsg);
@@ -7108,11 +13289,11 @@
13289 sqlite3_free(zCmd);
13290 if( x ) raw_printf(stderr, "System command returns %d\n", x);
13291 }else
13292
13293 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
13294 static const char *azBool[] = { "off", "on", "trigger", "full"};
13295 int i;
13296 if( nArg!=1 ){
13297 raw_printf(stderr, "Usage: .show\n");
13298 rc = 1;
13299 goto meta_command_exit;
@@ -7296,10 +13477,13 @@
13477 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD, "IDENTIFIER" },
13478 #endif
13479 { "localtime_fault", SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN" },
13480 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN" },
13481 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK" },
13482 #ifdef YYCOVERAGE
13483 { "parser_coverage", SQLITE_TESTCTRL_PARSER_COVERAGE, "" },
13484 #endif
13485 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE, "OFFSET " },
13486 { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET, "" },
13487 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE, "" },
13488 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE, "" },
13489 { "reserve", SQLITE_TESTCTRL_RESERVE, "BYTES-OF-RESERVE" },
@@ -7421,10 +13605,18 @@
13605 integerValue(azArg[3]),
13606 integerValue(azArg[4]));
13607 isOk = 3;
13608 }
13609 break;
13610
13611 #ifdef YYCOVERAGE
13612 case SQLITE_TESTCTRL_PARSER_COVERAGE:
13613 if( nArg==2 ){
13614 sqlite3_test_control(testctrl, p->out);
13615 isOk = 3;
13616 }
13617 #endif
13618 }
13619 }
13620 if( isOk==0 && iCtrl>=0 ){
13621 utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd, aCtrl[iCtrl].zUsage);
13622 rc = 1;
@@ -7484,12 +13676,11 @@
13676 if( nArg!=4 ){
13677 raw_printf(stderr, "Usage: .user login USER PASSWORD\n");
13678 rc = 1;
13679 goto meta_command_exit;
13680 }
13681 rc = sqlite3_user_authenticate(p->db, azArg[2], azArg[3], strlen30(azArg[3]));
 
13682 if( rc ){
13683 utf8_printf(stderr, "Authentication failed for user %s\n", azArg[2]);
13684 rc = 1;
13685 }
13686 }else if( strcmp(azArg[1],"add")==0 ){
@@ -7496,12 +13687,11 @@
13687 if( nArg!=5 ){
13688 raw_printf(stderr, "Usage: .user add USER PASSWORD ISADMIN\n");
13689 rc = 1;
13690 goto meta_command_exit;
13691 }
13692 rc = sqlite3_user_add(p->db, azArg[2], azArg[3], strlen30(azArg[3]),
 
13693 booleanValue(azArg[4]));
13694 if( rc ){
13695 raw_printf(stderr, "User-Add failed: %d\n", rc);
13696 rc = 1;
13697 }
@@ -7509,12 +13699,11 @@
13699 if( nArg!=5 ){
13700 raw_printf(stderr, "Usage: .user edit USER PASSWORD ISADMIN\n");
13701 rc = 1;
13702 goto meta_command_exit;
13703 }
13704 rc = sqlite3_user_change(p->db, azArg[2], azArg[3], strlen30(azArg[3]),
 
13705 booleanValue(azArg[4]));
13706 if( rc ){
13707 raw_printf(stderr, "User-Edit failed: %d\n", rc);
13708 rc = 1;
13709 }
@@ -8186,10 +14375,16 @@
14375 sqlite3_vfs_register(pVfs, 1);
14376 }else{
14377 utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
14378 exit(1);
14379 }
14380 #ifdef SQLITE_HAVE_ZIP
14381 }else if( strcmp(z,"-zip")==0 ){
14382 data.openMode = SHELL_OPEN_ZIPFILE;
14383 #endif
14384 }else if( strcmp(z,"-append")==0 ){
14385 data.openMode = SHELL_OPEN_APPENDVFS;
14386 }
14387 }
14388 if( data.zDbFilename==0 ){
14389 #ifndef SQLITE_OMIT_MEMORYDB
14390 data.zDbFilename = ":memory:";
@@ -8198,10 +14393,11 @@
14393 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
14394 return 1;
14395 #endif
14396 }
14397 data.out = stdout;
14398 sqlite3_appendvfs_init(0,0,0);
14399
14400 /* Go ahead and open the database file if it already exists. If the
14401 ** file does not exist, delay opening it. This prevents empty database
14402 ** files from being created if a user mistypes the database name argument
14403 ** to the sqlite command-line tool.
@@ -8238,10 +14434,16 @@
14434 }else if( strcmp(z,"-column")==0 ){
14435 data.mode = MODE_Column;
14436 }else if( strcmp(z,"-csv")==0 ){
14437 data.mode = MODE_Csv;
14438 memcpy(data.colSeparator,",",2);
14439 #ifdef SQLITE_HAVE_ZIP
14440 }else if( strcmp(z,"-zip")==0 ){
14441 data.openMode = SHELL_OPEN_ZIPFILE;
14442 #endif
14443 }else if( strcmp(z,"-append")==0 ){
14444 data.openMode = SHELL_OPEN_APPENDVFS;
14445 }else if( strcmp(z,"-ascii")==0 ){
14446 data.mode = MODE_Ascii;
14447 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
14448 SEP_Unit);
14449 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator,
@@ -8260,13 +14462,13 @@
14462 }else if( strcmp(z,"-noheader")==0 ){
14463 data.showHeader = 0;
14464 }else if( strcmp(z,"-echo")==0 ){
14465 ShellSetFlag(&data, SHFLG_Echo);
14466 }else if( strcmp(z,"-eqp")==0 ){
14467 data.autoEQP = AUTOEQP_on;
14468 }else if( strcmp(z,"-eqpfull")==0 ){
14469 data.autoEQP = AUTOEQP_full;
14470 }else if( strcmp(z,"-stats")==0 ){
14471 data.statsOn = 1;
14472 }else if( strcmp(z,"-scanstats")==0 ){
14473 data.scanstatsOn = 1;
14474 }else if( strcmp(z,"-backslash")==0 ){
14475
+3177 -2646
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
11471147
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11481148
** [sqlite_version()] and [sqlite_source_id()].
11491149
*/
11501150
#define SQLITE_VERSION "3.22.0"
11511151
#define SQLITE_VERSION_NUMBER 3022000
1152
-#define SQLITE_SOURCE_ID "2017-12-13 20:35:34 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b429b15"
1152
+#define SQLITE_SOURCE_ID "2018-01-07 20:38:10 67c4a8c6881e33b830aa27c80e7e3d697a4222939edd77cd5ca77ece16471ea4"
11531153
11541154
/*
11551155
** CAPI3REF: Run-Time Library Version Numbers
11561156
** KEYWORDS: sqlite3_version sqlite3_sourceid
11571157
**
@@ -3082,11 +3082,10 @@
30823082
** is an integer - non-zero to disable checkpoints-on-close, or zero (the
30833083
** default) to enable them. The second parameter is a pointer to an integer
30843084
** into which is written 0 or 1 to indicate whether checkpoints-on-close
30853085
** have been disabled - 0 if they are not disabled, 1 if they are.
30863086
** </dd>
3087
-**
30883087
** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
30893088
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
30903089
** the [query planner stability guarantee] (QPSG). When the QPSG is active,
30913090
** a single SQL query statement will always use the same algorithm regardless
30923091
** of values of [bound parameters].)^ The QPSG disables some query optimizations
@@ -3093,11 +3092,20 @@
30933092
** that look at the values of bound parameters, which can make some queries
30943093
** slower. But the QPSG has the advantage of more predictable behavior. With
30953094
** the QPSG active, SQLite will always use the same query plan in the field as
30963095
** was used during testing in the lab.
30973096
** </dd>
3098
-**
3097
+** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
3098
+** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
3099
+** include output for any operations performed by trigger programs. This
3100
+** option is used to set or clear (the default) a flag that governs this
3101
+** behavior. The first parameter passed to this operation is an integer -
3102
+** non-zero to enable output for trigger programs, or zero to disable it.
3103
+** The second parameter is a pointer to an integer into which is written
3104
+** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
3105
+** it is not disabled, 1 if it is.
3106
+** </dd>
30993107
** </dl>
31003108
*/
31013109
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
31023110
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
31033111
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -3104,11 +3112,12 @@
31043112
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
31053113
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
31063114
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
31073115
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
31083116
#define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
3109
-
3117
+#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
3118
+#define SQLITE_DBCONFIG_MAX 1008 /* Largest DBCONFIG */
31103119
31113120
/*
31123121
** CAPI3REF: Enable Or Disable Extended Result Codes
31133122
** METHOD: sqlite3
31143123
**
@@ -7984,13 +7993,13 @@
79847993
** ^The third and fourth parameters to this routine
79857994
** are passed directly through to the second and third parameters of
79867995
** the xFileControl method. ^The return value of the xFileControl
79877996
** method becomes the return value of this routine.
79887997
**
7989
-** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
7998
+** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
79907999
** a pointer to the underlying [sqlite3_file] object to be written into
7991
-** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER
8000
+** the space pointed to by the 4th parameter. ^The [SQLITE_FCNTL_FILE_POINTER]
79928001
** case is a short-circuit path which does not actually invoke the
79938002
** underlying sqlite3_io_methods.xFileControl method.
79948003
**
79958004
** ^If the second parameter (zDbName) does not match the name of any
79968005
** open database file, then SQLITE_ERROR is returned. ^This error
@@ -7998,11 +8007,11 @@
79988007
** or [sqlite3_errmsg()]. The underlying xFileControl method might
79998008
** also return SQLITE_ERROR. There is no way to distinguish between
80008009
** an incorrect zDbName and an SQLITE_ERROR return from the underlying
80018010
** xFileControl method.
80028011
**
8003
-** See also: [SQLITE_FCNTL_LOCKSTATE]
8012
+** See also: [file control opcodes]
80048013
*/
80058014
SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
80068015
80078016
/*
80088017
** CAPI3REF: Testing Interface
@@ -8055,11 +8064,12 @@
80558064
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
80568065
#define SQLITE_TESTCTRL_BYTEORDER 22
80578066
#define SQLITE_TESTCTRL_ISINIT 23
80588067
#define SQLITE_TESTCTRL_SORTER_MMAP 24
80598068
#define SQLITE_TESTCTRL_IMPOSTER 25
8060
-#define SQLITE_TESTCTRL_LAST 25
8069
+#define SQLITE_TESTCTRL_PARSER_COVERAGE 26
8070
+#define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */
80618071
80628072
/*
80638073
** CAPI3REF: SQLite Runtime Status
80648074
**
80658075
** ^These interfaces are used to retrieve runtime status information
@@ -9309,10 +9319,25 @@
93099319
** of the SQL statement that triggered the call to the [xUpdate] method of the
93109320
** [virtual table].
93119321
*/
93129322
SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
93139323
9324
+/*
9325
+** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9326
+**
9327
+** This function may only be called from within a call to the [xBestIndex]
9328
+** method of a [virtual table].
9329
+**
9330
+** The first argument must be the sqlite3_index_info object that is the
9331
+** first parameter to the xBestIndex() method. The second argument must be
9332
+** an index into the aConstraint[] array belonging to the sqlite3_index_info
9333
+** structure passed to xBestIndex. This function returns a pointer to a buffer
9334
+** containing the name of the collation sequence for the corresponding
9335
+** constraint.
9336
+*/
9337
+SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9338
+
93149339
/*
93159340
** CAPI3REF: Conflict resolution modes
93169341
** KEYWORDS: {conflict resolution mode}
93179342
**
93189343
** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -13144,11 +13169,10 @@
1314413169
typedef struct Column Column;
1314513170
typedef struct Db Db;
1314613171
typedef struct Schema Schema;
1314713172
typedef struct Expr Expr;
1314813173
typedef struct ExprList ExprList;
13149
-typedef struct ExprSpan ExprSpan;
1315013174
typedef struct FKey FKey;
1315113175
typedef struct FuncDestructor FuncDestructor;
1315213176
typedef struct FuncDef FuncDef;
1315313177
typedef struct FuncDefHash FuncDefHash;
1315413178
typedef struct IdList IdList;
@@ -13490,10 +13514,13 @@
1349013514
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
1349113515
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
1349213516
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
1349313517
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
1349413518
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
13519
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
13520
+SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
13521
+#endif
1349513522
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
1349613523
SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
1349713524
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
1349813525
1349913526
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
@@ -13841,82 +13868,84 @@
1384113868
#define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
1384213869
#define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
1384313870
#define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
1384413871
#define OP_Compare 94 /* synopsis: r[P1@P3] <-> r[P2@P3] */
1384513872
#define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
13846
-#define OP_Column 96 /* synopsis: r[P3]=PX */
13873
+#define OP_Offset 96 /* synopsis: r[P3] = sqlite_offset(P1) */
1384713874
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
13848
-#define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */
13849
-#define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
13850
-#define OP_Count 100 /* synopsis: r[P2]=count() */
13851
-#define OP_ReadCookie 101
13852
-#define OP_SetCookie 102
13853
-#define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */
13854
-#define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */
13855
-#define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */
13856
-#define OP_OpenDup 106
13857
-#define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */
13858
-#define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */
13859
-#define OP_SorterOpen 109
13860
-#define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
13861
-#define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */
13862
-#define OP_Close 112
13863
-#define OP_ColumnsUsed 113
13864
-#define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */
13865
-#define OP_NewRowid 115 /* synopsis: r[P2]=rowid */
13866
-#define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */
13867
-#define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */
13868
-#define OP_Delete 118
13869
-#define OP_ResetCount 119
13870
-#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13871
-#define OP_SorterData 121 /* synopsis: r[P2]=data */
13872
-#define OP_RowData 122 /* synopsis: r[P2]=data */
13873
-#define OP_Rowid 123 /* synopsis: r[P2]=rowid */
13874
-#define OP_NullRow 124
13875
-#define OP_SeekEnd 125
13876
-#define OP_SorterInsert 126 /* synopsis: key=r[P2] */
13877
-#define OP_IdxInsert 127 /* synopsis: key=r[P2] */
13878
-#define OP_IdxDelete 128 /* synopsis: key=r[P2@P3] */
13879
-#define OP_DeferredSeek 129 /* synopsis: Move P3 to P1.rowid if needed */
13880
-#define OP_IdxRowid 130 /* synopsis: r[P2]=rowid */
13881
-#define OP_Destroy 131
13875
+#define OP_Column 98 /* synopsis: r[P3]=PX */
13876
+#define OP_Affinity 99 /* synopsis: affinity(r[P1@P2]) */
13877
+#define OP_MakeRecord 100 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
13878
+#define OP_Count 101 /* synopsis: r[P2]=count() */
13879
+#define OP_ReadCookie 102
13880
+#define OP_SetCookie 103
13881
+#define OP_ReopenIdx 104 /* synopsis: root=P2 iDb=P3 */
13882
+#define OP_OpenRead 105 /* synopsis: root=P2 iDb=P3 */
13883
+#define OP_OpenWrite 106 /* synopsis: root=P2 iDb=P3 */
13884
+#define OP_OpenDup 107
13885
+#define OP_OpenAutoindex 108 /* synopsis: nColumn=P2 */
13886
+#define OP_OpenEphemeral 109 /* synopsis: nColumn=P2 */
13887
+#define OP_SorterOpen 110
13888
+#define OP_SequenceTest 111 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
13889
+#define OP_OpenPseudo 112 /* synopsis: P3 columns in r[P2] */
13890
+#define OP_Close 113
13891
+#define OP_ColumnsUsed 114
13892
+#define OP_Sequence 115 /* synopsis: r[P2]=cursor[P1].ctr++ */
13893
+#define OP_NewRowid 116 /* synopsis: r[P2]=rowid */
13894
+#define OP_Insert 117 /* synopsis: intkey=r[P3] data=r[P2] */
13895
+#define OP_InsertInt 118 /* synopsis: intkey=P3 data=r[P2] */
13896
+#define OP_Delete 119
13897
+#define OP_ResetCount 120
13898
+#define OP_SorterCompare 121 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13899
+#define OP_SorterData 122 /* synopsis: r[P2]=data */
13900
+#define OP_RowData 123 /* synopsis: r[P2]=data */
13901
+#define OP_Rowid 124 /* synopsis: r[P2]=rowid */
13902
+#define OP_NullRow 125
13903
+#define OP_SeekEnd 126
13904
+#define OP_SorterInsert 127 /* synopsis: key=r[P2] */
13905
+#define OP_IdxInsert 128 /* synopsis: key=r[P2] */
13906
+#define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */
13907
+#define OP_DeferredSeek 130 /* synopsis: Move P3 to P1.rowid if needed */
13908
+#define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */
1388213909
#define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13883
-#define OP_Clear 133
13884
-#define OP_ResetSorter 134
13885
-#define OP_CreateBtree 135 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
13886
-#define OP_SqlExec 136
13887
-#define OP_ParseSchema 137
13888
-#define OP_LoadAnalysis 138
13889
-#define OP_DropTable 139
13890
-#define OP_DropIndex 140
13891
-#define OP_DropTrigger 141
13892
-#define OP_IntegrityCk 142
13893
-#define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */
13894
-#define OP_Param 144
13895
-#define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */
13896
-#define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */
13897
-#define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
13898
-#define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13899
-#define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13900
-#define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */
13901
-#define OP_Expire 151
13902
-#define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */
13903
-#define OP_VBegin 153
13904
-#define OP_VCreate 154
13905
-#define OP_VDestroy 155
13906
-#define OP_VOpen 156
13907
-#define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */
13908
-#define OP_VRename 158
13909
-#define OP_Pagecount 159
13910
-#define OP_MaxPgcnt 160
13911
-#define OP_PureFunc0 161
13912
-#define OP_Function0 162 /* synopsis: r[P3]=func(r[P2@P5]) */
13913
-#define OP_PureFunc 163
13914
-#define OP_Function 164 /* synopsis: r[P3]=func(r[P2@P5]) */
13915
-#define OP_CursorHint 165
13916
-#define OP_Noop 166
13917
-#define OP_Explain 167
13910
+#define OP_Destroy 133
13911
+#define OP_Clear 134
13912
+#define OP_ResetSorter 135
13913
+#define OP_CreateBtree 136 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
13914
+#define OP_SqlExec 137
13915
+#define OP_ParseSchema 138
13916
+#define OP_LoadAnalysis 139
13917
+#define OP_DropTable 140
13918
+#define OP_DropIndex 141
13919
+#define OP_DropTrigger 142
13920
+#define OP_IntegrityCk 143
13921
+#define OP_RowSetAdd 144 /* synopsis: rowset(P1)=r[P2] */
13922
+#define OP_Param 145
13923
+#define OP_FkCounter 146 /* synopsis: fkctr[P1]+=P2 */
13924
+#define OP_MemMax 147 /* synopsis: r[P1]=max(r[P1],r[P2]) */
13925
+#define OP_OffsetLimit 148 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
13926
+#define OP_AggStep0 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13927
+#define OP_AggStep 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13928
+#define OP_AggFinal 151 /* synopsis: accum=r[P1] N=P2 */
13929
+#define OP_Expire 152
13930
+#define OP_TableLock 153 /* synopsis: iDb=P1 root=P2 write=P3 */
13931
+#define OP_VBegin 154
13932
+#define OP_VCreate 155
13933
+#define OP_VDestroy 156
13934
+#define OP_VOpen 157
13935
+#define OP_VColumn 158 /* synopsis: r[P3]=vcolumn(P2) */
13936
+#define OP_VRename 159
13937
+#define OP_Pagecount 160
13938
+#define OP_MaxPgcnt 161
13939
+#define OP_PureFunc0 162
13940
+#define OP_Function0 163 /* synopsis: r[P3]=func(r[P2@P5]) */
13941
+#define OP_PureFunc 164
13942
+#define OP_Function 165 /* synopsis: r[P3]=func(r[P2@P5]) */
13943
+#define OP_Trace 166
13944
+#define OP_CursorHint 167
13945
+#define OP_Noop 168
13946
+#define OP_Explain 169
1391813947
1391913948
/* Properties such as "out2" or "jump" that are specified in
1392013949
** comments following the "case" for each opcode in the vdbe.c
1392113950
** are encoded into bitvectors as follows:
1392213951
*/
@@ -13937,20 +13966,20 @@
1393713966
/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x02,\
1393813967
/* 64 */ 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,\
1393913968
/* 72 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
1394013969
/* 80 */ 0x02, 0x02, 0x02, 0x00, 0x26, 0x26, 0x26, 0x26,\
1394113970
/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
13942
-/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13971
+/* 96 */ 0x20, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
1394313972
/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13944
-/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
13945
-/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\
13946
-/* 128 */ 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10,\
13947
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
13948
-/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
13949
-/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
13950
-/* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13951
-}
13973
+/* 112 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
13974
+/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04,\
13975
+/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
13976
+/* 136 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13977
+/* 144 */ 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00,\
13978
+/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13979
+/* 160 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13980
+/* 168 */ 0x00, 0x00,}
1395213981
1395313982
/* The sqlite3P2Values() routine is able to run faster if it knows
1395413983
** the value of the largest JUMP opcode. The smaller the maximum
1395513984
** JUMP opcode the better, so the mkopcodeh.tcl script that
1395613985
** generated this include file strives to group all JUMP opcodes
@@ -15206,11 +15235,11 @@
1520615235
#ifndef SQLITE_OMIT_VIRTUALTABLE
1520715236
int nVTrans; /* Allocated size of aVTrans */
1520815237
Hash aModule; /* populated by sqlite3_create_module() */
1520915238
VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
1521015239
VTable **aVTrans; /* Virtual tables with open transactions */
15211
- VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
15240
+ VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
1521215241
#endif
1521315242
Hash aFunc; /* Hash table of connection functions */
1521415243
Hash aCollSeq; /* All collating sequences */
1521515244
BusyHandler busyHandler; /* Busy callback */
1521615245
Db aDbStatic[2]; /* Static space for the 2 default backends */
@@ -15281,11 +15310,13 @@
1528115310
#define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */
1528215311
#define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */
1528315312
#define SQLITE_QueryOnly 0x00100000 /* Disable database changes */
1528415313
#define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */
1528515314
#define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */
15286
-#define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee */
15315
+#define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee*/
15316
+#define SQLITE_TriggerEQP 0x01000000 /* Show trigger EXPLAIN QUERY PLAN */
15317
+
1528715318
/* Flags used only if debugging */
1528815319
#ifdef SQLITE_DEBUG
1528915320
#define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */
1529015321
#define SQLITE_VdbeListing 0x10000000 /* Debug listings of VDBE programs */
1529115322
#define SQLITE_VdbeTrace 0x20000000 /* True to trace VDBE execution */
@@ -15414,10 +15445,11 @@
1541415445
#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
1541515446
#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
1541615447
#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
1541715448
** single query - might change over time */
1541815449
#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
15450
+#define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
1541915451
1542015452
/*
1542115453
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1542215454
** used to create the initializers for the FuncDef structures.
1542315455
**
@@ -16288,21 +16320,10 @@
1628816320
int iConstExprReg; /* Register in which Expr value is cached */
1628916321
} u;
1629016322
} a[1]; /* One slot for each expression in the list */
1629116323
};
1629216324
16293
-/*
16294
-** An instance of this structure is used by the parser to record both
16295
-** the parse tree for an expression and the span of input text for an
16296
-** expression.
16297
-*/
16298
-struct ExprSpan {
16299
- Expr *pExpr; /* The expression parse tree */
16300
- const char *zStart; /* First character of input text */
16301
- const char *zEnd; /* One character past the end of input text */
16302
-};
16303
-
1630416325
/*
1630516326
** An instance of this structure can hold a simple list of identifiers,
1630616327
** such as the list "a,b,c" in the following statements:
1630716328
**
1630816329
** INSERT INTO t(a,b,c) VALUES ...;
@@ -16999,10 +17020,11 @@
1699917020
Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
1700017021
char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
1700117022
Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
1700217023
ExprList *pExprList; /* SET clause for UPDATE. */
1700317024
IdList *pIdList; /* Column names for INSERT */
17025
+ char *zSpan; /* Original SQL text of this command */
1700417026
TriggerStep *pNext; /* Next in the link-list */
1700517027
TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
1700617028
};
1700717029
1700817030
/*
@@ -17309,10 +17331,11 @@
1730917331
SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, u64);
1731017332
SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, u64);
1731117333
SQLITE_PRIVATE void *sqlite3DbMallocRawNN(sqlite3*, u64);
1731217334
SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
1731317335
SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
17336
+SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3*,const char*,const char*);
1731417337
SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
1731517338
SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
1731617339
SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
1731717340
SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
1731817341
SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
@@ -17447,11 +17470,11 @@
1744717470
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
1744817471
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
1744917472
SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
1745017473
SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
1745117474
SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
17452
-SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
17475
+SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
1745317476
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
1745417477
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
1745517478
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
1745617479
SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
1745717480
SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
@@ -17477,11 +17500,11 @@
1747717500
#endif
1747817501
SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*);
1747917502
SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
1748017503
SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
1748117504
SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
17482
-SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
17505
+SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
1748317506
SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
1748417507
SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
1748517508
SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
1748617509
sqlite3_vfs**,char**,char **);
1748717510
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
@@ -17698,15 +17721,18 @@
1769817721
SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
1769917722
int, int, int);
1770017723
SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
1770117724
void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
1770217725
SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*);
17703
-SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*);
17726
+SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*,
17727
+ const char*,const char*);
1770417728
SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
17705
- Select*,u8);
17706
-SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8);
17707
-SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
17729
+ Select*,u8,const char*,const char*);
17730
+SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8,
17731
+ const char*,const char*);
17732
+SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*,
17733
+ const char*,const char*);
1770817734
SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*);
1770917735
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
1771017736
SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
1771117737
# define sqlite3ParseToplevel(p) ((p)->pToplevel ? (p)->pToplevel : (p))
1771217738
# define sqlite3IsToplevel(p) ((p)->pToplevel==0)
@@ -18132,10 +18158,13 @@
1813218158
#endif
1813318159
1813418160
#ifdef SQLITE_DEBUG
1813518161
SQLITE_PRIVATE void sqlite3ParserTrace(FILE*, char *);
1813618162
#endif
18163
+#if defined(YYCOVERAGE)
18164
+SQLITE_PRIVATE int sqlite3ParserCoverage(FILE*);
18165
+#endif
1813718166
1813818167
/*
1813918168
** If the SQLITE_ENABLE IOTRACE exists then the global variable
1814018169
** sqlite3IoTrace is a pointer to a printf-like routine used to
1814118170
** print I/O tracing messages.
@@ -25667,10 +25696,23 @@
2566725696
memcpy(zNew, z, (size_t)n);
2566825697
zNew[n] = 0;
2566925698
}
2567025699
return zNew;
2567125700
}
25701
+
25702
+/*
25703
+** The text between zStart and zEnd represents a phrase within a larger
25704
+** SQL statement. Make a copy of this phrase in space obtained form
25705
+** sqlite3DbMalloc(). Omit leading and trailing whitespace.
25706
+*/
25707
+SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
25708
+ int n;
25709
+ while( sqlite3Isspace(zStart[0]) ) zStart++;
25710
+ n = (int)(zEnd - zStart);
25711
+ while( n>0 && sqlite3Isspace(zStart[n-1]) ) n--;
25712
+ return sqlite3DbStrNDup(db, zStart, n);
25713
+}
2567225714
2567325715
/*
2567425716
** Free any prior content in *pz and replace it with a copy of zNew.
2567525717
*/
2567625718
SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
@@ -27373,16 +27415,24 @@
2737327415
}else{
2737427416
int i;
2737527417
sqlite3TreeViewLine(pView, "%s", zLabel);
2737627418
for(i=0; i<pList->nExpr; i++){
2737727419
int j = pList->a[i].u.x.iOrderByCol;
27378
- if( j ){
27420
+ char *zName = pList->a[i].zName;
27421
+ if( j || zName ){
2737927422
sqlite3TreeViewPush(pView, 0);
27423
+ }
27424
+ if( zName ){
27425
+ sqlite3TreeViewLine(pView, "AS %s", zName);
27426
+ }
27427
+ if( j ){
2738027428
sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
2738127429
}
2738227430
sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
27383
- if( j ) sqlite3TreeViewPop(pView);
27431
+ if( j || zName ){
27432
+ sqlite3TreeViewPop(pView);
27433
+ }
2738427434
}
2738527435
}
2738627436
}
2738727437
SQLITE_PRIVATE void sqlite3TreeViewExprList(
2738827438
TreeView *pView,
@@ -28667,10 +28717,28 @@
2866728717
a = (unsigned char *)zLeft;
2866828718
b = (unsigned char *)zRight;
2866928719
while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
2867028720
return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
2867128721
}
28722
+
28723
+/*
28724
+** Compute 10 to the E-th power. Examples: E==1 results in 10.
28725
+** E==2 results in 100. E==50 results in 1.0e50.
28726
+**
28727
+** This routine only works for values of E between 1 and 341.
28728
+*/
28729
+static LONGDOUBLE_TYPE sqlite3Pow10(int E){
28730
+ LONGDOUBLE_TYPE x = 10.0;
28731
+ LONGDOUBLE_TYPE r = 1.0;
28732
+ while(1){
28733
+ if( E & 1 ) r *= x;
28734
+ E >>= 1;
28735
+ if( E==0 ) break;
28736
+ x *= x;
28737
+ }
28738
+ return r;
28739
+}
2867228740
2867328741
/*
2867428742
** The string z[] is an text representation of a real number.
2867528743
** Convert this string to a double and write it into *pResult.
2867628744
**
@@ -28823,15 +28891,14 @@
2882328891
s = sign<0 ? -s : s;
2882428892
2882528893
if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/
2882628894
result = (double)s;
2882728895
}else{
28828
- LONGDOUBLE_TYPE scale = 1.0;
2882928896
/* attempt to handle extremely small/large numbers better */
2883028897
if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/
2883128898
if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/
28832
- while( e%308 ) { scale *= 1.0e+1; e -= 1; }
28899
+ LONGDOUBLE_TYPE scale = sqlite3Pow10(e-308);
2883328900
if( esign<0 ){
2883428901
result = s / scale;
2883528902
result /= 1.0e+308;
2883628903
}else{
2883728904
result = s * scale;
@@ -28847,14 +28914,11 @@
2884728914
result = 1e308*1e308*s; /* Infinity */
2884828915
#endif
2884928916
}
2885028917
}
2885128918
}else{
28852
- /* 1.0e+22 is the largest power of 10 than can be
28853
- ** represented exactly. */
28854
- while( e%22 ) { scale *= 1.0e+1; e -= 1; }
28855
- while( e>0 ) { scale *= 1.0e+22; e -= 22; }
28919
+ LONGDOUBLE_TYPE scale = sqlite3Pow10(e);
2885628920
if( esign<0 ){
2885728921
result = s / scale;
2885828922
}else{
2885928923
result = s * scale;
2886028924
}
@@ -30308,82 +30372,84 @@
3030830372
/* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
3030930373
/* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
3031030374
/* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
3031130375
/* 94 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
3031230376
/* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
30313
- /* 96 */ "Column" OpHelp("r[P3]=PX"),
30377
+ /* 96 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
3031430378
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
30315
- /* 98 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
30316
- /* 99 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
30317
- /* 100 */ "Count" OpHelp("r[P2]=count()"),
30318
- /* 101 */ "ReadCookie" OpHelp(""),
30319
- /* 102 */ "SetCookie" OpHelp(""),
30320
- /* 103 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
30321
- /* 104 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
30322
- /* 105 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
30323
- /* 106 */ "OpenDup" OpHelp(""),
30324
- /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"),
30325
- /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"),
30326
- /* 109 */ "SorterOpen" OpHelp(""),
30327
- /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
30328
- /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
30329
- /* 112 */ "Close" OpHelp(""),
30330
- /* 113 */ "ColumnsUsed" OpHelp(""),
30331
- /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
30332
- /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"),
30333
- /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
30334
- /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
30335
- /* 118 */ "Delete" OpHelp(""),
30336
- /* 119 */ "ResetCount" OpHelp(""),
30337
- /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30338
- /* 121 */ "SorterData" OpHelp("r[P2]=data"),
30339
- /* 122 */ "RowData" OpHelp("r[P2]=data"),
30340
- /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
30341
- /* 124 */ "NullRow" OpHelp(""),
30342
- /* 125 */ "SeekEnd" OpHelp(""),
30343
- /* 126 */ "SorterInsert" OpHelp("key=r[P2]"),
30344
- /* 127 */ "IdxInsert" OpHelp("key=r[P2]"),
30345
- /* 128 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30346
- /* 129 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30347
- /* 130 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30348
- /* 131 */ "Destroy" OpHelp(""),
30379
+ /* 98 */ "Column" OpHelp("r[P3]=PX"),
30380
+ /* 99 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
30381
+ /* 100 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
30382
+ /* 101 */ "Count" OpHelp("r[P2]=count()"),
30383
+ /* 102 */ "ReadCookie" OpHelp(""),
30384
+ /* 103 */ "SetCookie" OpHelp(""),
30385
+ /* 104 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
30386
+ /* 105 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
30387
+ /* 106 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
30388
+ /* 107 */ "OpenDup" OpHelp(""),
30389
+ /* 108 */ "OpenAutoindex" OpHelp("nColumn=P2"),
30390
+ /* 109 */ "OpenEphemeral" OpHelp("nColumn=P2"),
30391
+ /* 110 */ "SorterOpen" OpHelp(""),
30392
+ /* 111 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
30393
+ /* 112 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
30394
+ /* 113 */ "Close" OpHelp(""),
30395
+ /* 114 */ "ColumnsUsed" OpHelp(""),
30396
+ /* 115 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
30397
+ /* 116 */ "NewRowid" OpHelp("r[P2]=rowid"),
30398
+ /* 117 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
30399
+ /* 118 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
30400
+ /* 119 */ "Delete" OpHelp(""),
30401
+ /* 120 */ "ResetCount" OpHelp(""),
30402
+ /* 121 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30403
+ /* 122 */ "SorterData" OpHelp("r[P2]=data"),
30404
+ /* 123 */ "RowData" OpHelp("r[P2]=data"),
30405
+ /* 124 */ "Rowid" OpHelp("r[P2]=rowid"),
30406
+ /* 125 */ "NullRow" OpHelp(""),
30407
+ /* 126 */ "SeekEnd" OpHelp(""),
30408
+ /* 127 */ "SorterInsert" OpHelp("key=r[P2]"),
30409
+ /* 128 */ "IdxInsert" OpHelp("key=r[P2]"),
30410
+ /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30411
+ /* 130 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30412
+ /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"),
3034930413
/* 132 */ "Real" OpHelp("r[P2]=P4"),
30350
- /* 133 */ "Clear" OpHelp(""),
30351
- /* 134 */ "ResetSorter" OpHelp(""),
30352
- /* 135 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
30353
- /* 136 */ "SqlExec" OpHelp(""),
30354
- /* 137 */ "ParseSchema" OpHelp(""),
30355
- /* 138 */ "LoadAnalysis" OpHelp(""),
30356
- /* 139 */ "DropTable" OpHelp(""),
30357
- /* 140 */ "DropIndex" OpHelp(""),
30358
- /* 141 */ "DropTrigger" OpHelp(""),
30359
- /* 142 */ "IntegrityCk" OpHelp(""),
30360
- /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
30361
- /* 144 */ "Param" OpHelp(""),
30362
- /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
30363
- /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
30364
- /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
30365
- /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
30366
- /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
30367
- /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
30368
- /* 151 */ "Expire" OpHelp(""),
30369
- /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
30370
- /* 153 */ "VBegin" OpHelp(""),
30371
- /* 154 */ "VCreate" OpHelp(""),
30372
- /* 155 */ "VDestroy" OpHelp(""),
30373
- /* 156 */ "VOpen" OpHelp(""),
30374
- /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
30375
- /* 158 */ "VRename" OpHelp(""),
30376
- /* 159 */ "Pagecount" OpHelp(""),
30377
- /* 160 */ "MaxPgcnt" OpHelp(""),
30378
- /* 161 */ "PureFunc0" OpHelp(""),
30379
- /* 162 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
30380
- /* 163 */ "PureFunc" OpHelp(""),
30381
- /* 164 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
30382
- /* 165 */ "CursorHint" OpHelp(""),
30383
- /* 166 */ "Noop" OpHelp(""),
30384
- /* 167 */ "Explain" OpHelp(""),
30414
+ /* 133 */ "Destroy" OpHelp(""),
30415
+ /* 134 */ "Clear" OpHelp(""),
30416
+ /* 135 */ "ResetSorter" OpHelp(""),
30417
+ /* 136 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
30418
+ /* 137 */ "SqlExec" OpHelp(""),
30419
+ /* 138 */ "ParseSchema" OpHelp(""),
30420
+ /* 139 */ "LoadAnalysis" OpHelp(""),
30421
+ /* 140 */ "DropTable" OpHelp(""),
30422
+ /* 141 */ "DropIndex" OpHelp(""),
30423
+ /* 142 */ "DropTrigger" OpHelp(""),
30424
+ /* 143 */ "IntegrityCk" OpHelp(""),
30425
+ /* 144 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
30426
+ /* 145 */ "Param" OpHelp(""),
30427
+ /* 146 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
30428
+ /* 147 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
30429
+ /* 148 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
30430
+ /* 149 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
30431
+ /* 150 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
30432
+ /* 151 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
30433
+ /* 152 */ "Expire" OpHelp(""),
30434
+ /* 153 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
30435
+ /* 154 */ "VBegin" OpHelp(""),
30436
+ /* 155 */ "VCreate" OpHelp(""),
30437
+ /* 156 */ "VDestroy" OpHelp(""),
30438
+ /* 157 */ "VOpen" OpHelp(""),
30439
+ /* 158 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
30440
+ /* 159 */ "VRename" OpHelp(""),
30441
+ /* 160 */ "Pagecount" OpHelp(""),
30442
+ /* 161 */ "MaxPgcnt" OpHelp(""),
30443
+ /* 162 */ "PureFunc0" OpHelp(""),
30444
+ /* 163 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
30445
+ /* 164 */ "PureFunc" OpHelp(""),
30446
+ /* 165 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
30447
+ /* 166 */ "Trace" OpHelp(""),
30448
+ /* 167 */ "CursorHint" OpHelp(""),
30449
+ /* 168 */ "Noop" OpHelp(""),
30450
+ /* 169 */ "Explain" OpHelp(""),
3038530451
};
3038630452
return azName[i];
3038730453
}
3038830454
#endif
3038930455
@@ -53382,11 +53448,11 @@
5338253448
if( pPager->eState>PAGER_READER || pPager->tempFile ){
5338353449
pPg = sqlite3PagerLookup(pPager, pgno);
5338453450
}
5338553451
if( pPg==0 ){
5338653452
rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
53387
- }else{
53453
+ }else{
5338853454
sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
5338953455
}
5339053456
if( pPg ){
5339153457
assert( rc==SQLITE_OK );
5339253458
*ppPage = pPg;
@@ -64672,10 +64738,24 @@
6467264738
assert( pCur->curIntKey );
6467364739
getCellInfo(pCur);
6467464740
return pCur->info.nKey;
6467564741
}
6467664742
64743
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
64744
+/*
64745
+** Return the offset into the database file for the start of the
64746
+** payload to which the cursor is pointing.
64747
+*/
64748
+SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor *pCur){
64749
+ assert( cursorHoldsMutex(pCur) );
64750
+ assert( pCur->eState==CURSOR_VALID );
64751
+ getCellInfo(pCur);
64752
+ return (i64)pCur->pBt->pageSize*((i64)pCur->pPage->pgno - 1) +
64753
+ (i64)(pCur->info.pPayload - pCur->pPage->aData);
64754
+}
64755
+#endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */
64756
+
6467764757
/*
6467864758
** Return the number of bytes of payload for the entry that pCur is
6467964759
** currently pointing to. For table btrees, this will be the amount
6468064760
** of data. For index btrees, this will be the size of the key.
6468164761
**
@@ -72430,11 +72510,14 @@
7243072510
7243172511
*ppVal = pVal;
7243272512
return rc;
7243372513
7243472514
no_mem:
72435
- sqlite3OomFault(db);
72515
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
72516
+ if( pCtx==0 || pCtx->pParse->nErr==0 )
72517
+#endif
72518
+ sqlite3OomFault(db);
7243672519
sqlite3DbFree(db, zVal);
7243772520
assert( *ppVal==0 );
7243872521
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
7243972522
if( pCtx==0 ) sqlite3ValueFree(pVal);
7244072523
#else
@@ -74416,10 +74499,12 @@
7441674499
Mem *pSub = 0; /* Memory cell hold array of subprogs */
7441774500
sqlite3 *db = p->db; /* The database connection */
7441874501
int i; /* Loop counter */
7441974502
int rc = SQLITE_OK; /* Return code */
7442074503
Mem *pMem = &p->aMem[1]; /* First Mem of result set */
74504
+ int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
74505
+ Op *pOp = 0;
7442174506
7442274507
assert( p->explain );
7442374508
assert( p->magic==VDBE_MAGIC_RUN );
7442474509
assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
7442574510
@@ -74428,11 +74513,11 @@
7442874513
** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
7442974514
*/
7443074515
releaseMemArray(pMem, 8);
7443174516
p->pResultSet = 0;
7443274517
74433
- if( p->rc==SQLITE_NOMEM_BKPT ){
74518
+ if( p->rc==SQLITE_NOMEM ){
7443474519
/* This happens if a malloc() inside a call to sqlite3_column_text() or
7443574520
** sqlite3_column_text16() failed. */
7443674521
sqlite3OomFault(db);
7443774522
return SQLITE_ERROR;
7443874523
}
@@ -74443,11 +74528,11 @@
7444374528
** the sum of the number of rows in all trigger subprograms encountered
7444474529
** so far. The nRow value will increase as new trigger subprograms are
7444574530
** encountered, but p->pc will eventually catch up to nRow.
7444674531
*/
7444774532
nRow = p->nOp;
74448
- if( p->explain==1 ){
74533
+ if( bListSubprogs ){
7444974534
/* The first 8 memory cells are used for the result set. So we will
7445074535
** commandeer the 9th cell to use as storage for an array of pointers
7445174536
** to trigger subprograms. The VDBE is guaranteed to have at least 9
7445274537
** cells. */
7445374538
assert( p->nMem>9 );
@@ -74463,21 +74548,15 @@
7446374548
}
7446474549
}
7446574550
7446674551
do{
7446774552
i = p->pc++;
74468
- }while( i<nRow && p->explain==2 && p->aOp[i].opcode!=OP_Explain );
74469
- if( i>=nRow ){
74470
- p->rc = SQLITE_OK;
74471
- rc = SQLITE_DONE;
74472
- }else if( db->u1.isInterrupted ){
74473
- p->rc = SQLITE_INTERRUPT;
74474
- rc = SQLITE_ERROR;
74475
- sqlite3VdbeError(p, sqlite3ErrStr(p->rc));
74476
- }else{
74477
- char *zP4;
74478
- Op *pOp;
74553
+ if( i>=nRow ){
74554
+ p->rc = SQLITE_OK;
74555
+ rc = SQLITE_DONE;
74556
+ break;
74557
+ }
7447974558
if( i<p->nOp ){
7448074559
/* The output line number is small enough that we are still in the
7448174560
** main program. */
7448274561
pOp = &p->aOp[i];
7448374562
}else{
@@ -74488,98 +74567,114 @@
7448874567
for(j=0; i>=apSub[j]->nOp; j++){
7448974568
i -= apSub[j]->nOp;
7449074569
}
7449174570
pOp = &apSub[j]->aOp[i];
7449274571
}
74493
- if( p->explain==1 ){
74494
- pMem->flags = MEM_Int;
74495
- pMem->u.i = i; /* Program counter */
74496
- pMem++;
74497
-
74498
- pMem->flags = MEM_Static|MEM_Str|MEM_Term;
74499
- pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
74500
- assert( pMem->z!=0 );
74501
- pMem->n = sqlite3Strlen30(pMem->z);
74502
- pMem->enc = SQLITE_UTF8;
74503
- pMem++;
74504
-
74505
- /* When an OP_Program opcode is encounter (the only opcode that has
74506
- ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
74507
- ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
74508
- ** has not already been seen.
74509
- */
74510
- if( pOp->p4type==P4_SUBPROGRAM ){
74511
- int nByte = (nSub+1)*sizeof(SubProgram*);
74512
- int j;
74513
- for(j=0; j<nSub; j++){
74514
- if( apSub[j]==pOp->p4.pProgram ) break;
74515
- }
74516
- if( j==nSub && SQLITE_OK==sqlite3VdbeMemGrow(pSub, nByte, nSub!=0) ){
74517
- apSub = (SubProgram **)pSub->z;
74518
- apSub[nSub++] = pOp->p4.pProgram;
74519
- pSub->flags |= MEM_Blob;
74520
- pSub->n = nSub*sizeof(SubProgram*);
74521
- }
74522
- }
74523
- }
74524
-
74525
- pMem->flags = MEM_Int;
74526
- pMem->u.i = pOp->p1; /* P1 */
74527
- pMem++;
74528
-
74529
- pMem->flags = MEM_Int;
74530
- pMem->u.i = pOp->p2; /* P2 */
74531
- pMem++;
74532
-
74533
- pMem->flags = MEM_Int;
74534
- pMem->u.i = pOp->p3; /* P3 */
74535
- pMem++;
74536
-
74537
- if( sqlite3VdbeMemClearAndResize(pMem, 100) ){ /* P4 */
74538
- assert( p->db->mallocFailed );
74539
- return SQLITE_ERROR;
74540
- }
74541
- pMem->flags = MEM_Str|MEM_Term;
74542
- zP4 = displayP4(pOp, pMem->z, pMem->szMalloc);
74543
- if( zP4!=pMem->z ){
74544
- pMem->n = 0;
74545
- sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
74546
- }else{
74547
- assert( pMem->z!=0 );
74548
- pMem->n = sqlite3Strlen30(pMem->z);
74549
- pMem->enc = SQLITE_UTF8;
74550
- }
74551
- pMem++;
74552
-
74553
- if( p->explain==1 ){
74554
- if( sqlite3VdbeMemClearAndResize(pMem, 4) ){
74555
- assert( p->db->mallocFailed );
74556
- return SQLITE_ERROR;
74557
- }
74558
- pMem->flags = MEM_Str|MEM_Term;
74559
- pMem->n = 2;
74560
- sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
74561
- pMem->enc = SQLITE_UTF8;
74562
- pMem++;
74563
-
74564
-#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
74565
- if( sqlite3VdbeMemClearAndResize(pMem, 500) ){
74566
- assert( p->db->mallocFailed );
74567
- return SQLITE_ERROR;
74568
- }
74569
- pMem->flags = MEM_Str|MEM_Term;
74570
- pMem->n = displayComment(pOp, zP4, pMem->z, 500);
74571
- pMem->enc = SQLITE_UTF8;
74572
-#else
74573
- pMem->flags = MEM_Null; /* Comment */
74574
-#endif
74575
- }
74576
-
74577
- p->nResColumn = 8 - 4*(p->explain-1);
74578
- p->pResultSet = &p->aMem[1];
74579
- p->rc = SQLITE_OK;
74580
- rc = SQLITE_ROW;
74572
+
74573
+ /* When an OP_Program opcode is encounter (the only opcode that has
74574
+ ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
74575
+ ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
74576
+ ** has not already been seen.
74577
+ */
74578
+ if( bListSubprogs && pOp->p4type==P4_SUBPROGRAM ){
74579
+ int nByte = (nSub+1)*sizeof(SubProgram*);
74580
+ int j;
74581
+ for(j=0; j<nSub; j++){
74582
+ if( apSub[j]==pOp->p4.pProgram ) break;
74583
+ }
74584
+ if( j==nSub ){
74585
+ p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0);
74586
+ if( p->rc!=SQLITE_OK ){
74587
+ rc = SQLITE_ERROR;
74588
+ break;
74589
+ }
74590
+ apSub = (SubProgram **)pSub->z;
74591
+ apSub[nSub++] = pOp->p4.pProgram;
74592
+ pSub->flags |= MEM_Blob;
74593
+ pSub->n = nSub*sizeof(SubProgram*);
74594
+ nRow += pOp->p4.pProgram->nOp;
74595
+ }
74596
+ }
74597
+ }while( p->explain==2 && pOp->opcode!=OP_Explain );
74598
+
74599
+ if( rc==SQLITE_OK ){
74600
+ if( db->u1.isInterrupted ){
74601
+ p->rc = SQLITE_INTERRUPT;
74602
+ rc = SQLITE_ERROR;
74603
+ sqlite3VdbeError(p, sqlite3ErrStr(p->rc));
74604
+ }else{
74605
+ char *zP4;
74606
+ if( p->explain==1 ){
74607
+ pMem->flags = MEM_Int;
74608
+ pMem->u.i = i; /* Program counter */
74609
+ pMem++;
74610
+
74611
+ pMem->flags = MEM_Static|MEM_Str|MEM_Term;
74612
+ pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
74613
+ assert( pMem->z!=0 );
74614
+ pMem->n = sqlite3Strlen30(pMem->z);
74615
+ pMem->enc = SQLITE_UTF8;
74616
+ pMem++;
74617
+ }
74618
+
74619
+ pMem->flags = MEM_Int;
74620
+ pMem->u.i = pOp->p1; /* P1 */
74621
+ pMem++;
74622
+
74623
+ pMem->flags = MEM_Int;
74624
+ pMem->u.i = pOp->p2; /* P2 */
74625
+ pMem++;
74626
+
74627
+ pMem->flags = MEM_Int;
74628
+ pMem->u.i = pOp->p3; /* P3 */
74629
+ pMem++;
74630
+
74631
+ if( sqlite3VdbeMemClearAndResize(pMem, 100) ){ /* P4 */
74632
+ assert( p->db->mallocFailed );
74633
+ return SQLITE_ERROR;
74634
+ }
74635
+ pMem->flags = MEM_Str|MEM_Term;
74636
+ zP4 = displayP4(pOp, pMem->z, pMem->szMalloc);
74637
+ if( zP4!=pMem->z ){
74638
+ pMem->n = 0;
74639
+ sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
74640
+ }else{
74641
+ assert( pMem->z!=0 );
74642
+ pMem->n = sqlite3Strlen30(pMem->z);
74643
+ pMem->enc = SQLITE_UTF8;
74644
+ }
74645
+ pMem++;
74646
+
74647
+ if( p->explain==1 ){
74648
+ if( sqlite3VdbeMemClearAndResize(pMem, 4) ){
74649
+ assert( p->db->mallocFailed );
74650
+ return SQLITE_ERROR;
74651
+ }
74652
+ pMem->flags = MEM_Str|MEM_Term;
74653
+ pMem->n = 2;
74654
+ sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
74655
+ pMem->enc = SQLITE_UTF8;
74656
+ pMem++;
74657
+
74658
+#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
74659
+ if( sqlite3VdbeMemClearAndResize(pMem, 500) ){
74660
+ assert( p->db->mallocFailed );
74661
+ return SQLITE_ERROR;
74662
+ }
74663
+ pMem->flags = MEM_Str|MEM_Term;
74664
+ pMem->n = displayComment(pOp, zP4, pMem->z, 500);
74665
+ pMem->enc = SQLITE_UTF8;
74666
+#else
74667
+ pMem->flags = MEM_Null; /* Comment */
74668
+#endif
74669
+ }
74670
+
74671
+ p->nResColumn = 8 - 4*(p->explain-1);
74672
+ p->pResultSet = &p->aMem[1];
74673
+ p->rc = SQLITE_OK;
74674
+ rc = SQLITE_ROW;
74675
+ }
7458174676
}
7458274677
return rc;
7458374678
}
7458474679
#endif /* SQLITE_OMIT_EXPLAIN */
7458574680
@@ -82102,10 +82197,40 @@
8210282197
goto jump_to_p2;
8210382198
}
8210482199
break;
8210582200
}
8210682201
82202
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
82203
+/* Opcode: Offset P1 P2 P3 * *
82204
+** Synopsis: r[P3] = sqlite_offset(P1)
82205
+**
82206
+** Store in register r[P3] the byte offset into the database file that is the
82207
+** start of the payload for the record at which that cursor P1 is currently
82208
+** pointing.
82209
+**
82210
+** P2 is the column number for the argument to the sqlite_offset() function.
82211
+** This opcode does not use P2 itself, but the P2 value is used by the
82212
+** code generator. The P1, P2, and P3 operands to this opcode are the
82213
+** as as for OP_Column.
82214
+**
82215
+** This opcode is only available if SQLite is compiled with the
82216
+** -DSQLITE_ENABLE_OFFSET_SQL_FUNC option.
82217
+*/
82218
+case OP_Offset: { /* out3 */
82219
+ VdbeCursor *pC; /* The VDBE cursor */
82220
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
82221
+ pC = p->apCsr[pOp->p1];
82222
+ pOut = &p->aMem[pOp->p3];
82223
+ if( NEVER(pC==0) || pC->eCurType!=CURTYPE_BTREE ){
82224
+ sqlite3VdbeMemSetNull(pOut);
82225
+ }else{
82226
+ sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor));
82227
+ }
82228
+ break;
82229
+}
82230
+#endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */
82231
+
8210782232
/* Opcode: Column P1 P2 P3 P4 P5
8210882233
** Synopsis: r[P3]=PX
8210982234
**
8211082235
** Interpret the data that cursor P1 points to as a structure built using
8211182236
** the MakeRecord instruction. (See the MakeRecord opcode for additional
@@ -86769,11 +86894,17 @@
8676986894
REGISTER_TRACE(pOp->p3, pOut);
8677086895
UPDATE_MAX_BLOBSIZE(pOut);
8677186896
break;
8677286897
}
8677386898
86774
-
86899
+/* Opcode: Trace P1 P2 * P4 *
86900
+**
86901
+** Write P4 on the statement trace output if statement tracing is
86902
+** enabled.
86903
+**
86904
+** Operand P1 must be 0x7fffffff and P2 must positive.
86905
+*/
8677586906
/* Opcode: Init P1 P2 P3 P4 *
8677686907
** Synopsis: Start at P2
8677786908
**
8677886909
** Programs contain a single instance of this opcode as the very first
8677986910
** opcode.
@@ -86788,10 +86919,11 @@
8678886919
** first time they are evaluated for this run.
8678986920
**
8679086921
** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
8679186922
** error is encountered.
8679286923
*/
86924
+case OP_Trace:
8679386925
case OP_Init: { /* jump */
8679486926
char *zTrace;
8679586927
int i;
8679686928
8679786929
/* If the P4 argument is not NULL, then it must be an SQL comment string.
@@ -86802,11 +86934,13 @@
8680286934
** would have been returned by the legacy sqlite3_trace() interface by
8680386935
** using the X argument when X begins with "--" and invoking
8680486936
** sqlite3_expanded_sql(P) otherwise.
8680586937
*/
8680686938
assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
86807
- assert( pOp==p->aOp ); /* Always instruction 0 */
86939
+
86940
+ /* OP_Init is always instruction 0 */
86941
+ assert( pOp==p->aOp || pOp->opcode==OP_Trace );
8680886942
8680986943
#ifndef SQLITE_OMIT_TRACE
8681086944
if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
8681186945
&& !p->doingRerun
8681286946
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
@@ -86845,10 +86979,11 @@
8684586979
}
8684686980
#endif /* SQLITE_DEBUG */
8684786981
#endif /* SQLITE_OMIT_TRACE */
8684886982
assert( pOp->p2>0 );
8684986983
if( pOp->p1>=sqlite3GlobalConfig.iOnceResetThreshold ){
86984
+ if( pOp->opcode==OP_Trace ) break;
8685086985
for(i=1; i<p->nOp; i++){
8685186986
if( p->aOp[i].opcode==OP_Once ) p->aOp[i].p1 = 0;
8685286987
}
8685386988
pOp->p1 = 0;
8685486989
}
@@ -94048,21 +94183,20 @@
9404894183
** is set.
9404994184
*/
9405094185
SQLITE_PRIVATE void sqlite3ExprListSetSpan(
9405194186
Parse *pParse, /* Parsing context */
9405294187
ExprList *pList, /* List to which to add the span. */
94053
- ExprSpan *pSpan /* The span to be added */
94188
+ const char *zStart, /* Start of the span */
94189
+ const char *zEnd /* End of the span */
9405494190
){
9405594191
sqlite3 *db = pParse->db;
9405694192
assert( pList!=0 || db->mallocFailed!=0 );
9405794193
if( pList ){
9405894194
struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
9405994195
assert( pList->nExpr>0 );
94060
- assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
9406194196
sqlite3DbFree(db, pItem->zSpan);
94062
- pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
94063
- (int)(pSpan->zEnd - pSpan->zStart));
94197
+ pItem->zSpan = sqlite3DbSpanDup(db, zStart, zEnd);
9406494198
}
9406594199
}
9406694200
9406794201
/*
9406894202
** If the expression list pEList contains more than iLimit elements,
@@ -96265,13 +96399,25 @@
9626596399
#endif
9626696400
if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
9626796401
if( !pColl ) pColl = db->pDfltColl;
9626896402
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
9626996403
}
96270
- sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0,
96271
- constMask, r1, target, (char*)pDef, P4_FUNCDEF);
96272
- sqlite3VdbeChangeP5(v, (u8)nFarg);
96404
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
96405
+ if( pDef->funcFlags & SQLITE_FUNC_OFFSET ){
96406
+ Expr *pArg = pFarg->a[0].pExpr;
96407
+ if( pArg->op==TK_COLUMN ){
96408
+ sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
96409
+ }else{
96410
+ sqlite3VdbeAddOp2(v, OP_Null, 0, target);
96411
+ }
96412
+ }else
96413
+#endif
96414
+ {
96415
+ sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0,
96416
+ constMask, r1, target, (char*)pDef, P4_FUNCDEF);
96417
+ sqlite3VdbeChangeP5(v, (u8)nFarg);
96418
+ }
9627396419
if( nFarg && constMask==0 ){
9627496420
sqlite3ReleaseTempRange(pParse, r1, nFarg);
9627596421
}
9627696422
return target;
9627796423
}
@@ -102511,38 +102657,41 @@
102511102657
** is not the case.
102512102658
**
102513102659
** This routine is called by the parser while in the middle of
102514102660
** parsing a CREATE TABLE statement.
102515102661
*/
102516
-SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse *pParse, ExprSpan *pSpan){
102662
+SQLITE_PRIVATE void sqlite3AddDefaultValue(
102663
+ Parse *pParse, /* Parsing context */
102664
+ Expr *pExpr, /* The parsed expression of the default value */
102665
+ const char *zStart, /* Start of the default value text */
102666
+ const char *zEnd /* First character past end of defaut value text */
102667
+){
102517102668
Table *p;
102518102669
Column *pCol;
102519102670
sqlite3 *db = pParse->db;
102520102671
p = pParse->pNewTable;
102521102672
if( p!=0 ){
102522102673
pCol = &(p->aCol[p->nCol-1]);
102523
- if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr, db->init.busy) ){
102674
+ if( !sqlite3ExprIsConstantOrFunction(pExpr, db->init.busy) ){
102524102675
sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
102525102676
pCol->zName);
102526102677
}else{
102527102678
/* A copy of pExpr is used instead of the original, as pExpr contains
102528
- ** tokens that point to volatile memory. The 'span' of the expression
102529
- ** is required by pragma table_info.
102679
+ ** tokens that point to volatile memory.
102530102680
*/
102531102681
Expr x;
102532102682
sqlite3ExprDelete(db, pCol->pDflt);
102533102683
memset(&x, 0, sizeof(x));
102534102684
x.op = TK_SPAN;
102535
- x.u.zToken = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
102536
- (int)(pSpan->zEnd - pSpan->zStart));
102537
- x.pLeft = pSpan->pExpr;
102685
+ x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd);
102686
+ x.pLeft = pExpr;
102538102687
x.flags = EP_Skip;
102539102688
pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
102540102689
sqlite3DbFree(db, x.u.zToken);
102541102690
}
102542102691
}
102543
- sqlite3ExprDelete(db, pSpan->pExpr);
102692
+ sqlite3ExprDelete(db, pExpr);
102544102693
}
102545102694
102546102695
/*
102547102696
** Backwards Compatibility Hack:
102548102697
**
@@ -103255,23 +103404,24 @@
103255103404
sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
103256103405
sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
103257103406
pParse->nTab = 2;
103258103407
addrTop = sqlite3VdbeCurrentAddr(v) + 1;
103259103408
sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
103260
- sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
103261
- sqlite3Select(pParse, pSelect, &dest);
103262
- sqlite3VdbeEndCoroutine(v, regYield);
103263
- sqlite3VdbeJumpHere(v, addrTop - 1);
103264103409
if( pParse->nErr ) return;
103265103410
pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect);
103266103411
if( pSelTab==0 ) return;
103267103412
assert( p->aCol==0 );
103268103413
p->nCol = pSelTab->nCol;
103269103414
p->aCol = pSelTab->aCol;
103270103415
pSelTab->nCol = 0;
103271103416
pSelTab->aCol = 0;
103272103417
sqlite3DeleteTable(db, pSelTab);
103418
+ sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
103419
+ sqlite3Select(pParse, pSelect, &dest);
103420
+ if( pParse->nErr ) return;
103421
+ sqlite3VdbeEndCoroutine(v, regYield);
103422
+ sqlite3VdbeJumpHere(v, addrTop - 1);
103273103423
addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
103274103424
VdbeCoverage(v);
103275103425
sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
103276103426
sqlite3TableAffinity(v, p, 0);
103277103427
sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
@@ -108980,10 +109130,14 @@
108980109130
FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
108981109131
FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
108982109132
#ifdef SQLITE_DEBUG
108983109133
FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY),
108984109134
#endif
109135
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
109136
+ FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET|
109137
+ SQLITE_FUNC_TYPEOF),
109138
+#endif
108985109139
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
108986109140
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
108987109141
FUNCTION(rtrim, 1, 2, 0, trimFunc ),
108988109142
FUNCTION(rtrim, 2, 2, 0, trimFunc ),
108989109143
FUNCTION(trim, 1, 3, 0, trimFunc ),
@@ -112072,10 +112226,11 @@
112072112226
sqlite3VdbeResolveLabel(v, addrUniqueOk);
112073112227
continue;
112074112228
}
112075112229
112076112230
/* Check to see if the new index entry will be unique */
112231
+ sqlite3ExprCachePush(pParse);
112077112232
sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
112078112233
regIdx, pIdx->nKeyCol); VdbeCoverage(v);
112079112234
112080112235
/* Generate code to handle collisions */
112081112236
regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
@@ -112160,10 +112315,11 @@
112160112315
seenReplace = 1;
112161112316
break;
112162112317
}
112163112318
}
112164112319
sqlite3VdbeResolveLabel(v, addrUniqueOk);
112320
+ sqlite3ExprCachePop(pParse);
112165112321
if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
112166112322
}
112167112323
if( ipkTop ){
112168112324
sqlite3VdbeGoto(v, ipkTop+1);
112169112325
sqlite3VdbeJumpHere(v, ipkBottom);
@@ -113985,12 +114141,14 @@
113985114141
113986114142
handle = sqlite3OsDlOpen(pVfs, zFile);
113987114143
#if SQLITE_OS_UNIX || SQLITE_OS_WIN
113988114144
for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
113989114145
char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
114146
+ int bExists = 0;
113990114147
if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
113991
- handle = sqlite3OsDlOpen(pVfs, zAltFile);
114148
+ sqlite3OsAccess(pVfs, zAltFile, SQLITE_ACCESS_EXISTS, &bExists);
114149
+ if( bExists ) handle = sqlite3OsDlOpen(pVfs, zAltFile);
113992114150
sqlite3_free(zAltFile);
113993114151
}
113994114152
#endif
113995114153
if( handle==0 ){
113996114154
if( pzErrMsg ){
@@ -116022,10 +116180,11 @@
116022116180
** cid: Column id (numbered from left to right, starting at 0)
116023116181
** name: Column name
116024116182
** type: Column declaration type.
116025116183
** notnull: True if 'NOT NULL' is part of column declaration
116026116184
** dflt_value: The default value for the column, if any.
116185
+ ** pk: Non-zero for PK fields.
116027116186
*/
116028116187
case PragTyp_TABLE_INFO: if( zRight ){
116029116188
Table *pTab;
116030116189
pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
116031116190
if( pTab ){
@@ -119715,22 +119874,21 @@
119715119874
char const *zOrigCol = 0;
119716119875
#endif
119717119876
119718119877
assert( pExpr!=0 );
119719119878
assert( pNC->pSrcList!=0 );
119879
+ assert( pExpr->op!=TK_AGG_COLUMN ); /* This routine runes before aggregates
119880
+ ** are processed */
119720119881
switch( pExpr->op ){
119721
- case TK_AGG_COLUMN:
119722119882
case TK_COLUMN: {
119723119883
/* The expression is a column. Locate the table the column is being
119724119884
** extracted from in NameContext.pSrcList. This table may be real
119725119885
** database table or a subquery.
119726119886
*/
119727119887
Table *pTab = 0; /* Table structure column is extracted from */
119728119888
Select *pS = 0; /* Select the column is extracted from */
119729119889
int iCol = pExpr->iColumn; /* Index of column in pTab */
119730
- testcase( pExpr->op==TK_AGG_COLUMN );
119731
- testcase( pExpr->op==TK_COLUMN );
119732119890
while( pNC && !pTab ){
119733119891
SrcList *pTabList = pNC->pSrcList;
119734119892
for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
119735119893
if( j<pTabList->nSrc ){
119736119894
pTab = pTabList->a[j].pTab;
@@ -119930,10 +120088,11 @@
119930120088
#endif
119931120089
119932120090
if( pParse->colNamesSet || db->mallocFailed ) return;
119933120091
/* Column names are determined by the left-most term of a compound select */
119934120092
while( pSelect->pPrior ) pSelect = pSelect->pPrior;
120093
+ SELECTTRACE(1,pParse,pSelect,("generating column names\n"));
119935120094
pTabList = pSelect->pSrc;
119936120095
pEList = pSelect->pEList;
119937120096
assert( v!=0 );
119938120097
assert( pTabList!=0 );
119939120098
pParse->colNamesSet = 1;
@@ -120038,16 +120197,16 @@
120038120197
Expr *pColExpr = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
120039120198
while( pColExpr->op==TK_DOT ){
120040120199
pColExpr = pColExpr->pRight;
120041120200
assert( pColExpr!=0 );
120042120201
}
120043
- if( (pColExpr->op==TK_COLUMN || pColExpr->op==TK_AGG_COLUMN)
120044
- && pColExpr->pTab!=0
120045
- ){
120202
+ assert( pColExpr->op!=TK_AGG_COLUMN );
120203
+ if( pColExpr->op==TK_COLUMN ){
120046120204
/* For columns use the column name name */
120047120205
int iCol = pColExpr->iColumn;
120048120206
Table *pTab = pColExpr->pTab;
120207
+ assert( pTab!=0 );
120049120208
if( iCol<0 ) iCol = pTab->iPKey;
120050120209
zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
120051120210
}else if( pColExpr->op==TK_ID ){
120052120211
assert( !ExprHasProperty(pColExpr, EP_IntValue) );
120053120212
zName = pColExpr->u.zToken;
@@ -124606,10 +124765,11 @@
124606124765
124607124766
sqlite3ExprDelete(db, pTmp->pWhere);
124608124767
sqlite3ExprListDelete(db, pTmp->pExprList);
124609124768
sqlite3SelectDelete(db, pTmp->pSelect);
124610124769
sqlite3IdListDelete(db, pTmp->pIdList);
124770
+ sqlite3DbFree(db, pTmp->zSpan);
124611124771
124612124772
sqlite3DbFree(db, pTmp);
124613124773
}
124614124774
}
124615124775
@@ -124920,26 +125080,43 @@
124920125080
sqlite3DeleteTrigger(db, pTrig);
124921125081
assert( !pParse->pNewTrigger );
124922125082
sqlite3DeleteTriggerStep(db, pStepList);
124923125083
}
124924125084
125085
+/*
125086
+** Duplicate a range of text from an SQL statement, then convert all
125087
+** whitespace characters into ordinary space characters.
125088
+*/
125089
+static char *triggerSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
125090
+ char *z = sqlite3DbSpanDup(db, zStart, zEnd);
125091
+ int i;
125092
+ if( z ) for(i=0; z[i]; i++) if( sqlite3Isspace(z[i]) ) z[i] = ' ';
125093
+ return z;
125094
+}
125095
+
124925125096
/*
124926125097
** Turn a SELECT statement (that the pSelect parameter points to) into
124927125098
** a trigger step. Return a pointer to a TriggerStep structure.
124928125099
**
124929125100
** The parser calls this routine when it finds a SELECT statement in
124930125101
** body of a TRIGGER.
124931125102
*/
124932
-SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
125103
+SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(
125104
+ sqlite3 *db, /* Database connection */
125105
+ Select *pSelect, /* The SELECT statement */
125106
+ const char *zStart, /* Start of SQL text */
125107
+ const char *zEnd /* End of SQL text */
125108
+){
124933125109
TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
124934125110
if( pTriggerStep==0 ) {
124935125111
sqlite3SelectDelete(db, pSelect);
124936125112
return 0;
124937125113
}
124938125114
pTriggerStep->op = TK_SELECT;
124939125115
pTriggerStep->pSelect = pSelect;
124940125116
pTriggerStep->orconf = OE_Default;
125117
+ pTriggerStep->zSpan = triggerSpanDup(db, zStart, zEnd);
124941125118
return pTriggerStep;
124942125119
}
124943125120
124944125121
/*
124945125122
** Allocate space to hold a new trigger step. The allocated space
@@ -124948,11 +125125,13 @@
124948125125
** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
124949125126
*/
124950125127
static TriggerStep *triggerStepAllocate(
124951125128
sqlite3 *db, /* Database connection */
124952125129
u8 op, /* Trigger opcode */
124953
- Token *pName /* The target name */
125130
+ Token *pName, /* The target name */
125131
+ const char *zStart, /* Start of SQL text */
125132
+ const char *zEnd /* End of SQL text */
124954125133
){
124955125134
TriggerStep *pTriggerStep;
124956125135
124957125136
pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
124958125137
if( pTriggerStep ){
@@ -124959,10 +125138,11 @@
124959125138
char *z = (char*)&pTriggerStep[1];
124960125139
memcpy(z, pName->z, pName->n);
124961125140
sqlite3Dequote(z);
124962125141
pTriggerStep->zTarget = z;
124963125142
pTriggerStep->op = op;
125143
+ pTriggerStep->zSpan = triggerSpanDup(db, zStart, zEnd);
124964125144
}
124965125145
return pTriggerStep;
124966125146
}
124967125147
124968125148
/*
@@ -124975,17 +125155,19 @@
124975125155
SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(
124976125156
sqlite3 *db, /* The database connection */
124977125157
Token *pTableName, /* Name of the table into which we insert */
124978125158
IdList *pColumn, /* List of columns in pTableName to insert into */
124979125159
Select *pSelect, /* A SELECT statement that supplies values */
124980
- u8 orconf /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
125160
+ u8 orconf, /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
125161
+ const char *zStart, /* Start of SQL text */
125162
+ const char *zEnd /* End of SQL text */
124981125163
){
124982125164
TriggerStep *pTriggerStep;
124983125165
124984125166
assert(pSelect != 0 || db->mallocFailed);
124985125167
124986
- pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
125168
+ pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName, zStart, zEnd);
124987125169
if( pTriggerStep ){
124988125170
pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
124989125171
pTriggerStep->pIdList = pColumn;
124990125172
pTriggerStep->orconf = orconf;
124991125173
}else{
@@ -125004,15 +125186,17 @@
125004125186
SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(
125005125187
sqlite3 *db, /* The database connection */
125006125188
Token *pTableName, /* Name of the table to be updated */
125007125189
ExprList *pEList, /* The SET clause: list of column and new values */
125008125190
Expr *pWhere, /* The WHERE clause */
125009
- u8 orconf /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
125191
+ u8 orconf, /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
125192
+ const char *zStart, /* Start of SQL text */
125193
+ const char *zEnd /* End of SQL text */
125010125194
){
125011125195
TriggerStep *pTriggerStep;
125012125196
125013
- pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
125197
+ pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName, zStart, zEnd);
125014125198
if( pTriggerStep ){
125015125199
pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
125016125200
pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
125017125201
pTriggerStep->orconf = orconf;
125018125202
}
@@ -125027,15 +125211,17 @@
125027125211
** sees a DELETE statement inside the body of a CREATE TRIGGER.
125028125212
*/
125029125213
SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(
125030125214
sqlite3 *db, /* Database connection */
125031125215
Token *pTableName, /* The table from which rows are deleted */
125032
- Expr *pWhere /* The WHERE clause */
125216
+ Expr *pWhere, /* The WHERE clause */
125217
+ const char *zStart, /* Start of SQL text */
125218
+ const char *zEnd /* End of SQL text */
125033125219
){
125034125220
TriggerStep *pTriggerStep;
125035125221
125036
- pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
125222
+ pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName, zStart, zEnd);
125037125223
if( pTriggerStep ){
125038125224
pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
125039125225
pTriggerStep->orconf = OE_Default;
125040125226
}
125041125227
sqlite3ExprDelete(db, pWhere);
@@ -125285,10 +125471,18 @@
125285125471
** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
125286125472
** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
125287125473
*/
125288125474
pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
125289125475
assert( pParse->okConstFactor==0 );
125476
+
125477
+#ifndef SQLITE_OMIT_TRACE
125478
+ if( pStep->zSpan ){
125479
+ sqlite3VdbeAddOp4(v, OP_Trace, 0x7fffffff, 1, 0,
125480
+ sqlite3MPrintf(db, "-- %s", pStep->zSpan),
125481
+ P4_DYNAMIC);
125482
+ }
125483
+#endif
125290125484
125291125485
switch( pStep->op ){
125292125486
case TK_UPDATE: {
125293125487
sqlite3Update(pParse,
125294125488
targetSrcList(pParse, pStep),
@@ -125426,13 +125620,15 @@
125426125620
(pTrigger->op==TK_INSERT ? "INSERT" : ""),
125427125621
(pTrigger->op==TK_DELETE ? "DELETE" : ""),
125428125622
pTab->zName
125429125623
));
125430125624
#ifndef SQLITE_OMIT_TRACE
125431
- sqlite3VdbeChangeP4(v, -1,
125432
- sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
125433
- );
125625
+ if( pTrigger->zName ){
125626
+ sqlite3VdbeChangeP4(v, -1,
125627
+ sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
125628
+ );
125629
+ }
125434125630
#endif
125435125631
125436125632
/* If one was specified, code the WHEN clause. If it evaluates to false
125437125633
** (or NULL) the sub-vdbe is immediately halted by jumping to the
125438125634
** OP_Halt inserted at the end of the program. */
@@ -128896,11 +129092,11 @@
128896129092
int iFrom, /* Value for "from" column of output */
128897129093
u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
128898129094
){
128899129095
int ret = 0;
128900129096
#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
128901
- if( pParse->explain==2 )
129097
+ if( sqlite3ParseToplevel(pParse)->explain==2 )
128902129098
#endif
128903129099
{
128904129100
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
128905129101
Vdbe *v = pParse->pVdbe; /* VM being constructed */
128906129102
sqlite3 *db = pParse->db; /* Database handle */
@@ -132526,10 +132722,25 @@
132526132722
** so is applicable. Because this module is responsible for selecting
132527132723
** indices, you might also think of this module as the "query optimizer".
132528132724
*/
132529132725
/* #include "sqliteInt.h" */
132530132726
/* #include "whereInt.h" */
132727
+
132728
+/*
132729
+** Extra information appended to the end of sqlite3_index_info but not
132730
+** visible to the xBestIndex function, at least not directly. The
132731
+** sqlite3_vtab_collation() interface knows how to reach it, however.
132732
+**
132733
+** This object is not an API and can be changed from one release to the
132734
+** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()
132735
+** agree on the structure, all will be well.
132736
+*/
132737
+typedef struct HiddenIndexInfo HiddenIndexInfo;
132738
+struct HiddenIndexInfo {
132739
+ WhereClause *pWC; /* The Where clause being analyzed */
132740
+ Parse *pParse; /* The parsing context */
132741
+};
132531132742
132532132743
/* Forward declaration of methods */
132533132744
static int whereLoopResize(sqlite3*, WhereLoop*, int);
132534132745
132535132746
/* Test variable that can be set to enable WHERE tracing */
@@ -133349,22 +133560,23 @@
133349133560
** Allocate and populate an sqlite3_index_info structure. It is the
133350133561
** responsibility of the caller to eventually release the structure
133351133562
** by passing the pointer returned by this function to sqlite3_free().
133352133563
*/
133353133564
static sqlite3_index_info *allocateIndexInfo(
133354
- Parse *pParse,
133355
- WhereClause *pWC,
133565
+ Parse *pParse, /* The parsing context */
133566
+ WhereClause *pWC, /* The WHERE clause being analyzed */
133356133567
Bitmask mUnusable, /* Ignore terms with these prereqs */
133357
- struct SrcList_item *pSrc,
133358
- ExprList *pOrderBy,
133568
+ struct SrcList_item *pSrc, /* The FROM clause term that is the vtab */
133569
+ ExprList *pOrderBy, /* The ORDER BY clause */
133359133570
u16 *pmNoOmit /* Mask of terms not to omit */
133360133571
){
133361133572
int i, j;
133362133573
int nTerm;
133363133574
struct sqlite3_index_constraint *pIdxCons;
133364133575
struct sqlite3_index_orderby *pIdxOrderBy;
133365133576
struct sqlite3_index_constraint_usage *pUsage;
133577
+ struct HiddenIndexInfo *pHidden;
133366133578
WhereTerm *pTerm;
133367133579
int nOrderBy;
133368133580
sqlite3_index_info *pIdxInfo;
133369133581
u16 mNoOmit = 0;
133370133582
@@ -133402,11 +133614,11 @@
133402133614
133403133615
/* Allocate the sqlite3_index_info structure
133404133616
*/
133405133617
pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
133406133618
+ (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
133407
- + sizeof(*pIdxOrderBy)*nOrderBy );
133619
+ + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
133408133620
if( pIdxInfo==0 ){
133409133621
sqlite3ErrorMsg(pParse, "out of memory");
133410133622
return 0;
133411133623
}
133412133624
@@ -133413,20 +133625,23 @@
133413133625
/* Initialize the structure. The sqlite3_index_info structure contains
133414133626
** many fields that are declared "const" to prevent xBestIndex from
133415133627
** changing them. We have to do some funky casting in order to
133416133628
** initialize those fields.
133417133629
*/
133418
- pIdxCons = (struct sqlite3_index_constraint*)&pIdxInfo[1];
133630
+ pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
133631
+ pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
133419133632
pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
133420133633
pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
133421133634
*(int*)&pIdxInfo->nConstraint = nTerm;
133422133635
*(int*)&pIdxInfo->nOrderBy = nOrderBy;
133423133636
*(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
133424133637
*(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
133425133638
*(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
133426133639
pUsage;
133427133640
133641
+ pHidden->pWC = pWC;
133642
+ pHidden->pParse = pParse;
133428133643
for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
133429133644
u16 op;
133430133645
if( pTerm->leftCursor != pSrc->iCursor ) continue;
133431133646
if( pTerm->prereqRight & mUnusable ) continue;
133432133647
assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
@@ -135646,10 +135861,31 @@
135646135861
(sqlite3_uint64)(pNew->prereq & ~mPrereq)));
135647135862
135648135863
return rc;
135649135864
}
135650135865
135866
+/*
135867
+** If this function is invoked from within an xBestIndex() callback, it
135868
+** returns a pointer to a buffer containing the name of the collation
135869
+** sequence associated with element iCons of the sqlite3_index_info.aConstraint
135870
+** array. Or, if iCons is out of range or there is no active xBestIndex
135871
+** call, return NULL.
135872
+*/
135873
+SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info *pIdxInfo, int iCons){
135874
+ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
135875
+ const char *zRet = 0;
135876
+ if( iCons>=0 && iCons<pIdxInfo->nConstraint ){
135877
+ CollSeq *pC = 0;
135878
+ int iTerm = pIdxInfo->aConstraint[iCons].iTermOffset;
135879
+ Expr *pX = pHidden->pWC->a[iTerm].pExpr;
135880
+ if( pX->pLeft ){
135881
+ pC = sqlite3BinaryCompareCollSeq(pHidden->pParse, pX->pLeft, pX->pRight);
135882
+ }
135883
+ zRet = (pC ? pC->zName : "BINARY");
135884
+ }
135885
+ return zRet;
135886
+}
135651135887
135652135888
/*
135653135889
** Add all WhereLoop objects for a table of the join identified by
135654135890
** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
135655135891
**
@@ -137614,11 +137850,15 @@
137614137850
last = sqlite3VdbeCurrentAddr(v);
137615137851
k = pLevel->addrBody;
137616137852
pOp = sqlite3VdbeGetOp(v, k);
137617137853
for(; k<last; k++, pOp++){
137618137854
if( pOp->p1!=pLevel->iTabCur ) continue;
137619
- if( pOp->opcode==OP_Column ){
137855
+ if( pOp->opcode==OP_Column
137856
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
137857
+ || pOp->opcode==OP_Offset
137858
+#endif
137859
+ ){
137620137860
int x = pOp->p2;
137621137861
assert( pIdx->pTable==pTab );
137622137862
if( !HasRowid(pTab) ){
137623137863
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
137624137864
x = pPk->aiColumn[x];
@@ -137756,24 +137996,16 @@
137756137996
sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
137757137997
}
137758137998
}
137759137999
}
137760138000
137761
- /* This is a utility routine used to set the ExprSpan.zStart and
137762
- ** ExprSpan.zEnd values of pOut so that the span covers the complete
137763
- ** range of text beginning with pStart and going to the end of pEnd.
137764
- */
137765
- static void spanSet(ExprSpan *pOut, Token *pStart, Token *pEnd){
137766
- pOut->zStart = pStart->z;
137767
- pOut->zEnd = &pEnd->z[pEnd->n];
137768
- }
137769138001
137770138002
/* Construct a new Expr object from a single identifier. Use the
137771138003
** new Expr to populate pOut. Set the span of pOut to be the identifier
137772138004
** that created the expression.
137773138005
*/
137774
- static void spanExpr(ExprSpan *pOut, Parse *pParse, int op, Token t){
138006
+ static Expr *tokenExpr(Parse *pParse, int op, Token t){
137775138007
Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
137776138008
if( p ){
137777138009
memset(p, 0, sizeof(Expr));
137778138010
p->op = (u8)op;
137779138011
p->flags = EP_Leaf;
@@ -137787,48 +138019,12 @@
137787138019
}
137788138020
#if SQLITE_MAX_EXPR_DEPTH>0
137789138021
p->nHeight = 1;
137790138022
#endif
137791138023
}
137792
- pOut->pExpr = p;
137793
- pOut->zStart = t.z;
137794
- pOut->zEnd = &t.z[t.n];
137795
- }
137796
-
137797
- /* This routine constructs a binary expression node out of two ExprSpan
137798
- ** objects and uses the result to populate a new ExprSpan object.
137799
- */
137800
- static void spanBinaryExpr(
137801
- Parse *pParse, /* The parsing context. Errors accumulate here */
137802
- int op, /* The binary operation */
137803
- ExprSpan *pLeft, /* The left operand, and output */
137804
- ExprSpan *pRight /* The right operand */
137805
- ){
137806
- pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr);
137807
- pLeft->zEnd = pRight->zEnd;
137808
- }
137809
-
137810
- /* If doNot is true, then add a TK_NOT Expr-node wrapper around the
137811
- ** outside of *ppExpr.
137812
- */
137813
- static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){
137814
- if( doNot ){
137815
- pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0);
137816
- }
137817
- }
137818
-
137819
- /* Construct an expression node for a unary postfix operator
137820
- */
137821
- static void spanUnaryPostfix(
137822
- Parse *pParse, /* Parsing context to record errors */
137823
- int op, /* The operator */
137824
- ExprSpan *pOperand, /* The operand, and output */
137825
- Token *pPostOp /* The operand token for setting the span */
137826
- ){
137827
- pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
137828
- pOperand->zEnd = &pPostOp->z[pPostOp->n];
137829
- }
138024
+ return p;
138025
+ }
137830138026
137831138027
/* A routine to convert a binary TK_IS or TK_ISNOT expression into a
137832138028
** unary TK_ISNULL or TK_NOTNULL expression. */
137833138029
static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
137834138030
sqlite3 *db = pParse->db;
@@ -137837,24 +138033,10 @@
137837138033
sqlite3ExprDelete(db, pA->pRight);
137838138034
pA->pRight = 0;
137839138035
}
137840138036
}
137841138037
137842
- /* Construct an expression node for a unary prefix operator
137843
- */
137844
- static void spanUnaryPrefix(
137845
- ExprSpan *pOut, /* Write the new expression node here */
137846
- Parse *pParse, /* Parsing context to record errors */
137847
- int op, /* The operator */
137848
- ExprSpan *pOperand, /* The operand */
137849
- Token *pPreOp /* The operand token for setting the span */
137850
- ){
137851
- pOut->zStart = pPreOp->z;
137852
- pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
137853
- pOut->zEnd = pOperand->zEnd;
137854
- }
137855
-
137856138038
/* Add a single new term to an ExprList that is used to store a
137857138039
** list of identifiers. Report an error if the ID list contains
137858138040
** a COLLATE clause or an ASC or DESC keyword, except ignore the
137859138041
** error while parsing a legacy schema.
137860138042
*/
@@ -137919,61 +138101,63 @@
137919138101
** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
137920138102
** YYERRORSYMBOL is the code number of the error symbol. If not
137921138103
** defined, then do no error processing.
137922138104
** YYNSTATE the combined number of states.
137923138105
** YYNRULE the number of rules in the grammar
138106
+** YYNTOKEN Number of terminal symbols
137924138107
** YY_MAX_SHIFT Maximum value for shift actions
137925138108
** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
137926138109
** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
137927
-** YY_MIN_REDUCE Minimum value for reduce actions
137928
-** YY_MAX_REDUCE Maximum value for reduce actions
137929138110
** YY_ERROR_ACTION The yy_action[] code for syntax error
137930138111
** YY_ACCEPT_ACTION The yy_action[] code for accept
137931138112
** YY_NO_ACTION The yy_action[] code for no-op
138113
+** YY_MIN_REDUCE Minimum value for reduce actions
138114
+** YY_MAX_REDUCE Maximum value for reduce actions
137932138115
*/
137933138116
#ifndef INTERFACE
137934138117
# define INTERFACE 1
137935138118
#endif
137936138119
/************* Begin control #defines *****************************************/
137937138120
#define YYCODETYPE unsigned char
137938
-#define YYNOCODE 252
138121
+#define YYNOCODE 253
137939138122
#define YYACTIONTYPE unsigned short int
137940138123
#define YYWILDCARD 83
137941138124
#define sqlite3ParserTOKENTYPE Token
137942138125
typedef union {
137943138126
int yyinit;
137944138127
sqlite3ParserTOKENTYPE yy0;
137945
- Expr* yy72;
137946
- TriggerStep* yy145;
137947
- ExprList* yy148;
137948
- SrcList* yy185;
137949
- ExprSpan yy190;
137950
- int yy194;
137951
- Select* yy243;
137952
- IdList* yy254;
137953
- With* yy285;
137954
- struct TrigEvent yy332;
137955
- struct {int value; int mask;} yy497;
138128
+ int yy4;
138129
+ struct TrigEvent yy90;
138130
+ TriggerStep* yy203;
138131
+ struct {int value; int mask;} yy215;
138132
+ SrcList* yy259;
138133
+ Expr* yy314;
138134
+ ExprList* yy322;
138135
+ const char* yy336;
138136
+ IdList* yy384;
138137
+ Select* yy387;
138138
+ With* yy451;
137956138139
} YYMINORTYPE;
137957138140
#ifndef YYSTACKDEPTH
137958138141
#define YYSTACKDEPTH 100
137959138142
#endif
137960138143
#define sqlite3ParserARG_SDECL Parse *pParse;
137961138144
#define sqlite3ParserARG_PDECL ,Parse *pParse
137962138145
#define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
137963138146
#define sqlite3ParserARG_STORE yypParser->pParse = pParse
137964138147
#define YYFALLBACK 1
137965
-#define YYNSTATE 455
137966
-#define YYNRULE 329
137967
-#define YY_MAX_SHIFT 454
137968
-#define YY_MIN_SHIFTREDUCE 664
137969
-#define YY_MAX_SHIFTREDUCE 992
137970
-#define YY_MIN_REDUCE 993
137971
-#define YY_MAX_REDUCE 1321
137972
-#define YY_ERROR_ACTION 1322
137973
-#define YY_ACCEPT_ACTION 1323
137974
-#define YY_NO_ACTION 1324
138148
+#define YYNSTATE 466
138149
+#define YYNRULE 330
138150
+#define YYNTOKEN 143
138151
+#define YY_MAX_SHIFT 465
138152
+#define YY_MIN_SHIFTREDUCE 675
138153
+#define YY_MAX_SHIFTREDUCE 1004
138154
+#define YY_ERROR_ACTION 1005
138155
+#define YY_ACCEPT_ACTION 1006
138156
+#define YY_NO_ACTION 1007
138157
+#define YY_MIN_REDUCE 1008
138158
+#define YY_MAX_REDUCE 1337
137975138159
/************* End control #defines *******************************************/
137976138160
137977138161
/* Define the yytestcase() macro to be a no-op if is not already defined
137978138162
** otherwise.
137979138163
**
@@ -137999,39 +138183,33 @@
137999138183
** token onto the stack and goto state N.
138000138184
**
138001138185
** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
138002138186
** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
138003138187
**
138004
-** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
138005
-** and YY_MAX_REDUCE
138006
-**
138007138188
** N == YY_ERROR_ACTION A syntax error has occurred.
138008138189
**
138009138190
** N == YY_ACCEPT_ACTION The parser accepts its input.
138010138191
**
138011138192
** N == YY_NO_ACTION No such action. Denotes unused
138012138193
** slots in the yy_action[] table.
138194
+**
138195
+** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
138196
+** and YY_MAX_REDUCE
138013138197
**
138014138198
** The action table is constructed as a single large table named yy_action[].
138015138199
** Given state S and lookahead X, the action is computed as either:
138016138200
**
138017138201
** (A) N = yy_action[ yy_shift_ofst[S] + X ]
138018138202
** (B) N = yy_default[S]
138019138203
**
138020
-** The (A) formula is preferred. The B formula is used instead if:
138021
-** (1) The yy_shift_ofst[S]+X value is out of range, or
138022
-** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
138023
-** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
138024
-** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
138025
-** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
138026
-** Hence only tests (1) and (2) need to be evaluated.)
138204
+** The (A) formula is preferred. The B formula is used instead if
138205
+** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
138027138206
**
138028138207
** The formulas above are for computing the action when the lookahead is
138029138208
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
138030138209
** a reduce action) then the yy_reduce_ofst[] array is used in place of
138031
-** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
138032
-** YY_SHIFT_USE_DFLT.
138210
+** the yy_shift_ofst[] array.
138033138211
**
138034138212
** The following are the tables generated in this section:
138035138213
**
138036138214
** yy_action[] A single table containing all actions.
138037138215
** yy_lookahead[] A table containing the lookahead for each entry in
@@ -138041,467 +138219,478 @@
138041138219
** yy_reduce_ofst[] For each state, the offset into yy_action for
138042138220
** shifting non-terminals after a reduce.
138043138221
** yy_default[] Default action for each state.
138044138222
**
138045138223
*********** Begin parsing tables **********************************************/
138046
-#define YY_ACTTAB_COUNT (1566)
138224
+#define YY_ACTTAB_COUNT (1541)
138047138225
static const YYACTIONTYPE yy_action[] = {
138048
- /* 0 */ 324, 1323, 155, 155, 2, 203, 94, 94, 94, 93,
138049
- /* 10 */ 350, 98, 98, 98, 98, 91, 95, 95, 94, 94,
138050
- /* 20 */ 94, 93, 350, 268, 99, 100, 90, 971, 971, 847,
138051
- /* 30 */ 850, 839, 839, 97, 97, 98, 98, 98, 98, 350,
138052
- /* 40 */ 969, 96, 96, 96, 96, 95, 95, 94, 94, 94,
138053
- /* 50 */ 93, 350, 950, 96, 96, 96, 96, 95, 95, 94,
138054
- /* 60 */ 94, 94, 93, 350, 250, 96, 96, 96, 96, 95,
138055
- /* 70 */ 95, 94, 94, 94, 93, 350, 224, 224, 969, 132,
138056
- /* 80 */ 888, 348, 347, 415, 172, 324, 1286, 449, 414, 950,
138057
- /* 90 */ 951, 952, 808, 977, 1032, 950, 300, 786, 428, 132,
138058
- /* 100 */ 975, 362, 976, 9, 9, 787, 132, 52, 52, 99,
138059
- /* 110 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
138060
- /* 120 */ 98, 98, 98, 98, 372, 978, 241, 978, 262, 369,
138061
- /* 130 */ 261, 120, 950, 951, 952, 194, 58, 324, 401, 398,
138062
- /* 140 */ 397, 808, 427, 429, 75, 808, 1260, 1260, 132, 396,
138063
- /* 150 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
138064
- /* 160 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839,
138065
- /* 170 */ 97, 97, 98, 98, 98, 98, 786, 262, 369, 261,
138066
- /* 180 */ 826, 262, 364, 251, 787, 1084, 101, 1114, 72, 324,
138067
- /* 190 */ 227, 1113, 242, 411, 442, 819, 92, 89, 178, 818,
138068
- /* 200 */ 1022, 268, 96, 96, 96, 96, 95, 95, 94, 94,
138069
- /* 210 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850,
138070
- /* 220 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 372,
138071
- /* 230 */ 818, 818, 820, 92, 89, 178, 60, 92, 89, 178,
138072
- /* 240 */ 1025, 324, 357, 930, 1316, 300, 61, 1316, 52, 52,
138073
- /* 250 */ 836, 836, 848, 851, 96, 96, 96, 96, 95, 95,
138074
- /* 260 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971,
138075
- /* 270 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
138076
- /* 280 */ 92, 89, 178, 427, 412, 198, 930, 1317, 454, 995,
138077
- /* 290 */ 1317, 355, 1024, 324, 243, 231, 114, 277, 348, 347,
138078
- /* 300 */ 1242, 950, 416, 1071, 928, 840, 96, 96, 96, 96,
138079
- /* 310 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90,
138080
- /* 320 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
138081
- /* 330 */ 98, 98, 449, 328, 449, 120, 23, 256, 950, 951,
138082
- /* 340 */ 952, 968, 978, 438, 978, 324, 329, 928, 954, 701,
138083
- /* 350 */ 200, 175, 52, 52, 52, 52, 939, 353, 96, 96,
138084
- /* 360 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99,
138085
- /* 370 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
138086
- /* 380 */ 98, 98, 98, 98, 354, 449, 954, 427, 417, 427,
138087
- /* 390 */ 426, 1290, 92, 89, 178, 268, 253, 324, 255, 1058,
138088
- /* 400 */ 1037, 694, 93, 350, 383, 52, 52, 380, 1058, 374,
138089
- /* 410 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
138090
- /* 420 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839,
138091
- /* 430 */ 97, 97, 98, 98, 98, 98, 228, 449, 167, 449,
138092
- /* 440 */ 427, 407, 157, 446, 446, 446, 349, 349, 349, 324,
138093
- /* 450 */ 310, 316, 991, 827, 320, 242, 411, 51, 51, 36,
138094
- /* 460 */ 36, 254, 96, 96, 96, 96, 95, 95, 94, 94,
138095
- /* 470 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850,
138096
- /* 480 */ 839, 839, 97, 97, 98, 98, 98, 98, 194, 316,
138097
- /* 490 */ 929, 401, 398, 397, 224, 224, 1265, 939, 353, 1318,
138098
- /* 500 */ 317, 324, 396, 1063, 1063, 813, 414, 1061, 1061, 950,
138099
- /* 510 */ 299, 448, 992, 268, 96, 96, 96, 96, 95, 95,
138100
- /* 520 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971,
138101
- /* 530 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
138102
- /* 540 */ 757, 1041, 449, 893, 893, 386, 950, 951, 952, 410,
138103
- /* 550 */ 992, 747, 747, 324, 229, 268, 221, 296, 268, 771,
138104
- /* 560 */ 890, 378, 52, 52, 890, 421, 96, 96, 96, 96,
138105
- /* 570 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90,
138106
- /* 580 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
138107
- /* 590 */ 98, 98, 103, 449, 275, 384, 1241, 343, 157, 1207,
138108
- /* 600 */ 909, 669, 670, 671, 176, 197, 196, 195, 324, 298,
138109
- /* 610 */ 319, 1266, 2, 37, 37, 910, 1134, 1040, 96, 96,
138110
- /* 620 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 697,
138111
- /* 630 */ 911, 177, 99, 100, 90, 971, 971, 847, 850, 839,
138112
- /* 640 */ 839, 97, 97, 98, 98, 98, 98, 230, 146, 120,
138113
- /* 650 */ 735, 1235, 826, 270, 1141, 273, 1141, 771, 171, 170,
138114
- /* 660 */ 736, 1141, 82, 324, 80, 268, 697, 819, 158, 268,
138115
- /* 670 */ 378, 818, 78, 96, 96, 96, 96, 95, 95, 94,
138116
- /* 680 */ 94, 94, 93, 350, 120, 950, 393, 99, 100, 90,
138117
- /* 690 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
138118
- /* 700 */ 98, 98, 818, 818, 820, 1141, 1070, 370, 331, 133,
138119
- /* 710 */ 1066, 1141, 1250, 198, 268, 324, 1016, 330, 245, 333,
138120
- /* 720 */ 24, 334, 950, 951, 952, 368, 335, 81, 96, 96,
138121
- /* 730 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99,
138122
- /* 740 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
138123
- /* 750 */ 98, 98, 98, 98, 132, 267, 260, 445, 330, 223,
138124
- /* 760 */ 175, 1289, 925, 752, 724, 318, 1073, 324, 751, 246,
138125
- /* 770 */ 385, 301, 301, 378, 329, 361, 344, 414, 1233, 280,
138126
- /* 780 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
138127
- /* 790 */ 350, 99, 88, 90, 971, 971, 847, 850, 839, 839,
138128
- /* 800 */ 97, 97, 98, 98, 98, 98, 337, 346, 721, 722,
138129
- /* 810 */ 449, 120, 118, 887, 162, 887, 810, 371, 324, 202,
138130
- /* 820 */ 202, 373, 249, 263, 202, 394, 74, 704, 208, 1069,
138131
- /* 830 */ 12, 12, 96, 96, 96, 96, 95, 95, 94, 94,
138132
- /* 840 */ 94, 93, 350, 100, 90, 971, 971, 847, 850, 839,
138133
- /* 850 */ 839, 97, 97, 98, 98, 98, 98, 449, 771, 232,
138134
- /* 860 */ 449, 278, 120, 286, 74, 704, 714, 713, 324, 342,
138135
- /* 870 */ 749, 877, 1209, 77, 285, 1255, 780, 52, 52, 202,
138136
- /* 880 */ 27, 27, 418, 96, 96, 96, 96, 95, 95, 94,
138137
- /* 890 */ 94, 94, 93, 350, 90, 971, 971, 847, 850, 839,
138138
- /* 900 */ 839, 97, 97, 98, 98, 98, 98, 86, 444, 877,
138139
- /* 910 */ 3, 1193, 422, 1013, 873, 435, 886, 208, 886, 689,
138140
- /* 920 */ 1091, 257, 116, 822, 447, 1230, 117, 1229, 86, 444,
138141
- /* 930 */ 177, 3, 381, 96, 96, 96, 96, 95, 95, 94,
138142
- /* 940 */ 94, 94, 93, 350, 339, 447, 120, 351, 120, 212,
138143
- /* 950 */ 169, 287, 404, 282, 403, 199, 771, 950, 433, 419,
138144
- /* 960 */ 439, 822, 280, 691, 1039, 264, 269, 132, 351, 153,
138145
- /* 970 */ 826, 376, 74, 272, 274, 276, 83, 84, 1054, 433,
138146
- /* 980 */ 147, 1038, 443, 85, 351, 451, 450, 281, 132, 818,
138147
- /* 990 */ 25, 826, 449, 120, 950, 951, 952, 83, 84, 86,
138148
- /* 1000 */ 444, 691, 3, 408, 85, 351, 451, 450, 449, 5,
138149
- /* 1010 */ 818, 203, 32, 32, 1107, 120, 447, 950, 225, 1140,
138150
- /* 1020 */ 818, 818, 820, 821, 19, 203, 226, 950, 38, 38,
138151
- /* 1030 */ 1087, 314, 314, 313, 215, 311, 120, 449, 678, 351,
138152
- /* 1040 */ 237, 818, 818, 820, 821, 19, 969, 409, 377, 1,
138153
- /* 1050 */ 433, 180, 706, 248, 950, 951, 952, 10, 10, 449,
138154
- /* 1060 */ 969, 247, 826, 1098, 950, 951, 952, 430, 83, 84,
138155
- /* 1070 */ 756, 336, 950, 20, 431, 85, 351, 451, 450, 10,
138156
- /* 1080 */ 10, 818, 86, 444, 969, 3, 950, 449, 302, 303,
138157
- /* 1090 */ 182, 950, 1146, 338, 1021, 1015, 1004, 183, 969, 447,
138158
- /* 1100 */ 132, 181, 76, 444, 21, 3, 449, 10, 10, 950,
138159
- /* 1110 */ 951, 952, 818, 818, 820, 821, 19, 715, 1279, 447,
138160
- /* 1120 */ 389, 233, 351, 950, 951, 952, 10, 10, 950, 951,
138161
- /* 1130 */ 952, 1003, 218, 433, 1005, 325, 1273, 773, 289, 291,
138162
- /* 1140 */ 424, 293, 351, 7, 159, 826, 363, 402, 315, 360,
138163
- /* 1150 */ 1129, 83, 84, 433, 1232, 716, 772, 259, 85, 351,
138164
- /* 1160 */ 451, 450, 358, 375, 818, 826, 360, 359, 399, 1211,
138165
- /* 1170 */ 157, 83, 84, 681, 98, 98, 98, 98, 85, 351,
138166
- /* 1180 */ 451, 450, 323, 252, 818, 295, 1211, 1213, 1235, 173,
138167
- /* 1190 */ 1037, 284, 434, 340, 1204, 818, 818, 820, 821, 19,
138168
- /* 1200 */ 308, 234, 449, 234, 96, 96, 96, 96, 95, 95,
138169
- /* 1210 */ 94, 94, 94, 93, 350, 818, 818, 820, 821, 19,
138170
- /* 1220 */ 909, 120, 39, 39, 1203, 449, 168, 360, 449, 1276,
138171
- /* 1230 */ 367, 449, 135, 449, 986, 910, 449, 1249, 449, 1247,
138172
- /* 1240 */ 449, 205, 983, 449, 370, 40, 40, 1211, 41, 41,
138173
- /* 1250 */ 911, 42, 42, 28, 28, 870, 29, 29, 31, 31,
138174
- /* 1260 */ 43, 43, 379, 44, 44, 449, 59, 449, 332, 449,
138175
- /* 1270 */ 432, 62, 144, 156, 449, 130, 449, 72, 449, 137,
138176
- /* 1280 */ 449, 365, 449, 392, 139, 45, 45, 11, 11, 46,
138177
- /* 1290 */ 46, 140, 1200, 449, 105, 105, 47, 47, 48, 48,
138178
- /* 1300 */ 33, 33, 49, 49, 1126, 449, 141, 366, 449, 185,
138179
- /* 1310 */ 142, 449, 1234, 50, 50, 449, 160, 449, 148, 449,
138180
- /* 1320 */ 1136, 382, 449, 67, 449, 34, 34, 449, 122, 122,
138181
- /* 1330 */ 449, 123, 123, 449, 1198, 124, 124, 56, 56, 35,
138182
- /* 1340 */ 35, 449, 106, 106, 53, 53, 449, 107, 107, 449,
138183
- /* 1350 */ 108, 108, 449, 104, 104, 449, 406, 449, 388, 449,
138184
- /* 1360 */ 189, 121, 121, 449, 190, 449, 119, 119, 449, 112,
138185
- /* 1370 */ 112, 449, 111, 111, 1218, 109, 109, 110, 110, 55,
138186
- /* 1380 */ 55, 266, 752, 57, 57, 54, 54, 751, 26, 26,
138187
- /* 1390 */ 1099, 30, 30, 219, 154, 390, 271, 191, 321, 1006,
138188
- /* 1400 */ 192, 405, 1057, 1056, 1055, 341, 1048, 706, 1047, 1029,
138189
- /* 1410 */ 322, 420, 1028, 71, 1095, 283, 288, 1027, 1288, 204,
138190
- /* 1420 */ 6, 297, 79, 1184, 437, 1096, 1094, 290, 345, 292,
138191
- /* 1430 */ 441, 1093, 294, 102, 425, 73, 423, 213, 1012, 22,
138192
- /* 1440 */ 452, 945, 214, 1077, 216, 217, 238, 453, 306, 304,
138193
- /* 1450 */ 307, 239, 240, 1001, 305, 125, 996, 126, 115, 235,
138194
- /* 1460 */ 127, 665, 352, 166, 244, 179, 356, 113, 885, 883,
138195
- /* 1470 */ 806, 136, 128, 738, 326, 138, 327, 258, 184, 899,
138196
- /* 1480 */ 143, 129, 145, 63, 64, 65, 66, 902, 186, 187,
138197
- /* 1490 */ 898, 8, 13, 188, 134, 265, 891, 202, 980, 387,
138198
- /* 1500 */ 150, 149, 680, 161, 391, 193, 285, 279, 395, 151,
138199
- /* 1510 */ 68, 717, 14, 15, 400, 69, 16, 131, 236, 825,
138200
- /* 1520 */ 824, 853, 746, 750, 4, 70, 174, 413, 220, 222,
138201
- /* 1530 */ 152, 779, 774, 77, 868, 74, 854, 201, 17, 852,
138202
- /* 1540 */ 908, 206, 907, 207, 18, 857, 934, 163, 436, 210,
138203
- /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 312, 690, 87,
138204
- /* 1560 */ 211, 309, 1281, 940, 995, 1280,
138226
+ /* 0 */ 1006, 156, 156, 2, 1302, 90, 87, 179, 90, 87,
138227
+ /* 10 */ 179, 460, 1048, 460, 465, 1010, 460, 333, 1130, 335,
138228
+ /* 20 */ 246, 330, 112, 303, 439, 1258, 304, 419, 1129, 1087,
138229
+ /* 30 */ 72, 798, 50, 50, 50, 50, 331, 30, 30, 799,
138230
+ /* 40 */ 951, 364, 371, 97, 98, 88, 983, 983, 859, 862,
138231
+ /* 50 */ 851, 851, 95, 95, 96, 96, 96, 96, 120, 371,
138232
+ /* 60 */ 370, 120, 348, 22, 90, 87, 179, 438, 423, 438,
138233
+ /* 70 */ 440, 335, 420, 385, 90, 87, 179, 116, 73, 163,
138234
+ /* 80 */ 848, 848, 860, 863, 94, 94, 94, 94, 93, 93,
138235
+ /* 90 */ 92, 92, 92, 91, 361, 97, 98, 88, 983, 983,
138236
+ /* 100 */ 859, 862, 851, 851, 95, 95, 96, 96, 96, 96,
138237
+ /* 110 */ 718, 365, 339, 93, 93, 92, 92, 92, 91, 361,
138238
+ /* 120 */ 99, 371, 453, 335, 94, 94, 94, 94, 93, 93,
138239
+ /* 130 */ 92, 92, 92, 91, 361, 852, 94, 94, 94, 94,
138240
+ /* 140 */ 93, 93, 92, 92, 92, 91, 361, 97, 98, 88,
138241
+ /* 150 */ 983, 983, 859, 862, 851, 851, 95, 95, 96, 96,
138242
+ /* 160 */ 96, 96, 92, 92, 92, 91, 361, 838, 132, 195,
138243
+ /* 170 */ 58, 244, 412, 409, 408, 335, 457, 457, 457, 304,
138244
+ /* 180 */ 59, 332, 831, 407, 394, 962, 830, 391, 94, 94,
138245
+ /* 190 */ 94, 94, 93, 93, 92, 92, 92, 91, 361, 97,
138246
+ /* 200 */ 98, 88, 983, 983, 859, 862, 851, 851, 95, 95,
138247
+ /* 210 */ 96, 96, 96, 96, 426, 357, 460, 830, 830, 832,
138248
+ /* 220 */ 91, 361, 962, 963, 964, 195, 459, 335, 412, 409,
138249
+ /* 230 */ 408, 280, 361, 820, 132, 11, 11, 50, 50, 407,
138250
+ /* 240 */ 94, 94, 94, 94, 93, 93, 92, 92, 92, 91,
138251
+ /* 250 */ 361, 97, 98, 88, 983, 983, 859, 862, 851, 851,
138252
+ /* 260 */ 95, 95, 96, 96, 96, 96, 460, 221, 460, 264,
138253
+ /* 270 */ 375, 254, 438, 428, 1276, 1276, 383, 1074, 1053, 335,
138254
+ /* 280 */ 245, 422, 299, 713, 271, 271, 1074, 50, 50, 50,
138255
+ /* 290 */ 50, 962, 94, 94, 94, 94, 93, 93, 92, 92,
138256
+ /* 300 */ 92, 91, 361, 97, 98, 88, 983, 983, 859, 862,
138257
+ /* 310 */ 851, 851, 95, 95, 96, 96, 96, 96, 90, 87,
138258
+ /* 320 */ 179, 1306, 438, 437, 438, 418, 368, 253, 962, 963,
138259
+ /* 330 */ 964, 335, 360, 360, 360, 706, 359, 358, 324, 962,
138260
+ /* 340 */ 1281, 951, 364, 230, 94, 94, 94, 94, 93, 93,
138261
+ /* 350 */ 92, 92, 92, 91, 361, 97, 98, 88, 983, 983,
138262
+ /* 360 */ 859, 862, 851, 851, 95, 95, 96, 96, 96, 96,
138263
+ /* 370 */ 769, 460, 120, 226, 226, 366, 962, 963, 964, 1089,
138264
+ /* 380 */ 990, 900, 990, 335, 1057, 425, 421, 839, 759, 759,
138265
+ /* 390 */ 425, 427, 50, 50, 432, 381, 94, 94, 94, 94,
138266
+ /* 400 */ 93, 93, 92, 92, 92, 91, 361, 97, 98, 88,
138267
+ /* 410 */ 983, 983, 859, 862, 851, 851, 95, 95, 96, 96,
138268
+ /* 420 */ 96, 96, 460, 259, 460, 120, 117, 354, 942, 1332,
138269
+ /* 430 */ 942, 1333, 1332, 278, 1333, 335, 680, 681, 682, 825,
138270
+ /* 440 */ 201, 176, 303, 50, 50, 49, 49, 404, 94, 94,
138271
+ /* 450 */ 94, 94, 93, 93, 92, 92, 92, 91, 361, 97,
138272
+ /* 460 */ 98, 88, 983, 983, 859, 862, 851, 851, 95, 95,
138273
+ /* 470 */ 96, 96, 96, 96, 199, 460, 380, 265, 433, 380,
138274
+ /* 480 */ 265, 383, 256, 158, 258, 319, 1003, 335, 155, 940,
138275
+ /* 490 */ 177, 940, 273, 379, 276, 322, 34, 34, 302, 962,
138276
+ /* 500 */ 94, 94, 94, 94, 93, 93, 92, 92, 92, 91,
138277
+ /* 510 */ 361, 97, 98, 88, 983, 983, 859, 862, 851, 851,
138278
+ /* 520 */ 95, 95, 96, 96, 96, 96, 905, 905, 397, 460,
138279
+ /* 530 */ 301, 158, 101, 319, 941, 340, 962, 963, 964, 313,
138280
+ /* 540 */ 283, 449, 335, 327, 146, 1266, 1004, 257, 234, 248,
138281
+ /* 550 */ 35, 35, 94, 94, 94, 94, 93, 93, 92, 92,
138282
+ /* 560 */ 92, 91, 361, 709, 785, 1227, 97, 98, 88, 983,
138283
+ /* 570 */ 983, 859, 862, 851, 851, 95, 95, 96, 96, 96,
138284
+ /* 580 */ 96, 962, 1227, 1229, 245, 422, 838, 198, 197, 196,
138285
+ /* 590 */ 1079, 1079, 1077, 1077, 1004, 1334, 320, 335, 172, 171,
138286
+ /* 600 */ 709, 831, 159, 271, 271, 830, 76, 94, 94, 94,
138287
+ /* 610 */ 94, 93, 93, 92, 92, 92, 91, 361, 962, 963,
138288
+ /* 620 */ 964, 97, 98, 88, 983, 983, 859, 862, 851, 851,
138289
+ /* 630 */ 95, 95, 96, 96, 96, 96, 830, 830, 832, 1157,
138290
+ /* 640 */ 1157, 199, 1157, 173, 1227, 231, 232, 1282, 2, 335,
138291
+ /* 650 */ 271, 764, 271, 820, 271, 271, 763, 389, 389, 389,
138292
+ /* 660 */ 132, 79, 94, 94, 94, 94, 93, 93, 92, 92,
138293
+ /* 670 */ 92, 91, 361, 97, 98, 88, 983, 983, 859, 862,
138294
+ /* 680 */ 851, 851, 95, 95, 96, 96, 96, 96, 460, 264,
138295
+ /* 690 */ 223, 460, 1257, 783, 1223, 1157, 1086, 1082, 80, 271,
138296
+ /* 700 */ 78, 335, 340, 1031, 341, 344, 345, 902, 346, 10,
138297
+ /* 710 */ 10, 902, 25, 25, 94, 94, 94, 94, 93, 93,
138298
+ /* 720 */ 92, 92, 92, 91, 361, 97, 86, 88, 983, 983,
138299
+ /* 730 */ 859, 862, 851, 851, 95, 95, 96, 96, 96, 96,
138300
+ /* 740 */ 1157, 270, 395, 117, 233, 263, 235, 70, 456, 341,
138301
+ /* 750 */ 225, 176, 335, 1305, 342, 133, 736, 966, 980, 249,
138302
+ /* 760 */ 1150, 396, 325, 1085, 1028, 178, 94, 94, 94, 94,
138303
+ /* 770 */ 93, 93, 92, 92, 92, 91, 361, 98, 88, 983,
138304
+ /* 780 */ 983, 859, 862, 851, 851, 95, 95, 96, 96, 96,
138305
+ /* 790 */ 96, 783, 783, 132, 120, 966, 120, 120, 120, 798,
138306
+ /* 800 */ 252, 937, 335, 353, 321, 429, 355, 799, 822, 692,
138307
+ /* 810 */ 390, 203, 446, 450, 372, 716, 454, 94, 94, 94,
138308
+ /* 820 */ 94, 93, 93, 92, 92, 92, 91, 361, 88, 983,
138309
+ /* 830 */ 983, 859, 862, 851, 851, 95, 95, 96, 96, 96,
138310
+ /* 840 */ 96, 84, 455, 1225, 3, 1209, 120, 120, 382, 387,
138311
+ /* 850 */ 120, 203, 1271, 716, 384, 168, 266, 203, 458, 72,
138312
+ /* 860 */ 260, 1246, 84, 455, 178, 3, 378, 94, 94, 94,
138313
+ /* 870 */ 94, 93, 93, 92, 92, 92, 91, 361, 350, 458,
138314
+ /* 880 */ 1245, 362, 430, 213, 228, 290, 415, 285, 414, 200,
138315
+ /* 890 */ 783, 882, 444, 726, 725, 405, 283, 921, 209, 921,
138316
+ /* 900 */ 281, 132, 362, 72, 838, 289, 147, 733, 734, 392,
138317
+ /* 910 */ 81, 82, 922, 444, 922, 267, 288, 83, 362, 462,
138318
+ /* 920 */ 461, 272, 132, 830, 23, 838, 388, 923, 1216, 923,
138319
+ /* 930 */ 1056, 81, 82, 84, 455, 899, 3, 899, 83, 362,
138320
+ /* 940 */ 462, 461, 761, 962, 830, 75, 1, 443, 275, 747,
138321
+ /* 950 */ 458, 5, 962, 204, 830, 830, 832, 833, 18, 748,
138322
+ /* 960 */ 229, 962, 277, 19, 153, 317, 317, 316, 216, 314,
138323
+ /* 970 */ 279, 460, 689, 362, 1055, 830, 830, 832, 833, 18,
138324
+ /* 980 */ 962, 963, 964, 962, 444, 181, 460, 251, 981, 962,
138325
+ /* 990 */ 963, 964, 8, 8, 20, 250, 838, 1070, 962, 963,
138326
+ /* 1000 */ 964, 417, 81, 82, 768, 204, 347, 36, 36, 83,
138327
+ /* 1010 */ 362, 462, 461, 1054, 284, 830, 84, 455, 1123, 3,
138328
+ /* 1020 */ 962, 963, 964, 460, 183, 962, 981, 764, 889, 1107,
138329
+ /* 1030 */ 460, 184, 763, 458, 132, 182, 74, 455, 460, 3,
138330
+ /* 1040 */ 981, 898, 834, 898, 8, 8, 830, 830, 832, 833,
138331
+ /* 1050 */ 18, 8, 8, 458, 219, 1156, 362, 1103, 349, 8,
138332
+ /* 1060 */ 8, 240, 962, 963, 964, 236, 889, 444, 792, 336,
138333
+ /* 1070 */ 158, 203, 885, 435, 700, 209, 362, 114, 981, 838,
138334
+ /* 1080 */ 834, 227, 334, 1114, 441, 81, 82, 444, 442, 305,
138335
+ /* 1090 */ 784, 306, 83, 362, 462, 461, 369, 1162, 830, 838,
138336
+ /* 1100 */ 460, 1037, 237, 1030, 237, 81, 82, 7, 96, 96,
138337
+ /* 1110 */ 96, 96, 83, 362, 462, 461, 1019, 1018, 830, 1020,
138338
+ /* 1120 */ 1289, 37, 37, 400, 96, 96, 96, 96, 89, 830,
138339
+ /* 1130 */ 830, 832, 833, 18, 1100, 318, 962, 292, 94, 94,
138340
+ /* 1140 */ 94, 94, 93, 93, 92, 92, 92, 91, 361, 830,
138341
+ /* 1150 */ 830, 832, 833, 18, 94, 94, 94, 94, 93, 93,
138342
+ /* 1160 */ 92, 92, 92, 91, 361, 359, 358, 226, 226, 727,
138343
+ /* 1170 */ 294, 296, 460, 962, 963, 964, 460, 989, 160, 425,
138344
+ /* 1180 */ 170, 1295, 262, 460, 987, 374, 988, 386, 1145, 255,
138345
+ /* 1190 */ 326, 460, 373, 38, 38, 410, 174, 39, 39, 413,
138346
+ /* 1200 */ 460, 287, 460, 1053, 40, 40, 298, 728, 1220, 990,
138347
+ /* 1210 */ 445, 990, 26, 26, 1219, 460, 311, 460, 169, 1292,
138348
+ /* 1220 */ 460, 27, 27, 29, 29, 998, 460, 206, 135, 995,
138349
+ /* 1230 */ 1265, 1263, 460, 57, 60, 460, 41, 41, 42, 42,
138350
+ /* 1240 */ 460, 43, 43, 460, 343, 351, 460, 9, 9, 460,
138351
+ /* 1250 */ 144, 460, 130, 44, 44, 460, 103, 103, 460, 137,
138352
+ /* 1260 */ 70, 45, 45, 460, 46, 46, 460, 31, 31, 1142,
138353
+ /* 1270 */ 47, 47, 48, 48, 460, 376, 32, 32, 460, 122,
138354
+ /* 1280 */ 122, 460, 157, 460, 123, 123, 139, 124, 124, 460,
138355
+ /* 1290 */ 186, 460, 377, 460, 115, 54, 54, 460, 403, 33,
138356
+ /* 1300 */ 33, 460, 104, 104, 51, 51, 460, 161, 460, 140,
138357
+ /* 1310 */ 105, 105, 106, 106, 102, 102, 460, 141, 121, 121,
138358
+ /* 1320 */ 460, 142, 119, 119, 190, 460, 1152, 110, 110, 109,
138359
+ /* 1330 */ 109, 702, 460, 148, 393, 65, 460, 107, 107, 460,
138360
+ /* 1340 */ 323, 108, 108, 399, 460, 1234, 53, 53, 1214, 269,
138361
+ /* 1350 */ 154, 416, 1115, 55, 55, 220, 401, 52, 52, 191,
138362
+ /* 1360 */ 24, 24, 274, 192, 193, 28, 28, 1021, 328, 702,
138363
+ /* 1370 */ 1073, 352, 1072, 718, 1071, 431, 1111, 1064, 329, 1045,
138364
+ /* 1380 */ 69, 205, 6, 291, 1044, 286, 1112, 1043, 1304, 1110,
138365
+ /* 1390 */ 293, 300, 295, 297, 1063, 1200, 1109, 77, 241, 448,
138366
+ /* 1400 */ 356, 452, 436, 100, 214, 71, 434, 1027, 1093, 21,
138367
+ /* 1410 */ 463, 242, 243, 957, 215, 217, 218, 464, 309, 307,
138368
+ /* 1420 */ 308, 310, 1016, 125, 1250, 1251, 1011, 1249, 126, 127,
138369
+ /* 1430 */ 1248, 113, 676, 337, 238, 338, 134, 363, 167, 1041,
138370
+ /* 1440 */ 1040, 56, 247, 367, 180, 897, 111, 895, 136, 1038,
138371
+ /* 1450 */ 818, 128, 138, 750, 261, 911, 185, 143, 145, 61,
138372
+ /* 1460 */ 62, 63, 64, 129, 914, 187, 188, 910, 118, 12,
138373
+ /* 1470 */ 189, 903, 268, 992, 203, 162, 398, 150, 149, 691,
138374
+ /* 1480 */ 402, 288, 194, 406, 151, 411, 66, 13, 729, 239,
138375
+ /* 1490 */ 282, 14, 67, 131, 837, 836, 865, 758, 15, 4,
138376
+ /* 1500 */ 68, 762, 175, 222, 224, 424, 152, 869, 791, 202,
138377
+ /* 1510 */ 786, 75, 72, 880, 866, 864, 16, 17, 920, 207,
138378
+ /* 1520 */ 919, 208, 447, 946, 164, 211, 947, 210, 165, 451,
138379
+ /* 1530 */ 868, 166, 315, 835, 701, 85, 212, 1297, 312, 952,
138380
+ /* 1540 */ 1296,
138205138381
};
138206138382
static const YYCODETYPE yy_lookahead[] = {
138207
- /* 0 */ 19, 144, 145, 146, 147, 24, 90, 91, 92, 93,
138208
- /* 10 */ 94, 54, 55, 56, 57, 58, 88, 89, 90, 91,
138209
- /* 20 */ 92, 93, 94, 152, 43, 44, 45, 46, 47, 48,
138210
- /* 30 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 94,
138211
- /* 40 */ 59, 84, 85, 86, 87, 88, 89, 90, 91, 92,
138212
- /* 50 */ 93, 94, 59, 84, 85, 86, 87, 88, 89, 90,
138213
- /* 60 */ 91, 92, 93, 94, 193, 84, 85, 86, 87, 88,
138214
- /* 70 */ 89, 90, 91, 92, 93, 94, 194, 195, 97, 79,
138215
- /* 80 */ 11, 88, 89, 152, 26, 19, 171, 152, 206, 96,
138216
- /* 90 */ 97, 98, 72, 100, 179, 59, 152, 31, 163, 79,
138217
- /* 100 */ 107, 219, 109, 172, 173, 39, 79, 172, 173, 43,
138218
- /* 110 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138219
- /* 120 */ 54, 55, 56, 57, 152, 132, 199, 134, 108, 109,
138220
- /* 130 */ 110, 196, 96, 97, 98, 99, 209, 19, 102, 103,
138221
- /* 140 */ 104, 72, 207, 208, 26, 72, 119, 120, 79, 113,
138222
- /* 150 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138223
- /* 160 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138224
- /* 170 */ 52, 53, 54, 55, 56, 57, 31, 108, 109, 110,
138225
- /* 180 */ 82, 108, 109, 110, 39, 210, 68, 175, 130, 19,
138226
- /* 190 */ 218, 175, 119, 120, 250, 97, 221, 222, 223, 101,
138227
- /* 200 */ 172, 152, 84, 85, 86, 87, 88, 89, 90, 91,
138228
- /* 210 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
138229
- /* 220 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 152,
138230
- /* 230 */ 132, 133, 134, 221, 222, 223, 66, 221, 222, 223,
138231
- /* 240 */ 172, 19, 193, 22, 23, 152, 24, 26, 172, 173,
138232
- /* 250 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89,
138233
- /* 260 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138234
- /* 270 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138235
- /* 280 */ 221, 222, 223, 207, 208, 46, 22, 23, 148, 149,
138236
- /* 290 */ 26, 242, 172, 19, 154, 218, 156, 23, 88, 89,
138237
- /* 300 */ 241, 59, 163, 163, 83, 101, 84, 85, 86, 87,
138238
- /* 310 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
138239
- /* 320 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138240
- /* 330 */ 56, 57, 152, 157, 152, 196, 196, 16, 96, 97,
138241
- /* 340 */ 98, 26, 132, 250, 134, 19, 107, 83, 59, 23,
138242
- /* 350 */ 211, 212, 172, 173, 172, 173, 1, 2, 84, 85,
138243
- /* 360 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
138244
- /* 370 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138245
- /* 380 */ 54, 55, 56, 57, 244, 152, 97, 207, 208, 207,
138246
- /* 390 */ 208, 185, 221, 222, 223, 152, 75, 19, 77, 179,
138247
- /* 400 */ 180, 23, 93, 94, 228, 172, 173, 231, 188, 152,
138248
- /* 410 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138249
- /* 420 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138250
- /* 430 */ 52, 53, 54, 55, 56, 57, 193, 152, 123, 152,
138251
- /* 440 */ 207, 208, 152, 168, 169, 170, 168, 169, 170, 19,
138252
- /* 450 */ 160, 22, 23, 23, 164, 119, 120, 172, 173, 172,
138253
- /* 460 */ 173, 140, 84, 85, 86, 87, 88, 89, 90, 91,
138254
- /* 470 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
138255
- /* 480 */ 50, 51, 52, 53, 54, 55, 56, 57, 99, 22,
138256
- /* 490 */ 23, 102, 103, 104, 194, 195, 0, 1, 2, 247,
138257
- /* 500 */ 248, 19, 113, 190, 191, 23, 206, 190, 191, 59,
138258
- /* 510 */ 225, 152, 83, 152, 84, 85, 86, 87, 88, 89,
138259
- /* 520 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138260
- /* 530 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138261
- /* 540 */ 90, 181, 152, 108, 109, 110, 96, 97, 98, 115,
138262
- /* 550 */ 83, 117, 118, 19, 193, 152, 23, 152, 152, 26,
138263
- /* 560 */ 29, 152, 172, 173, 33, 152, 84, 85, 86, 87,
138264
- /* 570 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
138265
- /* 580 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138266
- /* 590 */ 56, 57, 22, 152, 16, 64, 193, 207, 152, 193,
138267
- /* 600 */ 12, 7, 8, 9, 152, 108, 109, 110, 19, 152,
138268
- /* 610 */ 164, 146, 147, 172, 173, 27, 163, 181, 84, 85,
138269
- /* 620 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 59,
138270
- /* 630 */ 42, 98, 43, 44, 45, 46, 47, 48, 49, 50,
138271
- /* 640 */ 51, 52, 53, 54, 55, 56, 57, 238, 22, 196,
138272
- /* 650 */ 62, 163, 82, 75, 152, 77, 152, 124, 88, 89,
138273
- /* 660 */ 72, 152, 137, 19, 139, 152, 96, 97, 24, 152,
138274
- /* 670 */ 152, 101, 138, 84, 85, 86, 87, 88, 89, 90,
138275
- /* 680 */ 91, 92, 93, 94, 196, 59, 19, 43, 44, 45,
138276
- /* 690 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138277
- /* 700 */ 56, 57, 132, 133, 134, 152, 193, 219, 245, 246,
138278
- /* 710 */ 193, 152, 152, 46, 152, 19, 166, 167, 152, 217,
138279
- /* 720 */ 232, 217, 96, 97, 98, 237, 217, 138, 84, 85,
138280
- /* 730 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
138281
- /* 740 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138282
- /* 750 */ 54, 55, 56, 57, 79, 193, 238, 166, 167, 211,
138283
- /* 760 */ 212, 23, 23, 116, 26, 26, 195, 19, 121, 152,
138284
- /* 770 */ 217, 152, 152, 152, 107, 100, 217, 206, 163, 112,
138285
- /* 780 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138286
- /* 790 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138287
- /* 800 */ 52, 53, 54, 55, 56, 57, 187, 187, 7, 8,
138288
- /* 810 */ 152, 196, 22, 132, 24, 134, 23, 23, 19, 26,
138289
- /* 820 */ 26, 23, 152, 23, 26, 23, 26, 59, 26, 163,
138290
- /* 830 */ 172, 173, 84, 85, 86, 87, 88, 89, 90, 91,
138291
- /* 840 */ 92, 93, 94, 44, 45, 46, 47, 48, 49, 50,
138292
- /* 850 */ 51, 52, 53, 54, 55, 56, 57, 152, 26, 238,
138293
- /* 860 */ 152, 23, 196, 101, 26, 97, 100, 101, 19, 19,
138294
- /* 870 */ 23, 59, 152, 26, 112, 152, 23, 172, 173, 26,
138295
- /* 880 */ 172, 173, 19, 84, 85, 86, 87, 88, 89, 90,
138296
- /* 890 */ 91, 92, 93, 94, 45, 46, 47, 48, 49, 50,
138297
- /* 900 */ 51, 52, 53, 54, 55, 56, 57, 19, 20, 97,
138298
- /* 910 */ 22, 23, 207, 163, 23, 163, 132, 26, 134, 23,
138299
- /* 920 */ 213, 152, 26, 59, 36, 152, 22, 152, 19, 20,
138300
- /* 930 */ 98, 22, 152, 84, 85, 86, 87, 88, 89, 90,
138301
- /* 940 */ 91, 92, 93, 94, 94, 36, 196, 59, 196, 99,
138302
- /* 950 */ 100, 101, 102, 103, 104, 105, 124, 59, 70, 96,
138303
- /* 960 */ 163, 97, 112, 59, 181, 152, 152, 79, 59, 71,
138304
- /* 970 */ 82, 19, 26, 152, 152, 152, 88, 89, 152, 70,
138305
- /* 980 */ 22, 152, 163, 95, 96, 97, 98, 152, 79, 101,
138306
- /* 990 */ 22, 82, 152, 196, 96, 97, 98, 88, 89, 19,
138307
- /* 1000 */ 20, 97, 22, 163, 95, 96, 97, 98, 152, 22,
138308
- /* 1010 */ 101, 24, 172, 173, 152, 196, 36, 59, 22, 152,
138309
- /* 1020 */ 132, 133, 134, 135, 136, 24, 5, 59, 172, 173,
138310
- /* 1030 */ 152, 10, 11, 12, 13, 14, 196, 152, 17, 59,
138311
- /* 1040 */ 210, 132, 133, 134, 135, 136, 59, 207, 96, 22,
138312
- /* 1050 */ 70, 30, 106, 32, 96, 97, 98, 172, 173, 152,
138313
- /* 1060 */ 59, 40, 82, 152, 96, 97, 98, 152, 88, 89,
138314
- /* 1070 */ 90, 186, 59, 22, 191, 95, 96, 97, 98, 172,
138315
- /* 1080 */ 173, 101, 19, 20, 97, 22, 59, 152, 152, 152,
138316
- /* 1090 */ 69, 59, 152, 186, 152, 152, 152, 76, 97, 36,
138317
- /* 1100 */ 79, 80, 19, 20, 53, 22, 152, 172, 173, 96,
138318
- /* 1110 */ 97, 98, 132, 133, 134, 135, 136, 35, 122, 36,
138319
- /* 1120 */ 234, 186, 59, 96, 97, 98, 172, 173, 96, 97,
138320
- /* 1130 */ 98, 152, 233, 70, 152, 114, 152, 124, 210, 210,
138321
- /* 1140 */ 186, 210, 59, 198, 197, 82, 214, 65, 150, 152,
138322
- /* 1150 */ 201, 88, 89, 70, 201, 73, 124, 239, 95, 96,
138323
- /* 1160 */ 97, 98, 141, 239, 101, 82, 169, 170, 176, 152,
138324
- /* 1170 */ 152, 88, 89, 21, 54, 55, 56, 57, 95, 96,
138325
- /* 1180 */ 97, 98, 164, 214, 101, 214, 169, 170, 163, 184,
138326
- /* 1190 */ 180, 175, 227, 111, 175, 132, 133, 134, 135, 136,
138327
- /* 1200 */ 200, 183, 152, 185, 84, 85, 86, 87, 88, 89,
138328
- /* 1210 */ 90, 91, 92, 93, 94, 132, 133, 134, 135, 136,
138329
- /* 1220 */ 12, 196, 172, 173, 175, 152, 198, 230, 152, 155,
138330
- /* 1230 */ 78, 152, 243, 152, 60, 27, 152, 159, 152, 159,
138331
- /* 1240 */ 152, 122, 38, 152, 219, 172, 173, 230, 172, 173,
138332
- /* 1250 */ 42, 172, 173, 172, 173, 103, 172, 173, 172, 173,
138333
- /* 1260 */ 172, 173, 237, 172, 173, 152, 240, 152, 159, 152,
138334
- /* 1270 */ 62, 240, 22, 220, 152, 43, 152, 130, 152, 189,
138335
- /* 1280 */ 152, 18, 152, 18, 192, 172, 173, 172, 173, 172,
138336
- /* 1290 */ 173, 192, 140, 152, 172, 173, 172, 173, 172, 173,
138337
- /* 1300 */ 172, 173, 172, 173, 201, 152, 192, 159, 152, 158,
138338
- /* 1310 */ 192, 152, 201, 172, 173, 152, 220, 152, 189, 152,
138339
- /* 1320 */ 189, 159, 152, 137, 152, 172, 173, 152, 172, 173,
138340
- /* 1330 */ 152, 172, 173, 152, 201, 172, 173, 172, 173, 172,
138341
- /* 1340 */ 173, 152, 172, 173, 172, 173, 152, 172, 173, 152,
138342
- /* 1350 */ 172, 173, 152, 172, 173, 152, 90, 152, 61, 152,
138343
- /* 1360 */ 158, 172, 173, 152, 158, 152, 172, 173, 152, 172,
138344
- /* 1370 */ 173, 152, 172, 173, 236, 172, 173, 172, 173, 172,
138345
- /* 1380 */ 173, 235, 116, 172, 173, 172, 173, 121, 172, 173,
138346
- /* 1390 */ 159, 172, 173, 159, 22, 177, 159, 158, 177, 159,
138347
- /* 1400 */ 158, 107, 174, 174, 174, 63, 182, 106, 182, 174,
138348
- /* 1410 */ 177, 125, 176, 107, 216, 174, 215, 174, 174, 159,
138349
- /* 1420 */ 22, 159, 137, 224, 177, 216, 216, 215, 94, 215,
138350
- /* 1430 */ 177, 216, 215, 129, 126, 128, 127, 25, 162, 26,
138351
- /* 1440 */ 161, 13, 153, 205, 153, 6, 226, 151, 202, 204,
138352
- /* 1450 */ 201, 229, 229, 151, 203, 165, 151, 165, 178, 178,
138353
- /* 1460 */ 165, 4, 3, 22, 142, 15, 81, 16, 23, 23,
138354
- /* 1470 */ 120, 131, 111, 20, 249, 123, 249, 16, 125, 1,
138355
- /* 1480 */ 123, 111, 131, 53, 53, 53, 53, 96, 34, 122,
138356
- /* 1490 */ 1, 5, 22, 107, 246, 140, 67, 26, 74, 41,
138357
- /* 1500 */ 107, 67, 20, 24, 19, 105, 112, 23, 66, 22,
138358
- /* 1510 */ 22, 28, 22, 22, 66, 22, 22, 37, 66, 23,
138359
- /* 1520 */ 23, 23, 116, 23, 22, 26, 122, 26, 23, 23,
138360
- /* 1530 */ 22, 96, 124, 26, 23, 26, 23, 34, 34, 23,
138361
- /* 1540 */ 23, 26, 23, 22, 34, 11, 23, 22, 24, 122,
138362
- /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 15, 23, 22,
138363
- /* 1560 */ 122, 23, 122, 1, 251, 122,
138364
-};
138365
-#define YY_SHIFT_USE_DFLT (1566)
138366
-#define YY_SHIFT_COUNT (454)
138367
-#define YY_SHIFT_MIN (-84)
138368
-#define YY_SHIFT_MAX (1562)
138369
-static const short yy_shift_ofst[] = {
138370
- /* 0 */ 355, 888, 1021, 909, 1063, 1063, 1063, 1063, 20, -19,
138371
- /* 10 */ 66, 66, 170, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138372
- /* 20 */ -7, -7, 36, 73, 69, 27, 118, 222, 274, 326,
138373
- /* 30 */ 378, 430, 482, 534, 589, 644, 696, 696, 696, 696,
138374
- /* 40 */ 696, 696, 696, 696, 696, 696, 696, 696, 696, 696,
138375
- /* 50 */ 696, 696, 696, 748, 696, 799, 849, 849, 980, 1063,
138376
- /* 60 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138377
- /* 70 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138378
- /* 80 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138379
- /* 90 */ 1083, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138380
- /* 100 */ 1063, 1063, 1063, 1063, -43, 1120, 1120, 1120, 1120, 1120,
138381
- /* 110 */ -31, -72, -84, 242, 1152, 667, 210, 210, 242, 309,
138382
- /* 120 */ 336, -55, 1566, 1566, 1566, 850, 850, 850, 626, 626,
138383
- /* 130 */ 588, 588, 898, 221, 264, 242, 242, 242, 242, 242,
138384
- /* 140 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
138385
- /* 150 */ 242, 242, 242, 242, 242, 496, 675, 289, 289, 336,
138386
- /* 160 */ 0, 0, 0, 0, 0, 0, 1566, 1566, 1566, 570,
138387
- /* 170 */ 98, 98, 958, 389, 450, 968, 1013, 1032, 1027, 242,
138388
- /* 180 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
138389
- /* 190 */ 242, 242, 242, 242, 242, 1082, 1082, 1082, 242, 242,
138390
- /* 200 */ 533, 242, 242, 242, 987, 242, 242, 1208, 242, 242,
138391
- /* 210 */ 242, 242, 242, 242, 242, 242, 242, 242, 435, 531,
138392
- /* 220 */ 1001, 1001, 1001, 832, 434, 1266, 594, 58, 863, 863,
138393
- /* 230 */ 952, 58, 952, 946, 738, 239, 145, 863, 525, 145,
138394
- /* 240 */ 145, 315, 647, 790, 1174, 1119, 1119, 1204, 1204, 1119,
138395
- /* 250 */ 1250, 1232, 1147, 1263, 1263, 1263, 1263, 1119, 1265, 1147,
138396
- /* 260 */ 1250, 1232, 1232, 1147, 1119, 1265, 1186, 1297, 1119, 1119,
138397
- /* 270 */ 1265, 1372, 1119, 1265, 1119, 1265, 1372, 1294, 1294, 1294,
138398
- /* 280 */ 1342, 1372, 1294, 1301, 1294, 1342, 1294, 1294, 1286, 1306,
138399
- /* 290 */ 1286, 1306, 1286, 1306, 1286, 1306, 1119, 1398, 1119, 1285,
138400
- /* 300 */ 1372, 1334, 1334, 1372, 1304, 1308, 1307, 1309, 1147, 1412,
138401
- /* 310 */ 1413, 1428, 1428, 1439, 1439, 1439, 1566, 1566, 1566, 1566,
138402
- /* 320 */ 1566, 1566, 1566, 1566, 204, 321, 429, 467, 578, 497,
138403
- /* 330 */ 904, 739, 1051, 793, 794, 798, 800, 802, 838, 768,
138404
- /* 340 */ 766, 801, 762, 847, 853, 812, 891, 681, 784, 896,
138405
- /* 350 */ 864, 996, 1457, 1459, 1441, 1322, 1450, 1385, 1451, 1445,
138406
- /* 360 */ 1446, 1350, 1340, 1361, 1352, 1453, 1353, 1461, 1478, 1357,
138407
- /* 370 */ 1351, 1430, 1431, 1432, 1433, 1370, 1391, 1454, 1367, 1489,
138408
- /* 380 */ 1486, 1470, 1386, 1355, 1429, 1471, 1434, 1424, 1458, 1393,
138409
- /* 390 */ 1479, 1482, 1485, 1394, 1400, 1487, 1442, 1488, 1490, 1484,
138410
- /* 400 */ 1491, 1448, 1483, 1493, 1452, 1480, 1496, 1497, 1498, 1499,
138411
- /* 410 */ 1406, 1494, 1500, 1502, 1501, 1404, 1505, 1506, 1435, 1503,
138412
- /* 420 */ 1508, 1408, 1507, 1504, 1509, 1510, 1511, 1507, 1513, 1516,
138413
- /* 430 */ 1517, 1515, 1519, 1521, 1534, 1523, 1525, 1524, 1526, 1527,
138414
- /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1535, 1537, 1427, 1438,
138415
- /* 450 */ 1440, 1443, 1538, 1542, 1562,
138416
-};
138417
-#define YY_REDUCE_USE_DFLT (-144)
138418
-#define YY_REDUCE_COUNT (323)
138419
-#define YY_REDUCE_MIN (-143)
138420
-#define YY_REDUCE_MAX (1305)
138383
+ /* 0 */ 144, 145, 146, 147, 172, 222, 223, 224, 222, 223,
138384
+ /* 10 */ 224, 152, 180, 152, 148, 149, 152, 173, 176, 19,
138385
+ /* 20 */ 154, 173, 156, 152, 163, 242, 152, 163, 176, 163,
138386
+ /* 30 */ 26, 31, 173, 174, 173, 174, 173, 173, 174, 39,
138387
+ /* 40 */ 1, 2, 152, 43, 44, 45, 46, 47, 48, 49,
138388
+ /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 197, 169,
138389
+ /* 60 */ 170, 197, 188, 197, 222, 223, 224, 208, 209, 208,
138390
+ /* 70 */ 209, 19, 208, 152, 222, 223, 224, 22, 26, 24,
138391
+ /* 80 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89,
138392
+ /* 90 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138393
+ /* 100 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138394
+ /* 110 */ 106, 245, 157, 88, 89, 90, 91, 92, 93, 94,
138395
+ /* 120 */ 68, 231, 251, 19, 84, 85, 86, 87, 88, 89,
138396
+ /* 130 */ 90, 91, 92, 93, 94, 101, 84, 85, 86, 87,
138397
+ /* 140 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
138398
+ /* 150 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138399
+ /* 160 */ 56, 57, 90, 91, 92, 93, 94, 82, 79, 99,
138400
+ /* 170 */ 66, 200, 102, 103, 104, 19, 168, 169, 170, 152,
138401
+ /* 180 */ 24, 210, 97, 113, 229, 59, 101, 232, 84, 85,
138402
+ /* 190 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
138403
+ /* 200 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138404
+ /* 210 */ 54, 55, 56, 57, 152, 188, 152, 132, 133, 134,
138405
+ /* 220 */ 93, 94, 96, 97, 98, 99, 152, 19, 102, 103,
138406
+ /* 230 */ 104, 23, 94, 72, 79, 173, 174, 173, 174, 113,
138407
+ /* 240 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138408
+ /* 250 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138409
+ /* 260 */ 52, 53, 54, 55, 56, 57, 152, 171, 152, 108,
138410
+ /* 270 */ 109, 110, 208, 209, 119, 120, 152, 180, 181, 19,
138411
+ /* 280 */ 119, 120, 152, 23, 152, 152, 189, 173, 174, 173,
138412
+ /* 290 */ 174, 59, 84, 85, 86, 87, 88, 89, 90, 91,
138413
+ /* 300 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
138414
+ /* 310 */ 50, 51, 52, 53, 54, 55, 56, 57, 222, 223,
138415
+ /* 320 */ 224, 186, 208, 209, 208, 209, 194, 194, 96, 97,
138416
+ /* 330 */ 98, 19, 168, 169, 170, 23, 88, 89, 163, 59,
138417
+ /* 340 */ 0, 1, 2, 219, 84, 85, 86, 87, 88, 89,
138418
+ /* 350 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138419
+ /* 360 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138420
+ /* 370 */ 90, 152, 197, 195, 196, 243, 96, 97, 98, 196,
138421
+ /* 380 */ 132, 11, 134, 19, 182, 207, 115, 23, 117, 118,
138422
+ /* 390 */ 207, 163, 173, 174, 152, 220, 84, 85, 86, 87,
138423
+ /* 400 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
138424
+ /* 410 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138425
+ /* 420 */ 56, 57, 152, 16, 152, 197, 171, 208, 22, 23,
138426
+ /* 430 */ 22, 23, 26, 16, 26, 19, 7, 8, 9, 23,
138427
+ /* 440 */ 212, 213, 152, 173, 174, 173, 174, 19, 84, 85,
138428
+ /* 450 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
138429
+ /* 460 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138430
+ /* 470 */ 54, 55, 56, 57, 46, 152, 109, 110, 208, 109,
138431
+ /* 480 */ 110, 152, 75, 152, 77, 22, 23, 19, 233, 83,
138432
+ /* 490 */ 152, 83, 75, 238, 77, 164, 173, 174, 226, 59,
138433
+ /* 500 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138434
+ /* 510 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138435
+ /* 520 */ 52, 53, 54, 55, 56, 57, 108, 109, 110, 152,
138436
+ /* 530 */ 152, 152, 22, 22, 23, 107, 96, 97, 98, 160,
138437
+ /* 540 */ 112, 251, 19, 164, 22, 152, 83, 140, 219, 152,
138438
+ /* 550 */ 173, 174, 84, 85, 86, 87, 88, 89, 90, 91,
138439
+ /* 560 */ 92, 93, 94, 59, 124, 152, 43, 44, 45, 46,
138440
+ /* 570 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
138441
+ /* 580 */ 57, 59, 169, 170, 119, 120, 82, 108, 109, 110,
138442
+ /* 590 */ 191, 192, 191, 192, 83, 248, 249, 19, 88, 89,
138443
+ /* 600 */ 96, 97, 24, 152, 152, 101, 138, 84, 85, 86,
138444
+ /* 610 */ 87, 88, 89, 90, 91, 92, 93, 94, 96, 97,
138445
+ /* 620 */ 98, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138446
+ /* 630 */ 52, 53, 54, 55, 56, 57, 132, 133, 134, 152,
138447
+ /* 640 */ 152, 46, 152, 26, 231, 194, 194, 146, 147, 19,
138448
+ /* 650 */ 152, 116, 152, 72, 152, 152, 121, 152, 152, 152,
138449
+ /* 660 */ 79, 138, 84, 85, 86, 87, 88, 89, 90, 91,
138450
+ /* 670 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
138451
+ /* 680 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 108,
138452
+ /* 690 */ 23, 152, 194, 26, 194, 152, 194, 194, 137, 152,
138453
+ /* 700 */ 139, 19, 107, 166, 167, 218, 218, 29, 218, 173,
138454
+ /* 710 */ 174, 33, 173, 174, 84, 85, 86, 87, 88, 89,
138455
+ /* 720 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138456
+ /* 730 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138457
+ /* 740 */ 152, 194, 64, 171, 239, 239, 239, 130, 166, 167,
138458
+ /* 750 */ 212, 213, 19, 23, 246, 247, 26, 59, 26, 152,
138459
+ /* 760 */ 163, 218, 163, 163, 163, 98, 84, 85, 86, 87,
138460
+ /* 770 */ 88, 89, 90, 91, 92, 93, 94, 44, 45, 46,
138461
+ /* 780 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
138462
+ /* 790 */ 57, 124, 26, 79, 197, 97, 197, 197, 197, 31,
138463
+ /* 800 */ 152, 23, 19, 19, 26, 19, 218, 39, 23, 21,
138464
+ /* 810 */ 238, 26, 163, 163, 100, 59, 163, 84, 85, 86,
138465
+ /* 820 */ 87, 88, 89, 90, 91, 92, 93, 94, 45, 46,
138466
+ /* 830 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
138467
+ /* 840 */ 57, 19, 20, 152, 22, 23, 197, 197, 23, 19,
138468
+ /* 850 */ 197, 26, 152, 97, 23, 123, 23, 26, 36, 26,
138469
+ /* 860 */ 152, 152, 19, 20, 98, 22, 78, 84, 85, 86,
138470
+ /* 870 */ 87, 88, 89, 90, 91, 92, 93, 94, 94, 36,
138471
+ /* 880 */ 152, 59, 96, 99, 100, 101, 102, 103, 104, 105,
138472
+ /* 890 */ 124, 103, 70, 100, 101, 23, 112, 12, 26, 12,
138473
+ /* 900 */ 23, 79, 59, 26, 82, 101, 22, 7, 8, 152,
138474
+ /* 910 */ 88, 89, 27, 70, 27, 152, 112, 95, 96, 97,
138475
+ /* 920 */ 98, 152, 79, 101, 22, 82, 96, 42, 140, 42,
138476
+ /* 930 */ 182, 88, 89, 19, 20, 132, 22, 134, 95, 96,
138477
+ /* 940 */ 97, 98, 23, 59, 101, 26, 22, 62, 152, 62,
138478
+ /* 950 */ 36, 22, 59, 24, 132, 133, 134, 135, 136, 72,
138479
+ /* 960 */ 5, 59, 152, 22, 71, 10, 11, 12, 13, 14,
138480
+ /* 970 */ 152, 152, 17, 59, 182, 132, 133, 134, 135, 136,
138481
+ /* 980 */ 96, 97, 98, 59, 70, 30, 152, 32, 59, 96,
138482
+ /* 990 */ 97, 98, 173, 174, 53, 40, 82, 152, 96, 97,
138483
+ /* 1000 */ 98, 90, 88, 89, 90, 24, 187, 173, 174, 95,
138484
+ /* 1010 */ 96, 97, 98, 152, 152, 101, 19, 20, 152, 22,
138485
+ /* 1020 */ 96, 97, 98, 152, 69, 59, 97, 116, 59, 214,
138486
+ /* 1030 */ 152, 76, 121, 36, 79, 80, 19, 20, 152, 22,
138487
+ /* 1040 */ 59, 132, 59, 134, 173, 174, 132, 133, 134, 135,
138488
+ /* 1050 */ 136, 173, 174, 36, 234, 152, 59, 152, 187, 173,
138489
+ /* 1060 */ 174, 211, 96, 97, 98, 187, 97, 70, 23, 114,
138490
+ /* 1070 */ 152, 26, 23, 187, 23, 26, 59, 26, 97, 82,
138491
+ /* 1080 */ 97, 22, 164, 152, 152, 88, 89, 70, 192, 152,
138492
+ /* 1090 */ 124, 152, 95, 96, 97, 98, 141, 152, 101, 82,
138493
+ /* 1100 */ 152, 152, 184, 152, 186, 88, 89, 199, 54, 55,
138494
+ /* 1110 */ 56, 57, 95, 96, 97, 98, 152, 152, 101, 152,
138495
+ /* 1120 */ 152, 173, 174, 235, 54, 55, 56, 57, 58, 132,
138496
+ /* 1130 */ 133, 134, 135, 136, 211, 150, 59, 211, 84, 85,
138497
+ /* 1140 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 132,
138498
+ /* 1150 */ 133, 134, 135, 136, 84, 85, 86, 87, 88, 89,
138499
+ /* 1160 */ 90, 91, 92, 93, 94, 88, 89, 195, 196, 35,
138500
+ /* 1170 */ 211, 211, 152, 96, 97, 98, 152, 100, 198, 207,
138501
+ /* 1180 */ 171, 122, 240, 152, 107, 215, 109, 240, 202, 215,
138502
+ /* 1190 */ 202, 152, 220, 173, 174, 177, 185, 173, 174, 65,
138503
+ /* 1200 */ 152, 176, 152, 181, 173, 174, 215, 73, 176, 132,
138504
+ /* 1210 */ 228, 134, 173, 174, 176, 152, 201, 152, 199, 155,
138505
+ /* 1220 */ 152, 173, 174, 173, 174, 60, 152, 122, 244, 38,
138506
+ /* 1230 */ 159, 159, 152, 241, 241, 152, 173, 174, 173, 174,
138507
+ /* 1240 */ 152, 173, 174, 152, 159, 111, 152, 173, 174, 152,
138508
+ /* 1250 */ 22, 152, 43, 173, 174, 152, 173, 174, 152, 190,
138509
+ /* 1260 */ 130, 173, 174, 152, 173, 174, 152, 173, 174, 202,
138510
+ /* 1270 */ 173, 174, 173, 174, 152, 18, 173, 174, 152, 173,
138511
+ /* 1280 */ 174, 152, 221, 152, 173, 174, 193, 173, 174, 152,
138512
+ /* 1290 */ 158, 152, 159, 152, 22, 173, 174, 152, 18, 173,
138513
+ /* 1300 */ 174, 152, 173, 174, 173, 174, 152, 221, 152, 193,
138514
+ /* 1310 */ 173, 174, 173, 174, 173, 174, 152, 193, 173, 174,
138515
+ /* 1320 */ 152, 193, 173, 174, 158, 152, 190, 173, 174, 173,
138516
+ /* 1330 */ 174, 59, 152, 190, 159, 137, 152, 173, 174, 152,
138517
+ /* 1340 */ 202, 173, 174, 61, 152, 237, 173, 174, 202, 236,
138518
+ /* 1350 */ 22, 107, 159, 173, 174, 159, 178, 173, 174, 158,
138519
+ /* 1360 */ 173, 174, 159, 158, 158, 173, 174, 159, 178, 97,
138520
+ /* 1370 */ 175, 63, 175, 106, 175, 125, 217, 183, 178, 175,
138521
+ /* 1380 */ 107, 159, 22, 216, 177, 175, 217, 175, 175, 217,
138522
+ /* 1390 */ 216, 159, 216, 216, 183, 225, 217, 137, 227, 178,
138523
+ /* 1400 */ 94, 178, 126, 129, 25, 128, 127, 162, 206, 26,
138524
+ /* 1410 */ 161, 230, 230, 13, 153, 153, 6, 151, 203, 205,
138525
+ /* 1420 */ 204, 202, 151, 165, 171, 171, 151, 171, 165, 165,
138526
+ /* 1430 */ 171, 179, 4, 250, 179, 250, 247, 3, 22, 171,
138527
+ /* 1440 */ 171, 171, 142, 81, 15, 23, 16, 23, 131, 171,
138528
+ /* 1450 */ 120, 111, 123, 20, 16, 1, 125, 123, 131, 53,
138529
+ /* 1460 */ 53, 53, 53, 111, 96, 34, 122, 1, 5, 22,
138530
+ /* 1470 */ 107, 67, 140, 74, 26, 24, 41, 107, 67, 20,
138531
+ /* 1480 */ 19, 112, 105, 66, 22, 66, 22, 22, 28, 66,
138532
+ /* 1490 */ 23, 22, 22, 37, 23, 23, 23, 116, 22, 22,
138533
+ /* 1500 */ 26, 23, 122, 23, 23, 26, 22, 11, 96, 34,
138534
+ /* 1510 */ 124, 26, 26, 23, 23, 23, 34, 34, 23, 26,
138535
+ /* 1520 */ 23, 22, 24, 23, 22, 122, 23, 26, 22, 24,
138536
+ /* 1530 */ 23, 22, 15, 23, 23, 22, 122, 122, 23, 1,
138537
+ /* 1540 */ 122, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138538
+ /* 1550 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138539
+ /* 1560 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138540
+ /* 1570 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138541
+ /* 1580 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138542
+ /* 1590 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138543
+ /* 1600 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138544
+ /* 1610 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138545
+ /* 1620 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138546
+ /* 1630 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138547
+ /* 1640 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138548
+ /* 1650 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138549
+ /* 1660 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138550
+ /* 1670 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138551
+ /* 1680 */ 252, 252, 252, 252,
138552
+};
138553
+#define YY_SHIFT_COUNT (465)
138554
+#define YY_SHIFT_MIN (0)
138555
+#define YY_SHIFT_MAX (1538)
138556
+static const unsigned short int yy_shift_ofst[] = {
138557
+ /* 0 */ 39, 822, 955, 843, 997, 997, 997, 997, 0, 0,
138558
+ /* 10 */ 104, 630, 997, 997, 997, 997, 997, 997, 997, 1077,
138559
+ /* 20 */ 1077, 126, 161, 155, 52, 156, 208, 260, 312, 364,
138560
+ /* 30 */ 416, 468, 523, 578, 630, 630, 630, 630, 630, 630,
138561
+ /* 40 */ 630, 630, 630, 630, 630, 630, 630, 630, 630, 630,
138562
+ /* 50 */ 630, 682, 630, 733, 783, 783, 914, 997, 997, 997,
138563
+ /* 60 */ 997, 997, 997, 997, 997, 997, 997, 997, 997, 997,
138564
+ /* 70 */ 997, 997, 997, 997, 997, 997, 997, 997, 997, 997,
138565
+ /* 80 */ 997, 997, 997, 997, 997, 997, 997, 997, 1017, 997,
138566
+ /* 90 */ 997, 997, 997, 997, 997, 997, 997, 997, 997, 997,
138567
+ /* 100 */ 997, 997, 1070, 1054, 1054, 1054, 1054, 1054, 40, 25,
138568
+ /* 110 */ 72, 232, 788, 428, 248, 248, 232, 581, 367, 127,
138569
+ /* 120 */ 465, 138, 1541, 1541, 1541, 784, 784, 784, 522, 522,
138570
+ /* 130 */ 887, 887, 893, 406, 408, 232, 232, 232, 232, 232,
138571
+ /* 140 */ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
138572
+ /* 150 */ 232, 232, 232, 232, 232, 370, 340, 714, 698, 698,
138573
+ /* 160 */ 465, 89, 89, 89, 89, 89, 89, 1541, 1541, 1541,
138574
+ /* 170 */ 504, 85, 85, 884, 70, 280, 902, 440, 966, 924,
138575
+ /* 180 */ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
138576
+ /* 190 */ 232, 232, 232, 232, 232, 232, 1134, 1134, 1134, 232,
138577
+ /* 200 */ 232, 667, 232, 232, 232, 929, 232, 232, 885, 232,
138578
+ /* 210 */ 232, 232, 232, 232, 232, 232, 232, 232, 232, 418,
138579
+ /* 220 */ 678, 981, 981, 981, 981, 766, 271, 911, 510, 429,
138580
+ /* 230 */ 617, 786, 786, 830, 617, 830, 4, 730, 595, 768,
138581
+ /* 240 */ 786, 561, 768, 768, 732, 535, 55, 1165, 1105, 1105,
138582
+ /* 250 */ 1191, 1191, 1105, 1228, 1209, 1130, 1257, 1257, 1257, 1257,
138583
+ /* 260 */ 1105, 1280, 1130, 1228, 1209, 1209, 1130, 1105, 1280, 1198,
138584
+ /* 270 */ 1282, 1105, 1105, 1280, 1328, 1105, 1280, 1105, 1280, 1328,
138585
+ /* 280 */ 1244, 1244, 1244, 1308, 1328, 1244, 1267, 1244, 1308, 1244,
138586
+ /* 290 */ 1244, 1250, 1273, 1250, 1273, 1250, 1273, 1250, 1273, 1105,
138587
+ /* 300 */ 1360, 1105, 1260, 1328, 1306, 1306, 1328, 1274, 1276, 1277,
138588
+ /* 310 */ 1279, 1130, 1379, 1383, 1400, 1400, 1410, 1410, 1410, 1541,
138589
+ /* 320 */ 1541, 1541, 1541, 1541, 1541, 1541, 1541, 1541, 1541, 1541,
138590
+ /* 330 */ 1541, 1541, 1541, 1541, 1541, 34, 407, 463, 511, 417,
138591
+ /* 340 */ 479, 1272, 778, 941, 785, 825, 831, 833, 872, 877,
138592
+ /* 350 */ 756, 793, 900, 804, 919, 1045, 969, 1049, 803, 909,
138593
+ /* 360 */ 1051, 983, 1059, 1428, 1434, 1416, 1300, 1429, 1362, 1430,
138594
+ /* 370 */ 1422, 1424, 1330, 1317, 1340, 1329, 1433, 1331, 1438, 1454,
138595
+ /* 380 */ 1334, 1327, 1406, 1407, 1408, 1409, 1352, 1368, 1431, 1344,
138596
+ /* 390 */ 1466, 1463, 1447, 1363, 1332, 1404, 1448, 1411, 1399, 1435,
138597
+ /* 400 */ 1370, 1451, 1459, 1461, 1369, 1377, 1462, 1417, 1464, 1465,
138598
+ /* 410 */ 1467, 1469, 1419, 1460, 1470, 1423, 1456, 1471, 1472, 1473,
138599
+ /* 420 */ 1474, 1381, 1476, 1478, 1477, 1479, 1380, 1480, 1481, 1412,
138600
+ /* 430 */ 1475, 1484, 1386, 1485, 1482, 1486, 1483, 1490, 1485, 1491,
138601
+ /* 440 */ 1492, 1495, 1493, 1497, 1499, 1496, 1500, 1502, 1498, 1501,
138602
+ /* 450 */ 1503, 1506, 1505, 1501, 1507, 1509, 1510, 1511, 1513, 1403,
138603
+ /* 460 */ 1414, 1415, 1418, 1515, 1517, 1538,
138604
+};
138605
+#define YY_REDUCE_COUNT (334)
138606
+#define YY_REDUCE_MIN (-217)
138607
+#define YY_REDUCE_MAX (1278)
138421138608
static const short yy_reduce_ofst[] = {
138422
- /* 0 */ -143, -65, 140, 840, 76, 180, 182, 233, 488, -25,
138423
- /* 10 */ 12, 16, 59, 885, 907, 935, 390, 705, 954, 285,
138424
- /* 20 */ 997, 1017, 1018, -118, 1025, 139, 171, 171, 171, 171,
138425
- /* 30 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171,
138426
- /* 40 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171,
138427
- /* 50 */ 171, 171, 171, 171, 171, 171, 171, 171, -69, 287,
138428
- /* 60 */ 441, 658, 708, 856, 1050, 1073, 1076, 1079, 1081, 1084,
138429
- /* 70 */ 1086, 1088, 1091, 1113, 1115, 1117, 1122, 1124, 1126, 1128,
138430
- /* 80 */ 1130, 1141, 1153, 1156, 1159, 1163, 1165, 1167, 1170, 1172,
138431
- /* 90 */ 1175, 1178, 1181, 1189, 1194, 1197, 1200, 1203, 1205, 1207,
138432
- /* 100 */ 1211, 1213, 1216, 1219, 171, 171, 171, 171, 171, 171,
138433
- /* 110 */ 171, 171, 171, 49, 176, 220, 275, 278, 290, 171,
138434
- /* 120 */ 300, 171, 171, 171, 171, -85, -85, -85, -28, 77,
138435
- /* 130 */ 313, 317, -56, 252, 252, 446, -129, 243, 361, 403,
138436
- /* 140 */ 406, 513, 517, 409, 502, 518, 504, 509, 621, 553,
138437
- /* 150 */ 562, 619, 559, 93, 620, 465, 453, 550, 591, 571,
138438
- /* 160 */ 615, 666, 750, 752, 797, 819, 463, 548, -73, 28,
138439
- /* 170 */ 68, 120, 257, 206, 359, 405, 413, 452, 457, 560,
138440
- /* 180 */ 566, 617, 670, 720, 723, 769, 773, 775, 780, 813,
138441
- /* 190 */ 814, 821, 822, 823, 826, 360, 436, 783, 829, 835,
138442
- /* 200 */ 707, 862, 867, 878, 830, 911, 915, 883, 936, 937,
138443
- /* 210 */ 940, 359, 942, 943, 944, 979, 982, 984, 886, 899,
138444
- /* 220 */ 928, 929, 931, 707, 947, 945, 998, 949, 932, 969,
138445
- /* 230 */ 918, 953, 924, 992, 1005, 1010, 1016, 971, 965, 1019,
138446
- /* 240 */ 1049, 1000, 1028, 1074, 989, 1078, 1080, 1026, 1031, 1109,
138447
- /* 250 */ 1053, 1090, 1103, 1092, 1099, 1114, 1118, 1148, 1151, 1111,
138448
- /* 260 */ 1096, 1129, 1131, 1133, 1162, 1202, 1138, 1146, 1231, 1234,
138449
- /* 270 */ 1206, 1218, 1237, 1239, 1240, 1242, 1221, 1228, 1229, 1230,
138450
- /* 280 */ 1224, 1233, 1235, 1236, 1241, 1226, 1243, 1244, 1198, 1201,
138451
- /* 290 */ 1209, 1212, 1210, 1214, 1215, 1217, 1260, 1199, 1262, 1220,
138452
- /* 300 */ 1247, 1222, 1223, 1253, 1238, 1245, 1251, 1246, 1249, 1276,
138453
- /* 310 */ 1279, 1289, 1291, 1296, 1302, 1305, 1225, 1227, 1248, 1290,
138454
- /* 320 */ 1292, 1280, 1281, 1295,
138609
+ /* 0 */ -144, -139, -134, -136, -141, 64, 114, 116, -158, -148,
138610
+ /* 10 */ -217, 96, 819, 871, 878, 219, 270, 886, 272, -110,
138611
+ /* 20 */ 413, 918, 972, 228, -214, -214, -214, -214, -214, -214,
138612
+ /* 30 */ -214, -214, -214, -214, -214, -214, -214, -214, -214, -214,
138613
+ /* 40 */ -214, -214, -214, -214, -214, -214, -214, -214, -214, -214,
138614
+ /* 50 */ -214, -214, -214, -214, -214, -214, 62, 323, 377, 536,
138615
+ /* 60 */ 539, 834, 948, 1020, 1024, 1031, 1039, 1048, 1050, 1063,
138616
+ /* 70 */ 1065, 1068, 1074, 1080, 1083, 1088, 1091, 1094, 1097, 1099,
138617
+ /* 80 */ 1103, 1106, 1111, 1114, 1122, 1126, 1129, 1131, 1137, 1139,
138618
+ /* 90 */ 1141, 1145, 1149, 1154, 1156, 1164, 1168, 1173, 1180, 1184,
138619
+ /* 100 */ 1187, 1192, -214, -214, -214, -214, -214, -214, -214, -214,
138620
+ /* 110 */ -214, 132, -45, 97, 8, 164, 379, 175, 255, -214,
138621
+ /* 120 */ 178, -214, -214, -214, -214, -168, -168, -168, 124, 329,
138622
+ /* 130 */ 399, 401, -129, 347, 347, 331, 133, 451, 452, 498,
138623
+ /* 140 */ 500, 502, 503, 505, 487, 506, 488, 490, 507, 543,
138624
+ /* 150 */ 547, -126, 588, 290, 27, 572, 501, 597, 537, 582,
138625
+ /* 160 */ 183, 599, 600, 601, 649, 650, 653, 508, 538, -29,
138626
+ /* 170 */ -156, -152, -137, -79, 135, 74, 130, 242, 338, 378,
138627
+ /* 180 */ 393, 397, 607, 648, 691, 700, 708, 709, 728, 757,
138628
+ /* 190 */ 763, 769, 796, 810, 818, 845, 202, 748, 792, 861,
138629
+ /* 200 */ 862, 815, 866, 903, 905, 850, 931, 932, 896, 937,
138630
+ /* 210 */ 939, 945, 74, 949, 951, 964, 965, 967, 968, 888,
138631
+ /* 220 */ 820, 923, 926, 959, 960, 815, 980, 908, 1009, 985,
138632
+ /* 230 */ 986, 970, 974, 942, 988, 947, 1018, 1011, 1022, 1025,
138633
+ /* 240 */ 991, 982, 1032, 1038, 1015, 1019, 1064, 984, 1071, 1072,
138634
+ /* 250 */ 992, 993, 1085, 1061, 1069, 1067, 1093, 1116, 1124, 1128,
138635
+ /* 260 */ 1133, 1132, 1138, 1086, 1136, 1143, 1146, 1175, 1166, 1108,
138636
+ /* 270 */ 1113, 1193, 1196, 1201, 1178, 1203, 1205, 1208, 1206, 1190,
138637
+ /* 280 */ 1195, 1197, 1199, 1194, 1200, 1204, 1207, 1210, 1211, 1212,
138638
+ /* 290 */ 1213, 1159, 1167, 1169, 1174, 1172, 1176, 1179, 1177, 1222,
138639
+ /* 300 */ 1170, 1232, 1171, 1221, 1181, 1182, 1223, 1202, 1214, 1216,
138640
+ /* 310 */ 1215, 1219, 1245, 1249, 1261, 1262, 1266, 1271, 1275, 1183,
138641
+ /* 320 */ 1185, 1189, 1258, 1253, 1254, 1256, 1259, 1263, 1252, 1255,
138642
+ /* 330 */ 1268, 1269, 1270, 1278, 1264,
138455138643
};
138456138644
static const YYACTIONTYPE yy_default[] = {
138457
- /* 0 */ 1270, 1260, 1260, 1260, 1193, 1193, 1193, 1193, 1260, 1088,
138458
- /* 10 */ 1117, 1117, 1244, 1322, 1322, 1322, 1322, 1322, 1322, 1192,
138459
- /* 20 */ 1322, 1322, 1322, 1322, 1260, 1092, 1123, 1322, 1322, 1322,
138460
- /* 30 */ 1322, 1194, 1195, 1322, 1322, 1322, 1243, 1245, 1133, 1132,
138461
- /* 40 */ 1131, 1130, 1226, 1104, 1128, 1121, 1125, 1194, 1188, 1189,
138462
- /* 50 */ 1187, 1191, 1195, 1322, 1124, 1158, 1172, 1157, 1322, 1322,
138463
- /* 60 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138464
- /* 70 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138465
- /* 80 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138466
- /* 90 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138467
- /* 100 */ 1322, 1322, 1322, 1322, 1166, 1171, 1178, 1170, 1167, 1160,
138468
- /* 110 */ 1159, 1161, 1162, 1322, 1011, 1059, 1322, 1322, 1322, 1163,
138469
- /* 120 */ 1322, 1164, 1175, 1174, 1173, 1251, 1278, 1277, 1322, 1322,
138470
- /* 130 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138471
- /* 140 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138472
- /* 150 */ 1322, 1322, 1322, 1322, 1322, 1270, 1260, 1017, 1017, 1322,
138473
- /* 160 */ 1260, 1260, 1260, 1260, 1260, 1260, 1256, 1092, 1083, 1322,
138474
- /* 170 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138475
- /* 180 */ 1248, 1246, 1322, 1208, 1322, 1322, 1322, 1322, 1322, 1322,
138476
- /* 190 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138477
- /* 200 */ 1322, 1322, 1322, 1322, 1088, 1322, 1322, 1322, 1322, 1322,
138478
- /* 210 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1272, 1322, 1221,
138479
- /* 220 */ 1088, 1088, 1088, 1090, 1072, 1082, 997, 1127, 1106, 1106,
138480
- /* 230 */ 1311, 1127, 1311, 1034, 1292, 1031, 1117, 1106, 1190, 1117,
138481
- /* 240 */ 1117, 1089, 1082, 1322, 1314, 1097, 1097, 1313, 1313, 1097,
138482
- /* 250 */ 1138, 1062, 1127, 1068, 1068, 1068, 1068, 1097, 1008, 1127,
138483
- /* 260 */ 1138, 1062, 1062, 1127, 1097, 1008, 1225, 1308, 1097, 1097,
138484
- /* 270 */ 1008, 1201, 1097, 1008, 1097, 1008, 1201, 1060, 1060, 1060,
138485
- /* 280 */ 1049, 1201, 1060, 1034, 1060, 1049, 1060, 1060, 1110, 1105,
138486
- /* 290 */ 1110, 1105, 1110, 1105, 1110, 1105, 1097, 1196, 1097, 1322,
138487
- /* 300 */ 1201, 1205, 1205, 1201, 1122, 1111, 1120, 1118, 1127, 1014,
138488
- /* 310 */ 1052, 1275, 1275, 1271, 1271, 1271, 1319, 1319, 1256, 1287,
138489
- /* 320 */ 1287, 1036, 1036, 1287, 1322, 1322, 1322, 1322, 1322, 1322,
138490
- /* 330 */ 1282, 1322, 1210, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138491
- /* 340 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138492
- /* 350 */ 1322, 1143, 1322, 993, 1253, 1322, 1322, 1252, 1322, 1322,
138493
- /* 360 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138494
- /* 370 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1310, 1322,
138495
- /* 380 */ 1322, 1322, 1322, 1322, 1322, 1224, 1223, 1322, 1322, 1322,
138496
- /* 390 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138497
- /* 400 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138498
- /* 410 */ 1074, 1322, 1322, 1322, 1296, 1322, 1322, 1322, 1322, 1322,
138499
- /* 420 */ 1322, 1322, 1119, 1322, 1112, 1322, 1322, 1301, 1322, 1322,
138500
- /* 430 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1262, 1322,
138501
- /* 440 */ 1322, 1322, 1261, 1322, 1322, 1322, 1322, 1322, 1145, 1322,
138502
- /* 450 */ 1144, 1148, 1322, 1002, 1322,
138645
+ /* 0 */ 1286, 1276, 1276, 1276, 1209, 1209, 1209, 1209, 1133, 1133,
138646
+ /* 10 */ 1260, 1036, 1005, 1005, 1005, 1005, 1005, 1005, 1208, 1005,
138647
+ /* 20 */ 1005, 1005, 1005, 1108, 1139, 1005, 1005, 1005, 1005, 1210,
138648
+ /* 30 */ 1211, 1005, 1005, 1005, 1259, 1261, 1149, 1148, 1147, 1146,
138649
+ /* 40 */ 1242, 1120, 1144, 1137, 1141, 1210, 1204, 1205, 1203, 1207,
138650
+ /* 50 */ 1211, 1005, 1140, 1174, 1188, 1173, 1005, 1005, 1005, 1005,
138651
+ /* 60 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138652
+ /* 70 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138653
+ /* 80 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138654
+ /* 90 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138655
+ /* 100 */ 1005, 1005, 1182, 1187, 1194, 1186, 1183, 1176, 1175, 1177,
138656
+ /* 110 */ 1178, 1005, 1026, 1075, 1005, 1005, 1005, 1276, 1036, 1179,
138657
+ /* 120 */ 1005, 1180, 1191, 1190, 1189, 1267, 1294, 1293, 1005, 1005,
138658
+ /* 130 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138659
+ /* 140 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138660
+ /* 150 */ 1005, 1005, 1005, 1005, 1005, 1036, 1286, 1276, 1032, 1032,
138661
+ /* 160 */ 1005, 1276, 1276, 1276, 1276, 1276, 1276, 1272, 1108, 1099,
138662
+ /* 170 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138663
+ /* 180 */ 1005, 1264, 1262, 1005, 1224, 1005, 1005, 1005, 1005, 1005,
138664
+ /* 190 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138665
+ /* 200 */ 1005, 1005, 1005, 1005, 1005, 1104, 1005, 1005, 1005, 1005,
138666
+ /* 210 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1288, 1005,
138667
+ /* 220 */ 1237, 1104, 1104, 1104, 1104, 1106, 1088, 1098, 1036, 1012,
138668
+ /* 230 */ 1143, 1122, 1122, 1327, 1143, 1327, 1050, 1308, 1047, 1133,
138669
+ /* 240 */ 1122, 1206, 1133, 1133, 1105, 1098, 1005, 1330, 1113, 1113,
138670
+ /* 250 */ 1329, 1329, 1113, 1154, 1078, 1143, 1084, 1084, 1084, 1084,
138671
+ /* 260 */ 1113, 1023, 1143, 1154, 1078, 1078, 1143, 1113, 1023, 1241,
138672
+ /* 270 */ 1324, 1113, 1113, 1023, 1217, 1113, 1023, 1113, 1023, 1217,
138673
+ /* 280 */ 1076, 1076, 1076, 1065, 1217, 1076, 1050, 1076, 1065, 1076,
138674
+ /* 290 */ 1076, 1126, 1121, 1126, 1121, 1126, 1121, 1126, 1121, 1113,
138675
+ /* 300 */ 1212, 1113, 1005, 1217, 1221, 1221, 1217, 1138, 1127, 1136,
138676
+ /* 310 */ 1134, 1143, 1029, 1068, 1291, 1291, 1287, 1287, 1287, 1335,
138677
+ /* 320 */ 1335, 1272, 1303, 1036, 1036, 1036, 1036, 1303, 1052, 1052,
138678
+ /* 330 */ 1036, 1036, 1036, 1036, 1303, 1005, 1005, 1005, 1005, 1005,
138679
+ /* 340 */ 1005, 1298, 1005, 1226, 1005, 1005, 1005, 1005, 1005, 1005,
138680
+ /* 350 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138681
+ /* 360 */ 1005, 1005, 1159, 1005, 1008, 1269, 1005, 1005, 1268, 1005,
138682
+ /* 370 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138683
+ /* 380 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1326,
138684
+ /* 390 */ 1005, 1005, 1005, 1005, 1005, 1005, 1240, 1239, 1005, 1005,
138685
+ /* 400 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138686
+ /* 410 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138687
+ /* 420 */ 1005, 1090, 1005, 1005, 1005, 1312, 1005, 1005, 1005, 1005,
138688
+ /* 430 */ 1005, 1005, 1005, 1135, 1005, 1128, 1005, 1005, 1317, 1005,
138689
+ /* 440 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1278,
138690
+ /* 450 */ 1005, 1005, 1005, 1277, 1005, 1005, 1005, 1005, 1005, 1161,
138691
+ /* 460 */ 1005, 1160, 1164, 1005, 1017, 1005,
138503138692
};
138504138693
/********** End of lemon-generated parsing tables *****************************/
138505138694
138506138695
/* The next table maps tokens (terminal symbols) into fallback tokens.
138507138696
** If a construct like the following:
@@ -138682,79 +138871,268 @@
138682138871
if( yyTraceFILE==0 ) yyTracePrompt = 0;
138683138872
else if( yyTracePrompt==0 ) yyTraceFILE = 0;
138684138873
}
138685138874
#endif /* NDEBUG */
138686138875
138687
-#ifndef NDEBUG
138876
+#if defined(YYCOVERAGE) || !defined(NDEBUG)
138688138877
/* For tracing shifts, the names of all terminals and nonterminals
138689138878
** are required. The following table supplies these names */
138690138879
static const char *const yyTokenName[] = {
138691
- "$", "SEMI", "EXPLAIN", "QUERY",
138692
- "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
138693
- "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
138694
- "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
138695
- "TABLE", "CREATE", "IF", "NOT",
138696
- "EXISTS", "TEMP", "LP", "RP",
138697
- "AS", "WITHOUT", "COMMA", "ABORT",
138698
- "ACTION", "AFTER", "ANALYZE", "ASC",
138699
- "ATTACH", "BEFORE", "BY", "CASCADE",
138700
- "CAST", "CONFLICT", "DATABASE", "DESC",
138701
- "DETACH", "EACH", "FAIL", "OR",
138702
- "AND", "IS", "MATCH", "LIKE_KW",
138703
- "BETWEEN", "IN", "ISNULL", "NOTNULL",
138704
- "NE", "EQ", "GT", "LE",
138705
- "LT", "GE", "ESCAPE", "ID",
138706
- "COLUMNKW", "FOR", "IGNORE", "INITIALLY",
138707
- "INSTEAD", "NO", "KEY", "OF",
138708
- "OFFSET", "PRAGMA", "RAISE", "RECURSIVE",
138709
- "REPLACE", "RESTRICT", "ROW", "TRIGGER",
138710
- "VACUUM", "VIEW", "VIRTUAL", "WITH",
138711
- "REINDEX", "RENAME", "CTIME_KW", "ANY",
138712
- "BITAND", "BITOR", "LSHIFT", "RSHIFT",
138713
- "PLUS", "MINUS", "STAR", "SLASH",
138714
- "REM", "CONCAT", "COLLATE", "BITNOT",
138715
- "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
138716
- "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
138717
- "CHECK", "REFERENCES", "AUTOINCR", "ON",
138718
- "INSERT", "DELETE", "UPDATE", "SET",
138719
- "DEFERRABLE", "FOREIGN", "DROP", "UNION",
138720
- "ALL", "EXCEPT", "INTERSECT", "SELECT",
138721
- "VALUES", "DISTINCT", "DOT", "FROM",
138722
- "JOIN", "USING", "ORDER", "GROUP",
138723
- "HAVING", "LIMIT", "WHERE", "INTO",
138724
- "FLOAT", "BLOB", "INTEGER", "VARIABLE",
138725
- "CASE", "WHEN", "THEN", "ELSE",
138726
- "INDEX", "ALTER", "ADD", "error",
138727
- "input", "cmdlist", "ecmd", "explain",
138728
- "cmdx", "cmd", "transtype", "trans_opt",
138729
- "nm", "savepoint_opt", "create_table", "create_table_args",
138730
- "createkw", "temp", "ifnotexists", "dbnm",
138731
- "columnlist", "conslist_opt", "table_options", "select",
138732
- "columnname", "carglist", "typetoken", "typename",
138733
- "signed", "plus_num", "minus_num", "ccons",
138734
- "term", "expr", "onconf", "sortorder",
138735
- "autoinc", "eidlist_opt", "refargs", "defer_subclause",
138736
- "refarg", "refact", "init_deferred_pred_opt", "conslist",
138737
- "tconscomma", "tcons", "sortlist", "eidlist",
138738
- "defer_subclause_opt", "orconf", "resolvetype", "raisetype",
138739
- "ifexists", "fullname", "selectnowith", "oneselect",
138740
- "with", "multiselect_op", "distinct", "selcollist",
138741
- "from", "where_opt", "groupby_opt", "having_opt",
138742
- "orderby_opt", "limit_opt", "values", "nexprlist",
138743
- "exprlist", "sclp", "as", "seltablist",
138744
- "stl_prefix", "joinop", "indexed_opt", "on_opt",
138745
- "using_opt", "idlist", "setlist", "insert_cmd",
138746
- "idlist_opt", "likeop", "between_op", "in_op",
138747
- "paren_exprlist", "case_operand", "case_exprlist", "case_else",
138748
- "uniqueflag", "collate", "nmnum", "trigger_decl",
138749
- "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause",
138750
- "when_clause", "trigger_cmd", "trnm", "tridxby",
138751
- "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt",
138752
- "create_vtab", "vtabarglist", "vtabarg", "vtabargtoken",
138753
- "lp", "anylist", "wqlist",
138754
-};
138755
-#endif /* NDEBUG */
138880
+ /* 0 */ "$",
138881
+ /* 1 */ "SEMI",
138882
+ /* 2 */ "EXPLAIN",
138883
+ /* 3 */ "QUERY",
138884
+ /* 4 */ "PLAN",
138885
+ /* 5 */ "BEGIN",
138886
+ /* 6 */ "TRANSACTION",
138887
+ /* 7 */ "DEFERRED",
138888
+ /* 8 */ "IMMEDIATE",
138889
+ /* 9 */ "EXCLUSIVE",
138890
+ /* 10 */ "COMMIT",
138891
+ /* 11 */ "END",
138892
+ /* 12 */ "ROLLBACK",
138893
+ /* 13 */ "SAVEPOINT",
138894
+ /* 14 */ "RELEASE",
138895
+ /* 15 */ "TO",
138896
+ /* 16 */ "TABLE",
138897
+ /* 17 */ "CREATE",
138898
+ /* 18 */ "IF",
138899
+ /* 19 */ "NOT",
138900
+ /* 20 */ "EXISTS",
138901
+ /* 21 */ "TEMP",
138902
+ /* 22 */ "LP",
138903
+ /* 23 */ "RP",
138904
+ /* 24 */ "AS",
138905
+ /* 25 */ "WITHOUT",
138906
+ /* 26 */ "COMMA",
138907
+ /* 27 */ "ABORT",
138908
+ /* 28 */ "ACTION",
138909
+ /* 29 */ "AFTER",
138910
+ /* 30 */ "ANALYZE",
138911
+ /* 31 */ "ASC",
138912
+ /* 32 */ "ATTACH",
138913
+ /* 33 */ "BEFORE",
138914
+ /* 34 */ "BY",
138915
+ /* 35 */ "CASCADE",
138916
+ /* 36 */ "CAST",
138917
+ /* 37 */ "CONFLICT",
138918
+ /* 38 */ "DATABASE",
138919
+ /* 39 */ "DESC",
138920
+ /* 40 */ "DETACH",
138921
+ /* 41 */ "EACH",
138922
+ /* 42 */ "FAIL",
138923
+ /* 43 */ "OR",
138924
+ /* 44 */ "AND",
138925
+ /* 45 */ "IS",
138926
+ /* 46 */ "MATCH",
138927
+ /* 47 */ "LIKE_KW",
138928
+ /* 48 */ "BETWEEN",
138929
+ /* 49 */ "IN",
138930
+ /* 50 */ "ISNULL",
138931
+ /* 51 */ "NOTNULL",
138932
+ /* 52 */ "NE",
138933
+ /* 53 */ "EQ",
138934
+ /* 54 */ "GT",
138935
+ /* 55 */ "LE",
138936
+ /* 56 */ "LT",
138937
+ /* 57 */ "GE",
138938
+ /* 58 */ "ESCAPE",
138939
+ /* 59 */ "ID",
138940
+ /* 60 */ "COLUMNKW",
138941
+ /* 61 */ "FOR",
138942
+ /* 62 */ "IGNORE",
138943
+ /* 63 */ "INITIALLY",
138944
+ /* 64 */ "INSTEAD",
138945
+ /* 65 */ "NO",
138946
+ /* 66 */ "KEY",
138947
+ /* 67 */ "OF",
138948
+ /* 68 */ "OFFSET",
138949
+ /* 69 */ "PRAGMA",
138950
+ /* 70 */ "RAISE",
138951
+ /* 71 */ "RECURSIVE",
138952
+ /* 72 */ "REPLACE",
138953
+ /* 73 */ "RESTRICT",
138954
+ /* 74 */ "ROW",
138955
+ /* 75 */ "TRIGGER",
138956
+ /* 76 */ "VACUUM",
138957
+ /* 77 */ "VIEW",
138958
+ /* 78 */ "VIRTUAL",
138959
+ /* 79 */ "WITH",
138960
+ /* 80 */ "REINDEX",
138961
+ /* 81 */ "RENAME",
138962
+ /* 82 */ "CTIME_KW",
138963
+ /* 83 */ "ANY",
138964
+ /* 84 */ "BITAND",
138965
+ /* 85 */ "BITOR",
138966
+ /* 86 */ "LSHIFT",
138967
+ /* 87 */ "RSHIFT",
138968
+ /* 88 */ "PLUS",
138969
+ /* 89 */ "MINUS",
138970
+ /* 90 */ "STAR",
138971
+ /* 91 */ "SLASH",
138972
+ /* 92 */ "REM",
138973
+ /* 93 */ "CONCAT",
138974
+ /* 94 */ "COLLATE",
138975
+ /* 95 */ "BITNOT",
138976
+ /* 96 */ "INDEXED",
138977
+ /* 97 */ "STRING",
138978
+ /* 98 */ "JOIN_KW",
138979
+ /* 99 */ "CONSTRAINT",
138980
+ /* 100 */ "DEFAULT",
138981
+ /* 101 */ "NULL",
138982
+ /* 102 */ "PRIMARY",
138983
+ /* 103 */ "UNIQUE",
138984
+ /* 104 */ "CHECK",
138985
+ /* 105 */ "REFERENCES",
138986
+ /* 106 */ "AUTOINCR",
138987
+ /* 107 */ "ON",
138988
+ /* 108 */ "INSERT",
138989
+ /* 109 */ "DELETE",
138990
+ /* 110 */ "UPDATE",
138991
+ /* 111 */ "SET",
138992
+ /* 112 */ "DEFERRABLE",
138993
+ /* 113 */ "FOREIGN",
138994
+ /* 114 */ "DROP",
138995
+ /* 115 */ "UNION",
138996
+ /* 116 */ "ALL",
138997
+ /* 117 */ "EXCEPT",
138998
+ /* 118 */ "INTERSECT",
138999
+ /* 119 */ "SELECT",
139000
+ /* 120 */ "VALUES",
139001
+ /* 121 */ "DISTINCT",
139002
+ /* 122 */ "DOT",
139003
+ /* 123 */ "FROM",
139004
+ /* 124 */ "JOIN",
139005
+ /* 125 */ "USING",
139006
+ /* 126 */ "ORDER",
139007
+ /* 127 */ "GROUP",
139008
+ /* 128 */ "HAVING",
139009
+ /* 129 */ "LIMIT",
139010
+ /* 130 */ "WHERE",
139011
+ /* 131 */ "INTO",
139012
+ /* 132 */ "FLOAT",
139013
+ /* 133 */ "BLOB",
139014
+ /* 134 */ "INTEGER",
139015
+ /* 135 */ "VARIABLE",
139016
+ /* 136 */ "CASE",
139017
+ /* 137 */ "WHEN",
139018
+ /* 138 */ "THEN",
139019
+ /* 139 */ "ELSE",
139020
+ /* 140 */ "INDEX",
139021
+ /* 141 */ "ALTER",
139022
+ /* 142 */ "ADD",
139023
+ /* 143 */ "error",
139024
+ /* 144 */ "input",
139025
+ /* 145 */ "cmdlist",
139026
+ /* 146 */ "ecmd",
139027
+ /* 147 */ "explain",
139028
+ /* 148 */ "cmdx",
139029
+ /* 149 */ "cmd",
139030
+ /* 150 */ "transtype",
139031
+ /* 151 */ "trans_opt",
139032
+ /* 152 */ "nm",
139033
+ /* 153 */ "savepoint_opt",
139034
+ /* 154 */ "create_table",
139035
+ /* 155 */ "create_table_args",
139036
+ /* 156 */ "createkw",
139037
+ /* 157 */ "temp",
139038
+ /* 158 */ "ifnotexists",
139039
+ /* 159 */ "dbnm",
139040
+ /* 160 */ "columnlist",
139041
+ /* 161 */ "conslist_opt",
139042
+ /* 162 */ "table_options",
139043
+ /* 163 */ "select",
139044
+ /* 164 */ "columnname",
139045
+ /* 165 */ "carglist",
139046
+ /* 166 */ "typetoken",
139047
+ /* 167 */ "typename",
139048
+ /* 168 */ "signed",
139049
+ /* 169 */ "plus_num",
139050
+ /* 170 */ "minus_num",
139051
+ /* 171 */ "scanpt",
139052
+ /* 172 */ "ccons",
139053
+ /* 173 */ "term",
139054
+ /* 174 */ "expr",
139055
+ /* 175 */ "onconf",
139056
+ /* 176 */ "sortorder",
139057
+ /* 177 */ "autoinc",
139058
+ /* 178 */ "eidlist_opt",
139059
+ /* 179 */ "refargs",
139060
+ /* 180 */ "defer_subclause",
139061
+ /* 181 */ "refarg",
139062
+ /* 182 */ "refact",
139063
+ /* 183 */ "init_deferred_pred_opt",
139064
+ /* 184 */ "conslist",
139065
+ /* 185 */ "tconscomma",
139066
+ /* 186 */ "tcons",
139067
+ /* 187 */ "sortlist",
139068
+ /* 188 */ "eidlist",
139069
+ /* 189 */ "defer_subclause_opt",
139070
+ /* 190 */ "orconf",
139071
+ /* 191 */ "resolvetype",
139072
+ /* 192 */ "raisetype",
139073
+ /* 193 */ "ifexists",
139074
+ /* 194 */ "fullname",
139075
+ /* 195 */ "selectnowith",
139076
+ /* 196 */ "oneselect",
139077
+ /* 197 */ "with",
139078
+ /* 198 */ "multiselect_op",
139079
+ /* 199 */ "distinct",
139080
+ /* 200 */ "selcollist",
139081
+ /* 201 */ "from",
139082
+ /* 202 */ "where_opt",
139083
+ /* 203 */ "groupby_opt",
139084
+ /* 204 */ "having_opt",
139085
+ /* 205 */ "orderby_opt",
139086
+ /* 206 */ "limit_opt",
139087
+ /* 207 */ "values",
139088
+ /* 208 */ "nexprlist",
139089
+ /* 209 */ "exprlist",
139090
+ /* 210 */ "sclp",
139091
+ /* 211 */ "as",
139092
+ /* 212 */ "seltablist",
139093
+ /* 213 */ "stl_prefix",
139094
+ /* 214 */ "joinop",
139095
+ /* 215 */ "indexed_opt",
139096
+ /* 216 */ "on_opt",
139097
+ /* 217 */ "using_opt",
139098
+ /* 218 */ "idlist",
139099
+ /* 219 */ "setlist",
139100
+ /* 220 */ "insert_cmd",
139101
+ /* 221 */ "idlist_opt",
139102
+ /* 222 */ "likeop",
139103
+ /* 223 */ "between_op",
139104
+ /* 224 */ "in_op",
139105
+ /* 225 */ "paren_exprlist",
139106
+ /* 226 */ "case_operand",
139107
+ /* 227 */ "case_exprlist",
139108
+ /* 228 */ "case_else",
139109
+ /* 229 */ "uniqueflag",
139110
+ /* 230 */ "collate",
139111
+ /* 231 */ "nmnum",
139112
+ /* 232 */ "trigger_decl",
139113
+ /* 233 */ "trigger_cmd_list",
139114
+ /* 234 */ "trigger_time",
139115
+ /* 235 */ "trigger_event",
139116
+ /* 236 */ "foreach_clause",
139117
+ /* 237 */ "when_clause",
139118
+ /* 238 */ "trigger_cmd",
139119
+ /* 239 */ "trnm",
139120
+ /* 240 */ "tridxby",
139121
+ /* 241 */ "database_kw_opt",
139122
+ /* 242 */ "key_opt",
139123
+ /* 243 */ "add_column_fullname",
139124
+ /* 244 */ "kwcolumn_opt",
139125
+ /* 245 */ "create_vtab",
139126
+ /* 246 */ "vtabarglist",
139127
+ /* 247 */ "vtabarg",
139128
+ /* 248 */ "vtabargtoken",
139129
+ /* 249 */ "lp",
139130
+ /* 250 */ "anylist",
139131
+ /* 251 */ "wqlist",
139132
+};
139133
+#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
138756139134
138757139135
#ifndef NDEBUG
138758139136
/* For tracing reduce actions, the names of all rules are required.
138759139137
*/
138760139138
static const char *const yyRuleName[] = {
@@ -138784,311 +139162,312 @@
138784139162
/* 23 */ "columnname ::= nm typetoken",
138785139163
/* 24 */ "typetoken ::=",
138786139164
/* 25 */ "typetoken ::= typename LP signed RP",
138787139165
/* 26 */ "typetoken ::= typename LP signed COMMA signed RP",
138788139166
/* 27 */ "typename ::= typename ID|STRING",
138789
- /* 28 */ "ccons ::= CONSTRAINT nm",
138790
- /* 29 */ "ccons ::= DEFAULT term",
138791
- /* 30 */ "ccons ::= DEFAULT LP expr RP",
138792
- /* 31 */ "ccons ::= DEFAULT PLUS term",
138793
- /* 32 */ "ccons ::= DEFAULT MINUS term",
138794
- /* 33 */ "ccons ::= DEFAULT ID|INDEXED",
138795
- /* 34 */ "ccons ::= NOT NULL onconf",
138796
- /* 35 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
138797
- /* 36 */ "ccons ::= UNIQUE onconf",
138798
- /* 37 */ "ccons ::= CHECK LP expr RP",
138799
- /* 38 */ "ccons ::= REFERENCES nm eidlist_opt refargs",
138800
- /* 39 */ "ccons ::= defer_subclause",
138801
- /* 40 */ "ccons ::= COLLATE ID|STRING",
138802
- /* 41 */ "autoinc ::=",
138803
- /* 42 */ "autoinc ::= AUTOINCR",
138804
- /* 43 */ "refargs ::=",
138805
- /* 44 */ "refargs ::= refargs refarg",
138806
- /* 45 */ "refarg ::= MATCH nm",
138807
- /* 46 */ "refarg ::= ON INSERT refact",
138808
- /* 47 */ "refarg ::= ON DELETE refact",
138809
- /* 48 */ "refarg ::= ON UPDATE refact",
138810
- /* 49 */ "refact ::= SET NULL",
138811
- /* 50 */ "refact ::= SET DEFAULT",
138812
- /* 51 */ "refact ::= CASCADE",
138813
- /* 52 */ "refact ::= RESTRICT",
138814
- /* 53 */ "refact ::= NO ACTION",
138815
- /* 54 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
138816
- /* 55 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
138817
- /* 56 */ "init_deferred_pred_opt ::=",
138818
- /* 57 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
138819
- /* 58 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
138820
- /* 59 */ "conslist_opt ::=",
138821
- /* 60 */ "tconscomma ::= COMMA",
138822
- /* 61 */ "tcons ::= CONSTRAINT nm",
138823
- /* 62 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf",
138824
- /* 63 */ "tcons ::= UNIQUE LP sortlist RP onconf",
138825
- /* 64 */ "tcons ::= CHECK LP expr RP onconf",
138826
- /* 65 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt",
138827
- /* 66 */ "defer_subclause_opt ::=",
138828
- /* 67 */ "onconf ::=",
138829
- /* 68 */ "onconf ::= ON CONFLICT resolvetype",
138830
- /* 69 */ "orconf ::=",
138831
- /* 70 */ "orconf ::= OR resolvetype",
138832
- /* 71 */ "resolvetype ::= IGNORE",
138833
- /* 72 */ "resolvetype ::= REPLACE",
138834
- /* 73 */ "cmd ::= DROP TABLE ifexists fullname",
138835
- /* 74 */ "ifexists ::= IF EXISTS",
138836
- /* 75 */ "ifexists ::=",
138837
- /* 76 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select",
138838
- /* 77 */ "cmd ::= DROP VIEW ifexists fullname",
138839
- /* 78 */ "cmd ::= select",
138840
- /* 79 */ "select ::= with selectnowith",
138841
- /* 80 */ "selectnowith ::= selectnowith multiselect_op oneselect",
138842
- /* 81 */ "multiselect_op ::= UNION",
138843
- /* 82 */ "multiselect_op ::= UNION ALL",
138844
- /* 83 */ "multiselect_op ::= EXCEPT|INTERSECT",
138845
- /* 84 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
138846
- /* 85 */ "values ::= VALUES LP nexprlist RP",
138847
- /* 86 */ "values ::= values COMMA LP exprlist RP",
138848
- /* 87 */ "distinct ::= DISTINCT",
138849
- /* 88 */ "distinct ::= ALL",
138850
- /* 89 */ "distinct ::=",
138851
- /* 90 */ "sclp ::=",
138852
- /* 91 */ "selcollist ::= sclp expr as",
138853
- /* 92 */ "selcollist ::= sclp STAR",
138854
- /* 93 */ "selcollist ::= sclp nm DOT STAR",
138855
- /* 94 */ "as ::= AS nm",
138856
- /* 95 */ "as ::=",
138857
- /* 96 */ "from ::=",
138858
- /* 97 */ "from ::= FROM seltablist",
138859
- /* 98 */ "stl_prefix ::= seltablist joinop",
138860
- /* 99 */ "stl_prefix ::=",
138861
- /* 100 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
138862
- /* 101 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt",
138863
- /* 102 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
138864
- /* 103 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
138865
- /* 104 */ "dbnm ::=",
138866
- /* 105 */ "dbnm ::= DOT nm",
138867
- /* 106 */ "fullname ::= nm dbnm",
138868
- /* 107 */ "joinop ::= COMMA|JOIN",
138869
- /* 108 */ "joinop ::= JOIN_KW JOIN",
138870
- /* 109 */ "joinop ::= JOIN_KW nm JOIN",
138871
- /* 110 */ "joinop ::= JOIN_KW nm nm JOIN",
138872
- /* 111 */ "on_opt ::= ON expr",
138873
- /* 112 */ "on_opt ::=",
138874
- /* 113 */ "indexed_opt ::=",
138875
- /* 114 */ "indexed_opt ::= INDEXED BY nm",
138876
- /* 115 */ "indexed_opt ::= NOT INDEXED",
138877
- /* 116 */ "using_opt ::= USING LP idlist RP",
138878
- /* 117 */ "using_opt ::=",
138879
- /* 118 */ "orderby_opt ::=",
138880
- /* 119 */ "orderby_opt ::= ORDER BY sortlist",
138881
- /* 120 */ "sortlist ::= sortlist COMMA expr sortorder",
138882
- /* 121 */ "sortlist ::= expr sortorder",
138883
- /* 122 */ "sortorder ::= ASC",
138884
- /* 123 */ "sortorder ::= DESC",
138885
- /* 124 */ "sortorder ::=",
138886
- /* 125 */ "groupby_opt ::=",
138887
- /* 126 */ "groupby_opt ::= GROUP BY nexprlist",
138888
- /* 127 */ "having_opt ::=",
138889
- /* 128 */ "having_opt ::= HAVING expr",
138890
- /* 129 */ "limit_opt ::=",
138891
- /* 130 */ "limit_opt ::= LIMIT expr",
138892
- /* 131 */ "limit_opt ::= LIMIT expr OFFSET expr",
138893
- /* 132 */ "limit_opt ::= LIMIT expr COMMA expr",
138894
- /* 133 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
138895
- /* 134 */ "where_opt ::=",
138896
- /* 135 */ "where_opt ::= WHERE expr",
138897
- /* 136 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
138898
- /* 137 */ "setlist ::= setlist COMMA nm EQ expr",
138899
- /* 138 */ "setlist ::= setlist COMMA LP idlist RP EQ expr",
138900
- /* 139 */ "setlist ::= nm EQ expr",
138901
- /* 140 */ "setlist ::= LP idlist RP EQ expr",
138902
- /* 141 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select",
138903
- /* 142 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES",
138904
- /* 143 */ "insert_cmd ::= INSERT orconf",
138905
- /* 144 */ "insert_cmd ::= REPLACE",
138906
- /* 145 */ "idlist_opt ::=",
138907
- /* 146 */ "idlist_opt ::= LP idlist RP",
138908
- /* 147 */ "idlist ::= idlist COMMA nm",
138909
- /* 148 */ "idlist ::= nm",
138910
- /* 149 */ "expr ::= LP expr RP",
138911
- /* 150 */ "expr ::= ID|INDEXED",
138912
- /* 151 */ "expr ::= JOIN_KW",
138913
- /* 152 */ "expr ::= nm DOT nm",
138914
- /* 153 */ "expr ::= nm DOT nm DOT nm",
138915
- /* 154 */ "term ::= NULL|FLOAT|BLOB",
138916
- /* 155 */ "term ::= STRING",
138917
- /* 156 */ "term ::= INTEGER",
138918
- /* 157 */ "expr ::= VARIABLE",
138919
- /* 158 */ "expr ::= expr COLLATE ID|STRING",
138920
- /* 159 */ "expr ::= CAST LP expr AS typetoken RP",
138921
- /* 160 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
138922
- /* 161 */ "expr ::= ID|INDEXED LP STAR RP",
138923
- /* 162 */ "term ::= CTIME_KW",
138924
- /* 163 */ "expr ::= LP nexprlist COMMA expr RP",
138925
- /* 164 */ "expr ::= expr AND expr",
138926
- /* 165 */ "expr ::= expr OR expr",
138927
- /* 166 */ "expr ::= expr LT|GT|GE|LE expr",
138928
- /* 167 */ "expr ::= expr EQ|NE expr",
138929
- /* 168 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
138930
- /* 169 */ "expr ::= expr PLUS|MINUS expr",
138931
- /* 170 */ "expr ::= expr STAR|SLASH|REM expr",
138932
- /* 171 */ "expr ::= expr CONCAT expr",
138933
- /* 172 */ "likeop ::= NOT LIKE_KW|MATCH",
138934
- /* 173 */ "expr ::= expr likeop expr",
138935
- /* 174 */ "expr ::= expr likeop expr ESCAPE expr",
138936
- /* 175 */ "expr ::= expr ISNULL|NOTNULL",
138937
- /* 176 */ "expr ::= expr NOT NULL",
138938
- /* 177 */ "expr ::= expr IS expr",
138939
- /* 178 */ "expr ::= expr IS NOT expr",
138940
- /* 179 */ "expr ::= NOT expr",
138941
- /* 180 */ "expr ::= BITNOT expr",
138942
- /* 181 */ "expr ::= MINUS expr",
138943
- /* 182 */ "expr ::= PLUS expr",
138944
- /* 183 */ "between_op ::= BETWEEN",
138945
- /* 184 */ "between_op ::= NOT BETWEEN",
138946
- /* 185 */ "expr ::= expr between_op expr AND expr",
138947
- /* 186 */ "in_op ::= IN",
138948
- /* 187 */ "in_op ::= NOT IN",
138949
- /* 188 */ "expr ::= expr in_op LP exprlist RP",
138950
- /* 189 */ "expr ::= LP select RP",
138951
- /* 190 */ "expr ::= expr in_op LP select RP",
138952
- /* 191 */ "expr ::= expr in_op nm dbnm paren_exprlist",
138953
- /* 192 */ "expr ::= EXISTS LP select RP",
138954
- /* 193 */ "expr ::= CASE case_operand case_exprlist case_else END",
138955
- /* 194 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
138956
- /* 195 */ "case_exprlist ::= WHEN expr THEN expr",
138957
- /* 196 */ "case_else ::= ELSE expr",
138958
- /* 197 */ "case_else ::=",
138959
- /* 198 */ "case_operand ::= expr",
138960
- /* 199 */ "case_operand ::=",
138961
- /* 200 */ "exprlist ::=",
138962
- /* 201 */ "nexprlist ::= nexprlist COMMA expr",
138963
- /* 202 */ "nexprlist ::= expr",
138964
- /* 203 */ "paren_exprlist ::=",
138965
- /* 204 */ "paren_exprlist ::= LP exprlist RP",
138966
- /* 205 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
138967
- /* 206 */ "uniqueflag ::= UNIQUE",
138968
- /* 207 */ "uniqueflag ::=",
138969
- /* 208 */ "eidlist_opt ::=",
138970
- /* 209 */ "eidlist_opt ::= LP eidlist RP",
138971
- /* 210 */ "eidlist ::= eidlist COMMA nm collate sortorder",
138972
- /* 211 */ "eidlist ::= nm collate sortorder",
138973
- /* 212 */ "collate ::=",
138974
- /* 213 */ "collate ::= COLLATE ID|STRING",
138975
- /* 214 */ "cmd ::= DROP INDEX ifexists fullname",
138976
- /* 215 */ "cmd ::= VACUUM",
138977
- /* 216 */ "cmd ::= VACUUM nm",
138978
- /* 217 */ "cmd ::= PRAGMA nm dbnm",
138979
- /* 218 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
138980
- /* 219 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
138981
- /* 220 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
138982
- /* 221 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
138983
- /* 222 */ "plus_num ::= PLUS INTEGER|FLOAT",
138984
- /* 223 */ "minus_num ::= MINUS INTEGER|FLOAT",
138985
- /* 224 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
138986
- /* 225 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
138987
- /* 226 */ "trigger_time ::= BEFORE|AFTER",
138988
- /* 227 */ "trigger_time ::= INSTEAD OF",
138989
- /* 228 */ "trigger_time ::=",
138990
- /* 229 */ "trigger_event ::= DELETE|INSERT",
138991
- /* 230 */ "trigger_event ::= UPDATE",
138992
- /* 231 */ "trigger_event ::= UPDATE OF idlist",
138993
- /* 232 */ "when_clause ::=",
138994
- /* 233 */ "when_clause ::= WHEN expr",
138995
- /* 234 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
138996
- /* 235 */ "trigger_cmd_list ::= trigger_cmd SEMI",
138997
- /* 236 */ "trnm ::= nm DOT nm",
138998
- /* 237 */ "tridxby ::= INDEXED BY nm",
138999
- /* 238 */ "tridxby ::= NOT INDEXED",
139000
- /* 239 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
139001
- /* 240 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
139002
- /* 241 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
139003
- /* 242 */ "trigger_cmd ::= select",
139004
- /* 243 */ "expr ::= RAISE LP IGNORE RP",
139005
- /* 244 */ "expr ::= RAISE LP raisetype COMMA nm RP",
139006
- /* 245 */ "raisetype ::= ROLLBACK",
139007
- /* 246 */ "raisetype ::= ABORT",
139008
- /* 247 */ "raisetype ::= FAIL",
139009
- /* 248 */ "cmd ::= DROP TRIGGER ifexists fullname",
139010
- /* 249 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
139011
- /* 250 */ "cmd ::= DETACH database_kw_opt expr",
139012
- /* 251 */ "key_opt ::=",
139013
- /* 252 */ "key_opt ::= KEY expr",
139014
- /* 253 */ "cmd ::= REINDEX",
139015
- /* 254 */ "cmd ::= REINDEX nm dbnm",
139016
- /* 255 */ "cmd ::= ANALYZE",
139017
- /* 256 */ "cmd ::= ANALYZE nm dbnm",
139018
- /* 257 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
139019
- /* 258 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
139020
- /* 259 */ "add_column_fullname ::= fullname",
139021
- /* 260 */ "cmd ::= create_vtab",
139022
- /* 261 */ "cmd ::= create_vtab LP vtabarglist RP",
139023
- /* 262 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
139024
- /* 263 */ "vtabarg ::=",
139025
- /* 264 */ "vtabargtoken ::= ANY",
139026
- /* 265 */ "vtabargtoken ::= lp anylist RP",
139027
- /* 266 */ "lp ::= LP",
139028
- /* 267 */ "with ::=",
139029
- /* 268 */ "with ::= WITH wqlist",
139030
- /* 269 */ "with ::= WITH RECURSIVE wqlist",
139031
- /* 270 */ "wqlist ::= nm eidlist_opt AS LP select RP",
139032
- /* 271 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
139033
- /* 272 */ "input ::= cmdlist",
139034
- /* 273 */ "cmdlist ::= cmdlist ecmd",
139035
- /* 274 */ "cmdlist ::= ecmd",
139036
- /* 275 */ "ecmd ::= SEMI",
139037
- /* 276 */ "ecmd ::= explain cmdx SEMI",
139038
- /* 277 */ "explain ::=",
139039
- /* 278 */ "trans_opt ::=",
139040
- /* 279 */ "trans_opt ::= TRANSACTION",
139041
- /* 280 */ "trans_opt ::= TRANSACTION nm",
139042
- /* 281 */ "savepoint_opt ::= SAVEPOINT",
139043
- /* 282 */ "savepoint_opt ::=",
139044
- /* 283 */ "cmd ::= create_table create_table_args",
139045
- /* 284 */ "columnlist ::= columnlist COMMA columnname carglist",
139046
- /* 285 */ "columnlist ::= columnname carglist",
139047
- /* 286 */ "nm ::= ID|INDEXED",
139048
- /* 287 */ "nm ::= STRING",
139049
- /* 288 */ "nm ::= JOIN_KW",
139050
- /* 289 */ "typetoken ::= typename",
139051
- /* 290 */ "typename ::= ID|STRING",
139052
- /* 291 */ "signed ::= plus_num",
139053
- /* 292 */ "signed ::= minus_num",
139054
- /* 293 */ "carglist ::= carglist ccons",
139055
- /* 294 */ "carglist ::=",
139056
- /* 295 */ "ccons ::= NULL onconf",
139057
- /* 296 */ "conslist_opt ::= COMMA conslist",
139058
- /* 297 */ "conslist ::= conslist tconscomma tcons",
139059
- /* 298 */ "conslist ::= tcons",
139060
- /* 299 */ "tconscomma ::=",
139061
- /* 300 */ "defer_subclause_opt ::= defer_subclause",
139062
- /* 301 */ "resolvetype ::= raisetype",
139063
- /* 302 */ "selectnowith ::= oneselect",
139064
- /* 303 */ "oneselect ::= values",
139065
- /* 304 */ "sclp ::= selcollist COMMA",
139066
- /* 305 */ "as ::= ID|STRING",
139067
- /* 306 */ "expr ::= term",
139068
- /* 307 */ "likeop ::= LIKE_KW|MATCH",
139069
- /* 308 */ "exprlist ::= nexprlist",
139070
- /* 309 */ "nmnum ::= plus_num",
139071
- /* 310 */ "nmnum ::= nm",
139072
- /* 311 */ "nmnum ::= ON",
139073
- /* 312 */ "nmnum ::= DELETE",
139074
- /* 313 */ "nmnum ::= DEFAULT",
139075
- /* 314 */ "plus_num ::= INTEGER|FLOAT",
139076
- /* 315 */ "foreach_clause ::=",
139077
- /* 316 */ "foreach_clause ::= FOR EACH ROW",
139078
- /* 317 */ "trnm ::= nm",
139079
- /* 318 */ "tridxby ::=",
139080
- /* 319 */ "database_kw_opt ::= DATABASE",
139081
- /* 320 */ "database_kw_opt ::=",
139082
- /* 321 */ "kwcolumn_opt ::=",
139083
- /* 322 */ "kwcolumn_opt ::= COLUMNKW",
139084
- /* 323 */ "vtabarglist ::= vtabarg",
139085
- /* 324 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
139086
- /* 325 */ "vtabarg ::= vtabarg vtabargtoken",
139087
- /* 326 */ "anylist ::=",
139088
- /* 327 */ "anylist ::= anylist LP anylist RP",
139089
- /* 328 */ "anylist ::= anylist ANY",
139167
+ /* 28 */ "scanpt ::=",
139168
+ /* 29 */ "ccons ::= CONSTRAINT nm",
139169
+ /* 30 */ "ccons ::= DEFAULT scanpt term scanpt",
139170
+ /* 31 */ "ccons ::= DEFAULT LP expr RP",
139171
+ /* 32 */ "ccons ::= DEFAULT PLUS term scanpt",
139172
+ /* 33 */ "ccons ::= DEFAULT MINUS term scanpt",
139173
+ /* 34 */ "ccons ::= DEFAULT scanpt ID|INDEXED",
139174
+ /* 35 */ "ccons ::= NOT NULL onconf",
139175
+ /* 36 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
139176
+ /* 37 */ "ccons ::= UNIQUE onconf",
139177
+ /* 38 */ "ccons ::= CHECK LP expr RP",
139178
+ /* 39 */ "ccons ::= REFERENCES nm eidlist_opt refargs",
139179
+ /* 40 */ "ccons ::= defer_subclause",
139180
+ /* 41 */ "ccons ::= COLLATE ID|STRING",
139181
+ /* 42 */ "autoinc ::=",
139182
+ /* 43 */ "autoinc ::= AUTOINCR",
139183
+ /* 44 */ "refargs ::=",
139184
+ /* 45 */ "refargs ::= refargs refarg",
139185
+ /* 46 */ "refarg ::= MATCH nm",
139186
+ /* 47 */ "refarg ::= ON INSERT refact",
139187
+ /* 48 */ "refarg ::= ON DELETE refact",
139188
+ /* 49 */ "refarg ::= ON UPDATE refact",
139189
+ /* 50 */ "refact ::= SET NULL",
139190
+ /* 51 */ "refact ::= SET DEFAULT",
139191
+ /* 52 */ "refact ::= CASCADE",
139192
+ /* 53 */ "refact ::= RESTRICT",
139193
+ /* 54 */ "refact ::= NO ACTION",
139194
+ /* 55 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
139195
+ /* 56 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
139196
+ /* 57 */ "init_deferred_pred_opt ::=",
139197
+ /* 58 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
139198
+ /* 59 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
139199
+ /* 60 */ "conslist_opt ::=",
139200
+ /* 61 */ "tconscomma ::= COMMA",
139201
+ /* 62 */ "tcons ::= CONSTRAINT nm",
139202
+ /* 63 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf",
139203
+ /* 64 */ "tcons ::= UNIQUE LP sortlist RP onconf",
139204
+ /* 65 */ "tcons ::= CHECK LP expr RP onconf",
139205
+ /* 66 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt",
139206
+ /* 67 */ "defer_subclause_opt ::=",
139207
+ /* 68 */ "onconf ::=",
139208
+ /* 69 */ "onconf ::= ON CONFLICT resolvetype",
139209
+ /* 70 */ "orconf ::=",
139210
+ /* 71 */ "orconf ::= OR resolvetype",
139211
+ /* 72 */ "resolvetype ::= IGNORE",
139212
+ /* 73 */ "resolvetype ::= REPLACE",
139213
+ /* 74 */ "cmd ::= DROP TABLE ifexists fullname",
139214
+ /* 75 */ "ifexists ::= IF EXISTS",
139215
+ /* 76 */ "ifexists ::=",
139216
+ /* 77 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select",
139217
+ /* 78 */ "cmd ::= DROP VIEW ifexists fullname",
139218
+ /* 79 */ "cmd ::= select",
139219
+ /* 80 */ "select ::= with selectnowith",
139220
+ /* 81 */ "selectnowith ::= selectnowith multiselect_op oneselect",
139221
+ /* 82 */ "multiselect_op ::= UNION",
139222
+ /* 83 */ "multiselect_op ::= UNION ALL",
139223
+ /* 84 */ "multiselect_op ::= EXCEPT|INTERSECT",
139224
+ /* 85 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
139225
+ /* 86 */ "values ::= VALUES LP nexprlist RP",
139226
+ /* 87 */ "values ::= values COMMA LP exprlist RP",
139227
+ /* 88 */ "distinct ::= DISTINCT",
139228
+ /* 89 */ "distinct ::= ALL",
139229
+ /* 90 */ "distinct ::=",
139230
+ /* 91 */ "sclp ::=",
139231
+ /* 92 */ "selcollist ::= sclp scanpt expr scanpt as",
139232
+ /* 93 */ "selcollist ::= sclp scanpt STAR",
139233
+ /* 94 */ "selcollist ::= sclp scanpt nm DOT STAR",
139234
+ /* 95 */ "as ::= AS nm",
139235
+ /* 96 */ "as ::=",
139236
+ /* 97 */ "from ::=",
139237
+ /* 98 */ "from ::= FROM seltablist",
139238
+ /* 99 */ "stl_prefix ::= seltablist joinop",
139239
+ /* 100 */ "stl_prefix ::=",
139240
+ /* 101 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
139241
+ /* 102 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt",
139242
+ /* 103 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
139243
+ /* 104 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
139244
+ /* 105 */ "dbnm ::=",
139245
+ /* 106 */ "dbnm ::= DOT nm",
139246
+ /* 107 */ "fullname ::= nm dbnm",
139247
+ /* 108 */ "joinop ::= COMMA|JOIN",
139248
+ /* 109 */ "joinop ::= JOIN_KW JOIN",
139249
+ /* 110 */ "joinop ::= JOIN_KW nm JOIN",
139250
+ /* 111 */ "joinop ::= JOIN_KW nm nm JOIN",
139251
+ /* 112 */ "on_opt ::= ON expr",
139252
+ /* 113 */ "on_opt ::=",
139253
+ /* 114 */ "indexed_opt ::=",
139254
+ /* 115 */ "indexed_opt ::= INDEXED BY nm",
139255
+ /* 116 */ "indexed_opt ::= NOT INDEXED",
139256
+ /* 117 */ "using_opt ::= USING LP idlist RP",
139257
+ /* 118 */ "using_opt ::=",
139258
+ /* 119 */ "orderby_opt ::=",
139259
+ /* 120 */ "orderby_opt ::= ORDER BY sortlist",
139260
+ /* 121 */ "sortlist ::= sortlist COMMA expr sortorder",
139261
+ /* 122 */ "sortlist ::= expr sortorder",
139262
+ /* 123 */ "sortorder ::= ASC",
139263
+ /* 124 */ "sortorder ::= DESC",
139264
+ /* 125 */ "sortorder ::=",
139265
+ /* 126 */ "groupby_opt ::=",
139266
+ /* 127 */ "groupby_opt ::= GROUP BY nexprlist",
139267
+ /* 128 */ "having_opt ::=",
139268
+ /* 129 */ "having_opt ::= HAVING expr",
139269
+ /* 130 */ "limit_opt ::=",
139270
+ /* 131 */ "limit_opt ::= LIMIT expr",
139271
+ /* 132 */ "limit_opt ::= LIMIT expr OFFSET expr",
139272
+ /* 133 */ "limit_opt ::= LIMIT expr COMMA expr",
139273
+ /* 134 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
139274
+ /* 135 */ "where_opt ::=",
139275
+ /* 136 */ "where_opt ::= WHERE expr",
139276
+ /* 137 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
139277
+ /* 138 */ "setlist ::= setlist COMMA nm EQ expr",
139278
+ /* 139 */ "setlist ::= setlist COMMA LP idlist RP EQ expr",
139279
+ /* 140 */ "setlist ::= nm EQ expr",
139280
+ /* 141 */ "setlist ::= LP idlist RP EQ expr",
139281
+ /* 142 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select",
139282
+ /* 143 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES",
139283
+ /* 144 */ "insert_cmd ::= INSERT orconf",
139284
+ /* 145 */ "insert_cmd ::= REPLACE",
139285
+ /* 146 */ "idlist_opt ::=",
139286
+ /* 147 */ "idlist_opt ::= LP idlist RP",
139287
+ /* 148 */ "idlist ::= idlist COMMA nm",
139288
+ /* 149 */ "idlist ::= nm",
139289
+ /* 150 */ "expr ::= LP expr RP",
139290
+ /* 151 */ "expr ::= ID|INDEXED",
139291
+ /* 152 */ "expr ::= JOIN_KW",
139292
+ /* 153 */ "expr ::= nm DOT nm",
139293
+ /* 154 */ "expr ::= nm DOT nm DOT nm",
139294
+ /* 155 */ "term ::= NULL|FLOAT|BLOB",
139295
+ /* 156 */ "term ::= STRING",
139296
+ /* 157 */ "term ::= INTEGER",
139297
+ /* 158 */ "expr ::= VARIABLE",
139298
+ /* 159 */ "expr ::= expr COLLATE ID|STRING",
139299
+ /* 160 */ "expr ::= CAST LP expr AS typetoken RP",
139300
+ /* 161 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
139301
+ /* 162 */ "expr ::= ID|INDEXED LP STAR RP",
139302
+ /* 163 */ "term ::= CTIME_KW",
139303
+ /* 164 */ "expr ::= LP nexprlist COMMA expr RP",
139304
+ /* 165 */ "expr ::= expr AND expr",
139305
+ /* 166 */ "expr ::= expr OR expr",
139306
+ /* 167 */ "expr ::= expr LT|GT|GE|LE expr",
139307
+ /* 168 */ "expr ::= expr EQ|NE expr",
139308
+ /* 169 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
139309
+ /* 170 */ "expr ::= expr PLUS|MINUS expr",
139310
+ /* 171 */ "expr ::= expr STAR|SLASH|REM expr",
139311
+ /* 172 */ "expr ::= expr CONCAT expr",
139312
+ /* 173 */ "likeop ::= NOT LIKE_KW|MATCH",
139313
+ /* 174 */ "expr ::= expr likeop expr",
139314
+ /* 175 */ "expr ::= expr likeop expr ESCAPE expr",
139315
+ /* 176 */ "expr ::= expr ISNULL|NOTNULL",
139316
+ /* 177 */ "expr ::= expr NOT NULL",
139317
+ /* 178 */ "expr ::= expr IS expr",
139318
+ /* 179 */ "expr ::= expr IS NOT expr",
139319
+ /* 180 */ "expr ::= NOT expr",
139320
+ /* 181 */ "expr ::= BITNOT expr",
139321
+ /* 182 */ "expr ::= MINUS expr",
139322
+ /* 183 */ "expr ::= PLUS expr",
139323
+ /* 184 */ "between_op ::= BETWEEN",
139324
+ /* 185 */ "between_op ::= NOT BETWEEN",
139325
+ /* 186 */ "expr ::= expr between_op expr AND expr",
139326
+ /* 187 */ "in_op ::= IN",
139327
+ /* 188 */ "in_op ::= NOT IN",
139328
+ /* 189 */ "expr ::= expr in_op LP exprlist RP",
139329
+ /* 190 */ "expr ::= LP select RP",
139330
+ /* 191 */ "expr ::= expr in_op LP select RP",
139331
+ /* 192 */ "expr ::= expr in_op nm dbnm paren_exprlist",
139332
+ /* 193 */ "expr ::= EXISTS LP select RP",
139333
+ /* 194 */ "expr ::= CASE case_operand case_exprlist case_else END",
139334
+ /* 195 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
139335
+ /* 196 */ "case_exprlist ::= WHEN expr THEN expr",
139336
+ /* 197 */ "case_else ::= ELSE expr",
139337
+ /* 198 */ "case_else ::=",
139338
+ /* 199 */ "case_operand ::= expr",
139339
+ /* 200 */ "case_operand ::=",
139340
+ /* 201 */ "exprlist ::=",
139341
+ /* 202 */ "nexprlist ::= nexprlist COMMA expr",
139342
+ /* 203 */ "nexprlist ::= expr",
139343
+ /* 204 */ "paren_exprlist ::=",
139344
+ /* 205 */ "paren_exprlist ::= LP exprlist RP",
139345
+ /* 206 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
139346
+ /* 207 */ "uniqueflag ::= UNIQUE",
139347
+ /* 208 */ "uniqueflag ::=",
139348
+ /* 209 */ "eidlist_opt ::=",
139349
+ /* 210 */ "eidlist_opt ::= LP eidlist RP",
139350
+ /* 211 */ "eidlist ::= eidlist COMMA nm collate sortorder",
139351
+ /* 212 */ "eidlist ::= nm collate sortorder",
139352
+ /* 213 */ "collate ::=",
139353
+ /* 214 */ "collate ::= COLLATE ID|STRING",
139354
+ /* 215 */ "cmd ::= DROP INDEX ifexists fullname",
139355
+ /* 216 */ "cmd ::= VACUUM",
139356
+ /* 217 */ "cmd ::= VACUUM nm",
139357
+ /* 218 */ "cmd ::= PRAGMA nm dbnm",
139358
+ /* 219 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
139359
+ /* 220 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
139360
+ /* 221 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
139361
+ /* 222 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
139362
+ /* 223 */ "plus_num ::= PLUS INTEGER|FLOAT",
139363
+ /* 224 */ "minus_num ::= MINUS INTEGER|FLOAT",
139364
+ /* 225 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
139365
+ /* 226 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
139366
+ /* 227 */ "trigger_time ::= BEFORE|AFTER",
139367
+ /* 228 */ "trigger_time ::= INSTEAD OF",
139368
+ /* 229 */ "trigger_time ::=",
139369
+ /* 230 */ "trigger_event ::= DELETE|INSERT",
139370
+ /* 231 */ "trigger_event ::= UPDATE",
139371
+ /* 232 */ "trigger_event ::= UPDATE OF idlist",
139372
+ /* 233 */ "when_clause ::=",
139373
+ /* 234 */ "when_clause ::= WHEN expr",
139374
+ /* 235 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
139375
+ /* 236 */ "trigger_cmd_list ::= trigger_cmd SEMI",
139376
+ /* 237 */ "trnm ::= nm DOT nm",
139377
+ /* 238 */ "tridxby ::= INDEXED BY nm",
139378
+ /* 239 */ "tridxby ::= NOT INDEXED",
139379
+ /* 240 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt",
139380
+ /* 241 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt",
139381
+ /* 242 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
139382
+ /* 243 */ "trigger_cmd ::= scanpt select scanpt",
139383
+ /* 244 */ "expr ::= RAISE LP IGNORE RP",
139384
+ /* 245 */ "expr ::= RAISE LP raisetype COMMA nm RP",
139385
+ /* 246 */ "raisetype ::= ROLLBACK",
139386
+ /* 247 */ "raisetype ::= ABORT",
139387
+ /* 248 */ "raisetype ::= FAIL",
139388
+ /* 249 */ "cmd ::= DROP TRIGGER ifexists fullname",
139389
+ /* 250 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
139390
+ /* 251 */ "cmd ::= DETACH database_kw_opt expr",
139391
+ /* 252 */ "key_opt ::=",
139392
+ /* 253 */ "key_opt ::= KEY expr",
139393
+ /* 254 */ "cmd ::= REINDEX",
139394
+ /* 255 */ "cmd ::= REINDEX nm dbnm",
139395
+ /* 256 */ "cmd ::= ANALYZE",
139396
+ /* 257 */ "cmd ::= ANALYZE nm dbnm",
139397
+ /* 258 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
139398
+ /* 259 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
139399
+ /* 260 */ "add_column_fullname ::= fullname",
139400
+ /* 261 */ "cmd ::= create_vtab",
139401
+ /* 262 */ "cmd ::= create_vtab LP vtabarglist RP",
139402
+ /* 263 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
139403
+ /* 264 */ "vtabarg ::=",
139404
+ /* 265 */ "vtabargtoken ::= ANY",
139405
+ /* 266 */ "vtabargtoken ::= lp anylist RP",
139406
+ /* 267 */ "lp ::= LP",
139407
+ /* 268 */ "with ::=",
139408
+ /* 269 */ "with ::= WITH wqlist",
139409
+ /* 270 */ "with ::= WITH RECURSIVE wqlist",
139410
+ /* 271 */ "wqlist ::= nm eidlist_opt AS LP select RP",
139411
+ /* 272 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
139412
+ /* 273 */ "input ::= cmdlist",
139413
+ /* 274 */ "cmdlist ::= cmdlist ecmd",
139414
+ /* 275 */ "cmdlist ::= ecmd",
139415
+ /* 276 */ "ecmd ::= SEMI",
139416
+ /* 277 */ "ecmd ::= explain cmdx SEMI",
139417
+ /* 278 */ "explain ::=",
139418
+ /* 279 */ "trans_opt ::=",
139419
+ /* 280 */ "trans_opt ::= TRANSACTION",
139420
+ /* 281 */ "trans_opt ::= TRANSACTION nm",
139421
+ /* 282 */ "savepoint_opt ::= SAVEPOINT",
139422
+ /* 283 */ "savepoint_opt ::=",
139423
+ /* 284 */ "cmd ::= create_table create_table_args",
139424
+ /* 285 */ "columnlist ::= columnlist COMMA columnname carglist",
139425
+ /* 286 */ "columnlist ::= columnname carglist",
139426
+ /* 287 */ "nm ::= ID|INDEXED",
139427
+ /* 288 */ "nm ::= STRING",
139428
+ /* 289 */ "nm ::= JOIN_KW",
139429
+ /* 290 */ "typetoken ::= typename",
139430
+ /* 291 */ "typename ::= ID|STRING",
139431
+ /* 292 */ "signed ::= plus_num",
139432
+ /* 293 */ "signed ::= minus_num",
139433
+ /* 294 */ "carglist ::= carglist ccons",
139434
+ /* 295 */ "carglist ::=",
139435
+ /* 296 */ "ccons ::= NULL onconf",
139436
+ /* 297 */ "conslist_opt ::= COMMA conslist",
139437
+ /* 298 */ "conslist ::= conslist tconscomma tcons",
139438
+ /* 299 */ "conslist ::= tcons",
139439
+ /* 300 */ "tconscomma ::=",
139440
+ /* 301 */ "defer_subclause_opt ::= defer_subclause",
139441
+ /* 302 */ "resolvetype ::= raisetype",
139442
+ /* 303 */ "selectnowith ::= oneselect",
139443
+ /* 304 */ "oneselect ::= values",
139444
+ /* 305 */ "sclp ::= selcollist COMMA",
139445
+ /* 306 */ "as ::= ID|STRING",
139446
+ /* 307 */ "expr ::= term",
139447
+ /* 308 */ "likeop ::= LIKE_KW|MATCH",
139448
+ /* 309 */ "exprlist ::= nexprlist",
139449
+ /* 310 */ "nmnum ::= plus_num",
139450
+ /* 311 */ "nmnum ::= nm",
139451
+ /* 312 */ "nmnum ::= ON",
139452
+ /* 313 */ "nmnum ::= DELETE",
139453
+ /* 314 */ "nmnum ::= DEFAULT",
139454
+ /* 315 */ "plus_num ::= INTEGER|FLOAT",
139455
+ /* 316 */ "foreach_clause ::=",
139456
+ /* 317 */ "foreach_clause ::= FOR EACH ROW",
139457
+ /* 318 */ "trnm ::= nm",
139458
+ /* 319 */ "tridxby ::=",
139459
+ /* 320 */ "database_kw_opt ::= DATABASE",
139460
+ /* 321 */ "database_kw_opt ::=",
139461
+ /* 322 */ "kwcolumn_opt ::=",
139462
+ /* 323 */ "kwcolumn_opt ::= COLUMNKW",
139463
+ /* 324 */ "vtabarglist ::= vtabarg",
139464
+ /* 325 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
139465
+ /* 326 */ "vtabarg ::= vtabarg vtabargtoken",
139466
+ /* 327 */ "anylist ::=",
139467
+ /* 328 */ "anylist ::= anylist LP anylist RP",
139468
+ /* 329 */ "anylist ::= anylist ANY",
139090139469
};
139091139470
#endif /* NDEBUG */
139092139471
139093139472
139094139473
#if YYSTACKDEPTH<=0
@@ -139206,80 +139585,76 @@
139206139585
** which appear on the RHS of the rule, but which are *not* used
139207139586
** inside the C code.
139208139587
*/
139209139588
/********* Begin destructor definitions ***************************************/
139210139589
case 163: /* select */
139211
- case 194: /* selectnowith */
139212
- case 195: /* oneselect */
139213
- case 206: /* values */
139214
-{
139215
-sqlite3SelectDelete(pParse->db, (yypminor->yy243));
139216
-}
139217
- break;
139218
- case 172: /* term */
139219
- case 173: /* expr */
139220
-{
139221
-sqlite3ExprDelete(pParse->db, (yypminor->yy190).pExpr);
139222
-}
139223
- break;
139224
- case 177: /* eidlist_opt */
139225
- case 186: /* sortlist */
139226
- case 187: /* eidlist */
139227
- case 199: /* selcollist */
139228
- case 202: /* groupby_opt */
139229
- case 204: /* orderby_opt */
139230
- case 207: /* nexprlist */
139231
- case 208: /* exprlist */
139232
- case 209: /* sclp */
139233
- case 218: /* setlist */
139234
- case 224: /* paren_exprlist */
139235
- case 226: /* case_exprlist */
139236
-{
139237
-sqlite3ExprListDelete(pParse->db, (yypminor->yy148));
139238
-}
139239
- break;
139240
- case 193: /* fullname */
139241
- case 200: /* from */
139242
- case 211: /* seltablist */
139243
- case 212: /* stl_prefix */
139244
-{
139245
-sqlite3SrcListDelete(pParse->db, (yypminor->yy185));
139246
-}
139247
- break;
139248
- case 196: /* with */
139249
- case 250: /* wqlist */
139250
-{
139251
-sqlite3WithDelete(pParse->db, (yypminor->yy285));
139252
-}
139253
- break;
139254
- case 201: /* where_opt */
139255
- case 203: /* having_opt */
139256
- case 215: /* on_opt */
139257
- case 225: /* case_operand */
139258
- case 227: /* case_else */
139259
- case 236: /* when_clause */
139260
- case 241: /* key_opt */
139261
-{
139262
-sqlite3ExprDelete(pParse->db, (yypminor->yy72));
139263
-}
139264
- break;
139265
- case 216: /* using_opt */
139266
- case 217: /* idlist */
139267
- case 220: /* idlist_opt */
139268
-{
139269
-sqlite3IdListDelete(pParse->db, (yypminor->yy254));
139270
-}
139271
- break;
139272
- case 232: /* trigger_cmd_list */
139273
- case 237: /* trigger_cmd */
139274
-{
139275
-sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy145));
139276
-}
139277
- break;
139278
- case 234: /* trigger_event */
139279
-{
139280
-sqlite3IdListDelete(pParse->db, (yypminor->yy332).b);
139590
+ case 195: /* selectnowith */
139591
+ case 196: /* oneselect */
139592
+ case 207: /* values */
139593
+{
139594
+sqlite3SelectDelete(pParse->db, (yypminor->yy387));
139595
+}
139596
+ break;
139597
+ case 173: /* term */
139598
+ case 174: /* expr */
139599
+ case 202: /* where_opt */
139600
+ case 204: /* having_opt */
139601
+ case 216: /* on_opt */
139602
+ case 226: /* case_operand */
139603
+ case 228: /* case_else */
139604
+ case 237: /* when_clause */
139605
+ case 242: /* key_opt */
139606
+{
139607
+sqlite3ExprDelete(pParse->db, (yypminor->yy314));
139608
+}
139609
+ break;
139610
+ case 178: /* eidlist_opt */
139611
+ case 187: /* sortlist */
139612
+ case 188: /* eidlist */
139613
+ case 200: /* selcollist */
139614
+ case 203: /* groupby_opt */
139615
+ case 205: /* orderby_opt */
139616
+ case 208: /* nexprlist */
139617
+ case 209: /* exprlist */
139618
+ case 210: /* sclp */
139619
+ case 219: /* setlist */
139620
+ case 225: /* paren_exprlist */
139621
+ case 227: /* case_exprlist */
139622
+{
139623
+sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
139624
+}
139625
+ break;
139626
+ case 194: /* fullname */
139627
+ case 201: /* from */
139628
+ case 212: /* seltablist */
139629
+ case 213: /* stl_prefix */
139630
+{
139631
+sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
139632
+}
139633
+ break;
139634
+ case 197: /* with */
139635
+ case 251: /* wqlist */
139636
+{
139637
+sqlite3WithDelete(pParse->db, (yypminor->yy451));
139638
+}
139639
+ break;
139640
+ case 217: /* using_opt */
139641
+ case 218: /* idlist */
139642
+ case 221: /* idlist_opt */
139643
+{
139644
+sqlite3IdListDelete(pParse->db, (yypminor->yy384));
139645
+}
139646
+ break;
139647
+ case 233: /* trigger_cmd_list */
139648
+ case 238: /* trigger_cmd */
139649
+{
139650
+sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
139651
+}
139652
+ break;
139653
+ case 235: /* trigger_event */
139654
+{
139655
+sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
139281139656
}
139282139657
break;
139283139658
/********* End destructor definitions *****************************************/
139284139659
default: break; /* If no destructor action specified: do nothing */
139285139660
}
@@ -139346,10 +139721,47 @@
139346139721
yyParser *pParser = (yyParser*)p;
139347139722
return pParser->yyhwm;
139348139723
}
139349139724
#endif
139350139725
139726
+/* This array of booleans keeps track of the parser statement
139727
+** coverage. The element yycoverage[X][Y] is set when the parser
139728
+** is in state X and has a lookahead token Y. In a well-tested
139729
+** systems, every element of this matrix should end up being set.
139730
+*/
139731
+#if defined(YYCOVERAGE)
139732
+static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
139733
+#endif
139734
+
139735
+/*
139736
+** Write into out a description of every state/lookahead combination that
139737
+**
139738
+** (1) has not been used by the parser, and
139739
+** (2) is not a syntax error.
139740
+**
139741
+** Return the number of missed state/lookahead combinations.
139742
+*/
139743
+#if defined(YYCOVERAGE)
139744
+SQLITE_PRIVATE int sqlite3ParserCoverage(FILE *out){
139745
+ int stateno, iLookAhead, i;
139746
+ int nMissed = 0;
139747
+ for(stateno=0; stateno<YYNSTATE; stateno++){
139748
+ i = yy_shift_ofst[stateno];
139749
+ for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
139750
+ if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
139751
+ if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
139752
+ if( out ){
139753
+ fprintf(out,"State %d lookahead %s %s\n", stateno,
139754
+ yyTokenName[iLookAhead],
139755
+ yycoverage[stateno][iLookAhead] ? "ok" : "missed");
139756
+ }
139757
+ }
139758
+ }
139759
+ return nMissed;
139760
+}
139761
+#endif
139762
+
139351139763
/*
139352139764
** Find the appropriate action for a parser given the terminal
139353139765
** look-ahead token iLookAhead.
139354139766
*/
139355139767
static unsigned int yy_find_shift_action(
@@ -139357,17 +139769,22 @@
139357139769
YYCODETYPE iLookAhead /* The look-ahead token */
139358139770
){
139359139771
int i;
139360139772
int stateno = pParser->yytos->stateno;
139361139773
139362
- if( stateno>=YY_MIN_REDUCE ) return stateno;
139774
+ if( stateno>YY_MAX_SHIFT ) return stateno;
139363139775
assert( stateno <= YY_SHIFT_COUNT );
139776
+#if defined(YYCOVERAGE)
139777
+ yycoverage[stateno][iLookAhead] = 1;
139778
+#endif
139364139779
do{
139365139780
i = yy_shift_ofst[stateno];
139781
+ assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
139366139782
assert( iLookAhead!=YYNOCODE );
139783
+ assert( iLookAhead < YYNTOKEN );
139367139784
i += iLookAhead;
139368
- if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
139785
+ if( yy_lookahead[i]!=iLookAhead ){
139369139786
#ifdef YYFALLBACK
139370139787
YYCODETYPE iFallback; /* Fallback token */
139371139788
if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
139372139789
&& (iFallback = yyFallback[iLookAhead])!=0 ){
139373139790
#ifndef NDEBUG
@@ -139426,11 +139843,10 @@
139426139843
}
139427139844
#else
139428139845
assert( stateno<=YY_REDUCE_COUNT );
139429139846
#endif
139430139847
i = yy_reduce_ofst[stateno];
139431
- assert( i!=YY_REDUCE_USE_DFLT );
139432139848
assert( iLookAhead!=YYNOCODE );
139433139849
i += iLookAhead;
139434139850
#ifdef YYERRORSYMBOL
139435139851
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
139436139852
return yy_default[stateno];
@@ -139464,24 +139880,25 @@
139464139880
139465139881
/*
139466139882
** Print tracing information for a SHIFT action
139467139883
*/
139468139884
#ifndef NDEBUG
139469
-static void yyTraceShift(yyParser *yypParser, int yyNewState){
139885
+static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
139470139886
if( yyTraceFILE ){
139471139887
if( yyNewState<YYNSTATE ){
139472
- fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n",
139473
- yyTracePrompt,yyTokenName[yypParser->yytos->major],
139888
+ fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
139889
+ yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
139474139890
yyNewState);
139475139891
}else{
139476
- fprintf(yyTraceFILE,"%sShift '%s'\n",
139477
- yyTracePrompt,yyTokenName[yypParser->yytos->major]);
139892
+ fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
139893
+ yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
139894
+ yyNewState - YY_MIN_REDUCE);
139478139895
}
139479139896
}
139480139897
}
139481139898
#else
139482
-# define yyTraceShift(X,Y)
139899
+# define yyTraceShift(X,Y,Z)
139483139900
#endif
139484139901
139485139902
/*
139486139903
** Perform a shift action.
139487139904
*/
@@ -139519,360 +139936,369 @@
139519139936
}
139520139937
yytos = yypParser->yytos;
139521139938
yytos->stateno = (YYACTIONTYPE)yyNewState;
139522139939
yytos->major = (YYCODETYPE)yyMajor;
139523139940
yytos->minor.yy0 = yyMinor;
139524
- yyTraceShift(yypParser, yyNewState);
139941
+ yyTraceShift(yypParser, yyNewState, "Shift");
139525139942
}
139526139943
139527139944
/* The following table contains information about every rule that
139528139945
** is used during the reduce.
139529139946
*/
139530139947
static const struct {
139531139948
YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
139532139949
signed char nrhs; /* Negative of the number of RHS symbols in the rule */
139533139950
} yyRuleInfo[] = {
139534
- { 147, -1 },
139535
- { 147, -3 },
139536
- { 148, -1 },
139537
- { 149, -3 },
139538
- { 150, 0 },
139539
- { 150, -1 },
139540
- { 150, -1 },
139541
- { 150, -1 },
139542
- { 149, -2 },
139543
- { 149, -2 },
139544
- { 149, -2 },
139545
- { 149, -3 },
139546
- { 149, -5 },
139547
- { 154, -6 },
139548
- { 156, -1 },
139549
- { 158, 0 },
139550
- { 158, -3 },
139551
- { 157, -1 },
139552
- { 157, 0 },
139553
- { 155, -5 },
139554
- { 155, -2 },
139555
- { 162, 0 },
139556
- { 162, -2 },
139557
- { 164, -2 },
139558
- { 166, 0 },
139559
- { 166, -4 },
139560
- { 166, -6 },
139561
- { 167, -2 },
139562
- { 171, -2 },
139563
- { 171, -2 },
139564
- { 171, -4 },
139565
- { 171, -3 },
139566
- { 171, -3 },
139567
- { 171, -2 },
139568
- { 171, -3 },
139569
- { 171, -5 },
139570
- { 171, -2 },
139571
- { 171, -4 },
139572
- { 171, -4 },
139573
- { 171, -1 },
139574
- { 171, -2 },
139575
- { 176, 0 },
139576
- { 176, -1 },
139577
- { 178, 0 },
139578
- { 178, -2 },
139579
- { 180, -2 },
139580
- { 180, -3 },
139581
- { 180, -3 },
139582
- { 180, -3 },
139583
- { 181, -2 },
139584
- { 181, -2 },
139585
- { 181, -1 },
139586
- { 181, -1 },
139587
- { 181, -2 },
139588
- { 179, -3 },
139589
- { 179, -2 },
139590
- { 182, 0 },
139591
- { 182, -2 },
139592
- { 182, -2 },
139593
- { 161, 0 },
139594
- { 184, -1 },
139595
- { 185, -2 },
139596
- { 185, -7 },
139597
- { 185, -5 },
139598
- { 185, -5 },
139599
- { 185, -10 },
139600
- { 188, 0 },
139601
- { 174, 0 },
139602
- { 174, -3 },
139603
- { 189, 0 },
139604
- { 189, -2 },
139605
- { 190, -1 },
139606
- { 190, -1 },
139607
- { 149, -4 },
139608
- { 192, -2 },
139609
- { 192, 0 },
139610
- { 149, -9 },
139611
- { 149, -4 },
139612
- { 149, -1 },
139613
- { 163, -2 },
139614
- { 194, -3 },
139615
- { 197, -1 },
139616
- { 197, -2 },
139617
- { 197, -1 },
139618
- { 195, -9 },
139619
- { 206, -4 },
139620
- { 206, -5 },
139621
- { 198, -1 },
139622
- { 198, -1 },
139623
- { 198, 0 },
139624
- { 209, 0 },
139625
- { 199, -3 },
139626
- { 199, -2 },
139627
- { 199, -4 },
139628
- { 210, -2 },
139629
- { 210, 0 },
139630
- { 200, 0 },
139631
- { 200, -2 },
139632
- { 212, -2 },
139633
- { 212, 0 },
139634
- { 211, -7 },
139635
- { 211, -9 },
139636
- { 211, -7 },
139637
- { 211, -7 },
139638
- { 159, 0 },
139639
- { 159, -2 },
139640
- { 193, -2 },
139641
- { 213, -1 },
139642
- { 213, -2 },
139643
- { 213, -3 },
139644
- { 213, -4 },
139645
- { 215, -2 },
139646
- { 215, 0 },
139647
- { 214, 0 },
139648
- { 214, -3 },
139649
- { 214, -2 },
139650
- { 216, -4 },
139651
- { 216, 0 },
139652
- { 204, 0 },
139653
- { 204, -3 },
139654
- { 186, -4 },
139655
- { 186, -2 },
139656
- { 175, -1 },
139657
- { 175, -1 },
139658
- { 175, 0 },
139659
- { 202, 0 },
139660
- { 202, -3 },
139661
- { 203, 0 },
139662
- { 203, -2 },
139663
- { 205, 0 },
139664
- { 205, -2 },
139665
- { 205, -4 },
139666
- { 205, -4 },
139667
- { 149, -6 },
139668
- { 201, 0 },
139669
- { 201, -2 },
139670
- { 149, -8 },
139671
- { 218, -5 },
139672
- { 218, -7 },
139673
- { 218, -3 },
139674
- { 218, -5 },
139675
- { 149, -6 },
139676
- { 149, -7 },
139677
- { 219, -2 },
139678
- { 219, -1 },
139679
- { 220, 0 },
139680
- { 220, -3 },
139681
- { 217, -3 },
139682
- { 217, -1 },
139683
- { 173, -3 },
139684
- { 173, -1 },
139685
- { 173, -1 },
139686
- { 173, -3 },
139687
- { 173, -5 },
139688
- { 172, -1 },
139689
- { 172, -1 },
139690
- { 172, -1 },
139691
- { 173, -1 },
139692
- { 173, -3 },
139693
- { 173, -6 },
139694
- { 173, -5 },
139695
- { 173, -4 },
139696
- { 172, -1 },
139697
- { 173, -5 },
139698
- { 173, -3 },
139699
- { 173, -3 },
139700
- { 173, -3 },
139701
- { 173, -3 },
139702
- { 173, -3 },
139703
- { 173, -3 },
139704
- { 173, -3 },
139705
- { 173, -3 },
139706
- { 221, -2 },
139707
- { 173, -3 },
139708
- { 173, -5 },
139709
- { 173, -2 },
139710
- { 173, -3 },
139711
- { 173, -3 },
139712
- { 173, -4 },
139713
- { 173, -2 },
139714
- { 173, -2 },
139715
- { 173, -2 },
139716
- { 173, -2 },
139717
- { 222, -1 },
139718
- { 222, -2 },
139719
- { 173, -5 },
139720
- { 223, -1 },
139721
- { 223, -2 },
139722
- { 173, -5 },
139723
- { 173, -3 },
139724
- { 173, -5 },
139725
- { 173, -5 },
139726
- { 173, -4 },
139727
- { 173, -5 },
139728
- { 226, -5 },
139729
- { 226, -4 },
139730
- { 227, -2 },
139731
- { 227, 0 },
139732
- { 225, -1 },
139733
- { 225, 0 },
139734
- { 208, 0 },
139735
- { 207, -3 },
139736
- { 207, -1 },
139737
- { 224, 0 },
139738
- { 224, -3 },
139739
- { 149, -12 },
139740
- { 228, -1 },
139741
- { 228, 0 },
139742
- { 177, 0 },
139743
- { 177, -3 },
139744
- { 187, -5 },
139745
- { 187, -3 },
139746
- { 229, 0 },
139747
- { 229, -2 },
139748
- { 149, -4 },
139749
- { 149, -1 },
139750
- { 149, -2 },
139751
- { 149, -3 },
139752
- { 149, -5 },
139753
- { 149, -6 },
139754
- { 149, -5 },
139755
- { 149, -6 },
139756
- { 169, -2 },
139757
- { 170, -2 },
139758
- { 149, -5 },
139759
- { 231, -11 },
139760
- { 233, -1 },
139761
- { 233, -2 },
139762
- { 233, 0 },
139763
- { 234, -1 },
139764
- { 234, -1 },
139765
- { 234, -3 },
139766
- { 236, 0 },
139767
- { 236, -2 },
139768
- { 232, -3 },
139769
- { 232, -2 },
139770
- { 238, -3 },
139771
- { 239, -3 },
139772
- { 239, -2 },
139773
- { 237, -7 },
139774
- { 237, -5 },
139775
- { 237, -5 },
139776
- { 237, -1 },
139777
- { 173, -4 },
139778
- { 173, -6 },
139779
- { 191, -1 },
139780
- { 191, -1 },
139781
- { 191, -1 },
139782
- { 149, -4 },
139783
- { 149, -6 },
139784
- { 149, -3 },
139785
- { 241, 0 },
139786
- { 241, -2 },
139787
- { 149, -1 },
139788
- { 149, -3 },
139789
- { 149, -1 },
139790
- { 149, -3 },
139791
- { 149, -6 },
139792
- { 149, -7 },
139793
- { 242, -1 },
139794
- { 149, -1 },
139795
- { 149, -4 },
139796
- { 244, -8 },
139797
- { 246, 0 },
139798
- { 247, -1 },
139799
- { 247, -3 },
139800
- { 248, -1 },
139801
- { 196, 0 },
139802
- { 196, -2 },
139803
- { 196, -3 },
139804
- { 250, -6 },
139805
- { 250, -8 },
139806
- { 144, -1 },
139807
- { 145, -2 },
139808
- { 145, -1 },
139809
- { 146, -1 },
139810
- { 146, -3 },
139811
- { 147, 0 },
139812
- { 151, 0 },
139813
- { 151, -1 },
139814
- { 151, -2 },
139815
- { 153, -1 },
139816
- { 153, 0 },
139817
- { 149, -2 },
139818
- { 160, -4 },
139819
- { 160, -2 },
139820
- { 152, -1 },
139821
- { 152, -1 },
139822
- { 152, -1 },
139823
- { 166, -1 },
139824
- { 167, -1 },
139825
- { 168, -1 },
139826
- { 168, -1 },
139827
- { 165, -2 },
139828
- { 165, 0 },
139829
- { 171, -2 },
139830
- { 161, -2 },
139831
- { 183, -3 },
139832
- { 183, -1 },
139833
- { 184, 0 },
139834
- { 188, -1 },
139835
- { 190, -1 },
139836
- { 194, -1 },
139837
- { 195, -1 },
139838
- { 209, -2 },
139839
- { 210, -1 },
139840
- { 173, -1 },
139841
- { 221, -1 },
139842
- { 208, -1 },
139843
- { 230, -1 },
139844
- { 230, -1 },
139845
- { 230, -1 },
139846
- { 230, -1 },
139847
- { 230, -1 },
139848
- { 169, -1 },
139849
- { 235, 0 },
139850
- { 235, -3 },
139851
- { 238, -1 },
139852
- { 239, 0 },
139853
- { 240, -1 },
139854
- { 240, 0 },
139855
- { 243, 0 },
139856
- { 243, -1 },
139857
- { 245, -1 },
139858
- { 245, -3 },
139859
- { 246, -2 },
139860
- { 249, 0 },
139861
- { 249, -4 },
139862
- { 249, -2 },
139951
+ { 147, -1 }, /* (0) explain ::= EXPLAIN */
139952
+ { 147, -3 }, /* (1) explain ::= EXPLAIN QUERY PLAN */
139953
+ { 148, -1 }, /* (2) cmdx ::= cmd */
139954
+ { 149, -3 }, /* (3) cmd ::= BEGIN transtype trans_opt */
139955
+ { 150, 0 }, /* (4) transtype ::= */
139956
+ { 150, -1 }, /* (5) transtype ::= DEFERRED */
139957
+ { 150, -1 }, /* (6) transtype ::= IMMEDIATE */
139958
+ { 150, -1 }, /* (7) transtype ::= EXCLUSIVE */
139959
+ { 149, -2 }, /* (8) cmd ::= COMMIT|END trans_opt */
139960
+ { 149, -2 }, /* (9) cmd ::= ROLLBACK trans_opt */
139961
+ { 149, -2 }, /* (10) cmd ::= SAVEPOINT nm */
139962
+ { 149, -3 }, /* (11) cmd ::= RELEASE savepoint_opt nm */
139963
+ { 149, -5 }, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
139964
+ { 154, -6 }, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
139965
+ { 156, -1 }, /* (14) createkw ::= CREATE */
139966
+ { 158, 0 }, /* (15) ifnotexists ::= */
139967
+ { 158, -3 }, /* (16) ifnotexists ::= IF NOT EXISTS */
139968
+ { 157, -1 }, /* (17) temp ::= TEMP */
139969
+ { 157, 0 }, /* (18) temp ::= */
139970
+ { 155, -5 }, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
139971
+ { 155, -2 }, /* (20) create_table_args ::= AS select */
139972
+ { 162, 0 }, /* (21) table_options ::= */
139973
+ { 162, -2 }, /* (22) table_options ::= WITHOUT nm */
139974
+ { 164, -2 }, /* (23) columnname ::= nm typetoken */
139975
+ { 166, 0 }, /* (24) typetoken ::= */
139976
+ { 166, -4 }, /* (25) typetoken ::= typename LP signed RP */
139977
+ { 166, -6 }, /* (26) typetoken ::= typename LP signed COMMA signed RP */
139978
+ { 167, -2 }, /* (27) typename ::= typename ID|STRING */
139979
+ { 171, 0 }, /* (28) scanpt ::= */
139980
+ { 172, -2 }, /* (29) ccons ::= CONSTRAINT nm */
139981
+ { 172, -4 }, /* (30) ccons ::= DEFAULT scanpt term scanpt */
139982
+ { 172, -4 }, /* (31) ccons ::= DEFAULT LP expr RP */
139983
+ { 172, -4 }, /* (32) ccons ::= DEFAULT PLUS term scanpt */
139984
+ { 172, -4 }, /* (33) ccons ::= DEFAULT MINUS term scanpt */
139985
+ { 172, -3 }, /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */
139986
+ { 172, -3 }, /* (35) ccons ::= NOT NULL onconf */
139987
+ { 172, -5 }, /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */
139988
+ { 172, -2 }, /* (37) ccons ::= UNIQUE onconf */
139989
+ { 172, -4 }, /* (38) ccons ::= CHECK LP expr RP */
139990
+ { 172, -4 }, /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */
139991
+ { 172, -1 }, /* (40) ccons ::= defer_subclause */
139992
+ { 172, -2 }, /* (41) ccons ::= COLLATE ID|STRING */
139993
+ { 177, 0 }, /* (42) autoinc ::= */
139994
+ { 177, -1 }, /* (43) autoinc ::= AUTOINCR */
139995
+ { 179, 0 }, /* (44) refargs ::= */
139996
+ { 179, -2 }, /* (45) refargs ::= refargs refarg */
139997
+ { 181, -2 }, /* (46) refarg ::= MATCH nm */
139998
+ { 181, -3 }, /* (47) refarg ::= ON INSERT refact */
139999
+ { 181, -3 }, /* (48) refarg ::= ON DELETE refact */
140000
+ { 181, -3 }, /* (49) refarg ::= ON UPDATE refact */
140001
+ { 182, -2 }, /* (50) refact ::= SET NULL */
140002
+ { 182, -2 }, /* (51) refact ::= SET DEFAULT */
140003
+ { 182, -1 }, /* (52) refact ::= CASCADE */
140004
+ { 182, -1 }, /* (53) refact ::= RESTRICT */
140005
+ { 182, -2 }, /* (54) refact ::= NO ACTION */
140006
+ { 180, -3 }, /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
140007
+ { 180, -2 }, /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
140008
+ { 183, 0 }, /* (57) init_deferred_pred_opt ::= */
140009
+ { 183, -2 }, /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */
140010
+ { 183, -2 }, /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
140011
+ { 161, 0 }, /* (60) conslist_opt ::= */
140012
+ { 185, -1 }, /* (61) tconscomma ::= COMMA */
140013
+ { 186, -2 }, /* (62) tcons ::= CONSTRAINT nm */
140014
+ { 186, -7 }, /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
140015
+ { 186, -5 }, /* (64) tcons ::= UNIQUE LP sortlist RP onconf */
140016
+ { 186, -5 }, /* (65) tcons ::= CHECK LP expr RP onconf */
140017
+ { 186, -10 }, /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
140018
+ { 189, 0 }, /* (67) defer_subclause_opt ::= */
140019
+ { 175, 0 }, /* (68) onconf ::= */
140020
+ { 175, -3 }, /* (69) onconf ::= ON CONFLICT resolvetype */
140021
+ { 190, 0 }, /* (70) orconf ::= */
140022
+ { 190, -2 }, /* (71) orconf ::= OR resolvetype */
140023
+ { 191, -1 }, /* (72) resolvetype ::= IGNORE */
140024
+ { 191, -1 }, /* (73) resolvetype ::= REPLACE */
140025
+ { 149, -4 }, /* (74) cmd ::= DROP TABLE ifexists fullname */
140026
+ { 193, -2 }, /* (75) ifexists ::= IF EXISTS */
140027
+ { 193, 0 }, /* (76) ifexists ::= */
140028
+ { 149, -9 }, /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
140029
+ { 149, -4 }, /* (78) cmd ::= DROP VIEW ifexists fullname */
140030
+ { 149, -1 }, /* (79) cmd ::= select */
140031
+ { 163, -2 }, /* (80) select ::= with selectnowith */
140032
+ { 195, -3 }, /* (81) selectnowith ::= selectnowith multiselect_op oneselect */
140033
+ { 198, -1 }, /* (82) multiselect_op ::= UNION */
140034
+ { 198, -2 }, /* (83) multiselect_op ::= UNION ALL */
140035
+ { 198, -1 }, /* (84) multiselect_op ::= EXCEPT|INTERSECT */
140036
+ { 196, -9 }, /* (85) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
140037
+ { 207, -4 }, /* (86) values ::= VALUES LP nexprlist RP */
140038
+ { 207, -5 }, /* (87) values ::= values COMMA LP exprlist RP */
140039
+ { 199, -1 }, /* (88) distinct ::= DISTINCT */
140040
+ { 199, -1 }, /* (89) distinct ::= ALL */
140041
+ { 199, 0 }, /* (90) distinct ::= */
140042
+ { 210, 0 }, /* (91) sclp ::= */
140043
+ { 200, -5 }, /* (92) selcollist ::= sclp scanpt expr scanpt as */
140044
+ { 200, -3 }, /* (93) selcollist ::= sclp scanpt STAR */
140045
+ { 200, -5 }, /* (94) selcollist ::= sclp scanpt nm DOT STAR */
140046
+ { 211, -2 }, /* (95) as ::= AS nm */
140047
+ { 211, 0 }, /* (96) as ::= */
140048
+ { 201, 0 }, /* (97) from ::= */
140049
+ { 201, -2 }, /* (98) from ::= FROM seltablist */
140050
+ { 213, -2 }, /* (99) stl_prefix ::= seltablist joinop */
140051
+ { 213, 0 }, /* (100) stl_prefix ::= */
140052
+ { 212, -7 }, /* (101) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
140053
+ { 212, -9 }, /* (102) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
140054
+ { 212, -7 }, /* (103) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
140055
+ { 212, -7 }, /* (104) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
140056
+ { 159, 0 }, /* (105) dbnm ::= */
140057
+ { 159, -2 }, /* (106) dbnm ::= DOT nm */
140058
+ { 194, -2 }, /* (107) fullname ::= nm dbnm */
140059
+ { 214, -1 }, /* (108) joinop ::= COMMA|JOIN */
140060
+ { 214, -2 }, /* (109) joinop ::= JOIN_KW JOIN */
140061
+ { 214, -3 }, /* (110) joinop ::= JOIN_KW nm JOIN */
140062
+ { 214, -4 }, /* (111) joinop ::= JOIN_KW nm nm JOIN */
140063
+ { 216, -2 }, /* (112) on_opt ::= ON expr */
140064
+ { 216, 0 }, /* (113) on_opt ::= */
140065
+ { 215, 0 }, /* (114) indexed_opt ::= */
140066
+ { 215, -3 }, /* (115) indexed_opt ::= INDEXED BY nm */
140067
+ { 215, -2 }, /* (116) indexed_opt ::= NOT INDEXED */
140068
+ { 217, -4 }, /* (117) using_opt ::= USING LP idlist RP */
140069
+ { 217, 0 }, /* (118) using_opt ::= */
140070
+ { 205, 0 }, /* (119) orderby_opt ::= */
140071
+ { 205, -3 }, /* (120) orderby_opt ::= ORDER BY sortlist */
140072
+ { 187, -4 }, /* (121) sortlist ::= sortlist COMMA expr sortorder */
140073
+ { 187, -2 }, /* (122) sortlist ::= expr sortorder */
140074
+ { 176, -1 }, /* (123) sortorder ::= ASC */
140075
+ { 176, -1 }, /* (124) sortorder ::= DESC */
140076
+ { 176, 0 }, /* (125) sortorder ::= */
140077
+ { 203, 0 }, /* (126) groupby_opt ::= */
140078
+ { 203, -3 }, /* (127) groupby_opt ::= GROUP BY nexprlist */
140079
+ { 204, 0 }, /* (128) having_opt ::= */
140080
+ { 204, -2 }, /* (129) having_opt ::= HAVING expr */
140081
+ { 206, 0 }, /* (130) limit_opt ::= */
140082
+ { 206, -2 }, /* (131) limit_opt ::= LIMIT expr */
140083
+ { 206, -4 }, /* (132) limit_opt ::= LIMIT expr OFFSET expr */
140084
+ { 206, -4 }, /* (133) limit_opt ::= LIMIT expr COMMA expr */
140085
+ { 149, -6 }, /* (134) cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140086
+ { 202, 0 }, /* (135) where_opt ::= */
140087
+ { 202, -2 }, /* (136) where_opt ::= WHERE expr */
140088
+ { 149, -8 }, /* (137) cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140089
+ { 219, -5 }, /* (138) setlist ::= setlist COMMA nm EQ expr */
140090
+ { 219, -7 }, /* (139) setlist ::= setlist COMMA LP idlist RP EQ expr */
140091
+ { 219, -3 }, /* (140) setlist ::= nm EQ expr */
140092
+ { 219, -5 }, /* (141) setlist ::= LP idlist RP EQ expr */
140093
+ { 149, -6 }, /* (142) cmd ::= with insert_cmd INTO fullname idlist_opt select */
140094
+ { 149, -7 }, /* (143) cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
140095
+ { 220, -2 }, /* (144) insert_cmd ::= INSERT orconf */
140096
+ { 220, -1 }, /* (145) insert_cmd ::= REPLACE */
140097
+ { 221, 0 }, /* (146) idlist_opt ::= */
140098
+ { 221, -3 }, /* (147) idlist_opt ::= LP idlist RP */
140099
+ { 218, -3 }, /* (148) idlist ::= idlist COMMA nm */
140100
+ { 218, -1 }, /* (149) idlist ::= nm */
140101
+ { 174, -3 }, /* (150) expr ::= LP expr RP */
140102
+ { 174, -1 }, /* (151) expr ::= ID|INDEXED */
140103
+ { 174, -1 }, /* (152) expr ::= JOIN_KW */
140104
+ { 174, -3 }, /* (153) expr ::= nm DOT nm */
140105
+ { 174, -5 }, /* (154) expr ::= nm DOT nm DOT nm */
140106
+ { 173, -1 }, /* (155) term ::= NULL|FLOAT|BLOB */
140107
+ { 173, -1 }, /* (156) term ::= STRING */
140108
+ { 173, -1 }, /* (157) term ::= INTEGER */
140109
+ { 174, -1 }, /* (158) expr ::= VARIABLE */
140110
+ { 174, -3 }, /* (159) expr ::= expr COLLATE ID|STRING */
140111
+ { 174, -6 }, /* (160) expr ::= CAST LP expr AS typetoken RP */
140112
+ { 174, -5 }, /* (161) expr ::= ID|INDEXED LP distinct exprlist RP */
140113
+ { 174, -4 }, /* (162) expr ::= ID|INDEXED LP STAR RP */
140114
+ { 173, -1 }, /* (163) term ::= CTIME_KW */
140115
+ { 174, -5 }, /* (164) expr ::= LP nexprlist COMMA expr RP */
140116
+ { 174, -3 }, /* (165) expr ::= expr AND expr */
140117
+ { 174, -3 }, /* (166) expr ::= expr OR expr */
140118
+ { 174, -3 }, /* (167) expr ::= expr LT|GT|GE|LE expr */
140119
+ { 174, -3 }, /* (168) expr ::= expr EQ|NE expr */
140120
+ { 174, -3 }, /* (169) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
140121
+ { 174, -3 }, /* (170) expr ::= expr PLUS|MINUS expr */
140122
+ { 174, -3 }, /* (171) expr ::= expr STAR|SLASH|REM expr */
140123
+ { 174, -3 }, /* (172) expr ::= expr CONCAT expr */
140124
+ { 222, -2 }, /* (173) likeop ::= NOT LIKE_KW|MATCH */
140125
+ { 174, -3 }, /* (174) expr ::= expr likeop expr */
140126
+ { 174, -5 }, /* (175) expr ::= expr likeop expr ESCAPE expr */
140127
+ { 174, -2 }, /* (176) expr ::= expr ISNULL|NOTNULL */
140128
+ { 174, -3 }, /* (177) expr ::= expr NOT NULL */
140129
+ { 174, -3 }, /* (178) expr ::= expr IS expr */
140130
+ { 174, -4 }, /* (179) expr ::= expr IS NOT expr */
140131
+ { 174, -2 }, /* (180) expr ::= NOT expr */
140132
+ { 174, -2 }, /* (181) expr ::= BITNOT expr */
140133
+ { 174, -2 }, /* (182) expr ::= MINUS expr */
140134
+ { 174, -2 }, /* (183) expr ::= PLUS expr */
140135
+ { 223, -1 }, /* (184) between_op ::= BETWEEN */
140136
+ { 223, -2 }, /* (185) between_op ::= NOT BETWEEN */
140137
+ { 174, -5 }, /* (186) expr ::= expr between_op expr AND expr */
140138
+ { 224, -1 }, /* (187) in_op ::= IN */
140139
+ { 224, -2 }, /* (188) in_op ::= NOT IN */
140140
+ { 174, -5 }, /* (189) expr ::= expr in_op LP exprlist RP */
140141
+ { 174, -3 }, /* (190) expr ::= LP select RP */
140142
+ { 174, -5 }, /* (191) expr ::= expr in_op LP select RP */
140143
+ { 174, -5 }, /* (192) expr ::= expr in_op nm dbnm paren_exprlist */
140144
+ { 174, -4 }, /* (193) expr ::= EXISTS LP select RP */
140145
+ { 174, -5 }, /* (194) expr ::= CASE case_operand case_exprlist case_else END */
140146
+ { 227, -5 }, /* (195) case_exprlist ::= case_exprlist WHEN expr THEN expr */
140147
+ { 227, -4 }, /* (196) case_exprlist ::= WHEN expr THEN expr */
140148
+ { 228, -2 }, /* (197) case_else ::= ELSE expr */
140149
+ { 228, 0 }, /* (198) case_else ::= */
140150
+ { 226, -1 }, /* (199) case_operand ::= expr */
140151
+ { 226, 0 }, /* (200) case_operand ::= */
140152
+ { 209, 0 }, /* (201) exprlist ::= */
140153
+ { 208, -3 }, /* (202) nexprlist ::= nexprlist COMMA expr */
140154
+ { 208, -1 }, /* (203) nexprlist ::= expr */
140155
+ { 225, 0 }, /* (204) paren_exprlist ::= */
140156
+ { 225, -3 }, /* (205) paren_exprlist ::= LP exprlist RP */
140157
+ { 149, -12 }, /* (206) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
140158
+ { 229, -1 }, /* (207) uniqueflag ::= UNIQUE */
140159
+ { 229, 0 }, /* (208) uniqueflag ::= */
140160
+ { 178, 0 }, /* (209) eidlist_opt ::= */
140161
+ { 178, -3 }, /* (210) eidlist_opt ::= LP eidlist RP */
140162
+ { 188, -5 }, /* (211) eidlist ::= eidlist COMMA nm collate sortorder */
140163
+ { 188, -3 }, /* (212) eidlist ::= nm collate sortorder */
140164
+ { 230, 0 }, /* (213) collate ::= */
140165
+ { 230, -2 }, /* (214) collate ::= COLLATE ID|STRING */
140166
+ { 149, -4 }, /* (215) cmd ::= DROP INDEX ifexists fullname */
140167
+ { 149, -1 }, /* (216) cmd ::= VACUUM */
140168
+ { 149, -2 }, /* (217) cmd ::= VACUUM nm */
140169
+ { 149, -3 }, /* (218) cmd ::= PRAGMA nm dbnm */
140170
+ { 149, -5 }, /* (219) cmd ::= PRAGMA nm dbnm EQ nmnum */
140171
+ { 149, -6 }, /* (220) cmd ::= PRAGMA nm dbnm LP nmnum RP */
140172
+ { 149, -5 }, /* (221) cmd ::= PRAGMA nm dbnm EQ minus_num */
140173
+ { 149, -6 }, /* (222) cmd ::= PRAGMA nm dbnm LP minus_num RP */
140174
+ { 169, -2 }, /* (223) plus_num ::= PLUS INTEGER|FLOAT */
140175
+ { 170, -2 }, /* (224) minus_num ::= MINUS INTEGER|FLOAT */
140176
+ { 149, -5 }, /* (225) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
140177
+ { 232, -11 }, /* (226) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
140178
+ { 234, -1 }, /* (227) trigger_time ::= BEFORE|AFTER */
140179
+ { 234, -2 }, /* (228) trigger_time ::= INSTEAD OF */
140180
+ { 234, 0 }, /* (229) trigger_time ::= */
140181
+ { 235, -1 }, /* (230) trigger_event ::= DELETE|INSERT */
140182
+ { 235, -1 }, /* (231) trigger_event ::= UPDATE */
140183
+ { 235, -3 }, /* (232) trigger_event ::= UPDATE OF idlist */
140184
+ { 237, 0 }, /* (233) when_clause ::= */
140185
+ { 237, -2 }, /* (234) when_clause ::= WHEN expr */
140186
+ { 233, -3 }, /* (235) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
140187
+ { 233, -2 }, /* (236) trigger_cmd_list ::= trigger_cmd SEMI */
140188
+ { 239, -3 }, /* (237) trnm ::= nm DOT nm */
140189
+ { 240, -3 }, /* (238) tridxby ::= INDEXED BY nm */
140190
+ { 240, -2 }, /* (239) tridxby ::= NOT INDEXED */
140191
+ { 238, -8 }, /* (240) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
140192
+ { 238, -7 }, /* (241) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt */
140193
+ { 238, -6 }, /* (242) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
140194
+ { 238, -3 }, /* (243) trigger_cmd ::= scanpt select scanpt */
140195
+ { 174, -4 }, /* (244) expr ::= RAISE LP IGNORE RP */
140196
+ { 174, -6 }, /* (245) expr ::= RAISE LP raisetype COMMA nm RP */
140197
+ { 192, -1 }, /* (246) raisetype ::= ROLLBACK */
140198
+ { 192, -1 }, /* (247) raisetype ::= ABORT */
140199
+ { 192, -1 }, /* (248) raisetype ::= FAIL */
140200
+ { 149, -4 }, /* (249) cmd ::= DROP TRIGGER ifexists fullname */
140201
+ { 149, -6 }, /* (250) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
140202
+ { 149, -3 }, /* (251) cmd ::= DETACH database_kw_opt expr */
140203
+ { 242, 0 }, /* (252) key_opt ::= */
140204
+ { 242, -2 }, /* (253) key_opt ::= KEY expr */
140205
+ { 149, -1 }, /* (254) cmd ::= REINDEX */
140206
+ { 149, -3 }, /* (255) cmd ::= REINDEX nm dbnm */
140207
+ { 149, -1 }, /* (256) cmd ::= ANALYZE */
140208
+ { 149, -3 }, /* (257) cmd ::= ANALYZE nm dbnm */
140209
+ { 149, -6 }, /* (258) cmd ::= ALTER TABLE fullname RENAME TO nm */
140210
+ { 149, -7 }, /* (259) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
140211
+ { 243, -1 }, /* (260) add_column_fullname ::= fullname */
140212
+ { 149, -1 }, /* (261) cmd ::= create_vtab */
140213
+ { 149, -4 }, /* (262) cmd ::= create_vtab LP vtabarglist RP */
140214
+ { 245, -8 }, /* (263) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
140215
+ { 247, 0 }, /* (264) vtabarg ::= */
140216
+ { 248, -1 }, /* (265) vtabargtoken ::= ANY */
140217
+ { 248, -3 }, /* (266) vtabargtoken ::= lp anylist RP */
140218
+ { 249, -1 }, /* (267) lp ::= LP */
140219
+ { 197, 0 }, /* (268) with ::= */
140220
+ { 197, -2 }, /* (269) with ::= WITH wqlist */
140221
+ { 197, -3 }, /* (270) with ::= WITH RECURSIVE wqlist */
140222
+ { 251, -6 }, /* (271) wqlist ::= nm eidlist_opt AS LP select RP */
140223
+ { 251, -8 }, /* (272) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
140224
+ { 144, -1 }, /* (273) input ::= cmdlist */
140225
+ { 145, -2 }, /* (274) cmdlist ::= cmdlist ecmd */
140226
+ { 145, -1 }, /* (275) cmdlist ::= ecmd */
140227
+ { 146, -1 }, /* (276) ecmd ::= SEMI */
140228
+ { 146, -3 }, /* (277) ecmd ::= explain cmdx SEMI */
140229
+ { 147, 0 }, /* (278) explain ::= */
140230
+ { 151, 0 }, /* (279) trans_opt ::= */
140231
+ { 151, -1 }, /* (280) trans_opt ::= TRANSACTION */
140232
+ { 151, -2 }, /* (281) trans_opt ::= TRANSACTION nm */
140233
+ { 153, -1 }, /* (282) savepoint_opt ::= SAVEPOINT */
140234
+ { 153, 0 }, /* (283) savepoint_opt ::= */
140235
+ { 149, -2 }, /* (284) cmd ::= create_table create_table_args */
140236
+ { 160, -4 }, /* (285) columnlist ::= columnlist COMMA columnname carglist */
140237
+ { 160, -2 }, /* (286) columnlist ::= columnname carglist */
140238
+ { 152, -1 }, /* (287) nm ::= ID|INDEXED */
140239
+ { 152, -1 }, /* (288) nm ::= STRING */
140240
+ { 152, -1 }, /* (289) nm ::= JOIN_KW */
140241
+ { 166, -1 }, /* (290) typetoken ::= typename */
140242
+ { 167, -1 }, /* (291) typename ::= ID|STRING */
140243
+ { 168, -1 }, /* (292) signed ::= plus_num */
140244
+ { 168, -1 }, /* (293) signed ::= minus_num */
140245
+ { 165, -2 }, /* (294) carglist ::= carglist ccons */
140246
+ { 165, 0 }, /* (295) carglist ::= */
140247
+ { 172, -2 }, /* (296) ccons ::= NULL onconf */
140248
+ { 161, -2 }, /* (297) conslist_opt ::= COMMA conslist */
140249
+ { 184, -3 }, /* (298) conslist ::= conslist tconscomma tcons */
140250
+ { 184, -1 }, /* (299) conslist ::= tcons */
140251
+ { 185, 0 }, /* (300) tconscomma ::= */
140252
+ { 189, -1 }, /* (301) defer_subclause_opt ::= defer_subclause */
140253
+ { 191, -1 }, /* (302) resolvetype ::= raisetype */
140254
+ { 195, -1 }, /* (303) selectnowith ::= oneselect */
140255
+ { 196, -1 }, /* (304) oneselect ::= values */
140256
+ { 210, -2 }, /* (305) sclp ::= selcollist COMMA */
140257
+ { 211, -1 }, /* (306) as ::= ID|STRING */
140258
+ { 174, -1 }, /* (307) expr ::= term */
140259
+ { 222, -1 }, /* (308) likeop ::= LIKE_KW|MATCH */
140260
+ { 209, -1 }, /* (309) exprlist ::= nexprlist */
140261
+ { 231, -1 }, /* (310) nmnum ::= plus_num */
140262
+ { 231, -1 }, /* (311) nmnum ::= nm */
140263
+ { 231, -1 }, /* (312) nmnum ::= ON */
140264
+ { 231, -1 }, /* (313) nmnum ::= DELETE */
140265
+ { 231, -1 }, /* (314) nmnum ::= DEFAULT */
140266
+ { 169, -1 }, /* (315) plus_num ::= INTEGER|FLOAT */
140267
+ { 236, 0 }, /* (316) foreach_clause ::= */
140268
+ { 236, -3 }, /* (317) foreach_clause ::= FOR EACH ROW */
140269
+ { 239, -1 }, /* (318) trnm ::= nm */
140270
+ { 240, 0 }, /* (319) tridxby ::= */
140271
+ { 241, -1 }, /* (320) database_kw_opt ::= DATABASE */
140272
+ { 241, 0 }, /* (321) database_kw_opt ::= */
140273
+ { 244, 0 }, /* (322) kwcolumn_opt ::= */
140274
+ { 244, -1 }, /* (323) kwcolumn_opt ::= COLUMNKW */
140275
+ { 246, -1 }, /* (324) vtabarglist ::= vtabarg */
140276
+ { 246, -3 }, /* (325) vtabarglist ::= vtabarglist COMMA vtabarg */
140277
+ { 247, -2 }, /* (326) vtabarg ::= vtabarg vtabargtoken */
140278
+ { 250, 0 }, /* (327) anylist ::= */
140279
+ { 250, -4 }, /* (328) anylist ::= anylist LP anylist RP */
140280
+ { 250, -2 }, /* (329) anylist ::= anylist ANY */
139863140281
};
139864140282
139865140283
static void yy_accept(yyParser*); /* Forward Declaration */
139866140284
139867140285
/*
139868140286
** Perform a reduce action and the shift that must immediately
139869140287
** follow the reduce.
140288
+**
140289
+** The yyLookahead and yyLookaheadToken parameters provide reduce actions
140290
+** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
140291
+** if the lookahead token has already been consumed. As this procedure is
140292
+** only called from one place, optimizing compilers will in-line it, which
140293
+** means that the extra parameters have no performance impact.
139870140294
*/
139871140295
static void yy_reduce(
139872140296
yyParser *yypParser, /* The parser */
139873
- unsigned int yyruleno /* Number of the rule by which to reduce */
140297
+ unsigned int yyruleno, /* Number of the rule by which to reduce */
140298
+ int yyLookahead, /* Lookahead token, or YYNOCODE if none */
140299
+ sqlite3ParserTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
139874140300
){
139875140301
int yygoto; /* The next state */
139876140302
int yyact; /* The next action */
139877140303
yyStackEntry *yymsp; /* The top of the parser's stack */
139878140304
int yysize; /* Amount to pop the stack */
@@ -139879,12 +140305,18 @@
139879140305
sqlite3ParserARG_FETCH;
139880140306
yymsp = yypParser->yytos;
139881140307
#ifndef NDEBUG
139882140308
if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
139883140309
yysize = yyRuleInfo[yyruleno].nrhs;
139884
- fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
139885
- yyRuleName[yyruleno], yymsp[yysize].stateno);
140310
+ if( yysize ){
140311
+ fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
140312
+ yyTracePrompt,
140313
+ yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
140314
+ }else{
140315
+ fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
140316
+ yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
140317
+ }
139886140318
}
139887140319
#endif /* NDEBUG */
139888140320
139889140321
/* Check that the stack is large enough to grow by a single entry
139890140322
** if the RHS of the rule is empty. This ensures that there is room
@@ -139931,19 +140363,19 @@
139931140363
break;
139932140364
case 2: /* cmdx ::= cmd */
139933140365
{ sqlite3FinishCoding(pParse); }
139934140366
break;
139935140367
case 3: /* cmd ::= BEGIN transtype trans_opt */
139936
-{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy194);}
140368
+{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);}
139937140369
break;
139938140370
case 4: /* transtype ::= */
139939
-{yymsp[1].minor.yy194 = TK_DEFERRED;}
140371
+{yymsp[1].minor.yy4 = TK_DEFERRED;}
139940140372
break;
139941140373
case 5: /* transtype ::= DEFERRED */
139942140374
case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
139943140375
case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
139944
-{yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-X*/}
140376
+{yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-X*/}
139945140377
break;
139946140378
case 8: /* cmd ::= COMMIT|END trans_opt */
139947140379
case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
139948140380
{sqlite3EndTransaction(pParse,yymsp[-1].major);}
139949140381
break;
@@ -139962,61 +140394,61 @@
139962140394
sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
139963140395
}
139964140396
break;
139965140397
case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
139966140398
{
139967
- sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy194,0,0,yymsp[-2].minor.yy194);
140399
+ sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4);
139968140400
}
139969140401
break;
139970140402
case 14: /* createkw ::= CREATE */
139971140403
{disableLookaside(pParse);}
139972140404
break;
139973140405
case 15: /* ifnotexists ::= */
139974140406
case 18: /* temp ::= */ yytestcase(yyruleno==18);
139975140407
case 21: /* table_options ::= */ yytestcase(yyruleno==21);
139976
- case 41: /* autoinc ::= */ yytestcase(yyruleno==41);
139977
- case 56: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==56);
139978
- case 66: /* defer_subclause_opt ::= */ yytestcase(yyruleno==66);
139979
- case 75: /* ifexists ::= */ yytestcase(yyruleno==75);
139980
- case 89: /* distinct ::= */ yytestcase(yyruleno==89);
139981
- case 212: /* collate ::= */ yytestcase(yyruleno==212);
139982
-{yymsp[1].minor.yy194 = 0;}
140408
+ case 42: /* autoinc ::= */ yytestcase(yyruleno==42);
140409
+ case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
140410
+ case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
140411
+ case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
140412
+ case 90: /* distinct ::= */ yytestcase(yyruleno==90);
140413
+ case 213: /* collate ::= */ yytestcase(yyruleno==213);
140414
+{yymsp[1].minor.yy4 = 0;}
139983140415
break;
139984140416
case 16: /* ifnotexists ::= IF NOT EXISTS */
139985
-{yymsp[-2].minor.yy194 = 1;}
140417
+{yymsp[-2].minor.yy4 = 1;}
139986140418
break;
139987140419
case 17: /* temp ::= TEMP */
139988
- case 42: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==42);
139989
-{yymsp[0].minor.yy194 = 1;}
140420
+ case 43: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==43);
140421
+{yymsp[0].minor.yy4 = 1;}
139990140422
break;
139991140423
case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
139992140424
{
139993
- sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy194,0);
140425
+ sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy4,0);
139994140426
}
139995140427
break;
139996140428
case 20: /* create_table_args ::= AS select */
139997140429
{
139998
- sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy243);
139999
- sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy243);
140430
+ sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy387);
140431
+ sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
140000140432
}
140001140433
break;
140002140434
case 22: /* table_options ::= WITHOUT nm */
140003140435
{
140004140436
if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
140005
- yymsp[-1].minor.yy194 = TF_WithoutRowid | TF_NoVisibleRowid;
140437
+ yymsp[-1].minor.yy4 = TF_WithoutRowid | TF_NoVisibleRowid;
140006140438
}else{
140007
- yymsp[-1].minor.yy194 = 0;
140439
+ yymsp[-1].minor.yy4 = 0;
140008140440
sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
140009140441
}
140010140442
}
140011140443
break;
140012140444
case 23: /* columnname ::= nm typetoken */
140013140445
{sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
140014140446
break;
140015140447
case 24: /* typetoken ::= */
140016
- case 59: /* conslist_opt ::= */ yytestcase(yyruleno==59);
140017
- case 95: /* as ::= */ yytestcase(yyruleno==95);
140448
+ case 60: /* conslist_opt ::= */ yytestcase(yyruleno==60);
140449
+ case 96: /* as ::= */ yytestcase(yyruleno==96);
140018140450
{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
140019140451
break;
140020140452
case 25: /* typetoken ::= typename LP signed RP */
140021140453
{
140022140454
yymsp[-3].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
@@ -140028,214 +140460,218 @@
140028140460
}
140029140461
break;
140030140462
case 27: /* typename ::= typename ID|STRING */
140031140463
{yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
140032140464
break;
140033
- case 28: /* ccons ::= CONSTRAINT nm */
140034
- case 61: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==61);
140465
+ case 28: /* scanpt ::= */
140466
+{
140467
+ assert( yyLookahead!=YYNOCODE );
140468
+ yymsp[1].minor.yy336 = yyLookaheadToken.z;
140469
+}
140470
+ break;
140471
+ case 29: /* ccons ::= CONSTRAINT nm */
140472
+ case 62: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==62);
140035140473
{pParse->constraintName = yymsp[0].minor.yy0;}
140036140474
break;
140037
- case 29: /* ccons ::= DEFAULT term */
140038
- case 31: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==31);
140039
-{sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy190);}
140040
- break;
140041
- case 30: /* ccons ::= DEFAULT LP expr RP */
140042
-{sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy190);}
140043
- break;
140044
- case 32: /* ccons ::= DEFAULT MINUS term */
140045
-{
140046
- ExprSpan v;
140047
- v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0);
140048
- v.zStart = yymsp[-1].minor.yy0.z;
140049
- v.zEnd = yymsp[0].minor.yy190.zEnd;
140050
- sqlite3AddDefaultValue(pParse,&v);
140051
-}
140052
- break;
140053
- case 33: /* ccons ::= DEFAULT ID|INDEXED */
140054
-{
140055
- ExprSpan v;
140056
- spanExpr(&v, pParse, TK_STRING, yymsp[0].minor.yy0);
140057
- sqlite3AddDefaultValue(pParse,&v);
140058
-}
140059
- break;
140060
- case 34: /* ccons ::= NOT NULL onconf */
140061
-{sqlite3AddNotNull(pParse, yymsp[0].minor.yy194);}
140062
- break;
140063
- case 35: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
140064
-{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy194,yymsp[0].minor.yy194,yymsp[-2].minor.yy194);}
140065
- break;
140066
- case 36: /* ccons ::= UNIQUE onconf */
140067
-{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy194,0,0,0,0,
140475
+ case 30: /* ccons ::= DEFAULT scanpt term scanpt */
140476
+{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy336,yymsp[0].minor.yy336);}
140477
+ break;
140478
+ case 31: /* ccons ::= DEFAULT LP expr RP */
140479
+{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
140480
+ break;
140481
+ case 32: /* ccons ::= DEFAULT PLUS term scanpt */
140482
+{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy336);}
140483
+ break;
140484
+ case 33: /* ccons ::= DEFAULT MINUS term scanpt */
140485
+{
140486
+ Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy314, 0);
140487
+ sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy336);
140488
+}
140489
+ break;
140490
+ case 34: /* ccons ::= DEFAULT scanpt ID|INDEXED */
140491
+{
140492
+ Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
140493
+ sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
140494
+}
140495
+ break;
140496
+ case 35: /* ccons ::= NOT NULL onconf */
140497
+{sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);}
140498
+ break;
140499
+ case 36: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
140500
+{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);}
140501
+ break;
140502
+ case 37: /* ccons ::= UNIQUE onconf */
140503
+{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0,
140068140504
SQLITE_IDXTYPE_UNIQUE);}
140069140505
break;
140070
- case 37: /* ccons ::= CHECK LP expr RP */
140071
-{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy190.pExpr);}
140072
- break;
140073
- case 38: /* ccons ::= REFERENCES nm eidlist_opt refargs */
140074
-{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy148,yymsp[0].minor.yy194);}
140075
- break;
140076
- case 39: /* ccons ::= defer_subclause */
140077
-{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy194);}
140078
- break;
140079
- case 40: /* ccons ::= COLLATE ID|STRING */
140506
+ case 38: /* ccons ::= CHECK LP expr RP */
140507
+{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy314);}
140508
+ break;
140509
+ case 39: /* ccons ::= REFERENCES nm eidlist_opt refargs */
140510
+{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);}
140511
+ break;
140512
+ case 40: /* ccons ::= defer_subclause */
140513
+{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);}
140514
+ break;
140515
+ case 41: /* ccons ::= COLLATE ID|STRING */
140080140516
{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
140081140517
break;
140082
- case 43: /* refargs ::= */
140083
-{ yymsp[1].minor.yy194 = OE_None*0x0101; /* EV: R-19803-45884 */}
140084
- break;
140085
- case 44: /* refargs ::= refargs refarg */
140086
-{ yymsp[-1].minor.yy194 = (yymsp[-1].minor.yy194 & ~yymsp[0].minor.yy497.mask) | yymsp[0].minor.yy497.value; }
140087
- break;
140088
- case 45: /* refarg ::= MATCH nm */
140089
-{ yymsp[-1].minor.yy497.value = 0; yymsp[-1].minor.yy497.mask = 0x000000; }
140090
- break;
140091
- case 46: /* refarg ::= ON INSERT refact */
140092
-{ yymsp[-2].minor.yy497.value = 0; yymsp[-2].minor.yy497.mask = 0x000000; }
140093
- break;
140094
- case 47: /* refarg ::= ON DELETE refact */
140095
-{ yymsp[-2].minor.yy497.value = yymsp[0].minor.yy194; yymsp[-2].minor.yy497.mask = 0x0000ff; }
140096
- break;
140097
- case 48: /* refarg ::= ON UPDATE refact */
140098
-{ yymsp[-2].minor.yy497.value = yymsp[0].minor.yy194<<8; yymsp[-2].minor.yy497.mask = 0x00ff00; }
140099
- break;
140100
- case 49: /* refact ::= SET NULL */
140101
-{ yymsp[-1].minor.yy194 = OE_SetNull; /* EV: R-33326-45252 */}
140102
- break;
140103
- case 50: /* refact ::= SET DEFAULT */
140104
-{ yymsp[-1].minor.yy194 = OE_SetDflt; /* EV: R-33326-45252 */}
140105
- break;
140106
- case 51: /* refact ::= CASCADE */
140107
-{ yymsp[0].minor.yy194 = OE_Cascade; /* EV: R-33326-45252 */}
140108
- break;
140109
- case 52: /* refact ::= RESTRICT */
140110
-{ yymsp[0].minor.yy194 = OE_Restrict; /* EV: R-33326-45252 */}
140111
- break;
140112
- case 53: /* refact ::= NO ACTION */
140113
-{ yymsp[-1].minor.yy194 = OE_None; /* EV: R-33326-45252 */}
140114
- break;
140115
- case 54: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
140116
-{yymsp[-2].minor.yy194 = 0;}
140117
- break;
140118
- case 55: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
140119
- case 70: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==70);
140120
- case 143: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==143);
140121
-{yymsp[-1].minor.yy194 = yymsp[0].minor.yy194;}
140122
- break;
140123
- case 57: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
140124
- case 74: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==74);
140125
- case 184: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==184);
140126
- case 187: /* in_op ::= NOT IN */ yytestcase(yyruleno==187);
140127
- case 213: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==213);
140128
-{yymsp[-1].minor.yy194 = 1;}
140129
- break;
140130
- case 58: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
140131
-{yymsp[-1].minor.yy194 = 0;}
140132
- break;
140133
- case 60: /* tconscomma ::= COMMA */
140518
+ case 44: /* refargs ::= */
140519
+{ yymsp[1].minor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */}
140520
+ break;
140521
+ case 45: /* refargs ::= refargs refarg */
140522
+{ yymsp[-1].minor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; }
140523
+ break;
140524
+ case 46: /* refarg ::= MATCH nm */
140525
+{ yymsp[-1].minor.yy215.value = 0; yymsp[-1].minor.yy215.mask = 0x000000; }
140526
+ break;
140527
+ case 47: /* refarg ::= ON INSERT refact */
140528
+{ yymsp[-2].minor.yy215.value = 0; yymsp[-2].minor.yy215.mask = 0x000000; }
140529
+ break;
140530
+ case 48: /* refarg ::= ON DELETE refact */
140531
+{ yymsp[-2].minor.yy215.value = yymsp[0].minor.yy4; yymsp[-2].minor.yy215.mask = 0x0000ff; }
140532
+ break;
140533
+ case 49: /* refarg ::= ON UPDATE refact */
140534
+{ yymsp[-2].minor.yy215.value = yymsp[0].minor.yy4<<8; yymsp[-2].minor.yy215.mask = 0x00ff00; }
140535
+ break;
140536
+ case 50: /* refact ::= SET NULL */
140537
+{ yymsp[-1].minor.yy4 = OE_SetNull; /* EV: R-33326-45252 */}
140538
+ break;
140539
+ case 51: /* refact ::= SET DEFAULT */
140540
+{ yymsp[-1].minor.yy4 = OE_SetDflt; /* EV: R-33326-45252 */}
140541
+ break;
140542
+ case 52: /* refact ::= CASCADE */
140543
+{ yymsp[0].minor.yy4 = OE_Cascade; /* EV: R-33326-45252 */}
140544
+ break;
140545
+ case 53: /* refact ::= RESTRICT */
140546
+{ yymsp[0].minor.yy4 = OE_Restrict; /* EV: R-33326-45252 */}
140547
+ break;
140548
+ case 54: /* refact ::= NO ACTION */
140549
+{ yymsp[-1].minor.yy4 = OE_None; /* EV: R-33326-45252 */}
140550
+ break;
140551
+ case 55: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
140552
+{yymsp[-2].minor.yy4 = 0;}
140553
+ break;
140554
+ case 56: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
140555
+ case 71: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==71);
140556
+ case 144: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==144);
140557
+{yymsp[-1].minor.yy4 = yymsp[0].minor.yy4;}
140558
+ break;
140559
+ case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
140560
+ case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
140561
+ case 185: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==185);
140562
+ case 188: /* in_op ::= NOT IN */ yytestcase(yyruleno==188);
140563
+ case 214: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==214);
140564
+{yymsp[-1].minor.yy4 = 1;}
140565
+ break;
140566
+ case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
140567
+{yymsp[-1].minor.yy4 = 0;}
140568
+ break;
140569
+ case 61: /* tconscomma ::= COMMA */
140134140570
{pParse->constraintName.n = 0;}
140135140571
break;
140136
- case 62: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
140137
-{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy148,yymsp[0].minor.yy194,yymsp[-2].minor.yy194,0);}
140572
+ case 63: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
140573
+{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);}
140138140574
break;
140139
- case 63: /* tcons ::= UNIQUE LP sortlist RP onconf */
140140
-{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy148,yymsp[0].minor.yy194,0,0,0,0,
140575
+ case 64: /* tcons ::= UNIQUE LP sortlist RP onconf */
140576
+{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0,
140141140577
SQLITE_IDXTYPE_UNIQUE);}
140142140578
break;
140143
- case 64: /* tcons ::= CHECK LP expr RP onconf */
140144
-{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy190.pExpr);}
140145
- break;
140146
- case 65: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
140147
-{
140148
- sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy148, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy148, yymsp[-1].minor.yy194);
140149
- sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy194);
140150
-}
140151
- break;
140152
- case 67: /* onconf ::= */
140153
- case 69: /* orconf ::= */ yytestcase(yyruleno==69);
140154
-{yymsp[1].minor.yy194 = OE_Default;}
140155
- break;
140156
- case 68: /* onconf ::= ON CONFLICT resolvetype */
140157
-{yymsp[-2].minor.yy194 = yymsp[0].minor.yy194;}
140158
- break;
140159
- case 71: /* resolvetype ::= IGNORE */
140160
-{yymsp[0].minor.yy194 = OE_Ignore;}
140161
- break;
140162
- case 72: /* resolvetype ::= REPLACE */
140163
- case 144: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==144);
140164
-{yymsp[0].minor.yy194 = OE_Replace;}
140165
- break;
140166
- case 73: /* cmd ::= DROP TABLE ifexists fullname */
140167
-{
140168
- sqlite3DropTable(pParse, yymsp[0].minor.yy185, 0, yymsp[-1].minor.yy194);
140169
-}
140170
- break;
140171
- case 76: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
140172
-{
140173
- sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy148, yymsp[0].minor.yy243, yymsp[-7].minor.yy194, yymsp[-5].minor.yy194);
140174
-}
140175
- break;
140176
- case 77: /* cmd ::= DROP VIEW ifexists fullname */
140177
-{
140178
- sqlite3DropTable(pParse, yymsp[0].minor.yy185, 1, yymsp[-1].minor.yy194);
140179
-}
140180
- break;
140181
- case 78: /* cmd ::= select */
140579
+ case 65: /* tcons ::= CHECK LP expr RP onconf */
140580
+{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy314);}
140581
+ break;
140582
+ case 66: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
140583
+{
140584
+ sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4);
140585
+ sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4);
140586
+}
140587
+ break;
140588
+ case 68: /* onconf ::= */
140589
+ case 70: /* orconf ::= */ yytestcase(yyruleno==70);
140590
+{yymsp[1].minor.yy4 = OE_Default;}
140591
+ break;
140592
+ case 69: /* onconf ::= ON CONFLICT resolvetype */
140593
+{yymsp[-2].minor.yy4 = yymsp[0].minor.yy4;}
140594
+ break;
140595
+ case 72: /* resolvetype ::= IGNORE */
140596
+{yymsp[0].minor.yy4 = OE_Ignore;}
140597
+ break;
140598
+ case 73: /* resolvetype ::= REPLACE */
140599
+ case 145: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==145);
140600
+{yymsp[0].minor.yy4 = OE_Replace;}
140601
+ break;
140602
+ case 74: /* cmd ::= DROP TABLE ifexists fullname */
140603
+{
140604
+ sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4);
140605
+}
140606
+ break;
140607
+ case 77: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
140608
+{
140609
+ sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[0].minor.yy387, yymsp[-7].minor.yy4, yymsp[-5].minor.yy4);
140610
+}
140611
+ break;
140612
+ case 78: /* cmd ::= DROP VIEW ifexists fullname */
140613
+{
140614
+ sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4);
140615
+}
140616
+ break;
140617
+ case 79: /* cmd ::= select */
140182140618
{
140183140619
SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
140184
- sqlite3Select(pParse, yymsp[0].minor.yy243, &dest);
140185
- sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy243);
140620
+ sqlite3Select(pParse, yymsp[0].minor.yy387, &dest);
140621
+ sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
140186140622
}
140187140623
break;
140188
- case 79: /* select ::= with selectnowith */
140624
+ case 80: /* select ::= with selectnowith */
140189140625
{
140190
- Select *p = yymsp[0].minor.yy243;
140626
+ Select *p = yymsp[0].minor.yy387;
140191140627
if( p ){
140192
- p->pWith = yymsp[-1].minor.yy285;
140628
+ p->pWith = yymsp[-1].minor.yy451;
140193140629
parserDoubleLinkSelect(pParse, p);
140194140630
}else{
140195
- sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy285);
140631
+ sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy451);
140196140632
}
140197
- yymsp[-1].minor.yy243 = p; /*A-overwrites-W*/
140633
+ yymsp[-1].minor.yy387 = p; /*A-overwrites-W*/
140198140634
}
140199140635
break;
140200
- case 80: /* selectnowith ::= selectnowith multiselect_op oneselect */
140636
+ case 81: /* selectnowith ::= selectnowith multiselect_op oneselect */
140201140637
{
140202
- Select *pRhs = yymsp[0].minor.yy243;
140203
- Select *pLhs = yymsp[-2].minor.yy243;
140638
+ Select *pRhs = yymsp[0].minor.yy387;
140639
+ Select *pLhs = yymsp[-2].minor.yy387;
140204140640
if( pRhs && pRhs->pPrior ){
140205140641
SrcList *pFrom;
140206140642
Token x;
140207140643
x.n = 0;
140208140644
parserDoubleLinkSelect(pParse, pRhs);
140209140645
pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
140210140646
pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
140211140647
}
140212140648
if( pRhs ){
140213
- pRhs->op = (u8)yymsp[-1].minor.yy194;
140649
+ pRhs->op = (u8)yymsp[-1].minor.yy4;
140214140650
pRhs->pPrior = pLhs;
140215140651
if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
140216140652
pRhs->selFlags &= ~SF_MultiValue;
140217
- if( yymsp[-1].minor.yy194!=TK_ALL ) pParse->hasCompound = 1;
140653
+ if( yymsp[-1].minor.yy4!=TK_ALL ) pParse->hasCompound = 1;
140218140654
}else{
140219140655
sqlite3SelectDelete(pParse->db, pLhs);
140220140656
}
140221
- yymsp[-2].minor.yy243 = pRhs;
140657
+ yymsp[-2].minor.yy387 = pRhs;
140222140658
}
140223140659
break;
140224
- case 81: /* multiselect_op ::= UNION */
140225
- case 83: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==83);
140226
-{yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-OP*/}
140227
- break;
140228
- case 82: /* multiselect_op ::= UNION ALL */
140229
-{yymsp[-1].minor.yy194 = TK_ALL;}
140230
- break;
140231
- case 84: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
140660
+ case 82: /* multiselect_op ::= UNION */
140661
+ case 84: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==84);
140662
+{yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-OP*/}
140663
+ break;
140664
+ case 83: /* multiselect_op ::= UNION ALL */
140665
+{yymsp[-1].minor.yy4 = TK_ALL;}
140666
+ break;
140667
+ case 85: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
140232140668
{
140233140669
#if SELECTTRACE_ENABLED
140234140670
Token s = yymsp[-8].minor.yy0; /*A-overwrites-S*/
140235140671
#endif
140236
- yymsp[-8].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy148,yymsp[-5].minor.yy185,yymsp[-4].minor.yy72,yymsp[-3].minor.yy148,yymsp[-2].minor.yy72,yymsp[-1].minor.yy148,yymsp[-7].minor.yy194,yymsp[0].minor.yy72);
140672
+ yymsp[-8].minor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy4,yymsp[0].minor.yy314);
140237140673
#if SELECTTRACE_ENABLED
140238140674
/* Populate the Select.zSelName[] string that is used to help with
140239140675
** query planner debugging, to differentiate between multiple Select
140240140676
** objects in a complex query.
140241140677
**
@@ -140242,496 +140678,483 @@
140242140678
** If the SELECT keyword is immediately followed by a C-style comment
140243140679
** then extract the first few alphanumeric characters from within that
140244140680
** comment to be the zSelName value. Otherwise, the label is #N where
140245140681
** is an integer that is incremented with each SELECT statement seen.
140246140682
*/
140247
- if( yymsp[-8].minor.yy243!=0 ){
140683
+ if( yymsp[-8].minor.yy387!=0 ){
140248140684
const char *z = s.z+6;
140249140685
int i;
140250
- sqlite3_snprintf(sizeof(yymsp[-8].minor.yy243->zSelName), yymsp[-8].minor.yy243->zSelName, "#%d",
140686
+ sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName, "#%d",
140251140687
++pParse->nSelect);
140252140688
while( z[0]==' ' ) z++;
140253140689
if( z[0]=='/' && z[1]=='*' ){
140254140690
z += 2;
140255140691
while( z[0]==' ' ) z++;
140256140692
for(i=0; sqlite3Isalnum(z[i]); i++){}
140257
- sqlite3_snprintf(sizeof(yymsp[-8].minor.yy243->zSelName), yymsp[-8].minor.yy243->zSelName, "%.*s", i, z);
140693
+ sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName, "%.*s", i, z);
140258140694
}
140259140695
}
140260140696
#endif /* SELECTRACE_ENABLED */
140261140697
}
140262140698
break;
140263
- case 85: /* values ::= VALUES LP nexprlist RP */
140699
+ case 86: /* values ::= VALUES LP nexprlist RP */
140264140700
{
140265
- yymsp[-3].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values,0);
140701
+ yymsp[-3].minor.yy387 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy322,0,0,0,0,0,SF_Values,0);
140266140702
}
140267140703
break;
140268
- case 86: /* values ::= values COMMA LP exprlist RP */
140704
+ case 87: /* values ::= values COMMA LP exprlist RP */
140269140705
{
140270
- Select *pRight, *pLeft = yymsp[-4].minor.yy243;
140271
- pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values|SF_MultiValue,0);
140706
+ Select *pRight, *pLeft = yymsp[-4].minor.yy387;
140707
+ pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy322,0,0,0,0,0,SF_Values|SF_MultiValue,0);
140272140708
if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
140273140709
if( pRight ){
140274140710
pRight->op = TK_ALL;
140275140711
pRight->pPrior = pLeft;
140276
- yymsp[-4].minor.yy243 = pRight;
140277
- }else{
140278
- yymsp[-4].minor.yy243 = pLeft;
140279
- }
140280
-}
140281
- break;
140282
- case 87: /* distinct ::= DISTINCT */
140283
-{yymsp[0].minor.yy194 = SF_Distinct;}
140284
- break;
140285
- case 88: /* distinct ::= ALL */
140286
-{yymsp[0].minor.yy194 = SF_All;}
140287
- break;
140288
- case 90: /* sclp ::= */
140289
- case 118: /* orderby_opt ::= */ yytestcase(yyruleno==118);
140290
- case 125: /* groupby_opt ::= */ yytestcase(yyruleno==125);
140291
- case 200: /* exprlist ::= */ yytestcase(yyruleno==200);
140292
- case 203: /* paren_exprlist ::= */ yytestcase(yyruleno==203);
140293
- case 208: /* eidlist_opt ::= */ yytestcase(yyruleno==208);
140294
-{yymsp[1].minor.yy148 = 0;}
140295
- break;
140296
- case 91: /* selcollist ::= sclp expr as */
140297
-{
140298
- yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy148, yymsp[-1].minor.yy190.pExpr);
140299
- if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-2].minor.yy148, &yymsp[0].minor.yy0, 1);
140300
- sqlite3ExprListSetSpan(pParse,yymsp[-2].minor.yy148,&yymsp[-1].minor.yy190);
140301
-}
140302
- break;
140303
- case 92: /* selcollist ::= sclp STAR */
140712
+ yymsp[-4].minor.yy387 = pRight;
140713
+ }else{
140714
+ yymsp[-4].minor.yy387 = pLeft;
140715
+ }
140716
+}
140717
+ break;
140718
+ case 88: /* distinct ::= DISTINCT */
140719
+{yymsp[0].minor.yy4 = SF_Distinct;}
140720
+ break;
140721
+ case 89: /* distinct ::= ALL */
140722
+{yymsp[0].minor.yy4 = SF_All;}
140723
+ break;
140724
+ case 91: /* sclp ::= */
140725
+ case 119: /* orderby_opt ::= */ yytestcase(yyruleno==119);
140726
+ case 126: /* groupby_opt ::= */ yytestcase(yyruleno==126);
140727
+ case 201: /* exprlist ::= */ yytestcase(yyruleno==201);
140728
+ case 204: /* paren_exprlist ::= */ yytestcase(yyruleno==204);
140729
+ case 209: /* eidlist_opt ::= */ yytestcase(yyruleno==209);
140730
+{yymsp[1].minor.yy322 = 0;}
140731
+ break;
140732
+ case 92: /* selcollist ::= sclp scanpt expr scanpt as */
140733
+{
140734
+ yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy314);
140735
+ if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy322, &yymsp[0].minor.yy0, 1);
140736
+ sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy322,yymsp[-3].minor.yy336,yymsp[-1].minor.yy336);
140737
+}
140738
+ break;
140739
+ case 93: /* selcollist ::= sclp scanpt STAR */
140304140740
{
140305140741
Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
140306
- yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy148, p);
140742
+ yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, p);
140307140743
}
140308140744
break;
140309
- case 93: /* selcollist ::= sclp nm DOT STAR */
140745
+ case 94: /* selcollist ::= sclp scanpt nm DOT STAR */
140310140746
{
140311140747
Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
140312140748
Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140313140749
Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
140314
- yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot);
140750
+ yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
140315140751
}
140316140752
break;
140317
- case 94: /* as ::= AS nm */
140318
- case 105: /* dbnm ::= DOT nm */ yytestcase(yyruleno==105);
140319
- case 222: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==222);
140320
- case 223: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==223);
140753
+ case 95: /* as ::= AS nm */
140754
+ case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106);
140755
+ case 223: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==223);
140756
+ case 224: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==224);
140321140757
{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
140322140758
break;
140323
- case 96: /* from ::= */
140324
-{yymsp[1].minor.yy185 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy185));}
140325
- break;
140326
- case 97: /* from ::= FROM seltablist */
140327
-{
140328
- yymsp[-1].minor.yy185 = yymsp[0].minor.yy185;
140329
- sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy185);
140330
-}
140331
- break;
140332
- case 98: /* stl_prefix ::= seltablist joinop */
140333
-{
140334
- if( ALWAYS(yymsp[-1].minor.yy185 && yymsp[-1].minor.yy185->nSrc>0) ) yymsp[-1].minor.yy185->a[yymsp[-1].minor.yy185->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy194;
140335
-}
140336
- break;
140337
- case 99: /* stl_prefix ::= */
140338
-{yymsp[1].minor.yy185 = 0;}
140339
- break;
140340
- case 100: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
140341
-{
140342
- yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140343
- sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy185, &yymsp[-2].minor.yy0);
140344
-}
140345
- break;
140346
- case 101: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
140347
-{
140348
- yymsp[-8].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy185,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140349
- sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy185, yymsp[-4].minor.yy148);
140350
-}
140351
- break;
140352
- case 102: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
140353
-{
140354
- yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy243,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140355
- }
140356
- break;
140357
- case 103: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
140358
-{
140359
- if( yymsp[-6].minor.yy185==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy72==0 && yymsp[0].minor.yy254==0 ){
140360
- yymsp[-6].minor.yy185 = yymsp[-4].minor.yy185;
140361
- }else if( yymsp[-4].minor.yy185->nSrc==1 ){
140362
- yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140363
- if( yymsp[-6].minor.yy185 ){
140364
- struct SrcList_item *pNew = &yymsp[-6].minor.yy185->a[yymsp[-6].minor.yy185->nSrc-1];
140365
- struct SrcList_item *pOld = yymsp[-4].minor.yy185->a;
140759
+ case 97: /* from ::= */
140760
+{yymsp[1].minor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy259));}
140761
+ break;
140762
+ case 98: /* from ::= FROM seltablist */
140763
+{
140764
+ yymsp[-1].minor.yy259 = yymsp[0].minor.yy259;
140765
+ sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy259);
140766
+}
140767
+ break;
140768
+ case 99: /* stl_prefix ::= seltablist joinop */
140769
+{
140770
+ if( ALWAYS(yymsp[-1].minor.yy259 && yymsp[-1].minor.yy259->nSrc>0) ) yymsp[-1].minor.yy259->a[yymsp[-1].minor.yy259->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy4;
140771
+}
140772
+ break;
140773
+ case 100: /* stl_prefix ::= */
140774
+{yymsp[1].minor.yy259 = 0;}
140775
+ break;
140776
+ case 101: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
140777
+{
140778
+ yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140779
+ sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy259, &yymsp[-2].minor.yy0);
140780
+}
140781
+ break;
140782
+ case 102: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
140783
+{
140784
+ yymsp[-8].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy259,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140785
+ sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy259, yymsp[-4].minor.yy322);
140786
+}
140787
+ break;
140788
+ case 103: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
140789
+{
140790
+ yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140791
+ }
140792
+ break;
140793
+ case 104: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
140794
+{
140795
+ if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){
140796
+ yymsp[-6].minor.yy259 = yymsp[-4].minor.yy259;
140797
+ }else if( yymsp[-4].minor.yy259->nSrc==1 ){
140798
+ yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140799
+ if( yymsp[-6].minor.yy259 ){
140800
+ struct SrcList_item *pNew = &yymsp[-6].minor.yy259->a[yymsp[-6].minor.yy259->nSrc-1];
140801
+ struct SrcList_item *pOld = yymsp[-4].minor.yy259->a;
140366140802
pNew->zName = pOld->zName;
140367140803
pNew->zDatabase = pOld->zDatabase;
140368140804
pNew->pSelect = pOld->pSelect;
140369140805
pOld->zName = pOld->zDatabase = 0;
140370140806
pOld->pSelect = 0;
140371140807
}
140372
- sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy185);
140808
+ sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy259);
140373140809
}else{
140374140810
Select *pSubquery;
140375
- sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy185);
140376
- pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy185,0,0,0,0,SF_NestedFrom,0);
140377
- yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140811
+ sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259);
140812
+ pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,SF_NestedFrom,0);
140813
+ yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140378140814
}
140379140815
}
140380140816
break;
140381
- case 104: /* dbnm ::= */
140382
- case 113: /* indexed_opt ::= */ yytestcase(yyruleno==113);
140817
+ case 105: /* dbnm ::= */
140818
+ case 114: /* indexed_opt ::= */ yytestcase(yyruleno==114);
140383140819
{yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
140384140820
break;
140385
- case 106: /* fullname ::= nm dbnm */
140386
-{yymsp[-1].minor.yy185 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
140387
- break;
140388
- case 107: /* joinop ::= COMMA|JOIN */
140389
-{ yymsp[0].minor.yy194 = JT_INNER; }
140390
- break;
140391
- case 108: /* joinop ::= JOIN_KW JOIN */
140392
-{yymsp[-1].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
140393
- break;
140394
- case 109: /* joinop ::= JOIN_KW nm JOIN */
140395
-{yymsp[-2].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
140396
- break;
140397
- case 110: /* joinop ::= JOIN_KW nm nm JOIN */
140398
-{yymsp[-3].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
140399
- break;
140400
- case 111: /* on_opt ::= ON expr */
140401
- case 128: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==128);
140402
- case 135: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==135);
140403
- case 196: /* case_else ::= ELSE expr */ yytestcase(yyruleno==196);
140404
-{yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;}
140405
- break;
140406
- case 112: /* on_opt ::= */
140407
- case 127: /* having_opt ::= */ yytestcase(yyruleno==127);
140408
- case 129: /* limit_opt ::= */ yytestcase(yyruleno==129);
140409
- case 134: /* where_opt ::= */ yytestcase(yyruleno==134);
140410
- case 197: /* case_else ::= */ yytestcase(yyruleno==197);
140411
- case 199: /* case_operand ::= */ yytestcase(yyruleno==199);
140412
-{yymsp[1].minor.yy72 = 0;}
140413
- break;
140414
- case 114: /* indexed_opt ::= INDEXED BY nm */
140821
+ case 107: /* fullname ::= nm dbnm */
140822
+{yymsp[-1].minor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
140823
+ break;
140824
+ case 108: /* joinop ::= COMMA|JOIN */
140825
+{ yymsp[0].minor.yy4 = JT_INNER; }
140826
+ break;
140827
+ case 109: /* joinop ::= JOIN_KW JOIN */
140828
+{yymsp[-1].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
140829
+ break;
140830
+ case 110: /* joinop ::= JOIN_KW nm JOIN */
140831
+{yymsp[-2].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
140832
+ break;
140833
+ case 111: /* joinop ::= JOIN_KW nm nm JOIN */
140834
+{yymsp[-3].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
140835
+ break;
140836
+ case 112: /* on_opt ::= ON expr */
140837
+ case 129: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==129);
140838
+ case 136: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==136);
140839
+ case 197: /* case_else ::= ELSE expr */ yytestcase(yyruleno==197);
140840
+{yymsp[-1].minor.yy314 = yymsp[0].minor.yy314;}
140841
+ break;
140842
+ case 113: /* on_opt ::= */
140843
+ case 128: /* having_opt ::= */ yytestcase(yyruleno==128);
140844
+ case 130: /* limit_opt ::= */ yytestcase(yyruleno==130);
140845
+ case 135: /* where_opt ::= */ yytestcase(yyruleno==135);
140846
+ case 198: /* case_else ::= */ yytestcase(yyruleno==198);
140847
+ case 200: /* case_operand ::= */ yytestcase(yyruleno==200);
140848
+{yymsp[1].minor.yy314 = 0;}
140849
+ break;
140850
+ case 115: /* indexed_opt ::= INDEXED BY nm */
140415140851
{yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
140416140852
break;
140417
- case 115: /* indexed_opt ::= NOT INDEXED */
140853
+ case 116: /* indexed_opt ::= NOT INDEXED */
140418140854
{yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
140419140855
break;
140420
- case 116: /* using_opt ::= USING LP idlist RP */
140421
-{yymsp[-3].minor.yy254 = yymsp[-1].minor.yy254;}
140422
- break;
140423
- case 117: /* using_opt ::= */
140424
- case 145: /* idlist_opt ::= */ yytestcase(yyruleno==145);
140425
-{yymsp[1].minor.yy254 = 0;}
140426
- break;
140427
- case 119: /* orderby_opt ::= ORDER BY sortlist */
140428
- case 126: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==126);
140429
-{yymsp[-2].minor.yy148 = yymsp[0].minor.yy148;}
140430
- break;
140431
- case 120: /* sortlist ::= sortlist COMMA expr sortorder */
140432
-{
140433
- yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148,yymsp[-1].minor.yy190.pExpr);
140434
- sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy148,yymsp[0].minor.yy194);
140435
-}
140436
- break;
140437
- case 121: /* sortlist ::= expr sortorder */
140438
-{
140439
- yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy190.pExpr); /*A-overwrites-Y*/
140440
- sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy148,yymsp[0].minor.yy194);
140441
-}
140442
- break;
140443
- case 122: /* sortorder ::= ASC */
140444
-{yymsp[0].minor.yy194 = SQLITE_SO_ASC;}
140445
- break;
140446
- case 123: /* sortorder ::= DESC */
140447
-{yymsp[0].minor.yy194 = SQLITE_SO_DESC;}
140448
- break;
140449
- case 124: /* sortorder ::= */
140450
-{yymsp[1].minor.yy194 = SQLITE_SO_UNDEFINED;}
140451
- break;
140452
- case 130: /* limit_opt ::= LIMIT expr */
140453
-{yymsp[-1].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy190.pExpr,0);}
140454
- break;
140455
- case 131: /* limit_opt ::= LIMIT expr OFFSET expr */
140456
-{yymsp[-3].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy190.pExpr,yymsp[0].minor.yy190.pExpr);}
140457
- break;
140458
- case 132: /* limit_opt ::= LIMIT expr COMMA expr */
140459
-{yymsp[-3].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy190.pExpr,yymsp[-2].minor.yy190.pExpr);}
140460
- break;
140461
- case 133: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140462
-{
140463
- sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1);
140464
- sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy0);
140465
- sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72,0,0);
140466
-}
140467
- break;
140468
- case 136: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140469
-{
140470
- sqlite3WithPush(pParse, yymsp[-7].minor.yy285, 1);
140471
- sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy0);
140472
- sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy148,"set list");
140473
- sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194,0,0);
140474
-}
140475
- break;
140476
- case 137: /* setlist ::= setlist COMMA nm EQ expr */
140477
-{
140478
- yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
140479
- sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, 1);
140480
-}
140481
- break;
140482
- case 138: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
140483
-{
140484
- yymsp[-6].minor.yy148 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy148, yymsp[-3].minor.yy254, yymsp[0].minor.yy190.pExpr);
140485
-}
140486
- break;
140487
- case 139: /* setlist ::= nm EQ expr */
140488
-{
140489
- yylhsminor.yy148 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy190.pExpr);
140490
- sqlite3ExprListSetName(pParse, yylhsminor.yy148, &yymsp[-2].minor.yy0, 1);
140491
-}
140492
- yymsp[-2].minor.yy148 = yylhsminor.yy148;
140493
- break;
140494
- case 140: /* setlist ::= LP idlist RP EQ expr */
140495
-{
140496
- yymsp[-4].minor.yy148 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy254, yymsp[0].minor.yy190.pExpr);
140497
-}
140498
- break;
140499
- case 141: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */
140500
-{
140501
- sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1);
140502
- sqlite3Insert(pParse, yymsp[-2].minor.yy185, yymsp[0].minor.yy243, yymsp[-1].minor.yy254, yymsp[-4].minor.yy194);
140503
-}
140504
- break;
140505
- case 142: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
140506
-{
140507
- sqlite3WithPush(pParse, yymsp[-6].minor.yy285, 1);
140508
- sqlite3Insert(pParse, yymsp[-3].minor.yy185, 0, yymsp[-2].minor.yy254, yymsp[-5].minor.yy194);
140509
-}
140510
- break;
140511
- case 146: /* idlist_opt ::= LP idlist RP */
140512
-{yymsp[-2].minor.yy254 = yymsp[-1].minor.yy254;}
140513
- break;
140514
- case 147: /* idlist ::= idlist COMMA nm */
140515
-{yymsp[-2].minor.yy254 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy254,&yymsp[0].minor.yy0);}
140516
- break;
140517
- case 148: /* idlist ::= nm */
140518
-{yymsp[0].minor.yy254 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
140519
- break;
140520
- case 149: /* expr ::= LP expr RP */
140521
-{spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ yymsp[-2].minor.yy190.pExpr = yymsp[-1].minor.yy190.pExpr;}
140522
- break;
140523
- case 150: /* expr ::= ID|INDEXED */
140524
- case 151: /* expr ::= JOIN_KW */ yytestcase(yyruleno==151);
140525
-{spanExpr(&yymsp[0].minor.yy190,pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
140526
- break;
140527
- case 152: /* expr ::= nm DOT nm */
140856
+ case 117: /* using_opt ::= USING LP idlist RP */
140857
+{yymsp[-3].minor.yy384 = yymsp[-1].minor.yy384;}
140858
+ break;
140859
+ case 118: /* using_opt ::= */
140860
+ case 146: /* idlist_opt ::= */ yytestcase(yyruleno==146);
140861
+{yymsp[1].minor.yy384 = 0;}
140862
+ break;
140863
+ case 120: /* orderby_opt ::= ORDER BY sortlist */
140864
+ case 127: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==127);
140865
+{yymsp[-2].minor.yy322 = yymsp[0].minor.yy322;}
140866
+ break;
140867
+ case 121: /* sortlist ::= sortlist COMMA expr sortorder */
140868
+{
140869
+ yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy314);
140870
+ sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy322,yymsp[0].minor.yy4);
140871
+}
140872
+ break;
140873
+ case 122: /* sortlist ::= expr sortorder */
140874
+{
140875
+ yymsp[-1].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy314); /*A-overwrites-Y*/
140876
+ sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy322,yymsp[0].minor.yy4);
140877
+}
140878
+ break;
140879
+ case 123: /* sortorder ::= ASC */
140880
+{yymsp[0].minor.yy4 = SQLITE_SO_ASC;}
140881
+ break;
140882
+ case 124: /* sortorder ::= DESC */
140883
+{yymsp[0].minor.yy4 = SQLITE_SO_DESC;}
140884
+ break;
140885
+ case 125: /* sortorder ::= */
140886
+{yymsp[1].minor.yy4 = SQLITE_SO_UNDEFINED;}
140887
+ break;
140888
+ case 131: /* limit_opt ::= LIMIT expr */
140889
+{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy314,0);}
140890
+ break;
140891
+ case 132: /* limit_opt ::= LIMIT expr OFFSET expr */
140892
+{yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy314,yymsp[0].minor.yy314);}
140893
+ break;
140894
+ case 133: /* limit_opt ::= LIMIT expr COMMA expr */
140895
+{yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy314,yymsp[-2].minor.yy314);}
140896
+ break;
140897
+ case 134: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140898
+{
140899
+ sqlite3WithPush(pParse, yymsp[-5].minor.yy451, 1);
140900
+ sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0);
140901
+ sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314,0,0);
140902
+}
140903
+ break;
140904
+ case 137: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140905
+{
140906
+ sqlite3WithPush(pParse, yymsp[-7].minor.yy451, 1);
140907
+ sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0);
140908
+ sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list");
140909
+ sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy4,0,0);
140910
+}
140911
+ break;
140912
+ case 138: /* setlist ::= setlist COMMA nm EQ expr */
140913
+{
140914
+ yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy314);
140915
+ sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, 1);
140916
+}
140917
+ break;
140918
+ case 139: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
140919
+{
140920
+ yymsp[-6].minor.yy322 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy322, yymsp[-3].minor.yy384, yymsp[0].minor.yy314);
140921
+}
140922
+ break;
140923
+ case 140: /* setlist ::= nm EQ expr */
140924
+{
140925
+ yylhsminor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy314);
140926
+ sqlite3ExprListSetName(pParse, yylhsminor.yy322, &yymsp[-2].minor.yy0, 1);
140927
+}
140928
+ yymsp[-2].minor.yy322 = yylhsminor.yy322;
140929
+ break;
140930
+ case 141: /* setlist ::= LP idlist RP EQ expr */
140931
+{
140932
+ yymsp[-4].minor.yy322 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy384, yymsp[0].minor.yy314);
140933
+}
140934
+ break;
140935
+ case 142: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */
140936
+{
140937
+ sqlite3WithPush(pParse, yymsp[-5].minor.yy451, 1);
140938
+ sqlite3Insert(pParse, yymsp[-2].minor.yy259, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy4);
140939
+}
140940
+ break;
140941
+ case 143: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
140942
+{
140943
+ sqlite3WithPush(pParse, yymsp[-6].minor.yy451, 1);
140944
+ sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy4);
140945
+}
140946
+ break;
140947
+ case 147: /* idlist_opt ::= LP idlist RP */
140948
+{yymsp[-2].minor.yy384 = yymsp[-1].minor.yy384;}
140949
+ break;
140950
+ case 148: /* idlist ::= idlist COMMA nm */
140951
+{yymsp[-2].minor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
140952
+ break;
140953
+ case 149: /* idlist ::= nm */
140954
+{yymsp[0].minor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
140955
+ break;
140956
+ case 150: /* expr ::= LP expr RP */
140957
+{yymsp[-2].minor.yy314 = yymsp[-1].minor.yy314;}
140958
+ break;
140959
+ case 151: /* expr ::= ID|INDEXED */
140960
+ case 152: /* expr ::= JOIN_KW */ yytestcase(yyruleno==152);
140961
+{yymsp[0].minor.yy314=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
140962
+ break;
140963
+ case 153: /* expr ::= nm DOT nm */
140528140964
{
140529140965
Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140530140966
Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
140531
- spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140532
- yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
140967
+ yylhsminor.yy314 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
140533140968
}
140969
+ yymsp[-2].minor.yy314 = yylhsminor.yy314;
140534140970
break;
140535
- case 153: /* expr ::= nm DOT nm DOT nm */
140971
+ case 154: /* expr ::= nm DOT nm DOT nm */
140536140972
{
140537140973
Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
140538140974
Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140539140975
Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
140540140976
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
140541
- spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140542
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
140543
-}
140544
- break;
140545
- case 154: /* term ::= NULL|FLOAT|BLOB */
140546
- case 155: /* term ::= STRING */ yytestcase(yyruleno==155);
140547
-{spanExpr(&yymsp[0].minor.yy190,pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
140548
- break;
140549
- case 156: /* term ::= INTEGER */
140550
-{
140551
- yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
140552
- yylhsminor.yy190.zStart = yymsp[0].minor.yy0.z;
140553
- yylhsminor.yy190.zEnd = yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n;
140554
-}
140555
- yymsp[0].minor.yy190 = yylhsminor.yy190;
140556
- break;
140557
- case 157: /* expr ::= VARIABLE */
140977
+ yylhsminor.yy314 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
140978
+}
140979
+ yymsp[-4].minor.yy314 = yylhsminor.yy314;
140980
+ break;
140981
+ case 155: /* term ::= NULL|FLOAT|BLOB */
140982
+ case 156: /* term ::= STRING */ yytestcase(yyruleno==156);
140983
+{yymsp[0].minor.yy314=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
140984
+ break;
140985
+ case 157: /* term ::= INTEGER */
140986
+{
140987
+ yylhsminor.yy314 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
140988
+}
140989
+ yymsp[0].minor.yy314 = yylhsminor.yy314;
140990
+ break;
140991
+ case 158: /* expr ::= VARIABLE */
140558140992
{
140559140993
if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
140560140994
u32 n = yymsp[0].minor.yy0.n;
140561
- spanExpr(&yymsp[0].minor.yy190, pParse, TK_VARIABLE, yymsp[0].minor.yy0);
140562
- sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy190.pExpr, n);
140995
+ yymsp[0].minor.yy314 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
140996
+ sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy314, n);
140563140997
}else{
140564140998
/* When doing a nested parse, one can include terms in an expression
140565140999
** that look like this: #1 #2 ... These terms refer to registers
140566141000
** in the virtual machine. #N is the N-th register. */
140567141001
Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
140568141002
assert( t.n>=2 );
140569
- spanSet(&yymsp[0].minor.yy190, &t, &t);
140570141003
if( pParse->nested==0 ){
140571141004
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
140572
- yymsp[0].minor.yy190.pExpr = 0;
140573
- }else{
140574
- yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
140575
- if( yymsp[0].minor.yy190.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy190.pExpr->iTable);
140576
- }
140577
- }
140578
-}
140579
- break;
140580
- case 158: /* expr ::= expr COLLATE ID|STRING */
140581
-{
140582
- yymsp[-2].minor.yy190.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy190.pExpr, &yymsp[0].minor.yy0, 1);
140583
- yymsp[-2].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
140584
-}
140585
- break;
140586
- case 159: /* expr ::= CAST LP expr AS typetoken RP */
140587
-{
140588
- spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140589
- yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
140590
- sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, 0);
140591
-}
140592
- break;
140593
- case 160: /* expr ::= ID|INDEXED LP distinct exprlist RP */
140594
-{
140595
- if( yymsp[-1].minor.yy148 && yymsp[-1].minor.yy148->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
141005
+ yymsp[0].minor.yy314 = 0;
141006
+ }else{
141007
+ yymsp[0].minor.yy314 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
141008
+ if( yymsp[0].minor.yy314 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy314->iTable);
141009
+ }
141010
+ }
141011
+}
141012
+ break;
141013
+ case 159: /* expr ::= expr COLLATE ID|STRING */
141014
+{
141015
+ yymsp[-2].minor.yy314 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy314, &yymsp[0].minor.yy0, 1);
141016
+}
141017
+ break;
141018
+ case 160: /* expr ::= CAST LP expr AS typetoken RP */
141019
+{
141020
+ yymsp[-5].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
141021
+ sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy314, yymsp[-3].minor.yy314, 0);
141022
+}
141023
+ break;
141024
+ case 161: /* expr ::= ID|INDEXED LP distinct exprlist RP */
141025
+{
141026
+ if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
140596141027
sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
140597141028
}
140598
- yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy148, &yymsp[-4].minor.yy0);
140599
- spanSet(&yylhsminor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
140600
- if( yymsp[-2].minor.yy194==SF_Distinct && yylhsminor.yy190.pExpr ){
140601
- yylhsminor.yy190.pExpr->flags |= EP_Distinct;
140602
- }
140603
-}
140604
- yymsp[-4].minor.yy190 = yylhsminor.yy190;
140605
- break;
140606
- case 161: /* expr ::= ID|INDEXED LP STAR RP */
140607
-{
140608
- yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
140609
- spanSet(&yylhsminor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
140610
-}
140611
- yymsp[-3].minor.yy190 = yylhsminor.yy190;
140612
- break;
140613
- case 162: /* term ::= CTIME_KW */
140614
-{
140615
- yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
140616
- spanSet(&yylhsminor.yy190, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
140617
-}
140618
- yymsp[0].minor.yy190 = yylhsminor.yy190;
140619
- break;
140620
- case 163: /* expr ::= LP nexprlist COMMA expr RP */
140621
-{
140622
- ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy148, yymsp[-1].minor.yy190.pExpr);
140623
- yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
140624
- if( yylhsminor.yy190.pExpr ){
140625
- yylhsminor.yy190.pExpr->x.pList = pList;
140626
- spanSet(&yylhsminor.yy190, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
141029
+ yylhsminor.yy314 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
141030
+ if( yymsp[-2].minor.yy4==SF_Distinct && yylhsminor.yy314 ){
141031
+ yylhsminor.yy314->flags |= EP_Distinct;
141032
+ }
141033
+}
141034
+ yymsp[-4].minor.yy314 = yylhsminor.yy314;
141035
+ break;
141036
+ case 162: /* expr ::= ID|INDEXED LP STAR RP */
141037
+{
141038
+ yylhsminor.yy314 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
141039
+}
141040
+ yymsp[-3].minor.yy314 = yylhsminor.yy314;
141041
+ break;
141042
+ case 163: /* term ::= CTIME_KW */
141043
+{
141044
+ yylhsminor.yy314 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
141045
+}
141046
+ yymsp[0].minor.yy314 = yylhsminor.yy314;
141047
+ break;
141048
+ case 164: /* expr ::= LP nexprlist COMMA expr RP */
141049
+{
141050
+ ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy322, yymsp[-1].minor.yy314);
141051
+ yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
141052
+ if( yymsp[-4].minor.yy314 ){
141053
+ yymsp[-4].minor.yy314->x.pList = pList;
140627141054
}else{
140628141055
sqlite3ExprListDelete(pParse->db, pList);
140629141056
}
140630141057
}
140631
- yymsp[-4].minor.yy190 = yylhsminor.yy190;
140632
- break;
140633
- case 164: /* expr ::= expr AND expr */
140634
- case 165: /* expr ::= expr OR expr */ yytestcase(yyruleno==165);
140635
- case 166: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==166);
140636
- case 167: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==167);
140637
- case 168: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==168);
140638
- case 169: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==169);
140639
- case 170: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==170);
140640
- case 171: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==171);
140641
-{spanBinaryExpr(pParse,yymsp[-1].major,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);}
140642
- break;
140643
- case 172: /* likeop ::= NOT LIKE_KW|MATCH */
141058
+ break;
141059
+ case 165: /* expr ::= expr AND expr */
141060
+ case 166: /* expr ::= expr OR expr */ yytestcase(yyruleno==166);
141061
+ case 167: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==167);
141062
+ case 168: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==168);
141063
+ case 169: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==169);
141064
+ case 170: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==170);
141065
+ case 171: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==171);
141066
+ case 172: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==172);
141067
+{yymsp[-2].minor.yy314=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy314,yymsp[0].minor.yy314);}
141068
+ break;
141069
+ case 173: /* likeop ::= NOT LIKE_KW|MATCH */
140644141070
{yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
140645141071
break;
140646
- case 173: /* expr ::= expr likeop expr */
141072
+ case 174: /* expr ::= expr likeop expr */
140647141073
{
140648141074
ExprList *pList;
140649141075
int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
140650141076
yymsp[-1].minor.yy0.n &= 0x7fffffff;
140651
- pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy190.pExpr);
140652
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy190.pExpr);
140653
- yymsp[-2].minor.yy190.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0);
140654
- exprNot(pParse, bNot, &yymsp[-2].minor.yy190);
140655
- yymsp[-2].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
140656
- if( yymsp[-2].minor.yy190.pExpr ) yymsp[-2].minor.yy190.pExpr->flags |= EP_InfixFunc;
141077
+ pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy314);
141078
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy314);
141079
+ yymsp[-2].minor.yy314 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0);
141080
+ if( bNot ) yymsp[-2].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy314, 0);
141081
+ if( yymsp[-2].minor.yy314 ) yymsp[-2].minor.yy314->flags |= EP_InfixFunc;
140657141082
}
140658141083
break;
140659
- case 174: /* expr ::= expr likeop expr ESCAPE expr */
141084
+ case 175: /* expr ::= expr likeop expr ESCAPE expr */
140660141085
{
140661141086
ExprList *pList;
140662141087
int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
140663141088
yymsp[-3].minor.yy0.n &= 0x7fffffff;
140664
- pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
140665
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy190.pExpr);
140666
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
140667
- yymsp[-4].minor.yy190.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0);
140668
- exprNot(pParse, bNot, &yymsp[-4].minor.yy190);
140669
- yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
140670
- if( yymsp[-4].minor.yy190.pExpr ) yymsp[-4].minor.yy190.pExpr->flags |= EP_InfixFunc;
140671
-}
140672
- break;
140673
- case 175: /* expr ::= expr ISNULL|NOTNULL */
140674
-{spanUnaryPostfix(pParse,yymsp[0].major,&yymsp[-1].minor.yy190,&yymsp[0].minor.yy0);}
140675
- break;
140676
- case 176: /* expr ::= expr NOT NULL */
140677
-{spanUnaryPostfix(pParse,TK_NOTNULL,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy0);}
140678
- break;
140679
- case 177: /* expr ::= expr IS expr */
140680
-{
140681
- spanBinaryExpr(pParse,TK_IS,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);
140682
- binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-2].minor.yy190.pExpr, TK_ISNULL);
140683
-}
140684
- break;
140685
- case 178: /* expr ::= expr IS NOT expr */
140686
-{
140687
- spanBinaryExpr(pParse,TK_ISNOT,&yymsp[-3].minor.yy190,&yymsp[0].minor.yy190);
140688
- binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, TK_NOTNULL);
140689
-}
140690
- break;
140691
- case 179: /* expr ::= NOT expr */
140692
- case 180: /* expr ::= BITNOT expr */ yytestcase(yyruleno==180);
140693
-{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,yymsp[-1].major,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
140694
- break;
140695
- case 181: /* expr ::= MINUS expr */
140696
-{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UMINUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
140697
- break;
140698
- case 182: /* expr ::= PLUS expr */
140699
-{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UPLUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
140700
- break;
140701
- case 183: /* between_op ::= BETWEEN */
140702
- case 186: /* in_op ::= IN */ yytestcase(yyruleno==186);
140703
-{yymsp[0].minor.yy194 = 0;}
140704
- break;
140705
- case 185: /* expr ::= expr between_op expr AND expr */
140706
-{
140707
- ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
140708
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
140709
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0);
140710
- if( yymsp[-4].minor.yy190.pExpr ){
140711
- yymsp[-4].minor.yy190.pExpr->x.pList = pList;
141089
+ pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314);
141090
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy314);
141091
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy314);
141092
+ yymsp[-4].minor.yy314 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0);
141093
+ if( bNot ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
141094
+ if( yymsp[-4].minor.yy314 ) yymsp[-4].minor.yy314->flags |= EP_InfixFunc;
141095
+}
141096
+ break;
141097
+ case 176: /* expr ::= expr ISNULL|NOTNULL */
141098
+{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy314,0);}
141099
+ break;
141100
+ case 177: /* expr ::= expr NOT NULL */
141101
+{yymsp[-2].minor.yy314 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy314,0);}
141102
+ break;
141103
+ case 178: /* expr ::= expr IS expr */
141104
+{
141105
+ yymsp[-2].minor.yy314 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy314,yymsp[0].minor.yy314);
141106
+ binaryToUnaryIfNull(pParse, yymsp[0].minor.yy314, yymsp[-2].minor.yy314, TK_ISNULL);
141107
+}
141108
+ break;
141109
+ case 179: /* expr ::= expr IS NOT expr */
141110
+{
141111
+ yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy314,yymsp[0].minor.yy314);
141112
+ binaryToUnaryIfNull(pParse, yymsp[0].minor.yy314, yymsp[-3].minor.yy314, TK_NOTNULL);
141113
+}
141114
+ break;
141115
+ case 180: /* expr ::= NOT expr */
141116
+ case 181: /* expr ::= BITNOT expr */ yytestcase(yyruleno==181);
141117
+{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy314, 0);/*A-overwrites-B*/}
141118
+ break;
141119
+ case 182: /* expr ::= MINUS expr */
141120
+{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy314, 0);}
141121
+ break;
141122
+ case 183: /* expr ::= PLUS expr */
141123
+{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy314, 0);}
141124
+ break;
141125
+ case 184: /* between_op ::= BETWEEN */
141126
+ case 187: /* in_op ::= IN */ yytestcase(yyruleno==187);
141127
+{yymsp[0].minor.yy4 = 0;}
141128
+ break;
141129
+ case 186: /* expr ::= expr between_op expr AND expr */
141130
+{
141131
+ ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314);
141132
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy314);
141133
+ yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy314, 0);
141134
+ if( yymsp[-4].minor.yy314 ){
141135
+ yymsp[-4].minor.yy314->x.pList = pList;
140712141136
}else{
140713141137
sqlite3ExprListDelete(pParse->db, pList);
140714141138
}
140715
- exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140716
- yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
141139
+ if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
140717141140
}
140718141141
break;
140719
- case 188: /* expr ::= expr in_op LP exprlist RP */
141142
+ case 189: /* expr ::= expr in_op LP exprlist RP */
140720141143
{
140721
- if( yymsp[-1].minor.yy148==0 ){
141144
+ if( yymsp[-1].minor.yy322==0 ){
140722141145
/* Expressions of the form
140723141146
**
140724141147
** expr1 IN ()
140725141148
** expr1 NOT IN ()
140726141149
**
140727141150
** simplify to constants 0 (false) and 1 (true), respectively,
140728141151
** regardless of the value of expr1.
140729141152
*/
140730
- sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy190.pExpr);
140731
- yymsp[-4].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy194],1);
140732
- }else if( yymsp[-1].minor.yy148->nExpr==1 ){
141153
+ sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy314);
141154
+ yymsp[-4].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy4],1);
141155
+ }else if( yymsp[-1].minor.yy322->nExpr==1 ){
140733141156
/* Expressions of the form:
140734141157
**
140735141158
** expr1 IN (?1)
140736141159
** expr1 NOT IN (?2)
140737141160
**
@@ -140744,402 +141167,398 @@
140744141167
** But, the RHS of the == or <> is marked with the EP_Generic flag
140745141168
** so that it may not contribute to the computation of comparison
140746141169
** affinity or the collating sequence to use for comparison. Otherwise,
140747141170
** the semantics would be subtly different from IN or NOT IN.
140748141171
*/
140749
- Expr *pRHS = yymsp[-1].minor.yy148->a[0].pExpr;
140750
- yymsp[-1].minor.yy148->a[0].pExpr = 0;
140751
- sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148);
141172
+ Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr;
141173
+ yymsp[-1].minor.yy322->a[0].pExpr = 0;
141174
+ sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
140752141175
/* pRHS cannot be NULL because a malloc error would have been detected
140753141176
** before now and control would have never reached this point */
140754141177
if( ALWAYS(pRHS) ){
140755141178
pRHS->flags &= ~EP_Collate;
140756141179
pRHS->flags |= EP_Generic;
140757141180
}
140758
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS);
140759
- }else{
140760
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140761
- if( yymsp[-4].minor.yy190.pExpr ){
140762
- yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy148;
140763
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
140764
- }else{
140765
- sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148);
140766
- }
140767
- exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140768
- }
140769
- yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
140770
- }
140771
- break;
140772
- case 189: /* expr ::= LP select RP */
140773
-{
140774
- spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
140775
- yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
140776
- sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243);
140777
- }
140778
- break;
140779
- case 190: /* expr ::= expr in_op LP select RP */
140780
-{
140781
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140782
- sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243);
140783
- exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140784
- yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
140785
- }
140786
- break;
140787
- case 191: /* expr ::= expr in_op nm dbnm paren_exprlist */
141181
+ yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, yymsp[-3].minor.yy4 ? TK_NE : TK_EQ, yymsp[-4].minor.yy314, pRHS);
141182
+ }else{
141183
+ yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0);
141184
+ if( yymsp[-4].minor.yy314 ){
141185
+ yymsp[-4].minor.yy314->x.pList = yymsp[-1].minor.yy322;
141186
+ sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy314);
141187
+ }else{
141188
+ sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
141189
+ }
141190
+ if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
141191
+ }
141192
+ }
141193
+ break;
141194
+ case 190: /* expr ::= LP select RP */
141195
+{
141196
+ yymsp[-2].minor.yy314 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
141197
+ sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy314, yymsp[-1].minor.yy387);
141198
+ }
141199
+ break;
141200
+ case 191: /* expr ::= expr in_op LP select RP */
141201
+{
141202
+ yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0);
141203
+ sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy314, yymsp[-1].minor.yy387);
141204
+ if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
141205
+ }
141206
+ break;
141207
+ case 192: /* expr ::= expr in_op nm dbnm paren_exprlist */
140788141208
{
140789141209
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
140790141210
Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
140791
- if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
140792
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140793
- sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
140794
- exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140795
- yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n];
141211
+ if( yymsp[0].minor.yy322 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy322);
141212
+ yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0);
141213
+ sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy314, pSelect);
141214
+ if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
140796141215
}
140797141216
break;
140798
- case 192: /* expr ::= EXISTS LP select RP */
141217
+ case 193: /* expr ::= EXISTS LP select RP */
140799141218
{
140800141219
Expr *p;
140801
- spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
140802
- p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
140803
- sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243);
140804
- }
140805
- break;
140806
- case 193: /* expr ::= CASE case_operand case_exprlist case_else END */
140807
-{
140808
- spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
140809
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0);
140810
- if( yymsp[-4].minor.yy190.pExpr ){
140811
- yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy72 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[-1].minor.yy72) : yymsp[-2].minor.yy148;
140812
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
140813
- }else{
140814
- sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148);
140815
- sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy72);
140816
- }
140817
-}
140818
- break;
140819
- case 194: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
140820
-{
140821
- yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[-2].minor.yy190.pExpr);
140822
- yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
140823
-}
140824
- break;
140825
- case 195: /* case_exprlist ::= WHEN expr THEN expr */
140826
-{
140827
- yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
140828
- yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, yymsp[0].minor.yy190.pExpr);
140829
-}
140830
- break;
140831
- case 198: /* case_operand ::= expr */
140832
-{yymsp[0].minor.yy72 = yymsp[0].minor.yy190.pExpr; /*A-overwrites-X*/}
140833
- break;
140834
- case 201: /* nexprlist ::= nexprlist COMMA expr */
140835
-{yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[0].minor.yy190.pExpr);}
140836
- break;
140837
- case 202: /* nexprlist ::= expr */
140838
-{yymsp[0].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy190.pExpr); /*A-overwrites-Y*/}
140839
- break;
140840
- case 204: /* paren_exprlist ::= LP exprlist RP */
140841
- case 209: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==209);
140842
-{yymsp[-2].minor.yy148 = yymsp[-1].minor.yy148;}
140843
- break;
140844
- case 205: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
141220
+ p = yymsp[-3].minor.yy314 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
141221
+ sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy387);
141222
+ }
141223
+ break;
141224
+ case 194: /* expr ::= CASE case_operand case_exprlist case_else END */
141225
+{
141226
+ yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, 0);
141227
+ if( yymsp[-4].minor.yy314 ){
141228
+ yymsp[-4].minor.yy314->x.pList = yymsp[-1].minor.yy314 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy314) : yymsp[-2].minor.yy322;
141229
+ sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy314);
141230
+ }else{
141231
+ sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
141232
+ sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy314);
141233
+ }
141234
+}
141235
+ break;
141236
+ case 195: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
141237
+{
141238
+ yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy314);
141239
+ yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy314);
141240
+}
141241
+ break;
141242
+ case 196: /* case_exprlist ::= WHEN expr THEN expr */
141243
+{
141244
+ yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314);
141245
+ yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy314);
141246
+}
141247
+ break;
141248
+ case 199: /* case_operand ::= expr */
141249
+{yymsp[0].minor.yy314 = yymsp[0].minor.yy314; /*A-overwrites-X*/}
141250
+ break;
141251
+ case 202: /* nexprlist ::= nexprlist COMMA expr */
141252
+{yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy314);}
141253
+ break;
141254
+ case 203: /* nexprlist ::= expr */
141255
+{yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy314); /*A-overwrites-Y*/}
141256
+ break;
141257
+ case 205: /* paren_exprlist ::= LP exprlist RP */
141258
+ case 210: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==210);
141259
+{yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
141260
+ break;
141261
+ case 206: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
140845141262
{
140846141263
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
140847
- sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy148, yymsp[-10].minor.yy194,
140848
- &yymsp[-11].minor.yy0, yymsp[0].minor.yy72, SQLITE_SO_ASC, yymsp[-8].minor.yy194, SQLITE_IDXTYPE_APPDEF);
140849
-}
140850
- break;
140851
- case 206: /* uniqueflag ::= UNIQUE */
140852
- case 246: /* raisetype ::= ABORT */ yytestcase(yyruleno==246);
140853
-{yymsp[0].minor.yy194 = OE_Abort;}
140854
- break;
140855
- case 207: /* uniqueflag ::= */
140856
-{yymsp[1].minor.yy194 = OE_None;}
140857
- break;
140858
- case 210: /* eidlist ::= eidlist COMMA nm collate sortorder */
140859
-{
140860
- yymsp[-4].minor.yy148 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194);
140861
-}
140862
- break;
140863
- case 211: /* eidlist ::= nm collate sortorder */
140864
-{
140865
- yymsp[-2].minor.yy148 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); /*A-overwrites-Y*/
140866
-}
140867
- break;
140868
- case 214: /* cmd ::= DROP INDEX ifexists fullname */
140869
-{sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
140870
- break;
140871
- case 215: /* cmd ::= VACUUM */
141264
+ sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy4,
141265
+ &yymsp[-11].minor.yy0, yymsp[0].minor.yy314, SQLITE_SO_ASC, yymsp[-8].minor.yy4, SQLITE_IDXTYPE_APPDEF);
141266
+}
141267
+ break;
141268
+ case 207: /* uniqueflag ::= UNIQUE */
141269
+ case 247: /* raisetype ::= ABORT */ yytestcase(yyruleno==247);
141270
+{yymsp[0].minor.yy4 = OE_Abort;}
141271
+ break;
141272
+ case 208: /* uniqueflag ::= */
141273
+{yymsp[1].minor.yy4 = OE_None;}
141274
+ break;
141275
+ case 211: /* eidlist ::= eidlist COMMA nm collate sortorder */
141276
+{
141277
+ yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy4, yymsp[0].minor.yy4);
141278
+}
141279
+ break;
141280
+ case 212: /* eidlist ::= nm collate sortorder */
141281
+{
141282
+ yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy4, yymsp[0].minor.yy4); /*A-overwrites-Y*/
141283
+}
141284
+ break;
141285
+ case 215: /* cmd ::= DROP INDEX ifexists fullname */
141286
+{sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);}
141287
+ break;
141288
+ case 216: /* cmd ::= VACUUM */
140872141289
{sqlite3Vacuum(pParse,0);}
140873141290
break;
140874
- case 216: /* cmd ::= VACUUM nm */
141291
+ case 217: /* cmd ::= VACUUM nm */
140875141292
{sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
140876141293
break;
140877
- case 217: /* cmd ::= PRAGMA nm dbnm */
141294
+ case 218: /* cmd ::= PRAGMA nm dbnm */
140878141295
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
140879141296
break;
140880
- case 218: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
141297
+ case 219: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
140881141298
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
140882141299
break;
140883
- case 219: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
141300
+ case 220: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
140884141301
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
140885141302
break;
140886
- case 220: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
141303
+ case 221: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
140887141304
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
140888141305
break;
140889
- case 221: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
141306
+ case 222: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
140890141307
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
140891141308
break;
140892
- case 224: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
141309
+ case 225: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
140893141310
{
140894141311
Token all;
140895141312
all.z = yymsp[-3].minor.yy0.z;
140896141313
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
140897
- sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy145, &all);
141314
+ sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
140898141315
}
140899141316
break;
140900
- case 225: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
141317
+ case 226: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
140901141318
{
140902
- sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy194, yymsp[-4].minor.yy332.a, yymsp[-4].minor.yy332.b, yymsp[-2].minor.yy185, yymsp[0].minor.yy72, yymsp[-10].minor.yy194, yymsp[-8].minor.yy194);
141319
+ sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4);
140903141320
yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
140904141321
}
140905141322
break;
140906
- case 226: /* trigger_time ::= BEFORE|AFTER */
140907
-{ yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-X*/ }
140908
- break;
140909
- case 227: /* trigger_time ::= INSTEAD OF */
140910
-{ yymsp[-1].minor.yy194 = TK_INSTEAD;}
140911
- break;
140912
- case 228: /* trigger_time ::= */
140913
-{ yymsp[1].minor.yy194 = TK_BEFORE; }
140914
- break;
140915
- case 229: /* trigger_event ::= DELETE|INSERT */
140916
- case 230: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==230);
140917
-{yymsp[0].minor.yy332.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy332.b = 0;}
140918
- break;
140919
- case 231: /* trigger_event ::= UPDATE OF idlist */
140920
-{yymsp[-2].minor.yy332.a = TK_UPDATE; yymsp[-2].minor.yy332.b = yymsp[0].minor.yy254;}
140921
- break;
140922
- case 232: /* when_clause ::= */
140923
- case 251: /* key_opt ::= */ yytestcase(yyruleno==251);
140924
-{ yymsp[1].minor.yy72 = 0; }
140925
- break;
140926
- case 233: /* when_clause ::= WHEN expr */
140927
- case 252: /* key_opt ::= KEY expr */ yytestcase(yyruleno==252);
140928
-{ yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr; }
140929
- break;
140930
- case 234: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
140931
-{
140932
- assert( yymsp[-2].minor.yy145!=0 );
140933
- yymsp[-2].minor.yy145->pLast->pNext = yymsp[-1].minor.yy145;
140934
- yymsp[-2].minor.yy145->pLast = yymsp[-1].minor.yy145;
140935
-}
140936
- break;
140937
- case 235: /* trigger_cmd_list ::= trigger_cmd SEMI */
140938
-{
140939
- assert( yymsp[-1].minor.yy145!=0 );
140940
- yymsp[-1].minor.yy145->pLast = yymsp[-1].minor.yy145;
140941
-}
140942
- break;
140943
- case 236: /* trnm ::= nm DOT nm */
141323
+ case 227: /* trigger_time ::= BEFORE|AFTER */
141324
+{ yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-X*/ }
141325
+ break;
141326
+ case 228: /* trigger_time ::= INSTEAD OF */
141327
+{ yymsp[-1].minor.yy4 = TK_INSTEAD;}
141328
+ break;
141329
+ case 229: /* trigger_time ::= */
141330
+{ yymsp[1].minor.yy4 = TK_BEFORE; }
141331
+ break;
141332
+ case 230: /* trigger_event ::= DELETE|INSERT */
141333
+ case 231: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==231);
141334
+{yymsp[0].minor.yy90.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy90.b = 0;}
141335
+ break;
141336
+ case 232: /* trigger_event ::= UPDATE OF idlist */
141337
+{yymsp[-2].minor.yy90.a = TK_UPDATE; yymsp[-2].minor.yy90.b = yymsp[0].minor.yy384;}
141338
+ break;
141339
+ case 233: /* when_clause ::= */
141340
+ case 252: /* key_opt ::= */ yytestcase(yyruleno==252);
141341
+{ yymsp[1].minor.yy314 = 0; }
141342
+ break;
141343
+ case 234: /* when_clause ::= WHEN expr */
141344
+ case 253: /* key_opt ::= KEY expr */ yytestcase(yyruleno==253);
141345
+{ yymsp[-1].minor.yy314 = yymsp[0].minor.yy314; }
141346
+ break;
141347
+ case 235: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
141348
+{
141349
+ assert( yymsp[-2].minor.yy203!=0 );
141350
+ yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203;
141351
+ yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203;
141352
+}
141353
+ break;
141354
+ case 236: /* trigger_cmd_list ::= trigger_cmd SEMI */
141355
+{
141356
+ assert( yymsp[-1].minor.yy203!=0 );
141357
+ yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203;
141358
+}
141359
+ break;
141360
+ case 237: /* trnm ::= nm DOT nm */
140944141361
{
140945141362
yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
140946141363
sqlite3ErrorMsg(pParse,
140947141364
"qualified table names are not allowed on INSERT, UPDATE, and DELETE "
140948141365
"statements within triggers");
140949141366
}
140950141367
break;
140951
- case 237: /* tridxby ::= INDEXED BY nm */
141368
+ case 238: /* tridxby ::= INDEXED BY nm */
140952141369
{
140953141370
sqlite3ErrorMsg(pParse,
140954141371
"the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
140955141372
"within triggers");
140956141373
}
140957141374
break;
140958
- case 238: /* tridxby ::= NOT INDEXED */
141375
+ case 239: /* tridxby ::= NOT INDEXED */
140959141376
{
140960141377
sqlite3ErrorMsg(pParse,
140961141378
"the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
140962141379
"within triggers");
140963141380
}
140964141381
break;
140965
- case 239: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
140966
-{yymsp[-6].minor.yy145 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy148, yymsp[0].minor.yy72, yymsp[-5].minor.yy194);}
140967
- break;
140968
- case 240: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
140969
-{yymsp[-4].minor.yy145 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy254, yymsp[0].minor.yy243, yymsp[-4].minor.yy194);/*A-overwrites-R*/}
140970
- break;
140971
- case 241: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
140972
-{yymsp[-4].minor.yy145 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy72);}
140973
- break;
140974
- case 242: /* trigger_cmd ::= select */
140975
-{yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/}
140976
- break;
140977
- case 243: /* expr ::= RAISE LP IGNORE RP */
140978
-{
140979
- spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140980
- yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
140981
- if( yymsp[-3].minor.yy190.pExpr ){
140982
- yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore;
140983
- }
140984
-}
140985
- break;
140986
- case 244: /* expr ::= RAISE LP raisetype COMMA nm RP */
140987
-{
140988
- spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140989
- yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
140990
- if( yymsp[-5].minor.yy190.pExpr ) {
140991
- yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194;
140992
- }
140993
-}
140994
- break;
140995
- case 245: /* raisetype ::= ROLLBACK */
140996
-{yymsp[0].minor.yy194 = OE_Rollback;}
140997
- break;
140998
- case 247: /* raisetype ::= FAIL */
140999
-{yymsp[0].minor.yy194 = OE_Fail;}
141000
- break;
141001
- case 248: /* cmd ::= DROP TRIGGER ifexists fullname */
141002
-{
141003
- sqlite3DropTrigger(pParse,yymsp[0].minor.yy185,yymsp[-1].minor.yy194);
141004
-}
141005
- break;
141006
- case 249: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
141007
-{
141008
- sqlite3Attach(pParse, yymsp[-3].minor.yy190.pExpr, yymsp[-1].minor.yy190.pExpr, yymsp[0].minor.yy72);
141009
-}
141010
- break;
141011
- case 250: /* cmd ::= DETACH database_kw_opt expr */
141012
-{
141013
- sqlite3Detach(pParse, yymsp[0].minor.yy190.pExpr);
141014
-}
141015
- break;
141016
- case 253: /* cmd ::= REINDEX */
141382
+ case 240: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
141383
+{yylhsminor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy314, yymsp[-6].minor.yy4, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy336);}
141384
+ yymsp[-7].minor.yy203 = yylhsminor.yy203;
141385
+ break;
141386
+ case 241: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt */
141387
+{yylhsminor.yy203 = sqlite3TriggerInsertStep(pParse->db,&yymsp[-3].minor.yy0,yymsp[-2].minor.yy384,yymsp[-1].minor.yy387,yymsp[-5].minor.yy4,yymsp[-6].minor.yy336,yymsp[0].minor.yy336);/*yylhsminor.yy203-overwrites-yymsp[-5].minor.yy4*/}
141388
+ yymsp[-6].minor.yy203 = yylhsminor.yy203;
141389
+ break;
141390
+ case 242: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
141391
+{yylhsminor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy314, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy336);}
141392
+ yymsp[-5].minor.yy203 = yylhsminor.yy203;
141393
+ break;
141394
+ case 243: /* trigger_cmd ::= scanpt select scanpt */
141395
+{yylhsminor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy387, yymsp[-2].minor.yy336, yymsp[0].minor.yy336); /*yylhsminor.yy203-overwrites-yymsp[-1].minor.yy387*/}
141396
+ yymsp[-2].minor.yy203 = yylhsminor.yy203;
141397
+ break;
141398
+ case 244: /* expr ::= RAISE LP IGNORE RP */
141399
+{
141400
+ yymsp[-3].minor.yy314 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
141401
+ if( yymsp[-3].minor.yy314 ){
141402
+ yymsp[-3].minor.yy314->affinity = OE_Ignore;
141403
+ }
141404
+}
141405
+ break;
141406
+ case 245: /* expr ::= RAISE LP raisetype COMMA nm RP */
141407
+{
141408
+ yymsp[-5].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
141409
+ if( yymsp[-5].minor.yy314 ) {
141410
+ yymsp[-5].minor.yy314->affinity = (char)yymsp[-3].minor.yy4;
141411
+ }
141412
+}
141413
+ break;
141414
+ case 246: /* raisetype ::= ROLLBACK */
141415
+{yymsp[0].minor.yy4 = OE_Rollback;}
141416
+ break;
141417
+ case 248: /* raisetype ::= FAIL */
141418
+{yymsp[0].minor.yy4 = OE_Fail;}
141419
+ break;
141420
+ case 249: /* cmd ::= DROP TRIGGER ifexists fullname */
141421
+{
141422
+ sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4);
141423
+}
141424
+ break;
141425
+ case 250: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
141426
+{
141427
+ sqlite3Attach(pParse, yymsp[-3].minor.yy314, yymsp[-1].minor.yy314, yymsp[0].minor.yy314);
141428
+}
141429
+ break;
141430
+ case 251: /* cmd ::= DETACH database_kw_opt expr */
141431
+{
141432
+ sqlite3Detach(pParse, yymsp[0].minor.yy314);
141433
+}
141434
+ break;
141435
+ case 254: /* cmd ::= REINDEX */
141017141436
{sqlite3Reindex(pParse, 0, 0);}
141018141437
break;
141019
- case 254: /* cmd ::= REINDEX nm dbnm */
141438
+ case 255: /* cmd ::= REINDEX nm dbnm */
141020141439
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
141021141440
break;
141022
- case 255: /* cmd ::= ANALYZE */
141441
+ case 256: /* cmd ::= ANALYZE */
141023141442
{sqlite3Analyze(pParse, 0, 0);}
141024141443
break;
141025
- case 256: /* cmd ::= ANALYZE nm dbnm */
141444
+ case 257: /* cmd ::= ANALYZE nm dbnm */
141026141445
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
141027141446
break;
141028
- case 257: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
141447
+ case 258: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
141029141448
{
141030
- sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy185,&yymsp[0].minor.yy0);
141449
+ sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0);
141031141450
}
141032141451
break;
141033
- case 258: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
141452
+ case 259: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
141034141453
{
141035141454
yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
141036141455
sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
141037141456
}
141038141457
break;
141039
- case 259: /* add_column_fullname ::= fullname */
141458
+ case 260: /* add_column_fullname ::= fullname */
141040141459
{
141041141460
disableLookaside(pParse);
141042
- sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy185);
141461
+ sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259);
141043141462
}
141044141463
break;
141045
- case 260: /* cmd ::= create_vtab */
141464
+ case 261: /* cmd ::= create_vtab */
141046141465
{sqlite3VtabFinishParse(pParse,0);}
141047141466
break;
141048
- case 261: /* cmd ::= create_vtab LP vtabarglist RP */
141467
+ case 262: /* cmd ::= create_vtab LP vtabarglist RP */
141049141468
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
141050141469
break;
141051
- case 262: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
141470
+ case 263: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
141052141471
{
141053
- sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy194);
141472
+ sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy4);
141054141473
}
141055141474
break;
141056
- case 263: /* vtabarg ::= */
141475
+ case 264: /* vtabarg ::= */
141057141476
{sqlite3VtabArgInit(pParse);}
141058141477
break;
141059
- case 264: /* vtabargtoken ::= ANY */
141060
- case 265: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==265);
141061
- case 266: /* lp ::= LP */ yytestcase(yyruleno==266);
141478
+ case 265: /* vtabargtoken ::= ANY */
141479
+ case 266: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==266);
141480
+ case 267: /* lp ::= LP */ yytestcase(yyruleno==267);
141062141481
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
141063141482
break;
141064
- case 267: /* with ::= */
141065
-{yymsp[1].minor.yy285 = 0;}
141066
- break;
141067
- case 268: /* with ::= WITH wqlist */
141068
-{ yymsp[-1].minor.yy285 = yymsp[0].minor.yy285; }
141069
- break;
141070
- case 269: /* with ::= WITH RECURSIVE wqlist */
141071
-{ yymsp[-2].minor.yy285 = yymsp[0].minor.yy285; }
141072
- break;
141073
- case 270: /* wqlist ::= nm eidlist_opt AS LP select RP */
141074
-{
141075
- yymsp[-5].minor.yy285 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); /*A-overwrites-X*/
141076
-}
141077
- break;
141078
- case 271: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
141079
-{
141080
- yymsp[-7].minor.yy285 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy285, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243);
141483
+ case 268: /* with ::= */
141484
+{yymsp[1].minor.yy451 = 0;}
141485
+ break;
141486
+ case 269: /* with ::= WITH wqlist */
141487
+{ yymsp[-1].minor.yy451 = yymsp[0].minor.yy451; }
141488
+ break;
141489
+ case 270: /* with ::= WITH RECURSIVE wqlist */
141490
+{ yymsp[-2].minor.yy451 = yymsp[0].minor.yy451; }
141491
+ break;
141492
+ case 271: /* wqlist ::= nm eidlist_opt AS LP select RP */
141493
+{
141494
+ yymsp[-5].minor.yy451 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy387); /*A-overwrites-X*/
141495
+}
141496
+ break;
141497
+ case 272: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
141498
+{
141499
+ yymsp[-7].minor.yy451 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy451, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy387);
141081141500
}
141082141501
break;
141083141502
default:
141084
- /* (272) input ::= cmdlist */ yytestcase(yyruleno==272);
141085
- /* (273) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==273);
141086
- /* (274) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=274);
141087
- /* (275) ecmd ::= SEMI */ yytestcase(yyruleno==275);
141088
- /* (276) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==276);
141089
- /* (277) explain ::= */ yytestcase(yyruleno==277);
141090
- /* (278) trans_opt ::= */ yytestcase(yyruleno==278);
141091
- /* (279) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==279);
141092
- /* (280) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==280);
141093
- /* (281) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==281);
141094
- /* (282) savepoint_opt ::= */ yytestcase(yyruleno==282);
141095
- /* (283) cmd ::= create_table create_table_args */ yytestcase(yyruleno==283);
141096
- /* (284) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==284);
141097
- /* (285) columnlist ::= columnname carglist */ yytestcase(yyruleno==285);
141098
- /* (286) nm ::= ID|INDEXED */ yytestcase(yyruleno==286);
141099
- /* (287) nm ::= STRING */ yytestcase(yyruleno==287);
141100
- /* (288) nm ::= JOIN_KW */ yytestcase(yyruleno==288);
141101
- /* (289) typetoken ::= typename */ yytestcase(yyruleno==289);
141102
- /* (290) typename ::= ID|STRING */ yytestcase(yyruleno==290);
141103
- /* (291) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=291);
141104
- /* (292) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=292);
141105
- /* (293) carglist ::= carglist ccons */ yytestcase(yyruleno==293);
141106
- /* (294) carglist ::= */ yytestcase(yyruleno==294);
141107
- /* (295) ccons ::= NULL onconf */ yytestcase(yyruleno==295);
141108
- /* (296) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==296);
141109
- /* (297) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==297);
141110
- /* (298) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=298);
141111
- /* (299) tconscomma ::= */ yytestcase(yyruleno==299);
141112
- /* (300) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=300);
141113
- /* (301) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=301);
141114
- /* (302) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=302);
141115
- /* (303) oneselect ::= values */ yytestcase(yyruleno==303);
141116
- /* (304) sclp ::= selcollist COMMA */ yytestcase(yyruleno==304);
141117
- /* (305) as ::= ID|STRING */ yytestcase(yyruleno==305);
141118
- /* (306) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=306);
141119
- /* (307) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==307);
141120
- /* (308) exprlist ::= nexprlist */ yytestcase(yyruleno==308);
141121
- /* (309) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=309);
141122
- /* (310) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=310);
141123
- /* (311) nmnum ::= ON */ yytestcase(yyruleno==311);
141124
- /* (312) nmnum ::= DELETE */ yytestcase(yyruleno==312);
141125
- /* (313) nmnum ::= DEFAULT */ yytestcase(yyruleno==313);
141126
- /* (314) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==314);
141127
- /* (315) foreach_clause ::= */ yytestcase(yyruleno==315);
141128
- /* (316) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==316);
141129
- /* (317) trnm ::= nm */ yytestcase(yyruleno==317);
141130
- /* (318) tridxby ::= */ yytestcase(yyruleno==318);
141131
- /* (319) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==319);
141132
- /* (320) database_kw_opt ::= */ yytestcase(yyruleno==320);
141133
- /* (321) kwcolumn_opt ::= */ yytestcase(yyruleno==321);
141134
- /* (322) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==322);
141135
- /* (323) vtabarglist ::= vtabarg */ yytestcase(yyruleno==323);
141136
- /* (324) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==324);
141137
- /* (325) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==325);
141138
- /* (326) anylist ::= */ yytestcase(yyruleno==326);
141139
- /* (327) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==327);
141140
- /* (328) anylist ::= anylist ANY */ yytestcase(yyruleno==328);
141503
+ /* (273) input ::= cmdlist */ yytestcase(yyruleno==273);
141504
+ /* (274) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==274);
141505
+ /* (275) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=275);
141506
+ /* (276) ecmd ::= SEMI */ yytestcase(yyruleno==276);
141507
+ /* (277) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==277);
141508
+ /* (278) explain ::= */ yytestcase(yyruleno==278);
141509
+ /* (279) trans_opt ::= */ yytestcase(yyruleno==279);
141510
+ /* (280) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==280);
141511
+ /* (281) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==281);
141512
+ /* (282) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==282);
141513
+ /* (283) savepoint_opt ::= */ yytestcase(yyruleno==283);
141514
+ /* (284) cmd ::= create_table create_table_args */ yytestcase(yyruleno==284);
141515
+ /* (285) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==285);
141516
+ /* (286) columnlist ::= columnname carglist */ yytestcase(yyruleno==286);
141517
+ /* (287) nm ::= ID|INDEXED */ yytestcase(yyruleno==287);
141518
+ /* (288) nm ::= STRING */ yytestcase(yyruleno==288);
141519
+ /* (289) nm ::= JOIN_KW */ yytestcase(yyruleno==289);
141520
+ /* (290) typetoken ::= typename */ yytestcase(yyruleno==290);
141521
+ /* (291) typename ::= ID|STRING */ yytestcase(yyruleno==291);
141522
+ /* (292) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=292);
141523
+ /* (293) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=293);
141524
+ /* (294) carglist ::= carglist ccons */ yytestcase(yyruleno==294);
141525
+ /* (295) carglist ::= */ yytestcase(yyruleno==295);
141526
+ /* (296) ccons ::= NULL onconf */ yytestcase(yyruleno==296);
141527
+ /* (297) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==297);
141528
+ /* (298) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==298);
141529
+ /* (299) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=299);
141530
+ /* (300) tconscomma ::= */ yytestcase(yyruleno==300);
141531
+ /* (301) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=301);
141532
+ /* (302) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=302);
141533
+ /* (303) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=303);
141534
+ /* (304) oneselect ::= values */ yytestcase(yyruleno==304);
141535
+ /* (305) sclp ::= selcollist COMMA */ yytestcase(yyruleno==305);
141536
+ /* (306) as ::= ID|STRING */ yytestcase(yyruleno==306);
141537
+ /* (307) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=307);
141538
+ /* (308) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==308);
141539
+ /* (309) exprlist ::= nexprlist */ yytestcase(yyruleno==309);
141540
+ /* (310) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=310);
141541
+ /* (311) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=311);
141542
+ /* (312) nmnum ::= ON */ yytestcase(yyruleno==312);
141543
+ /* (313) nmnum ::= DELETE */ yytestcase(yyruleno==313);
141544
+ /* (314) nmnum ::= DEFAULT */ yytestcase(yyruleno==314);
141545
+ /* (315) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==315);
141546
+ /* (316) foreach_clause ::= */ yytestcase(yyruleno==316);
141547
+ /* (317) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==317);
141548
+ /* (318) trnm ::= nm */ yytestcase(yyruleno==318);
141549
+ /* (319) tridxby ::= */ yytestcase(yyruleno==319);
141550
+ /* (320) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==320);
141551
+ /* (321) database_kw_opt ::= */ yytestcase(yyruleno==321);
141552
+ /* (322) kwcolumn_opt ::= */ yytestcase(yyruleno==322);
141553
+ /* (323) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==323);
141554
+ /* (324) vtabarglist ::= vtabarg */ yytestcase(yyruleno==324);
141555
+ /* (325) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==325);
141556
+ /* (326) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==326);
141557
+ /* (327) anylist ::= */ yytestcase(yyruleno==327);
141558
+ /* (328) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==328);
141559
+ /* (329) anylist ::= anylist ANY */ yytestcase(yyruleno==329);
141141141560
break;
141142141561
/********** End reduce actions ************************************************/
141143141562
};
141144141563
assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
141145141564
yygoto = yyRuleInfo[yyruleno].lhs;
@@ -141151,20 +141570,15 @@
141151141570
assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
141152141571
141153141572
/* It is not possible for a REDUCE to be followed by an error */
141154141573
assert( yyact!=YY_ERROR_ACTION );
141155141574
141156
- if( yyact==YY_ACCEPT_ACTION ){
141157
- yypParser->yytos += yysize;
141158
- yy_accept(yypParser);
141159
- }else{
141160
- yymsp += yysize+1;
141161
- yypParser->yytos = yymsp;
141162
- yymsp->stateno = (YYACTIONTYPE)yyact;
141163
- yymsp->major = (YYCODETYPE)yygoto;
141164
- yyTraceShift(yypParser, yyact);
141165
- }
141575
+ yymsp += yysize+1;
141576
+ yypParser->yytos = yymsp;
141577
+ yymsp->stateno = (YYACTIONTYPE)yyact;
141578
+ yymsp->major = (YYCODETYPE)yygoto;
141579
+ yyTraceShift(yypParser, yyact, "... then shift");
141166141580
}
141167141581
141168141582
/*
141169141583
** The following code executes when the parse fails
141170141584
*/
@@ -141271,24 +141685,35 @@
141271141685
#endif
141272141686
sqlite3ParserARG_STORE;
141273141687
141274141688
#ifndef NDEBUG
141275141689
if( yyTraceFILE ){
141276
- fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]);
141690
+ int stateno = yypParser->yytos->stateno;
141691
+ if( stateno < YY_MIN_REDUCE ){
141692
+ fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
141693
+ yyTracePrompt,yyTokenName[yymajor],stateno);
141694
+ }else{
141695
+ fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
141696
+ yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE);
141697
+ }
141277141698
}
141278141699
#endif
141279141700
141280141701
do{
141281141702
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
141282
- if( yyact <= YY_MAX_SHIFTREDUCE ){
141703
+ if( yyact >= YY_MIN_REDUCE ){
141704
+ yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor);
141705
+ }else if( yyact <= YY_MAX_SHIFTREDUCE ){
141283141706
yy_shift(yypParser,yyact,yymajor,yyminor);
141284141707
#ifndef YYNOERRORRECOVERY
141285141708
yypParser->yyerrcnt--;
141286141709
#endif
141287141710
yymajor = YYNOCODE;
141288
- }else if( yyact <= YY_MAX_REDUCE ){
141289
- yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
141711
+ }else if( yyact==YY_ACCEPT_ACTION ){
141712
+ yypParser->yytos--;
141713
+ yy_accept(yypParser);
141714
+ return;
141290141715
}else{
141291141716
assert( yyact == YY_ERROR_ACTION );
141292141717
yyminorunion.yy0 = yyminor;
141293141718
#ifdef YYERRORSYMBOL
141294141719
int yymx;
@@ -143527,10 +143952,11 @@
143527143952
{ SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
143528143953
{ SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
143529143954
{ SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension },
143530143955
{ SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose },
143531143956
{ SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG },
143957
+ { SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP },
143532143958
};
143533143959
unsigned int i;
143534143960
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
143535143961
for(i=0; i<ArraySize(aFlagOp); i++){
143536143962
if( aFlagOp[i].op==op ){
@@ -146620,10 +147046,26 @@
146620147046
sqlite3ResetAllSchemasOfConnection(db);
146621147047
}
146622147048
sqlite3_mutex_leave(db->mutex);
146623147049
break;
146624147050
}
147051
+
147052
+#if defined(YYCOVERAGE)
147053
+ /* sqlite3_test_control(SQLITE_TESTCTRL_PARSER_COVERAGE, FILE *out)
147054
+ **
147055
+ ** This test control (only available when SQLite is compiled with
147056
+ ** -DYYCOVERAGE) writes a report onto "out" that shows all
147057
+ ** state/lookahead combinations in the parser state machine
147058
+ ** which are never exercised. If any state is missed, make the
147059
+ ** return code SQLITE_ERROR.
147060
+ */
147061
+ case SQLITE_TESTCTRL_PARSER_COVERAGE: {
147062
+ FILE *out = va_arg(ap, FILE*);
147063
+ if( sqlite3ParserCoverage(out) ) rc = SQLITE_ERROR;
147064
+ break;
147065
+ }
147066
+#endif /* defined(YYCOVERAGE) */
146625147067
}
146626147068
va_end(ap);
146627147069
#endif /* SQLITE_UNTESTABLE */
146628147070
return rc;
146629147071
}
@@ -168393,11 +168835,11 @@
168393168835
int iHeight, /* Height of sub-tree rooted at pCell */
168394168836
RtreeNode **ppLeaf /* OUT: Selected leaf page */
168395168837
){
168396168838
int rc;
168397168839
int ii;
168398
- RtreeNode *pNode;
168840
+ RtreeNode *pNode = 0;
168399168841
rc = nodeAcquire(pRtree, 1, 0, &pNode);
168400168842
168401168843
for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
168402168844
int iCell;
168403168845
sqlite3_int64 iBest = 0;
@@ -169268,11 +169710,11 @@
169268169710
** the root node (the operation that Gutman's paper says to perform
169269169711
** in this scenario).
169270169712
*/
169271169713
if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
169272169714
int rc2;
169273
- RtreeNode *pChild;
169715
+ RtreeNode *pChild = 0;
169274169716
i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
169275169717
rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
169276169718
if( rc==SQLITE_OK ){
169277169719
rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
169278169720
}
@@ -186623,18 +187065,19 @@
186623187065
** sqlite3Fts5ParserARG_FETCH Code to extract %extra_argument from fts5yypParser
186624187066
** fts5YYERRORSYMBOL is the code number of the error symbol. If not
186625187067
** defined, then do no error processing.
186626187068
** fts5YYNSTATE the combined number of states.
186627187069
** fts5YYNRULE the number of rules in the grammar
187070
+** fts5YYNFTS5TOKEN Number of terminal symbols
186628187071
** fts5YY_MAX_SHIFT Maximum value for shift actions
186629187072
** fts5YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
186630187073
** fts5YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
186631
-** fts5YY_MIN_REDUCE Minimum value for reduce actions
186632
-** fts5YY_MAX_REDUCE Maximum value for reduce actions
186633187074
** fts5YY_ERROR_ACTION The fts5yy_action[] code for syntax error
186634187075
** fts5YY_ACCEPT_ACTION The fts5yy_action[] code for accept
186635187076
** fts5YY_NO_ACTION The fts5yy_action[] code for no-op
187077
+** fts5YY_MIN_REDUCE Minimum value for reduce actions
187078
+** fts5YY_MAX_REDUCE Maximum value for reduce actions
186636187079
*/
186637187080
#ifndef INTERFACE
186638187081
# define INTERFACE 1
186639187082
#endif
186640187083
/************* Begin control #defines *****************************************/
@@ -186658,18 +187101,19 @@
186658187101
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
186659187102
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
186660187103
#define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
186661187104
#define fts5YYNSTATE 35
186662187105
#define fts5YYNRULE 28
187106
+#define fts5YYNFTS5TOKEN 16
186663187107
#define fts5YY_MAX_SHIFT 34
186664187108
#define fts5YY_MIN_SHIFTREDUCE 52
186665187109
#define fts5YY_MAX_SHIFTREDUCE 79
186666
-#define fts5YY_MIN_REDUCE 80
186667
-#define fts5YY_MAX_REDUCE 107
186668
-#define fts5YY_ERROR_ACTION 108
186669
-#define fts5YY_ACCEPT_ACTION 109
186670
-#define fts5YY_NO_ACTION 110
187110
+#define fts5YY_ERROR_ACTION 80
187111
+#define fts5YY_ACCEPT_ACTION 81
187112
+#define fts5YY_NO_ACTION 82
187113
+#define fts5YY_MIN_REDUCE 83
187114
+#define fts5YY_MAX_REDUCE 110
186671187115
/************* End control #defines *******************************************/
186672187116
186673187117
/* Define the fts5yytestcase() macro to be a no-op if is not already defined
186674187118
** otherwise.
186675187119
**
@@ -186695,39 +187139,33 @@
186695187139
** token onto the stack and goto state N.
186696187140
**
186697187141
** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
186698187142
** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
186699187143
**
186700
-** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
186701
-** and fts5YY_MAX_REDUCE
186702
-**
186703187144
** N == fts5YY_ERROR_ACTION A syntax error has occurred.
186704187145
**
186705187146
** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
186706187147
**
186707187148
** N == fts5YY_NO_ACTION No such action. Denotes unused
186708187149
** slots in the fts5yy_action[] table.
187150
+**
187151
+** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
187152
+** and fts5YY_MAX_REDUCE
186709187153
**
186710187154
** The action table is constructed as a single large table named fts5yy_action[].
186711187155
** Given state S and lookahead X, the action is computed as either:
186712187156
**
186713187157
** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
186714187158
** (B) N = fts5yy_default[S]
186715187159
**
186716
-** The (A) formula is preferred. The B formula is used instead if:
186717
-** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
186718
-** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
186719
-** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
186720
-** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
186721
-** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
186722
-** Hence only tests (1) and (2) need to be evaluated.)
187160
+** The (A) formula is preferred. The B formula is used instead if
187161
+** fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X.
186723187162
**
186724187163
** The formulas above are for computing the action when the lookahead is
186725187164
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
186726187165
** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
186727
-** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
186728
-** fts5YY_SHIFT_USE_DFLT.
187166
+** the fts5yy_shift_ofst[] array.
186729187167
**
186730187168
** The following are the tables generated in this section:
186731187169
**
186732187170
** fts5yy_action[] A single table containing all actions.
186733187171
** fts5yy_lookahead[] A table containing the lookahead for each entry in
@@ -186739,19 +187177,19 @@
186739187177
** fts5yy_default[] Default action for each state.
186740187178
**
186741187179
*********** Begin parsing tables **********************************************/
186742187180
#define fts5YY_ACTTAB_COUNT (105)
186743187181
static const fts5YYACTIONTYPE fts5yy_action[] = {
186744
- /* 0 */ 109, 20, 93, 6, 28, 96, 95, 26, 26, 18,
186745
- /* 10 */ 93, 6, 28, 17, 95, 56, 26, 19, 93, 6,
186746
- /* 20 */ 28, 14, 95, 105, 26, 89, 93, 6, 28, 25,
186747
- /* 30 */ 95, 78, 26, 21, 93, 6, 28, 104, 95, 58,
186748
- /* 40 */ 26, 29, 93, 6, 28, 32, 95, 22, 26, 24,
187182
+ /* 0 */ 81, 20, 96, 6, 28, 99, 98, 26, 26, 18,
187183
+ /* 10 */ 96, 6, 28, 17, 98, 56, 26, 19, 96, 6,
187184
+ /* 20 */ 28, 14, 98, 108, 26, 92, 96, 6, 28, 25,
187185
+ /* 30 */ 98, 78, 26, 21, 96, 6, 28, 107, 98, 58,
187186
+ /* 40 */ 26, 29, 96, 6, 28, 32, 98, 22, 26, 24,
186749187187
/* 50 */ 16, 23, 11, 1, 14, 13, 24, 16, 31, 11,
186750
- /* 60 */ 3, 94, 13, 27, 8, 95, 82, 26, 7, 4,
186751
- /* 70 */ 5, 3, 4, 5, 3, 80, 4, 5, 3, 63,
186752
- /* 80 */ 33, 34, 62, 12, 2, 83, 13, 10, 12, 71,
187188
+ /* 60 */ 3, 97, 13, 27, 8, 98, 82, 26, 7, 4,
187189
+ /* 70 */ 5, 3, 4, 5, 3, 83, 4, 5, 3, 63,
187190
+ /* 80 */ 33, 34, 62, 12, 2, 86, 13, 10, 12, 71,
186753187191
/* 90 */ 10, 13, 78, 5, 3, 78, 9, 30, 75, 82,
186754187192
/* 100 */ 54, 57, 53, 57, 15,
186755187193
};
186756187194
static const fts5YYCODETYPE fts5yy_lookahead[] = {
186757187195
/* 0 */ 17, 18, 19, 20, 21, 23, 23, 25, 25, 18,
@@ -186762,35 +187200,35 @@
186762187200
/* 50 */ 7, 22, 9, 10, 9, 12, 6, 7, 13, 9,
186763187201
/* 60 */ 3, 19, 12, 21, 5, 23, 28, 25, 5, 1,
186764187202
/* 70 */ 2, 3, 1, 2, 3, 0, 1, 2, 3, 11,
186765187203
/* 80 */ 25, 26, 11, 9, 10, 5, 12, 10, 9, 11,
186766187204
/* 90 */ 10, 12, 15, 2, 3, 15, 24, 25, 9, 28,
186767
- /* 100 */ 8, 9, 8, 9, 9,
187205
+ /* 100 */ 8, 9, 8, 9, 9, 28, 28, 28, 28, 28,
187206
+ /* 110 */ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
187207
+ /* 120 */ 28,
186768187208
};
186769
-#define fts5YY_SHIFT_USE_DFLT (105)
186770187209
#define fts5YY_SHIFT_COUNT (34)
186771187210
#define fts5YY_SHIFT_MIN (0)
186772187211
#define fts5YY_SHIFT_MAX (95)
186773187212
static const unsigned char fts5yy_shift_ofst[] = {
186774187213
/* 0 */ 43, 43, 43, 43, 43, 43, 50, 74, 79, 45,
186775187214
/* 10 */ 12, 80, 77, 12, 16, 16, 30, 30, 68, 71,
186776187215
/* 20 */ 75, 91, 92, 94, 6, 31, 31, 59, 63, 57,
186777187216
/* 30 */ 31, 89, 95, 31, 78,
186778187217
};
186779
-#define fts5YY_REDUCE_USE_DFLT (-19)
186780187218
#define fts5YY_REDUCE_COUNT (17)
186781187219
#define fts5YY_REDUCE_MIN (-18)
186782187220
#define fts5YY_REDUCE_MAX (72)
186783187221
static const signed char fts5yy_reduce_ofst[] = {
186784187222
/* 0 */ -17, -9, -1, 7, 15, 23, 42, -18, -18, 55,
186785187223
/* 10 */ 72, -4, -4, 4, -4, 10, 25, 29,
186786187224
};
186787187225
static const fts5YYACTIONTYPE fts5yy_default[] = {
186788
- /* 0 */ 108, 108, 108, 108, 108, 108, 92, 108, 108, 102,
186789
- /* 10 */ 108, 107, 107, 108, 107, 107, 108, 108, 108, 108,
186790
- /* 20 */ 108, 88, 108, 108, 108, 98, 97, 108, 108, 87,
186791
- /* 30 */ 100, 108, 108, 101, 108,
187226
+ /* 0 */ 80, 80, 80, 80, 80, 80, 95, 80, 80, 105,
187227
+ /* 10 */ 80, 110, 110, 80, 110, 110, 80, 80, 80, 80,
187228
+ /* 20 */ 80, 91, 80, 80, 80, 101, 100, 80, 80, 90,
187229
+ /* 30 */ 103, 80, 80, 104, 80,
186792187230
};
186793187231
/********** End of lemon-generated parsing tables *****************************/
186794187232
186795187233
/* The next table maps tokens (terminal symbols) into fallback tokens.
186796187234
** If a construct like the following:
@@ -186888,23 +187326,44 @@
186888187326
if( fts5yyTraceFILE==0 ) fts5yyTracePrompt = 0;
186889187327
else if( fts5yyTracePrompt==0 ) fts5yyTraceFILE = 0;
186890187328
}
186891187329
#endif /* NDEBUG */
186892187330
186893
-#ifndef NDEBUG
187331
+#if defined(fts5YYCOVERAGE) || !defined(NDEBUG)
186894187332
/* For tracing shifts, the names of all terminals and nonterminals
186895187333
** are required. The following table supplies these names */
186896187334
static const char *const fts5yyTokenName[] = {
186897
- "$", "OR", "AND", "NOT",
186898
- "TERM", "COLON", "MINUS", "LCP",
186899
- "RCP", "STRING", "LP", "RP",
186900
- "CARET", "COMMA", "PLUS", "STAR",
186901
- "error", "input", "expr", "cnearset",
186902
- "exprlist", "colset", "colsetlist", "nearset",
186903
- "nearphrases", "phrase", "neardist_opt", "star_opt",
187335
+ /* 0 */ "$",
187336
+ /* 1 */ "OR",
187337
+ /* 2 */ "AND",
187338
+ /* 3 */ "NOT",
187339
+ /* 4 */ "TERM",
187340
+ /* 5 */ "COLON",
187341
+ /* 6 */ "MINUS",
187342
+ /* 7 */ "LCP",
187343
+ /* 8 */ "RCP",
187344
+ /* 9 */ "STRING",
187345
+ /* 10 */ "LP",
187346
+ /* 11 */ "RP",
187347
+ /* 12 */ "CARET",
187348
+ /* 13 */ "COMMA",
187349
+ /* 14 */ "PLUS",
187350
+ /* 15 */ "STAR",
187351
+ /* 16 */ "error",
187352
+ /* 17 */ "input",
187353
+ /* 18 */ "expr",
187354
+ /* 19 */ "cnearset",
187355
+ /* 20 */ "exprlist",
187356
+ /* 21 */ "colset",
187357
+ /* 22 */ "colsetlist",
187358
+ /* 23 */ "nearset",
187359
+ /* 24 */ "nearphrases",
187360
+ /* 25 */ "phrase",
187361
+ /* 26 */ "neardist_opt",
187362
+ /* 27 */ "star_opt",
186904187363
};
186905
-#endif /* NDEBUG */
187364
+#endif /* defined(fts5YYCOVERAGE) || !defined(NDEBUG) */
186906187365
186907187366
#ifndef NDEBUG
186908187367
/* For tracing reduce actions, the names of all rules are required.
186909187368
*/
186910187369
static const char *const fts5yyRuleName[] = {
@@ -187151,10 +187610,47 @@
187151187610
fts5yyParser *pParser = (fts5yyParser*)p;
187152187611
return pParser->fts5yyhwm;
187153187612
}
187154187613
#endif
187155187614
187615
+/* This array of booleans keeps track of the parser statement
187616
+** coverage. The element fts5yycoverage[X][Y] is set when the parser
187617
+** is in state X and has a lookahead token Y. In a well-tested
187618
+** systems, every element of this matrix should end up being set.
187619
+*/
187620
+#if defined(fts5YYCOVERAGE)
187621
+static unsigned char fts5yycoverage[fts5YYNSTATE][fts5YYNFTS5TOKEN];
187622
+#endif
187623
+
187624
+/*
187625
+** Write into out a description of every state/lookahead combination that
187626
+**
187627
+** (1) has not been used by the parser, and
187628
+** (2) is not a syntax error.
187629
+**
187630
+** Return the number of missed state/lookahead combinations.
187631
+*/
187632
+#if defined(fts5YYCOVERAGE)
187633
+static int sqlite3Fts5ParserCoverage(FILE *out){
187634
+ int stateno, iLookAhead, i;
187635
+ int nMissed = 0;
187636
+ for(stateno=0; stateno<fts5YYNSTATE; stateno++){
187637
+ i = fts5yy_shift_ofst[stateno];
187638
+ for(iLookAhead=0; iLookAhead<fts5YYNFTS5TOKEN; iLookAhead++){
187639
+ if( fts5yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
187640
+ if( fts5yycoverage[stateno][iLookAhead]==0 ) nMissed++;
187641
+ if( out ){
187642
+ fprintf(out,"State %d lookahead %s %s\n", stateno,
187643
+ fts5yyTokenName[iLookAhead],
187644
+ fts5yycoverage[stateno][iLookAhead] ? "ok" : "missed");
187645
+ }
187646
+ }
187647
+ }
187648
+ return nMissed;
187649
+}
187650
+#endif
187651
+
187156187652
/*
187157187653
** Find the appropriate action for a parser given the terminal
187158187654
** look-ahead token iLookAhead.
187159187655
*/
187160187656
static unsigned int fts5yy_find_shift_action(
@@ -187162,17 +187658,22 @@
187162187658
fts5YYCODETYPE iLookAhead /* The look-ahead token */
187163187659
){
187164187660
int i;
187165187661
int stateno = pParser->fts5yytos->stateno;
187166187662
187167
- if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
187663
+ if( stateno>fts5YY_MAX_SHIFT ) return stateno;
187168187664
assert( stateno <= fts5YY_SHIFT_COUNT );
187665
+#if defined(fts5YYCOVERAGE)
187666
+ fts5yycoverage[stateno][iLookAhead] = 1;
187667
+#endif
187169187668
do{
187170187669
i = fts5yy_shift_ofst[stateno];
187670
+ assert( i>=0 && i+fts5YYNFTS5TOKEN<=sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0]) );
187171187671
assert( iLookAhead!=fts5YYNOCODE );
187672
+ assert( iLookAhead < fts5YYNFTS5TOKEN );
187172187673
i += iLookAhead;
187173
- if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
187674
+ if( fts5yy_lookahead[i]!=iLookAhead ){
187174187675
#ifdef fts5YYFALLBACK
187175187676
fts5YYCODETYPE iFallback; /* Fallback token */
187176187677
if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
187177187678
&& (iFallback = fts5yyFallback[iLookAhead])!=0 ){
187178187679
#ifndef NDEBUG
@@ -187231,11 +187732,10 @@
187231187732
}
187232187733
#else
187233187734
assert( stateno<=fts5YY_REDUCE_COUNT );
187234187735
#endif
187235187736
i = fts5yy_reduce_ofst[stateno];
187236
- assert( i!=fts5YY_REDUCE_USE_DFLT );
187237187737
assert( iLookAhead!=fts5YYNOCODE );
187238187738
i += iLookAhead;
187239187739
#ifdef fts5YYERRORSYMBOL
187240187740
if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
187241187741
return fts5yy_default[stateno];
@@ -187269,24 +187769,25 @@
187269187769
187270187770
/*
187271187771
** Print tracing information for a SHIFT action
187272187772
*/
187273187773
#ifndef NDEBUG
187274
-static void fts5yyTraceShift(fts5yyParser *fts5yypParser, int fts5yyNewState){
187774
+static void fts5yyTraceShift(fts5yyParser *fts5yypParser, int fts5yyNewState, const char *zTag){
187275187775
if( fts5yyTraceFILE ){
187276187776
if( fts5yyNewState<fts5YYNSTATE ){
187277
- fprintf(fts5yyTraceFILE,"%sShift '%s', go to state %d\n",
187278
- fts5yyTracePrompt,fts5yyTokenName[fts5yypParser->fts5yytos->major],
187777
+ fprintf(fts5yyTraceFILE,"%s%s '%s', go to state %d\n",
187778
+ fts5yyTracePrompt, zTag, fts5yyTokenName[fts5yypParser->fts5yytos->major],
187279187779
fts5yyNewState);
187280187780
}else{
187281
- fprintf(fts5yyTraceFILE,"%sShift '%s'\n",
187282
- fts5yyTracePrompt,fts5yyTokenName[fts5yypParser->fts5yytos->major]);
187781
+ fprintf(fts5yyTraceFILE,"%s%s '%s', pending reduce %d\n",
187782
+ fts5yyTracePrompt, zTag, fts5yyTokenName[fts5yypParser->fts5yytos->major],
187783
+ fts5yyNewState - fts5YY_MIN_REDUCE);
187283187784
}
187284187785
}
187285187786
}
187286187787
#else
187287
-# define fts5yyTraceShift(X,Y)
187788
+# define fts5yyTraceShift(X,Y,Z)
187288187789
#endif
187289187790
187290187791
/*
187291187792
** Perform a shift action.
187292187793
*/
@@ -187324,59 +187825,67 @@
187324187825
}
187325187826
fts5yytos = fts5yypParser->fts5yytos;
187326187827
fts5yytos->stateno = (fts5YYACTIONTYPE)fts5yyNewState;
187327187828
fts5yytos->major = (fts5YYCODETYPE)fts5yyMajor;
187328187829
fts5yytos->minor.fts5yy0 = fts5yyMinor;
187329
- fts5yyTraceShift(fts5yypParser, fts5yyNewState);
187830
+ fts5yyTraceShift(fts5yypParser, fts5yyNewState, "Shift");
187330187831
}
187331187832
187332187833
/* The following table contains information about every rule that
187333187834
** is used during the reduce.
187334187835
*/
187335187836
static const struct {
187336187837
fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
187337187838
signed char nrhs; /* Negative of the number of RHS symbols in the rule */
187338187839
} fts5yyRuleInfo[] = {
187339
- { 17, -1 },
187340
- { 21, -4 },
187341
- { 21, -3 },
187342
- { 21, -1 },
187343
- { 21, -2 },
187344
- { 22, -2 },
187345
- { 22, -1 },
187346
- { 18, -3 },
187347
- { 18, -3 },
187348
- { 18, -3 },
187349
- { 18, -5 },
187350
- { 18, -3 },
187351
- { 18, -1 },
187352
- { 20, -1 },
187353
- { 20, -2 },
187354
- { 19, -1 },
187355
- { 19, -3 },
187356
- { 23, -1 },
187357
- { 23, -2 },
187358
- { 23, -5 },
187359
- { 24, -1 },
187360
- { 24, -2 },
187361
- { 26, 0 },
187362
- { 26, -2 },
187363
- { 25, -4 },
187364
- { 25, -2 },
187365
- { 27, -1 },
187366
- { 27, 0 },
187840
+ { 17, -1 }, /* (0) input ::= expr */
187841
+ { 21, -4 }, /* (1) colset ::= MINUS LCP colsetlist RCP */
187842
+ { 21, -3 }, /* (2) colset ::= LCP colsetlist RCP */
187843
+ { 21, -1 }, /* (3) colset ::= STRING */
187844
+ { 21, -2 }, /* (4) colset ::= MINUS STRING */
187845
+ { 22, -2 }, /* (5) colsetlist ::= colsetlist STRING */
187846
+ { 22, -1 }, /* (6) colsetlist ::= STRING */
187847
+ { 18, -3 }, /* (7) expr ::= expr AND expr */
187848
+ { 18, -3 }, /* (8) expr ::= expr OR expr */
187849
+ { 18, -3 }, /* (9) expr ::= expr NOT expr */
187850
+ { 18, -5 }, /* (10) expr ::= colset COLON LP expr RP */
187851
+ { 18, -3 }, /* (11) expr ::= LP expr RP */
187852
+ { 18, -1 }, /* (12) expr ::= exprlist */
187853
+ { 20, -1 }, /* (13) exprlist ::= cnearset */
187854
+ { 20, -2 }, /* (14) exprlist ::= exprlist cnearset */
187855
+ { 19, -1 }, /* (15) cnearset ::= nearset */
187856
+ { 19, -3 }, /* (16) cnearset ::= colset COLON nearset */
187857
+ { 23, -1 }, /* (17) nearset ::= phrase */
187858
+ { 23, -2 }, /* (18) nearset ::= CARET phrase */
187859
+ { 23, -5 }, /* (19) nearset ::= STRING LP nearphrases neardist_opt RP */
187860
+ { 24, -1 }, /* (20) nearphrases ::= phrase */
187861
+ { 24, -2 }, /* (21) nearphrases ::= nearphrases phrase */
187862
+ { 26, 0 }, /* (22) neardist_opt ::= */
187863
+ { 26, -2 }, /* (23) neardist_opt ::= COMMA STRING */
187864
+ { 25, -4 }, /* (24) phrase ::= phrase PLUS STRING star_opt */
187865
+ { 25, -2 }, /* (25) phrase ::= STRING star_opt */
187866
+ { 27, -1 }, /* (26) star_opt ::= STAR */
187867
+ { 27, 0 }, /* (27) star_opt ::= */
187367187868
};
187368187869
187369187870
static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
187370187871
187371187872
/*
187372187873
** Perform a reduce action and the shift that must immediately
187373187874
** follow the reduce.
187875
+**
187876
+** The fts5yyLookahead and fts5yyLookaheadToken parameters provide reduce actions
187877
+** access to the lookahead token (if any). The fts5yyLookahead will be fts5YYNOCODE
187878
+** if the lookahead token has already been consumed. As this procedure is
187879
+** only called from one place, optimizing compilers will in-line it, which
187880
+** means that the extra parameters have no performance impact.
187374187881
*/
187375187882
static void fts5yy_reduce(
187376187883
fts5yyParser *fts5yypParser, /* The parser */
187377
- unsigned int fts5yyruleno /* Number of the rule by which to reduce */
187884
+ unsigned int fts5yyruleno, /* Number of the rule by which to reduce */
187885
+ int fts5yyLookahead, /* Lookahead token, or fts5YYNOCODE if none */
187886
+ sqlite3Fts5ParserFTS5TOKENTYPE fts5yyLookaheadToken /* Value of the lookahead token */
187378187887
){
187379187888
int fts5yygoto; /* The next state */
187380187889
int fts5yyact; /* The next action */
187381187890
fts5yyStackEntry *fts5yymsp; /* The top of the parser's stack */
187382187891
int fts5yysize; /* Amount to pop the stack */
@@ -187383,12 +187892,18 @@
187383187892
sqlite3Fts5ParserARG_FETCH;
187384187893
fts5yymsp = fts5yypParser->fts5yytos;
187385187894
#ifndef NDEBUG
187386187895
if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
187387187896
fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs;
187388
- fprintf(fts5yyTraceFILE, "%sReduce [%s], go to state %d.\n", fts5yyTracePrompt,
187389
- fts5yyRuleName[fts5yyruleno], fts5yymsp[fts5yysize].stateno);
187897
+ if( fts5yysize ){
187898
+ fprintf(fts5yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
187899
+ fts5yyTracePrompt,
187900
+ fts5yyruleno, fts5yyRuleName[fts5yyruleno], fts5yymsp[fts5yysize].stateno);
187901
+ }else{
187902
+ fprintf(fts5yyTraceFILE, "%sReduce %d [%s].\n",
187903
+ fts5yyTracePrompt, fts5yyruleno, fts5yyRuleName[fts5yyruleno]);
187904
+ }
187390187905
}
187391187906
#endif /* NDEBUG */
187392187907
187393187908
/* Check that the stack is large enough to grow by a single entry
187394187909
** if the RHS of the rule is empty. This ensures that there is room
@@ -187581,20 +188096,15 @@
187581188096
assert( !(fts5yyact>fts5YY_MAX_SHIFT && fts5yyact<=fts5YY_MAX_SHIFTREDUCE) );
187582188097
187583188098
/* It is not possible for a REDUCE to be followed by an error */
187584188099
assert( fts5yyact!=fts5YY_ERROR_ACTION );
187585188100
187586
- if( fts5yyact==fts5YY_ACCEPT_ACTION ){
187587
- fts5yypParser->fts5yytos += fts5yysize;
187588
- fts5yy_accept(fts5yypParser);
187589
- }else{
187590
- fts5yymsp += fts5yysize+1;
187591
- fts5yypParser->fts5yytos = fts5yymsp;
187592
- fts5yymsp->stateno = (fts5YYACTIONTYPE)fts5yyact;
187593
- fts5yymsp->major = (fts5YYCODETYPE)fts5yygoto;
187594
- fts5yyTraceShift(fts5yypParser, fts5yyact);
187595
- }
188101
+ fts5yymsp += fts5yysize+1;
188102
+ fts5yypParser->fts5yytos = fts5yymsp;
188103
+ fts5yymsp->stateno = (fts5YYACTIONTYPE)fts5yyact;
188104
+ fts5yymsp->major = (fts5YYCODETYPE)fts5yygoto;
188105
+ fts5yyTraceShift(fts5yypParser, fts5yyact, "... then shift");
187596188106
}
187597188107
187598188108
/*
187599188109
** The following code executes when the parse fails
187600188110
*/
@@ -187702,24 +188212,35 @@
187702188212
#endif
187703188213
sqlite3Fts5ParserARG_STORE;
187704188214
187705188215
#ifndef NDEBUG
187706188216
if( fts5yyTraceFILE ){
187707
- fprintf(fts5yyTraceFILE,"%sInput '%s'\n",fts5yyTracePrompt,fts5yyTokenName[fts5yymajor]);
188217
+ int stateno = fts5yypParser->fts5yytos->stateno;
188218
+ if( stateno < fts5YY_MIN_REDUCE ){
188219
+ fprintf(fts5yyTraceFILE,"%sInput '%s' in state %d\n",
188220
+ fts5yyTracePrompt,fts5yyTokenName[fts5yymajor],stateno);
188221
+ }else{
188222
+ fprintf(fts5yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
188223
+ fts5yyTracePrompt,fts5yyTokenName[fts5yymajor],stateno-fts5YY_MIN_REDUCE);
188224
+ }
187708188225
}
187709188226
#endif
187710188227
187711188228
do{
187712188229
fts5yyact = fts5yy_find_shift_action(fts5yypParser,(fts5YYCODETYPE)fts5yymajor);
187713
- if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
188230
+ if( fts5yyact >= fts5YY_MIN_REDUCE ){
188231
+ fts5yy_reduce(fts5yypParser,fts5yyact-fts5YY_MIN_REDUCE,fts5yymajor,fts5yyminor);
188232
+ }else if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
187714188233
fts5yy_shift(fts5yypParser,fts5yyact,fts5yymajor,fts5yyminor);
187715188234
#ifndef fts5YYNOERRORRECOVERY
187716188235
fts5yypParser->fts5yyerrcnt--;
187717188236
#endif
187718188237
fts5yymajor = fts5YYNOCODE;
187719
- }else if( fts5yyact <= fts5YY_MAX_REDUCE ){
187720
- fts5yy_reduce(fts5yypParser,fts5yyact-fts5YY_MIN_REDUCE);
188238
+ }else if( fts5yyact==fts5YY_ACCEPT_ACTION ){
188239
+ fts5yypParser->fts5yytos--;
188240
+ fts5yy_accept(fts5yypParser);
188241
+ return;
187721188242
}else{
187722188243
assert( fts5yyact == fts5YY_ERROR_ACTION );
187723188244
fts5yyminorunion.fts5yy0 = fts5yyminor;
187724188245
#ifdef fts5YYERRORSYMBOL
187725188246
int fts5yymx;
@@ -188193,10 +188714,20 @@
188193188714
*piPos = iAdj;
188194188715
}
188195188716
188196188717
return rc;
188197188718
}
188719
+
188720
+/*
188721
+** Return the value in pVal interpreted as utf-8 text. Except, if pVal
188722
+** contains a NULL value, return a pointer to a static string zero
188723
+** bytes in length instead of a NULL pointer.
188724
+*/
188725
+static const char *fts5ValueToText(sqlite3_value *pVal){
188726
+ const char *zRet = (const char*)sqlite3_value_text(pVal);
188727
+ return zRet ? zRet : "";
188728
+}
188198188729
188199188730
/*
188200188731
** Implementation of snippet() function.
188201188732
*/
188202188733
static void fts5SnippetFunction(
@@ -188229,13 +188760,13 @@
188229188760
}
188230188761
188231188762
nCol = pApi->xColumnCount(pFts);
188232188763
memset(&ctx, 0, sizeof(HighlightContext));
188233188764
iCol = sqlite3_value_int(apVal[0]);
188234
- ctx.zOpen = (const char*)sqlite3_value_text(apVal[1]);
188235
- ctx.zClose = (const char*)sqlite3_value_text(apVal[2]);
188236
- zEllips = (const char*)sqlite3_value_text(apVal[3]);
188765
+ ctx.zOpen = fts5ValueToText(apVal[1]);
188766
+ ctx.zClose = fts5ValueToText(apVal[2]);
188767
+ zEllips = fts5ValueToText(apVal[3]);
188237188768
nToken = sqlite3_value_int(apVal[4]);
188238188769
188239188770
iBestCol = (iCol>=0 ? iCol : 0);
188240188771
nPhrase = pApi->xPhraseCount(pFts);
188241188772
aSeen = sqlite3_malloc(nPhrase);
@@ -202410,11 +202941,11 @@
202410202941
int nArg, /* Number of args */
202411202942
sqlite3_value **apUnused /* Function arguments */
202412202943
){
202413202944
assert( nArg==0 );
202414202945
UNUSED_PARAM2(nArg, apUnused);
202415
- sqlite3_result_text(pCtx, "fts5: 2017-12-13 15:32:33 30bf38d589adf0b2eb613e184ffb03ed7e625736cb04fd5c341328f72bc5ef4d", -1, SQLITE_TRANSIENT);
202946
+ sqlite3_result_text(pCtx, "fts5: 2018-01-06 15:49:57 252ee55a7fc0b068b707af27bd912e684c28320996e78f0675217046b8c2fb49", -1, SQLITE_TRANSIENT);
202416202947
}
202417202948
202418202949
static int fts5Init(sqlite3 *db){
202419202950
static const sqlite3_module fts5Mod = {
202420202951
/* iVersion */ 2,
@@ -206678,12 +207209,12 @@
206678207209
}
206679207210
#endif /* SQLITE_CORE */
206680207211
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
206681207212
206682207213
/************** End of stmt.c ************************************************/
206683
-#if __LINE__!=206683
207214
+#if __LINE__!=207214
206684207215
#undef SQLITE_SOURCE_ID
206685
-#define SQLITE_SOURCE_ID "2017-12-13 20:35:34 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b42alt2"
207216
+#define SQLITE_SOURCE_ID "2018-01-07 20:38:10 67c4a8c6881e33b830aa27c80e7e3d697a4222939edd77cd5ca77ece1647alt2"
206686207217
#endif
206687207218
/* Return the source-id for this library */
206688207219
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
206689207220
/************************** End of sqlite3.c ******************************/
206690207221
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2017-12-13 20:35:34 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b429b15"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -3082,11 +3082,10 @@
3082 ** is an integer - non-zero to disable checkpoints-on-close, or zero (the
3083 ** default) to enable them. The second parameter is a pointer to an integer
3084 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
3085 ** have been disabled - 0 if they are not disabled, 1 if they are.
3086 ** </dd>
3087 **
3088 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
3089 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
3090 ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
3091 ** a single SQL query statement will always use the same algorithm regardless
3092 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
@@ -3093,11 +3092,20 @@
3093 ** that look at the values of bound parameters, which can make some queries
3094 ** slower. But the QPSG has the advantage of more predictable behavior. With
3095 ** the QPSG active, SQLite will always use the same query plan in the field as
3096 ** was used during testing in the lab.
3097 ** </dd>
3098 **
 
 
 
 
 
 
 
 
 
3099 ** </dl>
3100 */
3101 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
3102 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
3103 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -3104,11 +3112,12 @@
3104 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
3105 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
3106 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
3107 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
3108 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
3109
 
3110
3111 /*
3112 ** CAPI3REF: Enable Or Disable Extended Result Codes
3113 ** METHOD: sqlite3
3114 **
@@ -7984,13 +7993,13 @@
7984 ** ^The third and fourth parameters to this routine
7985 ** are passed directly through to the second and third parameters of
7986 ** the xFileControl method. ^The return value of the xFileControl
7987 ** method becomes the return value of this routine.
7988 **
7989 ** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
7990 ** a pointer to the underlying [sqlite3_file] object to be written into
7991 ** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER
7992 ** case is a short-circuit path which does not actually invoke the
7993 ** underlying sqlite3_io_methods.xFileControl method.
7994 **
7995 ** ^If the second parameter (zDbName) does not match the name of any
7996 ** open database file, then SQLITE_ERROR is returned. ^This error
@@ -7998,11 +8007,11 @@
7998 ** or [sqlite3_errmsg()]. The underlying xFileControl method might
7999 ** also return SQLITE_ERROR. There is no way to distinguish between
8000 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
8001 ** xFileControl method.
8002 **
8003 ** See also: [SQLITE_FCNTL_LOCKSTATE]
8004 */
8005 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
8006
8007 /*
8008 ** CAPI3REF: Testing Interface
@@ -8055,11 +8064,12 @@
8055 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
8056 #define SQLITE_TESTCTRL_BYTEORDER 22
8057 #define SQLITE_TESTCTRL_ISINIT 23
8058 #define SQLITE_TESTCTRL_SORTER_MMAP 24
8059 #define SQLITE_TESTCTRL_IMPOSTER 25
8060 #define SQLITE_TESTCTRL_LAST 25
 
8061
8062 /*
8063 ** CAPI3REF: SQLite Runtime Status
8064 **
8065 ** ^These interfaces are used to retrieve runtime status information
@@ -9309,10 +9319,25 @@
9309 ** of the SQL statement that triggered the call to the [xUpdate] method of the
9310 ** [virtual table].
9311 */
9312 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
9313
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9314 /*
9315 ** CAPI3REF: Conflict resolution modes
9316 ** KEYWORDS: {conflict resolution mode}
9317 **
9318 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -13144,11 +13169,10 @@
13144 typedef struct Column Column;
13145 typedef struct Db Db;
13146 typedef struct Schema Schema;
13147 typedef struct Expr Expr;
13148 typedef struct ExprList ExprList;
13149 typedef struct ExprSpan ExprSpan;
13150 typedef struct FKey FKey;
13151 typedef struct FuncDestructor FuncDestructor;
13152 typedef struct FuncDef FuncDef;
13153 typedef struct FuncDefHash FuncDefHash;
13154 typedef struct IdList IdList;
@@ -13490,10 +13514,13 @@
13490 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
13491 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
13492 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
13493 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
13494 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
 
 
 
13495 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
13496 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
13497 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
13498
13499 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
@@ -13841,82 +13868,84 @@
13841 #define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
13842 #define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
13843 #define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
13844 #define OP_Compare 94 /* synopsis: r[P1@P3] <-> r[P2@P3] */
13845 #define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
13846 #define OP_Column 96 /* synopsis: r[P3]=PX */
13847 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
13848 #define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */
13849 #define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
13850 #define OP_Count 100 /* synopsis: r[P2]=count() */
13851 #define OP_ReadCookie 101
13852 #define OP_SetCookie 102
13853 #define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */
13854 #define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */
13855 #define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */
13856 #define OP_OpenDup 106
13857 #define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */
13858 #define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */
13859 #define OP_SorterOpen 109
13860 #define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
13861 #define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */
13862 #define OP_Close 112
13863 #define OP_ColumnsUsed 113
13864 #define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */
13865 #define OP_NewRowid 115 /* synopsis: r[P2]=rowid */
13866 #define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */
13867 #define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */
13868 #define OP_Delete 118
13869 #define OP_ResetCount 119
13870 #define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13871 #define OP_SorterData 121 /* synopsis: r[P2]=data */
13872 #define OP_RowData 122 /* synopsis: r[P2]=data */
13873 #define OP_Rowid 123 /* synopsis: r[P2]=rowid */
13874 #define OP_NullRow 124
13875 #define OP_SeekEnd 125
13876 #define OP_SorterInsert 126 /* synopsis: key=r[P2] */
13877 #define OP_IdxInsert 127 /* synopsis: key=r[P2] */
13878 #define OP_IdxDelete 128 /* synopsis: key=r[P2@P3] */
13879 #define OP_DeferredSeek 129 /* synopsis: Move P3 to P1.rowid if needed */
13880 #define OP_IdxRowid 130 /* synopsis: r[P2]=rowid */
13881 #define OP_Destroy 131
13882 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13883 #define OP_Clear 133
13884 #define OP_ResetSorter 134
13885 #define OP_CreateBtree 135 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
13886 #define OP_SqlExec 136
13887 #define OP_ParseSchema 137
13888 #define OP_LoadAnalysis 138
13889 #define OP_DropTable 139
13890 #define OP_DropIndex 140
13891 #define OP_DropTrigger 141
13892 #define OP_IntegrityCk 142
13893 #define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */
13894 #define OP_Param 144
13895 #define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */
13896 #define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */
13897 #define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
13898 #define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13899 #define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13900 #define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */
13901 #define OP_Expire 151
13902 #define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */
13903 #define OP_VBegin 153
13904 #define OP_VCreate 154
13905 #define OP_VDestroy 155
13906 #define OP_VOpen 156
13907 #define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */
13908 #define OP_VRename 158
13909 #define OP_Pagecount 159
13910 #define OP_MaxPgcnt 160
13911 #define OP_PureFunc0 161
13912 #define OP_Function0 162 /* synopsis: r[P3]=func(r[P2@P5]) */
13913 #define OP_PureFunc 163
13914 #define OP_Function 164 /* synopsis: r[P3]=func(r[P2@P5]) */
13915 #define OP_CursorHint 165
13916 #define OP_Noop 166
13917 #define OP_Explain 167
 
 
13918
13919 /* Properties such as "out2" or "jump" that are specified in
13920 ** comments following the "case" for each opcode in the vdbe.c
13921 ** are encoded into bitvectors as follows:
13922 */
@@ -13937,20 +13966,20 @@
13937 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x02,\
13938 /* 64 */ 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,\
13939 /* 72 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13940 /* 80 */ 0x02, 0x02, 0x02, 0x00, 0x26, 0x26, 0x26, 0x26,\
13941 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
13942 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13943 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13944 /* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
13945 /* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\
13946 /* 128 */ 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10,\
13947 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
13948 /* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
13949 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
13950 /* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13951 }
13952
13953 /* The sqlite3P2Values() routine is able to run faster if it knows
13954 ** the value of the largest JUMP opcode. The smaller the maximum
13955 ** JUMP opcode the better, so the mkopcodeh.tcl script that
13956 ** generated this include file strives to group all JUMP opcodes
@@ -15206,11 +15235,11 @@
15206 #ifndef SQLITE_OMIT_VIRTUALTABLE
15207 int nVTrans; /* Allocated size of aVTrans */
15208 Hash aModule; /* populated by sqlite3_create_module() */
15209 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
15210 VTable **aVTrans; /* Virtual tables with open transactions */
15211 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
15212 #endif
15213 Hash aFunc; /* Hash table of connection functions */
15214 Hash aCollSeq; /* All collating sequences */
15215 BusyHandler busyHandler; /* Busy callback */
15216 Db aDbStatic[2]; /* Static space for the 2 default backends */
@@ -15281,11 +15310,13 @@
15281 #define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */
15282 #define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */
15283 #define SQLITE_QueryOnly 0x00100000 /* Disable database changes */
15284 #define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */
15285 #define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */
15286 #define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee */
 
 
15287 /* Flags used only if debugging */
15288 #ifdef SQLITE_DEBUG
15289 #define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */
15290 #define SQLITE_VdbeListing 0x10000000 /* Debug listings of VDBE programs */
15291 #define SQLITE_VdbeTrace 0x20000000 /* True to trace VDBE execution */
@@ -15414,10 +15445,11 @@
15414 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
15415 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
15416 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
15417 ** single query - might change over time */
15418 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
 
15419
15420 /*
15421 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
15422 ** used to create the initializers for the FuncDef structures.
15423 **
@@ -16288,21 +16320,10 @@
16288 int iConstExprReg; /* Register in which Expr value is cached */
16289 } u;
16290 } a[1]; /* One slot for each expression in the list */
16291 };
16292
16293 /*
16294 ** An instance of this structure is used by the parser to record both
16295 ** the parse tree for an expression and the span of input text for an
16296 ** expression.
16297 */
16298 struct ExprSpan {
16299 Expr *pExpr; /* The expression parse tree */
16300 const char *zStart; /* First character of input text */
16301 const char *zEnd; /* One character past the end of input text */
16302 };
16303
16304 /*
16305 ** An instance of this structure can hold a simple list of identifiers,
16306 ** such as the list "a,b,c" in the following statements:
16307 **
16308 ** INSERT INTO t(a,b,c) VALUES ...;
@@ -16999,10 +17020,11 @@
16999 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
17000 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
17001 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
17002 ExprList *pExprList; /* SET clause for UPDATE. */
17003 IdList *pIdList; /* Column names for INSERT */
 
17004 TriggerStep *pNext; /* Next in the link-list */
17005 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
17006 };
17007
17008 /*
@@ -17309,10 +17331,11 @@
17309 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, u64);
17310 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, u64);
17311 SQLITE_PRIVATE void *sqlite3DbMallocRawNN(sqlite3*, u64);
17312 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
17313 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
 
17314 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
17315 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
17316 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
17317 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
17318 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
@@ -17447,11 +17470,11 @@
17447 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
17448 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
17449 SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
17450 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
17451 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
17452 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
17453 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
17454 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
17455 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
17456 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
17457 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
@@ -17477,11 +17500,11 @@
17477 #endif
17478 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*);
17479 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
17480 SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
17481 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
17482 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
17483 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
17484 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
17485 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
17486 sqlite3_vfs**,char**,char **);
17487 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
@@ -17698,15 +17721,18 @@
17698 SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
17699 int, int, int);
17700 SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
17701 void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
17702 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*);
17703 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*);
 
17704 SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
17705 Select*,u8);
17706 SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8);
17707 SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
 
 
17708 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*);
17709 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
17710 SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
17711 # define sqlite3ParseToplevel(p) ((p)->pToplevel ? (p)->pToplevel : (p))
17712 # define sqlite3IsToplevel(p) ((p)->pToplevel==0)
@@ -18132,10 +18158,13 @@
18132 #endif
18133
18134 #ifdef SQLITE_DEBUG
18135 SQLITE_PRIVATE void sqlite3ParserTrace(FILE*, char *);
18136 #endif
 
 
 
18137
18138 /*
18139 ** If the SQLITE_ENABLE IOTRACE exists then the global variable
18140 ** sqlite3IoTrace is a pointer to a printf-like routine used to
18141 ** print I/O tracing messages.
@@ -25667,10 +25696,23 @@
25667 memcpy(zNew, z, (size_t)n);
25668 zNew[n] = 0;
25669 }
25670 return zNew;
25671 }
 
 
 
 
 
 
 
 
 
 
 
 
 
25672
25673 /*
25674 ** Free any prior content in *pz and replace it with a copy of zNew.
25675 */
25676 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
@@ -27373,16 +27415,24 @@
27373 }else{
27374 int i;
27375 sqlite3TreeViewLine(pView, "%s", zLabel);
27376 for(i=0; i<pList->nExpr; i++){
27377 int j = pList->a[i].u.x.iOrderByCol;
27378 if( j ){
 
27379 sqlite3TreeViewPush(pView, 0);
 
 
 
 
 
27380 sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
27381 }
27382 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
27383 if( j ) sqlite3TreeViewPop(pView);
 
 
27384 }
27385 }
27386 }
27387 SQLITE_PRIVATE void sqlite3TreeViewExprList(
27388 TreeView *pView,
@@ -28667,10 +28717,28 @@
28667 a = (unsigned char *)zLeft;
28668 b = (unsigned char *)zRight;
28669 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
28670 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
28671 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28672
28673 /*
28674 ** The string z[] is an text representation of a real number.
28675 ** Convert this string to a double and write it into *pResult.
28676 **
@@ -28823,15 +28891,14 @@
28823 s = sign<0 ? -s : s;
28824
28825 if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/
28826 result = (double)s;
28827 }else{
28828 LONGDOUBLE_TYPE scale = 1.0;
28829 /* attempt to handle extremely small/large numbers better */
28830 if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/
28831 if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/
28832 while( e%308 ) { scale *= 1.0e+1; e -= 1; }
28833 if( esign<0 ){
28834 result = s / scale;
28835 result /= 1.0e+308;
28836 }else{
28837 result = s * scale;
@@ -28847,14 +28914,11 @@
28847 result = 1e308*1e308*s; /* Infinity */
28848 #endif
28849 }
28850 }
28851 }else{
28852 /* 1.0e+22 is the largest power of 10 than can be
28853 ** represented exactly. */
28854 while( e%22 ) { scale *= 1.0e+1; e -= 1; }
28855 while( e>0 ) { scale *= 1.0e+22; e -= 22; }
28856 if( esign<0 ){
28857 result = s / scale;
28858 }else{
28859 result = s * scale;
28860 }
@@ -30308,82 +30372,84 @@
30308 /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
30309 /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
30310 /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
30311 /* 94 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
30312 /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
30313 /* 96 */ "Column" OpHelp("r[P3]=PX"),
30314 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
30315 /* 98 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
30316 /* 99 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
30317 /* 100 */ "Count" OpHelp("r[P2]=count()"),
30318 /* 101 */ "ReadCookie" OpHelp(""),
30319 /* 102 */ "SetCookie" OpHelp(""),
30320 /* 103 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
30321 /* 104 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
30322 /* 105 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
30323 /* 106 */ "OpenDup" OpHelp(""),
30324 /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"),
30325 /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"),
30326 /* 109 */ "SorterOpen" OpHelp(""),
30327 /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
30328 /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
30329 /* 112 */ "Close" OpHelp(""),
30330 /* 113 */ "ColumnsUsed" OpHelp(""),
30331 /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
30332 /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"),
30333 /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
30334 /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
30335 /* 118 */ "Delete" OpHelp(""),
30336 /* 119 */ "ResetCount" OpHelp(""),
30337 /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30338 /* 121 */ "SorterData" OpHelp("r[P2]=data"),
30339 /* 122 */ "RowData" OpHelp("r[P2]=data"),
30340 /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
30341 /* 124 */ "NullRow" OpHelp(""),
30342 /* 125 */ "SeekEnd" OpHelp(""),
30343 /* 126 */ "SorterInsert" OpHelp("key=r[P2]"),
30344 /* 127 */ "IdxInsert" OpHelp("key=r[P2]"),
30345 /* 128 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30346 /* 129 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30347 /* 130 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30348 /* 131 */ "Destroy" OpHelp(""),
30349 /* 132 */ "Real" OpHelp("r[P2]=P4"),
30350 /* 133 */ "Clear" OpHelp(""),
30351 /* 134 */ "ResetSorter" OpHelp(""),
30352 /* 135 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
30353 /* 136 */ "SqlExec" OpHelp(""),
30354 /* 137 */ "ParseSchema" OpHelp(""),
30355 /* 138 */ "LoadAnalysis" OpHelp(""),
30356 /* 139 */ "DropTable" OpHelp(""),
30357 /* 140 */ "DropIndex" OpHelp(""),
30358 /* 141 */ "DropTrigger" OpHelp(""),
30359 /* 142 */ "IntegrityCk" OpHelp(""),
30360 /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
30361 /* 144 */ "Param" OpHelp(""),
30362 /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
30363 /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
30364 /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
30365 /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
30366 /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
30367 /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
30368 /* 151 */ "Expire" OpHelp(""),
30369 /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
30370 /* 153 */ "VBegin" OpHelp(""),
30371 /* 154 */ "VCreate" OpHelp(""),
30372 /* 155 */ "VDestroy" OpHelp(""),
30373 /* 156 */ "VOpen" OpHelp(""),
30374 /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
30375 /* 158 */ "VRename" OpHelp(""),
30376 /* 159 */ "Pagecount" OpHelp(""),
30377 /* 160 */ "MaxPgcnt" OpHelp(""),
30378 /* 161 */ "PureFunc0" OpHelp(""),
30379 /* 162 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
30380 /* 163 */ "PureFunc" OpHelp(""),
30381 /* 164 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
30382 /* 165 */ "CursorHint" OpHelp(""),
30383 /* 166 */ "Noop" OpHelp(""),
30384 /* 167 */ "Explain" OpHelp(""),
 
 
30385 };
30386 return azName[i];
30387 }
30388 #endif
30389
@@ -53382,11 +53448,11 @@
53382 if( pPager->eState>PAGER_READER || pPager->tempFile ){
53383 pPg = sqlite3PagerLookup(pPager, pgno);
53384 }
53385 if( pPg==0 ){
53386 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
53387 }else{
53388 sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
53389 }
53390 if( pPg ){
53391 assert( rc==SQLITE_OK );
53392 *ppPage = pPg;
@@ -64672,10 +64738,24 @@
64672 assert( pCur->curIntKey );
64673 getCellInfo(pCur);
64674 return pCur->info.nKey;
64675 }
64676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64677 /*
64678 ** Return the number of bytes of payload for the entry that pCur is
64679 ** currently pointing to. For table btrees, this will be the amount
64680 ** of data. For index btrees, this will be the size of the key.
64681 **
@@ -72430,11 +72510,14 @@
72430
72431 *ppVal = pVal;
72432 return rc;
72433
72434 no_mem:
72435 sqlite3OomFault(db);
 
 
 
72436 sqlite3DbFree(db, zVal);
72437 assert( *ppVal==0 );
72438 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
72439 if( pCtx==0 ) sqlite3ValueFree(pVal);
72440 #else
@@ -74416,10 +74499,12 @@
74416 Mem *pSub = 0; /* Memory cell hold array of subprogs */
74417 sqlite3 *db = p->db; /* The database connection */
74418 int i; /* Loop counter */
74419 int rc = SQLITE_OK; /* Return code */
74420 Mem *pMem = &p->aMem[1]; /* First Mem of result set */
 
 
74421
74422 assert( p->explain );
74423 assert( p->magic==VDBE_MAGIC_RUN );
74424 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
74425
@@ -74428,11 +74513,11 @@
74428 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
74429 */
74430 releaseMemArray(pMem, 8);
74431 p->pResultSet = 0;
74432
74433 if( p->rc==SQLITE_NOMEM_BKPT ){
74434 /* This happens if a malloc() inside a call to sqlite3_column_text() or
74435 ** sqlite3_column_text16() failed. */
74436 sqlite3OomFault(db);
74437 return SQLITE_ERROR;
74438 }
@@ -74443,11 +74528,11 @@
74443 ** the sum of the number of rows in all trigger subprograms encountered
74444 ** so far. The nRow value will increase as new trigger subprograms are
74445 ** encountered, but p->pc will eventually catch up to nRow.
74446 */
74447 nRow = p->nOp;
74448 if( p->explain==1 ){
74449 /* The first 8 memory cells are used for the result set. So we will
74450 ** commandeer the 9th cell to use as storage for an array of pointers
74451 ** to trigger subprograms. The VDBE is guaranteed to have at least 9
74452 ** cells. */
74453 assert( p->nMem>9 );
@@ -74463,21 +74548,15 @@
74463 }
74464 }
74465
74466 do{
74467 i = p->pc++;
74468 }while( i<nRow && p->explain==2 && p->aOp[i].opcode!=OP_Explain );
74469 if( i>=nRow ){
74470 p->rc = SQLITE_OK;
74471 rc = SQLITE_DONE;
74472 }else if( db->u1.isInterrupted ){
74473 p->rc = SQLITE_INTERRUPT;
74474 rc = SQLITE_ERROR;
74475 sqlite3VdbeError(p, sqlite3ErrStr(p->rc));
74476 }else{
74477 char *zP4;
74478 Op *pOp;
74479 if( i<p->nOp ){
74480 /* The output line number is small enough that we are still in the
74481 ** main program. */
74482 pOp = &p->aOp[i];
74483 }else{
@@ -74488,98 +74567,114 @@
74488 for(j=0; i>=apSub[j]->nOp; j++){
74489 i -= apSub[j]->nOp;
74490 }
74491 pOp = &apSub[j]->aOp[i];
74492 }
74493 if( p->explain==1 ){
74494 pMem->flags = MEM_Int;
74495 pMem->u.i = i; /* Program counter */
74496 pMem++;
74497
74498 pMem->flags = MEM_Static|MEM_Str|MEM_Term;
74499 pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
74500 assert( pMem->z!=0 );
74501 pMem->n = sqlite3Strlen30(pMem->z);
74502 pMem->enc = SQLITE_UTF8;
74503 pMem++;
74504
74505 /* When an OP_Program opcode is encounter (the only opcode that has
74506 ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
74507 ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
74508 ** has not already been seen.
74509 */
74510 if( pOp->p4type==P4_SUBPROGRAM ){
74511 int nByte = (nSub+1)*sizeof(SubProgram*);
74512 int j;
74513 for(j=0; j<nSub; j++){
74514 if( apSub[j]==pOp->p4.pProgram ) break;
74515 }
74516 if( j==nSub && SQLITE_OK==sqlite3VdbeMemGrow(pSub, nByte, nSub!=0) ){
74517 apSub = (SubProgram **)pSub->z;
74518 apSub[nSub++] = pOp->p4.pProgram;
74519 pSub->flags |= MEM_Blob;
74520 pSub->n = nSub*sizeof(SubProgram*);
74521 }
74522 }
74523 }
74524
74525 pMem->flags = MEM_Int;
74526 pMem->u.i = pOp->p1; /* P1 */
74527 pMem++;
74528
74529 pMem->flags = MEM_Int;
74530 pMem->u.i = pOp->p2; /* P2 */
74531 pMem++;
74532
74533 pMem->flags = MEM_Int;
74534 pMem->u.i = pOp->p3; /* P3 */
74535 pMem++;
74536
74537 if( sqlite3VdbeMemClearAndResize(pMem, 100) ){ /* P4 */
74538 assert( p->db->mallocFailed );
74539 return SQLITE_ERROR;
74540 }
74541 pMem->flags = MEM_Str|MEM_Term;
74542 zP4 = displayP4(pOp, pMem->z, pMem->szMalloc);
74543 if( zP4!=pMem->z ){
74544 pMem->n = 0;
74545 sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
74546 }else{
74547 assert( pMem->z!=0 );
74548 pMem->n = sqlite3Strlen30(pMem->z);
74549 pMem->enc = SQLITE_UTF8;
74550 }
74551 pMem++;
74552
74553 if( p->explain==1 ){
74554 if( sqlite3VdbeMemClearAndResize(pMem, 4) ){
74555 assert( p->db->mallocFailed );
74556 return SQLITE_ERROR;
74557 }
74558 pMem->flags = MEM_Str|MEM_Term;
74559 pMem->n = 2;
74560 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
74561 pMem->enc = SQLITE_UTF8;
74562 pMem++;
74563
74564 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
74565 if( sqlite3VdbeMemClearAndResize(pMem, 500) ){
74566 assert( p->db->mallocFailed );
74567 return SQLITE_ERROR;
74568 }
74569 pMem->flags = MEM_Str|MEM_Term;
74570 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
74571 pMem->enc = SQLITE_UTF8;
74572 #else
74573 pMem->flags = MEM_Null; /* Comment */
74574 #endif
74575 }
74576
74577 p->nResColumn = 8 - 4*(p->explain-1);
74578 p->pResultSet = &p->aMem[1];
74579 p->rc = SQLITE_OK;
74580 rc = SQLITE_ROW;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74581 }
74582 return rc;
74583 }
74584 #endif /* SQLITE_OMIT_EXPLAIN */
74585
@@ -82102,10 +82197,40 @@
82102 goto jump_to_p2;
82103 }
82104 break;
82105 }
82106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82107 /* Opcode: Column P1 P2 P3 P4 P5
82108 ** Synopsis: r[P3]=PX
82109 **
82110 ** Interpret the data that cursor P1 points to as a structure built using
82111 ** the MakeRecord instruction. (See the MakeRecord opcode for additional
@@ -86769,11 +86894,17 @@
86769 REGISTER_TRACE(pOp->p3, pOut);
86770 UPDATE_MAX_BLOBSIZE(pOut);
86771 break;
86772 }
86773
86774
 
 
 
 
 
 
86775 /* Opcode: Init P1 P2 P3 P4 *
86776 ** Synopsis: Start at P2
86777 **
86778 ** Programs contain a single instance of this opcode as the very first
86779 ** opcode.
@@ -86788,10 +86919,11 @@
86788 ** first time they are evaluated for this run.
86789 **
86790 ** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
86791 ** error is encountered.
86792 */
 
86793 case OP_Init: { /* jump */
86794 char *zTrace;
86795 int i;
86796
86797 /* If the P4 argument is not NULL, then it must be an SQL comment string.
@@ -86802,11 +86934,13 @@
86802 ** would have been returned by the legacy sqlite3_trace() interface by
86803 ** using the X argument when X begins with "--" and invoking
86804 ** sqlite3_expanded_sql(P) otherwise.
86805 */
86806 assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
86807 assert( pOp==p->aOp ); /* Always instruction 0 */
 
 
86808
86809 #ifndef SQLITE_OMIT_TRACE
86810 if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
86811 && !p->doingRerun
86812 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
@@ -86845,10 +86979,11 @@
86845 }
86846 #endif /* SQLITE_DEBUG */
86847 #endif /* SQLITE_OMIT_TRACE */
86848 assert( pOp->p2>0 );
86849 if( pOp->p1>=sqlite3GlobalConfig.iOnceResetThreshold ){
 
86850 for(i=1; i<p->nOp; i++){
86851 if( p->aOp[i].opcode==OP_Once ) p->aOp[i].p1 = 0;
86852 }
86853 pOp->p1 = 0;
86854 }
@@ -94048,21 +94183,20 @@
94048 ** is set.
94049 */
94050 SQLITE_PRIVATE void sqlite3ExprListSetSpan(
94051 Parse *pParse, /* Parsing context */
94052 ExprList *pList, /* List to which to add the span. */
94053 ExprSpan *pSpan /* The span to be added */
 
94054 ){
94055 sqlite3 *db = pParse->db;
94056 assert( pList!=0 || db->mallocFailed!=0 );
94057 if( pList ){
94058 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
94059 assert( pList->nExpr>0 );
94060 assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
94061 sqlite3DbFree(db, pItem->zSpan);
94062 pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
94063 (int)(pSpan->zEnd - pSpan->zStart));
94064 }
94065 }
94066
94067 /*
94068 ** If the expression list pEList contains more than iLimit elements,
@@ -96265,13 +96399,25 @@
96265 #endif
96266 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
96267 if( !pColl ) pColl = db->pDfltColl;
96268 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
96269 }
96270 sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0,
96271 constMask, r1, target, (char*)pDef, P4_FUNCDEF);
96272 sqlite3VdbeChangeP5(v, (u8)nFarg);
 
 
 
 
 
 
 
 
 
 
 
 
96273 if( nFarg && constMask==0 ){
96274 sqlite3ReleaseTempRange(pParse, r1, nFarg);
96275 }
96276 return target;
96277 }
@@ -102511,38 +102657,41 @@
102511 ** is not the case.
102512 **
102513 ** This routine is called by the parser while in the middle of
102514 ** parsing a CREATE TABLE statement.
102515 */
102516 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse *pParse, ExprSpan *pSpan){
 
 
 
 
 
102517 Table *p;
102518 Column *pCol;
102519 sqlite3 *db = pParse->db;
102520 p = pParse->pNewTable;
102521 if( p!=0 ){
102522 pCol = &(p->aCol[p->nCol-1]);
102523 if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr, db->init.busy) ){
102524 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
102525 pCol->zName);
102526 }else{
102527 /* A copy of pExpr is used instead of the original, as pExpr contains
102528 ** tokens that point to volatile memory. The 'span' of the expression
102529 ** is required by pragma table_info.
102530 */
102531 Expr x;
102532 sqlite3ExprDelete(db, pCol->pDflt);
102533 memset(&x, 0, sizeof(x));
102534 x.op = TK_SPAN;
102535 x.u.zToken = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
102536 (int)(pSpan->zEnd - pSpan->zStart));
102537 x.pLeft = pSpan->pExpr;
102538 x.flags = EP_Skip;
102539 pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
102540 sqlite3DbFree(db, x.u.zToken);
102541 }
102542 }
102543 sqlite3ExprDelete(db, pSpan->pExpr);
102544 }
102545
102546 /*
102547 ** Backwards Compatibility Hack:
102548 **
@@ -103255,23 +103404,24 @@
103255 sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
103256 sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
103257 pParse->nTab = 2;
103258 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
103259 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
103260 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
103261 sqlite3Select(pParse, pSelect, &dest);
103262 sqlite3VdbeEndCoroutine(v, regYield);
103263 sqlite3VdbeJumpHere(v, addrTop - 1);
103264 if( pParse->nErr ) return;
103265 pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect);
103266 if( pSelTab==0 ) return;
103267 assert( p->aCol==0 );
103268 p->nCol = pSelTab->nCol;
103269 p->aCol = pSelTab->aCol;
103270 pSelTab->nCol = 0;
103271 pSelTab->aCol = 0;
103272 sqlite3DeleteTable(db, pSelTab);
 
 
 
 
 
103273 addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
103274 VdbeCoverage(v);
103275 sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
103276 sqlite3TableAffinity(v, p, 0);
103277 sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
@@ -108980,10 +109130,14 @@
108980 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
108981 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
108982 #ifdef SQLITE_DEBUG
108983 FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY),
108984 #endif
 
 
 
 
108985 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
108986 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
108987 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
108988 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
108989 FUNCTION(trim, 1, 3, 0, trimFunc ),
@@ -112072,10 +112226,11 @@
112072 sqlite3VdbeResolveLabel(v, addrUniqueOk);
112073 continue;
112074 }
112075
112076 /* Check to see if the new index entry will be unique */
 
112077 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
112078 regIdx, pIdx->nKeyCol); VdbeCoverage(v);
112079
112080 /* Generate code to handle collisions */
112081 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
@@ -112160,10 +112315,11 @@
112160 seenReplace = 1;
112161 break;
112162 }
112163 }
112164 sqlite3VdbeResolveLabel(v, addrUniqueOk);
 
112165 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
112166 }
112167 if( ipkTop ){
112168 sqlite3VdbeGoto(v, ipkTop+1);
112169 sqlite3VdbeJumpHere(v, ipkBottom);
@@ -113985,12 +114141,14 @@
113985
113986 handle = sqlite3OsDlOpen(pVfs, zFile);
113987 #if SQLITE_OS_UNIX || SQLITE_OS_WIN
113988 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
113989 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
 
113990 if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
113991 handle = sqlite3OsDlOpen(pVfs, zAltFile);
 
113992 sqlite3_free(zAltFile);
113993 }
113994 #endif
113995 if( handle==0 ){
113996 if( pzErrMsg ){
@@ -116022,10 +116180,11 @@
116022 ** cid: Column id (numbered from left to right, starting at 0)
116023 ** name: Column name
116024 ** type: Column declaration type.
116025 ** notnull: True if 'NOT NULL' is part of column declaration
116026 ** dflt_value: The default value for the column, if any.
 
116027 */
116028 case PragTyp_TABLE_INFO: if( zRight ){
116029 Table *pTab;
116030 pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
116031 if( pTab ){
@@ -119715,22 +119874,21 @@
119715 char const *zOrigCol = 0;
119716 #endif
119717
119718 assert( pExpr!=0 );
119719 assert( pNC->pSrcList!=0 );
 
 
119720 switch( pExpr->op ){
119721 case TK_AGG_COLUMN:
119722 case TK_COLUMN: {
119723 /* The expression is a column. Locate the table the column is being
119724 ** extracted from in NameContext.pSrcList. This table may be real
119725 ** database table or a subquery.
119726 */
119727 Table *pTab = 0; /* Table structure column is extracted from */
119728 Select *pS = 0; /* Select the column is extracted from */
119729 int iCol = pExpr->iColumn; /* Index of column in pTab */
119730 testcase( pExpr->op==TK_AGG_COLUMN );
119731 testcase( pExpr->op==TK_COLUMN );
119732 while( pNC && !pTab ){
119733 SrcList *pTabList = pNC->pSrcList;
119734 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
119735 if( j<pTabList->nSrc ){
119736 pTab = pTabList->a[j].pTab;
@@ -119930,10 +120088,11 @@
119930 #endif
119931
119932 if( pParse->colNamesSet || db->mallocFailed ) return;
119933 /* Column names are determined by the left-most term of a compound select */
119934 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
 
119935 pTabList = pSelect->pSrc;
119936 pEList = pSelect->pEList;
119937 assert( v!=0 );
119938 assert( pTabList!=0 );
119939 pParse->colNamesSet = 1;
@@ -120038,16 +120197,16 @@
120038 Expr *pColExpr = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
120039 while( pColExpr->op==TK_DOT ){
120040 pColExpr = pColExpr->pRight;
120041 assert( pColExpr!=0 );
120042 }
120043 if( (pColExpr->op==TK_COLUMN || pColExpr->op==TK_AGG_COLUMN)
120044 && pColExpr->pTab!=0
120045 ){
120046 /* For columns use the column name name */
120047 int iCol = pColExpr->iColumn;
120048 Table *pTab = pColExpr->pTab;
 
120049 if( iCol<0 ) iCol = pTab->iPKey;
120050 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
120051 }else if( pColExpr->op==TK_ID ){
120052 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
120053 zName = pColExpr->u.zToken;
@@ -124606,10 +124765,11 @@
124606
124607 sqlite3ExprDelete(db, pTmp->pWhere);
124608 sqlite3ExprListDelete(db, pTmp->pExprList);
124609 sqlite3SelectDelete(db, pTmp->pSelect);
124610 sqlite3IdListDelete(db, pTmp->pIdList);
 
124611
124612 sqlite3DbFree(db, pTmp);
124613 }
124614 }
124615
@@ -124920,26 +125080,43 @@
124920 sqlite3DeleteTrigger(db, pTrig);
124921 assert( !pParse->pNewTrigger );
124922 sqlite3DeleteTriggerStep(db, pStepList);
124923 }
124924
 
 
 
 
 
 
 
 
 
 
 
124925 /*
124926 ** Turn a SELECT statement (that the pSelect parameter points to) into
124927 ** a trigger step. Return a pointer to a TriggerStep structure.
124928 **
124929 ** The parser calls this routine when it finds a SELECT statement in
124930 ** body of a TRIGGER.
124931 */
124932 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
 
 
 
 
 
124933 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
124934 if( pTriggerStep==0 ) {
124935 sqlite3SelectDelete(db, pSelect);
124936 return 0;
124937 }
124938 pTriggerStep->op = TK_SELECT;
124939 pTriggerStep->pSelect = pSelect;
124940 pTriggerStep->orconf = OE_Default;
 
124941 return pTriggerStep;
124942 }
124943
124944 /*
124945 ** Allocate space to hold a new trigger step. The allocated space
@@ -124948,11 +125125,13 @@
124948 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
124949 */
124950 static TriggerStep *triggerStepAllocate(
124951 sqlite3 *db, /* Database connection */
124952 u8 op, /* Trigger opcode */
124953 Token *pName /* The target name */
 
 
124954 ){
124955 TriggerStep *pTriggerStep;
124956
124957 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
124958 if( pTriggerStep ){
@@ -124959,10 +125138,11 @@
124959 char *z = (char*)&pTriggerStep[1];
124960 memcpy(z, pName->z, pName->n);
124961 sqlite3Dequote(z);
124962 pTriggerStep->zTarget = z;
124963 pTriggerStep->op = op;
 
124964 }
124965 return pTriggerStep;
124966 }
124967
124968 /*
@@ -124975,17 +125155,19 @@
124975 SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(
124976 sqlite3 *db, /* The database connection */
124977 Token *pTableName, /* Name of the table into which we insert */
124978 IdList *pColumn, /* List of columns in pTableName to insert into */
124979 Select *pSelect, /* A SELECT statement that supplies values */
124980 u8 orconf /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
 
 
124981 ){
124982 TriggerStep *pTriggerStep;
124983
124984 assert(pSelect != 0 || db->mallocFailed);
124985
124986 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
124987 if( pTriggerStep ){
124988 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
124989 pTriggerStep->pIdList = pColumn;
124990 pTriggerStep->orconf = orconf;
124991 }else{
@@ -125004,15 +125186,17 @@
125004 SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(
125005 sqlite3 *db, /* The database connection */
125006 Token *pTableName, /* Name of the table to be updated */
125007 ExprList *pEList, /* The SET clause: list of column and new values */
125008 Expr *pWhere, /* The WHERE clause */
125009 u8 orconf /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
 
 
125010 ){
125011 TriggerStep *pTriggerStep;
125012
125013 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
125014 if( pTriggerStep ){
125015 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
125016 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
125017 pTriggerStep->orconf = orconf;
125018 }
@@ -125027,15 +125211,17 @@
125027 ** sees a DELETE statement inside the body of a CREATE TRIGGER.
125028 */
125029 SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(
125030 sqlite3 *db, /* Database connection */
125031 Token *pTableName, /* The table from which rows are deleted */
125032 Expr *pWhere /* The WHERE clause */
 
 
125033 ){
125034 TriggerStep *pTriggerStep;
125035
125036 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
125037 if( pTriggerStep ){
125038 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
125039 pTriggerStep->orconf = OE_Default;
125040 }
125041 sqlite3ExprDelete(db, pWhere);
@@ -125285,10 +125471,18 @@
125285 ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
125286 ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
125287 */
125288 pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
125289 assert( pParse->okConstFactor==0 );
 
 
 
 
 
 
 
 
125290
125291 switch( pStep->op ){
125292 case TK_UPDATE: {
125293 sqlite3Update(pParse,
125294 targetSrcList(pParse, pStep),
@@ -125426,13 +125620,15 @@
125426 (pTrigger->op==TK_INSERT ? "INSERT" : ""),
125427 (pTrigger->op==TK_DELETE ? "DELETE" : ""),
125428 pTab->zName
125429 ));
125430 #ifndef SQLITE_OMIT_TRACE
125431 sqlite3VdbeChangeP4(v, -1,
125432 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
125433 );
 
 
125434 #endif
125435
125436 /* If one was specified, code the WHEN clause. If it evaluates to false
125437 ** (or NULL) the sub-vdbe is immediately halted by jumping to the
125438 ** OP_Halt inserted at the end of the program. */
@@ -128896,11 +129092,11 @@
128896 int iFrom, /* Value for "from" column of output */
128897 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
128898 ){
128899 int ret = 0;
128900 #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
128901 if( pParse->explain==2 )
128902 #endif
128903 {
128904 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
128905 Vdbe *v = pParse->pVdbe; /* VM being constructed */
128906 sqlite3 *db = pParse->db; /* Database handle */
@@ -132526,10 +132722,25 @@
132526 ** so is applicable. Because this module is responsible for selecting
132527 ** indices, you might also think of this module as the "query optimizer".
132528 */
132529 /* #include "sqliteInt.h" */
132530 /* #include "whereInt.h" */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132531
132532 /* Forward declaration of methods */
132533 static int whereLoopResize(sqlite3*, WhereLoop*, int);
132534
132535 /* Test variable that can be set to enable WHERE tracing */
@@ -133349,22 +133560,23 @@
133349 ** Allocate and populate an sqlite3_index_info structure. It is the
133350 ** responsibility of the caller to eventually release the structure
133351 ** by passing the pointer returned by this function to sqlite3_free().
133352 */
133353 static sqlite3_index_info *allocateIndexInfo(
133354 Parse *pParse,
133355 WhereClause *pWC,
133356 Bitmask mUnusable, /* Ignore terms with these prereqs */
133357 struct SrcList_item *pSrc,
133358 ExprList *pOrderBy,
133359 u16 *pmNoOmit /* Mask of terms not to omit */
133360 ){
133361 int i, j;
133362 int nTerm;
133363 struct sqlite3_index_constraint *pIdxCons;
133364 struct sqlite3_index_orderby *pIdxOrderBy;
133365 struct sqlite3_index_constraint_usage *pUsage;
 
133366 WhereTerm *pTerm;
133367 int nOrderBy;
133368 sqlite3_index_info *pIdxInfo;
133369 u16 mNoOmit = 0;
133370
@@ -133402,11 +133614,11 @@
133402
133403 /* Allocate the sqlite3_index_info structure
133404 */
133405 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
133406 + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
133407 + sizeof(*pIdxOrderBy)*nOrderBy );
133408 if( pIdxInfo==0 ){
133409 sqlite3ErrorMsg(pParse, "out of memory");
133410 return 0;
133411 }
133412
@@ -133413,20 +133625,23 @@
133413 /* Initialize the structure. The sqlite3_index_info structure contains
133414 ** many fields that are declared "const" to prevent xBestIndex from
133415 ** changing them. We have to do some funky casting in order to
133416 ** initialize those fields.
133417 */
133418 pIdxCons = (struct sqlite3_index_constraint*)&pIdxInfo[1];
 
133419 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
133420 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
133421 *(int*)&pIdxInfo->nConstraint = nTerm;
133422 *(int*)&pIdxInfo->nOrderBy = nOrderBy;
133423 *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
133424 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
133425 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
133426 pUsage;
133427
 
 
133428 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
133429 u16 op;
133430 if( pTerm->leftCursor != pSrc->iCursor ) continue;
133431 if( pTerm->prereqRight & mUnusable ) continue;
133432 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
@@ -135646,10 +135861,31 @@
135646 (sqlite3_uint64)(pNew->prereq & ~mPrereq)));
135647
135648 return rc;
135649 }
135650
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135651
135652 /*
135653 ** Add all WhereLoop objects for a table of the join identified by
135654 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
135655 **
@@ -137614,11 +137850,15 @@
137614 last = sqlite3VdbeCurrentAddr(v);
137615 k = pLevel->addrBody;
137616 pOp = sqlite3VdbeGetOp(v, k);
137617 for(; k<last; k++, pOp++){
137618 if( pOp->p1!=pLevel->iTabCur ) continue;
137619 if( pOp->opcode==OP_Column ){
 
 
 
 
137620 int x = pOp->p2;
137621 assert( pIdx->pTable==pTab );
137622 if( !HasRowid(pTab) ){
137623 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
137624 x = pPk->aiColumn[x];
@@ -137756,24 +137996,16 @@
137756 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
137757 }
137758 }
137759 }
137760
137761 /* This is a utility routine used to set the ExprSpan.zStart and
137762 ** ExprSpan.zEnd values of pOut so that the span covers the complete
137763 ** range of text beginning with pStart and going to the end of pEnd.
137764 */
137765 static void spanSet(ExprSpan *pOut, Token *pStart, Token *pEnd){
137766 pOut->zStart = pStart->z;
137767 pOut->zEnd = &pEnd->z[pEnd->n];
137768 }
137769
137770 /* Construct a new Expr object from a single identifier. Use the
137771 ** new Expr to populate pOut. Set the span of pOut to be the identifier
137772 ** that created the expression.
137773 */
137774 static void spanExpr(ExprSpan *pOut, Parse *pParse, int op, Token t){
137775 Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
137776 if( p ){
137777 memset(p, 0, sizeof(Expr));
137778 p->op = (u8)op;
137779 p->flags = EP_Leaf;
@@ -137787,48 +138019,12 @@
137787 }
137788 #if SQLITE_MAX_EXPR_DEPTH>0
137789 p->nHeight = 1;
137790 #endif
137791 }
137792 pOut->pExpr = p;
137793 pOut->zStart = t.z;
137794 pOut->zEnd = &t.z[t.n];
137795 }
137796
137797 /* This routine constructs a binary expression node out of two ExprSpan
137798 ** objects and uses the result to populate a new ExprSpan object.
137799 */
137800 static void spanBinaryExpr(
137801 Parse *pParse, /* The parsing context. Errors accumulate here */
137802 int op, /* The binary operation */
137803 ExprSpan *pLeft, /* The left operand, and output */
137804 ExprSpan *pRight /* The right operand */
137805 ){
137806 pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr);
137807 pLeft->zEnd = pRight->zEnd;
137808 }
137809
137810 /* If doNot is true, then add a TK_NOT Expr-node wrapper around the
137811 ** outside of *ppExpr.
137812 */
137813 static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){
137814 if( doNot ){
137815 pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0);
137816 }
137817 }
137818
137819 /* Construct an expression node for a unary postfix operator
137820 */
137821 static void spanUnaryPostfix(
137822 Parse *pParse, /* Parsing context to record errors */
137823 int op, /* The operator */
137824 ExprSpan *pOperand, /* The operand, and output */
137825 Token *pPostOp /* The operand token for setting the span */
137826 ){
137827 pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
137828 pOperand->zEnd = &pPostOp->z[pPostOp->n];
137829 }
137830
137831 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
137832 ** unary TK_ISNULL or TK_NOTNULL expression. */
137833 static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
137834 sqlite3 *db = pParse->db;
@@ -137837,24 +138033,10 @@
137837 sqlite3ExprDelete(db, pA->pRight);
137838 pA->pRight = 0;
137839 }
137840 }
137841
137842 /* Construct an expression node for a unary prefix operator
137843 */
137844 static void spanUnaryPrefix(
137845 ExprSpan *pOut, /* Write the new expression node here */
137846 Parse *pParse, /* Parsing context to record errors */
137847 int op, /* The operator */
137848 ExprSpan *pOperand, /* The operand */
137849 Token *pPreOp /* The operand token for setting the span */
137850 ){
137851 pOut->zStart = pPreOp->z;
137852 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
137853 pOut->zEnd = pOperand->zEnd;
137854 }
137855
137856 /* Add a single new term to an ExprList that is used to store a
137857 ** list of identifiers. Report an error if the ID list contains
137858 ** a COLLATE clause or an ASC or DESC keyword, except ignore the
137859 ** error while parsing a legacy schema.
137860 */
@@ -137919,61 +138101,63 @@
137919 ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
137920 ** YYERRORSYMBOL is the code number of the error symbol. If not
137921 ** defined, then do no error processing.
137922 ** YYNSTATE the combined number of states.
137923 ** YYNRULE the number of rules in the grammar
 
137924 ** YY_MAX_SHIFT Maximum value for shift actions
137925 ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
137926 ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
137927 ** YY_MIN_REDUCE Minimum value for reduce actions
137928 ** YY_MAX_REDUCE Maximum value for reduce actions
137929 ** YY_ERROR_ACTION The yy_action[] code for syntax error
137930 ** YY_ACCEPT_ACTION The yy_action[] code for accept
137931 ** YY_NO_ACTION The yy_action[] code for no-op
 
 
137932 */
137933 #ifndef INTERFACE
137934 # define INTERFACE 1
137935 #endif
137936 /************* Begin control #defines *****************************************/
137937 #define YYCODETYPE unsigned char
137938 #define YYNOCODE 252
137939 #define YYACTIONTYPE unsigned short int
137940 #define YYWILDCARD 83
137941 #define sqlite3ParserTOKENTYPE Token
137942 typedef union {
137943 int yyinit;
137944 sqlite3ParserTOKENTYPE yy0;
137945 Expr* yy72;
137946 TriggerStep* yy145;
137947 ExprList* yy148;
137948 SrcList* yy185;
137949 ExprSpan yy190;
137950 int yy194;
137951 Select* yy243;
137952 IdList* yy254;
137953 With* yy285;
137954 struct TrigEvent yy332;
137955 struct {int value; int mask;} yy497;
137956 } YYMINORTYPE;
137957 #ifndef YYSTACKDEPTH
137958 #define YYSTACKDEPTH 100
137959 #endif
137960 #define sqlite3ParserARG_SDECL Parse *pParse;
137961 #define sqlite3ParserARG_PDECL ,Parse *pParse
137962 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
137963 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
137964 #define YYFALLBACK 1
137965 #define YYNSTATE 455
137966 #define YYNRULE 329
137967 #define YY_MAX_SHIFT 454
137968 #define YY_MIN_SHIFTREDUCE 664
137969 #define YY_MAX_SHIFTREDUCE 992
137970 #define YY_MIN_REDUCE 993
137971 #define YY_MAX_REDUCE 1321
137972 #define YY_ERROR_ACTION 1322
137973 #define YY_ACCEPT_ACTION 1323
137974 #define YY_NO_ACTION 1324
 
137975 /************* End control #defines *******************************************/
137976
137977 /* Define the yytestcase() macro to be a no-op if is not already defined
137978 ** otherwise.
137979 **
@@ -137999,39 +138183,33 @@
137999 ** token onto the stack and goto state N.
138000 **
138001 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
138002 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
138003 **
138004 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
138005 ** and YY_MAX_REDUCE
138006 **
138007 ** N == YY_ERROR_ACTION A syntax error has occurred.
138008 **
138009 ** N == YY_ACCEPT_ACTION The parser accepts its input.
138010 **
138011 ** N == YY_NO_ACTION No such action. Denotes unused
138012 ** slots in the yy_action[] table.
 
 
 
138013 **
138014 ** The action table is constructed as a single large table named yy_action[].
138015 ** Given state S and lookahead X, the action is computed as either:
138016 **
138017 ** (A) N = yy_action[ yy_shift_ofst[S] + X ]
138018 ** (B) N = yy_default[S]
138019 **
138020 ** The (A) formula is preferred. The B formula is used instead if:
138021 ** (1) The yy_shift_ofst[S]+X value is out of range, or
138022 ** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
138023 ** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
138024 ** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
138025 ** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
138026 ** Hence only tests (1) and (2) need to be evaluated.)
138027 **
138028 ** The formulas above are for computing the action when the lookahead is
138029 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
138030 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
138031 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
138032 ** YY_SHIFT_USE_DFLT.
138033 **
138034 ** The following are the tables generated in this section:
138035 **
138036 ** yy_action[] A single table containing all actions.
138037 ** yy_lookahead[] A table containing the lookahead for each entry in
@@ -138041,467 +138219,478 @@
138041 ** yy_reduce_ofst[] For each state, the offset into yy_action for
138042 ** shifting non-terminals after a reduce.
138043 ** yy_default[] Default action for each state.
138044 **
138045 *********** Begin parsing tables **********************************************/
138046 #define YY_ACTTAB_COUNT (1566)
138047 static const YYACTIONTYPE yy_action[] = {
138048 /* 0 */ 324, 1323, 155, 155, 2, 203, 94, 94, 94, 93,
138049 /* 10 */ 350, 98, 98, 98, 98, 91, 95, 95, 94, 94,
138050 /* 20 */ 94, 93, 350, 268, 99, 100, 90, 971, 971, 847,
138051 /* 30 */ 850, 839, 839, 97, 97, 98, 98, 98, 98, 350,
138052 /* 40 */ 969, 96, 96, 96, 96, 95, 95, 94, 94, 94,
138053 /* 50 */ 93, 350, 950, 96, 96, 96, 96, 95, 95, 94,
138054 /* 60 */ 94, 94, 93, 350, 250, 96, 96, 96, 96, 95,
138055 /* 70 */ 95, 94, 94, 94, 93, 350, 224, 224, 969, 132,
138056 /* 80 */ 888, 348, 347, 415, 172, 324, 1286, 449, 414, 950,
138057 /* 90 */ 951, 952, 808, 977, 1032, 950, 300, 786, 428, 132,
138058 /* 100 */ 975, 362, 976, 9, 9, 787, 132, 52, 52, 99,
138059 /* 110 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
138060 /* 120 */ 98, 98, 98, 98, 372, 978, 241, 978, 262, 369,
138061 /* 130 */ 261, 120, 950, 951, 952, 194, 58, 324, 401, 398,
138062 /* 140 */ 397, 808, 427, 429, 75, 808, 1260, 1260, 132, 396,
138063 /* 150 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
138064 /* 160 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839,
138065 /* 170 */ 97, 97, 98, 98, 98, 98, 786, 262, 369, 261,
138066 /* 180 */ 826, 262, 364, 251, 787, 1084, 101, 1114, 72, 324,
138067 /* 190 */ 227, 1113, 242, 411, 442, 819, 92, 89, 178, 818,
138068 /* 200 */ 1022, 268, 96, 96, 96, 96, 95, 95, 94, 94,
138069 /* 210 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850,
138070 /* 220 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 372,
138071 /* 230 */ 818, 818, 820, 92, 89, 178, 60, 92, 89, 178,
138072 /* 240 */ 1025, 324, 357, 930, 1316, 300, 61, 1316, 52, 52,
138073 /* 250 */ 836, 836, 848, 851, 96, 96, 96, 96, 95, 95,
138074 /* 260 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971,
138075 /* 270 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
138076 /* 280 */ 92, 89, 178, 427, 412, 198, 930, 1317, 454, 995,
138077 /* 290 */ 1317, 355, 1024, 324, 243, 231, 114, 277, 348, 347,
138078 /* 300 */ 1242, 950, 416, 1071, 928, 840, 96, 96, 96, 96,
138079 /* 310 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90,
138080 /* 320 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
138081 /* 330 */ 98, 98, 449, 328, 449, 120, 23, 256, 950, 951,
138082 /* 340 */ 952, 968, 978, 438, 978, 324, 329, 928, 954, 701,
138083 /* 350 */ 200, 175, 52, 52, 52, 52, 939, 353, 96, 96,
138084 /* 360 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99,
138085 /* 370 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
138086 /* 380 */ 98, 98, 98, 98, 354, 449, 954, 427, 417, 427,
138087 /* 390 */ 426, 1290, 92, 89, 178, 268, 253, 324, 255, 1058,
138088 /* 400 */ 1037, 694, 93, 350, 383, 52, 52, 380, 1058, 374,
138089 /* 410 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
138090 /* 420 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839,
138091 /* 430 */ 97, 97, 98, 98, 98, 98, 228, 449, 167, 449,
138092 /* 440 */ 427, 407, 157, 446, 446, 446, 349, 349, 349, 324,
138093 /* 450 */ 310, 316, 991, 827, 320, 242, 411, 51, 51, 36,
138094 /* 460 */ 36, 254, 96, 96, 96, 96, 95, 95, 94, 94,
138095 /* 470 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850,
138096 /* 480 */ 839, 839, 97, 97, 98, 98, 98, 98, 194, 316,
138097 /* 490 */ 929, 401, 398, 397, 224, 224, 1265, 939, 353, 1318,
138098 /* 500 */ 317, 324, 396, 1063, 1063, 813, 414, 1061, 1061, 950,
138099 /* 510 */ 299, 448, 992, 268, 96, 96, 96, 96, 95, 95,
138100 /* 520 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971,
138101 /* 530 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
138102 /* 540 */ 757, 1041, 449, 893, 893, 386, 950, 951, 952, 410,
138103 /* 550 */ 992, 747, 747, 324, 229, 268, 221, 296, 268, 771,
138104 /* 560 */ 890, 378, 52, 52, 890, 421, 96, 96, 96, 96,
138105 /* 570 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90,
138106 /* 580 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
138107 /* 590 */ 98, 98, 103, 449, 275, 384, 1241, 343, 157, 1207,
138108 /* 600 */ 909, 669, 670, 671, 176, 197, 196, 195, 324, 298,
138109 /* 610 */ 319, 1266, 2, 37, 37, 910, 1134, 1040, 96, 96,
138110 /* 620 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 697,
138111 /* 630 */ 911, 177, 99, 100, 90, 971, 971, 847, 850, 839,
138112 /* 640 */ 839, 97, 97, 98, 98, 98, 98, 230, 146, 120,
138113 /* 650 */ 735, 1235, 826, 270, 1141, 273, 1141, 771, 171, 170,
138114 /* 660 */ 736, 1141, 82, 324, 80, 268, 697, 819, 158, 268,
138115 /* 670 */ 378, 818, 78, 96, 96, 96, 96, 95, 95, 94,
138116 /* 680 */ 94, 94, 93, 350, 120, 950, 393, 99, 100, 90,
138117 /* 690 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
138118 /* 700 */ 98, 98, 818, 818, 820, 1141, 1070, 370, 331, 133,
138119 /* 710 */ 1066, 1141, 1250, 198, 268, 324, 1016, 330, 245, 333,
138120 /* 720 */ 24, 334, 950, 951, 952, 368, 335, 81, 96, 96,
138121 /* 730 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99,
138122 /* 740 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
138123 /* 750 */ 98, 98, 98, 98, 132, 267, 260, 445, 330, 223,
138124 /* 760 */ 175, 1289, 925, 752, 724, 318, 1073, 324, 751, 246,
138125 /* 770 */ 385, 301, 301, 378, 329, 361, 344, 414, 1233, 280,
138126 /* 780 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
138127 /* 790 */ 350, 99, 88, 90, 971, 971, 847, 850, 839, 839,
138128 /* 800 */ 97, 97, 98, 98, 98, 98, 337, 346, 721, 722,
138129 /* 810 */ 449, 120, 118, 887, 162, 887, 810, 371, 324, 202,
138130 /* 820 */ 202, 373, 249, 263, 202, 394, 74, 704, 208, 1069,
138131 /* 830 */ 12, 12, 96, 96, 96, 96, 95, 95, 94, 94,
138132 /* 840 */ 94, 93, 350, 100, 90, 971, 971, 847, 850, 839,
138133 /* 850 */ 839, 97, 97, 98, 98, 98, 98, 449, 771, 232,
138134 /* 860 */ 449, 278, 120, 286, 74, 704, 714, 713, 324, 342,
138135 /* 870 */ 749, 877, 1209, 77, 285, 1255, 780, 52, 52, 202,
138136 /* 880 */ 27, 27, 418, 96, 96, 96, 96, 95, 95, 94,
138137 /* 890 */ 94, 94, 93, 350, 90, 971, 971, 847, 850, 839,
138138 /* 900 */ 839, 97, 97, 98, 98, 98, 98, 86, 444, 877,
138139 /* 910 */ 3, 1193, 422, 1013, 873, 435, 886, 208, 886, 689,
138140 /* 920 */ 1091, 257, 116, 822, 447, 1230, 117, 1229, 86, 444,
138141 /* 930 */ 177, 3, 381, 96, 96, 96, 96, 95, 95, 94,
138142 /* 940 */ 94, 94, 93, 350, 339, 447, 120, 351, 120, 212,
138143 /* 950 */ 169, 287, 404, 282, 403, 199, 771, 950, 433, 419,
138144 /* 960 */ 439, 822, 280, 691, 1039, 264, 269, 132, 351, 153,
138145 /* 970 */ 826, 376, 74, 272, 274, 276, 83, 84, 1054, 433,
138146 /* 980 */ 147, 1038, 443, 85, 351, 451, 450, 281, 132, 818,
138147 /* 990 */ 25, 826, 449, 120, 950, 951, 952, 83, 84, 86,
138148 /* 1000 */ 444, 691, 3, 408, 85, 351, 451, 450, 449, 5,
138149 /* 1010 */ 818, 203, 32, 32, 1107, 120, 447, 950, 225, 1140,
138150 /* 1020 */ 818, 818, 820, 821, 19, 203, 226, 950, 38, 38,
138151 /* 1030 */ 1087, 314, 314, 313, 215, 311, 120, 449, 678, 351,
138152 /* 1040 */ 237, 818, 818, 820, 821, 19, 969, 409, 377, 1,
138153 /* 1050 */ 433, 180, 706, 248, 950, 951, 952, 10, 10, 449,
138154 /* 1060 */ 969, 247, 826, 1098, 950, 951, 952, 430, 83, 84,
138155 /* 1070 */ 756, 336, 950, 20, 431, 85, 351, 451, 450, 10,
138156 /* 1080 */ 10, 818, 86, 444, 969, 3, 950, 449, 302, 303,
138157 /* 1090 */ 182, 950, 1146, 338, 1021, 1015, 1004, 183, 969, 447,
138158 /* 1100 */ 132, 181, 76, 444, 21, 3, 449, 10, 10, 950,
138159 /* 1110 */ 951, 952, 818, 818, 820, 821, 19, 715, 1279, 447,
138160 /* 1120 */ 389, 233, 351, 950, 951, 952, 10, 10, 950, 951,
138161 /* 1130 */ 952, 1003, 218, 433, 1005, 325, 1273, 773, 289, 291,
138162 /* 1140 */ 424, 293, 351, 7, 159, 826, 363, 402, 315, 360,
138163 /* 1150 */ 1129, 83, 84, 433, 1232, 716, 772, 259, 85, 351,
138164 /* 1160 */ 451, 450, 358, 375, 818, 826, 360, 359, 399, 1211,
138165 /* 1170 */ 157, 83, 84, 681, 98, 98, 98, 98, 85, 351,
138166 /* 1180 */ 451, 450, 323, 252, 818, 295, 1211, 1213, 1235, 173,
138167 /* 1190 */ 1037, 284, 434, 340, 1204, 818, 818, 820, 821, 19,
138168 /* 1200 */ 308, 234, 449, 234, 96, 96, 96, 96, 95, 95,
138169 /* 1210 */ 94, 94, 94, 93, 350, 818, 818, 820, 821, 19,
138170 /* 1220 */ 909, 120, 39, 39, 1203, 449, 168, 360, 449, 1276,
138171 /* 1230 */ 367, 449, 135, 449, 986, 910, 449, 1249, 449, 1247,
138172 /* 1240 */ 449, 205, 983, 449, 370, 40, 40, 1211, 41, 41,
138173 /* 1250 */ 911, 42, 42, 28, 28, 870, 29, 29, 31, 31,
138174 /* 1260 */ 43, 43, 379, 44, 44, 449, 59, 449, 332, 449,
138175 /* 1270 */ 432, 62, 144, 156, 449, 130, 449, 72, 449, 137,
138176 /* 1280 */ 449, 365, 449, 392, 139, 45, 45, 11, 11, 46,
138177 /* 1290 */ 46, 140, 1200, 449, 105, 105, 47, 47, 48, 48,
138178 /* 1300 */ 33, 33, 49, 49, 1126, 449, 141, 366, 449, 185,
138179 /* 1310 */ 142, 449, 1234, 50, 50, 449, 160, 449, 148, 449,
138180 /* 1320 */ 1136, 382, 449, 67, 449, 34, 34, 449, 122, 122,
138181 /* 1330 */ 449, 123, 123, 449, 1198, 124, 124, 56, 56, 35,
138182 /* 1340 */ 35, 449, 106, 106, 53, 53, 449, 107, 107, 449,
138183 /* 1350 */ 108, 108, 449, 104, 104, 449, 406, 449, 388, 449,
138184 /* 1360 */ 189, 121, 121, 449, 190, 449, 119, 119, 449, 112,
138185 /* 1370 */ 112, 449, 111, 111, 1218, 109, 109, 110, 110, 55,
138186 /* 1380 */ 55, 266, 752, 57, 57, 54, 54, 751, 26, 26,
138187 /* 1390 */ 1099, 30, 30, 219, 154, 390, 271, 191, 321, 1006,
138188 /* 1400 */ 192, 405, 1057, 1056, 1055, 341, 1048, 706, 1047, 1029,
138189 /* 1410 */ 322, 420, 1028, 71, 1095, 283, 288, 1027, 1288, 204,
138190 /* 1420 */ 6, 297, 79, 1184, 437, 1096, 1094, 290, 345, 292,
138191 /* 1430 */ 441, 1093, 294, 102, 425, 73, 423, 213, 1012, 22,
138192 /* 1440 */ 452, 945, 214, 1077, 216, 217, 238, 453, 306, 304,
138193 /* 1450 */ 307, 239, 240, 1001, 305, 125, 996, 126, 115, 235,
138194 /* 1460 */ 127, 665, 352, 166, 244, 179, 356, 113, 885, 883,
138195 /* 1470 */ 806, 136, 128, 738, 326, 138, 327, 258, 184, 899,
138196 /* 1480 */ 143, 129, 145, 63, 64, 65, 66, 902, 186, 187,
138197 /* 1490 */ 898, 8, 13, 188, 134, 265, 891, 202, 980, 387,
138198 /* 1500 */ 150, 149, 680, 161, 391, 193, 285, 279, 395, 151,
138199 /* 1510 */ 68, 717, 14, 15, 400, 69, 16, 131, 236, 825,
138200 /* 1520 */ 824, 853, 746, 750, 4, 70, 174, 413, 220, 222,
138201 /* 1530 */ 152, 779, 774, 77, 868, 74, 854, 201, 17, 852,
138202 /* 1540 */ 908, 206, 907, 207, 18, 857, 934, 163, 436, 210,
138203 /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 312, 690, 87,
138204 /* 1560 */ 211, 309, 1281, 940, 995, 1280,
138205 };
138206 static const YYCODETYPE yy_lookahead[] = {
138207 /* 0 */ 19, 144, 145, 146, 147, 24, 90, 91, 92, 93,
138208 /* 10 */ 94, 54, 55, 56, 57, 58, 88, 89, 90, 91,
138209 /* 20 */ 92, 93, 94, 152, 43, 44, 45, 46, 47, 48,
138210 /* 30 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 94,
138211 /* 40 */ 59, 84, 85, 86, 87, 88, 89, 90, 91, 92,
138212 /* 50 */ 93, 94, 59, 84, 85, 86, 87, 88, 89, 90,
138213 /* 60 */ 91, 92, 93, 94, 193, 84, 85, 86, 87, 88,
138214 /* 70 */ 89, 90, 91, 92, 93, 94, 194, 195, 97, 79,
138215 /* 80 */ 11, 88, 89, 152, 26, 19, 171, 152, 206, 96,
138216 /* 90 */ 97, 98, 72, 100, 179, 59, 152, 31, 163, 79,
138217 /* 100 */ 107, 219, 109, 172, 173, 39, 79, 172, 173, 43,
138218 /* 110 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138219 /* 120 */ 54, 55, 56, 57, 152, 132, 199, 134, 108, 109,
138220 /* 130 */ 110, 196, 96, 97, 98, 99, 209, 19, 102, 103,
138221 /* 140 */ 104, 72, 207, 208, 26, 72, 119, 120, 79, 113,
138222 /* 150 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138223 /* 160 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138224 /* 170 */ 52, 53, 54, 55, 56, 57, 31, 108, 109, 110,
138225 /* 180 */ 82, 108, 109, 110, 39, 210, 68, 175, 130, 19,
138226 /* 190 */ 218, 175, 119, 120, 250, 97, 221, 222, 223, 101,
138227 /* 200 */ 172, 152, 84, 85, 86, 87, 88, 89, 90, 91,
138228 /* 210 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
138229 /* 220 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 152,
138230 /* 230 */ 132, 133, 134, 221, 222, 223, 66, 221, 222, 223,
138231 /* 240 */ 172, 19, 193, 22, 23, 152, 24, 26, 172, 173,
138232 /* 250 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89,
138233 /* 260 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138234 /* 270 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138235 /* 280 */ 221, 222, 223, 207, 208, 46, 22, 23, 148, 149,
138236 /* 290 */ 26, 242, 172, 19, 154, 218, 156, 23, 88, 89,
138237 /* 300 */ 241, 59, 163, 163, 83, 101, 84, 85, 86, 87,
138238 /* 310 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
138239 /* 320 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138240 /* 330 */ 56, 57, 152, 157, 152, 196, 196, 16, 96, 97,
138241 /* 340 */ 98, 26, 132, 250, 134, 19, 107, 83, 59, 23,
138242 /* 350 */ 211, 212, 172, 173, 172, 173, 1, 2, 84, 85,
138243 /* 360 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
138244 /* 370 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138245 /* 380 */ 54, 55, 56, 57, 244, 152, 97, 207, 208, 207,
138246 /* 390 */ 208, 185, 221, 222, 223, 152, 75, 19, 77, 179,
138247 /* 400 */ 180, 23, 93, 94, 228, 172, 173, 231, 188, 152,
138248 /* 410 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138249 /* 420 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138250 /* 430 */ 52, 53, 54, 55, 56, 57, 193, 152, 123, 152,
138251 /* 440 */ 207, 208, 152, 168, 169, 170, 168, 169, 170, 19,
138252 /* 450 */ 160, 22, 23, 23, 164, 119, 120, 172, 173, 172,
138253 /* 460 */ 173, 140, 84, 85, 86, 87, 88, 89, 90, 91,
138254 /* 470 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
138255 /* 480 */ 50, 51, 52, 53, 54, 55, 56, 57, 99, 22,
138256 /* 490 */ 23, 102, 103, 104, 194, 195, 0, 1, 2, 247,
138257 /* 500 */ 248, 19, 113, 190, 191, 23, 206, 190, 191, 59,
138258 /* 510 */ 225, 152, 83, 152, 84, 85, 86, 87, 88, 89,
138259 /* 520 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138260 /* 530 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138261 /* 540 */ 90, 181, 152, 108, 109, 110, 96, 97, 98, 115,
138262 /* 550 */ 83, 117, 118, 19, 193, 152, 23, 152, 152, 26,
138263 /* 560 */ 29, 152, 172, 173, 33, 152, 84, 85, 86, 87,
138264 /* 570 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
138265 /* 580 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138266 /* 590 */ 56, 57, 22, 152, 16, 64, 193, 207, 152, 193,
138267 /* 600 */ 12, 7, 8, 9, 152, 108, 109, 110, 19, 152,
138268 /* 610 */ 164, 146, 147, 172, 173, 27, 163, 181, 84, 85,
138269 /* 620 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 59,
138270 /* 630 */ 42, 98, 43, 44, 45, 46, 47, 48, 49, 50,
138271 /* 640 */ 51, 52, 53, 54, 55, 56, 57, 238, 22, 196,
138272 /* 650 */ 62, 163, 82, 75, 152, 77, 152, 124, 88, 89,
138273 /* 660 */ 72, 152, 137, 19, 139, 152, 96, 97, 24, 152,
138274 /* 670 */ 152, 101, 138, 84, 85, 86, 87, 88, 89, 90,
138275 /* 680 */ 91, 92, 93, 94, 196, 59, 19, 43, 44, 45,
138276 /* 690 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138277 /* 700 */ 56, 57, 132, 133, 134, 152, 193, 219, 245, 246,
138278 /* 710 */ 193, 152, 152, 46, 152, 19, 166, 167, 152, 217,
138279 /* 720 */ 232, 217, 96, 97, 98, 237, 217, 138, 84, 85,
138280 /* 730 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
138281 /* 740 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138282 /* 750 */ 54, 55, 56, 57, 79, 193, 238, 166, 167, 211,
138283 /* 760 */ 212, 23, 23, 116, 26, 26, 195, 19, 121, 152,
138284 /* 770 */ 217, 152, 152, 152, 107, 100, 217, 206, 163, 112,
138285 /* 780 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138286 /* 790 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138287 /* 800 */ 52, 53, 54, 55, 56, 57, 187, 187, 7, 8,
138288 /* 810 */ 152, 196, 22, 132, 24, 134, 23, 23, 19, 26,
138289 /* 820 */ 26, 23, 152, 23, 26, 23, 26, 59, 26, 163,
138290 /* 830 */ 172, 173, 84, 85, 86, 87, 88, 89, 90, 91,
138291 /* 840 */ 92, 93, 94, 44, 45, 46, 47, 48, 49, 50,
138292 /* 850 */ 51, 52, 53, 54, 55, 56, 57, 152, 26, 238,
138293 /* 860 */ 152, 23, 196, 101, 26, 97, 100, 101, 19, 19,
138294 /* 870 */ 23, 59, 152, 26, 112, 152, 23, 172, 173, 26,
138295 /* 880 */ 172, 173, 19, 84, 85, 86, 87, 88, 89, 90,
138296 /* 890 */ 91, 92, 93, 94, 45, 46, 47, 48, 49, 50,
138297 /* 900 */ 51, 52, 53, 54, 55, 56, 57, 19, 20, 97,
138298 /* 910 */ 22, 23, 207, 163, 23, 163, 132, 26, 134, 23,
138299 /* 920 */ 213, 152, 26, 59, 36, 152, 22, 152, 19, 20,
138300 /* 930 */ 98, 22, 152, 84, 85, 86, 87, 88, 89, 90,
138301 /* 940 */ 91, 92, 93, 94, 94, 36, 196, 59, 196, 99,
138302 /* 950 */ 100, 101, 102, 103, 104, 105, 124, 59, 70, 96,
138303 /* 960 */ 163, 97, 112, 59, 181, 152, 152, 79, 59, 71,
138304 /* 970 */ 82, 19, 26, 152, 152, 152, 88, 89, 152, 70,
138305 /* 980 */ 22, 152, 163, 95, 96, 97, 98, 152, 79, 101,
138306 /* 990 */ 22, 82, 152, 196, 96, 97, 98, 88, 89, 19,
138307 /* 1000 */ 20, 97, 22, 163, 95, 96, 97, 98, 152, 22,
138308 /* 1010 */ 101, 24, 172, 173, 152, 196, 36, 59, 22, 152,
138309 /* 1020 */ 132, 133, 134, 135, 136, 24, 5, 59, 172, 173,
138310 /* 1030 */ 152, 10, 11, 12, 13, 14, 196, 152, 17, 59,
138311 /* 1040 */ 210, 132, 133, 134, 135, 136, 59, 207, 96, 22,
138312 /* 1050 */ 70, 30, 106, 32, 96, 97, 98, 172, 173, 152,
138313 /* 1060 */ 59, 40, 82, 152, 96, 97, 98, 152, 88, 89,
138314 /* 1070 */ 90, 186, 59, 22, 191, 95, 96, 97, 98, 172,
138315 /* 1080 */ 173, 101, 19, 20, 97, 22, 59, 152, 152, 152,
138316 /* 1090 */ 69, 59, 152, 186, 152, 152, 152, 76, 97, 36,
138317 /* 1100 */ 79, 80, 19, 20, 53, 22, 152, 172, 173, 96,
138318 /* 1110 */ 97, 98, 132, 133, 134, 135, 136, 35, 122, 36,
138319 /* 1120 */ 234, 186, 59, 96, 97, 98, 172, 173, 96, 97,
138320 /* 1130 */ 98, 152, 233, 70, 152, 114, 152, 124, 210, 210,
138321 /* 1140 */ 186, 210, 59, 198, 197, 82, 214, 65, 150, 152,
138322 /* 1150 */ 201, 88, 89, 70, 201, 73, 124, 239, 95, 96,
138323 /* 1160 */ 97, 98, 141, 239, 101, 82, 169, 170, 176, 152,
138324 /* 1170 */ 152, 88, 89, 21, 54, 55, 56, 57, 95, 96,
138325 /* 1180 */ 97, 98, 164, 214, 101, 214, 169, 170, 163, 184,
138326 /* 1190 */ 180, 175, 227, 111, 175, 132, 133, 134, 135, 136,
138327 /* 1200 */ 200, 183, 152, 185, 84, 85, 86, 87, 88, 89,
138328 /* 1210 */ 90, 91, 92, 93, 94, 132, 133, 134, 135, 136,
138329 /* 1220 */ 12, 196, 172, 173, 175, 152, 198, 230, 152, 155,
138330 /* 1230 */ 78, 152, 243, 152, 60, 27, 152, 159, 152, 159,
138331 /* 1240 */ 152, 122, 38, 152, 219, 172, 173, 230, 172, 173,
138332 /* 1250 */ 42, 172, 173, 172, 173, 103, 172, 173, 172, 173,
138333 /* 1260 */ 172, 173, 237, 172, 173, 152, 240, 152, 159, 152,
138334 /* 1270 */ 62, 240, 22, 220, 152, 43, 152, 130, 152, 189,
138335 /* 1280 */ 152, 18, 152, 18, 192, 172, 173, 172, 173, 172,
138336 /* 1290 */ 173, 192, 140, 152, 172, 173, 172, 173, 172, 173,
138337 /* 1300 */ 172, 173, 172, 173, 201, 152, 192, 159, 152, 158,
138338 /* 1310 */ 192, 152, 201, 172, 173, 152, 220, 152, 189, 152,
138339 /* 1320 */ 189, 159, 152, 137, 152, 172, 173, 152, 172, 173,
138340 /* 1330 */ 152, 172, 173, 152, 201, 172, 173, 172, 173, 172,
138341 /* 1340 */ 173, 152, 172, 173, 172, 173, 152, 172, 173, 152,
138342 /* 1350 */ 172, 173, 152, 172, 173, 152, 90, 152, 61, 152,
138343 /* 1360 */ 158, 172, 173, 152, 158, 152, 172, 173, 152, 172,
138344 /* 1370 */ 173, 152, 172, 173, 236, 172, 173, 172, 173, 172,
138345 /* 1380 */ 173, 235, 116, 172, 173, 172, 173, 121, 172, 173,
138346 /* 1390 */ 159, 172, 173, 159, 22, 177, 159, 158, 177, 159,
138347 /* 1400 */ 158, 107, 174, 174, 174, 63, 182, 106, 182, 174,
138348 /* 1410 */ 177, 125, 176, 107, 216, 174, 215, 174, 174, 159,
138349 /* 1420 */ 22, 159, 137, 224, 177, 216, 216, 215, 94, 215,
138350 /* 1430 */ 177, 216, 215, 129, 126, 128, 127, 25, 162, 26,
138351 /* 1440 */ 161, 13, 153, 205, 153, 6, 226, 151, 202, 204,
138352 /* 1450 */ 201, 229, 229, 151, 203, 165, 151, 165, 178, 178,
138353 /* 1460 */ 165, 4, 3, 22, 142, 15, 81, 16, 23, 23,
138354 /* 1470 */ 120, 131, 111, 20, 249, 123, 249, 16, 125, 1,
138355 /* 1480 */ 123, 111, 131, 53, 53, 53, 53, 96, 34, 122,
138356 /* 1490 */ 1, 5, 22, 107, 246, 140, 67, 26, 74, 41,
138357 /* 1500 */ 107, 67, 20, 24, 19, 105, 112, 23, 66, 22,
138358 /* 1510 */ 22, 28, 22, 22, 66, 22, 22, 37, 66, 23,
138359 /* 1520 */ 23, 23, 116, 23, 22, 26, 122, 26, 23, 23,
138360 /* 1530 */ 22, 96, 124, 26, 23, 26, 23, 34, 34, 23,
138361 /* 1540 */ 23, 26, 23, 22, 34, 11, 23, 22, 24, 122,
138362 /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 15, 23, 22,
138363 /* 1560 */ 122, 23, 122, 1, 251, 122,
138364 };
138365 #define YY_SHIFT_USE_DFLT (1566)
138366 #define YY_SHIFT_COUNT (454)
138367 #define YY_SHIFT_MIN (-84)
138368 #define YY_SHIFT_MAX (1562)
138369 static const short yy_shift_ofst[] = {
138370 /* 0 */ 355, 888, 1021, 909, 1063, 1063, 1063, 1063, 20, -19,
138371 /* 10 */ 66, 66, 170, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138372 /* 20 */ -7, -7, 36, 73, 69, 27, 118, 222, 274, 326,
138373 /* 30 */ 378, 430, 482, 534, 589, 644, 696, 696, 696, 696,
138374 /* 40 */ 696, 696, 696, 696, 696, 696, 696, 696, 696, 696,
138375 /* 50 */ 696, 696, 696, 748, 696, 799, 849, 849, 980, 1063,
138376 /* 60 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138377 /* 70 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138378 /* 80 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138379 /* 90 */ 1083, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
138380 /* 100 */ 1063, 1063, 1063, 1063, -43, 1120, 1120, 1120, 1120, 1120,
138381 /* 110 */ -31, -72, -84, 242, 1152, 667, 210, 210, 242, 309,
138382 /* 120 */ 336, -55, 1566, 1566, 1566, 850, 850, 850, 626, 626,
138383 /* 130 */ 588, 588, 898, 221, 264, 242, 242, 242, 242, 242,
138384 /* 140 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
138385 /* 150 */ 242, 242, 242, 242, 242, 496, 675, 289, 289, 336,
138386 /* 160 */ 0, 0, 0, 0, 0, 0, 1566, 1566, 1566, 570,
138387 /* 170 */ 98, 98, 958, 389, 450, 968, 1013, 1032, 1027, 242,
138388 /* 180 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
138389 /* 190 */ 242, 242, 242, 242, 242, 1082, 1082, 1082, 242, 242,
138390 /* 200 */ 533, 242, 242, 242, 987, 242, 242, 1208, 242, 242,
138391 /* 210 */ 242, 242, 242, 242, 242, 242, 242, 242, 435, 531,
138392 /* 220 */ 1001, 1001, 1001, 832, 434, 1266, 594, 58, 863, 863,
138393 /* 230 */ 952, 58, 952, 946, 738, 239, 145, 863, 525, 145,
138394 /* 240 */ 145, 315, 647, 790, 1174, 1119, 1119, 1204, 1204, 1119,
138395 /* 250 */ 1250, 1232, 1147, 1263, 1263, 1263, 1263, 1119, 1265, 1147,
138396 /* 260 */ 1250, 1232, 1232, 1147, 1119, 1265, 1186, 1297, 1119, 1119,
138397 /* 270 */ 1265, 1372, 1119, 1265, 1119, 1265, 1372, 1294, 1294, 1294,
138398 /* 280 */ 1342, 1372, 1294, 1301, 1294, 1342, 1294, 1294, 1286, 1306,
138399 /* 290 */ 1286, 1306, 1286, 1306, 1286, 1306, 1119, 1398, 1119, 1285,
138400 /* 300 */ 1372, 1334, 1334, 1372, 1304, 1308, 1307, 1309, 1147, 1412,
138401 /* 310 */ 1413, 1428, 1428, 1439, 1439, 1439, 1566, 1566, 1566, 1566,
138402 /* 320 */ 1566, 1566, 1566, 1566, 204, 321, 429, 467, 578, 497,
138403 /* 330 */ 904, 739, 1051, 793, 794, 798, 800, 802, 838, 768,
138404 /* 340 */ 766, 801, 762, 847, 853, 812, 891, 681, 784, 896,
138405 /* 350 */ 864, 996, 1457, 1459, 1441, 1322, 1450, 1385, 1451, 1445,
138406 /* 360 */ 1446, 1350, 1340, 1361, 1352, 1453, 1353, 1461, 1478, 1357,
138407 /* 370 */ 1351, 1430, 1431, 1432, 1433, 1370, 1391, 1454, 1367, 1489,
138408 /* 380 */ 1486, 1470, 1386, 1355, 1429, 1471, 1434, 1424, 1458, 1393,
138409 /* 390 */ 1479, 1482, 1485, 1394, 1400, 1487, 1442, 1488, 1490, 1484,
138410 /* 400 */ 1491, 1448, 1483, 1493, 1452, 1480, 1496, 1497, 1498, 1499,
138411 /* 410 */ 1406, 1494, 1500, 1502, 1501, 1404, 1505, 1506, 1435, 1503,
138412 /* 420 */ 1508, 1408, 1507, 1504, 1509, 1510, 1511, 1507, 1513, 1516,
138413 /* 430 */ 1517, 1515, 1519, 1521, 1534, 1523, 1525, 1524, 1526, 1527,
138414 /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1535, 1537, 1427, 1438,
138415 /* 450 */ 1440, 1443, 1538, 1542, 1562,
138416 };
138417 #define YY_REDUCE_USE_DFLT (-144)
138418 #define YY_REDUCE_COUNT (323)
138419 #define YY_REDUCE_MIN (-143)
138420 #define YY_REDUCE_MAX (1305)
 
 
 
 
 
 
 
 
 
 
 
138421 static const short yy_reduce_ofst[] = {
138422 /* 0 */ -143, -65, 140, 840, 76, 180, 182, 233, 488, -25,
138423 /* 10 */ 12, 16, 59, 885, 907, 935, 390, 705, 954, 285,
138424 /* 20 */ 997, 1017, 1018, -118, 1025, 139, 171, 171, 171, 171,
138425 /* 30 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171,
138426 /* 40 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171,
138427 /* 50 */ 171, 171, 171, 171, 171, 171, 171, 171, -69, 287,
138428 /* 60 */ 441, 658, 708, 856, 1050, 1073, 1076, 1079, 1081, 1084,
138429 /* 70 */ 1086, 1088, 1091, 1113, 1115, 1117, 1122, 1124, 1126, 1128,
138430 /* 80 */ 1130, 1141, 1153, 1156, 1159, 1163, 1165, 1167, 1170, 1172,
138431 /* 90 */ 1175, 1178, 1181, 1189, 1194, 1197, 1200, 1203, 1205, 1207,
138432 /* 100 */ 1211, 1213, 1216, 1219, 171, 171, 171, 171, 171, 171,
138433 /* 110 */ 171, 171, 171, 49, 176, 220, 275, 278, 290, 171,
138434 /* 120 */ 300, 171, 171, 171, 171, -85, -85, -85, -28, 77,
138435 /* 130 */ 313, 317, -56, 252, 252, 446, -129, 243, 361, 403,
138436 /* 140 */ 406, 513, 517, 409, 502, 518, 504, 509, 621, 553,
138437 /* 150 */ 562, 619, 559, 93, 620, 465, 453, 550, 591, 571,
138438 /* 160 */ 615, 666, 750, 752, 797, 819, 463, 548, -73, 28,
138439 /* 170 */ 68, 120, 257, 206, 359, 405, 413, 452, 457, 560,
138440 /* 180 */ 566, 617, 670, 720, 723, 769, 773, 775, 780, 813,
138441 /* 190 */ 814, 821, 822, 823, 826, 360, 436, 783, 829, 835,
138442 /* 200 */ 707, 862, 867, 878, 830, 911, 915, 883, 936, 937,
138443 /* 210 */ 940, 359, 942, 943, 944, 979, 982, 984, 886, 899,
138444 /* 220 */ 928, 929, 931, 707, 947, 945, 998, 949, 932, 969,
138445 /* 230 */ 918, 953, 924, 992, 1005, 1010, 1016, 971, 965, 1019,
138446 /* 240 */ 1049, 1000, 1028, 1074, 989, 1078, 1080, 1026, 1031, 1109,
138447 /* 250 */ 1053, 1090, 1103, 1092, 1099, 1114, 1118, 1148, 1151, 1111,
138448 /* 260 */ 1096, 1129, 1131, 1133, 1162, 1202, 1138, 1146, 1231, 1234,
138449 /* 270 */ 1206, 1218, 1237, 1239, 1240, 1242, 1221, 1228, 1229, 1230,
138450 /* 280 */ 1224, 1233, 1235, 1236, 1241, 1226, 1243, 1244, 1198, 1201,
138451 /* 290 */ 1209, 1212, 1210, 1214, 1215, 1217, 1260, 1199, 1262, 1220,
138452 /* 300 */ 1247, 1222, 1223, 1253, 1238, 1245, 1251, 1246, 1249, 1276,
138453 /* 310 */ 1279, 1289, 1291, 1296, 1302, 1305, 1225, 1227, 1248, 1290,
138454 /* 320 */ 1292, 1280, 1281, 1295,
 
138455 };
138456 static const YYACTIONTYPE yy_default[] = {
138457 /* 0 */ 1270, 1260, 1260, 1260, 1193, 1193, 1193, 1193, 1260, 1088,
138458 /* 10 */ 1117, 1117, 1244, 1322, 1322, 1322, 1322, 1322, 1322, 1192,
138459 /* 20 */ 1322, 1322, 1322, 1322, 1260, 1092, 1123, 1322, 1322, 1322,
138460 /* 30 */ 1322, 1194, 1195, 1322, 1322, 1322, 1243, 1245, 1133, 1132,
138461 /* 40 */ 1131, 1130, 1226, 1104, 1128, 1121, 1125, 1194, 1188, 1189,
138462 /* 50 */ 1187, 1191, 1195, 1322, 1124, 1158, 1172, 1157, 1322, 1322,
138463 /* 60 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138464 /* 70 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138465 /* 80 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138466 /* 90 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138467 /* 100 */ 1322, 1322, 1322, 1322, 1166, 1171, 1178, 1170, 1167, 1160,
138468 /* 110 */ 1159, 1161, 1162, 1322, 1011, 1059, 1322, 1322, 1322, 1163,
138469 /* 120 */ 1322, 1164, 1175, 1174, 1173, 1251, 1278, 1277, 1322, 1322,
138470 /* 130 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138471 /* 140 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138472 /* 150 */ 1322, 1322, 1322, 1322, 1322, 1270, 1260, 1017, 1017, 1322,
138473 /* 160 */ 1260, 1260, 1260, 1260, 1260, 1260, 1256, 1092, 1083, 1322,
138474 /* 170 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138475 /* 180 */ 1248, 1246, 1322, 1208, 1322, 1322, 1322, 1322, 1322, 1322,
138476 /* 190 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138477 /* 200 */ 1322, 1322, 1322, 1322, 1088, 1322, 1322, 1322, 1322, 1322,
138478 /* 210 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1272, 1322, 1221,
138479 /* 220 */ 1088, 1088, 1088, 1090, 1072, 1082, 997, 1127, 1106, 1106,
138480 /* 230 */ 1311, 1127, 1311, 1034, 1292, 1031, 1117, 1106, 1190, 1117,
138481 /* 240 */ 1117, 1089, 1082, 1322, 1314, 1097, 1097, 1313, 1313, 1097,
138482 /* 250 */ 1138, 1062, 1127, 1068, 1068, 1068, 1068, 1097, 1008, 1127,
138483 /* 260 */ 1138, 1062, 1062, 1127, 1097, 1008, 1225, 1308, 1097, 1097,
138484 /* 270 */ 1008, 1201, 1097, 1008, 1097, 1008, 1201, 1060, 1060, 1060,
138485 /* 280 */ 1049, 1201, 1060, 1034, 1060, 1049, 1060, 1060, 1110, 1105,
138486 /* 290 */ 1110, 1105, 1110, 1105, 1110, 1105, 1097, 1196, 1097, 1322,
138487 /* 300 */ 1201, 1205, 1205, 1201, 1122, 1111, 1120, 1118, 1127, 1014,
138488 /* 310 */ 1052, 1275, 1275, 1271, 1271, 1271, 1319, 1319, 1256, 1287,
138489 /* 320 */ 1287, 1036, 1036, 1287, 1322, 1322, 1322, 1322, 1322, 1322,
138490 /* 330 */ 1282, 1322, 1210, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138491 /* 340 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138492 /* 350 */ 1322, 1143, 1322, 993, 1253, 1322, 1322, 1252, 1322, 1322,
138493 /* 360 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138494 /* 370 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1310, 1322,
138495 /* 380 */ 1322, 1322, 1322, 1322, 1322, 1224, 1223, 1322, 1322, 1322,
138496 /* 390 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138497 /* 400 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322,
138498 /* 410 */ 1074, 1322, 1322, 1322, 1296, 1322, 1322, 1322, 1322, 1322,
138499 /* 420 */ 1322, 1322, 1119, 1322, 1112, 1322, 1322, 1301, 1322, 1322,
138500 /* 430 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1262, 1322,
138501 /* 440 */ 1322, 1322, 1261, 1322, 1322, 1322, 1322, 1322, 1145, 1322,
138502 /* 450 */ 1144, 1148, 1322, 1002, 1322,
 
138503 };
138504 /********** End of lemon-generated parsing tables *****************************/
138505
138506 /* The next table maps tokens (terminal symbols) into fallback tokens.
138507 ** If a construct like the following:
@@ -138682,79 +138871,268 @@
138682 if( yyTraceFILE==0 ) yyTracePrompt = 0;
138683 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
138684 }
138685 #endif /* NDEBUG */
138686
138687 #ifndef NDEBUG
138688 /* For tracing shifts, the names of all terminals and nonterminals
138689 ** are required. The following table supplies these names */
138690 static const char *const yyTokenName[] = {
138691 "$", "SEMI", "EXPLAIN", "QUERY",
138692 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
138693 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
138694 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
138695 "TABLE", "CREATE", "IF", "NOT",
138696 "EXISTS", "TEMP", "LP", "RP",
138697 "AS", "WITHOUT", "COMMA", "ABORT",
138698 "ACTION", "AFTER", "ANALYZE", "ASC",
138699 "ATTACH", "BEFORE", "BY", "CASCADE",
138700 "CAST", "CONFLICT", "DATABASE", "DESC",
138701 "DETACH", "EACH", "FAIL", "OR",
138702 "AND", "IS", "MATCH", "LIKE_KW",
138703 "BETWEEN", "IN", "ISNULL", "NOTNULL",
138704 "NE", "EQ", "GT", "LE",
138705 "LT", "GE", "ESCAPE", "ID",
138706 "COLUMNKW", "FOR", "IGNORE", "INITIALLY",
138707 "INSTEAD", "NO", "KEY", "OF",
138708 "OFFSET", "PRAGMA", "RAISE", "RECURSIVE",
138709 "REPLACE", "RESTRICT", "ROW", "TRIGGER",
138710 "VACUUM", "VIEW", "VIRTUAL", "WITH",
138711 "REINDEX", "RENAME", "CTIME_KW", "ANY",
138712 "BITAND", "BITOR", "LSHIFT", "RSHIFT",
138713 "PLUS", "MINUS", "STAR", "SLASH",
138714 "REM", "CONCAT", "COLLATE", "BITNOT",
138715 "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
138716 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
138717 "CHECK", "REFERENCES", "AUTOINCR", "ON",
138718 "INSERT", "DELETE", "UPDATE", "SET",
138719 "DEFERRABLE", "FOREIGN", "DROP", "UNION",
138720 "ALL", "EXCEPT", "INTERSECT", "SELECT",
138721 "VALUES", "DISTINCT", "DOT", "FROM",
138722 "JOIN", "USING", "ORDER", "GROUP",
138723 "HAVING", "LIMIT", "WHERE", "INTO",
138724 "FLOAT", "BLOB", "INTEGER", "VARIABLE",
138725 "CASE", "WHEN", "THEN", "ELSE",
138726 "INDEX", "ALTER", "ADD", "error",
138727 "input", "cmdlist", "ecmd", "explain",
138728 "cmdx", "cmd", "transtype", "trans_opt",
138729 "nm", "savepoint_opt", "create_table", "create_table_args",
138730 "createkw", "temp", "ifnotexists", "dbnm",
138731 "columnlist", "conslist_opt", "table_options", "select",
138732 "columnname", "carglist", "typetoken", "typename",
138733 "signed", "plus_num", "minus_num", "ccons",
138734 "term", "expr", "onconf", "sortorder",
138735 "autoinc", "eidlist_opt", "refargs", "defer_subclause",
138736 "refarg", "refact", "init_deferred_pred_opt", "conslist",
138737 "tconscomma", "tcons", "sortlist", "eidlist",
138738 "defer_subclause_opt", "orconf", "resolvetype", "raisetype",
138739 "ifexists", "fullname", "selectnowith", "oneselect",
138740 "with", "multiselect_op", "distinct", "selcollist",
138741 "from", "where_opt", "groupby_opt", "having_opt",
138742 "orderby_opt", "limit_opt", "values", "nexprlist",
138743 "exprlist", "sclp", "as", "seltablist",
138744 "stl_prefix", "joinop", "indexed_opt", "on_opt",
138745 "using_opt", "idlist", "setlist", "insert_cmd",
138746 "idlist_opt", "likeop", "between_op", "in_op",
138747 "paren_exprlist", "case_operand", "case_exprlist", "case_else",
138748 "uniqueflag", "collate", "nmnum", "trigger_decl",
138749 "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause",
138750 "when_clause", "trigger_cmd", "trnm", "tridxby",
138751 "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt",
138752 "create_vtab", "vtabarglist", "vtabarg", "vtabargtoken",
138753 "lp", "anylist", "wqlist",
138754 };
138755 #endif /* NDEBUG */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138756
138757 #ifndef NDEBUG
138758 /* For tracing reduce actions, the names of all rules are required.
138759 */
138760 static const char *const yyRuleName[] = {
@@ -138784,311 +139162,312 @@
138784 /* 23 */ "columnname ::= nm typetoken",
138785 /* 24 */ "typetoken ::=",
138786 /* 25 */ "typetoken ::= typename LP signed RP",
138787 /* 26 */ "typetoken ::= typename LP signed COMMA signed RP",
138788 /* 27 */ "typename ::= typename ID|STRING",
138789 /* 28 */ "ccons ::= CONSTRAINT nm",
138790 /* 29 */ "ccons ::= DEFAULT term",
138791 /* 30 */ "ccons ::= DEFAULT LP expr RP",
138792 /* 31 */ "ccons ::= DEFAULT PLUS term",
138793 /* 32 */ "ccons ::= DEFAULT MINUS term",
138794 /* 33 */ "ccons ::= DEFAULT ID|INDEXED",
138795 /* 34 */ "ccons ::= NOT NULL onconf",
138796 /* 35 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
138797 /* 36 */ "ccons ::= UNIQUE onconf",
138798 /* 37 */ "ccons ::= CHECK LP expr RP",
138799 /* 38 */ "ccons ::= REFERENCES nm eidlist_opt refargs",
138800 /* 39 */ "ccons ::= defer_subclause",
138801 /* 40 */ "ccons ::= COLLATE ID|STRING",
138802 /* 41 */ "autoinc ::=",
138803 /* 42 */ "autoinc ::= AUTOINCR",
138804 /* 43 */ "refargs ::=",
138805 /* 44 */ "refargs ::= refargs refarg",
138806 /* 45 */ "refarg ::= MATCH nm",
138807 /* 46 */ "refarg ::= ON INSERT refact",
138808 /* 47 */ "refarg ::= ON DELETE refact",
138809 /* 48 */ "refarg ::= ON UPDATE refact",
138810 /* 49 */ "refact ::= SET NULL",
138811 /* 50 */ "refact ::= SET DEFAULT",
138812 /* 51 */ "refact ::= CASCADE",
138813 /* 52 */ "refact ::= RESTRICT",
138814 /* 53 */ "refact ::= NO ACTION",
138815 /* 54 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
138816 /* 55 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
138817 /* 56 */ "init_deferred_pred_opt ::=",
138818 /* 57 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
138819 /* 58 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
138820 /* 59 */ "conslist_opt ::=",
138821 /* 60 */ "tconscomma ::= COMMA",
138822 /* 61 */ "tcons ::= CONSTRAINT nm",
138823 /* 62 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf",
138824 /* 63 */ "tcons ::= UNIQUE LP sortlist RP onconf",
138825 /* 64 */ "tcons ::= CHECK LP expr RP onconf",
138826 /* 65 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt",
138827 /* 66 */ "defer_subclause_opt ::=",
138828 /* 67 */ "onconf ::=",
138829 /* 68 */ "onconf ::= ON CONFLICT resolvetype",
138830 /* 69 */ "orconf ::=",
138831 /* 70 */ "orconf ::= OR resolvetype",
138832 /* 71 */ "resolvetype ::= IGNORE",
138833 /* 72 */ "resolvetype ::= REPLACE",
138834 /* 73 */ "cmd ::= DROP TABLE ifexists fullname",
138835 /* 74 */ "ifexists ::= IF EXISTS",
138836 /* 75 */ "ifexists ::=",
138837 /* 76 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select",
138838 /* 77 */ "cmd ::= DROP VIEW ifexists fullname",
138839 /* 78 */ "cmd ::= select",
138840 /* 79 */ "select ::= with selectnowith",
138841 /* 80 */ "selectnowith ::= selectnowith multiselect_op oneselect",
138842 /* 81 */ "multiselect_op ::= UNION",
138843 /* 82 */ "multiselect_op ::= UNION ALL",
138844 /* 83 */ "multiselect_op ::= EXCEPT|INTERSECT",
138845 /* 84 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
138846 /* 85 */ "values ::= VALUES LP nexprlist RP",
138847 /* 86 */ "values ::= values COMMA LP exprlist RP",
138848 /* 87 */ "distinct ::= DISTINCT",
138849 /* 88 */ "distinct ::= ALL",
138850 /* 89 */ "distinct ::=",
138851 /* 90 */ "sclp ::=",
138852 /* 91 */ "selcollist ::= sclp expr as",
138853 /* 92 */ "selcollist ::= sclp STAR",
138854 /* 93 */ "selcollist ::= sclp nm DOT STAR",
138855 /* 94 */ "as ::= AS nm",
138856 /* 95 */ "as ::=",
138857 /* 96 */ "from ::=",
138858 /* 97 */ "from ::= FROM seltablist",
138859 /* 98 */ "stl_prefix ::= seltablist joinop",
138860 /* 99 */ "stl_prefix ::=",
138861 /* 100 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
138862 /* 101 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt",
138863 /* 102 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
138864 /* 103 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
138865 /* 104 */ "dbnm ::=",
138866 /* 105 */ "dbnm ::= DOT nm",
138867 /* 106 */ "fullname ::= nm dbnm",
138868 /* 107 */ "joinop ::= COMMA|JOIN",
138869 /* 108 */ "joinop ::= JOIN_KW JOIN",
138870 /* 109 */ "joinop ::= JOIN_KW nm JOIN",
138871 /* 110 */ "joinop ::= JOIN_KW nm nm JOIN",
138872 /* 111 */ "on_opt ::= ON expr",
138873 /* 112 */ "on_opt ::=",
138874 /* 113 */ "indexed_opt ::=",
138875 /* 114 */ "indexed_opt ::= INDEXED BY nm",
138876 /* 115 */ "indexed_opt ::= NOT INDEXED",
138877 /* 116 */ "using_opt ::= USING LP idlist RP",
138878 /* 117 */ "using_opt ::=",
138879 /* 118 */ "orderby_opt ::=",
138880 /* 119 */ "orderby_opt ::= ORDER BY sortlist",
138881 /* 120 */ "sortlist ::= sortlist COMMA expr sortorder",
138882 /* 121 */ "sortlist ::= expr sortorder",
138883 /* 122 */ "sortorder ::= ASC",
138884 /* 123 */ "sortorder ::= DESC",
138885 /* 124 */ "sortorder ::=",
138886 /* 125 */ "groupby_opt ::=",
138887 /* 126 */ "groupby_opt ::= GROUP BY nexprlist",
138888 /* 127 */ "having_opt ::=",
138889 /* 128 */ "having_opt ::= HAVING expr",
138890 /* 129 */ "limit_opt ::=",
138891 /* 130 */ "limit_opt ::= LIMIT expr",
138892 /* 131 */ "limit_opt ::= LIMIT expr OFFSET expr",
138893 /* 132 */ "limit_opt ::= LIMIT expr COMMA expr",
138894 /* 133 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
138895 /* 134 */ "where_opt ::=",
138896 /* 135 */ "where_opt ::= WHERE expr",
138897 /* 136 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
138898 /* 137 */ "setlist ::= setlist COMMA nm EQ expr",
138899 /* 138 */ "setlist ::= setlist COMMA LP idlist RP EQ expr",
138900 /* 139 */ "setlist ::= nm EQ expr",
138901 /* 140 */ "setlist ::= LP idlist RP EQ expr",
138902 /* 141 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select",
138903 /* 142 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES",
138904 /* 143 */ "insert_cmd ::= INSERT orconf",
138905 /* 144 */ "insert_cmd ::= REPLACE",
138906 /* 145 */ "idlist_opt ::=",
138907 /* 146 */ "idlist_opt ::= LP idlist RP",
138908 /* 147 */ "idlist ::= idlist COMMA nm",
138909 /* 148 */ "idlist ::= nm",
138910 /* 149 */ "expr ::= LP expr RP",
138911 /* 150 */ "expr ::= ID|INDEXED",
138912 /* 151 */ "expr ::= JOIN_KW",
138913 /* 152 */ "expr ::= nm DOT nm",
138914 /* 153 */ "expr ::= nm DOT nm DOT nm",
138915 /* 154 */ "term ::= NULL|FLOAT|BLOB",
138916 /* 155 */ "term ::= STRING",
138917 /* 156 */ "term ::= INTEGER",
138918 /* 157 */ "expr ::= VARIABLE",
138919 /* 158 */ "expr ::= expr COLLATE ID|STRING",
138920 /* 159 */ "expr ::= CAST LP expr AS typetoken RP",
138921 /* 160 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
138922 /* 161 */ "expr ::= ID|INDEXED LP STAR RP",
138923 /* 162 */ "term ::= CTIME_KW",
138924 /* 163 */ "expr ::= LP nexprlist COMMA expr RP",
138925 /* 164 */ "expr ::= expr AND expr",
138926 /* 165 */ "expr ::= expr OR expr",
138927 /* 166 */ "expr ::= expr LT|GT|GE|LE expr",
138928 /* 167 */ "expr ::= expr EQ|NE expr",
138929 /* 168 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
138930 /* 169 */ "expr ::= expr PLUS|MINUS expr",
138931 /* 170 */ "expr ::= expr STAR|SLASH|REM expr",
138932 /* 171 */ "expr ::= expr CONCAT expr",
138933 /* 172 */ "likeop ::= NOT LIKE_KW|MATCH",
138934 /* 173 */ "expr ::= expr likeop expr",
138935 /* 174 */ "expr ::= expr likeop expr ESCAPE expr",
138936 /* 175 */ "expr ::= expr ISNULL|NOTNULL",
138937 /* 176 */ "expr ::= expr NOT NULL",
138938 /* 177 */ "expr ::= expr IS expr",
138939 /* 178 */ "expr ::= expr IS NOT expr",
138940 /* 179 */ "expr ::= NOT expr",
138941 /* 180 */ "expr ::= BITNOT expr",
138942 /* 181 */ "expr ::= MINUS expr",
138943 /* 182 */ "expr ::= PLUS expr",
138944 /* 183 */ "between_op ::= BETWEEN",
138945 /* 184 */ "between_op ::= NOT BETWEEN",
138946 /* 185 */ "expr ::= expr between_op expr AND expr",
138947 /* 186 */ "in_op ::= IN",
138948 /* 187 */ "in_op ::= NOT IN",
138949 /* 188 */ "expr ::= expr in_op LP exprlist RP",
138950 /* 189 */ "expr ::= LP select RP",
138951 /* 190 */ "expr ::= expr in_op LP select RP",
138952 /* 191 */ "expr ::= expr in_op nm dbnm paren_exprlist",
138953 /* 192 */ "expr ::= EXISTS LP select RP",
138954 /* 193 */ "expr ::= CASE case_operand case_exprlist case_else END",
138955 /* 194 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
138956 /* 195 */ "case_exprlist ::= WHEN expr THEN expr",
138957 /* 196 */ "case_else ::= ELSE expr",
138958 /* 197 */ "case_else ::=",
138959 /* 198 */ "case_operand ::= expr",
138960 /* 199 */ "case_operand ::=",
138961 /* 200 */ "exprlist ::=",
138962 /* 201 */ "nexprlist ::= nexprlist COMMA expr",
138963 /* 202 */ "nexprlist ::= expr",
138964 /* 203 */ "paren_exprlist ::=",
138965 /* 204 */ "paren_exprlist ::= LP exprlist RP",
138966 /* 205 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
138967 /* 206 */ "uniqueflag ::= UNIQUE",
138968 /* 207 */ "uniqueflag ::=",
138969 /* 208 */ "eidlist_opt ::=",
138970 /* 209 */ "eidlist_opt ::= LP eidlist RP",
138971 /* 210 */ "eidlist ::= eidlist COMMA nm collate sortorder",
138972 /* 211 */ "eidlist ::= nm collate sortorder",
138973 /* 212 */ "collate ::=",
138974 /* 213 */ "collate ::= COLLATE ID|STRING",
138975 /* 214 */ "cmd ::= DROP INDEX ifexists fullname",
138976 /* 215 */ "cmd ::= VACUUM",
138977 /* 216 */ "cmd ::= VACUUM nm",
138978 /* 217 */ "cmd ::= PRAGMA nm dbnm",
138979 /* 218 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
138980 /* 219 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
138981 /* 220 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
138982 /* 221 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
138983 /* 222 */ "plus_num ::= PLUS INTEGER|FLOAT",
138984 /* 223 */ "minus_num ::= MINUS INTEGER|FLOAT",
138985 /* 224 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
138986 /* 225 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
138987 /* 226 */ "trigger_time ::= BEFORE|AFTER",
138988 /* 227 */ "trigger_time ::= INSTEAD OF",
138989 /* 228 */ "trigger_time ::=",
138990 /* 229 */ "trigger_event ::= DELETE|INSERT",
138991 /* 230 */ "trigger_event ::= UPDATE",
138992 /* 231 */ "trigger_event ::= UPDATE OF idlist",
138993 /* 232 */ "when_clause ::=",
138994 /* 233 */ "when_clause ::= WHEN expr",
138995 /* 234 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
138996 /* 235 */ "trigger_cmd_list ::= trigger_cmd SEMI",
138997 /* 236 */ "trnm ::= nm DOT nm",
138998 /* 237 */ "tridxby ::= INDEXED BY nm",
138999 /* 238 */ "tridxby ::= NOT INDEXED",
139000 /* 239 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
139001 /* 240 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
139002 /* 241 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
139003 /* 242 */ "trigger_cmd ::= select",
139004 /* 243 */ "expr ::= RAISE LP IGNORE RP",
139005 /* 244 */ "expr ::= RAISE LP raisetype COMMA nm RP",
139006 /* 245 */ "raisetype ::= ROLLBACK",
139007 /* 246 */ "raisetype ::= ABORT",
139008 /* 247 */ "raisetype ::= FAIL",
139009 /* 248 */ "cmd ::= DROP TRIGGER ifexists fullname",
139010 /* 249 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
139011 /* 250 */ "cmd ::= DETACH database_kw_opt expr",
139012 /* 251 */ "key_opt ::=",
139013 /* 252 */ "key_opt ::= KEY expr",
139014 /* 253 */ "cmd ::= REINDEX",
139015 /* 254 */ "cmd ::= REINDEX nm dbnm",
139016 /* 255 */ "cmd ::= ANALYZE",
139017 /* 256 */ "cmd ::= ANALYZE nm dbnm",
139018 /* 257 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
139019 /* 258 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
139020 /* 259 */ "add_column_fullname ::= fullname",
139021 /* 260 */ "cmd ::= create_vtab",
139022 /* 261 */ "cmd ::= create_vtab LP vtabarglist RP",
139023 /* 262 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
139024 /* 263 */ "vtabarg ::=",
139025 /* 264 */ "vtabargtoken ::= ANY",
139026 /* 265 */ "vtabargtoken ::= lp anylist RP",
139027 /* 266 */ "lp ::= LP",
139028 /* 267 */ "with ::=",
139029 /* 268 */ "with ::= WITH wqlist",
139030 /* 269 */ "with ::= WITH RECURSIVE wqlist",
139031 /* 270 */ "wqlist ::= nm eidlist_opt AS LP select RP",
139032 /* 271 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
139033 /* 272 */ "input ::= cmdlist",
139034 /* 273 */ "cmdlist ::= cmdlist ecmd",
139035 /* 274 */ "cmdlist ::= ecmd",
139036 /* 275 */ "ecmd ::= SEMI",
139037 /* 276 */ "ecmd ::= explain cmdx SEMI",
139038 /* 277 */ "explain ::=",
139039 /* 278 */ "trans_opt ::=",
139040 /* 279 */ "trans_opt ::= TRANSACTION",
139041 /* 280 */ "trans_opt ::= TRANSACTION nm",
139042 /* 281 */ "savepoint_opt ::= SAVEPOINT",
139043 /* 282 */ "savepoint_opt ::=",
139044 /* 283 */ "cmd ::= create_table create_table_args",
139045 /* 284 */ "columnlist ::= columnlist COMMA columnname carglist",
139046 /* 285 */ "columnlist ::= columnname carglist",
139047 /* 286 */ "nm ::= ID|INDEXED",
139048 /* 287 */ "nm ::= STRING",
139049 /* 288 */ "nm ::= JOIN_KW",
139050 /* 289 */ "typetoken ::= typename",
139051 /* 290 */ "typename ::= ID|STRING",
139052 /* 291 */ "signed ::= plus_num",
139053 /* 292 */ "signed ::= minus_num",
139054 /* 293 */ "carglist ::= carglist ccons",
139055 /* 294 */ "carglist ::=",
139056 /* 295 */ "ccons ::= NULL onconf",
139057 /* 296 */ "conslist_opt ::= COMMA conslist",
139058 /* 297 */ "conslist ::= conslist tconscomma tcons",
139059 /* 298 */ "conslist ::= tcons",
139060 /* 299 */ "tconscomma ::=",
139061 /* 300 */ "defer_subclause_opt ::= defer_subclause",
139062 /* 301 */ "resolvetype ::= raisetype",
139063 /* 302 */ "selectnowith ::= oneselect",
139064 /* 303 */ "oneselect ::= values",
139065 /* 304 */ "sclp ::= selcollist COMMA",
139066 /* 305 */ "as ::= ID|STRING",
139067 /* 306 */ "expr ::= term",
139068 /* 307 */ "likeop ::= LIKE_KW|MATCH",
139069 /* 308 */ "exprlist ::= nexprlist",
139070 /* 309 */ "nmnum ::= plus_num",
139071 /* 310 */ "nmnum ::= nm",
139072 /* 311 */ "nmnum ::= ON",
139073 /* 312 */ "nmnum ::= DELETE",
139074 /* 313 */ "nmnum ::= DEFAULT",
139075 /* 314 */ "plus_num ::= INTEGER|FLOAT",
139076 /* 315 */ "foreach_clause ::=",
139077 /* 316 */ "foreach_clause ::= FOR EACH ROW",
139078 /* 317 */ "trnm ::= nm",
139079 /* 318 */ "tridxby ::=",
139080 /* 319 */ "database_kw_opt ::= DATABASE",
139081 /* 320 */ "database_kw_opt ::=",
139082 /* 321 */ "kwcolumn_opt ::=",
139083 /* 322 */ "kwcolumn_opt ::= COLUMNKW",
139084 /* 323 */ "vtabarglist ::= vtabarg",
139085 /* 324 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
139086 /* 325 */ "vtabarg ::= vtabarg vtabargtoken",
139087 /* 326 */ "anylist ::=",
139088 /* 327 */ "anylist ::= anylist LP anylist RP",
139089 /* 328 */ "anylist ::= anylist ANY",
 
139090 };
139091 #endif /* NDEBUG */
139092
139093
139094 #if YYSTACKDEPTH<=0
@@ -139206,80 +139585,76 @@
139206 ** which appear on the RHS of the rule, but which are *not* used
139207 ** inside the C code.
139208 */
139209 /********* Begin destructor definitions ***************************************/
139210 case 163: /* select */
139211 case 194: /* selectnowith */
139212 case 195: /* oneselect */
139213 case 206: /* values */
139214 {
139215 sqlite3SelectDelete(pParse->db, (yypminor->yy243));
139216 }
139217 break;
139218 case 172: /* term */
139219 case 173: /* expr */
139220 {
139221 sqlite3ExprDelete(pParse->db, (yypminor->yy190).pExpr);
139222 }
139223 break;
139224 case 177: /* eidlist_opt */
139225 case 186: /* sortlist */
139226 case 187: /* eidlist */
139227 case 199: /* selcollist */
139228 case 202: /* groupby_opt */
139229 case 204: /* orderby_opt */
139230 case 207: /* nexprlist */
139231 case 208: /* exprlist */
139232 case 209: /* sclp */
139233 case 218: /* setlist */
139234 case 224: /* paren_exprlist */
139235 case 226: /* case_exprlist */
139236 {
139237 sqlite3ExprListDelete(pParse->db, (yypminor->yy148));
139238 }
139239 break;
139240 case 193: /* fullname */
139241 case 200: /* from */
139242 case 211: /* seltablist */
139243 case 212: /* stl_prefix */
139244 {
139245 sqlite3SrcListDelete(pParse->db, (yypminor->yy185));
139246 }
139247 break;
139248 case 196: /* with */
139249 case 250: /* wqlist */
139250 {
139251 sqlite3WithDelete(pParse->db, (yypminor->yy285));
139252 }
139253 break;
139254 case 201: /* where_opt */
139255 case 203: /* having_opt */
139256 case 215: /* on_opt */
139257 case 225: /* case_operand */
139258 case 227: /* case_else */
139259 case 236: /* when_clause */
139260 case 241: /* key_opt */
139261 {
139262 sqlite3ExprDelete(pParse->db, (yypminor->yy72));
139263 }
139264 break;
139265 case 216: /* using_opt */
139266 case 217: /* idlist */
139267 case 220: /* idlist_opt */
139268 {
139269 sqlite3IdListDelete(pParse->db, (yypminor->yy254));
139270 }
139271 break;
139272 case 232: /* trigger_cmd_list */
139273 case 237: /* trigger_cmd */
139274 {
139275 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy145));
139276 }
139277 break;
139278 case 234: /* trigger_event */
139279 {
139280 sqlite3IdListDelete(pParse->db, (yypminor->yy332).b);
139281 }
139282 break;
139283 /********* End destructor definitions *****************************************/
139284 default: break; /* If no destructor action specified: do nothing */
139285 }
@@ -139346,10 +139721,47 @@
139346 yyParser *pParser = (yyParser*)p;
139347 return pParser->yyhwm;
139348 }
139349 #endif
139350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139351 /*
139352 ** Find the appropriate action for a parser given the terminal
139353 ** look-ahead token iLookAhead.
139354 */
139355 static unsigned int yy_find_shift_action(
@@ -139357,17 +139769,22 @@
139357 YYCODETYPE iLookAhead /* The look-ahead token */
139358 ){
139359 int i;
139360 int stateno = pParser->yytos->stateno;
139361
139362 if( stateno>=YY_MIN_REDUCE ) return stateno;
139363 assert( stateno <= YY_SHIFT_COUNT );
 
 
 
139364 do{
139365 i = yy_shift_ofst[stateno];
 
139366 assert( iLookAhead!=YYNOCODE );
 
139367 i += iLookAhead;
139368 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
139369 #ifdef YYFALLBACK
139370 YYCODETYPE iFallback; /* Fallback token */
139371 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
139372 && (iFallback = yyFallback[iLookAhead])!=0 ){
139373 #ifndef NDEBUG
@@ -139426,11 +139843,10 @@
139426 }
139427 #else
139428 assert( stateno<=YY_REDUCE_COUNT );
139429 #endif
139430 i = yy_reduce_ofst[stateno];
139431 assert( i!=YY_REDUCE_USE_DFLT );
139432 assert( iLookAhead!=YYNOCODE );
139433 i += iLookAhead;
139434 #ifdef YYERRORSYMBOL
139435 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
139436 return yy_default[stateno];
@@ -139464,24 +139880,25 @@
139464
139465 /*
139466 ** Print tracing information for a SHIFT action
139467 */
139468 #ifndef NDEBUG
139469 static void yyTraceShift(yyParser *yypParser, int yyNewState){
139470 if( yyTraceFILE ){
139471 if( yyNewState<YYNSTATE ){
139472 fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n",
139473 yyTracePrompt,yyTokenName[yypParser->yytos->major],
139474 yyNewState);
139475 }else{
139476 fprintf(yyTraceFILE,"%sShift '%s'\n",
139477 yyTracePrompt,yyTokenName[yypParser->yytos->major]);
 
139478 }
139479 }
139480 }
139481 #else
139482 # define yyTraceShift(X,Y)
139483 #endif
139484
139485 /*
139486 ** Perform a shift action.
139487 */
@@ -139519,360 +139936,369 @@
139519 }
139520 yytos = yypParser->yytos;
139521 yytos->stateno = (YYACTIONTYPE)yyNewState;
139522 yytos->major = (YYCODETYPE)yyMajor;
139523 yytos->minor.yy0 = yyMinor;
139524 yyTraceShift(yypParser, yyNewState);
139525 }
139526
139527 /* The following table contains information about every rule that
139528 ** is used during the reduce.
139529 */
139530 static const struct {
139531 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
139532 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
139533 } yyRuleInfo[] = {
139534 { 147, -1 },
139535 { 147, -3 },
139536 { 148, -1 },
139537 { 149, -3 },
139538 { 150, 0 },
139539 { 150, -1 },
139540 { 150, -1 },
139541 { 150, -1 },
139542 { 149, -2 },
139543 { 149, -2 },
139544 { 149, -2 },
139545 { 149, -3 },
139546 { 149, -5 },
139547 { 154, -6 },
139548 { 156, -1 },
139549 { 158, 0 },
139550 { 158, -3 },
139551 { 157, -1 },
139552 { 157, 0 },
139553 { 155, -5 },
139554 { 155, -2 },
139555 { 162, 0 },
139556 { 162, -2 },
139557 { 164, -2 },
139558 { 166, 0 },
139559 { 166, -4 },
139560 { 166, -6 },
139561 { 167, -2 },
139562 { 171, -2 },
139563 { 171, -2 },
139564 { 171, -4 },
139565 { 171, -3 },
139566 { 171, -3 },
139567 { 171, -2 },
139568 { 171, -3 },
139569 { 171, -5 },
139570 { 171, -2 },
139571 { 171, -4 },
139572 { 171, -4 },
139573 { 171, -1 },
139574 { 171, -2 },
139575 { 176, 0 },
139576 { 176, -1 },
139577 { 178, 0 },
139578 { 178, -2 },
139579 { 180, -2 },
139580 { 180, -3 },
139581 { 180, -3 },
139582 { 180, -3 },
139583 { 181, -2 },
139584 { 181, -2 },
139585 { 181, -1 },
139586 { 181, -1 },
139587 { 181, -2 },
139588 { 179, -3 },
139589 { 179, -2 },
139590 { 182, 0 },
139591 { 182, -2 },
139592 { 182, -2 },
139593 { 161, 0 },
139594 { 184, -1 },
139595 { 185, -2 },
139596 { 185, -7 },
139597 { 185, -5 },
139598 { 185, -5 },
139599 { 185, -10 },
139600 { 188, 0 },
139601 { 174, 0 },
139602 { 174, -3 },
139603 { 189, 0 },
139604 { 189, -2 },
139605 { 190, -1 },
139606 { 190, -1 },
139607 { 149, -4 },
139608 { 192, -2 },
139609 { 192, 0 },
139610 { 149, -9 },
139611 { 149, -4 },
139612 { 149, -1 },
139613 { 163, -2 },
139614 { 194, -3 },
139615 { 197, -1 },
139616 { 197, -2 },
139617 { 197, -1 },
139618 { 195, -9 },
139619 { 206, -4 },
139620 { 206, -5 },
139621 { 198, -1 },
139622 { 198, -1 },
139623 { 198, 0 },
139624 { 209, 0 },
139625 { 199, -3 },
139626 { 199, -2 },
139627 { 199, -4 },
139628 { 210, -2 },
139629 { 210, 0 },
139630 { 200, 0 },
139631 { 200, -2 },
139632 { 212, -2 },
139633 { 212, 0 },
139634 { 211, -7 },
139635 { 211, -9 },
139636 { 211, -7 },
139637 { 211, -7 },
139638 { 159, 0 },
139639 { 159, -2 },
139640 { 193, -2 },
139641 { 213, -1 },
139642 { 213, -2 },
139643 { 213, -3 },
139644 { 213, -4 },
139645 { 215, -2 },
139646 { 215, 0 },
139647 { 214, 0 },
139648 { 214, -3 },
139649 { 214, -2 },
139650 { 216, -4 },
139651 { 216, 0 },
139652 { 204, 0 },
139653 { 204, -3 },
139654 { 186, -4 },
139655 { 186, -2 },
139656 { 175, -1 },
139657 { 175, -1 },
139658 { 175, 0 },
139659 { 202, 0 },
139660 { 202, -3 },
139661 { 203, 0 },
139662 { 203, -2 },
139663 { 205, 0 },
139664 { 205, -2 },
139665 { 205, -4 },
139666 { 205, -4 },
139667 { 149, -6 },
139668 { 201, 0 },
139669 { 201, -2 },
139670 { 149, -8 },
139671 { 218, -5 },
139672 { 218, -7 },
139673 { 218, -3 },
139674 { 218, -5 },
139675 { 149, -6 },
139676 { 149, -7 },
139677 { 219, -2 },
139678 { 219, -1 },
139679 { 220, 0 },
139680 { 220, -3 },
139681 { 217, -3 },
139682 { 217, -1 },
139683 { 173, -3 },
139684 { 173, -1 },
139685 { 173, -1 },
139686 { 173, -3 },
139687 { 173, -5 },
139688 { 172, -1 },
139689 { 172, -1 },
139690 { 172, -1 },
139691 { 173, -1 },
139692 { 173, -3 },
139693 { 173, -6 },
139694 { 173, -5 },
139695 { 173, -4 },
139696 { 172, -1 },
139697 { 173, -5 },
139698 { 173, -3 },
139699 { 173, -3 },
139700 { 173, -3 },
139701 { 173, -3 },
139702 { 173, -3 },
139703 { 173, -3 },
139704 { 173, -3 },
139705 { 173, -3 },
139706 { 221, -2 },
139707 { 173, -3 },
139708 { 173, -5 },
139709 { 173, -2 },
139710 { 173, -3 },
139711 { 173, -3 },
139712 { 173, -4 },
139713 { 173, -2 },
139714 { 173, -2 },
139715 { 173, -2 },
139716 { 173, -2 },
139717 { 222, -1 },
139718 { 222, -2 },
139719 { 173, -5 },
139720 { 223, -1 },
139721 { 223, -2 },
139722 { 173, -5 },
139723 { 173, -3 },
139724 { 173, -5 },
139725 { 173, -5 },
139726 { 173, -4 },
139727 { 173, -5 },
139728 { 226, -5 },
139729 { 226, -4 },
139730 { 227, -2 },
139731 { 227, 0 },
139732 { 225, -1 },
139733 { 225, 0 },
139734 { 208, 0 },
139735 { 207, -3 },
139736 { 207, -1 },
139737 { 224, 0 },
139738 { 224, -3 },
139739 { 149, -12 },
139740 { 228, -1 },
139741 { 228, 0 },
139742 { 177, 0 },
139743 { 177, -3 },
139744 { 187, -5 },
139745 { 187, -3 },
139746 { 229, 0 },
139747 { 229, -2 },
139748 { 149, -4 },
139749 { 149, -1 },
139750 { 149, -2 },
139751 { 149, -3 },
139752 { 149, -5 },
139753 { 149, -6 },
139754 { 149, -5 },
139755 { 149, -6 },
139756 { 169, -2 },
139757 { 170, -2 },
139758 { 149, -5 },
139759 { 231, -11 },
139760 { 233, -1 },
139761 { 233, -2 },
139762 { 233, 0 },
139763 { 234, -1 },
139764 { 234, -1 },
139765 { 234, -3 },
139766 { 236, 0 },
139767 { 236, -2 },
139768 { 232, -3 },
139769 { 232, -2 },
139770 { 238, -3 },
139771 { 239, -3 },
139772 { 239, -2 },
139773 { 237, -7 },
139774 { 237, -5 },
139775 { 237, -5 },
139776 { 237, -1 },
139777 { 173, -4 },
139778 { 173, -6 },
139779 { 191, -1 },
139780 { 191, -1 },
139781 { 191, -1 },
139782 { 149, -4 },
139783 { 149, -6 },
139784 { 149, -3 },
139785 { 241, 0 },
139786 { 241, -2 },
139787 { 149, -1 },
139788 { 149, -3 },
139789 { 149, -1 },
139790 { 149, -3 },
139791 { 149, -6 },
139792 { 149, -7 },
139793 { 242, -1 },
139794 { 149, -1 },
139795 { 149, -4 },
139796 { 244, -8 },
139797 { 246, 0 },
139798 { 247, -1 },
139799 { 247, -3 },
139800 { 248, -1 },
139801 { 196, 0 },
139802 { 196, -2 },
139803 { 196, -3 },
139804 { 250, -6 },
139805 { 250, -8 },
139806 { 144, -1 },
139807 { 145, -2 },
139808 { 145, -1 },
139809 { 146, -1 },
139810 { 146, -3 },
139811 { 147, 0 },
139812 { 151, 0 },
139813 { 151, -1 },
139814 { 151, -2 },
139815 { 153, -1 },
139816 { 153, 0 },
139817 { 149, -2 },
139818 { 160, -4 },
139819 { 160, -2 },
139820 { 152, -1 },
139821 { 152, -1 },
139822 { 152, -1 },
139823 { 166, -1 },
139824 { 167, -1 },
139825 { 168, -1 },
139826 { 168, -1 },
139827 { 165, -2 },
139828 { 165, 0 },
139829 { 171, -2 },
139830 { 161, -2 },
139831 { 183, -3 },
139832 { 183, -1 },
139833 { 184, 0 },
139834 { 188, -1 },
139835 { 190, -1 },
139836 { 194, -1 },
139837 { 195, -1 },
139838 { 209, -2 },
139839 { 210, -1 },
139840 { 173, -1 },
139841 { 221, -1 },
139842 { 208, -1 },
139843 { 230, -1 },
139844 { 230, -1 },
139845 { 230, -1 },
139846 { 230, -1 },
139847 { 230, -1 },
139848 { 169, -1 },
139849 { 235, 0 },
139850 { 235, -3 },
139851 { 238, -1 },
139852 { 239, 0 },
139853 { 240, -1 },
139854 { 240, 0 },
139855 { 243, 0 },
139856 { 243, -1 },
139857 { 245, -1 },
139858 { 245, -3 },
139859 { 246, -2 },
139860 { 249, 0 },
139861 { 249, -4 },
139862 { 249, -2 },
 
139863 };
139864
139865 static void yy_accept(yyParser*); /* Forward Declaration */
139866
139867 /*
139868 ** Perform a reduce action and the shift that must immediately
139869 ** follow the reduce.
 
 
 
 
 
 
139870 */
139871 static void yy_reduce(
139872 yyParser *yypParser, /* The parser */
139873 unsigned int yyruleno /* Number of the rule by which to reduce */
 
 
139874 ){
139875 int yygoto; /* The next state */
139876 int yyact; /* The next action */
139877 yyStackEntry *yymsp; /* The top of the parser's stack */
139878 int yysize; /* Amount to pop the stack */
@@ -139879,12 +140305,18 @@
139879 sqlite3ParserARG_FETCH;
139880 yymsp = yypParser->yytos;
139881 #ifndef NDEBUG
139882 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
139883 yysize = yyRuleInfo[yyruleno].nrhs;
139884 fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
139885 yyRuleName[yyruleno], yymsp[yysize].stateno);
 
 
 
 
 
 
139886 }
139887 #endif /* NDEBUG */
139888
139889 /* Check that the stack is large enough to grow by a single entry
139890 ** if the RHS of the rule is empty. This ensures that there is room
@@ -139931,19 +140363,19 @@
139931 break;
139932 case 2: /* cmdx ::= cmd */
139933 { sqlite3FinishCoding(pParse); }
139934 break;
139935 case 3: /* cmd ::= BEGIN transtype trans_opt */
139936 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy194);}
139937 break;
139938 case 4: /* transtype ::= */
139939 {yymsp[1].minor.yy194 = TK_DEFERRED;}
139940 break;
139941 case 5: /* transtype ::= DEFERRED */
139942 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
139943 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
139944 {yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-X*/}
139945 break;
139946 case 8: /* cmd ::= COMMIT|END trans_opt */
139947 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
139948 {sqlite3EndTransaction(pParse,yymsp[-1].major);}
139949 break;
@@ -139962,61 +140394,61 @@
139962 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
139963 }
139964 break;
139965 case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
139966 {
139967 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy194,0,0,yymsp[-2].minor.yy194);
139968 }
139969 break;
139970 case 14: /* createkw ::= CREATE */
139971 {disableLookaside(pParse);}
139972 break;
139973 case 15: /* ifnotexists ::= */
139974 case 18: /* temp ::= */ yytestcase(yyruleno==18);
139975 case 21: /* table_options ::= */ yytestcase(yyruleno==21);
139976 case 41: /* autoinc ::= */ yytestcase(yyruleno==41);
139977 case 56: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==56);
139978 case 66: /* defer_subclause_opt ::= */ yytestcase(yyruleno==66);
139979 case 75: /* ifexists ::= */ yytestcase(yyruleno==75);
139980 case 89: /* distinct ::= */ yytestcase(yyruleno==89);
139981 case 212: /* collate ::= */ yytestcase(yyruleno==212);
139982 {yymsp[1].minor.yy194 = 0;}
139983 break;
139984 case 16: /* ifnotexists ::= IF NOT EXISTS */
139985 {yymsp[-2].minor.yy194 = 1;}
139986 break;
139987 case 17: /* temp ::= TEMP */
139988 case 42: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==42);
139989 {yymsp[0].minor.yy194 = 1;}
139990 break;
139991 case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
139992 {
139993 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy194,0);
139994 }
139995 break;
139996 case 20: /* create_table_args ::= AS select */
139997 {
139998 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy243);
139999 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy243);
140000 }
140001 break;
140002 case 22: /* table_options ::= WITHOUT nm */
140003 {
140004 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
140005 yymsp[-1].minor.yy194 = TF_WithoutRowid | TF_NoVisibleRowid;
140006 }else{
140007 yymsp[-1].minor.yy194 = 0;
140008 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
140009 }
140010 }
140011 break;
140012 case 23: /* columnname ::= nm typetoken */
140013 {sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
140014 break;
140015 case 24: /* typetoken ::= */
140016 case 59: /* conslist_opt ::= */ yytestcase(yyruleno==59);
140017 case 95: /* as ::= */ yytestcase(yyruleno==95);
140018 {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
140019 break;
140020 case 25: /* typetoken ::= typename LP signed RP */
140021 {
140022 yymsp[-3].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
@@ -140028,214 +140460,218 @@
140028 }
140029 break;
140030 case 27: /* typename ::= typename ID|STRING */
140031 {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
140032 break;
140033 case 28: /* ccons ::= CONSTRAINT nm */
140034 case 61: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==61);
 
 
 
 
 
 
140035 {pParse->constraintName = yymsp[0].minor.yy0;}
140036 break;
140037 case 29: /* ccons ::= DEFAULT term */
140038 case 31: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==31);
140039 {sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy190);}
140040 break;
140041 case 30: /* ccons ::= DEFAULT LP expr RP */
140042 {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy190);}
140043 break;
140044 case 32: /* ccons ::= DEFAULT MINUS term */
140045 {
140046 ExprSpan v;
140047 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0);
140048 v.zStart = yymsp[-1].minor.yy0.z;
140049 v.zEnd = yymsp[0].minor.yy190.zEnd;
140050 sqlite3AddDefaultValue(pParse,&v);
140051 }
140052 break;
140053 case 33: /* ccons ::= DEFAULT ID|INDEXED */
140054 {
140055 ExprSpan v;
140056 spanExpr(&v, pParse, TK_STRING, yymsp[0].minor.yy0);
140057 sqlite3AddDefaultValue(pParse,&v);
140058 }
140059 break;
140060 case 34: /* ccons ::= NOT NULL onconf */
140061 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy194);}
140062 break;
140063 case 35: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
140064 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy194,yymsp[0].minor.yy194,yymsp[-2].minor.yy194);}
140065 break;
140066 case 36: /* ccons ::= UNIQUE onconf */
140067 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy194,0,0,0,0,
140068 SQLITE_IDXTYPE_UNIQUE);}
140069 break;
140070 case 37: /* ccons ::= CHECK LP expr RP */
140071 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy190.pExpr);}
140072 break;
140073 case 38: /* ccons ::= REFERENCES nm eidlist_opt refargs */
140074 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy148,yymsp[0].minor.yy194);}
140075 break;
140076 case 39: /* ccons ::= defer_subclause */
140077 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy194);}
140078 break;
140079 case 40: /* ccons ::= COLLATE ID|STRING */
140080 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
140081 break;
140082 case 43: /* refargs ::= */
140083 { yymsp[1].minor.yy194 = OE_None*0x0101; /* EV: R-19803-45884 */}
140084 break;
140085 case 44: /* refargs ::= refargs refarg */
140086 { yymsp[-1].minor.yy194 = (yymsp[-1].minor.yy194 & ~yymsp[0].minor.yy497.mask) | yymsp[0].minor.yy497.value; }
140087 break;
140088 case 45: /* refarg ::= MATCH nm */
140089 { yymsp[-1].minor.yy497.value = 0; yymsp[-1].minor.yy497.mask = 0x000000; }
140090 break;
140091 case 46: /* refarg ::= ON INSERT refact */
140092 { yymsp[-2].minor.yy497.value = 0; yymsp[-2].minor.yy497.mask = 0x000000; }
140093 break;
140094 case 47: /* refarg ::= ON DELETE refact */
140095 { yymsp[-2].minor.yy497.value = yymsp[0].minor.yy194; yymsp[-2].minor.yy497.mask = 0x0000ff; }
140096 break;
140097 case 48: /* refarg ::= ON UPDATE refact */
140098 { yymsp[-2].minor.yy497.value = yymsp[0].minor.yy194<<8; yymsp[-2].minor.yy497.mask = 0x00ff00; }
140099 break;
140100 case 49: /* refact ::= SET NULL */
140101 { yymsp[-1].minor.yy194 = OE_SetNull; /* EV: R-33326-45252 */}
140102 break;
140103 case 50: /* refact ::= SET DEFAULT */
140104 { yymsp[-1].minor.yy194 = OE_SetDflt; /* EV: R-33326-45252 */}
140105 break;
140106 case 51: /* refact ::= CASCADE */
140107 { yymsp[0].minor.yy194 = OE_Cascade; /* EV: R-33326-45252 */}
140108 break;
140109 case 52: /* refact ::= RESTRICT */
140110 { yymsp[0].minor.yy194 = OE_Restrict; /* EV: R-33326-45252 */}
140111 break;
140112 case 53: /* refact ::= NO ACTION */
140113 { yymsp[-1].minor.yy194 = OE_None; /* EV: R-33326-45252 */}
140114 break;
140115 case 54: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
140116 {yymsp[-2].minor.yy194 = 0;}
140117 break;
140118 case 55: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
140119 case 70: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==70);
140120 case 143: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==143);
140121 {yymsp[-1].minor.yy194 = yymsp[0].minor.yy194;}
140122 break;
140123 case 57: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
140124 case 74: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==74);
140125 case 184: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==184);
140126 case 187: /* in_op ::= NOT IN */ yytestcase(yyruleno==187);
140127 case 213: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==213);
140128 {yymsp[-1].minor.yy194 = 1;}
140129 break;
140130 case 58: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
140131 {yymsp[-1].minor.yy194 = 0;}
140132 break;
140133 case 60: /* tconscomma ::= COMMA */
140134 {pParse->constraintName.n = 0;}
140135 break;
140136 case 62: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
140137 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy148,yymsp[0].minor.yy194,yymsp[-2].minor.yy194,0);}
140138 break;
140139 case 63: /* tcons ::= UNIQUE LP sortlist RP onconf */
140140 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy148,yymsp[0].minor.yy194,0,0,0,0,
140141 SQLITE_IDXTYPE_UNIQUE);}
140142 break;
140143 case 64: /* tcons ::= CHECK LP expr RP onconf */
140144 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy190.pExpr);}
140145 break;
140146 case 65: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
140147 {
140148 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy148, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy148, yymsp[-1].minor.yy194);
140149 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy194);
140150 }
140151 break;
140152 case 67: /* onconf ::= */
140153 case 69: /* orconf ::= */ yytestcase(yyruleno==69);
140154 {yymsp[1].minor.yy194 = OE_Default;}
140155 break;
140156 case 68: /* onconf ::= ON CONFLICT resolvetype */
140157 {yymsp[-2].minor.yy194 = yymsp[0].minor.yy194;}
140158 break;
140159 case 71: /* resolvetype ::= IGNORE */
140160 {yymsp[0].minor.yy194 = OE_Ignore;}
140161 break;
140162 case 72: /* resolvetype ::= REPLACE */
140163 case 144: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==144);
140164 {yymsp[0].minor.yy194 = OE_Replace;}
140165 break;
140166 case 73: /* cmd ::= DROP TABLE ifexists fullname */
140167 {
140168 sqlite3DropTable(pParse, yymsp[0].minor.yy185, 0, yymsp[-1].minor.yy194);
140169 }
140170 break;
140171 case 76: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
140172 {
140173 sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy148, yymsp[0].minor.yy243, yymsp[-7].minor.yy194, yymsp[-5].minor.yy194);
140174 }
140175 break;
140176 case 77: /* cmd ::= DROP VIEW ifexists fullname */
140177 {
140178 sqlite3DropTable(pParse, yymsp[0].minor.yy185, 1, yymsp[-1].minor.yy194);
140179 }
140180 break;
140181 case 78: /* cmd ::= select */
140182 {
140183 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
140184 sqlite3Select(pParse, yymsp[0].minor.yy243, &dest);
140185 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy243);
140186 }
140187 break;
140188 case 79: /* select ::= with selectnowith */
140189 {
140190 Select *p = yymsp[0].minor.yy243;
140191 if( p ){
140192 p->pWith = yymsp[-1].minor.yy285;
140193 parserDoubleLinkSelect(pParse, p);
140194 }else{
140195 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy285);
140196 }
140197 yymsp[-1].minor.yy243 = p; /*A-overwrites-W*/
140198 }
140199 break;
140200 case 80: /* selectnowith ::= selectnowith multiselect_op oneselect */
140201 {
140202 Select *pRhs = yymsp[0].minor.yy243;
140203 Select *pLhs = yymsp[-2].minor.yy243;
140204 if( pRhs && pRhs->pPrior ){
140205 SrcList *pFrom;
140206 Token x;
140207 x.n = 0;
140208 parserDoubleLinkSelect(pParse, pRhs);
140209 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
140210 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
140211 }
140212 if( pRhs ){
140213 pRhs->op = (u8)yymsp[-1].minor.yy194;
140214 pRhs->pPrior = pLhs;
140215 if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
140216 pRhs->selFlags &= ~SF_MultiValue;
140217 if( yymsp[-1].minor.yy194!=TK_ALL ) pParse->hasCompound = 1;
140218 }else{
140219 sqlite3SelectDelete(pParse->db, pLhs);
140220 }
140221 yymsp[-2].minor.yy243 = pRhs;
140222 }
140223 break;
140224 case 81: /* multiselect_op ::= UNION */
140225 case 83: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==83);
140226 {yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-OP*/}
140227 break;
140228 case 82: /* multiselect_op ::= UNION ALL */
140229 {yymsp[-1].minor.yy194 = TK_ALL;}
140230 break;
140231 case 84: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
140232 {
140233 #if SELECTTRACE_ENABLED
140234 Token s = yymsp[-8].minor.yy0; /*A-overwrites-S*/
140235 #endif
140236 yymsp[-8].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy148,yymsp[-5].minor.yy185,yymsp[-4].minor.yy72,yymsp[-3].minor.yy148,yymsp[-2].minor.yy72,yymsp[-1].minor.yy148,yymsp[-7].minor.yy194,yymsp[0].minor.yy72);
140237 #if SELECTTRACE_ENABLED
140238 /* Populate the Select.zSelName[] string that is used to help with
140239 ** query planner debugging, to differentiate between multiple Select
140240 ** objects in a complex query.
140241 **
@@ -140242,496 +140678,483 @@
140242 ** If the SELECT keyword is immediately followed by a C-style comment
140243 ** then extract the first few alphanumeric characters from within that
140244 ** comment to be the zSelName value. Otherwise, the label is #N where
140245 ** is an integer that is incremented with each SELECT statement seen.
140246 */
140247 if( yymsp[-8].minor.yy243!=0 ){
140248 const char *z = s.z+6;
140249 int i;
140250 sqlite3_snprintf(sizeof(yymsp[-8].minor.yy243->zSelName), yymsp[-8].minor.yy243->zSelName, "#%d",
140251 ++pParse->nSelect);
140252 while( z[0]==' ' ) z++;
140253 if( z[0]=='/' && z[1]=='*' ){
140254 z += 2;
140255 while( z[0]==' ' ) z++;
140256 for(i=0; sqlite3Isalnum(z[i]); i++){}
140257 sqlite3_snprintf(sizeof(yymsp[-8].minor.yy243->zSelName), yymsp[-8].minor.yy243->zSelName, "%.*s", i, z);
140258 }
140259 }
140260 #endif /* SELECTRACE_ENABLED */
140261 }
140262 break;
140263 case 85: /* values ::= VALUES LP nexprlist RP */
140264 {
140265 yymsp[-3].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values,0);
140266 }
140267 break;
140268 case 86: /* values ::= values COMMA LP exprlist RP */
140269 {
140270 Select *pRight, *pLeft = yymsp[-4].minor.yy243;
140271 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values|SF_MultiValue,0);
140272 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
140273 if( pRight ){
140274 pRight->op = TK_ALL;
140275 pRight->pPrior = pLeft;
140276 yymsp[-4].minor.yy243 = pRight;
140277 }else{
140278 yymsp[-4].minor.yy243 = pLeft;
140279 }
140280 }
140281 break;
140282 case 87: /* distinct ::= DISTINCT */
140283 {yymsp[0].minor.yy194 = SF_Distinct;}
140284 break;
140285 case 88: /* distinct ::= ALL */
140286 {yymsp[0].minor.yy194 = SF_All;}
140287 break;
140288 case 90: /* sclp ::= */
140289 case 118: /* orderby_opt ::= */ yytestcase(yyruleno==118);
140290 case 125: /* groupby_opt ::= */ yytestcase(yyruleno==125);
140291 case 200: /* exprlist ::= */ yytestcase(yyruleno==200);
140292 case 203: /* paren_exprlist ::= */ yytestcase(yyruleno==203);
140293 case 208: /* eidlist_opt ::= */ yytestcase(yyruleno==208);
140294 {yymsp[1].minor.yy148 = 0;}
140295 break;
140296 case 91: /* selcollist ::= sclp expr as */
140297 {
140298 yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy148, yymsp[-1].minor.yy190.pExpr);
140299 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-2].minor.yy148, &yymsp[0].minor.yy0, 1);
140300 sqlite3ExprListSetSpan(pParse,yymsp[-2].minor.yy148,&yymsp[-1].minor.yy190);
140301 }
140302 break;
140303 case 92: /* selcollist ::= sclp STAR */
140304 {
140305 Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
140306 yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy148, p);
140307 }
140308 break;
140309 case 93: /* selcollist ::= sclp nm DOT STAR */
140310 {
140311 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
140312 Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140313 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
140314 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot);
140315 }
140316 break;
140317 case 94: /* as ::= AS nm */
140318 case 105: /* dbnm ::= DOT nm */ yytestcase(yyruleno==105);
140319 case 222: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==222);
140320 case 223: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==223);
140321 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
140322 break;
140323 case 96: /* from ::= */
140324 {yymsp[1].minor.yy185 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy185));}
140325 break;
140326 case 97: /* from ::= FROM seltablist */
140327 {
140328 yymsp[-1].minor.yy185 = yymsp[0].minor.yy185;
140329 sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy185);
140330 }
140331 break;
140332 case 98: /* stl_prefix ::= seltablist joinop */
140333 {
140334 if( ALWAYS(yymsp[-1].minor.yy185 && yymsp[-1].minor.yy185->nSrc>0) ) yymsp[-1].minor.yy185->a[yymsp[-1].minor.yy185->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy194;
140335 }
140336 break;
140337 case 99: /* stl_prefix ::= */
140338 {yymsp[1].minor.yy185 = 0;}
140339 break;
140340 case 100: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
140341 {
140342 yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140343 sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy185, &yymsp[-2].minor.yy0);
140344 }
140345 break;
140346 case 101: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
140347 {
140348 yymsp[-8].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy185,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140349 sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy185, yymsp[-4].minor.yy148);
140350 }
140351 break;
140352 case 102: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
140353 {
140354 yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy243,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140355 }
140356 break;
140357 case 103: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
140358 {
140359 if( yymsp[-6].minor.yy185==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy72==0 && yymsp[0].minor.yy254==0 ){
140360 yymsp[-6].minor.yy185 = yymsp[-4].minor.yy185;
140361 }else if( yymsp[-4].minor.yy185->nSrc==1 ){
140362 yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140363 if( yymsp[-6].minor.yy185 ){
140364 struct SrcList_item *pNew = &yymsp[-6].minor.yy185->a[yymsp[-6].minor.yy185->nSrc-1];
140365 struct SrcList_item *pOld = yymsp[-4].minor.yy185->a;
140366 pNew->zName = pOld->zName;
140367 pNew->zDatabase = pOld->zDatabase;
140368 pNew->pSelect = pOld->pSelect;
140369 pOld->zName = pOld->zDatabase = 0;
140370 pOld->pSelect = 0;
140371 }
140372 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy185);
140373 }else{
140374 Select *pSubquery;
140375 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy185);
140376 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy185,0,0,0,0,SF_NestedFrom,0);
140377 yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy72,yymsp[0].minor.yy254);
140378 }
140379 }
140380 break;
140381 case 104: /* dbnm ::= */
140382 case 113: /* indexed_opt ::= */ yytestcase(yyruleno==113);
140383 {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
140384 break;
140385 case 106: /* fullname ::= nm dbnm */
140386 {yymsp[-1].minor.yy185 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
140387 break;
140388 case 107: /* joinop ::= COMMA|JOIN */
140389 { yymsp[0].minor.yy194 = JT_INNER; }
140390 break;
140391 case 108: /* joinop ::= JOIN_KW JOIN */
140392 {yymsp[-1].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
140393 break;
140394 case 109: /* joinop ::= JOIN_KW nm JOIN */
140395 {yymsp[-2].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
140396 break;
140397 case 110: /* joinop ::= JOIN_KW nm nm JOIN */
140398 {yymsp[-3].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
140399 break;
140400 case 111: /* on_opt ::= ON expr */
140401 case 128: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==128);
140402 case 135: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==135);
140403 case 196: /* case_else ::= ELSE expr */ yytestcase(yyruleno==196);
140404 {yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;}
140405 break;
140406 case 112: /* on_opt ::= */
140407 case 127: /* having_opt ::= */ yytestcase(yyruleno==127);
140408 case 129: /* limit_opt ::= */ yytestcase(yyruleno==129);
140409 case 134: /* where_opt ::= */ yytestcase(yyruleno==134);
140410 case 197: /* case_else ::= */ yytestcase(yyruleno==197);
140411 case 199: /* case_operand ::= */ yytestcase(yyruleno==199);
140412 {yymsp[1].minor.yy72 = 0;}
140413 break;
140414 case 114: /* indexed_opt ::= INDEXED BY nm */
140415 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
140416 break;
140417 case 115: /* indexed_opt ::= NOT INDEXED */
140418 {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
140419 break;
140420 case 116: /* using_opt ::= USING LP idlist RP */
140421 {yymsp[-3].minor.yy254 = yymsp[-1].minor.yy254;}
140422 break;
140423 case 117: /* using_opt ::= */
140424 case 145: /* idlist_opt ::= */ yytestcase(yyruleno==145);
140425 {yymsp[1].minor.yy254 = 0;}
140426 break;
140427 case 119: /* orderby_opt ::= ORDER BY sortlist */
140428 case 126: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==126);
140429 {yymsp[-2].minor.yy148 = yymsp[0].minor.yy148;}
140430 break;
140431 case 120: /* sortlist ::= sortlist COMMA expr sortorder */
140432 {
140433 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148,yymsp[-1].minor.yy190.pExpr);
140434 sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy148,yymsp[0].minor.yy194);
140435 }
140436 break;
140437 case 121: /* sortlist ::= expr sortorder */
140438 {
140439 yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy190.pExpr); /*A-overwrites-Y*/
140440 sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy148,yymsp[0].minor.yy194);
140441 }
140442 break;
140443 case 122: /* sortorder ::= ASC */
140444 {yymsp[0].minor.yy194 = SQLITE_SO_ASC;}
140445 break;
140446 case 123: /* sortorder ::= DESC */
140447 {yymsp[0].minor.yy194 = SQLITE_SO_DESC;}
140448 break;
140449 case 124: /* sortorder ::= */
140450 {yymsp[1].minor.yy194 = SQLITE_SO_UNDEFINED;}
140451 break;
140452 case 130: /* limit_opt ::= LIMIT expr */
140453 {yymsp[-1].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy190.pExpr,0);}
140454 break;
140455 case 131: /* limit_opt ::= LIMIT expr OFFSET expr */
140456 {yymsp[-3].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy190.pExpr,yymsp[0].minor.yy190.pExpr);}
140457 break;
140458 case 132: /* limit_opt ::= LIMIT expr COMMA expr */
140459 {yymsp[-3].minor.yy72 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy190.pExpr,yymsp[-2].minor.yy190.pExpr);}
140460 break;
140461 case 133: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140462 {
140463 sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1);
140464 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy0);
140465 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72,0,0);
140466 }
140467 break;
140468 case 136: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140469 {
140470 sqlite3WithPush(pParse, yymsp[-7].minor.yy285, 1);
140471 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy0);
140472 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy148,"set list");
140473 sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194,0,0);
140474 }
140475 break;
140476 case 137: /* setlist ::= setlist COMMA nm EQ expr */
140477 {
140478 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
140479 sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, 1);
140480 }
140481 break;
140482 case 138: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
140483 {
140484 yymsp[-6].minor.yy148 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy148, yymsp[-3].minor.yy254, yymsp[0].minor.yy190.pExpr);
140485 }
140486 break;
140487 case 139: /* setlist ::= nm EQ expr */
140488 {
140489 yylhsminor.yy148 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy190.pExpr);
140490 sqlite3ExprListSetName(pParse, yylhsminor.yy148, &yymsp[-2].minor.yy0, 1);
140491 }
140492 yymsp[-2].minor.yy148 = yylhsminor.yy148;
140493 break;
140494 case 140: /* setlist ::= LP idlist RP EQ expr */
140495 {
140496 yymsp[-4].minor.yy148 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy254, yymsp[0].minor.yy190.pExpr);
140497 }
140498 break;
140499 case 141: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */
140500 {
140501 sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1);
140502 sqlite3Insert(pParse, yymsp[-2].minor.yy185, yymsp[0].minor.yy243, yymsp[-1].minor.yy254, yymsp[-4].minor.yy194);
140503 }
140504 break;
140505 case 142: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
140506 {
140507 sqlite3WithPush(pParse, yymsp[-6].minor.yy285, 1);
140508 sqlite3Insert(pParse, yymsp[-3].minor.yy185, 0, yymsp[-2].minor.yy254, yymsp[-5].minor.yy194);
140509 }
140510 break;
140511 case 146: /* idlist_opt ::= LP idlist RP */
140512 {yymsp[-2].minor.yy254 = yymsp[-1].minor.yy254;}
140513 break;
140514 case 147: /* idlist ::= idlist COMMA nm */
140515 {yymsp[-2].minor.yy254 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy254,&yymsp[0].minor.yy0);}
140516 break;
140517 case 148: /* idlist ::= nm */
140518 {yymsp[0].minor.yy254 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
140519 break;
140520 case 149: /* expr ::= LP expr RP */
140521 {spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ yymsp[-2].minor.yy190.pExpr = yymsp[-1].minor.yy190.pExpr;}
140522 break;
140523 case 150: /* expr ::= ID|INDEXED */
140524 case 151: /* expr ::= JOIN_KW */ yytestcase(yyruleno==151);
140525 {spanExpr(&yymsp[0].minor.yy190,pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
140526 break;
140527 case 152: /* expr ::= nm DOT nm */
140528 {
140529 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140530 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
140531 spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140532 yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
140533 }
 
140534 break;
140535 case 153: /* expr ::= nm DOT nm DOT nm */
140536 {
140537 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
140538 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140539 Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
140540 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
140541 spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140542 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
140543 }
140544 break;
140545 case 154: /* term ::= NULL|FLOAT|BLOB */
140546 case 155: /* term ::= STRING */ yytestcase(yyruleno==155);
140547 {spanExpr(&yymsp[0].minor.yy190,pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
140548 break;
140549 case 156: /* term ::= INTEGER */
140550 {
140551 yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
140552 yylhsminor.yy190.zStart = yymsp[0].minor.yy0.z;
140553 yylhsminor.yy190.zEnd = yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n;
140554 }
140555 yymsp[0].minor.yy190 = yylhsminor.yy190;
140556 break;
140557 case 157: /* expr ::= VARIABLE */
140558 {
140559 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
140560 u32 n = yymsp[0].minor.yy0.n;
140561 spanExpr(&yymsp[0].minor.yy190, pParse, TK_VARIABLE, yymsp[0].minor.yy0);
140562 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy190.pExpr, n);
140563 }else{
140564 /* When doing a nested parse, one can include terms in an expression
140565 ** that look like this: #1 #2 ... These terms refer to registers
140566 ** in the virtual machine. #N is the N-th register. */
140567 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
140568 assert( t.n>=2 );
140569 spanSet(&yymsp[0].minor.yy190, &t, &t);
140570 if( pParse->nested==0 ){
140571 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
140572 yymsp[0].minor.yy190.pExpr = 0;
140573 }else{
140574 yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
140575 if( yymsp[0].minor.yy190.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy190.pExpr->iTable);
140576 }
140577 }
140578 }
140579 break;
140580 case 158: /* expr ::= expr COLLATE ID|STRING */
140581 {
140582 yymsp[-2].minor.yy190.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy190.pExpr, &yymsp[0].minor.yy0, 1);
140583 yymsp[-2].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
140584 }
140585 break;
140586 case 159: /* expr ::= CAST LP expr AS typetoken RP */
140587 {
140588 spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140589 yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
140590 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, 0);
140591 }
140592 break;
140593 case 160: /* expr ::= ID|INDEXED LP distinct exprlist RP */
140594 {
140595 if( yymsp[-1].minor.yy148 && yymsp[-1].minor.yy148->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
140596 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
140597 }
140598 yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy148, &yymsp[-4].minor.yy0);
140599 spanSet(&yylhsminor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
140600 if( yymsp[-2].minor.yy194==SF_Distinct && yylhsminor.yy190.pExpr ){
140601 yylhsminor.yy190.pExpr->flags |= EP_Distinct;
140602 }
140603 }
140604 yymsp[-4].minor.yy190 = yylhsminor.yy190;
140605 break;
140606 case 161: /* expr ::= ID|INDEXED LP STAR RP */
140607 {
140608 yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
140609 spanSet(&yylhsminor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
140610 }
140611 yymsp[-3].minor.yy190 = yylhsminor.yy190;
140612 break;
140613 case 162: /* term ::= CTIME_KW */
140614 {
140615 yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
140616 spanSet(&yylhsminor.yy190, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
140617 }
140618 yymsp[0].minor.yy190 = yylhsminor.yy190;
140619 break;
140620 case 163: /* expr ::= LP nexprlist COMMA expr RP */
140621 {
140622 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy148, yymsp[-1].minor.yy190.pExpr);
140623 yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
140624 if( yylhsminor.yy190.pExpr ){
140625 yylhsminor.yy190.pExpr->x.pList = pList;
140626 spanSet(&yylhsminor.yy190, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
140627 }else{
140628 sqlite3ExprListDelete(pParse->db, pList);
140629 }
140630 }
140631 yymsp[-4].minor.yy190 = yylhsminor.yy190;
140632 break;
140633 case 164: /* expr ::= expr AND expr */
140634 case 165: /* expr ::= expr OR expr */ yytestcase(yyruleno==165);
140635 case 166: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==166);
140636 case 167: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==167);
140637 case 168: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==168);
140638 case 169: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==169);
140639 case 170: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==170);
140640 case 171: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==171);
140641 {spanBinaryExpr(pParse,yymsp[-1].major,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);}
140642 break;
140643 case 172: /* likeop ::= NOT LIKE_KW|MATCH */
140644 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
140645 break;
140646 case 173: /* expr ::= expr likeop expr */
140647 {
140648 ExprList *pList;
140649 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
140650 yymsp[-1].minor.yy0.n &= 0x7fffffff;
140651 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy190.pExpr);
140652 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy190.pExpr);
140653 yymsp[-2].minor.yy190.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0);
140654 exprNot(pParse, bNot, &yymsp[-2].minor.yy190);
140655 yymsp[-2].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
140656 if( yymsp[-2].minor.yy190.pExpr ) yymsp[-2].minor.yy190.pExpr->flags |= EP_InfixFunc;
140657 }
140658 break;
140659 case 174: /* expr ::= expr likeop expr ESCAPE expr */
140660 {
140661 ExprList *pList;
140662 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
140663 yymsp[-3].minor.yy0.n &= 0x7fffffff;
140664 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
140665 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy190.pExpr);
140666 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
140667 yymsp[-4].minor.yy190.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0);
140668 exprNot(pParse, bNot, &yymsp[-4].minor.yy190);
140669 yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
140670 if( yymsp[-4].minor.yy190.pExpr ) yymsp[-4].minor.yy190.pExpr->flags |= EP_InfixFunc;
140671 }
140672 break;
140673 case 175: /* expr ::= expr ISNULL|NOTNULL */
140674 {spanUnaryPostfix(pParse,yymsp[0].major,&yymsp[-1].minor.yy190,&yymsp[0].minor.yy0);}
140675 break;
140676 case 176: /* expr ::= expr NOT NULL */
140677 {spanUnaryPostfix(pParse,TK_NOTNULL,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy0);}
140678 break;
140679 case 177: /* expr ::= expr IS expr */
140680 {
140681 spanBinaryExpr(pParse,TK_IS,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);
140682 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-2].minor.yy190.pExpr, TK_ISNULL);
140683 }
140684 break;
140685 case 178: /* expr ::= expr IS NOT expr */
140686 {
140687 spanBinaryExpr(pParse,TK_ISNOT,&yymsp[-3].minor.yy190,&yymsp[0].minor.yy190);
140688 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, TK_NOTNULL);
140689 }
140690 break;
140691 case 179: /* expr ::= NOT expr */
140692 case 180: /* expr ::= BITNOT expr */ yytestcase(yyruleno==180);
140693 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,yymsp[-1].major,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
140694 break;
140695 case 181: /* expr ::= MINUS expr */
140696 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UMINUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
140697 break;
140698 case 182: /* expr ::= PLUS expr */
140699 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UPLUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
140700 break;
140701 case 183: /* between_op ::= BETWEEN */
140702 case 186: /* in_op ::= IN */ yytestcase(yyruleno==186);
140703 {yymsp[0].minor.yy194 = 0;}
140704 break;
140705 case 185: /* expr ::= expr between_op expr AND expr */
140706 {
140707 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
140708 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
140709 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0);
140710 if( yymsp[-4].minor.yy190.pExpr ){
140711 yymsp[-4].minor.yy190.pExpr->x.pList = pList;
140712 }else{
140713 sqlite3ExprListDelete(pParse->db, pList);
140714 }
140715 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140716 yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
140717 }
140718 break;
140719 case 188: /* expr ::= expr in_op LP exprlist RP */
140720 {
140721 if( yymsp[-1].minor.yy148==0 ){
140722 /* Expressions of the form
140723 **
140724 ** expr1 IN ()
140725 ** expr1 NOT IN ()
140726 **
140727 ** simplify to constants 0 (false) and 1 (true), respectively,
140728 ** regardless of the value of expr1.
140729 */
140730 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy190.pExpr);
140731 yymsp[-4].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy194],1);
140732 }else if( yymsp[-1].minor.yy148->nExpr==1 ){
140733 /* Expressions of the form:
140734 **
140735 ** expr1 IN (?1)
140736 ** expr1 NOT IN (?2)
140737 **
@@ -140744,402 +141167,398 @@
140744 ** But, the RHS of the == or <> is marked with the EP_Generic flag
140745 ** so that it may not contribute to the computation of comparison
140746 ** affinity or the collating sequence to use for comparison. Otherwise,
140747 ** the semantics would be subtly different from IN or NOT IN.
140748 */
140749 Expr *pRHS = yymsp[-1].minor.yy148->a[0].pExpr;
140750 yymsp[-1].minor.yy148->a[0].pExpr = 0;
140751 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148);
140752 /* pRHS cannot be NULL because a malloc error would have been detected
140753 ** before now and control would have never reached this point */
140754 if( ALWAYS(pRHS) ){
140755 pRHS->flags &= ~EP_Collate;
140756 pRHS->flags |= EP_Generic;
140757 }
140758 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS);
140759 }else{
140760 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140761 if( yymsp[-4].minor.yy190.pExpr ){
140762 yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy148;
140763 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
140764 }else{
140765 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148);
140766 }
140767 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140768 }
140769 yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
140770 }
140771 break;
140772 case 189: /* expr ::= LP select RP */
140773 {
140774 spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
140775 yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
140776 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243);
140777 }
140778 break;
140779 case 190: /* expr ::= expr in_op LP select RP */
140780 {
140781 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140782 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243);
140783 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140784 yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
140785 }
140786 break;
140787 case 191: /* expr ::= expr in_op nm dbnm paren_exprlist */
140788 {
140789 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
140790 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
140791 if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
140792 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
140793 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
140794 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
140795 yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n];
140796 }
140797 break;
140798 case 192: /* expr ::= EXISTS LP select RP */
140799 {
140800 Expr *p;
140801 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
140802 p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
140803 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243);
140804 }
140805 break;
140806 case 193: /* expr ::= CASE case_operand case_exprlist case_else END */
140807 {
140808 spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
140809 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0);
140810 if( yymsp[-4].minor.yy190.pExpr ){
140811 yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy72 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[-1].minor.yy72) : yymsp[-2].minor.yy148;
140812 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
140813 }else{
140814 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148);
140815 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy72);
140816 }
140817 }
140818 break;
140819 case 194: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
140820 {
140821 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[-2].minor.yy190.pExpr);
140822 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
140823 }
140824 break;
140825 case 195: /* case_exprlist ::= WHEN expr THEN expr */
140826 {
140827 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
140828 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, yymsp[0].minor.yy190.pExpr);
140829 }
140830 break;
140831 case 198: /* case_operand ::= expr */
140832 {yymsp[0].minor.yy72 = yymsp[0].minor.yy190.pExpr; /*A-overwrites-X*/}
140833 break;
140834 case 201: /* nexprlist ::= nexprlist COMMA expr */
140835 {yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[0].minor.yy190.pExpr);}
140836 break;
140837 case 202: /* nexprlist ::= expr */
140838 {yymsp[0].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy190.pExpr); /*A-overwrites-Y*/}
140839 break;
140840 case 204: /* paren_exprlist ::= LP exprlist RP */
140841 case 209: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==209);
140842 {yymsp[-2].minor.yy148 = yymsp[-1].minor.yy148;}
140843 break;
140844 case 205: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
140845 {
140846 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
140847 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy148, yymsp[-10].minor.yy194,
140848 &yymsp[-11].minor.yy0, yymsp[0].minor.yy72, SQLITE_SO_ASC, yymsp[-8].minor.yy194, SQLITE_IDXTYPE_APPDEF);
140849 }
140850 break;
140851 case 206: /* uniqueflag ::= UNIQUE */
140852 case 246: /* raisetype ::= ABORT */ yytestcase(yyruleno==246);
140853 {yymsp[0].minor.yy194 = OE_Abort;}
140854 break;
140855 case 207: /* uniqueflag ::= */
140856 {yymsp[1].minor.yy194 = OE_None;}
140857 break;
140858 case 210: /* eidlist ::= eidlist COMMA nm collate sortorder */
140859 {
140860 yymsp[-4].minor.yy148 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194);
140861 }
140862 break;
140863 case 211: /* eidlist ::= nm collate sortorder */
140864 {
140865 yymsp[-2].minor.yy148 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); /*A-overwrites-Y*/
140866 }
140867 break;
140868 case 214: /* cmd ::= DROP INDEX ifexists fullname */
140869 {sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
140870 break;
140871 case 215: /* cmd ::= VACUUM */
140872 {sqlite3Vacuum(pParse,0);}
140873 break;
140874 case 216: /* cmd ::= VACUUM nm */
140875 {sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
140876 break;
140877 case 217: /* cmd ::= PRAGMA nm dbnm */
140878 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
140879 break;
140880 case 218: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
140881 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
140882 break;
140883 case 219: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
140884 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
140885 break;
140886 case 220: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
140887 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
140888 break;
140889 case 221: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
140890 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
140891 break;
140892 case 224: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
140893 {
140894 Token all;
140895 all.z = yymsp[-3].minor.yy0.z;
140896 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
140897 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy145, &all);
140898 }
140899 break;
140900 case 225: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
140901 {
140902 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy194, yymsp[-4].minor.yy332.a, yymsp[-4].minor.yy332.b, yymsp[-2].minor.yy185, yymsp[0].minor.yy72, yymsp[-10].minor.yy194, yymsp[-8].minor.yy194);
140903 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
140904 }
140905 break;
140906 case 226: /* trigger_time ::= BEFORE|AFTER */
140907 { yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-X*/ }
140908 break;
140909 case 227: /* trigger_time ::= INSTEAD OF */
140910 { yymsp[-1].minor.yy194 = TK_INSTEAD;}
140911 break;
140912 case 228: /* trigger_time ::= */
140913 { yymsp[1].minor.yy194 = TK_BEFORE; }
140914 break;
140915 case 229: /* trigger_event ::= DELETE|INSERT */
140916 case 230: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==230);
140917 {yymsp[0].minor.yy332.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy332.b = 0;}
140918 break;
140919 case 231: /* trigger_event ::= UPDATE OF idlist */
140920 {yymsp[-2].minor.yy332.a = TK_UPDATE; yymsp[-2].minor.yy332.b = yymsp[0].minor.yy254;}
140921 break;
140922 case 232: /* when_clause ::= */
140923 case 251: /* key_opt ::= */ yytestcase(yyruleno==251);
140924 { yymsp[1].minor.yy72 = 0; }
140925 break;
140926 case 233: /* when_clause ::= WHEN expr */
140927 case 252: /* key_opt ::= KEY expr */ yytestcase(yyruleno==252);
140928 { yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr; }
140929 break;
140930 case 234: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
140931 {
140932 assert( yymsp[-2].minor.yy145!=0 );
140933 yymsp[-2].minor.yy145->pLast->pNext = yymsp[-1].minor.yy145;
140934 yymsp[-2].minor.yy145->pLast = yymsp[-1].minor.yy145;
140935 }
140936 break;
140937 case 235: /* trigger_cmd_list ::= trigger_cmd SEMI */
140938 {
140939 assert( yymsp[-1].minor.yy145!=0 );
140940 yymsp[-1].minor.yy145->pLast = yymsp[-1].minor.yy145;
140941 }
140942 break;
140943 case 236: /* trnm ::= nm DOT nm */
140944 {
140945 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
140946 sqlite3ErrorMsg(pParse,
140947 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
140948 "statements within triggers");
140949 }
140950 break;
140951 case 237: /* tridxby ::= INDEXED BY nm */
140952 {
140953 sqlite3ErrorMsg(pParse,
140954 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
140955 "within triggers");
140956 }
140957 break;
140958 case 238: /* tridxby ::= NOT INDEXED */
140959 {
140960 sqlite3ErrorMsg(pParse,
140961 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
140962 "within triggers");
140963 }
140964 break;
140965 case 239: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
140966 {yymsp[-6].minor.yy145 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy148, yymsp[0].minor.yy72, yymsp[-5].minor.yy194);}
140967 break;
140968 case 240: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
140969 {yymsp[-4].minor.yy145 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy254, yymsp[0].minor.yy243, yymsp[-4].minor.yy194);/*A-overwrites-R*/}
140970 break;
140971 case 241: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
140972 {yymsp[-4].minor.yy145 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy72);}
140973 break;
140974 case 242: /* trigger_cmd ::= select */
140975 {yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/}
140976 break;
140977 case 243: /* expr ::= RAISE LP IGNORE RP */
140978 {
140979 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140980 yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
140981 if( yymsp[-3].minor.yy190.pExpr ){
140982 yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore;
140983 }
140984 }
140985 break;
140986 case 244: /* expr ::= RAISE LP raisetype COMMA nm RP */
140987 {
140988 spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
140989 yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
140990 if( yymsp[-5].minor.yy190.pExpr ) {
140991 yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194;
140992 }
140993 }
140994 break;
140995 case 245: /* raisetype ::= ROLLBACK */
140996 {yymsp[0].minor.yy194 = OE_Rollback;}
140997 break;
140998 case 247: /* raisetype ::= FAIL */
140999 {yymsp[0].minor.yy194 = OE_Fail;}
141000 break;
141001 case 248: /* cmd ::= DROP TRIGGER ifexists fullname */
141002 {
141003 sqlite3DropTrigger(pParse,yymsp[0].minor.yy185,yymsp[-1].minor.yy194);
141004 }
141005 break;
141006 case 249: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
141007 {
141008 sqlite3Attach(pParse, yymsp[-3].minor.yy190.pExpr, yymsp[-1].minor.yy190.pExpr, yymsp[0].minor.yy72);
141009 }
141010 break;
141011 case 250: /* cmd ::= DETACH database_kw_opt expr */
141012 {
141013 sqlite3Detach(pParse, yymsp[0].minor.yy190.pExpr);
141014 }
141015 break;
141016 case 253: /* cmd ::= REINDEX */
 
 
141017 {sqlite3Reindex(pParse, 0, 0);}
141018 break;
141019 case 254: /* cmd ::= REINDEX nm dbnm */
141020 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
141021 break;
141022 case 255: /* cmd ::= ANALYZE */
141023 {sqlite3Analyze(pParse, 0, 0);}
141024 break;
141025 case 256: /* cmd ::= ANALYZE nm dbnm */
141026 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
141027 break;
141028 case 257: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
141029 {
141030 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy185,&yymsp[0].minor.yy0);
141031 }
141032 break;
141033 case 258: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
141034 {
141035 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
141036 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
141037 }
141038 break;
141039 case 259: /* add_column_fullname ::= fullname */
141040 {
141041 disableLookaside(pParse);
141042 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy185);
141043 }
141044 break;
141045 case 260: /* cmd ::= create_vtab */
141046 {sqlite3VtabFinishParse(pParse,0);}
141047 break;
141048 case 261: /* cmd ::= create_vtab LP vtabarglist RP */
141049 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
141050 break;
141051 case 262: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
141052 {
141053 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy194);
141054 }
141055 break;
141056 case 263: /* vtabarg ::= */
141057 {sqlite3VtabArgInit(pParse);}
141058 break;
141059 case 264: /* vtabargtoken ::= ANY */
141060 case 265: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==265);
141061 case 266: /* lp ::= LP */ yytestcase(yyruleno==266);
141062 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
141063 break;
141064 case 267: /* with ::= */
141065 {yymsp[1].minor.yy285 = 0;}
141066 break;
141067 case 268: /* with ::= WITH wqlist */
141068 { yymsp[-1].minor.yy285 = yymsp[0].minor.yy285; }
141069 break;
141070 case 269: /* with ::= WITH RECURSIVE wqlist */
141071 { yymsp[-2].minor.yy285 = yymsp[0].minor.yy285; }
141072 break;
141073 case 270: /* wqlist ::= nm eidlist_opt AS LP select RP */
141074 {
141075 yymsp[-5].minor.yy285 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); /*A-overwrites-X*/
141076 }
141077 break;
141078 case 271: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
141079 {
141080 yymsp[-7].minor.yy285 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy285, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243);
141081 }
141082 break;
141083 default:
141084 /* (272) input ::= cmdlist */ yytestcase(yyruleno==272);
141085 /* (273) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==273);
141086 /* (274) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=274);
141087 /* (275) ecmd ::= SEMI */ yytestcase(yyruleno==275);
141088 /* (276) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==276);
141089 /* (277) explain ::= */ yytestcase(yyruleno==277);
141090 /* (278) trans_opt ::= */ yytestcase(yyruleno==278);
141091 /* (279) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==279);
141092 /* (280) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==280);
141093 /* (281) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==281);
141094 /* (282) savepoint_opt ::= */ yytestcase(yyruleno==282);
141095 /* (283) cmd ::= create_table create_table_args */ yytestcase(yyruleno==283);
141096 /* (284) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==284);
141097 /* (285) columnlist ::= columnname carglist */ yytestcase(yyruleno==285);
141098 /* (286) nm ::= ID|INDEXED */ yytestcase(yyruleno==286);
141099 /* (287) nm ::= STRING */ yytestcase(yyruleno==287);
141100 /* (288) nm ::= JOIN_KW */ yytestcase(yyruleno==288);
141101 /* (289) typetoken ::= typename */ yytestcase(yyruleno==289);
141102 /* (290) typename ::= ID|STRING */ yytestcase(yyruleno==290);
141103 /* (291) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=291);
141104 /* (292) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=292);
141105 /* (293) carglist ::= carglist ccons */ yytestcase(yyruleno==293);
141106 /* (294) carglist ::= */ yytestcase(yyruleno==294);
141107 /* (295) ccons ::= NULL onconf */ yytestcase(yyruleno==295);
141108 /* (296) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==296);
141109 /* (297) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==297);
141110 /* (298) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=298);
141111 /* (299) tconscomma ::= */ yytestcase(yyruleno==299);
141112 /* (300) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=300);
141113 /* (301) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=301);
141114 /* (302) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=302);
141115 /* (303) oneselect ::= values */ yytestcase(yyruleno==303);
141116 /* (304) sclp ::= selcollist COMMA */ yytestcase(yyruleno==304);
141117 /* (305) as ::= ID|STRING */ yytestcase(yyruleno==305);
141118 /* (306) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=306);
141119 /* (307) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==307);
141120 /* (308) exprlist ::= nexprlist */ yytestcase(yyruleno==308);
141121 /* (309) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=309);
141122 /* (310) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=310);
141123 /* (311) nmnum ::= ON */ yytestcase(yyruleno==311);
141124 /* (312) nmnum ::= DELETE */ yytestcase(yyruleno==312);
141125 /* (313) nmnum ::= DEFAULT */ yytestcase(yyruleno==313);
141126 /* (314) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==314);
141127 /* (315) foreach_clause ::= */ yytestcase(yyruleno==315);
141128 /* (316) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==316);
141129 /* (317) trnm ::= nm */ yytestcase(yyruleno==317);
141130 /* (318) tridxby ::= */ yytestcase(yyruleno==318);
141131 /* (319) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==319);
141132 /* (320) database_kw_opt ::= */ yytestcase(yyruleno==320);
141133 /* (321) kwcolumn_opt ::= */ yytestcase(yyruleno==321);
141134 /* (322) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==322);
141135 /* (323) vtabarglist ::= vtabarg */ yytestcase(yyruleno==323);
141136 /* (324) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==324);
141137 /* (325) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==325);
141138 /* (326) anylist ::= */ yytestcase(yyruleno==326);
141139 /* (327) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==327);
141140 /* (328) anylist ::= anylist ANY */ yytestcase(yyruleno==328);
141141 break;
141142 /********** End reduce actions ************************************************/
141143 };
141144 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
141145 yygoto = yyRuleInfo[yyruleno].lhs;
@@ -141151,20 +141570,15 @@
141151 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
141152
141153 /* It is not possible for a REDUCE to be followed by an error */
141154 assert( yyact!=YY_ERROR_ACTION );
141155
141156 if( yyact==YY_ACCEPT_ACTION ){
141157 yypParser->yytos += yysize;
141158 yy_accept(yypParser);
141159 }else{
141160 yymsp += yysize+1;
141161 yypParser->yytos = yymsp;
141162 yymsp->stateno = (YYACTIONTYPE)yyact;
141163 yymsp->major = (YYCODETYPE)yygoto;
141164 yyTraceShift(yypParser, yyact);
141165 }
141166 }
141167
141168 /*
141169 ** The following code executes when the parse fails
141170 */
@@ -141271,24 +141685,35 @@
141271 #endif
141272 sqlite3ParserARG_STORE;
141273
141274 #ifndef NDEBUG
141275 if( yyTraceFILE ){
141276 fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]);
 
 
 
 
 
 
 
141277 }
141278 #endif
141279
141280 do{
141281 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
141282 if( yyact <= YY_MAX_SHIFTREDUCE ){
 
 
141283 yy_shift(yypParser,yyact,yymajor,yyminor);
141284 #ifndef YYNOERRORRECOVERY
141285 yypParser->yyerrcnt--;
141286 #endif
141287 yymajor = YYNOCODE;
141288 }else if( yyact <= YY_MAX_REDUCE ){
141289 yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
 
 
141290 }else{
141291 assert( yyact == YY_ERROR_ACTION );
141292 yyminorunion.yy0 = yyminor;
141293 #ifdef YYERRORSYMBOL
141294 int yymx;
@@ -143527,10 +143952,11 @@
143527 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
143528 { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
143529 { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension },
143530 { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose },
143531 { SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG },
 
143532 };
143533 unsigned int i;
143534 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
143535 for(i=0; i<ArraySize(aFlagOp); i++){
143536 if( aFlagOp[i].op==op ){
@@ -146620,10 +147046,26 @@
146620 sqlite3ResetAllSchemasOfConnection(db);
146621 }
146622 sqlite3_mutex_leave(db->mutex);
146623 break;
146624 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146625 }
146626 va_end(ap);
146627 #endif /* SQLITE_UNTESTABLE */
146628 return rc;
146629 }
@@ -168393,11 +168835,11 @@
168393 int iHeight, /* Height of sub-tree rooted at pCell */
168394 RtreeNode **ppLeaf /* OUT: Selected leaf page */
168395 ){
168396 int rc;
168397 int ii;
168398 RtreeNode *pNode;
168399 rc = nodeAcquire(pRtree, 1, 0, &pNode);
168400
168401 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
168402 int iCell;
168403 sqlite3_int64 iBest = 0;
@@ -169268,11 +169710,11 @@
169268 ** the root node (the operation that Gutman's paper says to perform
169269 ** in this scenario).
169270 */
169271 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
169272 int rc2;
169273 RtreeNode *pChild;
169274 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
169275 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
169276 if( rc==SQLITE_OK ){
169277 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
169278 }
@@ -186623,18 +187065,19 @@
186623 ** sqlite3Fts5ParserARG_FETCH Code to extract %extra_argument from fts5yypParser
186624 ** fts5YYERRORSYMBOL is the code number of the error symbol. If not
186625 ** defined, then do no error processing.
186626 ** fts5YYNSTATE the combined number of states.
186627 ** fts5YYNRULE the number of rules in the grammar
 
186628 ** fts5YY_MAX_SHIFT Maximum value for shift actions
186629 ** fts5YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
186630 ** fts5YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
186631 ** fts5YY_MIN_REDUCE Minimum value for reduce actions
186632 ** fts5YY_MAX_REDUCE Maximum value for reduce actions
186633 ** fts5YY_ERROR_ACTION The fts5yy_action[] code for syntax error
186634 ** fts5YY_ACCEPT_ACTION The fts5yy_action[] code for accept
186635 ** fts5YY_NO_ACTION The fts5yy_action[] code for no-op
 
 
186636 */
186637 #ifndef INTERFACE
186638 # define INTERFACE 1
186639 #endif
186640 /************* Begin control #defines *****************************************/
@@ -186658,18 +187101,19 @@
186658 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
186659 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
186660 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
186661 #define fts5YYNSTATE 35
186662 #define fts5YYNRULE 28
 
186663 #define fts5YY_MAX_SHIFT 34
186664 #define fts5YY_MIN_SHIFTREDUCE 52
186665 #define fts5YY_MAX_SHIFTREDUCE 79
186666 #define fts5YY_MIN_REDUCE 80
186667 #define fts5YY_MAX_REDUCE 107
186668 #define fts5YY_ERROR_ACTION 108
186669 #define fts5YY_ACCEPT_ACTION 109
186670 #define fts5YY_NO_ACTION 110
186671 /************* End control #defines *******************************************/
186672
186673 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
186674 ** otherwise.
186675 **
@@ -186695,39 +187139,33 @@
186695 ** token onto the stack and goto state N.
186696 **
186697 ** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
186698 ** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
186699 **
186700 ** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
186701 ** and fts5YY_MAX_REDUCE
186702 **
186703 ** N == fts5YY_ERROR_ACTION A syntax error has occurred.
186704 **
186705 ** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
186706 **
186707 ** N == fts5YY_NO_ACTION No such action. Denotes unused
186708 ** slots in the fts5yy_action[] table.
 
 
 
186709 **
186710 ** The action table is constructed as a single large table named fts5yy_action[].
186711 ** Given state S and lookahead X, the action is computed as either:
186712 **
186713 ** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
186714 ** (B) N = fts5yy_default[S]
186715 **
186716 ** The (A) formula is preferred. The B formula is used instead if:
186717 ** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
186718 ** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
186719 ** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
186720 ** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
186721 ** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
186722 ** Hence only tests (1) and (2) need to be evaluated.)
186723 **
186724 ** The formulas above are for computing the action when the lookahead is
186725 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
186726 ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
186727 ** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
186728 ** fts5YY_SHIFT_USE_DFLT.
186729 **
186730 ** The following are the tables generated in this section:
186731 **
186732 ** fts5yy_action[] A single table containing all actions.
186733 ** fts5yy_lookahead[] A table containing the lookahead for each entry in
@@ -186739,19 +187177,19 @@
186739 ** fts5yy_default[] Default action for each state.
186740 **
186741 *********** Begin parsing tables **********************************************/
186742 #define fts5YY_ACTTAB_COUNT (105)
186743 static const fts5YYACTIONTYPE fts5yy_action[] = {
186744 /* 0 */ 109, 20, 93, 6, 28, 96, 95, 26, 26, 18,
186745 /* 10 */ 93, 6, 28, 17, 95, 56, 26, 19, 93, 6,
186746 /* 20 */ 28, 14, 95, 105, 26, 89, 93, 6, 28, 25,
186747 /* 30 */ 95, 78, 26, 21, 93, 6, 28, 104, 95, 58,
186748 /* 40 */ 26, 29, 93, 6, 28, 32, 95, 22, 26, 24,
186749 /* 50 */ 16, 23, 11, 1, 14, 13, 24, 16, 31, 11,
186750 /* 60 */ 3, 94, 13, 27, 8, 95, 82, 26, 7, 4,
186751 /* 70 */ 5, 3, 4, 5, 3, 80, 4, 5, 3, 63,
186752 /* 80 */ 33, 34, 62, 12, 2, 83, 13, 10, 12, 71,
186753 /* 90 */ 10, 13, 78, 5, 3, 78, 9, 30, 75, 82,
186754 /* 100 */ 54, 57, 53, 57, 15,
186755 };
186756 static const fts5YYCODETYPE fts5yy_lookahead[] = {
186757 /* 0 */ 17, 18, 19, 20, 21, 23, 23, 25, 25, 18,
@@ -186762,35 +187200,35 @@
186762 /* 50 */ 7, 22, 9, 10, 9, 12, 6, 7, 13, 9,
186763 /* 60 */ 3, 19, 12, 21, 5, 23, 28, 25, 5, 1,
186764 /* 70 */ 2, 3, 1, 2, 3, 0, 1, 2, 3, 11,
186765 /* 80 */ 25, 26, 11, 9, 10, 5, 12, 10, 9, 11,
186766 /* 90 */ 10, 12, 15, 2, 3, 15, 24, 25, 9, 28,
186767 /* 100 */ 8, 9, 8, 9, 9,
 
 
186768 };
186769 #define fts5YY_SHIFT_USE_DFLT (105)
186770 #define fts5YY_SHIFT_COUNT (34)
186771 #define fts5YY_SHIFT_MIN (0)
186772 #define fts5YY_SHIFT_MAX (95)
186773 static const unsigned char fts5yy_shift_ofst[] = {
186774 /* 0 */ 43, 43, 43, 43, 43, 43, 50, 74, 79, 45,
186775 /* 10 */ 12, 80, 77, 12, 16, 16, 30, 30, 68, 71,
186776 /* 20 */ 75, 91, 92, 94, 6, 31, 31, 59, 63, 57,
186777 /* 30 */ 31, 89, 95, 31, 78,
186778 };
186779 #define fts5YY_REDUCE_USE_DFLT (-19)
186780 #define fts5YY_REDUCE_COUNT (17)
186781 #define fts5YY_REDUCE_MIN (-18)
186782 #define fts5YY_REDUCE_MAX (72)
186783 static const signed char fts5yy_reduce_ofst[] = {
186784 /* 0 */ -17, -9, -1, 7, 15, 23, 42, -18, -18, 55,
186785 /* 10 */ 72, -4, -4, 4, -4, 10, 25, 29,
186786 };
186787 static const fts5YYACTIONTYPE fts5yy_default[] = {
186788 /* 0 */ 108, 108, 108, 108, 108, 108, 92, 108, 108, 102,
186789 /* 10 */ 108, 107, 107, 108, 107, 107, 108, 108, 108, 108,
186790 /* 20 */ 108, 88, 108, 108, 108, 98, 97, 108, 108, 87,
186791 /* 30 */ 100, 108, 108, 101, 108,
186792 };
186793 /********** End of lemon-generated parsing tables *****************************/
186794
186795 /* The next table maps tokens (terminal symbols) into fallback tokens.
186796 ** If a construct like the following:
@@ -186888,23 +187326,44 @@
186888 if( fts5yyTraceFILE==0 ) fts5yyTracePrompt = 0;
186889 else if( fts5yyTracePrompt==0 ) fts5yyTraceFILE = 0;
186890 }
186891 #endif /* NDEBUG */
186892
186893 #ifndef NDEBUG
186894 /* For tracing shifts, the names of all terminals and nonterminals
186895 ** are required. The following table supplies these names */
186896 static const char *const fts5yyTokenName[] = {
186897 "$", "OR", "AND", "NOT",
186898 "TERM", "COLON", "MINUS", "LCP",
186899 "RCP", "STRING", "LP", "RP",
186900 "CARET", "COMMA", "PLUS", "STAR",
186901 "error", "input", "expr", "cnearset",
186902 "exprlist", "colset", "colsetlist", "nearset",
186903 "nearphrases", "phrase", "neardist_opt", "star_opt",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186904 };
186905 #endif /* NDEBUG */
186906
186907 #ifndef NDEBUG
186908 /* For tracing reduce actions, the names of all rules are required.
186909 */
186910 static const char *const fts5yyRuleName[] = {
@@ -187151,10 +187610,47 @@
187151 fts5yyParser *pParser = (fts5yyParser*)p;
187152 return pParser->fts5yyhwm;
187153 }
187154 #endif
187155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187156 /*
187157 ** Find the appropriate action for a parser given the terminal
187158 ** look-ahead token iLookAhead.
187159 */
187160 static unsigned int fts5yy_find_shift_action(
@@ -187162,17 +187658,22 @@
187162 fts5YYCODETYPE iLookAhead /* The look-ahead token */
187163 ){
187164 int i;
187165 int stateno = pParser->fts5yytos->stateno;
187166
187167 if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
187168 assert( stateno <= fts5YY_SHIFT_COUNT );
 
 
 
187169 do{
187170 i = fts5yy_shift_ofst[stateno];
 
187171 assert( iLookAhead!=fts5YYNOCODE );
 
187172 i += iLookAhead;
187173 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
187174 #ifdef fts5YYFALLBACK
187175 fts5YYCODETYPE iFallback; /* Fallback token */
187176 if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
187177 && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
187178 #ifndef NDEBUG
@@ -187231,11 +187732,10 @@
187231 }
187232 #else
187233 assert( stateno<=fts5YY_REDUCE_COUNT );
187234 #endif
187235 i = fts5yy_reduce_ofst[stateno];
187236 assert( i!=fts5YY_REDUCE_USE_DFLT );
187237 assert( iLookAhead!=fts5YYNOCODE );
187238 i += iLookAhead;
187239 #ifdef fts5YYERRORSYMBOL
187240 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
187241 return fts5yy_default[stateno];
@@ -187269,24 +187769,25 @@
187269
187270 /*
187271 ** Print tracing information for a SHIFT action
187272 */
187273 #ifndef NDEBUG
187274 static void fts5yyTraceShift(fts5yyParser *fts5yypParser, int fts5yyNewState){
187275 if( fts5yyTraceFILE ){
187276 if( fts5yyNewState<fts5YYNSTATE ){
187277 fprintf(fts5yyTraceFILE,"%sShift '%s', go to state %d\n",
187278 fts5yyTracePrompt,fts5yyTokenName[fts5yypParser->fts5yytos->major],
187279 fts5yyNewState);
187280 }else{
187281 fprintf(fts5yyTraceFILE,"%sShift '%s'\n",
187282 fts5yyTracePrompt,fts5yyTokenName[fts5yypParser->fts5yytos->major]);
 
187283 }
187284 }
187285 }
187286 #else
187287 # define fts5yyTraceShift(X,Y)
187288 #endif
187289
187290 /*
187291 ** Perform a shift action.
187292 */
@@ -187324,59 +187825,67 @@
187324 }
187325 fts5yytos = fts5yypParser->fts5yytos;
187326 fts5yytos->stateno = (fts5YYACTIONTYPE)fts5yyNewState;
187327 fts5yytos->major = (fts5YYCODETYPE)fts5yyMajor;
187328 fts5yytos->minor.fts5yy0 = fts5yyMinor;
187329 fts5yyTraceShift(fts5yypParser, fts5yyNewState);
187330 }
187331
187332 /* The following table contains information about every rule that
187333 ** is used during the reduce.
187334 */
187335 static const struct {
187336 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
187337 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
187338 } fts5yyRuleInfo[] = {
187339 { 17, -1 },
187340 { 21, -4 },
187341 { 21, -3 },
187342 { 21, -1 },
187343 { 21, -2 },
187344 { 22, -2 },
187345 { 22, -1 },
187346 { 18, -3 },
187347 { 18, -3 },
187348 { 18, -3 },
187349 { 18, -5 },
187350 { 18, -3 },
187351 { 18, -1 },
187352 { 20, -1 },
187353 { 20, -2 },
187354 { 19, -1 },
187355 { 19, -3 },
187356 { 23, -1 },
187357 { 23, -2 },
187358 { 23, -5 },
187359 { 24, -1 },
187360 { 24, -2 },
187361 { 26, 0 },
187362 { 26, -2 },
187363 { 25, -4 },
187364 { 25, -2 },
187365 { 27, -1 },
187366 { 27, 0 },
187367 };
187368
187369 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
187370
187371 /*
187372 ** Perform a reduce action and the shift that must immediately
187373 ** follow the reduce.
 
 
 
 
 
 
187374 */
187375 static void fts5yy_reduce(
187376 fts5yyParser *fts5yypParser, /* The parser */
187377 unsigned int fts5yyruleno /* Number of the rule by which to reduce */
 
 
187378 ){
187379 int fts5yygoto; /* The next state */
187380 int fts5yyact; /* The next action */
187381 fts5yyStackEntry *fts5yymsp; /* The top of the parser's stack */
187382 int fts5yysize; /* Amount to pop the stack */
@@ -187383,12 +187892,18 @@
187383 sqlite3Fts5ParserARG_FETCH;
187384 fts5yymsp = fts5yypParser->fts5yytos;
187385 #ifndef NDEBUG
187386 if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
187387 fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs;
187388 fprintf(fts5yyTraceFILE, "%sReduce [%s], go to state %d.\n", fts5yyTracePrompt,
187389 fts5yyRuleName[fts5yyruleno], fts5yymsp[fts5yysize].stateno);
 
 
 
 
 
 
187390 }
187391 #endif /* NDEBUG */
187392
187393 /* Check that the stack is large enough to grow by a single entry
187394 ** if the RHS of the rule is empty. This ensures that there is room
@@ -187581,20 +188096,15 @@
187581 assert( !(fts5yyact>fts5YY_MAX_SHIFT && fts5yyact<=fts5YY_MAX_SHIFTREDUCE) );
187582
187583 /* It is not possible for a REDUCE to be followed by an error */
187584 assert( fts5yyact!=fts5YY_ERROR_ACTION );
187585
187586 if( fts5yyact==fts5YY_ACCEPT_ACTION ){
187587 fts5yypParser->fts5yytos += fts5yysize;
187588 fts5yy_accept(fts5yypParser);
187589 }else{
187590 fts5yymsp += fts5yysize+1;
187591 fts5yypParser->fts5yytos = fts5yymsp;
187592 fts5yymsp->stateno = (fts5YYACTIONTYPE)fts5yyact;
187593 fts5yymsp->major = (fts5YYCODETYPE)fts5yygoto;
187594 fts5yyTraceShift(fts5yypParser, fts5yyact);
187595 }
187596 }
187597
187598 /*
187599 ** The following code executes when the parse fails
187600 */
@@ -187702,24 +188212,35 @@
187702 #endif
187703 sqlite3Fts5ParserARG_STORE;
187704
187705 #ifndef NDEBUG
187706 if( fts5yyTraceFILE ){
187707 fprintf(fts5yyTraceFILE,"%sInput '%s'\n",fts5yyTracePrompt,fts5yyTokenName[fts5yymajor]);
 
 
 
 
 
 
 
187708 }
187709 #endif
187710
187711 do{
187712 fts5yyact = fts5yy_find_shift_action(fts5yypParser,(fts5YYCODETYPE)fts5yymajor);
187713 if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
 
 
187714 fts5yy_shift(fts5yypParser,fts5yyact,fts5yymajor,fts5yyminor);
187715 #ifndef fts5YYNOERRORRECOVERY
187716 fts5yypParser->fts5yyerrcnt--;
187717 #endif
187718 fts5yymajor = fts5YYNOCODE;
187719 }else if( fts5yyact <= fts5YY_MAX_REDUCE ){
187720 fts5yy_reduce(fts5yypParser,fts5yyact-fts5YY_MIN_REDUCE);
 
 
187721 }else{
187722 assert( fts5yyact == fts5YY_ERROR_ACTION );
187723 fts5yyminorunion.fts5yy0 = fts5yyminor;
187724 #ifdef fts5YYERRORSYMBOL
187725 int fts5yymx;
@@ -188193,10 +188714,20 @@
188193 *piPos = iAdj;
188194 }
188195
188196 return rc;
188197 }
 
 
 
 
 
 
 
 
 
 
188198
188199 /*
188200 ** Implementation of snippet() function.
188201 */
188202 static void fts5SnippetFunction(
@@ -188229,13 +188760,13 @@
188229 }
188230
188231 nCol = pApi->xColumnCount(pFts);
188232 memset(&ctx, 0, sizeof(HighlightContext));
188233 iCol = sqlite3_value_int(apVal[0]);
188234 ctx.zOpen = (const char*)sqlite3_value_text(apVal[1]);
188235 ctx.zClose = (const char*)sqlite3_value_text(apVal[2]);
188236 zEllips = (const char*)sqlite3_value_text(apVal[3]);
188237 nToken = sqlite3_value_int(apVal[4]);
188238
188239 iBestCol = (iCol>=0 ? iCol : 0);
188240 nPhrase = pApi->xPhraseCount(pFts);
188241 aSeen = sqlite3_malloc(nPhrase);
@@ -202410,11 +202941,11 @@
202410 int nArg, /* Number of args */
202411 sqlite3_value **apUnused /* Function arguments */
202412 ){
202413 assert( nArg==0 );
202414 UNUSED_PARAM2(nArg, apUnused);
202415 sqlite3_result_text(pCtx, "fts5: 2017-12-13 15:32:33 30bf38d589adf0b2eb613e184ffb03ed7e625736cb04fd5c341328f72bc5ef4d", -1, SQLITE_TRANSIENT);
202416 }
202417
202418 static int fts5Init(sqlite3 *db){
202419 static const sqlite3_module fts5Mod = {
202420 /* iVersion */ 2,
@@ -206678,12 +207209,12 @@
206678 }
206679 #endif /* SQLITE_CORE */
206680 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
206681
206682 /************** End of stmt.c ************************************************/
206683 #if __LINE__!=206683
206684 #undef SQLITE_SOURCE_ID
206685 #define SQLITE_SOURCE_ID "2017-12-13 20:35:34 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b42alt2"
206686 #endif
206687 /* Return the source-id for this library */
206688 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
206689 /************************** End of sqlite3.c ******************************/
206690
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2018-01-07 20:38:10 67c4a8c6881e33b830aa27c80e7e3d697a4222939edd77cd5ca77ece16471ea4"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -3082,11 +3082,10 @@
3082 ** is an integer - non-zero to disable checkpoints-on-close, or zero (the
3083 ** default) to enable them. The second parameter is a pointer to an integer
3084 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
3085 ** have been disabled - 0 if they are not disabled, 1 if they are.
3086 ** </dd>
 
3087 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
3088 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
3089 ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
3090 ** a single SQL query statement will always use the same algorithm regardless
3091 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
@@ -3093,11 +3092,20 @@
3092 ** that look at the values of bound parameters, which can make some queries
3093 ** slower. But the QPSG has the advantage of more predictable behavior. With
3094 ** the QPSG active, SQLite will always use the same query plan in the field as
3095 ** was used during testing in the lab.
3096 ** </dd>
3097 ** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
3098 ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
3099 ** include output for any operations performed by trigger programs. This
3100 ** option is used to set or clear (the default) a flag that governs this
3101 ** behavior. The first parameter passed to this operation is an integer -
3102 ** non-zero to enable output for trigger programs, or zero to disable it.
3103 ** The second parameter is a pointer to an integer into which is written
3104 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
3105 ** it is not disabled, 1 if it is.
3106 ** </dd>
3107 ** </dl>
3108 */
3109 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
3110 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
3111 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -3104,11 +3112,12 @@
3112 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
3113 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
3114 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
3115 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
3116 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
3117 #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
3118 #define SQLITE_DBCONFIG_MAX 1008 /* Largest DBCONFIG */
3119
3120 /*
3121 ** CAPI3REF: Enable Or Disable Extended Result Codes
3122 ** METHOD: sqlite3
3123 **
@@ -7984,13 +7993,13 @@
7993 ** ^The third and fourth parameters to this routine
7994 ** are passed directly through to the second and third parameters of
7995 ** the xFileControl method. ^The return value of the xFileControl
7996 ** method becomes the return value of this routine.
7997 **
7998 ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
7999 ** a pointer to the underlying [sqlite3_file] object to be written into
8000 ** the space pointed to by the 4th parameter. ^The [SQLITE_FCNTL_FILE_POINTER]
8001 ** case is a short-circuit path which does not actually invoke the
8002 ** underlying sqlite3_io_methods.xFileControl method.
8003 **
8004 ** ^If the second parameter (zDbName) does not match the name of any
8005 ** open database file, then SQLITE_ERROR is returned. ^This error
@@ -7998,11 +8007,11 @@
8007 ** or [sqlite3_errmsg()]. The underlying xFileControl method might
8008 ** also return SQLITE_ERROR. There is no way to distinguish between
8009 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
8010 ** xFileControl method.
8011 **
8012 ** See also: [file control opcodes]
8013 */
8014 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
8015
8016 /*
8017 ** CAPI3REF: Testing Interface
@@ -8055,11 +8064,12 @@
8064 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
8065 #define SQLITE_TESTCTRL_BYTEORDER 22
8066 #define SQLITE_TESTCTRL_ISINIT 23
8067 #define SQLITE_TESTCTRL_SORTER_MMAP 24
8068 #define SQLITE_TESTCTRL_IMPOSTER 25
8069 #define SQLITE_TESTCTRL_PARSER_COVERAGE 26
8070 #define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */
8071
8072 /*
8073 ** CAPI3REF: SQLite Runtime Status
8074 **
8075 ** ^These interfaces are used to retrieve runtime status information
@@ -9309,10 +9319,25 @@
9319 ** of the SQL statement that triggered the call to the [xUpdate] method of the
9320 ** [virtual table].
9321 */
9322 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
9323
9324 /*
9325 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9326 **
9327 ** This function may only be called from within a call to the [xBestIndex]
9328 ** method of a [virtual table].
9329 **
9330 ** The first argument must be the sqlite3_index_info object that is the
9331 ** first parameter to the xBestIndex() method. The second argument must be
9332 ** an index into the aConstraint[] array belonging to the sqlite3_index_info
9333 ** structure passed to xBestIndex. This function returns a pointer to a buffer
9334 ** containing the name of the collation sequence for the corresponding
9335 ** constraint.
9336 */
9337 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9338
9339 /*
9340 ** CAPI3REF: Conflict resolution modes
9341 ** KEYWORDS: {conflict resolution mode}
9342 **
9343 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -13144,11 +13169,10 @@
13169 typedef struct Column Column;
13170 typedef struct Db Db;
13171 typedef struct Schema Schema;
13172 typedef struct Expr Expr;
13173 typedef struct ExprList ExprList;
 
13174 typedef struct FKey FKey;
13175 typedef struct FuncDestructor FuncDestructor;
13176 typedef struct FuncDef FuncDef;
13177 typedef struct FuncDefHash FuncDefHash;
13178 typedef struct IdList IdList;
@@ -13490,10 +13514,13 @@
13514 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
13515 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
13516 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
13517 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
13518 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
13519 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
13520 SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
13521 #endif
13522 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
13523 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
13524 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
13525
13526 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
@@ -13841,82 +13868,84 @@
13868 #define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
13869 #define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
13870 #define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
13871 #define OP_Compare 94 /* synopsis: r[P1@P3] <-> r[P2@P3] */
13872 #define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
13873 #define OP_Offset 96 /* synopsis: r[P3] = sqlite_offset(P1) */
13874 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
13875 #define OP_Column 98 /* synopsis: r[P3]=PX */
13876 #define OP_Affinity 99 /* synopsis: affinity(r[P1@P2]) */
13877 #define OP_MakeRecord 100 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
13878 #define OP_Count 101 /* synopsis: r[P2]=count() */
13879 #define OP_ReadCookie 102
13880 #define OP_SetCookie 103
13881 #define OP_ReopenIdx 104 /* synopsis: root=P2 iDb=P3 */
13882 #define OP_OpenRead 105 /* synopsis: root=P2 iDb=P3 */
13883 #define OP_OpenWrite 106 /* synopsis: root=P2 iDb=P3 */
13884 #define OP_OpenDup 107
13885 #define OP_OpenAutoindex 108 /* synopsis: nColumn=P2 */
13886 #define OP_OpenEphemeral 109 /* synopsis: nColumn=P2 */
13887 #define OP_SorterOpen 110
13888 #define OP_SequenceTest 111 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
13889 #define OP_OpenPseudo 112 /* synopsis: P3 columns in r[P2] */
13890 #define OP_Close 113
13891 #define OP_ColumnsUsed 114
13892 #define OP_Sequence 115 /* synopsis: r[P2]=cursor[P1].ctr++ */
13893 #define OP_NewRowid 116 /* synopsis: r[P2]=rowid */
13894 #define OP_Insert 117 /* synopsis: intkey=r[P3] data=r[P2] */
13895 #define OP_InsertInt 118 /* synopsis: intkey=P3 data=r[P2] */
13896 #define OP_Delete 119
13897 #define OP_ResetCount 120
13898 #define OP_SorterCompare 121 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13899 #define OP_SorterData 122 /* synopsis: r[P2]=data */
13900 #define OP_RowData 123 /* synopsis: r[P2]=data */
13901 #define OP_Rowid 124 /* synopsis: r[P2]=rowid */
13902 #define OP_NullRow 125
13903 #define OP_SeekEnd 126
13904 #define OP_SorterInsert 127 /* synopsis: key=r[P2] */
13905 #define OP_IdxInsert 128 /* synopsis: key=r[P2] */
13906 #define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */
13907 #define OP_DeferredSeek 130 /* synopsis: Move P3 to P1.rowid if needed */
13908 #define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */
13909 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13910 #define OP_Destroy 133
13911 #define OP_Clear 134
13912 #define OP_ResetSorter 135
13913 #define OP_CreateBtree 136 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
13914 #define OP_SqlExec 137
13915 #define OP_ParseSchema 138
13916 #define OP_LoadAnalysis 139
13917 #define OP_DropTable 140
13918 #define OP_DropIndex 141
13919 #define OP_DropTrigger 142
13920 #define OP_IntegrityCk 143
13921 #define OP_RowSetAdd 144 /* synopsis: rowset(P1)=r[P2] */
13922 #define OP_Param 145
13923 #define OP_FkCounter 146 /* synopsis: fkctr[P1]+=P2 */
13924 #define OP_MemMax 147 /* synopsis: r[P1]=max(r[P1],r[P2]) */
13925 #define OP_OffsetLimit 148 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
13926 #define OP_AggStep0 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13927 #define OP_AggStep 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13928 #define OP_AggFinal 151 /* synopsis: accum=r[P1] N=P2 */
13929 #define OP_Expire 152
13930 #define OP_TableLock 153 /* synopsis: iDb=P1 root=P2 write=P3 */
13931 #define OP_VBegin 154
13932 #define OP_VCreate 155
13933 #define OP_VDestroy 156
13934 #define OP_VOpen 157
13935 #define OP_VColumn 158 /* synopsis: r[P3]=vcolumn(P2) */
13936 #define OP_VRename 159
13937 #define OP_Pagecount 160
13938 #define OP_MaxPgcnt 161
13939 #define OP_PureFunc0 162
13940 #define OP_Function0 163 /* synopsis: r[P3]=func(r[P2@P5]) */
13941 #define OP_PureFunc 164
13942 #define OP_Function 165 /* synopsis: r[P3]=func(r[P2@P5]) */
13943 #define OP_Trace 166
13944 #define OP_CursorHint 167
13945 #define OP_Noop 168
13946 #define OP_Explain 169
13947
13948 /* Properties such as "out2" or "jump" that are specified in
13949 ** comments following the "case" for each opcode in the vdbe.c
13950 ** are encoded into bitvectors as follows:
13951 */
@@ -13937,20 +13966,20 @@
13966 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x02,\
13967 /* 64 */ 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,\
13968 /* 72 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13969 /* 80 */ 0x02, 0x02, 0x02, 0x00, 0x26, 0x26, 0x26, 0x26,\
13970 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
13971 /* 96 */ 0x20, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
13972 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13973 /* 112 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
13974 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04,\
13975 /* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
13976 /* 136 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13977 /* 144 */ 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00,\
13978 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13979 /* 160 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13980 /* 168 */ 0x00, 0x00,}
13981
13982 /* The sqlite3P2Values() routine is able to run faster if it knows
13983 ** the value of the largest JUMP opcode. The smaller the maximum
13984 ** JUMP opcode the better, so the mkopcodeh.tcl script that
13985 ** generated this include file strives to group all JUMP opcodes
@@ -15206,11 +15235,11 @@
15235 #ifndef SQLITE_OMIT_VIRTUALTABLE
15236 int nVTrans; /* Allocated size of aVTrans */
15237 Hash aModule; /* populated by sqlite3_create_module() */
15238 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
15239 VTable **aVTrans; /* Virtual tables with open transactions */
15240 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
15241 #endif
15242 Hash aFunc; /* Hash table of connection functions */
15243 Hash aCollSeq; /* All collating sequences */
15244 BusyHandler busyHandler; /* Busy callback */
15245 Db aDbStatic[2]; /* Static space for the 2 default backends */
@@ -15281,11 +15310,13 @@
15310 #define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */
15311 #define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */
15312 #define SQLITE_QueryOnly 0x00100000 /* Disable database changes */
15313 #define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */
15314 #define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */
15315 #define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee*/
15316 #define SQLITE_TriggerEQP 0x01000000 /* Show trigger EXPLAIN QUERY PLAN */
15317
15318 /* Flags used only if debugging */
15319 #ifdef SQLITE_DEBUG
15320 #define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */
15321 #define SQLITE_VdbeListing 0x10000000 /* Debug listings of VDBE programs */
15322 #define SQLITE_VdbeTrace 0x20000000 /* True to trace VDBE execution */
@@ -15414,10 +15445,11 @@
15445 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
15446 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
15447 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
15448 ** single query - might change over time */
15449 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
15450 #define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
15451
15452 /*
15453 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
15454 ** used to create the initializers for the FuncDef structures.
15455 **
@@ -16288,21 +16320,10 @@
16320 int iConstExprReg; /* Register in which Expr value is cached */
16321 } u;
16322 } a[1]; /* One slot for each expression in the list */
16323 };
16324
 
 
 
 
 
 
 
 
 
 
 
16325 /*
16326 ** An instance of this structure can hold a simple list of identifiers,
16327 ** such as the list "a,b,c" in the following statements:
16328 **
16329 ** INSERT INTO t(a,b,c) VALUES ...;
@@ -16999,10 +17020,11 @@
17020 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
17021 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
17022 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
17023 ExprList *pExprList; /* SET clause for UPDATE. */
17024 IdList *pIdList; /* Column names for INSERT */
17025 char *zSpan; /* Original SQL text of this command */
17026 TriggerStep *pNext; /* Next in the link-list */
17027 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
17028 };
17029
17030 /*
@@ -17309,10 +17331,11 @@
17331 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, u64);
17332 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, u64);
17333 SQLITE_PRIVATE void *sqlite3DbMallocRawNN(sqlite3*, u64);
17334 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
17335 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
17336 SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3*,const char*,const char*);
17337 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
17338 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
17339 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
17340 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
17341 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
@@ -17447,11 +17470,11 @@
17470 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
17471 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
17472 SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
17473 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
17474 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
17475 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
17476 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
17477 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
17478 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
17479 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
17480 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
@@ -17477,11 +17500,11 @@
17500 #endif
17501 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*);
17502 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
17503 SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
17504 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
17505 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
17506 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
17507 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
17508 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
17509 sqlite3_vfs**,char**,char **);
17510 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
@@ -17698,15 +17721,18 @@
17721 SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
17722 int, int, int);
17723 SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
17724 void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
17725 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*);
17726 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*,
17727 const char*,const char*);
17728 SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
17729 Select*,u8,const char*,const char*);
17730 SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8,
17731 const char*,const char*);
17732 SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*,
17733 const char*,const char*);
17734 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*);
17735 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
17736 SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
17737 # define sqlite3ParseToplevel(p) ((p)->pToplevel ? (p)->pToplevel : (p))
17738 # define sqlite3IsToplevel(p) ((p)->pToplevel==0)
@@ -18132,10 +18158,13 @@
18158 #endif
18159
18160 #ifdef SQLITE_DEBUG
18161 SQLITE_PRIVATE void sqlite3ParserTrace(FILE*, char *);
18162 #endif
18163 #if defined(YYCOVERAGE)
18164 SQLITE_PRIVATE int sqlite3ParserCoverage(FILE*);
18165 #endif
18166
18167 /*
18168 ** If the SQLITE_ENABLE IOTRACE exists then the global variable
18169 ** sqlite3IoTrace is a pointer to a printf-like routine used to
18170 ** print I/O tracing messages.
@@ -25667,10 +25696,23 @@
25696 memcpy(zNew, z, (size_t)n);
25697 zNew[n] = 0;
25698 }
25699 return zNew;
25700 }
25701
25702 /*
25703 ** The text between zStart and zEnd represents a phrase within a larger
25704 ** SQL statement. Make a copy of this phrase in space obtained form
25705 ** sqlite3DbMalloc(). Omit leading and trailing whitespace.
25706 */
25707 SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
25708 int n;
25709 while( sqlite3Isspace(zStart[0]) ) zStart++;
25710 n = (int)(zEnd - zStart);
25711 while( n>0 && sqlite3Isspace(zStart[n-1]) ) n--;
25712 return sqlite3DbStrNDup(db, zStart, n);
25713 }
25714
25715 /*
25716 ** Free any prior content in *pz and replace it with a copy of zNew.
25717 */
25718 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
@@ -27373,16 +27415,24 @@
27415 }else{
27416 int i;
27417 sqlite3TreeViewLine(pView, "%s", zLabel);
27418 for(i=0; i<pList->nExpr; i++){
27419 int j = pList->a[i].u.x.iOrderByCol;
27420 char *zName = pList->a[i].zName;
27421 if( j || zName ){
27422 sqlite3TreeViewPush(pView, 0);
27423 }
27424 if( zName ){
27425 sqlite3TreeViewLine(pView, "AS %s", zName);
27426 }
27427 if( j ){
27428 sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
27429 }
27430 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
27431 if( j || zName ){
27432 sqlite3TreeViewPop(pView);
27433 }
27434 }
27435 }
27436 }
27437 SQLITE_PRIVATE void sqlite3TreeViewExprList(
27438 TreeView *pView,
@@ -28667,10 +28717,28 @@
28717 a = (unsigned char *)zLeft;
28718 b = (unsigned char *)zRight;
28719 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
28720 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
28721 }
28722
28723 /*
28724 ** Compute 10 to the E-th power. Examples: E==1 results in 10.
28725 ** E==2 results in 100. E==50 results in 1.0e50.
28726 **
28727 ** This routine only works for values of E between 1 and 341.
28728 */
28729 static LONGDOUBLE_TYPE sqlite3Pow10(int E){
28730 LONGDOUBLE_TYPE x = 10.0;
28731 LONGDOUBLE_TYPE r = 1.0;
28732 while(1){
28733 if( E & 1 ) r *= x;
28734 E >>= 1;
28735 if( E==0 ) break;
28736 x *= x;
28737 }
28738 return r;
28739 }
28740
28741 /*
28742 ** The string z[] is an text representation of a real number.
28743 ** Convert this string to a double and write it into *pResult.
28744 **
@@ -28823,15 +28891,14 @@
28891 s = sign<0 ? -s : s;
28892
28893 if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/
28894 result = (double)s;
28895 }else{
 
28896 /* attempt to handle extremely small/large numbers better */
28897 if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/
28898 if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/
28899 LONGDOUBLE_TYPE scale = sqlite3Pow10(e-308);
28900 if( esign<0 ){
28901 result = s / scale;
28902 result /= 1.0e+308;
28903 }else{
28904 result = s * scale;
@@ -28847,14 +28914,11 @@
28914 result = 1e308*1e308*s; /* Infinity */
28915 #endif
28916 }
28917 }
28918 }else{
28919 LONGDOUBLE_TYPE scale = sqlite3Pow10(e);
 
 
 
28920 if( esign<0 ){
28921 result = s / scale;
28922 }else{
28923 result = s * scale;
28924 }
@@ -30308,82 +30372,84 @@
30372 /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
30373 /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
30374 /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
30375 /* 94 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
30376 /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
30377 /* 96 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
30378 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
30379 /* 98 */ "Column" OpHelp("r[P3]=PX"),
30380 /* 99 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
30381 /* 100 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
30382 /* 101 */ "Count" OpHelp("r[P2]=count()"),
30383 /* 102 */ "ReadCookie" OpHelp(""),
30384 /* 103 */ "SetCookie" OpHelp(""),
30385 /* 104 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
30386 /* 105 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
30387 /* 106 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
30388 /* 107 */ "OpenDup" OpHelp(""),
30389 /* 108 */ "OpenAutoindex" OpHelp("nColumn=P2"),
30390 /* 109 */ "OpenEphemeral" OpHelp("nColumn=P2"),
30391 /* 110 */ "SorterOpen" OpHelp(""),
30392 /* 111 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
30393 /* 112 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
30394 /* 113 */ "Close" OpHelp(""),
30395 /* 114 */ "ColumnsUsed" OpHelp(""),
30396 /* 115 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
30397 /* 116 */ "NewRowid" OpHelp("r[P2]=rowid"),
30398 /* 117 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
30399 /* 118 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
30400 /* 119 */ "Delete" OpHelp(""),
30401 /* 120 */ "ResetCount" OpHelp(""),
30402 /* 121 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30403 /* 122 */ "SorterData" OpHelp("r[P2]=data"),
30404 /* 123 */ "RowData" OpHelp("r[P2]=data"),
30405 /* 124 */ "Rowid" OpHelp("r[P2]=rowid"),
30406 /* 125 */ "NullRow" OpHelp(""),
30407 /* 126 */ "SeekEnd" OpHelp(""),
30408 /* 127 */ "SorterInsert" OpHelp("key=r[P2]"),
30409 /* 128 */ "IdxInsert" OpHelp("key=r[P2]"),
30410 /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30411 /* 130 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30412 /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30413 /* 132 */ "Real" OpHelp("r[P2]=P4"),
30414 /* 133 */ "Destroy" OpHelp(""),
30415 /* 134 */ "Clear" OpHelp(""),
30416 /* 135 */ "ResetSorter" OpHelp(""),
30417 /* 136 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
30418 /* 137 */ "SqlExec" OpHelp(""),
30419 /* 138 */ "ParseSchema" OpHelp(""),
30420 /* 139 */ "LoadAnalysis" OpHelp(""),
30421 /* 140 */ "DropTable" OpHelp(""),
30422 /* 141 */ "DropIndex" OpHelp(""),
30423 /* 142 */ "DropTrigger" OpHelp(""),
30424 /* 143 */ "IntegrityCk" OpHelp(""),
30425 /* 144 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
30426 /* 145 */ "Param" OpHelp(""),
30427 /* 146 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
30428 /* 147 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
30429 /* 148 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
30430 /* 149 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
30431 /* 150 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
30432 /* 151 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
30433 /* 152 */ "Expire" OpHelp(""),
30434 /* 153 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
30435 /* 154 */ "VBegin" OpHelp(""),
30436 /* 155 */ "VCreate" OpHelp(""),
30437 /* 156 */ "VDestroy" OpHelp(""),
30438 /* 157 */ "VOpen" OpHelp(""),
30439 /* 158 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
30440 /* 159 */ "VRename" OpHelp(""),
30441 /* 160 */ "Pagecount" OpHelp(""),
30442 /* 161 */ "MaxPgcnt" OpHelp(""),
30443 /* 162 */ "PureFunc0" OpHelp(""),
30444 /* 163 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
30445 /* 164 */ "PureFunc" OpHelp(""),
30446 /* 165 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
30447 /* 166 */ "Trace" OpHelp(""),
30448 /* 167 */ "CursorHint" OpHelp(""),
30449 /* 168 */ "Noop" OpHelp(""),
30450 /* 169 */ "Explain" OpHelp(""),
30451 };
30452 return azName[i];
30453 }
30454 #endif
30455
@@ -53382,11 +53448,11 @@
53448 if( pPager->eState>PAGER_READER || pPager->tempFile ){
53449 pPg = sqlite3PagerLookup(pPager, pgno);
53450 }
53451 if( pPg==0 ){
53452 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
53453 }else{
53454 sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
53455 }
53456 if( pPg ){
53457 assert( rc==SQLITE_OK );
53458 *ppPage = pPg;
@@ -64672,10 +64738,24 @@
64738 assert( pCur->curIntKey );
64739 getCellInfo(pCur);
64740 return pCur->info.nKey;
64741 }
64742
64743 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
64744 /*
64745 ** Return the offset into the database file for the start of the
64746 ** payload to which the cursor is pointing.
64747 */
64748 SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor *pCur){
64749 assert( cursorHoldsMutex(pCur) );
64750 assert( pCur->eState==CURSOR_VALID );
64751 getCellInfo(pCur);
64752 return (i64)pCur->pBt->pageSize*((i64)pCur->pPage->pgno - 1) +
64753 (i64)(pCur->info.pPayload - pCur->pPage->aData);
64754 }
64755 #endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */
64756
64757 /*
64758 ** Return the number of bytes of payload for the entry that pCur is
64759 ** currently pointing to. For table btrees, this will be the amount
64760 ** of data. For index btrees, this will be the size of the key.
64761 **
@@ -72430,11 +72510,14 @@
72510
72511 *ppVal = pVal;
72512 return rc;
72513
72514 no_mem:
72515 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
72516 if( pCtx==0 || pCtx->pParse->nErr==0 )
72517 #endif
72518 sqlite3OomFault(db);
72519 sqlite3DbFree(db, zVal);
72520 assert( *ppVal==0 );
72521 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
72522 if( pCtx==0 ) sqlite3ValueFree(pVal);
72523 #else
@@ -74416,10 +74499,12 @@
74499 Mem *pSub = 0; /* Memory cell hold array of subprogs */
74500 sqlite3 *db = p->db; /* The database connection */
74501 int i; /* Loop counter */
74502 int rc = SQLITE_OK; /* Return code */
74503 Mem *pMem = &p->aMem[1]; /* First Mem of result set */
74504 int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0);
74505 Op *pOp = 0;
74506
74507 assert( p->explain );
74508 assert( p->magic==VDBE_MAGIC_RUN );
74509 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
74510
@@ -74428,11 +74513,11 @@
74513 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
74514 */
74515 releaseMemArray(pMem, 8);
74516 p->pResultSet = 0;
74517
74518 if( p->rc==SQLITE_NOMEM ){
74519 /* This happens if a malloc() inside a call to sqlite3_column_text() or
74520 ** sqlite3_column_text16() failed. */
74521 sqlite3OomFault(db);
74522 return SQLITE_ERROR;
74523 }
@@ -74443,11 +74528,11 @@
74528 ** the sum of the number of rows in all trigger subprograms encountered
74529 ** so far. The nRow value will increase as new trigger subprograms are
74530 ** encountered, but p->pc will eventually catch up to nRow.
74531 */
74532 nRow = p->nOp;
74533 if( bListSubprogs ){
74534 /* The first 8 memory cells are used for the result set. So we will
74535 ** commandeer the 9th cell to use as storage for an array of pointers
74536 ** to trigger subprograms. The VDBE is guaranteed to have at least 9
74537 ** cells. */
74538 assert( p->nMem>9 );
@@ -74463,21 +74548,15 @@
74548 }
74549 }
74550
74551 do{
74552 i = p->pc++;
74553 if( i>=nRow ){
74554 p->rc = SQLITE_OK;
74555 rc = SQLITE_DONE;
74556 break;
74557 }
 
 
 
 
 
 
74558 if( i<p->nOp ){
74559 /* The output line number is small enough that we are still in the
74560 ** main program. */
74561 pOp = &p->aOp[i];
74562 }else{
@@ -74488,98 +74567,114 @@
74567 for(j=0; i>=apSub[j]->nOp; j++){
74568 i -= apSub[j]->nOp;
74569 }
74570 pOp = &apSub[j]->aOp[i];
74571 }
74572
74573 /* When an OP_Program opcode is encounter (the only opcode that has
74574 ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
74575 ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
74576 ** has not already been seen.
74577 */
74578 if( bListSubprogs && pOp->p4type==P4_SUBPROGRAM ){
74579 int nByte = (nSub+1)*sizeof(SubProgram*);
74580 int j;
74581 for(j=0; j<nSub; j++){
74582 if( apSub[j]==pOp->p4.pProgram ) break;
74583 }
74584 if( j==nSub ){
74585 p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0);
74586 if( p->rc!=SQLITE_OK ){
74587 rc = SQLITE_ERROR;
74588 break;
74589 }
74590 apSub = (SubProgram **)pSub->z;
74591 apSub[nSub++] = pOp->p4.pProgram;
74592 pSub->flags |= MEM_Blob;
74593 pSub->n = nSub*sizeof(SubProgram*);
74594 nRow += pOp->p4.pProgram->nOp;
74595 }
74596 }
74597 }while( p->explain==2 && pOp->opcode!=OP_Explain );
74598
74599 if( rc==SQLITE_OK ){
74600 if( db->u1.isInterrupted ){
74601 p->rc = SQLITE_INTERRUPT;
74602 rc = SQLITE_ERROR;
74603 sqlite3VdbeError(p, sqlite3ErrStr(p->rc));
74604 }else{
74605 char *zP4;
74606 if( p->explain==1 ){
74607 pMem->flags = MEM_Int;
74608 pMem->u.i = i; /* Program counter */
74609 pMem++;
74610
74611 pMem->flags = MEM_Static|MEM_Str|MEM_Term;
74612 pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
74613 assert( pMem->z!=0 );
74614 pMem->n = sqlite3Strlen30(pMem->z);
74615 pMem->enc = SQLITE_UTF8;
74616 pMem++;
74617 }
74618
74619 pMem->flags = MEM_Int;
74620 pMem->u.i = pOp->p1; /* P1 */
74621 pMem++;
74622
74623 pMem->flags = MEM_Int;
74624 pMem->u.i = pOp->p2; /* P2 */
74625 pMem++;
74626
74627 pMem->flags = MEM_Int;
74628 pMem->u.i = pOp->p3; /* P3 */
74629 pMem++;
74630
74631 if( sqlite3VdbeMemClearAndResize(pMem, 100) ){ /* P4 */
74632 assert( p->db->mallocFailed );
74633 return SQLITE_ERROR;
74634 }
74635 pMem->flags = MEM_Str|MEM_Term;
74636 zP4 = displayP4(pOp, pMem->z, pMem->szMalloc);
74637 if( zP4!=pMem->z ){
74638 pMem->n = 0;
74639 sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
74640 }else{
74641 assert( pMem->z!=0 );
74642 pMem->n = sqlite3Strlen30(pMem->z);
74643 pMem->enc = SQLITE_UTF8;
74644 }
74645 pMem++;
74646
74647 if( p->explain==1 ){
74648 if( sqlite3VdbeMemClearAndResize(pMem, 4) ){
74649 assert( p->db->mallocFailed );
74650 return SQLITE_ERROR;
74651 }
74652 pMem->flags = MEM_Str|MEM_Term;
74653 pMem->n = 2;
74654 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
74655 pMem->enc = SQLITE_UTF8;
74656 pMem++;
74657
74658 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
74659 if( sqlite3VdbeMemClearAndResize(pMem, 500) ){
74660 assert( p->db->mallocFailed );
74661 return SQLITE_ERROR;
74662 }
74663 pMem->flags = MEM_Str|MEM_Term;
74664 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
74665 pMem->enc = SQLITE_UTF8;
74666 #else
74667 pMem->flags = MEM_Null; /* Comment */
74668 #endif
74669 }
74670
74671 p->nResColumn = 8 - 4*(p->explain-1);
74672 p->pResultSet = &p->aMem[1];
74673 p->rc = SQLITE_OK;
74674 rc = SQLITE_ROW;
74675 }
74676 }
74677 return rc;
74678 }
74679 #endif /* SQLITE_OMIT_EXPLAIN */
74680
@@ -82102,10 +82197,40 @@
82197 goto jump_to_p2;
82198 }
82199 break;
82200 }
82201
82202 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
82203 /* Opcode: Offset P1 P2 P3 * *
82204 ** Synopsis: r[P3] = sqlite_offset(P1)
82205 **
82206 ** Store in register r[P3] the byte offset into the database file that is the
82207 ** start of the payload for the record at which that cursor P1 is currently
82208 ** pointing.
82209 **
82210 ** P2 is the column number for the argument to the sqlite_offset() function.
82211 ** This opcode does not use P2 itself, but the P2 value is used by the
82212 ** code generator. The P1, P2, and P3 operands to this opcode are the
82213 ** as as for OP_Column.
82214 **
82215 ** This opcode is only available if SQLite is compiled with the
82216 ** -DSQLITE_ENABLE_OFFSET_SQL_FUNC option.
82217 */
82218 case OP_Offset: { /* out3 */
82219 VdbeCursor *pC; /* The VDBE cursor */
82220 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
82221 pC = p->apCsr[pOp->p1];
82222 pOut = &p->aMem[pOp->p3];
82223 if( NEVER(pC==0) || pC->eCurType!=CURTYPE_BTREE ){
82224 sqlite3VdbeMemSetNull(pOut);
82225 }else{
82226 sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor));
82227 }
82228 break;
82229 }
82230 #endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */
82231
82232 /* Opcode: Column P1 P2 P3 P4 P5
82233 ** Synopsis: r[P3]=PX
82234 **
82235 ** Interpret the data that cursor P1 points to as a structure built using
82236 ** the MakeRecord instruction. (See the MakeRecord opcode for additional
@@ -86769,11 +86894,17 @@
86894 REGISTER_TRACE(pOp->p3, pOut);
86895 UPDATE_MAX_BLOBSIZE(pOut);
86896 break;
86897 }
86898
86899 /* Opcode: Trace P1 P2 * P4 *
86900 **
86901 ** Write P4 on the statement trace output if statement tracing is
86902 ** enabled.
86903 **
86904 ** Operand P1 must be 0x7fffffff and P2 must positive.
86905 */
86906 /* Opcode: Init P1 P2 P3 P4 *
86907 ** Synopsis: Start at P2
86908 **
86909 ** Programs contain a single instance of this opcode as the very first
86910 ** opcode.
@@ -86788,10 +86919,11 @@
86919 ** first time they are evaluated for this run.
86920 **
86921 ** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
86922 ** error is encountered.
86923 */
86924 case OP_Trace:
86925 case OP_Init: { /* jump */
86926 char *zTrace;
86927 int i;
86928
86929 /* If the P4 argument is not NULL, then it must be an SQL comment string.
@@ -86802,11 +86934,13 @@
86934 ** would have been returned by the legacy sqlite3_trace() interface by
86935 ** using the X argument when X begins with "--" and invoking
86936 ** sqlite3_expanded_sql(P) otherwise.
86937 */
86938 assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
86939
86940 /* OP_Init is always instruction 0 */
86941 assert( pOp==p->aOp || pOp->opcode==OP_Trace );
86942
86943 #ifndef SQLITE_OMIT_TRACE
86944 if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
86945 && !p->doingRerun
86946 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
@@ -86845,10 +86979,11 @@
86979 }
86980 #endif /* SQLITE_DEBUG */
86981 #endif /* SQLITE_OMIT_TRACE */
86982 assert( pOp->p2>0 );
86983 if( pOp->p1>=sqlite3GlobalConfig.iOnceResetThreshold ){
86984 if( pOp->opcode==OP_Trace ) break;
86985 for(i=1; i<p->nOp; i++){
86986 if( p->aOp[i].opcode==OP_Once ) p->aOp[i].p1 = 0;
86987 }
86988 pOp->p1 = 0;
86989 }
@@ -94048,21 +94183,20 @@
94183 ** is set.
94184 */
94185 SQLITE_PRIVATE void sqlite3ExprListSetSpan(
94186 Parse *pParse, /* Parsing context */
94187 ExprList *pList, /* List to which to add the span. */
94188 const char *zStart, /* Start of the span */
94189 const char *zEnd /* End of the span */
94190 ){
94191 sqlite3 *db = pParse->db;
94192 assert( pList!=0 || db->mallocFailed!=0 );
94193 if( pList ){
94194 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
94195 assert( pList->nExpr>0 );
 
94196 sqlite3DbFree(db, pItem->zSpan);
94197 pItem->zSpan = sqlite3DbSpanDup(db, zStart, zEnd);
 
94198 }
94199 }
94200
94201 /*
94202 ** If the expression list pEList contains more than iLimit elements,
@@ -96265,13 +96399,25 @@
96399 #endif
96400 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
96401 if( !pColl ) pColl = db->pDfltColl;
96402 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
96403 }
96404 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
96405 if( pDef->funcFlags & SQLITE_FUNC_OFFSET ){
96406 Expr *pArg = pFarg->a[0].pExpr;
96407 if( pArg->op==TK_COLUMN ){
96408 sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
96409 }else{
96410 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
96411 }
96412 }else
96413 #endif
96414 {
96415 sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0,
96416 constMask, r1, target, (char*)pDef, P4_FUNCDEF);
96417 sqlite3VdbeChangeP5(v, (u8)nFarg);
96418 }
96419 if( nFarg && constMask==0 ){
96420 sqlite3ReleaseTempRange(pParse, r1, nFarg);
96421 }
96422 return target;
96423 }
@@ -102511,38 +102657,41 @@
102657 ** is not the case.
102658 **
102659 ** This routine is called by the parser while in the middle of
102660 ** parsing a CREATE TABLE statement.
102661 */
102662 SQLITE_PRIVATE void sqlite3AddDefaultValue(
102663 Parse *pParse, /* Parsing context */
102664 Expr *pExpr, /* The parsed expression of the default value */
102665 const char *zStart, /* Start of the default value text */
102666 const char *zEnd /* First character past end of defaut value text */
102667 ){
102668 Table *p;
102669 Column *pCol;
102670 sqlite3 *db = pParse->db;
102671 p = pParse->pNewTable;
102672 if( p!=0 ){
102673 pCol = &(p->aCol[p->nCol-1]);
102674 if( !sqlite3ExprIsConstantOrFunction(pExpr, db->init.busy) ){
102675 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
102676 pCol->zName);
102677 }else{
102678 /* A copy of pExpr is used instead of the original, as pExpr contains
102679 ** tokens that point to volatile memory.
 
102680 */
102681 Expr x;
102682 sqlite3ExprDelete(db, pCol->pDflt);
102683 memset(&x, 0, sizeof(x));
102684 x.op = TK_SPAN;
102685 x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd);
102686 x.pLeft = pExpr;
 
102687 x.flags = EP_Skip;
102688 pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
102689 sqlite3DbFree(db, x.u.zToken);
102690 }
102691 }
102692 sqlite3ExprDelete(db, pExpr);
102693 }
102694
102695 /*
102696 ** Backwards Compatibility Hack:
102697 **
@@ -103255,23 +103404,24 @@
103404 sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
103405 sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
103406 pParse->nTab = 2;
103407 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
103408 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
 
 
 
 
103409 if( pParse->nErr ) return;
103410 pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect);
103411 if( pSelTab==0 ) return;
103412 assert( p->aCol==0 );
103413 p->nCol = pSelTab->nCol;
103414 p->aCol = pSelTab->aCol;
103415 pSelTab->nCol = 0;
103416 pSelTab->aCol = 0;
103417 sqlite3DeleteTable(db, pSelTab);
103418 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
103419 sqlite3Select(pParse, pSelect, &dest);
103420 if( pParse->nErr ) return;
103421 sqlite3VdbeEndCoroutine(v, regYield);
103422 sqlite3VdbeJumpHere(v, addrTop - 1);
103423 addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
103424 VdbeCoverage(v);
103425 sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
103426 sqlite3TableAffinity(v, p, 0);
103427 sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
@@ -108980,10 +109130,14 @@
109130 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
109131 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
109132 #ifdef SQLITE_DEBUG
109133 FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY),
109134 #endif
109135 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
109136 FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET|
109137 SQLITE_FUNC_TYPEOF),
109138 #endif
109139 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
109140 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
109141 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
109142 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
109143 FUNCTION(trim, 1, 3, 0, trimFunc ),
@@ -112072,10 +112226,11 @@
112226 sqlite3VdbeResolveLabel(v, addrUniqueOk);
112227 continue;
112228 }
112229
112230 /* Check to see if the new index entry will be unique */
112231 sqlite3ExprCachePush(pParse);
112232 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
112233 regIdx, pIdx->nKeyCol); VdbeCoverage(v);
112234
112235 /* Generate code to handle collisions */
112236 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
@@ -112160,10 +112315,11 @@
112315 seenReplace = 1;
112316 break;
112317 }
112318 }
112319 sqlite3VdbeResolveLabel(v, addrUniqueOk);
112320 sqlite3ExprCachePop(pParse);
112321 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
112322 }
112323 if( ipkTop ){
112324 sqlite3VdbeGoto(v, ipkTop+1);
112325 sqlite3VdbeJumpHere(v, ipkBottom);
@@ -113985,12 +114141,14 @@
114141
114142 handle = sqlite3OsDlOpen(pVfs, zFile);
114143 #if SQLITE_OS_UNIX || SQLITE_OS_WIN
114144 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
114145 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
114146 int bExists = 0;
114147 if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
114148 sqlite3OsAccess(pVfs, zAltFile, SQLITE_ACCESS_EXISTS, &bExists);
114149 if( bExists ) handle = sqlite3OsDlOpen(pVfs, zAltFile);
114150 sqlite3_free(zAltFile);
114151 }
114152 #endif
114153 if( handle==0 ){
114154 if( pzErrMsg ){
@@ -116022,10 +116180,11 @@
116180 ** cid: Column id (numbered from left to right, starting at 0)
116181 ** name: Column name
116182 ** type: Column declaration type.
116183 ** notnull: True if 'NOT NULL' is part of column declaration
116184 ** dflt_value: The default value for the column, if any.
116185 ** pk: Non-zero for PK fields.
116186 */
116187 case PragTyp_TABLE_INFO: if( zRight ){
116188 Table *pTab;
116189 pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
116190 if( pTab ){
@@ -119715,22 +119874,21 @@
119874 char const *zOrigCol = 0;
119875 #endif
119876
119877 assert( pExpr!=0 );
119878 assert( pNC->pSrcList!=0 );
119879 assert( pExpr->op!=TK_AGG_COLUMN ); /* This routine runes before aggregates
119880 ** are processed */
119881 switch( pExpr->op ){
 
119882 case TK_COLUMN: {
119883 /* The expression is a column. Locate the table the column is being
119884 ** extracted from in NameContext.pSrcList. This table may be real
119885 ** database table or a subquery.
119886 */
119887 Table *pTab = 0; /* Table structure column is extracted from */
119888 Select *pS = 0; /* Select the column is extracted from */
119889 int iCol = pExpr->iColumn; /* Index of column in pTab */
 
 
119890 while( pNC && !pTab ){
119891 SrcList *pTabList = pNC->pSrcList;
119892 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
119893 if( j<pTabList->nSrc ){
119894 pTab = pTabList->a[j].pTab;
@@ -119930,10 +120088,11 @@
120088 #endif
120089
120090 if( pParse->colNamesSet || db->mallocFailed ) return;
120091 /* Column names are determined by the left-most term of a compound select */
120092 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
120093 SELECTTRACE(1,pParse,pSelect,("generating column names\n"));
120094 pTabList = pSelect->pSrc;
120095 pEList = pSelect->pEList;
120096 assert( v!=0 );
120097 assert( pTabList!=0 );
120098 pParse->colNamesSet = 1;
@@ -120038,16 +120197,16 @@
120197 Expr *pColExpr = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
120198 while( pColExpr->op==TK_DOT ){
120199 pColExpr = pColExpr->pRight;
120200 assert( pColExpr!=0 );
120201 }
120202 assert( pColExpr->op!=TK_AGG_COLUMN );
120203 if( pColExpr->op==TK_COLUMN ){
 
120204 /* For columns use the column name name */
120205 int iCol = pColExpr->iColumn;
120206 Table *pTab = pColExpr->pTab;
120207 assert( pTab!=0 );
120208 if( iCol<0 ) iCol = pTab->iPKey;
120209 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
120210 }else if( pColExpr->op==TK_ID ){
120211 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
120212 zName = pColExpr->u.zToken;
@@ -124606,10 +124765,11 @@
124765
124766 sqlite3ExprDelete(db, pTmp->pWhere);
124767 sqlite3ExprListDelete(db, pTmp->pExprList);
124768 sqlite3SelectDelete(db, pTmp->pSelect);
124769 sqlite3IdListDelete(db, pTmp->pIdList);
124770 sqlite3DbFree(db, pTmp->zSpan);
124771
124772 sqlite3DbFree(db, pTmp);
124773 }
124774 }
124775
@@ -124920,26 +125080,43 @@
125080 sqlite3DeleteTrigger(db, pTrig);
125081 assert( !pParse->pNewTrigger );
125082 sqlite3DeleteTriggerStep(db, pStepList);
125083 }
125084
125085 /*
125086 ** Duplicate a range of text from an SQL statement, then convert all
125087 ** whitespace characters into ordinary space characters.
125088 */
125089 static char *triggerSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
125090 char *z = sqlite3DbSpanDup(db, zStart, zEnd);
125091 int i;
125092 if( z ) for(i=0; z[i]; i++) if( sqlite3Isspace(z[i]) ) z[i] = ' ';
125093 return z;
125094 }
125095
125096 /*
125097 ** Turn a SELECT statement (that the pSelect parameter points to) into
125098 ** a trigger step. Return a pointer to a TriggerStep structure.
125099 **
125100 ** The parser calls this routine when it finds a SELECT statement in
125101 ** body of a TRIGGER.
125102 */
125103 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(
125104 sqlite3 *db, /* Database connection */
125105 Select *pSelect, /* The SELECT statement */
125106 const char *zStart, /* Start of SQL text */
125107 const char *zEnd /* End of SQL text */
125108 ){
125109 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
125110 if( pTriggerStep==0 ) {
125111 sqlite3SelectDelete(db, pSelect);
125112 return 0;
125113 }
125114 pTriggerStep->op = TK_SELECT;
125115 pTriggerStep->pSelect = pSelect;
125116 pTriggerStep->orconf = OE_Default;
125117 pTriggerStep->zSpan = triggerSpanDup(db, zStart, zEnd);
125118 return pTriggerStep;
125119 }
125120
125121 /*
125122 ** Allocate space to hold a new trigger step. The allocated space
@@ -124948,11 +125125,13 @@
125125 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
125126 */
125127 static TriggerStep *triggerStepAllocate(
125128 sqlite3 *db, /* Database connection */
125129 u8 op, /* Trigger opcode */
125130 Token *pName, /* The target name */
125131 const char *zStart, /* Start of SQL text */
125132 const char *zEnd /* End of SQL text */
125133 ){
125134 TriggerStep *pTriggerStep;
125135
125136 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
125137 if( pTriggerStep ){
@@ -124959,10 +125138,11 @@
125138 char *z = (char*)&pTriggerStep[1];
125139 memcpy(z, pName->z, pName->n);
125140 sqlite3Dequote(z);
125141 pTriggerStep->zTarget = z;
125142 pTriggerStep->op = op;
125143 pTriggerStep->zSpan = triggerSpanDup(db, zStart, zEnd);
125144 }
125145 return pTriggerStep;
125146 }
125147
125148 /*
@@ -124975,17 +125155,19 @@
125155 SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(
125156 sqlite3 *db, /* The database connection */
125157 Token *pTableName, /* Name of the table into which we insert */
125158 IdList *pColumn, /* List of columns in pTableName to insert into */
125159 Select *pSelect, /* A SELECT statement that supplies values */
125160 u8 orconf, /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
125161 const char *zStart, /* Start of SQL text */
125162 const char *zEnd /* End of SQL text */
125163 ){
125164 TriggerStep *pTriggerStep;
125165
125166 assert(pSelect != 0 || db->mallocFailed);
125167
125168 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName, zStart, zEnd);
125169 if( pTriggerStep ){
125170 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
125171 pTriggerStep->pIdList = pColumn;
125172 pTriggerStep->orconf = orconf;
125173 }else{
@@ -125004,15 +125186,17 @@
125186 SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(
125187 sqlite3 *db, /* The database connection */
125188 Token *pTableName, /* Name of the table to be updated */
125189 ExprList *pEList, /* The SET clause: list of column and new values */
125190 Expr *pWhere, /* The WHERE clause */
125191 u8 orconf, /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
125192 const char *zStart, /* Start of SQL text */
125193 const char *zEnd /* End of SQL text */
125194 ){
125195 TriggerStep *pTriggerStep;
125196
125197 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName, zStart, zEnd);
125198 if( pTriggerStep ){
125199 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
125200 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
125201 pTriggerStep->orconf = orconf;
125202 }
@@ -125027,15 +125211,17 @@
125211 ** sees a DELETE statement inside the body of a CREATE TRIGGER.
125212 */
125213 SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(
125214 sqlite3 *db, /* Database connection */
125215 Token *pTableName, /* The table from which rows are deleted */
125216 Expr *pWhere, /* The WHERE clause */
125217 const char *zStart, /* Start of SQL text */
125218 const char *zEnd /* End of SQL text */
125219 ){
125220 TriggerStep *pTriggerStep;
125221
125222 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName, zStart, zEnd);
125223 if( pTriggerStep ){
125224 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
125225 pTriggerStep->orconf = OE_Default;
125226 }
125227 sqlite3ExprDelete(db, pWhere);
@@ -125285,10 +125471,18 @@
125471 ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
125472 ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
125473 */
125474 pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
125475 assert( pParse->okConstFactor==0 );
125476
125477 #ifndef SQLITE_OMIT_TRACE
125478 if( pStep->zSpan ){
125479 sqlite3VdbeAddOp4(v, OP_Trace, 0x7fffffff, 1, 0,
125480 sqlite3MPrintf(db, "-- %s", pStep->zSpan),
125481 P4_DYNAMIC);
125482 }
125483 #endif
125484
125485 switch( pStep->op ){
125486 case TK_UPDATE: {
125487 sqlite3Update(pParse,
125488 targetSrcList(pParse, pStep),
@@ -125426,13 +125620,15 @@
125620 (pTrigger->op==TK_INSERT ? "INSERT" : ""),
125621 (pTrigger->op==TK_DELETE ? "DELETE" : ""),
125622 pTab->zName
125623 ));
125624 #ifndef SQLITE_OMIT_TRACE
125625 if( pTrigger->zName ){
125626 sqlite3VdbeChangeP4(v, -1,
125627 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
125628 );
125629 }
125630 #endif
125631
125632 /* If one was specified, code the WHEN clause. If it evaluates to false
125633 ** (or NULL) the sub-vdbe is immediately halted by jumping to the
125634 ** OP_Halt inserted at the end of the program. */
@@ -128896,11 +129092,11 @@
129092 int iFrom, /* Value for "from" column of output */
129093 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
129094 ){
129095 int ret = 0;
129096 #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
129097 if( sqlite3ParseToplevel(pParse)->explain==2 )
129098 #endif
129099 {
129100 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
129101 Vdbe *v = pParse->pVdbe; /* VM being constructed */
129102 sqlite3 *db = pParse->db; /* Database handle */
@@ -132526,10 +132722,25 @@
132722 ** so is applicable. Because this module is responsible for selecting
132723 ** indices, you might also think of this module as the "query optimizer".
132724 */
132725 /* #include "sqliteInt.h" */
132726 /* #include "whereInt.h" */
132727
132728 /*
132729 ** Extra information appended to the end of sqlite3_index_info but not
132730 ** visible to the xBestIndex function, at least not directly. The
132731 ** sqlite3_vtab_collation() interface knows how to reach it, however.
132732 **
132733 ** This object is not an API and can be changed from one release to the
132734 ** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()
132735 ** agree on the structure, all will be well.
132736 */
132737 typedef struct HiddenIndexInfo HiddenIndexInfo;
132738 struct HiddenIndexInfo {
132739 WhereClause *pWC; /* The Where clause being analyzed */
132740 Parse *pParse; /* The parsing context */
132741 };
132742
132743 /* Forward declaration of methods */
132744 static int whereLoopResize(sqlite3*, WhereLoop*, int);
132745
132746 /* Test variable that can be set to enable WHERE tracing */
@@ -133349,22 +133560,23 @@
133560 ** Allocate and populate an sqlite3_index_info structure. It is the
133561 ** responsibility of the caller to eventually release the structure
133562 ** by passing the pointer returned by this function to sqlite3_free().
133563 */
133564 static sqlite3_index_info *allocateIndexInfo(
133565 Parse *pParse, /* The parsing context */
133566 WhereClause *pWC, /* The WHERE clause being analyzed */
133567 Bitmask mUnusable, /* Ignore terms with these prereqs */
133568 struct SrcList_item *pSrc, /* The FROM clause term that is the vtab */
133569 ExprList *pOrderBy, /* The ORDER BY clause */
133570 u16 *pmNoOmit /* Mask of terms not to omit */
133571 ){
133572 int i, j;
133573 int nTerm;
133574 struct sqlite3_index_constraint *pIdxCons;
133575 struct sqlite3_index_orderby *pIdxOrderBy;
133576 struct sqlite3_index_constraint_usage *pUsage;
133577 struct HiddenIndexInfo *pHidden;
133578 WhereTerm *pTerm;
133579 int nOrderBy;
133580 sqlite3_index_info *pIdxInfo;
133581 u16 mNoOmit = 0;
133582
@@ -133402,11 +133614,11 @@
133614
133615 /* Allocate the sqlite3_index_info structure
133616 */
133617 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
133618 + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
133619 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
133620 if( pIdxInfo==0 ){
133621 sqlite3ErrorMsg(pParse, "out of memory");
133622 return 0;
133623 }
133624
@@ -133413,20 +133625,23 @@
133625 /* Initialize the structure. The sqlite3_index_info structure contains
133626 ** many fields that are declared "const" to prevent xBestIndex from
133627 ** changing them. We have to do some funky casting in order to
133628 ** initialize those fields.
133629 */
133630 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
133631 pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
133632 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
133633 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
133634 *(int*)&pIdxInfo->nConstraint = nTerm;
133635 *(int*)&pIdxInfo->nOrderBy = nOrderBy;
133636 *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
133637 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
133638 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
133639 pUsage;
133640
133641 pHidden->pWC = pWC;
133642 pHidden->pParse = pParse;
133643 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
133644 u16 op;
133645 if( pTerm->leftCursor != pSrc->iCursor ) continue;
133646 if( pTerm->prereqRight & mUnusable ) continue;
133647 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
@@ -135646,10 +135861,31 @@
135861 (sqlite3_uint64)(pNew->prereq & ~mPrereq)));
135862
135863 return rc;
135864 }
135865
135866 /*
135867 ** If this function is invoked from within an xBestIndex() callback, it
135868 ** returns a pointer to a buffer containing the name of the collation
135869 ** sequence associated with element iCons of the sqlite3_index_info.aConstraint
135870 ** array. Or, if iCons is out of range or there is no active xBestIndex
135871 ** call, return NULL.
135872 */
135873 SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info *pIdxInfo, int iCons){
135874 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
135875 const char *zRet = 0;
135876 if( iCons>=0 && iCons<pIdxInfo->nConstraint ){
135877 CollSeq *pC = 0;
135878 int iTerm = pIdxInfo->aConstraint[iCons].iTermOffset;
135879 Expr *pX = pHidden->pWC->a[iTerm].pExpr;
135880 if( pX->pLeft ){
135881 pC = sqlite3BinaryCompareCollSeq(pHidden->pParse, pX->pLeft, pX->pRight);
135882 }
135883 zRet = (pC ? pC->zName : "BINARY");
135884 }
135885 return zRet;
135886 }
135887
135888 /*
135889 ** Add all WhereLoop objects for a table of the join identified by
135890 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
135891 **
@@ -137614,11 +137850,15 @@
137850 last = sqlite3VdbeCurrentAddr(v);
137851 k = pLevel->addrBody;
137852 pOp = sqlite3VdbeGetOp(v, k);
137853 for(; k<last; k++, pOp++){
137854 if( pOp->p1!=pLevel->iTabCur ) continue;
137855 if( pOp->opcode==OP_Column
137856 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
137857 || pOp->opcode==OP_Offset
137858 #endif
137859 ){
137860 int x = pOp->p2;
137861 assert( pIdx->pTable==pTab );
137862 if( !HasRowid(pTab) ){
137863 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
137864 x = pPk->aiColumn[x];
@@ -137756,24 +137996,16 @@
137996 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
137997 }
137998 }
137999 }
138000
 
 
 
 
 
 
 
 
138001
138002 /* Construct a new Expr object from a single identifier. Use the
138003 ** new Expr to populate pOut. Set the span of pOut to be the identifier
138004 ** that created the expression.
138005 */
138006 static Expr *tokenExpr(Parse *pParse, int op, Token t){
138007 Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
138008 if( p ){
138009 memset(p, 0, sizeof(Expr));
138010 p->op = (u8)op;
138011 p->flags = EP_Leaf;
@@ -137787,48 +138019,12 @@
138019 }
138020 #if SQLITE_MAX_EXPR_DEPTH>0
138021 p->nHeight = 1;
138022 #endif
138023 }
138024 return p;
138025 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138026
138027 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
138028 ** unary TK_ISNULL or TK_NOTNULL expression. */
138029 static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
138030 sqlite3 *db = pParse->db;
@@ -137837,24 +138033,10 @@
138033 sqlite3ExprDelete(db, pA->pRight);
138034 pA->pRight = 0;
138035 }
138036 }
138037
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138038 /* Add a single new term to an ExprList that is used to store a
138039 ** list of identifiers. Report an error if the ID list contains
138040 ** a COLLATE clause or an ASC or DESC keyword, except ignore the
138041 ** error while parsing a legacy schema.
138042 */
@@ -137919,61 +138101,63 @@
138101 ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
138102 ** YYERRORSYMBOL is the code number of the error symbol. If not
138103 ** defined, then do no error processing.
138104 ** YYNSTATE the combined number of states.
138105 ** YYNRULE the number of rules in the grammar
138106 ** YYNTOKEN Number of terminal symbols
138107 ** YY_MAX_SHIFT Maximum value for shift actions
138108 ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
138109 ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
 
 
138110 ** YY_ERROR_ACTION The yy_action[] code for syntax error
138111 ** YY_ACCEPT_ACTION The yy_action[] code for accept
138112 ** YY_NO_ACTION The yy_action[] code for no-op
138113 ** YY_MIN_REDUCE Minimum value for reduce actions
138114 ** YY_MAX_REDUCE Maximum value for reduce actions
138115 */
138116 #ifndef INTERFACE
138117 # define INTERFACE 1
138118 #endif
138119 /************* Begin control #defines *****************************************/
138120 #define YYCODETYPE unsigned char
138121 #define YYNOCODE 253
138122 #define YYACTIONTYPE unsigned short int
138123 #define YYWILDCARD 83
138124 #define sqlite3ParserTOKENTYPE Token
138125 typedef union {
138126 int yyinit;
138127 sqlite3ParserTOKENTYPE yy0;
138128 int yy4;
138129 struct TrigEvent yy90;
138130 TriggerStep* yy203;
138131 struct {int value; int mask;} yy215;
138132 SrcList* yy259;
138133 Expr* yy314;
138134 ExprList* yy322;
138135 const char* yy336;
138136 IdList* yy384;
138137 Select* yy387;
138138 With* yy451;
138139 } YYMINORTYPE;
138140 #ifndef YYSTACKDEPTH
138141 #define YYSTACKDEPTH 100
138142 #endif
138143 #define sqlite3ParserARG_SDECL Parse *pParse;
138144 #define sqlite3ParserARG_PDECL ,Parse *pParse
138145 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
138146 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
138147 #define YYFALLBACK 1
138148 #define YYNSTATE 466
138149 #define YYNRULE 330
138150 #define YYNTOKEN 143
138151 #define YY_MAX_SHIFT 465
138152 #define YY_MIN_SHIFTREDUCE 675
138153 #define YY_MAX_SHIFTREDUCE 1004
138154 #define YY_ERROR_ACTION 1005
138155 #define YY_ACCEPT_ACTION 1006
138156 #define YY_NO_ACTION 1007
138157 #define YY_MIN_REDUCE 1008
138158 #define YY_MAX_REDUCE 1337
138159 /************* End control #defines *******************************************/
138160
138161 /* Define the yytestcase() macro to be a no-op if is not already defined
138162 ** otherwise.
138163 **
@@ -137999,39 +138183,33 @@
138183 ** token onto the stack and goto state N.
138184 **
138185 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
138186 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
138187 **
 
 
 
138188 ** N == YY_ERROR_ACTION A syntax error has occurred.
138189 **
138190 ** N == YY_ACCEPT_ACTION The parser accepts its input.
138191 **
138192 ** N == YY_NO_ACTION No such action. Denotes unused
138193 ** slots in the yy_action[] table.
138194 **
138195 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
138196 ** and YY_MAX_REDUCE
138197 **
138198 ** The action table is constructed as a single large table named yy_action[].
138199 ** Given state S and lookahead X, the action is computed as either:
138200 **
138201 ** (A) N = yy_action[ yy_shift_ofst[S] + X ]
138202 ** (B) N = yy_default[S]
138203 **
138204 ** The (A) formula is preferred. The B formula is used instead if
138205 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
 
 
 
 
 
138206 **
138207 ** The formulas above are for computing the action when the lookahead is
138208 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
138209 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
138210 ** the yy_shift_ofst[] array.
 
138211 **
138212 ** The following are the tables generated in this section:
138213 **
138214 ** yy_action[] A single table containing all actions.
138215 ** yy_lookahead[] A table containing the lookahead for each entry in
@@ -138041,467 +138219,478 @@
138219 ** yy_reduce_ofst[] For each state, the offset into yy_action for
138220 ** shifting non-terminals after a reduce.
138221 ** yy_default[] Default action for each state.
138222 **
138223 *********** Begin parsing tables **********************************************/
138224 #define YY_ACTTAB_COUNT (1541)
138225 static const YYACTIONTYPE yy_action[] = {
138226 /* 0 */ 1006, 156, 156, 2, 1302, 90, 87, 179, 90, 87,
138227 /* 10 */ 179, 460, 1048, 460, 465, 1010, 460, 333, 1130, 335,
138228 /* 20 */ 246, 330, 112, 303, 439, 1258, 304, 419, 1129, 1087,
138229 /* 30 */ 72, 798, 50, 50, 50, 50, 331, 30, 30, 799,
138230 /* 40 */ 951, 364, 371, 97, 98, 88, 983, 983, 859, 862,
138231 /* 50 */ 851, 851, 95, 95, 96, 96, 96, 96, 120, 371,
138232 /* 60 */ 370, 120, 348, 22, 90, 87, 179, 438, 423, 438,
138233 /* 70 */ 440, 335, 420, 385, 90, 87, 179, 116, 73, 163,
138234 /* 80 */ 848, 848, 860, 863, 94, 94, 94, 94, 93, 93,
138235 /* 90 */ 92, 92, 92, 91, 361, 97, 98, 88, 983, 983,
138236 /* 100 */ 859, 862, 851, 851, 95, 95, 96, 96, 96, 96,
138237 /* 110 */ 718, 365, 339, 93, 93, 92, 92, 92, 91, 361,
138238 /* 120 */ 99, 371, 453, 335, 94, 94, 94, 94, 93, 93,
138239 /* 130 */ 92, 92, 92, 91, 361, 852, 94, 94, 94, 94,
138240 /* 140 */ 93, 93, 92, 92, 92, 91, 361, 97, 98, 88,
138241 /* 150 */ 983, 983, 859, 862, 851, 851, 95, 95, 96, 96,
138242 /* 160 */ 96, 96, 92, 92, 92, 91, 361, 838, 132, 195,
138243 /* 170 */ 58, 244, 412, 409, 408, 335, 457, 457, 457, 304,
138244 /* 180 */ 59, 332, 831, 407, 394, 962, 830, 391, 94, 94,
138245 /* 190 */ 94, 94, 93, 93, 92, 92, 92, 91, 361, 97,
138246 /* 200 */ 98, 88, 983, 983, 859, 862, 851, 851, 95, 95,
138247 /* 210 */ 96, 96, 96, 96, 426, 357, 460, 830, 830, 832,
138248 /* 220 */ 91, 361, 962, 963, 964, 195, 459, 335, 412, 409,
138249 /* 230 */ 408, 280, 361, 820, 132, 11, 11, 50, 50, 407,
138250 /* 240 */ 94, 94, 94, 94, 93, 93, 92, 92, 92, 91,
138251 /* 250 */ 361, 97, 98, 88, 983, 983, 859, 862, 851, 851,
138252 /* 260 */ 95, 95, 96, 96, 96, 96, 460, 221, 460, 264,
138253 /* 270 */ 375, 254, 438, 428, 1276, 1276, 383, 1074, 1053, 335,
138254 /* 280 */ 245, 422, 299, 713, 271, 271, 1074, 50, 50, 50,
138255 /* 290 */ 50, 962, 94, 94, 94, 94, 93, 93, 92, 92,
138256 /* 300 */ 92, 91, 361, 97, 98, 88, 983, 983, 859, 862,
138257 /* 310 */ 851, 851, 95, 95, 96, 96, 96, 96, 90, 87,
138258 /* 320 */ 179, 1306, 438, 437, 438, 418, 368, 253, 962, 963,
138259 /* 330 */ 964, 335, 360, 360, 360, 706, 359, 358, 324, 962,
138260 /* 340 */ 1281, 951, 364, 230, 94, 94, 94, 94, 93, 93,
138261 /* 350 */ 92, 92, 92, 91, 361, 97, 98, 88, 983, 983,
138262 /* 360 */ 859, 862, 851, 851, 95, 95, 96, 96, 96, 96,
138263 /* 370 */ 769, 460, 120, 226, 226, 366, 962, 963, 964, 1089,
138264 /* 380 */ 990, 900, 990, 335, 1057, 425, 421, 839, 759, 759,
138265 /* 390 */ 425, 427, 50, 50, 432, 381, 94, 94, 94, 94,
138266 /* 400 */ 93, 93, 92, 92, 92, 91, 361, 97, 98, 88,
138267 /* 410 */ 983, 983, 859, 862, 851, 851, 95, 95, 96, 96,
138268 /* 420 */ 96, 96, 460, 259, 460, 120, 117, 354, 942, 1332,
138269 /* 430 */ 942, 1333, 1332, 278, 1333, 335, 680, 681, 682, 825,
138270 /* 440 */ 201, 176, 303, 50, 50, 49, 49, 404, 94, 94,
138271 /* 450 */ 94, 94, 93, 93, 92, 92, 92, 91, 361, 97,
138272 /* 460 */ 98, 88, 983, 983, 859, 862, 851, 851, 95, 95,
138273 /* 470 */ 96, 96, 96, 96, 199, 460, 380, 265, 433, 380,
138274 /* 480 */ 265, 383, 256, 158, 258, 319, 1003, 335, 155, 940,
138275 /* 490 */ 177, 940, 273, 379, 276, 322, 34, 34, 302, 962,
138276 /* 500 */ 94, 94, 94, 94, 93, 93, 92, 92, 92, 91,
138277 /* 510 */ 361, 97, 98, 88, 983, 983, 859, 862, 851, 851,
138278 /* 520 */ 95, 95, 96, 96, 96, 96, 905, 905, 397, 460,
138279 /* 530 */ 301, 158, 101, 319, 941, 340, 962, 963, 964, 313,
138280 /* 540 */ 283, 449, 335, 327, 146, 1266, 1004, 257, 234, 248,
138281 /* 550 */ 35, 35, 94, 94, 94, 94, 93, 93, 92, 92,
138282 /* 560 */ 92, 91, 361, 709, 785, 1227, 97, 98, 88, 983,
138283 /* 570 */ 983, 859, 862, 851, 851, 95, 95, 96, 96, 96,
138284 /* 580 */ 96, 962, 1227, 1229, 245, 422, 838, 198, 197, 196,
138285 /* 590 */ 1079, 1079, 1077, 1077, 1004, 1334, 320, 335, 172, 171,
138286 /* 600 */ 709, 831, 159, 271, 271, 830, 76, 94, 94, 94,
138287 /* 610 */ 94, 93, 93, 92, 92, 92, 91, 361, 962, 963,
138288 /* 620 */ 964, 97, 98, 88, 983, 983, 859, 862, 851, 851,
138289 /* 630 */ 95, 95, 96, 96, 96, 96, 830, 830, 832, 1157,
138290 /* 640 */ 1157, 199, 1157, 173, 1227, 231, 232, 1282, 2, 335,
138291 /* 650 */ 271, 764, 271, 820, 271, 271, 763, 389, 389, 389,
138292 /* 660 */ 132, 79, 94, 94, 94, 94, 93, 93, 92, 92,
138293 /* 670 */ 92, 91, 361, 97, 98, 88, 983, 983, 859, 862,
138294 /* 680 */ 851, 851, 95, 95, 96, 96, 96, 96, 460, 264,
138295 /* 690 */ 223, 460, 1257, 783, 1223, 1157, 1086, 1082, 80, 271,
138296 /* 700 */ 78, 335, 340, 1031, 341, 344, 345, 902, 346, 10,
138297 /* 710 */ 10, 902, 25, 25, 94, 94, 94, 94, 93, 93,
138298 /* 720 */ 92, 92, 92, 91, 361, 97, 86, 88, 983, 983,
138299 /* 730 */ 859, 862, 851, 851, 95, 95, 96, 96, 96, 96,
138300 /* 740 */ 1157, 270, 395, 117, 233, 263, 235, 70, 456, 341,
138301 /* 750 */ 225, 176, 335, 1305, 342, 133, 736, 966, 980, 249,
138302 /* 760 */ 1150, 396, 325, 1085, 1028, 178, 94, 94, 94, 94,
138303 /* 770 */ 93, 93, 92, 92, 92, 91, 361, 98, 88, 983,
138304 /* 780 */ 983, 859, 862, 851, 851, 95, 95, 96, 96, 96,
138305 /* 790 */ 96, 783, 783, 132, 120, 966, 120, 120, 120, 798,
138306 /* 800 */ 252, 937, 335, 353, 321, 429, 355, 799, 822, 692,
138307 /* 810 */ 390, 203, 446, 450, 372, 716, 454, 94, 94, 94,
138308 /* 820 */ 94, 93, 93, 92, 92, 92, 91, 361, 88, 983,
138309 /* 830 */ 983, 859, 862, 851, 851, 95, 95, 96, 96, 96,
138310 /* 840 */ 96, 84, 455, 1225, 3, 1209, 120, 120, 382, 387,
138311 /* 850 */ 120, 203, 1271, 716, 384, 168, 266, 203, 458, 72,
138312 /* 860 */ 260, 1246, 84, 455, 178, 3, 378, 94, 94, 94,
138313 /* 870 */ 94, 93, 93, 92, 92, 92, 91, 361, 350, 458,
138314 /* 880 */ 1245, 362, 430, 213, 228, 290, 415, 285, 414, 200,
138315 /* 890 */ 783, 882, 444, 726, 725, 405, 283, 921, 209, 921,
138316 /* 900 */ 281, 132, 362, 72, 838, 289, 147, 733, 734, 392,
138317 /* 910 */ 81, 82, 922, 444, 922, 267, 288, 83, 362, 462,
138318 /* 920 */ 461, 272, 132, 830, 23, 838, 388, 923, 1216, 923,
138319 /* 930 */ 1056, 81, 82, 84, 455, 899, 3, 899, 83, 362,
138320 /* 940 */ 462, 461, 761, 962, 830, 75, 1, 443, 275, 747,
138321 /* 950 */ 458, 5, 962, 204, 830, 830, 832, 833, 18, 748,
138322 /* 960 */ 229, 962, 277, 19, 153, 317, 317, 316, 216, 314,
138323 /* 970 */ 279, 460, 689, 362, 1055, 830, 830, 832, 833, 18,
138324 /* 980 */ 962, 963, 964, 962, 444, 181, 460, 251, 981, 962,
138325 /* 990 */ 963, 964, 8, 8, 20, 250, 838, 1070, 962, 963,
138326 /* 1000 */ 964, 417, 81, 82, 768, 204, 347, 36, 36, 83,
138327 /* 1010 */ 362, 462, 461, 1054, 284, 830, 84, 455, 1123, 3,
138328 /* 1020 */ 962, 963, 964, 460, 183, 962, 981, 764, 889, 1107,
138329 /* 1030 */ 460, 184, 763, 458, 132, 182, 74, 455, 460, 3,
138330 /* 1040 */ 981, 898, 834, 898, 8, 8, 830, 830, 832, 833,
138331 /* 1050 */ 18, 8, 8, 458, 219, 1156, 362, 1103, 349, 8,
138332 /* 1060 */ 8, 240, 962, 963, 964, 236, 889, 444, 792, 336,
138333 /* 1070 */ 158, 203, 885, 435, 700, 209, 362, 114, 981, 838,
138334 /* 1080 */ 834, 227, 334, 1114, 441, 81, 82, 444, 442, 305,
138335 /* 1090 */ 784, 306, 83, 362, 462, 461, 369, 1162, 830, 838,
138336 /* 1100 */ 460, 1037, 237, 1030, 237, 81, 82, 7, 96, 96,
138337 /* 1110 */ 96, 96, 83, 362, 462, 461, 1019, 1018, 830, 1020,
138338 /* 1120 */ 1289, 37, 37, 400, 96, 96, 96, 96, 89, 830,
138339 /* 1130 */ 830, 832, 833, 18, 1100, 318, 962, 292, 94, 94,
138340 /* 1140 */ 94, 94, 93, 93, 92, 92, 92, 91, 361, 830,
138341 /* 1150 */ 830, 832, 833, 18, 94, 94, 94, 94, 93, 93,
138342 /* 1160 */ 92, 92, 92, 91, 361, 359, 358, 226, 226, 727,
138343 /* 1170 */ 294, 296, 460, 962, 963, 964, 460, 989, 160, 425,
138344 /* 1180 */ 170, 1295, 262, 460, 987, 374, 988, 386, 1145, 255,
138345 /* 1190 */ 326, 460, 373, 38, 38, 410, 174, 39, 39, 413,
138346 /* 1200 */ 460, 287, 460, 1053, 40, 40, 298, 728, 1220, 990,
138347 /* 1210 */ 445, 990, 26, 26, 1219, 460, 311, 460, 169, 1292,
138348 /* 1220 */ 460, 27, 27, 29, 29, 998, 460, 206, 135, 995,
138349 /* 1230 */ 1265, 1263, 460, 57, 60, 460, 41, 41, 42, 42,
138350 /* 1240 */ 460, 43, 43, 460, 343, 351, 460, 9, 9, 460,
138351 /* 1250 */ 144, 460, 130, 44, 44, 460, 103, 103, 460, 137,
138352 /* 1260 */ 70, 45, 45, 460, 46, 46, 460, 31, 31, 1142,
138353 /* 1270 */ 47, 47, 48, 48, 460, 376, 32, 32, 460, 122,
138354 /* 1280 */ 122, 460, 157, 460, 123, 123, 139, 124, 124, 460,
138355 /* 1290 */ 186, 460, 377, 460, 115, 54, 54, 460, 403, 33,
138356 /* 1300 */ 33, 460, 104, 104, 51, 51, 460, 161, 460, 140,
138357 /* 1310 */ 105, 105, 106, 106, 102, 102, 460, 141, 121, 121,
138358 /* 1320 */ 460, 142, 119, 119, 190, 460, 1152, 110, 110, 109,
138359 /* 1330 */ 109, 702, 460, 148, 393, 65, 460, 107, 107, 460,
138360 /* 1340 */ 323, 108, 108, 399, 460, 1234, 53, 53, 1214, 269,
138361 /* 1350 */ 154, 416, 1115, 55, 55, 220, 401, 52, 52, 191,
138362 /* 1360 */ 24, 24, 274, 192, 193, 28, 28, 1021, 328, 702,
138363 /* 1370 */ 1073, 352, 1072, 718, 1071, 431, 1111, 1064, 329, 1045,
138364 /* 1380 */ 69, 205, 6, 291, 1044, 286, 1112, 1043, 1304, 1110,
138365 /* 1390 */ 293, 300, 295, 297, 1063, 1200, 1109, 77, 241, 448,
138366 /* 1400 */ 356, 452, 436, 100, 214, 71, 434, 1027, 1093, 21,
138367 /* 1410 */ 463, 242, 243, 957, 215, 217, 218, 464, 309, 307,
138368 /* 1420 */ 308, 310, 1016, 125, 1250, 1251, 1011, 1249, 126, 127,
138369 /* 1430 */ 1248, 113, 676, 337, 238, 338, 134, 363, 167, 1041,
138370 /* 1440 */ 1040, 56, 247, 367, 180, 897, 111, 895, 136, 1038,
138371 /* 1450 */ 818, 128, 138, 750, 261, 911, 185, 143, 145, 61,
138372 /* 1460 */ 62, 63, 64, 129, 914, 187, 188, 910, 118, 12,
138373 /* 1470 */ 189, 903, 268, 992, 203, 162, 398, 150, 149, 691,
138374 /* 1480 */ 402, 288, 194, 406, 151, 411, 66, 13, 729, 239,
138375 /* 1490 */ 282, 14, 67, 131, 837, 836, 865, 758, 15, 4,
138376 /* 1500 */ 68, 762, 175, 222, 224, 424, 152, 869, 791, 202,
138377 /* 1510 */ 786, 75, 72, 880, 866, 864, 16, 17, 920, 207,
138378 /* 1520 */ 919, 208, 447, 946, 164, 211, 947, 210, 165, 451,
138379 /* 1530 */ 868, 166, 315, 835, 701, 85, 212, 1297, 312, 952,
138380 /* 1540 */ 1296,
 
 
138381 };
138382 static const YYCODETYPE yy_lookahead[] = {
138383 /* 0 */ 144, 145, 146, 147, 172, 222, 223, 224, 222, 223,
138384 /* 10 */ 224, 152, 180, 152, 148, 149, 152, 173, 176, 19,
138385 /* 20 */ 154, 173, 156, 152, 163, 242, 152, 163, 176, 163,
138386 /* 30 */ 26, 31, 173, 174, 173, 174, 173, 173, 174, 39,
138387 /* 40 */ 1, 2, 152, 43, 44, 45, 46, 47, 48, 49,
138388 /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 197, 169,
138389 /* 60 */ 170, 197, 188, 197, 222, 223, 224, 208, 209, 208,
138390 /* 70 */ 209, 19, 208, 152, 222, 223, 224, 22, 26, 24,
138391 /* 80 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89,
138392 /* 90 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138393 /* 100 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138394 /* 110 */ 106, 245, 157, 88, 89, 90, 91, 92, 93, 94,
138395 /* 120 */ 68, 231, 251, 19, 84, 85, 86, 87, 88, 89,
138396 /* 130 */ 90, 91, 92, 93, 94, 101, 84, 85, 86, 87,
138397 /* 140 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
138398 /* 150 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138399 /* 160 */ 56, 57, 90, 91, 92, 93, 94, 82, 79, 99,
138400 /* 170 */ 66, 200, 102, 103, 104, 19, 168, 169, 170, 152,
138401 /* 180 */ 24, 210, 97, 113, 229, 59, 101, 232, 84, 85,
138402 /* 190 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
138403 /* 200 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138404 /* 210 */ 54, 55, 56, 57, 152, 188, 152, 132, 133, 134,
138405 /* 220 */ 93, 94, 96, 97, 98, 99, 152, 19, 102, 103,
138406 /* 230 */ 104, 23, 94, 72, 79, 173, 174, 173, 174, 113,
138407 /* 240 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138408 /* 250 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138409 /* 260 */ 52, 53, 54, 55, 56, 57, 152, 171, 152, 108,
138410 /* 270 */ 109, 110, 208, 209, 119, 120, 152, 180, 181, 19,
138411 /* 280 */ 119, 120, 152, 23, 152, 152, 189, 173, 174, 173,
138412 /* 290 */ 174, 59, 84, 85, 86, 87, 88, 89, 90, 91,
138413 /* 300 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
138414 /* 310 */ 50, 51, 52, 53, 54, 55, 56, 57, 222, 223,
138415 /* 320 */ 224, 186, 208, 209, 208, 209, 194, 194, 96, 97,
138416 /* 330 */ 98, 19, 168, 169, 170, 23, 88, 89, 163, 59,
138417 /* 340 */ 0, 1, 2, 219, 84, 85, 86, 87, 88, 89,
138418 /* 350 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138419 /* 360 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138420 /* 370 */ 90, 152, 197, 195, 196, 243, 96, 97, 98, 196,
138421 /* 380 */ 132, 11, 134, 19, 182, 207, 115, 23, 117, 118,
138422 /* 390 */ 207, 163, 173, 174, 152, 220, 84, 85, 86, 87,
138423 /* 400 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
138424 /* 410 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
138425 /* 420 */ 56, 57, 152, 16, 152, 197, 171, 208, 22, 23,
138426 /* 430 */ 22, 23, 26, 16, 26, 19, 7, 8, 9, 23,
138427 /* 440 */ 212, 213, 152, 173, 174, 173, 174, 19, 84, 85,
138428 /* 450 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
138429 /* 460 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
138430 /* 470 */ 54, 55, 56, 57, 46, 152, 109, 110, 208, 109,
138431 /* 480 */ 110, 152, 75, 152, 77, 22, 23, 19, 233, 83,
138432 /* 490 */ 152, 83, 75, 238, 77, 164, 173, 174, 226, 59,
138433 /* 500 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
138434 /* 510 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138435 /* 520 */ 52, 53, 54, 55, 56, 57, 108, 109, 110, 152,
138436 /* 530 */ 152, 152, 22, 22, 23, 107, 96, 97, 98, 160,
138437 /* 540 */ 112, 251, 19, 164, 22, 152, 83, 140, 219, 152,
138438 /* 550 */ 173, 174, 84, 85, 86, 87, 88, 89, 90, 91,
138439 /* 560 */ 92, 93, 94, 59, 124, 152, 43, 44, 45, 46,
138440 /* 570 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
138441 /* 580 */ 57, 59, 169, 170, 119, 120, 82, 108, 109, 110,
138442 /* 590 */ 191, 192, 191, 192, 83, 248, 249, 19, 88, 89,
138443 /* 600 */ 96, 97, 24, 152, 152, 101, 138, 84, 85, 86,
138444 /* 610 */ 87, 88, 89, 90, 91, 92, 93, 94, 96, 97,
138445 /* 620 */ 98, 43, 44, 45, 46, 47, 48, 49, 50, 51,
138446 /* 630 */ 52, 53, 54, 55, 56, 57, 132, 133, 134, 152,
138447 /* 640 */ 152, 46, 152, 26, 231, 194, 194, 146, 147, 19,
138448 /* 650 */ 152, 116, 152, 72, 152, 152, 121, 152, 152, 152,
138449 /* 660 */ 79, 138, 84, 85, 86, 87, 88, 89, 90, 91,
138450 /* 670 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
138451 /* 680 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 108,
138452 /* 690 */ 23, 152, 194, 26, 194, 152, 194, 194, 137, 152,
138453 /* 700 */ 139, 19, 107, 166, 167, 218, 218, 29, 218, 173,
138454 /* 710 */ 174, 33, 173, 174, 84, 85, 86, 87, 88, 89,
138455 /* 720 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
138456 /* 730 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
138457 /* 740 */ 152, 194, 64, 171, 239, 239, 239, 130, 166, 167,
138458 /* 750 */ 212, 213, 19, 23, 246, 247, 26, 59, 26, 152,
138459 /* 760 */ 163, 218, 163, 163, 163, 98, 84, 85, 86, 87,
138460 /* 770 */ 88, 89, 90, 91, 92, 93, 94, 44, 45, 46,
138461 /* 780 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
138462 /* 790 */ 57, 124, 26, 79, 197, 97, 197, 197, 197, 31,
138463 /* 800 */ 152, 23, 19, 19, 26, 19, 218, 39, 23, 21,
138464 /* 810 */ 238, 26, 163, 163, 100, 59, 163, 84, 85, 86,
138465 /* 820 */ 87, 88, 89, 90, 91, 92, 93, 94, 45, 46,
138466 /* 830 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
138467 /* 840 */ 57, 19, 20, 152, 22, 23, 197, 197, 23, 19,
138468 /* 850 */ 197, 26, 152, 97, 23, 123, 23, 26, 36, 26,
138469 /* 860 */ 152, 152, 19, 20, 98, 22, 78, 84, 85, 86,
138470 /* 870 */ 87, 88, 89, 90, 91, 92, 93, 94, 94, 36,
138471 /* 880 */ 152, 59, 96, 99, 100, 101, 102, 103, 104, 105,
138472 /* 890 */ 124, 103, 70, 100, 101, 23, 112, 12, 26, 12,
138473 /* 900 */ 23, 79, 59, 26, 82, 101, 22, 7, 8, 152,
138474 /* 910 */ 88, 89, 27, 70, 27, 152, 112, 95, 96, 97,
138475 /* 920 */ 98, 152, 79, 101, 22, 82, 96, 42, 140, 42,
138476 /* 930 */ 182, 88, 89, 19, 20, 132, 22, 134, 95, 96,
138477 /* 940 */ 97, 98, 23, 59, 101, 26, 22, 62, 152, 62,
138478 /* 950 */ 36, 22, 59, 24, 132, 133, 134, 135, 136, 72,
138479 /* 960 */ 5, 59, 152, 22, 71, 10, 11, 12, 13, 14,
138480 /* 970 */ 152, 152, 17, 59, 182, 132, 133, 134, 135, 136,
138481 /* 980 */ 96, 97, 98, 59, 70, 30, 152, 32, 59, 96,
138482 /* 990 */ 97, 98, 173, 174, 53, 40, 82, 152, 96, 97,
138483 /* 1000 */ 98, 90, 88, 89, 90, 24, 187, 173, 174, 95,
138484 /* 1010 */ 96, 97, 98, 152, 152, 101, 19, 20, 152, 22,
138485 /* 1020 */ 96, 97, 98, 152, 69, 59, 97, 116, 59, 214,
138486 /* 1030 */ 152, 76, 121, 36, 79, 80, 19, 20, 152, 22,
138487 /* 1040 */ 59, 132, 59, 134, 173, 174, 132, 133, 134, 135,
138488 /* 1050 */ 136, 173, 174, 36, 234, 152, 59, 152, 187, 173,
138489 /* 1060 */ 174, 211, 96, 97, 98, 187, 97, 70, 23, 114,
138490 /* 1070 */ 152, 26, 23, 187, 23, 26, 59, 26, 97, 82,
138491 /* 1080 */ 97, 22, 164, 152, 152, 88, 89, 70, 192, 152,
138492 /* 1090 */ 124, 152, 95, 96, 97, 98, 141, 152, 101, 82,
138493 /* 1100 */ 152, 152, 184, 152, 186, 88, 89, 199, 54, 55,
138494 /* 1110 */ 56, 57, 95, 96, 97, 98, 152, 152, 101, 152,
138495 /* 1120 */ 152, 173, 174, 235, 54, 55, 56, 57, 58, 132,
138496 /* 1130 */ 133, 134, 135, 136, 211, 150, 59, 211, 84, 85,
138497 /* 1140 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 132,
138498 /* 1150 */ 133, 134, 135, 136, 84, 85, 86, 87, 88, 89,
138499 /* 1160 */ 90, 91, 92, 93, 94, 88, 89, 195, 196, 35,
138500 /* 1170 */ 211, 211, 152, 96, 97, 98, 152, 100, 198, 207,
138501 /* 1180 */ 171, 122, 240, 152, 107, 215, 109, 240, 202, 215,
138502 /* 1190 */ 202, 152, 220, 173, 174, 177, 185, 173, 174, 65,
138503 /* 1200 */ 152, 176, 152, 181, 173, 174, 215, 73, 176, 132,
138504 /* 1210 */ 228, 134, 173, 174, 176, 152, 201, 152, 199, 155,
138505 /* 1220 */ 152, 173, 174, 173, 174, 60, 152, 122, 244, 38,
138506 /* 1230 */ 159, 159, 152, 241, 241, 152, 173, 174, 173, 174,
138507 /* 1240 */ 152, 173, 174, 152, 159, 111, 152, 173, 174, 152,
138508 /* 1250 */ 22, 152, 43, 173, 174, 152, 173, 174, 152, 190,
138509 /* 1260 */ 130, 173, 174, 152, 173, 174, 152, 173, 174, 202,
138510 /* 1270 */ 173, 174, 173, 174, 152, 18, 173, 174, 152, 173,
138511 /* 1280 */ 174, 152, 221, 152, 173, 174, 193, 173, 174, 152,
138512 /* 1290 */ 158, 152, 159, 152, 22, 173, 174, 152, 18, 173,
138513 /* 1300 */ 174, 152, 173, 174, 173, 174, 152, 221, 152, 193,
138514 /* 1310 */ 173, 174, 173, 174, 173, 174, 152, 193, 173, 174,
138515 /* 1320 */ 152, 193, 173, 174, 158, 152, 190, 173, 174, 173,
138516 /* 1330 */ 174, 59, 152, 190, 159, 137, 152, 173, 174, 152,
138517 /* 1340 */ 202, 173, 174, 61, 152, 237, 173, 174, 202, 236,
138518 /* 1350 */ 22, 107, 159, 173, 174, 159, 178, 173, 174, 158,
138519 /* 1360 */ 173, 174, 159, 158, 158, 173, 174, 159, 178, 97,
138520 /* 1370 */ 175, 63, 175, 106, 175, 125, 217, 183, 178, 175,
138521 /* 1380 */ 107, 159, 22, 216, 177, 175, 217, 175, 175, 217,
138522 /* 1390 */ 216, 159, 216, 216, 183, 225, 217, 137, 227, 178,
138523 /* 1400 */ 94, 178, 126, 129, 25, 128, 127, 162, 206, 26,
138524 /* 1410 */ 161, 230, 230, 13, 153, 153, 6, 151, 203, 205,
138525 /* 1420 */ 204, 202, 151, 165, 171, 171, 151, 171, 165, 165,
138526 /* 1430 */ 171, 179, 4, 250, 179, 250, 247, 3, 22, 171,
138527 /* 1440 */ 171, 171, 142, 81, 15, 23, 16, 23, 131, 171,
138528 /* 1450 */ 120, 111, 123, 20, 16, 1, 125, 123, 131, 53,
138529 /* 1460 */ 53, 53, 53, 111, 96, 34, 122, 1, 5, 22,
138530 /* 1470 */ 107, 67, 140, 74, 26, 24, 41, 107, 67, 20,
138531 /* 1480 */ 19, 112, 105, 66, 22, 66, 22, 22, 28, 66,
138532 /* 1490 */ 23, 22, 22, 37, 23, 23, 23, 116, 22, 22,
138533 /* 1500 */ 26, 23, 122, 23, 23, 26, 22, 11, 96, 34,
138534 /* 1510 */ 124, 26, 26, 23, 23, 23, 34, 34, 23, 26,
138535 /* 1520 */ 23, 22, 24, 23, 22, 122, 23, 26, 22, 24,
138536 /* 1530 */ 23, 22, 15, 23, 23, 22, 122, 122, 23, 1,
138537 /* 1540 */ 122, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138538 /* 1550 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138539 /* 1560 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138540 /* 1570 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138541 /* 1580 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138542 /* 1590 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138543 /* 1600 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138544 /* 1610 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138545 /* 1620 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138546 /* 1630 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138547 /* 1640 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138548 /* 1650 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138549 /* 1660 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138550 /* 1670 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
138551 /* 1680 */ 252, 252, 252, 252,
138552 };
138553 #define YY_SHIFT_COUNT (465)
138554 #define YY_SHIFT_MIN (0)
138555 #define YY_SHIFT_MAX (1538)
138556 static const unsigned short int yy_shift_ofst[] = {
138557 /* 0 */ 39, 822, 955, 843, 997, 997, 997, 997, 0, 0,
138558 /* 10 */ 104, 630, 997, 997, 997, 997, 997, 997, 997, 1077,
138559 /* 20 */ 1077, 126, 161, 155, 52, 156, 208, 260, 312, 364,
138560 /* 30 */ 416, 468, 523, 578, 630, 630, 630, 630, 630, 630,
138561 /* 40 */ 630, 630, 630, 630, 630, 630, 630, 630, 630, 630,
138562 /* 50 */ 630, 682, 630, 733, 783, 783, 914, 997, 997, 997,
138563 /* 60 */ 997, 997, 997, 997, 997, 997, 997, 997, 997, 997,
138564 /* 70 */ 997, 997, 997, 997, 997, 997, 997, 997, 997, 997,
138565 /* 80 */ 997, 997, 997, 997, 997, 997, 997, 997, 1017, 997,
138566 /* 90 */ 997, 997, 997, 997, 997, 997, 997, 997, 997, 997,
138567 /* 100 */ 997, 997, 1070, 1054, 1054, 1054, 1054, 1054, 40, 25,
138568 /* 110 */ 72, 232, 788, 428, 248, 248, 232, 581, 367, 127,
138569 /* 120 */ 465, 138, 1541, 1541, 1541, 784, 784, 784, 522, 522,
138570 /* 130 */ 887, 887, 893, 406, 408, 232, 232, 232, 232, 232,
138571 /* 140 */ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
138572 /* 150 */ 232, 232, 232, 232, 232, 370, 340, 714, 698, 698,
138573 /* 160 */ 465, 89, 89, 89, 89, 89, 89, 1541, 1541, 1541,
138574 /* 170 */ 504, 85, 85, 884, 70, 280, 902, 440, 966, 924,
138575 /* 180 */ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
138576 /* 190 */ 232, 232, 232, 232, 232, 232, 1134, 1134, 1134, 232,
138577 /* 200 */ 232, 667, 232, 232, 232, 929, 232, 232, 885, 232,
138578 /* 210 */ 232, 232, 232, 232, 232, 232, 232, 232, 232, 418,
138579 /* 220 */ 678, 981, 981, 981, 981, 766, 271, 911, 510, 429,
138580 /* 230 */ 617, 786, 786, 830, 617, 830, 4, 730, 595, 768,
138581 /* 240 */ 786, 561, 768, 768, 732, 535, 55, 1165, 1105, 1105,
138582 /* 250 */ 1191, 1191, 1105, 1228, 1209, 1130, 1257, 1257, 1257, 1257,
138583 /* 260 */ 1105, 1280, 1130, 1228, 1209, 1209, 1130, 1105, 1280, 1198,
138584 /* 270 */ 1282, 1105, 1105, 1280, 1328, 1105, 1280, 1105, 1280, 1328,
138585 /* 280 */ 1244, 1244, 1244, 1308, 1328, 1244, 1267, 1244, 1308, 1244,
138586 /* 290 */ 1244, 1250, 1273, 1250, 1273, 1250, 1273, 1250, 1273, 1105,
138587 /* 300 */ 1360, 1105, 1260, 1328, 1306, 1306, 1328, 1274, 1276, 1277,
138588 /* 310 */ 1279, 1130, 1379, 1383, 1400, 1400, 1410, 1410, 1410, 1541,
138589 /* 320 */ 1541, 1541, 1541, 1541, 1541, 1541, 1541, 1541, 1541, 1541,
138590 /* 330 */ 1541, 1541, 1541, 1541, 1541, 34, 407, 463, 511, 417,
138591 /* 340 */ 479, 1272, 778, 941, 785, 825, 831, 833, 872, 877,
138592 /* 350 */ 756, 793, 900, 804, 919, 1045, 969, 1049, 803, 909,
138593 /* 360 */ 1051, 983, 1059, 1428, 1434, 1416, 1300, 1429, 1362, 1430,
138594 /* 370 */ 1422, 1424, 1330, 1317, 1340, 1329, 1433, 1331, 1438, 1454,
138595 /* 380 */ 1334, 1327, 1406, 1407, 1408, 1409, 1352, 1368, 1431, 1344,
138596 /* 390 */ 1466, 1463, 1447, 1363, 1332, 1404, 1448, 1411, 1399, 1435,
138597 /* 400 */ 1370, 1451, 1459, 1461, 1369, 1377, 1462, 1417, 1464, 1465,
138598 /* 410 */ 1467, 1469, 1419, 1460, 1470, 1423, 1456, 1471, 1472, 1473,
138599 /* 420 */ 1474, 1381, 1476, 1478, 1477, 1479, 1380, 1480, 1481, 1412,
138600 /* 430 */ 1475, 1484, 1386, 1485, 1482, 1486, 1483, 1490, 1485, 1491,
138601 /* 440 */ 1492, 1495, 1493, 1497, 1499, 1496, 1500, 1502, 1498, 1501,
138602 /* 450 */ 1503, 1506, 1505, 1501, 1507, 1509, 1510, 1511, 1513, 1403,
138603 /* 460 */ 1414, 1415, 1418, 1515, 1517, 1538,
138604 };
138605 #define YY_REDUCE_COUNT (334)
138606 #define YY_REDUCE_MIN (-217)
138607 #define YY_REDUCE_MAX (1278)
138608 static const short yy_reduce_ofst[] = {
138609 /* 0 */ -144, -139, -134, -136, -141, 64, 114, 116, -158, -148,
138610 /* 10 */ -217, 96, 819, 871, 878, 219, 270, 886, 272, -110,
138611 /* 20 */ 413, 918, 972, 228, -214, -214, -214, -214, -214, -214,
138612 /* 30 */ -214, -214, -214, -214, -214, -214, -214, -214, -214, -214,
138613 /* 40 */ -214, -214, -214, -214, -214, -214, -214, -214, -214, -214,
138614 /* 50 */ -214, -214, -214, -214, -214, -214, 62, 323, 377, 536,
138615 /* 60 */ 539, 834, 948, 1020, 1024, 1031, 1039, 1048, 1050, 1063,
138616 /* 70 */ 1065, 1068, 1074, 1080, 1083, 1088, 1091, 1094, 1097, 1099,
138617 /* 80 */ 1103, 1106, 1111, 1114, 1122, 1126, 1129, 1131, 1137, 1139,
138618 /* 90 */ 1141, 1145, 1149, 1154, 1156, 1164, 1168, 1173, 1180, 1184,
138619 /* 100 */ 1187, 1192, -214, -214, -214, -214, -214, -214, -214, -214,
138620 /* 110 */ -214, 132, -45, 97, 8, 164, 379, 175, 255, -214,
138621 /* 120 */ 178, -214, -214, -214, -214, -168, -168, -168, 124, 329,
138622 /* 130 */ 399, 401, -129, 347, 347, 331, 133, 451, 452, 498,
138623 /* 140 */ 500, 502, 503, 505, 487, 506, 488, 490, 507, 543,
138624 /* 150 */ 547, -126, 588, 290, 27, 572, 501, 597, 537, 582,
138625 /* 160 */ 183, 599, 600, 601, 649, 650, 653, 508, 538, -29,
138626 /* 170 */ -156, -152, -137, -79, 135, 74, 130, 242, 338, 378,
138627 /* 180 */ 393, 397, 607, 648, 691, 700, 708, 709, 728, 757,
138628 /* 190 */ 763, 769, 796, 810, 818, 845, 202, 748, 792, 861,
138629 /* 200 */ 862, 815, 866, 903, 905, 850, 931, 932, 896, 937,
138630 /* 210 */ 939, 945, 74, 949, 951, 964, 965, 967, 968, 888,
138631 /* 220 */ 820, 923, 926, 959, 960, 815, 980, 908, 1009, 985,
138632 /* 230 */ 986, 970, 974, 942, 988, 947, 1018, 1011, 1022, 1025,
138633 /* 240 */ 991, 982, 1032, 1038, 1015, 1019, 1064, 984, 1071, 1072,
138634 /* 250 */ 992, 993, 1085, 1061, 1069, 1067, 1093, 1116, 1124, 1128,
138635 /* 260 */ 1133, 1132, 1138, 1086, 1136, 1143, 1146, 1175, 1166, 1108,
138636 /* 270 */ 1113, 1193, 1196, 1201, 1178, 1203, 1205, 1208, 1206, 1190,
138637 /* 280 */ 1195, 1197, 1199, 1194, 1200, 1204, 1207, 1210, 1211, 1212,
138638 /* 290 */ 1213, 1159, 1167, 1169, 1174, 1172, 1176, 1179, 1177, 1222,
138639 /* 300 */ 1170, 1232, 1171, 1221, 1181, 1182, 1223, 1202, 1214, 1216,
138640 /* 310 */ 1215, 1219, 1245, 1249, 1261, 1262, 1266, 1271, 1275, 1183,
138641 /* 320 */ 1185, 1189, 1258, 1253, 1254, 1256, 1259, 1263, 1252, 1255,
138642 /* 330 */ 1268, 1269, 1270, 1278, 1264,
138643 };
138644 static const YYACTIONTYPE yy_default[] = {
138645 /* 0 */ 1286, 1276, 1276, 1276, 1209, 1209, 1209, 1209, 1133, 1133,
138646 /* 10 */ 1260, 1036, 1005, 1005, 1005, 1005, 1005, 1005, 1208, 1005,
138647 /* 20 */ 1005, 1005, 1005, 1108, 1139, 1005, 1005, 1005, 1005, 1210,
138648 /* 30 */ 1211, 1005, 1005, 1005, 1259, 1261, 1149, 1148, 1147, 1146,
138649 /* 40 */ 1242, 1120, 1144, 1137, 1141, 1210, 1204, 1205, 1203, 1207,
138650 /* 50 */ 1211, 1005, 1140, 1174, 1188, 1173, 1005, 1005, 1005, 1005,
138651 /* 60 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138652 /* 70 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138653 /* 80 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138654 /* 90 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138655 /* 100 */ 1005, 1005, 1182, 1187, 1194, 1186, 1183, 1176, 1175, 1177,
138656 /* 110 */ 1178, 1005, 1026, 1075, 1005, 1005, 1005, 1276, 1036, 1179,
138657 /* 120 */ 1005, 1180, 1191, 1190, 1189, 1267, 1294, 1293, 1005, 1005,
138658 /* 130 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138659 /* 140 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138660 /* 150 */ 1005, 1005, 1005, 1005, 1005, 1036, 1286, 1276, 1032, 1032,
138661 /* 160 */ 1005, 1276, 1276, 1276, 1276, 1276, 1276, 1272, 1108, 1099,
138662 /* 170 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138663 /* 180 */ 1005, 1264, 1262, 1005, 1224, 1005, 1005, 1005, 1005, 1005,
138664 /* 190 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138665 /* 200 */ 1005, 1005, 1005, 1005, 1005, 1104, 1005, 1005, 1005, 1005,
138666 /* 210 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1288, 1005,
138667 /* 220 */ 1237, 1104, 1104, 1104, 1104, 1106, 1088, 1098, 1036, 1012,
138668 /* 230 */ 1143, 1122, 1122, 1327, 1143, 1327, 1050, 1308, 1047, 1133,
138669 /* 240 */ 1122, 1206, 1133, 1133, 1105, 1098, 1005, 1330, 1113, 1113,
138670 /* 250 */ 1329, 1329, 1113, 1154, 1078, 1143, 1084, 1084, 1084, 1084,
138671 /* 260 */ 1113, 1023, 1143, 1154, 1078, 1078, 1143, 1113, 1023, 1241,
138672 /* 270 */ 1324, 1113, 1113, 1023, 1217, 1113, 1023, 1113, 1023, 1217,
138673 /* 280 */ 1076, 1076, 1076, 1065, 1217, 1076, 1050, 1076, 1065, 1076,
138674 /* 290 */ 1076, 1126, 1121, 1126, 1121, 1126, 1121, 1126, 1121, 1113,
138675 /* 300 */ 1212, 1113, 1005, 1217, 1221, 1221, 1217, 1138, 1127, 1136,
138676 /* 310 */ 1134, 1143, 1029, 1068, 1291, 1291, 1287, 1287, 1287, 1335,
138677 /* 320 */ 1335, 1272, 1303, 1036, 1036, 1036, 1036, 1303, 1052, 1052,
138678 /* 330 */ 1036, 1036, 1036, 1036, 1303, 1005, 1005, 1005, 1005, 1005,
138679 /* 340 */ 1005, 1298, 1005, 1226, 1005, 1005, 1005, 1005, 1005, 1005,
138680 /* 350 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138681 /* 360 */ 1005, 1005, 1159, 1005, 1008, 1269, 1005, 1005, 1268, 1005,
138682 /* 370 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138683 /* 380 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1326,
138684 /* 390 */ 1005, 1005, 1005, 1005, 1005, 1005, 1240, 1239, 1005, 1005,
138685 /* 400 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138686 /* 410 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005,
138687 /* 420 */ 1005, 1090, 1005, 1005, 1005, 1312, 1005, 1005, 1005, 1005,
138688 /* 430 */ 1005, 1005, 1005, 1135, 1005, 1128, 1005, 1005, 1317, 1005,
138689 /* 440 */ 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1278,
138690 /* 450 */ 1005, 1005, 1005, 1277, 1005, 1005, 1005, 1005, 1005, 1161,
138691 /* 460 */ 1005, 1160, 1164, 1005, 1017, 1005,
138692 };
138693 /********** End of lemon-generated parsing tables *****************************/
138694
138695 /* The next table maps tokens (terminal symbols) into fallback tokens.
138696 ** If a construct like the following:
@@ -138682,79 +138871,268 @@
138871 if( yyTraceFILE==0 ) yyTracePrompt = 0;
138872 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
138873 }
138874 #endif /* NDEBUG */
138875
138876 #if defined(YYCOVERAGE) || !defined(NDEBUG)
138877 /* For tracing shifts, the names of all terminals and nonterminals
138878 ** are required. The following table supplies these names */
138879 static const char *const yyTokenName[] = {
138880 /* 0 */ "$",
138881 /* 1 */ "SEMI",
138882 /* 2 */ "EXPLAIN",
138883 /* 3 */ "QUERY",
138884 /* 4 */ "PLAN",
138885 /* 5 */ "BEGIN",
138886 /* 6 */ "TRANSACTION",
138887 /* 7 */ "DEFERRED",
138888 /* 8 */ "IMMEDIATE",
138889 /* 9 */ "EXCLUSIVE",
138890 /* 10 */ "COMMIT",
138891 /* 11 */ "END",
138892 /* 12 */ "ROLLBACK",
138893 /* 13 */ "SAVEPOINT",
138894 /* 14 */ "RELEASE",
138895 /* 15 */ "TO",
138896 /* 16 */ "TABLE",
138897 /* 17 */ "CREATE",
138898 /* 18 */ "IF",
138899 /* 19 */ "NOT",
138900 /* 20 */ "EXISTS",
138901 /* 21 */ "TEMP",
138902 /* 22 */ "LP",
138903 /* 23 */ "RP",
138904 /* 24 */ "AS",
138905 /* 25 */ "WITHOUT",
138906 /* 26 */ "COMMA",
138907 /* 27 */ "ABORT",
138908 /* 28 */ "ACTION",
138909 /* 29 */ "AFTER",
138910 /* 30 */ "ANALYZE",
138911 /* 31 */ "ASC",
138912 /* 32 */ "ATTACH",
138913 /* 33 */ "BEFORE",
138914 /* 34 */ "BY",
138915 /* 35 */ "CASCADE",
138916 /* 36 */ "CAST",
138917 /* 37 */ "CONFLICT",
138918 /* 38 */ "DATABASE",
138919 /* 39 */ "DESC",
138920 /* 40 */ "DETACH",
138921 /* 41 */ "EACH",
138922 /* 42 */ "FAIL",
138923 /* 43 */ "OR",
138924 /* 44 */ "AND",
138925 /* 45 */ "IS",
138926 /* 46 */ "MATCH",
138927 /* 47 */ "LIKE_KW",
138928 /* 48 */ "BETWEEN",
138929 /* 49 */ "IN",
138930 /* 50 */ "ISNULL",
138931 /* 51 */ "NOTNULL",
138932 /* 52 */ "NE",
138933 /* 53 */ "EQ",
138934 /* 54 */ "GT",
138935 /* 55 */ "LE",
138936 /* 56 */ "LT",
138937 /* 57 */ "GE",
138938 /* 58 */ "ESCAPE",
138939 /* 59 */ "ID",
138940 /* 60 */ "COLUMNKW",
138941 /* 61 */ "FOR",
138942 /* 62 */ "IGNORE",
138943 /* 63 */ "INITIALLY",
138944 /* 64 */ "INSTEAD",
138945 /* 65 */ "NO",
138946 /* 66 */ "KEY",
138947 /* 67 */ "OF",
138948 /* 68 */ "OFFSET",
138949 /* 69 */ "PRAGMA",
138950 /* 70 */ "RAISE",
138951 /* 71 */ "RECURSIVE",
138952 /* 72 */ "REPLACE",
138953 /* 73 */ "RESTRICT",
138954 /* 74 */ "ROW",
138955 /* 75 */ "TRIGGER",
138956 /* 76 */ "VACUUM",
138957 /* 77 */ "VIEW",
138958 /* 78 */ "VIRTUAL",
138959 /* 79 */ "WITH",
138960 /* 80 */ "REINDEX",
138961 /* 81 */ "RENAME",
138962 /* 82 */ "CTIME_KW",
138963 /* 83 */ "ANY",
138964 /* 84 */ "BITAND",
138965 /* 85 */ "BITOR",
138966 /* 86 */ "LSHIFT",
138967 /* 87 */ "RSHIFT",
138968 /* 88 */ "PLUS",
138969 /* 89 */ "MINUS",
138970 /* 90 */ "STAR",
138971 /* 91 */ "SLASH",
138972 /* 92 */ "REM",
138973 /* 93 */ "CONCAT",
138974 /* 94 */ "COLLATE",
138975 /* 95 */ "BITNOT",
138976 /* 96 */ "INDEXED",
138977 /* 97 */ "STRING",
138978 /* 98 */ "JOIN_KW",
138979 /* 99 */ "CONSTRAINT",
138980 /* 100 */ "DEFAULT",
138981 /* 101 */ "NULL",
138982 /* 102 */ "PRIMARY",
138983 /* 103 */ "UNIQUE",
138984 /* 104 */ "CHECK",
138985 /* 105 */ "REFERENCES",
138986 /* 106 */ "AUTOINCR",
138987 /* 107 */ "ON",
138988 /* 108 */ "INSERT",
138989 /* 109 */ "DELETE",
138990 /* 110 */ "UPDATE",
138991 /* 111 */ "SET",
138992 /* 112 */ "DEFERRABLE",
138993 /* 113 */ "FOREIGN",
138994 /* 114 */ "DROP",
138995 /* 115 */ "UNION",
138996 /* 116 */ "ALL",
138997 /* 117 */ "EXCEPT",
138998 /* 118 */ "INTERSECT",
138999 /* 119 */ "SELECT",
139000 /* 120 */ "VALUES",
139001 /* 121 */ "DISTINCT",
139002 /* 122 */ "DOT",
139003 /* 123 */ "FROM",
139004 /* 124 */ "JOIN",
139005 /* 125 */ "USING",
139006 /* 126 */ "ORDER",
139007 /* 127 */ "GROUP",
139008 /* 128 */ "HAVING",
139009 /* 129 */ "LIMIT",
139010 /* 130 */ "WHERE",
139011 /* 131 */ "INTO",
139012 /* 132 */ "FLOAT",
139013 /* 133 */ "BLOB",
139014 /* 134 */ "INTEGER",
139015 /* 135 */ "VARIABLE",
139016 /* 136 */ "CASE",
139017 /* 137 */ "WHEN",
139018 /* 138 */ "THEN",
139019 /* 139 */ "ELSE",
139020 /* 140 */ "INDEX",
139021 /* 141 */ "ALTER",
139022 /* 142 */ "ADD",
139023 /* 143 */ "error",
139024 /* 144 */ "input",
139025 /* 145 */ "cmdlist",
139026 /* 146 */ "ecmd",
139027 /* 147 */ "explain",
139028 /* 148 */ "cmdx",
139029 /* 149 */ "cmd",
139030 /* 150 */ "transtype",
139031 /* 151 */ "trans_opt",
139032 /* 152 */ "nm",
139033 /* 153 */ "savepoint_opt",
139034 /* 154 */ "create_table",
139035 /* 155 */ "create_table_args",
139036 /* 156 */ "createkw",
139037 /* 157 */ "temp",
139038 /* 158 */ "ifnotexists",
139039 /* 159 */ "dbnm",
139040 /* 160 */ "columnlist",
139041 /* 161 */ "conslist_opt",
139042 /* 162 */ "table_options",
139043 /* 163 */ "select",
139044 /* 164 */ "columnname",
139045 /* 165 */ "carglist",
139046 /* 166 */ "typetoken",
139047 /* 167 */ "typename",
139048 /* 168 */ "signed",
139049 /* 169 */ "plus_num",
139050 /* 170 */ "minus_num",
139051 /* 171 */ "scanpt",
139052 /* 172 */ "ccons",
139053 /* 173 */ "term",
139054 /* 174 */ "expr",
139055 /* 175 */ "onconf",
139056 /* 176 */ "sortorder",
139057 /* 177 */ "autoinc",
139058 /* 178 */ "eidlist_opt",
139059 /* 179 */ "refargs",
139060 /* 180 */ "defer_subclause",
139061 /* 181 */ "refarg",
139062 /* 182 */ "refact",
139063 /* 183 */ "init_deferred_pred_opt",
139064 /* 184 */ "conslist",
139065 /* 185 */ "tconscomma",
139066 /* 186 */ "tcons",
139067 /* 187 */ "sortlist",
139068 /* 188 */ "eidlist",
139069 /* 189 */ "defer_subclause_opt",
139070 /* 190 */ "orconf",
139071 /* 191 */ "resolvetype",
139072 /* 192 */ "raisetype",
139073 /* 193 */ "ifexists",
139074 /* 194 */ "fullname",
139075 /* 195 */ "selectnowith",
139076 /* 196 */ "oneselect",
139077 /* 197 */ "with",
139078 /* 198 */ "multiselect_op",
139079 /* 199 */ "distinct",
139080 /* 200 */ "selcollist",
139081 /* 201 */ "from",
139082 /* 202 */ "where_opt",
139083 /* 203 */ "groupby_opt",
139084 /* 204 */ "having_opt",
139085 /* 205 */ "orderby_opt",
139086 /* 206 */ "limit_opt",
139087 /* 207 */ "values",
139088 /* 208 */ "nexprlist",
139089 /* 209 */ "exprlist",
139090 /* 210 */ "sclp",
139091 /* 211 */ "as",
139092 /* 212 */ "seltablist",
139093 /* 213 */ "stl_prefix",
139094 /* 214 */ "joinop",
139095 /* 215 */ "indexed_opt",
139096 /* 216 */ "on_opt",
139097 /* 217 */ "using_opt",
139098 /* 218 */ "idlist",
139099 /* 219 */ "setlist",
139100 /* 220 */ "insert_cmd",
139101 /* 221 */ "idlist_opt",
139102 /* 222 */ "likeop",
139103 /* 223 */ "between_op",
139104 /* 224 */ "in_op",
139105 /* 225 */ "paren_exprlist",
139106 /* 226 */ "case_operand",
139107 /* 227 */ "case_exprlist",
139108 /* 228 */ "case_else",
139109 /* 229 */ "uniqueflag",
139110 /* 230 */ "collate",
139111 /* 231 */ "nmnum",
139112 /* 232 */ "trigger_decl",
139113 /* 233 */ "trigger_cmd_list",
139114 /* 234 */ "trigger_time",
139115 /* 235 */ "trigger_event",
139116 /* 236 */ "foreach_clause",
139117 /* 237 */ "when_clause",
139118 /* 238 */ "trigger_cmd",
139119 /* 239 */ "trnm",
139120 /* 240 */ "tridxby",
139121 /* 241 */ "database_kw_opt",
139122 /* 242 */ "key_opt",
139123 /* 243 */ "add_column_fullname",
139124 /* 244 */ "kwcolumn_opt",
139125 /* 245 */ "create_vtab",
139126 /* 246 */ "vtabarglist",
139127 /* 247 */ "vtabarg",
139128 /* 248 */ "vtabargtoken",
139129 /* 249 */ "lp",
139130 /* 250 */ "anylist",
139131 /* 251 */ "wqlist",
139132 };
139133 #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
139134
139135 #ifndef NDEBUG
139136 /* For tracing reduce actions, the names of all rules are required.
139137 */
139138 static const char *const yyRuleName[] = {
@@ -138784,311 +139162,312 @@
139162 /* 23 */ "columnname ::= nm typetoken",
139163 /* 24 */ "typetoken ::=",
139164 /* 25 */ "typetoken ::= typename LP signed RP",
139165 /* 26 */ "typetoken ::= typename LP signed COMMA signed RP",
139166 /* 27 */ "typename ::= typename ID|STRING",
139167 /* 28 */ "scanpt ::=",
139168 /* 29 */ "ccons ::= CONSTRAINT nm",
139169 /* 30 */ "ccons ::= DEFAULT scanpt term scanpt",
139170 /* 31 */ "ccons ::= DEFAULT LP expr RP",
139171 /* 32 */ "ccons ::= DEFAULT PLUS term scanpt",
139172 /* 33 */ "ccons ::= DEFAULT MINUS term scanpt",
139173 /* 34 */ "ccons ::= DEFAULT scanpt ID|INDEXED",
139174 /* 35 */ "ccons ::= NOT NULL onconf",
139175 /* 36 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
139176 /* 37 */ "ccons ::= UNIQUE onconf",
139177 /* 38 */ "ccons ::= CHECK LP expr RP",
139178 /* 39 */ "ccons ::= REFERENCES nm eidlist_opt refargs",
139179 /* 40 */ "ccons ::= defer_subclause",
139180 /* 41 */ "ccons ::= COLLATE ID|STRING",
139181 /* 42 */ "autoinc ::=",
139182 /* 43 */ "autoinc ::= AUTOINCR",
139183 /* 44 */ "refargs ::=",
139184 /* 45 */ "refargs ::= refargs refarg",
139185 /* 46 */ "refarg ::= MATCH nm",
139186 /* 47 */ "refarg ::= ON INSERT refact",
139187 /* 48 */ "refarg ::= ON DELETE refact",
139188 /* 49 */ "refarg ::= ON UPDATE refact",
139189 /* 50 */ "refact ::= SET NULL",
139190 /* 51 */ "refact ::= SET DEFAULT",
139191 /* 52 */ "refact ::= CASCADE",
139192 /* 53 */ "refact ::= RESTRICT",
139193 /* 54 */ "refact ::= NO ACTION",
139194 /* 55 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
139195 /* 56 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
139196 /* 57 */ "init_deferred_pred_opt ::=",
139197 /* 58 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
139198 /* 59 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
139199 /* 60 */ "conslist_opt ::=",
139200 /* 61 */ "tconscomma ::= COMMA",
139201 /* 62 */ "tcons ::= CONSTRAINT nm",
139202 /* 63 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf",
139203 /* 64 */ "tcons ::= UNIQUE LP sortlist RP onconf",
139204 /* 65 */ "tcons ::= CHECK LP expr RP onconf",
139205 /* 66 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt",
139206 /* 67 */ "defer_subclause_opt ::=",
139207 /* 68 */ "onconf ::=",
139208 /* 69 */ "onconf ::= ON CONFLICT resolvetype",
139209 /* 70 */ "orconf ::=",
139210 /* 71 */ "orconf ::= OR resolvetype",
139211 /* 72 */ "resolvetype ::= IGNORE",
139212 /* 73 */ "resolvetype ::= REPLACE",
139213 /* 74 */ "cmd ::= DROP TABLE ifexists fullname",
139214 /* 75 */ "ifexists ::= IF EXISTS",
139215 /* 76 */ "ifexists ::=",
139216 /* 77 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select",
139217 /* 78 */ "cmd ::= DROP VIEW ifexists fullname",
139218 /* 79 */ "cmd ::= select",
139219 /* 80 */ "select ::= with selectnowith",
139220 /* 81 */ "selectnowith ::= selectnowith multiselect_op oneselect",
139221 /* 82 */ "multiselect_op ::= UNION",
139222 /* 83 */ "multiselect_op ::= UNION ALL",
139223 /* 84 */ "multiselect_op ::= EXCEPT|INTERSECT",
139224 /* 85 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
139225 /* 86 */ "values ::= VALUES LP nexprlist RP",
139226 /* 87 */ "values ::= values COMMA LP exprlist RP",
139227 /* 88 */ "distinct ::= DISTINCT",
139228 /* 89 */ "distinct ::= ALL",
139229 /* 90 */ "distinct ::=",
139230 /* 91 */ "sclp ::=",
139231 /* 92 */ "selcollist ::= sclp scanpt expr scanpt as",
139232 /* 93 */ "selcollist ::= sclp scanpt STAR",
139233 /* 94 */ "selcollist ::= sclp scanpt nm DOT STAR",
139234 /* 95 */ "as ::= AS nm",
139235 /* 96 */ "as ::=",
139236 /* 97 */ "from ::=",
139237 /* 98 */ "from ::= FROM seltablist",
139238 /* 99 */ "stl_prefix ::= seltablist joinop",
139239 /* 100 */ "stl_prefix ::=",
139240 /* 101 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
139241 /* 102 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt",
139242 /* 103 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
139243 /* 104 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
139244 /* 105 */ "dbnm ::=",
139245 /* 106 */ "dbnm ::= DOT nm",
139246 /* 107 */ "fullname ::= nm dbnm",
139247 /* 108 */ "joinop ::= COMMA|JOIN",
139248 /* 109 */ "joinop ::= JOIN_KW JOIN",
139249 /* 110 */ "joinop ::= JOIN_KW nm JOIN",
139250 /* 111 */ "joinop ::= JOIN_KW nm nm JOIN",
139251 /* 112 */ "on_opt ::= ON expr",
139252 /* 113 */ "on_opt ::=",
139253 /* 114 */ "indexed_opt ::=",
139254 /* 115 */ "indexed_opt ::= INDEXED BY nm",
139255 /* 116 */ "indexed_opt ::= NOT INDEXED",
139256 /* 117 */ "using_opt ::= USING LP idlist RP",
139257 /* 118 */ "using_opt ::=",
139258 /* 119 */ "orderby_opt ::=",
139259 /* 120 */ "orderby_opt ::= ORDER BY sortlist",
139260 /* 121 */ "sortlist ::= sortlist COMMA expr sortorder",
139261 /* 122 */ "sortlist ::= expr sortorder",
139262 /* 123 */ "sortorder ::= ASC",
139263 /* 124 */ "sortorder ::= DESC",
139264 /* 125 */ "sortorder ::=",
139265 /* 126 */ "groupby_opt ::=",
139266 /* 127 */ "groupby_opt ::= GROUP BY nexprlist",
139267 /* 128 */ "having_opt ::=",
139268 /* 129 */ "having_opt ::= HAVING expr",
139269 /* 130 */ "limit_opt ::=",
139270 /* 131 */ "limit_opt ::= LIMIT expr",
139271 /* 132 */ "limit_opt ::= LIMIT expr OFFSET expr",
139272 /* 133 */ "limit_opt ::= LIMIT expr COMMA expr",
139273 /* 134 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
139274 /* 135 */ "where_opt ::=",
139275 /* 136 */ "where_opt ::= WHERE expr",
139276 /* 137 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
139277 /* 138 */ "setlist ::= setlist COMMA nm EQ expr",
139278 /* 139 */ "setlist ::= setlist COMMA LP idlist RP EQ expr",
139279 /* 140 */ "setlist ::= nm EQ expr",
139280 /* 141 */ "setlist ::= LP idlist RP EQ expr",
139281 /* 142 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select",
139282 /* 143 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES",
139283 /* 144 */ "insert_cmd ::= INSERT orconf",
139284 /* 145 */ "insert_cmd ::= REPLACE",
139285 /* 146 */ "idlist_opt ::=",
139286 /* 147 */ "idlist_opt ::= LP idlist RP",
139287 /* 148 */ "idlist ::= idlist COMMA nm",
139288 /* 149 */ "idlist ::= nm",
139289 /* 150 */ "expr ::= LP expr RP",
139290 /* 151 */ "expr ::= ID|INDEXED",
139291 /* 152 */ "expr ::= JOIN_KW",
139292 /* 153 */ "expr ::= nm DOT nm",
139293 /* 154 */ "expr ::= nm DOT nm DOT nm",
139294 /* 155 */ "term ::= NULL|FLOAT|BLOB",
139295 /* 156 */ "term ::= STRING",
139296 /* 157 */ "term ::= INTEGER",
139297 /* 158 */ "expr ::= VARIABLE",
139298 /* 159 */ "expr ::= expr COLLATE ID|STRING",
139299 /* 160 */ "expr ::= CAST LP expr AS typetoken RP",
139300 /* 161 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
139301 /* 162 */ "expr ::= ID|INDEXED LP STAR RP",
139302 /* 163 */ "term ::= CTIME_KW",
139303 /* 164 */ "expr ::= LP nexprlist COMMA expr RP",
139304 /* 165 */ "expr ::= expr AND expr",
139305 /* 166 */ "expr ::= expr OR expr",
139306 /* 167 */ "expr ::= expr LT|GT|GE|LE expr",
139307 /* 168 */ "expr ::= expr EQ|NE expr",
139308 /* 169 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
139309 /* 170 */ "expr ::= expr PLUS|MINUS expr",
139310 /* 171 */ "expr ::= expr STAR|SLASH|REM expr",
139311 /* 172 */ "expr ::= expr CONCAT expr",
139312 /* 173 */ "likeop ::= NOT LIKE_KW|MATCH",
139313 /* 174 */ "expr ::= expr likeop expr",
139314 /* 175 */ "expr ::= expr likeop expr ESCAPE expr",
139315 /* 176 */ "expr ::= expr ISNULL|NOTNULL",
139316 /* 177 */ "expr ::= expr NOT NULL",
139317 /* 178 */ "expr ::= expr IS expr",
139318 /* 179 */ "expr ::= expr IS NOT expr",
139319 /* 180 */ "expr ::= NOT expr",
139320 /* 181 */ "expr ::= BITNOT expr",
139321 /* 182 */ "expr ::= MINUS expr",
139322 /* 183 */ "expr ::= PLUS expr",
139323 /* 184 */ "between_op ::= BETWEEN",
139324 /* 185 */ "between_op ::= NOT BETWEEN",
139325 /* 186 */ "expr ::= expr between_op expr AND expr",
139326 /* 187 */ "in_op ::= IN",
139327 /* 188 */ "in_op ::= NOT IN",
139328 /* 189 */ "expr ::= expr in_op LP exprlist RP",
139329 /* 190 */ "expr ::= LP select RP",
139330 /* 191 */ "expr ::= expr in_op LP select RP",
139331 /* 192 */ "expr ::= expr in_op nm dbnm paren_exprlist",
139332 /* 193 */ "expr ::= EXISTS LP select RP",
139333 /* 194 */ "expr ::= CASE case_operand case_exprlist case_else END",
139334 /* 195 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
139335 /* 196 */ "case_exprlist ::= WHEN expr THEN expr",
139336 /* 197 */ "case_else ::= ELSE expr",
139337 /* 198 */ "case_else ::=",
139338 /* 199 */ "case_operand ::= expr",
139339 /* 200 */ "case_operand ::=",
139340 /* 201 */ "exprlist ::=",
139341 /* 202 */ "nexprlist ::= nexprlist COMMA expr",
139342 /* 203 */ "nexprlist ::= expr",
139343 /* 204 */ "paren_exprlist ::=",
139344 /* 205 */ "paren_exprlist ::= LP exprlist RP",
139345 /* 206 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
139346 /* 207 */ "uniqueflag ::= UNIQUE",
139347 /* 208 */ "uniqueflag ::=",
139348 /* 209 */ "eidlist_opt ::=",
139349 /* 210 */ "eidlist_opt ::= LP eidlist RP",
139350 /* 211 */ "eidlist ::= eidlist COMMA nm collate sortorder",
139351 /* 212 */ "eidlist ::= nm collate sortorder",
139352 /* 213 */ "collate ::=",
139353 /* 214 */ "collate ::= COLLATE ID|STRING",
139354 /* 215 */ "cmd ::= DROP INDEX ifexists fullname",
139355 /* 216 */ "cmd ::= VACUUM",
139356 /* 217 */ "cmd ::= VACUUM nm",
139357 /* 218 */ "cmd ::= PRAGMA nm dbnm",
139358 /* 219 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
139359 /* 220 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
139360 /* 221 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
139361 /* 222 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
139362 /* 223 */ "plus_num ::= PLUS INTEGER|FLOAT",
139363 /* 224 */ "minus_num ::= MINUS INTEGER|FLOAT",
139364 /* 225 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
139365 /* 226 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
139366 /* 227 */ "trigger_time ::= BEFORE|AFTER",
139367 /* 228 */ "trigger_time ::= INSTEAD OF",
139368 /* 229 */ "trigger_time ::=",
139369 /* 230 */ "trigger_event ::= DELETE|INSERT",
139370 /* 231 */ "trigger_event ::= UPDATE",
139371 /* 232 */ "trigger_event ::= UPDATE OF idlist",
139372 /* 233 */ "when_clause ::=",
139373 /* 234 */ "when_clause ::= WHEN expr",
139374 /* 235 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
139375 /* 236 */ "trigger_cmd_list ::= trigger_cmd SEMI",
139376 /* 237 */ "trnm ::= nm DOT nm",
139377 /* 238 */ "tridxby ::= INDEXED BY nm",
139378 /* 239 */ "tridxby ::= NOT INDEXED",
139379 /* 240 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt",
139380 /* 241 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt",
139381 /* 242 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
139382 /* 243 */ "trigger_cmd ::= scanpt select scanpt",
139383 /* 244 */ "expr ::= RAISE LP IGNORE RP",
139384 /* 245 */ "expr ::= RAISE LP raisetype COMMA nm RP",
139385 /* 246 */ "raisetype ::= ROLLBACK",
139386 /* 247 */ "raisetype ::= ABORT",
139387 /* 248 */ "raisetype ::= FAIL",
139388 /* 249 */ "cmd ::= DROP TRIGGER ifexists fullname",
139389 /* 250 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
139390 /* 251 */ "cmd ::= DETACH database_kw_opt expr",
139391 /* 252 */ "key_opt ::=",
139392 /* 253 */ "key_opt ::= KEY expr",
139393 /* 254 */ "cmd ::= REINDEX",
139394 /* 255 */ "cmd ::= REINDEX nm dbnm",
139395 /* 256 */ "cmd ::= ANALYZE",
139396 /* 257 */ "cmd ::= ANALYZE nm dbnm",
139397 /* 258 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
139398 /* 259 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
139399 /* 260 */ "add_column_fullname ::= fullname",
139400 /* 261 */ "cmd ::= create_vtab",
139401 /* 262 */ "cmd ::= create_vtab LP vtabarglist RP",
139402 /* 263 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
139403 /* 264 */ "vtabarg ::=",
139404 /* 265 */ "vtabargtoken ::= ANY",
139405 /* 266 */ "vtabargtoken ::= lp anylist RP",
139406 /* 267 */ "lp ::= LP",
139407 /* 268 */ "with ::=",
139408 /* 269 */ "with ::= WITH wqlist",
139409 /* 270 */ "with ::= WITH RECURSIVE wqlist",
139410 /* 271 */ "wqlist ::= nm eidlist_opt AS LP select RP",
139411 /* 272 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
139412 /* 273 */ "input ::= cmdlist",
139413 /* 274 */ "cmdlist ::= cmdlist ecmd",
139414 /* 275 */ "cmdlist ::= ecmd",
139415 /* 276 */ "ecmd ::= SEMI",
139416 /* 277 */ "ecmd ::= explain cmdx SEMI",
139417 /* 278 */ "explain ::=",
139418 /* 279 */ "trans_opt ::=",
139419 /* 280 */ "trans_opt ::= TRANSACTION",
139420 /* 281 */ "trans_opt ::= TRANSACTION nm",
139421 /* 282 */ "savepoint_opt ::= SAVEPOINT",
139422 /* 283 */ "savepoint_opt ::=",
139423 /* 284 */ "cmd ::= create_table create_table_args",
139424 /* 285 */ "columnlist ::= columnlist COMMA columnname carglist",
139425 /* 286 */ "columnlist ::= columnname carglist",
139426 /* 287 */ "nm ::= ID|INDEXED",
139427 /* 288 */ "nm ::= STRING",
139428 /* 289 */ "nm ::= JOIN_KW",
139429 /* 290 */ "typetoken ::= typename",
139430 /* 291 */ "typename ::= ID|STRING",
139431 /* 292 */ "signed ::= plus_num",
139432 /* 293 */ "signed ::= minus_num",
139433 /* 294 */ "carglist ::= carglist ccons",
139434 /* 295 */ "carglist ::=",
139435 /* 296 */ "ccons ::= NULL onconf",
139436 /* 297 */ "conslist_opt ::= COMMA conslist",
139437 /* 298 */ "conslist ::= conslist tconscomma tcons",
139438 /* 299 */ "conslist ::= tcons",
139439 /* 300 */ "tconscomma ::=",
139440 /* 301 */ "defer_subclause_opt ::= defer_subclause",
139441 /* 302 */ "resolvetype ::= raisetype",
139442 /* 303 */ "selectnowith ::= oneselect",
139443 /* 304 */ "oneselect ::= values",
139444 /* 305 */ "sclp ::= selcollist COMMA",
139445 /* 306 */ "as ::= ID|STRING",
139446 /* 307 */ "expr ::= term",
139447 /* 308 */ "likeop ::= LIKE_KW|MATCH",
139448 /* 309 */ "exprlist ::= nexprlist",
139449 /* 310 */ "nmnum ::= plus_num",
139450 /* 311 */ "nmnum ::= nm",
139451 /* 312 */ "nmnum ::= ON",
139452 /* 313 */ "nmnum ::= DELETE",
139453 /* 314 */ "nmnum ::= DEFAULT",
139454 /* 315 */ "plus_num ::= INTEGER|FLOAT",
139455 /* 316 */ "foreach_clause ::=",
139456 /* 317 */ "foreach_clause ::= FOR EACH ROW",
139457 /* 318 */ "trnm ::= nm",
139458 /* 319 */ "tridxby ::=",
139459 /* 320 */ "database_kw_opt ::= DATABASE",
139460 /* 321 */ "database_kw_opt ::=",
139461 /* 322 */ "kwcolumn_opt ::=",
139462 /* 323 */ "kwcolumn_opt ::= COLUMNKW",
139463 /* 324 */ "vtabarglist ::= vtabarg",
139464 /* 325 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
139465 /* 326 */ "vtabarg ::= vtabarg vtabargtoken",
139466 /* 327 */ "anylist ::=",
139467 /* 328 */ "anylist ::= anylist LP anylist RP",
139468 /* 329 */ "anylist ::= anylist ANY",
139469 };
139470 #endif /* NDEBUG */
139471
139472
139473 #if YYSTACKDEPTH<=0
@@ -139206,80 +139585,76 @@
139585 ** which appear on the RHS of the rule, but which are *not* used
139586 ** inside the C code.
139587 */
139588 /********* Begin destructor definitions ***************************************/
139589 case 163: /* select */
139590 case 195: /* selectnowith */
139591 case 196: /* oneselect */
139592 case 207: /* values */
139593 {
139594 sqlite3SelectDelete(pParse->db, (yypminor->yy387));
139595 }
139596 break;
139597 case 173: /* term */
139598 case 174: /* expr */
139599 case 202: /* where_opt */
139600 case 204: /* having_opt */
139601 case 216: /* on_opt */
139602 case 226: /* case_operand */
139603 case 228: /* case_else */
139604 case 237: /* when_clause */
139605 case 242: /* key_opt */
139606 {
139607 sqlite3ExprDelete(pParse->db, (yypminor->yy314));
139608 }
139609 break;
139610 case 178: /* eidlist_opt */
139611 case 187: /* sortlist */
139612 case 188: /* eidlist */
139613 case 200: /* selcollist */
139614 case 203: /* groupby_opt */
139615 case 205: /* orderby_opt */
139616 case 208: /* nexprlist */
139617 case 209: /* exprlist */
139618 case 210: /* sclp */
139619 case 219: /* setlist */
139620 case 225: /* paren_exprlist */
139621 case 227: /* case_exprlist */
139622 {
139623 sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
139624 }
139625 break;
139626 case 194: /* fullname */
139627 case 201: /* from */
139628 case 212: /* seltablist */
139629 case 213: /* stl_prefix */
139630 {
139631 sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
139632 }
139633 break;
139634 case 197: /* with */
139635 case 251: /* wqlist */
139636 {
139637 sqlite3WithDelete(pParse->db, (yypminor->yy451));
139638 }
139639 break;
139640 case 217: /* using_opt */
139641 case 218: /* idlist */
139642 case 221: /* idlist_opt */
139643 {
139644 sqlite3IdListDelete(pParse->db, (yypminor->yy384));
139645 }
139646 break;
139647 case 233: /* trigger_cmd_list */
139648 case 238: /* trigger_cmd */
139649 {
139650 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
139651 }
139652 break;
139653 case 235: /* trigger_event */
139654 {
139655 sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
 
 
 
 
139656 }
139657 break;
139658 /********* End destructor definitions *****************************************/
139659 default: break; /* If no destructor action specified: do nothing */
139660 }
@@ -139346,10 +139721,47 @@
139721 yyParser *pParser = (yyParser*)p;
139722 return pParser->yyhwm;
139723 }
139724 #endif
139725
139726 /* This array of booleans keeps track of the parser statement
139727 ** coverage. The element yycoverage[X][Y] is set when the parser
139728 ** is in state X and has a lookahead token Y. In a well-tested
139729 ** systems, every element of this matrix should end up being set.
139730 */
139731 #if defined(YYCOVERAGE)
139732 static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
139733 #endif
139734
139735 /*
139736 ** Write into out a description of every state/lookahead combination that
139737 **
139738 ** (1) has not been used by the parser, and
139739 ** (2) is not a syntax error.
139740 **
139741 ** Return the number of missed state/lookahead combinations.
139742 */
139743 #if defined(YYCOVERAGE)
139744 SQLITE_PRIVATE int sqlite3ParserCoverage(FILE *out){
139745 int stateno, iLookAhead, i;
139746 int nMissed = 0;
139747 for(stateno=0; stateno<YYNSTATE; stateno++){
139748 i = yy_shift_ofst[stateno];
139749 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
139750 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
139751 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
139752 if( out ){
139753 fprintf(out,"State %d lookahead %s %s\n", stateno,
139754 yyTokenName[iLookAhead],
139755 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
139756 }
139757 }
139758 }
139759 return nMissed;
139760 }
139761 #endif
139762
139763 /*
139764 ** Find the appropriate action for a parser given the terminal
139765 ** look-ahead token iLookAhead.
139766 */
139767 static unsigned int yy_find_shift_action(
@@ -139357,17 +139769,22 @@
139769 YYCODETYPE iLookAhead /* The look-ahead token */
139770 ){
139771 int i;
139772 int stateno = pParser->yytos->stateno;
139773
139774 if( stateno>YY_MAX_SHIFT ) return stateno;
139775 assert( stateno <= YY_SHIFT_COUNT );
139776 #if defined(YYCOVERAGE)
139777 yycoverage[stateno][iLookAhead] = 1;
139778 #endif
139779 do{
139780 i = yy_shift_ofst[stateno];
139781 assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
139782 assert( iLookAhead!=YYNOCODE );
139783 assert( iLookAhead < YYNTOKEN );
139784 i += iLookAhead;
139785 if( yy_lookahead[i]!=iLookAhead ){
139786 #ifdef YYFALLBACK
139787 YYCODETYPE iFallback; /* Fallback token */
139788 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
139789 && (iFallback = yyFallback[iLookAhead])!=0 ){
139790 #ifndef NDEBUG
@@ -139426,11 +139843,10 @@
139843 }
139844 #else
139845 assert( stateno<=YY_REDUCE_COUNT );
139846 #endif
139847 i = yy_reduce_ofst[stateno];
 
139848 assert( iLookAhead!=YYNOCODE );
139849 i += iLookAhead;
139850 #ifdef YYERRORSYMBOL
139851 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
139852 return yy_default[stateno];
@@ -139464,24 +139880,25 @@
139880
139881 /*
139882 ** Print tracing information for a SHIFT action
139883 */
139884 #ifndef NDEBUG
139885 static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
139886 if( yyTraceFILE ){
139887 if( yyNewState<YYNSTATE ){
139888 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
139889 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
139890 yyNewState);
139891 }else{
139892 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
139893 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
139894 yyNewState - YY_MIN_REDUCE);
139895 }
139896 }
139897 }
139898 #else
139899 # define yyTraceShift(X,Y,Z)
139900 #endif
139901
139902 /*
139903 ** Perform a shift action.
139904 */
@@ -139519,360 +139936,369 @@
139936 }
139937 yytos = yypParser->yytos;
139938 yytos->stateno = (YYACTIONTYPE)yyNewState;
139939 yytos->major = (YYCODETYPE)yyMajor;
139940 yytos->minor.yy0 = yyMinor;
139941 yyTraceShift(yypParser, yyNewState, "Shift");
139942 }
139943
139944 /* The following table contains information about every rule that
139945 ** is used during the reduce.
139946 */
139947 static const struct {
139948 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
139949 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
139950 } yyRuleInfo[] = {
139951 { 147, -1 }, /* (0) explain ::= EXPLAIN */
139952 { 147, -3 }, /* (1) explain ::= EXPLAIN QUERY PLAN */
139953 { 148, -1 }, /* (2) cmdx ::= cmd */
139954 { 149, -3 }, /* (3) cmd ::= BEGIN transtype trans_opt */
139955 { 150, 0 }, /* (4) transtype ::= */
139956 { 150, -1 }, /* (5) transtype ::= DEFERRED */
139957 { 150, -1 }, /* (6) transtype ::= IMMEDIATE */
139958 { 150, -1 }, /* (7) transtype ::= EXCLUSIVE */
139959 { 149, -2 }, /* (8) cmd ::= COMMIT|END trans_opt */
139960 { 149, -2 }, /* (9) cmd ::= ROLLBACK trans_opt */
139961 { 149, -2 }, /* (10) cmd ::= SAVEPOINT nm */
139962 { 149, -3 }, /* (11) cmd ::= RELEASE savepoint_opt nm */
139963 { 149, -5 }, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
139964 { 154, -6 }, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
139965 { 156, -1 }, /* (14) createkw ::= CREATE */
139966 { 158, 0 }, /* (15) ifnotexists ::= */
139967 { 158, -3 }, /* (16) ifnotexists ::= IF NOT EXISTS */
139968 { 157, -1 }, /* (17) temp ::= TEMP */
139969 { 157, 0 }, /* (18) temp ::= */
139970 { 155, -5 }, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
139971 { 155, -2 }, /* (20) create_table_args ::= AS select */
139972 { 162, 0 }, /* (21) table_options ::= */
139973 { 162, -2 }, /* (22) table_options ::= WITHOUT nm */
139974 { 164, -2 }, /* (23) columnname ::= nm typetoken */
139975 { 166, 0 }, /* (24) typetoken ::= */
139976 { 166, -4 }, /* (25) typetoken ::= typename LP signed RP */
139977 { 166, -6 }, /* (26) typetoken ::= typename LP signed COMMA signed RP */
139978 { 167, -2 }, /* (27) typename ::= typename ID|STRING */
139979 { 171, 0 }, /* (28) scanpt ::= */
139980 { 172, -2 }, /* (29) ccons ::= CONSTRAINT nm */
139981 { 172, -4 }, /* (30) ccons ::= DEFAULT scanpt term scanpt */
139982 { 172, -4 }, /* (31) ccons ::= DEFAULT LP expr RP */
139983 { 172, -4 }, /* (32) ccons ::= DEFAULT PLUS term scanpt */
139984 { 172, -4 }, /* (33) ccons ::= DEFAULT MINUS term scanpt */
139985 { 172, -3 }, /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */
139986 { 172, -3 }, /* (35) ccons ::= NOT NULL onconf */
139987 { 172, -5 }, /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */
139988 { 172, -2 }, /* (37) ccons ::= UNIQUE onconf */
139989 { 172, -4 }, /* (38) ccons ::= CHECK LP expr RP */
139990 { 172, -4 }, /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */
139991 { 172, -1 }, /* (40) ccons ::= defer_subclause */
139992 { 172, -2 }, /* (41) ccons ::= COLLATE ID|STRING */
139993 { 177, 0 }, /* (42) autoinc ::= */
139994 { 177, -1 }, /* (43) autoinc ::= AUTOINCR */
139995 { 179, 0 }, /* (44) refargs ::= */
139996 { 179, -2 }, /* (45) refargs ::= refargs refarg */
139997 { 181, -2 }, /* (46) refarg ::= MATCH nm */
139998 { 181, -3 }, /* (47) refarg ::= ON INSERT refact */
139999 { 181, -3 }, /* (48) refarg ::= ON DELETE refact */
140000 { 181, -3 }, /* (49) refarg ::= ON UPDATE refact */
140001 { 182, -2 }, /* (50) refact ::= SET NULL */
140002 { 182, -2 }, /* (51) refact ::= SET DEFAULT */
140003 { 182, -1 }, /* (52) refact ::= CASCADE */
140004 { 182, -1 }, /* (53) refact ::= RESTRICT */
140005 { 182, -2 }, /* (54) refact ::= NO ACTION */
140006 { 180, -3 }, /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
140007 { 180, -2 }, /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
140008 { 183, 0 }, /* (57) init_deferred_pred_opt ::= */
140009 { 183, -2 }, /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */
140010 { 183, -2 }, /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
140011 { 161, 0 }, /* (60) conslist_opt ::= */
140012 { 185, -1 }, /* (61) tconscomma ::= COMMA */
140013 { 186, -2 }, /* (62) tcons ::= CONSTRAINT nm */
140014 { 186, -7 }, /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
140015 { 186, -5 }, /* (64) tcons ::= UNIQUE LP sortlist RP onconf */
140016 { 186, -5 }, /* (65) tcons ::= CHECK LP expr RP onconf */
140017 { 186, -10 }, /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
140018 { 189, 0 }, /* (67) defer_subclause_opt ::= */
140019 { 175, 0 }, /* (68) onconf ::= */
140020 { 175, -3 }, /* (69) onconf ::= ON CONFLICT resolvetype */
140021 { 190, 0 }, /* (70) orconf ::= */
140022 { 190, -2 }, /* (71) orconf ::= OR resolvetype */
140023 { 191, -1 }, /* (72) resolvetype ::= IGNORE */
140024 { 191, -1 }, /* (73) resolvetype ::= REPLACE */
140025 { 149, -4 }, /* (74) cmd ::= DROP TABLE ifexists fullname */
140026 { 193, -2 }, /* (75) ifexists ::= IF EXISTS */
140027 { 193, 0 }, /* (76) ifexists ::= */
140028 { 149, -9 }, /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
140029 { 149, -4 }, /* (78) cmd ::= DROP VIEW ifexists fullname */
140030 { 149, -1 }, /* (79) cmd ::= select */
140031 { 163, -2 }, /* (80) select ::= with selectnowith */
140032 { 195, -3 }, /* (81) selectnowith ::= selectnowith multiselect_op oneselect */
140033 { 198, -1 }, /* (82) multiselect_op ::= UNION */
140034 { 198, -2 }, /* (83) multiselect_op ::= UNION ALL */
140035 { 198, -1 }, /* (84) multiselect_op ::= EXCEPT|INTERSECT */
140036 { 196, -9 }, /* (85) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
140037 { 207, -4 }, /* (86) values ::= VALUES LP nexprlist RP */
140038 { 207, -5 }, /* (87) values ::= values COMMA LP exprlist RP */
140039 { 199, -1 }, /* (88) distinct ::= DISTINCT */
140040 { 199, -1 }, /* (89) distinct ::= ALL */
140041 { 199, 0 }, /* (90) distinct ::= */
140042 { 210, 0 }, /* (91) sclp ::= */
140043 { 200, -5 }, /* (92) selcollist ::= sclp scanpt expr scanpt as */
140044 { 200, -3 }, /* (93) selcollist ::= sclp scanpt STAR */
140045 { 200, -5 }, /* (94) selcollist ::= sclp scanpt nm DOT STAR */
140046 { 211, -2 }, /* (95) as ::= AS nm */
140047 { 211, 0 }, /* (96) as ::= */
140048 { 201, 0 }, /* (97) from ::= */
140049 { 201, -2 }, /* (98) from ::= FROM seltablist */
140050 { 213, -2 }, /* (99) stl_prefix ::= seltablist joinop */
140051 { 213, 0 }, /* (100) stl_prefix ::= */
140052 { 212, -7 }, /* (101) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
140053 { 212, -9 }, /* (102) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
140054 { 212, -7 }, /* (103) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
140055 { 212, -7 }, /* (104) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
140056 { 159, 0 }, /* (105) dbnm ::= */
140057 { 159, -2 }, /* (106) dbnm ::= DOT nm */
140058 { 194, -2 }, /* (107) fullname ::= nm dbnm */
140059 { 214, -1 }, /* (108) joinop ::= COMMA|JOIN */
140060 { 214, -2 }, /* (109) joinop ::= JOIN_KW JOIN */
140061 { 214, -3 }, /* (110) joinop ::= JOIN_KW nm JOIN */
140062 { 214, -4 }, /* (111) joinop ::= JOIN_KW nm nm JOIN */
140063 { 216, -2 }, /* (112) on_opt ::= ON expr */
140064 { 216, 0 }, /* (113) on_opt ::= */
140065 { 215, 0 }, /* (114) indexed_opt ::= */
140066 { 215, -3 }, /* (115) indexed_opt ::= INDEXED BY nm */
140067 { 215, -2 }, /* (116) indexed_opt ::= NOT INDEXED */
140068 { 217, -4 }, /* (117) using_opt ::= USING LP idlist RP */
140069 { 217, 0 }, /* (118) using_opt ::= */
140070 { 205, 0 }, /* (119) orderby_opt ::= */
140071 { 205, -3 }, /* (120) orderby_opt ::= ORDER BY sortlist */
140072 { 187, -4 }, /* (121) sortlist ::= sortlist COMMA expr sortorder */
140073 { 187, -2 }, /* (122) sortlist ::= expr sortorder */
140074 { 176, -1 }, /* (123) sortorder ::= ASC */
140075 { 176, -1 }, /* (124) sortorder ::= DESC */
140076 { 176, 0 }, /* (125) sortorder ::= */
140077 { 203, 0 }, /* (126) groupby_opt ::= */
140078 { 203, -3 }, /* (127) groupby_opt ::= GROUP BY nexprlist */
140079 { 204, 0 }, /* (128) having_opt ::= */
140080 { 204, -2 }, /* (129) having_opt ::= HAVING expr */
140081 { 206, 0 }, /* (130) limit_opt ::= */
140082 { 206, -2 }, /* (131) limit_opt ::= LIMIT expr */
140083 { 206, -4 }, /* (132) limit_opt ::= LIMIT expr OFFSET expr */
140084 { 206, -4 }, /* (133) limit_opt ::= LIMIT expr COMMA expr */
140085 { 149, -6 }, /* (134) cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140086 { 202, 0 }, /* (135) where_opt ::= */
140087 { 202, -2 }, /* (136) where_opt ::= WHERE expr */
140088 { 149, -8 }, /* (137) cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140089 { 219, -5 }, /* (138) setlist ::= setlist COMMA nm EQ expr */
140090 { 219, -7 }, /* (139) setlist ::= setlist COMMA LP idlist RP EQ expr */
140091 { 219, -3 }, /* (140) setlist ::= nm EQ expr */
140092 { 219, -5 }, /* (141) setlist ::= LP idlist RP EQ expr */
140093 { 149, -6 }, /* (142) cmd ::= with insert_cmd INTO fullname idlist_opt select */
140094 { 149, -7 }, /* (143) cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
140095 { 220, -2 }, /* (144) insert_cmd ::= INSERT orconf */
140096 { 220, -1 }, /* (145) insert_cmd ::= REPLACE */
140097 { 221, 0 }, /* (146) idlist_opt ::= */
140098 { 221, -3 }, /* (147) idlist_opt ::= LP idlist RP */
140099 { 218, -3 }, /* (148) idlist ::= idlist COMMA nm */
140100 { 218, -1 }, /* (149) idlist ::= nm */
140101 { 174, -3 }, /* (150) expr ::= LP expr RP */
140102 { 174, -1 }, /* (151) expr ::= ID|INDEXED */
140103 { 174, -1 }, /* (152) expr ::= JOIN_KW */
140104 { 174, -3 }, /* (153) expr ::= nm DOT nm */
140105 { 174, -5 }, /* (154) expr ::= nm DOT nm DOT nm */
140106 { 173, -1 }, /* (155) term ::= NULL|FLOAT|BLOB */
140107 { 173, -1 }, /* (156) term ::= STRING */
140108 { 173, -1 }, /* (157) term ::= INTEGER */
140109 { 174, -1 }, /* (158) expr ::= VARIABLE */
140110 { 174, -3 }, /* (159) expr ::= expr COLLATE ID|STRING */
140111 { 174, -6 }, /* (160) expr ::= CAST LP expr AS typetoken RP */
140112 { 174, -5 }, /* (161) expr ::= ID|INDEXED LP distinct exprlist RP */
140113 { 174, -4 }, /* (162) expr ::= ID|INDEXED LP STAR RP */
140114 { 173, -1 }, /* (163) term ::= CTIME_KW */
140115 { 174, -5 }, /* (164) expr ::= LP nexprlist COMMA expr RP */
140116 { 174, -3 }, /* (165) expr ::= expr AND expr */
140117 { 174, -3 }, /* (166) expr ::= expr OR expr */
140118 { 174, -3 }, /* (167) expr ::= expr LT|GT|GE|LE expr */
140119 { 174, -3 }, /* (168) expr ::= expr EQ|NE expr */
140120 { 174, -3 }, /* (169) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
140121 { 174, -3 }, /* (170) expr ::= expr PLUS|MINUS expr */
140122 { 174, -3 }, /* (171) expr ::= expr STAR|SLASH|REM expr */
140123 { 174, -3 }, /* (172) expr ::= expr CONCAT expr */
140124 { 222, -2 }, /* (173) likeop ::= NOT LIKE_KW|MATCH */
140125 { 174, -3 }, /* (174) expr ::= expr likeop expr */
140126 { 174, -5 }, /* (175) expr ::= expr likeop expr ESCAPE expr */
140127 { 174, -2 }, /* (176) expr ::= expr ISNULL|NOTNULL */
140128 { 174, -3 }, /* (177) expr ::= expr NOT NULL */
140129 { 174, -3 }, /* (178) expr ::= expr IS expr */
140130 { 174, -4 }, /* (179) expr ::= expr IS NOT expr */
140131 { 174, -2 }, /* (180) expr ::= NOT expr */
140132 { 174, -2 }, /* (181) expr ::= BITNOT expr */
140133 { 174, -2 }, /* (182) expr ::= MINUS expr */
140134 { 174, -2 }, /* (183) expr ::= PLUS expr */
140135 { 223, -1 }, /* (184) between_op ::= BETWEEN */
140136 { 223, -2 }, /* (185) between_op ::= NOT BETWEEN */
140137 { 174, -5 }, /* (186) expr ::= expr between_op expr AND expr */
140138 { 224, -1 }, /* (187) in_op ::= IN */
140139 { 224, -2 }, /* (188) in_op ::= NOT IN */
140140 { 174, -5 }, /* (189) expr ::= expr in_op LP exprlist RP */
140141 { 174, -3 }, /* (190) expr ::= LP select RP */
140142 { 174, -5 }, /* (191) expr ::= expr in_op LP select RP */
140143 { 174, -5 }, /* (192) expr ::= expr in_op nm dbnm paren_exprlist */
140144 { 174, -4 }, /* (193) expr ::= EXISTS LP select RP */
140145 { 174, -5 }, /* (194) expr ::= CASE case_operand case_exprlist case_else END */
140146 { 227, -5 }, /* (195) case_exprlist ::= case_exprlist WHEN expr THEN expr */
140147 { 227, -4 }, /* (196) case_exprlist ::= WHEN expr THEN expr */
140148 { 228, -2 }, /* (197) case_else ::= ELSE expr */
140149 { 228, 0 }, /* (198) case_else ::= */
140150 { 226, -1 }, /* (199) case_operand ::= expr */
140151 { 226, 0 }, /* (200) case_operand ::= */
140152 { 209, 0 }, /* (201) exprlist ::= */
140153 { 208, -3 }, /* (202) nexprlist ::= nexprlist COMMA expr */
140154 { 208, -1 }, /* (203) nexprlist ::= expr */
140155 { 225, 0 }, /* (204) paren_exprlist ::= */
140156 { 225, -3 }, /* (205) paren_exprlist ::= LP exprlist RP */
140157 { 149, -12 }, /* (206) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
140158 { 229, -1 }, /* (207) uniqueflag ::= UNIQUE */
140159 { 229, 0 }, /* (208) uniqueflag ::= */
140160 { 178, 0 }, /* (209) eidlist_opt ::= */
140161 { 178, -3 }, /* (210) eidlist_opt ::= LP eidlist RP */
140162 { 188, -5 }, /* (211) eidlist ::= eidlist COMMA nm collate sortorder */
140163 { 188, -3 }, /* (212) eidlist ::= nm collate sortorder */
140164 { 230, 0 }, /* (213) collate ::= */
140165 { 230, -2 }, /* (214) collate ::= COLLATE ID|STRING */
140166 { 149, -4 }, /* (215) cmd ::= DROP INDEX ifexists fullname */
140167 { 149, -1 }, /* (216) cmd ::= VACUUM */
140168 { 149, -2 }, /* (217) cmd ::= VACUUM nm */
140169 { 149, -3 }, /* (218) cmd ::= PRAGMA nm dbnm */
140170 { 149, -5 }, /* (219) cmd ::= PRAGMA nm dbnm EQ nmnum */
140171 { 149, -6 }, /* (220) cmd ::= PRAGMA nm dbnm LP nmnum RP */
140172 { 149, -5 }, /* (221) cmd ::= PRAGMA nm dbnm EQ minus_num */
140173 { 149, -6 }, /* (222) cmd ::= PRAGMA nm dbnm LP minus_num RP */
140174 { 169, -2 }, /* (223) plus_num ::= PLUS INTEGER|FLOAT */
140175 { 170, -2 }, /* (224) minus_num ::= MINUS INTEGER|FLOAT */
140176 { 149, -5 }, /* (225) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
140177 { 232, -11 }, /* (226) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
140178 { 234, -1 }, /* (227) trigger_time ::= BEFORE|AFTER */
140179 { 234, -2 }, /* (228) trigger_time ::= INSTEAD OF */
140180 { 234, 0 }, /* (229) trigger_time ::= */
140181 { 235, -1 }, /* (230) trigger_event ::= DELETE|INSERT */
140182 { 235, -1 }, /* (231) trigger_event ::= UPDATE */
140183 { 235, -3 }, /* (232) trigger_event ::= UPDATE OF idlist */
140184 { 237, 0 }, /* (233) when_clause ::= */
140185 { 237, -2 }, /* (234) when_clause ::= WHEN expr */
140186 { 233, -3 }, /* (235) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
140187 { 233, -2 }, /* (236) trigger_cmd_list ::= trigger_cmd SEMI */
140188 { 239, -3 }, /* (237) trnm ::= nm DOT nm */
140189 { 240, -3 }, /* (238) tridxby ::= INDEXED BY nm */
140190 { 240, -2 }, /* (239) tridxby ::= NOT INDEXED */
140191 { 238, -8 }, /* (240) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
140192 { 238, -7 }, /* (241) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt */
140193 { 238, -6 }, /* (242) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
140194 { 238, -3 }, /* (243) trigger_cmd ::= scanpt select scanpt */
140195 { 174, -4 }, /* (244) expr ::= RAISE LP IGNORE RP */
140196 { 174, -6 }, /* (245) expr ::= RAISE LP raisetype COMMA nm RP */
140197 { 192, -1 }, /* (246) raisetype ::= ROLLBACK */
140198 { 192, -1 }, /* (247) raisetype ::= ABORT */
140199 { 192, -1 }, /* (248) raisetype ::= FAIL */
140200 { 149, -4 }, /* (249) cmd ::= DROP TRIGGER ifexists fullname */
140201 { 149, -6 }, /* (250) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
140202 { 149, -3 }, /* (251) cmd ::= DETACH database_kw_opt expr */
140203 { 242, 0 }, /* (252) key_opt ::= */
140204 { 242, -2 }, /* (253) key_opt ::= KEY expr */
140205 { 149, -1 }, /* (254) cmd ::= REINDEX */
140206 { 149, -3 }, /* (255) cmd ::= REINDEX nm dbnm */
140207 { 149, -1 }, /* (256) cmd ::= ANALYZE */
140208 { 149, -3 }, /* (257) cmd ::= ANALYZE nm dbnm */
140209 { 149, -6 }, /* (258) cmd ::= ALTER TABLE fullname RENAME TO nm */
140210 { 149, -7 }, /* (259) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
140211 { 243, -1 }, /* (260) add_column_fullname ::= fullname */
140212 { 149, -1 }, /* (261) cmd ::= create_vtab */
140213 { 149, -4 }, /* (262) cmd ::= create_vtab LP vtabarglist RP */
140214 { 245, -8 }, /* (263) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
140215 { 247, 0 }, /* (264) vtabarg ::= */
140216 { 248, -1 }, /* (265) vtabargtoken ::= ANY */
140217 { 248, -3 }, /* (266) vtabargtoken ::= lp anylist RP */
140218 { 249, -1 }, /* (267) lp ::= LP */
140219 { 197, 0 }, /* (268) with ::= */
140220 { 197, -2 }, /* (269) with ::= WITH wqlist */
140221 { 197, -3 }, /* (270) with ::= WITH RECURSIVE wqlist */
140222 { 251, -6 }, /* (271) wqlist ::= nm eidlist_opt AS LP select RP */
140223 { 251, -8 }, /* (272) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
140224 { 144, -1 }, /* (273) input ::= cmdlist */
140225 { 145, -2 }, /* (274) cmdlist ::= cmdlist ecmd */
140226 { 145, -1 }, /* (275) cmdlist ::= ecmd */
140227 { 146, -1 }, /* (276) ecmd ::= SEMI */
140228 { 146, -3 }, /* (277) ecmd ::= explain cmdx SEMI */
140229 { 147, 0 }, /* (278) explain ::= */
140230 { 151, 0 }, /* (279) trans_opt ::= */
140231 { 151, -1 }, /* (280) trans_opt ::= TRANSACTION */
140232 { 151, -2 }, /* (281) trans_opt ::= TRANSACTION nm */
140233 { 153, -1 }, /* (282) savepoint_opt ::= SAVEPOINT */
140234 { 153, 0 }, /* (283) savepoint_opt ::= */
140235 { 149, -2 }, /* (284) cmd ::= create_table create_table_args */
140236 { 160, -4 }, /* (285) columnlist ::= columnlist COMMA columnname carglist */
140237 { 160, -2 }, /* (286) columnlist ::= columnname carglist */
140238 { 152, -1 }, /* (287) nm ::= ID|INDEXED */
140239 { 152, -1 }, /* (288) nm ::= STRING */
140240 { 152, -1 }, /* (289) nm ::= JOIN_KW */
140241 { 166, -1 }, /* (290) typetoken ::= typename */
140242 { 167, -1 }, /* (291) typename ::= ID|STRING */
140243 { 168, -1 }, /* (292) signed ::= plus_num */
140244 { 168, -1 }, /* (293) signed ::= minus_num */
140245 { 165, -2 }, /* (294) carglist ::= carglist ccons */
140246 { 165, 0 }, /* (295) carglist ::= */
140247 { 172, -2 }, /* (296) ccons ::= NULL onconf */
140248 { 161, -2 }, /* (297) conslist_opt ::= COMMA conslist */
140249 { 184, -3 }, /* (298) conslist ::= conslist tconscomma tcons */
140250 { 184, -1 }, /* (299) conslist ::= tcons */
140251 { 185, 0 }, /* (300) tconscomma ::= */
140252 { 189, -1 }, /* (301) defer_subclause_opt ::= defer_subclause */
140253 { 191, -1 }, /* (302) resolvetype ::= raisetype */
140254 { 195, -1 }, /* (303) selectnowith ::= oneselect */
140255 { 196, -1 }, /* (304) oneselect ::= values */
140256 { 210, -2 }, /* (305) sclp ::= selcollist COMMA */
140257 { 211, -1 }, /* (306) as ::= ID|STRING */
140258 { 174, -1 }, /* (307) expr ::= term */
140259 { 222, -1 }, /* (308) likeop ::= LIKE_KW|MATCH */
140260 { 209, -1 }, /* (309) exprlist ::= nexprlist */
140261 { 231, -1 }, /* (310) nmnum ::= plus_num */
140262 { 231, -1 }, /* (311) nmnum ::= nm */
140263 { 231, -1 }, /* (312) nmnum ::= ON */
140264 { 231, -1 }, /* (313) nmnum ::= DELETE */
140265 { 231, -1 }, /* (314) nmnum ::= DEFAULT */
140266 { 169, -1 }, /* (315) plus_num ::= INTEGER|FLOAT */
140267 { 236, 0 }, /* (316) foreach_clause ::= */
140268 { 236, -3 }, /* (317) foreach_clause ::= FOR EACH ROW */
140269 { 239, -1 }, /* (318) trnm ::= nm */
140270 { 240, 0 }, /* (319) tridxby ::= */
140271 { 241, -1 }, /* (320) database_kw_opt ::= DATABASE */
140272 { 241, 0 }, /* (321) database_kw_opt ::= */
140273 { 244, 0 }, /* (322) kwcolumn_opt ::= */
140274 { 244, -1 }, /* (323) kwcolumn_opt ::= COLUMNKW */
140275 { 246, -1 }, /* (324) vtabarglist ::= vtabarg */
140276 { 246, -3 }, /* (325) vtabarglist ::= vtabarglist COMMA vtabarg */
140277 { 247, -2 }, /* (326) vtabarg ::= vtabarg vtabargtoken */
140278 { 250, 0 }, /* (327) anylist ::= */
140279 { 250, -4 }, /* (328) anylist ::= anylist LP anylist RP */
140280 { 250, -2 }, /* (329) anylist ::= anylist ANY */
140281 };
140282
140283 static void yy_accept(yyParser*); /* Forward Declaration */
140284
140285 /*
140286 ** Perform a reduce action and the shift that must immediately
140287 ** follow the reduce.
140288 **
140289 ** The yyLookahead and yyLookaheadToken parameters provide reduce actions
140290 ** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
140291 ** if the lookahead token has already been consumed. As this procedure is
140292 ** only called from one place, optimizing compilers will in-line it, which
140293 ** means that the extra parameters have no performance impact.
140294 */
140295 static void yy_reduce(
140296 yyParser *yypParser, /* The parser */
140297 unsigned int yyruleno, /* Number of the rule by which to reduce */
140298 int yyLookahead, /* Lookahead token, or YYNOCODE if none */
140299 sqlite3ParserTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
140300 ){
140301 int yygoto; /* The next state */
140302 int yyact; /* The next action */
140303 yyStackEntry *yymsp; /* The top of the parser's stack */
140304 int yysize; /* Amount to pop the stack */
@@ -139879,12 +140305,18 @@
140305 sqlite3ParserARG_FETCH;
140306 yymsp = yypParser->yytos;
140307 #ifndef NDEBUG
140308 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
140309 yysize = yyRuleInfo[yyruleno].nrhs;
140310 if( yysize ){
140311 fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
140312 yyTracePrompt,
140313 yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
140314 }else{
140315 fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
140316 yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
140317 }
140318 }
140319 #endif /* NDEBUG */
140320
140321 /* Check that the stack is large enough to grow by a single entry
140322 ** if the RHS of the rule is empty. This ensures that there is room
@@ -139931,19 +140363,19 @@
140363 break;
140364 case 2: /* cmdx ::= cmd */
140365 { sqlite3FinishCoding(pParse); }
140366 break;
140367 case 3: /* cmd ::= BEGIN transtype trans_opt */
140368 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);}
140369 break;
140370 case 4: /* transtype ::= */
140371 {yymsp[1].minor.yy4 = TK_DEFERRED;}
140372 break;
140373 case 5: /* transtype ::= DEFERRED */
140374 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
140375 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
140376 {yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-X*/}
140377 break;
140378 case 8: /* cmd ::= COMMIT|END trans_opt */
140379 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
140380 {sqlite3EndTransaction(pParse,yymsp[-1].major);}
140381 break;
@@ -139962,61 +140394,61 @@
140394 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
140395 }
140396 break;
140397 case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
140398 {
140399 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4);
140400 }
140401 break;
140402 case 14: /* createkw ::= CREATE */
140403 {disableLookaside(pParse);}
140404 break;
140405 case 15: /* ifnotexists ::= */
140406 case 18: /* temp ::= */ yytestcase(yyruleno==18);
140407 case 21: /* table_options ::= */ yytestcase(yyruleno==21);
140408 case 42: /* autoinc ::= */ yytestcase(yyruleno==42);
140409 case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
140410 case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
140411 case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
140412 case 90: /* distinct ::= */ yytestcase(yyruleno==90);
140413 case 213: /* collate ::= */ yytestcase(yyruleno==213);
140414 {yymsp[1].minor.yy4 = 0;}
140415 break;
140416 case 16: /* ifnotexists ::= IF NOT EXISTS */
140417 {yymsp[-2].minor.yy4 = 1;}
140418 break;
140419 case 17: /* temp ::= TEMP */
140420 case 43: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==43);
140421 {yymsp[0].minor.yy4 = 1;}
140422 break;
140423 case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
140424 {
140425 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy4,0);
140426 }
140427 break;
140428 case 20: /* create_table_args ::= AS select */
140429 {
140430 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy387);
140431 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
140432 }
140433 break;
140434 case 22: /* table_options ::= WITHOUT nm */
140435 {
140436 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
140437 yymsp[-1].minor.yy4 = TF_WithoutRowid | TF_NoVisibleRowid;
140438 }else{
140439 yymsp[-1].minor.yy4 = 0;
140440 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
140441 }
140442 }
140443 break;
140444 case 23: /* columnname ::= nm typetoken */
140445 {sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
140446 break;
140447 case 24: /* typetoken ::= */
140448 case 60: /* conslist_opt ::= */ yytestcase(yyruleno==60);
140449 case 96: /* as ::= */ yytestcase(yyruleno==96);
140450 {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;}
140451 break;
140452 case 25: /* typetoken ::= typename LP signed RP */
140453 {
140454 yymsp[-3].minor.yy0.n = (int)(&yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy0.z);
@@ -140028,214 +140460,218 @@
140460 }
140461 break;
140462 case 27: /* typename ::= typename ID|STRING */
140463 {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
140464 break;
140465 case 28: /* scanpt ::= */
140466 {
140467 assert( yyLookahead!=YYNOCODE );
140468 yymsp[1].minor.yy336 = yyLookaheadToken.z;
140469 }
140470 break;
140471 case 29: /* ccons ::= CONSTRAINT nm */
140472 case 62: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==62);
140473 {pParse->constraintName = yymsp[0].minor.yy0;}
140474 break;
140475 case 30: /* ccons ::= DEFAULT scanpt term scanpt */
140476 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy336,yymsp[0].minor.yy336);}
140477 break;
140478 case 31: /* ccons ::= DEFAULT LP expr RP */
140479 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
140480 break;
140481 case 32: /* ccons ::= DEFAULT PLUS term scanpt */
140482 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy336);}
140483 break;
140484 case 33: /* ccons ::= DEFAULT MINUS term scanpt */
140485 {
140486 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy314, 0);
140487 sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy336);
140488 }
140489 break;
140490 case 34: /* ccons ::= DEFAULT scanpt ID|INDEXED */
140491 {
140492 Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
140493 sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
140494 }
140495 break;
140496 case 35: /* ccons ::= NOT NULL onconf */
140497 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);}
140498 break;
140499 case 36: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
140500 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);}
140501 break;
140502 case 37: /* ccons ::= UNIQUE onconf */
140503 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0,
 
 
140504 SQLITE_IDXTYPE_UNIQUE);}
140505 break;
140506 case 38: /* ccons ::= CHECK LP expr RP */
140507 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy314);}
140508 break;
140509 case 39: /* ccons ::= REFERENCES nm eidlist_opt refargs */
140510 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);}
140511 break;
140512 case 40: /* ccons ::= defer_subclause */
140513 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);}
140514 break;
140515 case 41: /* ccons ::= COLLATE ID|STRING */
140516 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
140517 break;
140518 case 44: /* refargs ::= */
140519 { yymsp[1].minor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */}
140520 break;
140521 case 45: /* refargs ::= refargs refarg */
140522 { yymsp[-1].minor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; }
140523 break;
140524 case 46: /* refarg ::= MATCH nm */
140525 { yymsp[-1].minor.yy215.value = 0; yymsp[-1].minor.yy215.mask = 0x000000; }
140526 break;
140527 case 47: /* refarg ::= ON INSERT refact */
140528 { yymsp[-2].minor.yy215.value = 0; yymsp[-2].minor.yy215.mask = 0x000000; }
140529 break;
140530 case 48: /* refarg ::= ON DELETE refact */
140531 { yymsp[-2].minor.yy215.value = yymsp[0].minor.yy4; yymsp[-2].minor.yy215.mask = 0x0000ff; }
140532 break;
140533 case 49: /* refarg ::= ON UPDATE refact */
140534 { yymsp[-2].minor.yy215.value = yymsp[0].minor.yy4<<8; yymsp[-2].minor.yy215.mask = 0x00ff00; }
140535 break;
140536 case 50: /* refact ::= SET NULL */
140537 { yymsp[-1].minor.yy4 = OE_SetNull; /* EV: R-33326-45252 */}
140538 break;
140539 case 51: /* refact ::= SET DEFAULT */
140540 { yymsp[-1].minor.yy4 = OE_SetDflt; /* EV: R-33326-45252 */}
140541 break;
140542 case 52: /* refact ::= CASCADE */
140543 { yymsp[0].minor.yy4 = OE_Cascade; /* EV: R-33326-45252 */}
140544 break;
140545 case 53: /* refact ::= RESTRICT */
140546 { yymsp[0].minor.yy4 = OE_Restrict; /* EV: R-33326-45252 */}
140547 break;
140548 case 54: /* refact ::= NO ACTION */
140549 { yymsp[-1].minor.yy4 = OE_None; /* EV: R-33326-45252 */}
140550 break;
140551 case 55: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
140552 {yymsp[-2].minor.yy4 = 0;}
140553 break;
140554 case 56: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
140555 case 71: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==71);
140556 case 144: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==144);
140557 {yymsp[-1].minor.yy4 = yymsp[0].minor.yy4;}
140558 break;
140559 case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
140560 case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
140561 case 185: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==185);
140562 case 188: /* in_op ::= NOT IN */ yytestcase(yyruleno==188);
140563 case 214: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==214);
140564 {yymsp[-1].minor.yy4 = 1;}
140565 break;
140566 case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
140567 {yymsp[-1].minor.yy4 = 0;}
140568 break;
140569 case 61: /* tconscomma ::= COMMA */
140570 {pParse->constraintName.n = 0;}
140571 break;
140572 case 63: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
140573 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);}
140574 break;
140575 case 64: /* tcons ::= UNIQUE LP sortlist RP onconf */
140576 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0,
140577 SQLITE_IDXTYPE_UNIQUE);}
140578 break;
140579 case 65: /* tcons ::= CHECK LP expr RP onconf */
140580 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy314);}
140581 break;
140582 case 66: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
140583 {
140584 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4);
140585 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4);
140586 }
140587 break;
140588 case 68: /* onconf ::= */
140589 case 70: /* orconf ::= */ yytestcase(yyruleno==70);
140590 {yymsp[1].minor.yy4 = OE_Default;}
140591 break;
140592 case 69: /* onconf ::= ON CONFLICT resolvetype */
140593 {yymsp[-2].minor.yy4 = yymsp[0].minor.yy4;}
140594 break;
140595 case 72: /* resolvetype ::= IGNORE */
140596 {yymsp[0].minor.yy4 = OE_Ignore;}
140597 break;
140598 case 73: /* resolvetype ::= REPLACE */
140599 case 145: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==145);
140600 {yymsp[0].minor.yy4 = OE_Replace;}
140601 break;
140602 case 74: /* cmd ::= DROP TABLE ifexists fullname */
140603 {
140604 sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4);
140605 }
140606 break;
140607 case 77: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
140608 {
140609 sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[0].minor.yy387, yymsp[-7].minor.yy4, yymsp[-5].minor.yy4);
140610 }
140611 break;
140612 case 78: /* cmd ::= DROP VIEW ifexists fullname */
140613 {
140614 sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4);
140615 }
140616 break;
140617 case 79: /* cmd ::= select */
140618 {
140619 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
140620 sqlite3Select(pParse, yymsp[0].minor.yy387, &dest);
140621 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
140622 }
140623 break;
140624 case 80: /* select ::= with selectnowith */
140625 {
140626 Select *p = yymsp[0].minor.yy387;
140627 if( p ){
140628 p->pWith = yymsp[-1].minor.yy451;
140629 parserDoubleLinkSelect(pParse, p);
140630 }else{
140631 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy451);
140632 }
140633 yymsp[-1].minor.yy387 = p; /*A-overwrites-W*/
140634 }
140635 break;
140636 case 81: /* selectnowith ::= selectnowith multiselect_op oneselect */
140637 {
140638 Select *pRhs = yymsp[0].minor.yy387;
140639 Select *pLhs = yymsp[-2].minor.yy387;
140640 if( pRhs && pRhs->pPrior ){
140641 SrcList *pFrom;
140642 Token x;
140643 x.n = 0;
140644 parserDoubleLinkSelect(pParse, pRhs);
140645 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
140646 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
140647 }
140648 if( pRhs ){
140649 pRhs->op = (u8)yymsp[-1].minor.yy4;
140650 pRhs->pPrior = pLhs;
140651 if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
140652 pRhs->selFlags &= ~SF_MultiValue;
140653 if( yymsp[-1].minor.yy4!=TK_ALL ) pParse->hasCompound = 1;
140654 }else{
140655 sqlite3SelectDelete(pParse->db, pLhs);
140656 }
140657 yymsp[-2].minor.yy387 = pRhs;
140658 }
140659 break;
140660 case 82: /* multiselect_op ::= UNION */
140661 case 84: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==84);
140662 {yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-OP*/}
140663 break;
140664 case 83: /* multiselect_op ::= UNION ALL */
140665 {yymsp[-1].minor.yy4 = TK_ALL;}
140666 break;
140667 case 85: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
140668 {
140669 #if SELECTTRACE_ENABLED
140670 Token s = yymsp[-8].minor.yy0; /*A-overwrites-S*/
140671 #endif
140672 yymsp[-8].minor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy4,yymsp[0].minor.yy314);
140673 #if SELECTTRACE_ENABLED
140674 /* Populate the Select.zSelName[] string that is used to help with
140675 ** query planner debugging, to differentiate between multiple Select
140676 ** objects in a complex query.
140677 **
@@ -140242,496 +140678,483 @@
140678 ** If the SELECT keyword is immediately followed by a C-style comment
140679 ** then extract the first few alphanumeric characters from within that
140680 ** comment to be the zSelName value. Otherwise, the label is #N where
140681 ** is an integer that is incremented with each SELECT statement seen.
140682 */
140683 if( yymsp[-8].minor.yy387!=0 ){
140684 const char *z = s.z+6;
140685 int i;
140686 sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName, "#%d",
140687 ++pParse->nSelect);
140688 while( z[0]==' ' ) z++;
140689 if( z[0]=='/' && z[1]=='*' ){
140690 z += 2;
140691 while( z[0]==' ' ) z++;
140692 for(i=0; sqlite3Isalnum(z[i]); i++){}
140693 sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName, "%.*s", i, z);
140694 }
140695 }
140696 #endif /* SELECTRACE_ENABLED */
140697 }
140698 break;
140699 case 86: /* values ::= VALUES LP nexprlist RP */
140700 {
140701 yymsp[-3].minor.yy387 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy322,0,0,0,0,0,SF_Values,0);
140702 }
140703 break;
140704 case 87: /* values ::= values COMMA LP exprlist RP */
140705 {
140706 Select *pRight, *pLeft = yymsp[-4].minor.yy387;
140707 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy322,0,0,0,0,0,SF_Values|SF_MultiValue,0);
140708 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
140709 if( pRight ){
140710 pRight->op = TK_ALL;
140711 pRight->pPrior = pLeft;
140712 yymsp[-4].minor.yy387 = pRight;
140713 }else{
140714 yymsp[-4].minor.yy387 = pLeft;
140715 }
140716 }
140717 break;
140718 case 88: /* distinct ::= DISTINCT */
140719 {yymsp[0].minor.yy4 = SF_Distinct;}
140720 break;
140721 case 89: /* distinct ::= ALL */
140722 {yymsp[0].minor.yy4 = SF_All;}
140723 break;
140724 case 91: /* sclp ::= */
140725 case 119: /* orderby_opt ::= */ yytestcase(yyruleno==119);
140726 case 126: /* groupby_opt ::= */ yytestcase(yyruleno==126);
140727 case 201: /* exprlist ::= */ yytestcase(yyruleno==201);
140728 case 204: /* paren_exprlist ::= */ yytestcase(yyruleno==204);
140729 case 209: /* eidlist_opt ::= */ yytestcase(yyruleno==209);
140730 {yymsp[1].minor.yy322 = 0;}
140731 break;
140732 case 92: /* selcollist ::= sclp scanpt expr scanpt as */
140733 {
140734 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy314);
140735 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy322, &yymsp[0].minor.yy0, 1);
140736 sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy322,yymsp[-3].minor.yy336,yymsp[-1].minor.yy336);
140737 }
140738 break;
140739 case 93: /* selcollist ::= sclp scanpt STAR */
140740 {
140741 Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
140742 yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, p);
140743 }
140744 break;
140745 case 94: /* selcollist ::= sclp scanpt nm DOT STAR */
140746 {
140747 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
140748 Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140749 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
140750 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
140751 }
140752 break;
140753 case 95: /* as ::= AS nm */
140754 case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106);
140755 case 223: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==223);
140756 case 224: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==224);
140757 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
140758 break;
140759 case 97: /* from ::= */
140760 {yymsp[1].minor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy259));}
140761 break;
140762 case 98: /* from ::= FROM seltablist */
140763 {
140764 yymsp[-1].minor.yy259 = yymsp[0].minor.yy259;
140765 sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy259);
140766 }
140767 break;
140768 case 99: /* stl_prefix ::= seltablist joinop */
140769 {
140770 if( ALWAYS(yymsp[-1].minor.yy259 && yymsp[-1].minor.yy259->nSrc>0) ) yymsp[-1].minor.yy259->a[yymsp[-1].minor.yy259->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy4;
140771 }
140772 break;
140773 case 100: /* stl_prefix ::= */
140774 {yymsp[1].minor.yy259 = 0;}
140775 break;
140776 case 101: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
140777 {
140778 yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140779 sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy259, &yymsp[-2].minor.yy0);
140780 }
140781 break;
140782 case 102: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
140783 {
140784 yymsp[-8].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy259,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140785 sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy259, yymsp[-4].minor.yy322);
140786 }
140787 break;
140788 case 103: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
140789 {
140790 yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140791 }
140792 break;
140793 case 104: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
140794 {
140795 if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){
140796 yymsp[-6].minor.yy259 = yymsp[-4].minor.yy259;
140797 }else if( yymsp[-4].minor.yy259->nSrc==1 ){
140798 yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140799 if( yymsp[-6].minor.yy259 ){
140800 struct SrcList_item *pNew = &yymsp[-6].minor.yy259->a[yymsp[-6].minor.yy259->nSrc-1];
140801 struct SrcList_item *pOld = yymsp[-4].minor.yy259->a;
140802 pNew->zName = pOld->zName;
140803 pNew->zDatabase = pOld->zDatabase;
140804 pNew->pSelect = pOld->pSelect;
140805 pOld->zName = pOld->zDatabase = 0;
140806 pOld->pSelect = 0;
140807 }
140808 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy259);
140809 }else{
140810 Select *pSubquery;
140811 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259);
140812 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,SF_NestedFrom,0);
140813 yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384);
140814 }
140815 }
140816 break;
140817 case 105: /* dbnm ::= */
140818 case 114: /* indexed_opt ::= */ yytestcase(yyruleno==114);
140819 {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
140820 break;
140821 case 107: /* fullname ::= nm dbnm */
140822 {yymsp[-1].minor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
140823 break;
140824 case 108: /* joinop ::= COMMA|JOIN */
140825 { yymsp[0].minor.yy4 = JT_INNER; }
140826 break;
140827 case 109: /* joinop ::= JOIN_KW JOIN */
140828 {yymsp[-1].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
140829 break;
140830 case 110: /* joinop ::= JOIN_KW nm JOIN */
140831 {yymsp[-2].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
140832 break;
140833 case 111: /* joinop ::= JOIN_KW nm nm JOIN */
140834 {yymsp[-3].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
140835 break;
140836 case 112: /* on_opt ::= ON expr */
140837 case 129: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==129);
140838 case 136: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==136);
140839 case 197: /* case_else ::= ELSE expr */ yytestcase(yyruleno==197);
140840 {yymsp[-1].minor.yy314 = yymsp[0].minor.yy314;}
140841 break;
140842 case 113: /* on_opt ::= */
140843 case 128: /* having_opt ::= */ yytestcase(yyruleno==128);
140844 case 130: /* limit_opt ::= */ yytestcase(yyruleno==130);
140845 case 135: /* where_opt ::= */ yytestcase(yyruleno==135);
140846 case 198: /* case_else ::= */ yytestcase(yyruleno==198);
140847 case 200: /* case_operand ::= */ yytestcase(yyruleno==200);
140848 {yymsp[1].minor.yy314 = 0;}
140849 break;
140850 case 115: /* indexed_opt ::= INDEXED BY nm */
140851 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
140852 break;
140853 case 116: /* indexed_opt ::= NOT INDEXED */
140854 {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
140855 break;
140856 case 117: /* using_opt ::= USING LP idlist RP */
140857 {yymsp[-3].minor.yy384 = yymsp[-1].minor.yy384;}
140858 break;
140859 case 118: /* using_opt ::= */
140860 case 146: /* idlist_opt ::= */ yytestcase(yyruleno==146);
140861 {yymsp[1].minor.yy384 = 0;}
140862 break;
140863 case 120: /* orderby_opt ::= ORDER BY sortlist */
140864 case 127: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==127);
140865 {yymsp[-2].minor.yy322 = yymsp[0].minor.yy322;}
140866 break;
140867 case 121: /* sortlist ::= sortlist COMMA expr sortorder */
140868 {
140869 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy314);
140870 sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy322,yymsp[0].minor.yy4);
140871 }
140872 break;
140873 case 122: /* sortlist ::= expr sortorder */
140874 {
140875 yymsp[-1].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy314); /*A-overwrites-Y*/
140876 sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy322,yymsp[0].minor.yy4);
140877 }
140878 break;
140879 case 123: /* sortorder ::= ASC */
140880 {yymsp[0].minor.yy4 = SQLITE_SO_ASC;}
140881 break;
140882 case 124: /* sortorder ::= DESC */
140883 {yymsp[0].minor.yy4 = SQLITE_SO_DESC;}
140884 break;
140885 case 125: /* sortorder ::= */
140886 {yymsp[1].minor.yy4 = SQLITE_SO_UNDEFINED;}
140887 break;
140888 case 131: /* limit_opt ::= LIMIT expr */
140889 {yymsp[-1].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy314,0);}
140890 break;
140891 case 132: /* limit_opt ::= LIMIT expr OFFSET expr */
140892 {yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy314,yymsp[0].minor.yy314);}
140893 break;
140894 case 133: /* limit_opt ::= LIMIT expr COMMA expr */
140895 {yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy314,yymsp[-2].minor.yy314);}
140896 break;
140897 case 134: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140898 {
140899 sqlite3WithPush(pParse, yymsp[-5].minor.yy451, 1);
140900 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0);
140901 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314,0,0);
140902 }
140903 break;
140904 case 137: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140905 {
140906 sqlite3WithPush(pParse, yymsp[-7].minor.yy451, 1);
140907 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0);
140908 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list");
140909 sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy4,0,0);
140910 }
140911 break;
140912 case 138: /* setlist ::= setlist COMMA nm EQ expr */
140913 {
140914 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy314);
140915 sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, 1);
140916 }
140917 break;
140918 case 139: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
140919 {
140920 yymsp[-6].minor.yy322 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy322, yymsp[-3].minor.yy384, yymsp[0].minor.yy314);
140921 }
140922 break;
140923 case 140: /* setlist ::= nm EQ expr */
140924 {
140925 yylhsminor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy314);
140926 sqlite3ExprListSetName(pParse, yylhsminor.yy322, &yymsp[-2].minor.yy0, 1);
140927 }
140928 yymsp[-2].minor.yy322 = yylhsminor.yy322;
140929 break;
140930 case 141: /* setlist ::= LP idlist RP EQ expr */
140931 {
140932 yymsp[-4].minor.yy322 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy384, yymsp[0].minor.yy314);
140933 }
140934 break;
140935 case 142: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */
140936 {
140937 sqlite3WithPush(pParse, yymsp[-5].minor.yy451, 1);
140938 sqlite3Insert(pParse, yymsp[-2].minor.yy259, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy4);
140939 }
140940 break;
140941 case 143: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
140942 {
140943 sqlite3WithPush(pParse, yymsp[-6].minor.yy451, 1);
140944 sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy4);
140945 }
140946 break;
140947 case 147: /* idlist_opt ::= LP idlist RP */
140948 {yymsp[-2].minor.yy384 = yymsp[-1].minor.yy384;}
140949 break;
140950 case 148: /* idlist ::= idlist COMMA nm */
140951 {yymsp[-2].minor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
140952 break;
140953 case 149: /* idlist ::= nm */
140954 {yymsp[0].minor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
140955 break;
140956 case 150: /* expr ::= LP expr RP */
140957 {yymsp[-2].minor.yy314 = yymsp[-1].minor.yy314;}
140958 break;
140959 case 151: /* expr ::= ID|INDEXED */
140960 case 152: /* expr ::= JOIN_KW */ yytestcase(yyruleno==152);
140961 {yymsp[0].minor.yy314=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
140962 break;
140963 case 153: /* expr ::= nm DOT nm */
140964 {
140965 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140966 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
140967 yylhsminor.yy314 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
 
140968 }
140969 yymsp[-2].minor.yy314 = yylhsminor.yy314;
140970 break;
140971 case 154: /* expr ::= nm DOT nm DOT nm */
140972 {
140973 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
140974 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
140975 Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
140976 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
140977 yylhsminor.yy314 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
140978 }
140979 yymsp[-4].minor.yy314 = yylhsminor.yy314;
140980 break;
140981 case 155: /* term ::= NULL|FLOAT|BLOB */
140982 case 156: /* term ::= STRING */ yytestcase(yyruleno==156);
140983 {yymsp[0].minor.yy314=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
140984 break;
140985 case 157: /* term ::= INTEGER */
140986 {
140987 yylhsminor.yy314 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
140988 }
140989 yymsp[0].minor.yy314 = yylhsminor.yy314;
140990 break;
140991 case 158: /* expr ::= VARIABLE */
 
 
140992 {
140993 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
140994 u32 n = yymsp[0].minor.yy0.n;
140995 yymsp[0].minor.yy314 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
140996 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy314, n);
140997 }else{
140998 /* When doing a nested parse, one can include terms in an expression
140999 ** that look like this: #1 #2 ... These terms refer to registers
141000 ** in the virtual machine. #N is the N-th register. */
141001 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
141002 assert( t.n>=2 );
 
141003 if( pParse->nested==0 ){
141004 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
141005 yymsp[0].minor.yy314 = 0;
141006 }else{
141007 yymsp[0].minor.yy314 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
141008 if( yymsp[0].minor.yy314 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy314->iTable);
141009 }
141010 }
141011 }
141012 break;
141013 case 159: /* expr ::= expr COLLATE ID|STRING */
141014 {
141015 yymsp[-2].minor.yy314 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy314, &yymsp[0].minor.yy0, 1);
141016 }
141017 break;
141018 case 160: /* expr ::= CAST LP expr AS typetoken RP */
141019 {
141020 yymsp[-5].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
141021 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy314, yymsp[-3].minor.yy314, 0);
141022 }
141023 break;
141024 case 161: /* expr ::= ID|INDEXED LP distinct exprlist RP */
141025 {
141026 if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
 
 
141027 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
141028 }
141029 yylhsminor.yy314 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
141030 if( yymsp[-2].minor.yy4==SF_Distinct && yylhsminor.yy314 ){
141031 yylhsminor.yy314->flags |= EP_Distinct;
141032 }
141033 }
141034 yymsp[-4].minor.yy314 = yylhsminor.yy314;
141035 break;
141036 case 162: /* expr ::= ID|INDEXED LP STAR RP */
141037 {
141038 yylhsminor.yy314 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
141039 }
141040 yymsp[-3].minor.yy314 = yylhsminor.yy314;
141041 break;
141042 case 163: /* term ::= CTIME_KW */
141043 {
141044 yylhsminor.yy314 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
141045 }
141046 yymsp[0].minor.yy314 = yylhsminor.yy314;
141047 break;
141048 case 164: /* expr ::= LP nexprlist COMMA expr RP */
141049 {
141050 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy322, yymsp[-1].minor.yy314);
141051 yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
141052 if( yymsp[-4].minor.yy314 ){
141053 yymsp[-4].minor.yy314->x.pList = pList;
 
 
 
 
141054 }else{
141055 sqlite3ExprListDelete(pParse->db, pList);
141056 }
141057 }
141058 break;
141059 case 165: /* expr ::= expr AND expr */
141060 case 166: /* expr ::= expr OR expr */ yytestcase(yyruleno==166);
141061 case 167: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==167);
141062 case 168: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==168);
141063 case 169: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==169);
141064 case 170: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==170);
141065 case 171: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==171);
141066 case 172: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==172);
141067 {yymsp[-2].minor.yy314=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy314,yymsp[0].minor.yy314);}
141068 break;
141069 case 173: /* likeop ::= NOT LIKE_KW|MATCH */
 
141070 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
141071 break;
141072 case 174: /* expr ::= expr likeop expr */
141073 {
141074 ExprList *pList;
141075 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
141076 yymsp[-1].minor.yy0.n &= 0x7fffffff;
141077 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy314);
141078 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy314);
141079 yymsp[-2].minor.yy314 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0);
141080 if( bNot ) yymsp[-2].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy314, 0);
141081 if( yymsp[-2].minor.yy314 ) yymsp[-2].minor.yy314->flags |= EP_InfixFunc;
 
141082 }
141083 break;
141084 case 175: /* expr ::= expr likeop expr ESCAPE expr */
141085 {
141086 ExprList *pList;
141087 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
141088 yymsp[-3].minor.yy0.n &= 0x7fffffff;
141089 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314);
141090 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy314);
141091 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy314);
141092 yymsp[-4].minor.yy314 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0);
141093 if( bNot ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
141094 if( yymsp[-4].minor.yy314 ) yymsp[-4].minor.yy314->flags |= EP_InfixFunc;
141095 }
141096 break;
141097 case 176: /* expr ::= expr ISNULL|NOTNULL */
141098 {yymsp[-1].minor.yy314 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy314,0);}
141099 break;
141100 case 177: /* expr ::= expr NOT NULL */
141101 {yymsp[-2].minor.yy314 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy314,0);}
141102 break;
141103 case 178: /* expr ::= expr IS expr */
141104 {
141105 yymsp[-2].minor.yy314 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy314,yymsp[0].minor.yy314);
141106 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy314, yymsp[-2].minor.yy314, TK_ISNULL);
141107 }
141108 break;
141109 case 179: /* expr ::= expr IS NOT expr */
141110 {
141111 yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy314,yymsp[0].minor.yy314);
141112 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy314, yymsp[-3].minor.yy314, TK_NOTNULL);
141113 }
141114 break;
141115 case 180: /* expr ::= NOT expr */
141116 case 181: /* expr ::= BITNOT expr */ yytestcase(yyruleno==181);
141117 {yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy314, 0);/*A-overwrites-B*/}
141118 break;
141119 case 182: /* expr ::= MINUS expr */
141120 {yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy314, 0);}
141121 break;
141122 case 183: /* expr ::= PLUS expr */
141123 {yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy314, 0);}
141124 break;
141125 case 184: /* between_op ::= BETWEEN */
141126 case 187: /* in_op ::= IN */ yytestcase(yyruleno==187);
141127 {yymsp[0].minor.yy4 = 0;}
141128 break;
141129 case 186: /* expr ::= expr between_op expr AND expr */
141130 {
141131 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314);
141132 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy314);
141133 yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy314, 0);
141134 if( yymsp[-4].minor.yy314 ){
141135 yymsp[-4].minor.yy314->x.pList = pList;
 
141136 }else{
141137 sqlite3ExprListDelete(pParse->db, pList);
141138 }
141139 if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
 
141140 }
141141 break;
141142 case 189: /* expr ::= expr in_op LP exprlist RP */
141143 {
141144 if( yymsp[-1].minor.yy322==0 ){
141145 /* Expressions of the form
141146 **
141147 ** expr1 IN ()
141148 ** expr1 NOT IN ()
141149 **
141150 ** simplify to constants 0 (false) and 1 (true), respectively,
141151 ** regardless of the value of expr1.
141152 */
141153 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy314);
141154 yymsp[-4].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy4],1);
141155 }else if( yymsp[-1].minor.yy322->nExpr==1 ){
141156 /* Expressions of the form:
141157 **
141158 ** expr1 IN (?1)
141159 ** expr1 NOT IN (?2)
141160 **
@@ -140744,402 +141167,398 @@
141167 ** But, the RHS of the == or <> is marked with the EP_Generic flag
141168 ** so that it may not contribute to the computation of comparison
141169 ** affinity or the collating sequence to use for comparison. Otherwise,
141170 ** the semantics would be subtly different from IN or NOT IN.
141171 */
141172 Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr;
141173 yymsp[-1].minor.yy322->a[0].pExpr = 0;
141174 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
141175 /* pRHS cannot be NULL because a malloc error would have been detected
141176 ** before now and control would have never reached this point */
141177 if( ALWAYS(pRHS) ){
141178 pRHS->flags &= ~EP_Collate;
141179 pRHS->flags |= EP_Generic;
141180 }
141181 yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, yymsp[-3].minor.yy4 ? TK_NE : TK_EQ, yymsp[-4].minor.yy314, pRHS);
141182 }else{
141183 yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0);
141184 if( yymsp[-4].minor.yy314 ){
141185 yymsp[-4].minor.yy314->x.pList = yymsp[-1].minor.yy322;
141186 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy314);
141187 }else{
141188 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
141189 }
141190 if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
141191 }
141192 }
141193 break;
141194 case 190: /* expr ::= LP select RP */
141195 {
141196 yymsp[-2].minor.yy314 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
141197 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy314, yymsp[-1].minor.yy387);
141198 }
141199 break;
141200 case 191: /* expr ::= expr in_op LP select RP */
141201 {
141202 yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0);
141203 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy314, yymsp[-1].minor.yy387);
141204 if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
141205 }
141206 break;
141207 case 192: /* expr ::= expr in_op nm dbnm paren_exprlist */
 
 
 
141208 {
141209 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
141210 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
141211 if( yymsp[0].minor.yy322 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy322);
141212 yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0);
141213 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy314, pSelect);
141214 if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0);
 
141215 }
141216 break;
141217 case 193: /* expr ::= EXISTS LP select RP */
141218 {
141219 Expr *p;
141220 p = yymsp[-3].minor.yy314 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
141221 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy387);
141222 }
141223 break;
141224 case 194: /* expr ::= CASE case_operand case_exprlist case_else END */
141225 {
141226 yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, 0);
141227 if( yymsp[-4].minor.yy314 ){
141228 yymsp[-4].minor.yy314->x.pList = yymsp[-1].minor.yy314 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy314) : yymsp[-2].minor.yy322;
141229 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy314);
141230 }else{
141231 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
141232 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy314);
141233 }
141234 }
141235 break;
141236 case 195: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
141237 {
141238 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy314);
141239 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy314);
141240 }
141241 break;
141242 case 196: /* case_exprlist ::= WHEN expr THEN expr */
141243 {
141244 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314);
141245 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy314);
141246 }
141247 break;
141248 case 199: /* case_operand ::= expr */
141249 {yymsp[0].minor.yy314 = yymsp[0].minor.yy314; /*A-overwrites-X*/}
141250 break;
141251 case 202: /* nexprlist ::= nexprlist COMMA expr */
141252 {yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy314);}
141253 break;
141254 case 203: /* nexprlist ::= expr */
141255 {yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy314); /*A-overwrites-Y*/}
141256 break;
141257 case 205: /* paren_exprlist ::= LP exprlist RP */
141258 case 210: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==210);
141259 {yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
141260 break;
141261 case 206: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
 
 
141262 {
141263 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
141264 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy4,
141265 &yymsp[-11].minor.yy0, yymsp[0].minor.yy314, SQLITE_SO_ASC, yymsp[-8].minor.yy4, SQLITE_IDXTYPE_APPDEF);
141266 }
141267 break;
141268 case 207: /* uniqueflag ::= UNIQUE */
141269 case 247: /* raisetype ::= ABORT */ yytestcase(yyruleno==247);
141270 {yymsp[0].minor.yy4 = OE_Abort;}
141271 break;
141272 case 208: /* uniqueflag ::= */
141273 {yymsp[1].minor.yy4 = OE_None;}
141274 break;
141275 case 211: /* eidlist ::= eidlist COMMA nm collate sortorder */
141276 {
141277 yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy4, yymsp[0].minor.yy4);
141278 }
141279 break;
141280 case 212: /* eidlist ::= nm collate sortorder */
141281 {
141282 yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy4, yymsp[0].minor.yy4); /*A-overwrites-Y*/
141283 }
141284 break;
141285 case 215: /* cmd ::= DROP INDEX ifexists fullname */
141286 {sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);}
141287 break;
141288 case 216: /* cmd ::= VACUUM */
141289 {sqlite3Vacuum(pParse,0);}
141290 break;
141291 case 217: /* cmd ::= VACUUM nm */
141292 {sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
141293 break;
141294 case 218: /* cmd ::= PRAGMA nm dbnm */
141295 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
141296 break;
141297 case 219: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
141298 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
141299 break;
141300 case 220: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
141301 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
141302 break;
141303 case 221: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
141304 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
141305 break;
141306 case 222: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
141307 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
141308 break;
141309 case 225: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
141310 {
141311 Token all;
141312 all.z = yymsp[-3].minor.yy0.z;
141313 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
141314 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
141315 }
141316 break;
141317 case 226: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
141318 {
141319 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4);
141320 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
141321 }
141322 break;
141323 case 227: /* trigger_time ::= BEFORE|AFTER */
141324 { yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-X*/ }
141325 break;
141326 case 228: /* trigger_time ::= INSTEAD OF */
141327 { yymsp[-1].minor.yy4 = TK_INSTEAD;}
141328 break;
141329 case 229: /* trigger_time ::= */
141330 { yymsp[1].minor.yy4 = TK_BEFORE; }
141331 break;
141332 case 230: /* trigger_event ::= DELETE|INSERT */
141333 case 231: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==231);
141334 {yymsp[0].minor.yy90.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy90.b = 0;}
141335 break;
141336 case 232: /* trigger_event ::= UPDATE OF idlist */
141337 {yymsp[-2].minor.yy90.a = TK_UPDATE; yymsp[-2].minor.yy90.b = yymsp[0].minor.yy384;}
141338 break;
141339 case 233: /* when_clause ::= */
141340 case 252: /* key_opt ::= */ yytestcase(yyruleno==252);
141341 { yymsp[1].minor.yy314 = 0; }
141342 break;
141343 case 234: /* when_clause ::= WHEN expr */
141344 case 253: /* key_opt ::= KEY expr */ yytestcase(yyruleno==253);
141345 { yymsp[-1].minor.yy314 = yymsp[0].minor.yy314; }
141346 break;
141347 case 235: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
141348 {
141349 assert( yymsp[-2].minor.yy203!=0 );
141350 yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203;
141351 yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203;
141352 }
141353 break;
141354 case 236: /* trigger_cmd_list ::= trigger_cmd SEMI */
141355 {
141356 assert( yymsp[-1].minor.yy203!=0 );
141357 yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203;
141358 }
141359 break;
141360 case 237: /* trnm ::= nm DOT nm */
141361 {
141362 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
141363 sqlite3ErrorMsg(pParse,
141364 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
141365 "statements within triggers");
141366 }
141367 break;
141368 case 238: /* tridxby ::= INDEXED BY nm */
141369 {
141370 sqlite3ErrorMsg(pParse,
141371 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
141372 "within triggers");
141373 }
141374 break;
141375 case 239: /* tridxby ::= NOT INDEXED */
141376 {
141377 sqlite3ErrorMsg(pParse,
141378 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
141379 "within triggers");
141380 }
141381 break;
141382 case 240: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
141383 {yylhsminor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy314, yymsp[-6].minor.yy4, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy336);}
141384 yymsp[-7].minor.yy203 = yylhsminor.yy203;
141385 break;
141386 case 241: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt */
141387 {yylhsminor.yy203 = sqlite3TriggerInsertStep(pParse->db,&yymsp[-3].minor.yy0,yymsp[-2].minor.yy384,yymsp[-1].minor.yy387,yymsp[-5].minor.yy4,yymsp[-6].minor.yy336,yymsp[0].minor.yy336);/*yylhsminor.yy203-overwrites-yymsp[-5].minor.yy4*/}
141388 yymsp[-6].minor.yy203 = yylhsminor.yy203;
141389 break;
141390 case 242: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
141391 {yylhsminor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy314, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy336);}
141392 yymsp[-5].minor.yy203 = yylhsminor.yy203;
141393 break;
141394 case 243: /* trigger_cmd ::= scanpt select scanpt */
141395 {yylhsminor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy387, yymsp[-2].minor.yy336, yymsp[0].minor.yy336); /*yylhsminor.yy203-overwrites-yymsp[-1].minor.yy387*/}
141396 yymsp[-2].minor.yy203 = yylhsminor.yy203;
141397 break;
141398 case 244: /* expr ::= RAISE LP IGNORE RP */
141399 {
141400 yymsp[-3].minor.yy314 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
141401 if( yymsp[-3].minor.yy314 ){
141402 yymsp[-3].minor.yy314->affinity = OE_Ignore;
141403 }
141404 }
141405 break;
141406 case 245: /* expr ::= RAISE LP raisetype COMMA nm RP */
141407 {
141408 yymsp[-5].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
141409 if( yymsp[-5].minor.yy314 ) {
141410 yymsp[-5].minor.yy314->affinity = (char)yymsp[-3].minor.yy4;
141411 }
141412 }
141413 break;
141414 case 246: /* raisetype ::= ROLLBACK */
141415 {yymsp[0].minor.yy4 = OE_Rollback;}
141416 break;
141417 case 248: /* raisetype ::= FAIL */
141418 {yymsp[0].minor.yy4 = OE_Fail;}
141419 break;
141420 case 249: /* cmd ::= DROP TRIGGER ifexists fullname */
141421 {
141422 sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4);
141423 }
141424 break;
141425 case 250: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
141426 {
141427 sqlite3Attach(pParse, yymsp[-3].minor.yy314, yymsp[-1].minor.yy314, yymsp[0].minor.yy314);
141428 }
141429 break;
141430 case 251: /* cmd ::= DETACH database_kw_opt expr */
141431 {
141432 sqlite3Detach(pParse, yymsp[0].minor.yy314);
141433 }
141434 break;
141435 case 254: /* cmd ::= REINDEX */
141436 {sqlite3Reindex(pParse, 0, 0);}
141437 break;
141438 case 255: /* cmd ::= REINDEX nm dbnm */
141439 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
141440 break;
141441 case 256: /* cmd ::= ANALYZE */
141442 {sqlite3Analyze(pParse, 0, 0);}
141443 break;
141444 case 257: /* cmd ::= ANALYZE nm dbnm */
141445 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
141446 break;
141447 case 258: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
141448 {
141449 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0);
141450 }
141451 break;
141452 case 259: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
141453 {
141454 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
141455 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
141456 }
141457 break;
141458 case 260: /* add_column_fullname ::= fullname */
141459 {
141460 disableLookaside(pParse);
141461 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259);
141462 }
141463 break;
141464 case 261: /* cmd ::= create_vtab */
141465 {sqlite3VtabFinishParse(pParse,0);}
141466 break;
141467 case 262: /* cmd ::= create_vtab LP vtabarglist RP */
141468 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
141469 break;
141470 case 263: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
141471 {
141472 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy4);
141473 }
141474 break;
141475 case 264: /* vtabarg ::= */
141476 {sqlite3VtabArgInit(pParse);}
141477 break;
141478 case 265: /* vtabargtoken ::= ANY */
141479 case 266: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==266);
141480 case 267: /* lp ::= LP */ yytestcase(yyruleno==267);
141481 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
141482 break;
141483 case 268: /* with ::= */
141484 {yymsp[1].minor.yy451 = 0;}
141485 break;
141486 case 269: /* with ::= WITH wqlist */
141487 { yymsp[-1].minor.yy451 = yymsp[0].minor.yy451; }
141488 break;
141489 case 270: /* with ::= WITH RECURSIVE wqlist */
141490 { yymsp[-2].minor.yy451 = yymsp[0].minor.yy451; }
141491 break;
141492 case 271: /* wqlist ::= nm eidlist_opt AS LP select RP */
141493 {
141494 yymsp[-5].minor.yy451 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy387); /*A-overwrites-X*/
141495 }
141496 break;
141497 case 272: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
141498 {
141499 yymsp[-7].minor.yy451 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy451, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy387);
141500 }
141501 break;
141502 default:
141503 /* (273) input ::= cmdlist */ yytestcase(yyruleno==273);
141504 /* (274) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==274);
141505 /* (275) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=275);
141506 /* (276) ecmd ::= SEMI */ yytestcase(yyruleno==276);
141507 /* (277) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==277);
141508 /* (278) explain ::= */ yytestcase(yyruleno==278);
141509 /* (279) trans_opt ::= */ yytestcase(yyruleno==279);
141510 /* (280) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==280);
141511 /* (281) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==281);
141512 /* (282) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==282);
141513 /* (283) savepoint_opt ::= */ yytestcase(yyruleno==283);
141514 /* (284) cmd ::= create_table create_table_args */ yytestcase(yyruleno==284);
141515 /* (285) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==285);
141516 /* (286) columnlist ::= columnname carglist */ yytestcase(yyruleno==286);
141517 /* (287) nm ::= ID|INDEXED */ yytestcase(yyruleno==287);
141518 /* (288) nm ::= STRING */ yytestcase(yyruleno==288);
141519 /* (289) nm ::= JOIN_KW */ yytestcase(yyruleno==289);
141520 /* (290) typetoken ::= typename */ yytestcase(yyruleno==290);
141521 /* (291) typename ::= ID|STRING */ yytestcase(yyruleno==291);
141522 /* (292) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=292);
141523 /* (293) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=293);
141524 /* (294) carglist ::= carglist ccons */ yytestcase(yyruleno==294);
141525 /* (295) carglist ::= */ yytestcase(yyruleno==295);
141526 /* (296) ccons ::= NULL onconf */ yytestcase(yyruleno==296);
141527 /* (297) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==297);
141528 /* (298) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==298);
141529 /* (299) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=299);
141530 /* (300) tconscomma ::= */ yytestcase(yyruleno==300);
141531 /* (301) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=301);
141532 /* (302) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=302);
141533 /* (303) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=303);
141534 /* (304) oneselect ::= values */ yytestcase(yyruleno==304);
141535 /* (305) sclp ::= selcollist COMMA */ yytestcase(yyruleno==305);
141536 /* (306) as ::= ID|STRING */ yytestcase(yyruleno==306);
141537 /* (307) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=307);
141538 /* (308) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==308);
141539 /* (309) exprlist ::= nexprlist */ yytestcase(yyruleno==309);
141540 /* (310) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=310);
141541 /* (311) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=311);
141542 /* (312) nmnum ::= ON */ yytestcase(yyruleno==312);
141543 /* (313) nmnum ::= DELETE */ yytestcase(yyruleno==313);
141544 /* (314) nmnum ::= DEFAULT */ yytestcase(yyruleno==314);
141545 /* (315) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==315);
141546 /* (316) foreach_clause ::= */ yytestcase(yyruleno==316);
141547 /* (317) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==317);
141548 /* (318) trnm ::= nm */ yytestcase(yyruleno==318);
141549 /* (319) tridxby ::= */ yytestcase(yyruleno==319);
141550 /* (320) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==320);
141551 /* (321) database_kw_opt ::= */ yytestcase(yyruleno==321);
141552 /* (322) kwcolumn_opt ::= */ yytestcase(yyruleno==322);
141553 /* (323) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==323);
141554 /* (324) vtabarglist ::= vtabarg */ yytestcase(yyruleno==324);
141555 /* (325) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==325);
141556 /* (326) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==326);
141557 /* (327) anylist ::= */ yytestcase(yyruleno==327);
141558 /* (328) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==328);
141559 /* (329) anylist ::= anylist ANY */ yytestcase(yyruleno==329);
141560 break;
141561 /********** End reduce actions ************************************************/
141562 };
141563 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
141564 yygoto = yyRuleInfo[yyruleno].lhs;
@@ -141151,20 +141570,15 @@
141570 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
141571
141572 /* It is not possible for a REDUCE to be followed by an error */
141573 assert( yyact!=YY_ERROR_ACTION );
141574
141575 yymsp += yysize+1;
141576 yypParser->yytos = yymsp;
141577 yymsp->stateno = (YYACTIONTYPE)yyact;
141578 yymsp->major = (YYCODETYPE)yygoto;
141579 yyTraceShift(yypParser, yyact, "... then shift");
 
 
 
 
 
141580 }
141581
141582 /*
141583 ** The following code executes when the parse fails
141584 */
@@ -141271,24 +141685,35 @@
141685 #endif
141686 sqlite3ParserARG_STORE;
141687
141688 #ifndef NDEBUG
141689 if( yyTraceFILE ){
141690 int stateno = yypParser->yytos->stateno;
141691 if( stateno < YY_MIN_REDUCE ){
141692 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
141693 yyTracePrompt,yyTokenName[yymajor],stateno);
141694 }else{
141695 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
141696 yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE);
141697 }
141698 }
141699 #endif
141700
141701 do{
141702 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
141703 if( yyact >= YY_MIN_REDUCE ){
141704 yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor);
141705 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
141706 yy_shift(yypParser,yyact,yymajor,yyminor);
141707 #ifndef YYNOERRORRECOVERY
141708 yypParser->yyerrcnt--;
141709 #endif
141710 yymajor = YYNOCODE;
141711 }else if( yyact==YY_ACCEPT_ACTION ){
141712 yypParser->yytos--;
141713 yy_accept(yypParser);
141714 return;
141715 }else{
141716 assert( yyact == YY_ERROR_ACTION );
141717 yyminorunion.yy0 = yyminor;
141718 #ifdef YYERRORSYMBOL
141719 int yymx;
@@ -143527,10 +143952,11 @@
143952 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
143953 { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
143954 { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension },
143955 { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose },
143956 { SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG },
143957 { SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP },
143958 };
143959 unsigned int i;
143960 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
143961 for(i=0; i<ArraySize(aFlagOp); i++){
143962 if( aFlagOp[i].op==op ){
@@ -146620,10 +147046,26 @@
147046 sqlite3ResetAllSchemasOfConnection(db);
147047 }
147048 sqlite3_mutex_leave(db->mutex);
147049 break;
147050 }
147051
147052 #if defined(YYCOVERAGE)
147053 /* sqlite3_test_control(SQLITE_TESTCTRL_PARSER_COVERAGE, FILE *out)
147054 **
147055 ** This test control (only available when SQLite is compiled with
147056 ** -DYYCOVERAGE) writes a report onto "out" that shows all
147057 ** state/lookahead combinations in the parser state machine
147058 ** which are never exercised. If any state is missed, make the
147059 ** return code SQLITE_ERROR.
147060 */
147061 case SQLITE_TESTCTRL_PARSER_COVERAGE: {
147062 FILE *out = va_arg(ap, FILE*);
147063 if( sqlite3ParserCoverage(out) ) rc = SQLITE_ERROR;
147064 break;
147065 }
147066 #endif /* defined(YYCOVERAGE) */
147067 }
147068 va_end(ap);
147069 #endif /* SQLITE_UNTESTABLE */
147070 return rc;
147071 }
@@ -168393,11 +168835,11 @@
168835 int iHeight, /* Height of sub-tree rooted at pCell */
168836 RtreeNode **ppLeaf /* OUT: Selected leaf page */
168837 ){
168838 int rc;
168839 int ii;
168840 RtreeNode *pNode = 0;
168841 rc = nodeAcquire(pRtree, 1, 0, &pNode);
168842
168843 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
168844 int iCell;
168845 sqlite3_int64 iBest = 0;
@@ -169268,11 +169710,11 @@
169710 ** the root node (the operation that Gutman's paper says to perform
169711 ** in this scenario).
169712 */
169713 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
169714 int rc2;
169715 RtreeNode *pChild = 0;
169716 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
169717 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
169718 if( rc==SQLITE_OK ){
169719 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
169720 }
@@ -186623,18 +187065,19 @@
187065 ** sqlite3Fts5ParserARG_FETCH Code to extract %extra_argument from fts5yypParser
187066 ** fts5YYERRORSYMBOL is the code number of the error symbol. If not
187067 ** defined, then do no error processing.
187068 ** fts5YYNSTATE the combined number of states.
187069 ** fts5YYNRULE the number of rules in the grammar
187070 ** fts5YYNFTS5TOKEN Number of terminal symbols
187071 ** fts5YY_MAX_SHIFT Maximum value for shift actions
187072 ** fts5YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
187073 ** fts5YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
 
 
187074 ** fts5YY_ERROR_ACTION The fts5yy_action[] code for syntax error
187075 ** fts5YY_ACCEPT_ACTION The fts5yy_action[] code for accept
187076 ** fts5YY_NO_ACTION The fts5yy_action[] code for no-op
187077 ** fts5YY_MIN_REDUCE Minimum value for reduce actions
187078 ** fts5YY_MAX_REDUCE Maximum value for reduce actions
187079 */
187080 #ifndef INTERFACE
187081 # define INTERFACE 1
187082 #endif
187083 /************* Begin control #defines *****************************************/
@@ -186658,18 +187101,19 @@
187101 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
187102 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
187103 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
187104 #define fts5YYNSTATE 35
187105 #define fts5YYNRULE 28
187106 #define fts5YYNFTS5TOKEN 16
187107 #define fts5YY_MAX_SHIFT 34
187108 #define fts5YY_MIN_SHIFTREDUCE 52
187109 #define fts5YY_MAX_SHIFTREDUCE 79
187110 #define fts5YY_ERROR_ACTION 80
187111 #define fts5YY_ACCEPT_ACTION 81
187112 #define fts5YY_NO_ACTION 82
187113 #define fts5YY_MIN_REDUCE 83
187114 #define fts5YY_MAX_REDUCE 110
187115 /************* End control #defines *******************************************/
187116
187117 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
187118 ** otherwise.
187119 **
@@ -186695,39 +187139,33 @@
187139 ** token onto the stack and goto state N.
187140 **
187141 ** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
187142 ** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
187143 **
 
 
 
187144 ** N == fts5YY_ERROR_ACTION A syntax error has occurred.
187145 **
187146 ** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
187147 **
187148 ** N == fts5YY_NO_ACTION No such action. Denotes unused
187149 ** slots in the fts5yy_action[] table.
187150 **
187151 ** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
187152 ** and fts5YY_MAX_REDUCE
187153 **
187154 ** The action table is constructed as a single large table named fts5yy_action[].
187155 ** Given state S and lookahead X, the action is computed as either:
187156 **
187157 ** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
187158 ** (B) N = fts5yy_default[S]
187159 **
187160 ** The (A) formula is preferred. The B formula is used instead if
187161 ** fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X.
 
 
 
 
 
187162 **
187163 ** The formulas above are for computing the action when the lookahead is
187164 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
187165 ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
187166 ** the fts5yy_shift_ofst[] array.
 
187167 **
187168 ** The following are the tables generated in this section:
187169 **
187170 ** fts5yy_action[] A single table containing all actions.
187171 ** fts5yy_lookahead[] A table containing the lookahead for each entry in
@@ -186739,19 +187177,19 @@
187177 ** fts5yy_default[] Default action for each state.
187178 **
187179 *********** Begin parsing tables **********************************************/
187180 #define fts5YY_ACTTAB_COUNT (105)
187181 static const fts5YYACTIONTYPE fts5yy_action[] = {
187182 /* 0 */ 81, 20, 96, 6, 28, 99, 98, 26, 26, 18,
187183 /* 10 */ 96, 6, 28, 17, 98, 56, 26, 19, 96, 6,
187184 /* 20 */ 28, 14, 98, 108, 26, 92, 96, 6, 28, 25,
187185 /* 30 */ 98, 78, 26, 21, 96, 6, 28, 107, 98, 58,
187186 /* 40 */ 26, 29, 96, 6, 28, 32, 98, 22, 26, 24,
187187 /* 50 */ 16, 23, 11, 1, 14, 13, 24, 16, 31, 11,
187188 /* 60 */ 3, 97, 13, 27, 8, 98, 82, 26, 7, 4,
187189 /* 70 */ 5, 3, 4, 5, 3, 83, 4, 5, 3, 63,
187190 /* 80 */ 33, 34, 62, 12, 2, 86, 13, 10, 12, 71,
187191 /* 90 */ 10, 13, 78, 5, 3, 78, 9, 30, 75, 82,
187192 /* 100 */ 54, 57, 53, 57, 15,
187193 };
187194 static const fts5YYCODETYPE fts5yy_lookahead[] = {
187195 /* 0 */ 17, 18, 19, 20, 21, 23, 23, 25, 25, 18,
@@ -186762,35 +187200,35 @@
187200 /* 50 */ 7, 22, 9, 10, 9, 12, 6, 7, 13, 9,
187201 /* 60 */ 3, 19, 12, 21, 5, 23, 28, 25, 5, 1,
187202 /* 70 */ 2, 3, 1, 2, 3, 0, 1, 2, 3, 11,
187203 /* 80 */ 25, 26, 11, 9, 10, 5, 12, 10, 9, 11,
187204 /* 90 */ 10, 12, 15, 2, 3, 15, 24, 25, 9, 28,
187205 /* 100 */ 8, 9, 8, 9, 9, 28, 28, 28, 28, 28,
187206 /* 110 */ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
187207 /* 120 */ 28,
187208 };
 
187209 #define fts5YY_SHIFT_COUNT (34)
187210 #define fts5YY_SHIFT_MIN (0)
187211 #define fts5YY_SHIFT_MAX (95)
187212 static const unsigned char fts5yy_shift_ofst[] = {
187213 /* 0 */ 43, 43, 43, 43, 43, 43, 50, 74, 79, 45,
187214 /* 10 */ 12, 80, 77, 12, 16, 16, 30, 30, 68, 71,
187215 /* 20 */ 75, 91, 92, 94, 6, 31, 31, 59, 63, 57,
187216 /* 30 */ 31, 89, 95, 31, 78,
187217 };
 
187218 #define fts5YY_REDUCE_COUNT (17)
187219 #define fts5YY_REDUCE_MIN (-18)
187220 #define fts5YY_REDUCE_MAX (72)
187221 static const signed char fts5yy_reduce_ofst[] = {
187222 /* 0 */ -17, -9, -1, 7, 15, 23, 42, -18, -18, 55,
187223 /* 10 */ 72, -4, -4, 4, -4, 10, 25, 29,
187224 };
187225 static const fts5YYACTIONTYPE fts5yy_default[] = {
187226 /* 0 */ 80, 80, 80, 80, 80, 80, 95, 80, 80, 105,
187227 /* 10 */ 80, 110, 110, 80, 110, 110, 80, 80, 80, 80,
187228 /* 20 */ 80, 91, 80, 80, 80, 101, 100, 80, 80, 90,
187229 /* 30 */ 103, 80, 80, 104, 80,
187230 };
187231 /********** End of lemon-generated parsing tables *****************************/
187232
187233 /* The next table maps tokens (terminal symbols) into fallback tokens.
187234 ** If a construct like the following:
@@ -186888,23 +187326,44 @@
187326 if( fts5yyTraceFILE==0 ) fts5yyTracePrompt = 0;
187327 else if( fts5yyTracePrompt==0 ) fts5yyTraceFILE = 0;
187328 }
187329 #endif /* NDEBUG */
187330
187331 #if defined(fts5YYCOVERAGE) || !defined(NDEBUG)
187332 /* For tracing shifts, the names of all terminals and nonterminals
187333 ** are required. The following table supplies these names */
187334 static const char *const fts5yyTokenName[] = {
187335 /* 0 */ "$",
187336 /* 1 */ "OR",
187337 /* 2 */ "AND",
187338 /* 3 */ "NOT",
187339 /* 4 */ "TERM",
187340 /* 5 */ "COLON",
187341 /* 6 */ "MINUS",
187342 /* 7 */ "LCP",
187343 /* 8 */ "RCP",
187344 /* 9 */ "STRING",
187345 /* 10 */ "LP",
187346 /* 11 */ "RP",
187347 /* 12 */ "CARET",
187348 /* 13 */ "COMMA",
187349 /* 14 */ "PLUS",
187350 /* 15 */ "STAR",
187351 /* 16 */ "error",
187352 /* 17 */ "input",
187353 /* 18 */ "expr",
187354 /* 19 */ "cnearset",
187355 /* 20 */ "exprlist",
187356 /* 21 */ "colset",
187357 /* 22 */ "colsetlist",
187358 /* 23 */ "nearset",
187359 /* 24 */ "nearphrases",
187360 /* 25 */ "phrase",
187361 /* 26 */ "neardist_opt",
187362 /* 27 */ "star_opt",
187363 };
187364 #endif /* defined(fts5YYCOVERAGE) || !defined(NDEBUG) */
187365
187366 #ifndef NDEBUG
187367 /* For tracing reduce actions, the names of all rules are required.
187368 */
187369 static const char *const fts5yyRuleName[] = {
@@ -187151,10 +187610,47 @@
187610 fts5yyParser *pParser = (fts5yyParser*)p;
187611 return pParser->fts5yyhwm;
187612 }
187613 #endif
187614
187615 /* This array of booleans keeps track of the parser statement
187616 ** coverage. The element fts5yycoverage[X][Y] is set when the parser
187617 ** is in state X and has a lookahead token Y. In a well-tested
187618 ** systems, every element of this matrix should end up being set.
187619 */
187620 #if defined(fts5YYCOVERAGE)
187621 static unsigned char fts5yycoverage[fts5YYNSTATE][fts5YYNFTS5TOKEN];
187622 #endif
187623
187624 /*
187625 ** Write into out a description of every state/lookahead combination that
187626 **
187627 ** (1) has not been used by the parser, and
187628 ** (2) is not a syntax error.
187629 **
187630 ** Return the number of missed state/lookahead combinations.
187631 */
187632 #if defined(fts5YYCOVERAGE)
187633 static int sqlite3Fts5ParserCoverage(FILE *out){
187634 int stateno, iLookAhead, i;
187635 int nMissed = 0;
187636 for(stateno=0; stateno<fts5YYNSTATE; stateno++){
187637 i = fts5yy_shift_ofst[stateno];
187638 for(iLookAhead=0; iLookAhead<fts5YYNFTS5TOKEN; iLookAhead++){
187639 if( fts5yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
187640 if( fts5yycoverage[stateno][iLookAhead]==0 ) nMissed++;
187641 if( out ){
187642 fprintf(out,"State %d lookahead %s %s\n", stateno,
187643 fts5yyTokenName[iLookAhead],
187644 fts5yycoverage[stateno][iLookAhead] ? "ok" : "missed");
187645 }
187646 }
187647 }
187648 return nMissed;
187649 }
187650 #endif
187651
187652 /*
187653 ** Find the appropriate action for a parser given the terminal
187654 ** look-ahead token iLookAhead.
187655 */
187656 static unsigned int fts5yy_find_shift_action(
@@ -187162,17 +187658,22 @@
187658 fts5YYCODETYPE iLookAhead /* The look-ahead token */
187659 ){
187660 int i;
187661 int stateno = pParser->fts5yytos->stateno;
187662
187663 if( stateno>fts5YY_MAX_SHIFT ) return stateno;
187664 assert( stateno <= fts5YY_SHIFT_COUNT );
187665 #if defined(fts5YYCOVERAGE)
187666 fts5yycoverage[stateno][iLookAhead] = 1;
187667 #endif
187668 do{
187669 i = fts5yy_shift_ofst[stateno];
187670 assert( i>=0 && i+fts5YYNFTS5TOKEN<=sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0]) );
187671 assert( iLookAhead!=fts5YYNOCODE );
187672 assert( iLookAhead < fts5YYNFTS5TOKEN );
187673 i += iLookAhead;
187674 if( fts5yy_lookahead[i]!=iLookAhead ){
187675 #ifdef fts5YYFALLBACK
187676 fts5YYCODETYPE iFallback; /* Fallback token */
187677 if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
187678 && (iFallback = fts5yyFallback[iLookAhead])!=0 ){
187679 #ifndef NDEBUG
@@ -187231,11 +187732,10 @@
187732 }
187733 #else
187734 assert( stateno<=fts5YY_REDUCE_COUNT );
187735 #endif
187736 i = fts5yy_reduce_ofst[stateno];
 
187737 assert( iLookAhead!=fts5YYNOCODE );
187738 i += iLookAhead;
187739 #ifdef fts5YYERRORSYMBOL
187740 if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
187741 return fts5yy_default[stateno];
@@ -187269,24 +187769,25 @@
187769
187770 /*
187771 ** Print tracing information for a SHIFT action
187772 */
187773 #ifndef NDEBUG
187774 static void fts5yyTraceShift(fts5yyParser *fts5yypParser, int fts5yyNewState, const char *zTag){
187775 if( fts5yyTraceFILE ){
187776 if( fts5yyNewState<fts5YYNSTATE ){
187777 fprintf(fts5yyTraceFILE,"%s%s '%s', go to state %d\n",
187778 fts5yyTracePrompt, zTag, fts5yyTokenName[fts5yypParser->fts5yytos->major],
187779 fts5yyNewState);
187780 }else{
187781 fprintf(fts5yyTraceFILE,"%s%s '%s', pending reduce %d\n",
187782 fts5yyTracePrompt, zTag, fts5yyTokenName[fts5yypParser->fts5yytos->major],
187783 fts5yyNewState - fts5YY_MIN_REDUCE);
187784 }
187785 }
187786 }
187787 #else
187788 # define fts5yyTraceShift(X,Y,Z)
187789 #endif
187790
187791 /*
187792 ** Perform a shift action.
187793 */
@@ -187324,59 +187825,67 @@
187825 }
187826 fts5yytos = fts5yypParser->fts5yytos;
187827 fts5yytos->stateno = (fts5YYACTIONTYPE)fts5yyNewState;
187828 fts5yytos->major = (fts5YYCODETYPE)fts5yyMajor;
187829 fts5yytos->minor.fts5yy0 = fts5yyMinor;
187830 fts5yyTraceShift(fts5yypParser, fts5yyNewState, "Shift");
187831 }
187832
187833 /* The following table contains information about every rule that
187834 ** is used during the reduce.
187835 */
187836 static const struct {
187837 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
187838 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
187839 } fts5yyRuleInfo[] = {
187840 { 17, -1 }, /* (0) input ::= expr */
187841 { 21, -4 }, /* (1) colset ::= MINUS LCP colsetlist RCP */
187842 { 21, -3 }, /* (2) colset ::= LCP colsetlist RCP */
187843 { 21, -1 }, /* (3) colset ::= STRING */
187844 { 21, -2 }, /* (4) colset ::= MINUS STRING */
187845 { 22, -2 }, /* (5) colsetlist ::= colsetlist STRING */
187846 { 22, -1 }, /* (6) colsetlist ::= STRING */
187847 { 18, -3 }, /* (7) expr ::= expr AND expr */
187848 { 18, -3 }, /* (8) expr ::= expr OR expr */
187849 { 18, -3 }, /* (9) expr ::= expr NOT expr */
187850 { 18, -5 }, /* (10) expr ::= colset COLON LP expr RP */
187851 { 18, -3 }, /* (11) expr ::= LP expr RP */
187852 { 18, -1 }, /* (12) expr ::= exprlist */
187853 { 20, -1 }, /* (13) exprlist ::= cnearset */
187854 { 20, -2 }, /* (14) exprlist ::= exprlist cnearset */
187855 { 19, -1 }, /* (15) cnearset ::= nearset */
187856 { 19, -3 }, /* (16) cnearset ::= colset COLON nearset */
187857 { 23, -1 }, /* (17) nearset ::= phrase */
187858 { 23, -2 }, /* (18) nearset ::= CARET phrase */
187859 { 23, -5 }, /* (19) nearset ::= STRING LP nearphrases neardist_opt RP */
187860 { 24, -1 }, /* (20) nearphrases ::= phrase */
187861 { 24, -2 }, /* (21) nearphrases ::= nearphrases phrase */
187862 { 26, 0 }, /* (22) neardist_opt ::= */
187863 { 26, -2 }, /* (23) neardist_opt ::= COMMA STRING */
187864 { 25, -4 }, /* (24) phrase ::= phrase PLUS STRING star_opt */
187865 { 25, -2 }, /* (25) phrase ::= STRING star_opt */
187866 { 27, -1 }, /* (26) star_opt ::= STAR */
187867 { 27, 0 }, /* (27) star_opt ::= */
187868 };
187869
187870 static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */
187871
187872 /*
187873 ** Perform a reduce action and the shift that must immediately
187874 ** follow the reduce.
187875 **
187876 ** The fts5yyLookahead and fts5yyLookaheadToken parameters provide reduce actions
187877 ** access to the lookahead token (if any). The fts5yyLookahead will be fts5YYNOCODE
187878 ** if the lookahead token has already been consumed. As this procedure is
187879 ** only called from one place, optimizing compilers will in-line it, which
187880 ** means that the extra parameters have no performance impact.
187881 */
187882 static void fts5yy_reduce(
187883 fts5yyParser *fts5yypParser, /* The parser */
187884 unsigned int fts5yyruleno, /* Number of the rule by which to reduce */
187885 int fts5yyLookahead, /* Lookahead token, or fts5YYNOCODE if none */
187886 sqlite3Fts5ParserFTS5TOKENTYPE fts5yyLookaheadToken /* Value of the lookahead token */
187887 ){
187888 int fts5yygoto; /* The next state */
187889 int fts5yyact; /* The next action */
187890 fts5yyStackEntry *fts5yymsp; /* The top of the parser's stack */
187891 int fts5yysize; /* Amount to pop the stack */
@@ -187383,12 +187892,18 @@
187892 sqlite3Fts5ParserARG_FETCH;
187893 fts5yymsp = fts5yypParser->fts5yytos;
187894 #ifndef NDEBUG
187895 if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
187896 fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs;
187897 if( fts5yysize ){
187898 fprintf(fts5yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
187899 fts5yyTracePrompt,
187900 fts5yyruleno, fts5yyRuleName[fts5yyruleno], fts5yymsp[fts5yysize].stateno);
187901 }else{
187902 fprintf(fts5yyTraceFILE, "%sReduce %d [%s].\n",
187903 fts5yyTracePrompt, fts5yyruleno, fts5yyRuleName[fts5yyruleno]);
187904 }
187905 }
187906 #endif /* NDEBUG */
187907
187908 /* Check that the stack is large enough to grow by a single entry
187909 ** if the RHS of the rule is empty. This ensures that there is room
@@ -187581,20 +188096,15 @@
188096 assert( !(fts5yyact>fts5YY_MAX_SHIFT && fts5yyact<=fts5YY_MAX_SHIFTREDUCE) );
188097
188098 /* It is not possible for a REDUCE to be followed by an error */
188099 assert( fts5yyact!=fts5YY_ERROR_ACTION );
188100
188101 fts5yymsp += fts5yysize+1;
188102 fts5yypParser->fts5yytos = fts5yymsp;
188103 fts5yymsp->stateno = (fts5YYACTIONTYPE)fts5yyact;
188104 fts5yymsp->major = (fts5YYCODETYPE)fts5yygoto;
188105 fts5yyTraceShift(fts5yypParser, fts5yyact, "... then shift");
 
 
 
 
 
188106 }
188107
188108 /*
188109 ** The following code executes when the parse fails
188110 */
@@ -187702,24 +188212,35 @@
188212 #endif
188213 sqlite3Fts5ParserARG_STORE;
188214
188215 #ifndef NDEBUG
188216 if( fts5yyTraceFILE ){
188217 int stateno = fts5yypParser->fts5yytos->stateno;
188218 if( stateno < fts5YY_MIN_REDUCE ){
188219 fprintf(fts5yyTraceFILE,"%sInput '%s' in state %d\n",
188220 fts5yyTracePrompt,fts5yyTokenName[fts5yymajor],stateno);
188221 }else{
188222 fprintf(fts5yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
188223 fts5yyTracePrompt,fts5yyTokenName[fts5yymajor],stateno-fts5YY_MIN_REDUCE);
188224 }
188225 }
188226 #endif
188227
188228 do{
188229 fts5yyact = fts5yy_find_shift_action(fts5yypParser,(fts5YYCODETYPE)fts5yymajor);
188230 if( fts5yyact >= fts5YY_MIN_REDUCE ){
188231 fts5yy_reduce(fts5yypParser,fts5yyact-fts5YY_MIN_REDUCE,fts5yymajor,fts5yyminor);
188232 }else if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
188233 fts5yy_shift(fts5yypParser,fts5yyact,fts5yymajor,fts5yyminor);
188234 #ifndef fts5YYNOERRORRECOVERY
188235 fts5yypParser->fts5yyerrcnt--;
188236 #endif
188237 fts5yymajor = fts5YYNOCODE;
188238 }else if( fts5yyact==fts5YY_ACCEPT_ACTION ){
188239 fts5yypParser->fts5yytos--;
188240 fts5yy_accept(fts5yypParser);
188241 return;
188242 }else{
188243 assert( fts5yyact == fts5YY_ERROR_ACTION );
188244 fts5yyminorunion.fts5yy0 = fts5yyminor;
188245 #ifdef fts5YYERRORSYMBOL
188246 int fts5yymx;
@@ -188193,10 +188714,20 @@
188714 *piPos = iAdj;
188715 }
188716
188717 return rc;
188718 }
188719
188720 /*
188721 ** Return the value in pVal interpreted as utf-8 text. Except, if pVal
188722 ** contains a NULL value, return a pointer to a static string zero
188723 ** bytes in length instead of a NULL pointer.
188724 */
188725 static const char *fts5ValueToText(sqlite3_value *pVal){
188726 const char *zRet = (const char*)sqlite3_value_text(pVal);
188727 return zRet ? zRet : "";
188728 }
188729
188730 /*
188731 ** Implementation of snippet() function.
188732 */
188733 static void fts5SnippetFunction(
@@ -188229,13 +188760,13 @@
188760 }
188761
188762 nCol = pApi->xColumnCount(pFts);
188763 memset(&ctx, 0, sizeof(HighlightContext));
188764 iCol = sqlite3_value_int(apVal[0]);
188765 ctx.zOpen = fts5ValueToText(apVal[1]);
188766 ctx.zClose = fts5ValueToText(apVal[2]);
188767 zEllips = fts5ValueToText(apVal[3]);
188768 nToken = sqlite3_value_int(apVal[4]);
188769
188770 iBestCol = (iCol>=0 ? iCol : 0);
188771 nPhrase = pApi->xPhraseCount(pFts);
188772 aSeen = sqlite3_malloc(nPhrase);
@@ -202410,11 +202941,11 @@
202941 int nArg, /* Number of args */
202942 sqlite3_value **apUnused /* Function arguments */
202943 ){
202944 assert( nArg==0 );
202945 UNUSED_PARAM2(nArg, apUnused);
202946 sqlite3_result_text(pCtx, "fts5: 2018-01-06 15:49:57 252ee55a7fc0b068b707af27bd912e684c28320996e78f0675217046b8c2fb49", -1, SQLITE_TRANSIENT);
202947 }
202948
202949 static int fts5Init(sqlite3 *db){
202950 static const sqlite3_module fts5Mod = {
202951 /* iVersion */ 2,
@@ -206678,12 +207209,12 @@
207209 }
207210 #endif /* SQLITE_CORE */
207211 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207212
207213 /************** End of stmt.c ************************************************/
207214 #if __LINE__!=207214
207215 #undef SQLITE_SOURCE_ID
207216 #define SQLITE_SOURCE_ID "2018-01-07 20:38:10 67c4a8c6881e33b830aa27c80e7e3d697a4222939edd77cd5ca77ece1647alt2"
207217 #endif
207218 /* Return the source-id for this library */
207219 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207220 /************************** End of sqlite3.c ******************************/
207221
+33 -8
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.22.0"
127127
#define SQLITE_VERSION_NUMBER 3022000
128
-#define SQLITE_SOURCE_ID "2017-12-13 20:35:34 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b429b15"
128
+#define SQLITE_SOURCE_ID "2018-01-07 20:38:10 67c4a8c6881e33b830aa27c80e7e3d697a4222939edd77cd5ca77ece16471ea4"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -2058,11 +2058,10 @@
20582058
** is an integer - non-zero to disable checkpoints-on-close, or zero (the
20592059
** default) to enable them. The second parameter is a pointer to an integer
20602060
** into which is written 0 or 1 to indicate whether checkpoints-on-close
20612061
** have been disabled - 0 if they are not disabled, 1 if they are.
20622062
** </dd>
2063
-**
20642063
** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
20652064
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
20662065
** the [query planner stability guarantee] (QPSG). When the QPSG is active,
20672066
** a single SQL query statement will always use the same algorithm regardless
20682067
** of values of [bound parameters].)^ The QPSG disables some query optimizations
@@ -2069,11 +2068,20 @@
20692068
** that look at the values of bound parameters, which can make some queries
20702069
** slower. But the QPSG has the advantage of more predictable behavior. With
20712070
** the QPSG active, SQLite will always use the same query plan in the field as
20722071
** was used during testing in the lab.
20732072
** </dd>
2074
-**
2073
+** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2074
+** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2075
+** include output for any operations performed by trigger programs. This
2076
+** option is used to set or clear (the default) a flag that governs this
2077
+** behavior. The first parameter passed to this operation is an integer -
2078
+** non-zero to enable output for trigger programs, or zero to disable it.
2079
+** The second parameter is a pointer to an integer into which is written
2080
+** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2081
+** it is not disabled, 1 if it is.
2082
+** </dd>
20752083
** </dl>
20762084
*/
20772085
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
20782086
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
20792087
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -2080,11 +2088,12 @@
20802088
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
20812089
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
20822090
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
20832091
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
20842092
#define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
2085
-
2093
+#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
2094
+#define SQLITE_DBCONFIG_MAX 1008 /* Largest DBCONFIG */
20862095
20872096
/*
20882097
** CAPI3REF: Enable Or Disable Extended Result Codes
20892098
** METHOD: sqlite3
20902099
**
@@ -6960,13 +6969,13 @@
69606969
** ^The third and fourth parameters to this routine
69616970
** are passed directly through to the second and third parameters of
69626971
** the xFileControl method. ^The return value of the xFileControl
69636972
** method becomes the return value of this routine.
69646973
**
6965
-** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
6974
+** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
69666975
** a pointer to the underlying [sqlite3_file] object to be written into
6967
-** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER
6976
+** the space pointed to by the 4th parameter. ^The [SQLITE_FCNTL_FILE_POINTER]
69686977
** case is a short-circuit path which does not actually invoke the
69696978
** underlying sqlite3_io_methods.xFileControl method.
69706979
**
69716980
** ^If the second parameter (zDbName) does not match the name of any
69726981
** open database file, then SQLITE_ERROR is returned. ^This error
@@ -6974,11 +6983,11 @@
69746983
** or [sqlite3_errmsg()]. The underlying xFileControl method might
69756984
** also return SQLITE_ERROR. There is no way to distinguish between
69766985
** an incorrect zDbName and an SQLITE_ERROR return from the underlying
69776986
** xFileControl method.
69786987
**
6979
-** See also: [SQLITE_FCNTL_LOCKSTATE]
6988
+** See also: [file control opcodes]
69806989
*/
69816990
SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
69826991
69836992
/*
69846993
** CAPI3REF: Testing Interface
@@ -7031,11 +7040,12 @@
70317040
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
70327041
#define SQLITE_TESTCTRL_BYTEORDER 22
70337042
#define SQLITE_TESTCTRL_ISINIT 23
70347043
#define SQLITE_TESTCTRL_SORTER_MMAP 24
70357044
#define SQLITE_TESTCTRL_IMPOSTER 25
7036
-#define SQLITE_TESTCTRL_LAST 25
7045
+#define SQLITE_TESTCTRL_PARSER_COVERAGE 26
7046
+#define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */
70377047
70387048
/*
70397049
** CAPI3REF: SQLite Runtime Status
70407050
**
70417051
** ^These interfaces are used to retrieve runtime status information
@@ -8285,10 +8295,25 @@
82858295
** of the SQL statement that triggered the call to the [xUpdate] method of the
82868296
** [virtual table].
82878297
*/
82888298
SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
82898299
8300
+/*
8301
+** CAPI3REF: Determine The Collation For a Virtual Table Constraint
8302
+**
8303
+** This function may only be called from within a call to the [xBestIndex]
8304
+** method of a [virtual table].
8305
+**
8306
+** The first argument must be the sqlite3_index_info object that is the
8307
+** first parameter to the xBestIndex() method. The second argument must be
8308
+** an index into the aConstraint[] array belonging to the sqlite3_index_info
8309
+** structure passed to xBestIndex. This function returns a pointer to a buffer
8310
+** containing the name of the collation sequence for the corresponding
8311
+** constraint.
8312
+*/
8313
+SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
8314
+
82908315
/*
82918316
** CAPI3REF: Conflict resolution modes
82928317
** KEYWORDS: {conflict resolution mode}
82938318
**
82948319
** These constants are returned by [sqlite3_vtab_on_conflict()] to
82958320
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2017-12-13 20:35:34 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b429b15"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -2058,11 +2058,10 @@
2058 ** is an integer - non-zero to disable checkpoints-on-close, or zero (the
2059 ** default) to enable them. The second parameter is a pointer to an integer
2060 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2061 ** have been disabled - 0 if they are not disabled, 1 if they are.
2062 ** </dd>
2063 **
2064 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2065 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2066 ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
2067 ** a single SQL query statement will always use the same algorithm regardless
2068 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
@@ -2069,11 +2068,20 @@
2069 ** that look at the values of bound parameters, which can make some queries
2070 ** slower. But the QPSG has the advantage of more predictable behavior. With
2071 ** the QPSG active, SQLite will always use the same query plan in the field as
2072 ** was used during testing in the lab.
2073 ** </dd>
2074 **
 
 
 
 
 
 
 
 
 
2075 ** </dl>
2076 */
2077 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2078 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2079 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -2080,11 +2088,12 @@
2080 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2081 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2082 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2083 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
2084 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
2085
 
2086
2087 /*
2088 ** CAPI3REF: Enable Or Disable Extended Result Codes
2089 ** METHOD: sqlite3
2090 **
@@ -6960,13 +6969,13 @@
6960 ** ^The third and fourth parameters to this routine
6961 ** are passed directly through to the second and third parameters of
6962 ** the xFileControl method. ^The return value of the xFileControl
6963 ** method becomes the return value of this routine.
6964 **
6965 ** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
6966 ** a pointer to the underlying [sqlite3_file] object to be written into
6967 ** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER
6968 ** case is a short-circuit path which does not actually invoke the
6969 ** underlying sqlite3_io_methods.xFileControl method.
6970 **
6971 ** ^If the second parameter (zDbName) does not match the name of any
6972 ** open database file, then SQLITE_ERROR is returned. ^This error
@@ -6974,11 +6983,11 @@
6974 ** or [sqlite3_errmsg()]. The underlying xFileControl method might
6975 ** also return SQLITE_ERROR. There is no way to distinguish between
6976 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
6977 ** xFileControl method.
6978 **
6979 ** See also: [SQLITE_FCNTL_LOCKSTATE]
6980 */
6981 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
6982
6983 /*
6984 ** CAPI3REF: Testing Interface
@@ -7031,11 +7040,12 @@
7031 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
7032 #define SQLITE_TESTCTRL_BYTEORDER 22
7033 #define SQLITE_TESTCTRL_ISINIT 23
7034 #define SQLITE_TESTCTRL_SORTER_MMAP 24
7035 #define SQLITE_TESTCTRL_IMPOSTER 25
7036 #define SQLITE_TESTCTRL_LAST 25
 
7037
7038 /*
7039 ** CAPI3REF: SQLite Runtime Status
7040 **
7041 ** ^These interfaces are used to retrieve runtime status information
@@ -8285,10 +8295,25 @@
8285 ** of the SQL statement that triggered the call to the [xUpdate] method of the
8286 ** [virtual table].
8287 */
8288 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
8289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8290 /*
8291 ** CAPI3REF: Conflict resolution modes
8292 ** KEYWORDS: {conflict resolution mode}
8293 **
8294 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
8295
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2018-01-07 20:38:10 67c4a8c6881e33b830aa27c80e7e3d697a4222939edd77cd5ca77ece16471ea4"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -2058,11 +2058,10 @@
2058 ** is an integer - non-zero to disable checkpoints-on-close, or zero (the
2059 ** default) to enable them. The second parameter is a pointer to an integer
2060 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2061 ** have been disabled - 0 if they are not disabled, 1 if they are.
2062 ** </dd>
 
2063 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2064 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2065 ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
2066 ** a single SQL query statement will always use the same algorithm regardless
2067 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
@@ -2069,11 +2068,20 @@
2068 ** that look at the values of bound parameters, which can make some queries
2069 ** slower. But the QPSG has the advantage of more predictable behavior. With
2070 ** the QPSG active, SQLite will always use the same query plan in the field as
2071 ** was used during testing in the lab.
2072 ** </dd>
2073 ** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2074 ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2075 ** include output for any operations performed by trigger programs. This
2076 ** option is used to set or clear (the default) a flag that governs this
2077 ** behavior. The first parameter passed to this operation is an integer -
2078 ** non-zero to enable output for trigger programs, or zero to disable it.
2079 ** The second parameter is a pointer to an integer into which is written
2080 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2081 ** it is not disabled, 1 if it is.
2082 ** </dd>
2083 ** </dl>
2084 */
2085 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2086 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2087 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -2080,11 +2088,12 @@
2088 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2089 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2090 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2091 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
2092 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
2093 #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
2094 #define SQLITE_DBCONFIG_MAX 1008 /* Largest DBCONFIG */
2095
2096 /*
2097 ** CAPI3REF: Enable Or Disable Extended Result Codes
2098 ** METHOD: sqlite3
2099 **
@@ -6960,13 +6969,13 @@
6969 ** ^The third and fourth parameters to this routine
6970 ** are passed directly through to the second and third parameters of
6971 ** the xFileControl method. ^The return value of the xFileControl
6972 ** method becomes the return value of this routine.
6973 **
6974 ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
6975 ** a pointer to the underlying [sqlite3_file] object to be written into
6976 ** the space pointed to by the 4th parameter. ^The [SQLITE_FCNTL_FILE_POINTER]
6977 ** case is a short-circuit path which does not actually invoke the
6978 ** underlying sqlite3_io_methods.xFileControl method.
6979 **
6980 ** ^If the second parameter (zDbName) does not match the name of any
6981 ** open database file, then SQLITE_ERROR is returned. ^This error
@@ -6974,11 +6983,11 @@
6983 ** or [sqlite3_errmsg()]. The underlying xFileControl method might
6984 ** also return SQLITE_ERROR. There is no way to distinguish between
6985 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
6986 ** xFileControl method.
6987 **
6988 ** See also: [file control opcodes]
6989 */
6990 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
6991
6992 /*
6993 ** CAPI3REF: Testing Interface
@@ -7031,11 +7040,12 @@
7040 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
7041 #define SQLITE_TESTCTRL_BYTEORDER 22
7042 #define SQLITE_TESTCTRL_ISINIT 23
7043 #define SQLITE_TESTCTRL_SORTER_MMAP 24
7044 #define SQLITE_TESTCTRL_IMPOSTER 25
7045 #define SQLITE_TESTCTRL_PARSER_COVERAGE 26
7046 #define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */
7047
7048 /*
7049 ** CAPI3REF: SQLite Runtime Status
7050 **
7051 ** ^These interfaces are used to retrieve runtime status information
@@ -8285,10 +8295,25 @@
8295 ** of the SQL statement that triggered the call to the [xUpdate] method of the
8296 ** [virtual table].
8297 */
8298 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
8299
8300 /*
8301 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
8302 **
8303 ** This function may only be called from within a call to the [xBestIndex]
8304 ** method of a [virtual table].
8305 **
8306 ** The first argument must be the sqlite3_index_info object that is the
8307 ** first parameter to the xBestIndex() method. The second argument must be
8308 ** an index into the aConstraint[] array belonging to the sqlite3_index_info
8309 ** structure passed to xBestIndex. This function returns a pointer to a buffer
8310 ** containing the name of the collation sequence for the corresponding
8311 ** constraint.
8312 */
8313 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
8314
8315 /*
8316 ** CAPI3REF: Conflict resolution modes
8317 ** KEYWORDS: {conflict resolution mode}
8318 **
8319 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
8320

Keyboard Shortcuts

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