Fossil SCM

Merge in latest from trunk.

andybradford 2013-11-21 01:47 UTC hide-diff-on-vdiff_page merge
Commit e2929a4ba165b69135eb080d6dcc6d37024133fe
-5
--- src/add.c
+++ src/add.c
@@ -316,19 +316,14 @@
316316
**
317317
** See also: addremove, add
318318
*/
319319
void delete_cmd(void){
320320
int i;
321
- int vid;
322321
Stmt loop;
323322
324323
capture_case_sensitive_option();
325324
db_must_be_within_tree();
326
- vid = db_lget_int("checkout", 0);
327
- if( vid==0 ){
328
- fossil_fatal("no checkout to remove from");
329
- }
330325
db_begin_transaction();
331326
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
332327
filename_collation());
333328
for(i=2; i<g.argc; i++){
334329
Blob treeName;
335330
--- src/add.c
+++ src/add.c
@@ -316,19 +316,14 @@
316 **
317 ** See also: addremove, add
318 */
319 void delete_cmd(void){
320 int i;
321 int vid;
322 Stmt loop;
323
324 capture_case_sensitive_option();
325 db_must_be_within_tree();
326 vid = db_lget_int("checkout", 0);
327 if( vid==0 ){
328 fossil_fatal("no checkout to remove from");
329 }
330 db_begin_transaction();
331 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
332 filename_collation());
333 for(i=2; i<g.argc; i++){
334 Blob treeName;
335
--- src/add.c
+++ src/add.c
@@ -316,19 +316,14 @@
316 **
317 ** See also: addremove, add
318 */
319 void delete_cmd(void){
320 int i;
 
321 Stmt loop;
322
323 capture_case_sensitive_option();
324 db_must_be_within_tree();
 
 
 
 
325 db_begin_transaction();
326 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
327 filename_collation());
328 for(i=2; i<g.argc; i++){
329 Blob treeName;
330
+21 -29
--- src/db.c
+++ src/db.c
@@ -1805,15 +1805,10 @@
18051805
char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
18061806
char *z = 0;
18071807
if( g.repositoryOpen ){
18081808
z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
18091809
}
1810
- if( z==0 && g.zConfigDbName ){
1811
- db_swap_connections();
1812
- z = db_text(0, "SELECT mtime FROM global_config WHERE name=%Q", zName);
1813
- db_swap_connections();
1814
- }
18151810
if( z==0 ){
18161811
z = zDefault;
18171812
}else if( zFormat!=0 ){
18181813
z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
18191814
}
@@ -2000,13 +1995,14 @@
20001995
** --nested Allow opening a repository inside an opened checkout
20011996
**
20021997
** See also: close
20031998
*/
20041999
void cmd_open(void){
2005
- int vid;
20062000
int keepFlag;
20072001
int allowNested;
2002
+ char **oldArgv;
2003
+ int oldArgc;
20082004
static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
20092005
20102006
url_proxy_options();
20112007
keepFlag = find_option("keep",0,0)!=0;
20122008
allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2025,29 @@
20292025
(char*)0);
20302026
db_delete_on_failure(LOCALDB_NAME);
20312027
db_open_local(0);
20322028
db_lset("repository", g.argv[2]);
20332029
db_record_repository_filename(g.argv[2]);
2034
- vid = db_int(0, "SELECT pid FROM plink y"
2035
- " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
2036
- if( vid==0 ){
2037
- db_lset_int("checkout", 1);
2038
- }else{
2039
- char **oldArgv = g.argv;
2040
- int oldArgc = g.argc;
2041
- db_lset_int("checkout", vid);
2042
- azNewArgv[0] = g.argv[0];
2043
- g.argv = azNewArgv;
2044
- g.argc = 3;
2045
- if( oldArgc==4 ){
2046
- azNewArgv[g.argc-1] = oldArgv[3];
2047
- }else{
2048
- azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2049
- }
2050
- if( keepFlag ){
2051
- azNewArgv[g.argc++] = "--keep";
2052
- }
2053
- checkout_cmd();
2054
- g.argc = 2;
2055
- info_cmd();
2056
- }
2030
+ db_lset_int("checkout", 0);
2031
+ oldArgv = g.argv;
2032
+ oldArgc = g.argc;
2033
+ azNewArgv[0] = g.argv[0];
2034
+ g.argv = azNewArgv;
2035
+ g.argc = 3;
2036
+ if( oldArgc==4 ){
2037
+ azNewArgv[g.argc-1] = oldArgv[3];
2038
+ }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2039
+ azNewArgv[g.argc-1] = "--latest";
2040
+ }else{
2041
+ azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2042
+ }
2043
+ if( keepFlag ){
2044
+ azNewArgv[g.argc++] = "--keep";
2045
+ }
2046
+ checkout_cmd();
2047
+ g.argc = 2;
2048
+ info_cmd();
20572049
}
20582050
20592051
/*
20602052
** Print the value of a setting named zName
20612053
*/
20622054
--- src/db.c
+++ src/db.c
@@ -1805,15 +1805,10 @@
1805 char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
1806 char *z = 0;
1807 if( g.repositoryOpen ){
1808 z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
1809 }
1810 if( z==0 && g.zConfigDbName ){
1811 db_swap_connections();
1812 z = db_text(0, "SELECT mtime FROM global_config WHERE name=%Q", zName);
1813 db_swap_connections();
1814 }
1815 if( z==0 ){
1816 z = zDefault;
1817 }else if( zFormat!=0 ){
1818 z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
1819 }
@@ -2000,13 +1995,14 @@
2000 ** --nested Allow opening a repository inside an opened checkout
2001 **
2002 ** See also: close
2003 */
2004 void cmd_open(void){
2005 int vid;
2006 int keepFlag;
2007 int allowNested;
 
 
2008 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
2009
2010 url_proxy_options();
2011 keepFlag = find_option("keep",0,0)!=0;
2012 allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2025,29 @@
2029 (char*)0);
2030 db_delete_on_failure(LOCALDB_NAME);
2031 db_open_local(0);
2032 db_lset("repository", g.argv[2]);
2033 db_record_repository_filename(g.argv[2]);
2034 vid = db_int(0, "SELECT pid FROM plink y"
2035 " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
2036 if( vid==0 ){
2037 db_lset_int("checkout", 1);
2038 }else{
2039 char **oldArgv = g.argv;
2040 int oldArgc = g.argc;
2041 db_lset_int("checkout", vid);
2042 azNewArgv[0] = g.argv[0];
2043 g.argv = azNewArgv;
2044 g.argc = 3;
2045 if( oldArgc==4 ){
2046 azNewArgv[g.argc-1] = oldArgv[3];
2047 }else{
2048 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2049 }
2050 if( keepFlag ){
2051 azNewArgv[g.argc++] = "--keep";
2052 }
2053 checkout_cmd();
2054 g.argc = 2;
2055 info_cmd();
2056 }
2057 }
2058
2059 /*
2060 ** Print the value of a setting named zName
2061 */
2062
--- src/db.c
+++ src/db.c
@@ -1805,15 +1805,10 @@
1805 char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
1806 char *z = 0;
1807 if( g.repositoryOpen ){
1808 z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
1809 }
 
 
 
 
 
1810 if( z==0 ){
1811 z = zDefault;
1812 }else if( zFormat!=0 ){
1813 z = db_text(0, "SELECT strftime(%Q,%Q,'unixepoch');", zFormat, z);
1814 }
@@ -2000,13 +1995,14 @@
1995 ** --nested Allow opening a repository inside an opened checkout
1996 **
1997 ** See also: close
1998 */
1999 void cmd_open(void){
 
2000 int keepFlag;
2001 int allowNested;
2002 char **oldArgv;
2003 int oldArgc;
2004 static char *azNewArgv[] = { 0, "checkout", "--prompt", 0, 0, 0 };
2005
2006 url_proxy_options();
2007 keepFlag = find_option("keep",0,0)!=0;
2008 allowNested = find_option("nested",0,0)!=0;
@@ -2029,33 +2025,29 @@
2025 (char*)0);
2026 db_delete_on_failure(LOCALDB_NAME);
2027 db_open_local(0);
2028 db_lset("repository", g.argv[2]);
2029 db_record_repository_filename(g.argv[2]);
2030 db_lset_int("checkout", 0);
2031 oldArgv = g.argv;
2032 oldArgc = g.argc;
2033 azNewArgv[0] = g.argv[0];
2034 g.argv = azNewArgv;
2035 g.argc = 3;
2036 if( oldArgc==4 ){
2037 azNewArgv[g.argc-1] = oldArgv[3];
2038 }else if( !db_exists("SELECT 1 FROM event WHERE type='ci'") ){
2039 azNewArgv[g.argc-1] = "--latest";
2040 }else{
2041 azNewArgv[g.argc-1] = db_get("main-branch", "trunk");
2042 }
2043 if( keepFlag ){
2044 azNewArgv[g.argc++] = "--keep";
2045 }
2046 checkout_cmd();
2047 g.argc = 2;
2048 info_cmd();
 
 
 
 
2049 }
2050
2051 /*
2052 ** Print the value of a setting named zName
2053 */
2054
+26 -9
--- src/diff.c
+++ src/diff.c
@@ -2123,10 +2123,11 @@
21232123
return c;
21242124
}
21252125
21262126
/*
21272127
** WEBPAGE: annotate
2128
+** WEBPAGE: blame
21282129
**
21292130
** Query parameters:
21302131
**
21312132
** checkin=ID The manifest ID at which to start the annotation
21322133
** filename=FILENAME The filename.
@@ -2145,10 +2146,11 @@
21452146
const char *zCI; /* The check-in containing zFilename */
21462147
Annotator ann;
21472148
HQuery url;
21482149
struct AnnVers *p;
21492150
unsigned clr1, clr2, clr;
2151
+ int bBlame = g.zPath[0]=='b';/* True for BLAME output. False for ANNOTATE. */
21502152
21512153
/* Gather query parameters */
21522154
showLog = atoi(PD("log","1"));
21532155
login_check_credentials();
21542156
if( !g.perm.Read ){ login_needed(); return; }
@@ -2251,20 +2253,35 @@
22512253
char *z = (char*)ann.aOrig[i].z;
22522254
int n = ann.aOrig[i].n;
22532255
char zPrefix[300];
22542256
z[n] = 0;
22552257
if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2256
- if( iVers>=0 ){
2257
- struct AnnVers *p = ann.aVers+iVers;
2258
- char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2259
- sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2260
- "<span style='background-color:%s'>"
2261
- "%s%.10s</a> %s</span> %4d:",
2262
- p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2263
- fossil_free(zLink);
2258
+
2259
+ if( bBlame ){
2260
+ if( iVers>=0 ){
2261
+ struct AnnVers *p = ann.aVers+iVers;
2262
+ char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2263
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2264
+ "<span style='background-color:%s'>"
2265
+ "%s%.10s</a> %s</span> %13.13s:",
2266
+ p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
2267
+ fossil_free(zLink);
2268
+ }else{
2269
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s", "");
2270
+ }
22642271
}else{
2265
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2272
+ if( iVers>=0 ){
2273
+ struct AnnVers *p = ann.aVers+iVers;
2274
+ char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2275
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2276
+ "<span style='background-color:%s'>"
2277
+ "%s%.10s</a> %s</span> %4d:",
2278
+ p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2279
+ fossil_free(zLink);
2280
+ }else{
2281
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2282
+ }
22662283
}
22672284
@ %s(zPrefix) %h(z)
22682285
22692286
}
22702287
@ </pre>
22712288
--- src/diff.c
+++ src/diff.c
@@ -2123,10 +2123,11 @@
2123 return c;
2124 }
2125
2126 /*
2127 ** WEBPAGE: annotate
 
2128 **
2129 ** Query parameters:
2130 **
2131 ** checkin=ID The manifest ID at which to start the annotation
2132 ** filename=FILENAME The filename.
@@ -2145,10 +2146,11 @@
2145 const char *zCI; /* The check-in containing zFilename */
2146 Annotator ann;
2147 HQuery url;
2148 struct AnnVers *p;
2149 unsigned clr1, clr2, clr;
 
2150
2151 /* Gather query parameters */
2152 showLog = atoi(PD("log","1"));
2153 login_check_credentials();
2154 if( !g.perm.Read ){ login_needed(); return; }
@@ -2251,20 +2253,35 @@
2251 char *z = (char*)ann.aOrig[i].z;
2252 int n = ann.aOrig[i].n;
2253 char zPrefix[300];
2254 z[n] = 0;
2255 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2256 if( iVers>=0 ){
2257 struct AnnVers *p = ann.aVers+iVers;
2258 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2259 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2260 "<span style='background-color:%s'>"
2261 "%s%.10s</a> %s</span> %4d:",
2262 p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2263 fossil_free(zLink);
 
 
 
 
 
2264 }else{
2265 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
 
 
 
 
 
 
 
 
 
 
2266 }
2267 @ %s(zPrefix) %h(z)
2268
2269 }
2270 @ </pre>
2271
--- src/diff.c
+++ src/diff.c
@@ -2123,10 +2123,11 @@
2123 return c;
2124 }
2125
2126 /*
2127 ** WEBPAGE: annotate
2128 ** WEBPAGE: blame
2129 **
2130 ** Query parameters:
2131 **
2132 ** checkin=ID The manifest ID at which to start the annotation
2133 ** filename=FILENAME The filename.
@@ -2145,10 +2146,11 @@
2146 const char *zCI; /* The check-in containing zFilename */
2147 Annotator ann;
2148 HQuery url;
2149 struct AnnVers *p;
2150 unsigned clr1, clr2, clr;
2151 int bBlame = g.zPath[0]=='b';/* True for BLAME output. False for ANNOTATE. */
2152
2153 /* Gather query parameters */
2154 showLog = atoi(PD("log","1"));
2155 login_check_credentials();
2156 if( !g.perm.Read ){ login_needed(); return; }
@@ -2251,20 +2253,35 @@
2253 char *z = (char*)ann.aOrig[i].z;
2254 int n = ann.aOrig[i].n;
2255 char zPrefix[300];
2256 z[n] = 0;
2257 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2258
2259 if( bBlame ){
2260 if( iVers>=0 ){
2261 struct AnnVers *p = ann.aVers+iVers;
2262 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2263 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2264 "<span style='background-color:%s'>"
2265 "%s%.10s</a> %s</span> %13.13s:",
2266 p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
2267 fossil_free(zLink);
2268 }else{
2269 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s", "");
2270 }
2271 }else{
2272 if( iVers>=0 ){
2273 struct AnnVers *p = ann.aVers+iVers;
2274 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2275 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2276 "<span style='background-color:%s'>"
2277 "%s%.10s</a> %s</span> %4d:",
2278 p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2279 fossil_free(zLink);
2280 }else{
2281 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2282 }
2283 }
2284 @ %s(zPrefix) %h(z)
2285
2286 }
2287 @ </pre>
2288
+5 -3
--- src/finfo.c
+++ src/finfo.c
@@ -463,16 +463,18 @@
463463
@ %w(zCom) (user:
464464
hyperlink_to_user(zUser, zDate, "");
465465
@ branch: %h(zBr))
466466
if( g.perm.Hyperlink && zUuid ){
467467
const char *z = zFilename;
468
+ @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
469
+ @ [annotate]</a>
470
+ @ %z(href("%R/blame?checkin=%S&filename=%h",zCkin,z))
471
+ @ [blame]</a>
472
+ @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
468473
if( fpid ){
469474
@ %z(href("%R/fdiff?v1=%S&v2=%S&sbs=1",zPUuid,zUuid))[diff]</a>
470475
}
471
- @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
472
- @ [annotate]</a>
473
- @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
474476
}
475477
if( fDebug & FINFO_DEBUG_MLINK ){
476478
int srcid = db_int(0, "SELECT srcid FROM delta WHERE rid=%d", frid);
477479
int sz = db_int(0, "SELECT length(content) FROM blob WHERE rid=%d", frid);
478480
@ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
479481
--- src/finfo.c
+++ src/finfo.c
@@ -463,16 +463,18 @@
463 @ %w(zCom) (user:
464 hyperlink_to_user(zUser, zDate, "");
465 @ branch: %h(zBr))
466 if( g.perm.Hyperlink && zUuid ){
467 const char *z = zFilename;
 
 
 
 
 
468 if( fpid ){
469 @ %z(href("%R/fdiff?v1=%S&v2=%S&sbs=1",zPUuid,zUuid))[diff]</a>
470 }
471 @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
472 @ [annotate]</a>
473 @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
474 }
475 if( fDebug & FINFO_DEBUG_MLINK ){
476 int srcid = db_int(0, "SELECT srcid FROM delta WHERE rid=%d", frid);
477 int sz = db_int(0, "SELECT length(content) FROM blob WHERE rid=%d", frid);
478 @ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
479
--- src/finfo.c
+++ src/finfo.c
@@ -463,16 +463,18 @@
463 @ %w(zCom) (user:
464 hyperlink_to_user(zUser, zDate, "");
465 @ branch: %h(zBr))
466 if( g.perm.Hyperlink && zUuid ){
467 const char *z = zFilename;
468 @ %z(href("%R/annotate?checkin=%S&filename=%h",zCkin,z))
469 @ [annotate]</a>
470 @ %z(href("%R/blame?checkin=%S&filename=%h",zCkin,z))
471 @ [blame]</a>
472 @ %z(href("%R/timeline?n=200&uf=%S",zUuid))[checkins&nbsp;using]</a>
473 if( fpid ){
474 @ %z(href("%R/fdiff?v1=%S&v2=%S&sbs=1",zPUuid,zUuid))[diff]</a>
475 }
 
 
 
476 }
477 if( fDebug & FINFO_DEBUG_MLINK ){
478 int srcid = db_int(0, "SELECT srcid FROM delta WHERE rid=%d", frid);
479 int sz = db_int(0, "SELECT length(content) FROM blob WHERE rid=%d", frid);
480 @ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
481
+3 -1
--- src/info.c
+++ src/info.c
@@ -1133,13 +1133,15 @@
11331133
@ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
11341134
}
11351135
@ - %!w(zCom) (user:
11361136
hyperlink_to_user(zUser,zDate,")");
11371137
if( g.perm.Hyperlink ){
1138
+ @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
11381139
@ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
11391140
@ [annotate]</a>
1140
- @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
1141
+ @ %z(href("%R/blame?checkin=%S&filename=%T",zVers,zName))
1142
+ @ [blame]</a>
11411143
}
11421144
cnt++;
11431145
if( pDownloadName && blob_size(pDownloadName)==0 ){
11441146
blob_append(pDownloadName, zName, -1);
11451147
}
11461148
--- src/info.c
+++ src/info.c
@@ -1133,13 +1133,15 @@
1133 @ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
1134 }
1135 @ - %!w(zCom) (user:
1136 hyperlink_to_user(zUser,zDate,")");
1137 if( g.perm.Hyperlink ){
 
1138 @ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
1139 @ [annotate]</a>
1140 @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
 
1141 }
1142 cnt++;
1143 if( pDownloadName && blob_size(pDownloadName)==0 ){
1144 blob_append(pDownloadName, zName, -1);
1145 }
1146
--- src/info.c
+++ src/info.c
@@ -1133,13 +1133,15 @@
1133 @ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
1134 }
1135 @ - %!w(zCom) (user:
1136 hyperlink_to_user(zUser,zDate,")");
1137 if( g.perm.Hyperlink ){
1138 @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
1139 @ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
1140 @ [annotate]</a>
1141 @ %z(href("%R/blame?checkin=%S&filename=%T",zVers,zName))
1142 @ [blame]</a>
1143 }
1144 cnt++;
1145 if( pDownloadName && blob_size(pDownloadName)==0 ){
1146 blob_append(pDownloadName, zName, -1);
1147 }
1148
+3 -1
--- src/info.c
+++ src/info.c
@@ -1133,13 +1133,15 @@
11331133
@ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
11341134
}
11351135
@ - %!w(zCom) (user:
11361136
hyperlink_to_user(zUser,zDate,")");
11371137
if( g.perm.Hyperlink ){
1138
+ @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
11381139
@ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
11391140
@ [annotate]</a>
1140
- @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
1141
+ @ %z(href("%R/blame?checkin=%S&filename=%T",zVers,zName))
1142
+ @ [blame]</a>
11411143
}
11421144
cnt++;
11431145
if( pDownloadName && blob_size(pDownloadName)==0 ){
11441146
blob_append(pDownloadName, zName, -1);
11451147
}
11461148
--- src/info.c
+++ src/info.c
@@ -1133,13 +1133,15 @@
1133 @ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
1134 }
1135 @ - %!w(zCom) (user:
1136 hyperlink_to_user(zUser,zDate,")");
1137 if( g.perm.Hyperlink ){
 
1138 @ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
1139 @ [annotate]</a>
1140 @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
 
1141 }
1142 cnt++;
1143 if( pDownloadName && blob_size(pDownloadName)==0 ){
1144 blob_append(pDownloadName, zName, -1);
1145 }
1146
--- src/info.c
+++ src/info.c
@@ -1133,13 +1133,15 @@
1133 @ on branch %z(href("%R/timeline?r=%T",zBr))%h(zBr)</a>
1134 }
1135 @ - %!w(zCom) (user:
1136 hyperlink_to_user(zUser,zDate,")");
1137 if( g.perm.Hyperlink ){
1138 @ %z(href("%R/finfo?name=%T&ci=%S",zName,zVers))[ancestry]</a>
1139 @ %z(href("%R/annotate?checkin=%S&filename=%T",zVers,zName))
1140 @ [annotate]</a>
1141 @ %z(href("%R/blame?checkin=%S&filename=%T",zVers,zName))
1142 @ [blame]</a>
1143 }
1144 cnt++;
1145 if( pDownloadName && blob_size(pDownloadName)==0 ){
1146 blob_append(pDownloadName, zName, -1);
1147 }
1148
+1
--- src/main.c
+++ src/main.c
@@ -551,10 +551,11 @@
551551
#endif
552552
{
553553
const char *zCmdName = "unknown";
554554
int idx;
555555
int rc;
556
+ sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
556557
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
557558
memset(&g, 0, sizeof(g));
558559
g.now = time(0);
559560
g.httpHeader = empty_blob;
560561
#ifdef FOSSIL_ENABLE_JSON
561562
--- src/main.c
+++ src/main.c
@@ -551,10 +551,11 @@
551 #endif
552 {
553 const char *zCmdName = "unknown";
554 int idx;
555 int rc;
 
556 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
557 memset(&g, 0, sizeof(g));
558 g.now = time(0);
559 g.httpHeader = empty_blob;
560 #ifdef FOSSIL_ENABLE_JSON
561
--- src/main.c
+++ src/main.c
@@ -551,10 +551,11 @@
551 #endif
552 {
553 const char *zCmdName = "unknown";
554 int idx;
555 int rc;
556 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
557 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
558 memset(&g, 0, sizeof(g));
559 g.now = time(0);
560 g.httpHeader = empty_blob;
561 #ifdef FOSSIL_ENABLE_JSON
562
+1 -1
--- src/main.mk
+++ src/main.mk
@@ -1160,11 +1160,11 @@
11601160
$(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
11611161
$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
11621162
11631163
$(OBJDIR)/zip.h: $(OBJDIR)/headers
11641164
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1165
- $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1165
+ $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
11661166
11671167
$(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
11681168
$(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
11691169
11701170
$(OBJDIR)/th.o: $(SRCDIR)/th.c
11711171
--- src/main.mk
+++ src/main.mk
@@ -1160,11 +1160,11 @@
1160 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1161 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1162
1163 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1164 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1165 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1166
1167 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1168 $(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1169
1170 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1171
--- src/main.mk
+++ src/main.mk
@@ -1160,11 +1160,11 @@
1160 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1161 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1162
1163 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1164 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1165 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1166
1167 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1168 $(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dsqlite3_strglob=strglob -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
1169
1170 $(OBJDIR)/th.o: $(SRCDIR)/th.c
1171
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -288,11 +288,13 @@
288288
289289
writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
290290
set opt {-DSQLITE_OMIT_LOAD_EXTENSION=1}
291291
append opt " -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4"
292292
#append opt " -DSQLITE_ENABLE_FTS3=1"
293
-append opt " -DSQLITE_ENABLE_STAT3"
293
+#append opt " -DSQLITE_ENABLE_STAT4"
294
+append opt " -DSQLITE_OMIT_DEPRECATED"
295
+append opt " -DSQLITE_ENABLE_EXPLAIN_COMMENTS"
294296
append opt " -Dlocaltime=fossil_localtime"
295297
append opt " -DSQLITE_ENABLE_LOCKING_STYLE=0"
296298
append opt " -DSQLITE_WIN32_NO_ANSI"
297299
set SQLITE_OPTIONS $opt
298300
writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
@@ -772,10 +774,12 @@
772774
773775
774776
writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
775777
set opt $SQLITE_OPTIONS
776778
append opt " -D_HAVE_SQLITE_CONFIG_H"
779
+append opt " -DSQLITE_USE_MALLOC_H"
780
+append opt " -DSQLITE_USE_MSIZE"
777781
writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
778782
779783
set opt {}
780784
writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
781785
writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
782786
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -288,11 +288,13 @@
288
289 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
290 set opt {-DSQLITE_OMIT_LOAD_EXTENSION=1}
291 append opt " -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4"
292 #append opt " -DSQLITE_ENABLE_FTS3=1"
293 append opt " -DSQLITE_ENABLE_STAT3"
 
 
294 append opt " -Dlocaltime=fossil_localtime"
295 append opt " -DSQLITE_ENABLE_LOCKING_STYLE=0"
296 append opt " -DSQLITE_WIN32_NO_ANSI"
297 set SQLITE_OPTIONS $opt
298 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
@@ -772,10 +774,12 @@
772
773
774 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
775 set opt $SQLITE_OPTIONS
776 append opt " -D_HAVE_SQLITE_CONFIG_H"
 
 
777 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
778
779 set opt {}
780 writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
781 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
782
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -288,11 +288,13 @@
288
289 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
290 set opt {-DSQLITE_OMIT_LOAD_EXTENSION=1}
291 append opt " -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4"
292 #append opt " -DSQLITE_ENABLE_FTS3=1"
293 #append opt " -DSQLITE_ENABLE_STAT4"
294 append opt " -DSQLITE_OMIT_DEPRECATED"
295 append opt " -DSQLITE_ENABLE_EXPLAIN_COMMENTS"
296 append opt " -Dlocaltime=fossil_localtime"
297 append opt " -DSQLITE_ENABLE_LOCKING_STYLE=0"
298 append opt " -DSQLITE_WIN32_NO_ANSI"
299 set SQLITE_OPTIONS $opt
300 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
@@ -772,10 +774,12 @@
774
775
776 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
777 set opt $SQLITE_OPTIONS
778 append opt " -D_HAVE_SQLITE_CONFIG_H"
779 append opt " -DSQLITE_USE_MALLOC_H"
780 append opt " -DSQLITE_USE_MSIZE"
781 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
782
783 set opt {}
784 writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
785 writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o\n"
786
+113 -2
--- src/shell.c
+++ src/shell.c
@@ -462,10 +462,13 @@
462462
const char *zDbFilename; /* name of the database file */
463463
char *zFreeOnClose; /* Filename to free when closing */
464464
const char *zVfs; /* Name of VFS to use */
465465
sqlite3_stmt *pStmt; /* Current statement if any. */
466466
FILE *pLog; /* Write log output here */
467
+ int *aiIndent; /* Array of indents used in MODE_Explain */
468
+ int nIndent; /* Size of array aiIndent[] */
469
+ int iIndent; /* Index of current op in aiIndent[] */
467470
};
468471
469472
/*
470473
** These are the allowed modes.
471474
*/
@@ -763,13 +766,18 @@
763766
if( i<ArraySize(p->actualWidth) ){
764767
w = p->actualWidth[i];
765768
}else{
766769
w = 10;
767770
}
768
- if( p->mode==MODE_Explain && azArg[i] &&
769
- strlen30(azArg[i])>w ){
771
+ if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
770772
w = strlen30(azArg[i]);
773
+ }
774
+ if( i==1 && p->aiIndent && p->pStmt ){
775
+ if( p->iIndent<p->nIndent ){
776
+ fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
777
+ }
778
+ p->iIndent++;
771779
}
772780
if( w<0 ){
773781
fprintf(p->out,"%*.*s%s",-w,-w,
774782
azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
775783
}else{
@@ -1138,10 +1146,105 @@
11381146
fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
11391147
}
11401148
11411149
return 0;
11421150
}
1151
+
1152
+/*
1153
+** Parameter azArray points to a zero-terminated array of strings. zStr
1154
+** points to a single nul-terminated string. Return non-zero if zStr
1155
+** is equal, according to strcmp(), to any of the strings in the array.
1156
+** Otherwise, return zero.
1157
+*/
1158
+static int str_in_array(const char *zStr, const char **azArray){
1159
+ int i;
1160
+ for(i=0; azArray[i]; i++){
1161
+ if( 0==strcmp(zStr, azArray[i]) ) return 1;
1162
+ }
1163
+ return 0;
1164
+}
1165
+
1166
+/*
1167
+** If compiled statement pSql appears to be an EXPLAIN statement, allocate
1168
+** and populate the callback_data.aiIndent[] array with the number of
1169
+** spaces each opcode should be indented before it is output.
1170
+**
1171
+** The indenting rules are:
1172
+**
1173
+** * For each "Next", "Prev", "VNext" or "VPrev" instruction, indent
1174
+** all opcodes that occur between the p2 jump destination and the opcode
1175
+** itself by 2 spaces.
1176
+**
1177
+** * For each "Goto", if the jump destination is earlier in the program
1178
+** and ends on one of:
1179
+** Yield SeekGt SeekLt RowSetRead
1180
+** then indent all opcodes between the earlier instruction
1181
+** and "Goto" by 2 spaces.
1182
+*/
1183
+static void explain_data_prepare(struct callback_data *p, sqlite3_stmt *pSql){
1184
+ const char *zSql; /* The text of the SQL statement */
1185
+ const char *z; /* Used to check if this is an EXPLAIN */
1186
+ int *abYield = 0; /* True if op is an OP_Yield */
1187
+ int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1188
+ int iOp; /* Index of operation in p->aiIndent[] */
1189
+
1190
+ const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext", 0 };
1191
+ const char *azYield[] = { "Yield", "SeekLt", "SeekGt", "RowSetRead", 0 };
1192
+ const char *azGoto[] = { "Goto", 0 };
1193
+
1194
+ /* Try to figure out if this is really an EXPLAIN statement. If this
1195
+ ** cannot be verified, return early. */
1196
+ zSql = sqlite3_sql(pSql);
1197
+ if( zSql==0 ) return;
1198
+ for(z=zSql; *z==' ' || *z=='\t' || *z=='\n' || *z=='\f' || *z=='\r'; z++);
1199
+ if( sqlite3_strnicmp(z, "explain", 7) ) return;
1200
+
1201
+ for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){
1202
+ int i;
1203
+ int iAddr = sqlite3_column_int(pSql, 0);
1204
+ const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
1205
+
1206
+ /* Set p2 to the P2 field of the current opcode. Then, assuming that
1207
+ ** p2 is an instruction address, set variable p2op to the index of that
1208
+ ** instruction in the aiIndent[] array. p2 and p2op may be different if
1209
+ ** the current instruction is part of a sub-program generated by an
1210
+ ** SQL trigger or foreign key. */
1211
+ int p2 = sqlite3_column_int(pSql, 3);
1212
+ int p2op = (p2 + (iOp-iAddr));
1213
+
1214
+ /* Grow the p->aiIndent array as required */
1215
+ if( iOp>=nAlloc ){
1216
+ nAlloc += 100;
1217
+ p->aiIndent = (int*)sqlite3_realloc(p->aiIndent, nAlloc*sizeof(int));
1218
+ abYield = (int*)sqlite3_realloc(abYield, nAlloc*sizeof(int));
1219
+ }
1220
+ abYield[iOp] = str_in_array(zOp, azYield);
1221
+ p->aiIndent[iOp] = 0;
1222
+ p->nIndent = iOp+1;
1223
+
1224
+ if( str_in_array(zOp, azNext) ){
1225
+ for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1226
+ }
1227
+ if( str_in_array(zOp, azGoto) && p2op<p->nIndent && abYield[p2op] ){
1228
+ for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1229
+ }
1230
+ }
1231
+
1232
+ p->iIndent = 0;
1233
+ sqlite3_free(abYield);
1234
+ sqlite3_reset(pSql);
1235
+}
1236
+
1237
+/*
1238
+** Free the array allocated by explain_data_prepare().
1239
+*/
1240
+static void explain_data_delete(struct callback_data *p){
1241
+ sqlite3_free(p->aiIndent);
1242
+ p->aiIndent = 0;
1243
+ p->nIndent = 0;
1244
+ p->iIndent = 0;
1245
+}
11431246
11441247
/*
11451248
** Execute a statement or set of statements. Print
11461249
** any result rows/columns depending on the current mode
11471250
** set via the supplied callback.
@@ -1199,10 +1302,16 @@
11991302
sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
12001303
if( zExplain && zExplain[0] ){
12011304
fprintf(pArg->out, "%s", zExplain);
12021305
}
12031306
}
1307
+
1308
+ /* If the shell is currently in ".explain" mode, gather the extra
1309
+ ** data required to add indents to the output.*/
1310
+ if( pArg->mode==MODE_Explain ){
1311
+ explain_data_prepare(pArg, pStmt);
1312
+ }
12041313
12051314
/* perform the first step. this will tell us if we
12061315
** have a result set or not and how wide it is.
12071316
*/
12081317
rc = sqlite3_step(pStmt);
@@ -1256,10 +1365,12 @@
12561365
do{
12571366
rc = sqlite3_step(pStmt);
12581367
} while( rc == SQLITE_ROW );
12591368
}
12601369
}
1370
+
1371
+ explain_data_delete(pArg);
12611372
12621373
/* print usage stats if stats on */
12631374
if( pArg && pArg->statsOn ){
12641375
display_stats(db, pArg, 0);
12651376
}
12661377
--- src/shell.c
+++ src/shell.c
@@ -462,10 +462,13 @@
462 const char *zDbFilename; /* name of the database file */
463 char *zFreeOnClose; /* Filename to free when closing */
464 const char *zVfs; /* Name of VFS to use */
465 sqlite3_stmt *pStmt; /* Current statement if any. */
466 FILE *pLog; /* Write log output here */
 
 
 
467 };
468
469 /*
470 ** These are the allowed modes.
471 */
@@ -763,13 +766,18 @@
763 if( i<ArraySize(p->actualWidth) ){
764 w = p->actualWidth[i];
765 }else{
766 w = 10;
767 }
768 if( p->mode==MODE_Explain && azArg[i] &&
769 strlen30(azArg[i])>w ){
770 w = strlen30(azArg[i]);
 
 
 
 
 
 
771 }
772 if( w<0 ){
773 fprintf(p->out,"%*.*s%s",-w,-w,
774 azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
775 }else{
@@ -1138,10 +1146,105 @@
1138 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1139 }
1140
1141 return 0;
1142 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1143
1144 /*
1145 ** Execute a statement or set of statements. Print
1146 ** any result rows/columns depending on the current mode
1147 ** set via the supplied callback.
@@ -1199,10 +1302,16 @@
1199 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1200 if( zExplain && zExplain[0] ){
1201 fprintf(pArg->out, "%s", zExplain);
1202 }
1203 }
 
 
 
 
 
 
1204
1205 /* perform the first step. this will tell us if we
1206 ** have a result set or not and how wide it is.
1207 */
1208 rc = sqlite3_step(pStmt);
@@ -1256,10 +1365,12 @@
1256 do{
1257 rc = sqlite3_step(pStmt);
1258 } while( rc == SQLITE_ROW );
1259 }
1260 }
 
 
1261
1262 /* print usage stats if stats on */
1263 if( pArg && pArg->statsOn ){
1264 display_stats(db, pArg, 0);
1265 }
1266
--- src/shell.c
+++ src/shell.c
@@ -462,10 +462,13 @@
462 const char *zDbFilename; /* name of the database file */
463 char *zFreeOnClose; /* Filename to free when closing */
464 const char *zVfs; /* Name of VFS to use */
465 sqlite3_stmt *pStmt; /* Current statement if any. */
466 FILE *pLog; /* Write log output here */
467 int *aiIndent; /* Array of indents used in MODE_Explain */
468 int nIndent; /* Size of array aiIndent[] */
469 int iIndent; /* Index of current op in aiIndent[] */
470 };
471
472 /*
473 ** These are the allowed modes.
474 */
@@ -763,13 +766,18 @@
766 if( i<ArraySize(p->actualWidth) ){
767 w = p->actualWidth[i];
768 }else{
769 w = 10;
770 }
771 if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
 
772 w = strlen30(azArg[i]);
773 }
774 if( i==1 && p->aiIndent && p->pStmt ){
775 if( p->iIndent<p->nIndent ){
776 fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
777 }
778 p->iIndent++;
779 }
780 if( w<0 ){
781 fprintf(p->out,"%*.*s%s",-w,-w,
782 azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " ");
783 }else{
@@ -1138,10 +1146,105 @@
1146 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1147 }
1148
1149 return 0;
1150 }
1151
1152 /*
1153 ** Parameter azArray points to a zero-terminated array of strings. zStr
1154 ** points to a single nul-terminated string. Return non-zero if zStr
1155 ** is equal, according to strcmp(), to any of the strings in the array.
1156 ** Otherwise, return zero.
1157 */
1158 static int str_in_array(const char *zStr, const char **azArray){
1159 int i;
1160 for(i=0; azArray[i]; i++){
1161 if( 0==strcmp(zStr, azArray[i]) ) return 1;
1162 }
1163 return 0;
1164 }
1165
1166 /*
1167 ** If compiled statement pSql appears to be an EXPLAIN statement, allocate
1168 ** and populate the callback_data.aiIndent[] array with the number of
1169 ** spaces each opcode should be indented before it is output.
1170 **
1171 ** The indenting rules are:
1172 **
1173 ** * For each "Next", "Prev", "VNext" or "VPrev" instruction, indent
1174 ** all opcodes that occur between the p2 jump destination and the opcode
1175 ** itself by 2 spaces.
1176 **
1177 ** * For each "Goto", if the jump destination is earlier in the program
1178 ** and ends on one of:
1179 ** Yield SeekGt SeekLt RowSetRead
1180 ** then indent all opcodes between the earlier instruction
1181 ** and "Goto" by 2 spaces.
1182 */
1183 static void explain_data_prepare(struct callback_data *p, sqlite3_stmt *pSql){
1184 const char *zSql; /* The text of the SQL statement */
1185 const char *z; /* Used to check if this is an EXPLAIN */
1186 int *abYield = 0; /* True if op is an OP_Yield */
1187 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1188 int iOp; /* Index of operation in p->aiIndent[] */
1189
1190 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext", 0 };
1191 const char *azYield[] = { "Yield", "SeekLt", "SeekGt", "RowSetRead", 0 };
1192 const char *azGoto[] = { "Goto", 0 };
1193
1194 /* Try to figure out if this is really an EXPLAIN statement. If this
1195 ** cannot be verified, return early. */
1196 zSql = sqlite3_sql(pSql);
1197 if( zSql==0 ) return;
1198 for(z=zSql; *z==' ' || *z=='\t' || *z=='\n' || *z=='\f' || *z=='\r'; z++);
1199 if( sqlite3_strnicmp(z, "explain", 7) ) return;
1200
1201 for(iOp=0; SQLITE_ROW==sqlite3_step(pSql); iOp++){
1202 int i;
1203 int iAddr = sqlite3_column_int(pSql, 0);
1204 const char *zOp = (const char*)sqlite3_column_text(pSql, 1);
1205
1206 /* Set p2 to the P2 field of the current opcode. Then, assuming that
1207 ** p2 is an instruction address, set variable p2op to the index of that
1208 ** instruction in the aiIndent[] array. p2 and p2op may be different if
1209 ** the current instruction is part of a sub-program generated by an
1210 ** SQL trigger or foreign key. */
1211 int p2 = sqlite3_column_int(pSql, 3);
1212 int p2op = (p2 + (iOp-iAddr));
1213
1214 /* Grow the p->aiIndent array as required */
1215 if( iOp>=nAlloc ){
1216 nAlloc += 100;
1217 p->aiIndent = (int*)sqlite3_realloc(p->aiIndent, nAlloc*sizeof(int));
1218 abYield = (int*)sqlite3_realloc(abYield, nAlloc*sizeof(int));
1219 }
1220 abYield[iOp] = str_in_array(zOp, azYield);
1221 p->aiIndent[iOp] = 0;
1222 p->nIndent = iOp+1;
1223
1224 if( str_in_array(zOp, azNext) ){
1225 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1226 }
1227 if( str_in_array(zOp, azGoto) && p2op<p->nIndent && abYield[p2op] ){
1228 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1229 }
1230 }
1231
1232 p->iIndent = 0;
1233 sqlite3_free(abYield);
1234 sqlite3_reset(pSql);
1235 }
1236
1237 /*
1238 ** Free the array allocated by explain_data_prepare().
1239 */
1240 static void explain_data_delete(struct callback_data *p){
1241 sqlite3_free(p->aiIndent);
1242 p->aiIndent = 0;
1243 p->nIndent = 0;
1244 p->iIndent = 0;
1245 }
1246
1247 /*
1248 ** Execute a statement or set of statements. Print
1249 ** any result rows/columns depending on the current mode
1250 ** set via the supplied callback.
@@ -1199,10 +1302,16 @@
1302 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1303 if( zExplain && zExplain[0] ){
1304 fprintf(pArg->out, "%s", zExplain);
1305 }
1306 }
1307
1308 /* If the shell is currently in ".explain" mode, gather the extra
1309 ** data required to add indents to the output.*/
1310 if( pArg->mode==MODE_Explain ){
1311 explain_data_prepare(pArg, pStmt);
1312 }
1313
1314 /* perform the first step. this will tell us if we
1315 ** have a result set or not and how wide it is.
1316 */
1317 rc = sqlite3_step(pStmt);
@@ -1256,10 +1365,12 @@
1365 do{
1366 rc = sqlite3_step(pStmt);
1367 } while( rc == SQLITE_ROW );
1368 }
1369 }
1370
1371 explain_data_delete(pArg);
1372
1373 /* print usage stats if stats on */
1374 if( pArg && pArg->statsOn ){
1375 display_stats(db, pArg, 0);
1376 }
1377
+691 -578
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138138
#define SQLITE_VERSION "3.8.2"
139139
#define SQLITE_VERSION_NUMBER 3008002
140
-#define SQLITE_SOURCE_ID "2013-11-12 15:33:40 0f924c6ef6cf2ac5a61aafa8dd8e3309b3970499"
140
+#define SQLITE_SOURCE_ID "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -396,11 +396,11 @@
396396
** Restrictions:
397397
**
398398
** <ul>
399399
** <li> The application must insure that the 1st parameter to sqlite3_exec()
400400
** is a valid and open [database connection].
401
-** <li> The application must not close [database connection] specified by
401
+** <li> The application must not close the [database connection] specified by
402402
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
403403
** <li> The application must not modify the SQL statement text passed into
404404
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
405405
** </ul>
406406
*/
@@ -473,11 +473,11 @@
473473
** about errors. The extended result codes are enabled or disabled
474474
** on a per database connection basis using the
475475
** [sqlite3_extended_result_codes()] API.
476476
**
477477
** Some of the available extended result codes are listed here.
478
-** One may expect the number of extended result codes will be expand
478
+** One may expect the number of extended result codes will increase
479479
** over time. Software that uses extended result codes should expect
480480
** to see new result codes in future releases of SQLite.
481481
**
482482
** The SQLITE_OK result code will never be extended. It will always
483483
** be exactly zero.
@@ -1411,11 +1411,11 @@
14111411
** of 8. Some allocators round up to a larger multiple or to a power of 2.
14121412
** Every memory allocation request coming in through [sqlite3_malloc()]
14131413
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
14141414
** that causes the corresponding memory allocation to fail.
14151415
**
1416
-** The xInit method initializes the memory allocator. (For example,
1416
+** The xInit method initializes the memory allocator. For example,
14171417
** it might allocate any require mutexes or initialize internal data
14181418
** structures. The xShutdown method is invoked (indirectly) by
14191419
** [sqlite3_shutdown()] and should deallocate any resources acquired
14201420
** by xInit. The pAppData pointer is used as the only parameter to
14211421
** xInit and xShutdown.
@@ -3137,11 +3137,10 @@
31373137
** to the [sqlite3_bind_text | bindings] of that [parameter].
31383138
** ^The specific value of WHERE-clause [parameter] might influence the
31393139
** choice of query plan if the parameter is the left-hand side of a [LIKE]
31403140
** or [GLOB] operator or if the parameter is compared to an indexed column
31413141
** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3142
-** the
31433142
** </li>
31443143
** </ol>
31453144
*/
31463145
SQLITE_API int sqlite3_prepare(
31473146
sqlite3 *db, /* Database handle */
@@ -3867,11 +3866,11 @@
38673866
**
38683867
** ^The pointers returned are valid until a type conversion occurs as
38693868
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
38703869
** [sqlite3_finalize()] is called. ^The memory space used to hold strings
38713870
** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3872
-** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3871
+** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
38733872
** [sqlite3_free()].
38743873
**
38753874
** ^(If a memory allocation error occurs during the evaluation of any
38763875
** of these routines, a default value is returned. The default value
38773876
** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4945,12 +4944,12 @@
49454944
/*
49464945
** CAPI3REF: Free Memory Used By A Database Connection
49474946
**
49484947
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
49494948
** memory as possible from database connection D. Unlike the
4950
-** [sqlite3_release_memory()] interface, this interface is effect even
4951
-** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4949
+** [sqlite3_release_memory()] interface, this interface is in effect even
4950
+** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
49524951
** omitted.
49534952
**
49544953
** See also: [sqlite3_release_memory()]
49554954
*/
49564955
SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -9096,22 +9095,22 @@
90969095
#define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
90979096
#define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
90989097
#define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
90999098
#define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
91009099
#define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9101
-#define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P3 */
9100
+#define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
91029101
#define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
91039102
#define OP_RowKey 82 /* synopsis: r[P2]=key */
91049103
#define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
91059104
#define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
91069105
#define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
91079106
#define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
91089107
#define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
91099108
#define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
91109109
#define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9111
-#define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P1]/r[P2] */
9112
-#define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P1]%r[P2] */
9110
+#define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9111
+#define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
91139112
#define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
91149113
#define OP_RowData 93 /* synopsis: r[P2]=data */
91159114
#define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
91169115
#define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
91179116
#define OP_Rowid 96 /* synopsis: r[P2]=rowid */
@@ -9237,11 +9236,10 @@
92379236
SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
92389237
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
92399238
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
92409239
#ifdef SQLITE_DEBUG
92419240
SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
9242
-SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
92439241
#endif
92449242
SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
92459243
SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
92469244
SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
92479245
SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
@@ -10304,10 +10302,11 @@
1030410302
#define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
1030510303
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
1030610304
#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
1030710305
#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
1030810306
#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
10307
+#define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
1030910308
1031010309
1031110310
/*
1031210311
** Bits of the sqlite3.dbOptFlags field that are used by the
1031310312
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11089,11 +11088,11 @@
1108911088
#define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
1109011089
#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
1109111090
#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
1109211091
#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
1109311092
#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
11094
-#define EP_FixedDest 0x000200 /* Result needed in a specific register */
11093
+ /* unused 0x000200 */
1109511094
#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
1109611095
#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
1109711096
#define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
1109811097
#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
1109911098
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
@@ -11160,12 +11159,17 @@
1116011159
char *zName; /* Token associated with this expression */
1116111160
char *zSpan; /* Original text of the expression */
1116211161
u8 sortOrder; /* 1 for DESC or 0 for ASC */
1116311162
unsigned done :1; /* A flag to indicate when processing is finished */
1116411163
unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11165
- u16 iOrderByCol; /* For ORDER BY, column number in result set */
11166
- u16 iAlias; /* Index into Parse.aAlias[] for zName */
11164
+ union {
11165
+ struct {
11166
+ u16 iOrderByCol; /* For ORDER BY, column number in result set */
11167
+ u16 iAlias; /* Index into Parse.aAlias[] for zName */
11168
+ } x;
11169
+ int iConstExprReg; /* Register in which Expr value is cached */
11170
+ } u;
1116711171
} *a; /* Alloc a power of two greater or equal to nExpr */
1116811172
};
1116911173
1117011174
/*
1117111175
** An instance of this structure is used by the parser to record both
@@ -11538,10 +11542,11 @@
1153811542
u8 tempReg; /* iReg is a temp register that needs to be freed */
1153911543
int iLevel; /* Nesting level */
1154011544
int iReg; /* Reg with value of this column. 0 means none. */
1154111545
int lru; /* Least recently used entry has the smallest value */
1154211546
} aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
11547
+ ExprList *pConstExpr;/* Constant expressions */
1154311548
yDbMask writeMask; /* Start a write transaction on these databases */
1154411549
yDbMask cookieMask; /* Bitmask of schema verified databases */
1154511550
int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
1154611551
int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
1154711552
int regRowid; /* Register holding rowid of CREATE TABLE entry */
@@ -12151,11 +12156,10 @@
1215112156
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
1215212157
SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
1215312158
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1215412159
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
1215512160
SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12156
-SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse*, Expr*);
1215712161
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
1215812162
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
1215912163
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
1216012164
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
1216112165
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
@@ -12197,11 +12201,11 @@
1219712201
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
1219812202
SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
1219912203
SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
1220012204
u8,u8,int,int*);
1220112205
SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12202
-SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, int*, int*);
12206
+SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, u8*, int*, int*);
1220312207
SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
1220412208
SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
1220512209
SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
1220612210
SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
1220712211
SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*);
@@ -12519,10 +12523,11 @@
1251912523
SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
1252012524
SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
1252112525
SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
1252212526
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
1252312527
SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
12528
+SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
1252412529
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
1252512530
SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
1252612531
SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
1252712532
SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
1252812533
SQLITE_PRIVATE const char *sqlite3JournalModename(int);
@@ -13700,13 +13705,10 @@
1370013705
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1370113706
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
1370213707
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
1370313708
char *zSql; /* Text of the SQL statement that generated this */
1370413709
void *pFree; /* Free this when deleting the vdbe */
13705
-#ifdef SQLITE_DEBUG
13706
- FILE *trace; /* Write an execution trace here, if not NULL */
13707
-#endif
1370813710
#ifdef SQLITE_ENABLE_TREE_EXPLAIN
1370913711
Explain *pExplain; /* The explainer */
1371013712
char *zExplain; /* Explanation of data structures */
1371113713
#endif
1371213714
VdbeFrame *pFrame; /* Parent frame */
@@ -15796,20 +15798,10 @@
1579615798
** This version of the memory allocator is the default. It is
1579715799
** used when no other memory allocator is specified using compile-time
1579815800
** macros.
1579915801
*/
1580015802
#ifdef SQLITE_SYSTEM_MALLOC
15801
-
15802
-/*
15803
-** The MSVCRT has malloc_usable_size() but it is called _msize().
15804
-** The use of _msize() is automatic, but can be disabled by compiling
15805
-** with -DSQLITE_WITHOUT_MSIZE
15806
-*/
15807
-#if defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
15808
-# define SQLITE_MALLOCSIZE _msize
15809
-#endif
15810
-
1581115803
#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
1581215804
1581315805
/*
1581415806
** Use the zone allocator available on apple products unless the
1581515807
** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
@@ -15828,25 +15820,51 @@
1582815820
1582915821
/*
1583015822
** Use standard C library malloc and free on non-Apple systems.
1583115823
** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
1583215824
*/
15833
-#define SQLITE_MALLOC(x) malloc(x)
15834
-#define SQLITE_FREE(x) free(x)
15835
-#define SQLITE_REALLOC(x,y) realloc((x),(y))
15836
-
15837
-#if (defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)) \
15838
- || (defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE))
15839
-# include <malloc.h> /* Needed for malloc_usable_size on linux */
15840
-#endif
15841
-#ifdef HAVE_MALLOC_USABLE_SIZE
15842
-# ifndef SQLITE_MALLOCSIZE
15843
-# define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
15844
-# endif
15845
-#else
15846
-# undef SQLITE_MALLOCSIZE
15847
-#endif
15825
+#define SQLITE_MALLOC(x) malloc(x)
15826
+#define SQLITE_FREE(x) free(x)
15827
+#define SQLITE_REALLOC(x,y) realloc((x),(y))
15828
+
15829
+/*
15830
+** The malloc.h header file is needed for malloc_usable_size() function
15831
+** on some systems (e.g. Linux).
15832
+*/
15833
+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE)
15834
+# define SQLITE_USE_MALLOC_H
15835
+# define SQLITE_USE_MALLOC_USABLE_SIZE
15836
+/*
15837
+** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
15838
+** use of _msize() is automatic, but can be disabled by compiling with
15839
+** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
15840
+** the malloc.h header file.
15841
+*/
15842
+#elif defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
15843
+# define SQLITE_USE_MALLOC_H
15844
+# define SQLITE_USE_MSIZE
15845
+#endif
15846
+
15847
+/*
15848
+** Include the malloc.h header file, if necessary. Also set define macro
15849
+** SQLITE_MALLOCSIZE to the appropriate function name, which is _msize()
15850
+** for MSVC and malloc_usable_size() for most other systems (e.g. Linux).
15851
+** The memory size function can always be overridden manually by defining
15852
+** the macro SQLITE_MALLOCSIZE to the desired function name.
15853
+*/
15854
+#if defined(SQLITE_USE_MALLOC_H)
15855
+# include <malloc.h>
15856
+# if defined(SQLITE_USE_MALLOC_USABLE_SIZE)
15857
+# if !defined(SQLITE_MALLOCSIZE)
15858
+# define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
15859
+# endif
15860
+# elif defined(SQLITE_USE_MSIZE)
15861
+# if !defined(SQLITE_MALLOCSIZE)
15862
+# define SQLITE_MALLOCSIZE _msize
15863
+# endif
15864
+# endif
15865
+#endif /* defined(SQLITE_USE_MALLOC_H) */
1584815866
1584915867
#endif /* __APPLE__ or not __APPLE__ */
1585015868
1585115869
/*
1585215870
** Like malloc(), but remember the size of the allocation
@@ -22957,22 +22975,22 @@
2295722975
/* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
2295822976
/* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
2295922977
/* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
2296022978
/* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
2296122979
/* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
22962
- /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P3"),
22980
+ /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
2296322981
/* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
2296422982
/* 82 */ "RowKey" OpHelp("r[P2]=key"),
2296522983
/* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
2296622984
/* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
2296722985
/* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
2296822986
/* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
2296922987
/* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
2297022988
/* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
2297122989
/* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
22972
- /* 90 */ "Divide" OpHelp("r[P3]=r[P1]/r[P2]"),
22973
- /* 91 */ "Remainder" OpHelp("r[P3]=r[P1]%r[P2]"),
22990
+ /* 90 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
22991
+ /* 91 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2297422992
/* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
2297522993
/* 93 */ "RowData" OpHelp("r[P2]=data"),
2297622994
/* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
2297722995
/* 95 */ "String8" OpHelp("r[P2]='P4'"),
2297822996
/* 96 */ "Rowid" OpHelp("r[P2]=rowid"),
@@ -58853,10 +58871,11 @@
5885358871
if( sqlite3OpenTempDatabase(pParse) ){
5885458872
sqlite3Error(pErrorDb, pParse->rc, "%s", pParse->zErrMsg);
5885558873
rc = SQLITE_ERROR;
5885658874
}
5885758875
sqlite3DbFree(pErrorDb, pParse->zErrMsg);
58876
+ sqlite3ParserReset(pParse);
5885858877
sqlite3StackFree(pErrorDb, pParse);
5885958878
}
5886058879
if( rc ){
5886158880
return 0;
5886258881
}
@@ -60997,19 +61016,10 @@
6099761016
pA->zSql = pB->zSql;
6099861017
pB->zSql = zTmp;
6099961018
pB->isPrepareV2 = pA->isPrepareV2;
6100061019
}
6100161020
61002
-#ifdef SQLITE_DEBUG
61003
-/*
61004
-** Turn tracing on or off
61005
-*/
61006
-SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
61007
- p->trace = trace;
61008
-}
61009
-#endif
61010
-
6101161021
/*
6101261022
** Resize the Vdbe.aOp array so that it is at least one op larger than
6101361023
** it was.
6101461024
**
6101561025
** If an out-of-memory error occurs while resizing the array, return
@@ -61901,11 +61911,11 @@
6190161911
assert( i<nTemp );
6190261912
break;
6190361913
}
6190461914
case P4_COLLSEQ: {
6190561915
CollSeq *pColl = pOp->p4.pColl;
61906
- sqlite3_snprintf(nTemp, zTemp, "collseq(%.20s)", pColl->zName);
61916
+ sqlite3_snprintf(nTemp, zTemp, "(%.20s)", pColl->zName);
6190761917
break;
6190861918
}
6190961919
case P4_FUNCDEF: {
6191061920
FuncDef *pDef = pOp->p4.pFunc;
6191161921
sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
@@ -62334,19 +62344,21 @@
6233462344
#ifdef SQLITE_DEBUG
6233562345
/*
6233662346
** Print the SQL that was used to generate a VDBE program.
6233762347
*/
6233862348
SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe *p){
62339
- int nOp = p->nOp;
62340
- VdbeOp *pOp;
62341
- if( nOp<1 ) return;
62342
- pOp = &p->aOp[0];
62343
- if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62344
- const char *z = pOp->p4.z;
62345
- while( sqlite3Isspace(*z) ) z++;
62346
- printf("SQL: [%s]\n", z);
62347
- }
62349
+ const char *z = 0;
62350
+ if( p->zSql ){
62351
+ z = p->zSql;
62352
+ }else if( p->nOp>=1 ){
62353
+ const VdbeOp *pOp = &p->aOp[0];
62354
+ if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62355
+ z = pOp->p4.z;
62356
+ while( sqlite3Isspace(*z) ) z++;
62357
+ }
62358
+ }
62359
+ if( z ) printf("SQL: [%s]\n", z);
6234862360
}
6234962361
#endif
6235062362
6235162363
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
6235262364
/*
@@ -63892,19 +63904,16 @@
6389263904
pMem->u.i = serial_type-8;
6389363905
pMem->flags = MEM_Int;
6389463906
return 0;
6389563907
}
6389663908
default: {
63909
+ static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
6389763910
u32 len = (serial_type-12)/2;
6389863911
pMem->z = (char *)buf;
6389963912
pMem->n = len;
6390063913
pMem->xDel = 0;
63901
- if( serial_type&0x01 ){
63902
- pMem->flags = MEM_Str | MEM_Ephem;
63903
- }else{
63904
- pMem->flags = MEM_Blob | MEM_Ephem;
63905
- }
63914
+ pMem->flags = aFlag[serial_type&1];
6390663915
return len;
6390763916
}
6390863917
}
6390963918
return 0;
6391063919
}
@@ -66350,41 +66359,40 @@
6635066359
6635166360
#ifdef SQLITE_DEBUG
6635266361
/*
6635366362
** Print the value of a register for tracing purposes:
6635466363
*/
66355
-static void memTracePrint(FILE *out, Mem *p){
66364
+static void memTracePrint(Mem *p){
6635666365
if( p->flags & MEM_Invalid ){
66357
- fprintf(out, " undefined");
66366
+ printf(" undefined");
6635866367
}else if( p->flags & MEM_Null ){
66359
- fprintf(out, " NULL");
66368
+ printf(" NULL");
6636066369
}else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66361
- fprintf(out, " si:%lld", p->u.i);
66370
+ printf(" si:%lld", p->u.i);
6636266371
}else if( p->flags & MEM_Int ){
66363
- fprintf(out, " i:%lld", p->u.i);
66372
+ printf(" i:%lld", p->u.i);
6636466373
#ifndef SQLITE_OMIT_FLOATING_POINT
6636566374
}else if( p->flags & MEM_Real ){
66366
- fprintf(out, " r:%g", p->r);
66375
+ printf(" r:%g", p->r);
6636766376
#endif
6636866377
}else if( p->flags & MEM_RowSet ){
66369
- fprintf(out, " (rowset)");
66378
+ printf(" (rowset)");
6637066379
}else{
6637166380
char zBuf[200];
6637266381
sqlite3VdbeMemPrettyPrint(p, zBuf);
66373
- fprintf(out, " ");
66374
- fprintf(out, "%s", zBuf);
66382
+ printf(" %s", zBuf);
6637566383
}
6637666384
}
66377
-static void registerTrace(FILE *out, int iReg, Mem *p){
66378
- fprintf(out, "REG[%d] = ", iReg);
66379
- memTracePrint(out, p);
66380
- fprintf(out, "\n");
66385
+static void registerTrace(int iReg, Mem *p){
66386
+ printf("REG[%d] = ", iReg);
66387
+ memTracePrint(p);
66388
+ printf("\n");
6638166389
}
6638266390
#endif
6638366391
6638466392
#ifdef SQLITE_DEBUG
66385
-# define REGISTER_TRACE(R,M) if(p->trace)registerTrace(p->trace,R,M)
66393
+# define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
6638666394
#else
6638766395
# define REGISTER_TRACE(R,M)
6638866396
#endif
6638966397
6639066398
@@ -67035,17 +67043,32 @@
6703567043
}
6703667044
}
6703767045
#endif
6703867046
#ifdef SQLITE_DEBUG
6703967047
sqlite3BeginBenignMalloc();
67040
- if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
67048
+ if( p->pc==0
67049
+ && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
67050
+ ){
6704167051
int i;
67042
- printf("VDBE Program Listing:\n");
67052
+ int once = 1;
6704367053
sqlite3VdbePrintSql(p);
67044
- for(i=0; i<p->nOp; i++){
67045
- sqlite3VdbePrintOp(stdout, i, &aOp[i]);
67054
+ if( p->db->flags & SQLITE_VdbeListing ){
67055
+ printf("VDBE Program Listing:\n");
67056
+ for(i=0; i<p->nOp; i++){
67057
+ sqlite3VdbePrintOp(stdout, i, &aOp[i]);
67058
+ }
6704667059
}
67060
+ if( p->db->flags & SQLITE_VdbeEQP ){
67061
+ for(i=0; i<p->nOp; i++){
67062
+ if( aOp[i].opcode==OP_Explain ){
67063
+ if( once ) printf("VDBE Query Plan:\n");
67064
+ printf("%s\n", aOp[i].p4.z);
67065
+ once = 0;
67066
+ }
67067
+ }
67068
+ }
67069
+ if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
6704767070
}
6704867071
sqlite3EndBenignMalloc();
6704967072
#endif
6705067073
for(pc=p->pc; rc==SQLITE_OK; pc++){
6705167074
assert( pc>=0 && pc<p->nOp );
@@ -67058,16 +67081,12 @@
6705867081
pOp = &aOp[pc];
6705967082
6706067083
/* Only allow tracing if SQLITE_DEBUG is defined.
6706167084
*/
6706267085
#ifdef SQLITE_DEBUG
67063
- if( p->trace ){
67064
- if( pc==0 ){
67065
- printf("VDBE Execution Trace:\n");
67066
- sqlite3VdbePrintSql(p);
67067
- }
67068
- sqlite3VdbePrintOp(p->trace, pc, pOp);
67086
+ if( db->flags & SQLITE_VdbeTrace ){
67087
+ sqlite3VdbePrintOp(stdout, pc, pOp);
6706967088
}
6707067089
#endif
6707167090
6707267091
6707367092
/* Check to see if we need to simulate an interrupt. This only happens
@@ -67194,19 +67213,16 @@
6719467213
** sqlite3VdbeExec() or since last time the progress callback was called).
6719567214
** If the progress callback returns non-zero, exit the virtual machine with
6719667215
** a return code SQLITE_ABORT.
6719767216
*/
6719867217
if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
67199
- int prc;
67200
- prc = db->xProgress(db->pProgressArg);
67201
- if( prc!=0 ){
67218
+ assert( db->nProgressOps!=0 );
67219
+ nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
67220
+ if( db->xProgress(db->pProgressArg) ){
6720267221
rc = SQLITE_INTERRUPT;
6720367222
goto vdbe_error_halt;
6720467223
}
67205
- if( db->xProgress!=0 ){
67206
- nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
67207
- }
6720867224
}
6720967225
#endif
6721067226
6721167227
break;
6721267228
}
@@ -67638,10 +67654,22 @@
6763867654
int i;
6763967655
#endif /* local variables moved into u.ag */
6764067656
assert( p->nResColumn==pOp->p2 );
6764167657
assert( pOp->p1>0 );
6764267658
assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67659
+
67660
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67661
+ /* Run the progress counter just before returning.
67662
+ */
67663
+ if( db->xProgress!=0
67664
+ && nVmStep>=nProgressLimit
67665
+ && db->xProgress(db->pProgressArg)!=0
67666
+ ){
67667
+ rc = SQLITE_INTERRUPT;
67668
+ goto vdbe_error_halt;
67669
+ }
67670
+#endif
6764367671
6764467672
/* If this statement has violated immediate foreign key constraints, do
6764567673
** not return the number of rows modified. And do not RELEASE the statement
6764667674
** transaction. It needs to be rolled back. */
6764767675
if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
@@ -67768,23 +67796,23 @@
6776867796
** Subtract the value in register P1 from the value in register P2
6776967797
** and store the result in register P3.
6777067798
** If either input is NULL, the result is NULL.
6777167799
*/
6777267800
/* Opcode: Divide P1 P2 P3 * *
67773
-** Synopsis: r[P3]=r[P1]/r[P2]
67801
+** Synopsis: r[P3]=r[P2]/r[P1]
6777467802
**
6777567803
** Divide the value in register P1 by the value in register P2
6777667804
** and store the result in register P3 (P3=P2/P1). If the value in
6777767805
** register P1 is zero, then the result is NULL. If either input is
6777867806
** NULL, the result is NULL.
6777967807
*/
6778067808
/* Opcode: Remainder P1 P2 P3 * *
67781
-** Synopsis: r[P3]=r[P1]%r[P2]
67809
+** Synopsis: r[P3]=r[P2]%r[P1]
6778267810
**
67783
-** Compute the remainder after integer division of the value in
67784
-** register P1 by the value in register P2 and store the result in P3.
67785
-** If the value in register P2 is zero the result is NULL.
67811
+** Compute the remainder after integer register P2 is divided by
67812
+** register P1 and store the result in register P3.
67813
+** If the value in register P1 is zero the result is NULL.
6778667814
** If either operand is NULL, the result is NULL.
6778767815
*/
6778867816
case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
6778967817
case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
6779067818
case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
@@ -68249,11 +68277,11 @@
6824968277
break;
6825068278
}
6825168279
#endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
6825268280
6825368281
/* Opcode: Lt P1 P2 P3 P4 P5
68254
-** Synopsis: if r[P1]<r[P3] goto P3
68282
+** Synopsis: if r[P1]<r[P3] goto P2
6825568283
**
6825668284
** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
6825768285
** jump to address P2.
6825868286
**
6825968287
** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -72846,17 +72874,17 @@
7284672874
*/
7284772875
#ifndef NDEBUG
7284872876
assert( pc>=-1 && pc<p->nOp );
7284972877
7285072878
#ifdef SQLITE_DEBUG
72851
- if( p->trace ){
72852
- if( rc!=0 ) fprintf(p->trace,"rc=%d\n",rc);
72879
+ if( db->flags & SQLITE_VdbeTrace ){
72880
+ if( rc!=0 ) printf("rc=%d\n",rc);
7285372881
if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
72854
- registerTrace(p->trace, pOp->p2, &aMem[pOp->p2]);
72882
+ registerTrace(pOp->p2, &aMem[pOp->p2]);
7285572883
}
7285672884
if( pOp->opflags & OPFLG_OUT3 ){
72857
- registerTrace(p->trace, pOp->p3, &aMem[pOp->p3]);
72885
+ registerTrace(pOp->p3, &aMem[pOp->p3]);
7285872886
}
7285972887
}
7286072888
#endif /* SQLITE_DEBUG */
7286172889
#endif /* NDEBUG */
7286272890
} /* The end of the for(;;) loop the loops through opcodes */
@@ -73253,10 +73281,11 @@
7325373281
if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
7325473282
sqlite3DbFree(db, pBlob);
7325573283
}
7325673284
sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
7325773285
sqlite3DbFree(db, zErr);
73286
+ sqlite3ParserReset(pParse);
7325873287
sqlite3StackFree(db, pParse);
7325973288
rc = sqlite3ApiExit(db, rc);
7326073289
sqlite3_mutex_leave(db->mutex);
7326173290
return rc;
7326273291
}
@@ -75218,14 +75247,14 @@
7521875247
if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
7521975248
incrAggFunctionDepth(pDup, nSubquery);
7522075249
pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
7522175250
if( pDup==0 ) return;
7522275251
ExprSetProperty(pDup, EP_Skip);
75223
- if( pEList->a[iCol].iAlias==0 ){
75224
- pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
75252
+ if( pEList->a[iCol].u.x.iAlias==0 ){
75253
+ pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
7522575254
}
75226
- pDup->iTable = pEList->a[iCol].iAlias;
75255
+ pDup->iTable = pEList->a[iCol].u.x.iAlias;
7522775256
}
7522875257
if( pExpr->op==TK_COLLATE ){
7522975258
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
7523075259
}
7523175260
@@ -76086,11 +76115,11 @@
7608676115
assert( pItem->pExpr->op==TK_COLLATE );
7608776116
assert( pItem->pExpr->pLeft==pE );
7608876117
pItem->pExpr->pLeft = pNew;
7608976118
}
7609076119
sqlite3ExprDelete(db, pE);
76091
- pItem->iOrderByCol = (u16)iCol;
76120
+ pItem->u.x.iOrderByCol = (u16)iCol;
7609276121
pItem->done = 1;
7609376122
}else{
7609476123
moreToDo = 1;
7609576124
}
7609676125
}
@@ -76107,12 +76136,12 @@
7610776136
}
7610876137
7610976138
/*
7611076139
** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
7611176140
** the SELECT statement pSelect. If any term is reference to a
76112
-** result set expression (as determined by the ExprList.a.iOrderByCol field)
76113
-** then convert that term into a copy of the corresponding result set
76141
+** result set expression (as determined by the ExprList.a.u.x.iOrderByCol
76142
+** field) then convert that term into a copy of the corresponding result set
7611476143
** column.
7611576144
**
7611676145
** If any errors are detected, add an error message to pParse and
7611776146
** return non-zero. Return zero if no errors are seen.
7611876147
*/
@@ -76135,16 +76164,16 @@
7613576164
}
7613676165
#endif
7613776166
pEList = pSelect->pEList;
7613876167
assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
7613976168
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
76140
- if( pItem->iOrderByCol ){
76141
- if( pItem->iOrderByCol>pEList->nExpr ){
76169
+ if( pItem->u.x.iOrderByCol ){
76170
+ if( pItem->u.x.iOrderByCol>pEList->nExpr ){
7614276171
resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
7614376172
return 1;
7614476173
}
76145
- resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType,0);
76174
+ resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, zType,0);
7614676175
}
7614776176
}
7614876177
return 0;
7614976178
}
7615076179
@@ -76189,11 +76218,11 @@
7618976218
if( iCol>0 ){
7619076219
/* If an AS-name match is found, mark this ORDER BY column as being
7619176220
** a copy of the iCol-th result-set column. The subsequent call to
7619276221
** sqlite3ResolveOrderGroupBy() will convert the expression to a
7619376222
** copy of the iCol-th result-set expression. */
76194
- pItem->iOrderByCol = (u16)iCol;
76223
+ pItem->u.x.iOrderByCol = (u16)iCol;
7619576224
continue;
7619676225
}
7619776226
}
7619876227
if( sqlite3ExprIsInteger(pE2, &iCol) ){
7619976228
/* The ORDER BY term is an integer constant. Again, set the column
@@ -76201,22 +76230,22 @@
7620176230
** order-by term to a copy of the result-set expression */
7620276231
if( iCol<1 || iCol>0xffff ){
7620376232
resolveOutOfRangeError(pParse, zType, i+1, nResult);
7620476233
return 1;
7620576234
}
76206
- pItem->iOrderByCol = (u16)iCol;
76235
+ pItem->u.x.iOrderByCol = (u16)iCol;
7620776236
continue;
7620876237
}
7620976238
7621076239
/* Otherwise, treat the ORDER BY term as an ordinary expression */
76211
- pItem->iOrderByCol = 0;
76240
+ pItem->u.x.iOrderByCol = 0;
7621276241
if( sqlite3ResolveExprNames(pNC, pE) ){
7621376242
return 1;
7621476243
}
7621576244
for(j=0; j<pSelect->pEList->nExpr; j++){
7621676245
if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
76217
- pItem->iOrderByCol = j+1;
76246
+ pItem->u.x.iOrderByCol = j+1;
7621876247
}
7621976248
}
7622076249
}
7622176250
return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
7622276251
}
@@ -77491,12 +77520,11 @@
7749177520
pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
7749277521
pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
7749377522
pItem->sortOrder = pOldItem->sortOrder;
7749477523
pItem->done = 0;
7749577524
pItem->bSpanIsTab = pOldItem->bSpanIsTab;
77496
- pItem->iOrderByCol = pOldItem->iOrderByCol;
77497
- pItem->iAlias = pOldItem->iAlias;
77525
+ pItem->u = pOldItem->u;
7749877526
}
7749977527
return pNew;
7750077528
}
7750177529
7750277530
/*
@@ -78917,10 +78945,11 @@
7891778945
int inReg = target; /* Results stored in register inReg */
7891878946
int regFree1 = 0; /* If non-zero free this temporary register */
7891978947
int regFree2 = 0; /* If non-zero free this temporary register */
7892078948
int r1, r2, r3, r4; /* Various register numbers */
7892178949
sqlite3 *db = pParse->db; /* The database connection */
78950
+ Expr tempX; /* Temporary expression node */
7892278951
7892378952
assert( target>0 && target<=pParse->nMem );
7892478953
if( v==0 ){
7892578954
assert( pParse->db->mallocFailed );
7892678955
return 0;
@@ -79136,12 +79165,14 @@
7913679165
}else if( pLeft->op==TK_FLOAT ){
7913779166
assert( !ExprHasProperty(pExpr, EP_IntValue) );
7913879167
codeReal(v, pLeft->u.zToken, 1, target);
7913979168
#endif
7914079169
}else{
79141
- regFree1 = r1 = sqlite3GetTempReg(pParse);
79142
- sqlite3VdbeAddOp2(v, OP_Integer, 0, r1);
79170
+ tempX.op = TK_INTEGER;
79171
+ tempX.flags = EP_IntValue|EP_TokenOnly;
79172
+ tempX.u.iValue = 0;
79173
+ r1 = sqlite3ExprCodeTemp(pParse, &tempX, &regFree1);
7914379174
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree2);
7914479175
sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target);
7914579176
testcase( regFree2==0 );
7914679177
}
7914779178
inReg = target;
@@ -79453,11 +79484,10 @@
7945379484
int nExpr; /* 2x number of WHEN terms */
7945479485
int i; /* Loop counter */
7945579486
ExprList *pEList; /* List of WHEN terms */
7945679487
struct ExprList_item *aListelem; /* Array of WHEN terms */
7945779488
Expr opCompare; /* The X==Ei expression */
79458
- Expr cacheX; /* Cached expression X */
7945979489
Expr *pX; /* The X expression */
7946079490
Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
7946179491
VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
7946279492
7946379493
assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
@@ -79465,17 +79495,16 @@
7946579495
pEList = pExpr->x.pList;
7946679496
aListelem = pEList->a;
7946779497
nExpr = pEList->nExpr;
7946879498
endLabel = sqlite3VdbeMakeLabel(v);
7946979499
if( (pX = pExpr->pLeft)!=0 ){
79470
- cacheX = *pX;
79500
+ tempX = *pX;
7947179501
testcase( pX->op==TK_COLUMN );
79472
- testcase( pX->op==TK_REGISTER );
79473
- exprToRegister(&cacheX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
79502
+ exprToRegister(&tempX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
7947479503
testcase( regFree1==0 );
7947579504
opCompare.op = TK_EQ;
79476
- opCompare.pLeft = &cacheX;
79505
+ opCompare.pLeft = &tempX;
7947779506
pTest = &opCompare;
7947879507
/* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
7947979508
** The value in regFree1 might get SCopy-ed into the file result.
7948079509
** So make sure that the regFree1 register is not reused for other
7948179510
** purposes and possibly overwritten. */
@@ -79491,11 +79520,10 @@
7949179520
}
7949279521
nextCase = sqlite3VdbeMakeLabel(v);
7949379522
testcase( pTest->op==TK_COLUMN );
7949479523
sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
7949579524
testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
79496
- testcase( aListelem[i+1].pExpr->op==TK_REGISTER );
7949779525
sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
7949879526
sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
7949979527
sqlite3ExprCachePop(pParse, 1);
7950079528
sqlite3VdbeResolveLabel(v, nextCase);
7950179529
}
@@ -79550,19 +79578,45 @@
7955079578
** are stored.
7955179579
**
7955279580
** If the register is a temporary register that can be deallocated,
7955379581
** then write its number into *pReg. If the result register is not
7955479582
** a temporary, then set *pReg to zero.
79583
+**
79584
+** If pExpr is a constant, then this routine might generate this
79585
+** code to fill the register in the initialization section of the
79586
+** VDBE program, in order to factor it out of the evaluation loop.
7955579587
*/
7955679588
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79557
- int r1 = sqlite3GetTempReg(pParse);
79558
- int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79559
- if( r2==r1 ){
79560
- *pReg = r1;
79589
+ int r2;
79590
+ pExpr = sqlite3ExprSkipCollate(pExpr);
79591
+ if( pParse->cookieGoto>0
79592
+ && pExpr->op!=TK_REGISTER
79593
+ && sqlite3ExprIsConstantNotJoin(pExpr)
79594
+ ){
79595
+ ExprList *p = pParse->pConstExpr;
79596
+ int i;
79597
+ *pReg = 0;
79598
+ if( p ){
79599
+ for(i=0; i<p->nExpr; i++){
79600
+ if( sqlite3ExprCompare(p->a[i].pExpr, pExpr, -1)==0 ){
79601
+ return p->a[i].u.iConstExprReg;
79602
+ }
79603
+ }
79604
+ }
79605
+ p = sqlite3ExprListAppend(pParse, p, sqlite3ExprDup(pParse->db, pExpr, 0));
79606
+ pParse->pConstExpr = p;
79607
+ r2 = ++pParse->nMem;
79608
+ if( p ) p->a[p->nExpr-1].u.iConstExprReg = r2;
7956179609
}else{
79562
- sqlite3ReleaseTempReg(pParse, r1);
79563
- *pReg = 0;
79610
+ int r1 = sqlite3GetTempReg(pParse);
79611
+ r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79612
+ if( r2==r1 ){
79613
+ *pReg = r1;
79614
+ }else{
79615
+ sqlite3ReleaseTempReg(pParse, r1);
79616
+ *pReg = 0;
79617
+ }
7956479618
}
7956579619
return r2;
7956679620
}
7956779621
7956879622
/*
@@ -79601,16 +79655,17 @@
7960179655
SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
7960279656
Vdbe *v = pParse->pVdbe;
7960379657
int inReg;
7960479658
inReg = sqlite3ExprCode(pParse, pExpr, target);
7960579659
assert( target>0 );
79606
- /* This routine is called for terms to INSERT or UPDATE. And the only
79607
- ** other place where expressions can be converted into TK_REGISTER is
79608
- ** in WHERE clause processing. So as currently implemented, there is
79609
- ** no way for a TK_REGISTER to exist here. But it seems prudent to
79610
- ** keep the ALWAYS() in case the conditions above change with future
79611
- ** modifications or enhancements. */
79660
+ /* The only place, other than this routine, where expressions can be
79661
+ ** converted to TK_REGISTER is internal subexpressions in BETWEEN and
79662
+ ** CASE operators. Neither ever calls this routine. And this routine
79663
+ ** is never called twice on the same expression. Hence it is impossible
79664
+ ** for the input to this routine to already be a register. Nevertheless,
79665
+ ** it seems prudent to keep the ALWAYS() in case the conditions above
79666
+ ** change with future modifications or enhancements. */
7961279667
if( ALWAYS(pExpr->op!=TK_REGISTER) ){
7961379668
int iMem;
7961479669
iMem = ++pParse->nMem;
7961579670
sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
7961679671
exprToRegister(pExpr, iMem);
@@ -79888,144 +79943,10 @@
7988879943
}
7988979944
sqlite3ExplainPop(pOut);
7989079945
}
7989179946
}
7989279947
#endif /* SQLITE_DEBUG */
79893
-
79894
-/*
79895
-** Return TRUE if pExpr is an constant expression that is appropriate
79896
-** for factoring out of a loop. Appropriate expressions are:
79897
-**
79898
-** * Any expression that evaluates to two or more opcodes.
79899
-**
79900
-** * Any OP_Integer, OP_Real, OP_String, OP_Blob, OP_Null,
79901
-** or OP_Variable that does not need to be placed in a
79902
-** specific register.
79903
-**
79904
-** There is no point in factoring out single-instruction constant
79905
-** expressions that need to be placed in a particular register.
79906
-** We could factor them out, but then we would end up adding an
79907
-** OP_SCopy instruction to move the value into the correct register
79908
-** later. We might as well just use the original instruction and
79909
-** avoid the OP_SCopy.
79910
-*/
79911
-static int isAppropriateForFactoring(Expr *p){
79912
- if( !sqlite3ExprIsConstantNotJoin(p) ){
79913
- return 0; /* Only constant expressions are appropriate for factoring */
79914
- }
79915
- if( (p->flags & EP_FixedDest)==0 ){
79916
- return 1; /* Any constant without a fixed destination is appropriate */
79917
- }
79918
- while( p->op==TK_UPLUS ) p = p->pLeft;
79919
- switch( p->op ){
79920
-#ifndef SQLITE_OMIT_BLOB_LITERAL
79921
- case TK_BLOB:
79922
-#endif
79923
- case TK_VARIABLE:
79924
- case TK_INTEGER:
79925
- case TK_FLOAT:
79926
- case TK_NULL:
79927
- case TK_STRING: {
79928
- testcase( p->op==TK_BLOB );
79929
- testcase( p->op==TK_VARIABLE );
79930
- testcase( p->op==TK_INTEGER );
79931
- testcase( p->op==TK_FLOAT );
79932
- testcase( p->op==TK_NULL );
79933
- testcase( p->op==TK_STRING );
79934
- /* Single-instruction constants with a fixed destination are
79935
- ** better done in-line. If we factor them, they will just end
79936
- ** up generating an OP_SCopy to move the value to the destination
79937
- ** register. */
79938
- return 0;
79939
- }
79940
- case TK_UMINUS: {
79941
- if( p->pLeft->op==TK_FLOAT || p->pLeft->op==TK_INTEGER ){
79942
- return 0;
79943
- }
79944
- break;
79945
- }
79946
- default: {
79947
- break;
79948
- }
79949
- }
79950
- return 1;
79951
-}
79952
-
79953
-/*
79954
-** If pExpr is a constant expression that is appropriate for
79955
-** factoring out of a loop, then evaluate the expression
79956
-** into a register and convert the expression into a TK_REGISTER
79957
-** expression.
79958
-*/
79959
-static int evalConstExpr(Walker *pWalker, Expr *pExpr){
79960
- Parse *pParse = pWalker->pParse;
79961
- switch( pExpr->op ){
79962
- case TK_IN:
79963
- case TK_REGISTER: {
79964
- return WRC_Prune;
79965
- }
79966
- case TK_COLLATE: {
79967
- return WRC_Continue;
79968
- }
79969
- case TK_FUNCTION:
79970
- case TK_AGG_FUNCTION:
79971
- case TK_CONST_FUNC: {
79972
- /* The arguments to a function have a fixed destination.
79973
- ** Mark them this way to avoid generated unneeded OP_SCopy
79974
- ** instructions.
79975
- */
79976
- ExprList *pList = pExpr->x.pList;
79977
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
79978
- if( pList ){
79979
- int i = pList->nExpr;
79980
- struct ExprList_item *pItem = pList->a;
79981
- for(; i>0; i--, pItem++){
79982
- if( ALWAYS(pItem->pExpr) ) pItem->pExpr->flags |= EP_FixedDest;
79983
- }
79984
- }
79985
- break;
79986
- }
79987
- }
79988
- if( isAppropriateForFactoring(pExpr) ){
79989
- int r1 = ++pParse->nMem;
79990
- int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79991
- /* If r2!=r1, it means that register r1 is never used. That is harmless
79992
- ** but suboptimal, so we want to know about the situation to fix it.
79993
- ** Hence the following assert: */
79994
- assert( r2==r1 );
79995
- exprToRegister(pExpr, r2);
79996
- return WRC_Prune;
79997
- }
79998
- return WRC_Continue;
79999
-}
80000
-
80001
-/*
80002
-** Preevaluate constant subexpressions within pExpr and store the
80003
-** results in registers. Modify pExpr so that the constant subexpresions
80004
-** are TK_REGISTER opcodes that refer to the precomputed values.
80005
-**
80006
-** This routine is a no-op if the jump to the cookie-check code has
80007
-** already occur. Since the cookie-check jump is generated prior to
80008
-** any other serious processing, this check ensures that there is no
80009
-** way to accidently bypass the constant initializations.
80010
-**
80011
-** This routine is also a no-op if the SQLITE_FactorOutConst optimization
80012
-** is disabled via the sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS)
80013
-** interface. This allows test logic to verify that the same answer is
80014
-** obtained for queries regardless of whether or not constants are
80015
-** precomputed into registers or if they are inserted in-line.
80016
-*/
80017
-SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse *pParse, Expr *pExpr){
80018
- Walker w;
80019
- if( pParse->cookieGoto ) return;
80020
- if( OptimizationDisabled(pParse->db, SQLITE_FactorOutConst) ) return;
80021
- memset(&w, 0, sizeof(w));
80022
- w.xExprCallback = evalConstExpr;
80023
- w.pParse = pParse;
80024
- sqlite3WalkExpr(&w, pExpr);
80025
-}
80026
-
8002779948
8002879949
/*
8002979950
** Generate code that pushes the value of every element of the given
8003079951
** expression list into a sequence of registers beginning at target.
8003179952
**
@@ -80400,44 +80321,46 @@
8040080321
** this routine is used, it does not hurt to get an extra 2 - that
8040180322
** just might result in some slightly slower code. But returning
8040280323
** an incorrect 0 or 1 could lead to a malfunction.
8040380324
*/
8040480325
SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
80405
- if( pA==0||pB==0 ){
80326
+ u32 combinedFlags;
80327
+ if( pA==0 || pB==0 ){
8040680328
return pB==pA ? 0 : 2;
8040780329
}
80408
- assert( !ExprHasProperty(pA, EP_TokenOnly|EP_Reduced) );
80409
- assert( !ExprHasProperty(pB, EP_TokenOnly|EP_Reduced) );
80410
- if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){
80330
+ combinedFlags = pA->flags | pB->flags;
80331
+ if( combinedFlags & EP_IntValue ){
80332
+ if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
80333
+ return 0;
80334
+ }
8041180335
return 2;
8041280336
}
80413
- if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
80414
- if( pA->op!=pB->op && (pA->op!=TK_REGISTER || pA->op2!=pB->op) ){
80337
+ if( pA->op!=pB->op ){
8041580338
if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB, iTab)<2 ){
8041680339
return 1;
8041780340
}
8041880341
if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
8041980342
return 1;
8042080343
}
8042180344
return 2;
8042280345
}
80423
- if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
80424
- if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
80425
- if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
80426
- if( pA->iColumn!=pB->iColumn ) return 2;
80427
- if( pA->iTable!=pB->iTable
80428
- && pA->op!=TK_REGISTER
80429
- && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
80430
- if( ExprHasProperty(pA, EP_IntValue) ){
80431
- if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
80432
- return 2;
80433
- }
80434
- }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){
80435
- if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
80346
+ if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
8043680347
if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
8043780348
return pA->op==TK_COLLATE ? 1 : 2;
8043880349
}
80350
+ }
80351
+ if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
80352
+ if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
80353
+ if( combinedFlags & EP_xIsSelect ) return 2;
80354
+ if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
80355
+ if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
80356
+ if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
80357
+ if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
80358
+ if( pA->iColumn!=pB->iColumn ) return 2;
80359
+ if( pA->iTable!=pB->iTable
80360
+ && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
80361
+ }
8043980362
}
8044080363
return 0;
8044180364
}
8044280365
8044380366
/*
@@ -83090,14 +83013,16 @@
8309083013
}
8309183014
pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
8309283015
if( pTable==0 ){
8309383016
return 0;
8309483017
}
83095
- if( argv[1] ){
83096
- pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
83097
- }else{
83018
+ if( argv[1]==0 ){
8309883019
pIndex = 0;
83020
+ }else if( sqlite3_stricmp(argv[0],argv[1])==0 ){
83021
+ pIndex = sqlite3PrimaryKeyIndex(pTable);
83022
+ }else{
83023
+ pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
8309983024
}
8310083025
z = argv[2];
8310183026
8310283027
if( pIndex ){
8310383028
decodeIntArray((char*)z, pIndex->nKeyCol+1, pIndex->aiRowEst, pIndex);
@@ -84408,11 +84333,11 @@
8440884333
** transaction on each used database and to verify the schema cookie
8440984334
** on each used database.
8441084335
*/
8441184336
if( pParse->cookieGoto>0 ){
8441284337
yDbMask mask;
84413
- int iDb;
84338
+ int iDb, i, addr;
8441484339
sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
8441584340
for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
8441684341
if( (mask & pParse->cookieMask)==0 ) continue;
8441784342
sqlite3VdbeUsesBtree(v, iDb);
8441884343
sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
@@ -84422,18 +84347,15 @@
8442284347
iDb, pParse->cookieValue[iDb],
8442384348
db->aDb[iDb].pSchema->iGeneration);
8442484349
}
8442584350
}
8442684351
#ifndef SQLITE_OMIT_VIRTUALTABLE
84427
- {
84428
- int i;
84429
- for(i=0; i<pParse->nVtabLock; i++){
84430
- char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84431
- sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
84432
- }
84433
- pParse->nVtabLock = 0;
84434
- }
84352
+ for(i=0; i<pParse->nVtabLock; i++){
84353
+ char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84354
+ sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
84355
+ }
84356
+ pParse->nVtabLock = 0;
8443584357
#endif
8443684358
8443784359
/* Once all the cookies have been verified and transactions opened,
8443884360
** obtain the required table-locks. This is a no-op unless the
8443984361
** shared-cache feature is enabled.
@@ -84441,24 +84363,30 @@
8444184363
codeTableLocks(pParse);
8444284364
8444384365
/* Initialize any AUTOINCREMENT data structures required.
8444484366
*/
8444584367
sqlite3AutoincrementBegin(pParse);
84368
+
84369
+ /* Code constant expressions that where factored out of inner loops */
84370
+ addr = pParse->cookieGoto;
84371
+ if( pParse->pConstExpr ){
84372
+ ExprList *pEL = pParse->pConstExpr;
84373
+ pParse->cookieGoto = 0;
84374
+ for(i=0; i<pEL->nExpr; i++){
84375
+ sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
84376
+ }
84377
+ }
8444684378
8444784379
/* Finally, jump back to the beginning of the executable code. */
84448
- sqlite3VdbeAddOp2(v, OP_Goto, 0, pParse->cookieGoto);
84380
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
8444984381
}
8445084382
}
8445184383
8445284384
8445384385
/* Get the VDBE program ready for execution
8445484386
*/
8445584387
if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
84456
-#ifdef SQLITE_DEBUG
84457
- FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
84458
- sqlite3VdbeTrace(v, trace);
84459
-#endif
8446084388
assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
8446184389
/* A minimum of one cursor is required if autoincrement is used
8446284390
* See ticket [a696379c1f08866] */
8446384391
if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
8446484392
sqlite3VdbeMakeReady(v, pParse);
@@ -89162,24 +89090,38 @@
8916289090
Expr *pWhere /* The WHERE clause. May be null */
8916389091
){
8916489092
Vdbe *v; /* The virtual database engine */
8916589093
Table *pTab; /* The table from which records will be deleted */
8916689094
const char *zDb; /* Name of database holding pTab */
89167
- int end, addr = 0; /* A couple addresses of generated code */
8916889095
int i; /* Loop counter */
8916989096
WhereInfo *pWInfo; /* Information about the WHERE clause */
8917089097
Index *pIdx; /* For looping over indices of the table */
8917189098
int iTabCur; /* Cursor number for the table */
8917289099
int iDataCur; /* VDBE cursor for the canonical data source */
8917389100
int iIdxCur; /* Cursor number of the first index */
89101
+ int nIdx; /* Number of indices */
8917489102
sqlite3 *db; /* Main database structure */
8917589103
AuthContext sContext; /* Authorization context */
8917689104
NameContext sNC; /* Name context to resolve expressions in */
8917789105
int iDb; /* Database number */
8917889106
int memCnt = -1; /* Memory cell used for change counting */
8917989107
int rcauth; /* Value returned by authorization callback */
89180
-
89108
+ int okOnePass; /* True for one-pass algorithm without the FIFO */
89109
+ int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
89110
+ u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
89111
+ Index *pPk; /* The PRIMARY KEY index on the table */
89112
+ int iPk; /* First of nPk registers holding PRIMARY KEY value */
89113
+ i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
89114
+ int iKey; /* Memory cell holding key of row to be deleted */
89115
+ i16 nKey; /* Number of memory cells in the row key */
89116
+ int iEphCur = 0; /* Ephemeral table holding all primary key values */
89117
+ int iRowSet = 0; /* Register for rowset of rows to delete */
89118
+ int addrBypass = 0; /* Address of jump over the delete logic */
89119
+ int addrLoop = 0; /* Top of the delete loop */
89120
+ int addrDelete = 0; /* Jump directly to the delete logic */
89121
+ int addrEphOpen = 0; /* Instruction to open the Ephermeral table */
89122
+
8918189123
#ifndef SQLITE_OMIT_TRIGGER
8918289124
int isView; /* True if attempting to delete from a view */
8918389125
Trigger *pTrigger; /* List of table triggers, if required */
8918489126
#endif
8918589127
@@ -89230,15 +89172,15 @@
8923089172
if( rcauth==SQLITE_DENY ){
8923189173
goto delete_from_cleanup;
8923289174
}
8923389175
assert(!isView || pTrigger);
8923489176
89235
- /* Assign cursor number to the table and all its indices.
89177
+ /* Assign cursor numbers to the table and all its indices.
8923689178
*/
8923789179
assert( pTabList->nSrc==1 );
8923889180
iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
89239
- for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
89181
+ for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
8924089182
pParse->nTab++;
8924189183
}
8924289184
8924389185
/* Start the view context
8924489186
*/
@@ -89300,132 +89242,162 @@
8930089242
assert( pIdx->pSchema==pTab->pSchema );
8930189243
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
8930289244
}
8930389245
}else
8930489246
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
89305
- if( !HasRowid(pTab) ){
89306
- /* There is a WHERE clause on a WITHOUT ROWID table.
89307
- */
89308
- Index *pPk; /* The PRIMARY KEY index on the table */
89309
- int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
89310
- int iEph; /* Ephemeral table holding all primary key values */
89311
- int iKey; /* Key value inserting into iEph */
89312
- i16 nPk; /* Number of components of the PRIMARY KEY */
89313
-
89314
- pPk = sqlite3PrimaryKeyIndex(pTab);
89315
- assert( pPk!=0 );
89316
- nPk = pPk->nKeyCol;
89317
- iPk = pParse->nMem+1;
89318
- pParse->nMem += nPk;
89319
- iKey = ++pParse->nMem;
89320
- iEph = pParse->nTab++;
89321
-
89322
- sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
89323
- sqlite3VdbeSetP4KeyInfo(pParse, pPk);
89324
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, 0, 0);
89325
- if( pWInfo==0 ) goto delete_from_cleanup;
89326
- for(i=0; i<nPk; i++){
89327
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, pPk->aiColumn[i],iPk+i);
89328
- }
89329
- sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89330
- sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89331
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, iKey);
89332
- if( db->flags & SQLITE_CountRows ){
89333
- sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89334
- }
89335
- sqlite3WhereEnd(pWInfo);
89336
-
89337
- /* Open cursors for all indices of the table.
89338
- */
89339
- sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite,
89340
- iTabCur, &iDataCur, &iIdxCur);
89341
-
89342
- /* Loop over the primary keys to be deleted. */
89343
- addr = sqlite3VdbeAddOp1(v, OP_Rewind, iEph);
89344
- sqlite3VdbeAddOp2(v, OP_RowKey, iEph, iPk);
89345
-
89346
- /* Delete the row */
89347
- sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89348
- iPk, 0, 1, OE_Default, 0);
89349
-
89350
- /* End of the delete loop */
89351
- sqlite3VdbeAddOp2(v, OP_Next, iEph, addr+1);
89352
- sqlite3VdbeJumpHere(v, addr);
89353
-
89354
- /* Close the cursors open on the table and its indexes. */
89355
- assert( iDataCur>=iIdxCur );
89356
- for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89357
- sqlite3VdbeAddOp1(v, OP_Close, iIdxCur+i);
89358
- }
89359
- }else{
89360
- /* There is a WHERE clause on a rowid table. Run a loop that extracts
89361
- ** all rowids to be deleted into a RowSet.
89362
- */
89363
- int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
89364
- int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
89365
- int regRowid; /* Actual register containing rowids */
89366
-
89367
- /* Collect rowids of every row to be deleted.
89368
- */
89369
- sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
89370
- pWInfo = sqlite3WhereBegin(
89371
- pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
89372
- );
89373
- if( pWInfo==0 ) goto delete_from_cleanup;
89374
- regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iRowid, 0);
89375
- sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
89376
- if( db->flags & SQLITE_CountRows ){
89377
- sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89378
- }
89379
- sqlite3WhereEnd(pWInfo);
89380
-
89381
- /* Delete every item whose key was written to the list during the
89382
- ** database scan. We have to delete items after the scan is complete
89383
- ** because deleting an item can change the scan order. */
89384
- end = sqlite3VdbeMakeLabel(v);
89385
-
89386
- /* Unless this is a view, open cursors for the table we are
89387
- ** deleting from and all its indices. If this is a view, then the
89388
- ** only effect this statement has is to fire the INSTEAD OF
89389
- ** triggers. */
89390
- if( !isView ){
89391
- sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur,
89392
- &iDataCur, &iIdxCur);
89393
- assert( iDataCur==iTabCur );
89394
- assert( iIdxCur==iDataCur+1 );
89395
- }
89396
-
89397
- addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);
89398
-
89247
+ {
89248
+ if( HasRowid(pTab) ){
89249
+ /* For a rowid table, initialize the RowSet to an empty set */
89250
+ pPk = 0;
89251
+ nPk = 1;
89252
+ iRowSet = ++pParse->nMem;
89253
+ sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
89254
+ }else{
89255
+ /* For a WITHOUT ROWID table, create an ephermeral table used to
89256
+ ** hold all primary keys for rows to be deleted. */
89257
+ pPk = sqlite3PrimaryKeyIndex(pTab);
89258
+ assert( pPk!=0 );
89259
+ nPk = pPk->nKeyCol;
89260
+ iPk = pParse->nMem+1;
89261
+ pParse->nMem += nPk;
89262
+ iEphCur = pParse->nTab++;
89263
+ addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk);
89264
+ sqlite3VdbeSetP4KeyInfo(pParse, pPk);
89265
+ }
89266
+
89267
+ /* Construct a query to find the rowid or primary key for every row
89268
+ ** to be deleted, based on the WHERE clause.
89269
+ */
89270
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
89271
+ WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK,
89272
+ iTabCur+1);
89273
+ if( pWInfo==0 ) goto delete_from_cleanup;
89274
+ okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
89275
+
89276
+ /* Keep track of the number of rows to be deleted */
89277
+ if( db->flags & SQLITE_CountRows ){
89278
+ sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89279
+ }
89280
+
89281
+ /* Extract the rowid or primary key for the current row */
89282
+ if( pPk ){
89283
+ for(i=0; i<nPk; i++){
89284
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
89285
+ pPk->aiColumn[i], iPk+i);
89286
+ }
89287
+ iKey = iPk;
89288
+ }else{
89289
+ iKey = pParse->nMem + 1;
89290
+ iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0);
89291
+ if( iKey>pParse->nMem ) pParse->nMem = iKey;
89292
+ }
89293
+
89294
+ if( okOnePass ){
89295
+ /* For ONEPASS, no need to store the rowid/primary-key. There is only
89296
+ ** one, so just keep it in its register(s) and fall through to the
89297
+ ** delete code.
89298
+ */
89299
+ nKey = nPk; /* OP_Found will use an unpacked key */
89300
+ aToOpen = sqlite3DbMallocRaw(db, nIdx+2);
89301
+ if( aToOpen==0 ){
89302
+ sqlite3WhereEnd(pWInfo);
89303
+ goto delete_from_cleanup;
89304
+ }
89305
+ memset(aToOpen, 1, nIdx+1);
89306
+ aToOpen[nIdx+1] = 0;
89307
+ if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
89308
+ if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
89309
+ if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
89310
+ addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */
89311
+ }else if( pPk ){
89312
+ /* Construct a composite key for the row to be deleted and remember it */
89313
+ iKey = ++pParse->nMem;
89314
+ nKey = 0; /* Zero tells OP_Found to use a composite key */
89315
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89316
+ sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89317
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
89318
+ }else{
89319
+ /* Get the rowid of the row to be deleted and remember it in the RowSet */
89320
+ nKey = 1; /* OP_Seek always uses a single rowid */
89321
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
89322
+ }
89323
+
89324
+ /* End of the WHERE loop */
89325
+ sqlite3WhereEnd(pWInfo);
89326
+ if( okOnePass ){
89327
+ /* Bypass the delete logic below if the WHERE loop found zero rows */
89328
+ addrBypass = sqlite3VdbeMakeLabel(v);
89329
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
89330
+ sqlite3VdbeJumpHere(v, addrDelete);
89331
+ }
89332
+
89333
+ /* Unless this is a view, open cursors for the table we are
89334
+ ** deleting from and all its indices. If this is a view, then the
89335
+ ** only effect this statement has is to fire the INSTEAD OF
89336
+ ** triggers.
89337
+ */
89338
+ if( !isView ){
89339
+ sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen,
89340
+ &iDataCur, &iIdxCur);
89341
+ assert( pPk || iDataCur==iTabCur );
89342
+ assert( pPk || iIdxCur==iDataCur+1 );
89343
+ }
89344
+
89345
+ /* Set up a loop over the rowids/primary-keys that were found in the
89346
+ ** where-clause loop above.
89347
+ */
89348
+ if( okOnePass ){
89349
+ /* Just one row. Hence the top-of-loop is a no-op */
89350
+ assert( nKey==nPk ); /* OP_Found will use an unpacked key */
89351
+ if( aToOpen[iDataCur-iTabCur] ){
89352
+ assert( pPk!=0 );
89353
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
89354
+ }
89355
+ }else if( pPk ){
89356
+ addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
89357
+ sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
89358
+ assert( nKey==0 ); /* OP_Found will use a composite key */
89359
+ }else{
89360
+ addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
89361
+ assert( nKey==1 );
89362
+ }
89363
+
8939989364
/* Delete the row */
8940089365
#ifndef SQLITE_OMIT_VIRTUALTABLE
8940189366
if( IsVirtual(pTab) ){
8940289367
const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
8940389368
sqlite3VtabMakeWritable(pParse, pTab);
89404
- sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);
89369
+ sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);
8940589370
sqlite3VdbeChangeP5(v, OE_Abort);
8940689371
sqlite3MayAbort(pParse);
8940789372
}else
8940889373
#endif
8940989374
{
8941089375
int count = (pParse->nested==0); /* True to count changes */
8941189376
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89412
- iRowid, 1, count, OE_Default, 0);
89377
+ iKey, nKey, count, OE_Default, okOnePass);
8941389378
}
89414
-
89415
- /* End of the delete loop */
89416
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
89417
- sqlite3VdbeResolveLabel(v, end);
89418
-
89379
+
89380
+ /* End of the loop over all rowids/primary-keys. */
89381
+ if( okOnePass ){
89382
+ sqlite3VdbeResolveLabel(v, addrBypass);
89383
+ }else if( pPk ){
89384
+ sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
89385
+ sqlite3VdbeJumpHere(v, addrLoop);
89386
+ }else{
89387
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
89388
+ sqlite3VdbeJumpHere(v, addrLoop);
89389
+ }
89390
+
8941989391
/* Close the cursors open on the table and its indexes. */
8942089392
if( !isView && !IsVirtual(pTab) ){
89421
- sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
89393
+ if( !pPk ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
8942289394
for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
8942389395
sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
8942489396
}
8942589397
}
89426
- }
89398
+ } /* End non-truncate path */
8942789399
8942889400
/* Update the sqlite_sequence table by storing the content of the
8942989401
** maximum rowid counter values recorded while inserting into
8943089402
** autoincrement tables.
8943189403
*/
@@ -89445,10 +89417,11 @@
8944589417
8944689418
delete_from_cleanup:
8944789419
sqlite3AuthContextPop(&sContext);
8944889420
sqlite3SrcListDelete(db, pTabList);
8944989421
sqlite3ExprDelete(db, pWhere);
89422
+ sqlite3DbFree(db, aToOpen);
8945089423
return;
8945189424
}
8945289425
/* Make sure "isView" and other macros defined above are undefined. Otherwise
8945389426
** thely may interfere with compilation of other functions in this file
8945489427
** (or in another file, if this file becomes part of the amalgamation). */
@@ -89511,10 +89484,11 @@
8951189484
/* If there are any triggers to fire, allocate a range of registers to
8951289485
** use for the old.* references in the triggers. */
8951389486
if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
8951489487
u32 mask; /* Mask of OLD.* columns in use */
8951589488
int iCol; /* Iterator used while populating OLD.* */
89489
+ int addrStart; /* Start of BEFORE trigger programs */
8951689490
8951789491
/* TODO: Could use temporary registers here. Also could attempt to
8951889492
** avoid copying the contents of the rowid register. */
8951989493
mask = sqlite3TriggerColmask(
8952089494
pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
@@ -89531,19 +89505,23 @@
8953189505
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
8953289506
}
8953389507
}
8953489508
8953589509
/* Invoke BEFORE DELETE trigger programs. */
89510
+ addrStart = sqlite3VdbeCurrentAddr(v);
8953689511
sqlite3CodeRowTrigger(pParse, pTrigger,
8953789512
TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
8953889513
);
8953989514
89540
- /* Seek the cursor to the row to be deleted again. It may be that
89541
- ** the BEFORE triggers coded above have already removed the row
89542
- ** being deleted. Do not attempt to delete the row a second time, and
89543
- ** do not fire AFTER triggers. */
89544
- sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89515
+ /* If any BEFORE triggers were coded, then seek the cursor to the
89516
+ ** row to be deleted again. It may be that the BEFORE triggers moved
89517
+ ** the cursor or of already deleted the row that the cursor was
89518
+ ** pointing to.
89519
+ */
89520
+ if( addrStart<sqlite3VdbeCurrentAddr(v) ){
89521
+ sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89522
+ }
8954589523
8954689524
/* Do FK processing. This call checks that any FK constraints that
8954789525
** refer to this table (i.e. constraints attached to other tables)
8954889526
** are not violated by deleting this row. */
8954989527
sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -91969,10 +91947,11 @@
9196991947
Vdbe *v = sqlite3GetVdbe(pParse);
9197091948
9197191949
assert( pIdx==0 || pIdx->pTable==pTab );
9197291950
assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
9197391951
assert( pIdx!=0 || pFKey->nCol==1 );
91952
+ assert( pIdx!=0 || HasRowid(pTab) );
9197491953
9197591954
if( nIncr<0 ){
9197691955
iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
9197791956
}
9197891957
@@ -92021,10 +92000,11 @@
9202192000
pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
9202292001
pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
9202392002
}else{
9202492003
Expr *pEq, *pAll = 0;
9202592004
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
92005
+ assert( pIdx!=0 );
9202692006
for(i=0; i<pPk->nKeyCol; i++){
9202792007
i16 iCol = pIdx->aiColumn[i];
9202892008
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
9202992009
pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
9203092010
pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
@@ -93599,11 +93579,11 @@
9359993579
}
9360093580
9360193581
/* If this is not a view, open the table and and all indices */
9360293582
if( !isView ){
9360393583
int nIdx;
93604
- nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1,
93584
+ nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1, 0,
9360593585
&iDataCur, &iIdxCur);
9360693586
aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
9360793587
if( aRegIdx==0 ){
9360893588
goto insert_cleanup;
9360993589
}
@@ -94459,42 +94439,50 @@
9445994439
SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
9446094440
Parse *pParse, /* Parsing context */
9446194441
Table *pTab, /* Table to be opened */
9446294442
int op, /* OP_OpenRead or OP_OpenWrite */
9446394443
int iBase, /* Use this for the table cursor, if there is one */
94444
+ u8 *aToOpen, /* If not NULL: boolean for each table and index */
9446494445
int *piDataCur, /* Write the database source cursor number here */
9446594446
int *piIdxCur /* Write the first index cursor number here */
9446694447
){
9446794448
int i;
9446894449
int iDb;
94450
+ int iDataCur;
9446994451
Index *pIdx;
9447094452
Vdbe *v;
9447194453
9447294454
assert( op==OP_OpenRead || op==OP_OpenWrite );
9447394455
if( IsVirtual(pTab) ){
94456
+ assert( aToOpen==0 );
9447494457
*piDataCur = 0;
9447594458
*piIdxCur = 1;
9447694459
return 0;
9447794460
}
9447894461
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
9447994462
v = sqlite3GetVdbe(pParse);
9448094463
assert( v!=0 );
9448194464
if( iBase<0 ) iBase = pParse->nTab;
94482
- if( HasRowid(pTab) ){
94483
- *piDataCur = iBase++;
94484
- sqlite3OpenTable(pParse, *piDataCur, iDb, pTab, op);
94465
+ iDataCur = iBase++;
94466
+ if( piDataCur ) *piDataCur = iDataCur;
94467
+ if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
94468
+ sqlite3OpenTable(pParse, iDataCur, iDb, pTab, op);
9448594469
}else{
9448694470
sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
9448794471
}
94488
- *piIdxCur = iBase;
94472
+ if( piIdxCur ) *piIdxCur = iBase;
9448994473
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
9449094474
int iIdxCur = iBase++;
9449194475
assert( pIdx->pSchema==pTab->pSchema );
94492
- if( pIdx->autoIndex==2 && !HasRowid(pTab) ) *piDataCur = iIdxCur;
94493
- sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
94494
- sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
94495
- VdbeComment((v, "%s", pIdx->zName));
94476
+ if( pIdx->autoIndex==2 && !HasRowid(pTab) && piDataCur ){
94477
+ *piDataCur = iIdxCur;
94478
+ }
94479
+ if( aToOpen==0 || aToOpen[i+1] ){
94480
+ sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
94481
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
94482
+ VdbeComment((v, "%s", pIdx->zName));
94483
+ }
9449694484
}
9449794485
if( iBase>pParse->nTab ) pParse->nTab = iBase;
9449894486
return i;
9449994487
}
9450094488
@@ -96664,10 +96652,14 @@
9666496652
/* iArg: */ SQLITE_VdbeAddopTrace },
9666596653
{ /* zName: */ "vdbe_debug",
9666696654
/* ePragTyp: */ PragTyp_FLAG,
9666796655
/* ePragFlag: */ 0,
9666896656
/* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
96657
+ { /* zName: */ "vdbe_eqp",
96658
+ /* ePragTyp: */ PragTyp_FLAG,
96659
+ /* ePragFlag: */ 0,
96660
+ /* iArg: */ SQLITE_VdbeEQP },
9666996661
{ /* zName: */ "vdbe_listing",
9667096662
/* ePragTyp: */ PragTyp_FLAG,
9667196663
/* ePragFlag: */ 0,
9667296664
/* iArg: */ SQLITE_VdbeListing },
9667396665
{ /* zName: */ "vdbe_trace",
@@ -96691,11 +96683,11 @@
9669196683
/* ePragTyp: */ PragTyp_FLAG,
9669296684
/* ePragFlag: */ 0,
9669396685
/* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
9669496686
#endif
9669596687
};
96696
-/* Number of pragmas: 56 on by default, 68 total. */
96688
+/* Number of pragmas: 56 on by default, 69 total. */
9669796689
/* End of the automatically generated pragma table.
9669896690
***************************************************************************/
9669996691
9670096692
/*
9670196693
** Interpret the given string as a safety level. Return 0 for OFF,
@@ -98117,11 +98109,11 @@
9811798109
addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
9811898110
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9811998111
sqlite3VdbeJumpHere(v, addr);
9812098112
sqlite3ExprCacheClear(pParse);
9812198113
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98122
- 1, &iDataCur, &iIdxCur);
98114
+ 1, 0, &iDataCur, &iIdxCur);
9812398115
sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
9812498116
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
9812598117
sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
9812698118
}
9812798119
pParse->nMem = MAX(pParse->nMem, 8+j);
@@ -99052,10 +99044,17 @@
9905299044
}
9905399045
assert( i>=0 && i<db->nDb );
9905499046
}
9905599047
return i;
9905699048
}
99049
+
99050
+/*
99051
+** Free all memory allocations in the pParse object
99052
+*/
99053
+SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
99054
+ if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
99055
+}
9905799056
9905899057
/*
9905999058
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
9906099059
*/
9906199060
static int sqlite3Prepare(
@@ -99210,10 +99209,11 @@
9921099209
sqlite3DbFree(db, pT);
9921199210
}
9921299211
9921399212
end_prepare:
9921499213
99214
+ sqlite3ParserReset(pParse);
9921599215
sqlite3StackFree(db, pParse);
9921699216
rc = sqlite3ApiExit(db, rc);
9921799217
assert( (rc&db->errMask)==rc );
9921899218
return rc;
9921999219
}
@@ -101776,20 +101776,20 @@
101776101776
*/
101777101777
if( op!=TK_ALL ){
101778101778
for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
101779101779
struct ExprList_item *pItem;
101780101780
for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
101781
- assert( pItem->iOrderByCol>0 );
101782
- if( pItem->iOrderByCol==i ) break;
101781
+ assert( pItem->u.x.iOrderByCol>0 );
101782
+ if( pItem->u.x.iOrderByCol==i ) break;
101783101783
}
101784101784
if( j==nOrderBy ){
101785101785
Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
101786101786
if( pNew==0 ) return SQLITE_NOMEM;
101787101787
pNew->flags |= EP_IntValue;
101788101788
pNew->u.iValue = i;
101789101789
pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
101790
- if( pOrderBy ) pOrderBy->a[nOrderBy++].iOrderByCol = (u16)i;
101790
+ if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
101791101791
}
101792101792
}
101793101793
}
101794101794
101795101795
/* Compute the comparison permutation and keyinfo that is used with
@@ -101801,12 +101801,13 @@
101801101801
*/
101802101802
aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
101803101803
if( aPermute ){
101804101804
struct ExprList_item *pItem;
101805101805
for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
101806
- assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
101807
- aPermute[i] = pItem->iOrderByCol - 1;
101806
+ assert( pItem->u.x.iOrderByCol>0
101807
+ && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
101808
+ aPermute[i] = pItem->u.x.iOrderByCol - 1;
101808101809
}
101809101810
pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
101810101811
if( pKeyMerge ){
101811101812
for(i=0; i<nOrderBy; i++){
101812101813
CollSeq *pColl;
@@ -102382,11 +102383,11 @@
102382102383
102383102384
/* Restriction 18. */
102384102385
if( p->pOrderBy ){
102385102386
int ii;
102386102387
for(ii=0; ii<p->pOrderBy->nExpr; ii++){
102387
- if( p->pOrderBy->a[ii].iOrderByCol==0 ) return 0;
102388
+ if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
102388102389
}
102389102390
}
102390102391
}
102391102392
102392102393
/***** If we reach this point, flattening is permitted. *****/
@@ -103789,14 +103790,14 @@
103789103790
if( pGroupBy ){
103790103791
int k; /* Loop counter */
103791103792
struct ExprList_item *pItem; /* For looping over expression in a list */
103792103793
103793103794
for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
103794
- pItem->iAlias = 0;
103795
+ pItem->u.x.iAlias = 0;
103795103796
}
103796103797
for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
103797
- pItem->iAlias = 0;
103798
+ pItem->u.x.iAlias = 0;
103798103799
}
103799103800
if( p->nSelectRow>100 ) p->nSelectRow = 100;
103800103801
}else{
103801103802
p->nSelectRow = 1;
103802103803
}
@@ -105443,10 +105444,11 @@
105443105444
sqlite3VdbeDelete(v);
105444105445
}
105445105446
105446105447
assert( !pSubParse->pAinc && !pSubParse->pZombieTab );
105447105448
assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
105449
+ sqlite3ParserReset(pSubParse);
105448105450
sqlite3StackFree(db, pSubParse);
105449105451
105450105452
return pPrg;
105451105453
}
105452105454
@@ -105757,22 +105759,23 @@
105757105759
WhereInfo *pWInfo; /* Information about the WHERE clause */
105758105760
Vdbe *v; /* The virtual database engine */
105759105761
Index *pIdx; /* For looping over indices */
105760105762
Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
105761105763
int nIdx; /* Number of indices that need updating */
105764
+ int iBaseCur; /* Base cursor number */
105762105765
int iDataCur; /* Cursor for the canonical data btree */
105763105766
int iIdxCur; /* Cursor for the first index */
105764105767
sqlite3 *db; /* The database structure */
105765105768
int *aRegIdx = 0; /* One register assigned to each index to be updated */
105766105769
int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
105767105770
** an expression for the i-th column of the table.
105768105771
** aXRef[i]==-1 if the i-th column is not changed. */
105772
+ u8 *aToOpen; /* 1 for tables and indices to be opened */
105769105773
u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
105770105774
u8 chngRowid; /* Rowid changed in a normal table */
105771105775
u8 chngKey; /* Either chngPk or chngRowid */
105772105776
Expr *pRowidExpr = 0; /* Expression defining the new record number */
105773
- int openAll = 0; /* True if all indices need to be opened */
105774105777
AuthContext sContext; /* The authorization context */
105775105778
NameContext sNC; /* The name-context to resolve expressions in */
105776105779
int iDb; /* Database containing the table being updated */
105777105780
int okOnePass; /* True for one-pass algorithm without the FIFO */
105778105781
int hasFK; /* True if foreign key processing is required */
@@ -105832,29 +105835,37 @@
105832105835
goto update_cleanup;
105833105836
}
105834105837
if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
105835105838
goto update_cleanup;
105836105839
}
105837
- aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
105838
- if( aXRef==0 ) goto update_cleanup;
105839
- for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
105840105840
105841105841
/* Allocate a cursors for the main database table and for all indices.
105842105842
** The index cursors might not be used, but if they are used they
105843105843
** need to occur right after the database cursor. So go ahead and
105844105844
** allocate enough space, just in case.
105845105845
*/
105846
- pTabList->a[0].iCursor = iDataCur = pParse->nTab++;
105846
+ pTabList->a[0].iCursor = iBaseCur = iDataCur = pParse->nTab++;
105847105847
iIdxCur = iDataCur+1;
105848105848
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
105849105849
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
105850105850
if( pIdx->autoIndex==2 && pPk!=0 ){
105851105851
iDataCur = pParse->nTab;
105852105852
pTabList->a[0].iCursor = iDataCur;
105853105853
}
105854105854
pParse->nTab++;
105855105855
}
105856
+
105857
+ /* Allocate space for aXRef[], aRegIdx[], and aToOpen[].
105858
+ ** Initialize aXRef[] and aToOpen[] to their default values.
105859
+ */
105860
+ aXRef = sqlite3DbMallocRaw(db, sizeof(int) * (pTab->nCol+nIdx) + nIdx+2 );
105861
+ if( aXRef==0 ) goto update_cleanup;
105862
+ aRegIdx = aXRef+pTab->nCol;
105863
+ aToOpen = (u8*)(aRegIdx+nIdx);
105864
+ memset(aToOpen, 1, nIdx+1);
105865
+ aToOpen[nIdx+1] = 0;
105866
+ for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
105856105867
105857105868
/* Initialize the name-context */
105858105869
memset(&sNC, 0, sizeof(sNC));
105859105870
sNC.pParse = pParse;
105860105871
sNC.pSrcList = pTabList;
@@ -105909,22 +105920,22 @@
105909105920
}
105910105921
assert( (chngRowid & chngPk)==0 );
105911105922
assert( chngRowid==0 || chngRowid==1 );
105912105923
assert( chngPk==0 || chngPk==1 );
105913105924
chngKey = chngRowid + chngPk;
105925
+
105926
+ /* The SET expressions are not actually used inside the WHERE loop.
105927
+ ** So reset the colUsed mask
105928
+ */
105929
+ pTabList->a[0].colUsed = 0;
105914105930
105915105931
hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
105916105932
105917
- /* Allocate memory for the array aRegIdx[]. There is one entry in the
105918
- ** array for each index associated with table being updated. Fill in
105919
- ** the value with a register number for indices that are to be used
105920
- ** and with zero for unused indices.
105933
+ /* There is one entry in the aRegIdx[] array for each index on the table
105934
+ ** being updated. Fill in aRegIdx[] with a register number that will hold
105935
+ ** the key for accessing each index.
105921105936
*/
105922
- if( nIdx>0 ){
105923
- aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
105924
- if( aRegIdx==0 ) goto update_cleanup;
105925
- }
105926105937
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
105927105938
int reg;
105928105939
if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
105929105940
reg = ++pParse->nMem;
105930105941
}else{
@@ -105934,10 +105945,11 @@
105934105945
reg = ++pParse->nMem;
105935105946
break;
105936105947
}
105937105948
}
105938105949
}
105950
+ if( reg==0 ) aToOpen[j+1] = 0;
105939105951
aRegIdx[j] = reg;
105940105952
}
105941105953
105942105954
/* Begin generating code. */
105943105955
v = sqlite3GetVdbe(pParse);
@@ -106057,46 +106069,34 @@
106057106069
** Open every index that needs updating. Note that if any
106058106070
** index could potentially invoke a REPLACE conflict resolution
106059106071
** action, then we need to open all indices because we might need
106060106072
** to be deleting some records.
106061106073
*/
106062
- if( !okOnePass && HasRowid(pTab) ){
106063
- sqlite3OpenTable(pParse, iDataCur, iDb, pTab, OP_OpenWrite);
106064
- }
106065
- sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
106066106074
if( onError==OE_Replace ){
106067
- openAll = 1;
106075
+ memset(aToOpen, 1, nIdx+1);
106068106076
}else{
106069
- openAll = 0;
106070106077
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
106071106078
if( pIdx->onError==OE_Replace ){
106072
- openAll = 1;
106079
+ memset(aToOpen, 1, nIdx+1);
106073106080
break;
106074106081
}
106075106082
}
106076106083
}
106077
- for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106078
- int iThisCur = iIdxCur+i;
106079
- assert( aRegIdx );
106080
- if( (openAll || aRegIdx[i]>0)
106081
- && iThisCur!=aiCurOnePass[1]
106082
- ){
106083
- assert( iThisCur!=aiCurOnePass[0] );
106084
- sqlite3VdbeAddOp3(v, OP_OpenWrite, iThisCur, pIdx->tnum, iDb);
106085
- sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
106086
- assert( pParse->nTab>iThisCur );
106087
- VdbeComment((v, "%s", pIdx->zName));
106088
- if( okOnePass && pPk && iThisCur==iDataCur ){
106089
- sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak,
106090
- regKey, nKey);
106091
- }
106092
- }
106093
- }
106084
+ if( okOnePass ){
106085
+ if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
106086
+ if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
106087
+ }
106088
+ sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iBaseCur, aToOpen,
106089
+ 0, 0);
106094106090
}
106095106091
106096106092
/* Top of the update loop */
106097106093
if( okOnePass ){
106094
+ if( aToOpen[iDataCur-iBaseCur] ){
106095
+ assert( pPk!=0 );
106096
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
106097
+ }
106098106098
labelContinue = labelBreak;
106099106099
sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106100106100
}else if( pPk ){
106101106101
labelContinue = sqlite3VdbeMakeLabel(v);
106102106102
sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
@@ -106285,11 +106285,11 @@
106285106285
sqlite3VdbeResolveLabel(v, labelBreak);
106286106286
106287106287
/* Close all tables */
106288106288
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106289106289
assert( aRegIdx );
106290
- if( openAll || aRegIdx[i]>0 ){
106290
+ if( aToOpen[i+1] ){
106291106291
sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
106292106292
}
106293106293
}
106294106294
if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
106295106295
@@ -106312,12 +106312,11 @@
106312106312
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
106313106313
}
106314106314
106315106315
update_cleanup:
106316106316
sqlite3AuthContextPop(&sContext);
106317
- sqlite3DbFree(db, aRegIdx);
106318
- sqlite3DbFree(db, aXRef);
106317
+ sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
106319106318
sqlite3SrcListDelete(db, pTabList);
106320106319
sqlite3ExprListDelete(db, pChanges);
106321106320
sqlite3ExprDelete(db, pWhere);
106322106321
return;
106323106322
}
@@ -107536,10 +107535,11 @@
107536107535
107537107536
if( pParse->pVdbe ){
107538107537
sqlite3VdbeFinalize(pParse->pVdbe);
107539107538
}
107540107539
sqlite3DeleteTable(db, pParse->pNewTable);
107540
+ sqlite3ParserReset(pParse);
107541107541
sqlite3StackFree(db, pParse);
107542107542
}
107543107543
107544107544
assert( (rc&0xff)==rc );
107545107545
rc = sqlite3ApiExit(db, rc);
@@ -107913,11 +107913,28 @@
107913107913
** generating the code that loops through a table looking for applicable
107914107914
** rows. Indices are selected and used to speed the search when doing
107915107915
** so is applicable. Because this module is responsible for selecting
107916107916
** indices, you might also think of this module as the "query optimizer".
107917107917
*/
107918
-
107918
+/************** Include whereInt.h in the middle of where.c ******************/
107919
+/************** Begin file whereInt.h ****************************************/
107920
+/*
107921
+** 2013-11-12
107922
+**
107923
+** The author disclaims copyright to this source code. In place of
107924
+** a legal notice, here is a blessing:
107925
+**
107926
+** May you do good and not evil.
107927
+** May you find forgiveness for yourself and forgive others.
107928
+** May you share freely, never taking more than you give.
107929
+**
107930
+*************************************************************************
107931
+**
107932
+** This file contains structure and macro definitions for the query
107933
+** planner logic in "where.c". These definitions are broken out into
107934
+** a separate source file for easier editing.
107935
+*/
107919107936
107920107937
/*
107921107938
** Trace output macros
107922107939
*/
107923107940
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
@@ -107965,10 +107982,11 @@
107965107982
int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
107966107983
int iTabCur; /* The VDBE cursor used to access the table */
107967107984
int iIdxCur; /* The VDBE cursor used to access pIdx */
107968107985
int addrBrk; /* Jump here to break out of the loop */
107969107986
int addrNxt; /* Jump here to start the next IN combination */
107987
+ int addrSkip; /* Jump here for next iteration of skip-scan */
107970107988
int addrCont; /* Jump here to continue with the next loop cycle */
107971107989
int addrFirst; /* First instruction of interior of the loop */
107972107990
int addrBody; /* Beginning of the body of this loop */
107973107991
u8 iFrom; /* Which entry in the FROM clause */
107974107992
u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
@@ -108014,11 +108032,11 @@
108014108032
LogEst rRun; /* Cost of running each loop */
108015108033
LogEst nOut; /* Estimated number of output rows */
108016108034
union {
108017108035
struct { /* Information for internal btree tables */
108018108036
u16 nEq; /* Number of equality constraints */
108019
- u16 nSkip; /* Number of initial index columns skipped */
108037
+ u16 nSkip; /* Number of initial index columns to skip */
108020108038
Index *pIndex; /* Index used, or NULL */
108021108039
} btree;
108022108040
struct { /* Information for virtual tables */
108023108041
int idxNum; /* Index number */
108024108042
u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -108355,10 +108373,14 @@
108355108373
#define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
108356108374
#define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108357108375
#define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108358108376
#define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108359108377
#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
108378
+#define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
108379
+
108380
+/************** End of whereInt.h ********************************************/
108381
+/************** Continuing where we left off in where.c **********************/
108360108382
108361108383
/*
108362108384
** Return the estimated number of output rows from a WHERE clause
108363108385
*/
108364108386
SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
@@ -109006,13 +109028,10 @@
109006109028
}
109007109029
assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
109008109030
109009109031
pRight = pList->a[0].pExpr;
109010109032
op = pRight->op;
109011
- if( op==TK_REGISTER ){
109012
- op = pRight->op2;
109013
- }
109014109033
if( op==TK_VARIABLE ){
109015109034
Vdbe *pReprepare = pParse->pReprepare;
109016109035
int iCol = pRight->iColumn;
109017109036
pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_NONE);
109018109037
if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
@@ -110759,11 +110778,11 @@
110759110778
return iReg;
110760110779
}
110761110780
110762110781
/*
110763110782
** Generate code that will evaluate all == and IN constraints for an
110764
-** index.
110783
+** index scan.
110765110784
**
110766110785
** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
110767110786
** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
110768110787
** The index has as many as three equality constraints, but in this
110769110788
** example, the third "c" value is an inequality. So only two
@@ -110774,13 +110793,19 @@
110774110793
** In the example above nEq==2. But this subroutine works for any value
110775110794
** of nEq including 0. If nEq==0, this routine is nearly a no-op.
110776110795
** The only thing it does is allocate the pLevel->iMem memory cell and
110777110796
** compute the affinity string.
110778110797
**
110779
-** This routine always allocates at least one memory cell and returns
110780
-** the index of that memory cell. The code that
110781
-** calls this routine will use that memory cell to store the termination
110798
+** The nExtraReg parameter is 0 or 1. It is 0 if all WHERE clause constraints
110799
+** are == or IN and are covered by the nEq. nExtraReg is 1 if there is
110800
+** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
110801
+** occurs after the nEq quality constraints.
110802
+**
110803
+** This routine allocates a range of nEq+nExtraReg memory cells and returns
110804
+** the index of the first memory cell in that range. The code that
110805
+** calls this routine will use that memory range to store keys for
110806
+** start and termination conditions of the loop.
110782110807
** key value of the loop. If one or more IN operators appear, then
110783110808
** this routine allocates an additional nEq memory cells for internal
110784110809
** use.
110785110810
**
110786110811
** Before returning, *pzAff is set to point to a buffer containing a
@@ -110803,11 +110828,12 @@
110803110828
WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
110804110829
int bRev, /* Reverse the order of IN operators */
110805110830
int nExtraReg, /* Number of extra registers to allocate */
110806110831
char **pzAff /* OUT: Set to point to affinity string */
110807110832
){
110808
- int nEq; /* The number of == or IN constraints to code */
110833
+ u16 nEq; /* The number of == or IN constraints to code */
110834
+ u16 nSkip; /* Number of left-most columns to skip */
110809110835
Vdbe *v = pParse->pVdbe; /* The vm under construction */
110810110836
Index *pIdx; /* The index being used for this loop */
110811110837
WhereTerm *pTerm; /* A single constraint term */
110812110838
WhereLoop *pLoop; /* The WhereLoop object */
110813110839
int j; /* Loop counter */
@@ -110817,10 +110843,11 @@
110817110843
110818110844
/* This module is only called on query plans that use an index. */
110819110845
pLoop = pLevel->pWLoop;
110820110846
assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
110821110847
nEq = pLoop->u.btree.nEq;
110848
+ nSkip = pLoop->u.btree.nSkip;
110822110849
pIdx = pLoop->u.btree.pIndex;
110823110850
assert( pIdx!=0 );
110824110851
110825110852
/* Figure out how many memory cells we will need then allocate them.
110826110853
*/
@@ -110830,19 +110857,34 @@
110830110857
110831110858
zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
110832110859
if( !zAff ){
110833110860
pParse->db->mallocFailed = 1;
110834110861
}
110862
+
110863
+ if( nSkip ){
110864
+ int iIdxCur = pLevel->iIdxCur;
110865
+ sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
110866
+ VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
110867
+ j = sqlite3VdbeAddOp0(v, OP_Goto);
110868
+ pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
110869
+ iIdxCur, 0, regBase, nSkip);
110870
+ sqlite3VdbeJumpHere(v, j);
110871
+ for(j=0; j<nSkip; j++){
110872
+ sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
110873
+ assert( pIdx->aiColumn[j]>=0 );
110874
+ VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
110875
+ }
110876
+ }
110835110877
110836110878
/* Evaluate the equality constraints
110837110879
*/
110838110880
assert( zAff==0 || (int)strlen(zAff)>=nEq );
110839
- for(j=0; j<nEq; j++){
110881
+ for(j=nSkip; j<nEq; j++){
110840110882
int r1;
110841110883
pTerm = pLoop->aLTerm[j];
110842110884
assert( pTerm!=0 );
110843
- /* The following true for indices with redundant columns.
110885
+ /* The following testcase is true for indices with redundant columns.
110844110886
** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
110845110887
testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
110846110888
testcase( pTerm->wtFlags & TERM_VIRTUAL );
110847110889
r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
110848110890
if( r1!=regBase+j ){
@@ -110912,11 +110954,12 @@
110912110954
** It is the responsibility of the caller to free the buffer when it is
110913110955
** no longer required.
110914110956
*/
110915110957
static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
110916110958
Index *pIndex = pLoop->u.btree.pIndex;
110917
- int nEq = pLoop->u.btree.nEq;
110959
+ u16 nEq = pLoop->u.btree.nEq;
110960
+ u16 nSkip = pLoop->u.btree.nSkip;
110918110961
int i, j;
110919110962
Column *aCol = pTab->aCol;
110920110963
i16 *aiColumn = pIndex->aiColumn;
110921110964
StrAccum txt;
110922110965
@@ -110926,11 +110969,18 @@
110926110969
sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
110927110970
txt.db = db;
110928110971
sqlite3StrAccumAppend(&txt, " (", 2);
110929110972
for(i=0; i<nEq; i++){
110930110973
char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
110931
- explainAppendTerm(&txt, i, z, "=");
110974
+ if( i>=nSkip ){
110975
+ explainAppendTerm(&txt, i, z, "=");
110976
+ }else{
110977
+ if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
110978
+ sqlite3StrAccumAppend(&txt, "ANY(", 4);
110979
+ sqlite3StrAccumAppend(&txt, z, -1);
110980
+ sqlite3StrAccumAppend(&txt, ")", 1);
110981
+ }
110932110982
}
110933110983
110934110984
j = i;
110935110985
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
110936110986
char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -110956,11 +111006,14 @@
110956111006
WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
110957111007
int iLevel, /* Value for "level" column of output */
110958111008
int iFrom, /* Value for "from" column of output */
110959111009
u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
110960111010
){
110961
- if( pParse->explain==2 ){
111011
+#ifndef SQLITE_DEBUG
111012
+ if( pParse->explain==2 )
111013
+#endif
111014
+ {
110962111015
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
110963111016
Vdbe *v = pParse->pVdbe; /* VM being constructed */
110964111017
sqlite3 *db = pParse->db; /* Database handle */
110965111018
char *zMsg; /* Text to add to EQP output */
110966111019
int iId = pParse->iSelectId; /* Select id (left-most output column) */
@@ -111062,11 +111115,11 @@
111062111115
iCur = pTabItem->iCursor;
111063111116
pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
111064111117
bRev = (pWInfo->revMask>>iLevel)&1;
111065111118
omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
111066111119
&& (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
111067
- VdbeNoopComment((v, "Begin WHERE-Loop %d: %s", iLevel,pTabItem->pTab->zName));
111120
+ VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
111068111121
111069111122
/* Create labels for the "break" and "continue" instructions
111070111123
** for the current loop. Jump to addrBrk to break out of a loop.
111071111124
** Jump to cont to go immediately to the next iteration of the
111072111125
** loop.
@@ -111289,12 +111342,12 @@
111289111342
static const u8 aEndOp[] = {
111290111343
OP_Noop, /* 0: (!end_constraints) */
111291111344
OP_IdxGE, /* 1: (end_constraints && !bRev) */
111292111345
OP_IdxLT /* 2: (end_constraints && bRev) */
111293111346
};
111294
- int nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111295
- int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111347
+ u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111348
+ int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111296111349
int regBase; /* Base register holding constraint values */
111297111350
int r1; /* Temp register */
111298111351
WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111299111352
WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111300111353
int startEq; /* True if range start uses ==, >= or <= */
@@ -111304,14 +111357,15 @@
111304111357
Index *pIdx; /* The index we will be using */
111305111358
int iIdxCur; /* The VDBE cursor for the index */
111306111359
int nExtraReg = 0; /* Number of extra registers needed */
111307111360
int op; /* Instruction opcode */
111308111361
char *zStartAff; /* Affinity for start of range constraint */
111309
- char *zEndAff; /* Affinity for end of range constraint */
111362
+ char cEndAff = 0; /* Affinity for end of range constraint */
111310111363
111311111364
pIdx = pLoop->u.btree.pIndex;
111312111365
iIdxCur = pLevel->iIdxCur;
111366
+ assert( nEq>=pLoop->u.btree.nSkip );
111313111367
111314111368
/* If this loop satisfies a sort order (pOrderBy) request that
111315111369
** was passed to this function to implement a "SELECT min(x) ..."
111316111370
** query, then the caller will only allow the loop to run for
111317111371
** a single iteration. This means that the first row returned
@@ -111321,12 +111375,11 @@
111321111375
*/
111322111376
if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111323111377
&& (pWInfo->bOBSat!=0)
111324111378
&& (pIdx->nKeyCol>nEq)
111325111379
){
111326
- /* assert( pOrderBy->nExpr==1 ); */
111327
- /* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
111380
+ assert( pLoop->u.btree.nSkip==0 );
111328111381
isMinQuery = 1;
111329111382
nExtraReg = 1;
111330111383
}
111331111384
111332111385
/* Find any inequality constraint terms for the start and end
@@ -111345,11 +111398,12 @@
111345111398
/* Generate code to evaluate all constraint terms using == or IN
111346111399
** and store the values of those terms in an array of registers
111347111400
** starting at regBase.
111348111401
*/
111349111402
regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
111350
- zEndAff = sqlite3DbStrDup(db, zStartAff);
111403
+ assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
111404
+ if( zStartAff ) cEndAff = zStartAff[nEq];
111351111405
addrNxt = pLevel->addrNxt;
111352111406
111353111407
/* If we are doing a reverse order scan on an ascending index, or
111354111408
** a forward order scan on a descending index, interchange the
111355111409
** start and end terms (pRangeStart and pRangeEnd).
@@ -111415,27 +111469,19 @@
111415111469
sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111416111470
sqlite3ExprCode(pParse, pRight, regBase+nEq);
111417111471
if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111418111472
sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
111419111473
}
111420
- if( zEndAff ){
111421
- if( sqlite3CompareAffinity(pRight, zEndAff[nEq])==SQLITE_AFF_NONE){
111422
- /* Since the comparison is to be performed with no conversions
111423
- ** applied to the operands, set the affinity to apply to pRight to
111424
- ** SQLITE_AFF_NONE. */
111425
- zEndAff[nEq] = SQLITE_AFF_NONE;
111426
- }
111427
- if( sqlite3ExprNeedsNoAffinityChange(pRight, zEndAff[nEq]) ){
111428
- zEndAff[nEq] = SQLITE_AFF_NONE;
111429
- }
111430
- }
111431
- codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
111474
+ if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
111475
+ && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
111476
+ ){
111477
+ codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
111478
+ }
111432111479
nConstraint++;
111433111480
testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
111434111481
}
111435111482
sqlite3DbFree(db, zStartAff);
111436
- sqlite3DbFree(db, zEndAff);
111437111483
111438111484
/* Top of the loop body */
111439111485
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111440111486
111441111487
/* Check if the index cursor is past the end of the range. */
@@ -111453,12 +111499,17 @@
111453111499
** If it is, jump to the next iteration of the loop.
111454111500
*/
111455111501
r1 = sqlite3GetTempReg(pParse);
111456111502
testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111457111503
testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111458
- if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 ){
111504
+ if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
111505
+ && (j = pIdx->aiColumn[nEq])>=0
111506
+ && pIdx->pTable->aCol[j].notNull==0
111507
+ && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0)
111508
+ ){
111459111509
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
111510
+ VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName));
111460111511
sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111461111512
}
111462111513
sqlite3ReleaseTempReg(pParse, r1);
111463111514
111464111515
/* Seek the table cursor, if required */
@@ -111769,11 +111820,11 @@
111769111820
pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
111770111821
if( pAlt==0 ) continue;
111771111822
if( pAlt->wtFlags & (TERM_CODED) ) continue;
111772111823
testcase( pAlt->eOperator & WO_EQ );
111773111824
testcase( pAlt->eOperator & WO_IN );
111774
- VdbeNoopComment((v, "begin transitive constraint"));
111825
+ VdbeModuleComment((v, "begin transitive constraint"));
111775111826
pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
111776111827
if( pEAlt ){
111777111828
*pEAlt = *pAlt->pExpr;
111778111829
pEAlt->pLeft = pE->pLeft;
111779111830
sqlite3ExprIfFalse(pParse, pEAlt, addrCont, SQLITE_JUMPIFNULL);
@@ -111842,16 +111893,11 @@
111842111893
if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
111843111894
int i = sqlite3Strlen30(zName) - 1;
111844111895
while( zName[i]!='_' ) i--;
111845111896
zName += i;
111846111897
}
111847
- if( p->u.btree.nSkip ){
111848
- sqlite3DebugPrintf(".%-15s %d+%d", zName,
111849
- p->u.btree.nSkip, p->u.btree.nEq);
111850
- }else{
111851
- sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
111852
- }
111898
+ sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
111853111899
}else{
111854111900
sqlite3DebugPrintf("%20s","");
111855111901
}
111856111902
}else{
111857111903
char *z;
@@ -111874,10 +111920,11 @@
111874111920
int i;
111875111921
Vdbe *v = pWInfo->pParse->pVdbe;
111876111922
sqlite3ExplainBegin(v);
111877111923
for(i=0; i<p->nLTerm; i++){
111878111924
WhereTerm *pTerm = p->aLTerm[i];
111925
+ if( pTerm==0 ) continue;
111879111926
sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
111880111927
sqlite3ExplainPush(v);
111881111928
whereExplainTerm(v, pTerm);
111882111929
sqlite3ExplainPop(v);
111883111930
sqlite3ExplainNL(v);
@@ -112157,10 +112204,11 @@
112157112204
if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
112158112205
if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
112159112206
if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
112160112207
for(j=pLoop->nLTerm-1; j>=0; j--){
112161112208
pX = pLoop->aLTerm[j];
112209
+ if( pX==0 ) continue;
112162112210
if( pX==pTerm ) break;
112163112211
if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
112164112212
}
112165112213
if( j<0 ) pLoop->nOut += pTerm->truthProb;
112166112214
}
@@ -112186,11 +112234,12 @@
112186112234
WhereTerm *pTerm; /* A WhereTerm under consideration */
112187112235
int opMask; /* Valid operators for constraints */
112188112236
WhereScan scan; /* Iterator for WHERE terms */
112189112237
Bitmask saved_prereq; /* Original value of pNew->prereq */
112190112238
u16 saved_nLTerm; /* Original value of pNew->nLTerm */
112191
- int saved_nEq; /* Original value of pNew->u.btree.nEq */
112239
+ u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
112240
+ u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
112192112241
u32 saved_wsFlags; /* Original value of pNew->wsFlags */
112193112242
LogEst saved_nOut; /* Original value of pNew->nOut */
112194112243
int iCol; /* Index of the column in the table */
112195112244
int rc = SQLITE_OK; /* Return code */
112196112245
LogEst nRowEst; /* Estimated index selectivity */
@@ -112221,16 +112270,35 @@
112221112270
nRowEst = 0;
112222112271
}
112223112272
pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
112224112273
opMask, pProbe);
112225112274
saved_nEq = pNew->u.btree.nEq;
112275
+ saved_nSkip = pNew->u.btree.nSkip;
112226112276
saved_nLTerm = pNew->nLTerm;
112227112277
saved_wsFlags = pNew->wsFlags;
112228112278
saved_prereq = pNew->prereq;
112229112279
saved_nOut = pNew->nOut;
112230112280
pNew->rSetup = 0;
112231112281
rLogSize = estLog(sqlite3LogEst(pProbe->aiRowEst[0]));
112282
+
112283
+ /* Consider using a skip-scan if there are no WHERE clause constraints
112284
+ ** available for the left-most terms of the index, and if the average
112285
+ ** number of repeats in the left-most terms is at least 50.
112286
+ */
112287
+ if( pTerm==0
112288
+ && saved_nEq==saved_nSkip
112289
+ && saved_nEq+1<pProbe->nKeyCol
112290
+ && pProbe->aiRowEst[saved_nEq+1]>50 /* TUNING: Minimum for skip-scan */
112291
+ ){
112292
+ LogEst nIter;
112293
+ pNew->u.btree.nEq++;
112294
+ pNew->u.btree.nSkip++;
112295
+ pNew->aLTerm[pNew->nLTerm++] = 0;
112296
+ pNew->wsFlags |= WHERE_SKIPSCAN;
112297
+ nIter = sqlite3LogEst(pProbe->aiRowEst[0]/pProbe->aiRowEst[saved_nEq+1]);
112298
+ whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter);
112299
+ }
112232112300
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
112233112301
int nIn = 0;
112234112302
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
112235112303
int nRecValid = pBuilder->nRecValid;
112236112304
#endif
@@ -112262,12 +112330,14 @@
112262112330
}
112263112331
pNew->rRun += nIn;
112264112332
pNew->u.btree.nEq++;
112265112333
pNew->nOut = nRowEst + nInMul + nIn;
112266112334
}else if( pTerm->eOperator & (WO_EQ) ){
112267
- assert( (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0
112268
- || nInMul==0 );
112335
+ assert(
112336
+ (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
112337
+ || nInMul==0
112338
+ );
112269112339
pNew->wsFlags |= WHERE_COLUMN_EQ;
112270112340
if( iCol<0
112271112341
|| (pProbe->onError!=OE_None && nInMul==0
112272112342
&& pNew->u.btree.nEq==pProbe->nKeyCol-1)
112273112343
){
@@ -112344,10 +112414,11 @@
112344112414
pBuilder->nRecValid = nRecValid;
112345112415
#endif
112346112416
}
112347112417
pNew->prereq = saved_prereq;
112348112418
pNew->u.btree.nEq = saved_nEq;
112419
+ pNew->u.btree.nSkip = saved_nSkip;
112349112420
pNew->wsFlags = saved_wsFlags;
112350112421
pNew->nOut = saved_nOut;
112351112422
pNew->nLTerm = saved_nLTerm;
112352112423
return rc;
112353112424
}
@@ -112490,10 +112561,11 @@
112490112561
WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
112491112562
for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
112492112563
if( pTerm->prereqRight & pNew->maskSelf ) continue;
112493112564
if( termCanDriveIndex(pTerm, pSrc, 0) ){
112494112565
pNew->u.btree.nEq = 1;
112566
+ pNew->u.btree.nSkip = 0;
112495112567
pNew->u.btree.pIndex = 0;
112496112568
pNew->nLTerm = 1;
112497112569
pNew->aLTerm[0] = pTerm;
112498112570
/* TUNING: One-time cost for computing the automatic index is
112499112571
** approximately 7*N*log2(N) where N is the number of rows in
@@ -112519,10 +112591,11 @@
112519112591
if( pProbe->pPartIdxWhere!=0
112520112592
&& !whereUsablePartialIndex(pNew->iTab, pWC, pProbe->pPartIdxWhere) ){
112521112593
continue; /* Partial index inappropriate for this query */
112522112594
}
112523112595
pNew->u.btree.nEq = 0;
112596
+ pNew->u.btree.nSkip = 0;
112524112597
pNew->nLTerm = 0;
112525112598
pNew->iSortIdx = 0;
112526112599
pNew->rSetup = 0;
112527112600
pNew->prereq = mExtra;
112528112601
pNew->nOut = rSize;
@@ -112604,11 +112677,12 @@
112604112677
/*
112605112678
** Add all WhereLoop objects for a table of the join identified by
112606112679
** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
112607112680
*/
112608112681
static int whereLoopAddVirtual(
112609
- WhereLoopBuilder *pBuilder /* WHERE clause information */
112682
+ WhereLoopBuilder *pBuilder, /* WHERE clause information */
112683
+ Bitmask mExtra
112610112684
){
112611112685
WhereInfo *pWInfo; /* WHERE analysis context */
112612112686
Parse *pParse; /* The parsing context */
112613112687
WhereClause *pWC; /* The WHERE clause */
112614112688
struct SrcList_item *pSrc; /* The FROM clause term to search */
@@ -112694,11 +112768,11 @@
112694112768
pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
112695112769
pIdxInfo->estimatedRows = 25;
112696112770
rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112697112771
if( rc ) goto whereLoopAddVtab_exit;
112698112772
pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112699
- pNew->prereq = 0;
112773
+ pNew->prereq = mExtra;
112700112774
mxTerm = -1;
112701112775
assert( pNew->nLSlot>=nConstraint );
112702112776
for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
112703112777
pNew->u.vtab.omitMask = 0;
112704112778
for(i=0; i<nConstraint; i++, pIdxCons++){
@@ -112821,12 +112895,11 @@
112821112895
continue;
112822112896
}
112823112897
sCur.n = 0;
112824112898
#ifndef SQLITE_OMIT_VIRTUALTABLE
112825112899
if( IsVirtual(pItem->pTab) ){
112826
- rc = whereLoopAddVirtual(&sSubBuild);
112827
- for(i=0; i<sCur.n; i++) sCur.a[i].prereq |= mExtra;
112900
+ rc = whereLoopAddVirtual(&sSubBuild, mExtra);
112828112901
}else
112829112902
#endif
112830112903
{
112831112904
rc = whereLoopAddBtree(&sSubBuild, mExtra);
112832112905
}
@@ -112892,11 +112965,11 @@
112892112965
if( ((pItem->jointype|priorJoinType) & (JT_LEFT|JT_CROSS))!=0 ){
112893112966
mExtra = mPrior;
112894112967
}
112895112968
priorJoinType = pItem->jointype;
112896112969
if( IsVirtual(pItem->pTab) ){
112897
- rc = whereLoopAddVirtual(pBuilder);
112970
+ rc = whereLoopAddVirtual(pBuilder, mExtra);
112898112971
}else{
112899112972
rc = whereLoopAddBtree(pBuilder, mExtra);
112900112973
}
112901112974
if( rc==SQLITE_OK ){
112902112975
rc = whereLoopAddOr(pBuilder, mExtra);
@@ -113053,10 +113126,11 @@
113053113126
for(j=0; j<nColumn; j++){
113054113127
u8 bOnce; /* True to run the ORDER BY search loop */
113055113128
113056113129
/* Skip over == and IS NULL terms */
113057113130
if( j<pLoop->u.btree.nEq
113131
+ && pLoop->u.btree.nSkip==0
113058113132
&& ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
113059113133
){
113060113134
if( i & WO_ISNULL ){
113061113135
testcase( isOrderDistinct );
113062113136
isOrderDistinct = 0;
@@ -113478,10 +113552,11 @@
113478113552
if( pItem->zIndex ) return 0;
113479113553
iCur = pItem->iCursor;
113480113554
pWC = &pWInfo->sWC;
113481113555
pLoop = pBuilder->pNew;
113482113556
pLoop->wsFlags = 0;
113557
+ pLoop->u.btree.nSkip = 0;
113483113558
pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
113484113559
if( pTerm ){
113485113560
pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
113486113561
pLoop->aLTerm[0] = pTerm;
113487113562
pLoop->nLTerm = 1;
@@ -113706,11 +113781,10 @@
113706113781
/* Split the WHERE clause into separate subexpressions where each
113707113782
** subexpression is separated by an AND operator.
113708113783
*/
113709113784
initMaskSet(pMaskSet);
113710113785
whereClauseInit(&pWInfo->sWC, pWInfo);
113711
- sqlite3ExprCodeConstants(pParse, pWhere);
113712113786
whereSplit(&pWInfo->sWC, pWhere, TK_AND);
113713113787
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113714113788
113715113789
/* Special case: a WHERE clause that is constant. Evaluate the
113716113790
** expression and either jump over all of the code or fall thru.
@@ -114021,10 +114095,11 @@
114021114095
notReady = codeOneLoopStart(pWInfo, ii, notReady);
114022114096
pWInfo->iContinue = pLevel->addrCont;
114023114097
}
114024114098
114025114099
/* Done. */
114100
+ VdbeModuleComment((v, "Begin WHERE-core"));
114026114101
return pWInfo;
114027114102
114028114103
/* Jump here if malloc fails */
114029114104
whereBeginError:
114030114105
if( pWInfo ){
@@ -114047,12 +114122,14 @@
114047114122
SrcList *pTabList = pWInfo->pTabList;
114048114123
sqlite3 *db = pParse->db;
114049114124
114050114125
/* Generate loop termination code.
114051114126
*/
114127
+ VdbeModuleComment((v, "End WHERE-core"));
114052114128
sqlite3ExprCacheClear(pParse);
114053114129
for(i=pWInfo->nLevel-1; i>=0; i--){
114130
+ int addr;
114054114131
pLevel = &pWInfo->a[i];
114055114132
pLoop = pLevel->pWLoop;
114056114133
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114057114134
if( pLevel->op!=OP_Noop ){
114058114135
sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
@@ -114068,12 +114145,17 @@
114068114145
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114069114146
}
114070114147
sqlite3DbFree(db, pLevel->u.in.aInLoop);
114071114148
}
114072114149
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
114150
+ if( pLevel->addrSkip ){
114151
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
114152
+ VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
114153
+ sqlite3VdbeJumpHere(v, pLevel->addrSkip);
114154
+ sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
114155
+ }
114073114156
if( pLevel->iLeftJoin ){
114074
- int addr;
114075114157
addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114076114158
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114077114159
|| (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114078114160
if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114079114161
sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
@@ -114086,11 +114168,11 @@
114086114168
}else{
114087114169
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
114088114170
}
114089114171
sqlite3VdbeJumpHere(v, addr);
114090114172
}
114091
- VdbeNoopComment((v, "End WHERE-Loop %d: %s", i,
114173
+ VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
114092114174
pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
114093114175
}
114094114176
114095114177
/* The "break" point is here, just past the end of the outer loop.
114096114178
** Set it.
@@ -123671,10 +123753,14 @@
123671123753
char *aDoclist; /* Pointer to doclist buffer */
123672123754
int nDoclist; /* Size of aDoclist[] in bytes */
123673123755
};
123674123756
123675123757
SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
123758
+
123759
+#define fts3GetVarint32(p, piVal) ( \
123760
+ (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
123761
+)
123676123762
123677123763
/* fts3.c */
123678123764
SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
123679123765
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
123680123766
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
@@ -123779,36 +123865,63 @@
123779123865
q[-1] &= 0x7f; /* turn off high bit in final byte */
123780123866
assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
123781123867
return (int) (q - (unsigned char *)p);
123782123868
}
123783123869
123870
+#define GETVARINT_STEP(v, ptr, shift, mask1, mask2, var, ret) \
123871
+ v = (v & mask1) | ( (*ptr++) << shift ); \
123872
+ if( (v & mask2)==0 ){ var = v; return ret; }
123873
+#define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
123874
+ v = (*ptr++); \
123875
+ if( (v & mask2)==0 ){ var = v; return ret; }
123876
+
123784123877
/*
123785123878
** Read a 64-bit variable-length integer from memory starting at p[0].
123786123879
** Return the number of bytes read, or 0 on error.
123787123880
** The value is stored in *v.
123788123881
*/
123789123882
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){
123790
- const unsigned char *q = (const unsigned char *) p;
123791
- sqlite_uint64 x = 0, y = 1;
123792
- while( (*q&0x80)==0x80 && q-(unsigned char *)p<FTS3_VARINT_MAX ){
123793
- x += y * (*q++ & 0x7f);
123794
- y <<= 7;
123795
- }
123796
- x += y * (*q++);
123797
- *v = (sqlite_int64) x;
123798
- return (int) (q - (unsigned char *)p);
123883
+ const char *pStart = p;
123884
+ u32 a;
123885
+ u64 b;
123886
+ int shift;
123887
+
123888
+ GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
123889
+ GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *v, 2);
123890
+ GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *v, 3);
123891
+ GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *v, 4);
123892
+ b = (a & 0x0FFFFFFF );
123893
+
123894
+ for(shift=28; shift<=63; shift+=7){
123895
+ u64 c = *p++;
123896
+ b += (c&0x7F) << shift;
123897
+ if( (c & 0x80)==0 ) break;
123898
+ }
123899
+ *v = b;
123900
+ return (int)(p - pStart);
123799123901
}
123800123902
123801123903
/*
123802123904
** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
123803123905
** 32-bit integer before it is returned.
123804123906
*/
123805123907
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
123806
- sqlite_int64 i;
123807
- int ret = sqlite3Fts3GetVarint(p, &i);
123808
- *pi = (int) i;
123809
- return ret;
123908
+ u32 a;
123909
+
123910
+#ifndef fts3GetVarint32
123911
+ GETVARINT_INIT(a, p, 0, 0x00, 0x80, *pi, 1);
123912
+#else
123913
+ a = (*p++);
123914
+ assert( a & 0x80 );
123915
+#endif
123916
+
123917
+ GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
123918
+ GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
123919
+ GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
123920
+ a = (a & 0x0FFFFFFF );
123921
+ *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
123922
+ return 5;
123810123923
}
123811123924
123812123925
/*
123813123926
** Return the number of bytes required to encode v as a varint
123814123927
*/
@@ -125164,14 +125277,14 @@
125164125277
int nBuffer; /* Total term size */
125165125278
125166125279
/* Load the next term on the node into zBuffer. Use realloc() to expand
125167125280
** the size of zBuffer if required. */
125168125281
if( !isFirstTerm ){
125169
- zCsr += sqlite3Fts3GetVarint32(zCsr, &nPrefix);
125282
+ zCsr += fts3GetVarint32(zCsr, &nPrefix);
125170125283
}
125171125284
isFirstTerm = 0;
125172
- zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
125285
+ zCsr += fts3GetVarint32(zCsr, &nSuffix);
125173125286
125174125287
if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
125175125288
rc = FTS_CORRUPT_VTAB;
125176125289
goto finish_scan;
125177125290
}
@@ -125255,11 +125368,11 @@
125255125368
int rc; /* Return code */
125256125369
int iHeight; /* Height of this node in tree */
125257125370
125258125371
assert( piLeaf || piLeaf2 );
125259125372
125260
- sqlite3Fts3GetVarint32(zNode, &iHeight);
125373
+ fts3GetVarint32(zNode, &iHeight);
125261125374
rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
125262125375
assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
125263125376
125264125377
if( rc==SQLITE_OK && iHeight>1 ){
125265125378
char *zBlob = 0; /* Blob read from %_segments table */
@@ -125457,15 +125570,15 @@
125457125570
125458125571
while( *p1 || *p2 ){
125459125572
int iCol1; /* The current column index in pp1 */
125460125573
int iCol2; /* The current column index in pp2 */
125461125574
125462
- if( *p1==POS_COLUMN ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
125575
+ if( *p1==POS_COLUMN ) fts3GetVarint32(&p1[1], &iCol1);
125463125576
else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
125464125577
else iCol1 = 0;
125465125578
125466
- if( *p2==POS_COLUMN ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
125579
+ if( *p2==POS_COLUMN ) fts3GetVarint32(&p2[1], &iCol2);
125467125580
else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
125468125581
else iCol2 = 0;
125469125582
125470125583
if( iCol1==iCol2 ){
125471125584
sqlite3_int64 i1 = 0; /* Last position from pp1 */
@@ -125554,15 +125667,15 @@
125554125667
assert( isSaveLeft==0 || isExact==0 );
125555125668
125556125669
assert( p!=0 && *p1!=0 && *p2!=0 );
125557125670
if( *p1==POS_COLUMN ){
125558125671
p1++;
125559
- p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125672
+ p1 += fts3GetVarint32(p1, &iCol1);
125560125673
}
125561125674
if( *p2==POS_COLUMN ){
125562125675
p2++;
125563
- p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125676
+ p2 += fts3GetVarint32(p2, &iCol2);
125564125677
}
125565125678
125566125679
while( 1 ){
125567125680
if( iCol1==iCol2 ){
125568125681
char *pSave = p;
@@ -125608,13 +125721,13 @@
125608125721
fts3ColumnlistCopy(0, &p2);
125609125722
assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
125610125723
if( 0==*p1 || 0==*p2 ) break;
125611125724
125612125725
p1++;
125613
- p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125726
+ p1 += fts3GetVarint32(p1, &iCol1);
125614125727
p2++;
125615
- p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125728
+ p2 += fts3GetVarint32(p2, &iCol2);
125616125729
}
125617125730
125618125731
/* Advance pointer p1 or p2 (whichever corresponds to the smaller of
125619125732
** iCol1 and iCol2) so that it points to either the 0x00 that marks the
125620125733
** end of the position list, or the 0x01 that precedes the next
@@ -125622,16 +125735,16 @@
125622125735
*/
125623125736
else if( iCol1<iCol2 ){
125624125737
fts3ColumnlistCopy(0, &p1);
125625125738
if( 0==*p1 ) break;
125626125739
p1++;
125627
- p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125740
+ p1 += fts3GetVarint32(p1, &iCol1);
125628125741
}else{
125629125742
fts3ColumnlistCopy(0, &p2);
125630125743
if( 0==*p2 ) break;
125631125744
p2++;
125632
- p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125745
+ p2 += fts3GetVarint32(p2, &iCol2);
125633125746
}
125634125747
}
125635125748
125636125749
fts3PoslistCopy(0, &p2);
125637125750
fts3PoslistCopy(0, &p1);
@@ -128794,11 +128907,11 @@
128794128907
*/
128795128908
pExpr->aMI[iCol*3 + 1] += iCnt;
128796128909
pExpr->aMI[iCol*3 + 2] += (iCnt>0);
128797128910
if( *p==0x00 ) break;
128798128911
p++;
128799
- p += sqlite3Fts3GetVarint32(p, &iCol);
128912
+ p += fts3GetVarint32(p, &iCol);
128800128913
}
128801128914
}
128802128915
128803128916
fts3EvalUpdateCounts(pExpr->pLeft);
128804128917
fts3EvalUpdateCounts(pExpr->pRight);
@@ -129095,19 +129208,19 @@
129095129208
}
129096129209
if( pIter==0 ) return SQLITE_OK;
129097129210
129098129211
if( *pIter==0x01 ){
129099129212
pIter++;
129100
- pIter += sqlite3Fts3GetVarint32(pIter, &iThis);
129213
+ pIter += fts3GetVarint32(pIter, &iThis);
129101129214
}else{
129102129215
iThis = 0;
129103129216
}
129104129217
while( iThis<iCol ){
129105129218
fts3ColumnlistCopy(0, &pIter);
129106129219
if( *pIter==0x00 ) return 0;
129107129220
pIter++;
129108
- pIter += sqlite3Fts3GetVarint32(pIter, &iThis);
129221
+ pIter += fts3GetVarint32(pIter, &iThis);
129109129222
}
129110129223
129111129224
*ppOut = ((iCol==iThis)?pIter:0);
129112129225
return SQLITE_OK;
129113129226
}
@@ -134552,12 +134665,12 @@
134552134665
rc = fts3SegReaderRequire(pReader, pNext, FTS3_VARINT_MAX*2);
134553134666
if( rc!=SQLITE_OK ) return rc;
134554134667
134555134668
/* Because of the FTS3_NODE_PADDING bytes of padding, the following is
134556134669
** safe (no risk of overread) even if the node data is corrupted. */
134557
- pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
134558
- pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
134670
+ pNext += fts3GetVarint32(pNext, &nPrefix);
134671
+ pNext += fts3GetVarint32(pNext, &nSuffix);
134559134672
if( nPrefix<0 || nSuffix<=0
134560134673
|| &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
134561134674
){
134562134675
return FTS_CORRUPT_VTAB;
134563134676
}
@@ -134576,11 +134689,11 @@
134576134689
if( rc!=SQLITE_OK ) return rc;
134577134690
134578134691
memcpy(&pReader->zTerm[nPrefix], pNext, nSuffix);
134579134692
pReader->nTerm = nPrefix+nSuffix;
134580134693
pNext += nSuffix;
134581
- pNext += sqlite3Fts3GetVarint32(pNext, &pReader->nDoclist);
134694
+ pNext += fts3GetVarint32(pNext, &pReader->nDoclist);
134582134695
pReader->aDoclist = pNext;
134583134696
pReader->pOffsetList = 0;
134584134697
134585134698
/* Check that the doclist does not appear to extend past the end of the
134586134699
** b-tree node. And that the final byte of the doclist is 0x00. If either
@@ -135737,11 +135850,11 @@
135737135850
pList = p;
135738135851
if( nList==0 ){
135739135852
break;
135740135853
}
135741135854
p = &pList[1];
135742
- p += sqlite3Fts3GetVarint32(p, &iCurrent);
135855
+ p += fts3GetVarint32(p, &iCurrent);
135743135856
}
135744135857
135745135858
if( bZero && &pList[nList]!=pEnd ){
135746135859
memset(&pList[nList], 0, pEnd - &pList[nList]);
135747135860
}
@@ -136702,21 +136815,21 @@
136702136815
if( p->iOff>=p->nNode ){
136703136816
/* EOF */
136704136817
p->aNode = 0;
136705136818
}else{
136706136819
if( bFirst==0 ){
136707
- p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
136820
+ p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
136708136821
}
136709
- p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
136822
+ p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
136710136823
136711136824
blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
136712136825
if( rc==SQLITE_OK ){
136713136826
memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix);
136714136827
p->term.n = nPrefix+nSuffix;
136715136828
p->iOff += nSuffix;
136716136829
if( p->iChild==0 ){
136717
- p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
136830
+ p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
136718136831
p->aDoclist = &p->aNode[p->iOff];
136719136832
p->iOff += p->nDoclist;
136720136833
}
136721136834
}
136722136835
}
@@ -137764,11 +137877,11 @@
137764137877
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137765137878
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137766137879
137767137880
pHint->n = i;
137768137881
i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
137769
- i += sqlite3Fts3GetVarint32(&pHint->a[i], pnInput);
137882
+ i += fts3GetVarint32(&pHint->a[i], pnInput);
137770137883
if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
137771137884
137772137885
return SQLITE_OK;
137773137886
}
137774137887
@@ -138757,11 +138870,11 @@
138757138870
** After it returns, *piPos contains the value of the next element of the
138758138871
** list and *pp is advanced to the following varint.
138759138872
*/
138760138873
static void fts3GetDeltaPosition(char **pp, int *piPos){
138761138874
int iVal;
138762
- *pp += sqlite3Fts3GetVarint32(*pp, &iVal);
138875
+ *pp += fts3GetVarint32(*pp, &iVal);
138763138876
*piPos += (iVal-2);
138764138877
}
138765138878
138766138879
/*
138767138880
** Helper function for fts3ExprIterate() (see below).
138768138881
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.2"
139 #define SQLITE_VERSION_NUMBER 3008002
140 #define SQLITE_SOURCE_ID "2013-11-12 15:33:40 0f924c6ef6cf2ac5a61aafa8dd8e3309b3970499"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -396,11 +396,11 @@
396 ** Restrictions:
397 **
398 ** <ul>
399 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
400 ** is a valid and open [database connection].
401 ** <li> The application must not close [database connection] specified by
402 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
403 ** <li> The application must not modify the SQL statement text passed into
404 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
405 ** </ul>
406 */
@@ -473,11 +473,11 @@
473 ** about errors. The extended result codes are enabled or disabled
474 ** on a per database connection basis using the
475 ** [sqlite3_extended_result_codes()] API.
476 **
477 ** Some of the available extended result codes are listed here.
478 ** One may expect the number of extended result codes will be expand
479 ** over time. Software that uses extended result codes should expect
480 ** to see new result codes in future releases of SQLite.
481 **
482 ** The SQLITE_OK result code will never be extended. It will always
483 ** be exactly zero.
@@ -1411,11 +1411,11 @@
1411 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1412 ** Every memory allocation request coming in through [sqlite3_malloc()]
1413 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1414 ** that causes the corresponding memory allocation to fail.
1415 **
1416 ** The xInit method initializes the memory allocator. (For example,
1417 ** it might allocate any require mutexes or initialize internal data
1418 ** structures. The xShutdown method is invoked (indirectly) by
1419 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1420 ** by xInit. The pAppData pointer is used as the only parameter to
1421 ** xInit and xShutdown.
@@ -3137,11 +3137,10 @@
3137 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3138 ** ^The specific value of WHERE-clause [parameter] might influence the
3139 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3140 ** or [GLOB] operator or if the parameter is compared to an indexed column
3141 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3142 ** the
3143 ** </li>
3144 ** </ol>
3145 */
3146 SQLITE_API int sqlite3_prepare(
3147 sqlite3 *db, /* Database handle */
@@ -3867,11 +3866,11 @@
3867 **
3868 ** ^The pointers returned are valid until a type conversion occurs as
3869 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3870 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3871 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3872 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3873 ** [sqlite3_free()].
3874 **
3875 ** ^(If a memory allocation error occurs during the evaluation of any
3876 ** of these routines, a default value is returned. The default value
3877 ** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4945,12 +4944,12 @@
4945 /*
4946 ** CAPI3REF: Free Memory Used By A Database Connection
4947 **
4948 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
4949 ** memory as possible from database connection D. Unlike the
4950 ** [sqlite3_release_memory()] interface, this interface is effect even
4951 ** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4952 ** omitted.
4953 **
4954 ** See also: [sqlite3_release_memory()]
4955 */
4956 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -9096,22 +9095,22 @@
9096 #define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9097 #define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9098 #define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9099 #define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9100 #define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9101 #define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P3 */
9102 #define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9103 #define OP_RowKey 82 /* synopsis: r[P2]=key */
9104 #define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9105 #define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9106 #define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9107 #define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9108 #define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
9109 #define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9110 #define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9111 #define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P1]/r[P2] */
9112 #define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P1]%r[P2] */
9113 #define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9114 #define OP_RowData 93 /* synopsis: r[P2]=data */
9115 #define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9116 #define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
9117 #define OP_Rowid 96 /* synopsis: r[P2]=rowid */
@@ -9237,11 +9236,10 @@
9237 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
9238 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
9239 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
9240 #ifdef SQLITE_DEBUG
9241 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
9242 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
9243 #endif
9244 SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
9245 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
9246 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
9247 SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
@@ -10304,10 +10302,11 @@
10304 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
10305 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
10306 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
10307 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
10308 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
 
10309
10310
10311 /*
10312 ** Bits of the sqlite3.dbOptFlags field that are used by the
10313 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11089,11 +11088,11 @@
11089 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
11090 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
11091 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
11092 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
11093 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
11094 #define EP_FixedDest 0x000200 /* Result needed in a specific register */
11095 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
11096 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
11097 #define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
11098 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
11099 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
@@ -11160,12 +11159,17 @@
11160 char *zName; /* Token associated with this expression */
11161 char *zSpan; /* Original text of the expression */
11162 u8 sortOrder; /* 1 for DESC or 0 for ASC */
11163 unsigned done :1; /* A flag to indicate when processing is finished */
11164 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11165 u16 iOrderByCol; /* For ORDER BY, column number in result set */
11166 u16 iAlias; /* Index into Parse.aAlias[] for zName */
 
 
 
 
 
11167 } *a; /* Alloc a power of two greater or equal to nExpr */
11168 };
11169
11170 /*
11171 ** An instance of this structure is used by the parser to record both
@@ -11538,10 +11542,11 @@
11538 u8 tempReg; /* iReg is a temp register that needs to be freed */
11539 int iLevel; /* Nesting level */
11540 int iReg; /* Reg with value of this column. 0 means none. */
11541 int lru; /* Least recently used entry has the smallest value */
11542 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
 
11543 yDbMask writeMask; /* Start a write transaction on these databases */
11544 yDbMask cookieMask; /* Bitmask of schema verified databases */
11545 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
11546 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
11547 int regRowid; /* Register holding rowid of CREATE TABLE entry */
@@ -12151,11 +12156,10 @@
12151 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12152 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
12153 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12154 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12155 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12156 SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse*, Expr*);
12157 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
12158 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12159 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
12160 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
12161 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
@@ -12197,11 +12201,11 @@
12197 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12198 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
12199 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
12200 u8,u8,int,int*);
12201 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12202 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, int*, int*);
12203 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
12204 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
12205 SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
12206 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
12207 SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*);
@@ -12519,10 +12523,11 @@
12519 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
12520 SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
12521 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
12522 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
12523 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
 
12524 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
12525 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
12526 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
12527 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
12528 SQLITE_PRIVATE const char *sqlite3JournalModename(int);
@@ -13700,13 +13705,10 @@
13700 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13701 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
13702 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
13703 char *zSql; /* Text of the SQL statement that generated this */
13704 void *pFree; /* Free this when deleting the vdbe */
13705 #ifdef SQLITE_DEBUG
13706 FILE *trace; /* Write an execution trace here, if not NULL */
13707 #endif
13708 #ifdef SQLITE_ENABLE_TREE_EXPLAIN
13709 Explain *pExplain; /* The explainer */
13710 char *zExplain; /* Explanation of data structures */
13711 #endif
13712 VdbeFrame *pFrame; /* Parent frame */
@@ -15796,20 +15798,10 @@
15796 ** This version of the memory allocator is the default. It is
15797 ** used when no other memory allocator is specified using compile-time
15798 ** macros.
15799 */
15800 #ifdef SQLITE_SYSTEM_MALLOC
15801
15802 /*
15803 ** The MSVCRT has malloc_usable_size() but it is called _msize().
15804 ** The use of _msize() is automatic, but can be disabled by compiling
15805 ** with -DSQLITE_WITHOUT_MSIZE
15806 */
15807 #if defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
15808 # define SQLITE_MALLOCSIZE _msize
15809 #endif
15810
15811 #if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
15812
15813 /*
15814 ** Use the zone allocator available on apple products unless the
15815 ** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
@@ -15828,25 +15820,51 @@
15828
15829 /*
15830 ** Use standard C library malloc and free on non-Apple systems.
15831 ** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
15832 */
15833 #define SQLITE_MALLOC(x) malloc(x)
15834 #define SQLITE_FREE(x) free(x)
15835 #define SQLITE_REALLOC(x,y) realloc((x),(y))
15836
15837 #if (defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)) \
15838 || (defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE))
15839 # include <malloc.h> /* Needed for malloc_usable_size on linux */
15840 #endif
15841 #ifdef HAVE_MALLOC_USABLE_SIZE
15842 # ifndef SQLITE_MALLOCSIZE
15843 # define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
15844 # endif
15845 #else
15846 # undef SQLITE_MALLOCSIZE
15847 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15848
15849 #endif /* __APPLE__ or not __APPLE__ */
15850
15851 /*
15852 ** Like malloc(), but remember the size of the allocation
@@ -22957,22 +22975,22 @@
22957 /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
22958 /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
22959 /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
22960 /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
22961 /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
22962 /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P3"),
22963 /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
22964 /* 82 */ "RowKey" OpHelp("r[P2]=key"),
22965 /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
22966 /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
22967 /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
22968 /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
22969 /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
22970 /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
22971 /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
22972 /* 90 */ "Divide" OpHelp("r[P3]=r[P1]/r[P2]"),
22973 /* 91 */ "Remainder" OpHelp("r[P3]=r[P1]%r[P2]"),
22974 /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
22975 /* 93 */ "RowData" OpHelp("r[P2]=data"),
22976 /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
22977 /* 95 */ "String8" OpHelp("r[P2]='P4'"),
22978 /* 96 */ "Rowid" OpHelp("r[P2]=rowid"),
@@ -58853,10 +58871,11 @@
58853 if( sqlite3OpenTempDatabase(pParse) ){
58854 sqlite3Error(pErrorDb, pParse->rc, "%s", pParse->zErrMsg);
58855 rc = SQLITE_ERROR;
58856 }
58857 sqlite3DbFree(pErrorDb, pParse->zErrMsg);
 
58858 sqlite3StackFree(pErrorDb, pParse);
58859 }
58860 if( rc ){
58861 return 0;
58862 }
@@ -60997,19 +61016,10 @@
60997 pA->zSql = pB->zSql;
60998 pB->zSql = zTmp;
60999 pB->isPrepareV2 = pA->isPrepareV2;
61000 }
61001
61002 #ifdef SQLITE_DEBUG
61003 /*
61004 ** Turn tracing on or off
61005 */
61006 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
61007 p->trace = trace;
61008 }
61009 #endif
61010
61011 /*
61012 ** Resize the Vdbe.aOp array so that it is at least one op larger than
61013 ** it was.
61014 **
61015 ** If an out-of-memory error occurs while resizing the array, return
@@ -61901,11 +61911,11 @@
61901 assert( i<nTemp );
61902 break;
61903 }
61904 case P4_COLLSEQ: {
61905 CollSeq *pColl = pOp->p4.pColl;
61906 sqlite3_snprintf(nTemp, zTemp, "collseq(%.20s)", pColl->zName);
61907 break;
61908 }
61909 case P4_FUNCDEF: {
61910 FuncDef *pDef = pOp->p4.pFunc;
61911 sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
@@ -62334,19 +62344,21 @@
62334 #ifdef SQLITE_DEBUG
62335 /*
62336 ** Print the SQL that was used to generate a VDBE program.
62337 */
62338 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe *p){
62339 int nOp = p->nOp;
62340 VdbeOp *pOp;
62341 if( nOp<1 ) return;
62342 pOp = &p->aOp[0];
62343 if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62344 const char *z = pOp->p4.z;
62345 while( sqlite3Isspace(*z) ) z++;
62346 printf("SQL: [%s]\n", z);
62347 }
 
 
62348 }
62349 #endif
62350
62351 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
62352 /*
@@ -63892,19 +63904,16 @@
63892 pMem->u.i = serial_type-8;
63893 pMem->flags = MEM_Int;
63894 return 0;
63895 }
63896 default: {
 
63897 u32 len = (serial_type-12)/2;
63898 pMem->z = (char *)buf;
63899 pMem->n = len;
63900 pMem->xDel = 0;
63901 if( serial_type&0x01 ){
63902 pMem->flags = MEM_Str | MEM_Ephem;
63903 }else{
63904 pMem->flags = MEM_Blob | MEM_Ephem;
63905 }
63906 return len;
63907 }
63908 }
63909 return 0;
63910 }
@@ -66350,41 +66359,40 @@
66350
66351 #ifdef SQLITE_DEBUG
66352 /*
66353 ** Print the value of a register for tracing purposes:
66354 */
66355 static void memTracePrint(FILE *out, Mem *p){
66356 if( p->flags & MEM_Invalid ){
66357 fprintf(out, " undefined");
66358 }else if( p->flags & MEM_Null ){
66359 fprintf(out, " NULL");
66360 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66361 fprintf(out, " si:%lld", p->u.i);
66362 }else if( p->flags & MEM_Int ){
66363 fprintf(out, " i:%lld", p->u.i);
66364 #ifndef SQLITE_OMIT_FLOATING_POINT
66365 }else if( p->flags & MEM_Real ){
66366 fprintf(out, " r:%g", p->r);
66367 #endif
66368 }else if( p->flags & MEM_RowSet ){
66369 fprintf(out, " (rowset)");
66370 }else{
66371 char zBuf[200];
66372 sqlite3VdbeMemPrettyPrint(p, zBuf);
66373 fprintf(out, " ");
66374 fprintf(out, "%s", zBuf);
66375 }
66376 }
66377 static void registerTrace(FILE *out, int iReg, Mem *p){
66378 fprintf(out, "REG[%d] = ", iReg);
66379 memTracePrint(out, p);
66380 fprintf(out, "\n");
66381 }
66382 #endif
66383
66384 #ifdef SQLITE_DEBUG
66385 # define REGISTER_TRACE(R,M) if(p->trace)registerTrace(p->trace,R,M)
66386 #else
66387 # define REGISTER_TRACE(R,M)
66388 #endif
66389
66390
@@ -67035,17 +67043,32 @@
67035 }
67036 }
67037 #endif
67038 #ifdef SQLITE_DEBUG
67039 sqlite3BeginBenignMalloc();
67040 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
 
 
67041 int i;
67042 printf("VDBE Program Listing:\n");
67043 sqlite3VdbePrintSql(p);
67044 for(i=0; i<p->nOp; i++){
67045 sqlite3VdbePrintOp(stdout, i, &aOp[i]);
 
 
 
67046 }
 
 
 
 
 
 
 
 
 
 
67047 }
67048 sqlite3EndBenignMalloc();
67049 #endif
67050 for(pc=p->pc; rc==SQLITE_OK; pc++){
67051 assert( pc>=0 && pc<p->nOp );
@@ -67058,16 +67081,12 @@
67058 pOp = &aOp[pc];
67059
67060 /* Only allow tracing if SQLITE_DEBUG is defined.
67061 */
67062 #ifdef SQLITE_DEBUG
67063 if( p->trace ){
67064 if( pc==0 ){
67065 printf("VDBE Execution Trace:\n");
67066 sqlite3VdbePrintSql(p);
67067 }
67068 sqlite3VdbePrintOp(p->trace, pc, pOp);
67069 }
67070 #endif
67071
67072
67073 /* Check to see if we need to simulate an interrupt. This only happens
@@ -67194,19 +67213,16 @@
67194 ** sqlite3VdbeExec() or since last time the progress callback was called).
67195 ** If the progress callback returns non-zero, exit the virtual machine with
67196 ** a return code SQLITE_ABORT.
67197 */
67198 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
67199 int prc;
67200 prc = db->xProgress(db->pProgressArg);
67201 if( prc!=0 ){
67202 rc = SQLITE_INTERRUPT;
67203 goto vdbe_error_halt;
67204 }
67205 if( db->xProgress!=0 ){
67206 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
67207 }
67208 }
67209 #endif
67210
67211 break;
67212 }
@@ -67638,10 +67654,22 @@
67638 int i;
67639 #endif /* local variables moved into u.ag */
67640 assert( p->nResColumn==pOp->p2 );
67641 assert( pOp->p1>0 );
67642 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
 
 
 
 
 
 
 
 
 
 
 
 
67643
67644 /* If this statement has violated immediate foreign key constraints, do
67645 ** not return the number of rows modified. And do not RELEASE the statement
67646 ** transaction. It needs to be rolled back. */
67647 if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
@@ -67768,23 +67796,23 @@
67768 ** Subtract the value in register P1 from the value in register P2
67769 ** and store the result in register P3.
67770 ** If either input is NULL, the result is NULL.
67771 */
67772 /* Opcode: Divide P1 P2 P3 * *
67773 ** Synopsis: r[P3]=r[P1]/r[P2]
67774 **
67775 ** Divide the value in register P1 by the value in register P2
67776 ** and store the result in register P3 (P3=P2/P1). If the value in
67777 ** register P1 is zero, then the result is NULL. If either input is
67778 ** NULL, the result is NULL.
67779 */
67780 /* Opcode: Remainder P1 P2 P3 * *
67781 ** Synopsis: r[P3]=r[P1]%r[P2]
67782 **
67783 ** Compute the remainder after integer division of the value in
67784 ** register P1 by the value in register P2 and store the result in P3.
67785 ** If the value in register P2 is zero the result is NULL.
67786 ** If either operand is NULL, the result is NULL.
67787 */
67788 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67789 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67790 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
@@ -68249,11 +68277,11 @@
68249 break;
68250 }
68251 #endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
68252
68253 /* Opcode: Lt P1 P2 P3 P4 P5
68254 ** Synopsis: if r[P1]<r[P3] goto P3
68255 **
68256 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
68257 ** jump to address P2.
68258 **
68259 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -72846,17 +72874,17 @@
72846 */
72847 #ifndef NDEBUG
72848 assert( pc>=-1 && pc<p->nOp );
72849
72850 #ifdef SQLITE_DEBUG
72851 if( p->trace ){
72852 if( rc!=0 ) fprintf(p->trace,"rc=%d\n",rc);
72853 if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
72854 registerTrace(p->trace, pOp->p2, &aMem[pOp->p2]);
72855 }
72856 if( pOp->opflags & OPFLG_OUT3 ){
72857 registerTrace(p->trace, pOp->p3, &aMem[pOp->p3]);
72858 }
72859 }
72860 #endif /* SQLITE_DEBUG */
72861 #endif /* NDEBUG */
72862 } /* The end of the for(;;) loop the loops through opcodes */
@@ -73253,10 +73281,11 @@
73253 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
73254 sqlite3DbFree(db, pBlob);
73255 }
73256 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
73257 sqlite3DbFree(db, zErr);
 
73258 sqlite3StackFree(db, pParse);
73259 rc = sqlite3ApiExit(db, rc);
73260 sqlite3_mutex_leave(db->mutex);
73261 return rc;
73262 }
@@ -75218,14 +75247,14 @@
75218 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
75219 incrAggFunctionDepth(pDup, nSubquery);
75220 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
75221 if( pDup==0 ) return;
75222 ExprSetProperty(pDup, EP_Skip);
75223 if( pEList->a[iCol].iAlias==0 ){
75224 pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
75225 }
75226 pDup->iTable = pEList->a[iCol].iAlias;
75227 }
75228 if( pExpr->op==TK_COLLATE ){
75229 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
75230 }
75231
@@ -76086,11 +76115,11 @@
76086 assert( pItem->pExpr->op==TK_COLLATE );
76087 assert( pItem->pExpr->pLeft==pE );
76088 pItem->pExpr->pLeft = pNew;
76089 }
76090 sqlite3ExprDelete(db, pE);
76091 pItem->iOrderByCol = (u16)iCol;
76092 pItem->done = 1;
76093 }else{
76094 moreToDo = 1;
76095 }
76096 }
@@ -76107,12 +76136,12 @@
76107 }
76108
76109 /*
76110 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
76111 ** the SELECT statement pSelect. If any term is reference to a
76112 ** result set expression (as determined by the ExprList.a.iOrderByCol field)
76113 ** then convert that term into a copy of the corresponding result set
76114 ** column.
76115 **
76116 ** If any errors are detected, add an error message to pParse and
76117 ** return non-zero. Return zero if no errors are seen.
76118 */
@@ -76135,16 +76164,16 @@
76135 }
76136 #endif
76137 pEList = pSelect->pEList;
76138 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
76139 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
76140 if( pItem->iOrderByCol ){
76141 if( pItem->iOrderByCol>pEList->nExpr ){
76142 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
76143 return 1;
76144 }
76145 resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType,0);
76146 }
76147 }
76148 return 0;
76149 }
76150
@@ -76189,11 +76218,11 @@
76189 if( iCol>0 ){
76190 /* If an AS-name match is found, mark this ORDER BY column as being
76191 ** a copy of the iCol-th result-set column. The subsequent call to
76192 ** sqlite3ResolveOrderGroupBy() will convert the expression to a
76193 ** copy of the iCol-th result-set expression. */
76194 pItem->iOrderByCol = (u16)iCol;
76195 continue;
76196 }
76197 }
76198 if( sqlite3ExprIsInteger(pE2, &iCol) ){
76199 /* The ORDER BY term is an integer constant. Again, set the column
@@ -76201,22 +76230,22 @@
76201 ** order-by term to a copy of the result-set expression */
76202 if( iCol<1 || iCol>0xffff ){
76203 resolveOutOfRangeError(pParse, zType, i+1, nResult);
76204 return 1;
76205 }
76206 pItem->iOrderByCol = (u16)iCol;
76207 continue;
76208 }
76209
76210 /* Otherwise, treat the ORDER BY term as an ordinary expression */
76211 pItem->iOrderByCol = 0;
76212 if( sqlite3ResolveExprNames(pNC, pE) ){
76213 return 1;
76214 }
76215 for(j=0; j<pSelect->pEList->nExpr; j++){
76216 if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
76217 pItem->iOrderByCol = j+1;
76218 }
76219 }
76220 }
76221 return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
76222 }
@@ -77491,12 +77520,11 @@
77491 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
77492 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
77493 pItem->sortOrder = pOldItem->sortOrder;
77494 pItem->done = 0;
77495 pItem->bSpanIsTab = pOldItem->bSpanIsTab;
77496 pItem->iOrderByCol = pOldItem->iOrderByCol;
77497 pItem->iAlias = pOldItem->iAlias;
77498 }
77499 return pNew;
77500 }
77501
77502 /*
@@ -78917,10 +78945,11 @@
78917 int inReg = target; /* Results stored in register inReg */
78918 int regFree1 = 0; /* If non-zero free this temporary register */
78919 int regFree2 = 0; /* If non-zero free this temporary register */
78920 int r1, r2, r3, r4; /* Various register numbers */
78921 sqlite3 *db = pParse->db; /* The database connection */
 
78922
78923 assert( target>0 && target<=pParse->nMem );
78924 if( v==0 ){
78925 assert( pParse->db->mallocFailed );
78926 return 0;
@@ -79136,12 +79165,14 @@
79136 }else if( pLeft->op==TK_FLOAT ){
79137 assert( !ExprHasProperty(pExpr, EP_IntValue) );
79138 codeReal(v, pLeft->u.zToken, 1, target);
79139 #endif
79140 }else{
79141 regFree1 = r1 = sqlite3GetTempReg(pParse);
79142 sqlite3VdbeAddOp2(v, OP_Integer, 0, r1);
 
 
79143 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree2);
79144 sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target);
79145 testcase( regFree2==0 );
79146 }
79147 inReg = target;
@@ -79453,11 +79484,10 @@
79453 int nExpr; /* 2x number of WHEN terms */
79454 int i; /* Loop counter */
79455 ExprList *pEList; /* List of WHEN terms */
79456 struct ExprList_item *aListelem; /* Array of WHEN terms */
79457 Expr opCompare; /* The X==Ei expression */
79458 Expr cacheX; /* Cached expression X */
79459 Expr *pX; /* The X expression */
79460 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
79461 VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
79462
79463 assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
@@ -79465,17 +79495,16 @@
79465 pEList = pExpr->x.pList;
79466 aListelem = pEList->a;
79467 nExpr = pEList->nExpr;
79468 endLabel = sqlite3VdbeMakeLabel(v);
79469 if( (pX = pExpr->pLeft)!=0 ){
79470 cacheX = *pX;
79471 testcase( pX->op==TK_COLUMN );
79472 testcase( pX->op==TK_REGISTER );
79473 exprToRegister(&cacheX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
79474 testcase( regFree1==0 );
79475 opCompare.op = TK_EQ;
79476 opCompare.pLeft = &cacheX;
79477 pTest = &opCompare;
79478 /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
79479 ** The value in regFree1 might get SCopy-ed into the file result.
79480 ** So make sure that the regFree1 register is not reused for other
79481 ** purposes and possibly overwritten. */
@@ -79491,11 +79520,10 @@
79491 }
79492 nextCase = sqlite3VdbeMakeLabel(v);
79493 testcase( pTest->op==TK_COLUMN );
79494 sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
79495 testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
79496 testcase( aListelem[i+1].pExpr->op==TK_REGISTER );
79497 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
79498 sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
79499 sqlite3ExprCachePop(pParse, 1);
79500 sqlite3VdbeResolveLabel(v, nextCase);
79501 }
@@ -79550,19 +79578,45 @@
79550 ** are stored.
79551 **
79552 ** If the register is a temporary register that can be deallocated,
79553 ** then write its number into *pReg. If the result register is not
79554 ** a temporary, then set *pReg to zero.
 
 
 
 
79555 */
79556 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79557 int r1 = sqlite3GetTempReg(pParse);
79558 int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79559 if( r2==r1 ){
79560 *pReg = r1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79561 }else{
79562 sqlite3ReleaseTempReg(pParse, r1);
79563 *pReg = 0;
 
 
 
 
 
 
79564 }
79565 return r2;
79566 }
79567
79568 /*
@@ -79601,16 +79655,17 @@
79601 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79602 Vdbe *v = pParse->pVdbe;
79603 int inReg;
79604 inReg = sqlite3ExprCode(pParse, pExpr, target);
79605 assert( target>0 );
79606 /* This routine is called for terms to INSERT or UPDATE. And the only
79607 ** other place where expressions can be converted into TK_REGISTER is
79608 ** in WHERE clause processing. So as currently implemented, there is
79609 ** no way for a TK_REGISTER to exist here. But it seems prudent to
79610 ** keep the ALWAYS() in case the conditions above change with future
79611 ** modifications or enhancements. */
 
79612 if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79613 int iMem;
79614 iMem = ++pParse->nMem;
79615 sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79616 exprToRegister(pExpr, iMem);
@@ -79888,144 +79943,10 @@
79888 }
79889 sqlite3ExplainPop(pOut);
79890 }
79891 }
79892 #endif /* SQLITE_DEBUG */
79893
79894 /*
79895 ** Return TRUE if pExpr is an constant expression that is appropriate
79896 ** for factoring out of a loop. Appropriate expressions are:
79897 **
79898 ** * Any expression that evaluates to two or more opcodes.
79899 **
79900 ** * Any OP_Integer, OP_Real, OP_String, OP_Blob, OP_Null,
79901 ** or OP_Variable that does not need to be placed in a
79902 ** specific register.
79903 **
79904 ** There is no point in factoring out single-instruction constant
79905 ** expressions that need to be placed in a particular register.
79906 ** We could factor them out, but then we would end up adding an
79907 ** OP_SCopy instruction to move the value into the correct register
79908 ** later. We might as well just use the original instruction and
79909 ** avoid the OP_SCopy.
79910 */
79911 static int isAppropriateForFactoring(Expr *p){
79912 if( !sqlite3ExprIsConstantNotJoin(p) ){
79913 return 0; /* Only constant expressions are appropriate for factoring */
79914 }
79915 if( (p->flags & EP_FixedDest)==0 ){
79916 return 1; /* Any constant without a fixed destination is appropriate */
79917 }
79918 while( p->op==TK_UPLUS ) p = p->pLeft;
79919 switch( p->op ){
79920 #ifndef SQLITE_OMIT_BLOB_LITERAL
79921 case TK_BLOB:
79922 #endif
79923 case TK_VARIABLE:
79924 case TK_INTEGER:
79925 case TK_FLOAT:
79926 case TK_NULL:
79927 case TK_STRING: {
79928 testcase( p->op==TK_BLOB );
79929 testcase( p->op==TK_VARIABLE );
79930 testcase( p->op==TK_INTEGER );
79931 testcase( p->op==TK_FLOAT );
79932 testcase( p->op==TK_NULL );
79933 testcase( p->op==TK_STRING );
79934 /* Single-instruction constants with a fixed destination are
79935 ** better done in-line. If we factor them, they will just end
79936 ** up generating an OP_SCopy to move the value to the destination
79937 ** register. */
79938 return 0;
79939 }
79940 case TK_UMINUS: {
79941 if( p->pLeft->op==TK_FLOAT || p->pLeft->op==TK_INTEGER ){
79942 return 0;
79943 }
79944 break;
79945 }
79946 default: {
79947 break;
79948 }
79949 }
79950 return 1;
79951 }
79952
79953 /*
79954 ** If pExpr is a constant expression that is appropriate for
79955 ** factoring out of a loop, then evaluate the expression
79956 ** into a register and convert the expression into a TK_REGISTER
79957 ** expression.
79958 */
79959 static int evalConstExpr(Walker *pWalker, Expr *pExpr){
79960 Parse *pParse = pWalker->pParse;
79961 switch( pExpr->op ){
79962 case TK_IN:
79963 case TK_REGISTER: {
79964 return WRC_Prune;
79965 }
79966 case TK_COLLATE: {
79967 return WRC_Continue;
79968 }
79969 case TK_FUNCTION:
79970 case TK_AGG_FUNCTION:
79971 case TK_CONST_FUNC: {
79972 /* The arguments to a function have a fixed destination.
79973 ** Mark them this way to avoid generated unneeded OP_SCopy
79974 ** instructions.
79975 */
79976 ExprList *pList = pExpr->x.pList;
79977 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
79978 if( pList ){
79979 int i = pList->nExpr;
79980 struct ExprList_item *pItem = pList->a;
79981 for(; i>0; i--, pItem++){
79982 if( ALWAYS(pItem->pExpr) ) pItem->pExpr->flags |= EP_FixedDest;
79983 }
79984 }
79985 break;
79986 }
79987 }
79988 if( isAppropriateForFactoring(pExpr) ){
79989 int r1 = ++pParse->nMem;
79990 int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79991 /* If r2!=r1, it means that register r1 is never used. That is harmless
79992 ** but suboptimal, so we want to know about the situation to fix it.
79993 ** Hence the following assert: */
79994 assert( r2==r1 );
79995 exprToRegister(pExpr, r2);
79996 return WRC_Prune;
79997 }
79998 return WRC_Continue;
79999 }
80000
80001 /*
80002 ** Preevaluate constant subexpressions within pExpr and store the
80003 ** results in registers. Modify pExpr so that the constant subexpresions
80004 ** are TK_REGISTER opcodes that refer to the precomputed values.
80005 **
80006 ** This routine is a no-op if the jump to the cookie-check code has
80007 ** already occur. Since the cookie-check jump is generated prior to
80008 ** any other serious processing, this check ensures that there is no
80009 ** way to accidently bypass the constant initializations.
80010 **
80011 ** This routine is also a no-op if the SQLITE_FactorOutConst optimization
80012 ** is disabled via the sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS)
80013 ** interface. This allows test logic to verify that the same answer is
80014 ** obtained for queries regardless of whether or not constants are
80015 ** precomputed into registers or if they are inserted in-line.
80016 */
80017 SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse *pParse, Expr *pExpr){
80018 Walker w;
80019 if( pParse->cookieGoto ) return;
80020 if( OptimizationDisabled(pParse->db, SQLITE_FactorOutConst) ) return;
80021 memset(&w, 0, sizeof(w));
80022 w.xExprCallback = evalConstExpr;
80023 w.pParse = pParse;
80024 sqlite3WalkExpr(&w, pExpr);
80025 }
80026
80027
80028 /*
80029 ** Generate code that pushes the value of every element of the given
80030 ** expression list into a sequence of registers beginning at target.
80031 **
@@ -80400,44 +80321,46 @@
80400 ** this routine is used, it does not hurt to get an extra 2 - that
80401 ** just might result in some slightly slower code. But returning
80402 ** an incorrect 0 or 1 could lead to a malfunction.
80403 */
80404 SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
80405 if( pA==0||pB==0 ){
 
80406 return pB==pA ? 0 : 2;
80407 }
80408 assert( !ExprHasProperty(pA, EP_TokenOnly|EP_Reduced) );
80409 assert( !ExprHasProperty(pB, EP_TokenOnly|EP_Reduced) );
80410 if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){
 
 
80411 return 2;
80412 }
80413 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
80414 if( pA->op!=pB->op && (pA->op!=TK_REGISTER || pA->op2!=pB->op) ){
80415 if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB, iTab)<2 ){
80416 return 1;
80417 }
80418 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
80419 return 1;
80420 }
80421 return 2;
80422 }
80423 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
80424 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
80425 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
80426 if( pA->iColumn!=pB->iColumn ) return 2;
80427 if( pA->iTable!=pB->iTable
80428 && pA->op!=TK_REGISTER
80429 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
80430 if( ExprHasProperty(pA, EP_IntValue) ){
80431 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
80432 return 2;
80433 }
80434 }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){
80435 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
80436 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
80437 return pA->op==TK_COLLATE ? 1 : 2;
80438 }
 
 
 
 
 
 
 
 
 
 
 
 
80439 }
80440 return 0;
80441 }
80442
80443 /*
@@ -83090,14 +83013,16 @@
83090 }
83091 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
83092 if( pTable==0 ){
83093 return 0;
83094 }
83095 if( argv[1] ){
83096 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
83097 }else{
83098 pIndex = 0;
 
 
 
 
83099 }
83100 z = argv[2];
83101
83102 if( pIndex ){
83103 decodeIntArray((char*)z, pIndex->nKeyCol+1, pIndex->aiRowEst, pIndex);
@@ -84408,11 +84333,11 @@
84408 ** transaction on each used database and to verify the schema cookie
84409 ** on each used database.
84410 */
84411 if( pParse->cookieGoto>0 ){
84412 yDbMask mask;
84413 int iDb;
84414 sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
84415 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
84416 if( (mask & pParse->cookieMask)==0 ) continue;
84417 sqlite3VdbeUsesBtree(v, iDb);
84418 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
@@ -84422,18 +84347,15 @@
84422 iDb, pParse->cookieValue[iDb],
84423 db->aDb[iDb].pSchema->iGeneration);
84424 }
84425 }
84426 #ifndef SQLITE_OMIT_VIRTUALTABLE
84427 {
84428 int i;
84429 for(i=0; i<pParse->nVtabLock; i++){
84430 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84431 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
84432 }
84433 pParse->nVtabLock = 0;
84434 }
84435 #endif
84436
84437 /* Once all the cookies have been verified and transactions opened,
84438 ** obtain the required table-locks. This is a no-op unless the
84439 ** shared-cache feature is enabled.
@@ -84441,24 +84363,30 @@
84441 codeTableLocks(pParse);
84442
84443 /* Initialize any AUTOINCREMENT data structures required.
84444 */
84445 sqlite3AutoincrementBegin(pParse);
 
 
 
 
 
 
 
 
 
 
84446
84447 /* Finally, jump back to the beginning of the executable code. */
84448 sqlite3VdbeAddOp2(v, OP_Goto, 0, pParse->cookieGoto);
84449 }
84450 }
84451
84452
84453 /* Get the VDBE program ready for execution
84454 */
84455 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
84456 #ifdef SQLITE_DEBUG
84457 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
84458 sqlite3VdbeTrace(v, trace);
84459 #endif
84460 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
84461 /* A minimum of one cursor is required if autoincrement is used
84462 * See ticket [a696379c1f08866] */
84463 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
84464 sqlite3VdbeMakeReady(v, pParse);
@@ -89162,24 +89090,38 @@
89162 Expr *pWhere /* The WHERE clause. May be null */
89163 ){
89164 Vdbe *v; /* The virtual database engine */
89165 Table *pTab; /* The table from which records will be deleted */
89166 const char *zDb; /* Name of database holding pTab */
89167 int end, addr = 0; /* A couple addresses of generated code */
89168 int i; /* Loop counter */
89169 WhereInfo *pWInfo; /* Information about the WHERE clause */
89170 Index *pIdx; /* For looping over indices of the table */
89171 int iTabCur; /* Cursor number for the table */
89172 int iDataCur; /* VDBE cursor for the canonical data source */
89173 int iIdxCur; /* Cursor number of the first index */
 
89174 sqlite3 *db; /* Main database structure */
89175 AuthContext sContext; /* Authorization context */
89176 NameContext sNC; /* Name context to resolve expressions in */
89177 int iDb; /* Database number */
89178 int memCnt = -1; /* Memory cell used for change counting */
89179 int rcauth; /* Value returned by authorization callback */
89180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89181 #ifndef SQLITE_OMIT_TRIGGER
89182 int isView; /* True if attempting to delete from a view */
89183 Trigger *pTrigger; /* List of table triggers, if required */
89184 #endif
89185
@@ -89230,15 +89172,15 @@
89230 if( rcauth==SQLITE_DENY ){
89231 goto delete_from_cleanup;
89232 }
89233 assert(!isView || pTrigger);
89234
89235 /* Assign cursor number to the table and all its indices.
89236 */
89237 assert( pTabList->nSrc==1 );
89238 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
89239 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
89240 pParse->nTab++;
89241 }
89242
89243 /* Start the view context
89244 */
@@ -89300,132 +89242,162 @@
89300 assert( pIdx->pSchema==pTab->pSchema );
89301 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
89302 }
89303 }else
89304 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
89305 if( !HasRowid(pTab) ){
89306 /* There is a WHERE clause on a WITHOUT ROWID table.
89307 */
89308 Index *pPk; /* The PRIMARY KEY index on the table */
89309 int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
89310 int iEph; /* Ephemeral table holding all primary key values */
89311 int iKey; /* Key value inserting into iEph */
89312 i16 nPk; /* Number of components of the PRIMARY KEY */
89313
89314 pPk = sqlite3PrimaryKeyIndex(pTab);
89315 assert( pPk!=0 );
89316 nPk = pPk->nKeyCol;
89317 iPk = pParse->nMem+1;
89318 pParse->nMem += nPk;
89319 iKey = ++pParse->nMem;
89320 iEph = pParse->nTab++;
89321
89322 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
89323 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
89324 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, 0, 0);
89325 if( pWInfo==0 ) goto delete_from_cleanup;
89326 for(i=0; i<nPk; i++){
89327 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, pPk->aiColumn[i],iPk+i);
89328 }
89329 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89330 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89331 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, iKey);
89332 if( db->flags & SQLITE_CountRows ){
89333 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89334 }
89335 sqlite3WhereEnd(pWInfo);
89336
89337 /* Open cursors for all indices of the table.
89338 */
89339 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite,
89340 iTabCur, &iDataCur, &iIdxCur);
89341
89342 /* Loop over the primary keys to be deleted. */
89343 addr = sqlite3VdbeAddOp1(v, OP_Rewind, iEph);
89344 sqlite3VdbeAddOp2(v, OP_RowKey, iEph, iPk);
89345
89346 /* Delete the row */
89347 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89348 iPk, 0, 1, OE_Default, 0);
89349
89350 /* End of the delete loop */
89351 sqlite3VdbeAddOp2(v, OP_Next, iEph, addr+1);
89352 sqlite3VdbeJumpHere(v, addr);
89353
89354 /* Close the cursors open on the table and its indexes. */
89355 assert( iDataCur>=iIdxCur );
89356 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89357 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur+i);
89358 }
89359 }else{
89360 /* There is a WHERE clause on a rowid table. Run a loop that extracts
89361 ** all rowids to be deleted into a RowSet.
89362 */
89363 int iRowSet = ++pParse->nMem; /* Register for rowset of rows to delete */
89364 int iRowid = ++pParse->nMem; /* Used for storing rowid values. */
89365 int regRowid; /* Actual register containing rowids */
89366
89367 /* Collect rowids of every row to be deleted.
89368 */
89369 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
89370 pWInfo = sqlite3WhereBegin(
89371 pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
89372 );
89373 if( pWInfo==0 ) goto delete_from_cleanup;
89374 regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iRowid, 0);
89375 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
89376 if( db->flags & SQLITE_CountRows ){
89377 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89378 }
89379 sqlite3WhereEnd(pWInfo);
89380
89381 /* Delete every item whose key was written to the list during the
89382 ** database scan. We have to delete items after the scan is complete
89383 ** because deleting an item can change the scan order. */
89384 end = sqlite3VdbeMakeLabel(v);
89385
89386 /* Unless this is a view, open cursors for the table we are
89387 ** deleting from and all its indices. If this is a view, then the
89388 ** only effect this statement has is to fire the INSTEAD OF
89389 ** triggers. */
89390 if( !isView ){
89391 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur,
89392 &iDataCur, &iIdxCur);
89393 assert( iDataCur==iTabCur );
89394 assert( iIdxCur==iDataCur+1 );
89395 }
89396
89397 addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);
89398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89399 /* Delete the row */
89400 #ifndef SQLITE_OMIT_VIRTUALTABLE
89401 if( IsVirtual(pTab) ){
89402 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
89403 sqlite3VtabMakeWritable(pParse, pTab);
89404 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);
89405 sqlite3VdbeChangeP5(v, OE_Abort);
89406 sqlite3MayAbort(pParse);
89407 }else
89408 #endif
89409 {
89410 int count = (pParse->nested==0); /* True to count changes */
89411 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89412 iRowid, 1, count, OE_Default, 0);
89413 }
89414
89415 /* End of the delete loop */
89416 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
89417 sqlite3VdbeResolveLabel(v, end);
89418
 
 
 
 
 
 
 
89419 /* Close the cursors open on the table and its indexes. */
89420 if( !isView && !IsVirtual(pTab) ){
89421 sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
89422 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89423 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
89424 }
89425 }
89426 }
89427
89428 /* Update the sqlite_sequence table by storing the content of the
89429 ** maximum rowid counter values recorded while inserting into
89430 ** autoincrement tables.
89431 */
@@ -89445,10 +89417,11 @@
89445
89446 delete_from_cleanup:
89447 sqlite3AuthContextPop(&sContext);
89448 sqlite3SrcListDelete(db, pTabList);
89449 sqlite3ExprDelete(db, pWhere);
 
89450 return;
89451 }
89452 /* Make sure "isView" and other macros defined above are undefined. Otherwise
89453 ** thely may interfere with compilation of other functions in this file
89454 ** (or in another file, if this file becomes part of the amalgamation). */
@@ -89511,10 +89484,11 @@
89511 /* If there are any triggers to fire, allocate a range of registers to
89512 ** use for the old.* references in the triggers. */
89513 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
89514 u32 mask; /* Mask of OLD.* columns in use */
89515 int iCol; /* Iterator used while populating OLD.* */
 
89516
89517 /* TODO: Could use temporary registers here. Also could attempt to
89518 ** avoid copying the contents of the rowid register. */
89519 mask = sqlite3TriggerColmask(
89520 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
@@ -89531,19 +89505,23 @@
89531 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
89532 }
89533 }
89534
89535 /* Invoke BEFORE DELETE trigger programs. */
 
89536 sqlite3CodeRowTrigger(pParse, pTrigger,
89537 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
89538 );
89539
89540 /* Seek the cursor to the row to be deleted again. It may be that
89541 ** the BEFORE triggers coded above have already removed the row
89542 ** being deleted. Do not attempt to delete the row a second time, and
89543 ** do not fire AFTER triggers. */
89544 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
 
 
 
89545
89546 /* Do FK processing. This call checks that any FK constraints that
89547 ** refer to this table (i.e. constraints attached to other tables)
89548 ** are not violated by deleting this row. */
89549 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -91969,10 +91947,11 @@
91969 Vdbe *v = sqlite3GetVdbe(pParse);
91970
91971 assert( pIdx==0 || pIdx->pTable==pTab );
91972 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
91973 assert( pIdx!=0 || pFKey->nCol==1 );
 
91974
91975 if( nIncr<0 ){
91976 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
91977 }
91978
@@ -92021,10 +92000,11 @@
92021 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
92022 pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
92023 }else{
92024 Expr *pEq, *pAll = 0;
92025 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
 
92026 for(i=0; i<pPk->nKeyCol; i++){
92027 i16 iCol = pIdx->aiColumn[i];
92028 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
92029 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
92030 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
@@ -93599,11 +93579,11 @@
93599 }
93600
93601 /* If this is not a view, open the table and and all indices */
93602 if( !isView ){
93603 int nIdx;
93604 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1,
93605 &iDataCur, &iIdxCur);
93606 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
93607 if( aRegIdx==0 ){
93608 goto insert_cleanup;
93609 }
@@ -94459,42 +94439,50 @@
94459 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
94460 Parse *pParse, /* Parsing context */
94461 Table *pTab, /* Table to be opened */
94462 int op, /* OP_OpenRead or OP_OpenWrite */
94463 int iBase, /* Use this for the table cursor, if there is one */
 
94464 int *piDataCur, /* Write the database source cursor number here */
94465 int *piIdxCur /* Write the first index cursor number here */
94466 ){
94467 int i;
94468 int iDb;
 
94469 Index *pIdx;
94470 Vdbe *v;
94471
94472 assert( op==OP_OpenRead || op==OP_OpenWrite );
94473 if( IsVirtual(pTab) ){
 
94474 *piDataCur = 0;
94475 *piIdxCur = 1;
94476 return 0;
94477 }
94478 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94479 v = sqlite3GetVdbe(pParse);
94480 assert( v!=0 );
94481 if( iBase<0 ) iBase = pParse->nTab;
94482 if( HasRowid(pTab) ){
94483 *piDataCur = iBase++;
94484 sqlite3OpenTable(pParse, *piDataCur, iDb, pTab, op);
 
94485 }else{
94486 sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
94487 }
94488 *piIdxCur = iBase;
94489 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94490 int iIdxCur = iBase++;
94491 assert( pIdx->pSchema==pTab->pSchema );
94492 if( pIdx->autoIndex==2 && !HasRowid(pTab) ) *piDataCur = iIdxCur;
94493 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
94494 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
94495 VdbeComment((v, "%s", pIdx->zName));
 
 
 
 
94496 }
94497 if( iBase>pParse->nTab ) pParse->nTab = iBase;
94498 return i;
94499 }
94500
@@ -96664,10 +96652,14 @@
96664 /* iArg: */ SQLITE_VdbeAddopTrace },
96665 { /* zName: */ "vdbe_debug",
96666 /* ePragTyp: */ PragTyp_FLAG,
96667 /* ePragFlag: */ 0,
96668 /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
 
 
 
 
96669 { /* zName: */ "vdbe_listing",
96670 /* ePragTyp: */ PragTyp_FLAG,
96671 /* ePragFlag: */ 0,
96672 /* iArg: */ SQLITE_VdbeListing },
96673 { /* zName: */ "vdbe_trace",
@@ -96691,11 +96683,11 @@
96691 /* ePragTyp: */ PragTyp_FLAG,
96692 /* ePragFlag: */ 0,
96693 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
96694 #endif
96695 };
96696 /* Number of pragmas: 56 on by default, 68 total. */
96697 /* End of the automatically generated pragma table.
96698 ***************************************************************************/
96699
96700 /*
96701 ** Interpret the given string as a safety level. Return 0 for OFF,
@@ -98117,11 +98109,11 @@
98117 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
98118 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98119 sqlite3VdbeJumpHere(v, addr);
98120 sqlite3ExprCacheClear(pParse);
98121 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98122 1, &iDataCur, &iIdxCur);
98123 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98124 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98125 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98126 }
98127 pParse->nMem = MAX(pParse->nMem, 8+j);
@@ -99052,10 +99044,17 @@
99052 }
99053 assert( i>=0 && i<db->nDb );
99054 }
99055 return i;
99056 }
 
 
 
 
 
 
 
99057
99058 /*
99059 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
99060 */
99061 static int sqlite3Prepare(
@@ -99210,10 +99209,11 @@
99210 sqlite3DbFree(db, pT);
99211 }
99212
99213 end_prepare:
99214
 
99215 sqlite3StackFree(db, pParse);
99216 rc = sqlite3ApiExit(db, rc);
99217 assert( (rc&db->errMask)==rc );
99218 return rc;
99219 }
@@ -101776,20 +101776,20 @@
101776 */
101777 if( op!=TK_ALL ){
101778 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
101779 struct ExprList_item *pItem;
101780 for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
101781 assert( pItem->iOrderByCol>0 );
101782 if( pItem->iOrderByCol==i ) break;
101783 }
101784 if( j==nOrderBy ){
101785 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
101786 if( pNew==0 ) return SQLITE_NOMEM;
101787 pNew->flags |= EP_IntValue;
101788 pNew->u.iValue = i;
101789 pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
101790 if( pOrderBy ) pOrderBy->a[nOrderBy++].iOrderByCol = (u16)i;
101791 }
101792 }
101793 }
101794
101795 /* Compute the comparison permutation and keyinfo that is used with
@@ -101801,12 +101801,13 @@
101801 */
101802 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
101803 if( aPermute ){
101804 struct ExprList_item *pItem;
101805 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
101806 assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
101807 aPermute[i] = pItem->iOrderByCol - 1;
 
101808 }
101809 pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
101810 if( pKeyMerge ){
101811 for(i=0; i<nOrderBy; i++){
101812 CollSeq *pColl;
@@ -102382,11 +102383,11 @@
102382
102383 /* Restriction 18. */
102384 if( p->pOrderBy ){
102385 int ii;
102386 for(ii=0; ii<p->pOrderBy->nExpr; ii++){
102387 if( p->pOrderBy->a[ii].iOrderByCol==0 ) return 0;
102388 }
102389 }
102390 }
102391
102392 /***** If we reach this point, flattening is permitted. *****/
@@ -103789,14 +103790,14 @@
103789 if( pGroupBy ){
103790 int k; /* Loop counter */
103791 struct ExprList_item *pItem; /* For looping over expression in a list */
103792
103793 for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
103794 pItem->iAlias = 0;
103795 }
103796 for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
103797 pItem->iAlias = 0;
103798 }
103799 if( p->nSelectRow>100 ) p->nSelectRow = 100;
103800 }else{
103801 p->nSelectRow = 1;
103802 }
@@ -105443,10 +105444,11 @@
105443 sqlite3VdbeDelete(v);
105444 }
105445
105446 assert( !pSubParse->pAinc && !pSubParse->pZombieTab );
105447 assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
 
105448 sqlite3StackFree(db, pSubParse);
105449
105450 return pPrg;
105451 }
105452
@@ -105757,22 +105759,23 @@
105757 WhereInfo *pWInfo; /* Information about the WHERE clause */
105758 Vdbe *v; /* The virtual database engine */
105759 Index *pIdx; /* For looping over indices */
105760 Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
105761 int nIdx; /* Number of indices that need updating */
 
105762 int iDataCur; /* Cursor for the canonical data btree */
105763 int iIdxCur; /* Cursor for the first index */
105764 sqlite3 *db; /* The database structure */
105765 int *aRegIdx = 0; /* One register assigned to each index to be updated */
105766 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
105767 ** an expression for the i-th column of the table.
105768 ** aXRef[i]==-1 if the i-th column is not changed. */
 
105769 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
105770 u8 chngRowid; /* Rowid changed in a normal table */
105771 u8 chngKey; /* Either chngPk or chngRowid */
105772 Expr *pRowidExpr = 0; /* Expression defining the new record number */
105773 int openAll = 0; /* True if all indices need to be opened */
105774 AuthContext sContext; /* The authorization context */
105775 NameContext sNC; /* The name-context to resolve expressions in */
105776 int iDb; /* Database containing the table being updated */
105777 int okOnePass; /* True for one-pass algorithm without the FIFO */
105778 int hasFK; /* True if foreign key processing is required */
@@ -105832,29 +105835,37 @@
105832 goto update_cleanup;
105833 }
105834 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
105835 goto update_cleanup;
105836 }
105837 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
105838 if( aXRef==0 ) goto update_cleanup;
105839 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
105840
105841 /* Allocate a cursors for the main database table and for all indices.
105842 ** The index cursors might not be used, but if they are used they
105843 ** need to occur right after the database cursor. So go ahead and
105844 ** allocate enough space, just in case.
105845 */
105846 pTabList->a[0].iCursor = iDataCur = pParse->nTab++;
105847 iIdxCur = iDataCur+1;
105848 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
105849 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
105850 if( pIdx->autoIndex==2 && pPk!=0 ){
105851 iDataCur = pParse->nTab;
105852 pTabList->a[0].iCursor = iDataCur;
105853 }
105854 pParse->nTab++;
105855 }
 
 
 
 
 
 
 
 
 
 
 
105856
105857 /* Initialize the name-context */
105858 memset(&sNC, 0, sizeof(sNC));
105859 sNC.pParse = pParse;
105860 sNC.pSrcList = pTabList;
@@ -105909,22 +105920,22 @@
105909 }
105910 assert( (chngRowid & chngPk)==0 );
105911 assert( chngRowid==0 || chngRowid==1 );
105912 assert( chngPk==0 || chngPk==1 );
105913 chngKey = chngRowid + chngPk;
 
 
 
 
 
105914
105915 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
105916
105917 /* Allocate memory for the array aRegIdx[]. There is one entry in the
105918 ** array for each index associated with table being updated. Fill in
105919 ** the value with a register number for indices that are to be used
105920 ** and with zero for unused indices.
105921 */
105922 if( nIdx>0 ){
105923 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
105924 if( aRegIdx==0 ) goto update_cleanup;
105925 }
105926 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
105927 int reg;
105928 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
105929 reg = ++pParse->nMem;
105930 }else{
@@ -105934,10 +105945,11 @@
105934 reg = ++pParse->nMem;
105935 break;
105936 }
105937 }
105938 }
 
105939 aRegIdx[j] = reg;
105940 }
105941
105942 /* Begin generating code. */
105943 v = sqlite3GetVdbe(pParse);
@@ -106057,46 +106069,34 @@
106057 ** Open every index that needs updating. Note that if any
106058 ** index could potentially invoke a REPLACE conflict resolution
106059 ** action, then we need to open all indices because we might need
106060 ** to be deleting some records.
106061 */
106062 if( !okOnePass && HasRowid(pTab) ){
106063 sqlite3OpenTable(pParse, iDataCur, iDb, pTab, OP_OpenWrite);
106064 }
106065 sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
106066 if( onError==OE_Replace ){
106067 openAll = 1;
106068 }else{
106069 openAll = 0;
106070 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
106071 if( pIdx->onError==OE_Replace ){
106072 openAll = 1;
106073 break;
106074 }
106075 }
106076 }
106077 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106078 int iThisCur = iIdxCur+i;
106079 assert( aRegIdx );
106080 if( (openAll || aRegIdx[i]>0)
106081 && iThisCur!=aiCurOnePass[1]
106082 ){
106083 assert( iThisCur!=aiCurOnePass[0] );
106084 sqlite3VdbeAddOp3(v, OP_OpenWrite, iThisCur, pIdx->tnum, iDb);
106085 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
106086 assert( pParse->nTab>iThisCur );
106087 VdbeComment((v, "%s", pIdx->zName));
106088 if( okOnePass && pPk && iThisCur==iDataCur ){
106089 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak,
106090 regKey, nKey);
106091 }
106092 }
106093 }
106094 }
106095
106096 /* Top of the update loop */
106097 if( okOnePass ){
 
 
 
 
106098 labelContinue = labelBreak;
106099 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106100 }else if( pPk ){
106101 labelContinue = sqlite3VdbeMakeLabel(v);
106102 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
@@ -106285,11 +106285,11 @@
106285 sqlite3VdbeResolveLabel(v, labelBreak);
106286
106287 /* Close all tables */
106288 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106289 assert( aRegIdx );
106290 if( openAll || aRegIdx[i]>0 ){
106291 sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
106292 }
106293 }
106294 if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
106295
@@ -106312,12 +106312,11 @@
106312 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
106313 }
106314
106315 update_cleanup:
106316 sqlite3AuthContextPop(&sContext);
106317 sqlite3DbFree(db, aRegIdx);
106318 sqlite3DbFree(db, aXRef);
106319 sqlite3SrcListDelete(db, pTabList);
106320 sqlite3ExprListDelete(db, pChanges);
106321 sqlite3ExprDelete(db, pWhere);
106322 return;
106323 }
@@ -107536,10 +107535,11 @@
107536
107537 if( pParse->pVdbe ){
107538 sqlite3VdbeFinalize(pParse->pVdbe);
107539 }
107540 sqlite3DeleteTable(db, pParse->pNewTable);
 
107541 sqlite3StackFree(db, pParse);
107542 }
107543
107544 assert( (rc&0xff)==rc );
107545 rc = sqlite3ApiExit(db, rc);
@@ -107913,11 +107913,28 @@
107913 ** generating the code that loops through a table looking for applicable
107914 ** rows. Indices are selected and used to speed the search when doing
107915 ** so is applicable. Because this module is responsible for selecting
107916 ** indices, you might also think of this module as the "query optimizer".
107917 */
107918
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107919
107920 /*
107921 ** Trace output macros
107922 */
107923 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
@@ -107965,10 +107982,11 @@
107965 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
107966 int iTabCur; /* The VDBE cursor used to access the table */
107967 int iIdxCur; /* The VDBE cursor used to access pIdx */
107968 int addrBrk; /* Jump here to break out of the loop */
107969 int addrNxt; /* Jump here to start the next IN combination */
 
107970 int addrCont; /* Jump here to continue with the next loop cycle */
107971 int addrFirst; /* First instruction of interior of the loop */
107972 int addrBody; /* Beginning of the body of this loop */
107973 u8 iFrom; /* Which entry in the FROM clause */
107974 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
@@ -108014,11 +108032,11 @@
108014 LogEst rRun; /* Cost of running each loop */
108015 LogEst nOut; /* Estimated number of output rows */
108016 union {
108017 struct { /* Information for internal btree tables */
108018 u16 nEq; /* Number of equality constraints */
108019 u16 nSkip; /* Number of initial index columns skipped */
108020 Index *pIndex; /* Index used, or NULL */
108021 } btree;
108022 struct { /* Information for virtual tables */
108023 int idxNum; /* Index number */
108024 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -108355,10 +108373,14 @@
108355 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
108356 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108357 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108358 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108359 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
 
 
 
 
108360
108361 /*
108362 ** Return the estimated number of output rows from a WHERE clause
108363 */
108364 SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
@@ -109006,13 +109028,10 @@
109006 }
109007 assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
109008
109009 pRight = pList->a[0].pExpr;
109010 op = pRight->op;
109011 if( op==TK_REGISTER ){
109012 op = pRight->op2;
109013 }
109014 if( op==TK_VARIABLE ){
109015 Vdbe *pReprepare = pParse->pReprepare;
109016 int iCol = pRight->iColumn;
109017 pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_NONE);
109018 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
@@ -110759,11 +110778,11 @@
110759 return iReg;
110760 }
110761
110762 /*
110763 ** Generate code that will evaluate all == and IN constraints for an
110764 ** index.
110765 **
110766 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
110767 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
110768 ** The index has as many as three equality constraints, but in this
110769 ** example, the third "c" value is an inequality. So only two
@@ -110774,13 +110793,19 @@
110774 ** In the example above nEq==2. But this subroutine works for any value
110775 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
110776 ** The only thing it does is allocate the pLevel->iMem memory cell and
110777 ** compute the affinity string.
110778 **
110779 ** This routine always allocates at least one memory cell and returns
110780 ** the index of that memory cell. The code that
110781 ** calls this routine will use that memory cell to store the termination
 
 
 
 
 
 
110782 ** key value of the loop. If one or more IN operators appear, then
110783 ** this routine allocates an additional nEq memory cells for internal
110784 ** use.
110785 **
110786 ** Before returning, *pzAff is set to point to a buffer containing a
@@ -110803,11 +110828,12 @@
110803 WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
110804 int bRev, /* Reverse the order of IN operators */
110805 int nExtraReg, /* Number of extra registers to allocate */
110806 char **pzAff /* OUT: Set to point to affinity string */
110807 ){
110808 int nEq; /* The number of == or IN constraints to code */
 
110809 Vdbe *v = pParse->pVdbe; /* The vm under construction */
110810 Index *pIdx; /* The index being used for this loop */
110811 WhereTerm *pTerm; /* A single constraint term */
110812 WhereLoop *pLoop; /* The WhereLoop object */
110813 int j; /* Loop counter */
@@ -110817,10 +110843,11 @@
110817
110818 /* This module is only called on query plans that use an index. */
110819 pLoop = pLevel->pWLoop;
110820 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
110821 nEq = pLoop->u.btree.nEq;
 
110822 pIdx = pLoop->u.btree.pIndex;
110823 assert( pIdx!=0 );
110824
110825 /* Figure out how many memory cells we will need then allocate them.
110826 */
@@ -110830,19 +110857,34 @@
110830
110831 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
110832 if( !zAff ){
110833 pParse->db->mallocFailed = 1;
110834 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110835
110836 /* Evaluate the equality constraints
110837 */
110838 assert( zAff==0 || (int)strlen(zAff)>=nEq );
110839 for(j=0; j<nEq; j++){
110840 int r1;
110841 pTerm = pLoop->aLTerm[j];
110842 assert( pTerm!=0 );
110843 /* The following true for indices with redundant columns.
110844 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
110845 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
110846 testcase( pTerm->wtFlags & TERM_VIRTUAL );
110847 r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
110848 if( r1!=regBase+j ){
@@ -110912,11 +110954,12 @@
110912 ** It is the responsibility of the caller to free the buffer when it is
110913 ** no longer required.
110914 */
110915 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
110916 Index *pIndex = pLoop->u.btree.pIndex;
110917 int nEq = pLoop->u.btree.nEq;
 
110918 int i, j;
110919 Column *aCol = pTab->aCol;
110920 i16 *aiColumn = pIndex->aiColumn;
110921 StrAccum txt;
110922
@@ -110926,11 +110969,18 @@
110926 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
110927 txt.db = db;
110928 sqlite3StrAccumAppend(&txt, " (", 2);
110929 for(i=0; i<nEq; i++){
110930 char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
110931 explainAppendTerm(&txt, i, z, "=");
 
 
 
 
 
 
 
110932 }
110933
110934 j = i;
110935 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
110936 char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -110956,11 +111006,14 @@
110956 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
110957 int iLevel, /* Value for "level" column of output */
110958 int iFrom, /* Value for "from" column of output */
110959 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
110960 ){
110961 if( pParse->explain==2 ){
 
 
 
110962 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
110963 Vdbe *v = pParse->pVdbe; /* VM being constructed */
110964 sqlite3 *db = pParse->db; /* Database handle */
110965 char *zMsg; /* Text to add to EQP output */
110966 int iId = pParse->iSelectId; /* Select id (left-most output column) */
@@ -111062,11 +111115,11 @@
111062 iCur = pTabItem->iCursor;
111063 pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
111064 bRev = (pWInfo->revMask>>iLevel)&1;
111065 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
111066 && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
111067 VdbeNoopComment((v, "Begin WHERE-Loop %d: %s", iLevel,pTabItem->pTab->zName));
111068
111069 /* Create labels for the "break" and "continue" instructions
111070 ** for the current loop. Jump to addrBrk to break out of a loop.
111071 ** Jump to cont to go immediately to the next iteration of the
111072 ** loop.
@@ -111289,12 +111342,12 @@
111289 static const u8 aEndOp[] = {
111290 OP_Noop, /* 0: (!end_constraints) */
111291 OP_IdxGE, /* 1: (end_constraints && !bRev) */
111292 OP_IdxLT /* 2: (end_constraints && bRev) */
111293 };
111294 int nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111295 int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111296 int regBase; /* Base register holding constraint values */
111297 int r1; /* Temp register */
111298 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111299 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111300 int startEq; /* True if range start uses ==, >= or <= */
@@ -111304,14 +111357,15 @@
111304 Index *pIdx; /* The index we will be using */
111305 int iIdxCur; /* The VDBE cursor for the index */
111306 int nExtraReg = 0; /* Number of extra registers needed */
111307 int op; /* Instruction opcode */
111308 char *zStartAff; /* Affinity for start of range constraint */
111309 char *zEndAff; /* Affinity for end of range constraint */
111310
111311 pIdx = pLoop->u.btree.pIndex;
111312 iIdxCur = pLevel->iIdxCur;
 
111313
111314 /* If this loop satisfies a sort order (pOrderBy) request that
111315 ** was passed to this function to implement a "SELECT min(x) ..."
111316 ** query, then the caller will only allow the loop to run for
111317 ** a single iteration. This means that the first row returned
@@ -111321,12 +111375,11 @@
111321 */
111322 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111323 && (pWInfo->bOBSat!=0)
111324 && (pIdx->nKeyCol>nEq)
111325 ){
111326 /* assert( pOrderBy->nExpr==1 ); */
111327 /* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
111328 isMinQuery = 1;
111329 nExtraReg = 1;
111330 }
111331
111332 /* Find any inequality constraint terms for the start and end
@@ -111345,11 +111398,12 @@
111345 /* Generate code to evaluate all constraint terms using == or IN
111346 ** and store the values of those terms in an array of registers
111347 ** starting at regBase.
111348 */
111349 regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
111350 zEndAff = sqlite3DbStrDup(db, zStartAff);
 
111351 addrNxt = pLevel->addrNxt;
111352
111353 /* If we are doing a reverse order scan on an ascending index, or
111354 ** a forward order scan on a descending index, interchange the
111355 ** start and end terms (pRangeStart and pRangeEnd).
@@ -111415,27 +111469,19 @@
111415 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111416 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111417 if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111418 sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
111419 }
111420 if( zEndAff ){
111421 if( sqlite3CompareAffinity(pRight, zEndAff[nEq])==SQLITE_AFF_NONE){
111422 /* Since the comparison is to be performed with no conversions
111423 ** applied to the operands, set the affinity to apply to pRight to
111424 ** SQLITE_AFF_NONE. */
111425 zEndAff[nEq] = SQLITE_AFF_NONE;
111426 }
111427 if( sqlite3ExprNeedsNoAffinityChange(pRight, zEndAff[nEq]) ){
111428 zEndAff[nEq] = SQLITE_AFF_NONE;
111429 }
111430 }
111431 codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
111432 nConstraint++;
111433 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
111434 }
111435 sqlite3DbFree(db, zStartAff);
111436 sqlite3DbFree(db, zEndAff);
111437
111438 /* Top of the loop body */
111439 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111440
111441 /* Check if the index cursor is past the end of the range. */
@@ -111453,12 +111499,17 @@
111453 ** If it is, jump to the next iteration of the loop.
111454 */
111455 r1 = sqlite3GetTempReg(pParse);
111456 testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111457 testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111458 if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 ){
 
 
 
 
111459 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
 
111460 sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111461 }
111462 sqlite3ReleaseTempReg(pParse, r1);
111463
111464 /* Seek the table cursor, if required */
@@ -111769,11 +111820,11 @@
111769 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
111770 if( pAlt==0 ) continue;
111771 if( pAlt->wtFlags & (TERM_CODED) ) continue;
111772 testcase( pAlt->eOperator & WO_EQ );
111773 testcase( pAlt->eOperator & WO_IN );
111774 VdbeNoopComment((v, "begin transitive constraint"));
111775 pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
111776 if( pEAlt ){
111777 *pEAlt = *pAlt->pExpr;
111778 pEAlt->pLeft = pE->pLeft;
111779 sqlite3ExprIfFalse(pParse, pEAlt, addrCont, SQLITE_JUMPIFNULL);
@@ -111842,16 +111893,11 @@
111842 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
111843 int i = sqlite3Strlen30(zName) - 1;
111844 while( zName[i]!='_' ) i--;
111845 zName += i;
111846 }
111847 if( p->u.btree.nSkip ){
111848 sqlite3DebugPrintf(".%-15s %d+%d", zName,
111849 p->u.btree.nSkip, p->u.btree.nEq);
111850 }else{
111851 sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
111852 }
111853 }else{
111854 sqlite3DebugPrintf("%20s","");
111855 }
111856 }else{
111857 char *z;
@@ -111874,10 +111920,11 @@
111874 int i;
111875 Vdbe *v = pWInfo->pParse->pVdbe;
111876 sqlite3ExplainBegin(v);
111877 for(i=0; i<p->nLTerm; i++){
111878 WhereTerm *pTerm = p->aLTerm[i];
 
111879 sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
111880 sqlite3ExplainPush(v);
111881 whereExplainTerm(v, pTerm);
111882 sqlite3ExplainPop(v);
111883 sqlite3ExplainNL(v);
@@ -112157,10 +112204,11 @@
112157 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
112158 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
112159 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
112160 for(j=pLoop->nLTerm-1; j>=0; j--){
112161 pX = pLoop->aLTerm[j];
 
112162 if( pX==pTerm ) break;
112163 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
112164 }
112165 if( j<0 ) pLoop->nOut += pTerm->truthProb;
112166 }
@@ -112186,11 +112234,12 @@
112186 WhereTerm *pTerm; /* A WhereTerm under consideration */
112187 int opMask; /* Valid operators for constraints */
112188 WhereScan scan; /* Iterator for WHERE terms */
112189 Bitmask saved_prereq; /* Original value of pNew->prereq */
112190 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
112191 int saved_nEq; /* Original value of pNew->u.btree.nEq */
 
112192 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
112193 LogEst saved_nOut; /* Original value of pNew->nOut */
112194 int iCol; /* Index of the column in the table */
112195 int rc = SQLITE_OK; /* Return code */
112196 LogEst nRowEst; /* Estimated index selectivity */
@@ -112221,16 +112270,35 @@
112221 nRowEst = 0;
112222 }
112223 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
112224 opMask, pProbe);
112225 saved_nEq = pNew->u.btree.nEq;
 
112226 saved_nLTerm = pNew->nLTerm;
112227 saved_wsFlags = pNew->wsFlags;
112228 saved_prereq = pNew->prereq;
112229 saved_nOut = pNew->nOut;
112230 pNew->rSetup = 0;
112231 rLogSize = estLog(sqlite3LogEst(pProbe->aiRowEst[0]));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112232 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
112233 int nIn = 0;
112234 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
112235 int nRecValid = pBuilder->nRecValid;
112236 #endif
@@ -112262,12 +112330,14 @@
112262 }
112263 pNew->rRun += nIn;
112264 pNew->u.btree.nEq++;
112265 pNew->nOut = nRowEst + nInMul + nIn;
112266 }else if( pTerm->eOperator & (WO_EQ) ){
112267 assert( (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0
112268 || nInMul==0 );
 
 
112269 pNew->wsFlags |= WHERE_COLUMN_EQ;
112270 if( iCol<0
112271 || (pProbe->onError!=OE_None && nInMul==0
112272 && pNew->u.btree.nEq==pProbe->nKeyCol-1)
112273 ){
@@ -112344,10 +112414,11 @@
112344 pBuilder->nRecValid = nRecValid;
112345 #endif
112346 }
112347 pNew->prereq = saved_prereq;
112348 pNew->u.btree.nEq = saved_nEq;
 
112349 pNew->wsFlags = saved_wsFlags;
112350 pNew->nOut = saved_nOut;
112351 pNew->nLTerm = saved_nLTerm;
112352 return rc;
112353 }
@@ -112490,10 +112561,11 @@
112490 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
112491 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
112492 if( pTerm->prereqRight & pNew->maskSelf ) continue;
112493 if( termCanDriveIndex(pTerm, pSrc, 0) ){
112494 pNew->u.btree.nEq = 1;
 
112495 pNew->u.btree.pIndex = 0;
112496 pNew->nLTerm = 1;
112497 pNew->aLTerm[0] = pTerm;
112498 /* TUNING: One-time cost for computing the automatic index is
112499 ** approximately 7*N*log2(N) where N is the number of rows in
@@ -112519,10 +112591,11 @@
112519 if( pProbe->pPartIdxWhere!=0
112520 && !whereUsablePartialIndex(pNew->iTab, pWC, pProbe->pPartIdxWhere) ){
112521 continue; /* Partial index inappropriate for this query */
112522 }
112523 pNew->u.btree.nEq = 0;
 
112524 pNew->nLTerm = 0;
112525 pNew->iSortIdx = 0;
112526 pNew->rSetup = 0;
112527 pNew->prereq = mExtra;
112528 pNew->nOut = rSize;
@@ -112604,11 +112677,12 @@
112604 /*
112605 ** Add all WhereLoop objects for a table of the join identified by
112606 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
112607 */
112608 static int whereLoopAddVirtual(
112609 WhereLoopBuilder *pBuilder /* WHERE clause information */
 
112610 ){
112611 WhereInfo *pWInfo; /* WHERE analysis context */
112612 Parse *pParse; /* The parsing context */
112613 WhereClause *pWC; /* The WHERE clause */
112614 struct SrcList_item *pSrc; /* The FROM clause term to search */
@@ -112694,11 +112768,11 @@
112694 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
112695 pIdxInfo->estimatedRows = 25;
112696 rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112697 if( rc ) goto whereLoopAddVtab_exit;
112698 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112699 pNew->prereq = 0;
112700 mxTerm = -1;
112701 assert( pNew->nLSlot>=nConstraint );
112702 for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
112703 pNew->u.vtab.omitMask = 0;
112704 for(i=0; i<nConstraint; i++, pIdxCons++){
@@ -112821,12 +112895,11 @@
112821 continue;
112822 }
112823 sCur.n = 0;
112824 #ifndef SQLITE_OMIT_VIRTUALTABLE
112825 if( IsVirtual(pItem->pTab) ){
112826 rc = whereLoopAddVirtual(&sSubBuild);
112827 for(i=0; i<sCur.n; i++) sCur.a[i].prereq |= mExtra;
112828 }else
112829 #endif
112830 {
112831 rc = whereLoopAddBtree(&sSubBuild, mExtra);
112832 }
@@ -112892,11 +112965,11 @@
112892 if( ((pItem->jointype|priorJoinType) & (JT_LEFT|JT_CROSS))!=0 ){
112893 mExtra = mPrior;
112894 }
112895 priorJoinType = pItem->jointype;
112896 if( IsVirtual(pItem->pTab) ){
112897 rc = whereLoopAddVirtual(pBuilder);
112898 }else{
112899 rc = whereLoopAddBtree(pBuilder, mExtra);
112900 }
112901 if( rc==SQLITE_OK ){
112902 rc = whereLoopAddOr(pBuilder, mExtra);
@@ -113053,10 +113126,11 @@
113053 for(j=0; j<nColumn; j++){
113054 u8 bOnce; /* True to run the ORDER BY search loop */
113055
113056 /* Skip over == and IS NULL terms */
113057 if( j<pLoop->u.btree.nEq
 
113058 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
113059 ){
113060 if( i & WO_ISNULL ){
113061 testcase( isOrderDistinct );
113062 isOrderDistinct = 0;
@@ -113478,10 +113552,11 @@
113478 if( pItem->zIndex ) return 0;
113479 iCur = pItem->iCursor;
113480 pWC = &pWInfo->sWC;
113481 pLoop = pBuilder->pNew;
113482 pLoop->wsFlags = 0;
 
113483 pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
113484 if( pTerm ){
113485 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
113486 pLoop->aLTerm[0] = pTerm;
113487 pLoop->nLTerm = 1;
@@ -113706,11 +113781,10 @@
113706 /* Split the WHERE clause into separate subexpressions where each
113707 ** subexpression is separated by an AND operator.
113708 */
113709 initMaskSet(pMaskSet);
113710 whereClauseInit(&pWInfo->sWC, pWInfo);
113711 sqlite3ExprCodeConstants(pParse, pWhere);
113712 whereSplit(&pWInfo->sWC, pWhere, TK_AND);
113713 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113714
113715 /* Special case: a WHERE clause that is constant. Evaluate the
113716 ** expression and either jump over all of the code or fall thru.
@@ -114021,10 +114095,11 @@
114021 notReady = codeOneLoopStart(pWInfo, ii, notReady);
114022 pWInfo->iContinue = pLevel->addrCont;
114023 }
114024
114025 /* Done. */
 
114026 return pWInfo;
114027
114028 /* Jump here if malloc fails */
114029 whereBeginError:
114030 if( pWInfo ){
@@ -114047,12 +114122,14 @@
114047 SrcList *pTabList = pWInfo->pTabList;
114048 sqlite3 *db = pParse->db;
114049
114050 /* Generate loop termination code.
114051 */
 
114052 sqlite3ExprCacheClear(pParse);
114053 for(i=pWInfo->nLevel-1; i>=0; i--){
 
114054 pLevel = &pWInfo->a[i];
114055 pLoop = pLevel->pWLoop;
114056 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114057 if( pLevel->op!=OP_Noop ){
114058 sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
@@ -114068,12 +114145,17 @@
114068 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114069 }
114070 sqlite3DbFree(db, pLevel->u.in.aInLoop);
114071 }
114072 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
 
 
 
 
 
 
114073 if( pLevel->iLeftJoin ){
114074 int addr;
114075 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114076 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114077 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114078 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114079 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
@@ -114086,11 +114168,11 @@
114086 }else{
114087 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
114088 }
114089 sqlite3VdbeJumpHere(v, addr);
114090 }
114091 VdbeNoopComment((v, "End WHERE-Loop %d: %s", i,
114092 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
114093 }
114094
114095 /* The "break" point is here, just past the end of the outer loop.
114096 ** Set it.
@@ -123671,10 +123753,14 @@
123671 char *aDoclist; /* Pointer to doclist buffer */
123672 int nDoclist; /* Size of aDoclist[] in bytes */
123673 };
123674
123675 SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
 
 
 
 
123676
123677 /* fts3.c */
123678 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
123679 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
123680 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
@@ -123779,36 +123865,63 @@
123779 q[-1] &= 0x7f; /* turn off high bit in final byte */
123780 assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
123781 return (int) (q - (unsigned char *)p);
123782 }
123783
 
 
 
 
 
 
 
123784 /*
123785 ** Read a 64-bit variable-length integer from memory starting at p[0].
123786 ** Return the number of bytes read, or 0 on error.
123787 ** The value is stored in *v.
123788 */
123789 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){
123790 const unsigned char *q = (const unsigned char *) p;
123791 sqlite_uint64 x = 0, y = 1;
123792 while( (*q&0x80)==0x80 && q-(unsigned char *)p<FTS3_VARINT_MAX ){
123793 x += y * (*q++ & 0x7f);
123794 y <<= 7;
123795 }
123796 x += y * (*q++);
123797 *v = (sqlite_int64) x;
123798 return (int) (q - (unsigned char *)p);
 
 
 
 
 
 
 
 
 
123799 }
123800
123801 /*
123802 ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
123803 ** 32-bit integer before it is returned.
123804 */
123805 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
123806 sqlite_int64 i;
123807 int ret = sqlite3Fts3GetVarint(p, &i);
123808 *pi = (int) i;
123809 return ret;
 
 
 
 
 
 
 
 
 
 
 
123810 }
123811
123812 /*
123813 ** Return the number of bytes required to encode v as a varint
123814 */
@@ -125164,14 +125277,14 @@
125164 int nBuffer; /* Total term size */
125165
125166 /* Load the next term on the node into zBuffer. Use realloc() to expand
125167 ** the size of zBuffer if required. */
125168 if( !isFirstTerm ){
125169 zCsr += sqlite3Fts3GetVarint32(zCsr, &nPrefix);
125170 }
125171 isFirstTerm = 0;
125172 zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
125173
125174 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
125175 rc = FTS_CORRUPT_VTAB;
125176 goto finish_scan;
125177 }
@@ -125255,11 +125368,11 @@
125255 int rc; /* Return code */
125256 int iHeight; /* Height of this node in tree */
125257
125258 assert( piLeaf || piLeaf2 );
125259
125260 sqlite3Fts3GetVarint32(zNode, &iHeight);
125261 rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
125262 assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
125263
125264 if( rc==SQLITE_OK && iHeight>1 ){
125265 char *zBlob = 0; /* Blob read from %_segments table */
@@ -125457,15 +125570,15 @@
125457
125458 while( *p1 || *p2 ){
125459 int iCol1; /* The current column index in pp1 */
125460 int iCol2; /* The current column index in pp2 */
125461
125462 if( *p1==POS_COLUMN ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
125463 else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
125464 else iCol1 = 0;
125465
125466 if( *p2==POS_COLUMN ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
125467 else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
125468 else iCol2 = 0;
125469
125470 if( iCol1==iCol2 ){
125471 sqlite3_int64 i1 = 0; /* Last position from pp1 */
@@ -125554,15 +125667,15 @@
125554 assert( isSaveLeft==0 || isExact==0 );
125555
125556 assert( p!=0 && *p1!=0 && *p2!=0 );
125557 if( *p1==POS_COLUMN ){
125558 p1++;
125559 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125560 }
125561 if( *p2==POS_COLUMN ){
125562 p2++;
125563 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125564 }
125565
125566 while( 1 ){
125567 if( iCol1==iCol2 ){
125568 char *pSave = p;
@@ -125608,13 +125721,13 @@
125608 fts3ColumnlistCopy(0, &p2);
125609 assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
125610 if( 0==*p1 || 0==*p2 ) break;
125611
125612 p1++;
125613 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125614 p2++;
125615 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125616 }
125617
125618 /* Advance pointer p1 or p2 (whichever corresponds to the smaller of
125619 ** iCol1 and iCol2) so that it points to either the 0x00 that marks the
125620 ** end of the position list, or the 0x01 that precedes the next
@@ -125622,16 +125735,16 @@
125622 */
125623 else if( iCol1<iCol2 ){
125624 fts3ColumnlistCopy(0, &p1);
125625 if( 0==*p1 ) break;
125626 p1++;
125627 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
125628 }else{
125629 fts3ColumnlistCopy(0, &p2);
125630 if( 0==*p2 ) break;
125631 p2++;
125632 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
125633 }
125634 }
125635
125636 fts3PoslistCopy(0, &p2);
125637 fts3PoslistCopy(0, &p1);
@@ -128794,11 +128907,11 @@
128794 */
128795 pExpr->aMI[iCol*3 + 1] += iCnt;
128796 pExpr->aMI[iCol*3 + 2] += (iCnt>0);
128797 if( *p==0x00 ) break;
128798 p++;
128799 p += sqlite3Fts3GetVarint32(p, &iCol);
128800 }
128801 }
128802
128803 fts3EvalUpdateCounts(pExpr->pLeft);
128804 fts3EvalUpdateCounts(pExpr->pRight);
@@ -129095,19 +129208,19 @@
129095 }
129096 if( pIter==0 ) return SQLITE_OK;
129097
129098 if( *pIter==0x01 ){
129099 pIter++;
129100 pIter += sqlite3Fts3GetVarint32(pIter, &iThis);
129101 }else{
129102 iThis = 0;
129103 }
129104 while( iThis<iCol ){
129105 fts3ColumnlistCopy(0, &pIter);
129106 if( *pIter==0x00 ) return 0;
129107 pIter++;
129108 pIter += sqlite3Fts3GetVarint32(pIter, &iThis);
129109 }
129110
129111 *ppOut = ((iCol==iThis)?pIter:0);
129112 return SQLITE_OK;
129113 }
@@ -134552,12 +134665,12 @@
134552 rc = fts3SegReaderRequire(pReader, pNext, FTS3_VARINT_MAX*2);
134553 if( rc!=SQLITE_OK ) return rc;
134554
134555 /* Because of the FTS3_NODE_PADDING bytes of padding, the following is
134556 ** safe (no risk of overread) even if the node data is corrupted. */
134557 pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
134558 pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
134559 if( nPrefix<0 || nSuffix<=0
134560 || &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
134561 ){
134562 return FTS_CORRUPT_VTAB;
134563 }
@@ -134576,11 +134689,11 @@
134576 if( rc!=SQLITE_OK ) return rc;
134577
134578 memcpy(&pReader->zTerm[nPrefix], pNext, nSuffix);
134579 pReader->nTerm = nPrefix+nSuffix;
134580 pNext += nSuffix;
134581 pNext += sqlite3Fts3GetVarint32(pNext, &pReader->nDoclist);
134582 pReader->aDoclist = pNext;
134583 pReader->pOffsetList = 0;
134584
134585 /* Check that the doclist does not appear to extend past the end of the
134586 ** b-tree node. And that the final byte of the doclist is 0x00. If either
@@ -135737,11 +135850,11 @@
135737 pList = p;
135738 if( nList==0 ){
135739 break;
135740 }
135741 p = &pList[1];
135742 p += sqlite3Fts3GetVarint32(p, &iCurrent);
135743 }
135744
135745 if( bZero && &pList[nList]!=pEnd ){
135746 memset(&pList[nList], 0, pEnd - &pList[nList]);
135747 }
@@ -136702,21 +136815,21 @@
136702 if( p->iOff>=p->nNode ){
136703 /* EOF */
136704 p->aNode = 0;
136705 }else{
136706 if( bFirst==0 ){
136707 p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
136708 }
136709 p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
136710
136711 blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
136712 if( rc==SQLITE_OK ){
136713 memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix);
136714 p->term.n = nPrefix+nSuffix;
136715 p->iOff += nSuffix;
136716 if( p->iChild==0 ){
136717 p->iOff += sqlite3Fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
136718 p->aDoclist = &p->aNode[p->iOff];
136719 p->iOff += p->nDoclist;
136720 }
136721 }
136722 }
@@ -137764,11 +137877,11 @@
137764 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137765 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137766
137767 pHint->n = i;
137768 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
137769 i += sqlite3Fts3GetVarint32(&pHint->a[i], pnInput);
137770 if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
137771
137772 return SQLITE_OK;
137773 }
137774
@@ -138757,11 +138870,11 @@
138757 ** After it returns, *piPos contains the value of the next element of the
138758 ** list and *pp is advanced to the following varint.
138759 */
138760 static void fts3GetDeltaPosition(char **pp, int *piPos){
138761 int iVal;
138762 *pp += sqlite3Fts3GetVarint32(*pp, &iVal);
138763 *piPos += (iVal-2);
138764 }
138765
138766 /*
138767 ** Helper function for fts3ExprIterate() (see below).
138768
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.2"
139 #define SQLITE_VERSION_NUMBER 3008002
140 #define SQLITE_SOURCE_ID "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -396,11 +396,11 @@
396 ** Restrictions:
397 **
398 ** <ul>
399 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
400 ** is a valid and open [database connection].
401 ** <li> The application must not close the [database connection] specified by
402 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
403 ** <li> The application must not modify the SQL statement text passed into
404 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
405 ** </ul>
406 */
@@ -473,11 +473,11 @@
473 ** about errors. The extended result codes are enabled or disabled
474 ** on a per database connection basis using the
475 ** [sqlite3_extended_result_codes()] API.
476 **
477 ** Some of the available extended result codes are listed here.
478 ** One may expect the number of extended result codes will increase
479 ** over time. Software that uses extended result codes should expect
480 ** to see new result codes in future releases of SQLite.
481 **
482 ** The SQLITE_OK result code will never be extended. It will always
483 ** be exactly zero.
@@ -1411,11 +1411,11 @@
1411 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1412 ** Every memory allocation request coming in through [sqlite3_malloc()]
1413 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1414 ** that causes the corresponding memory allocation to fail.
1415 **
1416 ** The xInit method initializes the memory allocator. For example,
1417 ** it might allocate any require mutexes or initialize internal data
1418 ** structures. The xShutdown method is invoked (indirectly) by
1419 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1420 ** by xInit. The pAppData pointer is used as the only parameter to
1421 ** xInit and xShutdown.
@@ -3137,11 +3137,10 @@
3137 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3138 ** ^The specific value of WHERE-clause [parameter] might influence the
3139 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3140 ** or [GLOB] operator or if the parameter is compared to an indexed column
3141 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
 
3142 ** </li>
3143 ** </ol>
3144 */
3145 SQLITE_API int sqlite3_prepare(
3146 sqlite3 *db, /* Database handle */
@@ -3867,11 +3866,11 @@
3866 **
3867 ** ^The pointers returned are valid until a type conversion occurs as
3868 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3869 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3870 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3871 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3872 ** [sqlite3_free()].
3873 **
3874 ** ^(If a memory allocation error occurs during the evaluation of any
3875 ** of these routines, a default value is returned. The default value
3876 ** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4945,12 +4944,12 @@
4944 /*
4945 ** CAPI3REF: Free Memory Used By A Database Connection
4946 **
4947 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
4948 ** memory as possible from database connection D. Unlike the
4949 ** [sqlite3_release_memory()] interface, this interface is in effect even
4950 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4951 ** omitted.
4952 **
4953 ** See also: [sqlite3_release_memory()]
4954 */
4955 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
@@ -9096,22 +9095,22 @@
9095 #define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9096 #define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9097 #define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9098 #define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9099 #define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9100 #define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9101 #define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9102 #define OP_RowKey 82 /* synopsis: r[P2]=key */
9103 #define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9104 #define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9105 #define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9106 #define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9107 #define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
9108 #define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9109 #define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9110 #define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9111 #define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9112 #define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9113 #define OP_RowData 93 /* synopsis: r[P2]=data */
9114 #define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9115 #define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
9116 #define OP_Rowid 96 /* synopsis: r[P2]=rowid */
@@ -9237,11 +9236,10 @@
9236 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
9237 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
9238 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
9239 #ifdef SQLITE_DEBUG
9240 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
 
9241 #endif
9242 SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
9243 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
9244 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
9245 SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
@@ -10304,10 +10302,11 @@
10302 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
10303 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
10304 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
10305 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
10306 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
10307 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
10308
10309
10310 /*
10311 ** Bits of the sqlite3.dbOptFlags field that are used by the
10312 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -11089,11 +11088,11 @@
11088 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
11089 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
11090 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
11091 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
11092 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
11093 /* unused 0x000200 */
11094 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
11095 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
11096 #define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
11097 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
11098 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
@@ -11160,12 +11159,17 @@
11159 char *zName; /* Token associated with this expression */
11160 char *zSpan; /* Original text of the expression */
11161 u8 sortOrder; /* 1 for DESC or 0 for ASC */
11162 unsigned done :1; /* A flag to indicate when processing is finished */
11163 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11164 union {
11165 struct {
11166 u16 iOrderByCol; /* For ORDER BY, column number in result set */
11167 u16 iAlias; /* Index into Parse.aAlias[] for zName */
11168 } x;
11169 int iConstExprReg; /* Register in which Expr value is cached */
11170 } u;
11171 } *a; /* Alloc a power of two greater or equal to nExpr */
11172 };
11173
11174 /*
11175 ** An instance of this structure is used by the parser to record both
@@ -11538,10 +11542,11 @@
11542 u8 tempReg; /* iReg is a temp register that needs to be freed */
11543 int iLevel; /* Nesting level */
11544 int iReg; /* Reg with value of this column. 0 means none. */
11545 int lru; /* Least recently used entry has the smallest value */
11546 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
11547 ExprList *pConstExpr;/* Constant expressions */
11548 yDbMask writeMask; /* Start a write transaction on these databases */
11549 yDbMask cookieMask; /* Bitmask of schema verified databases */
11550 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
11551 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
11552 int regRowid; /* Register holding rowid of CREATE TABLE entry */
@@ -12151,11 +12156,10 @@
12156 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12157 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
12158 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12159 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12160 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
 
12161 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
12162 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12163 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
12164 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
12165 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
@@ -12197,11 +12201,11 @@
12201 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12202 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*);
12203 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
12204 u8,u8,int,int*);
12205 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
12206 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, u8*, int*, int*);
12207 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
12208 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
12209 SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
12210 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8);
12211 SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*);
@@ -12519,10 +12523,11 @@
12523 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
12524 SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
12525 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
12526 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
12527 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
12528 SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
12529 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
12530 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
12531 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
12532 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
12533 SQLITE_PRIVATE const char *sqlite3JournalModename(int);
@@ -13700,13 +13705,10 @@
13705 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13706 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
13707 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
13708 char *zSql; /* Text of the SQL statement that generated this */
13709 void *pFree; /* Free this when deleting the vdbe */
 
 
 
13710 #ifdef SQLITE_ENABLE_TREE_EXPLAIN
13711 Explain *pExplain; /* The explainer */
13712 char *zExplain; /* Explanation of data structures */
13713 #endif
13714 VdbeFrame *pFrame; /* Parent frame */
@@ -15796,20 +15798,10 @@
15798 ** This version of the memory allocator is the default. It is
15799 ** used when no other memory allocator is specified using compile-time
15800 ** macros.
15801 */
15802 #ifdef SQLITE_SYSTEM_MALLOC
 
 
 
 
 
 
 
 
 
 
15803 #if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
15804
15805 /*
15806 ** Use the zone allocator available on apple products unless the
15807 ** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
@@ -15828,25 +15820,51 @@
15820
15821 /*
15822 ** Use standard C library malloc and free on non-Apple systems.
15823 ** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
15824 */
15825 #define SQLITE_MALLOC(x) malloc(x)
15826 #define SQLITE_FREE(x) free(x)
15827 #define SQLITE_REALLOC(x,y) realloc((x),(y))
15828
15829 /*
15830 ** The malloc.h header file is needed for malloc_usable_size() function
15831 ** on some systems (e.g. Linux).
15832 */
15833 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE)
15834 # define SQLITE_USE_MALLOC_H
15835 # define SQLITE_USE_MALLOC_USABLE_SIZE
15836 /*
15837 ** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
15838 ** use of _msize() is automatic, but can be disabled by compiling with
15839 ** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
15840 ** the malloc.h header file.
15841 */
15842 #elif defined(_MSC_VER) && !defined(SQLITE_WITHOUT_MSIZE)
15843 # define SQLITE_USE_MALLOC_H
15844 # define SQLITE_USE_MSIZE
15845 #endif
15846
15847 /*
15848 ** Include the malloc.h header file, if necessary. Also set define macro
15849 ** SQLITE_MALLOCSIZE to the appropriate function name, which is _msize()
15850 ** for MSVC and malloc_usable_size() for most other systems (e.g. Linux).
15851 ** The memory size function can always be overridden manually by defining
15852 ** the macro SQLITE_MALLOCSIZE to the desired function name.
15853 */
15854 #if defined(SQLITE_USE_MALLOC_H)
15855 # include <malloc.h>
15856 # if defined(SQLITE_USE_MALLOC_USABLE_SIZE)
15857 # if !defined(SQLITE_MALLOCSIZE)
15858 # define SQLITE_MALLOCSIZE(x) malloc_usable_size(x)
15859 # endif
15860 # elif defined(SQLITE_USE_MSIZE)
15861 # if !defined(SQLITE_MALLOCSIZE)
15862 # define SQLITE_MALLOCSIZE _msize
15863 # endif
15864 # endif
15865 #endif /* defined(SQLITE_USE_MALLOC_H) */
15866
15867 #endif /* __APPLE__ or not __APPLE__ */
15868
15869 /*
15870 ** Like malloc(), but remember the size of the allocation
@@ -22957,22 +22975,22 @@
22975 /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
22976 /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
22977 /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
22978 /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
22979 /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
22980 /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
22981 /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
22982 /* 82 */ "RowKey" OpHelp("r[P2]=key"),
22983 /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
22984 /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
22985 /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
22986 /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
22987 /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
22988 /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
22989 /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
22990 /* 90 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
22991 /* 91 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
22992 /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
22993 /* 93 */ "RowData" OpHelp("r[P2]=data"),
22994 /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
22995 /* 95 */ "String8" OpHelp("r[P2]='P4'"),
22996 /* 96 */ "Rowid" OpHelp("r[P2]=rowid"),
@@ -58853,10 +58871,11 @@
58871 if( sqlite3OpenTempDatabase(pParse) ){
58872 sqlite3Error(pErrorDb, pParse->rc, "%s", pParse->zErrMsg);
58873 rc = SQLITE_ERROR;
58874 }
58875 sqlite3DbFree(pErrorDb, pParse->zErrMsg);
58876 sqlite3ParserReset(pParse);
58877 sqlite3StackFree(pErrorDb, pParse);
58878 }
58879 if( rc ){
58880 return 0;
58881 }
@@ -60997,19 +61016,10 @@
61016 pA->zSql = pB->zSql;
61017 pB->zSql = zTmp;
61018 pB->isPrepareV2 = pA->isPrepareV2;
61019 }
61020
 
 
 
 
 
 
 
 
 
61021 /*
61022 ** Resize the Vdbe.aOp array so that it is at least one op larger than
61023 ** it was.
61024 **
61025 ** If an out-of-memory error occurs while resizing the array, return
@@ -61901,11 +61911,11 @@
61911 assert( i<nTemp );
61912 break;
61913 }
61914 case P4_COLLSEQ: {
61915 CollSeq *pColl = pOp->p4.pColl;
61916 sqlite3_snprintf(nTemp, zTemp, "(%.20s)", pColl->zName);
61917 break;
61918 }
61919 case P4_FUNCDEF: {
61920 FuncDef *pDef = pOp->p4.pFunc;
61921 sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
@@ -62334,19 +62344,21 @@
62344 #ifdef SQLITE_DEBUG
62345 /*
62346 ** Print the SQL that was used to generate a VDBE program.
62347 */
62348 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe *p){
62349 const char *z = 0;
62350 if( p->zSql ){
62351 z = p->zSql;
62352 }else if( p->nOp>=1 ){
62353 const VdbeOp *pOp = &p->aOp[0];
62354 if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62355 z = pOp->p4.z;
62356 while( sqlite3Isspace(*z) ) z++;
62357 }
62358 }
62359 if( z ) printf("SQL: [%s]\n", z);
62360 }
62361 #endif
62362
62363 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
62364 /*
@@ -63892,19 +63904,16 @@
63904 pMem->u.i = serial_type-8;
63905 pMem->flags = MEM_Int;
63906 return 0;
63907 }
63908 default: {
63909 static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
63910 u32 len = (serial_type-12)/2;
63911 pMem->z = (char *)buf;
63912 pMem->n = len;
63913 pMem->xDel = 0;
63914 pMem->flags = aFlag[serial_type&1];
 
 
 
 
63915 return len;
63916 }
63917 }
63918 return 0;
63919 }
@@ -66350,41 +66359,40 @@
66359
66360 #ifdef SQLITE_DEBUG
66361 /*
66362 ** Print the value of a register for tracing purposes:
66363 */
66364 static void memTracePrint(Mem *p){
66365 if( p->flags & MEM_Invalid ){
66366 printf(" undefined");
66367 }else if( p->flags & MEM_Null ){
66368 printf(" NULL");
66369 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66370 printf(" si:%lld", p->u.i);
66371 }else if( p->flags & MEM_Int ){
66372 printf(" i:%lld", p->u.i);
66373 #ifndef SQLITE_OMIT_FLOATING_POINT
66374 }else if( p->flags & MEM_Real ){
66375 printf(" r:%g", p->r);
66376 #endif
66377 }else if( p->flags & MEM_RowSet ){
66378 printf(" (rowset)");
66379 }else{
66380 char zBuf[200];
66381 sqlite3VdbeMemPrettyPrint(p, zBuf);
66382 printf(" %s", zBuf);
 
66383 }
66384 }
66385 static void registerTrace(int iReg, Mem *p){
66386 printf("REG[%d] = ", iReg);
66387 memTracePrint(p);
66388 printf("\n");
66389 }
66390 #endif
66391
66392 #ifdef SQLITE_DEBUG
66393 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
66394 #else
66395 # define REGISTER_TRACE(R,M)
66396 #endif
66397
66398
@@ -67035,17 +67043,32 @@
67043 }
67044 }
67045 #endif
67046 #ifdef SQLITE_DEBUG
67047 sqlite3BeginBenignMalloc();
67048 if( p->pc==0
67049 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
67050 ){
67051 int i;
67052 int once = 1;
67053 sqlite3VdbePrintSql(p);
67054 if( p->db->flags & SQLITE_VdbeListing ){
67055 printf("VDBE Program Listing:\n");
67056 for(i=0; i<p->nOp; i++){
67057 sqlite3VdbePrintOp(stdout, i, &aOp[i]);
67058 }
67059 }
67060 if( p->db->flags & SQLITE_VdbeEQP ){
67061 for(i=0; i<p->nOp; i++){
67062 if( aOp[i].opcode==OP_Explain ){
67063 if( once ) printf("VDBE Query Plan:\n");
67064 printf("%s\n", aOp[i].p4.z);
67065 once = 0;
67066 }
67067 }
67068 }
67069 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
67070 }
67071 sqlite3EndBenignMalloc();
67072 #endif
67073 for(pc=p->pc; rc==SQLITE_OK; pc++){
67074 assert( pc>=0 && pc<p->nOp );
@@ -67058,16 +67081,12 @@
67081 pOp = &aOp[pc];
67082
67083 /* Only allow tracing if SQLITE_DEBUG is defined.
67084 */
67085 #ifdef SQLITE_DEBUG
67086 if( db->flags & SQLITE_VdbeTrace ){
67087 sqlite3VdbePrintOp(stdout, pc, pOp);
 
 
 
 
67088 }
67089 #endif
67090
67091
67092 /* Check to see if we need to simulate an interrupt. This only happens
@@ -67194,19 +67213,16 @@
67213 ** sqlite3VdbeExec() or since last time the progress callback was called).
67214 ** If the progress callback returns non-zero, exit the virtual machine with
67215 ** a return code SQLITE_ABORT.
67216 */
67217 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
67218 assert( db->nProgressOps!=0 );
67219 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
67220 if( db->xProgress(db->pProgressArg) ){
67221 rc = SQLITE_INTERRUPT;
67222 goto vdbe_error_halt;
67223 }
 
 
 
67224 }
67225 #endif
67226
67227 break;
67228 }
@@ -67638,10 +67654,22 @@
67654 int i;
67655 #endif /* local variables moved into u.ag */
67656 assert( p->nResColumn==pOp->p2 );
67657 assert( pOp->p1>0 );
67658 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67659
67660 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67661 /* Run the progress counter just before returning.
67662 */
67663 if( db->xProgress!=0
67664 && nVmStep>=nProgressLimit
67665 && db->xProgress(db->pProgressArg)!=0
67666 ){
67667 rc = SQLITE_INTERRUPT;
67668 goto vdbe_error_halt;
67669 }
67670 #endif
67671
67672 /* If this statement has violated immediate foreign key constraints, do
67673 ** not return the number of rows modified. And do not RELEASE the statement
67674 ** transaction. It needs to be rolled back. */
67675 if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
@@ -67768,23 +67796,23 @@
67796 ** Subtract the value in register P1 from the value in register P2
67797 ** and store the result in register P3.
67798 ** If either input is NULL, the result is NULL.
67799 */
67800 /* Opcode: Divide P1 P2 P3 * *
67801 ** Synopsis: r[P3]=r[P2]/r[P1]
67802 **
67803 ** Divide the value in register P1 by the value in register P2
67804 ** and store the result in register P3 (P3=P2/P1). If the value in
67805 ** register P1 is zero, then the result is NULL. If either input is
67806 ** NULL, the result is NULL.
67807 */
67808 /* Opcode: Remainder P1 P2 P3 * *
67809 ** Synopsis: r[P3]=r[P2]%r[P1]
67810 **
67811 ** Compute the remainder after integer register P2 is divided by
67812 ** register P1 and store the result in register P3.
67813 ** If the value in register P1 is zero the result is NULL.
67814 ** If either operand is NULL, the result is NULL.
67815 */
67816 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67817 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67818 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
@@ -68249,11 +68277,11 @@
68277 break;
68278 }
68279 #endif /* !defined(SQLITE_OMIT_CAST) && !defined(SQLITE_OMIT_FLOATING_POINT) */
68280
68281 /* Opcode: Lt P1 P2 P3 P4 P5
68282 ** Synopsis: if r[P1]<r[P3] goto P2
68283 **
68284 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
68285 ** jump to address P2.
68286 **
68287 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
@@ -72846,17 +72874,17 @@
72874 */
72875 #ifndef NDEBUG
72876 assert( pc>=-1 && pc<p->nOp );
72877
72878 #ifdef SQLITE_DEBUG
72879 if( db->flags & SQLITE_VdbeTrace ){
72880 if( rc!=0 ) printf("rc=%d\n",rc);
72881 if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
72882 registerTrace(pOp->p2, &aMem[pOp->p2]);
72883 }
72884 if( pOp->opflags & OPFLG_OUT3 ){
72885 registerTrace(pOp->p3, &aMem[pOp->p3]);
72886 }
72887 }
72888 #endif /* SQLITE_DEBUG */
72889 #endif /* NDEBUG */
72890 } /* The end of the for(;;) loop the loops through opcodes */
@@ -73253,10 +73281,11 @@
73281 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
73282 sqlite3DbFree(db, pBlob);
73283 }
73284 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
73285 sqlite3DbFree(db, zErr);
73286 sqlite3ParserReset(pParse);
73287 sqlite3StackFree(db, pParse);
73288 rc = sqlite3ApiExit(db, rc);
73289 sqlite3_mutex_leave(db->mutex);
73290 return rc;
73291 }
@@ -75218,14 +75247,14 @@
75247 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
75248 incrAggFunctionDepth(pDup, nSubquery);
75249 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
75250 if( pDup==0 ) return;
75251 ExprSetProperty(pDup, EP_Skip);
75252 if( pEList->a[iCol].u.x.iAlias==0 ){
75253 pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
75254 }
75255 pDup->iTable = pEList->a[iCol].u.x.iAlias;
75256 }
75257 if( pExpr->op==TK_COLLATE ){
75258 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
75259 }
75260
@@ -76086,11 +76115,11 @@
76115 assert( pItem->pExpr->op==TK_COLLATE );
76116 assert( pItem->pExpr->pLeft==pE );
76117 pItem->pExpr->pLeft = pNew;
76118 }
76119 sqlite3ExprDelete(db, pE);
76120 pItem->u.x.iOrderByCol = (u16)iCol;
76121 pItem->done = 1;
76122 }else{
76123 moreToDo = 1;
76124 }
76125 }
@@ -76107,12 +76136,12 @@
76136 }
76137
76138 /*
76139 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
76140 ** the SELECT statement pSelect. If any term is reference to a
76141 ** result set expression (as determined by the ExprList.a.u.x.iOrderByCol
76142 ** field) then convert that term into a copy of the corresponding result set
76143 ** column.
76144 **
76145 ** If any errors are detected, add an error message to pParse and
76146 ** return non-zero. Return zero if no errors are seen.
76147 */
@@ -76135,16 +76164,16 @@
76164 }
76165 #endif
76166 pEList = pSelect->pEList;
76167 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
76168 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
76169 if( pItem->u.x.iOrderByCol ){
76170 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
76171 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
76172 return 1;
76173 }
76174 resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, zType,0);
76175 }
76176 }
76177 return 0;
76178 }
76179
@@ -76189,11 +76218,11 @@
76218 if( iCol>0 ){
76219 /* If an AS-name match is found, mark this ORDER BY column as being
76220 ** a copy of the iCol-th result-set column. The subsequent call to
76221 ** sqlite3ResolveOrderGroupBy() will convert the expression to a
76222 ** copy of the iCol-th result-set expression. */
76223 pItem->u.x.iOrderByCol = (u16)iCol;
76224 continue;
76225 }
76226 }
76227 if( sqlite3ExprIsInteger(pE2, &iCol) ){
76228 /* The ORDER BY term is an integer constant. Again, set the column
@@ -76201,22 +76230,22 @@
76230 ** order-by term to a copy of the result-set expression */
76231 if( iCol<1 || iCol>0xffff ){
76232 resolveOutOfRangeError(pParse, zType, i+1, nResult);
76233 return 1;
76234 }
76235 pItem->u.x.iOrderByCol = (u16)iCol;
76236 continue;
76237 }
76238
76239 /* Otherwise, treat the ORDER BY term as an ordinary expression */
76240 pItem->u.x.iOrderByCol = 0;
76241 if( sqlite3ResolveExprNames(pNC, pE) ){
76242 return 1;
76243 }
76244 for(j=0; j<pSelect->pEList->nExpr; j++){
76245 if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
76246 pItem->u.x.iOrderByCol = j+1;
76247 }
76248 }
76249 }
76250 return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
76251 }
@@ -77491,12 +77520,11 @@
77520 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
77521 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
77522 pItem->sortOrder = pOldItem->sortOrder;
77523 pItem->done = 0;
77524 pItem->bSpanIsTab = pOldItem->bSpanIsTab;
77525 pItem->u = pOldItem->u;
 
77526 }
77527 return pNew;
77528 }
77529
77530 /*
@@ -78917,10 +78945,11 @@
78945 int inReg = target; /* Results stored in register inReg */
78946 int regFree1 = 0; /* If non-zero free this temporary register */
78947 int regFree2 = 0; /* If non-zero free this temporary register */
78948 int r1, r2, r3, r4; /* Various register numbers */
78949 sqlite3 *db = pParse->db; /* The database connection */
78950 Expr tempX; /* Temporary expression node */
78951
78952 assert( target>0 && target<=pParse->nMem );
78953 if( v==0 ){
78954 assert( pParse->db->mallocFailed );
78955 return 0;
@@ -79136,12 +79165,14 @@
79165 }else if( pLeft->op==TK_FLOAT ){
79166 assert( !ExprHasProperty(pExpr, EP_IntValue) );
79167 codeReal(v, pLeft->u.zToken, 1, target);
79168 #endif
79169 }else{
79170 tempX.op = TK_INTEGER;
79171 tempX.flags = EP_IntValue|EP_TokenOnly;
79172 tempX.u.iValue = 0;
79173 r1 = sqlite3ExprCodeTemp(pParse, &tempX, &regFree1);
79174 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree2);
79175 sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target);
79176 testcase( regFree2==0 );
79177 }
79178 inReg = target;
@@ -79453,11 +79484,10 @@
79484 int nExpr; /* 2x number of WHEN terms */
79485 int i; /* Loop counter */
79486 ExprList *pEList; /* List of WHEN terms */
79487 struct ExprList_item *aListelem; /* Array of WHEN terms */
79488 Expr opCompare; /* The X==Ei expression */
 
79489 Expr *pX; /* The X expression */
79490 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
79491 VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
79492
79493 assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
@@ -79465,17 +79495,16 @@
79495 pEList = pExpr->x.pList;
79496 aListelem = pEList->a;
79497 nExpr = pEList->nExpr;
79498 endLabel = sqlite3VdbeMakeLabel(v);
79499 if( (pX = pExpr->pLeft)!=0 ){
79500 tempX = *pX;
79501 testcase( pX->op==TK_COLUMN );
79502 exprToRegister(&tempX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
 
79503 testcase( regFree1==0 );
79504 opCompare.op = TK_EQ;
79505 opCompare.pLeft = &tempX;
79506 pTest = &opCompare;
79507 /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
79508 ** The value in regFree1 might get SCopy-ed into the file result.
79509 ** So make sure that the regFree1 register is not reused for other
79510 ** purposes and possibly overwritten. */
@@ -79491,11 +79520,10 @@
79520 }
79521 nextCase = sqlite3VdbeMakeLabel(v);
79522 testcase( pTest->op==TK_COLUMN );
79523 sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
79524 testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
 
79525 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
79526 sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
79527 sqlite3ExprCachePop(pParse, 1);
79528 sqlite3VdbeResolveLabel(v, nextCase);
79529 }
@@ -79550,19 +79578,45 @@
79578 ** are stored.
79579 **
79580 ** If the register is a temporary register that can be deallocated,
79581 ** then write its number into *pReg. If the result register is not
79582 ** a temporary, then set *pReg to zero.
79583 **
79584 ** If pExpr is a constant, then this routine might generate this
79585 ** code to fill the register in the initialization section of the
79586 ** VDBE program, in order to factor it out of the evaluation loop.
79587 */
79588 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79589 int r2;
79590 pExpr = sqlite3ExprSkipCollate(pExpr);
79591 if( pParse->cookieGoto>0
79592 && pExpr->op!=TK_REGISTER
79593 && sqlite3ExprIsConstantNotJoin(pExpr)
79594 ){
79595 ExprList *p = pParse->pConstExpr;
79596 int i;
79597 *pReg = 0;
79598 if( p ){
79599 for(i=0; i<p->nExpr; i++){
79600 if( sqlite3ExprCompare(p->a[i].pExpr, pExpr, -1)==0 ){
79601 return p->a[i].u.iConstExprReg;
79602 }
79603 }
79604 }
79605 p = sqlite3ExprListAppend(pParse, p, sqlite3ExprDup(pParse->db, pExpr, 0));
79606 pParse->pConstExpr = p;
79607 r2 = ++pParse->nMem;
79608 if( p ) p->a[p->nExpr-1].u.iConstExprReg = r2;
79609 }else{
79610 int r1 = sqlite3GetTempReg(pParse);
79611 r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79612 if( r2==r1 ){
79613 *pReg = r1;
79614 }else{
79615 sqlite3ReleaseTempReg(pParse, r1);
79616 *pReg = 0;
79617 }
79618 }
79619 return r2;
79620 }
79621
79622 /*
@@ -79601,16 +79655,17 @@
79655 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79656 Vdbe *v = pParse->pVdbe;
79657 int inReg;
79658 inReg = sqlite3ExprCode(pParse, pExpr, target);
79659 assert( target>0 );
79660 /* The only place, other than this routine, where expressions can be
79661 ** converted to TK_REGISTER is internal subexpressions in BETWEEN and
79662 ** CASE operators. Neither ever calls this routine. And this routine
79663 ** is never called twice on the same expression. Hence it is impossible
79664 ** for the input to this routine to already be a register. Nevertheless,
79665 ** it seems prudent to keep the ALWAYS() in case the conditions above
79666 ** change with future modifications or enhancements. */
79667 if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79668 int iMem;
79669 iMem = ++pParse->nMem;
79670 sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79671 exprToRegister(pExpr, iMem);
@@ -79888,144 +79943,10 @@
79943 }
79944 sqlite3ExplainPop(pOut);
79945 }
79946 }
79947 #endif /* SQLITE_DEBUG */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79948
79949 /*
79950 ** Generate code that pushes the value of every element of the given
79951 ** expression list into a sequence of registers beginning at target.
79952 **
@@ -80400,44 +80321,46 @@
80321 ** this routine is used, it does not hurt to get an extra 2 - that
80322 ** just might result in some slightly slower code. But returning
80323 ** an incorrect 0 or 1 could lead to a malfunction.
80324 */
80325 SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
80326 u32 combinedFlags;
80327 if( pA==0 || pB==0 ){
80328 return pB==pA ? 0 : 2;
80329 }
80330 combinedFlags = pA->flags | pB->flags;
80331 if( combinedFlags & EP_IntValue ){
80332 if( (pA->flags&pB->flags&EP_IntValue)!=0 && pA->u.iValue==pB->u.iValue ){
80333 return 0;
80334 }
80335 return 2;
80336 }
80337 if( pA->op!=pB->op ){
 
80338 if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB, iTab)<2 ){
80339 return 1;
80340 }
80341 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
80342 return 1;
80343 }
80344 return 2;
80345 }
80346 if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
 
 
 
 
 
 
 
 
 
 
 
 
80347 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
80348 return pA->op==TK_COLLATE ? 1 : 2;
80349 }
80350 }
80351 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
80352 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
80353 if( combinedFlags & EP_xIsSelect ) return 2;
80354 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
80355 if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2;
80356 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
80357 if( ALWAYS((combinedFlags & EP_Reduced)==0) ){
80358 if( pA->iColumn!=pB->iColumn ) return 2;
80359 if( pA->iTable!=pB->iTable
80360 && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
80361 }
80362 }
80363 return 0;
80364 }
80365
80366 /*
@@ -83090,14 +83013,16 @@
83013 }
83014 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
83015 if( pTable==0 ){
83016 return 0;
83017 }
83018 if( argv[1]==0 ){
 
 
83019 pIndex = 0;
83020 }else if( sqlite3_stricmp(argv[0],argv[1])==0 ){
83021 pIndex = sqlite3PrimaryKeyIndex(pTable);
83022 }else{
83023 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
83024 }
83025 z = argv[2];
83026
83027 if( pIndex ){
83028 decodeIntArray((char*)z, pIndex->nKeyCol+1, pIndex->aiRowEst, pIndex);
@@ -84408,11 +84333,11 @@
84333 ** transaction on each used database and to verify the schema cookie
84334 ** on each used database.
84335 */
84336 if( pParse->cookieGoto>0 ){
84337 yDbMask mask;
84338 int iDb, i, addr;
84339 sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
84340 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
84341 if( (mask & pParse->cookieMask)==0 ) continue;
84342 sqlite3VdbeUsesBtree(v, iDb);
84343 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
@@ -84422,18 +84347,15 @@
84347 iDb, pParse->cookieValue[iDb],
84348 db->aDb[iDb].pSchema->iGeneration);
84349 }
84350 }
84351 #ifndef SQLITE_OMIT_VIRTUALTABLE
84352 for(i=0; i<pParse->nVtabLock; i++){
84353 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84354 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
84355 }
84356 pParse->nVtabLock = 0;
 
 
 
84357 #endif
84358
84359 /* Once all the cookies have been verified and transactions opened,
84360 ** obtain the required table-locks. This is a no-op unless the
84361 ** shared-cache feature is enabled.
@@ -84441,24 +84363,30 @@
84363 codeTableLocks(pParse);
84364
84365 /* Initialize any AUTOINCREMENT data structures required.
84366 */
84367 sqlite3AutoincrementBegin(pParse);
84368
84369 /* Code constant expressions that where factored out of inner loops */
84370 addr = pParse->cookieGoto;
84371 if( pParse->pConstExpr ){
84372 ExprList *pEL = pParse->pConstExpr;
84373 pParse->cookieGoto = 0;
84374 for(i=0; i<pEL->nExpr; i++){
84375 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
84376 }
84377 }
84378
84379 /* Finally, jump back to the beginning of the executable code. */
84380 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
84381 }
84382 }
84383
84384
84385 /* Get the VDBE program ready for execution
84386 */
84387 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
 
 
 
 
84388 assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */
84389 /* A minimum of one cursor is required if autoincrement is used
84390 * See ticket [a696379c1f08866] */
84391 if( pParse->pAinc!=0 && pParse->nTab==0 ) pParse->nTab = 1;
84392 sqlite3VdbeMakeReady(v, pParse);
@@ -89162,24 +89090,38 @@
89090 Expr *pWhere /* The WHERE clause. May be null */
89091 ){
89092 Vdbe *v; /* The virtual database engine */
89093 Table *pTab; /* The table from which records will be deleted */
89094 const char *zDb; /* Name of database holding pTab */
 
89095 int i; /* Loop counter */
89096 WhereInfo *pWInfo; /* Information about the WHERE clause */
89097 Index *pIdx; /* For looping over indices of the table */
89098 int iTabCur; /* Cursor number for the table */
89099 int iDataCur; /* VDBE cursor for the canonical data source */
89100 int iIdxCur; /* Cursor number of the first index */
89101 int nIdx; /* Number of indices */
89102 sqlite3 *db; /* Main database structure */
89103 AuthContext sContext; /* Authorization context */
89104 NameContext sNC; /* Name context to resolve expressions in */
89105 int iDb; /* Database number */
89106 int memCnt = -1; /* Memory cell used for change counting */
89107 int rcauth; /* Value returned by authorization callback */
89108 int okOnePass; /* True for one-pass algorithm without the FIFO */
89109 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
89110 u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
89111 Index *pPk; /* The PRIMARY KEY index on the table */
89112 int iPk; /* First of nPk registers holding PRIMARY KEY value */
89113 i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
89114 int iKey; /* Memory cell holding key of row to be deleted */
89115 i16 nKey; /* Number of memory cells in the row key */
89116 int iEphCur = 0; /* Ephemeral table holding all primary key values */
89117 int iRowSet = 0; /* Register for rowset of rows to delete */
89118 int addrBypass = 0; /* Address of jump over the delete logic */
89119 int addrLoop = 0; /* Top of the delete loop */
89120 int addrDelete = 0; /* Jump directly to the delete logic */
89121 int addrEphOpen = 0; /* Instruction to open the Ephermeral table */
89122
89123 #ifndef SQLITE_OMIT_TRIGGER
89124 int isView; /* True if attempting to delete from a view */
89125 Trigger *pTrigger; /* List of table triggers, if required */
89126 #endif
89127
@@ -89230,15 +89172,15 @@
89172 if( rcauth==SQLITE_DENY ){
89173 goto delete_from_cleanup;
89174 }
89175 assert(!isView || pTrigger);
89176
89177 /* Assign cursor numbers to the table and all its indices.
89178 */
89179 assert( pTabList->nSrc==1 );
89180 iTabCur = pTabList->a[0].iCursor = pParse->nTab++;
89181 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
89182 pParse->nTab++;
89183 }
89184
89185 /* Start the view context
89186 */
@@ -89300,132 +89242,162 @@
89242 assert( pIdx->pSchema==pTab->pSchema );
89243 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
89244 }
89245 }else
89246 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
89247 {
89248 if( HasRowid(pTab) ){
89249 /* For a rowid table, initialize the RowSet to an empty set */
89250 pPk = 0;
89251 nPk = 1;
89252 iRowSet = ++pParse->nMem;
89253 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
89254 }else{
89255 /* For a WITHOUT ROWID table, create an ephermeral table used to
89256 ** hold all primary keys for rows to be deleted. */
89257 pPk = sqlite3PrimaryKeyIndex(pTab);
89258 assert( pPk!=0 );
89259 nPk = pPk->nKeyCol;
89260 iPk = pParse->nMem+1;
89261 pParse->nMem += nPk;
89262 iEphCur = pParse->nTab++;
89263 addrEphOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEphCur, nPk);
89264 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
89265 }
89266
89267 /* Construct a query to find the rowid or primary key for every row
89268 ** to be deleted, based on the WHERE clause.
89269 */
89270 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
89271 WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK,
89272 iTabCur+1);
89273 if( pWInfo==0 ) goto delete_from_cleanup;
89274 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
89275
89276 /* Keep track of the number of rows to be deleted */
89277 if( db->flags & SQLITE_CountRows ){
89278 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
89279 }
89280
89281 /* Extract the rowid or primary key for the current row */
89282 if( pPk ){
89283 for(i=0; i<nPk; i++){
89284 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
89285 pPk->aiColumn[i], iPk+i);
89286 }
89287 iKey = iPk;
89288 }else{
89289 iKey = pParse->nMem + 1;
89290 iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0);
89291 if( iKey>pParse->nMem ) pParse->nMem = iKey;
89292 }
89293
89294 if( okOnePass ){
89295 /* For ONEPASS, no need to store the rowid/primary-key. There is only
89296 ** one, so just keep it in its register(s) and fall through to the
89297 ** delete code.
89298 */
89299 nKey = nPk; /* OP_Found will use an unpacked key */
89300 aToOpen = sqlite3DbMallocRaw(db, nIdx+2);
89301 if( aToOpen==0 ){
89302 sqlite3WhereEnd(pWInfo);
89303 goto delete_from_cleanup;
89304 }
89305 memset(aToOpen, 1, nIdx+1);
89306 aToOpen[nIdx+1] = 0;
89307 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
89308 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
89309 if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
89310 addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */
89311 }else if( pPk ){
89312 /* Construct a composite key for the row to be deleted and remember it */
89313 iKey = ++pParse->nMem;
89314 nKey = 0; /* Zero tells OP_Found to use a composite key */
89315 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89316 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89317 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
89318 }else{
89319 /* Get the rowid of the row to be deleted and remember it in the RowSet */
89320 nKey = 1; /* OP_Seek always uses a single rowid */
89321 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
89322 }
89323
89324 /* End of the WHERE loop */
89325 sqlite3WhereEnd(pWInfo);
89326 if( okOnePass ){
89327 /* Bypass the delete logic below if the WHERE loop found zero rows */
89328 addrBypass = sqlite3VdbeMakeLabel(v);
89329 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
89330 sqlite3VdbeJumpHere(v, addrDelete);
89331 }
89332
89333 /* Unless this is a view, open cursors for the table we are
89334 ** deleting from and all its indices. If this is a view, then the
89335 ** only effect this statement has is to fire the INSTEAD OF
89336 ** triggers.
89337 */
89338 if( !isView ){
89339 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen,
89340 &iDataCur, &iIdxCur);
89341 assert( pPk || iDataCur==iTabCur );
89342 assert( pPk || iIdxCur==iDataCur+1 );
89343 }
89344
89345 /* Set up a loop over the rowids/primary-keys that were found in the
89346 ** where-clause loop above.
89347 */
89348 if( okOnePass ){
89349 /* Just one row. Hence the top-of-loop is a no-op */
89350 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
89351 if( aToOpen[iDataCur-iTabCur] ){
89352 assert( pPk!=0 );
89353 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
89354 }
89355 }else if( pPk ){
89356 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
89357 sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
89358 assert( nKey==0 ); /* OP_Found will use a composite key */
89359 }else{
89360 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
89361 assert( nKey==1 );
89362 }
89363
89364 /* Delete the row */
89365 #ifndef SQLITE_OMIT_VIRTUALTABLE
89366 if( IsVirtual(pTab) ){
89367 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
89368 sqlite3VtabMakeWritable(pParse, pTab);
89369 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iKey, pVTab, P4_VTAB);
89370 sqlite3VdbeChangeP5(v, OE_Abort);
89371 sqlite3MayAbort(pParse);
89372 }else
89373 #endif
89374 {
89375 int count = (pParse->nested==0); /* True to count changes */
89376 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
89377 iKey, nKey, count, OE_Default, okOnePass);
89378 }
89379
89380 /* End of the loop over all rowids/primary-keys. */
89381 if( okOnePass ){
89382 sqlite3VdbeResolveLabel(v, addrBypass);
89383 }else if( pPk ){
89384 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
89385 sqlite3VdbeJumpHere(v, addrLoop);
89386 }else{
89387 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
89388 sqlite3VdbeJumpHere(v, addrLoop);
89389 }
89390
89391 /* Close the cursors open on the table and its indexes. */
89392 if( !isView && !IsVirtual(pTab) ){
89393 if( !pPk ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
89394 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
89395 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
89396 }
89397 }
89398 } /* End non-truncate path */
89399
89400 /* Update the sqlite_sequence table by storing the content of the
89401 ** maximum rowid counter values recorded while inserting into
89402 ** autoincrement tables.
89403 */
@@ -89445,10 +89417,11 @@
89417
89418 delete_from_cleanup:
89419 sqlite3AuthContextPop(&sContext);
89420 sqlite3SrcListDelete(db, pTabList);
89421 sqlite3ExprDelete(db, pWhere);
89422 sqlite3DbFree(db, aToOpen);
89423 return;
89424 }
89425 /* Make sure "isView" and other macros defined above are undefined. Otherwise
89426 ** thely may interfere with compilation of other functions in this file
89427 ** (or in another file, if this file becomes part of the amalgamation). */
@@ -89511,10 +89484,11 @@
89484 /* If there are any triggers to fire, allocate a range of registers to
89485 ** use for the old.* references in the triggers. */
89486 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
89487 u32 mask; /* Mask of OLD.* columns in use */
89488 int iCol; /* Iterator used while populating OLD.* */
89489 int addrStart; /* Start of BEFORE trigger programs */
89490
89491 /* TODO: Could use temporary registers here. Also could attempt to
89492 ** avoid copying the contents of the rowid register. */
89493 mask = sqlite3TriggerColmask(
89494 pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
@@ -89531,19 +89505,23 @@
89505 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
89506 }
89507 }
89508
89509 /* Invoke BEFORE DELETE trigger programs. */
89510 addrStart = sqlite3VdbeCurrentAddr(v);
89511 sqlite3CodeRowTrigger(pParse, pTrigger,
89512 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
89513 );
89514
89515 /* If any BEFORE triggers were coded, then seek the cursor to the
89516 ** row to be deleted again. It may be that the BEFORE triggers moved
89517 ** the cursor or of already deleted the row that the cursor was
89518 ** pointing to.
89519 */
89520 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
89521 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89522 }
89523
89524 /* Do FK processing. This call checks that any FK constraints that
89525 ** refer to this table (i.e. constraints attached to other tables)
89526 ** are not violated by deleting this row. */
89527 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
@@ -91969,10 +91947,11 @@
91947 Vdbe *v = sqlite3GetVdbe(pParse);
91948
91949 assert( pIdx==0 || pIdx->pTable==pTab );
91950 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
91951 assert( pIdx!=0 || pFKey->nCol==1 );
91952 assert( pIdx!=0 || HasRowid(pTab) );
91953
91954 if( nIncr<0 ){
91955 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
91956 }
91957
@@ -92021,10 +92000,11 @@
92000 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
92001 pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
92002 }else{
92003 Expr *pEq, *pAll = 0;
92004 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
92005 assert( pIdx!=0 );
92006 for(i=0; i<pPk->nKeyCol; i++){
92007 i16 iCol = pIdx->aiColumn[i];
92008 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
92009 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
92010 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
@@ -93599,11 +93579,11 @@
93579 }
93580
93581 /* If this is not a view, open the table and and all indices */
93582 if( !isView ){
93583 int nIdx;
93584 nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1, 0,
93585 &iDataCur, &iIdxCur);
93586 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
93587 if( aRegIdx==0 ){
93588 goto insert_cleanup;
93589 }
@@ -94459,42 +94439,50 @@
94439 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
94440 Parse *pParse, /* Parsing context */
94441 Table *pTab, /* Table to be opened */
94442 int op, /* OP_OpenRead or OP_OpenWrite */
94443 int iBase, /* Use this for the table cursor, if there is one */
94444 u8 *aToOpen, /* If not NULL: boolean for each table and index */
94445 int *piDataCur, /* Write the database source cursor number here */
94446 int *piIdxCur /* Write the first index cursor number here */
94447 ){
94448 int i;
94449 int iDb;
94450 int iDataCur;
94451 Index *pIdx;
94452 Vdbe *v;
94453
94454 assert( op==OP_OpenRead || op==OP_OpenWrite );
94455 if( IsVirtual(pTab) ){
94456 assert( aToOpen==0 );
94457 *piDataCur = 0;
94458 *piIdxCur = 1;
94459 return 0;
94460 }
94461 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
94462 v = sqlite3GetVdbe(pParse);
94463 assert( v!=0 );
94464 if( iBase<0 ) iBase = pParse->nTab;
94465 iDataCur = iBase++;
94466 if( piDataCur ) *piDataCur = iDataCur;
94467 if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
94468 sqlite3OpenTable(pParse, iDataCur, iDb, pTab, op);
94469 }else{
94470 sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
94471 }
94472 if( piIdxCur ) *piIdxCur = iBase;
94473 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94474 int iIdxCur = iBase++;
94475 assert( pIdx->pSchema==pTab->pSchema );
94476 if( pIdx->autoIndex==2 && !HasRowid(pTab) && piDataCur ){
94477 *piDataCur = iIdxCur;
94478 }
94479 if( aToOpen==0 || aToOpen[i+1] ){
94480 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
94481 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
94482 VdbeComment((v, "%s", pIdx->zName));
94483 }
94484 }
94485 if( iBase>pParse->nTab ) pParse->nTab = iBase;
94486 return i;
94487 }
94488
@@ -96664,10 +96652,14 @@
96652 /* iArg: */ SQLITE_VdbeAddopTrace },
96653 { /* zName: */ "vdbe_debug",
96654 /* ePragTyp: */ PragTyp_FLAG,
96655 /* ePragFlag: */ 0,
96656 /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
96657 { /* zName: */ "vdbe_eqp",
96658 /* ePragTyp: */ PragTyp_FLAG,
96659 /* ePragFlag: */ 0,
96660 /* iArg: */ SQLITE_VdbeEQP },
96661 { /* zName: */ "vdbe_listing",
96662 /* ePragTyp: */ PragTyp_FLAG,
96663 /* ePragFlag: */ 0,
96664 /* iArg: */ SQLITE_VdbeListing },
96665 { /* zName: */ "vdbe_trace",
@@ -96691,11 +96683,11 @@
96683 /* ePragTyp: */ PragTyp_FLAG,
96684 /* ePragFlag: */ 0,
96685 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
96686 #endif
96687 };
96688 /* Number of pragmas: 56 on by default, 69 total. */
96689 /* End of the automatically generated pragma table.
96690 ***************************************************************************/
96691
96692 /*
96693 ** Interpret the given string as a safety level. Return 0 for OFF,
@@ -98117,11 +98109,11 @@
98109 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
98110 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98111 sqlite3VdbeJumpHere(v, addr);
98112 sqlite3ExprCacheClear(pParse);
98113 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98114 1, 0, &iDataCur, &iIdxCur);
98115 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98116 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98117 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98118 }
98119 pParse->nMem = MAX(pParse->nMem, 8+j);
@@ -99052,10 +99044,17 @@
99044 }
99045 assert( i>=0 && i<db->nDb );
99046 }
99047 return i;
99048 }
99049
99050 /*
99051 ** Free all memory allocations in the pParse object
99052 */
99053 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
99054 if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
99055 }
99056
99057 /*
99058 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
99059 */
99060 static int sqlite3Prepare(
@@ -99210,10 +99209,11 @@
99209 sqlite3DbFree(db, pT);
99210 }
99211
99212 end_prepare:
99213
99214 sqlite3ParserReset(pParse);
99215 sqlite3StackFree(db, pParse);
99216 rc = sqlite3ApiExit(db, rc);
99217 assert( (rc&db->errMask)==rc );
99218 return rc;
99219 }
@@ -101776,20 +101776,20 @@
101776 */
101777 if( op!=TK_ALL ){
101778 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
101779 struct ExprList_item *pItem;
101780 for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
101781 assert( pItem->u.x.iOrderByCol>0 );
101782 if( pItem->u.x.iOrderByCol==i ) break;
101783 }
101784 if( j==nOrderBy ){
101785 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
101786 if( pNew==0 ) return SQLITE_NOMEM;
101787 pNew->flags |= EP_IntValue;
101788 pNew->u.iValue = i;
101789 pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
101790 if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
101791 }
101792 }
101793 }
101794
101795 /* Compute the comparison permutation and keyinfo that is used with
@@ -101801,12 +101801,13 @@
101801 */
101802 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
101803 if( aPermute ){
101804 struct ExprList_item *pItem;
101805 for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
101806 assert( pItem->u.x.iOrderByCol>0
101807 && pItem->u.x.iOrderByCol<=p->pEList->nExpr );
101808 aPermute[i] = pItem->u.x.iOrderByCol - 1;
101809 }
101810 pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
101811 if( pKeyMerge ){
101812 for(i=0; i<nOrderBy; i++){
101813 CollSeq *pColl;
@@ -102382,11 +102383,11 @@
102383
102384 /* Restriction 18. */
102385 if( p->pOrderBy ){
102386 int ii;
102387 for(ii=0; ii<p->pOrderBy->nExpr; ii++){
102388 if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
102389 }
102390 }
102391 }
102392
102393 /***** If we reach this point, flattening is permitted. *****/
@@ -103789,14 +103790,14 @@
103790 if( pGroupBy ){
103791 int k; /* Loop counter */
103792 struct ExprList_item *pItem; /* For looping over expression in a list */
103793
103794 for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
103795 pItem->u.x.iAlias = 0;
103796 }
103797 for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
103798 pItem->u.x.iAlias = 0;
103799 }
103800 if( p->nSelectRow>100 ) p->nSelectRow = 100;
103801 }else{
103802 p->nSelectRow = 1;
103803 }
@@ -105443,10 +105444,11 @@
105444 sqlite3VdbeDelete(v);
105445 }
105446
105447 assert( !pSubParse->pAinc && !pSubParse->pZombieTab );
105448 assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
105449 sqlite3ParserReset(pSubParse);
105450 sqlite3StackFree(db, pSubParse);
105451
105452 return pPrg;
105453 }
105454
@@ -105757,22 +105759,23 @@
105759 WhereInfo *pWInfo; /* Information about the WHERE clause */
105760 Vdbe *v; /* The virtual database engine */
105761 Index *pIdx; /* For looping over indices */
105762 Index *pPk; /* The PRIMARY KEY index for WITHOUT ROWID tables */
105763 int nIdx; /* Number of indices that need updating */
105764 int iBaseCur; /* Base cursor number */
105765 int iDataCur; /* Cursor for the canonical data btree */
105766 int iIdxCur; /* Cursor for the first index */
105767 sqlite3 *db; /* The database structure */
105768 int *aRegIdx = 0; /* One register assigned to each index to be updated */
105769 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
105770 ** an expression for the i-th column of the table.
105771 ** aXRef[i]==-1 if the i-th column is not changed. */
105772 u8 *aToOpen; /* 1 for tables and indices to be opened */
105773 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
105774 u8 chngRowid; /* Rowid changed in a normal table */
105775 u8 chngKey; /* Either chngPk or chngRowid */
105776 Expr *pRowidExpr = 0; /* Expression defining the new record number */
 
105777 AuthContext sContext; /* The authorization context */
105778 NameContext sNC; /* The name-context to resolve expressions in */
105779 int iDb; /* Database containing the table being updated */
105780 int okOnePass; /* True for one-pass algorithm without the FIFO */
105781 int hasFK; /* True if foreign key processing is required */
@@ -105832,29 +105835,37 @@
105835 goto update_cleanup;
105836 }
105837 if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
105838 goto update_cleanup;
105839 }
 
 
 
105840
105841 /* Allocate a cursors for the main database table and for all indices.
105842 ** The index cursors might not be used, but if they are used they
105843 ** need to occur right after the database cursor. So go ahead and
105844 ** allocate enough space, just in case.
105845 */
105846 pTabList->a[0].iCursor = iBaseCur = iDataCur = pParse->nTab++;
105847 iIdxCur = iDataCur+1;
105848 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
105849 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
105850 if( pIdx->autoIndex==2 && pPk!=0 ){
105851 iDataCur = pParse->nTab;
105852 pTabList->a[0].iCursor = iDataCur;
105853 }
105854 pParse->nTab++;
105855 }
105856
105857 /* Allocate space for aXRef[], aRegIdx[], and aToOpen[].
105858 ** Initialize aXRef[] and aToOpen[] to their default values.
105859 */
105860 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * (pTab->nCol+nIdx) + nIdx+2 );
105861 if( aXRef==0 ) goto update_cleanup;
105862 aRegIdx = aXRef+pTab->nCol;
105863 aToOpen = (u8*)(aRegIdx+nIdx);
105864 memset(aToOpen, 1, nIdx+1);
105865 aToOpen[nIdx+1] = 0;
105866 for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
105867
105868 /* Initialize the name-context */
105869 memset(&sNC, 0, sizeof(sNC));
105870 sNC.pParse = pParse;
105871 sNC.pSrcList = pTabList;
@@ -105909,22 +105920,22 @@
105920 }
105921 assert( (chngRowid & chngPk)==0 );
105922 assert( chngRowid==0 || chngRowid==1 );
105923 assert( chngPk==0 || chngPk==1 );
105924 chngKey = chngRowid + chngPk;
105925
105926 /* The SET expressions are not actually used inside the WHERE loop.
105927 ** So reset the colUsed mask
105928 */
105929 pTabList->a[0].colUsed = 0;
105930
105931 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
105932
105933 /* There is one entry in the aRegIdx[] array for each index on the table
105934 ** being updated. Fill in aRegIdx[] with a register number that will hold
105935 ** the key for accessing each index.
 
105936 */
 
 
 
 
105937 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
105938 int reg;
105939 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
105940 reg = ++pParse->nMem;
105941 }else{
@@ -105934,10 +105945,11 @@
105945 reg = ++pParse->nMem;
105946 break;
105947 }
105948 }
105949 }
105950 if( reg==0 ) aToOpen[j+1] = 0;
105951 aRegIdx[j] = reg;
105952 }
105953
105954 /* Begin generating code. */
105955 v = sqlite3GetVdbe(pParse);
@@ -106057,46 +106069,34 @@
106069 ** Open every index that needs updating. Note that if any
106070 ** index could potentially invoke a REPLACE conflict resolution
106071 ** action, then we need to open all indices because we might need
106072 ** to be deleting some records.
106073 */
 
 
 
 
106074 if( onError==OE_Replace ){
106075 memset(aToOpen, 1, nIdx+1);
106076 }else{
 
106077 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
106078 if( pIdx->onError==OE_Replace ){
106079 memset(aToOpen, 1, nIdx+1);
106080 break;
106081 }
106082 }
106083 }
106084 if( okOnePass ){
106085 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
106086 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
106087 }
106088 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iBaseCur, aToOpen,
106089 0, 0);
 
 
 
 
 
 
 
 
 
 
 
106090 }
106091
106092 /* Top of the update loop */
106093 if( okOnePass ){
106094 if( aToOpen[iDataCur-iBaseCur] ){
106095 assert( pPk!=0 );
106096 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
106097 }
106098 labelContinue = labelBreak;
106099 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106100 }else if( pPk ){
106101 labelContinue = sqlite3VdbeMakeLabel(v);
106102 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
@@ -106285,11 +106285,11 @@
106285 sqlite3VdbeResolveLabel(v, labelBreak);
106286
106287 /* Close all tables */
106288 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
106289 assert( aRegIdx );
106290 if( aToOpen[i+1] ){
106291 sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
106292 }
106293 }
106294 if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
106295
@@ -106312,12 +106312,11 @@
106312 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
106313 }
106314
106315 update_cleanup:
106316 sqlite3AuthContextPop(&sContext);
106317 sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
 
106318 sqlite3SrcListDelete(db, pTabList);
106319 sqlite3ExprListDelete(db, pChanges);
106320 sqlite3ExprDelete(db, pWhere);
106321 return;
106322 }
@@ -107536,10 +107535,11 @@
107535
107536 if( pParse->pVdbe ){
107537 sqlite3VdbeFinalize(pParse->pVdbe);
107538 }
107539 sqlite3DeleteTable(db, pParse->pNewTable);
107540 sqlite3ParserReset(pParse);
107541 sqlite3StackFree(db, pParse);
107542 }
107543
107544 assert( (rc&0xff)==rc );
107545 rc = sqlite3ApiExit(db, rc);
@@ -107913,11 +107913,28 @@
107913 ** generating the code that loops through a table looking for applicable
107914 ** rows. Indices are selected and used to speed the search when doing
107915 ** so is applicable. Because this module is responsible for selecting
107916 ** indices, you might also think of this module as the "query optimizer".
107917 */
107918 /************** Include whereInt.h in the middle of where.c ******************/
107919 /************** Begin file whereInt.h ****************************************/
107920 /*
107921 ** 2013-11-12
107922 **
107923 ** The author disclaims copyright to this source code. In place of
107924 ** a legal notice, here is a blessing:
107925 **
107926 ** May you do good and not evil.
107927 ** May you find forgiveness for yourself and forgive others.
107928 ** May you share freely, never taking more than you give.
107929 **
107930 *************************************************************************
107931 **
107932 ** This file contains structure and macro definitions for the query
107933 ** planner logic in "where.c". These definitions are broken out into
107934 ** a separate source file for easier editing.
107935 */
107936
107937 /*
107938 ** Trace output macros
107939 */
107940 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
@@ -107965,10 +107982,11 @@
107982 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
107983 int iTabCur; /* The VDBE cursor used to access the table */
107984 int iIdxCur; /* The VDBE cursor used to access pIdx */
107985 int addrBrk; /* Jump here to break out of the loop */
107986 int addrNxt; /* Jump here to start the next IN combination */
107987 int addrSkip; /* Jump here for next iteration of skip-scan */
107988 int addrCont; /* Jump here to continue with the next loop cycle */
107989 int addrFirst; /* First instruction of interior of the loop */
107990 int addrBody; /* Beginning of the body of this loop */
107991 u8 iFrom; /* Which entry in the FROM clause */
107992 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
@@ -108014,11 +108032,11 @@
108032 LogEst rRun; /* Cost of running each loop */
108033 LogEst nOut; /* Estimated number of output rows */
108034 union {
108035 struct { /* Information for internal btree tables */
108036 u16 nEq; /* Number of equality constraints */
108037 u16 nSkip; /* Number of initial index columns to skip */
108038 Index *pIndex; /* Index used, or NULL */
108039 } btree;
108040 struct { /* Information for virtual tables */
108041 int idxNum; /* Index number */
108042 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -108355,10 +108373,14 @@
108373 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
108374 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108375 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108376 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108377 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
108378 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
108379
108380 /************** End of whereInt.h ********************************************/
108381 /************** Continuing where we left off in where.c **********************/
108382
108383 /*
108384 ** Return the estimated number of output rows from a WHERE clause
108385 */
108386 SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
@@ -109006,13 +109028,10 @@
109028 }
109029 assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
109030
109031 pRight = pList->a[0].pExpr;
109032 op = pRight->op;
 
 
 
109033 if( op==TK_VARIABLE ){
109034 Vdbe *pReprepare = pParse->pReprepare;
109035 int iCol = pRight->iColumn;
109036 pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_NONE);
109037 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
@@ -110759,11 +110778,11 @@
110778 return iReg;
110779 }
110780
110781 /*
110782 ** Generate code that will evaluate all == and IN constraints for an
110783 ** index scan.
110784 **
110785 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
110786 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
110787 ** The index has as many as three equality constraints, but in this
110788 ** example, the third "c" value is an inequality. So only two
@@ -110774,13 +110793,19 @@
110793 ** In the example above nEq==2. But this subroutine works for any value
110794 ** of nEq including 0. If nEq==0, this routine is nearly a no-op.
110795 ** The only thing it does is allocate the pLevel->iMem memory cell and
110796 ** compute the affinity string.
110797 **
110798 ** The nExtraReg parameter is 0 or 1. It is 0 if all WHERE clause constraints
110799 ** are == or IN and are covered by the nEq. nExtraReg is 1 if there is
110800 ** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
110801 ** occurs after the nEq quality constraints.
110802 **
110803 ** This routine allocates a range of nEq+nExtraReg memory cells and returns
110804 ** the index of the first memory cell in that range. The code that
110805 ** calls this routine will use that memory range to store keys for
110806 ** start and termination conditions of the loop.
110807 ** key value of the loop. If one or more IN operators appear, then
110808 ** this routine allocates an additional nEq memory cells for internal
110809 ** use.
110810 **
110811 ** Before returning, *pzAff is set to point to a buffer containing a
@@ -110803,11 +110828,12 @@
110828 WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */
110829 int bRev, /* Reverse the order of IN operators */
110830 int nExtraReg, /* Number of extra registers to allocate */
110831 char **pzAff /* OUT: Set to point to affinity string */
110832 ){
110833 u16 nEq; /* The number of == or IN constraints to code */
110834 u16 nSkip; /* Number of left-most columns to skip */
110835 Vdbe *v = pParse->pVdbe; /* The vm under construction */
110836 Index *pIdx; /* The index being used for this loop */
110837 WhereTerm *pTerm; /* A single constraint term */
110838 WhereLoop *pLoop; /* The WhereLoop object */
110839 int j; /* Loop counter */
@@ -110817,10 +110843,11 @@
110843
110844 /* This module is only called on query plans that use an index. */
110845 pLoop = pLevel->pWLoop;
110846 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
110847 nEq = pLoop->u.btree.nEq;
110848 nSkip = pLoop->u.btree.nSkip;
110849 pIdx = pLoop->u.btree.pIndex;
110850 assert( pIdx!=0 );
110851
110852 /* Figure out how many memory cells we will need then allocate them.
110853 */
@@ -110830,19 +110857,34 @@
110857
110858 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
110859 if( !zAff ){
110860 pParse->db->mallocFailed = 1;
110861 }
110862
110863 if( nSkip ){
110864 int iIdxCur = pLevel->iIdxCur;
110865 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
110866 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
110867 j = sqlite3VdbeAddOp0(v, OP_Goto);
110868 pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
110869 iIdxCur, 0, regBase, nSkip);
110870 sqlite3VdbeJumpHere(v, j);
110871 for(j=0; j<nSkip; j++){
110872 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
110873 assert( pIdx->aiColumn[j]>=0 );
110874 VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
110875 }
110876 }
110877
110878 /* Evaluate the equality constraints
110879 */
110880 assert( zAff==0 || (int)strlen(zAff)>=nEq );
110881 for(j=nSkip; j<nEq; j++){
110882 int r1;
110883 pTerm = pLoop->aLTerm[j];
110884 assert( pTerm!=0 );
110885 /* The following testcase is true for indices with redundant columns.
110886 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
110887 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
110888 testcase( pTerm->wtFlags & TERM_VIRTUAL );
110889 r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
110890 if( r1!=regBase+j ){
@@ -110912,11 +110954,12 @@
110954 ** It is the responsibility of the caller to free the buffer when it is
110955 ** no longer required.
110956 */
110957 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
110958 Index *pIndex = pLoop->u.btree.pIndex;
110959 u16 nEq = pLoop->u.btree.nEq;
110960 u16 nSkip = pLoop->u.btree.nSkip;
110961 int i, j;
110962 Column *aCol = pTab->aCol;
110963 i16 *aiColumn = pIndex->aiColumn;
110964 StrAccum txt;
110965
@@ -110926,11 +110969,18 @@
110969 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
110970 txt.db = db;
110971 sqlite3StrAccumAppend(&txt, " (", 2);
110972 for(i=0; i<nEq; i++){
110973 char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
110974 if( i>=nSkip ){
110975 explainAppendTerm(&txt, i, z, "=");
110976 }else{
110977 if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
110978 sqlite3StrAccumAppend(&txt, "ANY(", 4);
110979 sqlite3StrAccumAppend(&txt, z, -1);
110980 sqlite3StrAccumAppend(&txt, ")", 1);
110981 }
110982 }
110983
110984 j = i;
110985 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
110986 char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
@@ -110956,11 +111006,14 @@
111006 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
111007 int iLevel, /* Value for "level" column of output */
111008 int iFrom, /* Value for "from" column of output */
111009 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
111010 ){
111011 #ifndef SQLITE_DEBUG
111012 if( pParse->explain==2 )
111013 #endif
111014 {
111015 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
111016 Vdbe *v = pParse->pVdbe; /* VM being constructed */
111017 sqlite3 *db = pParse->db; /* Database handle */
111018 char *zMsg; /* Text to add to EQP output */
111019 int iId = pParse->iSelectId; /* Select id (left-most output column) */
@@ -111062,11 +111115,11 @@
111115 iCur = pTabItem->iCursor;
111116 pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
111117 bRev = (pWInfo->revMask>>iLevel)&1;
111118 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
111119 && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
111120 VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
111121
111122 /* Create labels for the "break" and "continue" instructions
111123 ** for the current loop. Jump to addrBrk to break out of a loop.
111124 ** Jump to cont to go immediately to the next iteration of the
111125 ** loop.
@@ -111289,12 +111342,12 @@
111342 static const u8 aEndOp[] = {
111343 OP_Noop, /* 0: (!end_constraints) */
111344 OP_IdxGE, /* 1: (end_constraints && !bRev) */
111345 OP_IdxLT /* 2: (end_constraints && bRev) */
111346 };
111347 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111348 int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111349 int regBase; /* Base register holding constraint values */
111350 int r1; /* Temp register */
111351 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111352 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111353 int startEq; /* True if range start uses ==, >= or <= */
@@ -111304,14 +111357,15 @@
111357 Index *pIdx; /* The index we will be using */
111358 int iIdxCur; /* The VDBE cursor for the index */
111359 int nExtraReg = 0; /* Number of extra registers needed */
111360 int op; /* Instruction opcode */
111361 char *zStartAff; /* Affinity for start of range constraint */
111362 char cEndAff = 0; /* Affinity for end of range constraint */
111363
111364 pIdx = pLoop->u.btree.pIndex;
111365 iIdxCur = pLevel->iIdxCur;
111366 assert( nEq>=pLoop->u.btree.nSkip );
111367
111368 /* If this loop satisfies a sort order (pOrderBy) request that
111369 ** was passed to this function to implement a "SELECT min(x) ..."
111370 ** query, then the caller will only allow the loop to run for
111371 ** a single iteration. This means that the first row returned
@@ -111321,12 +111375,11 @@
111375 */
111376 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111377 && (pWInfo->bOBSat!=0)
111378 && (pIdx->nKeyCol>nEq)
111379 ){
111380 assert( pLoop->u.btree.nSkip==0 );
 
111381 isMinQuery = 1;
111382 nExtraReg = 1;
111383 }
111384
111385 /* Find any inequality constraint terms for the start and end
@@ -111345,11 +111398,12 @@
111398 /* Generate code to evaluate all constraint terms using == or IN
111399 ** and store the values of those terms in an array of registers
111400 ** starting at regBase.
111401 */
111402 regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
111403 assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
111404 if( zStartAff ) cEndAff = zStartAff[nEq];
111405 addrNxt = pLevel->addrNxt;
111406
111407 /* If we are doing a reverse order scan on an ascending index, or
111408 ** a forward order scan on a descending index, interchange the
111409 ** start and end terms (pRangeStart and pRangeEnd).
@@ -111415,27 +111469,19 @@
111469 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111470 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111471 if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111472 sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
111473 }
111474 if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
111475 && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
111476 ){
111477 codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
111478 }
 
 
 
 
 
 
 
111479 nConstraint++;
111480 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
111481 }
111482 sqlite3DbFree(db, zStartAff);
 
111483
111484 /* Top of the loop body */
111485 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111486
111487 /* Check if the index cursor is past the end of the range. */
@@ -111453,12 +111499,17 @@
111499 ** If it is, jump to the next iteration of the loop.
111500 */
111501 r1 = sqlite3GetTempReg(pParse);
111502 testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111503 testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111504 if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
111505 && (j = pIdx->aiColumn[nEq])>=0
111506 && pIdx->pTable->aCol[j].notNull==0
111507 && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0)
111508 ){
111509 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
111510 VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName));
111511 sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111512 }
111513 sqlite3ReleaseTempReg(pParse, r1);
111514
111515 /* Seek the table cursor, if required */
@@ -111769,11 +111820,11 @@
111820 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
111821 if( pAlt==0 ) continue;
111822 if( pAlt->wtFlags & (TERM_CODED) ) continue;
111823 testcase( pAlt->eOperator & WO_EQ );
111824 testcase( pAlt->eOperator & WO_IN );
111825 VdbeModuleComment((v, "begin transitive constraint"));
111826 pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
111827 if( pEAlt ){
111828 *pEAlt = *pAlt->pExpr;
111829 pEAlt->pLeft = pE->pLeft;
111830 sqlite3ExprIfFalse(pParse, pEAlt, addrCont, SQLITE_JUMPIFNULL);
@@ -111842,16 +111893,11 @@
111893 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
111894 int i = sqlite3Strlen30(zName) - 1;
111895 while( zName[i]!='_' ) i--;
111896 zName += i;
111897 }
111898 sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
 
 
 
 
 
111899 }else{
111900 sqlite3DebugPrintf("%20s","");
111901 }
111902 }else{
111903 char *z;
@@ -111874,10 +111920,11 @@
111920 int i;
111921 Vdbe *v = pWInfo->pParse->pVdbe;
111922 sqlite3ExplainBegin(v);
111923 for(i=0; i<p->nLTerm; i++){
111924 WhereTerm *pTerm = p->aLTerm[i];
111925 if( pTerm==0 ) continue;
111926 sqlite3ExplainPrintf(v, " (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
111927 sqlite3ExplainPush(v);
111928 whereExplainTerm(v, pTerm);
111929 sqlite3ExplainPop(v);
111930 sqlite3ExplainNL(v);
@@ -112157,10 +112204,11 @@
112204 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
112205 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
112206 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
112207 for(j=pLoop->nLTerm-1; j>=0; j--){
112208 pX = pLoop->aLTerm[j];
112209 if( pX==0 ) continue;
112210 if( pX==pTerm ) break;
112211 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
112212 }
112213 if( j<0 ) pLoop->nOut += pTerm->truthProb;
112214 }
@@ -112186,11 +112234,12 @@
112234 WhereTerm *pTerm; /* A WhereTerm under consideration */
112235 int opMask; /* Valid operators for constraints */
112236 WhereScan scan; /* Iterator for WHERE terms */
112237 Bitmask saved_prereq; /* Original value of pNew->prereq */
112238 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
112239 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
112240 u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
112241 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
112242 LogEst saved_nOut; /* Original value of pNew->nOut */
112243 int iCol; /* Index of the column in the table */
112244 int rc = SQLITE_OK; /* Return code */
112245 LogEst nRowEst; /* Estimated index selectivity */
@@ -112221,16 +112270,35 @@
112270 nRowEst = 0;
112271 }
112272 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
112273 opMask, pProbe);
112274 saved_nEq = pNew->u.btree.nEq;
112275 saved_nSkip = pNew->u.btree.nSkip;
112276 saved_nLTerm = pNew->nLTerm;
112277 saved_wsFlags = pNew->wsFlags;
112278 saved_prereq = pNew->prereq;
112279 saved_nOut = pNew->nOut;
112280 pNew->rSetup = 0;
112281 rLogSize = estLog(sqlite3LogEst(pProbe->aiRowEst[0]));
112282
112283 /* Consider using a skip-scan if there are no WHERE clause constraints
112284 ** available for the left-most terms of the index, and if the average
112285 ** number of repeats in the left-most terms is at least 50.
112286 */
112287 if( pTerm==0
112288 && saved_nEq==saved_nSkip
112289 && saved_nEq+1<pProbe->nKeyCol
112290 && pProbe->aiRowEst[saved_nEq+1]>50 /* TUNING: Minimum for skip-scan */
112291 ){
112292 LogEst nIter;
112293 pNew->u.btree.nEq++;
112294 pNew->u.btree.nSkip++;
112295 pNew->aLTerm[pNew->nLTerm++] = 0;
112296 pNew->wsFlags |= WHERE_SKIPSCAN;
112297 nIter = sqlite3LogEst(pProbe->aiRowEst[0]/pProbe->aiRowEst[saved_nEq+1]);
112298 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter);
112299 }
112300 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
112301 int nIn = 0;
112302 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
112303 int nRecValid = pBuilder->nRecValid;
112304 #endif
@@ -112262,12 +112330,14 @@
112330 }
112331 pNew->rRun += nIn;
112332 pNew->u.btree.nEq++;
112333 pNew->nOut = nRowEst + nInMul + nIn;
112334 }else if( pTerm->eOperator & (WO_EQ) ){
112335 assert(
112336 (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
112337 || nInMul==0
112338 );
112339 pNew->wsFlags |= WHERE_COLUMN_EQ;
112340 if( iCol<0
112341 || (pProbe->onError!=OE_None && nInMul==0
112342 && pNew->u.btree.nEq==pProbe->nKeyCol-1)
112343 ){
@@ -112344,10 +112414,11 @@
112414 pBuilder->nRecValid = nRecValid;
112415 #endif
112416 }
112417 pNew->prereq = saved_prereq;
112418 pNew->u.btree.nEq = saved_nEq;
112419 pNew->u.btree.nSkip = saved_nSkip;
112420 pNew->wsFlags = saved_wsFlags;
112421 pNew->nOut = saved_nOut;
112422 pNew->nLTerm = saved_nLTerm;
112423 return rc;
112424 }
@@ -112490,10 +112561,11 @@
112561 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
112562 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
112563 if( pTerm->prereqRight & pNew->maskSelf ) continue;
112564 if( termCanDriveIndex(pTerm, pSrc, 0) ){
112565 pNew->u.btree.nEq = 1;
112566 pNew->u.btree.nSkip = 0;
112567 pNew->u.btree.pIndex = 0;
112568 pNew->nLTerm = 1;
112569 pNew->aLTerm[0] = pTerm;
112570 /* TUNING: One-time cost for computing the automatic index is
112571 ** approximately 7*N*log2(N) where N is the number of rows in
@@ -112519,10 +112591,11 @@
112591 if( pProbe->pPartIdxWhere!=0
112592 && !whereUsablePartialIndex(pNew->iTab, pWC, pProbe->pPartIdxWhere) ){
112593 continue; /* Partial index inappropriate for this query */
112594 }
112595 pNew->u.btree.nEq = 0;
112596 pNew->u.btree.nSkip = 0;
112597 pNew->nLTerm = 0;
112598 pNew->iSortIdx = 0;
112599 pNew->rSetup = 0;
112600 pNew->prereq = mExtra;
112601 pNew->nOut = rSize;
@@ -112604,11 +112677,12 @@
112677 /*
112678 ** Add all WhereLoop objects for a table of the join identified by
112679 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
112680 */
112681 static int whereLoopAddVirtual(
112682 WhereLoopBuilder *pBuilder, /* WHERE clause information */
112683 Bitmask mExtra
112684 ){
112685 WhereInfo *pWInfo; /* WHERE analysis context */
112686 Parse *pParse; /* The parsing context */
112687 WhereClause *pWC; /* The WHERE clause */
112688 struct SrcList_item *pSrc; /* The FROM clause term to search */
@@ -112694,11 +112768,11 @@
112768 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
112769 pIdxInfo->estimatedRows = 25;
112770 rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112771 if( rc ) goto whereLoopAddVtab_exit;
112772 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112773 pNew->prereq = mExtra;
112774 mxTerm = -1;
112775 assert( pNew->nLSlot>=nConstraint );
112776 for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
112777 pNew->u.vtab.omitMask = 0;
112778 for(i=0; i<nConstraint; i++, pIdxCons++){
@@ -112821,12 +112895,11 @@
112895 continue;
112896 }
112897 sCur.n = 0;
112898 #ifndef SQLITE_OMIT_VIRTUALTABLE
112899 if( IsVirtual(pItem->pTab) ){
112900 rc = whereLoopAddVirtual(&sSubBuild, mExtra);
 
112901 }else
112902 #endif
112903 {
112904 rc = whereLoopAddBtree(&sSubBuild, mExtra);
112905 }
@@ -112892,11 +112965,11 @@
112965 if( ((pItem->jointype|priorJoinType) & (JT_LEFT|JT_CROSS))!=0 ){
112966 mExtra = mPrior;
112967 }
112968 priorJoinType = pItem->jointype;
112969 if( IsVirtual(pItem->pTab) ){
112970 rc = whereLoopAddVirtual(pBuilder, mExtra);
112971 }else{
112972 rc = whereLoopAddBtree(pBuilder, mExtra);
112973 }
112974 if( rc==SQLITE_OK ){
112975 rc = whereLoopAddOr(pBuilder, mExtra);
@@ -113053,10 +113126,11 @@
113126 for(j=0; j<nColumn; j++){
113127 u8 bOnce; /* True to run the ORDER BY search loop */
113128
113129 /* Skip over == and IS NULL terms */
113130 if( j<pLoop->u.btree.nEq
113131 && pLoop->u.btree.nSkip==0
113132 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
113133 ){
113134 if( i & WO_ISNULL ){
113135 testcase( isOrderDistinct );
113136 isOrderDistinct = 0;
@@ -113478,10 +113552,11 @@
113552 if( pItem->zIndex ) return 0;
113553 iCur = pItem->iCursor;
113554 pWC = &pWInfo->sWC;
113555 pLoop = pBuilder->pNew;
113556 pLoop->wsFlags = 0;
113557 pLoop->u.btree.nSkip = 0;
113558 pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
113559 if( pTerm ){
113560 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
113561 pLoop->aLTerm[0] = pTerm;
113562 pLoop->nLTerm = 1;
@@ -113706,11 +113781,10 @@
113781 /* Split the WHERE clause into separate subexpressions where each
113782 ** subexpression is separated by an AND operator.
113783 */
113784 initMaskSet(pMaskSet);
113785 whereClauseInit(&pWInfo->sWC, pWInfo);
 
113786 whereSplit(&pWInfo->sWC, pWhere, TK_AND);
113787 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113788
113789 /* Special case: a WHERE clause that is constant. Evaluate the
113790 ** expression and either jump over all of the code or fall thru.
@@ -114021,10 +114095,11 @@
114095 notReady = codeOneLoopStart(pWInfo, ii, notReady);
114096 pWInfo->iContinue = pLevel->addrCont;
114097 }
114098
114099 /* Done. */
114100 VdbeModuleComment((v, "Begin WHERE-core"));
114101 return pWInfo;
114102
114103 /* Jump here if malloc fails */
114104 whereBeginError:
114105 if( pWInfo ){
@@ -114047,12 +114122,14 @@
114122 SrcList *pTabList = pWInfo->pTabList;
114123 sqlite3 *db = pParse->db;
114124
114125 /* Generate loop termination code.
114126 */
114127 VdbeModuleComment((v, "End WHERE-core"));
114128 sqlite3ExprCacheClear(pParse);
114129 for(i=pWInfo->nLevel-1; i>=0; i--){
114130 int addr;
114131 pLevel = &pWInfo->a[i];
114132 pLoop = pLevel->pWLoop;
114133 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114134 if( pLevel->op!=OP_Noop ){
114135 sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
@@ -114068,12 +114145,17 @@
114145 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114146 }
114147 sqlite3DbFree(db, pLevel->u.in.aInLoop);
114148 }
114149 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
114150 if( pLevel->addrSkip ){
114151 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
114152 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
114153 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
114154 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
114155 }
114156 if( pLevel->iLeftJoin ){
 
114157 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114158 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114159 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114160 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114161 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
@@ -114086,11 +114168,11 @@
114168 }else{
114169 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
114170 }
114171 sqlite3VdbeJumpHere(v, addr);
114172 }
114173 VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
114174 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
114175 }
114176
114177 /* The "break" point is here, just past the end of the outer loop.
114178 ** Set it.
@@ -123671,10 +123753,14 @@
123753 char *aDoclist; /* Pointer to doclist buffer */
123754 int nDoclist; /* Size of aDoclist[] in bytes */
123755 };
123756
123757 SQLITE_PRIVATE int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
123758
123759 #define fts3GetVarint32(p, piVal) ( \
123760 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
123761 )
123762
123763 /* fts3.c */
123764 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
123765 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
123766 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
@@ -123779,36 +123865,63 @@
123865 q[-1] &= 0x7f; /* turn off high bit in final byte */
123866 assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
123867 return (int) (q - (unsigned char *)p);
123868 }
123869
123870 #define GETVARINT_STEP(v, ptr, shift, mask1, mask2, var, ret) \
123871 v = (v & mask1) | ( (*ptr++) << shift ); \
123872 if( (v & mask2)==0 ){ var = v; return ret; }
123873 #define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
123874 v = (*ptr++); \
123875 if( (v & mask2)==0 ){ var = v; return ret; }
123876
123877 /*
123878 ** Read a 64-bit variable-length integer from memory starting at p[0].
123879 ** Return the number of bytes read, or 0 on error.
123880 ** The value is stored in *v.
123881 */
123882 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){
123883 const char *pStart = p;
123884 u32 a;
123885 u64 b;
123886 int shift;
123887
123888 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
123889 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *v, 2);
123890 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *v, 3);
123891 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *v, 4);
123892 b = (a & 0x0FFFFFFF );
123893
123894 for(shift=28; shift<=63; shift+=7){
123895 u64 c = *p++;
123896 b += (c&0x7F) << shift;
123897 if( (c & 0x80)==0 ) break;
123898 }
123899 *v = b;
123900 return (int)(p - pStart);
123901 }
123902
123903 /*
123904 ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
123905 ** 32-bit integer before it is returned.
123906 */
123907 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
123908 u32 a;
123909
123910 #ifndef fts3GetVarint32
123911 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *pi, 1);
123912 #else
123913 a = (*p++);
123914 assert( a & 0x80 );
123915 #endif
123916
123917 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
123918 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
123919 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
123920 a = (a & 0x0FFFFFFF );
123921 *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
123922 return 5;
123923 }
123924
123925 /*
123926 ** Return the number of bytes required to encode v as a varint
123927 */
@@ -125164,14 +125277,14 @@
125277 int nBuffer; /* Total term size */
125278
125279 /* Load the next term on the node into zBuffer. Use realloc() to expand
125280 ** the size of zBuffer if required. */
125281 if( !isFirstTerm ){
125282 zCsr += fts3GetVarint32(zCsr, &nPrefix);
125283 }
125284 isFirstTerm = 0;
125285 zCsr += fts3GetVarint32(zCsr, &nSuffix);
125286
125287 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
125288 rc = FTS_CORRUPT_VTAB;
125289 goto finish_scan;
125290 }
@@ -125255,11 +125368,11 @@
125368 int rc; /* Return code */
125369 int iHeight; /* Height of this node in tree */
125370
125371 assert( piLeaf || piLeaf2 );
125372
125373 fts3GetVarint32(zNode, &iHeight);
125374 rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
125375 assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
125376
125377 if( rc==SQLITE_OK && iHeight>1 ){
125378 char *zBlob = 0; /* Blob read from %_segments table */
@@ -125457,15 +125570,15 @@
125570
125571 while( *p1 || *p2 ){
125572 int iCol1; /* The current column index in pp1 */
125573 int iCol2; /* The current column index in pp2 */
125574
125575 if( *p1==POS_COLUMN ) fts3GetVarint32(&p1[1], &iCol1);
125576 else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
125577 else iCol1 = 0;
125578
125579 if( *p2==POS_COLUMN ) fts3GetVarint32(&p2[1], &iCol2);
125580 else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
125581 else iCol2 = 0;
125582
125583 if( iCol1==iCol2 ){
125584 sqlite3_int64 i1 = 0; /* Last position from pp1 */
@@ -125554,15 +125667,15 @@
125667 assert( isSaveLeft==0 || isExact==0 );
125668
125669 assert( p!=0 && *p1!=0 && *p2!=0 );
125670 if( *p1==POS_COLUMN ){
125671 p1++;
125672 p1 += fts3GetVarint32(p1, &iCol1);
125673 }
125674 if( *p2==POS_COLUMN ){
125675 p2++;
125676 p2 += fts3GetVarint32(p2, &iCol2);
125677 }
125678
125679 while( 1 ){
125680 if( iCol1==iCol2 ){
125681 char *pSave = p;
@@ -125608,13 +125721,13 @@
125721 fts3ColumnlistCopy(0, &p2);
125722 assert( (*p1&0xFE)==0 && (*p2&0xFE)==0 );
125723 if( 0==*p1 || 0==*p2 ) break;
125724
125725 p1++;
125726 p1 += fts3GetVarint32(p1, &iCol1);
125727 p2++;
125728 p2 += fts3GetVarint32(p2, &iCol2);
125729 }
125730
125731 /* Advance pointer p1 or p2 (whichever corresponds to the smaller of
125732 ** iCol1 and iCol2) so that it points to either the 0x00 that marks the
125733 ** end of the position list, or the 0x01 that precedes the next
@@ -125622,16 +125735,16 @@
125735 */
125736 else if( iCol1<iCol2 ){
125737 fts3ColumnlistCopy(0, &p1);
125738 if( 0==*p1 ) break;
125739 p1++;
125740 p1 += fts3GetVarint32(p1, &iCol1);
125741 }else{
125742 fts3ColumnlistCopy(0, &p2);
125743 if( 0==*p2 ) break;
125744 p2++;
125745 p2 += fts3GetVarint32(p2, &iCol2);
125746 }
125747 }
125748
125749 fts3PoslistCopy(0, &p2);
125750 fts3PoslistCopy(0, &p1);
@@ -128794,11 +128907,11 @@
128907 */
128908 pExpr->aMI[iCol*3 + 1] += iCnt;
128909 pExpr->aMI[iCol*3 + 2] += (iCnt>0);
128910 if( *p==0x00 ) break;
128911 p++;
128912 p += fts3GetVarint32(p, &iCol);
128913 }
128914 }
128915
128916 fts3EvalUpdateCounts(pExpr->pLeft);
128917 fts3EvalUpdateCounts(pExpr->pRight);
@@ -129095,19 +129208,19 @@
129208 }
129209 if( pIter==0 ) return SQLITE_OK;
129210
129211 if( *pIter==0x01 ){
129212 pIter++;
129213 pIter += fts3GetVarint32(pIter, &iThis);
129214 }else{
129215 iThis = 0;
129216 }
129217 while( iThis<iCol ){
129218 fts3ColumnlistCopy(0, &pIter);
129219 if( *pIter==0x00 ) return 0;
129220 pIter++;
129221 pIter += fts3GetVarint32(pIter, &iThis);
129222 }
129223
129224 *ppOut = ((iCol==iThis)?pIter:0);
129225 return SQLITE_OK;
129226 }
@@ -134552,12 +134665,12 @@
134665 rc = fts3SegReaderRequire(pReader, pNext, FTS3_VARINT_MAX*2);
134666 if( rc!=SQLITE_OK ) return rc;
134667
134668 /* Because of the FTS3_NODE_PADDING bytes of padding, the following is
134669 ** safe (no risk of overread) even if the node data is corrupted. */
134670 pNext += fts3GetVarint32(pNext, &nPrefix);
134671 pNext += fts3GetVarint32(pNext, &nSuffix);
134672 if( nPrefix<0 || nSuffix<=0
134673 || &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
134674 ){
134675 return FTS_CORRUPT_VTAB;
134676 }
@@ -134576,11 +134689,11 @@
134689 if( rc!=SQLITE_OK ) return rc;
134690
134691 memcpy(&pReader->zTerm[nPrefix], pNext, nSuffix);
134692 pReader->nTerm = nPrefix+nSuffix;
134693 pNext += nSuffix;
134694 pNext += fts3GetVarint32(pNext, &pReader->nDoclist);
134695 pReader->aDoclist = pNext;
134696 pReader->pOffsetList = 0;
134697
134698 /* Check that the doclist does not appear to extend past the end of the
134699 ** b-tree node. And that the final byte of the doclist is 0x00. If either
@@ -135737,11 +135850,11 @@
135850 pList = p;
135851 if( nList==0 ){
135852 break;
135853 }
135854 p = &pList[1];
135855 p += fts3GetVarint32(p, &iCurrent);
135856 }
135857
135858 if( bZero && &pList[nList]!=pEnd ){
135859 memset(&pList[nList], 0, pEnd - &pList[nList]);
135860 }
@@ -136702,21 +136815,21 @@
136815 if( p->iOff>=p->nNode ){
136816 /* EOF */
136817 p->aNode = 0;
136818 }else{
136819 if( bFirst==0 ){
136820 p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
136821 }
136822 p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
136823
136824 blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
136825 if( rc==SQLITE_OK ){
136826 memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix);
136827 p->term.n = nPrefix+nSuffix;
136828 p->iOff += nSuffix;
136829 if( p->iChild==0 ){
136830 p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
136831 p->aDoclist = &p->aNode[p->iOff];
136832 p->iOff += p->nDoclist;
136833 }
136834 }
136835 }
@@ -137764,11 +137877,11 @@
137877 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137878 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
137879
137880 pHint->n = i;
137881 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
137882 i += fts3GetVarint32(&pHint->a[i], pnInput);
137883 if( i!=nHint ) return SQLITE_CORRUPT_VTAB;
137884
137885 return SQLITE_OK;
137886 }
137887
@@ -138757,11 +138870,11 @@
138870 ** After it returns, *piPos contains the value of the next element of the
138871 ** list and *pp is advanced to the following varint.
138872 */
138873 static void fts3GetDeltaPosition(char **pp, int *piPos){
138874 int iVal;
138875 *pp += fts3GetVarint32(*pp, &iVal);
138876 *piPos += (iVal-2);
138877 }
138878
138879 /*
138880 ** Helper function for fts3ExprIterate() (see below).
138881
+7 -8
--- 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.2"
111111
#define SQLITE_VERSION_NUMBER 3008002
112
-#define SQLITE_SOURCE_ID "2013-11-12 15:33:40 0f924c6ef6cf2ac5a61aafa8dd8e3309b3970499"
112
+#define SQLITE_SOURCE_ID "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -368,11 +368,11 @@
368368
** Restrictions:
369369
**
370370
** <ul>
371371
** <li> The application must insure that the 1st parameter to sqlite3_exec()
372372
** is a valid and open [database connection].
373
-** <li> The application must not close [database connection] specified by
373
+** <li> The application must not close the [database connection] specified by
374374
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
375375
** <li> The application must not modify the SQL statement text passed into
376376
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
377377
** </ul>
378378
*/
@@ -445,11 +445,11 @@
445445
** about errors. The extended result codes are enabled or disabled
446446
** on a per database connection basis using the
447447
** [sqlite3_extended_result_codes()] API.
448448
**
449449
** Some of the available extended result codes are listed here.
450
-** One may expect the number of extended result codes will be expand
450
+** One may expect the number of extended result codes will increase
451451
** over time. Software that uses extended result codes should expect
452452
** to see new result codes in future releases of SQLite.
453453
**
454454
** The SQLITE_OK result code will never be extended. It will always
455455
** be exactly zero.
@@ -1383,11 +1383,11 @@
13831383
** of 8. Some allocators round up to a larger multiple or to a power of 2.
13841384
** Every memory allocation request coming in through [sqlite3_malloc()]
13851385
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
13861386
** that causes the corresponding memory allocation to fail.
13871387
**
1388
-** The xInit method initializes the memory allocator. (For example,
1388
+** The xInit method initializes the memory allocator. For example,
13891389
** it might allocate any require mutexes or initialize internal data
13901390
** structures. The xShutdown method is invoked (indirectly) by
13911391
** [sqlite3_shutdown()] and should deallocate any resources acquired
13921392
** by xInit. The pAppData pointer is used as the only parameter to
13931393
** xInit and xShutdown.
@@ -3109,11 +3109,10 @@
31093109
** to the [sqlite3_bind_text | bindings] of that [parameter].
31103110
** ^The specific value of WHERE-clause [parameter] might influence the
31113111
** choice of query plan if the parameter is the left-hand side of a [LIKE]
31123112
** or [GLOB] operator or if the parameter is compared to an indexed column
31133113
** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3114
-** the
31153114
** </li>
31163115
** </ol>
31173116
*/
31183117
SQLITE_API int sqlite3_prepare(
31193118
sqlite3 *db, /* Database handle */
@@ -3839,11 +3838,11 @@
38393838
**
38403839
** ^The pointers returned are valid until a type conversion occurs as
38413840
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
38423841
** [sqlite3_finalize()] is called. ^The memory space used to hold strings
38433842
** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3844
-** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3843
+** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
38453844
** [sqlite3_free()].
38463845
**
38473846
** ^(If a memory allocation error occurs during the evaluation of any
38483847
** of these routines, a default value is returned. The default value
38493848
** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4917,12 +4916,12 @@
49174916
/*
49184917
** CAPI3REF: Free Memory Used By A Database Connection
49194918
**
49204919
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
49214920
** memory as possible from database connection D. Unlike the
4922
-** [sqlite3_release_memory()] interface, this interface is effect even
4923
-** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4921
+** [sqlite3_release_memory()] interface, this interface is in effect even
4922
+** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
49244923
** omitted.
49254924
**
49264925
** See also: [sqlite3_release_memory()]
49274926
*/
49284927
SQLITE_API int sqlite3_db_release_memory(sqlite3*);
49294928
--- 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.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-11-12 15:33:40 0f924c6ef6cf2ac5a61aafa8dd8e3309b3970499"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -368,11 +368,11 @@
368 ** Restrictions:
369 **
370 ** <ul>
371 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
372 ** is a valid and open [database connection].
373 ** <li> The application must not close [database connection] specified by
374 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
375 ** <li> The application must not modify the SQL statement text passed into
376 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
377 ** </ul>
378 */
@@ -445,11 +445,11 @@
445 ** about errors. The extended result codes are enabled or disabled
446 ** on a per database connection basis using the
447 ** [sqlite3_extended_result_codes()] API.
448 **
449 ** Some of the available extended result codes are listed here.
450 ** One may expect the number of extended result codes will be expand
451 ** over time. Software that uses extended result codes should expect
452 ** to see new result codes in future releases of SQLite.
453 **
454 ** The SQLITE_OK result code will never be extended. It will always
455 ** be exactly zero.
@@ -1383,11 +1383,11 @@
1383 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1384 ** Every memory allocation request coming in through [sqlite3_malloc()]
1385 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1386 ** that causes the corresponding memory allocation to fail.
1387 **
1388 ** The xInit method initializes the memory allocator. (For example,
1389 ** it might allocate any require mutexes or initialize internal data
1390 ** structures. The xShutdown method is invoked (indirectly) by
1391 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1392 ** by xInit. The pAppData pointer is used as the only parameter to
1393 ** xInit and xShutdown.
@@ -3109,11 +3109,10 @@
3109 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3110 ** ^The specific value of WHERE-clause [parameter] might influence the
3111 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3112 ** or [GLOB] operator or if the parameter is compared to an indexed column
3113 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3114 ** the
3115 ** </li>
3116 ** </ol>
3117 */
3118 SQLITE_API int sqlite3_prepare(
3119 sqlite3 *db, /* Database handle */
@@ -3839,11 +3838,11 @@
3839 **
3840 ** ^The pointers returned are valid until a type conversion occurs as
3841 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3842 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3843 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3844 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3845 ** [sqlite3_free()].
3846 **
3847 ** ^(If a memory allocation error occurs during the evaluation of any
3848 ** of these routines, a default value is returned. The default value
3849 ** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4917,12 +4916,12 @@
4917 /*
4918 ** CAPI3REF: Free Memory Used By A Database Connection
4919 **
4920 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
4921 ** memory as possible from database connection D. Unlike the
4922 ** [sqlite3_release_memory()] interface, this interface is effect even
4923 ** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4924 ** omitted.
4925 **
4926 ** See also: [sqlite3_release_memory()]
4927 */
4928 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
4929
--- 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.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -368,11 +368,11 @@
368 ** Restrictions:
369 **
370 ** <ul>
371 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
372 ** is a valid and open [database connection].
373 ** <li> The application must not close the [database connection] specified by
374 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
375 ** <li> The application must not modify the SQL statement text passed into
376 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
377 ** </ul>
378 */
@@ -445,11 +445,11 @@
445 ** about errors. The extended result codes are enabled or disabled
446 ** on a per database connection basis using the
447 ** [sqlite3_extended_result_codes()] API.
448 **
449 ** Some of the available extended result codes are listed here.
450 ** One may expect the number of extended result codes will increase
451 ** over time. Software that uses extended result codes should expect
452 ** to see new result codes in future releases of SQLite.
453 **
454 ** The SQLITE_OK result code will never be extended. It will always
455 ** be exactly zero.
@@ -1383,11 +1383,11 @@
1383 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1384 ** Every memory allocation request coming in through [sqlite3_malloc()]
1385 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1386 ** that causes the corresponding memory allocation to fail.
1387 **
1388 ** The xInit method initializes the memory allocator. For example,
1389 ** it might allocate any require mutexes or initialize internal data
1390 ** structures. The xShutdown method is invoked (indirectly) by
1391 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1392 ** by xInit. The pAppData pointer is used as the only parameter to
1393 ** xInit and xShutdown.
@@ -3109,11 +3109,10 @@
3109 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3110 ** ^The specific value of WHERE-clause [parameter] might influence the
3111 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3112 ** or [GLOB] operator or if the parameter is compared to an indexed column
3113 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
 
3114 ** </li>
3115 ** </ol>
3116 */
3117 SQLITE_API int sqlite3_prepare(
3118 sqlite3 *db, /* Database handle */
@@ -3839,11 +3838,11 @@
3838 **
3839 ** ^The pointers returned are valid until a type conversion occurs as
3840 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3841 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3842 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3843 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3844 ** [sqlite3_free()].
3845 **
3846 ** ^(If a memory allocation error occurs during the evaluation of any
3847 ** of these routines, a default value is returned. The default value
3848 ** is either the integer 0, the floating point number 0.0, or a NULL
@@ -4917,12 +4916,12 @@
4916 /*
4917 ** CAPI3REF: Free Memory Used By A Database Connection
4918 **
4919 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
4920 ** memory as possible from database connection D. Unlike the
4921 ** [sqlite3_release_memory()] interface, this interface is in effect even
4922 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
4923 ** omitted.
4924 **
4925 ** See also: [sqlite3_release_memory()]
4926 */
4927 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
4928
+27 -2
--- src/stat.c
+++ src/stat.c
@@ -55,10 +55,11 @@
5555
if( !g.perm.Read ){ login_needed(); return; }
5656
brief = P("brief")!=0;
5757
style_header("Repository Statistics");
5858
if( g.perm.Admin ){
5959
style_submenu_element("URLs", "URLs and Checkouts", "urllist");
60
+ style_submenu_element("Schema", "Repository Schema", "repo_schema");
6061
}
6162
@ <table class="label-value">
6263
@ <tr><th>Repository&nbsp;Size:</th><td>
6364
fsize = file_size(g.zRepositoryName);
6465
bigSizeName(sizeof(zBuf), zBuf, fsize);
@@ -237,12 +238,10 @@
237238
db_text(0, "PRAGMA %s.encoding", zDb),
238239
db_text(0, "PRAGMA %s.journal_mode", zDb));
239240
240241
}
241242
242
-
243
-
244243
/*
245244
** WEBPAGE: urllist
246245
**
247246
** Show ways in which this repository has been accessed
248247
*/
@@ -252,10 +251,11 @@
252251
login_check_credentials();
253252
if( !g.perm.Admin ){ login_needed(); return; }
254253
255254
style_header("URLs and Checkouts");
256255
style_submenu_element("Stat", "Repository Stats", "stat");
256
+ style_submenu_element("Schema", "Repository Schema", "repo_schema");
257257
@ <div class="section">URLs</div>
258258
@ <table border="0" width='100%%'>
259259
db_prepare(&q, "SELECT substr(name,9), datetime(mtime,'unixepoch')"
260260
" FROM config WHERE name GLOB 'baseurl:*' ORDER BY 2 DESC");
261261
cnt = 0;
@@ -284,5 +284,30 @@
284284
@ <tr><td>(none)</td>
285285
}
286286
@ </table>
287287
style_footer();
288288
}
289
+
290
+/*
291
+** WEBPAGE: repo_schema
292
+**
293
+** Show the repository schema
294
+*/
295
+void repo_schema_page(void){
296
+ Stmt q;
297
+ int cnt;
298
+ login_check_credentials();
299
+ if( !g.perm.Admin ){ login_needed(); return; }
300
+
301
+ style_header("Repository Schema");
302
+ style_submenu_element("Stat", "Repository Stats", "stat");
303
+ style_submenu_element("URLs", "URLs and Checkouts", "urllist");
304
+ db_prepare(&q, "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
305
+ db_name("repository"));
306
+ @ <pre>
307
+ while( db_step(&q)==SQLITE_ROW ){
308
+ @ %h(db_column_text(&q, 0));
309
+ }
310
+ @ </pre>
311
+ db_finalize(&q);
312
+ style_footer();
313
+}
289314
--- src/stat.c
+++ src/stat.c
@@ -55,10 +55,11 @@
55 if( !g.perm.Read ){ login_needed(); return; }
56 brief = P("brief")!=0;
57 style_header("Repository Statistics");
58 if( g.perm.Admin ){
59 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
 
60 }
61 @ <table class="label-value">
62 @ <tr><th>Repository&nbsp;Size:</th><td>
63 fsize = file_size(g.zRepositoryName);
64 bigSizeName(sizeof(zBuf), zBuf, fsize);
@@ -237,12 +238,10 @@
237 db_text(0, "PRAGMA %s.encoding", zDb),
238 db_text(0, "PRAGMA %s.journal_mode", zDb));
239
240 }
241
242
243
244 /*
245 ** WEBPAGE: urllist
246 **
247 ** Show ways in which this repository has been accessed
248 */
@@ -252,10 +251,11 @@
252 login_check_credentials();
253 if( !g.perm.Admin ){ login_needed(); return; }
254
255 style_header("URLs and Checkouts");
256 style_submenu_element("Stat", "Repository Stats", "stat");
 
257 @ <div class="section">URLs</div>
258 @ <table border="0" width='100%%'>
259 db_prepare(&q, "SELECT substr(name,9), datetime(mtime,'unixepoch')"
260 " FROM config WHERE name GLOB 'baseurl:*' ORDER BY 2 DESC");
261 cnt = 0;
@@ -284,5 +284,30 @@
284 @ <tr><td>(none)</td>
285 }
286 @ </table>
287 style_footer();
288 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
--- src/stat.c
+++ src/stat.c
@@ -55,10 +55,11 @@
55 if( !g.perm.Read ){ login_needed(); return; }
56 brief = P("brief")!=0;
57 style_header("Repository Statistics");
58 if( g.perm.Admin ){
59 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
60 style_submenu_element("Schema", "Repository Schema", "repo_schema");
61 }
62 @ <table class="label-value">
63 @ <tr><th>Repository&nbsp;Size:</th><td>
64 fsize = file_size(g.zRepositoryName);
65 bigSizeName(sizeof(zBuf), zBuf, fsize);
@@ -237,12 +238,10 @@
238 db_text(0, "PRAGMA %s.encoding", zDb),
239 db_text(0, "PRAGMA %s.journal_mode", zDb));
240
241 }
242
 
 
243 /*
244 ** WEBPAGE: urllist
245 **
246 ** Show ways in which this repository has been accessed
247 */
@@ -252,10 +251,11 @@
251 login_check_credentials();
252 if( !g.perm.Admin ){ login_needed(); return; }
253
254 style_header("URLs and Checkouts");
255 style_submenu_element("Stat", "Repository Stats", "stat");
256 style_submenu_element("Schema", "Repository Schema", "repo_schema");
257 @ <div class="section">URLs</div>
258 @ <table border="0" width='100%%'>
259 db_prepare(&q, "SELECT substr(name,9), datetime(mtime,'unixepoch')"
260 " FROM config WHERE name GLOB 'baseurl:*' ORDER BY 2 DESC");
261 cnt = 0;
@@ -284,5 +284,30 @@
284 @ <tr><td>(none)</td>
285 }
286 @ </table>
287 style_footer();
288 }
289
290 /*
291 ** WEBPAGE: repo_schema
292 **
293 ** Show the repository schema
294 */
295 void repo_schema_page(void){
296 Stmt q;
297 int cnt;
298 login_check_credentials();
299 if( !g.perm.Admin ){ login_needed(); return; }
300
301 style_header("Repository Schema");
302 style_submenu_element("Stat", "Repository Stats", "stat");
303 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
304 db_prepare(&q, "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
305 db_name("repository"));
306 @ <pre>
307 while( db_step(&q)==SQLITE_ROW ){
308 @ %h(db_column_text(&q, 0));
309 }
310 @ </pre>
311 db_finalize(&q);
312 style_footer();
313 }
314
+3 -3
--- src/timeline.c
+++ src/timeline.c
@@ -1828,13 +1828,13 @@
18281828
if( zType && (zType[0]!='a') ){
18291829
blob_appendf(&sql, " AND event.type=%Q ", zType);
18301830
}
18311831
blob_appendf(&sql, " ORDER BY event.mtime DESC");
18321832
if( iOffset>0 ){
1833
- int n2 = (n >= 0) ? n : -n;
1834
- if( n2==0 ) n2 = -1; /* NO LIMIT */
1835
- blob_appendf(&sql, " LIMIT %d OFFSET %d", n2, iOffset);
1833
+ /* Don't handle LIMIT here, otherwise print_timeline()
1834
+ * will not determine the end-marker correctly! */
1835
+ blob_appendf(&sql, " LIMIT -1 OFFSET %d", iOffset);
18361836
}
18371837
db_prepare(&q, blob_str(&sql));
18381838
blob_reset(&sql);
18391839
print_timeline(&q, n, width, verboseFlag);
18401840
db_finalize(&q);
18411841
--- src/timeline.c
+++ src/timeline.c
@@ -1828,13 +1828,13 @@
1828 if( zType && (zType[0]!='a') ){
1829 blob_appendf(&sql, " AND event.type=%Q ", zType);
1830 }
1831 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1832 if( iOffset>0 ){
1833 int n2 = (n >= 0) ? n : -n;
1834 if( n2==0 ) n2 = -1; /* NO LIMIT */
1835 blob_appendf(&sql, " LIMIT %d OFFSET %d", n2, iOffset);
1836 }
1837 db_prepare(&q, blob_str(&sql));
1838 blob_reset(&sql);
1839 print_timeline(&q, n, width, verboseFlag);
1840 db_finalize(&q);
1841
--- src/timeline.c
+++ src/timeline.c
@@ -1828,13 +1828,13 @@
1828 if( zType && (zType[0]!='a') ){
1829 blob_appendf(&sql, " AND event.type=%Q ", zType);
1830 }
1831 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1832 if( iOffset>0 ){
1833 /* Don't handle LIMIT here, otherwise print_timeline()
1834 * will not determine the end-marker correctly! */
1835 blob_appendf(&sql, " LIMIT -1 OFFSET %d", iOffset);
1836 }
1837 db_prepare(&q, blob_str(&sql));
1838 blob_reset(&sql);
1839 print_timeline(&q, n, width, verboseFlag);
1840 db_finalize(&q);
1841
+3 -3
--- src/timeline.c
+++ src/timeline.c
@@ -1828,13 +1828,13 @@
18281828
if( zType && (zType[0]!='a') ){
18291829
blob_appendf(&sql, " AND event.type=%Q ", zType);
18301830
}
18311831
blob_appendf(&sql, " ORDER BY event.mtime DESC");
18321832
if( iOffset>0 ){
1833
- int n2 = (n >= 0) ? n : -n;
1834
- if( n2==0 ) n2 = -1; /* NO LIMIT */
1835
- blob_appendf(&sql, " LIMIT %d OFFSET %d", n2, iOffset);
1833
+ /* Don't handle LIMIT here, otherwise print_timeline()
1834
+ * will not determine the end-marker correctly! */
1835
+ blob_appendf(&sql, " LIMIT -1 OFFSET %d", iOffset);
18361836
}
18371837
db_prepare(&q, blob_str(&sql));
18381838
blob_reset(&sql);
18391839
print_timeline(&q, n, width, verboseFlag);
18401840
db_finalize(&q);
18411841
--- src/timeline.c
+++ src/timeline.c
@@ -1828,13 +1828,13 @@
1828 if( zType && (zType[0]!='a') ){
1829 blob_appendf(&sql, " AND event.type=%Q ", zType);
1830 }
1831 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1832 if( iOffset>0 ){
1833 int n2 = (n >= 0) ? n : -n;
1834 if( n2==0 ) n2 = -1; /* NO LIMIT */
1835 blob_appendf(&sql, " LIMIT %d OFFSET %d", n2, iOffset);
1836 }
1837 db_prepare(&q, blob_str(&sql));
1838 blob_reset(&sql);
1839 print_timeline(&q, n, width, verboseFlag);
1840 db_finalize(&q);
1841
--- src/timeline.c
+++ src/timeline.c
@@ -1828,13 +1828,13 @@
1828 if( zType && (zType[0]!='a') ){
1829 blob_appendf(&sql, " AND event.type=%Q ", zType);
1830 }
1831 blob_appendf(&sql, " ORDER BY event.mtime DESC");
1832 if( iOffset>0 ){
1833 /* Don't handle LIMIT here, otherwise print_timeline()
1834 * will not determine the end-marker correctly! */
1835 blob_appendf(&sql, " LIMIT -1 OFFSET %d", iOffset);
1836 }
1837 db_prepare(&q, blob_str(&sql));
1838 blob_reset(&sql);
1839 print_timeline(&q, n, width, verboseFlag);
1840 db_finalize(&q);
1841
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,11 +24,11 @@
2424
CFLAGS = -o
2525
BCC = $(DMDIR)\bin\dmc $(CFLAGS)
2626
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2727
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
2828
29
-SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
29
+SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
3030
3131
SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
3232
3333
OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
3434
3535
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,11 +24,11 @@
24 CFLAGS = -o
25 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
30
31 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
32
33 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
34
35
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -24,11 +24,11 @@
24 CFLAGS = -o
25 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI
30
31 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
32
33 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
34
35
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1685,11 +1685,11 @@
16851685
$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
16861686
16871687
$(OBJDIR)/zip.h: $(OBJDIR)/headers
16881688
16891689
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690
- $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1690
+ $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -DSQLITE_USE_MALLOC_H -DSQLITE_USE_MSIZE -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
16911691
16921692
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
16931693
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
16941694
16951695
$(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
16961696
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1685,11 +1685,11 @@
1685 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1686
1687 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1688
1689 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1691
1692 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1693 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1694
1695 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
1696
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1685,11 +1685,11 @@
1685 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1686
1687 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1688
1689 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -DSQLITE_USE_MALLOC_H -DSQLITE_USE_MSIZE -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1691
1692 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1693 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1694
1695 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
1696
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -1685,11 +1685,11 @@
16851685
$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
16861686
16871687
$(OBJDIR)/zip.h: $(OBJDIR)/headers
16881688
16891689
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690
- $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1690
+ $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -DSQLITE_USE_MALLOC_H -DSQLITE_USE_MSIZE -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
16911691
16921692
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
16931693
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
16941694
16951695
$(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
16961696
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -1685,11 +1685,11 @@
1685 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1686
1687 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1688
1689 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1691
1692 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1693 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1694
1695 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
1696
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -1685,11 +1685,11 @@
1685 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1686
1687 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1688
1689 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1690 $(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_WIN32_NO_ANSI -D_HAVE_SQLITE_CONFIG_H -DSQLITE_USE_MALLOC_H -DSQLITE_USE_MSIZE -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1691
1692 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
1693 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o
1694
1695 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_status.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
1696
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -67,11 +67,12 @@
6767
!endif
6868
6969
SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
7070
/DSQLITE_THREADSAFE=0 \
7171
/DSQLITE_DEFAULT_FILE_FORMAT=4 \
72
- /DSQLITE_ENABLE_STAT3 \
72
+ /DSQLITE_OMIT_DEPRECATED \
73
+ /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
7374
/Dlocaltime=fossil_localtime \
7475
/DSQLITE_ENABLE_LOCKING_STYLE=0 \
7576
/DSQLITE_WIN32_NO_ANSI
7677
7778
SRC = add_.c \
7879
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -67,11 +67,12 @@
67 !endif
68
69 SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
70 /DSQLITE_THREADSAFE=0 \
71 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
72 /DSQLITE_ENABLE_STAT3 \
 
73 /Dlocaltime=fossil_localtime \
74 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
75 /DSQLITE_WIN32_NO_ANSI
76
77 SRC = add_.c \
78
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -67,11 +67,12 @@
67 !endif
68
69 SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \
70 /DSQLITE_THREADSAFE=0 \
71 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
72 /DSQLITE_OMIT_DEPRECATED \
73 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
74 /Dlocaltime=fossil_localtime \
75 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
76 /DSQLITE_WIN32_NO_ANSI
77
78 SRC = add_.c \
79

Keyboard Shortcuts

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