Fossil SCM

Merge updates from trunk.

mistachkin 2014-10-16 02:16 warningFix merge
Commit 1b6dfe8178199bffcafb40a0cd884f9507643a83
+1
--- auto.def
+++ auto.def
@@ -278,10 +278,11 @@
278278
}
279279
}
280280
cc-check-function-in-lib iconv iconv
281281
cc-check-functions utime
282282
cc-check-functions usleep
283
+cc-check-functions strchrnul
283284
284285
# Check for getloadavg(), and if it doesn't exist, define FOSSIL_OMIT_LOAD_AVERAGE
285286
if {![cc-check-functions getloadavg]} {
286287
define FOSSIL_OMIT_LOAD_AVERAGE 1
287288
msg-result "Load average support unavailable"
288289
--- auto.def
+++ auto.def
@@ -278,10 +278,11 @@
278 }
279 }
280 cc-check-function-in-lib iconv iconv
281 cc-check-functions utime
282 cc-check-functions usleep
 
283
284 # Check for getloadavg(), and if it doesn't exist, define FOSSIL_OMIT_LOAD_AVERAGE
285 if {![cc-check-functions getloadavg]} {
286 define FOSSIL_OMIT_LOAD_AVERAGE 1
287 msg-result "Load average support unavailable"
288
--- auto.def
+++ auto.def
@@ -278,10 +278,11 @@
278 }
279 }
280 cc-check-function-in-lib iconv iconv
281 cc-check-functions utime
282 cc-check-functions usleep
283 cc-check-functions strchrnul
284
285 # Check for getloadavg(), and if it doesn't exist, define FOSSIL_OMIT_LOAD_AVERAGE
286 if {![cc-check-functions getloadavg]} {
287 define FOSSIL_OMIT_LOAD_AVERAGE 1
288 msg-result "Load average support unavailable"
289
+9 -1
--- src/allrepo.c
+++ src/allrepo.c
@@ -98,10 +98,12 @@
9898
** carefully review the local checkouts to be operated upon
9999
** and the --whatif option to carefully review the files to
100100
** be deleted beforehand is highly recommended. The command
101101
** line options supported by the clean command itself, if any
102102
** are present, are passed along verbatim.
103
+**
104
+** dbstat Run the "dbstat" command on all repositories.
103105
**
104106
** extras Shows "extra" files from all local checkouts. The command
105107
** line options supported by the extra command itself, if any
106108
** are present, are passed along verbatim.
107109
**
@@ -129,11 +131,11 @@
129131
** sync Run a "sync" on all repositories. Only the --verbose
130132
** option is supported.
131133
**
132134
** setting Run the "setting", "set", or "unset" commands on all
133135
** set repositories. These command are particularly useful in
134
-** unset conjunection with the "max-loadavg" setting which cannot
136
+** unset conjunction with the "max-loadavg" setting which cannot
135137
** otherwise be set globally.
136138
**
137139
** Repositories are automatically added to the set of known repositories
138140
** when one of the following commands are run against the repository:
139141
** clone, info, pull, push, or sync. Even previously ignored repositories
@@ -190,10 +192,16 @@
190192
collect_argument_value(&extra, "keep");
191193
collect_argument(&extra, "temp",0);
192194
collect_argument(&extra, "verbose","v");
193195
collect_argument(&extra, "whatif",0);
194196
useCheckouts = 1;
197
+ }else if( strncmp(zCmd, "dbstat", n)==0 ){
198
+ zCmd = "dbstat --omit-version-info -R";
199
+ showLabel = 1;
200
+ quiet = 1;
201
+ collect_argument(&extra, "brief", "b");
202
+ collect_argument(&extra, "db-check", 0);
195203
}else if( strncmp(zCmd, "extras", n)==0 ){
196204
if( showFile ){
197205
zCmd = "extras --chdir";
198206
}else{
199207
zCmd = "extras --header --chdir";
200208
--- src/allrepo.c
+++ src/allrepo.c
@@ -98,10 +98,12 @@
98 ** carefully review the local checkouts to be operated upon
99 ** and the --whatif option to carefully review the files to
100 ** be deleted beforehand is highly recommended. The command
101 ** line options supported by the clean command itself, if any
102 ** are present, are passed along verbatim.
 
 
103 **
104 ** extras Shows "extra" files from all local checkouts. The command
105 ** line options supported by the extra command itself, if any
106 ** are present, are passed along verbatim.
107 **
@@ -129,11 +131,11 @@
129 ** sync Run a "sync" on all repositories. Only the --verbose
130 ** option is supported.
131 **
132 ** setting Run the "setting", "set", or "unset" commands on all
133 ** set repositories. These command are particularly useful in
134 ** unset conjunection with the "max-loadavg" setting which cannot
135 ** otherwise be set globally.
136 **
137 ** Repositories are automatically added to the set of known repositories
138 ** when one of the following commands are run against the repository:
139 ** clone, info, pull, push, or sync. Even previously ignored repositories
@@ -190,10 +192,16 @@
190 collect_argument_value(&extra, "keep");
191 collect_argument(&extra, "temp",0);
192 collect_argument(&extra, "verbose","v");
193 collect_argument(&extra, "whatif",0);
194 useCheckouts = 1;
 
 
 
 
 
 
195 }else if( strncmp(zCmd, "extras", n)==0 ){
196 if( showFile ){
197 zCmd = "extras --chdir";
198 }else{
199 zCmd = "extras --header --chdir";
200
--- src/allrepo.c
+++ src/allrepo.c
@@ -98,10 +98,12 @@
98 ** carefully review the local checkouts to be operated upon
99 ** and the --whatif option to carefully review the files to
100 ** be deleted beforehand is highly recommended. The command
101 ** line options supported by the clean command itself, if any
102 ** are present, are passed along verbatim.
103 **
104 ** dbstat Run the "dbstat" command on all repositories.
105 **
106 ** extras Shows "extra" files from all local checkouts. The command
107 ** line options supported by the extra command itself, if any
108 ** are present, are passed along verbatim.
109 **
@@ -129,11 +131,11 @@
131 ** sync Run a "sync" on all repositories. Only the --verbose
132 ** option is supported.
133 **
134 ** setting Run the "setting", "set", or "unset" commands on all
135 ** set repositories. These command are particularly useful in
136 ** unset conjunction with the "max-loadavg" setting which cannot
137 ** otherwise be set globally.
138 **
139 ** Repositories are automatically added to the set of known repositories
140 ** when one of the following commands are run against the repository:
141 ** clone, info, pull, push, or sync. Even previously ignored repositories
@@ -190,10 +192,16 @@
192 collect_argument_value(&extra, "keep");
193 collect_argument(&extra, "temp",0);
194 collect_argument(&extra, "verbose","v");
195 collect_argument(&extra, "whatif",0);
196 useCheckouts = 1;
197 }else if( strncmp(zCmd, "dbstat", n)==0 ){
198 zCmd = "dbstat --omit-version-info -R";
199 showLabel = 1;
200 quiet = 1;
201 collect_argument(&extra, "brief", "b");
202 collect_argument(&extra, "db-check", 0);
203 }else if( strncmp(zCmd, "extras", n)==0 ){
204 if( showFile ){
205 zCmd = "extras --chdir";
206 }else{
207 zCmd = "extras --header --chdir";
208
+1 -1
--- src/browse.c
+++ src/browse.c
@@ -759,11 +759,11 @@
759759
db_prepare(&ins,
760760
"INSERT INTO temp.fileage(fid, pathname)"
761761
" SELECT rid, :path FROM blob WHERE uuid=:uuid"
762762
);
763763
while( (pFile = manifest_file_next(pManifest, 0))!=0 ){
764
- if(zGlob && !strglob(zGlob, pFile->zName)) continue;
764
+ if( zGlob && sqlite3_strglob(zGlob, pFile->zName)!=0 ) continue;
765765
db_bind_text(&ins, ":uuid", pFile->zUuid);
766766
db_bind_text(&ins, ":path", pFile->zName);
767767
db_step(&ins);
768768
db_reset(&ins);
769769
nFile++;
770770
--- src/browse.c
+++ src/browse.c
@@ -759,11 +759,11 @@
759 db_prepare(&ins,
760 "INSERT INTO temp.fileage(fid, pathname)"
761 " SELECT rid, :path FROM blob WHERE uuid=:uuid"
762 );
763 while( (pFile = manifest_file_next(pManifest, 0))!=0 ){
764 if(zGlob && !strglob(zGlob, pFile->zName)) continue;
765 db_bind_text(&ins, ":uuid", pFile->zUuid);
766 db_bind_text(&ins, ":path", pFile->zName);
767 db_step(&ins);
768 db_reset(&ins);
769 nFile++;
770
--- src/browse.c
+++ src/browse.c
@@ -759,11 +759,11 @@
759 db_prepare(&ins,
760 "INSERT INTO temp.fileage(fid, pathname)"
761 " SELECT rid, :path FROM blob WHERE uuid=:uuid"
762 );
763 while( (pFile = manifest_file_next(pManifest, 0))!=0 ){
764 if( zGlob && sqlite3_strglob(zGlob, pFile->zName)!=0 ) continue;
765 db_bind_text(&ins, ":uuid", pFile->zUuid);
766 db_bind_text(&ins, ":path", pFile->zName);
767 db_step(&ins);
768 db_reset(&ins);
769 nFile++;
770
+2 -2
--- src/cgi.c
+++ src/cgi.c
@@ -277,12 +277,12 @@
277277
** Return true if the response should be sent with Content-Encoding: gzip.
278278
*/
279279
static int is_gzippable(void){
280280
if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
281281
return strncmp(zContentType, "text/", 5)==0
282
- || strglob("application/*xml", zContentType)
283
- || strglob("application/*javascript", zContentType);
282
+ || sqlite3_strglob("application/*xml", zContentType)==0
283
+ || sqlite3_strglob("application/*javascript", zContentType)==0;
284284
}
285285
286286
/*
287287
** Do a normal HTTP reply
288288
*/
289289
--- src/cgi.c
+++ src/cgi.c
@@ -277,12 +277,12 @@
277 ** Return true if the response should be sent with Content-Encoding: gzip.
278 */
279 static int is_gzippable(void){
280 if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
281 return strncmp(zContentType, "text/", 5)==0
282 || strglob("application/*xml", zContentType)
283 || strglob("application/*javascript", zContentType);
284 }
285
286 /*
287 ** Do a normal HTTP reply
288 */
289
--- src/cgi.c
+++ src/cgi.c
@@ -277,12 +277,12 @@
277 ** Return true if the response should be sent with Content-Encoding: gzip.
278 */
279 static int is_gzippable(void){
280 if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
281 return strncmp(zContentType, "text/", 5)==0
282 || sqlite3_strglob("application/*xml", zContentType)==0
283 || sqlite3_strglob("application/*javascript", zContentType)==0;
284 }
285
286 /*
287 ** Do a normal HTTP reply
288 */
289
+5 -5
--- src/db.c
+++ src/db.c
@@ -892,11 +892,11 @@
892892
" WHERE name=='%s' /*scan*/",
893893
db_name("localdb"), zTable);
894894
int rc = 0;
895895
if( zDef ){
896896
char *zPattern = mprintf("* %s *", zColumn);
897
- rc = strglob(zPattern, zDef)==0;
897
+ rc = sqlite3_strglob(zPattern, zDef)!=0;
898898
fossil_free(zPattern);
899899
fossil_free(zDef);
900900
}
901901
return rc;
902902
}
@@ -919,19 +919,19 @@
919919
920920
/* If the "isexe" column is missing from the vfile table, then
921921
** add it now. This code added on 2010-03-06. After all users have
922922
** upgraded, this code can be safely deleted.
923923
*/
924
- if( !strglob("* isexe *", zVFileDef) ){
924
+ if( sqlite3_strglob("* isexe *", zVFileDef)!=0 ){
925925
db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
926926
}
927927
928928
/* If "islink"/"isLink" columns are missing from tables, then
929929
** add them now. This code added on 2011-01-17 and 2011-08-27.
930930
** After all users have upgraded, this code can be safely deleted.
931931
*/
932
- if( !strglob("* islink *", zVFileDef) ){
932
+ if( sqlite3_strglob("* islink *", zVFileDef)!=0 ){
933933
db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
934934
if( db_local_table_exists_but_lacks_column("stashfile", "isLink") ){
935935
db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOL DEFAULT 0");
936936
}
937937
if( db_local_table_exists_but_lacks_column("undo", "isLink") ){
@@ -1330,17 +1330,17 @@
13301330
"INSERT INTO config(name,value,mtime)"
13311331
" VALUES('project-code', lower(hex(randomblob(20))),now());"
13321332
);
13331333
}else{
13341334
if( db_get("server-code", 0)==0 ) {
1335
- db_optional_sql("repository",
1335
+ db_multi_exec(
13361336
"INSERT INTO config(name,value,mtime)"
13371337
" VALUES('server-code', lower(hex(randomblob(20))),now());"
13381338
);
13391339
}
13401340
if( db_get("project-code", 0)==0 ) {
1341
- db_optional_sql("repository",
1341
+ db_multi_exec(
13421342
"INSERT INTO config(name,value,mtime)"
13431343
" VALUES('project-code', lower(hex(randomblob(20))),now());"
13441344
);
13451345
}
13461346
}
13471347
--- src/db.c
+++ src/db.c
@@ -892,11 +892,11 @@
892 " WHERE name=='%s' /*scan*/",
893 db_name("localdb"), zTable);
894 int rc = 0;
895 if( zDef ){
896 char *zPattern = mprintf("* %s *", zColumn);
897 rc = strglob(zPattern, zDef)==0;
898 fossil_free(zPattern);
899 fossil_free(zDef);
900 }
901 return rc;
902 }
@@ -919,19 +919,19 @@
919
920 /* If the "isexe" column is missing from the vfile table, then
921 ** add it now. This code added on 2010-03-06. After all users have
922 ** upgraded, this code can be safely deleted.
923 */
924 if( !strglob("* isexe *", zVFileDef) ){
925 db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
926 }
927
928 /* If "islink"/"isLink" columns are missing from tables, then
929 ** add them now. This code added on 2011-01-17 and 2011-08-27.
930 ** After all users have upgraded, this code can be safely deleted.
931 */
932 if( !strglob("* islink *", zVFileDef) ){
933 db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
934 if( db_local_table_exists_but_lacks_column("stashfile", "isLink") ){
935 db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOL DEFAULT 0");
936 }
937 if( db_local_table_exists_but_lacks_column("undo", "isLink") ){
@@ -1330,17 +1330,17 @@
1330 "INSERT INTO config(name,value,mtime)"
1331 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1332 );
1333 }else{
1334 if( db_get("server-code", 0)==0 ) {
1335 db_optional_sql("repository",
1336 "INSERT INTO config(name,value,mtime)"
1337 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1338 );
1339 }
1340 if( db_get("project-code", 0)==0 ) {
1341 db_optional_sql("repository",
1342 "INSERT INTO config(name,value,mtime)"
1343 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1344 );
1345 }
1346 }
1347
--- src/db.c
+++ src/db.c
@@ -892,11 +892,11 @@
892 " WHERE name=='%s' /*scan*/",
893 db_name("localdb"), zTable);
894 int rc = 0;
895 if( zDef ){
896 char *zPattern = mprintf("* %s *", zColumn);
897 rc = sqlite3_strglob(zPattern, zDef)!=0;
898 fossil_free(zPattern);
899 fossil_free(zDef);
900 }
901 return rc;
902 }
@@ -919,19 +919,19 @@
919
920 /* If the "isexe" column is missing from the vfile table, then
921 ** add it now. This code added on 2010-03-06. After all users have
922 ** upgraded, this code can be safely deleted.
923 */
924 if( sqlite3_strglob("* isexe *", zVFileDef)!=0 ){
925 db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
926 }
927
928 /* If "islink"/"isLink" columns are missing from tables, then
929 ** add them now. This code added on 2011-01-17 and 2011-08-27.
930 ** After all users have upgraded, this code can be safely deleted.
931 */
932 if( sqlite3_strglob("* islink *", zVFileDef)!=0 ){
933 db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
934 if( db_local_table_exists_but_lacks_column("stashfile", "isLink") ){
935 db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOL DEFAULT 0");
936 }
937 if( db_local_table_exists_but_lacks_column("undo", "isLink") ){
@@ -1330,17 +1330,17 @@
1330 "INSERT INTO config(name,value,mtime)"
1331 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1332 );
1333 }else{
1334 if( db_get("server-code", 0)==0 ) {
1335 db_multi_exec(
1336 "INSERT INTO config(name,value,mtime)"
1337 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1338 );
1339 }
1340 if( db_get("project-code", 0)==0 ) {
1341 db_multi_exec(
1342 "INSERT INTO config(name,value,mtime)"
1343 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1344 );
1345 }
1346 }
1347
+2 -2
--- src/export.c
+++ src/export.c
@@ -232,12 +232,12 @@
232232
db_finalize(&q3);
233233
234234
/* Output the commit records.
235235
*/
236236
db_prepare(&q,
237
- "SELECT strftime('%%s',mtime), objid, coalesce(comment,ecomment),"
238
- " coalesce(user,euser),"
237
+ "SELECT strftime('%%s',mtime), objid, coalesce(ecomment,comment),"
238
+ " coalesce(euser,user),"
239239
" (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)"
240240
" FROM event"
241241
" WHERE type='ci' AND NOT EXISTS (SELECT 1 FROM oldcommit WHERE objid=rid)"
242242
" ORDER BY mtime ASC",
243243
TAG_BRANCH
244244
--- src/export.c
+++ src/export.c
@@ -232,12 +232,12 @@
232 db_finalize(&q3);
233
234 /* Output the commit records.
235 */
236 db_prepare(&q,
237 "SELECT strftime('%%s',mtime), objid, coalesce(comment,ecomment),"
238 " coalesce(user,euser),"
239 " (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)"
240 " FROM event"
241 " WHERE type='ci' AND NOT EXISTS (SELECT 1 FROM oldcommit WHERE objid=rid)"
242 " ORDER BY mtime ASC",
243 TAG_BRANCH
244
--- src/export.c
+++ src/export.c
@@ -232,12 +232,12 @@
232 db_finalize(&q3);
233
234 /* Output the commit records.
235 */
236 db_prepare(&q,
237 "SELECT strftime('%%s',mtime), objid, coalesce(ecomment,comment),"
238 " coalesce(euser,user),"
239 " (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)"
240 " FROM event"
241 " WHERE type='ci' AND NOT EXISTS (SELECT 1 FROM oldcommit WHERE objid=rid)"
242 " ORDER BY mtime ASC",
243 TAG_BRANCH
244
+1 -1
--- src/loadctrl.c
+++ src/loadctrl.c
@@ -27,11 +27,11 @@
2727
*/
2828
double load_average(void){
2929
#if !defined(_WIN32) && !defined(FOSSIL_OMIT_LOAD_AVERAGE)
3030
double a[3];
3131
if( getloadavg(a, 3)>0 ){
32
- return a[0];
32
+ return a[0]>=0.000001 ? a[0] : 0.000001;
3333
}
3434
#endif
3535
return 0.0;
3636
}
3737
3838
--- src/loadctrl.c
+++ src/loadctrl.c
@@ -27,11 +27,11 @@
27 */
28 double load_average(void){
29 #if !defined(_WIN32) && !defined(FOSSIL_OMIT_LOAD_AVERAGE)
30 double a[3];
31 if( getloadavg(a, 3)>0 ){
32 return a[0];
33 }
34 #endif
35 return 0.0;
36 }
37
38
--- src/loadctrl.c
+++ src/loadctrl.c
@@ -27,11 +27,11 @@
27 */
28 double load_average(void){
29 #if !defined(_WIN32) && !defined(FOSSIL_OMIT_LOAD_AVERAGE)
30 double a[3];
31 if( getloadavg(a, 3)>0 ){
32 return a[0]>=0.000001 ? a[0] : 0.000001;
33 }
34 #endif
35 return 0.0;
36 }
37
38
+5 -5
--- src/login.c
+++ src/login.c
@@ -395,15 +395,15 @@
395395
/* If a URI appears in the User-Agent, it is probably a bot */
396396
if( strncmp("http", zAgent+i,4)==0 ) return 0;
397397
}
398398
if( strncmp(zAgent, "Mozilla/", 8)==0 ){
399399
if( atoi(&zAgent[8])<4 ) return 0; /* Many bots advertise as Mozilla/3 */
400
- if( strglob("*Firefox/[1-9]*", zAgent) ) return 1;
401
- if( strglob("*Chrome/[1-9]*", zAgent) ) return 1;
402
- if( strglob("*(compatible;?MSIE?[1789]*", zAgent) ) return 1;
403
- if( strglob("*Trident/[1-9]*;?rv:[1-9]*", zAgent) ) return 1; /* IE11+ */
404
- if( strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent) ) return 1;
400
+ if( sqlite3_strglob("*Firefox/[1-9]*", zAgent)==0 ) return 1;
401
+ if( sqlite3_strglob("*Chrome/[1-9]*", zAgent)==0 ) return 1;
402
+ if( sqlite3_strglob("*(compatible;?MSIE?[1789]*", zAgent)==0 ) return 1;
403
+ if( sqlite3_strglob("*Trident/[1-9]*;?rv:[1-9]*", zAgent)==0 ) return 1; /* IE11+ */
404
+ if( sqlite3_strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent)==0 ) return 1;
405405
return 0;
406406
}
407407
if( strncmp(zAgent, "Opera/", 6)==0 ) return 1;
408408
if( strncmp(zAgent, "Safari/", 7)==0 ) return 1;
409409
if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1;
410410
--- src/login.c
+++ src/login.c
@@ -395,15 +395,15 @@
395 /* If a URI appears in the User-Agent, it is probably a bot */
396 if( strncmp("http", zAgent+i,4)==0 ) return 0;
397 }
398 if( strncmp(zAgent, "Mozilla/", 8)==0 ){
399 if( atoi(&zAgent[8])<4 ) return 0; /* Many bots advertise as Mozilla/3 */
400 if( strglob("*Firefox/[1-9]*", zAgent) ) return 1;
401 if( strglob("*Chrome/[1-9]*", zAgent) ) return 1;
402 if( strglob("*(compatible;?MSIE?[1789]*", zAgent) ) return 1;
403 if( strglob("*Trident/[1-9]*;?rv:[1-9]*", zAgent) ) return 1; /* IE11+ */
404 if( strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent) ) return 1;
405 return 0;
406 }
407 if( strncmp(zAgent, "Opera/", 6)==0 ) return 1;
408 if( strncmp(zAgent, "Safari/", 7)==0 ) return 1;
409 if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1;
410
--- src/login.c
+++ src/login.c
@@ -395,15 +395,15 @@
395 /* If a URI appears in the User-Agent, it is probably a bot */
396 if( strncmp("http", zAgent+i,4)==0 ) return 0;
397 }
398 if( strncmp(zAgent, "Mozilla/", 8)==0 ){
399 if( atoi(&zAgent[8])<4 ) return 0; /* Many bots advertise as Mozilla/3 */
400 if( sqlite3_strglob("*Firefox/[1-9]*", zAgent)==0 ) return 1;
401 if( sqlite3_strglob("*Chrome/[1-9]*", zAgent)==0 ) return 1;
402 if( sqlite3_strglob("*(compatible;?MSIE?[1789]*", zAgent)==0 ) return 1;
403 if( sqlite3_strglob("*Trident/[1-9]*;?rv:[1-9]*", zAgent)==0 ) return 1; /* IE11+ */
404 if( sqlite3_strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent)==0 ) return 1;
405 return 0;
406 }
407 if( strncmp(zAgent, "Opera/", 6)==0 ) return 1;
408 if( strncmp(zAgent, "Safari/", 7)==0 ) return 1;
409 if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1;
410
+5 -3
--- src/main.c
+++ src/main.c
@@ -1927,11 +1927,11 @@
19271927
** --scgi Interpret input as SCGI rather than HTTP
19281928
**
19291929
** See also: cgi, server, winsrv
19301930
*/
19311931
void cmd_http(void){
1932
- const char *zIpAddr;
1932
+ const char *zIpAddr = 0;
19331933
const char *zNotFound;
19341934
const char *zHost;
19351935
const char *zAltBase;
19361936
const char *zFileGlob;
19371937
int useSCGI;
@@ -1952,11 +1952,14 @@
19521952
g.useLocalauth = find_option("localauth", 0, 0)!=0;
19531953
g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
19541954
useSCGI = find_option("scgi", 0, 0)!=0;
19551955
zAltBase = find_option("baseurl", 0, 1);
19561956
if( zAltBase ) set_base_url(zAltBase);
1957
- if( find_option("https",0,0)!=0 ) cgi_replace_parameter("HTTPS","on");
1957
+ if( find_option("https",0,0)!=0 ){
1958
+ zIpAddr = fossil_getenv("REMOTE_HOST"); /* From stunnel */
1959
+ cgi_replace_parameter("HTTPS","on");
1960
+ }
19581961
zHost = find_option("host", 0, 1);
19591962
if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost);
19601963
g.cgiOutput = 1;
19611964
19621965
/* We should be done with options.. */
@@ -1972,11 +1975,10 @@
19721975
zIpAddr = g.argv[4];
19731976
find_server_repository(0, 5);
19741977
}else{
19751978
g.httpIn = stdin;
19761979
g.httpOut = stdout;
1977
- zIpAddr = 0;
19781980
find_server_repository(0, 2);
19791981
}
19801982
if( zIpAddr==0 ){
19811983
zIpAddr = cgi_ssh_remote_addr(0);
19821984
if( zIpAddr && zIpAddr[0] ){
19831985
--- src/main.c
+++ src/main.c
@@ -1927,11 +1927,11 @@
1927 ** --scgi Interpret input as SCGI rather than HTTP
1928 **
1929 ** See also: cgi, server, winsrv
1930 */
1931 void cmd_http(void){
1932 const char *zIpAddr;
1933 const char *zNotFound;
1934 const char *zHost;
1935 const char *zAltBase;
1936 const char *zFileGlob;
1937 int useSCGI;
@@ -1952,11 +1952,14 @@
1952 g.useLocalauth = find_option("localauth", 0, 0)!=0;
1953 g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
1954 useSCGI = find_option("scgi", 0, 0)!=0;
1955 zAltBase = find_option("baseurl", 0, 1);
1956 if( zAltBase ) set_base_url(zAltBase);
1957 if( find_option("https",0,0)!=0 ) cgi_replace_parameter("HTTPS","on");
 
 
 
1958 zHost = find_option("host", 0, 1);
1959 if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost);
1960 g.cgiOutput = 1;
1961
1962 /* We should be done with options.. */
@@ -1972,11 +1975,10 @@
1972 zIpAddr = g.argv[4];
1973 find_server_repository(0, 5);
1974 }else{
1975 g.httpIn = stdin;
1976 g.httpOut = stdout;
1977 zIpAddr = 0;
1978 find_server_repository(0, 2);
1979 }
1980 if( zIpAddr==0 ){
1981 zIpAddr = cgi_ssh_remote_addr(0);
1982 if( zIpAddr && zIpAddr[0] ){
1983
--- src/main.c
+++ src/main.c
@@ -1927,11 +1927,11 @@
1927 ** --scgi Interpret input as SCGI rather than HTTP
1928 **
1929 ** See also: cgi, server, winsrv
1930 */
1931 void cmd_http(void){
1932 const char *zIpAddr = 0;
1933 const char *zNotFound;
1934 const char *zHost;
1935 const char *zAltBase;
1936 const char *zFileGlob;
1937 int useSCGI;
@@ -1952,11 +1952,14 @@
1952 g.useLocalauth = find_option("localauth", 0, 0)!=0;
1953 g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
1954 useSCGI = find_option("scgi", 0, 0)!=0;
1955 zAltBase = find_option("baseurl", 0, 1);
1956 if( zAltBase ) set_base_url(zAltBase);
1957 if( find_option("https",0,0)!=0 ){
1958 zIpAddr = fossil_getenv("REMOTE_HOST"); /* From stunnel */
1959 cgi_replace_parameter("HTTPS","on");
1960 }
1961 zHost = find_option("host", 0, 1);
1962 if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost);
1963 g.cgiOutput = 1;
1964
1965 /* We should be done with options.. */
@@ -1972,11 +1975,10 @@
1975 zIpAddr = g.argv[4];
1976 find_server_repository(0, 5);
1977 }else{
1978 g.httpIn = stdin;
1979 g.httpOut = stdout;
 
1980 find_server_repository(0, 2);
1981 }
1982 if( zIpAddr==0 ){
1983 zIpAddr = cgi_ssh_remote_addr(0);
1984 if( zIpAddr && zIpAddr[0] ){
1985
+26 -3
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -505,12 +505,12 @@
505505
#### The directories where the OpenSSL include and library files are located.
506506
# The recommended usage here is to use the Sysinternals junction tool
507507
# to create a hard link between an "openssl-1.x" sub-directory of the
508508
# Fossil source code directory and the target OpenSSL source directory.
509509
#
510
-OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1i/include
511
-OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1i
510
+OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
511
+OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
512512
513513
#### Either the directory where the Tcl library is installed or the Tcl
514514
# source code directory resides (depending on the value of the macro
515515
# FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
516516
# this directory must have "include" and "lib" sub-directories. If
@@ -1174,10 +1174,13 @@
11741174
PERLDIR = C:\Perl\bin
11751175
PERL = perl.exe
11761176
11771177
# Uncomment to enable debug symbols
11781178
# DEBUG = 1
1179
+
1180
+# Uncomment to support Windows XP with Visual Studio 201x
1181
+# FOSSIL_ENABLE_WINXP = 1
11791182
11801183
# Uncomment to enable JSON API
11811184
# FOSSIL_ENABLE_JSON = 1
11821185
11831186
# Uncomment to enable miniz usage
@@ -1197,13 +1200,14 @@
11971200
11981201
# Uncomment to enable Tcl support
11991202
# FOSSIL_ENABLE_TCL = 1
12001203
12011204
!ifdef FOSSIL_ENABLE_SSL
1202
-SSLDIR = $(B)\compat\openssl-1.0.1i
1205
+SSLDIR = $(B)\compat\openssl-1.0.1j
12031206
SSLINCDIR = $(SSLDIR)\inc32
12041207
SSLLIBDIR = $(SSLDIR)\out32
1208
+SSLLFLAGS = /nologo /opt:ref /debug
12051209
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
12061210
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
12071211
!message Using 'x64' platform for OpenSSL...
12081212
SSLCONFIG = VC-WIN64A no-asm
12091213
SSLSETUP = ms\do_win64a.bat
@@ -1246,10 +1250,21 @@
12461250
INCL = $(INCL) /I$(TCLINCDIR)
12471251
!endif
12481252
12491253
CFLAGS = /nologo
12501254
LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
1255
+
1256
+!ifdef FOSSIL_ENABLE_WINXP
1257
+XPCFLAGS = $(XPCFLAGS) /D_USING_V110_SDK71_=1
1258
+CFLAGS = $(CFLAGS) $(XPCFLAGS)
1259
+!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1260
+XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.02
1261
+!else
1262
+XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.01
1263
+!endif
1264
+LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
1265
+!endif
12511266
12521267
!ifdef DEBUG
12531268
CFLAGS = $(CFLAGS) /Zi /MTd /Od
12541269
LDFLAGS = $(LDFLAGS) /DEBUG
12551270
!else
@@ -1352,21 +1367,29 @@
13521367
13531368
all: $(OX) $(APPNAME)
13541369
13551370
zlib:
13561371
@echo Building zlib from "$(ZLIBDIR)"...
1372
+!ifdef FOSSIL_ENABLE_WINXP
1373
+ @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) "CC=cl $(XPCFLAGS)" "LD=link $(XPLDFLAGS)" && popd
1374
+!else
13571375
@pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) && popd
1376
+!endif
13581377
13591378
!ifdef FOSSIL_ENABLE_SSL
13601379
openssl:
13611380
@echo Building OpenSSL from "$(SSLDIR)"...
13621381
!if "$(PERLDIR)" != ""
13631382
@set PATH=$(PERLDIR);$(PATH)
13641383
!endif
13651384
@pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
13661385
@pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
1386
+!ifdef FOSSIL_ENABLE_WINXP
1387
+ @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
1388
+!else
13671389
@pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
1390
+!endif
13681391
!endif
13691392
13701393
!ifndef FOSSIL_ENABLE_MINIZ
13711394
APPTARGETS = $(APPTARGETS) zlib
13721395
!endif
13731396
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -505,12 +505,12 @@
505 #### The directories where the OpenSSL include and library files are located.
506 # The recommended usage here is to use the Sysinternals junction tool
507 # to create a hard link between an "openssl-1.x" sub-directory of the
508 # Fossil source code directory and the target OpenSSL source directory.
509 #
510 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1i/include
511 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1i
512
513 #### Either the directory where the Tcl library is installed or the Tcl
514 # source code directory resides (depending on the value of the macro
515 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
516 # this directory must have "include" and "lib" sub-directories. If
@@ -1174,10 +1174,13 @@
1174 PERLDIR = C:\Perl\bin
1175 PERL = perl.exe
1176
1177 # Uncomment to enable debug symbols
1178 # DEBUG = 1
 
 
 
1179
1180 # Uncomment to enable JSON API
1181 # FOSSIL_ENABLE_JSON = 1
1182
1183 # Uncomment to enable miniz usage
@@ -1197,13 +1200,14 @@
1197
1198 # Uncomment to enable Tcl support
1199 # FOSSIL_ENABLE_TCL = 1
1200
1201 !ifdef FOSSIL_ENABLE_SSL
1202 SSLDIR = $(B)\compat\openssl-1.0.1i
1203 SSLINCDIR = $(SSLDIR)\inc32
1204 SSLLIBDIR = $(SSLDIR)\out32
 
1205 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1206 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1207 !message Using 'x64' platform for OpenSSL...
1208 SSLCONFIG = VC-WIN64A no-asm
1209 SSLSETUP = ms\do_win64a.bat
@@ -1246,10 +1250,21 @@
1246 INCL = $(INCL) /I$(TCLINCDIR)
1247 !endif
1248
1249 CFLAGS = /nologo
1250 LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
 
 
 
 
 
 
 
 
 
 
 
1251
1252 !ifdef DEBUG
1253 CFLAGS = $(CFLAGS) /Zi /MTd /Od
1254 LDFLAGS = $(LDFLAGS) /DEBUG
1255 !else
@@ -1352,21 +1367,29 @@
1352
1353 all: $(OX) $(APPNAME)
1354
1355 zlib:
1356 @echo Building zlib from "$(ZLIBDIR)"...
 
 
 
1357 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) && popd
 
1358
1359 !ifdef FOSSIL_ENABLE_SSL
1360 openssl:
1361 @echo Building OpenSSL from "$(SSLDIR)"...
1362 !if "$(PERLDIR)" != ""
1363 @set PATH=$(PERLDIR);$(PATH)
1364 !endif
1365 @pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
1366 @pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
 
 
 
1367 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
 
1368 !endif
1369
1370 !ifndef FOSSIL_ENABLE_MINIZ
1371 APPTARGETS = $(APPTARGETS) zlib
1372 !endif
1373
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -505,12 +505,12 @@
505 #### The directories where the OpenSSL include and library files are located.
506 # The recommended usage here is to use the Sysinternals junction tool
507 # to create a hard link between an "openssl-1.x" sub-directory of the
508 # Fossil source code directory and the target OpenSSL source directory.
509 #
510 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
511 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
512
513 #### Either the directory where the Tcl library is installed or the Tcl
514 # source code directory resides (depending on the value of the macro
515 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
516 # this directory must have "include" and "lib" sub-directories. If
@@ -1174,10 +1174,13 @@
1174 PERLDIR = C:\Perl\bin
1175 PERL = perl.exe
1176
1177 # Uncomment to enable debug symbols
1178 # DEBUG = 1
1179
1180 # Uncomment to support Windows XP with Visual Studio 201x
1181 # FOSSIL_ENABLE_WINXP = 1
1182
1183 # Uncomment to enable JSON API
1184 # FOSSIL_ENABLE_JSON = 1
1185
1186 # Uncomment to enable miniz usage
@@ -1197,13 +1200,14 @@
1200
1201 # Uncomment to enable Tcl support
1202 # FOSSIL_ENABLE_TCL = 1
1203
1204 !ifdef FOSSIL_ENABLE_SSL
1205 SSLDIR = $(B)\compat\openssl-1.0.1j
1206 SSLINCDIR = $(SSLDIR)\inc32
1207 SSLLIBDIR = $(SSLDIR)\out32
1208 SSLLFLAGS = /nologo /opt:ref /debug
1209 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1210 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1211 !message Using 'x64' platform for OpenSSL...
1212 SSLCONFIG = VC-WIN64A no-asm
1213 SSLSETUP = ms\do_win64a.bat
@@ -1246,10 +1250,21 @@
1250 INCL = $(INCL) /I$(TCLINCDIR)
1251 !endif
1252
1253 CFLAGS = /nologo
1254 LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
1255
1256 !ifdef FOSSIL_ENABLE_WINXP
1257 XPCFLAGS = $(XPCFLAGS) /D_USING_V110_SDK71_=1
1258 CFLAGS = $(CFLAGS) $(XPCFLAGS)
1259 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1260 XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.02
1261 !else
1262 XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.01
1263 !endif
1264 LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
1265 !endif
1266
1267 !ifdef DEBUG
1268 CFLAGS = $(CFLAGS) /Zi /MTd /Od
1269 LDFLAGS = $(LDFLAGS) /DEBUG
1270 !else
@@ -1352,21 +1367,29 @@
1367
1368 all: $(OX) $(APPNAME)
1369
1370 zlib:
1371 @echo Building zlib from "$(ZLIBDIR)"...
1372 !ifdef FOSSIL_ENABLE_WINXP
1373 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) "CC=cl $(XPCFLAGS)" "LD=link $(XPLDFLAGS)" && popd
1374 !else
1375 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) && popd
1376 !endif
1377
1378 !ifdef FOSSIL_ENABLE_SSL
1379 openssl:
1380 @echo Building OpenSSL from "$(SSLDIR)"...
1381 !if "$(PERLDIR)" != ""
1382 @set PATH=$(PERLDIR);$(PATH)
1383 !endif
1384 @pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
1385 @pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
1386 !ifdef FOSSIL_ENABLE_WINXP
1387 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
1388 !else
1389 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
1390 !endif
1391 !endif
1392
1393 !ifndef FOSSIL_ENABLE_MINIZ
1394 APPTARGETS = $(APPTARGETS) zlib
1395 !endif
1396
+101 -31
--- src/setup.c
+++ src/setup.c
@@ -307,11 +307,11 @@
307307
int uid, i;
308308
int higherUser = 0; /* True if user being edited is SETUP and the */
309309
/* user doing the editing is ADMIN. Disallow editing */
310310
char *inherit[128];
311311
int a[128];
312
- char *oa[128];
312
+ const char *oa[128];
313313
314314
/* Must have ADMIN privileges to access this page
315315
*/
316316
login_check_credentials();
317317
if( !g.perm.Admin ){ login_needed(); return; }
@@ -441,38 +441,38 @@
441441
if( fossil_strcmp(zLogin, "developer") ){
442442
char *z1, *z2;
443443
z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='developer'");
444444
while( z1 && *z1 ){
445445
inherit[0x7f & *(z1++)] =
446
- "<span class=\"ueditInheritDeveloper\"><sub>D</sub></span>";
446
+ "<span class=\"ueditInheritDeveloper\"><sub>[D]</sub></span>";
447447
}
448448
free(z2);
449449
}
450450
if( fossil_strcmp(zLogin, "reader") ){
451451
char *z1, *z2;
452452
z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='reader'");
453453
while( z1 && *z1 ){
454454
inherit[0x7f & *(z1++)] =
455
- "<span class=\"ueditInheritReader\"><sub>R</sub></span>";
455
+ "<span class=\"ueditInheritReader\"><sub>[R]</sub></span>";
456456
}
457457
free(z2);
458458
}
459459
if( fossil_strcmp(zLogin, "anonymous") ){
460460
char *z1, *z2;
461461
z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='anonymous'");
462462
while( z1 && *z1 ){
463463
inherit[0x7f & *(z1++)] =
464
- "<span class=\"ueditInheritAnonymous\"><sub>A</sub></span>";
464
+ "<span class=\"ueditInheritAnonymous\"><sub>[A]</sub></span>";
465465
}
466466
free(z2);
467467
}
468468
if( fossil_strcmp(zLogin, "nobody") ){
469469
char *z1, *z2;
470470
z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='nobody'");
471471
while( z1 && *z1 ){
472472
inherit[0x7f & *(z1++)] =
473
- "<span class=\"ueditInheritNobody\"><sub>N</sub></span>";
473
+ "<span class=\"ueditInheritNobody\"><sub>[N]</sub></span>";
474474
}
475475
free(z2);
476476
}
477477
478478
/* Begin generating the page
@@ -489,10 +489,47 @@
489489
if( login_is_special(zLogin) ){
490490
@ <input type="hidden" name="login" value="%s(zLogin)">
491491
@ <input type="hidden" name="info" value="">
492492
@ <input type="hidden" name="pw" value="*">
493493
}
494
+ @ <script type='text/javascript'>
495
+ @ function updateCapabilityString(){
496
+ @ /*
497
+ @ ** This function updates the "#usetupEditCapability" span content
498
+ @ ** with the capabilities selected by the interactive user, based
499
+ @ ** upon the state of the capability checkboxes.
500
+ @ */
501
+ @ try {
502
+ @ var inputs = document.getElementsByTagName('input');
503
+ @ if( inputs && inputs.length ){
504
+ @ var output = document.getElementById('usetupEditCapability');
505
+ @ if( output ){
506
+ @ var permsIds = [], x = 0;
507
+ @ for(var i = 0; i < inputs.length; i++){
508
+ @ var e = inputs[i];
509
+ @ if( !e.name || !e.type ) continue;
510
+ @ if( e.type.toLowerCase()!=='checkbox' ) continue;
511
+ @ if( e.name.length===2 && e.name[0]==='a' ){
512
+ @ // looks like a capability checkbox
513
+ @ if( e.checked ){
514
+ @ // grab the second character of the element
515
+ @ // name, which is the textual flag for this
516
+ @ // capability, and then add it to the result
517
+ @ // array.
518
+ @ permsIds[x++] = e.name[1];
519
+ @ }
520
+ @ }
521
+ @ }
522
+ @ permsIds.sort();
523
+ @ output.innerHTML = permsIds.join('');
524
+ @ }
525
+ @ }
526
+ @ } catch (e) {
527
+ @ /* ignore errors */
528
+ @ }
529
+ @ }
530
+ @ </script>
494531
@ <table>
495532
@ <tr>
496533
@ <td class="usetupEditLabel">User ID:</td>
497534
if( uid ){
498535
@ <td>%d(uid) <input type="hidden" name="id" value="%d(uid)" /></td>
@@ -516,64 +553,96 @@
516553
@ <td class="usetupEditLabel">Capabilities:</td>
517554
@ <td>
518555
#define B(x) inherit[x]
519556
@ <table border=0><tr><td valign="top">
520557
if( g.perm.Setup ){
521
- @ <label><input type="checkbox" name="as"%s(oa['s']) />
558
+ @ <label><input type="checkbox" name="as"%s(oa['s'])
559
+ @ onchange="updateCapabilityString()"/>
522560
@ Setup%s(B('s'))</label><br />
523561
}
524
- @ <label><input type="checkbox" name="aa"%s(oa['a']) />
562
+ @ <label><input type="checkbox" name="aa"%s(oa['a'])
563
+ @ onchange="updateCapabilityString()" />
525564
@ Admin%s(B('a'))</label><br />
526
- @ <label><input type="checkbox" name="ad"%s(oa['d']) />
565
+ @ <label><input type="checkbox" name="ad"%s(oa['d'])
566
+ @ onchange="updateCapabilityString()" />
527567
@ Delete%s(B('d'))</label><br />
528
- @ <label><input type="checkbox" name="ae"%s(oa['e']) />
568
+ @ <label><input type="checkbox" name="ae"%s(oa['e'])
569
+ @ onchange="updateCapabilityString()" />
529570
@ Email%s(B('e'))</label><br />
530
- @ <label><input type="checkbox" name="ap"%s(oa['p']) />
571
+ @ <label><input type="checkbox" name="ap"%s(oa['p'])
572
+ @ onchange="updateCapabilityString()" />
531573
@ Password%s(B('p'))</label><br />
532
- @ <label><input type="checkbox" name="ai"%s(oa['i']) />
574
+ @ <label><input type="checkbox" name="ai"%s(oa['i'])
575
+ @ onchange="updateCapabilityString()" />
533576
@ Check-In%s(B('i'))</label><br />
534
- @ <label><input type="checkbox" name="ao"%s(oa['o']) />
577
+ @ <label><input type="checkbox" name="ao"%s(oa['o'])
578
+ @ onchange="updateCapabilityString()" />
535579
@ Check-Out%s(B('o'))</label><br />
536
- @ <label><input type="checkbox" name="ah"%s(oa['h']) />
580
+ @ <label><input type="checkbox" name="ah"%s(oa['h'])
581
+ @ onchange="updateCapabilityString()" />
537582
@ Hyperlinks%s(B('h'))</label><br />
538
- @ <label><input type="checkbox" name="ab"%s(oa['b']) />
583
+ @ <label><input type="checkbox" name="ab"%s(oa['b'])
584
+ @ onchange="updateCapabilityString()" />
539585
@ Attachments%s(B('b'))</label><br />
540586
@ </td><td><td width="40"></td><td valign="top">
541
- @ <label><input type="checkbox" name="au"%s(oa['u']) />
587
+ @ <label><input type="checkbox" name="au"%s(oa['u'])
588
+ @ onchange="updateCapabilityString()" />
542589
@ Reader%s(B('u'))</label><br />
543
- @ <label><input type="checkbox" name="av"%s(oa['v']) />
590
+ @ <label><input type="checkbox" name="av"%s(oa['v'])
591
+ @ onchange="updateCapabilityString()" />
544592
@ Developer%s(B('v'))</label><br />
545
- @ <label><input type="checkbox" name="ag"%s(oa['g']) />
593
+ @ <label><input type="checkbox" name="ag"%s(oa['g'])
594
+ @ onchange="updateCapabilityString()" />
546595
@ Clone%s(B('g'))</label><br />
547
- @ <label><input type="checkbox" name="aj"%s(oa['j']) />
596
+ @ <label><input type="checkbox" name="aj"%s(oa['j'])
597
+ @ onchange="updateCapabilityString()" />
548598
@ Read Wiki%s(B('j'))</label><br />
549
- @ <label><input type="checkbox" name="af"%s(oa['f']) />
599
+ @ <label><input type="checkbox" name="af"%s(oa['f'])
600
+ @ onchange="updateCapabilityString()" />
550601
@ New Wiki%s(B('f'))</label><br />
551
- @ <label><input type="checkbox" name="am"%s(oa['m']) />
602
+ @ <label><input type="checkbox" name="am"%s(oa['m'])
603
+ @ onchange="updateCapabilityString()" />
552604
@ Append Wiki%s(B('m'))</label><br />
553
- @ <label><input type="checkbox" name="ak"%s(oa['k']) />
605
+ @ <label><input type="checkbox" name="ak"%s(oa['k'])
606
+ @ onchange="updateCapabilityString()" />
554607
@ Write Wiki%s(B('k'))</label><br />
555
- @ <label><input type="checkbox" name="al"%s(oa['l']) />
608
+ @ <label><input type="checkbox" name="al"%s(oa['l'])
609
+ @ onchange="updateCapabilityString()" />
556610
@ Moderate Wiki%s(B('l'))</label><br />
557611
@ </td><td><td width="40"></td><td valign="top">
558
- @ <label><input type="checkbox" name="ar"%s(oa['r']) />
612
+ @ <label><input type="checkbox" name="ar"%s(oa['r'])
613
+ @ onchange="updateCapabilityString()" />
559614
@ Read Ticket%s(B('r'))</label><br />
560
- @ <label><input type="checkbox" name="an"%s(oa['n']) />
615
+ @ <label><input type="checkbox" name="an"%s(oa['n'])
616
+ @ onchange="updateCapabilityString()" />
561617
@ New Tickets%s(B('n'))</label><br />
562
- @ <label><input type="checkbox" name="ac"%s(oa['c']) />
618
+ @ <label><input type="checkbox" name="ac"%s(oa['c'])
619
+ @ onchange="updateCapabilityString()" />
563620
@ Append To Ticket%s(B('c'))</label><br />
564
- @ <label><input type="checkbox" name="aw"%s(oa['w']) />
621
+ @ <label><input type="checkbox" name="aw"%s(oa['w'])
622
+ @ onchange="updateCapabilityString()" />
565623
@ Write Tickets%s(B('w'))</label><br />
566
- @ <label><input type="checkbox" name="aq"%s(oa['q']) />
624
+ @ <label><input type="checkbox" name="aq"%s(oa['q'])
625
+ @ onchange="updateCapabilityString()" />
567626
@ Moderate Tickets%s(B('q'))</label><br />
568
- @ <label><input type="checkbox" name="at"%s(oa['t']) />
627
+ @ <label><input type="checkbox" name="at"%s(oa['t'])
628
+ @ onchange="updateCapabilityString()" />
569629
@ Ticket Report%s(B('t'))</label><br />
570
- @ <label><input type="checkbox" name="ax"%s(oa['x']) />
630
+ @ <label><input type="checkbox" name="ax"%s(oa['x'])
631
+ @ onchange="updateCapabilityString()" />
571632
@ Private%s(B('x'))</label><br />
572
- @ <label><input type="checkbox" name="az"%s(oa['z']) />
633
+ @ <label><input type="checkbox" name="az"%s(oa['z'])
634
+ @ onchange="updateCapabilityString()" />
573635
@ Download Zip%s(B('z'))</label>
574
- @ </td></tr></table>
636
+ @ </td></tr>
637
+ @ </table>
638
+ @ </td>
639
+ @ </tr>
640
+ @ <tr>
641
+ @ <td class="usetupEditLabel">Selected Cap.:</td>
642
+ @ <td>
643
+ @ <span id="usetupEditCapability">(missing JS?)</span>
575644
@ </td>
576645
@ </tr>
577646
if( !login_is_special(zLogin) ){
578647
@ <tr>
579648
@ <td align="right">Password:</td>
@@ -604,10 +673,11 @@
604673
@ </tr>
605674
}
606675
@ </table>
607676
@ </div></form>
608677
@ </div>
678
+ @ <script type='text/javascript'>updateCapabilityString();</script>
609679
@ <h2>Privileges And Capabilities:</h2>
610680
@ <ul>
611681
if( higherUser ){
612682
@ <li><p class="missingPriv">
613683
@ User %h(zLogin) has Setup privileges and you only have Admin privileges
614684
--- src/setup.c
+++ src/setup.c
@@ -307,11 +307,11 @@
307 int uid, i;
308 int higherUser = 0; /* True if user being edited is SETUP and the */
309 /* user doing the editing is ADMIN. Disallow editing */
310 char *inherit[128];
311 int a[128];
312 char *oa[128];
313
314 /* Must have ADMIN privileges to access this page
315 */
316 login_check_credentials();
317 if( !g.perm.Admin ){ login_needed(); return; }
@@ -441,38 +441,38 @@
441 if( fossil_strcmp(zLogin, "developer") ){
442 char *z1, *z2;
443 z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='developer'");
444 while( z1 && *z1 ){
445 inherit[0x7f & *(z1++)] =
446 "<span class=\"ueditInheritDeveloper\"><sub>D</sub></span>";
447 }
448 free(z2);
449 }
450 if( fossil_strcmp(zLogin, "reader") ){
451 char *z1, *z2;
452 z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='reader'");
453 while( z1 && *z1 ){
454 inherit[0x7f & *(z1++)] =
455 "<span class=\"ueditInheritReader\"><sub>R</sub></span>";
456 }
457 free(z2);
458 }
459 if( fossil_strcmp(zLogin, "anonymous") ){
460 char *z1, *z2;
461 z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='anonymous'");
462 while( z1 && *z1 ){
463 inherit[0x7f & *(z1++)] =
464 "<span class=\"ueditInheritAnonymous\"><sub>A</sub></span>";
465 }
466 free(z2);
467 }
468 if( fossil_strcmp(zLogin, "nobody") ){
469 char *z1, *z2;
470 z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='nobody'");
471 while( z1 && *z1 ){
472 inherit[0x7f & *(z1++)] =
473 "<span class=\"ueditInheritNobody\"><sub>N</sub></span>";
474 }
475 free(z2);
476 }
477
478 /* Begin generating the page
@@ -489,10 +489,47 @@
489 if( login_is_special(zLogin) ){
490 @ <input type="hidden" name="login" value="%s(zLogin)">
491 @ <input type="hidden" name="info" value="">
492 @ <input type="hidden" name="pw" value="*">
493 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
494 @ <table>
495 @ <tr>
496 @ <td class="usetupEditLabel">User ID:</td>
497 if( uid ){
498 @ <td>%d(uid) <input type="hidden" name="id" value="%d(uid)" /></td>
@@ -516,64 +553,96 @@
516 @ <td class="usetupEditLabel">Capabilities:</td>
517 @ <td>
518 #define B(x) inherit[x]
519 @ <table border=0><tr><td valign="top">
520 if( g.perm.Setup ){
521 @ <label><input type="checkbox" name="as"%s(oa['s']) />
 
522 @ Setup%s(B('s'))</label><br />
523 }
524 @ <label><input type="checkbox" name="aa"%s(oa['a']) />
 
525 @ Admin%s(B('a'))</label><br />
526 @ <label><input type="checkbox" name="ad"%s(oa['d']) />
 
527 @ Delete%s(B('d'))</label><br />
528 @ <label><input type="checkbox" name="ae"%s(oa['e']) />
 
529 @ Email%s(B('e'))</label><br />
530 @ <label><input type="checkbox" name="ap"%s(oa['p']) />
 
531 @ Password%s(B('p'))</label><br />
532 @ <label><input type="checkbox" name="ai"%s(oa['i']) />
 
533 @ Check-In%s(B('i'))</label><br />
534 @ <label><input type="checkbox" name="ao"%s(oa['o']) />
 
535 @ Check-Out%s(B('o'))</label><br />
536 @ <label><input type="checkbox" name="ah"%s(oa['h']) />
 
537 @ Hyperlinks%s(B('h'))</label><br />
538 @ <label><input type="checkbox" name="ab"%s(oa['b']) />
 
539 @ Attachments%s(B('b'))</label><br />
540 @ </td><td><td width="40"></td><td valign="top">
541 @ <label><input type="checkbox" name="au"%s(oa['u']) />
 
542 @ Reader%s(B('u'))</label><br />
543 @ <label><input type="checkbox" name="av"%s(oa['v']) />
 
544 @ Developer%s(B('v'))</label><br />
545 @ <label><input type="checkbox" name="ag"%s(oa['g']) />
 
546 @ Clone%s(B('g'))</label><br />
547 @ <label><input type="checkbox" name="aj"%s(oa['j']) />
 
548 @ Read Wiki%s(B('j'))</label><br />
549 @ <label><input type="checkbox" name="af"%s(oa['f']) />
 
550 @ New Wiki%s(B('f'))</label><br />
551 @ <label><input type="checkbox" name="am"%s(oa['m']) />
 
552 @ Append Wiki%s(B('m'))</label><br />
553 @ <label><input type="checkbox" name="ak"%s(oa['k']) />
 
554 @ Write Wiki%s(B('k'))</label><br />
555 @ <label><input type="checkbox" name="al"%s(oa['l']) />
 
556 @ Moderate Wiki%s(B('l'))</label><br />
557 @ </td><td><td width="40"></td><td valign="top">
558 @ <label><input type="checkbox" name="ar"%s(oa['r']) />
 
559 @ Read Ticket%s(B('r'))</label><br />
560 @ <label><input type="checkbox" name="an"%s(oa['n']) />
 
561 @ New Tickets%s(B('n'))</label><br />
562 @ <label><input type="checkbox" name="ac"%s(oa['c']) />
 
563 @ Append To Ticket%s(B('c'))</label><br />
564 @ <label><input type="checkbox" name="aw"%s(oa['w']) />
 
565 @ Write Tickets%s(B('w'))</label><br />
566 @ <label><input type="checkbox" name="aq"%s(oa['q']) />
 
567 @ Moderate Tickets%s(B('q'))</label><br />
568 @ <label><input type="checkbox" name="at"%s(oa['t']) />
 
569 @ Ticket Report%s(B('t'))</label><br />
570 @ <label><input type="checkbox" name="ax"%s(oa['x']) />
 
571 @ Private%s(B('x'))</label><br />
572 @ <label><input type="checkbox" name="az"%s(oa['z']) />
 
573 @ Download Zip%s(B('z'))</label>
574 @ </td></tr></table>
 
 
 
 
 
 
 
575 @ </td>
576 @ </tr>
577 if( !login_is_special(zLogin) ){
578 @ <tr>
579 @ <td align="right">Password:</td>
@@ -604,10 +673,11 @@
604 @ </tr>
605 }
606 @ </table>
607 @ </div></form>
608 @ </div>
 
609 @ <h2>Privileges And Capabilities:</h2>
610 @ <ul>
611 if( higherUser ){
612 @ <li><p class="missingPriv">
613 @ User %h(zLogin) has Setup privileges and you only have Admin privileges
614
--- src/setup.c
+++ src/setup.c
@@ -307,11 +307,11 @@
307 int uid, i;
308 int higherUser = 0; /* True if user being edited is SETUP and the */
309 /* user doing the editing is ADMIN. Disallow editing */
310 char *inherit[128];
311 int a[128];
312 const char *oa[128];
313
314 /* Must have ADMIN privileges to access this page
315 */
316 login_check_credentials();
317 if( !g.perm.Admin ){ login_needed(); return; }
@@ -441,38 +441,38 @@
441 if( fossil_strcmp(zLogin, "developer") ){
442 char *z1, *z2;
443 z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='developer'");
444 while( z1 && *z1 ){
445 inherit[0x7f & *(z1++)] =
446 "<span class=\"ueditInheritDeveloper\"><sub>[D]</sub></span>";
447 }
448 free(z2);
449 }
450 if( fossil_strcmp(zLogin, "reader") ){
451 char *z1, *z2;
452 z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='reader'");
453 while( z1 && *z1 ){
454 inherit[0x7f & *(z1++)] =
455 "<span class=\"ueditInheritReader\"><sub>[R]</sub></span>";
456 }
457 free(z2);
458 }
459 if( fossil_strcmp(zLogin, "anonymous") ){
460 char *z1, *z2;
461 z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='anonymous'");
462 while( z1 && *z1 ){
463 inherit[0x7f & *(z1++)] =
464 "<span class=\"ueditInheritAnonymous\"><sub>[A]</sub></span>";
465 }
466 free(z2);
467 }
468 if( fossil_strcmp(zLogin, "nobody") ){
469 char *z1, *z2;
470 z1 = z2 = db_text(0,"SELECT cap FROM user WHERE login='nobody'");
471 while( z1 && *z1 ){
472 inherit[0x7f & *(z1++)] =
473 "<span class=\"ueditInheritNobody\"><sub>[N]</sub></span>";
474 }
475 free(z2);
476 }
477
478 /* Begin generating the page
@@ -489,10 +489,47 @@
489 if( login_is_special(zLogin) ){
490 @ <input type="hidden" name="login" value="%s(zLogin)">
491 @ <input type="hidden" name="info" value="">
492 @ <input type="hidden" name="pw" value="*">
493 }
494 @ <script type='text/javascript'>
495 @ function updateCapabilityString(){
496 @ /*
497 @ ** This function updates the "#usetupEditCapability" span content
498 @ ** with the capabilities selected by the interactive user, based
499 @ ** upon the state of the capability checkboxes.
500 @ */
501 @ try {
502 @ var inputs = document.getElementsByTagName('input');
503 @ if( inputs && inputs.length ){
504 @ var output = document.getElementById('usetupEditCapability');
505 @ if( output ){
506 @ var permsIds = [], x = 0;
507 @ for(var i = 0; i < inputs.length; i++){
508 @ var e = inputs[i];
509 @ if( !e.name || !e.type ) continue;
510 @ if( e.type.toLowerCase()!=='checkbox' ) continue;
511 @ if( e.name.length===2 && e.name[0]==='a' ){
512 @ // looks like a capability checkbox
513 @ if( e.checked ){
514 @ // grab the second character of the element
515 @ // name, which is the textual flag for this
516 @ // capability, and then add it to the result
517 @ // array.
518 @ permsIds[x++] = e.name[1];
519 @ }
520 @ }
521 @ }
522 @ permsIds.sort();
523 @ output.innerHTML = permsIds.join('');
524 @ }
525 @ }
526 @ } catch (e) {
527 @ /* ignore errors */
528 @ }
529 @ }
530 @ </script>
531 @ <table>
532 @ <tr>
533 @ <td class="usetupEditLabel">User ID:</td>
534 if( uid ){
535 @ <td>%d(uid) <input type="hidden" name="id" value="%d(uid)" /></td>
@@ -516,64 +553,96 @@
553 @ <td class="usetupEditLabel">Capabilities:</td>
554 @ <td>
555 #define B(x) inherit[x]
556 @ <table border=0><tr><td valign="top">
557 if( g.perm.Setup ){
558 @ <label><input type="checkbox" name="as"%s(oa['s'])
559 @ onchange="updateCapabilityString()"/>
560 @ Setup%s(B('s'))</label><br />
561 }
562 @ <label><input type="checkbox" name="aa"%s(oa['a'])
563 @ onchange="updateCapabilityString()" />
564 @ Admin%s(B('a'))</label><br />
565 @ <label><input type="checkbox" name="ad"%s(oa['d'])
566 @ onchange="updateCapabilityString()" />
567 @ Delete%s(B('d'))</label><br />
568 @ <label><input type="checkbox" name="ae"%s(oa['e'])
569 @ onchange="updateCapabilityString()" />
570 @ Email%s(B('e'))</label><br />
571 @ <label><input type="checkbox" name="ap"%s(oa['p'])
572 @ onchange="updateCapabilityString()" />
573 @ Password%s(B('p'))</label><br />
574 @ <label><input type="checkbox" name="ai"%s(oa['i'])
575 @ onchange="updateCapabilityString()" />
576 @ Check-In%s(B('i'))</label><br />
577 @ <label><input type="checkbox" name="ao"%s(oa['o'])
578 @ onchange="updateCapabilityString()" />
579 @ Check-Out%s(B('o'))</label><br />
580 @ <label><input type="checkbox" name="ah"%s(oa['h'])
581 @ onchange="updateCapabilityString()" />
582 @ Hyperlinks%s(B('h'))</label><br />
583 @ <label><input type="checkbox" name="ab"%s(oa['b'])
584 @ onchange="updateCapabilityString()" />
585 @ Attachments%s(B('b'))</label><br />
586 @ </td><td><td width="40"></td><td valign="top">
587 @ <label><input type="checkbox" name="au"%s(oa['u'])
588 @ onchange="updateCapabilityString()" />
589 @ Reader%s(B('u'))</label><br />
590 @ <label><input type="checkbox" name="av"%s(oa['v'])
591 @ onchange="updateCapabilityString()" />
592 @ Developer%s(B('v'))</label><br />
593 @ <label><input type="checkbox" name="ag"%s(oa['g'])
594 @ onchange="updateCapabilityString()" />
595 @ Clone%s(B('g'))</label><br />
596 @ <label><input type="checkbox" name="aj"%s(oa['j'])
597 @ onchange="updateCapabilityString()" />
598 @ Read Wiki%s(B('j'))</label><br />
599 @ <label><input type="checkbox" name="af"%s(oa['f'])
600 @ onchange="updateCapabilityString()" />
601 @ New Wiki%s(B('f'))</label><br />
602 @ <label><input type="checkbox" name="am"%s(oa['m'])
603 @ onchange="updateCapabilityString()" />
604 @ Append Wiki%s(B('m'))</label><br />
605 @ <label><input type="checkbox" name="ak"%s(oa['k'])
606 @ onchange="updateCapabilityString()" />
607 @ Write Wiki%s(B('k'))</label><br />
608 @ <label><input type="checkbox" name="al"%s(oa['l'])
609 @ onchange="updateCapabilityString()" />
610 @ Moderate Wiki%s(B('l'))</label><br />
611 @ </td><td><td width="40"></td><td valign="top">
612 @ <label><input type="checkbox" name="ar"%s(oa['r'])
613 @ onchange="updateCapabilityString()" />
614 @ Read Ticket%s(B('r'))</label><br />
615 @ <label><input type="checkbox" name="an"%s(oa['n'])
616 @ onchange="updateCapabilityString()" />
617 @ New Tickets%s(B('n'))</label><br />
618 @ <label><input type="checkbox" name="ac"%s(oa['c'])
619 @ onchange="updateCapabilityString()" />
620 @ Append To Ticket%s(B('c'))</label><br />
621 @ <label><input type="checkbox" name="aw"%s(oa['w'])
622 @ onchange="updateCapabilityString()" />
623 @ Write Tickets%s(B('w'))</label><br />
624 @ <label><input type="checkbox" name="aq"%s(oa['q'])
625 @ onchange="updateCapabilityString()" />
626 @ Moderate Tickets%s(B('q'))</label><br />
627 @ <label><input type="checkbox" name="at"%s(oa['t'])
628 @ onchange="updateCapabilityString()" />
629 @ Ticket Report%s(B('t'))</label><br />
630 @ <label><input type="checkbox" name="ax"%s(oa['x'])
631 @ onchange="updateCapabilityString()" />
632 @ Private%s(B('x'))</label><br />
633 @ <label><input type="checkbox" name="az"%s(oa['z'])
634 @ onchange="updateCapabilityString()" />
635 @ Download Zip%s(B('z'))</label>
636 @ </td></tr>
637 @ </table>
638 @ </td>
639 @ </tr>
640 @ <tr>
641 @ <td class="usetupEditLabel">Selected Cap.:</td>
642 @ <td>
643 @ <span id="usetupEditCapability">(missing JS?)</span>
644 @ </td>
645 @ </tr>
646 if( !login_is_special(zLogin) ){
647 @ <tr>
648 @ <td align="right">Password:</td>
@@ -604,10 +673,11 @@
673 @ </tr>
674 }
675 @ </table>
676 @ </div></form>
677 @ </div>
678 @ <script type='text/javascript'>updateCapabilityString();</script>
679 @ <h2>Privileges And Capabilities:</h2>
680 @ <ul>
681 if( higherUser ){
682 @ <li><p class="missingPriv">
683 @ User %h(zLogin) has Setup privileges and you only have Admin privileges
684
+10 -9
--- src/shell.c
+++ src/shell.c
@@ -1351,19 +1351,10 @@
13511351
}
13521352
sqlite3_finalize(pExplain);
13531353
sqlite3_free(zEQP);
13541354
}
13551355
1356
- /* Output TESTCTRL_EXPLAIN text of requested */
1357
- if( pArg && pArg->mode==MODE_Explain ){
1358
- const char *zExplain = 0;
1359
- sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1360
- if( zExplain && zExplain[0] ){
1361
- fprintf(pArg->out, "%s", zExplain);
1362
- }
1363
- }
1364
-
13651356
/* If the shell is currently in ".explain" mode, gather the extra
13661357
** data required to add indents to the output.*/
13671358
if( pArg && pArg->mode==MODE_Explain ){
13681359
explain_data_prepare(pArg, pStmt);
13691360
}
@@ -3098,10 +3089,19 @@
30983089
rc = 1;
30993090
}else{
31003091
rc = 0;
31013092
}
31023093
}else
3094
+
3095
+
3096
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
3097
+ if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){
3098
+ extern int sqlite3SelectTrace;
3099
+ sqlite3SelectTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
3100
+ }else
3101
+#endif
3102
+
31033103
31043104
#ifdef SQLITE_DEBUG
31053105
/* Undocumented commands for internal testing. Subject to change
31063106
** without notice. */
31073107
if( c=='s' && n>=10 && strncmp(azArg[0], "selftest-", 9)==0 ){
@@ -3723,10 +3723,11 @@
37233723
}
37243724
}
37253725
if( nSql ){
37263726
if( !_all_whitespace(zSql) ){
37273727
fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
3728
+ errCnt++;
37283729
}
37293730
free(zSql);
37303731
}
37313732
free(zLine);
37323733
return errCnt>0;
37333734
--- src/shell.c
+++ src/shell.c
@@ -1351,19 +1351,10 @@
1351 }
1352 sqlite3_finalize(pExplain);
1353 sqlite3_free(zEQP);
1354 }
1355
1356 /* Output TESTCTRL_EXPLAIN text of requested */
1357 if( pArg && pArg->mode==MODE_Explain ){
1358 const char *zExplain = 0;
1359 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1360 if( zExplain && zExplain[0] ){
1361 fprintf(pArg->out, "%s", zExplain);
1362 }
1363 }
1364
1365 /* If the shell is currently in ".explain" mode, gather the extra
1366 ** data required to add indents to the output.*/
1367 if( pArg && pArg->mode==MODE_Explain ){
1368 explain_data_prepare(pArg, pStmt);
1369 }
@@ -3098,10 +3089,19 @@
3098 rc = 1;
3099 }else{
3100 rc = 0;
3101 }
3102 }else
 
 
 
 
 
 
 
 
 
3103
3104 #ifdef SQLITE_DEBUG
3105 /* Undocumented commands for internal testing. Subject to change
3106 ** without notice. */
3107 if( c=='s' && n>=10 && strncmp(azArg[0], "selftest-", 9)==0 ){
@@ -3723,10 +3723,11 @@
3723 }
3724 }
3725 if( nSql ){
3726 if( !_all_whitespace(zSql) ){
3727 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
 
3728 }
3729 free(zSql);
3730 }
3731 free(zLine);
3732 return errCnt>0;
3733
--- src/shell.c
+++ src/shell.c
@@ -1351,19 +1351,10 @@
1351 }
1352 sqlite3_finalize(pExplain);
1353 sqlite3_free(zEQP);
1354 }
1355
 
 
 
 
 
 
 
 
 
1356 /* If the shell is currently in ".explain" mode, gather the extra
1357 ** data required to add indents to the output.*/
1358 if( pArg && pArg->mode==MODE_Explain ){
1359 explain_data_prepare(pArg, pStmt);
1360 }
@@ -3098,10 +3089,19 @@
3089 rc = 1;
3090 }else{
3091 rc = 0;
3092 }
3093 }else
3094
3095
3096 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
3097 if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){
3098 extern int sqlite3SelectTrace;
3099 sqlite3SelectTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
3100 }else
3101 #endif
3102
3103
3104 #ifdef SQLITE_DEBUG
3105 /* Undocumented commands for internal testing. Subject to change
3106 ** without notice. */
3107 if( c=='s' && n>=10 && strncmp(azArg[0], "selftest-", 9)==0 ){
@@ -3723,10 +3723,11 @@
3723 }
3724 }
3725 if( nSql ){
3726 if( !_all_whitespace(zSql) ){
3727 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
3728 errCnt++;
3729 }
3730 free(zSql);
3731 }
3732 free(zLine);
3733 return errCnt>0;
3734
+1201 -971
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231231
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232232
** [sqlite_version()] and [sqlite_source_id()].
233233
*/
234234
#define SQLITE_VERSION "3.8.7"
235235
#define SQLITE_VERSION_NUMBER 3008007
236
-#define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7"
236
+#define SQLITE_SOURCE_ID "2014-10-15 15:28:27 3c1e70f4d55bc009ed9ed4cf6d756d7061985851"
237237
238238
/*
239239
** CAPI3REF: Run-Time Library Version Numbers
240240
** KEYWORDS: sqlite3_version, sqlite3_sourceid
241241
**
@@ -2791,13 +2791,13 @@
27912791
** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
27922792
** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
27932793
** an English language description of the error following a failure of any
27942794
** of the sqlite3_open() routines.
27952795
**
2796
-** ^The default encoding for the database will be UTF-8 if
2797
-** sqlite3_open() or sqlite3_open_v2() is called and
2798
-** UTF-16 in the native byte order if sqlite3_open16() is used.
2796
+** ^The default encoding will be UTF-8 for databases created using
2797
+** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
2798
+** created using sqlite3_open16() will be UTF-16 in the native byte order.
27992799
**
28002800
** Whether or not an error occurs when it is opened, resources
28012801
** associated with the [database connection] handle should be released by
28022802
** passing it to [sqlite3_close()] when it is no longer required.
28032803
**
@@ -2881,17 +2881,18 @@
28812881
** ^SQLite uses the path component of the URI as the name of the disk file
28822882
** which contains the database. ^If the path begins with a '/' character,
28832883
** then it is interpreted as an absolute path. ^If the path does not begin
28842884
** with a '/' (meaning that the authority section is omitted from the URI)
28852885
** then the path is interpreted as a relative path.
2886
-** ^On windows, the first component of an absolute path
2887
-** is a drive specification (e.g. "C:").
2886
+** ^(On windows, the first component of an absolute path
2887
+** is a drive specification (e.g. "C:").)^
28882888
**
28892889
** [[core URI query parameters]]
28902890
** The query component of a URI may contain parameters that are interpreted
28912891
** either by SQLite itself, or by a [VFS | custom VFS implementation].
2892
-** SQLite interprets the following three query parameters:
2892
+** SQLite and its built-in [VFSes] interpret the
2893
+** following query parameters:
28932894
**
28942895
** <ul>
28952896
** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
28962897
** a VFS object that provides the operating system interface that should
28972898
** be used to access the database file on disk. ^If this option is set to
@@ -2922,15 +2923,13 @@
29222923
** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
29232924
** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
29242925
** a URI filename, its value overrides any behavior requested by setting
29252926
** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
29262927
**
2927
-** <li> <b>psow</b>: ^The psow parameter may be "true" (or "on" or "yes" or
2928
-** "1") or "false" (or "off" or "no" or "0") to indicate that the
2928
+** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
29292929
** [powersafe overwrite] property does or does not apply to the
2930
-** storage media on which the database file resides. ^The psow query
2931
-** parameter only works for the built-in unix and Windows VFSes.
2930
+** storage media on which the database file resides.
29322931
**
29332932
** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
29342933
** which if set disables file locking in rollback journal modes. This
29352934
** is useful for accessing a database on a filesystem that does not
29362935
** support locking. Caution: Database corruption might result if two
@@ -3521,15 +3520,14 @@
35213520
** terminated. If any NUL characters occur at byte offsets less than
35223521
** the value of the fourth parameter then the resulting string value will
35233522
** contain embedded NULs. The result of expressions involving strings
35243523
** with embedded NULs is undefined.
35253524
**
3526
-** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3527
-** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3525
+** ^The fifth argument to the BLOB and string binding interfaces
3526
+** is a destructor used to dispose of the BLOB or
35283527
** string after SQLite has finished with it. ^The destructor is called
3529
-** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
3530
-** sqlite3_bind_text(), or sqlite3_bind_text16() fails.
3528
+** to dispose of the BLOB or string even if the call to bind API fails.
35313529
** ^If the fifth argument is
35323530
** the special value [SQLITE_STATIC], then SQLite assumes that the
35333531
** information is in static, unmanaged space and does not need to be freed.
35343532
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
35353533
** SQLite makes its own private copy of the data immediately, before
@@ -3536,11 +3534,11 @@
35363534
** the sqlite3_bind_*() routine returns.
35373535
**
35383536
** ^The sixth argument to sqlite3_bind_text64() must be one of
35393537
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
35403538
** to specify the encoding of the text in the third parameter. If
3541
-** the sixth argument to sqlite3_bind_text64() is not how of the
3539
+** the sixth argument to sqlite3_bind_text64() is not one of the
35423540
** allowed values shown above, or if the text encoding is different
35433541
** from the encoding specified by the sixth parameter, then the behavior
35443542
** is undefined.
35453543
**
35463544
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
@@ -4572,11 +4570,11 @@
45724570
**
45734571
** ^The sqlite3_result_null() interface sets the return value
45744572
** of the application-defined function to be NULL.
45754573
**
45764574
** ^The sqlite3_result_text(), sqlite3_result_text16(),
4577
-** sqlite3_result_text16le(), and sqlite3_result_text16be()
4575
+** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
45784576
** set the return value of the application-defined function to be
45794577
** a text string which is represented as UTF-8, UTF-16 native byte order,
45804578
** UTF-16 little endian, or UTF-16 big endian, respectively.
45814579
** ^The sqlite3_result_text64() interface sets the return value of an
45824580
** application-defined function to be a text string in an encoding
@@ -6332,11 +6330,11 @@
63326330
#define SQLITE_TESTCTRL_RESERVE 14
63336331
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
63346332
#define SQLITE_TESTCTRL_ISKEYWORD 16
63356333
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
63366334
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6337
-#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6335
+#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
63386336
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
63396337
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
63406338
#define SQLITE_TESTCTRL_BYTEORDER 22
63416339
#define SQLITE_TESTCTRL_ISINIT 23
63426340
#define SQLITE_TESTCTRL_SORTER_MMAP 24
@@ -7946,11 +7944,11 @@
79467944
** A macro to hint to the compiler that a function should not be
79477945
** inlined.
79487946
*/
79497947
#if defined(__GNUC__)
79507948
# define SQLITE_NOINLINE __attribute__((noinline))
7951
-#elif defined(_MSC_VER)
7949
+#elif defined(_MSC_VER) && _MSC_VER>=1310
79527950
# define SQLITE_NOINLINE __declspec(noinline)
79537951
#else
79547952
# define SQLITE_NOINLINE
79557953
#endif
79567954
@@ -8519,10 +8517,15 @@
85198517
** Macros to compute minimum and maximum of two numbers.
85208518
*/
85218519
#define MIN(A,B) ((A)<(B)?(A):(B))
85228520
#define MAX(A,B) ((A)>(B)?(A):(B))
85238521
8522
+/*
8523
+** Swap two objects of type TYPE.
8524
+*/
8525
+#define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
8526
+
85248527
/*
85258528
** Check to see if this machine uses EBCDIC. (Yes, believe it or
85268529
** not, there are still machines out there that use EBCDIC.)
85278530
*/
85288531
#if 'A' == '\301'
@@ -8756,10 +8759,20 @@
87568759
# define SQLITE_ENABLE_STAT3_OR_STAT4 1
87578760
#elif SQLITE_ENABLE_STAT3_OR_STAT4
87588761
# undef SQLITE_ENABLE_STAT3_OR_STAT4
87598762
#endif
87608763
8764
+/*
8765
+** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
8766
+** the Select query generator tracing logic is turned on.
8767
+*/
8768
+#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE)
8769
+# define SELECTTRACE_ENABLED 1
8770
+#else
8771
+# define SELECTTRACE_ENABLED 0
8772
+#endif
8773
+
87618774
/*
87628775
** An instance of the following structure is used to store the busy-handler
87638776
** callback for a given sqlite handle.
87648777
**
87658778
** The sqlite.busyHandler member of the sqlite struct contains the busy
@@ -8895,10 +8908,11 @@
88958908
typedef struct SrcList SrcList;
88968909
typedef struct StrAccum StrAccum;
88978910
typedef struct Table Table;
88988911
typedef struct TableLock TableLock;
88998912
typedef struct Token Token;
8913
+typedef struct TreeView TreeView;
89008914
typedef struct Trigger Trigger;
89018915
typedef struct TriggerPrg TriggerPrg;
89028916
typedef struct TriggerStep TriggerStep;
89038917
typedef struct UnpackedRecord UnpackedRecord;
89048918
typedef struct VTable VTable;
@@ -11308,10 +11322,11 @@
1130811322
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
1130911323
int nSample; /* Number of elements in aSample[] */
1131011324
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
1131111325
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
1131211326
IndexSample *aSample; /* Samples of the left-most key */
11327
+ tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */
1131311328
#endif
1131411329
};
1131511330
1131611331
/*
1131711332
** Allowed values for Index.idxType
@@ -11738,11 +11753,11 @@
1173811753
#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
1173911754
#define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
1174011755
#define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
1174111756
#define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
1174211757
#define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11743
-#define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
11758
+ /* 0x0080 // not currently used */
1174411759
#define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
1174511760
#define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
1174611761
#define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
1174711762
#define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
1174811763
#define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
@@ -11823,10 +11838,13 @@
1182311838
struct Select {
1182411839
ExprList *pEList; /* The fields of the result */
1182511840
u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
1182611841
u16 selFlags; /* Various SF_* values */
1182711842
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
11843
+#if SELECTTRACE_ENABLED
11844
+ char zSelName[12]; /* Symbolic name of this SELECT use for debugging */
11845
+#endif
1182811846
int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
1182911847
u64 nSelectRow; /* Estimated number of result rows */
1183011848
SrcList *pSrc; /* The FROM clause */
1183111849
Expr *pWhere; /* The WHERE clause */
1183211850
ExprList *pGroupBy; /* The GROUP BY clause */
@@ -12081,10 +12099,14 @@
1208112099
yDbMask cookieMask; /* Bitmask of schema verified databases */
1208212100
int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
1208312101
int regRowid; /* Register holding rowid of CREATE TABLE entry */
1208412102
int regRoot; /* Register holding root page number for new objects */
1208512103
int nMaxArg; /* Max args passed to user function by sub-program */
12104
+#if SELECTTRACE_ENABLED
12105
+ int nSelect; /* Number of SELECT statements seen */
12106
+ int nSelectIndent; /* How far to indent SELECTTRACE() output */
12107
+#endif
1208612108
#ifndef SQLITE_OMIT_SHARED_CACHE
1208712109
int nTableLock; /* Number of locks in aTableLock */
1208812110
TableLock *aTableLock; /* Required table locks for shared-cache mode */
1208912111
#endif
1209012112
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -12160,15 +12182,15 @@
1216012182
1216112183
/*
1216212184
** Bitfield flags for P5 value in various opcodes.
1216312185
*/
1216412186
#define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
12187
+#define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
1216512188
#define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
1216612189
#define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
1216712190
#define OPFLAG_APPEND 0x08 /* This is likely to be an append */
1216812191
#define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
12169
-#define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */
1217012192
#define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
1217112193
#define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
1217212194
#define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
1217312195
#define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */
1217412196
#define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
@@ -12428,10 +12450,21 @@
1242812450
Select *pSelect; /* The definition of this CTE */
1242912451
const char *zErr; /* Error message for circular references */
1243012452
} a[1];
1243112453
};
1243212454
12455
+#ifdef SQLITE_DEBUG
12456
+/*
12457
+** An instance of the TreeView object is used for printing the content of
12458
+** data structures on sqlite3DebugPrintf() using a tree-like view.
12459
+*/
12460
+struct TreeView {
12461
+ int iLevel; /* Which level of the tree we are on */
12462
+ u8 bLine[100]; /* Draw vertical in column i if bLine[i] is true */
12463
+};
12464
+#endif /* SQLITE_DEBUG */
12465
+
1243312466
/*
1243412467
** Assuming zIn points to the first byte of a UTF-8 character,
1243512468
** advance zIn to point to the first byte of the next UTF-8 character.
1243612469
*/
1243712470
#define SQLITE_SKIP_UTF8(zIn) { \
@@ -12493,10 +12526,11 @@
1249312526
# define sqlite3Isalpha(x) isalpha((unsigned char)(x))
1249412527
# define sqlite3Isdigit(x) isdigit((unsigned char)(x))
1249512528
# define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
1249612529
# define sqlite3Tolower(x) tolower((unsigned char)(x))
1249712530
#endif
12531
+SQLITE_PRIVATE int sqlite3IsIdChar(u8);
1249812532
1249912533
/*
1250012534
** Internal function prototypes
1250112535
*/
1250212536
#define sqlite3StrICmp sqlite3_stricmp
@@ -12591,29 +12625,18 @@
1259112625
#endif
1259212626
#if defined(SQLITE_TEST)
1259312627
SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
1259412628
#endif
1259512629
12596
-/* Output formatting for SQLITE_TESTCTRL_EXPLAIN */
12597
-#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
12598
-SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe*);
12599
-SQLITE_PRIVATE void sqlite3ExplainPrintf(Vdbe*, const char*, ...);
12600
-SQLITE_PRIVATE void sqlite3ExplainNL(Vdbe*);
12601
-SQLITE_PRIVATE void sqlite3ExplainPush(Vdbe*);
12602
-SQLITE_PRIVATE void sqlite3ExplainPop(Vdbe*);
12603
-SQLITE_PRIVATE void sqlite3ExplainFinish(Vdbe*);
12604
-SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe*, Select*);
12605
-SQLITE_PRIVATE void sqlite3ExplainExpr(Vdbe*, Expr*);
12606
-SQLITE_PRIVATE void sqlite3ExplainExprList(Vdbe*, ExprList*);
12607
-SQLITE_PRIVATE const char *sqlite3VdbeExplanation(Vdbe*);
12608
-#else
12609
-# define sqlite3ExplainBegin(X)
12610
-# define sqlite3ExplainSelect(A,B)
12611
-# define sqlite3ExplainExpr(A,B)
12612
-# define sqlite3ExplainExprList(A,B)
12613
-# define sqlite3ExplainFinish(X)
12614
-# define sqlite3VdbeExplanation(X) 0
12630
+#if defined(SQLITE_DEBUG)
12631
+SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView*,u8);
12632
+SQLITE_PRIVATE void sqlite3TreeViewPop(TreeView*);
12633
+SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView*, const char*, ...);
12634
+SQLITE_PRIVATE void sqlite3TreeViewItem(TreeView*, const char*, u8);
12635
+SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
12636
+SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
12637
+SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
1261512638
#endif
1261612639
1261712640
1261812641
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*, ...);
1261912642
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -12791,11 +12814,11 @@
1279112814
SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
1279212815
SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
1279312816
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
1279412817
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1279512818
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12796
-SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
12819
+SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
1279712820
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
1279812821
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
1279912822
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
1280012823
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
1280112824
SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -12815,10 +12838,15 @@
1281512838
SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
1281612839
SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
1281712840
SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
1281812841
SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*);
1281912842
SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int);
12843
+#if SELECTTRACE_ENABLED
12844
+SQLITE_PRIVATE void sqlite3SelectSetName(Select*,const char*);
12845
+#else
12846
+# define sqlite3SelectSetName(A,B)
12847
+#endif
1282012848
SQLITE_PRIVATE void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*);
1282112849
SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8);
1282212850
SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3*);
1282312851
SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void);
1282412852
SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void);
@@ -13292,14 +13320,13 @@
1329213320
# define sqlite3MemdebugSetType(X,Y) /* no-op */
1329313321
# define sqlite3MemdebugHasType(X,Y) 1
1329413322
# define sqlite3MemdebugNoType(X,Y) 1
1329513323
#endif
1329613324
#define MEMTYPE_HEAP 0x01 /* General heap allocations */
13297
-#define MEMTYPE_LOOKASIDE 0x02 /* Might have been lookaside memory */
13325
+#define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
1329813326
#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
1329913327
#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
13300
-#define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
1330113328
1330213329
/*
1330313330
** Threading interface
1330413331
*/
1330513332
#if SQLITE_MAX_WORKER_THREADS>0
@@ -13439,10 +13466,17 @@
1343913466
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
1344013467
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
1344113468
};
1344213469
#endif
1344313470
13471
+/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
13472
+** compatibility for legacy applications, the URI filename capability is
13473
+** disabled by default.
13474
+**
13475
+** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
13476
+** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
13477
+*/
1344413478
#ifndef SQLITE_USE_URI
1344513479
# define SQLITE_USE_URI 0
1344613480
#endif
1344713481
1344813482
#ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
@@ -13945,11 +13979,11 @@
1394513979
1394613980
/* Since ArraySize(azCompileOpt) is normally in single digits, a
1394713981
** linear search is adequate. No need for a binary search. */
1394813982
for(i=0; i<ArraySize(azCompileOpt); i++){
1394913983
if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
13950
- && sqlite3CtypeMap[(unsigned char)azCompileOpt[i][n]]==0
13984
+ && sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0
1395113985
){
1395213986
return 1;
1395313987
}
1395413988
}
1395513989
return 0;
@@ -14060,21 +14094,19 @@
1406014094
#ifdef SQLITE_DEBUG
1406114095
u8 seekOp; /* Most recent seek operation on this cursor */
1406214096
#endif
1406314097
i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
1406414098
u8 nullRow; /* True if pointing to a row with no data */
14065
- u8 rowidIsValid; /* True if lastRowid is valid */
1406614099
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1406714100
Bool isEphemeral:1; /* True for an ephemeral table */
1406814101
Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
1406914102
Bool isTable:1; /* True if a table requiring integer keys */
1407014103
Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
1407114104
Pgno pgnoRoot; /* Root page of the open btree cursor */
1407214105
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
1407314106
i64 seqCount; /* Sequence counter */
1407414107
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
14075
- i64 lastRowid; /* Rowid being deleted by OP_Delete */
1407614108
VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
1407714109
1407814110
/* Cached information about the header for the data record that the
1407914111
** cursor is currently pointing to. Only valid if cacheStatus matches
1408014112
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -14087,10 +14119,11 @@
1408714119
u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
1408814120
u32 payloadSize; /* Total number of bytes in the record */
1408914121
u32 szRow; /* Byte available in aRow */
1409014122
u32 iHdrOffset; /* Offset to next unparsed byte of the header */
1409114123
const u8 *aRow; /* Data for the current row, if all on one page */
14124
+ u32 *aOffset; /* Pointer to aType[nField] */
1409214125
u32 aType[1]; /* Type values for all entries in the record */
1409314126
/* 2*nField extra array elements allocated for aType[], beyond the one
1409414127
** static element declared in the structure. nField total array slots for
1409514128
** aType[] and nField+1 array slots for aOffset[] */
1409614129
};
@@ -14163,11 +14196,11 @@
1416314196
int n; /* Number of characters in string value, excluding '\0' */
1416414197
char *z; /* String or BLOB value */
1416514198
/* ShallowCopy only needs to copy the information above */
1416614199
char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
1416714200
int szMalloc; /* Size of the zMalloc allocation */
14168
- int iPadding1; /* Padding for 8-byte alignment */
14201
+ u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
1416914202
sqlite3 *db; /* The associated database connection */
1417014203
void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
1417114204
#ifdef SQLITE_DEBUG
1417214205
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
1417314206
void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
@@ -14259,11 +14292,10 @@
1425914292
*/
1426014293
struct sqlite3_context {
1426114294
Mem *pOut; /* The return value is stored here */
1426214295
FuncDef *pFunc; /* Pointer to function information */
1426314296
Mem *pMem; /* Memory cell used to store aggregate context */
14264
- CollSeq *pColl; /* Collating sequence */
1426514297
Vdbe *pVdbe; /* The VM that owns this context */
1426614298
int iOp; /* Instruction number of OP_Function */
1426714299
int isError; /* Error code returned by the function. */
1426814300
u8 skipFlag; /* Skip accumulator loading if true */
1426914301
u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
@@ -14348,14 +14380,10 @@
1434814380
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1434914381
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
1435014382
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
1435114383
char *zSql; /* Text of the SQL statement that generated this */
1435214384
void *pFree; /* Free this when deleting the vdbe */
14353
-#ifdef SQLITE_ENABLE_TREE_EXPLAIN
14354
- Explain *pExplain; /* The explainer */
14355
- char *zExplain; /* Explanation of data structures */
14356
-#endif
1435714385
VdbeFrame *pFrame; /* Parent frame */
1435814386
VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */
1435914387
int nFrame; /* Number of frames in pFrame list */
1436014388
u32 expmask; /* Binding to these vars invalidates VM */
1436114389
SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
@@ -14376,10 +14404,11 @@
1437614404
** Function prototypes
1437714405
*/
1437814406
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
1437914407
void sqliteVdbePopStack(Vdbe*,int);
1438014408
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
14409
+SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
1438114410
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
1438214411
SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
1438314412
#endif
1438414413
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
1438514414
SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
@@ -14675,11 +14704,11 @@
1467514704
sqlite3VdbeClearObject(db, pVdbe);
1467614705
sqlite3DbFree(db, pVdbe);
1467714706
}
1467814707
db->pnBytesFreed = 0;
1467914708
14680
- *pHighwater = 0;
14709
+ *pHighwater = 0; /* IMP: R-64479-57858 */
1468114710
*pCurrent = nByte;
1468214711
1468314712
break;
1468414713
}
1468514714
@@ -14700,21 +14729,23 @@
1470014729
if( db->aDb[i].pBt ){
1470114730
Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
1470214731
sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet);
1470314732
}
1470414733
}
14705
- *pHighwater = 0;
14734
+ *pHighwater = 0; /* IMP: R-42420-56072 */
14735
+ /* IMP: R-54100-20147 */
14736
+ /* IMP: R-29431-39229 */
1470614737
*pCurrent = nRet;
1470714738
break;
1470814739
}
1470914740
1471014741
/* Set *pCurrent to non-zero if there are unresolved deferred foreign
1471114742
** key constraints. Set *pCurrent to zero if all foreign key constraints
1471214743
** have been satisfied. The *pHighwater is always set to zero.
1471314744
*/
1471414745
case SQLITE_DBSTATUS_DEFERRED_FKS: {
14715
- *pHighwater = 0;
14746
+ *pHighwater = 0; /* IMP: R-11967-56545 */
1471614747
*pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
1471714748
break;
1471814749
}
1471914750
1472014751
default: {
@@ -17098,11 +17129,11 @@
1709817129
** allocation p. Also return true if p==NULL.
1709917130
**
1710017131
** This routine is designed for use within an assert() statement, to
1710117132
** verify the type of an allocation. For example:
1710217133
**
17103
-** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17134
+** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1710417135
*/
1710517136
SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
1710617137
int rc = 1;
1710717138
if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
1710817139
struct MemBlockHdr *pHdr;
@@ -17120,11 +17151,11 @@
1712017151
** allocation p. Also return true if p==NULL.
1712117152
**
1712217153
** This routine is designed for use within an assert() statement, to
1712317154
** verify the type of an allocation. For example:
1712417155
**
17125
-** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
17156
+** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
1712617157
*/
1712717158
SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
1712817159
int rc = 1;
1712917160
if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
1713017161
struct MemBlockHdr *pHdr;
@@ -20195,11 +20226,11 @@
2019520226
mallocWithAlarm((int)n, &p);
2019620227
sqlite3_mutex_leave(mem0.mutex);
2019720228
}else{
2019820229
p = sqlite3GlobalConfig.m.xMalloc((int)n);
2019920230
}
20200
- assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */
20231
+ assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-11148-40995 */
2020120232
return p;
2020220233
}
2020320234
2020420235
/*
2020520236
** This version of the memory allocation is for use by the application.
@@ -20332,39 +20363,41 @@
2033220363
** Return the size of a memory allocation previously obtained from
2033320364
** sqlite3Malloc() or sqlite3_malloc().
2033420365
*/
2033520366
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
2033620367
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20337
- assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
2033820368
return sqlite3GlobalConfig.m.xSize(p);
2033920369
}
2034020370
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
2034120371
if( db==0 ){
20372
+ assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20373
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2034220374
return sqlite3MallocSize(p);
2034320375
}else{
2034420376
assert( sqlite3_mutex_held(db->mutex) );
2034520377
if( isLookaside(db, p) ){
2034620378
return db->lookaside.sz;
2034720379
}else{
20348
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20349
- assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20350
- assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20380
+ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20381
+ assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2035120382
return sqlite3GlobalConfig.m.xSize(p);
2035220383
}
2035320384
}
2035420385
}
2035520386
SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20387
+ assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20388
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2035620389
return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
2035720390
}
2035820391
2035920392
/*
2036020393
** Free memory previously obtained from sqlite3Malloc().
2036120394
*/
2036220395
SQLITE_API void sqlite3_free(void *p){
2036320396
if( p==0 ) return; /* IMP: R-49053-54554 */
20364
- assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
2036520397
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20398
+ assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
2036620399
if( sqlite3GlobalConfig.bMemstat ){
2036720400
sqlite3_mutex_enter(mem0.mutex);
2036820401
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
2036920402
sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
2037020403
sqlite3GlobalConfig.m.xFree(p);
@@ -20404,12 +20437,12 @@
2040420437
db->lookaside.pFree = pBuf;
2040520438
db->lookaside.nOut--;
2040620439
return;
2040720440
}
2040820441
}
20409
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20410
- assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20442
+ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20443
+ assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2041120444
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
2041220445
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2041320446
sqlite3_free(p);
2041420447
}
2041520448
@@ -20417,15 +20450,17 @@
2041720450
** Change the size of an existing memory allocation
2041820451
*/
2041920452
SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
2042020453
int nOld, nNew, nDiff;
2042120454
void *pNew;
20455
+ assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20456
+ assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
2042220457
if( pOld==0 ){
20423
- return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
20458
+ return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
2042420459
}
2042520460
if( nBytes==0 ){
20426
- sqlite3_free(pOld); /* IMP: R-31593-10574 */
20461
+ sqlite3_free(pOld); /* IMP: R-26507-47431 */
2042720462
return 0;
2042820463
}
2042920464
if( nBytes>=0x7fffff00 ){
2043020465
/* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
2043120466
return 0;
@@ -20443,12 +20478,10 @@
2044320478
nDiff = nNew - nOld;
2044420479
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
2044520480
mem0.alarmThreshold-nDiff ){
2044620481
sqlite3MallocAlarm(nDiff);
2044720482
}
20448
- assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20449
- assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
2045020483
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2045120484
if( pNew==0 && mem0.alarmCallback ){
2045220485
sqlite3MallocAlarm((int)nBytes);
2045320486
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2045420487
}
@@ -20458,11 +20491,11 @@
2045820491
}
2045920492
sqlite3_mutex_leave(mem0.mutex);
2046020493
}else{
2046120494
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2046220495
}
20463
- assert( EIGHT_BYTE_ALIGNMENT(pNew) ); /* IMP: R-04675-44850 */
20496
+ assert( EIGHT_BYTE_ALIGNMENT(pNew) ); /* IMP: R-11148-40995 */
2046420497
return pNew;
2046520498
}
2046620499
2046720500
/*
2046820501
** The public interface to sqlite3Realloc. Make sure that the memory
@@ -20470,11 +20503,11 @@
2047020503
*/
2047120504
SQLITE_API void *sqlite3_realloc(void *pOld, int n){
2047220505
#ifndef SQLITE_OMIT_AUTOINIT
2047320506
if( sqlite3_initialize() ) return 0;
2047420507
#endif
20475
- if( n<0 ) n = 0;
20508
+ if( n<0 ) n = 0; /* IMP: R-26507-47431 */
2047620509
return sqlite3Realloc(pOld, n);
2047720510
}
2047820511
SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
2047920512
#ifndef SQLITE_OMIT_AUTOINIT
2048020513
if( sqlite3_initialize() ) return 0;
@@ -20557,12 +20590,12 @@
2055720590
#endif
2055820591
p = sqlite3Malloc(n);
2055920592
if( !p && db ){
2056020593
db->mallocFailed = 1;
2056120594
}
20562
- sqlite3MemdebugSetType(p, MEMTYPE_DB |
20563
- ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20595
+ sqlite3MemdebugSetType(p,
20596
+ (db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
2056420597
return p;
2056520598
}
2056620599
2056720600
/*
2056820601
** Resize the block of memory pointed to by p to n bytes. If the
@@ -20584,19 +20617,18 @@
2058420617
if( pNew ){
2058520618
memcpy(pNew, p, db->lookaside.sz);
2058620619
sqlite3DbFree(db, p);
2058720620
}
2058820621
}else{
20589
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20590
- assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20622
+ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20623
+ assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2059120624
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2059220625
pNew = sqlite3_realloc64(p, n);
2059320626
if( !pNew ){
20594
- sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
2059520627
db->mallocFailed = 1;
2059620628
}
20597
- sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
20629
+ sqlite3MemdebugSetType(pNew,
2059820630
(db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
2059920631
}
2060020632
}
2060120633
return pNew;
2060220634
}
@@ -21757,10 +21789,73 @@
2175721789
fprintf(stdout,"%s", zBuf);
2175821790
fflush(stdout);
2175921791
}
2176021792
#endif
2176121793
21794
+#ifdef SQLITE_DEBUG
21795
+/*************************************************************************
21796
+** Routines for implementing the "TreeView" display of hierarchical
21797
+** data structures for debugging.
21798
+**
21799
+** The main entry points (coded elsewhere) are:
21800
+** sqlite3TreeViewExpr(0, pExpr, 0);
21801
+** sqlite3TreeViewExprList(0, pList, 0, 0);
21802
+** sqlite3TreeViewSelect(0, pSelect, 0);
21803
+** Insert calls to those routines while debugging in order to display
21804
+** a diagram of Expr, ExprList, and Select objects.
21805
+**
21806
+*/
21807
+/* Add a new subitem to the tree. The moreToFollow flag indicates that this
21808
+** is not the last item in the tree. */
21809
+SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
21810
+ if( p==0 ){
21811
+ p = sqlite3_malloc( sizeof(*p) );
21812
+ if( p==0 ) return 0;
21813
+ memset(p, 0, sizeof(*p));
21814
+ }else{
21815
+ p->iLevel++;
21816
+ }
21817
+ assert( moreToFollow==0 || moreToFollow==1 );
21818
+ if( p->iLevel<sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
21819
+ return p;
21820
+}
21821
+/* Finished with one layer of the tree */
21822
+SQLITE_PRIVATE void sqlite3TreeViewPop(TreeView *p){
21823
+ if( p==0 ) return;
21824
+ p->iLevel--;
21825
+ if( p->iLevel<0 ) sqlite3_free(p);
21826
+}
21827
+/* Generate a single line of output for the tree, with a prefix that contains
21828
+** all the appropriate tree lines */
21829
+SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
21830
+ va_list ap;
21831
+ int i;
21832
+ StrAccum acc;
21833
+ char zBuf[500];
21834
+ sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
21835
+ acc.useMalloc = 0;
21836
+ if( p ){
21837
+ for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
21838
+ sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
21839
+ }
21840
+ sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
21841
+ }
21842
+ va_start(ap, zFormat);
21843
+ sqlite3VXPrintf(&acc, 0, zFormat, ap);
21844
+ va_end(ap);
21845
+ if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
21846
+ sqlite3StrAccumFinish(&acc);
21847
+ fprintf(stdout,"%s", zBuf);
21848
+ fflush(stdout);
21849
+}
21850
+/* Shorthand for starting a new tree item that consists of a single label */
21851
+SQLITE_PRIVATE void sqlite3TreeViewItem(TreeView *p, const char *zLabel, u8 moreToFollow){
21852
+ p = sqlite3TreeViewPush(p, moreToFollow);
21853
+ sqlite3TreeViewLine(p, "%s", zLabel);
21854
+}
21855
+#endif /* SQLITE_DEBUG */
21856
+
2176221857
/*
2176321858
** variable-argument wrapper around sqlite3VXPrintf().
2176421859
*/
2176521860
SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
2176621861
va_list ap;
@@ -22003,11 +22098,11 @@
2200322098
#define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
2200422099
#include <process.h>
2200522100
2200622101
/* A running thread */
2200722102
struct SQLiteThread {
22008
- uintptr_t tid; /* The thread handle */
22103
+ void *tid; /* The thread handle */
2200922104
unsigned id; /* The thread identifier */
2201022105
void *(*xTask)(void*); /* The routine to run as a thread */
2201122106
void *pIn; /* Argument to xTask */
2201222107
void *pResult; /* Result of xTask */
2201322108
};
@@ -22051,11 +22146,11 @@
2205122146
if( sqlite3GlobalConfig.bCoreMutex==0 ){
2205222147
memset(p, 0, sizeof(*p));
2205322148
}else{
2205422149
p->xTask = xTask;
2205522150
p->pIn = pIn;
22056
- p->tid = _beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
22151
+ p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
2205722152
if( p->tid==0 ){
2205822153
memset(p, 0, sizeof(*p));
2205922154
}
2206022155
}
2206122156
if( p->xTask==0 ){
@@ -29659,11 +29754,11 @@
2965929754
** methods CLOSE, LOCK, UNLOCK, CKRESLOCK.
2966029755
**
2966129756
** * An I/O method finder function called FINDER that returns a pointer
2966229757
** to the METHOD object in the previous bullet.
2966329758
*/
29664
-#define IOMETHODS(FINDER, METHOD, VERSION, CLOSE, LOCK, UNLOCK, CKLOCK) \
29759
+#define IOMETHODS(FINDER, METHOD, VERSION, CLOSE, LOCK, UNLOCK, CKLOCK, SHMMAP) \
2966529760
static const sqlite3_io_methods METHOD = { \
2966629761
VERSION, /* iVersion */ \
2966729762
CLOSE, /* xClose */ \
2966829763
unixRead, /* xRead */ \
2966929764
unixWrite, /* xWrite */ \
@@ -29674,11 +29769,11 @@
2967429769
UNLOCK, /* xUnlock */ \
2967529770
CKLOCK, /* xCheckReservedLock */ \
2967629771
unixFileControl, /* xFileControl */ \
2967729772
unixSectorSize, /* xSectorSize */ \
2967829773
unixDeviceCharacteristics, /* xDeviceCapabilities */ \
29679
- unixShmMap, /* xShmMap */ \
29774
+ SHMMAP, /* xShmMap */ \
2968029775
unixShmLock, /* xShmLock */ \
2968129776
unixShmBarrier, /* xShmBarrier */ \
2968229777
unixShmUnmap, /* xShmUnmap */ \
2968329778
unixFetch, /* xFetch */ \
2968429779
unixUnfetch, /* xUnfetch */ \
@@ -29700,29 +29795,32 @@
2970029795
posixIoMethods, /* sqlite3_io_methods object name */
2970129796
3, /* shared memory and mmap are enabled */
2970229797
unixClose, /* xClose method */
2970329798
unixLock, /* xLock method */
2970429799
unixUnlock, /* xUnlock method */
29705
- unixCheckReservedLock /* xCheckReservedLock method */
29800
+ unixCheckReservedLock, /* xCheckReservedLock method */
29801
+ unixShmMap /* xShmMap method */
2970629802
)
2970729803
IOMETHODS(
2970829804
nolockIoFinder, /* Finder function name */
2970929805
nolockIoMethods, /* sqlite3_io_methods object name */
2971029806
3, /* shared memory is disabled */
2971129807
nolockClose, /* xClose method */
2971229808
nolockLock, /* xLock method */
2971329809
nolockUnlock, /* xUnlock method */
29714
- nolockCheckReservedLock /* xCheckReservedLock method */
29810
+ nolockCheckReservedLock, /* xCheckReservedLock method */
29811
+ 0 /* xShmMap method */
2971529812
)
2971629813
IOMETHODS(
2971729814
dotlockIoFinder, /* Finder function name */
2971829815
dotlockIoMethods, /* sqlite3_io_methods object name */
2971929816
1, /* shared memory is disabled */
2972029817
dotlockClose, /* xClose method */
2972129818
dotlockLock, /* xLock method */
2972229819
dotlockUnlock, /* xUnlock method */
29723
- dotlockCheckReservedLock /* xCheckReservedLock method */
29820
+ dotlockCheckReservedLock, /* xCheckReservedLock method */
29821
+ 0 /* xShmMap method */
2972429822
)
2972529823
2972629824
#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
2972729825
IOMETHODS(
2972829826
flockIoFinder, /* Finder function name */
@@ -29729,11 +29827,12 @@
2972929827
flockIoMethods, /* sqlite3_io_methods object name */
2973029828
1, /* shared memory is disabled */
2973129829
flockClose, /* xClose method */
2973229830
flockLock, /* xLock method */
2973329831
flockUnlock, /* xUnlock method */
29734
- flockCheckReservedLock /* xCheckReservedLock method */
29832
+ flockCheckReservedLock, /* xCheckReservedLock method */
29833
+ 0 /* xShmMap method */
2973529834
)
2973629835
#endif
2973729836
2973829837
#if OS_VXWORKS
2973929838
IOMETHODS(
@@ -29741,11 +29840,12 @@
2974129840
semIoMethods, /* sqlite3_io_methods object name */
2974229841
1, /* shared memory is disabled */
2974329842
semClose, /* xClose method */
2974429843
semLock, /* xLock method */
2974529844
semUnlock, /* xUnlock method */
29746
- semCheckReservedLock /* xCheckReservedLock method */
29845
+ semCheckReservedLock, /* xCheckReservedLock method */
29846
+ 0 /* xShmMap method */
2974729847
)
2974829848
#endif
2974929849
2975029850
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2975129851
IOMETHODS(
@@ -29753,11 +29853,12 @@
2975329853
afpIoMethods, /* sqlite3_io_methods object name */
2975429854
1, /* shared memory is disabled */
2975529855
afpClose, /* xClose method */
2975629856
afpLock, /* xLock method */
2975729857
afpUnlock, /* xUnlock method */
29758
- afpCheckReservedLock /* xCheckReservedLock method */
29858
+ afpCheckReservedLock, /* xCheckReservedLock method */
29859
+ 0 /* xShmMap method */
2975929860
)
2976029861
#endif
2976129862
2976229863
/*
2976329864
** The proxy locking method is a "super-method" in the sense that it
@@ -29778,11 +29879,12 @@
2977829879
proxyIoMethods, /* sqlite3_io_methods object name */
2977929880
1, /* shared memory is disabled */
2978029881
proxyClose, /* xClose method */
2978129882
proxyLock, /* xLock method */
2978229883
proxyUnlock, /* xUnlock method */
29783
- proxyCheckReservedLock /* xCheckReservedLock method */
29884
+ proxyCheckReservedLock, /* xCheckReservedLock method */
29885
+ 0 /* xShmMap method */
2978429886
)
2978529887
#endif
2978629888
2978729889
/* nfs lockd on OSX 10.3+ doesn't clear write locks when a read lock is set */
2978829890
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -29791,11 +29893,12 @@
2979129893
nfsIoMethods, /* sqlite3_io_methods object name */
2979229894
1, /* shared memory is disabled */
2979329895
unixClose, /* xClose method */
2979429896
unixLock, /* xLock method */
2979529897
nfsUnlock, /* xUnlock method */
29796
- unixCheckReservedLock /* xCheckReservedLock method */
29898
+ unixCheckReservedLock, /* xCheckReservedLock method */
29899
+ 0 /* xShmMap method */
2979729900
)
2979829901
#endif
2979929902
2980029903
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2980129904
/*
@@ -39752,11 +39855,11 @@
3975239855
assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
3975339856
assert( pCache->n90pct == pCache->nMax*9/10 );
3975439857
if( createFlag==1 && (
3975539858
nPinned>=pGroup->mxPinned
3975639859
|| nPinned>=pCache->n90pct
39757
- || pcache1UnderMemoryPressure(pCache)
39860
+ || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
3975839861
)){
3975939862
return 0;
3976039863
}
3976139864
3976239865
if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
@@ -44373,17 +44476,19 @@
4437344476
if( !pNew ) rc = SQLITE_NOMEM;
4437444477
}
4437544478
4437644479
if( rc==SQLITE_OK ){
4437744480
pager_reset(pPager);
44378
- sqlite3PageFree(pPager->pTmpSpace);
44379
- pPager->pTmpSpace = pNew;
4438044481
rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
4438144482
}
4438244483
if( rc==SQLITE_OK ){
44484
+ sqlite3PageFree(pPager->pTmpSpace);
44485
+ pPager->pTmpSpace = pNew;
4438344486
pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
4438444487
pPager->pageSize = pageSize;
44488
+ }else{
44489
+ sqlite3PageFree(pNew);
4438544490
}
4438644491
}
4438744492
4438844493
*pPageSize = pPager->pageSize;
4438944494
if( rc==SQLITE_OK ){
@@ -51383,13 +51488,14 @@
5138351488
** stored in MemPage.pBt->mutex.
5138451489
*/
5138551490
struct MemPage {
5138651491
u8 isInit; /* True if previously initialized. MUST BE FIRST! */
5138751492
u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
51388
- u8 intKey; /* True if intkey flag is set */
51389
- u8 leaf; /* True if leaf flag is set */
51390
- u8 hasData; /* True if this page stores data */
51493
+ u8 intKey; /* True if table b-trees. False for index b-trees */
51494
+ u8 intKeyLeaf; /* True if the leaf of an intKey table */
51495
+ u8 noPayload; /* True if internal intKey page (thus w/o data) */
51496
+ u8 leaf; /* True if a leaf page */
5139151497
u8 hdrOffset; /* 100 for page 1. 0 otherwise */
5139251498
u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
5139351499
u8 max1bytePayload; /* min(maxLocal,127) */
5139451500
u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
5139551501
u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
@@ -51545,11 +51651,11 @@
5154551651
int nRef; /* Number of references to this structure */
5154651652
BtShared *pNext; /* Next on a list of sharable BtShared structs */
5154751653
BtLock *pLock; /* List of locks held on this shared-btree struct */
5154851654
Btree *pWriter; /* Btree with currently open write transaction */
5154951655
#endif
51550
- u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
51656
+ u8 *pTmpSpace; /* Temp space sufficient to hold a single cell */
5155151657
};
5155251658
5155351659
/*
5155451660
** Allowed values for BtShared.btsFlags
5155551661
*/
@@ -51566,16 +51672,14 @@
5156651672
** about a cell. The parseCellPtr() function fills in this structure
5156751673
** based on information extract from the raw disk page.
5156851674
*/
5156951675
typedef struct CellInfo CellInfo;
5157051676
struct CellInfo {
51571
- i64 nKey; /* The key for INTKEY tables, or number of bytes in key */
51572
- u8 *pCell; /* Pointer to the start of cell content */
51573
- u32 nData; /* Number of bytes of data */
51574
- u32 nPayload; /* Total amount of payload */
51575
- u16 nHeader; /* Size of the cell content header in bytes */
51576
- u16 nLocal; /* Amount of payload held locally */
51677
+ i64 nKey; /* The key for INTKEY tables, or nPayload otherwise */
51678
+ u8 *pPayload; /* Pointer to the start of payload */
51679
+ u32 nPayload; /* Bytes of payload */
51680
+ u16 nLocal; /* Amount of payload held locally, not on overflow */
5157751681
u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */
5157851682
u16 nSize; /* Size of the cell content on the main b-tree page */
5157951683
};
5158051684
5158151685
/*
@@ -51768,10 +51872,12 @@
5176851872
u8 *aPgRef; /* 1 bit per page in the db (see above) */
5176951873
Pgno nPage; /* Number of pages in the database */
5177051874
int mxErr; /* Stop accumulating errors when this reaches zero */
5177151875
int nErr; /* Number of messages written to zErrMsg so far */
5177251876
int mallocFailed; /* A memory allocation error has occurred */
51877
+ const char *zPfx; /* Error message prefix */
51878
+ int v1, v2; /* Values for up to two %d fields in zPfx */
5177351879
StrAccum errMsg; /* Accumulate the error message text here */
5177451880
};
5177551881
5177651882
/*
5177751883
** Routines to read or write a two- and four-byte big-endian integer values.
@@ -52554,11 +52660,13 @@
5255452660
){
5255552661
BtCursor *p;
5255652662
BtShared *pBt = pBtree->pBt;
5255752663
assert( sqlite3BtreeHoldsMutex(pBtree) );
5255852664
for(p=pBt->pCursor; p; p=p->pNext){
52559
- if( (p->curFlags & BTCF_Incrblob)!=0 && (isClearTable || p->info.nKey==iRow) ){
52665
+ if( (p->curFlags & BTCF_Incrblob)!=0
52666
+ && (isClearTable || p->info.nKey==iRow)
52667
+ ){
5256052668
p->eState = CURSOR_INVALID;
5256152669
}
5256252670
}
5256352671
}
5256452672
@@ -52727,13 +52835,13 @@
5272752835
** the cursors if and when a cursor is found that actually requires saving.
5272852836
** The common case is that no cursors need to be saved, so this routine is
5272952837
** broken out from its caller to avoid unnecessary stack pointer movement.
5273052838
*/
5273152839
static int SQLITE_NOINLINE saveCursorsOnList(
52732
- BtCursor *p, /* The first cursor that needs saving */
52733
- Pgno iRoot, /* Only save cursor with this iRoot. Save all if zero */
52734
- BtCursor *pExcept /* Do not save this cursor */
52840
+ BtCursor *p, /* The first cursor that needs saving */
52841
+ Pgno iRoot, /* Only save cursor with this iRoot. Save all if zero */
52842
+ BtCursor *pExcept /* Do not save this cursor */
5273552843
){
5273652844
do{
5273752845
if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
5273852846
if( p->eState==CURSOR_VALID ){
5273952847
int rc = saveCursorPosition(p);
@@ -52841,11 +52949,11 @@
5284152949
**
5284252950
** Use the separate sqlite3BtreeCursorRestore() routine to restore a cursor
5284352951
** back to where it ought to be if this routine returns true.
5284452952
*/
5284552953
SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
52846
- return pCur && pCur->eState!=CURSOR_VALID;
52954
+ return pCur->eState!=CURSOR_VALID;
5284752955
}
5284852956
5284952957
/*
5285052958
** This routine restores a cursor back to its original position after it
5285152959
** has been moved by some outside activity (such as a btree rebalance or
@@ -53035,51 +53143,48 @@
5303553143
/*
5303653144
** Parse a cell content block and fill in the CellInfo structure. There
5303753145
** are two versions of this function. btreeParseCell() takes a
5303853146
** cell index as the second argument and btreeParseCellPtr()
5303953147
** takes a pointer to the body of the cell as its second argument.
53040
-**
53041
-** Within this file, the parseCell() macro can be called instead of
53042
-** btreeParseCellPtr(). Using some compilers, this will be faster.
5304353148
*/
5304453149
static void btreeParseCellPtr(
5304553150
MemPage *pPage, /* Page containing the cell */
5304653151
u8 *pCell, /* Pointer to the cell text. */
5304753152
CellInfo *pInfo /* Fill in this structure */
5304853153
){
53049
- u16 n; /* Number bytes in cell content header */
53154
+ u8 *pIter; /* For scanning through pCell */
5305053155
u32 nPayload; /* Number of bytes of cell payload */
5305153156
5305253157
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53053
-
53054
- pInfo->pCell = pCell;
5305553158
assert( pPage->leaf==0 || pPage->leaf==1 );
53056
- n = pPage->childPtrSize;
53057
- assert( n==4-4*pPage->leaf );
53058
- if( pPage->intKey ){
53059
- if( pPage->hasData ){
53060
- assert( n==0 );
53061
- n = getVarint32(pCell, nPayload);
53062
- }else{
53063
- nPayload = 0;
53064
- }
53065
- n += getVarint(&pCell[n], (u64*)&pInfo->nKey);
53066
- pInfo->nData = nPayload;
53067
- }else{
53068
- pInfo->nData = 0;
53069
- n += getVarint32(&pCell[n], nPayload);
53159
+ if( pPage->intKeyLeaf ){
53160
+ assert( pPage->childPtrSize==0 );
53161
+ pIter = pCell + getVarint32(pCell, nPayload);
53162
+ pIter += getVarint(pIter, (u64*)&pInfo->nKey);
53163
+ }else if( pPage->noPayload ){
53164
+ assert( pPage->childPtrSize==4 );
53165
+ pInfo->nSize = 4 + getVarint(&pCell[4], (u64*)&pInfo->nKey);
53166
+ pInfo->nPayload = 0;
53167
+ pInfo->nLocal = 0;
53168
+ pInfo->iOverflow = 0;
53169
+ pInfo->pPayload = 0;
53170
+ return;
53171
+ }else{
53172
+ pIter = pCell + pPage->childPtrSize;
53173
+ pIter += getVarint32(pIter, nPayload);
5307053174
pInfo->nKey = nPayload;
5307153175
}
5307253176
pInfo->nPayload = nPayload;
53073
- pInfo->nHeader = n;
53177
+ pInfo->pPayload = pIter;
5307453178
testcase( nPayload==pPage->maxLocal );
5307553179
testcase( nPayload==pPage->maxLocal+1 );
53076
- if( likely(nPayload<=pPage->maxLocal) ){
53180
+ if( nPayload<=pPage->maxLocal ){
5307753181
/* This is the (easy) common case where the entire payload fits
5307853182
** on the local page. No overflow is required.
5307953183
*/
53080
- if( (pInfo->nSize = (u16)(n+nPayload))<4 ) pInfo->nSize = 4;
53184
+ pInfo->nSize = nPayload + (u16)(pIter - pCell);
53185
+ if( pInfo->nSize<4 ) pInfo->nSize = 4;
5308153186
pInfo->nLocal = (u16)nPayload;
5308253187
pInfo->iOverflow = 0;
5308353188
}else{
5308453189
/* If the payload will not fit completely on the local page, we have
5308553190
** to decide how much to store locally and how much to spill onto
@@ -53102,33 +53207,32 @@
5310253207
if( surplus <= maxLocal ){
5310353208
pInfo->nLocal = (u16)surplus;
5310453209
}else{
5310553210
pInfo->nLocal = (u16)minLocal;
5310653211
}
53107
- pInfo->iOverflow = (u16)(pInfo->nLocal + n);
53212
+ pInfo->iOverflow = (u16)(&pInfo->pPayload[pInfo->nLocal] - pCell);
5310853213
pInfo->nSize = pInfo->iOverflow + 4;
5310953214
}
5311053215
}
53111
-#define parseCell(pPage, iCell, pInfo) \
53112
- btreeParseCellPtr((pPage), findCell((pPage), (iCell)), (pInfo))
5311353216
static void btreeParseCell(
5311453217
MemPage *pPage, /* Page containing the cell */
5311553218
int iCell, /* The cell index. First cell is 0 */
5311653219
CellInfo *pInfo /* Fill in this structure */
5311753220
){
53118
- parseCell(pPage, iCell, pInfo);
53221
+ btreeParseCellPtr(pPage, findCell(pPage, iCell), pInfo);
5311953222
}
5312053223
5312153224
/*
5312253225
** Compute the total number of bytes that a Cell needs in the cell
5312353226
** data area of the btree-page. The return number includes the cell
5312453227
** data header and the local payload, but not any overflow page or
5312553228
** the space used by the cell pointer.
5312653229
*/
5312753230
static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
53128
- u8 *pIter = &pCell[pPage->childPtrSize];
53129
- u32 nSize;
53231
+ u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */
53232
+ u8 *pEnd; /* End mark for a varint */
53233
+ u32 nSize; /* Size value to return */
5313053234
5313153235
#ifdef SQLITE_DEBUG
5313253236
/* The value returned by this function should always be the same as
5313353237
** the (CellInfo.nSize) value found by doing a full parse of the
5313453238
** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
@@ -53135,47 +53239,48 @@
5313553239
** this function verifies that this invariant is not violated. */
5313653240
CellInfo debuginfo;
5313753241
btreeParseCellPtr(pPage, pCell, &debuginfo);
5313853242
#endif
5313953243
53244
+ if( pPage->noPayload ){
53245
+ pEnd = &pIter[9];
53246
+ while( (*pIter++)&0x80 && pIter<pEnd );
53247
+ assert( pPage->childPtrSize==4 );
53248
+ return (u16)(pIter - pCell);
53249
+ }
53250
+ nSize = *pIter;
53251
+ if( nSize>=0x80 ){
53252
+ pEnd = &pIter[9];
53253
+ nSize &= 0x7f;
53254
+ do{
53255
+ nSize = (nSize<<7) | (*++pIter & 0x7f);
53256
+ }while( *(pIter)>=0x80 && pIter<pEnd );
53257
+ }
53258
+ pIter++;
5314053259
if( pPage->intKey ){
53141
- u8 *pEnd;
53142
- if( pPage->hasData ){
53143
- pIter += getVarint32(pIter, nSize);
53144
- }else{
53145
- nSize = 0;
53146
- }
53147
-
5314853260
/* pIter now points at the 64-bit integer key value, a variable length
5314953261
** integer. The following block moves pIter to point at the first byte
5315053262
** past the end of the key value. */
5315153263
pEnd = &pIter[9];
5315253264
while( (*pIter++)&0x80 && pIter<pEnd );
53153
- }else{
53154
- pIter += getVarint32(pIter, nSize);
5315553265
}
53156
-
5315753266
testcase( nSize==pPage->maxLocal );
5315853267
testcase( nSize==pPage->maxLocal+1 );
53159
- if( nSize>pPage->maxLocal ){
53268
+ if( nSize<=pPage->maxLocal ){
53269
+ nSize += (u32)(pIter - pCell);
53270
+ if( nSize<4 ) nSize = 4;
53271
+ }else{
5316053272
int minLocal = pPage->minLocal;
5316153273
nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
5316253274
testcase( nSize==pPage->maxLocal );
5316353275
testcase( nSize==pPage->maxLocal+1 );
5316453276
if( nSize>pPage->maxLocal ){
5316553277
nSize = minLocal;
5316653278
}
53167
- nSize += 4;
53168
- }
53169
- nSize += (u32)(pIter - pCell);
53170
-
53171
- /* The minimum size of any cell is 4 bytes. */
53172
- if( nSize<4 ){
53173
- nSize = 4;
53174
- }
53175
-
53176
- assert( nSize==debuginfo.nSize );
53279
+ nSize += 4 + (u16)(pIter - pCell);
53280
+ }
53281
+ assert( nSize==debuginfo.nSize || CORRUPT_DB );
5317753282
return (u16)nSize;
5317853283
}
5317953284
5318053285
#ifdef SQLITE_DEBUG
5318153286
/* This variation on cellSizePtr() is used inside of assert() statements
@@ -53194,11 +53299,10 @@
5319453299
static void ptrmapPutOvflPtr(MemPage *pPage, u8 *pCell, int *pRC){
5319553300
CellInfo info;
5319653301
if( *pRC ) return;
5319753302
assert( pCell!=0 );
5319853303
btreeParseCellPtr(pPage, pCell, &info);
53199
- assert( (info.nData+(pPage->intKey?0:info.nKey))==info.nPayload );
5320053304
if( info.iOverflow ){
5320153305
Pgno ovfl = get4byte(&pCell[info.iOverflow]);
5320253306
ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC);
5320353307
}
5320453308
}
@@ -53407,11 +53511,11 @@
5340753511
** does it detect cells or freeblocks that encrouch into the reserved bytes
5340853512
** at the end of the page. So do additional corruption checks inside this
5340953513
** routine and return SQLITE_CORRUPT if any problems are found.
5341053514
*/
5341153515
static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
53412
- u16 iPtr; /* Address of pointer to next freeblock */
53516
+ u16 iPtr; /* Address of ptr to next freeblock */
5341353517
u16 iFreeBlk; /* Address of the next freeblock */
5341453518
u8 hdr; /* Page header size. 0 or 100 */
5341553519
u8 nFrag = 0; /* Reduction in fragmentation */
5341653520
u16 iOrigSize = iSize; /* Original value of iSize */
5341753521
u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */
@@ -53459,13 +53563,13 @@
5345953563
iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
5346053564
iSize = iEnd - iStart;
5346153565
iFreeBlk = get2byte(&data[iFreeBlk]);
5346253566
}
5346353567
53464
- /* If iPtr is another freeblock (that is, if iPtr is not the freelist pointer
53465
- ** in the page header) then check to see if iStart should be coalesced
53466
- ** onto the end of iPtr.
53568
+ /* If iPtr is another freeblock (that is, if iPtr is not the freelist
53569
+ ** pointer in the page header) then check to see if iStart should be
53570
+ ** coalesced onto the end of iPtr.
5346753571
*/
5346853572
if( iPtr>hdr+1 ){
5346953573
int iPtrEnd = iPtr + get2byte(&data[iPtr+2]);
5347053574
if( iPtrEnd+3>=iStart ){
5347153575
if( iPtrEnd>iStart ) return SQLITE_CORRUPT_BKPT;
@@ -53515,16 +53619,18 @@
5351553619
flagByte &= ~PTF_LEAF;
5351653620
pPage->childPtrSize = 4-4*pPage->leaf;
5351753621
pBt = pPage->pBt;
5351853622
if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
5351953623
pPage->intKey = 1;
53520
- pPage->hasData = pPage->leaf;
53624
+ pPage->intKeyLeaf = pPage->leaf;
53625
+ pPage->noPayload = !pPage->leaf;
5352153626
pPage->maxLocal = pBt->maxLeaf;
5352253627
pPage->minLocal = pBt->minLeaf;
5352353628
}else if( flagByte==PTF_ZERODATA ){
5352453629
pPage->intKey = 0;
53525
- pPage->hasData = 0;
53630
+ pPage->intKeyLeaf = 0;
53631
+ pPage->noPayload = 0;
5352653632
pPage->maxLocal = pBt->maxLocal;
5352753633
pPage->minLocal = pBt->minLocal;
5352853634
}else{
5352953635
return SQLITE_CORRUPT_BKPT;
5353053636
}
@@ -54175,11 +54281,12 @@
5417554281
#endif
5417654282
}
5417754283
5417854284
/*
5417954285
** Make sure pBt->pTmpSpace points to an allocation of
54180
-** MX_CELL_SIZE(pBt) bytes.
54286
+** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child
54287
+** pointer.
5418154288
*/
5418254289
static void allocateTempSpace(BtShared *pBt){
5418354290
if( !pBt->pTmpSpace ){
5418454291
pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
5418554292
@@ -54190,21 +54297,32 @@
5419054297
** can mean that fillInCell() only initializes the first 2 or 3
5419154298
** bytes of pTmpSpace, but that the first 4 bytes are copied from
5419254299
** it into a database page. This is not actually a problem, but it
5419354300
** does cause a valgrind error when the 1 or 2 bytes of unitialized
5419454301
** data is passed to system call write(). So to avoid this error,
54195
- ** zero the first 4 bytes of temp space here. */
54196
- if( pBt->pTmpSpace ) memset(pBt->pTmpSpace, 0, 4);
54302
+ ** zero the first 4 bytes of temp space here.
54303
+ **
54304
+ ** Also: Provide four bytes of initialized space before the
54305
+ ** beginning of pTmpSpace as an area available to prepend the
54306
+ ** left-child pointer to the beginning of a cell.
54307
+ */
54308
+ if( pBt->pTmpSpace ){
54309
+ memset(pBt->pTmpSpace, 0, 8);
54310
+ pBt->pTmpSpace += 4;
54311
+ }
5419754312
}
5419854313
}
5419954314
5420054315
/*
5420154316
** Free the pBt->pTmpSpace allocation
5420254317
*/
5420354318
static void freeTempSpace(BtShared *pBt){
54204
- sqlite3PageFree( pBt->pTmpSpace);
54205
- pBt->pTmpSpace = 0;
54319
+ if( pBt->pTmpSpace ){
54320
+ pBt->pTmpSpace -= 4;
54321
+ sqlite3PageFree(pBt->pTmpSpace);
54322
+ pBt->pTmpSpace = 0;
54323
+ }
5420654324
}
5420754325
5420854326
/*
5420954327
** Close an open database and invalidate all cursors.
5421054328
*/
@@ -54694,15 +54812,15 @@
5469454812
*/
5469554813
static void unlockBtreeIfUnused(BtShared *pBt){
5469654814
assert( sqlite3_mutex_held(pBt->mutex) );
5469754815
assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE );
5469854816
if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
54699
- assert( pBt->pPage1->aData );
54817
+ MemPage *pPage1 = pBt->pPage1;
54818
+ assert( pPage1->aData );
5470054819
assert( sqlite3PagerRefcount(pBt->pPager)==1 );
54701
- assert( pBt->pPage1->aData );
54702
- releasePage(pBt->pPage1);
5470354820
pBt->pPage1 = 0;
54821
+ releasePage(pPage1);
5470454822
}
5470554823
}
5470654824
5470754825
/*
5470854826
** If pBt points to an empty file then convert that empty file
@@ -55739,10 +55857,14 @@
5573955857
assert( pBt->pPage1 && pBt->pPage1->aData );
5574055858
5574155859
if( NEVER(wrFlag && (pBt->btsFlags & BTS_READ_ONLY)!=0) ){
5574255860
return SQLITE_READONLY;
5574355861
}
55862
+ if( wrFlag ){
55863
+ allocateTempSpace(pBt);
55864
+ if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM;
55865
+ }
5574455866
if( iTable==1 && btreePagecount(pBt)==0 ){
5574555867
assert( wrFlag==0 );
5574655868
iTable = 0;
5574755869
}
5574855870
@@ -55928,12 +56050,13 @@
5592856050
** to return an integer result code for historical reasons.
5592956051
*/
5593056052
SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
5593156053
assert( cursorHoldsMutex(pCur) );
5593256054
assert( pCur->eState==CURSOR_VALID );
56055
+ assert( pCur->apPage[pCur->iPage]->intKeyLeaf==1 );
5593356056
getCellInfo(pCur);
55934
- *pSize = pCur->info.nData;
56057
+ *pSize = pCur->info.nPayload;
5593556058
return SQLITE_OK;
5593656059
}
5593756060
5593856061
/*
5593956062
** Given the page number of an overflow page in the database (parameter
@@ -56080,34 +56203,32 @@
5608056203
unsigned char *pBuf, /* Write the bytes into this buffer */
5608156204
int eOp /* zero to read. non-zero to write. */
5608256205
){
5608356206
unsigned char *aPayload;
5608456207
int rc = SQLITE_OK;
56085
- u32 nKey;
5608656208
int iIdx = 0;
5608756209
MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
5608856210
BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
5608956211
#ifdef SQLITE_DIRECT_OVERFLOW_READ
56090
- int bEnd; /* True if reading to end of data */
56212
+ unsigned char * const pBufStart = pBuf;
56213
+ int bEnd; /* True if reading to end of data */
5609156214
#endif
5609256215
5609356216
assert( pPage );
5609456217
assert( pCur->eState==CURSOR_VALID );
5609556218
assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
5609656219
assert( cursorHoldsMutex(pCur) );
56097
- assert( eOp!=2 || offset==0 ); /* Always start from beginning for eOp==2 */
56220
+ assert( eOp!=2 || offset==0 ); /* Always start from beginning for eOp==2 */
5609856221
5609956222
getCellInfo(pCur);
56100
- aPayload = pCur->info.pCell + pCur->info.nHeader;
56101
- nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey);
56223
+ aPayload = pCur->info.pPayload;
5610256224
#ifdef SQLITE_DIRECT_OVERFLOW_READ
56103
- bEnd = (offset+amt==nKey+pCur->info.nData);
56225
+ bEnd = offset+amt==pCur->info.nPayload;
5610456226
#endif
56227
+ assert( offset+amt <= pCur->info.nPayload );
5610556228
56106
- if( NEVER(offset+amt > nKey+pCur->info.nData)
56107
- || &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
56108
- ){
56229
+ if( &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ){
5610956230
/* Trying to read or write past the end of the data is an error */
5611056231
return SQLITE_CORRUPT_BKPT;
5611156232
}
5611256233
5611356234
/* Check if data must be read/written to/from the btree page itself. */
@@ -56159,11 +56280,13 @@
5615956280
5616056281
/* If the overflow page-list cache has been allocated and the
5616156282
** entry for the first required overflow page is valid, skip
5616256283
** directly to it.
5616356284
*/
56164
- if( (pCur->curFlags & BTCF_ValidOvfl)!=0 && pCur->aOverflow[offset/ovflSize] ){
56285
+ if( (pCur->curFlags & BTCF_ValidOvfl)!=0
56286
+ && pCur->aOverflow[offset/ovflSize]
56287
+ ){
5616556288
iIdx = (offset/ovflSize);
5616656289
nextPage = pCur->aOverflow[iIdx];
5616756290
offset = (offset%ovflSize);
5616856291
}
5616956292
@@ -56212,10 +56335,11 @@
5621256335
** 2) data is required from the start of this overflow page, and
5621356336
** 3) the database is file-backed, and
5621456337
** 4) there is no open write-transaction, and
5621556338
** 5) the database is not a WAL database,
5621656339
** 6) all data from the page is being read.
56340
+ ** 7) at least 4 bytes have already been read into the output buffer
5621756341
**
5621856342
** then data can be read directly from the database file into the
5621956343
** output buffer, bypassing the page-cache altogether. This speeds
5622056344
** up loading large records that span many overflow pages.
5622156345
*/
@@ -56223,13 +56347,15 @@
5622356347
&& offset==0 /* (2) */
5622456348
&& (bEnd || a==ovflSize) /* (6) */
5622556349
&& pBt->inTransaction==TRANS_READ /* (4) */
5622656350
&& (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */
5622756351
&& pBt->pPage1->aData[19]==0x01 /* (5) */
56352
+ && &pBuf[-4]>=pBufStart /* (7) */
5622856353
){
5622956354
u8 aSave[4];
5623056355
u8 *aWrite = &pBuf[-4];
56356
+ assert( aWrite>=pBufStart ); /* hence (7) */
5623156357
memcpy(aSave, aWrite, 4);
5623256358
rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
5623356359
nextPage = get4byte(aWrite);
5623456360
memcpy(aWrite, aSave, 4);
5623556361
}else
@@ -56337,11 +56463,11 @@
5633756463
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5633856464
assert( cursorHoldsMutex(pCur) );
5633956465
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
5634056466
assert( pCur->info.nSize>0 );
5634156467
*pAmt = pCur->info.nLocal;
56342
- return (void*)(pCur->info.pCell + pCur->info.nHeader);
56468
+ return (void*)pCur->info.pPayload;
5634356469
}
5634456470
5634556471
5634656472
/*
5634756473
** For the entry that cursor pCur is point to, return as
@@ -56765,11 +56891,11 @@
5676556891
pCur->aiIdx[pCur->iPage] = (u16)idx;
5676656892
if( xRecordCompare==0 ){
5676756893
for(;;){
5676856894
i64 nCellKey;
5676956895
pCell = findCell(pPage, idx) + pPage->childPtrSize;
56770
- if( pPage->hasData ){
56896
+ if( pPage->intKeyLeaf ){
5677156897
while( 0x80 <= *(pCell++) ){
5677256898
if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
5677356899
}
5677456900
}
5677556901
getVarint(pCell, (u64*)&nCellKey);
@@ -57024,13 +57150,13 @@
5702457150
** was already pointing to the first entry in the database before
5702557151
** this routine was called, then set *pRes=1.
5702657152
**
5702757153
** The main entry point is sqlite3BtreePrevious(). That routine is optimized
5702857154
** for the common case of merely decrementing the cell counter BtCursor.aiIdx
57029
-** to the previous cell on the current page. The (slower) btreePrevious() helper
57030
-** routine is called when it is necessary to move to a different page or
57031
-** to restore the cursor.
57155
+** to the previous cell on the current page. The (slower) btreePrevious()
57156
+** helper routine is called when it is necessary to move to a different page
57157
+** or to restore the cursor.
5703257158
**
5703357159
** The calling function will set *pRes to 0 or 1. The initial *pRes value
5703457160
** will be 1 if the cursor being stepped corresponds to an SQL index and
5703557161
** if this routine could have been skipped if that SQL index had been
5703657162
** a unique index. Otherwise the caller will have set *pRes to zero.
@@ -57048,12 +57174,11 @@
5704857174
assert( *pRes==0 );
5704957175
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
5705057176
assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
5705157177
assert( pCur->info.nSize==0 );
5705257178
if( pCur->eState!=CURSOR_VALID ){
57053
- assert( pCur->eState>=CURSOR_REQUIRESEEK );
57054
- rc = btreeRestoreCursorPosition(pCur);
57179
+ rc = restoreCursorPosition(pCur);
5705557180
if( rc!=SQLITE_OK ){
5705657181
return rc;
5705757182
}
5705857183
if( CURSOR_INVALID==pCur->eState ){
5705957184
*pRes = 1;
@@ -57354,11 +57479,11 @@
5735457479
if( rc ) goto end_allocate_page;
5735557480
if( closest<k-1 ){
5735657481
memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
5735757482
}
5735857483
put4byte(&aData[4], k-1);
57359
- noContent = !btreeGetHasContent(pBt, *pPgno) ? PAGER_GET_NOCONTENT : 0;
57484
+ noContent = !btreeGetHasContent(pBt, *pPgno)? PAGER_GET_NOCONTENT : 0;
5736057485
rc = btreeGetPage(pBt, *pPgno, ppPage, noContent);
5736157486
if( rc==SQLITE_OK ){
5736257487
rc = sqlite3PagerWrite((*ppPage)->pDbPage);
5736357488
if( rc!=SQLITE_OK ){
5736457489
releasePage(*ppPage);
@@ -57387,11 +57512,11 @@
5738757512
** content for any page that really does lie past the end of the database
5738857513
** file on disk. So the effects of disabling the no-content optimization
5738957514
** here are confined to those pages that lie between the end of the
5739057515
** database image and the end of the database file.
5739157516
*/
57392
- int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)) ? PAGER_GET_NOCONTENT : 0;
57517
+ int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate))? PAGER_GET_NOCONTENT:0;
5739357518
5739457519
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
5739557520
if( rc ) return rc;
5739657521
pBt->nPage++;
5739757522
if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
@@ -57586,22 +57711,29 @@
5758657711
*pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
5758757712
}
5758857713
}
5758957714
5759057715
/*
57591
-** Free any overflow pages associated with the given Cell.
57716
+** Free any overflow pages associated with the given Cell. Write the
57717
+** local Cell size (the number of bytes on the original page, omitting
57718
+** overflow) into *pnSize.
5759257719
*/
57593
-static int clearCell(MemPage *pPage, unsigned char *pCell){
57720
+static int clearCell(
57721
+ MemPage *pPage, /* The page that contains the Cell */
57722
+ unsigned char *pCell, /* First byte of the Cell */
57723
+ u16 *pnSize /* Write the size of the Cell here */
57724
+){
5759457725
BtShared *pBt = pPage->pBt;
5759557726
CellInfo info;
5759657727
Pgno ovflPgno;
5759757728
int rc;
5759857729
int nOvfl;
5759957730
u32 ovflPageSize;
5760057731
5760157732
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5760257733
btreeParseCellPtr(pPage, pCell, &info);
57734
+ *pnSize = info.nSize;
5760357735
if( info.iOverflow==0 ){
5760457736
return SQLITE_OK; /* No overflow pages. Return without doing anything */
5760557737
}
5760657738
if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){
5760757739
return SQLITE_CORRUPT_BKPT; /* Cell extends past end of page */
@@ -57681,54 +57813,87 @@
5768157813
unsigned char *pPrior;
5768257814
unsigned char *pPayload;
5768357815
BtShared *pBt = pPage->pBt;
5768457816
Pgno pgnoOvfl = 0;
5768557817
int nHeader;
57686
- CellInfo info;
5768757818
5768857819
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5768957820
5769057821
/* pPage is not necessarily writeable since pCell might be auxiliary
5769157822
** buffer space that is separate from the pPage buffer area */
5769257823
assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
5769357824
|| sqlite3PagerIswriteable(pPage->pDbPage) );
5769457825
5769557826
/* Fill in the header. */
57696
- nHeader = 0;
57697
- if( !pPage->leaf ){
57698
- nHeader += 4;
57699
- }
57700
- if( pPage->hasData ){
57701
- nHeader += putVarint32(&pCell[nHeader], nData+nZero);
57827
+ nHeader = pPage->childPtrSize;
57828
+ nPayload = nData + nZero;
57829
+ if( pPage->intKeyLeaf ){
57830
+ nHeader += putVarint32(&pCell[nHeader], nPayload);
5770257831
}else{
57703
- nData = nZero = 0;
57832
+ assert( nData==0 );
57833
+ assert( nZero==0 );
5770457834
}
5770557835
nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
57706
- btreeParseCellPtr(pPage, pCell, &info);
57707
- assert( info.nHeader==nHeader );
57708
- assert( info.nKey==nKey );
57709
- assert( info.nData==(u32)(nData+nZero) );
5771057836
57711
- /* Fill in the payload */
57712
- nPayload = nData + nZero;
57837
+ /* Fill in the payload size */
5771357838
if( pPage->intKey ){
5771457839
pSrc = pData;
5771557840
nSrc = nData;
5771657841
nData = 0;
5771757842
}else{
5771857843
if( NEVER(nKey>0x7fffffff || pKey==0) ){
5771957844
return SQLITE_CORRUPT_BKPT;
5772057845
}
57721
- nPayload += (int)nKey;
57846
+ nPayload = (int)nKey;
5772257847
pSrc = pKey;
5772357848
nSrc = (int)nKey;
5772457849
}
57725
- *pnSize = info.nSize;
57726
- spaceLeft = info.nLocal;
57850
+ if( nPayload<=pPage->maxLocal ){
57851
+ n = nHeader + nPayload;
57852
+ testcase( n==3 );
57853
+ testcase( n==4 );
57854
+ if( n<4 ) n = 4;
57855
+ *pnSize = n;
57856
+ spaceLeft = nPayload;
57857
+ pPrior = pCell;
57858
+ }else{
57859
+ int mn = pPage->minLocal;
57860
+ n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
57861
+ testcase( n==pPage->maxLocal );
57862
+ testcase( n==pPage->maxLocal+1 );
57863
+ if( n > pPage->maxLocal ) n = mn;
57864
+ spaceLeft = n;
57865
+ *pnSize = n + nHeader + 4;
57866
+ pPrior = &pCell[nHeader+n];
57867
+ }
5772757868
pPayload = &pCell[nHeader];
57728
- pPrior = &pCell[info.iOverflow];
5772957869
57870
+ /* At this point variables should be set as follows:
57871
+ **
57872
+ ** nPayload Total payload size in bytes
57873
+ ** pPayload Begin writing payload here
57874
+ ** spaceLeft Space available at pPayload. If nPayload>spaceLeft,
57875
+ ** that means content must spill into overflow pages.
57876
+ ** *pnSize Size of the local cell (not counting overflow pages)
57877
+ ** pPrior Where to write the pgno of the first overflow page
57878
+ **
57879
+ ** Use a call to btreeParseCellPtr() to verify that the values above
57880
+ ** were computed correctly.
57881
+ */
57882
+#if SQLITE_DEBUG
57883
+ {
57884
+ CellInfo info;
57885
+ btreeParseCellPtr(pPage, pCell, &info);
57886
+ assert( nHeader=(int)(info.pPayload - pCell) );
57887
+ assert( info.nKey==nKey );
57888
+ assert( *pnSize == info.nSize );
57889
+ assert( spaceLeft == info.nLocal );
57890
+ assert( pPrior == &pCell[info.iOverflow] );
57891
+ }
57892
+#endif
57893
+
57894
+ /* Write the payload into the local Cell and any extra into overflow pages */
5773057895
while( nPayload>0 ){
5773157896
if( spaceLeft==0 ){
5773257897
#ifndef SQLITE_OMIT_AUTOVACUUM
5773357898
Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
5773457899
if( pBt->autoVacuum ){
@@ -57865,15 +58030,10 @@
5786558030
** pTemp is not null. Regardless of pTemp, allocate a new entry
5786658031
** in pPage->apOvfl[] and make it point to the cell content (either
5786758032
** in pTemp or the original pCell) and also record its index.
5786858033
** Allocating a new entry in pPage->aCell[] implies that
5786958034
** pPage->nOverflow is incremented.
57870
-**
57871
-** If nSkip is non-zero, then do not copy the first nSkip bytes of the
57872
-** cell. The caller will overwrite them after this function returns. If
57873
-** nSkip is non-zero, then pCell may not point to an invalid memory location
57874
-** (but pCell+nSkip is always valid).
5787558035
*/
5787658036
static void insertCell(
5787758037
MemPage *pPage, /* Page into which we are copying */
5787858038
int i, /* New cell becomes the i-th cell of the page */
5787958039
u8 *pCell, /* Content of the new cell */
@@ -57886,11 +58046,10 @@
5788658046
int j; /* Loop counter */
5788758047
int end; /* First byte past the last cell pointer in data[] */
5788858048
int ins; /* Index in data[] where new cell pointer is inserted */
5788958049
int cellOffset; /* Address of first cell pointer in data[] */
5789058050
u8 *data; /* The content of the whole page */
57891
- int nSkip = (iChild ? 4 : 0);
5789258051
5789358052
if( *pRC ) return;
5789458053
5789558054
assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
5789658055
assert( MX_CELL(pPage->pBt)<=10921 );
@@ -57904,11 +58063,11 @@
5790458063
** might be less than 8 (leaf-size + pointer) on the interior node. Hence
5790558064
** the term after the || in the following assert(). */
5790658065
assert( sz==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
5790758066
if( pPage->nOverflow || sz+2>pPage->nFree ){
5790858067
if( pTemp ){
57909
- memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
58068
+ memcpy(pTemp, pCell, sz);
5791058069
pCell = pTemp;
5791158070
}
5791258071
if( iChild ){
5791358072
put4byte(pCell, iChild);
5791458073
}
@@ -57933,11 +58092,11 @@
5793358092
** if it returns success */
5793458093
assert( idx >= end+2 );
5793558094
assert( idx+sz <= (int)pPage->pBt->usableSize );
5793658095
pPage->nCell++;
5793758096
pPage->nFree -= (u16)(2 + sz);
57938
- memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
58097
+ memcpy(&data[idx], pCell, sz);
5793958098
if( iChild ){
5794058099
put4byte(&data[idx], iChild);
5794158100
}
5794258101
memmove(&data[ins+2], &data[ins], end-ins);
5794358102
put2byte(&data[ins], idx);
@@ -58432,11 +58591,11 @@
5843258591
**
5843358592
** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
5843458593
** leafData: 1 if pPage holds key+data and pParent holds only keys.
5843558594
*/
5843658595
leafCorrection = apOld[0]->leaf*4;
58437
- leafData = apOld[0]->hasData;
58596
+ leafData = apOld[0]->intKeyLeaf;
5843858597
for(i=0; i<nOld; i++){
5843958598
int limit;
5844058599
5844158600
/* Before doing anything else, take a copy of the i'th original sibling
5844258601
** The rest of this function will use data from the copies rather
@@ -59008,11 +59167,11 @@
5900859167
int const iIdx = pCur->aiIdx[iPage-1];
5900959168
5901059169
rc = sqlite3PagerWrite(pParent->pDbPage);
5901159170
if( rc==SQLITE_OK ){
5901259171
#ifndef SQLITE_OMIT_QUICKBALANCE
59013
- if( pPage->hasData
59172
+ if( pPage->intKeyLeaf
5901459173
&& pPage->nOverflow==1
5901559174
&& pPage->aiOvfl[0]==pPage->nCell
5901659175
&& pParent->pgno!=1
5901759176
&& pParent->nCell==iIdx
5901859177
){
@@ -59127,11 +59286,12 @@
5912759286
assert( pCur->skipNext!=SQLITE_OK );
5912859287
return pCur->skipNext;
5912959288
}
5913059289
5913159290
assert( cursorHoldsMutex(pCur) );
59132
- assert( (pCur->curFlags & BTCF_WriteFlag)!=0 && pBt->inTransaction==TRANS_WRITE
59291
+ assert( (pCur->curFlags & BTCF_WriteFlag)!=0
59292
+ && pBt->inTransaction==TRANS_WRITE
5913359293
&& (pBt->btsFlags & BTS_READ_ONLY)==0 );
5913459294
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
5913559295
5913659296
/* Assert that the caller has been consistent. If this cursor was opened
5913759297
** expecting an index b-tree, then the caller should be inserting blob
@@ -59160,11 +59320,12 @@
5916059320
invalidateIncrblobCursors(p, nKey, 0);
5916159321
5916259322
/* If the cursor is currently on the last row and we are appending a
5916359323
** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto()
5916459324
** call */
59165
- if( (pCur->curFlags&BTCF_ValidNKey)!=0 && nKey>0 && pCur->info.nKey==nKey-1 ){
59325
+ if( (pCur->curFlags&BTCF_ValidNKey)!=0 && nKey>0
59326
+ && pCur->info.nKey==nKey-1 ){
5916659327
loc = -1;
5916759328
}
5916859329
}
5916959330
5917059331
if( !loc ){
@@ -59179,13 +59340,12 @@
5917959340
5918059341
TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
5918159342
pCur->pgnoRoot, nKey, nData, pPage->pgno,
5918259343
loc==0 ? "overwrite" : "new entry"));
5918359344
assert( pPage->isInit );
59184
- allocateTempSpace(pBt);
5918559345
newCell = pBt->pTmpSpace;
59186
- if( newCell==0 ) return SQLITE_NOMEM;
59346
+ assert( newCell!=0 );
5918759347
rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
5918859348
if( rc ) goto end_insert;
5918959349
assert( szNew==cellSizePtr(pPage, newCell) );
5919059350
assert( szNew <= MX_CELL_SIZE(pBt) );
5919159351
idx = pCur->aiIdx[pCur->iPage];
@@ -59198,12 +59358,11 @@
5919859358
}
5919959359
oldCell = findCell(pPage, idx);
5920059360
if( !pPage->leaf ){
5920159361
memcpy(newCell, oldCell, 4);
5920259362
}
59203
- szOld = cellSizePtr(pPage, oldCell);
59204
- rc = clearCell(pPage, oldCell);
59363
+ rc = clearCell(pPage, oldCell, &szOld);
5920559364
dropCell(pPage, idx, szOld, &rc);
5920659365
if( rc ) goto end_insert;
5920759366
}else if( loc<0 && pPage->nCell>0 ){
5920859367
assert( pPage->leaf );
5920959368
idx = ++pCur->aiIdx[pCur->iPage];
@@ -59261,10 +59420,11 @@
5926159420
int rc; /* Return code */
5926259421
MemPage *pPage; /* Page to delete cell from */
5926359422
unsigned char *pCell; /* Pointer to cell to delete */
5926459423
int iCellIdx; /* Index of cell to delete */
5926559424
int iCellDepth; /* Depth of node containing pCell */
59425
+ u16 szCell; /* Size of the cell being deleted */
5926659426
5926759427
assert( cursorHoldsMutex(pCur) );
5926859428
assert( pBt->inTransaction==TRANS_WRITE );
5926959429
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
5927059430
assert( pCur->curFlags & BTCF_WriteFlag );
@@ -59309,12 +59469,12 @@
5930959469
invalidateIncrblobCursors(p, pCur->info.nKey, 0);
5931059470
}
5931159471
5931259472
rc = sqlite3PagerWrite(pPage->pDbPage);
5931359473
if( rc ) return rc;
59314
- rc = clearCell(pPage, pCell);
59315
- dropCell(pPage, iCellIdx, cellSizePtr(pPage, pCell), &rc);
59474
+ rc = clearCell(pPage, pCell, &szCell);
59475
+ dropCell(pPage, iCellIdx, szCell, &rc);
5931659476
if( rc ) return rc;
5931759477
5931859478
/* If the cell deleted was not located on a leaf page, then the cursor
5931959479
** is currently pointing to the largest entry in the sub-tree headed
5932059480
** by the child-page of the cell that was just deleted from an internal
@@ -59327,14 +59487,12 @@
5932759487
unsigned char *pTmp;
5932859488
5932959489
pCell = findCell(pLeaf, pLeaf->nCell-1);
5933059490
nCell = cellSizePtr(pLeaf, pCell);
5933159491
assert( MX_CELL_SIZE(pBt) >= nCell );
59332
-
59333
- allocateTempSpace(pBt);
5933459492
pTmp = pBt->pTmpSpace;
59335
-
59493
+ assert( pTmp!=0 );
5933659494
rc = sqlite3PagerWrite(pLeaf->pDbPage);
5933759495
insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n, &rc);
5933859496
dropCell(pLeaf, pLeaf->nCell-1, nCell, &rc);
5933959497
if( rc ) return rc;
5934059498
}
@@ -59542,10 +59700,11 @@
5954259700
MemPage *pPage;
5954359701
int rc;
5954459702
unsigned char *pCell;
5954559703
int i;
5954659704
int hdr;
59705
+ u16 szCell;
5954759706
5954859707
assert( sqlite3_mutex_held(pBt->mutex) );
5954959708
if( pgno>btreePagecount(pBt) ){
5955059709
return SQLITE_CORRUPT_BKPT;
5955159710
}
@@ -59557,11 +59716,11 @@
5955759716
pCell = findCell(pPage, i);
5955859717
if( !pPage->leaf ){
5955959718
rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
5956059719
if( rc ) goto cleardatabasepage_out;
5956159720
}
59562
- rc = clearCell(pPage, pCell);
59721
+ rc = clearCell(pPage, pCell, &szCell);
5956359722
if( rc ) goto cleardatabasepage_out;
5956459723
}
5956559724
if( !pPage->leaf ){
5956659725
rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
5956759726
if( rc ) goto cleardatabasepage_out;
@@ -59903,24 +60062,25 @@
5990360062
/*
5990460063
** Append a message to the error message string.
5990560064
*/
5990660065
static void checkAppendMsg(
5990760066
IntegrityCk *pCheck,
59908
- char *zMsg1,
5990960067
const char *zFormat,
5991060068
...
5991160069
){
5991260070
va_list ap;
60071
+ char zBuf[200];
5991360072
if( !pCheck->mxErr ) return;
5991460073
pCheck->mxErr--;
5991560074
pCheck->nErr++;
5991660075
va_start(ap, zFormat);
5991760076
if( pCheck->errMsg.nChar ){
5991860077
sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
5991960078
}
59920
- if( zMsg1 ){
59921
- sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1);
60079
+ if( pCheck->zPfx ){
60080
+ sqlite3_snprintf(sizeof(zBuf), zBuf, pCheck->zPfx, pCheck->v1, pCheck->v2);
60081
+ sqlite3StrAccumAppendAll(&pCheck->errMsg, zBuf);
5992260082
}
5992360083
sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
5992460084
va_end(ap);
5992560085
if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
5992660086
pCheck->mallocFailed = 1;
@@ -59954,18 +60114,18 @@
5995460114
** Return 1 if there are 2 or more references to the page and 0 if
5995560115
** if this is the first reference to the page.
5995660116
**
5995760117
** Also check that the page number is in bounds.
5995860118
*/
59959
-static int checkRef(IntegrityCk *pCheck, Pgno iPage, char *zContext){
60119
+static int checkRef(IntegrityCk *pCheck, Pgno iPage){
5996060120
if( iPage==0 ) return 1;
5996160121
if( iPage>pCheck->nPage ){
59962
- checkAppendMsg(pCheck, zContext, "invalid page number %d", iPage);
60122
+ checkAppendMsg(pCheck, "invalid page number %d", iPage);
5996360123
return 1;
5996460124
}
5996560125
if( getPageReferenced(pCheck, iPage) ){
59966
- checkAppendMsg(pCheck, zContext, "2nd reference to page %d", iPage);
60126
+ checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
5996760127
return 1;
5996860128
}
5996960129
setPageReferenced(pCheck, iPage);
5997060130
return 0;
5997160131
}
@@ -59978,26 +60138,25 @@
5997860138
*/
5997960139
static void checkPtrmap(
5998060140
IntegrityCk *pCheck, /* Integrity check context */
5998160141
Pgno iChild, /* Child page number */
5998260142
u8 eType, /* Expected pointer map type */
59983
- Pgno iParent, /* Expected pointer map parent page number */
59984
- char *zContext /* Context description (used for error msg) */
60143
+ Pgno iParent /* Expected pointer map parent page number */
5998560144
){
5998660145
int rc;
5998760146
u8 ePtrmapType;
5998860147
Pgno iPtrmapParent;
5998960148
5999060149
rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
5999160150
if( rc!=SQLITE_OK ){
5999260151
if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->mallocFailed = 1;
59993
- checkAppendMsg(pCheck, zContext, "Failed to read ptrmap key=%d", iChild);
60152
+ checkAppendMsg(pCheck, "Failed to read ptrmap key=%d", iChild);
5999460153
return;
5999560154
}
5999660155
5999760156
if( ePtrmapType!=eType || iPtrmapParent!=iParent ){
59998
- checkAppendMsg(pCheck, zContext,
60157
+ checkAppendMsg(pCheck,
5999960158
"Bad ptr map entry key=%d expected=(%d,%d) got=(%d,%d)",
6000060159
iChild, eType, iParent, ePtrmapType, iPtrmapParent);
6000160160
}
6000260161
}
6000360162
#endif
@@ -60008,51 +60167,50 @@
6000860167
*/
6000960168
static void checkList(
6001060169
IntegrityCk *pCheck, /* Integrity checking context */
6001160170
int isFreeList, /* True for a freelist. False for overflow page list */
6001260171
int iPage, /* Page number for first page in the list */
60013
- int N, /* Expected number of pages in the list */
60014
- char *zContext /* Context for error messages */
60172
+ int N /* Expected number of pages in the list */
6001560173
){
6001660174
int i;
6001760175
int expected = N;
6001860176
int iFirst = iPage;
6001960177
while( N-- > 0 && pCheck->mxErr ){
6002060178
DbPage *pOvflPage;
6002160179
unsigned char *pOvflData;
6002260180
if( iPage<1 ){
60023
- checkAppendMsg(pCheck, zContext,
60181
+ checkAppendMsg(pCheck,
6002460182
"%d of %d pages missing from overflow list starting at %d",
6002560183
N+1, expected, iFirst);
6002660184
break;
6002760185
}
60028
- if( checkRef(pCheck, iPage, zContext) ) break;
60186
+ if( checkRef(pCheck, iPage) ) break;
6002960187
if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage) ){
60030
- checkAppendMsg(pCheck, zContext, "failed to get page %d", iPage);
60188
+ checkAppendMsg(pCheck, "failed to get page %d", iPage);
6003160189
break;
6003260190
}
6003360191
pOvflData = (unsigned char *)sqlite3PagerGetData(pOvflPage);
6003460192
if( isFreeList ){
6003560193
int n = get4byte(&pOvflData[4]);
6003660194
#ifndef SQLITE_OMIT_AUTOVACUUM
6003760195
if( pCheck->pBt->autoVacuum ){
60038
- checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0, zContext);
60196
+ checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0);
6003960197
}
6004060198
#endif
6004160199
if( n>(int)pCheck->pBt->usableSize/4-2 ){
60042
- checkAppendMsg(pCheck, zContext,
60200
+ checkAppendMsg(pCheck,
6004360201
"freelist leaf count too big on page %d", iPage);
6004460202
N--;
6004560203
}else{
6004660204
for(i=0; i<n; i++){
6004760205
Pgno iFreePage = get4byte(&pOvflData[8+i*4]);
6004860206
#ifndef SQLITE_OMIT_AUTOVACUUM
6004960207
if( pCheck->pBt->autoVacuum ){
60050
- checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0, zContext);
60208
+ checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0);
6005160209
}
6005260210
#endif
60053
- checkRef(pCheck, iFreePage, zContext);
60211
+ checkRef(pCheck, iFreePage);
6005460212
}
6005560213
N -= n;
6005660214
}
6005760215
}
6005860216
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -60061,11 +60219,11 @@
6006160219
** page in this overflow list, check that the pointer-map entry for
6006260220
** the following page matches iPage.
6006360221
*/
6006460222
if( pCheck->pBt->autoVacuum && N>0 ){
6006560223
i = get4byte(pOvflData);
60066
- checkPtrmap(pCheck, i, PTRMAP_OVERFLOW2, iPage, zContext);
60224
+ checkPtrmap(pCheck, i, PTRMAP_OVERFLOW2, iPage);
6006760225
}
6006860226
}
6006960227
#endif
6007060228
iPage = get4byte(pOvflData);
6007160229
sqlite3PagerUnref(pOvflPage);
@@ -60093,11 +60251,10 @@
6009360251
** the root of the tree.
6009460252
*/
6009560253
static int checkTreePage(
6009660254
IntegrityCk *pCheck, /* Context for the sanity check */
6009760255
int iPage, /* Page number of the page to check */
60098
- char *zParentContext, /* Parent context */
6009960256
i64 *pnParentMinKey,
6010060257
i64 *pnParentMaxKey
6010160258
){
6010260259
MemPage *pPage;
6010360260
int i, rc, depth, d2, pgno, cnt;
@@ -60104,38 +60261,42 @@
6010460261
int hdr, cellStart;
6010560262
int nCell;
6010660263
u8 *data;
6010760264
BtShared *pBt;
6010860265
int usableSize;
60109
- char zContext[100];
6011060266
char *hit = 0;
6011160267
i64 nMinKey = 0;
6011260268
i64 nMaxKey = 0;
60113
-
60114
- sqlite3_snprintf(sizeof(zContext), zContext, "Page %d: ", iPage);
60269
+ const char *saved_zPfx = pCheck->zPfx;
60270
+ int saved_v1 = pCheck->v1;
60271
+ int saved_v2 = pCheck->v2;
6011560272
6011660273
/* Check that the page exists
6011760274
*/
6011860275
pBt = pCheck->pBt;
6011960276
usableSize = pBt->usableSize;
6012060277
if( iPage==0 ) return 0;
60121
- if( checkRef(pCheck, iPage, zParentContext) ) return 0;
60278
+ if( checkRef(pCheck, iPage) ) return 0;
60279
+ pCheck->zPfx = "Page %d: ";
60280
+ pCheck->v1 = iPage;
6012260281
if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
60123
- checkAppendMsg(pCheck, zContext,
60282
+ checkAppendMsg(pCheck,
6012460283
"unable to get the page. error code=%d", rc);
60125
- return 0;
60284
+ depth = -1;
60285
+ goto end_of_check;
6012660286
}
6012760287
6012860288
/* Clear MemPage.isInit to make sure the corruption detection code in
6012960289
** btreeInitPage() is executed. */
6013060290
pPage->isInit = 0;
6013160291
if( (rc = btreeInitPage(pPage))!=0 ){
6013260292
assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
60133
- checkAppendMsg(pCheck, zContext,
60293
+ checkAppendMsg(pCheck,
6013460294
"btreeInitPage() returns error code %d", rc);
6013560295
releasePage(pPage);
60136
- return 0;
60296
+ depth = -1;
60297
+ goto end_of_check;
6013760298
}
6013860299
6013960300
/* Check out all the cells.
6014060301
*/
6014160302
depth = 0;
@@ -60144,99 +60305,101 @@
6014460305
u32 sz;
6014560306
CellInfo info;
6014660307
6014760308
/* Check payload overflow pages
6014860309
*/
60149
- sqlite3_snprintf(sizeof(zContext), zContext,
60150
- "On tree page %d cell %d: ", iPage, i);
60310
+ pCheck->zPfx = "On tree page %d cell %d: ";
60311
+ pCheck->v1 = iPage;
60312
+ pCheck->v2 = i;
6015160313
pCell = findCell(pPage,i);
6015260314
btreeParseCellPtr(pPage, pCell, &info);
60153
- sz = info.nData;
60154
- if( !pPage->intKey ) sz += (int)info.nKey;
60315
+ sz = info.nPayload;
6015560316
/* For intKey pages, check that the keys are in order.
6015660317
*/
60157
- else if( i==0 ) nMinKey = nMaxKey = info.nKey;
60158
- else{
60159
- if( info.nKey <= nMaxKey ){
60160
- checkAppendMsg(pCheck, zContext,
60161
- "Rowid %lld out of order (previous was %lld)", info.nKey, nMaxKey);
60318
+ if( pPage->intKey ){
60319
+ if( i==0 ){
60320
+ nMinKey = nMaxKey = info.nKey;
60321
+ }else if( info.nKey <= nMaxKey ){
60322
+ checkAppendMsg(pCheck,
60323
+ "Rowid %lld out of order (previous was %lld)", info.nKey, nMaxKey);
6016260324
}
6016360325
nMaxKey = info.nKey;
6016460326
}
60165
- assert( sz==info.nPayload );
6016660327
if( (sz>info.nLocal)
6016760328
&& (&pCell[info.iOverflow]<=&pPage->aData[pBt->usableSize])
6016860329
){
6016960330
int nPage = (sz - info.nLocal + usableSize - 5)/(usableSize - 4);
6017060331
Pgno pgnoOvfl = get4byte(&pCell[info.iOverflow]);
6017160332
#ifndef SQLITE_OMIT_AUTOVACUUM
6017260333
if( pBt->autoVacuum ){
60173
- checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage, zContext);
60334
+ checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage);
6017460335
}
6017560336
#endif
60176
- checkList(pCheck, 0, pgnoOvfl, nPage, zContext);
60337
+ checkList(pCheck, 0, pgnoOvfl, nPage);
6017760338
}
6017860339
6017960340
/* Check sanity of left child page.
6018060341
*/
6018160342
if( !pPage->leaf ){
6018260343
pgno = get4byte(pCell);
6018360344
#ifndef SQLITE_OMIT_AUTOVACUUM
6018460345
if( pBt->autoVacuum ){
60185
- checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage, zContext);
60346
+ checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
6018660347
}
6018760348
#endif
60188
- d2 = checkTreePage(pCheck, pgno, zContext, &nMinKey, i==0 ? NULL : &nMaxKey);
60349
+ d2 = checkTreePage(pCheck, pgno, &nMinKey, i==0?NULL:&nMaxKey);
6018960350
if( i>0 && d2!=depth ){
60190
- checkAppendMsg(pCheck, zContext, "Child page depth differs");
60351
+ checkAppendMsg(pCheck, "Child page depth differs");
6019160352
}
6019260353
depth = d2;
6019360354
}
6019460355
}
6019560356
6019660357
if( !pPage->leaf ){
6019760358
pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
60198
- sqlite3_snprintf(sizeof(zContext), zContext,
60199
- "On page %d at right child: ", iPage);
60359
+ pCheck->zPfx = "On page %d at right child: ";
60360
+ pCheck->v1 = iPage;
6020060361
#ifndef SQLITE_OMIT_AUTOVACUUM
6020160362
if( pBt->autoVacuum ){
60202
- checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage, zContext);
60363
+ checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
6020360364
}
6020460365
#endif
60205
- checkTreePage(pCheck, pgno, zContext, NULL, !pPage->nCell ? NULL : &nMaxKey);
60366
+ checkTreePage(pCheck, pgno, NULL, !pPage->nCell?NULL:&nMaxKey);
6020660367
}
6020760368
6020860369
/* For intKey leaf pages, check that the min/max keys are in order
6020960370
** with any left/parent/right pages.
6021060371
*/
60372
+ pCheck->zPfx = "Page %d: ";
60373
+ pCheck->v1 = iPage;
6021160374
if( pPage->leaf && pPage->intKey ){
6021260375
/* if we are a left child page */
6021360376
if( pnParentMinKey ){
6021460377
/* if we are the left most child page */
6021560378
if( !pnParentMaxKey ){
6021660379
if( nMaxKey > *pnParentMinKey ){
60217
- checkAppendMsg(pCheck, zContext,
60380
+ checkAppendMsg(pCheck,
6021860381
"Rowid %lld out of order (max larger than parent min of %lld)",
6021960382
nMaxKey, *pnParentMinKey);
6022060383
}
6022160384
}else{
6022260385
if( nMinKey <= *pnParentMinKey ){
60223
- checkAppendMsg(pCheck, zContext,
60386
+ checkAppendMsg(pCheck,
6022460387
"Rowid %lld out of order (min less than parent min of %lld)",
6022560388
nMinKey, *pnParentMinKey);
6022660389
}
6022760390
if( nMaxKey > *pnParentMaxKey ){
60228
- checkAppendMsg(pCheck, zContext,
60391
+ checkAppendMsg(pCheck,
6022960392
"Rowid %lld out of order (max larger than parent max of %lld)",
6023060393
nMaxKey, *pnParentMaxKey);
6023160394
}
6023260395
*pnParentMinKey = nMaxKey;
6023360396
}
6023460397
/* else if we're a right child page */
6023560398
} else if( pnParentMaxKey ){
6023660399
if( nMinKey <= *pnParentMaxKey ){
60237
- checkAppendMsg(pCheck, zContext,
60400
+ checkAppendMsg(pCheck,
6023860401
"Rowid %lld out of order (min less than parent max of %lld)",
6023960402
nMinKey, *pnParentMaxKey);
6024060403
}
6024160404
}
6024260405
}
@@ -60244,10 +60407,11 @@
6024460407
/* Check for complete coverage of the page
6024560408
*/
6024660409
data = pPage->aData;
6024760410
hdr = pPage->hdrOffset;
6024860411
hit = sqlite3PageMalloc( pBt->pageSize );
60412
+ pCheck->zPfx = 0;
6024960413
if( hit==0 ){
6025060414
pCheck->mallocFailed = 1;
6025160415
}else{
6025260416
int contentOffset = get2byteNotZero(&data[hdr+5]);
6025360417
assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
@@ -60261,11 +60425,12 @@
6026160425
int j;
6026260426
if( pc<=usableSize-4 ){
6026360427
size = cellSizePtr(pPage, &data[pc]);
6026460428
}
6026560429
if( (int)(pc+size-1)>=usableSize ){
60266
- checkAppendMsg(pCheck, 0,
60430
+ pCheck->zPfx = 0;
60431
+ checkAppendMsg(pCheck,
6026760432
"Corruption detected in cell %d on page %d",i,iPage);
6026860433
}else{
6026960434
for(j=pc+size-1; j>=pc; j--) hit[j]++;
6027060435
}
6027160436
}
@@ -60283,23 +60448,28 @@
6028360448
}
6028460449
for(i=cnt=0; i<usableSize; i++){
6028560450
if( hit[i]==0 ){
6028660451
cnt++;
6028760452
}else if( hit[i]>1 ){
60288
- checkAppendMsg(pCheck, 0,
60453
+ checkAppendMsg(pCheck,
6028960454
"Multiple uses for byte %d of page %d", i, iPage);
6029060455
break;
6029160456
}
6029260457
}
6029360458
if( cnt!=data[hdr+7] ){
60294
- checkAppendMsg(pCheck, 0,
60459
+ checkAppendMsg(pCheck,
6029560460
"Fragmentation of %d bytes reported as %d on page %d",
6029660461
cnt, data[hdr+7], iPage);
6029760462
}
6029860463
}
6029960464
sqlite3PageFree(hit);
6030060465
releasePage(pPage);
60466
+
60467
+end_of_check:
60468
+ pCheck->zPfx = saved_zPfx;
60469
+ pCheck->v1 = saved_v1;
60470
+ pCheck->v2 = saved_v2;
6030160471
return depth+1;
6030260472
}
6030360473
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
6030460474
6030560475
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -60336,10 +60506,13 @@
6033660506
sCheck.pPager = pBt->pPager;
6033760507
sCheck.nPage = btreePagecount(sCheck.pBt);
6033860508
sCheck.mxErr = mxErr;
6033960509
sCheck.nErr = 0;
6034060510
sCheck.mallocFailed = 0;
60511
+ sCheck.zPfx = 0;
60512
+ sCheck.v1 = 0;
60513
+ sCheck.v2 = 0;
6034160514
*pnErr = 0;
6034260515
if( sCheck.nPage==0 ){
6034360516
sqlite3BtreeLeave(p);
6034460517
return 0;
6034560518
}
@@ -60355,53 +60528,57 @@
6035560528
sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
6035660529
sCheck.errMsg.useMalloc = 2;
6035760530
6035860531
/* Check the integrity of the freelist
6035960532
*/
60533
+ sCheck.zPfx = "Main freelist: ";
6036060534
checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
60361
- get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");
60535
+ get4byte(&pBt->pPage1->aData[36]));
60536
+ sCheck.zPfx = 0;
6036260537
6036360538
/* Check all the tables.
6036460539
*/
6036560540
for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
6036660541
if( aRoot[i]==0 ) continue;
6036760542
#ifndef SQLITE_OMIT_AUTOVACUUM
6036860543
if( pBt->autoVacuum && aRoot[i]>1 ){
60369
- checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0, 0);
60544
+ checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
6037060545
}
6037160546
#endif
60372
- checkTreePage(&sCheck, aRoot[i], "List of tree roots: ", NULL, NULL);
60547
+ sCheck.zPfx = "List of tree roots: ";
60548
+ checkTreePage(&sCheck, aRoot[i], NULL, NULL);
60549
+ sCheck.zPfx = 0;
6037360550
}
6037460551
6037560552
/* Make sure every page in the file is referenced
6037660553
*/
6037760554
for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
6037860555
#ifdef SQLITE_OMIT_AUTOVACUUM
6037960556
if( getPageReferenced(&sCheck, i)==0 ){
60380
- checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
60557
+ checkAppendMsg(&sCheck, "Page %d is never used", i);
6038160558
}
6038260559
#else
6038360560
/* If the database supports auto-vacuum, make sure no tables contain
6038460561
** references to pointer-map pages.
6038560562
*/
6038660563
if( getPageReferenced(&sCheck, i)==0 &&
6038760564
(PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
60388
- checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
60565
+ checkAppendMsg(&sCheck, "Page %d is never used", i);
6038960566
}
6039060567
if( getPageReferenced(&sCheck, i)!=0 &&
6039160568
(PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
60392
- checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
60569
+ checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
6039360570
}
6039460571
#endif
6039560572
}
6039660573
6039760574
/* Make sure this analysis did not leave any unref() pages.
6039860575
** This is an internal consistency check; an integrity check
6039960576
** of the integrity check.
6040060577
*/
6040160578
if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
60402
- checkAppendMsg(&sCheck, 0,
60579
+ checkAppendMsg(&sCheck,
6040360580
"Outstanding page count goes from %d to %d during this analysis",
6040460581
nRef, sqlite3PagerRefcount(pBt->pPager)
6040560582
);
6040660583
}
6040760584
@@ -60593,11 +60770,11 @@
6059360770
6059460771
/* Save the positions of all other cursors open on this table. This is
6059560772
** required in case any of them are holding references to an xFetch
6059660773
** version of the b-tree page modified by the accessPayload call below.
6059760774
**
60598
- ** Note that pCsr must be open on a BTREE_INTKEY table and saveCursorPosition()
60775
+ ** Note that pCsr must be open on a INTKEY table and saveCursorPosition()
6059960776
** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
6060060777
** saveAllCursors can only return SQLITE_OK.
6060160778
*/
6060260779
VVA_ONLY(rc =) saveAllCursors(pCsr->pBt, pCsr->pgnoRoot, pCsr);
6060360780
assert( rc==SQLITE_OK );
@@ -61461,11 +61638,14 @@
6146161638
/* If MEM_Dyn is set then Mem.xDel!=0.
6146261639
** Mem.xDel is might not be initialized if MEM_Dyn is clear.
6146361640
*/
6146461641
assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
6146561642
61466
- /* MEM_Dyn may only be set if Mem.szMalloc==0 */
61643
+ /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
61644
+ ** ensure that if Mem.szMalloc>0 then it is safe to do
61645
+ ** Mem.z = Mem.zMalloc without having to check Mem.flags&MEM_Dyn.
61646
+ ** That saves a few cycles in inner loops. */
6146761647
assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
6146861648
6146961649
/* Cannot be both MEM_Int and MEM_Real at the same time */
6147061650
assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
6147161651
@@ -61570,11 +61750,11 @@
6157061750
}else{
6157161751
pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
6157261752
}
6157361753
}
6157461754
61575
- if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
61755
+ if( bPreserve && pMem->z && pMem->z!=pMem->zMalloc ){
6157661756
memcpy(pMem->zMalloc, pMem->z, pMem->n);
6157761757
}
6157861758
if( (pMem->flags&MEM_Dyn)!=0 ){
6157961759
assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
6158061760
pMem->xDel((void *)(pMem->z));
@@ -61597,11 +61777,12 @@
6159761777
**
6159861778
** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
6159961779
** if unable to complete the resizing.
6160061780
*/
6160161781
SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
61602
- assert( szNew>=0 );
61782
+ assert( szNew>0 );
61783
+ assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
6160361784
if( pMem->szMalloc<szNew ){
6160461785
return sqlite3VdbeMemGrow(pMem, szNew, 0);
6160561786
}
6160661787
assert( (pMem->flags & MEM_Dyn)==0 );
6160761788
pMem->z = pMem->zMalloc;
@@ -62321,11 +62502,14 @@
6232162502
nAlloc += (enc==SQLITE_UTF8?1:2);
6232262503
}
6232362504
if( nByte>iLimit ){
6232462505
return SQLITE_TOOBIG;
6232562506
}
62326
- if( sqlite3VdbeMemClearAndResize(pMem, nAlloc) ){
62507
+ testcase( nAlloc==0 );
62508
+ testcase( nAlloc==31 );
62509
+ testcase( nAlloc==32 );
62510
+ if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
6232762511
return SQLITE_NOMEM;
6232862512
}
6232962513
memcpy(pMem->z, z, nAlloc);
6233062514
}else if( xDel==SQLITE_DYNAMIC ){
6233162515
sqlite3VdbeMemRelease(pMem);
@@ -62424,11 +62608,11 @@
6242462608
/*
6242562609
** The pVal argument is known to be a value other than NULL.
6242662610
** Convert it into a string with encoding enc and return a pointer
6242762611
** to a zero-terminated version of that string.
6242862612
*/
62429
-SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){
62613
+static SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){
6243062614
assert( pVal!=0 );
6243162615
assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
6243262616
assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
6243362617
assert( (pVal->flags & MEM_RowSet)==0 );
6243462618
assert( (pVal->flags & (MEM_Null))==0 );
@@ -63751,11 +63935,12 @@
6375163935
if( addr==p->nOp-1 ) p->nOp--;
6375263936
}
6375363937
}
6375463938
6375563939
/*
63756
-** Remove the last opcode inserted
63940
+** If the last opcode is "op" and it is not a jump destination,
63941
+** then remove it. Return true if and only if an opcode was removed.
6375763942
*/
6375863943
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){
6375963944
if( (p->nOp-1)>(p->pParse->iFixedOp) && p->aOp[p->nOp-1].opcode==op ){
6376063945
sqlite3VdbeChangeToNoop(p, p->nOp-1);
6376163946
return 1;
@@ -64743,11 +64928,11 @@
6474364928
** the call above. */
6474464929
}else if( pCx->pCursor ){
6474564930
sqlite3BtreeCloseCursor(pCx->pCursor);
6474664931
}
6474764932
#ifndef SQLITE_OMIT_VIRTUALTABLE
64748
- if( pCx->pVtabCursor ){
64933
+ else if( pCx->pVtabCursor ){
6474964934
sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
6475064935
const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
6475164936
p->inVtabMethod = 1;
6475264937
pModule->xClose(pVtabCursor);
6475364938
p->inVtabMethod = 0;
@@ -64786,13 +64971,14 @@
6478664971
static void closeAllCursors(Vdbe *p){
6478764972
if( p->pFrame ){
6478864973
VdbeFrame *pFrame;
6478964974
for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
6479064975
sqlite3VdbeFrameRestore(pFrame);
64976
+ p->pFrame = 0;
64977
+ p->nFrame = 0;
6479164978
}
64792
- p->pFrame = 0;
64793
- p->nFrame = 0;
64979
+ assert( p->nFrame==0 );
6479464980
6479564981
if( p->apCsr ){
6479664982
int i;
6479764983
for(i=0; i<p->nCursor; i++){
6479864984
VdbeCursor *pC = p->apCsr[i];
@@ -64810,11 +64996,11 @@
6481064996
p->pDelFrame = pDel->pParent;
6481164997
sqlite3VdbeFrameDelete(pDel);
6481264998
}
6481364999
6481465000
/* Delete any auxdata allocations made by the VM */
64815
- sqlite3VdbeDeleteAuxData(p, -1, 0);
65001
+ if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p, -1, 0);
6481665002
assert( p->pAuxData==0 );
6481765003
}
6481865004
6481965005
/*
6482065006
** Clean up the VM after a single run.
@@ -65676,14 +65862,10 @@
6567665862
for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
6567765863
vdbeFreeOpArray(db, p->aOp, p->nOp);
6567865864
sqlite3DbFree(db, p->aColName);
6567965865
sqlite3DbFree(db, p->zSql);
6568065866
sqlite3DbFree(db, p->pFree);
65681
-#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
65682
- sqlite3DbFree(db, p->zExplain);
65683
- sqlite3DbFree(db, p->pExplain);
65684
-#endif
6568565867
}
6568665868
6568765869
/*
6568865870
** Delete an entire VDBE.
6568965871
*/
@@ -65720,13 +65902,11 @@
6572065902
#endif
6572165903
assert( p->deferredMoveto );
6572265904
assert( p->isTable );
6572365905
rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
6572465906
if( rc ) return rc;
65725
- p->lastRowid = p->movetoTarget;
6572665907
if( res!=0 ) return SQLITE_CORRUPT_BKPT;
65727
- p->rowidIsValid = 1;
6572865908
#ifdef SQLITE_TEST
6572965909
sqlite3_search_count++;
6573065910
#endif
6573165911
p->deferredMoveto = 0;
6573265912
p->cacheStatus = CACHE_STALE;
@@ -65747,10 +65927,21 @@
6574765927
rc = sqlite3BtreeCursorRestore(p->pCursor, &isDifferentRow);
6574865928
p->cacheStatus = CACHE_STALE;
6574965929
if( isDifferentRow ) p->nullRow = 1;
6575065930
return rc;
6575165931
}
65932
+
65933
+/*
65934
+** Check to ensure that the cursor is valid. Restore the cursor
65935
+** if need be. Return any I/O error from the restore operation.
65936
+*/
65937
+SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){
65938
+ if( sqlite3BtreeCursorHasMoved(p->pCursor) ){
65939
+ return handleMovedCursor(p);
65940
+ }
65941
+ return SQLITE_OK;
65942
+}
6575265943
6575365944
/*
6575465945
** Make sure the cursor p is ready to read or write the row to which it
6575565946
** was last positioned. Return an error code if an OOM fault or I/O error
6575665947
** prevents us from positioning the cursor to its correct position.
@@ -65765,11 +65956,11 @@
6576565956
*/
6576665957
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor *p){
6576765958
if( p->deferredMoveto ){
6576865959
return handleDeferredMoveto(p);
6576965960
}
65770
- if( sqlite3BtreeCursorHasMoved(p->pCursor) ){
65961
+ if( p->pCursor && sqlite3BtreeCursorHasMoved(p->pCursor) ){
6577165962
return handleMovedCursor(p);
6577265963
}
6577365964
return SQLITE_OK;
6577465965
}
6577565966
@@ -67390,10 +67581,11 @@
6739067581
void (*xDel)(void *),
6739167582
unsigned char enc
6739267583
){
6739367584
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
6739467585
assert( xDel!=SQLITE_DYNAMIC );
67586
+ if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
6739567587
if( n>0x7fffffff ){
6739667588
(void)invokeValueDestructor(z, xDel, pCtx);
6739767589
}else{
6739867590
setResultStrOrError(pCtx, z, (int)n, enc, xDel);
6739967591
}
@@ -68712,125 +68904,10 @@
6871268904
return sqlite3StrAccumFinish(&out);
6871368905
}
6871468906
6871568907
#endif /* #ifndef SQLITE_OMIT_TRACE */
6871668908
68717
-/*****************************************************************************
68718
-** The following code implements the data-structure explaining logic
68719
-** for the Vdbe.
68720
-*/
68721
-
68722
-#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
68723
-
68724
-/*
68725
-** Allocate a new Explain object
68726
-*/
68727
-SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe *pVdbe){
68728
- if( pVdbe ){
68729
- Explain *p;
68730
- sqlite3BeginBenignMalloc();
68731
- p = (Explain *)sqlite3MallocZero( sizeof(Explain) );
68732
- if( p ){
68733
- p->pVdbe = pVdbe;
68734
- sqlite3_free(pVdbe->pExplain);
68735
- pVdbe->pExplain = p;
68736
- sqlite3StrAccumInit(&p->str, p->zBase, sizeof(p->zBase),
68737
- SQLITE_MAX_LENGTH);
68738
- p->str.useMalloc = 2;
68739
- }else{
68740
- sqlite3EndBenignMalloc();
68741
- }
68742
- }
68743
-}
68744
-
68745
-/*
68746
-** Return true if the Explain ends with a new-line.
68747
-*/
68748
-static int endsWithNL(Explain *p){
68749
- return p && p->str.zText && p->str.nChar
68750
- && p->str.zText[p->str.nChar-1]=='\n';
68751
-}
68752
-
68753
-/*
68754
-** Append text to the indentation
68755
-*/
68756
-SQLITE_PRIVATE void sqlite3ExplainPrintf(Vdbe *pVdbe, const char *zFormat, ...){
68757
- Explain *p;
68758
- if( pVdbe && (p = pVdbe->pExplain)!=0 ){
68759
- va_list ap;
68760
- if( p->nIndent && endsWithNL(p) ){
68761
- int n = p->nIndent;
68762
- if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
68763
- sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
68764
- }
68765
- va_start(ap, zFormat);
68766
- sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap);
68767
- va_end(ap);
68768
- }
68769
-}
68770
-
68771
-/*
68772
-** Append a '\n' if there is not already one.
68773
-*/
68774
-SQLITE_PRIVATE void sqlite3ExplainNL(Vdbe *pVdbe){
68775
- Explain *p;
68776
- if( pVdbe && (p = pVdbe->pExplain)!=0 && !endsWithNL(p) ){
68777
- sqlite3StrAccumAppend(&p->str, "\n", 1);
68778
- }
68779
-}
68780
-
68781
-/*
68782
-** Push a new indentation level. Subsequent lines will be indented
68783
-** so that they begin at the current cursor position.
68784
-*/
68785
-SQLITE_PRIVATE void sqlite3ExplainPush(Vdbe *pVdbe){
68786
- Explain *p;
68787
- if( pVdbe && (p = pVdbe->pExplain)!=0 ){
68788
- if( p->str.zText && p->nIndent<ArraySize(p->aIndent) ){
68789
- const char *z = p->str.zText;
68790
- int i = p->str.nChar-1;
68791
- int x;
68792
- while( i>=0 && z[i]!='\n' ){ i--; }
68793
- x = (p->str.nChar - 1) - i;
68794
- if( p->nIndent && x<p->aIndent[p->nIndent-1] ){
68795
- x = p->aIndent[p->nIndent-1];
68796
- }
68797
- p->aIndent[p->nIndent] = x;
68798
- }
68799
- p->nIndent++;
68800
- }
68801
-}
68802
-
68803
-/*
68804
-** Pop the indentation stack by one level.
68805
-*/
68806
-SQLITE_PRIVATE void sqlite3ExplainPop(Vdbe *p){
68807
- if( p && p->pExplain ) p->pExplain->nIndent--;
68808
-}
68809
-
68810
-/*
68811
-** Free the indentation structure
68812
-*/
68813
-SQLITE_PRIVATE void sqlite3ExplainFinish(Vdbe *pVdbe){
68814
- if( pVdbe && pVdbe->pExplain ){
68815
- sqlite3_free(pVdbe->zExplain);
68816
- sqlite3ExplainNL(pVdbe);
68817
- pVdbe->zExplain = sqlite3StrAccumFinish(&pVdbe->pExplain->str);
68818
- sqlite3_free(pVdbe->pExplain);
68819
- pVdbe->pExplain = 0;
68820
- sqlite3EndBenignMalloc();
68821
- }
68822
-}
68823
-
68824
-/*
68825
-** Return the explanation of a virtual machine.
68826
-*/
68827
-SQLITE_PRIVATE const char *sqlite3VdbeExplanation(Vdbe *pVdbe){
68828
- return (pVdbe && pVdbe->zExplain) ? pVdbe->zExplain : 0;
68829
-}
68830
-#endif /* defined(SQLITE_DEBUG) */
68831
-
6883268909
/************** End of vdbetrace.c *******************************************/
6883368910
/************** Begin file vdbe.c ********************************************/
6883468911
/*
6883568912
** 2001 September 15
6883668913
**
@@ -69043,10 +69120,11 @@
6904369120
if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
6904469121
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
6904569122
memset(pCx, 0, sizeof(VdbeCursor));
6904669123
pCx->iDb = iDb;
6904769124
pCx->nField = nField;
69125
+ pCx->aOffset = &pCx->aType[nField];
6904869126
if( isBtreeCursor ){
6904969127
pCx->pCursor = (BtCursor*)
6905069128
&pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
6905169129
sqlite3BtreeCursorZero(pCx->pCursor);
6905269130
}
@@ -70475,21 +70553,14 @@
7047570553
assert( pOp->p4type==P4_FUNCDEF );
7047670554
ctx.pFunc = pOp->p4.pFunc;
7047770555
ctx.iOp = pc;
7047870556
ctx.pVdbe = p;
7047970557
MemSetTypeFlag(ctx.pOut, MEM_Null);
70480
-
7048170558
ctx.fErrorOrAux = 0;
70482
- if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
70483
- assert( pOp>aOp );
70484
- assert( pOp[-1].p4type==P4_COLLSEQ );
70485
- assert( pOp[-1].opcode==OP_CollSeq );
70486
- ctx.pColl = pOp[-1].p4.pColl;
70487
- }
7048870559
db->lastRowid = lastRowid;
7048970560
(*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
70490
- lastRowid = db->lastRowid;
70561
+ lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */
7049170562
7049270563
/* If the function returned an error, throw an exception */
7049370564
if( ctx.fErrorOrAux ){
7049470565
if( ctx.isError ){
7049570566
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
@@ -71201,11 +71272,11 @@
7120171272
memAboutToChange(p, pDest);
7120271273
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7120371274
pC = p->apCsr[pOp->p1];
7120471275
assert( pC!=0 );
7120571276
assert( p2<pC->nField );
71206
- aOffset = pC->aType + pC->nField;
71277
+ aOffset = pC->aOffset;
7120771278
#ifndef SQLITE_OMIT_VIRTUALTABLE
7120871279
assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
7120971280
#endif
7121071281
pCrsr = pC->pCursor;
7121171282
assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -71212,11 +71283,11 @@
7121271283
assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
7121371284
7121471285
/* If the cursor cache is stale, bring it up-to-date */
7121571286
rc = sqlite3VdbeCursorMoveto(pC);
7121671287
if( rc ) goto abort_due_to_error;
71217
- if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
71288
+ if( pC->cacheStatus!=p->cacheCtr ){
7121871289
if( pC->nullRow ){
7121971290
if( pCrsr==0 ){
7122071291
assert( pC->pseudoTableReg>0 );
7122171292
pReg = &aMem[pC->pseudoTableReg];
7122271293
assert( pReg->flags & MEM_Blob );
@@ -71257,18 +71328,10 @@
7125771328
}
7125871329
pC->cacheStatus = p->cacheCtr;
7125971330
pC->iHdrOffset = getVarint32(pC->aRow, offset);
7126071331
pC->nHdrParsed = 0;
7126171332
aOffset[0] = offset;
71262
- if( avail<offset ){
71263
- /* pC->aRow does not have to hold the entire row, but it does at least
71264
- ** need to cover the header of the record. If pC->aRow does not contain
71265
- ** the complete header, then set it to zero, forcing the header to be
71266
- ** dynamically allocated. */
71267
- pC->aRow = 0;
71268
- pC->szRow = 0;
71269
- }
7127071333
7127171334
/* Make sure a corrupt database has not given us an oversize header.
7127271335
** Do this now to avoid an oversize memory allocation.
7127371336
**
7127471337
** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -71279,19 +71342,36 @@
7127971342
*/
7128071343
if( offset > 98307 || offset > pC->payloadSize ){
7128171344
rc = SQLITE_CORRUPT_BKPT;
7128271345
goto op_column_error;
7128371346
}
71347
+
71348
+ if( avail<offset ){
71349
+ /* pC->aRow does not have to hold the entire row, but it does at least
71350
+ ** need to cover the header of the record. If pC->aRow does not contain
71351
+ ** the complete header, then set it to zero, forcing the header to be
71352
+ ** dynamically allocated. */
71353
+ pC->aRow = 0;
71354
+ pC->szRow = 0;
71355
+ }
71356
+
71357
+ /* The following goto is an optimization. It can be omitted and
71358
+ ** everything will still work. But OP_Column is measurably faster
71359
+ ** by skipping the subsequent conditional, which is always true.
71360
+ */
71361
+ assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
71362
+ goto op_column_read_header;
7128471363
}
7128571364
7128671365
/* Make sure at least the first p2+1 entries of the header have been
7128771366
** parsed and valid information is in aOffset[] and pC->aType[].
7128871367
*/
7128971368
if( pC->nHdrParsed<=p2 ){
7129071369
/* If there is more header available for parsing in the record, try
7129171370
** to extract additional fields up through the p2+1-th field
7129271371
*/
71372
+ op_column_read_header:
7129371373
if( pC->iHdrOffset<aOffset[0] ){
7129471374
/* Make sure zData points to enough of the record to cover the header. */
7129571375
if( pC->aRow==0 ){
7129671376
memset(&sMem, 0, sizeof(sMem));
7129771377
rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
@@ -71332,19 +71412,20 @@
7133271412
if( pC->aRow==0 ){
7133371413
sqlite3VdbeMemRelease(&sMem);
7133471414
sMem.flags = MEM_Null;
7133571415
}
7133671416
71337
- /* If we have read more header data than was contained in the header,
71338
- ** or if the end of the last field appears to be past the end of the
71339
- ** record, or if the end of the last field appears to be before the end
71340
- ** of the record (when all fields present), then we must be dealing
71341
- ** with a corrupt database.
71417
+ /* The record is corrupt if any of the following are true:
71418
+ ** (1) the bytes of the header extend past the declared header size
71419
+ ** (zHdr>zEndHdr)
71420
+ ** (2) the entire header was used but not all data was used
71421
+ ** (zHdr==zEndHdr && offset!=pC->payloadSize)
71422
+ ** (3) the end of the data extends beyond the end of the record.
71423
+ ** (offset > pC->payloadSize)
7134271424
*/
71343
- if( (zHdr > zEndHdr)
71425
+ if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset!=pC->payloadSize))
7134471426
|| (offset > pC->payloadSize)
71345
- || (zHdr==zEndHdr && offset!=pC->payloadSize)
7134671427
){
7134771428
rc = SQLITE_CORRUPT_BKPT;
7134871429
goto op_column_error;
7134971430
}
7135071431
}
@@ -71531,11 +71612,11 @@
7153171612
** out how much space is required for the new record.
7153271613
*/
7153371614
pRec = pLast;
7153471615
do{
7153571616
assert( memIsValid(pRec) );
71536
- serial_type = sqlite3VdbeSerialType(pRec, file_format);
71617
+ pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format);
7153771618
len = sqlite3VdbeSerialTypeLen(serial_type);
7153871619
if( pRec->flags & MEM_Zero ){
7153971620
if( nData ){
7154071621
sqlite3VdbeMemExpandBlob(pRec);
7154171622
}else{
@@ -71580,11 +71661,11 @@
7158071661
i = putVarint32(zNewRecord, nHdr);
7158171662
j = nHdr;
7158271663
assert( pData0<=pLast );
7158371664
pRec = pData0;
7158471665
do{
71585
- serial_type = sqlite3VdbeSerialType(pRec, file_format);
71666
+ serial_type = pRec->uTemp;
7158671667
i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
7158771668
j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
7158871669
}while( (++pRec)<=pLast );
7158971670
assert( i==nHdr );
7159071671
assert( j==nByte );
@@ -72205,14 +72286,10 @@
7220572286
rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
7220672287
pCur->pKeyInfo = pKeyInfo;
7220772288
assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
7220872289
sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
7220972290
72210
- /* Since it performs no memory allocation or IO, the only value that
72211
- ** sqlite3BtreeCursor() may return is SQLITE_OK. */
72212
- assert( rc==SQLITE_OK );
72213
-
7221472291
/* Set the VdbeCursor.isTable variable. Previous versions of
7221572292
** SQLite used to check if the root-page flags were sane at this point
7221672293
** and report database corruption if they were not, but this check has
7221772294
** since moved into the btree layer. */
7221872295
pCur->isTable = pOp->p4type!=P4_KEYINFO;
@@ -72483,11 +72560,10 @@
7248372560
pIn3 = &aMem[pOp->p3];
7248472561
if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
7248572562
applyNumericAffinity(pIn3, 0);
7248672563
}
7248772564
iKey = sqlite3VdbeIntValue(pIn3);
72488
- pC->rowidIsValid = 0;
7248972565
7249072566
/* If the P3 value could not be converted into an integer without
7249172567
** loss of information, then special processing is required... */
7249272568
if( (pIn3->flags & MEM_Int)==0 ){
7249372569
if( (pIn3->flags & MEM_Real)==0 ){
@@ -72519,17 +72595,14 @@
7251972595
assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
7252072596
if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
7252172597
}
7252272598
}
7252372599
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
72600
+ pC->movetoTarget = iKey; /* Used by OP_Delete */
7252472601
if( rc!=SQLITE_OK ){
7252572602
goto abort_due_to_error;
7252672603
}
72527
- if( res==0 ){
72528
- pC->rowidIsValid = 1;
72529
- pC->lastRowid = iKey;
72530
- }
7253172604
}else{
7253272605
nField = pOp->p4.i;
7253372606
assert( pOp->p4type==P4_INT32 );
7253472607
assert( nField>0 );
7253572608
r.pKeyInfo = pC->pKeyInfo;
@@ -72555,11 +72628,10 @@
7255572628
ExpandBlob(r.aMem);
7255672629
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
7255772630
if( rc!=SQLITE_OK ){
7255872631
goto abort_due_to_error;
7255972632
}
72560
- pC->rowidIsValid = 0;
7256172633
}
7256272634
pC->deferredMoveto = 0;
7256372635
pC->cacheStatus = CACHE_STALE;
7256472636
#ifdef SQLITE_TEST
7256572637
sqlite3_search_count++;
@@ -72567,21 +72639,19 @@
7256772639
if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
7256872640
if( res<0 || (res==0 && oc==OP_SeekGT) ){
7256972641
res = 0;
7257072642
rc = sqlite3BtreeNext(pC->pCursor, &res);
7257172643
if( rc!=SQLITE_OK ) goto abort_due_to_error;
72572
- pC->rowidIsValid = 0;
7257372644
}else{
7257472645
res = 0;
7257572646
}
7257672647
}else{
7257772648
assert( oc==OP_SeekLT || oc==OP_SeekLE );
7257872649
if( res>0 || (res==0 && oc==OP_SeekLT) ){
7257972650
res = 0;
7258072651
rc = sqlite3BtreePrevious(pC->pCursor, &res);
7258172652
if( rc!=SQLITE_OK ) goto abort_due_to_error;
72582
- pC->rowidIsValid = 0;
7258372653
}else{
7258472654
/* res might be negative because the table is empty. Check to
7258572655
** see if this is the case.
7258672656
*/
7258772657
res = sqlite3BtreeEof(pC->pCursor);
@@ -72614,11 +72684,10 @@
7261472684
assert( pC->pCursor!=0 );
7261572685
assert( pC->isTable );
7261672686
pC->nullRow = 0;
7261772687
pIn2 = &aMem[pOp->p2];
7261872688
pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
72619
- pC->rowidIsValid = 0;
7262072689
pC->deferredMoveto = 1;
7262172690
break;
7262272691
}
7262372692
7262472693
@@ -72800,19 +72869,17 @@
7280072869
pCrsr = pC->pCursor;
7280172870
assert( pCrsr!=0 );
7280272871
res = 0;
7280372872
iKey = pIn3->u.i;
7280472873
rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
72805
- pC->lastRowid = pIn3->u.i;
72806
- pC->rowidIsValid = res==0 ?1:0;
72874
+ pC->movetoTarget = iKey; /* Used by OP_Delete */
7280772875
pC->nullRow = 0;
7280872876
pC->cacheStatus = CACHE_STALE;
7280972877
pC->deferredMoveto = 0;
7281072878
VdbeBranchTaken(res!=0,2);
7281172879
if( res!=0 ){
7281272880
pc = pOp->p2 - 1;
72813
- assert( pC->rowidIsValid==0 );
7281472881
}
7281572882
pC->seekResult = res;
7281672883
break;
7281772884
}
7281872885
@@ -72942,36 +73009,24 @@
7294273009
** largest possible integer (9223372036854775807) then the database
7294373010
** engine starts picking positive candidate ROWIDs at random until
7294473011
** it finds one that is not previously used. */
7294573012
assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
7294673013
** an AUTOINCREMENT table. */
72947
- /* on the first attempt, simply do one more than previous */
72948
- v = lastRowid;
72949
- v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
72950
- v++; /* ensure non-zero */
7295173014
cnt = 0;
72952
- while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
73015
+ do{
73016
+ sqlite3_randomness(sizeof(v), &v);
73017
+ v &= (MAX_ROWID>>1); v++; /* Ensure that v is greater than zero */
73018
+ }while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
7295373019
0, &res))==SQLITE_OK)
7295473020
&& (res==0)
72955
- && (++cnt<100)){
72956
- /* collision - try another random rowid */
72957
- sqlite3_randomness(sizeof(v), &v);
72958
- if( cnt<5 ){
72959
- /* try "small" random rowids for the initial attempts */
72960
- v &= 0xffffff;
72961
- }else{
72962
- v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
72963
- }
72964
- v++; /* ensure non-zero */
72965
- }
73021
+ && (++cnt<100));
7296673022
if( rc==SQLITE_OK && res==0 ){
7296773023
rc = SQLITE_FULL; /* IMP: R-38219-53002 */
7296873024
goto abort_due_to_error;
7296973025
}
7297073026
assert( v>0 ); /* EV: R-40812-03570 */
7297173027
}
72972
- pC->rowidIsValid = 0;
7297373028
pC->deferredMoveto = 0;
7297473029
pC->cacheStatus = CACHE_STALE;
7297573030
}
7297673031
pOut->u.i = v;
7297773032
break;
@@ -73072,11 +73127,10 @@
7307273127
}
7307373128
rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
7307473129
pData->z, pData->n, nZero,
7307573130
(pOp->p5 & OPFLAG_APPEND)!=0, seekResult
7307673131
);
73077
- pC->rowidIsValid = 0;
7307873132
pC->deferredMoveto = 0;
7307973133
pC->cacheStatus = CACHE_STALE;
7308073134
7308173135
/* Invoke the update-hook if required. */
7308273136
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
@@ -73109,37 +73163,36 @@
7310973163
** pointing to. The update hook will be invoked, if it exists.
7311073164
** If P4 is not NULL then the P1 cursor must have been positioned
7311173165
** using OP_NotFound prior to invoking this opcode.
7311273166
*/
7311373167
case OP_Delete: {
73114
- i64 iKey;
7311573168
VdbeCursor *pC;
7311673169
7311773170
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7311873171
pC = p->apCsr[pOp->p1];
7311973172
assert( pC!=0 );
7312073173
assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
73121
- iKey = pC->lastRowid; /* Only used for the update hook */
73122
-
73123
- /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
73124
- ** OP_Column on the same table without any intervening operations that
73125
- ** might move or invalidate the cursor. Hence cursor pC is always pointing
73126
- ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
73127
- ** below is always a no-op and cannot fail. We will run it anyhow, though,
73128
- ** to guard against future changes to the code generator.
73129
- **/
7313073174
assert( pC->deferredMoveto==0 );
73131
- rc = sqlite3VdbeCursorMoveto(pC);
73132
- if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
7313373175
73176
+#ifdef SQLITE_DEBUG
73177
+ /* The seek operation that positioned the cursor prior to OP_Delete will
73178
+ ** have also set the pC->movetoTarget field to the rowid of the row that
73179
+ ** is being deleted */
73180
+ if( pOp->p4.z && pC->isTable ){
73181
+ i64 iKey = 0;
73182
+ sqlite3BtreeKeySize(pC->pCursor, &iKey);
73183
+ assert( pC->movetoTarget==iKey );
73184
+ }
73185
+#endif
73186
+
7313473187
rc = sqlite3BtreeDelete(pC->pCursor);
7313573188
pC->cacheStatus = CACHE_STALE;
7313673189
7313773190
/* Invoke the update-hook if required. */
7313873191
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
7313973192
db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
73140
- db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
73193
+ db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget);
7314173194
assert( pC->iDb>=0 );
7314273195
}
7314373196
if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
7314473197
break;
7314573198
}
@@ -73188,23 +73241,32 @@
7318873241
pc = pOp->p2-1;
7318973242
}
7319073243
break;
7319173244
};
7319273245
73193
-/* Opcode: SorterData P1 P2 * * *
73246
+/* Opcode: SorterData P1 P2 P3 * *
7319473247
** Synopsis: r[P2]=data
7319573248
**
7319673249
** Write into register P2 the current sorter data for sorter cursor P1.
73250
+** Then clear the column header cache on cursor P3.
73251
+**
73252
+** This opcode is normally use to move a record out of the sorter and into
73253
+** a register that is the source for a pseudo-table cursor created using
73254
+** OpenPseudo. That pseudo-table cursor is the one that is identified by
73255
+** parameter P3. Clearing the P3 column cache as part of this opcode saves
73256
+** us from having to issue a separate NullRow instruction to clear that cache.
7319773257
*/
7319873258
case OP_SorterData: {
7319973259
VdbeCursor *pC;
7320073260
7320173261
pOut = &aMem[pOp->p2];
7320273262
pC = p->apCsr[pOp->p1];
7320373263
assert( isSorter(pC) );
7320473264
rc = sqlite3VdbeSorterRowkey(pC, pOut);
7320573265
assert( rc!=SQLITE_OK || (pOut->flags & MEM_Blob) );
73266
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73267
+ p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE;
7320673268
break;
7320773269
}
7320873270
7320973271
/* Opcode: RowData P1 P2 * * *
7321073272
** Synopsis: r[P2]=data
@@ -73247,20 +73309,24 @@
7324773309
assert( pC!=0 );
7324873310
assert( pC->nullRow==0 );
7324973311
assert( pC->pseudoTableReg==0 );
7325073312
assert( pC->pCursor!=0 );
7325173313
pCrsr = pC->pCursor;
73252
- assert( sqlite3BtreeCursorIsValid(pCrsr) );
7325373314
7325473315
/* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
7325573316
** OP_Rewind/Op_Next with no intervening instructions that might invalidate
73256
- ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
73257
- ** a no-op and can never fail. But we leave it in place as a safety.
73317
+ ** the cursor. If this where not the case, on of the following assert()s
73318
+ ** would fail. Should this ever change (because of changes in the code
73319
+ ** generator) then the fix would be to insert a call to
73320
+ ** sqlite3VdbeCursorMoveto().
7325873321
*/
7325973322
assert( pC->deferredMoveto==0 );
73323
+ assert( sqlite3BtreeCursorIsValid(pCrsr) );
73324
+#if 0 /* Not required due to the previous to assert() statements */
7326073325
rc = sqlite3VdbeCursorMoveto(pC);
73261
- if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
73326
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
73327
+#endif
7326273328
7326373329
if( pC->isTable==0 ){
7326473330
assert( !pC->isTable );
7326573331
VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
7326673332
assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
@@ -73273,11 +73339,12 @@
7327373339
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
7327473340
if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
7327573341
goto too_big;
7327673342
}
7327773343
}
73278
- if( sqlite3VdbeMemClearAndResize(pOut, n) ){
73344
+ testcase( n==0 );
73345
+ if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
7327973346
goto no_mem;
7328073347
}
7328173348
pOut->n = n;
7328273349
MemSetTypeFlag(pOut, MEM_Blob);
7328373350
if( pC->isTable==0 ){
@@ -73324,18 +73391,14 @@
7332473391
rc = pModule->xRowid(pC->pVtabCursor, &v);
7332573392
sqlite3VtabImportErrmsg(p, pVtab);
7332673393
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7332773394
}else{
7332873395
assert( pC->pCursor!=0 );
73329
- rc = sqlite3VdbeCursorMoveto(pC);
73396
+ rc = sqlite3VdbeCursorRestore(pC);
7333073397
if( rc ) goto abort_due_to_error;
73331
- if( pC->rowidIsValid ){
73332
- v = pC->lastRowid;
73333
- }else{
73334
- rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73335
- assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
73336
- }
73398
+ rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73399
+ assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
7333773400
}
7333873401
pOut->u.i = v;
7333973402
break;
7334073403
}
7334173404
@@ -73350,11 +73413,10 @@
7335073413
7335173414
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7335273415
pC = p->apCsr[pOp->p1];
7335373416
assert( pC!=0 );
7335473417
pC->nullRow = 1;
73355
- pC->rowidIsValid = 0;
7335673418
pC->cacheStatus = CACHE_STALE;
7335773419
if( pC->pCursor ){
7335873420
sqlite3BtreeClearCursor(pC->pCursor);
7335973421
}
7336073422
break;
@@ -73384,11 +73446,10 @@
7338473446
res = 0;
7338573447
assert( pCrsr!=0 );
7338673448
rc = sqlite3BtreeLast(pCrsr, &res);
7338773449
pC->nullRow = (u8)res;
7338873450
pC->deferredMoveto = 0;
73389
- pC->rowidIsValid = 0;
7339073451
pC->cacheStatus = CACHE_STALE;
7339173452
#ifdef SQLITE_DEBUG
7339273453
pC->seekOp = OP_Last;
7339373454
#endif
7339473455
if( pOp->p2>0 ){
@@ -73451,11 +73512,10 @@
7345173512
pCrsr = pC->pCursor;
7345273513
assert( pCrsr );
7345373514
rc = sqlite3BtreeFirst(pCrsr, &res);
7345473515
pC->deferredMoveto = 0;
7345573516
pC->cacheStatus = CACHE_STALE;
73456
- pC->rowidIsValid = 0;
7345773517
}
7345873518
pC->nullRow = (u8)res;
7345973519
assert( pOp->p2>0 && pOp->p2<p->nOp );
7346073520
VdbeBranchTaken(res!=0,2);
7346173521
if( res ){
@@ -73577,11 +73637,10 @@
7357773637
sqlite3_search_count++;
7357873638
#endif
7357973639
}else{
7358073640
pC->nullRow = 1;
7358173641
}
73582
- pC->rowidIsValid = 0;
7358373642
goto check_for_interrupt;
7358473643
}
7358573644
7358673645
/* Opcode: IdxInsert P1 P2 P3 * P5
7358773646
** Synopsis: key=r[P2]
@@ -73693,14 +73752,20 @@
7369373752
pC = p->apCsr[pOp->p1];
7369473753
assert( pC!=0 );
7369573754
pCrsr = pC->pCursor;
7369673755
assert( pCrsr!=0 );
7369773756
pOut->flags = MEM_Null;
73698
- rc = sqlite3VdbeCursorMoveto(pC);
73699
- if( NEVER(rc) ) goto abort_due_to_error;
73757
+ assert( pC->isTable==0 );
7370073758
assert( pC->deferredMoveto==0 );
73701
- assert( pC->isTable==0 );
73759
+
73760
+ /* sqlite3VbeCursorRestore() can only fail if the record has been deleted
73761
+ ** out from under the cursor. That will never happend for an IdxRowid
73762
+ ** opcode, hence the NEVER() arround the check of the return value.
73763
+ */
73764
+ rc = sqlite3VdbeCursorRestore(pC);
73765
+ if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
73766
+
7370273767
if( !pC->nullRow ){
7370373768
rowid = 0; /* Not needed. Only used to silence a warning. */
7370473769
rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
7370573770
if( rc!=SQLITE_OK ){
7370673771
goto abort_due_to_error;
@@ -74556,18 +74621,13 @@
7455674621
ctx.pMem = pMem = &aMem[pOp->p3];
7455774622
pMem->n++;
7455874623
sqlite3VdbeMemInit(&t, db, MEM_Null);
7455974624
ctx.pOut = &t;
7456074625
ctx.isError = 0;
74561
- ctx.pColl = 0;
74626
+ ctx.pVdbe = p;
74627
+ ctx.iOp = pc;
7456274628
ctx.skipFlag = 0;
74563
- if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
74564
- assert( pOp>p->aOp );
74565
- assert( pOp[-1].p4type==P4_COLLSEQ );
74566
- assert( pOp[-1].opcode==OP_CollSeq );
74567
- ctx.pColl = pOp[-1].p4.pColl;
74568
- }
7456974629
(ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
7457074630
if( ctx.isError ){
7457174631
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
7457274632
rc = ctx.isError;
7457374633
}
@@ -81597,10 +81657,11 @@
8159781657
pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
8159881658
pNew->addrOpenEphm[0] = -1;
8159981659
pNew->addrOpenEphm[1] = -1;
8160081660
pNew->nSelectRow = p->nSelectRow;
8160181661
pNew->pWith = withDup(db, p->pWith);
81662
+ sqlite3SelectSetName(pNew, p->zSelName);
8160281663
return pNew;
8160381664
}
8160481665
#else
8160581666
SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
8160681667
assert( p==0 );
@@ -81739,36 +81800,44 @@
8173981800
}
8174081801
8174181802
/*
8174281803
** These routines are Walker callbacks. Walker.u.pi is a pointer
8174381804
** to an integer. These routines are checking an expression to see
81744
-** if it is a constant. Set *Walker.u.pi to 0 if the expression is
81805
+** if it is a constant. Set *Walker.u.i to 0 if the expression is
8174581806
** not constant.
8174681807
**
8174781808
** These callback routines are used to implement the following:
8174881809
**
81749
-** sqlite3ExprIsConstant()
81750
-** sqlite3ExprIsConstantNotJoin()
81751
-** sqlite3ExprIsConstantOrFunction()
81810
+** sqlite3ExprIsConstant() pWalker->u.i==1
81811
+** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2
81812
+** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4
8175281813
**
81814
+** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
81815
+** in a CREATE TABLE statement. The Walker.u.i value is 4 when parsing
81816
+** an existing schema and 3 when processing a new statement. A bound
81817
+** parameter raises an error for new statements, but is silently converted
81818
+** to NULL for existing schemas. This allows sqlite_master tables that
81819
+** contain a bound parameter because they were generated by older versions
81820
+** of SQLite to be parsed by newer versions of SQLite without raising a
81821
+** malformed schema error.
8175381822
*/
8175481823
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
8175581824
81756
- /* If pWalker->u.i is 3 then any term of the expression that comes from
81825
+ /* If pWalker->u.i is 2 then any term of the expression that comes from
8175781826
** the ON or USING clauses of a join disqualifies the expression
8175881827
** from being considered constant. */
81759
- if( pWalker->u.i==3 && ExprHasProperty(pExpr, EP_FromJoin) ){
81828
+ if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
8176081829
pWalker->u.i = 0;
8176181830
return WRC_Abort;
8176281831
}
8176381832
8176481833
switch( pExpr->op ){
8176581834
/* Consider functions to be constant if all their arguments are constant
81766
- ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST
81835
+ ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST
8176781836
** flag. */
8176881837
case TK_FUNCTION:
81769
- if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){
81838
+ if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){
8177081839
return WRC_Continue;
8177181840
}
8177281841
/* Fall through */
8177381842
case TK_ID:
8177481843
case TK_COLUMN:
@@ -81778,10 +81847,23 @@
8177881847
testcase( pExpr->op==TK_COLUMN );
8177981848
testcase( pExpr->op==TK_AGG_FUNCTION );
8178081849
testcase( pExpr->op==TK_AGG_COLUMN );
8178181850
pWalker->u.i = 0;
8178281851
return WRC_Abort;
81852
+ case TK_VARIABLE:
81853
+ if( pWalker->u.i==4 ){
81854
+ /* Silently convert bound parameters that appear inside of CREATE
81855
+ ** statements into a NULL when parsing the CREATE statement text out
81856
+ ** of the sqlite_master table */
81857
+ pExpr->op = TK_NULL;
81858
+ }else if( pWalker->u.i==3 ){
81859
+ /* A bound parameter in a CREATE statement that originates from
81860
+ ** sqlite3_prepare() causes an error */
81861
+ pWalker->u.i = 0;
81862
+ return WRC_Abort;
81863
+ }
81864
+ /* Fall through */
8178381865
default:
8178481866
testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
8178581867
testcase( pExpr->op==TK_EXISTS ); /* selectNodeIsConstant will disallow */
8178681868
return WRC_Continue;
8178781869
}
@@ -81818,11 +81900,11 @@
8181881900
** that does no originate from the ON or USING clauses of a join.
8181981901
** Return 0 if it involves variables or function calls or terms from
8182081902
** an ON or USING clause.
8182181903
*/
8182281904
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
81823
- return exprIsConst(p, 3);
81905
+ return exprIsConst(p, 2);
8182481906
}
8182581907
8182681908
/*
8182781909
** Walk an expression tree. Return 1 if the expression is constant
8182881910
** or a function call with constant arguments. Return and 0 if there
@@ -81830,12 +81912,13 @@
8183081912
**
8183181913
** For the purposes of this function, a double-quoted string (ex: "abc")
8183281914
** is considered a variable but a single-quoted string (ex: 'abc') is
8183381915
** a constant.
8183481916
*/
81835
-SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p){
81836
- return exprIsConst(p, 2);
81917
+SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
81918
+ assert( isInit==0 || isInit==1 );
81919
+ return exprIsConst(p, 3+isInit);
8183781920
}
8183881921
8183981922
/*
8184081923
** If the expression p codes a constant integer that is small enough
8184181924
** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -83741,94 +83824,90 @@
8374183824
iMem = ++pParse->nMem;
8374283825
sqlite3VdbeAddOp2(v, OP_Copy, target, iMem);
8374383826
exprToRegister(pExpr, iMem);
8374483827
}
8374583828
83746
-#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
83829
+#ifdef SQLITE_DEBUG
8374783830
/*
8374883831
** Generate a human-readable explanation of an expression tree.
8374983832
*/
83750
-SQLITE_PRIVATE void sqlite3ExplainExpr(Vdbe *pOut, Expr *pExpr){
83751
- int op; /* The opcode being coded */
83833
+SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
8375283834
const char *zBinOp = 0; /* Binary operator */
8375383835
const char *zUniOp = 0; /* Unary operator */
83836
+ pView = sqlite3TreeViewPush(pView, moreToFollow);
8375483837
if( pExpr==0 ){
83755
- op = TK_NULL;
83756
- }else{
83757
- op = pExpr->op;
83838
+ sqlite3TreeViewLine(pView, "nil");
83839
+ sqlite3TreeViewPop(pView);
83840
+ return;
8375883841
}
83759
- switch( op ){
83842
+ switch( pExpr->op ){
8376083843
case TK_AGG_COLUMN: {
83761
- sqlite3ExplainPrintf(pOut, "AGG{%d:%d}",
83844
+ sqlite3TreeViewLine(pView, "AGG{%d:%d}",
8376283845
pExpr->iTable, pExpr->iColumn);
8376383846
break;
8376483847
}
8376583848
case TK_COLUMN: {
8376683849
if( pExpr->iTable<0 ){
8376783850
/* This only happens when coding check constraints */
83768
- sqlite3ExplainPrintf(pOut, "COLUMN(%d)", pExpr->iColumn);
83851
+ sqlite3TreeViewLine(pView, "COLUMN(%d)", pExpr->iColumn);
8376983852
}else{
83770
- sqlite3ExplainPrintf(pOut, "{%d:%d}",
83853
+ sqlite3TreeViewLine(pView, "{%d:%d}",
8377183854
pExpr->iTable, pExpr->iColumn);
8377283855
}
8377383856
break;
8377483857
}
8377583858
case TK_INTEGER: {
8377683859
if( pExpr->flags & EP_IntValue ){
83777
- sqlite3ExplainPrintf(pOut, "%d", pExpr->u.iValue);
83860
+ sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue);
8377883861
}else{
83779
- sqlite3ExplainPrintf(pOut, "%s", pExpr->u.zToken);
83862
+ sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken);
8378083863
}
8378183864
break;
8378283865
}
8378383866
#ifndef SQLITE_OMIT_FLOATING_POINT
8378483867
case TK_FLOAT: {
83785
- sqlite3ExplainPrintf(pOut,"%s", pExpr->u.zToken);
83868
+ sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
8378683869
break;
8378783870
}
8378883871
#endif
8378983872
case TK_STRING: {
83790
- sqlite3ExplainPrintf(pOut,"%Q", pExpr->u.zToken);
83873
+ sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
8379183874
break;
8379283875
}
8379383876
case TK_NULL: {
83794
- sqlite3ExplainPrintf(pOut,"NULL");
83877
+ sqlite3TreeViewLine(pView,"NULL");
8379583878
break;
8379683879
}
8379783880
#ifndef SQLITE_OMIT_BLOB_LITERAL
8379883881
case TK_BLOB: {
83799
- sqlite3ExplainPrintf(pOut,"%s", pExpr->u.zToken);
83882
+ sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
8380083883
break;
8380183884
}
8380283885
#endif
8380383886
case TK_VARIABLE: {
83804
- sqlite3ExplainPrintf(pOut,"VARIABLE(%s,%d)",
83805
- pExpr->u.zToken, pExpr->iColumn);
83887
+ sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
83888
+ pExpr->u.zToken, pExpr->iColumn);
8380683889
break;
8380783890
}
8380883891
case TK_REGISTER: {
83809
- sqlite3ExplainPrintf(pOut,"REGISTER(%d)", pExpr->iTable);
83892
+ sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
8381083893
break;
8381183894
}
8381283895
case TK_AS: {
83813
- sqlite3ExplainExpr(pOut, pExpr->pLeft);
83896
+ sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
83897
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
83898
+ break;
83899
+ }
83900
+ case TK_ID: {
83901
+ sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken);
8381483902
break;
8381583903
}
8381683904
#ifndef SQLITE_OMIT_CAST
8381783905
case TK_CAST: {
8381883906
/* Expressions of the form: CAST(pLeft AS token) */
83819
- const char *zAff = "unk";
83820
- switch( sqlite3AffinityType(pExpr->u.zToken, 0) ){
83821
- case SQLITE_AFF_TEXT: zAff = "TEXT"; break;
83822
- case SQLITE_AFF_NONE: zAff = "NONE"; break;
83823
- case SQLITE_AFF_NUMERIC: zAff = "NUMERIC"; break;
83824
- case SQLITE_AFF_INTEGER: zAff = "INTEGER"; break;
83825
- case SQLITE_AFF_REAL: zAff = "REAL"; break;
83826
- }
83827
- sqlite3ExplainPrintf(pOut, "CAST-%s(", zAff);
83828
- sqlite3ExplainExpr(pOut, pExpr->pLeft);
83829
- sqlite3ExplainPrintf(pOut, ")");
83907
+ sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
83908
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
8383083909
break;
8383183910
}
8383283911
#endif /* SQLITE_OMIT_CAST */
8383383912
case TK_LT: zBinOp = "LT"; break;
8383483913
case TK_LE: zBinOp = "LE"; break;
@@ -83848,21 +83927,22 @@
8384883927
case TK_BITOR: zBinOp = "BITOR"; break;
8384983928
case TK_SLASH: zBinOp = "DIV"; break;
8385083929
case TK_LSHIFT: zBinOp = "LSHIFT"; break;
8385183930
case TK_RSHIFT: zBinOp = "RSHIFT"; break;
8385283931
case TK_CONCAT: zBinOp = "CONCAT"; break;
83932
+ case TK_DOT: zBinOp = "DOT"; break;
8385383933
8385483934
case TK_UMINUS: zUniOp = "UMINUS"; break;
8385583935
case TK_UPLUS: zUniOp = "UPLUS"; break;
8385683936
case TK_BITNOT: zUniOp = "BITNOT"; break;
8385783937
case TK_NOT: zUniOp = "NOT"; break;
8385883938
case TK_ISNULL: zUniOp = "ISNULL"; break;
8385983939
case TK_NOTNULL: zUniOp = "NOTNULL"; break;
8386083940
8386183941
case TK_COLLATE: {
83862
- sqlite3ExplainExpr(pOut, pExpr->pLeft);
83863
- sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
83942
+ sqlite3TreeViewLine(pView, "COLLATE %Q", pExpr->u.zToken);
83943
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
8386483944
break;
8386583945
}
8386683946
8386783947
case TK_AGG_FUNCTION:
8386883948
case TK_FUNCTION: {
@@ -83870,45 +83950,40 @@
8387083950
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
8387183951
pFarg = 0;
8387283952
}else{
8387383953
pFarg = pExpr->x.pList;
8387483954
}
83875
- if( op==TK_AGG_FUNCTION ){
83876
- sqlite3ExplainPrintf(pOut, "AGG_FUNCTION%d:%s(",
83955
+ if( pExpr->op==TK_AGG_FUNCTION ){
83956
+ sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q",
8387783957
pExpr->op2, pExpr->u.zToken);
8387883958
}else{
83879
- sqlite3ExplainPrintf(pOut, "FUNCTION:%s(", pExpr->u.zToken);
83959
+ sqlite3TreeViewLine(pView, "FUNCTION %Q", pExpr->u.zToken);
8388083960
}
8388183961
if( pFarg ){
83882
- sqlite3ExplainExprList(pOut, pFarg);
83962
+ sqlite3TreeViewExprList(pView, pFarg, 0, 0);
8388383963
}
83884
- sqlite3ExplainPrintf(pOut, ")");
8388583964
break;
8388683965
}
8388783966
#ifndef SQLITE_OMIT_SUBQUERY
8388883967
case TK_EXISTS: {
83889
- sqlite3ExplainPrintf(pOut, "EXISTS(");
83890
- sqlite3ExplainSelect(pOut, pExpr->x.pSelect);
83891
- sqlite3ExplainPrintf(pOut,")");
83968
+ sqlite3TreeViewLine(pView, "EXISTS-expr");
83969
+ sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
8389283970
break;
8389383971
}
8389483972
case TK_SELECT: {
83895
- sqlite3ExplainPrintf(pOut, "(");
83896
- sqlite3ExplainSelect(pOut, pExpr->x.pSelect);
83897
- sqlite3ExplainPrintf(pOut, ")");
83973
+ sqlite3TreeViewLine(pView, "SELECT-expr");
83974
+ sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
8389883975
break;
8389983976
}
8390083977
case TK_IN: {
83901
- sqlite3ExplainPrintf(pOut, "IN(");
83902
- sqlite3ExplainExpr(pOut, pExpr->pLeft);
83903
- sqlite3ExplainPrintf(pOut, ",");
83978
+ sqlite3TreeViewLine(pView, "IN");
83979
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
8390483980
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
83905
- sqlite3ExplainSelect(pOut, pExpr->x.pSelect);
83981
+ sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
8390683982
}else{
83907
- sqlite3ExplainExprList(pOut, pExpr->x.pList);
83983
+ sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
8390883984
}
83909
- sqlite3ExplainPrintf(pOut, ")");
8391083985
break;
8391183986
}
8391283987
#endif /* SQLITE_OMIT_SUBQUERY */
8391383988
8391483989
/*
@@ -83924,17 +83999,14 @@
8392483999
*/
8392584000
case TK_BETWEEN: {
8392684001
Expr *pX = pExpr->pLeft;
8392784002
Expr *pY = pExpr->x.pList->a[0].pExpr;
8392884003
Expr *pZ = pExpr->x.pList->a[1].pExpr;
83929
- sqlite3ExplainPrintf(pOut, "BETWEEN(");
83930
- sqlite3ExplainExpr(pOut, pX);
83931
- sqlite3ExplainPrintf(pOut, ",");
83932
- sqlite3ExplainExpr(pOut, pY);
83933
- sqlite3ExplainPrintf(pOut, ",");
83934
- sqlite3ExplainExpr(pOut, pZ);
83935
- sqlite3ExplainPrintf(pOut, ")");
84004
+ sqlite3TreeViewLine(pView, "BETWEEN");
84005
+ sqlite3TreeViewExpr(pView, pX, 1);
84006
+ sqlite3TreeViewExpr(pView, pY, 1);
84007
+ sqlite3TreeViewExpr(pView, pZ, 0);
8393684008
break;
8393784009
}
8393884010
case TK_TRIGGER: {
8393984011
/* If the opcode is TK_TRIGGER, then the expression is a reference
8394084012
** to a column in the new.* or old.* pseudo-tables available to
@@ -83941,19 +84013,18 @@
8394184013
** trigger programs. In this case Expr.iTable is set to 1 for the
8394284014
** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
8394384015
** is set to the column of the pseudo-table to read, or to -1 to
8394484016
** read the rowid field.
8394584017
*/
83946
- sqlite3ExplainPrintf(pOut, "%s(%d)",
84018
+ sqlite3TreeViewLine(pView, "%s(%d)",
8394784019
pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn);
8394884020
break;
8394984021
}
8395084022
case TK_CASE: {
83951
- sqlite3ExplainPrintf(pOut, "CASE(");
83952
- sqlite3ExplainExpr(pOut, pExpr->pLeft);
83953
- sqlite3ExplainPrintf(pOut, ",");
83954
- sqlite3ExplainExprList(pOut, pExpr->x.pList);
84023
+ sqlite3TreeViewLine(pView, "CASE");
84024
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
84025
+ sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
8395584026
break;
8395684027
}
8395784028
#ifndef SQLITE_OMIT_TRIGGER
8395884029
case TK_RAISE: {
8395984030
const char *zType = "unk";
@@ -83961,59 +84032,61 @@
8396184032
case OE_Rollback: zType = "rollback"; break;
8396284033
case OE_Abort: zType = "abort"; break;
8396384034
case OE_Fail: zType = "fail"; break;
8396484035
case OE_Ignore: zType = "ignore"; break;
8396584036
}
83966
- sqlite3ExplainPrintf(pOut, "RAISE-%s(%s)", zType, pExpr->u.zToken);
84037
+ sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
8396784038
break;
8396884039
}
8396984040
#endif
84041
+ default: {
84042
+ sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
84043
+ break;
84044
+ }
8397084045
}
8397184046
if( zBinOp ){
83972
- sqlite3ExplainPrintf(pOut,"%s(", zBinOp);
83973
- sqlite3ExplainExpr(pOut, pExpr->pLeft);
83974
- sqlite3ExplainPrintf(pOut,",");
83975
- sqlite3ExplainExpr(pOut, pExpr->pRight);
83976
- sqlite3ExplainPrintf(pOut,")");
84047
+ sqlite3TreeViewLine(pView, "%s", zBinOp);
84048
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
84049
+ sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
8397784050
}else if( zUniOp ){
83978
- sqlite3ExplainPrintf(pOut,"%s(", zUniOp);
83979
- sqlite3ExplainExpr(pOut, pExpr->pLeft);
83980
- sqlite3ExplainPrintf(pOut,")");
83981
- }
83982
-}
83983
-#endif /* defined(SQLITE_ENABLE_TREE_EXPLAIN) */
83984
-
83985
-#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
84051
+ sqlite3TreeViewLine(pView, "%s", zUniOp);
84052
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
84053
+ }
84054
+ sqlite3TreeViewPop(pView);
84055
+}
84056
+#endif /* SQLITE_DEBUG */
84057
+
84058
+#ifdef SQLITE_DEBUG
8398684059
/*
8398784060
** Generate a human-readable explanation of an expression list.
8398884061
*/
83989
-SQLITE_PRIVATE void sqlite3ExplainExprList(Vdbe *pOut, ExprList *pList){
84062
+SQLITE_PRIVATE void sqlite3TreeViewExprList(
84063
+ TreeView *pView,
84064
+ const ExprList *pList,
84065
+ u8 moreToFollow,
84066
+ const char *zLabel
84067
+){
8399084068
int i;
83991
- if( pList==0 || pList->nExpr==0 ){
83992
- sqlite3ExplainPrintf(pOut, "(empty-list)");
83993
- return;
83994
- }else if( pList->nExpr==1 ){
83995
- sqlite3ExplainExpr(pOut, pList->a[0].pExpr);
84069
+ pView = sqlite3TreeViewPush(pView, moreToFollow);
84070
+ if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
84071
+ if( pList==0 ){
84072
+ sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
8399684073
}else{
83997
- sqlite3ExplainPush(pOut);
84074
+ sqlite3TreeViewLine(pView, "%s", zLabel);
8399884075
for(i=0; i<pList->nExpr; i++){
83999
- sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
84000
- sqlite3ExplainPush(pOut);
84001
- sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
84002
- sqlite3ExplainPop(pOut);
84003
- if( pList->a[i].zName ){
84076
+ sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
84077
+#if 0
84078
+ if( pList->a[i].zName ){
8400484079
sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
8400584080
}
8400684081
if( pList->a[i].bSpanIsTab ){
8400784082
sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
8400884083
}
84009
- if( i<pList->nExpr-1 ){
84010
- sqlite3ExplainNL(pOut);
84011
- }
84084
+#endif
8401284085
}
84013
- sqlite3ExplainPop(pOut);
8401484086
}
84087
+ sqlite3TreeViewPop(pView);
8401584088
}
8401684089
#endif /* SQLITE_DEBUG */
8401784090
8401884091
/*
8401984092
** Generate code that pushes the value of every element of the given
@@ -87130,29 +87203,27 @@
8713087203
tRowcnt v;
8713187204
8713287205
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
8713387206
if( z==0 ) z = "";
8713487207
#else
87135
- if( NEVER(z==0) ) z = "";
87208
+ assert( z!=0 );
8713687209
#endif
8713787210
for(i=0; *z && i<nOut; i++){
8713887211
v = 0;
8713987212
while( (c=z[0])>='0' && c<='9' ){
8714087213
v = v*10 + c - '0';
8714187214
z++;
8714287215
}
8714387216
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87144
- if( aOut ){
87145
- aOut[i] = v;
87146
- }else
87217
+ if( aOut ) aOut[i] = v;
87218
+ if( aLog ) aLog[i] = sqlite3LogEst(v);
8714787219
#else
8714887220
assert( aOut==0 );
8714987221
UNUSED_PARAMETER(aOut);
87222
+ assert( aLog!=0 );
87223
+ aLog[i] = sqlite3LogEst(v);
8715087224
#endif
87151
- {
87152
- aLog[i] = sqlite3LogEst(v);
87153
- }
8715487225
if( *z==' ' ) z++;
8715587226
}
8715687227
#ifndef SQLITE_ENABLE_STAT3_OR_STAT4
8715787228
assert( pIndex!=0 );
8715887229
#else
@@ -87209,12 +87280,21 @@
8720987280
pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
8721087281
}
8721187282
z = argv[2];
8721287283
8721387284
if( pIndex ){
87285
+ int nCol = pIndex->nKeyCol+1;
87286
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87287
+ tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
87288
+ sizeof(tRowcnt) * nCol
87289
+ );
87290
+ if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
87291
+#else
87292
+ tRowcnt * const aiRowEst = 0;
87293
+#endif
8721487294
pIndex->bUnordered = 0;
87215
- decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex);
87295
+ decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
8721687296
if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
8721787297
}else{
8721887298
Index fakeIdx;
8721987299
fakeIdx.szIdxRow = pTable->szTabRow;
8722087300
#ifdef SQLITE_ENABLE_COSTMULT
@@ -87269,29 +87349,42 @@
8726987349
** unique. */
8727087350
nCol = pIdx->nSampleCol-1;
8727187351
pIdx->aAvgEq[nCol] = 1;
8727287352
}
8727387353
for(iCol=0; iCol<nCol; iCol++){
87354
+ int nSample = pIdx->nSample;
8727487355
int i; /* Used to iterate through samples */
8727587356
tRowcnt sumEq = 0; /* Sum of the nEq values */
87276
- tRowcnt nSum = 0; /* Number of terms contributing to sumEq */
8727787357
tRowcnt avgEq = 0;
87278
- tRowcnt nDLt = pFinal->anDLt[iCol];
87358
+ tRowcnt nRow; /* Number of rows in index */
87359
+ i64 nSum100 = 0; /* Number of terms contributing to sumEq */
87360
+ i64 nDist100; /* Number of distinct values in index */
87361
+
87362
+ if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
87363
+ nRow = pFinal->anLt[iCol];
87364
+ nDist100 = (i64)100 * pFinal->anDLt[iCol];
87365
+ nSample--;
87366
+ }else{
87367
+ nRow = pIdx->aiRowEst[0];
87368
+ nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
87369
+ }
8727987370
8728087371
/* Set nSum to the number of distinct (iCol+1) field prefixes that
87281
- ** occur in the stat4 table for this index before pFinal. Set
87282
- ** sumEq to the sum of the nEq values for column iCol for the same
87283
- ** set (adding the value only once where there exist duplicate
87284
- ** prefixes). */
87285
- for(i=0; i<(pIdx->nSample-1); i++){
87286
- if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
87372
+ ** occur in the stat4 table for this index. Set sumEq to the sum of
87373
+ ** the nEq values for column iCol for the same set (adding the value
87374
+ ** only once where there exist duplicate prefixes). */
87375
+ for(i=0; i<nSample; i++){
87376
+ if( i==(pIdx->nSample-1)
87377
+ || aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol]
87378
+ ){
8728787379
sumEq += aSample[i].anEq[iCol];
87288
- nSum++;
87380
+ nSum100 += 100;
8728987381
}
8729087382
}
87291
- if( nDLt>nSum ){
87292
- avgEq = (pFinal->anLt[iCol] - sumEq)/(nDLt - nSum);
87383
+
87384
+ if( nDist100>nSum100 ){
87385
+ avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100);
8729387386
}
8729487387
if( avgEq==0 ) avgEq = 1;
8729587388
pIdx->aAvgEq[iCol] = avgEq;
8729687389
}
8729787390
}
@@ -87538,10 +87631,15 @@
8753887631
if( rc==SQLITE_OK ){
8753987632
int lookasideEnabled = db->lookaside.bEnabled;
8754087633
db->lookaside.bEnabled = 0;
8754187634
rc = loadStat4(db, sInfo.zDatabase);
8754287635
db->lookaside.bEnabled = lookasideEnabled;
87636
+ }
87637
+ for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
87638
+ Index *pIdx = sqliteHashData(i);
87639
+ sqlite3_free(pIdx->aiRowEst);
87640
+ pIdx->aiRowEst = 0;
8754387641
}
8754487642
#endif
8754587643
8754687644
if( rc==SQLITE_NOMEM ){
8754787645
db->mallocFailed = 1;
@@ -88832,10 +88930,13 @@
8883288930
#endif
8883388931
if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
8883488932
sqlite3ExprDelete(db, p->pPartIdxWhere);
8883588933
sqlite3DbFree(db, p->zColAff);
8883688934
if( p->isResized ) sqlite3DbFree(db, p->azColl);
88935
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
88936
+ sqlite3_free(p->aiRowEst);
88937
+#endif
8883788938
sqlite3DbFree(db, p);
8883888939
}
8883988940
8884088941
/*
8884188942
** For the index called zIdxName which is found in the database iDb,
@@ -89633,11 +89734,11 @@
8963389734
Column *pCol;
8963489735
sqlite3 *db = pParse->db;
8963589736
p = pParse->pNewTable;
8963689737
if( p!=0 ){
8963789738
pCol = &(p->aCol[p->nCol-1]);
89638
- if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr) ){
89739
+ if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr, db->init.busy) ){
8963989740
sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
8964089741
pCol->zName);
8964189742
}else{
8964289743
/* A copy of pExpr is used instead of the original, as pExpr contains
8964389744
** tokens that point to volatile memory. The 'span' of the expression
@@ -91141,11 +91242,11 @@
9114191242
pIndex->nKeyCol); VdbeCoverage(v);
9114291243
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
9114391244
}else{
9114491245
addr2 = sqlite3VdbeCurrentAddr(v);
9114591246
}
91146
- sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
91247
+ sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
9114791248
sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
9114891249
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
9114991250
sqlite3ReleaseTempReg(pParse, regRecord);
9115091251
sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
9115191252
sqlite3VdbeJumpHere(v, addr1);
@@ -94030,11 +94131,14 @@
9403094131
9403194132
/*
9403294133
** Return the collating function associated with a function.
9403394134
*/
9403494135
static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
94035
- return context->pColl;
94136
+ VdbeOp *pOp = &context->pVdbe->aOp[context->iOp-1];
94137
+ assert( pOp->opcode==OP_CollSeq );
94138
+ assert( pOp->p4type==P4_COLLSEQ );
94139
+ return pOp->p4.pColl;
9403694140
}
9403794141
9403894142
/*
9403994143
** Indicate that the accumulator load should be skipped on this
9404094144
** iteration of the aggregate loop.
@@ -94575,14 +94679,16 @@
9457594679
** character is exactly one byte in size. Also, all characters are
9457694680
** able to participate in upper-case-to-lower-case mappings in EBCDIC
9457794681
** whereas only characters less than 0x80 do in ASCII.
9457894682
*/
9457994683
#if defined(SQLITE_EBCDIC)
94580
-# define sqlite3Utf8Read(A) (*((*A)++))
94581
-# define GlobUpperToLower(A) A = sqlite3UpperToLower[A]
94684
+# define sqlite3Utf8Read(A) (*((*A)++))
94685
+# define GlobUpperToLower(A) A = sqlite3UpperToLower[A]
94686
+# define GlobUpperToLowerAscii(A) A = sqlite3UpperToLower[A]
9458294687
#else
94583
-# define GlobUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
94688
+# define GlobUpperToLower(A) if( A<=0x7f ){ A = sqlite3UpperToLower[A]; }
94689
+# define GlobUpperToLowerAscii(A) A = sqlite3UpperToLower[A]
9458494690
#endif
9458594691
9458694692
static const struct compareInfo globInfo = { '*', '?', '[', 0 };
9458794693
/* The correct SQL-92 behavior is for the LIKE operator to ignore
9458894694
** case. Thus 'a' LIKE 'A' would be true. */
@@ -94591,11 +94697,11 @@
9459194697
** is case sensitive causing 'a' LIKE 'A' to be false */
9459294698
static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
9459394699
9459494700
/*
9459594701
** Compare two UTF-8 strings for equality where the first string can
94596
-** potentially be a "glob" expression. Return true (1) if they
94702
+** potentially be a "glob" or "like" expression. Return true (1) if they
9459794703
** are the same and false (0) if they are different.
9459894704
**
9459994705
** Globbing rules:
9460094706
**
9460194707
** '*' Matches any sequence of zero or more characters.
@@ -94611,120 +94717,147 @@
9461194717
** in the list by making it the first character after '[' or '^'. A
9461294718
** range of characters can be specified using '-'. Example:
9461394719
** "[a-z]" matches any single lower-case letter. To match a '-', make
9461494720
** it the last character in the list.
9461594721
**
94722
+** Like matching rules:
94723
+**
94724
+** '%' Matches any sequence of zero or more characters
94725
+**
94726
+*** '_' Matches any one character
94727
+**
94728
+** Ec Where E is the "esc" character and c is any other
94729
+** character, including '%', '_', and esc, match exactly c.
94730
+**
94731
+** The comments through this routine usually assume glob matching.
94732
+**
9461694733
** This routine is usually quick, but can be N**2 in the worst case.
94617
-**
94618
-** Hints: to match '*' or '?', put them in "[]". Like this:
94619
-**
94620
-** abc[*]xyz Matches "abc*xyz" only
9462194734
*/
9462294735
static int patternCompare(
9462394736
const u8 *zPattern, /* The glob pattern */
9462494737
const u8 *zString, /* The string to compare against the glob */
9462594738
const struct compareInfo *pInfo, /* Information about how to do the compare */
9462694739
u32 esc /* The escape character */
9462794740
){
94628
- u32 c, c2;
94629
- int invert;
94630
- int seen;
94631
- u8 matchOne = pInfo->matchOne;
94632
- u8 matchAll = pInfo->matchAll;
94633
- u8 matchSet = pInfo->matchSet;
94634
- u8 noCase = pInfo->noCase;
94635
- int prevEscape = 0; /* True if the previous character was 'escape' */
94741
+ u32 c, c2; /* Next pattern and input string chars */
94742
+ u32 matchOne = pInfo->matchOne; /* "?" or "_" */
94743
+ u32 matchAll = pInfo->matchAll; /* "*" or "%" */
94744
+ u32 matchOther; /* "[" or the escape character */
94745
+ u8 noCase = pInfo->noCase; /* True if uppercase==lowercase */
94746
+ const u8 *zEscaped = 0; /* One past the last escaped input char */
94747
+
94748
+ /* The GLOB operator does not have an ESCAPE clause. And LIKE does not
94749
+ ** have the matchSet operator. So we either have to look for one or
94750
+ ** the other, never both. Hence the single variable matchOther is used
94751
+ ** to store the one we have to look for.
94752
+ */
94753
+ matchOther = esc ? esc : pInfo->matchSet;
9463694754
9463794755
while( (c = sqlite3Utf8Read(&zPattern))!=0 ){
94638
- if( c==matchAll && !prevEscape ){
94756
+ if( c==matchAll ){ /* Match "*" */
94757
+ /* Skip over multiple "*" characters in the pattern. If there
94758
+ ** are also "?" characters, skip those as well, but consume a
94759
+ ** single character of the input string for each "?" skipped */
9463994760
while( (c=sqlite3Utf8Read(&zPattern)) == matchAll
9464094761
|| c == matchOne ){
9464194762
if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
9464294763
return 0;
9464394764
}
9464494765
}
9464594766
if( c==0 ){
94646
- return 1;
94647
- }else if( c==esc ){
94648
- c = sqlite3Utf8Read(&zPattern);
94649
- if( c==0 ){
94650
- return 0;
94651
- }
94652
- }else if( c==matchSet ){
94653
- assert( esc==0 ); /* This is GLOB, not LIKE */
94654
- assert( matchSet<0x80 ); /* '[' is a single-byte character */
94655
- while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
94656
- SQLITE_SKIP_UTF8(zString);
94657
- }
94658
- return *zString!=0;
94659
- }
94660
- while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
94661
- if( noCase ){
94662
- GlobUpperToLower(c2);
94663
- GlobUpperToLower(c);
94664
- while( c2 != 0 && c2 != c ){
94665
- c2 = sqlite3Utf8Read(&zString);
94666
- GlobUpperToLower(c2);
94667
- }
94668
- }else{
94669
- while( c2 != 0 && c2 != c ){
94670
- c2 = sqlite3Utf8Read(&zString);
94671
- }
94672
- }
94673
- if( c2==0 ) return 0;
94674
- if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
94675
- }
94676
- return 0;
94677
- }else if( c==matchOne && !prevEscape ){
94678
- if( sqlite3Utf8Read(&zString)==0 ){
94679
- return 0;
94680
- }
94681
- }else if( c==matchSet ){
94682
- u32 prior_c = 0;
94683
- assert( esc==0 ); /* This only occurs for GLOB, not LIKE */
94684
- seen = 0;
94685
- invert = 0;
94686
- c = sqlite3Utf8Read(&zString);
94687
- if( c==0 ) return 0;
94688
- c2 = sqlite3Utf8Read(&zPattern);
94689
- if( c2=='^' ){
94690
- invert = 1;
94691
- c2 = sqlite3Utf8Read(&zPattern);
94692
- }
94693
- if( c2==']' ){
94694
- if( c==']' ) seen = 1;
94695
- c2 = sqlite3Utf8Read(&zPattern);
94696
- }
94697
- while( c2 && c2!=']' ){
94698
- if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
94699
- c2 = sqlite3Utf8Read(&zPattern);
94700
- if( c>=prior_c && c<=c2 ) seen = 1;
94701
- prior_c = 0;
94702
- }else{
94703
- if( c==c2 ){
94704
- seen = 1;
94705
- }
94706
- prior_c = c2;
94707
- }
94708
- c2 = sqlite3Utf8Read(&zPattern);
94709
- }
94710
- if( c2==0 || (seen ^ invert)==0 ){
94711
- return 0;
94712
- }
94713
- }else if( esc==c && !prevEscape ){
94714
- prevEscape = 1;
94715
- }else{
94716
- c2 = sqlite3Utf8Read(&zString);
94717
- if( noCase ){
94718
- GlobUpperToLower(c);
94719
- GlobUpperToLower(c2);
94720
- }
94721
- if( c!=c2 ){
94722
- return 0;
94723
- }
94724
- prevEscape = 0;
94725
- }
94767
+ return 1; /* "*" at the end of the pattern matches */
94768
+ }else if( c==matchOther ){
94769
+ if( esc ){
94770
+ c = sqlite3Utf8Read(&zPattern);
94771
+ if( c==0 ) return 0;
94772
+ }else{
94773
+ /* "[...]" immediately follows the "*". We have to do a slow
94774
+ ** recursive search in this case, but it is an unusual case. */
94775
+ assert( matchOther<0x80 ); /* '[' is a single-byte character */
94776
+ while( *zString
94777
+ && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
94778
+ SQLITE_SKIP_UTF8(zString);
94779
+ }
94780
+ return *zString!=0;
94781
+ }
94782
+ }
94783
+
94784
+ /* At this point variable c contains the first character of the
94785
+ ** pattern string past the "*". Search in the input string for the
94786
+ ** first matching character and recursively contine the match from
94787
+ ** that point.
94788
+ **
94789
+ ** For a case-insensitive search, set variable cx to be the same as
94790
+ ** c but in the other case and search the input string for either
94791
+ ** c or cx.
94792
+ */
94793
+ if( c<=0x80 ){
94794
+ u32 cx;
94795
+ if( noCase ){
94796
+ cx = sqlite3Toupper(c);
94797
+ c = sqlite3Tolower(c);
94798
+ }else{
94799
+ cx = c;
94800
+ }
94801
+ while( (c2 = *(zString++))!=0 ){
94802
+ if( c2!=c && c2!=cx ) continue;
94803
+ if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
94804
+ }
94805
+ }else{
94806
+ while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
94807
+ if( c2!=c ) continue;
94808
+ if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
94809
+ }
94810
+ }
94811
+ return 0;
94812
+ }
94813
+ if( c==matchOther ){
94814
+ if( esc ){
94815
+ c = sqlite3Utf8Read(&zPattern);
94816
+ if( c==0 ) return 0;
94817
+ zEscaped = zPattern;
94818
+ }else{
94819
+ u32 prior_c = 0;
94820
+ int seen = 0;
94821
+ int invert = 0;
94822
+ c = sqlite3Utf8Read(&zString);
94823
+ if( c==0 ) return 0;
94824
+ c2 = sqlite3Utf8Read(&zPattern);
94825
+ if( c2=='^' ){
94826
+ invert = 1;
94827
+ c2 = sqlite3Utf8Read(&zPattern);
94828
+ }
94829
+ if( c2==']' ){
94830
+ if( c==']' ) seen = 1;
94831
+ c2 = sqlite3Utf8Read(&zPattern);
94832
+ }
94833
+ while( c2 && c2!=']' ){
94834
+ if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
94835
+ c2 = sqlite3Utf8Read(&zPattern);
94836
+ if( c>=prior_c && c<=c2 ) seen = 1;
94837
+ prior_c = 0;
94838
+ }else{
94839
+ if( c==c2 ){
94840
+ seen = 1;
94841
+ }
94842
+ prior_c = c2;
94843
+ }
94844
+ c2 = sqlite3Utf8Read(&zPattern);
94845
+ }
94846
+ if( c2==0 || (seen ^ invert)==0 ){
94847
+ return 0;
94848
+ }
94849
+ continue;
94850
+ }
94851
+ }
94852
+ c2 = sqlite3Utf8Read(&zString);
94853
+ if( c==c2 ) continue;
94854
+ if( noCase && c<0x80 && c2<0x80 && sqlite3Tolower(c)==sqlite3Tolower(c2) ){
94855
+ continue;
94856
+ }
94857
+ if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
94858
+ return 0;
9472694859
}
9472794860
return *zString==0;
9472894861
}
9472994862
9473094863
/*
@@ -103884,10 +104017,24 @@
103884104017
**
103885104018
*************************************************************************
103886104019
** This file contains C code routines that are called by the parser
103887104020
** to handle SELECT statements in SQLite.
103888104021
*/
104022
+
104023
+/*
104024
+** Trace output macros
104025
+*/
104026
+#if SELECTTRACE_ENABLED
104027
+/***/ int sqlite3SelectTrace = 0;
104028
+# define SELECTTRACE(K,P,S,X) \
104029
+ if(sqlite3SelectTrace&(K)) \
104030
+ sqlite3DebugPrintf("%*s%s.%p: ",(P)->nSelectIndent*2-2,"",(S)->zSelName,(S)),\
104031
+ sqlite3DebugPrintf X
104032
+#else
104033
+# define SELECTTRACE(K,P,S,X)
104034
+#endif
104035
+
103889104036
103890104037
/*
103891104038
** An instance of the following object is used to record information about
103892104039
** how to process the DISTINCT keyword, to simplify passing that information
103893104040
** into the selectInnerLoop() routine.
@@ -103996,10 +104143,22 @@
103996104143
assert( pNew->pSrc!=0 || pParse->nErr>0 );
103997104144
}
103998104145
assert( pNew!=&standin );
103999104146
return pNew;
104000104147
}
104148
+
104149
+#if SELECTTRACE_ENABLED
104150
+/*
104151
+** Set the name of a Select object
104152
+*/
104153
+SQLITE_PRIVATE void sqlite3SelectSetName(Select *p, const char *zName){
104154
+ if( p && zName ){
104155
+ sqlite3_snprintf(sizeof(p->zSelName), p->zSelName, "%s", zName);
104156
+ }
104157
+}
104158
+#endif
104159
+
104001104160
104002104161
/*
104003104162
** Delete the given Select structure and all of its substructures.
104004104163
*/
104005104164
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
@@ -105026,11 +105185,10 @@
105026105185
int regRow;
105027105186
int regRowid;
105028105187
int nKey;
105029105188
int iSortTab; /* Sorter cursor to read from */
105030105189
int nSortData; /* Trailing values to read from sorter */
105031
- u8 p5; /* p5 parameter for 1st OP_Column */
105032105190
int i;
105033105191
int bSeq; /* True if sorter record includes seq. no. */
105034105192
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
105035105193
struct ExprList_item *aOutEx = p->pEList->a;
105036105194
#endif
@@ -105060,23 +105218,20 @@
105060105218
sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
105061105219
if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
105062105220
addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
105063105221
VdbeCoverage(v);
105064105222
codeOffset(v, p->iOffset, addrContinue);
105065
- sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
105066
- p5 = OPFLAG_CLEARCACHE;
105223
+ sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
105067105224
bSeq = 0;
105068105225
}else{
105069105226
addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
105070105227
codeOffset(v, p->iOffset, addrContinue);
105071105228
iSortTab = iTab;
105072
- p5 = 0;
105073105229
bSeq = 1;
105074105230
}
105075105231
for(i=0; i<nSortData; i++){
105076105232
sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
105077
- if( i==0 ) sqlite3VdbeChangeP5(v, p5);
105078105233
VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
105079105234
}
105080105235
switch( eDest ){
105081105236
case SRT_Table:
105082105237
case SRT_EphemTab: {
@@ -107226,10 +107381,12 @@
107226107381
}
107227107382
}
107228107383
}
107229107384
107230107385
/***** If we reach this point, flattening is permitted. *****/
107386
+ SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
107387
+ pSub->zSelName, pSub, iFrom));
107231107388
107232107389
/* Authorize the subquery */
107233107390
pParse->zAuthContext = pSubitem->zName;
107234107391
TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
107235107392
testcase( i==SQLITE_DENY );
@@ -107278,10 +107435,11 @@
107278107435
p->pSrc = 0;
107279107436
p->pPrior = 0;
107280107437
p->pLimit = 0;
107281107438
p->pOffset = 0;
107282107439
pNew = sqlite3SelectDup(db, p, 0);
107440
+ sqlite3SelectSetName(pNew, pSub->zSelName);
107283107441
p->pOffset = pOffset;
107284107442
p->pLimit = pLimit;
107285107443
p->pOrderBy = pOrderBy;
107286107444
p->pSrc = pSrc;
107287107445
p->op = TK_ALL;
@@ -107290,10 +107448,13 @@
107290107448
}else{
107291107449
pNew->pPrior = pPrior;
107292107450
if( pPrior ) pPrior->pNext = pNew;
107293107451
pNew->pNext = p;
107294107452
p->pPrior = pNew;
107453
+ SELECTTRACE(2,pParse,p,
107454
+ ("compound-subquery flattener creates %s.%p as peer\n",
107455
+ pNew->zSelName, pNew));
107295107456
}
107296107457
if( db->mallocFailed ) return 1;
107297107458
}
107298107459
107299107460
/* Begin flattening the iFrom-th entry of the FROM clause
@@ -107419,12 +107580,27 @@
107419107580
if( isAgg ){
107420107581
substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
107421107582
pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
107422107583
}
107423107584
if( pSub->pOrderBy ){
107585
+ /* At this point, any non-zero iOrderByCol values indicate that the
107586
+ ** ORDER BY column expression is identical to the iOrderByCol'th
107587
+ ** expression returned by SELECT statement pSub. Since these values
107588
+ ** do not necessarily correspond to columns in SELECT statement pParent,
107589
+ ** zero them before transfering the ORDER BY clause.
107590
+ **
107591
+ ** Not doing this may cause an error if a subsequent call to this
107592
+ ** function attempts to flatten a compound sub-query into pParent
107593
+ ** (the only way this can happen is if the compound sub-query is
107594
+ ** currently part of pSub->pSrc). See ticket [d11a6e908f]. */
107595
+ ExprList *pOrderBy = pSub->pOrderBy;
107596
+ for(i=0; i<pOrderBy->nExpr; i++){
107597
+ pOrderBy->a[i].u.x.iOrderByCol = 0;
107598
+ }
107424107599
assert( pParent->pOrderBy==0 );
107425
- pParent->pOrderBy = pSub->pOrderBy;
107600
+ assert( pSub->pPrior==0 );
107601
+ pParent->pOrderBy = pOrderBy;
107426107602
pSub->pOrderBy = 0;
107427107603
}else if( pParent->pOrderBy ){
107428107604
substExprList(db, pParent->pOrderBy, iParent, pSub->pEList);
107429107605
}
107430107606
if( pSub->pWhere ){
@@ -107465,10 +107641,17 @@
107465107641
107466107642
/* Finially, delete what is left of the subquery and return
107467107643
** success.
107468107644
*/
107469107645
sqlite3SelectDelete(db, pSub1);
107646
+
107647
+#if SELECTTRACE_ENABLED
107648
+ if( sqlite3SelectTrace & 0x100 ){
107649
+ sqlite3DebugPrintf("After flattening:\n");
107650
+ sqlite3TreeViewSelect(0, p, 0);
107651
+ }
107652
+#endif
107470107653
107471107654
return 1;
107472107655
}
107473107656
#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
107474107657
@@ -107936,10 +108119,11 @@
107936108119
if( pTab->pSelect || IsVirtual(pTab) ){
107937108120
/* We reach here if the named table is a really a view */
107938108121
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
107939108122
assert( pFrom->pSelect==0 );
107940108123
pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
108124
+ sqlite3SelectSetName(pFrom->pSelect, pTab->zName);
107941108125
sqlite3WalkSelect(pWalker, pFrom->pSelect);
107942108126
}
107943108127
#endif
107944108128
}
107945108129
@@ -108470,10 +108654,17 @@
108470108654
if( p==0 || db->mallocFailed || pParse->nErr ){
108471108655
return 1;
108472108656
}
108473108657
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
108474108658
memset(&sAggInfo, 0, sizeof(sAggInfo));
108659
+#if SELECTTRACE_ENABLED
108660
+ pParse->nSelectIndent++;
108661
+ SELECTTRACE(1,pParse,p, ("begin processing:\n"));
108662
+ if( sqlite3SelectTrace & 0x100 ){
108663
+ sqlite3TreeViewSelect(0, p, 0);
108664
+ }
108665
+#endif
108475108666
108476108667
assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
108477108668
assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
108478108669
assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
108479108670
assert( p->pOrderBy==0 || pDest->eDest!=SRT_Queue );
@@ -108626,10 +108817,14 @@
108626108817
/* If there is are a sequence of queries, do the earlier ones first.
108627108818
*/
108628108819
if( p->pPrior ){
108629108820
rc = multiSelect(pParse, p, pDest);
108630108821
explainSetInteger(pParse->iSelectId, iRestoreSelectId);
108822
+#if SELECTTRACE_ENABLED
108823
+ SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
108824
+ pParse->nSelectIndent--;
108825
+#endif
108631108826
return rc;
108632108827
}
108633108828
#endif
108634108829
108635108830
/* If the query is DISTINCT with an ORDER BY but is not an aggregate, and
@@ -108961,16 +109156,15 @@
108961109156
** from the previous row currently stored in a0, a1, a2...
108962109157
*/
108963109158
addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
108964109159
sqlite3ExprCacheClear(pParse);
108965109160
if( groupBySort ){
108966
- sqlite3VdbeAddOp2(v, OP_SorterData, sAggInfo.sortingIdx, sortOut);
109161
+ sqlite3VdbeAddOp3(v, OP_SorterData, sAggInfo.sortingIdx, sortOut,sortPTab);
108967109162
}
108968109163
for(j=0; j<pGroupBy->nExpr; j++){
108969109164
if( groupBySort ){
108970109165
sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
108971
- if( j==0 ) sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
108972109166
}else{
108973109167
sAggInfo.directMode = 1;
108974109168
sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
108975109169
}
108976109170
}
@@ -109225,107 +109419,110 @@
109225109419
generateColumnNames(pParse, pTabList, pEList);
109226109420
}
109227109421
109228109422
sqlite3DbFree(db, sAggInfo.aCol);
109229109423
sqlite3DbFree(db, sAggInfo.aFunc);
109424
+#if SELECTTRACE_ENABLED
109425
+ SELECTTRACE(1,pParse,p,("end processing\n"));
109426
+ pParse->nSelectIndent--;
109427
+#endif
109230109428
return rc;
109231109429
}
109232109430
109233
-#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
109431
+#ifdef SQLITE_DEBUG
109234109432
/*
109235109433
** Generate a human-readable description of a the Select object.
109236109434
*/
109237
-static void explainOneSelect(Vdbe *pVdbe, Select *p){
109238
- sqlite3ExplainPrintf(pVdbe, "SELECT ");
109239
- if( p->selFlags & (SF_Distinct|SF_Aggregate) ){
109240
- if( p->selFlags & SF_Distinct ){
109241
- sqlite3ExplainPrintf(pVdbe, "DISTINCT ");
109242
- }
109243
- if( p->selFlags & SF_Aggregate ){
109244
- sqlite3ExplainPrintf(pVdbe, "agg_flag ");
109245
- }
109246
- sqlite3ExplainNL(pVdbe);
109247
- sqlite3ExplainPrintf(pVdbe, " ");
109248
- }
109249
- sqlite3ExplainExprList(pVdbe, p->pEList);
109250
- sqlite3ExplainNL(pVdbe);
109435
+SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
109436
+ int n = 0;
109437
+ pView = sqlite3TreeViewPush(pView, moreToFollow);
109438
+ sqlite3TreeViewLine(pView, "SELECT%s%s",
109439
+ ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
109440
+ ((p->selFlags & SF_Aggregate) ? " agg_flag" : "")
109441
+ );
109442
+ if( p->pSrc && p->pSrc->nSrc ) n++;
109443
+ if( p->pWhere ) n++;
109444
+ if( p->pGroupBy ) n++;
109445
+ if( p->pHaving ) n++;
109446
+ if( p->pOrderBy ) n++;
109447
+ if( p->pLimit ) n++;
109448
+ if( p->pOffset ) n++;
109449
+ if( p->pPrior ) n++;
109450
+ sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
109251109451
if( p->pSrc && p->pSrc->nSrc ){
109252109452
int i;
109253
- sqlite3ExplainPrintf(pVdbe, "FROM ");
109254
- sqlite3ExplainPush(pVdbe);
109453
+ pView = sqlite3TreeViewPush(pView, (n--)>0);
109454
+ sqlite3TreeViewLine(pView, "FROM");
109255109455
for(i=0; i<p->pSrc->nSrc; i++){
109256109456
struct SrcList_item *pItem = &p->pSrc->a[i];
109257
- sqlite3ExplainPrintf(pVdbe, "{%d,*} = ", pItem->iCursor);
109258
- if( pItem->pSelect ){
109259
- sqlite3ExplainSelect(pVdbe, pItem->pSelect);
109260
- if( pItem->pTab ){
109261
- sqlite3ExplainPrintf(pVdbe, " (tabname=%s)", pItem->pTab->zName);
109262
- }
109457
+ StrAccum x;
109458
+ char zLine[100];
109459
+ sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0);
109460
+ sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
109461
+ if( pItem->zDatabase ){
109462
+ sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
109263109463
}else if( pItem->zName ){
109264
- sqlite3ExplainPrintf(pVdbe, "%s", pItem->zName);
109464
+ sqlite3XPrintf(&x, 0, " %s", pItem->zName);
109465
+ }
109466
+ if( pItem->pTab ){
109467
+ sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
109265109468
}
109266109469
if( pItem->zAlias ){
109267
- sqlite3ExplainPrintf(pVdbe, " (AS %s)", pItem->zAlias);
109470
+ sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
109268109471
}
109269109472
if( pItem->jointype & JT_LEFT ){
109270
- sqlite3ExplainPrintf(pVdbe, " LEFT-JOIN");
109473
+ sqlite3XPrintf(&x, 0, " LEFT-JOIN");
109271109474
}
109272
- sqlite3ExplainNL(pVdbe);
109475
+ sqlite3StrAccumFinish(&x);
109476
+ sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
109477
+ if( pItem->pSelect ){
109478
+ sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
109479
+ }
109480
+ sqlite3TreeViewPop(pView);
109273109481
}
109274
- sqlite3ExplainPop(pVdbe);
109482
+ sqlite3TreeViewPop(pView);
109275109483
}
109276109484
if( p->pWhere ){
109277
- sqlite3ExplainPrintf(pVdbe, "WHERE ");
109278
- sqlite3ExplainExpr(pVdbe, p->pWhere);
109279
- sqlite3ExplainNL(pVdbe);
109485
+ sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
109486
+ sqlite3TreeViewExpr(pView, p->pWhere, 0);
109487
+ sqlite3TreeViewPop(pView);
109280109488
}
109281109489
if( p->pGroupBy ){
109282
- sqlite3ExplainPrintf(pVdbe, "GROUPBY ");
109283
- sqlite3ExplainExprList(pVdbe, p->pGroupBy);
109284
- sqlite3ExplainNL(pVdbe);
109490
+ sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
109285109491
}
109286109492
if( p->pHaving ){
109287
- sqlite3ExplainPrintf(pVdbe, "HAVING ");
109288
- sqlite3ExplainExpr(pVdbe, p->pHaving);
109289
- sqlite3ExplainNL(pVdbe);
109493
+ sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
109494
+ sqlite3TreeViewExpr(pView, p->pHaving, 0);
109495
+ sqlite3TreeViewPop(pView);
109290109496
}
109291109497
if( p->pOrderBy ){
109292
- sqlite3ExplainPrintf(pVdbe, "ORDERBY ");
109293
- sqlite3ExplainExprList(pVdbe, p->pOrderBy);
109294
- sqlite3ExplainNL(pVdbe);
109498
+ sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
109295109499
}
109296109500
if( p->pLimit ){
109297
- sqlite3ExplainPrintf(pVdbe, "LIMIT ");
109298
- sqlite3ExplainExpr(pVdbe, p->pLimit);
109299
- sqlite3ExplainNL(pVdbe);
109501
+ sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
109502
+ sqlite3TreeViewExpr(pView, p->pLimit, 0);
109503
+ sqlite3TreeViewPop(pView);
109300109504
}
109301109505
if( p->pOffset ){
109302
- sqlite3ExplainPrintf(pVdbe, "OFFSET ");
109303
- sqlite3ExplainExpr(pVdbe, p->pOffset);
109304
- sqlite3ExplainNL(pVdbe);
109305
- }
109306
-}
109307
-SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){
109308
- if( p==0 ){
109309
- sqlite3ExplainPrintf(pVdbe, "(null-select)");
109310
- return;
109311
- }
109312
- sqlite3ExplainPush(pVdbe);
109313
- while( p ){
109314
- explainOneSelect(pVdbe, p);
109315
- p = p->pNext;
109316
- if( p==0 ) break;
109317
- sqlite3ExplainNL(pVdbe);
109318
- sqlite3ExplainPrintf(pVdbe, "%s\n", selectOpName(p->op));
109319
- }
109320
- sqlite3ExplainPrintf(pVdbe, "END");
109321
- sqlite3ExplainPop(pVdbe);
109322
-}
109323
-
109324
-/* End of the structure debug printing code
109325
-*****************************************************************************/
109326
-#endif /* defined(SQLITE_ENABLE_TREE_EXPLAIN) */
109506
+ sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
109507
+ sqlite3TreeViewExpr(pView, p->pOffset, 0);
109508
+ sqlite3TreeViewPop(pView);
109509
+ }
109510
+ if( p->pPrior ){
109511
+ const char *zOp = "UNION";
109512
+ switch( p->op ){
109513
+ case TK_ALL: zOp = "UNION ALL"; break;
109514
+ case TK_INTERSECT: zOp = "INTERSECT"; break;
109515
+ case TK_EXCEPT: zOp = "EXCEPT"; break;
109516
+ }
109517
+ sqlite3TreeViewItem(pView, zOp, (n--)>0);
109518
+ sqlite3TreeViewSelect(pView, p->pPrior, 0);
109519
+ sqlite3TreeViewPop(pView);
109520
+ }
109521
+ sqlite3TreeViewPop(pView);
109522
+}
109523
+#endif /* SQLITE_DEBUG */
109327109524
109328109525
/************** End of select.c **********************************************/
109329109526
/************** Begin file table.c *******************************************/
109330109527
/*
109331109528
** 2001 September 15
@@ -112311,10 +112508,11 @@
112311112508
}
112312112509
sqlite3DbFree(db, pVTable);
112313112510
}else if( ALWAYS(pVTable->pVtab) ){
112314112511
/* Justification of ALWAYS(): A correct vtab constructor must allocate
112315112512
** the sqlite3_vtab object if successful. */
112513
+ memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
112316112514
pVTable->pVtab->pModule = pMod->pModule;
112317112515
pVTable->nRef = 1;
112318112516
if( sCtx.pTab ){
112319112517
const char *zFormat = "vtable constructor did not declare schema: %s";
112320112518
*pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
@@ -113719,15 +113917,10 @@
113719113917
assert( TK_LE>TK_EQ && TK_LE<TK_GE );
113720113918
assert( TK_GE==TK_EQ+4 );
113721113919
return op==TK_IN || (op>=TK_EQ && op<=TK_GE) || op==TK_ISNULL;
113722113920
}
113723113921
113724
-/*
113725
-** Swap two objects of type TYPE.
113726
-*/
113727
-#define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
113728
-
113729113922
/*
113730113923
** Commute a comparison operator. Expressions of the form "X op Y"
113731113924
** are converted into "Y op X".
113732113925
**
113733113926
** If left/right precedence rules come into play when determining the
@@ -115566,21 +115759,28 @@
115566115759
** have been requested when testing key $P in whereEqualScanEst(). */
115567115760
whereKeyStats(pParse, p, pRec, 0, a);
115568115761
iLower = a[0];
115569115762
iUpper = a[0] + a[1];
115570115763
}
115764
+
115765
+ assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );
115766
+ assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
115767
+ assert( p->aSortOrder!=0 );
115768
+ if( p->aSortOrder[nEq] ){
115769
+ /* The roles of pLower and pUpper are swapped for a DESC index */
115770
+ SWAP(WhereTerm*, pLower, pUpper);
115771
+ }
115571115772
115572115773
/* If possible, improve on the iLower estimate using ($P:$L). */
115573115774
if( pLower ){
115574115775
int bOk; /* True if value is extracted from pExpr */
115575115776
Expr *pExpr = pLower->pExpr->pRight;
115576
- assert( (pLower->eOperator & (WO_GT|WO_GE))!=0 );
115577115777
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115578115778
if( rc==SQLITE_OK && bOk ){
115579115779
tRowcnt iNew;
115580115780
whereKeyStats(pParse, p, pRec, 0, a);
115581
- iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
115781
+ iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115582115782
if( iNew>iLower ) iLower = iNew;
115583115783
nOut--;
115584115784
pLower = 0;
115585115785
}
115586115786
}
@@ -115587,16 +115787,15 @@
115587115787
115588115788
/* If possible, improve on the iUpper estimate using ($P:$U). */
115589115789
if( pUpper ){
115590115790
int bOk; /* True if value is extracted from pExpr */
115591115791
Expr *pExpr = pUpper->pExpr->pRight;
115592
- assert( (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
115593115792
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115594115793
if( rc==SQLITE_OK && bOk ){
115595115794
tRowcnt iNew;
115596115795
whereKeyStats(pParse, p, pRec, 1, a);
115597
- iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
115796
+ iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115598115797
if( iNew<iUpper ) iUpper = iNew;
115599115798
nOut--;
115600115799
pUpper = 0;
115601115800
}
115602115801
}
@@ -116091,65 +116290,52 @@
116091116290
sqlite3StrAccumAppend(pStr, "?", 1);
116092116291
}
116093116292
116094116293
/*
116095116294
** Argument pLevel describes a strategy for scanning table pTab. This
116096
-** function returns a pointer to a string buffer containing a description
116097
-** of the subset of table rows scanned by the strategy in the form of an
116098
-** SQL expression. Or, if all rows are scanned, NULL is returned.
116295
+** function appends text to pStr that describes the subset of table
116296
+** rows scanned by the strategy in the form of an SQL expression.
116099116297
**
116100116298
** For example, if the query:
116101116299
**
116102116300
** SELECT * FROM t1 WHERE a=1 AND b>2;
116103116301
**
116104116302
** is run and there is an index on (a, b), then this function returns a
116105116303
** string similar to:
116106116304
**
116107116305
** "a=? AND b>?"
116108
-**
116109
-** The returned pointer points to memory obtained from sqlite3DbMalloc().
116110
-** It is the responsibility of the caller to free the buffer when it is
116111
-** no longer required.
116112116306
*/
116113
-static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
116307
+static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
116114116308
Index *pIndex = pLoop->u.btree.pIndex;
116115116309
u16 nEq = pLoop->u.btree.nEq;
116116116310
u16 nSkip = pLoop->u.btree.nSkip;
116117116311
int i, j;
116118116312
Column *aCol = pTab->aCol;
116119116313
i16 *aiColumn = pIndex->aiColumn;
116120
- StrAccum txt;
116121
-
116122
- if( nEq==0 && (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ){
116123
- return 0;
116124
- }
116125
- sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
116126
- txt.db = db;
116127
- sqlite3StrAccumAppend(&txt, " (", 2);
116314
+
116315
+ if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
116316
+ sqlite3StrAccumAppend(pStr, " (", 2);
116128116317
for(i=0; i<nEq; i++){
116129116318
char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
116130116319
if( i>=nSkip ){
116131
- explainAppendTerm(&txt, i, z, "=");
116320
+ explainAppendTerm(pStr, i, z, "=");
116132116321
}else{
116133
- if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
116134
- sqlite3StrAccumAppend(&txt, "ANY(", 4);
116135
- sqlite3StrAccumAppendAll(&txt, z);
116136
- sqlite3StrAccumAppend(&txt, ")", 1);
116322
+ if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
116323
+ sqlite3XPrintf(pStr, 0, "ANY(%s)", z);
116137116324
}
116138116325
}
116139116326
116140116327
j = i;
116141116328
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
116142116329
char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116143
- explainAppendTerm(&txt, i++, z, ">");
116330
+ explainAppendTerm(pStr, i++, z, ">");
116144116331
}
116145116332
if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
116146116333
char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116147
- explainAppendTerm(&txt, i, z, "<");
116334
+ explainAppendTerm(pStr, i, z, "<");
116148116335
}
116149
- sqlite3StrAccumAppend(&txt, ")", 1);
116150
- return sqlite3StrAccumFinish(&txt);
116336
+ sqlite3StrAccumAppend(pStr, ")", 1);
116151116337
}
116152116338
116153116339
/*
116154116340
** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116155116341
** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
@@ -116169,72 +116355,90 @@
116169116355
#endif
116170116356
{
116171116357
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116172116358
Vdbe *v = pParse->pVdbe; /* VM being constructed */
116173116359
sqlite3 *db = pParse->db; /* Database handle */
116174
- char *zMsg; /* Text to add to EQP output */
116175116360
int iId = pParse->iSelectId; /* Select id (left-most output column) */
116176116361
int isSearch; /* True for a SEARCH. False for SCAN. */
116177116362
WhereLoop *pLoop; /* The controlling WhereLoop object */
116178116363
u32 flags; /* Flags that describe this loop */
116364
+ char *zMsg; /* Text to add to EQP output */
116365
+ StrAccum str; /* EQP output string */
116366
+ char zBuf[100]; /* Initial space for EQP output string */
116179116367
116180116368
pLoop = pLevel->pWLoop;
116181116369
flags = pLoop->wsFlags;
116182116370
if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
116183116371
116184116372
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116185116373
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116186116374
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116187116375
116188
- zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
116376
+ sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
116377
+ str.db = db;
116378
+ sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
116189116379
if( pItem->pSelect ){
116190
- zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
116380
+ sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
116191116381
}else{
116192
- zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
116382
+ sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
116193116383
}
116194116384
116195116385
if( pItem->zAlias ){
116196
- zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
116197
- }
116198
- if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0
116199
- && ALWAYS(pLoop->u.btree.pIndex!=0)
116200
- ){
116201
- const char *zFmt;
116202
- Index *pIdx = pLoop->u.btree.pIndex;
116203
- char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
116386
+ sqlite3XPrintf(&str, 0, " AS %s", pItem->zAlias);
116387
+ }
116388
+ if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
116389
+ const char *zFmt = 0;
116390
+ Index *pIdx;
116391
+
116392
+ assert( pLoop->u.btree.pIndex!=0 );
116393
+ pIdx = pLoop->u.btree.pIndex;
116204116394
assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116205116395
if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116206
- zFmt = zWhere ? "%s USING PRIMARY KEY%.0s%s" : "%s%.0s%s";
116396
+ if( isSearch ){
116397
+ zFmt = "PRIMARY KEY";
116398
+ }
116207116399
}else if( flags & WHERE_AUTO_INDEX ){
116208
- zFmt = "%s USING AUTOMATIC COVERING INDEX%.0s%s";
116400
+ zFmt = "AUTOMATIC COVERING INDEX";
116209116401
}else if( flags & WHERE_IDX_ONLY ){
116210
- zFmt = "%s USING COVERING INDEX %s%s";
116402
+ zFmt = "COVERING INDEX %s";
116211116403
}else{
116212
- zFmt = "%s USING INDEX %s%s";
116404
+ zFmt = "INDEX %s";
116213116405
}
116214
- zMsg = sqlite3MAppendf(db, zMsg, zFmt, zMsg, pIdx->zName, zWhere);
116215
- sqlite3DbFree(db, zWhere);
116406
+ if( zFmt ){
116407
+ sqlite3StrAccumAppend(&str, " USING ", 7);
116408
+ sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
116409
+ explainIndexRange(&str, pLoop, pItem->pTab);
116410
+ }
116216116411
}else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
116217
- zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
116218
-
116412
+ const char *zRange;
116219116413
if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
116220
- zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
116414
+ zRange = "(rowid=?)";
116221116415
}else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
116222
- zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
116416
+ zRange = "(rowid>? AND rowid<?)";
116223116417
}else if( flags&WHERE_BTM_LIMIT ){
116224
- zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
116225
- }else if( ALWAYS(flags&WHERE_TOP_LIMIT) ){
116226
- zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
116418
+ zRange = "(rowid>?)";
116419
+ }else{
116420
+ assert( flags&WHERE_TOP_LIMIT);
116421
+ zRange = "(rowid<?)";
116227116422
}
116423
+ sqlite3StrAccumAppendAll(&str, " USING INTEGER PRIMARY KEY ");
116424
+ sqlite3StrAccumAppendAll(&str, zRange);
116228116425
}
116229116426
#ifndef SQLITE_OMIT_VIRTUALTABLE
116230116427
else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
116231
- zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
116428
+ sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
116232116429
pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
116233116430
}
116234116431
#endif
116235
- zMsg = sqlite3MAppendf(db, zMsg, "%s", zMsg);
116432
+#ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
116433
+ if( pLoop->nOut>=10 ){
116434
+ sqlite3XPrintf(&str, 0, " (~%llu rows)", sqlite3LogEstToInt(pLoop->nOut));
116435
+ }else{
116436
+ sqlite3StrAccumAppend(&str, " (~1 row)", 9);
116437
+ }
116438
+#endif
116439
+ zMsg = sqlite3StrAccumFinish(&str);
116236116440
sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116237116441
}
116238116442
}
116239116443
#else
116240116444
# define explainOneScan(u,v,w,x,y,z)
@@ -116884,12 +117088,13 @@
116884117088
116885117089
/* Run a separate WHERE clause for each term of the OR clause. After
116886117090
** eliminating duplicates from other WHERE clauses, the action for each
116887117091
** sub-WHERE clause is to to invoke the main loop body as a subroutine.
116888117092
*/
116889
- wctrlFlags = WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
116890
- WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY;
117093
+ wctrlFlags = WHERE_OMIT_OPEN_CLOSE
117094
+ | WHERE_FORCE_TABLE
117095
+ | WHERE_ONETABLE_ONLY;
116891117096
for(ii=0; ii<pOrWc->nTerm; ii++){
116892117097
WhereTerm *pOrTerm = &pOrWc->a[ii];
116893117098
if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
116894117099
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
116895117100
Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -116897,10 +117102,11 @@
116897117102
if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
116898117103
pAndExpr->pLeft = pOrExpr;
116899117104
pOrExpr = pAndExpr;
116900117105
}
116901117106
/* Loop through table entries that match term pOrTerm. */
117107
+ WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
116902117108
pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
116903117109
wctrlFlags, iCovCur);
116904117110
assert( pSubWInfo || pParse->nErr || db->mallocFailed );
116905117111
if( pSubWInfo ){
116906117112
WhereLoop *pSubLoop;
@@ -117116,25 +117322,30 @@
117116117322
}
117117117323
117118117324
return pLevel->notReady;
117119117325
}
117120117326
117121
-#if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
117327
+#ifdef WHERETRACE_ENABLED
117122117328
/*
117123
-** Generate "Explanation" text for a WhereTerm.
117329
+** Print the content of a WhereTerm object
117124117330
*/
117125
-static void whereExplainTerm(Vdbe *v, WhereTerm *pTerm){
117126
- char zType[4];
117127
- memcpy(zType, "...", 4);
117128
- if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
117129
- if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
117130
- if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
117131
- sqlite3ExplainPrintf(v, "%s ", zType);
117132
- sqlite3ExplainExpr(v, pTerm->pExpr);
117133
-}
117134
-#endif /* WHERETRACE_ENABLED && SQLITE_ENABLE_TREE_EXPLAIN */
117135
-
117331
+static void whereTermPrint(WhereTerm *pTerm, int iTerm){
117332
+ if( pTerm==0 ){
117333
+ sqlite3DebugPrintf("TERM-%-3d NULL\n", iTerm);
117334
+ }else{
117335
+ char zType[4];
117336
+ memcpy(zType, "...", 4);
117337
+ if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
117338
+ if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
117339
+ if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
117340
+ sqlite3DebugPrintf("TERM-%-3d %p %s cursor=%-3d prob=%-3d op=0x%03x\n",
117341
+ iTerm, pTerm, zType, pTerm->leftCursor, pTerm->truthProb,
117342
+ pTerm->eOperator);
117343
+ sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
117344
+ }
117345
+}
117346
+#endif
117136117347
117137117348
#ifdef WHERETRACE_ENABLED
117138117349
/*
117139117350
** Print a WhereLoop object for debugging purposes
117140117351
*/
@@ -117174,31 +117385,16 @@
117174117385
sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip);
117175117386
}else{
117176117387
sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
117177117388
}
117178117389
sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
117179
-#ifdef SQLITE_ENABLE_TREE_EXPLAIN
117180
- /* If the 0x100 bit of wheretracing is set, then show all of the constraint
117181
- ** expressions in the WhereLoop.aLTerm[] array.
117182
- */
117183
- if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ /* WHERETRACE 0x100 */
117390
+ if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
117184117391
int i;
117185
- Vdbe *v = pWInfo->pParse->pVdbe;
117186
- sqlite3ExplainBegin(v);
117187117392
for(i=0; i<p->nLTerm; i++){
117188
- WhereTerm *pTerm = p->aLTerm[i];
117189
- if( pTerm==0 ) continue;
117190
- sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
117191
- sqlite3ExplainPush(v);
117192
- whereExplainTerm(v, pTerm);
117193
- sqlite3ExplainPop(v);
117194
- sqlite3ExplainNL(v);
117195
- }
117196
- sqlite3ExplainFinish(v);
117197
- sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
117198
- }
117199
-#endif
117393
+ whereTermPrint(p->aLTerm[i], i);
117394
+ }
117395
+ }
117200117396
}
117201117397
#endif
117202117398
117203117399
/*
117204117400
** Convert bulk memory into a valid WhereLoop that can be passed
@@ -117507,11 +117703,11 @@
117507117703
if( ppPrev==0 ){
117508117704
/* There already exists a WhereLoop on the list that is better
117509117705
** than pTemplate, so just ignore pTemplate */
117510117706
#if WHERETRACE_ENABLED /* 0x8 */
117511117707
if( sqlite3WhereTrace & 0x8 ){
117512
- sqlite3DebugPrintf("ins-noop: ");
117708
+ sqlite3DebugPrintf(" skip: ");
117513117709
whereLoopPrint(pTemplate, pBuilder->pWC);
117514117710
}
117515117711
#endif
117516117712
return SQLITE_OK;
117517117713
}else{
@@ -117523,14 +117719,14 @@
117523117719
** WhereLoop and insert it.
117524117720
*/
117525117721
#if WHERETRACE_ENABLED /* 0x8 */
117526117722
if( sqlite3WhereTrace & 0x8 ){
117527117723
if( p!=0 ){
117528
- sqlite3DebugPrintf("ins-del: ");
117724
+ sqlite3DebugPrintf("replace: ");
117529117725
whereLoopPrint(p, pBuilder->pWC);
117530117726
}
117531
- sqlite3DebugPrintf("ins-new: ");
117727
+ sqlite3DebugPrintf(" add: ");
117532117728
whereLoopPrint(pTemplate, pBuilder->pWC);
117533117729
}
117534117730
#endif
117535117731
if( p==0 ){
117536117732
/* Allocate a new WhereLoop to add to the end of the list */
@@ -117550,11 +117746,11 @@
117550117746
pToDel = *ppTail;
117551117747
if( pToDel==0 ) break;
117552117748
*ppTail = pToDel->pNextLoop;
117553117749
#if WHERETRACE_ENABLED /* 0x8 */
117554117750
if( sqlite3WhereTrace & 0x8 ){
117555
- sqlite3DebugPrintf("ins-del: ");
117751
+ sqlite3DebugPrintf(" delete: ");
117556117752
whereLoopPrint(pToDel, pBuilder->pWC);
117557117753
}
117558117754
#endif
117559117755
whereLoopDelete(db, pToDel);
117560117756
}
@@ -117714,15 +117910,18 @@
117714117910
pNew->aLTerm[pNew->nLTerm++] = 0;
117715117911
pNew->wsFlags |= WHERE_SKIPSCAN;
117716117912
nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
117717117913
if( pTerm ){
117718117914
/* TUNING: When estimating skip-scan for a term that is also indexable,
117719
- ** increase the cost of the skip-scan by 2x, to make it a little less
117915
+ ** multiply the cost of the skip-scan by 2.0, to make it a little less
117720117916
** desirable than the regular index lookup. */
117721117917
nIter += 10; assert( 10==sqlite3LogEst(2) );
117722117918
}
117723117919
pNew->nOut -= nIter;
117920
+ /* TUNING: Because uncertainties in the estimates for skip-scan queries,
117921
+ ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
117922
+ nIter += 5;
117724117923
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
117725117924
pNew->nOut = saved_nOut;
117726117925
pNew->u.btree.nEq = saved_nEq;
117727117926
pNew->u.btree.nSkip = saved_nSkip;
117728117927
}
@@ -118073,13 +118272,21 @@
118073118272
pNew->u.btree.nSkip = 0;
118074118273
pNew->u.btree.pIndex = 0;
118075118274
pNew->nLTerm = 1;
118076118275
pNew->aLTerm[0] = pTerm;
118077118276
/* TUNING: One-time cost for computing the automatic index is
118078
- ** approximately 7*N*log2(N) where N is the number of rows in
118079
- ** the table being indexed. */
118080
- pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
118277
+ ** estimated to be X*N*log2(N) where N is the number of rows in
118278
+ ** the table being indexed and where X is 7 (LogEst=28) for normal
118279
+ ** tables or 1.375 (LogEst=4) for views and subqueries. The value
118280
+ ** of X is smaller for views and subqueries so that the query planner
118281
+ ** will be more aggressive about generating automatic indexes for
118282
+ ** those objects, since there is no opportunity to add schema
118283
+ ** indexes on subqueries and views. */
118284
+ pNew->rSetup = rLogSize + rSize + 4;
118285
+ if( pTab->pSelect==0 && (pTab->tabFlags & TF_Ephemeral)==0 ){
118286
+ pNew->rSetup += 24;
118287
+ }
118081118288
ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
118082118289
/* TUNING: Each index lookup yields 20 rows in the table. This
118083118290
** is more than the usual guess of 10 rows, since we have no way
118084118291
** of knowing how selective the index will ultimately be. It would
118085118292
** not be unreasonable to make this value much larger. */
@@ -118363,11 +118570,10 @@
118363118570
WhereLoopBuilder sSubBuild;
118364118571
WhereOrSet sSum, sCur;
118365118572
struct SrcList_item *pItem;
118366118573
118367118574
pWC = pBuilder->pWC;
118368
- if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
118369118575
pWCEnd = pWC->a + pWC->nTerm;
118370118576
pNew = pBuilder->pNew;
118371118577
memset(&sSum, 0, sizeof(sSum));
118372118578
pItem = pWInfo->pTabList->a + pNew->iTab;
118373118579
iCur = pItem->iCursor;
@@ -118384,10 +118590,11 @@
118384118590
118385118591
sSubBuild = *pBuilder;
118386118592
sSubBuild.pOrderBy = 0;
118387118593
sSubBuild.pOrSet = &sCur;
118388118594
118595
+ WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
118389118596
for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
118390118597
if( (pOrTerm->eOperator & WO_AND)!=0 ){
118391118598
sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
118392118599
}else if( pOrTerm->leftCursor==iCur ){
118393118600
tempWC.pWInfo = pWC->pWInfo;
@@ -118398,18 +118605,30 @@
118398118605
sSubBuild.pWC = &tempWC;
118399118606
}else{
118400118607
continue;
118401118608
}
118402118609
sCur.n = 0;
118610
+#ifdef WHERETRACE_ENABLED
118611
+ WHERETRACE(0x200, ("OR-term %d of %p has %d subterms:\n",
118612
+ (int)(pOrTerm-pOrWC->a), pTerm, sSubBuild.pWC->nTerm));
118613
+ if( sqlite3WhereTrace & 0x400 ){
118614
+ for(i=0; i<sSubBuild.pWC->nTerm; i++){
118615
+ whereTermPrint(&sSubBuild.pWC->a[i], i);
118616
+ }
118617
+ }
118618
+#endif
118403118619
#ifndef SQLITE_OMIT_VIRTUALTABLE
118404118620
if( IsVirtual(pItem->pTab) ){
118405118621
rc = whereLoopAddVirtual(&sSubBuild, mExtra);
118406118622
}else
118407118623
#endif
118408118624
{
118409118625
rc = whereLoopAddBtree(&sSubBuild, mExtra);
118410118626
}
118627
+ if( rc==SQLITE_OK ){
118628
+ rc = whereLoopAddOr(&sSubBuild, mExtra);
118629
+ }
118411118630
assert( rc==SQLITE_OK || sCur.n==0 );
118412118631
if( sCur.n==0 ){
118413118632
sSum.n = 0;
118414118633
break;
118415118634
}else if( once ){
@@ -118450,10 +118669,11 @@
118450118669
pNew->rRun = sSum.a[i].rRun + 1;
118451118670
pNew->nOut = sSum.a[i].nOut;
118452118671
pNew->prereq = sSum.a[i].prereq;
118453118672
rc = whereLoopInsert(pBuilder, pNew);
118454118673
}
118674
+ WHERETRACE(0x200, ("End processing OR-clause %p\n", pTerm));
118455118675
}
118456118676
}
118457118677
return rc;
118458118678
}
118459118679
@@ -118693,11 +118913,11 @@
118693118913
if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
118694118914
}
118695118915
isMatch = 1;
118696118916
break;
118697118917
}
118698
- if( isMatch && (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
118918
+ if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
118699118919
/* Make sure the sort order is compatible in an ORDER BY clause.
118700118920
** Sort order is irrelevant for a GROUP BY clause. */
118701118921
if( revSet ){
118702118922
if( (rev ^ revIdx)!=pOrderBy->a[i].sortOrder ) isMatch = 0;
118703118923
}else{
@@ -119158,16 +119378,19 @@
119158119378
pWInfo->revMask = pFrom->revLoop;
119159119379
}
119160119380
if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
119161119381
&& pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
119162119382
){
119163
- Bitmask notUsed = 0;
119383
+ Bitmask revMask = 0;
119164119384
int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
119165
- pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed
119385
+ pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
119166119386
);
119167119387
assert( pWInfo->sorted==0 );
119168
- pWInfo->sorted = (nOrder==pWInfo->pOrderBy->nExpr);
119388
+ if( nOrder==pWInfo->pOrderBy->nExpr ){
119389
+ pWInfo->sorted = 1;
119390
+ pWInfo->revMask = revMask;
119391
+ }
119169119392
}
119170119393
}
119171119394
119172119395
119173119396
pWInfo->nRowOut = pFrom->nRow;
@@ -119516,27 +119739,20 @@
119516119739
}
119517119740
}
119518119741
119519119742
/* Construct the WhereLoop objects */
119520119743
WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
119744
+#if defined(WHERETRACE_ENABLED)
119521119745
/* Display all terms of the WHERE clause */
119522
-#if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
119523119746
if( sqlite3WhereTrace & 0x100 ){
119524119747
int i;
119525
- Vdbe *v = pParse->pVdbe;
119526
- sqlite3ExplainBegin(v);
119527119748
for(i=0; i<sWLB.pWC->nTerm; i++){
119528
- sqlite3ExplainPrintf(v, "#%-2d ", i);
119529
- sqlite3ExplainPush(v);
119530
- whereExplainTerm(v, &sWLB.pWC->a[i]);
119531
- sqlite3ExplainPop(v);
119532
- sqlite3ExplainNL(v);
119533
- }
119534
- sqlite3ExplainFinish(v);
119535
- sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
119749
+ whereTermPrint(&sWLB.pWC->a[i], i);
119750
+ }
119536119751
}
119537119752
#endif
119753
+
119538119754
if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
119539119755
rc = whereLoopAddAll(&sWLB);
119540119756
if( rc ) goto whereBeginError;
119541119757
119542119758
/* Display all of the WhereLoop objects if wheretrace is enabled */
@@ -120059,11 +120275,11 @@
120059120275
120060120276
/* A routine to convert a binary TK_IS or TK_ISNOT expression into a
120061120277
** unary TK_ISNULL or TK_NOTNULL expression. */
120062120278
static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
120063120279
sqlite3 *db = pParse->db;
120064
- if( db->mallocFailed==0 && pY->op==TK_NULL ){
120280
+ if( pY && pA && pY->op==TK_NULL ){
120065120281
pA->op = (u8)op;
120066120282
sqlite3ExprDelete(db, pA->pRight);
120067120283
pA->pRight = 0;
120068120284
}
120069120285
}
@@ -122318,13 +122534,10 @@
122318122534
break;
122319122535
case 111: /* cmd ::= select */
122320122536
{
122321122537
SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
122322122538
sqlite3Select(pParse, yymsp[0].minor.yy3, &dest);
122323
- sqlite3ExplainBegin(pParse->pVdbe);
122324
- sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy3);
122325
- sqlite3ExplainFinish(pParse->pVdbe);
122326122539
sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
122327122540
}
122328122541
break;
122329122542
case 112: /* select ::= with selectnowith */
122330122543
{
@@ -122377,10 +122590,34 @@
122377122590
{yygotominor.yy328 = TK_ALL;}
122378122591
break;
122379122592
case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
122380122593
{
122381122594
yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy14,yymsp[-5].minor.yy65,yymsp[-4].minor.yy132,yymsp[-3].minor.yy14,yymsp[-2].minor.yy132,yymsp[-1].minor.yy14,yymsp[-7].minor.yy381,yymsp[0].minor.yy476.pLimit,yymsp[0].minor.yy476.pOffset);
122595
+#if SELECTTRACE_ENABLED
122596
+ /* Populate the Select.zSelName[] string that is used to help with
122597
+ ** query planner debugging, to differentiate between multiple Select
122598
+ ** objects in a complex query.
122599
+ **
122600
+ ** If the SELECT keyword is immediately followed by a C-style comment
122601
+ ** then extract the first few alphanumeric characters from within that
122602
+ ** comment to be the zSelName value. Otherwise, the label is #N where
122603
+ ** is an integer that is incremented with each SELECT statement seen.
122604
+ */
122605
+ if( yygotominor.yy3!=0 ){
122606
+ const char *z = yymsp[-8].minor.yy0.z+6;
122607
+ int i;
122608
+ sqlite3_snprintf(sizeof(yygotominor.yy3->zSelName), yygotominor.yy3->zSelName, "#%d",
122609
+ ++pParse->nSelect);
122610
+ while( z[0]==' ' ) z++;
122611
+ if( z[0]=='/' && z[1]=='*' ){
122612
+ z += 2;
122613
+ while( z[0]==' ' ) z++;
122614
+ for(i=0; sqlite3Isalnum(z[i]); i++){}
122615
+ sqlite3_snprintf(sizeof(yygotominor.yy3->zSelName), yygotominor.yy3->zSelName, "%.*s", i, z);
122616
+ }
122617
+ }
122618
+#endif /* SELECTRACE_ENABLED */
122382122619
}
122383122620
break;
122384122621
case 120: /* values ::= VALUES LP nexprlist RP */
122385122622
{
122386122623
yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
@@ -123868,10 +124105,11 @@
123868124105
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */
123869124106
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */
123870124107
};
123871124108
#define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
123872124109
#endif
124110
+SQLITE_PRIVATE int sqlite3IsIdChar(u8 c){ return IdChar(c); }
123873124111
123874124112
123875124113
/*
123876124114
** Return the length of the token that begins at z[0].
123877124115
** Store the token type in *tokenType before returning.
@@ -125138,10 +125376,15 @@
125138125376
sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
125139125377
sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
125140125378
break;
125141125379
}
125142125380
125381
+ /* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
125382
+ ** can be changed at start-time using the
125383
+ ** sqlite3_config(SQLITE_CONFIG_URI,1) or
125384
+ ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
125385
+ */
125143125386
case SQLITE_CONFIG_URI: {
125144125387
sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
125145125388
break;
125146125389
}
125147125390
@@ -126875,11 +127118,11 @@
126875127118
int nUri = sqlite3Strlen30(zUri);
126876127119
126877127120
assert( *pzErrMsg==0 );
126878127121
126879127122
if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
126880
- && nUri>=5 && memcmp(zUri, "file:", 5)==0
127123
+ && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
126881127124
){
126882127125
char *zOpt;
126883127126
int eState; /* Parser state when parsing URI */
126884127127
int iIn; /* Input character index */
126885127128
int iOut = 0; /* Output character index */
@@ -127105,11 +127348,13 @@
127105127348
assert( SQLITE_OPEN_READWRITE == 0x02 );
127106127349
assert( SQLITE_OPEN_CREATE == 0x04 );
127107127350
testcase( (1<<(flags&7))==0x02 ); /* READONLY */
127108127351
testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
127109127352
testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
127110
- if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE_BKPT;
127353
+ if( ((1<<(flags&7)) & 0x46)==0 ){
127354
+ return SQLITE_MISUSE_BKPT; /* IMP: R-65497-44594 */
127355
+ }
127111127356
127112127357
if( sqlite3GlobalConfig.bCoreMutex==0 ){
127113127358
isThreadsafe = 0;
127114127359
}else if( flags & SQLITE_OPEN_NOMUTEX ){
127115127360
isThreadsafe = 0;
@@ -127989,26 +128234,10 @@
127989128234
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
127990128235
sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
127991128236
break;
127992128237
}
127993128238
127994
-#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
127995
- /* sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT,
127996
- ** sqlite3_stmt*,const char**);
127997
- **
127998
- ** If compiled with SQLITE_ENABLE_TREE_EXPLAIN, each sqlite3_stmt holds
127999
- ** a string that describes the optimized parse tree. This test-control
128000
- ** returns a pointer to that string.
128001
- */
128002
- case SQLITE_TESTCTRL_EXPLAIN_STMT: {
128003
- sqlite3_stmt *pStmt = va_arg(ap, sqlite3_stmt*);
128004
- const char **pzRet = va_arg(ap, const char**);
128005
- *pzRet = sqlite3VdbeExplanation((Vdbe*)pStmt);
128006
- break;
128007
- }
128008
-#endif
128009
-
128010128239
/* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
128011128240
**
128012128241
** Set or clear a flag that indicates that the database file is always well-
128013128242
** formed and never corrupt. This flag is clear by default, indicating that
128014128243
** database files might have arbitrary corruption. Setting the flag during
@@ -132464,10 +132693,11 @@
132464132693
assert( iIdx==nVal );
132465132694
132466132695
/* In case the cursor has been used before, clear it now. */
132467132696
sqlite3_finalize(pCsr->pStmt);
132468132697
sqlite3_free(pCsr->aDoclist);
132698
+ sqlite3_free(pCsr->aMatchinfo);
132469132699
sqlite3Fts3ExprFree(pCsr->pExpr);
132470132700
memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
132471132701
132472132702
/* Set the lower and upper bounds on docids to return */
132473132703
pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
@@ -133774,11 +134004,11 @@
133774134004
if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
133775134005
iMax = a[i].iDocid;
133776134006
bMaxSet = 1;
133777134007
}
133778134008
}
133779
- assert( rc!=SQLITE_OK || a[p->nToken-1].bIgnore==0 );
134009
+ assert( rc!=SQLITE_OK || (p->nToken>=1 && a[p->nToken-1].bIgnore==0) );
133780134010
assert( rc!=SQLITE_OK || bMaxSet );
133781134011
133782134012
/* Keep advancing iterators until they all point to the same document */
133783134013
for(i=0; i<p->nToken; i++){
133784134014
while( rc==SQLITE_OK && bEof==0
@@ -135891,11 +136121,11 @@
135891136121
int i = 0;
135892136122
135893136123
/* Set variable i to the maximum number of bytes of input to tokenize. */
135894136124
for(i=0; i<n; i++){
135895136125
if( sqlite3_fts3_enable_parentheses && (z[i]=='(' || z[i]==')') ) break;
135896
- if( z[i]=='*' || z[i]=='"' ) break;
136126
+ if( z[i]=='"' ) break;
135897136127
}
135898136128
135899136129
*pnConsumed = i;
135900136130
rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, i, &pCursor);
135901136131
if( rc==SQLITE_OK ){
135902136132
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.7"
235 #define SQLITE_VERSION_NUMBER 3008007
236 #define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -2791,13 +2791,13 @@
2791 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
2792 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
2793 ** an English language description of the error following a failure of any
2794 ** of the sqlite3_open() routines.
2795 **
2796 ** ^The default encoding for the database will be UTF-8 if
2797 ** sqlite3_open() or sqlite3_open_v2() is called and
2798 ** UTF-16 in the native byte order if sqlite3_open16() is used.
2799 **
2800 ** Whether or not an error occurs when it is opened, resources
2801 ** associated with the [database connection] handle should be released by
2802 ** passing it to [sqlite3_close()] when it is no longer required.
2803 **
@@ -2881,17 +2881,18 @@
2881 ** ^SQLite uses the path component of the URI as the name of the disk file
2882 ** which contains the database. ^If the path begins with a '/' character,
2883 ** then it is interpreted as an absolute path. ^If the path does not begin
2884 ** with a '/' (meaning that the authority section is omitted from the URI)
2885 ** then the path is interpreted as a relative path.
2886 ** ^On windows, the first component of an absolute path
2887 ** is a drive specification (e.g. "C:").
2888 **
2889 ** [[core URI query parameters]]
2890 ** The query component of a URI may contain parameters that are interpreted
2891 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
2892 ** SQLite interprets the following three query parameters:
 
2893 **
2894 ** <ul>
2895 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
2896 ** a VFS object that provides the operating system interface that should
2897 ** be used to access the database file on disk. ^If this option is set to
@@ -2922,15 +2923,13 @@
2922 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2923 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2924 ** a URI filename, its value overrides any behavior requested by setting
2925 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2926 **
2927 ** <li> <b>psow</b>: ^The psow parameter may be "true" (or "on" or "yes" or
2928 ** "1") or "false" (or "off" or "no" or "0") to indicate that the
2929 ** [powersafe overwrite] property does or does not apply to the
2930 ** storage media on which the database file resides. ^The psow query
2931 ** parameter only works for the built-in unix and Windows VFSes.
2932 **
2933 ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
2934 ** which if set disables file locking in rollback journal modes. This
2935 ** is useful for accessing a database on a filesystem that does not
2936 ** support locking. Caution: Database corruption might result if two
@@ -3521,15 +3520,14 @@
3521 ** terminated. If any NUL characters occur at byte offsets less than
3522 ** the value of the fourth parameter then the resulting string value will
3523 ** contain embedded NULs. The result of expressions involving strings
3524 ** with embedded NULs is undefined.
3525 **
3526 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3527 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3528 ** string after SQLite has finished with it. ^The destructor is called
3529 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
3530 ** sqlite3_bind_text(), or sqlite3_bind_text16() fails.
3531 ** ^If the fifth argument is
3532 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3533 ** information is in static, unmanaged space and does not need to be freed.
3534 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3535 ** SQLite makes its own private copy of the data immediately, before
@@ -3536,11 +3534,11 @@
3536 ** the sqlite3_bind_*() routine returns.
3537 **
3538 ** ^The sixth argument to sqlite3_bind_text64() must be one of
3539 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3540 ** to specify the encoding of the text in the third parameter. If
3541 ** the sixth argument to sqlite3_bind_text64() is not how of the
3542 ** allowed values shown above, or if the text encoding is different
3543 ** from the encoding specified by the sixth parameter, then the behavior
3544 ** is undefined.
3545 **
3546 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
@@ -4572,11 +4570,11 @@
4572 **
4573 ** ^The sqlite3_result_null() interface sets the return value
4574 ** of the application-defined function to be NULL.
4575 **
4576 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4577 ** sqlite3_result_text16le(), and sqlite3_result_text16be()
4578 ** set the return value of the application-defined function to be
4579 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4580 ** UTF-16 little endian, or UTF-16 big endian, respectively.
4581 ** ^The sqlite3_result_text64() interface sets the return value of an
4582 ** application-defined function to be a text string in an encoding
@@ -6332,11 +6330,11 @@
6332 #define SQLITE_TESTCTRL_RESERVE 14
6333 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6334 #define SQLITE_TESTCTRL_ISKEYWORD 16
6335 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6336 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6337 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6338 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6339 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6340 #define SQLITE_TESTCTRL_BYTEORDER 22
6341 #define SQLITE_TESTCTRL_ISINIT 23
6342 #define SQLITE_TESTCTRL_SORTER_MMAP 24
@@ -7946,11 +7944,11 @@
7946 ** A macro to hint to the compiler that a function should not be
7947 ** inlined.
7948 */
7949 #if defined(__GNUC__)
7950 # define SQLITE_NOINLINE __attribute__((noinline))
7951 #elif defined(_MSC_VER)
7952 # define SQLITE_NOINLINE __declspec(noinline)
7953 #else
7954 # define SQLITE_NOINLINE
7955 #endif
7956
@@ -8519,10 +8517,15 @@
8519 ** Macros to compute minimum and maximum of two numbers.
8520 */
8521 #define MIN(A,B) ((A)<(B)?(A):(B))
8522 #define MAX(A,B) ((A)>(B)?(A):(B))
8523
 
 
 
 
 
8524 /*
8525 ** Check to see if this machine uses EBCDIC. (Yes, believe it or
8526 ** not, there are still machines out there that use EBCDIC.)
8527 */
8528 #if 'A' == '\301'
@@ -8756,10 +8759,20 @@
8756 # define SQLITE_ENABLE_STAT3_OR_STAT4 1
8757 #elif SQLITE_ENABLE_STAT3_OR_STAT4
8758 # undef SQLITE_ENABLE_STAT3_OR_STAT4
8759 #endif
8760
 
 
 
 
 
 
 
 
 
 
8761 /*
8762 ** An instance of the following structure is used to store the busy-handler
8763 ** callback for a given sqlite handle.
8764 **
8765 ** The sqlite.busyHandler member of the sqlite struct contains the busy
@@ -8895,10 +8908,11 @@
8895 typedef struct SrcList SrcList;
8896 typedef struct StrAccum StrAccum;
8897 typedef struct Table Table;
8898 typedef struct TableLock TableLock;
8899 typedef struct Token Token;
 
8900 typedef struct Trigger Trigger;
8901 typedef struct TriggerPrg TriggerPrg;
8902 typedef struct TriggerStep TriggerStep;
8903 typedef struct UnpackedRecord UnpackedRecord;
8904 typedef struct VTable VTable;
@@ -11308,10 +11322,11 @@
11308 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
11309 int nSample; /* Number of elements in aSample[] */
11310 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
11311 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11312 IndexSample *aSample; /* Samples of the left-most key */
 
11313 #endif
11314 };
11315
11316 /*
11317 ** Allowed values for Index.idxType
@@ -11738,11 +11753,11 @@
11738 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
11739 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
11740 #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
11741 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
11742 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11743 #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
11744 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
11745 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
11746 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
11747 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
11748 #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
@@ -11823,10 +11838,13 @@
11823 struct Select {
11824 ExprList *pEList; /* The fields of the result */
11825 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
11826 u16 selFlags; /* Various SF_* values */
11827 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
 
 
 
11828 int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
11829 u64 nSelectRow; /* Estimated number of result rows */
11830 SrcList *pSrc; /* The FROM clause */
11831 Expr *pWhere; /* The WHERE clause */
11832 ExprList *pGroupBy; /* The GROUP BY clause */
@@ -12081,10 +12099,14 @@
12081 yDbMask cookieMask; /* Bitmask of schema verified databases */
12082 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
12083 int regRowid; /* Register holding rowid of CREATE TABLE entry */
12084 int regRoot; /* Register holding root page number for new objects */
12085 int nMaxArg; /* Max args passed to user function by sub-program */
 
 
 
 
12086 #ifndef SQLITE_OMIT_SHARED_CACHE
12087 int nTableLock; /* Number of locks in aTableLock */
12088 TableLock *aTableLock; /* Required table locks for shared-cache mode */
12089 #endif
12090 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -12160,15 +12182,15 @@
12160
12161 /*
12162 ** Bitfield flags for P5 value in various opcodes.
12163 */
12164 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
 
12165 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
12166 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
12167 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
12168 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
12169 #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */
12170 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
12171 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
12172 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
12173 #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */
12174 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
@@ -12428,10 +12450,21 @@
12428 Select *pSelect; /* The definition of this CTE */
12429 const char *zErr; /* Error message for circular references */
12430 } a[1];
12431 };
12432
 
 
 
 
 
 
 
 
 
 
 
12433 /*
12434 ** Assuming zIn points to the first byte of a UTF-8 character,
12435 ** advance zIn to point to the first byte of the next UTF-8 character.
12436 */
12437 #define SQLITE_SKIP_UTF8(zIn) { \
@@ -12493,10 +12526,11 @@
12493 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
12494 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
12495 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
12496 # define sqlite3Tolower(x) tolower((unsigned char)(x))
12497 #endif
 
12498
12499 /*
12500 ** Internal function prototypes
12501 */
12502 #define sqlite3StrICmp sqlite3_stricmp
@@ -12591,29 +12625,18 @@
12591 #endif
12592 #if defined(SQLITE_TEST)
12593 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
12594 #endif
12595
12596 /* Output formatting for SQLITE_TESTCTRL_EXPLAIN */
12597 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
12598 SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe*);
12599 SQLITE_PRIVATE void sqlite3ExplainPrintf(Vdbe*, const char*, ...);
12600 SQLITE_PRIVATE void sqlite3ExplainNL(Vdbe*);
12601 SQLITE_PRIVATE void sqlite3ExplainPush(Vdbe*);
12602 SQLITE_PRIVATE void sqlite3ExplainPop(Vdbe*);
12603 SQLITE_PRIVATE void sqlite3ExplainFinish(Vdbe*);
12604 SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe*, Select*);
12605 SQLITE_PRIVATE void sqlite3ExplainExpr(Vdbe*, Expr*);
12606 SQLITE_PRIVATE void sqlite3ExplainExprList(Vdbe*, ExprList*);
12607 SQLITE_PRIVATE const char *sqlite3VdbeExplanation(Vdbe*);
12608 #else
12609 # define sqlite3ExplainBegin(X)
12610 # define sqlite3ExplainSelect(A,B)
12611 # define sqlite3ExplainExpr(A,B)
12612 # define sqlite3ExplainExprList(A,B)
12613 # define sqlite3ExplainFinish(X)
12614 # define sqlite3VdbeExplanation(X) 0
12615 #endif
12616
12617
12618 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*, ...);
12619 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -12791,11 +12814,11 @@
12791 SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
12792 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
12793 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
12794 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12795 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12796 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
12797 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12798 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12799 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12800 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12801 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -12815,10 +12838,15 @@
12815 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
12816 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
12817 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
12818 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*);
12819 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int);
 
 
 
 
 
12820 SQLITE_PRIVATE void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*);
12821 SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8);
12822 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3*);
12823 SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void);
12824 SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void);
@@ -13292,14 +13320,13 @@
13292 # define sqlite3MemdebugSetType(X,Y) /* no-op */
13293 # define sqlite3MemdebugHasType(X,Y) 1
13294 # define sqlite3MemdebugNoType(X,Y) 1
13295 #endif
13296 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
13297 #define MEMTYPE_LOOKASIDE 0x02 /* Might have been lookaside memory */
13298 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
13299 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
13300 #define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
13301
13302 /*
13303 ** Threading interface
13304 */
13305 #if SQLITE_MAX_WORKER_THREADS>0
@@ -13439,10 +13466,17 @@
13439 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
13440 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
13441 };
13442 #endif
13443
 
 
 
 
 
 
 
13444 #ifndef SQLITE_USE_URI
13445 # define SQLITE_USE_URI 0
13446 #endif
13447
13448 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
@@ -13945,11 +13979,11 @@
13945
13946 /* Since ArraySize(azCompileOpt) is normally in single digits, a
13947 ** linear search is adequate. No need for a binary search. */
13948 for(i=0; i<ArraySize(azCompileOpt); i++){
13949 if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
13950 && sqlite3CtypeMap[(unsigned char)azCompileOpt[i][n]]==0
13951 ){
13952 return 1;
13953 }
13954 }
13955 return 0;
@@ -14060,21 +14094,19 @@
14060 #ifdef SQLITE_DEBUG
14061 u8 seekOp; /* Most recent seek operation on this cursor */
14062 #endif
14063 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
14064 u8 nullRow; /* True if pointing to a row with no data */
14065 u8 rowidIsValid; /* True if lastRowid is valid */
14066 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
14067 Bool isEphemeral:1; /* True for an ephemeral table */
14068 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
14069 Bool isTable:1; /* True if a table requiring integer keys */
14070 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
14071 Pgno pgnoRoot; /* Root page of the open btree cursor */
14072 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
14073 i64 seqCount; /* Sequence counter */
14074 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
14075 i64 lastRowid; /* Rowid being deleted by OP_Delete */
14076 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
14077
14078 /* Cached information about the header for the data record that the
14079 ** cursor is currently pointing to. Only valid if cacheStatus matches
14080 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -14087,10 +14119,11 @@
14087 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
14088 u32 payloadSize; /* Total number of bytes in the record */
14089 u32 szRow; /* Byte available in aRow */
14090 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
14091 const u8 *aRow; /* Data for the current row, if all on one page */
 
14092 u32 aType[1]; /* Type values for all entries in the record */
14093 /* 2*nField extra array elements allocated for aType[], beyond the one
14094 ** static element declared in the structure. nField total array slots for
14095 ** aType[] and nField+1 array slots for aOffset[] */
14096 };
@@ -14163,11 +14196,11 @@
14163 int n; /* Number of characters in string value, excluding '\0' */
14164 char *z; /* String or BLOB value */
14165 /* ShallowCopy only needs to copy the information above */
14166 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
14167 int szMalloc; /* Size of the zMalloc allocation */
14168 int iPadding1; /* Padding for 8-byte alignment */
14169 sqlite3 *db; /* The associated database connection */
14170 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
14171 #ifdef SQLITE_DEBUG
14172 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
14173 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
@@ -14259,11 +14292,10 @@
14259 */
14260 struct sqlite3_context {
14261 Mem *pOut; /* The return value is stored here */
14262 FuncDef *pFunc; /* Pointer to function information */
14263 Mem *pMem; /* Memory cell used to store aggregate context */
14264 CollSeq *pColl; /* Collating sequence */
14265 Vdbe *pVdbe; /* The VM that owns this context */
14266 int iOp; /* Instruction number of OP_Function */
14267 int isError; /* Error code returned by the function. */
14268 u8 skipFlag; /* Skip accumulator loading if true */
14269 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
@@ -14348,14 +14380,10 @@
14348 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
14349 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
14350 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
14351 char *zSql; /* Text of the SQL statement that generated this */
14352 void *pFree; /* Free this when deleting the vdbe */
14353 #ifdef SQLITE_ENABLE_TREE_EXPLAIN
14354 Explain *pExplain; /* The explainer */
14355 char *zExplain; /* Explanation of data structures */
14356 #endif
14357 VdbeFrame *pFrame; /* Parent frame */
14358 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */
14359 int nFrame; /* Number of frames in pFrame list */
14360 u32 expmask; /* Binding to these vars invalidates VM */
14361 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
@@ -14376,10 +14404,11 @@
14376 ** Function prototypes
14377 */
14378 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
14379 void sqliteVdbePopStack(Vdbe*,int);
14380 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
 
14381 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
14382 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
14383 #endif
14384 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
14385 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
@@ -14675,11 +14704,11 @@
14675 sqlite3VdbeClearObject(db, pVdbe);
14676 sqlite3DbFree(db, pVdbe);
14677 }
14678 db->pnBytesFreed = 0;
14679
14680 *pHighwater = 0;
14681 *pCurrent = nByte;
14682
14683 break;
14684 }
14685
@@ -14700,21 +14729,23 @@
14700 if( db->aDb[i].pBt ){
14701 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
14702 sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet);
14703 }
14704 }
14705 *pHighwater = 0;
 
 
14706 *pCurrent = nRet;
14707 break;
14708 }
14709
14710 /* Set *pCurrent to non-zero if there are unresolved deferred foreign
14711 ** key constraints. Set *pCurrent to zero if all foreign key constraints
14712 ** have been satisfied. The *pHighwater is always set to zero.
14713 */
14714 case SQLITE_DBSTATUS_DEFERRED_FKS: {
14715 *pHighwater = 0;
14716 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
14717 break;
14718 }
14719
14720 default: {
@@ -17098,11 +17129,11 @@
17098 ** allocation p. Also return true if p==NULL.
17099 **
17100 ** This routine is designed for use within an assert() statement, to
17101 ** verify the type of an allocation. For example:
17102 **
17103 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17104 */
17105 SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
17106 int rc = 1;
17107 if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
17108 struct MemBlockHdr *pHdr;
@@ -17120,11 +17151,11 @@
17120 ** allocation p. Also return true if p==NULL.
17121 **
17122 ** This routine is designed for use within an assert() statement, to
17123 ** verify the type of an allocation. For example:
17124 **
17125 ** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
17126 */
17127 SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
17128 int rc = 1;
17129 if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
17130 struct MemBlockHdr *pHdr;
@@ -20195,11 +20226,11 @@
20195 mallocWithAlarm((int)n, &p);
20196 sqlite3_mutex_leave(mem0.mutex);
20197 }else{
20198 p = sqlite3GlobalConfig.m.xMalloc((int)n);
20199 }
20200 assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */
20201 return p;
20202 }
20203
20204 /*
20205 ** This version of the memory allocation is for use by the application.
@@ -20332,39 +20363,41 @@
20332 ** Return the size of a memory allocation previously obtained from
20333 ** sqlite3Malloc() or sqlite3_malloc().
20334 */
20335 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
20336 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20337 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
20338 return sqlite3GlobalConfig.m.xSize(p);
20339 }
20340 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20341 if( db==0 ){
 
 
20342 return sqlite3MallocSize(p);
20343 }else{
20344 assert( sqlite3_mutex_held(db->mutex) );
20345 if( isLookaside(db, p) ){
20346 return db->lookaside.sz;
20347 }else{
20348 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20349 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20350 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20351 return sqlite3GlobalConfig.m.xSize(p);
20352 }
20353 }
20354 }
20355 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
 
 
20356 return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
20357 }
20358
20359 /*
20360 ** Free memory previously obtained from sqlite3Malloc().
20361 */
20362 SQLITE_API void sqlite3_free(void *p){
20363 if( p==0 ) return; /* IMP: R-49053-54554 */
20364 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
20365 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 
20366 if( sqlite3GlobalConfig.bMemstat ){
20367 sqlite3_mutex_enter(mem0.mutex);
20368 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
20369 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
20370 sqlite3GlobalConfig.m.xFree(p);
@@ -20404,12 +20437,12 @@
20404 db->lookaside.pFree = pBuf;
20405 db->lookaside.nOut--;
20406 return;
20407 }
20408 }
20409 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20410 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20411 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20412 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20413 sqlite3_free(p);
20414 }
20415
@@ -20417,15 +20450,17 @@
20417 ** Change the size of an existing memory allocation
20418 */
20419 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
20420 int nOld, nNew, nDiff;
20421 void *pNew;
 
 
20422 if( pOld==0 ){
20423 return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
20424 }
20425 if( nBytes==0 ){
20426 sqlite3_free(pOld); /* IMP: R-31593-10574 */
20427 return 0;
20428 }
20429 if( nBytes>=0x7fffff00 ){
20430 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
20431 return 0;
@@ -20443,12 +20478,10 @@
20443 nDiff = nNew - nOld;
20444 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
20445 mem0.alarmThreshold-nDiff ){
20446 sqlite3MallocAlarm(nDiff);
20447 }
20448 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20449 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
20450 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20451 if( pNew==0 && mem0.alarmCallback ){
20452 sqlite3MallocAlarm((int)nBytes);
20453 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20454 }
@@ -20458,11 +20491,11 @@
20458 }
20459 sqlite3_mutex_leave(mem0.mutex);
20460 }else{
20461 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20462 }
20463 assert( EIGHT_BYTE_ALIGNMENT(pNew) ); /* IMP: R-04675-44850 */
20464 return pNew;
20465 }
20466
20467 /*
20468 ** The public interface to sqlite3Realloc. Make sure that the memory
@@ -20470,11 +20503,11 @@
20470 */
20471 SQLITE_API void *sqlite3_realloc(void *pOld, int n){
20472 #ifndef SQLITE_OMIT_AUTOINIT
20473 if( sqlite3_initialize() ) return 0;
20474 #endif
20475 if( n<0 ) n = 0;
20476 return sqlite3Realloc(pOld, n);
20477 }
20478 SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
20479 #ifndef SQLITE_OMIT_AUTOINIT
20480 if( sqlite3_initialize() ) return 0;
@@ -20557,12 +20590,12 @@
20557 #endif
20558 p = sqlite3Malloc(n);
20559 if( !p && db ){
20560 db->mallocFailed = 1;
20561 }
20562 sqlite3MemdebugSetType(p, MEMTYPE_DB |
20563 ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20564 return p;
20565 }
20566
20567 /*
20568 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -20584,19 +20617,18 @@
20584 if( pNew ){
20585 memcpy(pNew, p, db->lookaside.sz);
20586 sqlite3DbFree(db, p);
20587 }
20588 }else{
20589 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20590 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20591 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20592 pNew = sqlite3_realloc64(p, n);
20593 if( !pNew ){
20594 sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
20595 db->mallocFailed = 1;
20596 }
20597 sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
20598 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20599 }
20600 }
20601 return pNew;
20602 }
@@ -21757,10 +21789,73 @@
21757 fprintf(stdout,"%s", zBuf);
21758 fflush(stdout);
21759 }
21760 #endif
21761
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21762 /*
21763 ** variable-argument wrapper around sqlite3VXPrintf().
21764 */
21765 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
21766 va_list ap;
@@ -22003,11 +22098,11 @@
22003 #define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
22004 #include <process.h>
22005
22006 /* A running thread */
22007 struct SQLiteThread {
22008 uintptr_t tid; /* The thread handle */
22009 unsigned id; /* The thread identifier */
22010 void *(*xTask)(void*); /* The routine to run as a thread */
22011 void *pIn; /* Argument to xTask */
22012 void *pResult; /* Result of xTask */
22013 };
@@ -22051,11 +22146,11 @@
22051 if( sqlite3GlobalConfig.bCoreMutex==0 ){
22052 memset(p, 0, sizeof(*p));
22053 }else{
22054 p->xTask = xTask;
22055 p->pIn = pIn;
22056 p->tid = _beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
22057 if( p->tid==0 ){
22058 memset(p, 0, sizeof(*p));
22059 }
22060 }
22061 if( p->xTask==0 ){
@@ -29659,11 +29754,11 @@
29659 ** methods CLOSE, LOCK, UNLOCK, CKRESLOCK.
29660 **
29661 ** * An I/O method finder function called FINDER that returns a pointer
29662 ** to the METHOD object in the previous bullet.
29663 */
29664 #define IOMETHODS(FINDER, METHOD, VERSION, CLOSE, LOCK, UNLOCK, CKLOCK) \
29665 static const sqlite3_io_methods METHOD = { \
29666 VERSION, /* iVersion */ \
29667 CLOSE, /* xClose */ \
29668 unixRead, /* xRead */ \
29669 unixWrite, /* xWrite */ \
@@ -29674,11 +29769,11 @@
29674 UNLOCK, /* xUnlock */ \
29675 CKLOCK, /* xCheckReservedLock */ \
29676 unixFileControl, /* xFileControl */ \
29677 unixSectorSize, /* xSectorSize */ \
29678 unixDeviceCharacteristics, /* xDeviceCapabilities */ \
29679 unixShmMap, /* xShmMap */ \
29680 unixShmLock, /* xShmLock */ \
29681 unixShmBarrier, /* xShmBarrier */ \
29682 unixShmUnmap, /* xShmUnmap */ \
29683 unixFetch, /* xFetch */ \
29684 unixUnfetch, /* xUnfetch */ \
@@ -29700,29 +29795,32 @@
29700 posixIoMethods, /* sqlite3_io_methods object name */
29701 3, /* shared memory and mmap are enabled */
29702 unixClose, /* xClose method */
29703 unixLock, /* xLock method */
29704 unixUnlock, /* xUnlock method */
29705 unixCheckReservedLock /* xCheckReservedLock method */
 
29706 )
29707 IOMETHODS(
29708 nolockIoFinder, /* Finder function name */
29709 nolockIoMethods, /* sqlite3_io_methods object name */
29710 3, /* shared memory is disabled */
29711 nolockClose, /* xClose method */
29712 nolockLock, /* xLock method */
29713 nolockUnlock, /* xUnlock method */
29714 nolockCheckReservedLock /* xCheckReservedLock method */
 
29715 )
29716 IOMETHODS(
29717 dotlockIoFinder, /* Finder function name */
29718 dotlockIoMethods, /* sqlite3_io_methods object name */
29719 1, /* shared memory is disabled */
29720 dotlockClose, /* xClose method */
29721 dotlockLock, /* xLock method */
29722 dotlockUnlock, /* xUnlock method */
29723 dotlockCheckReservedLock /* xCheckReservedLock method */
 
29724 )
29725
29726 #if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
29727 IOMETHODS(
29728 flockIoFinder, /* Finder function name */
@@ -29729,11 +29827,12 @@
29729 flockIoMethods, /* sqlite3_io_methods object name */
29730 1, /* shared memory is disabled */
29731 flockClose, /* xClose method */
29732 flockLock, /* xLock method */
29733 flockUnlock, /* xUnlock method */
29734 flockCheckReservedLock /* xCheckReservedLock method */
 
29735 )
29736 #endif
29737
29738 #if OS_VXWORKS
29739 IOMETHODS(
@@ -29741,11 +29840,12 @@
29741 semIoMethods, /* sqlite3_io_methods object name */
29742 1, /* shared memory is disabled */
29743 semClose, /* xClose method */
29744 semLock, /* xLock method */
29745 semUnlock, /* xUnlock method */
29746 semCheckReservedLock /* xCheckReservedLock method */
 
29747 )
29748 #endif
29749
29750 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
29751 IOMETHODS(
@@ -29753,11 +29853,12 @@
29753 afpIoMethods, /* sqlite3_io_methods object name */
29754 1, /* shared memory is disabled */
29755 afpClose, /* xClose method */
29756 afpLock, /* xLock method */
29757 afpUnlock, /* xUnlock method */
29758 afpCheckReservedLock /* xCheckReservedLock method */
 
29759 )
29760 #endif
29761
29762 /*
29763 ** The proxy locking method is a "super-method" in the sense that it
@@ -29778,11 +29879,12 @@
29778 proxyIoMethods, /* sqlite3_io_methods object name */
29779 1, /* shared memory is disabled */
29780 proxyClose, /* xClose method */
29781 proxyLock, /* xLock method */
29782 proxyUnlock, /* xUnlock method */
29783 proxyCheckReservedLock /* xCheckReservedLock method */
 
29784 )
29785 #endif
29786
29787 /* nfs lockd on OSX 10.3+ doesn't clear write locks when a read lock is set */
29788 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -29791,11 +29893,12 @@
29791 nfsIoMethods, /* sqlite3_io_methods object name */
29792 1, /* shared memory is disabled */
29793 unixClose, /* xClose method */
29794 unixLock, /* xLock method */
29795 nfsUnlock, /* xUnlock method */
29796 unixCheckReservedLock /* xCheckReservedLock method */
 
29797 )
29798 #endif
29799
29800 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
29801 /*
@@ -39752,11 +39855,11 @@
39752 assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
39753 assert( pCache->n90pct == pCache->nMax*9/10 );
39754 if( createFlag==1 && (
39755 nPinned>=pGroup->mxPinned
39756 || nPinned>=pCache->n90pct
39757 || pcache1UnderMemoryPressure(pCache)
39758 )){
39759 return 0;
39760 }
39761
39762 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
@@ -44373,17 +44476,19 @@
44373 if( !pNew ) rc = SQLITE_NOMEM;
44374 }
44375
44376 if( rc==SQLITE_OK ){
44377 pager_reset(pPager);
44378 sqlite3PageFree(pPager->pTmpSpace);
44379 pPager->pTmpSpace = pNew;
44380 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
44381 }
44382 if( rc==SQLITE_OK ){
 
 
44383 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
44384 pPager->pageSize = pageSize;
 
 
44385 }
44386 }
44387
44388 *pPageSize = pPager->pageSize;
44389 if( rc==SQLITE_OK ){
@@ -51383,13 +51488,14 @@
51383 ** stored in MemPage.pBt->mutex.
51384 */
51385 struct MemPage {
51386 u8 isInit; /* True if previously initialized. MUST BE FIRST! */
51387 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
51388 u8 intKey; /* True if intkey flag is set */
51389 u8 leaf; /* True if leaf flag is set */
51390 u8 hasData; /* True if this page stores data */
 
51391 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
51392 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
51393 u8 max1bytePayload; /* min(maxLocal,127) */
51394 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
51395 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
@@ -51545,11 +51651,11 @@
51545 int nRef; /* Number of references to this structure */
51546 BtShared *pNext; /* Next on a list of sharable BtShared structs */
51547 BtLock *pLock; /* List of locks held on this shared-btree struct */
51548 Btree *pWriter; /* Btree with currently open write transaction */
51549 #endif
51550 u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
51551 };
51552
51553 /*
51554 ** Allowed values for BtShared.btsFlags
51555 */
@@ -51566,16 +51672,14 @@
51566 ** about a cell. The parseCellPtr() function fills in this structure
51567 ** based on information extract from the raw disk page.
51568 */
51569 typedef struct CellInfo CellInfo;
51570 struct CellInfo {
51571 i64 nKey; /* The key for INTKEY tables, or number of bytes in key */
51572 u8 *pCell; /* Pointer to the start of cell content */
51573 u32 nData; /* Number of bytes of data */
51574 u32 nPayload; /* Total amount of payload */
51575 u16 nHeader; /* Size of the cell content header in bytes */
51576 u16 nLocal; /* Amount of payload held locally */
51577 u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */
51578 u16 nSize; /* Size of the cell content on the main b-tree page */
51579 };
51580
51581 /*
@@ -51768,10 +51872,12 @@
51768 u8 *aPgRef; /* 1 bit per page in the db (see above) */
51769 Pgno nPage; /* Number of pages in the database */
51770 int mxErr; /* Stop accumulating errors when this reaches zero */
51771 int nErr; /* Number of messages written to zErrMsg so far */
51772 int mallocFailed; /* A memory allocation error has occurred */
 
 
51773 StrAccum errMsg; /* Accumulate the error message text here */
51774 };
51775
51776 /*
51777 ** Routines to read or write a two- and four-byte big-endian integer values.
@@ -52554,11 +52660,13 @@
52554 ){
52555 BtCursor *p;
52556 BtShared *pBt = pBtree->pBt;
52557 assert( sqlite3BtreeHoldsMutex(pBtree) );
52558 for(p=pBt->pCursor; p; p=p->pNext){
52559 if( (p->curFlags & BTCF_Incrblob)!=0 && (isClearTable || p->info.nKey==iRow) ){
 
 
52560 p->eState = CURSOR_INVALID;
52561 }
52562 }
52563 }
52564
@@ -52727,13 +52835,13 @@
52727 ** the cursors if and when a cursor is found that actually requires saving.
52728 ** The common case is that no cursors need to be saved, so this routine is
52729 ** broken out from its caller to avoid unnecessary stack pointer movement.
52730 */
52731 static int SQLITE_NOINLINE saveCursorsOnList(
52732 BtCursor *p, /* The first cursor that needs saving */
52733 Pgno iRoot, /* Only save cursor with this iRoot. Save all if zero */
52734 BtCursor *pExcept /* Do not save this cursor */
52735 ){
52736 do{
52737 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
52738 if( p->eState==CURSOR_VALID ){
52739 int rc = saveCursorPosition(p);
@@ -52841,11 +52949,11 @@
52841 **
52842 ** Use the separate sqlite3BtreeCursorRestore() routine to restore a cursor
52843 ** back to where it ought to be if this routine returns true.
52844 */
52845 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
52846 return pCur && pCur->eState!=CURSOR_VALID;
52847 }
52848
52849 /*
52850 ** This routine restores a cursor back to its original position after it
52851 ** has been moved by some outside activity (such as a btree rebalance or
@@ -53035,51 +53143,48 @@
53035 /*
53036 ** Parse a cell content block and fill in the CellInfo structure. There
53037 ** are two versions of this function. btreeParseCell() takes a
53038 ** cell index as the second argument and btreeParseCellPtr()
53039 ** takes a pointer to the body of the cell as its second argument.
53040 **
53041 ** Within this file, the parseCell() macro can be called instead of
53042 ** btreeParseCellPtr(). Using some compilers, this will be faster.
53043 */
53044 static void btreeParseCellPtr(
53045 MemPage *pPage, /* Page containing the cell */
53046 u8 *pCell, /* Pointer to the cell text. */
53047 CellInfo *pInfo /* Fill in this structure */
53048 ){
53049 u16 n; /* Number bytes in cell content header */
53050 u32 nPayload; /* Number of bytes of cell payload */
53051
53052 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53053
53054 pInfo->pCell = pCell;
53055 assert( pPage->leaf==0 || pPage->leaf==1 );
53056 n = pPage->childPtrSize;
53057 assert( n==4-4*pPage->leaf );
53058 if( pPage->intKey ){
53059 if( pPage->hasData ){
53060 assert( n==0 );
53061 n = getVarint32(pCell, nPayload);
53062 }else{
53063 nPayload = 0;
53064 }
53065 n += getVarint(&pCell[n], (u64*)&pInfo->nKey);
53066 pInfo->nData = nPayload;
53067 }else{
53068 pInfo->nData = 0;
53069 n += getVarint32(&pCell[n], nPayload);
 
53070 pInfo->nKey = nPayload;
53071 }
53072 pInfo->nPayload = nPayload;
53073 pInfo->nHeader = n;
53074 testcase( nPayload==pPage->maxLocal );
53075 testcase( nPayload==pPage->maxLocal+1 );
53076 if( likely(nPayload<=pPage->maxLocal) ){
53077 /* This is the (easy) common case where the entire payload fits
53078 ** on the local page. No overflow is required.
53079 */
53080 if( (pInfo->nSize = (u16)(n+nPayload))<4 ) pInfo->nSize = 4;
 
53081 pInfo->nLocal = (u16)nPayload;
53082 pInfo->iOverflow = 0;
53083 }else{
53084 /* If the payload will not fit completely on the local page, we have
53085 ** to decide how much to store locally and how much to spill onto
@@ -53102,33 +53207,32 @@
53102 if( surplus <= maxLocal ){
53103 pInfo->nLocal = (u16)surplus;
53104 }else{
53105 pInfo->nLocal = (u16)minLocal;
53106 }
53107 pInfo->iOverflow = (u16)(pInfo->nLocal + n);
53108 pInfo->nSize = pInfo->iOverflow + 4;
53109 }
53110 }
53111 #define parseCell(pPage, iCell, pInfo) \
53112 btreeParseCellPtr((pPage), findCell((pPage), (iCell)), (pInfo))
53113 static void btreeParseCell(
53114 MemPage *pPage, /* Page containing the cell */
53115 int iCell, /* The cell index. First cell is 0 */
53116 CellInfo *pInfo /* Fill in this structure */
53117 ){
53118 parseCell(pPage, iCell, pInfo);
53119 }
53120
53121 /*
53122 ** Compute the total number of bytes that a Cell needs in the cell
53123 ** data area of the btree-page. The return number includes the cell
53124 ** data header and the local payload, but not any overflow page or
53125 ** the space used by the cell pointer.
53126 */
53127 static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
53128 u8 *pIter = &pCell[pPage->childPtrSize];
53129 u32 nSize;
 
53130
53131 #ifdef SQLITE_DEBUG
53132 /* The value returned by this function should always be the same as
53133 ** the (CellInfo.nSize) value found by doing a full parse of the
53134 ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
@@ -53135,47 +53239,48 @@
53135 ** this function verifies that this invariant is not violated. */
53136 CellInfo debuginfo;
53137 btreeParseCellPtr(pPage, pCell, &debuginfo);
53138 #endif
53139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53140 if( pPage->intKey ){
53141 u8 *pEnd;
53142 if( pPage->hasData ){
53143 pIter += getVarint32(pIter, nSize);
53144 }else{
53145 nSize = 0;
53146 }
53147
53148 /* pIter now points at the 64-bit integer key value, a variable length
53149 ** integer. The following block moves pIter to point at the first byte
53150 ** past the end of the key value. */
53151 pEnd = &pIter[9];
53152 while( (*pIter++)&0x80 && pIter<pEnd );
53153 }else{
53154 pIter += getVarint32(pIter, nSize);
53155 }
53156
53157 testcase( nSize==pPage->maxLocal );
53158 testcase( nSize==pPage->maxLocal+1 );
53159 if( nSize>pPage->maxLocal ){
 
 
 
53160 int minLocal = pPage->minLocal;
53161 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
53162 testcase( nSize==pPage->maxLocal );
53163 testcase( nSize==pPage->maxLocal+1 );
53164 if( nSize>pPage->maxLocal ){
53165 nSize = minLocal;
53166 }
53167 nSize += 4;
53168 }
53169 nSize += (u32)(pIter - pCell);
53170
53171 /* The minimum size of any cell is 4 bytes. */
53172 if( nSize<4 ){
53173 nSize = 4;
53174 }
53175
53176 assert( nSize==debuginfo.nSize );
53177 return (u16)nSize;
53178 }
53179
53180 #ifdef SQLITE_DEBUG
53181 /* This variation on cellSizePtr() is used inside of assert() statements
@@ -53194,11 +53299,10 @@
53194 static void ptrmapPutOvflPtr(MemPage *pPage, u8 *pCell, int *pRC){
53195 CellInfo info;
53196 if( *pRC ) return;
53197 assert( pCell!=0 );
53198 btreeParseCellPtr(pPage, pCell, &info);
53199 assert( (info.nData+(pPage->intKey?0:info.nKey))==info.nPayload );
53200 if( info.iOverflow ){
53201 Pgno ovfl = get4byte(&pCell[info.iOverflow]);
53202 ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC);
53203 }
53204 }
@@ -53407,11 +53511,11 @@
53407 ** does it detect cells or freeblocks that encrouch into the reserved bytes
53408 ** at the end of the page. So do additional corruption checks inside this
53409 ** routine and return SQLITE_CORRUPT if any problems are found.
53410 */
53411 static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
53412 u16 iPtr; /* Address of pointer to next freeblock */
53413 u16 iFreeBlk; /* Address of the next freeblock */
53414 u8 hdr; /* Page header size. 0 or 100 */
53415 u8 nFrag = 0; /* Reduction in fragmentation */
53416 u16 iOrigSize = iSize; /* Original value of iSize */
53417 u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */
@@ -53459,13 +53563,13 @@
53459 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
53460 iSize = iEnd - iStart;
53461 iFreeBlk = get2byte(&data[iFreeBlk]);
53462 }
53463
53464 /* If iPtr is another freeblock (that is, if iPtr is not the freelist pointer
53465 ** in the page header) then check to see if iStart should be coalesced
53466 ** onto the end of iPtr.
53467 */
53468 if( iPtr>hdr+1 ){
53469 int iPtrEnd = iPtr + get2byte(&data[iPtr+2]);
53470 if( iPtrEnd+3>=iStart ){
53471 if( iPtrEnd>iStart ) return SQLITE_CORRUPT_BKPT;
@@ -53515,16 +53619,18 @@
53515 flagByte &= ~PTF_LEAF;
53516 pPage->childPtrSize = 4-4*pPage->leaf;
53517 pBt = pPage->pBt;
53518 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
53519 pPage->intKey = 1;
53520 pPage->hasData = pPage->leaf;
 
53521 pPage->maxLocal = pBt->maxLeaf;
53522 pPage->minLocal = pBt->minLeaf;
53523 }else if( flagByte==PTF_ZERODATA ){
53524 pPage->intKey = 0;
53525 pPage->hasData = 0;
 
53526 pPage->maxLocal = pBt->maxLocal;
53527 pPage->minLocal = pBt->minLocal;
53528 }else{
53529 return SQLITE_CORRUPT_BKPT;
53530 }
@@ -54175,11 +54281,12 @@
54175 #endif
54176 }
54177
54178 /*
54179 ** Make sure pBt->pTmpSpace points to an allocation of
54180 ** MX_CELL_SIZE(pBt) bytes.
 
54181 */
54182 static void allocateTempSpace(BtShared *pBt){
54183 if( !pBt->pTmpSpace ){
54184 pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
54185
@@ -54190,21 +54297,32 @@
54190 ** can mean that fillInCell() only initializes the first 2 or 3
54191 ** bytes of pTmpSpace, but that the first 4 bytes are copied from
54192 ** it into a database page. This is not actually a problem, but it
54193 ** does cause a valgrind error when the 1 or 2 bytes of unitialized
54194 ** data is passed to system call write(). So to avoid this error,
54195 ** zero the first 4 bytes of temp space here. */
54196 if( pBt->pTmpSpace ) memset(pBt->pTmpSpace, 0, 4);
 
 
 
 
 
 
 
 
54197 }
54198 }
54199
54200 /*
54201 ** Free the pBt->pTmpSpace allocation
54202 */
54203 static void freeTempSpace(BtShared *pBt){
54204 sqlite3PageFree( pBt->pTmpSpace);
54205 pBt->pTmpSpace = 0;
 
 
 
54206 }
54207
54208 /*
54209 ** Close an open database and invalidate all cursors.
54210 */
@@ -54694,15 +54812,15 @@
54694 */
54695 static void unlockBtreeIfUnused(BtShared *pBt){
54696 assert( sqlite3_mutex_held(pBt->mutex) );
54697 assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE );
54698 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
54699 assert( pBt->pPage1->aData );
 
54700 assert( sqlite3PagerRefcount(pBt->pPager)==1 );
54701 assert( pBt->pPage1->aData );
54702 releasePage(pBt->pPage1);
54703 pBt->pPage1 = 0;
 
54704 }
54705 }
54706
54707 /*
54708 ** If pBt points to an empty file then convert that empty file
@@ -55739,10 +55857,14 @@
55739 assert( pBt->pPage1 && pBt->pPage1->aData );
55740
55741 if( NEVER(wrFlag && (pBt->btsFlags & BTS_READ_ONLY)!=0) ){
55742 return SQLITE_READONLY;
55743 }
 
 
 
 
55744 if( iTable==1 && btreePagecount(pBt)==0 ){
55745 assert( wrFlag==0 );
55746 iTable = 0;
55747 }
55748
@@ -55928,12 +56050,13 @@
55928 ** to return an integer result code for historical reasons.
55929 */
55930 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
55931 assert( cursorHoldsMutex(pCur) );
55932 assert( pCur->eState==CURSOR_VALID );
 
55933 getCellInfo(pCur);
55934 *pSize = pCur->info.nData;
55935 return SQLITE_OK;
55936 }
55937
55938 /*
55939 ** Given the page number of an overflow page in the database (parameter
@@ -56080,34 +56203,32 @@
56080 unsigned char *pBuf, /* Write the bytes into this buffer */
56081 int eOp /* zero to read. non-zero to write. */
56082 ){
56083 unsigned char *aPayload;
56084 int rc = SQLITE_OK;
56085 u32 nKey;
56086 int iIdx = 0;
56087 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
56088 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
56089 #ifdef SQLITE_DIRECT_OVERFLOW_READ
56090 int bEnd; /* True if reading to end of data */
 
56091 #endif
56092
56093 assert( pPage );
56094 assert( pCur->eState==CURSOR_VALID );
56095 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
56096 assert( cursorHoldsMutex(pCur) );
56097 assert( eOp!=2 || offset==0 ); /* Always start from beginning for eOp==2 */
56098
56099 getCellInfo(pCur);
56100 aPayload = pCur->info.pCell + pCur->info.nHeader;
56101 nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey);
56102 #ifdef SQLITE_DIRECT_OVERFLOW_READ
56103 bEnd = (offset+amt==nKey+pCur->info.nData);
56104 #endif
 
56105
56106 if( NEVER(offset+amt > nKey+pCur->info.nData)
56107 || &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
56108 ){
56109 /* Trying to read or write past the end of the data is an error */
56110 return SQLITE_CORRUPT_BKPT;
56111 }
56112
56113 /* Check if data must be read/written to/from the btree page itself. */
@@ -56159,11 +56280,13 @@
56159
56160 /* If the overflow page-list cache has been allocated and the
56161 ** entry for the first required overflow page is valid, skip
56162 ** directly to it.
56163 */
56164 if( (pCur->curFlags & BTCF_ValidOvfl)!=0 && pCur->aOverflow[offset/ovflSize] ){
 
 
56165 iIdx = (offset/ovflSize);
56166 nextPage = pCur->aOverflow[iIdx];
56167 offset = (offset%ovflSize);
56168 }
56169
@@ -56212,10 +56335,11 @@
56212 ** 2) data is required from the start of this overflow page, and
56213 ** 3) the database is file-backed, and
56214 ** 4) there is no open write-transaction, and
56215 ** 5) the database is not a WAL database,
56216 ** 6) all data from the page is being read.
 
56217 **
56218 ** then data can be read directly from the database file into the
56219 ** output buffer, bypassing the page-cache altogether. This speeds
56220 ** up loading large records that span many overflow pages.
56221 */
@@ -56223,13 +56347,15 @@
56223 && offset==0 /* (2) */
56224 && (bEnd || a==ovflSize) /* (6) */
56225 && pBt->inTransaction==TRANS_READ /* (4) */
56226 && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */
56227 && pBt->pPage1->aData[19]==0x01 /* (5) */
 
56228 ){
56229 u8 aSave[4];
56230 u8 *aWrite = &pBuf[-4];
 
56231 memcpy(aSave, aWrite, 4);
56232 rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
56233 nextPage = get4byte(aWrite);
56234 memcpy(aWrite, aSave, 4);
56235 }else
@@ -56337,11 +56463,11 @@
56337 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
56338 assert( cursorHoldsMutex(pCur) );
56339 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
56340 assert( pCur->info.nSize>0 );
56341 *pAmt = pCur->info.nLocal;
56342 return (void*)(pCur->info.pCell + pCur->info.nHeader);
56343 }
56344
56345
56346 /*
56347 ** For the entry that cursor pCur is point to, return as
@@ -56765,11 +56891,11 @@
56765 pCur->aiIdx[pCur->iPage] = (u16)idx;
56766 if( xRecordCompare==0 ){
56767 for(;;){
56768 i64 nCellKey;
56769 pCell = findCell(pPage, idx) + pPage->childPtrSize;
56770 if( pPage->hasData ){
56771 while( 0x80 <= *(pCell++) ){
56772 if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
56773 }
56774 }
56775 getVarint(pCell, (u64*)&nCellKey);
@@ -57024,13 +57150,13 @@
57024 ** was already pointing to the first entry in the database before
57025 ** this routine was called, then set *pRes=1.
57026 **
57027 ** The main entry point is sqlite3BtreePrevious(). That routine is optimized
57028 ** for the common case of merely decrementing the cell counter BtCursor.aiIdx
57029 ** to the previous cell on the current page. The (slower) btreePrevious() helper
57030 ** routine is called when it is necessary to move to a different page or
57031 ** to restore the cursor.
57032 **
57033 ** The calling function will set *pRes to 0 or 1. The initial *pRes value
57034 ** will be 1 if the cursor being stepped corresponds to an SQL index and
57035 ** if this routine could have been skipped if that SQL index had been
57036 ** a unique index. Otherwise the caller will have set *pRes to zero.
@@ -57048,12 +57174,11 @@
57048 assert( *pRes==0 );
57049 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
57050 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
57051 assert( pCur->info.nSize==0 );
57052 if( pCur->eState!=CURSOR_VALID ){
57053 assert( pCur->eState>=CURSOR_REQUIRESEEK );
57054 rc = btreeRestoreCursorPosition(pCur);
57055 if( rc!=SQLITE_OK ){
57056 return rc;
57057 }
57058 if( CURSOR_INVALID==pCur->eState ){
57059 *pRes = 1;
@@ -57354,11 +57479,11 @@
57354 if( rc ) goto end_allocate_page;
57355 if( closest<k-1 ){
57356 memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
57357 }
57358 put4byte(&aData[4], k-1);
57359 noContent = !btreeGetHasContent(pBt, *pPgno) ? PAGER_GET_NOCONTENT : 0;
57360 rc = btreeGetPage(pBt, *pPgno, ppPage, noContent);
57361 if( rc==SQLITE_OK ){
57362 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
57363 if( rc!=SQLITE_OK ){
57364 releasePage(*ppPage);
@@ -57387,11 +57512,11 @@
57387 ** content for any page that really does lie past the end of the database
57388 ** file on disk. So the effects of disabling the no-content optimization
57389 ** here are confined to those pages that lie between the end of the
57390 ** database image and the end of the database file.
57391 */
57392 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)) ? PAGER_GET_NOCONTENT : 0;
57393
57394 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
57395 if( rc ) return rc;
57396 pBt->nPage++;
57397 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
@@ -57586,22 +57711,29 @@
57586 *pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
57587 }
57588 }
57589
57590 /*
57591 ** Free any overflow pages associated with the given Cell.
 
 
57592 */
57593 static int clearCell(MemPage *pPage, unsigned char *pCell){
 
 
 
 
57594 BtShared *pBt = pPage->pBt;
57595 CellInfo info;
57596 Pgno ovflPgno;
57597 int rc;
57598 int nOvfl;
57599 u32 ovflPageSize;
57600
57601 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57602 btreeParseCellPtr(pPage, pCell, &info);
 
57603 if( info.iOverflow==0 ){
57604 return SQLITE_OK; /* No overflow pages. Return without doing anything */
57605 }
57606 if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){
57607 return SQLITE_CORRUPT_BKPT; /* Cell extends past end of page */
@@ -57681,54 +57813,87 @@
57681 unsigned char *pPrior;
57682 unsigned char *pPayload;
57683 BtShared *pBt = pPage->pBt;
57684 Pgno pgnoOvfl = 0;
57685 int nHeader;
57686 CellInfo info;
57687
57688 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57689
57690 /* pPage is not necessarily writeable since pCell might be auxiliary
57691 ** buffer space that is separate from the pPage buffer area */
57692 assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
57693 || sqlite3PagerIswriteable(pPage->pDbPage) );
57694
57695 /* Fill in the header. */
57696 nHeader = 0;
57697 if( !pPage->leaf ){
57698 nHeader += 4;
57699 }
57700 if( pPage->hasData ){
57701 nHeader += putVarint32(&pCell[nHeader], nData+nZero);
57702 }else{
57703 nData = nZero = 0;
 
57704 }
57705 nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
57706 btreeParseCellPtr(pPage, pCell, &info);
57707 assert( info.nHeader==nHeader );
57708 assert( info.nKey==nKey );
57709 assert( info.nData==(u32)(nData+nZero) );
57710
57711 /* Fill in the payload */
57712 nPayload = nData + nZero;
57713 if( pPage->intKey ){
57714 pSrc = pData;
57715 nSrc = nData;
57716 nData = 0;
57717 }else{
57718 if( NEVER(nKey>0x7fffffff || pKey==0) ){
57719 return SQLITE_CORRUPT_BKPT;
57720 }
57721 nPayload += (int)nKey;
57722 pSrc = pKey;
57723 nSrc = (int)nKey;
57724 }
57725 *pnSize = info.nSize;
57726 spaceLeft = info.nLocal;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57727 pPayload = &pCell[nHeader];
57728 pPrior = &pCell[info.iOverflow];
57729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57730 while( nPayload>0 ){
57731 if( spaceLeft==0 ){
57732 #ifndef SQLITE_OMIT_AUTOVACUUM
57733 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
57734 if( pBt->autoVacuum ){
@@ -57865,15 +58030,10 @@
57865 ** pTemp is not null. Regardless of pTemp, allocate a new entry
57866 ** in pPage->apOvfl[] and make it point to the cell content (either
57867 ** in pTemp or the original pCell) and also record its index.
57868 ** Allocating a new entry in pPage->aCell[] implies that
57869 ** pPage->nOverflow is incremented.
57870 **
57871 ** If nSkip is non-zero, then do not copy the first nSkip bytes of the
57872 ** cell. The caller will overwrite them after this function returns. If
57873 ** nSkip is non-zero, then pCell may not point to an invalid memory location
57874 ** (but pCell+nSkip is always valid).
57875 */
57876 static void insertCell(
57877 MemPage *pPage, /* Page into which we are copying */
57878 int i, /* New cell becomes the i-th cell of the page */
57879 u8 *pCell, /* Content of the new cell */
@@ -57886,11 +58046,10 @@
57886 int j; /* Loop counter */
57887 int end; /* First byte past the last cell pointer in data[] */
57888 int ins; /* Index in data[] where new cell pointer is inserted */
57889 int cellOffset; /* Address of first cell pointer in data[] */
57890 u8 *data; /* The content of the whole page */
57891 int nSkip = (iChild ? 4 : 0);
57892
57893 if( *pRC ) return;
57894
57895 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
57896 assert( MX_CELL(pPage->pBt)<=10921 );
@@ -57904,11 +58063,11 @@
57904 ** might be less than 8 (leaf-size + pointer) on the interior node. Hence
57905 ** the term after the || in the following assert(). */
57906 assert( sz==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
57907 if( pPage->nOverflow || sz+2>pPage->nFree ){
57908 if( pTemp ){
57909 memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
57910 pCell = pTemp;
57911 }
57912 if( iChild ){
57913 put4byte(pCell, iChild);
57914 }
@@ -57933,11 +58092,11 @@
57933 ** if it returns success */
57934 assert( idx >= end+2 );
57935 assert( idx+sz <= (int)pPage->pBt->usableSize );
57936 pPage->nCell++;
57937 pPage->nFree -= (u16)(2 + sz);
57938 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
57939 if( iChild ){
57940 put4byte(&data[idx], iChild);
57941 }
57942 memmove(&data[ins+2], &data[ins], end-ins);
57943 put2byte(&data[ins], idx);
@@ -58432,11 +58591,11 @@
58432 **
58433 ** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
58434 ** leafData: 1 if pPage holds key+data and pParent holds only keys.
58435 */
58436 leafCorrection = apOld[0]->leaf*4;
58437 leafData = apOld[0]->hasData;
58438 for(i=0; i<nOld; i++){
58439 int limit;
58440
58441 /* Before doing anything else, take a copy of the i'th original sibling
58442 ** The rest of this function will use data from the copies rather
@@ -59008,11 +59167,11 @@
59008 int const iIdx = pCur->aiIdx[iPage-1];
59009
59010 rc = sqlite3PagerWrite(pParent->pDbPage);
59011 if( rc==SQLITE_OK ){
59012 #ifndef SQLITE_OMIT_QUICKBALANCE
59013 if( pPage->hasData
59014 && pPage->nOverflow==1
59015 && pPage->aiOvfl[0]==pPage->nCell
59016 && pParent->pgno!=1
59017 && pParent->nCell==iIdx
59018 ){
@@ -59127,11 +59286,12 @@
59127 assert( pCur->skipNext!=SQLITE_OK );
59128 return pCur->skipNext;
59129 }
59130
59131 assert( cursorHoldsMutex(pCur) );
59132 assert( (pCur->curFlags & BTCF_WriteFlag)!=0 && pBt->inTransaction==TRANS_WRITE
 
59133 && (pBt->btsFlags & BTS_READ_ONLY)==0 );
59134 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
59135
59136 /* Assert that the caller has been consistent. If this cursor was opened
59137 ** expecting an index b-tree, then the caller should be inserting blob
@@ -59160,11 +59320,12 @@
59160 invalidateIncrblobCursors(p, nKey, 0);
59161
59162 /* If the cursor is currently on the last row and we are appending a
59163 ** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto()
59164 ** call */
59165 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && nKey>0 && pCur->info.nKey==nKey-1 ){
 
59166 loc = -1;
59167 }
59168 }
59169
59170 if( !loc ){
@@ -59179,13 +59340,12 @@
59179
59180 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
59181 pCur->pgnoRoot, nKey, nData, pPage->pgno,
59182 loc==0 ? "overwrite" : "new entry"));
59183 assert( pPage->isInit );
59184 allocateTempSpace(pBt);
59185 newCell = pBt->pTmpSpace;
59186 if( newCell==0 ) return SQLITE_NOMEM;
59187 rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
59188 if( rc ) goto end_insert;
59189 assert( szNew==cellSizePtr(pPage, newCell) );
59190 assert( szNew <= MX_CELL_SIZE(pBt) );
59191 idx = pCur->aiIdx[pCur->iPage];
@@ -59198,12 +59358,11 @@
59198 }
59199 oldCell = findCell(pPage, idx);
59200 if( !pPage->leaf ){
59201 memcpy(newCell, oldCell, 4);
59202 }
59203 szOld = cellSizePtr(pPage, oldCell);
59204 rc = clearCell(pPage, oldCell);
59205 dropCell(pPage, idx, szOld, &rc);
59206 if( rc ) goto end_insert;
59207 }else if( loc<0 && pPage->nCell>0 ){
59208 assert( pPage->leaf );
59209 idx = ++pCur->aiIdx[pCur->iPage];
@@ -59261,10 +59420,11 @@
59261 int rc; /* Return code */
59262 MemPage *pPage; /* Page to delete cell from */
59263 unsigned char *pCell; /* Pointer to cell to delete */
59264 int iCellIdx; /* Index of cell to delete */
59265 int iCellDepth; /* Depth of node containing pCell */
 
59266
59267 assert( cursorHoldsMutex(pCur) );
59268 assert( pBt->inTransaction==TRANS_WRITE );
59269 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
59270 assert( pCur->curFlags & BTCF_WriteFlag );
@@ -59309,12 +59469,12 @@
59309 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
59310 }
59311
59312 rc = sqlite3PagerWrite(pPage->pDbPage);
59313 if( rc ) return rc;
59314 rc = clearCell(pPage, pCell);
59315 dropCell(pPage, iCellIdx, cellSizePtr(pPage, pCell), &rc);
59316 if( rc ) return rc;
59317
59318 /* If the cell deleted was not located on a leaf page, then the cursor
59319 ** is currently pointing to the largest entry in the sub-tree headed
59320 ** by the child-page of the cell that was just deleted from an internal
@@ -59327,14 +59487,12 @@
59327 unsigned char *pTmp;
59328
59329 pCell = findCell(pLeaf, pLeaf->nCell-1);
59330 nCell = cellSizePtr(pLeaf, pCell);
59331 assert( MX_CELL_SIZE(pBt) >= nCell );
59332
59333 allocateTempSpace(pBt);
59334 pTmp = pBt->pTmpSpace;
59335
59336 rc = sqlite3PagerWrite(pLeaf->pDbPage);
59337 insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n, &rc);
59338 dropCell(pLeaf, pLeaf->nCell-1, nCell, &rc);
59339 if( rc ) return rc;
59340 }
@@ -59542,10 +59700,11 @@
59542 MemPage *pPage;
59543 int rc;
59544 unsigned char *pCell;
59545 int i;
59546 int hdr;
 
59547
59548 assert( sqlite3_mutex_held(pBt->mutex) );
59549 if( pgno>btreePagecount(pBt) ){
59550 return SQLITE_CORRUPT_BKPT;
59551 }
@@ -59557,11 +59716,11 @@
59557 pCell = findCell(pPage, i);
59558 if( !pPage->leaf ){
59559 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
59560 if( rc ) goto cleardatabasepage_out;
59561 }
59562 rc = clearCell(pPage, pCell);
59563 if( rc ) goto cleardatabasepage_out;
59564 }
59565 if( !pPage->leaf ){
59566 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
59567 if( rc ) goto cleardatabasepage_out;
@@ -59903,24 +60062,25 @@
59903 /*
59904 ** Append a message to the error message string.
59905 */
59906 static void checkAppendMsg(
59907 IntegrityCk *pCheck,
59908 char *zMsg1,
59909 const char *zFormat,
59910 ...
59911 ){
59912 va_list ap;
 
59913 if( !pCheck->mxErr ) return;
59914 pCheck->mxErr--;
59915 pCheck->nErr++;
59916 va_start(ap, zFormat);
59917 if( pCheck->errMsg.nChar ){
59918 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
59919 }
59920 if( zMsg1 ){
59921 sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1);
 
59922 }
59923 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
59924 va_end(ap);
59925 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
59926 pCheck->mallocFailed = 1;
@@ -59954,18 +60114,18 @@
59954 ** Return 1 if there are 2 or more references to the page and 0 if
59955 ** if this is the first reference to the page.
59956 **
59957 ** Also check that the page number is in bounds.
59958 */
59959 static int checkRef(IntegrityCk *pCheck, Pgno iPage, char *zContext){
59960 if( iPage==0 ) return 1;
59961 if( iPage>pCheck->nPage ){
59962 checkAppendMsg(pCheck, zContext, "invalid page number %d", iPage);
59963 return 1;
59964 }
59965 if( getPageReferenced(pCheck, iPage) ){
59966 checkAppendMsg(pCheck, zContext, "2nd reference to page %d", iPage);
59967 return 1;
59968 }
59969 setPageReferenced(pCheck, iPage);
59970 return 0;
59971 }
@@ -59978,26 +60138,25 @@
59978 */
59979 static void checkPtrmap(
59980 IntegrityCk *pCheck, /* Integrity check context */
59981 Pgno iChild, /* Child page number */
59982 u8 eType, /* Expected pointer map type */
59983 Pgno iParent, /* Expected pointer map parent page number */
59984 char *zContext /* Context description (used for error msg) */
59985 ){
59986 int rc;
59987 u8 ePtrmapType;
59988 Pgno iPtrmapParent;
59989
59990 rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
59991 if( rc!=SQLITE_OK ){
59992 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->mallocFailed = 1;
59993 checkAppendMsg(pCheck, zContext, "Failed to read ptrmap key=%d", iChild);
59994 return;
59995 }
59996
59997 if( ePtrmapType!=eType || iPtrmapParent!=iParent ){
59998 checkAppendMsg(pCheck, zContext,
59999 "Bad ptr map entry key=%d expected=(%d,%d) got=(%d,%d)",
60000 iChild, eType, iParent, ePtrmapType, iPtrmapParent);
60001 }
60002 }
60003 #endif
@@ -60008,51 +60167,50 @@
60008 */
60009 static void checkList(
60010 IntegrityCk *pCheck, /* Integrity checking context */
60011 int isFreeList, /* True for a freelist. False for overflow page list */
60012 int iPage, /* Page number for first page in the list */
60013 int N, /* Expected number of pages in the list */
60014 char *zContext /* Context for error messages */
60015 ){
60016 int i;
60017 int expected = N;
60018 int iFirst = iPage;
60019 while( N-- > 0 && pCheck->mxErr ){
60020 DbPage *pOvflPage;
60021 unsigned char *pOvflData;
60022 if( iPage<1 ){
60023 checkAppendMsg(pCheck, zContext,
60024 "%d of %d pages missing from overflow list starting at %d",
60025 N+1, expected, iFirst);
60026 break;
60027 }
60028 if( checkRef(pCheck, iPage, zContext) ) break;
60029 if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage) ){
60030 checkAppendMsg(pCheck, zContext, "failed to get page %d", iPage);
60031 break;
60032 }
60033 pOvflData = (unsigned char *)sqlite3PagerGetData(pOvflPage);
60034 if( isFreeList ){
60035 int n = get4byte(&pOvflData[4]);
60036 #ifndef SQLITE_OMIT_AUTOVACUUM
60037 if( pCheck->pBt->autoVacuum ){
60038 checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0, zContext);
60039 }
60040 #endif
60041 if( n>(int)pCheck->pBt->usableSize/4-2 ){
60042 checkAppendMsg(pCheck, zContext,
60043 "freelist leaf count too big on page %d", iPage);
60044 N--;
60045 }else{
60046 for(i=0; i<n; i++){
60047 Pgno iFreePage = get4byte(&pOvflData[8+i*4]);
60048 #ifndef SQLITE_OMIT_AUTOVACUUM
60049 if( pCheck->pBt->autoVacuum ){
60050 checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0, zContext);
60051 }
60052 #endif
60053 checkRef(pCheck, iFreePage, zContext);
60054 }
60055 N -= n;
60056 }
60057 }
60058 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -60061,11 +60219,11 @@
60061 ** page in this overflow list, check that the pointer-map entry for
60062 ** the following page matches iPage.
60063 */
60064 if( pCheck->pBt->autoVacuum && N>0 ){
60065 i = get4byte(pOvflData);
60066 checkPtrmap(pCheck, i, PTRMAP_OVERFLOW2, iPage, zContext);
60067 }
60068 }
60069 #endif
60070 iPage = get4byte(pOvflData);
60071 sqlite3PagerUnref(pOvflPage);
@@ -60093,11 +60251,10 @@
60093 ** the root of the tree.
60094 */
60095 static int checkTreePage(
60096 IntegrityCk *pCheck, /* Context for the sanity check */
60097 int iPage, /* Page number of the page to check */
60098 char *zParentContext, /* Parent context */
60099 i64 *pnParentMinKey,
60100 i64 *pnParentMaxKey
60101 ){
60102 MemPage *pPage;
60103 int i, rc, depth, d2, pgno, cnt;
@@ -60104,38 +60261,42 @@
60104 int hdr, cellStart;
60105 int nCell;
60106 u8 *data;
60107 BtShared *pBt;
60108 int usableSize;
60109 char zContext[100];
60110 char *hit = 0;
60111 i64 nMinKey = 0;
60112 i64 nMaxKey = 0;
60113
60114 sqlite3_snprintf(sizeof(zContext), zContext, "Page %d: ", iPage);
 
60115
60116 /* Check that the page exists
60117 */
60118 pBt = pCheck->pBt;
60119 usableSize = pBt->usableSize;
60120 if( iPage==0 ) return 0;
60121 if( checkRef(pCheck, iPage, zParentContext) ) return 0;
 
 
60122 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
60123 checkAppendMsg(pCheck, zContext,
60124 "unable to get the page. error code=%d", rc);
60125 return 0;
 
60126 }
60127
60128 /* Clear MemPage.isInit to make sure the corruption detection code in
60129 ** btreeInitPage() is executed. */
60130 pPage->isInit = 0;
60131 if( (rc = btreeInitPage(pPage))!=0 ){
60132 assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
60133 checkAppendMsg(pCheck, zContext,
60134 "btreeInitPage() returns error code %d", rc);
60135 releasePage(pPage);
60136 return 0;
 
60137 }
60138
60139 /* Check out all the cells.
60140 */
60141 depth = 0;
@@ -60144,99 +60305,101 @@
60144 u32 sz;
60145 CellInfo info;
60146
60147 /* Check payload overflow pages
60148 */
60149 sqlite3_snprintf(sizeof(zContext), zContext,
60150 "On tree page %d cell %d: ", iPage, i);
 
60151 pCell = findCell(pPage,i);
60152 btreeParseCellPtr(pPage, pCell, &info);
60153 sz = info.nData;
60154 if( !pPage->intKey ) sz += (int)info.nKey;
60155 /* For intKey pages, check that the keys are in order.
60156 */
60157 else if( i==0 ) nMinKey = nMaxKey = info.nKey;
60158 else{
60159 if( info.nKey <= nMaxKey ){
60160 checkAppendMsg(pCheck, zContext,
60161 "Rowid %lld out of order (previous was %lld)", info.nKey, nMaxKey);
 
60162 }
60163 nMaxKey = info.nKey;
60164 }
60165 assert( sz==info.nPayload );
60166 if( (sz>info.nLocal)
60167 && (&pCell[info.iOverflow]<=&pPage->aData[pBt->usableSize])
60168 ){
60169 int nPage = (sz - info.nLocal + usableSize - 5)/(usableSize - 4);
60170 Pgno pgnoOvfl = get4byte(&pCell[info.iOverflow]);
60171 #ifndef SQLITE_OMIT_AUTOVACUUM
60172 if( pBt->autoVacuum ){
60173 checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage, zContext);
60174 }
60175 #endif
60176 checkList(pCheck, 0, pgnoOvfl, nPage, zContext);
60177 }
60178
60179 /* Check sanity of left child page.
60180 */
60181 if( !pPage->leaf ){
60182 pgno = get4byte(pCell);
60183 #ifndef SQLITE_OMIT_AUTOVACUUM
60184 if( pBt->autoVacuum ){
60185 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage, zContext);
60186 }
60187 #endif
60188 d2 = checkTreePage(pCheck, pgno, zContext, &nMinKey, i==0 ? NULL : &nMaxKey);
60189 if( i>0 && d2!=depth ){
60190 checkAppendMsg(pCheck, zContext, "Child page depth differs");
60191 }
60192 depth = d2;
60193 }
60194 }
60195
60196 if( !pPage->leaf ){
60197 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
60198 sqlite3_snprintf(sizeof(zContext), zContext,
60199 "On page %d at right child: ", iPage);
60200 #ifndef SQLITE_OMIT_AUTOVACUUM
60201 if( pBt->autoVacuum ){
60202 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage, zContext);
60203 }
60204 #endif
60205 checkTreePage(pCheck, pgno, zContext, NULL, !pPage->nCell ? NULL : &nMaxKey);
60206 }
60207
60208 /* For intKey leaf pages, check that the min/max keys are in order
60209 ** with any left/parent/right pages.
60210 */
 
 
60211 if( pPage->leaf && pPage->intKey ){
60212 /* if we are a left child page */
60213 if( pnParentMinKey ){
60214 /* if we are the left most child page */
60215 if( !pnParentMaxKey ){
60216 if( nMaxKey > *pnParentMinKey ){
60217 checkAppendMsg(pCheck, zContext,
60218 "Rowid %lld out of order (max larger than parent min of %lld)",
60219 nMaxKey, *pnParentMinKey);
60220 }
60221 }else{
60222 if( nMinKey <= *pnParentMinKey ){
60223 checkAppendMsg(pCheck, zContext,
60224 "Rowid %lld out of order (min less than parent min of %lld)",
60225 nMinKey, *pnParentMinKey);
60226 }
60227 if( nMaxKey > *pnParentMaxKey ){
60228 checkAppendMsg(pCheck, zContext,
60229 "Rowid %lld out of order (max larger than parent max of %lld)",
60230 nMaxKey, *pnParentMaxKey);
60231 }
60232 *pnParentMinKey = nMaxKey;
60233 }
60234 /* else if we're a right child page */
60235 } else if( pnParentMaxKey ){
60236 if( nMinKey <= *pnParentMaxKey ){
60237 checkAppendMsg(pCheck, zContext,
60238 "Rowid %lld out of order (min less than parent max of %lld)",
60239 nMinKey, *pnParentMaxKey);
60240 }
60241 }
60242 }
@@ -60244,10 +60407,11 @@
60244 /* Check for complete coverage of the page
60245 */
60246 data = pPage->aData;
60247 hdr = pPage->hdrOffset;
60248 hit = sqlite3PageMalloc( pBt->pageSize );
 
60249 if( hit==0 ){
60250 pCheck->mallocFailed = 1;
60251 }else{
60252 int contentOffset = get2byteNotZero(&data[hdr+5]);
60253 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
@@ -60261,11 +60425,12 @@
60261 int j;
60262 if( pc<=usableSize-4 ){
60263 size = cellSizePtr(pPage, &data[pc]);
60264 }
60265 if( (int)(pc+size-1)>=usableSize ){
60266 checkAppendMsg(pCheck, 0,
 
60267 "Corruption detected in cell %d on page %d",i,iPage);
60268 }else{
60269 for(j=pc+size-1; j>=pc; j--) hit[j]++;
60270 }
60271 }
@@ -60283,23 +60448,28 @@
60283 }
60284 for(i=cnt=0; i<usableSize; i++){
60285 if( hit[i]==0 ){
60286 cnt++;
60287 }else if( hit[i]>1 ){
60288 checkAppendMsg(pCheck, 0,
60289 "Multiple uses for byte %d of page %d", i, iPage);
60290 break;
60291 }
60292 }
60293 if( cnt!=data[hdr+7] ){
60294 checkAppendMsg(pCheck, 0,
60295 "Fragmentation of %d bytes reported as %d on page %d",
60296 cnt, data[hdr+7], iPage);
60297 }
60298 }
60299 sqlite3PageFree(hit);
60300 releasePage(pPage);
 
 
 
 
 
60301 return depth+1;
60302 }
60303 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
60304
60305 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -60336,10 +60506,13 @@
60336 sCheck.pPager = pBt->pPager;
60337 sCheck.nPage = btreePagecount(sCheck.pBt);
60338 sCheck.mxErr = mxErr;
60339 sCheck.nErr = 0;
60340 sCheck.mallocFailed = 0;
 
 
 
60341 *pnErr = 0;
60342 if( sCheck.nPage==0 ){
60343 sqlite3BtreeLeave(p);
60344 return 0;
60345 }
@@ -60355,53 +60528,57 @@
60355 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
60356 sCheck.errMsg.useMalloc = 2;
60357
60358 /* Check the integrity of the freelist
60359 */
 
60360 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
60361 get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");
 
60362
60363 /* Check all the tables.
60364 */
60365 for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
60366 if( aRoot[i]==0 ) continue;
60367 #ifndef SQLITE_OMIT_AUTOVACUUM
60368 if( pBt->autoVacuum && aRoot[i]>1 ){
60369 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0, 0);
60370 }
60371 #endif
60372 checkTreePage(&sCheck, aRoot[i], "List of tree roots: ", NULL, NULL);
 
 
60373 }
60374
60375 /* Make sure every page in the file is referenced
60376 */
60377 for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
60378 #ifdef SQLITE_OMIT_AUTOVACUUM
60379 if( getPageReferenced(&sCheck, i)==0 ){
60380 checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
60381 }
60382 #else
60383 /* If the database supports auto-vacuum, make sure no tables contain
60384 ** references to pointer-map pages.
60385 */
60386 if( getPageReferenced(&sCheck, i)==0 &&
60387 (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
60388 checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
60389 }
60390 if( getPageReferenced(&sCheck, i)!=0 &&
60391 (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
60392 checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
60393 }
60394 #endif
60395 }
60396
60397 /* Make sure this analysis did not leave any unref() pages.
60398 ** This is an internal consistency check; an integrity check
60399 ** of the integrity check.
60400 */
60401 if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
60402 checkAppendMsg(&sCheck, 0,
60403 "Outstanding page count goes from %d to %d during this analysis",
60404 nRef, sqlite3PagerRefcount(pBt->pPager)
60405 );
60406 }
60407
@@ -60593,11 +60770,11 @@
60593
60594 /* Save the positions of all other cursors open on this table. This is
60595 ** required in case any of them are holding references to an xFetch
60596 ** version of the b-tree page modified by the accessPayload call below.
60597 **
60598 ** Note that pCsr must be open on a BTREE_INTKEY table and saveCursorPosition()
60599 ** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
60600 ** saveAllCursors can only return SQLITE_OK.
60601 */
60602 VVA_ONLY(rc =) saveAllCursors(pCsr->pBt, pCsr->pgnoRoot, pCsr);
60603 assert( rc==SQLITE_OK );
@@ -61461,11 +61638,14 @@
61461 /* If MEM_Dyn is set then Mem.xDel!=0.
61462 ** Mem.xDel is might not be initialized if MEM_Dyn is clear.
61463 */
61464 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
61465
61466 /* MEM_Dyn may only be set if Mem.szMalloc==0 */
 
 
 
61467 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
61468
61469 /* Cannot be both MEM_Int and MEM_Real at the same time */
61470 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
61471
@@ -61570,11 +61750,11 @@
61570 }else{
61571 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
61572 }
61573 }
61574
61575 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
61576 memcpy(pMem->zMalloc, pMem->z, pMem->n);
61577 }
61578 if( (pMem->flags&MEM_Dyn)!=0 ){
61579 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
61580 pMem->xDel((void *)(pMem->z));
@@ -61597,11 +61777,12 @@
61597 **
61598 ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
61599 ** if unable to complete the resizing.
61600 */
61601 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
61602 assert( szNew>=0 );
 
61603 if( pMem->szMalloc<szNew ){
61604 return sqlite3VdbeMemGrow(pMem, szNew, 0);
61605 }
61606 assert( (pMem->flags & MEM_Dyn)==0 );
61607 pMem->z = pMem->zMalloc;
@@ -62321,11 +62502,14 @@
62321 nAlloc += (enc==SQLITE_UTF8?1:2);
62322 }
62323 if( nByte>iLimit ){
62324 return SQLITE_TOOBIG;
62325 }
62326 if( sqlite3VdbeMemClearAndResize(pMem, nAlloc) ){
 
 
 
62327 return SQLITE_NOMEM;
62328 }
62329 memcpy(pMem->z, z, nAlloc);
62330 }else if( xDel==SQLITE_DYNAMIC ){
62331 sqlite3VdbeMemRelease(pMem);
@@ -62424,11 +62608,11 @@
62424 /*
62425 ** The pVal argument is known to be a value other than NULL.
62426 ** Convert it into a string with encoding enc and return a pointer
62427 ** to a zero-terminated version of that string.
62428 */
62429 SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){
62430 assert( pVal!=0 );
62431 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
62432 assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
62433 assert( (pVal->flags & MEM_RowSet)==0 );
62434 assert( (pVal->flags & (MEM_Null))==0 );
@@ -63751,11 +63935,12 @@
63751 if( addr==p->nOp-1 ) p->nOp--;
63752 }
63753 }
63754
63755 /*
63756 ** Remove the last opcode inserted
 
63757 */
63758 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){
63759 if( (p->nOp-1)>(p->pParse->iFixedOp) && p->aOp[p->nOp-1].opcode==op ){
63760 sqlite3VdbeChangeToNoop(p, p->nOp-1);
63761 return 1;
@@ -64743,11 +64928,11 @@
64743 ** the call above. */
64744 }else if( pCx->pCursor ){
64745 sqlite3BtreeCloseCursor(pCx->pCursor);
64746 }
64747 #ifndef SQLITE_OMIT_VIRTUALTABLE
64748 if( pCx->pVtabCursor ){
64749 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
64750 const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
64751 p->inVtabMethod = 1;
64752 pModule->xClose(pVtabCursor);
64753 p->inVtabMethod = 0;
@@ -64786,13 +64971,14 @@
64786 static void closeAllCursors(Vdbe *p){
64787 if( p->pFrame ){
64788 VdbeFrame *pFrame;
64789 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
64790 sqlite3VdbeFrameRestore(pFrame);
 
 
64791 }
64792 p->pFrame = 0;
64793 p->nFrame = 0;
64794
64795 if( p->apCsr ){
64796 int i;
64797 for(i=0; i<p->nCursor; i++){
64798 VdbeCursor *pC = p->apCsr[i];
@@ -64810,11 +64996,11 @@
64810 p->pDelFrame = pDel->pParent;
64811 sqlite3VdbeFrameDelete(pDel);
64812 }
64813
64814 /* Delete any auxdata allocations made by the VM */
64815 sqlite3VdbeDeleteAuxData(p, -1, 0);
64816 assert( p->pAuxData==0 );
64817 }
64818
64819 /*
64820 ** Clean up the VM after a single run.
@@ -65676,14 +65862,10 @@
65676 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
65677 vdbeFreeOpArray(db, p->aOp, p->nOp);
65678 sqlite3DbFree(db, p->aColName);
65679 sqlite3DbFree(db, p->zSql);
65680 sqlite3DbFree(db, p->pFree);
65681 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
65682 sqlite3DbFree(db, p->zExplain);
65683 sqlite3DbFree(db, p->pExplain);
65684 #endif
65685 }
65686
65687 /*
65688 ** Delete an entire VDBE.
65689 */
@@ -65720,13 +65902,11 @@
65720 #endif
65721 assert( p->deferredMoveto );
65722 assert( p->isTable );
65723 rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
65724 if( rc ) return rc;
65725 p->lastRowid = p->movetoTarget;
65726 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
65727 p->rowidIsValid = 1;
65728 #ifdef SQLITE_TEST
65729 sqlite3_search_count++;
65730 #endif
65731 p->deferredMoveto = 0;
65732 p->cacheStatus = CACHE_STALE;
@@ -65747,10 +65927,21 @@
65747 rc = sqlite3BtreeCursorRestore(p->pCursor, &isDifferentRow);
65748 p->cacheStatus = CACHE_STALE;
65749 if( isDifferentRow ) p->nullRow = 1;
65750 return rc;
65751 }
 
 
 
 
 
 
 
 
 
 
 
65752
65753 /*
65754 ** Make sure the cursor p is ready to read or write the row to which it
65755 ** was last positioned. Return an error code if an OOM fault or I/O error
65756 ** prevents us from positioning the cursor to its correct position.
@@ -65765,11 +65956,11 @@
65765 */
65766 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor *p){
65767 if( p->deferredMoveto ){
65768 return handleDeferredMoveto(p);
65769 }
65770 if( sqlite3BtreeCursorHasMoved(p->pCursor) ){
65771 return handleMovedCursor(p);
65772 }
65773 return SQLITE_OK;
65774 }
65775
@@ -67390,10 +67581,11 @@
67390 void (*xDel)(void *),
67391 unsigned char enc
67392 ){
67393 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67394 assert( xDel!=SQLITE_DYNAMIC );
 
67395 if( n>0x7fffffff ){
67396 (void)invokeValueDestructor(z, xDel, pCtx);
67397 }else{
67398 setResultStrOrError(pCtx, z, (int)n, enc, xDel);
67399 }
@@ -68712,125 +68904,10 @@
68712 return sqlite3StrAccumFinish(&out);
68713 }
68714
68715 #endif /* #ifndef SQLITE_OMIT_TRACE */
68716
68717 /*****************************************************************************
68718 ** The following code implements the data-structure explaining logic
68719 ** for the Vdbe.
68720 */
68721
68722 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
68723
68724 /*
68725 ** Allocate a new Explain object
68726 */
68727 SQLITE_PRIVATE void sqlite3ExplainBegin(Vdbe *pVdbe){
68728 if( pVdbe ){
68729 Explain *p;
68730 sqlite3BeginBenignMalloc();
68731 p = (Explain *)sqlite3MallocZero( sizeof(Explain) );
68732 if( p ){
68733 p->pVdbe = pVdbe;
68734 sqlite3_free(pVdbe->pExplain);
68735 pVdbe->pExplain = p;
68736 sqlite3StrAccumInit(&p->str, p->zBase, sizeof(p->zBase),
68737 SQLITE_MAX_LENGTH);
68738 p->str.useMalloc = 2;
68739 }else{
68740 sqlite3EndBenignMalloc();
68741 }
68742 }
68743 }
68744
68745 /*
68746 ** Return true if the Explain ends with a new-line.
68747 */
68748 static int endsWithNL(Explain *p){
68749 return p && p->str.zText && p->str.nChar
68750 && p->str.zText[p->str.nChar-1]=='\n';
68751 }
68752
68753 /*
68754 ** Append text to the indentation
68755 */
68756 SQLITE_PRIVATE void sqlite3ExplainPrintf(Vdbe *pVdbe, const char *zFormat, ...){
68757 Explain *p;
68758 if( pVdbe && (p = pVdbe->pExplain)!=0 ){
68759 va_list ap;
68760 if( p->nIndent && endsWithNL(p) ){
68761 int n = p->nIndent;
68762 if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
68763 sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
68764 }
68765 va_start(ap, zFormat);
68766 sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap);
68767 va_end(ap);
68768 }
68769 }
68770
68771 /*
68772 ** Append a '\n' if there is not already one.
68773 */
68774 SQLITE_PRIVATE void sqlite3ExplainNL(Vdbe *pVdbe){
68775 Explain *p;
68776 if( pVdbe && (p = pVdbe->pExplain)!=0 && !endsWithNL(p) ){
68777 sqlite3StrAccumAppend(&p->str, "\n", 1);
68778 }
68779 }
68780
68781 /*
68782 ** Push a new indentation level. Subsequent lines will be indented
68783 ** so that they begin at the current cursor position.
68784 */
68785 SQLITE_PRIVATE void sqlite3ExplainPush(Vdbe *pVdbe){
68786 Explain *p;
68787 if( pVdbe && (p = pVdbe->pExplain)!=0 ){
68788 if( p->str.zText && p->nIndent<ArraySize(p->aIndent) ){
68789 const char *z = p->str.zText;
68790 int i = p->str.nChar-1;
68791 int x;
68792 while( i>=0 && z[i]!='\n' ){ i--; }
68793 x = (p->str.nChar - 1) - i;
68794 if( p->nIndent && x<p->aIndent[p->nIndent-1] ){
68795 x = p->aIndent[p->nIndent-1];
68796 }
68797 p->aIndent[p->nIndent] = x;
68798 }
68799 p->nIndent++;
68800 }
68801 }
68802
68803 /*
68804 ** Pop the indentation stack by one level.
68805 */
68806 SQLITE_PRIVATE void sqlite3ExplainPop(Vdbe *p){
68807 if( p && p->pExplain ) p->pExplain->nIndent--;
68808 }
68809
68810 /*
68811 ** Free the indentation structure
68812 */
68813 SQLITE_PRIVATE void sqlite3ExplainFinish(Vdbe *pVdbe){
68814 if( pVdbe && pVdbe->pExplain ){
68815 sqlite3_free(pVdbe->zExplain);
68816 sqlite3ExplainNL(pVdbe);
68817 pVdbe->zExplain = sqlite3StrAccumFinish(&pVdbe->pExplain->str);
68818 sqlite3_free(pVdbe->pExplain);
68819 pVdbe->pExplain = 0;
68820 sqlite3EndBenignMalloc();
68821 }
68822 }
68823
68824 /*
68825 ** Return the explanation of a virtual machine.
68826 */
68827 SQLITE_PRIVATE const char *sqlite3VdbeExplanation(Vdbe *pVdbe){
68828 return (pVdbe && pVdbe->zExplain) ? pVdbe->zExplain : 0;
68829 }
68830 #endif /* defined(SQLITE_DEBUG) */
68831
68832 /************** End of vdbetrace.c *******************************************/
68833 /************** Begin file vdbe.c ********************************************/
68834 /*
68835 ** 2001 September 15
68836 **
@@ -69043,10 +69120,11 @@
69043 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
69044 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
69045 memset(pCx, 0, sizeof(VdbeCursor));
69046 pCx->iDb = iDb;
69047 pCx->nField = nField;
 
69048 if( isBtreeCursor ){
69049 pCx->pCursor = (BtCursor*)
69050 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
69051 sqlite3BtreeCursorZero(pCx->pCursor);
69052 }
@@ -70475,21 +70553,14 @@
70475 assert( pOp->p4type==P4_FUNCDEF );
70476 ctx.pFunc = pOp->p4.pFunc;
70477 ctx.iOp = pc;
70478 ctx.pVdbe = p;
70479 MemSetTypeFlag(ctx.pOut, MEM_Null);
70480
70481 ctx.fErrorOrAux = 0;
70482 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
70483 assert( pOp>aOp );
70484 assert( pOp[-1].p4type==P4_COLLSEQ );
70485 assert( pOp[-1].opcode==OP_CollSeq );
70486 ctx.pColl = pOp[-1].p4.pColl;
70487 }
70488 db->lastRowid = lastRowid;
70489 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
70490 lastRowid = db->lastRowid;
70491
70492 /* If the function returned an error, throw an exception */
70493 if( ctx.fErrorOrAux ){
70494 if( ctx.isError ){
70495 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
@@ -71201,11 +71272,11 @@
71201 memAboutToChange(p, pDest);
71202 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71203 pC = p->apCsr[pOp->p1];
71204 assert( pC!=0 );
71205 assert( p2<pC->nField );
71206 aOffset = pC->aType + pC->nField;
71207 #ifndef SQLITE_OMIT_VIRTUALTABLE
71208 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
71209 #endif
71210 pCrsr = pC->pCursor;
71211 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -71212,11 +71283,11 @@
71212 assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
71213
71214 /* If the cursor cache is stale, bring it up-to-date */
71215 rc = sqlite3VdbeCursorMoveto(pC);
71216 if( rc ) goto abort_due_to_error;
71217 if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
71218 if( pC->nullRow ){
71219 if( pCrsr==0 ){
71220 assert( pC->pseudoTableReg>0 );
71221 pReg = &aMem[pC->pseudoTableReg];
71222 assert( pReg->flags & MEM_Blob );
@@ -71257,18 +71328,10 @@
71257 }
71258 pC->cacheStatus = p->cacheCtr;
71259 pC->iHdrOffset = getVarint32(pC->aRow, offset);
71260 pC->nHdrParsed = 0;
71261 aOffset[0] = offset;
71262 if( avail<offset ){
71263 /* pC->aRow does not have to hold the entire row, but it does at least
71264 ** need to cover the header of the record. If pC->aRow does not contain
71265 ** the complete header, then set it to zero, forcing the header to be
71266 ** dynamically allocated. */
71267 pC->aRow = 0;
71268 pC->szRow = 0;
71269 }
71270
71271 /* Make sure a corrupt database has not given us an oversize header.
71272 ** Do this now to avoid an oversize memory allocation.
71273 **
71274 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -71279,19 +71342,36 @@
71279 */
71280 if( offset > 98307 || offset > pC->payloadSize ){
71281 rc = SQLITE_CORRUPT_BKPT;
71282 goto op_column_error;
71283 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71284 }
71285
71286 /* Make sure at least the first p2+1 entries of the header have been
71287 ** parsed and valid information is in aOffset[] and pC->aType[].
71288 */
71289 if( pC->nHdrParsed<=p2 ){
71290 /* If there is more header available for parsing in the record, try
71291 ** to extract additional fields up through the p2+1-th field
71292 */
 
71293 if( pC->iHdrOffset<aOffset[0] ){
71294 /* Make sure zData points to enough of the record to cover the header. */
71295 if( pC->aRow==0 ){
71296 memset(&sMem, 0, sizeof(sMem));
71297 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
@@ -71332,19 +71412,20 @@
71332 if( pC->aRow==0 ){
71333 sqlite3VdbeMemRelease(&sMem);
71334 sMem.flags = MEM_Null;
71335 }
71336
71337 /* If we have read more header data than was contained in the header,
71338 ** or if the end of the last field appears to be past the end of the
71339 ** record, or if the end of the last field appears to be before the end
71340 ** of the record (when all fields present), then we must be dealing
71341 ** with a corrupt database.
 
 
71342 */
71343 if( (zHdr > zEndHdr)
71344 || (offset > pC->payloadSize)
71345 || (zHdr==zEndHdr && offset!=pC->payloadSize)
71346 ){
71347 rc = SQLITE_CORRUPT_BKPT;
71348 goto op_column_error;
71349 }
71350 }
@@ -71531,11 +71612,11 @@
71531 ** out how much space is required for the new record.
71532 */
71533 pRec = pLast;
71534 do{
71535 assert( memIsValid(pRec) );
71536 serial_type = sqlite3VdbeSerialType(pRec, file_format);
71537 len = sqlite3VdbeSerialTypeLen(serial_type);
71538 if( pRec->flags & MEM_Zero ){
71539 if( nData ){
71540 sqlite3VdbeMemExpandBlob(pRec);
71541 }else{
@@ -71580,11 +71661,11 @@
71580 i = putVarint32(zNewRecord, nHdr);
71581 j = nHdr;
71582 assert( pData0<=pLast );
71583 pRec = pData0;
71584 do{
71585 serial_type = sqlite3VdbeSerialType(pRec, file_format);
71586 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
71587 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
71588 }while( (++pRec)<=pLast );
71589 assert( i==nHdr );
71590 assert( j==nByte );
@@ -72205,14 +72286,10 @@
72205 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
72206 pCur->pKeyInfo = pKeyInfo;
72207 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
72208 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
72209
72210 /* Since it performs no memory allocation or IO, the only value that
72211 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
72212 assert( rc==SQLITE_OK );
72213
72214 /* Set the VdbeCursor.isTable variable. Previous versions of
72215 ** SQLite used to check if the root-page flags were sane at this point
72216 ** and report database corruption if they were not, but this check has
72217 ** since moved into the btree layer. */
72218 pCur->isTable = pOp->p4type!=P4_KEYINFO;
@@ -72483,11 +72560,10 @@
72483 pIn3 = &aMem[pOp->p3];
72484 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
72485 applyNumericAffinity(pIn3, 0);
72486 }
72487 iKey = sqlite3VdbeIntValue(pIn3);
72488 pC->rowidIsValid = 0;
72489
72490 /* If the P3 value could not be converted into an integer without
72491 ** loss of information, then special processing is required... */
72492 if( (pIn3->flags & MEM_Int)==0 ){
72493 if( (pIn3->flags & MEM_Real)==0 ){
@@ -72519,17 +72595,14 @@
72519 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
72520 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
72521 }
72522 }
72523 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
 
72524 if( rc!=SQLITE_OK ){
72525 goto abort_due_to_error;
72526 }
72527 if( res==0 ){
72528 pC->rowidIsValid = 1;
72529 pC->lastRowid = iKey;
72530 }
72531 }else{
72532 nField = pOp->p4.i;
72533 assert( pOp->p4type==P4_INT32 );
72534 assert( nField>0 );
72535 r.pKeyInfo = pC->pKeyInfo;
@@ -72555,11 +72628,10 @@
72555 ExpandBlob(r.aMem);
72556 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
72557 if( rc!=SQLITE_OK ){
72558 goto abort_due_to_error;
72559 }
72560 pC->rowidIsValid = 0;
72561 }
72562 pC->deferredMoveto = 0;
72563 pC->cacheStatus = CACHE_STALE;
72564 #ifdef SQLITE_TEST
72565 sqlite3_search_count++;
@@ -72567,21 +72639,19 @@
72567 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
72568 if( res<0 || (res==0 && oc==OP_SeekGT) ){
72569 res = 0;
72570 rc = sqlite3BtreeNext(pC->pCursor, &res);
72571 if( rc!=SQLITE_OK ) goto abort_due_to_error;
72572 pC->rowidIsValid = 0;
72573 }else{
72574 res = 0;
72575 }
72576 }else{
72577 assert( oc==OP_SeekLT || oc==OP_SeekLE );
72578 if( res>0 || (res==0 && oc==OP_SeekLT) ){
72579 res = 0;
72580 rc = sqlite3BtreePrevious(pC->pCursor, &res);
72581 if( rc!=SQLITE_OK ) goto abort_due_to_error;
72582 pC->rowidIsValid = 0;
72583 }else{
72584 /* res might be negative because the table is empty. Check to
72585 ** see if this is the case.
72586 */
72587 res = sqlite3BtreeEof(pC->pCursor);
@@ -72614,11 +72684,10 @@
72614 assert( pC->pCursor!=0 );
72615 assert( pC->isTable );
72616 pC->nullRow = 0;
72617 pIn2 = &aMem[pOp->p2];
72618 pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
72619 pC->rowidIsValid = 0;
72620 pC->deferredMoveto = 1;
72621 break;
72622 }
72623
72624
@@ -72800,19 +72869,17 @@
72800 pCrsr = pC->pCursor;
72801 assert( pCrsr!=0 );
72802 res = 0;
72803 iKey = pIn3->u.i;
72804 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
72805 pC->lastRowid = pIn3->u.i;
72806 pC->rowidIsValid = res==0 ?1:0;
72807 pC->nullRow = 0;
72808 pC->cacheStatus = CACHE_STALE;
72809 pC->deferredMoveto = 0;
72810 VdbeBranchTaken(res!=0,2);
72811 if( res!=0 ){
72812 pc = pOp->p2 - 1;
72813 assert( pC->rowidIsValid==0 );
72814 }
72815 pC->seekResult = res;
72816 break;
72817 }
72818
@@ -72942,36 +73009,24 @@
72942 ** largest possible integer (9223372036854775807) then the database
72943 ** engine starts picking positive candidate ROWIDs at random until
72944 ** it finds one that is not previously used. */
72945 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
72946 ** an AUTOINCREMENT table. */
72947 /* on the first attempt, simply do one more than previous */
72948 v = lastRowid;
72949 v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
72950 v++; /* ensure non-zero */
72951 cnt = 0;
72952 while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
 
 
 
72953 0, &res))==SQLITE_OK)
72954 && (res==0)
72955 && (++cnt<100)){
72956 /* collision - try another random rowid */
72957 sqlite3_randomness(sizeof(v), &v);
72958 if( cnt<5 ){
72959 /* try "small" random rowids for the initial attempts */
72960 v &= 0xffffff;
72961 }else{
72962 v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
72963 }
72964 v++; /* ensure non-zero */
72965 }
72966 if( rc==SQLITE_OK && res==0 ){
72967 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
72968 goto abort_due_to_error;
72969 }
72970 assert( v>0 ); /* EV: R-40812-03570 */
72971 }
72972 pC->rowidIsValid = 0;
72973 pC->deferredMoveto = 0;
72974 pC->cacheStatus = CACHE_STALE;
72975 }
72976 pOut->u.i = v;
72977 break;
@@ -73072,11 +73127,10 @@
73072 }
73073 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
73074 pData->z, pData->n, nZero,
73075 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
73076 );
73077 pC->rowidIsValid = 0;
73078 pC->deferredMoveto = 0;
73079 pC->cacheStatus = CACHE_STALE;
73080
73081 /* Invoke the update-hook if required. */
73082 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
@@ -73109,37 +73163,36 @@
73109 ** pointing to. The update hook will be invoked, if it exists.
73110 ** If P4 is not NULL then the P1 cursor must have been positioned
73111 ** using OP_NotFound prior to invoking this opcode.
73112 */
73113 case OP_Delete: {
73114 i64 iKey;
73115 VdbeCursor *pC;
73116
73117 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73118 pC = p->apCsr[pOp->p1];
73119 assert( pC!=0 );
73120 assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
73121 iKey = pC->lastRowid; /* Only used for the update hook */
73122
73123 /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
73124 ** OP_Column on the same table without any intervening operations that
73125 ** might move or invalidate the cursor. Hence cursor pC is always pointing
73126 ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
73127 ** below is always a no-op and cannot fail. We will run it anyhow, though,
73128 ** to guard against future changes to the code generator.
73129 **/
73130 assert( pC->deferredMoveto==0 );
73131 rc = sqlite3VdbeCursorMoveto(pC);
73132 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
73133
 
 
 
 
 
 
 
 
 
 
 
73134 rc = sqlite3BtreeDelete(pC->pCursor);
73135 pC->cacheStatus = CACHE_STALE;
73136
73137 /* Invoke the update-hook if required. */
73138 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
73139 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
73140 db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
73141 assert( pC->iDb>=0 );
73142 }
73143 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
73144 break;
73145 }
@@ -73188,23 +73241,32 @@
73188 pc = pOp->p2-1;
73189 }
73190 break;
73191 };
73192
73193 /* Opcode: SorterData P1 P2 * * *
73194 ** Synopsis: r[P2]=data
73195 **
73196 ** Write into register P2 the current sorter data for sorter cursor P1.
 
 
 
 
 
 
 
73197 */
73198 case OP_SorterData: {
73199 VdbeCursor *pC;
73200
73201 pOut = &aMem[pOp->p2];
73202 pC = p->apCsr[pOp->p1];
73203 assert( isSorter(pC) );
73204 rc = sqlite3VdbeSorterRowkey(pC, pOut);
73205 assert( rc!=SQLITE_OK || (pOut->flags & MEM_Blob) );
 
 
73206 break;
73207 }
73208
73209 /* Opcode: RowData P1 P2 * * *
73210 ** Synopsis: r[P2]=data
@@ -73247,20 +73309,24 @@
73247 assert( pC!=0 );
73248 assert( pC->nullRow==0 );
73249 assert( pC->pseudoTableReg==0 );
73250 assert( pC->pCursor!=0 );
73251 pCrsr = pC->pCursor;
73252 assert( sqlite3BtreeCursorIsValid(pCrsr) );
73253
73254 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
73255 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
73256 ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
73257 ** a no-op and can never fail. But we leave it in place as a safety.
 
 
73258 */
73259 assert( pC->deferredMoveto==0 );
 
 
73260 rc = sqlite3VdbeCursorMoveto(pC);
73261 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
 
73262
73263 if( pC->isTable==0 ){
73264 assert( !pC->isTable );
73265 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
73266 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
@@ -73273,11 +73339,12 @@
73273 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
73274 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
73275 goto too_big;
73276 }
73277 }
73278 if( sqlite3VdbeMemClearAndResize(pOut, n) ){
 
73279 goto no_mem;
73280 }
73281 pOut->n = n;
73282 MemSetTypeFlag(pOut, MEM_Blob);
73283 if( pC->isTable==0 ){
@@ -73324,18 +73391,14 @@
73324 rc = pModule->xRowid(pC->pVtabCursor, &v);
73325 sqlite3VtabImportErrmsg(p, pVtab);
73326 #endif /* SQLITE_OMIT_VIRTUALTABLE */
73327 }else{
73328 assert( pC->pCursor!=0 );
73329 rc = sqlite3VdbeCursorMoveto(pC);
73330 if( rc ) goto abort_due_to_error;
73331 if( pC->rowidIsValid ){
73332 v = pC->lastRowid;
73333 }else{
73334 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73335 assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
73336 }
73337 }
73338 pOut->u.i = v;
73339 break;
73340 }
73341
@@ -73350,11 +73413,10 @@
73350
73351 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73352 pC = p->apCsr[pOp->p1];
73353 assert( pC!=0 );
73354 pC->nullRow = 1;
73355 pC->rowidIsValid = 0;
73356 pC->cacheStatus = CACHE_STALE;
73357 if( pC->pCursor ){
73358 sqlite3BtreeClearCursor(pC->pCursor);
73359 }
73360 break;
@@ -73384,11 +73446,10 @@
73384 res = 0;
73385 assert( pCrsr!=0 );
73386 rc = sqlite3BtreeLast(pCrsr, &res);
73387 pC->nullRow = (u8)res;
73388 pC->deferredMoveto = 0;
73389 pC->rowidIsValid = 0;
73390 pC->cacheStatus = CACHE_STALE;
73391 #ifdef SQLITE_DEBUG
73392 pC->seekOp = OP_Last;
73393 #endif
73394 if( pOp->p2>0 ){
@@ -73451,11 +73512,10 @@
73451 pCrsr = pC->pCursor;
73452 assert( pCrsr );
73453 rc = sqlite3BtreeFirst(pCrsr, &res);
73454 pC->deferredMoveto = 0;
73455 pC->cacheStatus = CACHE_STALE;
73456 pC->rowidIsValid = 0;
73457 }
73458 pC->nullRow = (u8)res;
73459 assert( pOp->p2>0 && pOp->p2<p->nOp );
73460 VdbeBranchTaken(res!=0,2);
73461 if( res ){
@@ -73577,11 +73637,10 @@
73577 sqlite3_search_count++;
73578 #endif
73579 }else{
73580 pC->nullRow = 1;
73581 }
73582 pC->rowidIsValid = 0;
73583 goto check_for_interrupt;
73584 }
73585
73586 /* Opcode: IdxInsert P1 P2 P3 * P5
73587 ** Synopsis: key=r[P2]
@@ -73693,14 +73752,20 @@
73693 pC = p->apCsr[pOp->p1];
73694 assert( pC!=0 );
73695 pCrsr = pC->pCursor;
73696 assert( pCrsr!=0 );
73697 pOut->flags = MEM_Null;
73698 rc = sqlite3VdbeCursorMoveto(pC);
73699 if( NEVER(rc) ) goto abort_due_to_error;
73700 assert( pC->deferredMoveto==0 );
73701 assert( pC->isTable==0 );
 
 
 
 
 
 
 
73702 if( !pC->nullRow ){
73703 rowid = 0; /* Not needed. Only used to silence a warning. */
73704 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
73705 if( rc!=SQLITE_OK ){
73706 goto abort_due_to_error;
@@ -74556,18 +74621,13 @@
74556 ctx.pMem = pMem = &aMem[pOp->p3];
74557 pMem->n++;
74558 sqlite3VdbeMemInit(&t, db, MEM_Null);
74559 ctx.pOut = &t;
74560 ctx.isError = 0;
74561 ctx.pColl = 0;
 
74562 ctx.skipFlag = 0;
74563 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
74564 assert( pOp>p->aOp );
74565 assert( pOp[-1].p4type==P4_COLLSEQ );
74566 assert( pOp[-1].opcode==OP_CollSeq );
74567 ctx.pColl = pOp[-1].p4.pColl;
74568 }
74569 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
74570 if( ctx.isError ){
74571 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
74572 rc = ctx.isError;
74573 }
@@ -81597,10 +81657,11 @@
81597 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
81598 pNew->addrOpenEphm[0] = -1;
81599 pNew->addrOpenEphm[1] = -1;
81600 pNew->nSelectRow = p->nSelectRow;
81601 pNew->pWith = withDup(db, p->pWith);
 
81602 return pNew;
81603 }
81604 #else
81605 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
81606 assert( p==0 );
@@ -81739,36 +81800,44 @@
81739 }
81740
81741 /*
81742 ** These routines are Walker callbacks. Walker.u.pi is a pointer
81743 ** to an integer. These routines are checking an expression to see
81744 ** if it is a constant. Set *Walker.u.pi to 0 if the expression is
81745 ** not constant.
81746 **
81747 ** These callback routines are used to implement the following:
81748 **
81749 ** sqlite3ExprIsConstant()
81750 ** sqlite3ExprIsConstantNotJoin()
81751 ** sqlite3ExprIsConstantOrFunction()
81752 **
 
 
 
 
 
 
 
 
81753 */
81754 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
81755
81756 /* If pWalker->u.i is 3 then any term of the expression that comes from
81757 ** the ON or USING clauses of a join disqualifies the expression
81758 ** from being considered constant. */
81759 if( pWalker->u.i==3 && ExprHasProperty(pExpr, EP_FromJoin) ){
81760 pWalker->u.i = 0;
81761 return WRC_Abort;
81762 }
81763
81764 switch( pExpr->op ){
81765 /* Consider functions to be constant if all their arguments are constant
81766 ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST
81767 ** flag. */
81768 case TK_FUNCTION:
81769 if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){
81770 return WRC_Continue;
81771 }
81772 /* Fall through */
81773 case TK_ID:
81774 case TK_COLUMN:
@@ -81778,10 +81847,23 @@
81778 testcase( pExpr->op==TK_COLUMN );
81779 testcase( pExpr->op==TK_AGG_FUNCTION );
81780 testcase( pExpr->op==TK_AGG_COLUMN );
81781 pWalker->u.i = 0;
81782 return WRC_Abort;
 
 
 
 
 
 
 
 
 
 
 
 
 
81783 default:
81784 testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
81785 testcase( pExpr->op==TK_EXISTS ); /* selectNodeIsConstant will disallow */
81786 return WRC_Continue;
81787 }
@@ -81818,11 +81900,11 @@
81818 ** that does no originate from the ON or USING clauses of a join.
81819 ** Return 0 if it involves variables or function calls or terms from
81820 ** an ON or USING clause.
81821 */
81822 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
81823 return exprIsConst(p, 3);
81824 }
81825
81826 /*
81827 ** Walk an expression tree. Return 1 if the expression is constant
81828 ** or a function call with constant arguments. Return and 0 if there
@@ -81830,12 +81912,13 @@
81830 **
81831 ** For the purposes of this function, a double-quoted string (ex: "abc")
81832 ** is considered a variable but a single-quoted string (ex: 'abc') is
81833 ** a constant.
81834 */
81835 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p){
81836 return exprIsConst(p, 2);
 
81837 }
81838
81839 /*
81840 ** If the expression p codes a constant integer that is small enough
81841 ** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -83741,94 +83824,90 @@
83741 iMem = ++pParse->nMem;
83742 sqlite3VdbeAddOp2(v, OP_Copy, target, iMem);
83743 exprToRegister(pExpr, iMem);
83744 }
83745
83746 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
83747 /*
83748 ** Generate a human-readable explanation of an expression tree.
83749 */
83750 SQLITE_PRIVATE void sqlite3ExplainExpr(Vdbe *pOut, Expr *pExpr){
83751 int op; /* The opcode being coded */
83752 const char *zBinOp = 0; /* Binary operator */
83753 const char *zUniOp = 0; /* Unary operator */
 
83754 if( pExpr==0 ){
83755 op = TK_NULL;
83756 }else{
83757 op = pExpr->op;
83758 }
83759 switch( op ){
83760 case TK_AGG_COLUMN: {
83761 sqlite3ExplainPrintf(pOut, "AGG{%d:%d}",
83762 pExpr->iTable, pExpr->iColumn);
83763 break;
83764 }
83765 case TK_COLUMN: {
83766 if( pExpr->iTable<0 ){
83767 /* This only happens when coding check constraints */
83768 sqlite3ExplainPrintf(pOut, "COLUMN(%d)", pExpr->iColumn);
83769 }else{
83770 sqlite3ExplainPrintf(pOut, "{%d:%d}",
83771 pExpr->iTable, pExpr->iColumn);
83772 }
83773 break;
83774 }
83775 case TK_INTEGER: {
83776 if( pExpr->flags & EP_IntValue ){
83777 sqlite3ExplainPrintf(pOut, "%d", pExpr->u.iValue);
83778 }else{
83779 sqlite3ExplainPrintf(pOut, "%s", pExpr->u.zToken);
83780 }
83781 break;
83782 }
83783 #ifndef SQLITE_OMIT_FLOATING_POINT
83784 case TK_FLOAT: {
83785 sqlite3ExplainPrintf(pOut,"%s", pExpr->u.zToken);
83786 break;
83787 }
83788 #endif
83789 case TK_STRING: {
83790 sqlite3ExplainPrintf(pOut,"%Q", pExpr->u.zToken);
83791 break;
83792 }
83793 case TK_NULL: {
83794 sqlite3ExplainPrintf(pOut,"NULL");
83795 break;
83796 }
83797 #ifndef SQLITE_OMIT_BLOB_LITERAL
83798 case TK_BLOB: {
83799 sqlite3ExplainPrintf(pOut,"%s", pExpr->u.zToken);
83800 break;
83801 }
83802 #endif
83803 case TK_VARIABLE: {
83804 sqlite3ExplainPrintf(pOut,"VARIABLE(%s,%d)",
83805 pExpr->u.zToken, pExpr->iColumn);
83806 break;
83807 }
83808 case TK_REGISTER: {
83809 sqlite3ExplainPrintf(pOut,"REGISTER(%d)", pExpr->iTable);
83810 break;
83811 }
83812 case TK_AS: {
83813 sqlite3ExplainExpr(pOut, pExpr->pLeft);
 
 
 
 
 
83814 break;
83815 }
83816 #ifndef SQLITE_OMIT_CAST
83817 case TK_CAST: {
83818 /* Expressions of the form: CAST(pLeft AS token) */
83819 const char *zAff = "unk";
83820 switch( sqlite3AffinityType(pExpr->u.zToken, 0) ){
83821 case SQLITE_AFF_TEXT: zAff = "TEXT"; break;
83822 case SQLITE_AFF_NONE: zAff = "NONE"; break;
83823 case SQLITE_AFF_NUMERIC: zAff = "NUMERIC"; break;
83824 case SQLITE_AFF_INTEGER: zAff = "INTEGER"; break;
83825 case SQLITE_AFF_REAL: zAff = "REAL"; break;
83826 }
83827 sqlite3ExplainPrintf(pOut, "CAST-%s(", zAff);
83828 sqlite3ExplainExpr(pOut, pExpr->pLeft);
83829 sqlite3ExplainPrintf(pOut, ")");
83830 break;
83831 }
83832 #endif /* SQLITE_OMIT_CAST */
83833 case TK_LT: zBinOp = "LT"; break;
83834 case TK_LE: zBinOp = "LE"; break;
@@ -83848,21 +83927,22 @@
83848 case TK_BITOR: zBinOp = "BITOR"; break;
83849 case TK_SLASH: zBinOp = "DIV"; break;
83850 case TK_LSHIFT: zBinOp = "LSHIFT"; break;
83851 case TK_RSHIFT: zBinOp = "RSHIFT"; break;
83852 case TK_CONCAT: zBinOp = "CONCAT"; break;
 
83853
83854 case TK_UMINUS: zUniOp = "UMINUS"; break;
83855 case TK_UPLUS: zUniOp = "UPLUS"; break;
83856 case TK_BITNOT: zUniOp = "BITNOT"; break;
83857 case TK_NOT: zUniOp = "NOT"; break;
83858 case TK_ISNULL: zUniOp = "ISNULL"; break;
83859 case TK_NOTNULL: zUniOp = "NOTNULL"; break;
83860
83861 case TK_COLLATE: {
83862 sqlite3ExplainExpr(pOut, pExpr->pLeft);
83863 sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
83864 break;
83865 }
83866
83867 case TK_AGG_FUNCTION:
83868 case TK_FUNCTION: {
@@ -83870,45 +83950,40 @@
83870 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
83871 pFarg = 0;
83872 }else{
83873 pFarg = pExpr->x.pList;
83874 }
83875 if( op==TK_AGG_FUNCTION ){
83876 sqlite3ExplainPrintf(pOut, "AGG_FUNCTION%d:%s(",
83877 pExpr->op2, pExpr->u.zToken);
83878 }else{
83879 sqlite3ExplainPrintf(pOut, "FUNCTION:%s(", pExpr->u.zToken);
83880 }
83881 if( pFarg ){
83882 sqlite3ExplainExprList(pOut, pFarg);
83883 }
83884 sqlite3ExplainPrintf(pOut, ")");
83885 break;
83886 }
83887 #ifndef SQLITE_OMIT_SUBQUERY
83888 case TK_EXISTS: {
83889 sqlite3ExplainPrintf(pOut, "EXISTS(");
83890 sqlite3ExplainSelect(pOut, pExpr->x.pSelect);
83891 sqlite3ExplainPrintf(pOut,")");
83892 break;
83893 }
83894 case TK_SELECT: {
83895 sqlite3ExplainPrintf(pOut, "(");
83896 sqlite3ExplainSelect(pOut, pExpr->x.pSelect);
83897 sqlite3ExplainPrintf(pOut, ")");
83898 break;
83899 }
83900 case TK_IN: {
83901 sqlite3ExplainPrintf(pOut, "IN(");
83902 sqlite3ExplainExpr(pOut, pExpr->pLeft);
83903 sqlite3ExplainPrintf(pOut, ",");
83904 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
83905 sqlite3ExplainSelect(pOut, pExpr->x.pSelect);
83906 }else{
83907 sqlite3ExplainExprList(pOut, pExpr->x.pList);
83908 }
83909 sqlite3ExplainPrintf(pOut, ")");
83910 break;
83911 }
83912 #endif /* SQLITE_OMIT_SUBQUERY */
83913
83914 /*
@@ -83924,17 +83999,14 @@
83924 */
83925 case TK_BETWEEN: {
83926 Expr *pX = pExpr->pLeft;
83927 Expr *pY = pExpr->x.pList->a[0].pExpr;
83928 Expr *pZ = pExpr->x.pList->a[1].pExpr;
83929 sqlite3ExplainPrintf(pOut, "BETWEEN(");
83930 sqlite3ExplainExpr(pOut, pX);
83931 sqlite3ExplainPrintf(pOut, ",");
83932 sqlite3ExplainExpr(pOut, pY);
83933 sqlite3ExplainPrintf(pOut, ",");
83934 sqlite3ExplainExpr(pOut, pZ);
83935 sqlite3ExplainPrintf(pOut, ")");
83936 break;
83937 }
83938 case TK_TRIGGER: {
83939 /* If the opcode is TK_TRIGGER, then the expression is a reference
83940 ** to a column in the new.* or old.* pseudo-tables available to
@@ -83941,19 +84013,18 @@
83941 ** trigger programs. In this case Expr.iTable is set to 1 for the
83942 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
83943 ** is set to the column of the pseudo-table to read, or to -1 to
83944 ** read the rowid field.
83945 */
83946 sqlite3ExplainPrintf(pOut, "%s(%d)",
83947 pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn);
83948 break;
83949 }
83950 case TK_CASE: {
83951 sqlite3ExplainPrintf(pOut, "CASE(");
83952 sqlite3ExplainExpr(pOut, pExpr->pLeft);
83953 sqlite3ExplainPrintf(pOut, ",");
83954 sqlite3ExplainExprList(pOut, pExpr->x.pList);
83955 break;
83956 }
83957 #ifndef SQLITE_OMIT_TRIGGER
83958 case TK_RAISE: {
83959 const char *zType = "unk";
@@ -83961,59 +84032,61 @@
83961 case OE_Rollback: zType = "rollback"; break;
83962 case OE_Abort: zType = "abort"; break;
83963 case OE_Fail: zType = "fail"; break;
83964 case OE_Ignore: zType = "ignore"; break;
83965 }
83966 sqlite3ExplainPrintf(pOut, "RAISE-%s(%s)", zType, pExpr->u.zToken);
83967 break;
83968 }
83969 #endif
 
 
 
 
83970 }
83971 if( zBinOp ){
83972 sqlite3ExplainPrintf(pOut,"%s(", zBinOp);
83973 sqlite3ExplainExpr(pOut, pExpr->pLeft);
83974 sqlite3ExplainPrintf(pOut,",");
83975 sqlite3ExplainExpr(pOut, pExpr->pRight);
83976 sqlite3ExplainPrintf(pOut,")");
83977 }else if( zUniOp ){
83978 sqlite3ExplainPrintf(pOut,"%s(", zUniOp);
83979 sqlite3ExplainExpr(pOut, pExpr->pLeft);
83980 sqlite3ExplainPrintf(pOut,")");
83981 }
83982 }
83983 #endif /* defined(SQLITE_ENABLE_TREE_EXPLAIN) */
83984
83985 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
83986 /*
83987 ** Generate a human-readable explanation of an expression list.
83988 */
83989 SQLITE_PRIVATE void sqlite3ExplainExprList(Vdbe *pOut, ExprList *pList){
 
 
 
 
 
83990 int i;
83991 if( pList==0 || pList->nExpr==0 ){
83992 sqlite3ExplainPrintf(pOut, "(empty-list)");
83993 return;
83994 }else if( pList->nExpr==1 ){
83995 sqlite3ExplainExpr(pOut, pList->a[0].pExpr);
83996 }else{
83997 sqlite3ExplainPush(pOut);
83998 for(i=0; i<pList->nExpr; i++){
83999 sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
84000 sqlite3ExplainPush(pOut);
84001 sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
84002 sqlite3ExplainPop(pOut);
84003 if( pList->a[i].zName ){
84004 sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
84005 }
84006 if( pList->a[i].bSpanIsTab ){
84007 sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
84008 }
84009 if( i<pList->nExpr-1 ){
84010 sqlite3ExplainNL(pOut);
84011 }
84012 }
84013 sqlite3ExplainPop(pOut);
84014 }
 
84015 }
84016 #endif /* SQLITE_DEBUG */
84017
84018 /*
84019 ** Generate code that pushes the value of every element of the given
@@ -87130,29 +87203,27 @@
87130 tRowcnt v;
87131
87132 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87133 if( z==0 ) z = "";
87134 #else
87135 if( NEVER(z==0) ) z = "";
87136 #endif
87137 for(i=0; *z && i<nOut; i++){
87138 v = 0;
87139 while( (c=z[0])>='0' && c<='9' ){
87140 v = v*10 + c - '0';
87141 z++;
87142 }
87143 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87144 if( aOut ){
87145 aOut[i] = v;
87146 }else
87147 #else
87148 assert( aOut==0 );
87149 UNUSED_PARAMETER(aOut);
 
 
87150 #endif
87151 {
87152 aLog[i] = sqlite3LogEst(v);
87153 }
87154 if( *z==' ' ) z++;
87155 }
87156 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
87157 assert( pIndex!=0 );
87158 #else
@@ -87209,12 +87280,21 @@
87209 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
87210 }
87211 z = argv[2];
87212
87213 if( pIndex ){
 
 
 
 
 
 
 
 
 
87214 pIndex->bUnordered = 0;
87215 decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex);
87216 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
87217 }else{
87218 Index fakeIdx;
87219 fakeIdx.szIdxRow = pTable->szTabRow;
87220 #ifdef SQLITE_ENABLE_COSTMULT
@@ -87269,29 +87349,42 @@
87269 ** unique. */
87270 nCol = pIdx->nSampleCol-1;
87271 pIdx->aAvgEq[nCol] = 1;
87272 }
87273 for(iCol=0; iCol<nCol; iCol++){
 
87274 int i; /* Used to iterate through samples */
87275 tRowcnt sumEq = 0; /* Sum of the nEq values */
87276 tRowcnt nSum = 0; /* Number of terms contributing to sumEq */
87277 tRowcnt avgEq = 0;
87278 tRowcnt nDLt = pFinal->anDLt[iCol];
 
 
 
 
 
 
 
 
 
 
 
87279
87280 /* Set nSum to the number of distinct (iCol+1) field prefixes that
87281 ** occur in the stat4 table for this index before pFinal. Set
87282 ** sumEq to the sum of the nEq values for column iCol for the same
87283 ** set (adding the value only once where there exist duplicate
87284 ** prefixes). */
87285 for(i=0; i<(pIdx->nSample-1); i++){
87286 if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
 
87287 sumEq += aSample[i].anEq[iCol];
87288 nSum++;
87289 }
87290 }
87291 if( nDLt>nSum ){
87292 avgEq = (pFinal->anLt[iCol] - sumEq)/(nDLt - nSum);
 
87293 }
87294 if( avgEq==0 ) avgEq = 1;
87295 pIdx->aAvgEq[iCol] = avgEq;
87296 }
87297 }
@@ -87538,10 +87631,15 @@
87538 if( rc==SQLITE_OK ){
87539 int lookasideEnabled = db->lookaside.bEnabled;
87540 db->lookaside.bEnabled = 0;
87541 rc = loadStat4(db, sInfo.zDatabase);
87542 db->lookaside.bEnabled = lookasideEnabled;
 
 
 
 
 
87543 }
87544 #endif
87545
87546 if( rc==SQLITE_NOMEM ){
87547 db->mallocFailed = 1;
@@ -88832,10 +88930,13 @@
88832 #endif
88833 if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
88834 sqlite3ExprDelete(db, p->pPartIdxWhere);
88835 sqlite3DbFree(db, p->zColAff);
88836 if( p->isResized ) sqlite3DbFree(db, p->azColl);
 
 
 
88837 sqlite3DbFree(db, p);
88838 }
88839
88840 /*
88841 ** For the index called zIdxName which is found in the database iDb,
@@ -89633,11 +89734,11 @@
89633 Column *pCol;
89634 sqlite3 *db = pParse->db;
89635 p = pParse->pNewTable;
89636 if( p!=0 ){
89637 pCol = &(p->aCol[p->nCol-1]);
89638 if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr) ){
89639 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
89640 pCol->zName);
89641 }else{
89642 /* A copy of pExpr is used instead of the original, as pExpr contains
89643 ** tokens that point to volatile memory. The 'span' of the expression
@@ -91141,11 +91242,11 @@
91141 pIndex->nKeyCol); VdbeCoverage(v);
91142 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
91143 }else{
91144 addr2 = sqlite3VdbeCurrentAddr(v);
91145 }
91146 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
91147 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
91148 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
91149 sqlite3ReleaseTempReg(pParse, regRecord);
91150 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
91151 sqlite3VdbeJumpHere(v, addr1);
@@ -94030,11 +94131,14 @@
94030
94031 /*
94032 ** Return the collating function associated with a function.
94033 */
94034 static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
94035 return context->pColl;
 
 
 
94036 }
94037
94038 /*
94039 ** Indicate that the accumulator load should be skipped on this
94040 ** iteration of the aggregate loop.
@@ -94575,14 +94679,16 @@
94575 ** character is exactly one byte in size. Also, all characters are
94576 ** able to participate in upper-case-to-lower-case mappings in EBCDIC
94577 ** whereas only characters less than 0x80 do in ASCII.
94578 */
94579 #if defined(SQLITE_EBCDIC)
94580 # define sqlite3Utf8Read(A) (*((*A)++))
94581 # define GlobUpperToLower(A) A = sqlite3UpperToLower[A]
 
94582 #else
94583 # define GlobUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
 
94584 #endif
94585
94586 static const struct compareInfo globInfo = { '*', '?', '[', 0 };
94587 /* The correct SQL-92 behavior is for the LIKE operator to ignore
94588 ** case. Thus 'a' LIKE 'A' would be true. */
@@ -94591,11 +94697,11 @@
94591 ** is case sensitive causing 'a' LIKE 'A' to be false */
94592 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
94593
94594 /*
94595 ** Compare two UTF-8 strings for equality where the first string can
94596 ** potentially be a "glob" expression. Return true (1) if they
94597 ** are the same and false (0) if they are different.
94598 **
94599 ** Globbing rules:
94600 **
94601 ** '*' Matches any sequence of zero or more characters.
@@ -94611,120 +94717,147 @@
94611 ** in the list by making it the first character after '[' or '^'. A
94612 ** range of characters can be specified using '-'. Example:
94613 ** "[a-z]" matches any single lower-case letter. To match a '-', make
94614 ** it the last character in the list.
94615 **
 
 
 
 
 
 
 
 
 
 
 
94616 ** This routine is usually quick, but can be N**2 in the worst case.
94617 **
94618 ** Hints: to match '*' or '?', put them in "[]". Like this:
94619 **
94620 ** abc[*]xyz Matches "abc*xyz" only
94621 */
94622 static int patternCompare(
94623 const u8 *zPattern, /* The glob pattern */
94624 const u8 *zString, /* The string to compare against the glob */
94625 const struct compareInfo *pInfo, /* Information about how to do the compare */
94626 u32 esc /* The escape character */
94627 ){
94628 u32 c, c2;
94629 int invert;
94630 int seen;
94631 u8 matchOne = pInfo->matchOne;
94632 u8 matchAll = pInfo->matchAll;
94633 u8 matchSet = pInfo->matchSet;
94634 u8 noCase = pInfo->noCase;
94635 int prevEscape = 0; /* True if the previous character was 'escape' */
 
 
 
 
 
94636
94637 while( (c = sqlite3Utf8Read(&zPattern))!=0 ){
94638 if( c==matchAll && !prevEscape ){
 
 
 
94639 while( (c=sqlite3Utf8Read(&zPattern)) == matchAll
94640 || c == matchOne ){
94641 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
94642 return 0;
94643 }
94644 }
94645 if( c==0 ){
94646 return 1;
94647 }else if( c==esc ){
94648 c = sqlite3Utf8Read(&zPattern);
94649 if( c==0 ){
94650 return 0;
94651 }
94652 }else if( c==matchSet ){
94653 assert( esc==0 ); /* This is GLOB, not LIKE */
94654 assert( matchSet<0x80 ); /* '[' is a single-byte character */
94655 while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
94656 SQLITE_SKIP_UTF8(zString);
94657 }
94658 return *zString!=0;
94659 }
94660 while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
94661 if( noCase ){
94662 GlobUpperToLower(c2);
94663 GlobUpperToLower(c);
94664 while( c2 != 0 && c2 != c ){
94665 c2 = sqlite3Utf8Read(&zString);
94666 GlobUpperToLower(c2);
94667 }
94668 }else{
94669 while( c2 != 0 && c2 != c ){
94670 c2 = sqlite3Utf8Read(&zString);
94671 }
94672 }
94673 if( c2==0 ) return 0;
94674 if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
94675 }
94676 return 0;
94677 }else if( c==matchOne && !prevEscape ){
94678 if( sqlite3Utf8Read(&zString)==0 ){
94679 return 0;
94680 }
94681 }else if( c==matchSet ){
94682 u32 prior_c = 0;
94683 assert( esc==0 ); /* This only occurs for GLOB, not LIKE */
94684 seen = 0;
94685 invert = 0;
94686 c = sqlite3Utf8Read(&zString);
94687 if( c==0 ) return 0;
94688 c2 = sqlite3Utf8Read(&zPattern);
94689 if( c2=='^' ){
94690 invert = 1;
94691 c2 = sqlite3Utf8Read(&zPattern);
94692 }
94693 if( c2==']' ){
94694 if( c==']' ) seen = 1;
94695 c2 = sqlite3Utf8Read(&zPattern);
94696 }
94697 while( c2 && c2!=']' ){
94698 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
94699 c2 = sqlite3Utf8Read(&zPattern);
94700 if( c>=prior_c && c<=c2 ) seen = 1;
94701 prior_c = 0;
94702 }else{
94703 if( c==c2 ){
94704 seen = 1;
94705 }
94706 prior_c = c2;
94707 }
94708 c2 = sqlite3Utf8Read(&zPattern);
94709 }
94710 if( c2==0 || (seen ^ invert)==0 ){
94711 return 0;
94712 }
94713 }else if( esc==c && !prevEscape ){
94714 prevEscape = 1;
94715 }else{
94716 c2 = sqlite3Utf8Read(&zString);
94717 if( noCase ){
94718 GlobUpperToLower(c);
94719 GlobUpperToLower(c2);
94720 }
94721 if( c!=c2 ){
94722 return 0;
94723 }
94724 prevEscape = 0;
94725 }
 
 
 
 
 
 
 
 
 
 
 
 
94726 }
94727 return *zString==0;
94728 }
94729
94730 /*
@@ -103884,10 +104017,24 @@
103884 **
103885 *************************************************************************
103886 ** This file contains C code routines that are called by the parser
103887 ** to handle SELECT statements in SQLite.
103888 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103889
103890 /*
103891 ** An instance of the following object is used to record information about
103892 ** how to process the DISTINCT keyword, to simplify passing that information
103893 ** into the selectInnerLoop() routine.
@@ -103996,10 +104143,22 @@
103996 assert( pNew->pSrc!=0 || pParse->nErr>0 );
103997 }
103998 assert( pNew!=&standin );
103999 return pNew;
104000 }
 
 
 
 
 
 
 
 
 
 
 
 
104001
104002 /*
104003 ** Delete the given Select structure and all of its substructures.
104004 */
104005 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
@@ -105026,11 +105185,10 @@
105026 int regRow;
105027 int regRowid;
105028 int nKey;
105029 int iSortTab; /* Sorter cursor to read from */
105030 int nSortData; /* Trailing values to read from sorter */
105031 u8 p5; /* p5 parameter for 1st OP_Column */
105032 int i;
105033 int bSeq; /* True if sorter record includes seq. no. */
105034 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
105035 struct ExprList_item *aOutEx = p->pEList->a;
105036 #endif
@@ -105060,23 +105218,20 @@
105060 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
105061 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
105062 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
105063 VdbeCoverage(v);
105064 codeOffset(v, p->iOffset, addrContinue);
105065 sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
105066 p5 = OPFLAG_CLEARCACHE;
105067 bSeq = 0;
105068 }else{
105069 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
105070 codeOffset(v, p->iOffset, addrContinue);
105071 iSortTab = iTab;
105072 p5 = 0;
105073 bSeq = 1;
105074 }
105075 for(i=0; i<nSortData; i++){
105076 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
105077 if( i==0 ) sqlite3VdbeChangeP5(v, p5);
105078 VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
105079 }
105080 switch( eDest ){
105081 case SRT_Table:
105082 case SRT_EphemTab: {
@@ -107226,10 +107381,12 @@
107226 }
107227 }
107228 }
107229
107230 /***** If we reach this point, flattening is permitted. *****/
 
 
107231
107232 /* Authorize the subquery */
107233 pParse->zAuthContext = pSubitem->zName;
107234 TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
107235 testcase( i==SQLITE_DENY );
@@ -107278,10 +107435,11 @@
107278 p->pSrc = 0;
107279 p->pPrior = 0;
107280 p->pLimit = 0;
107281 p->pOffset = 0;
107282 pNew = sqlite3SelectDup(db, p, 0);
 
107283 p->pOffset = pOffset;
107284 p->pLimit = pLimit;
107285 p->pOrderBy = pOrderBy;
107286 p->pSrc = pSrc;
107287 p->op = TK_ALL;
@@ -107290,10 +107448,13 @@
107290 }else{
107291 pNew->pPrior = pPrior;
107292 if( pPrior ) pPrior->pNext = pNew;
107293 pNew->pNext = p;
107294 p->pPrior = pNew;
 
 
 
107295 }
107296 if( db->mallocFailed ) return 1;
107297 }
107298
107299 /* Begin flattening the iFrom-th entry of the FROM clause
@@ -107419,12 +107580,27 @@
107419 if( isAgg ){
107420 substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
107421 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
107422 }
107423 if( pSub->pOrderBy ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107424 assert( pParent->pOrderBy==0 );
107425 pParent->pOrderBy = pSub->pOrderBy;
 
107426 pSub->pOrderBy = 0;
107427 }else if( pParent->pOrderBy ){
107428 substExprList(db, pParent->pOrderBy, iParent, pSub->pEList);
107429 }
107430 if( pSub->pWhere ){
@@ -107465,10 +107641,17 @@
107465
107466 /* Finially, delete what is left of the subquery and return
107467 ** success.
107468 */
107469 sqlite3SelectDelete(db, pSub1);
 
 
 
 
 
 
 
107470
107471 return 1;
107472 }
107473 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
107474
@@ -107936,10 +108119,11 @@
107936 if( pTab->pSelect || IsVirtual(pTab) ){
107937 /* We reach here if the named table is a really a view */
107938 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
107939 assert( pFrom->pSelect==0 );
107940 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
 
107941 sqlite3WalkSelect(pWalker, pFrom->pSelect);
107942 }
107943 #endif
107944 }
107945
@@ -108470,10 +108654,17 @@
108470 if( p==0 || db->mallocFailed || pParse->nErr ){
108471 return 1;
108472 }
108473 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
108474 memset(&sAggInfo, 0, sizeof(sAggInfo));
 
 
 
 
 
 
 
108475
108476 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
108477 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
108478 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
108479 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Queue );
@@ -108626,10 +108817,14 @@
108626 /* If there is are a sequence of queries, do the earlier ones first.
108627 */
108628 if( p->pPrior ){
108629 rc = multiSelect(pParse, p, pDest);
108630 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
 
 
 
 
108631 return rc;
108632 }
108633 #endif
108634
108635 /* If the query is DISTINCT with an ORDER BY but is not an aggregate, and
@@ -108961,16 +109156,15 @@
108961 ** from the previous row currently stored in a0, a1, a2...
108962 */
108963 addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
108964 sqlite3ExprCacheClear(pParse);
108965 if( groupBySort ){
108966 sqlite3VdbeAddOp2(v, OP_SorterData, sAggInfo.sortingIdx, sortOut);
108967 }
108968 for(j=0; j<pGroupBy->nExpr; j++){
108969 if( groupBySort ){
108970 sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
108971 if( j==0 ) sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
108972 }else{
108973 sAggInfo.directMode = 1;
108974 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
108975 }
108976 }
@@ -109225,107 +109419,110 @@
109225 generateColumnNames(pParse, pTabList, pEList);
109226 }
109227
109228 sqlite3DbFree(db, sAggInfo.aCol);
109229 sqlite3DbFree(db, sAggInfo.aFunc);
 
 
 
 
109230 return rc;
109231 }
109232
109233 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
109234 /*
109235 ** Generate a human-readable description of a the Select object.
109236 */
109237 static void explainOneSelect(Vdbe *pVdbe, Select *p){
109238 sqlite3ExplainPrintf(pVdbe, "SELECT ");
109239 if( p->selFlags & (SF_Distinct|SF_Aggregate) ){
109240 if( p->selFlags & SF_Distinct ){
109241 sqlite3ExplainPrintf(pVdbe, "DISTINCT ");
109242 }
109243 if( p->selFlags & SF_Aggregate ){
109244 sqlite3ExplainPrintf(pVdbe, "agg_flag ");
109245 }
109246 sqlite3ExplainNL(pVdbe);
109247 sqlite3ExplainPrintf(pVdbe, " ");
109248 }
109249 sqlite3ExplainExprList(pVdbe, p->pEList);
109250 sqlite3ExplainNL(pVdbe);
 
 
109251 if( p->pSrc && p->pSrc->nSrc ){
109252 int i;
109253 sqlite3ExplainPrintf(pVdbe, "FROM ");
109254 sqlite3ExplainPush(pVdbe);
109255 for(i=0; i<p->pSrc->nSrc; i++){
109256 struct SrcList_item *pItem = &p->pSrc->a[i];
109257 sqlite3ExplainPrintf(pVdbe, "{%d,*} = ", pItem->iCursor);
109258 if( pItem->pSelect ){
109259 sqlite3ExplainSelect(pVdbe, pItem->pSelect);
109260 if( pItem->pTab ){
109261 sqlite3ExplainPrintf(pVdbe, " (tabname=%s)", pItem->pTab->zName);
109262 }
109263 }else if( pItem->zName ){
109264 sqlite3ExplainPrintf(pVdbe, "%s", pItem->zName);
 
 
 
109265 }
109266 if( pItem->zAlias ){
109267 sqlite3ExplainPrintf(pVdbe, " (AS %s)", pItem->zAlias);
109268 }
109269 if( pItem->jointype & JT_LEFT ){
109270 sqlite3ExplainPrintf(pVdbe, " LEFT-JOIN");
109271 }
109272 sqlite3ExplainNL(pVdbe);
 
 
 
 
 
109273 }
109274 sqlite3ExplainPop(pVdbe);
109275 }
109276 if( p->pWhere ){
109277 sqlite3ExplainPrintf(pVdbe, "WHERE ");
109278 sqlite3ExplainExpr(pVdbe, p->pWhere);
109279 sqlite3ExplainNL(pVdbe);
109280 }
109281 if( p->pGroupBy ){
109282 sqlite3ExplainPrintf(pVdbe, "GROUPBY ");
109283 sqlite3ExplainExprList(pVdbe, p->pGroupBy);
109284 sqlite3ExplainNL(pVdbe);
109285 }
109286 if( p->pHaving ){
109287 sqlite3ExplainPrintf(pVdbe, "HAVING ");
109288 sqlite3ExplainExpr(pVdbe, p->pHaving);
109289 sqlite3ExplainNL(pVdbe);
109290 }
109291 if( p->pOrderBy ){
109292 sqlite3ExplainPrintf(pVdbe, "ORDERBY ");
109293 sqlite3ExplainExprList(pVdbe, p->pOrderBy);
109294 sqlite3ExplainNL(pVdbe);
109295 }
109296 if( p->pLimit ){
109297 sqlite3ExplainPrintf(pVdbe, "LIMIT ");
109298 sqlite3ExplainExpr(pVdbe, p->pLimit);
109299 sqlite3ExplainNL(pVdbe);
109300 }
109301 if( p->pOffset ){
109302 sqlite3ExplainPrintf(pVdbe, "OFFSET ");
109303 sqlite3ExplainExpr(pVdbe, p->pOffset);
109304 sqlite3ExplainNL(pVdbe);
109305 }
109306 }
109307 SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){
109308 if( p==0 ){
109309 sqlite3ExplainPrintf(pVdbe, "(null-select)");
109310 return;
109311 }
109312 sqlite3ExplainPush(pVdbe);
109313 while( p ){
109314 explainOneSelect(pVdbe, p);
109315 p = p->pNext;
109316 if( p==0 ) break;
109317 sqlite3ExplainNL(pVdbe);
109318 sqlite3ExplainPrintf(pVdbe, "%s\n", selectOpName(p->op));
109319 }
109320 sqlite3ExplainPrintf(pVdbe, "END");
109321 sqlite3ExplainPop(pVdbe);
109322 }
109323
109324 /* End of the structure debug printing code
109325 *****************************************************************************/
109326 #endif /* defined(SQLITE_ENABLE_TREE_EXPLAIN) */
109327
109328 /************** End of select.c **********************************************/
109329 /************** Begin file table.c *******************************************/
109330 /*
109331 ** 2001 September 15
@@ -112311,10 +112508,11 @@
112311 }
112312 sqlite3DbFree(db, pVTable);
112313 }else if( ALWAYS(pVTable->pVtab) ){
112314 /* Justification of ALWAYS(): A correct vtab constructor must allocate
112315 ** the sqlite3_vtab object if successful. */
 
112316 pVTable->pVtab->pModule = pMod->pModule;
112317 pVTable->nRef = 1;
112318 if( sCtx.pTab ){
112319 const char *zFormat = "vtable constructor did not declare schema: %s";
112320 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
@@ -113719,15 +113917,10 @@
113719 assert( TK_LE>TK_EQ && TK_LE<TK_GE );
113720 assert( TK_GE==TK_EQ+4 );
113721 return op==TK_IN || (op>=TK_EQ && op<=TK_GE) || op==TK_ISNULL;
113722 }
113723
113724 /*
113725 ** Swap two objects of type TYPE.
113726 */
113727 #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
113728
113729 /*
113730 ** Commute a comparison operator. Expressions of the form "X op Y"
113731 ** are converted into "Y op X".
113732 **
113733 ** If left/right precedence rules come into play when determining the
@@ -115566,21 +115759,28 @@
115566 ** have been requested when testing key $P in whereEqualScanEst(). */
115567 whereKeyStats(pParse, p, pRec, 0, a);
115568 iLower = a[0];
115569 iUpper = a[0] + a[1];
115570 }
 
 
 
 
 
 
 
 
115571
115572 /* If possible, improve on the iLower estimate using ($P:$L). */
115573 if( pLower ){
115574 int bOk; /* True if value is extracted from pExpr */
115575 Expr *pExpr = pLower->pExpr->pRight;
115576 assert( (pLower->eOperator & (WO_GT|WO_GE))!=0 );
115577 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115578 if( rc==SQLITE_OK && bOk ){
115579 tRowcnt iNew;
115580 whereKeyStats(pParse, p, pRec, 0, a);
115581 iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
115582 if( iNew>iLower ) iLower = iNew;
115583 nOut--;
115584 pLower = 0;
115585 }
115586 }
@@ -115587,16 +115787,15 @@
115587
115588 /* If possible, improve on the iUpper estimate using ($P:$U). */
115589 if( pUpper ){
115590 int bOk; /* True if value is extracted from pExpr */
115591 Expr *pExpr = pUpper->pExpr->pRight;
115592 assert( (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
115593 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115594 if( rc==SQLITE_OK && bOk ){
115595 tRowcnt iNew;
115596 whereKeyStats(pParse, p, pRec, 1, a);
115597 iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
115598 if( iNew<iUpper ) iUpper = iNew;
115599 nOut--;
115600 pUpper = 0;
115601 }
115602 }
@@ -116091,65 +116290,52 @@
116091 sqlite3StrAccumAppend(pStr, "?", 1);
116092 }
116093
116094 /*
116095 ** Argument pLevel describes a strategy for scanning table pTab. This
116096 ** function returns a pointer to a string buffer containing a description
116097 ** of the subset of table rows scanned by the strategy in the form of an
116098 ** SQL expression. Or, if all rows are scanned, NULL is returned.
116099 **
116100 ** For example, if the query:
116101 **
116102 ** SELECT * FROM t1 WHERE a=1 AND b>2;
116103 **
116104 ** is run and there is an index on (a, b), then this function returns a
116105 ** string similar to:
116106 **
116107 ** "a=? AND b>?"
116108 **
116109 ** The returned pointer points to memory obtained from sqlite3DbMalloc().
116110 ** It is the responsibility of the caller to free the buffer when it is
116111 ** no longer required.
116112 */
116113 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
116114 Index *pIndex = pLoop->u.btree.pIndex;
116115 u16 nEq = pLoop->u.btree.nEq;
116116 u16 nSkip = pLoop->u.btree.nSkip;
116117 int i, j;
116118 Column *aCol = pTab->aCol;
116119 i16 *aiColumn = pIndex->aiColumn;
116120 StrAccum txt;
116121
116122 if( nEq==0 && (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ){
116123 return 0;
116124 }
116125 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
116126 txt.db = db;
116127 sqlite3StrAccumAppend(&txt, " (", 2);
116128 for(i=0; i<nEq; i++){
116129 char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
116130 if( i>=nSkip ){
116131 explainAppendTerm(&txt, i, z, "=");
116132 }else{
116133 if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
116134 sqlite3StrAccumAppend(&txt, "ANY(", 4);
116135 sqlite3StrAccumAppendAll(&txt, z);
116136 sqlite3StrAccumAppend(&txt, ")", 1);
116137 }
116138 }
116139
116140 j = i;
116141 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
116142 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116143 explainAppendTerm(&txt, i++, z, ">");
116144 }
116145 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
116146 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116147 explainAppendTerm(&txt, i, z, "<");
116148 }
116149 sqlite3StrAccumAppend(&txt, ")", 1);
116150 return sqlite3StrAccumFinish(&txt);
116151 }
116152
116153 /*
116154 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116155 ** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
@@ -116169,72 +116355,90 @@
116169 #endif
116170 {
116171 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116172 Vdbe *v = pParse->pVdbe; /* VM being constructed */
116173 sqlite3 *db = pParse->db; /* Database handle */
116174 char *zMsg; /* Text to add to EQP output */
116175 int iId = pParse->iSelectId; /* Select id (left-most output column) */
116176 int isSearch; /* True for a SEARCH. False for SCAN. */
116177 WhereLoop *pLoop; /* The controlling WhereLoop object */
116178 u32 flags; /* Flags that describe this loop */
 
 
 
116179
116180 pLoop = pLevel->pWLoop;
116181 flags = pLoop->wsFlags;
116182 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
116183
116184 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116185 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116186 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116187
116188 zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
 
 
116189 if( pItem->pSelect ){
116190 zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
116191 }else{
116192 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
116193 }
116194
116195 if( pItem->zAlias ){
116196 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
116197 }
116198 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0
116199 && ALWAYS(pLoop->u.btree.pIndex!=0)
116200 ){
116201 const char *zFmt;
116202 Index *pIdx = pLoop->u.btree.pIndex;
116203 char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
116204 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116205 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116206 zFmt = zWhere ? "%s USING PRIMARY KEY%.0s%s" : "%s%.0s%s";
 
 
116207 }else if( flags & WHERE_AUTO_INDEX ){
116208 zFmt = "%s USING AUTOMATIC COVERING INDEX%.0s%s";
116209 }else if( flags & WHERE_IDX_ONLY ){
116210 zFmt = "%s USING COVERING INDEX %s%s";
116211 }else{
116212 zFmt = "%s USING INDEX %s%s";
116213 }
116214 zMsg = sqlite3MAppendf(db, zMsg, zFmt, zMsg, pIdx->zName, zWhere);
116215 sqlite3DbFree(db, zWhere);
 
 
 
116216 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
116217 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
116218
116219 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
116220 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
116221 }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
116222 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
116223 }else if( flags&WHERE_BTM_LIMIT ){
116224 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
116225 }else if( ALWAYS(flags&WHERE_TOP_LIMIT) ){
116226 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
 
116227 }
 
 
116228 }
116229 #ifndef SQLITE_OMIT_VIRTUALTABLE
116230 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
116231 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
116232 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
116233 }
116234 #endif
116235 zMsg = sqlite3MAppendf(db, zMsg, "%s", zMsg);
 
 
 
 
 
 
 
116236 sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116237 }
116238 }
116239 #else
116240 # define explainOneScan(u,v,w,x,y,z)
@@ -116884,12 +117088,13 @@
116884
116885 /* Run a separate WHERE clause for each term of the OR clause. After
116886 ** eliminating duplicates from other WHERE clauses, the action for each
116887 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
116888 */
116889 wctrlFlags = WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
116890 WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY;
 
116891 for(ii=0; ii<pOrWc->nTerm; ii++){
116892 WhereTerm *pOrTerm = &pOrWc->a[ii];
116893 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
116894 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
116895 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -116897,10 +117102,11 @@
116897 if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
116898 pAndExpr->pLeft = pOrExpr;
116899 pOrExpr = pAndExpr;
116900 }
116901 /* Loop through table entries that match term pOrTerm. */
 
116902 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
116903 wctrlFlags, iCovCur);
116904 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
116905 if( pSubWInfo ){
116906 WhereLoop *pSubLoop;
@@ -117116,25 +117322,30 @@
117116 }
117117
117118 return pLevel->notReady;
117119 }
117120
117121 #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
117122 /*
117123 ** Generate "Explanation" text for a WhereTerm.
117124 */
117125 static void whereExplainTerm(Vdbe *v, WhereTerm *pTerm){
117126 char zType[4];
117127 memcpy(zType, "...", 4);
117128 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
117129 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
117130 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
117131 sqlite3ExplainPrintf(v, "%s ", zType);
117132 sqlite3ExplainExpr(v, pTerm->pExpr);
117133 }
117134 #endif /* WHERETRACE_ENABLED && SQLITE_ENABLE_TREE_EXPLAIN */
117135
 
 
 
 
 
117136
117137 #ifdef WHERETRACE_ENABLED
117138 /*
117139 ** Print a WhereLoop object for debugging purposes
117140 */
@@ -117174,31 +117385,16 @@
117174 sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip);
117175 }else{
117176 sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
117177 }
117178 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
117179 #ifdef SQLITE_ENABLE_TREE_EXPLAIN
117180 /* If the 0x100 bit of wheretracing is set, then show all of the constraint
117181 ** expressions in the WhereLoop.aLTerm[] array.
117182 */
117183 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ /* WHERETRACE 0x100 */
117184 int i;
117185 Vdbe *v = pWInfo->pParse->pVdbe;
117186 sqlite3ExplainBegin(v);
117187 for(i=0; i<p->nLTerm; i++){
117188 WhereTerm *pTerm = p->aLTerm[i];
117189 if( pTerm==0 ) continue;
117190 sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
117191 sqlite3ExplainPush(v);
117192 whereExplainTerm(v, pTerm);
117193 sqlite3ExplainPop(v);
117194 sqlite3ExplainNL(v);
117195 }
117196 sqlite3ExplainFinish(v);
117197 sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
117198 }
117199 #endif
117200 }
117201 #endif
117202
117203 /*
117204 ** Convert bulk memory into a valid WhereLoop that can be passed
@@ -117507,11 +117703,11 @@
117507 if( ppPrev==0 ){
117508 /* There already exists a WhereLoop on the list that is better
117509 ** than pTemplate, so just ignore pTemplate */
117510 #if WHERETRACE_ENABLED /* 0x8 */
117511 if( sqlite3WhereTrace & 0x8 ){
117512 sqlite3DebugPrintf("ins-noop: ");
117513 whereLoopPrint(pTemplate, pBuilder->pWC);
117514 }
117515 #endif
117516 return SQLITE_OK;
117517 }else{
@@ -117523,14 +117719,14 @@
117523 ** WhereLoop and insert it.
117524 */
117525 #if WHERETRACE_ENABLED /* 0x8 */
117526 if( sqlite3WhereTrace & 0x8 ){
117527 if( p!=0 ){
117528 sqlite3DebugPrintf("ins-del: ");
117529 whereLoopPrint(p, pBuilder->pWC);
117530 }
117531 sqlite3DebugPrintf("ins-new: ");
117532 whereLoopPrint(pTemplate, pBuilder->pWC);
117533 }
117534 #endif
117535 if( p==0 ){
117536 /* Allocate a new WhereLoop to add to the end of the list */
@@ -117550,11 +117746,11 @@
117550 pToDel = *ppTail;
117551 if( pToDel==0 ) break;
117552 *ppTail = pToDel->pNextLoop;
117553 #if WHERETRACE_ENABLED /* 0x8 */
117554 if( sqlite3WhereTrace & 0x8 ){
117555 sqlite3DebugPrintf("ins-del: ");
117556 whereLoopPrint(pToDel, pBuilder->pWC);
117557 }
117558 #endif
117559 whereLoopDelete(db, pToDel);
117560 }
@@ -117714,15 +117910,18 @@
117714 pNew->aLTerm[pNew->nLTerm++] = 0;
117715 pNew->wsFlags |= WHERE_SKIPSCAN;
117716 nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
117717 if( pTerm ){
117718 /* TUNING: When estimating skip-scan for a term that is also indexable,
117719 ** increase the cost of the skip-scan by 2x, to make it a little less
117720 ** desirable than the regular index lookup. */
117721 nIter += 10; assert( 10==sqlite3LogEst(2) );
117722 }
117723 pNew->nOut -= nIter;
 
 
 
117724 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
117725 pNew->nOut = saved_nOut;
117726 pNew->u.btree.nEq = saved_nEq;
117727 pNew->u.btree.nSkip = saved_nSkip;
117728 }
@@ -118073,13 +118272,21 @@
118073 pNew->u.btree.nSkip = 0;
118074 pNew->u.btree.pIndex = 0;
118075 pNew->nLTerm = 1;
118076 pNew->aLTerm[0] = pTerm;
118077 /* TUNING: One-time cost for computing the automatic index is
118078 ** approximately 7*N*log2(N) where N is the number of rows in
118079 ** the table being indexed. */
118080 pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
 
 
 
 
 
 
 
 
118081 ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
118082 /* TUNING: Each index lookup yields 20 rows in the table. This
118083 ** is more than the usual guess of 10 rows, since we have no way
118084 ** of knowing how selective the index will ultimately be. It would
118085 ** not be unreasonable to make this value much larger. */
@@ -118363,11 +118570,10 @@
118363 WhereLoopBuilder sSubBuild;
118364 WhereOrSet sSum, sCur;
118365 struct SrcList_item *pItem;
118366
118367 pWC = pBuilder->pWC;
118368 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
118369 pWCEnd = pWC->a + pWC->nTerm;
118370 pNew = pBuilder->pNew;
118371 memset(&sSum, 0, sizeof(sSum));
118372 pItem = pWInfo->pTabList->a + pNew->iTab;
118373 iCur = pItem->iCursor;
@@ -118384,10 +118590,11 @@
118384
118385 sSubBuild = *pBuilder;
118386 sSubBuild.pOrderBy = 0;
118387 sSubBuild.pOrSet = &sCur;
118388
 
118389 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
118390 if( (pOrTerm->eOperator & WO_AND)!=0 ){
118391 sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
118392 }else if( pOrTerm->leftCursor==iCur ){
118393 tempWC.pWInfo = pWC->pWInfo;
@@ -118398,18 +118605,30 @@
118398 sSubBuild.pWC = &tempWC;
118399 }else{
118400 continue;
118401 }
118402 sCur.n = 0;
 
 
 
 
 
 
 
 
 
118403 #ifndef SQLITE_OMIT_VIRTUALTABLE
118404 if( IsVirtual(pItem->pTab) ){
118405 rc = whereLoopAddVirtual(&sSubBuild, mExtra);
118406 }else
118407 #endif
118408 {
118409 rc = whereLoopAddBtree(&sSubBuild, mExtra);
118410 }
 
 
 
118411 assert( rc==SQLITE_OK || sCur.n==0 );
118412 if( sCur.n==0 ){
118413 sSum.n = 0;
118414 break;
118415 }else if( once ){
@@ -118450,10 +118669,11 @@
118450 pNew->rRun = sSum.a[i].rRun + 1;
118451 pNew->nOut = sSum.a[i].nOut;
118452 pNew->prereq = sSum.a[i].prereq;
118453 rc = whereLoopInsert(pBuilder, pNew);
118454 }
 
118455 }
118456 }
118457 return rc;
118458 }
118459
@@ -118693,11 +118913,11 @@
118693 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
118694 }
118695 isMatch = 1;
118696 break;
118697 }
118698 if( isMatch && (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
118699 /* Make sure the sort order is compatible in an ORDER BY clause.
118700 ** Sort order is irrelevant for a GROUP BY clause. */
118701 if( revSet ){
118702 if( (rev ^ revIdx)!=pOrderBy->a[i].sortOrder ) isMatch = 0;
118703 }else{
@@ -119158,16 +119378,19 @@
119158 pWInfo->revMask = pFrom->revLoop;
119159 }
119160 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
119161 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
119162 ){
119163 Bitmask notUsed = 0;
119164 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
119165 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed
119166 );
119167 assert( pWInfo->sorted==0 );
119168 pWInfo->sorted = (nOrder==pWInfo->pOrderBy->nExpr);
 
 
 
119169 }
119170 }
119171
119172
119173 pWInfo->nRowOut = pFrom->nRow;
@@ -119516,27 +119739,20 @@
119516 }
119517 }
119518
119519 /* Construct the WhereLoop objects */
119520 WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
 
119521 /* Display all terms of the WHERE clause */
119522 #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
119523 if( sqlite3WhereTrace & 0x100 ){
119524 int i;
119525 Vdbe *v = pParse->pVdbe;
119526 sqlite3ExplainBegin(v);
119527 for(i=0; i<sWLB.pWC->nTerm; i++){
119528 sqlite3ExplainPrintf(v, "#%-2d ", i);
119529 sqlite3ExplainPush(v);
119530 whereExplainTerm(v, &sWLB.pWC->a[i]);
119531 sqlite3ExplainPop(v);
119532 sqlite3ExplainNL(v);
119533 }
119534 sqlite3ExplainFinish(v);
119535 sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
119536 }
119537 #endif
 
119538 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
119539 rc = whereLoopAddAll(&sWLB);
119540 if( rc ) goto whereBeginError;
119541
119542 /* Display all of the WhereLoop objects if wheretrace is enabled */
@@ -120059,11 +120275,11 @@
120059
120060 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
120061 ** unary TK_ISNULL or TK_NOTNULL expression. */
120062 static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
120063 sqlite3 *db = pParse->db;
120064 if( db->mallocFailed==0 && pY->op==TK_NULL ){
120065 pA->op = (u8)op;
120066 sqlite3ExprDelete(db, pA->pRight);
120067 pA->pRight = 0;
120068 }
120069 }
@@ -122318,13 +122534,10 @@
122318 break;
122319 case 111: /* cmd ::= select */
122320 {
122321 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
122322 sqlite3Select(pParse, yymsp[0].minor.yy3, &dest);
122323 sqlite3ExplainBegin(pParse->pVdbe);
122324 sqlite3ExplainSelect(pParse->pVdbe, yymsp[0].minor.yy3);
122325 sqlite3ExplainFinish(pParse->pVdbe);
122326 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
122327 }
122328 break;
122329 case 112: /* select ::= with selectnowith */
122330 {
@@ -122377,10 +122590,34 @@
122377 {yygotominor.yy328 = TK_ALL;}
122378 break;
122379 case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
122380 {
122381 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy14,yymsp[-5].minor.yy65,yymsp[-4].minor.yy132,yymsp[-3].minor.yy14,yymsp[-2].minor.yy132,yymsp[-1].minor.yy14,yymsp[-7].minor.yy381,yymsp[0].minor.yy476.pLimit,yymsp[0].minor.yy476.pOffset);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122382 }
122383 break;
122384 case 120: /* values ::= VALUES LP nexprlist RP */
122385 {
122386 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
@@ -123868,10 +124105,11 @@
123868 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */
123869 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */
123870 };
123871 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
123872 #endif
 
123873
123874
123875 /*
123876 ** Return the length of the token that begins at z[0].
123877 ** Store the token type in *tokenType before returning.
@@ -125138,10 +125376,15 @@
125138 sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
125139 sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
125140 break;
125141 }
125142
 
 
 
 
 
125143 case SQLITE_CONFIG_URI: {
125144 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
125145 break;
125146 }
125147
@@ -126875,11 +127118,11 @@
126875 int nUri = sqlite3Strlen30(zUri);
126876
126877 assert( *pzErrMsg==0 );
126878
126879 if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
126880 && nUri>=5 && memcmp(zUri, "file:", 5)==0
126881 ){
126882 char *zOpt;
126883 int eState; /* Parser state when parsing URI */
126884 int iIn; /* Input character index */
126885 int iOut = 0; /* Output character index */
@@ -127105,11 +127348,13 @@
127105 assert( SQLITE_OPEN_READWRITE == 0x02 );
127106 assert( SQLITE_OPEN_CREATE == 0x04 );
127107 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
127108 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
127109 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
127110 if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE_BKPT;
 
 
127111
127112 if( sqlite3GlobalConfig.bCoreMutex==0 ){
127113 isThreadsafe = 0;
127114 }else if( flags & SQLITE_OPEN_NOMUTEX ){
127115 isThreadsafe = 0;
@@ -127989,26 +128234,10 @@
127989 case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
127990 sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
127991 break;
127992 }
127993
127994 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
127995 /* sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT,
127996 ** sqlite3_stmt*,const char**);
127997 **
127998 ** If compiled with SQLITE_ENABLE_TREE_EXPLAIN, each sqlite3_stmt holds
127999 ** a string that describes the optimized parse tree. This test-control
128000 ** returns a pointer to that string.
128001 */
128002 case SQLITE_TESTCTRL_EXPLAIN_STMT: {
128003 sqlite3_stmt *pStmt = va_arg(ap, sqlite3_stmt*);
128004 const char **pzRet = va_arg(ap, const char**);
128005 *pzRet = sqlite3VdbeExplanation((Vdbe*)pStmt);
128006 break;
128007 }
128008 #endif
128009
128010 /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
128011 **
128012 ** Set or clear a flag that indicates that the database file is always well-
128013 ** formed and never corrupt. This flag is clear by default, indicating that
128014 ** database files might have arbitrary corruption. Setting the flag during
@@ -132464,10 +132693,11 @@
132464 assert( iIdx==nVal );
132465
132466 /* In case the cursor has been used before, clear it now. */
132467 sqlite3_finalize(pCsr->pStmt);
132468 sqlite3_free(pCsr->aDoclist);
 
132469 sqlite3Fts3ExprFree(pCsr->pExpr);
132470 memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
132471
132472 /* Set the lower and upper bounds on docids to return */
132473 pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
@@ -133774,11 +134004,11 @@
133774 if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
133775 iMax = a[i].iDocid;
133776 bMaxSet = 1;
133777 }
133778 }
133779 assert( rc!=SQLITE_OK || a[p->nToken-1].bIgnore==0 );
133780 assert( rc!=SQLITE_OK || bMaxSet );
133781
133782 /* Keep advancing iterators until they all point to the same document */
133783 for(i=0; i<p->nToken; i++){
133784 while( rc==SQLITE_OK && bEof==0
@@ -135891,11 +136121,11 @@
135891 int i = 0;
135892
135893 /* Set variable i to the maximum number of bytes of input to tokenize. */
135894 for(i=0; i<n; i++){
135895 if( sqlite3_fts3_enable_parentheses && (z[i]=='(' || z[i]==')') ) break;
135896 if( z[i]=='*' || z[i]=='"' ) break;
135897 }
135898
135899 *pnConsumed = i;
135900 rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, i, &pCursor);
135901 if( rc==SQLITE_OK ){
135902
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.7"
235 #define SQLITE_VERSION_NUMBER 3008007
236 #define SQLITE_SOURCE_ID "2014-10-15 15:28:27 3c1e70f4d55bc009ed9ed4cf6d756d7061985851"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -2791,13 +2791,13 @@
2791 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
2792 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
2793 ** an English language description of the error following a failure of any
2794 ** of the sqlite3_open() routines.
2795 **
2796 ** ^The default encoding will be UTF-8 for databases created using
2797 ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
2798 ** created using sqlite3_open16() will be UTF-16 in the native byte order.
2799 **
2800 ** Whether or not an error occurs when it is opened, resources
2801 ** associated with the [database connection] handle should be released by
2802 ** passing it to [sqlite3_close()] when it is no longer required.
2803 **
@@ -2881,17 +2881,18 @@
2881 ** ^SQLite uses the path component of the URI as the name of the disk file
2882 ** which contains the database. ^If the path begins with a '/' character,
2883 ** then it is interpreted as an absolute path. ^If the path does not begin
2884 ** with a '/' (meaning that the authority section is omitted from the URI)
2885 ** then the path is interpreted as a relative path.
2886 ** ^(On windows, the first component of an absolute path
2887 ** is a drive specification (e.g. "C:").)^
2888 **
2889 ** [[core URI query parameters]]
2890 ** The query component of a URI may contain parameters that are interpreted
2891 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
2892 ** SQLite and its built-in [VFSes] interpret the
2893 ** following query parameters:
2894 **
2895 ** <ul>
2896 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
2897 ** a VFS object that provides the operating system interface that should
2898 ** be used to access the database file on disk. ^If this option is set to
@@ -2922,15 +2923,13 @@
2923 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2924 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2925 ** a URI filename, its value overrides any behavior requested by setting
2926 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2927 **
2928 ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
 
2929 ** [powersafe overwrite] property does or does not apply to the
2930 ** storage media on which the database file resides.
 
2931 **
2932 ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
2933 ** which if set disables file locking in rollback journal modes. This
2934 ** is useful for accessing a database on a filesystem that does not
2935 ** support locking. Caution: Database corruption might result if two
@@ -3521,15 +3520,14 @@
3520 ** terminated. If any NUL characters occur at byte offsets less than
3521 ** the value of the fourth parameter then the resulting string value will
3522 ** contain embedded NULs. The result of expressions involving strings
3523 ** with embedded NULs is undefined.
3524 **
3525 ** ^The fifth argument to the BLOB and string binding interfaces
3526 ** is a destructor used to dispose of the BLOB or
3527 ** string after SQLite has finished with it. ^The destructor is called
3528 ** to dispose of the BLOB or string even if the call to bind API fails.
 
3529 ** ^If the fifth argument is
3530 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3531 ** information is in static, unmanaged space and does not need to be freed.
3532 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3533 ** SQLite makes its own private copy of the data immediately, before
@@ -3536,11 +3534,11 @@
3534 ** the sqlite3_bind_*() routine returns.
3535 **
3536 ** ^The sixth argument to sqlite3_bind_text64() must be one of
3537 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3538 ** to specify the encoding of the text in the third parameter. If
3539 ** the sixth argument to sqlite3_bind_text64() is not one of the
3540 ** allowed values shown above, or if the text encoding is different
3541 ** from the encoding specified by the sixth parameter, then the behavior
3542 ** is undefined.
3543 **
3544 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
@@ -4572,11 +4570,11 @@
4570 **
4571 ** ^The sqlite3_result_null() interface sets the return value
4572 ** of the application-defined function to be NULL.
4573 **
4574 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4575 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4576 ** set the return value of the application-defined function to be
4577 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4578 ** UTF-16 little endian, or UTF-16 big endian, respectively.
4579 ** ^The sqlite3_result_text64() interface sets the return value of an
4580 ** application-defined function to be a text string in an encoding
@@ -6332,11 +6330,11 @@
6330 #define SQLITE_TESTCTRL_RESERVE 14
6331 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6332 #define SQLITE_TESTCTRL_ISKEYWORD 16
6333 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6334 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6335 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
6336 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6337 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6338 #define SQLITE_TESTCTRL_BYTEORDER 22
6339 #define SQLITE_TESTCTRL_ISINIT 23
6340 #define SQLITE_TESTCTRL_SORTER_MMAP 24
@@ -7946,11 +7944,11 @@
7944 ** A macro to hint to the compiler that a function should not be
7945 ** inlined.
7946 */
7947 #if defined(__GNUC__)
7948 # define SQLITE_NOINLINE __attribute__((noinline))
7949 #elif defined(_MSC_VER) && _MSC_VER>=1310
7950 # define SQLITE_NOINLINE __declspec(noinline)
7951 #else
7952 # define SQLITE_NOINLINE
7953 #endif
7954
@@ -8519,10 +8517,15 @@
8517 ** Macros to compute minimum and maximum of two numbers.
8518 */
8519 #define MIN(A,B) ((A)<(B)?(A):(B))
8520 #define MAX(A,B) ((A)>(B)?(A):(B))
8521
8522 /*
8523 ** Swap two objects of type TYPE.
8524 */
8525 #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
8526
8527 /*
8528 ** Check to see if this machine uses EBCDIC. (Yes, believe it or
8529 ** not, there are still machines out there that use EBCDIC.)
8530 */
8531 #if 'A' == '\301'
@@ -8756,10 +8759,20 @@
8759 # define SQLITE_ENABLE_STAT3_OR_STAT4 1
8760 #elif SQLITE_ENABLE_STAT3_OR_STAT4
8761 # undef SQLITE_ENABLE_STAT3_OR_STAT4
8762 #endif
8763
8764 /*
8765 ** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
8766 ** the Select query generator tracing logic is turned on.
8767 */
8768 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE)
8769 # define SELECTTRACE_ENABLED 1
8770 #else
8771 # define SELECTTRACE_ENABLED 0
8772 #endif
8773
8774 /*
8775 ** An instance of the following structure is used to store the busy-handler
8776 ** callback for a given sqlite handle.
8777 **
8778 ** The sqlite.busyHandler member of the sqlite struct contains the busy
@@ -8895,10 +8908,11 @@
8908 typedef struct SrcList SrcList;
8909 typedef struct StrAccum StrAccum;
8910 typedef struct Table Table;
8911 typedef struct TableLock TableLock;
8912 typedef struct Token Token;
8913 typedef struct TreeView TreeView;
8914 typedef struct Trigger Trigger;
8915 typedef struct TriggerPrg TriggerPrg;
8916 typedef struct TriggerStep TriggerStep;
8917 typedef struct UnpackedRecord UnpackedRecord;
8918 typedef struct VTable VTable;
@@ -11308,10 +11322,11 @@
11322 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
11323 int nSample; /* Number of elements in aSample[] */
11324 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
11325 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11326 IndexSample *aSample; /* Samples of the left-most key */
11327 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */
11328 #endif
11329 };
11330
11331 /*
11332 ** Allowed values for Index.idxType
@@ -11738,11 +11753,11 @@
11753 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
11754 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
11755 #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
11756 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
11757 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11758 /* 0x0080 // not currently used */
11759 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
11760 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
11761 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
11762 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
11763 #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
@@ -11823,10 +11838,13 @@
11838 struct Select {
11839 ExprList *pEList; /* The fields of the result */
11840 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
11841 u16 selFlags; /* Various SF_* values */
11842 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
11843 #if SELECTTRACE_ENABLED
11844 char zSelName[12]; /* Symbolic name of this SELECT use for debugging */
11845 #endif
11846 int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
11847 u64 nSelectRow; /* Estimated number of result rows */
11848 SrcList *pSrc; /* The FROM clause */
11849 Expr *pWhere; /* The WHERE clause */
11850 ExprList *pGroupBy; /* The GROUP BY clause */
@@ -12081,10 +12099,14 @@
12099 yDbMask cookieMask; /* Bitmask of schema verified databases */
12100 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
12101 int regRowid; /* Register holding rowid of CREATE TABLE entry */
12102 int regRoot; /* Register holding root page number for new objects */
12103 int nMaxArg; /* Max args passed to user function by sub-program */
12104 #if SELECTTRACE_ENABLED
12105 int nSelect; /* Number of SELECT statements seen */
12106 int nSelectIndent; /* How far to indent SELECTTRACE() output */
12107 #endif
12108 #ifndef SQLITE_OMIT_SHARED_CACHE
12109 int nTableLock; /* Number of locks in aTableLock */
12110 TableLock *aTableLock; /* Required table locks for shared-cache mode */
12111 #endif
12112 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -12160,15 +12182,15 @@
12182
12183 /*
12184 ** Bitfield flags for P5 value in various opcodes.
12185 */
12186 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
12187 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
12188 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
12189 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
12190 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
12191 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
 
12192 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
12193 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
12194 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
12195 #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */
12196 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
@@ -12428,10 +12450,21 @@
12450 Select *pSelect; /* The definition of this CTE */
12451 const char *zErr; /* Error message for circular references */
12452 } a[1];
12453 };
12454
12455 #ifdef SQLITE_DEBUG
12456 /*
12457 ** An instance of the TreeView object is used for printing the content of
12458 ** data structures on sqlite3DebugPrintf() using a tree-like view.
12459 */
12460 struct TreeView {
12461 int iLevel; /* Which level of the tree we are on */
12462 u8 bLine[100]; /* Draw vertical in column i if bLine[i] is true */
12463 };
12464 #endif /* SQLITE_DEBUG */
12465
12466 /*
12467 ** Assuming zIn points to the first byte of a UTF-8 character,
12468 ** advance zIn to point to the first byte of the next UTF-8 character.
12469 */
12470 #define SQLITE_SKIP_UTF8(zIn) { \
@@ -12493,10 +12526,11 @@
12526 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
12527 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
12528 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
12529 # define sqlite3Tolower(x) tolower((unsigned char)(x))
12530 #endif
12531 SQLITE_PRIVATE int sqlite3IsIdChar(u8);
12532
12533 /*
12534 ** Internal function prototypes
12535 */
12536 #define sqlite3StrICmp sqlite3_stricmp
@@ -12591,29 +12625,18 @@
12625 #endif
12626 #if defined(SQLITE_TEST)
12627 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
12628 #endif
12629
12630 #if defined(SQLITE_DEBUG)
12631 SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView*,u8);
12632 SQLITE_PRIVATE void sqlite3TreeViewPop(TreeView*);
12633 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView*, const char*, ...);
12634 SQLITE_PRIVATE void sqlite3TreeViewItem(TreeView*, const char*, u8);
12635 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
12636 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
12637 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
 
 
 
 
 
 
 
 
 
 
 
12638 #endif
12639
12640
12641 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*, ...);
12642 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -12791,11 +12814,11 @@
12814 SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
12815 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
12816 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
12817 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12818 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12819 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
12820 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12821 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12822 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12823 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12824 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -12815,10 +12838,15 @@
12838 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
12839 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
12840 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
12841 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*);
12842 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int);
12843 #if SELECTTRACE_ENABLED
12844 SQLITE_PRIVATE void sqlite3SelectSetName(Select*,const char*);
12845 #else
12846 # define sqlite3SelectSetName(A,B)
12847 #endif
12848 SQLITE_PRIVATE void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*);
12849 SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8);
12850 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3*);
12851 SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void);
12852 SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void);
@@ -13292,14 +13320,13 @@
13320 # define sqlite3MemdebugSetType(X,Y) /* no-op */
13321 # define sqlite3MemdebugHasType(X,Y) 1
13322 # define sqlite3MemdebugNoType(X,Y) 1
13323 #endif
13324 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
13325 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
13326 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
13327 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
 
13328
13329 /*
13330 ** Threading interface
13331 */
13332 #if SQLITE_MAX_WORKER_THREADS>0
@@ -13439,10 +13466,17 @@
13466 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
13467 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
13468 };
13469 #endif
13470
13471 /* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
13472 ** compatibility for legacy applications, the URI filename capability is
13473 ** disabled by default.
13474 **
13475 ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
13476 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
13477 */
13478 #ifndef SQLITE_USE_URI
13479 # define SQLITE_USE_URI 0
13480 #endif
13481
13482 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
@@ -13945,11 +13979,11 @@
13979
13980 /* Since ArraySize(azCompileOpt) is normally in single digits, a
13981 ** linear search is adequate. No need for a binary search. */
13982 for(i=0; i<ArraySize(azCompileOpt); i++){
13983 if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
13984 && sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0
13985 ){
13986 return 1;
13987 }
13988 }
13989 return 0;
@@ -14060,21 +14094,19 @@
14094 #ifdef SQLITE_DEBUG
14095 u8 seekOp; /* Most recent seek operation on this cursor */
14096 #endif
14097 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
14098 u8 nullRow; /* True if pointing to a row with no data */
 
14099 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
14100 Bool isEphemeral:1; /* True for an ephemeral table */
14101 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
14102 Bool isTable:1; /* True if a table requiring integer keys */
14103 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
14104 Pgno pgnoRoot; /* Root page of the open btree cursor */
14105 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
14106 i64 seqCount; /* Sequence counter */
14107 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
 
14108 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
14109
14110 /* Cached information about the header for the data record that the
14111 ** cursor is currently pointing to. Only valid if cacheStatus matches
14112 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -14087,10 +14119,11 @@
14119 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
14120 u32 payloadSize; /* Total number of bytes in the record */
14121 u32 szRow; /* Byte available in aRow */
14122 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
14123 const u8 *aRow; /* Data for the current row, if all on one page */
14124 u32 *aOffset; /* Pointer to aType[nField] */
14125 u32 aType[1]; /* Type values for all entries in the record */
14126 /* 2*nField extra array elements allocated for aType[], beyond the one
14127 ** static element declared in the structure. nField total array slots for
14128 ** aType[] and nField+1 array slots for aOffset[] */
14129 };
@@ -14163,11 +14196,11 @@
14196 int n; /* Number of characters in string value, excluding '\0' */
14197 char *z; /* String or BLOB value */
14198 /* ShallowCopy only needs to copy the information above */
14199 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
14200 int szMalloc; /* Size of the zMalloc allocation */
14201 u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
14202 sqlite3 *db; /* The associated database connection */
14203 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
14204 #ifdef SQLITE_DEBUG
14205 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
14206 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
@@ -14259,11 +14292,10 @@
14292 */
14293 struct sqlite3_context {
14294 Mem *pOut; /* The return value is stored here */
14295 FuncDef *pFunc; /* Pointer to function information */
14296 Mem *pMem; /* Memory cell used to store aggregate context */
 
14297 Vdbe *pVdbe; /* The VM that owns this context */
14298 int iOp; /* Instruction number of OP_Function */
14299 int isError; /* Error code returned by the function. */
14300 u8 skipFlag; /* Skip accumulator loading if true */
14301 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
@@ -14348,14 +14380,10 @@
14380 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
14381 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
14382 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
14383 char *zSql; /* Text of the SQL statement that generated this */
14384 void *pFree; /* Free this when deleting the vdbe */
 
 
 
 
14385 VdbeFrame *pFrame; /* Parent frame */
14386 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */
14387 int nFrame; /* Number of frames in pFrame list */
14388 u32 expmask; /* Binding to these vars invalidates VM */
14389 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
@@ -14376,10 +14404,11 @@
14404 ** Function prototypes
14405 */
14406 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
14407 void sqliteVdbePopStack(Vdbe*,int);
14408 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
14409 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
14410 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
14411 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
14412 #endif
14413 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
14414 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
@@ -14675,11 +14704,11 @@
14704 sqlite3VdbeClearObject(db, pVdbe);
14705 sqlite3DbFree(db, pVdbe);
14706 }
14707 db->pnBytesFreed = 0;
14708
14709 *pHighwater = 0; /* IMP: R-64479-57858 */
14710 *pCurrent = nByte;
14711
14712 break;
14713 }
14714
@@ -14700,21 +14729,23 @@
14729 if( db->aDb[i].pBt ){
14730 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
14731 sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet);
14732 }
14733 }
14734 *pHighwater = 0; /* IMP: R-42420-56072 */
14735 /* IMP: R-54100-20147 */
14736 /* IMP: R-29431-39229 */
14737 *pCurrent = nRet;
14738 break;
14739 }
14740
14741 /* Set *pCurrent to non-zero if there are unresolved deferred foreign
14742 ** key constraints. Set *pCurrent to zero if all foreign key constraints
14743 ** have been satisfied. The *pHighwater is always set to zero.
14744 */
14745 case SQLITE_DBSTATUS_DEFERRED_FKS: {
14746 *pHighwater = 0; /* IMP: R-11967-56545 */
14747 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
14748 break;
14749 }
14750
14751 default: {
@@ -17098,11 +17129,11 @@
17129 ** allocation p. Also return true if p==NULL.
17130 **
17131 ** This routine is designed for use within an assert() statement, to
17132 ** verify the type of an allocation. For example:
17133 **
17134 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
17135 */
17136 SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
17137 int rc = 1;
17138 if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
17139 struct MemBlockHdr *pHdr;
@@ -17120,11 +17151,11 @@
17151 ** allocation p. Also return true if p==NULL.
17152 **
17153 ** This routine is designed for use within an assert() statement, to
17154 ** verify the type of an allocation. For example:
17155 **
17156 ** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
17157 */
17158 SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
17159 int rc = 1;
17160 if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
17161 struct MemBlockHdr *pHdr;
@@ -20195,11 +20226,11 @@
20226 mallocWithAlarm((int)n, &p);
20227 sqlite3_mutex_leave(mem0.mutex);
20228 }else{
20229 p = sqlite3GlobalConfig.m.xMalloc((int)n);
20230 }
20231 assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-11148-40995 */
20232 return p;
20233 }
20234
20235 /*
20236 ** This version of the memory allocation is for use by the application.
@@ -20332,39 +20363,41 @@
20363 ** Return the size of a memory allocation previously obtained from
20364 ** sqlite3Malloc() or sqlite3_malloc().
20365 */
20366 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
20367 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 
20368 return sqlite3GlobalConfig.m.xSize(p);
20369 }
20370 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20371 if( db==0 ){
20372 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20373 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20374 return sqlite3MallocSize(p);
20375 }else{
20376 assert( sqlite3_mutex_held(db->mutex) );
20377 if( isLookaside(db, p) ){
20378 return db->lookaside.sz;
20379 }else{
20380 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20381 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 
20382 return sqlite3GlobalConfig.m.xSize(p);
20383 }
20384 }
20385 }
20386 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20387 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20388 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20389 return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
20390 }
20391
20392 /*
20393 ** Free memory previously obtained from sqlite3Malloc().
20394 */
20395 SQLITE_API void sqlite3_free(void *p){
20396 if( p==0 ) return; /* IMP: R-49053-54554 */
 
20397 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20398 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20399 if( sqlite3GlobalConfig.bMemstat ){
20400 sqlite3_mutex_enter(mem0.mutex);
20401 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
20402 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
20403 sqlite3GlobalConfig.m.xFree(p);
@@ -20404,12 +20437,12 @@
20437 db->lookaside.pFree = pBuf;
20438 db->lookaside.nOut--;
20439 return;
20440 }
20441 }
20442 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20443 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20444 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20445 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20446 sqlite3_free(p);
20447 }
20448
@@ -20417,15 +20450,17 @@
20450 ** Change the size of an existing memory allocation
20451 */
20452 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
20453 int nOld, nNew, nDiff;
20454 void *pNew;
20455 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20456 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
20457 if( pOld==0 ){
20458 return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
20459 }
20460 if( nBytes==0 ){
20461 sqlite3_free(pOld); /* IMP: R-26507-47431 */
20462 return 0;
20463 }
20464 if( nBytes>=0x7fffff00 ){
20465 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
20466 return 0;
@@ -20443,12 +20478,10 @@
20478 nDiff = nNew - nOld;
20479 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
20480 mem0.alarmThreshold-nDiff ){
20481 sqlite3MallocAlarm(nDiff);
20482 }
 
 
20483 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20484 if( pNew==0 && mem0.alarmCallback ){
20485 sqlite3MallocAlarm((int)nBytes);
20486 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20487 }
@@ -20458,11 +20491,11 @@
20491 }
20492 sqlite3_mutex_leave(mem0.mutex);
20493 }else{
20494 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20495 }
20496 assert( EIGHT_BYTE_ALIGNMENT(pNew) ); /* IMP: R-11148-40995 */
20497 return pNew;
20498 }
20499
20500 /*
20501 ** The public interface to sqlite3Realloc. Make sure that the memory
@@ -20470,11 +20503,11 @@
20503 */
20504 SQLITE_API void *sqlite3_realloc(void *pOld, int n){
20505 #ifndef SQLITE_OMIT_AUTOINIT
20506 if( sqlite3_initialize() ) return 0;
20507 #endif
20508 if( n<0 ) n = 0; /* IMP: R-26507-47431 */
20509 return sqlite3Realloc(pOld, n);
20510 }
20511 SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
20512 #ifndef SQLITE_OMIT_AUTOINIT
20513 if( sqlite3_initialize() ) return 0;
@@ -20557,12 +20590,12 @@
20590 #endif
20591 p = sqlite3Malloc(n);
20592 if( !p && db ){
20593 db->mallocFailed = 1;
20594 }
20595 sqlite3MemdebugSetType(p,
20596 (db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
20597 return p;
20598 }
20599
20600 /*
20601 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -20584,19 +20617,18 @@
20617 if( pNew ){
20618 memcpy(pNew, p, db->lookaside.sz);
20619 sqlite3DbFree(db, p);
20620 }
20621 }else{
20622 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20623 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20624 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20625 pNew = sqlite3_realloc64(p, n);
20626 if( !pNew ){
 
20627 db->mallocFailed = 1;
20628 }
20629 sqlite3MemdebugSetType(pNew,
20630 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20631 }
20632 }
20633 return pNew;
20634 }
@@ -21757,10 +21789,73 @@
21789 fprintf(stdout,"%s", zBuf);
21790 fflush(stdout);
21791 }
21792 #endif
21793
21794 #ifdef SQLITE_DEBUG
21795 /*************************************************************************
21796 ** Routines for implementing the "TreeView" display of hierarchical
21797 ** data structures for debugging.
21798 **
21799 ** The main entry points (coded elsewhere) are:
21800 ** sqlite3TreeViewExpr(0, pExpr, 0);
21801 ** sqlite3TreeViewExprList(0, pList, 0, 0);
21802 ** sqlite3TreeViewSelect(0, pSelect, 0);
21803 ** Insert calls to those routines while debugging in order to display
21804 ** a diagram of Expr, ExprList, and Select objects.
21805 **
21806 */
21807 /* Add a new subitem to the tree. The moreToFollow flag indicates that this
21808 ** is not the last item in the tree. */
21809 SQLITE_PRIVATE TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
21810 if( p==0 ){
21811 p = sqlite3_malloc( sizeof(*p) );
21812 if( p==0 ) return 0;
21813 memset(p, 0, sizeof(*p));
21814 }else{
21815 p->iLevel++;
21816 }
21817 assert( moreToFollow==0 || moreToFollow==1 );
21818 if( p->iLevel<sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
21819 return p;
21820 }
21821 /* Finished with one layer of the tree */
21822 SQLITE_PRIVATE void sqlite3TreeViewPop(TreeView *p){
21823 if( p==0 ) return;
21824 p->iLevel--;
21825 if( p->iLevel<0 ) sqlite3_free(p);
21826 }
21827 /* Generate a single line of output for the tree, with a prefix that contains
21828 ** all the appropriate tree lines */
21829 SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
21830 va_list ap;
21831 int i;
21832 StrAccum acc;
21833 char zBuf[500];
21834 sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
21835 acc.useMalloc = 0;
21836 if( p ){
21837 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
21838 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
21839 }
21840 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
21841 }
21842 va_start(ap, zFormat);
21843 sqlite3VXPrintf(&acc, 0, zFormat, ap);
21844 va_end(ap);
21845 if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
21846 sqlite3StrAccumFinish(&acc);
21847 fprintf(stdout,"%s", zBuf);
21848 fflush(stdout);
21849 }
21850 /* Shorthand for starting a new tree item that consists of a single label */
21851 SQLITE_PRIVATE void sqlite3TreeViewItem(TreeView *p, const char *zLabel, u8 moreToFollow){
21852 p = sqlite3TreeViewPush(p, moreToFollow);
21853 sqlite3TreeViewLine(p, "%s", zLabel);
21854 }
21855 #endif /* SQLITE_DEBUG */
21856
21857 /*
21858 ** variable-argument wrapper around sqlite3VXPrintf().
21859 */
21860 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
21861 va_list ap;
@@ -22003,11 +22098,11 @@
22098 #define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
22099 #include <process.h>
22100
22101 /* A running thread */
22102 struct SQLiteThread {
22103 void *tid; /* The thread handle */
22104 unsigned id; /* The thread identifier */
22105 void *(*xTask)(void*); /* The routine to run as a thread */
22106 void *pIn; /* Argument to xTask */
22107 void *pResult; /* Result of xTask */
22108 };
@@ -22051,11 +22146,11 @@
22146 if( sqlite3GlobalConfig.bCoreMutex==0 ){
22147 memset(p, 0, sizeof(*p));
22148 }else{
22149 p->xTask = xTask;
22150 p->pIn = pIn;
22151 p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
22152 if( p->tid==0 ){
22153 memset(p, 0, sizeof(*p));
22154 }
22155 }
22156 if( p->xTask==0 ){
@@ -29659,11 +29754,11 @@
29754 ** methods CLOSE, LOCK, UNLOCK, CKRESLOCK.
29755 **
29756 ** * An I/O method finder function called FINDER that returns a pointer
29757 ** to the METHOD object in the previous bullet.
29758 */
29759 #define IOMETHODS(FINDER, METHOD, VERSION, CLOSE, LOCK, UNLOCK, CKLOCK, SHMMAP) \
29760 static const sqlite3_io_methods METHOD = { \
29761 VERSION, /* iVersion */ \
29762 CLOSE, /* xClose */ \
29763 unixRead, /* xRead */ \
29764 unixWrite, /* xWrite */ \
@@ -29674,11 +29769,11 @@
29769 UNLOCK, /* xUnlock */ \
29770 CKLOCK, /* xCheckReservedLock */ \
29771 unixFileControl, /* xFileControl */ \
29772 unixSectorSize, /* xSectorSize */ \
29773 unixDeviceCharacteristics, /* xDeviceCapabilities */ \
29774 SHMMAP, /* xShmMap */ \
29775 unixShmLock, /* xShmLock */ \
29776 unixShmBarrier, /* xShmBarrier */ \
29777 unixShmUnmap, /* xShmUnmap */ \
29778 unixFetch, /* xFetch */ \
29779 unixUnfetch, /* xUnfetch */ \
@@ -29700,29 +29795,32 @@
29795 posixIoMethods, /* sqlite3_io_methods object name */
29796 3, /* shared memory and mmap are enabled */
29797 unixClose, /* xClose method */
29798 unixLock, /* xLock method */
29799 unixUnlock, /* xUnlock method */
29800 unixCheckReservedLock, /* xCheckReservedLock method */
29801 unixShmMap /* xShmMap method */
29802 )
29803 IOMETHODS(
29804 nolockIoFinder, /* Finder function name */
29805 nolockIoMethods, /* sqlite3_io_methods object name */
29806 3, /* shared memory is disabled */
29807 nolockClose, /* xClose method */
29808 nolockLock, /* xLock method */
29809 nolockUnlock, /* xUnlock method */
29810 nolockCheckReservedLock, /* xCheckReservedLock method */
29811 0 /* xShmMap method */
29812 )
29813 IOMETHODS(
29814 dotlockIoFinder, /* Finder function name */
29815 dotlockIoMethods, /* sqlite3_io_methods object name */
29816 1, /* shared memory is disabled */
29817 dotlockClose, /* xClose method */
29818 dotlockLock, /* xLock method */
29819 dotlockUnlock, /* xUnlock method */
29820 dotlockCheckReservedLock, /* xCheckReservedLock method */
29821 0 /* xShmMap method */
29822 )
29823
29824 #if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
29825 IOMETHODS(
29826 flockIoFinder, /* Finder function name */
@@ -29729,11 +29827,12 @@
29827 flockIoMethods, /* sqlite3_io_methods object name */
29828 1, /* shared memory is disabled */
29829 flockClose, /* xClose method */
29830 flockLock, /* xLock method */
29831 flockUnlock, /* xUnlock method */
29832 flockCheckReservedLock, /* xCheckReservedLock method */
29833 0 /* xShmMap method */
29834 )
29835 #endif
29836
29837 #if OS_VXWORKS
29838 IOMETHODS(
@@ -29741,11 +29840,12 @@
29840 semIoMethods, /* sqlite3_io_methods object name */
29841 1, /* shared memory is disabled */
29842 semClose, /* xClose method */
29843 semLock, /* xLock method */
29844 semUnlock, /* xUnlock method */
29845 semCheckReservedLock, /* xCheckReservedLock method */
29846 0 /* xShmMap method */
29847 )
29848 #endif
29849
29850 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
29851 IOMETHODS(
@@ -29753,11 +29853,12 @@
29853 afpIoMethods, /* sqlite3_io_methods object name */
29854 1, /* shared memory is disabled */
29855 afpClose, /* xClose method */
29856 afpLock, /* xLock method */
29857 afpUnlock, /* xUnlock method */
29858 afpCheckReservedLock, /* xCheckReservedLock method */
29859 0 /* xShmMap method */
29860 )
29861 #endif
29862
29863 /*
29864 ** The proxy locking method is a "super-method" in the sense that it
@@ -29778,11 +29879,12 @@
29879 proxyIoMethods, /* sqlite3_io_methods object name */
29880 1, /* shared memory is disabled */
29881 proxyClose, /* xClose method */
29882 proxyLock, /* xLock method */
29883 proxyUnlock, /* xUnlock method */
29884 proxyCheckReservedLock, /* xCheckReservedLock method */
29885 0 /* xShmMap method */
29886 )
29887 #endif
29888
29889 /* nfs lockd on OSX 10.3+ doesn't clear write locks when a read lock is set */
29890 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -29791,11 +29893,12 @@
29893 nfsIoMethods, /* sqlite3_io_methods object name */
29894 1, /* shared memory is disabled */
29895 unixClose, /* xClose method */
29896 unixLock, /* xLock method */
29897 nfsUnlock, /* xUnlock method */
29898 unixCheckReservedLock, /* xCheckReservedLock method */
29899 0 /* xShmMap method */
29900 )
29901 #endif
29902
29903 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
29904 /*
@@ -39752,11 +39855,11 @@
39855 assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
39856 assert( pCache->n90pct == pCache->nMax*9/10 );
39857 if( createFlag==1 && (
39858 nPinned>=pGroup->mxPinned
39859 || nPinned>=pCache->n90pct
39860 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
39861 )){
39862 return 0;
39863 }
39864
39865 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
@@ -44373,17 +44476,19 @@
44476 if( !pNew ) rc = SQLITE_NOMEM;
44477 }
44478
44479 if( rc==SQLITE_OK ){
44480 pager_reset(pPager);
 
 
44481 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
44482 }
44483 if( rc==SQLITE_OK ){
44484 sqlite3PageFree(pPager->pTmpSpace);
44485 pPager->pTmpSpace = pNew;
44486 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
44487 pPager->pageSize = pageSize;
44488 }else{
44489 sqlite3PageFree(pNew);
44490 }
44491 }
44492
44493 *pPageSize = pPager->pageSize;
44494 if( rc==SQLITE_OK ){
@@ -51383,13 +51488,14 @@
51488 ** stored in MemPage.pBt->mutex.
51489 */
51490 struct MemPage {
51491 u8 isInit; /* True if previously initialized. MUST BE FIRST! */
51492 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
51493 u8 intKey; /* True if table b-trees. False for index b-trees */
51494 u8 intKeyLeaf; /* True if the leaf of an intKey table */
51495 u8 noPayload; /* True if internal intKey page (thus w/o data) */
51496 u8 leaf; /* True if a leaf page */
51497 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
51498 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
51499 u8 max1bytePayload; /* min(maxLocal,127) */
51500 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
51501 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
@@ -51545,11 +51651,11 @@
51651 int nRef; /* Number of references to this structure */
51652 BtShared *pNext; /* Next on a list of sharable BtShared structs */
51653 BtLock *pLock; /* List of locks held on this shared-btree struct */
51654 Btree *pWriter; /* Btree with currently open write transaction */
51655 #endif
51656 u8 *pTmpSpace; /* Temp space sufficient to hold a single cell */
51657 };
51658
51659 /*
51660 ** Allowed values for BtShared.btsFlags
51661 */
@@ -51566,16 +51672,14 @@
51672 ** about a cell. The parseCellPtr() function fills in this structure
51673 ** based on information extract from the raw disk page.
51674 */
51675 typedef struct CellInfo CellInfo;
51676 struct CellInfo {
51677 i64 nKey; /* The key for INTKEY tables, or nPayload otherwise */
51678 u8 *pPayload; /* Pointer to the start of payload */
51679 u32 nPayload; /* Bytes of payload */
51680 u16 nLocal; /* Amount of payload held locally, not on overflow */
 
 
51681 u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */
51682 u16 nSize; /* Size of the cell content on the main b-tree page */
51683 };
51684
51685 /*
@@ -51768,10 +51872,12 @@
51872 u8 *aPgRef; /* 1 bit per page in the db (see above) */
51873 Pgno nPage; /* Number of pages in the database */
51874 int mxErr; /* Stop accumulating errors when this reaches zero */
51875 int nErr; /* Number of messages written to zErrMsg so far */
51876 int mallocFailed; /* A memory allocation error has occurred */
51877 const char *zPfx; /* Error message prefix */
51878 int v1, v2; /* Values for up to two %d fields in zPfx */
51879 StrAccum errMsg; /* Accumulate the error message text here */
51880 };
51881
51882 /*
51883 ** Routines to read or write a two- and four-byte big-endian integer values.
@@ -52554,11 +52660,13 @@
52660 ){
52661 BtCursor *p;
52662 BtShared *pBt = pBtree->pBt;
52663 assert( sqlite3BtreeHoldsMutex(pBtree) );
52664 for(p=pBt->pCursor; p; p=p->pNext){
52665 if( (p->curFlags & BTCF_Incrblob)!=0
52666 && (isClearTable || p->info.nKey==iRow)
52667 ){
52668 p->eState = CURSOR_INVALID;
52669 }
52670 }
52671 }
52672
@@ -52727,13 +52835,13 @@
52835 ** the cursors if and when a cursor is found that actually requires saving.
52836 ** The common case is that no cursors need to be saved, so this routine is
52837 ** broken out from its caller to avoid unnecessary stack pointer movement.
52838 */
52839 static int SQLITE_NOINLINE saveCursorsOnList(
52840 BtCursor *p, /* The first cursor that needs saving */
52841 Pgno iRoot, /* Only save cursor with this iRoot. Save all if zero */
52842 BtCursor *pExcept /* Do not save this cursor */
52843 ){
52844 do{
52845 if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){
52846 if( p->eState==CURSOR_VALID ){
52847 int rc = saveCursorPosition(p);
@@ -52841,11 +52949,11 @@
52949 **
52950 ** Use the separate sqlite3BtreeCursorRestore() routine to restore a cursor
52951 ** back to where it ought to be if this routine returns true.
52952 */
52953 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
52954 return pCur->eState!=CURSOR_VALID;
52955 }
52956
52957 /*
52958 ** This routine restores a cursor back to its original position after it
52959 ** has been moved by some outside activity (such as a btree rebalance or
@@ -53035,51 +53143,48 @@
53143 /*
53144 ** Parse a cell content block and fill in the CellInfo structure. There
53145 ** are two versions of this function. btreeParseCell() takes a
53146 ** cell index as the second argument and btreeParseCellPtr()
53147 ** takes a pointer to the body of the cell as its second argument.
 
 
 
53148 */
53149 static void btreeParseCellPtr(
53150 MemPage *pPage, /* Page containing the cell */
53151 u8 *pCell, /* Pointer to the cell text. */
53152 CellInfo *pInfo /* Fill in this structure */
53153 ){
53154 u8 *pIter; /* For scanning through pCell */
53155 u32 nPayload; /* Number of bytes of cell payload */
53156
53157 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 
 
53158 assert( pPage->leaf==0 || pPage->leaf==1 );
53159 if( pPage->intKeyLeaf ){
53160 assert( pPage->childPtrSize==0 );
53161 pIter = pCell + getVarint32(pCell, nPayload);
53162 pIter += getVarint(pIter, (u64*)&pInfo->nKey);
53163 }else if( pPage->noPayload ){
53164 assert( pPage->childPtrSize==4 );
53165 pInfo->nSize = 4 + getVarint(&pCell[4], (u64*)&pInfo->nKey);
53166 pInfo->nPayload = 0;
53167 pInfo->nLocal = 0;
53168 pInfo->iOverflow = 0;
53169 pInfo->pPayload = 0;
53170 return;
53171 }else{
53172 pIter = pCell + pPage->childPtrSize;
53173 pIter += getVarint32(pIter, nPayload);
53174 pInfo->nKey = nPayload;
53175 }
53176 pInfo->nPayload = nPayload;
53177 pInfo->pPayload = pIter;
53178 testcase( nPayload==pPage->maxLocal );
53179 testcase( nPayload==pPage->maxLocal+1 );
53180 if( nPayload<=pPage->maxLocal ){
53181 /* This is the (easy) common case where the entire payload fits
53182 ** on the local page. No overflow is required.
53183 */
53184 pInfo->nSize = nPayload + (u16)(pIter - pCell);
53185 if( pInfo->nSize<4 ) pInfo->nSize = 4;
53186 pInfo->nLocal = (u16)nPayload;
53187 pInfo->iOverflow = 0;
53188 }else{
53189 /* If the payload will not fit completely on the local page, we have
53190 ** to decide how much to store locally and how much to spill onto
@@ -53102,33 +53207,32 @@
53207 if( surplus <= maxLocal ){
53208 pInfo->nLocal = (u16)surplus;
53209 }else{
53210 pInfo->nLocal = (u16)minLocal;
53211 }
53212 pInfo->iOverflow = (u16)(&pInfo->pPayload[pInfo->nLocal] - pCell);
53213 pInfo->nSize = pInfo->iOverflow + 4;
53214 }
53215 }
 
 
53216 static void btreeParseCell(
53217 MemPage *pPage, /* Page containing the cell */
53218 int iCell, /* The cell index. First cell is 0 */
53219 CellInfo *pInfo /* Fill in this structure */
53220 ){
53221 btreeParseCellPtr(pPage, findCell(pPage, iCell), pInfo);
53222 }
53223
53224 /*
53225 ** Compute the total number of bytes that a Cell needs in the cell
53226 ** data area of the btree-page. The return number includes the cell
53227 ** data header and the local payload, but not any overflow page or
53228 ** the space used by the cell pointer.
53229 */
53230 static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
53231 u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */
53232 u8 *pEnd; /* End mark for a varint */
53233 u32 nSize; /* Size value to return */
53234
53235 #ifdef SQLITE_DEBUG
53236 /* The value returned by this function should always be the same as
53237 ** the (CellInfo.nSize) value found by doing a full parse of the
53238 ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
@@ -53135,47 +53239,48 @@
53239 ** this function verifies that this invariant is not violated. */
53240 CellInfo debuginfo;
53241 btreeParseCellPtr(pPage, pCell, &debuginfo);
53242 #endif
53243
53244 if( pPage->noPayload ){
53245 pEnd = &pIter[9];
53246 while( (*pIter++)&0x80 && pIter<pEnd );
53247 assert( pPage->childPtrSize==4 );
53248 return (u16)(pIter - pCell);
53249 }
53250 nSize = *pIter;
53251 if( nSize>=0x80 ){
53252 pEnd = &pIter[9];
53253 nSize &= 0x7f;
53254 do{
53255 nSize = (nSize<<7) | (*++pIter & 0x7f);
53256 }while( *(pIter)>=0x80 && pIter<pEnd );
53257 }
53258 pIter++;
53259 if( pPage->intKey ){
 
 
 
 
 
 
 
53260 /* pIter now points at the 64-bit integer key value, a variable length
53261 ** integer. The following block moves pIter to point at the first byte
53262 ** past the end of the key value. */
53263 pEnd = &pIter[9];
53264 while( (*pIter++)&0x80 && pIter<pEnd );
 
 
53265 }
 
53266 testcase( nSize==pPage->maxLocal );
53267 testcase( nSize==pPage->maxLocal+1 );
53268 if( nSize<=pPage->maxLocal ){
53269 nSize += (u32)(pIter - pCell);
53270 if( nSize<4 ) nSize = 4;
53271 }else{
53272 int minLocal = pPage->minLocal;
53273 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
53274 testcase( nSize==pPage->maxLocal );
53275 testcase( nSize==pPage->maxLocal+1 );
53276 if( nSize>pPage->maxLocal ){
53277 nSize = minLocal;
53278 }
53279 nSize += 4 + (u16)(pIter - pCell);
53280 }
53281 assert( nSize==debuginfo.nSize || CORRUPT_DB );
 
 
 
 
 
 
 
53282 return (u16)nSize;
53283 }
53284
53285 #ifdef SQLITE_DEBUG
53286 /* This variation on cellSizePtr() is used inside of assert() statements
@@ -53194,11 +53299,10 @@
53299 static void ptrmapPutOvflPtr(MemPage *pPage, u8 *pCell, int *pRC){
53300 CellInfo info;
53301 if( *pRC ) return;
53302 assert( pCell!=0 );
53303 btreeParseCellPtr(pPage, pCell, &info);
 
53304 if( info.iOverflow ){
53305 Pgno ovfl = get4byte(&pCell[info.iOverflow]);
53306 ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC);
53307 }
53308 }
@@ -53407,11 +53511,11 @@
53511 ** does it detect cells or freeblocks that encrouch into the reserved bytes
53512 ** at the end of the page. So do additional corruption checks inside this
53513 ** routine and return SQLITE_CORRUPT if any problems are found.
53514 */
53515 static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
53516 u16 iPtr; /* Address of ptr to next freeblock */
53517 u16 iFreeBlk; /* Address of the next freeblock */
53518 u8 hdr; /* Page header size. 0 or 100 */
53519 u8 nFrag = 0; /* Reduction in fragmentation */
53520 u16 iOrigSize = iSize; /* Original value of iSize */
53521 u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */
@@ -53459,13 +53563,13 @@
53563 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
53564 iSize = iEnd - iStart;
53565 iFreeBlk = get2byte(&data[iFreeBlk]);
53566 }
53567
53568 /* If iPtr is another freeblock (that is, if iPtr is not the freelist
53569 ** pointer in the page header) then check to see if iStart should be
53570 ** coalesced onto the end of iPtr.
53571 */
53572 if( iPtr>hdr+1 ){
53573 int iPtrEnd = iPtr + get2byte(&data[iPtr+2]);
53574 if( iPtrEnd+3>=iStart ){
53575 if( iPtrEnd>iStart ) return SQLITE_CORRUPT_BKPT;
@@ -53515,16 +53619,18 @@
53619 flagByte &= ~PTF_LEAF;
53620 pPage->childPtrSize = 4-4*pPage->leaf;
53621 pBt = pPage->pBt;
53622 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
53623 pPage->intKey = 1;
53624 pPage->intKeyLeaf = pPage->leaf;
53625 pPage->noPayload = !pPage->leaf;
53626 pPage->maxLocal = pBt->maxLeaf;
53627 pPage->minLocal = pBt->minLeaf;
53628 }else if( flagByte==PTF_ZERODATA ){
53629 pPage->intKey = 0;
53630 pPage->intKeyLeaf = 0;
53631 pPage->noPayload = 0;
53632 pPage->maxLocal = pBt->maxLocal;
53633 pPage->minLocal = pBt->minLocal;
53634 }else{
53635 return SQLITE_CORRUPT_BKPT;
53636 }
@@ -54175,11 +54281,12 @@
54281 #endif
54282 }
54283
54284 /*
54285 ** Make sure pBt->pTmpSpace points to an allocation of
54286 ** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child
54287 ** pointer.
54288 */
54289 static void allocateTempSpace(BtShared *pBt){
54290 if( !pBt->pTmpSpace ){
54291 pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
54292
@@ -54190,21 +54297,32 @@
54297 ** can mean that fillInCell() only initializes the first 2 or 3
54298 ** bytes of pTmpSpace, but that the first 4 bytes are copied from
54299 ** it into a database page. This is not actually a problem, but it
54300 ** does cause a valgrind error when the 1 or 2 bytes of unitialized
54301 ** data is passed to system call write(). So to avoid this error,
54302 ** zero the first 4 bytes of temp space here.
54303 **
54304 ** Also: Provide four bytes of initialized space before the
54305 ** beginning of pTmpSpace as an area available to prepend the
54306 ** left-child pointer to the beginning of a cell.
54307 */
54308 if( pBt->pTmpSpace ){
54309 memset(pBt->pTmpSpace, 0, 8);
54310 pBt->pTmpSpace += 4;
54311 }
54312 }
54313 }
54314
54315 /*
54316 ** Free the pBt->pTmpSpace allocation
54317 */
54318 static void freeTempSpace(BtShared *pBt){
54319 if( pBt->pTmpSpace ){
54320 pBt->pTmpSpace -= 4;
54321 sqlite3PageFree(pBt->pTmpSpace);
54322 pBt->pTmpSpace = 0;
54323 }
54324 }
54325
54326 /*
54327 ** Close an open database and invalidate all cursors.
54328 */
@@ -54694,15 +54812,15 @@
54812 */
54813 static void unlockBtreeIfUnused(BtShared *pBt){
54814 assert( sqlite3_mutex_held(pBt->mutex) );
54815 assert( countValidCursors(pBt,0)==0 || pBt->inTransaction>TRANS_NONE );
54816 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
54817 MemPage *pPage1 = pBt->pPage1;
54818 assert( pPage1->aData );
54819 assert( sqlite3PagerRefcount(pBt->pPager)==1 );
 
 
54820 pBt->pPage1 = 0;
54821 releasePage(pPage1);
54822 }
54823 }
54824
54825 /*
54826 ** If pBt points to an empty file then convert that empty file
@@ -55739,10 +55857,14 @@
55857 assert( pBt->pPage1 && pBt->pPage1->aData );
55858
55859 if( NEVER(wrFlag && (pBt->btsFlags & BTS_READ_ONLY)!=0) ){
55860 return SQLITE_READONLY;
55861 }
55862 if( wrFlag ){
55863 allocateTempSpace(pBt);
55864 if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM;
55865 }
55866 if( iTable==1 && btreePagecount(pBt)==0 ){
55867 assert( wrFlag==0 );
55868 iTable = 0;
55869 }
55870
@@ -55928,12 +56050,13 @@
56050 ** to return an integer result code for historical reasons.
56051 */
56052 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
56053 assert( cursorHoldsMutex(pCur) );
56054 assert( pCur->eState==CURSOR_VALID );
56055 assert( pCur->apPage[pCur->iPage]->intKeyLeaf==1 );
56056 getCellInfo(pCur);
56057 *pSize = pCur->info.nPayload;
56058 return SQLITE_OK;
56059 }
56060
56061 /*
56062 ** Given the page number of an overflow page in the database (parameter
@@ -56080,34 +56203,32 @@
56203 unsigned char *pBuf, /* Write the bytes into this buffer */
56204 int eOp /* zero to read. non-zero to write. */
56205 ){
56206 unsigned char *aPayload;
56207 int rc = SQLITE_OK;
 
56208 int iIdx = 0;
56209 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
56210 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
56211 #ifdef SQLITE_DIRECT_OVERFLOW_READ
56212 unsigned char * const pBufStart = pBuf;
56213 int bEnd; /* True if reading to end of data */
56214 #endif
56215
56216 assert( pPage );
56217 assert( pCur->eState==CURSOR_VALID );
56218 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
56219 assert( cursorHoldsMutex(pCur) );
56220 assert( eOp!=2 || offset==0 ); /* Always start from beginning for eOp==2 */
56221
56222 getCellInfo(pCur);
56223 aPayload = pCur->info.pPayload;
 
56224 #ifdef SQLITE_DIRECT_OVERFLOW_READ
56225 bEnd = offset+amt==pCur->info.nPayload;
56226 #endif
56227 assert( offset+amt <= pCur->info.nPayload );
56228
56229 if( &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ){
 
 
56230 /* Trying to read or write past the end of the data is an error */
56231 return SQLITE_CORRUPT_BKPT;
56232 }
56233
56234 /* Check if data must be read/written to/from the btree page itself. */
@@ -56159,11 +56280,13 @@
56280
56281 /* If the overflow page-list cache has been allocated and the
56282 ** entry for the first required overflow page is valid, skip
56283 ** directly to it.
56284 */
56285 if( (pCur->curFlags & BTCF_ValidOvfl)!=0
56286 && pCur->aOverflow[offset/ovflSize]
56287 ){
56288 iIdx = (offset/ovflSize);
56289 nextPage = pCur->aOverflow[iIdx];
56290 offset = (offset%ovflSize);
56291 }
56292
@@ -56212,10 +56335,11 @@
56335 ** 2) data is required from the start of this overflow page, and
56336 ** 3) the database is file-backed, and
56337 ** 4) there is no open write-transaction, and
56338 ** 5) the database is not a WAL database,
56339 ** 6) all data from the page is being read.
56340 ** 7) at least 4 bytes have already been read into the output buffer
56341 **
56342 ** then data can be read directly from the database file into the
56343 ** output buffer, bypassing the page-cache altogether. This speeds
56344 ** up loading large records that span many overflow pages.
56345 */
@@ -56223,13 +56347,15 @@
56347 && offset==0 /* (2) */
56348 && (bEnd || a==ovflSize) /* (6) */
56349 && pBt->inTransaction==TRANS_READ /* (4) */
56350 && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */
56351 && pBt->pPage1->aData[19]==0x01 /* (5) */
56352 && &pBuf[-4]>=pBufStart /* (7) */
56353 ){
56354 u8 aSave[4];
56355 u8 *aWrite = &pBuf[-4];
56356 assert( aWrite>=pBufStart ); /* hence (7) */
56357 memcpy(aSave, aWrite, 4);
56358 rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
56359 nextPage = get4byte(aWrite);
56360 memcpy(aWrite, aSave, 4);
56361 }else
@@ -56337,11 +56463,11 @@
56463 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
56464 assert( cursorHoldsMutex(pCur) );
56465 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
56466 assert( pCur->info.nSize>0 );
56467 *pAmt = pCur->info.nLocal;
56468 return (void*)pCur->info.pPayload;
56469 }
56470
56471
56472 /*
56473 ** For the entry that cursor pCur is point to, return as
@@ -56765,11 +56891,11 @@
56891 pCur->aiIdx[pCur->iPage] = (u16)idx;
56892 if( xRecordCompare==0 ){
56893 for(;;){
56894 i64 nCellKey;
56895 pCell = findCell(pPage, idx) + pPage->childPtrSize;
56896 if( pPage->intKeyLeaf ){
56897 while( 0x80 <= *(pCell++) ){
56898 if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
56899 }
56900 }
56901 getVarint(pCell, (u64*)&nCellKey);
@@ -57024,13 +57150,13 @@
57150 ** was already pointing to the first entry in the database before
57151 ** this routine was called, then set *pRes=1.
57152 **
57153 ** The main entry point is sqlite3BtreePrevious(). That routine is optimized
57154 ** for the common case of merely decrementing the cell counter BtCursor.aiIdx
57155 ** to the previous cell on the current page. The (slower) btreePrevious()
57156 ** helper routine is called when it is necessary to move to a different page
57157 ** or to restore the cursor.
57158 **
57159 ** The calling function will set *pRes to 0 or 1. The initial *pRes value
57160 ** will be 1 if the cursor being stepped corresponds to an SQL index and
57161 ** if this routine could have been skipped if that SQL index had been
57162 ** a unique index. Otherwise the caller will have set *pRes to zero.
@@ -57048,12 +57174,11 @@
57174 assert( *pRes==0 );
57175 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
57176 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
57177 assert( pCur->info.nSize==0 );
57178 if( pCur->eState!=CURSOR_VALID ){
57179 rc = restoreCursorPosition(pCur);
 
57180 if( rc!=SQLITE_OK ){
57181 return rc;
57182 }
57183 if( CURSOR_INVALID==pCur->eState ){
57184 *pRes = 1;
@@ -57354,11 +57479,11 @@
57479 if( rc ) goto end_allocate_page;
57480 if( closest<k-1 ){
57481 memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
57482 }
57483 put4byte(&aData[4], k-1);
57484 noContent = !btreeGetHasContent(pBt, *pPgno)? PAGER_GET_NOCONTENT : 0;
57485 rc = btreeGetPage(pBt, *pPgno, ppPage, noContent);
57486 if( rc==SQLITE_OK ){
57487 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
57488 if( rc!=SQLITE_OK ){
57489 releasePage(*ppPage);
@@ -57387,11 +57512,11 @@
57512 ** content for any page that really does lie past the end of the database
57513 ** file on disk. So the effects of disabling the no-content optimization
57514 ** here are confined to those pages that lie between the end of the
57515 ** database image and the end of the database file.
57516 */
57517 int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate))? PAGER_GET_NOCONTENT:0;
57518
57519 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
57520 if( rc ) return rc;
57521 pBt->nPage++;
57522 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
@@ -57586,22 +57711,29 @@
57711 *pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
57712 }
57713 }
57714
57715 /*
57716 ** Free any overflow pages associated with the given Cell. Write the
57717 ** local Cell size (the number of bytes on the original page, omitting
57718 ** overflow) into *pnSize.
57719 */
57720 static int clearCell(
57721 MemPage *pPage, /* The page that contains the Cell */
57722 unsigned char *pCell, /* First byte of the Cell */
57723 u16 *pnSize /* Write the size of the Cell here */
57724 ){
57725 BtShared *pBt = pPage->pBt;
57726 CellInfo info;
57727 Pgno ovflPgno;
57728 int rc;
57729 int nOvfl;
57730 u32 ovflPageSize;
57731
57732 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57733 btreeParseCellPtr(pPage, pCell, &info);
57734 *pnSize = info.nSize;
57735 if( info.iOverflow==0 ){
57736 return SQLITE_OK; /* No overflow pages. Return without doing anything */
57737 }
57738 if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){
57739 return SQLITE_CORRUPT_BKPT; /* Cell extends past end of page */
@@ -57681,54 +57813,87 @@
57813 unsigned char *pPrior;
57814 unsigned char *pPayload;
57815 BtShared *pBt = pPage->pBt;
57816 Pgno pgnoOvfl = 0;
57817 int nHeader;
 
57818
57819 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
57820
57821 /* pPage is not necessarily writeable since pCell might be auxiliary
57822 ** buffer space that is separate from the pPage buffer area */
57823 assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
57824 || sqlite3PagerIswriteable(pPage->pDbPage) );
57825
57826 /* Fill in the header. */
57827 nHeader = pPage->childPtrSize;
57828 nPayload = nData + nZero;
57829 if( pPage->intKeyLeaf ){
57830 nHeader += putVarint32(&pCell[nHeader], nPayload);
 
 
57831 }else{
57832 assert( nData==0 );
57833 assert( nZero==0 );
57834 }
57835 nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
 
 
 
 
57836
57837 /* Fill in the payload size */
 
57838 if( pPage->intKey ){
57839 pSrc = pData;
57840 nSrc = nData;
57841 nData = 0;
57842 }else{
57843 if( NEVER(nKey>0x7fffffff || pKey==0) ){
57844 return SQLITE_CORRUPT_BKPT;
57845 }
57846 nPayload = (int)nKey;
57847 pSrc = pKey;
57848 nSrc = (int)nKey;
57849 }
57850 if( nPayload<=pPage->maxLocal ){
57851 n = nHeader + nPayload;
57852 testcase( n==3 );
57853 testcase( n==4 );
57854 if( n<4 ) n = 4;
57855 *pnSize = n;
57856 spaceLeft = nPayload;
57857 pPrior = pCell;
57858 }else{
57859 int mn = pPage->minLocal;
57860 n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
57861 testcase( n==pPage->maxLocal );
57862 testcase( n==pPage->maxLocal+1 );
57863 if( n > pPage->maxLocal ) n = mn;
57864 spaceLeft = n;
57865 *pnSize = n + nHeader + 4;
57866 pPrior = &pCell[nHeader+n];
57867 }
57868 pPayload = &pCell[nHeader];
 
57869
57870 /* At this point variables should be set as follows:
57871 **
57872 ** nPayload Total payload size in bytes
57873 ** pPayload Begin writing payload here
57874 ** spaceLeft Space available at pPayload. If nPayload>spaceLeft,
57875 ** that means content must spill into overflow pages.
57876 ** *pnSize Size of the local cell (not counting overflow pages)
57877 ** pPrior Where to write the pgno of the first overflow page
57878 **
57879 ** Use a call to btreeParseCellPtr() to verify that the values above
57880 ** were computed correctly.
57881 */
57882 #if SQLITE_DEBUG
57883 {
57884 CellInfo info;
57885 btreeParseCellPtr(pPage, pCell, &info);
57886 assert( nHeader=(int)(info.pPayload - pCell) );
57887 assert( info.nKey==nKey );
57888 assert( *pnSize == info.nSize );
57889 assert( spaceLeft == info.nLocal );
57890 assert( pPrior == &pCell[info.iOverflow] );
57891 }
57892 #endif
57893
57894 /* Write the payload into the local Cell and any extra into overflow pages */
57895 while( nPayload>0 ){
57896 if( spaceLeft==0 ){
57897 #ifndef SQLITE_OMIT_AUTOVACUUM
57898 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
57899 if( pBt->autoVacuum ){
@@ -57865,15 +58030,10 @@
58030 ** pTemp is not null. Regardless of pTemp, allocate a new entry
58031 ** in pPage->apOvfl[] and make it point to the cell content (either
58032 ** in pTemp or the original pCell) and also record its index.
58033 ** Allocating a new entry in pPage->aCell[] implies that
58034 ** pPage->nOverflow is incremented.
 
 
 
 
 
58035 */
58036 static void insertCell(
58037 MemPage *pPage, /* Page into which we are copying */
58038 int i, /* New cell becomes the i-th cell of the page */
58039 u8 *pCell, /* Content of the new cell */
@@ -57886,11 +58046,10 @@
58046 int j; /* Loop counter */
58047 int end; /* First byte past the last cell pointer in data[] */
58048 int ins; /* Index in data[] where new cell pointer is inserted */
58049 int cellOffset; /* Address of first cell pointer in data[] */
58050 u8 *data; /* The content of the whole page */
 
58051
58052 if( *pRC ) return;
58053
58054 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
58055 assert( MX_CELL(pPage->pBt)<=10921 );
@@ -57904,11 +58063,11 @@
58063 ** might be less than 8 (leaf-size + pointer) on the interior node. Hence
58064 ** the term after the || in the following assert(). */
58065 assert( sz==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
58066 if( pPage->nOverflow || sz+2>pPage->nFree ){
58067 if( pTemp ){
58068 memcpy(pTemp, pCell, sz);
58069 pCell = pTemp;
58070 }
58071 if( iChild ){
58072 put4byte(pCell, iChild);
58073 }
@@ -57933,11 +58092,11 @@
58092 ** if it returns success */
58093 assert( idx >= end+2 );
58094 assert( idx+sz <= (int)pPage->pBt->usableSize );
58095 pPage->nCell++;
58096 pPage->nFree -= (u16)(2 + sz);
58097 memcpy(&data[idx], pCell, sz);
58098 if( iChild ){
58099 put4byte(&data[idx], iChild);
58100 }
58101 memmove(&data[ins+2], &data[ins], end-ins);
58102 put2byte(&data[ins], idx);
@@ -58432,11 +58591,11 @@
58591 **
58592 ** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
58593 ** leafData: 1 if pPage holds key+data and pParent holds only keys.
58594 */
58595 leafCorrection = apOld[0]->leaf*4;
58596 leafData = apOld[0]->intKeyLeaf;
58597 for(i=0; i<nOld; i++){
58598 int limit;
58599
58600 /* Before doing anything else, take a copy of the i'th original sibling
58601 ** The rest of this function will use data from the copies rather
@@ -59008,11 +59167,11 @@
59167 int const iIdx = pCur->aiIdx[iPage-1];
59168
59169 rc = sqlite3PagerWrite(pParent->pDbPage);
59170 if( rc==SQLITE_OK ){
59171 #ifndef SQLITE_OMIT_QUICKBALANCE
59172 if( pPage->intKeyLeaf
59173 && pPage->nOverflow==1
59174 && pPage->aiOvfl[0]==pPage->nCell
59175 && pParent->pgno!=1
59176 && pParent->nCell==iIdx
59177 ){
@@ -59127,11 +59286,12 @@
59286 assert( pCur->skipNext!=SQLITE_OK );
59287 return pCur->skipNext;
59288 }
59289
59290 assert( cursorHoldsMutex(pCur) );
59291 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
59292 && pBt->inTransaction==TRANS_WRITE
59293 && (pBt->btsFlags & BTS_READ_ONLY)==0 );
59294 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
59295
59296 /* Assert that the caller has been consistent. If this cursor was opened
59297 ** expecting an index b-tree, then the caller should be inserting blob
@@ -59160,11 +59320,12 @@
59320 invalidateIncrblobCursors(p, nKey, 0);
59321
59322 /* If the cursor is currently on the last row and we are appending a
59323 ** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto()
59324 ** call */
59325 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && nKey>0
59326 && pCur->info.nKey==nKey-1 ){
59327 loc = -1;
59328 }
59329 }
59330
59331 if( !loc ){
@@ -59179,13 +59340,12 @@
59340
59341 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
59342 pCur->pgnoRoot, nKey, nData, pPage->pgno,
59343 loc==0 ? "overwrite" : "new entry"));
59344 assert( pPage->isInit );
 
59345 newCell = pBt->pTmpSpace;
59346 assert( newCell!=0 );
59347 rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
59348 if( rc ) goto end_insert;
59349 assert( szNew==cellSizePtr(pPage, newCell) );
59350 assert( szNew <= MX_CELL_SIZE(pBt) );
59351 idx = pCur->aiIdx[pCur->iPage];
@@ -59198,12 +59358,11 @@
59358 }
59359 oldCell = findCell(pPage, idx);
59360 if( !pPage->leaf ){
59361 memcpy(newCell, oldCell, 4);
59362 }
59363 rc = clearCell(pPage, oldCell, &szOld);
 
59364 dropCell(pPage, idx, szOld, &rc);
59365 if( rc ) goto end_insert;
59366 }else if( loc<0 && pPage->nCell>0 ){
59367 assert( pPage->leaf );
59368 idx = ++pCur->aiIdx[pCur->iPage];
@@ -59261,10 +59420,11 @@
59420 int rc; /* Return code */
59421 MemPage *pPage; /* Page to delete cell from */
59422 unsigned char *pCell; /* Pointer to cell to delete */
59423 int iCellIdx; /* Index of cell to delete */
59424 int iCellDepth; /* Depth of node containing pCell */
59425 u16 szCell; /* Size of the cell being deleted */
59426
59427 assert( cursorHoldsMutex(pCur) );
59428 assert( pBt->inTransaction==TRANS_WRITE );
59429 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
59430 assert( pCur->curFlags & BTCF_WriteFlag );
@@ -59309,12 +59469,12 @@
59469 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
59470 }
59471
59472 rc = sqlite3PagerWrite(pPage->pDbPage);
59473 if( rc ) return rc;
59474 rc = clearCell(pPage, pCell, &szCell);
59475 dropCell(pPage, iCellIdx, szCell, &rc);
59476 if( rc ) return rc;
59477
59478 /* If the cell deleted was not located on a leaf page, then the cursor
59479 ** is currently pointing to the largest entry in the sub-tree headed
59480 ** by the child-page of the cell that was just deleted from an internal
@@ -59327,14 +59487,12 @@
59487 unsigned char *pTmp;
59488
59489 pCell = findCell(pLeaf, pLeaf->nCell-1);
59490 nCell = cellSizePtr(pLeaf, pCell);
59491 assert( MX_CELL_SIZE(pBt) >= nCell );
 
 
59492 pTmp = pBt->pTmpSpace;
59493 assert( pTmp!=0 );
59494 rc = sqlite3PagerWrite(pLeaf->pDbPage);
59495 insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n, &rc);
59496 dropCell(pLeaf, pLeaf->nCell-1, nCell, &rc);
59497 if( rc ) return rc;
59498 }
@@ -59542,10 +59700,11 @@
59700 MemPage *pPage;
59701 int rc;
59702 unsigned char *pCell;
59703 int i;
59704 int hdr;
59705 u16 szCell;
59706
59707 assert( sqlite3_mutex_held(pBt->mutex) );
59708 if( pgno>btreePagecount(pBt) ){
59709 return SQLITE_CORRUPT_BKPT;
59710 }
@@ -59557,11 +59716,11 @@
59716 pCell = findCell(pPage, i);
59717 if( !pPage->leaf ){
59718 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
59719 if( rc ) goto cleardatabasepage_out;
59720 }
59721 rc = clearCell(pPage, pCell, &szCell);
59722 if( rc ) goto cleardatabasepage_out;
59723 }
59724 if( !pPage->leaf ){
59725 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
59726 if( rc ) goto cleardatabasepage_out;
@@ -59903,24 +60062,25 @@
60062 /*
60063 ** Append a message to the error message string.
60064 */
60065 static void checkAppendMsg(
60066 IntegrityCk *pCheck,
 
60067 const char *zFormat,
60068 ...
60069 ){
60070 va_list ap;
60071 char zBuf[200];
60072 if( !pCheck->mxErr ) return;
60073 pCheck->mxErr--;
60074 pCheck->nErr++;
60075 va_start(ap, zFormat);
60076 if( pCheck->errMsg.nChar ){
60077 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
60078 }
60079 if( pCheck->zPfx ){
60080 sqlite3_snprintf(sizeof(zBuf), zBuf, pCheck->zPfx, pCheck->v1, pCheck->v2);
60081 sqlite3StrAccumAppendAll(&pCheck->errMsg, zBuf);
60082 }
60083 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
60084 va_end(ap);
60085 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
60086 pCheck->mallocFailed = 1;
@@ -59954,18 +60114,18 @@
60114 ** Return 1 if there are 2 or more references to the page and 0 if
60115 ** if this is the first reference to the page.
60116 **
60117 ** Also check that the page number is in bounds.
60118 */
60119 static int checkRef(IntegrityCk *pCheck, Pgno iPage){
60120 if( iPage==0 ) return 1;
60121 if( iPage>pCheck->nPage ){
60122 checkAppendMsg(pCheck, "invalid page number %d", iPage);
60123 return 1;
60124 }
60125 if( getPageReferenced(pCheck, iPage) ){
60126 checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
60127 return 1;
60128 }
60129 setPageReferenced(pCheck, iPage);
60130 return 0;
60131 }
@@ -59978,26 +60138,25 @@
60138 */
60139 static void checkPtrmap(
60140 IntegrityCk *pCheck, /* Integrity check context */
60141 Pgno iChild, /* Child page number */
60142 u8 eType, /* Expected pointer map type */
60143 Pgno iParent /* Expected pointer map parent page number */
 
60144 ){
60145 int rc;
60146 u8 ePtrmapType;
60147 Pgno iPtrmapParent;
60148
60149 rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
60150 if( rc!=SQLITE_OK ){
60151 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->mallocFailed = 1;
60152 checkAppendMsg(pCheck, "Failed to read ptrmap key=%d", iChild);
60153 return;
60154 }
60155
60156 if( ePtrmapType!=eType || iPtrmapParent!=iParent ){
60157 checkAppendMsg(pCheck,
60158 "Bad ptr map entry key=%d expected=(%d,%d) got=(%d,%d)",
60159 iChild, eType, iParent, ePtrmapType, iPtrmapParent);
60160 }
60161 }
60162 #endif
@@ -60008,51 +60167,50 @@
60167 */
60168 static void checkList(
60169 IntegrityCk *pCheck, /* Integrity checking context */
60170 int isFreeList, /* True for a freelist. False for overflow page list */
60171 int iPage, /* Page number for first page in the list */
60172 int N /* Expected number of pages in the list */
 
60173 ){
60174 int i;
60175 int expected = N;
60176 int iFirst = iPage;
60177 while( N-- > 0 && pCheck->mxErr ){
60178 DbPage *pOvflPage;
60179 unsigned char *pOvflData;
60180 if( iPage<1 ){
60181 checkAppendMsg(pCheck,
60182 "%d of %d pages missing from overflow list starting at %d",
60183 N+1, expected, iFirst);
60184 break;
60185 }
60186 if( checkRef(pCheck, iPage) ) break;
60187 if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage) ){
60188 checkAppendMsg(pCheck, "failed to get page %d", iPage);
60189 break;
60190 }
60191 pOvflData = (unsigned char *)sqlite3PagerGetData(pOvflPage);
60192 if( isFreeList ){
60193 int n = get4byte(&pOvflData[4]);
60194 #ifndef SQLITE_OMIT_AUTOVACUUM
60195 if( pCheck->pBt->autoVacuum ){
60196 checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0);
60197 }
60198 #endif
60199 if( n>(int)pCheck->pBt->usableSize/4-2 ){
60200 checkAppendMsg(pCheck,
60201 "freelist leaf count too big on page %d", iPage);
60202 N--;
60203 }else{
60204 for(i=0; i<n; i++){
60205 Pgno iFreePage = get4byte(&pOvflData[8+i*4]);
60206 #ifndef SQLITE_OMIT_AUTOVACUUM
60207 if( pCheck->pBt->autoVacuum ){
60208 checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0);
60209 }
60210 #endif
60211 checkRef(pCheck, iFreePage);
60212 }
60213 N -= n;
60214 }
60215 }
60216 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -60061,11 +60219,11 @@
60219 ** page in this overflow list, check that the pointer-map entry for
60220 ** the following page matches iPage.
60221 */
60222 if( pCheck->pBt->autoVacuum && N>0 ){
60223 i = get4byte(pOvflData);
60224 checkPtrmap(pCheck, i, PTRMAP_OVERFLOW2, iPage);
60225 }
60226 }
60227 #endif
60228 iPage = get4byte(pOvflData);
60229 sqlite3PagerUnref(pOvflPage);
@@ -60093,11 +60251,10 @@
60251 ** the root of the tree.
60252 */
60253 static int checkTreePage(
60254 IntegrityCk *pCheck, /* Context for the sanity check */
60255 int iPage, /* Page number of the page to check */
 
60256 i64 *pnParentMinKey,
60257 i64 *pnParentMaxKey
60258 ){
60259 MemPage *pPage;
60260 int i, rc, depth, d2, pgno, cnt;
@@ -60104,38 +60261,42 @@
60261 int hdr, cellStart;
60262 int nCell;
60263 u8 *data;
60264 BtShared *pBt;
60265 int usableSize;
 
60266 char *hit = 0;
60267 i64 nMinKey = 0;
60268 i64 nMaxKey = 0;
60269 const char *saved_zPfx = pCheck->zPfx;
60270 int saved_v1 = pCheck->v1;
60271 int saved_v2 = pCheck->v2;
60272
60273 /* Check that the page exists
60274 */
60275 pBt = pCheck->pBt;
60276 usableSize = pBt->usableSize;
60277 if( iPage==0 ) return 0;
60278 if( checkRef(pCheck, iPage) ) return 0;
60279 pCheck->zPfx = "Page %d: ";
60280 pCheck->v1 = iPage;
60281 if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
60282 checkAppendMsg(pCheck,
60283 "unable to get the page. error code=%d", rc);
60284 depth = -1;
60285 goto end_of_check;
60286 }
60287
60288 /* Clear MemPage.isInit to make sure the corruption detection code in
60289 ** btreeInitPage() is executed. */
60290 pPage->isInit = 0;
60291 if( (rc = btreeInitPage(pPage))!=0 ){
60292 assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
60293 checkAppendMsg(pCheck,
60294 "btreeInitPage() returns error code %d", rc);
60295 releasePage(pPage);
60296 depth = -1;
60297 goto end_of_check;
60298 }
60299
60300 /* Check out all the cells.
60301 */
60302 depth = 0;
@@ -60144,99 +60305,101 @@
60305 u32 sz;
60306 CellInfo info;
60307
60308 /* Check payload overflow pages
60309 */
60310 pCheck->zPfx = "On tree page %d cell %d: ";
60311 pCheck->v1 = iPage;
60312 pCheck->v2 = i;
60313 pCell = findCell(pPage,i);
60314 btreeParseCellPtr(pPage, pCell, &info);
60315 sz = info.nPayload;
 
60316 /* For intKey pages, check that the keys are in order.
60317 */
60318 if( pPage->intKey ){
60319 if( i==0 ){
60320 nMinKey = nMaxKey = info.nKey;
60321 }else if( info.nKey <= nMaxKey ){
60322 checkAppendMsg(pCheck,
60323 "Rowid %lld out of order (previous was %lld)", info.nKey, nMaxKey);
60324 }
60325 nMaxKey = info.nKey;
60326 }
 
60327 if( (sz>info.nLocal)
60328 && (&pCell[info.iOverflow]<=&pPage->aData[pBt->usableSize])
60329 ){
60330 int nPage = (sz - info.nLocal + usableSize - 5)/(usableSize - 4);
60331 Pgno pgnoOvfl = get4byte(&pCell[info.iOverflow]);
60332 #ifndef SQLITE_OMIT_AUTOVACUUM
60333 if( pBt->autoVacuum ){
60334 checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage);
60335 }
60336 #endif
60337 checkList(pCheck, 0, pgnoOvfl, nPage);
60338 }
60339
60340 /* Check sanity of left child page.
60341 */
60342 if( !pPage->leaf ){
60343 pgno = get4byte(pCell);
60344 #ifndef SQLITE_OMIT_AUTOVACUUM
60345 if( pBt->autoVacuum ){
60346 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
60347 }
60348 #endif
60349 d2 = checkTreePage(pCheck, pgno, &nMinKey, i==0?NULL:&nMaxKey);
60350 if( i>0 && d2!=depth ){
60351 checkAppendMsg(pCheck, "Child page depth differs");
60352 }
60353 depth = d2;
60354 }
60355 }
60356
60357 if( !pPage->leaf ){
60358 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
60359 pCheck->zPfx = "On page %d at right child: ";
60360 pCheck->v1 = iPage;
60361 #ifndef SQLITE_OMIT_AUTOVACUUM
60362 if( pBt->autoVacuum ){
60363 checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage);
60364 }
60365 #endif
60366 checkTreePage(pCheck, pgno, NULL, !pPage->nCell?NULL:&nMaxKey);
60367 }
60368
60369 /* For intKey leaf pages, check that the min/max keys are in order
60370 ** with any left/parent/right pages.
60371 */
60372 pCheck->zPfx = "Page %d: ";
60373 pCheck->v1 = iPage;
60374 if( pPage->leaf && pPage->intKey ){
60375 /* if we are a left child page */
60376 if( pnParentMinKey ){
60377 /* if we are the left most child page */
60378 if( !pnParentMaxKey ){
60379 if( nMaxKey > *pnParentMinKey ){
60380 checkAppendMsg(pCheck,
60381 "Rowid %lld out of order (max larger than parent min of %lld)",
60382 nMaxKey, *pnParentMinKey);
60383 }
60384 }else{
60385 if( nMinKey <= *pnParentMinKey ){
60386 checkAppendMsg(pCheck,
60387 "Rowid %lld out of order (min less than parent min of %lld)",
60388 nMinKey, *pnParentMinKey);
60389 }
60390 if( nMaxKey > *pnParentMaxKey ){
60391 checkAppendMsg(pCheck,
60392 "Rowid %lld out of order (max larger than parent max of %lld)",
60393 nMaxKey, *pnParentMaxKey);
60394 }
60395 *pnParentMinKey = nMaxKey;
60396 }
60397 /* else if we're a right child page */
60398 } else if( pnParentMaxKey ){
60399 if( nMinKey <= *pnParentMaxKey ){
60400 checkAppendMsg(pCheck,
60401 "Rowid %lld out of order (min less than parent max of %lld)",
60402 nMinKey, *pnParentMaxKey);
60403 }
60404 }
60405 }
@@ -60244,10 +60407,11 @@
60407 /* Check for complete coverage of the page
60408 */
60409 data = pPage->aData;
60410 hdr = pPage->hdrOffset;
60411 hit = sqlite3PageMalloc( pBt->pageSize );
60412 pCheck->zPfx = 0;
60413 if( hit==0 ){
60414 pCheck->mallocFailed = 1;
60415 }else{
60416 int contentOffset = get2byteNotZero(&data[hdr+5]);
60417 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
@@ -60261,11 +60425,12 @@
60425 int j;
60426 if( pc<=usableSize-4 ){
60427 size = cellSizePtr(pPage, &data[pc]);
60428 }
60429 if( (int)(pc+size-1)>=usableSize ){
60430 pCheck->zPfx = 0;
60431 checkAppendMsg(pCheck,
60432 "Corruption detected in cell %d on page %d",i,iPage);
60433 }else{
60434 for(j=pc+size-1; j>=pc; j--) hit[j]++;
60435 }
60436 }
@@ -60283,23 +60448,28 @@
60448 }
60449 for(i=cnt=0; i<usableSize; i++){
60450 if( hit[i]==0 ){
60451 cnt++;
60452 }else if( hit[i]>1 ){
60453 checkAppendMsg(pCheck,
60454 "Multiple uses for byte %d of page %d", i, iPage);
60455 break;
60456 }
60457 }
60458 if( cnt!=data[hdr+7] ){
60459 checkAppendMsg(pCheck,
60460 "Fragmentation of %d bytes reported as %d on page %d",
60461 cnt, data[hdr+7], iPage);
60462 }
60463 }
60464 sqlite3PageFree(hit);
60465 releasePage(pPage);
60466
60467 end_of_check:
60468 pCheck->zPfx = saved_zPfx;
60469 pCheck->v1 = saved_v1;
60470 pCheck->v2 = saved_v2;
60471 return depth+1;
60472 }
60473 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
60474
60475 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
@@ -60336,10 +60506,13 @@
60506 sCheck.pPager = pBt->pPager;
60507 sCheck.nPage = btreePagecount(sCheck.pBt);
60508 sCheck.mxErr = mxErr;
60509 sCheck.nErr = 0;
60510 sCheck.mallocFailed = 0;
60511 sCheck.zPfx = 0;
60512 sCheck.v1 = 0;
60513 sCheck.v2 = 0;
60514 *pnErr = 0;
60515 if( sCheck.nPage==0 ){
60516 sqlite3BtreeLeave(p);
60517 return 0;
60518 }
@@ -60355,53 +60528,57 @@
60528 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
60529 sCheck.errMsg.useMalloc = 2;
60530
60531 /* Check the integrity of the freelist
60532 */
60533 sCheck.zPfx = "Main freelist: ";
60534 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
60535 get4byte(&pBt->pPage1->aData[36]));
60536 sCheck.zPfx = 0;
60537
60538 /* Check all the tables.
60539 */
60540 for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
60541 if( aRoot[i]==0 ) continue;
60542 #ifndef SQLITE_OMIT_AUTOVACUUM
60543 if( pBt->autoVacuum && aRoot[i]>1 ){
60544 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
60545 }
60546 #endif
60547 sCheck.zPfx = "List of tree roots: ";
60548 checkTreePage(&sCheck, aRoot[i], NULL, NULL);
60549 sCheck.zPfx = 0;
60550 }
60551
60552 /* Make sure every page in the file is referenced
60553 */
60554 for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
60555 #ifdef SQLITE_OMIT_AUTOVACUUM
60556 if( getPageReferenced(&sCheck, i)==0 ){
60557 checkAppendMsg(&sCheck, "Page %d is never used", i);
60558 }
60559 #else
60560 /* If the database supports auto-vacuum, make sure no tables contain
60561 ** references to pointer-map pages.
60562 */
60563 if( getPageReferenced(&sCheck, i)==0 &&
60564 (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
60565 checkAppendMsg(&sCheck, "Page %d is never used", i);
60566 }
60567 if( getPageReferenced(&sCheck, i)!=0 &&
60568 (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
60569 checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
60570 }
60571 #endif
60572 }
60573
60574 /* Make sure this analysis did not leave any unref() pages.
60575 ** This is an internal consistency check; an integrity check
60576 ** of the integrity check.
60577 */
60578 if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
60579 checkAppendMsg(&sCheck,
60580 "Outstanding page count goes from %d to %d during this analysis",
60581 nRef, sqlite3PagerRefcount(pBt->pPager)
60582 );
60583 }
60584
@@ -60593,11 +60770,11 @@
60770
60771 /* Save the positions of all other cursors open on this table. This is
60772 ** required in case any of them are holding references to an xFetch
60773 ** version of the b-tree page modified by the accessPayload call below.
60774 **
60775 ** Note that pCsr must be open on a INTKEY table and saveCursorPosition()
60776 ** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
60777 ** saveAllCursors can only return SQLITE_OK.
60778 */
60779 VVA_ONLY(rc =) saveAllCursors(pCsr->pBt, pCsr->pgnoRoot, pCsr);
60780 assert( rc==SQLITE_OK );
@@ -61461,11 +61638,14 @@
61638 /* If MEM_Dyn is set then Mem.xDel!=0.
61639 ** Mem.xDel is might not be initialized if MEM_Dyn is clear.
61640 */
61641 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
61642
61643 /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
61644 ** ensure that if Mem.szMalloc>0 then it is safe to do
61645 ** Mem.z = Mem.zMalloc without having to check Mem.flags&MEM_Dyn.
61646 ** That saves a few cycles in inner loops. */
61647 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
61648
61649 /* Cannot be both MEM_Int and MEM_Real at the same time */
61650 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
61651
@@ -61570,11 +61750,11 @@
61750 }else{
61751 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
61752 }
61753 }
61754
61755 if( bPreserve && pMem->z && pMem->z!=pMem->zMalloc ){
61756 memcpy(pMem->zMalloc, pMem->z, pMem->n);
61757 }
61758 if( (pMem->flags&MEM_Dyn)!=0 ){
61759 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
61760 pMem->xDel((void *)(pMem->z));
@@ -61597,11 +61777,12 @@
61777 **
61778 ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
61779 ** if unable to complete the resizing.
61780 */
61781 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
61782 assert( szNew>0 );
61783 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
61784 if( pMem->szMalloc<szNew ){
61785 return sqlite3VdbeMemGrow(pMem, szNew, 0);
61786 }
61787 assert( (pMem->flags & MEM_Dyn)==0 );
61788 pMem->z = pMem->zMalloc;
@@ -62321,11 +62502,14 @@
62502 nAlloc += (enc==SQLITE_UTF8?1:2);
62503 }
62504 if( nByte>iLimit ){
62505 return SQLITE_TOOBIG;
62506 }
62507 testcase( nAlloc==0 );
62508 testcase( nAlloc==31 );
62509 testcase( nAlloc==32 );
62510 if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
62511 return SQLITE_NOMEM;
62512 }
62513 memcpy(pMem->z, z, nAlloc);
62514 }else if( xDel==SQLITE_DYNAMIC ){
62515 sqlite3VdbeMemRelease(pMem);
@@ -62424,11 +62608,11 @@
62608 /*
62609 ** The pVal argument is known to be a value other than NULL.
62610 ** Convert it into a string with encoding enc and return a pointer
62611 ** to a zero-terminated version of that string.
62612 */
62613 static SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){
62614 assert( pVal!=0 );
62615 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
62616 assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
62617 assert( (pVal->flags & MEM_RowSet)==0 );
62618 assert( (pVal->flags & (MEM_Null))==0 );
@@ -63751,11 +63935,12 @@
63935 if( addr==p->nOp-1 ) p->nOp--;
63936 }
63937 }
63938
63939 /*
63940 ** If the last opcode is "op" and it is not a jump destination,
63941 ** then remove it. Return true if and only if an opcode was removed.
63942 */
63943 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){
63944 if( (p->nOp-1)>(p->pParse->iFixedOp) && p->aOp[p->nOp-1].opcode==op ){
63945 sqlite3VdbeChangeToNoop(p, p->nOp-1);
63946 return 1;
@@ -64743,11 +64928,11 @@
64928 ** the call above. */
64929 }else if( pCx->pCursor ){
64930 sqlite3BtreeCloseCursor(pCx->pCursor);
64931 }
64932 #ifndef SQLITE_OMIT_VIRTUALTABLE
64933 else if( pCx->pVtabCursor ){
64934 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
64935 const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
64936 p->inVtabMethod = 1;
64937 pModule->xClose(pVtabCursor);
64938 p->inVtabMethod = 0;
@@ -64786,13 +64971,14 @@
64971 static void closeAllCursors(Vdbe *p){
64972 if( p->pFrame ){
64973 VdbeFrame *pFrame;
64974 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
64975 sqlite3VdbeFrameRestore(pFrame);
64976 p->pFrame = 0;
64977 p->nFrame = 0;
64978 }
64979 assert( p->nFrame==0 );
 
64980
64981 if( p->apCsr ){
64982 int i;
64983 for(i=0; i<p->nCursor; i++){
64984 VdbeCursor *pC = p->apCsr[i];
@@ -64810,11 +64996,11 @@
64996 p->pDelFrame = pDel->pParent;
64997 sqlite3VdbeFrameDelete(pDel);
64998 }
64999
65000 /* Delete any auxdata allocations made by the VM */
65001 if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p, -1, 0);
65002 assert( p->pAuxData==0 );
65003 }
65004
65005 /*
65006 ** Clean up the VM after a single run.
@@ -65676,14 +65862,10 @@
65862 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
65863 vdbeFreeOpArray(db, p->aOp, p->nOp);
65864 sqlite3DbFree(db, p->aColName);
65865 sqlite3DbFree(db, p->zSql);
65866 sqlite3DbFree(db, p->pFree);
 
 
 
 
65867 }
65868
65869 /*
65870 ** Delete an entire VDBE.
65871 */
@@ -65720,13 +65902,11 @@
65902 #endif
65903 assert( p->deferredMoveto );
65904 assert( p->isTable );
65905 rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
65906 if( rc ) return rc;
 
65907 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
 
65908 #ifdef SQLITE_TEST
65909 sqlite3_search_count++;
65910 #endif
65911 p->deferredMoveto = 0;
65912 p->cacheStatus = CACHE_STALE;
@@ -65747,10 +65927,21 @@
65927 rc = sqlite3BtreeCursorRestore(p->pCursor, &isDifferentRow);
65928 p->cacheStatus = CACHE_STALE;
65929 if( isDifferentRow ) p->nullRow = 1;
65930 return rc;
65931 }
65932
65933 /*
65934 ** Check to ensure that the cursor is valid. Restore the cursor
65935 ** if need be. Return any I/O error from the restore operation.
65936 */
65937 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){
65938 if( sqlite3BtreeCursorHasMoved(p->pCursor) ){
65939 return handleMovedCursor(p);
65940 }
65941 return SQLITE_OK;
65942 }
65943
65944 /*
65945 ** Make sure the cursor p is ready to read or write the row to which it
65946 ** was last positioned. Return an error code if an OOM fault or I/O error
65947 ** prevents us from positioning the cursor to its correct position.
@@ -65765,11 +65956,11 @@
65956 */
65957 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor *p){
65958 if( p->deferredMoveto ){
65959 return handleDeferredMoveto(p);
65960 }
65961 if( p->pCursor && sqlite3BtreeCursorHasMoved(p->pCursor) ){
65962 return handleMovedCursor(p);
65963 }
65964 return SQLITE_OK;
65965 }
65966
@@ -67390,10 +67581,11 @@
67581 void (*xDel)(void *),
67582 unsigned char enc
67583 ){
67584 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
67585 assert( xDel!=SQLITE_DYNAMIC );
67586 if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
67587 if( n>0x7fffffff ){
67588 (void)invokeValueDestructor(z, xDel, pCtx);
67589 }else{
67590 setResultStrOrError(pCtx, z, (int)n, enc, xDel);
67591 }
@@ -68712,125 +68904,10 @@
68904 return sqlite3StrAccumFinish(&out);
68905 }
68906
68907 #endif /* #ifndef SQLITE_OMIT_TRACE */
68908
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68909 /************** End of vdbetrace.c *******************************************/
68910 /************** Begin file vdbe.c ********************************************/
68911 /*
68912 ** 2001 September 15
68913 **
@@ -69043,10 +69120,11 @@
69120 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
69121 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
69122 memset(pCx, 0, sizeof(VdbeCursor));
69123 pCx->iDb = iDb;
69124 pCx->nField = nField;
69125 pCx->aOffset = &pCx->aType[nField];
69126 if( isBtreeCursor ){
69127 pCx->pCursor = (BtCursor*)
69128 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
69129 sqlite3BtreeCursorZero(pCx->pCursor);
69130 }
@@ -70475,21 +70553,14 @@
70553 assert( pOp->p4type==P4_FUNCDEF );
70554 ctx.pFunc = pOp->p4.pFunc;
70555 ctx.iOp = pc;
70556 ctx.pVdbe = p;
70557 MemSetTypeFlag(ctx.pOut, MEM_Null);
 
70558 ctx.fErrorOrAux = 0;
 
 
 
 
 
 
70559 db->lastRowid = lastRowid;
70560 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
70561 lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */
70562
70563 /* If the function returned an error, throw an exception */
70564 if( ctx.fErrorOrAux ){
70565 if( ctx.isError ){
70566 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut));
@@ -71201,11 +71272,11 @@
71272 memAboutToChange(p, pDest);
71273 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71274 pC = p->apCsr[pOp->p1];
71275 assert( pC!=0 );
71276 assert( p2<pC->nField );
71277 aOffset = pC->aOffset;
71278 #ifndef SQLITE_OMIT_VIRTUALTABLE
71279 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
71280 #endif
71281 pCrsr = pC->pCursor;
71282 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -71212,11 +71283,11 @@
71283 assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
71284
71285 /* If the cursor cache is stale, bring it up-to-date */
71286 rc = sqlite3VdbeCursorMoveto(pC);
71287 if( rc ) goto abort_due_to_error;
71288 if( pC->cacheStatus!=p->cacheCtr ){
71289 if( pC->nullRow ){
71290 if( pCrsr==0 ){
71291 assert( pC->pseudoTableReg>0 );
71292 pReg = &aMem[pC->pseudoTableReg];
71293 assert( pReg->flags & MEM_Blob );
@@ -71257,18 +71328,10 @@
71328 }
71329 pC->cacheStatus = p->cacheCtr;
71330 pC->iHdrOffset = getVarint32(pC->aRow, offset);
71331 pC->nHdrParsed = 0;
71332 aOffset[0] = offset;
 
 
 
 
 
 
 
 
71333
71334 /* Make sure a corrupt database has not given us an oversize header.
71335 ** Do this now to avoid an oversize memory allocation.
71336 **
71337 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -71279,19 +71342,36 @@
71342 */
71343 if( offset > 98307 || offset > pC->payloadSize ){
71344 rc = SQLITE_CORRUPT_BKPT;
71345 goto op_column_error;
71346 }
71347
71348 if( avail<offset ){
71349 /* pC->aRow does not have to hold the entire row, but it does at least
71350 ** need to cover the header of the record. If pC->aRow does not contain
71351 ** the complete header, then set it to zero, forcing the header to be
71352 ** dynamically allocated. */
71353 pC->aRow = 0;
71354 pC->szRow = 0;
71355 }
71356
71357 /* The following goto is an optimization. It can be omitted and
71358 ** everything will still work. But OP_Column is measurably faster
71359 ** by skipping the subsequent conditional, which is always true.
71360 */
71361 assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
71362 goto op_column_read_header;
71363 }
71364
71365 /* Make sure at least the first p2+1 entries of the header have been
71366 ** parsed and valid information is in aOffset[] and pC->aType[].
71367 */
71368 if( pC->nHdrParsed<=p2 ){
71369 /* If there is more header available for parsing in the record, try
71370 ** to extract additional fields up through the p2+1-th field
71371 */
71372 op_column_read_header:
71373 if( pC->iHdrOffset<aOffset[0] ){
71374 /* Make sure zData points to enough of the record to cover the header. */
71375 if( pC->aRow==0 ){
71376 memset(&sMem, 0, sizeof(sMem));
71377 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
@@ -71332,19 +71412,20 @@
71412 if( pC->aRow==0 ){
71413 sqlite3VdbeMemRelease(&sMem);
71414 sMem.flags = MEM_Null;
71415 }
71416
71417 /* The record is corrupt if any of the following are true:
71418 ** (1) the bytes of the header extend past the declared header size
71419 ** (zHdr>zEndHdr)
71420 ** (2) the entire header was used but not all data was used
71421 ** (zHdr==zEndHdr && offset!=pC->payloadSize)
71422 ** (3) the end of the data extends beyond the end of the record.
71423 ** (offset > pC->payloadSize)
71424 */
71425 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset!=pC->payloadSize))
71426 || (offset > pC->payloadSize)
 
71427 ){
71428 rc = SQLITE_CORRUPT_BKPT;
71429 goto op_column_error;
71430 }
71431 }
@@ -71531,11 +71612,11 @@
71612 ** out how much space is required for the new record.
71613 */
71614 pRec = pLast;
71615 do{
71616 assert( memIsValid(pRec) );
71617 pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format);
71618 len = sqlite3VdbeSerialTypeLen(serial_type);
71619 if( pRec->flags & MEM_Zero ){
71620 if( nData ){
71621 sqlite3VdbeMemExpandBlob(pRec);
71622 }else{
@@ -71580,11 +71661,11 @@
71661 i = putVarint32(zNewRecord, nHdr);
71662 j = nHdr;
71663 assert( pData0<=pLast );
71664 pRec = pData0;
71665 do{
71666 serial_type = pRec->uTemp;
71667 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
71668 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
71669 }while( (++pRec)<=pLast );
71670 assert( i==nHdr );
71671 assert( j==nByte );
@@ -72205,14 +72286,10 @@
72286 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
72287 pCur->pKeyInfo = pKeyInfo;
72288 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
72289 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
72290
 
 
 
 
72291 /* Set the VdbeCursor.isTable variable. Previous versions of
72292 ** SQLite used to check if the root-page flags were sane at this point
72293 ** and report database corruption if they were not, but this check has
72294 ** since moved into the btree layer. */
72295 pCur->isTable = pOp->p4type!=P4_KEYINFO;
@@ -72483,11 +72560,10 @@
72560 pIn3 = &aMem[pOp->p3];
72561 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
72562 applyNumericAffinity(pIn3, 0);
72563 }
72564 iKey = sqlite3VdbeIntValue(pIn3);
 
72565
72566 /* If the P3 value could not be converted into an integer without
72567 ** loss of information, then special processing is required... */
72568 if( (pIn3->flags & MEM_Int)==0 ){
72569 if( (pIn3->flags & MEM_Real)==0 ){
@@ -72519,17 +72595,14 @@
72595 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
72596 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
72597 }
72598 }
72599 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
72600 pC->movetoTarget = iKey; /* Used by OP_Delete */
72601 if( rc!=SQLITE_OK ){
72602 goto abort_due_to_error;
72603 }
 
 
 
 
72604 }else{
72605 nField = pOp->p4.i;
72606 assert( pOp->p4type==P4_INT32 );
72607 assert( nField>0 );
72608 r.pKeyInfo = pC->pKeyInfo;
@@ -72555,11 +72628,10 @@
72628 ExpandBlob(r.aMem);
72629 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
72630 if( rc!=SQLITE_OK ){
72631 goto abort_due_to_error;
72632 }
 
72633 }
72634 pC->deferredMoveto = 0;
72635 pC->cacheStatus = CACHE_STALE;
72636 #ifdef SQLITE_TEST
72637 sqlite3_search_count++;
@@ -72567,21 +72639,19 @@
72639 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
72640 if( res<0 || (res==0 && oc==OP_SeekGT) ){
72641 res = 0;
72642 rc = sqlite3BtreeNext(pC->pCursor, &res);
72643 if( rc!=SQLITE_OK ) goto abort_due_to_error;
 
72644 }else{
72645 res = 0;
72646 }
72647 }else{
72648 assert( oc==OP_SeekLT || oc==OP_SeekLE );
72649 if( res>0 || (res==0 && oc==OP_SeekLT) ){
72650 res = 0;
72651 rc = sqlite3BtreePrevious(pC->pCursor, &res);
72652 if( rc!=SQLITE_OK ) goto abort_due_to_error;
 
72653 }else{
72654 /* res might be negative because the table is empty. Check to
72655 ** see if this is the case.
72656 */
72657 res = sqlite3BtreeEof(pC->pCursor);
@@ -72614,11 +72684,10 @@
72684 assert( pC->pCursor!=0 );
72685 assert( pC->isTable );
72686 pC->nullRow = 0;
72687 pIn2 = &aMem[pOp->p2];
72688 pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
 
72689 pC->deferredMoveto = 1;
72690 break;
72691 }
72692
72693
@@ -72800,19 +72869,17 @@
72869 pCrsr = pC->pCursor;
72870 assert( pCrsr!=0 );
72871 res = 0;
72872 iKey = pIn3->u.i;
72873 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
72874 pC->movetoTarget = iKey; /* Used by OP_Delete */
 
72875 pC->nullRow = 0;
72876 pC->cacheStatus = CACHE_STALE;
72877 pC->deferredMoveto = 0;
72878 VdbeBranchTaken(res!=0,2);
72879 if( res!=0 ){
72880 pc = pOp->p2 - 1;
 
72881 }
72882 pC->seekResult = res;
72883 break;
72884 }
72885
@@ -72942,36 +73009,24 @@
73009 ** largest possible integer (9223372036854775807) then the database
73010 ** engine starts picking positive candidate ROWIDs at random until
73011 ** it finds one that is not previously used. */
73012 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
73013 ** an AUTOINCREMENT table. */
 
 
 
 
73014 cnt = 0;
73015 do{
73016 sqlite3_randomness(sizeof(v), &v);
73017 v &= (MAX_ROWID>>1); v++; /* Ensure that v is greater than zero */
73018 }while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
73019 0, &res))==SQLITE_OK)
73020 && (res==0)
73021 && (++cnt<100));
 
 
 
 
 
 
 
 
 
 
73022 if( rc==SQLITE_OK && res==0 ){
73023 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
73024 goto abort_due_to_error;
73025 }
73026 assert( v>0 ); /* EV: R-40812-03570 */
73027 }
 
73028 pC->deferredMoveto = 0;
73029 pC->cacheStatus = CACHE_STALE;
73030 }
73031 pOut->u.i = v;
73032 break;
@@ -73072,11 +73127,10 @@
73127 }
73128 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
73129 pData->z, pData->n, nZero,
73130 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
73131 );
 
73132 pC->deferredMoveto = 0;
73133 pC->cacheStatus = CACHE_STALE;
73134
73135 /* Invoke the update-hook if required. */
73136 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
@@ -73109,37 +73163,36 @@
73163 ** pointing to. The update hook will be invoked, if it exists.
73164 ** If P4 is not NULL then the P1 cursor must have been positioned
73165 ** using OP_NotFound prior to invoking this opcode.
73166 */
73167 case OP_Delete: {
 
73168 VdbeCursor *pC;
73169
73170 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73171 pC = p->apCsr[pOp->p1];
73172 assert( pC!=0 );
73173 assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
 
 
 
 
 
 
 
 
 
73174 assert( pC->deferredMoveto==0 );
 
 
73175
73176 #ifdef SQLITE_DEBUG
73177 /* The seek operation that positioned the cursor prior to OP_Delete will
73178 ** have also set the pC->movetoTarget field to the rowid of the row that
73179 ** is being deleted */
73180 if( pOp->p4.z && pC->isTable ){
73181 i64 iKey = 0;
73182 sqlite3BtreeKeySize(pC->pCursor, &iKey);
73183 assert( pC->movetoTarget==iKey );
73184 }
73185 #endif
73186
73187 rc = sqlite3BtreeDelete(pC->pCursor);
73188 pC->cacheStatus = CACHE_STALE;
73189
73190 /* Invoke the update-hook if required. */
73191 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
73192 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
73193 db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget);
73194 assert( pC->iDb>=0 );
73195 }
73196 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
73197 break;
73198 }
@@ -73188,23 +73241,32 @@
73241 pc = pOp->p2-1;
73242 }
73243 break;
73244 };
73245
73246 /* Opcode: SorterData P1 P2 P3 * *
73247 ** Synopsis: r[P2]=data
73248 **
73249 ** Write into register P2 the current sorter data for sorter cursor P1.
73250 ** Then clear the column header cache on cursor P3.
73251 **
73252 ** This opcode is normally use to move a record out of the sorter and into
73253 ** a register that is the source for a pseudo-table cursor created using
73254 ** OpenPseudo. That pseudo-table cursor is the one that is identified by
73255 ** parameter P3. Clearing the P3 column cache as part of this opcode saves
73256 ** us from having to issue a separate NullRow instruction to clear that cache.
73257 */
73258 case OP_SorterData: {
73259 VdbeCursor *pC;
73260
73261 pOut = &aMem[pOp->p2];
73262 pC = p->apCsr[pOp->p1];
73263 assert( isSorter(pC) );
73264 rc = sqlite3VdbeSorterRowkey(pC, pOut);
73265 assert( rc!=SQLITE_OK || (pOut->flags & MEM_Blob) );
73266 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73267 p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE;
73268 break;
73269 }
73270
73271 /* Opcode: RowData P1 P2 * * *
73272 ** Synopsis: r[P2]=data
@@ -73247,20 +73309,24 @@
73309 assert( pC!=0 );
73310 assert( pC->nullRow==0 );
73311 assert( pC->pseudoTableReg==0 );
73312 assert( pC->pCursor!=0 );
73313 pCrsr = pC->pCursor;
 
73314
73315 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
73316 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
73317 ** the cursor. If this where not the case, on of the following assert()s
73318 ** would fail. Should this ever change (because of changes in the code
73319 ** generator) then the fix would be to insert a call to
73320 ** sqlite3VdbeCursorMoveto().
73321 */
73322 assert( pC->deferredMoveto==0 );
73323 assert( sqlite3BtreeCursorIsValid(pCrsr) );
73324 #if 0 /* Not required due to the previous to assert() statements */
73325 rc = sqlite3VdbeCursorMoveto(pC);
73326 if( rc!=SQLITE_OK ) goto abort_due_to_error;
73327 #endif
73328
73329 if( pC->isTable==0 ){
73330 assert( !pC->isTable );
73331 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
73332 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
@@ -73273,11 +73339,12 @@
73339 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
73340 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
73341 goto too_big;
73342 }
73343 }
73344 testcase( n==0 );
73345 if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
73346 goto no_mem;
73347 }
73348 pOut->n = n;
73349 MemSetTypeFlag(pOut, MEM_Blob);
73350 if( pC->isTable==0 ){
@@ -73324,18 +73391,14 @@
73391 rc = pModule->xRowid(pC->pVtabCursor, &v);
73392 sqlite3VtabImportErrmsg(p, pVtab);
73393 #endif /* SQLITE_OMIT_VIRTUALTABLE */
73394 }else{
73395 assert( pC->pCursor!=0 );
73396 rc = sqlite3VdbeCursorRestore(pC);
73397 if( rc ) goto abort_due_to_error;
73398 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73399 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
 
 
 
 
73400 }
73401 pOut->u.i = v;
73402 break;
73403 }
73404
@@ -73350,11 +73413,10 @@
73413
73414 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73415 pC = p->apCsr[pOp->p1];
73416 assert( pC!=0 );
73417 pC->nullRow = 1;
 
73418 pC->cacheStatus = CACHE_STALE;
73419 if( pC->pCursor ){
73420 sqlite3BtreeClearCursor(pC->pCursor);
73421 }
73422 break;
@@ -73384,11 +73446,10 @@
73446 res = 0;
73447 assert( pCrsr!=0 );
73448 rc = sqlite3BtreeLast(pCrsr, &res);
73449 pC->nullRow = (u8)res;
73450 pC->deferredMoveto = 0;
 
73451 pC->cacheStatus = CACHE_STALE;
73452 #ifdef SQLITE_DEBUG
73453 pC->seekOp = OP_Last;
73454 #endif
73455 if( pOp->p2>0 ){
@@ -73451,11 +73512,10 @@
73512 pCrsr = pC->pCursor;
73513 assert( pCrsr );
73514 rc = sqlite3BtreeFirst(pCrsr, &res);
73515 pC->deferredMoveto = 0;
73516 pC->cacheStatus = CACHE_STALE;
 
73517 }
73518 pC->nullRow = (u8)res;
73519 assert( pOp->p2>0 && pOp->p2<p->nOp );
73520 VdbeBranchTaken(res!=0,2);
73521 if( res ){
@@ -73577,11 +73637,10 @@
73637 sqlite3_search_count++;
73638 #endif
73639 }else{
73640 pC->nullRow = 1;
73641 }
 
73642 goto check_for_interrupt;
73643 }
73644
73645 /* Opcode: IdxInsert P1 P2 P3 * P5
73646 ** Synopsis: key=r[P2]
@@ -73693,14 +73752,20 @@
73752 pC = p->apCsr[pOp->p1];
73753 assert( pC!=0 );
73754 pCrsr = pC->pCursor;
73755 assert( pCrsr!=0 );
73756 pOut->flags = MEM_Null;
73757 assert( pC->isTable==0 );
 
73758 assert( pC->deferredMoveto==0 );
73759
73760 /* sqlite3VbeCursorRestore() can only fail if the record has been deleted
73761 ** out from under the cursor. That will never happend for an IdxRowid
73762 ** opcode, hence the NEVER() arround the check of the return value.
73763 */
73764 rc = sqlite3VdbeCursorRestore(pC);
73765 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
73766
73767 if( !pC->nullRow ){
73768 rowid = 0; /* Not needed. Only used to silence a warning. */
73769 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
73770 if( rc!=SQLITE_OK ){
73771 goto abort_due_to_error;
@@ -74556,18 +74621,13 @@
74621 ctx.pMem = pMem = &aMem[pOp->p3];
74622 pMem->n++;
74623 sqlite3VdbeMemInit(&t, db, MEM_Null);
74624 ctx.pOut = &t;
74625 ctx.isError = 0;
74626 ctx.pVdbe = p;
74627 ctx.iOp = pc;
74628 ctx.skipFlag = 0;
 
 
 
 
 
 
74629 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
74630 if( ctx.isError ){
74631 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t));
74632 rc = ctx.isError;
74633 }
@@ -81597,10 +81657,11 @@
81657 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
81658 pNew->addrOpenEphm[0] = -1;
81659 pNew->addrOpenEphm[1] = -1;
81660 pNew->nSelectRow = p->nSelectRow;
81661 pNew->pWith = withDup(db, p->pWith);
81662 sqlite3SelectSetName(pNew, p->zSelName);
81663 return pNew;
81664 }
81665 #else
81666 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
81667 assert( p==0 );
@@ -81739,36 +81800,44 @@
81800 }
81801
81802 /*
81803 ** These routines are Walker callbacks. Walker.u.pi is a pointer
81804 ** to an integer. These routines are checking an expression to see
81805 ** if it is a constant. Set *Walker.u.i to 0 if the expression is
81806 ** not constant.
81807 **
81808 ** These callback routines are used to implement the following:
81809 **
81810 ** sqlite3ExprIsConstant() pWalker->u.i==1
81811 ** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2
81812 ** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4
81813 **
81814 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
81815 ** in a CREATE TABLE statement. The Walker.u.i value is 4 when parsing
81816 ** an existing schema and 3 when processing a new statement. A bound
81817 ** parameter raises an error for new statements, but is silently converted
81818 ** to NULL for existing schemas. This allows sqlite_master tables that
81819 ** contain a bound parameter because they were generated by older versions
81820 ** of SQLite to be parsed by newer versions of SQLite without raising a
81821 ** malformed schema error.
81822 */
81823 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
81824
81825 /* If pWalker->u.i is 2 then any term of the expression that comes from
81826 ** the ON or USING clauses of a join disqualifies the expression
81827 ** from being considered constant. */
81828 if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
81829 pWalker->u.i = 0;
81830 return WRC_Abort;
81831 }
81832
81833 switch( pExpr->op ){
81834 /* Consider functions to be constant if all their arguments are constant
81835 ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST
81836 ** flag. */
81837 case TK_FUNCTION:
81838 if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){
81839 return WRC_Continue;
81840 }
81841 /* Fall through */
81842 case TK_ID:
81843 case TK_COLUMN:
@@ -81778,10 +81847,23 @@
81847 testcase( pExpr->op==TK_COLUMN );
81848 testcase( pExpr->op==TK_AGG_FUNCTION );
81849 testcase( pExpr->op==TK_AGG_COLUMN );
81850 pWalker->u.i = 0;
81851 return WRC_Abort;
81852 case TK_VARIABLE:
81853 if( pWalker->u.i==4 ){
81854 /* Silently convert bound parameters that appear inside of CREATE
81855 ** statements into a NULL when parsing the CREATE statement text out
81856 ** of the sqlite_master table */
81857 pExpr->op = TK_NULL;
81858 }else if( pWalker->u.i==3 ){
81859 /* A bound parameter in a CREATE statement that originates from
81860 ** sqlite3_prepare() causes an error */
81861 pWalker->u.i = 0;
81862 return WRC_Abort;
81863 }
81864 /* Fall through */
81865 default:
81866 testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
81867 testcase( pExpr->op==TK_EXISTS ); /* selectNodeIsConstant will disallow */
81868 return WRC_Continue;
81869 }
@@ -81818,11 +81900,11 @@
81900 ** that does no originate from the ON or USING clauses of a join.
81901 ** Return 0 if it involves variables or function calls or terms from
81902 ** an ON or USING clause.
81903 */
81904 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
81905 return exprIsConst(p, 2);
81906 }
81907
81908 /*
81909 ** Walk an expression tree. Return 1 if the expression is constant
81910 ** or a function call with constant arguments. Return and 0 if there
@@ -81830,12 +81912,13 @@
81912 **
81913 ** For the purposes of this function, a double-quoted string (ex: "abc")
81914 ** is considered a variable but a single-quoted string (ex: 'abc') is
81915 ** a constant.
81916 */
81917 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
81918 assert( isInit==0 || isInit==1 );
81919 return exprIsConst(p, 3+isInit);
81920 }
81921
81922 /*
81923 ** If the expression p codes a constant integer that is small enough
81924 ** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -83741,94 +83824,90 @@
83824 iMem = ++pParse->nMem;
83825 sqlite3VdbeAddOp2(v, OP_Copy, target, iMem);
83826 exprToRegister(pExpr, iMem);
83827 }
83828
83829 #ifdef SQLITE_DEBUG
83830 /*
83831 ** Generate a human-readable explanation of an expression tree.
83832 */
83833 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
 
83834 const char *zBinOp = 0; /* Binary operator */
83835 const char *zUniOp = 0; /* Unary operator */
83836 pView = sqlite3TreeViewPush(pView, moreToFollow);
83837 if( pExpr==0 ){
83838 sqlite3TreeViewLine(pView, "nil");
83839 sqlite3TreeViewPop(pView);
83840 return;
83841 }
83842 switch( pExpr->op ){
83843 case TK_AGG_COLUMN: {
83844 sqlite3TreeViewLine(pView, "AGG{%d:%d}",
83845 pExpr->iTable, pExpr->iColumn);
83846 break;
83847 }
83848 case TK_COLUMN: {
83849 if( pExpr->iTable<0 ){
83850 /* This only happens when coding check constraints */
83851 sqlite3TreeViewLine(pView, "COLUMN(%d)", pExpr->iColumn);
83852 }else{
83853 sqlite3TreeViewLine(pView, "{%d:%d}",
83854 pExpr->iTable, pExpr->iColumn);
83855 }
83856 break;
83857 }
83858 case TK_INTEGER: {
83859 if( pExpr->flags & EP_IntValue ){
83860 sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue);
83861 }else{
83862 sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken);
83863 }
83864 break;
83865 }
83866 #ifndef SQLITE_OMIT_FLOATING_POINT
83867 case TK_FLOAT: {
83868 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
83869 break;
83870 }
83871 #endif
83872 case TK_STRING: {
83873 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
83874 break;
83875 }
83876 case TK_NULL: {
83877 sqlite3TreeViewLine(pView,"NULL");
83878 break;
83879 }
83880 #ifndef SQLITE_OMIT_BLOB_LITERAL
83881 case TK_BLOB: {
83882 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
83883 break;
83884 }
83885 #endif
83886 case TK_VARIABLE: {
83887 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
83888 pExpr->u.zToken, pExpr->iColumn);
83889 break;
83890 }
83891 case TK_REGISTER: {
83892 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
83893 break;
83894 }
83895 case TK_AS: {
83896 sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
83897 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
83898 break;
83899 }
83900 case TK_ID: {
83901 sqlite3TreeViewLine(pView,"ID %Q", pExpr->u.zToken);
83902 break;
83903 }
83904 #ifndef SQLITE_OMIT_CAST
83905 case TK_CAST: {
83906 /* Expressions of the form: CAST(pLeft AS token) */
83907 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
83908 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
 
 
 
 
 
 
 
 
 
83909 break;
83910 }
83911 #endif /* SQLITE_OMIT_CAST */
83912 case TK_LT: zBinOp = "LT"; break;
83913 case TK_LE: zBinOp = "LE"; break;
@@ -83848,21 +83927,22 @@
83927 case TK_BITOR: zBinOp = "BITOR"; break;
83928 case TK_SLASH: zBinOp = "DIV"; break;
83929 case TK_LSHIFT: zBinOp = "LSHIFT"; break;
83930 case TK_RSHIFT: zBinOp = "RSHIFT"; break;
83931 case TK_CONCAT: zBinOp = "CONCAT"; break;
83932 case TK_DOT: zBinOp = "DOT"; break;
83933
83934 case TK_UMINUS: zUniOp = "UMINUS"; break;
83935 case TK_UPLUS: zUniOp = "UPLUS"; break;
83936 case TK_BITNOT: zUniOp = "BITNOT"; break;
83937 case TK_NOT: zUniOp = "NOT"; break;
83938 case TK_ISNULL: zUniOp = "ISNULL"; break;
83939 case TK_NOTNULL: zUniOp = "NOTNULL"; break;
83940
83941 case TK_COLLATE: {
83942 sqlite3TreeViewLine(pView, "COLLATE %Q", pExpr->u.zToken);
83943 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
83944 break;
83945 }
83946
83947 case TK_AGG_FUNCTION:
83948 case TK_FUNCTION: {
@@ -83870,45 +83950,40 @@
83950 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
83951 pFarg = 0;
83952 }else{
83953 pFarg = pExpr->x.pList;
83954 }
83955 if( pExpr->op==TK_AGG_FUNCTION ){
83956 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q",
83957 pExpr->op2, pExpr->u.zToken);
83958 }else{
83959 sqlite3TreeViewLine(pView, "FUNCTION %Q", pExpr->u.zToken);
83960 }
83961 if( pFarg ){
83962 sqlite3TreeViewExprList(pView, pFarg, 0, 0);
83963 }
 
83964 break;
83965 }
83966 #ifndef SQLITE_OMIT_SUBQUERY
83967 case TK_EXISTS: {
83968 sqlite3TreeViewLine(pView, "EXISTS-expr");
83969 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
 
83970 break;
83971 }
83972 case TK_SELECT: {
83973 sqlite3TreeViewLine(pView, "SELECT-expr");
83974 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
 
83975 break;
83976 }
83977 case TK_IN: {
83978 sqlite3TreeViewLine(pView, "IN");
83979 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
 
83980 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
83981 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
83982 }else{
83983 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
83984 }
 
83985 break;
83986 }
83987 #endif /* SQLITE_OMIT_SUBQUERY */
83988
83989 /*
@@ -83924,17 +83999,14 @@
83999 */
84000 case TK_BETWEEN: {
84001 Expr *pX = pExpr->pLeft;
84002 Expr *pY = pExpr->x.pList->a[0].pExpr;
84003 Expr *pZ = pExpr->x.pList->a[1].pExpr;
84004 sqlite3TreeViewLine(pView, "BETWEEN");
84005 sqlite3TreeViewExpr(pView, pX, 1);
84006 sqlite3TreeViewExpr(pView, pY, 1);
84007 sqlite3TreeViewExpr(pView, pZ, 0);
 
 
 
84008 break;
84009 }
84010 case TK_TRIGGER: {
84011 /* If the opcode is TK_TRIGGER, then the expression is a reference
84012 ** to a column in the new.* or old.* pseudo-tables available to
@@ -83941,19 +84013,18 @@
84013 ** trigger programs. In this case Expr.iTable is set to 1 for the
84014 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
84015 ** is set to the column of the pseudo-table to read, or to -1 to
84016 ** read the rowid field.
84017 */
84018 sqlite3TreeViewLine(pView, "%s(%d)",
84019 pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn);
84020 break;
84021 }
84022 case TK_CASE: {
84023 sqlite3TreeViewLine(pView, "CASE");
84024 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
84025 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
 
84026 break;
84027 }
84028 #ifndef SQLITE_OMIT_TRIGGER
84029 case TK_RAISE: {
84030 const char *zType = "unk";
@@ -83961,59 +84032,61 @@
84032 case OE_Rollback: zType = "rollback"; break;
84033 case OE_Abort: zType = "abort"; break;
84034 case OE_Fail: zType = "fail"; break;
84035 case OE_Ignore: zType = "ignore"; break;
84036 }
84037 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
84038 break;
84039 }
84040 #endif
84041 default: {
84042 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
84043 break;
84044 }
84045 }
84046 if( zBinOp ){
84047 sqlite3TreeViewLine(pView, "%s", zBinOp);
84048 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
84049 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
 
 
84050 }else if( zUniOp ){
84051 sqlite3TreeViewLine(pView, "%s", zUniOp);
84052 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
84053 }
84054 sqlite3TreeViewPop(pView);
84055 }
84056 #endif /* SQLITE_DEBUG */
84057
84058 #ifdef SQLITE_DEBUG
84059 /*
84060 ** Generate a human-readable explanation of an expression list.
84061 */
84062 SQLITE_PRIVATE void sqlite3TreeViewExprList(
84063 TreeView *pView,
84064 const ExprList *pList,
84065 u8 moreToFollow,
84066 const char *zLabel
84067 ){
84068 int i;
84069 pView = sqlite3TreeViewPush(pView, moreToFollow);
84070 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
84071 if( pList==0 ){
84072 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
 
84073 }else{
84074 sqlite3TreeViewLine(pView, "%s", zLabel);
84075 for(i=0; i<pList->nExpr; i++){
84076 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
84077 #if 0
84078 if( pList->a[i].zName ){
 
 
84079 sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
84080 }
84081 if( pList->a[i].bSpanIsTab ){
84082 sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
84083 }
84084 #endif
 
 
84085 }
 
84086 }
84087 sqlite3TreeViewPop(pView);
84088 }
84089 #endif /* SQLITE_DEBUG */
84090
84091 /*
84092 ** Generate code that pushes the value of every element of the given
@@ -87130,29 +87203,27 @@
87203 tRowcnt v;
87204
87205 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87206 if( z==0 ) z = "";
87207 #else
87208 assert( z!=0 );
87209 #endif
87210 for(i=0; *z && i<nOut; i++){
87211 v = 0;
87212 while( (c=z[0])>='0' && c<='9' ){
87213 v = v*10 + c - '0';
87214 z++;
87215 }
87216 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87217 if( aOut ) aOut[i] = v;
87218 if( aLog ) aLog[i] = sqlite3LogEst(v);
 
87219 #else
87220 assert( aOut==0 );
87221 UNUSED_PARAMETER(aOut);
87222 assert( aLog!=0 );
87223 aLog[i] = sqlite3LogEst(v);
87224 #endif
 
 
 
87225 if( *z==' ' ) z++;
87226 }
87227 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
87228 assert( pIndex!=0 );
87229 #else
@@ -87209,12 +87280,21 @@
87280 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
87281 }
87282 z = argv[2];
87283
87284 if( pIndex ){
87285 int nCol = pIndex->nKeyCol+1;
87286 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87287 tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
87288 sizeof(tRowcnt) * nCol
87289 );
87290 if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
87291 #else
87292 tRowcnt * const aiRowEst = 0;
87293 #endif
87294 pIndex->bUnordered = 0;
87295 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
87296 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
87297 }else{
87298 Index fakeIdx;
87299 fakeIdx.szIdxRow = pTable->szTabRow;
87300 #ifdef SQLITE_ENABLE_COSTMULT
@@ -87269,29 +87349,42 @@
87349 ** unique. */
87350 nCol = pIdx->nSampleCol-1;
87351 pIdx->aAvgEq[nCol] = 1;
87352 }
87353 for(iCol=0; iCol<nCol; iCol++){
87354 int nSample = pIdx->nSample;
87355 int i; /* Used to iterate through samples */
87356 tRowcnt sumEq = 0; /* Sum of the nEq values */
 
87357 tRowcnt avgEq = 0;
87358 tRowcnt nRow; /* Number of rows in index */
87359 i64 nSum100 = 0; /* Number of terms contributing to sumEq */
87360 i64 nDist100; /* Number of distinct values in index */
87361
87362 if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
87363 nRow = pFinal->anLt[iCol];
87364 nDist100 = (i64)100 * pFinal->anDLt[iCol];
87365 nSample--;
87366 }else{
87367 nRow = pIdx->aiRowEst[0];
87368 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
87369 }
87370
87371 /* Set nSum to the number of distinct (iCol+1) field prefixes that
87372 ** occur in the stat4 table for this index. Set sumEq to the sum of
87373 ** the nEq values for column iCol for the same set (adding the value
87374 ** only once where there exist duplicate prefixes). */
87375 for(i=0; i<nSample; i++){
87376 if( i==(pIdx->nSample-1)
87377 || aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol]
87378 ){
87379 sumEq += aSample[i].anEq[iCol];
87380 nSum100 += 100;
87381 }
87382 }
87383
87384 if( nDist100>nSum100 ){
87385 avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100);
87386 }
87387 if( avgEq==0 ) avgEq = 1;
87388 pIdx->aAvgEq[iCol] = avgEq;
87389 }
87390 }
@@ -87538,10 +87631,15 @@
87631 if( rc==SQLITE_OK ){
87632 int lookasideEnabled = db->lookaside.bEnabled;
87633 db->lookaside.bEnabled = 0;
87634 rc = loadStat4(db, sInfo.zDatabase);
87635 db->lookaside.bEnabled = lookasideEnabled;
87636 }
87637 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
87638 Index *pIdx = sqliteHashData(i);
87639 sqlite3_free(pIdx->aiRowEst);
87640 pIdx->aiRowEst = 0;
87641 }
87642 #endif
87643
87644 if( rc==SQLITE_NOMEM ){
87645 db->mallocFailed = 1;
@@ -88832,10 +88930,13 @@
88930 #endif
88931 if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
88932 sqlite3ExprDelete(db, p->pPartIdxWhere);
88933 sqlite3DbFree(db, p->zColAff);
88934 if( p->isResized ) sqlite3DbFree(db, p->azColl);
88935 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
88936 sqlite3_free(p->aiRowEst);
88937 #endif
88938 sqlite3DbFree(db, p);
88939 }
88940
88941 /*
88942 ** For the index called zIdxName which is found in the database iDb,
@@ -89633,11 +89734,11 @@
89734 Column *pCol;
89735 sqlite3 *db = pParse->db;
89736 p = pParse->pNewTable;
89737 if( p!=0 ){
89738 pCol = &(p->aCol[p->nCol-1]);
89739 if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr, db->init.busy) ){
89740 sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
89741 pCol->zName);
89742 }else{
89743 /* A copy of pExpr is used instead of the original, as pExpr contains
89744 ** tokens that point to volatile memory. The 'span' of the expression
@@ -91141,11 +91242,11 @@
91242 pIndex->nKeyCol); VdbeCoverage(v);
91243 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
91244 }else{
91245 addr2 = sqlite3VdbeCurrentAddr(v);
91246 }
91247 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
91248 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
91249 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
91250 sqlite3ReleaseTempReg(pParse, regRecord);
91251 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
91252 sqlite3VdbeJumpHere(v, addr1);
@@ -94030,11 +94131,14 @@
94131
94132 /*
94133 ** Return the collating function associated with a function.
94134 */
94135 static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
94136 VdbeOp *pOp = &context->pVdbe->aOp[context->iOp-1];
94137 assert( pOp->opcode==OP_CollSeq );
94138 assert( pOp->p4type==P4_COLLSEQ );
94139 return pOp->p4.pColl;
94140 }
94141
94142 /*
94143 ** Indicate that the accumulator load should be skipped on this
94144 ** iteration of the aggregate loop.
@@ -94575,14 +94679,16 @@
94679 ** character is exactly one byte in size. Also, all characters are
94680 ** able to participate in upper-case-to-lower-case mappings in EBCDIC
94681 ** whereas only characters less than 0x80 do in ASCII.
94682 */
94683 #if defined(SQLITE_EBCDIC)
94684 # define sqlite3Utf8Read(A) (*((*A)++))
94685 # define GlobUpperToLower(A) A = sqlite3UpperToLower[A]
94686 # define GlobUpperToLowerAscii(A) A = sqlite3UpperToLower[A]
94687 #else
94688 # define GlobUpperToLower(A) if( A<=0x7f ){ A = sqlite3UpperToLower[A]; }
94689 # define GlobUpperToLowerAscii(A) A = sqlite3UpperToLower[A]
94690 #endif
94691
94692 static const struct compareInfo globInfo = { '*', '?', '[', 0 };
94693 /* The correct SQL-92 behavior is for the LIKE operator to ignore
94694 ** case. Thus 'a' LIKE 'A' would be true. */
@@ -94591,11 +94697,11 @@
94697 ** is case sensitive causing 'a' LIKE 'A' to be false */
94698 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
94699
94700 /*
94701 ** Compare two UTF-8 strings for equality where the first string can
94702 ** potentially be a "glob" or "like" expression. Return true (1) if they
94703 ** are the same and false (0) if they are different.
94704 **
94705 ** Globbing rules:
94706 **
94707 ** '*' Matches any sequence of zero or more characters.
@@ -94611,120 +94717,147 @@
94717 ** in the list by making it the first character after '[' or '^'. A
94718 ** range of characters can be specified using '-'. Example:
94719 ** "[a-z]" matches any single lower-case letter. To match a '-', make
94720 ** it the last character in the list.
94721 **
94722 ** Like matching rules:
94723 **
94724 ** '%' Matches any sequence of zero or more characters
94725 **
94726 *** '_' Matches any one character
94727 **
94728 ** Ec Where E is the "esc" character and c is any other
94729 ** character, including '%', '_', and esc, match exactly c.
94730 **
94731 ** The comments through this routine usually assume glob matching.
94732 **
94733 ** This routine is usually quick, but can be N**2 in the worst case.
 
 
 
 
94734 */
94735 static int patternCompare(
94736 const u8 *zPattern, /* The glob pattern */
94737 const u8 *zString, /* The string to compare against the glob */
94738 const struct compareInfo *pInfo, /* Information about how to do the compare */
94739 u32 esc /* The escape character */
94740 ){
94741 u32 c, c2; /* Next pattern and input string chars */
94742 u32 matchOne = pInfo->matchOne; /* "?" or "_" */
94743 u32 matchAll = pInfo->matchAll; /* "*" or "%" */
94744 u32 matchOther; /* "[" or the escape character */
94745 u8 noCase = pInfo->noCase; /* True if uppercase==lowercase */
94746 const u8 *zEscaped = 0; /* One past the last escaped input char */
94747
94748 /* The GLOB operator does not have an ESCAPE clause. And LIKE does not
94749 ** have the matchSet operator. So we either have to look for one or
94750 ** the other, never both. Hence the single variable matchOther is used
94751 ** to store the one we have to look for.
94752 */
94753 matchOther = esc ? esc : pInfo->matchSet;
94754
94755 while( (c = sqlite3Utf8Read(&zPattern))!=0 ){
94756 if( c==matchAll ){ /* Match "*" */
94757 /* Skip over multiple "*" characters in the pattern. If there
94758 ** are also "?" characters, skip those as well, but consume a
94759 ** single character of the input string for each "?" skipped */
94760 while( (c=sqlite3Utf8Read(&zPattern)) == matchAll
94761 || c == matchOne ){
94762 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
94763 return 0;
94764 }
94765 }
94766 if( c==0 ){
94767 return 1; /* "*" at the end of the pattern matches */
94768 }else if( c==matchOther ){
94769 if( esc ){
94770 c = sqlite3Utf8Read(&zPattern);
94771 if( c==0 ) return 0;
94772 }else{
94773 /* "[...]" immediately follows the "*". We have to do a slow
94774 ** recursive search in this case, but it is an unusual case. */
94775 assert( matchOther<0x80 ); /* '[' is a single-byte character */
94776 while( *zString
94777 && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
94778 SQLITE_SKIP_UTF8(zString);
94779 }
94780 return *zString!=0;
94781 }
94782 }
94783
94784 /* At this point variable c contains the first character of the
94785 ** pattern string past the "*". Search in the input string for the
94786 ** first matching character and recursively contine the match from
94787 ** that point.
94788 **
94789 ** For a case-insensitive search, set variable cx to be the same as
94790 ** c but in the other case and search the input string for either
94791 ** c or cx.
94792 */
94793 if( c<=0x80 ){
94794 u32 cx;
94795 if( noCase ){
94796 cx = sqlite3Toupper(c);
94797 c = sqlite3Tolower(c);
94798 }else{
94799 cx = c;
94800 }
94801 while( (c2 = *(zString++))!=0 ){
94802 if( c2!=c && c2!=cx ) continue;
94803 if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
94804 }
94805 }else{
94806 while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
94807 if( c2!=c ) continue;
94808 if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
94809 }
94810 }
94811 return 0;
94812 }
94813 if( c==matchOther ){
94814 if( esc ){
94815 c = sqlite3Utf8Read(&zPattern);
94816 if( c==0 ) return 0;
94817 zEscaped = zPattern;
94818 }else{
94819 u32 prior_c = 0;
94820 int seen = 0;
94821 int invert = 0;
94822 c = sqlite3Utf8Read(&zString);
94823 if( c==0 ) return 0;
94824 c2 = sqlite3Utf8Read(&zPattern);
94825 if( c2=='^' ){
94826 invert = 1;
94827 c2 = sqlite3Utf8Read(&zPattern);
94828 }
94829 if( c2==']' ){
94830 if( c==']' ) seen = 1;
94831 c2 = sqlite3Utf8Read(&zPattern);
94832 }
94833 while( c2 && c2!=']' ){
94834 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
94835 c2 = sqlite3Utf8Read(&zPattern);
94836 if( c>=prior_c && c<=c2 ) seen = 1;
94837 prior_c = 0;
94838 }else{
94839 if( c==c2 ){
94840 seen = 1;
94841 }
94842 prior_c = c2;
94843 }
94844 c2 = sqlite3Utf8Read(&zPattern);
94845 }
94846 if( c2==0 || (seen ^ invert)==0 ){
94847 return 0;
94848 }
94849 continue;
94850 }
94851 }
94852 c2 = sqlite3Utf8Read(&zString);
94853 if( c==c2 ) continue;
94854 if( noCase && c<0x80 && c2<0x80 && sqlite3Tolower(c)==sqlite3Tolower(c2) ){
94855 continue;
94856 }
94857 if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
94858 return 0;
94859 }
94860 return *zString==0;
94861 }
94862
94863 /*
@@ -103884,10 +104017,24 @@
104017 **
104018 *************************************************************************
104019 ** This file contains C code routines that are called by the parser
104020 ** to handle SELECT statements in SQLite.
104021 */
104022
104023 /*
104024 ** Trace output macros
104025 */
104026 #if SELECTTRACE_ENABLED
104027 /***/ int sqlite3SelectTrace = 0;
104028 # define SELECTTRACE(K,P,S,X) \
104029 if(sqlite3SelectTrace&(K)) \
104030 sqlite3DebugPrintf("%*s%s.%p: ",(P)->nSelectIndent*2-2,"",(S)->zSelName,(S)),\
104031 sqlite3DebugPrintf X
104032 #else
104033 # define SELECTTRACE(K,P,S,X)
104034 #endif
104035
104036
104037 /*
104038 ** An instance of the following object is used to record information about
104039 ** how to process the DISTINCT keyword, to simplify passing that information
104040 ** into the selectInnerLoop() routine.
@@ -103996,10 +104143,22 @@
104143 assert( pNew->pSrc!=0 || pParse->nErr>0 );
104144 }
104145 assert( pNew!=&standin );
104146 return pNew;
104147 }
104148
104149 #if SELECTTRACE_ENABLED
104150 /*
104151 ** Set the name of a Select object
104152 */
104153 SQLITE_PRIVATE void sqlite3SelectSetName(Select *p, const char *zName){
104154 if( p && zName ){
104155 sqlite3_snprintf(sizeof(p->zSelName), p->zSelName, "%s", zName);
104156 }
104157 }
104158 #endif
104159
104160
104161 /*
104162 ** Delete the given Select structure and all of its substructures.
104163 */
104164 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
@@ -105026,11 +105185,10 @@
105185 int regRow;
105186 int regRowid;
105187 int nKey;
105188 int iSortTab; /* Sorter cursor to read from */
105189 int nSortData; /* Trailing values to read from sorter */
 
105190 int i;
105191 int bSeq; /* True if sorter record includes seq. no. */
105192 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
105193 struct ExprList_item *aOutEx = p->pEList->a;
105194 #endif
@@ -105060,23 +105218,20 @@
105218 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
105219 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
105220 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
105221 VdbeCoverage(v);
105222 codeOffset(v, p->iOffset, addrContinue);
105223 sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
 
105224 bSeq = 0;
105225 }else{
105226 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
105227 codeOffset(v, p->iOffset, addrContinue);
105228 iSortTab = iTab;
 
105229 bSeq = 1;
105230 }
105231 for(i=0; i<nSortData; i++){
105232 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
 
105233 VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
105234 }
105235 switch( eDest ){
105236 case SRT_Table:
105237 case SRT_EphemTab: {
@@ -107226,10 +107381,12 @@
107381 }
107382 }
107383 }
107384
107385 /***** If we reach this point, flattening is permitted. *****/
107386 SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
107387 pSub->zSelName, pSub, iFrom));
107388
107389 /* Authorize the subquery */
107390 pParse->zAuthContext = pSubitem->zName;
107391 TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
107392 testcase( i==SQLITE_DENY );
@@ -107278,10 +107435,11 @@
107435 p->pSrc = 0;
107436 p->pPrior = 0;
107437 p->pLimit = 0;
107438 p->pOffset = 0;
107439 pNew = sqlite3SelectDup(db, p, 0);
107440 sqlite3SelectSetName(pNew, pSub->zSelName);
107441 p->pOffset = pOffset;
107442 p->pLimit = pLimit;
107443 p->pOrderBy = pOrderBy;
107444 p->pSrc = pSrc;
107445 p->op = TK_ALL;
@@ -107290,10 +107448,13 @@
107448 }else{
107449 pNew->pPrior = pPrior;
107450 if( pPrior ) pPrior->pNext = pNew;
107451 pNew->pNext = p;
107452 p->pPrior = pNew;
107453 SELECTTRACE(2,pParse,p,
107454 ("compound-subquery flattener creates %s.%p as peer\n",
107455 pNew->zSelName, pNew));
107456 }
107457 if( db->mallocFailed ) return 1;
107458 }
107459
107460 /* Begin flattening the iFrom-th entry of the FROM clause
@@ -107419,12 +107580,27 @@
107580 if( isAgg ){
107581 substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
107582 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
107583 }
107584 if( pSub->pOrderBy ){
107585 /* At this point, any non-zero iOrderByCol values indicate that the
107586 ** ORDER BY column expression is identical to the iOrderByCol'th
107587 ** expression returned by SELECT statement pSub. Since these values
107588 ** do not necessarily correspond to columns in SELECT statement pParent,
107589 ** zero them before transfering the ORDER BY clause.
107590 **
107591 ** Not doing this may cause an error if a subsequent call to this
107592 ** function attempts to flatten a compound sub-query into pParent
107593 ** (the only way this can happen is if the compound sub-query is
107594 ** currently part of pSub->pSrc). See ticket [d11a6e908f]. */
107595 ExprList *pOrderBy = pSub->pOrderBy;
107596 for(i=0; i<pOrderBy->nExpr; i++){
107597 pOrderBy->a[i].u.x.iOrderByCol = 0;
107598 }
107599 assert( pParent->pOrderBy==0 );
107600 assert( pSub->pPrior==0 );
107601 pParent->pOrderBy = pOrderBy;
107602 pSub->pOrderBy = 0;
107603 }else if( pParent->pOrderBy ){
107604 substExprList(db, pParent->pOrderBy, iParent, pSub->pEList);
107605 }
107606 if( pSub->pWhere ){
@@ -107465,10 +107641,17 @@
107641
107642 /* Finially, delete what is left of the subquery and return
107643 ** success.
107644 */
107645 sqlite3SelectDelete(db, pSub1);
107646
107647 #if SELECTTRACE_ENABLED
107648 if( sqlite3SelectTrace & 0x100 ){
107649 sqlite3DebugPrintf("After flattening:\n");
107650 sqlite3TreeViewSelect(0, p, 0);
107651 }
107652 #endif
107653
107654 return 1;
107655 }
107656 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
107657
@@ -107936,10 +108119,11 @@
108119 if( pTab->pSelect || IsVirtual(pTab) ){
108120 /* We reach here if the named table is a really a view */
108121 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
108122 assert( pFrom->pSelect==0 );
108123 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
108124 sqlite3SelectSetName(pFrom->pSelect, pTab->zName);
108125 sqlite3WalkSelect(pWalker, pFrom->pSelect);
108126 }
108127 #endif
108128 }
108129
@@ -108470,10 +108654,17 @@
108654 if( p==0 || db->mallocFailed || pParse->nErr ){
108655 return 1;
108656 }
108657 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
108658 memset(&sAggInfo, 0, sizeof(sAggInfo));
108659 #if SELECTTRACE_ENABLED
108660 pParse->nSelectIndent++;
108661 SELECTTRACE(1,pParse,p, ("begin processing:\n"));
108662 if( sqlite3SelectTrace & 0x100 ){
108663 sqlite3TreeViewSelect(0, p, 0);
108664 }
108665 #endif
108666
108667 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
108668 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
108669 assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
108670 assert( p->pOrderBy==0 || pDest->eDest!=SRT_Queue );
@@ -108626,10 +108817,14 @@
108817 /* If there is are a sequence of queries, do the earlier ones first.
108818 */
108819 if( p->pPrior ){
108820 rc = multiSelect(pParse, p, pDest);
108821 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
108822 #if SELECTTRACE_ENABLED
108823 SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
108824 pParse->nSelectIndent--;
108825 #endif
108826 return rc;
108827 }
108828 #endif
108829
108830 /* If the query is DISTINCT with an ORDER BY but is not an aggregate, and
@@ -108961,16 +109156,15 @@
109156 ** from the previous row currently stored in a0, a1, a2...
109157 */
109158 addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
109159 sqlite3ExprCacheClear(pParse);
109160 if( groupBySort ){
109161 sqlite3VdbeAddOp3(v, OP_SorterData, sAggInfo.sortingIdx, sortOut,sortPTab);
109162 }
109163 for(j=0; j<pGroupBy->nExpr; j++){
109164 if( groupBySort ){
109165 sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
 
109166 }else{
109167 sAggInfo.directMode = 1;
109168 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
109169 }
109170 }
@@ -109225,107 +109419,110 @@
109419 generateColumnNames(pParse, pTabList, pEList);
109420 }
109421
109422 sqlite3DbFree(db, sAggInfo.aCol);
109423 sqlite3DbFree(db, sAggInfo.aFunc);
109424 #if SELECTTRACE_ENABLED
109425 SELECTTRACE(1,pParse,p,("end processing\n"));
109426 pParse->nSelectIndent--;
109427 #endif
109428 return rc;
109429 }
109430
109431 #ifdef SQLITE_DEBUG
109432 /*
109433 ** Generate a human-readable description of a the Select object.
109434 */
109435 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
109436 int n = 0;
109437 pView = sqlite3TreeViewPush(pView, moreToFollow);
109438 sqlite3TreeViewLine(pView, "SELECT%s%s",
109439 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
109440 ((p->selFlags & SF_Aggregate) ? " agg_flag" : "")
109441 );
109442 if( p->pSrc && p->pSrc->nSrc ) n++;
109443 if( p->pWhere ) n++;
109444 if( p->pGroupBy ) n++;
109445 if( p->pHaving ) n++;
109446 if( p->pOrderBy ) n++;
109447 if( p->pLimit ) n++;
109448 if( p->pOffset ) n++;
109449 if( p->pPrior ) n++;
109450 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
109451 if( p->pSrc && p->pSrc->nSrc ){
109452 int i;
109453 pView = sqlite3TreeViewPush(pView, (n--)>0);
109454 sqlite3TreeViewLine(pView, "FROM");
109455 for(i=0; i<p->pSrc->nSrc; i++){
109456 struct SrcList_item *pItem = &p->pSrc->a[i];
109457 StrAccum x;
109458 char zLine[100];
109459 sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0);
109460 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
109461 if( pItem->zDatabase ){
109462 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
109463 }else if( pItem->zName ){
109464 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
109465 }
109466 if( pItem->pTab ){
109467 sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
109468 }
109469 if( pItem->zAlias ){
109470 sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
109471 }
109472 if( pItem->jointype & JT_LEFT ){
109473 sqlite3XPrintf(&x, 0, " LEFT-JOIN");
109474 }
109475 sqlite3StrAccumFinish(&x);
109476 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
109477 if( pItem->pSelect ){
109478 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
109479 }
109480 sqlite3TreeViewPop(pView);
109481 }
109482 sqlite3TreeViewPop(pView);
109483 }
109484 if( p->pWhere ){
109485 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
109486 sqlite3TreeViewExpr(pView, p->pWhere, 0);
109487 sqlite3TreeViewPop(pView);
109488 }
109489 if( p->pGroupBy ){
109490 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
 
 
109491 }
109492 if( p->pHaving ){
109493 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
109494 sqlite3TreeViewExpr(pView, p->pHaving, 0);
109495 sqlite3TreeViewPop(pView);
109496 }
109497 if( p->pOrderBy ){
109498 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
 
 
109499 }
109500 if( p->pLimit ){
109501 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
109502 sqlite3TreeViewExpr(pView, p->pLimit, 0);
109503 sqlite3TreeViewPop(pView);
109504 }
109505 if( p->pOffset ){
109506 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
109507 sqlite3TreeViewExpr(pView, p->pOffset, 0);
109508 sqlite3TreeViewPop(pView);
109509 }
109510 if( p->pPrior ){
109511 const char *zOp = "UNION";
109512 switch( p->op ){
109513 case TK_ALL: zOp = "UNION ALL"; break;
109514 case TK_INTERSECT: zOp = "INTERSECT"; break;
109515 case TK_EXCEPT: zOp = "EXCEPT"; break;
109516 }
109517 sqlite3TreeViewItem(pView, zOp, (n--)>0);
109518 sqlite3TreeViewSelect(pView, p->pPrior, 0);
109519 sqlite3TreeViewPop(pView);
109520 }
109521 sqlite3TreeViewPop(pView);
109522 }
109523 #endif /* SQLITE_DEBUG */
 
 
 
 
 
 
 
109524
109525 /************** End of select.c **********************************************/
109526 /************** Begin file table.c *******************************************/
109527 /*
109528 ** 2001 September 15
@@ -112311,10 +112508,11 @@
112508 }
112509 sqlite3DbFree(db, pVTable);
112510 }else if( ALWAYS(pVTable->pVtab) ){
112511 /* Justification of ALWAYS(): A correct vtab constructor must allocate
112512 ** the sqlite3_vtab object if successful. */
112513 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
112514 pVTable->pVtab->pModule = pMod->pModule;
112515 pVTable->nRef = 1;
112516 if( sCtx.pTab ){
112517 const char *zFormat = "vtable constructor did not declare schema: %s";
112518 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
@@ -113719,15 +113917,10 @@
113917 assert( TK_LE>TK_EQ && TK_LE<TK_GE );
113918 assert( TK_GE==TK_EQ+4 );
113919 return op==TK_IN || (op>=TK_EQ && op<=TK_GE) || op==TK_ISNULL;
113920 }
113921
 
 
 
 
 
113922 /*
113923 ** Commute a comparison operator. Expressions of the form "X op Y"
113924 ** are converted into "Y op X".
113925 **
113926 ** If left/right precedence rules come into play when determining the
@@ -115566,21 +115759,28 @@
115759 ** have been requested when testing key $P in whereEqualScanEst(). */
115760 whereKeyStats(pParse, p, pRec, 0, a);
115761 iLower = a[0];
115762 iUpper = a[0] + a[1];
115763 }
115764
115765 assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );
115766 assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
115767 assert( p->aSortOrder!=0 );
115768 if( p->aSortOrder[nEq] ){
115769 /* The roles of pLower and pUpper are swapped for a DESC index */
115770 SWAP(WhereTerm*, pLower, pUpper);
115771 }
115772
115773 /* If possible, improve on the iLower estimate using ($P:$L). */
115774 if( pLower ){
115775 int bOk; /* True if value is extracted from pExpr */
115776 Expr *pExpr = pLower->pExpr->pRight;
 
115777 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115778 if( rc==SQLITE_OK && bOk ){
115779 tRowcnt iNew;
115780 whereKeyStats(pParse, p, pRec, 0, a);
115781 iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115782 if( iNew>iLower ) iLower = iNew;
115783 nOut--;
115784 pLower = 0;
115785 }
115786 }
@@ -115587,16 +115787,15 @@
115787
115788 /* If possible, improve on the iUpper estimate using ($P:$U). */
115789 if( pUpper ){
115790 int bOk; /* True if value is extracted from pExpr */
115791 Expr *pExpr = pUpper->pExpr->pRight;
 
115792 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115793 if( rc==SQLITE_OK && bOk ){
115794 tRowcnt iNew;
115795 whereKeyStats(pParse, p, pRec, 1, a);
115796 iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115797 if( iNew<iUpper ) iUpper = iNew;
115798 nOut--;
115799 pUpper = 0;
115800 }
115801 }
@@ -116091,65 +116290,52 @@
116290 sqlite3StrAccumAppend(pStr, "?", 1);
116291 }
116292
116293 /*
116294 ** Argument pLevel describes a strategy for scanning table pTab. This
116295 ** function appends text to pStr that describes the subset of table
116296 ** rows scanned by the strategy in the form of an SQL expression.
 
116297 **
116298 ** For example, if the query:
116299 **
116300 ** SELECT * FROM t1 WHERE a=1 AND b>2;
116301 **
116302 ** is run and there is an index on (a, b), then this function returns a
116303 ** string similar to:
116304 **
116305 ** "a=? AND b>?"
 
 
 
 
116306 */
116307 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
116308 Index *pIndex = pLoop->u.btree.pIndex;
116309 u16 nEq = pLoop->u.btree.nEq;
116310 u16 nSkip = pLoop->u.btree.nSkip;
116311 int i, j;
116312 Column *aCol = pTab->aCol;
116313 i16 *aiColumn = pIndex->aiColumn;
116314
116315 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
116316 sqlite3StrAccumAppend(pStr, " (", 2);
 
 
 
 
 
116317 for(i=0; i<nEq; i++){
116318 char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
116319 if( i>=nSkip ){
116320 explainAppendTerm(pStr, i, z, "=");
116321 }else{
116322 if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
116323 sqlite3XPrintf(pStr, 0, "ANY(%s)", z);
 
 
116324 }
116325 }
116326
116327 j = i;
116328 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
116329 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116330 explainAppendTerm(pStr, i++, z, ">");
116331 }
116332 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
116333 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116334 explainAppendTerm(pStr, i, z, "<");
116335 }
116336 sqlite3StrAccumAppend(pStr, ")", 1);
 
116337 }
116338
116339 /*
116340 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116341 ** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
@@ -116169,72 +116355,90 @@
116355 #endif
116356 {
116357 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116358 Vdbe *v = pParse->pVdbe; /* VM being constructed */
116359 sqlite3 *db = pParse->db; /* Database handle */
 
116360 int iId = pParse->iSelectId; /* Select id (left-most output column) */
116361 int isSearch; /* True for a SEARCH. False for SCAN. */
116362 WhereLoop *pLoop; /* The controlling WhereLoop object */
116363 u32 flags; /* Flags that describe this loop */
116364 char *zMsg; /* Text to add to EQP output */
116365 StrAccum str; /* EQP output string */
116366 char zBuf[100]; /* Initial space for EQP output string */
116367
116368 pLoop = pLevel->pWLoop;
116369 flags = pLoop->wsFlags;
116370 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
116371
116372 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116373 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116374 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116375
116376 sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
116377 str.db = db;
116378 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
116379 if( pItem->pSelect ){
116380 sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
116381 }else{
116382 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
116383 }
116384
116385 if( pItem->zAlias ){
116386 sqlite3XPrintf(&str, 0, " AS %s", pItem->zAlias);
116387 }
116388 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
116389 const char *zFmt = 0;
116390 Index *pIdx;
116391
116392 assert( pLoop->u.btree.pIndex!=0 );
116393 pIdx = pLoop->u.btree.pIndex;
116394 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116395 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116396 if( isSearch ){
116397 zFmt = "PRIMARY KEY";
116398 }
116399 }else if( flags & WHERE_AUTO_INDEX ){
116400 zFmt = "AUTOMATIC COVERING INDEX";
116401 }else if( flags & WHERE_IDX_ONLY ){
116402 zFmt = "COVERING INDEX %s";
116403 }else{
116404 zFmt = "INDEX %s";
116405 }
116406 if( zFmt ){
116407 sqlite3StrAccumAppend(&str, " USING ", 7);
116408 sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
116409 explainIndexRange(&str, pLoop, pItem->pTab);
116410 }
116411 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
116412 const char *zRange;
 
116413 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
116414 zRange = "(rowid=?)";
116415 }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
116416 zRange = "(rowid>? AND rowid<?)";
116417 }else if( flags&WHERE_BTM_LIMIT ){
116418 zRange = "(rowid>?)";
116419 }else{
116420 assert( flags&WHERE_TOP_LIMIT);
116421 zRange = "(rowid<?)";
116422 }
116423 sqlite3StrAccumAppendAll(&str, " USING INTEGER PRIMARY KEY ");
116424 sqlite3StrAccumAppendAll(&str, zRange);
116425 }
116426 #ifndef SQLITE_OMIT_VIRTUALTABLE
116427 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
116428 sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
116429 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
116430 }
116431 #endif
116432 #ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
116433 if( pLoop->nOut>=10 ){
116434 sqlite3XPrintf(&str, 0, " (~%llu rows)", sqlite3LogEstToInt(pLoop->nOut));
116435 }else{
116436 sqlite3StrAccumAppend(&str, " (~1 row)", 9);
116437 }
116438 #endif
116439 zMsg = sqlite3StrAccumFinish(&str);
116440 sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116441 }
116442 }
116443 #else
116444 # define explainOneScan(u,v,w,x,y,z)
@@ -116884,12 +117088,13 @@
117088
117089 /* Run a separate WHERE clause for each term of the OR clause. After
117090 ** eliminating duplicates from other WHERE clauses, the action for each
117091 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
117092 */
117093 wctrlFlags = WHERE_OMIT_OPEN_CLOSE
117094 | WHERE_FORCE_TABLE
117095 | WHERE_ONETABLE_ONLY;
117096 for(ii=0; ii<pOrWc->nTerm; ii++){
117097 WhereTerm *pOrTerm = &pOrWc->a[ii];
117098 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
117099 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
117100 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -116897,10 +117102,11 @@
117102 if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
117103 pAndExpr->pLeft = pOrExpr;
117104 pOrExpr = pAndExpr;
117105 }
117106 /* Loop through table entries that match term pOrTerm. */
117107 WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
117108 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
117109 wctrlFlags, iCovCur);
117110 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
117111 if( pSubWInfo ){
117112 WhereLoop *pSubLoop;
@@ -117116,25 +117322,30 @@
117322 }
117323
117324 return pLevel->notReady;
117325 }
117326
117327 #ifdef WHERETRACE_ENABLED
117328 /*
117329 ** Print the content of a WhereTerm object
117330 */
117331 static void whereTermPrint(WhereTerm *pTerm, int iTerm){
117332 if( pTerm==0 ){
117333 sqlite3DebugPrintf("TERM-%-3d NULL\n", iTerm);
117334 }else{
117335 char zType[4];
117336 memcpy(zType, "...", 4);
117337 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
117338 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
117339 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
117340 sqlite3DebugPrintf("TERM-%-3d %p %s cursor=%-3d prob=%-3d op=0x%03x\n",
117341 iTerm, pTerm, zType, pTerm->leftCursor, pTerm->truthProb,
117342 pTerm->eOperator);
117343 sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
117344 }
117345 }
117346 #endif
117347
117348 #ifdef WHERETRACE_ENABLED
117349 /*
117350 ** Print a WhereLoop object for debugging purposes
117351 */
@@ -117174,31 +117385,16 @@
117385 sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip);
117386 }else{
117387 sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
117388 }
117389 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
117390 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
 
 
 
 
117391 int i;
 
 
117392 for(i=0; i<p->nLTerm; i++){
117393 whereTermPrint(p->aLTerm[i], i);
117394 }
117395 }
 
 
 
 
 
 
 
 
 
117396 }
117397 #endif
117398
117399 /*
117400 ** Convert bulk memory into a valid WhereLoop that can be passed
@@ -117507,11 +117703,11 @@
117703 if( ppPrev==0 ){
117704 /* There already exists a WhereLoop on the list that is better
117705 ** than pTemplate, so just ignore pTemplate */
117706 #if WHERETRACE_ENABLED /* 0x8 */
117707 if( sqlite3WhereTrace & 0x8 ){
117708 sqlite3DebugPrintf(" skip: ");
117709 whereLoopPrint(pTemplate, pBuilder->pWC);
117710 }
117711 #endif
117712 return SQLITE_OK;
117713 }else{
@@ -117523,14 +117719,14 @@
117719 ** WhereLoop and insert it.
117720 */
117721 #if WHERETRACE_ENABLED /* 0x8 */
117722 if( sqlite3WhereTrace & 0x8 ){
117723 if( p!=0 ){
117724 sqlite3DebugPrintf("replace: ");
117725 whereLoopPrint(p, pBuilder->pWC);
117726 }
117727 sqlite3DebugPrintf(" add: ");
117728 whereLoopPrint(pTemplate, pBuilder->pWC);
117729 }
117730 #endif
117731 if( p==0 ){
117732 /* Allocate a new WhereLoop to add to the end of the list */
@@ -117550,11 +117746,11 @@
117746 pToDel = *ppTail;
117747 if( pToDel==0 ) break;
117748 *ppTail = pToDel->pNextLoop;
117749 #if WHERETRACE_ENABLED /* 0x8 */
117750 if( sqlite3WhereTrace & 0x8 ){
117751 sqlite3DebugPrintf(" delete: ");
117752 whereLoopPrint(pToDel, pBuilder->pWC);
117753 }
117754 #endif
117755 whereLoopDelete(db, pToDel);
117756 }
@@ -117714,15 +117910,18 @@
117910 pNew->aLTerm[pNew->nLTerm++] = 0;
117911 pNew->wsFlags |= WHERE_SKIPSCAN;
117912 nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
117913 if( pTerm ){
117914 /* TUNING: When estimating skip-scan for a term that is also indexable,
117915 ** multiply the cost of the skip-scan by 2.0, to make it a little less
117916 ** desirable than the regular index lookup. */
117917 nIter += 10; assert( 10==sqlite3LogEst(2) );
117918 }
117919 pNew->nOut -= nIter;
117920 /* TUNING: Because uncertainties in the estimates for skip-scan queries,
117921 ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
117922 nIter += 5;
117923 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
117924 pNew->nOut = saved_nOut;
117925 pNew->u.btree.nEq = saved_nEq;
117926 pNew->u.btree.nSkip = saved_nSkip;
117927 }
@@ -118073,13 +118272,21 @@
118272 pNew->u.btree.nSkip = 0;
118273 pNew->u.btree.pIndex = 0;
118274 pNew->nLTerm = 1;
118275 pNew->aLTerm[0] = pTerm;
118276 /* TUNING: One-time cost for computing the automatic index is
118277 ** estimated to be X*N*log2(N) where N is the number of rows in
118278 ** the table being indexed and where X is 7 (LogEst=28) for normal
118279 ** tables or 1.375 (LogEst=4) for views and subqueries. The value
118280 ** of X is smaller for views and subqueries so that the query planner
118281 ** will be more aggressive about generating automatic indexes for
118282 ** those objects, since there is no opportunity to add schema
118283 ** indexes on subqueries and views. */
118284 pNew->rSetup = rLogSize + rSize + 4;
118285 if( pTab->pSelect==0 && (pTab->tabFlags & TF_Ephemeral)==0 ){
118286 pNew->rSetup += 24;
118287 }
118288 ApplyCostMultiplier(pNew->rSetup, pTab->costMult);
118289 /* TUNING: Each index lookup yields 20 rows in the table. This
118290 ** is more than the usual guess of 10 rows, since we have no way
118291 ** of knowing how selective the index will ultimately be. It would
118292 ** not be unreasonable to make this value much larger. */
@@ -118363,11 +118570,10 @@
118570 WhereLoopBuilder sSubBuild;
118571 WhereOrSet sSum, sCur;
118572 struct SrcList_item *pItem;
118573
118574 pWC = pBuilder->pWC;
 
118575 pWCEnd = pWC->a + pWC->nTerm;
118576 pNew = pBuilder->pNew;
118577 memset(&sSum, 0, sizeof(sSum));
118578 pItem = pWInfo->pTabList->a + pNew->iTab;
118579 iCur = pItem->iCursor;
@@ -118384,10 +118590,11 @@
118590
118591 sSubBuild = *pBuilder;
118592 sSubBuild.pOrderBy = 0;
118593 sSubBuild.pOrSet = &sCur;
118594
118595 WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
118596 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
118597 if( (pOrTerm->eOperator & WO_AND)!=0 ){
118598 sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
118599 }else if( pOrTerm->leftCursor==iCur ){
118600 tempWC.pWInfo = pWC->pWInfo;
@@ -118398,18 +118605,30 @@
118605 sSubBuild.pWC = &tempWC;
118606 }else{
118607 continue;
118608 }
118609 sCur.n = 0;
118610 #ifdef WHERETRACE_ENABLED
118611 WHERETRACE(0x200, ("OR-term %d of %p has %d subterms:\n",
118612 (int)(pOrTerm-pOrWC->a), pTerm, sSubBuild.pWC->nTerm));
118613 if( sqlite3WhereTrace & 0x400 ){
118614 for(i=0; i<sSubBuild.pWC->nTerm; i++){
118615 whereTermPrint(&sSubBuild.pWC->a[i], i);
118616 }
118617 }
118618 #endif
118619 #ifndef SQLITE_OMIT_VIRTUALTABLE
118620 if( IsVirtual(pItem->pTab) ){
118621 rc = whereLoopAddVirtual(&sSubBuild, mExtra);
118622 }else
118623 #endif
118624 {
118625 rc = whereLoopAddBtree(&sSubBuild, mExtra);
118626 }
118627 if( rc==SQLITE_OK ){
118628 rc = whereLoopAddOr(&sSubBuild, mExtra);
118629 }
118630 assert( rc==SQLITE_OK || sCur.n==0 );
118631 if( sCur.n==0 ){
118632 sSum.n = 0;
118633 break;
118634 }else if( once ){
@@ -118450,10 +118669,11 @@
118669 pNew->rRun = sSum.a[i].rRun + 1;
118670 pNew->nOut = sSum.a[i].nOut;
118671 pNew->prereq = sSum.a[i].prereq;
118672 rc = whereLoopInsert(pBuilder, pNew);
118673 }
118674 WHERETRACE(0x200, ("End processing OR-clause %p\n", pTerm));
118675 }
118676 }
118677 return rc;
118678 }
118679
@@ -118693,11 +118913,11 @@
118913 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
118914 }
118915 isMatch = 1;
118916 break;
118917 }
118918 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
118919 /* Make sure the sort order is compatible in an ORDER BY clause.
118920 ** Sort order is irrelevant for a GROUP BY clause. */
118921 if( revSet ){
118922 if( (rev ^ revIdx)!=pOrderBy->a[i].sortOrder ) isMatch = 0;
118923 }else{
@@ -119158,16 +119378,19 @@
119378 pWInfo->revMask = pFrom->revLoop;
119379 }
119380 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
119381 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
119382 ){
119383 Bitmask revMask = 0;
119384 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
119385 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
119386 );
119387 assert( pWInfo->sorted==0 );
119388 if( nOrder==pWInfo->pOrderBy->nExpr ){
119389 pWInfo->sorted = 1;
119390 pWInfo->revMask = revMask;
119391 }
119392 }
119393 }
119394
119395
119396 pWInfo->nRowOut = pFrom->nRow;
@@ -119516,27 +119739,20 @@
119739 }
119740 }
119741
119742 /* Construct the WhereLoop objects */
119743 WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
119744 #if defined(WHERETRACE_ENABLED)
119745 /* Display all terms of the WHERE clause */
 
119746 if( sqlite3WhereTrace & 0x100 ){
119747 int i;
 
 
119748 for(i=0; i<sWLB.pWC->nTerm; i++){
119749 whereTermPrint(&sWLB.pWC->a[i], i);
119750 }
 
 
 
 
 
 
119751 }
119752 #endif
119753
119754 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
119755 rc = whereLoopAddAll(&sWLB);
119756 if( rc ) goto whereBeginError;
119757
119758 /* Display all of the WhereLoop objects if wheretrace is enabled */
@@ -120059,11 +120275,11 @@
120275
120276 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
120277 ** unary TK_ISNULL or TK_NOTNULL expression. */
120278 static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
120279 sqlite3 *db = pParse->db;
120280 if( pY && pA && pY->op==TK_NULL ){
120281 pA->op = (u8)op;
120282 sqlite3ExprDelete(db, pA->pRight);
120283 pA->pRight = 0;
120284 }
120285 }
@@ -122318,13 +122534,10 @@
122534 break;
122535 case 111: /* cmd ::= select */
122536 {
122537 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
122538 sqlite3Select(pParse, yymsp[0].minor.yy3, &dest);
 
 
 
122539 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
122540 }
122541 break;
122542 case 112: /* select ::= with selectnowith */
122543 {
@@ -122377,10 +122590,34 @@
122590 {yygotominor.yy328 = TK_ALL;}
122591 break;
122592 case 118: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
122593 {
122594 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy14,yymsp[-5].minor.yy65,yymsp[-4].minor.yy132,yymsp[-3].minor.yy14,yymsp[-2].minor.yy132,yymsp[-1].minor.yy14,yymsp[-7].minor.yy381,yymsp[0].minor.yy476.pLimit,yymsp[0].minor.yy476.pOffset);
122595 #if SELECTTRACE_ENABLED
122596 /* Populate the Select.zSelName[] string that is used to help with
122597 ** query planner debugging, to differentiate between multiple Select
122598 ** objects in a complex query.
122599 **
122600 ** If the SELECT keyword is immediately followed by a C-style comment
122601 ** then extract the first few alphanumeric characters from within that
122602 ** comment to be the zSelName value. Otherwise, the label is #N where
122603 ** is an integer that is incremented with each SELECT statement seen.
122604 */
122605 if( yygotominor.yy3!=0 ){
122606 const char *z = yymsp[-8].minor.yy0.z+6;
122607 int i;
122608 sqlite3_snprintf(sizeof(yygotominor.yy3->zSelName), yygotominor.yy3->zSelName, "#%d",
122609 ++pParse->nSelect);
122610 while( z[0]==' ' ) z++;
122611 if( z[0]=='/' && z[1]=='*' ){
122612 z += 2;
122613 while( z[0]==' ' ) z++;
122614 for(i=0; sqlite3Isalnum(z[i]); i++){}
122615 sqlite3_snprintf(sizeof(yygotominor.yy3->zSelName), yygotominor.yy3->zSelName, "%.*s", i, z);
122616 }
122617 }
122618 #endif /* SELECTRACE_ENABLED */
122619 }
122620 break;
122621 case 120: /* values ::= VALUES LP nexprlist RP */
122622 {
122623 yygotominor.yy3 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy14,0,0,0,0,0,SF_Values,0,0);
@@ -123868,10 +124105,11 @@
124105 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */
124106 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */
124107 };
124108 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
124109 #endif
124110 SQLITE_PRIVATE int sqlite3IsIdChar(u8 c){ return IdChar(c); }
124111
124112
124113 /*
124114 ** Return the length of the token that begins at z[0].
124115 ** Store the token type in *tokenType before returning.
@@ -125138,10 +125376,15 @@
125376 sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
125377 sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
125378 break;
125379 }
125380
125381 /* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
125382 ** can be changed at start-time using the
125383 ** sqlite3_config(SQLITE_CONFIG_URI,1) or
125384 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
125385 */
125386 case SQLITE_CONFIG_URI: {
125387 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
125388 break;
125389 }
125390
@@ -126875,11 +127118,11 @@
127118 int nUri = sqlite3Strlen30(zUri);
127119
127120 assert( *pzErrMsg==0 );
127121
127122 if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
127123 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
127124 ){
127125 char *zOpt;
127126 int eState; /* Parser state when parsing URI */
127127 int iIn; /* Input character index */
127128 int iOut = 0; /* Output character index */
@@ -127105,11 +127348,13 @@
127348 assert( SQLITE_OPEN_READWRITE == 0x02 );
127349 assert( SQLITE_OPEN_CREATE == 0x04 );
127350 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
127351 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
127352 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
127353 if( ((1<<(flags&7)) & 0x46)==0 ){
127354 return SQLITE_MISUSE_BKPT; /* IMP: R-65497-44594 */
127355 }
127356
127357 if( sqlite3GlobalConfig.bCoreMutex==0 ){
127358 isThreadsafe = 0;
127359 }else if( flags & SQLITE_OPEN_NOMUTEX ){
127360 isThreadsafe = 0;
@@ -127989,26 +128234,10 @@
128234 case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
128235 sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
128236 break;
128237 }
128238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128239 /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
128240 **
128241 ** Set or clear a flag that indicates that the database file is always well-
128242 ** formed and never corrupt. This flag is clear by default, indicating that
128243 ** database files might have arbitrary corruption. Setting the flag during
@@ -132464,10 +132693,11 @@
132693 assert( iIdx==nVal );
132694
132695 /* In case the cursor has been used before, clear it now. */
132696 sqlite3_finalize(pCsr->pStmt);
132697 sqlite3_free(pCsr->aDoclist);
132698 sqlite3_free(pCsr->aMatchinfo);
132699 sqlite3Fts3ExprFree(pCsr->pExpr);
132700 memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
132701
132702 /* Set the lower and upper bounds on docids to return */
132703 pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
@@ -133774,11 +134004,11 @@
134004 if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
134005 iMax = a[i].iDocid;
134006 bMaxSet = 1;
134007 }
134008 }
134009 assert( rc!=SQLITE_OK || (p->nToken>=1 && a[p->nToken-1].bIgnore==0) );
134010 assert( rc!=SQLITE_OK || bMaxSet );
134011
134012 /* Keep advancing iterators until they all point to the same document */
134013 for(i=0; i<p->nToken; i++){
134014 while( rc==SQLITE_OK && bEof==0
@@ -135891,11 +136121,11 @@
136121 int i = 0;
136122
136123 /* Set variable i to the maximum number of bytes of input to tokenize. */
136124 for(i=0; i<n; i++){
136125 if( sqlite3_fts3_enable_parentheses && (z[i]=='(' || z[i]==')') ) break;
136126 if( z[i]=='"' ) break;
136127 }
136128
136129 *pnConsumed = i;
136130 rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, i, &pCursor);
136131 if( rc==SQLITE_OK ){
136132
+16 -18
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.7"
111111
#define SQLITE_VERSION_NUMBER 3008007
112
-#define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7"
112
+#define SQLITE_SOURCE_ID "2014-10-15 15:28:27 3c1e70f4d55bc009ed9ed4cf6d756d7061985851"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2667,13 +2667,13 @@
26672667
** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
26682668
** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
26692669
** an English language description of the error following a failure of any
26702670
** of the sqlite3_open() routines.
26712671
**
2672
-** ^The default encoding for the database will be UTF-8 if
2673
-** sqlite3_open() or sqlite3_open_v2() is called and
2674
-** UTF-16 in the native byte order if sqlite3_open16() is used.
2672
+** ^The default encoding will be UTF-8 for databases created using
2673
+** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
2674
+** created using sqlite3_open16() will be UTF-16 in the native byte order.
26752675
**
26762676
** Whether or not an error occurs when it is opened, resources
26772677
** associated with the [database connection] handle should be released by
26782678
** passing it to [sqlite3_close()] when it is no longer required.
26792679
**
@@ -2757,17 +2757,18 @@
27572757
** ^SQLite uses the path component of the URI as the name of the disk file
27582758
** which contains the database. ^If the path begins with a '/' character,
27592759
** then it is interpreted as an absolute path. ^If the path does not begin
27602760
** with a '/' (meaning that the authority section is omitted from the URI)
27612761
** then the path is interpreted as a relative path.
2762
-** ^On windows, the first component of an absolute path
2763
-** is a drive specification (e.g. "C:").
2762
+** ^(On windows, the first component of an absolute path
2763
+** is a drive specification (e.g. "C:").)^
27642764
**
27652765
** [[core URI query parameters]]
27662766
** The query component of a URI may contain parameters that are interpreted
27672767
** either by SQLite itself, or by a [VFS | custom VFS implementation].
2768
-** SQLite interprets the following three query parameters:
2768
+** SQLite and its built-in [VFSes] interpret the
2769
+** following query parameters:
27692770
**
27702771
** <ul>
27712772
** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
27722773
** a VFS object that provides the operating system interface that should
27732774
** be used to access the database file on disk. ^If this option is set to
@@ -2798,15 +2799,13 @@
27982799
** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
27992800
** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
28002801
** a URI filename, its value overrides any behavior requested by setting
28012802
** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
28022803
**
2803
-** <li> <b>psow</b>: ^The psow parameter may be "true" (or "on" or "yes" or
2804
-** "1") or "false" (or "off" or "no" or "0") to indicate that the
2804
+** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
28052805
** [powersafe overwrite] property does or does not apply to the
2806
-** storage media on which the database file resides. ^The psow query
2807
-** parameter only works for the built-in unix and Windows VFSes.
2806
+** storage media on which the database file resides.
28082807
**
28092808
** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
28102809
** which if set disables file locking in rollback journal modes. This
28112810
** is useful for accessing a database on a filesystem that does not
28122811
** support locking. Caution: Database corruption might result if two
@@ -3397,15 +3396,14 @@
33973396
** terminated. If any NUL characters occur at byte offsets less than
33983397
** the value of the fourth parameter then the resulting string value will
33993398
** contain embedded NULs. The result of expressions involving strings
34003399
** with embedded NULs is undefined.
34013400
**
3402
-** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3403
-** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3401
+** ^The fifth argument to the BLOB and string binding interfaces
3402
+** is a destructor used to dispose of the BLOB or
34043403
** string after SQLite has finished with it. ^The destructor is called
3405
-** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
3406
-** sqlite3_bind_text(), or sqlite3_bind_text16() fails.
3404
+** to dispose of the BLOB or string even if the call to bind API fails.
34073405
** ^If the fifth argument is
34083406
** the special value [SQLITE_STATIC], then SQLite assumes that the
34093407
** information is in static, unmanaged space and does not need to be freed.
34103408
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
34113409
** SQLite makes its own private copy of the data immediately, before
@@ -3412,11 +3410,11 @@
34123410
** the sqlite3_bind_*() routine returns.
34133411
**
34143412
** ^The sixth argument to sqlite3_bind_text64() must be one of
34153413
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
34163414
** to specify the encoding of the text in the third parameter. If
3417
-** the sixth argument to sqlite3_bind_text64() is not how of the
3415
+** the sixth argument to sqlite3_bind_text64() is not one of the
34183416
** allowed values shown above, or if the text encoding is different
34193417
** from the encoding specified by the sixth parameter, then the behavior
34203418
** is undefined.
34213419
**
34223420
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
@@ -4448,11 +4446,11 @@
44484446
**
44494447
** ^The sqlite3_result_null() interface sets the return value
44504448
** of the application-defined function to be NULL.
44514449
**
44524450
** ^The sqlite3_result_text(), sqlite3_result_text16(),
4453
-** sqlite3_result_text16le(), and sqlite3_result_text16be()
4451
+** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
44544452
** set the return value of the application-defined function to be
44554453
** a text string which is represented as UTF-8, UTF-16 native byte order,
44564454
** UTF-16 little endian, or UTF-16 big endian, respectively.
44574455
** ^The sqlite3_result_text64() interface sets the return value of an
44584456
** application-defined function to be a text string in an encoding
@@ -6208,11 +6206,11 @@
62086206
#define SQLITE_TESTCTRL_RESERVE 14
62096207
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
62106208
#define SQLITE_TESTCTRL_ISKEYWORD 16
62116209
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
62126210
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6213
-#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6211
+#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
62146212
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
62156213
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
62166214
#define SQLITE_TESTCTRL_BYTEORDER 22
62176215
#define SQLITE_TESTCTRL_ISINIT 23
62186216
#define SQLITE_TESTCTRL_SORTER_MMAP 24
62196217
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.7"
111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2014-09-20 00:35:05 59e2c9df02d7e988c5ad44c560ead1e5288b12e7"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2667,13 +2667,13 @@
2667 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
2668 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
2669 ** an English language description of the error following a failure of any
2670 ** of the sqlite3_open() routines.
2671 **
2672 ** ^The default encoding for the database will be UTF-8 if
2673 ** sqlite3_open() or sqlite3_open_v2() is called and
2674 ** UTF-16 in the native byte order if sqlite3_open16() is used.
2675 **
2676 ** Whether or not an error occurs when it is opened, resources
2677 ** associated with the [database connection] handle should be released by
2678 ** passing it to [sqlite3_close()] when it is no longer required.
2679 **
@@ -2757,17 +2757,18 @@
2757 ** ^SQLite uses the path component of the URI as the name of the disk file
2758 ** which contains the database. ^If the path begins with a '/' character,
2759 ** then it is interpreted as an absolute path. ^If the path does not begin
2760 ** with a '/' (meaning that the authority section is omitted from the URI)
2761 ** then the path is interpreted as a relative path.
2762 ** ^On windows, the first component of an absolute path
2763 ** is a drive specification (e.g. "C:").
2764 **
2765 ** [[core URI query parameters]]
2766 ** The query component of a URI may contain parameters that are interpreted
2767 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
2768 ** SQLite interprets the following three query parameters:
 
2769 **
2770 ** <ul>
2771 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
2772 ** a VFS object that provides the operating system interface that should
2773 ** be used to access the database file on disk. ^If this option is set to
@@ -2798,15 +2799,13 @@
2798 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2799 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2800 ** a URI filename, its value overrides any behavior requested by setting
2801 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2802 **
2803 ** <li> <b>psow</b>: ^The psow parameter may be "true" (or "on" or "yes" or
2804 ** "1") or "false" (or "off" or "no" or "0") to indicate that the
2805 ** [powersafe overwrite] property does or does not apply to the
2806 ** storage media on which the database file resides. ^The psow query
2807 ** parameter only works for the built-in unix and Windows VFSes.
2808 **
2809 ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
2810 ** which if set disables file locking in rollback journal modes. This
2811 ** is useful for accessing a database on a filesystem that does not
2812 ** support locking. Caution: Database corruption might result if two
@@ -3397,15 +3396,14 @@
3397 ** terminated. If any NUL characters occur at byte offsets less than
3398 ** the value of the fourth parameter then the resulting string value will
3399 ** contain embedded NULs. The result of expressions involving strings
3400 ** with embedded NULs is undefined.
3401 **
3402 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3403 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3404 ** string after SQLite has finished with it. ^The destructor is called
3405 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
3406 ** sqlite3_bind_text(), or sqlite3_bind_text16() fails.
3407 ** ^If the fifth argument is
3408 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3409 ** information is in static, unmanaged space and does not need to be freed.
3410 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3411 ** SQLite makes its own private copy of the data immediately, before
@@ -3412,11 +3410,11 @@
3412 ** the sqlite3_bind_*() routine returns.
3413 **
3414 ** ^The sixth argument to sqlite3_bind_text64() must be one of
3415 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3416 ** to specify the encoding of the text in the third parameter. If
3417 ** the sixth argument to sqlite3_bind_text64() is not how of the
3418 ** allowed values shown above, or if the text encoding is different
3419 ** from the encoding specified by the sixth parameter, then the behavior
3420 ** is undefined.
3421 **
3422 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
@@ -4448,11 +4446,11 @@
4448 **
4449 ** ^The sqlite3_result_null() interface sets the return value
4450 ** of the application-defined function to be NULL.
4451 **
4452 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4453 ** sqlite3_result_text16le(), and sqlite3_result_text16be()
4454 ** set the return value of the application-defined function to be
4455 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4456 ** UTF-16 little endian, or UTF-16 big endian, respectively.
4457 ** ^The sqlite3_result_text64() interface sets the return value of an
4458 ** application-defined function to be a text string in an encoding
@@ -6208,11 +6206,11 @@
6208 #define SQLITE_TESTCTRL_RESERVE 14
6209 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6210 #define SQLITE_TESTCTRL_ISKEYWORD 16
6211 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6212 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6213 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6214 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6215 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6216 #define SQLITE_TESTCTRL_BYTEORDER 22
6217 #define SQLITE_TESTCTRL_ISINIT 23
6218 #define SQLITE_TESTCTRL_SORTER_MMAP 24
6219
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.7"
111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2014-10-15 15:28:27 3c1e70f4d55bc009ed9ed4cf6d756d7061985851"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2667,13 +2667,13 @@
2667 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
2668 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
2669 ** an English language description of the error following a failure of any
2670 ** of the sqlite3_open() routines.
2671 **
2672 ** ^The default encoding will be UTF-8 for databases created using
2673 ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
2674 ** created using sqlite3_open16() will be UTF-16 in the native byte order.
2675 **
2676 ** Whether or not an error occurs when it is opened, resources
2677 ** associated with the [database connection] handle should be released by
2678 ** passing it to [sqlite3_close()] when it is no longer required.
2679 **
@@ -2757,17 +2757,18 @@
2757 ** ^SQLite uses the path component of the URI as the name of the disk file
2758 ** which contains the database. ^If the path begins with a '/' character,
2759 ** then it is interpreted as an absolute path. ^If the path does not begin
2760 ** with a '/' (meaning that the authority section is omitted from the URI)
2761 ** then the path is interpreted as a relative path.
2762 ** ^(On windows, the first component of an absolute path
2763 ** is a drive specification (e.g. "C:").)^
2764 **
2765 ** [[core URI query parameters]]
2766 ** The query component of a URI may contain parameters that are interpreted
2767 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
2768 ** SQLite and its built-in [VFSes] interpret the
2769 ** following query parameters:
2770 **
2771 ** <ul>
2772 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
2773 ** a VFS object that provides the operating system interface that should
2774 ** be used to access the database file on disk. ^If this option is set to
@@ -2798,15 +2799,13 @@
2799 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2800 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2801 ** a URI filename, its value overrides any behavior requested by setting
2802 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2803 **
2804 ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
 
2805 ** [powersafe overwrite] property does or does not apply to the
2806 ** storage media on which the database file resides.
 
2807 **
2808 ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
2809 ** which if set disables file locking in rollback journal modes. This
2810 ** is useful for accessing a database on a filesystem that does not
2811 ** support locking. Caution: Database corruption might result if two
@@ -3397,15 +3396,14 @@
3396 ** terminated. If any NUL characters occur at byte offsets less than
3397 ** the value of the fourth parameter then the resulting string value will
3398 ** contain embedded NULs. The result of expressions involving strings
3399 ** with embedded NULs is undefined.
3400 **
3401 ** ^The fifth argument to the BLOB and string binding interfaces
3402 ** is a destructor used to dispose of the BLOB or
3403 ** string after SQLite has finished with it. ^The destructor is called
3404 ** to dispose of the BLOB or string even if the call to bind API fails.
 
3405 ** ^If the fifth argument is
3406 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3407 ** information is in static, unmanaged space and does not need to be freed.
3408 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3409 ** SQLite makes its own private copy of the data immediately, before
@@ -3412,11 +3410,11 @@
3410 ** the sqlite3_bind_*() routine returns.
3411 **
3412 ** ^The sixth argument to sqlite3_bind_text64() must be one of
3413 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3414 ** to specify the encoding of the text in the third parameter. If
3415 ** the sixth argument to sqlite3_bind_text64() is not one of the
3416 ** allowed values shown above, or if the text encoding is different
3417 ** from the encoding specified by the sixth parameter, then the behavior
3418 ** is undefined.
3419 **
3420 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
@@ -4448,11 +4446,11 @@
4446 **
4447 ** ^The sqlite3_result_null() interface sets the return value
4448 ** of the application-defined function to be NULL.
4449 **
4450 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4451 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4452 ** set the return value of the application-defined function to be
4453 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4454 ** UTF-16 little endian, or UTF-16 big endian, respectively.
4455 ** ^The sqlite3_result_text64() interface sets the return value of an
4456 ** application-defined function to be a text string in an encoding
@@ -6208,11 +6206,11 @@
6206 #define SQLITE_TESTCTRL_RESERVE 14
6207 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6208 #define SQLITE_TESTCTRL_ISKEYWORD 16
6209 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6210 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6211 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
6212 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6213 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6214 #define SQLITE_TESTCTRL_BYTEORDER 22
6215 #define SQLITE_TESTCTRL_ISINIT 23
6216 #define SQLITE_TESTCTRL_SORTER_MMAP 24
6217
+37 -14
--- src/stat.c
+++ src/stat.c
@@ -151,35 +151,45 @@
151151
}
152152
153153
/*
154154
** COMMAND: dbstat*
155155
**
156
-** Usage: %fossil dbstat ?-brief | -b?
156
+** Usage: %fossil dbstat OPTIONS
157157
**
158158
** Shows statistics and global information about the repository.
159159
**
160
-** The (-brief|-b) option removes any "long-running" statistics, namely
161
-** those whose calculations are known to slow down as the repository
162
-** grows.
160
+** Options:
163161
**
162
+** --brief|-b Only show essential elements
163
+** --db-check Run a PRAGMA quick_check on the repository database
164
+** --omit-version-info Omit the SQLite and Fossil version information
164165
*/
165166
void dbstat_cmd(void){
166167
i64 t, fsize;
167168
int n, m;
168169
int szMax, szAvg;
169170
const char *zDb;
170171
int brief;
172
+ int omitVers; /* Omit Fossil and SQLite version information */
173
+ int dbCheck; /* True for the --db-check option */
171174
char zBuf[100];
172175
const int colWidth = -19 /* printf alignment/width for left column */;
173
- const char *p;
176
+ const char *p, *z;
174177
175178
brief = find_option("brief", "b",0)!=0;
179
+ omitVers = find_option("omit-version-info", 0, 0)!=0;
180
+ dbCheck = find_option("db-check",0,0)!=0;
176181
db_find_and_open_repository(0,0);
177182
178183
/* We should be done with options.. */
179184
verify_all_options();
180185
186
+ if( (z = db_get("project-name",0))!=0
187
+ || (z = db_get("short-project-name",0))!=0
188
+ ){
189
+ fossil_print("%*s%s\n", colWidth, "project-name:", z);
190
+ }
181191
fsize = file_size(g.zRepositoryName);
182192
bigSizeName(sizeof(zBuf), zBuf, fsize);
183193
fossil_print( "%*s%s\n", colWidth, "repository-size:", zBuf );
184194
if( !brief ){
185195
n = db_int(0, "SELECT count(*) FROM blob");
@@ -225,38 +235,51 @@
225235
fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
226236
n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
227237
fossil_print("%*s%d\n", colWidth, "events:", n);
228238
n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
229239
fossil_print("%*s%d\n", colWidth, "tagchanges:", n);
240
+ z = db_text(0, "SELECT datetime(mtime) || ' - about ' ||"
241
+ " CAST(julianday('now') - mtime AS INTEGER)"
242
+ " || ' days ago' FROM event "
243
+ " ORDER BY mtime DESC LIMIT 1");
244
+ fossil_print("%*s%s\n", colWidth, "latest-change:", z);
230245
}
231246
n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
232247
" + 0.99");
233248
fossil_print("%*s%d days or approximately %.2f years.\n",
234249
colWidth, "project-age:", n, n/365.2425);
235250
p = db_get("project-code", 0);
236251
if( p ){
237252
fossil_print("%*s%s\n", colWidth, "project-id:", p);
238253
}
254
+#if 0
255
+ /* Server-id is not useful information any more */
239256
fossil_print("%*s%s\n", colWidth, "server-id:", db_get("server-code", 0));
240
- fossil_print("%*s%s %s [%s] (%s)\n",
241
- colWidth, "fossil-version:",
242
- MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
243
- COMPILER_NAME);
244
- fossil_print("%*s%.19s [%.10s] (%s)\n",
245
- colWidth, "sqlite-version:",
246
- sqlite3_sourceid(), &sqlite3_sourceid()[20],
247
- sqlite3_libversion());
257
+#endif
258
+ if( !omitVers ){
259
+ fossil_print("%*s%s %s [%s] (%s)\n",
260
+ colWidth, "fossil-version:",
261
+ MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
262
+ COMPILER_NAME);
263
+ fossil_print("%*s%.19s [%.10s] (%s)\n",
264
+ colWidth, "sqlite-version:",
265
+ sqlite3_sourceid(), &sqlite3_sourceid()[20],
266
+ sqlite3_libversion());
267
+ }
248268
zDb = db_name("repository");
249269
fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
250270
"%s, %s mode\n",
251271
colWidth, "database-stats:",
252272
db_int(0, "PRAGMA %s.page_count", zDb),
253273
db_int(0, "PRAGMA %s.page_size", zDb),
254274
db_int(0, "PRAGMA %s.freelist_count", zDb),
255275
db_text(0, "PRAGMA %s.encoding", zDb),
256276
db_text(0, "PRAGMA %s.journal_mode", zDb));
257
-
277
+ if( dbCheck ){
278
+ fossil_print("%*s%s\n", colWidth, "database-check:",
279
+ db_text(0, "PRAGMA quick_check(1)"));
280
+ }
258281
}
259282
260283
/*
261284
** WEBPAGE: urllist
262285
**
263286
--- src/stat.c
+++ src/stat.c
@@ -151,35 +151,45 @@
151 }
152
153 /*
154 ** COMMAND: dbstat*
155 **
156 ** Usage: %fossil dbstat ?-brief | -b?
157 **
158 ** Shows statistics and global information about the repository.
159 **
160 ** The (-brief|-b) option removes any "long-running" statistics, namely
161 ** those whose calculations are known to slow down as the repository
162 ** grows.
163 **
 
 
 
164 */
165 void dbstat_cmd(void){
166 i64 t, fsize;
167 int n, m;
168 int szMax, szAvg;
169 const char *zDb;
170 int brief;
 
 
171 char zBuf[100];
172 const int colWidth = -19 /* printf alignment/width for left column */;
173 const char *p;
174
175 brief = find_option("brief", "b",0)!=0;
 
 
176 db_find_and_open_repository(0,0);
177
178 /* We should be done with options.. */
179 verify_all_options();
180
 
 
 
 
 
181 fsize = file_size(g.zRepositoryName);
182 bigSizeName(sizeof(zBuf), zBuf, fsize);
183 fossil_print( "%*s%s\n", colWidth, "repository-size:", zBuf );
184 if( !brief ){
185 n = db_int(0, "SELECT count(*) FROM blob");
@@ -225,38 +235,51 @@
225 fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
226 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
227 fossil_print("%*s%d\n", colWidth, "events:", n);
228 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
229 fossil_print("%*s%d\n", colWidth, "tagchanges:", n);
 
 
 
 
 
230 }
231 n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
232 " + 0.99");
233 fossil_print("%*s%d days or approximately %.2f years.\n",
234 colWidth, "project-age:", n, n/365.2425);
235 p = db_get("project-code", 0);
236 if( p ){
237 fossil_print("%*s%s\n", colWidth, "project-id:", p);
238 }
 
 
239 fossil_print("%*s%s\n", colWidth, "server-id:", db_get("server-code", 0));
240 fossil_print("%*s%s %s [%s] (%s)\n",
241 colWidth, "fossil-version:",
242 MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
243 COMPILER_NAME);
244 fossil_print("%*s%.19s [%.10s] (%s)\n",
245 colWidth, "sqlite-version:",
246 sqlite3_sourceid(), &sqlite3_sourceid()[20],
247 sqlite3_libversion());
 
 
 
248 zDb = db_name("repository");
249 fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
250 "%s, %s mode\n",
251 colWidth, "database-stats:",
252 db_int(0, "PRAGMA %s.page_count", zDb),
253 db_int(0, "PRAGMA %s.page_size", zDb),
254 db_int(0, "PRAGMA %s.freelist_count", zDb),
255 db_text(0, "PRAGMA %s.encoding", zDb),
256 db_text(0, "PRAGMA %s.journal_mode", zDb));
257
 
 
 
258 }
259
260 /*
261 ** WEBPAGE: urllist
262 **
263
--- src/stat.c
+++ src/stat.c
@@ -151,35 +151,45 @@
151 }
152
153 /*
154 ** COMMAND: dbstat*
155 **
156 ** Usage: %fossil dbstat OPTIONS
157 **
158 ** Shows statistics and global information about the repository.
159 **
160 ** Options:
 
 
161 **
162 ** --brief|-b Only show essential elements
163 ** --db-check Run a PRAGMA quick_check on the repository database
164 ** --omit-version-info Omit the SQLite and Fossil version information
165 */
166 void dbstat_cmd(void){
167 i64 t, fsize;
168 int n, m;
169 int szMax, szAvg;
170 const char *zDb;
171 int brief;
172 int omitVers; /* Omit Fossil and SQLite version information */
173 int dbCheck; /* True for the --db-check option */
174 char zBuf[100];
175 const int colWidth = -19 /* printf alignment/width for left column */;
176 const char *p, *z;
177
178 brief = find_option("brief", "b",0)!=0;
179 omitVers = find_option("omit-version-info", 0, 0)!=0;
180 dbCheck = find_option("db-check",0,0)!=0;
181 db_find_and_open_repository(0,0);
182
183 /* We should be done with options.. */
184 verify_all_options();
185
186 if( (z = db_get("project-name",0))!=0
187 || (z = db_get("short-project-name",0))!=0
188 ){
189 fossil_print("%*s%s\n", colWidth, "project-name:", z);
190 }
191 fsize = file_size(g.zRepositoryName);
192 bigSizeName(sizeof(zBuf), zBuf, fsize);
193 fossil_print( "%*s%s\n", colWidth, "repository-size:", zBuf );
194 if( !brief ){
195 n = db_int(0, "SELECT count(*) FROM blob");
@@ -225,38 +235,51 @@
235 fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
236 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
237 fossil_print("%*s%d\n", colWidth, "events:", n);
238 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
239 fossil_print("%*s%d\n", colWidth, "tagchanges:", n);
240 z = db_text(0, "SELECT datetime(mtime) || ' - about ' ||"
241 " CAST(julianday('now') - mtime AS INTEGER)"
242 " || ' days ago' FROM event "
243 " ORDER BY mtime DESC LIMIT 1");
244 fossil_print("%*s%s\n", colWidth, "latest-change:", z);
245 }
246 n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
247 " + 0.99");
248 fossil_print("%*s%d days or approximately %.2f years.\n",
249 colWidth, "project-age:", n, n/365.2425);
250 p = db_get("project-code", 0);
251 if( p ){
252 fossil_print("%*s%s\n", colWidth, "project-id:", p);
253 }
254 #if 0
255 /* Server-id is not useful information any more */
256 fossil_print("%*s%s\n", colWidth, "server-id:", db_get("server-code", 0));
257 #endif
258 if( !omitVers ){
259 fossil_print("%*s%s %s [%s] (%s)\n",
260 colWidth, "fossil-version:",
261 MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
262 COMPILER_NAME);
263 fossil_print("%*s%.19s [%.10s] (%s)\n",
264 colWidth, "sqlite-version:",
265 sqlite3_sourceid(), &sqlite3_sourceid()[20],
266 sqlite3_libversion());
267 }
268 zDb = db_name("repository");
269 fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
270 "%s, %s mode\n",
271 colWidth, "database-stats:",
272 db_int(0, "PRAGMA %s.page_count", zDb),
273 db_int(0, "PRAGMA %s.page_size", zDb),
274 db_int(0, "PRAGMA %s.freelist_count", zDb),
275 db_text(0, "PRAGMA %s.encoding", zDb),
276 db_text(0, "PRAGMA %s.journal_mode", zDb));
277 if( dbCheck ){
278 fossil_print("%*s%s\n", colWidth, "database-check:",
279 db_text(0, "PRAGMA quick_check(1)"));
280 }
281 }
282
283 /*
284 ** WEBPAGE: urllist
285 **
286
+9 -1
--- src/style.c
+++ src/style.c
@@ -175,11 +175,11 @@
175175
}
176176
for(i=0; i<nFormAction; i++){
177177
@ gebi("form%d(i+1)").action="%s(aFormAction[i])";
178178
}
179179
@ }
180
- if( strglob("*Opera Mini/[1-9]*", P("HTTP_USER_AGENT")) ){
180
+ if( sqlite3_strglob("*Opera Mini/[1-9]*", P("HTTP_USER_AGENT"))==0 ){
181181
/* Special case for Opera Mini, which executes JS server-side */
182182
@ var isOperaMini = Object.prototype.toString.call(window.operamini)
183183
@ === "[object OperaMini]";
184184
@ if( isOperaMini ){
185185
@ setTimeout("setAllHrefs();",%d(nDelay));
@@ -934,22 +934,26 @@
934934
@ white-space: nowrap;
935935
},
936936
{ "span.ueditInheritNobody",
937937
"color for capabilities, inherited by nobody",
938938
@ color: green;
939
+ @ padding: .2em;
939940
},
940941
{ "span.ueditInheritDeveloper",
941942
"color for capabilities, inherited by developer",
942943
@ color: red;
944
+ @ padding: .2em;
943945
},
944946
{ "span.ueditInheritReader",
945947
"color for capabilities, inherited by reader",
946948
@ color: black;
949
+ @ padding: .2em;
947950
},
948951
{ "span.ueditInheritAnonymous",
949952
"color for capabilities, inherited by anonymous",
950953
@ color: blue;
954
+ @ padding: .2em;
951955
},
952956
{ "span.capability",
953957
"format for capabilities, mentioned on the user edit page",
954958
@ font-weight: bold;
955959
},
@@ -1191,10 +1195,14 @@
11911195
@ /* use default */
11921196
},
11931197
{ "tr.row1",
11941198
"odd table row color",
11951199
@ /* Use default */
1200
+ },
1201
+ { "#usetupEditCapability",
1202
+ "format for capabilities string, mentioned on the user edit page",
1203
+ @ font-weight: bold;
11961204
},
11971205
{ "#canvas", "timeline graph node colors",
11981206
@ color: black;
11991207
@ background-color: white;
12001208
},
12011209
--- src/style.c
+++ src/style.c
@@ -175,11 +175,11 @@
175 }
176 for(i=0; i<nFormAction; i++){
177 @ gebi("form%d(i+1)").action="%s(aFormAction[i])";
178 }
179 @ }
180 if( strglob("*Opera Mini/[1-9]*", P("HTTP_USER_AGENT")) ){
181 /* Special case for Opera Mini, which executes JS server-side */
182 @ var isOperaMini = Object.prototype.toString.call(window.operamini)
183 @ === "[object OperaMini]";
184 @ if( isOperaMini ){
185 @ setTimeout("setAllHrefs();",%d(nDelay));
@@ -934,22 +934,26 @@
934 @ white-space: nowrap;
935 },
936 { "span.ueditInheritNobody",
937 "color for capabilities, inherited by nobody",
938 @ color: green;
 
939 },
940 { "span.ueditInheritDeveloper",
941 "color for capabilities, inherited by developer",
942 @ color: red;
 
943 },
944 { "span.ueditInheritReader",
945 "color for capabilities, inherited by reader",
946 @ color: black;
 
947 },
948 { "span.ueditInheritAnonymous",
949 "color for capabilities, inherited by anonymous",
950 @ color: blue;
 
951 },
952 { "span.capability",
953 "format for capabilities, mentioned on the user edit page",
954 @ font-weight: bold;
955 },
@@ -1191,10 +1195,14 @@
1191 @ /* use default */
1192 },
1193 { "tr.row1",
1194 "odd table row color",
1195 @ /* Use default */
 
 
 
 
1196 },
1197 { "#canvas", "timeline graph node colors",
1198 @ color: black;
1199 @ background-color: white;
1200 },
1201
--- src/style.c
+++ src/style.c
@@ -175,11 +175,11 @@
175 }
176 for(i=0; i<nFormAction; i++){
177 @ gebi("form%d(i+1)").action="%s(aFormAction[i])";
178 }
179 @ }
180 if( sqlite3_strglob("*Opera Mini/[1-9]*", P("HTTP_USER_AGENT"))==0 ){
181 /* Special case for Opera Mini, which executes JS server-side */
182 @ var isOperaMini = Object.prototype.toString.call(window.operamini)
183 @ === "[object OperaMini]";
184 @ if( isOperaMini ){
185 @ setTimeout("setAllHrefs();",%d(nDelay));
@@ -934,22 +934,26 @@
934 @ white-space: nowrap;
935 },
936 { "span.ueditInheritNobody",
937 "color for capabilities, inherited by nobody",
938 @ color: green;
939 @ padding: .2em;
940 },
941 { "span.ueditInheritDeveloper",
942 "color for capabilities, inherited by developer",
943 @ color: red;
944 @ padding: .2em;
945 },
946 { "span.ueditInheritReader",
947 "color for capabilities, inherited by reader",
948 @ color: black;
949 @ padding: .2em;
950 },
951 { "span.ueditInheritAnonymous",
952 "color for capabilities, inherited by anonymous",
953 @ color: blue;
954 @ padding: .2em;
955 },
956 { "span.capability",
957 "format for capabilities, mentioned on the user edit page",
958 @ font-weight: bold;
959 },
@@ -1191,10 +1195,14 @@
1195 @ /* use default */
1196 },
1197 { "tr.row1",
1198 "odd table row color",
1199 @ /* Use default */
1200 },
1201 { "#usetupEditCapability",
1202 "format for capabilities string, mentioned on the user edit page",
1203 @ font-weight: bold;
1204 },
1205 { "#canvas", "timeline graph node colors",
1206 @ color: black;
1207 @ background-color: white;
1208 },
1209
+9
--- src/util.c
+++ src/util.c
@@ -78,10 +78,19 @@
7878
free(zNewCmd);
7979
#else
8080
/* On unix, evaluate the command directly.
8181
*/
8282
if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd);
83
+
84
+ /* Unix systems should never shell-out while processing an HTTP request,
85
+ ** either via CGI, SCGI, or direct HTTP. The following assert verifies
86
+ ** this. And the following assert proves that Fossil is not vulnerable
87
+ ** to the ShellShock or BashDoor bug.
88
+ */
89
+ assert( g.cgiOutput==0 );
90
+
91
+ /* The regular system() call works to get a shell on unix */
8392
rc = system(zOrigCmd);
8493
#endif
8594
return rc;
8695
}
8796
8897
--- src/util.c
+++ src/util.c
@@ -78,10 +78,19 @@
78 free(zNewCmd);
79 #else
80 /* On unix, evaluate the command directly.
81 */
82 if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd);
 
 
 
 
 
 
 
 
 
83 rc = system(zOrigCmd);
84 #endif
85 return rc;
86 }
87
88
--- src/util.c
+++ src/util.c
@@ -78,10 +78,19 @@
78 free(zNewCmd);
79 #else
80 /* On unix, evaluate the command directly.
81 */
82 if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd);
83
84 /* Unix systems should never shell-out while processing an HTTP request,
85 ** either via CGI, SCGI, or direct HTTP. The following assert verifies
86 ** this. And the following assert proves that Fossil is not vulnerable
87 ** to the ShellShock or BashDoor bug.
88 */
89 assert( g.cgiOutput==0 );
90
91 /* The regular system() call works to get a shell on unix */
92 rc = system(zOrigCmd);
93 #endif
94 return rc;
95 }
96
97
+2 -2
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397397
"original",
398398
"output",
399399
};
400400
int i, j, n;
401401
402
- if( strglob("ci-comment-????????????.txt", zName) ) return 1;
402
+ if( sqlite3_strglob("ci-comment-????????????.txt", zName)==0 ) return 1;
403403
for(; zName[0]!=0; zName++){
404
- if( zName[0]=='/' && strglob("/ci-comment-????????????.txt", zName) ){
404
+ if( zName[0]=='/' && sqlite3_strglob("/ci-comment-????????????.txt", zName)==0 ){
405405
return 1;
406406
}
407407
if( zName[0]!='-' ) continue;
408408
for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409409
n = (int)strlen(azTemp[i]);
410410
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397 "original",
398 "output",
399 };
400 int i, j, n;
401
402 if( strglob("ci-comment-????????????.txt", zName) ) return 1;
403 for(; zName[0]!=0; zName++){
404 if( zName[0]=='/' && strglob("/ci-comment-????????????.txt", zName) ){
405 return 1;
406 }
407 if( zName[0]!='-' ) continue;
408 for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409 n = (int)strlen(azTemp[i]);
410
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397 "original",
398 "output",
399 };
400 int i, j, n;
401
402 if( sqlite3_strglob("ci-comment-????????????.txt", zName)==0 ) return 1;
403 for(; zName[0]!=0; zName++){
404 if( zName[0]=='/' && sqlite3_strglob("/ci-comment-????????????.txt", zName)==0 ){
405 return 1;
406 }
407 if( zName[0]!='-' ) continue;
408 for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409 n = (int)strlen(azTemp[i]);
410
+3 -1
--- src/xfer.c
+++ src/xfer.c
@@ -1814,11 +1814,11 @@
18141814
** to the next cycle.
18151815
*/
18161816
if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
18171817
char *zMsg = blob_terminate(&xfer.aToken[1]);
18181818
defossilize(zMsg);
1819
- if( (syncFlags & SYNC_PUSH) && zMsg && strglob("pull only *", zMsg) ){
1819
+ if( (syncFlags & SYNC_PUSH) && zMsg && sqlite3_strglob("pull only *", zMsg)==0 ){
18201820
syncFlags &= ~SYNC_PUSH;
18211821
zMsg = 0;
18221822
}
18231823
if( zMsg && zMsg[0] ){
18241824
fossil_force_newline();
@@ -1860,10 +1860,12 @@
18601860
g.url.flags |= URL_PROMPT_PW;
18611861
g.url.flags &= ~URL_PROMPTED;
18621862
url_prompt_for_password();
18631863
url_remember();
18641864
}
1865
+ }else{
1866
+ nErr++;
18651867
}
18661868
}else{
18671869
blob_appendf(&xfer.err, "server says: %s\n", zMsg);
18681870
nErr++;
18691871
}
18701872
--- src/xfer.c
+++ src/xfer.c
@@ -1814,11 +1814,11 @@
1814 ** to the next cycle.
1815 */
1816 if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
1817 char *zMsg = blob_terminate(&xfer.aToken[1]);
1818 defossilize(zMsg);
1819 if( (syncFlags & SYNC_PUSH) && zMsg && strglob("pull only *", zMsg) ){
1820 syncFlags &= ~SYNC_PUSH;
1821 zMsg = 0;
1822 }
1823 if( zMsg && zMsg[0] ){
1824 fossil_force_newline();
@@ -1860,10 +1860,12 @@
1860 g.url.flags |= URL_PROMPT_PW;
1861 g.url.flags &= ~URL_PROMPTED;
1862 url_prompt_for_password();
1863 url_remember();
1864 }
 
 
1865 }
1866 }else{
1867 blob_appendf(&xfer.err, "server says: %s\n", zMsg);
1868 nErr++;
1869 }
1870
--- src/xfer.c
+++ src/xfer.c
@@ -1814,11 +1814,11 @@
1814 ** to the next cycle.
1815 */
1816 if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
1817 char *zMsg = blob_terminate(&xfer.aToken[1]);
1818 defossilize(zMsg);
1819 if( (syncFlags & SYNC_PUSH) && zMsg && sqlite3_strglob("pull only *", zMsg)==0 ){
1820 syncFlags &= ~SYNC_PUSH;
1821 zMsg = 0;
1822 }
1823 if( zMsg && zMsg[0] ){
1824 fossil_force_newline();
@@ -1860,10 +1860,12 @@
1860 g.url.flags |= URL_PROMPT_PW;
1861 g.url.flags &= ~URL_PROMPTED;
1862 url_prompt_for_password();
1863 url_remember();
1864 }
1865 }else{
1866 nErr++;
1867 }
1868 }else{
1869 blob_appendf(&xfer.err, "server says: %s\n", zMsg);
1870 nErr++;
1871 }
1872
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -113,12 +113,12 @@
113113
#### The directories where the OpenSSL include and library files are located.
114114
# The recommended usage here is to use the Sysinternals junction tool
115115
# to create a hard link between an "openssl-1.x" sub-directory of the
116116
# Fossil source code directory and the target OpenSSL source directory.
117117
#
118
-OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1i/include
119
-OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1i
118
+OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
119
+OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
120120
121121
#### Either the directory where the Tcl library is installed or the Tcl
122122
# source code directory resides (depending on the value of the macro
123123
# FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
124124
# this directory must have "include" and "lib" sub-directories. If
125125
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -113,12 +113,12 @@
113 #### The directories where the OpenSSL include and library files are located.
114 # The recommended usage here is to use the Sysinternals junction tool
115 # to create a hard link between an "openssl-1.x" sub-directory of the
116 # Fossil source code directory and the target OpenSSL source directory.
117 #
118 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1i/include
119 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1i
120
121 #### Either the directory where the Tcl library is installed or the Tcl
122 # source code directory resides (depending on the value of the macro
123 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
124 # this directory must have "include" and "lib" sub-directories. If
125
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -113,12 +113,12 @@
113 #### The directories where the OpenSSL include and library files are located.
114 # The recommended usage here is to use the Sysinternals junction tool
115 # to create a hard link between an "openssl-1.x" sub-directory of the
116 # Fossil source code directory and the target OpenSSL source directory.
117 #
118 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
119 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
120
121 #### Either the directory where the Tcl library is installed or the Tcl
122 # source code directory resides (depending on the value of the macro
123 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
124 # this directory must have "include" and "lib" sub-directories. If
125
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -113,12 +113,12 @@
113113
#### The directories where the OpenSSL include and library files are located.
114114
# The recommended usage here is to use the Sysinternals junction tool
115115
# to create a hard link between an "openssl-1.x" sub-directory of the
116116
# Fossil source code directory and the target OpenSSL source directory.
117117
#
118
-OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1i/include
119
-OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1i
118
+OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
119
+OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
120120
121121
#### Either the directory where the Tcl library is installed or the Tcl
122122
# source code directory resides (depending on the value of the macro
123123
# FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
124124
# this directory must have "include" and "lib" sub-directories. If
125125
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -113,12 +113,12 @@
113 #### The directories where the OpenSSL include and library files are located.
114 # The recommended usage here is to use the Sysinternals junction tool
115 # to create a hard link between an "openssl-1.x" sub-directory of the
116 # Fossil source code directory and the target OpenSSL source directory.
117 #
118 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1i/include
119 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1i
120
121 #### Either the directory where the Tcl library is installed or the Tcl
122 # source code directory resides (depending on the value of the macro
123 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
124 # this directory must have "include" and "lib" sub-directories. If
125
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -113,12 +113,12 @@
113 #### The directories where the OpenSSL include and library files are located.
114 # The recommended usage here is to use the Sysinternals junction tool
115 # to create a hard link between an "openssl-1.x" sub-directory of the
116 # Fossil source code directory and the target OpenSSL source directory.
117 #
118 OPENSSLINCDIR = $(SRCDIR)/../compat/openssl-1.0.1j/include
119 OPENSSLLIBDIR = $(SRCDIR)/../compat/openssl-1.0.1j
120
121 #### Either the directory where the Tcl library is installed or the Tcl
122 # source code directory resides (depending on the value of the macro
123 # FOSSIL_TCL_SOURCE). If this points to the Tcl install directory,
124 # this directory must have "include" and "lib" sub-directories. If
125
+24 -1
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -29,10 +29,13 @@
2929
PERLDIR = C:\Perl\bin
3030
PERL = perl.exe
3131
3232
# Uncomment to enable debug symbols
3333
# DEBUG = 1
34
+
35
+# Uncomment to support Windows XP with Visual Studio 201x
36
+# FOSSIL_ENABLE_WINXP = 1
3437
3538
# Uncomment to enable JSON API
3639
# FOSSIL_ENABLE_JSON = 1
3740
3841
# Uncomment to enable miniz usage
@@ -52,13 +55,14 @@
5255
5356
# Uncomment to enable Tcl support
5457
# FOSSIL_ENABLE_TCL = 1
5558
5659
!ifdef FOSSIL_ENABLE_SSL
57
-SSLDIR = $(B)\compat\openssl-1.0.1i
60
+SSLDIR = $(B)\compat\openssl-1.0.1j
5861
SSLINCDIR = $(SSLDIR)\inc32
5962
SSLLIBDIR = $(SSLDIR)\out32
63
+SSLLFLAGS = /nologo /opt:ref /debug
6064
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
6165
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
6266
!message Using 'x64' platform for OpenSSL...
6367
SSLCONFIG = VC-WIN64A no-asm
6468
SSLSETUP = ms\do_win64a.bat
@@ -101,10 +105,21 @@
101105
INCL = $(INCL) /I$(TCLINCDIR)
102106
!endif
103107
104108
CFLAGS = /nologo
105109
LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
110
+
111
+!ifdef FOSSIL_ENABLE_WINXP
112
+XPCFLAGS = $(XPCFLAGS) /D_USING_V110_SDK71_=1
113
+CFLAGS = $(CFLAGS) $(XPCFLAGS)
114
+!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
115
+XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.02
116
+!else
117
+XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.01
118
+!endif
119
+LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
120
+!endif
106121
107122
!ifdef DEBUG
108123
CFLAGS = $(CFLAGS) /Zi /MTd /Od
109124
LDFLAGS = $(LDFLAGS) /DEBUG
110125
!else
@@ -423,21 +438,29 @@
423438
424439
all: $(OX) $(APPNAME)
425440
426441
zlib:
427442
@echo Building zlib from "$(ZLIBDIR)"...
443
+!ifdef FOSSIL_ENABLE_WINXP
444
+ @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) "CC=cl $(XPCFLAGS)" "LD=link $(XPLDFLAGS)" && popd
445
+!else
428446
@pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) && popd
447
+!endif
429448
430449
!ifdef FOSSIL_ENABLE_SSL
431450
openssl:
432451
@echo Building OpenSSL from "$(SSLDIR)"...
433452
!if "$(PERLDIR)" != ""
434453
@set PATH=$(PERLDIR);$(PATH)
435454
!endif
436455
@pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
437456
@pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
457
+!ifdef FOSSIL_ENABLE_WINXP
458
+ @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
459
+!else
438460
@pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
461
+!endif
439462
!endif
440463
441464
!ifndef FOSSIL_ENABLE_MINIZ
442465
APPTARGETS = $(APPTARGETS) zlib
443466
!endif
444467
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -29,10 +29,13 @@
29 PERLDIR = C:\Perl\bin
30 PERL = perl.exe
31
32 # Uncomment to enable debug symbols
33 # DEBUG = 1
 
 
 
34
35 # Uncomment to enable JSON API
36 # FOSSIL_ENABLE_JSON = 1
37
38 # Uncomment to enable miniz usage
@@ -52,13 +55,14 @@
52
53 # Uncomment to enable Tcl support
54 # FOSSIL_ENABLE_TCL = 1
55
56 !ifdef FOSSIL_ENABLE_SSL
57 SSLDIR = $(B)\compat\openssl-1.0.1i
58 SSLINCDIR = $(SSLDIR)\inc32
59 SSLLIBDIR = $(SSLDIR)\out32
 
60 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
61 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
62 !message Using 'x64' platform for OpenSSL...
63 SSLCONFIG = VC-WIN64A no-asm
64 SSLSETUP = ms\do_win64a.bat
@@ -101,10 +105,21 @@
101 INCL = $(INCL) /I$(TCLINCDIR)
102 !endif
103
104 CFLAGS = /nologo
105 LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
 
 
 
 
 
 
 
 
 
 
 
106
107 !ifdef DEBUG
108 CFLAGS = $(CFLAGS) /Zi /MTd /Od
109 LDFLAGS = $(LDFLAGS) /DEBUG
110 !else
@@ -423,21 +438,29 @@
423
424 all: $(OX) $(APPNAME)
425
426 zlib:
427 @echo Building zlib from "$(ZLIBDIR)"...
 
 
 
428 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) && popd
 
429
430 !ifdef FOSSIL_ENABLE_SSL
431 openssl:
432 @echo Building OpenSSL from "$(SSLDIR)"...
433 !if "$(PERLDIR)" != ""
434 @set PATH=$(PERLDIR);$(PATH)
435 !endif
436 @pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
437 @pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
 
 
 
438 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
 
439 !endif
440
441 !ifndef FOSSIL_ENABLE_MINIZ
442 APPTARGETS = $(APPTARGETS) zlib
443 !endif
444
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -29,10 +29,13 @@
29 PERLDIR = C:\Perl\bin
30 PERL = perl.exe
31
32 # Uncomment to enable debug symbols
33 # DEBUG = 1
34
35 # Uncomment to support Windows XP with Visual Studio 201x
36 # FOSSIL_ENABLE_WINXP = 1
37
38 # Uncomment to enable JSON API
39 # FOSSIL_ENABLE_JSON = 1
40
41 # Uncomment to enable miniz usage
@@ -52,13 +55,14 @@
55
56 # Uncomment to enable Tcl support
57 # FOSSIL_ENABLE_TCL = 1
58
59 !ifdef FOSSIL_ENABLE_SSL
60 SSLDIR = $(B)\compat\openssl-1.0.1j
61 SSLINCDIR = $(SSLDIR)\inc32
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66 !message Using 'x64' platform for OpenSSL...
67 SSLCONFIG = VC-WIN64A no-asm
68 SSLSETUP = ms\do_win64a.bat
@@ -101,10 +105,21 @@
105 INCL = $(INCL) /I$(TCLINCDIR)
106 !endif
107
108 CFLAGS = /nologo
109 LDFLAGS = /NODEFAULTLIB:msvcrt /MANIFEST:NO
110
111 !ifdef FOSSIL_ENABLE_WINXP
112 XPCFLAGS = $(XPCFLAGS) /D_USING_V110_SDK71_=1
113 CFLAGS = $(CFLAGS) $(XPCFLAGS)
114 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
115 XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.02
116 !else
117 XPLDFLAGS = $(XPLDFLAGS) /SUBSYSTEM:CONSOLE,5.01
118 !endif
119 LDFLAGS = $(LDFLAGS) $(XPLDFLAGS)
120 !endif
121
122 !ifdef DEBUG
123 CFLAGS = $(CFLAGS) /Zi /MTd /Od
124 LDFLAGS = $(LDFLAGS) /DEBUG
125 !else
@@ -423,21 +438,29 @@
438
439 all: $(OX) $(APPNAME)
440
441 zlib:
442 @echo Building zlib from "$(ZLIBDIR)"...
443 !ifdef FOSSIL_ENABLE_WINXP
444 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) "CC=cl $(XPCFLAGS)" "LD=link $(XPLDFLAGS)" && popd
445 !else
446 @pushd "$(ZLIBDIR)" && $(MAKE) /f win32\Makefile.msc $(ZLIB) && popd
447 !endif
448
449 !ifdef FOSSIL_ENABLE_SSL
450 openssl:
451 @echo Building OpenSSL from "$(SSLDIR)"...
452 !if "$(PERLDIR)" != ""
453 @set PATH=$(PERLDIR);$(PATH)
454 !endif
455 @pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
456 @pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
457 !ifdef FOSSIL_ENABLE_WINXP
458 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
459 !else
460 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
461 !endif
462 !endif
463
464 !ifndef FOSSIL_ENABLE_MINIZ
465 APPTARGETS = $(APPTARGETS) zlib
466 !endif
467
--- win/buildmsvc.bat
+++ win/buildmsvc.bat
@@ -192,15 +192,30 @@
192192
IF ERRORLEVEL 1 (
193193
ECHO Could not change to directory "%ROOT%\msvcbld".
194194
GOTO errors
195195
)
196196
197
+REM
198
+REM NOTE: If requested, setup the build environment to refer to the Windows
199
+REM SDK v7.1A, which is required if the binaries are being built with
200
+REM Visual Studio 201x and need to work on Windows XP.
201
+REM
202
+IF DEFINED USE_V110SDK71A (
203
+ %_AECHO% Forcing use of the Windows SDK v7.1A...
204
+ CALL :fn_UseV110Sdk71A
205
+)
206
+
207
+%_VECHO% Path = '%PATH%'
208
+%_VECHO% Include = '%INCLUDE%'
209
+%_VECHO% Lib = '%LIB%'
210
+%_VECHO% NmakeArgs = '%NMAKE_ARGS%'
211
+
197212
REM
198213
REM NOTE: Attempt to execute NMAKE for the Fossil MSVC makefile, passing
199214
REM anything extra from our command line along (e.g. extra options).
200215
REM
201
-%__ECHO% nmake /f "%TOOLS%\Makefile.msc" %*
216
+%__ECHO% nmake /f "%TOOLS%\Makefile.msc" %NMAKE_ARGS% %*
202217
203218
IF ERRORLEVEL 1 (
204219
GOTO errors
205220
)
206221
@@ -213,10 +228,35 @@
213228
ECHO Could not restore directory.
214229
GOTO errors
215230
)
216231
217232
GOTO no_errors
233
+
234
+:fn_UseV110Sdk71A
235
+ IF "%PROCESSOR_ARCHITECTURE%" == "x86" GOTO set_v110Sdk71A_x86
236
+ SET PFILES_SDK71A=%ProgramFiles(x86)%
237
+ GOTO set_v110Sdk71A_done
238
+ :set_v110Sdk71A_x86
239
+ SET PFILES_SDK71A=%ProgramFiles%
240
+ :set_v110Sdk71A_done
241
+ SET PATH=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Bin;%PATH%
242
+ SET INCLUDE=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Include;%INCLUDE%
243
+ IF "%PLATFORM%" == "x64" (
244
+ SET LIB=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Lib\x64;%LIB%
245
+ ) ELSE (
246
+ SET LIB=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Lib;%LIB%
247
+ )
248
+ CALL :fn_UnsetVariable PFILES_SDK71A
249
+ SET NMAKE_ARGS=%NMAKE_ARGS% FOSSIL_ENABLE_WINXP=1
250
+ GOTO :EOF
251
+
252
+:fn_UnsetVariable
253
+ IF NOT "%1" == "" (
254
+ SET %1=
255
+ CALL :fn_ResetErrorLevel
256
+ )
257
+ GOTO :EOF
218258
219259
:fn_ResetErrorLevel
220260
VERIFY > NUL
221261
GOTO :EOF
222262
223263
--- win/buildmsvc.bat
+++ win/buildmsvc.bat
@@ -192,15 +192,30 @@
192 IF ERRORLEVEL 1 (
193 ECHO Could not change to directory "%ROOT%\msvcbld".
194 GOTO errors
195 )
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197 REM
198 REM NOTE: Attempt to execute NMAKE for the Fossil MSVC makefile, passing
199 REM anything extra from our command line along (e.g. extra options).
200 REM
201 %__ECHO% nmake /f "%TOOLS%\Makefile.msc" %*
202
203 IF ERRORLEVEL 1 (
204 GOTO errors
205 )
206
@@ -213,10 +228,35 @@
213 ECHO Could not restore directory.
214 GOTO errors
215 )
216
217 GOTO no_errors
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
219 :fn_ResetErrorLevel
220 VERIFY > NUL
221 GOTO :EOF
222
223
--- win/buildmsvc.bat
+++ win/buildmsvc.bat
@@ -192,15 +192,30 @@
192 IF ERRORLEVEL 1 (
193 ECHO Could not change to directory "%ROOT%\msvcbld".
194 GOTO errors
195 )
196
197 REM
198 REM NOTE: If requested, setup the build environment to refer to the Windows
199 REM SDK v7.1A, which is required if the binaries are being built with
200 REM Visual Studio 201x and need to work on Windows XP.
201 REM
202 IF DEFINED USE_V110SDK71A (
203 %_AECHO% Forcing use of the Windows SDK v7.1A...
204 CALL :fn_UseV110Sdk71A
205 )
206
207 %_VECHO% Path = '%PATH%'
208 %_VECHO% Include = '%INCLUDE%'
209 %_VECHO% Lib = '%LIB%'
210 %_VECHO% NmakeArgs = '%NMAKE_ARGS%'
211
212 REM
213 REM NOTE: Attempt to execute NMAKE for the Fossil MSVC makefile, passing
214 REM anything extra from our command line along (e.g. extra options).
215 REM
216 %__ECHO% nmake /f "%TOOLS%\Makefile.msc" %NMAKE_ARGS% %*
217
218 IF ERRORLEVEL 1 (
219 GOTO errors
220 )
221
@@ -213,10 +228,35 @@
228 ECHO Could not restore directory.
229 GOTO errors
230 )
231
232 GOTO no_errors
233
234 :fn_UseV110Sdk71A
235 IF "%PROCESSOR_ARCHITECTURE%" == "x86" GOTO set_v110Sdk71A_x86
236 SET PFILES_SDK71A=%ProgramFiles(x86)%
237 GOTO set_v110Sdk71A_done
238 :set_v110Sdk71A_x86
239 SET PFILES_SDK71A=%ProgramFiles%
240 :set_v110Sdk71A_done
241 SET PATH=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Bin;%PATH%
242 SET INCLUDE=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Include;%INCLUDE%
243 IF "%PLATFORM%" == "x64" (
244 SET LIB=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Lib\x64;%LIB%
245 ) ELSE (
246 SET LIB=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Lib;%LIB%
247 )
248 CALL :fn_UnsetVariable PFILES_SDK71A
249 SET NMAKE_ARGS=%NMAKE_ARGS% FOSSIL_ENABLE_WINXP=1
250 GOTO :EOF
251
252 :fn_UnsetVariable
253 IF NOT "%1" == "" (
254 SET %1=
255 CALL :fn_ResetErrorLevel
256 )
257 GOTO :EOF
258
259 :fn_ResetErrorLevel
260 VERIFY > NUL
261 GOTO :EOF
262
263
+1 -1
--- www/build.wiki
+++ www/build.wiki
@@ -122,11 +122,11 @@
122122
the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
123123
first <a href="https://www.openssl.org/source/">download the official
124124
source code for OpenSSL</a> and extract it to an appropriately named
125125
"<b>openssl-X.Y.ZA</b>" subdirectory within the local
126126
[/tree?ci=trunk&name=compat | compat] directory (e.g.
127
-"<b>compat/openssl-1.0.1i</b>"), then make sure that some recent
127
+"<b>compat/openssl-1.0.1j</b>"), then make sure that some recent
128128
<a href="http://www.perl.org/">Perl</a> binaries are installed locally,
129129
and finally run one of the following commands:
130130
<blockquote><pre>
131131
nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
132132
</pre></blockquote>
133133
--- www/build.wiki
+++ www/build.wiki
@@ -122,11 +122,11 @@
122 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
123 first <a href="https://www.openssl.org/source/">download the official
124 source code for OpenSSL</a> and extract it to an appropriately named
125 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
126 [/tree?ci=trunk&name=compat | compat] directory (e.g.
127 "<b>compat/openssl-1.0.1i</b>"), then make sure that some recent
128 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
129 and finally run one of the following commands:
130 <blockquote><pre>
131 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
132 </pre></blockquote>
133
--- www/build.wiki
+++ www/build.wiki
@@ -122,11 +122,11 @@
122 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
123 first <a href="https://www.openssl.org/source/">download the official
124 source code for OpenSSL</a> and extract it to an appropriately named
125 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
126 [/tree?ci=trunk&name=compat | compat] directory (e.g.
127 "<b>compat/openssl-1.0.1j</b>"), then make sure that some recent
128 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
129 and finally run one of the following commands:
130 <blockquote><pre>
131 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
132 </pre></blockquote>
133

Keyboard Shortcuts

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