Fossil SCM

Merge the latest SQLite 3.36 enhancements for testing.

drh 2021-04-07 18:20 trunk
Commit 1464e18add639018a57d8f28e6d7490db32e5146d2b6f8e1fa5a58f35bdacbdf
3 files changed +6 -4 +1029 -557 +18 -3
+6 -4
--- src/shell.c
+++ src/shell.c
@@ -4154,13 +4154,15 @@
41544154
pApndFile->iMark = -1; /* Append mark not yet written */
41554155
41564156
rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
41574157
if( rc==SQLITE_OK ){
41584158
rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
4159
+ if( rc ){
4160
+ pBaseFile->pMethods->xClose(pBaseFile);
4161
+ }
41594162
}
41604163
if( rc ){
4161
- pBaseFile->pMethods->xClose(pBaseFile);
41624164
pFile->pMethods = 0;
41634165
return rc;
41644166
}
41654167
if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
41664168
/* The file being opened appears to be just an ordinary DB. Copy
@@ -13069,11 +13071,11 @@
1306913071
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
1307013072
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
1307113073
sqlite3_exec(p->db,
1307213074
"CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
1307313075
" key TEXT PRIMARY KEY,\n"
13074
- " value ANY\n"
13076
+ " value\n"
1307513077
") WITHOUT ROWID;",
1307613078
0, 0, 0);
1307713079
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
1307813080
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
1307913081
}
@@ -15933,11 +15935,11 @@
1593315935
" 'EXPLAIN QUERY PLAN SELECT 1 FROM ' || quote(s.name) || ' WHERE '"
1593415936
" || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
1593515937
" || fkey_collate_clause("
1593615938
" f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
1593715939
", "
15938
- " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
15940
+ " 'SEARCH ' || s.name || ' USING COVERING INDEX*('"
1593915941
" || group_concat('*=?', ' AND ') || ')'"
1594015942
", "
1594115943
" s.name || '(' || group_concat(f.[from], ', ') || ')'"
1594215944
", "
1594315945
" f.[table] || '(' || group_concat(COALESCE(f.[to], p.[name])) || ')'"
@@ -15953,11 +15955,11 @@
1595315955
"FROM sqlite_schema AS s, pragma_foreign_key_list(s.name) AS f "
1595415956
"LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
1595515957
"GROUP BY s.name, f.id "
1595615958
"ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
1595715959
;
15958
- const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
15960
+ const char *zGlobIPK = "SEARCH * USING INTEGER PRIMARY KEY (rowid=?)";
1595915961
1596015962
for(i=2; i<nArg; i++){
1596115963
int n = strlen30(azArg[i]);
1596215964
if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
1596315965
bVerbose = 1;
1596415966
--- src/shell.c
+++ src/shell.c
@@ -4154,13 +4154,15 @@
4154 pApndFile->iMark = -1; /* Append mark not yet written */
4155
4156 rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
4157 if( rc==SQLITE_OK ){
4158 rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
 
 
 
4159 }
4160 if( rc ){
4161 pBaseFile->pMethods->xClose(pBaseFile);
4162 pFile->pMethods = 0;
4163 return rc;
4164 }
4165 if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
4166 /* The file being opened appears to be just an ordinary DB. Copy
@@ -13069,11 +13071,11 @@
13069 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
13070 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
13071 sqlite3_exec(p->db,
13072 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
13073 " key TEXT PRIMARY KEY,\n"
13074 " value ANY\n"
13075 ") WITHOUT ROWID;",
13076 0, 0, 0);
13077 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
13078 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
13079 }
@@ -15933,11 +15935,11 @@
15933 " 'EXPLAIN QUERY PLAN SELECT 1 FROM ' || quote(s.name) || ' WHERE '"
15934 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
15935 " || fkey_collate_clause("
15936 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
15937 ", "
15938 " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
15939 " || group_concat('*=?', ' AND ') || ')'"
15940 ", "
15941 " s.name || '(' || group_concat(f.[from], ', ') || ')'"
15942 ", "
15943 " f.[table] || '(' || group_concat(COALESCE(f.[to], p.[name])) || ')'"
@@ -15953,11 +15955,11 @@
15953 "FROM sqlite_schema AS s, pragma_foreign_key_list(s.name) AS f "
15954 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
15955 "GROUP BY s.name, f.id "
15956 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
15957 ;
15958 const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
15959
15960 for(i=2; i<nArg; i++){
15961 int n = strlen30(azArg[i]);
15962 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
15963 bVerbose = 1;
15964
--- src/shell.c
+++ src/shell.c
@@ -4154,13 +4154,15 @@
4154 pApndFile->iMark = -1; /* Append mark not yet written */
4155
4156 rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
4157 if( rc==SQLITE_OK ){
4158 rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
4159 if( rc ){
4160 pBaseFile->pMethods->xClose(pBaseFile);
4161 }
4162 }
4163 if( rc ){
 
4164 pFile->pMethods = 0;
4165 return rc;
4166 }
4167 if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
4168 /* The file being opened appears to be just an ordinary DB. Copy
@@ -13069,11 +13071,11 @@
13071 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
13072 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
13073 sqlite3_exec(p->db,
13074 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
13075 " key TEXT PRIMARY KEY,\n"
13076 " value\n"
13077 ") WITHOUT ROWID;",
13078 0, 0, 0);
13079 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
13080 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
13081 }
@@ -15933,11 +15935,11 @@
15935 " 'EXPLAIN QUERY PLAN SELECT 1 FROM ' || quote(s.name) || ' WHERE '"
15936 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
15937 " || fkey_collate_clause("
15938 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
15939 ", "
15940 " 'SEARCH ' || s.name || ' USING COVERING INDEX*('"
15941 " || group_concat('*=?', ' AND ') || ')'"
15942 ", "
15943 " s.name || '(' || group_concat(f.[from], ', ') || ')'"
15944 ", "
15945 " f.[table] || '(' || group_concat(COALESCE(f.[to], p.[name])) || ')'"
@@ -15953,11 +15955,11 @@
15955 "FROM sqlite_schema AS s, pragma_foreign_key_list(s.name) AS f "
15956 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
15957 "GROUP BY s.name, f.id "
15958 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
15959 ;
15960 const char *zGlobIPK = "SEARCH * USING INTEGER PRIMARY KEY (rowid=?)";
15961
15962 for(i=2; i<nArg; i++){
15963 int n = strlen30(azArg[i]);
15964 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
15965 bVerbose = 1;
15966
+1029 -557
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.35.4. By combining all the individual C code files into this
3
+** version 3.36.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -1184,13 +1184,13 @@
11841184
**
11851185
** See also: [sqlite3_libversion()],
11861186
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11871187
** [sqlite_version()] and [sqlite_source_id()].
11881188
*/
1189
-#define SQLITE_VERSION "3.35.4"
1190
-#define SQLITE_VERSION_NUMBER 3035004
1191
-#define SQLITE_SOURCE_ID "2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db635aa"
1189
+#define SQLITE_VERSION "3.36.0"
1190
+#define SQLITE_VERSION_NUMBER 3036000
1191
+#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16"
11921192
11931193
/*
11941194
** CAPI3REF: Run-Time Library Version Numbers
11951195
** KEYWORDS: sqlite3_version sqlite3_sourceid
11961196
**
@@ -2189,10 +2189,23 @@
21892189
** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
21902190
** in wal mode after the client has finished copying pages from the wal
21912191
** file to the database file, but before the *-shm file is updated to
21922192
** record the fact that the pages have been checkpointed.
21932193
** </ul>
2194
+**
2195
+** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
2196
+** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
2197
+** whether or not there is a database client in another process with a wal-mode
2198
+** transaction open on the database or not. It is only available on unix.The
2199
+** (void*) argument passed with this file-control should be a pointer to a
2200
+** value of type (int). The integer value is set to 1 if the database is a wal
2201
+** mode database and there exists at least one client in another process that
2202
+** currently has an SQL transaction open on the database. It is set to 0 if
2203
+** the database is not a wal-mode db, or if there is no such connection in any
2204
+** other process. This opcode cannot be used to detect transactions opened
2205
+** by clients within the current process, only within other processes.
2206
+** </ul>
21942207
*/
21952208
#define SQLITE_FCNTL_LOCKSTATE 1
21962209
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
21972210
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
21982211
#define SQLITE_FCNTL_LAST_ERRNO 4
@@ -2228,10 +2241,12 @@
22282241
#define SQLITE_FCNTL_DATA_VERSION 35
22292242
#define SQLITE_FCNTL_SIZE_LIMIT 36
22302243
#define SQLITE_FCNTL_CKPT_DONE 37
22312244
#define SQLITE_FCNTL_RESERVE_BYTES 38
22322245
#define SQLITE_FCNTL_CKPT_START 39
2246
+
2247
+#define SQLITE_FCNTL_EXTERNAL_READER 40
22332248
22342249
/* deprecated names */
22352250
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
22362251
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
22372252
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -15758,11 +15773,11 @@
1575815773
#define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
1575915774
#define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
1576015775
#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
1576115776
#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
1576215777
#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15763
-#define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
15778
+#define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
1576415779
#define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
1576515780
#define OP_IncrVacuum 60 /* jump */
1576615781
#define OP_VNext 61 /* jump */
1576715782
#define OP_Init 62 /* jump, synopsis: Start at P2 */
1576815783
#define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@NP]) */
@@ -15789,23 +15804,23 @@
1578915804
#define OP_RealAffinity 84
1579015805
#define OP_Cast 85 /* synopsis: affinity(r[P1]) */
1579115806
#define OP_Permutation 86
1579215807
#define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */
1579315808
#define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15794
-#define OP_Offset 89 /* synopsis: r[P3] = sqlite_offset(P1) */
15795
-#define OP_Column 90 /* synopsis: r[P3]=PX */
15796
-#define OP_Affinity 91 /* synopsis: affinity(r[P1@P2]) */
15797
-#define OP_MakeRecord 92 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15798
-#define OP_Count 93 /* synopsis: r[P2]=count() */
15799
-#define OP_ReadCookie 94
15800
-#define OP_SetCookie 95
15801
-#define OP_ReopenIdx 96 /* synopsis: root=P2 iDb=P3 */
15802
-#define OP_OpenRead 97 /* synopsis: root=P2 iDb=P3 */
15803
-#define OP_OpenWrite 98 /* synopsis: root=P2 iDb=P3 */
15804
-#define OP_OpenDup 99
15805
-#define OP_OpenAutoindex 100 /* synopsis: nColumn=P2 */
15806
-#define OP_OpenEphemeral 101 /* synopsis: nColumn=P2 */
15809
+#define OP_ZeroOrNull 89 /* synopsis: r[P2] = 0 OR NULL */
15810
+#define OP_Offset 90 /* synopsis: r[P3] = sqlite_offset(P1) */
15811
+#define OP_Column 91 /* synopsis: r[P3]=PX */
15812
+#define OP_Affinity 92 /* synopsis: affinity(r[P1@P2]) */
15813
+#define OP_MakeRecord 93 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15814
+#define OP_Count 94 /* synopsis: r[P2]=count() */
15815
+#define OP_ReadCookie 95
15816
+#define OP_SetCookie 96
15817
+#define OP_ReopenIdx 97 /* synopsis: root=P2 iDb=P3 */
15818
+#define OP_OpenRead 98 /* synopsis: root=P2 iDb=P3 */
15819
+#define OP_OpenWrite 99 /* synopsis: root=P2 iDb=P3 */
15820
+#define OP_OpenDup 100
15821
+#define OP_OpenAutoindex 101 /* synopsis: nColumn=P2 */
1580715822
#define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
1580815823
#define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
1580915824
#define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
1581015825
#define OP_ShiftRight 105 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
1581115826
#define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -15812,77 +15827,78 @@
1581215827
#define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
1581315828
#define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
1581415829
#define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
1581515830
#define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
1581615831
#define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15817
-#define OP_SorterOpen 112
15832
+#define OP_OpenEphemeral 112 /* synopsis: nColumn=P2 */
1581815833
#define OP_BitNot 113 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15819
-#define OP_SequenceTest 114 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15820
-#define OP_OpenPseudo 115 /* synopsis: P3 columns in r[P2] */
15834
+#define OP_SorterOpen 114
15835
+#define OP_SequenceTest 115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
1582115836
#define OP_String8 116 /* same as TK_STRING, synopsis: r[P2]='P4' */
15822
-#define OP_Close 117
15823
-#define OP_ColumnsUsed 118
15824
-#define OP_SeekScan 119 /* synopsis: Scan-ahead up to P1 rows */
15825
-#define OP_SeekHit 120 /* synopsis: set P2<=seekHit<=P3 */
15826
-#define OP_Sequence 121 /* synopsis: r[P2]=cursor[P1].ctr++ */
15827
-#define OP_NewRowid 122 /* synopsis: r[P2]=rowid */
15828
-#define OP_Insert 123 /* synopsis: intkey=r[P3] data=r[P2] */
15829
-#define OP_RowCell 124
15830
-#define OP_Delete 125
15831
-#define OP_ResetCount 126
15832
-#define OP_SorterCompare 127 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15833
-#define OP_SorterData 128 /* synopsis: r[P2]=data */
15834
-#define OP_RowData 129 /* synopsis: r[P2]=data */
15835
-#define OP_Rowid 130 /* synopsis: r[P2]=rowid */
15836
-#define OP_NullRow 131
15837
-#define OP_SeekEnd 132
15838
-#define OP_IdxInsert 133 /* synopsis: key=r[P2] */
15839
-#define OP_SorterInsert 134 /* synopsis: key=r[P2] */
15840
-#define OP_IdxDelete 135 /* synopsis: key=r[P2@P3] */
15841
-#define OP_DeferredSeek 136 /* synopsis: Move P3 to P1.rowid if needed */
15842
-#define OP_IdxRowid 137 /* synopsis: r[P2]=rowid */
15843
-#define OP_FinishSeek 138
15844
-#define OP_Destroy 139
15845
-#define OP_Clear 140
15846
-#define OP_ResetSorter 141
15847
-#define OP_CreateBtree 142 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15848
-#define OP_SqlExec 143
15849
-#define OP_ParseSchema 144
15850
-#define OP_LoadAnalysis 145
15851
-#define OP_DropTable 146
15852
-#define OP_DropIndex 147
15853
-#define OP_DropTrigger 148
15854
-#define OP_IntegrityCk 149
15855
-#define OP_RowSetAdd 150 /* synopsis: rowset(P1)=r[P2] */
15856
-#define OP_Param 151
15837
+#define OP_OpenPseudo 117 /* synopsis: P3 columns in r[P2] */
15838
+#define OP_Close 118
15839
+#define OP_ColumnsUsed 119
15840
+#define OP_SeekScan 120 /* synopsis: Scan-ahead up to P1 rows */
15841
+#define OP_SeekHit 121 /* synopsis: set P2<=seekHit<=P3 */
15842
+#define OP_Sequence 122 /* synopsis: r[P2]=cursor[P1].ctr++ */
15843
+#define OP_NewRowid 123 /* synopsis: r[P2]=rowid */
15844
+#define OP_Insert 124 /* synopsis: intkey=r[P3] data=r[P2] */
15845
+#define OP_RowCell 125
15846
+#define OP_Delete 126
15847
+#define OP_ResetCount 127
15848
+#define OP_SorterCompare 128 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15849
+#define OP_SorterData 129 /* synopsis: r[P2]=data */
15850
+#define OP_RowData 130 /* synopsis: r[P2]=data */
15851
+#define OP_Rowid 131 /* synopsis: r[P2]=rowid */
15852
+#define OP_NullRow 132
15853
+#define OP_SeekEnd 133
15854
+#define OP_IdxInsert 134 /* synopsis: key=r[P2] */
15855
+#define OP_SorterInsert 135 /* synopsis: key=r[P2] */
15856
+#define OP_IdxDelete 136 /* synopsis: key=r[P2@P3] */
15857
+#define OP_DeferredSeek 137 /* synopsis: Move P3 to P1.rowid if needed */
15858
+#define OP_IdxRowid 138 /* synopsis: r[P2]=rowid */
15859
+#define OP_FinishSeek 139
15860
+#define OP_Destroy 140
15861
+#define OP_Clear 141
15862
+#define OP_ResetSorter 142
15863
+#define OP_CreateBtree 143 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15864
+#define OP_SqlExec 144
15865
+#define OP_ParseSchema 145
15866
+#define OP_LoadAnalysis 146
15867
+#define OP_DropTable 147
15868
+#define OP_DropIndex 148
15869
+#define OP_DropTrigger 149
15870
+#define OP_IntegrityCk 150
15871
+#define OP_RowSetAdd 151 /* synopsis: rowset(P1)=r[P2] */
1585715872
#define OP_Real 152 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15858
-#define OP_FkCounter 153 /* synopsis: fkctr[P1]+=P2 */
15859
-#define OP_MemMax 154 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15860
-#define OP_OffsetLimit 155 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15861
-#define OP_AggInverse 156 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15862
-#define OP_AggStep 157 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15863
-#define OP_AggStep1 158 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15864
-#define OP_AggValue 159 /* synopsis: r[P3]=value N=P2 */
15865
-#define OP_AggFinal 160 /* synopsis: accum=r[P1] N=P2 */
15866
-#define OP_Expire 161
15867
-#define OP_CursorLock 162
15868
-#define OP_CursorUnlock 163
15869
-#define OP_TableLock 164 /* synopsis: iDb=P1 root=P2 write=P3 */
15870
-#define OP_VBegin 165
15871
-#define OP_VCreate 166
15872
-#define OP_VDestroy 167
15873
-#define OP_VOpen 168
15874
-#define OP_VColumn 169 /* synopsis: r[P3]=vcolumn(P2) */
15875
-#define OP_VRename 170
15876
-#define OP_Pagecount 171
15877
-#define OP_MaxPgcnt 172
15878
-#define OP_Trace 173
15879
-#define OP_CursorHint 174
15880
-#define OP_ReleaseReg 175 /* synopsis: release r[P1@P2] mask P3 */
15881
-#define OP_Noop 176
15882
-#define OP_Explain 177
15883
-#define OP_Abortable 178
15873
+#define OP_Param 153
15874
+#define OP_FkCounter 154 /* synopsis: fkctr[P1]+=P2 */
15875
+#define OP_MemMax 155 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15876
+#define OP_OffsetLimit 156 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15877
+#define OP_AggInverse 157 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15878
+#define OP_AggStep 158 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15879
+#define OP_AggStep1 159 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15880
+#define OP_AggValue 160 /* synopsis: r[P3]=value N=P2 */
15881
+#define OP_AggFinal 161 /* synopsis: accum=r[P1] N=P2 */
15882
+#define OP_Expire 162
15883
+#define OP_CursorLock 163
15884
+#define OP_CursorUnlock 164
15885
+#define OP_TableLock 165 /* synopsis: iDb=P1 root=P2 write=P3 */
15886
+#define OP_VBegin 166
15887
+#define OP_VCreate 167
15888
+#define OP_VDestroy 168
15889
+#define OP_VOpen 169
15890
+#define OP_VColumn 170 /* synopsis: r[P3]=vcolumn(P2) */
15891
+#define OP_VRename 171
15892
+#define OP_Pagecount 172
15893
+#define OP_MaxPgcnt 173
15894
+#define OP_Trace 174
15895
+#define OP_CursorHint 175
15896
+#define OP_ReleaseReg 176 /* synopsis: release r[P1@P2] mask P3 */
15897
+#define OP_Noop 177
15898
+#define OP_Explain 178
15899
+#define OP_Abortable 179
1588415900
1588515901
/* Properties such as "out2" or "jump" that are specified in
1588615902
** comments following the "case" for each opcode in the vdbe.c
1588715903
** are encoded into bitvectors as follows:
1588815904
*/
@@ -15902,22 +15918,22 @@
1590215918
/* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
1590315919
/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
1590415920
/* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
1590515921
/* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
1590615922
/* 80 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
15907
-/* 88 */ 0x12, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
15923
+/* 88 */ 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10,\
1590815924
/* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26,\
1590915925
/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
1591015926
/* 112 */ 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,\
15911
-/* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15912
-/* 128 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04, 0x00,\
15913
-/* 136 */ 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00,\
15914
-/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10,\
15915
-/* 152 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
15927
+/* 120 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
15928
+/* 128 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\
15929
+/* 136 */ 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10,\
15930
+/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
15931
+/* 152 */ 0x10, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00,\
1591615932
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15917
-/* 168 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
15918
-/* 176 */ 0x00, 0x00, 0x00,}
15933
+/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15934
+/* 176 */ 0x00, 0x00, 0x00, 0x00,}
1591915935
1592015936
/* The sqlite3P2Values() routine is able to run faster if it knows
1592115937
** the value of the largest JUMP opcode. The smaller the maximum
1592215938
** JUMP opcode the better, so the mkopcodeh.tcl script that
1592315939
** generated this include file strives to group all JUMP opcodes
@@ -17005,14 +17021,11 @@
1700517021
u8 iDb; /* Which db file is being initialized */
1700617022
u8 busy; /* TRUE if currently initializing */
1700717023
unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
1700817024
unsigned imposterTable : 1; /* Building an imposter table */
1700917025
unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
17010
- unsigned bDropColumn : 1; /* Doing schema check after DROP COLUMN */
1701117026
char **azInit; /* "type", "name", and "tbl_name" columns */
17012
- /* or if bDropColumn, then azInit[0] is the */
17013
- /* name of the column being dropped */
1701417027
} init;
1701517028
int nVdbeActive; /* Number of VDBEs currently running */
1701617029
int nVdbeRead; /* Number of active VDBEs that read or write */
1701717030
int nVdbeWrite; /* Number of active VDBEs that read and write */
1701817031
int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -17579,13 +17592,11 @@
1757917592
** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
1758017593
** It causes an assert() to fire if either operand to a comparison
1758117594
** operator is NULL. It is added to certain comparison operators to
1758217595
** prove that the operands are always NOT NULL.
1758317596
*/
17584
-#define SQLITE_KEEPNULL 0x08 /* Used by vector == or <> */
1758517597
#define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
17586
-#define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */
1758717598
#define SQLITE_NULLEQ 0x80 /* NULL=NULL */
1758817599
#define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
1758917600
1759017601
/*
1759117602
** An object of this type is created for each virtual table present in
@@ -18078,10 +18089,11 @@
1807818089
struct AggInfo_func { /* For each aggregate function */
1807918090
Expr *pFExpr; /* Expression encoding the function */
1808018091
FuncDef *pFunc; /* The aggregate function implementation */
1808118092
int iMem; /* Memory location that acts as accumulator */
1808218093
int iDistinct; /* Ephemeral table used to enforce DISTINCT */
18094
+ int iDistAddr; /* Address of OP_OpenEphemeral */
1808318095
} *aFunc;
1808418096
int nFunc; /* Number of entries in aFunc[] */
1808518097
u32 selId; /* Select to which this AggInfo belongs */
1808618098
};
1808718099
@@ -18350,10 +18362,11 @@
1835018362
** ENAME_SPAN Text of the original result set
1835118363
** expression.
1835218364
*/
1835318365
struct ExprList {
1835418366
int nExpr; /* Number of expressions on the list */
18367
+ int nAlloc; /* Number of a[] slots allocated */
1835518368
struct ExprList_item { /* For each expression in the list */
1835618369
Expr *pExpr; /* The parse tree for this expression */
1835718370
char *zEName; /* Token associated with this expression */
1835818371
u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
1835918372
unsigned eEName :2; /* Meaning of zEName */
@@ -18494,11 +18507,11 @@
1849418507
** the OR optimization */
1849518508
#define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
1849618509
#define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
1849718510
#define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
1849818511
#define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18499
- /* 0x0400 not currently used */
18512
+#define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */
1850018513
#define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
1850118514
/* 0x1000 not currently used */
1850218515
/* 0x2000 not currently used */
1850318516
#define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
1850418517
/* 0x8000 not currently used */
@@ -20213,10 +20226,13 @@
2021320226
SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
2021420227
#ifndef SQLITE_AMALGAMATION
2021520228
SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
2021620229
SQLITE_PRIVATE const char sqlite3StrBINARY[];
2021720230
SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
20231
+SQLITE_PRIVATE const unsigned char *sqlite3aLTb;
20232
+SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
20233
+SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
2021820234
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
2021920235
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
2022020236
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
2022120237
#ifndef SQLITE_OMIT_WSD
2022220238
SQLITE_PRIVATE int sqlite3PendingByte;
@@ -20679,11 +20695,11 @@
2067920695
162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
2068020696
180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
2068120697
198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
2068220698
216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
2068320699
234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
20684
- 252,253,254,255
20700
+ 252,253,254,255,
2068520701
#endif
2068620702
#ifdef SQLITE_EBCDIC
2068720703
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
2068820704
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
2068920705
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
@@ -20699,11 +20715,39 @@
2069920715
192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */
2070020716
208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */
2070120717
224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
2070220718
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
2070320719
#endif
20720
+/* All of the upper-to-lower conversion data is above. The following
20721
+** 18 integers are completely unrelated. They are appended to the
20722
+** sqlite3UpperToLower[] array to avoid UBSAN warnings. Here's what is
20723
+** going on:
20724
+**
20725
+** The SQL comparison operators (<>, =, >, <=, <, and >=) are implemented
20726
+** by invoking sqlite3MemCompare(A,B) which compares values A and B and
20727
+** returns negative, zero, or positive if A is less then, equal to, or
20728
+** greater than B, respectively. Then the true false results is found by
20729
+** consulting sqlite3aLTb[opcode], sqlite3aEQb[opcode], or
20730
+** sqlite3aGTb[opcode] depending on whether the result of compare(A,B)
20731
+** is negative, zero, or positive, where opcode is the specific opcode.
20732
+** The only works because the comparison opcodes are consecutive and in
20733
+** this order: NE EQ GT LE LT GE. Various assert()s throughout the code
20734
+** ensure that is the case.
20735
+**
20736
+** These elements must be appended to another array. Otherwise the
20737
+** index (here shown as [256-OP_Ne]) would be out-of-bounds and thus
20738
+** be undefined behavior. That's goofy, but the C-standards people thought
20739
+** it was a good idea, so here we are.
20740
+*/
20741
+/* NE EQ GT LE LT GE */
20742
+ 1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */
20743
+ 0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */
20744
+ 1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/
2070420745
};
20746
+SQLITE_PRIVATE const unsigned char *sqlite3aLTb = &sqlite3UpperToLower[256-OP_Ne];
20747
+SQLITE_PRIVATE const unsigned char *sqlite3aEQb = &sqlite3UpperToLower[256+6-OP_Ne];
20748
+SQLITE_PRIVATE const unsigned char *sqlite3aGTb = &sqlite3UpperToLower[256+12-OP_Ne];
2070520749
2070620750
/*
2070720751
** The following 256 byte lookup table is used to support SQLites built-in
2070820752
** equivalents to the following standard library functions:
2070920753
**
@@ -23472,11 +23516,11 @@
2347223516
return rc;
2347323517
}
2347423518
SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
2347523519
DO_OS_MALLOC_TEST(0);
2347623520
assert( dirSync==0 || dirSync==1 );
23477
- return pVfs->xDelete(pVfs, zPath, dirSync);
23521
+ return pVfs->xDelete!=0 ? pVfs->xDelete(pVfs, zPath, dirSync) : SQLITE_OK;
2347823522
}
2347923523
SQLITE_PRIVATE int sqlite3OsAccess(
2348023524
sqlite3_vfs *pVfs,
2348123525
const char *zPath,
2348223526
int flags,
@@ -28461,11 +28505,11 @@
2846128505
/* The rest are extensions, not normally found in printf() */
2846228506
#define etSQLESCAPE 9 /* Strings with '\'' doubled. %q */
2846328507
#define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
2846428508
NULL pointers replaced by SQL NULL. %Q */
2846528509
#define etTOKEN 11 /* a pointer to a Token structure */
28466
-#define etSRCLIST 12 /* a pointer to a SrcList */
28510
+#define etSRCITEM 12 /* a pointer to a SrcItem */
2846728511
#define etPOINTER 13 /* The %p conversion */
2846828512
#define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
2846928513
#define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
2847028514
#define etDECIMAL 16 /* %d or %u, but not %x, %o */
2847128515
@@ -28527,13 +28571,19 @@
2852728571
{ '%', 0, 0, etPERCENT, 0, 0 },
2852828572
{ 'p', 16, 0, etPOINTER, 0, 1 },
2852928573
2853028574
/* All the rest are undocumented and are for internal use only */
2853128575
{ 'T', 0, 0, etTOKEN, 0, 0 },
28532
- { 'S', 0, 0, etSRCLIST, 0, 0 },
28576
+ { 'S', 0, 0, etSRCITEM, 0, 0 },
2853328577
{ 'r', 10, 1, etORDINAL, 0, 0 },
2853428578
};
28579
+
28580
+/* Notes:
28581
+**
28582
+** %S Takes a pointer to SrcItem. Shows name or database.name
28583
+** %!S Like %S but prefer the zName over the zAlias
28584
+*/
2853528585
2853628586
/* Floating point constants used for rounding */
2853728587
static const double arRound[] = {
2853828588
5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
2853928589
5.0e-06, 5.0e-07, 5.0e-08, 5.0e-09, 5.0e-10,
@@ -29285,25 +29335,28 @@
2928529335
sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
2928629336
}
2928729337
length = width = 0;
2928829338
break;
2928929339
}
29290
- case etSRCLIST: {
29291
- SrcList *pSrc;
29292
- int k;
29340
+ case etSRCITEM: {
2929329341
SrcItem *pItem;
2929429342
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
29295
- pSrc = va_arg(ap, SrcList*);
29296
- k = va_arg(ap, int);
29297
- pItem = &pSrc->a[k];
29343
+ pItem = va_arg(ap, SrcItem*);
2929829344
assert( bArgList==0 );
29299
- assert( k>=0 && k<pSrc->nSrc );
29300
- if( pItem->zDatabase ){
29301
- sqlite3_str_appendall(pAccum, pItem->zDatabase);
29302
- sqlite3_str_append(pAccum, ".", 1);
29345
+ if( pItem->zAlias && !flag_altform2 ){
29346
+ sqlite3_str_appendall(pAccum, pItem->zAlias);
29347
+ }else if( pItem->zName ){
29348
+ if( pItem->zDatabase ){
29349
+ sqlite3_str_appendall(pAccum, pItem->zDatabase);
29350
+ sqlite3_str_append(pAccum, ".", 1);
29351
+ }
29352
+ sqlite3_str_appendall(pAccum, pItem->zName);
29353
+ }else if( pItem->zAlias ){
29354
+ sqlite3_str_appendall(pAccum, pItem->zAlias);
29355
+ }else if( ALWAYS(pItem->pSelect) ){
29356
+ sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
2930329357
}
29304
- sqlite3_str_appendall(pAccum, pItem->zName);
2930529358
length = width = 0;
2930629359
break;
2930729360
}
2930829361
default: {
2930929362
assert( xtype==etINVALID );
@@ -29879,23 +29932,15 @@
2987929932
for(i=0; i<pSrc->nSrc; i++){
2988029933
const SrcItem *pItem = &pSrc->a[i];
2988129934
StrAccum x;
2988229935
char zLine[100];
2988329936
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
29884
- sqlite3_str_appendf(&x, "{%d:*}", pItem->iCursor);
29885
- if( pItem->zDatabase ){
29886
- sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
29887
- }else if( pItem->zName ){
29888
- sqlite3_str_appendf(&x, " %s", pItem->zName);
29889
- }
29937
+ sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
2989029938
if( pItem->pTab ){
2989129939
sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
2989229940
pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
2989329941
}
29894
- if( pItem->zAlias ){
29895
- sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
29896
- }
2989729942
if( pItem->fg.jointype & JT_LEFT ){
2989829943
sqlite3_str_appendf(&x, " LEFT-JOIN");
2989929944
}
2990029945
if( pItem->fg.fromDDL ){
2990129946
sqlite3_str_appendf(&x, " DDL");
@@ -33531,11 +33576,11 @@
3353133576
/* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
3353233577
/* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
3353333578
/* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
3353433579
/* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
3353533580
/* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
33536
- /* 58 */ "ElseNotEq" OpHelp(""),
33581
+ /* 58 */ "ElseEq" OpHelp(""),
3353733582
/* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
3353833583
/* 60 */ "IncrVacuum" OpHelp(""),
3353933584
/* 61 */ "VNext" OpHelp(""),
3354033585
/* 62 */ "Init" OpHelp("Start at P2"),
3354133586
/* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
@@ -33562,23 +33607,23 @@
3356233607
/* 84 */ "RealAffinity" OpHelp(""),
3356333608
/* 85 */ "Cast" OpHelp("affinity(r[P1])"),
3356433609
/* 86 */ "Permutation" OpHelp(""),
3356533610
/* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
3356633611
/* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
33567
- /* 89 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
33568
- /* 90 */ "Column" OpHelp("r[P3]=PX"),
33569
- /* 91 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
33570
- /* 92 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
33571
- /* 93 */ "Count" OpHelp("r[P2]=count()"),
33572
- /* 94 */ "ReadCookie" OpHelp(""),
33573
- /* 95 */ "SetCookie" OpHelp(""),
33574
- /* 96 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
33575
- /* 97 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
33576
- /* 98 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
33577
- /* 99 */ "OpenDup" OpHelp(""),
33578
- /* 100 */ "OpenAutoindex" OpHelp("nColumn=P2"),
33579
- /* 101 */ "OpenEphemeral" OpHelp("nColumn=P2"),
33612
+ /* 89 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
33613
+ /* 90 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
33614
+ /* 91 */ "Column" OpHelp("r[P3]=PX"),
33615
+ /* 92 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
33616
+ /* 93 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
33617
+ /* 94 */ "Count" OpHelp("r[P2]=count()"),
33618
+ /* 95 */ "ReadCookie" OpHelp(""),
33619
+ /* 96 */ "SetCookie" OpHelp(""),
33620
+ /* 97 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
33621
+ /* 98 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
33622
+ /* 99 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
33623
+ /* 100 */ "OpenDup" OpHelp(""),
33624
+ /* 101 */ "OpenAutoindex" OpHelp("nColumn=P2"),
3358033625
/* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
3358133626
/* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
3358233627
/* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
3358333628
/* 105 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
3358433629
/* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -33585,77 +33630,78 @@
3358533630
/* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
3358633631
/* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
3358733632
/* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
3358833633
/* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
3358933634
/* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
33590
- /* 112 */ "SorterOpen" OpHelp(""),
33635
+ /* 112 */ "OpenEphemeral" OpHelp("nColumn=P2"),
3359133636
/* 113 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
33592
- /* 114 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
33593
- /* 115 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
33637
+ /* 114 */ "SorterOpen" OpHelp(""),
33638
+ /* 115 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
3359433639
/* 116 */ "String8" OpHelp("r[P2]='P4'"),
33595
- /* 117 */ "Close" OpHelp(""),
33596
- /* 118 */ "ColumnsUsed" OpHelp(""),
33597
- /* 119 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
33598
- /* 120 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
33599
- /* 121 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
33600
- /* 122 */ "NewRowid" OpHelp("r[P2]=rowid"),
33601
- /* 123 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
33602
- /* 124 */ "RowCell" OpHelp(""),
33603
- /* 125 */ "Delete" OpHelp(""),
33604
- /* 126 */ "ResetCount" OpHelp(""),
33605
- /* 127 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
33606
- /* 128 */ "SorterData" OpHelp("r[P2]=data"),
33607
- /* 129 */ "RowData" OpHelp("r[P2]=data"),
33608
- /* 130 */ "Rowid" OpHelp("r[P2]=rowid"),
33609
- /* 131 */ "NullRow" OpHelp(""),
33610
- /* 132 */ "SeekEnd" OpHelp(""),
33611
- /* 133 */ "IdxInsert" OpHelp("key=r[P2]"),
33612
- /* 134 */ "SorterInsert" OpHelp("key=r[P2]"),
33613
- /* 135 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
33614
- /* 136 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
33615
- /* 137 */ "IdxRowid" OpHelp("r[P2]=rowid"),
33616
- /* 138 */ "FinishSeek" OpHelp(""),
33617
- /* 139 */ "Destroy" OpHelp(""),
33618
- /* 140 */ "Clear" OpHelp(""),
33619
- /* 141 */ "ResetSorter" OpHelp(""),
33620
- /* 142 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
33621
- /* 143 */ "SqlExec" OpHelp(""),
33622
- /* 144 */ "ParseSchema" OpHelp(""),
33623
- /* 145 */ "LoadAnalysis" OpHelp(""),
33624
- /* 146 */ "DropTable" OpHelp(""),
33625
- /* 147 */ "DropIndex" OpHelp(""),
33626
- /* 148 */ "DropTrigger" OpHelp(""),
33627
- /* 149 */ "IntegrityCk" OpHelp(""),
33628
- /* 150 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
33629
- /* 151 */ "Param" OpHelp(""),
33640
+ /* 117 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
33641
+ /* 118 */ "Close" OpHelp(""),
33642
+ /* 119 */ "ColumnsUsed" OpHelp(""),
33643
+ /* 120 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
33644
+ /* 121 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
33645
+ /* 122 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
33646
+ /* 123 */ "NewRowid" OpHelp("r[P2]=rowid"),
33647
+ /* 124 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
33648
+ /* 125 */ "RowCell" OpHelp(""),
33649
+ /* 126 */ "Delete" OpHelp(""),
33650
+ /* 127 */ "ResetCount" OpHelp(""),
33651
+ /* 128 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
33652
+ /* 129 */ "SorterData" OpHelp("r[P2]=data"),
33653
+ /* 130 */ "RowData" OpHelp("r[P2]=data"),
33654
+ /* 131 */ "Rowid" OpHelp("r[P2]=rowid"),
33655
+ /* 132 */ "NullRow" OpHelp(""),
33656
+ /* 133 */ "SeekEnd" OpHelp(""),
33657
+ /* 134 */ "IdxInsert" OpHelp("key=r[P2]"),
33658
+ /* 135 */ "SorterInsert" OpHelp("key=r[P2]"),
33659
+ /* 136 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
33660
+ /* 137 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
33661
+ /* 138 */ "IdxRowid" OpHelp("r[P2]=rowid"),
33662
+ /* 139 */ "FinishSeek" OpHelp(""),
33663
+ /* 140 */ "Destroy" OpHelp(""),
33664
+ /* 141 */ "Clear" OpHelp(""),
33665
+ /* 142 */ "ResetSorter" OpHelp(""),
33666
+ /* 143 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
33667
+ /* 144 */ "SqlExec" OpHelp(""),
33668
+ /* 145 */ "ParseSchema" OpHelp(""),
33669
+ /* 146 */ "LoadAnalysis" OpHelp(""),
33670
+ /* 147 */ "DropTable" OpHelp(""),
33671
+ /* 148 */ "DropIndex" OpHelp(""),
33672
+ /* 149 */ "DropTrigger" OpHelp(""),
33673
+ /* 150 */ "IntegrityCk" OpHelp(""),
33674
+ /* 151 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
3363033675
/* 152 */ "Real" OpHelp("r[P2]=P4"),
33631
- /* 153 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33632
- /* 154 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
33633
- /* 155 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
33634
- /* 156 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
33635
- /* 157 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
33636
- /* 158 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
33637
- /* 159 */ "AggValue" OpHelp("r[P3]=value N=P2"),
33638
- /* 160 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
33639
- /* 161 */ "Expire" OpHelp(""),
33640
- /* 162 */ "CursorLock" OpHelp(""),
33641
- /* 163 */ "CursorUnlock" OpHelp(""),
33642
- /* 164 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
33643
- /* 165 */ "VBegin" OpHelp(""),
33644
- /* 166 */ "VCreate" OpHelp(""),
33645
- /* 167 */ "VDestroy" OpHelp(""),
33646
- /* 168 */ "VOpen" OpHelp(""),
33647
- /* 169 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
33648
- /* 170 */ "VRename" OpHelp(""),
33649
- /* 171 */ "Pagecount" OpHelp(""),
33650
- /* 172 */ "MaxPgcnt" OpHelp(""),
33651
- /* 173 */ "Trace" OpHelp(""),
33652
- /* 174 */ "CursorHint" OpHelp(""),
33653
- /* 175 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
33654
- /* 176 */ "Noop" OpHelp(""),
33655
- /* 177 */ "Explain" OpHelp(""),
33656
- /* 178 */ "Abortable" OpHelp(""),
33676
+ /* 153 */ "Param" OpHelp(""),
33677
+ /* 154 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33678
+ /* 155 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
33679
+ /* 156 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
33680
+ /* 157 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
33681
+ /* 158 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
33682
+ /* 159 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
33683
+ /* 160 */ "AggValue" OpHelp("r[P3]=value N=P2"),
33684
+ /* 161 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
33685
+ /* 162 */ "Expire" OpHelp(""),
33686
+ /* 163 */ "CursorLock" OpHelp(""),
33687
+ /* 164 */ "CursorUnlock" OpHelp(""),
33688
+ /* 165 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
33689
+ /* 166 */ "VBegin" OpHelp(""),
33690
+ /* 167 */ "VCreate" OpHelp(""),
33691
+ /* 168 */ "VDestroy" OpHelp(""),
33692
+ /* 169 */ "VOpen" OpHelp(""),
33693
+ /* 170 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
33694
+ /* 171 */ "VRename" OpHelp(""),
33695
+ /* 172 */ "Pagecount" OpHelp(""),
33696
+ /* 173 */ "MaxPgcnt" OpHelp(""),
33697
+ /* 174 */ "Trace" OpHelp(""),
33698
+ /* 175 */ "CursorHint" OpHelp(""),
33699
+ /* 176 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
33700
+ /* 177 */ "Noop" OpHelp(""),
33701
+ /* 178 */ "Explain" OpHelp(""),
33702
+ /* 179 */ "Abortable" OpHelp(""),
3365733703
};
3365833704
return azName[i];
3365933705
}
3366033706
#endif
3366133707
@@ -37810,10 +37856,11 @@
3781037856
}
3781137857
}
3781237858
3781337859
/* Forward declaration */
3781437860
static int unixGetTempname(int nBuf, char *zBuf);
37861
+static int unixFcntlExternalReader(unixFile*, int*);
3781537862
3781637863
/*
3781737864
** Information and control of an open file handle.
3781837865
*/
3781937866
static int unixFileControl(sqlite3_file *id, int op, void *pArg){
@@ -37926,10 +37973,14 @@
3792637973
case SQLITE_FCNTL_SET_LOCKPROXYFILE:
3792737974
case SQLITE_FCNTL_GET_LOCKPROXYFILE: {
3792837975
return proxyFileControl(id,op,pArg);
3792937976
}
3793037977
#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
37978
+
37979
+ case SQLITE_FCNTL_EXTERNAL_READER: {
37980
+ return unixFcntlExternalReader((unixFile*)id, (int*)pArg);
37981
+ }
3793137982
}
3793237983
return SQLITE_NOTFOUND;
3793337984
}
3793437985
3793537986
/*
@@ -38170,10 +38221,44 @@
3817038221
/*
3817138222
** Constants used for locking
3817238223
*/
3817338224
#define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
3817438225
#define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
38226
+
38227
+/*
38228
+** Use F_GETLK to check whether or not there are any readers with open
38229
+** wal-mode transactions in other processes on database file pFile. If
38230
+** no error occurs, return SQLITE_OK and set (*piOut) to 1 if there are
38231
+** such transactions, or 0 otherwise. If an error occurs, return an
38232
+** SQLite error code. The final value of *piOut is undefined in this
38233
+** case.
38234
+*/
38235
+static int unixFcntlExternalReader(unixFile *pFile, int *piOut){
38236
+ int rc = SQLITE_OK;
38237
+ *piOut = 0;
38238
+ if( pFile->pShm){
38239
+ unixShmNode *pShmNode = pFile->pShm->pShmNode;
38240
+ struct flock f;
38241
+
38242
+ memset(&f, 0, sizeof(f));
38243
+ f.l_type = F_WRLCK;
38244
+ f.l_whence = SEEK_SET;
38245
+ f.l_start = UNIX_SHM_BASE + 3;
38246
+ f.l_len = SQLITE_SHM_NLOCK - 3;
38247
+
38248
+ sqlite3_mutex_enter(pShmNode->pShmMutex);
38249
+ if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){
38250
+ rc = SQLITE_IOERR_LOCK;
38251
+ }else{
38252
+ *piOut = (f.l_type!=F_UNLCK);
38253
+ }
38254
+ sqlite3_mutex_leave(pShmNode->pShmMutex);
38255
+ }
38256
+
38257
+ return rc;
38258
+}
38259
+
3817538260
3817638261
/*
3817738262
** Apply posix advisory locks for all bytes from ofst through ofst+n-1.
3817838263
**
3817938264
** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking
@@ -56081,11 +56166,12 @@
5608156166
** Once this function has been called, the transaction must either be
5608256167
** rolled back or committed. It is not safe to call this function and
5608356168
** then continue writing to the database.
5608456169
*/
5608556170
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
56086
- assert( pPager->dbSize>=nPage );
56171
+ assert( pPager->dbSize>=nPage || CORRUPT_DB );
56172
+ testcase( pPager->dbSize<nPage );
5608756173
assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
5608856174
pPager->dbSize = nPage;
5608956175
5609056176
/* At one point the code here called assertTruncateConstraint() to
5609156177
** ensure that all pages being truncated away by this operation are,
@@ -70348,11 +70434,13 @@
7034870434
** to the last entry in the b-tree. */
7034970435
int ii;
7035070436
for(ii=0; ii<pCur->iPage; ii++){
7035170437
assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
7035270438
}
70353
- assert( pCur->ix==pCur->pPage->nCell-1 );
70439
+ assert( pCur->ix==pCur->pPage->nCell-1 || CORRUPT_DB );
70440
+ testcase( pCur->ix!=pCur->pPage->nCell-1 );
70441
+ /* ^-- dbsqlfuzz b92b72e4de80b5140c30ab71372ca719b8feb618 */
7035470442
assert( pCur->pPage->leaf );
7035570443
#endif
7035670444
*pRes = 0;
7035770445
return SQLITE_OK;
7035870446
}
@@ -71115,11 +71203,11 @@
7111571203
closest = 0;
7111671204
}
7111771205
7111871206
iPage = get4byte(&aData[8+closest*4]);
7111971207
testcase( iPage==mxPage );
71120
- if( iPage>mxPage ){
71208
+ if( iPage>mxPage || iPage<2 ){
7112171209
rc = SQLITE_CORRUPT_PGNO(iTrunk);
7112271210
goto end_allocate_page;
7112371211
}
7112471212
testcase( iPage==mxPage );
7112571213
if( !searchList
@@ -74062,11 +74150,11 @@
7406274150
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
7406374151
if( pCur->eState==CURSOR_REQUIRESEEK ){
7406474152
rc = btreeRestoreCursorPosition(pCur);
7406574153
if( rc ) return rc;
7406674154
}
74067
- assert( pCur->eState==CURSOR_VALID );
74155
+ assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
7406874156
7406974157
iCellDepth = pCur->iPage;
7407074158
iCellIdx = pCur->ix;
7407174159
pPage = pCur->pPage;
7407274160
pCell = findCell(pPage, iCellIdx);
@@ -79862,15 +79950,11 @@
7986279950
if( zOpName[nOpName+1] ){
7986379951
int seenCom = 0;
7986479952
char c;
7986579953
zSynopsis = zOpName += nOpName + 1;
7986679954
if( strncmp(zSynopsis,"IF ",3)==0 ){
79867
- if( pOp->p5 & SQLITE_STOREP2 ){
79868
- sqlite3_snprintf(sizeof(zAlt), zAlt, "r[P2] = (%s)", zSynopsis+3);
79869
- }else{
79870
- sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3);
79871
- }
79955
+ sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3);
7987279956
zSynopsis = zAlt;
7987379957
}
7987479958
for(ii=0; (c = zSynopsis[ii])!=0; ii++){
7987579959
if( c=='P' ){
7987679960
c = zSynopsis[++ii];
@@ -87438,11 +87522,11 @@
8743887522
*/
8743987523
case OP_ResultRow: {
8744087524
Mem *pMem;
8744187525
int i;
8744287526
assert( p->nResColumn==pOp->p2 );
87443
- assert( pOp->p1>0 );
87527
+ assert( pOp->p1>0 || CORRUPT_DB );
8744487528
assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
8744587529
8744687530
/* Invalidate all ephemeral cursor row caches */
8744787531
p->cacheCtr = (p->cacheCtr + 2)|1;
8744887532
@@ -87880,12 +87964,11 @@
8788087964
8788187965
/* Opcode: Eq P1 P2 P3 P4 P5
8788287966
** Synopsis: IF r[P3]==r[P1]
8788387967
**
8788487968
** Compare the values in register P1 and P3. If reg(P3)==reg(P1) then
87885
-** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5, then
87886
-** store the result of comparison in register P2.
87969
+** jump to address P2.
8788787970
**
8788887971
** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
8788987972
** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
8789087973
** to coerce both inputs according to this affinity before the
8789187974
** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
@@ -87907,31 +87990,25 @@
8790787990
** true or false and is never NULL. If both operands are NULL then the result
8790887991
** of comparison is true. If either operand is NULL then the result is false.
8790987992
** If neither operand is NULL the result is the same as it would be if
8791087993
** the SQLITE_NULLEQ flag were omitted from P5.
8791187994
**
87912
-** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
87913
-** content of r[P2] is only changed if the new value is NULL or 0 (false).
87914
-** In other words, a prior r[P2] value will not be overwritten by 1 (true).
87995
+** This opcode saves the result of comparison for use by the new
87996
+** OP_Jump opcode.
8791587997
*/
8791687998
/* Opcode: Ne P1 P2 P3 P4 P5
8791787999
** Synopsis: IF r[P3]!=r[P1]
8791888000
**
8791988001
** This works just like the Eq opcode except that the jump is taken if
8792088002
** the operands in registers P1 and P3 are not equal. See the Eq opcode for
8792188003
** additional information.
87922
-**
87923
-** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
87924
-** content of r[P2] is only changed if the new value is NULL or 1 (true).
87925
-** In other words, a prior r[P2] value will not be overwritten by 0 (false).
8792688004
*/
8792788005
/* Opcode: Lt P1 P2 P3 P4 P5
8792888006
** Synopsis: IF r[P3]<r[P1]
8792988007
**
8793088008
** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
87931
-** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5 store
87932
-** the result of comparison (0 or 1 or NULL) into register P2.
88009
+** jump to address P2.
8793388010
**
8793488011
** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
8793588012
** reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL
8793688013
** bit is clear then fall through if either operand is NULL.
8793788014
**
@@ -87950,10 +88027,13 @@
8795088027
** P4 is used to do the comparison. If P4 is not specified then
8795188028
** memcmp() is used to compare text string. If both values are
8795288029
** numeric, then a numeric comparison is used. If the two values
8795388030
** are of different types, then numbers are considered less than
8795488031
** strings and strings are considered less than blobs.
88032
+**
88033
+** This opcode saves the result of comparison for use by the new
88034
+** OP_Jump opcode.
8795588035
*/
8795688036
/* Opcode: Le P1 P2 P3 P4 P5
8795788037
** Synopsis: IF r[P3]<=r[P1]
8795888038
**
8795988039
** This works just like the Lt opcode except that the jump is taken if
@@ -88009,21 +88089,14 @@
8800988089
}else{
8801088090
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
8801188091
** then the result is always NULL.
8801288092
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
8801388093
*/
88014
- if( pOp->p5 & SQLITE_STOREP2 ){
88015
- pOut = &aMem[pOp->p2];
88016
- iCompare = 1; /* Operands are not equal */
88017
- memAboutToChange(p, pOut);
88018
- MemSetTypeFlag(pOut, MEM_Null);
88019
- REGISTER_TRACE(pOp->p2, pOut);
88020
- }else{
88021
- VdbeBranchTaken(2,3);
88022
- if( pOp->p5 & SQLITE_JUMPIFNULL ){
88023
- goto jump_to_p2;
88024
- }
88094
+ iCompare = 1; /* Operands are not equal */
88095
+ VdbeBranchTaken(2,3);
88096
+ if( pOp->p5 & SQLITE_JUMPIFNULL ){
88097
+ goto jump_to_p2;
8802588098
}
8802688099
break;
8802788100
}
8802888101
}else{
8802988102
/* Neither operand is NULL. Do a comparison. */
@@ -88076,88 +88149,58 @@
8807688149
** operator actually is. The next block of code depends on the fact
8807788150
** that the 6 comparison operators are consecutive integers in this
8807888151
** order: NE, EQ, GT, LE, LT, GE */
8807988152
assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 );
8808088153
assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 );
88081
- if( res<0 ){ /* ne, eq, gt, le, lt, ge */
88082
- static const unsigned char aLTb[] = { 1, 0, 0, 1, 1, 0 };
88083
- res2 = aLTb[pOp->opcode - OP_Ne];
88154
+ if( res<0 ){
88155
+ res2 = sqlite3aLTb[pOp->opcode];
8808488156
}else if( res==0 ){
88085
- static const unsigned char aEQb[] = { 0, 1, 0, 1, 0, 1 };
88086
- res2 = aEQb[pOp->opcode - OP_Ne];
88157
+ res2 = sqlite3aEQb[pOp->opcode];
8808788158
}else{
88088
- static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 };
88089
- res2 = aGTb[pOp->opcode - OP_Ne];
88159
+ res2 = sqlite3aGTb[pOp->opcode];
8809088160
}
88161
+ iCompare = res;
8809188162
8809288163
/* Undo any changes made by applyAffinity() to the input registers. */
8809388164
assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
8809488165
pIn3->flags = flags3;
8809588166
assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
8809688167
pIn1->flags = flags1;
8809788168
88098
- if( pOp->p5 & SQLITE_STOREP2 ){
88099
- pOut = &aMem[pOp->p2];
88100
- iCompare = res;
88101
- if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
88102
- /* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1
88103
- ** and prevents OP_Ne from overwriting NULL with 0. This flag
88104
- ** is only used in contexts where either:
88105
- ** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0)
88106
- ** (2) op==OP_Ne && (r[P2]==NULL || r[P2]==1)
88107
- ** Therefore it is not necessary to check the content of r[P2] for
88108
- ** NULL. */
88109
- assert( pOp->opcode==OP_Ne || pOp->opcode==OP_Eq );
88110
- assert( res2==0 || res2==1 );
88111
- testcase( res2==0 && pOp->opcode==OP_Eq );
88112
- testcase( res2==1 && pOp->opcode==OP_Eq );
88113
- testcase( res2==0 && pOp->opcode==OP_Ne );
88114
- testcase( res2==1 && pOp->opcode==OP_Ne );
88115
- if( (pOp->opcode==OP_Eq)==res2 ) break;
88116
- }
88117
- memAboutToChange(p, pOut);
88118
- MemSetTypeFlag(pOut, MEM_Int);
88119
- pOut->u.i = res2;
88120
- REGISTER_TRACE(pOp->p2, pOut);
88121
- }else{
88122
- VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
88123
- if( res2 ){
88124
- goto jump_to_p2;
88125
- }
88169
+ VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
88170
+ if( res2 ){
88171
+ goto jump_to_p2;
8812688172
}
8812788173
break;
8812888174
}
8812988175
88130
-/* Opcode: ElseNotEq * P2 * * *
88176
+/* Opcode: ElseEq * P2 * * *
8813188177
**
8813288178
** This opcode must follow an OP_Lt or OP_Gt comparison operator. There
8813388179
** can be zero or more OP_ReleaseReg opcodes intervening, but no other
8813488180
** opcodes are allowed to occur between this instruction and the previous
88135
-** OP_Lt or OP_Gt. Furthermore, the prior OP_Lt or OP_Gt must have the
88136
-** SQLITE_STOREP2 bit set in the P5 field.
88181
+** OP_Lt or OP_Gt.
8813788182
**
8813888183
** If result of an OP_Eq comparison on the same two operands as the
88139
-** prior OP_Lt or OP_Gt would have been NULL or false (0), then then
88140
-** jump to P2. If the result of an OP_Eq comparison on the two previous
88141
-** operands would have been true (1), then fall through.
88184
+** prior OP_Lt or OP_Gt would have been true, then jump to P2.
88185
+** If the result of an OP_Eq comparison on the two previous
88186
+** operands would have been false or NULL, then fall through.
8814288187
*/
88143
-case OP_ElseNotEq: { /* same as TK_ESCAPE, jump */
88188
+case OP_ElseEq: { /* same as TK_ESCAPE, jump */
8814488189
8814588190
#ifdef SQLITE_DEBUG
8814688191
/* Verify the preconditions of this opcode - that it follows an OP_Lt or
88147
- ** OP_Gt with the SQLITE_STOREP2 flag set, with zero or more intervening
88148
- ** OP_ReleaseReg opcodes */
88192
+ ** OP_Gt with zero or more intervening OP_ReleaseReg opcodes */
8814988193
int iAddr;
8815088194
for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
8815188195
if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
8815288196
assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
88153
- assert( aOp[iAddr].p5 & SQLITE_STOREP2 );
8815488197
break;
8815588198
}
8815688199
#endif /* SQLITE_DEBUG */
88157
- VdbeBranchTaken(iCompare!=0, 2);
88158
- if( iCompare!=0 ) goto jump_to_p2;
88200
+ VdbeBranchTaken(iCompare==0, 2);
88201
+ if( iCompare==0 ) goto jump_to_p2;
8815988202
break;
8816088203
}
8816188204
8816288205
8816388206
/* Opcode: Permutation * * * P4 *
@@ -88463,10 +88506,28 @@
8846388506
if( (pIn1->flags & MEM_Null)!=0 ){
8846488507
goto jump_to_p2;
8846588508
}
8846688509
break;
8846788510
}
88511
+
88512
+/* Opcode: ZeroOrNull P1 P2 P3 * *
88513
+** Synopsis: r[P2] = 0 OR NULL
88514
+**
88515
+** If all both registers P1 and P3 are NOT NULL, then store a zero in
88516
+** register P2. If either registers P1 or P3 are NULL then put
88517
+** a NULL in register P2.
88518
+*/
88519
+case OP_ZeroOrNull: { /* in1, in2, out2, in3 */
88520
+ if( (aMem[pOp->p1].flags & MEM_Null)!=0
88521
+ || (aMem[pOp->p3].flags & MEM_Null)!=0
88522
+ ){
88523
+ sqlite3VdbeMemSetNull(aMem + pOp->p2);
88524
+ }else{
88525
+ sqlite3VdbeMemSetInt64(aMem + pOp->p2, 0);
88526
+ }
88527
+ break;
88528
+}
8846888529
8846988530
/* Opcode: NotNull P1 P2 * * *
8847088531
** Synopsis: if r[P1]!=NULL goto P2
8847188532
**
8847288533
** Jump to P2 if the value in register P1 is not NULL.
@@ -99001,12 +99062,14 @@
9900199062
pTab = 0;
9900299063
#ifndef SQLITE_OMIT_TRIGGER
9900399064
if( pParse->pTriggerTab!=0 ){
9900499065
int op = pParse->eTriggerOp;
9900599066
assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
99006
- if( pParse->bReturning && (pNC->ncFlags & NC_UBaseReg)!=0 ){
99007
- if( zTab==0 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0 ){
99067
+ if( pParse->bReturning ){
99068
+ if( (pNC->ncFlags & NC_UBaseReg)!=0
99069
+ && (zTab==0 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0)
99070
+ ){
9900899071
pExpr->iTable = op!=TK_DELETE;
9900999072
pTab = pParse->pTriggerTab;
9901099073
}
9901199074
}else if( op!=TK_DELETE && zTab && sqlite3StrICmp("new",zTab) == 0 ){
9901299075
pExpr->iTable = 1;
@@ -99186,11 +99249,10 @@
9918699249
*/
9918799250
if( cnt==0 && zTab==0 ){
9918899251
assert( pExpr->op==TK_ID );
9918999252
if( ExprHasProperty(pExpr,EP_DblQuoted)
9919099253
&& areDoubleQuotedStringsEnabled(db, pTopNC)
99191
- && (db->init.bDropColumn==0 || sqlite3StrICmp(zCol, db->init.azInit[0])!=0)
9919299254
){
9919399255
/* If a double-quoted identifier does not match any known column name,
9919499256
** then treat it as a string.
9919599257
**
9919699258
** This hack was added in the early days of SQLite in a misguided attempt
@@ -99201,15 +99263,10 @@
9920199263
** programmers. To all those frustrated programmers, my apologies.
9920299264
**
9920399265
** Someday, I hope to get rid of this hack. Unfortunately there is
9920499266
** a huge amount of legacy SQL that uses it. So for now, we just
9920599267
** issue a warning.
99206
- **
99207
- ** 2021-03-15: ticket 1c24a659e6d7f3a1
99208
- ** Do not do the ID-to-STRING conversion when doing the schema
99209
- ** sanity check following a DROP COLUMN if the identifer name matches
99210
- ** the name of the column being dropped.
9921199268
*/
9921299269
sqlite3_log(SQLITE_WARNING,
9921399270
"double-quoted string literal: \"%w\"", zCol);
9921499271
#ifdef SQLITE_ENABLE_NORMALIZE
9921599272
sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
@@ -101259,10 +101316,11 @@
101259101316
int nLeft = sqlite3ExprVectorSize(pLeft);
101260101317
int i;
101261101318
int regLeft = 0;
101262101319
int regRight = 0;
101263101320
u8 opx = op;
101321
+ int addrCmp = 0;
101264101322
int addrDone = sqlite3VdbeMakeLabel(pParse);
101265101323
int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
101266101324
101267101325
assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
101268101326
if( pParse->nErr ) return;
@@ -101278,53 +101336,62 @@
101278101336
assert( pExpr->op==op || (pExpr->op==TK_IS && op==TK_EQ)
101279101337
|| (pExpr->op==TK_ISNOT && op==TK_NE) );
101280101338
assert( p5==0 || pExpr->op!=op );
101281101339
assert( p5==SQLITE_NULLEQ || pExpr->op==op );
101282101340
101283
- p5 |= SQLITE_STOREP2;
101284
- if( opx==TK_LE ) opx = TK_LT;
101285
- if( opx==TK_GE ) opx = TK_GT;
101341
+ if( op==TK_LE ) opx = TK_LT;
101342
+ if( op==TK_GE ) opx = TK_GT;
101343
+ if( op==TK_NE ) opx = TK_EQ;
101286101344
101287101345
regLeft = exprCodeSubselect(pParse, pLeft);
101288101346
regRight = exprCodeSubselect(pParse, pRight);
101289101347
101348
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, dest);
101290101349
for(i=0; 1 /*Loop exits by "break"*/; i++){
101291101350
int regFree1 = 0, regFree2 = 0;
101292101351
Expr *pL, *pR;
101293101352
int r1, r2;
101294101353
assert( i>=0 && i<nLeft );
101354
+ if( addrCmp ) sqlite3VdbeJumpHere(v, addrCmp);
101295101355
r1 = exprVectorRegister(pParse, pLeft, i, regLeft, &pL, &regFree1);
101296101356
r2 = exprVectorRegister(pParse, pRight, i, regRight, &pR, &regFree2);
101297
- codeCompare(pParse, pL, pR, opx, r1, r2, dest, p5, isCommuted);
101357
+ addrCmp = sqlite3VdbeCurrentAddr(v);
101358
+ codeCompare(pParse, pL, pR, opx, r1, r2, addrDone, p5, isCommuted);
101298101359
testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
101299101360
testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
101300101361
testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
101301101362
testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
101302101363
testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
101303101364
testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
101304101365
sqlite3ReleaseTempReg(pParse, regFree1);
101305101366
sqlite3ReleaseTempReg(pParse, regFree2);
101367
+ if( (opx==TK_LT || opx==TK_GT) && i<nLeft-1 ){
101368
+ addrCmp = sqlite3VdbeAddOp0(v, OP_ElseEq);
101369
+ testcase(opx==TK_LT); VdbeCoverageIf(v,opx==TK_LT);
101370
+ testcase(opx==TK_GT); VdbeCoverageIf(v,opx==TK_GT);
101371
+ }
101372
+ if( p5==SQLITE_NULLEQ ){
101373
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, dest);
101374
+ }else{
101375
+ sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, dest, r2);
101376
+ }
101306101377
if( i==nLeft-1 ){
101307101378
break;
101308101379
}
101309101380
if( opx==TK_EQ ){
101310
- sqlite3VdbeAddOp2(v, OP_IfNot, dest, addrDone); VdbeCoverage(v);
101311
- p5 |= SQLITE_KEEPNULL;
101312
- }else if( opx==TK_NE ){
101313
- sqlite3VdbeAddOp2(v, OP_If, dest, addrDone); VdbeCoverage(v);
101314
- p5 |= SQLITE_KEEPNULL;
101381
+ sqlite3VdbeAddOp2(v, OP_NotNull, dest, addrDone); VdbeCoverage(v);
101315101382
}else{
101316101383
assert( op==TK_LT || op==TK_GT || op==TK_LE || op==TK_GE );
101317
- sqlite3VdbeAddOp2(v, OP_ElseNotEq, 0, addrDone);
101318
- VdbeCoverageIf(v, op==TK_LT);
101319
- VdbeCoverageIf(v, op==TK_GT);
101320
- VdbeCoverageIf(v, op==TK_LE);
101321
- VdbeCoverageIf(v, op==TK_GE);
101384
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
101322101385
if( i==nLeft-2 ) opx = op;
101323101386
}
101324101387
}
101388
+ sqlite3VdbeJumpHere(v, addrCmp);
101325101389
sqlite3VdbeResolveLabel(v, addrDone);
101390
+ if( op==TK_NE ){
101391
+ sqlite3VdbeAddOp2(v, OP_Not, dest, dest);
101392
+ }
101326101393
}
101327101394
101328101395
#if SQLITE_MAX_EXPR_DEPTH>0
101329101396
/*
101330101397
** Check that argument nHeight is less than or equal to the maximum
@@ -102142,10 +102209,11 @@
102142102209
assert( db!=0 );
102143102210
if( p==0 ) return 0;
102144102211
pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p));
102145102212
if( pNew==0 ) return 0;
102146102213
pNew->nExpr = p->nExpr;
102214
+ pNew->nAlloc = p->nAlloc;
102147102215
pItem = pNew->a;
102148102216
pOldItem = p->a;
102149102217
for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
102150102218
Expr *pOldExpr = pOldItem->pExpr;
102151102219
Expr *pNewExpr;
@@ -102314,45 +102382,68 @@
102314102382
**
102315102383
** If a memory allocation error occurs, the entire list is freed and
102316102384
** NULL is returned. If non-NULL is returned, then it is guaranteed
102317102385
** that the new entry was successfully appended.
102318102386
*/
102387
+static const struct ExprList_item zeroItem = {0};
102388
+SQLITE_PRIVATE SQLITE_NOINLINE ExprList *sqlite3ExprListAppendNew(
102389
+ sqlite3 *db, /* Database handle. Used for memory allocation */
102390
+ Expr *pExpr /* Expression to be appended. Might be NULL */
102391
+){
102392
+ struct ExprList_item *pItem;
102393
+ ExprList *pList;
102394
+
102395
+ pList = sqlite3DbMallocRawNN(db, sizeof(ExprList)+sizeof(pList->a[0])*4 );
102396
+ if( pList==0 ){
102397
+ sqlite3ExprDelete(db, pExpr);
102398
+ return 0;
102399
+ }
102400
+ pList->nAlloc = 4;
102401
+ pList->nExpr = 1;
102402
+ pItem = &pList->a[0];
102403
+ *pItem = zeroItem;
102404
+ pItem->pExpr = pExpr;
102405
+ return pList;
102406
+}
102407
+SQLITE_PRIVATE SQLITE_NOINLINE ExprList *sqlite3ExprListAppendGrow(
102408
+ sqlite3 *db, /* Database handle. Used for memory allocation */
102409
+ ExprList *pList, /* List to which to append. Might be NULL */
102410
+ Expr *pExpr /* Expression to be appended. Might be NULL */
102411
+){
102412
+ struct ExprList_item *pItem;
102413
+ ExprList *pNew;
102414
+ pList->nAlloc *= 2;
102415
+ pNew = sqlite3DbRealloc(db, pList,
102416
+ sizeof(*pList)+(pList->nAlloc-1)*sizeof(pList->a[0]));
102417
+ if( pNew==0 ){
102418
+ sqlite3ExprListDelete(db, pList);
102419
+ sqlite3ExprDelete(db, pExpr);
102420
+ return 0;
102421
+ }else{
102422
+ pList = pNew;
102423
+ }
102424
+ pItem = &pList->a[pList->nExpr++];
102425
+ *pItem = zeroItem;
102426
+ pItem->pExpr = pExpr;
102427
+ return pList;
102428
+}
102319102429
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
102320102430
Parse *pParse, /* Parsing context */
102321102431
ExprList *pList, /* List to which to append. Might be NULL */
102322102432
Expr *pExpr /* Expression to be appended. Might be NULL */
102323102433
){
102324102434
struct ExprList_item *pItem;
102325
- sqlite3 *db = pParse->db;
102326
- assert( db!=0 );
102327
- if( pList==0 ){
102328
- pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
102329
- if( pList==0 ){
102330
- goto no_mem;
102331
- }
102332
- pList->nExpr = 0;
102333
- }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
102334
- ExprList *pNew;
102335
- pNew = sqlite3DbRealloc(db, pList,
102336
- sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
102337
- if( pNew==0 ){
102338
- goto no_mem;
102339
- }
102340
- pList = pNew;
102435
+ if( pList==0 ){
102436
+ return sqlite3ExprListAppendNew(pParse->db,pExpr);
102437
+ }
102438
+ if( pList->nAlloc<pList->nExpr+1 ){
102439
+ return sqlite3ExprListAppendGrow(pParse->db,pList,pExpr);
102341102440
}
102342102441
pItem = &pList->a[pList->nExpr++];
102343
- assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) );
102344
- assert( offsetof(struct ExprList_item,pExpr)==0 );
102345
- memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName));
102442
+ *pItem = zeroItem;
102346102443
pItem->pExpr = pExpr;
102347102444
return pList;
102348
-
102349
-no_mem:
102350
- /* Avoid leaking memory if malloc has failed. */
102351
- sqlite3ExprDelete(db, pExpr);
102352
- sqlite3ExprListDelete(db, pList);
102353
- return 0;
102354102445
}
102355102446
102356102447
/*
102357102448
** pColumns and pExpr form a vector assignment which is part of the SET
102358102449
** clause of an UPDATE statement. Like this:
@@ -104003,10 +104094,11 @@
104003104094
destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
104004104095
}
104005104096
if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
104006104097
for(i=0; i<nVector; i++){
104007104098
Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
104099
+ if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
104008104100
if( sqlite3ExprCanBeNull(p) ){
104009104101
sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
104010104102
VdbeCoverage(v);
104011104103
}
104012104104
}
@@ -104694,19 +104786,25 @@
104694104786
if( sqlite3ExprIsVector(pLeft) ){
104695104787
codeVectorCompare(pParse, pExpr, target, op, p5);
104696104788
}else{
104697104789
r1 = sqlite3ExprCodeTemp(pParse, pLeft, &regFree1);
104698104790
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
104699
- codeCompare(pParse, pLeft, pExpr->pRight, op,
104700
- r1, r2, inReg, SQLITE_STOREP2 | p5,
104791
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, inReg);
104792
+ codeCompare(pParse, pLeft, pExpr->pRight, op, r1, r2,
104793
+ sqlite3VdbeCurrentAddr(v)+2, p5,
104701104794
ExprHasProperty(pExpr,EP_Commuted));
104702104795
assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
104703104796
assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
104704104797
assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
104705104798
assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
104706104799
assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
104707104800
assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
104801
+ if( p5==SQLITE_NULLEQ ){
104802
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
104803
+ }else{
104804
+ sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, inReg, r2);
104805
+ }
104708104806
testcase( regFree1==0 );
104709104807
testcase( regFree2==0 );
104710104808
}
104711104809
break;
104712104810
}
@@ -106820,31 +106918,55 @@
106820106918
static void renameTestSchema(
106821106919
Parse *pParse, /* Parse context */
106822106920
const char *zDb, /* Name of db to verify schema of */
106823106921
int bTemp, /* True if this is the temp db */
106824106922
const char *zWhen, /* "when" part of error message */
106825
- const char *zDropColumn /* Name of column being dropped */
106923
+ int bNoDQS /* Do not allow DQS in the schema */
106826106924
){
106827106925
pParse->colNamesSet = 1;
106828106926
sqlite3NestedParse(pParse,
106829106927
"SELECT 1 "
106830106928
"FROM \"%w\"." DFLT_SCHEMA_TABLE " "
106831106929
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106832106930
" AND sql NOT LIKE 'create virtual%%'"
106833
- " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %Q)=NULL ",
106931
+ " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL ",
106834106932
zDb,
106835
- zDb, bTemp, zWhen, zDropColumn
106933
+ zDb, bTemp, zWhen, bNoDQS
106836106934
);
106837106935
106838106936
if( bTemp==0 ){
106839106937
sqlite3NestedParse(pParse,
106840106938
"SELECT 1 "
106841106939
"FROM temp." DFLT_SCHEMA_TABLE " "
106842106940
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106843106941
" AND sql NOT LIKE 'create virtual%%'"
106844
- " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %Q)=NULL ",
106845
- zDb, zWhen, zDropColumn
106942
+ " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL ",
106943
+ zDb, zWhen, bNoDQS
106944
+ );
106945
+ }
106946
+}
106947
+
106948
+/*
106949
+** Generate VM code to replace any double-quoted strings (but not double-quoted
106950
+** identifiers) within the "sql" column of the sqlite_schema table in
106951
+** database zDb with their single-quoted equivalents. If argument bTemp is
106952
+** not true, similarly update all SQL statements in the sqlite_schema table
106953
+** of the temp db.
106954
+*/
106955
+static void renameFixQuotes(Parse *pParse, const char *zDb, int bTemp){
106956
+ sqlite3NestedParse(pParse,
106957
+ "UPDATE \"%w\"." DFLT_SCHEMA_TABLE
106958
+ " SET sql = sqlite_rename_quotefix(%Q, sql)"
106959
+ "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106960
+ " AND sql NOT LIKE 'create virtual%%'" , zDb, zDb
106961
+ );
106962
+ if( bTemp==0 ){
106963
+ sqlite3NestedParse(pParse,
106964
+ "UPDATE temp." DFLT_SCHEMA_TABLE
106965
+ " SET sql = sqlite_rename_quotefix('temp', sql)"
106966
+ "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106967
+ " AND sql NOT LIKE 'create virtual%%'"
106846106968
);
106847106969
}
106848106970
}
106849106971
106850106972
/*
@@ -107003,11 +107125,11 @@
107003107125
sqlite3NestedParse(pParse,
107004107126
"UPDATE sqlite_temp_schema SET "
107005107127
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
107006107128
"tbl_name = "
107007107129
"CASE WHEN tbl_name=%Q COLLATE nocase AND "
107008
- " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename',0) "
107130
+ " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) "
107009107131
"THEN %Q ELSE tbl_name END "
107010107132
"WHERE type IN ('view', 'trigger')"
107011107133
, zDb, zTabName, zName, zTabName, zDb, zName);
107012107134
}
107013107135
@@ -107361,10 +107483,14 @@
107361107483
}
107362107484
if( iCol==pTab->nCol ){
107363107485
sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
107364107486
goto exit_rename_column;
107365107487
}
107488
+
107489
+ /* Ensure the schema contains no double-quoted strings */
107490
+ renameTestSchema(pParse, zDb, iSchema==1, "", 0);
107491
+ renameFixQuotes(pParse, zDb, iSchema==1);
107366107492
107367107493
/* Do the rename operation using a recursive UPDATE statement that
107368107494
** uses the sqlite_rename_column() SQL function to compute the new
107369107495
** CREATE statement text for the sqlite_schema table.
107370107496
*/
@@ -107391,11 +107517,11 @@
107391107517
zDb, pTab->zName, iCol, zNew, bQuote
107392107518
);
107393107519
107394107520
/* Drop and reload the database schema. */
107395107521
renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename);
107396
- renameTestSchema(pParse, zDb, iSchema==1, "after rename", 0);
107522
+ renameTestSchema(pParse, zDb, iSchema==1, "after rename", 1);
107397107523
107398107524
exit_rename_column:
107399107525
sqlite3SrcListDelete(db, pSrc);
107400107526
sqlite3DbFree(db, zOld);
107401107527
sqlite3DbFree(db, zNew);
@@ -107815,21 +107941,16 @@
107815107941
static int renameParseSql(
107816107942
Parse *p, /* Memory to use for Parse object */
107817107943
const char *zDb, /* Name of schema SQL belongs to */
107818107944
sqlite3 *db, /* Database handle */
107819107945
const char *zSql, /* SQL to parse */
107820
- int bTemp, /* True if SQL is from temp schema */
107821
- const char *zDropColumn /* Name of column being dropped */
107946
+ int bTemp /* True if SQL is from temp schema */
107822107947
){
107823107948
int rc;
107824107949
char *zErr = 0;
107825107950
107826107951
db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
107827
- if( zDropColumn ){
107828
- db->init.bDropColumn = 1;
107829
- db->init.azInit = (char**)&zDropColumn;
107830
- }
107831107952
107832107953
/* Parse the SQL statement passed as the first argument. If no error
107833107954
** occurs and the parse does not result in a new table, index or
107834107955
** trigger object, the database must be corrupt. */
107835107956
memset(p, 0, sizeof(Parse));
@@ -107858,11 +107979,10 @@
107858107979
}
107859107980
}
107860107981
#endif
107861107982
107862107983
db->init.iDb = 0;
107863
- db->init.bDropColumn = 0;
107864107984
return rc;
107865107985
}
107866107986
107867107987
/*
107868107988
** This function edits SQL statement zSql, replacing each token identified
@@ -107882,51 +108002,76 @@
107882108002
){
107883108003
int nNew = sqlite3Strlen30(zNew);
107884108004
int nSql = sqlite3Strlen30(zSql);
107885108005
sqlite3 *db = sqlite3_context_db_handle(pCtx);
107886108006
int rc = SQLITE_OK;
107887
- char *zQuot;
108007
+ char *zQuot = 0;
107888108008
char *zOut;
107889
- int nQuot;
107890
-
107891
- /* Set zQuot to point to a buffer containing a quoted copy of the
107892
- ** identifier zNew. If the corresponding identifier in the original
107893
- ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
107894
- ** point to zQuot so that all substitutions are made using the
107895
- ** quoted version of the new column name. */
107896
- zQuot = sqlite3MPrintf(db, "\"%w\"", zNew);
107897
- if( zQuot==0 ){
107898
- return SQLITE_NOMEM;
107899
- }else{
107900
- nQuot = sqlite3Strlen30(zQuot);
107901
- }
107902
- if( bQuote ){
107903
- zNew = zQuot;
107904
- nNew = nQuot;
108009
+ int nQuot = 0;
108010
+ char *zBuf1 = 0;
108011
+ char *zBuf2 = 0;
108012
+
108013
+ if( zNew ){
108014
+ /* Set zQuot to point to a buffer containing a quoted copy of the
108015
+ ** identifier zNew. If the corresponding identifier in the original
108016
+ ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
108017
+ ** point to zQuot so that all substitutions are made using the
108018
+ ** quoted version of the new column name. */
108019
+ zQuot = sqlite3MPrintf(db, "\"%w\" ", zNew);
108020
+ if( zQuot==0 ){
108021
+ return SQLITE_NOMEM;
108022
+ }else{
108023
+ nQuot = sqlite3Strlen30(zQuot)-1;
108024
+ }
108025
+
108026
+ assert( nQuot>=nNew );
108027
+ zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1);
108028
+ }else{
108029
+ zOut = (char*)sqlite3DbMallocZero(db, (nSql*2+1) * 3);
108030
+ if( zOut ){
108031
+ zBuf1 = &zOut[nSql*2+1];
108032
+ zBuf2 = &zOut[nSql*4+2];
108033
+ }
107905108034
}
107906108035
107907108036
/* At this point pRename->pList contains a list of RenameToken objects
107908108037
** corresponding to all tokens in the input SQL that must be replaced
107909
- ** with the new column name. All that remains is to construct and
107910
- ** return the edited SQL string. */
107911
- assert( nQuot>=nNew );
107912
- zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1);
108038
+ ** with the new column name, or with single-quoted versions of themselves.
108039
+ ** All that remains is to construct and return the edited SQL string. */
107913108040
if( zOut ){
107914108041
int nOut = nSql;
107915108042
memcpy(zOut, zSql, nSql);
107916108043
while( pRename->pList ){
107917108044
int iOff; /* Offset of token to replace in zOut */
107918
- RenameToken *pBest = renameColumnTokenNext(pRename);
107919
-
107920108045
u32 nReplace;
107921108046
const char *zReplace;
107922
- if( sqlite3IsIdChar(*pBest->t.z) ){
107923
- nReplace = nNew;
107924
- zReplace = zNew;
108047
+ RenameToken *pBest = renameColumnTokenNext(pRename);
108048
+
108049
+ if( zNew ){
108050
+ if( bQuote==0 && sqlite3IsIdChar(*pBest->t.z) ){
108051
+ nReplace = nNew;
108052
+ zReplace = zNew;
108053
+ }else{
108054
+ nReplace = nQuot;
108055
+ zReplace = zQuot;
108056
+ if( pBest->t.z[pBest->t.n]=='"' ) nReplace++;
108057
+ }
107925108058
}else{
107926
- nReplace = nQuot;
107927
- zReplace = zQuot;
108059
+ /* Dequote the double-quoted token. Then requote it again, this time
108060
+ ** using single quotes. If the character immediately following the
108061
+ ** original token within the input SQL was a single quote ('), then
108062
+ ** add another space after the new, single-quoted version of the
108063
+ ** token. This is so that (SELECT "string"'alias') maps to
108064
+ ** (SELECT 'string' 'alias'), and not (SELECT 'string''alias'). */
108065
+ memcpy(zBuf1, pBest->t.z, pBest->t.n);
108066
+ zBuf1[pBest->t.n] = 0;
108067
+ sqlite3Dequote(zBuf1);
108068
+ sqlite3_snprintf(nSql*2, zBuf2, "%Q%s", zBuf1,
108069
+ pBest->t.z[pBest->t.n]=='\'' ? " " : ""
108070
+ );
108071
+ zReplace = zBuf2;
108072
+ nReplace = sqlite3Strlen30(zReplace);
107928108073
}
107929108074
107930108075
iOff = pBest->t.z - zSql;
107931108076
if( pBest->t.n!=nReplace ){
107932108077
memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n],
@@ -108160,11 +108305,11 @@
108160108305
sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
108161108306
108162108307
#ifndef SQLITE_OMIT_AUTHORIZATION
108163108308
db->xAuth = 0;
108164108309
#endif
108165
- rc = renameParseSql(&sParse, zDb, db, zSql, bTemp, 0);
108310
+ rc = renameParseSql(&sParse, zDb, db, zSql, bTemp);
108166108311
108167108312
/* Find tokens that need to be replaced. */
108168108313
memset(&sWalker, 0, sizeof(Walker));
108169108314
sWalker.pParse = &sParse;
108170108315
sWalker.xExprCallback = renameColumnExprCb;
@@ -108364,11 +108509,11 @@
108364108509
sWalker.pParse = &sParse;
108365108510
sWalker.xExprCallback = renameTableExprCb;
108366108511
sWalker.xSelectCallback = renameTableSelectCb;
108367108512
sWalker.u.pRename = &sCtx;
108368108513
108369
- rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, 0);
108514
+ rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
108370108515
108371108516
if( rc==SQLITE_OK ){
108372108517
int isLegacy = (db->flags & SQLITE_LegacyAlter);
108373108518
if( sParse.pNewTable ){
108374108519
Table *pTab = sParse.pNewTable;
@@ -108466,10 +108611,123 @@
108466108611
#endif
108467108612
}
108468108613
108469108614
return;
108470108615
}
108616
+
108617
+static int renameQuotefixExprCb(Walker *pWalker, Expr *pExpr){
108618
+ if( pExpr->op==TK_STRING && (pExpr->flags & EP_DblQuoted) ){
108619
+ renameTokenFind(pWalker->pParse, pWalker->u.pRename, (void*)pExpr);
108620
+ }
108621
+ return WRC_Continue;
108622
+}
108623
+
108624
+/*
108625
+** The implementation of an SQL scalar function that rewrites DDL statements
108626
+** so that any string literals that use double-quotes are modified so that
108627
+** they use single quotes.
108628
+**
108629
+** Two arguments must be passed:
108630
+**
108631
+** 0: Database name ("main", "temp" etc.).
108632
+** 1: SQL statement to edit.
108633
+**
108634
+** The returned value is the modified SQL statement. For example, given
108635
+** the database schema:
108636
+**
108637
+** CREATE TABLE t1(a, b, c);
108638
+**
108639
+** SELECT sqlite_rename_quotefix('main',
108640
+** 'CREATE VIEW v1 AS SELECT "a", "string" FROM t1'
108641
+** );
108642
+**
108643
+** returns the string:
108644
+**
108645
+** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
108646
+*/
108647
+static void renameQuotefixFunc(
108648
+ sqlite3_context *context,
108649
+ int NotUsed,
108650
+ sqlite3_value **argv
108651
+){
108652
+ sqlite3 *db = sqlite3_context_db_handle(context);
108653
+ char const *zDb = (const char*)sqlite3_value_text(argv[0]);
108654
+ char const *zInput = (const char*)sqlite3_value_text(argv[1]);
108655
+
108656
+#ifndef SQLITE_OMIT_AUTHORIZATION
108657
+ sqlite3_xauth xAuth = db->xAuth;
108658
+ db->xAuth = 0;
108659
+#endif
108660
+
108661
+ sqlite3BtreeEnterAll(db);
108662
+
108663
+ UNUSED_PARAMETER(NotUsed);
108664
+ if( zDb && zInput ){
108665
+ int rc;
108666
+ Parse sParse;
108667
+ rc = renameParseSql(&sParse, zDb, db, zInput, 0);
108668
+
108669
+ if( rc==SQLITE_OK ){
108670
+ RenameCtx sCtx;
108671
+ Walker sWalker;
108672
+
108673
+ /* Walker to find tokens that need to be replaced. */
108674
+ memset(&sCtx, 0, sizeof(RenameCtx));
108675
+ memset(&sWalker, 0, sizeof(Walker));
108676
+ sWalker.pParse = &sParse;
108677
+ sWalker.xExprCallback = renameQuotefixExprCb;
108678
+ sWalker.xSelectCallback = renameColumnSelectCb;
108679
+ sWalker.u.pRename = &sCtx;
108680
+
108681
+ if( sParse.pNewTable ){
108682
+ Select *pSelect = sParse.pNewTable->pSelect;
108683
+ if( pSelect ){
108684
+ pSelect->selFlags &= ~SF_View;
108685
+ sParse.rc = SQLITE_OK;
108686
+ sqlite3SelectPrep(&sParse, pSelect, 0);
108687
+ rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
108688
+ if( rc==SQLITE_OK ){
108689
+ sqlite3WalkSelect(&sWalker, pSelect);
108690
+ }
108691
+ }else{
108692
+ int i;
108693
+ sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
108694
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
108695
+ for(i=0; i<sParse.pNewTable->nCol; i++){
108696
+ sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
108697
+ }
108698
+#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
108699
+ }
108700
+ }else if( sParse.pNewIndex ){
108701
+ sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr);
108702
+ sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere);
108703
+ }else{
108704
+#ifndef SQLITE_OMIT_TRIGGER
108705
+ rc = renameResolveTrigger(&sParse);
108706
+ if( rc==SQLITE_OK ){
108707
+ renameWalkTrigger(&sWalker, sParse.pNewTrigger);
108708
+ }
108709
+#endif /* SQLITE_OMIT_TRIGGER */
108710
+ }
108711
+
108712
+ if( rc==SQLITE_OK ){
108713
+ rc = renameEditSql(context, &sCtx, zInput, 0, 0);
108714
+ }
108715
+ renameTokenFree(db, sCtx.pList);
108716
+ }
108717
+ if( rc!=SQLITE_OK ){
108718
+ sqlite3_result_error_code(context, rc);
108719
+ }
108720
+ renameParseCleanup(&sParse);
108721
+ }
108722
+
108723
+#ifndef SQLITE_OMIT_AUTHORIZATION
108724
+ db->xAuth = xAuth;
108725
+#endif
108726
+
108727
+ sqlite3BtreeLeaveAll(db);
108728
+}
108471108729
108472108730
/*
108473108731
** An SQL user function that checks that there are no parse or symbol
108474108732
** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
108475108733
** After an ALTER TABLE .. RENAME operation is performed and the schema
@@ -108480,11 +108738,11 @@
108480108738
** 1: SQL statement.
108481108739
** 2: Object type ("view", "table", "trigger" or "index").
108482108740
** 3: Object name.
108483108741
** 4: True if object is from temp schema.
108484108742
** 5: "when" part of error message.
108485
-** 6: Name of column being dropped, or NULL.
108743
+** 6: True to disable the DQS quirk when parsing SQL.
108486108744
**
108487108745
** Unless it finds an error, this function normally returns NULL. However, it
108488108746
** returns integer value 1 if:
108489108747
**
108490108748
** * the SQL argument creates a trigger, and
@@ -108499,22 +108757,26 @@
108499108757
char const *zDb = (const char*)sqlite3_value_text(argv[0]);
108500108758
char const *zInput = (const char*)sqlite3_value_text(argv[1]);
108501108759
int bTemp = sqlite3_value_int(argv[4]);
108502108760
int isLegacy = (db->flags & SQLITE_LegacyAlter);
108503108761
char const *zWhen = (const char*)sqlite3_value_text(argv[5]);
108504
- char const *zDropColumn = (const char*)sqlite3_value_text(argv[6]);
108762
+ int bNoDQS = sqlite3_value_int(argv[6]);
108505108763
108506108764
#ifndef SQLITE_OMIT_AUTHORIZATION
108507108765
sqlite3_xauth xAuth = db->xAuth;
108508108766
db->xAuth = 0;
108509108767
#endif
108510108768
108511108769
UNUSED_PARAMETER(NotUsed);
108770
+
108512108771
if( zDb && zInput ){
108513108772
int rc;
108514108773
Parse sParse;
108515
- rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, zDropColumn);
108774
+ int flags = db->flags;
108775
+ if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL);
108776
+ rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
108777
+ db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL));
108516108778
if( rc==SQLITE_OK ){
108517108779
if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
108518108780
NameContext sNC;
108519108781
memset(&sNC, 0, sizeof(sNC));
108520108782
sNC.pParse = &sParse;
@@ -108578,11 +108840,11 @@
108578108840
sqlite3_xauth xAuth = db->xAuth;
108579108841
db->xAuth = 0;
108580108842
#endif
108581108843
108582108844
UNUSED_PARAMETER(NotUsed);
108583
- rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1, 0);
108845
+ rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1);
108584108846
if( rc!=SQLITE_OK ) goto drop_column_done;
108585108847
pTab = sParse.pNewTable;
108586108848
if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
108587108849
/* This can happen if the sqlite_schema table is corrupt */
108588108850
rc = SQLITE_CORRUPT_BKPT;
@@ -108672,20 +108934,21 @@
108672108934
/* Edit the sqlite_schema table */
108673108935
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108674108936
assert( iDb>=0 );
108675108937
zDb = db->aDb[iDb].zDbSName;
108676108938
renameTestSchema(pParse, zDb, iDb==1, "", 0);
108939
+ renameFixQuotes(pParse, zDb, iDb==1);
108677108940
sqlite3NestedParse(pParse,
108678108941
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108679108942
"sql = sqlite_drop_column(%d, sql, %d) "
108680108943
"WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
108681108944
, zDb, iDb, iCol, pTab->zName
108682108945
);
108683108946
108684108947
/* Drop and reload the database schema. */
108685108948
renameReloadSchema(pParse, iDb, INITFLAG_AlterDrop);
108686
- renameTestSchema(pParse, zDb, iDb==1, "after drop column", zCol);
108949
+ renameTestSchema(pParse, zDb, iDb==1, "after drop column", 1);
108687108950
108688108951
/* Edit rows of table on disk */
108689108952
if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
108690108953
int i;
108691108954
int addr;
@@ -108697,31 +108960,37 @@
108697108960
Vdbe *v = sqlite3GetVdbe(pParse);
108698108961
iCur = pParse->nTab++;
108699108962
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
108700108963
addr = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
108701108964
reg = ++pParse->nMem;
108702
- pParse->nMem += pTab->nCol;
108703108965
if( HasRowid(pTab) ){
108704108966
sqlite3VdbeAddOp2(v, OP_Rowid, iCur, reg);
108967
+ pParse->nMem += pTab->nCol;
108705108968
}else{
108706108969
pPk = sqlite3PrimaryKeyIndex(pTab);
108970
+ pParse->nMem += pPk->nColumn;
108971
+ for(i=0; i<pPk->nKeyCol; i++){
108972
+ sqlite3VdbeAddOp3(v, OP_Column, iCur, i, reg+i+1);
108973
+ }
108974
+ nField = pPk->nKeyCol;
108707108975
}
108976
+ regRec = ++pParse->nMem;
108708108977
for(i=0; i<pTab->nCol; i++){
108709108978
if( i!=iCol && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
108710108979
int regOut;
108711108980
if( pPk ){
108712108981
int iPos = sqlite3TableColumnToIndex(pPk, i);
108713108982
int iColPos = sqlite3TableColumnToIndex(pPk, iCol);
108983
+ if( iPos<pPk->nKeyCol ) continue;
108714108984
regOut = reg+1+iPos-(iPos>iColPos);
108715108985
}else{
108716108986
regOut = reg+1+nField;
108717108987
}
108718108988
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
108719108989
nField++;
108720108990
}
108721108991
}
108722
- regRec = reg + pTab->nCol;
108723108992
sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
108724108993
if( pPk ){
108725108994
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
108726108995
}else{
108727108996
sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg);
@@ -108743,10 +109012,11 @@
108743109012
static FuncDef aAlterTableFuncs[] = {
108744109013
INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc),
108745109014
INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc),
108746109015
INTERNAL_FUNCTION(sqlite_rename_test, 7, renameTableTest),
108747109016
INTERNAL_FUNCTION(sqlite_drop_column, 3, dropColumnFunc),
109017
+ INTERNAL_FUNCTION(sqlite_rename_quotefix,2, renameQuotefixFunc),
108748109018
};
108749109019
sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs));
108750109020
}
108751109021
#endif /* SQLITE_ALTER_TABLE */
108752109022
@@ -112737,21 +113007,10 @@
112737113007
pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
112738113008
#endif
112739113009
assert( pParse->pNewTable==0 );
112740113010
pParse->pNewTable = pTable;
112741113011
112742
- /* If this is the magic sqlite_sequence table used by autoincrement,
112743
- ** then record a pointer to this table in the main database structure
112744
- ** so that INSERT can find the table easily.
112745
- */
112746
-#ifndef SQLITE_OMIT_AUTOINCREMENT
112747
- if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
112748
- assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
112749
- pTable->pSchema->pSeqTab = pTable;
112750
- }
112751
-#endif
112752
-
112753113012
/* Begin generating the code that will insert the table record into
112754113013
** the schema table. Note in particular that we must go ahead
112755113014
** and allocate the record number for the table entry now. Before any
112756113015
** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
112757113016
** indices to be created and the table record must come before the
@@ -114192,11 +114451,11 @@
114192114451
114193114452
#ifndef SQLITE_OMIT_AUTOINCREMENT
114194114453
/* Check to see if we need to create an sqlite_sequence table for
114195114454
** keeping track of autoincrement keys.
114196114455
*/
114197
- if( (p->tabFlags & TF_Autoincrement)!=0 ){
114456
+ if( (p->tabFlags & TF_Autoincrement)!=0 && !IN_SPECIAL_PARSE ){
114198114457
Db *pDb = &db->aDb[iDb];
114199114458
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114200114459
if( pDb->pSchema->pSeqTab==0 ){
114201114460
sqlite3NestedParse(pParse,
114202114461
"CREATE TABLE %Q.sqlite_sequence(name,seq)",
@@ -114223,10 +114482,21 @@
114223114482
sqlite3OomFault(db);
114224114483
return;
114225114484
}
114226114485
pParse->pNewTable = 0;
114227114486
db->mDbFlags |= DBFLAG_SchemaChange;
114487
+
114488
+ /* If this is the magic sqlite_sequence table used by autoincrement,
114489
+ ** then record a pointer to this table in the main database structure
114490
+ ** so that INSERT can find the table easily. */
114491
+ assert( !pParse->nested );
114492
+#ifndef SQLITE_OMIT_AUTOINCREMENT
114493
+ if( strcmp(p->zName, "sqlite_sequence")==0 ){
114494
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114495
+ p->pSchema->pSeqTab = p;
114496
+ }
114497
+#endif
114228114498
}
114229114499
114230114500
#ifndef SQLITE_OMIT_ALTERTABLE
114231114501
if( !pSelect && !p->pSelect ){
114232114502
assert( pCons && pEnd );
@@ -114266,10 +114536,20 @@
114266114536
goto create_view_fail;
114267114537
}
114268114538
sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
114269114539
p = pParse->pNewTable;
114270114540
if( p==0 || pParse->nErr ) goto create_view_fail;
114541
+
114542
+ /* Legacy versions of SQLite allowed the use of the magic "rowid" column
114543
+ ** on a view, even though views do not have rowids. The following flag
114544
+ ** setting fixes this problem. But the fix can be disabled by compiling
114545
+ ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
114546
+ ** depend upon the old buggy behavior. */
114547
+#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
114548
+ p->tabFlags |= TF_NoVisibleRowid;
114549
+#endif
114550
+
114271114551
sqlite3TwoPartName(pParse, pName1, pName2, &pName);
114272114552
iDb = sqlite3SchemaToIndex(db, p->pSchema);
114273114553
sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
114274114554
if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
114275114555
@@ -115827,11 +116107,11 @@
115827116107
goto exit_drop_index;
115828116108
}
115829116109
pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
115830116110
if( pIndex==0 ){
115831116111
if( !ifExists ){
115832
- sqlite3ErrorMsg(pParse, "no such index: %S", pName, 0);
116112
+ sqlite3ErrorMsg(pParse, "no such index: %S", pName->a);
115833116113
}else{
115834116114
sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
115835116115
}
115836116116
pParse->checkSchema = 1;
115837116117
goto exit_drop_index;
@@ -122970,11 +123250,11 @@
122970123250
if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
122971123251
ipkColumn = i;
122972123252
bIdListInOrder = 0;
122973123253
}else{
122974123254
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
122975
- pTabList, 0, pColumn->a[i].zName);
123255
+ pTabList->a, pColumn->a[i].zName);
122976123256
pParse->checkSchema = 1;
122977123257
goto insert_cleanup;
122978123258
}
122979123259
}
122980123260
}
@@ -123098,11 +123378,11 @@
123098123378
}
123099123379
}
123100123380
if( nColumn!=(pTab->nCol-nHidden) ){
123101123381
sqlite3ErrorMsg(pParse,
123102123382
"table %S has %d columns but %d values were supplied",
123103
- pTabList, 0, pTab->nCol-nHidden, nColumn);
123383
+ pTabList->a, pTab->nCol-nHidden, nColumn);
123104123384
goto insert_cleanup;
123105123385
}
123106123386
}
123107123387
if( pColumn!=0 && nColumn!=pColumn->nId ){
123108123388
sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
@@ -123401,11 +123681,11 @@
123401123681
sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
123402123682
sqlite3MayAbort(pParse);
123403123683
}else
123404123684
#endif
123405123685
{
123406
- int isReplace; /* Set to true if constraints may cause a replace */
123686
+ int isReplace = 0;/* Set to true if constraints may cause a replace */
123407123687
int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
123408123688
sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
123409123689
regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
123410123690
);
123411123691
sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
@@ -123421,10 +123701,17 @@
123421123701
bUseSeek = (isReplace==0 || !sqlite3VdbeHasSubProgram(v));
123422123702
sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
123423123703
regIns, aRegIdx, 0, appendFlag, bUseSeek
123424123704
);
123425123705
}
123706
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
123707
+ }else if( pParse->bReturning ){
123708
+ /* If there is a RETURNING clause, populate the rowid register with
123709
+ ** constant value -1, in case one or more of the returned expressions
123710
+ ** refer to the "rowid" of the view. */
123711
+ sqlite3VdbeAddOp2(v, OP_Integer, -1, regRowid);
123712
+#endif
123426123713
}
123427123714
123428123715
/* Update the count of rows that are inserted
123429123716
*/
123430123717
if( regRowCount ){
@@ -130625,10 +130912,11 @@
130625130912
** will be closed immediately after reading the meta-value. */
130626130913
if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_NONE ){
130627130914
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
130628130915
if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
130629130916
sqlite3OomFault(db);
130917
+ pParse->rc = SQLITE_NOMEM;
130630130918
}
130631130919
if( rc!=SQLITE_OK ) return;
130632130920
openedTransaction = 1;
130633130921
}
130634130922
@@ -130860,10 +131148,11 @@
130860131148
if( db->init.busy==0 ){
130861131149
sqlite3VdbeSetSql(sParse.pVdbe, zSql, (int)(sParse.zTail-zSql), prepFlags);
130862131150
}
130863131151
if( db->mallocFailed ){
130864131152
sParse.rc = SQLITE_NOMEM_BKPT;
131153
+ sParse.checkSchema = 0;
130865131154
}
130866131155
if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
130867131156
if( sParse.checkSchema ){
130868131157
schemaIsValid(&sParse);
130869131158
}
@@ -131884,35 +132173,159 @@
131884132173
VdbeComment((v, "OFFSET"));
131885132174
}
131886132175
}
131887132176
131888132177
/*
131889
-** Add code that will check to make sure the N registers starting at iMem
131890
-** form a distinct entry. iTab is a sorting index that holds previously
131891
-** seen combinations of the N values. A new entry is made in iTab
131892
-** if the current N values are new.
132178
+** Add code that will check to make sure the array of registers starting at
132179
+** iMem form a distinct entry. This is used by both "SELECT DISTINCT ..." and
132180
+** distinct aggregates ("SELECT count(DISTINCT <expr>) ..."). Three strategies
132181
+** are available. Which is used depends on the value of parameter eTnctType,
132182
+** as follows:
131893132183
**
131894
-** A jump to addrRepeat is made and the N+1 values are popped from the
131895
-** stack if the top N elements are not distinct.
132184
+** WHERE_DISTINCT_UNORDERED/WHERE_DISTINCT_NOOP:
132185
+** Build an ephemeral table that contains all entries seen before and
132186
+** skip entries which have been seen before.
132187
+**
132188
+** Parameter iTab is the cursor number of an ephemeral table that must
132189
+** be opened before the VM code generated by this routine is executed.
132190
+** The ephemeral cursor table is queried for a record identical to the
132191
+** record formed by the current array of registers. If one is found,
132192
+** jump to VM address addrRepeat. Otherwise, insert a new record into
132193
+** the ephemeral cursor and proceed.
132194
+**
132195
+** The returned value in this case is a copy of parameter iTab.
132196
+**
132197
+** WHERE_DISTINCT_ORDERED:
132198
+** In this case rows are being delivered sorted order. The ephermal
132199
+** table is not required. Instead, the current set of values
132200
+** is compared against previous row. If they match, the new row
132201
+** is not distinct and control jumps to VM address addrRepeat. Otherwise,
132202
+** the VM program proceeds with processing the new row.
132203
+**
132204
+** The returned value in this case is the register number of the first
132205
+** in an array of registers used to store the previous result row so that
132206
+** it can be compared to the next. The caller must ensure that this
132207
+** register is initialized to NULL. (The fixDistinctOpenEph() routine
132208
+** will take care of this initialization.)
132209
+**
132210
+** WHERE_DISTINCT_UNIQUE:
132211
+** In this case it has already been determined that the rows are distinct.
132212
+** No special action is required. The return value is zero.
132213
+**
132214
+** Parameter pEList is the list of expressions used to generated the
132215
+** contents of each row. It is used by this routine to determine (a)
132216
+** how many elements there are in the array of registers and (b) the
132217
+** collation sequences that should be used for the comparisons if
132218
+** eTnctType is WHERE_DISTINCT_ORDERED.
131896132219
*/
131897
-static void codeDistinct(
132220
+static int codeDistinct(
131898132221
Parse *pParse, /* Parsing and code generating context */
132222
+ int eTnctType, /* WHERE_DISTINCT_* value */
131899132223
int iTab, /* A sorting index used to test for distinctness */
131900132224
int addrRepeat, /* Jump to here if not distinct */
131901
- int N, /* Number of elements */
131902
- int iMem /* First element */
132225
+ ExprList *pEList, /* Expression for each element */
132226
+ int regElem /* First element */
131903132227
){
131904
- Vdbe *v;
131905
- int r1;
131906
-
131907
- v = pParse->pVdbe;
131908
- r1 = sqlite3GetTempReg(pParse);
131909
- sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
131910
- sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
131911
- sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N);
131912
- sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
131913
- sqlite3ReleaseTempReg(pParse, r1);
132228
+ int iRet = 0;
132229
+ int nResultCol = pEList->nExpr;
132230
+ Vdbe *v = pParse->pVdbe;
132231
+
132232
+ switch( eTnctType ){
132233
+ case WHERE_DISTINCT_ORDERED: {
132234
+ int i;
132235
+ int iJump; /* Jump destination */
132236
+ int regPrev; /* Previous row content */
132237
+
132238
+ /* Allocate space for the previous row */
132239
+ iRet = regPrev = pParse->nMem+1;
132240
+ pParse->nMem += nResultCol;
132241
+
132242
+ iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
132243
+ for(i=0; i<nResultCol; i++){
132244
+ CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
132245
+ if( i<nResultCol-1 ){
132246
+ sqlite3VdbeAddOp3(v, OP_Ne, regElem+i, iJump, regPrev+i);
132247
+ VdbeCoverage(v);
132248
+ }else{
132249
+ sqlite3VdbeAddOp3(v, OP_Eq, regElem+i, addrRepeat, regPrev+i);
132250
+ VdbeCoverage(v);
132251
+ }
132252
+ sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
132253
+ sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
132254
+ }
132255
+ assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );
132256
+ sqlite3VdbeAddOp3(v, OP_Copy, regElem, regPrev, nResultCol-1);
132257
+ break;
132258
+ }
132259
+
132260
+ case WHERE_DISTINCT_UNIQUE: {
132261
+ /* nothing to do */
132262
+ break;
132263
+ }
132264
+
132265
+ default: {
132266
+ int r1 = sqlite3GetTempReg(pParse);
132267
+ sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, regElem, nResultCol);
132268
+ VdbeCoverage(v);
132269
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regElem, nResultCol, r1);
132270
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, regElem, nResultCol);
132271
+ sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
132272
+ sqlite3ReleaseTempReg(pParse, r1);
132273
+ iRet = iTab;
132274
+ break;
132275
+ }
132276
+ }
132277
+
132278
+ return iRet;
132279
+}
132280
+
132281
+/*
132282
+** This routine runs after codeDistinct(). It makes necessary
132283
+** adjustments to the OP_OpenEphemeral opcode that the codeDistinct()
132284
+** routine made use of. This processing must be done separately since
132285
+** sometimes codeDistinct is called before the OP_OpenEphemeral is actually
132286
+** laid down.
132287
+**
132288
+** WHERE_DISTINCT_NOOP:
132289
+** WHERE_DISTINCT_UNORDERED:
132290
+**
132291
+** No adjustments necessary. This function is a no-op.
132292
+**
132293
+** WHERE_DISTINCT_UNIQUE:
132294
+**
132295
+** The ephemeral table is not needed. So change the
132296
+** OP_OpenEphemeral opcode into an OP_Noop.
132297
+**
132298
+** WHERE_DISTINCT_ORDERED:
132299
+**
132300
+** The ephemeral table is not needed. But we do need register
132301
+** iVal to be initialized to NULL. So change the OP_OpenEphemeral
132302
+** into an OP_Null on the iVal register.
132303
+*/
132304
+static void fixDistinctOpenEph(
132305
+ Parse *pParse, /* Parsing and code generating context */
132306
+ int eTnctType, /* WHERE_DISTINCT_* value */
132307
+ int iVal, /* Value returned by codeDistinct() */
132308
+ int iOpenEphAddr /* Address of OP_OpenEphemeral instruction for iTab */
132309
+){
132310
+ if( eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED ){
132311
+ Vdbe *v = pParse->pVdbe;
132312
+ sqlite3VdbeChangeToNoop(v, iOpenEphAddr);
132313
+ if( sqlite3VdbeGetOp(v, iOpenEphAddr+1)->opcode==OP_Explain ){
132314
+ sqlite3VdbeChangeToNoop(v, iOpenEphAddr+1);
132315
+ }
132316
+ if( eTnctType==WHERE_DISTINCT_ORDERED ){
132317
+ /* Change the OP_OpenEphemeral to an OP_Null that sets the MEM_Cleared
132318
+ ** bit on the first register of the previous value. This will cause the
132319
+ ** OP_Ne added in codeDistinct() to always fail on the first iteration of
132320
+ ** the loop even if the first row is all NULLs. */
132321
+ VdbeOp *pOp = sqlite3VdbeGetOp(v, iOpenEphAddr);
132322
+ pOp->opcode = OP_Null;
132323
+ pOp->p1 = 1;
132324
+ pOp->p2 = iVal;
132325
+ }
132326
+ }
131914132327
}
131915132328
131916132329
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
131917132330
/*
131918132331
** This function is called as part of inner-loop generation for a SELECT
@@ -132156,63 +132569,15 @@
132156132569
/* If the DISTINCT keyword was present on the SELECT statement
132157132570
** and this row has been seen before, then do not make this row
132158132571
** part of the result.
132159132572
*/
132160132573
if( hasDistinct ){
132161
- switch( pDistinct->eTnctType ){
132162
- case WHERE_DISTINCT_ORDERED: {
132163
- VdbeOp *pOp; /* No longer required OpenEphemeral instr. */
132164
- int iJump; /* Jump destination */
132165
- int regPrev; /* Previous row content */
132166
-
132167
- /* Allocate space for the previous row */
132168
- regPrev = pParse->nMem+1;
132169
- pParse->nMem += nResultCol;
132170
-
132171
- /* Change the OP_OpenEphemeral coded earlier to an OP_Null
132172
- ** sets the MEM_Cleared bit on the first register of the
132173
- ** previous value. This will cause the OP_Ne below to always
132174
- ** fail on the first iteration of the loop even if the first
132175
- ** row is all NULLs.
132176
- */
132177
- sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
132178
- pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);
132179
- pOp->opcode = OP_Null;
132180
- pOp->p1 = 1;
132181
- pOp->p2 = regPrev;
132182
- pOp = 0; /* Ensure pOp is not used after sqlite3VdbeAddOp() */
132183
-
132184
- iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
132185
- for(i=0; i<nResultCol; i++){
132186
- CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr);
132187
- if( i<nResultCol-1 ){
132188
- sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
132189
- VdbeCoverage(v);
132190
- }else{
132191
- sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
132192
- VdbeCoverage(v);
132193
- }
132194
- sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
132195
- sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
132196
- }
132197
- assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );
132198
- sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
132199
- break;
132200
- }
132201
-
132202
- case WHERE_DISTINCT_UNIQUE: {
132203
- sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
132204
- break;
132205
- }
132206
-
132207
- default: {
132208
- assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED );
132209
- codeDistinct(pParse, pDistinct->tabTnct, iContinue, nResultCol,
132210
- regResult);
132211
- break;
132212
- }
132213
- }
132574
+ int eType = pDistinct->eTnctType;
132575
+ int iTab = pDistinct->tabTnct;
132576
+ assert( nResultCol==p->pEList->nExpr );
132577
+ iTab = codeDistinct(pParse, eType, iTab, iContinue, p->pEList, regResult);
132578
+ fixDistinctOpenEph(pParse, eType, iTab, pDistinct->addrTnct);
132214132579
if( pSort==0 ){
132215132580
codeOffset(v, p->iOffset, iContinue);
132216132581
}
132217132582
}
132218132583
@@ -132874,11 +133239,17 @@
132874133239
if( pS ){
132875133240
/* The "table" is actually a sub-select or a view in the FROM clause
132876133241
** of the SELECT statement. Return the declaration type and origin
132877133242
** data for the result-set column of the sub-select.
132878133243
*/
132879
- if( iCol>=0 && iCol<pS->pEList->nExpr ){
133244
+ if( iCol<pS->pEList->nExpr
133245
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
133246
+ && iCol>=0
133247
+#else
133248
+ && ALWAYS(iCol>=0)
133249
+#endif
133250
+ ){
132880133251
/* If iCol is less than zero, then the expression requests the
132881133252
** rowid of the sub-select or view. This expression is legal (see
132882133253
** test case misc2.2.2) - it always evaluates to NULL.
132883133254
*/
132884133255
NameContext sNC;
@@ -133804,11 +134175,11 @@
133804134175
/* Generate code for the left and right SELECT statements.
133805134176
*/
133806134177
switch( p->op ){
133807134178
case TK_ALL: {
133808134179
int addr = 0;
133809
- int nLimit;
134180
+ int nLimit = 0; /* Initialize to suppress harmless compiler warning */
133810134181
assert( !pPrior->pLimit );
133811134182
pPrior->iLimit = p->iLimit;
133812134183
pPrior->iOffset = p->iOffset;
133813134184
pPrior->pLimit = p->pLimit;
133814134185
rc = sqlite3Select(pParse, pPrior, &dest);
@@ -134660,13 +135031,16 @@
134660135031
}
134661135032
if( pExpr->op==TK_COLUMN
134662135033
&& pExpr->iTable==pSubst->iTable
134663135034
&& !ExprHasProperty(pExpr, EP_FixedCol)
134664135035
){
135036
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
134665135037
if( pExpr->iColumn<0 ){
134666135038
pExpr->op = TK_NULL;
134667
- }else{
135039
+ }else
135040
+#endif
135041
+ {
134668135042
Expr *pNew;
134669135043
Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
134670135044
Expr ifNullRow;
134671135045
assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
134672135046
assert( pExpr->pRight==0 );
@@ -136301,11 +136675,17 @@
136301136675
}
136302136676
while( pSel->pPrior ){ pSel = pSel->pPrior; }
136303136677
sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
136304136678
pTab->iPKey = -1;
136305136679
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
136306
- pTab->tabFlags |= TF_Ephemeral;
136680
+#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
136681
+ /* The usual case - do not allow ROWID on a subquery */
136682
+ pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
136683
+#else
136684
+ pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */
136685
+#endif
136686
+
136307136687
136308136688
return pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
136309136689
}
136310136690
136311136691
/*
@@ -136788,12 +137168,14 @@
136788137168
sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
136789137169
"argument");
136790137170
pFunc->iDistinct = -1;
136791137171
}else{
136792137172
KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pE->x.pList,0,0);
136793
- sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0,
136794
- (char*)pKeyInfo, P4_KEYINFO);
137173
+ pFunc->iDistAddr = sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
137174
+ pFunc->iDistinct, 0, 0, (char*)pKeyInfo, P4_KEYINFO);
137175
+ ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(DISTINCT)",
137176
+ pFunc->pFunc->zName));
136795137177
}
136796137178
}
136797137179
}
136798137180
}
136799137181
@@ -136821,11 +137203,16 @@
136821137203
** If regAcc is non-zero and there are no min() or max() aggregates
136822137204
** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
136823137205
** registers if register regAcc contains 0. The caller will take care
136824137206
** of setting and clearing regAcc.
136825137207
*/
136826
-static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
137208
+static void updateAccumulator(
137209
+ Parse *pParse,
137210
+ int regAcc,
137211
+ AggInfo *pAggInfo,
137212
+ int eDistinctType
137213
+){
136827137214
Vdbe *v = pParse->pVdbe;
136828137215
int i;
136829137216
int regHit = 0;
136830137217
int addrHitTest = 0;
136831137218
struct AggInfo_func *pF;
@@ -136867,17 +137254,16 @@
136867137254
sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
136868137255
}else{
136869137256
nArg = 0;
136870137257
regAgg = 0;
136871137258
}
136872
- if( pF->iDistinct>=0 ){
137259
+ if( pF->iDistinct>=0 && pList ){
136873137260
if( addrNext==0 ){
136874137261
addrNext = sqlite3VdbeMakeLabel(pParse);
136875137262
}
136876
- testcase( nArg==0 ); /* Error condition */
136877
- testcase( nArg>1 ); /* Also an error */
136878
- codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
137263
+ pF->iDistinct = codeDistinct(pParse, eDistinctType,
137264
+ pF->iDistinct, addrNext, pList, regAgg);
136879137265
}
136880137266
if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
136881137267
CollSeq *pColl = 0;
136882137268
struct ExprList_item *pItem;
136883137269
int j;
@@ -136925,11 +137311,11 @@
136925137311
Table *pTab, /* Table being queried */
136926137312
Index *pIdx /* Index used to optimize scan, or NULL */
136927137313
){
136928137314
if( pParse->explain==2 ){
136929137315
int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
136930
- sqlite3VdbeExplain(pParse, 0, "SCAN TABLE %s%s%s",
137316
+ sqlite3VdbeExplain(pParse, 0, "SCAN %s%s%s",
136931137317
pTab->zName,
136932137318
bCover ? " USING COVERING INDEX " : "",
136933137319
bCover ? pIdx->zName : ""
136934137320
);
136935137321
}
@@ -137498,14 +137884,14 @@
137498137884
*/
137499137885
int addrTop = sqlite3VdbeCurrentAddr(v)+1;
137500137886
137501137887
pItem->regReturn = ++pParse->nMem;
137502137888
sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
137503
- VdbeComment((v, "%s", pItem->pTab->zName));
137889
+ VdbeComment((v, "%!S", pItem));
137504137890
pItem->addrFillSub = addrTop;
137505137891
sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
137506
- ExplainQueryPlan((pParse, 1, "CO-ROUTINE %u", pSub->selId));
137892
+ ExplainQueryPlan((pParse, 1, "CO-ROUTINE %!S", pItem));
137507137893
sqlite3Select(pParse, pSub, &dest);
137508137894
pItem->pTab->nRowLogEst = pSub->nSelectRow;
137509137895
pItem->fg.viaCoroutine = 1;
137510137896
pItem->regResult = dest.iSdst;
137511137897
sqlite3VdbeEndCoroutine(v, pItem->regReturn);
@@ -137545,21 +137931,21 @@
137545137931
if( pItem->fg.isCorrelated==0 ){
137546137932
/* If the subquery is not correlated and if we are not inside of
137547137933
** a trigger, then we only need to compute the value of the subquery
137548137934
** once. */
137549137935
onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
137550
- VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
137936
+ VdbeComment((v, "materialize %!S", pItem));
137551137937
}else{
137552
- VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
137938
+ VdbeNoopComment((v, "materialize %!S", pItem));
137553137939
}
137554137940
sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
137555
- ExplainQueryPlan((pParse, 1, "MATERIALIZE %u", pSub->selId));
137941
+ ExplainQueryPlan((pParse, 1, "MATERIALIZE %!S", pItem));
137556137942
sqlite3Select(pParse, pSub, &dest);
137557137943
pItem->pTab->nRowLogEst = pSub->nSelectRow;
137558137944
if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
137559137945
retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
137560
- VdbeComment((v, "end %s", pItem->pTab->zName));
137946
+ VdbeComment((v, "end %!S", pItem));
137561137947
sqlite3VdbeChangeP1(v, topAddr, retAddr);
137562137948
sqlite3ClearTempRegCache(pParse);
137563137949
if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
137564137950
CteUse *pCteUse = pItem->u2.pCteUse;
137565137951
pCteUse->addrM9e = pItem->addrFillSub;
@@ -137905,10 +138291,24 @@
137905138291
int addrSetAbort; /* Set the abort flag and return */
137906138292
int addrTopOfLoop; /* Top of the input loop */
137907138293
int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */
137908138294
int addrReset; /* Subroutine for resetting the accumulator */
137909138295
int regReset; /* Return address register for reset subroutine */
138296
+ ExprList *pDistinct = 0;
138297
+ u16 distFlag = 0;
138298
+ int eDist = WHERE_DISTINCT_NOOP;
138299
+
138300
+ if( pAggInfo->nFunc==1
138301
+ && pAggInfo->aFunc[0].iDistinct>=0
138302
+ && pAggInfo->aFunc[0].pFExpr->x.pList
138303
+ ){
138304
+ Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
138305
+ pExpr = sqlite3ExprDup(db, pExpr, 0);
138306
+ pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
138307
+ pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr);
138308
+ distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
138309
+ }
137910138310
137911138311
/* If there is a GROUP BY clause we might need a sorting index to
137912138312
** implement it. Allocate that sorting index now. If it turns out
137913138313
** that we do not need it after all, the OP_SorterOpen instruction
137914138314
** will be converted into a Noop.
@@ -137941,14 +138341,16 @@
137941138341
** it might be a single loop that uses an index to extract information
137942138342
** in the right order to begin with.
137943138343
*/
137944138344
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
137945138345
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
137946
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0,
137947
- WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0), 0
138346
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
138347
+ WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
137948138348
);
138349
+ sqlite3ExprListDelete(db, pDistinct);
137949138350
if( pWInfo==0 ) goto select_end;
138351
+ eDist = sqlite3WhereIsDistinct(pWInfo);
137950138352
SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
137951138353
if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
137952138354
/* The optimizer is able to deliver rows in group by order so
137953138355
** we do not have to sort. The OP_OpenEphemeral table will be
137954138356
** cancelled later because we still need to use the pKeyInfo
@@ -138062,11 +138464,11 @@
138062138464
138063138465
/* Update the aggregate accumulators based on the content of
138064138466
** the current row
138065138467
*/
138066138468
sqlite3VdbeJumpHere(v, addr1);
138067
- updateAccumulator(pParse, iUseFlag, pAggInfo);
138469
+ updateAccumulator(pParse, iUseFlag, pAggInfo, eDist);
138068138470
sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
138069138471
VdbeComment((v, "indicate data in accumulator"));
138070138472
138071138473
/* End of the loop
138072138474
*/
@@ -138119,10 +138521,14 @@
138119138521
resetAccumulator(pParse, pAggInfo);
138120138522
sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
138121138523
VdbeComment((v, "indicate accumulator empty"));
138122138524
sqlite3VdbeAddOp1(v, OP_Return, regReset);
138123138525
138526
+ if( eDist!=WHERE_DISTINCT_NOOP ){
138527
+ struct AggInfo_func *pF = &pAggInfo->aFunc[0];
138528
+ fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
138529
+ }
138124138530
} /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
138125138531
else {
138126138532
Table *pTab;
138127138533
if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
138128138534
/* If isSimpleCount() returns a pointer to a Table structure, then
@@ -138182,10 +138588,13 @@
138182138588
sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
138183138589
sqlite3VdbeAddOp1(v, OP_Close, iCsr);
138184138590
explainSimpleCount(pParse, pTab, pBest);
138185138591
}else{
138186138592
int regAcc = 0; /* "populate accumulators" flag */
138593
+ ExprList *pDistinct = 0;
138594
+ u16 distFlag = 0;
138595
+ int eDist;
138187138596
138188138597
/* If there are accumulator registers but no min() or max() functions
138189138598
** without FILTER clauses, allocate register regAcc. Register regAcc
138190138599
** will contain 0 the first time the inner loop runs, and 1 thereafter.
138191138600
** The code generated by updateAccumulator() uses this to ensure
@@ -138205,10 +138614,13 @@
138205138614
}
138206138615
if( i==pAggInfo->nFunc ){
138207138616
regAcc = ++pParse->nMem;
138208138617
sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
138209138618
}
138619
+ }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
138620
+ pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
138621
+ distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
138210138622
}
138211138623
138212138624
/* This case runs if the aggregate has no GROUP BY clause. The
138213138625
** processing is much simpler since there is only a single row
138214138626
** of output.
@@ -138224,16 +138636,22 @@
138224138636
assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
138225138637
assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
138226138638
138227138639
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
138228138640
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
138229
- 0, minMaxFlag, 0);
138641
+ pDistinct, minMaxFlag|distFlag, 0);
138230138642
if( pWInfo==0 ){
138231138643
goto select_end;
138232138644
}
138233138645
SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
138234
- updateAccumulator(pParse, regAcc, pAggInfo);
138646
+ eDist = sqlite3WhereIsDistinct(pWInfo);
138647
+ updateAccumulator(pParse, regAcc, pAggInfo, eDist);
138648
+ if( eDist!=WHERE_DISTINCT_NOOP ){
138649
+ struct AggInfo_func *pF = &pAggInfo->aFunc[0];
138650
+ fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
138651
+ }
138652
+
138235138653
if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
138236138654
if( minMaxFlag ){
138237138655
sqlite3WhereMinMaxOptEarlyOut(v, pWInfo);
138238138656
}
138239138657
SELECTTRACE(1,pParse,p,("WhereEnd\n"));
@@ -138576,11 +138994,15 @@
138576138994
if( pTrig->pTabSchema==pTab->pSchema
138577138995
&& 0==sqlite3StrICmp(pTrig->table, pTab->zName)
138578138996
){
138579138997
pTrig->pNext = pList;
138580138998
pList = pTrig;
138581
- }else if( pTrig->op==TK_RETURNING ){
138999
+ }else if( pTrig->op==TK_RETURNING
139000
+#ifndef SQLITE_OMIT_VIRTUALTABLE
139001
+ && pParse->db->pVtabCtx==0
139002
+#endif
139003
+ ){
138582139004
assert( pParse->bReturning );
138583139005
assert( &(pParse->u1.pReturning->retTrig) == pTrig );
138584139006
pTrig->table = pTab->zName;
138585139007
pTrig->pTabSchema = pTab->pSchema;
138586139008
pTrig->pNext = pList;
@@ -138716,16 +139138,16 @@
138716139138
/* INSTEAD of triggers are only for views and views only support INSTEAD
138717139139
** of triggers.
138718139140
*/
138719139141
if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
138720139142
sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
138721
- (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
139143
+ (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName->a);
138722139144
goto trigger_orphan_error;
138723139145
}
138724139146
if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
138725139147
sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
138726
- " trigger on table: %S", pTableName, 0);
139148
+ " trigger on table: %S", pTableName->a);
138727139149
goto trigger_orphan_error;
138728139150
}
138729139151
138730139152
#ifndef SQLITE_OMIT_AUTHORIZATION
138731139153
if( !IN_RENAME_OBJECT ){
@@ -139118,11 +139540,11 @@
139118139540
pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
139119139541
if( pTrigger ) break;
139120139542
}
139121139543
if( !pTrigger ){
139122139544
if( !noErr ){
139123
- sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
139545
+ sqlite3ErrorMsg(pParse, "no such trigger: %S", pName->a);
139124139546
}else{
139125139547
sqlite3CodeVerifyNamedSchema(pParse, zDb);
139126139548
}
139127139549
pParse->checkSchema = 1;
139128139550
goto drop_trigger_cleanup;
@@ -139650,12 +140072,12 @@
139650140072
/* If one was specified, code the WHEN clause. If it evaluates to false
139651140073
** (or NULL) the sub-vdbe is immediately halted by jumping to the
139652140074
** OP_Halt inserted at the end of the program. */
139653140075
if( pTrigger->pWhen ){
139654140076
pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
139655
- if( SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
139656
- && db->mallocFailed==0
140077
+ if( db->mallocFailed==0
140078
+ && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
139657140079
){
139658140080
iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
139659140081
sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
139660140082
}
139661140083
sqlite3ExprDelete(db, pWhen);
@@ -140709,11 +141131,16 @@
140709141131
}
140710141132
}
140711141133
140712141134
/* Top of the update loop */
140713141135
if( eOnePass!=ONEPASS_OFF ){
140714
- if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
141136
+ if( aiCurOnePass[0]!=iDataCur
141137
+ && aiCurOnePass[1]!=iDataCur
141138
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
141139
+ && !isView
141140
+#endif
141141
+ ){
140715141142
assert( pPk );
140716141143
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey);
140717141144
VdbeCoverage(v);
140718141145
}
140719141146
if( eOnePass!=ONEPASS_SINGLE ){
@@ -144040,20 +144467,12 @@
144040144467
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
144041144468
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
144042144469
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
144043144470
144044144471
sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
144045
- sqlite3_str_appendall(&str, isSearch ? "SEARCH" : "SCAN");
144046
- if( pItem->pSelect ){
144047
- sqlite3_str_appendf(&str, " SUBQUERY %u", pItem->pSelect->selId);
144048
- }else{
144049
- sqlite3_str_appendf(&str, " TABLE %s", pItem->zName);
144050
- }
144051
-
144052
- if( pItem->zAlias ){
144053
- sqlite3_str_appendf(&str, " AS %s", pItem->zAlias);
144054
- }
144472
+ str.printfFlags = SQLITE_PRINTF_INTERNAL;
144473
+ sqlite3_str_appendf(&str, "%s %S", isSearch ? "SEARCH" : "SCAN", pItem);
144055144474
if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
144056144475
const char *zFmt = 0;
144057144476
Index *pIdx;
144058144477
144059144478
assert( pLoop->u.btree.pIndex!=0 );
@@ -146348,10 +146767,11 @@
146348146767
testcase( pAlt->eOperator & WO_IN );
146349146768
VdbeModuleComment((v, "begin transitive constraint"));
146350146769
sEAlt = *pAlt->pExpr;
146351146770
sEAlt.pLeft = pE->pLeft;
146352146771
sqlite3ExprIfFalse(pParse, &sEAlt, addrCont, SQLITE_JUMPIFNULL);
146772
+ pAlt->wtFlags |= TERM_CODED;
146353146773
}
146354146774
146355146775
/* For a LEFT OUTER JOIN, generate code that will record the fact that
146356146776
** at least one row of the right table has matched the left table.
146357146777
*/
@@ -148784,11 +149204,11 @@
148784149204
const char *zColl = pIdx->azColl[iCol];
148785149205
148786149206
for(i=0; i<pList->nExpr; i++){
148787149207
Expr *p = sqlite3ExprSkipCollateAndLikely(pList->a[i].pExpr);
148788149208
if( ALWAYS(p!=0)
148789
- && p->op==TK_COLUMN
149209
+ && (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
148790149210
&& p->iColumn==pIdx->aiColumn[iCol]
148791149211
&& p->iTable==iBase
148792149212
){
148793149213
CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);
148794149214
if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
@@ -148849,11 +149269,12 @@
148849149269
** current SELECT is a correlated sub-query.
148850149270
*/
148851149271
for(i=0; i<pDistinct->nExpr; i++){
148852149272
Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
148853149273
if( NEVER(p==0) ) continue;
148854
- if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
149274
+ if( p->op!=TK_COLUMN && p->op!=TK_AGG_COLUMN ) continue;
149275
+ if( p->iTable==iBase && p->iColumn<0 ) return 1;
148855149276
}
148856149277
148857149278
/* Loop through all indices on the table, checking each to see if it makes
148858149279
** the DISTINCT qualifier redundant. It does so if:
148859149280
**
@@ -148867,10 +149288,11 @@
148867149288
** 3. All of those index columns for which the WHERE clause does not
148868149289
** contain a "col=X" term are subject to a NOT NULL constraint.
148869149290
*/
148870149291
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
148871149292
if( !IsUniqueIndex(pIdx) ) continue;
149293
+ if( pIdx->pPartIdxWhere ) continue;
148872149294
for(i=0; i<pIdx->nKeyCol; i++){
148873149295
if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
148874149296
if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
148875149297
if( indexColumnNotNull(pIdx, i)==0 ) break;
148876149298
}
@@ -148921,18 +149343,18 @@
148921149343
pOp->opcode = OP_Copy;
148922149344
pOp->p1 = pOp->p2 + iRegister;
148923149345
pOp->p2 = pOp->p3;
148924149346
pOp->p3 = 0;
148925149347
}else if( pOp->opcode==OP_Rowid ){
148926
- if( iAutoidxCur ){
148927
- pOp->opcode = OP_Sequence;
148928
- pOp->p1 = iAutoidxCur;
148929
- }else{
149348
+ pOp->opcode = OP_Sequence;
149349
+ pOp->p1 = iAutoidxCur;
149350
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
149351
+ if( iAutoidxCur==0 ){
148930149352
pOp->opcode = OP_Null;
148931
- pOp->p1 = 0;
148932149353
pOp->p3 = 0;
148933149354
}
149355
+#endif
148934149356
}
148935149357
}
148936149358
}
148937149359
148938149360
/*
@@ -149093,11 +149515,11 @@
149093149515
pLoop->aLTerm[nKeyCol++] = pTerm;
149094149516
idxCols |= cMask;
149095149517
}
149096149518
}
149097149519
}
149098
- assert( nKeyCol>0 );
149520
+ assert( nKeyCol>0 || pParse->db->mallocFailed );
149099149521
pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol;
149100149522
pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
149101149523
| WHERE_AUTO_INDEX;
149102149524
149103149525
/* Count the number of additional columns needed to create a
@@ -152114,11 +152536,11 @@
152114152536
*/
152115152537
for(i=0; i<nOrderBy; i++){
152116152538
if( MASKBIT(i) & obSat ) continue;
152117152539
pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
152118152540
if( NEVER(pOBExpr==0) ) continue;
152119
- if( pOBExpr->op!=TK_COLUMN ) continue;
152541
+ if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) continue;
152120152542
if( pOBExpr->iTable!=iCur ) continue;
152121152543
pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
152122152544
~ready, eqOpMask, 0);
152123152545
if( pTerm==0 ) continue;
152124152546
if( pTerm->eOperator==WO_IN ){
@@ -152243,11 +152665,11 @@
152243152665
testcase( wctrlFlags & WHERE_GROUPBY );
152244152666
testcase( wctrlFlags & WHERE_DISTINCTBY );
152245152667
if( NEVER(pOBExpr==0) ) continue;
152246152668
if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
152247152669
if( iColumn>=XN_ROWID ){
152248
- if( pOBExpr->op!=TK_COLUMN ) continue;
152670
+ if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) continue;
152249152671
if( pOBExpr->iTable!=iCur ) continue;
152250152672
if( pOBExpr->iColumn!=iColumn ) continue;
152251152673
}else{
152252152674
Expr *pIdxExpr = pIndex->aColExpr->a[j].pExpr;
152253152675
if( sqlite3ExprCompareSkip(pOBExpr, pIdxExpr, iCur) ){
@@ -153344,11 +153766,12 @@
153344153766
** LEFT JOIN t2
153345153767
** LEFT JOIN t3 ON (t1.ipk=t3.ipk)
153346153768
*/
153347153769
notReady = ~(Bitmask)0;
153348153770
if( pWInfo->nLevel>=2
153349
- && pResultSet!=0 /* guarantees condition (1) above */
153771
+ && pResultSet!=0 /* these two combine to guarantee */
153772
+ && 0==(wctrlFlags & WHERE_AGG_DISTINCT) /* condition (1) above */
153350153773
&& OptimizationEnabled(db, SQLITE_OmitNoopJoin)
153351153774
){
153352153775
int i;
153353153776
Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
153354153777
if( sWLB.pOrderBy ){
@@ -153857,11 +154280,11 @@
153857154280
assert( pOp->opcode!=OP_Rowid || pOp->p1!=pLevel->iTabCur );
153858154281
assert( pOp->opcode!=OP_IfNullRow || pOp->p1!=pLevel->iTabCur );
153859154282
#endif
153860154283
pOp = sqlite3VdbeGetOp(v, k);
153861154284
pLastOp = pOp + (last - k);
153862
- assert( pOp<pLastOp || (pParse->nErr>0 && pOp==pLastOp) );
154285
+ assert( pOp<=pLastOp );
153863154286
do{
153864154287
if( pOp->p1!=pLevel->iTabCur ){
153865154288
/* no-op */
153866154289
}else if( pOp->opcode==OP_Column
153867154290
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
@@ -154709,10 +155132,11 @@
154709155132
/* no break */ deliberate_fall_through
154710155133
154711155134
case TK_AGG_FUNCTION:
154712155135
case TK_COLUMN: {
154713155136
int iCol = -1;
155137
+ if( pParse->db->mallocFailed ) return WRC_Abort;
154714155138
if( p->pSub ){
154715155139
int i;
154716155140
for(i=0; i<p->pSub->nExpr; i++){
154717155141
if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
154718155142
iCol = i;
@@ -154818,13 +155242,18 @@
154818155242
){
154819155243
if( pAppend ){
154820155244
int i;
154821155245
int nInit = pList ? pList->nExpr : 0;
154822155246
for(i=0; i<pAppend->nExpr; i++){
154823
- Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
155247
+ sqlite3 *db = pParse->db;
155248
+ Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0);
154824155249
assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
154825
- if( bIntToNull && pDup ){
155250
+ if( db->mallocFailed ){
155251
+ sqlite3ExprDelete(db, pDup);
155252
+ break;
155253
+ }
155254
+ if( bIntToNull ){
154826155255
int iDummy;
154827155256
Expr *pSub;
154828155257
for(pSub=pDup; ExprHasProperty(pSub, EP_Skip); pSub=pSub->pLeft){
154829155258
assert( pSub );
154830155259
}
@@ -155601,19 +156030,19 @@
155601156030
VdbeCoverage(v);
155602156031
sqlite3ReleaseTempReg(pParse, regTmp);
155603156032
}
155604156033
155605156034
if( pWin->bExprArgs ){
155606
- int iStart = sqlite3VdbeCurrentAddr(v);
155607
- VdbeOp *pOp, *pEnd;
156035
+ int iOp = sqlite3VdbeCurrentAddr(v);
156036
+ int iEnd;
155608156037
155609156038
nArg = pWin->pOwner->x.pList->nExpr;
155610156039
regArg = sqlite3GetTempRange(pParse, nArg);
155611156040
sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
155612156041
155613
- pEnd = sqlite3VdbeGetOp(v, -1);
155614
- for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
156042
+ for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
156043
+ VdbeOp *pOp = sqlite3VdbeGetOp(v, iOp);
155615156044
if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
155616156045
pOp->p1 = csr;
155617156046
}
155618156047
}
155619156048
}
@@ -155968,11 +156397,11 @@
155968156397
** is OP_Ge, the generated code is equivalent to:
155969156398
**
155970156399
** if( csr1.peerVal - regVal <= csr2.peerVal ) goto lbl;
155971156400
**
155972156401
** A special type of arithmetic is used such that if csr1.peerVal is not
155973
-** a numeric type (real or integer), then the result of the addition addition
156402
+** a numeric type (real or integer), then the result of the addition
155974156403
** or subtraction is a a copy of csr1.peerVal.
155975156404
*/
155976156405
static void windowCodeRangeTest(
155977156406
WindowCodeArg *p,
155978156407
int op, /* OP_Ge, OP_Gt, or OP_Le */
@@ -155987,11 +156416,16 @@
155987156416
int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */
155988156417
int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */
155989156418
int regString = ++pParse->nMem; /* Reg. for constant value '' */
155990156419
int arith = OP_Add; /* OP_Add or OP_Subtract */
155991156420
int addrGe; /* Jump destination */
156421
+ int addrDone = sqlite3VdbeMakeLabel(pParse); /* Address past OP_Ge */
155992156422
CollSeq *pColl;
156423
+
156424
+ /* Read the peer-value from each cursor into a register */
156425
+ windowReadPeerValues(p, csr1, reg1);
156426
+ windowReadPeerValues(p, csr2, reg2);
155993156427
155994156428
assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
155995156429
assert( pOrderBy && pOrderBy->nExpr==1 );
155996156430
if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
155997156431
switch( op ){
@@ -156000,38 +156434,15 @@
156000156434
default: assert( op==OP_Le ); op = OP_Ge; break;
156001156435
}
156002156436
arith = OP_Subtract;
156003156437
}
156004156438
156005
- /* Read the peer-value from each cursor into a register */
156006
- windowReadPeerValues(p, csr1, reg1);
156007
- windowReadPeerValues(p, csr2, reg2);
156008
-
156009156439
VdbeModuleComment((v, "CodeRangeTest: if( R%d %s R%d %s R%d ) goto lbl",
156010156440
reg1, (arith==OP_Add ? "+" : "-"), regVal,
156011156441
((op==OP_Ge) ? ">=" : (op==OP_Le) ? "<=" : (op==OP_Gt) ? ">" : "<"), reg2
156012156442
));
156013156443
156014
- /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
156015
- ** This block adds (or subtracts for DESC) the numeric value in regVal
156016
- ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
156017
- ** then leave reg1 as it is. In pseudo-code, this is implemented as:
156018
- **
156019
- ** if( reg1>='' ) goto addrGe;
156020
- ** reg1 = reg1 +/- regVal
156021
- ** addrGe:
156022
- **
156023
- ** Since all strings and blobs are greater-than-or-equal-to an empty string,
156024
- ** the add/subtract is skipped for these, as required. If reg1 is a NULL,
156025
- ** then the arithmetic is performed, but since adding or subtracting from
156026
- ** NULL is always NULL anyway, this case is handled as required too. */
156027
- sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
156028
- addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
156029
- VdbeCoverage(v);
156030
- sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
156031
- sqlite3VdbeJumpHere(v, addrGe);
156032
-
156033156444
/* If the BIGNULL flag is set for the ORDER BY, then it is required to
156034156445
** consider NULL values to be larger than all other values, instead of
156035156446
** the usual smaller. The VDBE opcodes OP_Ge and so on do not handle this
156036156447
** (and adding that capability causes a performance regression), so
156037156448
** instead if the BIGNULL flag is set then cases where either reg1 or
@@ -156064,27 +156475,50 @@
156064156475
sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl);
156065156476
VdbeCoverage(v);
156066156477
break;
156067156478
default: assert( op==OP_Lt ); /* no-op */ break;
156068156479
}
156069
- sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3);
156480
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
156070156481
156071156482
/* This block runs if reg1 is not NULL, but reg2 is. */
156072156483
sqlite3VdbeJumpHere(v, addr);
156073156484
sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
156074156485
if( op==OP_Gt || op==OP_Ge ){
156075
- sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1);
156486
+ sqlite3VdbeChangeP2(v, -1, addrDone);
156076156487
}
156077156488
}
156489
+
156490
+ /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
156491
+ ** This block adds (or subtracts for DESC) the numeric value in regVal
156492
+ ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
156493
+ ** then leave reg1 as it is. In pseudo-code, this is implemented as:
156494
+ **
156495
+ ** if( reg1>='' ) goto addrGe;
156496
+ ** reg1 = reg1 +/- regVal
156497
+ ** addrGe:
156498
+ **
156499
+ ** Since all strings and blobs are greater-than-or-equal-to an empty string,
156500
+ ** the add/subtract is skipped for these, as required. If reg1 is a NULL,
156501
+ ** then the arithmetic is performed, but since adding or subtracting from
156502
+ ** NULL is always NULL anyway, this case is handled as required too. */
156503
+ sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
156504
+ addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
156505
+ VdbeCoverage(v);
156506
+ if( (op==OP_Ge && arith==OP_Add) || (op==OP_Le && arith==OP_Subtract) ){
156507
+ sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
156508
+ }
156509
+ sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
156510
+ sqlite3VdbeJumpHere(v, addrGe);
156078156511
156079156512
/* Compare registers reg2 and reg1, taking the jump if required. Note that
156080156513
** control skips over this test if the BIGNULL flag is set and either
156081156514
** reg1 or reg2 contain a NULL value. */
156082156515
sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
156083156516
pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr);
156084156517
sqlite3VdbeAppendP4(v, (void*)pColl, P4_COLLSEQ);
156085156518
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
156519
+ sqlite3VdbeResolveLabel(v, addrDone);
156086156520
156087156521
assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
156088156522
testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
156089156523
testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
156090156524
testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
@@ -169758,11 +170192,11 @@
169758170192
/*
169759170193
** The assert_fts3_nc() macro is similar to the assert() macro, except that it
169760170194
** is used for assert() conditions that are true only if it can be
169761170195
** guranteed that the database is not corrupt.
169762170196
*/
169763
-#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
170197
+#ifdef SQLITE_DEBUG
169764170198
SQLITE_API extern int sqlite3_fts3_may_be_corrupt;
169765170199
# define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
169766170200
#else
169767170201
# define assert_fts3_nc(x) assert(x)
169768170202
#endif
@@ -170314,11 +170748,13 @@
170314170748
** This variable is set to false when running tests for which the on disk
170315170749
** structures should not be corrupt. Otherwise, true. If it is false, extra
170316170750
** assert() conditions in the fts3 code are activated - conditions that are
170317170751
** only true if it is guaranteed that the fts3 database is not corrupt.
170318170752
*/
170753
+#ifdef SQLITE_DEBUG
170319170754
SQLITE_API int sqlite3_fts3_may_be_corrupt = 1;
170755
+#endif
170320170756
170321170757
/*
170322170758
** Write a 64-bit variable-length integer to memory starting at p[0].
170323170759
** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
170324170760
** The number of bytes written is returned.
@@ -173574,18 +174010,24 @@
173574174010
/*
173575174011
** Implementation of xBegin() method.
173576174012
*/
173577174013
static int fts3BeginMethod(sqlite3_vtab *pVtab){
173578174014
Fts3Table *p = (Fts3Table*)pVtab;
174015
+ int rc;
173579174016
UNUSED_PARAMETER(pVtab);
173580174017
assert( p->pSegments==0 );
173581174018
assert( p->nPendingData==0 );
173582174019
assert( p->inTransaction!=1 );
173583
- TESTONLY( p->inTransaction = 1 );
173584
- TESTONLY( p->mxSavepoint = -1; );
173585174020
p->nLeafAdd = 0;
173586
- return fts3SetHasStat(p);
174021
+ rc = fts3SetHasStat(p);
174022
+#ifdef SQLITE_DEBUG
174023
+ if( rc==SQLITE_OK ){
174024
+ p->inTransaction = 1;
174025
+ p->mxSavepoint = -1;
174026
+ }
174027
+#endif
174028
+ return rc;
173587174029
}
173588174030
173589174031
/*
173590174032
** Implementation of xCommit() method. This is a no-op. The contents of
173591174033
** the pending-terms hash-table have already been flushed into the database
@@ -195860,10 +196302,14 @@
195860196302
if( sqlite3_value_type(pVal)==SQLITE_BLOB
195861196303
&& (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord))
195862196304
){
195863196305
const unsigned char *a = sqlite3_value_blob(pVal);
195864196306
int nVertex;
196307
+ if( a==0 ){
196308
+ sqlite3_result_error_nomem(pCtx);
196309
+ return 0;
196310
+ }
195865196311
nVertex = (a[1]<<16) + (a[2]<<8) + a[3];
195866196312
if( (a[0]==0 || a[0]==1)
195867196313
&& (nVertex*2*sizeof(GeoCoord) + 4)==(unsigned int)nByte
195868196314
){
195869196315
p = sqlite3_malloc64( sizeof(*p) + (nVertex-1)*2*sizeof(GeoCoord) );
@@ -196233,11 +196679,11 @@
196233196679
aCoord[0].f = mnX;
196234196680
aCoord[1].f = mxX;
196235196681
aCoord[2].f = mnY;
196236196682
aCoord[3].f = mxY;
196237196683
}
196238
- }else{
196684
+ }else if( aCoord ){
196239196685
memset(aCoord, 0, sizeof(RtreeCoord)*4);
196240196686
}
196241196687
return pOut;
196242196688
}
196243196689
@@ -226018,10 +226464,11 @@
226018226464
**************************************************************************
226019226465
** Below this point is the implementation of the fts5_decode() scalar
226020226466
** function only.
226021226467
*/
226022226468
226469
+#ifdef SQLITE_TEST
226023226470
/*
226024226471
** Decode a segment-data rowid from the %_data table. This function is
226025226472
** the opposite of macro FTS5_SEGMENT_ROWID().
226026226473
*/
226027226474
static void fts5DecodeRowid(
@@ -226040,11 +226487,13 @@
226040226487
*pbDlidx = (int)(iRowid & 0x0001);
226041226488
iRowid >>= FTS5_DATA_DLI_B;
226042226489
226043226490
*piSegid = (int)(iRowid & (((i64)1 << FTS5_DATA_ID_B) - 1));
226044226491
}
226492
+#endif /* SQLITE_TEST */
226045226493
226494
+#ifdef SQLITE_TEST
226046226495
static void fts5DebugRowid(int *pRc, Fts5Buffer *pBuf, i64 iKey){
226047226496
int iSegid, iHeight, iPgno, bDlidx; /* Rowid compenents */
226048226497
fts5DecodeRowid(iKey, &iSegid, &bDlidx, &iHeight, &iPgno);
226049226498
226050226499
if( iSegid==0 ){
@@ -226058,11 +226507,13 @@
226058226507
sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "{%ssegid=%d h=%d pgno=%d}",
226059226508
bDlidx ? "dlidx " : "", iSegid, iHeight, iPgno
226060226509
);
226061226510
}
226062226511
}
226512
+#endif /* SQLITE_TEST */
226063226513
226514
+#ifdef SQLITE_TEST
226064226515
static void fts5DebugStructure(
226065226516
int *pRc, /* IN/OUT: error code */
226066226517
Fts5Buffer *pBuf,
226067226518
Fts5Structure *p
226068226519
){
@@ -226080,11 +226531,13 @@
226080226531
);
226081226532
}
226082226533
sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "}");
226083226534
}
226084226535
}
226536
+#endif /* SQLITE_TEST */
226085226537
226538
+#ifdef SQLITE_TEST
226086226539
/*
226087226540
** This is part of the fts5_decode() debugging aid.
226088226541
**
226089226542
** Arguments pBlob/nBlob contain a serialized Fts5Structure object. This
226090226543
** function appends a human-readable representation of the same object
@@ -226105,11 +226558,13 @@
226105226558
}
226106226559
226107226560
fts5DebugStructure(pRc, pBuf, p);
226108226561
fts5StructureRelease(p);
226109226562
}
226563
+#endif /* SQLITE_TEST */
226110226564
226565
+#ifdef SQLITE_TEST
226111226566
/*
226112226567
** This is part of the fts5_decode() debugging aid.
226113226568
**
226114226569
** Arguments pBlob/nBlob contain an "averages" record. This function
226115226570
** appends a human-readable representation of record to the buffer passed
@@ -226128,11 +226583,13 @@
226128226583
i += sqlite3Fts5GetVarint(&pBlob[i], &iVal);
226129226584
sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "%s%d", zSpace, (int)iVal);
226130226585
zSpace = " ";
226131226586
}
226132226587
}
226588
+#endif /* SQLITE_TEST */
226133226589
226590
+#ifdef SQLITE_TEST
226134226591
/*
226135226592
** Buffer (a/n) is assumed to contain a list of serialized varints. Read
226136226593
** each varint and append its string representation to buffer pBuf. Return
226137226594
** after either the input buffer is exhausted or a 0 value is read.
226138226595
**
@@ -226145,11 +226602,13 @@
226145226602
iOff += fts5GetVarint32(&a[iOff], iVal);
226146226603
sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %d", iVal);
226147226604
}
226148226605
return iOff;
226149226606
}
226607
+#endif /* SQLITE_TEST */
226150226608
226609
+#ifdef SQLITE_TEST
226151226610
/*
226152226611
** The start of buffer (a/n) contains the start of a doclist. The doclist
226153226612
** may or may not finish within the buffer. This function appends a text
226154226613
** representation of the part of the doclist that is present to buffer
226155226614
** pBuf.
@@ -226178,11 +226637,13 @@
226178226637
}
226179226638
}
226180226639
226181226640
return iOff;
226182226641
}
226642
+#endif /* SQLITE_TEST */
226183226643
226644
+#ifdef SQLITE_TEST
226184226645
/*
226185226646
** This function is part of the fts5_decode() debugging function. It is
226186226647
** only ever used with detail=none tables.
226187226648
**
226188226649
** Buffer (pData/nData) contains a doclist in the format used by detail=none
@@ -226219,11 +226680,13 @@
226219226680
}
226220226681
226221226682
sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %lld%s", iRowid, zApp);
226222226683
}
226223226684
}
226685
+#endif /* SQLITE_TEST */
226224226686
226687
+#ifdef SQLITE_TEST
226225226688
/*
226226226689
** The implementation of user-defined scalar function fts5_decode().
226227226690
*/
226228226691
static void fts5DecodeFunction(
226229226692
sqlite3_context *pCtx, /* Function call context */
@@ -226428,11 +226891,13 @@
226428226891
}else{
226429226892
sqlite3_result_error_code(pCtx, rc);
226430226893
}
226431226894
fts5BufferFree(&s);
226432226895
}
226896
+#endif /* SQLITE_TEST */
226433226897
226898
+#ifdef SQLITE_TEST
226434226899
/*
226435226900
** The implementation of user-defined scalar function fts5_rowid().
226436226901
*/
226437226902
static void fts5RowidFunction(
226438226903
sqlite3_context *pCtx, /* Function call context */
@@ -226462,10 +226927,11 @@
226462226927
"first arg to fts5_rowid() must be 'segment'" , -1
226463226928
);
226464226929
}
226465226930
}
226466226931
}
226932
+#endif /* SQLITE_TEST */
226467226933
226468226934
/*
226469226935
** This is called as part of registering the FTS5 module with database
226470226936
** connection db. It registers several user-defined scalar functions useful
226471226937
** with FTS5.
@@ -226472,10 +226938,11 @@
226472226938
**
226473226939
** If successful, SQLITE_OK is returned. If an error occurs, some other
226474226940
** SQLite error code is returned instead.
226475226941
*/
226476226942
static int sqlite3Fts5IndexInit(sqlite3 *db){
226943
+#ifdef SQLITE_TEST
226477226944
int rc = sqlite3_create_function(
226478226945
db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
226479226946
);
226480226947
226481226948
if( rc==SQLITE_OK ){
@@ -226489,10 +226956,13 @@
226489226956
rc = sqlite3_create_function(
226490226957
db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0
226491226958
);
226492226959
}
226493226960
return rc;
226961
+#else
226962
+ return SQLITE_OK;
226963
+#endif
226494226964
}
226495226965
226496226966
226497226967
static int sqlite3Fts5IndexReset(Fts5Index *p){
226498226968
assert( p->pStruct==0 || p->iStructVersion!=0 );
@@ -226524,11 +226994,13 @@
226524226994
** This variable is set to false when running tests for which the on disk
226525226995
** structures should not be corrupt. Otherwise, true. If it is false, extra
226526226996
** assert() conditions in the fts5 code are activated - conditions that are
226527226997
** only true if it is guaranteed that the fts5 database is not corrupt.
226528226998
*/
226999
+#ifdef SQLITE_DEBUG
226529227000
SQLITE_API int sqlite3_fts5_may_be_corrupt = 1;
227001
+#endif
226530227002
226531227003
226532227004
typedef struct Fts5Auxdata Fts5Auxdata;
226533227005
typedef struct Fts5Auxiliary Fts5Auxiliary;
226534227006
typedef struct Fts5Cursor Fts5Cursor;
@@ -229290,11 +229762,11 @@
229290229762
int nArg, /* Number of args */
229291229763
sqlite3_value **apUnused /* Function arguments */
229292229764
){
229293229765
assert( nArg==0 );
229294229766
UNUSED_PARAM2(nArg, apUnused);
229295
- sqlite3_result_text(pCtx, "fts5: 2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db635aa", -1, SQLITE_TRANSIENT);
229767
+ sqlite3_result_text(pCtx, "fts5: 2021-04-07 13:20:34 c22e47c77a35ebcd1fdfc0caea9119dd5e24e76d5fdd0f2ffbb58205a7242297", -1, SQLITE_TRANSIENT);
229296229768
}
229297229769
229298229770
/*
229299229771
** Return true if zName is the extension on one of the shadow tables used
229300229772
** by this module.
@@ -234216,12 +234688,12 @@
234216234688
}
234217234689
#endif /* SQLITE_CORE */
234218234690
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234219234691
234220234692
/************** End of stmt.c ************************************************/
234221
-#if __LINE__!=234221
234693
+#if __LINE__!=234693
234222234694
#undef SQLITE_SOURCE_ID
234223
-#define SQLITE_SOURCE_ID "2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db6alt2"
234695
+#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e158alt2"
234224234696
#endif
234225234697
/* Return the source-id for this library */
234226234698
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234227234699
/************************** End of sqlite3.c ******************************/
234228234700
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.35.4. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -1184,13 +1184,13 @@
1184 **
1185 ** See also: [sqlite3_libversion()],
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.35.4"
1190 #define SQLITE_VERSION_NUMBER 3035004
1191 #define SQLITE_SOURCE_ID "2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db635aa"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -2189,10 +2189,23 @@
2189 ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
2190 ** in wal mode after the client has finished copying pages from the wal
2191 ** file to the database file, but before the *-shm file is updated to
2192 ** record the fact that the pages have been checkpointed.
2193 ** </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
2194 */
2195 #define SQLITE_FCNTL_LOCKSTATE 1
2196 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
2197 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
2198 #define SQLITE_FCNTL_LAST_ERRNO 4
@@ -2228,10 +2241,12 @@
2228 #define SQLITE_FCNTL_DATA_VERSION 35
2229 #define SQLITE_FCNTL_SIZE_LIMIT 36
2230 #define SQLITE_FCNTL_CKPT_DONE 37
2231 #define SQLITE_FCNTL_RESERVE_BYTES 38
2232 #define SQLITE_FCNTL_CKPT_START 39
 
 
2233
2234 /* deprecated names */
2235 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2236 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2237 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -15758,11 +15773,11 @@
15758 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
15759 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
15760 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15761 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15762 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15763 #define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
15764 #define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15765 #define OP_IncrVacuum 60 /* jump */
15766 #define OP_VNext 61 /* jump */
15767 #define OP_Init 62 /* jump, synopsis: Start at P2 */
15768 #define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@NP]) */
@@ -15789,23 +15804,23 @@
15789 #define OP_RealAffinity 84
15790 #define OP_Cast 85 /* synopsis: affinity(r[P1]) */
15791 #define OP_Permutation 86
15792 #define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15793 #define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15794 #define OP_Offset 89 /* synopsis: r[P3] = sqlite_offset(P1) */
15795 #define OP_Column 90 /* synopsis: r[P3]=PX */
15796 #define OP_Affinity 91 /* synopsis: affinity(r[P1@P2]) */
15797 #define OP_MakeRecord 92 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15798 #define OP_Count 93 /* synopsis: r[P2]=count() */
15799 #define OP_ReadCookie 94
15800 #define OP_SetCookie 95
15801 #define OP_ReopenIdx 96 /* synopsis: root=P2 iDb=P3 */
15802 #define OP_OpenRead 97 /* synopsis: root=P2 iDb=P3 */
15803 #define OP_OpenWrite 98 /* synopsis: root=P2 iDb=P3 */
15804 #define OP_OpenDup 99
15805 #define OP_OpenAutoindex 100 /* synopsis: nColumn=P2 */
15806 #define OP_OpenEphemeral 101 /* synopsis: nColumn=P2 */
15807 #define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15808 #define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15809 #define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
15810 #define OP_ShiftRight 105 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
15811 #define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -15812,77 +15827,78 @@
15812 #define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
15813 #define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
15814 #define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15815 #define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15816 #define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15817 #define OP_SorterOpen 112
15818 #define OP_BitNot 113 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15819 #define OP_SequenceTest 114 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15820 #define OP_OpenPseudo 115 /* synopsis: P3 columns in r[P2] */
15821 #define OP_String8 116 /* same as TK_STRING, synopsis: r[P2]='P4' */
15822 #define OP_Close 117
15823 #define OP_ColumnsUsed 118
15824 #define OP_SeekScan 119 /* synopsis: Scan-ahead up to P1 rows */
15825 #define OP_SeekHit 120 /* synopsis: set P2<=seekHit<=P3 */
15826 #define OP_Sequence 121 /* synopsis: r[P2]=cursor[P1].ctr++ */
15827 #define OP_NewRowid 122 /* synopsis: r[P2]=rowid */
15828 #define OP_Insert 123 /* synopsis: intkey=r[P3] data=r[P2] */
15829 #define OP_RowCell 124
15830 #define OP_Delete 125
15831 #define OP_ResetCount 126
15832 #define OP_SorterCompare 127 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15833 #define OP_SorterData 128 /* synopsis: r[P2]=data */
15834 #define OP_RowData 129 /* synopsis: r[P2]=data */
15835 #define OP_Rowid 130 /* synopsis: r[P2]=rowid */
15836 #define OP_NullRow 131
15837 #define OP_SeekEnd 132
15838 #define OP_IdxInsert 133 /* synopsis: key=r[P2] */
15839 #define OP_SorterInsert 134 /* synopsis: key=r[P2] */
15840 #define OP_IdxDelete 135 /* synopsis: key=r[P2@P3] */
15841 #define OP_DeferredSeek 136 /* synopsis: Move P3 to P1.rowid if needed */
15842 #define OP_IdxRowid 137 /* synopsis: r[P2]=rowid */
15843 #define OP_FinishSeek 138
15844 #define OP_Destroy 139
15845 #define OP_Clear 140
15846 #define OP_ResetSorter 141
15847 #define OP_CreateBtree 142 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15848 #define OP_SqlExec 143
15849 #define OP_ParseSchema 144
15850 #define OP_LoadAnalysis 145
15851 #define OP_DropTable 146
15852 #define OP_DropIndex 147
15853 #define OP_DropTrigger 148
15854 #define OP_IntegrityCk 149
15855 #define OP_RowSetAdd 150 /* synopsis: rowset(P1)=r[P2] */
15856 #define OP_Param 151
15857 #define OP_Real 152 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15858 #define OP_FkCounter 153 /* synopsis: fkctr[P1]+=P2 */
15859 #define OP_MemMax 154 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15860 #define OP_OffsetLimit 155 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15861 #define OP_AggInverse 156 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15862 #define OP_AggStep 157 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15863 #define OP_AggStep1 158 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15864 #define OP_AggValue 159 /* synopsis: r[P3]=value N=P2 */
15865 #define OP_AggFinal 160 /* synopsis: accum=r[P1] N=P2 */
15866 #define OP_Expire 161
15867 #define OP_CursorLock 162
15868 #define OP_CursorUnlock 163
15869 #define OP_TableLock 164 /* synopsis: iDb=P1 root=P2 write=P3 */
15870 #define OP_VBegin 165
15871 #define OP_VCreate 166
15872 #define OP_VDestroy 167
15873 #define OP_VOpen 168
15874 #define OP_VColumn 169 /* synopsis: r[P3]=vcolumn(P2) */
15875 #define OP_VRename 170
15876 #define OP_Pagecount 171
15877 #define OP_MaxPgcnt 172
15878 #define OP_Trace 173
15879 #define OP_CursorHint 174
15880 #define OP_ReleaseReg 175 /* synopsis: release r[P1@P2] mask P3 */
15881 #define OP_Noop 176
15882 #define OP_Explain 177
15883 #define OP_Abortable 178
 
15884
15885 /* Properties such as "out2" or "jump" that are specified in
15886 ** comments following the "case" for each opcode in the vdbe.c
15887 ** are encoded into bitvectors as follows:
15888 */
@@ -15902,22 +15918,22 @@
15902 /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15903 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
15904 /* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
15905 /* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
15906 /* 80 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
15907 /* 88 */ 0x12, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
15908 /* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26,\
15909 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
15910 /* 112 */ 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,\
15911 /* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15912 /* 128 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04, 0x00,\
15913 /* 136 */ 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00,\
15914 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10,\
15915 /* 152 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
15916 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15917 /* 168 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
15918 /* 176 */ 0x00, 0x00, 0x00,}
15919
15920 /* The sqlite3P2Values() routine is able to run faster if it knows
15921 ** the value of the largest JUMP opcode. The smaller the maximum
15922 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15923 ** generated this include file strives to group all JUMP opcodes
@@ -17005,14 +17021,11 @@
17005 u8 iDb; /* Which db file is being initialized */
17006 u8 busy; /* TRUE if currently initializing */
17007 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
17008 unsigned imposterTable : 1; /* Building an imposter table */
17009 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
17010 unsigned bDropColumn : 1; /* Doing schema check after DROP COLUMN */
17011 char **azInit; /* "type", "name", and "tbl_name" columns */
17012 /* or if bDropColumn, then azInit[0] is the */
17013 /* name of the column being dropped */
17014 } init;
17015 int nVdbeActive; /* Number of VDBEs currently running */
17016 int nVdbeRead; /* Number of active VDBEs that read or write */
17017 int nVdbeWrite; /* Number of active VDBEs that read and write */
17018 int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -17579,13 +17592,11 @@
17579 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
17580 ** It causes an assert() to fire if either operand to a comparison
17581 ** operator is NULL. It is added to certain comparison operators to
17582 ** prove that the operands are always NOT NULL.
17583 */
17584 #define SQLITE_KEEPNULL 0x08 /* Used by vector == or <> */
17585 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
17586 #define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */
17587 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
17588 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
17589
17590 /*
17591 ** An object of this type is created for each virtual table present in
@@ -18078,10 +18089,11 @@
18078 struct AggInfo_func { /* For each aggregate function */
18079 Expr *pFExpr; /* Expression encoding the function */
18080 FuncDef *pFunc; /* The aggregate function implementation */
18081 int iMem; /* Memory location that acts as accumulator */
18082 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
 
18083 } *aFunc;
18084 int nFunc; /* Number of entries in aFunc[] */
18085 u32 selId; /* Select to which this AggInfo belongs */
18086 };
18087
@@ -18350,10 +18362,11 @@
18350 ** ENAME_SPAN Text of the original result set
18351 ** expression.
18352 */
18353 struct ExprList {
18354 int nExpr; /* Number of expressions on the list */
 
18355 struct ExprList_item { /* For each expression in the list */
18356 Expr *pExpr; /* The parse tree for this expression */
18357 char *zEName; /* Token associated with this expression */
18358 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18359 unsigned eEName :2; /* Meaning of zEName */
@@ -18494,11 +18507,11 @@
18494 ** the OR optimization */
18495 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
18496 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
18497 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
18498 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18499 /* 0x0400 not currently used */
18500 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
18501 /* 0x1000 not currently used */
18502 /* 0x2000 not currently used */
18503 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
18504 /* 0x8000 not currently used */
@@ -20213,10 +20226,13 @@
20213 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
20214 #ifndef SQLITE_AMALGAMATION
20215 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
20216 SQLITE_PRIVATE const char sqlite3StrBINARY[];
20217 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
 
 
 
20218 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
20219 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
20220 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
20221 #ifndef SQLITE_OMIT_WSD
20222 SQLITE_PRIVATE int sqlite3PendingByte;
@@ -20679,11 +20695,11 @@
20679 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
20680 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
20681 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
20682 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
20683 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
20684 252,253,254,255
20685 #endif
20686 #ifdef SQLITE_EBCDIC
20687 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
20688 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
20689 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
@@ -20699,11 +20715,39 @@
20699 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */
20700 208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */
20701 224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
20702 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
20703 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20704 };
 
 
 
20705
20706 /*
20707 ** The following 256 byte lookup table is used to support SQLites built-in
20708 ** equivalents to the following standard library functions:
20709 **
@@ -23472,11 +23516,11 @@
23472 return rc;
23473 }
23474 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
23475 DO_OS_MALLOC_TEST(0);
23476 assert( dirSync==0 || dirSync==1 );
23477 return pVfs->xDelete(pVfs, zPath, dirSync);
23478 }
23479 SQLITE_PRIVATE int sqlite3OsAccess(
23480 sqlite3_vfs *pVfs,
23481 const char *zPath,
23482 int flags,
@@ -28461,11 +28505,11 @@
28461 /* The rest are extensions, not normally found in printf() */
28462 #define etSQLESCAPE 9 /* Strings with '\'' doubled. %q */
28463 #define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
28464 NULL pointers replaced by SQL NULL. %Q */
28465 #define etTOKEN 11 /* a pointer to a Token structure */
28466 #define etSRCLIST 12 /* a pointer to a SrcList */
28467 #define etPOINTER 13 /* The %p conversion */
28468 #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
28469 #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
28470 #define etDECIMAL 16 /* %d or %u, but not %x, %o */
28471
@@ -28527,13 +28571,19 @@
28527 { '%', 0, 0, etPERCENT, 0, 0 },
28528 { 'p', 16, 0, etPOINTER, 0, 1 },
28529
28530 /* All the rest are undocumented and are for internal use only */
28531 { 'T', 0, 0, etTOKEN, 0, 0 },
28532 { 'S', 0, 0, etSRCLIST, 0, 0 },
28533 { 'r', 10, 1, etORDINAL, 0, 0 },
28534 };
 
 
 
 
 
 
28535
28536 /* Floating point constants used for rounding */
28537 static const double arRound[] = {
28538 5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
28539 5.0e-06, 5.0e-07, 5.0e-08, 5.0e-09, 5.0e-10,
@@ -29285,25 +29335,28 @@
29285 sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
29286 }
29287 length = width = 0;
29288 break;
29289 }
29290 case etSRCLIST: {
29291 SrcList *pSrc;
29292 int k;
29293 SrcItem *pItem;
29294 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
29295 pSrc = va_arg(ap, SrcList*);
29296 k = va_arg(ap, int);
29297 pItem = &pSrc->a[k];
29298 assert( bArgList==0 );
29299 assert( k>=0 && k<pSrc->nSrc );
29300 if( pItem->zDatabase ){
29301 sqlite3_str_appendall(pAccum, pItem->zDatabase);
29302 sqlite3_str_append(pAccum, ".", 1);
 
 
 
 
 
 
 
 
29303 }
29304 sqlite3_str_appendall(pAccum, pItem->zName);
29305 length = width = 0;
29306 break;
29307 }
29308 default: {
29309 assert( xtype==etINVALID );
@@ -29879,23 +29932,15 @@
29879 for(i=0; i<pSrc->nSrc; i++){
29880 const SrcItem *pItem = &pSrc->a[i];
29881 StrAccum x;
29882 char zLine[100];
29883 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
29884 sqlite3_str_appendf(&x, "{%d:*}", pItem->iCursor);
29885 if( pItem->zDatabase ){
29886 sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
29887 }else if( pItem->zName ){
29888 sqlite3_str_appendf(&x, " %s", pItem->zName);
29889 }
29890 if( pItem->pTab ){
29891 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
29892 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
29893 }
29894 if( pItem->zAlias ){
29895 sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
29896 }
29897 if( pItem->fg.jointype & JT_LEFT ){
29898 sqlite3_str_appendf(&x, " LEFT-JOIN");
29899 }
29900 if( pItem->fg.fromDDL ){
29901 sqlite3_str_appendf(&x, " DDL");
@@ -33531,11 +33576,11 @@
33531 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
33532 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
33533 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
33534 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
33535 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
33536 /* 58 */ "ElseNotEq" OpHelp(""),
33537 /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
33538 /* 60 */ "IncrVacuum" OpHelp(""),
33539 /* 61 */ "VNext" OpHelp(""),
33540 /* 62 */ "Init" OpHelp("Start at P2"),
33541 /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
@@ -33562,23 +33607,23 @@
33562 /* 84 */ "RealAffinity" OpHelp(""),
33563 /* 85 */ "Cast" OpHelp("affinity(r[P1])"),
33564 /* 86 */ "Permutation" OpHelp(""),
33565 /* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
33566 /* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
33567 /* 89 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
33568 /* 90 */ "Column" OpHelp("r[P3]=PX"),
33569 /* 91 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
33570 /* 92 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
33571 /* 93 */ "Count" OpHelp("r[P2]=count()"),
33572 /* 94 */ "ReadCookie" OpHelp(""),
33573 /* 95 */ "SetCookie" OpHelp(""),
33574 /* 96 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
33575 /* 97 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
33576 /* 98 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
33577 /* 99 */ "OpenDup" OpHelp(""),
33578 /* 100 */ "OpenAutoindex" OpHelp("nColumn=P2"),
33579 /* 101 */ "OpenEphemeral" OpHelp("nColumn=P2"),
33580 /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
33581 /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
33582 /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
33583 /* 105 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
33584 /* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -33585,77 +33630,78 @@
33585 /* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
33586 /* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
33587 /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
33588 /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
33589 /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
33590 /* 112 */ "SorterOpen" OpHelp(""),
33591 /* 113 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
33592 /* 114 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
33593 /* 115 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
33594 /* 116 */ "String8" OpHelp("r[P2]='P4'"),
33595 /* 117 */ "Close" OpHelp(""),
33596 /* 118 */ "ColumnsUsed" OpHelp(""),
33597 /* 119 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
33598 /* 120 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
33599 /* 121 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
33600 /* 122 */ "NewRowid" OpHelp("r[P2]=rowid"),
33601 /* 123 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
33602 /* 124 */ "RowCell" OpHelp(""),
33603 /* 125 */ "Delete" OpHelp(""),
33604 /* 126 */ "ResetCount" OpHelp(""),
33605 /* 127 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
33606 /* 128 */ "SorterData" OpHelp("r[P2]=data"),
33607 /* 129 */ "RowData" OpHelp("r[P2]=data"),
33608 /* 130 */ "Rowid" OpHelp("r[P2]=rowid"),
33609 /* 131 */ "NullRow" OpHelp(""),
33610 /* 132 */ "SeekEnd" OpHelp(""),
33611 /* 133 */ "IdxInsert" OpHelp("key=r[P2]"),
33612 /* 134 */ "SorterInsert" OpHelp("key=r[P2]"),
33613 /* 135 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
33614 /* 136 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
33615 /* 137 */ "IdxRowid" OpHelp("r[P2]=rowid"),
33616 /* 138 */ "FinishSeek" OpHelp(""),
33617 /* 139 */ "Destroy" OpHelp(""),
33618 /* 140 */ "Clear" OpHelp(""),
33619 /* 141 */ "ResetSorter" OpHelp(""),
33620 /* 142 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
33621 /* 143 */ "SqlExec" OpHelp(""),
33622 /* 144 */ "ParseSchema" OpHelp(""),
33623 /* 145 */ "LoadAnalysis" OpHelp(""),
33624 /* 146 */ "DropTable" OpHelp(""),
33625 /* 147 */ "DropIndex" OpHelp(""),
33626 /* 148 */ "DropTrigger" OpHelp(""),
33627 /* 149 */ "IntegrityCk" OpHelp(""),
33628 /* 150 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
33629 /* 151 */ "Param" OpHelp(""),
33630 /* 152 */ "Real" OpHelp("r[P2]=P4"),
33631 /* 153 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33632 /* 154 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
33633 /* 155 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
33634 /* 156 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
33635 /* 157 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
33636 /* 158 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
33637 /* 159 */ "AggValue" OpHelp("r[P3]=value N=P2"),
33638 /* 160 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
33639 /* 161 */ "Expire" OpHelp(""),
33640 /* 162 */ "CursorLock" OpHelp(""),
33641 /* 163 */ "CursorUnlock" OpHelp(""),
33642 /* 164 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
33643 /* 165 */ "VBegin" OpHelp(""),
33644 /* 166 */ "VCreate" OpHelp(""),
33645 /* 167 */ "VDestroy" OpHelp(""),
33646 /* 168 */ "VOpen" OpHelp(""),
33647 /* 169 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
33648 /* 170 */ "VRename" OpHelp(""),
33649 /* 171 */ "Pagecount" OpHelp(""),
33650 /* 172 */ "MaxPgcnt" OpHelp(""),
33651 /* 173 */ "Trace" OpHelp(""),
33652 /* 174 */ "CursorHint" OpHelp(""),
33653 /* 175 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
33654 /* 176 */ "Noop" OpHelp(""),
33655 /* 177 */ "Explain" OpHelp(""),
33656 /* 178 */ "Abortable" OpHelp(""),
 
33657 };
33658 return azName[i];
33659 }
33660 #endif
33661
@@ -37810,10 +37856,11 @@
37810 }
37811 }
37812
37813 /* Forward declaration */
37814 static int unixGetTempname(int nBuf, char *zBuf);
 
37815
37816 /*
37817 ** Information and control of an open file handle.
37818 */
37819 static int unixFileControl(sqlite3_file *id, int op, void *pArg){
@@ -37926,10 +37973,14 @@
37926 case SQLITE_FCNTL_SET_LOCKPROXYFILE:
37927 case SQLITE_FCNTL_GET_LOCKPROXYFILE: {
37928 return proxyFileControl(id,op,pArg);
37929 }
37930 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
 
 
 
 
37931 }
37932 return SQLITE_NOTFOUND;
37933 }
37934
37935 /*
@@ -38170,10 +38221,44 @@
38170 /*
38171 ** Constants used for locking
38172 */
38173 #define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
38174 #define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38175
38176 /*
38177 ** Apply posix advisory locks for all bytes from ofst through ofst+n-1.
38178 **
38179 ** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking
@@ -56081,11 +56166,12 @@
56081 ** Once this function has been called, the transaction must either be
56082 ** rolled back or committed. It is not safe to call this function and
56083 ** then continue writing to the database.
56084 */
56085 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
56086 assert( pPager->dbSize>=nPage );
 
56087 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
56088 pPager->dbSize = nPage;
56089
56090 /* At one point the code here called assertTruncateConstraint() to
56091 ** ensure that all pages being truncated away by this operation are,
@@ -70348,11 +70434,13 @@
70348 ** to the last entry in the b-tree. */
70349 int ii;
70350 for(ii=0; ii<pCur->iPage; ii++){
70351 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
70352 }
70353 assert( pCur->ix==pCur->pPage->nCell-1 );
 
 
70354 assert( pCur->pPage->leaf );
70355 #endif
70356 *pRes = 0;
70357 return SQLITE_OK;
70358 }
@@ -71115,11 +71203,11 @@
71115 closest = 0;
71116 }
71117
71118 iPage = get4byte(&aData[8+closest*4]);
71119 testcase( iPage==mxPage );
71120 if( iPage>mxPage ){
71121 rc = SQLITE_CORRUPT_PGNO(iTrunk);
71122 goto end_allocate_page;
71123 }
71124 testcase( iPage==mxPage );
71125 if( !searchList
@@ -74062,11 +74150,11 @@
74062 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
74063 if( pCur->eState==CURSOR_REQUIRESEEK ){
74064 rc = btreeRestoreCursorPosition(pCur);
74065 if( rc ) return rc;
74066 }
74067 assert( pCur->eState==CURSOR_VALID );
74068
74069 iCellDepth = pCur->iPage;
74070 iCellIdx = pCur->ix;
74071 pPage = pCur->pPage;
74072 pCell = findCell(pPage, iCellIdx);
@@ -79862,15 +79950,11 @@
79862 if( zOpName[nOpName+1] ){
79863 int seenCom = 0;
79864 char c;
79865 zSynopsis = zOpName += nOpName + 1;
79866 if( strncmp(zSynopsis,"IF ",3)==0 ){
79867 if( pOp->p5 & SQLITE_STOREP2 ){
79868 sqlite3_snprintf(sizeof(zAlt), zAlt, "r[P2] = (%s)", zSynopsis+3);
79869 }else{
79870 sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3);
79871 }
79872 zSynopsis = zAlt;
79873 }
79874 for(ii=0; (c = zSynopsis[ii])!=0; ii++){
79875 if( c=='P' ){
79876 c = zSynopsis[++ii];
@@ -87438,11 +87522,11 @@
87438 */
87439 case OP_ResultRow: {
87440 Mem *pMem;
87441 int i;
87442 assert( p->nResColumn==pOp->p2 );
87443 assert( pOp->p1>0 );
87444 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
87445
87446 /* Invalidate all ephemeral cursor row caches */
87447 p->cacheCtr = (p->cacheCtr + 2)|1;
87448
@@ -87880,12 +87964,11 @@
87880
87881 /* Opcode: Eq P1 P2 P3 P4 P5
87882 ** Synopsis: IF r[P3]==r[P1]
87883 **
87884 ** Compare the values in register P1 and P3. If reg(P3)==reg(P1) then
87885 ** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5, then
87886 ** store the result of comparison in register P2.
87887 **
87888 ** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
87889 ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
87890 ** to coerce both inputs according to this affinity before the
87891 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
@@ -87907,31 +87990,25 @@
87907 ** true or false and is never NULL. If both operands are NULL then the result
87908 ** of comparison is true. If either operand is NULL then the result is false.
87909 ** If neither operand is NULL the result is the same as it would be if
87910 ** the SQLITE_NULLEQ flag were omitted from P5.
87911 **
87912 ** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
87913 ** content of r[P2] is only changed if the new value is NULL or 0 (false).
87914 ** In other words, a prior r[P2] value will not be overwritten by 1 (true).
87915 */
87916 /* Opcode: Ne P1 P2 P3 P4 P5
87917 ** Synopsis: IF r[P3]!=r[P1]
87918 **
87919 ** This works just like the Eq opcode except that the jump is taken if
87920 ** the operands in registers P1 and P3 are not equal. See the Eq opcode for
87921 ** additional information.
87922 **
87923 ** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
87924 ** content of r[P2] is only changed if the new value is NULL or 1 (true).
87925 ** In other words, a prior r[P2] value will not be overwritten by 0 (false).
87926 */
87927 /* Opcode: Lt P1 P2 P3 P4 P5
87928 ** Synopsis: IF r[P3]<r[P1]
87929 **
87930 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
87931 ** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5 store
87932 ** the result of comparison (0 or 1 or NULL) into register P2.
87933 **
87934 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
87935 ** reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL
87936 ** bit is clear then fall through if either operand is NULL.
87937 **
@@ -87950,10 +88027,13 @@
87950 ** P4 is used to do the comparison. If P4 is not specified then
87951 ** memcmp() is used to compare text string. If both values are
87952 ** numeric, then a numeric comparison is used. If the two values
87953 ** are of different types, then numbers are considered less than
87954 ** strings and strings are considered less than blobs.
 
 
 
87955 */
87956 /* Opcode: Le P1 P2 P3 P4 P5
87957 ** Synopsis: IF r[P3]<=r[P1]
87958 **
87959 ** This works just like the Lt opcode except that the jump is taken if
@@ -88009,21 +88089,14 @@
88009 }else{
88010 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
88011 ** then the result is always NULL.
88012 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
88013 */
88014 if( pOp->p5 & SQLITE_STOREP2 ){
88015 pOut = &aMem[pOp->p2];
88016 iCompare = 1; /* Operands are not equal */
88017 memAboutToChange(p, pOut);
88018 MemSetTypeFlag(pOut, MEM_Null);
88019 REGISTER_TRACE(pOp->p2, pOut);
88020 }else{
88021 VdbeBranchTaken(2,3);
88022 if( pOp->p5 & SQLITE_JUMPIFNULL ){
88023 goto jump_to_p2;
88024 }
88025 }
88026 break;
88027 }
88028 }else{
88029 /* Neither operand is NULL. Do a comparison. */
@@ -88076,88 +88149,58 @@
88076 ** operator actually is. The next block of code depends on the fact
88077 ** that the 6 comparison operators are consecutive integers in this
88078 ** order: NE, EQ, GT, LE, LT, GE */
88079 assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 );
88080 assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 );
88081 if( res<0 ){ /* ne, eq, gt, le, lt, ge */
88082 static const unsigned char aLTb[] = { 1, 0, 0, 1, 1, 0 };
88083 res2 = aLTb[pOp->opcode - OP_Ne];
88084 }else if( res==0 ){
88085 static const unsigned char aEQb[] = { 0, 1, 0, 1, 0, 1 };
88086 res2 = aEQb[pOp->opcode - OP_Ne];
88087 }else{
88088 static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 };
88089 res2 = aGTb[pOp->opcode - OP_Ne];
88090 }
 
88091
88092 /* Undo any changes made by applyAffinity() to the input registers. */
88093 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
88094 pIn3->flags = flags3;
88095 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
88096 pIn1->flags = flags1;
88097
88098 if( pOp->p5 & SQLITE_STOREP2 ){
88099 pOut = &aMem[pOp->p2];
88100 iCompare = res;
88101 if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
88102 /* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1
88103 ** and prevents OP_Ne from overwriting NULL with 0. This flag
88104 ** is only used in contexts where either:
88105 ** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0)
88106 ** (2) op==OP_Ne && (r[P2]==NULL || r[P2]==1)
88107 ** Therefore it is not necessary to check the content of r[P2] for
88108 ** NULL. */
88109 assert( pOp->opcode==OP_Ne || pOp->opcode==OP_Eq );
88110 assert( res2==0 || res2==1 );
88111 testcase( res2==0 && pOp->opcode==OP_Eq );
88112 testcase( res2==1 && pOp->opcode==OP_Eq );
88113 testcase( res2==0 && pOp->opcode==OP_Ne );
88114 testcase( res2==1 && pOp->opcode==OP_Ne );
88115 if( (pOp->opcode==OP_Eq)==res2 ) break;
88116 }
88117 memAboutToChange(p, pOut);
88118 MemSetTypeFlag(pOut, MEM_Int);
88119 pOut->u.i = res2;
88120 REGISTER_TRACE(pOp->p2, pOut);
88121 }else{
88122 VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
88123 if( res2 ){
88124 goto jump_to_p2;
88125 }
88126 }
88127 break;
88128 }
88129
88130 /* Opcode: ElseNotEq * P2 * * *
88131 **
88132 ** This opcode must follow an OP_Lt or OP_Gt comparison operator. There
88133 ** can be zero or more OP_ReleaseReg opcodes intervening, but no other
88134 ** opcodes are allowed to occur between this instruction and the previous
88135 ** OP_Lt or OP_Gt. Furthermore, the prior OP_Lt or OP_Gt must have the
88136 ** SQLITE_STOREP2 bit set in the P5 field.
88137 **
88138 ** If result of an OP_Eq comparison on the same two operands as the
88139 ** prior OP_Lt or OP_Gt would have been NULL or false (0), then then
88140 ** jump to P2. If the result of an OP_Eq comparison on the two previous
88141 ** operands would have been true (1), then fall through.
88142 */
88143 case OP_ElseNotEq: { /* same as TK_ESCAPE, jump */
88144
88145 #ifdef SQLITE_DEBUG
88146 /* Verify the preconditions of this opcode - that it follows an OP_Lt or
88147 ** OP_Gt with the SQLITE_STOREP2 flag set, with zero or more intervening
88148 ** OP_ReleaseReg opcodes */
88149 int iAddr;
88150 for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
88151 if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
88152 assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
88153 assert( aOp[iAddr].p5 & SQLITE_STOREP2 );
88154 break;
88155 }
88156 #endif /* SQLITE_DEBUG */
88157 VdbeBranchTaken(iCompare!=0, 2);
88158 if( iCompare!=0 ) goto jump_to_p2;
88159 break;
88160 }
88161
88162
88163 /* Opcode: Permutation * * * P4 *
@@ -88463,10 +88506,28 @@
88463 if( (pIn1->flags & MEM_Null)!=0 ){
88464 goto jump_to_p2;
88465 }
88466 break;
88467 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88468
88469 /* Opcode: NotNull P1 P2 * * *
88470 ** Synopsis: if r[P1]!=NULL goto P2
88471 **
88472 ** Jump to P2 if the value in register P1 is not NULL.
@@ -99001,12 +99062,14 @@
99001 pTab = 0;
99002 #ifndef SQLITE_OMIT_TRIGGER
99003 if( pParse->pTriggerTab!=0 ){
99004 int op = pParse->eTriggerOp;
99005 assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
99006 if( pParse->bReturning && (pNC->ncFlags & NC_UBaseReg)!=0 ){
99007 if( zTab==0 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0 ){
 
 
99008 pExpr->iTable = op!=TK_DELETE;
99009 pTab = pParse->pTriggerTab;
99010 }
99011 }else if( op!=TK_DELETE && zTab && sqlite3StrICmp("new",zTab) == 0 ){
99012 pExpr->iTable = 1;
@@ -99186,11 +99249,10 @@
99186 */
99187 if( cnt==0 && zTab==0 ){
99188 assert( pExpr->op==TK_ID );
99189 if( ExprHasProperty(pExpr,EP_DblQuoted)
99190 && areDoubleQuotedStringsEnabled(db, pTopNC)
99191 && (db->init.bDropColumn==0 || sqlite3StrICmp(zCol, db->init.azInit[0])!=0)
99192 ){
99193 /* If a double-quoted identifier does not match any known column name,
99194 ** then treat it as a string.
99195 **
99196 ** This hack was added in the early days of SQLite in a misguided attempt
@@ -99201,15 +99263,10 @@
99201 ** programmers. To all those frustrated programmers, my apologies.
99202 **
99203 ** Someday, I hope to get rid of this hack. Unfortunately there is
99204 ** a huge amount of legacy SQL that uses it. So for now, we just
99205 ** issue a warning.
99206 **
99207 ** 2021-03-15: ticket 1c24a659e6d7f3a1
99208 ** Do not do the ID-to-STRING conversion when doing the schema
99209 ** sanity check following a DROP COLUMN if the identifer name matches
99210 ** the name of the column being dropped.
99211 */
99212 sqlite3_log(SQLITE_WARNING,
99213 "double-quoted string literal: \"%w\"", zCol);
99214 #ifdef SQLITE_ENABLE_NORMALIZE
99215 sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
@@ -101259,10 +101316,11 @@
101259 int nLeft = sqlite3ExprVectorSize(pLeft);
101260 int i;
101261 int regLeft = 0;
101262 int regRight = 0;
101263 u8 opx = op;
 
101264 int addrDone = sqlite3VdbeMakeLabel(pParse);
101265 int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
101266
101267 assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
101268 if( pParse->nErr ) return;
@@ -101278,53 +101336,62 @@
101278 assert( pExpr->op==op || (pExpr->op==TK_IS && op==TK_EQ)
101279 || (pExpr->op==TK_ISNOT && op==TK_NE) );
101280 assert( p5==0 || pExpr->op!=op );
101281 assert( p5==SQLITE_NULLEQ || pExpr->op==op );
101282
101283 p5 |= SQLITE_STOREP2;
101284 if( opx==TK_LE ) opx = TK_LT;
101285 if( opx==TK_GE ) opx = TK_GT;
101286
101287 regLeft = exprCodeSubselect(pParse, pLeft);
101288 regRight = exprCodeSubselect(pParse, pRight);
101289
 
101290 for(i=0; 1 /*Loop exits by "break"*/; i++){
101291 int regFree1 = 0, regFree2 = 0;
101292 Expr *pL, *pR;
101293 int r1, r2;
101294 assert( i>=0 && i<nLeft );
 
101295 r1 = exprVectorRegister(pParse, pLeft, i, regLeft, &pL, &regFree1);
101296 r2 = exprVectorRegister(pParse, pRight, i, regRight, &pR, &regFree2);
101297 codeCompare(pParse, pL, pR, opx, r1, r2, dest, p5, isCommuted);
 
101298 testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
101299 testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
101300 testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
101301 testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
101302 testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
101303 testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
101304 sqlite3ReleaseTempReg(pParse, regFree1);
101305 sqlite3ReleaseTempReg(pParse, regFree2);
 
 
 
 
 
 
 
 
 
 
101306 if( i==nLeft-1 ){
101307 break;
101308 }
101309 if( opx==TK_EQ ){
101310 sqlite3VdbeAddOp2(v, OP_IfNot, dest, addrDone); VdbeCoverage(v);
101311 p5 |= SQLITE_KEEPNULL;
101312 }else if( opx==TK_NE ){
101313 sqlite3VdbeAddOp2(v, OP_If, dest, addrDone); VdbeCoverage(v);
101314 p5 |= SQLITE_KEEPNULL;
101315 }else{
101316 assert( op==TK_LT || op==TK_GT || op==TK_LE || op==TK_GE );
101317 sqlite3VdbeAddOp2(v, OP_ElseNotEq, 0, addrDone);
101318 VdbeCoverageIf(v, op==TK_LT);
101319 VdbeCoverageIf(v, op==TK_GT);
101320 VdbeCoverageIf(v, op==TK_LE);
101321 VdbeCoverageIf(v, op==TK_GE);
101322 if( i==nLeft-2 ) opx = op;
101323 }
101324 }
 
101325 sqlite3VdbeResolveLabel(v, addrDone);
 
 
 
101326 }
101327
101328 #if SQLITE_MAX_EXPR_DEPTH>0
101329 /*
101330 ** Check that argument nHeight is less than or equal to the maximum
@@ -102142,10 +102209,11 @@
102142 assert( db!=0 );
102143 if( p==0 ) return 0;
102144 pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p));
102145 if( pNew==0 ) return 0;
102146 pNew->nExpr = p->nExpr;
 
102147 pItem = pNew->a;
102148 pOldItem = p->a;
102149 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
102150 Expr *pOldExpr = pOldItem->pExpr;
102151 Expr *pNewExpr;
@@ -102314,45 +102382,68 @@
102314 **
102315 ** If a memory allocation error occurs, the entire list is freed and
102316 ** NULL is returned. If non-NULL is returned, then it is guaranteed
102317 ** that the new entry was successfully appended.
102318 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102319 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
102320 Parse *pParse, /* Parsing context */
102321 ExprList *pList, /* List to which to append. Might be NULL */
102322 Expr *pExpr /* Expression to be appended. Might be NULL */
102323 ){
102324 struct ExprList_item *pItem;
102325 sqlite3 *db = pParse->db;
102326 assert( db!=0 );
102327 if( pList==0 ){
102328 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
102329 if( pList==0 ){
102330 goto no_mem;
102331 }
102332 pList->nExpr = 0;
102333 }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
102334 ExprList *pNew;
102335 pNew = sqlite3DbRealloc(db, pList,
102336 sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
102337 if( pNew==0 ){
102338 goto no_mem;
102339 }
102340 pList = pNew;
102341 }
102342 pItem = &pList->a[pList->nExpr++];
102343 assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) );
102344 assert( offsetof(struct ExprList_item,pExpr)==0 );
102345 memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName));
102346 pItem->pExpr = pExpr;
102347 return pList;
102348
102349 no_mem:
102350 /* Avoid leaking memory if malloc has failed. */
102351 sqlite3ExprDelete(db, pExpr);
102352 sqlite3ExprListDelete(db, pList);
102353 return 0;
102354 }
102355
102356 /*
102357 ** pColumns and pExpr form a vector assignment which is part of the SET
102358 ** clause of an UPDATE statement. Like this:
@@ -104003,10 +104094,11 @@
104003 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
104004 }
104005 if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
104006 for(i=0; i<nVector; i++){
104007 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
 
104008 if( sqlite3ExprCanBeNull(p) ){
104009 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
104010 VdbeCoverage(v);
104011 }
104012 }
@@ -104694,19 +104786,25 @@
104694 if( sqlite3ExprIsVector(pLeft) ){
104695 codeVectorCompare(pParse, pExpr, target, op, p5);
104696 }else{
104697 r1 = sqlite3ExprCodeTemp(pParse, pLeft, &regFree1);
104698 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
104699 codeCompare(pParse, pLeft, pExpr->pRight, op,
104700 r1, r2, inReg, SQLITE_STOREP2 | p5,
 
104701 ExprHasProperty(pExpr,EP_Commuted));
104702 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
104703 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
104704 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
104705 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
104706 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
104707 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
 
 
 
 
 
104708 testcase( regFree1==0 );
104709 testcase( regFree2==0 );
104710 }
104711 break;
104712 }
@@ -106820,31 +106918,55 @@
106820 static void renameTestSchema(
106821 Parse *pParse, /* Parse context */
106822 const char *zDb, /* Name of db to verify schema of */
106823 int bTemp, /* True if this is the temp db */
106824 const char *zWhen, /* "when" part of error message */
106825 const char *zDropColumn /* Name of column being dropped */
106826 ){
106827 pParse->colNamesSet = 1;
106828 sqlite3NestedParse(pParse,
106829 "SELECT 1 "
106830 "FROM \"%w\"." DFLT_SCHEMA_TABLE " "
106831 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106832 " AND sql NOT LIKE 'create virtual%%'"
106833 " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %Q)=NULL ",
106834 zDb,
106835 zDb, bTemp, zWhen, zDropColumn
106836 );
106837
106838 if( bTemp==0 ){
106839 sqlite3NestedParse(pParse,
106840 "SELECT 1 "
106841 "FROM temp." DFLT_SCHEMA_TABLE " "
106842 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106843 " AND sql NOT LIKE 'create virtual%%'"
106844 " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %Q)=NULL ",
106845 zDb, zWhen, zDropColumn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106846 );
106847 }
106848 }
106849
106850 /*
@@ -107003,11 +107125,11 @@
107003 sqlite3NestedParse(pParse,
107004 "UPDATE sqlite_temp_schema SET "
107005 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
107006 "tbl_name = "
107007 "CASE WHEN tbl_name=%Q COLLATE nocase AND "
107008 " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename',0) "
107009 "THEN %Q ELSE tbl_name END "
107010 "WHERE type IN ('view', 'trigger')"
107011 , zDb, zTabName, zName, zTabName, zDb, zName);
107012 }
107013
@@ -107361,10 +107483,14 @@
107361 }
107362 if( iCol==pTab->nCol ){
107363 sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
107364 goto exit_rename_column;
107365 }
 
 
 
 
107366
107367 /* Do the rename operation using a recursive UPDATE statement that
107368 ** uses the sqlite_rename_column() SQL function to compute the new
107369 ** CREATE statement text for the sqlite_schema table.
107370 */
@@ -107391,11 +107517,11 @@
107391 zDb, pTab->zName, iCol, zNew, bQuote
107392 );
107393
107394 /* Drop and reload the database schema. */
107395 renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename);
107396 renameTestSchema(pParse, zDb, iSchema==1, "after rename", 0);
107397
107398 exit_rename_column:
107399 sqlite3SrcListDelete(db, pSrc);
107400 sqlite3DbFree(db, zOld);
107401 sqlite3DbFree(db, zNew);
@@ -107815,21 +107941,16 @@
107815 static int renameParseSql(
107816 Parse *p, /* Memory to use for Parse object */
107817 const char *zDb, /* Name of schema SQL belongs to */
107818 sqlite3 *db, /* Database handle */
107819 const char *zSql, /* SQL to parse */
107820 int bTemp, /* True if SQL is from temp schema */
107821 const char *zDropColumn /* Name of column being dropped */
107822 ){
107823 int rc;
107824 char *zErr = 0;
107825
107826 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
107827 if( zDropColumn ){
107828 db->init.bDropColumn = 1;
107829 db->init.azInit = (char**)&zDropColumn;
107830 }
107831
107832 /* Parse the SQL statement passed as the first argument. If no error
107833 ** occurs and the parse does not result in a new table, index or
107834 ** trigger object, the database must be corrupt. */
107835 memset(p, 0, sizeof(Parse));
@@ -107858,11 +107979,10 @@
107858 }
107859 }
107860 #endif
107861
107862 db->init.iDb = 0;
107863 db->init.bDropColumn = 0;
107864 return rc;
107865 }
107866
107867 /*
107868 ** This function edits SQL statement zSql, replacing each token identified
@@ -107882,51 +108002,76 @@
107882 ){
107883 int nNew = sqlite3Strlen30(zNew);
107884 int nSql = sqlite3Strlen30(zSql);
107885 sqlite3 *db = sqlite3_context_db_handle(pCtx);
107886 int rc = SQLITE_OK;
107887 char *zQuot;
107888 char *zOut;
107889 int nQuot;
107890
107891 /* Set zQuot to point to a buffer containing a quoted copy of the
107892 ** identifier zNew. If the corresponding identifier in the original
107893 ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
107894 ** point to zQuot so that all substitutions are made using the
107895 ** quoted version of the new column name. */
107896 zQuot = sqlite3MPrintf(db, "\"%w\"", zNew);
107897 if( zQuot==0 ){
107898 return SQLITE_NOMEM;
107899 }else{
107900 nQuot = sqlite3Strlen30(zQuot);
107901 }
107902 if( bQuote ){
107903 zNew = zQuot;
107904 nNew = nQuot;
 
 
 
 
 
 
 
 
 
107905 }
107906
107907 /* At this point pRename->pList contains a list of RenameToken objects
107908 ** corresponding to all tokens in the input SQL that must be replaced
107909 ** with the new column name. All that remains is to construct and
107910 ** return the edited SQL string. */
107911 assert( nQuot>=nNew );
107912 zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1);
107913 if( zOut ){
107914 int nOut = nSql;
107915 memcpy(zOut, zSql, nSql);
107916 while( pRename->pList ){
107917 int iOff; /* Offset of token to replace in zOut */
107918 RenameToken *pBest = renameColumnTokenNext(pRename);
107919
107920 u32 nReplace;
107921 const char *zReplace;
107922 if( sqlite3IsIdChar(*pBest->t.z) ){
107923 nReplace = nNew;
107924 zReplace = zNew;
 
 
 
 
 
 
 
 
107925 }else{
107926 nReplace = nQuot;
107927 zReplace = zQuot;
 
 
 
 
 
 
 
 
 
 
 
 
107928 }
107929
107930 iOff = pBest->t.z - zSql;
107931 if( pBest->t.n!=nReplace ){
107932 memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n],
@@ -108160,11 +108305,11 @@
108160 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
108161
108162 #ifndef SQLITE_OMIT_AUTHORIZATION
108163 db->xAuth = 0;
108164 #endif
108165 rc = renameParseSql(&sParse, zDb, db, zSql, bTemp, 0);
108166
108167 /* Find tokens that need to be replaced. */
108168 memset(&sWalker, 0, sizeof(Walker));
108169 sWalker.pParse = &sParse;
108170 sWalker.xExprCallback = renameColumnExprCb;
@@ -108364,11 +108509,11 @@
108364 sWalker.pParse = &sParse;
108365 sWalker.xExprCallback = renameTableExprCb;
108366 sWalker.xSelectCallback = renameTableSelectCb;
108367 sWalker.u.pRename = &sCtx;
108368
108369 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, 0);
108370
108371 if( rc==SQLITE_OK ){
108372 int isLegacy = (db->flags & SQLITE_LegacyAlter);
108373 if( sParse.pNewTable ){
108374 Table *pTab = sParse.pNewTable;
@@ -108466,10 +108611,123 @@
108466 #endif
108467 }
108468
108469 return;
108470 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108471
108472 /*
108473 ** An SQL user function that checks that there are no parse or symbol
108474 ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
108475 ** After an ALTER TABLE .. RENAME operation is performed and the schema
@@ -108480,11 +108738,11 @@
108480 ** 1: SQL statement.
108481 ** 2: Object type ("view", "table", "trigger" or "index").
108482 ** 3: Object name.
108483 ** 4: True if object is from temp schema.
108484 ** 5: "when" part of error message.
108485 ** 6: Name of column being dropped, or NULL.
108486 **
108487 ** Unless it finds an error, this function normally returns NULL. However, it
108488 ** returns integer value 1 if:
108489 **
108490 ** * the SQL argument creates a trigger, and
@@ -108499,22 +108757,26 @@
108499 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
108500 char const *zInput = (const char*)sqlite3_value_text(argv[1]);
108501 int bTemp = sqlite3_value_int(argv[4]);
108502 int isLegacy = (db->flags & SQLITE_LegacyAlter);
108503 char const *zWhen = (const char*)sqlite3_value_text(argv[5]);
108504 char const *zDropColumn = (const char*)sqlite3_value_text(argv[6]);
108505
108506 #ifndef SQLITE_OMIT_AUTHORIZATION
108507 sqlite3_xauth xAuth = db->xAuth;
108508 db->xAuth = 0;
108509 #endif
108510
108511 UNUSED_PARAMETER(NotUsed);
 
108512 if( zDb && zInput ){
108513 int rc;
108514 Parse sParse;
108515 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, zDropColumn);
 
 
 
108516 if( rc==SQLITE_OK ){
108517 if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
108518 NameContext sNC;
108519 memset(&sNC, 0, sizeof(sNC));
108520 sNC.pParse = &sParse;
@@ -108578,11 +108840,11 @@
108578 sqlite3_xauth xAuth = db->xAuth;
108579 db->xAuth = 0;
108580 #endif
108581
108582 UNUSED_PARAMETER(NotUsed);
108583 rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1, 0);
108584 if( rc!=SQLITE_OK ) goto drop_column_done;
108585 pTab = sParse.pNewTable;
108586 if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
108587 /* This can happen if the sqlite_schema table is corrupt */
108588 rc = SQLITE_CORRUPT_BKPT;
@@ -108672,20 +108934,21 @@
108672 /* Edit the sqlite_schema table */
108673 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108674 assert( iDb>=0 );
108675 zDb = db->aDb[iDb].zDbSName;
108676 renameTestSchema(pParse, zDb, iDb==1, "", 0);
 
108677 sqlite3NestedParse(pParse,
108678 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108679 "sql = sqlite_drop_column(%d, sql, %d) "
108680 "WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
108681 , zDb, iDb, iCol, pTab->zName
108682 );
108683
108684 /* Drop and reload the database schema. */
108685 renameReloadSchema(pParse, iDb, INITFLAG_AlterDrop);
108686 renameTestSchema(pParse, zDb, iDb==1, "after drop column", zCol);
108687
108688 /* Edit rows of table on disk */
108689 if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
108690 int i;
108691 int addr;
@@ -108697,31 +108960,37 @@
108697 Vdbe *v = sqlite3GetVdbe(pParse);
108698 iCur = pParse->nTab++;
108699 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
108700 addr = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
108701 reg = ++pParse->nMem;
108702 pParse->nMem += pTab->nCol;
108703 if( HasRowid(pTab) ){
108704 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, reg);
 
108705 }else{
108706 pPk = sqlite3PrimaryKeyIndex(pTab);
 
 
 
 
 
108707 }
 
108708 for(i=0; i<pTab->nCol; i++){
108709 if( i!=iCol && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
108710 int regOut;
108711 if( pPk ){
108712 int iPos = sqlite3TableColumnToIndex(pPk, i);
108713 int iColPos = sqlite3TableColumnToIndex(pPk, iCol);
 
108714 regOut = reg+1+iPos-(iPos>iColPos);
108715 }else{
108716 regOut = reg+1+nField;
108717 }
108718 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
108719 nField++;
108720 }
108721 }
108722 regRec = reg + pTab->nCol;
108723 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
108724 if( pPk ){
108725 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
108726 }else{
108727 sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg);
@@ -108743,10 +109012,11 @@
108743 static FuncDef aAlterTableFuncs[] = {
108744 INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc),
108745 INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc),
108746 INTERNAL_FUNCTION(sqlite_rename_test, 7, renameTableTest),
108747 INTERNAL_FUNCTION(sqlite_drop_column, 3, dropColumnFunc),
 
108748 };
108749 sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs));
108750 }
108751 #endif /* SQLITE_ALTER_TABLE */
108752
@@ -112737,21 +113007,10 @@
112737 pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
112738 #endif
112739 assert( pParse->pNewTable==0 );
112740 pParse->pNewTable = pTable;
112741
112742 /* If this is the magic sqlite_sequence table used by autoincrement,
112743 ** then record a pointer to this table in the main database structure
112744 ** so that INSERT can find the table easily.
112745 */
112746 #ifndef SQLITE_OMIT_AUTOINCREMENT
112747 if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
112748 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
112749 pTable->pSchema->pSeqTab = pTable;
112750 }
112751 #endif
112752
112753 /* Begin generating the code that will insert the table record into
112754 ** the schema table. Note in particular that we must go ahead
112755 ** and allocate the record number for the table entry now. Before any
112756 ** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
112757 ** indices to be created and the table record must come before the
@@ -114192,11 +114451,11 @@
114192
114193 #ifndef SQLITE_OMIT_AUTOINCREMENT
114194 /* Check to see if we need to create an sqlite_sequence table for
114195 ** keeping track of autoincrement keys.
114196 */
114197 if( (p->tabFlags & TF_Autoincrement)!=0 ){
114198 Db *pDb = &db->aDb[iDb];
114199 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114200 if( pDb->pSchema->pSeqTab==0 ){
114201 sqlite3NestedParse(pParse,
114202 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
@@ -114223,10 +114482,21 @@
114223 sqlite3OomFault(db);
114224 return;
114225 }
114226 pParse->pNewTable = 0;
114227 db->mDbFlags |= DBFLAG_SchemaChange;
 
 
 
 
 
 
 
 
 
 
 
114228 }
114229
114230 #ifndef SQLITE_OMIT_ALTERTABLE
114231 if( !pSelect && !p->pSelect ){
114232 assert( pCons && pEnd );
@@ -114266,10 +114536,20 @@
114266 goto create_view_fail;
114267 }
114268 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
114269 p = pParse->pNewTable;
114270 if( p==0 || pParse->nErr ) goto create_view_fail;
 
 
 
 
 
 
 
 
 
 
114271 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
114272 iDb = sqlite3SchemaToIndex(db, p->pSchema);
114273 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
114274 if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
114275
@@ -115827,11 +116107,11 @@
115827 goto exit_drop_index;
115828 }
115829 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
115830 if( pIndex==0 ){
115831 if( !ifExists ){
115832 sqlite3ErrorMsg(pParse, "no such index: %S", pName, 0);
115833 }else{
115834 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
115835 }
115836 pParse->checkSchema = 1;
115837 goto exit_drop_index;
@@ -122970,11 +123250,11 @@
122970 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
122971 ipkColumn = i;
122972 bIdListInOrder = 0;
122973 }else{
122974 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
122975 pTabList, 0, pColumn->a[i].zName);
122976 pParse->checkSchema = 1;
122977 goto insert_cleanup;
122978 }
122979 }
122980 }
@@ -123098,11 +123378,11 @@
123098 }
123099 }
123100 if( nColumn!=(pTab->nCol-nHidden) ){
123101 sqlite3ErrorMsg(pParse,
123102 "table %S has %d columns but %d values were supplied",
123103 pTabList, 0, pTab->nCol-nHidden, nColumn);
123104 goto insert_cleanup;
123105 }
123106 }
123107 if( pColumn!=0 && nColumn!=pColumn->nId ){
123108 sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
@@ -123401,11 +123681,11 @@
123401 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
123402 sqlite3MayAbort(pParse);
123403 }else
123404 #endif
123405 {
123406 int isReplace; /* Set to true if constraints may cause a replace */
123407 int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
123408 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
123409 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
123410 );
123411 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
@@ -123421,10 +123701,17 @@
123421 bUseSeek = (isReplace==0 || !sqlite3VdbeHasSubProgram(v));
123422 sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
123423 regIns, aRegIdx, 0, appendFlag, bUseSeek
123424 );
123425 }
 
 
 
 
 
 
 
123426 }
123427
123428 /* Update the count of rows that are inserted
123429 */
123430 if( regRowCount ){
@@ -130625,10 +130912,11 @@
130625 ** will be closed immediately after reading the meta-value. */
130626 if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_NONE ){
130627 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
130628 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
130629 sqlite3OomFault(db);
 
130630 }
130631 if( rc!=SQLITE_OK ) return;
130632 openedTransaction = 1;
130633 }
130634
@@ -130860,10 +131148,11 @@
130860 if( db->init.busy==0 ){
130861 sqlite3VdbeSetSql(sParse.pVdbe, zSql, (int)(sParse.zTail-zSql), prepFlags);
130862 }
130863 if( db->mallocFailed ){
130864 sParse.rc = SQLITE_NOMEM_BKPT;
 
130865 }
130866 if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
130867 if( sParse.checkSchema ){
130868 schemaIsValid(&sParse);
130869 }
@@ -131884,35 +132173,159 @@
131884 VdbeComment((v, "OFFSET"));
131885 }
131886 }
131887
131888 /*
131889 ** Add code that will check to make sure the N registers starting at iMem
131890 ** form a distinct entry. iTab is a sorting index that holds previously
131891 ** seen combinations of the N values. A new entry is made in iTab
131892 ** if the current N values are new.
 
131893 **
131894 ** A jump to addrRepeat is made and the N+1 values are popped from the
131895 ** stack if the top N elements are not distinct.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131896 */
131897 static void codeDistinct(
131898 Parse *pParse, /* Parsing and code generating context */
 
131899 int iTab, /* A sorting index used to test for distinctness */
131900 int addrRepeat, /* Jump to here if not distinct */
131901 int N, /* Number of elements */
131902 int iMem /* First element */
131903 ){
131904 Vdbe *v;
131905 int r1;
131906
131907 v = pParse->pVdbe;
131908 r1 = sqlite3GetTempReg(pParse);
131909 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
131910 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
131911 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N);
131912 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
131913 sqlite3ReleaseTempReg(pParse, r1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131914 }
131915
131916 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
131917 /*
131918 ** This function is called as part of inner-loop generation for a SELECT
@@ -132156,63 +132569,15 @@
132156 /* If the DISTINCT keyword was present on the SELECT statement
132157 ** and this row has been seen before, then do not make this row
132158 ** part of the result.
132159 */
132160 if( hasDistinct ){
132161 switch( pDistinct->eTnctType ){
132162 case WHERE_DISTINCT_ORDERED: {
132163 VdbeOp *pOp; /* No longer required OpenEphemeral instr. */
132164 int iJump; /* Jump destination */
132165 int regPrev; /* Previous row content */
132166
132167 /* Allocate space for the previous row */
132168 regPrev = pParse->nMem+1;
132169 pParse->nMem += nResultCol;
132170
132171 /* Change the OP_OpenEphemeral coded earlier to an OP_Null
132172 ** sets the MEM_Cleared bit on the first register of the
132173 ** previous value. This will cause the OP_Ne below to always
132174 ** fail on the first iteration of the loop even if the first
132175 ** row is all NULLs.
132176 */
132177 sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
132178 pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);
132179 pOp->opcode = OP_Null;
132180 pOp->p1 = 1;
132181 pOp->p2 = regPrev;
132182 pOp = 0; /* Ensure pOp is not used after sqlite3VdbeAddOp() */
132183
132184 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
132185 for(i=0; i<nResultCol; i++){
132186 CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr);
132187 if( i<nResultCol-1 ){
132188 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
132189 VdbeCoverage(v);
132190 }else{
132191 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
132192 VdbeCoverage(v);
132193 }
132194 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
132195 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
132196 }
132197 assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );
132198 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
132199 break;
132200 }
132201
132202 case WHERE_DISTINCT_UNIQUE: {
132203 sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
132204 break;
132205 }
132206
132207 default: {
132208 assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED );
132209 codeDistinct(pParse, pDistinct->tabTnct, iContinue, nResultCol,
132210 regResult);
132211 break;
132212 }
132213 }
132214 if( pSort==0 ){
132215 codeOffset(v, p->iOffset, iContinue);
132216 }
132217 }
132218
@@ -132874,11 +133239,17 @@
132874 if( pS ){
132875 /* The "table" is actually a sub-select or a view in the FROM clause
132876 ** of the SELECT statement. Return the declaration type and origin
132877 ** data for the result-set column of the sub-select.
132878 */
132879 if( iCol>=0 && iCol<pS->pEList->nExpr ){
 
 
 
 
 
 
132880 /* If iCol is less than zero, then the expression requests the
132881 ** rowid of the sub-select or view. This expression is legal (see
132882 ** test case misc2.2.2) - it always evaluates to NULL.
132883 */
132884 NameContext sNC;
@@ -133804,11 +134175,11 @@
133804 /* Generate code for the left and right SELECT statements.
133805 */
133806 switch( p->op ){
133807 case TK_ALL: {
133808 int addr = 0;
133809 int nLimit;
133810 assert( !pPrior->pLimit );
133811 pPrior->iLimit = p->iLimit;
133812 pPrior->iOffset = p->iOffset;
133813 pPrior->pLimit = p->pLimit;
133814 rc = sqlite3Select(pParse, pPrior, &dest);
@@ -134660,13 +135031,16 @@
134660 }
134661 if( pExpr->op==TK_COLUMN
134662 && pExpr->iTable==pSubst->iTable
134663 && !ExprHasProperty(pExpr, EP_FixedCol)
134664 ){
 
134665 if( pExpr->iColumn<0 ){
134666 pExpr->op = TK_NULL;
134667 }else{
 
 
134668 Expr *pNew;
134669 Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
134670 Expr ifNullRow;
134671 assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
134672 assert( pExpr->pRight==0 );
@@ -136301,11 +136675,17 @@
136301 }
136302 while( pSel->pPrior ){ pSel = pSel->pPrior; }
136303 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
136304 pTab->iPKey = -1;
136305 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
136306 pTab->tabFlags |= TF_Ephemeral;
 
 
 
 
 
 
136307
136308 return pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
136309 }
136310
136311 /*
@@ -136788,12 +137168,14 @@
136788 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
136789 "argument");
136790 pFunc->iDistinct = -1;
136791 }else{
136792 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pE->x.pList,0,0);
136793 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0,
136794 (char*)pKeyInfo, P4_KEYINFO);
 
 
136795 }
136796 }
136797 }
136798 }
136799
@@ -136821,11 +137203,16 @@
136821 ** If regAcc is non-zero and there are no min() or max() aggregates
136822 ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
136823 ** registers if register regAcc contains 0. The caller will take care
136824 ** of setting and clearing regAcc.
136825 */
136826 static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
 
 
 
 
 
136827 Vdbe *v = pParse->pVdbe;
136828 int i;
136829 int regHit = 0;
136830 int addrHitTest = 0;
136831 struct AggInfo_func *pF;
@@ -136867,17 +137254,16 @@
136867 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
136868 }else{
136869 nArg = 0;
136870 regAgg = 0;
136871 }
136872 if( pF->iDistinct>=0 ){
136873 if( addrNext==0 ){
136874 addrNext = sqlite3VdbeMakeLabel(pParse);
136875 }
136876 testcase( nArg==0 ); /* Error condition */
136877 testcase( nArg>1 ); /* Also an error */
136878 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
136879 }
136880 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
136881 CollSeq *pColl = 0;
136882 struct ExprList_item *pItem;
136883 int j;
@@ -136925,11 +137311,11 @@
136925 Table *pTab, /* Table being queried */
136926 Index *pIdx /* Index used to optimize scan, or NULL */
136927 ){
136928 if( pParse->explain==2 ){
136929 int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
136930 sqlite3VdbeExplain(pParse, 0, "SCAN TABLE %s%s%s",
136931 pTab->zName,
136932 bCover ? " USING COVERING INDEX " : "",
136933 bCover ? pIdx->zName : ""
136934 );
136935 }
@@ -137498,14 +137884,14 @@
137498 */
137499 int addrTop = sqlite3VdbeCurrentAddr(v)+1;
137500
137501 pItem->regReturn = ++pParse->nMem;
137502 sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
137503 VdbeComment((v, "%s", pItem->pTab->zName));
137504 pItem->addrFillSub = addrTop;
137505 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
137506 ExplainQueryPlan((pParse, 1, "CO-ROUTINE %u", pSub->selId));
137507 sqlite3Select(pParse, pSub, &dest);
137508 pItem->pTab->nRowLogEst = pSub->nSelectRow;
137509 pItem->fg.viaCoroutine = 1;
137510 pItem->regResult = dest.iSdst;
137511 sqlite3VdbeEndCoroutine(v, pItem->regReturn);
@@ -137545,21 +137931,21 @@
137545 if( pItem->fg.isCorrelated==0 ){
137546 /* If the subquery is not correlated and if we are not inside of
137547 ** a trigger, then we only need to compute the value of the subquery
137548 ** once. */
137549 onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
137550 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
137551 }else{
137552 VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
137553 }
137554 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
137555 ExplainQueryPlan((pParse, 1, "MATERIALIZE %u", pSub->selId));
137556 sqlite3Select(pParse, pSub, &dest);
137557 pItem->pTab->nRowLogEst = pSub->nSelectRow;
137558 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
137559 retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
137560 VdbeComment((v, "end %s", pItem->pTab->zName));
137561 sqlite3VdbeChangeP1(v, topAddr, retAddr);
137562 sqlite3ClearTempRegCache(pParse);
137563 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
137564 CteUse *pCteUse = pItem->u2.pCteUse;
137565 pCteUse->addrM9e = pItem->addrFillSub;
@@ -137905,10 +138291,24 @@
137905 int addrSetAbort; /* Set the abort flag and return */
137906 int addrTopOfLoop; /* Top of the input loop */
137907 int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */
137908 int addrReset; /* Subroutine for resetting the accumulator */
137909 int regReset; /* Return address register for reset subroutine */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137910
137911 /* If there is a GROUP BY clause we might need a sorting index to
137912 ** implement it. Allocate that sorting index now. If it turns out
137913 ** that we do not need it after all, the OP_SorterOpen instruction
137914 ** will be converted into a Noop.
@@ -137941,14 +138341,16 @@
137941 ** it might be a single loop that uses an index to extract information
137942 ** in the right order to begin with.
137943 */
137944 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
137945 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
137946 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0,
137947 WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0), 0
137948 );
 
137949 if( pWInfo==0 ) goto select_end;
 
137950 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
137951 if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
137952 /* The optimizer is able to deliver rows in group by order so
137953 ** we do not have to sort. The OP_OpenEphemeral table will be
137954 ** cancelled later because we still need to use the pKeyInfo
@@ -138062,11 +138464,11 @@
138062
138063 /* Update the aggregate accumulators based on the content of
138064 ** the current row
138065 */
138066 sqlite3VdbeJumpHere(v, addr1);
138067 updateAccumulator(pParse, iUseFlag, pAggInfo);
138068 sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
138069 VdbeComment((v, "indicate data in accumulator"));
138070
138071 /* End of the loop
138072 */
@@ -138119,10 +138521,14 @@
138119 resetAccumulator(pParse, pAggInfo);
138120 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
138121 VdbeComment((v, "indicate accumulator empty"));
138122 sqlite3VdbeAddOp1(v, OP_Return, regReset);
138123
 
 
 
 
138124 } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
138125 else {
138126 Table *pTab;
138127 if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
138128 /* If isSimpleCount() returns a pointer to a Table structure, then
@@ -138182,10 +138588,13 @@
138182 sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
138183 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
138184 explainSimpleCount(pParse, pTab, pBest);
138185 }else{
138186 int regAcc = 0; /* "populate accumulators" flag */
 
 
 
138187
138188 /* If there are accumulator registers but no min() or max() functions
138189 ** without FILTER clauses, allocate register regAcc. Register regAcc
138190 ** will contain 0 the first time the inner loop runs, and 1 thereafter.
138191 ** The code generated by updateAccumulator() uses this to ensure
@@ -138205,10 +138614,13 @@
138205 }
138206 if( i==pAggInfo->nFunc ){
138207 regAcc = ++pParse->nMem;
138208 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
138209 }
 
 
 
138210 }
138211
138212 /* This case runs if the aggregate has no GROUP BY clause. The
138213 ** processing is much simpler since there is only a single row
138214 ** of output.
@@ -138224,16 +138636,22 @@
138224 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
138225 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
138226
138227 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
138228 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
138229 0, minMaxFlag, 0);
138230 if( pWInfo==0 ){
138231 goto select_end;
138232 }
138233 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
138234 updateAccumulator(pParse, regAcc, pAggInfo);
 
 
 
 
 
 
138235 if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
138236 if( minMaxFlag ){
138237 sqlite3WhereMinMaxOptEarlyOut(v, pWInfo);
138238 }
138239 SELECTTRACE(1,pParse,p,("WhereEnd\n"));
@@ -138576,11 +138994,15 @@
138576 if( pTrig->pTabSchema==pTab->pSchema
138577 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
138578 ){
138579 pTrig->pNext = pList;
138580 pList = pTrig;
138581 }else if( pTrig->op==TK_RETURNING ){
 
 
 
 
138582 assert( pParse->bReturning );
138583 assert( &(pParse->u1.pReturning->retTrig) == pTrig );
138584 pTrig->table = pTab->zName;
138585 pTrig->pTabSchema = pTab->pSchema;
138586 pTrig->pNext = pList;
@@ -138716,16 +139138,16 @@
138716 /* INSTEAD of triggers are only for views and views only support INSTEAD
138717 ** of triggers.
138718 */
138719 if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
138720 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
138721 (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0);
138722 goto trigger_orphan_error;
138723 }
138724 if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
138725 sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
138726 " trigger on table: %S", pTableName, 0);
138727 goto trigger_orphan_error;
138728 }
138729
138730 #ifndef SQLITE_OMIT_AUTHORIZATION
138731 if( !IN_RENAME_OBJECT ){
@@ -139118,11 +139540,11 @@
139118 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
139119 if( pTrigger ) break;
139120 }
139121 if( !pTrigger ){
139122 if( !noErr ){
139123 sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
139124 }else{
139125 sqlite3CodeVerifyNamedSchema(pParse, zDb);
139126 }
139127 pParse->checkSchema = 1;
139128 goto drop_trigger_cleanup;
@@ -139650,12 +140072,12 @@
139650 /* If one was specified, code the WHEN clause. If it evaluates to false
139651 ** (or NULL) the sub-vdbe is immediately halted by jumping to the
139652 ** OP_Halt inserted at the end of the program. */
139653 if( pTrigger->pWhen ){
139654 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
139655 if( SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
139656 && db->mallocFailed==0
139657 ){
139658 iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
139659 sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
139660 }
139661 sqlite3ExprDelete(db, pWhen);
@@ -140709,11 +141131,16 @@
140709 }
140710 }
140711
140712 /* Top of the update loop */
140713 if( eOnePass!=ONEPASS_OFF ){
140714 if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
 
 
 
 
 
140715 assert( pPk );
140716 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey);
140717 VdbeCoverage(v);
140718 }
140719 if( eOnePass!=ONEPASS_SINGLE ){
@@ -144040,20 +144467,12 @@
144040 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
144041 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
144042 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
144043
144044 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
144045 sqlite3_str_appendall(&str, isSearch ? "SEARCH" : "SCAN");
144046 if( pItem->pSelect ){
144047 sqlite3_str_appendf(&str, " SUBQUERY %u", pItem->pSelect->selId);
144048 }else{
144049 sqlite3_str_appendf(&str, " TABLE %s", pItem->zName);
144050 }
144051
144052 if( pItem->zAlias ){
144053 sqlite3_str_appendf(&str, " AS %s", pItem->zAlias);
144054 }
144055 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
144056 const char *zFmt = 0;
144057 Index *pIdx;
144058
144059 assert( pLoop->u.btree.pIndex!=0 );
@@ -146348,10 +146767,11 @@
146348 testcase( pAlt->eOperator & WO_IN );
146349 VdbeModuleComment((v, "begin transitive constraint"));
146350 sEAlt = *pAlt->pExpr;
146351 sEAlt.pLeft = pE->pLeft;
146352 sqlite3ExprIfFalse(pParse, &sEAlt, addrCont, SQLITE_JUMPIFNULL);
 
146353 }
146354
146355 /* For a LEFT OUTER JOIN, generate code that will record the fact that
146356 ** at least one row of the right table has matched the left table.
146357 */
@@ -148784,11 +149204,11 @@
148784 const char *zColl = pIdx->azColl[iCol];
148785
148786 for(i=0; i<pList->nExpr; i++){
148787 Expr *p = sqlite3ExprSkipCollateAndLikely(pList->a[i].pExpr);
148788 if( ALWAYS(p!=0)
148789 && p->op==TK_COLUMN
148790 && p->iColumn==pIdx->aiColumn[iCol]
148791 && p->iTable==iBase
148792 ){
148793 CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);
148794 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
@@ -148849,11 +149269,12 @@
148849 ** current SELECT is a correlated sub-query.
148850 */
148851 for(i=0; i<pDistinct->nExpr; i++){
148852 Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
148853 if( NEVER(p==0) ) continue;
148854 if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
 
148855 }
148856
148857 /* Loop through all indices on the table, checking each to see if it makes
148858 ** the DISTINCT qualifier redundant. It does so if:
148859 **
@@ -148867,10 +149288,11 @@
148867 ** 3. All of those index columns for which the WHERE clause does not
148868 ** contain a "col=X" term are subject to a NOT NULL constraint.
148869 */
148870 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
148871 if( !IsUniqueIndex(pIdx) ) continue;
 
148872 for(i=0; i<pIdx->nKeyCol; i++){
148873 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
148874 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
148875 if( indexColumnNotNull(pIdx, i)==0 ) break;
148876 }
@@ -148921,18 +149343,18 @@
148921 pOp->opcode = OP_Copy;
148922 pOp->p1 = pOp->p2 + iRegister;
148923 pOp->p2 = pOp->p3;
148924 pOp->p3 = 0;
148925 }else if( pOp->opcode==OP_Rowid ){
148926 if( iAutoidxCur ){
148927 pOp->opcode = OP_Sequence;
148928 pOp->p1 = iAutoidxCur;
148929 }else{
148930 pOp->opcode = OP_Null;
148931 pOp->p1 = 0;
148932 pOp->p3 = 0;
148933 }
 
148934 }
148935 }
148936 }
148937
148938 /*
@@ -149093,11 +149515,11 @@
149093 pLoop->aLTerm[nKeyCol++] = pTerm;
149094 idxCols |= cMask;
149095 }
149096 }
149097 }
149098 assert( nKeyCol>0 );
149099 pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol;
149100 pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
149101 | WHERE_AUTO_INDEX;
149102
149103 /* Count the number of additional columns needed to create a
@@ -152114,11 +152536,11 @@
152114 */
152115 for(i=0; i<nOrderBy; i++){
152116 if( MASKBIT(i) & obSat ) continue;
152117 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
152118 if( NEVER(pOBExpr==0) ) continue;
152119 if( pOBExpr->op!=TK_COLUMN ) continue;
152120 if( pOBExpr->iTable!=iCur ) continue;
152121 pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
152122 ~ready, eqOpMask, 0);
152123 if( pTerm==0 ) continue;
152124 if( pTerm->eOperator==WO_IN ){
@@ -152243,11 +152665,11 @@
152243 testcase( wctrlFlags & WHERE_GROUPBY );
152244 testcase( wctrlFlags & WHERE_DISTINCTBY );
152245 if( NEVER(pOBExpr==0) ) continue;
152246 if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
152247 if( iColumn>=XN_ROWID ){
152248 if( pOBExpr->op!=TK_COLUMN ) continue;
152249 if( pOBExpr->iTable!=iCur ) continue;
152250 if( pOBExpr->iColumn!=iColumn ) continue;
152251 }else{
152252 Expr *pIdxExpr = pIndex->aColExpr->a[j].pExpr;
152253 if( sqlite3ExprCompareSkip(pOBExpr, pIdxExpr, iCur) ){
@@ -153344,11 +153766,12 @@
153344 ** LEFT JOIN t2
153345 ** LEFT JOIN t3 ON (t1.ipk=t3.ipk)
153346 */
153347 notReady = ~(Bitmask)0;
153348 if( pWInfo->nLevel>=2
153349 && pResultSet!=0 /* guarantees condition (1) above */
 
153350 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
153351 ){
153352 int i;
153353 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
153354 if( sWLB.pOrderBy ){
@@ -153857,11 +154280,11 @@
153857 assert( pOp->opcode!=OP_Rowid || pOp->p1!=pLevel->iTabCur );
153858 assert( pOp->opcode!=OP_IfNullRow || pOp->p1!=pLevel->iTabCur );
153859 #endif
153860 pOp = sqlite3VdbeGetOp(v, k);
153861 pLastOp = pOp + (last - k);
153862 assert( pOp<pLastOp || (pParse->nErr>0 && pOp==pLastOp) );
153863 do{
153864 if( pOp->p1!=pLevel->iTabCur ){
153865 /* no-op */
153866 }else if( pOp->opcode==OP_Column
153867 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
@@ -154709,10 +155132,11 @@
154709 /* no break */ deliberate_fall_through
154710
154711 case TK_AGG_FUNCTION:
154712 case TK_COLUMN: {
154713 int iCol = -1;
 
154714 if( p->pSub ){
154715 int i;
154716 for(i=0; i<p->pSub->nExpr; i++){
154717 if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
154718 iCol = i;
@@ -154818,13 +155242,18 @@
154818 ){
154819 if( pAppend ){
154820 int i;
154821 int nInit = pList ? pList->nExpr : 0;
154822 for(i=0; i<pAppend->nExpr; i++){
154823 Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
 
154824 assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
154825 if( bIntToNull && pDup ){
 
 
 
 
154826 int iDummy;
154827 Expr *pSub;
154828 for(pSub=pDup; ExprHasProperty(pSub, EP_Skip); pSub=pSub->pLeft){
154829 assert( pSub );
154830 }
@@ -155601,19 +156030,19 @@
155601 VdbeCoverage(v);
155602 sqlite3ReleaseTempReg(pParse, regTmp);
155603 }
155604
155605 if( pWin->bExprArgs ){
155606 int iStart = sqlite3VdbeCurrentAddr(v);
155607 VdbeOp *pOp, *pEnd;
155608
155609 nArg = pWin->pOwner->x.pList->nExpr;
155610 regArg = sqlite3GetTempRange(pParse, nArg);
155611 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
155612
155613 pEnd = sqlite3VdbeGetOp(v, -1);
155614 for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
155615 if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
155616 pOp->p1 = csr;
155617 }
155618 }
155619 }
@@ -155968,11 +156397,11 @@
155968 ** is OP_Ge, the generated code is equivalent to:
155969 **
155970 ** if( csr1.peerVal - regVal <= csr2.peerVal ) goto lbl;
155971 **
155972 ** A special type of arithmetic is used such that if csr1.peerVal is not
155973 ** a numeric type (real or integer), then the result of the addition addition
155974 ** or subtraction is a a copy of csr1.peerVal.
155975 */
155976 static void windowCodeRangeTest(
155977 WindowCodeArg *p,
155978 int op, /* OP_Ge, OP_Gt, or OP_Le */
@@ -155987,11 +156416,16 @@
155987 int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */
155988 int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */
155989 int regString = ++pParse->nMem; /* Reg. for constant value '' */
155990 int arith = OP_Add; /* OP_Add or OP_Subtract */
155991 int addrGe; /* Jump destination */
 
155992 CollSeq *pColl;
 
 
 
 
155993
155994 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
155995 assert( pOrderBy && pOrderBy->nExpr==1 );
155996 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
155997 switch( op ){
@@ -156000,38 +156434,15 @@
156000 default: assert( op==OP_Le ); op = OP_Ge; break;
156001 }
156002 arith = OP_Subtract;
156003 }
156004
156005 /* Read the peer-value from each cursor into a register */
156006 windowReadPeerValues(p, csr1, reg1);
156007 windowReadPeerValues(p, csr2, reg2);
156008
156009 VdbeModuleComment((v, "CodeRangeTest: if( R%d %s R%d %s R%d ) goto lbl",
156010 reg1, (arith==OP_Add ? "+" : "-"), regVal,
156011 ((op==OP_Ge) ? ">=" : (op==OP_Le) ? "<=" : (op==OP_Gt) ? ">" : "<"), reg2
156012 ));
156013
156014 /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
156015 ** This block adds (or subtracts for DESC) the numeric value in regVal
156016 ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
156017 ** then leave reg1 as it is. In pseudo-code, this is implemented as:
156018 **
156019 ** if( reg1>='' ) goto addrGe;
156020 ** reg1 = reg1 +/- regVal
156021 ** addrGe:
156022 **
156023 ** Since all strings and blobs are greater-than-or-equal-to an empty string,
156024 ** the add/subtract is skipped for these, as required. If reg1 is a NULL,
156025 ** then the arithmetic is performed, but since adding or subtracting from
156026 ** NULL is always NULL anyway, this case is handled as required too. */
156027 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
156028 addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
156029 VdbeCoverage(v);
156030 sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
156031 sqlite3VdbeJumpHere(v, addrGe);
156032
156033 /* If the BIGNULL flag is set for the ORDER BY, then it is required to
156034 ** consider NULL values to be larger than all other values, instead of
156035 ** the usual smaller. The VDBE opcodes OP_Ge and so on do not handle this
156036 ** (and adding that capability causes a performance regression), so
156037 ** instead if the BIGNULL flag is set then cases where either reg1 or
@@ -156064,27 +156475,50 @@
156064 sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl);
156065 VdbeCoverage(v);
156066 break;
156067 default: assert( op==OP_Lt ); /* no-op */ break;
156068 }
156069 sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3);
156070
156071 /* This block runs if reg1 is not NULL, but reg2 is. */
156072 sqlite3VdbeJumpHere(v, addr);
156073 sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
156074 if( op==OP_Gt || op==OP_Ge ){
156075 sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1);
156076 }
156077 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156078
156079 /* Compare registers reg2 and reg1, taking the jump if required. Note that
156080 ** control skips over this test if the BIGNULL flag is set and either
156081 ** reg1 or reg2 contain a NULL value. */
156082 sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
156083 pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr);
156084 sqlite3VdbeAppendP4(v, (void*)pColl, P4_COLLSEQ);
156085 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
 
156086
156087 assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
156088 testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
156089 testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
156090 testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
@@ -169758,11 +170192,11 @@
169758 /*
169759 ** The assert_fts3_nc() macro is similar to the assert() macro, except that it
169760 ** is used for assert() conditions that are true only if it can be
169761 ** guranteed that the database is not corrupt.
169762 */
169763 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
169764 SQLITE_API extern int sqlite3_fts3_may_be_corrupt;
169765 # define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
169766 #else
169767 # define assert_fts3_nc(x) assert(x)
169768 #endif
@@ -170314,11 +170748,13 @@
170314 ** This variable is set to false when running tests for which the on disk
170315 ** structures should not be corrupt. Otherwise, true. If it is false, extra
170316 ** assert() conditions in the fts3 code are activated - conditions that are
170317 ** only true if it is guaranteed that the fts3 database is not corrupt.
170318 */
 
170319 SQLITE_API int sqlite3_fts3_may_be_corrupt = 1;
 
170320
170321 /*
170322 ** Write a 64-bit variable-length integer to memory starting at p[0].
170323 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
170324 ** The number of bytes written is returned.
@@ -173574,18 +174010,24 @@
173574 /*
173575 ** Implementation of xBegin() method.
173576 */
173577 static int fts3BeginMethod(sqlite3_vtab *pVtab){
173578 Fts3Table *p = (Fts3Table*)pVtab;
 
173579 UNUSED_PARAMETER(pVtab);
173580 assert( p->pSegments==0 );
173581 assert( p->nPendingData==0 );
173582 assert( p->inTransaction!=1 );
173583 TESTONLY( p->inTransaction = 1 );
173584 TESTONLY( p->mxSavepoint = -1; );
173585 p->nLeafAdd = 0;
173586 return fts3SetHasStat(p);
 
 
 
 
 
 
 
173587 }
173588
173589 /*
173590 ** Implementation of xCommit() method. This is a no-op. The contents of
173591 ** the pending-terms hash-table have already been flushed into the database
@@ -195860,10 +196302,14 @@
195860 if( sqlite3_value_type(pVal)==SQLITE_BLOB
195861 && (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord))
195862 ){
195863 const unsigned char *a = sqlite3_value_blob(pVal);
195864 int nVertex;
 
 
 
 
195865 nVertex = (a[1]<<16) + (a[2]<<8) + a[3];
195866 if( (a[0]==0 || a[0]==1)
195867 && (nVertex*2*sizeof(GeoCoord) + 4)==(unsigned int)nByte
195868 ){
195869 p = sqlite3_malloc64( sizeof(*p) + (nVertex-1)*2*sizeof(GeoCoord) );
@@ -196233,11 +196679,11 @@
196233 aCoord[0].f = mnX;
196234 aCoord[1].f = mxX;
196235 aCoord[2].f = mnY;
196236 aCoord[3].f = mxY;
196237 }
196238 }else{
196239 memset(aCoord, 0, sizeof(RtreeCoord)*4);
196240 }
196241 return pOut;
196242 }
196243
@@ -226018,10 +226464,11 @@
226018 **************************************************************************
226019 ** Below this point is the implementation of the fts5_decode() scalar
226020 ** function only.
226021 */
226022
 
226023 /*
226024 ** Decode a segment-data rowid from the %_data table. This function is
226025 ** the opposite of macro FTS5_SEGMENT_ROWID().
226026 */
226027 static void fts5DecodeRowid(
@@ -226040,11 +226487,13 @@
226040 *pbDlidx = (int)(iRowid & 0x0001);
226041 iRowid >>= FTS5_DATA_DLI_B;
226042
226043 *piSegid = (int)(iRowid & (((i64)1 << FTS5_DATA_ID_B) - 1));
226044 }
 
226045
 
226046 static void fts5DebugRowid(int *pRc, Fts5Buffer *pBuf, i64 iKey){
226047 int iSegid, iHeight, iPgno, bDlidx; /* Rowid compenents */
226048 fts5DecodeRowid(iKey, &iSegid, &bDlidx, &iHeight, &iPgno);
226049
226050 if( iSegid==0 ){
@@ -226058,11 +226507,13 @@
226058 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "{%ssegid=%d h=%d pgno=%d}",
226059 bDlidx ? "dlidx " : "", iSegid, iHeight, iPgno
226060 );
226061 }
226062 }
 
226063
 
226064 static void fts5DebugStructure(
226065 int *pRc, /* IN/OUT: error code */
226066 Fts5Buffer *pBuf,
226067 Fts5Structure *p
226068 ){
@@ -226080,11 +226531,13 @@
226080 );
226081 }
226082 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "}");
226083 }
226084 }
 
226085
 
226086 /*
226087 ** This is part of the fts5_decode() debugging aid.
226088 **
226089 ** Arguments pBlob/nBlob contain a serialized Fts5Structure object. This
226090 ** function appends a human-readable representation of the same object
@@ -226105,11 +226558,13 @@
226105 }
226106
226107 fts5DebugStructure(pRc, pBuf, p);
226108 fts5StructureRelease(p);
226109 }
 
226110
 
226111 /*
226112 ** This is part of the fts5_decode() debugging aid.
226113 **
226114 ** Arguments pBlob/nBlob contain an "averages" record. This function
226115 ** appends a human-readable representation of record to the buffer passed
@@ -226128,11 +226583,13 @@
226128 i += sqlite3Fts5GetVarint(&pBlob[i], &iVal);
226129 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "%s%d", zSpace, (int)iVal);
226130 zSpace = " ";
226131 }
226132 }
 
226133
 
226134 /*
226135 ** Buffer (a/n) is assumed to contain a list of serialized varints. Read
226136 ** each varint and append its string representation to buffer pBuf. Return
226137 ** after either the input buffer is exhausted or a 0 value is read.
226138 **
@@ -226145,11 +226602,13 @@
226145 iOff += fts5GetVarint32(&a[iOff], iVal);
226146 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %d", iVal);
226147 }
226148 return iOff;
226149 }
 
226150
 
226151 /*
226152 ** The start of buffer (a/n) contains the start of a doclist. The doclist
226153 ** may or may not finish within the buffer. This function appends a text
226154 ** representation of the part of the doclist that is present to buffer
226155 ** pBuf.
@@ -226178,11 +226637,13 @@
226178 }
226179 }
226180
226181 return iOff;
226182 }
 
226183
 
226184 /*
226185 ** This function is part of the fts5_decode() debugging function. It is
226186 ** only ever used with detail=none tables.
226187 **
226188 ** Buffer (pData/nData) contains a doclist in the format used by detail=none
@@ -226219,11 +226680,13 @@
226219 }
226220
226221 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %lld%s", iRowid, zApp);
226222 }
226223 }
 
226224
 
226225 /*
226226 ** The implementation of user-defined scalar function fts5_decode().
226227 */
226228 static void fts5DecodeFunction(
226229 sqlite3_context *pCtx, /* Function call context */
@@ -226428,11 +226891,13 @@
226428 }else{
226429 sqlite3_result_error_code(pCtx, rc);
226430 }
226431 fts5BufferFree(&s);
226432 }
 
226433
 
226434 /*
226435 ** The implementation of user-defined scalar function fts5_rowid().
226436 */
226437 static void fts5RowidFunction(
226438 sqlite3_context *pCtx, /* Function call context */
@@ -226462,10 +226927,11 @@
226462 "first arg to fts5_rowid() must be 'segment'" , -1
226463 );
226464 }
226465 }
226466 }
 
226467
226468 /*
226469 ** This is called as part of registering the FTS5 module with database
226470 ** connection db. It registers several user-defined scalar functions useful
226471 ** with FTS5.
@@ -226472,10 +226938,11 @@
226472 **
226473 ** If successful, SQLITE_OK is returned. If an error occurs, some other
226474 ** SQLite error code is returned instead.
226475 */
226476 static int sqlite3Fts5IndexInit(sqlite3 *db){
 
226477 int rc = sqlite3_create_function(
226478 db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
226479 );
226480
226481 if( rc==SQLITE_OK ){
@@ -226489,10 +226956,13 @@
226489 rc = sqlite3_create_function(
226490 db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0
226491 );
226492 }
226493 return rc;
 
 
 
226494 }
226495
226496
226497 static int sqlite3Fts5IndexReset(Fts5Index *p){
226498 assert( p->pStruct==0 || p->iStructVersion!=0 );
@@ -226524,11 +226994,13 @@
226524 ** This variable is set to false when running tests for which the on disk
226525 ** structures should not be corrupt. Otherwise, true. If it is false, extra
226526 ** assert() conditions in the fts5 code are activated - conditions that are
226527 ** only true if it is guaranteed that the fts5 database is not corrupt.
226528 */
 
226529 SQLITE_API int sqlite3_fts5_may_be_corrupt = 1;
 
226530
226531
226532 typedef struct Fts5Auxdata Fts5Auxdata;
226533 typedef struct Fts5Auxiliary Fts5Auxiliary;
226534 typedef struct Fts5Cursor Fts5Cursor;
@@ -229290,11 +229762,11 @@
229290 int nArg, /* Number of args */
229291 sqlite3_value **apUnused /* Function arguments */
229292 ){
229293 assert( nArg==0 );
229294 UNUSED_PARAM2(nArg, apUnused);
229295 sqlite3_result_text(pCtx, "fts5: 2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db635aa", -1, SQLITE_TRANSIENT);
229296 }
229297
229298 /*
229299 ** Return true if zName is the extension on one of the shadow tables used
229300 ** by this module.
@@ -234216,12 +234688,12 @@
234216 }
234217 #endif /* SQLITE_CORE */
234218 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234219
234220 /************** End of stmt.c ************************************************/
234221 #if __LINE__!=234221
234222 #undef SQLITE_SOURCE_ID
234223 #define SQLITE_SOURCE_ID "2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db6alt2"
234224 #endif
234225 /* Return the source-id for this library */
234226 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234227 /************************** End of sqlite3.c ******************************/
234228
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.36.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -1184,13 +1184,13 @@
1184 **
1185 ** See also: [sqlite3_libversion()],
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.36.0"
1190 #define SQLITE_VERSION_NUMBER 3036000
1191 #define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -2189,10 +2189,23 @@
2189 ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
2190 ** in wal mode after the client has finished copying pages from the wal
2191 ** file to the database file, but before the *-shm file is updated to
2192 ** record the fact that the pages have been checkpointed.
2193 ** </ul>
2194 **
2195 ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
2196 ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
2197 ** whether or not there is a database client in another process with a wal-mode
2198 ** transaction open on the database or not. It is only available on unix.The
2199 ** (void*) argument passed with this file-control should be a pointer to a
2200 ** value of type (int). The integer value is set to 1 if the database is a wal
2201 ** mode database and there exists at least one client in another process that
2202 ** currently has an SQL transaction open on the database. It is set to 0 if
2203 ** the database is not a wal-mode db, or if there is no such connection in any
2204 ** other process. This opcode cannot be used to detect transactions opened
2205 ** by clients within the current process, only within other processes.
2206 ** </ul>
2207 */
2208 #define SQLITE_FCNTL_LOCKSTATE 1
2209 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
2210 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
2211 #define SQLITE_FCNTL_LAST_ERRNO 4
@@ -2228,10 +2241,12 @@
2241 #define SQLITE_FCNTL_DATA_VERSION 35
2242 #define SQLITE_FCNTL_SIZE_LIMIT 36
2243 #define SQLITE_FCNTL_CKPT_DONE 37
2244 #define SQLITE_FCNTL_RESERVE_BYTES 38
2245 #define SQLITE_FCNTL_CKPT_START 39
2246
2247 #define SQLITE_FCNTL_EXTERNAL_READER 40
2248
2249 /* deprecated names */
2250 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2251 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2252 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -15758,11 +15773,11 @@
15773 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
15774 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
15775 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15776 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15777 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15778 #define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15779 #define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15780 #define OP_IncrVacuum 60 /* jump */
15781 #define OP_VNext 61 /* jump */
15782 #define OP_Init 62 /* jump, synopsis: Start at P2 */
15783 #define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@NP]) */
@@ -15789,23 +15804,23 @@
15804 #define OP_RealAffinity 84
15805 #define OP_Cast 85 /* synopsis: affinity(r[P1]) */
15806 #define OP_Permutation 86
15807 #define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15808 #define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15809 #define OP_ZeroOrNull 89 /* synopsis: r[P2] = 0 OR NULL */
15810 #define OP_Offset 90 /* synopsis: r[P3] = sqlite_offset(P1) */
15811 #define OP_Column 91 /* synopsis: r[P3]=PX */
15812 #define OP_Affinity 92 /* synopsis: affinity(r[P1@P2]) */
15813 #define OP_MakeRecord 93 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15814 #define OP_Count 94 /* synopsis: r[P2]=count() */
15815 #define OP_ReadCookie 95
15816 #define OP_SetCookie 96
15817 #define OP_ReopenIdx 97 /* synopsis: root=P2 iDb=P3 */
15818 #define OP_OpenRead 98 /* synopsis: root=P2 iDb=P3 */
15819 #define OP_OpenWrite 99 /* synopsis: root=P2 iDb=P3 */
15820 #define OP_OpenDup 100
15821 #define OP_OpenAutoindex 101 /* synopsis: nColumn=P2 */
15822 #define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15823 #define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15824 #define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
15825 #define OP_ShiftRight 105 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
15826 #define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -15812,77 +15827,78 @@
15827 #define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
15828 #define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
15829 #define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15830 #define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15831 #define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15832 #define OP_OpenEphemeral 112 /* synopsis: nColumn=P2 */
15833 #define OP_BitNot 113 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15834 #define OP_SorterOpen 114
15835 #define OP_SequenceTest 115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15836 #define OP_String8 116 /* same as TK_STRING, synopsis: r[P2]='P4' */
15837 #define OP_OpenPseudo 117 /* synopsis: P3 columns in r[P2] */
15838 #define OP_Close 118
15839 #define OP_ColumnsUsed 119
15840 #define OP_SeekScan 120 /* synopsis: Scan-ahead up to P1 rows */
15841 #define OP_SeekHit 121 /* synopsis: set P2<=seekHit<=P3 */
15842 #define OP_Sequence 122 /* synopsis: r[P2]=cursor[P1].ctr++ */
15843 #define OP_NewRowid 123 /* synopsis: r[P2]=rowid */
15844 #define OP_Insert 124 /* synopsis: intkey=r[P3] data=r[P2] */
15845 #define OP_RowCell 125
15846 #define OP_Delete 126
15847 #define OP_ResetCount 127
15848 #define OP_SorterCompare 128 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15849 #define OP_SorterData 129 /* synopsis: r[P2]=data */
15850 #define OP_RowData 130 /* synopsis: r[P2]=data */
15851 #define OP_Rowid 131 /* synopsis: r[P2]=rowid */
15852 #define OP_NullRow 132
15853 #define OP_SeekEnd 133
15854 #define OP_IdxInsert 134 /* synopsis: key=r[P2] */
15855 #define OP_SorterInsert 135 /* synopsis: key=r[P2] */
15856 #define OP_IdxDelete 136 /* synopsis: key=r[P2@P3] */
15857 #define OP_DeferredSeek 137 /* synopsis: Move P3 to P1.rowid if needed */
15858 #define OP_IdxRowid 138 /* synopsis: r[P2]=rowid */
15859 #define OP_FinishSeek 139
15860 #define OP_Destroy 140
15861 #define OP_Clear 141
15862 #define OP_ResetSorter 142
15863 #define OP_CreateBtree 143 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15864 #define OP_SqlExec 144
15865 #define OP_ParseSchema 145
15866 #define OP_LoadAnalysis 146
15867 #define OP_DropTable 147
15868 #define OP_DropIndex 148
15869 #define OP_DropTrigger 149
15870 #define OP_IntegrityCk 150
15871 #define OP_RowSetAdd 151 /* synopsis: rowset(P1)=r[P2] */
15872 #define OP_Real 152 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15873 #define OP_Param 153
15874 #define OP_FkCounter 154 /* synopsis: fkctr[P1]+=P2 */
15875 #define OP_MemMax 155 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15876 #define OP_OffsetLimit 156 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15877 #define OP_AggInverse 157 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15878 #define OP_AggStep 158 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15879 #define OP_AggStep1 159 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15880 #define OP_AggValue 160 /* synopsis: r[P3]=value N=P2 */
15881 #define OP_AggFinal 161 /* synopsis: accum=r[P1] N=P2 */
15882 #define OP_Expire 162
15883 #define OP_CursorLock 163
15884 #define OP_CursorUnlock 164
15885 #define OP_TableLock 165 /* synopsis: iDb=P1 root=P2 write=P3 */
15886 #define OP_VBegin 166
15887 #define OP_VCreate 167
15888 #define OP_VDestroy 168
15889 #define OP_VOpen 169
15890 #define OP_VColumn 170 /* synopsis: r[P3]=vcolumn(P2) */
15891 #define OP_VRename 171
15892 #define OP_Pagecount 172
15893 #define OP_MaxPgcnt 173
15894 #define OP_Trace 174
15895 #define OP_CursorHint 175
15896 #define OP_ReleaseReg 176 /* synopsis: release r[P1@P2] mask P3 */
15897 #define OP_Noop 177
15898 #define OP_Explain 178
15899 #define OP_Abortable 179
15900
15901 /* Properties such as "out2" or "jump" that are specified in
15902 ** comments following the "case" for each opcode in the vdbe.c
15903 ** are encoded into bitvectors as follows:
15904 */
@@ -15902,22 +15918,22 @@
15918 /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15919 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
15920 /* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
15921 /* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
15922 /* 80 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
15923 /* 88 */ 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10,\
15924 /* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26,\
15925 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
15926 /* 112 */ 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,\
15927 /* 120 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
15928 /* 128 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\
15929 /* 136 */ 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10,\
15930 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
15931 /* 152 */ 0x10, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00,\
15932 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15933 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15934 /* 176 */ 0x00, 0x00, 0x00, 0x00,}
15935
15936 /* The sqlite3P2Values() routine is able to run faster if it knows
15937 ** the value of the largest JUMP opcode. The smaller the maximum
15938 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15939 ** generated this include file strives to group all JUMP opcodes
@@ -17005,14 +17021,11 @@
17021 u8 iDb; /* Which db file is being initialized */
17022 u8 busy; /* TRUE if currently initializing */
17023 unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
17024 unsigned imposterTable : 1; /* Building an imposter table */
17025 unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */
 
17026 char **azInit; /* "type", "name", and "tbl_name" columns */
 
 
17027 } init;
17028 int nVdbeActive; /* Number of VDBEs currently running */
17029 int nVdbeRead; /* Number of active VDBEs that read or write */
17030 int nVdbeWrite; /* Number of active VDBEs that read and write */
17031 int nVdbeExec; /* Number of nested calls to VdbeExec() */
@@ -17579,13 +17592,11 @@
17592 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
17593 ** It causes an assert() to fire if either operand to a comparison
17594 ** operator is NULL. It is added to certain comparison operators to
17595 ** prove that the operands are always NOT NULL.
17596 */
 
17597 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
 
17598 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
17599 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
17600
17601 /*
17602 ** An object of this type is created for each virtual table present in
@@ -18078,10 +18089,11 @@
18089 struct AggInfo_func { /* For each aggregate function */
18090 Expr *pFExpr; /* Expression encoding the function */
18091 FuncDef *pFunc; /* The aggregate function implementation */
18092 int iMem; /* Memory location that acts as accumulator */
18093 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
18094 int iDistAddr; /* Address of OP_OpenEphemeral */
18095 } *aFunc;
18096 int nFunc; /* Number of entries in aFunc[] */
18097 u32 selId; /* Select to which this AggInfo belongs */
18098 };
18099
@@ -18350,10 +18362,11 @@
18362 ** ENAME_SPAN Text of the original result set
18363 ** expression.
18364 */
18365 struct ExprList {
18366 int nExpr; /* Number of expressions on the list */
18367 int nAlloc; /* Number of a[] slots allocated */
18368 struct ExprList_item { /* For each expression in the list */
18369 Expr *pExpr; /* The parse tree for this expression */
18370 char *zEName; /* Token associated with this expression */
18371 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18372 unsigned eEName :2; /* Meaning of zEName */
@@ -18494,11 +18507,11 @@
18507 ** the OR optimization */
18508 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
18509 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
18510 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
18511 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18512 #define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */
18513 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
18514 /* 0x1000 not currently used */
18515 /* 0x2000 not currently used */
18516 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
18517 /* 0x8000 not currently used */
@@ -20213,10 +20226,13 @@
20226 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
20227 #ifndef SQLITE_AMALGAMATION
20228 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
20229 SQLITE_PRIVATE const char sqlite3StrBINARY[];
20230 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
20231 SQLITE_PRIVATE const unsigned char *sqlite3aLTb;
20232 SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
20233 SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
20234 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
20235 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
20236 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
20237 #ifndef SQLITE_OMIT_WSD
20238 SQLITE_PRIVATE int sqlite3PendingByte;
@@ -20679,11 +20695,11 @@
20695 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
20696 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
20697 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
20698 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
20699 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
20700 252,253,254,255,
20701 #endif
20702 #ifdef SQLITE_EBCDIC
20703 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
20704 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */
20705 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */
@@ -20699,11 +20715,39 @@
20715 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */
20716 208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */
20717 224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
20718 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
20719 #endif
20720 /* All of the upper-to-lower conversion data is above. The following
20721 ** 18 integers are completely unrelated. They are appended to the
20722 ** sqlite3UpperToLower[] array to avoid UBSAN warnings. Here's what is
20723 ** going on:
20724 **
20725 ** The SQL comparison operators (<>, =, >, <=, <, and >=) are implemented
20726 ** by invoking sqlite3MemCompare(A,B) which compares values A and B and
20727 ** returns negative, zero, or positive if A is less then, equal to, or
20728 ** greater than B, respectively. Then the true false results is found by
20729 ** consulting sqlite3aLTb[opcode], sqlite3aEQb[opcode], or
20730 ** sqlite3aGTb[opcode] depending on whether the result of compare(A,B)
20731 ** is negative, zero, or positive, where opcode is the specific opcode.
20732 ** The only works because the comparison opcodes are consecutive and in
20733 ** this order: NE EQ GT LE LT GE. Various assert()s throughout the code
20734 ** ensure that is the case.
20735 **
20736 ** These elements must be appended to another array. Otherwise the
20737 ** index (here shown as [256-OP_Ne]) would be out-of-bounds and thus
20738 ** be undefined behavior. That's goofy, but the C-standards people thought
20739 ** it was a good idea, so here we are.
20740 */
20741 /* NE EQ GT LE LT GE */
20742 1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */
20743 0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */
20744 1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/
20745 };
20746 SQLITE_PRIVATE const unsigned char *sqlite3aLTb = &sqlite3UpperToLower[256-OP_Ne];
20747 SQLITE_PRIVATE const unsigned char *sqlite3aEQb = &sqlite3UpperToLower[256+6-OP_Ne];
20748 SQLITE_PRIVATE const unsigned char *sqlite3aGTb = &sqlite3UpperToLower[256+12-OP_Ne];
20749
20750 /*
20751 ** The following 256 byte lookup table is used to support SQLites built-in
20752 ** equivalents to the following standard library functions:
20753 **
@@ -23472,11 +23516,11 @@
23516 return rc;
23517 }
23518 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
23519 DO_OS_MALLOC_TEST(0);
23520 assert( dirSync==0 || dirSync==1 );
23521 return pVfs->xDelete!=0 ? pVfs->xDelete(pVfs, zPath, dirSync) : SQLITE_OK;
23522 }
23523 SQLITE_PRIVATE int sqlite3OsAccess(
23524 sqlite3_vfs *pVfs,
23525 const char *zPath,
23526 int flags,
@@ -28461,11 +28505,11 @@
28505 /* The rest are extensions, not normally found in printf() */
28506 #define etSQLESCAPE 9 /* Strings with '\'' doubled. %q */
28507 #define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
28508 NULL pointers replaced by SQL NULL. %Q */
28509 #define etTOKEN 11 /* a pointer to a Token structure */
28510 #define etSRCITEM 12 /* a pointer to a SrcItem */
28511 #define etPOINTER 13 /* The %p conversion */
28512 #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
28513 #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
28514 #define etDECIMAL 16 /* %d or %u, but not %x, %o */
28515
@@ -28527,13 +28571,19 @@
28571 { '%', 0, 0, etPERCENT, 0, 0 },
28572 { 'p', 16, 0, etPOINTER, 0, 1 },
28573
28574 /* All the rest are undocumented and are for internal use only */
28575 { 'T', 0, 0, etTOKEN, 0, 0 },
28576 { 'S', 0, 0, etSRCITEM, 0, 0 },
28577 { 'r', 10, 1, etORDINAL, 0, 0 },
28578 };
28579
28580 /* Notes:
28581 **
28582 ** %S Takes a pointer to SrcItem. Shows name or database.name
28583 ** %!S Like %S but prefer the zName over the zAlias
28584 */
28585
28586 /* Floating point constants used for rounding */
28587 static const double arRound[] = {
28588 5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
28589 5.0e-06, 5.0e-07, 5.0e-08, 5.0e-09, 5.0e-10,
@@ -29285,25 +29335,28 @@
29335 sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
29336 }
29337 length = width = 0;
29338 break;
29339 }
29340 case etSRCITEM: {
 
 
29341 SrcItem *pItem;
29342 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
29343 pItem = va_arg(ap, SrcItem*);
 
 
29344 assert( bArgList==0 );
29345 if( pItem->zAlias && !flag_altform2 ){
29346 sqlite3_str_appendall(pAccum, pItem->zAlias);
29347 }else if( pItem->zName ){
29348 if( pItem->zDatabase ){
29349 sqlite3_str_appendall(pAccum, pItem->zDatabase);
29350 sqlite3_str_append(pAccum, ".", 1);
29351 }
29352 sqlite3_str_appendall(pAccum, pItem->zName);
29353 }else if( pItem->zAlias ){
29354 sqlite3_str_appendall(pAccum, pItem->zAlias);
29355 }else if( ALWAYS(pItem->pSelect) ){
29356 sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
29357 }
 
29358 length = width = 0;
29359 break;
29360 }
29361 default: {
29362 assert( xtype==etINVALID );
@@ -29879,23 +29932,15 @@
29932 for(i=0; i<pSrc->nSrc; i++){
29933 const SrcItem *pItem = &pSrc->a[i];
29934 StrAccum x;
29935 char zLine[100];
29936 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
29937 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
 
 
 
 
 
29938 if( pItem->pTab ){
29939 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
29940 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
29941 }
 
 
 
29942 if( pItem->fg.jointype & JT_LEFT ){
29943 sqlite3_str_appendf(&x, " LEFT-JOIN");
29944 }
29945 if( pItem->fg.fromDDL ){
29946 sqlite3_str_appendf(&x, " DDL");
@@ -33531,11 +33576,11 @@
33576 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
33577 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
33578 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
33579 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
33580 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
33581 /* 58 */ "ElseEq" OpHelp(""),
33582 /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
33583 /* 60 */ "IncrVacuum" OpHelp(""),
33584 /* 61 */ "VNext" OpHelp(""),
33585 /* 62 */ "Init" OpHelp("Start at P2"),
33586 /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
@@ -33562,23 +33607,23 @@
33607 /* 84 */ "RealAffinity" OpHelp(""),
33608 /* 85 */ "Cast" OpHelp("affinity(r[P1])"),
33609 /* 86 */ "Permutation" OpHelp(""),
33610 /* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
33611 /* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
33612 /* 89 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
33613 /* 90 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
33614 /* 91 */ "Column" OpHelp("r[P3]=PX"),
33615 /* 92 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
33616 /* 93 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
33617 /* 94 */ "Count" OpHelp("r[P2]=count()"),
33618 /* 95 */ "ReadCookie" OpHelp(""),
33619 /* 96 */ "SetCookie" OpHelp(""),
33620 /* 97 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
33621 /* 98 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
33622 /* 99 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
33623 /* 100 */ "OpenDup" OpHelp(""),
33624 /* 101 */ "OpenAutoindex" OpHelp("nColumn=P2"),
33625 /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
33626 /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
33627 /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
33628 /* 105 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
33629 /* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -33585,77 +33630,78 @@
33630 /* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
33631 /* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
33632 /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
33633 /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
33634 /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
33635 /* 112 */ "OpenEphemeral" OpHelp("nColumn=P2"),
33636 /* 113 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
33637 /* 114 */ "SorterOpen" OpHelp(""),
33638 /* 115 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
33639 /* 116 */ "String8" OpHelp("r[P2]='P4'"),
33640 /* 117 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
33641 /* 118 */ "Close" OpHelp(""),
33642 /* 119 */ "ColumnsUsed" OpHelp(""),
33643 /* 120 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
33644 /* 121 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
33645 /* 122 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
33646 /* 123 */ "NewRowid" OpHelp("r[P2]=rowid"),
33647 /* 124 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
33648 /* 125 */ "RowCell" OpHelp(""),
33649 /* 126 */ "Delete" OpHelp(""),
33650 /* 127 */ "ResetCount" OpHelp(""),
33651 /* 128 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
33652 /* 129 */ "SorterData" OpHelp("r[P2]=data"),
33653 /* 130 */ "RowData" OpHelp("r[P2]=data"),
33654 /* 131 */ "Rowid" OpHelp("r[P2]=rowid"),
33655 /* 132 */ "NullRow" OpHelp(""),
33656 /* 133 */ "SeekEnd" OpHelp(""),
33657 /* 134 */ "IdxInsert" OpHelp("key=r[P2]"),
33658 /* 135 */ "SorterInsert" OpHelp("key=r[P2]"),
33659 /* 136 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
33660 /* 137 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
33661 /* 138 */ "IdxRowid" OpHelp("r[P2]=rowid"),
33662 /* 139 */ "FinishSeek" OpHelp(""),
33663 /* 140 */ "Destroy" OpHelp(""),
33664 /* 141 */ "Clear" OpHelp(""),
33665 /* 142 */ "ResetSorter" OpHelp(""),
33666 /* 143 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
33667 /* 144 */ "SqlExec" OpHelp(""),
33668 /* 145 */ "ParseSchema" OpHelp(""),
33669 /* 146 */ "LoadAnalysis" OpHelp(""),
33670 /* 147 */ "DropTable" OpHelp(""),
33671 /* 148 */ "DropIndex" OpHelp(""),
33672 /* 149 */ "DropTrigger" OpHelp(""),
33673 /* 150 */ "IntegrityCk" OpHelp(""),
33674 /* 151 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
33675 /* 152 */ "Real" OpHelp("r[P2]=P4"),
33676 /* 153 */ "Param" OpHelp(""),
33677 /* 154 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33678 /* 155 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
33679 /* 156 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
33680 /* 157 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
33681 /* 158 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
33682 /* 159 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
33683 /* 160 */ "AggValue" OpHelp("r[P3]=value N=P2"),
33684 /* 161 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
33685 /* 162 */ "Expire" OpHelp(""),
33686 /* 163 */ "CursorLock" OpHelp(""),
33687 /* 164 */ "CursorUnlock" OpHelp(""),
33688 /* 165 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
33689 /* 166 */ "VBegin" OpHelp(""),
33690 /* 167 */ "VCreate" OpHelp(""),
33691 /* 168 */ "VDestroy" OpHelp(""),
33692 /* 169 */ "VOpen" OpHelp(""),
33693 /* 170 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
33694 /* 171 */ "VRename" OpHelp(""),
33695 /* 172 */ "Pagecount" OpHelp(""),
33696 /* 173 */ "MaxPgcnt" OpHelp(""),
33697 /* 174 */ "Trace" OpHelp(""),
33698 /* 175 */ "CursorHint" OpHelp(""),
33699 /* 176 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
33700 /* 177 */ "Noop" OpHelp(""),
33701 /* 178 */ "Explain" OpHelp(""),
33702 /* 179 */ "Abortable" OpHelp(""),
33703 };
33704 return azName[i];
33705 }
33706 #endif
33707
@@ -37810,10 +37856,11 @@
37856 }
37857 }
37858
37859 /* Forward declaration */
37860 static int unixGetTempname(int nBuf, char *zBuf);
37861 static int unixFcntlExternalReader(unixFile*, int*);
37862
37863 /*
37864 ** Information and control of an open file handle.
37865 */
37866 static int unixFileControl(sqlite3_file *id, int op, void *pArg){
@@ -37926,10 +37973,14 @@
37973 case SQLITE_FCNTL_SET_LOCKPROXYFILE:
37974 case SQLITE_FCNTL_GET_LOCKPROXYFILE: {
37975 return proxyFileControl(id,op,pArg);
37976 }
37977 #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
37978
37979 case SQLITE_FCNTL_EXTERNAL_READER: {
37980 return unixFcntlExternalReader((unixFile*)id, (int*)pArg);
37981 }
37982 }
37983 return SQLITE_NOTFOUND;
37984 }
37985
37986 /*
@@ -38170,10 +38221,44 @@
38221 /*
38222 ** Constants used for locking
38223 */
38224 #define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
38225 #define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
38226
38227 /*
38228 ** Use F_GETLK to check whether or not there are any readers with open
38229 ** wal-mode transactions in other processes on database file pFile. If
38230 ** no error occurs, return SQLITE_OK and set (*piOut) to 1 if there are
38231 ** such transactions, or 0 otherwise. If an error occurs, return an
38232 ** SQLite error code. The final value of *piOut is undefined in this
38233 ** case.
38234 */
38235 static int unixFcntlExternalReader(unixFile *pFile, int *piOut){
38236 int rc = SQLITE_OK;
38237 *piOut = 0;
38238 if( pFile->pShm){
38239 unixShmNode *pShmNode = pFile->pShm->pShmNode;
38240 struct flock f;
38241
38242 memset(&f, 0, sizeof(f));
38243 f.l_type = F_WRLCK;
38244 f.l_whence = SEEK_SET;
38245 f.l_start = UNIX_SHM_BASE + 3;
38246 f.l_len = SQLITE_SHM_NLOCK - 3;
38247
38248 sqlite3_mutex_enter(pShmNode->pShmMutex);
38249 if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){
38250 rc = SQLITE_IOERR_LOCK;
38251 }else{
38252 *piOut = (f.l_type!=F_UNLCK);
38253 }
38254 sqlite3_mutex_leave(pShmNode->pShmMutex);
38255 }
38256
38257 return rc;
38258 }
38259
38260
38261 /*
38262 ** Apply posix advisory locks for all bytes from ofst through ofst+n-1.
38263 **
38264 ** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking
@@ -56081,11 +56166,12 @@
56166 ** Once this function has been called, the transaction must either be
56167 ** rolled back or committed. It is not safe to call this function and
56168 ** then continue writing to the database.
56169 */
56170 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
56171 assert( pPager->dbSize>=nPage || CORRUPT_DB );
56172 testcase( pPager->dbSize<nPage );
56173 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
56174 pPager->dbSize = nPage;
56175
56176 /* At one point the code here called assertTruncateConstraint() to
56177 ** ensure that all pages being truncated away by this operation are,
@@ -70348,11 +70434,13 @@
70434 ** to the last entry in the b-tree. */
70435 int ii;
70436 for(ii=0; ii<pCur->iPage; ii++){
70437 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
70438 }
70439 assert( pCur->ix==pCur->pPage->nCell-1 || CORRUPT_DB );
70440 testcase( pCur->ix!=pCur->pPage->nCell-1 );
70441 /* ^-- dbsqlfuzz b92b72e4de80b5140c30ab71372ca719b8feb618 */
70442 assert( pCur->pPage->leaf );
70443 #endif
70444 *pRes = 0;
70445 return SQLITE_OK;
70446 }
@@ -71115,11 +71203,11 @@
71203 closest = 0;
71204 }
71205
71206 iPage = get4byte(&aData[8+closest*4]);
71207 testcase( iPage==mxPage );
71208 if( iPage>mxPage || iPage<2 ){
71209 rc = SQLITE_CORRUPT_PGNO(iTrunk);
71210 goto end_allocate_page;
71211 }
71212 testcase( iPage==mxPage );
71213 if( !searchList
@@ -74062,11 +74150,11 @@
74150 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
74151 if( pCur->eState==CURSOR_REQUIRESEEK ){
74152 rc = btreeRestoreCursorPosition(pCur);
74153 if( rc ) return rc;
74154 }
74155 assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
74156
74157 iCellDepth = pCur->iPage;
74158 iCellIdx = pCur->ix;
74159 pPage = pCur->pPage;
74160 pCell = findCell(pPage, iCellIdx);
@@ -79862,15 +79950,11 @@
79950 if( zOpName[nOpName+1] ){
79951 int seenCom = 0;
79952 char c;
79953 zSynopsis = zOpName += nOpName + 1;
79954 if( strncmp(zSynopsis,"IF ",3)==0 ){
79955 sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3);
 
 
 
 
79956 zSynopsis = zAlt;
79957 }
79958 for(ii=0; (c = zSynopsis[ii])!=0; ii++){
79959 if( c=='P' ){
79960 c = zSynopsis[++ii];
@@ -87438,11 +87522,11 @@
87522 */
87523 case OP_ResultRow: {
87524 Mem *pMem;
87525 int i;
87526 assert( p->nResColumn==pOp->p2 );
87527 assert( pOp->p1>0 || CORRUPT_DB );
87528 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
87529
87530 /* Invalidate all ephemeral cursor row caches */
87531 p->cacheCtr = (p->cacheCtr + 2)|1;
87532
@@ -87880,12 +87964,11 @@
87964
87965 /* Opcode: Eq P1 P2 P3 P4 P5
87966 ** Synopsis: IF r[P3]==r[P1]
87967 **
87968 ** Compare the values in register P1 and P3. If reg(P3)==reg(P1) then
87969 ** jump to address P2.
 
87970 **
87971 ** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
87972 ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
87973 ** to coerce both inputs according to this affinity before the
87974 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
@@ -87907,31 +87990,25 @@
87990 ** true or false and is never NULL. If both operands are NULL then the result
87991 ** of comparison is true. If either operand is NULL then the result is false.
87992 ** If neither operand is NULL the result is the same as it would be if
87993 ** the SQLITE_NULLEQ flag were omitted from P5.
87994 **
87995 ** This opcode saves the result of comparison for use by the new
87996 ** OP_Jump opcode.
 
87997 */
87998 /* Opcode: Ne P1 P2 P3 P4 P5
87999 ** Synopsis: IF r[P3]!=r[P1]
88000 **
88001 ** This works just like the Eq opcode except that the jump is taken if
88002 ** the operands in registers P1 and P3 are not equal. See the Eq opcode for
88003 ** additional information.
 
 
 
 
88004 */
88005 /* Opcode: Lt P1 P2 P3 P4 P5
88006 ** Synopsis: IF r[P3]<r[P1]
88007 **
88008 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
88009 ** jump to address P2.
 
88010 **
88011 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
88012 ** reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL
88013 ** bit is clear then fall through if either operand is NULL.
88014 **
@@ -87950,10 +88027,13 @@
88027 ** P4 is used to do the comparison. If P4 is not specified then
88028 ** memcmp() is used to compare text string. If both values are
88029 ** numeric, then a numeric comparison is used. If the two values
88030 ** are of different types, then numbers are considered less than
88031 ** strings and strings are considered less than blobs.
88032 **
88033 ** This opcode saves the result of comparison for use by the new
88034 ** OP_Jump opcode.
88035 */
88036 /* Opcode: Le P1 P2 P3 P4 P5
88037 ** Synopsis: IF r[P3]<=r[P1]
88038 **
88039 ** This works just like the Lt opcode except that the jump is taken if
@@ -88009,21 +88089,14 @@
88089 }else{
88090 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
88091 ** then the result is always NULL.
88092 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
88093 */
88094 iCompare = 1; /* Operands are not equal */
88095 VdbeBranchTaken(2,3);
88096 if( pOp->p5 & SQLITE_JUMPIFNULL ){
88097 goto jump_to_p2;
 
 
 
 
 
 
 
88098 }
88099 break;
88100 }
88101 }else{
88102 /* Neither operand is NULL. Do a comparison. */
@@ -88076,88 +88149,58 @@
88149 ** operator actually is. The next block of code depends on the fact
88150 ** that the 6 comparison operators are consecutive integers in this
88151 ** order: NE, EQ, GT, LE, LT, GE */
88152 assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 );
88153 assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 );
88154 if( res<0 ){
88155 res2 = sqlite3aLTb[pOp->opcode];
 
88156 }else if( res==0 ){
88157 res2 = sqlite3aEQb[pOp->opcode];
 
88158 }else{
88159 res2 = sqlite3aGTb[pOp->opcode];
 
88160 }
88161 iCompare = res;
88162
88163 /* Undo any changes made by applyAffinity() to the input registers. */
88164 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
88165 pIn3->flags = flags3;
88166 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
88167 pIn1->flags = flags1;
88168
88169 VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
88170 if( res2 ){
88171 goto jump_to_p2;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88172 }
88173 break;
88174 }
88175
88176 /* Opcode: ElseEq * P2 * * *
88177 **
88178 ** This opcode must follow an OP_Lt or OP_Gt comparison operator. There
88179 ** can be zero or more OP_ReleaseReg opcodes intervening, but no other
88180 ** opcodes are allowed to occur between this instruction and the previous
88181 ** OP_Lt or OP_Gt.
 
88182 **
88183 ** If result of an OP_Eq comparison on the same two operands as the
88184 ** prior OP_Lt or OP_Gt would have been true, then jump to P2.
88185 ** If the result of an OP_Eq comparison on the two previous
88186 ** operands would have been false or NULL, then fall through.
88187 */
88188 case OP_ElseEq: { /* same as TK_ESCAPE, jump */
88189
88190 #ifdef SQLITE_DEBUG
88191 /* Verify the preconditions of this opcode - that it follows an OP_Lt or
88192 ** OP_Gt with zero or more intervening OP_ReleaseReg opcodes */
 
88193 int iAddr;
88194 for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
88195 if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
88196 assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
 
88197 break;
88198 }
88199 #endif /* SQLITE_DEBUG */
88200 VdbeBranchTaken(iCompare==0, 2);
88201 if( iCompare==0 ) goto jump_to_p2;
88202 break;
88203 }
88204
88205
88206 /* Opcode: Permutation * * * P4 *
@@ -88463,10 +88506,28 @@
88506 if( (pIn1->flags & MEM_Null)!=0 ){
88507 goto jump_to_p2;
88508 }
88509 break;
88510 }
88511
88512 /* Opcode: ZeroOrNull P1 P2 P3 * *
88513 ** Synopsis: r[P2] = 0 OR NULL
88514 **
88515 ** If all both registers P1 and P3 are NOT NULL, then store a zero in
88516 ** register P2. If either registers P1 or P3 are NULL then put
88517 ** a NULL in register P2.
88518 */
88519 case OP_ZeroOrNull: { /* in1, in2, out2, in3 */
88520 if( (aMem[pOp->p1].flags & MEM_Null)!=0
88521 || (aMem[pOp->p3].flags & MEM_Null)!=0
88522 ){
88523 sqlite3VdbeMemSetNull(aMem + pOp->p2);
88524 }else{
88525 sqlite3VdbeMemSetInt64(aMem + pOp->p2, 0);
88526 }
88527 break;
88528 }
88529
88530 /* Opcode: NotNull P1 P2 * * *
88531 ** Synopsis: if r[P1]!=NULL goto P2
88532 **
88533 ** Jump to P2 if the value in register P1 is not NULL.
@@ -99001,12 +99062,14 @@
99062 pTab = 0;
99063 #ifndef SQLITE_OMIT_TRIGGER
99064 if( pParse->pTriggerTab!=0 ){
99065 int op = pParse->eTriggerOp;
99066 assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
99067 if( pParse->bReturning ){
99068 if( (pNC->ncFlags & NC_UBaseReg)!=0
99069 && (zTab==0 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0)
99070 ){
99071 pExpr->iTable = op!=TK_DELETE;
99072 pTab = pParse->pTriggerTab;
99073 }
99074 }else if( op!=TK_DELETE && zTab && sqlite3StrICmp("new",zTab) == 0 ){
99075 pExpr->iTable = 1;
@@ -99186,11 +99249,10 @@
99249 */
99250 if( cnt==0 && zTab==0 ){
99251 assert( pExpr->op==TK_ID );
99252 if( ExprHasProperty(pExpr,EP_DblQuoted)
99253 && areDoubleQuotedStringsEnabled(db, pTopNC)
 
99254 ){
99255 /* If a double-quoted identifier does not match any known column name,
99256 ** then treat it as a string.
99257 **
99258 ** This hack was added in the early days of SQLite in a misguided attempt
@@ -99201,15 +99263,10 @@
99263 ** programmers. To all those frustrated programmers, my apologies.
99264 **
99265 ** Someday, I hope to get rid of this hack. Unfortunately there is
99266 ** a huge amount of legacy SQL that uses it. So for now, we just
99267 ** issue a warning.
 
 
 
 
 
99268 */
99269 sqlite3_log(SQLITE_WARNING,
99270 "double-quoted string literal: \"%w\"", zCol);
99271 #ifdef SQLITE_ENABLE_NORMALIZE
99272 sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
@@ -101259,10 +101316,11 @@
101316 int nLeft = sqlite3ExprVectorSize(pLeft);
101317 int i;
101318 int regLeft = 0;
101319 int regRight = 0;
101320 u8 opx = op;
101321 int addrCmp = 0;
101322 int addrDone = sqlite3VdbeMakeLabel(pParse);
101323 int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
101324
101325 assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
101326 if( pParse->nErr ) return;
@@ -101278,53 +101336,62 @@
101336 assert( pExpr->op==op || (pExpr->op==TK_IS && op==TK_EQ)
101337 || (pExpr->op==TK_ISNOT && op==TK_NE) );
101338 assert( p5==0 || pExpr->op!=op );
101339 assert( p5==SQLITE_NULLEQ || pExpr->op==op );
101340
101341 if( op==TK_LE ) opx = TK_LT;
101342 if( op==TK_GE ) opx = TK_GT;
101343 if( op==TK_NE ) opx = TK_EQ;
101344
101345 regLeft = exprCodeSubselect(pParse, pLeft);
101346 regRight = exprCodeSubselect(pParse, pRight);
101347
101348 sqlite3VdbeAddOp2(v, OP_Integer, 1, dest);
101349 for(i=0; 1 /*Loop exits by "break"*/; i++){
101350 int regFree1 = 0, regFree2 = 0;
101351 Expr *pL, *pR;
101352 int r1, r2;
101353 assert( i>=0 && i<nLeft );
101354 if( addrCmp ) sqlite3VdbeJumpHere(v, addrCmp);
101355 r1 = exprVectorRegister(pParse, pLeft, i, regLeft, &pL, &regFree1);
101356 r2 = exprVectorRegister(pParse, pRight, i, regRight, &pR, &regFree2);
101357 addrCmp = sqlite3VdbeCurrentAddr(v);
101358 codeCompare(pParse, pL, pR, opx, r1, r2, addrDone, p5, isCommuted);
101359 testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
101360 testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
101361 testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
101362 testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
101363 testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
101364 testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
101365 sqlite3ReleaseTempReg(pParse, regFree1);
101366 sqlite3ReleaseTempReg(pParse, regFree2);
101367 if( (opx==TK_LT || opx==TK_GT) && i<nLeft-1 ){
101368 addrCmp = sqlite3VdbeAddOp0(v, OP_ElseEq);
101369 testcase(opx==TK_LT); VdbeCoverageIf(v,opx==TK_LT);
101370 testcase(opx==TK_GT); VdbeCoverageIf(v,opx==TK_GT);
101371 }
101372 if( p5==SQLITE_NULLEQ ){
101373 sqlite3VdbeAddOp2(v, OP_Integer, 0, dest);
101374 }else{
101375 sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, dest, r2);
101376 }
101377 if( i==nLeft-1 ){
101378 break;
101379 }
101380 if( opx==TK_EQ ){
101381 sqlite3VdbeAddOp2(v, OP_NotNull, dest, addrDone); VdbeCoverage(v);
 
 
 
 
101382 }else{
101383 assert( op==TK_LT || op==TK_GT || op==TK_LE || op==TK_GE );
101384 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
 
 
 
 
101385 if( i==nLeft-2 ) opx = op;
101386 }
101387 }
101388 sqlite3VdbeJumpHere(v, addrCmp);
101389 sqlite3VdbeResolveLabel(v, addrDone);
101390 if( op==TK_NE ){
101391 sqlite3VdbeAddOp2(v, OP_Not, dest, dest);
101392 }
101393 }
101394
101395 #if SQLITE_MAX_EXPR_DEPTH>0
101396 /*
101397 ** Check that argument nHeight is less than or equal to the maximum
@@ -102142,10 +102209,11 @@
102209 assert( db!=0 );
102210 if( p==0 ) return 0;
102211 pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p));
102212 if( pNew==0 ) return 0;
102213 pNew->nExpr = p->nExpr;
102214 pNew->nAlloc = p->nAlloc;
102215 pItem = pNew->a;
102216 pOldItem = p->a;
102217 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
102218 Expr *pOldExpr = pOldItem->pExpr;
102219 Expr *pNewExpr;
@@ -102314,45 +102382,68 @@
102382 **
102383 ** If a memory allocation error occurs, the entire list is freed and
102384 ** NULL is returned. If non-NULL is returned, then it is guaranteed
102385 ** that the new entry was successfully appended.
102386 */
102387 static const struct ExprList_item zeroItem = {0};
102388 SQLITE_PRIVATE SQLITE_NOINLINE ExprList *sqlite3ExprListAppendNew(
102389 sqlite3 *db, /* Database handle. Used for memory allocation */
102390 Expr *pExpr /* Expression to be appended. Might be NULL */
102391 ){
102392 struct ExprList_item *pItem;
102393 ExprList *pList;
102394
102395 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList)+sizeof(pList->a[0])*4 );
102396 if( pList==0 ){
102397 sqlite3ExprDelete(db, pExpr);
102398 return 0;
102399 }
102400 pList->nAlloc = 4;
102401 pList->nExpr = 1;
102402 pItem = &pList->a[0];
102403 *pItem = zeroItem;
102404 pItem->pExpr = pExpr;
102405 return pList;
102406 }
102407 SQLITE_PRIVATE SQLITE_NOINLINE ExprList *sqlite3ExprListAppendGrow(
102408 sqlite3 *db, /* Database handle. Used for memory allocation */
102409 ExprList *pList, /* List to which to append. Might be NULL */
102410 Expr *pExpr /* Expression to be appended. Might be NULL */
102411 ){
102412 struct ExprList_item *pItem;
102413 ExprList *pNew;
102414 pList->nAlloc *= 2;
102415 pNew = sqlite3DbRealloc(db, pList,
102416 sizeof(*pList)+(pList->nAlloc-1)*sizeof(pList->a[0]));
102417 if( pNew==0 ){
102418 sqlite3ExprListDelete(db, pList);
102419 sqlite3ExprDelete(db, pExpr);
102420 return 0;
102421 }else{
102422 pList = pNew;
102423 }
102424 pItem = &pList->a[pList->nExpr++];
102425 *pItem = zeroItem;
102426 pItem->pExpr = pExpr;
102427 return pList;
102428 }
102429 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
102430 Parse *pParse, /* Parsing context */
102431 ExprList *pList, /* List to which to append. Might be NULL */
102432 Expr *pExpr /* Expression to be appended. Might be NULL */
102433 ){
102434 struct ExprList_item *pItem;
102435 if( pList==0 ){
102436 return sqlite3ExprListAppendNew(pParse->db,pExpr);
102437 }
102438 if( pList->nAlloc<pList->nExpr+1 ){
102439 return sqlite3ExprListAppendGrow(pParse->db,pList,pExpr);
 
 
 
 
 
 
 
 
 
 
 
102440 }
102441 pItem = &pList->a[pList->nExpr++];
102442 *pItem = zeroItem;
 
 
102443 pItem->pExpr = pExpr;
102444 return pList;
 
 
 
 
 
 
102445 }
102446
102447 /*
102448 ** pColumns and pExpr form a vector assignment which is part of the SET
102449 ** clause of an UPDATE statement. Like this:
@@ -104003,10 +104094,11 @@
104094 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
104095 }
104096 if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
104097 for(i=0; i<nVector; i++){
104098 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
104099 if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
104100 if( sqlite3ExprCanBeNull(p) ){
104101 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
104102 VdbeCoverage(v);
104103 }
104104 }
@@ -104694,19 +104786,25 @@
104786 if( sqlite3ExprIsVector(pLeft) ){
104787 codeVectorCompare(pParse, pExpr, target, op, p5);
104788 }else{
104789 r1 = sqlite3ExprCodeTemp(pParse, pLeft, &regFree1);
104790 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
104791 sqlite3VdbeAddOp2(v, OP_Integer, 1, inReg);
104792 codeCompare(pParse, pLeft, pExpr->pRight, op, r1, r2,
104793 sqlite3VdbeCurrentAddr(v)+2, p5,
104794 ExprHasProperty(pExpr,EP_Commuted));
104795 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
104796 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
104797 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
104798 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
104799 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
104800 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
104801 if( p5==SQLITE_NULLEQ ){
104802 sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg);
104803 }else{
104804 sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, inReg, r2);
104805 }
104806 testcase( regFree1==0 );
104807 testcase( regFree2==0 );
104808 }
104809 break;
104810 }
@@ -106820,31 +106918,55 @@
106918 static void renameTestSchema(
106919 Parse *pParse, /* Parse context */
106920 const char *zDb, /* Name of db to verify schema of */
106921 int bTemp, /* True if this is the temp db */
106922 const char *zWhen, /* "when" part of error message */
106923 int bNoDQS /* Do not allow DQS in the schema */
106924 ){
106925 pParse->colNamesSet = 1;
106926 sqlite3NestedParse(pParse,
106927 "SELECT 1 "
106928 "FROM \"%w\"." DFLT_SCHEMA_TABLE " "
106929 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106930 " AND sql NOT LIKE 'create virtual%%'"
106931 " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL ",
106932 zDb,
106933 zDb, bTemp, zWhen, bNoDQS
106934 );
106935
106936 if( bTemp==0 ){
106937 sqlite3NestedParse(pParse,
106938 "SELECT 1 "
106939 "FROM temp." DFLT_SCHEMA_TABLE " "
106940 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106941 " AND sql NOT LIKE 'create virtual%%'"
106942 " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL ",
106943 zDb, zWhen, bNoDQS
106944 );
106945 }
106946 }
106947
106948 /*
106949 ** Generate VM code to replace any double-quoted strings (but not double-quoted
106950 ** identifiers) within the "sql" column of the sqlite_schema table in
106951 ** database zDb with their single-quoted equivalents. If argument bTemp is
106952 ** not true, similarly update all SQL statements in the sqlite_schema table
106953 ** of the temp db.
106954 */
106955 static void renameFixQuotes(Parse *pParse, const char *zDb, int bTemp){
106956 sqlite3NestedParse(pParse,
106957 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE
106958 " SET sql = sqlite_rename_quotefix(%Q, sql)"
106959 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106960 " AND sql NOT LIKE 'create virtual%%'" , zDb, zDb
106961 );
106962 if( bTemp==0 ){
106963 sqlite3NestedParse(pParse,
106964 "UPDATE temp." DFLT_SCHEMA_TABLE
106965 " SET sql = sqlite_rename_quotefix('temp', sql)"
106966 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
106967 " AND sql NOT LIKE 'create virtual%%'"
106968 );
106969 }
106970 }
106971
106972 /*
@@ -107003,11 +107125,11 @@
107125 sqlite3NestedParse(pParse,
107126 "UPDATE sqlite_temp_schema SET "
107127 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
107128 "tbl_name = "
107129 "CASE WHEN tbl_name=%Q COLLATE nocase AND "
107130 " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) "
107131 "THEN %Q ELSE tbl_name END "
107132 "WHERE type IN ('view', 'trigger')"
107133 , zDb, zTabName, zName, zTabName, zDb, zName);
107134 }
107135
@@ -107361,10 +107483,14 @@
107483 }
107484 if( iCol==pTab->nCol ){
107485 sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld);
107486 goto exit_rename_column;
107487 }
107488
107489 /* Ensure the schema contains no double-quoted strings */
107490 renameTestSchema(pParse, zDb, iSchema==1, "", 0);
107491 renameFixQuotes(pParse, zDb, iSchema==1);
107492
107493 /* Do the rename operation using a recursive UPDATE statement that
107494 ** uses the sqlite_rename_column() SQL function to compute the new
107495 ** CREATE statement text for the sqlite_schema table.
107496 */
@@ -107391,11 +107517,11 @@
107517 zDb, pTab->zName, iCol, zNew, bQuote
107518 );
107519
107520 /* Drop and reload the database schema. */
107521 renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename);
107522 renameTestSchema(pParse, zDb, iSchema==1, "after rename", 1);
107523
107524 exit_rename_column:
107525 sqlite3SrcListDelete(db, pSrc);
107526 sqlite3DbFree(db, zOld);
107527 sqlite3DbFree(db, zNew);
@@ -107815,21 +107941,16 @@
107941 static int renameParseSql(
107942 Parse *p, /* Memory to use for Parse object */
107943 const char *zDb, /* Name of schema SQL belongs to */
107944 sqlite3 *db, /* Database handle */
107945 const char *zSql, /* SQL to parse */
107946 int bTemp /* True if SQL is from temp schema */
 
107947 ){
107948 int rc;
107949 char *zErr = 0;
107950
107951 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
 
 
 
 
107952
107953 /* Parse the SQL statement passed as the first argument. If no error
107954 ** occurs and the parse does not result in a new table, index or
107955 ** trigger object, the database must be corrupt. */
107956 memset(p, 0, sizeof(Parse));
@@ -107858,11 +107979,10 @@
107979 }
107980 }
107981 #endif
107982
107983 db->init.iDb = 0;
 
107984 return rc;
107985 }
107986
107987 /*
107988 ** This function edits SQL statement zSql, replacing each token identified
@@ -107882,51 +108002,76 @@
108002 ){
108003 int nNew = sqlite3Strlen30(zNew);
108004 int nSql = sqlite3Strlen30(zSql);
108005 sqlite3 *db = sqlite3_context_db_handle(pCtx);
108006 int rc = SQLITE_OK;
108007 char *zQuot = 0;
108008 char *zOut;
108009 int nQuot = 0;
108010 char *zBuf1 = 0;
108011 char *zBuf2 = 0;
108012
108013 if( zNew ){
108014 /* Set zQuot to point to a buffer containing a quoted copy of the
108015 ** identifier zNew. If the corresponding identifier in the original
108016 ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
108017 ** point to zQuot so that all substitutions are made using the
108018 ** quoted version of the new column name. */
108019 zQuot = sqlite3MPrintf(db, "\"%w\" ", zNew);
108020 if( zQuot==0 ){
108021 return SQLITE_NOMEM;
108022 }else{
108023 nQuot = sqlite3Strlen30(zQuot)-1;
108024 }
108025
108026 assert( nQuot>=nNew );
108027 zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1);
108028 }else{
108029 zOut = (char*)sqlite3DbMallocZero(db, (nSql*2+1) * 3);
108030 if( zOut ){
108031 zBuf1 = &zOut[nSql*2+1];
108032 zBuf2 = &zOut[nSql*4+2];
108033 }
108034 }
108035
108036 /* At this point pRename->pList contains a list of RenameToken objects
108037 ** corresponding to all tokens in the input SQL that must be replaced
108038 ** with the new column name, or with single-quoted versions of themselves.
108039 ** All that remains is to construct and return the edited SQL string. */
 
 
108040 if( zOut ){
108041 int nOut = nSql;
108042 memcpy(zOut, zSql, nSql);
108043 while( pRename->pList ){
108044 int iOff; /* Offset of token to replace in zOut */
 
 
108045 u32 nReplace;
108046 const char *zReplace;
108047 RenameToken *pBest = renameColumnTokenNext(pRename);
108048
108049 if( zNew ){
108050 if( bQuote==0 && sqlite3IsIdChar(*pBest->t.z) ){
108051 nReplace = nNew;
108052 zReplace = zNew;
108053 }else{
108054 nReplace = nQuot;
108055 zReplace = zQuot;
108056 if( pBest->t.z[pBest->t.n]=='"' ) nReplace++;
108057 }
108058 }else{
108059 /* Dequote the double-quoted token. Then requote it again, this time
108060 ** using single quotes. If the character immediately following the
108061 ** original token within the input SQL was a single quote ('), then
108062 ** add another space after the new, single-quoted version of the
108063 ** token. This is so that (SELECT "string"'alias') maps to
108064 ** (SELECT 'string' 'alias'), and not (SELECT 'string''alias'). */
108065 memcpy(zBuf1, pBest->t.z, pBest->t.n);
108066 zBuf1[pBest->t.n] = 0;
108067 sqlite3Dequote(zBuf1);
108068 sqlite3_snprintf(nSql*2, zBuf2, "%Q%s", zBuf1,
108069 pBest->t.z[pBest->t.n]=='\'' ? " " : ""
108070 );
108071 zReplace = zBuf2;
108072 nReplace = sqlite3Strlen30(zReplace);
108073 }
108074
108075 iOff = pBest->t.z - zSql;
108076 if( pBest->t.n!=nReplace ){
108077 memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n],
@@ -108160,11 +108305,11 @@
108305 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
108306
108307 #ifndef SQLITE_OMIT_AUTHORIZATION
108308 db->xAuth = 0;
108309 #endif
108310 rc = renameParseSql(&sParse, zDb, db, zSql, bTemp);
108311
108312 /* Find tokens that need to be replaced. */
108313 memset(&sWalker, 0, sizeof(Walker));
108314 sWalker.pParse = &sParse;
108315 sWalker.xExprCallback = renameColumnExprCb;
@@ -108364,11 +108509,11 @@
108509 sWalker.pParse = &sParse;
108510 sWalker.xExprCallback = renameTableExprCb;
108511 sWalker.xSelectCallback = renameTableSelectCb;
108512 sWalker.u.pRename = &sCtx;
108513
108514 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
108515
108516 if( rc==SQLITE_OK ){
108517 int isLegacy = (db->flags & SQLITE_LegacyAlter);
108518 if( sParse.pNewTable ){
108519 Table *pTab = sParse.pNewTable;
@@ -108466,10 +108611,123 @@
108611 #endif
108612 }
108613
108614 return;
108615 }
108616
108617 static int renameQuotefixExprCb(Walker *pWalker, Expr *pExpr){
108618 if( pExpr->op==TK_STRING && (pExpr->flags & EP_DblQuoted) ){
108619 renameTokenFind(pWalker->pParse, pWalker->u.pRename, (void*)pExpr);
108620 }
108621 return WRC_Continue;
108622 }
108623
108624 /*
108625 ** The implementation of an SQL scalar function that rewrites DDL statements
108626 ** so that any string literals that use double-quotes are modified so that
108627 ** they use single quotes.
108628 **
108629 ** Two arguments must be passed:
108630 **
108631 ** 0: Database name ("main", "temp" etc.).
108632 ** 1: SQL statement to edit.
108633 **
108634 ** The returned value is the modified SQL statement. For example, given
108635 ** the database schema:
108636 **
108637 ** CREATE TABLE t1(a, b, c);
108638 **
108639 ** SELECT sqlite_rename_quotefix('main',
108640 ** 'CREATE VIEW v1 AS SELECT "a", "string" FROM t1'
108641 ** );
108642 **
108643 ** returns the string:
108644 **
108645 ** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1
108646 */
108647 static void renameQuotefixFunc(
108648 sqlite3_context *context,
108649 int NotUsed,
108650 sqlite3_value **argv
108651 ){
108652 sqlite3 *db = sqlite3_context_db_handle(context);
108653 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
108654 char const *zInput = (const char*)sqlite3_value_text(argv[1]);
108655
108656 #ifndef SQLITE_OMIT_AUTHORIZATION
108657 sqlite3_xauth xAuth = db->xAuth;
108658 db->xAuth = 0;
108659 #endif
108660
108661 sqlite3BtreeEnterAll(db);
108662
108663 UNUSED_PARAMETER(NotUsed);
108664 if( zDb && zInput ){
108665 int rc;
108666 Parse sParse;
108667 rc = renameParseSql(&sParse, zDb, db, zInput, 0);
108668
108669 if( rc==SQLITE_OK ){
108670 RenameCtx sCtx;
108671 Walker sWalker;
108672
108673 /* Walker to find tokens that need to be replaced. */
108674 memset(&sCtx, 0, sizeof(RenameCtx));
108675 memset(&sWalker, 0, sizeof(Walker));
108676 sWalker.pParse = &sParse;
108677 sWalker.xExprCallback = renameQuotefixExprCb;
108678 sWalker.xSelectCallback = renameColumnSelectCb;
108679 sWalker.u.pRename = &sCtx;
108680
108681 if( sParse.pNewTable ){
108682 Select *pSelect = sParse.pNewTable->pSelect;
108683 if( pSelect ){
108684 pSelect->selFlags &= ~SF_View;
108685 sParse.rc = SQLITE_OK;
108686 sqlite3SelectPrep(&sParse, pSelect, 0);
108687 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
108688 if( rc==SQLITE_OK ){
108689 sqlite3WalkSelect(&sWalker, pSelect);
108690 }
108691 }else{
108692 int i;
108693 sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
108694 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
108695 for(i=0; i<sParse.pNewTable->nCol; i++){
108696 sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt);
108697 }
108698 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
108699 }
108700 }else if( sParse.pNewIndex ){
108701 sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr);
108702 sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere);
108703 }else{
108704 #ifndef SQLITE_OMIT_TRIGGER
108705 rc = renameResolveTrigger(&sParse);
108706 if( rc==SQLITE_OK ){
108707 renameWalkTrigger(&sWalker, sParse.pNewTrigger);
108708 }
108709 #endif /* SQLITE_OMIT_TRIGGER */
108710 }
108711
108712 if( rc==SQLITE_OK ){
108713 rc = renameEditSql(context, &sCtx, zInput, 0, 0);
108714 }
108715 renameTokenFree(db, sCtx.pList);
108716 }
108717 if( rc!=SQLITE_OK ){
108718 sqlite3_result_error_code(context, rc);
108719 }
108720 renameParseCleanup(&sParse);
108721 }
108722
108723 #ifndef SQLITE_OMIT_AUTHORIZATION
108724 db->xAuth = xAuth;
108725 #endif
108726
108727 sqlite3BtreeLeaveAll(db);
108728 }
108729
108730 /*
108731 ** An SQL user function that checks that there are no parse or symbol
108732 ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement.
108733 ** After an ALTER TABLE .. RENAME operation is performed and the schema
@@ -108480,11 +108738,11 @@
108738 ** 1: SQL statement.
108739 ** 2: Object type ("view", "table", "trigger" or "index").
108740 ** 3: Object name.
108741 ** 4: True if object is from temp schema.
108742 ** 5: "when" part of error message.
108743 ** 6: True to disable the DQS quirk when parsing SQL.
108744 **
108745 ** Unless it finds an error, this function normally returns NULL. However, it
108746 ** returns integer value 1 if:
108747 **
108748 ** * the SQL argument creates a trigger, and
@@ -108499,22 +108757,26 @@
108757 char const *zDb = (const char*)sqlite3_value_text(argv[0]);
108758 char const *zInput = (const char*)sqlite3_value_text(argv[1]);
108759 int bTemp = sqlite3_value_int(argv[4]);
108760 int isLegacy = (db->flags & SQLITE_LegacyAlter);
108761 char const *zWhen = (const char*)sqlite3_value_text(argv[5]);
108762 int bNoDQS = sqlite3_value_int(argv[6]);
108763
108764 #ifndef SQLITE_OMIT_AUTHORIZATION
108765 sqlite3_xauth xAuth = db->xAuth;
108766 db->xAuth = 0;
108767 #endif
108768
108769 UNUSED_PARAMETER(NotUsed);
108770
108771 if( zDb && zInput ){
108772 int rc;
108773 Parse sParse;
108774 int flags = db->flags;
108775 if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL);
108776 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
108777 db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL));
108778 if( rc==SQLITE_OK ){
108779 if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
108780 NameContext sNC;
108781 memset(&sNC, 0, sizeof(sNC));
108782 sNC.pParse = &sParse;
@@ -108578,11 +108840,11 @@
108840 sqlite3_xauth xAuth = db->xAuth;
108841 db->xAuth = 0;
108842 #endif
108843
108844 UNUSED_PARAMETER(NotUsed);
108845 rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1);
108846 if( rc!=SQLITE_OK ) goto drop_column_done;
108847 pTab = sParse.pNewTable;
108848 if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){
108849 /* This can happen if the sqlite_schema table is corrupt */
108850 rc = SQLITE_CORRUPT_BKPT;
@@ -108672,20 +108934,21 @@
108934 /* Edit the sqlite_schema table */
108935 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108936 assert( iDb>=0 );
108937 zDb = db->aDb[iDb].zDbSName;
108938 renameTestSchema(pParse, zDb, iDb==1, "", 0);
108939 renameFixQuotes(pParse, zDb, iDb==1);
108940 sqlite3NestedParse(pParse,
108941 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108942 "sql = sqlite_drop_column(%d, sql, %d) "
108943 "WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)"
108944 , zDb, iDb, iCol, pTab->zName
108945 );
108946
108947 /* Drop and reload the database schema. */
108948 renameReloadSchema(pParse, iDb, INITFLAG_AlterDrop);
108949 renameTestSchema(pParse, zDb, iDb==1, "after drop column", 1);
108950
108951 /* Edit rows of table on disk */
108952 if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){
108953 int i;
108954 int addr;
@@ -108697,31 +108960,37 @@
108960 Vdbe *v = sqlite3GetVdbe(pParse);
108961 iCur = pParse->nTab++;
108962 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite);
108963 addr = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
108964 reg = ++pParse->nMem;
 
108965 if( HasRowid(pTab) ){
108966 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, reg);
108967 pParse->nMem += pTab->nCol;
108968 }else{
108969 pPk = sqlite3PrimaryKeyIndex(pTab);
108970 pParse->nMem += pPk->nColumn;
108971 for(i=0; i<pPk->nKeyCol; i++){
108972 sqlite3VdbeAddOp3(v, OP_Column, iCur, i, reg+i+1);
108973 }
108974 nField = pPk->nKeyCol;
108975 }
108976 regRec = ++pParse->nMem;
108977 for(i=0; i<pTab->nCol; i++){
108978 if( i!=iCol && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
108979 int regOut;
108980 if( pPk ){
108981 int iPos = sqlite3TableColumnToIndex(pPk, i);
108982 int iColPos = sqlite3TableColumnToIndex(pPk, iCol);
108983 if( iPos<pPk->nKeyCol ) continue;
108984 regOut = reg+1+iPos-(iPos>iColPos);
108985 }else{
108986 regOut = reg+1+nField;
108987 }
108988 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
108989 nField++;
108990 }
108991 }
 
108992 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
108993 if( pPk ){
108994 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
108995 }else{
108996 sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg);
@@ -108743,10 +109012,11 @@
109012 static FuncDef aAlterTableFuncs[] = {
109013 INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc),
109014 INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc),
109015 INTERNAL_FUNCTION(sqlite_rename_test, 7, renameTableTest),
109016 INTERNAL_FUNCTION(sqlite_drop_column, 3, dropColumnFunc),
109017 INTERNAL_FUNCTION(sqlite_rename_quotefix,2, renameQuotefixFunc),
109018 };
109019 sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs));
109020 }
109021 #endif /* SQLITE_ALTER_TABLE */
109022
@@ -112737,21 +113007,10 @@
113007 pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
113008 #endif
113009 assert( pParse->pNewTable==0 );
113010 pParse->pNewTable = pTable;
113011
 
 
 
 
 
 
 
 
 
 
 
113012 /* Begin generating the code that will insert the table record into
113013 ** the schema table. Note in particular that we must go ahead
113014 ** and allocate the record number for the table entry now. Before any
113015 ** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
113016 ** indices to be created and the table record must come before the
@@ -114192,11 +114451,11 @@
114451
114452 #ifndef SQLITE_OMIT_AUTOINCREMENT
114453 /* Check to see if we need to create an sqlite_sequence table for
114454 ** keeping track of autoincrement keys.
114455 */
114456 if( (p->tabFlags & TF_Autoincrement)!=0 && !IN_SPECIAL_PARSE ){
114457 Db *pDb = &db->aDb[iDb];
114458 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114459 if( pDb->pSchema->pSeqTab==0 ){
114460 sqlite3NestedParse(pParse,
114461 "CREATE TABLE %Q.sqlite_sequence(name,seq)",
@@ -114223,10 +114482,21 @@
114482 sqlite3OomFault(db);
114483 return;
114484 }
114485 pParse->pNewTable = 0;
114486 db->mDbFlags |= DBFLAG_SchemaChange;
114487
114488 /* If this is the magic sqlite_sequence table used by autoincrement,
114489 ** then record a pointer to this table in the main database structure
114490 ** so that INSERT can find the table easily. */
114491 assert( !pParse->nested );
114492 #ifndef SQLITE_OMIT_AUTOINCREMENT
114493 if( strcmp(p->zName, "sqlite_sequence")==0 ){
114494 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114495 p->pSchema->pSeqTab = p;
114496 }
114497 #endif
114498 }
114499
114500 #ifndef SQLITE_OMIT_ALTERTABLE
114501 if( !pSelect && !p->pSelect ){
114502 assert( pCons && pEnd );
@@ -114266,10 +114536,20 @@
114536 goto create_view_fail;
114537 }
114538 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
114539 p = pParse->pNewTable;
114540 if( p==0 || pParse->nErr ) goto create_view_fail;
114541
114542 /* Legacy versions of SQLite allowed the use of the magic "rowid" column
114543 ** on a view, even though views do not have rowids. The following flag
114544 ** setting fixes this problem. But the fix can be disabled by compiling
114545 ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
114546 ** depend upon the old buggy behavior. */
114547 #ifndef SQLITE_ALLOW_ROWID_IN_VIEW
114548 p->tabFlags |= TF_NoVisibleRowid;
114549 #endif
114550
114551 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
114552 iDb = sqlite3SchemaToIndex(db, p->pSchema);
114553 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
114554 if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
114555
@@ -115827,11 +116107,11 @@
116107 goto exit_drop_index;
116108 }
116109 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
116110 if( pIndex==0 ){
116111 if( !ifExists ){
116112 sqlite3ErrorMsg(pParse, "no such index: %S", pName->a);
116113 }else{
116114 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
116115 }
116116 pParse->checkSchema = 1;
116117 goto exit_drop_index;
@@ -122970,11 +123250,11 @@
123250 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
123251 ipkColumn = i;
123252 bIdListInOrder = 0;
123253 }else{
123254 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
123255 pTabList->a, pColumn->a[i].zName);
123256 pParse->checkSchema = 1;
123257 goto insert_cleanup;
123258 }
123259 }
123260 }
@@ -123098,11 +123378,11 @@
123378 }
123379 }
123380 if( nColumn!=(pTab->nCol-nHidden) ){
123381 sqlite3ErrorMsg(pParse,
123382 "table %S has %d columns but %d values were supplied",
123383 pTabList->a, pTab->nCol-nHidden, nColumn);
123384 goto insert_cleanup;
123385 }
123386 }
123387 if( pColumn!=0 && nColumn!=pColumn->nId ){
123388 sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
@@ -123401,11 +123681,11 @@
123681 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
123682 sqlite3MayAbort(pParse);
123683 }else
123684 #endif
123685 {
123686 int isReplace = 0;/* Set to true if constraints may cause a replace */
123687 int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
123688 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
123689 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
123690 );
123691 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
@@ -123421,10 +123701,17 @@
123701 bUseSeek = (isReplace==0 || !sqlite3VdbeHasSubProgram(v));
123702 sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
123703 regIns, aRegIdx, 0, appendFlag, bUseSeek
123704 );
123705 }
123706 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
123707 }else if( pParse->bReturning ){
123708 /* If there is a RETURNING clause, populate the rowid register with
123709 ** constant value -1, in case one or more of the returned expressions
123710 ** refer to the "rowid" of the view. */
123711 sqlite3VdbeAddOp2(v, OP_Integer, -1, regRowid);
123712 #endif
123713 }
123714
123715 /* Update the count of rows that are inserted
123716 */
123717 if( regRowCount ){
@@ -130625,10 +130912,11 @@
130912 ** will be closed immediately after reading the meta-value. */
130913 if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_NONE ){
130914 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
130915 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
130916 sqlite3OomFault(db);
130917 pParse->rc = SQLITE_NOMEM;
130918 }
130919 if( rc!=SQLITE_OK ) return;
130920 openedTransaction = 1;
130921 }
130922
@@ -130860,10 +131148,11 @@
131148 if( db->init.busy==0 ){
131149 sqlite3VdbeSetSql(sParse.pVdbe, zSql, (int)(sParse.zTail-zSql), prepFlags);
131150 }
131151 if( db->mallocFailed ){
131152 sParse.rc = SQLITE_NOMEM_BKPT;
131153 sParse.checkSchema = 0;
131154 }
131155 if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
131156 if( sParse.checkSchema ){
131157 schemaIsValid(&sParse);
131158 }
@@ -131884,35 +132173,159 @@
132173 VdbeComment((v, "OFFSET"));
132174 }
132175 }
132176
132177 /*
132178 ** Add code that will check to make sure the array of registers starting at
132179 ** iMem form a distinct entry. This is used by both "SELECT DISTINCT ..." and
132180 ** distinct aggregates ("SELECT count(DISTINCT <expr>) ..."). Three strategies
132181 ** are available. Which is used depends on the value of parameter eTnctType,
132182 ** as follows:
132183 **
132184 ** WHERE_DISTINCT_UNORDERED/WHERE_DISTINCT_NOOP:
132185 ** Build an ephemeral table that contains all entries seen before and
132186 ** skip entries which have been seen before.
132187 **
132188 ** Parameter iTab is the cursor number of an ephemeral table that must
132189 ** be opened before the VM code generated by this routine is executed.
132190 ** The ephemeral cursor table is queried for a record identical to the
132191 ** record formed by the current array of registers. If one is found,
132192 ** jump to VM address addrRepeat. Otherwise, insert a new record into
132193 ** the ephemeral cursor and proceed.
132194 **
132195 ** The returned value in this case is a copy of parameter iTab.
132196 **
132197 ** WHERE_DISTINCT_ORDERED:
132198 ** In this case rows are being delivered sorted order. The ephermal
132199 ** table is not required. Instead, the current set of values
132200 ** is compared against previous row. If they match, the new row
132201 ** is not distinct and control jumps to VM address addrRepeat. Otherwise,
132202 ** the VM program proceeds with processing the new row.
132203 **
132204 ** The returned value in this case is the register number of the first
132205 ** in an array of registers used to store the previous result row so that
132206 ** it can be compared to the next. The caller must ensure that this
132207 ** register is initialized to NULL. (The fixDistinctOpenEph() routine
132208 ** will take care of this initialization.)
132209 **
132210 ** WHERE_DISTINCT_UNIQUE:
132211 ** In this case it has already been determined that the rows are distinct.
132212 ** No special action is required. The return value is zero.
132213 **
132214 ** Parameter pEList is the list of expressions used to generated the
132215 ** contents of each row. It is used by this routine to determine (a)
132216 ** how many elements there are in the array of registers and (b) the
132217 ** collation sequences that should be used for the comparisons if
132218 ** eTnctType is WHERE_DISTINCT_ORDERED.
132219 */
132220 static int codeDistinct(
132221 Parse *pParse, /* Parsing and code generating context */
132222 int eTnctType, /* WHERE_DISTINCT_* value */
132223 int iTab, /* A sorting index used to test for distinctness */
132224 int addrRepeat, /* Jump to here if not distinct */
132225 ExprList *pEList, /* Expression for each element */
132226 int regElem /* First element */
132227 ){
132228 int iRet = 0;
132229 int nResultCol = pEList->nExpr;
132230 Vdbe *v = pParse->pVdbe;
132231
132232 switch( eTnctType ){
132233 case WHERE_DISTINCT_ORDERED: {
132234 int i;
132235 int iJump; /* Jump destination */
132236 int regPrev; /* Previous row content */
132237
132238 /* Allocate space for the previous row */
132239 iRet = regPrev = pParse->nMem+1;
132240 pParse->nMem += nResultCol;
132241
132242 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
132243 for(i=0; i<nResultCol; i++){
132244 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
132245 if( i<nResultCol-1 ){
132246 sqlite3VdbeAddOp3(v, OP_Ne, regElem+i, iJump, regPrev+i);
132247 VdbeCoverage(v);
132248 }else{
132249 sqlite3VdbeAddOp3(v, OP_Eq, regElem+i, addrRepeat, regPrev+i);
132250 VdbeCoverage(v);
132251 }
132252 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
132253 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
132254 }
132255 assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );
132256 sqlite3VdbeAddOp3(v, OP_Copy, regElem, regPrev, nResultCol-1);
132257 break;
132258 }
132259
132260 case WHERE_DISTINCT_UNIQUE: {
132261 /* nothing to do */
132262 break;
132263 }
132264
132265 default: {
132266 int r1 = sqlite3GetTempReg(pParse);
132267 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, regElem, nResultCol);
132268 VdbeCoverage(v);
132269 sqlite3VdbeAddOp3(v, OP_MakeRecord, regElem, nResultCol, r1);
132270 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, regElem, nResultCol);
132271 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
132272 sqlite3ReleaseTempReg(pParse, r1);
132273 iRet = iTab;
132274 break;
132275 }
132276 }
132277
132278 return iRet;
132279 }
132280
132281 /*
132282 ** This routine runs after codeDistinct(). It makes necessary
132283 ** adjustments to the OP_OpenEphemeral opcode that the codeDistinct()
132284 ** routine made use of. This processing must be done separately since
132285 ** sometimes codeDistinct is called before the OP_OpenEphemeral is actually
132286 ** laid down.
132287 **
132288 ** WHERE_DISTINCT_NOOP:
132289 ** WHERE_DISTINCT_UNORDERED:
132290 **
132291 ** No adjustments necessary. This function is a no-op.
132292 **
132293 ** WHERE_DISTINCT_UNIQUE:
132294 **
132295 ** The ephemeral table is not needed. So change the
132296 ** OP_OpenEphemeral opcode into an OP_Noop.
132297 **
132298 ** WHERE_DISTINCT_ORDERED:
132299 **
132300 ** The ephemeral table is not needed. But we do need register
132301 ** iVal to be initialized to NULL. So change the OP_OpenEphemeral
132302 ** into an OP_Null on the iVal register.
132303 */
132304 static void fixDistinctOpenEph(
132305 Parse *pParse, /* Parsing and code generating context */
132306 int eTnctType, /* WHERE_DISTINCT_* value */
132307 int iVal, /* Value returned by codeDistinct() */
132308 int iOpenEphAddr /* Address of OP_OpenEphemeral instruction for iTab */
132309 ){
132310 if( eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED ){
132311 Vdbe *v = pParse->pVdbe;
132312 sqlite3VdbeChangeToNoop(v, iOpenEphAddr);
132313 if( sqlite3VdbeGetOp(v, iOpenEphAddr+1)->opcode==OP_Explain ){
132314 sqlite3VdbeChangeToNoop(v, iOpenEphAddr+1);
132315 }
132316 if( eTnctType==WHERE_DISTINCT_ORDERED ){
132317 /* Change the OP_OpenEphemeral to an OP_Null that sets the MEM_Cleared
132318 ** bit on the first register of the previous value. This will cause the
132319 ** OP_Ne added in codeDistinct() to always fail on the first iteration of
132320 ** the loop even if the first row is all NULLs. */
132321 VdbeOp *pOp = sqlite3VdbeGetOp(v, iOpenEphAddr);
132322 pOp->opcode = OP_Null;
132323 pOp->p1 = 1;
132324 pOp->p2 = iVal;
132325 }
132326 }
132327 }
132328
132329 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
132330 /*
132331 ** This function is called as part of inner-loop generation for a SELECT
@@ -132156,63 +132569,15 @@
132569 /* If the DISTINCT keyword was present on the SELECT statement
132570 ** and this row has been seen before, then do not make this row
132571 ** part of the result.
132572 */
132573 if( hasDistinct ){
132574 int eType = pDistinct->eTnctType;
132575 int iTab = pDistinct->tabTnct;
132576 assert( nResultCol==p->pEList->nExpr );
132577 iTab = codeDistinct(pParse, eType, iTab, iContinue, p->pEList, regResult);
132578 fixDistinctOpenEph(pParse, eType, iTab, pDistinct->addrTnct);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132579 if( pSort==0 ){
132580 codeOffset(v, p->iOffset, iContinue);
132581 }
132582 }
132583
@@ -132874,11 +133239,17 @@
133239 if( pS ){
133240 /* The "table" is actually a sub-select or a view in the FROM clause
133241 ** of the SELECT statement. Return the declaration type and origin
133242 ** data for the result-set column of the sub-select.
133243 */
133244 if( iCol<pS->pEList->nExpr
133245 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
133246 && iCol>=0
133247 #else
133248 && ALWAYS(iCol>=0)
133249 #endif
133250 ){
133251 /* If iCol is less than zero, then the expression requests the
133252 ** rowid of the sub-select or view. This expression is legal (see
133253 ** test case misc2.2.2) - it always evaluates to NULL.
133254 */
133255 NameContext sNC;
@@ -133804,11 +134175,11 @@
134175 /* Generate code for the left and right SELECT statements.
134176 */
134177 switch( p->op ){
134178 case TK_ALL: {
134179 int addr = 0;
134180 int nLimit = 0; /* Initialize to suppress harmless compiler warning */
134181 assert( !pPrior->pLimit );
134182 pPrior->iLimit = p->iLimit;
134183 pPrior->iOffset = p->iOffset;
134184 pPrior->pLimit = p->pLimit;
134185 rc = sqlite3Select(pParse, pPrior, &dest);
@@ -134660,13 +135031,16 @@
135031 }
135032 if( pExpr->op==TK_COLUMN
135033 && pExpr->iTable==pSubst->iTable
135034 && !ExprHasProperty(pExpr, EP_FixedCol)
135035 ){
135036 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
135037 if( pExpr->iColumn<0 ){
135038 pExpr->op = TK_NULL;
135039 }else
135040 #endif
135041 {
135042 Expr *pNew;
135043 Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
135044 Expr ifNullRow;
135045 assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
135046 assert( pExpr->pRight==0 );
@@ -136301,11 +136675,17 @@
136675 }
136676 while( pSel->pPrior ){ pSel = pSel->pPrior; }
136677 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
136678 pTab->iPKey = -1;
136679 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
136680 #ifndef SQLITE_ALLOW_ROWID_IN_VIEW
136681 /* The usual case - do not allow ROWID on a subquery */
136682 pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
136683 #else
136684 pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */
136685 #endif
136686
136687
136688 return pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
136689 }
136690
136691 /*
@@ -136788,12 +137168,14 @@
137168 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
137169 "argument");
137170 pFunc->iDistinct = -1;
137171 }else{
137172 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pE->x.pList,0,0);
137173 pFunc->iDistAddr = sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
137174 pFunc->iDistinct, 0, 0, (char*)pKeyInfo, P4_KEYINFO);
137175 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(DISTINCT)",
137176 pFunc->pFunc->zName));
137177 }
137178 }
137179 }
137180 }
137181
@@ -136821,11 +137203,16 @@
137203 ** If regAcc is non-zero and there are no min() or max() aggregates
137204 ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
137205 ** registers if register regAcc contains 0. The caller will take care
137206 ** of setting and clearing regAcc.
137207 */
137208 static void updateAccumulator(
137209 Parse *pParse,
137210 int regAcc,
137211 AggInfo *pAggInfo,
137212 int eDistinctType
137213 ){
137214 Vdbe *v = pParse->pVdbe;
137215 int i;
137216 int regHit = 0;
137217 int addrHitTest = 0;
137218 struct AggInfo_func *pF;
@@ -136867,17 +137254,16 @@
137254 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
137255 }else{
137256 nArg = 0;
137257 regAgg = 0;
137258 }
137259 if( pF->iDistinct>=0 && pList ){
137260 if( addrNext==0 ){
137261 addrNext = sqlite3VdbeMakeLabel(pParse);
137262 }
137263 pF->iDistinct = codeDistinct(pParse, eDistinctType,
137264 pF->iDistinct, addrNext, pList, regAgg);
 
137265 }
137266 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
137267 CollSeq *pColl = 0;
137268 struct ExprList_item *pItem;
137269 int j;
@@ -136925,11 +137311,11 @@
137311 Table *pTab, /* Table being queried */
137312 Index *pIdx /* Index used to optimize scan, or NULL */
137313 ){
137314 if( pParse->explain==2 ){
137315 int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
137316 sqlite3VdbeExplain(pParse, 0, "SCAN %s%s%s",
137317 pTab->zName,
137318 bCover ? " USING COVERING INDEX " : "",
137319 bCover ? pIdx->zName : ""
137320 );
137321 }
@@ -137498,14 +137884,14 @@
137884 */
137885 int addrTop = sqlite3VdbeCurrentAddr(v)+1;
137886
137887 pItem->regReturn = ++pParse->nMem;
137888 sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
137889 VdbeComment((v, "%!S", pItem));
137890 pItem->addrFillSub = addrTop;
137891 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
137892 ExplainQueryPlan((pParse, 1, "CO-ROUTINE %!S", pItem));
137893 sqlite3Select(pParse, pSub, &dest);
137894 pItem->pTab->nRowLogEst = pSub->nSelectRow;
137895 pItem->fg.viaCoroutine = 1;
137896 pItem->regResult = dest.iSdst;
137897 sqlite3VdbeEndCoroutine(v, pItem->regReturn);
@@ -137545,21 +137931,21 @@
137931 if( pItem->fg.isCorrelated==0 ){
137932 /* If the subquery is not correlated and if we are not inside of
137933 ** a trigger, then we only need to compute the value of the subquery
137934 ** once. */
137935 onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
137936 VdbeComment((v, "materialize %!S", pItem));
137937 }else{
137938 VdbeNoopComment((v, "materialize %!S", pItem));
137939 }
137940 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
137941 ExplainQueryPlan((pParse, 1, "MATERIALIZE %!S", pItem));
137942 sqlite3Select(pParse, pSub, &dest);
137943 pItem->pTab->nRowLogEst = pSub->nSelectRow;
137944 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
137945 retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
137946 VdbeComment((v, "end %!S", pItem));
137947 sqlite3VdbeChangeP1(v, topAddr, retAddr);
137948 sqlite3ClearTempRegCache(pParse);
137949 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
137950 CteUse *pCteUse = pItem->u2.pCteUse;
137951 pCteUse->addrM9e = pItem->addrFillSub;
@@ -137905,10 +138291,24 @@
138291 int addrSetAbort; /* Set the abort flag and return */
138292 int addrTopOfLoop; /* Top of the input loop */
138293 int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */
138294 int addrReset; /* Subroutine for resetting the accumulator */
138295 int regReset; /* Return address register for reset subroutine */
138296 ExprList *pDistinct = 0;
138297 u16 distFlag = 0;
138298 int eDist = WHERE_DISTINCT_NOOP;
138299
138300 if( pAggInfo->nFunc==1
138301 && pAggInfo->aFunc[0].iDistinct>=0
138302 && pAggInfo->aFunc[0].pFExpr->x.pList
138303 ){
138304 Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
138305 pExpr = sqlite3ExprDup(db, pExpr, 0);
138306 pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
138307 pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr);
138308 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
138309 }
138310
138311 /* If there is a GROUP BY clause we might need a sorting index to
138312 ** implement it. Allocate that sorting index now. If it turns out
138313 ** that we do not need it after all, the OP_SorterOpen instruction
138314 ** will be converted into a Noop.
@@ -137941,14 +138341,16 @@
138341 ** it might be a single loop that uses an index to extract information
138342 ** in the right order to begin with.
138343 */
138344 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
138345 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
138346 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
138347 WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
138348 );
138349 sqlite3ExprListDelete(db, pDistinct);
138350 if( pWInfo==0 ) goto select_end;
138351 eDist = sqlite3WhereIsDistinct(pWInfo);
138352 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
138353 if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
138354 /* The optimizer is able to deliver rows in group by order so
138355 ** we do not have to sort. The OP_OpenEphemeral table will be
138356 ** cancelled later because we still need to use the pKeyInfo
@@ -138062,11 +138464,11 @@
138464
138465 /* Update the aggregate accumulators based on the content of
138466 ** the current row
138467 */
138468 sqlite3VdbeJumpHere(v, addr1);
138469 updateAccumulator(pParse, iUseFlag, pAggInfo, eDist);
138470 sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
138471 VdbeComment((v, "indicate data in accumulator"));
138472
138473 /* End of the loop
138474 */
@@ -138119,10 +138521,14 @@
138521 resetAccumulator(pParse, pAggInfo);
138522 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
138523 VdbeComment((v, "indicate accumulator empty"));
138524 sqlite3VdbeAddOp1(v, OP_Return, regReset);
138525
138526 if( eDist!=WHERE_DISTINCT_NOOP ){
138527 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
138528 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
138529 }
138530 } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
138531 else {
138532 Table *pTab;
138533 if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){
138534 /* If isSimpleCount() returns a pointer to a Table structure, then
@@ -138182,10 +138588,13 @@
138588 sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem);
138589 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
138590 explainSimpleCount(pParse, pTab, pBest);
138591 }else{
138592 int regAcc = 0; /* "populate accumulators" flag */
138593 ExprList *pDistinct = 0;
138594 u16 distFlag = 0;
138595 int eDist;
138596
138597 /* If there are accumulator registers but no min() or max() functions
138598 ** without FILTER clauses, allocate register regAcc. Register regAcc
138599 ** will contain 0 the first time the inner loop runs, and 1 thereafter.
138600 ** The code generated by updateAccumulator() uses this to ensure
@@ -138205,10 +138614,13 @@
138614 }
138615 if( i==pAggInfo->nFunc ){
138616 regAcc = ++pParse->nMem;
138617 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
138618 }
138619 }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
138620 pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
138621 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
138622 }
138623
138624 /* This case runs if the aggregate has no GROUP BY clause. The
138625 ** processing is much simpler since there is only a single row
138626 ** of output.
@@ -138224,16 +138636,22 @@
138636 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
138637 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
138638
138639 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
138640 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
138641 pDistinct, minMaxFlag|distFlag, 0);
138642 if( pWInfo==0 ){
138643 goto select_end;
138644 }
138645 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
138646 eDist = sqlite3WhereIsDistinct(pWInfo);
138647 updateAccumulator(pParse, regAcc, pAggInfo, eDist);
138648 if( eDist!=WHERE_DISTINCT_NOOP ){
138649 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
138650 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
138651 }
138652
138653 if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
138654 if( minMaxFlag ){
138655 sqlite3WhereMinMaxOptEarlyOut(v, pWInfo);
138656 }
138657 SELECTTRACE(1,pParse,p,("WhereEnd\n"));
@@ -138576,11 +138994,15 @@
138994 if( pTrig->pTabSchema==pTab->pSchema
138995 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
138996 ){
138997 pTrig->pNext = pList;
138998 pList = pTrig;
138999 }else if( pTrig->op==TK_RETURNING
139000 #ifndef SQLITE_OMIT_VIRTUALTABLE
139001 && pParse->db->pVtabCtx==0
139002 #endif
139003 ){
139004 assert( pParse->bReturning );
139005 assert( &(pParse->u1.pReturning->retTrig) == pTrig );
139006 pTrig->table = pTab->zName;
139007 pTrig->pTabSchema = pTab->pSchema;
139008 pTrig->pNext = pList;
@@ -138716,16 +139138,16 @@
139138 /* INSTEAD of triggers are only for views and views only support INSTEAD
139139 ** of triggers.
139140 */
139141 if( pTab->pSelect && tr_tm!=TK_INSTEAD ){
139142 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
139143 (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName->a);
139144 goto trigger_orphan_error;
139145 }
139146 if( !pTab->pSelect && tr_tm==TK_INSTEAD ){
139147 sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF"
139148 " trigger on table: %S", pTableName->a);
139149 goto trigger_orphan_error;
139150 }
139151
139152 #ifndef SQLITE_OMIT_AUTHORIZATION
139153 if( !IN_RENAME_OBJECT ){
@@ -139118,11 +139540,11 @@
139540 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
139541 if( pTrigger ) break;
139542 }
139543 if( !pTrigger ){
139544 if( !noErr ){
139545 sqlite3ErrorMsg(pParse, "no such trigger: %S", pName->a);
139546 }else{
139547 sqlite3CodeVerifyNamedSchema(pParse, zDb);
139548 }
139549 pParse->checkSchema = 1;
139550 goto drop_trigger_cleanup;
@@ -139650,12 +140072,12 @@
140072 /* If one was specified, code the WHEN clause. If it evaluates to false
140073 ** (or NULL) the sub-vdbe is immediately halted by jumping to the
140074 ** OP_Halt inserted at the end of the program. */
140075 if( pTrigger->pWhen ){
140076 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
140077 if( db->mallocFailed==0
140078 && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
140079 ){
140080 iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
140081 sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
140082 }
140083 sqlite3ExprDelete(db, pWhen);
@@ -140709,11 +141131,16 @@
141131 }
141132 }
141133
141134 /* Top of the update loop */
141135 if( eOnePass!=ONEPASS_OFF ){
141136 if( aiCurOnePass[0]!=iDataCur
141137 && aiCurOnePass[1]!=iDataCur
141138 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
141139 && !isView
141140 #endif
141141 ){
141142 assert( pPk );
141143 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey);
141144 VdbeCoverage(v);
141145 }
141146 if( eOnePass!=ONEPASS_SINGLE ){
@@ -144040,20 +144467,12 @@
144467 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
144468 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
144469 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
144470
144471 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
144472 str.printfFlags = SQLITE_PRINTF_INTERNAL;
144473 sqlite3_str_appendf(&str, "%s %S", isSearch ? "SEARCH" : "SCAN", pItem);
 
 
 
 
 
 
 
 
144474 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
144475 const char *zFmt = 0;
144476 Index *pIdx;
144477
144478 assert( pLoop->u.btree.pIndex!=0 );
@@ -146348,10 +146767,11 @@
146767 testcase( pAlt->eOperator & WO_IN );
146768 VdbeModuleComment((v, "begin transitive constraint"));
146769 sEAlt = *pAlt->pExpr;
146770 sEAlt.pLeft = pE->pLeft;
146771 sqlite3ExprIfFalse(pParse, &sEAlt, addrCont, SQLITE_JUMPIFNULL);
146772 pAlt->wtFlags |= TERM_CODED;
146773 }
146774
146775 /* For a LEFT OUTER JOIN, generate code that will record the fact that
146776 ** at least one row of the right table has matched the left table.
146777 */
@@ -148784,11 +149204,11 @@
149204 const char *zColl = pIdx->azColl[iCol];
149205
149206 for(i=0; i<pList->nExpr; i++){
149207 Expr *p = sqlite3ExprSkipCollateAndLikely(pList->a[i].pExpr);
149208 if( ALWAYS(p!=0)
149209 && (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
149210 && p->iColumn==pIdx->aiColumn[iCol]
149211 && p->iTable==iBase
149212 ){
149213 CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);
149214 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
@@ -148849,11 +149269,12 @@
149269 ** current SELECT is a correlated sub-query.
149270 */
149271 for(i=0; i<pDistinct->nExpr; i++){
149272 Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
149273 if( NEVER(p==0) ) continue;
149274 if( p->op!=TK_COLUMN && p->op!=TK_AGG_COLUMN ) continue;
149275 if( p->iTable==iBase && p->iColumn<0 ) return 1;
149276 }
149277
149278 /* Loop through all indices on the table, checking each to see if it makes
149279 ** the DISTINCT qualifier redundant. It does so if:
149280 **
@@ -148867,10 +149288,11 @@
149288 ** 3. All of those index columns for which the WHERE clause does not
149289 ** contain a "col=X" term are subject to a NOT NULL constraint.
149290 */
149291 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
149292 if( !IsUniqueIndex(pIdx) ) continue;
149293 if( pIdx->pPartIdxWhere ) continue;
149294 for(i=0; i<pIdx->nKeyCol; i++){
149295 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
149296 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
149297 if( indexColumnNotNull(pIdx, i)==0 ) break;
149298 }
@@ -148921,18 +149343,18 @@
149343 pOp->opcode = OP_Copy;
149344 pOp->p1 = pOp->p2 + iRegister;
149345 pOp->p2 = pOp->p3;
149346 pOp->p3 = 0;
149347 }else if( pOp->opcode==OP_Rowid ){
149348 pOp->opcode = OP_Sequence;
149349 pOp->p1 = iAutoidxCur;
149350 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
149351 if( iAutoidxCur==0 ){
149352 pOp->opcode = OP_Null;
 
149353 pOp->p3 = 0;
149354 }
149355 #endif
149356 }
149357 }
149358 }
149359
149360 /*
@@ -149093,11 +149515,11 @@
149515 pLoop->aLTerm[nKeyCol++] = pTerm;
149516 idxCols |= cMask;
149517 }
149518 }
149519 }
149520 assert( nKeyCol>0 || pParse->db->mallocFailed );
149521 pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol;
149522 pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
149523 | WHERE_AUTO_INDEX;
149524
149525 /* Count the number of additional columns needed to create a
@@ -152114,11 +152536,11 @@
152536 */
152537 for(i=0; i<nOrderBy; i++){
152538 if( MASKBIT(i) & obSat ) continue;
152539 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
152540 if( NEVER(pOBExpr==0) ) continue;
152541 if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) continue;
152542 if( pOBExpr->iTable!=iCur ) continue;
152543 pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
152544 ~ready, eqOpMask, 0);
152545 if( pTerm==0 ) continue;
152546 if( pTerm->eOperator==WO_IN ){
@@ -152243,11 +152665,11 @@
152665 testcase( wctrlFlags & WHERE_GROUPBY );
152666 testcase( wctrlFlags & WHERE_DISTINCTBY );
152667 if( NEVER(pOBExpr==0) ) continue;
152668 if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
152669 if( iColumn>=XN_ROWID ){
152670 if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) continue;
152671 if( pOBExpr->iTable!=iCur ) continue;
152672 if( pOBExpr->iColumn!=iColumn ) continue;
152673 }else{
152674 Expr *pIdxExpr = pIndex->aColExpr->a[j].pExpr;
152675 if( sqlite3ExprCompareSkip(pOBExpr, pIdxExpr, iCur) ){
@@ -153344,11 +153766,12 @@
153766 ** LEFT JOIN t2
153767 ** LEFT JOIN t3 ON (t1.ipk=t3.ipk)
153768 */
153769 notReady = ~(Bitmask)0;
153770 if( pWInfo->nLevel>=2
153771 && pResultSet!=0 /* these two combine to guarantee */
153772 && 0==(wctrlFlags & WHERE_AGG_DISTINCT) /* condition (1) above */
153773 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
153774 ){
153775 int i;
153776 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
153777 if( sWLB.pOrderBy ){
@@ -153857,11 +154280,11 @@
154280 assert( pOp->opcode!=OP_Rowid || pOp->p1!=pLevel->iTabCur );
154281 assert( pOp->opcode!=OP_IfNullRow || pOp->p1!=pLevel->iTabCur );
154282 #endif
154283 pOp = sqlite3VdbeGetOp(v, k);
154284 pLastOp = pOp + (last - k);
154285 assert( pOp<=pLastOp );
154286 do{
154287 if( pOp->p1!=pLevel->iTabCur ){
154288 /* no-op */
154289 }else if( pOp->opcode==OP_Column
154290 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
@@ -154709,10 +155132,11 @@
155132 /* no break */ deliberate_fall_through
155133
155134 case TK_AGG_FUNCTION:
155135 case TK_COLUMN: {
155136 int iCol = -1;
155137 if( pParse->db->mallocFailed ) return WRC_Abort;
155138 if( p->pSub ){
155139 int i;
155140 for(i=0; i<p->pSub->nExpr; i++){
155141 if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
155142 iCol = i;
@@ -154818,13 +155242,18 @@
155242 ){
155243 if( pAppend ){
155244 int i;
155245 int nInit = pList ? pList->nExpr : 0;
155246 for(i=0; i<pAppend->nExpr; i++){
155247 sqlite3 *db = pParse->db;
155248 Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0);
155249 assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
155250 if( db->mallocFailed ){
155251 sqlite3ExprDelete(db, pDup);
155252 break;
155253 }
155254 if( bIntToNull ){
155255 int iDummy;
155256 Expr *pSub;
155257 for(pSub=pDup; ExprHasProperty(pSub, EP_Skip); pSub=pSub->pLeft){
155258 assert( pSub );
155259 }
@@ -155601,19 +156030,19 @@
156030 VdbeCoverage(v);
156031 sqlite3ReleaseTempReg(pParse, regTmp);
156032 }
156033
156034 if( pWin->bExprArgs ){
156035 int iOp = sqlite3VdbeCurrentAddr(v);
156036 int iEnd;
156037
156038 nArg = pWin->pOwner->x.pList->nExpr;
156039 regArg = sqlite3GetTempRange(pParse, nArg);
156040 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
156041
156042 for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
156043 VdbeOp *pOp = sqlite3VdbeGetOp(v, iOp);
156044 if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
156045 pOp->p1 = csr;
156046 }
156047 }
156048 }
@@ -155968,11 +156397,11 @@
156397 ** is OP_Ge, the generated code is equivalent to:
156398 **
156399 ** if( csr1.peerVal - regVal <= csr2.peerVal ) goto lbl;
156400 **
156401 ** A special type of arithmetic is used such that if csr1.peerVal is not
156402 ** a numeric type (real or integer), then the result of the addition
156403 ** or subtraction is a a copy of csr1.peerVal.
156404 */
156405 static void windowCodeRangeTest(
156406 WindowCodeArg *p,
156407 int op, /* OP_Ge, OP_Gt, or OP_Le */
@@ -155987,11 +156416,16 @@
156416 int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */
156417 int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */
156418 int regString = ++pParse->nMem; /* Reg. for constant value '' */
156419 int arith = OP_Add; /* OP_Add or OP_Subtract */
156420 int addrGe; /* Jump destination */
156421 int addrDone = sqlite3VdbeMakeLabel(pParse); /* Address past OP_Ge */
156422 CollSeq *pColl;
156423
156424 /* Read the peer-value from each cursor into a register */
156425 windowReadPeerValues(p, csr1, reg1);
156426 windowReadPeerValues(p, csr2, reg2);
156427
156428 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
156429 assert( pOrderBy && pOrderBy->nExpr==1 );
156430 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
156431 switch( op ){
@@ -156000,38 +156434,15 @@
156434 default: assert( op==OP_Le ); op = OP_Ge; break;
156435 }
156436 arith = OP_Subtract;
156437 }
156438
 
 
 
 
156439 VdbeModuleComment((v, "CodeRangeTest: if( R%d %s R%d %s R%d ) goto lbl",
156440 reg1, (arith==OP_Add ? "+" : "-"), regVal,
156441 ((op==OP_Ge) ? ">=" : (op==OP_Le) ? "<=" : (op==OP_Gt) ? ">" : "<"), reg2
156442 ));
156443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156444 /* If the BIGNULL flag is set for the ORDER BY, then it is required to
156445 ** consider NULL values to be larger than all other values, instead of
156446 ** the usual smaller. The VDBE opcodes OP_Ge and so on do not handle this
156447 ** (and adding that capability causes a performance regression), so
156448 ** instead if the BIGNULL flag is set then cases where either reg1 or
@@ -156064,27 +156475,50 @@
156475 sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl);
156476 VdbeCoverage(v);
156477 break;
156478 default: assert( op==OP_Lt ); /* no-op */ break;
156479 }
156480 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
156481
156482 /* This block runs if reg1 is not NULL, but reg2 is. */
156483 sqlite3VdbeJumpHere(v, addr);
156484 sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
156485 if( op==OP_Gt || op==OP_Ge ){
156486 sqlite3VdbeChangeP2(v, -1, addrDone);
156487 }
156488 }
156489
156490 /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
156491 ** This block adds (or subtracts for DESC) the numeric value in regVal
156492 ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
156493 ** then leave reg1 as it is. In pseudo-code, this is implemented as:
156494 **
156495 ** if( reg1>='' ) goto addrGe;
156496 ** reg1 = reg1 +/- regVal
156497 ** addrGe:
156498 **
156499 ** Since all strings and blobs are greater-than-or-equal-to an empty string,
156500 ** the add/subtract is skipped for these, as required. If reg1 is a NULL,
156501 ** then the arithmetic is performed, but since adding or subtracting from
156502 ** NULL is always NULL anyway, this case is handled as required too. */
156503 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
156504 addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
156505 VdbeCoverage(v);
156506 if( (op==OP_Ge && arith==OP_Add) || (op==OP_Le && arith==OP_Subtract) ){
156507 sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
156508 }
156509 sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
156510 sqlite3VdbeJumpHere(v, addrGe);
156511
156512 /* Compare registers reg2 and reg1, taking the jump if required. Note that
156513 ** control skips over this test if the BIGNULL flag is set and either
156514 ** reg1 or reg2 contain a NULL value. */
156515 sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
156516 pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr);
156517 sqlite3VdbeAppendP4(v, (void*)pColl, P4_COLLSEQ);
156518 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
156519 sqlite3VdbeResolveLabel(v, addrDone);
156520
156521 assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
156522 testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
156523 testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
156524 testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
@@ -169758,11 +170192,11 @@
170192 /*
170193 ** The assert_fts3_nc() macro is similar to the assert() macro, except that it
170194 ** is used for assert() conditions that are true only if it can be
170195 ** guranteed that the database is not corrupt.
170196 */
170197 #ifdef SQLITE_DEBUG
170198 SQLITE_API extern int sqlite3_fts3_may_be_corrupt;
170199 # define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
170200 #else
170201 # define assert_fts3_nc(x) assert(x)
170202 #endif
@@ -170314,11 +170748,13 @@
170748 ** This variable is set to false when running tests for which the on disk
170749 ** structures should not be corrupt. Otherwise, true. If it is false, extra
170750 ** assert() conditions in the fts3 code are activated - conditions that are
170751 ** only true if it is guaranteed that the fts3 database is not corrupt.
170752 */
170753 #ifdef SQLITE_DEBUG
170754 SQLITE_API int sqlite3_fts3_may_be_corrupt = 1;
170755 #endif
170756
170757 /*
170758 ** Write a 64-bit variable-length integer to memory starting at p[0].
170759 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
170760 ** The number of bytes written is returned.
@@ -173574,18 +174010,24 @@
174010 /*
174011 ** Implementation of xBegin() method.
174012 */
174013 static int fts3BeginMethod(sqlite3_vtab *pVtab){
174014 Fts3Table *p = (Fts3Table*)pVtab;
174015 int rc;
174016 UNUSED_PARAMETER(pVtab);
174017 assert( p->pSegments==0 );
174018 assert( p->nPendingData==0 );
174019 assert( p->inTransaction!=1 );
 
 
174020 p->nLeafAdd = 0;
174021 rc = fts3SetHasStat(p);
174022 #ifdef SQLITE_DEBUG
174023 if( rc==SQLITE_OK ){
174024 p->inTransaction = 1;
174025 p->mxSavepoint = -1;
174026 }
174027 #endif
174028 return rc;
174029 }
174030
174031 /*
174032 ** Implementation of xCommit() method. This is a no-op. The contents of
174033 ** the pending-terms hash-table have already been flushed into the database
@@ -195860,10 +196302,14 @@
196302 if( sqlite3_value_type(pVal)==SQLITE_BLOB
196303 && (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord))
196304 ){
196305 const unsigned char *a = sqlite3_value_blob(pVal);
196306 int nVertex;
196307 if( a==0 ){
196308 sqlite3_result_error_nomem(pCtx);
196309 return 0;
196310 }
196311 nVertex = (a[1]<<16) + (a[2]<<8) + a[3];
196312 if( (a[0]==0 || a[0]==1)
196313 && (nVertex*2*sizeof(GeoCoord) + 4)==(unsigned int)nByte
196314 ){
196315 p = sqlite3_malloc64( sizeof(*p) + (nVertex-1)*2*sizeof(GeoCoord) );
@@ -196233,11 +196679,11 @@
196679 aCoord[0].f = mnX;
196680 aCoord[1].f = mxX;
196681 aCoord[2].f = mnY;
196682 aCoord[3].f = mxY;
196683 }
196684 }else if( aCoord ){
196685 memset(aCoord, 0, sizeof(RtreeCoord)*4);
196686 }
196687 return pOut;
196688 }
196689
@@ -226018,10 +226464,11 @@
226464 **************************************************************************
226465 ** Below this point is the implementation of the fts5_decode() scalar
226466 ** function only.
226467 */
226468
226469 #ifdef SQLITE_TEST
226470 /*
226471 ** Decode a segment-data rowid from the %_data table. This function is
226472 ** the opposite of macro FTS5_SEGMENT_ROWID().
226473 */
226474 static void fts5DecodeRowid(
@@ -226040,11 +226487,13 @@
226487 *pbDlidx = (int)(iRowid & 0x0001);
226488 iRowid >>= FTS5_DATA_DLI_B;
226489
226490 *piSegid = (int)(iRowid & (((i64)1 << FTS5_DATA_ID_B) - 1));
226491 }
226492 #endif /* SQLITE_TEST */
226493
226494 #ifdef SQLITE_TEST
226495 static void fts5DebugRowid(int *pRc, Fts5Buffer *pBuf, i64 iKey){
226496 int iSegid, iHeight, iPgno, bDlidx; /* Rowid compenents */
226497 fts5DecodeRowid(iKey, &iSegid, &bDlidx, &iHeight, &iPgno);
226498
226499 if( iSegid==0 ){
@@ -226058,11 +226507,13 @@
226507 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "{%ssegid=%d h=%d pgno=%d}",
226508 bDlidx ? "dlidx " : "", iSegid, iHeight, iPgno
226509 );
226510 }
226511 }
226512 #endif /* SQLITE_TEST */
226513
226514 #ifdef SQLITE_TEST
226515 static void fts5DebugStructure(
226516 int *pRc, /* IN/OUT: error code */
226517 Fts5Buffer *pBuf,
226518 Fts5Structure *p
226519 ){
@@ -226080,11 +226531,13 @@
226531 );
226532 }
226533 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "}");
226534 }
226535 }
226536 #endif /* SQLITE_TEST */
226537
226538 #ifdef SQLITE_TEST
226539 /*
226540 ** This is part of the fts5_decode() debugging aid.
226541 **
226542 ** Arguments pBlob/nBlob contain a serialized Fts5Structure object. This
226543 ** function appends a human-readable representation of the same object
@@ -226105,11 +226558,13 @@
226558 }
226559
226560 fts5DebugStructure(pRc, pBuf, p);
226561 fts5StructureRelease(p);
226562 }
226563 #endif /* SQLITE_TEST */
226564
226565 #ifdef SQLITE_TEST
226566 /*
226567 ** This is part of the fts5_decode() debugging aid.
226568 **
226569 ** Arguments pBlob/nBlob contain an "averages" record. This function
226570 ** appends a human-readable representation of record to the buffer passed
@@ -226128,11 +226583,13 @@
226583 i += sqlite3Fts5GetVarint(&pBlob[i], &iVal);
226584 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "%s%d", zSpace, (int)iVal);
226585 zSpace = " ";
226586 }
226587 }
226588 #endif /* SQLITE_TEST */
226589
226590 #ifdef SQLITE_TEST
226591 /*
226592 ** Buffer (a/n) is assumed to contain a list of serialized varints. Read
226593 ** each varint and append its string representation to buffer pBuf. Return
226594 ** after either the input buffer is exhausted or a 0 value is read.
226595 **
@@ -226145,11 +226602,13 @@
226602 iOff += fts5GetVarint32(&a[iOff], iVal);
226603 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %d", iVal);
226604 }
226605 return iOff;
226606 }
226607 #endif /* SQLITE_TEST */
226608
226609 #ifdef SQLITE_TEST
226610 /*
226611 ** The start of buffer (a/n) contains the start of a doclist. The doclist
226612 ** may or may not finish within the buffer. This function appends a text
226613 ** representation of the part of the doclist that is present to buffer
226614 ** pBuf.
@@ -226178,11 +226637,13 @@
226637 }
226638 }
226639
226640 return iOff;
226641 }
226642 #endif /* SQLITE_TEST */
226643
226644 #ifdef SQLITE_TEST
226645 /*
226646 ** This function is part of the fts5_decode() debugging function. It is
226647 ** only ever used with detail=none tables.
226648 **
226649 ** Buffer (pData/nData) contains a doclist in the format used by detail=none
@@ -226219,11 +226680,13 @@
226680 }
226681
226682 sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %lld%s", iRowid, zApp);
226683 }
226684 }
226685 #endif /* SQLITE_TEST */
226686
226687 #ifdef SQLITE_TEST
226688 /*
226689 ** The implementation of user-defined scalar function fts5_decode().
226690 */
226691 static void fts5DecodeFunction(
226692 sqlite3_context *pCtx, /* Function call context */
@@ -226428,11 +226891,13 @@
226891 }else{
226892 sqlite3_result_error_code(pCtx, rc);
226893 }
226894 fts5BufferFree(&s);
226895 }
226896 #endif /* SQLITE_TEST */
226897
226898 #ifdef SQLITE_TEST
226899 /*
226900 ** The implementation of user-defined scalar function fts5_rowid().
226901 */
226902 static void fts5RowidFunction(
226903 sqlite3_context *pCtx, /* Function call context */
@@ -226462,10 +226927,11 @@
226927 "first arg to fts5_rowid() must be 'segment'" , -1
226928 );
226929 }
226930 }
226931 }
226932 #endif /* SQLITE_TEST */
226933
226934 /*
226935 ** This is called as part of registering the FTS5 module with database
226936 ** connection db. It registers several user-defined scalar functions useful
226937 ** with FTS5.
@@ -226472,10 +226938,11 @@
226938 **
226939 ** If successful, SQLITE_OK is returned. If an error occurs, some other
226940 ** SQLite error code is returned instead.
226941 */
226942 static int sqlite3Fts5IndexInit(sqlite3 *db){
226943 #ifdef SQLITE_TEST
226944 int rc = sqlite3_create_function(
226945 db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
226946 );
226947
226948 if( rc==SQLITE_OK ){
@@ -226489,10 +226956,13 @@
226956 rc = sqlite3_create_function(
226957 db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0
226958 );
226959 }
226960 return rc;
226961 #else
226962 return SQLITE_OK;
226963 #endif
226964 }
226965
226966
226967 static int sqlite3Fts5IndexReset(Fts5Index *p){
226968 assert( p->pStruct==0 || p->iStructVersion!=0 );
@@ -226524,11 +226994,13 @@
226994 ** This variable is set to false when running tests for which the on disk
226995 ** structures should not be corrupt. Otherwise, true. If it is false, extra
226996 ** assert() conditions in the fts5 code are activated - conditions that are
226997 ** only true if it is guaranteed that the fts5 database is not corrupt.
226998 */
226999 #ifdef SQLITE_DEBUG
227000 SQLITE_API int sqlite3_fts5_may_be_corrupt = 1;
227001 #endif
227002
227003
227004 typedef struct Fts5Auxdata Fts5Auxdata;
227005 typedef struct Fts5Auxiliary Fts5Auxiliary;
227006 typedef struct Fts5Cursor Fts5Cursor;
@@ -229290,11 +229762,11 @@
229762 int nArg, /* Number of args */
229763 sqlite3_value **apUnused /* Function arguments */
229764 ){
229765 assert( nArg==0 );
229766 UNUSED_PARAM2(nArg, apUnused);
229767 sqlite3_result_text(pCtx, "fts5: 2021-04-07 13:20:34 c22e47c77a35ebcd1fdfc0caea9119dd5e24e76d5fdd0f2ffbb58205a7242297", -1, SQLITE_TRANSIENT);
229768 }
229769
229770 /*
229771 ** Return true if zName is the extension on one of the shadow tables used
229772 ** by this module.
@@ -234216,12 +234688,12 @@
234688 }
234689 #endif /* SQLITE_CORE */
234690 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234691
234692 /************** End of stmt.c ************************************************/
234693 #if __LINE__!=234693
234694 #undef SQLITE_SOURCE_ID
234695 #define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e158alt2"
234696 #endif
234697 /* Return the source-id for this library */
234698 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234699 /************************** End of sqlite3.c ******************************/
234700
+18 -3
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121121
**
122122
** See also: [sqlite3_libversion()],
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126
-#define SQLITE_VERSION "3.35.4"
127
-#define SQLITE_VERSION_NUMBER 3035004
128
-#define SQLITE_SOURCE_ID "2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db635aa"
126
+#define SQLITE_VERSION "3.36.0"
127
+#define SQLITE_VERSION_NUMBER 3036000
128
+#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -1126,10 +1126,23 @@
11261126
** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
11271127
** in wal mode after the client has finished copying pages from the wal
11281128
** file to the database file, but before the *-shm file is updated to
11291129
** record the fact that the pages have been checkpointed.
11301130
** </ul>
1131
+**
1132
+** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1133
+** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1134
+** whether or not there is a database client in another process with a wal-mode
1135
+** transaction open on the database or not. It is only available on unix.The
1136
+** (void*) argument passed with this file-control should be a pointer to a
1137
+** value of type (int). The integer value is set to 1 if the database is a wal
1138
+** mode database and there exists at least one client in another process that
1139
+** currently has an SQL transaction open on the database. It is set to 0 if
1140
+** the database is not a wal-mode db, or if there is no such connection in any
1141
+** other process. This opcode cannot be used to detect transactions opened
1142
+** by clients within the current process, only within other processes.
1143
+** </ul>
11311144
*/
11321145
#define SQLITE_FCNTL_LOCKSTATE 1
11331146
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
11341147
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
11351148
#define SQLITE_FCNTL_LAST_ERRNO 4
@@ -1165,10 +1178,12 @@
11651178
#define SQLITE_FCNTL_DATA_VERSION 35
11661179
#define SQLITE_FCNTL_SIZE_LIMIT 36
11671180
#define SQLITE_FCNTL_CKPT_DONE 37
11681181
#define SQLITE_FCNTL_RESERVE_BYTES 38
11691182
#define SQLITE_FCNTL_CKPT_START 39
1183
+
1184
+#define SQLITE_FCNTL_EXTERNAL_READER 40
11701185
11711186
/* deprecated names */
11721187
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
11731188
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
11741189
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
11751190
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.35.4"
127 #define SQLITE_VERSION_NUMBER 3035004
128 #define SQLITE_SOURCE_ID "2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db635aa"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1126,10 +1126,23 @@
1126 ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
1127 ** in wal mode after the client has finished copying pages from the wal
1128 ** file to the database file, but before the *-shm file is updated to
1129 ** record the fact that the pages have been checkpointed.
1130 ** </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
1131 */
1132 #define SQLITE_FCNTL_LOCKSTATE 1
1133 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1134 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
1135 #define SQLITE_FCNTL_LAST_ERRNO 4
@@ -1165,10 +1178,12 @@
1165 #define SQLITE_FCNTL_DATA_VERSION 35
1166 #define SQLITE_FCNTL_SIZE_LIMIT 36
1167 #define SQLITE_FCNTL_CKPT_DONE 37
1168 #define SQLITE_FCNTL_RESERVE_BYTES 38
1169 #define SQLITE_FCNTL_CKPT_START 39
 
 
1170
1171 /* deprecated names */
1172 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1173 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1174 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
1175
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.36.0"
127 #define SQLITE_VERSION_NUMBER 3036000
128 #define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1126,10 +1126,23 @@
1126 ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
1127 ** in wal mode after the client has finished copying pages from the wal
1128 ** file to the database file, but before the *-shm file is updated to
1129 ** record the fact that the pages have been checkpointed.
1130 ** </ul>
1131 **
1132 ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1133 ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1134 ** whether or not there is a database client in another process with a wal-mode
1135 ** transaction open on the database or not. It is only available on unix.The
1136 ** (void*) argument passed with this file-control should be a pointer to a
1137 ** value of type (int). The integer value is set to 1 if the database is a wal
1138 ** mode database and there exists at least one client in another process that
1139 ** currently has an SQL transaction open on the database. It is set to 0 if
1140 ** the database is not a wal-mode db, or if there is no such connection in any
1141 ** other process. This opcode cannot be used to detect transactions opened
1142 ** by clients within the current process, only within other processes.
1143 ** </ul>
1144 */
1145 #define SQLITE_FCNTL_LOCKSTATE 1
1146 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1147 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
1148 #define SQLITE_FCNTL_LAST_ERRNO 4
@@ -1165,10 +1178,12 @@
1178 #define SQLITE_FCNTL_DATA_VERSION 35
1179 #define SQLITE_FCNTL_SIZE_LIMIT 36
1180 #define SQLITE_FCNTL_CKPT_DONE 37
1181 #define SQLITE_FCNTL_RESERVE_BYTES 38
1182 #define SQLITE_FCNTL_CKPT_START 39
1183
1184 #define SQLITE_FCNTL_EXTERNAL_READER 40
1185
1186 /* deprecated names */
1187 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1188 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1189 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
1190

Keyboard Shortcuts

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